* anything-config.el (anything-find-files-do-action): Remove the window save/restore...
[anything-config.git] / anything-config.el
blob9659219ee6a33e8b193eaf2d4c262b38a7fc2a4c
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 (find-function . anything-completing-read-symbols)
1174 (trace-function . anything-completing-read-symbols)
1175 (trace-function-background . anything-completing-read-symbols)
1176 (ffap-alternate-file . nil))
1177 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1178 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1179 where key and value are symbols.
1181 Each key is an Emacs command that use originaly `completing-read'.
1183 Each value maybe an anything function that take same arguments as
1184 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1185 anything source and BUFFER the name of the buffer we will use.
1186 This function prefix name must start by \"anything\".
1188 See `anything-completing-read-symbols' for example.
1190 If the value of an entry is nil completion will fall back to
1191 emacs vanilla behavior.
1192 e.g If you want to disable anything completion for `describe-function':
1193 \(describe-function . nil\).
1195 Ido is also supported, you can use `ido-completing-read' and
1196 `ido-read-file-name' as value of an entry or just 'ido.
1197 e.g ido completion for `find-file':
1198 \(find-file . ido\)
1199 same as
1200 \(find-file . ido-read-file-name\)
1201 Note that you don't need to enable `ido-mode' for this to work."
1202 :group 'anything-config
1203 :type '(alist :key-type symbol :value-type symbol))
1207 ;;; General internal variables
1209 ;; Some internals variable that need to be loaded
1210 ;; here to avoid compiler warnings.
1211 (defvar anything-c-external-commands-list nil
1212 "A list of all external commands the user can execute. If this
1213 variable is not set by the user, it will be calculated
1214 automatically.")
1216 (defvar anything-c-show-completion-overlay nil)
1218 (defvar anything-c-locate-command
1219 (case system-type
1220 ('gnu/linux "locate -i -r %s")
1221 ('berkeley-unix "locate -i %s")
1222 ('windows-nt "es -i -r %s")
1223 (t "locate %s"))
1224 "A list of arguments for locate program.
1225 The \"-r\" option must be the last option.")
1228 ;;; Faces
1231 (defface anything-buffer-saved-out
1232 '((t (:foreground "red")))
1233 "*Face used for buffer files modified outside of emacs."
1234 :group 'anything-config)
1236 (defface anything-buffer-not-saved
1237 '((t (:foreground "Indianred2")))
1238 "*Face used for buffer files not already saved on disk."
1239 :group 'anything-config)
1241 (defface anything-ff-prefix
1242 '((t (:background "yellow" :foreground "black")))
1243 "*Face used to prefix new file or url paths in `anything-find-files'."
1244 :group 'anything-config)
1246 (defface anything-ff-executable
1247 '((t (:foreground "green")))
1248 "*Face used for executable files in `anything-find-files'."
1249 :group 'anything-config)
1251 (defface anything-ff-directory
1252 '((t (:foreground "DarkRed" :background "LightGray")))
1253 "*Face used for directories in `anything-find-files'."
1254 :group 'anything-config)
1256 (defface anything-ff-symlink
1257 '((t (:foreground "DarkOrange")))
1258 "*Face used for symlinks in `anything-find-files'."
1259 :group 'anything-config)
1261 (defface anything-ff-invalid-symlink
1262 '((t (:foreground "black" :background "red")))
1263 "*Face used for invalid symlinks in `anything-find-files'."
1264 :group 'anything-config)
1266 (defface anything-ff-file
1267 '((t (:foreground "CadetBlue" :underline t)))
1268 "*Face used for file names in `anything-find-files'."
1269 :group 'anything-config)
1271 (defface anything-grep-match
1272 '((t (:inherit match)))
1273 "Face used to highlight grep matches."
1274 :group 'anything-config)
1276 (defface anything-grep-file
1277 '((t (:foreground "BlueViolet" :underline t)))
1278 "Face used to highlight grep results filenames."
1279 :group 'anything-config)
1281 (defface anything-grep-lineno
1282 '((t (:foreground "Darkorange1")))
1283 "Face used to highlight grep number lines."
1284 :group 'anything-config)
1286 (defface anything-grep-running
1287 '((t (:foreground "Red")))
1288 "Face used in mode line when grep is running."
1289 :group 'anything-config)
1291 (defface anything-grep-finish
1292 '((t (:foreground "Green")))
1293 "Face used in mode line when grep is finish."
1294 :group 'anything-config)
1296 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1297 "*Face used in anything-M-x to show keybinding."
1298 :group 'anything)
1300 (defface anything-bmkext-info
1301 '((t (:foreground "green")))
1302 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1303 :group 'anything)
1305 (defface anything-bmkext-w3m
1306 '((t (:foreground "yellow")))
1307 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1308 :group 'anything)
1310 (defface anything-bmkext-gnus
1311 '((t (:foreground "magenta")))
1312 "*Face used for Gnus bookmarks."
1313 :group 'anything)
1315 (defface anything-bmkext-man
1316 '((t (:foreground "Orange4")))
1317 "*Face used for Woman/man bookmarks."
1318 :group 'anything)
1320 (defface anything-bmkext-no--file
1321 '((t (:foreground "grey")))
1322 "*Face used for non--file bookmarks."
1323 :group 'anything)
1325 (defface anything-bmkext-file
1326 '((t (:foreground "Deepskyblue2")))
1327 "*Face used for non--file bookmarks."
1328 :group 'anything)
1330 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1331 "Face for su/sudo bookmarks."
1332 :group 'anything)
1334 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1335 "Face for w3m bookmarks" :group 'anything)
1337 (defface anything-emms-playlist
1338 '((t (:foreground "Springgreen4" :underline t)))
1339 "*Face used for tracks in current emms playlist."
1340 :group 'anything)
1342 (defface anything-apt-installed
1343 '((t (:foreground "green")))
1344 "*Face used for apt installed candidates."
1345 :group 'anything)
1347 (defface anything-gentoo-match-face '((t (:foreground "red")))
1348 "Face for anything-gentoo installed packages."
1349 :group 'traverse-faces)
1351 (defface anything-lisp-show-completion
1352 '((t (:background "DarkSlateGray")))
1353 "*Face used for showing candidates in `anything-lisp-completion'."
1354 :group 'anything-config)
1356 (defface anything-lisp-completion-info
1357 '((t (:foreground "red")))
1358 "*Face used for showing info in `anything-lisp-completion'."
1359 :group 'anything-config)
1361 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1362 "Face for source header in the anything buffer." :group 'anything)
1364 ;;;###autoload
1365 (defun anything-configuration ()
1366 "Customize `anything'."
1367 (interactive)
1368 (customize-group "anything-config"))
1372 ;;; Anything-command-map
1375 ;;;###autoload
1376 (defvar anything-command-map)
1377 (define-prefix-command 'anything-command-map)
1380 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1381 (define-key anything-command-map (kbd "a") 'anything-c-apropos)
1382 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1383 (define-key anything-command-map (kbd "l") 'anything-locate)
1384 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1385 (define-key anything-command-map (kbd "r") 'anything-regexp)
1386 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1387 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1388 (define-key anything-command-map (kbd "#") 'anything-emms)
1389 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1390 (define-key anything-command-map (kbd "t") 'anything-top)
1391 (define-key anything-command-map (kbd "i") 'anything-imenu)
1392 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1393 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1394 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1395 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1396 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1397 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1398 (define-key anything-command-map (kbd "f") 'anything-for-files)
1399 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1400 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1401 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1402 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1403 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1404 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1405 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1406 (define-key anything-command-map (kbd "c") 'anything-colors)
1407 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1408 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1409 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1410 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1411 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1412 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1413 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1414 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1415 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1416 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1418 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1419 ;; minibuffer-local-filename-must-match-map.
1420 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1421 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1422 (dolist (map (list minibuffer-local-filename-completion-map
1423 minibuffer-local-completion-map
1424 minibuffer-local-must-match-filename-map
1425 minibuffer-local-filename-must-match-map
1426 minibuffer-local-map
1427 minibuffer-local-isearch-map
1428 minibuffer-local-must-match-map
1429 minibuffer-local-ns-map))
1430 (define-key map "\C-r" 'anything-minibuffer-history))
1434 ;;; Menu
1437 (easy-menu-define nil global-map
1438 "`anything' menu"
1439 '("Anything"
1440 ["All anything commands" anything-execute-anything-command t]
1441 ["Find any Files/Buffers" anything-for-files t]
1442 ["Anything Everywhere" ac-mode t]
1443 "----"
1444 ("Files:"
1445 ["Find files" anything-find-files t]
1446 ["Recent Files" anything-recentf t]
1447 ["Locate" anything-locate t]
1448 ["Bookmarks" anything-c-pp-bookmarks t])
1449 ("Buffers:"
1450 ["Find buffers" anything-buffers-list t])
1451 ("Commands:"
1452 ["Emacs Commands" anything-M-x t]
1453 ["Externals Commands" anything-c-run-external-command t])
1454 ("Help:"
1455 ["Anything Apropos" anything-c-apropos t])
1456 ("Info:"
1457 ["Info at point" anything-info-at-point t]
1458 ["Emacs Manual index" anything-info-emacs t]
1459 ["Gnus Manual index" anything-info-gnus t])
1460 ("Org:"
1461 ["Org keywords" anything-org-keywords t]
1462 ["Org headlines" anything-org-headlines t])
1463 ("Tools:"
1464 ["Occur" anything-occur t]
1465 ["Grep" anything-do-grep t]
1466 ["Etags" anything-c-etags-select t]
1467 ["Lisp complete at point" anything-lisp-completion-at-point t]
1468 ["Browse Kill ring" anything-show-kill-ring t]
1469 ["Browse register" anything-register t]
1470 ["Browse code" anything-browse-code t]
1471 ["Mark Ring" anything-all-mark-rings t]
1472 ["Regexp handler" anything-regexp t]
1473 ["Colors & Faces" anything-colors t]
1474 ["Show xfonts" anything-select-xfont t]
1475 ["Ucs Symbols" anything-ucs t]
1476 ["Imenu" anything-imenu t]
1477 ["Google Suggest" anything-google-suggest t]
1478 ["Eval expression" anything-eval-expression-with-eldoc t]
1479 ["Calcul expression" anything-calcul-expression t]
1480 ["Man pages" anything-man-woman t]
1481 ["Top externals process" anything-top t]
1482 ["Emacs internals process" anything-list-emacs-process t])
1483 "----"
1484 ["Prefered Options" anything-configuration t]))
1486 ;;; Anything map add ons
1489 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1490 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1491 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1494 ;;; Specialized keymaps
1497 (defvar anything-c-buffer-map
1498 (let ((map (copy-keymap anything-map)))
1499 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1500 ;; No need to have separate command for grep and zgrep
1501 ;; as we don't use recursivity for buffers.
1502 ;; So use zgrep for both as it is capable to handle non--compressed files.
1503 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1504 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1505 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1506 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1507 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1508 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1509 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1510 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1511 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1512 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1513 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1514 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1515 (define-key map (kbd "M-a") 'anything-mark-all)
1516 (when (locate-library "elscreen")
1517 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1518 (delq nil map))
1519 "Keymap for buffer sources in anything.")
1521 (defvar anything-find-files-map
1522 (let ((map (copy-keymap anything-map)))
1523 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1524 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1525 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1526 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1527 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1528 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1529 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1530 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1531 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1532 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1533 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1534 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1535 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1536 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1537 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1538 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1539 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1540 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1541 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1542 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1543 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1544 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1545 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1546 (define-key map (kbd "C-c ?") 'anything-ff-help)
1547 (define-key map (kbd "C-}") 'anything-narrow-window)
1548 (define-key map (kbd "C-{") 'anything-enlarge-window)
1549 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1550 (define-key map (kbd "M-a") 'anything-mark-all)
1551 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1552 (define-key map (kbd "M-u") 'anything-unmark-all)
1553 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1554 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1555 ;; Next 2 have no effect if candidate is not an image file.
1556 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1557 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1558 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1559 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1560 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1561 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1562 (when anything-ff-lynx-style-map
1563 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1564 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1565 (delq nil map))
1566 "Keymap for `anything-find-files'.")
1568 (defvar anything-c-read-file-map
1569 (let ((map (copy-keymap anything-map)))
1570 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1571 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1572 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1573 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1574 (when anything-ff-lynx-style-map
1575 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1576 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1577 (define-key map (kbd "<M-left>") 'anything-previous-source)
1578 (define-key map (kbd "<M-right>") 'anything-next-source))
1579 (delq nil map))
1580 "Keymap for `anything-c-read-file-name'.")
1582 (defvar anything-generic-files-map
1583 (let ((map (copy-keymap anything-map)))
1584 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1585 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1586 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1587 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1588 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1589 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1590 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1591 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1592 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1593 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1594 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1595 map)
1596 "Generic Keymap for files.")
1598 (defvar anything-c-grep-map
1599 (let ((map (copy-keymap anything-map)))
1600 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1601 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1602 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1603 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1604 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1605 (when anything-c-grep-use-ioccur-style-keys
1606 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1607 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1608 (define-key map (kbd "C-c ?") 'anything-grep-help)
1609 (delq nil map))
1610 "Keymap used in Grep sources.")
1612 (defvar anything-c-pdfgrep-map
1613 (let ((map (copy-keymap anything-map)))
1614 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1615 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1616 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1617 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1618 map)
1619 "Keymap used in pdfgrep.")
1621 (defvar anything-c-etags-map
1622 (let ((map (copy-keymap anything-map)))
1623 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1624 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1625 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1626 (define-key map (kbd "C-c ?") 'anything-etags-help)
1627 map)
1628 "Keymap used in Etags.")
1630 (defvar anything-eval-expression-map
1631 (let ((map (copy-keymap anything-map)))
1632 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1633 (define-key map (kbd "<tab>") 'lisp-indent-line)
1634 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1635 (define-key map (kbd "C-p") 'previous-line)
1636 (define-key map (kbd "C-n") 'next-line)
1637 (define-key map (kbd "<up>") 'previous-line)
1638 (define-key map (kbd "<down>") 'next-line)
1639 (define-key map (kbd "<right>") 'forward-char)
1640 (define-key map (kbd "<left>") 'backward-char)
1641 map))
1643 (defvar anything-c-ucs-map
1644 (let ((map (copy-keymap anything-map)))
1645 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1646 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1647 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1648 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1649 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1650 map)
1651 "Keymap for `anything-ucs'.")
1655 ;;; Embeded documentation.
1658 (defun anything-c-list-preconfigured-anything ()
1659 "Collect preconfigured anything functions in this file."
1660 (loop with doc
1661 with sym
1662 for entry in (cdr (assoc
1663 (file-truename (locate-library "anything-config"))
1664 load-history))
1665 if (and (consp entry)
1666 (eq (car entry) 'defun)
1667 (string-match "^Preconfigured.+$"
1668 (setq doc (or (documentation (setq sym (cdr entry)))
1669 ""))))
1670 collect (cons sym (match-string 0 doc))))
1672 (defun anything-c-format-preconfigured-anything ()
1673 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1674 (anything-c-list-preconfigured-anything)))
1676 ;;; Global help message - Used by `anything-help'
1679 (setq anything-help-message
1680 (lambda ()
1681 (concat
1682 "\\<anything-map>"
1683 "`anything' is QuickSilver-like candidate-selection framework.
1685 Narrow the list by typing some pattern,
1686 Multiple patterns are allowed by splitting by space.
1687 Select with natural Emacs operations, choose with RET.
1689 If you have any problems, press C-c C-x C-b!!
1690 Feel free to send bug reports. I'll fix them.
1691 The steps are described in the beginning of anything.el file.
1693 == Basic Operations ==
1694 C-p, Up: Previous Line
1695 C-n, Down : Next Line
1696 M-v, PageUp : Previous Page
1697 C-v, PageDown : Next Page
1698 Enter : Execute first (default) action / Select
1699 M-< : First Line
1700 M-> : Last Line
1701 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1702 M-PageDown, C-M-v : Next Page (other-window)
1704 Tab, C-i : Show action list
1705 Left : Previous Source
1706 Right, C-o : Next Source
1707 C-k : Delete pattern
1708 C-z : Persistent Action (Execute action with anything session kept)
1709 C-c C-x C-b: Send a bug report
1711 == Shortcuts For 2nd/3rd Action ==
1712 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1713 \\[anything-select-3rd-action] : Execute 3rd Action
1715 == Visible Marks ==
1716 Visible marks store candidate. Some actions uses marked candidates.
1718 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1719 \\[anything-prev-visible-mark] : Previous Mark
1720 \\[anything-next-visible-mark] : Next Mark
1722 == Miscellaneous Commands ==
1723 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1724 \\[anything-quit-and-find-file] : Drop into `find-file'
1725 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1726 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1727 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1728 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1729 \\[anything-force-update] : Recalculate And Redisplay Candidates
1731 == Global Commands ==
1732 \\<global-map>\\[anything-resume] revives last `anything' session.
1733 It is very useful, so you should bind any key.
1735 Single source is executed by \\[anything-call-source].
1737 == Preconfigured `anything' ==
1738 Preconfigured `anything' is commands that uses `anything' interface.
1739 You can use them without configuration.
1742 (apply 'concat (anything-c-format-preconfigured-anything))
1744 Enjoy!")))
1746 ;;; `anything-buffer-list' help
1749 ;;;###autoload
1750 (defun anything-c-buffer-help ()
1751 "Help command for anything buffers."
1752 (interactive)
1753 (let ((anything-help-message "== Anything Buffer ==
1754 \nTips:
1755 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1756 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1757 \nSpecific commands for `anything-buffers-list':
1758 \\<anything-c-buffer-map>
1759 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1760 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1761 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1762 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1763 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1764 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1765 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1766 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1767 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1768 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1769 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1770 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1771 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1772 \\[anything-mark-all]\t\t->Mark all.
1773 \\[anything-c-buffer-help]\t\t->Display this help.
1774 \n== Anything Map ==
1775 \\{anything-map}
1777 (anything-help)))
1780 ;;; Find files help (`anything-find-files')
1783 ;;;###autoload
1784 (defun anything-ff-help ()
1785 "Help command for `anything-find-files'."
1786 (interactive)
1787 (let ((anything-help-message "== Anything Find Files ==
1788 \nTips:
1789 \n- Enter `~/' at end of pattern to quickly reach home directory.
1790 - Enter `/' at end of pattern to quickly reach root of your file system.
1791 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1792 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1793 - Use `C-u C-z' to watch an image.
1794 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1795 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1797 \nSpecific commands for `anything-find-files':
1798 \\<anything-find-files-map>
1799 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1800 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1801 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1802 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1803 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1804 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1805 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1806 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1807 \\[anything-ff-run-load-file]\t\t->Load File.
1808 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1809 \\[anything-ff-run-delete-file]\t\t->Delete File.
1810 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1811 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1812 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1813 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1814 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1815 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1816 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1817 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1818 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1819 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1820 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1821 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1822 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1823 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1824 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1825 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1826 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1827 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1828 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1829 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1830 \\[anything-narrow-window]\t\t->Narrow anything window.
1831 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1832 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1833 \\[anything-ff-help]\t\t->Display this help info.
1834 \n== Anything Map ==
1835 \\{anything-map}
1837 (anything-help)))
1839 ;;; Help for `anything-c-read-file-name'
1842 ;;;###autoload
1843 (defun anything-read-file-name-help ()
1844 (interactive)
1845 (let ((anything-help-message "== Anything read file name Map ==\
1846 \nSpecific commands for anything-c-read-file-name:
1847 \\<anything-c-read-file-map>
1848 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1849 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1850 \\[anything-next-source]\t\t->Goto next source.
1851 \\[anything-previous-source]\t->Goto previous source.
1852 \\[anything-read-file-name-help]\t\t->Display this help info.
1853 \n== Anything Map ==
1854 \\{anything-map}
1856 (anything-help)))
1858 ;;; Generic file help - Used by locate.
1861 ;;;###autoload
1862 (defun anything-generic-file-help ()
1863 (interactive)
1864 (let ((anything-help-message "== Anything Generic files Map ==\
1865 \nSpecific commands for anything locate and others files sources:
1866 \\<anything-generic-files-map>
1867 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1868 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1869 \\[anything-ff-run-delete-file]\t\t->Delete file.
1870 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1871 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1872 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1873 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1874 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1875 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1876 \nLocate tips:
1877 You can add after writing search pattern any of the locate command line options.
1878 e.g -b, -e, -n <number>...etc.
1879 See Man locate for more infos.
1880 \n== Anything Map ==
1881 \\{anything-map}"))
1882 (anything-help)))
1885 ;;; Grep help
1888 ;;;###autoload
1889 (defun anything-grep-help ()
1890 (interactive)
1891 (let ((anything-help-message "== Anything Grep Map ==\
1892 \nSpecific commands for Grep and Etags:
1893 \\<anything-c-grep-map>
1894 \\[anything-c-goto-next-file]\t->Next File.
1895 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1896 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1897 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1898 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1899 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1900 \\[anything-grep-help]\t\t->Show this help.
1901 \n== Anything Map ==
1902 \\{anything-map}"))
1903 (anything-help)))
1905 ;;; Pdf grep help
1908 ;;;###autoload
1909 (defun anything-pdfgrep-help ()
1910 (interactive)
1911 (let ((anything-help-message "== Anything PdfGrep Map ==\
1912 \nSpecific commands for Pdf Grep:
1913 \\<anything-c-pdfgrep-map>
1914 \\[anything-c-goto-next-file]\t->Next File.
1915 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1916 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1917 \\[anything-pdfgrep-help]\t\t->Show this help.
1918 \n== Anything Map ==
1919 \\{anything-map}"))
1920 (anything-help)))
1922 ;;; Etags help
1925 ;;;###autoload
1926 (defun anything-etags-help ()
1927 "The help function for etags."
1928 (interactive)
1929 (let ((anything-help-message "== Anything Etags Map ==\
1930 \nSpecific commands for Etags:
1931 \\<anything-c-etags-map>
1932 \\[anything-c-goto-next-file]\t->Next File.
1933 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1934 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1935 \\[anything-etags-help]\t\t->Show this help.
1936 \n== Anything Map ==
1937 \\{anything-map}"))
1938 (anything-help)))
1940 ;;; Ucs help
1943 (defun anything-c-ucs-help ()
1944 "Help command for `anything-ucs'."
1945 (interactive)
1946 (let ((anything-help-message "== Anything Ucs ==
1947 \nSpecific commands for `anything-ucs':
1948 \\<anything-c-ucs-map>
1949 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1950 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1951 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1952 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1953 \\[anything-c-ucs-help]\t\t->Show this help.
1955 \n== Anything Map ==
1956 \\{anything-map}
1958 (anything-help)))
1962 ;;; Mode line strings
1965 (defvar anything-buffer-mode-line-string
1966 '("Buffer(s)"
1967 "\\<anything-c-buffer-map>\
1968 \\[anything-c-buffer-help]:Help, \
1969 \\<anything-map>\
1970 \\[anything-select-action]:Acts,\
1971 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1972 \\[anything-select-3rd-action]:NthAct,\
1973 \\[anything-send-bug-report-from-anything]:BugReport."
1974 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1976 (defvar anything-ff-mode-line-string
1977 "\\<anything-find-files-map>\
1978 \\[anything-ff-help]:Help, \
1979 \\[anything-send-bug-report-from-anything]:BugReport, \
1980 \\<anything-map>\
1981 \\[anything-select-action]:Acts, \
1982 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1983 \\[anything-select-3rd-action]:NthAct"
1984 "String displayed in mode-line in `anything-c-source-find-files'")
1986 (defvar anything-read-file-name-mode-line-string
1987 "\\<anything-c-read-file-map>\
1988 \\[anything-read-file-name-help]:Help, \
1989 \\<anything-map>\
1990 \\[anything-select-action]:Acts,\
1991 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1992 \\[anything-select-3rd-action]:NthAct"
1993 "String displayed in mode-line in `anything-c-source-find-files'")
1995 (defvar anything-generic-file-mode-line-string
1996 "\\<anything-generic-files-map>\
1997 \\[anything-generic-file-help]:Help, \
1998 \\<anything-map>\
1999 \\[anything-select-action]:Acts,\
2000 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2001 \\[anything-select-3rd-action]:NthAct,\
2002 \\[anything-send-bug-report-from-anything]:BugReport."
2003 "String displayed in mode-line in Locate.")
2005 (defvar anything-grep-mode-line-string
2006 "\\<anything-c-grep-map>\
2007 \\[anything-grep-help]:Help,\
2008 \\<anything-map>\
2009 \\[anything-select-action]:Acts,\
2010 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2011 \\[anything-select-3rd-action]:NthAct,\
2012 \\[anything-send-bug-report-from-anything]:BugReport."
2013 "String displayed in mode-line in `anything-do-grep'.")
2015 (defvar anything-pdfgrep-mode-line-string
2016 "\\<anything-c-pdfgrep-map>\
2017 \\[anything-pdfgrep-help]:Help,\
2018 \\<anything-map>\
2019 \\[anything-select-action]:Acts,\
2020 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2021 \\[anything-select-3rd-action]:NthAct,\
2022 \\[anything-send-bug-report-from-anything]:BugReport."
2023 "String displayed in mode-line in `anything-do-pdfgrep'.")
2025 (defvar anything-etags-mode-line-string
2026 "\\<anything-c-etags-map>\
2027 \\[anything-etags-help]:Help,\
2028 \\<anything-map>\
2029 \\[anything-select-action]:Acts,\
2030 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2031 \\[anything-select-3rd-action]:NthAct,\
2032 \\[anything-send-bug-report-from-anything]:BugReport."
2033 "String displayed in mode-line in `anything-c-etags-select'.")
2036 (defvar anything-c-ucs-mode-line-string
2037 "\\<anything-c-ucs-map>\
2038 \\[anything-c-ucs-help]:Help, \
2039 \\<anything-map>\
2040 \\[anything-select-action]:Acts,\
2041 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2042 \\[anything-select-3rd-action]:NthAct."
2043 "String displayed in mode-line in `anything-ucs'.")
2047 ;;; Utilities Functions
2050 (defun anything-ff-find-printers ()
2051 "Return a list of available printers on Unix systems."
2052 (let ((printer-list (with-temp-buffer
2053 (call-process "lpstat" nil t nil "-a")
2054 (split-string (buffer-string) "\n"))))
2055 (loop for p in printer-list
2056 for printer = (car (split-string p))
2057 when printer
2058 collect printer)))
2060 ;; Shut up byte compiler in emacs24*.
2061 (defun anything-c-switch-to-buffer (buffer-or-name)
2062 "Same as `switch-to-buffer' whithout warnings at compile time."
2063 (with-no-warnings
2064 (switch-to-buffer buffer-or-name)))
2066 (defsubst* anything-c-position (item seq &key (test 'eq))
2067 "A simple and faster replacement of CL `position'."
2068 (loop for i in seq for index from 0
2069 when (funcall test i item) return index))
2071 (defun anything-c-get-pid-from-process-name (process-name)
2072 "Get pid from running process PROCESS-NAME."
2073 (loop with process-list = (list-system-processes)
2074 for pid in process-list
2075 for process = (assoc-default 'comm (process-attributes pid))
2076 when (and process (string-match process-name process))
2077 return pid))
2079 (defun* anything-current-buffer-narrowed-p (&optional
2080 (buffer anything-current-buffer))
2081 "Check if BUFFER is narrowed.
2082 Default is `anything-current-buffer'."
2083 (with-current-buffer buffer
2084 (let ((beg (point-min))
2085 (end (point-max))
2086 (total (buffer-size)))
2087 (or (/= beg 1) (/= end (1+ total))))))
2089 (defun anything-region-active-p ()
2090 (and transient-mark-mode mark-active (/= (mark) (point))))
2092 (defun anything-goto-line (lineno)
2093 "Goto LINENO opening only outline headline if needed."
2094 (goto-char (point-min)) (forward-line (1- lineno))
2095 (when (or (eq major-mode 'org-mode)
2096 (and (boundp 'outline-minor-mode)
2097 outline-minor-mode))
2098 (require 'org) ; On some old Emacs versions org may not be loaded.
2099 (org-reveal))
2100 (anything-match-line-color-current-line) (sit-for 0.3)
2101 (anything-match-line-cleanup))
2103 (defun anything-show-this-source-only ()
2104 "Show all candidates of this source."
2105 (interactive)
2106 (setq anything-candidate-number-limit nil)
2107 (anything-set-source-filter
2108 (list (assoc-default 'name (anything-get-current-source)))))
2110 ;;;###autoload
2111 (defun anything-test-sources ()
2112 "List all anything sources for test.
2113 The output is sexps which are evaluated by \\[eval-last-sexp]."
2114 (interactive)
2115 (with-output-to-temp-buffer "*Anything Test Sources*"
2116 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2117 (apropos-internal "^anything-c-source" #'boundp))
2118 (pop-to-buffer standard-output)))
2120 (defun anything-nest (&rest same-as-anything)
2121 "Nested `anything'. If you use `anything' within `anything', use it."
2122 (with-selected-window (anything-window)
2123 (let (anything-current-position
2124 anything-current-buffer
2125 (orig-anything-buffer anything-buffer)
2126 anything-pattern
2127 anything-buffer
2128 anything-sources
2129 anything-compiled-sources
2130 anything-buffer-chars-modified-tick
2131 (anything-samewindow t)
2132 (enable-recursive-minibuffers t))
2133 (unwind-protect
2134 (apply #'anything same-as-anything)
2135 (anything-initialize-overlays orig-anything-buffer)
2136 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2138 (defun anything-displaying-source-names ()
2139 "Display sources name."
2140 (with-current-buffer anything-buffer
2141 (goto-char (point-min))
2142 (loop with pos
2143 while (setq pos (next-single-property-change (point) 'anything-header))
2144 do (goto-char pos)
2145 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2146 do (forward-line 1))))
2148 ;; [Obsolete]
2149 (defun anything-select-source ()
2150 "[OBSOLETE] Select source."
2151 (interactive)
2152 (let ((default (assoc-default 'name (anything-get-current-source)))
2153 (source-names (anything-displaying-source-names))
2154 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2155 (anything-get-sources))))
2156 (setq anything-candidate-number-limit 9999)
2157 (anything-aif
2158 (let (anything-source-filter)
2159 (anything-nest '(((name . "Anything Source")
2160 (candidates . source-names)
2161 (action . identity))
2162 ((name . "Anything Source (ALL)")
2163 (candidates . all-source-names)
2164 (action . identity)))
2165 nil "Source: " nil
2166 default "*anything select source*"))
2167 (anything-set-source-filter (list it))
2168 (anything-set-source-filter nil))))
2170 (defun anything-c-match-on-file-name (candidate)
2171 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2172 (string-match anything-pattern (file-name-nondirectory candidate)))
2174 (defun anything-c-match-on-directory-name (candidate)
2175 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2176 (anything-aif (file-name-directory candidate)
2177 (string-match anything-pattern it)))
2179 (defun anything-c-match-on-basename (candidate)
2180 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2181 (string-match anything-pattern (anything-c-basename candidate)))
2183 (defun anything-c-string-match (candidate)
2184 "Return non-nil if `anything-pattern' match CANDIDATE.
2185 The match is done with `string-match'."
2186 (string-match anything-pattern candidate))
2188 (defun anything-c-skip-entries (list regexp)
2189 "Remove entries which matches REGEXP from LIST."
2190 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2191 list))
2193 (defun anything-c-shadow-entries (list regexp)
2194 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2195 (mapcar (lambda (file)
2196 ;; Add shadow face property to boring files.
2197 (let ((face (if (facep 'file-name-shadow)
2198 'file-name-shadow
2199 ;; fall back to default on XEmacs
2200 'default)))
2201 (if (string-match regexp file)
2202 (setq file (propertize file 'face face))))
2203 file)
2204 list))
2206 (defsubst anything-c-stringify (str-or-sym)
2207 "Get string of STR-OR-SYM."
2208 (if (stringp str-or-sym)
2209 str-or-sym
2210 (symbol-name str-or-sym)))
2212 (defsubst anything-c-symbolify (str-or-sym)
2213 "Get symbol of STR-OR-SYM."
2214 (if (symbolp str-or-sym)
2215 str-or-sym
2216 (intern str-or-sym)))
2218 (defun anything-c-describe-function (func)
2219 "FUNC is symbol or string."
2220 (describe-function (anything-c-symbolify func)))
2222 (defun anything-c-describe-variable (var)
2223 "VAR is symbol or string."
2224 (describe-variable (anything-c-symbolify var)))
2226 (defun anything-c-find-function (func)
2227 "FUNC is symbol or string."
2228 (find-function (anything-c-symbolify func)))
2230 (defun anything-c-find-variable (var)
2231 "VAR is symbol or string."
2232 (find-variable (anything-c-symbolify var)))
2234 (defun anything-c-kill-new (candidate &optional replace)
2235 "CANDIDATE is symbol or string.
2236 See `kill-new' for argument REPLACE."
2237 (kill-new (anything-c-stringify candidate) replace))
2239 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2240 "Remove duplicates elements in list SEQ.
2241 This is same as `remove-duplicates' but with memoisation.
2242 It is much faster, especially in large lists.
2243 A test function can be provided with TEST argument key.
2244 Default is `eq'."
2245 (let ((cont (make-hash-table :test test)))
2246 (loop for elm in seq
2247 unless (gethash elm cont)
2248 do (puthash elm elm cont)
2249 finally return
2250 (loop for i being the hash-values in cont collect i))))
2252 (defadvice eval-defun (after anything-source-hack activate)
2253 "Allow immediate execution of anything source when evaling it.
2254 See `anything-c-enable-eval-defun-hack'."
2255 (when anything-c-enable-eval-defun-hack
2256 (let ((varsym (save-excursion
2257 (beginning-of-defun)
2258 (forward-char 1)
2259 (when (memq (read (current-buffer)) '(defvar setq))
2260 (read (current-buffer))))))
2261 (when (string-match "^anything-c-source-" (symbol-name varsym))
2262 (anything varsym)))))
2263 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2266 ;; Move this function from anything.el and redefine here
2267 ;; to avoid an unneeded defadvice.
2268 (defun anything-quit-and-find-file ()
2269 "Drop into `anything-find-files' from `anything'.
2270 If current selection is a buffer or a file, `anything-find-files'
2271 from its directory."
2272 (interactive)
2273 (anything-run-after-quit
2274 (lambda (f)
2275 (if (file-exists-p f)
2276 (anything-find-files-1 (file-name-directory f)
2277 (if anything-ff-transformer-show-only-basename
2278 (anything-c-basename f) f))
2279 (anything-find-files-1 f)))
2280 (anything-aif (get-buffer (anything-get-selection))
2281 (or (buffer-file-name it)
2282 (car (rassoc it dired-buffers))
2283 (and (with-current-buffer it
2284 (eq major-mode 'org-agenda-mode))
2285 org-directory
2286 (expand-file-name org-directory))
2287 default-directory)
2288 (let ((sel (anything-get-selection)))
2289 (if (file-exists-p sel)
2290 (expand-file-name sel)
2291 default-directory)))))
2294 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2295 "Walk through DIRECTORY tree.
2296 PATH can be one of basename, relative, or full.
2297 DIRECTORIES when non--nil (default) return also directories names, otherwise
2298 skip directories names.
2299 MATCH match only filenames matching regexp MATCH."
2300 `(let (result
2301 (fn (case ,path
2302 (basename 'file-name-nondirectory)
2303 (relative 'file-relative-name)
2304 (full 'identity)
2305 (t 'file-name-nondirectory))))
2306 (labels ((ls-R (dir)
2307 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2308 for f in ls
2309 if (file-directory-p f)
2310 do (progn (when ,directories
2311 (push (funcall fn f) result))
2312 ;; Don't recurse in directory symlink.
2313 (unless (file-symlink-p f)
2314 (ls-R f)))
2315 else do
2316 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2317 (push (funcall fn f) result)))))
2318 (ls-R ,directory)
2319 (nreverse result))))
2321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2323 ;;; Anything regexp.
2326 (defun anything-c-query-replace-regexp (candidate)
2327 "Query replace regexp from `anything-regexp'.
2328 With a prefix arg replace only matches surrounded by word boundaries,
2329 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2330 (let ((regexp (funcall (anything-attr 'regexp))))
2331 (apply 'query-replace-regexp
2332 (anything-c-query-replace-args regexp))))
2334 (defun anything-c-kill-regexp-as-sexp (candidate)
2335 "Kill regexp in a format usable in lisp code."
2336 (anything-c-regexp-kill-new
2337 (prin1-to-string (funcall (anything-attr 'regexp)))))
2339 (defun anything-c-kill-regexp (candidate)
2340 "Kill regexp as it is in `anything-pattern'."
2341 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2343 (defun anything-c-query-replace-args (regexp)
2344 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2345 (let ((region-only (anything-region-active-p)))
2346 (list
2347 regexp
2348 (query-replace-read-to regexp
2349 (format "Query replace %sregexp %s"
2350 (if anything-current-prefix-arg "word " "")
2351 (if region-only "in region " ""))
2353 anything-current-prefix-arg
2354 (when region-only (region-beginning))
2355 (when region-only (region-end)))))
2357 (defvar anything-c-source-regexp
2358 '((name . "Regexp Builder")
2359 (init . (lambda ()
2360 (anything-candidate-buffer anything-current-buffer)))
2361 (candidates-in-buffer)
2362 (get-line . anything-c-regexp-get-line)
2363 (persistent-action . anything-c-regexp-persistent-action)
2364 (persistent-help . "Show this line")
2365 (multiline)
2366 (delayed)
2367 (requires-pattern . 2)
2368 (mode-line . "Press TAB to select action.")
2369 (regexp . (lambda () anything-input))
2370 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2371 ("Query Replace Regexp (C-u Not inside word.)"
2372 . anything-c-query-replace-regexp)
2373 ("Kill Regexp" . anything-c-kill-regexp)))))
2375 (defun anything-c-regexp-get-line (s e)
2376 (propertize
2377 (apply 'concat
2378 ;; Line contents
2379 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2380 ;; subexps
2381 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2382 collect (format "\n %s'%s'"
2383 (if (zerop i) "Group 0: " (format "Group %d: " i))
2384 (match-string i))))
2385 ;; match beginning
2386 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2387 ;; It is implementation problem of candidates-in-buffer.
2388 'anything-realvalue
2389 (1- s)))
2391 (defun anything-c-regexp-persistent-action (pt)
2392 (goto-char pt)
2393 (anything-persistent-highlight-point))
2395 (defun anything-c-regexp-kill-new (input)
2396 (kill-new input)
2397 (message "Killed: %s" input))
2401 ;;; Toggle all marks.
2404 ;;;###autoload
2405 (defun anything-mark-all ()
2406 "Mark all visible unmarked candidates in current source."
2407 (interactive)
2408 (with-anything-window
2409 (save-excursion
2410 (goto-char (anything-get-previous-header-pos))
2411 (anything-next-line)
2412 (let* ((next-head (anything-get-next-header-pos))
2413 (end (and next-head
2414 (save-excursion
2415 (goto-char next-head)
2416 (forward-line -1)
2417 (point))))
2418 (maxpoint (or end (point-max))))
2419 (while (< (point) maxpoint)
2420 (anything-mark-current-line)
2421 (let ((prefix (get-text-property (point-at-bol) 'display))
2422 (bn (anything-c-basename (anything-get-selection)))
2423 (src (assoc-default 'name (anything-get-current-source))))
2424 (when (and (not (anything-this-visible-mark))
2425 (not (or (string= prefix "[?]")
2426 (string= prefix "[@]"))))
2427 ;; Don't mark possibles directories ending with . or ..
2428 ;; and also autosave files/links.
2429 (unless
2430 (and (or (anything-file-completion-source-p)
2431 (equal src "Files from Current Directory"))
2432 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2433 (anything-make-visible-mark))))
2434 (forward-line 1) (end-of-line))))
2435 (anything-mark-current-line)
2436 (message "%s candidates marked" (length anything-marked-candidates))))
2438 ;;;###autoload
2439 (defun anything-unmark-all ()
2440 "Unmark all candidates in all sources of current anything session."
2441 (interactive)
2442 (with-anything-window
2443 (let ((len (length anything-marked-candidates)))
2444 (save-excursion
2445 (anything-clear-visible-mark))
2446 (setq anything-marked-candidates nil)
2447 (anything-mark-current-line)
2448 (message "%s candidates unmarked" len))))
2450 ;;;###autoload
2451 (defun anything-toggle-all-marks ()
2452 "Toggle all marks.
2453 Mark all visible candidates of current source or unmark all candidates
2454 visible or invisible in all sources of current anything session"
2455 (interactive)
2456 (let ((marked (anything-marked-candidates)))
2457 (if (and (>= (length marked) 1)
2458 (with-anything-window anything-visible-mark-overlays))
2459 (anything-unmark-all)
2460 (anything-mark-all))))
2464 ;;; Buffers
2467 (defun anything-c-buffer-list ()
2468 "Return the list of names of buffers with boring buffers filtered out.
2469 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2470 The first buffer in the list will be the last recently used
2471 buffer that is not the current buffer."
2472 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2473 (append (cdr buffers) (list (car buffers)))))
2475 (defvar anything-c-source-buffers
2476 '((name . "Buffers")
2477 (candidates . anything-c-buffer-list)
2478 (type . buffer)))
2479 ;; (anything 'anything-c-source-buffers)
2481 (defvar anything-c-source-buffer-not-found
2482 '((name . "Create buffer")
2483 (dummy)
2484 (filtered-candidate-transformer (lambda (cands source)
2485 (list anything-pattern)))
2486 (action . (lambda (candidate)
2487 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2488 ;; (anything 'anything-c-source-buffer-not-found)
2490 ;;; Buffers-list (was buffers+)
2493 (eval-when-compile (require 'dired))
2495 (defun anything-c-highlight-buffers (buffers)
2496 (loop for i in buffers
2497 for buf = (get-buffer i)
2498 for bfname = (buffer-file-name buf)
2499 collect
2500 (cond (;; A dired buffer.
2501 (rassoc buf dired-buffers)
2502 (propertize i 'face 'anything-ff-directory
2503 'help-echo (car (rassoc buf dired-buffers))))
2504 ;; A buffer file modified somewhere outside of emacs.
2505 ((and bfname (not (file-remote-p bfname))
2506 (file-exists-p bfname)
2507 (not (verify-visited-file-modtime buf)))
2508 (propertize i 'face 'anything-buffer-saved-out
2509 'help-echo bfname))
2510 ;; A new buffer file not already saved on disk.
2511 ((and bfname (not (file-remote-p bfname))
2512 (not (verify-visited-file-modtime buf)))
2513 (propertize i 'face 'anything-buffer-not-saved
2514 'help-echo bfname))
2515 ;; A Remote buffer file modified and not saved on disk.
2516 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2517 (let ((prefix (propertize
2518 " " 'display
2519 (propertize "@ " 'face 'anything-ff-prefix))))
2520 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2521 'help-echo bfname)) i)))
2522 ;; A buffer file modified and not saved on disk.
2523 ((and bfname (buffer-modified-p buf))
2524 (propertize i 'face 'anything-ff-symlink
2525 'help-echo bfname))
2526 ;; A remote buffer file not modified and saved on disk.
2527 ((and bfname (file-remote-p bfname))
2528 (let ((prefix (propertize
2529 " " 'display
2530 (propertize "@ " 'face 'anything-ff-prefix))))
2531 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2532 'help-echo bfname)) i)))
2533 ;; A buffer file not modified and saved on disk.
2534 (bfname
2535 (propertize i 'face 'font-lock-type-face
2536 'help-echo bfname))
2537 ;; Any non--file buffer.
2538 (t (propertize i 'face 'italic)))))
2541 (defvar anything-c-source-buffers-list
2542 '((name . "Buffers")
2543 (candidates . anything-c-buffer-list)
2544 (type . buffer)
2545 (match anything-c-buffer-match-major-mode)
2546 (diff-action . anything-buffer-toggle-diff)
2547 (revert-action . anything-buffer-revert-and-update)
2548 (save-action . anything-buffer-save-and-update)
2549 (candidate-transformer anything-c-skip-current-buffer
2550 anything-c-skip-boring-buffers
2551 anything-c-highlight-buffers)
2552 (persistent-action . anything-c-buffers-list-persistent-action)
2553 (volatile)
2554 (mode-line . anything-buffer-mode-line-string)
2555 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2556 ;; (anything 'anything-c-source-buffers-list)
2558 (defun anything-c-buffer-match-major-mode (candidate)
2559 "Match maybe buffer by major-mode.
2560 If you give a major-mode or partial major-mode,
2561 it will list all buffers of this major-mode and/or buffers with name
2562 matching this major-mode.
2563 If you add a space after major-mode and then a space,
2564 it will match all buffers of the major-mode
2565 before space matching pattern after space.
2566 If you give a pattern which doesn't match a major-mode, it will search buffer
2567 with name matching pattern."
2568 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2569 (buf (get-buffer cand)))
2570 (when buf
2571 (with-current-buffer buf
2572 (let ((mjm (symbol-name major-mode))
2573 (split (split-string anything-pattern)))
2574 (cond ((string-match "\\s-$" anything-pattern)
2575 (string-match (car split) mjm))
2576 ((string-match "\\s-" anything-pattern)
2577 (and (string-match (car split) mjm)
2578 (string-match (cadr split) cand)))
2579 (t (or (string-match anything-pattern mjm)
2580 (string-match anything-pattern cand)))))))))
2582 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2583 "Query replace in marked buffers.
2584 If REGEXP-FLAG is given use `query-replace-regexp'."
2585 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2586 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2587 (bufs (anything-marked-candidates)))
2588 (loop
2589 with replace = (query-replace-read-from prompt regexp-flag)
2590 with tostring = (unless (consp replace)
2591 (query-replace-read-to
2592 replace prompt regexp-flag))
2593 for buf in bufs
2595 (save-window-excursion
2596 (anything-c-switch-to-buffer buf)
2597 (save-excursion
2598 (let ((case-fold-search t))
2599 (goto-char (point-min))
2600 (if (consp replace)
2601 (apply fn (list (car replace) (cdr replace)))
2602 (apply fn (list replace tostring)))))))))
2604 (defun anything-c-buffer-query-replace-regexp (candidate)
2605 (anything-c-buffer-query-replace-1 'regexp))
2607 (defun anything-c-buffer-query-replace (candidate)
2608 (anything-c-buffer-query-replace-1))
2610 (defun anything-buffer-toggle-diff (candidate)
2611 "Toggle diff buffer CANDIDATE with it's file."
2612 (if (get-buffer-window "*Diff*")
2613 (kill-buffer "*Diff*")
2614 (diff-buffer-with-file (get-buffer candidate))))
2616 ;;;###autoload
2617 (defun anything-buffer-diff-persistent ()
2618 "Toggle diff buffer without quitting anything."
2619 (interactive)
2620 (anything-execute-persistent-action 'diff-action))
2622 (defun anything-buffer-revert-and-update (candidate)
2623 (let ((marked (anything-marked-candidates)))
2624 (loop for buf in marked do (anything-revert-buffer buf))
2625 (anything-force-update)
2626 (anything-c-recenter-window)))
2628 ;;;###autoload
2629 (defun anything-buffer-revert-persistent ()
2630 "Revert buffer without quitting anything."
2631 (interactive)
2632 (anything-execute-persistent-action 'revert-action 'onewindow))
2634 (defun anything-buffer-save-and-update (candidate)
2635 (let ((marked (anything-marked-candidates))
2636 (enable-recursive-minibuffers t))
2637 (loop for buf in marked do
2638 (with-current-buffer (get-buffer buf)
2639 (save-buffer)))
2640 (anything-force-update)
2641 (anything-c-recenter-window)))
2643 ;;;###autoload
2644 (defun anything-buffer-save-persistent ()
2645 "Save buffer without quitting anything."
2646 (interactive)
2647 (anything-execute-persistent-action 'save-action 'onewindow))
2649 ;;;###autoload
2650 (defun anything-buffer-run-kill-buffers ()
2651 "Run kill buffer action from `anything-c-source-buffers-list'."
2652 (interactive)
2653 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2655 ;;;###autoload
2656 (defun anything-buffer-run-grep ()
2657 "Run Grep action from `anything-c-source-buffers-list'."
2658 (interactive)
2659 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2661 ;;;###autoload
2662 (defun anything-buffer-run-zgrep ()
2663 "Run Grep action from `anything-c-source-buffers-list'."
2664 (interactive)
2665 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2667 ;;;###autoload
2668 (defun anything-buffer-run-query-replace-regexp ()
2669 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2670 (interactive)
2671 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2673 ;;;###autoload
2674 (defun anything-buffer-run-query-replace ()
2675 "Run Query replace action from `anything-c-source-buffers-list'."
2676 (interactive)
2677 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2679 ;;;###autoload
2680 (defun anything-buffer-switch-other-window ()
2681 "Run switch to other window action from `anything-c-source-buffers-list'."
2682 (interactive)
2683 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2685 ;;;###autoload
2686 (defun anything-buffer-switch-other-frame ()
2687 "Run switch to other frame action from `anything-c-source-buffers-list'."
2688 (interactive)
2689 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2691 ;;;###autoload
2692 (defun anything-buffer-switch-to-elscreen ()
2693 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2694 (interactive)
2695 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2697 ;;;###autoload
2698 (defun anything-buffer-run-ediff ()
2699 "Run ediff action from `anything-c-source-buffers-list'."
2700 (interactive)
2701 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2703 (defun anything-buffer-run-ediff-merge ()
2704 "Run ediff action from `anything-c-source-buffers-list'."
2705 (interactive)
2706 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2708 (defun anything-c-buffers-persistent-kill (buffer)
2709 "Persistent action to kill buffer."
2710 (with-current-buffer (get-buffer buffer)
2711 (if (and (buffer-modified-p)
2712 (buffer-file-name (current-buffer)))
2713 (progn
2714 (save-buffer)
2715 (kill-buffer buffer))
2716 (kill-buffer buffer)))
2717 (anything-delete-current-selection))
2719 (defun anything-c-recenter-window ()
2720 "Make visible current selection by recentering anything window."
2721 (with-anything-window (recenter)))
2723 (defun anything-c-buffers-list-persistent-action (candidate)
2724 (if current-prefix-arg
2725 (anything-c-buffers-persistent-kill candidate)
2726 (anything-c-switch-to-buffer candidate)))
2729 ;;;; <File>
2732 ;;; File name history
2733 (defvar anything-c-source-file-name-history
2734 '((name . "File Name History")
2735 (candidates . file-name-history)
2736 (match anything-c-match-on-basename)
2737 (type . file)))
2738 ;; (anything 'anything-c-source-file-name-history)
2740 ;;; Files in current dir
2743 (defvar anything-c-source-files-in-current-dir
2744 '((name . "Files from Current Directory")
2745 (candidates . (lambda ()
2746 (with-anything-current-buffer
2747 (directory-files (anything-c-current-directory)))))
2748 ;; volatile is not needed, I think.
2749 (type . file)))
2750 ;; (anything 'anything-c-source-files-in-current-dir)
2752 (defun anything-c-highlight-files (files)
2753 (loop for i in files
2754 if (file-directory-p i)
2755 collect (propertize (file-name-nondirectory i)
2756 'face 'anything-ff-directory
2757 'help-echo (expand-file-name i))
2758 else
2759 collect (propertize (file-name-nondirectory i)
2760 'face 'anything-ff-file
2761 'help-echo (expand-file-name i))))
2763 (defvar anything-c-source-files-in-current-dir+
2764 '((name . "Files from Current Directory")
2765 (candidates . (lambda ()
2766 (with-anything-current-buffer
2767 (directory-files (anything-c-current-directory) t))))
2768 (candidate-transformer anything-c-highlight-files)
2769 ;; volatile is not needed, I think.
2770 (type . file)))
2771 ;; (anything 'anything-c-source-files-in-current-dir+)
2775 ;;; Anything-find-files - The anything files browser.
2778 ;; Internal.
2779 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2780 "*The doc that is inserted in the Name header of a find-files or dired source.")
2781 (defvar anything-ff-auto-update-flag nil
2782 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2783 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2784 (defvar anything-ff-last-expanded nil
2785 "Store last expanded directory or file.")
2786 (defvar anything-ff-default-directory nil)
2787 (defvar anything-ff-history nil)
2788 (defvar anything-ff-cand-to-mark nil)
2791 (defvar anything-c-source-find-files
2792 `((name . "Find Files")
2793 (header-name . (lambda (name)
2794 (concat name anything-c-find-files-doc-header)))
2795 ;; It is needed for filenames with capital letters
2796 (disable-shortcuts)
2797 (init . (lambda ()
2798 (setq anything-ff-auto-update-flag
2799 anything-ff-auto-update-initial-value)))
2800 (candidates . anything-find-files-get-candidates)
2801 (filtered-candidate-transformer anything-c-find-files-transformer)
2802 (image-action1 . anything-ff-rotate-image-left)
2803 (image-action2 . anything-ff-rotate-image-right)
2804 (toggle-basename . anything-ff-toggle-basename)
2805 (properties-action . anything-ff-properties)
2806 (toggle-auto-update . anything-ff-toggle-auto-update)
2807 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2808 (persistent-action . anything-find-files-persistent-action)
2809 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2810 (mode-line . anything-ff-mode-line-string)
2811 (volatile)
2812 (candidate-number-limit . 9999)
2813 (action-transformer . anything-find-files-action-transformer)
2814 (action
2815 . ,(delq
2817 `(("Find File" . anything-c-find-file-or-marked)
2818 ("Find file in Dired" . anything-c-point-file-in-dired)
2819 ,(and (locate-library "elscreen")
2820 '("Find file in Elscreen" . anything-elscreen-find-file))
2821 ,(and (locate-library "popwin")
2822 '("Find file in popup window" . popwin:find-file))
2823 ("Checksum File" . anything-ff-checksum)
2824 ("Complete at point `M-tab'"
2825 . anything-c-insert-file-name-completion-at-point)
2826 ("Open file externally `C-c C-x, C-u to choose'"
2827 . anything-c-open-file-externally)
2828 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2829 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2830 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2831 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2832 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2833 . anything-find-files-eshell-command-on-file)
2834 ("Find file as root" . anything-find-file-as-root)
2835 ("Find file in hex dump" . hexl-find-file)
2836 ("Ediff File `C-='" . anything-find-files-ediff-files)
2837 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2838 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2839 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2840 ("Copy file(s) Async" . anything-ff-copy-async)
2841 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2842 ("Serial rename files" . anything-ff-serial-rename)
2843 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2844 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2845 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2846 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2847 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2848 ("Find file other window `C-o'" . find-file-other-window)
2849 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2850 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2851 ("Print File `C-c p'" . anything-ff-print)
2852 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2853 ;; (anything 'anything-c-source-find-files)
2855 (defun anything-find-files-set-prompt-for-action (prompt files)
2856 "Set prompt for action in `anything-find-files'."
2857 (let ((len (length files)))
2858 (if (> len 1)
2859 (format "%s * %d Files to: " prompt len)
2860 (format "%s %s to: " prompt (car files)))))
2862 (defun anything-dwim-target-directory ()
2863 "Return value of `default-directory' of buffer in other window.
2864 If there is only one window return the value ot `default-directory'
2865 for current buffer."
2866 (with-anything-current-buffer
2867 (let ((num-windows (length (window-list))))
2868 (if (> num-windows 1)
2869 (save-window-excursion
2870 (other-window 1)
2871 default-directory)
2872 (car anything-ff-history)))))
2874 (defun anything-find-files-do-action (action)
2875 "Generic function for creating action from `anything-c-source-find-files'.
2876 ACTION must be an action supported by `anything-dired-action'."
2877 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2878 (anything-marked-candidates)))
2879 (cand (anything-get-selection)) ; Target
2880 (prompt (anything-find-files-set-prompt-for-action
2881 (capitalize (symbol-name action)) ifiles))
2882 (parg anything-current-prefix-arg)
2883 (dest (anything-c-read-file-name
2884 prompt
2885 :preselect (if anything-ff-transformer-show-only-basename
2886 (anything-c-basename cand) cand)
2887 :initial-input (anything-dwim-target-directory)
2888 :history (anything-find-files-history :comp-read nil))))
2889 (let ((default-directory anything-ff-default-directory))
2890 (anything-dired-action
2891 dest :files ifiles :action action :follow parg))))
2893 (defun anything-find-files-copy (candidate)
2894 "Copy files from `anything-find-files'."
2895 (anything-find-files-do-action 'copy))
2897 (defun anything-find-files-rename (candidate)
2898 "Rename files from `anything-find-files'."
2899 (anything-find-files-do-action 'rename))
2901 (defun anything-find-files-symlink (candidate)
2902 "Symlink files from `anything-find-files'."
2903 (anything-find-files-do-action 'symlink))
2905 (defun anything-find-files-relsymlink (candidate)
2906 "Relsymlink files from `anything-find-files'."
2907 (anything-find-files-do-action 'relsymlink))
2909 (defun anything-find-files-hardlink (candidate)
2910 "Hardlink files from `anything-find-files'."
2911 (anything-find-files-do-action 'hardlink))
2913 (defun anything-find-files-byte-compile (candidate)
2914 "Byte compile elisp files from `anything-find-files'."
2915 (let ((files (anything-marked-candidates))
2916 (parg anything-current-prefix-arg))
2917 (loop for fname in files
2918 do (byte-compile-file fname parg))))
2920 (defun anything-find-files-load-files (candidate)
2921 "Load elisp files from `anything-find-files'."
2922 (let ((files (anything-marked-candidates)))
2923 (loop for fname in files
2924 do (load fname))))
2926 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2927 "Generic function to ediff/merge files in `anything-find-files'."
2928 (let ((bname (anything-c-basename candidate))
2929 (prompt (if merge "Ediff Merge `%s' With File: "
2930 "Ediff `%s' With File: "))
2931 (fun (if merge 'ediff-merge-files 'ediff-files)))
2932 (funcall fun
2933 candidate
2934 (condition-case quit
2935 (anything-c-read-file-name
2936 (format prompt bname))
2937 (quit ;; Hit C-g ask user to fallback to locate.
2938 (if (y-or-n-p "Search file for ediff with locate? ")
2939 (anything-c-locate-read-file-name
2940 (format prompt bname)
2941 ;; Check if -b option is available.
2942 (if (and (eq system-type 'windows-nt)
2943 (string-match "^es" anything-c-locate-command))
2944 bname
2945 (concat bname " -b")))
2946 (error "Error: Ediff Operation aborted")))))))
2948 (defun anything-find-files-ediff-files (candidate)
2949 (anything-find-files-ediff-files-1 candidate))
2951 (defun anything-find-files-ediff-merge-files (candidate)
2952 (anything-find-files-ediff-files-1 candidate 'merge))
2954 (defun anything-find-files-grep (candidate)
2955 "Default action to grep files from `anything-find-files'."
2956 (anything-do-grep-1 (anything-marked-candidates)
2957 anything-current-prefix-arg))
2959 (defun anything-ff-zgrep (candidate)
2960 "Default action to zgrep files from `anything-find-files'."
2961 (let ((prefarg anything-current-prefix-arg)
2962 (ls (anything-marked-candidates)))
2963 (anything-ff-zgrep-1 ls prefarg)))
2965 (defun anything-ff-pdfgrep (candidate)
2966 "Default action to pdfgrep files from `anything-find-files'."
2967 (let ((cands (loop for file in (anything-marked-candidates)
2968 if (or (string= (file-name-extension file) "pdf")
2969 (string= (file-name-extension file) "PDF"))
2970 collect file))
2971 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2972 (when cands
2973 (anything-do-pdfgrep-1 cands))))
2975 (defun anything-ff-etags-select (candidate)
2976 "Default action to jump to etags from `anything-find-files'."
2977 (when (get-buffer anything-action-buffer)
2978 (kill-buffer anything-action-buffer))
2979 (let ((default-directory anything-ff-default-directory))
2980 (anything-c-etags-select anything-current-prefix-arg)))
2982 (defun anything-find-files-switch-to-hist (candidate)
2983 "Switch to anything-find-files history."
2984 (anything-find-files t))
2986 ;;; Asynchronous copy of files.
2989 (defun anything-c-copy-files-async-1 (flist dest)
2990 "Copy a list of Files FLIST to DEST asynchronously.
2991 It use another emacs process to do the job.
2992 Communication with background emacs is done with temp file
2993 `anything-c-copy-files-async-log-file'."
2994 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
2995 "-Q" "--batch" "--eval"
2996 (format "(progn
2997 (require 'dired) (require 'cl)
2998 (let ((dired-recursive-copies 'always)
2999 failures success
3000 (ovw-count 0)
3001 (cpf-count 0))
3002 (dolist (f '%S)
3003 (condition-case err
3004 (let ((file-exists (file-exists-p
3005 (expand-file-name
3006 (file-name-nondirectory (directory-file-name f))
3007 (file-name-directory
3008 (file-name-as-directory \"%s\"))))))
3009 (dired-copy-file f \"%s\" t)
3010 (if file-exists
3011 (progn (push (cons \"Overwriting\" f) success)
3012 (incf ovw-count))
3013 (push (cons \"Copying\" f) success)
3014 (incf cpf-count)))
3015 (file-error
3016 (push (dired-make-relative
3017 (expand-file-name
3018 (file-name-nondirectory (directory-file-name f))
3019 (file-name-directory \"%s\")))
3020 failures))))
3021 (with-current-buffer (find-file-noselect \"%s\")
3022 (erase-buffer)
3023 (when failures
3024 (dolist (fail (reverse failures))
3025 (insert (concat \"Failed to copy \" fail \"\n\"))))
3026 (when success
3027 (loop for (a . s) in (reverse success) do
3028 (insert (concat a \" \" s \" to %s done\n\"))))
3029 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3030 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3031 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3032 (save-buffer))))"
3033 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3035 (defun anything-c-copy-async-with-log (flist dest)
3036 "Copy file list FLIST to DEST showing log.
3037 Log is send to `anything-c-copy-files-async-log-file'.
3038 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3039 (declare (special auto-revert-interval))
3040 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3041 (set (make-local-variable 'auto-revert-interval) 1)
3042 (erase-buffer)
3043 (insert "Wait copying files...\n")
3044 (sit-for 0.5) (save-buffer)
3045 (goto-char (point-max))
3046 (auto-revert-mode 1)
3047 (anything-c-copy-files-async-1 flist dest))
3049 (defun anything-ff-copy-async (candidate)
3050 "Anything find files action to copy files async.
3051 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3052 (let ((flist (anything-marked-candidates))
3053 (dest (anything-c-read-file-name
3054 "Copy File(s) async To: "
3055 :preselect candidate
3056 :initial-input (car anything-ff-history)
3057 :history (anything-find-files-history :comp-read nil))))
3058 (anything-c-copy-async-with-log flist dest)))
3060 (defvar eshell-command-aliases-list nil)
3061 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3062 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3064 Basename of CANDIDATE can be a wild-card.
3065 If MAP is given run `eshell-command' on all marked files at once,
3066 Otherwise, run `eshell-command' on each marked files.
3068 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3069 `eshell-command-aliases-list' will not be loaded first time you use this."
3070 (when (or eshell-command-aliases-list
3071 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3072 (and eshell-command-aliases-list (eshell-read-aliases-list))
3073 (let* ((cand-list (anything-marked-candidates))
3074 (default-directory (or anything-ff-default-directory
3075 ;; If candidate is an url *-ff-default-directory is nil
3076 ;; so keep value of default-directory.
3077 default-directory))
3078 (command (anything-comp-read
3079 "Command: "
3080 (loop for (a . c) in eshell-command-aliases-list
3081 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3082 collect (propertize a 'help-echo (car c)) into ls
3083 finally return (sort ls 'string<))))
3084 (com-value (car (assoc-default command eshell-command-aliases-list))))
3085 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3086 (> (length cand-list) 1))
3087 ;; Run eshell-command with ALL marked files as arguments.
3088 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3089 (eshell-command (format "%s %s" command mapfiles)))
3090 ;; Run eshell-command on EACH marked files.
3091 (loop
3092 for i in cand-list
3093 for bn = (anything-c-basename i)
3094 for files = (if (and bn (string-match "^\*" bn))
3095 ;; Assume if fname is a wildcard
3096 ;; cand-list have a length of 1.
3097 (mapconcat
3098 'shell-quote-argument
3099 (file-expand-wildcards i t) " ")
3100 (format "'%s'" i))
3101 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3102 ;; This allow to enter other args AFTER filename
3103 ;; i.e <command %s some_more_args>
3104 (format command files)
3105 (format "%s %s" command files))
3106 do (eshell-command com))))))
3108 (defun anything-find-files-eshell-command-on-file (candidate)
3109 "Run `eshell-command' on CANDIDATE or marked candidates.
3110 See `anything-find-files-eshell-command-on-file-1' for more info."
3111 (anything-find-files-eshell-command-on-file-1
3112 candidate anything-current-prefix-arg))
3114 (defun anything-ff-switch-to-eshell (candidate)
3115 "Switch to eshell and cd to `anything-ff-default-directory'."
3116 (flet ((cd-eshell ()
3117 (goto-char (point-max))
3118 (insert
3119 (format "cd '%s'" anything-ff-default-directory))
3120 (eshell-send-input)))
3121 (if (get-buffer "*eshell*")
3122 (progn
3123 (anything-c-switch-to-buffer "*eshell*")
3124 (cd-eshell))
3125 (call-interactively 'eshell)
3126 (cd-eshell))))
3128 (defun anything-ff-serial-rename-action (method)
3129 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3130 See `anything-ff-serial-rename-1'."
3131 (let* ((cands (anything-marked-candidates))
3132 (name (read-string "NewName: "))
3133 (start (read-number "StartAtNumber: "))
3134 (extension (read-string "Extension: " (file-name-extension (car cands))))
3135 (dir (expand-file-name
3136 (anything-c-read-file-name
3137 "Serial Rename to directory: " :initial-input
3138 (expand-file-name anything-ff-default-directory)))))
3139 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3140 (length cands) dir name))
3141 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3142 (anything-find-files-1 dir))))
3144 (defun anything-ff-member-directory-p (file directory)
3145 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3146 (cur-dir (expand-file-name (file-name-as-directory directory))))
3147 (string= dir-file cur-dir)))
3149 (defun* anything-ff-serial-rename-1
3150 (directory collection new-name start-at-num extension &key (method 'rename))
3151 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3152 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3153 EXTENSION is the file extension to use, in empty prompt,
3154 reuse the original extension of file.
3155 METHOD can be one of rename, copy or symlink.
3156 Files will be renamed if they are files of current directory, otherwise they
3157 will be treated with METHOD.
3158 Default METHOD is rename."
3159 ;; Maybe remove directories selected by error in collection.
3160 (setq collection (remove-if 'file-directory-p collection))
3161 (flet ((symlink-file (file dest)
3162 (let ((flist (list file)))
3163 (anything-dired-action
3164 dest :action 'symlink :files flist))))
3166 (let* ((tmp-dir (file-name-as-directory
3167 (concat (file-name-as-directory directory)
3168 (symbol-name (gensym "tmp")))))
3169 (fn (case method
3170 (copy 'copy-file)
3171 (symlink 'symlink-file)
3172 (rename 'rename-file)
3173 (t (error "Error: Unknow method %s" method)))))
3174 (make-directory tmp-dir)
3175 (loop for i in collection
3176 for count from start-at-num
3177 for fnum = (if (< count 10) "0%s" "%s")
3178 for nname = (concat tmp-dir new-name (format fnum count)
3179 (if (not (string= extension ""))
3180 (format ".%s" (replace-regexp-in-string
3181 "[.]" "" extension))
3182 (file-name-extension i 'dot)))
3183 do (if (anything-ff-member-directory-p i directory)
3184 (rename-file i nname)
3185 (funcall fn i nname)))
3186 (loop with dirlist = (directory-files
3187 tmp-dir t directory-files-no-dot-files-regexp)
3188 for f in dirlist do
3189 (if (file-symlink-p f)
3190 (symlink-file (file-truename f)
3191 (concat (file-name-as-directory directory)
3192 (anything-c-basename f)))
3193 (rename-file f directory)))
3194 (delete-directory tmp-dir t))))
3196 (defun anything-ff-serial-rename (candidate)
3197 "Serial rename all marked files to `anything-ff-default-directory'.
3198 Rename only file of current directory, and symlink files coming from
3199 other directories.
3200 See `anything-ff-serial-rename-1'."
3201 (anything-ff-serial-rename-action 'rename))
3203 (defun anything-ff-serial-rename-by-symlink (candidate)
3204 "Serial rename all marked files to `anything-ff-default-directory'.
3205 Rename only file of current directory, and symlink files coming from
3206 other directories.
3207 See `anything-ff-serial-rename-1'."
3208 (anything-ff-serial-rename-action 'symlink))
3210 (defun anything-ff-serial-rename-by-copying (candidate)
3211 "Serial rename all marked files to `anything-ff-default-directory'.
3212 Rename only file of current directory, and copy files coming from
3213 other directories.
3214 See `anything-ff-serial-rename-1'."
3215 (anything-ff-serial-rename-action 'copy))
3217 (defun anything-c-quit-and-execute-action (action)
3218 "Quit current anything session and execute ACTION."
3219 (setq anything-saved-action action)
3220 (anything-exit-minibuffer))
3222 (defun anything-ff-toggle-auto-update (candidate)
3223 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3224 (message "[Auto expansion %s]"
3225 (if anything-ff-auto-update-flag "enabled" "disabled")))
3227 ;;;###autoload
3228 (defun anything-ff-run-toggle-auto-update ()
3229 (interactive)
3230 (anything-execute-persistent-action 'toggle-auto-update))
3232 ;;;###autoload
3233 (defun anything-ff-run-switch-to-history ()
3234 "Run Switch to history action from `anything-c-source-find-files'."
3235 (interactive)
3236 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3238 ;;;###autoload
3239 (defun anything-ff-run-grep ()
3240 "Run Grep action from `anything-c-source-find-files'."
3241 (interactive)
3242 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3244 ;;;###autoload
3245 (defun anything-ff-run-pdfgrep ()
3246 "Run Pdfgrep action from `anything-c-source-find-files'."
3247 (interactive)
3248 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3250 ;;;###autoload
3251 (defun anything-ff-run-zgrep ()
3252 "Run Grep action from `anything-c-source-find-files'."
3253 (interactive)
3254 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3256 ;;;###autoload
3257 (defun anything-ff-run-copy-file ()
3258 "Run Copy file action from `anything-c-source-find-files'."
3259 (interactive)
3260 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3262 ;;;###autoload
3263 (defun anything-ff-run-rename-file ()
3264 "Run Rename file action from `anything-c-source-find-files'."
3265 (interactive)
3266 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3268 ;;;###autoload
3269 (defun anything-ff-run-byte-compile-file ()
3270 "Run Byte compile file action from `anything-c-source-find-files'."
3271 (interactive)
3272 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3274 ;;;###autoload
3275 (defun anything-ff-run-load-file ()
3276 "Run Load file action from `anything-c-source-find-files'."
3277 (interactive)
3278 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3280 ;;;###autoload
3281 (defun anything-ff-run-eshell-command-on-file ()
3282 "Run eshell command on file action from `anything-c-source-find-files'."
3283 (interactive)
3284 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3286 ;;;###autoload
3287 (defun anything-ff-run-ediff-file ()
3288 "Run Ediff file action from `anything-c-source-find-files'."
3289 (interactive)
3290 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3292 ;;;###autoload
3293 (defun anything-ff-run-ediff-merge-file ()
3294 "Run Ediff merge file action from `anything-c-source-find-files'."
3295 (interactive)
3296 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3298 ;;;###autoload
3299 (defun anything-ff-run-symlink-file ()
3300 "Run Symlink file action from `anything-c-source-find-files'."
3301 (interactive)
3302 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3304 ;;;###autoload
3305 (defun anything-ff-run-delete-file ()
3306 "Run Delete file action from `anything-c-source-find-files'."
3307 (interactive)
3308 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3310 ;;;###autoload
3311 (defun anything-ff-run-complete-fn-at-point ()
3312 "Run complete file name action from `anything-c-source-find-files'."
3313 (interactive)
3314 (anything-c-quit-and-execute-action
3315 'anything-c-insert-file-name-completion-at-point))
3317 ;;;###autoload
3318 (defun anything-ff-run-switch-to-eshell ()
3319 "Run switch to eshell action from `anything-c-source-find-files'."
3320 (interactive)
3321 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3323 ;;;###autoload
3324 (defun anything-ff-run-switch-other-window ()
3325 "Run switch to other window action from `anything-c-source-find-files'."
3326 (interactive)
3327 (anything-c-quit-and-execute-action 'find-file-other-window))
3329 ;;;###autoload
3330 (defun anything-ff-run-switch-other-frame ()
3331 "Run switch to other frame action from `anything-c-source-find-files'."
3332 (interactive)
3333 (anything-c-quit-and-execute-action 'find-file-other-frame))
3335 ;;;###autoload
3336 (defun anything-ff-run-open-file-externally ()
3337 "Run open file externally command action from `anything-c-source-find-files'."
3338 (interactive)
3339 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3341 (defun anything-ff-locate (candidate)
3342 "Locate action function for `anything-find-files'."
3343 (let ((input (concat (anything-c-basename
3344 (expand-file-name
3345 candidate
3346 anything-ff-default-directory))
3347 ;; The locate '-b' option doesn't exists
3348 ;; in everything.
3349 (unless (and (eq system-type 'windows-nt)
3350 (string-match "^es" anything-c-locate-command))
3351 " -b")))
3352 (anything-mp-highlight-delay 0.7))
3353 (anything-locate-1 anything-current-prefix-arg input)))
3355 ;;;###autoload
3356 (defun anything-ff-run-locate ()
3357 "Run locate action from `anything-c-source-find-files'."
3358 (interactive)
3359 (anything-c-quit-and-execute-action 'anything-ff-locate))
3361 ;;;###autoload
3362 (defun anything-ff-run-gnus-attach-files ()
3363 "Run gnus attach files command action from `anything-c-source-find-files'."
3364 (interactive)
3365 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3367 ;;;###autoload
3368 (defun anything-ff-run-etags ()
3369 "Run Etags command action from `anything-c-source-find-files'."
3370 (interactive)
3371 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3374 (defun anything-ff-print (candidate)
3375 "Print marked files.
3376 You have to set in order
3377 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3379 e.g:
3380 \(setq lpr-command \"gtklp\"\)
3381 \(setq lpr-switches '(\"-P\")\)
3382 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3384 Same as `dired-do-print' but for anything."
3385 (let* ((file-list (anything-marked-candidates))
3386 (len (length file-list))
3387 (printer-name (if anything-ff-printer-list
3388 (anything-comp-read
3389 "Printer: " anything-ff-printer-list)
3390 printer-name))
3391 (command (read-string
3392 (format "Print *%s File(s):\n%s with: "
3394 (mapconcat
3395 (lambda (f) (format "- %s\n" f))
3396 file-list ""))
3397 (when (and lpr-command
3398 (or lpr-switches
3399 printer-name))
3400 (mapconcat 'identity
3401 (cons lpr-command
3402 (append (if (stringp lpr-switches)
3403 (list lpr-switches)
3404 lpr-switches)
3405 (list printer-name)))
3406 " "))))
3407 (file-args (mapconcat #'(lambda (x)
3408 (format "'%s'" x))
3409 file-list " "))
3410 (cmd-line (concat command " " file-args)))
3411 (if command
3412 (start-process-shell-command "anything-print" nil cmd-line)
3413 (error "Error: Please verify your printer settings in Emacs."))))
3415 ;;;###autoload
3416 (defun anything-ff-run-print-file ()
3417 "Run Print file action from `anything-c-source-find-files'."
3418 (interactive)
3419 (anything-c-quit-and-execute-action 'anything-ff-print))
3421 (defun anything-ff-checksum (file)
3422 "Calculate the checksum of FILE.
3423 Provide completion on different algorithms to use on Emacs24.
3424 On Emacs23 only 'sha1' is available.
3425 The checksum is copied to kill-ring."
3426 (let ((algo-list (and (fboundp 'secure-hash)
3427 '(md5 sha1 sha224 sha256 sha384 sha512))))
3428 (kill-new
3429 (if algo-list
3430 (secure-hash (intern
3431 (anything-comp-read
3432 "Algorithm: " algo-list))
3433 file)
3434 (sha1 (with-temp-buffer
3435 (insert-file-contents file)
3436 (buffer-string)))))
3437 (message "Checksum copied to kill-ring.")))
3439 (defun anything-ff-toggle-basename (candidate)
3440 (setq anything-ff-transformer-show-only-basename
3441 (not anything-ff-transformer-show-only-basename))
3442 (save-excursion
3443 (anything-force-update)))
3445 (defun anything-ff-run-toggle-basename ()
3446 (interactive)
3447 (anything-execute-persistent-action 'toggle-basename))
3449 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3450 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3451 If LEVEL is positive reduce from end else from beginning.
3452 If UNIX-CLOSE is non--nil close filename with /.
3453 If EXPAND is non--nil expand-file-name."
3454 (let* ((exp-fname (expand-file-name fname))
3455 (fname-list (split-string (if (or (string= fname "~/") expand)
3456 exp-fname fname) "/" t))
3457 (len (length fname-list))
3458 (pop-list (if (< level 0)
3459 (subseq fname-list (* level -1))
3460 (subseq fname-list 0 (- len level))))
3461 (result (mapconcat 'identity pop-list "/"))
3462 (empty (string= result "")))
3463 (when unix-close (setq result (concat result "/")))
3464 (if (string-match "^~" result)
3465 (if (string= result "~/") "~/" result)
3466 (if (< level 0)
3467 (if empty "../" (concat "../" result))
3468 (cond ((eq system-type 'windows-nt)
3469 (if empty "c:/" result))
3470 (empty "/")
3472 (concat "/" result)))))))
3474 ;; Internal
3475 (defvar anything-file-completion-sources
3476 '("Find Files" "find-file" "Copy Files"
3477 "dired-do-copy" "dired-do-rename"
3478 "dired-do-symlink" "dired-do-hardlink"
3479 "write-file" "insert-file" "dired"
3480 "find-alternate-file" "find-alternate-file-other-window"
3481 "find-file-read-only" "list-directory"
3482 "Read File Name History"
3483 "Rename Files" "Symlink Files"
3484 "Hardlink Files" "Write File"
3485 "Insert File" "Read File Name")
3486 "Sources that use the *find-files mechanism can be added here.
3487 You should not modify this yourself and know what you do if you do so.")
3489 (defun anything-file-completion-source-p ()
3490 "Test if current source is a dired or find-files source."
3491 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3492 (loop for i in anything-file-completion-sources
3493 thereis (string= cur-source i))))
3495 (defun anything-find-files-down-one-level (arg)
3496 "Go down one level like unix command `cd ..'.
3497 If prefix numeric arg is given go ARG level down."
3498 (interactive "p")
3499 (when (and (anything-file-completion-source-p)
3500 (not (anything-ff-invalid-tramp-name-p)))
3501 (with-anything-window
3502 (setq anything-follow-mode nil))
3503 ;; When going to precedent level we want to be at the line
3504 ;; corresponding to actual directory, so store this info
3505 ;; in `anything-ff-last-expanded'.
3506 (if (and (not (file-directory-p anything-pattern))
3507 (file-exists-p anything-pattern))
3508 (setq anything-ff-last-expanded anything-pattern)
3509 (setq anything-ff-last-expanded anything-ff-default-directory))
3510 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3511 :unix-close t :expand t)))
3512 (anything-set-pattern new-pattern))))
3514 (defun anything-ff-retrieve-last-expanded ()
3515 "Move overlay to last visited directory `anything-ff-last-expanded'.
3516 This happen after using `anything-find-files-down-one-level',
3517 or hitting C-z on \"..\"."
3518 (when (and anything-ff-last-expanded
3519 (anything-file-completion-source-p))
3520 (let ((dirname (if anything-ff-transformer-show-only-basename
3521 (anything-c-basename
3522 (directory-file-name anything-ff-last-expanded))
3523 (directory-file-name anything-ff-last-expanded))))
3524 (with-anything-window
3525 (when (or (re-search-forward (concat dirname "$") nil t)
3526 (re-search-forward
3527 (concat anything-ff-last-expanded "$") nil t))
3528 (forward-line 0)
3529 (anything-mark-current-line)))
3530 (setq anything-ff-last-expanded nil))))
3531 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3533 ;; Auto-update - anything-find-files auto expansion of directories.
3535 (defun anything-ff-update-when-only-one-matched ()
3536 "Expand to directory when sole completion.
3537 When only one candidate is remaining and it is a directory,
3538 expand to this directory."
3539 (when (and anything-ff-auto-update-flag
3540 (anything-file-completion-source-p)
3541 (not (anything-ff-invalid-tramp-name-p)))
3542 (let* ((history-p (string= (assoc-default
3543 'name (anything-get-current-source))
3544 "Read File Name History"))
3545 (pat (if (string-match tramp-file-name-regexp
3546 anything-pattern)
3547 (anything-create-tramp-name anything-pattern)
3548 anything-pattern))
3549 (completed-p (string= (file-name-as-directory pat)
3550 anything-ff-default-directory)))
3551 (when (and (or
3552 ;; Only one candidate remaining
3553 ;; and at least 2 char in basename.
3554 (and (<= (anything-approximate-candidate-number) 2)
3555 (>= (length (anything-c-basename anything-pattern)) 2))
3556 ;; Already completed.
3557 completed-p)
3558 (not history-p)) ; Don't try to auto complete in history.
3559 (with-anything-window
3560 (let ((cur-cand (prog2
3561 (unless completed-p
3562 ;; Only one non--existing candidate
3563 ;; and one directory candidate, move to it.
3564 (anything-next-line))
3565 (anything-get-selection))))
3566 (when (file-directory-p cur-cand)
3567 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3568 ;; Maybe we are here because completed-p is true
3569 ;; but check this again to be sure. (Windows fix)
3570 (<= (anything-approximate-candidate-number) 2)) ; [2]
3571 ;; If after going to next line the candidate
3572 ;; is not one of "." or ".." [1]
3573 ;; and only one candidate is remaining [2],
3574 ;; assume candidate is a new directory to expand, and do it.
3575 (anything-set-pattern (file-name-as-directory cur-cand))
3576 ;; The candidate is one of "." or ".."
3577 ;; that mean we have entered the last letter of the directory name
3578 ;; in prompt, so expansion is already done, just add the "/" at end
3579 ;; of name unless anything-pattern ends with "."
3580 ;; (i.e we are writing something starting with ".")
3581 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3582 (anything-set-pattern
3583 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3584 (expand-file-name (file-name-as-directory anything-pattern)))))
3585 (anything-check-minibuffer-input-1))))))))
3586 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3588 ;; Allow expanding to home directory or root
3589 ;; when entering respectively "~/" or "//" at end of pattern.
3590 ;; e.g /home/thierry/labo/anything-config-qp/~/
3591 ;; will expand to "~/"
3592 ;; and /home/thierry/labo/anything-config-qp//
3593 ;; will expand to "/"
3594 (defun anything-ff-auto-expand-to-home-or-root ()
3595 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3596 This happen only in function using sources that are
3597 `anything-file-completion-source-p' compliant."
3598 (when (and (anything-file-completion-source-p)
3599 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3600 anything-pattern))
3601 (let ((match (match-string 1 anything-pattern)))
3602 (cond ((string= match "//")
3603 (if (eq system-type 'windows-nt)
3604 (setq anything-pattern "c:/")
3605 (setq anything-pattern "/")))
3606 ((string= match "/~/")
3607 (if (eq system-type 'windows-nt)
3608 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3609 (setq anything-pattern "~/")))
3610 ((string= match "/./")
3611 (setq anything-pattern
3612 (with-anything-current-buffer
3613 (expand-file-name default-directory))))))
3614 (setq anything-ff-default-directory anything-pattern)
3615 ;; For some reasons, i must use here with-current-buffer => mini buffer
3616 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3617 (with-current-buffer (window-buffer (minibuffer-window))
3618 (delete-minibuffer-contents)
3619 (insert anything-pattern))))
3621 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3623 (defun anything-c-point-file-in-dired (file)
3624 "Put point on filename FILE in dired buffer."
3625 (dired (file-name-directory file))
3626 (dired-goto-file file))
3628 (defun anything-create-tramp-name (fname)
3629 "Build filename for `anything-pattern' like /su:: or /sudo::."
3630 (apply #'tramp-make-tramp-file-name
3631 (loop with v = (tramp-dissect-file-name fname)
3632 for i across v collect i)))
3634 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3635 "Get a list of hosts for tramp method found in `anything-pattern'.
3636 Argument PATTERN default to `anything-pattern', it is here only for debugging
3637 purpose."
3638 (when (string-match tramp-file-name-regexp pattern)
3639 (let ((method (match-string 1 pattern))
3640 (tn (match-string 0 pattern))
3641 (all-methods (mapcar 'car tramp-methods)))
3642 (remove-duplicates
3643 (loop for (f . h) in (tramp-get-completion-function method)
3644 append (loop for e in (funcall f (car h))
3645 for host = (and (consp e) (cadr e))
3646 when (and host (not (member host all-methods)))
3647 collect (concat tn host)))
3648 :test 'equal))))
3650 (defun anything-ff-before-action-hook-fn ()
3651 "Exit anything when user try to execute action on an invalid tramp fname."
3652 (let ((cand (anything-get-selection)))
3653 (when (and (anything-file-completion-source-p)
3654 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3655 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3656 (error "Error: Unknow file or directory `%s'" cand))))
3657 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3659 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3660 "Return non--nil when PATTERN is an invalid tramp filename."
3661 (string= (anything-ff-set-pattern pattern)
3662 "Invalid tramp file name"))
3664 (defun anything-ff-set-pattern (pattern)
3665 "Handle tramp filenames in `anything-pattern'."
3666 (let ((methods (mapcar 'car tramp-methods))
3667 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3668 cur-method tramp-name)
3669 (cond ((string= pattern "") "")
3670 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3671 (with-anything-current-buffer
3672 (expand-file-name default-directory)))
3673 ((string-match ".*\\(~//\\|//\\)$" pattern)
3674 (if (eq system-type 'windows-nt) "c:/" "/"))
3675 ((string-match "^~\\|.*/~/$" pattern)
3676 (let* ((home (expand-file-name (getenv "HOME"))))
3677 (replace-match home nil t pattern)))
3678 ;; Match "/method:maybe_hostname:"
3679 ((and (string-match reg pattern)
3680 (setq cur-method (match-string 1 pattern))
3681 (member cur-method methods))
3682 (setq tramp-name (anything-create-tramp-name
3683 (match-string 0 pattern)))
3684 (replace-match tramp-name nil t pattern))
3685 ;; Match "/hostname:"
3686 ((and (string-match tramp-file-name-regexp pattern)
3687 (setq cur-method (match-string 1 pattern))
3688 (and cur-method (not (member cur-method methods))))
3689 (setq tramp-name (anything-create-tramp-name
3690 (match-string 0 pattern)))
3691 (replace-match tramp-name nil t pattern))
3692 ;; Match "/method:" in this case don't try to connect.
3693 ((and (not (string-match reg pattern))
3694 (string-match tramp-file-name-regexp pattern)
3695 (member (match-string 1 pattern) methods))
3696 "Invalid tramp file name") ; Write in anything-buffer.
3697 ;; PATTERN is a directory, end it with "/".
3698 ;; This will make PATTERN not ending yet with "/"
3699 ;; candidate for `anything-ff-default-directory',
3700 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3701 ;; when descending level.
3702 ((file-directory-p pattern)
3703 (file-name-as-directory pattern))
3704 ;; Return PATTERN unchanged.
3705 (t pattern))))
3707 (defun anything-find-files-get-candidates ()
3708 "Create candidate list for `anything-c-source-find-files'."
3709 (let* ((path (anything-ff-set-pattern anything-pattern))
3710 (path-name-dir (if (file-directory-p path)
3711 (file-name-as-directory path)
3712 (file-name-directory path)))
3713 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3714 (set-text-properties 0 (length path) nil path)
3715 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3716 ;; like that the actual value (e.g /ssh:) is passed to
3717 ;; `anything-ff-tramp-hostnames'.
3718 (unless (string= path "Invalid tramp file name")
3719 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3720 (setq anything-ff-default-directory
3721 (if (string= anything-pattern "")
3722 (if (eq system-type 'windows-nt) "c:/" "/")
3723 (unless (string-match ffap-url-regexp path)
3724 ;; If path is an url *default-directory have to be nil.
3725 path-name-dir)))
3726 (cond ((string= path "Invalid tramp file name")
3727 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3728 (prog2
3729 ;; `anything-pattern' have not been modified yet.
3730 ;; Set it here to the value of `path' that should be now
3731 ;; "Invalid tramp file name" and set the candidates list
3732 ;; to ("Invalid tramp file name") to make `anything-pattern'
3733 ;; match single candidate "Invalid tramp file name".
3734 (setq anything-pattern path)
3735 ;; "Invalid tramp file name" is now printed
3736 ;; in `anything-buffer'.
3737 (list path))))
3738 ((or (file-regular-p path)
3739 (and (not (file-exists-p path)) (string-match "/$" path))
3740 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3741 (list path))
3742 ((string= path "") (directory-files "/" t))
3743 ((and (file-directory-p path) (not (file-readable-p path)))
3744 (list (format "Opening directory: access denied, `%s'" path)))
3745 ((file-directory-p path) (directory-files path t))
3747 (append (list path) (directory-files path-name-dir t))))))
3749 (defun anything-ff-transform-fname-for-completion (fname)
3750 "Return FNAME with it's basename modified as a regexp.
3751 e.g foo => f.*o.*o .
3752 If basename contain one or more space or FNAME is a valid directory name
3753 return FNAME unchanged."
3754 (let ((bn (anything-c-basename fname)))
3755 (if (or (not anything-ff-smart-completion)
3756 (string-match "\\s-" bn)
3757 (string-match "/$" fname) ; Allow mkdir.
3758 (file-directory-p fname))
3759 fname ; Fall back to match-plugin.
3760 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3761 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3762 (concat (file-name-directory fname) bn))))
3764 (defun anything-ff-save-history ()
3765 "Store the last value of `anything-ff-default-directory' \
3766 in `anything-ff-history'."
3767 (when (and anything-ff-default-directory
3768 (anything-file-completion-source-p))
3769 (push anything-ff-default-directory anything-ff-history)))
3770 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3772 (defun anything-ff-valid-symlink-p (file)
3773 (file-exists-p (file-truename file)))
3775 (defun anything-ff-properties (candidate)
3776 "Show file properties of CANDIDATE in a tooltip or message."
3777 (let ((type (anything-ff-attributes candidate :type t))
3778 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3779 (if (window-system)
3780 (tooltip-show
3781 (concat
3782 (anything-c-basename candidate) ": \n"
3783 "Type: " type "\n"
3784 (when (string= type "symlink")
3785 (format "True name: '%s'\n"
3786 (cond ((string-match "^\.#" (anything-c-basename candidate))
3787 "Autosave symlink")
3788 ((anything-ff-valid-symlink-p candidate)
3789 (file-truename candidate))
3790 (t "Invalid Symlink"))))
3791 dired-line))
3792 (message dired-line) (sit-for 5))))
3794 ;;;###autoload
3795 (defun anything-ff-properties-persistent ()
3796 "Show properties without quitting anything."
3797 (interactive)
3798 (anything-execute-persistent-action 'properties-action))
3800 (defun anything-ff-kill-buffer-fname (candidate)
3801 (let* ((buf (get-file-buffer candidate))
3802 (buf-name (buffer-name buf)))
3803 (if buf
3804 (progn
3805 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3806 (message "No buffer to kill"))))
3808 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3809 "Find file CANDIDATE or kill it's buffer if it is visible.
3810 Never kill `anything-current-buffer'.
3811 Never kill buffer modified.
3812 This is called normally on third hit of \
3813 \\<anything-map>\\[anything-execute-persistent-action]
3814 in `anything-find-files-persistent-action'."
3815 (let* ((buf (get-file-buffer candidate))
3816 (buf-name (buffer-name buf)))
3817 (if (and buf (get-buffer-window buf)
3818 (not (eq buf (get-buffer anything-current-buffer)))
3819 (not (buffer-modified-p buf)))
3820 (progn
3821 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3822 (find-file candidate))))
3824 ;;;###autoload
3825 (defun anything-ff-run-kill-buffer-persistent ()
3826 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3827 (interactive)
3828 (anything-execute-persistent-action 'kill-buffer-fname))
3830 (defun anything-ff-human-size (size)
3831 "Return a string showing SIZE of a file in human readable form.
3832 SIZE can be an integer or a float depending it's value.
3833 `file-attributes' will take care of that to avoid overflow error.
3834 KBSIZE if a floating point number, default value is 1024.0."
3835 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3836 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3837 (K (cons "K" (/ size anything-ff-default-kbsize)))
3838 (B (cons "B" size)))
3839 (loop with result = B
3840 for (a . b) in
3841 (loop for (x . y) in (list M G K B)
3842 unless (< y 1) collect (cons x y))
3843 when (< b (cdr result)) do (setq result (cons a b))
3844 finally return (if (string= (car result) "B")
3845 (format "%s" size)
3846 (format "%.1f%s" (cdr result) (car result))))))
3848 (defun* anything-ff-attributes
3849 (file &key type links uid gid access-time modif-time
3850 status size mode gid-change inode device-num dired human-size)
3851 "Easy interface for `file-attributes'."
3852 (let ((all (destructuring-bind
3853 (type links uid gid access-time modif-time
3854 status size mode gid-change inode device-num)
3855 (file-attributes file 'string)
3856 (list :type type
3857 :links links
3858 :uid uid
3859 :gid gid
3860 :access-time access-time
3861 :modif-time modif-time
3862 :status status
3863 :size size
3864 :mode mode
3865 :gid-change gid-change
3866 :inode inode
3867 :device-num device-num))))
3868 (cond (type
3869 (let ((result (getf all :type)))
3870 (cond ((stringp result)
3871 "symlink")
3872 (result "directory")
3873 (t "file"))))
3874 (links (getf all :links))
3875 (uid (getf all :uid))
3876 (gid (getf all :gid))
3877 (access-time
3878 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3879 (modif-time
3880 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3881 (status
3882 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3883 (size (if human-size (anything-ff-human-size (getf all :size))
3884 (getf all :size)))
3885 (mode (getf all :mode))
3886 (gid-change (getf all :gid-change))
3887 (inode (getf all :inode))
3888 (device-num (getf all :device-num))
3889 (dired
3890 (concat
3891 (getf all :mode) " "
3892 (number-to-string (getf all :links)) " "
3893 (getf all :uid) ":"
3894 (getf all :gid) " "
3895 (if human-size (anything-ff-human-size (getf all :size))
3896 (int-to-string (getf all :size))) " "
3897 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3898 (t all))))
3900 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3901 "Return filename FNAME maybe prefixed with [?] or [@].
3902 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3903 existing filename or valid symlink and there is no need to test it.
3904 NEW-FILE when non--nil mean FNAME is a non existing file and
3905 return FNAME prefixed with [?]."
3906 (let* ((prefix-new (propertize
3907 " " 'display
3908 (propertize "[?]" 'face 'anything-ff-prefix)))
3909 (prefix-url (propertize
3910 " " 'display
3911 (propertize "[@]" 'face 'anything-ff-prefix))))
3912 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3913 ((string-match ffap-url-regexp fname)
3914 (concat prefix-url " " fname))
3915 ((or new-file (not (file-exists-p fname)))
3916 (concat prefix-new " " fname)))))
3918 (defun anything-c-find-files-transformer (files sources)
3919 "Transformer for `anything-c-source-find-files'.
3920 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3921 is non--nil."
3922 (if (and (string-match tramp-file-name-regexp anything-pattern)
3923 anything-ff-tramp-not-fancy)
3924 (if anything-ff-transformer-show-only-basename
3925 (loop for i in files collect
3926 (if (string-match "[.]\\{1,2\\}$" i)
3927 i (cons (anything-c-basename i) i)))
3928 files)
3929 (anything-ff-highlight-files files sources)))
3931 (defun anything-ff-highlight-files (files sources)
3932 "Candidate transformer for `anything-c-source-find-files' without icons."
3933 (loop for i in files
3934 for disp = (if (and anything-ff-transformer-show-only-basename
3935 (not (string-match "[.]\\{1,2\\}$" i))
3936 (not (string-match ffap-url-regexp i)))
3937 (anything-c-basename i) i)
3938 collect
3939 (cond ((and (stringp (car (file-attributes i)))
3940 (not (anything-ff-valid-symlink-p i))
3941 (not (string-match "^\.#" (anything-c-basename i))))
3942 (cons (anything-ff-prefix-filename
3943 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3945 ((stringp (car (file-attributes i)))
3946 (cons (anything-ff-prefix-filename
3947 (propertize disp 'face 'anything-ff-symlink) t)
3949 ((eq t (car (file-attributes i)))
3950 (cons (anything-ff-prefix-filename
3951 (propertize disp 'face 'anything-ff-directory) t)
3953 ((file-executable-p i)
3954 (cons (anything-ff-prefix-filename
3955 (propertize disp 'face 'anything-ff-executable) t)
3957 ((file-exists-p i)
3958 (cons (anything-ff-prefix-filename
3959 (propertize disp 'face 'anything-ff-file) t)
3962 (cons (anything-ff-prefix-filename
3963 (propertize disp 'face 'anything-ff-file) nil 'new-file)
3964 i)))))
3966 (defun anything-find-files-action-transformer (actions candidate)
3967 "Action transformer for `anything-c-source-find-files'."
3968 (cond ((with-anything-current-buffer
3969 (eq major-mode 'message-mode))
3970 (append (subseq actions 0 4)
3971 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
3972 (subseq actions 4)))
3973 ((string-match (image-file-name-regexp) candidate)
3974 (append (subseq actions 0 4)
3975 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
3976 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
3977 (subseq actions 4)))
3978 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
3979 (car it) candidate))
3980 (append (subseq actions 0 4)
3981 '(("Byte compile lisp file(s) `M-B, C-u to load'"
3982 . anything-find-files-byte-compile)
3983 ("Load File(s) `M-L'" . anything-find-files-load-files))
3984 (subseq actions 4)))
3985 ((and (string-match "\.html?$" candidate)
3986 (file-exists-p candidate))
3987 (append (subseq actions 0 4)
3988 '(("Browse url file" . browse-url-of-file))
3989 (subseq actions 5)))
3990 ((or (string= (file-name-extension candidate) "pdf")
3991 (string= (file-name-extension candidate) "PDF"))
3992 (append (subseq actions 0 4)
3993 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
3994 (subseq actions 5)))
3995 (t actions)))
3997 (defun anything-ff-gnus-attach-files (candidate)
3998 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
3999 (let ((flist (anything-marked-candidates)))
4000 (gnus-dired-attach flist)))
4002 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4003 "Rotate current image at NUM-ARG degrees.
4004 This is a destructive operation on FILE made by external tool mogrify."
4005 (declare (special image-dired-display-image-buffer))
4006 (setq file (file-truename file)) ; For symlinked images.
4007 ;; When FILE is not an image-file, do nothing.
4008 (when (string-match (image-file-name-regexp) file)
4009 (if (executable-find "mogrify")
4010 (progn
4011 (shell-command (format "mogrify -rotate %s %s"
4012 (or num-arg 90)
4013 (shell-quote-argument file)))
4014 (when (buffer-live-p image-dired-display-image-buffer)
4015 (kill-buffer image-dired-display-image-buffer))
4016 (image-dired-display-image file)
4017 (message nil)
4018 (display-buffer (get-buffer image-dired-display-image-buffer)))
4019 (error "mogrify not found"))))
4021 (defun anything-ff-rotate-image-left (candidate)
4022 "Rotate image file CANDIDATE left.
4023 This affect directly file CANDIDATE."
4024 (anything-ff-rotate-current-image-1 candidate -90))
4026 (defun anything-ff-rotate-image-right (candidate)
4027 "Rotate image file CANDIDATE right.
4028 This affect directly file CANDIDATE."
4029 (anything-ff-rotate-current-image-1 candidate))
4031 (defun anything-ff-rotate-left-persistent ()
4032 "Rotate image left without quitting anything."
4033 (interactive)
4034 (anything-execute-persistent-action 'image-action1))
4036 (defun anything-ff-rotate-right-persistent ()
4037 "Rotate image right without quitting anything."
4038 (interactive)
4039 (anything-execute-persistent-action 'image-action2))
4041 (defun anything-ff-exif-data (candidate)
4042 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4043 (if (and anything-ff-exif-data-program
4044 (executable-find anything-ff-exif-data-program))
4045 (shell-command-to-string (format "%s %s %s"
4046 anything-ff-exif-data-program
4047 anything-ff-exif-data-program-args
4048 candidate))
4049 (format "No program %s found to extract exif"
4050 anything-ff-exif-data-program)))
4052 (defun anything-find-files-persistent-action (candidate)
4053 "Open subtree CANDIDATE without quitting anything.
4054 If CANDIDATE is not a directory expand CANDIDATE filename.
4055 If CANDIDATE is alone, open file CANDIDATE filename.
4056 That's mean:
4057 First hit on C-z expand CANDIDATE second hit open file.
4058 If a prefix arg is given or `anything-follow-mode' is on open file."
4059 (let ((follow (buffer-local-value
4060 'anything-follow-mode
4061 (get-buffer-create anything-buffer)))
4062 (new-pattern (anything-get-selection))
4063 (num-lines-buf (with-current-buffer anything-buffer
4064 (count-lines (point-min) (point-max)))))
4065 (flet ((insert-in-minibuffer (fname)
4066 (with-selected-window (minibuffer-window)
4067 (unless follow
4068 (delete-minibuffer-contents)
4069 (set-text-properties 0 (length fname) nil fname)
4070 (insert fname)))))
4071 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4072 "Invalid tramp file name")
4073 (string-match tramp-file-name-regexp candidate))
4074 (insert-in-minibuffer candidate))
4075 (;; A symlink directory, expand it's truename.
4076 (and (file-directory-p candidate) (file-symlink-p candidate))
4077 (insert-in-minibuffer (file-name-as-directory
4078 (file-truename
4079 (expand-file-name candidate)))))
4080 ;; A directory, open it.
4081 ((file-directory-p candidate)
4082 (when (string= (anything-c-basename candidate) "..")
4083 (setq anything-ff-last-expanded anything-ff-default-directory))
4084 (insert-in-minibuffer (file-name-as-directory
4085 (expand-file-name candidate))))
4086 ;; A symlink file, expand to it's true name. (first hit)
4087 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4088 (insert-in-minibuffer (file-truename candidate)))
4089 ;; A regular file, expand it, (first hit)
4090 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4091 (insert-in-minibuffer new-pattern))
4092 ;; An image file and it is the second hit on C-z,
4093 ;; show the file in `image-dired'.
4094 ((string-match (image-file-name-regexp) candidate)
4095 (when (buffer-live-p image-dired-display-image-buffer)
4096 (kill-buffer image-dired-display-image-buffer))
4097 (image-dired-display-image candidate)
4098 (message nil)
4099 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4100 (with-current-buffer image-dired-display-image-buffer
4101 (let ((exif-data (anything-ff-exif-data candidate)))
4102 (image-dired-update-property 'help-echo exif-data))))
4103 ;; Allow browsing archive on avfs fs.
4104 ;; Assume volume is already mounted with mountavfs.
4105 ((and anything-ff-avfs-directory
4106 (string-match
4107 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4108 (file-name-directory candidate))
4109 (anything-ff-file-compressed-p candidate))
4110 (insert-in-minibuffer (concat candidate "#")))
4111 ;; On second hit we open file.
4112 ;; On Third hit we kill it's buffer maybe.
4114 (anything-ff-kill-or-find-buffer-fname candidate))))))
4116 (defun anything-ff-file-compressed-p (candidate)
4117 "Whether CANDIDATE is a compressed file or not."
4118 (member (file-name-extension candidate)
4119 anything-ff-file-compressed-list))
4121 (defun anything-c-insert-file-name-completion-at-point (candidate)
4122 "Insert file name completion at point."
4123 (with-anything-current-buffer
4124 (if buffer-read-only
4125 (error "Error: Buffer `%s' is read-only" (buffer-name))
4126 (let* ((end (point))
4127 (guess (substring-no-properties (thing-at-point 'filename)))
4128 (beg (- (point) (length guess)))
4129 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4130 (string-match-p "^[^\~]" guess))))
4131 (set-text-properties 0 (length candidate) nil candidate)
4132 (if (and guess (not (string= guess ""))
4133 (string-match-p "^~\\|/.*" guess))
4134 (progn
4135 (delete-region beg end)
4136 (insert (if full-path-p
4137 (expand-file-name candidate)
4138 (abbreviate-file-name candidate))))
4139 (error "Aborting completion: No valid file name at point"))))))
4141 (defun* anything-find-files-history (&key (comp-read t))
4142 "The `anything-find-files' history.
4143 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
4144 in an `anything-comp-read'."
4145 (let ((history (when anything-ff-history
4146 (loop with dup for i in anything-ff-history
4147 ;; Remove duplicate and not existing files.
4148 ;; Keep remote files.
4149 unless (or (member i dup)
4150 (and (not (file-remote-p i))
4151 (not (file-exists-p i))))
4152 collect i into dup
4153 finally return dup)))) ; Remove dups.
4154 (when history
4155 (setq anything-ff-history
4156 (if (>= (length history) anything-ff-history-max-length)
4157 (subseq history 0 anything-ff-history-max-length)
4158 history))
4159 (if comp-read
4160 (anything-comp-read
4161 "Switch to Directory: "
4162 anything-ff-history
4163 :name "Anything Find Files History"
4164 :must-match t)
4165 anything-ff-history))))
4167 (defun anything-find-files-1 (fname &optional preselect)
4168 "Find FNAME with `anything' completion.
4169 Like `find-file' but with `anything' support.
4170 Use it for non--interactive calls of `anything-find-files'."
4171 (when (get-buffer anything-action-buffer)
4172 (kill-buffer anything-action-buffer))
4173 (let ((anything-mp-highlight-delay nil)
4174 ;; Be sure we don't erase the precedent minibuffer if some.
4175 (anything-ff-auto-update-initial-value
4176 (not (minibuffer-window-active-p (minibuffer-window))))
4177 anything-samewindow)
4178 (anything :sources 'anything-c-source-find-files
4179 :input fname
4180 :preselect preselect
4181 :keymap anything-find-files-map
4182 :prompt "Find Files or Url: "
4183 :buffer "*Anything Find Files*")))
4186 (defun anything-find-files-initial-input (&optional input)
4187 "Return INPUT if present, otherwise try to guess it."
4188 (or (and input (expand-file-name input))
4189 (anything-find-files-input
4190 (ffap-guesser)
4191 (thing-at-point 'filename))))
4193 (defun anything-find-files-input (fap tap)
4194 "Default input of `anything-find-files'."
4195 (let* ((def-dir (anything-c-current-directory))
4196 (lib (anything-find-library-at-point))
4197 (url (anything-ff-find-url-at-point))
4198 (file-p (and fap (not (string= fap ""))
4199 (file-exists-p fap)
4200 tap (not (string= tap ""))
4201 (file-exists-p
4202 (file-name-directory (expand-file-name tap def-dir))))))
4203 (cond (lib) ; e.g we are inside a require sexp.
4204 (url) ; String at point is an hyperlink.
4205 (file-p (expand-file-name tap def-dir))
4206 (t (and (not (string= fap "")) fap)))))
4208 (defun anything-c-current-directory ()
4209 "Return current-directory name at point.
4210 Useful in dired buffers when there is inserted subdirs."
4211 (if (eq major-mode 'dired-mode)
4212 (dired-current-directory)
4213 default-directory))
4215 (defun anything-ff-find-url-at-point ()
4216 "Try to find link to an url in text-property at point."
4217 (let* ((he (get-text-property (point) 'help-echo))
4218 (ov (overlays-at (point)))
4219 (ov-he (and ov (overlay-get
4220 (car (overlays-at (point))) 'help-echo)))
4221 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4222 (nt-prop (get-text-property (point) 'nt-link)))
4223 ;; Org link.
4224 (when (and (stringp he) (string-match "^LINK: " he))
4225 (setq he (replace-match "" t t he)))
4226 (loop for i in (list he ov-he w3m-l nt-prop)
4227 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4229 (defun anything-find-library-at-point ()
4230 "Try to find library path at point.
4231 Find inside `require' and `declare-function' sexp."
4232 (require 'find-func)
4233 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4234 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4235 (sexp (and beg-sexp end-sexp
4236 (buffer-substring-no-properties
4237 (1+ beg-sexp) (1- end-sexp)))))
4238 (ignore-errors
4239 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4240 (find-library-name
4241 (replace-regexp-in-string
4242 "'\\|\)\\|\(" ""
4243 ;; If require use third arg, ignore it,
4244 ;; always use library path found in `load-path'.
4245 (second (split-string (match-string 0 sexp))))))
4246 ((and sexp (string-match-p "^declare-function" sexp))
4247 (find-library-name
4248 (replace-regexp-in-string
4249 "\"\\|ext:" ""
4250 (third (split-string sexp)))))
4251 (t nil)))))
4253 ;;; Anything completion for `write-file'.==> C-x C-w
4254 (defvar anything-c-source-write-file
4255 `((name . "Write File")
4256 (header-name . (lambda (name)
4257 (concat name anything-c-find-files-doc-header)))
4258 ;; It is needed for filenames with capital letters
4259 (disable-shortcuts)
4260 (candidates . anything-find-files-get-candidates)
4261 (filtered-candidate-transformer anything-c-find-files-transformer)
4262 (persistent-action . anything-find-files-persistent-action)
4263 (persistent-help . "Expand Candidate")
4264 (volatile)
4265 (action .
4266 (("Write File" . (lambda (candidate)
4267 (write-file candidate 'confirm)))))))
4269 ;;; Anything completion for `insert-file'.==> C-x i
4270 (defvar anything-c-source-insert-file
4271 `((name . "Insert File")
4272 (header-name . (lambda (name)
4273 (concat name anything-c-find-files-doc-header)))
4274 ;; It is needed for filenames with capital letters
4275 (disable-shortcuts)
4276 (candidates . anything-find-files-get-candidates)
4277 (filtered-candidate-transformer anything-c-find-files-transformer)
4278 (persistent-action . anything-find-files-persistent-action)
4279 (persistent-help . "Expand Candidate")
4280 (volatile)
4281 (action .
4282 (("Insert File" . (lambda (candidate)
4283 (when (y-or-n-p (format "Really insert %s in %s "
4284 candidate anything-current-buffer))
4285 (insert-file-contents candidate))))))))
4287 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4288 (defvar anything-c-source-copy-files
4289 `((name . "Copy Files")
4290 (header-name . (lambda (name)
4291 (concat name anything-c-find-files-doc-header)))
4292 ;; It is needed for filenames with capital letters
4293 (disable-shortcuts)
4294 (candidates . anything-find-files-get-candidates)
4295 (filtered-candidate-transformer anything-c-find-files-transformer)
4296 (persistent-action . anything-find-files-persistent-action)
4297 (persistent-help . "Expand Candidate")
4298 (volatile)
4299 (action .
4300 (("Copy File"
4301 . (lambda (candidate)
4302 (anything-dired-action candidate :action 'copy)))
4303 ("Copy and Follow"
4304 . (lambda (candidate)
4305 (anything-dired-action candidate :action 'copy :follow t)))))))
4308 (defvar anything-c-source-rename-files
4309 `((name . "Rename Files")
4310 (header-name . (lambda (name)
4311 (concat name anything-c-find-files-doc-header)))
4312 ;; It is needed for filenames with capital letters
4313 (disable-shortcuts)
4314 (candidates . anything-find-files-get-candidates)
4315 (filtered-candidate-transformer anything-c-find-files-transformer)
4316 (persistent-action . anything-find-files-persistent-action)
4317 (persistent-help . "Expand Candidate")
4318 (volatile)
4319 (action .
4320 (("Rename File"
4321 . (lambda (candidate)
4322 (anything-dired-action candidate :action 'rename)))
4323 ("Rename and Follow"
4324 . (lambda (candidate)
4325 (anything-dired-action candidate :action 'rename :follow t)))))))
4327 (defvar anything-c-source-symlink-files
4328 `((name . "Symlink Files")
4329 (header-name . (lambda (name)
4330 (concat name anything-c-find-files-doc-header)))
4331 ;; It is needed for filenames with capital letters
4332 (disable-shortcuts)
4333 (candidates . anything-find-files-get-candidates)
4334 (filtered-candidate-transformer anything-c-find-files-transformer)
4335 (persistent-action . anything-find-files-persistent-action)
4336 (persistent-help . "Expand Candidate")
4337 (volatile)
4338 (action
4339 . (("Symlink File"
4340 . (lambda (candidate)
4341 (anything-dired-action candidate :action 'symlink)))
4342 ("RelSymlink File"
4343 . (lambda (candidate)
4344 (anything-dired-action candidate :action 'relsymlink)))))))
4347 (defvar anything-c-source-hardlink-files
4348 `((name . "Hardlink Files")
4349 (header-name . (lambda (name)
4350 (concat name anything-c-find-files-doc-header)))
4351 ;; It is needed for filenames with capital letters
4352 (disable-shortcuts)
4353 (candidates . anything-find-files-get-candidates)
4354 (filtered-candidate-transformer anything-c-find-files-transformer)
4355 (persistent-action . anything-find-files-persistent-action)
4356 (persistent-help . "Expand Candidate")
4357 (volatile)
4358 (action
4359 . (("Hardlink File"
4360 . (lambda (candidate)
4361 (anything-dired-action candidate :action 'hardlink)))))))
4363 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4364 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4365 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4366 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4367 (let ((fn (case action
4368 ('copy 'dired-copy-file)
4369 ('rename 'dired-rename-file)
4370 ('symlink 'make-symbolic-link)
4371 ('relsymlink 'dired-make-relative-symlink)
4372 ('hardlink 'dired-hardlink)))
4373 (marker (case action
4374 ((copy rename) dired-keep-marker-copy)
4375 ('symlink dired-keep-marker-symlink)
4376 ('relsymlink dired-keep-marker-relsymlink)
4377 ('hardlink dired-keep-marker-hardlink)))
4378 (dirflag (and (= (length files) 1)
4379 (file-directory-p (car files))
4380 (not (file-directory-p candidate)))))
4381 (dired-create-files
4382 fn (symbol-name action) files
4383 ;; CANDIDATE is the destination.
4384 (if (file-directory-p candidate)
4385 ;; When CANDIDATE is a directory, build file-name in this directory.
4386 ;; Else we use CANDIDATE.
4387 #'(lambda (from)
4388 (expand-file-name (file-name-nondirectory from) candidate))
4389 #'(lambda (from) candidate))
4390 marker)
4391 (when (and follow (not (get-buffer dired-log-buffer)))
4392 (let ((target (directory-file-name candidate)))
4393 (unwind-protect
4394 (progn
4395 (setq anything-ff-cand-to-mark
4396 (anything-get-dest-fnames-from-list files candidate dirflag))
4397 (if (and dirflag (eq action 'rename))
4398 (anything-find-files-1 (file-name-directory target)
4399 (if anything-ff-transformer-show-only-basename
4400 (anything-c-basename target) target))
4401 (anything-find-files-1 (expand-file-name candidate))))
4402 (setq anything-ff-cand-to-mark nil))))))
4405 (defun anything-c-basename (fname)
4406 "Resolve basename of file or directory named FNAME."
4407 (file-name-nondirectory (directory-file-name fname)))
4409 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4410 "Transform filenames of FLIST to abs of DEST-CAND.
4411 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4412 members of FLIST."
4413 ;; At this point files have been renamed/copied at destination.
4414 ;; That's mean DEST-CAND exists.
4415 (loop
4416 with dest = (expand-file-name dest-cand)
4417 for src in flist
4418 for basename-src = (anything-c-basename src)
4419 for fname = (cond (rename-dir-flag (directory-file-name dest))
4420 ((file-directory-p dest)
4421 (concat (file-name-as-directory dest) basename-src))
4422 (t dest))
4423 when (file-exists-p fname)
4424 collect fname into tmp-list
4425 finally return (sort tmp-list 'string<)))
4427 (defun anything-ff-maybe-mark-candidates ()
4428 "Mark all candidates of list `anything-ff-cand-to-mark'."
4429 (when (and (string= (assoc-default 'name (anything-get-current-source))
4430 (assoc-default 'name anything-c-source-find-files))
4431 anything-ff-cand-to-mark)
4432 (with-anything-window
4433 (while anything-ff-cand-to-mark
4434 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4435 (progn
4436 (anything-make-visible-mark)
4437 (anything-next-line)
4438 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4439 (anything-next-line)))
4440 (unless (anything-this-visible-mark)
4441 (anything-prev-visible-mark)))))
4443 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4445 (defun* anything-dired-do-action-on-file (&key action)
4446 (let* ((files (dired-get-marked-files))
4447 (len (length files))
4448 (fname (if (> len 1)
4449 (format "* %d Files" len)
4450 (car files)))
4451 (source (case action
4452 ('copy 'anything-c-source-copy-files)
4453 ('rename 'anything-c-source-rename-files)
4454 ('symlink 'anything-c-source-symlink-files)
4455 ('hardlink 'anything-c-source-hardlink-files)))
4456 (prompt-fm (case action
4457 ('copy "Copy %s to: ")
4458 ('rename "Rename %s to: ")
4459 ('symlink "Symlink %s to: ")
4460 ('hardlink "Hardlink %s to: ")))
4461 (buffer (case action
4462 ('copy "*Anything Copy Files*")
4463 ('rename "*Anything Rename Files*")
4464 ('symlink "*Anything Symlink Files*")
4465 ('hardlink "*Anything Hardlink Files*")))
4466 (anything-mp-highlight-delay nil))
4467 (anything :sources source
4468 :input (or (dired-dwim-target-directory)
4469 (expand-file-name (anything-c-current-directory)))
4470 :preselect (dired-get-filename)
4471 :prompt (format prompt-fm fname)
4472 :keymap anything-c-read-file-map
4473 :buffer buffer)))
4475 ;;;###autoload
4476 (define-minor-mode anything-dired-mode ()
4477 "Enable anything completion in Dired functions.
4478 Bindings affected are C, R, S, H.
4479 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4480 :group 'anything-config
4481 :global t
4482 (if anything-dired-mode
4483 (progn
4484 (substitute-key-definition
4485 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4486 (substitute-key-definition
4487 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4488 (substitute-key-definition
4489 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4490 (substitute-key-definition
4491 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4492 (substitute-key-definition
4493 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4494 (substitute-key-definition
4495 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4496 (substitute-key-definition
4497 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4498 (substitute-key-definition
4499 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4501 (defalias 'anything-dired-bindings 'anything-dired-mode)
4503 (defun* anything-c-read-file-name (prompt
4504 &key
4505 (name "Read File Name")
4506 (initial-input (expand-file-name default-directory))
4507 (buffer "*Anything Completions*")
4508 test
4509 (preselect nil)
4510 (history nil)
4511 (marked-candidates nil)
4512 (alistp t)
4513 (persistent-action 'anything-find-files-persistent-action)
4514 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4515 "Anything `read-file-name' emulation.
4516 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4517 (when (get-buffer anything-action-buffer)
4518 (kill-buffer anything-action-buffer))
4519 (let ((anything-mp-highlight-delay nil)
4520 ;; Be sure we don't erase the underlying minibuffer if some.
4521 (anything-ff-auto-update-initial-value
4522 (not (minibuffer-window-active-p (minibuffer-window))))
4523 anything-same-window)
4524 (flet ((action-fn (candidate)
4525 (if marked-candidates
4526 (anything-marked-candidates)
4527 (identity candidate))))
4528 (or (anything
4529 :sources
4530 `(((name . ,(format "%s History" name))
4531 (header-name . (lambda (name)
4532 (concat name anything-c-find-files-doc-header)))
4533 (disable-shortcuts)
4534 (mode-line . anything-read-file-name-mode-line-string)
4535 (candidates . (lambda ()
4536 (anything-comp-read-get-candidates history nil nil alistp)))
4537 (persistent-action . ,persistent-action)
4538 (persistent-help . ,persistent-help)
4539 (action . ,'action-fn))
4540 ((name . ,name)
4541 (header-name . (lambda (name)
4542 (concat name anything-c-find-files-doc-header)))
4543 ;; It is needed for filenames with capital letters
4544 (disable-shortcuts)
4545 (mode-line . anything-read-file-name-mode-line-string)
4546 (candidates . (lambda ()
4547 (let ((seq (anything-find-files-get-candidates)))
4548 (if test
4549 (loop for fname in seq
4550 when (funcall test fname) collect fname)
4551 seq))))
4552 (filtered-candidate-transformer anything-c-find-files-transformer)
4553 (persistent-action . ,persistent-action)
4554 (candidate-number-limit . 9999)
4555 (toggle-auto-update . anything-ff-toggle-auto-update)
4556 (persistent-help . ,persistent-help)
4557 (volatile)
4558 (action . ,'action-fn)))
4559 :input initial-input
4560 :prompt prompt
4561 :keymap anything-c-read-file-map
4562 :resume 'noresume
4563 :buffer buffer
4564 :preselect preselect)
4565 (keyboard-quit)))))
4568 ;;; File Cache
4569 (defvar anything-c-file-cache-initialized-p nil)
4571 (defvar anything-c-file-cache-files nil)
4573 (defvar anything-c-source-file-cache
4574 '((name . "File Cache")
4575 (init
4576 . (lambda ()
4577 (require 'filecache nil t)
4578 (unless anything-c-file-cache-initialized-p
4579 (setq anything-c-file-cache-files
4580 (loop for item in file-cache-alist append
4581 (destructuring-bind (base &rest dirs) item
4582 (loop for dir in dirs collect
4583 (concat dir base)))))
4584 (defadvice file-cache-add-file (after file-cache-list activate)
4585 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4586 (setq anything-c-file-cache-initialized-p t))))
4587 (candidates . anything-c-file-cache-files)
4588 (match anything-c-match-on-basename)
4589 (type . file)))
4590 ;; (anything 'anything-c-source-file-cache)
4593 ;;; Locate
4596 ;; NOTE for WINDOZE users:
4597 ;; You have to install Everything with his command line interface here:
4598 ;; http://www.voidtools.com/download.php
4600 (defun anything-locate-1 (&optional localdb init)
4601 "Generic function to run Locate.
4602 if LOCALDB is non--nil search and use a local locate db file.
4603 INIT is a string to use as initial input in prompt.
4604 See `anything-locate-with-db' and `anything-locate'."
4605 (anything-locate-with-db
4606 (and localdb
4607 (anything-c-read-file-name
4608 "LocateDBFiles: "
4609 :marked-candidates t
4610 :preselect anything-locate-db-file-regexp
4611 :test #'(lambda (x)
4612 (if anything-locate-db-file-regexp
4613 ;; Select only locate db files and directories
4614 ;; to allow navigation.
4615 (or (string-match
4616 anything-locate-db-file-regexp x)
4617 (file-directory-p x))
4618 x))))
4619 init))
4620 ;; (anything-locate-1 t)
4622 (defun anything-locate-with-db (&optional db initial-input)
4623 "Run locate -d DB.
4624 If DB is not given or nil use locate without -d option.
4625 Argument DB can be given as a string or list of db files.
4626 Argument INITIAL-INPUT is a string to use as initial-input.
4627 See also `anything-locate'."
4628 (when (and db (stringp db)) (setq db (list db)))
4629 (let ((anything-c-locate-command
4630 (if db
4631 (replace-regexp-in-string
4632 "locate"
4633 (format "locate -d %s"
4634 (mapconcat 'identity
4635 ;; Remove eventually
4636 ;; marked directories by error.
4637 (loop for i in db
4638 unless (file-directory-p i)
4639 collect i) ":"))
4640 anything-c-locate-command)
4641 anything-c-locate-command)))
4642 (anything :sources 'anything-c-source-locate
4643 :buffer "*anything locate*"
4644 :input initial-input
4645 :keymap anything-generic-files-map)))
4646 ;; (anything-locate-with-db "~/locate.db")
4648 (defun anything-c-locate-init ()
4649 "Initialize async locate process for `anything-c-source-locate'."
4650 (setq mode-line-format
4651 '(" " mode-line-buffer-identification " "
4652 (line-number-mode "%l") " "
4653 (:eval (propertize "(Locate Process Running) "
4654 'face '((:foreground "red"))))))
4655 (prog1
4656 (start-process-shell-command "locate-process" nil
4657 (format anything-c-locate-command
4658 anything-pattern))
4659 (set-process-sentinel (get-process "locate-process")
4660 #'(lambda (process event)
4661 (when (string= event "finished\n")
4662 (with-anything-window
4663 (force-mode-line-update nil)
4664 (anything-update-move-first-line)))))))
4666 (defvar anything-c-source-locate
4667 '((name . "Locate")
4668 (candidates . anything-c-locate-init)
4669 (type . file)
4670 (properties-action . anything-ff-properties)
4671 (requires-pattern . 3)
4672 (candidate-number-limit . 9999)
4673 (mode-line . anything-generic-file-mode-line-string)
4674 (delayed))
4675 "Find files matching the current input pattern with locate.")
4676 ;; (anything 'anything-c-source-locate)
4678 (defun anything-c-locate-read-file-name (prompt &optional init)
4679 "Search a file with locate and return it's filename.
4680 Use argument PROMPT and INIT for `anything' arguments
4681 prompt and input."
4682 (anything :sources
4683 '((name . "Locate")
4684 (candidates . anything-c-locate-init)
4685 (action . identity)
4686 (properties-action . anything-ff-properties)
4687 (requires-pattern . 3)
4688 (candidate-number-limit . 9999)
4689 (mode-line . anything-generic-file-mode-line-string)
4690 (delayed))
4691 :prompt prompt
4692 :input init
4693 :buffer "*anything locate rfn*"))
4697 ;;; Anything Incremental Grep.
4700 ;; Allow to grep incrementally with anything interface.
4701 ;; It allow also to Grep files recursively without using 'find' shell command.
4702 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4703 (defvar anything-c-grep-default-command
4704 "grep -d skip %e -niH -e %p %f"
4705 "Default grep format command for `anything-do-grep-1'.
4706 Where:
4707 '%e' format spec is for --exclude or --include grep options.
4708 '%p' format spec is for pattern.
4709 '%f' format spec is for filenames.")
4711 (defvar anything-c-grep-default-recurse-command
4712 "grep -d recurse %e -niH -e %p %f"
4713 "Default recursive grep format command for `anything-do-grep-1'.
4714 See `anything-c-grep-default-command' for format specs.")
4716 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4718 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4720 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4722 (defvar anything-c-grep-debug-command-line nil
4723 "Turn on anything grep command-line debugging when non--nil.")
4725 (defvar anything-c-zgrep-recurse-flag nil)
4727 (defvar anything-c-grep-history nil)
4729 (defvar anything-c-grep-max-length-history 100
4730 "*Max number of elements to save in `anything-c-grep-history'.")
4732 (defun anything-c-grep-prepare-candidates (candidates)
4733 "Prepare filenames and directories CANDIDATES for grep command line."
4734 ;; If one or more candidate is a directory, search in all files
4735 ;; of this candidate (e.g /home/user/directory/*).
4736 ;; If r option is enabled search also in subdidrectories.
4737 ;; We need here to expand wildcards to support crap windows filenames
4738 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4739 (if anything-c-zgrep-recurse-flag
4740 (mapconcat 'shell-quote-argument candidates " ")
4741 (loop for i in candidates append
4742 (cond ( ;; Candidate is a directory and we use recursion.
4743 (and (file-directory-p i)
4744 (anything-c-grep-recurse-p))
4745 (list (expand-file-name i)))
4746 ;; Candidate is a directory, search in all files.
4747 ((file-directory-p i)
4748 (file-expand-wildcards
4749 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4750 ;; Candidate is a file or wildcard and we use recursion, use the
4751 ;; current directory instead of candidate.
4752 ((and (or (file-exists-p i) (string-match "\*" i))
4753 (anything-c-grep-recurse-p))
4754 (list (expand-file-name
4755 (directory-file-name ; Needed for windoze.
4756 (file-name-directory (directory-file-name i))))))
4757 ;; Candidate use wildcard.
4758 ((string-match "^\*" (anything-c-basename i))
4759 (file-expand-wildcards i t))
4760 ;; Else should be one or more file.
4761 (t (list i))) into all-files
4762 finally return
4763 (mapconcat 'shell-quote-argument all-files " "))))
4765 (defun anything-c-grep-recurse-p ()
4766 "Check if `anything-do-grep-1' have switched to recursive."
4767 (let ((args (replace-regexp-in-string
4768 "grep" "" anything-c-grep-default-command)))
4769 (string-match-p "r\\|recurse" args)))
4771 (defun anything-c-grep-init (only-files &optional include zgrep)
4772 "Start an asynchronous grep process in ONLY-FILES list."
4773 (let* ((fnargs (anything-c-grep-prepare-candidates
4774 (if (file-remote-p anything-ff-default-directory)
4775 (mapcar #'(lambda (x)
4776 (file-remote-p x 'localname))
4777 only-files)
4778 only-files)))
4779 (ignored-files (mapconcat
4780 #'(lambda (x)
4781 (concat "--exclude=" (shell-quote-argument x)))
4782 grep-find-ignored-files " "))
4783 (ignored-dirs (mapconcat
4784 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4785 #'(lambda (x)
4786 (concat "--exclude-dir=" (shell-quote-argument x)))
4787 grep-find-ignored-directories " "))
4788 (exclude (if (anything-c-grep-recurse-p)
4789 (concat (or include ignored-files) " " ignored-dirs)
4790 ignored-files))
4791 (cmd-line (format-spec
4792 anything-c-grep-default-command
4793 (delq nil
4794 (list (unless zgrep (cons ?e exclude))
4795 (cons ?p (shell-quote-argument anything-pattern))
4796 (cons ?f fnargs))))))
4797 (when anything-c-grep-debug-command-line
4798 (with-current-buffer (get-buffer-create "*any grep debug*")
4799 (goto-char (point-max))
4800 (insert (concat ">>> " cmd-line "\n\n"))))
4801 (setq mode-line-format
4802 '(" " mode-line-buffer-identification " "
4803 (line-number-mode "%l") " "
4804 (:eval (when (get-process "grep-process")
4805 (propertize "[Grep Process Running] "
4806 'face 'anything-grep-running)))))
4807 (force-mode-line-update nil)
4808 (prog1
4809 (let ((default-directory anything-ff-default-directory))
4810 (start-file-process-shell-command "grep-process" nil cmd-line))
4811 (message nil)
4812 (set-process-sentinel
4813 (get-process "grep-process")
4814 #'(lambda (process event)
4815 (when (string= event "finished\n")
4816 (with-anything-window
4817 (anything-update-move-first-line)
4818 (setq mode-line-format
4819 '(" " mode-line-buffer-identification " "
4820 (line-number-mode "%l") " "
4821 (:eval (propertize
4822 (format "[Grep Process Finished - (%s results)] "
4823 (let ((nlines (1- (count-lines
4824 (point-min)
4825 (point-max)))))
4826 (if (> nlines 0) nlines 0)))
4827 'face 'anything-grep-finish))))
4828 (force-mode-line-update nil))))))))
4830 (defun anything-c-grep-action (candidate &optional where mark)
4831 "Define a default action for `anything-do-grep' on CANDIDATE.
4832 WHERE can be one of other-window, elscreen, other-frame."
4833 (let* ((split (anything-c-grep-split-line candidate))
4834 (lineno (string-to-number (nth 1 split)))
4835 (loc-fname (car split))
4836 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4837 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4838 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4839 (fname (if tramp-host
4840 (concat tramp-prefix loc-fname) loc-fname)))
4841 (case where
4842 (other-window (find-file-other-window fname))
4843 (elscreen (anything-elscreen-find-file fname))
4844 (other-frame (find-file-other-frame fname))
4845 (t (find-file fname)))
4846 (anything-goto-line lineno)
4847 (when mark
4848 (set-marker (mark-marker) (point))
4849 (push-mark (point) 'nomsg))
4850 ;; Save history
4851 (unless (or anything-in-persistent-action
4852 (string= anything-pattern ""))
4853 (setq anything-c-grep-history
4854 (cons anything-pattern
4855 (delete anything-pattern anything-c-grep-history)))
4856 (when (> (length anything-c-grep-history)
4857 anything-c-grep-max-length-history)
4858 (setq anything-c-grep-history
4859 (delete (car (last anything-c-grep-history))
4860 anything-c-grep-history))))))
4862 (defun anything-c-grep-other-window (candidate)
4863 "Jump to result in other window from anything grep."
4864 (anything-c-grep-action candidate 'other-window))
4866 (defun anything-c-grep-other-frame (candidate)
4867 "Jump to result in other frame from anything grep."
4868 (anything-c-grep-action candidate 'other-frame))
4870 (defun anything-c-grep-jump-elscreen (candidate)
4871 "Jump to result in elscreen from anything grep."
4872 (anything-c-grep-action candidate 'elscreen))
4874 (defun anything-c-grep-save-results (candidate)
4875 "Save anything grep result in a `grep-mode' buffer."
4876 (let ((buf "*grep*")
4877 new-buf)
4878 (when (get-buffer buf)
4879 (setq new-buf (read-string "GrepBufferName: " buf))
4880 (loop for b in (anything-c-buffer-list)
4881 when (and (string= new-buf b)
4882 (not (y-or-n-p
4883 (format "Buffer `%s' already exists overwrite? "
4884 new-buf))))
4885 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4886 (setq buf new-buf))
4887 (with-current-buffer (get-buffer-create buf)
4888 (let ((inhibit-read-only t))
4889 (erase-buffer)
4890 (insert "-*- mode: grep -*-\n\n"
4891 (format "Grep Results for `%s':\n\n" anything-pattern))
4892 (save-excursion
4893 (insert (with-current-buffer anything-buffer
4894 (forward-line 1)
4895 (buffer-substring (point) (point-max))))
4896 (grep-mode))))
4897 (message "Anything Grep Results saved in `%s' buffer" buf)))
4899 (defun anything-c-grep-persistent-action (candidate)
4900 "Persistent action for `anything-do-grep'.
4901 With a prefix arg record CANDIDATE in `mark-ring'."
4902 (if current-prefix-arg
4903 (anything-c-grep-action candidate nil 'mark)
4904 (anything-c-grep-action candidate))
4905 (anything-match-line-color-current-line))
4907 (defun anything-c-grep-guess-extensions (files)
4908 "Try to guess file extensions in FILES list when using grep recurse.
4909 These extensions will be added to command line with --include arg of grep."
4910 (loop
4911 with glob-list = nil
4912 with lst = (if (file-directory-p (car files))
4913 (directory-files
4914 (car files) nil
4915 directory-files-no-dot-files-regexp)
4916 files)
4917 for i in lst
4918 for ext = (file-name-extension i t)
4919 for glob = (and ext (not (string= ext ""))
4920 (concat "*" ext))
4921 unless (or (not glob)
4922 (member glob glob-list)
4923 (member glob grep-find-ignored-files))
4924 collect glob into glob-list
4925 finally return glob-list))
4927 (defun anything-do-grep-1 (only &optional recurse zgrep)
4928 "Launch grep with a list of ONLY files.
4929 When RECURSE is given use -r option of grep and prompt user
4930 to set the --include args of grep.
4931 You can give more than one arg separated by space.
4932 e.g *.el *.py *.tex.
4933 If it's empty --exclude `grep-find-ignored-files' is used instead."
4934 (let* ((anything-compile-source-functions
4935 ;; rule out anything-match-plugin because the input is one regexp.
4936 (delq 'anything-compile-source--match-plugin
4937 (copy-sequence anything-compile-source-functions)))
4938 (exts (anything-c-grep-guess-extensions only))
4939 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4940 (include-files (and recurse (not zgrep)
4941 (read-string "OnlyExt(*.[ext]): "
4942 globs)))
4943 ;; Set `minibuffer-history' AFTER includes-files
4944 ;; to avoid storing wild-cards here.
4945 (minibuffer-history anything-c-grep-history)
4946 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4947 (recurse anything-c-grep-default-recurse-command)
4948 (zgrep anything-c-default-zgrep-command)
4949 (t anything-c-grep-default-command)))
4950 ;; Disable match-plugin and use here own highlighting.
4951 (anything-mp-highlight-delay nil))
4952 (when include-files
4953 (setq include-files
4954 (and (not (string= include-files ""))
4955 (mapconcat #'(lambda (x)
4956 (concat "--include=" (shell-quote-argument x)))
4957 (split-string include-files) " "))))
4958 ;; When called as action from an other source e.g *-find-files
4959 ;; we have to kill action buffer.
4960 (when (get-buffer anything-action-buffer)
4961 (kill-buffer anything-action-buffer))
4962 ;; `anything-find-files' haven't already started,
4963 ;; give a default value to `anything-ff-default-directory'.
4964 (setq anything-ff-default-directory (or anything-ff-default-directory
4965 default-directory))
4966 (anything
4967 :sources
4968 `(((name . "Grep (C-c ? Help)")
4969 (candidates
4970 . (lambda ()
4971 (funcall anything-c-grep-default-function only include-files zgrep)))
4972 (filtered-candidate-transformer anything-c-grep-cand-transformer)
4973 (candidate-number-limit . 9999)
4974 (mode-line . anything-grep-mode-line-string)
4975 (jump-persistent . anything-c-grep-persistent-action)
4976 (action . ,(delq
4978 `(("Find File" . anything-c-grep-action)
4979 ("Find file other frame" . anything-c-grep-other-frame)
4980 ,(and (locate-library "elscreen")
4981 '("Find file in Elscreen"
4982 . anything-c-grep-jump-elscreen))
4983 ("Save results in grep buffer" . anything-c-grep-save-results)
4984 ("Find file other window" . anything-c-grep-other-window))))
4985 (persistent-action . anything-c-grep-persistent-action)
4986 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
4987 (requires-pattern . 3)
4988 (delayed)))
4989 :keymap anything-c-grep-map
4990 :buffer "*anything grep*")))
4992 (defun anything-ff-zgrep-1 (flist recursive)
4993 (unwind-protect
4994 (let* ((def-dir (or anything-ff-default-directory
4995 default-directory))
4996 (only (if recursive
4997 (or (gethash def-dir anything-c-rzgrep-cache)
4998 (puthash
4999 def-dir
5000 (anything-c-walk-directory
5001 def-dir
5002 :directories nil
5003 :path 'full
5004 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5005 anything-c-rzgrep-cache))
5006 flist)))
5007 (when recursive (setq anything-c-zgrep-recurse-flag t))
5008 (anything-do-grep-1 only recursive 'zgrep))
5009 (setq anything-c-zgrep-recurse-flag nil)))
5011 (defun anything-c-grep-split-line (line)
5012 "Split a grep output line."
5013 (let (beg fname lineno str)
5014 ;; Don't print until grep line is valid.
5015 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5016 (with-temp-buffer
5017 (insert line)
5018 (goto-char (point-min))
5019 (setq beg (point))
5020 (forward-char 2)
5021 (re-search-forward ":" nil t)
5022 (setq fname (buffer-substring-no-properties beg (1- (point))))
5023 (setq beg (point))
5024 (re-search-forward ":" nil t)
5025 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5026 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5027 (list fname lineno str))))
5029 (defun anything-c-grep-cand-transformer (candidates sources)
5030 "Filtered candidate transformer function for `anything-do-grep'."
5031 (loop for i in candidates
5032 for split = (and i (anything-c-grep-split-line i))
5033 for fname = (car split)
5034 for lineno = (nth 1 split)
5035 for str = (nth 2 split)
5036 when (and fname lineno str)
5037 collect
5038 (cons (concat (propertize (file-name-nondirectory fname)
5039 'face 'anything-grep-file
5040 'help-echo fname) ":"
5041 (propertize lineno 'face 'anything-grep-lineno) ":"
5042 (anything-c-grep-highlight-match str))
5043 i)))
5045 (defun anything-c-grep-highlight-match (str)
5046 "Highlight in string STR all occurences matching `anything-pattern'."
5047 (condition-case nil
5048 (with-temp-buffer
5049 (insert str)
5050 (goto-char (point-min))
5051 (while (and (re-search-forward anything-pattern nil t)
5052 (> (- (match-end 0) (match-beginning 0)) 0))
5053 (add-text-properties
5054 (match-beginning 0) (match-end 0)
5055 '(face anything-grep-match)))
5056 (buffer-string))
5057 (error nil)))
5059 ;; Go to next or precedent file (common to etags and grep).
5060 (defun anything-c-goto-next-or-prec-file (n)
5061 "Go to next or precedent candidate file in anything grep/etags buffers.
5062 If N is positive go forward otherwise go backward."
5063 (with-anything-window
5064 (let* ((current-line-list (split-string
5065 (buffer-substring
5066 (point-at-bol)
5067 (point-at-eol)) ":"))
5068 (current-fname (nth 0 current-line-list))
5069 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5070 (catch 'break
5071 (while (not (funcall fn-b-o-f))
5072 (forward-line n) ; Go forward or backward depending of n value.
5073 (unless (search-forward current-fname (point-at-eol) t)
5074 (anything-mark-current-line)
5075 (throw 'break nil))))
5076 (cond ((and (eq n 1) (eobp))
5077 (re-search-backward ".")
5078 (forward-line 0)
5079 (anything-mark-current-line))
5080 ((and (< n 1) (bobp))
5081 (forward-line 1)
5082 (anything-mark-current-line))))))
5084 ;;;###autoload
5085 (defun anything-c-goto-precedent-file ()
5086 "Go to precedent file in anything grep/etags buffers."
5087 (interactive)
5088 (anything-c-goto-next-or-prec-file -1))
5090 ;;;###autoload
5091 (defun anything-c-goto-next-file ()
5092 "Go to precedent file in anything grep/etags buffers."
5093 (interactive)
5094 (anything-c-goto-next-or-prec-file 1))
5096 ;;;###autoload
5097 (defun anything-c-grep-run-persistent-action ()
5098 "Run grep persistent action from `anything-do-grep-1'."
5099 (interactive)
5100 (anything-execute-persistent-action 'jump-persistent))
5102 ;;;###autoload
5103 (defun anything-c-grep-run-default-action ()
5104 "Run grep default action from `anything-do-grep-1'."
5105 (interactive)
5106 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5108 ;;;###autoload
5109 (defun anything-c-grep-run-other-window-action ()
5110 "Run grep goto other window action from `anything-do-grep-1'."
5111 (interactive)
5112 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5114 ;;;###autoload
5115 (defun anything-c-grep-run-save-buffer ()
5116 "Run grep save results action from `anything-do-grep-1'."
5117 (interactive)
5118 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5120 ;; Grep buffers
5121 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5122 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5123 If one of selected buffers is not a file--buffer,
5124 it is ignored and grep will run on all others file--buffers.
5125 If only one candidate is selected and it is not a file--buffer,
5126 switch to this buffer and run `anything-occur'.
5127 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5128 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5129 (cands (if prefarg
5130 (buffer-list)
5131 (anything-marked-candidates)))
5132 (win-conf (current-window-configuration))
5133 ;; Non--fname buffers are ignored.
5134 (bufs (loop for buf in cands
5135 for fname = (buffer-file-name (get-buffer buf))
5136 when fname
5137 collect (expand-file-name fname))))
5138 (if bufs
5139 (if zgrep
5140 (anything-do-grep-1 bufs nil 'zgrep)
5141 (anything-do-grep-1 bufs))
5142 ;; bufs is empty, thats mean we have only CANDIDATE
5143 ;; and it is not a buffer-filename, fallback to occur.
5144 (anything-c-switch-to-buffer candidate)
5145 (when (get-buffer anything-action-buffer)
5146 (kill-buffer anything-action-buffer))
5147 (anything-occur)
5148 (when (eq anything-exit-status 1)
5149 (set-window-configuration win-conf)))))
5151 (defun anything-c-grep-buffers (candidate)
5152 "Action to grep buffers."
5153 (anything-c-grep-buffers-1 candidate))
5155 (defun anything-c-zgrep-buffers (candidate)
5156 "Action to zgrep buffers."
5157 (anything-c-grep-buffers-1 candidate 'zgrep))
5160 ;;; Anything interface for pdfgrep
5161 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5162 ;; and a pdf-reader (e.g xpdf) are needed.
5164 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5165 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5166 (defvar anything-c-pdfgrep-debug-command-line nil)
5168 (defun anything-c-pdfgrep-init (only-files)
5169 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5170 (let* ((fnargs (anything-c-grep-prepare-candidates
5171 (if (file-remote-p anything-ff-default-directory)
5172 (mapcar #'(lambda (x)
5173 (file-remote-p x 'localname))
5174 only-files)
5175 only-files)))
5176 (cmd-line (format anything-c-pdfgrep-default-command
5177 anything-pattern
5178 fnargs)))
5179 (when anything-c-pdfgrep-debug-command-line
5180 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5181 (goto-char (point-max))
5182 (insert (concat ">>> " cmd-line "\n\n"))))
5183 (setq mode-line-format
5184 '(" " mode-line-buffer-identification " "
5185 (line-number-mode "%l") " "
5186 (:eval (propertize "(Pdfgrep Process Running) "
5187 'face '((:foreground "red"))))))
5188 (prog1
5189 (let ((default-directory anything-ff-default-directory))
5190 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5191 (message nil)
5192 (set-process-sentinel
5193 (get-process "pdfgrep-process")
5194 #'(lambda (process event)
5195 (when (string= event "finished\n")
5196 (with-anything-window
5197 (anything-update-move-first-line))
5198 (force-mode-line-update nil)))))))
5201 (defun anything-do-pdfgrep-1 (only)
5202 "Launch pdfgrep with a list of ONLY files."
5203 (unless (executable-find "pdfgrep")
5204 (error "Error: No such program `pdfgrep'."))
5205 (let* ((anything-compile-source-functions
5206 ;; rule out anything-match-plugin because the input is one regexp.
5207 (delq 'anything-compile-source--match-plugin
5208 (copy-sequence anything-compile-source-functions)))
5209 ;; Disable match-plugin and use here own highlighting.
5210 (anything-mp-highlight-delay nil))
5211 ;; When called as action from an other source e.g *-find-files
5212 ;; we have to kill action buffer.
5213 (when (get-buffer anything-action-buffer)
5214 (kill-buffer anything-action-buffer))
5215 ;; If `anything-find-files' haven't already started,
5216 ;; give a default value to `anything-ff-default-directory'.
5217 (setq anything-ff-default-directory (or anything-ff-default-directory
5218 default-directory))
5219 (anything
5220 :sources
5221 `(((name . "PdfGrep")
5222 (candidates
5223 . (lambda ()
5224 (funcall anything-c-pdfgrep-default-function only)))
5225 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5226 (candidate-number-limit . 9999)
5227 (mode-line . anything-pdfgrep-mode-line-string)
5228 (action . anything-c-pdfgrep-action)
5229 (persistent-help . "Jump to PDF Page")
5230 (requires-pattern . 3)
5231 (delayed)))
5232 :keymap anything-c-pdfgrep-map
5233 :buffer "*anything grep*")))
5236 (defun anything-c-pdfgrep-action (candidate)
5237 (let* ((split (anything-c-grep-split-line candidate))
5238 (pageno (nth 1 split))
5239 (fname (car split)))
5240 (start-file-process-shell-command
5241 "pdf-reader" nil
5242 (format-spec anything-c-pdfgrep-default-read-command
5243 (list (cons ?f fname) (cons ?p pageno))))))
5245 (defun anything-do-pdfgrep ()
5246 (interactive)
5247 (let ((only (anything-c-read-file-name
5248 "Search in file(s): "
5249 :marked-candidates t
5250 :test #'(lambda (file)
5251 (or (string= (file-name-extension file) "pdf")
5252 (string= (file-name-extension file) "PDF")
5253 (file-directory-p file)))
5254 :preselect (or (dired-get-filename nil t)
5255 (buffer-file-name (current-buffer)))))
5256 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5257 (anything-do-pdfgrep-1 only)))
5260 ;; Yank text at point.
5263 ;; Internal
5264 (defvar anything-yank-point nil)
5266 ;;;###autoload
5267 (defun anything-yank-text-at-point ()
5268 "Yank text at point in minibuffer."
5269 (interactive)
5270 (let (input)
5271 (flet ((insert-in-minibuffer (word)
5272 (with-selected-window (minibuffer-window)
5273 (let ((str anything-pattern))
5274 (delete-minibuffer-contents)
5275 (set-text-properties 0 (length word) nil word)
5276 (insert (concat str word))))))
5277 (with-anything-current-buffer
5278 ;; Start to initial point if C-w have never been hit.
5279 (unless anything-yank-point (setq anything-yank-point (point)))
5280 (and anything-yank-point (goto-char anything-yank-point))
5281 (forward-word 1)
5282 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5283 (setq anything-yank-point (point))) ; End of last forward-word
5284 (insert-in-minibuffer input))))
5286 (defun anything-reset-yank-point ()
5287 (setq anything-yank-point nil))
5289 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5290 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5293 ;;; Recentf files
5296 (defvar anything-c-source-recentf
5297 '((name . "Recentf")
5298 (init . (lambda ()
5299 (require 'recentf)
5300 (or recentf-mode (recentf-mode 1))))
5301 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5302 (candidates . recentf-list)
5303 (match anything-c-match-on-basename)
5304 (type . file))
5305 "See (info \"(emacs)File Conveniences\").
5306 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5307 ;; (anything 'anything-c-source-recentf)
5309 ;;; ffap
5310 (eval-when-compile (require 'ffap))
5311 (defvar anything-c-source-ffap-guesser
5312 '((name . "File at point")
5313 (init . (lambda () (require 'ffap)))
5314 (candidates . (lambda ()
5315 (anything-aif
5316 (with-anything-current-buffer
5317 (ffap-guesser))
5318 (list it))))
5319 (type . file)))
5320 ;; (anything 'anything-c-source-ffap-guesser)
5322 ;;; ffap with line number
5323 (defun anything-c-ffap-file-line-at-point ()
5324 "Get (FILENAME . LINENO) at point."
5325 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5326 (save-excursion
5327 (beginning-of-line)
5328 (when (and (search-forward it nil t)
5329 (looking-at ":\\([0-9]+\\)"))
5330 (cons it (string-to-number (match-string 1)))))))
5332 (defvar anything-c-ffap-line-location nil
5333 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5334 It is cleared after jumping line.")
5336 (defun anything-c-ffap-line-candidates ()
5337 (with-anything-current-buffer
5338 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5339 (when anything-c-ffap-line-location
5340 (destructuring-bind (file . line) anything-c-ffap-line-location
5341 (list (cons (format "%s (line %d)" file line) file)))))
5343 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5344 (defun anything-c-ffap-line-goto-line ()
5345 (when (car anything-c-ffap-line-location)
5346 (unwind-protect
5347 (ignore-errors
5348 (with-selected-window
5349 (get-buffer-window
5350 (get-file-buffer (car anything-c-ffap-line-location)))
5351 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5352 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5353 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5355 (defvar anything-c-source-ffap-line
5356 '((name . "File/Lineno at point")
5357 (init . (lambda () (require 'ffap)))
5358 (candidates . anything-c-ffap-line-candidates)
5359 (type . file)))
5360 ;; (anything 'anything-c-source-ffap-line)
5362 ;;; list of files gleaned from every dired buffer
5363 (defun anything-c-files-in-all-dired-candidates ()
5364 (save-excursion
5365 (mapcan
5366 (lambda (dir)
5367 (cond ((listp dir) ;filelist
5368 dir)
5369 ((equal "" (file-name-nondirectory dir)) ;dir
5370 (directory-files dir t))
5371 (t ;wildcard
5372 (file-expand-wildcards dir t))))
5373 (delq nil
5374 (mapcar (lambda (buf)
5375 (set-buffer buf)
5376 (when (eq major-mode 'dired-mode)
5377 (if (consp dired-directory)
5378 (cdr dired-directory) ;filelist
5379 dired-directory))) ;dir or wildcard
5380 (buffer-list))))))
5381 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5383 (defvar anything-c-source-files-in-all-dired
5384 '((name . "Files in all dired buffer.")
5385 (candidates . anything-c-files-in-all-dired-candidates)
5386 (type . file)))
5387 ;; (anything 'anything-c-source-files-in-all-dired)
5389 (defvar anything-c-source-filelist
5390 '((name . "FileList")
5391 (grep-candidates . anything-c-filelist-file-name)
5392 (candidate-number-limit . 200)
5393 (requires-pattern . 4)
5394 (type . file))
5395 "Source to find files instantly.
5396 See `anything-c-filelist-file-name' docstring for usage.")
5399 ;;;; <info>
5400 ;;; Info pages
5401 (defvar anything-c-info-pages nil
5402 "All info pages on system.
5403 Will be calculated the first time you invoke anything with this
5404 source.")
5406 (defun anything-c-info-pages-init ()
5407 "Collect candidates for initial Info node Top."
5408 (if anything-c-info-pages
5409 anything-c-info-pages
5410 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5411 topics)
5412 (require 'info)
5413 (with-temp-buffer
5414 (Info-find-node "dir" "top")
5415 (goto-char (point-min))
5416 (while (re-search-forward info-topic-regexp nil t)
5417 (push (match-string-no-properties 1) topics))
5418 (kill-buffer))
5419 (setq anything-c-info-pages topics))))
5421 (defvar anything-c-source-info-pages
5422 `((name . "Info Pages")
5423 (init . anything-c-info-pages-init)
5424 (candidates . anything-c-info-pages)
5425 (action . (("Show with Info" .(lambda (node-str)
5426 (info (replace-regexp-in-string
5427 "^[^:]+: " "" node-str))))))
5428 (requires-pattern . 2)))
5429 ;; (anything 'anything-c-source-info-pages)
5432 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5433 (defun anything-c-describe-attributes (anything-attribute)
5434 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5435 Same as `anything-describe-anything-attribute' but with anything completion."
5436 (interactive (list (intern
5437 (anything-comp-read
5438 "Describe anything attribute: "
5439 (mapcar 'symbol-name anything-additional-attributes)
5440 :must-match t
5441 :persistent-action
5442 #'(lambda (candidate)
5443 (with-output-to-temp-buffer "*Help*"
5444 (princ (get (intern candidate) 'anything-attrdoc))))))))
5445 (with-output-to-temp-buffer "*Help*"
5446 (princ (get anything-attribute 'anything-attrdoc))))
5449 ;;; Use info-index plug-in.
5452 ;; Note that `name' attribute is not needed since
5453 ;; `anything-c-insert-summary' have been removed.
5454 ;; Info Elisp
5455 (defvar anything-c-source-info-elisp
5456 '((name . "Info index: elisp")
5457 (info-index . "elisp")))
5458 ;; (anything 'anything-c-source-info-elisp)
5460 ;; Info-Common-Lisp
5461 (defvar anything-c-source-info-cl
5462 '((name . "Info index: cl")
5463 (info-index . "cl")))
5464 ;; (anything 'anything-c-source-info-cl)
5466 ;; Info Index org
5467 (defvar anything-c-source-info-org
5468 '((name . "Info index: org")
5469 (info-index . "org")))
5470 ;; (anything 'anything-c-source-info-org)
5472 ;; Info Index gnus
5473 (defvar anything-c-source-info-gnus
5474 '((name . "Info index: Gnus")
5475 (info-index . "gnus")))
5477 ;; Info Index ratpoison
5478 (defvar anything-c-source-info-ratpoison
5479 '((name . "Info index: ratpoison")
5480 (info-index . "ratpoison")))
5481 ;; (anything 'anything-c-source-info-ratpoison)
5483 ;; Info Index zsh
5484 (defvar anything-c-source-info-zsh
5485 '((name . "Info index: zsh")
5486 (info-index . "zsh")))
5487 ;; (anything 'anything-c-source-info-zsh)
5489 ;; Info Index bash
5490 (defvar anything-c-source-info-bash
5491 '((name . "Info index: bash")
5492 (info-index . "bash")))
5493 ;; (anything 'anything-c-source-info-bash)
5495 ;; Info Index coreutils
5496 (defvar anything-c-source-info-coreutils
5497 '((name . "Info index: coreutils")
5498 (info-index . "coreutils")))
5499 ;; (anything 'anything-c-source-info-coreutils)
5501 ;; Info Index fileutils
5502 (defvar anything-c-source-info-fileutils
5503 '((name . "Info index: fileutils")
5504 (info-index . "fileutils")))
5505 ;; (anything 'anything-c-source-info-fileutils)
5507 ;; Info Index find
5508 (defvar anything-c-source-info-find
5509 '((name . "Info index: find")
5510 (info-index . "find")))
5511 ;; (anything 'anything-c-source-info-find)
5513 ;; Info Index sh-utils
5514 (defvar anything-c-source-info-sh-utils
5515 '((name . "Info index: sh-utils")
5516 (info-index . "sh-utils")))
5517 ;; (anything 'anything-c-source-info-sh-utils)
5519 ;; Info Index textutils
5520 (defvar anything-c-source-info-textutils
5521 '((name . "Info index: textutils")
5522 (info-index . "textutils")))
5523 ;; (anything 'anything-c-source-info-textutils)
5525 ;; Info Index libc
5526 (defvar anything-c-source-info-libc
5527 '((name . "Info index: libc")
5528 (info-index . "libc")))
5529 ;; (anything 'anything-c-source-info-libc)
5531 ;; Info Index make
5532 (defvar anything-c-source-info-make
5533 '((name . "Info index: make")
5534 (info-index . "make")))
5535 ;; (anything 'anything-c-source-info-make)
5537 ;; Info Index automake
5538 (defvar anything-c-source-info-automake
5539 '((name . "Info index: automake")
5540 (info-index . "automake")))
5541 ;; (anything 'anything-c-source-info-automake)
5543 ;; Info Index autoconf
5544 (defvar anything-c-source-info-autoconf
5545 '((name . "Info index: autoconf")
5546 (info-index . "autoconf")))
5547 ;; (anything 'anything-c-source-info-autoconf)
5549 ;; Info Index emacs-lisp-intro
5550 (defvar anything-c-source-info-emacs-lisp-intro
5551 '((name . "Info index: emacs-lisp-intro")
5552 (info-index . "emacs-lisp-intro")))
5553 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5555 ;; Info Index emacs
5556 (defvar anything-c-source-info-emacs
5557 '((name . "Info index: emacs")
5558 (info-index . "emacs")))
5559 ;; (anything 'anything-c-source-info-emacs)
5561 ;; Info Index elib
5562 (defvar anything-c-source-info-elib
5563 '((name . "Info index: elib")
5564 (info-index . "elib")))
5565 ;; (anything 'anything-c-source-info-elib)
5567 ;; Info Index eieio
5568 (defvar anything-c-source-info-eieio
5569 '((name . "Info index: eieio")
5570 (info-index . "eieio")))
5571 ;; (anything 'anything-c-source-info-eieio)
5573 ;; Info Index gauche-refe
5574 (defvar anything-c-source-info-gauche-refe
5575 '((name . "Info index: gauche")
5576 (info-index . "gauche-refe")))
5577 ;; (anything 'anything-c-source-info-gauche-refe)
5579 ;; Info Index guile
5580 (defvar anything-c-source-info-guile
5581 '((name . "Info index: guile")
5582 (info-index . "guile")))
5583 ;; (anything 'anything-c-source-info-guile)
5585 ;; Info Index guile-tut
5586 (defvar anything-c-source-info-guile-tut
5587 '((name . "Info index: guile-tut")
5588 (info-index . "guile-tut")))
5589 ;; (anything 'anything-c-source-info-guile-tut)
5591 ;; Info Index goops
5592 (defvar anything-c-source-info-goops
5593 '((name . "Info index: goops")
5594 (info-index . "goops")))
5595 ;; (anything 'anything-c-source-info-goops)
5597 ;; Info Index screen
5598 (defvar anything-c-source-info-screen
5599 '((name . "Info index: screen")
5600 (info-index . "screen")
5601 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5602 ;; (anything 'anything-c-source-info-screen)
5604 ;; Info Index latex
5605 (defvar anything-c-source-info-latex
5606 '((name . "Info index: latex")
5607 (info-index . "latex")))
5608 ;; (anything 'anything-c-source-info-latex)
5610 ;; Info Index gawk
5611 (defvar anything-c-source-info-gawk
5612 '((name . "Info index: gawk")
5613 (info-index . "gawk")))
5614 ;; (anything 'anything-c-source-info-gawk)
5616 ;; Info Index sed
5617 (defvar anything-c-source-info-sed
5618 '((name . "Info index: sed")
5619 (info-index . "sed")))
5620 ;; (anything 'anything-c-source-info-sed)
5622 ;; Info Index m4
5623 (defvar anything-c-source-info-m4
5624 '((name . "Info index: m4")
5625 (info-index . "m4")))
5626 ;; (anything 'anything-c-source-info-m4)
5628 ;; Info Index wget
5629 (defvar anything-c-source-info-wget
5630 '((name . "Info index: wget")
5631 (info-index . "wget")))
5632 ;; (anything 'anything-c-source-info-wget)
5634 ;; Info Index binutils
5635 (defvar anything-c-source-info-binutils
5636 '((name . "Info index: binutils")
5637 (info-index . "binutils")))
5638 ;; (anything 'anything-c-source-info-binutils)
5640 ;; Info Index as
5641 (defvar anything-c-source-info-as
5642 '((name . "Info index: as")
5643 (info-index . "as")))
5644 ;; (anything 'anything-c-source-info-as)
5646 ;; Info Index bfd
5647 (defvar anything-c-source-info-bfd
5648 '((name . "Info index: bfd")
5649 (info-index . "bfd")))
5650 ;; (anything 'anything-c-source-info-bfd)
5652 ;; Info Index gprof
5653 (defvar anything-c-source-info-gprof
5654 '((name . "Info index: gprof")
5655 (info-index . "gprof")))
5656 ;; (anything 'anything-c-source-info-gprof)
5658 ;; Info Index ld
5659 (defvar anything-c-source-info-ld
5660 '((name . "Info index: ld")
5661 (info-index . "ld")))
5662 ;; (anything 'anything-c-source-info-ld)
5664 ;; Info Index diff
5665 (defvar anything-c-source-info-diff
5666 '((name . "Info index: diff")
5667 (info-index . "diff")))
5668 ;; (anything 'anything-c-source-info-diff)
5670 ;; Info Index flex
5671 (defvar anything-c-source-info-flex
5672 '((name . "Info index: flex")
5673 (info-index . "flex")))
5674 ;; (anything 'anything-c-source-info-flex)
5676 ;; Info Index grep
5677 (defvar anything-c-source-info-grep
5678 '((name . "Info index: grep")
5679 (info-index . "grep")))
5680 ;; (anything 'anything-c-source-info-grep)
5682 ;; Info Index gzip
5683 (defvar anything-c-source-info-gzip
5684 '((name . "Info index: gzip")
5685 (info-index . "gzip")))
5686 ;; (anything 'anything-c-source-info-gzip)
5688 ;; Info Index libtool
5689 (defvar anything-c-source-info-libtool
5690 '((name . "Info index: libtool")
5691 (info-index . "libtool")))
5692 ;; (anything 'anything-c-source-info-libtool)
5694 ;; Info Index texinfo
5695 (defvar anything-c-source-info-texinfo
5696 '((name . "Info index: texinfo")
5697 (info-index . "texinfo")))
5698 ;; (anything 'anything-c-source-info-texinfo)
5700 ;; Info Index info
5701 (defvar anything-c-source-info-info
5702 '((name . "Info index: info")
5703 (info-index . "info")))
5704 ;; (anything 'anything-c-source-info-info)
5706 ;; Info Index gdb
5707 (defvar anything-c-source-info-gdb
5708 '((name . "Info index: gdb")
5709 (info-index . "gdb")))
5710 ;; (anything 'anything-c-source-info-gdb)
5712 ;; Info Index stabs
5713 (defvar anything-c-source-info-stabs
5714 '((name . "Info index: stabs")
5715 (info-index . "stabs")))
5716 ;; (anything 'anything-c-source-info-stabs)
5718 ;; Info Index cvsbook
5719 (defvar anything-c-source-info-cvsbook
5720 '((name . "Info index: cvsbook")
5721 (info-index . "cvsbook")))
5722 ;; (anything 'anything-c-source-info-cvsbook)
5724 ;; Info Index cvs
5725 (defvar anything-c-source-info-cvs
5726 '((name . "Info index: cvs")
5727 (info-index . "cvs")))
5728 ;; (anything 'anything-c-source-info-cvs)
5730 ;; Info Index bison
5731 (defvar anything-c-source-info-bison
5732 '((name . "Info index: bison")
5733 (info-index . "bison")))
5734 ;; (anything 'anything-c-source-info-bison)
5736 ;; Info Index id-utils
5737 (defvar anything-c-source-info-id-utils
5738 '((name . "Info index: id-utils")
5739 (info-index . "id-utils")))
5740 ;; (anything 'anything-c-source-info-id-utils)
5742 ;; Info Index global
5743 (defvar anything-c-source-info-global
5744 '((name . "Info index: global")
5745 (info-index . "global")))
5746 ;; (anything 'anything-c-source-info-global)
5749 ;;; Man and woman UI
5752 (defvar anything-c-man-pages nil
5753 "All man pages on system.
5754 Will be calculated the first time you invoke anything with this
5755 source.")
5757 (defun anything-c-man-default-action (candidate)
5758 "Default action for jumping to a woman or man page from anything."
5759 (let ((wfiles (woman-file-name-all-completions candidate)))
5760 (condition-case err
5761 (if (> (length wfiles) 1)
5762 (woman-find-file
5763 (anything-comp-read
5764 "ManFile: " wfiles :must-match t))
5765 (woman candidate))
5766 ;; If woman is unable to format correctly
5767 ;; use man instead.
5768 (error (kill-buffer) ; Kill woman buffer.
5769 (let ((Man-notify-method 'meek))
5770 (Man-getpage-in-background candidate))))))
5772 (defvar anything-c-source-man-pages
5773 `((name . "Manual Pages")
5774 (candidates . (lambda ()
5775 (if anything-c-man-pages
5776 anything-c-man-pages
5777 ;; XEmacs doesn't have a woman :)
5778 (setq anything-c-man-pages
5779 (ignore-errors
5780 (require 'woman)
5781 (woman-file-name "")
5782 (sort (mapcar 'car woman-topic-all-completions)
5783 'string-lessp))))))
5784 (action ("Show with Woman" . anything-c-man-default-action))
5785 ;; Woman does not work OS X
5786 ;; http://xahlee.org/emacs/modernization_man_page.html
5787 (action-transformer . (lambda (actions candidate)
5788 (if (eq system-type 'darwin)
5789 '(("Show with Man" . man))
5790 actions)))
5791 (requires-pattern . 2)))
5792 ;; (anything 'anything-c-source-man-pages)
5795 ;;;; <Command>
5796 ;;; Anything M-x - Enhanced M-x UI
5799 ;; Another replacement of `M-x' that act exactly like the
5800 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5801 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5802 ;; anything invocation.
5803 ;; Documentation of commands available without quitting,
5804 ;; Show keybindings of commands.
5805 ;; Show history.
5806 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5807 "Return alist of MODE-MAP."
5808 (loop for key being the key-seqs of mode-map using (key-bindings com)
5809 for str-key = (key-description key)
5810 for ismenu = (string-match "<menu-bar>" str-key)
5811 unless ismenu collect (cons str-key com)))
5813 (defun anything-get-mode-map-from-mode (mode)
5814 "Guess the mode-map name according to MODE.
5815 Some modes don't use conventional mode-map name
5816 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5817 Return nil if no mode-map found."
5818 (loop
5819 ;; Start with a conventional mode-map name.
5820 with mode-map = (intern-soft (format "%s-map" mode))
5821 with mode-string = (symbol-name mode)
5822 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5823 while (not mode-map)
5824 for count downfrom (length mode-name)
5825 ;; Return when no result after parsing entire string.
5826 when (eq count 0) return nil
5827 for sub-name = (substring mode-name 0 count)
5828 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5829 finally return mode-map))
5831 (defun anything-M-x-current-mode-map-alist ()
5832 "Return mode-map alist of current `major-mode'."
5833 (let ((map (anything-get-mode-map-from-mode major-mode)))
5834 (when (and map (boundp map))
5835 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5838 (defun anything-M-x-transformer (candidates sources)
5839 "filtered-candidate-transformer to show bindings in emacs commands.
5840 Show global bindings and local bindings according to current `major-mode'."
5841 (with-anything-current-buffer
5842 (loop
5843 with local-map = (anything-M-x-current-mode-map-alist)
5844 for cand in candidates
5845 for local-key = (car (rassq cand local-map))
5846 for key = (substitute-command-keys (format "\\[%s]" cand))
5847 collect
5848 (cons (cond ((and (string-match "^M-x" key) local-key)
5849 (format "%s (%s)"
5850 cand (propertize
5851 local-key
5852 'face 'anything-M-x-key-face)))
5853 ((string-match "^M-x" key) cand)
5854 (t (format "%s (%s)"
5855 cand (propertize
5857 'face 'anything-M-x-key-face))))
5858 cand) into ls
5859 finally return
5860 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5863 ;;; Complex command history
5866 (defvar anything-c-source-complex-command-history
5867 '((name . "Complex Command History")
5868 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5869 (type . sexp)))
5870 ;; (anything 'anything-c-source-complex-command-history)
5872 ;;; M-x history (not related to `anything-M-x')
5875 (defvar anything-c-source-extended-command-history
5876 '((name . "Emacs Commands History")
5877 (candidates . extended-command-history)
5878 (type . command)))
5879 ;; (anything 'anything-c-source-extended-command-history)
5881 ;;; Emacs commands (Basic source for emacs commands)
5884 (defvar anything-c-source-emacs-commands
5885 '((name . "Emacs Commands")
5886 (candidates . (lambda ()
5887 (let (commands)
5888 (mapatoms (lambda (a)
5889 (if (commandp a)
5890 (push (symbol-name a)
5891 commands))))
5892 (sort commands 'string-lessp))))
5893 (type . command)
5894 (requires-pattern . 2))
5895 "Source for completing and invoking Emacs commands.
5896 A command is a function with interactive spec that can
5897 be invoked with `M-x'.
5899 To get non-interactive functions listed, use
5900 `anything-c-source-emacs-functions'.")
5901 ;; (anything 'anything-c-source-emacs-commands)
5904 ;;;; <Function>
5905 ;;; Emacs functions
5908 (defvar anything-c-source-emacs-functions
5909 '((name . "Emacs Functions")
5910 (candidates . (lambda ()
5911 (let (commands)
5912 (mapatoms (lambda (a)
5913 (if (functionp a)
5914 (push (symbol-name a) commands))))
5915 (sort commands 'string-lessp))))
5916 (type . function)
5917 (requires-pattern . 2))
5918 "Source for completing Emacs functions.")
5919 ;; (anything 'anything-c-source-emacs-functions)
5921 ;;; With abbrev expansion
5922 ;;; Similar to my exec-abbrev-cmd.el
5923 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5924 (defvar anything-c-function-abbrev-regexp nil
5925 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5926 Regexp built from the current `anything-pattern' interpreting it
5927 as abbreviation.
5928 Only for internal use.")
5930 (defun anything-c-match-function-by-abbrev (candidate)
5931 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5933 Abbreviations are made by taking the first character from each
5934 word in the function's name, e.g. \"bb\" is an abbrev for
5935 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5936 (string-match anything-c-function-abbrev-regexp candidate))
5938 (defvar anything-c-source-emacs-functions-with-abbrevs
5939 (append anything-c-source-emacs-functions
5940 '((match anything-c-match-function-by-abbrev
5941 anything-c-string-match))
5942 '((init
5943 . (lambda ()
5944 (defadvice anything-update
5945 (before anything-c-update-function-abbrev-regexp activate)
5946 (let ((char-list (append anything-pattern nil))
5947 (str "^"))
5948 (dolist (c char-list)
5949 (setq str (concat str (list c) "[^-]*-")))
5950 (setq str (concat (substring str 0 (1- (length str))) "$"))
5951 (setq anything-c-function-abbrev-regexp str))))))))
5952 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5954 (defvar anything-c-source-advice
5955 '((name . "Function Advice")
5956 (candidates . anything-c-advice-candidates)
5957 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
5958 ;; (real-to-display . anything-c-advice-real-to-display)
5959 (persistent-action . anything-c-advice-persistent-action)
5960 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
5961 ;; (anything 'anything-c-source-advice)
5962 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5963 ;; (testadvice)
5965 (defun anything-c-advice-candidates ()
5966 (require 'advice)
5967 (loop for (fname) in ad-advised-functions
5968 for function = (intern fname)
5969 append
5970 (loop for class in ad-advice-classes append
5971 (loop for advice in (ad-get-advice-info-field function class)
5972 for enabled = (ad-advice-enabled advice)
5973 collect
5974 (cons (format
5975 "%s %s %s"
5976 (if enabled "Enabled " "Disabled")
5977 (propertize fname 'face 'font-lock-function-name-face)
5978 (ad-make-single-advice-docstring advice class nil))
5979 (list function class advice))))))
5981 (defun anything-c-advice-persistent-action (func-class-advice)
5982 (if current-prefix-arg
5983 (anything-c-advice-toggle func-class-advice)
5984 (describe-function (car func-class-advice))))
5986 (defun anything-c-advice-toggle (func-class-advice)
5987 (destructuring-bind (function class advice) func-class-advice
5988 (cond ((ad-advice-enabled advice)
5989 (ad-advice-set-enabled advice nil)
5990 (message "Disabled"))
5991 (t ;disabled
5992 (ad-advice-set-enabled advice t)
5993 (message "Enabled")))
5994 (ad-activate function)
5995 (and anything-in-persistent-action
5996 (anything-c-advice-update-current-display-string))))
5998 (defun anything-c-advice-update-current-display-string ()
5999 (anything-edit-current-selection
6000 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6001 ((looking-at "Enabled") "Disabled")))
6002 realvalue)
6003 (when newword
6004 (delete-region (point) (progn (forward-word 1) (point)))
6005 (insert newword)))))
6008 ;;;; <Variable>
6009 ;;; Emacs variables
6012 (defvar anything-c-source-emacs-variables
6013 '((name . "Emacs Variables")
6014 (candidates . (lambda ()
6015 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6016 (type . variable)
6017 (requires-pattern . 2))
6018 "Source for completing Emacs variables.")
6019 ;; (anything 'anything-c-source-emacs-variables)
6022 ;;; LaCarte
6023 (defvar anything-c-source-lacarte
6024 '((name . "Lacarte")
6025 (init . (lambda () (require 'lacarte )))
6026 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6027 (candidate-number-limit . 9999)
6028 (action . anything-c-call-interactively))
6029 "Needs lacarte.el.
6031 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6032 ;; (anything 'anything-c-source-lacarte)
6035 ;;; Bookmarks
6038 ;; Bind some faces for bookmarks.
6039 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6040 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6041 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6043 (eval-when-compile (require 'bookmark))
6044 (defvar anything-c-source-bookmarks
6045 '((name . "Bookmarks")
6046 (init . (lambda ()
6047 (require 'bookmark)))
6048 (candidates . bookmark-all-names)
6049 (type . bookmark))
6050 "See (info \"(emacs)Bookmarks\").")
6051 ;; (anything 'anything-c-source-bookmarks)
6053 ;;; bookmark-set
6054 (defvar anything-c-source-bookmark-set
6055 '((name . "Set Bookmark")
6056 (dummy)
6057 (action . bookmark-set))
6058 "See (info \"(emacs)Bookmarks\").")
6059 ;; (anything 'anything-c-source-bookmark-set)
6061 ;;; Visible Bookmarks
6062 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6065 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6066 (defvar anything-c-source-bm
6067 '((name . "Visible Bookmarks")
6068 (init . anything-c-bm-init)
6069 (candidates-in-buffer)
6070 (type . line))
6071 "Needs bm.el.
6073 http://www.nongnu.org/bm/")
6075 (defun anything-c-bm-init ()
6076 "Init function for `anything-c-source-bm'."
6077 (when (require 'bm nil t)
6078 (with-no-warnings
6079 (let ((bookmarks (bm-lists))
6080 (buf (anything-candidate-buffer 'global)))
6081 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6082 '< :key 'overlay-start))
6083 (let ((start (overlay-start bm))
6084 (end (overlay-end bm))
6085 (annotation (or (overlay-get bm 'annotation) "")))
6086 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6087 (let ((str (format "%5d: [%s]: %s\n"
6088 (line-number-at-pos start)
6089 annotation
6090 (buffer-substring start (1- end)))))
6091 (with-current-buffer buf (insert str))))))))))
6093 ;;; Special bookmarks
6094 (defvar anything-c-source-bookmarks-ssh
6095 '((name . "Bookmarks-ssh")
6096 (init . (lambda ()
6097 (require 'bookmark)))
6098 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6099 (type . bookmark))
6100 "See (info \"(emacs)Bookmarks\").")
6101 ;; (anything 'anything-c-source-bookmarks-ssh)
6103 (defvar anything-c-source-bookmarks-su
6104 '((name . "Bookmarks-root")
6105 (init . (lambda ()
6106 (require 'bookmark)))
6107 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6108 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6110 (type . bookmark))
6111 "See (info \"(emacs)Bookmarks\").")
6112 ;; (anything 'anything-c-source-bookmarks-su)
6114 (defvar anything-c-source-bookmarks-local
6115 '((name . "Bookmarks-Local")
6116 (init . (lambda ()
6117 (require 'bookmark)))
6118 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6119 (filtered-candidate-transformer
6120 anything-c-adaptive-sort
6121 anything-c-highlight-bookmark)
6122 (type . bookmark))
6123 "See (info \"(emacs)Bookmarks\").")
6124 ;; (anything 'anything-c-source-bookmarks-local)
6126 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6127 (let* ((lis-all (bookmark-all-names))
6128 (lis-loc (cond (local (loop for i in lis-all
6129 unless (string-match "^(ssh)\\|^(su)" i)
6130 collect i))
6131 (su (loop for i in lis-all
6132 when (string-match "^(su)" i)
6133 collect i))
6134 (sudo (loop for i in lis-all
6135 when (string-match "^(sudo)" i)
6136 collect i))
6137 (ssh (loop for i in lis-all
6138 when (string-match "^(ssh)" i)
6139 collect i)))))
6140 (sort lis-loc 'string-lessp)))
6142 (defun anything-c-bookmark-root-logged-p ()
6143 (catch 'break
6144 (dolist (i (mapcar #'buffer-name (buffer-list)))
6145 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6146 (throw 'break t)))))
6148 (defun anything-c-highlight-bookmark-su (files source)
6149 (if (anything-c-bookmark-root-logged-p)
6150 (anything-c-highlight-bookmark files source)
6151 (anything-c-highlight-not-logged files source)))
6153 (defun anything-c-highlight-not-logged (files source)
6154 (loop for i in files
6155 collect (propertize i 'face anything-c-bookmarks-face3)))
6157 (defun anything-c-highlight-bookmark (bookmarks source)
6158 "Used as `candidate-transformer' to colorize bookmarks.
6159 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6160 (loop for i in bookmarks
6161 for isfile = (bookmark-get-filename i)
6162 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6163 (bmkext-get-buffer-name i))
6164 for handlerp = (and (fboundp 'bookmark-get-handler)
6165 (bookmark-get-handler i))
6166 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6167 (bmkext-w3m-bookmark-p i))
6168 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6169 (bmkext-gnus-bookmark-p i))
6170 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6171 (bmkext-man-bookmark-p i))
6172 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6173 (bmkext-woman-bookmark-p i))
6174 for handlerp = (bookmark-get-handler i)
6175 for isannotation = (bookmark-get-annotation i)
6176 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6177 for isinfo = (eq handlerp 'Info-bookmark-jump)
6178 ;; Add a * if bookmark have annotation
6179 if (and isannotation (not (string-equal isannotation "")))
6180 do (setq i (concat "*" i))
6181 collect (cond (;; info buffers
6182 isinfo
6183 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6184 (;; w3m buffers
6185 isw3m
6186 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6187 (;; gnus buffers
6188 isgnus
6189 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6190 (;; Man Woman
6191 (or iswoman isman)
6192 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6193 (;; Addressbook
6194 isabook
6195 (propertize i 'face '((:foreground "Tomato"))))
6196 (;; directories
6197 (and isfile (file-directory-p isfile))
6198 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6199 (;; regular files
6201 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6205 ;;; Sources to filter bookmark-extensions bookmarks.
6208 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6209 ;; If you want to enable google-maps in addressbook you will need
6210 ;; Julien Danjou google-maps-el package available here:
6211 ;; http://julien.danjou.info/google-maps-el.html
6213 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6214 "Return a filtered `bookmark-alist' sorted alphabetically."
6215 (loop
6216 with alist = (if args
6217 (apply #'(lambda (x) (funcall fn x)) args)
6218 (funcall fn))
6219 for i in alist
6220 for b = (car i)
6221 collect b into sa
6222 finally return (sort sa 'string-lessp)))
6224 ;;; Addressbook.
6227 (defvar anything-c-source-bmkext-addressbook
6228 '((name . "Bookmark Addressbook")
6229 (init . (lambda ()
6230 (require 'bookmark-extensions)
6231 (bookmark-maybe-load-default-file)))
6232 (candidates . anything-c-bmkext-addressbook-setup-alist)
6233 (persistent-action
6234 . (lambda (candidate)
6235 (let ((bmk (anything-bookmark-get-bookmark-from-name
6236 candidate)))
6237 (bookmark--jump-via bmk 'pop-to-buffer))))
6238 (persistent-help . "Show contact - Prefix with C-u to append")
6239 (filtered-candidate-transformer
6240 anything-c-adaptive-sort
6241 anything-c-highlight-bookmark)
6242 (action . (("Show Contact(s)"
6243 . (lambda (candidate)
6244 (let* ((contacts (anything-marked-candidates))
6245 (current-prefix-arg (or anything-current-prefix-arg
6246 (> (length contacts) 1))))
6247 (bookmark-jump
6248 (anything-bookmark-get-bookmark-from-name (car contacts)))
6249 (anything-aif (cdr contacts)
6250 (loop for bmk in it do
6251 (bookmark-jump
6252 (anything-bookmark-get-bookmark-from-name bmk)))))))
6253 ("Send Mail"
6254 . (lambda (candidate)
6255 (let* ((contacts (anything-marked-candidates))
6256 (bmk (anything-bookmark-get-bookmark-from-name
6257 (car contacts)))
6258 (append (message-buffers)))
6259 (if append
6260 (addressbook-set-mail-buffer1 bmk 'append)
6261 (addressbook-set-mail-buffer1 bmk))
6262 (setq contacts (cdr contacts))
6263 (when contacts
6264 (loop for bmk in contacts do
6265 (addressbook-set-mail-buffer1 bmk 'append))))))
6266 ("Edit Bookmark"
6267 . (lambda (candidate)
6268 (let ((bmk (anything-bookmark-get-bookmark-from-name
6269 candidate)))
6270 (addressbook-bookmark-edit
6271 (assoc bmk bookmark-alist)))))
6272 ("Insert Email at point"
6273 . (lambda (candidate)
6274 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6275 candidate))
6276 (mlist (split-string
6277 (assoc-default
6278 'email (assoc bmk bookmark-alist))
6279 ", ")))
6280 (insert
6281 (if (> (length mlist) 1)
6282 (anything-comp-read
6283 "Insert Mail Address: " mlist :must-match t)
6284 (car mlist))))))
6285 ("Show annotation"
6286 . (lambda (candidate)
6287 (let ((bmk (anything-bookmark-get-bookmark-from-name
6288 candidate)))
6289 (bookmark-show-annotation bmk))))
6290 ("Edit annotation"
6291 . (lambda (candidate)
6292 (let ((bmk (anything-bookmark-get-bookmark-from-name
6293 candidate)))
6294 (bookmark-edit-annotation bmk))))
6295 ("Show Google map"
6296 . (lambda (candidate)
6297 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6298 candidate))
6299 (full-bmk (assoc bmk bookmark-alist)))
6300 (addressbook-google-map full-bmk))))))))
6303 (defun anything-c-bmkext-addressbook-setup-alist ()
6304 "Specialized filter function for bookmarks w3m."
6305 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6307 ;; W3m bookmarks from bookmark-extensions.
6308 (defvar anything-c-source-bookmark-w3m
6309 '((name . "Bookmark W3m")
6310 (init . (lambda ()
6311 (require 'bookmark-extensions)
6312 (bookmark-maybe-load-default-file)))
6313 (candidates . anything-c-bookmark-w3m-setup-alist)
6314 (filtered-candidate-transformer
6315 anything-c-adaptive-sort
6316 anything-c-highlight-bookmark)
6317 (type . bookmark)))
6318 ;; (anything 'anything-c-source-bookmark-w3m)
6320 (defun anything-c-bookmark-w3m-setup-alist ()
6321 "Specialized filter function for bookmarks w3m."
6322 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6324 ;; Images
6325 (defvar anything-c-source-bookmark-images
6326 '((name . "Bookmark Images")
6327 (init . (lambda ()
6328 (require 'bookmark-extensions)
6329 (bookmark-maybe-load-default-file)))
6330 (candidates . anything-c-bookmark-images-setup-alist)
6331 (filtered-candidate-transformer
6332 anything-c-adaptive-sort
6333 anything-c-highlight-bookmark)
6334 (type . bookmark)))
6335 ;; (anything 'anything-c-source-bookmark-images)
6337 (defun anything-c-bookmark-images-setup-alist ()
6338 "Specialized filter function for images bookmarks."
6339 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6341 ;; Woman Man
6342 (defvar anything-c-source-bookmark-man
6343 '((name . "Bookmark Woman&Man")
6344 (init . (lambda ()
6345 (require 'bookmark-extensions)
6346 (bookmark-maybe-load-default-file)))
6347 (candidates . anything-c-bookmark-man-setup-alist)
6348 (filtered-candidate-transformer
6349 anything-c-adaptive-sort
6350 anything-c-highlight-bookmark)
6351 (type . bookmark)))
6352 ;; (anything 'anything-c-source-bookmark-man)
6354 (defun anything-c-bookmark-man-setup-alist ()
6355 "Specialized filter function for bookmarks w3m."
6356 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6357 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6359 ;; Gnus
6360 (defvar anything-c-source-bookmark-gnus
6361 '((name . "Bookmark Gnus")
6362 (init . (lambda ()
6363 (require 'bookmark-extensions)
6364 (bookmark-maybe-load-default-file)))
6365 (candidates . anything-c-bookmark-gnus-setup-alist)
6366 (filtered-candidate-transformer
6367 anything-c-adaptive-sort
6368 anything-c-highlight-bookmark)
6369 (type . bookmark)))
6370 ;; (anything 'anything-c-source-bookmark-gnus)
6372 (defun anything-c-bookmark-gnus-setup-alist ()
6373 "Specialized filter function for bookmarks gnus."
6374 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6376 ;; Info
6377 (defvar anything-c-source-bookmark-info
6378 '((name . "Bookmark Info")
6379 (init . (lambda ()
6380 (require 'bookmark-extensions)
6381 (bookmark-maybe-load-default-file)))
6382 (candidates . anything-c-bookmark-info-setup-alist)
6383 (filtered-candidate-transformer
6384 anything-c-adaptive-sort
6385 anything-c-highlight-bookmark)
6386 (type . bookmark)))
6387 ;; (anything 'anything-c-source-bookmark-info)
6389 (defun anything-c-bookmark-info-setup-alist ()
6390 "Specialized filter function for bookmarks info."
6391 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6393 ;; Local Files&directories
6394 (defvar anything-c-source-bookmark-files&dirs
6395 '((name . "Bookmark Files&Directories")
6396 (init . (lambda ()
6397 (require 'bookmark-extensions)
6398 (bookmark-maybe-load-default-file)))
6399 (candidates . anything-c-bookmark-local-files-setup-alist)
6400 (filtered-candidate-transformer
6401 anything-c-adaptive-sort
6402 anything-c-highlight-bookmark)
6403 (type . bookmark)))
6404 ;; (anything 'anything-c-source-bookmark-files&dirs)
6406 (defun anything-c-bookmark-local-files-setup-alist ()
6407 "Specialized filter function for bookmarks locals files."
6408 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6410 ;; Su Files&directories
6411 (defvar anything-c-source-bookmark-su-files&dirs
6412 '((name . "Bookmark Root-Files&Directories")
6413 (init . (lambda ()
6414 (require 'bookmark-extensions)
6415 (bookmark-maybe-load-default-file)))
6416 (candidates . anything-c-bookmark-su-files-setup-alist)
6417 (filtered-candidate-transformer
6418 anything-c-adaptive-sort
6419 anything-c-highlight-bookmark-su)
6420 (type . bookmark)))
6421 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6423 (defun anything-c-bookmark-su-files-setup-alist ()
6424 "Specialized filter function for bookmarks su/sudo files."
6425 (declare (special bmkext-su-or-sudo-regexp))
6426 (loop
6427 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6428 for i in l
6429 for isfile = (bookmark-get-filename i)
6430 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6431 (save-match-data
6432 (string-match tramp-file-name-regexp isfile)))
6433 for issu = (and istramp
6434 (string-match bmkext-su-or-sudo-regexp isfile))
6435 if issu
6436 collect i))
6438 ;; Ssh Files&directories
6439 (defvar anything-c-source-bookmark-ssh-files&dirs
6440 '((name . "Bookmark Ssh-Files&Directories")
6441 (init . (lambda ()
6442 (require 'bookmark-extensions)
6443 (bookmark-maybe-load-default-file)))
6444 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6445 (filtered-candidate-transformer . anything-c-adaptive-sort)
6446 (type . bookmark)))
6447 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6449 (defun anything-c-bookmark-ssh-files-setup-alist ()
6450 "Specialized filter function for bookmarks ssh files."
6451 (loop
6452 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6453 for i in l
6454 for isfile = (bookmark-get-filename i)
6455 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6456 (save-match-data
6457 (string-match tramp-file-name-regexp isfile)))
6458 for isssh = (and istramp
6459 (string-match "/ssh:" isfile))
6460 if isssh
6461 collect i))
6465 ;;; Firefox bookmarks
6468 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6469 ;; (only for firefox versions >=3)
6470 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6471 ;; to true:
6472 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6473 ;; You should have now:
6474 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6476 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6477 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6479 (defun anything-get-firefox-user-init-dir ()
6480 "Guess the default Firefox user directory name."
6481 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6482 (moz-user-dir
6483 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6484 (goto-char (point-min))
6485 (prog1
6486 (when (search-forward "Path=" nil t)
6487 (buffer-substring-no-properties (point) (point-at-eol)))
6488 (kill-buffer)))))
6489 (file-name-as-directory (concat moz-dir moz-user-dir))))
6491 (defun anything-guess-firefox-bookmark-file ()
6492 "Return the path of the Firefox bookmarks file."
6493 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6495 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6496 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6497 (let (bookmarks-alist url title)
6498 (with-temp-buffer
6499 (insert-file-contents file)
6500 (goto-char (point-min))
6501 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6502 (forward-line 0)
6503 (when (re-search-forward url-regexp nil t)
6504 (setq url (match-string 0)))
6505 (when (re-search-forward bmk-regexp nil t)
6506 (setq title (match-string 1)))
6507 (push (cons title url) bookmarks-alist)
6508 (forward-line)))
6509 (nreverse bookmarks-alist)))
6511 (defvar anything-c-firefox-bookmarks-alist nil)
6512 (defvar anything-c-source-firefox-bookmarks
6513 '((name . "Firefox Bookmarks")
6514 (init . (lambda ()
6515 (setq anything-c-firefox-bookmarks-alist
6516 (anything-html-bookmarks-to-alist
6517 (anything-guess-firefox-bookmark-file)
6518 anything-firefox-bookmark-url-regexp
6519 anything-firefox-bookmarks-regexp))))
6520 (candidates . (lambda ()
6521 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6522 (filtered-candidate-transformer
6523 anything-c-adaptive-sort
6524 anything-c-highlight-firefox-bookmarks)
6525 (action . (("Browse Url Firefox"
6526 . (lambda (candidate)
6527 (browse-url-firefox
6528 (anything-c-firefox-bookmarks-get-value candidate))))
6529 ("Browse Url w3m"
6530 . (lambda (candidate)
6531 (w3m-browse-url
6532 (anything-c-firefox-bookmarks-get-value candidate))))
6533 ("Copy Url"
6534 . (lambda (elm)
6535 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6537 ;; (anything 'anything-c-source-firefox-bookmarks)
6539 (defun anything-c-firefox-bookmarks-get-value (elm)
6540 (assoc-default elm anything-c-firefox-bookmarks-alist))
6542 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6543 (loop for i in bookmarks
6544 collect (propertize
6545 i 'face '((:foreground "YellowGreen"))
6546 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6550 ;;; W3m bookmark - anything interface.
6553 ;; Some users have the emacs-w3m library in load-path
6554 ;; without having the w3m executable :-;
6555 ;; So check if w3m program is present before trying to load
6556 ;; emacs-w3m.
6557 (eval-when-compile
6558 (when (executable-find "w3m")
6559 (require 'w3m-bookmark nil t)))
6561 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6562 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6563 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6564 (defvar anything-c-w3m-bookmarks-alist nil)
6565 (defvar anything-c-source-w3m-bookmarks
6566 '((name . "W3m Bookmarks")
6567 (init . (lambda ()
6568 (setq anything-c-w3m-bookmarks-alist
6569 (anything-html-bookmarks-to-alist
6570 w3m-bookmark-file
6571 anything-w3m-bookmark-url-regexp
6572 anything-w3m-bookmarks-regexp))))
6573 (candidates . (lambda ()
6574 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6575 (filtered-candidate-transformer
6576 anything-c-adaptive-sort
6577 anything-c-highlight-w3m-bookmarks)
6578 (action . (("Browse Url"
6579 . (lambda (candidate)
6580 (anything-c-w3m-browse-bookmark candidate)))
6581 ("Copy Url"
6582 . (lambda (elm)
6583 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6584 ("Browse Url Firefox"
6585 . (lambda (candidate)
6586 (anything-c-w3m-browse-bookmark candidate t)))
6587 ("Delete Bookmark"
6588 . (lambda (candidate)
6589 (anything-c-w3m-delete-bookmark candidate)))
6590 ("Rename Bookmark"
6591 . (lambda (candidate)
6592 (anything-c-w3m-rename-bookmark candidate)))))
6593 (persistent-action . (lambda (candidate)
6594 (if current-prefix-arg
6595 (anything-c-w3m-browse-bookmark candidate t)
6596 (anything-c-w3m-browse-bookmark candidate nil t))))
6597 (persistent-help . "Open URL with emacs-w3m in new tab / \
6598 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6599 "Needs w3m and emacs-w3m.
6601 http://w3m.sourceforge.net/
6602 http://emacs-w3m.namazu.org/")
6604 ;; (anything 'anything-c-source-w3m-bookmarks)
6606 (defun anything-c-w3m-bookmarks-get-value (elm)
6607 (replace-regexp-in-string
6608 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6610 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6611 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6612 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6613 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6615 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6616 (loop for i in bookmarks
6617 collect (propertize
6618 i 'face 'anything-w3m-bookmarks-face
6619 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6622 (defun anything-c-w3m-delete-bookmark (elm)
6623 "Delete w3m bookmark from `w3m-bookmark-file'."
6624 (with-current-buffer
6625 (find-file-literally w3m-bookmark-file)
6626 (goto-char (point-min))
6627 (when (re-search-forward elm nil t)
6628 (beginning-of-line)
6629 (delete-region (point)
6630 (line-end-position))
6631 (delete-blank-lines))
6632 (save-buffer)
6633 (kill-buffer)))
6635 (defun anything-c-w3m-rename-bookmark (elm)
6636 "Rename w3m bookmark in `w3m-bookmark-file'."
6637 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6638 (new-title (read-string "NewTitle: " old-title)))
6639 (with-current-buffer
6640 (find-file-literally w3m-bookmark-file)
6641 (goto-char (point-min))
6642 (when (re-search-forward (concat elm "<") nil t)
6643 (goto-char (1- (point)))
6644 (delete-char (- (length old-title)))
6645 (insert new-title))
6646 (save-buffer)
6647 (kill-buffer))))
6650 ;;;; <Library>
6651 ;;; Elisp library scan
6654 (defvar anything-c-source-elisp-library-scan
6655 '((name . "Elisp libraries (Scan)")
6656 (init . (anything-c-elisp-library-scan-init))
6657 (candidates-in-buffer)
6658 (action ("Find library"
6659 . (lambda (candidate) (find-file (find-library-name candidate))))
6660 ("Find library other window"
6661 . (lambda (candidate)
6662 (find-file-other-window (find-library-name candidate))))
6663 ("Load library"
6664 . (lambda (candidate) (load-library candidate))))))
6665 ;; (anything 'anything-c-source-elisp-library-scan)
6667 (defun anything-c-elisp-library-scan-init ()
6668 "Init anything buffer status."
6669 (let ((anything-buffer (anything-candidate-buffer 'global))
6670 (library-list (anything-c-elisp-library-scan-list)))
6671 (with-current-buffer anything-buffer
6672 (dolist (library library-list)
6673 (insert (format "%s\n" library))))))
6675 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6676 "Do completion for file names passed to `locate-file'.
6677 DIRS is directory to search path.
6678 STRING is string to match."
6679 ;; Use `load-path' as path when ignore `dirs'.
6680 (or dirs (setq dirs load-path))
6681 ;; Init with blank when ignore `string'.
6682 (or string (setq string ""))
6683 ;; Get library list.
6684 (let ((string-dir (file-name-directory string))
6685 ;; File regexp that suffix match `load-file-rep-suffixes'.
6686 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6687 name
6688 names)
6689 (dolist (dir dirs)
6690 (unless dir
6691 (setq dir default-directory))
6692 (if string-dir
6693 (setq dir (expand-file-name string-dir dir)))
6694 (when (file-directory-p dir)
6695 (dolist (file (file-name-all-completions
6696 (file-name-nondirectory string) dir))
6697 ;; Suffixes match `load-file-rep-suffixes'.
6698 (setq name (if string-dir (concat string-dir file) file))
6699 (if (string-match match-regexp name)
6700 (add-to-list 'names name)))))
6701 names))
6704 ;;;; <Programming>
6708 ;;; Imenu
6711 (defvar anything-c-imenu-delimiter " / ")
6713 (defvar anything-c-imenu-index-filter nil)
6714 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6716 (defvar anything-c-cached-imenu-alist nil)
6717 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6719 (defvar anything-c-cached-imenu-candidates nil)
6720 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6722 (defvar anything-c-cached-imenu-tick nil)
6723 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6725 (eval-when-compile (require 'imenu))
6726 (setq imenu-auto-rescan t)
6728 (defun anything-imenu-create-candidates (entry)
6729 "Create candidates with ENTRY."
6730 (if (listp (cdr entry))
6731 (mapcan
6732 (lambda (sub)
6733 (if (consp (cdr sub))
6734 (mapcar
6735 (lambda (subentry)
6736 (concat (car entry) anything-c-imenu-delimiter subentry))
6737 (anything-imenu-create-candidates sub))
6738 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6739 (cdr entry))
6740 (list entry)))
6742 (defvar anything-c-source-imenu
6743 '((name . "Imenu")
6744 (init . (lambda () (require 'imenu)))
6745 (candidates . anything-c-imenu-candidates)
6746 (persistent-action . (lambda (elm)
6747 (anything-c-imenu-default-action elm)
6748 (unless (fboundp 'semantic-imenu-tag-overlay)
6749 (anything-match-line-color-current-line))))
6750 (persistent-help . "Show this entry")
6751 (action . anything-c-imenu-default-action))
6752 "See (info \"(emacs)Imenu\")")
6754 ;; (anything 'anything-c-source-imenu)
6756 (defun anything-c-imenu-candidates ()
6757 (with-anything-current-buffer
6758 (let ((tick (buffer-modified-tick)))
6759 (if (eq anything-c-cached-imenu-tick tick)
6760 anything-c-cached-imenu-candidates
6761 (setq imenu--index-alist nil)
6762 (setq anything-c-cached-imenu-tick tick
6763 anything-c-cached-imenu-candidates
6764 (ignore-errors
6765 (mapcan
6766 'anything-imenu-create-candidates
6767 (setq anything-c-cached-imenu-alist
6768 (let ((index (imenu--make-index-alist)))
6769 (if anything-c-imenu-index-filter
6770 (funcall anything-c-imenu-index-filter index)
6771 index))))))
6772 (setq anything-c-cached-imenu-candidates
6773 (mapcar #'(lambda (x)
6774 (if (stringp x)
6776 (car x)))
6777 anything-c-cached-imenu-candidates))))))
6779 (setq imenu-default-goto-function 'imenu-default-goto-function)
6780 (defun anything-c-imenu-default-action (elm)
6781 "The default action for `anything-c-source-imenu'."
6782 (let ((path (split-string elm anything-c-imenu-delimiter))
6783 (alist anything-c-cached-imenu-alist))
6784 (dolist (elm path)
6785 (setq alist (assoc elm alist)))
6786 (imenu alist)))
6790 ;;; Ctags
6793 (defvar anything-c-ctags-modes
6794 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6795 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6796 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6798 (defun anything-c-source-ctags-init ()
6799 (when (and buffer-file-name
6800 (memq major-mode anything-c-ctags-modes)
6801 (anything-current-buffer-is-modified))
6802 (with-current-buffer (anything-candidate-buffer 'local)
6803 (call-process-shell-command
6804 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6805 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6806 anything-buffer-file-name)
6807 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6808 nil (current-buffer))
6809 (goto-char (point-min))
6810 (forward-line 2)
6811 (delete-region (point-min) (point))
6812 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6813 for lineno-start = (point)
6814 for lineno = (buffer-substring
6815 lineno-start
6816 (1- (search-forward "," (point-at-eol) t)))
6818 (beginning-of-line)
6819 (insert (format "%5s:" lineno))
6820 (search-forward "\177" (point-at-eol) t)
6821 (delete-region (1- (point)) (point-at-eol))
6822 (forward-line 1)))))
6824 (defvar anything-c-source-ctags
6825 '((name . "Exuberant ctags")
6826 (init . anything-c-source-ctags-init)
6827 (candidates-in-buffer)
6828 (adjust)
6829 (type . line))
6830 "Needs Exuberant Ctags.
6832 http://ctags.sourceforge.net/")
6833 ;; (anything 'anything-c-source-ctags)
6836 ;;; Etags
6839 ;; anything-etags.el is deprecated, if this file is found,
6840 ;; warn user at compile time.
6841 (eval-when-compile
6842 (when (locate-library "anything-etags.el")
6843 (display-warning
6844 '(anything-config)
6845 "You are using obsolete library `anything-etags.el' and should remove it."
6846 :warning)))
6848 (defvar anything-c-etags-tag-file-dir nil
6849 "Etags file directory.")
6850 (defvar anything-c-etags-mtime-alist nil
6851 "Store the last modification time of etags files here.")
6852 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6853 "Cache content of etags files used here for faster access.")
6855 (defun anything-c-etags-get-tag-file (&optional directory)
6856 "Return the path of etags file if found."
6857 ;; Get tag file from `default-directory' or upper directory.
6858 (let ((current-dir (anything-c-etags-find-tag-file-directory
6859 (or directory default-directory))))
6860 ;; Return nil if not find tag file.
6861 (when current-dir
6862 ;; Set tag file directory.
6863 (setq anything-c-etags-tag-file-dir current-dir)
6864 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6866 (defun anything-c-etags-find-tag-file-directory (current-dir)
6867 "Try to find the directory containing tag file.
6868 If not found in CURRENT-DIR search in upper directory."
6869 (flet ((file-exists? (dir)
6870 (let ((tag-path (expand-file-name
6871 anything-c-etags-tag-file-name dir)))
6872 (and (stringp tag-path)
6873 (file-exists-p tag-path)
6874 (file-readable-p tag-path)))))
6875 (loop with count = 0
6876 until (file-exists? current-dir)
6877 ;; Return nil if outside the value of
6878 ;; `anything-c-etags-tag-file-search-limit'.
6879 if (= count anything-c-etags-tag-file-search-limit)
6880 do (return nil)
6881 ;; Or search upper directories.
6882 else
6883 do (incf count)
6884 (setq current-dir (expand-file-name (concat current-dir "../")))
6885 finally return current-dir)))
6887 (defun anything-c-source-etags-header-name (x)
6888 "Create header name for this anything etags session."
6889 (concat "Etags in "
6890 (with-anything-current-buffer
6891 (anything-c-etags-get-tag-file))))
6893 (defmacro anything-c-etags-create-buffer (file)
6894 "Create the `anything-buffer' based on contents of etags tag FILE."
6895 `(let* ((tag-fname ,file)
6897 (split (with-current-buffer (find-file-noselect tag-fname)
6898 (prog1
6899 (split-string (buffer-string) "\n" 'omit-nulls)
6900 (setq max (line-number-at-pos (point-max)))
6901 (kill-buffer))))
6902 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6903 (loop
6904 with fname
6905 with cand
6906 for i in split for count from 0
6907 for elm = (unless (string-match "^\x0c" i)
6908 (anything-aif (string-match "\177" i)
6909 (substring i 0 it)
6911 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6912 (setq fname (match-string 1 elm)))
6913 (elm (setq cand (concat fname ": " elm)))
6914 (t (setq cand nil)))
6915 when cand do (progn
6916 (insert (concat cand "\n"))
6917 (progress-reporter-update progress-reporter count)))))
6919 (defun anything-c-etags-init ()
6920 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6921 If no entry in cache, create one."
6922 (let ((tagfile (anything-c-etags-get-tag-file)))
6923 (when tagfile
6924 (with-current-buffer (anything-candidate-buffer 'global)
6925 (anything-aif (gethash tagfile anything-c-etags-cache)
6926 ;; An entry is present in cache, insert it.
6927 (insert it)
6928 ;; No entry, create a new buffer using content of tag file (slower).
6929 (anything-c-etags-create-buffer tagfile)
6930 ;; Store content of buffer in cache.
6931 (puthash tagfile (buffer-string) anything-c-etags-cache)
6932 ;; Store or set the last modification of tag file.
6933 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6934 ;; If an entry exists modify it.
6935 (setcdr it (anything-c-etags-mtime tagfile))
6936 ;; No entry create a new one.
6937 (add-to-list 'anything-c-etags-mtime-alist
6938 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6940 (defvar anything-c-source-etags-select
6941 '((name . "Etags")
6942 (header-name . anything-c-source-etags-header-name)
6943 (init . anything-c-etags-init)
6944 (candidates-in-buffer)
6945 (search . (anything-c-etags-search-fn))
6946 (mode-line . anything-etags-mode-line-string)
6947 (action . anything-c-etags-default-action)
6948 (persistent-action . (lambda (candidate)
6949 (anything-c-etags-default-action candidate)
6950 (anything-match-line-color-current-line))))
6951 "Anything source for Etags.")
6953 (defun anything-c-etags-search-fn (pattern bound noerror)
6954 "Search function for `anything-c-source-etags-select'."
6955 (re-search-forward
6956 (if anything-c-etags-use-regexp-search (concat "\\_<" pattern) pattern)
6957 bound noerror))
6959 (defun anything-c-etags-default-action (candidate)
6960 "Anything default action to jump to an etags entry."
6961 (let* ((split (split-string candidate ": "))
6962 (fname (expand-file-name
6963 (car split) anything-c-etags-tag-file-dir))
6964 (elm (cadr split)))
6965 (find-file fname)
6966 (goto-char (point-min))
6967 (search-forward elm nil t)
6968 (goto-char (match-beginning 0))))
6970 (defun anything-c-etags-mtime (file)
6971 "Last modification time of etags tag FILE."
6972 (cadr (nth 5 (file-attributes file))))
6974 (defun anything-c-etags-file-modified-p (file)
6975 "Check if tag FILE have been modified in this session.
6976 If FILE is nil return nil."
6977 (let ((last-modif (and file
6978 (assoc-default file anything-c-etags-mtime-alist))))
6979 (and last-modif
6980 (/= last-modif (anything-c-etags-mtime file)))))
6984 ;;; Semantic
6987 (defvar anything-semantic-candidates nil)
6989 (defun anything-semantic-construct-candidates (tags depth)
6990 (when (require 'semantic nil t)
6991 (apply
6992 'append
6993 (mapcar
6994 (lambda (tag)
6995 (if (listp tag)
6996 (let ((type (semantic-tag-type tag))
6997 (class (semantic-tag-class tag)))
6998 (if (or (and (stringp type)
6999 (or (string= type "class")
7000 (string= type "namespace")))
7001 (eq class 'function)
7002 (eq class 'variable))
7003 (cons (cons (concat (make-string (* depth 2) ?\s)
7004 (semantic-format-tag-summarize tag nil t))
7005 tag)
7006 (anything-semantic-construct-candidates
7007 (semantic-tag-components tag) (1+ depth)))))))
7008 tags))))
7010 (defun anything-semantic-default-action (candidate)
7011 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7012 (semantic-go-to-tag tag)))
7014 (defvar anything-c-source-semantic
7015 '((name . "Semantic Tags")
7016 (init . (lambda ()
7017 (setq anything-semantic-candidates
7018 (ignore-errors (anything-semantic-construct-candidates
7019 (semantic-fetch-tags) 0)))))
7020 (candidates . (lambda ()
7021 (if anything-semantic-candidates
7022 (mapcar 'car anything-semantic-candidates))))
7023 (persistent-action . (lambda (elm)
7024 (anything-semantic-default-action elm)
7025 (anything-match-line-color-current-line)))
7026 (persistent-help . "Show this entry")
7027 (action . anything-semantic-default-action)
7028 "Needs semantic in CEDET.
7030 http://cedet.sourceforge.net/semantic.shtml
7031 http://cedet.sourceforge.net/"))
7033 ;; (anything 'anything-c-source-semantic)
7036 ;;; Anything interface of `simple-call-tree.el'.
7038 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7040 ;; Function is called by
7041 (defvar anything-c-source-simple-call-tree-functions-callers
7042 '((name . "Function is called by")
7043 (init . anything-c-simple-call-tree-functions-callers-init)
7044 (multiline)
7045 (candidates . anything-c-simple-call-tree-candidates)
7046 (persistent-action . anything-c-simple-call-tree-persistent-action)
7047 (persistent-help . "Show function definitions by rotation")
7048 (action ("Find definition selected by persistent-action" .
7049 anything-c-simple-call-tree-find-definition)))
7050 "Needs simple-call-tree.el.
7051 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7053 (defvar anything-c-simple-call-tree-tick nil)
7054 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7055 (defun anything-c-simple-call-tree-analyze-maybe ()
7056 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7057 (simple-call-tree-analyze)
7058 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7060 (defun anything-c-simple-call-tree-init-base (function message)
7061 (require 'simple-call-tree)
7062 (with-no-warnings
7063 (when (anything-current-buffer-is-modified)
7064 (anything-c-simple-call-tree-analyze-maybe)
7065 (let ((list (funcall function simple-call-tree-alist)))
7066 (with-current-buffer (anything-candidate-buffer 'local)
7067 (dolist (entry list)
7068 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7069 (insert (car entry) message
7070 (if (string= funcs " ")
7071 " no functions."
7072 funcs)
7073 "\n\n"))))))))
7075 (defun anything-c-simple-call-tree-functions-callers-init ()
7076 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7077 " is called by\n"))
7079 (defun anything-c-simple-call-tree-candidates ()
7080 (with-current-buffer (anything-candidate-buffer)
7081 (split-string (buffer-string) "\n\n")))
7083 (defvar anything-c-simple-call-tree-related-functions nil)
7084 (defvar anything-c-simple-call-tree-function-index 0)
7085 (defun anything-c-simple-call-tree-persistent-action (candidate)
7086 (unless (eq last-command 'anything-execute-persistent-action)
7087 (setq anything-c-simple-call-tree-related-functions
7088 (delete "no functions."
7089 (split-string
7090 (replace-regexp-in-string " \\| is called by\\| calls "
7091 "" candidate)
7092 "\n")))
7093 (setq anything-c-simple-call-tree-function-index -1))
7094 (incf anything-c-simple-call-tree-function-index)
7095 (anything-c-simple-call-tree-find-definition candidate))
7097 (defun anything-c-simple-call-tree-find-definition (candidate)
7098 (find-function
7099 (intern
7100 (nth (mod anything-c-simple-call-tree-function-index
7101 (length anything-c-simple-call-tree-related-functions))
7102 anything-c-simple-call-tree-related-functions))))
7104 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7106 ;;; Function calls
7107 (defvar anything-c-source-simple-call-tree-callers-functions
7108 '((name . "Function calls")
7109 (init . anything-c-simple-call-tree-callers-functions-init)
7110 (multiline)
7111 (candidates . anything-c-simple-call-tree-candidates)
7112 (persistent-action . anything-c-simple-call-tree-persistent-action)
7113 (persistent-help . "Show function definitions by rotation")
7114 (action ("Find definition selected by persistent-action" .
7115 anything-c-simple-call-tree-find-definition)))
7116 "Needs simple-call-tree.el.
7117 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7119 (defun anything-c-simple-call-tree-callers-functions-init ()
7120 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7122 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7126 ;;; Anything UI of auto-document.el
7128 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7130 ;; Commands/Options with doc
7131 (defvar anything-c-auto-document-data nil)
7132 (make-variable-buffer-local 'anything-c-auto-document-data)
7133 (defvar anything-c-source-commands-and-options-in-file
7134 '((name . "Commands/Options in file")
7135 (header-name
7136 . (lambda (x) (format "Commands/Options in %s"
7137 (buffer-local-value 'buffer-file-name
7138 anything-current-buffer))))
7139 (candidates . anything-command-and-options-candidates)
7140 (multiline)
7141 (action . imenu))
7142 "List Commands and Options with doc. It needs auto-document.el .
7144 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7146 (eval-when-compile (require 'auto-document nil t))
7147 (defun anything-command-and-options-candidates ()
7148 (with-anything-current-buffer
7149 (when (and (require 'auto-document nil t)
7150 (eq major-mode 'emacs-lisp-mode)
7151 (or (anything-current-buffer-is-modified)
7152 (not anything-c-auto-document-data)))
7153 (or imenu--index-alist (imenu--make-index-alist t))
7154 (setq anything-c-auto-document-data
7155 (destructuring-bind (commands options)
7156 (adoc-construct anything-current-buffer)
7157 (append
7158 (loop for (command . doc) in commands
7159 for cmdname = (symbol-name command)
7160 collect
7161 (cons
7162 (format "Command: %s\n %s"
7163 (propertize cmdname 'face font-lock-function-name-face)
7164 (adoc-first-line doc))
7165 (assoc cmdname imenu--index-alist)))
7166 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7167 for (option doc default) in options
7168 for optname = (symbol-name option)
7169 collect
7170 (cons
7171 (format "Option: %s\n %s\n default = %s"
7172 (propertize optname 'face font-lock-variable-name-face)
7173 (adoc-first-line doc)
7174 (adoc-prin1-to-string default))
7175 (assoc optname
7176 var-alist)))))))
7177 anything-c-auto-document-data))
7179 ;; (anything 'anything-c-source-commands-and-options-in-file)
7182 ;;;; <Color and Face>
7185 ;;; Customize Face
7188 (defvar anything-c-source-customize-face
7189 '((name . "Customize Face")
7190 (init . (lambda ()
7191 (unless (anything-candidate-buffer)
7192 (save-window-excursion (list-faces-display))
7193 (anything-candidate-buffer (get-buffer "*Faces*")))))
7194 (candidates-in-buffer)
7195 (get-line . buffer-substring)
7196 (action . (lambda (line)
7197 (customize-face (intern (car (split-string line))))))
7198 (requires-pattern . 3))
7199 "See (info \"(emacs)Faces\")")
7200 ;; (anything 'anything-c-source-customize-face)
7202 ;;; Colors browser
7205 (defvar anything-c-source-colors
7206 '((name . "Colors")
7207 (init . (lambda () (unless (anything-candidate-buffer)
7208 (save-window-excursion (list-colors-display))
7209 (anything-candidate-buffer (get-buffer "*Colors*")))))
7210 (candidates-in-buffer)
7211 (get-line . buffer-substring)
7212 (action
7213 ("Copy Name" . (lambda (candidate)
7214 (kill-new (anything-c-colors-get-name candidate))))
7215 ("Copy RGB" . (lambda (candidate)
7216 (kill-new (anything-c-colors-get-rgb candidate))))
7217 ("Insert Name" . (lambda (candidate)
7218 (with-anything-current-buffer
7219 (insert (anything-c-colors-get-name candidate)))))
7220 ("Insert RGB" . (lambda (candidate)
7221 (with-anything-current-buffer
7222 (insert (anything-c-colors-get-rgb candidate))))))))
7223 ;; (anything 'anything-c-source-colors)
7225 (defun anything-c-colors-get-name (candidate)
7226 "Get color name."
7227 (replace-regexp-in-string
7228 " " ""
7229 (with-temp-buffer
7230 (insert (capitalize candidate))
7231 (goto-char (point-min))
7232 (search-forward-regexp "\\s-\\{2,\\}")
7233 (delete-region (point) (point-max))
7234 (buffer-string))))
7236 (defun anything-c-colors-get-rgb (candidate)
7237 "Get color RGB."
7238 (replace-regexp-in-string
7239 " " ""
7240 (with-temp-buffer
7241 (insert (capitalize candidate))
7242 (goto-char (point-max))
7243 (search-backward-regexp "\\s-\\{2,\\}")
7244 (delete-region (point) (point-min))
7245 (buffer-string))))
7248 ;;;; <Search Engine>
7249 ;;; Tracker desktop search
7250 (defvar anything-c-source-tracker-search
7251 '((name . "Tracker Search")
7252 (candidates . (lambda ()
7253 (start-process "tracker-search-process" nil
7254 "tracker-search"
7255 anything-pattern)))
7256 (type . file)
7257 (requires-pattern . 3)
7258 (delayed))
7259 "Source for retrieving files matching the current input pattern
7260 with the tracker desktop search.")
7261 ;; (anything 'anything-c-source-tracker-search)
7263 ;;; Spotlight (MacOS X desktop search)
7264 (defvar anything-c-source-mac-spotlight
7265 '((name . "mdfind")
7266 (candidates
7267 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7268 (type . file)
7269 (requires-pattern . 3)
7270 (delayed))
7271 "Source for retrieving files via Spotlight's command line
7272 utility mdfind.")
7273 ;; (anything 'anything-c-source-mac-spotlight)
7275 ;;; Picklist
7276 (defvar anything-c-source-picklist
7277 '((name . "Picklist")
7278 (candidates . (lambda () (mapcar 'car picklist-list)))
7279 (type . file)))
7280 ;; (anything 'anything-c-source-picklist)
7284 ;;; Kill ring
7287 (defvar anything-c-source-kill-ring
7288 '((name . "Kill Ring")
7289 (init . (lambda () (anything-attrset 'last-command last-command)))
7290 (candidates . anything-c-kill-ring-candidates)
7291 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7292 (action . anything-c-kill-ring-action)
7293 (last-command)
7294 (migemo)
7295 (multiline))
7296 "Source for browse and insert contents of kill-ring.")
7298 (defun anything-c-kill-ring-candidates ()
7299 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7300 unless (or (< (length kill) anything-kill-ring-threshold)
7301 (string-match "^[\\s\\t]+$" kill))
7302 collect kill))
7304 (defun anything-c-kill-ring-transformer (candidates source)
7305 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7306 (loop for i in candidates
7307 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7308 if (and anything-c-kill-ring-max-lines-number
7309 (> nlines anything-c-kill-ring-max-lines-number))
7310 collect (cons
7311 (with-temp-buffer
7312 (insert i)
7313 (goto-char (point-min))
7314 (concat
7315 (buffer-substring
7316 (point-min)
7317 (save-excursion
7318 (forward-line anything-c-kill-ring-max-lines-number)
7319 (point)))
7320 "[...]")) i)
7321 else collect i))
7323 (defun anything-c-kill-ring-action (str)
7324 "Insert STR in `kill-ring' and set STR to the head.
7325 If this action is executed just after `yank',
7326 replace with STR as yanked string."
7327 (setq kill-ring (delete str kill-ring))
7328 (if (not (eq (anything-attr 'last-command) 'yank))
7329 (insert-for-yank str)
7330 ;; from `yank-pop'
7331 (let ((inhibit-read-only t)
7332 (before (< (point) (mark t))))
7333 (if before
7334 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7335 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7336 (setq yank-undo-function nil)
7337 (set-marker (mark-marker) (point) (current-buffer))
7338 (insert-for-yank str)
7339 ;; Set the window start back where it was in the yank command,
7340 ;; if possible.
7341 (set-window-start (selected-window) yank-window-start t)
7342 (if before
7343 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7344 ;; It is cleaner to avoid activation, even though the command
7345 ;; loop would deactivate the mark because we inserted text.
7346 (goto-char (prog1 (mark t)
7347 (set-marker (mark-marker) (point) (current-buffer)))))))
7348 (kill-new str))
7350 ;; (anything 'anything-c-source-kill-ring)
7353 ;;;; <Mark ring>
7354 ;; DO NOT include these sources in `anything-sources' use
7355 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7356 ;; `anything-all-mark-rings' instead.
7358 (defun anything-c-source-mark-ring-candidates ()
7359 (flet ((get-marks (pos)
7360 (save-excursion
7361 (goto-char pos)
7362 (beginning-of-line)
7363 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7364 (when (string= "" line)
7365 (setq line "<EMPTY LINE>"))
7366 (format "%7d: %s" (line-number-at-pos) line)))))
7367 (with-anything-current-buffer
7368 (loop
7369 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7370 with recip = nil
7371 for i in marks
7372 for m = (get-marks i)
7373 unless (member m recip)
7374 collect m into recip
7375 finally return recip))))
7377 (defvar anything-mark-ring-cache nil)
7378 (defvar anything-c-source-mark-ring
7379 '((name . "mark-ring")
7380 (init . (lambda ()
7381 (setq anything-mark-ring-cache
7382 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7383 (candidates . (lambda ()
7384 (anything-aif anything-mark-ring-cache
7385 it)))
7386 (action . (("Goto line"
7387 . (lambda (candidate)
7388 (anything-goto-line (string-to-number candidate))))))
7389 (persistent-action . (lambda (candidate)
7390 (anything-goto-line (string-to-number candidate))
7391 (anything-match-line-color-current-line)))
7392 (persistent-help . "Show this line")))
7394 ;; (anything 'anything-c-source-mark-ring)
7396 ;;; Global-mark-ring
7397 (defvar anything-c-source-global-mark-ring
7398 '((name . "global-mark-ring")
7399 (candidates . anything-c-source-global-mark-ring-candidates)
7400 (action . (("Goto line"
7401 . (lambda (candidate)
7402 (let ((items (split-string candidate ":")))
7403 (anything-c-switch-to-buffer (second items))
7404 (anything-goto-line (string-to-number (car items))))))))
7405 (persistent-action . (lambda (candidate)
7406 (let ((items (split-string candidate ":")))
7407 (anything-c-switch-to-buffer (second items))
7408 (anything-goto-line (string-to-number (car items)))
7409 (anything-match-line-color-current-line))))
7410 (persistent-help . "Show this line")))
7412 (defun anything-c-source-global-mark-ring-candidates ()
7413 (flet ((buf-fn (m)
7414 (with-current-buffer (marker-buffer m)
7415 (goto-char m)
7416 (beginning-of-line)
7417 (let (line)
7418 (if (string= "" line)
7419 (setq line "<EMPTY LINE>")
7420 (setq line (car (split-string (thing-at-point 'line)
7421 "[\n\r]"))))
7422 (format "%7d:%s: %s"
7423 (line-number-at-pos) (marker-buffer m) line)))))
7424 (loop
7425 with marks = global-mark-ring
7426 with recip = nil
7427 for i in marks
7428 for gm = (unless (or (string-match
7429 "^ " (format "%s" (marker-buffer i)))
7430 (null (marker-buffer i)))
7431 (buf-fn i))
7432 when (and gm (not (member gm recip)))
7433 collect gm into recip
7434 finally return recip)))
7436 ;; (anything 'anything-c-source-global-mark-ring)
7439 ;;;; <Register>
7440 ;;; Insert from register
7441 (defvar anything-c-source-register
7442 '((name . "Registers")
7443 (candidates . anything-c-register-candidates)
7444 (action-transformer . anything-c-register-action-transformer)
7445 (multiline)
7446 (action))
7447 "See (info \"(emacs)Registers\")")
7449 (defun anything-c-register-candidates ()
7450 "Collecting register contents and appropriate commands."
7451 (loop for (char . val) in register-alist
7452 for key = (single-key-description char)
7453 for string-actions =
7454 (cond
7455 ((numberp val)
7456 (list (int-to-string val)
7457 'insert-register
7458 'increment-register))
7459 ((markerp val)
7460 (let ((buf (marker-buffer val)))
7461 (if (null buf)
7462 (list "a marker in no buffer")
7463 (list (concat
7464 "a buffer position:"
7465 (buffer-name buf)
7466 ", position "
7467 (int-to-string (marker-position val)))
7468 'jump-to-register
7469 'insert-register))))
7470 ((and (consp val) (window-configuration-p (car val)))
7471 (list "window configuration."
7472 'jump-to-register))
7473 ((and (consp val) (frame-configuration-p (car val)))
7474 (list "frame configuration."
7475 'jump-to-register))
7476 ((and (consp val) (eq (car val) 'file))
7477 (list (concat "file:"
7478 (prin1-to-string (cdr val))
7479 ".")
7480 'jump-to-register))
7481 ((and (consp val) (eq (car val) 'file-query))
7482 (list (concat "file:a file-query reference: file "
7483 (car (cdr val))
7484 ", position "
7485 (int-to-string (car (cdr (cdr val))))
7486 ".")
7487 'jump-to-register))
7488 ((consp val)
7489 (let ((lines (format "%4d" (length val))))
7490 (list (format "%s: %s\n" lines
7491 (truncate-string-to-width
7492 (mapconcat 'identity (list (car val))
7493 ;; (mapconcat (lambda (y) y) val
7494 "^J") (- (window-width) 15)))
7495 'insert-register)))
7496 ((stringp val)
7497 (list ;; without properties
7498 (substring-no-properties val)
7499 'insert-register
7500 'append-to-register
7501 'prepend-to-register))
7503 "GARBAGE!"))
7504 collect (cons (format "register %3s: %s" key (car string-actions))
7505 (cons char (cdr string-actions)))))
7507 (defun anything-c-register-action-transformer (actions register-and-functions)
7508 "Decide actions by the contents of register."
7509 (loop with func-actions =
7510 '((insert-register
7511 "Insert Register" .
7512 (lambda (c) (insert-register (car c))))
7513 (jump-to-register
7514 "Jump to Register" .
7515 (lambda (c) (jump-to-register (car c))))
7516 (append-to-register
7517 "Append Region to Register" .
7518 (lambda (c) (append-to-register
7519 (car c) (region-beginning) (region-end))))
7520 (prepend-to-register
7521 "Prepend Region to Register" .
7522 (lambda (c) (prepend-to-register
7523 (car c) (region-beginning) (region-end))))
7524 (increment-register
7525 "Increment Prefix Arg to Register" .
7526 (lambda (c) (increment-register
7527 anything-current-prefix-arg (car c)))))
7528 for func in (cdr register-and-functions)
7529 for cell = (assq func func-actions)
7530 when cell
7531 collect (cdr cell)))
7533 ;; (anything 'anything-c-source-register)
7536 ;;; Latex completion
7537 (defun anything-c-latex-math-candidates ()
7538 "Collect candidates for latex math completion."
7539 (declare (special LaTeX-math-menu))
7540 (loop for i in (cddr LaTeX-math-menu)
7541 for elm = (loop for s in i when (vectorp s)
7542 collect (cons (aref s 0) (aref s 1)))
7543 append elm))
7545 (defvar anything-c-source-latex-math
7546 '((name . "Latex Math Menu")
7547 (init . (lambda ()
7548 (with-anything-current-buffer
7549 (LaTeX-math-mode 1))))
7550 (candidate-number-limit . 9999)
7551 (candidates . anything-c-latex-math-candidates)
7552 (action . (lambda (candidate)
7553 (call-interactively candidate)))))
7556 ;;;; <Headline Extraction>
7557 (defvar anything-c-source-fixme
7558 '((name . "TODO/FIXME/DRY comments")
7559 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7560 (adjust)
7561 (recenter))
7562 "Show TODO/FIXME/DRY comments in current file.")
7563 ;; (anything 'anything-c-source-fixme)
7565 (defvar anything-c-source-rd-headline
7566 '((name . "RD HeadLine")
7567 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7568 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7569 (migemo)
7570 (subexp . 1))
7571 "Show RD headlines.
7573 RD is Ruby's POD.
7574 http://en.wikipedia.org/wiki/Ruby_Document_format")
7575 ;; (anything 'anything-c-source-rd-headline)
7577 (defvar anything-c-source-oddmuse-headline
7578 '((name . "Oddmuse HeadLine")
7579 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7580 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7581 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7582 (migemo)
7583 (subexp . 1))
7584 "Show Oddmuse headlines, such as EmacsWiki.")
7585 ;; (anything 'anything-c-source-oddmuse-headline)
7587 (defvar anything-c-source-emacs-source-defun
7588 '((name . "Emacs Source DEFUN")
7589 (headline . "DEFUN\\|DEFVAR")
7590 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7591 (or buffer-file-name ""))))
7592 "Show DEFUN/DEFVAR in Emacs C source file.")
7593 ;; (anything 'anything-c-source-emacs-source-defun)
7595 (defvar anything-c-source-emacs-lisp-expectations
7596 '((name . "Emacs Lisp Expectations")
7597 (headline . "(desc[ ]\\|(expectations")
7598 (condition . (eq major-mode 'emacs-lisp-mode)))
7599 "Show descriptions (desc) in Emacs Lisp Expectations.
7601 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7602 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7604 (defvar anything-c-source-emacs-lisp-toplevels
7605 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7606 (headline . "^(\\|(@\\*\\|^;;;;")
7607 (get-line . buffer-substring)
7608 (condition . (eq major-mode 'emacs-lisp-mode))
7609 (adjust))
7610 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7611 linkd.el is optional because linkd stars are extracted by regexp.
7612 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7613 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7616 ;;; Anything yaoddmuse
7618 ;; Be sure to have yaoddmuse.el installed
7619 ;; install-elisp may be required if you want to install elisp file from here.
7620 (defvar anything-yaoddmuse-use-cache-file nil)
7621 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7622 (defvar anything-c-yaoddmuse-ew-cache nil)
7624 (defun anything-yaoddmuse-get-candidates ()
7625 (declare (special yaoddmuse-pages-hash))
7626 (if anything-yaoddmuse-use-cache-file
7627 (ignore-errors
7628 (unless anything-c-yaoddmuse-ew-cache
7629 (load anything-c-yaoddmuse-cache-file)
7630 (setq anything-c-yaoddmuse-ew-cache
7631 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7632 anything-c-yaoddmuse-ew-cache)
7633 (yaoddmuse-update-pagename t)
7634 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7636 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7637 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7638 (candidates . anything-yaoddmuse-get-candidates)
7639 (action . (("Edit page" . (lambda (candidate)
7640 (yaoddmuse-edit "EmacsWiki" candidate)))
7641 ("Browse page"
7642 . (lambda (candidate)
7643 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7644 ("Browse page other window"
7645 . (lambda (candidate)
7646 (if (one-window-p)
7647 (split-window-vertically))
7648 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7649 ("Browse diff"
7650 . (lambda (candidate)
7651 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7652 ("Copy URL"
7653 . (lambda (candidate)
7654 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7655 (message "Have copy page %s's URL to yank." candidate)))
7656 ("Create page"
7657 . (lambda (candidate)
7658 (yaoddmuse-edit "EmacsWiki" anything-input)))
7659 ("Update cache"
7660 . (lambda (candidate)
7661 (if anything-yaoddmuse-use-cache-file
7662 (progn
7663 (anything-yaoddmuse-cache-pages t)
7664 (setq anything-c-yaoddmuse-ew-cache
7665 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7666 (yaoddmuse-update-pagename))))))
7667 (action-transformer anything-c-yaoddmuse-action-transformer))
7668 "Needs yaoddmuse.el.
7670 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7672 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7674 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7675 '((name . "Yaoddmuse Post library (EmacsWiki)")
7676 (init . (anything-yaoddmuse-init))
7677 (candidates-in-buffer)
7678 (action . (("Post library and Browse"
7679 . (lambda (candidate)
7680 (yaoddmuse-post-file
7681 (find-library-name candidate)
7682 "EmacsWiki"
7683 (file-name-nondirectory (find-library-name candidate))
7684 nil t)))
7685 ("Post library"
7686 . (lambda (candidate)
7687 (yaoddmuse-post-file
7688 (find-library-name candidate)
7689 "EmacsWiki"
7690 (file-name-nondirectory
7691 (find-library-name candidate))))))))
7692 "Needs yaoddmuse.el.
7694 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7696 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7698 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7699 "Allow the use of `install-elisp' only on elisp files."
7700 (if (string-match "\.el$" candidate)
7701 (append actions '(("Install Elisp"
7702 . (lambda (elm)
7703 (install-elisp-from-emacswiki elm)))))
7704 actions))
7706 ;;;###autoload
7707 (defun anything-yaoddmuse-cache-pages (&optional load)
7708 "Fetch the list of files on emacswiki and create cache file.
7709 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7710 (interactive)
7711 (declare (special yaoddmuse-pages-hash))
7712 (yaoddmuse-update-pagename)
7713 (save-excursion
7714 (find-file anything-c-yaoddmuse-cache-file)
7715 (erase-buffer)
7716 (insert "(puthash \"EmacsWiki\" '(")
7717 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7719 (insert (concat "(\"" (car i) "\") ")))
7720 (insert ") yaoddmuse-pages-hash)\n")
7721 (save-buffer)
7722 (kill-buffer (current-buffer))
7723 (when (or current-prefix-arg
7724 load)
7725 (load anything-c-yaoddmuse-cache-file))))
7727 (defun anything-yaoddmuse-init ()
7728 "Init anything buffer status."
7729 (let ((anything-buffer (anything-candidate-buffer 'global))
7730 (library-list (yaoddmuse-get-library-list)))
7731 (with-current-buffer anything-buffer
7732 ;; Insert library name.
7733 (dolist (library library-list)
7734 (insert (format "%s\n" library)))
7735 ;; Sort lines.
7736 (sort-lines nil (point-min) (point-max)))))
7739 ;;; Eev anchors
7740 (defvar anything-c-source-eev-anchor
7741 '((name . "Anchors")
7742 (candidates
7743 . (lambda ()
7744 (ignore-errors
7745 (with-anything-current-buffer
7746 (loop initially (goto-char (point-min))
7747 while (re-search-forward
7748 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7749 for anchor = (match-string-no-properties 1)
7750 collect (cons (format "%5d:%s"
7751 (line-number-at-pos (match-beginning 0))
7752 (format ee-anchor-format anchor))
7753 anchor))))))
7754 (persistent-action . (lambda (item)
7755 (ee-to item)
7756 (anything-match-line-color-current-line)))
7757 (persistent-help . "Show this entry")
7758 (action . (("Goto link" . ee-to)))))
7759 ;; (anything 'anything-c-source-eev-anchor)
7762 ;;; Org headlines
7765 (defvar anything-c-source-org-headline
7766 `((name . "Org HeadLine")
7767 (headline
7768 ,@(mapcar
7769 (lambda (num)
7770 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7771 num))
7772 (number-sequence 1 8)))
7773 (condition . (eq major-mode 'org-mode))
7774 (migemo)
7775 (subexp . 1)
7776 (persistent-action . (lambda (elm)
7777 (anything-c-action-line-goto elm)
7778 (org-cycle)))
7779 (action-transformer
7780 . (lambda (actions candidate)
7781 '(("Go to Line" . anything-c-action-line-goto)
7782 ("Refile to this Headline" . anything-c-org-headline-refile)
7783 ("Insert Link to This Headline"
7784 . anything-c-org-headline-insert-link-to-headline)))))
7785 "Show Org headlines.
7786 org-mode is very very much extended text-mode/outline-mode.
7788 See (find-library \"org.el\")
7789 See http://orgmode.org for the latest version.")
7790 ;; (anything 'anything-c-source-org-headline)
7792 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7793 (insert
7794 (save-excursion
7795 (anything-goto-line (car lineno-and-content))
7796 (and (looking-at org-complex-heading-regexp)
7797 (org-make-link-string (concat "*" (match-string 4)))))))
7799 (defun anything-c-org-headline-refile (lineno-and-content)
7800 "Refile current org entry to LINENO-AND-CONTENT."
7801 (with-anything-current-buffer
7802 (org-cut-subtree)
7803 (anything-goto-line (car lineno-and-content))
7804 (org-end-of-subtree t t)
7805 (let ((org-yank-adjusted-subtrees t))
7806 (org-yank))))
7809 ;;; Org keywords
7812 (defvar anything-c-source-org-keywords
7813 '((name . "Org Keywords")
7814 (init . anything-c-org-keywords-init)
7815 (candidates . anything-c-org-keywords-candidates)
7816 (action . anything-c-org-keywords-insert)
7817 (persistent-action . anything-c-org-keywords-show-help)
7818 (persistent-help . "Show an example and info page to describe this keyword.")
7819 (keywords-examples)
7820 (keywords)))
7821 ;; (anything 'anything-c-source-org-keywords)
7823 (defvar anything-c-org-keywords-info-location
7824 '(("#+TITLE:" . "(org)Export options")
7825 ("#+AUTHOR:" . "(org)Export options")
7826 ("#+DATE:" . "(org)Export options")
7827 ("#+EMAIL:" . "(org)Export options")
7828 ("#+DESCRIPTION:" . "(org)Export options")
7829 ("#+KEYWORDS:" . "(org)Export options")
7830 ("#+LANGUAGE:" . "(org)Export options")
7831 ("#+TEXT:" . "(org)Export options")
7832 ("#+TEXT:" . "(org)Export options")
7833 ("#+OPTIONS:" . "(org)Export options")
7834 ("#+BIND:" . "(org)Export options")
7835 ("#+LINK_UP:" . "(org)Export options")
7836 ("#+LINK_HOME:" . "(org)Export options")
7837 ("#+LATEX_HEADER:" . "(org)Export options")
7838 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7839 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7840 ("#+INFOJS_OPT" . "(org)Javascript support")
7841 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7842 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7843 ("#+ORGTBL" . "(org)Radio tables")
7844 ("#+HTML:" . "(org)Quoting HTML tags")
7845 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7846 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7847 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7848 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7849 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7850 ("#+BEGIN_SRC" . "(org)Literal examples")
7851 ("#+CAPTION" . "(org)Tables in HTML export")
7852 ("#+LABEL" . "(org)Tables in LaTeX export")
7853 ("#+ATTR_HTML" . "(org)Links")
7854 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7856 (defun anything-c-org-keywords-init ()
7857 (unless (anything-attr 'keywords-examples)
7858 (require 'org)
7859 (anything-attrset 'keywords-examples
7860 (append
7861 (mapcar
7862 (lambda (x)
7863 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7864 (cons (match-string 2 x) (match-string 1 x)))
7865 (org-split-string (org-get-current-options) "\n"))
7866 (mapcar 'list org-additional-option-like-keywords)))
7867 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7869 (defun anything-c-org-keywords-candidates ()
7870 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7871 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7872 (anything-attr 'keywords)))
7874 (defun anything-c-org-keywords-insert (keyword)
7875 (cond ((and (string-match "BEGIN" keyword)
7876 (anything-region-active-p))
7877 (let ((beg (region-beginning))
7878 (end (region-end)))
7879 (goto-char end)
7880 (insert "\n#+" (replace-regexp-in-string
7881 "BEGIN" "END" keyword) "\n")
7882 (goto-char beg)
7883 (insert "#+" keyword " ")
7884 (save-excursion (insert "\n"))))
7885 ((string-match "BEGIN" keyword)
7886 (insert "#+" keyword " ")
7887 (save-excursion
7888 (insert "\n#+" (replace-regexp-in-string
7889 "BEGIN" "END" keyword) "\n")))
7890 (t (insert "#+" keyword " "))))
7892 (defun anything-c-org-keywords-show-help (keyword)
7893 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7894 "(org)In-buffer settings"))
7895 (search-forward (concat "#+" keyword) nil t)
7896 (anything-persistent-highlight-point)
7897 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7901 ;;; bbdb
7904 (defvar bbdb-records)
7905 (defvar bbdb-buffer-name)
7907 (defun anything-c-bbdb-candidates ()
7908 "Return a list of all names in the bbdb database. The format
7909 is \"Firstname Lastname\"."
7910 (mapcar (lambda (bbdb-record)
7911 (replace-regexp-in-string
7912 "\\s-+$" ""
7913 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7914 (bbdb-records)))
7916 (defun anything-c-bbdb-create-contact (actions candidate)
7917 "Action transformer that returns only an entry to add the
7918 current `anything-pattern' as new contact. All other actions are
7919 removed."
7920 (if (string= candidate "*Add to contacts*")
7921 '(("Add to contacts" . (lambda (actions)
7922 (bbdb-create-internal
7923 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7924 (read-from-minibuffer "Company: ")
7925 (read-from-minibuffer "Email: ")
7928 (read-from-minibuffer "Note: ")))))
7929 actions))
7931 (defun anything-c-bbdb-get-record (candidate)
7932 "Return record that match CANDIDATE."
7933 (bbdb candidate nil)
7934 (set-buffer "*BBDB*")
7935 (bbdb-current-record))
7937 (defvar anything-c-bbdb-name nil
7938 "Only for internal use.")
7940 (defvar anything-c-source-bbdb
7941 '((name . "BBDB")
7942 (candidates . anything-c-bbdb-candidates)
7943 (action ("Send a mail" . anything-c-bbdb-compose-mail)
7944 ("View person's data" . anything-c-bbdb-view-person-action))
7945 (filtered-candidate-transformer . (lambda (candidates source)
7946 (setq anything-c-bbdb-name anything-pattern)
7947 (if (not candidates)
7948 (list "*Add to contacts*")
7949 candidates)))
7950 (action-transformer . (lambda (actions candidate)
7951 (anything-c-bbdb-create-contact actions candidate))))
7952 "Needs BBDB.
7954 http://bbdb.sourceforge.net/")
7955 ;; (anything 'anything-c-source-bbdb)
7957 (defun anything-c-bbdb-view-person-action (candidate)
7958 "View BBDB data of single CANDIDATE or marked candidates."
7959 (anything-aif (anything-marked-candidates)
7960 (let ((bbdb-append-records (length it)))
7961 (dolist (i it)
7962 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
7963 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
7965 (defun anything-c-bbdb-collect-mail-addresses ()
7966 "Return a list of all mail addresses of records in bbdb buffer."
7967 (with-current-buffer bbdb-buffer-name
7968 (loop for i in bbdb-records
7969 if (bbdb-record-net (car i))
7970 collect (bbdb-dwim-net-address (car i)))))
7972 (defun anything-c-bbdb-compose-mail (candidate)
7973 "Compose a mail with all records of bbdb buffer."
7974 (anything-c-bbdb-view-person-action candidate)
7975 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7976 (address-str (mapconcat 'identity address-list ",\n ")))
7977 (compose-mail address-str)))
7980 ;;; Evaluation Result
7983 ;; Internal
7984 (defvar anything-eldoc-active-minibuffers-list nil)
7986 (defvar anything-c-source-evaluation-result
7987 '((name . "Evaluation Result")
7988 (disable-shortcuts)
7989 (dummy)
7990 (multiline)
7991 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
7992 (filtered-candidate-transformer . (lambda (candidates source)
7993 (list
7994 (condition-case nil
7995 (with-anything-current-buffer
7996 (pp-to-string
7997 (eval (read anything-pattern))))
7998 (error "Error")))))
7999 (action . (("Copy result to kill-ring" . (lambda (candidate)
8000 (with-current-buffer anything-buffer
8001 (let ((end (save-excursion
8002 (goto-char (point-max))
8003 (search-backward "\n")
8004 (point))))
8005 (kill-region (point) end)))))
8006 ("copy sexp to kill-ring" . (lambda (candidate)
8007 (kill-new anything-input)))))))
8008 ;; (anything 'anything-c-source-evaluation-result)
8010 (defun anything-eval-new-line-and-indent ()
8011 (interactive)
8012 (newline) (lisp-indent-line))
8014 (defun anything-eldoc-store-minibuffer ()
8015 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8016 (with-selected-window (minibuffer-window)
8017 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8019 (defun anything-eldoc-show-in-eval ()
8020 "Return eldoc in mode-line for current minibuffer input."
8021 (let ((buf (with-selected-window (minibuffer-window)
8022 (buffer-name))))
8023 (when (member buf anything-eldoc-active-minibuffers-list)
8024 (let* ((str-all (with-current-buffer buf
8025 (minibuffer-completion-contents)))
8026 (sym (when str-all
8027 (with-temp-buffer
8028 (insert str-all)
8029 (goto-char (point-max))
8030 (unless (looking-back ")\\|\"") (forward-char -1))
8031 (eldoc-current-symbol))))
8032 (info-fn (eldoc-fnsym-in-current-sexp))
8033 (doc (or (eldoc-get-var-docstring sym)
8034 (eldoc-get-fnsym-args-string
8035 (car info-fn) (cadr info-fn)))))
8036 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8038 (defun anything-c-eldoc-show-in-mode-line (str)
8039 "Show string STR in mode-line."
8040 (save-window-excursion
8041 (with-current-buffer anything-buffer
8042 (let ((mode-line-format (concat " " str)))
8043 (force-mode-line-update)
8044 (sit-for anything-c-eldoc-show-in-mode-line-delay))
8045 (force-mode-line-update))))
8047 ;;; Calculation Result
8050 (defvar anything-c-source-calculation-result
8051 '((name . "Calculation Result")
8052 (dummy)
8053 (filtered-candidate-transformer . (lambda (candidates source)
8054 (list
8055 (condition-case nil
8056 (calc-eval anything-pattern)
8057 (error "error")))))
8058 (action ("Copy result to kill-ring" . kill-new))))
8059 ;; (anything 'anything-c-source-calculation-result)
8062 ;;; Google Suggestions
8065 ;; Internal
8066 (defvar anything-ggs-max-length-real-flag 0)
8067 (defvar anything-ggs-max-length-num-flag 0)
8069 (defun anything-c-google-suggest-fetch (input)
8070 "Fetch suggestions for INPUT from XML buffer.
8071 Return an alist with elements like (data . number_results)."
8072 (setq anything-ggs-max-length-real-flag 0
8073 anything-ggs-max-length-num-flag 0)
8074 (let ((request (concat anything-c-google-suggest-url
8075 (url-hexify-string input))))
8076 (flet ((fetch ()
8077 (loop
8078 with result-alist = (xml-get-children
8079 (car (xml-parse-region
8080 (point-min) (point-max)))
8081 'CompleteSuggestion)
8082 for i in result-alist
8083 for data = (cdr (caadr (assoc 'suggestion i)))
8084 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8085 for lqueries = (length (anything-c-ggs-set-number-result
8086 nqueries))
8087 for ldata = (length data)
8089 (progn
8090 (when (> ldata anything-ggs-max-length-real-flag)
8091 (setq anything-ggs-max-length-real-flag ldata))
8092 (when (> lqueries anything-ggs-max-length-num-flag)
8093 (setq anything-ggs-max-length-num-flag lqueries)))
8094 collect (cons data nqueries) into cont
8095 finally return cont)))
8096 (if anything-google-suggest-use-curl-p
8097 (with-temp-buffer
8098 (call-process "curl" nil t nil request)
8099 (fetch))
8100 (with-current-buffer
8101 (url-retrieve-synchronously request)
8102 (fetch))))))
8104 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8105 "Set candidates with result and number of google results found."
8106 (let ((suggestions
8107 (loop with suggested-results = (anything-c-google-suggest-fetch
8108 (or (and request-prefix
8109 (concat request-prefix " " anything-pattern))
8110 anything-pattern))
8111 for (real . numresult) in suggested-results
8112 ;; Prepare number of results with ","
8113 for fnumresult = (anything-c-ggs-set-number-result numresult)
8114 ;; Calculate number of spaces to add before fnumresult
8115 ;; if it is smaller than longest result
8116 ;; `anything-ggs-max-length-num-flag'.
8117 ;; e.g 1,234,567
8118 ;; 345,678
8119 ;; To be sure it is aligned properly.
8120 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8121 (- anything-ggs-max-length-num-flag (length fnumresult))
8123 ;; Add now the spaces before fnumresult.
8124 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8125 for interval = (- anything-ggs-max-length-real-flag (length real))
8126 for spaces = (make-string (+ 2 interval) ? )
8127 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8128 collect (cons display real))))
8129 (if (loop for (disp . dat) in suggestions
8130 thereis (equal dat anything-pattern))
8131 suggestions
8132 ;; if there is no suggestion exactly matching the input then
8133 ;; prepend a Search on Google item to the list
8134 (append
8135 suggestions
8136 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8137 anything-input))))))
8139 (defun anything-c-ggs-set-number-result (num)
8140 (if num
8141 (progn
8142 (and (numberp num) (setq num (number-to-string num)))
8143 (loop for i in (reverse (split-string num "" t))
8144 for count from 1
8145 append (list i) into C
8146 when (= count 3)
8147 append (list ",") into C
8148 and do (setq count 0)
8149 finally return
8150 (replace-regexp-in-string
8151 "^," "" (mapconcat 'identity (reverse C) ""))))
8152 "?"))
8154 (defvar anything-c-google-suggest-default-browser-function nil
8155 "*The browse url function you prefer to use with google suggest.
8156 When nil, use the first browser function available
8157 See `anything-browse-url-default-browser-alist'.")
8159 (defun anything-c-google-suggest-action (candidate)
8160 "Default action to jump to a google suggested candidate."
8161 (let ((arg (concat anything-c-google-suggest-search-url
8162 (url-hexify-string candidate))))
8163 (anything-aif anything-c-google-suggest-default-browser-function
8164 (funcall it arg)
8165 (anything-c-browse-url arg))))
8167 (defvar anything-c-google-suggest-default-function
8168 'anything-c-google-suggest-set-candidates
8169 "Default function to use in anything google suggest.")
8171 (defvar anything-c-source-google-suggest
8172 '((name . "Google Suggest")
8173 (candidates . (lambda ()
8174 (funcall anything-c-google-suggest-default-function)))
8175 (action . (("Google Search" . anything-c-google-suggest-action)))
8176 (volatile)
8177 (requires-pattern . 3)
8178 (delayed)))
8180 (defun anything-c-google-suggest-emacs-lisp ()
8181 "Try to emacs lisp complete with google suggestions."
8182 (anything-c-google-suggest-set-candidates "emacs lisp"))
8184 ;; (anything 'anything-c-source-google-suggest)
8186 ;;; Yahoo suggestions
8189 (defun anything-c-yahoo-suggest-fetch (input)
8190 "Fetch Yahoo suggestions for INPUT from XML buffer.
8191 Return an alist with elements like (data . number_results)."
8192 (let ((request (concat anything-c-yahoo-suggest-url
8193 (url-hexify-string input))))
8194 (flet ((fetch ()
8195 (loop
8196 with result-alist = (xml-get-children
8197 (car (xml-parse-region (point-min) (point-max)))
8198 'Result)
8199 for i in result-alist
8200 collect (caddr i))))
8201 (with-current-buffer
8202 (url-retrieve-synchronously request)
8203 (fetch)))))
8205 (defun anything-c-yahoo-suggest-set-candidates ()
8206 "Set candidates with Yahoo results found."
8207 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8208 (or suggestions
8209 (append
8210 suggestions
8211 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8212 anything-input))))))
8214 (defun anything-c-yahoo-suggest-action (candidate)
8215 "Default action to jump to a Yahoo suggested candidate."
8216 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8217 (url-hexify-string candidate))))
8219 (defvar anything-c-source-yahoo-suggest
8220 '((name . "Yahoo Suggest")
8221 (candidates . anything-c-yahoo-suggest-set-candidates)
8222 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8223 (volatile)
8224 (requires-pattern . 3)
8225 (delayed)))
8227 ;; (anything 'anything-c-source-yahoo-suggest)
8230 ;;; Web browser functions.
8233 (require 'browse-url)
8234 ;; If default setting of `w3m-command' is not
8235 ;; what you want you and you modify it, you will have to reeval
8236 ;; also `anything-browse-url-default-browser-alist'.
8237 (defvar w3m-command "/usr/bin/w3m")
8238 (defvar anything-c-home-url "http://www.google.fr"
8239 "*Default url to use as home url.")
8241 (defvar ac-browse-url-chromium-program "chromium-browser")
8242 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8243 (defvar anything-browse-url-default-browser-alist
8244 `((,w3m-command . w3m-browse-url)
8245 (,browse-url-firefox-program . browse-url-firefox)
8246 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8247 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8248 (,browse-url-kde-program . browse-url-kde)
8249 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8250 (,browse-url-mozilla-program . browse-url-mozilla)
8251 (,browse-url-galeon-program . browse-url-galeon)
8252 (,browse-url-netscape-program . browse-url-netscape)
8253 (,browse-url-mosaic-program . browse-url-mosaic)
8254 (,browse-url-xterm-program . browse-url-text-xterm))
8255 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8257 (defun* anything-c-generic-browser (url name &rest args)
8258 "Browse URL with NAME browser."
8259 (let ((proc (concat name " " url)))
8260 (message "Starting %s..." name)
8261 (apply 'start-process proc nil name
8262 (append args (list url)))
8263 (set-process-sentinel
8264 (get-process proc)
8265 #'(lambda (process event)
8266 (when (string= event "finished\n")
8267 (message "%s process %s" process event))))))
8269 (defun ac-browse-url-chromium (url)
8270 "Browse URL with google chrome browser."
8271 (interactive "sURL: ")
8272 (anything-c-generic-browser
8273 url ac-browse-url-chromium-program))
8275 (defun ac-browse-url-uzbl (url &optional ignore)
8276 "Browse URL with uzbl browser."
8277 (interactive "sURL: ")
8278 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8280 (defun anything-browse-url-default-browser (url &rest args)
8281 "Find the first available browser and ask it to load URL."
8282 (let ((default-browser-fn
8283 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8284 thereis (and exe (executable-find exe) fn))))
8285 (if default-browser-fn
8286 (apply default-browser-fn url args)
8287 (error "No usable browser found"))))
8289 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8290 "Default command to browse URL."
8291 (if browse-url-browser-function
8292 (browse-url url)
8293 (anything-browse-url-default-browser url)))
8296 ;;; Surfraw
8298 ;; Need external program surfraw.
8299 ;; <http://surfraw.alioth.debian.org/>
8301 (defvar anything-surfraw-default-browser-function nil
8302 "*The browse url function you prefer to use with surfraw.
8303 When nil, fallback to `browse-url-browser-function'.")
8305 ;; Internal
8306 (defvar anything-surfraw-engines-history nil)
8308 (defun anything-c-build-elvi-list ()
8309 "Return list of all engines and descriptions handled by surfraw."
8310 (cdr
8311 (with-temp-buffer
8312 (call-process "surfraw" nil t nil
8313 "-elvi")
8314 (split-string (buffer-string) "\n"))))
8317 ;;; Emms
8320 (defun anything-emms-stream-edit-bookmark (elm)
8321 "Change the information of current emms-stream bookmark from anything."
8322 (declare (special emms-stream-list))
8323 (let* ((cur-buf anything-current-buffer)
8324 (bookmark (assoc elm emms-stream-list))
8325 (name (read-from-minibuffer "Description: "
8326 (nth 0 bookmark)))
8327 (url (read-from-minibuffer "URL: "
8328 (nth 1 bookmark)))
8329 (fd (read-from-minibuffer "Feed Descriptor: "
8330 (int-to-string (nth 2 bookmark))))
8331 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8332 (format "%s" (car (last bookmark))))))
8333 (save-excursion
8334 (emms-streams)
8335 (when (re-search-forward (concat "^" name) nil t)
8336 (beginning-of-line)
8337 (emms-stream-delete-bookmark)
8338 (emms-stream-add-bookmark name url (string-to-number fd) type)
8339 (emms-stream-save-bookmarks-file)
8340 (emms-stream-quit)
8341 (anything-c-switch-to-buffer cur-buf)))))
8343 (defun anything-emms-stream-delete-bookmark (elm)
8344 "Delete an emms-stream bookmark from anything."
8345 (let* ((cur-buf anything-current-buffer)
8346 (bookmark (assoc elm emms-stream-list))
8347 (name (nth 0 bookmark)))
8348 (save-excursion
8349 (emms-streams)
8350 (when (re-search-forward (concat "^" name) nil t)
8351 (beginning-of-line)
8352 (emms-stream-delete-bookmark)
8353 (emms-stream-save-bookmarks-file)
8354 (emms-stream-quit)
8355 (anything-c-switch-to-buffer cur-buf)))))
8357 (defvar anything-c-source-emms-streams
8358 '((name . "Emms Streams")
8359 (init . (lambda ()
8360 (emms-stream-init)))
8361 (candidates . (lambda ()
8362 (declare (special emms-stream-list))
8363 (mapcar 'car emms-stream-list)))
8364 (action . (("Play" . (lambda (elm)
8365 (declare (special emms-stream-list))
8366 (let* ((stream (assoc elm emms-stream-list))
8367 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8368 (url (second stream)))
8369 (funcall fn url))))
8370 ("Delete" . anything-emms-stream-delete-bookmark)
8371 ("Edit" . anything-emms-stream-edit-bookmark)))
8372 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8373 ;; (anything 'anything-c-source-emms-streams)
8375 ;; Don't forget to set `emms-source-file-default-directory'
8376 (defvar anything-c-source-emms-dired
8377 '((name . "Music Directory")
8378 (candidates . (lambda ()
8379 (cddr (directory-files emms-source-file-default-directory))))
8380 (action .
8381 (("Play Directory" . (lambda (item)
8382 (emms-play-directory
8383 (expand-file-name
8384 item
8385 emms-source-file-default-directory))))
8386 ("Open dired in file's directory" . (lambda (item)
8387 (anything-c-open-dired
8388 (expand-file-name
8389 item
8390 emms-source-file-default-directory))))))
8391 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8392 ;; (anything 'anything-c-source-emms-dired)
8395 (defun anything-c-emms-files-modifier (candidates source)
8396 (let ((current-playlist (with-current-emms-playlist
8397 (loop
8398 with cur-list = (emms-playlist-tracks-in-region
8399 (point-min) (point-max))
8400 for i in cur-list
8401 collect (assoc-default 'name i)))))
8402 (loop for i in candidates
8403 if (member (cdr i) current-playlist)
8404 collect (cons (propertize (car i)
8405 'face 'anything-emms-playlist)
8406 (cdr i)) into lis
8407 else collect i into lis
8408 finally return lis)))
8410 (defun anything-c-emms-play-current-playlist ()
8411 "Play current playlist."
8412 (with-current-emms-playlist
8413 (emms-playlist-first)
8414 (emms-playlist-mode-play-smart)))
8416 (defvar anything-c-source-emms-files
8417 '((name . "Emms files")
8418 (candidates . (lambda ()
8419 (loop for v being the hash-values in emms-cache-db
8420 for name = (assoc-default 'name v)
8421 for artist = (or (assoc-default 'info-artist v) "unknown")
8422 for genre = (or (assoc-default 'info-genre v) "unknown")
8423 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8424 for song = (or (assoc-default 'info-title v) "unknown")
8425 for info = (concat artist " - " genre " - " tracknum ": " song)
8426 unless (string-match "^http:" name) collect (cons info name))))
8427 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8428 (action . (("Play file" . emms-play-file)
8429 ("Add to Playlist and play (C-u clear current)"
8430 . (lambda (candidate)
8431 (when anything-current-prefix-arg
8432 (emms-playlist-current-clear))
8433 (emms-playlist-new)
8434 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8435 (unless emms-player-playing-p
8436 (anything-c-emms-play-current-playlist))))))))
8438 ;; (anything 'anything-c-source-emms-files)
8441 ;;; Jabber Contacts (jabber.el)
8442 (defun anything-c-jabber-online-contacts ()
8443 "List online Jabber contacts."
8444 (with-no-warnings
8445 (let (jids)
8446 (dolist (item (jabber-concat-rosters) jids)
8447 (when (get item 'connected)
8448 (push (if (get item 'name)
8449 (cons (get item 'name) item)
8450 (cons (symbol-name item) item)) jids))))))
8452 (defvar anything-c-source-jabber-contacts
8453 '((name . "Jabber Contacts")
8454 (init . (lambda () (require 'jabber)))
8455 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8456 (action . (lambda (x)
8457 (jabber-chat-with
8458 (jabber-read-account)
8459 (symbol-name
8460 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8461 ;; (anything 'anything-c-source-jabber-contacts)
8465 ;;; Call source.
8466 (defvar anything-source-select-buffer "*anything source select*")
8467 (defvar anything-c-source-call-source
8468 `((name . "Call anything source")
8469 (candidate-number-limit)
8470 (candidates
8471 . (lambda ()
8472 (loop for vname in (all-completions "anything-c-source-" obarray)
8473 for var = (intern vname)
8474 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8475 if name collect
8476 (cons (format "%s `%s'"
8477 name (propertize vname 'face 'font-lock-variable-name-face))
8478 var))))
8479 (action
8480 . (("Invoke anything with selected source"
8482 (lambda (candidate)
8483 (setq anything-candidate-number-limit 9999)
8484 (anything candidate nil nil nil nil
8485 anything-source-select-buffer)))
8486 ("Describe variable" . describe-variable)
8487 ("Find variable" . find-variable)))
8488 (persistent-action . describe-variable)
8489 (persistent-help . "Show description of this source")))
8490 ;; (anything 'anything-c-source-call-source)
8492 (defun anything-call-source-from-anything ()
8493 "Call anything source within `anything' session."
8494 (interactive)
8495 (setq anything-input-idle-delay 0)
8496 (anything-set-sources '(anything-c-source-call-source)))
8498 ;;; Execute Preconfigured anything.
8499 (defvar anything-c-source-anything-commands
8500 '((name . "Preconfigured Anything")
8501 (candidates . anything-c-anything-commands-candidates)
8502 (type . command)
8503 (candidate-number-limit)))
8504 ;; (anything 'anything-c-source-anything-commands)
8506 (defun anything-c-anything-commands-candidates ()
8507 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8508 collect (cons (if (where-is-internal cmd nil t)
8509 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8510 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8511 cmd)))
8514 ;;; Occur
8517 (defun anything-c-occur-init ()
8518 "Create the initial anything occur buffer.
8519 If region is active use region as buffer contents
8520 instead of whole buffer."
8521 (with-current-buffer (anything-candidate-buffer 'global)
8522 (erase-buffer)
8523 (let ((buf-contents
8524 (with-anything-current-buffer
8525 (if (anything-region-active-p)
8526 (buffer-substring (region-beginning) (region-end))
8527 (buffer-substring (point-min) (point-max))))))
8528 (insert buf-contents))))
8530 (defun anything-c-occur-get-line (s e)
8531 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8533 (defun anything-c-occur-query-replace-regexp (candidate)
8534 "Query replace regexp starting from CANDIDATE.
8535 If region is active ignore CANDIDATE and replace only in region.
8536 With a prefix arg replace only matches surrounded by word boundaries,
8537 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8538 (let ((regexp anything-input))
8539 (unless (anything-region-active-p)
8540 (anything-c-action-line-goto candidate))
8541 (apply 'query-replace-regexp
8542 (anything-c-query-replace-args regexp))))
8544 (defvar anything-c-source-occur
8545 '((name . "Occur")
8546 (init . anything-c-occur-init)
8547 (candidates-in-buffer)
8548 (migemo)
8549 (get-line . anything-c-occur-get-line)
8550 (display-to-real . anything-c-display-to-real-line)
8551 (action . (("Go to Line" . anything-c-action-line-goto)
8552 ("Query replace regexp (C-u Not inside word.)"
8553 . anything-c-occur-query-replace-regexp)))
8554 (recenter)
8555 (requires-pattern . 1)
8556 (delayed)
8557 (volatile)))
8558 ;; (anything 'anything-c-source-occur)
8561 ;;; Anything browse code.
8562 (defun anything-c-browse-code-get-line (beg end)
8563 "Select line if it match the regexp corresponding to current `major-mode'.
8564 Line is parsed for BEG position to END position."
8565 (let ((str-line (buffer-substring beg end))
8566 (regexp (assoc-default major-mode
8567 anything-c-browse-code-regexp-alist))
8568 (num-line (if (string= anything-pattern "") beg (1- beg))))
8569 (when (and regexp (string-match regexp str-line))
8570 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8573 (defvar anything-c-source-browse-code
8574 '((name . "Browse code")
8575 (init . (lambda ()
8576 (anything-candidate-buffer anything-current-buffer)
8577 (with-anything-current-buffer
8578 (jit-lock-fontify-now))))
8579 (candidate-number-limit . 9999)
8580 (candidates-in-buffer)
8581 (get-line . anything-c-browse-code-get-line)
8582 (type . line)
8583 (recenter)))
8586 ;; Do many actions for input
8587 (defvar anything-c-source-create
8588 '((name . "Create")
8589 (dummy)
8590 (action)
8591 (action-transformer . anything-create--actions))
8592 "Do many create actions from `anything-pattern'.
8593 See also `anything-create--actions'.")
8594 ;; (anything 'anything-c-source-create)
8596 (defun anything-create-from-anything ()
8597 "Run `anything-create' from `anything' as a fallback."
8598 (interactive)
8599 (anything-run-after-quit 'anything-create nil anything-pattern))
8601 (defun anything-create--actions (&rest ignored)
8602 "Default actions for `anything-create' / `anything-c-source-create'."
8603 (remove-if-not
8604 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8605 (append anything-create--actions-private
8606 '(("find-file" . find-file)
8607 ("find-file other window" . find-file-other-window)
8608 ("New buffer" . anything-c-switch-to-buffer)
8609 ("New buffer other window" . switch-to-buffer-other-window)
8610 ("Bookmark Set" . bookmark-set)
8611 ("Set Register" .
8612 (lambda (x) (set-register (read-char "Register: ") x)))
8613 ("Insert Linkd star" . linkd-insert-star)
8614 ("Insert Linkd Tag" . linkd-insert-tag)
8615 ("Insert Linkd Link" . linkd-insert-link)
8616 ("Insert Linkd Lisp" . linkd-insert-lisp)
8617 ("Insert Linkd Wiki" . linkd-insert-wiki)
8618 ("Google Search" . google)))))
8621 ;; Minibuffer History
8624 (defvar anything-c-source-minibuffer-history
8625 '((name . "Minibuffer History")
8626 (header-name . (lambda (name)
8627 (format "%s (%s)" name minibuffer-history-variable)))
8628 (candidates
8629 . (lambda ()
8630 (let ((history (loop
8631 for i in (symbol-value minibuffer-history-variable)
8632 unless (string= "" i) collect i)))
8633 (if (consp (car history))
8634 (mapcar 'prin1-to-string history)
8635 history))))
8636 (migemo)
8637 (action . insert)))
8638 ;; (anything 'anything-c-source-minibuffer-history)
8641 ;;; Elscreen
8644 (defvar anything-c-source-elscreen
8645 '((name . "Elscreen")
8646 (candidates . (lambda ()
8647 (if (cdr (elscreen-get-screen-to-name-alist))
8648 (sort
8649 (loop for sname in (elscreen-get-screen-to-name-alist)
8650 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8651 finally (return lst))
8652 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8653 (action . (("Change Screen".
8654 (lambda (candidate)
8655 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8656 ("Kill Screen(s)".
8657 (lambda (candidate)
8658 (dolist (i (anything-marked-candidates))
8659 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8660 (elscreen-kill))))
8661 ("Only Screen".
8662 (lambda (candidate)
8663 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8664 (elscreen-kill-others)))))))
8665 ;; (anything 'anything-c-source-elscreen)
8668 ;;;; <System>
8670 ;;; Top (process)
8671 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8672 "Top command (batch mode). %s is replaced with `frame-width'.")
8673 (defvar anything-c-source-top
8674 '((name . "Top (Press C-c C-u to refresh)")
8675 (init . anything-c-top-init)
8676 (candidates-in-buffer)
8677 (display-to-real . anything-c-top-display-to-real)
8678 (update . anything-c-top-update)
8679 (persistent-action . anything-c-top-sh-persistent-action)
8680 (persistent-help . "SIGTERM")
8681 (action
8682 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8683 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8684 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8685 ;; (anything 'anything-c-source-top)
8687 (defun anything-c-top-sh (cmd)
8688 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8690 (defun anything-c-top-sh-persistent-action (pid)
8691 (delete-other-windows)
8692 (anything-c-top-sh (format "kill -TERM %s" pid))
8693 (anything-force-update))
8695 (defun anything-c-top-init ()
8696 (with-current-buffer (anything-candidate-buffer 'global)
8697 (call-process-shell-command
8698 (format anything-c-top-command
8699 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8700 nil (current-buffer))))
8702 (defun anything-c-top-display-to-real (line)
8703 (car (split-string line)))
8705 (defun anything-c-top-update ()
8706 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8707 (anything-c-top-init)))
8709 ;;; Timers
8710 (defvar anything-c-source-absolute-time-timers
8711 '((name . "Absolute Time Timers")
8712 (candidates . timer-list)
8713 (type . timer)))
8714 ;; (anything 'anything-c-source-absolute-time-timers)
8716 (defvar anything-c-source-idle-time-timers
8717 '((name . "Idle Time Timers")
8718 (candidates . timer-idle-list)
8719 (type . timer)))
8720 ;; (anything 'anything-c-source-idle-time-timers)
8722 (defun anything-c-timer-real-to-display (timer)
8723 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8724 (append timer nil) ;use `append' to convert vector->list
8725 (format "%s repeat=%5S %s(%s)"
8726 (let ((time (list t1 t2 t3)))
8727 (if idle-delay
8728 (format-time-string "idle-for=%5s" time)
8729 (format-time-string "%m/%d %T" time)))
8730 repeat-delay
8731 func
8732 (mapconcat 'prin1-to-string args " "))))
8734 ;;; X RandR resolution change
8735 ;;; FIXME I do not care multi-display.
8736 (defvar anything-c-xrandr-output "VGA")
8737 (defvar anything-c-xrandr-screen "0")
8738 (defvar anything-c-source-xrandr-change-resolution
8739 '((name . "Change Resolution")
8740 (candidates
8741 . (lambda ()
8742 (with-temp-buffer
8743 (call-process "xrandr" nil (current-buffer) nil
8744 "--screen" anything-c-xrandr-screen "-q")
8745 (goto-char 1)
8746 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8747 collect (match-string 1)))))
8748 (action
8749 ("Change Resolution" . (lambda (mode)
8750 (call-process "xrandr" nil nil nil
8751 "--screen" anything-c-xrandr-screen
8752 "--output" anything-c-xrandr-output
8753 "--mode" mode))))))
8754 ;; (anything 'anything-c-source-xrandr-change-resolution)
8756 ;;; Xfont selection
8759 (defun anything-c-persistent-xfont-action (elm)
8760 "Show current font temporarily"
8761 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8762 (default-font elm))
8763 (unwind-protect
8764 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8765 (set-frame-font current-font))))
8767 (defvar anything-c-xfonts-cache nil)
8768 (defvar anything-c-source-xfonts
8769 '((name . "X Fonts")
8770 (init . (lambda ()
8771 (unless anything-c-xfonts-cache
8772 (setq anything-c-xfonts-cache
8773 (x-list-fonts "*")))))
8774 (candidates . anything-c-xfonts-cache)
8775 (action . (("Copy to kill ring" . (lambda (elm)
8776 (kill-new elm)))
8777 ("Set Font" . (lambda (elm)
8778 (kill-new elm)
8779 (set-frame-font elm 'keep-size)
8780 (message "New font have been copied to kill ring")))))
8781 (persistent-action . anything-c-persistent-xfont-action)
8782 (persistent-help . "Switch to this font temporarily")))
8783 ;; (anything 'anything-c-source-xfonts)
8785 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8788 (defvar anything-c-ucs-max-len 0)
8789 (defun anything-c-calculate-ucs-max-len ()
8790 "Calculate the length of longest `ucs-names' candidate."
8791 (loop with count = 0
8792 for (n . v) in (ucs-names)
8793 for len = (length n)
8794 if (> len count)
8795 do (setq count len)
8796 finally return count))
8798 (defun anything-c-ucs-init ()
8799 "Initialize an anything buffer with ucs symbols.
8800 Only math* symbols are collected."
8801 (unless (> anything-c-ucs-max-len 0)
8802 (setq anything-c-ucs-max-len
8803 (anything-c-calculate-ucs-max-len)))
8804 (with-current-buffer (anything-candidate-buffer
8805 (get-buffer-create "*anything ucs*"))
8806 ;; `ucs-names' fn will not run again, data is cached in
8807 ;; var `ucs-names'.
8808 (loop for (n . v) in (ucs-names)
8809 for len = (length n)
8810 for diff = (+ (- anything-c-ucs-max-len len) 2)
8811 unless (string= "" n)
8812 do (progn (insert (concat
8813 n ":"
8814 (make-string
8815 diff ? )))
8816 (ucs-insert v)
8817 (insert "\n")))))
8819 (defun anything-c-ucs-forward-char (candidate)
8820 (with-anything-current-buffer
8821 (forward-char 1)))
8823 (defun anything-c-ucs-backward-char (candidate)
8824 (with-anything-current-buffer
8825 (forward-char -1)))
8827 (defun anything-c-ucs-delete-backward (candidate)
8828 (with-anything-current-buffer
8829 (delete-char -1)))
8831 (defun anything-c-ucs-insert-char (candidate)
8832 (with-anything-current-buffer
8833 (insert
8834 (replace-regexp-in-string
8835 " " ""
8836 (cadr (split-string candidate ":"))))))
8838 (defun anything-c-ucs-persistent-insert ()
8839 (interactive)
8840 (anything-execute-persistent-action 'action-insert))
8842 (defun anything-c-ucs-persistent-forward ()
8843 (interactive)
8844 (anything-execute-persistent-action 'action-forward))
8846 (defun anything-c-ucs-persistent-backward ()
8847 (interactive)
8848 (anything-execute-persistent-action 'action-back))
8850 (defun anything-c-ucs-persistent-delete ()
8851 (interactive)
8852 (anything-execute-persistent-action 'action-delete))
8854 (defvar anything-c-source-ucs
8855 '((name . "Ucs names")
8856 (init . anything-c-ucs-init)
8857 (candidate-number-limit . 9999)
8858 (candidates-in-buffer)
8859 (mode-line . anything-c-ucs-mode-line-string)
8860 (action-insert . anything-c-ucs-insert-char)
8861 (action-forward . anything-c-ucs-forward-char)
8862 (action-back . anything-c-ucs-backward-char)
8863 (action-delete . anything-c-ucs-delete-backward)
8864 (action . (("Insert" . anything-c-ucs-insert-char)
8865 ("Forward char" . anything-c-ucs-forward-char)
8866 ("Backward char" . anything-c-ucs-backward-char)
8867 ("Delete char backward" . anything-c-ucs-delete-backward))))
8868 "Source for collecting `ucs-names' math symbols.")
8871 ;;; Emacs process
8874 (defvar anything-c-source-emacs-process
8875 '((name . "Emacs Process")
8876 (candidates . (lambda () (mapcar #'process-name (process-list))))
8877 (persistent-action . (lambda (elm)
8878 (delete-process (get-process elm))
8879 (anything-delete-current-selection)))
8880 (persistent-help . "Kill Process")
8881 (action ("Kill Process" . (lambda (elm)
8882 (delete-process (get-process elm)))))))
8883 ;; (anything 'anything-c-source-emacs-process)
8885 ;;; World time
8888 (defvar anything-c-source-time-world
8889 '((name . "Time World List")
8890 (init . (lambda ()
8891 (let ((anything-buffer (anything-candidate-buffer 'global)))
8892 (with-current-buffer anything-buffer
8893 (display-time-world-display display-time-world-list)))))
8894 (candidates-in-buffer)))
8898 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8901 (defvar anything-c-source-apt
8902 '((name . "APT")
8903 (init . anything-c-apt-init)
8904 (candidates-in-buffer)
8905 (candidate-transformer anything-c-apt-candidate-transformer)
8906 (display-to-real . anything-c-apt-display-to-real)
8907 (requires-pattern . 2)
8908 (delayed)
8909 (action
8910 ("Show package description" . anything-c-apt-cache-show)
8911 ("Install package" . anything-c-apt-install)
8912 ("Remove package" . anything-c-apt-uninstall)
8913 ("Purge package" . anything-c-apt-purge))
8914 (persistent-action . anything-c-apt-persistent-action)
8915 (persistent-help . "Show - C-u Refresh")))
8916 ;; (anything 'anything-c-source-apt)
8918 (defvar anything-c-apt-query "emacs")
8919 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8920 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8921 (defvar anything-c-apt-installed-packages nil)
8922 (defvar anything-c-apt-all-packages nil)
8925 (defun anything-c-apt-refresh ()
8926 "Refresh installed candidates list."
8927 (setq anything-c-apt-installed-packages nil)
8928 (setq anything-c-apt-all-packages nil)
8929 (anything-force-update))
8931 (defun anything-c-apt-persistent-action (candidate)
8932 "Persistent action for APT source."
8933 (if current-prefix-arg
8934 (anything-c-apt-refresh)
8935 (anything-c-apt-cache-show candidate)))
8937 (defun anything-c-apt-candidate-transformer (candidates)
8938 "Show installed candidates in a different color."
8939 (loop
8940 with all
8941 for cand in candidates
8942 for name = (anything-c-apt-display-to-real cand)
8943 if (member name anything-c-apt-installed-packages)
8944 collect (propertize cand 'face 'anything-apt-installed) into all
8945 else collect cand into all finally return all))
8947 (defun anything-c-apt-init ()
8948 "Initialize list of debian packages."
8949 (let ((query ""))
8950 (unless (and anything-c-apt-installed-packages
8951 anything-c-apt-all-packages)
8952 (message "Loading package list...")
8953 (setq anything-c-apt-installed-packages
8954 (with-temp-buffer
8955 (call-process-shell-command "dpkg --get-selections"
8956 nil (current-buffer))
8957 (loop for i in (split-string (buffer-string) "\n" t)
8958 collect (car (split-string i)))))
8959 (setq anything-c-apt-all-packages
8960 (with-current-buffer
8961 (anything-candidate-buffer
8962 (get-buffer-create (format "*anything-apt*")))
8963 (erase-buffer)
8964 (call-process-shell-command
8965 (format anything-c-apt-search-command query)
8966 nil (current-buffer))))
8967 (message "Loading package list done")
8968 (sit-for 0.5))))
8970 (defun anything-c-apt-display-to-real (line)
8971 "Return only name of a debian package.
8972 LINE is displayed like:
8973 package name - description."
8974 (car (split-string line " - ")))
8976 (defun anything-c-shell-command-if-needed (command)
8977 "Run shell command COMMAND to describe package.
8978 If a buffer named COMMAND already exists, just switch to it."
8979 (let ((buf (get-buffer command)))
8980 (anything-c-switch-to-buffer (get-buffer-create command))
8981 (unless buf (insert (shell-command-to-string command)))))
8983 (defun anything-c-apt-cache-show (package)
8984 "Show information on apt package PACKAGE."
8985 (anything-c-shell-command-if-needed
8986 (format anything-c-apt-show-command package)))
8988 (defun anything-c-apt-install (package)
8989 "Run 'apt-get install' shell command on PACKAGE."
8990 (anything-c-apt-generic-action :action 'install))
8992 (defun anything-c-apt-uninstall (package)
8993 "Run 'apt-get remove' shell command on PACKAGE."
8994 (anything-c-apt-generic-action :action 'uninstall))
8996 (defun anything-c-apt-purge (package)
8997 "Run 'apt-get purge' shell command on PACKAGE."
8998 (anything-c-apt-generic-action :action 'purge))
9000 (defun* anything-c-apt-generic-action (&key action)
9001 "Run 'apt-get ACTION'.
9002 Support install, remove and purge actions."
9003 (ansi-term (getenv "SHELL") "anything apt")
9004 (term-line-mode)
9005 (let ((command (case action
9006 ('install "sudo apt-get install ")
9007 ('uninstall "sudo apt-get remove ")
9008 ('purge "sudo apt-get purge ")
9009 (t (error "Unknow action"))))
9010 (beg (point))
9012 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9013 (anything-marked-candidates) " ")))
9014 (goto-char (point-max))
9015 (insert (concat command cand-list))
9016 (setq end (point))
9017 (if (y-or-n-p (format "%s package" (symbol-name action)))
9018 (progn
9019 (setq anything-c-external-commands-list nil)
9020 (setq anything-c-apt-installed-packages nil)
9021 (term-char-mode) (term-send-input))
9022 (delete-region beg end) (term-send-eof) (kill-buffer))))
9024 ;; (anything-c-apt-install "jed")
9027 ;;; Anything UI for gentoo portage.
9030 (defvar anything-c-gentoo-use-flags nil)
9031 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9032 (defvar anything-c-cache-gentoo nil)
9033 (defvar anything-c-cache-world nil)
9034 (defvar anything-c-source-gentoo
9035 '((name . "Portage sources")
9036 (init . (lambda ()
9037 (get-buffer-create anything-c-gentoo-buffer)
9038 (unless anything-c-cache-gentoo
9039 (anything-c-gentoo-setup-cache))
9040 (unless anything-c-cache-world
9041 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9042 (anything-c-gentoo-init-list)))
9043 (candidates-in-buffer)
9044 (match . identity)
9045 (candidate-transformer anything-c-highlight-world)
9046 (action . (("Show package" . (lambda (elm)
9047 (anything-c-gentoo-eshell-action elm "eix")))
9048 ("Show history" . (lambda (elm)
9049 (if (member elm anything-c-cache-world)
9050 (anything-c-gentoo-eshell-action elm "genlop -qe")
9051 (message "No infos on packages not yet installed"))))
9052 ("Copy in kill-ring" . kill-new)
9053 ("insert at point" . insert)
9054 ("Browse HomePage" . (lambda (elm)
9055 (let ((urls (anything-c-gentoo-get-url elm)))
9056 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9057 ("Show extra infos" . (lambda (elm)
9058 (if (member elm anything-c-cache-world)
9059 (anything-c-gentoo-eshell-action elm "genlop -qi")
9060 (message "No infos on packages not yet installed"))))
9061 ("Show use flags" . (lambda (elm)
9062 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9063 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9064 (font-lock-mode 1)))
9065 ("Run emerge pretend" . (lambda (elm)
9066 (anything-c-gentoo-eshell-action elm "emerge -p")))
9067 ("Emerge" . (lambda (elm)
9068 (anything-gentoo-install elm :action 'install)))
9069 ("Unmerge" . (lambda (elm)
9070 (anything-gentoo-install elm :action 'uninstall)))
9071 ("Show dependencies" . (lambda (elm)
9072 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9073 ("Show related files" . (lambda (elm)
9074 (anything-c-gentoo-default-action elm "equery" "files")))
9075 ("Refresh" . (lambda (elm)
9076 (anything-c-gentoo-setup-cache)
9077 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9079 ;; (anything 'anything-c-source-gentoo)
9081 (defun* anything-gentoo-install (candidate &key action)
9082 (setq anything-c-external-commands-list nil)
9083 (ansi-term (getenv "SHELL") "Gentoo emerge")
9084 (term-line-mode)
9085 (let ((command (case action
9086 ('install "sudo emerge -av ")
9087 ('uninstall "sudo emerge -avC ")
9088 (t (error "Unknow action"))))
9089 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9090 (beg (point)) end)
9091 (goto-char (point-max))
9092 (insert (concat command elms))
9093 (setq end (point))
9094 (term-char-mode) (term-send-input)))
9096 (defun anything-c-gentoo-default-action (elm command &rest args)
9097 "Gentoo default action that use `anything-c-gentoo-buffer'."
9098 (if (member elm anything-c-cache-world)
9099 (progn
9100 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9101 (erase-buffer)
9102 (let ((com-list (append args (list elm))))
9103 (apply #'call-process command nil t nil
9104 com-list)))
9105 (message "No infos on packages not yet installed")))
9107 (defvar anything-c-source-use-flags
9108 '((name . "Use Flags")
9109 (init . (lambda ()
9110 (unless anything-c-gentoo-use-flags
9111 (anything-c-gentoo-setup-use-flags-cache))
9112 (anything-c-gentoo-get-use)))
9113 (candidates-in-buffer)
9114 (match . identity)
9115 (candidate-transformer anything-c-highlight-local-use)
9116 (action . (("Description"
9117 . (lambda (elm)
9118 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9119 (erase-buffer)
9120 (apply #'call-process "euse" nil t nil
9121 `("-i"
9122 ,elm))
9123 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9124 (font-lock-mode 1)))
9125 ("Enable"
9126 . (lambda (elm)
9127 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9128 ("Disable"
9129 . (lambda (elm)
9130 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9131 ("Remove"
9132 . (lambda (elm)
9133 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9134 ("Show which dep use this flag"
9135 . (lambda (elm)
9136 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9137 (erase-buffer)
9138 (apply #'call-process "equery" nil t nil
9139 `("-C"
9141 ,elm))))))))
9144 ;; (anything 'anything-c-source-use-flags)
9146 (defun anything-c-gentoo-init-list ()
9147 "Initialize buffer with all packages in Portage."
9148 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9149 (buf (anything-candidate-buffer 'portage-buf)))
9150 (with-current-buffer buf
9151 (dolist (i anything-c-cache-gentoo)
9152 (insert (concat i "\n"))))))
9154 (defun anything-c-gentoo-setup-cache ()
9155 "Set up `anything-c-cache-gentoo'"
9156 (setq anything-c-cache-gentoo
9157 (split-string (with-temp-buffer
9158 (call-process "eix" nil t nil
9159 "--only-names")
9160 (buffer-string)))))
9162 (defun anything-c-gentoo-eshell-action (elm command)
9163 (when (get-buffer "*EShell Command Output*")
9164 (kill-buffer "*EShell Command Output*"))
9165 (message "Wait searching...")
9166 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9167 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9168 (progn
9169 (save-window-excursion
9170 (pop-to-buffer "*scratch*")
9171 (eshell-command (format "%s %s" command elm)))
9172 (pop-to-buffer "*EShell Command Output*"))
9173 (eshell-command (format "%s %s" command elm)))))
9175 (defun anything-c-gentoo-get-use ()
9176 "Initialize buffer with all use flags."
9177 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9178 (buf (anything-candidate-buffer 'use-buf)))
9179 (with-current-buffer buf
9180 (dolist (i anything-c-gentoo-use-flags)
9181 (insert (concat i "\n"))))))
9184 (defun anything-c-gentoo-setup-use-flags-cache ()
9185 "Setup `anything-c-gentoo-use-flags'"
9186 (setq anything-c-gentoo-use-flags
9187 (split-string (with-temp-buffer
9188 (call-process "eix" nil t nil
9189 "--print-all-useflags")
9190 (buffer-string)))))
9192 (defun anything-c-gentoo-get-url (elm)
9193 "Return a list of urls from eix output."
9194 (loop
9195 with url-list = (split-string
9196 (with-temp-buffer
9197 (call-process "eix" nil t nil
9198 elm "--format" "<homepage>\n")
9199 (buffer-string)))
9200 with all
9201 for i in url-list
9202 when (and (string-match "^http://.*" i)
9203 (not (member i all)))
9204 collect i into all
9205 finally return all))
9207 (defun anything-c-gentoo-get-world ()
9208 "Return list of all installed package on your system."
9209 (split-string (with-temp-buffer
9210 (call-process "qlist" nil t nil
9211 "-I")
9212 (buffer-string))))
9214 (defun anything-c-gentoo-get-local-use ()
9215 (split-string (with-temp-buffer
9216 (call-process "portageq" nil t nil
9217 "envvar"
9218 "USE")
9219 (buffer-string))))
9222 (defun anything-c-highlight-world (eix)
9223 "Highlight all installed package."
9224 (loop for i in eix
9225 if (member i anything-c-cache-world)
9226 collect (propertize i 'face 'anything-gentoo-match-face)
9227 else
9228 collect i))
9230 (defun anything-c-highlight-local-use (use-flags)
9231 (let ((local-uses (anything-c-gentoo-get-local-use)))
9232 (loop for i in use-flags
9233 if (member i local-uses)
9234 collect (propertize i 'face 'anything-gentoo-match-face)
9235 else
9236 collect i)))
9240 ;;; Anything ratpoison UI
9243 (defvar anything-c-source-ratpoison-commands
9244 '((name . "Ratpoison Commands")
9245 (init . anything-c-ratpoison-commands-init)
9246 (candidates-in-buffer)
9247 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9248 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9249 (candidate-number-limit)))
9250 ;; (anything 'anything-c-source-ratpoison-commands)
9252 (defun anything-c-ratpoison-commands-init ()
9253 (unless (anything-candidate-buffer)
9254 (with-current-buffer (anything-candidate-buffer 'global)
9255 ;; with ratpoison prefix key
9256 (save-excursion
9257 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9258 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9259 (replace-match "<ratpoison> \\1: \\2"))
9260 (goto-char (point-max))
9261 ;; direct binding
9262 (save-excursion
9263 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9264 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9265 (replace-match "\\1: \\2")))))
9267 (defun anything-c-ratpoison-commands-display-to-real (display)
9268 (and (string-match ": " display)
9269 (substring display (match-end 0))))
9271 (defun anything-c-ratpoison-commands-execute (candidate)
9272 (call-process "ratpoison" nil nil nil "-ic" candidate))
9276 ;;; Anything `completing-read' replacement
9279 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9280 "Convert COLLECTION to list removing elements that don't match TEST.
9281 See `anything-comp-read' about supported COLLECTION arguments.
9283 SORT-FN is a predicate to sort COLLECTION.
9285 ALISTP when non--nil will not use `all-completions' to collect
9286 candidates because it doesn't handle alists correctly for anything.
9287 i.e In `all-completions' the keys \(cars of elements\)
9288 are the possible completions. In anything we want to use the cdr instead
9289 like \(display . real\).
9290 See docstring of `all-completions' for more info.
9292 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9293 (let ((cands
9294 (cond ((and (eq collection obarray) test)
9295 (all-completions "" collection test))
9296 ((and (vectorp collection) test)
9297 (loop for i across collection when (funcall test i) collect i))
9298 ((vectorp collection)
9299 (loop for i across collection collect i))
9300 ((and alistp test)
9301 (loop for i in collection when (funcall test i) collect i))
9302 (alistp collection)
9303 ((and collection test)
9304 (all-completions "" collection test))
9305 (t (all-completions "" collection)))))
9306 (if sort-fn (sort cands sort-fn) cands)))
9308 (defun anything-cr-default-transformer (candidates source)
9309 "Default filter candidate function for `anything-comp-read'.
9310 Do nothing, just return candidate list unmodified."
9311 candidates)
9313 (defun* anything-comp-read (prompt collection
9314 &key
9315 test
9316 initial-input
9317 default
9318 preselect
9319 (buffer "*Anything Completions*")
9320 must-match
9321 (requires-pattern 0)
9322 (history nil)
9323 (persistent-action nil)
9324 (persistent-help "DoNothing")
9325 (name "Anything Completions")
9326 (volatile t)
9327 sort
9328 (fc-transformer 'anything-cr-default-transformer)
9329 (marked-candidates nil)
9330 (alistp t))
9331 "Anything `completing-read' emulation.
9332 PROMPT is the prompt name to use.
9333 COLLECTION can be a list, vector, obarray or hash-table.
9334 It can be also a function that receives three arguments:
9335 the values string, predicate and t. See `all-completions' for more details.
9337 Keys description:
9339 TEST: A predicate called with one arg i.e candidate.
9340 INITIAL-INPUT: Same as initial-input arg in `anything'.
9341 PRESELECT: See preselect arg of `anything'.
9342 DEFAULT: This option is used only for compatibility with regular
9343 Emacs `completing-read'.
9344 BUFFER: Name of anything-buffer.
9345 MUST-MATCH: Candidate selected must be one of COLLECTION.
9346 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9347 HISTORY: A list containing specific history, default is nil.
9348 When it is non--nil, all elements of HISTORY are displayed in
9349 a special source before COLLECTION.
9350 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9351 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9352 NAME: The name related to this local source.
9353 VOLATILE: Use volatile attribute \(enabled by default\).
9354 SORT: A predicate to give to `sort' e.g `string-lessp'.
9355 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9356 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9357 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9359 Any prefix args passed during `anything-comp-read' invocation will be recorded
9360 in `anything-current-prefix-arg', otherwise if prefix args where given before
9361 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9362 That's mean you can pass prefix args before or after calling a command
9363 that use `anything-comp-read' See `anything-M-x' for example."
9364 (when (get-buffer anything-action-buffer)
9365 (kill-buffer anything-action-buffer))
9366 (flet ((action-fn (candidate)
9367 (if marked-candidates
9368 (anything-marked-candidates)
9369 (identity candidate))))
9370 (let ((hist `((name . ,(format "%s History" name))
9371 (candidates
9372 . (lambda ()
9373 (let ((all (anything-comp-read-get-candidates
9374 history nil nil ,alistp)))
9375 (anything-fast-remove-dups
9376 (if (and default (not (string= default "")))
9377 (delq nil (cons default (delete default all)))
9378 all)
9379 :test 'equal))))
9380 (filtered-candidate-transformer
9381 . (lambda (candidates sources)
9382 (loop for i in candidates
9383 do (set-text-properties 0 (length i) nil i)
9384 collect i)))
9385 (persistent-action . ,persistent-action)
9386 (persistent-help . ,persistent-help)
9387 (action . ,'action-fn)))
9388 (src `((name . ,name)
9389 (candidates
9390 . (lambda ()
9391 (let ((cands (anything-comp-read-get-candidates
9392 collection test sort alistp)))
9393 (unless (or must-match (string= anything-pattern ""))
9394 (setq cands (append (list anything-pattern) cands)))
9395 (if (and default (not (string= default "")))
9396 (delq nil (cons default (delete default cands)))
9397 cands))))
9398 (filtered-candidate-transformer ,fc-transformer)
9399 (requires-pattern . ,requires-pattern)
9400 (persistent-action . ,persistent-action)
9401 (persistent-help . ,persistent-help)
9402 (action . ,'action-fn))))
9403 (when volatile (setq src (append src '((volatile)))))
9404 (or (anything
9405 :sources `(,hist ,src)
9406 :input initial-input
9407 :default default
9408 :preselect preselect
9409 :prompt prompt
9410 :resume 'noresume
9411 :buffer buffer)
9412 (keyboard-quit)))))
9414 ;; Generic completing-read
9416 ;; Support also function as collection.
9417 ;; e.g M-x man is supported.
9418 ;; Support hash-table and vectors as collection.
9419 ;; NOTE:
9420 ;; Some crap emacs functions may not be supported
9421 ;; like ffap-alternate-file (bad use of completing-read)
9422 ;; and maybe others.
9423 ;; Provide a mode `anything-completion-mode' which turn on
9424 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9426 (defvar anything-completion-mode-string " AC")
9428 (defvar anything-completion-mode-quit-message
9429 "Anything completion disabled")
9431 (defvar anything-completion-mode-start-message
9432 "Anything completion enabled")
9434 ;;; Specialized handlers
9437 (defun anything-completing-read-symbols
9438 (prompt collection test require-match init
9439 hist default inherit-input-method name buffer)
9440 "Specialized function for fast symbols completion in `ac-mode'."
9442 (anything
9443 :sources `((name . ,name)
9444 (init . (lambda ()
9445 (with-current-buffer (anything-candidate-buffer 'global)
9446 (goto-char (point-min))
9447 (when (and default (stringp default)
9448 ;; Some defaults args result as
9449 ;; (symbol-name nil) == "nil".
9450 ;; e.g debug-on-entry.
9451 (not (string= default "nil")))
9452 (insert (concat default "\n")))
9453 (loop with all = (all-completions "" collection test)
9454 for sym in all
9455 unless (and default (eq sym default))
9456 do (insert (concat sym "\n"))))))
9457 (persistent-action . anything-lisp-completion-persistent-action)
9458 (persistent-help . "Show brief doc in mode-line")
9459 (candidates-in-buffer)
9460 (action . identity))
9461 :prompt prompt
9462 :buffer buffer
9463 :input init
9464 :resume 'noresume
9465 :default (or default ""))
9466 (keyboard-quit)))
9469 ;;; Generic completing read
9472 (defun anything-completing-read-default-1
9473 (prompt collection test require-match
9474 init hist default inherit-input-method
9475 name buffer)
9476 (anything-comp-read
9477 prompt collection
9478 :test test
9479 :fc-transformer #'(lambda (candidates source)
9480 ;; In regular `completing-read'
9481 ;; when a candidate is a cons cell
9482 ;; the car is used. Anything use
9483 ;; normally the cdr, so modify that
9484 ;; to fit `completing-read'.
9485 (loop for i in candidates
9486 for cand = (if (consp i) (car i) i)
9487 do (set-text-properties 0 (length cand) nil cand)
9488 collect cand))
9489 :history (eval (or (car-safe hist) hist))
9490 :must-match require-match
9491 :alistp nil
9492 :name name
9493 :buffer buffer
9494 ;; If DEF is not provided, fallback to empty string
9495 ;; to avoid `thing-at-point' to be appended on top of list
9496 :default (or default "")
9497 :initial-input init))
9499 (defun* anything-completing-read-default
9500 (prompt collection &optional
9501 predicate require-match
9502 initial-input hist def
9503 inherit-input-method)
9504 "An anything replacement of `completing-read'.
9505 This function should be used only as a `completing-read-function'.
9507 Don't use it directly, use instead `anything-comp-read' in your programs \
9508 which is more powerful.
9510 See documentation of `completing-read' and `all-completions' for details."
9511 (declare (special anything-completion-mode))
9512 (let* ((current-command this-command)
9513 (str-command (symbol-name current-command))
9514 (buf-name (format "*ac-mode-%s*" str-command))
9515 (entry (assq current-command
9516 anything-completing-read-handlers-alist))
9517 (def-com (cdr-safe entry))
9518 (str-defcom (and def-com (symbol-name def-com)))
9519 (def-args (list prompt collection predicate require-match
9520 initial-input hist def inherit-input-method))
9521 ;; Append the two extra args needed to set the buffer and source name
9522 ;; in anything specialized functions.
9523 (any-args (append def-args (list str-command buf-name)))
9524 anything-completion-mode-start-message ; Be quiet
9525 anything-completion-mode-quit-message)
9526 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9527 (unless (or (not entry) def-com)
9528 ;; An entry in *read-handlers-alist exists but have
9529 ;; a nil value, so we exit from here, disable `ac-mode'
9530 ;; and run the command again with it original behavior.
9531 ;; `ac-mode' will be restored on exit.
9532 (return-from anything-completing-read-default
9533 (unwind-protect
9534 (progn
9535 (ac-mode -1)
9536 (call-interactively current-command))
9537 (ac-mode 1))))
9538 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9539 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9540 (when (or (eq def-com 'completing-read)
9541 ;; All specialized functions are prefixed by "anything"
9542 (and (stringp str-defcom)
9543 (not (string-match "^anything" str-defcom))))
9544 (ac-mode -1))
9545 (unwind-protect
9546 (cond (;; An anything specialized function exists, run it.
9547 (and def-com anything-completion-mode)
9548 (apply def-com any-args))
9549 (;; Try to handle `ido-completing-read' everywhere.
9550 (and def-com (eq def-com 'ido-completing-read))
9551 (setcar (memq collection def-args)
9552 (all-completions "" collection predicate))
9553 (apply def-com def-args))
9554 (;; User set explicitely `completing-read' or something similar
9555 ;; in *read-handlers-alist, use this with exactly the same
9556 ;; args as in `completing-read'.
9557 ;; If we are here `anything-completion-mode' is now disabled.
9558 def-com
9559 (apply def-com def-args))
9560 (t ; Fall back to classic `anything-comp-read'.
9561 (anything-completing-read-default-1
9562 prompt collection predicate require-match
9563 initial-input hist def inherit-input-method str-command buf-name)))
9564 (ac-mode 1))))
9566 (defun* anything-generic-read-file-name
9567 (prompt &optional dir default-filename mustmatch initial predicate)
9568 "An anything replacement of `read-file-name'."
9569 (declare (special anything-completion-mode))
9570 (let* ((default (and default-filename
9571 (if (listp default-filename)
9572 (car default-filename)
9573 default-filename)))
9574 (init (or default initial dir default-directory))
9575 (ini-input (and init (expand-file-name init)))
9576 (current-command this-command)
9577 (str-command (symbol-name current-command))
9578 (buf-name (format "*ac-mode-%s*" str-command))
9579 (entry (assq current-command
9580 anything-completing-read-handlers-alist))
9581 (def-com (cdr-safe entry))
9582 (str-defcom (symbol-name def-com))
9583 (def-args (list prompt dir default-filename mustmatch initial predicate))
9584 ;; Append the two extra args needed to set the buffer and source name
9585 ;; in anything specialized functions.
9586 (any-args (append def-args (list str-command buf-name)))
9587 (ido-state ido-mode)
9588 anything-completion-mode-start-message ; Be quiet
9589 anything-completion-mode-quit-message ; Same here
9590 fname)
9591 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9592 (unless (or (not entry) def-com)
9593 (return-from anything-completing-read-default
9594 (unwind-protect
9595 (progn
9596 (ac-mode -1)
9597 (call-interactively current-command))
9598 (ac-mode 1))))
9599 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9600 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9601 (when (or (eq def-com 'read-file-name)
9602 (eq def-com 'ido-read-file-name)
9603 (and (stringp str-defcom)
9604 (not (string-match "^anything" str-defcom))))
9605 (ac-mode -1))
9606 (unwind-protect
9607 (setq fname
9608 (cond (;; A specialized function exists, run it
9609 ;; with the two extra args specific to anything..
9610 (and def-com anything-completion-mode
9611 (not (eq def-com 'ido-read-file-name)))
9612 (apply def-com any-args))
9613 (;; Def-com value is `ido-read-file-name'
9614 ;; run it with default args.
9615 (and def-com (eq def-com 'ido-read-file-name))
9616 (ido-mode 1)
9617 (apply def-com def-args))
9618 (;; Def-com value is `read-file-name'
9619 ;; run it with default args.
9620 def-com
9621 (apply def-com def-args))
9622 (t ; Fall back to classic `anything-c-read-file-name'.
9623 (anything-c-read-file-name
9624 prompt
9625 :name str-command
9626 :buffer buf-name
9627 :initial-input (expand-file-name init dir)
9628 :alistp nil
9629 :test predicate))))
9630 (ac-mode 1)
9631 (ido-mode (if ido-state 1 -1)))
9632 (if (and mustmatch (not (file-exists-p fname)))
9633 (if (y-or-n-p "File does not exists, create buffer?")
9634 fname (error "Abort file does not exists"))
9635 fname)))
9637 ;;;###autoload
9638 (define-minor-mode anything-completion-mode
9639 "Toggle generic anything completion.
9641 All functions in Emacs that use `completing-read'
9642 or `read-file-name' and friends will use anything interface
9643 when this mode is turned on.
9644 However you can modify this behavior for functions of your choice
9645 with `anything-completing-read-handlers-alist'.
9647 Called with a positive arg, turn on inconditionnaly, with a
9648 negative arg turn off.
9649 You can turn it on with `ac-mode'.
9651 Some crap emacs functions may not be supported,
9652 e.g `ffap-alternate-file' and maybe others
9653 You can add such functions to `anything-completing-read-handlers-alist'
9654 with a nil value.
9656 Note: This mode will work only partially on Emacs23."
9657 :group 'anything
9658 :global t
9659 :lighter anything-completion-mode-string
9660 (declare (special completing-read-function))
9661 (if anything-completion-mode
9662 (progn
9663 (setq completing-read-function 'anything-completing-read-default
9664 read-file-name-function 'anything-generic-read-file-name)
9665 (message anything-completion-mode-start-message))
9666 (setq completing-read-function (and (fboundp 'completing-read-default)
9667 'completing-read-default)
9668 read-file-name-function (and (fboundp 'read-file-name-default)
9669 'read-file-name-default))
9670 (message anything-completion-mode-quit-message)))
9672 (defalias 'ac-mode 'anything-completion-mode)
9676 ;;; Eshell completion.
9678 ;; Enable like this in .emacs:
9680 ;; (add-hook 'eshell-mode-hook
9681 ;; #'(lambda ()
9682 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9684 (defvar anything-c-source-esh
9685 '((name . "Eshell completions")
9686 (init . (lambda ()
9687 (setq pcomplete-current-completions nil
9688 pcomplete-last-completion-raw nil)
9689 ;; Eshell-command add this hook in all minibuffers
9690 ;; Remove it for the anything one.
9691 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9692 (candidates . anything-esh-get-candidates)
9693 (action . anything-ec-insert))
9694 "Anything source for Eshell completion.")
9696 ;; Internal.
9697 (defvar anything-ec-target "")
9698 (defun anything-ec-insert (candidate)
9699 "Insert CANDIDATE at point.
9700 This is the same as `ac-insert', just inlined here for compatibility."
9701 (let ((pt (point)))
9702 (when (and anything-ec-target
9703 (search-backward anything-ec-target nil t)
9704 (string= (buffer-substring (point) pt) anything-ec-target))
9705 (delete-region (point) pt)))
9706 (insert candidate))
9708 (defun anything-esh-get-candidates ()
9709 "Get candidates for eshell completion using `pcomplete'."
9710 (catch 'pcompleted
9711 (let* ((pcomplete-stub)
9712 pcomplete-seen pcomplete-norm-func
9713 pcomplete-args pcomplete-last pcomplete-index
9714 (pcomplete-autolist pcomplete-autolist)
9715 (pcomplete-suffix-list pcomplete-suffix-list))
9716 (with-anything-current-buffer
9717 (loop
9718 with table = (pcomplete-completions)
9719 with entry = (condition-case nil
9720 ;; For Emacs24
9721 (try-completion anything-pattern (pcomplete-entries))
9722 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9723 (error
9725 (let ((fc (car (last (pcomplete-parse-arguments)))))
9726 ;; Check if last arg require fname completion.
9727 (and (file-name-directory fc) fc))))
9728 for i in (if (listp table) table ; Emacs23 or commands.
9729 (all-completions pcomplete-stub table)) ; Emacs24
9730 for file-cand = (and entry
9731 (if (file-remote-p i) i
9732 (expand-file-name i (file-name-directory entry))))
9733 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9734 collect file-cand into ls
9735 else collect i into ls
9736 finally return
9737 (if (and entry (not (string= entry "")) (file-exists-p entry))
9738 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9740 ;;; Eshell history.
9743 (defvar anything-c-source-eshell-history
9744 '((name . "Eshell history")
9745 (init . (lambda ()
9746 (let (eshell-hist-ignoredups)
9747 ;; Dump the content's of hist file
9748 ;; to `eshell-history-ring'.
9749 (eshell-read-history eshell-history-file-name)
9750 ;; And now write the content's of ring to file.
9751 (eshell-write-history eshell-history-file-name t)
9752 (with-current-buffer (anything-candidate-buffer 'global)
9753 (insert-file-contents eshell-history-file-name)))
9754 ;; Same comment as in `anything-c-source-esh'
9755 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9756 (candidates-in-buffer)
9757 (filtered-candidate-transformer . (lambda (candidates sources)
9758 (reverse candidates)))
9759 (candidate-number-limit . 9999)
9760 (action . (lambda (candidate)
9761 (eshell-kill-input)
9762 (insert candidate))))
9763 "Anything source for Eshell history.")
9766 ;;; Show completion - an alternative of anything-show-completion.el.
9768 ;; Provide show completion with macro `with-anything-show-completion'.
9771 ;; Called each time cursor move in anything-buffer.
9772 (defun anything-c-show-completion ()
9773 (with-anything-current-buffer
9774 (overlay-put anything-c-show-completion-overlay
9775 'display (anything-get-selection))))
9777 (defun anything-c-show-completion-init-overlay (beg end)
9778 (and anything-c-turn-on-show-completion
9779 (setq anything-c-show-completion-overlay (make-overlay beg end))
9780 (overlay-put anything-c-show-completion-overlay
9781 'face 'anything-lisp-show-completion)))
9783 (defmacro with-anything-show-completion (beg end &rest body)
9784 "Show anything candidate in an overlay at point.
9785 BEG and END are the beginning and end position of the current completion
9786 in `anything-current-buffer'.
9787 BODY is an anything call where we want to enable show completion.
9788 If `anything-c-turn-on-show-completion' is nil just do nothing."
9789 (declare (indent 2) (debug t))
9790 `(let ((anything-move-selection-after-hook
9791 (and anything-c-turn-on-show-completion
9792 (append (list 'anything-c-show-completion)
9793 anything-move-selection-after-hook))))
9794 (unwind-protect
9795 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9796 ,@body)
9797 (and anything-c-turn-on-show-completion
9798 (delete-overlay anything-c-show-completion-overlay)))))
9801 ;;; Lisp symbol completion.
9804 ;;;###autoload
9805 (defun anything-lisp-completion-at-point ()
9806 "Anything lisp symbol completion at point."
9807 (interactive)
9808 (let* ((data (lisp-completion-at-point))
9809 (beg (car data))
9810 (end (point)) ; 'cadr data' is wrong when no space after point.
9811 (plist (nthcdr 3 data))
9812 (pred (plist-get plist :predicate))
9813 (lgst-len 0)
9814 (target (and beg end (buffer-substring-no-properties beg end)))
9815 (candidates (all-completions target (nth 2 data) pred))
9816 (anything-quit-if-no-candidate t)
9817 (anything-execute-action-at-once-if-one t)
9818 (anything-match-plugin-enabled
9819 (member 'anything-compile-source--match-plugin
9820 anything-compile-source-functions)))
9821 (if candidates
9822 (with-anything-show-completion beg end
9823 ;; Overlay is initialized now in anything-current-buffer.
9824 (anything
9825 :sources
9826 '((name . "Lisp completion")
9827 (init . (lambda ()
9828 (with-current-buffer (anything-candidate-buffer 'global)
9829 (loop for sym in candidates
9830 for len = (length sym)
9831 when (> len lgst-len) do (setq lgst-len len)
9832 do (insert (concat sym "\n"))))))
9833 (candidates-in-buffer)
9834 (persistent-action . anything-lisp-completion-persistent-action)
9835 (persistent-help . "Show brief doc in mode-line")
9836 (filtered-candidate-transformer anything-lisp-completion-transformer)
9837 (action . (lambda (candidate)
9838 (delete-region beg end)
9839 (insert candidate))))
9840 :input (if anything-match-plugin-enabled (concat target " ") target)))
9841 (message "[No Match]"))))
9843 (defun anything-lisp-completion-persistent-action (candidate)
9844 (let ((cursor-in-echo-area t)
9845 mode-line-in-non-selected-windows)
9846 (anything-c-eldoc-show-in-mode-line
9847 (propertize
9848 (anything-c-get-first-line-documentation
9849 (intern candidate))
9850 'face 'anything-lisp-completion-info))))
9852 (defun anything-lisp-completion-transformer (candidates source)
9853 "Anything candidates transformer for lisp completion."
9854 (declare (special lgst-len))
9855 (loop for c in candidates
9856 for sym = (intern c)
9857 for annot = (cond ((commandp sym) " (Com)")
9858 ((fboundp sym) " (Fun)")
9859 ((boundp sym) " (Var)")
9860 ((facep sym) " (Face)"))
9861 for spaces = (make-string (- lgst-len (length c)) ? )
9862 collect (cons (concat c spaces annot) c)))
9864 (defun anything-c-get-first-line-documentation (sym)
9865 "Return first line documentation of symbol SYM.
9866 If SYM is not documented, return \"Not documented\"."
9867 (let ((doc (cond ((fboundp sym)
9868 (documentation sym t))
9869 ((boundp sym)
9870 (documentation-property sym 'variable-documentation t))
9871 ((facep sym)
9872 (face-documentation sym))
9873 (t nil))))
9874 (if (and doc (not (string= doc ""))
9875 ;; `documentation' return "\n\n(args...)"
9876 ;; for CL-style functions.
9877 (not (string-match-p "^\n\n" doc)))
9878 (car (split-string doc "\n"))
9879 "Not documented")))
9881 ;;; File completion.
9883 ;; Complete file name at point.
9884 (defun anything-c-thing-before-point ()
9885 "Get symbol name before point.
9886 Borrowed from anything-complete.el, inlined here for compatibility."
9887 (save-excursion
9888 (let ((beg (point)))
9889 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9890 (when (re-search-backward
9891 "\\_<" (field-beginning nil nil (point-at-bol)) t)
9892 (buffer-substring-no-properties beg (match-end 0))))))
9894 ;;;###autoload
9895 (defun anything-c-complete-file-name-at-point ()
9896 "Complete file name at point."
9897 (interactive)
9898 (let* ((init (substring-no-properties (thing-at-point 'filename)))
9899 (end (point))
9900 (beg (- (point) (length init)))
9901 (anything-quit-if-no-candidate t)
9902 (anything-execute-action-at-once-if-one t)
9903 completion)
9904 (with-anything-show-completion beg end
9905 (setq completion (anything-c-read-file-name "FileName: "
9906 :initial-input init)))
9907 (anything-c-insert-file-name-completion-at-point completion)))
9909 ;; Internal
9910 (defvar anything-lisp-completion-counter 0)
9911 ;;;###autoload
9912 (defun anything-lisp-completion-at-point-or-indent (arg)
9913 "First call indent and second call complete lisp symbol.
9914 The second call should happen before `anything-lisp-completion-or-indent-delay',
9915 after this delay, next call will indent again.
9916 After completion, next call is always indent.
9917 See that like click and double mouse click.
9918 One hit indent, two quick hits maybe indent and complete."
9919 (interactive "P")
9920 ;; Be sure `indent-for-tab-command' will not try
9921 ;; to use `completion-at-point'.
9922 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
9923 t tab-always-indent)))
9924 (incf anything-lisp-completion-counter)
9925 (unwind-protect
9926 (if (> anything-lisp-completion-counter 1)
9927 (anything-lisp-completion-or-file-name-at-point)
9928 (indent-for-tab-command arg))
9929 ;; After `anything-lisp-completion-or-indent-delay' seconds
9930 ;; reset to 0.
9931 (run-with-timer anything-lisp-completion-or-indent-delay nil
9932 #'(lambda ()
9933 (setq anything-lisp-completion-counter 0)))
9934 ;; Always reset to 0 at second hit.
9935 (when (eq anything-lisp-completion-counter 2)
9936 (setq anything-lisp-completion-counter 0)))))
9938 ;;;###autoload
9939 (defun anything-lisp-completion-or-file-name-at-point ()
9940 "Complete lisp symbol or filename at point.
9941 Filename completion happen if filename is started in
9942 or between double quotes."
9943 (interactive)
9944 (let ((tap (substring-no-properties (thing-at-point 'filename))))
9945 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
9946 (save-excursion (search-backward "\"" (point-at-bol) t)))
9947 (anything-c-complete-file-name-at-point)
9948 (anything-lisp-completion-at-point))))
9950 (defun anything-c-apropos-init (test default)
9951 "Init candidates buffer for `anything-c-apropos' sources."
9952 (with-current-buffer (anything-candidate-buffer 'global)
9953 (goto-char (point-min))
9954 (when (and default (stringp default)
9955 ;; Some defaults args result as
9956 ;; (symbol-name nil) == "nil".
9957 ;; e.g debug-on-entry.
9958 (not (string= default "nil"))
9959 (funcall test (intern default)))
9960 (insert (concat default "\n")))
9961 (loop with all = (all-completions "" obarray test)
9962 for sym in all
9963 unless (and default (eq sym default))
9964 do (insert (concat sym "\n")))))
9967 ;;; Run Externals commands within Emacs with anything completion
9970 (defvar anything-external-command-history nil)
9972 (defun anything-c-external-commands-list-1 (&optional sort)
9973 "Returns a list of all external commands the user can execute.
9974 If `anything-c-external-commands-list' is non-nil it will
9975 return its contents. Else it calculates all external commands
9976 and sets `anything-c-external-commands-list'."
9977 (if anything-c-external-commands-list
9978 anything-c-external-commands-list
9979 (setq anything-c-external-commands-list
9980 (loop
9981 with paths = (split-string (getenv "PATH") path-separator)
9982 with completions = ()
9983 for dir in paths
9984 when (and (file-exists-p dir) (file-accessible-directory-p dir))
9985 for lsdir = (loop for i in (directory-files dir t)
9986 for bn = (file-name-nondirectory i)
9987 when (and (not (member bn completions))
9988 (not (file-directory-p i))
9989 (file-executable-p i))
9990 collect bn)
9991 append lsdir into completions
9992 finally return (if sort (sort completions 'string-lessp) completions)))))
9994 (defun anything-run-or-raise (exe &optional file)
9995 "Generic command that run asynchronously EXE.
9996 If EXE is already running just jump to his window if `anything-raise-command'
9997 is non--nil.
9998 When FILE argument is provided run EXE with FILE.
9999 In this case EXE must be provided as \"EXE %s\"."
10000 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10001 "'%s'" "" exe))))
10002 (proc (if file (concat real-com " " file) real-com)))
10003 (if (get-process proc)
10004 (if anything-raise-command
10005 (shell-command (format anything-raise-command real-com))
10006 (error "Error: %s is already running" real-com))
10007 (when (loop for i in anything-c-external-commands-list thereis real-com)
10008 (message "Starting %s..." real-com)
10009 (if file
10010 (start-process-shell-command proc nil (format exe file))
10011 (start-process-shell-command proc nil real-com))
10012 (set-process-sentinel
10013 (get-process proc)
10014 #'(lambda (process event)
10015 (when (and (string= event "finished\n")
10016 anything-raise-command
10017 (not (anything-c-get-pid-from-process-name real-com)))
10018 (shell-command (format anything-raise-command "emacs")))
10019 (message "%s process...Finished." process))))
10020 (setq anything-c-external-commands-list
10021 (cons real-com
10022 (delete real-com anything-c-external-commands-list))))))
10026 ;;; Generic action functions
10029 (defun anything-c-file-buffers (filename)
10030 "Returns a list of buffer names corresponding to FILENAME."
10031 (let ((name (expand-file-name filename))
10032 (buf-list ()))
10033 (dolist (buf (buffer-list) buf-list)
10034 (let ((bfn (buffer-file-name buf)))
10035 (when (and bfn (string= name bfn))
10036 (push (buffer-name buf) buf-list))))))
10038 (defun anything-revert-buffer (candidate)
10039 (with-current-buffer candidate
10040 (when (or (buffer-modified-p)
10041 (not (verify-visited-file-modtime
10042 (get-buffer candidate))))
10043 (revert-buffer t t))))
10045 (defun anything-revert-marked-buffers (ignore)
10046 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10048 (defun anything-kill-marked-buffers (ignore)
10049 (mapc 'kill-buffer (anything-marked-candidates)))
10051 (defun anything-c-delete-file (file)
10052 "Delete the given file after querying the user.
10053 Ask to kill buffers associated with that file, too."
10054 (let ((buffers (anything-c-file-buffers file)))
10055 (if (< emacs-major-version 24)
10056 ;; `dired-delete-file' in Emacs versions < 24
10057 ;; doesn't support delete-by-moving-to-trash
10058 ;; so use `delete-directory' and `delete-file'
10059 ;; that handle it.
10060 (cond ((and (not (file-symlink-p file))
10061 (file-directory-p file)
10062 (directory-files file t dired-re-no-dot))
10063 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10064 (delete-directory file 'recursive)))
10065 ((and (not (file-symlink-p file))
10066 (file-directory-p file))
10067 (delete-directory file))
10068 (t (delete-file file)))
10069 (dired-delete-file
10070 file 'dired-recursive-deletes delete-by-moving-to-trash))
10071 (when buffers
10072 (dolist (buf buffers)
10073 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10074 (kill-buffer buf))))))
10076 (defun anything-get-mailcap-for-file (filename)
10077 "Get the command to use for FILENAME from mailcap files.
10078 The command is like <command %s> and is meant to use with `format'."
10079 (mailcap-parse-mailcaps)
10080 (let* ((ext (file-name-extension filename))
10081 (mime (when ext (mailcap-extension-to-mime ext)))
10082 (result (when mime (mailcap-mime-info mime))))
10083 ;; If elisp file have no associations in .mailcap
10084 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10085 (when (stringp result) result)))
10087 (defun anything-get-default-program-for-file (filename)
10088 "Try to find a default program to open FILENAME.
10089 Try first in `anything-c-external-programs-associations' and then in mailcap file
10090 if nothing found return nil."
10091 (let* ((ext (file-name-extension filename))
10092 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10093 (cond ((and def-prog (not (string= def-prog "")))
10094 (concat def-prog " %s"))
10095 ((and anything-c-default-external-file-browser
10096 (file-directory-p filename))
10097 (concat anything-c-default-external-file-browser " %s"))
10098 (t (anything-get-mailcap-for-file filename)))))
10100 (defun anything-c-open-file-externally (file)
10101 "Open FILE with an external program.
10102 Try to guess which program to use with `anything-get-default-program-for-file'.
10103 If not found or a prefix arg is given query the user which tool to use."
10104 (let* ((fname (expand-file-name file))
10105 (collection (anything-c-external-commands-list-1 'sort))
10106 (def-prog (anything-get-default-program-for-file fname))
10107 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10108 ;; Prefix arg or no default program.
10109 (prog1
10110 (anything-comp-read
10111 "Program: " collection
10112 :must-match t
10113 :name "Open file Externally"
10114 :history anything-external-command-history)
10115 ;; Always prompt to set this program as default.
10116 (setq def-prog nil))
10117 ;; No prefix arg or default program exists.
10118 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10119 (program (concat real-prog-name " '%s'")))
10120 (unless (or def-prog ; Association exists, no need to record it.
10121 ;; Don't try to record non--filenames associations (e.g urls).
10122 (not (file-exists-p fname)))
10123 (when
10124 (y-or-n-p
10125 (format
10126 "Do you want to make `%s' the default program for this kind of files? "
10127 real-prog-name))
10128 (anything-aif (assoc (file-name-extension fname)
10129 anything-c-external-programs-associations)
10130 (setq anything-c-external-programs-associations
10131 (delete it anything-c-external-programs-associations)))
10132 (push (cons (file-name-extension fname)
10133 (read-string
10134 "Program (Add args maybe and confirm): " real-prog-name))
10135 anything-c-external-programs-associations)
10136 (customize-save-variable 'anything-c-external-programs-associations
10137 anything-c-external-programs-associations)))
10138 (anything-run-or-raise program file)
10139 (setq anything-external-command-history
10140 (cons real-prog-name
10141 (delete real-prog-name
10142 (loop for i in anything-external-command-history
10143 when (executable-find i) collect i))))))
10146 (defun anything-c-find-file-or-marked (candidate)
10147 "Open file CANDIDATE or open anything marked files in background."
10148 (let ((marked (anything-marked-candidates))
10149 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10150 (find-file-wildcards nil))
10151 (if (> (length marked) 1)
10152 ;; Open all marked files in background and display
10153 ;; the first one.
10154 (progn (mapc 'find-file-noselect (cdr marked))
10155 (find-file (car marked)))
10156 (if (and (not (file-exists-p candidate))
10157 (and ffap-url-regexp
10158 (not (string-match ffap-url-regexp candidate)))
10159 (string-match "/$" candidate))
10160 ;; A a non--existing filename ending with /
10161 ;; Create a directory and jump to it.
10162 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10163 (let ((dirfname (directory-file-name candidate)))
10164 (if (file-exists-p dirfname)
10165 (error "Mkdir: Unable to create directory `%s': file exists."
10166 (anything-c-basename dirfname))
10167 (make-directory candidate 'parent)))
10168 (anything-find-files-1 candidate))
10169 ;; A non--existing filename NOT ending with / or
10170 ;; an existing filename, create or jump to it.
10171 (find-file-at-point (car marked))))))
10173 (defun anything-delete-marked-files (ignore)
10174 (let* ((files (anything-marked-candidates))
10175 (len (length files)))
10176 (if (not (y-or-n-p
10177 (format "Delete *%s File(s):\n%s"
10179 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10180 (message "(No deletions performed)")
10181 (dolist (i files)
10182 (set-text-properties 0 (length i) nil i)
10183 (anything-c-delete-file i))
10184 (message "%s File(s) deleted" len))))
10186 (defun anything-ediff-marked-buffers (candidate &optional merge)
10187 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10188 With optional arg MERGE call `ediff-merge-buffers'."
10189 (let ((lg-lst (length (anything-marked-candidates)))
10190 buf1 buf2)
10191 (case lg-lst
10193 (error "Error:You have to mark at least 1 buffer"))
10195 (setq buf1 anything-current-buffer
10196 buf2 (first (anything-marked-candidates))))
10198 (setq buf1 (first (anything-marked-candidates))
10199 buf2 (second (anything-marked-candidates))))
10201 (error "Error:To much buffers marked!")))
10202 (if merge
10203 (ediff-merge-buffers buf1 buf2)
10204 (ediff-buffers buf1 buf2))))
10206 (defun anything-ediff-marked-buffers-merge (candidate)
10207 "Ediff merge `anything-current-buffer' with CANDIDATE.
10208 See `anything-ediff-marked-buffers'."
10209 (anything-ediff-marked-buffers candidate t))
10211 (defun anything-bookmark-get-bookmark-from-name (bmk)
10212 "Return bookmark name even if it is a bookmark with annotation.
10213 e.g prepended with *.
10214 Return nil if bmk is not a valid bookmark."
10215 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10216 (if (assoc bookmark bookmark-alist)
10217 bookmark
10218 (when (assoc bmk bookmark-alist)
10219 bmk))))
10221 (defun anything-delete-marked-bookmarks (ignore)
10222 "Delete this bookmark or all marked bookmarks."
10223 (dolist (i (anything-marked-candidates))
10224 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10225 'batch)))
10227 (defun anything-require-or-error (feature function)
10228 (or (require feature nil t)
10229 (error "Need %s to use `%s'." feature function)))
10231 (defun anything-find-buffer-on-elscreen (candidate)
10232 "Open buffer in new screen, if marked buffers open all in elscreens."
10233 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10234 (anything-aif (anything-marked-candidates)
10235 (dolist (i it)
10236 (let ((target-screen (elscreen-find-screen-by-buffer
10237 (get-buffer i) 'create)))
10238 (elscreen-goto target-screen)))
10239 (let ((target-screen (elscreen-find-screen-by-buffer
10240 (get-buffer candidate) 'create)))
10241 (elscreen-goto target-screen))))
10243 (defun anything-elscreen-find-file (file)
10244 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10245 (elscreen-find-file file))
10247 ;;;###autoload
10248 (defun w32-shell-execute-open-file (file)
10249 (interactive "fOpen file:")
10250 (with-no-warnings
10251 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10252 "/" "\\"
10253 (replace-regexp-in-string ; strip cygdrive paths
10254 "/cygdrive/\\(.\\)" "\\1:"
10255 file nil nil) nil t))))
10257 (defun anything-c-open-file-with-default-tool (file)
10258 "Open FILE with the default tool on this platform."
10259 (if (eq system-type 'windows-nt)
10260 (w32-shell-execute-open-file file)
10261 (start-process "anything-c-open-file-with-default-tool"
10263 (cond ((eq system-type 'gnu/linux)
10264 "xdg-open")
10265 ((or (eq system-type 'darwin) ;; Mac OS X
10266 (eq system-type 'macos)) ;; Mac OS 9
10267 "open"))
10268 file)))
10270 (defun anything-c-open-dired (file)
10271 "Opens a dired buffer in FILE's directory. If FILE is a
10272 directory, open this directory."
10273 (if (file-directory-p file)
10274 (dired file)
10275 (dired (file-name-directory file))
10276 (dired-goto-file file)))
10278 (defun anything-c-display-to-real-line (candidate)
10279 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10280 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10281 (error "Line number not found")))
10283 (defun anything-c-action-line-goto (lineno-and-content)
10284 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10285 (append lineno-and-content
10286 (list (if (and (anything-attr-defined 'target-file)
10287 (not anything-in-persistent-action))
10288 'find-file-other-window
10289 'find-file)))))
10291 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10292 (apply #'anything-goto-file-line
10293 (if (stringp file-line-content)
10294 ;; Case: filtered-candidate-transformer is skipped
10295 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10296 file-line-content)))
10298 (require 'compile)
10299 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10300 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10302 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10303 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10304 (let ((filename (match-string 1 candidate))
10305 (lineno (match-string 2 candidate))
10306 (content (match-string 3 candidate)))
10307 (cons (format "%s:%s\n %s"
10308 (propertize filename 'face compilation-info-face)
10309 (propertize lineno 'face compilation-line-face)
10310 content)
10311 (list (expand-file-name
10312 filename
10313 (or (anything-interpret-value (anything-attr 'default-directory))
10314 (and (anything-candidate-buffer)
10315 (buffer-local-value
10316 'default-directory (anything-candidate-buffer)))))
10317 (string-to-number lineno) content)))))
10319 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10320 (anything-aif (anything-attr 'before-jump-hook)
10321 (funcall it))
10322 (when file (funcall find-file-function file))
10323 (if (anything-attr-defined 'adjust)
10324 (anything-c-goto-line-with-adjustment lineno content)
10325 (anything-goto-line lineno))
10326 (unless (anything-attr-defined 'recenter)
10327 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10328 (anything-aif (anything-attr 'after-jump-hook)
10329 (funcall it))
10330 (when anything-in-persistent-action
10331 (anything-match-line-color-current-line)))
10333 (defun anything-find-file-as-root (candidate)
10334 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10336 (defun anything-find-many-files (ignore)
10337 (mapc 'find-file (anything-marked-candidates)))
10339 ;; borrowed from etags.el
10340 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10341 (defun anything-c-goto-line-with-adjustment (line line-content)
10342 (let ((startpos)
10343 offset found pat)
10344 ;; This constant is 1/2 the initial search window.
10345 ;; There is no sense in making it too small,
10346 ;; since just going around the loop once probably
10347 ;; costs about as much as searching 2000 chars.
10348 (setq offset 1000
10349 found nil
10350 pat (concat (if (eq selective-display t)
10351 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10352 (regexp-quote line-content)))
10353 ;; If no char pos was given, try the given line number.
10354 (setq startpos (progn (anything-goto-line line) (point)))
10355 (or startpos (setq startpos (point-min)))
10356 ;; First see if the tag is right at the specified location.
10357 (goto-char startpos)
10358 (setq found (looking-at pat))
10359 (while (and (not found)
10360 (progn
10361 (goto-char (- startpos offset))
10362 (not (bobp))))
10363 (setq found
10364 (re-search-forward pat (+ startpos offset) t)
10365 offset (* 3 offset))) ; expand search window
10366 (or found
10367 (re-search-forward pat nil t)
10368 (error "not found")))
10369 ;; Position point at the right place
10370 ;; if the search string matched an extra Ctrl-m at the beginning.
10371 (and (eq selective-display t)
10372 (looking-at "\^m")
10373 (forward-char 1))
10374 (beginning-of-line))
10376 (anything-document-attribute 'default-directory "type . file-line"
10377 "`default-directory' to interpret file.")
10378 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10379 "Function to call before jumping to the target location.")
10380 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10381 "Function to call after jumping to the target location.")
10382 (anything-document-attribute 'adjust "type . file-line"
10383 "Search around line matching line contents.")
10384 (anything-document-attribute 'recenter "type . file-line / line"
10385 "`recenter' after jumping.")
10386 (anything-document-attribute 'target-file "type . line"
10387 "Goto line of target-file.")
10389 ;;;###autoload
10390 (defun anything-c-call-interactively (cmd-or-name)
10391 "Execute CMD-OR-NAME as Emacs command.
10392 It is added to `extended-command-history'.
10393 `anything-current-prefix-arg' is used as the command's prefix argument."
10394 (setq extended-command-history
10395 (cons (anything-c-stringify cmd-or-name)
10396 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10397 (let ((current-prefix-arg anything-current-prefix-arg)
10398 (cmd (anything-c-symbolify cmd-or-name)))
10399 (if (stringp (symbol-function cmd))
10400 (execute-kbd-macro (symbol-function cmd))
10401 (setq this-command cmd)
10402 (call-interactively cmd))))
10404 ;;;###autoload
10405 (defun anything-c-set-variable (var)
10406 "Set value to VAR interactively."
10407 (interactive)
10408 (let ((sym (anything-c-symbolify var)))
10409 (set sym (eval-minibuffer (format "Set %s: " var)
10410 (prin1-to-string (symbol-value sym))))))
10411 ;; (setq hh 12)
10412 ;; (anything-c-set-variable 'hh)
10416 ;;; Persistent Action Helpers
10419 (defvar anything-match-line-overlay-face nil)
10420 (defvar anything-match-line-overlay nil)
10422 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10423 "Highlight and underline current position"
10424 (let ((args (list (or start (line-beginning-position))
10425 (or end (1+ (line-end-position)))
10426 buf)))
10427 (if (not anything-match-line-overlay)
10428 (setq anything-match-line-overlay (apply 'make-overlay args))
10429 (apply 'move-overlay anything-match-line-overlay args)))
10430 (overlay-put anything-match-line-overlay
10431 'face (or face anything-match-line-overlay-face))
10432 (when rec
10433 (goto-char start)
10434 (recenter)))
10436 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10439 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10441 (defun anything-match-line-cleanup ()
10442 (when anything-match-line-overlay
10443 (delete-overlay anything-match-line-overlay)
10444 (setq anything-match-line-overlay nil)))
10446 (defun anything-match-line-update ()
10447 (when anything-match-line-overlay
10448 (delete-overlay anything-match-line-overlay)
10449 (anything-match-line-color-current-line)))
10451 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10452 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10455 ;;; Actions Transformers
10458 ;;; Files
10459 (defun anything-c-transform-file-load-el (actions candidate)
10460 "Add action to load the file CANDIDATE if it is an emacs lisp
10461 file. Else return ACTIONS unmodified."
10462 (if (member (file-name-extension candidate) '("el" "elc"))
10463 (append actions '(("Load Emacs Lisp File" . load-file)))
10464 actions))
10466 (defun anything-c-transform-file-browse-url (actions candidate)
10467 "Add an action to browse the file CANDIDATE if it in a html
10468 file or URL. Else return ACTIONS unmodified."
10469 (let ((browse-action '("Browse with Browser" . browse-url)))
10470 (cond ((string-match "^http\\|^ftp" candidate)
10471 (cons browse-action actions))
10472 ((string-match "\\.html?$" candidate)
10473 (append actions (list browse-action)))
10474 (t actions))))
10476 ;;; Function
10477 (defun anything-c-transform-function-call-interactively (actions candidate)
10478 "Add an action to call the function CANDIDATE interactively if
10479 it is a command. Else return ACTIONS unmodified."
10480 (if (commandp (intern-soft candidate))
10481 (append actions '(("Call Interactively"
10483 anything-c-call-interactively)))
10484 actions))
10486 ;;;; S-Expressions
10487 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10488 "If CANDIDATE's `car' is a command, then add an action to
10489 evaluate it and put it onto the `command-history'."
10490 (if (commandp (car (read candidate)))
10491 ;; Make it first entry
10492 (cons '("Eval and put onto command-history" .
10493 (lambda (sexp)
10494 (let ((sym (read sexp)))
10495 (eval sym)
10496 (setq command-history
10497 (cons sym command-history)))))
10498 actions)
10499 actions))
10502 ;;; Candidate Transformers
10505 ;;; Buffers
10506 (defun anything-c-skip-boring-buffers (buffers)
10507 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10509 (defun anything-c-skip-current-buffer (buffers)
10510 (if anything-allow-skipping-current-buffer
10511 (remove (buffer-name anything-current-buffer) buffers)
10512 buffers))
10514 (defun anything-c-shadow-boring-buffers (buffers)
10515 "Buffers matching `anything-c-boring-buffer-regexp' will be
10516 displayed with the `file-name-shadow' face if available."
10517 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10519 (defvar anything-c-buffer-display-string-functions
10520 '(anything-c-buffer-display-string--compilation
10521 anything-c-buffer-display-string--shell
10522 anything-c-buffer-display-string--eshell)
10523 "Functions to setup display string for buffer.
10525 Function has one argument, buffer name.
10526 If it returns string, use it.
10527 If it returns nil, display buffer name.
10528 See `anything-c-buffer-display-string--compilation' for example.")
10530 (defun anything-c-transform-buffer-display-string (buffers)
10531 "Setup display string for buffer candidates
10532 using `anything-c-buffer-display-string-functions'."
10533 (loop for buf in buffers
10534 if (consp buf)
10535 collect buf
10536 else
10537 for disp = (progn (set-buffer buf)
10538 (run-hook-with-args-until-success
10539 'anything-c-buffer-display-string-functions buf))
10540 collect (if disp (cons disp buf) buf)))
10542 (defun anything-c-buffer-display-string--compilation (buf)
10543 (anything-aif (car compilation-arguments)
10544 (format "%s: %s [%s]" buf it default-directory)))
10546 (defun anything-c-buffer-display-string--eshell (buf)
10547 (declare (special eshell-history-ring))
10548 (when (eq major-mode 'eshell-mode)
10549 (format "%s: %s [%s]" buf
10550 (ignore-errors (ring-ref eshell-history-ring 0))
10551 default-directory)))
10553 (defun anything-c-buffer-display-string--shell (buf)
10554 (when (eq major-mode 'shell-mode)
10555 (format "%s: %s [%s]" buf
10556 (ignore-errors (ring-ref comint-input-ring 0))
10557 default-directory)))
10559 ;;; Files
10560 (defun anything-c-shadow-boring-files (files)
10561 "Files matching `anything-c-boring-file-regexp' will be
10562 displayed with the `file-name-shadow' face if available."
10563 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10565 (defun anything-c-skip-boring-files (files)
10566 "Files matching `anything-c-boring-file-regexp' will be skipped."
10567 (anything-c-skip-entries files anything-c-boring-file-regexp))
10568 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10570 (defun anything-c-skip-current-file (files)
10571 "Current file will be skipped."
10572 (remove (buffer-file-name anything-current-buffer) files))
10574 (defun anything-c-w32-pathname-transformer (args)
10575 "Change undesirable features of windows pathnames to ones more acceptable to
10576 other candidate transformers."
10577 (if (eq system-type 'windows-nt)
10578 (mapcar (lambda (x)
10579 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10580 (mapcar (lambda (y)
10581 (replace-regexp-in-string "\\\\" "/" y)) args))
10582 args))
10584 (defun anything-c-shorten-home-path (files)
10585 "Replaces /home/user with ~."
10586 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10587 (getenv "HOME"))))
10588 (mapcar (lambda (file)
10589 (if (and (stringp file) (string-match home file))
10590 (cons (replace-match "~" nil nil file) file)
10591 file))
10592 files)))
10594 ;;; Functions
10595 (defun anything-c-mark-interactive-functions (functions)
10596 "Mark interactive functions (commands) with (i) after the function name."
10597 (let (list)
10598 (loop for function in functions
10599 do (push (cons (concat function
10600 (when (commandp (intern-soft function)) " (i)"))
10601 function)
10602 list)
10603 finally (return (nreverse list)))))
10606 ;;; Adaptive Sorting of Candidates
10609 ;; Internal
10610 (defvar anything-c-adaptive-done nil
10611 "nil if history information is not yet stored for the current
10612 selection.")
10614 (defvar anything-c-adaptive-history nil
10615 "Contains the stored history information.
10616 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10618 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10619 "Reset `anything-c-adaptive-done' when anything is started."
10620 (when anything-c-use-adaptative-sorting
10621 (setq anything-c-adaptive-done nil)))
10623 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10624 "Store history information when action is executed on selected candidate."
10625 (when anything-c-use-adaptative-sorting
10626 (anything-c-adaptive-store-selection)))
10628 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10629 "Store history information when the user goes to the action buffer."
10630 (when anything-c-use-adaptative-sorting
10631 (anything-c-adaptive-store-selection)))
10633 (defun anything-c-source-use-adaptative-p (&optional source-name)
10634 "Return current source only if it use adaptative history, nil otherwise."
10635 (when anything-c-use-adaptative-sorting
10636 (let* ((source (or source-name (anything-get-current-source)))
10637 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10638 (assoc (assoc-default 'type source)
10639 anything-type-attributes))
10640 (assoc-default 'candidate-transformer
10641 (assoc (assoc-default 'type source)
10642 anything-type-attributes))
10643 (assoc-default 'filtered-candidate-transformer source)
10644 (assoc-default 'candidate-transformer source))))
10645 (if (listp adapt-source)
10646 (when (member 'anything-c-adaptive-sort adapt-source) source)
10647 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10649 (defun anything-c-adaptive-store-selection ()
10650 "Store history information for the selected candidate."
10651 (unless anything-c-adaptive-done
10652 (setq anything-c-adaptive-done t)
10653 (let ((source (anything-c-source-use-adaptative-p)))
10654 (when source
10655 (let* ((source-name (or (assoc-default 'type source)
10656 (assoc-default 'name source)))
10657 (source-info (or (assoc source-name anything-c-adaptive-history)
10658 (progn
10659 (push (list source-name) anything-c-adaptive-history)
10660 (car anything-c-adaptive-history))))
10661 (selection (anything-get-selection))
10662 (selection-info (progn
10663 (setcdr source-info
10664 (cons
10665 (let ((found (assoc selection (cdr source-info))))
10666 (if (not found)
10667 ;; new entry
10668 (list selection)
10670 ;; move entry to the beginning of the
10671 ;; list, so that it doesn't get
10672 ;; trimmed when the history is
10673 ;; truncated
10674 (setcdr source-info
10675 (delete found (cdr source-info)))
10676 found))
10677 (cdr source-info)))
10678 (cadr source-info)))
10679 (pattern-info (progn
10680 (setcdr selection-info
10681 (cons
10682 (let ((found (assoc anything-pattern (cdr selection-info))))
10683 (if (not found)
10684 ;; new entry
10685 (cons anything-pattern 0)
10687 ;; move entry to the beginning of the
10688 ;; list, so if two patterns used the
10689 ;; same number of times then the one
10690 ;; used last appears first in the list
10691 (setcdr selection-info
10692 (delete found (cdr selection-info)))
10693 found))
10694 (cdr selection-info)))
10695 (cadr selection-info))))
10697 ;; increase usage count
10698 (setcdr pattern-info (1+ (cdr pattern-info)))
10700 ;; truncate history if needed
10701 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10702 (setcdr selection-info
10703 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10705 (defun anything-c-adaptative-maybe-load-history ()
10706 (when (and anything-c-use-adaptative-sorting
10707 (file-readable-p anything-c-adaptive-history-file))
10708 (load-file anything-c-adaptive-history-file)))
10710 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10711 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10713 (defun anything-c-adaptive-save-history (&optional arg)
10714 "Save history information to file given by `anything-c-adaptive-history-file'."
10715 (interactive "p")
10716 (when anything-c-use-adaptative-sorting
10717 (with-temp-buffer
10718 (insert
10719 ";; -*- mode: emacs-lisp -*-\n"
10720 ";; History entries used for anything adaptive display.\n")
10721 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10722 (current-buffer))
10723 (insert ?\n)
10724 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10725 (unless arg 'quiet)))))
10727 (defun anything-c-adaptive-sort (candidates source)
10728 "Sort the CANDIDATES for SOURCE by usage frequency.
10729 This is a filtered candidate transformer you can use for the
10730 attribute `filtered-candidate-transformer' of a source in
10731 `anything-sources' or a type in `anything-type-attributes'."
10732 (let* ((source-name (or (assoc-default 'type source)
10733 (assoc-default 'name source)))
10734 (source-info (assoc source-name anything-c-adaptive-history)))
10735 (if source-info
10736 (let ((usage
10737 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10738 ;; pairs
10739 (mapcar (lambda (candidate-info)
10740 (let ((count 0))
10741 (dolist (pattern-info (cdr candidate-info))
10742 (if (not (equal (car pattern-info)
10743 anything-pattern))
10744 (incf count (cdr pattern-info))
10746 ;; if current pattern is equal to the previously
10747 ;; used one then this candidate has priority
10748 ;; (that's why its count is boosted by 10000) and
10749 ;; it only has to compete with other candidates
10750 ;; which were also selected with the same pattern
10751 (setq count (+ 10000 (cdr pattern-info)))
10752 (return)))
10753 (cons (car candidate-info) count)))
10754 (cdr source-info)))
10755 sorted)
10756 (if (and usage (consp usage))
10757 ;; sort the list in descending order, so candidates with highest
10758 ;; priorty come first
10759 (progn
10760 (setq usage (sort usage (lambda (first second)
10761 (> (cdr first) (cdr second)))))
10763 ;; put those candidates first which have the highest usage count
10764 (dolist (info usage)
10765 (when (member* (car info) candidates
10766 :test 'anything-c-adaptive-compare)
10767 (push (car info) sorted)
10768 (setq candidates (remove* (car info) candidates
10769 :test 'anything-c-adaptive-compare))))
10771 ;; and append the rest
10772 (append (reverse sorted) candidates nil))
10773 (message "Your `%s' is maybe corrupted or too old, \
10774 you should reinitialize it with `anything-c-reset-adaptative-history'"
10775 anything-c-adaptive-history-file)
10776 (sit-for 1)
10777 candidates))
10778 ;; if there is no information stored for this source then do nothing
10779 candidates)))
10781 ;;;###autoload
10782 (defun anything-c-reset-adaptative-history ()
10783 "Delete all `anything-c-adaptive-history' and his file.
10784 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10785 (interactive)
10786 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10787 (setq anything-c-adaptive-history nil)
10788 (delete-file anything-c-adaptive-history-file)))
10790 (defun anything-c-adaptive-compare (x y)
10791 "Compare candidates X and Y taking into account that the
10792 candidate can be in (DISPLAY . REAL) format."
10793 (equal (if (listp x)
10794 (cdr x)
10796 (if (listp y)
10797 (cdr y)
10798 y)))
10802 ;;; Outliner
10805 (defvar anything-outline-goto-near-line-flag t)
10806 (defvar anything-outline-using nil)
10807 (defun anything-after-update-hook--outline ()
10808 (if (and (eq anything-outline-using t)
10809 (eq anything-outline-goto-near-line-flag t))
10810 (anything-outline-goto-near-line)))
10811 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10813 (defun anything-outline-goto-near-line ()
10814 (with-anything-window
10815 ;; TODO need consideration whether to update position by every input.
10816 (when t ; (equal anything-pattern "")
10817 (anything-goto-line 2)
10818 (let ((lineno (with-anything-current-buffer
10819 (line-number-at-pos (car anything-current-position)))))
10820 (block exit
10821 (while (<= (progn (skip-chars-forward " ")
10822 (or (number-at-point) lineno))
10823 lineno)
10824 (forward-line 1)
10825 (when (eobp)
10826 (forward-line -1)
10827 (return-from exit))))
10828 (forward-line -1)
10829 (and (bobp) (forward-line 1))
10830 (and (anything-pos-header-line-p) (forward-line -2))
10831 (anything-mark-current-line)))))
10835 ;;; Plug-in
10838 ;; Plug-in: info-index
10839 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
10840 (let (result)
10841 (unless (anything-candidate-buffer)
10842 (save-window-excursion
10843 (info file)
10844 (let (Info-history
10845 (tobuf (anything-candidate-buffer 'global))
10846 (infobuf (current-buffer))
10847 s e)
10848 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
10849 (Info-goto-node node)
10850 (goto-char (point-min))
10851 (while (search-forward "\n* " nil t)
10852 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
10853 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
10854 (setq s (point-at-bol)
10855 e (point-at-eol))
10856 (with-current-buffer tobuf
10857 (insert-buffer-substring infobuf s e)
10858 (insert "\n"))))))))))
10860 (defun anything-c-info-goto (node-line)
10861 (Info-goto-node (car node-line))
10862 (anything-goto-line (cdr node-line)))
10864 (defun anything-c-info-display-to-real (line)
10865 (and (string-match
10866 ;; This regexp is stolen from Info-apropos-matches
10867 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
10868 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
10869 (string-to-number (or (match-string 3 line) "1")))))
10871 (defun anything-c-make-info-source (source file)
10872 `(,@source
10873 (name . ,(concat "Info Index: " file))
10874 (info-file . ,file)
10875 (init . anything-c-info-init)
10876 (display-to-real . anything-c-info-display-to-real)
10877 (get-line . buffer-substring)
10878 (candidates-in-buffer)
10879 (action ("Goto node" . anything-c-info-goto))))
10881 (defun anything-compile-source--info-index (source)
10882 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
10883 (anything-c-make-info-source source it)
10884 source))
10885 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
10887 (anything-document-attribute 'info-index "info-index plugin"
10888 "Create a source of info index very easily.
10890 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10892 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
10893 "Index nodes of info file.
10895 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10896 Some info files are missing index specification.
10898 ex. See `anything-c-source-info-screen'.")
10900 ;; Plug-in: candidates-file
10901 (defun anything-compile-source--candidates-file (source)
10902 (if (assoc-default 'candidates-file source)
10903 `((init anything-p-candidats-file-init
10904 ,@(let ((orig-init (assoc-default 'init source)))
10905 (cond ((null orig-init) nil)
10906 ((functionp orig-init) (list orig-init))
10907 (t orig-init))))
10908 (candidates-in-buffer)
10909 ,@source)
10910 source))
10911 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
10913 (defun anything-p-candidats-file-init ()
10914 (destructuring-bind (file &optional updating)
10915 (anything-mklist (anything-attr 'candidates-file))
10916 (setq file (anything-interpret-value file))
10917 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
10918 (when updating
10919 (buffer-disable-undo)
10920 (font-lock-mode -1)
10921 (auto-revert-mode 1)))))
10923 (anything-document-attribute 'candidates-file "candidates-file plugin"
10924 "Use a file as the candidates buffer.
10926 1st argument is a filename, string or function name or variable name.
10927 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
10929 ;; Plug-in: headline
10930 (defun anything-compile-source--anything-headline (source)
10931 (if (assoc-default 'headline source)
10932 (append '((init . anything-headline-init)
10933 (get-line . buffer-substring)
10934 (type . line))
10935 source
10936 '((candidates-in-buffer)
10937 (persistent-help . "Show this line")))
10938 source))
10939 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
10941 (defun anything-headline-init ()
10942 (when (and (anything-current-buffer-is-modified)
10943 (with-anything-current-buffer
10944 (eval (or (anything-attr 'condition) t))))
10945 (anything-headline-make-candidate-buffer
10946 (anything-interpret-value (anything-attr 'headline))
10947 (anything-interpret-value (anything-attr 'subexp)))))
10949 (anything-document-attribute 'headline "Headline plug-in"
10950 "Regexp string for anything-headline to scan.")
10951 (anything-document-attribute 'condition "Headline plug-in"
10952 "A sexp representing the condition to use anything-headline.")
10953 (anything-document-attribute 'subexp "Headline plug-in"
10954 "Display (match-string-no-properties subexp).")
10956 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
10957 ;; of regexps.
10959 ;; 1. Create list of ((title . start-of-match) . hiearchy)
10960 ;; 2. Sort this list by start-of-match.
10961 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
10963 ;; It's quite brilliantly written.
10967 (defun anything-headline-get-candidates (regexp subexp)
10968 (with-anything-current-buffer
10969 (save-excursion
10970 (goto-char (point-min))
10971 (if (functionp regexp) (setq regexp (funcall regexp)))
10972 (let (hierarchy curhead)
10973 (flet ((matched ()
10974 (if (numberp subexp)
10975 (cons (match-string-no-properties subexp) (match-beginning subexp))
10976 (cons (buffer-substring (point-at-bol) (point-at-eol))
10977 (point-at-bol))))
10978 (hierarchies (headlines)
10979 (1+ (loop for (_ . hierarchy) in headlines
10980 maximize hierarchy)))
10981 (vector-0-n (v n)
10982 (loop for i from 0 to hierarchy
10983 collecting (aref curhead i)))
10984 (arrange (headlines)
10985 (unless (null headlines) ; FIX headlines empty bug!
10986 (loop with curhead = (make-vector (hierarchies headlines) "")
10987 for ((str . pt) . hierarchy) in headlines
10988 do (aset curhead hierarchy str)
10989 collecting
10990 (cons
10991 (format "H%d:%s" (1+ hierarchy)
10992 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
10993 pt)))))
10994 (if (listp regexp)
10995 (arrange
10996 (sort
10997 (loop for re in regexp
10998 for hierarchy from 0
10999 do (goto-char (point-min))
11000 appending
11001 (loop
11002 while (re-search-forward re nil t)
11003 collect (cons (matched) hierarchy)))
11004 (lambda (a b) (> (cdar b) (cdar a)))))
11005 (loop while (re-search-forward regexp nil t)
11006 collect (matched))))))))
11009 (defun anything-headline-make-candidate-buffer (regexp subexp)
11010 (with-current-buffer (anything-candidate-buffer 'local)
11011 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11012 do (insert
11013 (format "%5d:%s\n"
11014 (with-anything-current-buffer
11015 (line-number-at-pos pos))
11016 content)))))
11018 (defun anything-headline-goto-position (pos recenter)
11019 (goto-char pos)
11020 (unless recenter
11021 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11024 ;; Plug-in: persistent-help
11025 (defun anything-compile-source--persistent-help (source)
11026 (append source '((header-line . anything-persistent-help-string))))
11027 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11029 (defun anything-persistent-help-string ()
11030 (substitute-command-keys
11031 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11032 (or (anything-interpret-value (anything-attr 'persistent-help))
11033 (anything-aif (or (assoc-default 'persistent-action
11034 (anything-get-current-source))
11035 (assoc-default 'action
11036 (anything-get-current-source)))
11037 (cond ((symbolp it) (symbol-name it))
11038 ((listp it) (or (ignore-errors (caar it)) ""))))
11040 " (keeping session)")))
11042 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11043 "A string to explain persistent-action of this source.
11044 It also accepts a function or a variable name.")
11046 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11048 ;; Plug-in: Type customize
11049 (defun anything-c-uniq-list (lst)
11050 "Like `remove-duplicates' in CL.
11051 But cut deeper duplicates and test by `equal'. "
11052 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11053 (defvar anything-additional-type-attributes nil)
11054 (defun anything-c-arrange-type-attribute (type spec)
11055 "Override type attributes by `define-anything-type-attribute'.
11057 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11059 Example: Set `play-sound-file' as default action
11060 (anything-c-arrange-type-attribute 'file
11061 '((action (\"Play sound\" . play-sound-file)
11062 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11065 (add-to-list 'anything-additional-type-attributes
11066 (cons type
11067 (loop with typeattr = (assoc-default type anything-type-attributes)
11068 for (attr . value) in spec
11069 if (listp value)
11070 collect (cons attr
11071 (anything-c-uniq-list
11072 (loop for v in value
11073 if (eq v 'REST)
11074 append (assoc-default attr typeattr)
11075 else
11076 collect v)))
11077 else
11078 collect (cons attr value)))))
11079 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11081 (defun anything-compile-source--type-customize (source)
11082 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11083 (append it source)
11084 source))
11085 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11087 ;; Plug-in: default-action
11088 (defun anything-compile-source--default-action (source)
11089 (anything-aif (assoc-default 'default-action source)
11090 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11091 source)
11092 source))
11093 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11094 (anything-document-attribute 'default-action "default-action plug-in"
11095 "Default action.")
11098 ;;; Toggle anything-match-plugin
11101 (defvar anything-mp-initial-highlight-delay nil)
11103 ;;;###autoload
11104 (defun anything-c-toggle-match-plugin ()
11105 "Toggle anything-match-plugin."
11106 (interactive)
11107 (let ((anything-match-plugin-enabled
11108 (member 'anything-compile-source--match-plugin
11109 anything-compile-source-functions)))
11110 (flet ((disable-match-plugin ()
11111 (setq anything-compile-source-functions
11112 (delq 'anything-compile-source--match-plugin
11113 anything-compile-source-functions))
11114 (setq anything-mp-initial-highlight-delay
11115 anything-mp-highlight-delay)
11116 (setq anything-mp-highlight-delay nil))
11117 (enable-match-plugin ()
11118 (require 'anything-match-plugin)
11119 (unless anything-mp-initial-highlight-delay
11120 (setq anything-mp-initial-highlight-delay
11121 anything-mp-highlight-delay))
11122 (setq anything-compile-source-functions
11123 (cons 'anything-compile-source--match-plugin
11124 anything-compile-source-functions))
11125 (unless anything-mp-highlight-delay
11126 (setq anything-mp-highlight-delay
11127 anything-mp-initial-highlight-delay))))
11128 (if anything-match-plugin-enabled
11129 (when (y-or-n-p "Really disable match-plugin? ")
11130 (disable-match-plugin)
11131 (message "Anything-match-plugin disabled"))
11132 (when (y-or-n-p "Really enable match-plugin? ")
11133 (enable-match-plugin)
11134 (message "Anything-match-plugin enabled"))))))
11138 ;;; Type Attributes
11141 (define-anything-type-attribute 'buffer
11142 `((action
11143 ("Switch to buffer" . anything-c-switch-to-buffer)
11144 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11145 ("Switch to buffer other window" . switch-to-buffer-other-window)
11146 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11147 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11148 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11149 ("Query replace" . anything-c-buffer-query-replace)
11150 ("View buffer" . view-buffer)
11151 ("Display buffer" . display-buffer)
11152 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11153 ("Revert buffer(s)" . anything-revert-marked-buffers)
11154 ("Insert buffer" . insert-buffer)
11155 ("Kill buffer(s)" . anything-kill-marked-buffers)
11156 ("Diff with file" . diff-buffer-with-file)
11157 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11158 ("Ediff Merge marked buffers" . (lambda (candidate)
11159 (anything-ediff-marked-buffers candidate t))))
11160 (persistent-help . "Show this buffer")
11161 (candidate-transformer anything-c-skip-current-buffer
11162 anything-c-skip-boring-buffers
11163 anything-c-transform-buffer-display-string))
11164 "Buffer or buffer name.")
11166 (define-anything-type-attribute 'file
11167 `((action
11168 ("Find file" . anything-find-many-files)
11169 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11170 ("Find file as root" . anything-find-file-as-root)
11171 ("Find file other window" . find-file-other-window)
11172 ("Find file other frame" . find-file-other-frame)
11173 ("Open dired in file's directory" . anything-c-open-dired)
11174 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11175 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11176 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11177 ("Checksum File" . anything-ff-checksum)
11178 ("Ediff File" . anything-find-files-ediff-files)
11179 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11180 ("View file" . view-file)
11181 ("Insert file" . insert-file)
11182 ("Delete file(s)" . anything-delete-marked-files)
11183 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11184 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11185 ("Find file in hex dump" . hexl-find-file))
11186 (persistent-help . "Show this file")
11187 (action-transformer anything-c-transform-file-load-el
11188 anything-c-transform-file-browse-url)
11189 (candidate-transformer anything-c-w32-pathname-transformer
11190 anything-c-skip-current-file
11191 anything-c-skip-boring-files
11192 anything-c-shorten-home-path))
11193 "File name.")
11195 (let ((actions '(("Describe command" . describe-function)
11196 ("Add command to kill ring" . anything-c-kill-new)
11197 ("Go to command's definition" . find-function)
11198 ("Debug on entry" . debug-on-entry)
11199 ("Cancel debug on entry" . cancel-debug-on-entry)
11200 ("Trace function" . trace-function)
11201 ("Trace function (background)" . trace-function-background)
11202 ("Untrace function" . untrace-function))))
11203 (define-anything-type-attribute 'command
11204 `((action ("Call interactively" . anything-c-call-interactively)
11205 ,@actions)
11206 ;; Sort commands according to their usage count.
11207 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11208 (coerce . anything-c-symbolify)
11209 (persistent-action . describe-function))
11210 "Command. (string or symbol)")
11212 (define-anything-type-attribute 'function
11213 `((action . ,actions)
11214 (action-transformer anything-c-transform-function-call-interactively)
11215 (candidate-transformer anything-c-mark-interactive-functions)
11216 (coerce . anything-c-symbolify))
11217 "Function. (string or symbol)"))
11219 (define-anything-type-attribute 'variable
11220 '((action ("Describe variable" . describe-variable)
11221 ("Add variable to kill ring" . anything-c-kill-new)
11222 ("Go to variable's definition" . find-variable)
11223 ("Set variable" . anything-c-set-variable))
11224 (coerce . anything-c-symbolify))
11225 "Variable.")
11227 (define-anything-type-attribute 'sexp
11228 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11229 ("Add s-expression to kill ring" . kill-new))
11230 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11231 "String representing S-Expressions.")
11233 (define-anything-type-attribute 'bookmark
11234 `((coerce . anything-bookmark-get-bookmark-from-name)
11235 (action
11236 ("Jump to bookmark" . (lambda (bookmark)
11237 (let ((current-prefix-arg anything-current-prefix-arg))
11238 (bookmark-jump bookmark))
11239 (anything-update)))
11240 ("Jump to BM other window" . (lambda (bookmark)
11241 (bookmark-jump-other-window bookmark)
11242 (anything-update)))
11243 ("Bookmark edit annotation" . bookmark-edit-annotation)
11244 ("Bookmark show annotation" . bookmark-show-annotation)
11245 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11246 ,@(and (locate-library "bookmark-extensions")
11247 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11248 ("Rename bookmark" . bookmark-rename)
11249 ("Relocate bookmark" . bookmark-relocate)))
11250 "Bookmark name.")
11252 (define-anything-type-attribute 'line
11253 '((display-to-real . anything-c-display-to-real-line)
11254 (action ("Go to Line" . anything-c-action-line-goto)))
11255 "LINENO:CONTENT string, eg. \" 16:foo\".
11257 Optional `target-file' attribute is a name of target file.
11259 Optional `before-jump-hook' attribute is a function with no
11260 arguments which is called before jumping to position.
11262 Optional `after-jump-hook' attribute is a function with no
11263 arguments which is called after jumping to position.
11265 If `adjust' attribute is specified, searches the line whose
11266 content is CONTENT near the LINENO.
11268 If `recenter' attribute is specified, the line is displayed at
11269 the center of window, otherwise at the top of window.
11272 (define-anything-type-attribute 'file-line
11273 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11274 (multiline)
11275 (action ("Go to" . anything-c-action-file-line-goto)))
11276 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11278 Optional `default-directory' attribute is a default-directory
11279 FILENAME is interpreted.
11281 Optional `before-jump-hook' attribute is a function with no
11282 arguments which is called before jumping to position.
11284 Optional `after-jump-hook' attribute is a function with no
11285 arguments which is called after jumping to position.
11287 If `adjust' attribute is specified, searches the line whose
11288 content is CONTENT near the LINENO.
11290 If `recenter' attribute is specified, the line is displayed at
11291 the center of window, otherwise at the top of window.
11294 (define-anything-type-attribute 'timer
11295 '((real-to-display . anything-c-timer-real-to-display)
11296 (action ("Cancel Timer" . cancel-timer)
11297 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11298 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11299 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11300 (persistent-help . "Describe Function"))
11301 "Timer.")
11304 ;;; Default `anything-sources'
11305 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11306 ;; tend to invoke M-x anything directly. So I offer default setting.
11307 (setq anything-sources
11308 '(anything-c-source-buffers-list
11309 anything-c-source-recentf
11310 anything-c-source-files-in-current-dir+))
11313 ;;; Preconfigured Anything
11316 ;;;###autoload
11317 (defun anything-mini ()
11318 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11319 (interactive)
11320 (anything-other-buffer '(anything-c-source-buffers-list
11321 anything-c-source-recentf
11322 anything-c-source-buffer-not-found)
11323 "*anything mini*"))
11324 ;;;###autoload
11325 (defun anything-for-files ()
11326 "Preconfigured `anything' for opening files.
11327 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11328 (interactive)
11329 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11331 ;;;###autoload
11332 (defun anything-recentf ()
11333 "Preconfigured `anything' for `recentf'."
11334 (interactive)
11335 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11337 ;;;###autoload
11338 (defun anything-info-at-point (arg)
11339 "Preconfigured `anything' for searching info at point.
11340 With a prefix-arg insert symbol at point."
11341 (interactive "P")
11342 (let ((anything-c-google-suggest-default-function
11343 'anything-c-google-suggest-emacs-lisp))
11344 (anything :sources '(anything-c-source-info-elisp
11345 anything-c-source-info-cl
11346 anything-c-source-info-pages
11347 anything-c-source-google-suggest)
11348 :input (and arg (thing-at-point 'symbol))
11349 :buffer "*anything info*")))
11351 ;;;###autoload
11352 (defun anything-info-emacs ()
11353 "Preconfigured anything for Emacs manual index."
11354 (interactive)
11355 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11357 ;;;###autoload
11358 (defun anything-show-kill-ring ()
11359 "Preconfigured `anything' for `kill-ring'.
11360 It is drop-in replacement of `yank-pop'.
11361 You may bind this command to M-y.
11362 First call open the kill-ring browser, next calls move to next line."
11363 (interactive)
11364 (let ((buf "*anything kill-ring*"))
11365 (if (get-buffer-window buf)
11366 (with-anything-window
11367 (if (eq (overlay-end anything-selection-overlay) (point-max))
11368 (anything-beginning-of-buffer)
11369 (anything-next-line)))
11370 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11372 ;;;###autoload
11373 (defun anything-minibuffer-history ()
11374 "Preconfigured `anything' for `minibuffer-history'."
11375 (interactive)
11376 (let ((enable-recursive-minibuffers t))
11377 (anything-other-buffer 'anything-c-source-minibuffer-history
11378 "*anything minibuffer-history*")))
11380 ;;;###autoload
11381 (defun anything-gentoo ()
11382 "Preconfigured `anything' for gentoo linux."
11383 (interactive)
11384 (anything-other-buffer '(anything-c-source-gentoo
11385 anything-c-source-use-flags)
11386 "*anything gentoo*"))
11388 ;;;###autoload
11389 (defun anything-imenu ()
11390 "Preconfigured `anything' for `imenu'."
11391 (interactive)
11392 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
11394 ;;;###autoload
11395 (defun anything-google-suggest ()
11396 "Preconfigured `anything' for google search with google suggest."
11397 (interactive)
11398 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11400 ;;;###autoload
11401 (defun anything-yahoo-suggest ()
11402 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11403 (interactive)
11404 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11406 ;;; Converted from anything-show-*-only
11407 ;;;###autoload
11408 (defun anything-for-buffers ()
11409 "Preconfigured `anything' for buffer."
11410 (interactive)
11411 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11413 ;;;###autoload
11414 (defun anything-buffers-list ()
11415 "Enhanced preconfigured `anything' for buffer."
11416 (interactive)
11417 (anything :sources '(anything-c-source-buffers-list
11418 anything-c-source-buffer-not-found)
11419 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11421 ;;;###autoload
11422 (defun anything-bbdb ()
11423 "Preconfigured `anything' for BBDB.
11425 Needs BBDB.
11427 http://bbdb.sourceforge.net/"
11428 (interactive)
11429 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11431 ;;;###autoload
11432 (defun anything-locate (arg)
11433 "Preconfigured `anything' for Locate.
11434 Note: you can add locate options after entering pattern.
11435 See 'man locate' for valid options.
11437 You can specify a specific database with prefix argument ARG \(C-u\).
11438 Many databases can be used: navigate and mark them.
11439 See also `anything-locate-with-db'.
11441 To create a user specific db, use
11442 \"updatedb -l 0 -o db_path -U directory\".
11443 Where db_path is a filename matched by
11444 `anything-locate-db-file-regexp'."
11445 (interactive "P")
11446 (anything-locate-1 arg))
11448 ;;;###autoload
11449 (defun anything-w3m-bookmarks ()
11450 "Preconfigured `anything' for w3m bookmark.
11452 Needs w3m and emacs-w3m.
11454 http://w3m.sourceforge.net/
11455 http://emacs-w3m.namazu.org/"
11456 (interactive)
11457 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11458 "*anything w3m bookmarks*"))
11460 ;;;###autoload
11461 (defun anything-firefox-bookmarks ()
11462 "Preconfigured `anything' for firefox bookmark.
11463 You will have to enable html bookmarks in firefox:
11464 open about:config in firefox and double click on this line to enable value \
11465 to true:
11467 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11469 You should have now:
11471 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11473 After closing firefox, you will be able to browse you bookmarks.
11475 (interactive)
11476 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11477 "*Anything Firefox*"))
11479 ;;;###autoload
11480 (defun anything-colors ()
11481 "Preconfigured `anything' for color."
11482 (interactive)
11483 (anything-other-buffer
11484 '(anything-c-source-colors anything-c-source-customize-face)
11485 "*anything colors*"))
11487 ;;;###autoload
11488 (defun anything-bookmarks ()
11489 "Preconfigured `anything' for bookmarks."
11490 (interactive)
11491 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11493 ;;;###autoload
11494 (defun anything-c-pp-bookmarks ()
11495 "Preconfigured `anything' for bookmarks (pretty-printed)."
11496 (interactive)
11497 (anything-other-buffer '(anything-c-source-bookmarks-local
11498 anything-c-source-bookmarks-su
11499 anything-c-source-bookmarks-ssh)
11500 "*anything pp bookmarks*"))
11502 ;;;###autoload
11503 (defun anything-c-insert-latex-math ()
11504 "Preconfigured anything for latex math symbols completion."
11505 (interactive)
11506 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11508 ;;;###autoload
11509 (defun anything-register ()
11510 "Preconfigured `anything' for Emacs registers."
11511 (interactive)
11512 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11514 ;;;###autoload
11515 (defun anything-man-woman ()
11516 "Preconfigured `anything' for Man and Woman pages."
11517 (interactive)
11518 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11520 ;;;###autoload
11521 (defun anything-org-keywords ()
11522 "Preconfigured `anything' for org keywords."
11523 (interactive)
11524 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11526 ;;;###autoload
11527 (defun anything-emms ()
11528 "Preconfigured `anything' for emms sources."
11529 (interactive)
11530 (anything '(anything-c-source-emms-streams
11531 anything-c-source-emms-files
11532 anything-c-source-emms-dired)
11533 nil nil nil nil
11534 "*Anything Emms*"))
11536 ;;;###autoload
11537 (defun anything-eev-anchors ()
11538 "Preconfigured `anything' for eev anchors."
11539 (interactive)
11540 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11542 ;;;###autoload
11543 (defun anything-bm-list ()
11544 "Preconfigured `anything' for visible bookmarks.
11546 Needs bm.el
11548 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11549 (interactive)
11550 (let ((anything-outline-using t))
11551 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11553 ;;;###autoload
11554 (defun anything-timers ()
11555 "Preconfigured `anything' for timers."
11556 (interactive)
11557 (anything-other-buffer '(anything-c-source-absolute-time-timers
11558 anything-c-source-idle-time-timers)
11559 "*anything timers*"))
11561 ;;;###autoload
11562 (defun anything-list-emacs-process ()
11563 "Preconfigured `anything' for emacs process."
11564 (interactive)
11565 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11567 ;;;###autoload
11568 (defun anything-occur ()
11569 "Preconfigured Anything for Occur source.
11570 If region is active, search only in region,
11571 otherwise search in whole buffer."
11572 (interactive)
11573 (let ((anything-compile-source-functions
11574 ;; rule out anything-match-plugin because the input is one regexp.
11575 (delq 'anything-compile-source--match-plugin
11576 (copy-sequence anything-compile-source-functions))))
11577 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11579 ;;;###autoload
11580 (defun anything-browse-code ()
11581 "Preconfigured anything to browse code."
11582 (interactive)
11583 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
11585 ;;;###autoload
11586 (defun anything-org-headlines ()
11587 "Preconfigured anything to show org headlines."
11588 (interactive)
11589 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11591 ;;;###autoload
11592 (defun anything-info-gnus ()
11593 "Preconfigured anything to browse Gnus Manual."
11594 (interactive)
11595 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11597 ;;;###autoload
11598 (defun anything-regexp ()
11599 "Preconfigured anything to build regexps and run query-replace-regexp \
11600 against."
11601 (interactive)
11602 (save-restriction
11603 (let ((anything-compile-source-functions
11604 ;; rule out anything-match-plugin because the input is one regexp.
11605 (delq 'anything-compile-source--match-plugin
11606 (copy-sequence anything-compile-source-functions))))
11607 (when (and (anything-region-active-p)
11608 ;; Don't narrow to region if buffer is already narrowed.
11609 (not (anything-current-buffer-narrowed-p)))
11610 (narrow-to-region (region-beginning) (region-end)))
11611 (anything :sources
11612 anything-c-source-regexp
11613 :buffer "*anything regexp*"
11614 :prompt "Regexp: "))))
11616 (defun anything-c-copy-files-async ()
11617 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11618 (interactive)
11619 (let* ((flist (anything-c-read-file-name
11620 "Copy File async: "
11621 :marked-candidates t))
11622 (dest (anything-c-read-file-name
11623 "Copy File async To: "
11624 :preselect (car flist)
11625 :initial-input (car anything-ff-history)
11626 :history (anything-find-files-history :comp-read nil))))
11627 (anything-c-copy-async-with-log flist dest)))
11629 ;;;###autoload
11630 (defun anything-find-files (arg)
11631 "Preconfigured `anything' for anything implementation of `find-file'.
11632 Called with a prefix arg show history if some.
11633 Don't call it from programs, use `anything-find-files-1' instead.
11634 This is the starting point for nearly all actions you can do on files."
11635 (interactive "P")
11636 (let ((any-input (if (and arg anything-ff-history)
11637 (anything-find-files-history)
11638 (anything-find-files-initial-input)))
11639 (presel (buffer-file-name (current-buffer))))
11640 (when (and (eq major-mode 'org-agenda-mode)
11641 org-directory
11642 (not any-input))
11643 (setq any-input (expand-file-name org-directory)))
11644 (set-text-properties 0 (length any-input) nil any-input)
11645 (if any-input
11646 (anything-find-files-1 any-input)
11647 (setq any-input (expand-file-name (anything-c-current-directory)))
11648 (anything-find-files-1
11649 any-input (if anything-ff-transformer-show-only-basename
11650 (and presel (anything-c-basename presel))
11651 presel)))))
11653 ;;;###autoload
11654 (defun anything-write-file ()
11655 "Preconfigured `anything' providing completion for `write-file'."
11656 (interactive)
11657 (let ((anything-mp-highlight-delay nil))
11658 (anything :sources 'anything-c-source-write-file
11659 :input (expand-file-name default-directory)
11660 :prompt "Write buffer to file: "
11661 :buffer "*Anything write file*")))
11663 ;;;###autoload
11664 (defun anything-insert-file ()
11665 "Preconfigured `anything' providing completion for `insert-file'."
11666 (interactive)
11667 (let ((anything-mp-highlight-delay nil))
11668 (anything :sources 'anything-c-source-insert-file
11669 :input (expand-file-name default-directory)
11670 :prompt "Insert file: "
11671 :buffer "*Anything insert file*")))
11673 ;;;###autoload
11674 (defun anything-dired-rename-file ()
11675 "Preconfigured `anything' to rename files from dired."
11676 (interactive)
11677 (anything-dired-do-action-on-file :action 'rename))
11679 ;;;###autoload
11680 (defun anything-dired-copy-file ()
11681 "Preconfigured `anything' to copy files from dired."
11682 (interactive)
11683 (anything-dired-do-action-on-file :action 'copy))
11685 ;;;###autoload
11686 (defun anything-dired-symlink-file ()
11687 "Preconfigured `anything' to symlink files from dired."
11688 (interactive)
11689 (anything-dired-do-action-on-file :action 'symlink))
11691 ;;;###autoload
11692 (defun anything-dired-hardlink-file ()
11693 "Preconfigured `anything' to hardlink files from dired."
11694 (interactive)
11695 (anything-dired-do-action-on-file :action 'hardlink))
11697 ;;;###autoload
11698 (defun anything-do-grep ()
11699 "Preconfigured anything for grep.
11700 Contrarily to Emacs `grep' no default directory is given, but
11701 the full path of candidates in ONLY.
11702 That allow to grep different files not only in `default-directory' but anywhere
11703 by marking them (C-<SPACE>). If one or more directory is selected
11704 grep will search in all files of these directories.
11705 You can use also wildcard in the base name of candidate.
11706 If a prefix arg is given use the -r option of grep.
11707 The prefix arg can be passed before or after start.
11708 See also `anything-do-grep-1'."
11709 (interactive)
11710 (let ((only (anything-c-read-file-name
11711 "Search in file(s): "
11712 :marked-candidates t
11713 :preselect (or (dired-get-filename nil t)
11714 (buffer-file-name (current-buffer)))))
11715 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11716 (anything-do-grep-1 only prefarg)))
11718 ;;;###autoload
11719 (defun anything-do-zgrep (candidate)
11720 "Preconfigured anything for zgrep."
11721 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11722 (ls (anything-c-read-file-name
11723 "Search in file(s): "
11724 :marked-candidates t
11725 :preselect (or (dired-get-filename nil t)
11726 (buffer-file-name (current-buffer))))))
11727 (anything-ff-zgrep-1 ls prefarg)))
11729 (defun anything-c-etags-select (arg)
11730 "Preconfigured anything for etags.
11731 Called with one prefix arg use symbol at point as initial input.
11732 Called with two prefix arg reinitialize cache.
11733 If tag file have been modified reinitialize cache."
11734 (interactive "P")
11735 (let ((tag (anything-c-etags-get-tag-file))
11736 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11737 (anything-quit-if-no-candidate t)
11738 (anything-execute-action-at-once-if-one t)
11739 (anything-compile-source-functions
11740 (if anything-c-etags-use-regexp-search
11741 ;; rule out anything-match-plugin because the input is one regexp.
11742 (delq 'anything-compile-source--match-plugin
11743 (copy-sequence anything-compile-source-functions))
11744 anything-compile-source-functions)))
11745 (when (or (equal arg '(16))
11746 (and anything-c-etags-mtime-alist
11747 (anything-c-etags-file-modified-p tag)))
11748 (remhash tag anything-c-etags-cache))
11749 (if (and tag (file-exists-p tag))
11750 (anything :sources 'anything-c-source-etags-select
11751 :keymap anything-c-etags-map
11752 :input init
11753 :buffer "*anything etags*")
11754 (message "Error: No tag file found, please create one with etags shell command."))))
11756 ;;;###autoload
11757 (defun anything-filelist ()
11758 "Preconfigured `anything' to open files instantly.
11760 See `anything-c-filelist-file-name' docstring for usage."
11761 (interactive)
11762 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11764 ;;;###autoload
11765 (defun anything-filelist+ ()
11766 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11768 This is a replacement for `anything-for-files'.
11769 See `anything-c-filelist-file-name' docstring for usage."
11770 (interactive)
11771 (anything-other-buffer
11772 '(anything-c-source-ffap-line
11773 anything-c-source-ffap-guesser
11774 anything-c-source-buffers-list
11775 anything-c-source-recentf
11776 anything-c-source-bookmarks
11777 anything-c-source-file-cache
11778 anything-c-source-filelist)
11779 "*anything file list*"))
11781 ;;;###autoload
11782 (defun anything-M-x ()
11783 "Preconfigured `anything' for Emacs commands.
11784 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11785 (interactive)
11786 (let* (in-help
11787 help-cand
11788 anything-persistent-action-use-special-display
11789 (history (loop with hist
11790 for i in extended-command-history
11791 for com = (intern i)
11792 when (fboundp com)
11793 collect i into hist finally return hist)))
11794 (flet ((pers-help (candidate)
11795 (let ((hbuf (get-buffer (help-buffer))))
11796 (if (and in-help (string= candidate help-cand))
11797 (progn
11798 ;; When M-x is started from a help buffer,
11799 ;; Don't kill it as it is anything-current-buffer.
11800 (unless (equal hbuf anything-current-buffer)
11801 (kill-buffer hbuf))
11802 (setq in-help nil))
11803 ;; Be sure anything-current-buffer
11804 ;; have not a dedicated window.
11805 (set-window-dedicated-p
11806 (get-buffer-window anything-current-buffer) nil)
11807 (describe-function (intern candidate))
11808 (message nil) ; Erase the new stupid message Type "q"[...]
11809 (setq in-help t))
11810 (setq help-cand candidate))))
11811 (let* ((command
11813 (anything
11814 :sources
11815 '(((name . "Emacs Commands history")
11816 (candidates . history)
11817 (filtered-candidate-transformer
11818 . (lambda (candidates sources)
11819 (loop for i in candidates
11820 do (set-text-properties 0 (length i) nil i)
11821 collect i)))
11822 (persistent-action . pers-help)
11823 (persistent-help . "Describe this command")
11824 (action . identity))
11825 ((name . "Emacs Commands")
11826 (init
11827 . (lambda ()
11828 (with-current-buffer (anything-candidate-buffer 'global)
11829 (goto-char (point-min))
11830 (loop
11831 for sym in (all-completions "" obarray 'commandp)
11832 do (insert (concat sym "\n"))))))
11833 (persistent-action . pers-help)
11834 (persistent-help . "Describe this command")
11835 (filtered-candidate-transformer . anything-M-x-transformer)
11836 (candidates-in-buffer)
11837 (action . identity)))
11838 :buffer "*anything M-x*")
11839 (keyboard-quit)))
11840 (sym-com (intern command)))
11841 (unless current-prefix-arg
11842 (setq current-prefix-arg anything-current-prefix-arg))
11843 ;; Avoid having `this-command' set to *exit-minibuffer.
11844 (setq this-command sym-com)
11845 (call-interactively sym-com)
11846 (setq extended-command-history
11847 (cons command (delete command history)))))))
11849 ;;;###autoload
11850 (defun anything-manage-advice ()
11851 "Preconfigured `anything' to disable/enable function advices."
11852 (interactive)
11853 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
11855 ;;;###autoload
11856 (defun anything-bookmark-ext ()
11857 "Preconfigured `anything' for bookmark-extensions sources.
11858 Needs bookmark-ext.el:
11859 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11860 Contain also `anything-c-source-google-suggest'."
11861 (interactive)
11862 (anything
11863 :sources
11864 '(anything-c-source-bookmark-files&dirs
11865 anything-c-source-bookmark-w3m
11866 anything-c-source-google-suggest
11867 anything-c-source-bmkext-addressbook
11868 anything-c-source-bookmark-gnus
11869 anything-c-source-bookmark-info
11870 anything-c-source-bookmark-man
11871 anything-c-source-bookmark-images
11872 anything-c-source-bookmark-su-files&dirs
11873 anything-c-source-bookmark-ssh-files&dirs)
11874 :prompt "SearchBookmark: "
11875 :buffer "*anything bmkext*"))
11877 ;;;###autoload
11878 (defun anything-simple-call-tree ()
11879 "Preconfigured `anything' for simple-call-tree. List function relationships.
11881 Needs simple-call-tree.el.
11882 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11883 (interactive)
11884 (anything-other-buffer
11885 '(anything-c-source-simple-call-tree-functions-callers
11886 anything-c-source-simple-call-tree-callers-functions)
11887 "*anything simple-call-tree*"))
11889 ;;;###autoload
11890 (defun anything-mark-ring ()
11891 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11892 (interactive)
11893 (anything 'anything-c-source-mark-ring))
11895 ;;;###autoload
11896 (defun anything-global-mark-ring ()
11897 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
11898 (interactive)
11899 (anything 'anything-c-source-global-mark-ring))
11901 ;;;###autoload
11902 (defun anything-all-mark-rings ()
11903 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
11904 `anything-c-source-mark-ring'."
11905 (interactive)
11906 (anything '(anything-c-source-mark-ring
11907 anything-c-source-global-mark-ring)))
11909 ;;;###autoload
11910 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
11911 "Preconfigured `anything' to edit or view EmacsWiki page.
11913 Needs yaoddmuse.el.
11915 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11916 (interactive)
11917 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
11919 ;;;###autoload
11920 (defun anything-yaoddmuse-emacswiki-post-library ()
11921 "Preconfigured `anything' to post library to EmacsWiki.
11923 Needs yaoddmuse.el.
11925 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11926 (interactive)
11927 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
11929 ;;;###autoload
11930 (defun anything-eval-expression (arg)
11931 "Preconfigured anything for `anything-c-source-evaluation-result'."
11932 (interactive "P")
11933 (anything :sources 'anything-c-source-evaluation-result
11934 :input (when arg (thing-at-point 'sexp))
11935 :buffer "*anything eval*"
11936 :keymap anything-eval-expression-map))
11938 ;;;###autoload
11939 (defun anything-eval-expression-with-eldoc ()
11940 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
11941 (interactive)
11942 (declare (special eldoc-idle-delay))
11943 (let ((timer (run-with-idle-timer eldoc-idle-delay
11944 'repeat 'anything-eldoc-show-in-eval))
11945 (minibuffer-completing-symbol t) ; Enable lisp completion.
11946 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
11947 (unwind-protect
11948 (minibuffer-with-setup-hook
11949 'anything-eldoc-store-minibuffer
11950 (call-interactively 'anything-eval-expression))
11951 (and timer (cancel-timer timer))
11952 (setq anything-eldoc-active-minibuffers-list
11953 (cdr anything-eldoc-active-minibuffers-list)))))
11955 ;;;###autoload
11956 (defun anything-calcul-expression ()
11957 "Preconfigured anything for `anything-c-source-calculation-result'."
11958 (interactive)
11959 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
11961 ;;;###autoload
11962 (defun anything-surfraw (pattern engine)
11963 "Preconfigured `anything' to search PATTERN with search ENGINE."
11964 (interactive (list (read-string "SearchFor: ")
11965 (anything-comp-read
11966 "Engine: "
11967 (anything-c-build-elvi-list)
11968 :must-match t
11969 :name "Surfraw Search Engines"
11970 :history anything-surfraw-engines-history)))
11971 (let* ((engine-nodesc (car (split-string engine)))
11972 (url (with-temp-buffer
11973 (apply 'call-process "surfraw" nil t nil
11974 ;;JAVE
11975 (append (list engine-nodesc "-p") (split-string pattern)))
11976 (replace-regexp-in-string
11977 "\n" "" (buffer-string))))
11978 (browse-url-browser-function (or anything-surfraw-default-browser-function
11979 browse-url-browser-function)))
11980 (if (string= engine-nodesc "W")
11981 (anything-c-browse-url)
11982 (anything-c-browse-url url)
11983 (setq anything-surfraw-engines-history
11984 (cons engine (delete engine anything-surfraw-engines-history))))))
11986 ;;;###autoload
11987 (defun anything-call-source ()
11988 "Preconfigured `anything' to call anything source."
11989 (interactive)
11990 (anything 'anything-c-source-call-source nil nil nil nil
11991 anything-source-select-buffer))
11993 ;;;###autoload
11994 (defun anything-execute-anything-command ()
11995 "Preconfigured `anything' to execute preconfigured `anything'."
11996 (interactive)
11997 (anything-other-buffer 'anything-c-source-anything-commands
11998 "*anything commands*"))
12000 ;;;###autoload
12001 (defun anything-create (&optional string initial-input)
12002 "Preconfigured `anything' to do many create actions from STRING.
12003 See also `anything-create--actions'."
12004 (interactive)
12005 (setq string (or string (read-string "Create Anything: " initial-input)))
12006 (anything '(((name . "Anything Create")
12007 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12008 (candidates . anything-create--actions)
12009 (candidate-number-limit)
12010 (action . (lambda (func) (funcall func string)))))))
12012 ;;;###autoload
12013 (defun anything-top ()
12014 "Preconfigured `anything' for top command."
12015 (interactive)
12016 (let ((anything-samewindow t)
12017 (anything-enable-shortcuts)
12018 (anything-display-function 'anything-default-display-buffer)
12019 (anything-candidate-number-limit 9999))
12020 (save-window-excursion
12021 (delete-other-windows)
12022 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12024 ;;;###autoload
12025 (defun anything-select-xfont ()
12026 "Preconfigured `anything' to select Xfont."
12027 (interactive)
12028 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12030 ;;;###autoload
12031 (defun anything-world-time ()
12032 "Preconfigured `anything' to show world time."
12033 (interactive)
12034 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12036 ;;;###autoload
12037 (defun anything-apt (arg query)
12038 "Preconfigured `anything' : frontend of APT package manager.
12039 With a prefix arg reload cache."
12040 (interactive "P\nsSearch Package: ")
12041 (when arg
12042 (setq anything-c-apt-installed-packages nil)
12043 (setq anything-c-apt-all-packages nil))
12044 (anything :sources 'anything-c-source-apt
12045 :prompt "Search Package: " :input query))
12047 ;;;###autoload
12048 (defun anything-esh-pcomplete ()
12049 "Preconfigured anything to provide anything completion in eshell."
12050 (interactive)
12051 (let* ((anything-quit-if-no-candidate t)
12052 (anything-execute-action-at-once-if-one t)
12053 (target (thing-at-point 'symbol))
12054 (end (point))
12055 (beg (or (and target (- end (length target)))
12056 ;; Nothing at point.
12057 (progn (insert " ") (point)))))
12058 (setq anything-ec-target (or target " "))
12059 (with-anything-show-completion beg end
12060 (anything :sources 'anything-c-source-esh
12061 :input (anything-ff-set-pattern ; Handle tramp filenames.
12062 (car (last (ignore-errors ; Needed in lisp symbols completion.
12063 (pcomplete-parse-arguments)))))))))
12065 ;;;###autoload
12066 (defun anything-eshell-history ()
12067 "Preconfigured anything for eshell history."
12068 (interactive)
12069 (let* ((end (point))
12070 (beg (save-excursion (eshell-bol) (point)))
12071 flag-empty)
12072 (when (eq beg end)
12073 (insert " ")
12074 (setq flag-empty t)
12075 (setq end (point)))
12076 (unwind-protect
12077 (with-anything-show-completion beg end
12078 (anything :sources 'anything-c-source-eshell-history
12079 :buffer "*Eshell history*"))
12080 (when (and flag-empty
12081 (looking-back " "))
12082 (delete-char -1)))))
12084 ;;;###autoload
12085 (defun anything-c-run-external-command (program)
12086 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12087 If program is already running exit with error.
12088 You can set your own list of commands with
12089 `anything-c-external-commands-list'."
12090 (interactive (list
12091 (anything-comp-read
12092 "RunProgram: "
12093 (anything-c-external-commands-list-1 'sort)
12094 :must-match t
12095 :name "External Commands"
12096 :history anything-external-command-history)))
12097 (anything-run-or-raise program)
12098 (setq anything-external-command-history
12099 (cons program (delete program
12100 (loop for i in anything-external-command-history
12101 when (executable-find i) collect i)))))
12103 ;;;###autoload
12104 (defun anything-ratpoison-commands ()
12105 "Preconfigured `anything' to execute ratpoison commands."
12106 (interactive)
12107 (anything-other-buffer 'anything-c-source-ratpoison-commands
12108 "*anything ratpoison commands*"))
12110 ;;;###autoload
12111 (defun anything-ucs ()
12112 "Preconfigured anything for `ucs-names' math symbols."
12113 (interactive)
12114 (anything :sources 'anything-c-source-ucs
12115 :keymap anything-c-ucs-map))
12117 ;;;###autoload
12118 (defun anything-c-apropos ()
12119 "Preconfigured anything to describe commands, functions, variables and faces."
12120 (interactive)
12121 (let ((default (thing-at-point 'symbol)))
12122 (anything :sources
12123 `(((name . "Commands")
12124 (init . (lambda ()
12125 (anything-c-apropos-init 'commandp ,default)))
12126 (persistent-action . anything-lisp-completion-persistent-action)
12127 (persistent-help . "Show brief doc in mode-line")
12128 (candidates-in-buffer)
12129 (action . (lambda (candidate)
12130 (describe-function (intern candidate)))))
12131 ((name . "Functions")
12132 (init . (lambda ()
12133 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12134 (not (commandp x))))
12135 ,default)))
12136 (persistent-action . anything-lisp-completion-persistent-action)
12137 (persistent-help . "Show brief doc in mode-line")
12138 (candidates-in-buffer)
12139 (action . (lambda (candidate)
12140 (describe-function (intern candidate)))))
12141 ((name . "Variables")
12142 (init . (lambda ()
12143 (anything-c-apropos-init 'boundp ,default)))
12144 (persistent-action . anything-lisp-completion-persistent-action)
12145 (persistent-help . "Show brief doc in mode-line")
12146 (candidates-in-buffer)
12147 (action . (lambda (candidate)
12148 (describe-variable (intern candidate)))))
12149 ((name . "Faces")
12150 (init . (lambda ()
12151 (anything-c-apropos-init 'facep ,default)))
12152 (persistent-action . anything-lisp-completion-persistent-action)
12153 (persistent-help . "Show brief doc in mode-line")
12154 (candidates-in-buffer)
12155 (filtered-candidate-transformer . (lambda (candidates source)
12156 (loop for c in candidates
12157 collect (propertize c 'face (intern c)))))
12158 (action . (lambda (candidate)
12159 (describe-face (intern candidate)))))
12160 ((name . "Anything attributes")
12161 (candidates . (lambda ()
12162 (mapcar 'symbol-name anything-additional-attributes)))
12163 (action . (lambda (candidate)
12164 (with-output-to-temp-buffer "*Help*"
12165 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12168 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12171 (provide 'anything-config)
12173 ;;; Local Variables:
12174 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12175 ;;; End:
12177 ;; How to save (DO NOT REMOVE!!)
12178 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12179 ;;; anything-config.el ends here
12181 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12182 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12183 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12184 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12185 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12186 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12187 ;;; LocalWords: dotimes Thierry online vname
12188 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12189 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12190 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12191 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12192 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12193 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12194 ;;; LocalWords: startpos noselect dont desc