* anything-config.el (anything-c-source-recentf): Fix docstring.
[anything-config.git] / anything-config.el
blob4e2f51281a198cabe3f60efc03a8c923a9eeaf71
1 ;;; anything-config.el --- Predefined configurations for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Predefined configurations for `anything.el'
6 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
7 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
8 ;; rubikitch <rubikitch@ruby-lang.org>
9 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
10 ;; Copyright (C) 2007 ~ 2011, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009 ~ 2011, Thierry Volpiatto, all rights reserved.
14 ;; Created: 2009-02-16 21:38:23
15 ;; Version: 0.4.1
16 ;; X-URL: http://repo.or.cz/w/anything-config.git
17 ;; Keywords: anything, anything-config
18 ;; Compatibility: GNU Emacs 22 ~ 24
20 ;; Features that might be required by this library:
22 ;; `anything'
25 ;;; This file is NOT part of GNU Emacs
27 ;;; License
29 ;; This program is free software; you can redistribute it and/or modify
30 ;; it under the terms of the GNU General Public License as published by
31 ;; the Free Software Foundation; either version 3, or (at your option)
32 ;; any later version.
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;; GNU General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING. If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
44 ;;; !NOTICE!
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
49 ;;; Commentary:
51 ;; Predefined configurations for `anything.el'
53 ;; For quick start, try `anything-for-files' to open files.
55 ;; To configure anything you should define anything command
56 ;; with your favorite sources, like below:
58 ;; (defun my-anything ()
59 ;; (interactive)
60 ;; (anything-other-buffer
61 ;; '(anything-c-source-buffers
62 ;; anything-c-source-file-name-history
63 ;; anything-c-source-info-pages
64 ;; anything-c-source-info-elisp
65 ;; anything-c-source-man-pages
66 ;; anything-c-source-locate
67 ;; anything-c-source-emacs-commands)
68 ;; " *my-anything*"))
70 ;; Then type M-x my-anything to use sources.
72 ;; Defining own command is better than setup `anything-sources'
73 ;; directly, because you can define multiple anything commands with
74 ;; different sources. Each anything command should have own anything
75 ;; buffer, because M-x anything-resume revives anything command.
78 ;;; Autodoc documentation:
79 ;; ---------------------
81 ;; * Commands defined here are:
82 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
83 ;; `anything-configuration'
84 ;; Customize `anything'.
85 ;; `anything-c-buffer-help'
86 ;; Help command for anything buffers.
87 ;; `anything-ff-help'
88 ;; Help command for `anything-find-files'.
89 ;; `anything-read-file-name-help'
90 ;; Not documented.
91 ;; `anything-generic-file-help'
92 ;; Not documented.
93 ;; `anything-grep-help'
94 ;; Not documented.
95 ;; `anything-pdfgrep-help'
96 ;; Not documented.
97 ;; `anything-etags-help'
98 ;; The help function for etags.
99 ;; `anything-c-ucs-help'
100 ;; Help command for `anything-ucs'.
101 ;; `anything-mini'
102 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
103 ;; `anything-for-files'
104 ;; Preconfigured `anything' for opening files.
105 ;; `anything-recentf'
106 ;; Preconfigured `anything' for `recentf'.
107 ;; `anything-info-at-point'
108 ;; Preconfigured `anything' for searching info at point.
109 ;; `anything-info-emacs'
110 ;; Preconfigured anything for Emacs manual index.
111 ;; `anything-show-kill-ring'
112 ;; Preconfigured `anything' for `kill-ring'.
113 ;; `anything-minibuffer-history'
114 ;; Preconfigured `anything' for `minibuffer-history'.
115 ;; `anything-gentoo'
116 ;; Preconfigured `anything' for gentoo linux.
117 ;; `anything-imenu'
118 ;; Preconfigured `anything' for `imenu'.
119 ;; `anything-google-suggest'
120 ;; Preconfigured `anything' for google search with google suggest.
121 ;; `anything-yahoo-suggest'
122 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
123 ;; `anything-for-buffers'
124 ;; Preconfigured `anything' for buffer.
125 ;; `anything-buffers-list'
126 ;; Enhanced preconfigured `anything' for buffer.
127 ;; `anything-bbdb'
128 ;; Preconfigured `anything' for BBDB.
129 ;; `anything-locate'
130 ;; Preconfigured `anything' for Locate.
131 ;; `anything-w3m-bookmarks'
132 ;; Preconfigured `anything' for w3m bookmark.
133 ;; `anything-firefox-bookmarks'
134 ;; Preconfigured `anything' for firefox bookmark.
135 ;; `anything-colors'
136 ;; Preconfigured `anything' for color.
137 ;; `anything-bookmarks'
138 ;; Preconfigured `anything' for bookmarks.
139 ;; `anything-c-pp-bookmarks'
140 ;; Preconfigured `anything' for bookmarks (pretty-printed).
141 ;; `anything-c-insert-latex-math'
142 ;; Preconfigured anything for latex math symbols completion.
143 ;; `anything-register'
144 ;; Preconfigured `anything' for Emacs registers.
145 ;; `anything-man-woman'
146 ;; Preconfigured `anything' for Man and Woman pages.
147 ;; `anything-org-keywords'
148 ;; Preconfigured `anything' for org keywords.
149 ;; `anything-emms'
150 ;; Preconfigured `anything' for emms sources.
151 ;; `anything-eev-anchors'
152 ;; Preconfigured `anything' for eev anchors.
153 ;; `anything-bm-list'
154 ;; Preconfigured `anything' for visible bookmarks.
155 ;; `anything-timers'
156 ;; Preconfigured `anything' for timers.
157 ;; `anything-list-emacs-process'
158 ;; Preconfigured `anything' for emacs process.
159 ;; `anything-occur'
160 ;; Preconfigured Anything for Occur source.
161 ;; `anything-browse-code'
162 ;; Preconfigured anything to browse code.
163 ;; `anything-org-headlines'
164 ;; Preconfigured anything to show org headlines.
165 ;; `anything-info-gnus'
166 ;; Preconfigured anything to browse Gnus Manual.
167 ;; `anything-regexp'
168 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
169 ;; `anything-c-copy-files-async'
170 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
171 ;; `anything-find-files'
172 ;; Preconfigured `anything' for anything implementation of `find-file'.
173 ;; `anything-write-file'
174 ;; Preconfigured `anything' providing completion for `write-file'.
175 ;; `anything-insert-file'
176 ;; Preconfigured `anything' providing completion for `insert-file'.
177 ;; `anything-dired-rename-file'
178 ;; Preconfigured `anything' to rename files from dired.
179 ;; `anything-dired-copy-file'
180 ;; Preconfigured `anything' to copy files from dired.
181 ;; `anything-dired-symlink-file'
182 ;; Preconfigured `anything' to symlink files from dired.
183 ;; `anything-dired-hardlink-file'
184 ;; Preconfigured `anything' to hardlink files from dired.
185 ;; `anything-do-grep'
186 ;; Preconfigured anything for grep.
187 ;; `anything-c-etags-select'
188 ;; Preconfigured anything for etags.
189 ;; `anything-filelist'
190 ;; Preconfigured `anything' to open files instantly.
191 ;; `anything-filelist+'
192 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
193 ;; `anything-M-x'
194 ;; Preconfigured `anything' for Emacs commands.
195 ;; `anything-manage-advice'
196 ;; Preconfigured `anything' to disable/enable function advices.
197 ;; `anything-bookmark-ext'
198 ;; Preconfigured `anything' for bookmark-extensions sources.
199 ;; `anything-simple-call-tree'
200 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
201 ;; `anything-mark-ring'
202 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
203 ;; `anything-global-mark-ring'
204 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
205 ;; `anything-all-mark-rings'
206 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
207 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
208 ;; Preconfigured `anything' to edit or view EmacsWiki page.
209 ;; `anything-yaoddmuse-emacswiki-post-library'
210 ;; Preconfigured `anything' to post library to EmacsWiki.
211 ;; `anything-eval-expression'
212 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
213 ;; `anything-eval-expression-with-eldoc'
214 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
215 ;; `anything-calcul-expression'
216 ;; Preconfigured anything for `anything-c-source-calculation-result'.
217 ;; `anything-surfraw'
218 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
219 ;; `anything-call-source'
220 ;; Preconfigured `anything' to call anything source.
221 ;; `anything-execute-anything-command'
222 ;; Preconfigured `anything' to execute preconfigured `anything'.
223 ;; `anything-create'
224 ;; Preconfigured `anything' to do many create actions from STRING.
225 ;; `anything-top'
226 ;; Preconfigured `anything' for top command.
227 ;; `anything-select-xfont'
228 ;; Preconfigured `anything' to select Xfont.
229 ;; `anything-world-time'
230 ;; Preconfigured `anything' to show world time.
231 ;; `anything-apt'
232 ;; Preconfigured `anything' : frontend of APT package manager.
233 ;; `anything-esh-pcomplete'
234 ;; Preconfigured anything to provide anything completion in eshell.
235 ;; `anything-eshell-history'
236 ;; Preconfigured anything for eshell history.
237 ;; `anything-c-run-external-command'
238 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
239 ;; `anything-ratpoison-commands'
240 ;; Preconfigured `anything' to execute ratpoison commands.
241 ;; `anything-ucs'
242 ;; Preconfigured anything for `ucs-names' math symbols.
243 ;; `anything-show-this-source-only'
244 ;; Show all candidates of this source.
245 ;; `anything-test-sources'
246 ;; List all anything sources for test.
247 ;; `anything-select-source'
248 ;; [OBSOLETE] Select source.
249 ;; `anything-mark-all'
250 ;; Mark all visible unmarked candidates in current source.
251 ;; `anything-unmark-all'
252 ;; Unmark all candidates in all sources of current anything session.
253 ;; `anything-toggle-all-marks'
254 ;; Toggle all marks.
255 ;; `anything-buffer-diff-persistent'
256 ;; Toggle diff buffer without quitting anything.
257 ;; `anything-buffer-revert-persistent'
258 ;; Revert buffer without quitting anything.
259 ;; `anything-buffer-save-persistent'
260 ;; Save buffer without quitting anything.
261 ;; `anything-buffer-run-kill-buffers'
262 ;; Run kill buffer action from `anything-c-source-buffers-list'.
263 ;; `anything-buffer-run-grep'
264 ;; Run Grep action from `anything-c-source-buffers-list'.
265 ;; `anything-buffer-run-zgrep'
266 ;; Run Grep action from `anything-c-source-buffers-list'.
267 ;; `anything-buffer-run-query-replace-regexp'
268 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
269 ;; `anything-buffer-run-query-replace'
270 ;; Run Query replace action from `anything-c-source-buffers-list'.
271 ;; `anything-buffer-switch-other-window'
272 ;; Run switch to other window action from `anything-c-source-buffers-list'.
273 ;; `anything-buffer-switch-other-frame'
274 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
275 ;; `anything-buffer-switch-to-elscreen'
276 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
277 ;; `anything-buffer-run-ediff'
278 ;; Run ediff action from `anything-c-source-buffers-list'.
279 ;; `anything-buffer-run-ediff-merge'
280 ;; Run ediff action from `anything-c-source-buffers-list'.
281 ;; `anything-ff-run-toggle-auto-update'
282 ;; Not documented.
283 ;; `anything-ff-run-switch-to-history'
284 ;; Run Switch to history action from `anything-c-source-find-files'.
285 ;; `anything-ff-run-grep'
286 ;; Run Grep action from `anything-c-source-find-files'.
287 ;; `anything-ff-run-pdfgrep'
288 ;; Run Pdfgrep action from `anything-c-source-find-files'.
289 ;; `anything-ff-run-zgrep'
290 ;; Run Grep action from `anything-c-source-find-files'.
291 ;; `anything-ff-run-copy-file'
292 ;; Run Copy file action from `anything-c-source-find-files'.
293 ;; `anything-ff-run-rename-file'
294 ;; Run Rename file action from `anything-c-source-find-files'.
295 ;; `anything-ff-run-byte-compile-file'
296 ;; Run Byte compile file action from `anything-c-source-find-files'.
297 ;; `anything-ff-run-load-file'
298 ;; Run Load file action from `anything-c-source-find-files'.
299 ;; `anything-ff-run-eshell-command-on-file'
300 ;; Run eshell command on file action from `anything-c-source-find-files'.
301 ;; `anything-ff-run-ediff-file'
302 ;; Run Ediff file action from `anything-c-source-find-files'.
303 ;; `anything-ff-run-ediff-merge-file'
304 ;; Run Ediff merge file action from `anything-c-source-find-files'.
305 ;; `anything-ff-run-symlink-file'
306 ;; Run Symlink file action from `anything-c-source-find-files'.
307 ;; `anything-ff-run-delete-file'
308 ;; Run Delete file action from `anything-c-source-find-files'.
309 ;; `anything-ff-run-complete-fn-at-point'
310 ;; Run complete file name action from `anything-c-source-find-files'.
311 ;; `anything-ff-run-switch-to-eshell'
312 ;; Run switch to eshell action from `anything-c-source-find-files'.
313 ;; `anything-ff-run-switch-other-window'
314 ;; Run switch to other window action from `anything-c-source-find-files'.
315 ;; `anything-ff-run-switch-other-frame'
316 ;; Run switch to other frame action from `anything-c-source-find-files'.
317 ;; `anything-ff-run-open-file-externally'
318 ;; Run open file externally command action from `anything-c-source-find-files'.
319 ;; `anything-ff-run-locate'
320 ;; Run locate action from `anything-c-source-find-files'.
321 ;; `anything-ff-run-gnus-attach-files'
322 ;; Run gnus attach files command action from `anything-c-source-find-files'.
323 ;; `anything-ff-run-etags'
324 ;; Run Etags command action from `anything-c-source-find-files'.
325 ;; `anything-ff-run-print-file'
326 ;; Run Print file action from `anything-c-source-find-files'.
327 ;; `anything-ff-run-toggle-basename'
328 ;; Not documented.
329 ;; `anything-find-files-down-one-level'
330 ;; Go down one level like unix command `cd ..'.
331 ;; `anything-ff-properties-persistent'
332 ;; Show properties without quitting anything.
333 ;; `anything-ff-run-kill-buffer-persistent'
334 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
335 ;; `anything-ff-rotate-left-persistent'
336 ;; Rotate image left without quitting anything.
337 ;; `anything-ff-rotate-right-persistent'
338 ;; Rotate image right without quitting anything.
339 ;; `anything-c-goto-precedent-file'
340 ;; Go to precedent file in anything grep/etags buffers.
341 ;; `anything-c-goto-next-file'
342 ;; Go to precedent file in anything grep/etags buffers.
343 ;; `anything-c-grep-run-persistent-action'
344 ;; Run grep persistent action from `anything-do-grep-1'.
345 ;; `anything-c-grep-run-default-action'
346 ;; Run grep default action from `anything-do-grep-1'.
347 ;; `anything-c-grep-run-other-window-action'
348 ;; Run grep goto other window action from `anything-do-grep-1'.
349 ;; `anything-c-grep-run-save-buffer'
350 ;; Run grep save results action from `anything-do-grep-1'.
351 ;; `anything-do-pdfgrep'
352 ;; Not documented.
353 ;; `anything-yank-text-at-point'
354 ;; Yank text at point in minibuffer.
355 ;; `anything-c-describe-attributes'
356 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
357 ;; `anything-yaoddmuse-cache-pages'
358 ;; Fetch the list of files on emacswiki and create cache file.
359 ;; `anything-eval-new-line-and-indent'
360 ;; Not documented.
361 ;; `anything-call-source-from-anything'
362 ;; Call anything source within `anything' session.
363 ;; `anything-create-from-anything'
364 ;; Run `anything-create' from `anything' as a fallback.
365 ;; `anything-c-ucs-persistent-insert'
366 ;; Not documented.
367 ;; `anything-c-ucs-persistent-forward'
368 ;; Not documented.
369 ;; `anything-c-ucs-persistent-backward'
370 ;; Not documented.
371 ;; `anything-c-ucs-persistent-delete'
372 ;; Not documented.
373 ;; `anything-lisp-completion-at-point'
374 ;; Anything lisp symbol completion at point.
375 ;; `anything-c-complete-file-name-at-point'
376 ;; Complete file name at point.
377 ;; `anything-lisp-completion-at-point-or-indent'
378 ;; First call indent and second call complete lisp symbol.
379 ;; `anything-lisp-completion-or-file-name-at-point'
380 ;; Complete lisp symbol or filename at point.
381 ;; `anything-c-set-variable'
382 ;; Set value to VAR interactively.
383 ;; `anything-c-adaptive-save-history'
384 ;; Save history information to file given by `anything-c-adaptive-history-file'.
385 ;; `anything-c-reset-adaptative-history'
386 ;; Delete all `anything-c-adaptive-history' and his file.
387 ;; `anything-c-toggle-match-plugin'
388 ;; Toggle anything-match-plugin.
390 ;; * User variables defined here:
391 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
392 ;; `anything-c-adaptive-history-file'
393 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
394 ;; `anything-c-adaptive-history-length'
395 ;; Default Value: 50
396 ;; `anything-c-google-suggest-url'
397 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
398 ;; `anything-c-google-suggest-search-url'
399 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
400 ;; `anything-google-suggest-use-curl-p'
401 ;; Default Value: nil
402 ;; `anything-c-yahoo-suggest-url'
403 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
404 ;; `anything-c-yahoo-suggest-search-url'
405 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
406 ;; `anything-c-boring-buffer-regexp'
407 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
408 ;; `anything-c-boring-file-regexp'
409 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
410 ;; `anything-kill-ring-threshold'
411 ;; Default Value: 10
412 ;; `anything-c-kill-ring-max-lines-number'
413 ;; Default Value: nil
414 ;; `anything-su-or-sudo'
415 ;; Default Value: "su"
416 ;; `anything-for-files-prefered-list'
417 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
418 ;; `anything-create--actions-private'
419 ;; Default Value: nil
420 ;; `anything-allow-skipping-current-buffer'
421 ;; Default Value: t
422 ;; `anything-c-enable-eval-defun-hack'
423 ;; Default Value: t
424 ;; `anything-tramp-verbose'
425 ;; Default Value: 0
426 ;; `anything-raise-command'
427 ;; Default Value: nil
428 ;; `anything-command-map-prefix-key'
429 ;; Default Value: "<f5> a"
430 ;; `anything-c-browse-code-regexp-lisp'
431 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
432 ;; `anything-c-browse-code-regexp-python'
433 ;; Default Value: "\\<def\\>\\|\\<class\\>"
434 ;; `anything-c-browse-code-regexp-alist'
435 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
436 ;; `anything-c-external-programs-associations'
437 ;; Default Value: nil
438 ;; `anything-ff-auto-update-initial-value'
439 ;; Default Value: t
440 ;; `anything-c-copy-async-prefered-emacs'
441 ;; Default Value: "emacs"
442 ;; `anything-ff-lynx-style-map'
443 ;; Default Value: t
444 ;; `anything-ff-history-max-length'
445 ;; Default Value: 100
446 ;; `anything-ff-smart-completion'
447 ;; Default Value: t
448 ;; `anything-ff-default-kbsize'
449 ;; Default Value: 1024.0
450 ;; `anything-ff-tramp-not-fancy'
451 ;; Default Value: t
452 ;; `anything-ff-exif-data-program'
453 ;; Default Value: "exiftran"
454 ;; `anything-ff-exif-data-program-args'
455 ;; Default Value: "-d"
456 ;; `anything-c-grep-use-ioccur-style-keys'
457 ;; Default Value: t
458 ;; `anything-c-pdfgrep-default-read-command'
459 ;; Default Value: "xpdf '%f' %p"
460 ;; `anything-c-etags-tag-file-name'
461 ;; Default Value: "TAGS"
462 ;; `anything-c-etags-tag-file-search-limit'
463 ;; Default Value: 10
464 ;; `anything-c-etags-use-regexp-search'
465 ;; Default Value: nil
466 ;; `anything-c-filelist-file-name'
467 ;; Default Value: nil
468 ;; `anything-c-eldoc-in-minibuffer-show-fn'
469 ;; Default Value: anything-c-eldoc-show-in-mode-line
470 ;; `anything-c-turn-on-show-completion'
471 ;; Default Value: t
472 ;; `anything-lisp-completion-or-indent-delay'
473 ;; Default Value: 0.6
474 ;; `anything-c-default-external-file-browser'
475 ;; Default Value: "nautilus"
476 ;; `anything-c-use-adaptative-sorting'
477 ;; Default Value: nil
478 ;; `anything-ff-newfile-prompt-p'
479 ;; Default Value: t
480 ;; `anything-ff-avfs-directory'
481 ;; Default Value: nil
482 ;; `anything-ff-file-compressed-list'
483 ;; Default Value: ("gz" "bz2" "zip" "7z")
484 ;; `anything-locate-db-file-regexp'
485 ;; Default Value: "m?locate.db$"
486 ;; `anything-c-eldoc-show-in-mode-line-delay'
487 ;; Default Value: 12
488 ;; `anything-c-copy-files-async-log-file'
489 ;; Default Value: "/tmp/dired.log"
490 ;; `anything-ff-printer-list'
491 ;; Default Value: nil
492 ;; `anything-ff-transformer-show-only-basename'
493 ;; Default Value: nil
495 ;; * Anything sources defined here:
496 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
497 ;; `anything-c-source-regexp' (Regexp Builder)
498 ;; `anything-c-source-buffers' (Buffers)
499 ;; `anything-c-source-buffer-not-found' (Create buffer)
500 ;; `anything-c-source-buffers-list' (Buffers)
501 ;; `anything-c-source-file-name-history' (File Name History)
502 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
503 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
504 ;; `anything-c-source-find-files' (Find Files)
505 ;; `anything-c-source-write-file' (Write File)
506 ;; `anything-c-source-insert-file' (Insert File)
507 ;; `anything-c-source-copy-files' (Copy Files)
508 ;; `anything-c-source-symlink-files' (Symlink Files)
509 ;; `anything-c-source-hardlink-files' (Hardlink Files)
510 ;; `anything-c-source-file-cache' (File Cache)
511 ;; `anything-c-source-locate' (Locate)
512 ;; `anything-c-source-recentf' (Recentf)
513 ;; `anything-c-source-ffap-guesser' (File at point)
514 ;; `anything-c-source-ffap-line' (File/Lineno at point)
515 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
516 ;; `anything-c-source-filelist' (FileList)
517 ;; `anything-c-source-info-pages' (Info Pages)
518 ;; `anything-c-source-info-elisp' (Info index: elisp)
519 ;; `anything-c-source-info-cl' (Info index: cl)
520 ;; `anything-c-source-info-org' (Info index: org)
521 ;; `anything-c-source-info-gnus' (Info index: Gnus)
522 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
523 ;; `anything-c-source-info-zsh' (Info index: zsh)
524 ;; `anything-c-source-info-bash' (Info index: bash)
525 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
526 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
527 ;; `anything-c-source-info-find' (Info index: find)
528 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
529 ;; `anything-c-source-info-textutils' (Info index: textutils)
530 ;; `anything-c-source-info-libc' (Info index: libc)
531 ;; `anything-c-source-info-make' (Info index: make)
532 ;; `anything-c-source-info-automake' (Info index: automake)
533 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
534 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
535 ;; `anything-c-source-info-emacs' (Info index: emacs)
536 ;; `anything-c-source-info-elib' (Info index: elib)
537 ;; `anything-c-source-info-eieio' (Info index: eieio)
538 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
539 ;; `anything-c-source-info-guile' (Info index: guile)
540 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
541 ;; `anything-c-source-info-goops' (Info index: goops)
542 ;; `anything-c-source-info-screen' (Info index: screen)
543 ;; `anything-c-source-info-latex' (Info index: latex)
544 ;; `anything-c-source-info-gawk' (Info index: gawk)
545 ;; `anything-c-source-info-sed' (Info index: sed)
546 ;; `anything-c-source-info-m4' (Info index: m4)
547 ;; `anything-c-source-info-wget' (Info index: wget)
548 ;; `anything-c-source-info-binutils' (Info index: binutils)
549 ;; `anything-c-source-info-as' (Info index: as)
550 ;; `anything-c-source-info-bfd' (Info index: bfd)
551 ;; `anything-c-source-info-gprof' (Info index: gprof)
552 ;; `anything-c-source-info-ld' (Info index: ld)
553 ;; `anything-c-source-info-diff' (Info index: diff)
554 ;; `anything-c-source-info-flex' (Info index: flex)
555 ;; `anything-c-source-info-grep' (Info index: grep)
556 ;; `anything-c-source-info-gzip' (Info index: gzip)
557 ;; `anything-c-source-info-libtool' (Info index: libtool)
558 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
559 ;; `anything-c-source-info-info' (Info index: info)
560 ;; `anything-c-source-info-gdb' (Info index: gdb)
561 ;; `anything-c-source-info-stabs' (Info index: stabs)
562 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
563 ;; `anything-c-source-info-cvs' (Info index: cvs)
564 ;; `anything-c-source-info-bison' (Info index: bison)
565 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
566 ;; `anything-c-source-info-global' (Info index: global)
567 ;; `anything-c-source-man-pages' (Manual Pages)
568 ;; `anything-c-source-complex-command-history' (Complex Command History)
569 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
570 ;; `anything-c-source-emacs-commands' (Emacs Commands)
571 ;; `anything-c-source-lacarte' (Lacarte)
572 ;; `anything-c-source-emacs-functions' (Emacs Functions)
573 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
574 ;; `anything-c-source-advice' (Function Advice)
575 ;; `anything-c-source-emacs-variables' (Emacs Variables)
576 ;; `anything-c-source-bookmarks' (Bookmarks)
577 ;; `anything-c-source-bookmark-set' (Set Bookmark)
578 ;; `anything-c-source-bm' (Visible Bookmarks)
579 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
580 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
581 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
582 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
583 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
584 ;; `anything-c-source-bookmark-images' (Bookmark Images)
585 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
586 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
587 ;; `anything-c-source-bookmark-info' (Bookmark Info)
588 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
589 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
590 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
591 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
592 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
593 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
594 ;; `anything-c-source-imenu' (Imenu)
595 ;; `anything-c-source-ctags' (Exuberant ctags)
596 ;; `anything-c-source-etags-select' (Etags)
597 ;; `anything-c-source-semantic' (Semantic Tags)
598 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
599 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
600 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
601 ;; `anything-c-source-customize-face' (Customize Face)
602 ;; `anything-c-source-colors' (Colors)
603 ;; `anything-c-source-tracker-search' (Tracker Search)
604 ;; `anything-c-source-mac-spotlight' (mdfind)
605 ;; `anything-c-source-picklist' (Picklist)
606 ;; `anything-c-source-kill-ring' (Kill Ring)
607 ;; `anything-c-source-mark-ring' (mark-ring)
608 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
609 ;; `anything-c-source-register' (Registers)
610 ;; `anything-c-source-latex-math' (Latex Math Menu)
611 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
612 ;; `anything-c-source-rd-headline' (RD HeadLine)
613 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
614 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
615 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
616 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
617 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
618 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
619 ;; `anything-c-source-eev-anchor' (Anchors)
620 ;; `anything-c-source-org-headline' (Org HeadLine)
621 ;; `anything-c-source-org-keywords' (Org Keywords)
622 ;; `anything-c-source-bbdb' (BBDB)
623 ;; `anything-c-source-evaluation-result' (Evaluation Result)
624 ;; `anything-c-source-calculation-result' (Calculation Result)
625 ;; `anything-c-source-google-suggest' (Google Suggest)
626 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
627 ;; `anything-c-source-emms-streams' (Emms Streams)
628 ;; `anything-c-source-emms-dired' (Music Directory)
629 ;; `anything-c-source-emms-files' (Emms files)
630 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
631 ;; `anything-c-source-call-source' (Call anything source)
632 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
633 ;; `anything-c-source-occur' (Occur)
634 ;; `anything-c-source-browse-code' (Browse code)
635 ;; `anything-c-source-create' (Create)
636 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
637 ;; `anything-c-source-elscreen' (Elscreen)
638 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
639 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
640 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
641 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
642 ;; `anything-c-source-xfonts' (X Fonts)
643 ;; `anything-c-source-ucs' (Ucs names)
644 ;; `anything-c-source-emacs-process' (Emacs Process)
645 ;; `anything-c-source-time-world' (Time World List)
646 ;; `anything-c-source-apt' (APT)
647 ;; `anything-c-source-gentoo' (Portage sources)
648 ;; `anything-c-source-use-flags' (Use Flags)
649 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
650 ;; `anything-c-source-esh' (Eshell completions)
651 ;; `anything-c-source-eshell-history' (Eshell history)
653 ;; *** END auto-documentation
655 ;;; For Maintainers:
657 ;; Install developer-tools/autodoc.el and
658 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
659 ;; This function generates anything-c-source-* / functions / options list.
661 ;; [EVAL IT] (autodoc-update-all)
663 ;; Please write details documentation about function, then others will
664 ;; read code more easier. -- Andy Stewart
668 ;;; Change log:
670 ;; Change log of this file is found at
671 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
673 ;; Change log of this project is found at
674 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
676 ;;; Contributors:
678 ;; Tamas Patrovics
679 ;; Tassilo Horn <tassilo@member.fsf.org>
680 ;; Vagn Johansen <gonz808@hotmail.com>
681 ;; Mathias Dahl <mathias.dahl@gmail.com>
682 ;; Bill Clementson <billclem@gmail.com>
683 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
684 ;; Drew Adams <drew.adams@oracle.com>
685 ;; Jason McBrayer <jmcbray@carcosa.net>
686 ;; Andy Stewart <lazycat.manatee@gmail.com>
687 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
688 ;; rubikitch <rubikitch@ruby-lang.org>
689 ;; Scott Vokes <vokes.s@gmail.com>
690 ;; Kenichirou Oyama <k1lowxb@gmail.com>
693 ;;; TODO
695 ;; - Fix documentation, now many functions haven't documentations.
699 ;;; Code:
701 ;;; Require
704 (require 'anything)
705 (require 'thingatpt)
706 (require 'ffap)
707 (require 'cl)
708 (require 'dired-aux)
709 (require 'dired-x)
710 (require 'tramp)
711 (require 'grep)
712 (require 'url)
713 (require 'xml)
714 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
715 (eval-when-compile (require 'semantic nil t))
716 (require 'anything-match-plugin)
720 ;;; Declare external functions
723 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
724 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
725 (declare-function image-dired-update-property "image-dired.el" (prop value))
726 (declare-function woman-file-name-all-completions "woman.el" (topic))
727 (declare-function Man-getpage-in-background "man.el" (topic))
728 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
729 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
730 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
731 (declare-function org-get-current-options "ext:org-exp.el")
732 (declare-function emms-streams "ext:emms-streams")
733 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
734 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
735 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
736 (declare-function emms-stream-quit "ext:emms-streams")
737 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
738 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
739 (declare-function emms-playlist-first "ext:emms")
740 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
741 (declare-function term-line-mode "term")
742 (declare-function term-char-mode "term")
743 (declare-function term-send-input "term")
744 (declare-function term-send-eof "term")
745 (declare-function Info-index-nodes "info" (&optional file))
746 (declare-function Info-goto-node "info" (&optional fork))
747 (declare-function Info-find-node "info.el" (filename nodename &optional no-going-back))
748 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
749 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
750 (declare-function elscreen-goto "ext:elscreen.el" (screen))
751 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
752 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
753 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
754 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
755 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
756 (declare-function bbdb "ext:bbdb-com")
757 (declare-function bbdb-current-record "ext:bbdb-com")
758 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
759 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
760 (declare-function bbdb-current-record "ext:bbdb-com")
761 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
762 (declare-function bbdb-records "ext:bbdb-com"
763 (&optional dont-check-disk already-in-db-buffer))
764 (declare-function eshell-read-aliases-list "em-alias")
765 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
766 (declare-function eshell-bol "esh-mode")
767 (declare-function eldoc-current-symbol "eldoc")
768 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
769 (declare-function eldoc-get-var-docstring "eldoc" (sym))
770 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
771 (declare-function find-library-name "find-func.el" (library))
772 (declare-function adoc-construct "ext:auto-document.el" (buf))
773 (declare-function adoc-first-line "ext:auto-document.el" (str))
774 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
775 (declare-function secure-hash "ext:fns.c" (algorithm object &optional start end binary))
779 ;;; compatibility
782 (unless (fboundp 'window-system)
783 (defun window-system (&optional arg)
784 window-system))
788 ;;; Customize
791 (defgroup anything-config nil
792 "Predefined configurations for `anything.el'."
793 :group 'anything)
795 (defcustom anything-c-adaptive-history-file
796 "~/.emacs.d/anything-c-adaptive-history"
797 "Path of file where history information is stored."
798 :type 'string
799 :group 'anything-config)
801 (defcustom anything-c-adaptive-history-length 50
802 "Maximum number of candidates stored for a source."
803 :type 'number
804 :group 'anything-config)
806 (defcustom anything-c-google-suggest-url
807 "http://google.com/complete/search?output=toolbar&q="
808 "URL used for looking up Google suggestions."
809 :type 'string
810 :group 'anything-config)
812 (defcustom anything-c-google-suggest-search-url
813 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
814 "URL used for Google searching."
815 :type 'string
816 :group 'anything-config)
818 (defcustom anything-google-suggest-use-curl-p nil
819 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
820 Otherwise `url-retrieve-synchronously' is used."
821 :type 'boolean
822 :group 'anything-config)
824 (defcustom anything-c-yahoo-suggest-url
825 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
826 "Url used for looking up Yahoo suggestions."
827 :type 'string
828 :group 'anything-config)
830 (defcustom anything-c-yahoo-suggest-search-url
831 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
832 "Url used for Yahoo searching."
833 :type 'string
834 :group 'anything-config)
836 (defcustom anything-c-boring-buffer-regexp
837 (rx (or
838 (group bos " ")
839 ;; anything-buffer
840 "*anything"
841 ;; echo area
842 " *Echo Area" " *Minibuf"))
843 "The regexp that match boring buffers.
844 Buffer candidates matching this regular expression will be
845 filtered from the list of candidates if the
846 `anything-c-skip-boring-buffers' candidate transformer is used, or
847 they will be displayed with face `file-name-shadow' if
848 `anything-c-shadow-boring-buffers' is used."
849 :type 'string
850 :group 'anything-config)
851 ;; (string-match anything-c-boring-buffer-regexp "buf")
852 ;; (string-match anything-c-boring-buffer-regexp " hidden")
853 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
855 (defcustom anything-c-boring-file-regexp
856 (rx (or
857 ;; Boring directories
858 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
859 ;; Boring files
860 (and line-start ".#")
861 (and (or ".class" ".la" ".o" "~") eol)))
862 "The regexp that match boring files.
863 File candidates matching this regular expression will be
864 filtered from the list of candidates if the
865 `anything-c-skip-boring-files' candidate transformer is used, or
866 they will be displayed with face `file-name-shadow' if
867 `anything-c-shadow-boring-files' is used."
868 :type 'string
869 :group 'anything-config)
871 (defcustom anything-kill-ring-threshold 10
872 "*Minimum length to be listed by `anything-c-source-kill-ring'."
873 :type 'integer
874 :group 'anything-config)
876 (defcustom anything-c-kill-ring-max-lines-number nil
877 "Max number of lines displayed per candidate in kill-ring browser.
878 If nil or zero, don't truncate candidate, show all."
879 :type 'integer
880 :group 'anything-config)
882 (defcustom anything-su-or-sudo "su"
883 "What command to use for root access."
884 :type 'string
885 :group 'anything-config)
887 (defcustom anything-for-files-prefered-list
888 '(anything-c-source-ffap-line
889 anything-c-source-ffap-guesser
890 anything-c-source-buffers-list
891 anything-c-source-recentf
892 anything-c-source-bookmarks
893 anything-c-source-file-cache
894 anything-c-source-files-in-current-dir+
895 anything-c-source-locate)
896 "Your prefered sources to find files."
897 :type 'list
898 :group 'anything-config)
900 (defcustom anything-create--actions-private nil
901 "User defined actions for `anything-create' / `anything-c-source-create'.
902 It is a list of (DISPLAY . FUNCTION) pairs like `action'
903 attribute of `anything-sources'.
905 It is prepended to predefined pairs."
906 :type 'list
907 :group 'anything-config)
909 (defcustom anything-allow-skipping-current-buffer t
910 "Show current buffer or not in anything buffer"
911 :type 'boolean
912 :group 'anything-config)
914 (defcustom anything-c-enable-eval-defun-hack t
915 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
916 This hack is invoked when pressing C-M-x in the form \
917 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
918 :type 'boolean
919 :group 'anything-config)
921 (defcustom anything-tramp-verbose 0
922 "*Just like `tramp-verbose' but specific to anything.
923 When set to 0 don't show tramp messages in anything.
924 If you want to have the default tramp messages set it to 3."
925 :type 'integer
926 :group 'anything-config)
928 (defcustom anything-raise-command nil
929 "*A shell command to jump to a window running specific program.
930 Need external program wmctrl.
931 This will be use with `format', so use something like \"wmctrl -xa %s\"."
932 :type 'string
933 :group 'anything-config)
935 (defun anything-set-anything-command-map-prefix-key (var key)
936 (declare (special anything-command-map-prefix-key))
937 (when (boundp 'anything-command-map-prefix-key)
938 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
939 (setq anything-command-map-prefix-key key)
940 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
941 'anything-command-map))
943 (defcustom anything-command-map-prefix-key "<f5> a"
944 "*The prefix key for all `anything-command-map' commands.
946 !!WARNING!!
947 This default value is very likely to be changed,
948 because it is under discussion."
949 :type 'string
950 :set 'anything-set-anything-command-map-prefix-key
951 :group 'anything-config)
953 (defcustom anything-c-browse-code-regexp-lisp
954 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
955 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
956 "*Regexp used to parse lisp buffer when browsing code."
957 :type 'string
958 :group 'anything-config)
960 (defcustom anything-c-browse-code-regexp-python
961 "\\<def\\>\\|\\<class\\>"
962 "*Regexp used to parse python buffer when browsing code."
963 :type 'string
964 :group 'anything-config)
966 (defcustom anything-c-browse-code-regexp-alist
967 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
968 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
969 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
970 (python-mode . ,anything-c-browse-code-regexp-python))
971 "*Alist to store regexps for browsing code corresponding \
972 to a specific `major-mode'."
973 :type 'list
974 :group 'anything-config)
976 (defcustom anything-c-external-programs-associations nil
977 "*Alist to store externals programs associated with file extension.
978 This variable overhide setting in .mailcap file.
979 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
980 :type 'list
981 :group 'anything-config)
983 (defcustom anything-ff-auto-update-initial-value t
984 "Auto update when only one candidate directory is matched.
985 This is the default value when starting `anything-find-files'."
986 :group 'anything-config
987 :type 'boolean)
989 (defcustom anything-c-copy-async-prefered-emacs "emacs"
990 "Path to the emacs you want to use for copying async.
991 Emacs versions < 24 fail to copy directory due to a bug not fixed
992 in `copy-directory'."
993 :group 'anything-config
994 :type 'string)
996 (defcustom anything-ff-lynx-style-map t
997 "Use arrow keys to navigate with `anything-find-files'.
998 You will have to restart Emacs or reeval `anything-find-files-map'
999 and `anything-c-read-file-map' for this take effect."
1000 :group 'anything-config
1001 :type 'boolean)
1003 (defcustom anything-ff-history-max-length 100
1004 "*Number of elements shown in `anything-find-files' history."
1005 :group 'anything-config
1006 :type 'integer)
1008 (defcustom anything-ff-smart-completion t
1009 "Try to complete filenames smarter when non--nil.
1010 See `anything-ff-transform-fname-for-completion' for more info."
1011 :group 'anything-config
1012 :type 'boolean)
1014 (defcustom anything-ff-default-kbsize 1024.0
1015 "Default Kbsize to use for showing files size.
1016 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1017 :group 'anything-config
1018 :type 'float)
1020 (defcustom anything-ff-tramp-not-fancy t
1021 "No colors when listing remote files when set to non--nil.
1022 This make listing much faster, specially on slow machines."
1023 :group 'anything-config
1024 :type 'boolean)
1026 (defcustom anything-ff-exif-data-program "exiftran"
1027 "*Program used to extract exif data of an image file."
1028 :group 'anything-config
1029 :type 'string)
1031 (defcustom anything-ff-exif-data-program-args "-d"
1032 "*Arguments used for `anything-ff-exif-data-program'."
1033 :group 'anything-config
1034 :type 'string)
1036 (defcustom anything-c-grep-use-ioccur-style-keys t
1037 "Use Arrow keys to jump to occurences."
1038 :group 'anything-config
1039 :type 'boolean)
1041 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
1042 "Default command to read pdf files from pdfgrep.
1043 Where '%f' format spec is filename and '%p' is page number"
1044 :group 'anything-config
1045 :type 'string)
1047 (defcustom anything-c-etags-tag-file-name "TAGS"
1048 "Etags tag file name."
1049 :type 'string
1050 :group 'anything-config)
1052 (defcustom anything-c-etags-tag-file-search-limit 10
1053 "The limit level of directory to search tag file.
1054 Don't search tag file deeply if outside this value."
1055 :type 'number
1056 :group 'anything-config)
1058 (defcustom anything-c-etags-use-regexp-search nil
1059 "When non--nil search etags candidates by regexp.
1060 This disable anything-match-plugin when enabled.
1061 When nil search is performed literally and *match-plugin is used
1062 if available."
1063 :group 'anything-config
1064 :type 'boolean)
1066 (defcustom anything-c-filelist-file-name nil
1067 "Filename of file list.
1068 Accept a list of string for multiple files.
1070 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1071 File list is created by make-filelist.rb script.
1073 Usage:
1074 ruby make-filelist.rb > /tmp/all.filelist
1076 Then
1077 ;; Assume that /tmp is ramdisk or tmpfs
1078 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1079 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1081 :type 'string
1082 :group 'anything-config)
1084 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1085 'anything-c-eldoc-show-in-mode-line
1086 "A function to display eldoc info.
1087 Should take one arg: the string to display."
1088 :group 'anything-config
1089 :type 'symbol)
1091 (defcustom anything-c-turn-on-show-completion t
1092 "Display candidate in buffer while moving selection when non--nil."
1093 :group 'anything-config
1094 :type 'boolean)
1096 (defcustom anything-lisp-completion-or-indent-delay 0.6
1097 "After this delay `anything-lisp-completion-counter' is reset to 0.
1098 This allow to indent again without completing lisp symbol after this delay.
1099 Default is 0.6 seconds."
1100 :group 'anything-config
1101 :type 'number)
1103 (defcustom anything-c-default-external-file-browser "nautilus"
1104 "Default external file browser for your system.
1105 Directories will be opened externally with it.
1106 Set to nil if you do not have external file browser
1107 or do not want to use it."
1108 :group 'anything-config
1109 :type 'string)
1111 (defcustom anything-c-use-adaptative-sorting nil
1112 "*Wheter to use or not adaptative sorting.
1113 Even if a source use it, it will have no effect when set to nil."
1114 :type 'boolean
1115 :group 'anything-config)
1117 (defcustom anything-ff-newfile-prompt-p t
1118 "Whether Prompt or not when creating new file.
1119 This set `ffap-newfile-prompt'."
1120 :type 'boolean
1121 :group 'anything-config)
1124 (defcustom anything-ff-avfs-directory nil
1125 "*The default avfs directory, usually '.avfs'.
1126 When this is set you will be able to expand archive filenames with `C-z'
1127 inside an avfs directory mounted with mountavfs.
1128 See <http://sourceforge.net/projects/avf/>."
1129 :type 'boolean
1130 :group 'anything-config)
1132 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1133 "*Minimal list of compressed files extension."
1134 :type 'list
1135 :group 'anything-config)
1137 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1138 "Default regexp to match locate database.
1139 If nil Search in all files."
1140 :type 'string
1141 :group 'anything-config)
1143 (defcustom anything-c-eldoc-show-in-mode-line-delay 12
1144 "Eldoc will show info in mode-line during this delay if user is idle."
1145 :type 'integer
1146 :group 'anything-config)
1148 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1149 "The file used to communicate with two emacs when copying files async."
1150 :type 'string
1151 :group 'anything-config)
1153 (defcustom anything-ff-printer-list nil
1154 "A list of available printers on your system.
1155 When non--nil let you choose a printer to print file.
1156 Otherwise when nil the variable `printer-name' will be used.
1157 On Unix based systems you can use `anything-ff-find-printers' to
1158 find a list of available printers."
1159 :type 'list
1160 :group 'anything-config)
1162 (defcustom anything-ff-transformer-show-only-basename nil
1163 "Show only basename of candidates in `anything-find-files'.
1164 This can be toggled at anytime from `anything-find-files' with \
1165 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1166 :type 'boolean
1167 :group 'anything-config)
1169 (defcustom anything-completing-read-handlers-alist
1170 '((describe-function . anything-completing-read-symbols)
1171 (describe-variable . anything-completing-read-symbols)
1172 (debug-on-entry . anything-completing-read-symbols)
1173 (ffap-alternate-file . nil))
1174 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1175 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1176 where key and value are symbols.
1178 Each key is an Emacs command that use originaly `completing-read'.
1180 Each value maybe an anything function that take same arguments as
1181 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1182 anything source and BUFFER the name of the buffer we will use.
1183 This function prefix name must start by \"anything\".
1185 See `anything-completing-read-symbols' for example.
1187 If the value of an entry is nil completion will fall back to
1188 emacs vanilla behavior.
1189 e.g If you want to disable anything completion for `describe-function':
1190 \(describe-function . nil\).
1192 Ido is also supported, you can use `ido-completing-read' and
1193 `ido-read-file-name' as value of an entry or just 'ido.
1194 e.g ido completion for `find-file':
1195 \(find-file . ido\)
1196 same as
1197 \(find-file . ido-read-file-name\)
1198 Note that you don't need to enable `ido-mode' for this to work."
1199 :group 'anything-config
1200 :type '(alist :key-type symbol :value-type symbol))
1204 ;;; General internal variables
1206 ;; Some internals variable that need to be loaded
1207 ;; here to avoid compiler warnings.
1208 (defvar anything-c-external-commands-list nil
1209 "A list of all external commands the user can execute. If this
1210 variable is not set by the user, it will be calculated
1211 automatically.")
1213 (defvar anything-c-show-completion-overlay nil)
1215 (defvar anything-c-locate-command
1216 (case system-type
1217 ('gnu/linux "locate -i -r %s")
1218 ('berkeley-unix "locate -i %s")
1219 ('windows-nt "es -i -r %s")
1220 (t "locate %s"))
1221 "A list of arguments for locate program.
1222 The \"-r\" option must be the last option.")
1225 ;;; Faces
1228 (defface anything-buffer-saved-out
1229 '((t (:foreground "red")))
1230 "*Face used for buffer files modified outside of emacs."
1231 :group 'anything-config)
1233 (defface anything-buffer-not-saved
1234 '((t (:foreground "Indianred2")))
1235 "*Face used for buffer files not already saved on disk."
1236 :group 'anything-config)
1238 (defface anything-ff-prefix
1239 '((t (:background "yellow" :foreground "black")))
1240 "*Face used to prefix new file or url paths in `anything-find-files'."
1241 :group 'anything-config)
1243 (defface anything-ff-executable
1244 '((t (:foreground "green")))
1245 "*Face used for executable files in `anything-find-files'."
1246 :group 'anything-config)
1248 (defface anything-ff-directory
1249 '((t (:foreground "DarkRed" :background "LightGray")))
1250 "*Face used for directories in `anything-find-files'."
1251 :group 'anything-config)
1253 (defface anything-ff-symlink
1254 '((t (:foreground "DarkOrange")))
1255 "*Face used for symlinks in `anything-find-files'."
1256 :group 'anything-config)
1258 (defface anything-ff-invalid-symlink
1259 '((t (:foreground "black" :background "red")))
1260 "*Face used for invalid symlinks in `anything-find-files'."
1261 :group 'anything-config)
1263 (defface anything-ff-file
1264 '((t (:foreground "CadetBlue" :underline t)))
1265 "*Face used for file names in `anything-find-files'."
1266 :group 'anything-config)
1268 (defface anything-grep-match
1269 '((t (:inherit match)))
1270 "Face used to highlight grep matches."
1271 :group 'anything-config)
1273 (defface anything-grep-file
1274 '((t (:foreground "BlueViolet" :underline t)))
1275 "Face used to highlight grep results filenames."
1276 :group 'anything-config)
1278 (defface anything-grep-lineno
1279 '((t (:foreground "Darkorange1")))
1280 "Face used to highlight grep number lines."
1281 :group 'anything-config)
1283 (defface anything-grep-running
1284 '((t (:foreground "Red")))
1285 "Face used in mode line when grep is running."
1286 :group 'anything-config)
1288 (defface anything-grep-finish
1289 '((t (:foreground "Green")))
1290 "Face used in mode line when grep is finish."
1291 :group 'anything-config)
1293 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1294 "*Face used in anything-M-x to show keybinding."
1295 :group 'anything)
1297 (defface anything-bmkext-info
1298 '((t (:foreground "green")))
1299 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1300 :group 'anything)
1302 (defface anything-bmkext-w3m
1303 '((t (:foreground "yellow")))
1304 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1305 :group 'anything)
1307 (defface anything-bmkext-gnus
1308 '((t (:foreground "magenta")))
1309 "*Face used for Gnus bookmarks."
1310 :group 'anything)
1312 (defface anything-bmkext-man
1313 '((t (:foreground "Orange4")))
1314 "*Face used for Woman/man bookmarks."
1315 :group 'anything)
1317 (defface anything-bmkext-no--file
1318 '((t (:foreground "grey")))
1319 "*Face used for non--file bookmarks."
1320 :group 'anything)
1322 (defface anything-bmkext-file
1323 '((t (:foreground "Deepskyblue2")))
1324 "*Face used for non--file bookmarks."
1325 :group 'anything)
1327 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1328 "Face for su/sudo bookmarks."
1329 :group 'anything)
1331 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1332 "Face for w3m bookmarks" :group 'anything)
1334 (defface anything-emms-playlist
1335 '((t (:foreground "Springgreen4" :underline t)))
1336 "*Face used for tracks in current emms playlist."
1337 :group 'anything)
1339 (defface anything-apt-installed
1340 '((t (:foreground "green")))
1341 "*Face used for apt installed candidates."
1342 :group 'anything)
1344 (defface anything-gentoo-match-face '((t (:foreground "red")))
1345 "Face for anything-gentoo installed packages."
1346 :group 'traverse-faces)
1348 (defface anything-lisp-show-completion
1349 '((t (:background "DarkSlateGray")))
1350 "*Face used for showing candidates in `anything-lisp-completion'."
1351 :group 'anything-config)
1353 (defface anything-lisp-completion-info
1354 '((t (:foreground "red")))
1355 "*Face used for showing info in `anything-lisp-completion'."
1356 :group 'anything-config)
1358 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1359 "Face for source header in the anything buffer." :group 'anything)
1361 ;;;###autoload
1362 (defun anything-configuration ()
1363 "Customize `anything'."
1364 (interactive)
1365 (customize-group "anything-config"))
1369 ;;; Anything-command-map
1372 ;;;###autoload
1373 (defvar anything-command-map)
1374 (define-prefix-command 'anything-command-map)
1377 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1378 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1379 (define-key anything-command-map (kbd "l") 'anything-locate)
1380 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1381 (define-key anything-command-map (kbd "r") 'anything-regexp)
1382 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1383 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1384 (define-key anything-command-map (kbd "#") 'anything-emms)
1385 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1386 (define-key anything-command-map (kbd "t") 'anything-top)
1387 (define-key anything-command-map (kbd "i") 'anything-imenu)
1388 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1389 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1390 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1391 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1392 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1393 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1394 (define-key anything-command-map (kbd "f") 'anything-for-files)
1395 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1396 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1397 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1398 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1399 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1400 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1401 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1402 (define-key anything-command-map (kbd "c") 'anything-colors)
1403 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1404 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1405 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1406 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1407 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1408 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1409 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1410 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1411 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1412 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1414 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1415 ;; minibuffer-local-filename-must-match-map.
1416 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1417 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1418 (dolist (map (list minibuffer-local-filename-completion-map
1419 minibuffer-local-completion-map
1420 minibuffer-local-must-match-filename-map
1421 minibuffer-local-filename-must-match-map
1422 minibuffer-local-map
1423 minibuffer-local-isearch-map
1424 minibuffer-local-must-match-map
1425 minibuffer-local-ns-map))
1426 (define-key map "\C-r" 'anything-minibuffer-history))
1430 ;;; Menu
1433 (easy-menu-define nil global-map
1434 "`anything' menu"
1435 '("Anything"
1436 ["All anything commands" anything-execute-anything-command t]
1437 ["Find any Files/Buffers" anything-for-files t]
1438 "----"
1439 ("Files:"
1440 ["Find files" anything-find-files t]
1441 ["Recent Files" anything-recentf t]
1442 ["Locate" anything-locate t]
1443 ["Bookmarks" anything-c-pp-bookmarks t])
1444 ("Buffers:"
1445 ["Find buffers" anything-buffers-list t])
1446 ("Commands:"
1447 ["Emacs Commands" anything-M-x t]
1448 ["Externals Commands" anything-c-run-external-command t])
1449 ("Info:"
1450 ["Info at point" anything-info-at-point t]
1451 ["Emacs Manual index" anything-info-emacs t]
1452 ["Gnus Manual index" anything-info-gnus t])
1453 ("Org:"
1454 ["Org keywords" anything-org-keywords t]
1455 ["Org headlines" anything-org-headlines t])
1456 ("Tools:"
1457 ["Occur" anything-occur t]
1458 ["Grep" anything-do-grep t]
1459 ["Etags" anything-c-etags-select t]
1460 ["Lisp complete at point" anything-lisp-completion-at-point t]
1461 ["Browse Kill ring" anything-show-kill-ring t]
1462 ["Browse register" anything-register t]
1463 ["Browse code" anything-browse-code t]
1464 ["Mark Ring" anything-all-mark-rings t]
1465 ["Regexp handler" anything-regexp t]
1466 ["Colors & Faces" anything-colors t]
1467 ["Show xfonts" anything-select-xfont t]
1468 ["Ucs Symbols" anything-ucs t]
1469 ["Imenu" anything-imenu t]
1470 ["Google Suggest" anything-google-suggest t]
1471 ["Eval expression" anything-eval-expression-with-eldoc t]
1472 ["Calcul expression" anything-calcul-expression t]
1473 ["Man pages" anything-man-woman t]
1474 ["Top externals process" anything-top t]
1475 ["Emacs internals process" anything-list-emacs-process t])
1476 "----"
1477 ["Prefered Options" anything-configuration t]))
1479 ;;; Anything map add ons
1482 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1483 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1484 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1487 ;;; Specialized keymaps
1490 (defvar anything-c-buffer-map
1491 (let ((map (copy-keymap anything-map)))
1492 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1493 ;; No need to have separate command for grep and zgrep
1494 ;; as we don't use recursivity for buffers.
1495 ;; So use zgrep for both as it is capable to handle non--compressed files.
1496 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1497 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1498 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1499 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1500 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1501 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1502 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1503 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1504 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1505 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1506 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1507 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1508 (define-key map (kbd "M-a") 'anything-mark-all)
1509 (when (locate-library "elscreen")
1510 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1511 (delq nil map))
1512 "Keymap for buffer sources in anything.")
1514 (defvar anything-find-files-map
1515 (let ((map (copy-keymap anything-map)))
1516 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1517 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1518 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1519 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1520 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1521 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1522 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1523 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1524 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1525 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1526 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1527 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1528 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1529 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1530 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1531 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1532 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1533 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1534 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1535 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1536 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1537 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1538 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1539 (define-key map (kbd "C-c ?") 'anything-ff-help)
1540 (define-key map (kbd "C-}") 'anything-narrow-window)
1541 (define-key map (kbd "C-{") 'anything-enlarge-window)
1542 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1543 (define-key map (kbd "M-a") 'anything-mark-all)
1544 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1545 (define-key map (kbd "M-u") 'anything-unmark-all)
1546 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1547 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1548 ;; Next 2 have no effect if candidate is not an image file.
1549 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1550 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1551 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1552 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1553 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1554 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1555 (when anything-ff-lynx-style-map
1556 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1557 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1558 (delq nil map))
1559 "Keymap for `anything-find-files'.")
1561 (defvar anything-c-read-file-map
1562 (let ((map (copy-keymap anything-map)))
1563 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1564 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1565 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1566 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1567 (when anything-ff-lynx-style-map
1568 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1569 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1570 (define-key map (kbd "<M-left>") 'anything-previous-source)
1571 (define-key map (kbd "<M-right>") 'anything-next-source))
1572 (delq nil map))
1573 "Keymap for `anything-c-read-file-name'.")
1575 (defvar anything-generic-files-map
1576 (let ((map (copy-keymap anything-map)))
1577 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1578 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1579 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1580 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1581 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1582 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1583 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1584 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1585 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1586 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1587 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1588 map)
1589 "Generic Keymap for files.")
1591 (defvar anything-c-grep-map
1592 (let ((map (copy-keymap anything-map)))
1593 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1594 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1595 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1596 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1597 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1598 (when anything-c-grep-use-ioccur-style-keys
1599 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1600 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1601 (define-key map (kbd "C-c ?") 'anything-grep-help)
1602 (delq nil map))
1603 "Keymap used in Grep sources.")
1605 (defvar anything-c-pdfgrep-map
1606 (let ((map (copy-keymap anything-map)))
1607 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1608 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1609 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1610 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1611 map)
1612 "Keymap used in pdfgrep.")
1614 (defvar anything-c-etags-map
1615 (let ((map (copy-keymap anything-map)))
1616 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1617 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1618 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1619 (define-key map (kbd "C-c ?") 'anything-etags-help)
1620 map)
1621 "Keymap used in Etags.")
1623 (defvar anything-eval-expression-map
1624 (let ((map (copy-keymap anything-map)))
1625 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1626 (define-key map (kbd "<tab>") 'lisp-indent-line)
1627 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1628 (define-key map (kbd "C-p") 'previous-line)
1629 (define-key map (kbd "C-n") 'next-line)
1630 (define-key map (kbd "<up>") 'previous-line)
1631 (define-key map (kbd "<down>") 'next-line)
1632 (define-key map (kbd "<right>") 'forward-char)
1633 (define-key map (kbd "<left>") 'backward-char)
1634 map))
1636 (defvar anything-c-ucs-map
1637 (let ((map (copy-keymap anything-map)))
1638 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1639 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1640 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1641 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1642 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1643 map)
1644 "Keymap for `anything-ucs'.")
1648 ;;; Embeded documentation.
1651 (defun anything-c-list-preconfigured-anything ()
1652 "Collect preconfigured anything functions in this file."
1653 (loop with doc
1654 with sym
1655 for entry in (cdr (assoc
1656 (file-truename (locate-library "anything-config"))
1657 load-history))
1658 if (and (consp entry)
1659 (eq (car entry) 'defun)
1660 (string-match "^Preconfigured.+$"
1661 (setq doc (or (documentation (setq sym (cdr entry)))
1662 ""))))
1663 collect (cons sym (match-string 0 doc))))
1665 (defun anything-c-format-preconfigured-anything ()
1666 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1667 (anything-c-list-preconfigured-anything)))
1669 ;;; Global help message - Used by `anything-help'
1672 (setq anything-help-message
1673 (lambda ()
1674 (concat
1675 "\\<anything-map>"
1676 "`anything' is QuickSilver-like candidate-selection framework.
1678 Narrow the list by typing some pattern,
1679 Multiple patterns are allowed by splitting by space.
1680 Select with natural Emacs operations, choose with RET.
1682 If you have any problems, press C-c C-x C-b!!
1683 Feel free to send bug reports. I'll fix them.
1684 The steps are described in the beginning of anything.el file.
1686 == Basic Operations ==
1687 C-p, Up: Previous Line
1688 C-n, Down : Next Line
1689 M-v, PageUp : Previous Page
1690 C-v, PageDown : Next Page
1691 Enter : Execute first (default) action / Select
1692 M-< : First Line
1693 M-> : Last Line
1694 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1695 M-PageDown, C-M-v : Next Page (other-window)
1697 Tab, C-i : Show action list
1698 Left : Previous Source
1699 Right, C-o : Next Source
1700 C-k : Delete pattern
1701 C-z : Persistent Action (Execute action with anything session kept)
1702 C-c C-x C-b: Send a bug report
1704 == Shortcuts For 2nd/3rd Action ==
1705 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1706 \\[anything-select-3rd-action] : Execute 3rd Action
1708 == Visible Marks ==
1709 Visible marks store candidate. Some actions uses marked candidates.
1711 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1712 \\[anything-prev-visible-mark] : Previous Mark
1713 \\[anything-next-visible-mark] : Next Mark
1715 == Miscellaneous Commands ==
1716 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1717 \\[anything-quit-and-find-file] : Drop into `find-file'
1718 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1719 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1720 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1721 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1722 \\[anything-force-update] : Recalculate And Redisplay Candidates
1724 == Global Commands ==
1725 \\<global-map>\\[anything-resume] revives last `anything' session.
1726 It is very useful, so you should bind any key.
1728 Single source is executed by \\[anything-call-source].
1730 == Preconfigured `anything' ==
1731 Preconfigured `anything' is commands that uses `anything' interface.
1732 You can use them without configuration.
1735 (apply 'concat (anything-c-format-preconfigured-anything))
1737 Enjoy!")))
1739 ;;; `anything-buffer-list' help
1742 ;;;###autoload
1743 (defun anything-c-buffer-help ()
1744 "Help command for anything buffers."
1745 (interactive)
1746 (let ((anything-help-message "== Anything Buffer ==
1747 \nTips:
1748 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1749 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1750 \nSpecific commands for `anything-buffers-list':
1751 \\<anything-c-buffer-map>
1752 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1753 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1754 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1755 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1756 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1757 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1758 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1759 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1760 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1761 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1762 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1763 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1764 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1765 \\[anything-mark-all]\t\t->Mark all.
1766 \\[anything-c-buffer-help]\t\t->Display this help.
1767 \n== Anything Map ==
1768 \\{anything-map}
1770 (anything-help)))
1773 ;;; Find files help (`anything-find-files')
1776 ;;;###autoload
1777 (defun anything-ff-help ()
1778 "Help command for `anything-find-files'."
1779 (interactive)
1780 (let ((anything-help-message "== Anything Find Files ==
1781 \nTips:
1782 \n- Enter `~/' at end of pattern to quickly reach home directory.
1783 - Enter `/' at end of pattern to quickly reach root of your file system.
1784 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1785 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1786 - Use `C-u C-z' to watch an image.
1787 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1788 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1790 \nSpecific commands for `anything-find-files':
1791 \\<anything-find-files-map>
1792 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1793 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1794 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1795 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1796 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1797 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1798 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1799 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1800 \\[anything-ff-run-load-file]\t\t->Load File.
1801 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1802 \\[anything-ff-run-delete-file]\t\t->Delete File.
1803 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1804 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1805 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1806 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1807 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1808 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1809 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1810 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1811 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1812 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1813 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1814 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1815 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1816 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1817 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1818 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1819 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1820 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1821 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1822 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1823 \\[anything-narrow-window]\t\t->Narrow anything window.
1824 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1825 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1826 \\[anything-ff-help]\t\t->Display this help info.
1827 \n== Anything Map ==
1828 \\{anything-map}
1830 (anything-help)))
1832 ;;; Help for `anything-c-read-file-name'
1835 ;;;###autoload
1836 (defun anything-read-file-name-help ()
1837 (interactive)
1838 (let ((anything-help-message "== Anything read file name Map ==\
1839 \nSpecific commands for anything-c-read-file-name:
1840 \\<anything-c-read-file-map>
1841 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1842 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1843 \\[anything-next-source]\t\t->Goto next source.
1844 \\[anything-previous-source]\t->Goto previous source.
1845 \\[anything-read-file-name-help]\t\t->Display this help info.
1846 \n== Anything Map ==
1847 \\{anything-map}
1849 (anything-help)))
1851 ;;; Generic file help - Used by locate.
1854 ;;;###autoload
1855 (defun anything-generic-file-help ()
1856 (interactive)
1857 (let ((anything-help-message "== Anything Generic files Map ==\
1858 \nSpecific commands for anything locate and others files sources:
1859 \\<anything-generic-files-map>
1860 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1861 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1862 \\[anything-ff-run-delete-file]\t\t->Delete file.
1863 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1864 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1865 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1866 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1867 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1868 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1869 \nLocate tips:
1870 You can add after writing search pattern any of the locate command line options.
1871 e.g -b, -e, -n <number>...etc.
1872 See Man locate for more infos.
1873 \n== Anything Map ==
1874 \\{anything-map}"))
1875 (anything-help)))
1878 ;;; Grep help
1881 ;;;###autoload
1882 (defun anything-grep-help ()
1883 (interactive)
1884 (let ((anything-help-message "== Anything Grep Map ==\
1885 \nSpecific commands for Grep and Etags:
1886 \\<anything-c-grep-map>
1887 \\[anything-c-goto-next-file]\t->Next File.
1888 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1889 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1890 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1891 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1892 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1893 \\[anything-grep-help]\t\t->Show this help.
1894 \n== Anything Map ==
1895 \\{anything-map}"))
1896 (anything-help)))
1898 ;;; Pdf grep help
1901 ;;;###autoload
1902 (defun anything-pdfgrep-help ()
1903 (interactive)
1904 (let ((anything-help-message "== Anything PdfGrep Map ==\
1905 \nSpecific commands for Pdf Grep:
1906 \\<anything-c-pdfgrep-map>
1907 \\[anything-c-goto-next-file]\t->Next File.
1908 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1909 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1910 \\[anything-pdfgrep-help]\t\t->Show this help.
1911 \n== Anything Map ==
1912 \\{anything-map}"))
1913 (anything-help)))
1915 ;;; Etags help
1918 ;;;###autoload
1919 (defun anything-etags-help ()
1920 "The help function for etags."
1921 (interactive)
1922 (let ((anything-help-message "== Anything Etags Map ==\
1923 \nSpecific commands for Etags:
1924 \\<anything-c-etags-map>
1925 \\[anything-c-goto-next-file]\t->Next File.
1926 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1927 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1928 \\[anything-etags-help]\t\t->Show this help.
1929 \n== Anything Map ==
1930 \\{anything-map}"))
1931 (anything-help)))
1933 ;;; Ucs help
1936 (defun anything-c-ucs-help ()
1937 "Help command for `anything-ucs'."
1938 (interactive)
1939 (let ((anything-help-message "== Anything Ucs ==
1940 \nSpecific commands for `anything-ucs':
1941 \\<anything-c-ucs-map>
1942 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1943 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1944 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1945 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1946 \\[anything-c-ucs-help]\t\t->Show this help.
1948 \n== Anything Map ==
1949 \\{anything-map}
1951 (anything-help)))
1955 ;;; Mode line strings
1958 (defvar anything-buffer-mode-line-string
1959 '("Buffer(s)"
1960 "\\<anything-c-buffer-map>\
1961 \\[anything-c-buffer-help]:Help, \
1962 \\<anything-map>\
1963 \\[anything-select-action]:Acts,\
1964 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1965 \\[anything-select-3rd-action]:NthAct,\
1966 \\[anything-send-bug-report-from-anything]:BugReport."
1967 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1969 (defvar anything-ff-mode-line-string
1970 "\\<anything-find-files-map>\
1971 \\[anything-ff-help]:Help, \
1972 \\[anything-send-bug-report-from-anything]:BugReport, \
1973 \\<anything-map>\
1974 \\[anything-select-action]:Acts, \
1975 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1976 \\[anything-select-3rd-action]:NthAct"
1977 "String displayed in mode-line in `anything-c-source-find-files'")
1979 (defvar anything-read-file-name-mode-line-string
1980 "\\<anything-c-read-file-map>\
1981 \\[anything-read-file-name-help]:Help, \
1982 \\<anything-map>\
1983 \\[anything-select-action]:Acts,\
1984 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1985 \\[anything-select-3rd-action]:NthAct"
1986 "String displayed in mode-line in `anything-c-source-find-files'")
1988 (defvar anything-generic-file-mode-line-string
1989 "\\<anything-generic-files-map>\
1990 \\[anything-generic-file-help]:Help, \
1991 \\<anything-map>\
1992 \\[anything-select-action]:Acts,\
1993 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1994 \\[anything-select-3rd-action]:NthAct,\
1995 \\[anything-send-bug-report-from-anything]:BugReport."
1996 "String displayed in mode-line in Locate.")
1998 (defvar anything-grep-mode-line-string
1999 "\\<anything-c-grep-map>\
2000 \\[anything-grep-help]:Help,\
2001 \\<anything-map>\
2002 \\[anything-select-action]:Acts,\
2003 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2004 \\[anything-select-3rd-action]:NthAct,\
2005 \\[anything-send-bug-report-from-anything]:BugReport."
2006 "String displayed in mode-line in `anything-do-grep'.")
2008 (defvar anything-pdfgrep-mode-line-string
2009 "\\<anything-c-pdfgrep-map>\
2010 \\[anything-pdfgrep-help]:Help,\
2011 \\<anything-map>\
2012 \\[anything-select-action]:Acts,\
2013 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2014 \\[anything-select-3rd-action]:NthAct,\
2015 \\[anything-send-bug-report-from-anything]:BugReport."
2016 "String displayed in mode-line in `anything-do-pdfgrep'.")
2018 (defvar anything-etags-mode-line-string
2019 "\\<anything-c-etags-map>\
2020 \\[anything-etags-help]:Help,\
2021 \\<anything-map>\
2022 \\[anything-select-action]:Acts,\
2023 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2024 \\[anything-select-3rd-action]:NthAct,\
2025 \\[anything-send-bug-report-from-anything]:BugReport."
2026 "String displayed in mode-line in `anything-c-etags-select'.")
2029 (defvar anything-c-ucs-mode-line-string
2030 "\\<anything-c-ucs-map>\
2031 \\[anything-c-ucs-help]:Help, \
2032 \\<anything-map>\
2033 \\[anything-select-action]:Acts,\
2034 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2035 \\[anything-select-3rd-action]:NthAct."
2036 "String displayed in mode-line in `anything-ucs'.")
2040 ;;; Utilities Functions
2043 (defun anything-ff-find-printers ()
2044 "Return a list of available printers on Unix systems."
2045 (let ((printer-list (with-temp-buffer
2046 (call-process "lpstat" nil t nil "-a")
2047 (split-string (buffer-string) "\n"))))
2048 (loop for p in printer-list
2049 for printer = (car (split-string p))
2050 when printer
2051 collect printer)))
2053 ;; Shut up byte compiler in emacs24*.
2054 (defun anything-c-switch-to-buffer (buffer-or-name)
2055 "Same as `switch-to-buffer' whithout warnings at compile time."
2056 (with-no-warnings
2057 (switch-to-buffer buffer-or-name)))
2059 (defsubst* anything-c-position (item seq &key (test 'eq))
2060 "A simple and faster replacement of CL `position'."
2061 (loop for i in seq for index from 0
2062 when (funcall test i item) return index))
2064 (defun anything-c-get-pid-from-process-name (process-name)
2065 "Get pid from running process PROCESS-NAME."
2066 (loop with process-list = (list-system-processes)
2067 for pid in process-list
2068 for process = (assoc-default 'comm (process-attributes pid))
2069 when (and process (string-match process-name process))
2070 return pid))
2072 (defun* anything-current-buffer-narrowed-p (&optional
2073 (buffer anything-current-buffer))
2074 "Check if BUFFER is narrowed.
2075 Default is `anything-current-buffer'."
2076 (with-current-buffer buffer
2077 (let ((beg (point-min))
2078 (end (point-max))
2079 (total (buffer-size)))
2080 (or (/= beg 1) (/= end (1+ total))))))
2082 (defun anything-region-active-p ()
2083 (and transient-mark-mode mark-active (/= (mark) (point))))
2085 (defun anything-goto-line (lineno)
2086 "Goto LINENO opening only outline headline if needed."
2087 (goto-char (point-min)) (forward-line (1- lineno))
2088 (when (or (eq major-mode 'org-mode)
2089 (and (boundp 'outline-minor-mode)
2090 outline-minor-mode))
2091 (require 'org) ; On some old Emacs versions org may not be loaded.
2092 (org-reveal))
2093 (anything-match-line-color-current-line) (sit-for 0.3)
2094 (anything-match-line-cleanup))
2096 (defun anything-show-this-source-only ()
2097 "Show all candidates of this source."
2098 (interactive)
2099 (setq anything-candidate-number-limit nil)
2100 (anything-set-source-filter
2101 (list (assoc-default 'name (anything-get-current-source)))))
2103 ;;;###autoload
2104 (defun anything-test-sources ()
2105 "List all anything sources for test.
2106 The output is sexps which are evaluated by \\[eval-last-sexp]."
2107 (interactive)
2108 (with-output-to-temp-buffer "*Anything Test Sources*"
2109 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2110 (apropos-internal "^anything-c-source" #'boundp))
2111 (pop-to-buffer standard-output)))
2113 (defun anything-nest (&rest same-as-anything)
2114 "Nested `anything'. If you use `anything' within `anything', use it."
2115 (with-selected-window (anything-window)
2116 (let (anything-current-position
2117 anything-current-buffer
2118 (orig-anything-buffer anything-buffer)
2119 anything-pattern
2120 anything-buffer
2121 anything-sources
2122 anything-compiled-sources
2123 anything-buffer-chars-modified-tick
2124 (anything-samewindow t)
2125 (enable-recursive-minibuffers t))
2126 (unwind-protect
2127 (apply #'anything same-as-anything)
2128 (anything-initialize-overlays orig-anything-buffer)
2129 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2131 (defun anything-displaying-source-names ()
2132 "Display sources name."
2133 (with-current-buffer anything-buffer
2134 (goto-char (point-min))
2135 (loop with pos
2136 while (setq pos (next-single-property-change (point) 'anything-header))
2137 do (goto-char pos)
2138 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2139 do (forward-line 1))))
2141 ;; [Obsolete]
2142 (defun anything-select-source ()
2143 "[OBSOLETE] Select source."
2144 (interactive)
2145 (let ((default (assoc-default 'name (anything-get-current-source)))
2146 (source-names (anything-displaying-source-names))
2147 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2148 (anything-get-sources))))
2149 (setq anything-candidate-number-limit 9999)
2150 (anything-aif
2151 (let (anything-source-filter)
2152 (anything-nest '(((name . "Anything Source")
2153 (candidates . source-names)
2154 (action . identity))
2155 ((name . "Anything Source (ALL)")
2156 (candidates . all-source-names)
2157 (action . identity)))
2158 nil "Source: " nil
2159 default "*anything select source*"))
2160 (anything-set-source-filter (list it))
2161 (anything-set-source-filter nil))))
2163 (defun anything-c-match-on-file-name (candidate)
2164 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2165 (string-match anything-pattern (file-name-nondirectory candidate)))
2167 (defun anything-c-match-on-directory-name (candidate)
2168 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2169 (anything-aif (file-name-directory candidate)
2170 (string-match anything-pattern it)))
2172 (defun anything-c-match-on-basename (candidate)
2173 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2174 (string-match anything-pattern (anything-c-basename candidate)))
2176 (defun anything-c-string-match (candidate)
2177 "Return non-nil if `anything-pattern' match CANDIDATE.
2178 The match is done with `string-match'."
2179 (string-match anything-pattern candidate))
2181 (defun anything-c-skip-entries (list regexp)
2182 "Remove entries which matches REGEXP from LIST."
2183 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2184 list))
2186 (defun anything-c-shadow-entries (list regexp)
2187 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2188 (mapcar (lambda (file)
2189 ;; Add shadow face property to boring files.
2190 (let ((face (if (facep 'file-name-shadow)
2191 'file-name-shadow
2192 ;; fall back to default on XEmacs
2193 'default)))
2194 (if (string-match regexp file)
2195 (setq file (propertize file 'face face))))
2196 file)
2197 list))
2199 (defsubst anything-c-stringify (str-or-sym)
2200 "Get string of STR-OR-SYM."
2201 (if (stringp str-or-sym)
2202 str-or-sym
2203 (symbol-name str-or-sym)))
2205 (defsubst anything-c-symbolify (str-or-sym)
2206 "Get symbol of STR-OR-SYM."
2207 (if (symbolp str-or-sym)
2208 str-or-sym
2209 (intern str-or-sym)))
2211 (defun anything-c-describe-function (func)
2212 "FUNC is symbol or string."
2213 (describe-function (anything-c-symbolify func)))
2215 (defun anything-c-describe-variable (var)
2216 "VAR is symbol or string."
2217 (describe-variable (anything-c-symbolify var)))
2219 (defun anything-c-find-function (func)
2220 "FUNC is symbol or string."
2221 (find-function (anything-c-symbolify func)))
2223 (defun anything-c-find-variable (var)
2224 "VAR is symbol or string."
2225 (find-variable (anything-c-symbolify var)))
2227 (defun anything-c-kill-new (candidate &optional replace)
2228 "CANDIDATE is symbol or string.
2229 See `kill-new' for argument REPLACE."
2230 (kill-new (anything-c-stringify candidate) replace))
2232 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2233 "Remove duplicates elements in list SEQ.
2234 This is same as `remove-duplicates' but with memoisation.
2235 It is much faster, especially in large lists.
2236 A test function can be provided with TEST argument key.
2237 Default is `eq'."
2238 (let ((cont (make-hash-table :test test)))
2239 (loop for elm in seq
2240 unless (gethash elm cont)
2241 do (puthash elm elm cont)
2242 finally return
2243 (loop for i being the hash-values in cont collect i))))
2245 (defadvice eval-defun (after anything-source-hack activate)
2246 "Allow immediate execution of anything source when evaling it.
2247 See `anything-c-enable-eval-defun-hack'."
2248 (when anything-c-enable-eval-defun-hack
2249 (let ((varsym (save-excursion
2250 (beginning-of-defun)
2251 (forward-char 1)
2252 (when (memq (read (current-buffer)) '(defvar setq))
2253 (read (current-buffer))))))
2254 (when (string-match "^anything-c-source-" (symbol-name varsym))
2255 (anything varsym)))))
2256 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2259 ;; Move this function from anything.el and redefine here
2260 ;; to avoid an unneeded defadvice.
2261 (defun anything-quit-and-find-file ()
2262 "Drop into `anything-find-files' from `anything'.
2263 If current selection is a buffer or a file, `anything-find-files'
2264 from its directory."
2265 (interactive)
2266 (anything-run-after-quit
2267 (lambda (f)
2268 (if (file-exists-p f)
2269 (anything-find-files-1 (file-name-directory f)
2270 (if anything-ff-transformer-show-only-basename
2271 (anything-c-basename f) f))
2272 (anything-find-files-1 f)))
2273 (anything-aif (get-buffer (anything-get-selection))
2274 (or (buffer-file-name it)
2275 (car (rassoc it dired-buffers))
2276 (and (with-current-buffer it
2277 (eq major-mode 'org-agenda-mode))
2278 org-directory
2279 (expand-file-name org-directory))
2280 default-directory)
2281 (let ((sel (anything-get-selection)))
2282 (if (file-exists-p sel)
2283 (expand-file-name sel)
2284 default-directory)))))
2287 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2288 "Walk through DIRECTORY tree.
2289 PATH can be one of basename, relative, or full.
2290 DIRECTORIES when non--nil (default) return also directories names, otherwise
2291 skip directories names.
2292 MATCH match only filenames matching regexp MATCH."
2293 `(let (result
2294 (fn (case ,path
2295 (basename 'file-name-nondirectory)
2296 (relative 'file-relative-name)
2297 (full 'identity)
2298 (t 'file-name-nondirectory))))
2299 (labels ((ls-R (dir)
2300 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2301 for f in ls
2302 if (file-directory-p f)
2303 do (progn (when ,directories
2304 (push (funcall fn f) result))
2305 ;; Don't recurse in directory symlink.
2306 (unless (file-symlink-p f)
2307 (ls-R f)))
2308 else do
2309 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2310 (push (funcall fn f) result)))))
2311 (ls-R ,directory)
2312 (nreverse result))))
2314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2316 ;;; Anything regexp.
2319 (defun anything-c-query-replace-regexp (candidate)
2320 "Query replace regexp from `anything-regexp'.
2321 With a prefix arg replace only matches surrounded by word boundaries,
2322 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2323 (let ((regexp (funcall (anything-attr 'regexp))))
2324 (apply 'query-replace-regexp
2325 (anything-c-query-replace-args regexp))))
2327 (defun anything-c-kill-regexp-as-sexp (candidate)
2328 "Kill regexp in a format usable in lisp code."
2329 (anything-c-regexp-kill-new
2330 (prin1-to-string (funcall (anything-attr 'regexp)))))
2332 (defun anything-c-kill-regexp (candidate)
2333 "Kill regexp as it is in `anything-pattern'."
2334 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2336 (defun anything-c-query-replace-args (regexp)
2337 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2338 (let ((region-only (anything-region-active-p)))
2339 (list
2340 regexp
2341 (query-replace-read-to regexp
2342 (format "Query replace %sregexp %s"
2343 (if anything-current-prefix-arg "word " "")
2344 (if region-only "in region " ""))
2346 anything-current-prefix-arg
2347 (when region-only (region-beginning))
2348 (when region-only (region-end)))))
2350 (defvar anything-c-source-regexp
2351 '((name . "Regexp Builder")
2352 (init . (lambda ()
2353 (anything-candidate-buffer anything-current-buffer)))
2354 (candidates-in-buffer)
2355 (get-line . anything-c-regexp-get-line)
2356 (persistent-action . anything-c-regexp-persistent-action)
2357 (persistent-help . "Show this line")
2358 (multiline)
2359 (delayed)
2360 (requires-pattern . 2)
2361 (mode-line . "Press TAB to select action.")
2362 (regexp . (lambda () anything-input))
2363 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2364 ("Query Replace Regexp (C-u Not inside word.)"
2365 . anything-c-query-replace-regexp)
2366 ("Kill Regexp" . anything-c-kill-regexp)))))
2368 (defun anything-c-regexp-get-line (s e)
2369 (propertize
2370 (apply 'concat
2371 ;; Line contents
2372 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2373 ;; subexps
2374 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2375 collect (format "\n %s'%s'"
2376 (if (zerop i) "Group 0: " (format "Group %d: " i))
2377 (match-string i))))
2378 ;; match beginning
2379 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2380 ;; It is implementation problem of candidates-in-buffer.
2381 'anything-realvalue
2382 (1- s)))
2384 (defun anything-c-regexp-persistent-action (pt)
2385 (goto-char pt)
2386 (anything-persistent-highlight-point))
2388 (defun anything-c-regexp-kill-new (input)
2389 (kill-new input)
2390 (message "Killed: %s" input))
2394 ;;; Toggle all marks.
2397 ;;;###autoload
2398 (defun anything-mark-all ()
2399 "Mark all visible unmarked candidates in current source."
2400 (interactive)
2401 (with-anything-window
2402 (save-excursion
2403 (goto-char (anything-get-previous-header-pos))
2404 (anything-next-line)
2405 (let* ((next-head (anything-get-next-header-pos))
2406 (end (and next-head
2407 (save-excursion
2408 (goto-char next-head)
2409 (forward-line -1)
2410 (point))))
2411 (maxpoint (or end (point-max))))
2412 (while (< (point) maxpoint)
2413 (anything-mark-current-line)
2414 (let ((prefix (get-text-property (point-at-bol) 'display))
2415 (bn (anything-c-basename (anything-get-selection)))
2416 (src (assoc-default 'name (anything-get-current-source))))
2417 (when (and (not (anything-this-visible-mark))
2418 (not (or (string= prefix "[?]")
2419 (string= prefix "[@]"))))
2420 ;; Don't mark possibles directories ending with . or ..
2421 ;; and also autosave files/links.
2422 (unless
2423 (and (or (anything-file-completion-source-p)
2424 (equal src "Files from Current Directory"))
2425 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2426 (anything-make-visible-mark))))
2427 (forward-line 1) (end-of-line))))
2428 (anything-mark-current-line)
2429 (message "%s candidates marked" (length anything-marked-candidates))))
2431 ;;;###autoload
2432 (defun anything-unmark-all ()
2433 "Unmark all candidates in all sources of current anything session."
2434 (interactive)
2435 (with-anything-window
2436 (let ((len (length anything-marked-candidates)))
2437 (save-excursion
2438 (anything-clear-visible-mark))
2439 (setq anything-marked-candidates nil)
2440 (anything-mark-current-line)
2441 (message "%s candidates unmarked" len))))
2443 ;;;###autoload
2444 (defun anything-toggle-all-marks ()
2445 "Toggle all marks.
2446 Mark all visible candidates of current source or unmark all candidates
2447 visible or invisible in all sources of current anything session"
2448 (interactive)
2449 (let ((marked (anything-marked-candidates)))
2450 (if (and (>= (length marked) 1)
2451 (with-anything-window anything-visible-mark-overlays))
2452 (anything-unmark-all)
2453 (anything-mark-all))))
2457 ;;; Buffers
2460 (defun anything-c-buffer-list ()
2461 "Return the list of names of buffers with boring buffers filtered out.
2462 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2463 The first buffer in the list will be the last recently used
2464 buffer that is not the current buffer."
2465 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2466 (append (cdr buffers) (list (car buffers)))))
2468 (defvar anything-c-source-buffers
2469 '((name . "Buffers")
2470 (candidates . anything-c-buffer-list)
2471 (type . buffer)))
2472 ;; (anything 'anything-c-source-buffers)
2474 (defvar anything-c-source-buffer-not-found
2475 '((name . "Create buffer")
2476 (dummy)
2477 (filtered-candidate-transformer (lambda (cands source)
2478 (list anything-pattern)))
2479 (action . (lambda (candidate)
2480 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2481 ;; (anything 'anything-c-source-buffer-not-found)
2483 ;;; Buffers-list (was buffers+)
2486 (eval-when-compile (require 'dired))
2488 (defun anything-c-highlight-buffers (buffers)
2489 (loop for i in buffers
2490 for buf = (get-buffer i)
2491 for bfname = (buffer-file-name buf)
2492 collect
2493 (cond (;; A dired buffer.
2494 (rassoc buf dired-buffers)
2495 (propertize i 'face 'anything-ff-directory
2496 'help-echo (car (rassoc buf dired-buffers))))
2497 ;; A buffer file modified somewhere outside of emacs.
2498 ((and bfname (not (file-remote-p bfname))
2499 (file-exists-p bfname)
2500 (not (verify-visited-file-modtime buf)))
2501 (propertize i 'face 'anything-buffer-saved-out
2502 'help-echo bfname))
2503 ;; A new buffer file not already saved on disk.
2504 ((and bfname (not (file-remote-p bfname))
2505 (not (verify-visited-file-modtime buf)))
2506 (propertize i 'face 'anything-buffer-not-saved
2507 'help-echo bfname))
2508 ;; A Remote buffer file modified and not saved on disk.
2509 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2510 (let ((prefix (propertize
2511 " " 'display
2512 (propertize "@ " 'face 'anything-ff-prefix))))
2513 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2514 'help-echo bfname)) i)))
2515 ;; A buffer file modified and not saved on disk.
2516 ((and bfname (buffer-modified-p buf))
2517 (propertize i 'face 'anything-ff-symlink
2518 'help-echo bfname))
2519 ;; A remote buffer file not modified and saved on disk.
2520 ((and bfname (file-remote-p bfname))
2521 (let ((prefix (propertize
2522 " " 'display
2523 (propertize "@ " 'face 'anything-ff-prefix))))
2524 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2525 'help-echo bfname)) i)))
2526 ;; A buffer file not modified and saved on disk.
2527 (bfname
2528 (propertize i 'face 'font-lock-type-face
2529 'help-echo bfname))
2530 ;; Any non--file buffer.
2531 (t (propertize i 'face 'italic)))))
2534 (defvar anything-c-source-buffers-list
2535 '((name . "Buffers")
2536 (candidates . anything-c-buffer-list)
2537 (type . buffer)
2538 (match anything-c-buffer-match-major-mode)
2539 (diff-action . anything-buffer-toggle-diff)
2540 (revert-action . anything-buffer-revert-and-update)
2541 (save-action . anything-buffer-save-and-update)
2542 (candidate-transformer anything-c-skip-current-buffer
2543 anything-c-skip-boring-buffers
2544 anything-c-highlight-buffers)
2545 (persistent-action . anything-c-buffers-list-persistent-action)
2546 (volatile)
2547 (mode-line . anything-buffer-mode-line-string)
2548 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2549 ;; (anything 'anything-c-source-buffers-list)
2551 (defun anything-c-buffer-match-major-mode (candidate)
2552 "Match maybe buffer by major-mode.
2553 If you give a major-mode or partial major-mode,
2554 it will list all buffers of this major-mode and/or buffers with name
2555 matching this major-mode.
2556 If you add a space after major-mode and then a space,
2557 it will match all buffers of the major-mode
2558 before space matching pattern after space.
2559 If you give a pattern which doesn't match a major-mode, it will search buffer
2560 with name matching pattern."
2561 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2562 (buf (get-buffer cand)))
2563 (when buf
2564 (with-current-buffer buf
2565 (let ((mjm (symbol-name major-mode))
2566 (split (split-string anything-pattern)))
2567 (cond ((string-match "\\s-$" anything-pattern)
2568 (string-match (car split) mjm))
2569 ((string-match "\\s-" anything-pattern)
2570 (and (string-match (car split) mjm)
2571 (string-match (cadr split) cand)))
2572 (t (or (string-match anything-pattern mjm)
2573 (string-match anything-pattern cand)))))))))
2575 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2576 "Query replace in marked buffers.
2577 If REGEXP-FLAG is given use `query-replace-regexp'."
2578 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2579 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2580 (bufs (anything-marked-candidates)))
2581 (loop
2582 with replace = (query-replace-read-from prompt regexp-flag)
2583 with tostring = (unless (consp replace)
2584 (query-replace-read-to
2585 replace prompt regexp-flag))
2586 for buf in bufs
2588 (save-window-excursion
2589 (anything-c-switch-to-buffer buf)
2590 (save-excursion
2591 (let ((case-fold-search t))
2592 (goto-char (point-min))
2593 (if (consp replace)
2594 (apply fn (list (car replace) (cdr replace)))
2595 (apply fn (list replace tostring)))))))))
2597 (defun anything-c-buffer-query-replace-regexp (candidate)
2598 (anything-c-buffer-query-replace-1 'regexp))
2600 (defun anything-c-buffer-query-replace (candidate)
2601 (anything-c-buffer-query-replace-1))
2603 (defun anything-buffer-toggle-diff (candidate)
2604 "Toggle diff buffer CANDIDATE with it's file."
2605 (if (get-buffer-window "*Diff*")
2606 (kill-buffer "*Diff*")
2607 (diff-buffer-with-file (get-buffer candidate))))
2609 ;;;###autoload
2610 (defun anything-buffer-diff-persistent ()
2611 "Toggle diff buffer without quitting anything."
2612 (interactive)
2613 (anything-execute-persistent-action 'diff-action))
2615 (defun anything-buffer-revert-and-update (candidate)
2616 (let ((marked (anything-marked-candidates)))
2617 (loop for buf in marked do (anything-revert-buffer buf))
2618 (anything-force-update)
2619 (anything-c-recenter-window)))
2621 ;;;###autoload
2622 (defun anything-buffer-revert-persistent ()
2623 "Revert buffer without quitting anything."
2624 (interactive)
2625 (anything-execute-persistent-action 'revert-action 'onewindow))
2627 (defun anything-buffer-save-and-update (candidate)
2628 (let ((marked (anything-marked-candidates))
2629 (enable-recursive-minibuffers t))
2630 (loop for buf in marked do
2631 (with-current-buffer (get-buffer buf)
2632 (save-buffer)))
2633 (anything-force-update)
2634 (anything-c-recenter-window)))
2636 ;;;###autoload
2637 (defun anything-buffer-save-persistent ()
2638 "Save buffer without quitting anything."
2639 (interactive)
2640 (anything-execute-persistent-action 'save-action 'onewindow))
2642 ;;;###autoload
2643 (defun anything-buffer-run-kill-buffers ()
2644 "Run kill buffer action from `anything-c-source-buffers-list'."
2645 (interactive)
2646 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2648 ;;;###autoload
2649 (defun anything-buffer-run-grep ()
2650 "Run Grep action from `anything-c-source-buffers-list'."
2651 (interactive)
2652 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2654 ;;;###autoload
2655 (defun anything-buffer-run-zgrep ()
2656 "Run Grep action from `anything-c-source-buffers-list'."
2657 (interactive)
2658 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2660 ;;;###autoload
2661 (defun anything-buffer-run-query-replace-regexp ()
2662 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2663 (interactive)
2664 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2666 ;;;###autoload
2667 (defun anything-buffer-run-query-replace ()
2668 "Run Query replace action from `anything-c-source-buffers-list'."
2669 (interactive)
2670 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2672 ;;;###autoload
2673 (defun anything-buffer-switch-other-window ()
2674 "Run switch to other window action from `anything-c-source-buffers-list'."
2675 (interactive)
2676 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2678 ;;;###autoload
2679 (defun anything-buffer-switch-other-frame ()
2680 "Run switch to other frame action from `anything-c-source-buffers-list'."
2681 (interactive)
2682 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2684 ;;;###autoload
2685 (defun anything-buffer-switch-to-elscreen ()
2686 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2687 (interactive)
2688 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2690 ;;;###autoload
2691 (defun anything-buffer-run-ediff ()
2692 "Run ediff action from `anything-c-source-buffers-list'."
2693 (interactive)
2694 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2696 (defun anything-buffer-run-ediff-merge ()
2697 "Run ediff action from `anything-c-source-buffers-list'."
2698 (interactive)
2699 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2701 (defun anything-c-buffers-persistent-kill (buffer)
2702 "Persistent action to kill buffer."
2703 (with-current-buffer (get-buffer buffer)
2704 (if (and (buffer-modified-p)
2705 (buffer-file-name (current-buffer)))
2706 (progn
2707 (save-buffer)
2708 (kill-buffer buffer))
2709 (kill-buffer buffer)))
2710 (anything-delete-current-selection))
2712 (defun anything-c-recenter-window ()
2713 "Make visible current selection by recentering anything window."
2714 (with-anything-window (recenter)))
2716 (defun anything-c-buffers-list-persistent-action (candidate)
2717 (if current-prefix-arg
2718 (anything-c-buffers-persistent-kill candidate)
2719 (anything-c-switch-to-buffer candidate)))
2722 ;;;; <File>
2725 ;;; File name history
2726 (defvar anything-c-source-file-name-history
2727 '((name . "File Name History")
2728 (candidates . file-name-history)
2729 (match anything-c-match-on-basename)
2730 (type . file)))
2731 ;; (anything 'anything-c-source-file-name-history)
2733 ;;; Files in current dir
2736 (defvar anything-c-source-files-in-current-dir
2737 '((name . "Files from Current Directory")
2738 (candidates . (lambda ()
2739 (with-anything-current-buffer
2740 (directory-files (anything-c-current-directory)))))
2741 ;; volatile is not needed, I think.
2742 (type . file)))
2743 ;; (anything 'anything-c-source-files-in-current-dir)
2745 (defun anything-c-highlight-files (files)
2746 (loop for i in files
2747 if (file-directory-p i)
2748 collect (propertize (file-name-nondirectory i)
2749 'face 'anything-ff-directory
2750 'help-echo (expand-file-name i))
2751 else
2752 collect (propertize (file-name-nondirectory i)
2753 'face 'anything-ff-file
2754 'help-echo (expand-file-name i))))
2756 (defvar anything-c-source-files-in-current-dir+
2757 '((name . "Files from Current Directory")
2758 (candidates . (lambda ()
2759 (with-anything-current-buffer
2760 (directory-files (anything-c-current-directory) t))))
2761 (candidate-transformer anything-c-highlight-files)
2762 ;; volatile is not needed, I think.
2763 (type . file)))
2764 ;; (anything 'anything-c-source-files-in-current-dir+)
2768 ;;; Anything-find-files - The anything files browser.
2771 ;; Internal.
2772 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2773 "*The doc that is inserted in the Name header of a find-files or dired source.")
2774 (defvar anything-ff-auto-update-flag nil
2775 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2776 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2777 (defvar anything-ff-last-expanded nil
2778 "Store last expanded directory or file.")
2779 (defvar anything-ff-default-directory nil)
2780 (defvar anything-ff-history nil)
2781 (defvar anything-ff-cand-to-mark nil)
2784 (defvar anything-c-source-find-files
2785 `((name . "Find Files")
2786 (header-name . (lambda (name)
2787 (concat name anything-c-find-files-doc-header)))
2788 ;; It is needed for filenames with capital letters
2789 (disable-shortcuts)
2790 (init . (lambda ()
2791 (setq anything-ff-auto-update-flag
2792 anything-ff-auto-update-initial-value)))
2793 (candidates . anything-find-files-get-candidates)
2794 (filtered-candidate-transformer anything-c-find-files-transformer)
2795 (image-action1 . anything-ff-rotate-image-left)
2796 (image-action2 . anything-ff-rotate-image-right)
2797 (toggle-basename . anything-ff-toggle-basename)
2798 (properties-action . anything-ff-properties)
2799 (toggle-auto-update . anything-ff-toggle-auto-update)
2800 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2801 (persistent-action . anything-find-files-persistent-action)
2802 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2803 (mode-line . anything-ff-mode-line-string)
2804 (volatile)
2805 (candidate-number-limit . 9999)
2806 (action-transformer . anything-find-files-action-transformer)
2807 (action
2808 . ,(delq
2810 `(("Find File" . anything-c-find-file-or-marked)
2811 ("Find file in Dired" . anything-c-point-file-in-dired)
2812 ,(and (locate-library "elscreen")
2813 '("Find file in Elscreen" . anything-elscreen-find-file))
2814 ,(and (locate-library "popwin")
2815 '("Find file in popup window" . popwin:find-file))
2816 ("Checksum File" . anything-ff-checksum)
2817 ("Complete at point `M-tab'"
2818 . anything-c-insert-file-name-completion-at-point)
2819 ("Open file externally `C-c C-x, C-u to choose'"
2820 . anything-c-open-file-externally)
2821 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2822 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2823 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2824 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2825 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2826 . anything-find-files-eshell-command-on-file)
2827 ("Find file as root" . anything-find-file-as-root)
2828 ("Find file in hex dump" . hexl-find-file)
2829 ("Ediff File `C-='" . anything-find-files-ediff-files)
2830 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2831 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2832 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2833 ("Copy file(s) Async" . anything-ff-copy-async)
2834 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2835 ("Serial rename files" . anything-ff-serial-rename)
2836 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2837 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2838 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2839 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2840 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2841 ("Find file other window `C-o'" . find-file-other-window)
2842 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2843 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2844 ("Print File `C-c p'" . anything-ff-print)
2845 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2846 ;; (anything 'anything-c-source-find-files)
2848 (defun anything-find-files-set-prompt-for-action (prompt files)
2849 "Set prompt for action in `anything-find-files'."
2850 (let ((len (length files)))
2851 (if (> len 1)
2852 (format "%s * %d Files to: " prompt len)
2853 (format "%s %s to: " prompt (car files)))))
2855 (defun anything-dwim-target-directory ()
2856 "Return value of `default-directory' of buffer in other window.
2857 If there is only one window return the value ot `default-directory'
2858 for current buffer."
2859 (with-anything-current-buffer
2860 (let ((num-windows (length (window-list))))
2861 (if (> num-windows 1)
2862 (save-window-excursion
2863 (other-window 1)
2864 default-directory)
2865 (car anything-ff-history)))))
2867 (defun anything-find-files-do-action (action)
2868 "Generic function for creating action from `anything-c-source-find-files'.
2869 ACTION must be an action supported by `anything-dired-action'."
2870 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2871 (anything-marked-candidates)))
2872 (cand (anything-get-selection)) ; Target
2873 (prompt (anything-find-files-set-prompt-for-action
2874 (capitalize (symbol-name action)) ifiles))
2875 (parg anything-current-prefix-arg)
2876 (dest (anything-c-read-file-name
2877 prompt
2878 :preselect (if anything-ff-transformer-show-only-basename
2879 (anything-c-basename cand) cand)
2880 :initial-input (anything-dwim-target-directory)
2881 :history (anything-find-files-history :comp-read nil)))
2882 (win-conf (current-window-configuration)))
2883 (unwind-protect
2884 (let ((default-directory anything-ff-default-directory))
2885 (anything-dired-action
2886 dest :files ifiles :action action :follow parg))
2887 ;; Don't reset win-conf when following.
2888 (unless parg (set-window-configuration win-conf)))))
2890 (defun anything-find-files-copy (candidate)
2891 "Copy files from `anything-find-files'."
2892 (anything-find-files-do-action 'copy))
2894 (defun anything-find-files-rename (candidate)
2895 "Rename files from `anything-find-files'."
2896 (anything-find-files-do-action 'rename))
2898 (defun anything-find-files-symlink (candidate)
2899 "Symlink files from `anything-find-files'."
2900 (anything-find-files-do-action 'symlink))
2902 (defun anything-find-files-relsymlink (candidate)
2903 "Relsymlink files from `anything-find-files'."
2904 (anything-find-files-do-action 'relsymlink))
2906 (defun anything-find-files-hardlink (candidate)
2907 "Hardlink files from `anything-find-files'."
2908 (anything-find-files-do-action 'hardlink))
2910 (defun anything-find-files-byte-compile (candidate)
2911 "Byte compile elisp files from `anything-find-files'."
2912 (let ((files (anything-marked-candidates))
2913 (parg anything-current-prefix-arg))
2914 (loop for fname in files
2915 do (byte-compile-file fname parg))))
2917 (defun anything-find-files-load-files (candidate)
2918 "Load elisp files from `anything-find-files'."
2919 (let ((files (anything-marked-candidates)))
2920 (loop for fname in files
2921 do (load fname))))
2923 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2924 "Generic function to ediff/merge files in `anything-find-files'."
2925 (let ((bname (anything-c-basename candidate))
2926 (prompt (if merge "Ediff Merge `%s' With File: "
2927 "Ediff `%s' With File: "))
2928 (fun (if merge 'ediff-merge-files 'ediff-files)))
2929 (funcall fun
2930 candidate
2931 (condition-case quit
2932 (anything-c-read-file-name
2933 (format prompt bname))
2934 (quit ;; Hit C-g ask user to fallback to locate.
2935 (if (y-or-n-p "Search file for ediff with locate? ")
2936 (anything-c-locate-read-file-name
2937 (format prompt bname)
2938 ;; Check if -b option is available.
2939 (if (and (eq system-type 'windows-nt)
2940 (string-match "^es" anything-c-locate-command))
2941 bname
2942 (concat bname " -b")))
2943 (error "Error: Ediff Operation aborted")))))))
2945 (defun anything-find-files-ediff-files (candidate)
2946 (anything-find-files-ediff-files-1 candidate))
2948 (defun anything-find-files-ediff-merge-files (candidate)
2949 (anything-find-files-ediff-files-1 candidate 'merge))
2951 (defun anything-find-files-grep (candidate)
2952 "Default action to grep files from `anything-find-files'."
2953 (anything-do-grep-1 (anything-marked-candidates)
2954 anything-current-prefix-arg))
2956 (defun anything-ff-zgrep (candidate)
2957 "Default action to zgrep files from `anything-find-files'."
2958 (let ((prefarg anything-current-prefix-arg)
2959 (ls (anything-marked-candidates)))
2960 (anything-ff-zgrep-1 ls prefarg)))
2962 (defun anything-ff-pdfgrep (candidate)
2963 "Default action to pdfgrep files from `anything-find-files'."
2964 (let ((cands (loop for file in (anything-marked-candidates)
2965 if (or (string= (file-name-extension file) "pdf")
2966 (string= (file-name-extension file) "PDF"))
2967 collect file))
2968 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2969 (when cands
2970 (anything-do-pdfgrep-1 cands))))
2972 (defun anything-ff-etags-select (candidate)
2973 "Default action to jump to etags from `anything-find-files'."
2974 (when (get-buffer anything-action-buffer)
2975 (kill-buffer anything-action-buffer))
2976 (let ((default-directory anything-ff-default-directory))
2977 (anything-c-etags-select anything-current-prefix-arg)))
2979 (defun anything-find-files-switch-to-hist (candidate)
2980 "Switch to anything-find-files history."
2981 (anything-find-files t))
2983 ;;; Asynchronous copy of files.
2986 (defun anything-c-copy-files-async-1 (flist dest)
2987 "Copy a list of Files FLIST to DEST asynchronously.
2988 It use another emacs process to do the job.
2989 Communication with background emacs is done with temp file
2990 `anything-c-copy-files-async-log-file'."
2991 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
2992 "-Q" "--batch" "--eval"
2993 (format "(progn
2994 (require 'dired) (require 'cl)
2995 (let ((dired-recursive-copies 'always)
2996 failures success
2997 (ovw-count 0)
2998 (cpf-count 0))
2999 (dolist (f '%S)
3000 (condition-case err
3001 (let ((file-exists (file-exists-p
3002 (expand-file-name
3003 (file-name-nondirectory (directory-file-name f))
3004 (file-name-directory
3005 (file-name-as-directory \"%s\"))))))
3006 (dired-copy-file f \"%s\" t)
3007 (if file-exists
3008 (progn (push (cons \"Overwriting\" f) success)
3009 (incf ovw-count))
3010 (push (cons \"Copying\" f) success)
3011 (incf cpf-count)))
3012 (file-error
3013 (push (dired-make-relative
3014 (expand-file-name
3015 (file-name-nondirectory (directory-file-name f))
3016 (file-name-directory \"%s\")))
3017 failures))))
3018 (with-current-buffer (find-file-noselect \"%s\")
3019 (erase-buffer)
3020 (when failures
3021 (dolist (fail (reverse failures))
3022 (insert (concat \"Failed to copy \" fail \"\n\"))))
3023 (when success
3024 (loop for (a . s) in (reverse success) do
3025 (insert (concat a \" \" s \" to %s done\n\"))))
3026 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3027 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3028 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3029 (save-buffer))))"
3030 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3032 (defun anything-c-copy-async-with-log (flist dest)
3033 "Copy file list FLIST to DEST showing log.
3034 Log is send to `anything-c-copy-files-async-log-file'.
3035 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3036 (declare (special auto-revert-interval))
3037 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3038 (set (make-local-variable 'auto-revert-interval) 1)
3039 (erase-buffer)
3040 (insert "Wait copying files...\n")
3041 (sit-for 0.5) (save-buffer)
3042 (goto-char (point-max))
3043 (auto-revert-mode 1)
3044 (anything-c-copy-files-async-1 flist dest))
3046 (defun anything-ff-copy-async (candidate)
3047 "Anything find files action to copy files async.
3048 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3049 (let ((flist (anything-marked-candidates))
3050 (dest (anything-c-read-file-name
3051 "Copy File(s) async To: "
3052 :preselect candidate
3053 :initial-input (car anything-ff-history)
3054 :history (anything-find-files-history :comp-read nil))))
3055 (anything-c-copy-async-with-log flist dest)))
3057 (defvar eshell-command-aliases-list nil)
3058 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3059 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3061 Basename of CANDIDATE can be a wild-card.
3062 If MAP is given run `eshell-command' on all marked files at once,
3063 Otherwise, run `eshell-command' on each marked files.
3065 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3066 `eshell-command-aliases-list' will not be loaded first time you use this."
3067 (when (or eshell-command-aliases-list
3068 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3069 (and eshell-command-aliases-list (eshell-read-aliases-list))
3070 (let* ((cand-list (anything-marked-candidates))
3071 (default-directory (or anything-ff-default-directory
3072 ;; If candidate is an url *-ff-default-directory is nil
3073 ;; so keep value of default-directory.
3074 default-directory))
3075 (command (anything-comp-read
3076 "Command: "
3077 (loop for (a . c) in eshell-command-aliases-list
3078 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3079 collect (propertize a 'help-echo (car c)) into ls
3080 finally return (sort ls 'string<))))
3081 (com-value (car (assoc-default command eshell-command-aliases-list))))
3082 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3083 (> (length cand-list) 1))
3084 ;; Run eshell-command with ALL marked files as arguments.
3085 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3086 (eshell-command (format "%s %s" command mapfiles)))
3087 ;; Run eshell-command on EACH marked files.
3088 (loop
3089 for i in cand-list
3090 for bn = (anything-c-basename i)
3091 for files = (if (and bn (string-match "^\*" bn))
3092 ;; Assume if fname is a wildcard
3093 ;; cand-list have a length of 1.
3094 (mapconcat
3095 'shell-quote-argument
3096 (file-expand-wildcards i t) " ")
3097 (format "'%s'" i))
3098 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3099 ;; This allow to enter other args AFTER filename
3100 ;; i.e <command %s some_more_args>
3101 (format command files)
3102 (format "%s %s" command files))
3103 do (eshell-command com))))))
3105 (defun anything-find-files-eshell-command-on-file (candidate)
3106 "Run `eshell-command' on CANDIDATE or marked candidates.
3107 See `anything-find-files-eshell-command-on-file-1' for more info."
3108 (anything-find-files-eshell-command-on-file-1
3109 candidate anything-current-prefix-arg))
3111 (defun anything-ff-switch-to-eshell (candidate)
3112 "Switch to eshell and cd to `anything-ff-default-directory'."
3113 (flet ((cd-eshell ()
3114 (goto-char (point-max))
3115 (insert
3116 (format "cd '%s'" anything-ff-default-directory))
3117 (eshell-send-input)))
3118 (if (get-buffer "*eshell*")
3119 (progn
3120 (anything-c-switch-to-buffer "*eshell*")
3121 (cd-eshell))
3122 (call-interactively 'eshell)
3123 (cd-eshell))))
3125 (defun anything-ff-serial-rename-action (method)
3126 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3127 See `anything-ff-serial-rename-1'."
3128 (let* ((cands (anything-marked-candidates))
3129 (name (read-string "NewName: "))
3130 (start (read-number "StartAtNumber: "))
3131 (extension (read-string "Extension: " (file-name-extension (car cands))))
3132 (dir (expand-file-name
3133 (anything-c-read-file-name
3134 "Serial Rename to directory: " :initial-input
3135 (expand-file-name anything-ff-default-directory)))))
3136 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3137 (length cands) dir name))
3138 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3139 (anything-find-files-1 dir))))
3141 (defun anything-ff-member-directory-p (file directory)
3142 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3143 (cur-dir (expand-file-name (file-name-as-directory directory))))
3144 (string= dir-file cur-dir)))
3146 (defun* anything-ff-serial-rename-1
3147 (directory collection new-name start-at-num extension &key (method 'rename))
3148 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3149 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3150 EXTENSION is the file extension to use, in empty prompt,
3151 reuse the original extension of file.
3152 METHOD can be one of rename, copy or symlink.
3153 Files will be renamed if they are files of current directory, otherwise they
3154 will be treated with METHOD.
3155 Default METHOD is rename."
3156 ;; Maybe remove directories selected by error in collection.
3157 (setq collection (remove-if 'file-directory-p collection))
3158 (flet ((symlink-file (file dest)
3159 (let ((flist (list file)))
3160 (anything-dired-action
3161 dest :action 'symlink :files flist))))
3163 (let* ((tmp-dir (file-name-as-directory
3164 (concat (file-name-as-directory directory)
3165 (symbol-name (gensym "tmp")))))
3166 (fn (case method
3167 (copy 'copy-file)
3168 (symlink 'symlink-file)
3169 (rename 'rename-file)
3170 (t (error "Error: Unknow method %s" method)))))
3171 (make-directory tmp-dir)
3172 (loop for i in collection
3173 for count from start-at-num
3174 for fnum = (if (< count 10) "0%s" "%s")
3175 for nname = (concat tmp-dir new-name (format fnum count)
3176 (if (not (string= extension ""))
3177 (format ".%s" (replace-regexp-in-string
3178 "[.]" "" extension))
3179 (file-name-extension i 'dot)))
3180 do (if (anything-ff-member-directory-p i directory)
3181 (rename-file i nname)
3182 (funcall fn i nname)))
3183 (loop with dirlist = (directory-files
3184 tmp-dir t directory-files-no-dot-files-regexp)
3185 for f in dirlist do
3186 (if (file-symlink-p f)
3187 (symlink-file (file-truename f)
3188 (concat (file-name-as-directory directory)
3189 (anything-c-basename f)))
3190 (rename-file f directory)))
3191 (delete-directory tmp-dir t))))
3193 (defun anything-ff-serial-rename (candidate)
3194 "Serial rename all marked files to `anything-ff-default-directory'.
3195 Rename only file of current directory, and symlink files coming from
3196 other directories.
3197 See `anything-ff-serial-rename-1'."
3198 (anything-ff-serial-rename-action 'rename))
3200 (defun anything-ff-serial-rename-by-symlink (candidate)
3201 "Serial rename all marked files to `anything-ff-default-directory'.
3202 Rename only file of current directory, and symlink files coming from
3203 other directories.
3204 See `anything-ff-serial-rename-1'."
3205 (anything-ff-serial-rename-action 'symlink))
3207 (defun anything-ff-serial-rename-by-copying (candidate)
3208 "Serial rename all marked files to `anything-ff-default-directory'.
3209 Rename only file of current directory, and copy files coming from
3210 other directories.
3211 See `anything-ff-serial-rename-1'."
3212 (anything-ff-serial-rename-action 'copy))
3214 (defun anything-c-quit-and-execute-action (action)
3215 "Quit current anything session and execute ACTION."
3216 (setq anything-saved-action action)
3217 (anything-exit-minibuffer))
3219 (defun anything-ff-toggle-auto-update (candidate)
3220 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3221 (message "[Auto expansion %s]"
3222 (if anything-ff-auto-update-flag "enabled" "disabled")))
3224 ;;;###autoload
3225 (defun anything-ff-run-toggle-auto-update ()
3226 (interactive)
3227 (anything-execute-persistent-action 'toggle-auto-update))
3229 ;;;###autoload
3230 (defun anything-ff-run-switch-to-history ()
3231 "Run Switch to history action from `anything-c-source-find-files'."
3232 (interactive)
3233 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3235 ;;;###autoload
3236 (defun anything-ff-run-grep ()
3237 "Run Grep action from `anything-c-source-find-files'."
3238 (interactive)
3239 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3241 ;;;###autoload
3242 (defun anything-ff-run-pdfgrep ()
3243 "Run Pdfgrep action from `anything-c-source-find-files'."
3244 (interactive)
3245 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3247 ;;;###autoload
3248 (defun anything-ff-run-zgrep ()
3249 "Run Grep action from `anything-c-source-find-files'."
3250 (interactive)
3251 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3253 ;;;###autoload
3254 (defun anything-ff-run-copy-file ()
3255 "Run Copy file action from `anything-c-source-find-files'."
3256 (interactive)
3257 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3259 ;;;###autoload
3260 (defun anything-ff-run-rename-file ()
3261 "Run Rename file action from `anything-c-source-find-files'."
3262 (interactive)
3263 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3265 ;;;###autoload
3266 (defun anything-ff-run-byte-compile-file ()
3267 "Run Byte compile file action from `anything-c-source-find-files'."
3268 (interactive)
3269 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3271 ;;;###autoload
3272 (defun anything-ff-run-load-file ()
3273 "Run Load file action from `anything-c-source-find-files'."
3274 (interactive)
3275 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3277 ;;;###autoload
3278 (defun anything-ff-run-eshell-command-on-file ()
3279 "Run eshell command on file action from `anything-c-source-find-files'."
3280 (interactive)
3281 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3283 ;;;###autoload
3284 (defun anything-ff-run-ediff-file ()
3285 "Run Ediff file action from `anything-c-source-find-files'."
3286 (interactive)
3287 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3289 ;;;###autoload
3290 (defun anything-ff-run-ediff-merge-file ()
3291 "Run Ediff merge file action from `anything-c-source-find-files'."
3292 (interactive)
3293 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3295 ;;;###autoload
3296 (defun anything-ff-run-symlink-file ()
3297 "Run Symlink file action from `anything-c-source-find-files'."
3298 (interactive)
3299 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3301 ;;;###autoload
3302 (defun anything-ff-run-delete-file ()
3303 "Run Delete file action from `anything-c-source-find-files'."
3304 (interactive)
3305 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3307 ;;;###autoload
3308 (defun anything-ff-run-complete-fn-at-point ()
3309 "Run complete file name action from `anything-c-source-find-files'."
3310 (interactive)
3311 (anything-c-quit-and-execute-action
3312 'anything-c-insert-file-name-completion-at-point))
3314 ;;;###autoload
3315 (defun anything-ff-run-switch-to-eshell ()
3316 "Run switch to eshell action from `anything-c-source-find-files'."
3317 (interactive)
3318 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3320 ;;;###autoload
3321 (defun anything-ff-run-switch-other-window ()
3322 "Run switch to other window action from `anything-c-source-find-files'."
3323 (interactive)
3324 (anything-c-quit-and-execute-action 'find-file-other-window))
3326 ;;;###autoload
3327 (defun anything-ff-run-switch-other-frame ()
3328 "Run switch to other frame action from `anything-c-source-find-files'."
3329 (interactive)
3330 (anything-c-quit-and-execute-action 'find-file-other-frame))
3332 ;;;###autoload
3333 (defun anything-ff-run-open-file-externally ()
3334 "Run open file externally command action from `anything-c-source-find-files'."
3335 (interactive)
3336 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3338 (defun anything-ff-locate (candidate)
3339 "Locate action function for `anything-find-files'."
3340 (let ((input (concat (anything-c-basename
3341 (expand-file-name
3342 candidate
3343 anything-ff-default-directory))
3344 ;; The locate '-b' option doesn't exists
3345 ;; in everything.
3346 (unless (and (eq system-type 'windows-nt)
3347 (string-match "^es" anything-c-locate-command))
3348 " -b")))
3349 (anything-mp-highlight-delay 0.7))
3350 (anything-locate-1 anything-current-prefix-arg input)))
3352 ;;;###autoload
3353 (defun anything-ff-run-locate ()
3354 "Run locate action from `anything-c-source-find-files'."
3355 (interactive)
3356 (anything-c-quit-and-execute-action 'anything-ff-locate))
3358 ;;;###autoload
3359 (defun anything-ff-run-gnus-attach-files ()
3360 "Run gnus attach files command action from `anything-c-source-find-files'."
3361 (interactive)
3362 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3364 ;;;###autoload
3365 (defun anything-ff-run-etags ()
3366 "Run Etags command action from `anything-c-source-find-files'."
3367 (interactive)
3368 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3371 (defun anything-ff-print (candidate)
3372 "Print marked files.
3373 You have to set in order
3374 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3376 e.g:
3377 \(setq lpr-command \"gtklp\"\)
3378 \(setq lpr-switches '(\"-P\")\)
3379 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3381 Same as `dired-do-print' but for anything."
3382 (let* ((file-list (anything-marked-candidates))
3383 (len (length file-list))
3384 (printer-name (if anything-ff-printer-list
3385 (anything-comp-read
3386 "Printer: " anything-ff-printer-list)
3387 printer-name))
3388 (command (read-string
3389 (format "Print *%s File(s):\n%s with: "
3391 (mapconcat
3392 (lambda (f) (format "- %s\n" f))
3393 file-list ""))
3394 (when (and lpr-command
3395 (or lpr-switches
3396 printer-name))
3397 (mapconcat 'identity
3398 (cons lpr-command
3399 (append (if (stringp lpr-switches)
3400 (list lpr-switches)
3401 lpr-switches)
3402 (list printer-name)))
3403 " "))))
3404 (file-args (mapconcat #'(lambda (x)
3405 (format "'%s'" x))
3406 file-list " "))
3407 (cmd-line (concat command " " file-args)))
3408 (if command
3409 (start-process-shell-command "anything-print" nil cmd-line)
3410 (error "Error: Please verify your printer settings in Emacs."))))
3412 ;;;###autoload
3413 (defun anything-ff-run-print-file ()
3414 "Run Print file action from `anything-c-source-find-files'."
3415 (interactive)
3416 (anything-c-quit-and-execute-action 'anything-ff-print))
3418 (defun anything-ff-checksum (file)
3419 "Calculate the checksum of FILE.
3420 Provide completion on different algorithms to use on Emacs24.
3421 On Emacs23 only 'sha1' is available.
3422 The checksum is copied to kill-ring."
3423 (let ((algo-list (and (fboundp 'secure-hash)
3424 '(md5 sha1 sha224 sha256 sha384 sha512))))
3425 (kill-new
3426 (if algo-list
3427 (secure-hash (intern
3428 (anything-comp-read
3429 "Algorithm: " algo-list))
3430 file)
3431 (sha1 (with-temp-buffer
3432 (insert-file-contents file)
3433 (buffer-string)))))
3434 (message "Checksum copied to kill-ring.")))
3436 (defun anything-ff-toggle-basename (candidate)
3437 (setq anything-ff-transformer-show-only-basename
3438 (not anything-ff-transformer-show-only-basename))
3439 (save-excursion
3440 (anything-force-update)))
3442 (defun anything-ff-run-toggle-basename ()
3443 (interactive)
3444 (anything-execute-persistent-action 'toggle-basename))
3446 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3447 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3448 If LEVEL is positive reduce from end else from beginning.
3449 If UNIX-CLOSE is non--nil close filename with /.
3450 If EXPAND is non--nil expand-file-name."
3451 (let* ((exp-fname (expand-file-name fname))
3452 (fname-list (split-string (if (or (string= fname "~/") expand)
3453 exp-fname fname) "/" t))
3454 (len (length fname-list))
3455 (pop-list (if (< level 0)
3456 (subseq fname-list (* level -1))
3457 (subseq fname-list 0 (- len level))))
3458 (result (mapconcat 'identity pop-list "/"))
3459 (empty (string= result "")))
3460 (when unix-close (setq result (concat result "/")))
3461 (if (string-match "^~" result)
3462 (if (string= result "~/") "~/" result)
3463 (if (< level 0)
3464 (if empty "../" (concat "../" result))
3465 (cond ((eq system-type 'windows-nt)
3466 (if empty "c:/" result))
3467 (empty "/")
3469 (concat "/" result)))))))
3471 ;; Internal
3472 (defvar anything-file-completion-sources
3473 '("Find Files" "find-file" "Copy Files"
3474 "dired-do-copy" "dired-do-rename"
3475 "dired-do-symlink" "dired-do-hardlink"
3476 "write-file" "insert-file" "dired"
3477 "find-alternate-file" "find-alternate-file-other-window"
3478 "find-file-read-only" "list-directory"
3479 "Read File Name History"
3480 "Rename Files" "Symlink Files"
3481 "Hardlink Files" "Write File"
3482 "Insert File" "Read File Name")
3483 "Sources that use the *find-files mechanism can be added here.
3484 You should not modify this yourself and know what you do if you do so.")
3486 (defun anything-file-completion-source-p ()
3487 "Test if current source is a dired or find-files source."
3488 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3489 (loop for i in anything-file-completion-sources
3490 thereis (string= cur-source i))))
3492 (defun anything-find-files-down-one-level (arg)
3493 "Go down one level like unix command `cd ..'.
3494 If prefix numeric arg is given go ARG level down."
3495 (interactive "p")
3496 (with-anything-window
3497 (setq anything-follow-mode nil))
3498 ;; When going to precedent level we want to be at the line
3499 ;; corresponding to actual directory, so store this info
3500 ;; in `anything-ff-last-expanded'.
3501 (if (and (not (file-directory-p anything-pattern))
3502 (file-exists-p anything-pattern))
3503 (setq anything-ff-last-expanded anything-pattern)
3504 (setq anything-ff-last-expanded anything-ff-default-directory))
3505 (when (anything-file-completion-source-p)
3506 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3507 :unix-close t :expand t)))
3508 (anything-set-pattern new-pattern))))
3510 (defun anything-ff-retrieve-last-expanded ()
3511 "Move overlay to last visited directory `anything-ff-last-expanded'.
3512 This happen after using `anything-find-files-down-one-level',
3513 or hitting C-z on \"..\"."
3514 (when (and anything-ff-last-expanded
3515 (anything-file-completion-source-p))
3516 (let ((dirname (if anything-ff-transformer-show-only-basename
3517 (anything-c-basename
3518 (directory-file-name anything-ff-last-expanded))
3519 (directory-file-name anything-ff-last-expanded))))
3520 (with-anything-window
3521 (when (or (re-search-forward (concat dirname "$") nil t)
3522 (re-search-forward
3523 (concat anything-ff-last-expanded "$") nil t))
3524 (forward-line 0)
3525 (anything-mark-current-line)))
3526 (setq anything-ff-last-expanded nil))))
3527 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3529 ;; Auto-update - anything-find-files auto expansion of directories.
3531 (defun anything-ff-update-when-only-one-matched ()
3532 "Expand to directory when sole completion.
3533 When only one candidate is remaining and it is a directory,
3534 expand to this directory."
3535 (when (and anything-ff-auto-update-flag
3536 (anything-file-completion-source-p))
3537 (let* ((history-p (string= (assoc-default
3538 'name (anything-get-current-source))
3539 "Read File Name History"))
3540 (pat (if (string-match tramp-file-name-regexp
3541 anything-pattern)
3542 (anything-create-tramp-name anything-pattern)
3543 anything-pattern))
3544 (completed-p (string= (file-name-as-directory pat)
3545 anything-ff-default-directory)))
3546 (when (and (or
3547 ;; Only one candidate remaining
3548 ;; and at least 2 char in basename.
3549 (and (<= (anything-approximate-candidate-number) 2)
3550 (>= (length (anything-c-basename anything-pattern)) 2))
3551 ;; Already completed.
3552 completed-p)
3553 (not history-p)) ; Don't try to auto complete in history.
3554 (with-anything-window
3555 (let ((cur-cand (prog2
3556 (unless completed-p
3557 ;; Only one non--existing candidate
3558 ;; and one directory candidate, move to it.
3559 (anything-next-line))
3560 (anything-get-selection))))
3561 (when (file-directory-p cur-cand)
3562 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3563 ;; Maybe we are here because completed-p is true
3564 ;; but check this again to be sure. (Windows fix)
3565 (<= (anything-approximate-candidate-number) 2)) ; [2]
3566 ;; If after going to next line the candidate
3567 ;; is not one of "." or ".." [1]
3568 ;; and only one candidate is remaining [2],
3569 ;; assume candidate is a new directory to expand, and do it.
3570 (anything-set-pattern (file-name-as-directory cur-cand))
3571 ;; The candidate is one of "." or ".."
3572 ;; that mean we have entered the last letter of the directory name
3573 ;; in prompt, so expansion is already done, just add the "/" at end
3574 ;; of name unless anything-pattern ends with "."
3575 ;; (i.e we are writing something starting with ".")
3576 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3577 (anything-set-pattern
3578 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3579 (expand-file-name (file-name-as-directory anything-pattern)))))
3580 (anything-check-minibuffer-input-1))))))))
3581 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3583 ;; Allow expanding to home directory or root
3584 ;; when entering respectively "~/" or "//" at end of pattern.
3585 ;; e.g /home/thierry/labo/anything-config-qp/~/
3586 ;; will expand to "~/"
3587 ;; and /home/thierry/labo/anything-config-qp//
3588 ;; will expand to "/"
3589 (defun anything-ff-auto-expand-to-home-or-root ()
3590 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3591 This happen only in function using sources that are
3592 `anything-file-completion-source-p' compliant."
3593 (when (and (anything-file-completion-source-p)
3594 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3595 anything-pattern))
3596 (let ((match (match-string 1 anything-pattern)))
3597 (cond ((string= match "//")
3598 (if (eq system-type 'windows-nt)
3599 (setq anything-pattern "c:/")
3600 (setq anything-pattern "/")))
3601 ((string= match "/~/")
3602 (if (eq system-type 'windows-nt)
3603 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3604 (setq anything-pattern "~/")))
3605 ((string= match "/./")
3606 (setq anything-pattern
3607 (with-anything-current-buffer
3608 (expand-file-name default-directory))))))
3609 (setq anything-ff-default-directory anything-pattern)
3610 ;; For some reasons, i must use here with-current-buffer => mini buffer
3611 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3612 (with-current-buffer (window-buffer (minibuffer-window))
3613 (delete-minibuffer-contents)
3614 (insert anything-pattern))))
3616 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3618 (defun anything-c-point-file-in-dired (file)
3619 "Put point on filename FILE in dired buffer."
3620 (dired (file-name-directory file))
3621 (dired-goto-file file))
3623 (defun anything-create-tramp-name (fname)
3624 "Build filename for `anything-pattern' like /su:: or /sudo::."
3625 (apply #'tramp-make-tramp-file-name
3626 (loop with v = (tramp-dissect-file-name fname)
3627 for i across v collect i)))
3629 (defun anything-ff-set-pattern (pattern)
3630 "Handle tramp filenames in `anything-pattern'."
3631 (let ((methods (mapcar 'car tramp-methods))
3632 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3633 cur-method tramp-name)
3634 (cond ((string= pattern "") "")
3635 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3636 (with-anything-current-buffer
3637 (expand-file-name default-directory)))
3638 ((string-match ".*\\(~//\\|//\\)$" pattern)
3639 (if (eq system-type 'windows-nt) "c:/" "/"))
3640 ((string-match "^~\\|.*/~/$" pattern)
3641 (let* ((home (expand-file-name (getenv "HOME"))))
3642 (replace-match home nil t pattern)))
3643 ;; Match "/method:maybe_hostname:"
3644 ((and (string-match reg pattern)
3645 (setq cur-method (match-string 1 pattern))
3646 (member cur-method methods))
3647 (setq tramp-name (anything-create-tramp-name
3648 (match-string 0 pattern)))
3649 (replace-match tramp-name nil t pattern))
3650 ;; Match "/hostname:"
3651 ((and (string-match tramp-file-name-regexp pattern)
3652 (setq cur-method (match-string 1 pattern))
3653 (and cur-method (not (member cur-method methods))))
3654 (setq tramp-name (anything-create-tramp-name
3655 (match-string 0 pattern)))
3656 (replace-match tramp-name nil t pattern))
3657 ;; Match "/method:" in this case don't try to connect.
3658 ((and (not (string-match reg pattern))
3659 (string-match tramp-file-name-regexp pattern)
3660 (member (match-string 1 pattern) methods))
3661 "Invalid tramp file name") ; Write in anything-buffer.
3662 ;; PATTERN is a directory, end it with "/".
3663 ;; This will make PATTERN not ending yet with "/"
3664 ;; candidate for `anything-ff-default-directory',
3665 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3666 ;; when descending level.
3667 ((file-directory-p pattern)
3668 (file-name-as-directory pattern))
3669 ;; Return PATTERN unchanged.
3670 (t pattern))))
3673 (defun anything-find-files-get-candidates ()
3674 "Create candidate list for `anything-c-source-find-files'."
3675 (let* ((path (anything-ff-set-pattern anything-pattern))
3676 (path-name-dir (if (file-directory-p path)
3677 (file-name-as-directory path)
3678 (file-name-directory path)))
3679 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3680 (set-text-properties 0 (length path) nil path)
3681 (setq anything-pattern (anything-ff-transform-fname-for-completion path))
3682 (setq anything-ff-default-directory
3683 (if (string= anything-pattern "")
3684 (if (eq system-type 'windows-nt) "c:/" "/")
3685 (unless (string-match ffap-url-regexp path)
3686 ;; If path is an url *default-directory have to be nil.
3687 path-name-dir)))
3688 (cond ((or (string= path "Invalid tramp file name")
3689 (file-regular-p path)
3690 (and (not (file-exists-p path)) (string-match "/$" path))
3691 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3692 (list path))
3693 ((string= path "") (directory-files "/" t))
3694 ((and (file-directory-p path) (not (file-readable-p path)))
3695 (list (format "Opening directory: access denied, `%s'" path)))
3696 ((file-directory-p path) (directory-files path t))
3698 (append (list path) (directory-files path-name-dir t))))))
3700 (defun anything-ff-transform-fname-for-completion (fname)
3701 "Return FNAME with it's basename modified as a regexp.
3702 e.g foo => f.*o.*o .
3703 If basename contain one or more space or FNAME is a valid directory name
3704 return FNAME unchanged."
3705 (let ((bn (anything-c-basename fname)))
3706 (if (or (not anything-ff-smart-completion)
3707 (string-match "\\s-" bn)
3708 (string-match "/$" fname) ; Allow mkdir.
3709 (file-directory-p fname))
3710 fname ; Fall back to match-plugin.
3711 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3712 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3713 (concat (file-name-directory fname) bn))))
3715 (defun anything-ff-save-history ()
3716 "Store the last value of `anything-ff-default-directory' \
3717 in `anything-ff-history'."
3718 (when (and anything-ff-default-directory
3719 (anything-file-completion-source-p))
3720 (push anything-ff-default-directory anything-ff-history)))
3721 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3723 (defun anything-ff-valid-symlink-p (file)
3724 (file-exists-p (file-truename file)))
3726 (defun anything-ff-properties (candidate)
3727 "Show file properties of CANDIDATE in a tooltip or message."
3728 (let ((type (anything-ff-attributes candidate :type t))
3729 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3730 (if (window-system)
3731 (tooltip-show
3732 (concat
3733 (anything-c-basename candidate) ": \n"
3734 "Type: " type "\n"
3735 (when (string= type "symlink")
3736 (format "True name: '%s'\n"
3737 (cond ((string-match "^\.#" (anything-c-basename candidate))
3738 "Autosave symlink")
3739 ((anything-ff-valid-symlink-p candidate)
3740 (file-truename candidate))
3741 (t "Invalid Symlink"))))
3742 dired-line))
3743 (message dired-line) (sit-for 5))))
3745 ;;;###autoload
3746 (defun anything-ff-properties-persistent ()
3747 "Show properties without quitting anything."
3748 (interactive)
3749 (anything-execute-persistent-action 'properties-action))
3751 (defun anything-ff-kill-buffer-fname (candidate)
3752 (let* ((buf (get-file-buffer candidate))
3753 (buf-name (buffer-name buf)))
3754 (if buf
3755 (progn
3756 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3757 (message "No buffer to kill"))))
3759 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3760 "Find file CANDIDATE or kill it's buffer if it is visible.
3761 Never kill `anything-current-buffer'.
3762 Never kill buffer modified.
3763 This is called normally on third hit of \
3764 \\<anything-map>\\[anything-execute-persistent-action]
3765 in `anything-find-files-persistent-action'."
3766 (let* ((buf (get-file-buffer candidate))
3767 (buf-name (buffer-name buf)))
3768 (if (and buf (get-buffer-window buf)
3769 (not (eq buf (get-buffer anything-current-buffer)))
3770 (not (buffer-modified-p buf)))
3771 (progn
3772 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3773 (find-file candidate))))
3775 ;;;###autoload
3776 (defun anything-ff-run-kill-buffer-persistent ()
3777 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3778 (interactive)
3779 (anything-execute-persistent-action 'kill-buffer-fname))
3781 (defun anything-ff-human-size (size)
3782 "Return a string showing SIZE of a file in human readable form.
3783 SIZE can be an integer or a float depending it's value.
3784 `file-attributes' will take care of that to avoid overflow error.
3785 KBSIZE if a floating point number, default value is 1024.0."
3786 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3787 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3788 (K (cons "K" (/ size anything-ff-default-kbsize)))
3789 (B (cons "B" size)))
3790 (loop with result = B
3791 for (a . b) in
3792 (loop for (x . y) in (list M G K B)
3793 unless (< y 1) collect (cons x y))
3794 when (< b (cdr result)) do (setq result (cons a b))
3795 finally return (if (string= (car result) "B")
3796 (format "%s" size)
3797 (format "%.1f%s" (cdr result) (car result))))))
3799 (defun* anything-ff-attributes
3800 (file &key type links uid gid access-time modif-time
3801 status size mode gid-change inode device-num dired human-size)
3802 "Easy interface for `file-attributes'."
3803 (let ((all (destructuring-bind
3804 (type links uid gid access-time modif-time
3805 status size mode gid-change inode device-num)
3806 (file-attributes file 'string)
3807 (list :type type
3808 :links links
3809 :uid uid
3810 :gid gid
3811 :access-time access-time
3812 :modif-time modif-time
3813 :status status
3814 :size size
3815 :mode mode
3816 :gid-change gid-change
3817 :inode inode
3818 :device-num device-num))))
3819 (cond (type
3820 (let ((result (getf all :type)))
3821 (cond ((stringp result)
3822 "symlink")
3823 (result "directory")
3824 (t "file"))))
3825 (links (getf all :links))
3826 (uid (getf all :uid))
3827 (gid (getf all :gid))
3828 (access-time
3829 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3830 (modif-time
3831 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3832 (status
3833 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3834 (size (if human-size (anything-ff-human-size (getf all :size))
3835 (getf all :size)))
3836 (mode (getf all :mode))
3837 (gid-change (getf all :gid-change))
3838 (inode (getf all :inode))
3839 (device-num (getf all :device-num))
3840 (dired
3841 (concat
3842 (getf all :mode) " "
3843 (number-to-string (getf all :links)) " "
3844 (getf all :uid) ":"
3845 (getf all :gid) " "
3846 (if human-size (anything-ff-human-size (getf all :size))
3847 (int-to-string (getf all :size))) " "
3848 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3849 (t all))))
3851 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3852 "Return filename FNAME maybe prefixed with [?] or [@].
3853 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3854 existing filename or valid symlink and there is no need to test it.
3855 NEW-FILE when non--nil mean FNAME is a non existing file and
3856 return FNAME prefixed with [?]."
3857 (let* ((prefix-new (propertize
3858 " " 'display
3859 (propertize "[?]" 'face 'anything-ff-prefix)))
3860 (prefix-url (propertize
3861 " " 'display
3862 (propertize "[@]" 'face 'anything-ff-prefix))))
3863 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3864 ((string-match ffap-url-regexp fname)
3865 (concat prefix-url " " fname))
3866 ((or new-file (not (file-exists-p fname)))
3867 (concat prefix-new " " fname)))))
3869 (defun anything-c-find-files-transformer (files sources)
3870 "Transformer for `anything-c-source-find-files'.
3871 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3872 is non--nil."
3873 (if (and (string-match tramp-file-name-regexp anything-pattern)
3874 anything-ff-tramp-not-fancy)
3875 (if anything-ff-transformer-show-only-basename
3876 (loop for i in files collect
3877 (if (string-match "[.]\\{1,2\\}$" i)
3878 i (cons (anything-c-basename i) i)))
3879 files)
3880 (anything-ff-highlight-files files sources)))
3882 (defun anything-ff-highlight-files (files sources)
3883 "Candidate transformer for `anything-c-source-find-files' without icons."
3884 (loop for i in files
3885 for disp = (if (and anything-ff-transformer-show-only-basename
3886 (not (string-match "[.]\\{1,2\\}$" i))
3887 (not (string-match ffap-url-regexp i)))
3888 (anything-c-basename i) i)
3889 collect
3890 (cond ((and (stringp (car (file-attributes i)))
3891 (not (anything-ff-valid-symlink-p i))
3892 (not (string-match "^\.#" (anything-c-basename i))))
3893 (cons (anything-ff-prefix-filename
3894 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3896 ((stringp (car (file-attributes i)))
3897 (cons (anything-ff-prefix-filename
3898 (propertize disp 'face 'anything-ff-symlink) t)
3900 ((eq t (car (file-attributes i)))
3901 (cons (anything-ff-prefix-filename
3902 (propertize disp 'face 'anything-ff-directory) t)
3904 ((file-executable-p i)
3905 (cons (anything-ff-prefix-filename
3906 (propertize disp 'face 'anything-ff-executable) t)
3908 ((file-exists-p i)
3909 (cons (anything-ff-prefix-filename
3910 (propertize disp 'face 'anything-ff-file) t)
3913 (cons (anything-ff-prefix-filename
3914 (propertize disp 'face 'anything-ff-file) nil 'new-file)
3915 i)))))
3917 (defun anything-find-files-action-transformer (actions candidate)
3918 "Action transformer for `anything-c-source-find-files'."
3919 (cond ((with-anything-current-buffer
3920 (eq major-mode 'message-mode))
3921 (append (subseq actions 0 4)
3922 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
3923 (subseq actions 4)))
3924 ((string-match (image-file-name-regexp) candidate)
3925 (append (subseq actions 0 4)
3926 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
3927 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
3928 (subseq actions 4)))
3929 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
3930 (car it) candidate))
3931 (append (subseq actions 0 4)
3932 '(("Byte compile lisp file(s) `M-B, C-u to load'"
3933 . anything-find-files-byte-compile)
3934 ("Load File(s) `M-L'" . anything-find-files-load-files))
3935 (subseq actions 4)))
3936 ((and (string-match "\.html?$" candidate)
3937 (file-exists-p candidate))
3938 (append (subseq actions 0 4)
3939 '(("Browse url file" . browse-url-of-file))
3940 (subseq actions 5)))
3941 ((or (string= (file-name-extension candidate) "pdf")
3942 (string= (file-name-extension candidate) "PDF"))
3943 (append (subseq actions 0 4)
3944 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
3945 (subseq actions 5)))
3946 (t actions)))
3948 (defun anything-ff-gnus-attach-files (candidate)
3949 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
3950 (let ((flist (anything-marked-candidates)))
3951 (gnus-dired-attach flist)))
3953 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
3954 "Rotate current image at NUM-ARG degrees.
3955 This is a destructive operation on FILE made by external tool mogrify."
3956 (declare (special image-dired-display-image-buffer))
3957 (setq file (file-truename file)) ; For symlinked images.
3958 ;; When FILE is not an image-file, do nothing.
3959 (when (string-match (image-file-name-regexp) file)
3960 (if (executable-find "mogrify")
3961 (progn
3962 (shell-command (format "mogrify -rotate %s %s"
3963 (or num-arg 90)
3964 (shell-quote-argument file)))
3965 (when (buffer-live-p image-dired-display-image-buffer)
3966 (kill-buffer image-dired-display-image-buffer))
3967 (image-dired-display-image file)
3968 (message nil)
3969 (display-buffer (get-buffer image-dired-display-image-buffer)))
3970 (error "mogrify not found"))))
3972 (defun anything-ff-rotate-image-left (candidate)
3973 "Rotate image file CANDIDATE left.
3974 This affect directly file CANDIDATE."
3975 (anything-ff-rotate-current-image-1 candidate -90))
3977 (defun anything-ff-rotate-image-right (candidate)
3978 "Rotate image file CANDIDATE right.
3979 This affect directly file CANDIDATE."
3980 (anything-ff-rotate-current-image-1 candidate))
3982 (defun anything-ff-rotate-left-persistent ()
3983 "Rotate image left without quitting anything."
3984 (interactive)
3985 (anything-execute-persistent-action 'image-action1))
3987 (defun anything-ff-rotate-right-persistent ()
3988 "Rotate image right without quitting anything."
3989 (interactive)
3990 (anything-execute-persistent-action 'image-action2))
3992 (defun anything-ff-exif-data (candidate)
3993 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
3994 (if (and anything-ff-exif-data-program
3995 (executable-find anything-ff-exif-data-program))
3996 (shell-command-to-string (format "%s %s %s"
3997 anything-ff-exif-data-program
3998 anything-ff-exif-data-program-args
3999 candidate))
4000 (format "No program %s found to extract exif"
4001 anything-ff-exif-data-program)))
4003 (defun anything-find-files-persistent-action (candidate)
4004 "Open subtree CANDIDATE without quitting anything.
4005 If CANDIDATE is not a directory expand CANDIDATE filename.
4006 If CANDIDATE is alone, open file CANDIDATE filename.
4007 That's mean:
4008 First hit on C-z expand CANDIDATE second hit open file.
4009 If a prefix arg is given or `anything-follow-mode' is on open file."
4010 (let ((follow (buffer-local-value
4011 'anything-follow-mode
4012 (get-buffer-create anything-buffer)))
4013 (new-pattern (anything-get-selection))
4014 (num-lines-buf (with-current-buffer anything-buffer
4015 (count-lines (point-min) (point-max)))))
4016 (flet ((insert-in-minibuffer (fname)
4017 (with-selected-window (minibuffer-window)
4018 (unless follow
4019 (delete-minibuffer-contents)
4020 (set-text-properties 0 (length fname) nil fname)
4021 (insert fname)))))
4022 (cond (;; A symlink directory, expand it's truename.
4023 (and (file-directory-p candidate) (file-symlink-p candidate))
4024 (insert-in-minibuffer (file-name-as-directory
4025 (file-truename
4026 (expand-file-name candidate)))))
4027 ;; A directory, open it.
4028 ((file-directory-p candidate)
4029 (when (string= (anything-c-basename candidate) "..")
4030 (setq anything-ff-last-expanded anything-ff-default-directory))
4031 (insert-in-minibuffer (file-name-as-directory
4032 (expand-file-name candidate))))
4033 ;; A symlink file, expand to it's true name. (first hit)
4034 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4035 (insert-in-minibuffer (file-truename candidate)))
4036 ;; A regular file, expand it, (first hit)
4037 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4038 (insert-in-minibuffer new-pattern))
4039 ;; An image file and it is the second hit on C-z,
4040 ;; show the file in `image-dired'.
4041 ((string-match (image-file-name-regexp) candidate)
4042 (when (buffer-live-p image-dired-display-image-buffer)
4043 (kill-buffer image-dired-display-image-buffer))
4044 (image-dired-display-image candidate)
4045 (message nil)
4046 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4047 (with-current-buffer image-dired-display-image-buffer
4048 (let ((exif-data (anything-ff-exif-data candidate)))
4049 (image-dired-update-property 'help-echo exif-data))))
4050 ;; Allow browsing archive on avfs fs.
4051 ;; Assume volume is already mounted with mountavfs.
4052 ((and anything-ff-avfs-directory
4053 (string-match
4054 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4055 (file-name-directory candidate))
4056 (anything-ff-file-compressed-p candidate))
4057 (insert-in-minibuffer (concat candidate "#")))
4058 ;; On second hit we open file.
4059 ;; On Third hit we kill it's buffer maybe.
4061 (anything-ff-kill-or-find-buffer-fname candidate))))))
4063 (defun anything-ff-file-compressed-p (candidate)
4064 "Whether CANDIDATE is a compressed file or not."
4065 (member (file-name-extension candidate)
4066 anything-ff-file-compressed-list))
4068 (defun anything-c-insert-file-name-completion-at-point (candidate)
4069 "Insert file name completion at point."
4070 (with-anything-current-buffer
4071 (if buffer-read-only
4072 (error "Error: Buffer `%s' is read-only" (buffer-name))
4073 (let* ((end (point))
4074 (guess (substring-no-properties (thing-at-point 'filename)))
4075 (beg (- (point) (length guess)))
4076 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4077 (string-match-p "^[^\~]" guess))))
4078 (set-text-properties 0 (length candidate) nil candidate)
4079 (if (and guess (not (string= guess ""))
4080 (string-match-p "^~\\|/.*" guess))
4081 (progn
4082 (delete-region beg end)
4083 (insert (if full-path-p
4084 (expand-file-name candidate)
4085 (abbreviate-file-name candidate))))
4086 (error "Aborting completion: No valid file name at point"))))))
4088 (defun* anything-find-files-history (&key (comp-read t))
4089 "The `anything-find-files' history.
4090 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
4091 in an `anything-comp-read'."
4092 (let ((history (when anything-ff-history
4093 (loop with dup for i in anything-ff-history
4094 ;; Remove duplicate and not existing files.
4095 ;; Keep remote files.
4096 unless (or (member i dup)
4097 (and (not (file-remote-p i))
4098 (not (file-exists-p i))))
4099 collect i into dup
4100 finally return dup)))) ; Remove dups.
4101 (when history
4102 (setq anything-ff-history
4103 (if (>= (length history) anything-ff-history-max-length)
4104 (subseq history 0 anything-ff-history-max-length)
4105 history))
4106 (if comp-read
4107 (anything-comp-read
4108 "Switch to Directory: "
4109 anything-ff-history
4110 :name "Anything Find Files History"
4111 :must-match t)
4112 anything-ff-history))))
4114 (defun anything-find-files-1 (fname &optional preselect)
4115 "Find FNAME with `anything' completion.
4116 Like `find-file' but with `anything' support.
4117 Use it for non--interactive calls of `anything-find-files'."
4118 (when (get-buffer anything-action-buffer)
4119 (kill-buffer anything-action-buffer))
4120 (let ((anything-mp-highlight-delay nil)
4121 ;; Be sure we don't erase the precedent minibuffer if some.
4122 (anything-ff-auto-update-initial-value
4123 (not (minibuffer-window-active-p (minibuffer-window))))
4124 anything-samewindow)
4125 (anything :sources 'anything-c-source-find-files
4126 :input fname
4127 :preselect preselect
4128 :keymap anything-find-files-map
4129 :prompt "Find Files or Url: "
4130 :buffer "*Anything Find Files*")))
4133 (defun anything-find-files-initial-input (&optional input)
4134 "Return INPUT if present, otherwise try to guess it."
4135 (or (and input (expand-file-name input))
4136 (anything-find-files-input
4137 (ffap-guesser)
4138 (thing-at-point 'filename))))
4140 (defun anything-find-files-input (fap tap)
4141 "Default input of `anything-find-files'."
4142 (let* ((def-dir (anything-c-current-directory))
4143 (lib (anything-find-library-at-point))
4144 (url (anything-ff-find-url-at-point))
4145 (file-p (and fap (not (string= fap ""))
4146 (file-exists-p fap)
4147 tap (not (string= tap ""))
4148 (file-exists-p
4149 (file-name-directory (expand-file-name tap def-dir))))))
4150 (cond (lib) ; e.g we are inside a require sexp.
4151 (url) ; String at point is an hyperlink.
4152 (file-p (expand-file-name tap def-dir))
4153 (t (and (not (string= fap "")) fap)))))
4155 (defun anything-c-current-directory ()
4156 "Return current-directory name at point.
4157 Useful in dired buffers when there is inserted subdirs."
4158 (if (eq major-mode 'dired-mode)
4159 (dired-current-directory)
4160 default-directory))
4162 (defun anything-ff-find-url-at-point ()
4163 "Try to find link to an url in text-property at point."
4164 (let* ((he (get-text-property (point) 'help-echo))
4165 (ov (overlays-at (point)))
4166 (ov-he (and ov (overlay-get
4167 (car (overlays-at (point))) 'help-echo)))
4168 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4169 (nt-prop (get-text-property (point) 'nt-link)))
4170 ;; Org link.
4171 (when (and (stringp he) (string-match "^LINK: " he))
4172 (setq he (replace-match "" t t he)))
4173 (loop for i in (list he ov-he w3m-l nt-prop)
4174 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4176 (defun anything-find-library-at-point ()
4177 "Try to find library path at point.
4178 Find inside `require' and `declare-function' sexp."
4179 (require 'find-func)
4180 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4181 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4182 (sexp (and beg-sexp end-sexp
4183 (buffer-substring-no-properties
4184 (1+ beg-sexp) (1- end-sexp)))))
4185 (ignore-errors
4186 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4187 (find-library-name
4188 (replace-regexp-in-string
4189 "'\\|\)\\|\(" ""
4190 ;; If require use third arg, ignore it,
4191 ;; always use library path found in `load-path'.
4192 (second (split-string (match-string 0 sexp))))))
4193 ((and sexp (string-match-p "^declare-function" sexp))
4194 (find-library-name
4195 (replace-regexp-in-string
4196 "\"\\|ext:" ""
4197 (third (split-string sexp)))))
4198 (t nil)))))
4200 ;;; Anything completion for `write-file'.==> C-x C-w
4201 (defvar anything-c-source-write-file
4202 `((name . "Write File")
4203 (header-name . (lambda (name)
4204 (concat name anything-c-find-files-doc-header)))
4205 ;; It is needed for filenames with capital letters
4206 (disable-shortcuts)
4207 (candidates . anything-find-files-get-candidates)
4208 (filtered-candidate-transformer anything-c-find-files-transformer)
4209 (persistent-action . anything-find-files-persistent-action)
4210 (persistent-help . "Expand Candidate")
4211 (volatile)
4212 (action .
4213 (("Write File" . (lambda (candidate)
4214 (write-file candidate 'confirm)))))))
4216 ;;; Anything completion for `insert-file'.==> C-x i
4217 (defvar anything-c-source-insert-file
4218 `((name . "Insert File")
4219 (header-name . (lambda (name)
4220 (concat name anything-c-find-files-doc-header)))
4221 ;; It is needed for filenames with capital letters
4222 (disable-shortcuts)
4223 (candidates . anything-find-files-get-candidates)
4224 (filtered-candidate-transformer anything-c-find-files-transformer)
4225 (persistent-action . anything-find-files-persistent-action)
4226 (persistent-help . "Expand Candidate")
4227 (volatile)
4228 (action .
4229 (("Insert File" . (lambda (candidate)
4230 (when (y-or-n-p (format "Really insert %s in %s "
4231 candidate anything-current-buffer))
4232 (insert-file-contents candidate))))))))
4234 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4235 (defvar anything-c-source-copy-files
4236 `((name . "Copy Files")
4237 (header-name . (lambda (name)
4238 (concat name anything-c-find-files-doc-header)))
4239 ;; It is needed for filenames with capital letters
4240 (disable-shortcuts)
4241 (candidates . anything-find-files-get-candidates)
4242 (filtered-candidate-transformer anything-c-find-files-transformer)
4243 (persistent-action . anything-find-files-persistent-action)
4244 (persistent-help . "Expand Candidate")
4245 (volatile)
4246 (action .
4247 (("Copy File"
4248 . (lambda (candidate)
4249 (anything-dired-action candidate :action 'copy)))
4250 ("Copy and Follow"
4251 . (lambda (candidate)
4252 (anything-dired-action candidate :action 'copy :follow t)))))))
4255 (defvar anything-c-source-rename-files
4256 `((name . "Rename Files")
4257 (header-name . (lambda (name)
4258 (concat name anything-c-find-files-doc-header)))
4259 ;; It is needed for filenames with capital letters
4260 (disable-shortcuts)
4261 (candidates . anything-find-files-get-candidates)
4262 (filtered-candidate-transformer anything-c-find-files-transformer)
4263 (persistent-action . anything-find-files-persistent-action)
4264 (persistent-help . "Expand Candidate")
4265 (volatile)
4266 (action .
4267 (("Rename File"
4268 . (lambda (candidate)
4269 (anything-dired-action candidate :action 'rename)))
4270 ("Rename and Follow"
4271 . (lambda (candidate)
4272 (anything-dired-action candidate :action 'rename :follow t)))))))
4274 (defvar anything-c-source-symlink-files
4275 `((name . "Symlink Files")
4276 (header-name . (lambda (name)
4277 (concat name anything-c-find-files-doc-header)))
4278 ;; It is needed for filenames with capital letters
4279 (disable-shortcuts)
4280 (candidates . anything-find-files-get-candidates)
4281 (filtered-candidate-transformer anything-c-find-files-transformer)
4282 (persistent-action . anything-find-files-persistent-action)
4283 (persistent-help . "Expand Candidate")
4284 (volatile)
4285 (action
4286 . (("Symlink File"
4287 . (lambda (candidate)
4288 (anything-dired-action candidate :action 'symlink)))
4289 ("RelSymlink File"
4290 . (lambda (candidate)
4291 (anything-dired-action candidate :action 'relsymlink)))))))
4294 (defvar anything-c-source-hardlink-files
4295 `((name . "Hardlink Files")
4296 (header-name . (lambda (name)
4297 (concat name anything-c-find-files-doc-header)))
4298 ;; It is needed for filenames with capital letters
4299 (disable-shortcuts)
4300 (candidates . anything-find-files-get-candidates)
4301 (filtered-candidate-transformer anything-c-find-files-transformer)
4302 (persistent-action . anything-find-files-persistent-action)
4303 (persistent-help . "Expand Candidate")
4304 (volatile)
4305 (action
4306 . (("Hardlink File"
4307 . (lambda (candidate)
4308 (anything-dired-action candidate :action 'hardlink)))))))
4310 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4311 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4312 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4313 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4314 (let ((fn (case action
4315 ('copy 'dired-copy-file)
4316 ('rename 'dired-rename-file)
4317 ('symlink 'make-symbolic-link)
4318 ('relsymlink 'dired-make-relative-symlink)
4319 ('hardlink 'dired-hardlink)))
4320 (marker (case action
4321 ((copy rename) dired-keep-marker-copy)
4322 ('symlink dired-keep-marker-symlink)
4323 ('relsymlink dired-keep-marker-relsymlink)
4324 ('hardlink dired-keep-marker-hardlink)))
4325 (dirflag (and (= (length files) 1)
4326 (file-directory-p (car files))
4327 (not (file-directory-p candidate)))))
4328 (dired-create-files
4329 fn (symbol-name action) files
4330 ;; CANDIDATE is the destination.
4331 (if (file-directory-p candidate)
4332 ;; When CANDIDATE is a directory, build file-name in this directory.
4333 ;; Else we use CANDIDATE.
4334 #'(lambda (from)
4335 (expand-file-name (file-name-nondirectory from) candidate))
4336 #'(lambda (from) candidate))
4337 marker)
4338 (when (and follow (not (get-buffer dired-log-buffer)))
4339 (let ((target (directory-file-name candidate)))
4340 (unwind-protect
4341 (progn
4342 (setq anything-ff-cand-to-mark
4343 (anything-get-dest-fnames-from-list files candidate dirflag))
4344 (if (and dirflag (eq action 'rename))
4345 (anything-find-files-1 (file-name-directory target)
4346 (if anything-ff-transformer-show-only-basename
4347 (anything-c-basename target) target))
4348 (anything-find-files-1 (expand-file-name candidate))))
4349 (setq anything-ff-cand-to-mark nil))))))
4352 (defun anything-c-basename (fname)
4353 "Resolve basename of file or directory named FNAME."
4354 (file-name-nondirectory (directory-file-name fname)))
4356 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4357 "Transform filenames of FLIST to abs of DEST-CAND.
4358 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4359 members of FLIST."
4360 ;; At this point files have been renamed/copied at destination.
4361 ;; That's mean DEST-CAND exists.
4362 (loop
4363 with dest = (expand-file-name dest-cand)
4364 for src in flist
4365 for basename-src = (anything-c-basename src)
4366 for fname = (cond (rename-dir-flag (directory-file-name dest))
4367 ((file-directory-p dest)
4368 (concat (file-name-as-directory dest) basename-src))
4369 (t dest))
4370 when (file-exists-p fname)
4371 collect fname into tmp-list
4372 finally return (sort tmp-list 'string<)))
4374 (defun anything-ff-maybe-mark-candidates ()
4375 "Mark all candidates of list `anything-ff-cand-to-mark'."
4376 (when (and (string= (assoc-default 'name (anything-get-current-source))
4377 (assoc-default 'name anything-c-source-find-files))
4378 anything-ff-cand-to-mark)
4379 (with-anything-window
4380 (while anything-ff-cand-to-mark
4381 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4382 (progn
4383 (anything-make-visible-mark)
4384 (anything-next-line)
4385 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4386 (anything-next-line)))
4387 (unless (anything-this-visible-mark)
4388 (anything-prev-visible-mark)))))
4390 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4392 (defun* anything-dired-do-action-on-file (&key action)
4393 (let* ((files (dired-get-marked-files))
4394 (len (length files))
4395 (fname (if (> len 1)
4396 (format "* %d Files" len)
4397 (car files)))
4398 (source (case action
4399 ('copy 'anything-c-source-copy-files)
4400 ('rename 'anything-c-source-rename-files)
4401 ('symlink 'anything-c-source-symlink-files)
4402 ('hardlink 'anything-c-source-hardlink-files)))
4403 (prompt-fm (case action
4404 ('copy "Copy %s to: ")
4405 ('rename "Rename %s to: ")
4406 ('symlink "Symlink %s to: ")
4407 ('hardlink "Hardlink %s to: ")))
4408 (buffer (case action
4409 ('copy "*Anything Copy Files*")
4410 ('rename "*Anything Rename Files*")
4411 ('symlink "*Anything Symlink Files*")
4412 ('hardlink "*Anything Hardlink Files*")))
4413 (anything-mp-highlight-delay nil))
4414 (anything :sources source
4415 :input (or (dired-dwim-target-directory)
4416 (expand-file-name (anything-c-current-directory)))
4417 :preselect (dired-get-filename)
4418 :prompt (format prompt-fm fname)
4419 :keymap anything-c-read-file-map
4420 :buffer buffer)))
4422 ;;;###autoload
4423 (define-minor-mode anything-dired-mode ()
4424 "Enable anything completion in Dired functions.
4425 Bindings affected are C, R, S, H.
4426 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4427 :group 'anything-config
4428 :global t
4429 (if anything-dired-mode
4430 (progn
4431 (substitute-key-definition
4432 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4433 (substitute-key-definition
4434 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4435 (substitute-key-definition
4436 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4437 (substitute-key-definition
4438 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4439 (substitute-key-definition
4440 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4441 (substitute-key-definition
4442 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4443 (substitute-key-definition
4444 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4445 (substitute-key-definition
4446 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4448 (defalias 'anything-dired-bindings 'anything-dired-mode)
4450 (defun* anything-c-read-file-name (prompt
4451 &key
4452 (name "Read File Name")
4453 (initial-input (expand-file-name default-directory))
4454 (buffer "*Anything Completions*")
4455 test
4456 (preselect nil)
4457 (history nil)
4458 (marked-candidates nil)
4459 (alistp t)
4460 (persistent-action 'anything-find-files-persistent-action)
4461 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4462 "Anything `read-file-name' emulation.
4463 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4464 (when (get-buffer anything-action-buffer)
4465 (kill-buffer anything-action-buffer))
4466 (let ((anything-mp-highlight-delay nil)
4467 ;; Be sure we don't erase the underlying minibuffer if some.
4468 (anything-ff-auto-update-initial-value
4469 (not (minibuffer-window-active-p (minibuffer-window))))
4470 anything-same-window)
4471 (flet ((action-fn (candidate)
4472 (if marked-candidates
4473 (anything-marked-candidates)
4474 (identity candidate))))
4475 (or (anything
4476 :sources
4477 `(((name . ,(format "%s History" name))
4478 (header-name . (lambda (name)
4479 (concat name anything-c-find-files-doc-header)))
4480 (disable-shortcuts)
4481 (mode-line . anything-read-file-name-mode-line-string)
4482 (candidates . (lambda ()
4483 (anything-comp-read-get-candidates history nil nil alistp)))
4484 (persistent-action . ,persistent-action)
4485 (persistent-help . ,persistent-help)
4486 (action . ,'action-fn))
4487 ((name . ,name)
4488 (header-name . (lambda (name)
4489 (concat name anything-c-find-files-doc-header)))
4490 ;; It is needed for filenames with capital letters
4491 (disable-shortcuts)
4492 (mode-line . anything-read-file-name-mode-line-string)
4493 (candidates . (lambda ()
4494 (let ((seq (anything-find-files-get-candidates)))
4495 (if test
4496 (loop for fname in seq
4497 when (funcall test fname) collect fname)
4498 seq))))
4499 (filtered-candidate-transformer anything-c-find-files-transformer)
4500 (persistent-action . ,persistent-action)
4501 (candidate-number-limit . 9999)
4502 (toggle-auto-update . anything-ff-toggle-auto-update)
4503 (persistent-help . ,persistent-help)
4504 (volatile)
4505 (action . ,'action-fn)))
4506 :input initial-input
4507 :prompt prompt
4508 :keymap anything-c-read-file-map
4509 :resume 'noresume
4510 :buffer buffer
4511 :preselect preselect)
4512 (keyboard-quit)))))
4515 ;;; File Cache
4516 (defvar anything-c-file-cache-initialized-p nil)
4518 (defvar anything-c-file-cache-files nil)
4520 (defvar anything-c-source-file-cache
4521 '((name . "File Cache")
4522 (init
4523 . (lambda ()
4524 (require 'filecache nil t)
4525 (unless anything-c-file-cache-initialized-p
4526 (setq anything-c-file-cache-files
4527 (loop for item in file-cache-alist append
4528 (destructuring-bind (base &rest dirs) item
4529 (loop for dir in dirs collect
4530 (concat dir base)))))
4531 (defadvice file-cache-add-file (after file-cache-list activate)
4532 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4533 (setq anything-c-file-cache-initialized-p t))))
4534 (candidates . anything-c-file-cache-files)
4535 (match anything-c-match-on-basename)
4536 (type . file)))
4537 ;; (anything 'anything-c-source-file-cache)
4540 ;;; Locate
4543 ;; NOTE for WINDOZE users:
4544 ;; You have to install Everything with his command line interface here:
4545 ;; http://www.voidtools.com/download.php
4547 (defun anything-locate-1 (&optional localdb init)
4548 "Generic function to run Locate.
4549 if LOCALDB is non--nil search and use a local locate db file.
4550 INIT is a string to use as initial input in prompt.
4551 See `anything-locate-with-db' and `anything-locate'."
4552 (anything-locate-with-db
4553 (and localdb
4554 (anything-c-read-file-name
4555 "LocateDBFiles: "
4556 :marked-candidates t
4557 :preselect anything-locate-db-file-regexp
4558 :test #'(lambda (x)
4559 (if anything-locate-db-file-regexp
4560 ;; Select only locate db files and directories
4561 ;; to allow navigation.
4562 (or (string-match
4563 anything-locate-db-file-regexp x)
4564 (file-directory-p x))
4565 x))))
4566 init))
4567 ;; (anything-locate-1 t)
4569 (defun anything-locate-with-db (&optional db initial-input)
4570 "Run locate -d DB.
4571 If DB is not given or nil use locate without -d option.
4572 Argument DB can be given as a string or list of db files.
4573 Argument INITIAL-INPUT is a string to use as initial-input.
4574 See also `anything-locate'."
4575 (when (and db (stringp db)) (setq db (list db)))
4576 (let ((anything-c-locate-command
4577 (if db
4578 (replace-regexp-in-string
4579 "locate"
4580 (format "locate -d %s"
4581 (mapconcat 'identity
4582 ;; Remove eventually
4583 ;; marked directories by error.
4584 (loop for i in db
4585 unless (file-directory-p i)
4586 collect i) ":"))
4587 anything-c-locate-command)
4588 anything-c-locate-command)))
4589 (anything :sources 'anything-c-source-locate
4590 :buffer "*anything locate*"
4591 :input initial-input
4592 :keymap anything-generic-files-map)))
4593 ;; (anything-locate-with-db "~/locate.db")
4595 (defun anything-c-locate-init ()
4596 "Initialize async locate process for `anything-c-source-locate'."
4597 (setq mode-line-format
4598 '(" " mode-line-buffer-identification " "
4599 (line-number-mode "%l") " "
4600 (:eval (propertize "(Locate Process Running) "
4601 'face '((:foreground "red"))))))
4602 (prog1
4603 (start-process-shell-command "locate-process" nil
4604 (format anything-c-locate-command
4605 anything-pattern))
4606 (set-process-sentinel (get-process "locate-process")
4607 #'(lambda (process event)
4608 (when (string= event "finished\n")
4609 (with-anything-window
4610 (force-mode-line-update nil)
4611 (anything-update-move-first-line)))))))
4613 (defvar anything-c-source-locate
4614 '((name . "Locate")
4615 (candidates . anything-c-locate-init)
4616 (type . file)
4617 (properties-action . anything-ff-properties)
4618 (requires-pattern . 3)
4619 (candidate-number-limit . 9999)
4620 (mode-line . anything-generic-file-mode-line-string)
4621 (delayed))
4622 "Find files matching the current input pattern with locate.")
4623 ;; (anything 'anything-c-source-locate)
4625 (defun anything-c-locate-read-file-name (prompt &optional init)
4626 "Search a file with locate and return it's filename.
4627 Use argument PROMPT and INIT for `anything' arguments
4628 prompt and input."
4629 (anything :sources
4630 '((name . "Locate")
4631 (candidates . anything-c-locate-init)
4632 (action . identity)
4633 (properties-action . anything-ff-properties)
4634 (requires-pattern . 3)
4635 (candidate-number-limit . 9999)
4636 (mode-line . anything-generic-file-mode-line-string)
4637 (delayed))
4638 :prompt prompt
4639 :input init
4640 :buffer "*anything locate rfn*"))
4644 ;;; Anything Incremental Grep.
4647 ;; Allow to grep incrementally with anything interface.
4648 ;; It allow also to Grep files recursively without using 'find' shell command.
4649 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4650 (defvar anything-c-grep-default-command
4651 "grep -d skip %e -niH -e %p %f"
4652 "Default grep format command for `anything-do-grep-1'.
4653 Where:
4654 '%e' format spec is for --exclude or --include grep options.
4655 '%p' format spec is for pattern.
4656 '%f' format spec is for filenames.")
4658 (defvar anything-c-grep-default-recurse-command
4659 "grep -d recurse %e -niH -e %p %f"
4660 "Default recursive grep format command for `anything-do-grep-1'.
4661 See `anything-c-grep-default-command' for format specs.")
4663 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4665 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4667 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4669 (defvar anything-c-grep-debug-command-line nil
4670 "Turn on anything grep command-line debugging when non--nil.")
4672 (defvar anything-c-zgrep-recurse-flag nil)
4674 (defvar anything-c-grep-history nil)
4676 (defvar anything-c-grep-max-length-history 100
4677 "*Max number of elements to save in `anything-c-grep-history'.")
4679 (defun anything-c-grep-prepare-candidates (candidates)
4680 "Prepare filenames and directories CANDIDATES for grep command line."
4681 ;; If one or more candidate is a directory, search in all files
4682 ;; of this candidate (e.g /home/user/directory/*).
4683 ;; If r option is enabled search also in subdidrectories.
4684 ;; We need here to expand wildcards to support crap windows filenames
4685 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4686 (if anything-c-zgrep-recurse-flag
4687 (mapconcat 'shell-quote-argument candidates " ")
4688 (loop for i in candidates append
4689 (cond ( ;; Candidate is a directory and we use recursion.
4690 (and (file-directory-p i)
4691 (anything-c-grep-recurse-p))
4692 (list (expand-file-name i)))
4693 ;; Candidate is a directory, search in all files.
4694 ((file-directory-p i)
4695 (file-expand-wildcards
4696 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4697 ;; Candidate is a file or wildcard and we use recursion, use the
4698 ;; current directory instead of candidate.
4699 ((and (or (file-exists-p i) (string-match "\*" i))
4700 (anything-c-grep-recurse-p))
4701 (list (expand-file-name
4702 (directory-file-name ; Needed for windoze.
4703 (file-name-directory (directory-file-name i))))))
4704 ;; Candidate use wildcard.
4705 ((string-match "^\*" (anything-c-basename i))
4706 (file-expand-wildcards i t))
4707 ;; Else should be one or more file.
4708 (t (list i))) into all-files
4709 finally return
4710 (mapconcat 'shell-quote-argument all-files " "))))
4712 (defun anything-c-grep-recurse-p ()
4713 "Check if `anything-do-grep-1' have switched to recursive."
4714 (let ((args (replace-regexp-in-string
4715 "grep" "" anything-c-grep-default-command)))
4716 (string-match-p "r\\|recurse" args)))
4718 (defun anything-c-grep-init (only-files &optional include zgrep)
4719 "Start an asynchronous grep process in ONLY-FILES list."
4720 (let* ((fnargs (anything-c-grep-prepare-candidates
4721 (if (file-remote-p anything-ff-default-directory)
4722 (mapcar #'(lambda (x)
4723 (file-remote-p x 'localname))
4724 only-files)
4725 only-files)))
4726 (ignored-files (mapconcat
4727 #'(lambda (x)
4728 (concat "--exclude=" (shell-quote-argument x)))
4729 grep-find-ignored-files " "))
4730 (ignored-dirs (mapconcat
4731 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4732 #'(lambda (x)
4733 (concat "--exclude-dir=" (shell-quote-argument x)))
4734 grep-find-ignored-directories " "))
4735 (exclude (if (anything-c-grep-recurse-p)
4736 (concat (or include ignored-files) " " ignored-dirs)
4737 ignored-files))
4738 (cmd-line (format-spec
4739 anything-c-grep-default-command
4740 (delq nil
4741 (list (unless zgrep (cons ?e exclude))
4742 (cons ?p (shell-quote-argument anything-pattern))
4743 (cons ?f fnargs))))))
4744 (when anything-c-grep-debug-command-line
4745 (with-current-buffer (get-buffer-create "*any grep debug*")
4746 (goto-char (point-max))
4747 (insert (concat ">>> " cmd-line "\n\n"))))
4748 (setq mode-line-format
4749 '(" " mode-line-buffer-identification " "
4750 (line-number-mode "%l") " "
4751 (:eval (when (get-process "grep-process")
4752 (propertize "[Grep Process Running] "
4753 'face 'anything-grep-running)))))
4754 (force-mode-line-update nil)
4755 (prog1
4756 (let ((default-directory anything-ff-default-directory))
4757 (start-file-process-shell-command "grep-process" nil cmd-line))
4758 (message nil)
4759 (set-process-sentinel
4760 (get-process "grep-process")
4761 #'(lambda (process event)
4762 (when (string= event "finished\n")
4763 (with-anything-window
4764 (anything-update-move-first-line)
4765 (setq mode-line-format
4766 '(" " mode-line-buffer-identification " "
4767 (line-number-mode "%l") " "
4768 (:eval (propertize
4769 (format "[Grep Process Finished - (%s results)] "
4770 (let ((nlines (1- (count-lines
4771 (point-min)
4772 (point-max)))))
4773 (if (> nlines 0) nlines 0)))
4774 'face 'anything-grep-finish))))
4775 (force-mode-line-update nil))))))))
4777 (defun anything-c-grep-action (candidate &optional where mark)
4778 "Define a default action for `anything-do-grep' on CANDIDATE.
4779 WHERE can be one of other-window, elscreen, other-frame."
4780 (let* ((split (anything-c-grep-split-line candidate))
4781 (lineno (string-to-number (nth 1 split)))
4782 (loc-fname (car split))
4783 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4784 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4785 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4786 (fname (if tramp-host
4787 (concat tramp-prefix loc-fname) loc-fname)))
4788 (case where
4789 (other-window (find-file-other-window fname))
4790 (elscreen (anything-elscreen-find-file fname))
4791 (other-frame (find-file-other-frame fname))
4792 (t (find-file fname)))
4793 (anything-goto-line lineno)
4794 (when mark
4795 (set-marker (mark-marker) (point))
4796 (push-mark (point) 'nomsg))
4797 ;; Save history
4798 (unless (or anything-in-persistent-action
4799 (string= anything-pattern ""))
4800 (setq anything-c-grep-history
4801 (cons anything-pattern
4802 (delete anything-pattern anything-c-grep-history)))
4803 (when (> (length anything-c-grep-history)
4804 anything-c-grep-max-length-history)
4805 (setq anything-c-grep-history
4806 (delete (car (last anything-c-grep-history))
4807 anything-c-grep-history))))))
4809 (defun anything-c-grep-other-window (candidate)
4810 "Jump to result in other window from anything grep."
4811 (anything-c-grep-action candidate 'other-window))
4813 (defun anything-c-grep-other-frame (candidate)
4814 "Jump to result in other frame from anything grep."
4815 (anything-c-grep-action candidate 'other-frame))
4817 (defun anything-c-grep-jump-elscreen (candidate)
4818 "Jump to result in elscreen from anything grep."
4819 (anything-c-grep-action candidate 'elscreen))
4821 (defun anything-c-grep-save-results (candidate)
4822 "Save anything grep result in a `grep-mode' buffer."
4823 (let ((buf "*grep*")
4824 new-buf)
4825 (when (get-buffer buf)
4826 (setq new-buf (read-string "GrepBufferName: " buf))
4827 (loop for b in (anything-c-buffer-list)
4828 when (and (string= new-buf b)
4829 (not (y-or-n-p
4830 (format "Buffer `%s' already exists overwrite? "
4831 new-buf))))
4832 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4833 (setq buf new-buf))
4834 (with-current-buffer (get-buffer-create buf)
4835 (let ((inhibit-read-only t))
4836 (erase-buffer)
4837 (insert "-*- mode: grep -*-\n\n"
4838 (format "Grep Results for `%s':\n\n" anything-pattern))
4839 (save-excursion
4840 (insert (with-current-buffer anything-buffer
4841 (forward-line 1)
4842 (buffer-substring (point) (point-max))))
4843 (grep-mode))))
4844 (message "Anything Grep Results saved in `%s' buffer" buf)))
4846 (defun anything-c-grep-persistent-action (candidate)
4847 "Persistent action for `anything-do-grep'.
4848 With a prefix arg record CANDIDATE in `mark-ring'."
4849 (if current-prefix-arg
4850 (anything-c-grep-action candidate nil 'mark)
4851 (anything-c-grep-action candidate))
4852 (anything-match-line-color-current-line))
4854 (defun anything-c-grep-guess-extensions (files)
4855 "Try to guess file extensions in FILES list when using grep recurse.
4856 These extensions will be added to command line with --include arg of grep."
4857 (loop
4858 with glob-list = nil
4859 with lst = (if (file-directory-p (car files))
4860 (directory-files
4861 (car files) nil
4862 directory-files-no-dot-files-regexp)
4863 files)
4864 for i in lst
4865 for ext = (file-name-extension i t)
4866 for glob = (and ext (not (string= ext ""))
4867 (concat "*" ext))
4868 unless (or (not glob)
4869 (member glob glob-list)
4870 (member glob grep-find-ignored-files))
4871 collect glob into glob-list
4872 finally return glob-list))
4874 (defun anything-do-grep-1 (only &optional recurse zgrep)
4875 "Launch grep with a list of ONLY files.
4876 When RECURSE is given use -r option of grep and prompt user
4877 to set the --include args of grep.
4878 You can give more than one arg separated by space.
4879 e.g *.el *.py *.tex.
4880 If it's empty --exclude `grep-find-ignored-files' is used instead."
4881 (let* ((anything-compile-source-functions
4882 ;; rule out anything-match-plugin because the input is one regexp.
4883 (delq 'anything-compile-source--match-plugin
4884 (copy-sequence anything-compile-source-functions)))
4885 (exts (anything-c-grep-guess-extensions only))
4886 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4887 (include-files (and recurse (not zgrep)
4888 (read-string "OnlyExt(*.[ext]): "
4889 globs)))
4890 ;; Set `minibuffer-history' AFTER includes-files
4891 ;; to avoid storing wild-cards here.
4892 (minibuffer-history anything-c-grep-history)
4893 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4894 (recurse anything-c-grep-default-recurse-command)
4895 (zgrep anything-c-default-zgrep-command)
4896 (t anything-c-grep-default-command)))
4897 ;; Disable match-plugin and use here own highlighting.
4898 (anything-mp-highlight-delay nil))
4899 (when include-files
4900 (setq include-files
4901 (and (not (string= include-files ""))
4902 (mapconcat #'(lambda (x)
4903 (concat "--include=" (shell-quote-argument x)))
4904 (split-string include-files) " "))))
4905 ;; When called as action from an other source e.g *-find-files
4906 ;; we have to kill action buffer.
4907 (when (get-buffer anything-action-buffer)
4908 (kill-buffer anything-action-buffer))
4909 ;; `anything-find-files' haven't already started,
4910 ;; give a default value to `anything-ff-default-directory'.
4911 (setq anything-ff-default-directory (or anything-ff-default-directory
4912 default-directory))
4913 (anything
4914 :sources
4915 `(((name . "Grep (C-c ? Help)")
4916 (candidates
4917 . (lambda ()
4918 (funcall anything-c-grep-default-function only include-files zgrep)))
4919 (filtered-candidate-transformer anything-c-grep-cand-transformer)
4920 (candidate-number-limit . 9999)
4921 (mode-line . anything-grep-mode-line-string)
4922 (jump-persistent . anything-c-grep-persistent-action)
4923 (action . ,(delq
4925 `(("Find File" . anything-c-grep-action)
4926 ("Find file other frame" . anything-c-grep-other-frame)
4927 ,(and (locate-library "elscreen")
4928 '("Find file in Elscreen"
4929 . anything-c-grep-jump-elscreen))
4930 ("Save results in grep buffer" . anything-c-grep-save-results)
4931 ("Find file other window" . anything-c-grep-other-window))))
4932 (persistent-action . anything-c-grep-persistent-action)
4933 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
4934 (requires-pattern . 3)
4935 (delayed)))
4936 :keymap anything-c-grep-map
4937 :buffer "*anything grep*")))
4939 (defun anything-ff-zgrep-1 (flist recursive)
4940 (unwind-protect
4941 (let* ((def-dir (or anything-ff-default-directory
4942 default-directory))
4943 (only (if recursive
4944 (or (gethash def-dir anything-c-rzgrep-cache)
4945 (puthash
4946 def-dir
4947 (anything-c-walk-directory
4948 def-dir
4949 :directories nil
4950 :path 'full
4951 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
4952 anything-c-rzgrep-cache))
4953 flist)))
4954 (when recursive (setq anything-c-zgrep-recurse-flag t))
4955 (anything-do-grep-1 only recursive 'zgrep))
4956 (setq anything-c-zgrep-recurse-flag nil)))
4958 (defun anything-c-grep-split-line (line)
4959 "Split a grep output line."
4960 (let (beg fname lineno str)
4961 ;; Don't print until grep line is valid.
4962 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
4963 (with-temp-buffer
4964 (insert line)
4965 (goto-char (point-min))
4966 (setq beg (point))
4967 (forward-char 2)
4968 (re-search-forward ":" nil t)
4969 (setq fname (buffer-substring-no-properties beg (1- (point))))
4970 (setq beg (point))
4971 (re-search-forward ":" nil t)
4972 (setq lineno (buffer-substring-no-properties beg (1- (point))))
4973 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
4974 (list fname lineno str))))
4976 (defun anything-c-grep-cand-transformer (candidates sources)
4977 "Filtered candidate transformer function for `anything-do-grep'."
4978 (loop for i in candidates
4979 for split = (and i (anything-c-grep-split-line i))
4980 for fname = (car split)
4981 for lineno = (nth 1 split)
4982 for str = (nth 2 split)
4983 when (and fname lineno str)
4984 collect
4985 (cons (concat (propertize (file-name-nondirectory fname)
4986 'face 'anything-grep-file
4987 'help-echo fname) ":"
4988 (propertize lineno 'face 'anything-grep-lineno) ":"
4989 (anything-c-grep-highlight-match str))
4990 i)))
4992 (defun anything-c-grep-highlight-match (str)
4993 "Highlight in string STR all occurences matching `anything-pattern'."
4994 (condition-case nil
4995 (with-temp-buffer
4996 (insert str)
4997 (goto-char (point-min))
4998 (while (and (re-search-forward anything-pattern nil t)
4999 (> (- (match-end 0) (match-beginning 0)) 0))
5000 (add-text-properties
5001 (match-beginning 0) (match-end 0)
5002 '(face anything-grep-match)))
5003 (buffer-string))
5004 (error nil)))
5006 ;; Go to next or precedent file (common to etags and grep).
5007 (defun anything-c-goto-next-or-prec-file (n)
5008 "Go to next or precedent candidate file in anything grep/etags buffers.
5009 If N is positive go forward otherwise go backward."
5010 (with-anything-window
5011 (let* ((current-line-list (split-string
5012 (buffer-substring
5013 (point-at-bol)
5014 (point-at-eol)) ":"))
5015 (current-fname (nth 0 current-line-list))
5016 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5017 (catch 'break
5018 (while (not (funcall fn-b-o-f))
5019 (forward-line n) ; Go forward or backward depending of n value.
5020 (unless (search-forward current-fname (point-at-eol) t)
5021 (anything-mark-current-line)
5022 (throw 'break nil))))
5023 (cond ((and (eq n 1) (eobp))
5024 (re-search-backward ".")
5025 (forward-line 0)
5026 (anything-mark-current-line))
5027 ((and (< n 1) (bobp))
5028 (forward-line 1)
5029 (anything-mark-current-line))))))
5031 ;;;###autoload
5032 (defun anything-c-goto-precedent-file ()
5033 "Go to precedent file in anything grep/etags buffers."
5034 (interactive)
5035 (anything-c-goto-next-or-prec-file -1))
5037 ;;;###autoload
5038 (defun anything-c-goto-next-file ()
5039 "Go to precedent file in anything grep/etags buffers."
5040 (interactive)
5041 (anything-c-goto-next-or-prec-file 1))
5043 ;;;###autoload
5044 (defun anything-c-grep-run-persistent-action ()
5045 "Run grep persistent action from `anything-do-grep-1'."
5046 (interactive)
5047 (anything-execute-persistent-action 'jump-persistent))
5049 ;;;###autoload
5050 (defun anything-c-grep-run-default-action ()
5051 "Run grep default action from `anything-do-grep-1'."
5052 (interactive)
5053 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5055 ;;;###autoload
5056 (defun anything-c-grep-run-other-window-action ()
5057 "Run grep goto other window action from `anything-do-grep-1'."
5058 (interactive)
5059 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5061 ;;;###autoload
5062 (defun anything-c-grep-run-save-buffer ()
5063 "Run grep save results action from `anything-do-grep-1'."
5064 (interactive)
5065 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5067 ;; Grep buffers
5068 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5069 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5070 If one of selected buffers is not a file--buffer,
5071 it is ignored and grep will run on all others file--buffers.
5072 If only one candidate is selected and it is not a file--buffer,
5073 switch to this buffer and run `anything-occur'.
5074 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5075 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5076 (cands (if prefarg
5077 (buffer-list)
5078 (anything-marked-candidates)))
5079 (win-conf (current-window-configuration))
5080 ;; Non--fname buffers are ignored.
5081 (bufs (loop for buf in cands
5082 for fname = (buffer-file-name (get-buffer buf))
5083 when fname
5084 collect (expand-file-name fname))))
5085 (if bufs
5086 (if zgrep
5087 (anything-do-grep-1 bufs nil 'zgrep)
5088 (anything-do-grep-1 bufs))
5089 ;; bufs is empty, thats mean we have only CANDIDATE
5090 ;; and it is not a buffer-filename, fallback to occur.
5091 (anything-c-switch-to-buffer candidate)
5092 (when (get-buffer anything-action-buffer)
5093 (kill-buffer anything-action-buffer))
5094 (anything-occur)
5095 (when (eq anything-exit-status 1)
5096 (set-window-configuration win-conf)))))
5098 (defun anything-c-grep-buffers (candidate)
5099 "Action to grep buffers."
5100 (anything-c-grep-buffers-1 candidate))
5102 (defun anything-c-zgrep-buffers (candidate)
5103 "Action to zgrep buffers."
5104 (anything-c-grep-buffers-1 candidate 'zgrep))
5107 ;;; Anything interface for pdfgrep
5108 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5109 ;; and a pdf-reader (e.g xpdf) are needed.
5111 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5112 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5113 (defvar anything-c-pdfgrep-debug-command-line nil)
5115 (defun anything-c-pdfgrep-init (only-files)
5116 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5117 (let* ((fnargs (anything-c-grep-prepare-candidates
5118 (if (file-remote-p anything-ff-default-directory)
5119 (mapcar #'(lambda (x)
5120 (file-remote-p x 'localname))
5121 only-files)
5122 only-files)))
5123 (cmd-line (format anything-c-pdfgrep-default-command
5124 anything-pattern
5125 fnargs)))
5126 (when anything-c-pdfgrep-debug-command-line
5127 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5128 (goto-char (point-max))
5129 (insert (concat ">>> " cmd-line "\n\n"))))
5130 (setq mode-line-format
5131 '(" " mode-line-buffer-identification " "
5132 (line-number-mode "%l") " "
5133 (:eval (propertize "(Pdfgrep Process Running) "
5134 'face '((:foreground "red"))))))
5135 (prog1
5136 (let ((default-directory anything-ff-default-directory))
5137 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5138 (message nil)
5139 (set-process-sentinel
5140 (get-process "pdfgrep-process")
5141 #'(lambda (process event)
5142 (when (string= event "finished\n")
5143 (with-anything-window
5144 (anything-update-move-first-line))
5145 (force-mode-line-update nil)))))))
5148 (defun anything-do-pdfgrep-1 (only)
5149 "Launch pdfgrep with a list of ONLY files."
5150 (unless (executable-find "pdfgrep")
5151 (error "Error: No such program `pdfgrep'."))
5152 (let* ((anything-compile-source-functions
5153 ;; rule out anything-match-plugin because the input is one regexp.
5154 (delq 'anything-compile-source--match-plugin
5155 (copy-sequence anything-compile-source-functions)))
5156 ;; Disable match-plugin and use here own highlighting.
5157 (anything-mp-highlight-delay nil))
5158 ;; When called as action from an other source e.g *-find-files
5159 ;; we have to kill action buffer.
5160 (when (get-buffer anything-action-buffer)
5161 (kill-buffer anything-action-buffer))
5162 ;; If `anything-find-files' haven't already started,
5163 ;; give a default value to `anything-ff-default-directory'.
5164 (setq anything-ff-default-directory (or anything-ff-default-directory
5165 default-directory))
5166 (anything
5167 :sources
5168 `(((name . "PdfGrep")
5169 (candidates
5170 . (lambda ()
5171 (funcall anything-c-pdfgrep-default-function only)))
5172 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5173 (candidate-number-limit . 9999)
5174 (mode-line . anything-pdfgrep-mode-line-string)
5175 (action . anything-c-pdfgrep-action)
5176 (persistent-help . "Jump to PDF Page")
5177 (requires-pattern . 3)
5178 (delayed)))
5179 :keymap anything-c-pdfgrep-map
5180 :buffer "*anything grep*")))
5183 (defun anything-c-pdfgrep-action (candidate)
5184 (let* ((split (anything-c-grep-split-line candidate))
5185 (pageno (nth 1 split))
5186 (fname (car split)))
5187 (start-file-process-shell-command
5188 "pdf-reader" nil
5189 (format-spec anything-c-pdfgrep-default-read-command
5190 (list (cons ?f fname) (cons ?p pageno))))))
5192 (defun anything-do-pdfgrep ()
5193 (interactive)
5194 (let ((only (anything-c-read-file-name
5195 "Search in file(s): "
5196 :marked-candidates t
5197 :test #'(lambda (file)
5198 (or (string= (file-name-extension file) "pdf")
5199 (string= (file-name-extension file) "PDF")
5200 (file-directory-p file)))
5201 :preselect (or (dired-get-filename nil t)
5202 (buffer-file-name (current-buffer)))))
5203 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5204 (anything-do-pdfgrep-1 only)))
5207 ;; Yank text at point.
5210 ;; Internal
5211 (defvar anything-yank-point nil)
5213 ;;;###autoload
5214 (defun anything-yank-text-at-point ()
5215 "Yank text at point in minibuffer."
5216 (interactive)
5217 (let (input)
5218 (flet ((insert-in-minibuffer (word)
5219 (with-selected-window (minibuffer-window)
5220 (let ((str anything-pattern))
5221 (delete-minibuffer-contents)
5222 (set-text-properties 0 (length word) nil word)
5223 (insert (concat str word))))))
5224 (with-anything-current-buffer
5225 ;; Start to initial point if C-w have never been hit.
5226 (unless anything-yank-point (setq anything-yank-point (point)))
5227 (and anything-yank-point (goto-char anything-yank-point))
5228 (forward-word 1)
5229 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5230 (setq anything-yank-point (point))) ; End of last forward-word
5231 (insert-in-minibuffer input))))
5233 (defun anything-reset-yank-point ()
5234 (setq anything-yank-point nil))
5236 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5237 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5240 ;;; Recentf files
5243 (defvar anything-c-source-recentf
5244 '((name . "Recentf")
5245 (init . (lambda ()
5246 (require 'recentf)
5247 (or recentf-mode (recentf-mode 1))))
5248 (candidates . recentf-list)
5249 (match anything-c-match-on-basename)
5250 (type . file))
5251 "See (info \"(emacs)File Conveniences\").
5252 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5253 ;; (anything 'anything-c-source-recentf)
5255 ;;; ffap
5256 (eval-when-compile (require 'ffap))
5257 (defvar anything-c-source-ffap-guesser
5258 '((name . "File at point")
5259 (init . (lambda () (require 'ffap)))
5260 (candidates . (lambda ()
5261 (anything-aif
5262 (with-anything-current-buffer
5263 (ffap-guesser))
5264 (list it))))
5265 (type . file)))
5266 ;; (anything 'anything-c-source-ffap-guesser)
5268 ;;; ffap with line number
5269 (defun anything-c-ffap-file-line-at-point ()
5270 "Get (FILENAME . LINENO) at point."
5271 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5272 (save-excursion
5273 (beginning-of-line)
5274 (when (and (search-forward it nil t)
5275 (looking-at ":\\([0-9]+\\)"))
5276 (cons it (string-to-number (match-string 1)))))))
5278 (defvar anything-c-ffap-line-location nil
5279 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5280 It is cleared after jumping line.")
5282 (defun anything-c-ffap-line-candidates ()
5283 (with-anything-current-buffer
5284 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5285 (when anything-c-ffap-line-location
5286 (destructuring-bind (file . line) anything-c-ffap-line-location
5287 (list (cons (format "%s (line %d)" file line) file)))))
5289 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5290 (defun anything-c-ffap-line-goto-line ()
5291 (when (car anything-c-ffap-line-location)
5292 (unwind-protect
5293 (ignore-errors
5294 (with-selected-window
5295 (get-buffer-window
5296 (get-file-buffer (car anything-c-ffap-line-location)))
5297 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5298 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5299 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5301 (defvar anything-c-source-ffap-line
5302 '((name . "File/Lineno at point")
5303 (init . (lambda () (require 'ffap)))
5304 (candidates . anything-c-ffap-line-candidates)
5305 (type . file)))
5306 ;; (anything 'anything-c-source-ffap-line)
5308 ;;; list of files gleaned from every dired buffer
5309 (defun anything-c-files-in-all-dired-candidates ()
5310 (save-excursion
5311 (mapcan
5312 (lambda (dir)
5313 (cond ((listp dir) ;filelist
5314 dir)
5315 ((equal "" (file-name-nondirectory dir)) ;dir
5316 (directory-files dir t))
5317 (t ;wildcard
5318 (file-expand-wildcards dir t))))
5319 (delq nil
5320 (mapcar (lambda (buf)
5321 (set-buffer buf)
5322 (when (eq major-mode 'dired-mode)
5323 (if (consp dired-directory)
5324 (cdr dired-directory) ;filelist
5325 dired-directory))) ;dir or wildcard
5326 (buffer-list))))))
5327 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5329 (defvar anything-c-source-files-in-all-dired
5330 '((name . "Files in all dired buffer.")
5331 (candidates . anything-c-files-in-all-dired-candidates)
5332 (type . file)))
5333 ;; (anything 'anything-c-source-files-in-all-dired)
5335 (defvar anything-c-source-filelist
5336 '((name . "FileList")
5337 (grep-candidates . anything-c-filelist-file-name)
5338 (candidate-number-limit . 200)
5339 (requires-pattern . 4)
5340 (type . file))
5341 "Source to find files instantly.
5342 See `anything-c-filelist-file-name' docstring for usage.")
5345 ;;;; <info>
5346 ;;; Info pages
5347 (defvar anything-c-info-pages nil
5348 "All info pages on system.
5349 Will be calculated the first time you invoke anything with this
5350 source.")
5352 (defun anything-c-info-pages-init ()
5353 "Collect candidates for initial Info node Top."
5354 (if anything-c-info-pages
5355 anything-c-info-pages
5356 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5357 topics)
5358 (require 'info)
5359 (with-temp-buffer
5360 (Info-find-node "dir" "top")
5361 (goto-char (point-min))
5362 (while (re-search-forward info-topic-regexp nil t)
5363 (push (match-string-no-properties 1) topics))
5364 (kill-buffer))
5365 (setq anything-c-info-pages topics))))
5367 (defvar anything-c-source-info-pages
5368 `((name . "Info Pages")
5369 (init . anything-c-info-pages-init)
5370 (candidates . anything-c-info-pages)
5371 (action . (("Show with Info" .(lambda (node-str)
5372 (info (replace-regexp-in-string
5373 "^[^:]+: " "" node-str))))))
5374 (requires-pattern . 2)))
5375 ;; (anything 'anything-c-source-info-pages)
5378 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5379 (defun anything-c-describe-attributes (anything-attribute)
5380 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5381 Same as `anything-describe-anything-attribute' but with anything completion."
5382 (interactive (list (intern
5383 (anything-comp-read
5384 "Describe anything attribute: "
5385 (mapcar 'symbol-name anything-additional-attributes)
5386 :must-match t
5387 :persistent-action
5388 #'(lambda (candidate)
5389 (with-output-to-temp-buffer "*Help*"
5390 (princ (get (intern candidate) 'anything-attrdoc))))))))
5391 (with-output-to-temp-buffer "*Help*"
5392 (princ (get anything-attribute 'anything-attrdoc))))
5395 ;;; Use info-index plug-in.
5398 ;; Note that `name' attribute is not needed since
5399 ;; `anything-c-insert-summary' have been removed.
5400 ;; Info Elisp
5401 (defvar anything-c-source-info-elisp
5402 '((name . "Info index: elisp")
5403 (info-index . "elisp")))
5404 ;; (anything 'anything-c-source-info-elisp)
5406 ;; Info-Common-Lisp
5407 (defvar anything-c-source-info-cl
5408 '((name . "Info index: cl")
5409 (info-index . "cl")))
5410 ;; (anything 'anything-c-source-info-cl)
5412 ;; Info Index org
5413 (defvar anything-c-source-info-org
5414 '((name . "Info index: org")
5415 (info-index . "org")))
5416 ;; (anything 'anything-c-source-info-org)
5418 ;; Info Index gnus
5419 (defvar anything-c-source-info-gnus
5420 '((name . "Info index: Gnus")
5421 (info-index . "gnus")))
5423 ;; Info Index ratpoison
5424 (defvar anything-c-source-info-ratpoison
5425 '((name . "Info index: ratpoison")
5426 (info-index . "ratpoison")))
5427 ;; (anything 'anything-c-source-info-ratpoison)
5429 ;; Info Index zsh
5430 (defvar anything-c-source-info-zsh
5431 '((name . "Info index: zsh")
5432 (info-index . "zsh")))
5433 ;; (anything 'anything-c-source-info-zsh)
5435 ;; Info Index bash
5436 (defvar anything-c-source-info-bash
5437 '((name . "Info index: bash")
5438 (info-index . "bash")))
5439 ;; (anything 'anything-c-source-info-bash)
5441 ;; Info Index coreutils
5442 (defvar anything-c-source-info-coreutils
5443 '((name . "Info index: coreutils")
5444 (info-index . "coreutils")))
5445 ;; (anything 'anything-c-source-info-coreutils)
5447 ;; Info Index fileutils
5448 (defvar anything-c-source-info-fileutils
5449 '((name . "Info index: fileutils")
5450 (info-index . "fileutils")))
5451 ;; (anything 'anything-c-source-info-fileutils)
5453 ;; Info Index find
5454 (defvar anything-c-source-info-find
5455 '((name . "Info index: find")
5456 (info-index . "find")))
5457 ;; (anything 'anything-c-source-info-find)
5459 ;; Info Index sh-utils
5460 (defvar anything-c-source-info-sh-utils
5461 '((name . "Info index: sh-utils")
5462 (info-index . "sh-utils")))
5463 ;; (anything 'anything-c-source-info-sh-utils)
5465 ;; Info Index textutils
5466 (defvar anything-c-source-info-textutils
5467 '((name . "Info index: textutils")
5468 (info-index . "textutils")))
5469 ;; (anything 'anything-c-source-info-textutils)
5471 ;; Info Index libc
5472 (defvar anything-c-source-info-libc
5473 '((name . "Info index: libc")
5474 (info-index . "libc")))
5475 ;; (anything 'anything-c-source-info-libc)
5477 ;; Info Index make
5478 (defvar anything-c-source-info-make
5479 '((name . "Info index: make")
5480 (info-index . "make")))
5481 ;; (anything 'anything-c-source-info-make)
5483 ;; Info Index automake
5484 (defvar anything-c-source-info-automake
5485 '((name . "Info index: automake")
5486 (info-index . "automake")))
5487 ;; (anything 'anything-c-source-info-automake)
5489 ;; Info Index autoconf
5490 (defvar anything-c-source-info-autoconf
5491 '((name . "Info index: autoconf")
5492 (info-index . "autoconf")))
5493 ;; (anything 'anything-c-source-info-autoconf)
5495 ;; Info Index emacs-lisp-intro
5496 (defvar anything-c-source-info-emacs-lisp-intro
5497 '((name . "Info index: emacs-lisp-intro")
5498 (info-index . "emacs-lisp-intro")))
5499 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5501 ;; Info Index emacs
5502 (defvar anything-c-source-info-emacs
5503 '((name . "Info index: emacs")
5504 (info-index . "emacs")))
5505 ;; (anything 'anything-c-source-info-emacs)
5507 ;; Info Index elib
5508 (defvar anything-c-source-info-elib
5509 '((name . "Info index: elib")
5510 (info-index . "elib")))
5511 ;; (anything 'anything-c-source-info-elib)
5513 ;; Info Index eieio
5514 (defvar anything-c-source-info-eieio
5515 '((name . "Info index: eieio")
5516 (info-index . "eieio")))
5517 ;; (anything 'anything-c-source-info-eieio)
5519 ;; Info Index gauche-refe
5520 (defvar anything-c-source-info-gauche-refe
5521 '((name . "Info index: gauche")
5522 (info-index . "gauche-refe")))
5523 ;; (anything 'anything-c-source-info-gauche-refe)
5525 ;; Info Index guile
5526 (defvar anything-c-source-info-guile
5527 '((name . "Info index: guile")
5528 (info-index . "guile")))
5529 ;; (anything 'anything-c-source-info-guile)
5531 ;; Info Index guile-tut
5532 (defvar anything-c-source-info-guile-tut
5533 '((name . "Info index: guile-tut")
5534 (info-index . "guile-tut")))
5535 ;; (anything 'anything-c-source-info-guile-tut)
5537 ;; Info Index goops
5538 (defvar anything-c-source-info-goops
5539 '((name . "Info index: goops")
5540 (info-index . "goops")))
5541 ;; (anything 'anything-c-source-info-goops)
5543 ;; Info Index screen
5544 (defvar anything-c-source-info-screen
5545 '((name . "Info index: screen")
5546 (info-index . "screen")
5547 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5548 ;; (anything 'anything-c-source-info-screen)
5550 ;; Info Index latex
5551 (defvar anything-c-source-info-latex
5552 '((name . "Info index: latex")
5553 (info-index . "latex")))
5554 ;; (anything 'anything-c-source-info-latex)
5556 ;; Info Index gawk
5557 (defvar anything-c-source-info-gawk
5558 '((name . "Info index: gawk")
5559 (info-index . "gawk")))
5560 ;; (anything 'anything-c-source-info-gawk)
5562 ;; Info Index sed
5563 (defvar anything-c-source-info-sed
5564 '((name . "Info index: sed")
5565 (info-index . "sed")))
5566 ;; (anything 'anything-c-source-info-sed)
5568 ;; Info Index m4
5569 (defvar anything-c-source-info-m4
5570 '((name . "Info index: m4")
5571 (info-index . "m4")))
5572 ;; (anything 'anything-c-source-info-m4)
5574 ;; Info Index wget
5575 (defvar anything-c-source-info-wget
5576 '((name . "Info index: wget")
5577 (info-index . "wget")))
5578 ;; (anything 'anything-c-source-info-wget)
5580 ;; Info Index binutils
5581 (defvar anything-c-source-info-binutils
5582 '((name . "Info index: binutils")
5583 (info-index . "binutils")))
5584 ;; (anything 'anything-c-source-info-binutils)
5586 ;; Info Index as
5587 (defvar anything-c-source-info-as
5588 '((name . "Info index: as")
5589 (info-index . "as")))
5590 ;; (anything 'anything-c-source-info-as)
5592 ;; Info Index bfd
5593 (defvar anything-c-source-info-bfd
5594 '((name . "Info index: bfd")
5595 (info-index . "bfd")))
5596 ;; (anything 'anything-c-source-info-bfd)
5598 ;; Info Index gprof
5599 (defvar anything-c-source-info-gprof
5600 '((name . "Info index: gprof")
5601 (info-index . "gprof")))
5602 ;; (anything 'anything-c-source-info-gprof)
5604 ;; Info Index ld
5605 (defvar anything-c-source-info-ld
5606 '((name . "Info index: ld")
5607 (info-index . "ld")))
5608 ;; (anything 'anything-c-source-info-ld)
5610 ;; Info Index diff
5611 (defvar anything-c-source-info-diff
5612 '((name . "Info index: diff")
5613 (info-index . "diff")))
5614 ;; (anything 'anything-c-source-info-diff)
5616 ;; Info Index flex
5617 (defvar anything-c-source-info-flex
5618 '((name . "Info index: flex")
5619 (info-index . "flex")))
5620 ;; (anything 'anything-c-source-info-flex)
5622 ;; Info Index grep
5623 (defvar anything-c-source-info-grep
5624 '((name . "Info index: grep")
5625 (info-index . "grep")))
5626 ;; (anything 'anything-c-source-info-grep)
5628 ;; Info Index gzip
5629 (defvar anything-c-source-info-gzip
5630 '((name . "Info index: gzip")
5631 (info-index . "gzip")))
5632 ;; (anything 'anything-c-source-info-gzip)
5634 ;; Info Index libtool
5635 (defvar anything-c-source-info-libtool
5636 '((name . "Info index: libtool")
5637 (info-index . "libtool")))
5638 ;; (anything 'anything-c-source-info-libtool)
5640 ;; Info Index texinfo
5641 (defvar anything-c-source-info-texinfo
5642 '((name . "Info index: texinfo")
5643 (info-index . "texinfo")))
5644 ;; (anything 'anything-c-source-info-texinfo)
5646 ;; Info Index info
5647 (defvar anything-c-source-info-info
5648 '((name . "Info index: info")
5649 (info-index . "info")))
5650 ;; (anything 'anything-c-source-info-info)
5652 ;; Info Index gdb
5653 (defvar anything-c-source-info-gdb
5654 '((name . "Info index: gdb")
5655 (info-index . "gdb")))
5656 ;; (anything 'anything-c-source-info-gdb)
5658 ;; Info Index stabs
5659 (defvar anything-c-source-info-stabs
5660 '((name . "Info index: stabs")
5661 (info-index . "stabs")))
5662 ;; (anything 'anything-c-source-info-stabs)
5664 ;; Info Index cvsbook
5665 (defvar anything-c-source-info-cvsbook
5666 '((name . "Info index: cvsbook")
5667 (info-index . "cvsbook")))
5668 ;; (anything 'anything-c-source-info-cvsbook)
5670 ;; Info Index cvs
5671 (defvar anything-c-source-info-cvs
5672 '((name . "Info index: cvs")
5673 (info-index . "cvs")))
5674 ;; (anything 'anything-c-source-info-cvs)
5676 ;; Info Index bison
5677 (defvar anything-c-source-info-bison
5678 '((name . "Info index: bison")
5679 (info-index . "bison")))
5680 ;; (anything 'anything-c-source-info-bison)
5682 ;; Info Index id-utils
5683 (defvar anything-c-source-info-id-utils
5684 '((name . "Info index: id-utils")
5685 (info-index . "id-utils")))
5686 ;; (anything 'anything-c-source-info-id-utils)
5688 ;; Info Index global
5689 (defvar anything-c-source-info-global
5690 '((name . "Info index: global")
5691 (info-index . "global")))
5692 ;; (anything 'anything-c-source-info-global)
5695 ;;;; <Help>
5696 ;;; Man and woman UI
5699 (defvar anything-c-man-pages nil
5700 "All man pages on system.
5701 Will be calculated the first time you invoke anything with this
5702 source.")
5704 (defun anything-c-man-default-action (candidate)
5705 "Default action for jumping to a woman or man page from anything."
5706 (let ((wfiles (woman-file-name-all-completions candidate)))
5707 (condition-case err
5708 (if (> (length wfiles) 1)
5709 (woman-find-file
5710 (anything-comp-read
5711 "ManFile: " wfiles :must-match t))
5712 (woman candidate))
5713 ;; If woman is unable to format correctly
5714 ;; use man instead.
5715 (error (kill-buffer) ; Kill woman buffer.
5716 (let ((Man-notify-method 'meek))
5717 (Man-getpage-in-background candidate))))))
5719 (defvar anything-c-source-man-pages
5720 `((name . "Manual Pages")
5721 (candidates . (lambda ()
5722 (if anything-c-man-pages
5723 anything-c-man-pages
5724 ;; XEmacs doesn't have a woman :)
5725 (setq anything-c-man-pages
5726 (ignore-errors
5727 (require 'woman)
5728 (woman-file-name "")
5729 (sort (mapcar 'car woman-topic-all-completions)
5730 'string-lessp))))))
5731 (action ("Show with Woman" . anything-c-man-default-action))
5732 ;; Woman does not work OS X
5733 ;; http://xahlee.org/emacs/modernization_man_page.html
5734 (action-transformer . (lambda (actions candidate)
5735 (if (eq system-type 'darwin)
5736 '(("Show with Man" . man))
5737 actions)))
5738 (requires-pattern . 2)))
5739 ;; (anything 'anything-c-source-man-pages)
5742 ;;;; <Command>
5743 ;;; Complex command history
5746 (defvar anything-c-source-complex-command-history
5747 '((name . "Complex Command History")
5748 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5749 (type . sexp)))
5750 ;; (anything 'anything-c-source-complex-command-history)
5752 ;;; M-x history (not related to `anything-M-x')
5755 (defvar anything-c-source-extended-command-history
5756 '((name . "Emacs Commands History")
5757 (candidates . extended-command-history)
5758 (type . command)))
5759 ;; (anything 'anything-c-source-extended-command-history)
5761 ;;; Emacs commands (Basic source for emacs commands)
5764 (defvar anything-c-source-emacs-commands
5765 '((name . "Emacs Commands")
5766 (candidates . (lambda ()
5767 (let (commands)
5768 (mapatoms (lambda (a)
5769 (if (commandp a)
5770 (push (symbol-name a)
5771 commands))))
5772 (sort commands 'string-lessp))))
5773 (type . command)
5774 (requires-pattern . 2))
5775 "Source for completing and invoking Emacs commands.
5776 A command is a function with interactive spec that can
5777 be invoked with `M-x'.
5779 To get non-interactive functions listed, use
5780 `anything-c-source-emacs-functions'.")
5781 ;; (anything 'anything-c-source-emacs-commands)
5784 ;;; Anything M-x - Enhanced M-x UI
5787 ;; Another replacement of `M-x' that act exactly like the
5788 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5789 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5790 ;; anything invocation.
5791 ;; Documentation of commands available without quitting,
5792 ;; Show keybindings of commands.
5793 ;; Show history.
5794 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5795 "Return alist of MODE-MAP."
5796 (loop for key being the key-seqs of mode-map using (key-bindings com)
5797 for str-key = (key-description key)
5798 for ismenu = (string-match "<menu-bar>" str-key)
5799 unless ismenu collect (cons str-key com)))
5801 (defun anything-get-mode-map-from-mode (mode)
5802 "Guess the mode-map name according to MODE.
5803 Some modes don't use conventional mode-map name
5804 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5805 Return nil if no mode-map found."
5806 (loop
5807 ;; Start with a conventional mode-map name.
5808 with mode-map = (intern-soft (format "%s-map" mode))
5809 with mode-string = (symbol-name mode)
5810 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5811 while (not mode-map)
5812 for count downfrom (length mode-name)
5813 ;; Return when no result after parsing entire string.
5814 when (eq count 0) return nil
5815 for sub-name = (substring mode-name 0 count)
5816 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5817 finally return mode-map))
5819 (defun anything-M-x-current-mode-map-alist ()
5820 "Return mode-map alist of current `major-mode'."
5821 (let ((map (anything-get-mode-map-from-mode major-mode)))
5822 (when (and map (boundp map))
5823 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5826 (defun anything-M-x-transformer (candidates sources)
5827 "filtered-candidate-transformer to show bindings in emacs commands.
5828 Show global bindings and local bindings according to current `major-mode'."
5829 (with-anything-current-buffer
5830 (loop
5831 with local-map = (anything-M-x-current-mode-map-alist)
5832 for cand in candidates
5833 for local-key = (car (rassq cand local-map))
5834 for key = (substitute-command-keys (format "\\[%s]" cand))
5835 collect
5836 (cons (cond ((and (string-match "^M-x" key) local-key)
5837 (format "%s (%s)"
5838 cand (propertize
5839 local-key
5840 'face 'anything-M-x-key-face)))
5841 ((string-match "^M-x" key) cand)
5842 (t (format "%s (%s)"
5843 cand (propertize
5845 'face 'anything-M-x-key-face))))
5846 cand) into ls
5847 finally return
5848 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5851 ;;; LaCarte
5852 (defvar anything-c-source-lacarte
5853 '((name . "Lacarte")
5854 (init . (lambda () (require 'lacarte )))
5855 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
5856 (candidate-number-limit . 9999)
5857 (action . anything-c-call-interactively))
5858 "Needs lacarte.el.
5860 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
5861 ;; (anything 'anything-c-source-lacarte)
5864 ;;;; <Function>
5865 ;;; Emacs functions
5868 (defvar anything-c-source-emacs-functions
5869 '((name . "Emacs Functions")
5870 (candidates . (lambda ()
5871 (let (commands)
5872 (mapatoms (lambda (a)
5873 (if (functionp a)
5874 (push (symbol-name a) commands))))
5875 (sort commands 'string-lessp))))
5876 (type . function)
5877 (requires-pattern . 2))
5878 "Source for completing Emacs functions.")
5879 ;; (anything 'anything-c-source-emacs-functions)
5881 ;;; With abbrev expansion
5882 ;;; Similar to my exec-abbrev-cmd.el
5883 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5884 (defvar anything-c-function-abbrev-regexp nil
5885 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5886 Regexp built from the current `anything-pattern' interpreting it
5887 as abbreviation.
5888 Only for internal use.")
5890 (defun anything-c-match-function-by-abbrev (candidate)
5891 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5893 Abbreviations are made by taking the first character from each
5894 word in the function's name, e.g. \"bb\" is an abbrev for
5895 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5896 (string-match anything-c-function-abbrev-regexp candidate))
5898 (defvar anything-c-source-emacs-functions-with-abbrevs
5899 (append anything-c-source-emacs-functions
5900 '((match anything-c-match-function-by-abbrev
5901 anything-c-string-match))
5902 '((init
5903 . (lambda ()
5904 (defadvice anything-update
5905 (before anything-c-update-function-abbrev-regexp activate)
5906 (let ((char-list (append anything-pattern nil))
5907 (str "^"))
5908 (dolist (c char-list)
5909 (setq str (concat str (list c) "[^-]*-")))
5910 (setq str (concat (substring str 0 (1- (length str))) "$"))
5911 (setq anything-c-function-abbrev-regexp str))))))))
5912 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5914 (defvar anything-c-source-advice
5915 '((name . "Function Advice")
5916 (candidates . anything-c-advice-candidates)
5917 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
5918 ;; (real-to-display . anything-c-advice-real-to-display)
5919 (persistent-action . anything-c-advice-persistent-action)
5920 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
5921 ;; (anything 'anything-c-source-advice)
5922 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5923 ;; (testadvice)
5925 (defun anything-c-advice-candidates ()
5926 (require 'advice)
5927 (loop for (fname) in ad-advised-functions
5928 for function = (intern fname)
5929 append
5930 (loop for class in ad-advice-classes append
5931 (loop for advice in (ad-get-advice-info-field function class)
5932 for enabled = (ad-advice-enabled advice)
5933 collect
5934 (cons (format
5935 "%s %s %s"
5936 (if enabled "Enabled " "Disabled")
5937 (propertize fname 'face 'font-lock-function-name-face)
5938 (ad-make-single-advice-docstring advice class nil))
5939 (list function class advice))))))
5941 (defun anything-c-advice-persistent-action (func-class-advice)
5942 (if current-prefix-arg
5943 (anything-c-advice-toggle func-class-advice)
5944 (describe-function (car func-class-advice))))
5946 (defun anything-c-advice-toggle (func-class-advice)
5947 (destructuring-bind (function class advice) func-class-advice
5948 (cond ((ad-advice-enabled advice)
5949 (ad-advice-set-enabled advice nil)
5950 (message "Disabled"))
5951 (t ;disabled
5952 (ad-advice-set-enabled advice t)
5953 (message "Enabled")))
5954 (ad-activate function)
5955 (and anything-in-persistent-action
5956 (anything-c-advice-update-current-display-string))))
5958 (defun anything-c-advice-update-current-display-string ()
5959 (anything-edit-current-selection
5960 (let ((newword (cond ((looking-at "Disabled") "Enabled")
5961 ((looking-at "Enabled") "Disabled")))
5962 realvalue)
5963 (when newword
5964 (delete-region (point) (progn (forward-word 1) (point)))
5965 (insert newword)))))
5968 ;;;; <Variable>
5969 ;;; Emacs variables
5972 (defvar anything-c-source-emacs-variables
5973 '((name . "Emacs Variables")
5974 (candidates . (lambda ()
5975 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
5976 (type . variable)
5977 (requires-pattern . 2))
5978 "Source for completing Emacs variables.")
5979 ;; (anything 'anything-c-source-emacs-variables)
5982 ;;; Bookmarks
5985 ;; Bind some faces for bookmarks.
5986 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
5987 (defvar anything-c-bookmarks-face2 'anything-ff-file)
5988 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
5990 (eval-when-compile (require 'bookmark))
5991 (defvar anything-c-source-bookmarks
5992 '((name . "Bookmarks")
5993 (init . (lambda ()
5994 (require 'bookmark)))
5995 (candidates . bookmark-all-names)
5996 (type . bookmark))
5997 "See (info \"(emacs)Bookmarks\").")
5998 ;; (anything 'anything-c-source-bookmarks)
6000 ;;; bookmark-set
6001 (defvar anything-c-source-bookmark-set
6002 '((name . "Set Bookmark")
6003 (dummy)
6004 (action . bookmark-set))
6005 "See (info \"(emacs)Bookmarks\").")
6006 ;; (anything 'anything-c-source-bookmark-set)
6008 ;;; Visible Bookmarks
6009 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6012 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6013 (defvar anything-c-source-bm
6014 '((name . "Visible Bookmarks")
6015 (init . anything-c-bm-init)
6016 (candidates-in-buffer)
6017 (type . line))
6018 "Needs bm.el.
6020 http://www.nongnu.org/bm/")
6022 (defun anything-c-bm-init ()
6023 "Init function for `anything-c-source-bm'."
6024 (when (require 'bm nil t)
6025 (with-no-warnings
6026 (let ((bookmarks (bm-lists))
6027 (buf (anything-candidate-buffer 'global)))
6028 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6029 '< :key 'overlay-start))
6030 (let ((start (overlay-start bm))
6031 (end (overlay-end bm))
6032 (annotation (or (overlay-get bm 'annotation) "")))
6033 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6034 (let ((str (format "%5d: [%s]: %s\n"
6035 (line-number-at-pos start)
6036 annotation
6037 (buffer-substring start (1- end)))))
6038 (with-current-buffer buf (insert str))))))))))
6040 ;;; Special bookmarks
6041 (defvar anything-c-source-bookmarks-ssh
6042 '((name . "Bookmarks-ssh")
6043 (init . (lambda ()
6044 (require 'bookmark)))
6045 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6046 (type . bookmark))
6047 "See (info \"(emacs)Bookmarks\").")
6048 ;; (anything 'anything-c-source-bookmarks-ssh)
6050 (defvar anything-c-source-bookmarks-su
6051 '((name . "Bookmarks-root")
6052 (init . (lambda ()
6053 (require 'bookmark)))
6054 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6055 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6057 (type . bookmark))
6058 "See (info \"(emacs)Bookmarks\").")
6059 ;; (anything 'anything-c-source-bookmarks-su)
6061 (defvar anything-c-source-bookmarks-local
6062 '((name . "Bookmarks-Local")
6063 (init . (lambda ()
6064 (require 'bookmark)))
6065 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6066 (filtered-candidate-transformer
6067 anything-c-adaptive-sort
6068 anything-c-highlight-bookmark)
6069 (type . bookmark))
6070 "See (info \"(emacs)Bookmarks\").")
6071 ;; (anything 'anything-c-source-bookmarks-local)
6073 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6074 (let* ((lis-all (bookmark-all-names))
6075 (lis-loc (cond (local (loop for i in lis-all
6076 unless (string-match "^(ssh)\\|^(su)" i)
6077 collect i))
6078 (su (loop for i in lis-all
6079 when (string-match "^(su)" i)
6080 collect i))
6081 (sudo (loop for i in lis-all
6082 when (string-match "^(sudo)" i)
6083 collect i))
6084 (ssh (loop for i in lis-all
6085 when (string-match "^(ssh)" i)
6086 collect i)))))
6087 (sort lis-loc 'string-lessp)))
6089 (defun anything-c-bookmark-root-logged-p ()
6090 (catch 'break
6091 (dolist (i (mapcar #'buffer-name (buffer-list)))
6092 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6093 (throw 'break t)))))
6095 (defun anything-c-highlight-bookmark-su (files source)
6096 (if (anything-c-bookmark-root-logged-p)
6097 (anything-c-highlight-bookmark files source)
6098 (anything-c-highlight-not-logged files source)))
6100 (defun anything-c-highlight-not-logged (files source)
6101 (loop for i in files
6102 collect (propertize i 'face anything-c-bookmarks-face3)))
6104 (defun anything-c-highlight-bookmark (bookmarks source)
6105 "Used as `candidate-transformer' to colorize bookmarks.
6106 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6107 (loop for i in bookmarks
6108 for isfile = (bookmark-get-filename i)
6109 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6110 (bmkext-get-buffer-name i))
6111 for handlerp = (and (fboundp 'bookmark-get-handler)
6112 (bookmark-get-handler i))
6113 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6114 (bmkext-w3m-bookmark-p i))
6115 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6116 (bmkext-gnus-bookmark-p i))
6117 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6118 (bmkext-man-bookmark-p i))
6119 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6120 (bmkext-woman-bookmark-p i))
6121 for handlerp = (bookmark-get-handler i)
6122 for isannotation = (bookmark-get-annotation i)
6123 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6124 for isinfo = (eq handlerp 'Info-bookmark-jump)
6125 ;; Add a * if bookmark have annotation
6126 if (and isannotation (not (string-equal isannotation "")))
6127 do (setq i (concat "*" i))
6128 collect (cond (;; info buffers
6129 isinfo
6130 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6131 (;; w3m buffers
6132 isw3m
6133 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6134 (;; gnus buffers
6135 isgnus
6136 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6137 (;; Man Woman
6138 (or iswoman isman)
6139 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6140 (;; Addressbook
6141 isabook
6142 (propertize i 'face '((:foreground "Tomato"))))
6143 (;; directories
6144 (and isfile (file-directory-p isfile))
6145 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6146 (;; regular files
6148 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6152 ;;; Sources to filter bookmark-extensions bookmarks.
6155 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6156 ;; If you want to enable google-maps in addressbook you will need
6157 ;; Julien Danjou google-maps-el package available here:
6158 ;; http://julien.danjou.info/google-maps-el.html
6160 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6161 "Return a filtered `bookmark-alist' sorted alphabetically."
6162 (loop
6163 with alist = (if args
6164 (apply #'(lambda (x) (funcall fn x)) args)
6165 (funcall fn))
6166 for i in alist
6167 for b = (car i)
6168 collect b into sa
6169 finally return (sort sa 'string-lessp)))
6171 ;;; Addressbook.
6174 (defvar anything-c-source-bmkext-addressbook
6175 '((name . "Bookmark Addressbook")
6176 (init . (lambda ()
6177 (require 'bookmark-extensions)
6178 (bookmark-maybe-load-default-file)))
6179 (candidates . anything-c-bmkext-addressbook-setup-alist)
6180 (persistent-action
6181 . (lambda (candidate)
6182 (let ((bmk (anything-bookmark-get-bookmark-from-name
6183 candidate)))
6184 (bookmark--jump-via bmk 'pop-to-buffer))))
6185 (persistent-help . "Show contact - Prefix with C-u to append")
6186 (filtered-candidate-transformer
6187 anything-c-adaptive-sort
6188 anything-c-highlight-bookmark)
6189 (action . (("Show Contact(s)"
6190 . (lambda (candidate)
6191 (let* ((contacts (anything-marked-candidates))
6192 (current-prefix-arg (or anything-current-prefix-arg
6193 (> (length contacts) 1))))
6194 (bookmark-jump
6195 (anything-bookmark-get-bookmark-from-name (car contacts)))
6196 (anything-aif (cdr contacts)
6197 (loop for bmk in it do
6198 (bookmark-jump
6199 (anything-bookmark-get-bookmark-from-name bmk)))))))
6200 ("Send Mail"
6201 . (lambda (candidate)
6202 (let* ((contacts (anything-marked-candidates))
6203 (bmk (anything-bookmark-get-bookmark-from-name
6204 (car contacts)))
6205 (append (message-buffers)))
6206 (if append
6207 (addressbook-set-mail-buffer1 bmk 'append)
6208 (addressbook-set-mail-buffer1 bmk))
6209 (setq contacts (cdr contacts))
6210 (when contacts
6211 (loop for bmk in contacts do
6212 (addressbook-set-mail-buffer1 bmk 'append))))))
6213 ("Edit Bookmark"
6214 . (lambda (candidate)
6215 (let ((bmk (anything-bookmark-get-bookmark-from-name
6216 candidate)))
6217 (addressbook-bookmark-edit
6218 (assoc bmk bookmark-alist)))))
6219 ("Insert Email at point"
6220 . (lambda (candidate)
6221 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6222 candidate))
6223 (mlist (split-string
6224 (assoc-default
6225 'email (assoc bmk bookmark-alist))
6226 ", ")))
6227 (insert
6228 (if (> (length mlist) 1)
6229 (anything-comp-read
6230 "Insert Mail Address: " mlist :must-match t)
6231 (car mlist))))))
6232 ("Show annotation"
6233 . (lambda (candidate)
6234 (let ((bmk (anything-bookmark-get-bookmark-from-name
6235 candidate)))
6236 (bookmark-show-annotation bmk))))
6237 ("Edit annotation"
6238 . (lambda (candidate)
6239 (let ((bmk (anything-bookmark-get-bookmark-from-name
6240 candidate)))
6241 (bookmark-edit-annotation bmk))))
6242 ("Show Google map"
6243 . (lambda (candidate)
6244 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6245 candidate))
6246 (full-bmk (assoc bmk bookmark-alist)))
6247 (addressbook-google-map full-bmk))))))))
6250 (defun anything-c-bmkext-addressbook-setup-alist ()
6251 "Specialized filter function for bookmarks w3m."
6252 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6254 ;; W3m bookmarks from bookmark-extensions.
6255 (defvar anything-c-source-bookmark-w3m
6256 '((name . "Bookmark W3m")
6257 (init . (lambda ()
6258 (require 'bookmark-extensions)
6259 (bookmark-maybe-load-default-file)))
6260 (candidates . anything-c-bookmark-w3m-setup-alist)
6261 (filtered-candidate-transformer
6262 anything-c-adaptive-sort
6263 anything-c-highlight-bookmark)
6264 (type . bookmark)))
6265 ;; (anything 'anything-c-source-bookmark-w3m)
6267 (defun anything-c-bookmark-w3m-setup-alist ()
6268 "Specialized filter function for bookmarks w3m."
6269 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6271 ;; Images
6272 (defvar anything-c-source-bookmark-images
6273 '((name . "Bookmark Images")
6274 (init . (lambda ()
6275 (require 'bookmark-extensions)
6276 (bookmark-maybe-load-default-file)))
6277 (candidates . anything-c-bookmark-images-setup-alist)
6278 (filtered-candidate-transformer
6279 anything-c-adaptive-sort
6280 anything-c-highlight-bookmark)
6281 (type . bookmark)))
6282 ;; (anything 'anything-c-source-bookmark-images)
6284 (defun anything-c-bookmark-images-setup-alist ()
6285 "Specialized filter function for images bookmarks."
6286 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6288 ;; Woman Man
6289 (defvar anything-c-source-bookmark-man
6290 '((name . "Bookmark Woman&Man")
6291 (init . (lambda ()
6292 (require 'bookmark-extensions)
6293 (bookmark-maybe-load-default-file)))
6294 (candidates . anything-c-bookmark-man-setup-alist)
6295 (filtered-candidate-transformer
6296 anything-c-adaptive-sort
6297 anything-c-highlight-bookmark)
6298 (type . bookmark)))
6299 ;; (anything 'anything-c-source-bookmark-man)
6301 (defun anything-c-bookmark-man-setup-alist ()
6302 "Specialized filter function for bookmarks w3m."
6303 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6304 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6306 ;; Gnus
6307 (defvar anything-c-source-bookmark-gnus
6308 '((name . "Bookmark Gnus")
6309 (init . (lambda ()
6310 (require 'bookmark-extensions)
6311 (bookmark-maybe-load-default-file)))
6312 (candidates . anything-c-bookmark-gnus-setup-alist)
6313 (filtered-candidate-transformer
6314 anything-c-adaptive-sort
6315 anything-c-highlight-bookmark)
6316 (type . bookmark)))
6317 ;; (anything 'anything-c-source-bookmark-gnus)
6319 (defun anything-c-bookmark-gnus-setup-alist ()
6320 "Specialized filter function for bookmarks gnus."
6321 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6323 ;; Info
6324 (defvar anything-c-source-bookmark-info
6325 '((name . "Bookmark Info")
6326 (init . (lambda ()
6327 (require 'bookmark-extensions)
6328 (bookmark-maybe-load-default-file)))
6329 (candidates . anything-c-bookmark-info-setup-alist)
6330 (filtered-candidate-transformer
6331 anything-c-adaptive-sort
6332 anything-c-highlight-bookmark)
6333 (type . bookmark)))
6334 ;; (anything 'anything-c-source-bookmark-info)
6336 (defun anything-c-bookmark-info-setup-alist ()
6337 "Specialized filter function for bookmarks info."
6338 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6340 ;; Local Files&directories
6341 (defvar anything-c-source-bookmark-files&dirs
6342 '((name . "Bookmark Files&Directories")
6343 (init . (lambda ()
6344 (require 'bookmark-extensions)
6345 (bookmark-maybe-load-default-file)))
6346 (candidates . anything-c-bookmark-local-files-setup-alist)
6347 (filtered-candidate-transformer
6348 anything-c-adaptive-sort
6349 anything-c-highlight-bookmark)
6350 (type . bookmark)))
6351 ;; (anything 'anything-c-source-bookmark-files&dirs)
6353 (defun anything-c-bookmark-local-files-setup-alist ()
6354 "Specialized filter function for bookmarks locals files."
6355 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6357 ;; Su Files&directories
6358 (defvar anything-c-source-bookmark-su-files&dirs
6359 '((name . "Bookmark Root-Files&Directories")
6360 (init . (lambda ()
6361 (require 'bookmark-extensions)
6362 (bookmark-maybe-load-default-file)))
6363 (candidates . anything-c-bookmark-su-files-setup-alist)
6364 (filtered-candidate-transformer
6365 anything-c-adaptive-sort
6366 anything-c-highlight-bookmark-su)
6367 (type . bookmark)))
6368 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6370 (defun anything-c-bookmark-su-files-setup-alist ()
6371 "Specialized filter function for bookmarks su/sudo files."
6372 (declare (special bmkext-su-or-sudo-regexp))
6373 (loop
6374 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6375 for i in l
6376 for isfile = (bookmark-get-filename i)
6377 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6378 (save-match-data
6379 (string-match tramp-file-name-regexp isfile)))
6380 for issu = (and istramp
6381 (string-match bmkext-su-or-sudo-regexp isfile))
6382 if issu
6383 collect i))
6385 ;; Ssh Files&directories
6386 (defvar anything-c-source-bookmark-ssh-files&dirs
6387 '((name . "Bookmark Ssh-Files&Directories")
6388 (init . (lambda ()
6389 (require 'bookmark-extensions)
6390 (bookmark-maybe-load-default-file)))
6391 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6392 (filtered-candidate-transformer . anything-c-adaptive-sort)
6393 (type . bookmark)))
6394 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6396 (defun anything-c-bookmark-ssh-files-setup-alist ()
6397 "Specialized filter function for bookmarks ssh files."
6398 (loop
6399 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6400 for i in l
6401 for isfile = (bookmark-get-filename i)
6402 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6403 (save-match-data
6404 (string-match tramp-file-name-regexp isfile)))
6405 for isssh = (and istramp
6406 (string-match "/ssh:" isfile))
6407 if isssh
6408 collect i))
6412 ;;; Firefox bookmarks
6415 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6416 ;; (only for firefox versions >=3)
6417 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6418 ;; to true:
6419 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6420 ;; You should have now:
6421 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6423 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6424 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6426 (defun anything-get-firefox-user-init-dir ()
6427 "Guess the default Firefox user directory name."
6428 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6429 (moz-user-dir
6430 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6431 (goto-char (point-min))
6432 (prog1
6433 (when (search-forward "Path=" nil t)
6434 (buffer-substring-no-properties (point) (point-at-eol)))
6435 (kill-buffer)))))
6436 (file-name-as-directory (concat moz-dir moz-user-dir))))
6438 (defun anything-guess-firefox-bookmark-file ()
6439 "Return the path of the Firefox bookmarks file."
6440 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6442 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6443 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6444 (let (bookmarks-alist url title)
6445 (with-temp-buffer
6446 (insert-file-contents file)
6447 (goto-char (point-min))
6448 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6449 (forward-line 0)
6450 (when (re-search-forward url-regexp nil t)
6451 (setq url (match-string 0)))
6452 (when (re-search-forward bmk-regexp nil t)
6453 (setq title (match-string 1)))
6454 (push (cons title url) bookmarks-alist)
6455 (forward-line)))
6456 (nreverse bookmarks-alist)))
6458 (defvar anything-c-firefox-bookmarks-alist nil)
6459 (defvar anything-c-source-firefox-bookmarks
6460 '((name . "Firefox Bookmarks")
6461 (init . (lambda ()
6462 (setq anything-c-firefox-bookmarks-alist
6463 (anything-html-bookmarks-to-alist
6464 (anything-guess-firefox-bookmark-file)
6465 anything-firefox-bookmark-url-regexp
6466 anything-firefox-bookmarks-regexp))))
6467 (candidates . (lambda ()
6468 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6469 (filtered-candidate-transformer
6470 anything-c-adaptive-sort
6471 anything-c-highlight-firefox-bookmarks)
6472 (action . (("Browse Url Firefox"
6473 . (lambda (candidate)
6474 (browse-url-firefox
6475 (anything-c-firefox-bookmarks-get-value candidate))))
6476 ("Browse Url w3m"
6477 . (lambda (candidate)
6478 (w3m-browse-url
6479 (anything-c-firefox-bookmarks-get-value candidate))))
6480 ("Copy Url"
6481 . (lambda (elm)
6482 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6484 ;; (anything 'anything-c-source-firefox-bookmarks)
6486 (defun anything-c-firefox-bookmarks-get-value (elm)
6487 (assoc-default elm anything-c-firefox-bookmarks-alist))
6489 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6490 (loop for i in bookmarks
6491 collect (propertize
6492 i 'face '((:foreground "YellowGreen"))
6493 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6497 ;;; W3m bookmark - anything interface.
6500 ;; Some users have the emacs-w3m library in load-path
6501 ;; without having the w3m executable :-;
6502 ;; So check if w3m program is present before trying to load
6503 ;; emacs-w3m.
6504 (eval-when-compile
6505 (when (executable-find "w3m")
6506 (require 'w3m-bookmark nil t)))
6508 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6509 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6510 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6511 (defvar anything-c-w3m-bookmarks-alist nil)
6512 (defvar anything-c-source-w3m-bookmarks
6513 '((name . "W3m Bookmarks")
6514 (init . (lambda ()
6515 (setq anything-c-w3m-bookmarks-alist
6516 (anything-html-bookmarks-to-alist
6517 w3m-bookmark-file
6518 anything-w3m-bookmark-url-regexp
6519 anything-w3m-bookmarks-regexp))))
6520 (candidates . (lambda ()
6521 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6522 (filtered-candidate-transformer
6523 anything-c-adaptive-sort
6524 anything-c-highlight-w3m-bookmarks)
6525 (action . (("Browse Url"
6526 . (lambda (candidate)
6527 (anything-c-w3m-browse-bookmark candidate)))
6528 ("Copy Url"
6529 . (lambda (elm)
6530 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6531 ("Browse Url Firefox"
6532 . (lambda (candidate)
6533 (anything-c-w3m-browse-bookmark candidate t)))
6534 ("Delete Bookmark"
6535 . (lambda (candidate)
6536 (anything-c-w3m-delete-bookmark candidate)))
6537 ("Rename Bookmark"
6538 . (lambda (candidate)
6539 (anything-c-w3m-rename-bookmark candidate)))))
6540 (persistent-action . (lambda (candidate)
6541 (if current-prefix-arg
6542 (anything-c-w3m-browse-bookmark candidate t)
6543 (anything-c-w3m-browse-bookmark candidate nil t))))
6544 (persistent-help . "Open URL with emacs-w3m in new tab / \
6545 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6546 "Needs w3m and emacs-w3m.
6548 http://w3m.sourceforge.net/
6549 http://emacs-w3m.namazu.org/")
6551 ;; (anything 'anything-c-source-w3m-bookmarks)
6553 (defun anything-c-w3m-bookmarks-get-value (elm)
6554 (replace-regexp-in-string
6555 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6557 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6558 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6559 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6560 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6562 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6563 (loop for i in bookmarks
6564 collect (propertize
6565 i 'face 'anything-w3m-bookmarks-face
6566 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6569 (defun anything-c-w3m-delete-bookmark (elm)
6570 "Delete w3m bookmark from `w3m-bookmark-file'."
6571 (with-current-buffer
6572 (find-file-literally w3m-bookmark-file)
6573 (goto-char (point-min))
6574 (when (re-search-forward elm nil t)
6575 (beginning-of-line)
6576 (delete-region (point)
6577 (line-end-position))
6578 (delete-blank-lines))
6579 (save-buffer)
6580 (kill-buffer)))
6582 (defun anything-c-w3m-rename-bookmark (elm)
6583 "Rename w3m bookmark in `w3m-bookmark-file'."
6584 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6585 (new-title (read-string "NewTitle: " old-title)))
6586 (with-current-buffer
6587 (find-file-literally w3m-bookmark-file)
6588 (goto-char (point-min))
6589 (when (re-search-forward (concat elm "<") nil t)
6590 (goto-char (1- (point)))
6591 (delete-char (- (length old-title)))
6592 (insert new-title))
6593 (save-buffer)
6594 (kill-buffer))))
6597 ;;;; <Library>
6598 ;;; Elisp library scan
6601 (defvar anything-c-source-elisp-library-scan
6602 '((name . "Elisp libraries (Scan)")
6603 (init . (anything-c-elisp-library-scan-init))
6604 (candidates-in-buffer)
6605 (action ("Find library"
6606 . (lambda (candidate) (find-file (find-library-name candidate))))
6607 ("Find library other window"
6608 . (lambda (candidate)
6609 (find-file-other-window (find-library-name candidate))))
6610 ("Load library"
6611 . (lambda (candidate) (load-library candidate))))))
6612 ;; (anything 'anything-c-source-elisp-library-scan)
6614 (defun anything-c-elisp-library-scan-init ()
6615 "Init anything buffer status."
6616 (let ((anything-buffer (anything-candidate-buffer 'global))
6617 (library-list (anything-c-elisp-library-scan-list)))
6618 (with-current-buffer anything-buffer
6619 (dolist (library library-list)
6620 (insert (format "%s\n" library))))))
6622 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6623 "Do completion for file names passed to `locate-file'.
6624 DIRS is directory to search path.
6625 STRING is string to match."
6626 ;; Use `load-path' as path when ignore `dirs'.
6627 (or dirs (setq dirs load-path))
6628 ;; Init with blank when ignore `string'.
6629 (or string (setq string ""))
6630 ;; Get library list.
6631 (let ((string-dir (file-name-directory string))
6632 ;; File regexp that suffix match `load-file-rep-suffixes'.
6633 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6634 name
6635 names)
6636 (dolist (dir dirs)
6637 (unless dir
6638 (setq dir default-directory))
6639 (if string-dir
6640 (setq dir (expand-file-name string-dir dir)))
6641 (when (file-directory-p dir)
6642 (dolist (file (file-name-all-completions
6643 (file-name-nondirectory string) dir))
6644 ;; Suffixes match `load-file-rep-suffixes'.
6645 (setq name (if string-dir (concat string-dir file) file))
6646 (if (string-match match-regexp name)
6647 (add-to-list 'names name)))))
6648 names))
6651 ;;;; <Programming>
6655 ;;; Imenu
6658 (defvar anything-c-imenu-delimiter " / ")
6660 (defvar anything-c-imenu-index-filter nil)
6661 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6663 (defvar anything-c-cached-imenu-alist nil)
6664 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6666 (defvar anything-c-cached-imenu-candidates nil)
6667 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6669 (defvar anything-c-cached-imenu-tick nil)
6670 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6672 (eval-when-compile (require 'imenu))
6673 (setq imenu-auto-rescan t)
6675 (defun anything-imenu-create-candidates (entry)
6676 "Create candidates with ENTRY."
6677 (if (listp (cdr entry))
6678 (mapcan
6679 (lambda (sub)
6680 (if (consp (cdr sub))
6681 (mapcar
6682 (lambda (subentry)
6683 (concat (car entry) anything-c-imenu-delimiter subentry))
6684 (anything-imenu-create-candidates sub))
6685 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6686 (cdr entry))
6687 (list entry)))
6689 (defvar anything-c-source-imenu
6690 '((name . "Imenu")
6691 (init . (lambda () (require 'imenu)))
6692 (candidates . anything-c-imenu-candidates)
6693 (persistent-action . (lambda (elm)
6694 (anything-c-imenu-default-action elm)
6695 (unless (fboundp 'semantic-imenu-tag-overlay)
6696 (anything-match-line-color-current-line))))
6697 (persistent-help . "Show this entry")
6698 (action . anything-c-imenu-default-action))
6699 "See (info \"(emacs)Imenu\")")
6701 ;; (anything 'anything-c-source-imenu)
6703 (defun anything-c-imenu-candidates ()
6704 (with-anything-current-buffer
6705 (let ((tick (buffer-modified-tick)))
6706 (if (eq anything-c-cached-imenu-tick tick)
6707 anything-c-cached-imenu-candidates
6708 (setq imenu--index-alist nil)
6709 (setq anything-c-cached-imenu-tick tick
6710 anything-c-cached-imenu-candidates
6711 (ignore-errors
6712 (mapcan
6713 'anything-imenu-create-candidates
6714 (setq anything-c-cached-imenu-alist
6715 (let ((index (imenu--make-index-alist)))
6716 (if anything-c-imenu-index-filter
6717 (funcall anything-c-imenu-index-filter index)
6718 index))))))
6719 (setq anything-c-cached-imenu-candidates
6720 (mapcar #'(lambda (x)
6721 (if (stringp x)
6723 (car x)))
6724 anything-c-cached-imenu-candidates))))))
6726 (setq imenu-default-goto-function 'imenu-default-goto-function)
6727 (defun anything-c-imenu-default-action (elm)
6728 "The default action for `anything-c-source-imenu'."
6729 (let ((path (split-string elm anything-c-imenu-delimiter))
6730 (alist anything-c-cached-imenu-alist))
6731 (dolist (elm path)
6732 (setq alist (assoc elm alist)))
6733 (imenu alist)))
6737 ;;; Ctags
6740 (defvar anything-c-ctags-modes
6741 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6742 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6743 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6745 (defun anything-c-source-ctags-init ()
6746 (when (and buffer-file-name
6747 (memq major-mode anything-c-ctags-modes)
6748 (anything-current-buffer-is-modified))
6749 (with-current-buffer (anything-candidate-buffer 'local)
6750 (call-process-shell-command
6751 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6752 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6753 anything-buffer-file-name)
6754 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6755 nil (current-buffer))
6756 (goto-char (point-min))
6757 (forward-line 2)
6758 (delete-region (point-min) (point))
6759 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6760 for lineno-start = (point)
6761 for lineno = (buffer-substring
6762 lineno-start
6763 (1- (search-forward "," (point-at-eol) t)))
6765 (beginning-of-line)
6766 (insert (format "%5s:" lineno))
6767 (search-forward "\177" (point-at-eol) t)
6768 (delete-region (1- (point)) (point-at-eol))
6769 (forward-line 1)))))
6771 (defvar anything-c-source-ctags
6772 '((name . "Exuberant ctags")
6773 (init . anything-c-source-ctags-init)
6774 (candidates-in-buffer)
6775 (adjust)
6776 (type . line))
6777 "Needs Exuberant Ctags.
6779 http://ctags.sourceforge.net/")
6780 ;; (anything 'anything-c-source-ctags)
6783 ;;; Etags
6786 ;; anything-etags.el is deprecated, if this file is found,
6787 ;; warn user at compile time.
6788 (eval-when-compile
6789 (when (locate-library "anything-etags.el")
6790 (display-warning
6791 '(anything-config)
6792 "You are using obsolete library `anything-etags.el' and should remove it."
6793 :warning)))
6795 (defvar anything-c-etags-tag-file-dir nil
6796 "Etags file directory.")
6797 (defvar anything-c-etags-mtime-alist nil
6798 "Store the last modification time of etags files here.")
6799 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6800 "Cache content of etags files used here for faster access.")
6802 (defun anything-c-etags-get-tag-file (&optional directory)
6803 "Return the path of etags file if found."
6804 ;; Get tag file from `default-directory' or upper directory.
6805 (let ((current-dir (anything-c-etags-find-tag-file-directory
6806 (or directory default-directory))))
6807 ;; Return nil if not find tag file.
6808 (when current-dir
6809 ;; Set tag file directory.
6810 (setq anything-c-etags-tag-file-dir current-dir)
6811 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6813 (defun anything-c-etags-find-tag-file-directory (current-dir)
6814 "Try to find the directory containing tag file.
6815 If not found in CURRENT-DIR search in upper directory."
6816 (flet ((file-exists? (dir)
6817 (let ((tag-path (expand-file-name
6818 anything-c-etags-tag-file-name dir)))
6819 (and (stringp tag-path)
6820 (file-exists-p tag-path)
6821 (file-readable-p tag-path)))))
6822 (loop with count = 0
6823 until (file-exists? current-dir)
6824 ;; Return nil if outside the value of
6825 ;; `anything-c-etags-tag-file-search-limit'.
6826 if (= count anything-c-etags-tag-file-search-limit)
6827 do (return nil)
6828 ;; Or search upper directories.
6829 else
6830 do (incf count)
6831 (setq current-dir (expand-file-name (concat current-dir "../")))
6832 finally return current-dir)))
6834 (defun anything-c-source-etags-header-name (x)
6835 "Create header name for this anything etags session."
6836 (concat "Etags in "
6837 (with-anything-current-buffer
6838 (anything-c-etags-get-tag-file))))
6840 (defmacro anything-c-etags-create-buffer (file)
6841 "Create the `anything-buffer' based on contents of etags tag FILE."
6842 `(let* ((tag-fname ,file)
6844 (split (with-current-buffer (find-file-noselect tag-fname)
6845 (prog1
6846 (split-string (buffer-string) "\n" 'omit-nulls)
6847 (setq max (line-number-at-pos (point-max)))
6848 (kill-buffer))))
6849 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6850 (loop
6851 with fname
6852 with cand
6853 for i in split for count from 0
6854 for elm = (unless (string-match "^\x0c" i)
6855 (anything-aif (string-match "\177" i)
6856 (substring i 0 it)
6858 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6859 (setq fname (match-string 1 elm)))
6860 (elm (setq cand (concat fname ": " elm)))
6861 (t (setq cand nil)))
6862 when cand do (progn
6863 (insert (concat cand "\n"))
6864 (progress-reporter-update progress-reporter count)))))
6866 (defun anything-c-etags-init ()
6867 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6868 If no entry in cache, create one."
6869 (let ((tagfile (anything-c-etags-get-tag-file)))
6870 (when tagfile
6871 (with-current-buffer (anything-candidate-buffer 'global)
6872 (anything-aif (gethash tagfile anything-c-etags-cache)
6873 ;; An entry is present in cache, insert it.
6874 (insert it)
6875 ;; No entry, create a new buffer using content of tag file (slower).
6876 (anything-c-etags-create-buffer tagfile)
6877 ;; Store content of buffer in cache.
6878 (puthash tagfile (buffer-string) anything-c-etags-cache)
6879 ;; Store or set the last modification of tag file.
6880 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6881 ;; If an entry exists modify it.
6882 (setcdr it (anything-c-etags-mtime tagfile))
6883 ;; No entry create a new one.
6884 (add-to-list 'anything-c-etags-mtime-alist
6885 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6887 (defvar anything-c-source-etags-select
6888 '((name . "Etags")
6889 (header-name . anything-c-source-etags-header-name)
6890 (init . anything-c-etags-init)
6891 (candidates-in-buffer)
6892 (search . (anything-c-etags-search-fn))
6893 (mode-line . anything-etags-mode-line-string)
6894 (action . anything-c-etags-default-action)
6895 (persistent-action . (lambda (candidate)
6896 (anything-c-etags-default-action candidate)
6897 (anything-match-line-color-current-line))))
6898 "Anything source for Etags.")
6900 (defun anything-c-etags-search-fn (pattern bound noerror)
6901 "Search function for `anything-c-source-etags-select'."
6902 (re-search-forward
6903 (if anything-c-etags-use-regexp-search (concat "\\_<" pattern) pattern)
6904 bound noerror))
6906 (defun anything-c-etags-default-action (candidate)
6907 "Anything default action to jump to an etags entry."
6908 (let* ((split (split-string candidate ": "))
6909 (fname (expand-file-name
6910 (car split) anything-c-etags-tag-file-dir))
6911 (elm (cadr split)))
6912 (find-file fname)
6913 (goto-char (point-min))
6914 (search-forward elm nil t)
6915 (goto-char (match-beginning 0))))
6917 (defun anything-c-etags-mtime (file)
6918 "Last modification time of etags tag FILE."
6919 (cadr (nth 5 (file-attributes file))))
6921 (defun anything-c-etags-file-modified-p (file)
6922 "Check if tag FILE have been modified in this session.
6923 If FILE is nil return nil."
6924 (let ((last-modif (and file
6925 (assoc-default file anything-c-etags-mtime-alist))))
6926 (and last-modif
6927 (/= last-modif (anything-c-etags-mtime file)))))
6931 ;;; Semantic
6934 (defvar anything-semantic-candidates nil)
6936 (defun anything-semantic-construct-candidates (tags depth)
6937 (when (require 'semantic nil t)
6938 (apply
6939 'append
6940 (mapcar
6941 (lambda (tag)
6942 (if (listp tag)
6943 (let ((type (semantic-tag-type tag))
6944 (class (semantic-tag-class tag)))
6945 (if (or (and (stringp type)
6946 (or (string= type "class")
6947 (string= type "namespace")))
6948 (eq class 'function)
6949 (eq class 'variable))
6950 (cons (cons (concat (make-string (* depth 2) ?\s)
6951 (semantic-format-tag-summarize tag nil t))
6952 tag)
6953 (anything-semantic-construct-candidates
6954 (semantic-tag-components tag) (1+ depth)))))))
6955 tags))))
6957 (defun anything-semantic-default-action (candidate)
6958 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
6959 (semantic-go-to-tag tag)))
6961 (defvar anything-c-source-semantic
6962 '((name . "Semantic Tags")
6963 (init . (lambda ()
6964 (setq anything-semantic-candidates
6965 (ignore-errors (anything-semantic-construct-candidates
6966 (semantic-fetch-tags) 0)))))
6967 (candidates . (lambda ()
6968 (if anything-semantic-candidates
6969 (mapcar 'car anything-semantic-candidates))))
6970 (persistent-action . (lambda (elm)
6971 (anything-semantic-default-action elm)
6972 (anything-match-line-color-current-line)))
6973 (persistent-help . "Show this entry")
6974 (action . anything-semantic-default-action)
6975 "Needs semantic in CEDET.
6977 http://cedet.sourceforge.net/semantic.shtml
6978 http://cedet.sourceforge.net/"))
6980 ;; (anything 'anything-c-source-semantic)
6983 ;;; Anything interface of `simple-call-tree.el'.
6985 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
6987 ;; Function is called by
6988 (defvar anything-c-source-simple-call-tree-functions-callers
6989 '((name . "Function is called by")
6990 (init . anything-c-simple-call-tree-functions-callers-init)
6991 (multiline)
6992 (candidates . anything-c-simple-call-tree-candidates)
6993 (persistent-action . anything-c-simple-call-tree-persistent-action)
6994 (persistent-help . "Show function definitions by rotation")
6995 (action ("Find definition selected by persistent-action" .
6996 anything-c-simple-call-tree-find-definition)))
6997 "Needs simple-call-tree.el.
6998 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7000 (defvar anything-c-simple-call-tree-tick nil)
7001 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7002 (defun anything-c-simple-call-tree-analyze-maybe ()
7003 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7004 (simple-call-tree-analyze)
7005 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7007 (defun anything-c-simple-call-tree-init-base (function message)
7008 (require 'simple-call-tree)
7009 (with-no-warnings
7010 (when (anything-current-buffer-is-modified)
7011 (anything-c-simple-call-tree-analyze-maybe)
7012 (let ((list (funcall function simple-call-tree-alist)))
7013 (with-current-buffer (anything-candidate-buffer 'local)
7014 (dolist (entry list)
7015 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7016 (insert (car entry) message
7017 (if (string= funcs " ")
7018 " no functions."
7019 funcs)
7020 "\n\n"))))))))
7022 (defun anything-c-simple-call-tree-functions-callers-init ()
7023 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7024 " is called by\n"))
7026 (defun anything-c-simple-call-tree-candidates ()
7027 (with-current-buffer (anything-candidate-buffer)
7028 (split-string (buffer-string) "\n\n")))
7030 (defvar anything-c-simple-call-tree-related-functions nil)
7031 (defvar anything-c-simple-call-tree-function-index 0)
7032 (defun anything-c-simple-call-tree-persistent-action (candidate)
7033 (unless (eq last-command 'anything-execute-persistent-action)
7034 (setq anything-c-simple-call-tree-related-functions
7035 (delete "no functions."
7036 (split-string
7037 (replace-regexp-in-string " \\| is called by\\| calls "
7038 "" candidate)
7039 "\n")))
7040 (setq anything-c-simple-call-tree-function-index -1))
7041 (incf anything-c-simple-call-tree-function-index)
7042 (anything-c-simple-call-tree-find-definition candidate))
7044 (defun anything-c-simple-call-tree-find-definition (candidate)
7045 (find-function
7046 (intern
7047 (nth (mod anything-c-simple-call-tree-function-index
7048 (length anything-c-simple-call-tree-related-functions))
7049 anything-c-simple-call-tree-related-functions))))
7051 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7053 ;;; Function calls
7054 (defvar anything-c-source-simple-call-tree-callers-functions
7055 '((name . "Function calls")
7056 (init . anything-c-simple-call-tree-callers-functions-init)
7057 (multiline)
7058 (candidates . anything-c-simple-call-tree-candidates)
7059 (persistent-action . anything-c-simple-call-tree-persistent-action)
7060 (persistent-help . "Show function definitions by rotation")
7061 (action ("Find definition selected by persistent-action" .
7062 anything-c-simple-call-tree-find-definition)))
7063 "Needs simple-call-tree.el.
7064 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7066 (defun anything-c-simple-call-tree-callers-functions-init ()
7067 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7069 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7073 ;;; Anything UI of auto-document.el
7075 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7077 ;; Commands/Options with doc
7078 (defvar anything-c-auto-document-data nil)
7079 (make-variable-buffer-local 'anything-c-auto-document-data)
7080 (defvar anything-c-source-commands-and-options-in-file
7081 '((name . "Commands/Options in file")
7082 (header-name
7083 . (lambda (x) (format "Commands/Options in %s"
7084 (buffer-local-value 'buffer-file-name
7085 anything-current-buffer))))
7086 (candidates . anything-command-and-options-candidates)
7087 (multiline)
7088 (action . imenu))
7089 "List Commands and Options with doc. It needs auto-document.el .
7091 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7093 (eval-when-compile (require 'auto-document nil t))
7094 (defun anything-command-and-options-candidates ()
7095 (with-anything-current-buffer
7096 (when (and (require 'auto-document nil t)
7097 (eq major-mode 'emacs-lisp-mode)
7098 (or (anything-current-buffer-is-modified)
7099 (not anything-c-auto-document-data)))
7100 (or imenu--index-alist (imenu--make-index-alist t))
7101 (setq anything-c-auto-document-data
7102 (destructuring-bind (commands options)
7103 (adoc-construct anything-current-buffer)
7104 (append
7105 (loop for (command . doc) in commands
7106 for cmdname = (symbol-name command)
7107 collect
7108 (cons
7109 (format "Command: %s\n %s"
7110 (propertize cmdname 'face font-lock-function-name-face)
7111 (adoc-first-line doc))
7112 (assoc cmdname imenu--index-alist)))
7113 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7114 for (option doc default) in options
7115 for optname = (symbol-name option)
7116 collect
7117 (cons
7118 (format "Option: %s\n %s\n default = %s"
7119 (propertize optname 'face font-lock-variable-name-face)
7120 (adoc-first-line doc)
7121 (adoc-prin1-to-string default))
7122 (assoc optname
7123 var-alist)))))))
7124 anything-c-auto-document-data))
7126 ;; (anything 'anything-c-source-commands-and-options-in-file)
7129 ;;;; <Color and Face>
7132 ;;; Customize Face
7135 (defvar anything-c-source-customize-face
7136 '((name . "Customize Face")
7137 (init . (lambda ()
7138 (unless (anything-candidate-buffer)
7139 (save-window-excursion (list-faces-display))
7140 (anything-candidate-buffer (get-buffer "*Faces*")))))
7141 (candidates-in-buffer)
7142 (get-line . buffer-substring)
7143 (action . (lambda (line)
7144 (customize-face (intern (car (split-string line))))))
7145 (requires-pattern . 3))
7146 "See (info \"(emacs)Faces\")")
7147 ;; (anything 'anything-c-source-customize-face)
7149 ;;; Colors browser
7152 (defvar anything-c-source-colors
7153 '((name . "Colors")
7154 (init . (lambda () (unless (anything-candidate-buffer)
7155 (save-window-excursion (list-colors-display))
7156 (anything-candidate-buffer (get-buffer "*Colors*")))))
7157 (candidates-in-buffer)
7158 (get-line . buffer-substring)
7159 (action
7160 ("Copy Name" . (lambda (candidate)
7161 (kill-new (anything-c-colors-get-name candidate))))
7162 ("Copy RGB" . (lambda (candidate)
7163 (kill-new (anything-c-colors-get-rgb candidate))))
7164 ("Insert Name" . (lambda (candidate)
7165 (with-anything-current-buffer
7166 (insert (anything-c-colors-get-name candidate)))))
7167 ("Insert RGB" . (lambda (candidate)
7168 (with-anything-current-buffer
7169 (insert (anything-c-colors-get-rgb candidate))))))))
7170 ;; (anything 'anything-c-source-colors)
7172 (defun anything-c-colors-get-name (candidate)
7173 "Get color name."
7174 (replace-regexp-in-string
7175 " " ""
7176 (with-temp-buffer
7177 (insert (capitalize candidate))
7178 (goto-char (point-min))
7179 (search-forward-regexp "\\s-\\{2,\\}")
7180 (delete-region (point) (point-max))
7181 (buffer-string))))
7183 (defun anything-c-colors-get-rgb (candidate)
7184 "Get color RGB."
7185 (replace-regexp-in-string
7186 " " ""
7187 (with-temp-buffer
7188 (insert (capitalize candidate))
7189 (goto-char (point-max))
7190 (search-backward-regexp "\\s-\\{2,\\}")
7191 (delete-region (point) (point-min))
7192 (buffer-string))))
7195 ;;;; <Search Engine>
7196 ;;; Tracker desktop search
7197 (defvar anything-c-source-tracker-search
7198 '((name . "Tracker Search")
7199 (candidates . (lambda ()
7200 (start-process "tracker-search-process" nil
7201 "tracker-search"
7202 anything-pattern)))
7203 (type . file)
7204 (requires-pattern . 3)
7205 (delayed))
7206 "Source for retrieving files matching the current input pattern
7207 with the tracker desktop search.")
7208 ;; (anything 'anything-c-source-tracker-search)
7210 ;;; Spotlight (MacOS X desktop search)
7211 (defvar anything-c-source-mac-spotlight
7212 '((name . "mdfind")
7213 (candidates
7214 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7215 (type . file)
7216 (requires-pattern . 3)
7217 (delayed))
7218 "Source for retrieving files via Spotlight's command line
7219 utility mdfind.")
7220 ;; (anything 'anything-c-source-mac-spotlight)
7222 ;;; Picklist
7223 (defvar anything-c-source-picklist
7224 '((name . "Picklist")
7225 (candidates . (lambda () (mapcar 'car picklist-list)))
7226 (type . file)))
7227 ;; (anything 'anything-c-source-picklist)
7231 ;;; Kill ring
7234 (defvar anything-c-source-kill-ring
7235 '((name . "Kill Ring")
7236 (init . (lambda () (anything-attrset 'last-command last-command)))
7237 (candidates . anything-c-kill-ring-candidates)
7238 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7239 (action . anything-c-kill-ring-action)
7240 (last-command)
7241 (migemo)
7242 (multiline))
7243 "Source for browse and insert contents of kill-ring.")
7245 (defun anything-c-kill-ring-candidates ()
7246 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7247 unless (or (< (length kill) anything-kill-ring-threshold)
7248 (string-match "^[\\s\\t]+$" kill))
7249 collect kill))
7251 (defun anything-c-kill-ring-transformer (candidates source)
7252 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7253 (loop for i in candidates
7254 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7255 if (and anything-c-kill-ring-max-lines-number
7256 (> nlines anything-c-kill-ring-max-lines-number))
7257 collect (cons
7258 (with-temp-buffer
7259 (insert i)
7260 (goto-char (point-min))
7261 (concat
7262 (buffer-substring
7263 (point-min)
7264 (save-excursion
7265 (forward-line anything-c-kill-ring-max-lines-number)
7266 (point)))
7267 "[...]")) i)
7268 else collect i))
7270 (defun anything-c-kill-ring-action (str)
7271 "Insert STR in `kill-ring' and set STR to the head.
7272 If this action is executed just after `yank',
7273 replace with STR as yanked string."
7274 (setq kill-ring (delete str kill-ring))
7275 (if (not (eq (anything-attr 'last-command) 'yank))
7276 (insert-for-yank str)
7277 ;; from `yank-pop'
7278 (let ((inhibit-read-only t)
7279 (before (< (point) (mark t))))
7280 (if before
7281 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7282 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7283 (setq yank-undo-function nil)
7284 (set-marker (mark-marker) (point) (current-buffer))
7285 (insert-for-yank str)
7286 ;; Set the window start back where it was in the yank command,
7287 ;; if possible.
7288 (set-window-start (selected-window) yank-window-start t)
7289 (if before
7290 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7291 ;; It is cleaner to avoid activation, even though the command
7292 ;; loop would deactivate the mark because we inserted text.
7293 (goto-char (prog1 (mark t)
7294 (set-marker (mark-marker) (point) (current-buffer)))))))
7295 (kill-new str))
7297 ;; (anything 'anything-c-source-kill-ring)
7300 ;;;; <Mark ring>
7301 ;; DO NOT include these sources in `anything-sources' use
7302 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7303 ;; `anything-all-mark-rings' instead.
7305 (defun anything-c-source-mark-ring-candidates ()
7306 (flet ((get-marks (pos)
7307 (save-excursion
7308 (goto-char pos)
7309 (beginning-of-line)
7310 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7311 (when (string= "" line)
7312 (setq line "<EMPTY LINE>"))
7313 (format "%7d: %s" (line-number-at-pos) line)))))
7314 (with-anything-current-buffer
7315 (loop
7316 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7317 with recip = nil
7318 for i in marks
7319 for m = (get-marks i)
7320 unless (member m recip)
7321 collect m into recip
7322 finally return recip))))
7324 (defvar anything-mark-ring-cache nil)
7325 (defvar anything-c-source-mark-ring
7326 '((name . "mark-ring")
7327 (init . (lambda ()
7328 (setq anything-mark-ring-cache
7329 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7330 (candidates . (lambda ()
7331 (anything-aif anything-mark-ring-cache
7332 it)))
7333 (action . (("Goto line"
7334 . (lambda (candidate)
7335 (anything-goto-line (string-to-number candidate))))))
7336 (persistent-action . (lambda (candidate)
7337 (anything-goto-line (string-to-number candidate))
7338 (anything-match-line-color-current-line)))
7339 (persistent-help . "Show this line")))
7341 ;; (anything 'anything-c-source-mark-ring)
7343 ;;; Global-mark-ring
7344 (defvar anything-c-source-global-mark-ring
7345 '((name . "global-mark-ring")
7346 (candidates . anything-c-source-global-mark-ring-candidates)
7347 (action . (("Goto line"
7348 . (lambda (candidate)
7349 (let ((items (split-string candidate ":")))
7350 (anything-c-switch-to-buffer (second items))
7351 (anything-goto-line (string-to-number (car items))))))))
7352 (persistent-action . (lambda (candidate)
7353 (let ((items (split-string candidate ":")))
7354 (anything-c-switch-to-buffer (second items))
7355 (anything-goto-line (string-to-number (car items)))
7356 (anything-match-line-color-current-line))))
7357 (persistent-help . "Show this line")))
7359 (defun anything-c-source-global-mark-ring-candidates ()
7360 (flet ((buf-fn (m)
7361 (with-current-buffer (marker-buffer m)
7362 (goto-char m)
7363 (beginning-of-line)
7364 (let (line)
7365 (if (string= "" line)
7366 (setq line "<EMPTY LINE>")
7367 (setq line (car (split-string (thing-at-point 'line)
7368 "[\n\r]"))))
7369 (format "%7d:%s: %s"
7370 (line-number-at-pos) (marker-buffer m) line)))))
7371 (loop
7372 with marks = global-mark-ring
7373 with recip = nil
7374 for i in marks
7375 for gm = (unless (or (string-match
7376 "^ " (format "%s" (marker-buffer i)))
7377 (null (marker-buffer i)))
7378 (buf-fn i))
7379 when (and gm (not (member gm recip)))
7380 collect gm into recip
7381 finally return recip)))
7383 ;; (anything 'anything-c-source-global-mark-ring)
7386 ;;;; <Register>
7387 ;;; Insert from register
7388 (defvar anything-c-source-register
7389 '((name . "Registers")
7390 (candidates . anything-c-register-candidates)
7391 (action-transformer . anything-c-register-action-transformer)
7392 (multiline)
7393 (action))
7394 "See (info \"(emacs)Registers\")")
7396 (defun anything-c-register-candidates ()
7397 "Collecting register contents and appropriate commands."
7398 (loop for (char . val) in register-alist
7399 for key = (single-key-description char)
7400 for string-actions =
7401 (cond
7402 ((numberp val)
7403 (list (int-to-string val)
7404 'insert-register
7405 'increment-register))
7406 ((markerp val)
7407 (let ((buf (marker-buffer val)))
7408 (if (null buf)
7409 (list "a marker in no buffer")
7410 (list (concat
7411 "a buffer position:"
7412 (buffer-name buf)
7413 ", position "
7414 (int-to-string (marker-position val)))
7415 'jump-to-register
7416 'insert-register))))
7417 ((and (consp val) (window-configuration-p (car val)))
7418 (list "window configuration."
7419 'jump-to-register))
7420 ((and (consp val) (frame-configuration-p (car val)))
7421 (list "frame configuration."
7422 'jump-to-register))
7423 ((and (consp val) (eq (car val) 'file))
7424 (list (concat "file:"
7425 (prin1-to-string (cdr val))
7426 ".")
7427 'jump-to-register))
7428 ((and (consp val) (eq (car val) 'file-query))
7429 (list (concat "file:a file-query reference: file "
7430 (car (cdr val))
7431 ", position "
7432 (int-to-string (car (cdr (cdr val))))
7433 ".")
7434 'jump-to-register))
7435 ((consp val)
7436 (let ((lines (format "%4d" (length val))))
7437 (list (format "%s: %s\n" lines
7438 (truncate-string-to-width
7439 (mapconcat 'identity (list (car val))
7440 ;; (mapconcat (lambda (y) y) val
7441 "^J") (- (window-width) 15)))
7442 'insert-register)))
7443 ((stringp val)
7444 (list ;; without properties
7445 (substring-no-properties val)
7446 'insert-register
7447 'append-to-register
7448 'prepend-to-register))
7450 "GARBAGE!"))
7451 collect (cons (format "register %3s: %s" key (car string-actions))
7452 (cons char (cdr string-actions)))))
7454 (defun anything-c-register-action-transformer (actions register-and-functions)
7455 "Decide actions by the contents of register."
7456 (loop with func-actions =
7457 '((insert-register
7458 "Insert Register" .
7459 (lambda (c) (insert-register (car c))))
7460 (jump-to-register
7461 "Jump to Register" .
7462 (lambda (c) (jump-to-register (car c))))
7463 (append-to-register
7464 "Append Region to Register" .
7465 (lambda (c) (append-to-register
7466 (car c) (region-beginning) (region-end))))
7467 (prepend-to-register
7468 "Prepend Region to Register" .
7469 (lambda (c) (prepend-to-register
7470 (car c) (region-beginning) (region-end))))
7471 (increment-register
7472 "Increment Prefix Arg to Register" .
7473 (lambda (c) (increment-register
7474 anything-current-prefix-arg (car c)))))
7475 for func in (cdr register-and-functions)
7476 for cell = (assq func func-actions)
7477 when cell
7478 collect (cdr cell)))
7480 ;; (anything 'anything-c-source-register)
7483 ;;; Latex completion
7484 (defun anything-c-latex-math-candidates ()
7485 "Collect candidates for latex math completion."
7486 (declare (special LaTeX-math-menu))
7487 (loop for i in (cddr LaTeX-math-menu)
7488 for elm = (loop for s in i when (vectorp s)
7489 collect (cons (aref s 0) (aref s 1)))
7490 append elm))
7492 (defvar anything-c-source-latex-math
7493 '((name . "Latex Math Menu")
7494 (init . (lambda ()
7495 (with-anything-current-buffer
7496 (LaTeX-math-mode 1))))
7497 (candidate-number-limit . 9999)
7498 (candidates . anything-c-latex-math-candidates)
7499 (action . (lambda (candidate)
7500 (call-interactively candidate)))))
7503 ;;;; <Headline Extraction>
7504 (defvar anything-c-source-fixme
7505 '((name . "TODO/FIXME/DRY comments")
7506 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7507 (adjust)
7508 (recenter))
7509 "Show TODO/FIXME/DRY comments in current file.")
7510 ;; (anything 'anything-c-source-fixme)
7512 (defvar anything-c-source-rd-headline
7513 '((name . "RD HeadLine")
7514 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7515 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7516 (migemo)
7517 (subexp . 1))
7518 "Show RD headlines.
7520 RD is Ruby's POD.
7521 http://en.wikipedia.org/wiki/Ruby_Document_format")
7522 ;; (anything 'anything-c-source-rd-headline)
7524 (defvar anything-c-source-oddmuse-headline
7525 '((name . "Oddmuse HeadLine")
7526 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7527 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7528 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7529 (migemo)
7530 (subexp . 1))
7531 "Show Oddmuse headlines, such as EmacsWiki.")
7532 ;; (anything 'anything-c-source-oddmuse-headline)
7534 (defvar anything-c-source-emacs-source-defun
7535 '((name . "Emacs Source DEFUN")
7536 (headline . "DEFUN\\|DEFVAR")
7537 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7538 (or buffer-file-name ""))))
7539 "Show DEFUN/DEFVAR in Emacs C source file.")
7540 ;; (anything 'anything-c-source-emacs-source-defun)
7542 (defvar anything-c-source-emacs-lisp-expectations
7543 '((name . "Emacs Lisp Expectations")
7544 (headline . "(desc[ ]\\|(expectations")
7545 (condition . (eq major-mode 'emacs-lisp-mode)))
7546 "Show descriptions (desc) in Emacs Lisp Expectations.
7548 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7549 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7551 (defvar anything-c-source-emacs-lisp-toplevels
7552 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7553 (headline . "^(\\|(@\\*\\|^;;;;")
7554 (get-line . buffer-substring)
7555 (condition . (eq major-mode 'emacs-lisp-mode))
7556 (adjust))
7557 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7558 linkd.el is optional because linkd stars are extracted by regexp.
7559 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7560 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7563 ;;; Anything yaoddmuse
7565 ;; Be sure to have yaoddmuse.el installed
7566 ;; install-elisp may be required if you want to install elisp file from here.
7567 (defvar anything-yaoddmuse-use-cache-file nil)
7568 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7569 (defvar anything-c-yaoddmuse-ew-cache nil)
7571 (defun anything-yaoddmuse-get-candidates ()
7572 (declare (special yaoddmuse-pages-hash))
7573 (if anything-yaoddmuse-use-cache-file
7574 (ignore-errors
7575 (unless anything-c-yaoddmuse-ew-cache
7576 (load anything-c-yaoddmuse-cache-file)
7577 (setq anything-c-yaoddmuse-ew-cache
7578 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7579 anything-c-yaoddmuse-ew-cache)
7580 (yaoddmuse-update-pagename t)
7581 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7583 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7584 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7585 (candidates . anything-yaoddmuse-get-candidates)
7586 (action . (("Edit page" . (lambda (candidate)
7587 (yaoddmuse-edit "EmacsWiki" candidate)))
7588 ("Browse page"
7589 . (lambda (candidate)
7590 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7591 ("Browse page other window"
7592 . (lambda (candidate)
7593 (if (one-window-p)
7594 (split-window-vertically))
7595 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7596 ("Browse diff"
7597 . (lambda (candidate)
7598 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7599 ("Copy URL"
7600 . (lambda (candidate)
7601 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7602 (message "Have copy page %s's URL to yank." candidate)))
7603 ("Create page"
7604 . (lambda (candidate)
7605 (yaoddmuse-edit "EmacsWiki" anything-input)))
7606 ("Update cache"
7607 . (lambda (candidate)
7608 (if anything-yaoddmuse-use-cache-file
7609 (progn
7610 (anything-yaoddmuse-cache-pages t)
7611 (setq anything-c-yaoddmuse-ew-cache
7612 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7613 (yaoddmuse-update-pagename))))))
7614 (action-transformer anything-c-yaoddmuse-action-transformer))
7615 "Needs yaoddmuse.el.
7617 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7619 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7621 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7622 '((name . "Yaoddmuse Post library (EmacsWiki)")
7623 (init . (anything-yaoddmuse-init))
7624 (candidates-in-buffer)
7625 (action . (("Post library and Browse"
7626 . (lambda (candidate)
7627 (yaoddmuse-post-file
7628 (find-library-name candidate)
7629 "EmacsWiki"
7630 (file-name-nondirectory (find-library-name candidate))
7631 nil t)))
7632 ("Post library"
7633 . (lambda (candidate)
7634 (yaoddmuse-post-file
7635 (find-library-name candidate)
7636 "EmacsWiki"
7637 (file-name-nondirectory
7638 (find-library-name candidate))))))))
7639 "Needs yaoddmuse.el.
7641 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7643 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7645 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7646 "Allow the use of `install-elisp' only on elisp files."
7647 (if (string-match "\.el$" candidate)
7648 (append actions '(("Install Elisp"
7649 . (lambda (elm)
7650 (install-elisp-from-emacswiki elm)))))
7651 actions))
7653 ;;;###autoload
7654 (defun anything-yaoddmuse-cache-pages (&optional load)
7655 "Fetch the list of files on emacswiki and create cache file.
7656 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7657 (interactive)
7658 (declare (special yaoddmuse-pages-hash))
7659 (yaoddmuse-update-pagename)
7660 (save-excursion
7661 (find-file anything-c-yaoddmuse-cache-file)
7662 (erase-buffer)
7663 (insert "(puthash \"EmacsWiki\" '(")
7664 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7666 (insert (concat "(\"" (car i) "\") ")))
7667 (insert ") yaoddmuse-pages-hash)\n")
7668 (save-buffer)
7669 (kill-buffer (current-buffer))
7670 (when (or current-prefix-arg
7671 load)
7672 (load anything-c-yaoddmuse-cache-file))))
7674 (defun anything-yaoddmuse-init ()
7675 "Init anything buffer status."
7676 (let ((anything-buffer (anything-candidate-buffer 'global))
7677 (library-list (yaoddmuse-get-library-list)))
7678 (with-current-buffer anything-buffer
7679 ;; Insert library name.
7680 (dolist (library library-list)
7681 (insert (format "%s\n" library)))
7682 ;; Sort lines.
7683 (sort-lines nil (point-min) (point-max)))))
7686 ;;; Eev anchors
7687 (defvar anything-c-source-eev-anchor
7688 '((name . "Anchors")
7689 (candidates
7690 . (lambda ()
7691 (ignore-errors
7692 (with-anything-current-buffer
7693 (loop initially (goto-char (point-min))
7694 while (re-search-forward
7695 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7696 for anchor = (match-string-no-properties 1)
7697 collect (cons (format "%5d:%s"
7698 (line-number-at-pos (match-beginning 0))
7699 (format ee-anchor-format anchor))
7700 anchor))))))
7701 (persistent-action . (lambda (item)
7702 (ee-to item)
7703 (anything-match-line-color-current-line)))
7704 (persistent-help . "Show this entry")
7705 (action . (("Goto link" . ee-to)))))
7706 ;; (anything 'anything-c-source-eev-anchor)
7709 ;;; Org headlines
7712 (defvar anything-c-source-org-headline
7713 `((name . "Org HeadLine")
7714 (headline
7715 ,@(mapcar
7716 (lambda (num)
7717 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7718 num))
7719 (number-sequence 1 8)))
7720 (condition . (eq major-mode 'org-mode))
7721 (migemo)
7722 (subexp . 1)
7723 (persistent-action . (lambda (elm)
7724 (anything-c-action-line-goto elm)
7725 (org-cycle)))
7726 (action-transformer
7727 . (lambda (actions candidate)
7728 '(("Go to Line" . anything-c-action-line-goto)
7729 ("Refile to this Headline" . anything-c-org-headline-refile)
7730 ("Insert Link to This Headline"
7731 . anything-c-org-headline-insert-link-to-headline)))))
7732 "Show Org headlines.
7733 org-mode is very very much extended text-mode/outline-mode.
7735 See (find-library \"org.el\")
7736 See http://orgmode.org for the latest version.")
7737 ;; (anything 'anything-c-source-org-headline)
7739 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7740 (insert
7741 (save-excursion
7742 (anything-goto-line (car lineno-and-content))
7743 (and (looking-at org-complex-heading-regexp)
7744 (org-make-link-string (concat "*" (match-string 4)))))))
7746 (defun anything-c-org-headline-refile (lineno-and-content)
7747 "Refile current org entry to LINENO-AND-CONTENT."
7748 (with-anything-current-buffer
7749 (org-cut-subtree)
7750 (anything-goto-line (car lineno-and-content))
7751 (org-end-of-subtree t t)
7752 (let ((org-yank-adjusted-subtrees t))
7753 (org-yank))))
7756 ;;; Org keywords
7759 (defvar anything-c-source-org-keywords
7760 '((name . "Org Keywords")
7761 (init . anything-c-org-keywords-init)
7762 (candidates . anything-c-org-keywords-candidates)
7763 (action . anything-c-org-keywords-insert)
7764 (persistent-action . anything-c-org-keywords-show-help)
7765 (persistent-help . "Show an example and info page to describe this keyword.")
7766 (keywords-examples)
7767 (keywords)))
7768 ;; (anything 'anything-c-source-org-keywords)
7770 (defvar anything-c-org-keywords-info-location
7771 '(("#+TITLE:" . "(org)Export options")
7772 ("#+AUTHOR:" . "(org)Export options")
7773 ("#+DATE:" . "(org)Export options")
7774 ("#+EMAIL:" . "(org)Export options")
7775 ("#+DESCRIPTION:" . "(org)Export options")
7776 ("#+KEYWORDS:" . "(org)Export options")
7777 ("#+LANGUAGE:" . "(org)Export options")
7778 ("#+TEXT:" . "(org)Export options")
7779 ("#+TEXT:" . "(org)Export options")
7780 ("#+OPTIONS:" . "(org)Export options")
7781 ("#+BIND:" . "(org)Export options")
7782 ("#+LINK_UP:" . "(org)Export options")
7783 ("#+LINK_HOME:" . "(org)Export options")
7784 ("#+LATEX_HEADER:" . "(org)Export options")
7785 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7786 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7787 ("#+INFOJS_OPT" . "(org)Javascript support")
7788 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7789 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7790 ("#+ORGTBL" . "(org)Radio tables")
7791 ("#+HTML:" . "(org)Quoting HTML tags")
7792 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7793 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7794 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7795 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7796 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7797 ("#+BEGIN_SRC" . "(org)Literal examples")
7798 ("#+CAPTION" . "(org)Tables in HTML export")
7799 ("#+LABEL" . "(org)Tables in LaTeX export")
7800 ("#+ATTR_HTML" . "(org)Links")
7801 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7803 (defun anything-c-org-keywords-init ()
7804 (unless (anything-attr 'keywords-examples)
7805 (require 'org)
7806 (anything-attrset 'keywords-examples
7807 (append
7808 (mapcar
7809 (lambda (x)
7810 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7811 (cons (match-string 2 x) (match-string 1 x)))
7812 (org-split-string (org-get-current-options) "\n"))
7813 (mapcar 'list org-additional-option-like-keywords)))
7814 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7816 (defun anything-c-org-keywords-candidates ()
7817 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7818 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7819 (anything-attr 'keywords)))
7821 (defun anything-c-org-keywords-insert (keyword)
7822 (cond ((and (string-match "BEGIN" keyword)
7823 (anything-region-active-p))
7824 (let ((beg (region-beginning))
7825 (end (region-end)))
7826 (goto-char end)
7827 (insert "\n#+" (replace-regexp-in-string
7828 "BEGIN" "END" keyword) "\n")
7829 (goto-char beg)
7830 (insert "#+" keyword " ")
7831 (save-excursion (insert "\n"))))
7832 ((string-match "BEGIN" keyword)
7833 (insert "#+" keyword " ")
7834 (save-excursion
7835 (insert "\n#+" (replace-regexp-in-string
7836 "BEGIN" "END" keyword) "\n")))
7837 (t (insert "#+" keyword " "))))
7839 (defun anything-c-org-keywords-show-help (keyword)
7840 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7841 "(org)In-buffer settings"))
7842 (search-forward (concat "#+" keyword) nil t)
7843 (anything-persistent-highlight-point)
7844 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7848 ;;; bbdb
7851 (defvar bbdb-records)
7852 (defvar bbdb-buffer-name)
7854 (defun anything-c-bbdb-candidates ()
7855 "Return a list of all names in the bbdb database. The format
7856 is \"Firstname Lastname\"."
7857 (mapcar (lambda (bbdb-record)
7858 (replace-regexp-in-string
7859 "\\s-+$" ""
7860 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7861 (bbdb-records)))
7863 (defun anything-c-bbdb-create-contact (actions candidate)
7864 "Action transformer that returns only an entry to add the
7865 current `anything-pattern' as new contact. All other actions are
7866 removed."
7867 (if (string= candidate "*Add to contacts*")
7868 '(("Add to contacts" . (lambda (actions)
7869 (bbdb-create-internal
7870 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7871 (read-from-minibuffer "Company: ")
7872 (read-from-minibuffer "Email: ")
7875 (read-from-minibuffer "Note: ")))))
7876 actions))
7878 (defun anything-c-bbdb-get-record (candidate)
7879 "Return record that match CANDIDATE."
7880 (bbdb candidate nil)
7881 (set-buffer "*BBDB*")
7882 (bbdb-current-record))
7884 (defvar anything-c-bbdb-name nil
7885 "Only for internal use.")
7887 (defvar anything-c-source-bbdb
7888 '((name . "BBDB")
7889 (candidates . anything-c-bbdb-candidates)
7890 (action ("Send a mail" . anything-c-bbdb-compose-mail)
7891 ("View person's data" . anything-c-bbdb-view-person-action))
7892 (filtered-candidate-transformer . (lambda (candidates source)
7893 (setq anything-c-bbdb-name anything-pattern)
7894 (if (not candidates)
7895 (list "*Add to contacts*")
7896 candidates)))
7897 (action-transformer . (lambda (actions candidate)
7898 (anything-c-bbdb-create-contact actions candidate))))
7899 "Needs BBDB.
7901 http://bbdb.sourceforge.net/")
7902 ;; (anything 'anything-c-source-bbdb)
7904 (defun anything-c-bbdb-view-person-action (candidate)
7905 "View BBDB data of single CANDIDATE or marked candidates."
7906 (anything-aif (anything-marked-candidates)
7907 (let ((bbdb-append-records (length it)))
7908 (dolist (i it)
7909 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
7910 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
7912 (defun anything-c-bbdb-collect-mail-addresses ()
7913 "Return a list of all mail addresses of records in bbdb buffer."
7914 (with-current-buffer bbdb-buffer-name
7915 (loop for i in bbdb-records
7916 if (bbdb-record-net (car i))
7917 collect (bbdb-dwim-net-address (car i)))))
7919 (defun anything-c-bbdb-compose-mail (candidate)
7920 "Compose a mail with all records of bbdb buffer."
7921 (anything-c-bbdb-view-person-action candidate)
7922 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7923 (address-str (mapconcat 'identity address-list ",\n ")))
7924 (compose-mail address-str)))
7927 ;;; Evaluation Result
7930 ;; Internal
7931 (defvar anything-eldoc-active-minibuffers-list nil)
7933 (defvar anything-c-source-evaluation-result
7934 '((name . "Evaluation Result")
7935 (disable-shortcuts)
7936 (dummy)
7937 (multiline)
7938 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
7939 (filtered-candidate-transformer . (lambda (candidates source)
7940 (list
7941 (condition-case nil
7942 (with-anything-current-buffer
7943 (pp-to-string
7944 (eval (read anything-pattern))))
7945 (error "Error")))))
7946 (action . (("Copy result to kill-ring" . (lambda (candidate)
7947 (with-current-buffer anything-buffer
7948 (let ((end (save-excursion
7949 (goto-char (point-max))
7950 (search-backward "\n")
7951 (point))))
7952 (kill-region (point) end)))))
7953 ("copy sexp to kill-ring" . (lambda (candidate)
7954 (kill-new anything-input)))))))
7955 ;; (anything 'anything-c-source-evaluation-result)
7957 (defun anything-eval-new-line-and-indent ()
7958 (interactive)
7959 (newline) (lisp-indent-line))
7961 (defun anything-eldoc-store-minibuffer ()
7962 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
7963 (with-selected-window (minibuffer-window)
7964 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
7966 (defun anything-eldoc-show-in-eval ()
7967 "Return eldoc in mode-line for current minibuffer input."
7968 (let ((buf (with-selected-window (minibuffer-window)
7969 (buffer-name))))
7970 (when (member buf anything-eldoc-active-minibuffers-list)
7971 (let* ((str-all (with-current-buffer buf
7972 (minibuffer-completion-contents)))
7973 (sym (when str-all
7974 (with-temp-buffer
7975 (insert str-all)
7976 (goto-char (point-max))
7977 (unless (looking-back ")\\|\"") (forward-char -1))
7978 (eldoc-current-symbol))))
7979 (info-fn (eldoc-fnsym-in-current-sexp))
7980 (doc (or (eldoc-get-var-docstring sym)
7981 (eldoc-get-fnsym-args-string
7982 (car info-fn) (cadr info-fn)))))
7983 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
7985 (defun anything-c-eldoc-show-in-mode-line (str)
7986 "Show string STR in mode-line."
7987 (save-window-excursion
7988 (with-current-buffer anything-buffer
7989 (let ((mode-line-format (concat " " str)))
7990 (force-mode-line-update)
7991 (sit-for anything-c-eldoc-show-in-mode-line-delay))
7992 (force-mode-line-update))))
7994 ;;; Calculation Result
7997 (defvar anything-c-source-calculation-result
7998 '((name . "Calculation Result")
7999 (dummy)
8000 (filtered-candidate-transformer . (lambda (candidates source)
8001 (list
8002 (condition-case nil
8003 (calc-eval anything-pattern)
8004 (error "error")))))
8005 (action ("Copy result to kill-ring" . kill-new))))
8006 ;; (anything 'anything-c-source-calculation-result)
8009 ;;; Google Suggestions
8012 ;; Internal
8013 (defvar anything-ggs-max-length-real-flag 0)
8014 (defvar anything-ggs-max-length-num-flag 0)
8016 (defun anything-c-google-suggest-fetch (input)
8017 "Fetch suggestions for INPUT from XML buffer.
8018 Return an alist with elements like (data . number_results)."
8019 (setq anything-ggs-max-length-real-flag 0
8020 anything-ggs-max-length-num-flag 0)
8021 (let ((request (concat anything-c-google-suggest-url
8022 (url-hexify-string input))))
8023 (flet ((fetch ()
8024 (loop
8025 with result-alist = (xml-get-children
8026 (car (xml-parse-region
8027 (point-min) (point-max)))
8028 'CompleteSuggestion)
8029 for i in result-alist
8030 for data = (cdr (caadr (assoc 'suggestion i)))
8031 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8032 for lqueries = (length (anything-c-ggs-set-number-result
8033 nqueries))
8034 for ldata = (length data)
8036 (progn
8037 (when (> ldata anything-ggs-max-length-real-flag)
8038 (setq anything-ggs-max-length-real-flag ldata))
8039 (when (> lqueries anything-ggs-max-length-num-flag)
8040 (setq anything-ggs-max-length-num-flag lqueries)))
8041 collect (cons data nqueries) into cont
8042 finally return cont)))
8043 (if anything-google-suggest-use-curl-p
8044 (with-temp-buffer
8045 (call-process "curl" nil t nil request)
8046 (fetch))
8047 (with-current-buffer
8048 (url-retrieve-synchronously request)
8049 (fetch))))))
8051 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8052 "Set candidates with result and number of google results found."
8053 (let ((suggestions
8054 (loop with suggested-results = (anything-c-google-suggest-fetch
8055 (or (and request-prefix
8056 (concat request-prefix " " anything-pattern))
8057 anything-pattern))
8058 for (real . numresult) in suggested-results
8059 ;; Prepare number of results with ","
8060 for fnumresult = (anything-c-ggs-set-number-result numresult)
8061 ;; Calculate number of spaces to add before fnumresult
8062 ;; if it is smaller than longest result
8063 ;; `anything-ggs-max-length-num-flag'.
8064 ;; e.g 1,234,567
8065 ;; 345,678
8066 ;; To be sure it is aligned properly.
8067 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8068 (- anything-ggs-max-length-num-flag (length fnumresult))
8070 ;; Add now the spaces before fnumresult.
8071 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8072 for interval = (- anything-ggs-max-length-real-flag (length real))
8073 for spaces = (make-string (+ 2 interval) ? )
8074 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8075 collect (cons display real))))
8076 (if (loop for (disp . dat) in suggestions
8077 thereis (equal dat anything-pattern))
8078 suggestions
8079 ;; if there is no suggestion exactly matching the input then
8080 ;; prepend a Search on Google item to the list
8081 (append
8082 suggestions
8083 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8084 anything-input))))))
8086 (defun anything-c-ggs-set-number-result (num)
8087 (if num
8088 (progn
8089 (and (numberp num) (setq num (number-to-string num)))
8090 (loop for i in (reverse (split-string num "" t))
8091 for count from 1
8092 append (list i) into C
8093 when (= count 3)
8094 append (list ",") into C
8095 and do (setq count 0)
8096 finally return
8097 (replace-regexp-in-string
8098 "^," "" (mapconcat 'identity (reverse C) ""))))
8099 "?"))
8101 (defvar anything-c-google-suggest-default-browser-function nil
8102 "*The browse url function you prefer to use with google suggest.
8103 When nil, use the first browser function available
8104 See `anything-browse-url-default-browser-alist'.")
8106 (defun anything-c-google-suggest-action (candidate)
8107 "Default action to jump to a google suggested candidate."
8108 (let ((arg (concat anything-c-google-suggest-search-url
8109 (url-hexify-string candidate))))
8110 (anything-aif anything-c-google-suggest-default-browser-function
8111 (funcall it arg)
8112 (anything-c-browse-url arg))))
8114 (defvar anything-c-google-suggest-default-function
8115 'anything-c-google-suggest-set-candidates
8116 "Default function to use in anything google suggest.")
8118 (defvar anything-c-source-google-suggest
8119 '((name . "Google Suggest")
8120 (candidates . (lambda ()
8121 (funcall anything-c-google-suggest-default-function)))
8122 (action . (("Google Search" . anything-c-google-suggest-action)))
8123 (volatile)
8124 (requires-pattern . 3)
8125 (delayed)))
8127 (defun anything-c-google-suggest-emacs-lisp ()
8128 "Try to emacs lisp complete with google suggestions."
8129 (anything-c-google-suggest-set-candidates "emacs lisp"))
8131 ;; (anything 'anything-c-source-google-suggest)
8133 ;;; Yahoo suggestions
8136 (defun anything-c-yahoo-suggest-fetch (input)
8137 "Fetch Yahoo suggestions for INPUT from XML buffer.
8138 Return an alist with elements like (data . number_results)."
8139 (let ((request (concat anything-c-yahoo-suggest-url
8140 (url-hexify-string input))))
8141 (flet ((fetch ()
8142 (loop
8143 with result-alist = (xml-get-children
8144 (car (xml-parse-region (point-min) (point-max)))
8145 'Result)
8146 for i in result-alist
8147 collect (caddr i))))
8148 (with-current-buffer
8149 (url-retrieve-synchronously request)
8150 (fetch)))))
8152 (defun anything-c-yahoo-suggest-set-candidates ()
8153 "Set candidates with Yahoo results found."
8154 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8155 (or suggestions
8156 (append
8157 suggestions
8158 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8159 anything-input))))))
8161 (defun anything-c-yahoo-suggest-action (candidate)
8162 "Default action to jump to a Yahoo suggested candidate."
8163 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8164 (url-hexify-string candidate))))
8166 (defvar anything-c-source-yahoo-suggest
8167 '((name . "Yahoo Suggest")
8168 (candidates . anything-c-yahoo-suggest-set-candidates)
8169 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8170 (volatile)
8171 (requires-pattern . 3)
8172 (delayed)))
8174 ;; (anything 'anything-c-source-yahoo-suggest)
8177 ;;; Web browser functions.
8180 (require 'browse-url)
8181 ;; If default setting of `w3m-command' is not
8182 ;; what you want you and you modify it, you will have to reeval
8183 ;; also `anything-browse-url-default-browser-alist'.
8184 (defvar w3m-command "/usr/bin/w3m")
8185 (defvar anything-c-home-url "http://www.google.fr"
8186 "*Default url to use as home url.")
8188 (defvar ac-browse-url-chromium-program "chromium-browser")
8189 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8190 (defvar anything-browse-url-default-browser-alist
8191 `((,w3m-command . w3m-browse-url)
8192 (,browse-url-firefox-program . browse-url-firefox)
8193 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8194 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8195 (,browse-url-kde-program . browse-url-kde)
8196 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8197 (,browse-url-mozilla-program . browse-url-mozilla)
8198 (,browse-url-galeon-program . browse-url-galeon)
8199 (,browse-url-netscape-program . browse-url-netscape)
8200 (,browse-url-mosaic-program . browse-url-mosaic)
8201 (,browse-url-xterm-program . browse-url-text-xterm))
8202 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8204 (defun* anything-c-generic-browser (url name &rest args)
8205 "Browse URL with NAME browser."
8206 (let ((proc (concat name " " url)))
8207 (message "Starting %s..." name)
8208 (apply 'start-process proc nil name
8209 (append args (list url)))
8210 (set-process-sentinel
8211 (get-process proc)
8212 #'(lambda (process event)
8213 (when (string= event "finished\n")
8214 (message "%s process %s" process event))))))
8216 (defun ac-browse-url-chromium (url)
8217 "Browse URL with google chrome browser."
8218 (interactive "sURL: ")
8219 (anything-c-generic-browser
8220 url ac-browse-url-chromium-program))
8222 (defun ac-browse-url-uzbl (url &optional ignore)
8223 "Browse URL with uzbl browser."
8224 (interactive "sURL: ")
8225 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8227 (defun anything-browse-url-default-browser (url &rest args)
8228 "Find the first available browser and ask it to load URL."
8229 (let ((default-browser-fn
8230 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8231 thereis (and exe (executable-find exe) fn))))
8232 (if default-browser-fn
8233 (apply default-browser-fn url args)
8234 (error "No usable browser found"))))
8236 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8237 "Default command to browse URL."
8238 (if browse-url-browser-function
8239 (browse-url url)
8240 (anything-browse-url-default-browser url)))
8243 ;;; Surfraw
8245 ;; Need external program surfraw.
8246 ;; <http://surfraw.alioth.debian.org/>
8248 (defvar anything-surfraw-default-browser-function nil
8249 "*The browse url function you prefer to use with surfraw.
8250 When nil, fallback to `browse-url-browser-function'.")
8252 ;; Internal
8253 (defvar anything-surfraw-engines-history nil)
8255 (defun anything-c-build-elvi-list ()
8256 "Return list of all engines and descriptions handled by surfraw."
8257 (cdr
8258 (with-temp-buffer
8259 (call-process "surfraw" nil t nil
8260 "-elvi")
8261 (split-string (buffer-string) "\n"))))
8264 ;;; Emms
8267 (defun anything-emms-stream-edit-bookmark (elm)
8268 "Change the information of current emms-stream bookmark from anything."
8269 (declare (special emms-stream-list))
8270 (let* ((cur-buf anything-current-buffer)
8271 (bookmark (assoc elm emms-stream-list))
8272 (name (read-from-minibuffer "Description: "
8273 (nth 0 bookmark)))
8274 (url (read-from-minibuffer "URL: "
8275 (nth 1 bookmark)))
8276 (fd (read-from-minibuffer "Feed Descriptor: "
8277 (int-to-string (nth 2 bookmark))))
8278 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8279 (format "%s" (car (last bookmark))))))
8280 (save-excursion
8281 (emms-streams)
8282 (when (re-search-forward (concat "^" name) nil t)
8283 (beginning-of-line)
8284 (emms-stream-delete-bookmark)
8285 (emms-stream-add-bookmark name url (string-to-number fd) type)
8286 (emms-stream-save-bookmarks-file)
8287 (emms-stream-quit)
8288 (anything-c-switch-to-buffer cur-buf)))))
8290 (defun anything-emms-stream-delete-bookmark (elm)
8291 "Delete an emms-stream bookmark from anything."
8292 (let* ((cur-buf anything-current-buffer)
8293 (bookmark (assoc elm emms-stream-list))
8294 (name (nth 0 bookmark)))
8295 (save-excursion
8296 (emms-streams)
8297 (when (re-search-forward (concat "^" name) nil t)
8298 (beginning-of-line)
8299 (emms-stream-delete-bookmark)
8300 (emms-stream-save-bookmarks-file)
8301 (emms-stream-quit)
8302 (anything-c-switch-to-buffer cur-buf)))))
8304 (defvar anything-c-source-emms-streams
8305 '((name . "Emms Streams")
8306 (init . (lambda ()
8307 (emms-stream-init)))
8308 (candidates . (lambda ()
8309 (declare (special emms-stream-list))
8310 (mapcar 'car emms-stream-list)))
8311 (action . (("Play" . (lambda (elm)
8312 (declare (special emms-stream-list))
8313 (let* ((stream (assoc elm emms-stream-list))
8314 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8315 (url (second stream)))
8316 (funcall fn url))))
8317 ("Delete" . anything-emms-stream-delete-bookmark)
8318 ("Edit" . anything-emms-stream-edit-bookmark)))
8319 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8320 ;; (anything 'anything-c-source-emms-streams)
8322 ;; Don't forget to set `emms-source-file-default-directory'
8323 (defvar anything-c-source-emms-dired
8324 '((name . "Music Directory")
8325 (candidates . (lambda ()
8326 (cddr (directory-files emms-source-file-default-directory))))
8327 (action .
8328 (("Play Directory" . (lambda (item)
8329 (emms-play-directory
8330 (expand-file-name
8331 item
8332 emms-source-file-default-directory))))
8333 ("Open dired in file's directory" . (lambda (item)
8334 (anything-c-open-dired
8335 (expand-file-name
8336 item
8337 emms-source-file-default-directory))))))
8338 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8339 ;; (anything 'anything-c-source-emms-dired)
8342 (defun anything-c-emms-files-modifier (candidates source)
8343 (let ((current-playlist (with-current-emms-playlist
8344 (loop
8345 with cur-list = (emms-playlist-tracks-in-region
8346 (point-min) (point-max))
8347 for i in cur-list
8348 collect (assoc-default 'name i)))))
8349 (loop for i in candidates
8350 if (member (cdr i) current-playlist)
8351 collect (cons (propertize (car i)
8352 'face 'anything-emms-playlist)
8353 (cdr i)) into lis
8354 else collect i into lis
8355 finally return lis)))
8357 (defun anything-c-emms-play-current-playlist ()
8358 "Play current playlist."
8359 (with-current-emms-playlist
8360 (emms-playlist-first)
8361 (emms-playlist-mode-play-smart)))
8363 (defvar anything-c-source-emms-files
8364 '((name . "Emms files")
8365 (candidates . (lambda ()
8366 (loop for v being the hash-values in emms-cache-db
8367 for name = (assoc-default 'name v)
8368 for artist = (or (assoc-default 'info-artist v) "unknown")
8369 for genre = (or (assoc-default 'info-genre v) "unknown")
8370 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8371 for song = (or (assoc-default 'info-title v) "unknown")
8372 for info = (concat artist " - " genre " - " tracknum ": " song)
8373 unless (string-match "^http:" name) collect (cons info name))))
8374 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8375 (action . (("Play file" . emms-play-file)
8376 ("Add to Playlist and play (C-u clear current)"
8377 . (lambda (candidate)
8378 (when anything-current-prefix-arg
8379 (emms-playlist-current-clear))
8380 (emms-playlist-new)
8381 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8382 (unless emms-player-playing-p
8383 (anything-c-emms-play-current-playlist))))))))
8385 ;; (anything 'anything-c-source-emms-files)
8388 ;;; Jabber Contacts (jabber.el)
8389 (defun anything-c-jabber-online-contacts ()
8390 "List online Jabber contacts."
8391 (with-no-warnings
8392 (let (jids)
8393 (dolist (item (jabber-concat-rosters) jids)
8394 (when (get item 'connected)
8395 (push (if (get item 'name)
8396 (cons (get item 'name) item)
8397 (cons (symbol-name item) item)) jids))))))
8399 (defvar anything-c-source-jabber-contacts
8400 '((name . "Jabber Contacts")
8401 (init . (lambda () (require 'jabber)))
8402 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8403 (action . (lambda (x)
8404 (jabber-chat-with
8405 (jabber-read-account)
8406 (symbol-name
8407 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8408 ;; (anything 'anything-c-source-jabber-contacts)
8412 ;;; Call source.
8413 (defvar anything-source-select-buffer "*anything source select*")
8414 (defvar anything-c-source-call-source
8415 `((name . "Call anything source")
8416 (candidate-number-limit)
8417 (candidates
8418 . (lambda ()
8419 (loop for vname in (all-completions "anything-c-source-" obarray)
8420 for var = (intern vname)
8421 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8422 if name collect
8423 (cons (format "%s `%s'"
8424 name (propertize vname 'face 'font-lock-variable-name-face))
8425 var))))
8426 (action
8427 . (("Invoke anything with selected source"
8429 (lambda (candidate)
8430 (setq anything-candidate-number-limit 9999)
8431 (anything candidate nil nil nil nil
8432 anything-source-select-buffer)))
8433 ("Describe variable" . describe-variable)
8434 ("Find variable" . find-variable)))
8435 (persistent-action . describe-variable)
8436 (persistent-help . "Show description of this source")))
8437 ;; (anything 'anything-c-source-call-source)
8439 (defun anything-call-source-from-anything ()
8440 "Call anything source within `anything' session."
8441 (interactive)
8442 (setq anything-input-idle-delay 0)
8443 (anything-set-sources '(anything-c-source-call-source)))
8445 ;;; Execute Preconfigured anything.
8446 (defvar anything-c-source-anything-commands
8447 '((name . "Preconfigured Anything")
8448 (candidates . anything-c-anything-commands-candidates)
8449 (type . command)
8450 (candidate-number-limit)))
8451 ;; (anything 'anything-c-source-anything-commands)
8453 (defun anything-c-anything-commands-candidates ()
8454 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8455 collect (cons (if (where-is-internal cmd nil t)
8456 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8457 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8458 cmd)))
8461 ;;; Occur
8464 (defun anything-c-occur-init ()
8465 "Create the initial anything occur buffer.
8466 If region is active use region as buffer contents
8467 instead of whole buffer."
8468 (with-current-buffer (anything-candidate-buffer 'global)
8469 (erase-buffer)
8470 (let ((buf-contents
8471 (with-anything-current-buffer
8472 (if (anything-region-active-p)
8473 (buffer-substring (region-beginning) (region-end))
8474 (buffer-substring (point-min) (point-max))))))
8475 (insert buf-contents))))
8477 (defun anything-c-occur-get-line (s e)
8478 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8480 (defun anything-c-occur-query-replace-regexp (candidate)
8481 "Query replace regexp starting from CANDIDATE.
8482 If region is active ignore CANDIDATE and replace only in region.
8483 With a prefix arg replace only matches surrounded by word boundaries,
8484 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8485 (let ((regexp anything-input))
8486 (unless (anything-region-active-p)
8487 (anything-c-action-line-goto candidate))
8488 (apply 'query-replace-regexp
8489 (anything-c-query-replace-args regexp))))
8491 (defvar anything-c-source-occur
8492 '((name . "Occur")
8493 (init . anything-c-occur-init)
8494 (candidates-in-buffer)
8495 (migemo)
8496 (get-line . anything-c-occur-get-line)
8497 (display-to-real . anything-c-display-to-real-line)
8498 (action . (("Go to Line" . anything-c-action-line-goto)
8499 ("Query replace regexp (C-u Not inside word.)"
8500 . anything-c-occur-query-replace-regexp)))
8501 (recenter)
8502 (requires-pattern . 1)
8503 (delayed)
8504 (volatile)))
8505 ;; (anything 'anything-c-source-occur)
8508 ;;; Anything browse code.
8509 (defun anything-c-browse-code-get-line (beg end)
8510 "Select line if it match the regexp corresponding to current `major-mode'.
8511 Line is parsed for BEG position to END position."
8512 (let ((str-line (buffer-substring beg end))
8513 (regexp (assoc-default major-mode
8514 anything-c-browse-code-regexp-alist))
8515 (num-line (if (string= anything-pattern "") beg (1- beg))))
8516 (when (and regexp (string-match regexp str-line))
8517 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8520 (defvar anything-c-source-browse-code
8521 '((name . "Browse code")
8522 (init . (lambda ()
8523 (anything-candidate-buffer anything-current-buffer)
8524 (with-anything-current-buffer
8525 (jit-lock-fontify-now))))
8526 (candidate-number-limit . 9999)
8527 (candidates-in-buffer)
8528 (get-line . anything-c-browse-code-get-line)
8529 (type . line)
8530 (recenter)))
8533 ;; Do many actions for input
8534 (defvar anything-c-source-create
8535 '((name . "Create")
8536 (dummy)
8537 (action)
8538 (action-transformer . anything-create--actions))
8539 "Do many create actions from `anything-pattern'.
8540 See also `anything-create--actions'.")
8541 ;; (anything 'anything-c-source-create)
8543 (defun anything-create-from-anything ()
8544 "Run `anything-create' from `anything' as a fallback."
8545 (interactive)
8546 (anything-run-after-quit 'anything-create nil anything-pattern))
8548 (defun anything-create--actions (&rest ignored)
8549 "Default actions for `anything-create' / `anything-c-source-create'."
8550 (remove-if-not
8551 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8552 (append anything-create--actions-private
8553 '(("find-file" . find-file)
8554 ("find-file other window" . find-file-other-window)
8555 ("New buffer" . anything-c-switch-to-buffer)
8556 ("New buffer other window" . switch-to-buffer-other-window)
8557 ("Bookmark Set" . bookmark-set)
8558 ("Set Register" .
8559 (lambda (x) (set-register (read-char "Register: ") x)))
8560 ("Insert Linkd star" . linkd-insert-star)
8561 ("Insert Linkd Tag" . linkd-insert-tag)
8562 ("Insert Linkd Link" . linkd-insert-link)
8563 ("Insert Linkd Lisp" . linkd-insert-lisp)
8564 ("Insert Linkd Wiki" . linkd-insert-wiki)
8565 ("Google Search" . google)))))
8568 ;; Minibuffer History
8571 (defvar anything-c-source-minibuffer-history
8572 '((name . "Minibuffer History")
8573 (header-name . (lambda (name)
8574 (format "%s (%s)" name minibuffer-history-variable)))
8575 (candidates
8576 . (lambda ()
8577 (let ((history (loop
8578 for i in (symbol-value minibuffer-history-variable)
8579 unless (string= "" i) collect i)))
8580 (if (consp (car history))
8581 (mapcar 'prin1-to-string history)
8582 history))))
8583 (migemo)
8584 (action . insert)))
8585 ;; (anything 'anything-c-source-minibuffer-history)
8588 ;;; Elscreen
8591 (defvar anything-c-source-elscreen
8592 '((name . "Elscreen")
8593 (candidates . (lambda ()
8594 (if (cdr (elscreen-get-screen-to-name-alist))
8595 (sort
8596 (loop for sname in (elscreen-get-screen-to-name-alist)
8597 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8598 finally (return lst))
8599 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8600 (action . (("Change Screen".
8601 (lambda (candidate)
8602 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8603 ("Kill Screen(s)".
8604 (lambda (candidate)
8605 (dolist (i (anything-marked-candidates))
8606 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8607 (elscreen-kill))))
8608 ("Only Screen".
8609 (lambda (candidate)
8610 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8611 (elscreen-kill-others)))))))
8612 ;; (anything 'anything-c-source-elscreen)
8615 ;;;; <System>
8617 ;;; Top (process)
8618 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8619 "Top command (batch mode). %s is replaced with `frame-width'.")
8620 (defvar anything-c-source-top
8621 '((name . "Top (Press C-c C-u to refresh)")
8622 (init . anything-c-top-init)
8623 (candidates-in-buffer)
8624 (display-to-real . anything-c-top-display-to-real)
8625 (update . anything-c-top-update)
8626 (persistent-action . anything-c-top-sh-persistent-action)
8627 (persistent-help . "SIGTERM")
8628 (action
8629 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8630 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8631 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8632 ;; (anything 'anything-c-source-top)
8634 (defun anything-c-top-sh (cmd)
8635 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8637 (defun anything-c-top-sh-persistent-action (pid)
8638 (delete-other-windows)
8639 (anything-c-top-sh (format "kill -TERM %s" pid))
8640 (anything-force-update))
8642 (defun anything-c-top-init ()
8643 (with-current-buffer (anything-candidate-buffer 'global)
8644 (call-process-shell-command
8645 (format anything-c-top-command
8646 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8647 nil (current-buffer))))
8649 (defun anything-c-top-display-to-real (line)
8650 (car (split-string line)))
8652 (defun anything-c-top-update ()
8653 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8654 (anything-c-top-init)))
8656 ;;; Timers
8657 (defvar anything-c-source-absolute-time-timers
8658 '((name . "Absolute Time Timers")
8659 (candidates . timer-list)
8660 (type . timer)))
8661 ;; (anything 'anything-c-source-absolute-time-timers)
8663 (defvar anything-c-source-idle-time-timers
8664 '((name . "Idle Time Timers")
8665 (candidates . timer-idle-list)
8666 (type . timer)))
8667 ;; (anything 'anything-c-source-idle-time-timers)
8669 (defun anything-c-timer-real-to-display (timer)
8670 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8671 (append timer nil) ;use `append' to convert vector->list
8672 (format "%s repeat=%5S %s(%s)"
8673 (let ((time (list t1 t2 t3)))
8674 (if idle-delay
8675 (format-time-string "idle-for=%5s" time)
8676 (format-time-string "%m/%d %T" time)))
8677 repeat-delay
8678 func
8679 (mapconcat 'prin1-to-string args " "))))
8681 ;;; X RandR resolution change
8682 ;;; FIXME I do not care multi-display.
8683 (defvar anything-c-xrandr-output "VGA")
8684 (defvar anything-c-xrandr-screen "0")
8685 (defvar anything-c-source-xrandr-change-resolution
8686 '((name . "Change Resolution")
8687 (candidates
8688 . (lambda ()
8689 (with-temp-buffer
8690 (call-process "xrandr" nil (current-buffer) nil
8691 "--screen" anything-c-xrandr-screen "-q")
8692 (goto-char 1)
8693 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8694 collect (match-string 1)))))
8695 (action
8696 ("Change Resolution" . (lambda (mode)
8697 (call-process "xrandr" nil nil nil
8698 "--screen" anything-c-xrandr-screen
8699 "--output" anything-c-xrandr-output
8700 "--mode" mode))))))
8701 ;; (anything 'anything-c-source-xrandr-change-resolution)
8703 ;;; Xfont selection
8706 (defun anything-c-persistent-xfont-action (elm)
8707 "Show current font temporarily"
8708 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8709 (default-font elm))
8710 (unwind-protect
8711 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8712 (set-frame-font current-font))))
8714 (defvar anything-c-xfonts-cache nil)
8715 (defvar anything-c-source-xfonts
8716 '((name . "X Fonts")
8717 (init . (lambda ()
8718 (unless anything-c-xfonts-cache
8719 (setq anything-c-xfonts-cache
8720 (x-list-fonts "*")))))
8721 (candidates . anything-c-xfonts-cache)
8722 (action . (("Copy to kill ring" . (lambda (elm)
8723 (kill-new elm)))
8724 ("Set Font" . (lambda (elm)
8725 (kill-new elm)
8726 (set-frame-font elm 'keep-size)
8727 (message "New font have been copied to kill ring")))))
8728 (persistent-action . anything-c-persistent-xfont-action)
8729 (persistent-help . "Switch to this font temporarily")))
8730 ;; (anything 'anything-c-source-xfonts)
8732 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8735 (defvar anything-c-ucs-max-len 0)
8736 (defun anything-c-calculate-ucs-max-len ()
8737 "Calculate the length of longest `ucs-names' candidate."
8738 (loop with count = 0
8739 for (n . v) in (ucs-names)
8740 for len = (length n)
8741 if (> len count)
8742 do (setq count len)
8743 finally return count))
8745 (defun anything-c-ucs-init ()
8746 "Initialize an anything buffer with ucs symbols.
8747 Only math* symbols are collected."
8748 (unless (> anything-c-ucs-max-len 0)
8749 (setq anything-c-ucs-max-len
8750 (anything-c-calculate-ucs-max-len)))
8751 (with-current-buffer (anything-candidate-buffer
8752 (get-buffer-create "*anything ucs*"))
8753 ;; `ucs-names' fn will not run again, data is cached in
8754 ;; var `ucs-names'.
8755 (loop for (n . v) in (ucs-names)
8756 for len = (length n)
8757 for diff = (+ (- anything-c-ucs-max-len len) 2)
8758 unless (string= "" n)
8759 do (progn (insert (concat
8760 n ":"
8761 (make-string
8762 diff ? )))
8763 (ucs-insert v)
8764 (insert "\n")))))
8766 (defun anything-c-ucs-forward-char (candidate)
8767 (with-anything-current-buffer
8768 (forward-char 1)))
8770 (defun anything-c-ucs-backward-char (candidate)
8771 (with-anything-current-buffer
8772 (forward-char -1)))
8774 (defun anything-c-ucs-delete-backward (candidate)
8775 (with-anything-current-buffer
8776 (delete-char -1)))
8778 (defun anything-c-ucs-insert-char (candidate)
8779 (with-anything-current-buffer
8780 (insert
8781 (replace-regexp-in-string
8782 " " ""
8783 (cadr (split-string candidate ":"))))))
8785 (defun anything-c-ucs-persistent-insert ()
8786 (interactive)
8787 (anything-execute-persistent-action 'action-insert))
8789 (defun anything-c-ucs-persistent-forward ()
8790 (interactive)
8791 (anything-execute-persistent-action 'action-forward))
8793 (defun anything-c-ucs-persistent-backward ()
8794 (interactive)
8795 (anything-execute-persistent-action 'action-back))
8797 (defun anything-c-ucs-persistent-delete ()
8798 (interactive)
8799 (anything-execute-persistent-action 'action-delete))
8801 (defvar anything-c-source-ucs
8802 '((name . "Ucs names")
8803 (init . anything-c-ucs-init)
8804 (candidate-number-limit . 9999)
8805 (candidates-in-buffer)
8806 (mode-line . anything-c-ucs-mode-line-string)
8807 (action-insert . anything-c-ucs-insert-char)
8808 (action-forward . anything-c-ucs-forward-char)
8809 (action-back . anything-c-ucs-backward-char)
8810 (action-delete . anything-c-ucs-delete-backward)
8811 (action . (("Insert" . anything-c-ucs-insert-char)
8812 ("Forward char" . anything-c-ucs-forward-char)
8813 ("Backward char" . anything-c-ucs-backward-char)
8814 ("Delete char backward" . anything-c-ucs-delete-backward))))
8815 "Source for collecting `ucs-names' math symbols.")
8818 ;;; Emacs process
8821 (defvar anything-c-source-emacs-process
8822 '((name . "Emacs Process")
8823 (candidates . (lambda () (mapcar #'process-name (process-list))))
8824 (persistent-action . (lambda (elm)
8825 (delete-process (get-process elm))
8826 (anything-delete-current-selection)))
8827 (persistent-help . "Kill Process")
8828 (action ("Kill Process" . (lambda (elm)
8829 (delete-process (get-process elm)))))))
8830 ;; (anything 'anything-c-source-emacs-process)
8832 ;;; World time
8835 (defvar anything-c-source-time-world
8836 '((name . "Time World List")
8837 (init . (lambda ()
8838 (let ((anything-buffer (anything-candidate-buffer 'global)))
8839 (with-current-buffer anything-buffer
8840 (display-time-world-display display-time-world-list)))))
8841 (candidates-in-buffer)))
8845 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8848 (defvar anything-c-source-apt
8849 '((name . "APT")
8850 (init . anything-c-apt-init)
8851 (candidates-in-buffer)
8852 (candidate-transformer anything-c-apt-candidate-transformer)
8853 (display-to-real . anything-c-apt-display-to-real)
8854 (requires-pattern . 2)
8855 (delayed)
8856 (action
8857 ("Show package description" . anything-c-apt-cache-show)
8858 ("Install package" . anything-c-apt-install)
8859 ("Remove package" . anything-c-apt-uninstall)
8860 ("Purge package" . anything-c-apt-purge))
8861 (persistent-action . anything-c-apt-persistent-action)
8862 (persistent-help . "Show - C-u Refresh")))
8863 ;; (anything 'anything-c-source-apt)
8865 (defvar anything-c-apt-query "emacs")
8866 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8867 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8868 (defvar anything-c-apt-installed-packages nil)
8869 (defvar anything-c-apt-all-packages nil)
8872 (defun anything-c-apt-refresh ()
8873 "Refresh installed candidates list."
8874 (setq anything-c-apt-installed-packages nil)
8875 (setq anything-c-apt-all-packages nil)
8876 (anything-force-update))
8878 (defun anything-c-apt-persistent-action (candidate)
8879 "Persistent action for APT source."
8880 (if current-prefix-arg
8881 (anything-c-apt-refresh)
8882 (anything-c-apt-cache-show candidate)))
8884 (defun anything-c-apt-candidate-transformer (candidates)
8885 "Show installed candidates in a different color."
8886 (loop
8887 with all
8888 for cand in candidates
8889 for name = (anything-c-apt-display-to-real cand)
8890 if (member name anything-c-apt-installed-packages)
8891 collect (propertize cand 'face 'anything-apt-installed) into all
8892 else collect cand into all finally return all))
8894 (defun anything-c-apt-init ()
8895 "Initialize list of debian packages."
8896 (let ((query ""))
8897 (unless (and anything-c-apt-installed-packages
8898 anything-c-apt-all-packages)
8899 (message "Loading package list...")
8900 (setq anything-c-apt-installed-packages
8901 (with-temp-buffer
8902 (call-process-shell-command "dpkg --get-selections"
8903 nil (current-buffer))
8904 (loop for i in (split-string (buffer-string) "\n" t)
8905 collect (car (split-string i)))))
8906 (setq anything-c-apt-all-packages
8907 (with-current-buffer
8908 (anything-candidate-buffer
8909 (get-buffer-create (format "*anything-apt*")))
8910 (erase-buffer)
8911 (call-process-shell-command
8912 (format anything-c-apt-search-command query)
8913 nil (current-buffer))))
8914 (message "Loading package list done")
8915 (sit-for 0.5))))
8917 (defun anything-c-apt-display-to-real (line)
8918 "Return only name of a debian package.
8919 LINE is displayed like:
8920 package name - description."
8921 (car (split-string line " - ")))
8923 (defun anything-c-shell-command-if-needed (command)
8924 "Run shell command COMMAND to describe package.
8925 If a buffer named COMMAND already exists, just switch to it."
8926 (let ((buf (get-buffer command)))
8927 (anything-c-switch-to-buffer (get-buffer-create command))
8928 (unless buf (insert (shell-command-to-string command)))))
8930 (defun anything-c-apt-cache-show (package)
8931 "Show information on apt package PACKAGE."
8932 (anything-c-shell-command-if-needed
8933 (format anything-c-apt-show-command package)))
8935 (defun anything-c-apt-install (package)
8936 "Run 'apt-get install' shell command on PACKAGE."
8937 (anything-c-apt-generic-action :action 'install))
8939 (defun anything-c-apt-uninstall (package)
8940 "Run 'apt-get remove' shell command on PACKAGE."
8941 (anything-c-apt-generic-action :action 'uninstall))
8943 (defun anything-c-apt-purge (package)
8944 "Run 'apt-get purge' shell command on PACKAGE."
8945 (anything-c-apt-generic-action :action 'purge))
8947 (defun* anything-c-apt-generic-action (&key action)
8948 "Run 'apt-get ACTION'.
8949 Support install, remove and purge actions."
8950 (ansi-term (getenv "SHELL") "anything apt")
8951 (term-line-mode)
8952 (let ((command (case action
8953 ('install "sudo apt-get install ")
8954 ('uninstall "sudo apt-get remove ")
8955 ('purge "sudo apt-get purge ")
8956 (t (error "Unknow action"))))
8957 (beg (point))
8959 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
8960 (anything-marked-candidates) " ")))
8961 (goto-char (point-max))
8962 (insert (concat command cand-list))
8963 (setq end (point))
8964 (if (y-or-n-p (format "%s package" (symbol-name action)))
8965 (progn
8966 (setq anything-c-external-commands-list nil)
8967 (setq anything-c-apt-installed-packages nil)
8968 (term-char-mode) (term-send-input))
8969 (delete-region beg end) (term-send-eof) (kill-buffer))))
8971 ;; (anything-c-apt-install "jed")
8974 ;;; Anything UI for gentoo portage.
8977 (defvar anything-c-gentoo-use-flags nil)
8978 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
8979 (defvar anything-c-cache-gentoo nil)
8980 (defvar anything-c-cache-world nil)
8981 (defvar anything-c-source-gentoo
8982 '((name . "Portage sources")
8983 (init . (lambda ()
8984 (get-buffer-create anything-c-gentoo-buffer)
8985 (unless anything-c-cache-gentoo
8986 (anything-c-gentoo-setup-cache))
8987 (unless anything-c-cache-world
8988 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
8989 (anything-c-gentoo-init-list)))
8990 (candidates-in-buffer)
8991 (match . identity)
8992 (candidate-transformer anything-c-highlight-world)
8993 (action . (("Show package" . (lambda (elm)
8994 (anything-c-gentoo-eshell-action elm "eix")))
8995 ("Show history" . (lambda (elm)
8996 (if (member elm anything-c-cache-world)
8997 (anything-c-gentoo-eshell-action elm "genlop -qe")
8998 (message "No infos on packages not yet installed"))))
8999 ("Copy in kill-ring" . kill-new)
9000 ("insert at point" . insert)
9001 ("Browse HomePage" . (lambda (elm)
9002 (let ((urls (anything-c-gentoo-get-url elm)))
9003 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9004 ("Show extra infos" . (lambda (elm)
9005 (if (member elm anything-c-cache-world)
9006 (anything-c-gentoo-eshell-action elm "genlop -qi")
9007 (message "No infos on packages not yet installed"))))
9008 ("Show use flags" . (lambda (elm)
9009 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9010 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9011 (font-lock-mode 1)))
9012 ("Run emerge pretend" . (lambda (elm)
9013 (anything-c-gentoo-eshell-action elm "emerge -p")))
9014 ("Emerge" . (lambda (elm)
9015 (anything-gentoo-install elm :action 'install)))
9016 ("Unmerge" . (lambda (elm)
9017 (anything-gentoo-install elm :action 'uninstall)))
9018 ("Show dependencies" . (lambda (elm)
9019 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9020 ("Show related files" . (lambda (elm)
9021 (anything-c-gentoo-default-action elm "equery" "files")))
9022 ("Refresh" . (lambda (elm)
9023 (anything-c-gentoo-setup-cache)
9024 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9026 ;; (anything 'anything-c-source-gentoo)
9028 (defun* anything-gentoo-install (candidate &key action)
9029 (setq anything-c-external-commands-list nil)
9030 (ansi-term (getenv "SHELL") "Gentoo emerge")
9031 (term-line-mode)
9032 (let ((command (case action
9033 ('install "sudo emerge -av ")
9034 ('uninstall "sudo emerge -avC ")
9035 (t (error "Unknow action"))))
9036 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9037 (beg (point)) end)
9038 (goto-char (point-max))
9039 (insert (concat command elms))
9040 (setq end (point))
9041 (term-char-mode) (term-send-input)))
9043 (defun anything-c-gentoo-default-action (elm command &rest args)
9044 "Gentoo default action that use `anything-c-gentoo-buffer'."
9045 (if (member elm anything-c-cache-world)
9046 (progn
9047 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9048 (erase-buffer)
9049 (let ((com-list (append args (list elm))))
9050 (apply #'call-process command nil t nil
9051 com-list)))
9052 (message "No infos on packages not yet installed")))
9054 (defvar anything-c-source-use-flags
9055 '((name . "Use Flags")
9056 (init . (lambda ()
9057 (unless anything-c-gentoo-use-flags
9058 (anything-c-gentoo-setup-use-flags-cache))
9059 (anything-c-gentoo-get-use)))
9060 (candidates-in-buffer)
9061 (match . identity)
9062 (candidate-transformer anything-c-highlight-local-use)
9063 (action . (("Description"
9064 . (lambda (elm)
9065 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9066 (erase-buffer)
9067 (apply #'call-process "euse" nil t nil
9068 `("-i"
9069 ,elm))
9070 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9071 (font-lock-mode 1)))
9072 ("Enable"
9073 . (lambda (elm)
9074 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9075 ("Disable"
9076 . (lambda (elm)
9077 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9078 ("Remove"
9079 . (lambda (elm)
9080 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9081 ("Show which dep use this flag"
9082 . (lambda (elm)
9083 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9084 (erase-buffer)
9085 (apply #'call-process "equery" nil t nil
9086 `("-C"
9088 ,elm))))))))
9091 ;; (anything 'anything-c-source-use-flags)
9093 (defun anything-c-gentoo-init-list ()
9094 "Initialize buffer with all packages in Portage."
9095 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9096 (buf (anything-candidate-buffer 'portage-buf)))
9097 (with-current-buffer buf
9098 (dolist (i anything-c-cache-gentoo)
9099 (insert (concat i "\n"))))))
9101 (defun anything-c-gentoo-setup-cache ()
9102 "Set up `anything-c-cache-gentoo'"
9103 (setq anything-c-cache-gentoo
9104 (split-string (with-temp-buffer
9105 (call-process "eix" nil t nil
9106 "--only-names")
9107 (buffer-string)))))
9109 (defun anything-c-gentoo-eshell-action (elm command)
9110 (when (get-buffer "*EShell Command Output*")
9111 (kill-buffer "*EShell Command Output*"))
9112 (message "Wait searching...")
9113 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9114 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9115 (progn
9116 (save-window-excursion
9117 (pop-to-buffer "*scratch*")
9118 (eshell-command (format "%s %s" command elm)))
9119 (pop-to-buffer "*EShell Command Output*"))
9120 (eshell-command (format "%s %s" command elm)))))
9122 (defun anything-c-gentoo-get-use ()
9123 "Initialize buffer with all use flags."
9124 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9125 (buf (anything-candidate-buffer 'use-buf)))
9126 (with-current-buffer buf
9127 (dolist (i anything-c-gentoo-use-flags)
9128 (insert (concat i "\n"))))))
9131 (defun anything-c-gentoo-setup-use-flags-cache ()
9132 "Setup `anything-c-gentoo-use-flags'"
9133 (setq anything-c-gentoo-use-flags
9134 (split-string (with-temp-buffer
9135 (call-process "eix" nil t nil
9136 "--print-all-useflags")
9137 (buffer-string)))))
9139 (defun anything-c-gentoo-get-url (elm)
9140 "Return a list of urls from eix output."
9141 (loop
9142 with url-list = (split-string
9143 (with-temp-buffer
9144 (call-process "eix" nil t nil
9145 elm "--format" "<homepage>\n")
9146 (buffer-string)))
9147 with all
9148 for i in url-list
9149 when (and (string-match "^http://.*" i)
9150 (not (member i all)))
9151 collect i into all
9152 finally return all))
9154 (defun anything-c-gentoo-get-world ()
9155 "Return list of all installed package on your system."
9156 (split-string (with-temp-buffer
9157 (call-process "qlist" nil t nil
9158 "-I")
9159 (buffer-string))))
9161 (defun anything-c-gentoo-get-local-use ()
9162 (split-string (with-temp-buffer
9163 (call-process "portageq" nil t nil
9164 "envvar"
9165 "USE")
9166 (buffer-string))))
9169 (defun anything-c-highlight-world (eix)
9170 "Highlight all installed package."
9171 (loop for i in eix
9172 if (member i anything-c-cache-world)
9173 collect (propertize i 'face 'anything-gentoo-match-face)
9174 else
9175 collect i))
9177 (defun anything-c-highlight-local-use (use-flags)
9178 (let ((local-uses (anything-c-gentoo-get-local-use)))
9179 (loop for i in use-flags
9180 if (member i local-uses)
9181 collect (propertize i 'face 'anything-gentoo-match-face)
9182 else
9183 collect i)))
9187 ;;; Anything ratpoison UI
9190 (defvar anything-c-source-ratpoison-commands
9191 '((name . "Ratpoison Commands")
9192 (init . anything-c-ratpoison-commands-init)
9193 (candidates-in-buffer)
9194 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9195 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9196 (candidate-number-limit)))
9197 ;; (anything 'anything-c-source-ratpoison-commands)
9199 (defun anything-c-ratpoison-commands-init ()
9200 (unless (anything-candidate-buffer)
9201 (with-current-buffer (anything-candidate-buffer 'global)
9202 ;; with ratpoison prefix key
9203 (save-excursion
9204 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9205 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9206 (replace-match "<ratpoison> \\1: \\2"))
9207 (goto-char (point-max))
9208 ;; direct binding
9209 (save-excursion
9210 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9211 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9212 (replace-match "\\1: \\2")))))
9214 (defun anything-c-ratpoison-commands-display-to-real (display)
9215 (and (string-match ": " display)
9216 (substring display (match-end 0))))
9218 (defun anything-c-ratpoison-commands-execute (candidate)
9219 (call-process "ratpoison" nil nil nil "-ic" candidate))
9223 ;;; Anything `completing-read' replacement
9226 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9227 "Convert COLLECTION to list removing elements that don't match TEST.
9228 See `anything-comp-read' about supported COLLECTION arguments.
9230 SORT-FN is a predicate to sort COLLECTION.
9232 ALISTP when non--nil will not use `all-completions' to collect
9233 candidates because it doesn't handle alists correctly for anything.
9234 i.e In `all-completions' the keys \(cars of elements\)
9235 are the possible completions. In anything we want to use the cdr instead
9236 like \(display . real\).
9237 See docstring of `all-completions' for more info.
9239 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9240 (let ((cands
9241 (cond ((and (eq collection obarray) test)
9242 (all-completions "" collection test))
9243 ((and (vectorp collection) test)
9244 (loop for i across collection when (funcall test i) collect i))
9245 ((vectorp collection)
9246 (loop for i across collection collect i))
9247 ((and alistp test)
9248 (loop for i in collection when (funcall test i) collect i))
9249 (alistp collection)
9250 ((and collection test)
9251 (all-completions "" collection test))
9252 (t (all-completions "" collection)))))
9253 (if sort-fn (sort cands sort-fn) cands)))
9255 (defun anything-cr-default-transformer (candidates source)
9256 "Default filter candidate function for `anything-comp-read'.
9257 Do nothing, just return candidate list unmodified."
9258 candidates)
9260 (defun* anything-comp-read (prompt collection
9261 &key
9262 test
9263 initial-input
9264 default
9265 preselect
9266 (buffer "*Anything Completions*")
9267 must-match
9268 (requires-pattern 0)
9269 (history nil)
9270 (persistent-action nil)
9271 (persistent-help "DoNothing")
9272 (name "Anything Completions")
9273 (volatile t)
9274 sort
9275 (fc-transformer 'anything-cr-default-transformer)
9276 (marked-candidates nil)
9277 (alistp t))
9278 "Anything `completing-read' emulation.
9279 PROMPT is the prompt name to use.
9280 COLLECTION can be a list, vector, obarray or hash-table.
9281 It can be also a function that receives three arguments:
9282 the values string, predicate and t. See `all-completions' for more details.
9284 Keys description:
9286 TEST: A predicate called with one arg i.e candidate.
9287 INITIAL-INPUT: Same as initial-input arg in `anything'.
9288 PRESELECT: See preselect arg of `anything'.
9289 DEFAULT: This option is used only for compatibility with regular
9290 Emacs `completing-read'.
9291 BUFFER: Name of anything-buffer.
9292 MUST-MATCH: Candidate selected must be one of COLLECTION.
9293 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9294 HISTORY: A list containing specific history, default is nil.
9295 When it is non--nil, all elements of HISTORY are displayed in
9296 a special source before COLLECTION.
9297 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9298 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9299 NAME: The name related to this local source.
9300 VOLATILE: Use volatile attribute \(enabled by default\).
9301 SORT: A predicate to give to `sort' e.g `string-lessp'.
9302 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9303 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9304 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9306 Any prefix args passed during `anything-comp-read' invocation will be recorded
9307 in `anything-current-prefix-arg', otherwise if prefix args where given before
9308 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9309 That's mean you can pass prefix args before or after calling a command
9310 that use `anything-comp-read' See `anything-M-x' for example."
9311 (when (get-buffer anything-action-buffer)
9312 (kill-buffer anything-action-buffer))
9313 (flet ((action-fn (candidate)
9314 (if marked-candidates
9315 (anything-marked-candidates)
9316 (identity candidate))))
9317 (let ((hist `((name . ,(format "%s History" name))
9318 (candidates
9319 . (lambda ()
9320 (let ((all (anything-comp-read-get-candidates
9321 history nil nil ,alistp)))
9322 (anything-fast-remove-dups
9323 (if (and default (not (string= default "")))
9324 (delq nil (cons default (delete default all)))
9325 all)
9326 :test 'equal))))
9327 (filtered-candidate-transformer
9328 . (lambda (candidates sources)
9329 (loop for i in candidates
9330 do (set-text-properties 0 (length i) nil i)
9331 collect i)))
9332 (persistent-action . ,persistent-action)
9333 (persistent-help . ,persistent-help)
9334 (action . ,'action-fn)))
9335 (src `((name . ,name)
9336 (candidates
9337 . (lambda ()
9338 (let ((cands (anything-comp-read-get-candidates
9339 collection test sort alistp)))
9340 (unless (or must-match (string= anything-pattern ""))
9341 (setq cands (append (list anything-pattern) cands)))
9342 (if (and default (not (string= default "")))
9343 (delq nil (cons default (delete default cands)))
9344 cands))))
9345 (filtered-candidate-transformer ,fc-transformer)
9346 (requires-pattern . ,requires-pattern)
9347 (persistent-action . ,persistent-action)
9348 (persistent-help . ,persistent-help)
9349 (action . ,'action-fn))))
9350 (when volatile (setq src (append src '((volatile)))))
9351 (or (anything
9352 :sources `(,hist ,src)
9353 :input initial-input
9354 :default default
9355 :preselect preselect
9356 :prompt prompt
9357 :resume 'noresume
9358 :buffer buffer)
9359 (keyboard-quit)))))
9361 ;; Generic completing-read
9363 ;; Support also function as collection.
9364 ;; e.g M-x man is supported.
9365 ;; Support hash-table and vectors as collection.
9366 ;; NOTE:
9367 ;; Some crap emacs functions may not be supported
9368 ;; like ffap-alternate-file (bad use of completing-read)
9369 ;; and maybe others.
9370 ;; Provide a mode `anything-completion-mode' which turn on
9371 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9373 (defvar anything-completion-mode-string " AC")
9375 (defvar anything-completion-mode-quit-message
9376 "Anything completion disabled")
9378 (defvar anything-completion-mode-start-message
9379 "Anything completion enabled")
9381 ;;; Specialized handlers
9384 (defun anything-completing-read-symbols
9385 (prompt collection test require-match init
9386 hist default inherit-input-method name buffer)
9387 "Specialized function for fast symbols completion in `ac-mode'."
9389 (anything
9390 :sources `((name . ,name)
9391 (init . (lambda ()
9392 (with-current-buffer (anything-candidate-buffer 'global)
9393 (goto-char (point-min))
9394 (when (and default (stringp default)
9395 ;; Some defaults args result as
9396 ;; (symbol-name nil) == "nil".
9397 ;; e.g debug-on-entry.
9398 (not (string= default "nil")))
9399 (insert (concat default "\n")))
9400 (loop with all = (all-completions "" collection test)
9401 for sym in all
9402 unless (and default (eq sym default))
9403 do (insert (concat sym "\n"))))))
9404 (persistent-action . anything-lisp-completion-persistent-action)
9405 (persistent-help . "Show brief doc in mode-line")
9406 (candidates-in-buffer)
9407 (action . identity))
9408 :prompt prompt
9409 :buffer buffer
9410 :input init
9411 :resume 'noresume
9412 :default (or default ""))
9413 (keyboard-quit)))
9416 ;;; Generic completing read
9419 (defun anything-completing-read-default-1
9420 (prompt collection test require-match
9421 init hist default inherit-input-method
9422 name buffer)
9423 (anything-comp-read
9424 prompt collection
9425 :test test
9426 :fc-transformer #'(lambda (candidates source)
9427 ;; In regular `completing-read'
9428 ;; when a candidate is a cons cell
9429 ;; the car is used. Anything use
9430 ;; normally the cdr, so modify that
9431 ;; to fit `completing-read'.
9432 (loop for i in candidates
9433 for cand = (if (consp i) (car i) i)
9434 do (set-text-properties 0 (length cand) nil cand)
9435 collect cand))
9436 :history (eval (or (car-safe hist) hist))
9437 :must-match require-match
9438 :alistp nil
9439 :name name
9440 :buffer buffer
9441 ;; If DEF is not provided, fallback to empty string
9442 ;; to avoid `thing-at-point' to be appended on top of list
9443 :default (or default "")
9444 :initial-input init))
9446 (defun* anything-completing-read-default
9447 (prompt collection &optional
9448 predicate require-match
9449 initial-input hist def
9450 inherit-input-method)
9451 "An anything replacement of `completing-read'.
9452 This function should be used only as a `completing-read-function'.
9454 Don't use it directly, use instead `anything-comp-read' in your programs \
9455 which is more powerful.
9457 See documentation of `completing-read' and `all-completions' for details."
9458 (declare (special anything-completion-mode))
9459 (let* ((current-command this-command)
9460 (str-command (symbol-name current-command))
9461 (buf-name (format "*ac-mode-%s*" str-command))
9462 (entry (assq current-command
9463 anything-completing-read-handlers-alist))
9464 (def-com (cdr-safe entry))
9465 (str-defcom (and def-com (symbol-name def-com)))
9466 (def-args (list prompt collection predicate require-match
9467 initial-input hist def inherit-input-method))
9468 ;; Append the two extra args needed to set the buffer and source name
9469 ;; in anything specialized functions.
9470 (any-args (append def-args (list str-command buf-name)))
9471 anything-completion-mode-start-message ; Be quiet
9472 anything-completion-mode-quit-message)
9473 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9474 (unless (or (not entry) def-com)
9475 ;; An entry in *read-handlers-alist exists but have
9476 ;; a nil value, so we exit from here, disable `ac-mode'
9477 ;; and run the command again with it original behavior.
9478 ;; `ac-mode' will be restored on exit.
9479 (return-from anything-completing-read-default
9480 (unwind-protect
9481 (progn
9482 (ac-mode -1)
9483 (call-interactively current-command))
9484 (ac-mode 1))))
9485 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9486 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9487 (when (or (eq def-com 'completing-read)
9488 ;; All specialized functions are prefixed by "anything"
9489 (and (stringp str-defcom)
9490 (not (string-match "^anything" str-defcom))))
9491 (ac-mode -1))
9492 (unwind-protect
9493 (cond (;; An anything specialized function exists, run it.
9494 (and def-com anything-completion-mode)
9495 (apply def-com any-args))
9496 (;; Try to handle `ido-completing-read' everywhere.
9497 (and def-com (eq def-com 'ido-completing-read))
9498 (setcar (memq collection def-args)
9499 (all-completions "" collection predicate))
9500 (apply def-com def-args))
9501 (;; User set explicitely `completing-read' or something similar
9502 ;; in *read-handlers-alist, use this with exactly the same
9503 ;; args as in `completing-read'.
9504 ;; If we are here `anything-completion-mode' is now disabled.
9505 def-com
9506 (apply def-com def-args))
9507 (t ; Fall back to classic `anything-comp-read'.
9508 (anything-completing-read-default-1
9509 prompt collection predicate require-match
9510 initial-input hist def inherit-input-method str-command buf-name)))
9511 (ac-mode 1))))
9513 (defun* anything-generic-read-file-name
9514 (prompt &optional dir default-filename mustmatch initial predicate)
9515 "An anything replacement of `read-file-name'."
9516 (declare (special anything-completion-mode))
9517 (let* ((default (and default-filename
9518 (if (listp default-filename)
9519 (car default-filename)
9520 default-filename)))
9521 (init (or default initial dir default-directory))
9522 (ini-input (and init (expand-file-name init)))
9523 (current-command this-command)
9524 (str-command (symbol-name current-command))
9525 (buf-name (format "*ac-mode-%s*" str-command))
9526 (entry (assq current-command
9527 anything-completing-read-handlers-alist))
9528 (def-com (cdr-safe entry))
9529 (str-defcom (symbol-name def-com))
9530 (def-args (list prompt dir default-filename mustmatch initial predicate))
9531 ;; Append the two extra args needed to set the buffer and source name
9532 ;; in anything specialized functions.
9533 (any-args (append def-args (list str-command buf-name)))
9534 (ido-state ido-mode)
9535 anything-completion-mode-start-message ; Be quiet
9536 anything-completion-mode-quit-message ; Same here
9537 fname)
9538 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9539 (unless (or (not entry) def-com)
9540 (return-from anything-completing-read-default
9541 (unwind-protect
9542 (progn
9543 (ac-mode -1)
9544 (call-interactively current-command))
9545 (ac-mode 1))))
9546 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9547 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9548 (when (or (eq def-com 'read-file-name)
9549 (eq def-com 'ido-read-file-name)
9550 (and (stringp str-defcom)
9551 (not (string-match "^anything" str-defcom))))
9552 (ac-mode -1))
9553 (unwind-protect
9554 (setq fname
9555 (cond (;; A specialized function exists, run it
9556 ;; with the two extra args specific to anything..
9557 (and def-com anything-completion-mode
9558 (not (eq def-com 'ido-read-file-name)))
9559 (apply def-com any-args))
9560 (;; Def-com value is `ido-read-file-name'
9561 ;; run it with default args.
9562 (and def-com (eq def-com 'ido-read-file-name))
9563 (ido-mode 1)
9564 (apply def-com def-args))
9565 (;; Def-com value is `read-file-name'
9566 ;; run it with default args.
9567 def-com
9568 (apply def-com def-args))
9569 (t ; Fall back to classic `anything-c-read-file-name'.
9570 (anything-c-read-file-name
9571 prompt
9572 :name str-command
9573 :buffer buf-name
9574 :initial-input (expand-file-name init dir)
9575 :alistp nil
9576 :test predicate))))
9577 (ac-mode 1)
9578 (ido-mode (if ido-state 1 -1)))
9579 (if (and mustmatch (not (file-exists-p fname)))
9580 (if (y-or-n-p "File does not exists, create buffer?")
9581 fname (error "Abort file does not exists"))
9582 fname)))
9584 ;;;###autoload
9585 (define-minor-mode anything-completion-mode
9586 "Toggle generic anything completion.
9588 All functions in Emacs that use `completing-read'
9589 or `read-file-name' and friends will use anything interface
9590 when this mode is turned on.
9591 However you can modify this behavior for functions of your choice
9592 with `anything-completing-read-handlers-alist'.
9594 Called with a positive arg, turn on inconditionnaly, with a
9595 negative arg turn off.
9596 You can turn it on with `ac-mode'.
9598 Some crap emacs functions may not be supported,
9599 e.g `ffap-alternate-file' and maybe others
9600 You can add such functions to `anything-completing-read-handlers-alist'
9601 with a nil value.
9603 Note: This mode will work only partially on Emacs23."
9604 :group 'anything
9605 :global t
9606 :lighter anything-completion-mode-string
9607 (declare (special completing-read-function))
9608 (if anything-completion-mode
9609 (progn
9610 (setq completing-read-function 'anything-completing-read-default
9611 read-file-name-function 'anything-generic-read-file-name)
9612 (message anything-completion-mode-start-message))
9613 (setq completing-read-function (and (fboundp 'completing-read-default)
9614 'completing-read-default)
9615 read-file-name-function (and (fboundp 'read-file-name-default)
9616 'read-file-name-default))
9617 (message anything-completion-mode-quit-message)))
9619 (defalias 'ac-mode 'anything-completion-mode)
9623 ;;; Eshell completion.
9625 ;; Enable like this in .emacs:
9627 ;; (add-hook 'eshell-mode-hook
9628 ;; #'(lambda ()
9629 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9631 (defvar anything-c-source-esh
9632 '((name . "Eshell completions")
9633 (init . (lambda ()
9634 (setq pcomplete-current-completions nil
9635 pcomplete-last-completion-raw nil)
9636 ;; Eshell-command add this hook in all minibuffers
9637 ;; Remove it for the anything one.
9638 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9639 (candidates . anything-esh-get-candidates)
9640 (action . anything-ec-insert))
9641 "Anything source for Eshell completion.")
9643 ;; Internal.
9644 (defvar anything-ec-target "")
9645 (defun anything-ec-insert (candidate)
9646 "Insert CANDIDATE at point.
9647 This is the same as `ac-insert', just inlined here for compatibility."
9648 (let ((pt (point)))
9649 (when (and anything-ec-target
9650 (search-backward anything-ec-target nil t)
9651 (string= (buffer-substring (point) pt) anything-ec-target))
9652 (delete-region (point) pt)))
9653 (insert candidate))
9655 (defun anything-esh-get-candidates ()
9656 "Get candidates for eshell completion using `pcomplete'."
9657 (catch 'pcompleted
9658 (let* ((pcomplete-stub)
9659 pcomplete-seen pcomplete-norm-func
9660 pcomplete-args pcomplete-last pcomplete-index
9661 (pcomplete-autolist pcomplete-autolist)
9662 (pcomplete-suffix-list pcomplete-suffix-list))
9663 (with-anything-current-buffer
9664 (loop
9665 with table = (pcomplete-completions)
9666 with entry = (condition-case nil
9667 ;; For Emacs24
9668 (try-completion anything-pattern (pcomplete-entries))
9669 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9670 (error
9672 (let ((fc (car (last (pcomplete-parse-arguments)))))
9673 ;; Check if last arg require fname completion.
9674 (and (file-name-directory fc) fc))))
9675 for i in (if (listp table) table ; Emacs23 or commands.
9676 (all-completions pcomplete-stub table)) ; Emacs24
9677 for file-cand = (and entry
9678 (if (file-remote-p i) i
9679 (expand-file-name i (file-name-directory entry))))
9680 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9681 collect file-cand into ls
9682 else collect i into ls
9683 finally return
9684 (if (and entry (not (string= entry "")) (file-exists-p entry))
9685 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9687 ;;; Eshell history.
9690 (defvar anything-c-source-eshell-history
9691 '((name . "Eshell history")
9692 (init . (lambda ()
9693 (let (eshell-hist-ignoredups)
9694 ;; Dump the content's of hist file
9695 ;; to `eshell-history-ring'.
9696 (eshell-read-history eshell-history-file-name)
9697 ;; And now write the content's of ring to file.
9698 (eshell-write-history eshell-history-file-name t)
9699 (with-current-buffer (anything-candidate-buffer 'global)
9700 (insert-file-contents eshell-history-file-name)))
9701 ;; Same comment as in `anything-c-source-esh'
9702 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9703 (candidates-in-buffer)
9704 (filtered-candidate-transformer . (lambda (candidates sources)
9705 (reverse candidates)))
9706 (candidate-number-limit . 9999)
9707 (action . (lambda (candidate)
9708 (eshell-kill-input)
9709 (insert candidate))))
9710 "Anything source for Eshell history.")
9713 ;;; Show completion - an alternative of anything-show-completion.el.
9715 ;; Provide show completion with macro `with-anything-show-completion'.
9718 ;; Called each time cursor move in anything-buffer.
9719 (defun anything-c-show-completion ()
9720 (with-anything-current-buffer
9721 (overlay-put anything-c-show-completion-overlay
9722 'display (anything-get-selection))))
9724 (defun anything-c-show-completion-init-overlay (beg end)
9725 (and anything-c-turn-on-show-completion
9726 (setq anything-c-show-completion-overlay (make-overlay beg end))
9727 (overlay-put anything-c-show-completion-overlay
9728 'face 'anything-lisp-show-completion)))
9730 (defmacro with-anything-show-completion (beg end &rest body)
9731 "Show anything candidate in an overlay at point.
9732 BEG and END are the beginning and end position of the current completion
9733 in `anything-current-buffer'.
9734 BODY is an anything call where we want to enable show completion.
9735 If `anything-c-turn-on-show-completion' is nil just do nothing."
9736 (declare (indent 2) (debug t))
9737 `(let ((anything-move-selection-after-hook
9738 (and anything-c-turn-on-show-completion
9739 (append (list 'anything-c-show-completion)
9740 anything-move-selection-after-hook))))
9741 (unwind-protect
9742 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9743 ,@body)
9744 (and anything-c-turn-on-show-completion
9745 (delete-overlay anything-c-show-completion-overlay)))))
9748 ;;; Lisp symbol completion.
9751 ;;;###autoload
9752 (defun anything-lisp-completion-at-point ()
9753 "Anything lisp symbol completion at point."
9754 (interactive)
9755 (let* ((data (lisp-completion-at-point))
9756 (beg (car data))
9757 (end (point)) ; 'cadr data' is wrong when no space after point.
9758 (plist (nthcdr 3 data))
9759 (pred (plist-get plist :predicate))
9760 (lgst-len 0)
9761 (target (and beg end (buffer-substring-no-properties beg end)))
9762 (candidates (all-completions target (nth 2 data) pred))
9763 (anything-quit-if-no-candidate t)
9764 (anything-execute-action-at-once-if-one t)
9765 (anything-match-plugin-enabled
9766 (member 'anything-compile-source--match-plugin
9767 anything-compile-source-functions)))
9768 (if candidates
9769 (with-anything-show-completion beg end
9770 ;; Overlay is initialized now in anything-current-buffer.
9771 (anything
9772 :sources
9773 '((name . "Lisp completion")
9774 (init . (lambda ()
9775 (with-current-buffer (anything-candidate-buffer 'global)
9776 (loop for sym in candidates
9777 for len = (length sym)
9778 when (> len lgst-len) do (setq lgst-len len)
9779 do (insert (concat sym "\n"))))))
9780 (candidates-in-buffer)
9781 (persistent-action . anything-lisp-completion-persistent-action)
9782 (persistent-help . "Show brief doc in mode-line")
9783 (filtered-candidate-transformer anything-lisp-completion-transformer)
9784 (action . (lambda (candidate)
9785 (delete-region beg end)
9786 (insert candidate))))
9787 :input (if anything-match-plugin-enabled (concat target " ") target)))
9788 (message "[No Match]"))))
9790 (defun anything-lisp-completion-persistent-action (candidate)
9791 (let ((cursor-in-echo-area t)
9792 mode-line-in-non-selected-windows)
9793 (anything-c-eldoc-show-in-mode-line
9794 (propertize
9795 (anything-c-get-first-line-documentation
9796 (intern candidate))
9797 'face 'anything-lisp-completion-info))))
9799 (defun anything-lisp-completion-transformer (candidates source)
9800 "Anything candidates transformer for lisp completion."
9801 (declare (special lgst-len))
9802 (loop for c in candidates
9803 for sym = (intern c)
9804 for annot = (cond ((commandp sym) " (Com)")
9805 ((fboundp sym) " (Fun)")
9806 ((boundp sym) " (Var)")
9807 ((facep sym) " (Face)"))
9808 for spaces = (make-string (- lgst-len (length c)) ? )
9809 collect (cons (concat c spaces annot) c)))
9811 (defun anything-c-get-first-line-documentation (sym)
9812 "Return first line documentation of symbol SYM.
9813 If SYM is not documented, return \"Not documented\"."
9814 (let ((doc (cond ((fboundp sym)
9815 (documentation sym t))
9816 ((boundp sym)
9817 (documentation-property sym 'variable-documentation t))
9818 ((facep sym)
9819 (face-documentation sym))
9820 (t nil))))
9821 (if (and doc (not (string= doc ""))
9822 ;; `documentation' return "\n\n(args...)"
9823 ;; for CL-style functions.
9824 (not (string-match-p "^\n\n" doc)))
9825 (car (split-string doc "\n"))
9826 "Not documented")))
9828 ;;; File completion.
9830 ;; Complete file name at point.
9831 (defun anything-c-thing-before-point ()
9832 "Get symbol name before point.
9833 Borrowed from anything-complete.el, inlined here for compatibility."
9834 (save-excursion
9835 (let ((beg (point)))
9836 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9837 (when (re-search-backward
9838 "\\_<" (field-beginning nil nil (point-at-bol)) t)
9839 (buffer-substring-no-properties beg (match-end 0))))))
9841 ;;;###autoload
9842 (defun anything-c-complete-file-name-at-point ()
9843 "Complete file name at point."
9844 (interactive)
9845 (let* ((init (substring-no-properties (thing-at-point 'filename)))
9846 (end (point))
9847 (beg (- (point) (length init)))
9848 (anything-quit-if-no-candidate t)
9849 (anything-execute-action-at-once-if-one t)
9850 completion)
9851 (with-anything-show-completion beg end
9852 (setq completion (anything-c-read-file-name "FileName: "
9853 :initial-input init)))
9854 (anything-c-insert-file-name-completion-at-point completion)))
9856 ;; Internal
9857 (defvar anything-lisp-completion-counter 0)
9858 ;;;###autoload
9859 (defun anything-lisp-completion-at-point-or-indent (arg)
9860 "First call indent and second call complete lisp symbol.
9861 The second call should happen before `anything-lisp-completion-or-indent-delay',
9862 after this delay, next call will indent again.
9863 After completion, next call is always indent.
9864 See that like click and double mouse click.
9865 One hit indent, two quick hits maybe indent and complete."
9866 (interactive "P")
9867 ;; Be sure `indent-for-tab-command' will not try
9868 ;; to use `completion-at-point'.
9869 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
9870 t tab-always-indent)))
9871 (incf anything-lisp-completion-counter)
9872 (unwind-protect
9873 (if (> anything-lisp-completion-counter 1)
9874 (anything-lisp-completion-or-file-name-at-point)
9875 (indent-for-tab-command arg))
9876 ;; After `anything-lisp-completion-or-indent-delay' seconds
9877 ;; reset to 0.
9878 (run-with-timer anything-lisp-completion-or-indent-delay nil
9879 #'(lambda ()
9880 (setq anything-lisp-completion-counter 0)))
9881 ;; Always reset to 0 at second hit.
9882 (when (eq anything-lisp-completion-counter 2)
9883 (setq anything-lisp-completion-counter 0)))))
9885 ;;;###autoload
9886 (defun anything-lisp-completion-or-file-name-at-point ()
9887 "Complete lisp symbol or filename at point.
9888 Filename completion happen if filename is started in
9889 or between double quotes."
9890 (interactive)
9891 (let ((tap (substring-no-properties (thing-at-point 'filename))))
9892 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
9893 (save-excursion (search-backward "\"" (point-at-bol) t)))
9894 (anything-c-complete-file-name-at-point)
9895 (anything-lisp-completion-at-point))))
9899 ;;; Run Externals commands within Emacs with anything completion
9902 (defvar anything-external-command-history nil)
9904 (defun anything-c-external-commands-list-1 (&optional sort)
9905 "Returns a list of all external commands the user can execute.
9906 If `anything-c-external-commands-list' is non-nil it will
9907 return its contents. Else it calculates all external commands
9908 and sets `anything-c-external-commands-list'."
9909 (if anything-c-external-commands-list
9910 anything-c-external-commands-list
9911 (setq anything-c-external-commands-list
9912 (loop
9913 with paths = (split-string (getenv "PATH") path-separator)
9914 with completions = ()
9915 for dir in paths
9916 when (and (file-exists-p dir) (file-accessible-directory-p dir))
9917 for lsdir = (loop for i in (directory-files dir t)
9918 for bn = (file-name-nondirectory i)
9919 when (and (not (member bn completions))
9920 (not (file-directory-p i))
9921 (file-executable-p i))
9922 collect bn)
9923 append lsdir into completions
9924 finally return (if sort (sort completions 'string-lessp) completions)))))
9926 (defun anything-run-or-raise (exe &optional file)
9927 "Generic command that run asynchronously EXE.
9928 If EXE is already running just jump to his window if `anything-raise-command'
9929 is non--nil.
9930 When FILE argument is provided run EXE with FILE.
9931 In this case EXE must be provided as \"EXE %s\"."
9932 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
9933 "'%s'" "" exe))))
9934 (proc (if file (concat real-com " " file) real-com)))
9935 (if (get-process proc)
9936 (if anything-raise-command
9937 (shell-command (format anything-raise-command real-com))
9938 (error "Error: %s is already running" real-com))
9939 (when (loop for i in anything-c-external-commands-list thereis real-com)
9940 (message "Starting %s..." real-com)
9941 (if file
9942 (start-process-shell-command proc nil (format exe file))
9943 (start-process-shell-command proc nil real-com))
9944 (set-process-sentinel
9945 (get-process proc)
9946 #'(lambda (process event)
9947 (when (and (string= event "finished\n")
9948 anything-raise-command
9949 (not (anything-c-get-pid-from-process-name real-com)))
9950 (shell-command (format anything-raise-command "emacs")))
9951 (message "%s process...Finished." process))))
9952 (setq anything-c-external-commands-list
9953 (cons real-com
9954 (delete real-com anything-c-external-commands-list))))))
9958 ;;; Generic action functions
9961 (defun anything-c-file-buffers (filename)
9962 "Returns a list of buffer names corresponding to FILENAME."
9963 (let ((name (expand-file-name filename))
9964 (buf-list ()))
9965 (dolist (buf (buffer-list) buf-list)
9966 (let ((bfn (buffer-file-name buf)))
9967 (when (and bfn (string= name bfn))
9968 (push (buffer-name buf) buf-list))))))
9970 (defun anything-revert-buffer (candidate)
9971 (with-current-buffer candidate
9972 (when (or (buffer-modified-p)
9973 (not (verify-visited-file-modtime
9974 (get-buffer candidate))))
9975 (revert-buffer t t))))
9977 (defun anything-revert-marked-buffers (ignore)
9978 (mapc 'anything-revert-buffer (anything-marked-candidates)))
9980 (defun anything-kill-marked-buffers (ignore)
9981 (mapc 'kill-buffer (anything-marked-candidates)))
9983 (defun anything-c-delete-file (file)
9984 "Delete the given file after querying the user.
9985 Ask to kill buffers associated with that file, too."
9986 (let ((buffers (anything-c-file-buffers file)))
9987 (if (< emacs-major-version 24)
9988 ;; `dired-delete-file' in Emacs versions < 24
9989 ;; doesn't support delete-by-moving-to-trash
9990 ;; so use `delete-directory' and `delete-file'
9991 ;; that handle it.
9992 (cond ((and (not (file-symlink-p file))
9993 (file-directory-p file)
9994 (directory-files file t dired-re-no-dot))
9995 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
9996 (delete-directory file 'recursive)))
9997 ((and (not (file-symlink-p file))
9998 (file-directory-p file))
9999 (delete-directory file))
10000 (t (delete-file file)))
10001 (dired-delete-file
10002 file 'dired-recursive-deletes delete-by-moving-to-trash))
10003 (when buffers
10004 (dolist (buf buffers)
10005 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10006 (kill-buffer buf))))))
10008 (defun anything-get-mailcap-for-file (filename)
10009 "Get the command to use for FILENAME from mailcap files.
10010 The command is like <command %s> and is meant to use with `format'."
10011 (mailcap-parse-mailcaps)
10012 (let* ((ext (file-name-extension filename))
10013 (mime (when ext (mailcap-extension-to-mime ext)))
10014 (result (when mime (mailcap-mime-info mime))))
10015 ;; If elisp file have no associations in .mailcap
10016 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10017 (when (stringp result) result)))
10019 (defun anything-get-default-program-for-file (filename)
10020 "Try to find a default program to open FILENAME.
10021 Try first in `anything-c-external-programs-associations' and then in mailcap file
10022 if nothing found return nil."
10023 (let* ((ext (file-name-extension filename))
10024 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10025 (cond ((and def-prog (not (string= def-prog "")))
10026 (concat def-prog " %s"))
10027 ((and anything-c-default-external-file-browser
10028 (file-directory-p filename))
10029 (concat anything-c-default-external-file-browser " %s"))
10030 (t (anything-get-mailcap-for-file filename)))))
10032 (defun anything-c-open-file-externally (file)
10033 "Open FILE with an external program.
10034 Try to guess which program to use with `anything-get-default-program-for-file'.
10035 If not found or a prefix arg is given query the user which tool to use."
10036 (let* ((fname (expand-file-name file))
10037 (collection (anything-c-external-commands-list-1 'sort))
10038 (def-prog (anything-get-default-program-for-file fname))
10039 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10040 ;; Prefix arg or no default program.
10041 (prog1
10042 (anything-comp-read
10043 "Program: " collection
10044 :must-match t
10045 :name "Open file Externally"
10046 :history anything-external-command-history)
10047 ;; Always prompt to set this program as default.
10048 (setq def-prog nil))
10049 ;; No prefix arg or default program exists.
10050 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10051 (program (concat real-prog-name " '%s'")))
10052 (unless (or def-prog ; Association exists, no need to record it.
10053 ;; Don't try to record non--filenames associations (e.g urls).
10054 (not (file-exists-p fname)))
10055 (when
10056 (y-or-n-p
10057 (format
10058 "Do you want to make `%s' the default program for this kind of files? "
10059 real-prog-name))
10060 (anything-aif (assoc (file-name-extension fname)
10061 anything-c-external-programs-associations)
10062 (setq anything-c-external-programs-associations
10063 (delete it anything-c-external-programs-associations)))
10064 (push (cons (file-name-extension fname)
10065 (read-string
10066 "Program (Add args maybe and confirm): " real-prog-name))
10067 anything-c-external-programs-associations)
10068 (customize-save-variable 'anything-c-external-programs-associations
10069 anything-c-external-programs-associations)))
10070 (anything-run-or-raise program file)
10071 (setq anything-external-command-history
10072 (cons real-prog-name
10073 (delete real-prog-name
10074 (loop for i in anything-external-command-history
10075 when (executable-find i) collect i))))))
10078 (defun anything-c-find-file-or-marked (candidate)
10079 "Open file CANDIDATE or open anything marked files in background."
10080 (let ((marked (anything-marked-candidates))
10081 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10082 (find-file-wildcards nil))
10083 (if (> (length marked) 1)
10084 ;; Open all marked files in background and display
10085 ;; the first one.
10086 (progn (mapc 'find-file-noselect (cdr marked))
10087 (find-file (car marked)))
10088 (if (and (not (file-exists-p candidate))
10089 (and ffap-url-regexp
10090 (not (string-match ffap-url-regexp candidate)))
10091 (string-match "/$" candidate))
10092 ;; A a non--existing filename ending with /
10093 ;; Create a directory and jump to it.
10094 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10095 (let ((dirfname (directory-file-name candidate)))
10096 (if (file-exists-p dirfname)
10097 (error "Mkdir: Unable to create directory `%s': file exists."
10098 (anything-c-basename dirfname))
10099 (make-directory candidate 'parent)))
10100 (anything-find-files-1 candidate))
10101 ;; A non--existing filename NOT ending with / or
10102 ;; an existing filename, create or jump to it.
10103 (find-file-at-point (car marked))))))
10105 (defun anything-delete-marked-files (ignore)
10106 (let* ((files (anything-marked-candidates))
10107 (len (length files)))
10108 (if (not (y-or-n-p
10109 (format "Delete *%s File(s):\n%s"
10111 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10112 (message "(No deletions performed)")
10113 (dolist (i files)
10114 (set-text-properties 0 (length i) nil i)
10115 (anything-c-delete-file i))
10116 (message "%s File(s) deleted" len))))
10118 (defun anything-ediff-marked-buffers (candidate &optional merge)
10119 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10120 With optional arg MERGE call `ediff-merge-buffers'."
10121 (let ((lg-lst (length (anything-marked-candidates)))
10122 buf1 buf2)
10123 (case lg-lst
10125 (error "Error:You have to mark at least 1 buffer"))
10127 (setq buf1 anything-current-buffer
10128 buf2 (first (anything-marked-candidates))))
10130 (setq buf1 (first (anything-marked-candidates))
10131 buf2 (second (anything-marked-candidates))))
10133 (error "Error:To much buffers marked!")))
10134 (if merge
10135 (ediff-merge-buffers buf1 buf2)
10136 (ediff-buffers buf1 buf2))))
10138 (defun anything-ediff-marked-buffers-merge (candidate)
10139 "Ediff merge `anything-current-buffer' with CANDIDATE.
10140 See `anything-ediff-marked-buffers'."
10141 (anything-ediff-marked-buffers candidate t))
10143 (defun anything-bookmark-get-bookmark-from-name (bmk)
10144 "Return bookmark name even if it is a bookmark with annotation.
10145 e.g prepended with *.
10146 Return nil if bmk is not a valid bookmark."
10147 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10148 (if (assoc bookmark bookmark-alist)
10149 bookmark
10150 (when (assoc bmk bookmark-alist)
10151 bmk))))
10153 (defun anything-delete-marked-bookmarks (ignore)
10154 "Delete this bookmark or all marked bookmarks."
10155 (dolist (i (anything-marked-candidates))
10156 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10157 'batch)))
10159 (defun anything-require-or-error (feature function)
10160 (or (require feature nil t)
10161 (error "Need %s to use `%s'." feature function)))
10163 (defun anything-find-buffer-on-elscreen (candidate)
10164 "Open buffer in new screen, if marked buffers open all in elscreens."
10165 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10166 (anything-aif (anything-marked-candidates)
10167 (dolist (i it)
10168 (let ((target-screen (elscreen-find-screen-by-buffer
10169 (get-buffer i) 'create)))
10170 (elscreen-goto target-screen)))
10171 (let ((target-screen (elscreen-find-screen-by-buffer
10172 (get-buffer candidate) 'create)))
10173 (elscreen-goto target-screen))))
10175 (defun anything-elscreen-find-file (file)
10176 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10177 (elscreen-find-file file))
10179 ;;;###autoload
10180 (defun w32-shell-execute-open-file (file)
10181 (interactive "fOpen file:")
10182 (with-no-warnings
10183 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10184 "/" "\\"
10185 (replace-regexp-in-string ; strip cygdrive paths
10186 "/cygdrive/\\(.\\)" "\\1:"
10187 file nil nil) nil t))))
10189 (defun anything-c-open-file-with-default-tool (file)
10190 "Open FILE with the default tool on this platform."
10191 (if (eq system-type 'windows-nt)
10192 (w32-shell-execute-open-file file)
10193 (start-process "anything-c-open-file-with-default-tool"
10195 (cond ((eq system-type 'gnu/linux)
10196 "xdg-open")
10197 ((or (eq system-type 'darwin) ;; Mac OS X
10198 (eq system-type 'macos)) ;; Mac OS 9
10199 "open"))
10200 file)))
10202 (defun anything-c-open-dired (file)
10203 "Opens a dired buffer in FILE's directory. If FILE is a
10204 directory, open this directory."
10205 (if (file-directory-p file)
10206 (dired file)
10207 (dired (file-name-directory file))
10208 (dired-goto-file file)))
10210 (defun anything-c-display-to-real-line (candidate)
10211 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10212 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10213 (error "Line number not found")))
10215 (defun anything-c-action-line-goto (lineno-and-content)
10216 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10217 (append lineno-and-content
10218 (list (if (and (anything-attr-defined 'target-file)
10219 (not anything-in-persistent-action))
10220 'find-file-other-window
10221 'find-file)))))
10223 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10224 (apply #'anything-goto-file-line
10225 (if (stringp file-line-content)
10226 ;; Case: filtered-candidate-transformer is skipped
10227 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10228 file-line-content)))
10230 (require 'compile)
10231 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10232 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10234 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10235 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10236 (let ((filename (match-string 1 candidate))
10237 (lineno (match-string 2 candidate))
10238 (content (match-string 3 candidate)))
10239 (cons (format "%s:%s\n %s"
10240 (propertize filename 'face compilation-info-face)
10241 (propertize lineno 'face compilation-line-face)
10242 content)
10243 (list (expand-file-name
10244 filename
10245 (or (anything-interpret-value (anything-attr 'default-directory))
10246 (and (anything-candidate-buffer)
10247 (buffer-local-value
10248 'default-directory (anything-candidate-buffer)))))
10249 (string-to-number lineno) content)))))
10251 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10252 (anything-aif (anything-attr 'before-jump-hook)
10253 (funcall it))
10254 (when file (funcall find-file-function file))
10255 (if (anything-attr-defined 'adjust)
10256 (anything-c-goto-line-with-adjustment lineno content)
10257 (anything-goto-line lineno))
10258 (unless (anything-attr-defined 'recenter)
10259 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10260 (anything-aif (anything-attr 'after-jump-hook)
10261 (funcall it))
10262 (when anything-in-persistent-action
10263 (anything-match-line-color-current-line)))
10265 (defun anything-find-file-as-root (candidate)
10266 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10268 (defun anything-find-many-files (ignore)
10269 (mapc 'find-file (anything-marked-candidates)))
10271 ;; borrowed from etags.el
10272 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10273 (defun anything-c-goto-line-with-adjustment (line line-content)
10274 (let ((startpos)
10275 offset found pat)
10276 ;; This constant is 1/2 the initial search window.
10277 ;; There is no sense in making it too small,
10278 ;; since just going around the loop once probably
10279 ;; costs about as much as searching 2000 chars.
10280 (setq offset 1000
10281 found nil
10282 pat (concat (if (eq selective-display t)
10283 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10284 (regexp-quote line-content)))
10285 ;; If no char pos was given, try the given line number.
10286 (setq startpos (progn (anything-goto-line line) (point)))
10287 (or startpos (setq startpos (point-min)))
10288 ;; First see if the tag is right at the specified location.
10289 (goto-char startpos)
10290 (setq found (looking-at pat))
10291 (while (and (not found)
10292 (progn
10293 (goto-char (- startpos offset))
10294 (not (bobp))))
10295 (setq found
10296 (re-search-forward pat (+ startpos offset) t)
10297 offset (* 3 offset))) ; expand search window
10298 (or found
10299 (re-search-forward pat nil t)
10300 (error "not found")))
10301 ;; Position point at the right place
10302 ;; if the search string matched an extra Ctrl-m at the beginning.
10303 (and (eq selective-display t)
10304 (looking-at "\^m")
10305 (forward-char 1))
10306 (beginning-of-line))
10308 (anything-document-attribute 'default-directory "type . file-line"
10309 "`default-directory' to interpret file.")
10310 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10311 "Function to call before jumping to the target location.")
10312 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10313 "Function to call after jumping to the target location.")
10314 (anything-document-attribute 'adjust "type . file-line"
10315 "Search around line matching line contents.")
10316 (anything-document-attribute 'recenter "type . file-line / line"
10317 "`recenter' after jumping.")
10318 (anything-document-attribute 'target-file "type . line"
10319 "Goto line of target-file.")
10321 ;;;###autoload
10322 (defun anything-c-call-interactively (cmd-or-name)
10323 "Execute CMD-OR-NAME as Emacs command.
10324 It is added to `extended-command-history'.
10325 `anything-current-prefix-arg' is used as the command's prefix argument."
10326 (setq extended-command-history
10327 (cons (anything-c-stringify cmd-or-name)
10328 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10329 (let ((current-prefix-arg anything-current-prefix-arg)
10330 (cmd (anything-c-symbolify cmd-or-name)))
10331 (if (stringp (symbol-function cmd))
10332 (execute-kbd-macro (symbol-function cmd))
10333 (setq this-command cmd)
10334 (call-interactively cmd))))
10336 ;;;###autoload
10337 (defun anything-c-set-variable (var)
10338 "Set value to VAR interactively."
10339 (interactive)
10340 (let ((sym (anything-c-symbolify var)))
10341 (set sym (eval-minibuffer (format "Set %s: " var)
10342 (prin1-to-string (symbol-value sym))))))
10343 ;; (setq hh 12)
10344 ;; (anything-c-set-variable 'hh)
10348 ;;; Persistent Action Helpers
10351 (defvar anything-match-line-overlay-face nil)
10352 (defvar anything-match-line-overlay nil)
10354 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10355 "Highlight and underline current position"
10356 (let ((args (list (or start (line-beginning-position))
10357 (or end (1+ (line-end-position)))
10358 buf)))
10359 (if (not anything-match-line-overlay)
10360 (setq anything-match-line-overlay (apply 'make-overlay args))
10361 (apply 'move-overlay anything-match-line-overlay args)))
10362 (overlay-put anything-match-line-overlay
10363 'face (or face anything-match-line-overlay-face))
10364 (when rec
10365 (goto-char start)
10366 (recenter)))
10368 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10371 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10373 (defun anything-match-line-cleanup ()
10374 (when anything-match-line-overlay
10375 (delete-overlay anything-match-line-overlay)
10376 (setq anything-match-line-overlay nil)))
10378 (defun anything-match-line-update ()
10379 (when anything-match-line-overlay
10380 (delete-overlay anything-match-line-overlay)
10381 (anything-match-line-color-current-line)))
10383 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10384 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10387 ;;; Actions Transformers
10390 ;;; Files
10391 (defun anything-c-transform-file-load-el (actions candidate)
10392 "Add action to load the file CANDIDATE if it is an emacs lisp
10393 file. Else return ACTIONS unmodified."
10394 (if (member (file-name-extension candidate) '("el" "elc"))
10395 (append actions '(("Load Emacs Lisp File" . load-file)))
10396 actions))
10398 (defun anything-c-transform-file-browse-url (actions candidate)
10399 "Add an action to browse the file CANDIDATE if it in a html
10400 file or URL. Else return ACTIONS unmodified."
10401 (let ((browse-action '("Browse with Browser" . browse-url)))
10402 (cond ((string-match "^http\\|^ftp" candidate)
10403 (cons browse-action actions))
10404 ((string-match "\\.html?$" candidate)
10405 (append actions (list browse-action)))
10406 (t actions))))
10408 ;;; Function
10409 (defun anything-c-transform-function-call-interactively (actions candidate)
10410 "Add an action to call the function CANDIDATE interactively if
10411 it is a command. Else return ACTIONS unmodified."
10412 (if (commandp (intern-soft candidate))
10413 (append actions '(("Call Interactively"
10415 anything-c-call-interactively)))
10416 actions))
10418 ;;;; S-Expressions
10419 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10420 "If CANDIDATE's `car' is a command, then add an action to
10421 evaluate it and put it onto the `command-history'."
10422 (if (commandp (car (read candidate)))
10423 ;; Make it first entry
10424 (cons '("Eval and put onto command-history" .
10425 (lambda (sexp)
10426 (let ((sym (read sexp)))
10427 (eval sym)
10428 (setq command-history
10429 (cons sym command-history)))))
10430 actions)
10431 actions))
10434 ;;; Candidate Transformers
10437 ;;; Buffers
10438 (defun anything-c-skip-boring-buffers (buffers)
10439 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10441 (defun anything-c-skip-current-buffer (buffers)
10442 (if anything-allow-skipping-current-buffer
10443 (remove (buffer-name anything-current-buffer) buffers)
10444 buffers))
10446 (defun anything-c-shadow-boring-buffers (buffers)
10447 "Buffers matching `anything-c-boring-buffer-regexp' will be
10448 displayed with the `file-name-shadow' face if available."
10449 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10451 (defvar anything-c-buffer-display-string-functions
10452 '(anything-c-buffer-display-string--compilation
10453 anything-c-buffer-display-string--shell
10454 anything-c-buffer-display-string--eshell)
10455 "Functions to setup display string for buffer.
10457 Function has one argument, buffer name.
10458 If it returns string, use it.
10459 If it returns nil, display buffer name.
10460 See `anything-c-buffer-display-string--compilation' for example.")
10462 (defun anything-c-transform-buffer-display-string (buffers)
10463 "Setup display string for buffer candidates
10464 using `anything-c-buffer-display-string-functions'."
10465 (loop for buf in buffers
10466 if (consp buf)
10467 collect buf
10468 else
10469 for disp = (progn (set-buffer buf)
10470 (run-hook-with-args-until-success
10471 'anything-c-buffer-display-string-functions buf))
10472 collect (if disp (cons disp buf) buf)))
10474 (defun anything-c-buffer-display-string--compilation (buf)
10475 (anything-aif (car compilation-arguments)
10476 (format "%s: %s [%s]" buf it default-directory)))
10478 (defun anything-c-buffer-display-string--eshell (buf)
10479 (declare (special eshell-history-ring))
10480 (when (eq major-mode 'eshell-mode)
10481 (format "%s: %s [%s]" buf
10482 (ignore-errors (ring-ref eshell-history-ring 0))
10483 default-directory)))
10485 (defun anything-c-buffer-display-string--shell (buf)
10486 (when (eq major-mode 'shell-mode)
10487 (format "%s: %s [%s]" buf
10488 (ignore-errors (ring-ref comint-input-ring 0))
10489 default-directory)))
10491 ;;; Files
10492 (defun anything-c-shadow-boring-files (files)
10493 "Files matching `anything-c-boring-file-regexp' will be
10494 displayed with the `file-name-shadow' face if available."
10495 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10497 (defun anything-c-skip-boring-files (files)
10498 "Files matching `anything-c-boring-file-regexp' will be skipped."
10499 (anything-c-skip-entries files anything-c-boring-file-regexp))
10500 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10502 (defun anything-c-skip-current-file (files)
10503 "Current file will be skipped."
10504 (remove (buffer-file-name anything-current-buffer) files))
10506 (defun anything-c-w32-pathname-transformer (args)
10507 "Change undesirable features of windows pathnames to ones more acceptable to
10508 other candidate transformers."
10509 (if (eq system-type 'windows-nt)
10510 (mapcar (lambda (x)
10511 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10512 (mapcar (lambda (y)
10513 (replace-regexp-in-string "\\\\" "/" y)) args))
10514 args))
10516 (defun anything-c-shorten-home-path (files)
10517 "Replaces /home/user with ~."
10518 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10519 (getenv "HOME"))))
10520 (mapcar (lambda (file)
10521 (if (and (stringp file) (string-match home file))
10522 (cons (replace-match "~" nil nil file) file)
10523 file))
10524 files)))
10526 ;;; Functions
10527 (defun anything-c-mark-interactive-functions (functions)
10528 "Mark interactive functions (commands) with (i) after the function name."
10529 (let (list)
10530 (loop for function in functions
10531 do (push (cons (concat function
10532 (when (commandp (intern-soft function)) " (i)"))
10533 function)
10534 list)
10535 finally (return (nreverse list)))))
10538 ;;; Adaptive Sorting of Candidates
10541 ;; Internal
10542 (defvar anything-c-adaptive-done nil
10543 "nil if history information is not yet stored for the current
10544 selection.")
10546 (defvar anything-c-adaptive-history nil
10547 "Contains the stored history information.
10548 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10550 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10551 "Reset `anything-c-adaptive-done' when anything is started."
10552 (when anything-c-use-adaptative-sorting
10553 (setq anything-c-adaptive-done nil)))
10555 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10556 "Store history information when action is executed on selected candidate."
10557 (when anything-c-use-adaptative-sorting
10558 (anything-c-adaptive-store-selection)))
10560 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10561 "Store history information when the user goes to the action buffer."
10562 (when anything-c-use-adaptative-sorting
10563 (anything-c-adaptive-store-selection)))
10565 (defun anything-c-source-use-adaptative-p (&optional source-name)
10566 "Return current source only if it use adaptative history, nil otherwise."
10567 (when anything-c-use-adaptative-sorting
10568 (let* ((source (or source-name (anything-get-current-source)))
10569 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10570 (assoc (assoc-default 'type source)
10571 anything-type-attributes))
10572 (assoc-default 'candidate-transformer
10573 (assoc (assoc-default 'type source)
10574 anything-type-attributes))
10575 (assoc-default 'filtered-candidate-transformer source)
10576 (assoc-default 'candidate-transformer source))))
10577 (if (listp adapt-source)
10578 (when (member 'anything-c-adaptive-sort adapt-source) source)
10579 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10581 (defun anything-c-adaptive-store-selection ()
10582 "Store history information for the selected candidate."
10583 (unless anything-c-adaptive-done
10584 (setq anything-c-adaptive-done t)
10585 (let ((source (anything-c-source-use-adaptative-p)))
10586 (when source
10587 (let* ((source-name (or (assoc-default 'type source)
10588 (assoc-default 'name source)))
10589 (source-info (or (assoc source-name anything-c-adaptive-history)
10590 (progn
10591 (push (list source-name) anything-c-adaptive-history)
10592 (car anything-c-adaptive-history))))
10593 (selection (anything-get-selection))
10594 (selection-info (progn
10595 (setcdr source-info
10596 (cons
10597 (let ((found (assoc selection (cdr source-info))))
10598 (if (not found)
10599 ;; new entry
10600 (list selection)
10602 ;; move entry to the beginning of the
10603 ;; list, so that it doesn't get
10604 ;; trimmed when the history is
10605 ;; truncated
10606 (setcdr source-info
10607 (delete found (cdr source-info)))
10608 found))
10609 (cdr source-info)))
10610 (cadr source-info)))
10611 (pattern-info (progn
10612 (setcdr selection-info
10613 (cons
10614 (let ((found (assoc anything-pattern (cdr selection-info))))
10615 (if (not found)
10616 ;; new entry
10617 (cons anything-pattern 0)
10619 ;; move entry to the beginning of the
10620 ;; list, so if two patterns used the
10621 ;; same number of times then the one
10622 ;; used last appears first in the list
10623 (setcdr selection-info
10624 (delete found (cdr selection-info)))
10625 found))
10626 (cdr selection-info)))
10627 (cadr selection-info))))
10629 ;; increase usage count
10630 (setcdr pattern-info (1+ (cdr pattern-info)))
10632 ;; truncate history if needed
10633 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10634 (setcdr selection-info
10635 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10637 (defun anything-c-adaptative-maybe-load-history ()
10638 (when (and anything-c-use-adaptative-sorting
10639 (file-readable-p anything-c-adaptive-history-file))
10640 (load-file anything-c-adaptive-history-file)))
10642 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10643 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10645 (defun anything-c-adaptive-save-history (&optional arg)
10646 "Save history information to file given by `anything-c-adaptive-history-file'."
10647 (interactive "p")
10648 (when anything-c-use-adaptative-sorting
10649 (with-temp-buffer
10650 (insert
10651 ";; -*- mode: emacs-lisp -*-\n"
10652 ";; History entries used for anything adaptive display.\n")
10653 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10654 (current-buffer))
10655 (insert ?\n)
10656 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10657 (unless arg 'quiet)))))
10659 (defun anything-c-adaptive-sort (candidates source)
10660 "Sort the CANDIDATES for SOURCE by usage frequency.
10661 This is a filtered candidate transformer you can use for the
10662 attribute `filtered-candidate-transformer' of a source in
10663 `anything-sources' or a type in `anything-type-attributes'."
10664 (let* ((source-name (or (assoc-default 'type source)
10665 (assoc-default 'name source)))
10666 (source-info (assoc source-name anything-c-adaptive-history)))
10667 (if source-info
10668 (let ((usage
10669 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10670 ;; pairs
10671 (mapcar (lambda (candidate-info)
10672 (let ((count 0))
10673 (dolist (pattern-info (cdr candidate-info))
10674 (if (not (equal (car pattern-info)
10675 anything-pattern))
10676 (incf count (cdr pattern-info))
10678 ;; if current pattern is equal to the previously
10679 ;; used one then this candidate has priority
10680 ;; (that's why its count is boosted by 10000) and
10681 ;; it only has to compete with other candidates
10682 ;; which were also selected with the same pattern
10683 (setq count (+ 10000 (cdr pattern-info)))
10684 (return)))
10685 (cons (car candidate-info) count)))
10686 (cdr source-info)))
10687 sorted)
10688 (if (and usage (consp usage))
10689 ;; sort the list in descending order, so candidates with highest
10690 ;; priorty come first
10691 (progn
10692 (setq usage (sort usage (lambda (first second)
10693 (> (cdr first) (cdr second)))))
10695 ;; put those candidates first which have the highest usage count
10696 (dolist (info usage)
10697 (when (member* (car info) candidates
10698 :test 'anything-c-adaptive-compare)
10699 (push (car info) sorted)
10700 (setq candidates (remove* (car info) candidates
10701 :test 'anything-c-adaptive-compare))))
10703 ;; and append the rest
10704 (append (reverse sorted) candidates nil))
10705 (message "Your `%s' is maybe corrupted or too old, \
10706 you should reinitialize it with `anything-c-reset-adaptative-history'"
10707 anything-c-adaptive-history-file)
10708 (sit-for 1)
10709 candidates))
10710 ;; if there is no information stored for this source then do nothing
10711 candidates)))
10713 ;;;###autoload
10714 (defun anything-c-reset-adaptative-history ()
10715 "Delete all `anything-c-adaptive-history' and his file.
10716 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10717 (interactive)
10718 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10719 (setq anything-c-adaptive-history nil)
10720 (delete-file anything-c-adaptive-history-file)))
10722 (defun anything-c-adaptive-compare (x y)
10723 "Compare candidates X and Y taking into account that the
10724 candidate can be in (DISPLAY . REAL) format."
10725 (equal (if (listp x)
10726 (cdr x)
10728 (if (listp y)
10729 (cdr y)
10730 y)))
10734 ;;; Outliner
10737 (defvar anything-outline-goto-near-line-flag t)
10738 (defvar anything-outline-using nil)
10739 (defun anything-after-update-hook--outline ()
10740 (if (and (eq anything-outline-using t)
10741 (eq anything-outline-goto-near-line-flag t))
10742 (anything-outline-goto-near-line)))
10743 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10745 (defun anything-outline-goto-near-line ()
10746 (with-anything-window
10747 ;; TODO need consideration whether to update position by every input.
10748 (when t ; (equal anything-pattern "")
10749 (anything-goto-line 2)
10750 (let ((lineno (with-anything-current-buffer
10751 (line-number-at-pos (car anything-current-position)))))
10752 (block exit
10753 (while (<= (progn (skip-chars-forward " ")
10754 (or (number-at-point) lineno))
10755 lineno)
10756 (forward-line 1)
10757 (when (eobp)
10758 (forward-line -1)
10759 (return-from exit))))
10760 (forward-line -1)
10761 (and (bobp) (forward-line 1))
10762 (and (anything-pos-header-line-p) (forward-line -2))
10763 (anything-mark-current-line)))))
10767 ;;; Plug-in
10770 ;; Plug-in: info-index
10771 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
10772 (let (result)
10773 (unless (anything-candidate-buffer)
10774 (save-window-excursion
10775 (info file)
10776 (let (Info-history
10777 (tobuf (anything-candidate-buffer 'global))
10778 (infobuf (current-buffer))
10779 s e)
10780 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
10781 (Info-goto-node node)
10782 (goto-char (point-min))
10783 (while (search-forward "\n* " nil t)
10784 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
10785 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
10786 (setq s (point-at-bol)
10787 e (point-at-eol))
10788 (with-current-buffer tobuf
10789 (insert-buffer-substring infobuf s e)
10790 (insert "\n"))))))))))
10792 (defun anything-c-info-goto (node-line)
10793 (Info-goto-node (car node-line))
10794 (anything-goto-line (cdr node-line)))
10796 (defun anything-c-info-display-to-real (line)
10797 (and (string-match
10798 ;; This regexp is stolen from Info-apropos-matches
10799 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
10800 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
10801 (string-to-number (or (match-string 3 line) "1")))))
10803 (defun anything-c-make-info-source (source file)
10804 `(,@source
10805 (name . ,(concat "Info Index: " file))
10806 (info-file . ,file)
10807 (init . anything-c-info-init)
10808 (display-to-real . anything-c-info-display-to-real)
10809 (get-line . buffer-substring)
10810 (candidates-in-buffer)
10811 (action ("Goto node" . anything-c-info-goto))))
10813 (defun anything-compile-source--info-index (source)
10814 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
10815 (anything-c-make-info-source source it)
10816 source))
10817 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
10819 (anything-document-attribute 'info-index "info-index plugin"
10820 "Create a source of info index very easily.
10822 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10824 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
10825 "Index nodes of info file.
10827 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10828 Some info files are missing index specification.
10830 ex. See `anything-c-source-info-screen'.")
10832 ;; Plug-in: candidates-file
10833 (defun anything-compile-source--candidates-file (source)
10834 (if (assoc-default 'candidates-file source)
10835 `((init anything-p-candidats-file-init
10836 ,@(let ((orig-init (assoc-default 'init source)))
10837 (cond ((null orig-init) nil)
10838 ((functionp orig-init) (list orig-init))
10839 (t orig-init))))
10840 (candidates-in-buffer)
10841 ,@source)
10842 source))
10843 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
10845 (defun anything-p-candidats-file-init ()
10846 (destructuring-bind (file &optional updating)
10847 (anything-mklist (anything-attr 'candidates-file))
10848 (setq file (anything-interpret-value file))
10849 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
10850 (when updating
10851 (buffer-disable-undo)
10852 (font-lock-mode -1)
10853 (auto-revert-mode 1)))))
10855 (anything-document-attribute 'candidates-file "candidates-file plugin"
10856 "Use a file as the candidates buffer.
10858 1st argument is a filename, string or function name or variable name.
10859 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
10861 ;; Plug-in: headline
10862 (defun anything-compile-source--anything-headline (source)
10863 (if (assoc-default 'headline source)
10864 (append '((init . anything-headline-init)
10865 (get-line . buffer-substring)
10866 (type . line))
10867 source
10868 '((candidates-in-buffer)
10869 (persistent-help . "Show this line")))
10870 source))
10871 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
10873 (defun anything-headline-init ()
10874 (when (and (anything-current-buffer-is-modified)
10875 (with-anything-current-buffer
10876 (eval (or (anything-attr 'condition) t))))
10877 (anything-headline-make-candidate-buffer
10878 (anything-interpret-value (anything-attr 'headline))
10879 (anything-interpret-value (anything-attr 'subexp)))))
10881 (anything-document-attribute 'headline "Headline plug-in"
10882 "Regexp string for anything-headline to scan.")
10883 (anything-document-attribute 'condition "Headline plug-in"
10884 "A sexp representing the condition to use anything-headline.")
10885 (anything-document-attribute 'subexp "Headline plug-in"
10886 "Display (match-string-no-properties subexp).")
10888 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
10889 ;; of regexps.
10891 ;; 1. Create list of ((title . start-of-match) . hiearchy)
10892 ;; 2. Sort this list by start-of-match.
10893 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
10895 ;; It's quite brilliantly written.
10899 (defun anything-headline-get-candidates (regexp subexp)
10900 (with-anything-current-buffer
10901 (save-excursion
10902 (goto-char (point-min))
10903 (if (functionp regexp) (setq regexp (funcall regexp)))
10904 (let (hierarchy curhead)
10905 (flet ((matched ()
10906 (if (numberp subexp)
10907 (cons (match-string-no-properties subexp) (match-beginning subexp))
10908 (cons (buffer-substring (point-at-bol) (point-at-eol))
10909 (point-at-bol))))
10910 (hierarchies (headlines)
10911 (1+ (loop for (_ . hierarchy) in headlines
10912 maximize hierarchy)))
10913 (vector-0-n (v n)
10914 (loop for i from 0 to hierarchy
10915 collecting (aref curhead i)))
10916 (arrange (headlines)
10917 (unless (null headlines) ; FIX headlines empty bug!
10918 (loop with curhead = (make-vector (hierarchies headlines) "")
10919 for ((str . pt) . hierarchy) in headlines
10920 do (aset curhead hierarchy str)
10921 collecting
10922 (cons
10923 (format "H%d:%s" (1+ hierarchy)
10924 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
10925 pt)))))
10926 (if (listp regexp)
10927 (arrange
10928 (sort
10929 (loop for re in regexp
10930 for hierarchy from 0
10931 do (goto-char (point-min))
10932 appending
10933 (loop
10934 while (re-search-forward re nil t)
10935 collect (cons (matched) hierarchy)))
10936 (lambda (a b) (> (cdar b) (cdar a)))))
10937 (loop while (re-search-forward regexp nil t)
10938 collect (matched))))))))
10941 (defun anything-headline-make-candidate-buffer (regexp subexp)
10942 (with-current-buffer (anything-candidate-buffer 'local)
10943 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
10944 do (insert
10945 (format "%5d:%s\n"
10946 (with-anything-current-buffer
10947 (line-number-at-pos pos))
10948 content)))))
10950 (defun anything-headline-goto-position (pos recenter)
10951 (goto-char pos)
10952 (unless recenter
10953 (set-window-start (get-buffer-window anything-current-buffer) (point))))
10956 ;; Plug-in: persistent-help
10957 (defun anything-compile-source--persistent-help (source)
10958 (append source '((header-line . anything-persistent-help-string))))
10959 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
10961 (defun anything-persistent-help-string ()
10962 (substitute-command-keys
10963 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
10964 (or (anything-interpret-value (anything-attr 'persistent-help))
10965 (anything-aif (or (assoc-default 'persistent-action
10966 (anything-get-current-source))
10967 (assoc-default 'action
10968 (anything-get-current-source)))
10969 (cond ((symbolp it) (symbol-name it))
10970 ((listp it) (or (ignore-errors (caar it)) ""))))
10972 " (keeping session)")))
10974 (anything-document-attribute 'persistent-help "persistent-help plug-in"
10975 "A string to explain persistent-action of this source.
10976 It also accepts a function or a variable name.")
10978 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
10980 ;; Plug-in: Type customize
10981 (defun anything-c-uniq-list (lst)
10982 "Like `remove-duplicates' in CL.
10983 But cut deeper duplicates and test by `equal'. "
10984 (reverse (remove-duplicates (reverse lst) :test 'equal)))
10985 (defvar anything-additional-type-attributes nil)
10986 (defun anything-c-arrange-type-attribute (type spec)
10987 "Override type attributes by `define-anything-type-attribute'.
10989 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
10991 Example: Set `play-sound-file' as default action
10992 (anything-c-arrange-type-attribute 'file
10993 '((action (\"Play sound\" . play-sound-file)
10994 REST ;; Rest of actions (find-file, find-file-other-window, ...)
10997 (add-to-list 'anything-additional-type-attributes
10998 (cons type
10999 (loop with typeattr = (assoc-default type anything-type-attributes)
11000 for (attr . value) in spec
11001 if (listp value)
11002 collect (cons attr
11003 (anything-c-uniq-list
11004 (loop for v in value
11005 if (eq v 'REST)
11006 append (assoc-default attr typeattr)
11007 else
11008 collect v)))
11009 else
11010 collect (cons attr value)))))
11011 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11013 (defun anything-compile-source--type-customize (source)
11014 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11015 (append it source)
11016 source))
11017 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11019 ;; Plug-in: default-action
11020 (defun anything-compile-source--default-action (source)
11021 (anything-aif (assoc-default 'default-action source)
11022 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11023 source)
11024 source))
11025 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11026 (anything-document-attribute 'default-action "default-action plug-in"
11027 "Default action.")
11030 ;;; Toggle anything-match-plugin
11033 (defvar anything-mp-initial-highlight-delay nil)
11035 ;;;###autoload
11036 (defun anything-c-toggle-match-plugin ()
11037 "Toggle anything-match-plugin."
11038 (interactive)
11039 (let ((anything-match-plugin-enabled
11040 (member 'anything-compile-source--match-plugin
11041 anything-compile-source-functions)))
11042 (flet ((disable-match-plugin ()
11043 (setq anything-compile-source-functions
11044 (delq 'anything-compile-source--match-plugin
11045 anything-compile-source-functions))
11046 (setq anything-mp-initial-highlight-delay
11047 anything-mp-highlight-delay)
11048 (setq anything-mp-highlight-delay nil))
11049 (enable-match-plugin ()
11050 (require 'anything-match-plugin)
11051 (unless anything-mp-initial-highlight-delay
11052 (setq anything-mp-initial-highlight-delay
11053 anything-mp-highlight-delay))
11054 (setq anything-compile-source-functions
11055 (cons 'anything-compile-source--match-plugin
11056 anything-compile-source-functions))
11057 (unless anything-mp-highlight-delay
11058 (setq anything-mp-highlight-delay
11059 anything-mp-initial-highlight-delay))))
11060 (if anything-match-plugin-enabled
11061 (when (y-or-n-p "Really disable match-plugin? ")
11062 (disable-match-plugin)
11063 (message "Anything-match-plugin disabled"))
11064 (when (y-or-n-p "Really enable match-plugin? ")
11065 (enable-match-plugin)
11066 (message "Anything-match-plugin enabled"))))))
11070 ;;; Type Attributes
11073 (define-anything-type-attribute 'buffer
11074 `((action
11075 ("Switch to buffer" . anything-c-switch-to-buffer)
11076 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11077 ("Switch to buffer other window" . switch-to-buffer-other-window)
11078 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11079 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11080 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11081 ("Query replace" . anything-c-buffer-query-replace)
11082 ("View buffer" . view-buffer)
11083 ("Display buffer" . display-buffer)
11084 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11085 ("Revert buffer(s)" . anything-revert-marked-buffers)
11086 ("Insert buffer" . insert-buffer)
11087 ("Kill buffer(s)" . anything-kill-marked-buffers)
11088 ("Diff with file" . diff-buffer-with-file)
11089 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11090 ("Ediff Merge marked buffers" . (lambda (candidate)
11091 (anything-ediff-marked-buffers candidate t))))
11092 (persistent-help . "Show this buffer")
11093 (candidate-transformer anything-c-skip-current-buffer
11094 anything-c-skip-boring-buffers
11095 anything-c-transform-buffer-display-string))
11096 "Buffer or buffer name.")
11098 (define-anything-type-attribute 'file
11099 `((action
11100 ("Find file" . anything-find-many-files)
11101 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11102 ("Find file as root" . anything-find-file-as-root)
11103 ("Find file other window" . find-file-other-window)
11104 ("Find file other frame" . find-file-other-frame)
11105 ("Open dired in file's directory" . anything-c-open-dired)
11106 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11107 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11108 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11109 ("Checksum File" . anything-ff-checksum)
11110 ("Ediff File" . anything-find-files-ediff-files)
11111 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11112 ("View file" . view-file)
11113 ("Insert file" . insert-file)
11114 ("Delete file(s)" . anything-delete-marked-files)
11115 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11116 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11117 ("Find file in hex dump" . hexl-find-file))
11118 (persistent-help . "Show this file")
11119 (action-transformer anything-c-transform-file-load-el
11120 anything-c-transform-file-browse-url)
11121 (candidate-transformer anything-c-w32-pathname-transformer
11122 anything-c-skip-current-file
11123 anything-c-skip-boring-files
11124 anything-c-shorten-home-path))
11125 "File name.")
11127 (let ((actions '(("Describe command" . describe-function)
11128 ("Add command to kill ring" . anything-c-kill-new)
11129 ("Go to command's definition" . find-function)
11130 ("Debug on entry" . debug-on-entry)
11131 ("Cancel debug on entry" . cancel-debug-on-entry)
11132 ("Trace function" . trace-function)
11133 ("Trace function (background)" . trace-function-background)
11134 ("Untrace function" . untrace-function))))
11135 (define-anything-type-attribute 'command
11136 `((action ("Call interactively" . anything-c-call-interactively)
11137 ,@actions)
11138 ;; Sort commands according to their usage count.
11139 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11140 (coerce . anything-c-symbolify)
11141 (persistent-action . describe-function))
11142 "Command. (string or symbol)")
11144 (define-anything-type-attribute 'function
11145 `((action . ,actions)
11146 (action-transformer anything-c-transform-function-call-interactively)
11147 (candidate-transformer anything-c-mark-interactive-functions)
11148 (coerce . anything-c-symbolify))
11149 "Function. (string or symbol)"))
11151 (define-anything-type-attribute 'variable
11152 '((action ("Describe variable" . describe-variable)
11153 ("Add variable to kill ring" . anything-c-kill-new)
11154 ("Go to variable's definition" . find-variable)
11155 ("Set variable" . anything-c-set-variable))
11156 (coerce . anything-c-symbolify))
11157 "Variable.")
11159 (define-anything-type-attribute 'sexp
11160 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11161 ("Add s-expression to kill ring" . kill-new))
11162 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11163 "String representing S-Expressions.")
11165 (define-anything-type-attribute 'bookmark
11166 `((coerce . anything-bookmark-get-bookmark-from-name)
11167 (action
11168 ("Jump to bookmark" . (lambda (bookmark)
11169 (let ((current-prefix-arg anything-current-prefix-arg))
11170 (bookmark-jump bookmark))
11171 (anything-update)))
11172 ("Jump to BM other window" . (lambda (bookmark)
11173 (bookmark-jump-other-window bookmark)
11174 (anything-update)))
11175 ("Bookmark edit annotation" . bookmark-edit-annotation)
11176 ("Bookmark show annotation" . bookmark-show-annotation)
11177 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11178 ,@(and (locate-library "bookmark-extensions")
11179 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11180 ("Rename bookmark" . bookmark-rename)
11181 ("Relocate bookmark" . bookmark-relocate)))
11182 "Bookmark name.")
11184 (define-anything-type-attribute 'line
11185 '((display-to-real . anything-c-display-to-real-line)
11186 (action ("Go to Line" . anything-c-action-line-goto)))
11187 "LINENO:CONTENT string, eg. \" 16:foo\".
11189 Optional `target-file' attribute is a name of target file.
11191 Optional `before-jump-hook' attribute is a function with no
11192 arguments which is called before jumping to position.
11194 Optional `after-jump-hook' attribute is a function with no
11195 arguments which is called after jumping to position.
11197 If `adjust' attribute is specified, searches the line whose
11198 content is CONTENT near the LINENO.
11200 If `recenter' attribute is specified, the line is displayed at
11201 the center of window, otherwise at the top of window.
11204 (define-anything-type-attribute 'file-line
11205 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11206 (multiline)
11207 (action ("Go to" . anything-c-action-file-line-goto)))
11208 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11210 Optional `default-directory' attribute is a default-directory
11211 FILENAME is interpreted.
11213 Optional `before-jump-hook' attribute is a function with no
11214 arguments which is called before jumping to position.
11216 Optional `after-jump-hook' attribute is a function with no
11217 arguments which is called after jumping to position.
11219 If `adjust' attribute is specified, searches the line whose
11220 content is CONTENT near the LINENO.
11222 If `recenter' attribute is specified, the line is displayed at
11223 the center of window, otherwise at the top of window.
11226 (define-anything-type-attribute 'timer
11227 '((real-to-display . anything-c-timer-real-to-display)
11228 (action ("Cancel Timer" . cancel-timer)
11229 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11230 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11231 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11232 (persistent-help . "Describe Function"))
11233 "Timer.")
11236 ;;; Default `anything-sources'
11237 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11238 ;; tend to invoke M-x anything directly. So I offer default setting.
11239 (setq anything-sources
11240 '(anything-c-source-buffers-list
11241 anything-c-source-recentf
11242 anything-c-source-files-in-current-dir+))
11245 ;;; Preconfigured Anything
11248 ;;;###autoload
11249 (defun anything-mini ()
11250 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11251 (interactive)
11252 (anything-other-buffer '(anything-c-source-buffers-list
11253 anything-c-source-recentf
11254 anything-c-source-buffer-not-found)
11255 "*anything mini*"))
11256 ;;;###autoload
11257 (defun anything-for-files ()
11258 "Preconfigured `anything' for opening files.
11259 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11260 (interactive)
11261 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11263 ;;;###autoload
11264 (defun anything-recentf ()
11265 "Preconfigured `anything' for `recentf'."
11266 (interactive)
11267 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11269 ;;;###autoload
11270 (defun anything-info-at-point (arg)
11271 "Preconfigured `anything' for searching info at point.
11272 With a prefix-arg insert symbol at point."
11273 (interactive "P")
11274 (let ((anything-c-google-suggest-default-function
11275 'anything-c-google-suggest-emacs-lisp))
11276 (anything :sources '(anything-c-source-info-elisp
11277 anything-c-source-info-cl
11278 anything-c-source-info-pages
11279 anything-c-source-google-suggest)
11280 :input (and arg (thing-at-point 'symbol))
11281 :buffer "*anything info*")))
11283 ;;;###autoload
11284 (defun anything-info-emacs ()
11285 "Preconfigured anything for Emacs manual index."
11286 (interactive)
11287 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11289 ;;;###autoload
11290 (defun anything-show-kill-ring ()
11291 "Preconfigured `anything' for `kill-ring'.
11292 It is drop-in replacement of `yank-pop'.
11293 You may bind this command to M-y.
11294 First call open the kill-ring browser, next calls move to next line."
11295 (interactive)
11296 (let ((buf "*anything kill-ring*"))
11297 (if (get-buffer-window buf)
11298 (with-anything-window
11299 (if (eq (overlay-end anything-selection-overlay) (point-max))
11300 (anything-beginning-of-buffer)
11301 (anything-next-line)))
11302 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11304 ;;;###autoload
11305 (defun anything-minibuffer-history ()
11306 "Preconfigured `anything' for `minibuffer-history'."
11307 (interactive)
11308 (let ((enable-recursive-minibuffers t))
11309 (anything-other-buffer 'anything-c-source-minibuffer-history
11310 "*anything minibuffer-history*")))
11312 ;;;###autoload
11313 (defun anything-gentoo ()
11314 "Preconfigured `anything' for gentoo linux."
11315 (interactive)
11316 (anything-other-buffer '(anything-c-source-gentoo
11317 anything-c-source-use-flags)
11318 "*anything gentoo*"))
11320 ;;;###autoload
11321 (defun anything-imenu ()
11322 "Preconfigured `anything' for `imenu'."
11323 (interactive)
11324 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
11326 ;;;###autoload
11327 (defun anything-google-suggest ()
11328 "Preconfigured `anything' for google search with google suggest."
11329 (interactive)
11330 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11332 ;;;###autoload
11333 (defun anything-yahoo-suggest ()
11334 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11335 (interactive)
11336 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11338 ;;; Converted from anything-show-*-only
11339 ;;;###autoload
11340 (defun anything-for-buffers ()
11341 "Preconfigured `anything' for buffer."
11342 (interactive)
11343 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11345 ;;;###autoload
11346 (defun anything-buffers-list ()
11347 "Enhanced preconfigured `anything' for buffer."
11348 (interactive)
11349 (anything :sources '(anything-c-source-buffers-list
11350 anything-c-source-buffer-not-found)
11351 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11353 ;;;###autoload
11354 (defun anything-bbdb ()
11355 "Preconfigured `anything' for BBDB.
11357 Needs BBDB.
11359 http://bbdb.sourceforge.net/"
11360 (interactive)
11361 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11363 ;;;###autoload
11364 (defun anything-locate (arg)
11365 "Preconfigured `anything' for Locate.
11366 Note: you can add locate options after entering pattern.
11367 See 'man locate' for valid options.
11369 You can specify a specific database with prefix argument ARG \(C-u\).
11370 Many databases can be used: navigate and mark them.
11371 See also `anything-locate-with-db'.
11373 To create a user specific db, use
11374 \"updatedb -l 0 -o db_path -U directory\".
11375 Where db_path is a filename matched by
11376 `anything-locate-db-file-regexp'."
11377 (interactive "P")
11378 (anything-locate-1 arg))
11380 ;;;###autoload
11381 (defun anything-w3m-bookmarks ()
11382 "Preconfigured `anything' for w3m bookmark.
11384 Needs w3m and emacs-w3m.
11386 http://w3m.sourceforge.net/
11387 http://emacs-w3m.namazu.org/"
11388 (interactive)
11389 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11390 "*anything w3m bookmarks*"))
11392 ;;;###autoload
11393 (defun anything-firefox-bookmarks ()
11394 "Preconfigured `anything' for firefox bookmark.
11395 You will have to enable html bookmarks in firefox:
11396 open about:config in firefox and double click on this line to enable value \
11397 to true:
11399 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11401 You should have now:
11403 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11405 After closing firefox, you will be able to browse you bookmarks.
11407 (interactive)
11408 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11409 "*Anything Firefox*"))
11411 ;;;###autoload
11412 (defun anything-colors ()
11413 "Preconfigured `anything' for color."
11414 (interactive)
11415 (anything-other-buffer
11416 '(anything-c-source-colors anything-c-source-customize-face)
11417 "*anything colors*"))
11419 ;;;###autoload
11420 (defun anything-bookmarks ()
11421 "Preconfigured `anything' for bookmarks."
11422 (interactive)
11423 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11425 ;;;###autoload
11426 (defun anything-c-pp-bookmarks ()
11427 "Preconfigured `anything' for bookmarks (pretty-printed)."
11428 (interactive)
11429 (anything-other-buffer '(anything-c-source-bookmarks-local
11430 anything-c-source-bookmarks-su
11431 anything-c-source-bookmarks-ssh)
11432 "*anything pp bookmarks*"))
11434 ;;;###autoload
11435 (defun anything-c-insert-latex-math ()
11436 "Preconfigured anything for latex math symbols completion."
11437 (interactive)
11438 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11440 ;;;###autoload
11441 (defun anything-register ()
11442 "Preconfigured `anything' for Emacs registers."
11443 (interactive)
11444 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11446 ;;;###autoload
11447 (defun anything-man-woman ()
11448 "Preconfigured `anything' for Man and Woman pages."
11449 (interactive)
11450 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11452 ;;;###autoload
11453 (defun anything-org-keywords ()
11454 "Preconfigured `anything' for org keywords."
11455 (interactive)
11456 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11458 ;;;###autoload
11459 (defun anything-emms ()
11460 "Preconfigured `anything' for emms sources."
11461 (interactive)
11462 (anything '(anything-c-source-emms-streams
11463 anything-c-source-emms-files
11464 anything-c-source-emms-dired)
11465 nil nil nil nil
11466 "*Anything Emms*"))
11468 ;;;###autoload
11469 (defun anything-eev-anchors ()
11470 "Preconfigured `anything' for eev anchors."
11471 (interactive)
11472 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11474 ;;;###autoload
11475 (defun anything-bm-list ()
11476 "Preconfigured `anything' for visible bookmarks.
11478 Needs bm.el
11480 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11481 (interactive)
11482 (let ((anything-outline-using t))
11483 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11485 ;;;###autoload
11486 (defun anything-timers ()
11487 "Preconfigured `anything' for timers."
11488 (interactive)
11489 (anything-other-buffer '(anything-c-source-absolute-time-timers
11490 anything-c-source-idle-time-timers)
11491 "*anything timers*"))
11493 ;;;###autoload
11494 (defun anything-list-emacs-process ()
11495 "Preconfigured `anything' for emacs process."
11496 (interactive)
11497 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11499 ;;;###autoload
11500 (defun anything-occur ()
11501 "Preconfigured Anything for Occur source.
11502 If region is active, search only in region,
11503 otherwise search in whole buffer."
11504 (interactive)
11505 (let ((anything-compile-source-functions
11506 ;; rule out anything-match-plugin because the input is one regexp.
11507 (delq 'anything-compile-source--match-plugin
11508 (copy-sequence anything-compile-source-functions))))
11509 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11511 ;;;###autoload
11512 (defun anything-browse-code ()
11513 "Preconfigured anything to browse code."
11514 (interactive)
11515 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
11517 ;;;###autoload
11518 (defun anything-org-headlines ()
11519 "Preconfigured anything to show org headlines."
11520 (interactive)
11521 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11523 ;;;###autoload
11524 (defun anything-info-gnus ()
11525 "Preconfigured anything to browse Gnus Manual."
11526 (interactive)
11527 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11529 ;;;###autoload
11530 (defun anything-regexp ()
11531 "Preconfigured anything to build regexps and run query-replace-regexp \
11532 against."
11533 (interactive)
11534 (save-restriction
11535 (let ((anything-compile-source-functions
11536 ;; rule out anything-match-plugin because the input is one regexp.
11537 (delq 'anything-compile-source--match-plugin
11538 (copy-sequence anything-compile-source-functions))))
11539 (when (and (anything-region-active-p)
11540 ;; Don't narrow to region if buffer is already narrowed.
11541 (not (anything-current-buffer-narrowed-p)))
11542 (narrow-to-region (region-beginning) (region-end)))
11543 (anything :sources
11544 anything-c-source-regexp
11545 :buffer "*anything regexp*"
11546 :prompt "Regexp: "))))
11548 (defun anything-c-copy-files-async ()
11549 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11550 (interactive)
11551 (let* ((flist (anything-c-read-file-name
11552 "Copy File async: "
11553 :marked-candidates t))
11554 (dest (anything-c-read-file-name
11555 "Copy File async To: "
11556 :preselect (car flist)
11557 :initial-input (car anything-ff-history)
11558 :history (anything-find-files-history :comp-read nil))))
11559 (anything-c-copy-async-with-log flist dest)))
11561 ;;;###autoload
11562 (defun anything-find-files (arg)
11563 "Preconfigured `anything' for anything implementation of `find-file'.
11564 Called with a prefix arg show history if some.
11565 Don't call it from programs, use `anything-find-files-1' instead.
11566 This is the starting point for nearly all actions you can do on files."
11567 (interactive "P")
11568 (let ((any-input (if (and arg anything-ff-history)
11569 (anything-find-files-history)
11570 (anything-find-files-initial-input)))
11571 (presel (buffer-file-name (current-buffer))))
11572 (when (and (eq major-mode 'org-agenda-mode)
11573 org-directory
11574 (not any-input))
11575 (setq any-input (expand-file-name org-directory)))
11576 (set-text-properties 0 (length any-input) nil any-input)
11577 (if any-input
11578 (anything-find-files-1 any-input)
11579 (setq any-input (expand-file-name (anything-c-current-directory)))
11580 (anything-find-files-1
11581 any-input (if anything-ff-transformer-show-only-basename
11582 (and presel (anything-c-basename presel))
11583 presel)))))
11585 ;;;###autoload
11586 (defun anything-write-file ()
11587 "Preconfigured `anything' providing completion for `write-file'."
11588 (interactive)
11589 (let ((anything-mp-highlight-delay nil))
11590 (anything :sources 'anything-c-source-write-file
11591 :input (expand-file-name default-directory)
11592 :prompt "Write buffer to file: "
11593 :buffer "*Anything write file*")))
11595 ;;;###autoload
11596 (defun anything-insert-file ()
11597 "Preconfigured `anything' providing completion for `insert-file'."
11598 (interactive)
11599 (let ((anything-mp-highlight-delay nil))
11600 (anything :sources 'anything-c-source-insert-file
11601 :input (expand-file-name default-directory)
11602 :prompt "Insert file: "
11603 :buffer "*Anything insert file*")))
11605 ;;;###autoload
11606 (defun anything-dired-rename-file ()
11607 "Preconfigured `anything' to rename files from dired."
11608 (interactive)
11609 (anything-dired-do-action-on-file :action 'rename))
11611 ;;;###autoload
11612 (defun anything-dired-copy-file ()
11613 "Preconfigured `anything' to copy files from dired."
11614 (interactive)
11615 (anything-dired-do-action-on-file :action 'copy))
11617 ;;;###autoload
11618 (defun anything-dired-symlink-file ()
11619 "Preconfigured `anything' to symlink files from dired."
11620 (interactive)
11621 (anything-dired-do-action-on-file :action 'symlink))
11623 ;;;###autoload
11624 (defun anything-dired-hardlink-file ()
11625 "Preconfigured `anything' to hardlink files from dired."
11626 (interactive)
11627 (anything-dired-do-action-on-file :action 'hardlink))
11629 ;;;###autoload
11630 (defun anything-do-grep ()
11631 "Preconfigured anything for grep.
11632 Contrarily to Emacs `grep' no default directory is given, but
11633 the full path of candidates in ONLY.
11634 That allow to grep different files not only in `default-directory' but anywhere
11635 by marking them (C-<SPACE>). If one or more directory is selected
11636 grep will search in all files of these directories.
11637 You can use also wildcard in the base name of candidate.
11638 If a prefix arg is given use the -r option of grep.
11639 The prefix arg can be passed before or after start.
11640 See also `anything-do-grep-1'."
11641 (interactive)
11642 (let ((only (anything-c-read-file-name
11643 "Search in file(s): "
11644 :marked-candidates t
11645 :preselect (or (dired-get-filename nil t)
11646 (buffer-file-name (current-buffer)))))
11647 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11648 (anything-do-grep-1 only prefarg)))
11650 ;;;###autoload
11651 (defun anything-do-zgrep (candidate)
11652 "Preconfigured anything for zgrep."
11653 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11654 (ls (anything-c-read-file-name
11655 "Search in file(s): "
11656 :marked-candidates t
11657 :preselect (or (dired-get-filename nil t)
11658 (buffer-file-name (current-buffer))))))
11659 (anything-ff-zgrep-1 ls prefarg)))
11661 (defun anything-c-etags-select (arg)
11662 "Preconfigured anything for etags.
11663 Called with one prefix arg use symbol at point as initial input.
11664 Called with two prefix arg reinitialize cache.
11665 If tag file have been modified reinitialize cache."
11666 (interactive "P")
11667 (let ((tag (anything-c-etags-get-tag-file))
11668 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11669 (anything-quit-if-no-candidate t)
11670 (anything-execute-action-at-once-if-one t)
11671 (anything-compile-source-functions
11672 (if anything-c-etags-use-regexp-search
11673 ;; rule out anything-match-plugin because the input is one regexp.
11674 (delq 'anything-compile-source--match-plugin
11675 (copy-sequence anything-compile-source-functions))
11676 anything-compile-source-functions)))
11677 (when (or (equal arg '(16))
11678 (and anything-c-etags-mtime-alist
11679 (anything-c-etags-file-modified-p tag)))
11680 (remhash tag anything-c-etags-cache))
11681 (if (and tag (file-exists-p tag))
11682 (anything :sources 'anything-c-source-etags-select
11683 :keymap anything-c-etags-map
11684 :input init
11685 :buffer "*anything etags*")
11686 (message "Error: No tag file found, please create one with etags shell command."))))
11688 ;;;###autoload
11689 (defun anything-filelist ()
11690 "Preconfigured `anything' to open files instantly.
11692 See `anything-c-filelist-file-name' docstring for usage."
11693 (interactive)
11694 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11696 ;;;###autoload
11697 (defun anything-filelist+ ()
11698 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11700 This is a replacement for `anything-for-files'.
11701 See `anything-c-filelist-file-name' docstring for usage."
11702 (interactive)
11703 (anything-other-buffer
11704 '(anything-c-source-ffap-line
11705 anything-c-source-ffap-guesser
11706 anything-c-source-buffers-list
11707 anything-c-source-recentf
11708 anything-c-source-bookmarks
11709 anything-c-source-file-cache
11710 anything-c-source-filelist)
11711 "*anything file list*"))
11713 ;;;###autoload
11714 (defun anything-M-x ()
11715 "Preconfigured `anything' for Emacs commands.
11716 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11717 (interactive)
11718 (let* (in-help
11719 help-cand
11720 anything-persistent-action-use-special-display
11721 (history (loop with hist
11722 for i in extended-command-history
11723 for com = (intern i)
11724 when (fboundp com)
11725 collect i into hist finally return hist)))
11726 (flet ((pers-help (candidate)
11727 (let ((hbuf (get-buffer (help-buffer))))
11728 (if (and in-help (string= candidate help-cand))
11729 (progn
11730 ;; When M-x is started from a help buffer,
11731 ;; Don't kill it as it is anything-current-buffer.
11732 (unless (equal hbuf anything-current-buffer)
11733 (kill-buffer hbuf))
11734 (setq in-help nil))
11735 ;; Be sure anything-current-buffer
11736 ;; have not a dedicated window.
11737 (set-window-dedicated-p
11738 (get-buffer-window anything-current-buffer) nil)
11739 (describe-function (intern candidate))
11740 (message nil) ; Erase the new stupid message Type "q"[...]
11741 (setq in-help t))
11742 (setq help-cand candidate))))
11743 (let* ((command
11745 (anything
11746 :sources
11747 '(((name . "Emacs Commands history")
11748 (candidates . history)
11749 (filtered-candidate-transformer
11750 . (lambda (candidates sources)
11751 (loop for i in candidates
11752 do (set-text-properties 0 (length i) nil i)
11753 collect i)))
11754 (persistent-action . pers-help)
11755 (persistent-help . "Describe this command")
11756 (action . identity))
11757 ((name . "Emacs Commands")
11758 (init
11759 . (lambda ()
11760 (with-current-buffer (anything-candidate-buffer 'global)
11761 (goto-char (point-min))
11762 (loop
11763 for sym in (all-completions "" obarray 'commandp)
11764 do (insert (concat sym "\n"))))))
11765 (persistent-action . pers-help)
11766 (persistent-help . "Describe this command")
11767 (filtered-candidate-transformer . anything-M-x-transformer)
11768 (candidates-in-buffer)
11769 (action . identity)))
11770 :buffer "*anything M-x*")
11771 (keyboard-quit)))
11772 (sym-com (intern command)))
11773 (unless current-prefix-arg
11774 (setq current-prefix-arg anything-current-prefix-arg))
11775 ;; Avoid having `this-command' set to *exit-minibuffer.
11776 (setq this-command sym-com)
11777 (call-interactively sym-com)
11778 (setq extended-command-history
11779 (cons command (delete command history)))))))
11781 ;;;###autoload
11782 (defun anything-manage-advice ()
11783 "Preconfigured `anything' to disable/enable function advices."
11784 (interactive)
11785 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
11787 ;;;###autoload
11788 (defun anything-bookmark-ext ()
11789 "Preconfigured `anything' for bookmark-extensions sources.
11790 Needs bookmark-ext.el:
11791 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11792 Contain also `anything-c-source-google-suggest'."
11793 (interactive)
11794 (anything
11795 :sources
11796 '(anything-c-source-bookmark-files&dirs
11797 anything-c-source-bookmark-w3m
11798 anything-c-source-google-suggest
11799 anything-c-source-bmkext-addressbook
11800 anything-c-source-bookmark-gnus
11801 anything-c-source-bookmark-info
11802 anything-c-source-bookmark-man
11803 anything-c-source-bookmark-images
11804 anything-c-source-bookmark-su-files&dirs
11805 anything-c-source-bookmark-ssh-files&dirs)
11806 :prompt "SearchBookmark: "
11807 :buffer "*anything bmkext*"))
11809 ;;;###autoload
11810 (defun anything-simple-call-tree ()
11811 "Preconfigured `anything' for simple-call-tree. List function relationships.
11813 Needs simple-call-tree.el.
11814 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11815 (interactive)
11816 (anything-other-buffer
11817 '(anything-c-source-simple-call-tree-functions-callers
11818 anything-c-source-simple-call-tree-callers-functions)
11819 "*anything simple-call-tree*"))
11821 ;;;###autoload
11822 (defun anything-mark-ring ()
11823 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11824 (interactive)
11825 (anything 'anything-c-source-mark-ring))
11827 ;;;###autoload
11828 (defun anything-global-mark-ring ()
11829 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
11830 (interactive)
11831 (anything 'anything-c-source-global-mark-ring))
11833 ;;;###autoload
11834 (defun anything-all-mark-rings ()
11835 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
11836 `anything-c-source-mark-ring'."
11837 (interactive)
11838 (anything '(anything-c-source-mark-ring
11839 anything-c-source-global-mark-ring)))
11841 ;;;###autoload
11842 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
11843 "Preconfigured `anything' to edit or view EmacsWiki page.
11845 Needs yaoddmuse.el.
11847 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11848 (interactive)
11849 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
11851 ;;;###autoload
11852 (defun anything-yaoddmuse-emacswiki-post-library ()
11853 "Preconfigured `anything' to post library to EmacsWiki.
11855 Needs yaoddmuse.el.
11857 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11858 (interactive)
11859 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
11861 ;;;###autoload
11862 (defun anything-eval-expression (arg)
11863 "Preconfigured anything for `anything-c-source-evaluation-result'."
11864 (interactive "P")
11865 (anything :sources 'anything-c-source-evaluation-result
11866 :input (when arg (thing-at-point 'sexp))
11867 :buffer "*anything eval*"
11868 :keymap anything-eval-expression-map))
11870 ;;;###autoload
11871 (defun anything-eval-expression-with-eldoc ()
11872 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
11873 (interactive)
11874 (declare (special eldoc-idle-delay))
11875 (let ((timer (run-with-idle-timer eldoc-idle-delay
11876 'repeat 'anything-eldoc-show-in-eval))
11877 (minibuffer-completing-symbol t) ; Enable lisp completion.
11878 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
11879 (unwind-protect
11880 (minibuffer-with-setup-hook
11881 'anything-eldoc-store-minibuffer
11882 (call-interactively 'anything-eval-expression))
11883 (and timer (cancel-timer timer))
11884 (setq anything-eldoc-active-minibuffers-list
11885 (cdr anything-eldoc-active-minibuffers-list)))))
11887 ;;;###autoload
11888 (defun anything-calcul-expression ()
11889 "Preconfigured anything for `anything-c-source-calculation-result'."
11890 (interactive)
11891 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
11893 ;;;###autoload
11894 (defun anything-surfraw (pattern engine)
11895 "Preconfigured `anything' to search PATTERN with search ENGINE."
11896 (interactive (list (read-string "SearchFor: ")
11897 (anything-comp-read
11898 "Engine: "
11899 (anything-c-build-elvi-list)
11900 :must-match t
11901 :name "Surfraw Search Engines"
11902 :history anything-surfraw-engines-history)))
11903 (let* ((engine-nodesc (car (split-string engine)))
11904 (url (with-temp-buffer
11905 (apply 'call-process "surfraw" nil t nil
11906 ;;JAVE
11907 (append (list engine-nodesc "-p") (split-string pattern)))
11908 (replace-regexp-in-string
11909 "\n" "" (buffer-string))))
11910 (browse-url-browser-function (or anything-surfraw-default-browser-function
11911 browse-url-browser-function)))
11912 (if (string= engine-nodesc "W")
11913 (anything-c-browse-url)
11914 (anything-c-browse-url url)
11915 (setq anything-surfraw-engines-history
11916 (cons engine (delete engine anything-surfraw-engines-history))))))
11918 ;;;###autoload
11919 (defun anything-call-source ()
11920 "Preconfigured `anything' to call anything source."
11921 (interactive)
11922 (anything 'anything-c-source-call-source nil nil nil nil
11923 anything-source-select-buffer))
11925 ;;;###autoload
11926 (defun anything-execute-anything-command ()
11927 "Preconfigured `anything' to execute preconfigured `anything'."
11928 (interactive)
11929 (anything-other-buffer 'anything-c-source-anything-commands
11930 "*anything commands*"))
11932 ;;;###autoload
11933 (defun anything-create (&optional string initial-input)
11934 "Preconfigured `anything' to do many create actions from STRING.
11935 See also `anything-create--actions'."
11936 (interactive)
11937 (setq string (or string (read-string "Create Anything: " initial-input)))
11938 (anything '(((name . "Anything Create")
11939 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
11940 (candidates . anything-create--actions)
11941 (candidate-number-limit)
11942 (action . (lambda (func) (funcall func string)))))))
11944 ;;;###autoload
11945 (defun anything-top ()
11946 "Preconfigured `anything' for top command."
11947 (interactive)
11948 (let ((anything-samewindow t)
11949 (anything-enable-shortcuts)
11950 (anything-display-function 'anything-default-display-buffer)
11951 (anything-candidate-number-limit 9999))
11952 (save-window-excursion
11953 (delete-other-windows)
11954 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
11956 ;;;###autoload
11957 (defun anything-select-xfont ()
11958 "Preconfigured `anything' to select Xfont."
11959 (interactive)
11960 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
11962 ;;;###autoload
11963 (defun anything-world-time ()
11964 "Preconfigured `anything' to show world time."
11965 (interactive)
11966 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
11968 ;;;###autoload
11969 (defun anything-apt (arg query)
11970 "Preconfigured `anything' : frontend of APT package manager.
11971 With a prefix arg reload cache."
11972 (interactive "P\nsSearch Package: ")
11973 (when arg
11974 (setq anything-c-apt-installed-packages nil)
11975 (setq anything-c-apt-all-packages nil))
11976 (anything :sources 'anything-c-source-apt
11977 :prompt "Search Package: " :input query))
11979 ;;;###autoload
11980 (defun anything-esh-pcomplete ()
11981 "Preconfigured anything to provide anything completion in eshell."
11982 (interactive)
11983 (let* ((anything-quit-if-no-candidate t)
11984 (anything-execute-action-at-once-if-one t)
11985 (target (thing-at-point 'symbol))
11986 (end (point))
11987 (beg (or (and target (- end (length target)))
11988 ;; Nothing at point.
11989 (progn (insert " ") (point)))))
11990 (setq anything-ec-target (or target " "))
11991 (with-anything-show-completion beg end
11992 (anything :sources 'anything-c-source-esh
11993 :input (anything-ff-set-pattern ; Handle tramp filenames.
11994 (car (last (ignore-errors ; Needed in lisp symbols completion.
11995 (pcomplete-parse-arguments)))))))))
11997 ;;;###autoload
11998 (defun anything-eshell-history ()
11999 "Preconfigured anything for eshell history."
12000 (interactive)
12001 (let* ((end (point))
12002 (beg (save-excursion (eshell-bol) (point)))
12003 flag-empty)
12004 (when (eq beg end)
12005 (insert " ")
12006 (setq flag-empty t)
12007 (setq end (point)))
12008 (unwind-protect
12009 (with-anything-show-completion beg end
12010 (anything :sources 'anything-c-source-eshell-history
12011 :buffer "*Eshell history*"))
12012 (when (and flag-empty
12013 (looking-back " "))
12014 (delete-char -1)))))
12016 ;;;###autoload
12017 (defun anything-c-run-external-command (program)
12018 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12019 If program is already running exit with error.
12020 You can set your own list of commands with
12021 `anything-c-external-commands-list'."
12022 (interactive (list
12023 (anything-comp-read
12024 "RunProgram: "
12025 (anything-c-external-commands-list-1 'sort)
12026 :must-match t
12027 :name "External Commands"
12028 :history anything-external-command-history)))
12029 (anything-run-or-raise program)
12030 (setq anything-external-command-history
12031 (cons program (delete program
12032 (loop for i in anything-external-command-history
12033 when (executable-find i) collect i)))))
12035 ;;;###autoload
12036 (defun anything-ratpoison-commands ()
12037 "Preconfigured `anything' to execute ratpoison commands."
12038 (interactive)
12039 (anything-other-buffer 'anything-c-source-ratpoison-commands
12040 "*anything ratpoison commands*"))
12042 ;;;###autoload
12043 (defun anything-ucs ()
12044 "Preconfigured anything for `ucs-names' math symbols."
12045 (interactive)
12046 (anything :sources 'anything-c-source-ucs
12047 :keymap anything-c-ucs-map))
12051 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12054 (provide 'anything-config)
12056 ;;; Local Variables:
12057 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12058 ;;; End:
12060 ;; How to save (DO NOT REMOVE!!)
12061 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12062 ;;; anything-config.el ends here
12064 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12065 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12066 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12067 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12068 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12069 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12070 ;;; LocalWords: dotimes Thierry online vname
12071 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12072 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12073 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12074 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12075 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12076 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12077 ;;; LocalWords: startpos noselect dont desc