* anything-config.el Fast deletion of files in anything-find-files.
[anything-config.git] / anything-config.el
blobbc78bd61e42329348bed51a4bcb725c42439412d
1 ;;; anything-config.el --- Applications libary for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Applications libary for `anything.el'
7 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
9 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
10 ;; rubikitch <rubikitch@ruby-lang.org>
11 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
12 ;; Copyright (C) 2007 ~ 2011, Tassilo Horn, all rights reserved.
13 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
14 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
15 ;; Copyright (C) 2009 ~ 2011, Thierry Volpiatto, all rights reserved.
17 ;; Created: 2009-02-16 21:38:23
19 ;; X-URL: http://repo.or.cz/w/anything-config.git
21 ;; MailingList: https://groups.google.com/group/emacs-anything?hl=en
23 ;; Keywords: anything, anything-config
25 ;; Compatibility: GNU Emacs 22 ~ 24
27 ;; Dependencies: `anything.el'
29 ;;; This file is NOT part of GNU Emacs
31 ;;; License
33 ;; This program is free software; you can redistribute it and/or modify
34 ;; it under the terms of the GNU General Public License as published by
35 ;; the Free Software Foundation; either version 3, or (at your option)
36 ;; any later version.
38 ;; This program is distributed in the hope that it will be useful,
39 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
40 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 ;; GNU General Public License for more details.
43 ;; You should have received a copy of the GNU General Public License
44 ;; along with this program; see the file COPYING. If not, write to
45 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
46 ;; Floor, Boston, MA 02110-1301, USA.
48 ;;; !NOTICE!
50 ;; If this file does not work, upgrade anything.el!
51 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
53 ;;; Commentary:
55 ;; Predefined configurations for `anything.el'
57 ;; For quick start, try `anything-for-files' to open files.
59 ;; To configure anything you should define anything command
60 ;; with your favorite sources, like below:
62 ;; (defun my-anything ()
63 ;; (interactive)
64 ;; (anything-other-buffer
65 ;; '(anything-c-source-buffers
66 ;; anything-c-source-file-name-history
67 ;; anything-c-source-info-pages
68 ;; anything-c-source-info-elisp
69 ;; anything-c-source-man-pages
70 ;; anything-c-source-locate
71 ;; anything-c-source-emacs-commands)
72 ;; " *my-anything*"))
74 ;; Then type M-x my-anything to use sources.
76 ;; Defining own command is better than setup `anything-sources'
77 ;; directly, because you can define multiple anything commands with
78 ;; different sources. Each anything command should have own anything
79 ;; buffer, because M-x anything-resume revives anything command.
82 ;;; Autodoc documentation:
83 ;; ---------------------
85 ;; * Commands defined here are:
86 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
87 ;; `anything-configuration'
88 ;; Customize `anything'.
89 ;; `anything-c-buffer-help'
90 ;; Help command for anything buffers.
91 ;; `anything-ff-help'
92 ;; Help command for `anything-find-files'.
93 ;; `anything-read-file-name-help'
94 ;; Not documented.
95 ;; `anything-generic-file-help'
96 ;; Not documented.
97 ;; `anything-grep-help'
98 ;; Not documented.
99 ;; `anything-pdfgrep-help'
100 ;; Not documented.
101 ;; `anything-etags-help'
102 ;; The help function for etags.
103 ;; `anything-c-ucs-help'
104 ;; Help command for `anything-ucs'.
105 ;; `anything-show-this-source-only'
106 ;; Show all candidates of this source.
107 ;; `anything-test-sources'
108 ;; List all anything sources for test.
109 ;; `anything-select-source'
110 ;; [OBSOLETE] Select source.
111 ;; `anything-quit-and-find-file'
112 ;; Drop into `anything-find-files' from `anything'.
113 ;; `anything-mark-all'
114 ;; Mark all visible unmarked candidates in current source.
115 ;; `anything-unmark-all'
116 ;; Unmark all candidates in all sources of current anything session.
117 ;; `anything-toggle-all-marks'
118 ;; Toggle all marks.
119 ;; `anything-buffer-diff-persistent'
120 ;; Toggle diff buffer without quitting anything.
121 ;; `anything-buffer-revert-persistent'
122 ;; Revert buffer without quitting anything.
123 ;; `anything-buffer-save-persistent'
124 ;; Save buffer without quitting anything.
125 ;; `anything-buffer-run-kill-buffers'
126 ;; Run kill buffer action from `anything-c-source-buffers-list'.
127 ;; `anything-buffer-run-grep'
128 ;; Run Grep action from `anything-c-source-buffers-list'.
129 ;; `anything-buffer-run-zgrep'
130 ;; Run Grep action from `anything-c-source-buffers-list'.
131 ;; `anything-buffer-run-query-replace-regexp'
132 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
133 ;; `anything-buffer-run-query-replace'
134 ;; Run Query replace action from `anything-c-source-buffers-list'.
135 ;; `anything-buffer-switch-other-window'
136 ;; Run switch to other window action from `anything-c-source-buffers-list'.
137 ;; `anything-buffer-switch-other-frame'
138 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
139 ;; `anything-buffer-switch-to-elscreen'
140 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
141 ;; `anything-buffer-run-ediff'
142 ;; Run ediff action from `anything-c-source-buffers-list'.
143 ;; `anything-buffer-run-ediff-merge'
144 ;; Run ediff action from `anything-c-source-buffers-list'.
145 ;; `anything-ff-run-toggle-auto-update'
146 ;; Not documented.
147 ;; `anything-ff-run-switch-to-history'
148 ;; Run Switch to history action from `anything-c-source-find-files'.
149 ;; `anything-ff-run-grep'
150 ;; Run Grep action from `anything-c-source-find-files'.
151 ;; `anything-ff-run-pdfgrep'
152 ;; Run Pdfgrep action from `anything-c-source-find-files'.
153 ;; `anything-ff-run-zgrep'
154 ;; Run Grep action from `anything-c-source-find-files'.
155 ;; `anything-ff-run-copy-file'
156 ;; Run Copy file action from `anything-c-source-find-files'.
157 ;; `anything-ff-run-rename-file'
158 ;; Run Rename file action from `anything-c-source-find-files'.
159 ;; `anything-ff-run-byte-compile-file'
160 ;; Run Byte compile file action from `anything-c-source-find-files'.
161 ;; `anything-ff-run-load-file'
162 ;; Run Load file action from `anything-c-source-find-files'.
163 ;; `anything-ff-run-eshell-command-on-file'
164 ;; Run eshell command on file action from `anything-c-source-find-files'.
165 ;; `anything-ff-run-ediff-file'
166 ;; Run Ediff file action from `anything-c-source-find-files'.
167 ;; `anything-ff-run-ediff-merge-file'
168 ;; Run Ediff merge file action from `anything-c-source-find-files'.
169 ;; `anything-ff-run-symlink-file'
170 ;; Run Symlink file action from `anything-c-source-find-files'.
171 ;; `anything-ff-run-delete-file'
172 ;; Run Delete file action from `anything-c-source-find-files'.
173 ;; `anything-ff-run-complete-fn-at-point'
174 ;; Run complete file name action from `anything-c-source-find-files'.
175 ;; `anything-ff-run-switch-to-eshell'
176 ;; Run switch to eshell action from `anything-c-source-find-files'.
177 ;; `anything-ff-run-switch-other-window'
178 ;; Run switch to other window action from `anything-c-source-find-files'.
179 ;; `anything-ff-run-switch-other-frame'
180 ;; Run switch to other frame action from `anything-c-source-find-files'.
181 ;; `anything-ff-run-open-file-externally'
182 ;; Run open file externally command action from `anything-c-source-find-files'.
183 ;; `anything-ff-run-locate'
184 ;; Run locate action from `anything-c-source-find-files'.
185 ;; `anything-ff-run-gnus-attach-files'
186 ;; Run gnus attach files command action from `anything-c-source-find-files'.
187 ;; `anything-ff-run-etags'
188 ;; Run Etags command action from `anything-c-source-find-files'.
189 ;; `anything-ff-run-print-file'
190 ;; Run Print file action from `anything-c-source-find-files'.
191 ;; `anything-ff-run-toggle-basename'
192 ;; Not documented.
193 ;; `anything-find-files-down-one-level'
194 ;; Go down one level like unix command `cd ..'.
195 ;; `anything-ff-properties-persistent'
196 ;; Show properties without quitting anything.
197 ;; `anything-ff-run-kill-buffer-persistent'
198 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
199 ;; `anything-ff-rotate-left-persistent'
200 ;; Rotate image left without quitting anything.
201 ;; `anything-ff-rotate-right-persistent'
202 ;; Rotate image right without quitting anything.
203 ;; `anything-c-goto-precedent-file'
204 ;; Go to precedent file in anything grep/etags buffers.
205 ;; `anything-c-goto-next-file'
206 ;; Go to precedent file in anything grep/etags buffers.
207 ;; `anything-c-grep-run-persistent-action'
208 ;; Run grep persistent action from `anything-do-grep-1'.
209 ;; `anything-c-grep-run-default-action'
210 ;; Run grep default action from `anything-do-grep-1'.
211 ;; `anything-c-grep-run-other-window-action'
212 ;; Run grep goto other window action from `anything-do-grep-1'.
213 ;; `anything-c-grep-run-save-buffer'
214 ;; Run grep save results action from `anything-do-grep-1'.
215 ;; `anything-do-pdfgrep'
216 ;; Not documented.
217 ;; `anything-yank-text-at-point'
218 ;; Yank text at point in minibuffer.
219 ;; `anything-c-describe-attributes'
220 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
221 ;; `anything-yaoddmuse-cache-pages'
222 ;; Fetch the list of files on emacswiki and create cache file.
223 ;; `anything-eval-new-line-and-indent'
224 ;; Not documented.
225 ;; `anything-call-source-from-anything'
226 ;; Call anything source within `anything' session.
227 ;; `anything-create-from-anything'
228 ;; Run `anything-create' from `anything' as a fallback.
229 ;; `anything-c-ucs-persistent-insert'
230 ;; Not documented.
231 ;; `anything-c-ucs-persistent-forward'
232 ;; Not documented.
233 ;; `anything-c-ucs-persistent-backward'
234 ;; Not documented.
235 ;; `anything-c-ucs-persistent-delete'
236 ;; Not documented.
237 ;; `anything-lisp-completion-at-point'
238 ;; Anything lisp symbol completion at point.
239 ;; `anything-c-complete-file-name-at-point'
240 ;; Complete file name at point.
241 ;; `anything-lisp-completion-at-point-or-indent'
242 ;; First call indent and second call complete lisp symbol.
243 ;; `anything-lisp-completion-or-file-name-at-point'
244 ;; Complete lisp symbol or filename at point.
245 ;; `anything-c-set-variable'
246 ;; Set value to VAR interactively.
247 ;; `anything-c-adaptive-save-history'
248 ;; Save history information to file given by `anything-c-adaptive-history-file'.
249 ;; `anything-c-reset-adaptative-history'
250 ;; Delete all `anything-c-adaptive-history' and his file.
251 ;; `anything-c-toggle-match-plugin'
252 ;; Toggle anything-match-plugin.
253 ;; `anything-mini'
254 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
255 ;; `anything-for-files'
256 ;; Preconfigured `anything' for opening files.
257 ;; `anything-recentf'
258 ;; Preconfigured `anything' for `recentf'.
259 ;; `anything-info-at-point'
260 ;; Preconfigured `anything' for searching info at point.
261 ;; `anything-info-emacs'
262 ;; Preconfigured anything for Emacs manual index.
263 ;; `anything-show-kill-ring'
264 ;; Preconfigured `anything' for `kill-ring'.
265 ;; `anything-minibuffer-history'
266 ;; Preconfigured `anything' for `minibuffer-history'.
267 ;; `anything-gentoo'
268 ;; Preconfigured `anything' for gentoo linux.
269 ;; `anything-imenu'
270 ;; Preconfigured `anything' for `imenu'.
271 ;; `anything-google-suggest'
272 ;; Preconfigured `anything' for google search with google suggest.
273 ;; `anything-yahoo-suggest'
274 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
275 ;; `anything-for-buffers'
276 ;; Preconfigured `anything' for buffer.
277 ;; `anything-buffers-list'
278 ;; Enhanced preconfigured `anything' for buffer.
279 ;; `anything-bbdb'
280 ;; Preconfigured `anything' for BBDB.
281 ;; `anything-locate'
282 ;; Preconfigured `anything' for Locate.
283 ;; `anything-w3m-bookmarks'
284 ;; Preconfigured `anything' for w3m bookmark.
285 ;; `anything-firefox-bookmarks'
286 ;; Preconfigured `anything' for firefox bookmark.
287 ;; `anything-colors'
288 ;; Preconfigured `anything' for color.
289 ;; `anything-bookmarks'
290 ;; Preconfigured `anything' for bookmarks.
291 ;; `anything-c-pp-bookmarks'
292 ;; Preconfigured `anything' for bookmarks (pretty-printed).
293 ;; `anything-c-insert-latex-math'
294 ;; Preconfigured anything for latex math symbols completion.
295 ;; `anything-register'
296 ;; Preconfigured `anything' for Emacs registers.
297 ;; `anything-man-woman'
298 ;; Preconfigured `anything' for Man and Woman pages.
299 ;; `anything-org-keywords'
300 ;; Preconfigured `anything' for org keywords.
301 ;; `anything-emms'
302 ;; Preconfigured `anything' for emms sources.
303 ;; `anything-eev-anchors'
304 ;; Preconfigured `anything' for eev anchors.
305 ;; `anything-bm-list'
306 ;; Preconfigured `anything' for visible bookmarks.
307 ;; `anything-timers'
308 ;; Preconfigured `anything' for timers.
309 ;; `anything-list-emacs-process'
310 ;; Preconfigured `anything' for emacs process.
311 ;; `anything-occur'
312 ;; Preconfigured Anything for Occur source.
313 ;; `anything-browse-code'
314 ;; Preconfigured anything to browse code.
315 ;; `anything-org-headlines'
316 ;; Preconfigured anything to show org headlines.
317 ;; `anything-info-gnus'
318 ;; Preconfigured anything to browse Gnus Manual.
319 ;; `anything-regexp'
320 ;; Preconfigured anything to build regexps.
321 ;; `anything-c-copy-files-async'
322 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
323 ;; `anything-find-files'
324 ;; Preconfigured `anything' for anything implementation of `find-file'.
325 ;; `anything-write-file'
326 ;; Preconfigured `anything' providing completion for `write-file'.
327 ;; `anything-insert-file'
328 ;; Preconfigured `anything' providing completion for `insert-file'.
329 ;; `anything-dired-rename-file'
330 ;; Preconfigured `anything' to rename files from dired.
331 ;; `anything-dired-copy-file'
332 ;; Preconfigured `anything' to copy files from dired.
333 ;; `anything-dired-symlink-file'
334 ;; Preconfigured `anything' to symlink files from dired.
335 ;; `anything-dired-hardlink-file'
336 ;; Preconfigured `anything' to hardlink files from dired.
337 ;; `anything-do-grep'
338 ;; Preconfigured anything for grep.
339 ;; `anything-c-etags-select'
340 ;; Preconfigured anything for etags.
341 ;; `anything-filelist'
342 ;; Preconfigured `anything' to open files instantly.
343 ;; `anything-filelist+'
344 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
345 ;; `anything-M-x'
346 ;; Preconfigured `anything' for Emacs commands.
347 ;; `anything-manage-advice'
348 ;; Preconfigured `anything' to disable/enable function advices.
349 ;; `anything-bookmark-ext'
350 ;; Preconfigured `anything' for bookmark-extensions sources.
351 ;; `anything-simple-call-tree'
352 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
353 ;; `anything-mark-ring'
354 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
355 ;; `anything-global-mark-ring'
356 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
357 ;; `anything-all-mark-rings'
358 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
359 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
360 ;; Preconfigured `anything' to edit or view EmacsWiki page.
361 ;; `anything-yaoddmuse-emacswiki-post-library'
362 ;; Preconfigured `anything' to post library to EmacsWiki.
363 ;; `anything-eval-expression'
364 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
365 ;; `anything-eval-expression-with-eldoc'
366 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
367 ;; `anything-calcul-expression'
368 ;; Preconfigured anything for `anything-c-source-calculation-result'.
369 ;; `anything-surfraw'
370 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
371 ;; `anything-call-source'
372 ;; Preconfigured `anything' to call anything source.
373 ;; `anything-execute-anything-command'
374 ;; Preconfigured `anything' to execute preconfigured `anything'.
375 ;; `anything-create'
376 ;; Preconfigured `anything' to do many create actions from STRING.
377 ;; `anything-top'
378 ;; Preconfigured `anything' for top command.
379 ;; `anything-select-xfont'
380 ;; Preconfigured `anything' to select Xfont.
381 ;; `anything-world-time'
382 ;; Preconfigured `anything' to show world time.
383 ;; `anything-apt'
384 ;; Preconfigured `anything' : frontend of APT package manager.
385 ;; `anything-esh-pcomplete'
386 ;; Preconfigured anything to provide anything completion in eshell.
387 ;; `anything-eshell-history'
388 ;; Preconfigured anything for eshell history.
389 ;; `anything-c-run-external-command'
390 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
391 ;; `anything-ratpoison-commands'
392 ;; Preconfigured `anything' to execute ratpoison commands.
393 ;; `anything-ucs'
394 ;; Preconfigured anything for `ucs-names' math symbols.
395 ;; `anything-c-apropos'
396 ;; Preconfigured anything to describe commands, functions, variables and faces.
398 ;; * User variables defined here:
399 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
400 ;; `anything-c-adaptive-history-file'
401 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
402 ;; `anything-c-adaptive-history-length'
403 ;; Default Value: 50
404 ;; `anything-c-google-suggest-url'
405 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
406 ;; `anything-c-google-suggest-search-url'
407 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
408 ;; `anything-google-suggest-use-curl-p'
409 ;; Default Value: nil
410 ;; `anything-c-yahoo-suggest-url'
411 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
412 ;; `anything-c-yahoo-suggest-search-url'
413 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
414 ;; `anything-c-boring-buffer-regexp'
415 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\|\\*ac-mode\\| \\*Echo Area\\| \\*Minibuf"
416 ;; `anything-c-boring-file-regexp'
417 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
418 ;; `anything-kill-ring-threshold'
419 ;; Default Value: 10
420 ;; `anything-c-kill-ring-max-lines-number'
421 ;; Default Value: nil
422 ;; `anything-su-or-sudo'
423 ;; Default Value: "su"
424 ;; `anything-for-files-prefered-list'
425 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
426 ;; `anything-create--actions-private'
427 ;; Default Value: nil
428 ;; `anything-allow-skipping-current-buffer'
429 ;; Default Value: t
430 ;; `anything-c-enable-eval-defun-hack'
431 ;; Default Value: t
432 ;; `anything-tramp-verbose'
433 ;; Default Value: 0
434 ;; `anything-raise-command'
435 ;; Default Value: nil
436 ;; `anything-command-map-prefix-key'
437 ;; Default Value: "<f5> a"
438 ;; `anything-c-browse-code-regexp-lisp'
439 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
440 ;; `anything-c-browse-code-regexp-python'
441 ;; Default Value: "\\<def\\>\\|\\<class\\>"
442 ;; `anything-c-browse-code-regexp-alist'
443 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
444 ;; `anything-c-external-programs-associations'
445 ;; Default Value: nil
446 ;; `anything-ff-auto-update-initial-value'
447 ;; Default Value: t
448 ;; `anything-c-copy-async-prefered-emacs'
449 ;; Default Value: "emacs"
450 ;; `anything-ff-lynx-style-map'
451 ;; Default Value: t
452 ;; `anything-ff-history-max-length'
453 ;; Default Value: 100
454 ;; `anything-ff-smart-completion'
455 ;; Default Value: t
456 ;; `anything-ff-default-kbsize'
457 ;; Default Value: 1024.0
458 ;; `anything-ff-tramp-not-fancy'
459 ;; Default Value: t
460 ;; `anything-ff-exif-data-program'
461 ;; Default Value: "exiftran"
462 ;; `anything-ff-exif-data-program-args'
463 ;; Default Value: "-d"
464 ;; `anything-c-grep-use-ioccur-style-keys'
465 ;; Default Value: t
466 ;; `anything-c-pdfgrep-default-read-command'
467 ;; Default Value: "xpdf '%f' %p"
468 ;; `anything-c-etags-tag-file-name'
469 ;; Default Value: "TAGS"
470 ;; `anything-c-etags-tag-file-search-limit'
471 ;; Default Value: 10
472 ;; `anything-c-etags-use-regexp-search'
473 ;; Default Value: nil
474 ;; `anything-c-etags-search-regexp'
475 ;; Default Value: "^.+: .+ \\<%s"
476 ;; `anything-c-filelist-file-name'
477 ;; Default Value: nil
478 ;; `anything-c-eldoc-in-minibuffer-show-fn'
479 ;; Default Value: anything-c-show-info-in-mode-line
480 ;; `anything-c-turn-on-show-completion'
481 ;; Default Value: t
482 ;; `anything-lisp-completion-or-indent-delay'
483 ;; Default Value: 0.6
484 ;; `anything-c-default-external-file-browser'
485 ;; Default Value: "nautilus"
486 ;; `anything-c-use-adaptative-sorting'
487 ;; Default Value: nil
488 ;; `anything-ff-newfile-prompt-p'
489 ;; Default Value: t
490 ;; `anything-ff-avfs-directory'
491 ;; Default Value: nil
492 ;; `anything-ff-file-compressed-list'
493 ;; Default Value: ("gz" "bz2" "zip" "7z")
494 ;; `anything-locate-db-file-regexp'
495 ;; Default Value: "m?locate.db$"
496 ;; `anything-c-show-info-in-mode-line-delay'
497 ;; Default Value: 12
498 ;; `anything-c-copy-files-async-log-file'
499 ;; Default Value: "/tmp/dired.log"
500 ;; `anything-ff-printer-list'
501 ;; Default Value: nil
502 ;; `anything-ff-transformer-show-only-basename'
503 ;; Default Value: nil
504 ;; `anything-completing-read-handlers-alist'
505 ;; Default Value: ((describe-function . anything-completing-read-symbols) (describe-variabl [...]
507 ;; * Anything sources defined here:
508 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
509 ;; `anything-c-source-regexp' (Regexp Builder)
510 ;; `anything-c-source-buffers' (Buffers)
511 ;; `anything-c-source-buffer-not-found' (Create buffer)
512 ;; `anything-c-source-buffers-list' (Buffers)
513 ;; `anything-c-source-file-name-history' (File Name History)
514 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
515 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
516 ;; `anything-c-source-find-files' (Find Files)
517 ;; `anything-c-source-write-file' (Write File)
518 ;; `anything-c-source-insert-file' (Insert File)
519 ;; `anything-c-source-copy-files' (Copy Files)
520 ;; `anything-c-source-symlink-files' (Symlink Files)
521 ;; `anything-c-source-hardlink-files' (Hardlink Files)
522 ;; `anything-c-source-file-cache' (File Cache)
523 ;; `anything-c-source-locate' (Locate)
524 ;; `anything-c-source-recentf' (Recentf)
525 ;; `anything-c-source-ffap-guesser' (File at point)
526 ;; `anything-c-source-ffap-line' (File/Lineno at point)
527 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
528 ;; `anything-c-source-filelist' (FileList)
529 ;; `anything-c-source-info-pages' (Info Pages)
530 ;; `anything-c-source-info-elisp' (Info index: elisp)
531 ;; `anything-c-source-info-cl' (Info index: cl)
532 ;; `anything-c-source-info-org' (Info index: org)
533 ;; `anything-c-source-info-gnus' (Info index: Gnus)
534 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
535 ;; `anything-c-source-info-zsh' (Info index: zsh)
536 ;; `anything-c-source-info-bash' (Info index: bash)
537 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
538 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
539 ;; `anything-c-source-info-find' (Info index: find)
540 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
541 ;; `anything-c-source-info-textutils' (Info index: textutils)
542 ;; `anything-c-source-info-libc' (Info index: libc)
543 ;; `anything-c-source-info-make' (Info index: make)
544 ;; `anything-c-source-info-automake' (Info index: automake)
545 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
546 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
547 ;; `anything-c-source-info-emacs' (Info index: emacs)
548 ;; `anything-c-source-info-elib' (Info index: elib)
549 ;; `anything-c-source-info-eieio' (Info index: eieio)
550 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
551 ;; `anything-c-source-info-guile' (Info index: guile)
552 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
553 ;; `anything-c-source-info-goops' (Info index: goops)
554 ;; `anything-c-source-info-screen' (Info index: screen)
555 ;; `anything-c-source-info-latex' (Info index: latex)
556 ;; `anything-c-source-info-gawk' (Info index: gawk)
557 ;; `anything-c-source-info-sed' (Info index: sed)
558 ;; `anything-c-source-info-m4' (Info index: m4)
559 ;; `anything-c-source-info-wget' (Info index: wget)
560 ;; `anything-c-source-info-binutils' (Info index: binutils)
561 ;; `anything-c-source-info-as' (Info index: as)
562 ;; `anything-c-source-info-bfd' (Info index: bfd)
563 ;; `anything-c-source-info-gprof' (Info index: gprof)
564 ;; `anything-c-source-info-ld' (Info index: ld)
565 ;; `anything-c-source-info-diff' (Info index: diff)
566 ;; `anything-c-source-info-flex' (Info index: flex)
567 ;; `anything-c-source-info-grep' (Info index: grep)
568 ;; `anything-c-source-info-gzip' (Info index: gzip)
569 ;; `anything-c-source-info-libtool' (Info index: libtool)
570 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
571 ;; `anything-c-source-info-info' (Info index: info)
572 ;; `anything-c-source-info-gdb' (Info index: gdb)
573 ;; `anything-c-source-info-stabs' (Info index: stabs)
574 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
575 ;; `anything-c-source-info-cvs' (Info index: cvs)
576 ;; `anything-c-source-info-bison' (Info index: bison)
577 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
578 ;; `anything-c-source-info-global' (Info index: global)
579 ;; `anything-c-source-man-pages' (Manual Pages)
580 ;; `anything-c-source-complex-command-history' (Complex Command History)
581 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
582 ;; `anything-c-source-emacs-commands' (Emacs Commands)
583 ;; `anything-c-source-emacs-functions' (Emacs Functions)
584 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
585 ;; `anything-c-source-advice' (Function Advice)
586 ;; `anything-c-source-emacs-variables' (Emacs Variables)
587 ;; `anything-c-source-lacarte' (Lacarte)
588 ;; `anything-c-source-bookmarks' (Bookmarks)
589 ;; `anything-c-source-bookmark-set' (Set Bookmark)
590 ;; `anything-c-source-bm' (Visible Bookmarks)
591 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
592 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
593 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
594 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
595 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
596 ;; `anything-c-source-bookmark-images' (Bookmark Images)
597 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
598 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
599 ;; `anything-c-source-bookmark-info' (Bookmark Info)
600 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
601 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
602 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
603 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
604 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
605 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
606 ;; `anything-c-source-imenu' (Imenu)
607 ;; `anything-c-source-ctags' (Exuberant ctags)
608 ;; `anything-c-source-etags-select' (Etags)
609 ;; `anything-c-source-semantic' (Semantic Tags)
610 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
611 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
612 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
613 ;; `anything-c-source-customize-face' (Customize Face)
614 ;; `anything-c-source-colors' (Colors)
615 ;; `anything-c-source-tracker-search' (Tracker Search)
616 ;; `anything-c-source-mac-spotlight' (mdfind)
617 ;; `anything-c-source-picklist' (Picklist)
618 ;; `anything-c-source-kill-ring' (Kill Ring)
619 ;; `anything-c-source-mark-ring' (mark-ring)
620 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
621 ;; `anything-c-source-register' (Registers)
622 ;; `anything-c-source-latex-math' (Latex Math Menu)
623 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
624 ;; `anything-c-source-rd-headline' (RD HeadLine)
625 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
626 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
627 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
628 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
629 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
630 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
631 ;; `anything-c-source-eev-anchor' (Anchors)
632 ;; `anything-c-source-org-headline' (Org HeadLine)
633 ;; `anything-c-source-org-keywords' (Org Keywords)
634 ;; `anything-c-source-bbdb' (BBDB)
635 ;; `anything-c-source-evaluation-result' (Evaluation Result)
636 ;; `anything-c-source-calculation-result' (Calculation Result)
637 ;; `anything-c-source-google-suggest' (Google Suggest)
638 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
639 ;; `anything-c-source-emms-streams' (Emms Streams)
640 ;; `anything-c-source-emms-dired' (Music Directory)
641 ;; `anything-c-source-emms-files' (Emms files)
642 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
643 ;; `anything-c-source-call-source' (Call anything source)
644 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
645 ;; `anything-c-source-occur' (Occur)
646 ;; `anything-c-source-browse-code' (Browse code)
647 ;; `anything-c-source-create' (Create)
648 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
649 ;; `anything-c-source-elscreen' (Elscreen)
650 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
651 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
652 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
653 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
654 ;; `anything-c-source-xfonts' (X Fonts)
655 ;; `anything-c-source-ucs' (Ucs names)
656 ;; `anything-c-source-emacs-process' (Emacs Process)
657 ;; `anything-c-source-time-world' (Time World List)
658 ;; `anything-c-source-apt' (APT)
659 ;; `anything-c-source-gentoo' (Portage sources)
660 ;; `anything-c-source-use-flags' (Use Flags)
661 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
662 ;; `anything-c-source-esh' (Eshell completions)
663 ;; `anything-c-source-eshell-history' (Eshell history)
665 ;; *** END auto-documentation
667 ;;; For Maintainers:
669 ;; Install developer-tools/autodoc.el and
670 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
671 ;; This function generates anything-c-source-* / functions / options list.
673 ;; [EVAL IT] (autodoc-update-all)
675 ;; Please write details documentation about function, then others will
676 ;; read code more easier. -- Andy Stewart
680 ;;; Change log:
682 ;; Change log of this file is found at
683 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
685 ;; Change log of this project is found at
686 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
688 ;;; Contributors:
690 ;; Tamas Patrovics
691 ;; Tassilo Horn <tassilo@member.fsf.org>
692 ;; Vagn Johansen <gonz808@hotmail.com>
693 ;; Mathias Dahl <mathias.dahl@gmail.com>
694 ;; Bill Clementson <billclem@gmail.com>
695 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
696 ;; Drew Adams <drew.adams@oracle.com>
697 ;; Jason McBrayer <jmcbray@carcosa.net>
698 ;; Andy Stewart <lazycat.manatee@gmail.com>
699 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
700 ;; rubikitch <rubikitch@ruby-lang.org>
701 ;; Scott Vokes <vokes.s@gmail.com>
702 ;; Kenichirou Oyama <k1lowxb@gmail.com>
705 ;;; TODO
707 ;; - Fix documentation, now many functions haven't documentations.
711 ;;; Code:
713 ;;; Require
716 (require 'anything)
717 (require 'thingatpt)
718 (require 'ffap)
719 (require 'cl)
720 (require 'dired-aux)
721 (require 'dired-x)
722 (require 'tramp)
723 (require 'grep)
724 (require 'url)
725 (require 'xml)
726 (eval-when-compile (require 'org)) ; Shut up byte compiler about org-directory.
727 (eval-when-compile (require 'semantic nil t))
728 (require 'anything-match-plugin)
732 ;;; Declare external functions
735 (declare-function gnus-dired-attach "ext:gnus-dired.el" (files-to-attach))
736 (declare-function image-dired-display-image "image-dired.el" (file &optional original-size))
737 (declare-function image-dired-update-property "image-dired.el" (prop value))
738 (declare-function woman-file-name-all-completions "woman.el" (topic))
739 (declare-function Man-getpage-in-background "man.el" (topic))
740 (declare-function simple-call-tree-analyze "ext:simple-call-tree.el" (&optional test))
741 (declare-function yaoddmuse-update-pagename "ext:yaoddmuse.el" (&optional unforced))
742 (declare-function yaoddmuse-get-library-list "ext:yaoddmuse.el" (&optional dirs string))
743 (declare-function org-get-current-options "ext:org-exp.el")
744 (declare-function emms-streams "ext:emms-streams")
745 (declare-function emms-stream-delete-bookmark "ext:emms-streams")
746 (declare-function emms-stream-add-bookmark "ext:emms-streams" (name url fd type))
747 (declare-function emms-stream-save-bookmarks-file "ext:emms-streams")
748 (declare-function emms-stream-quit "ext:emms-streams")
749 (declare-function with-current-emms-playlist "ext:emms" (&rest body))
750 (declare-function emms-playlist-tracks-in-region "ext:emms" (beg end))
751 (declare-function emms-playlist-first "ext:emms")
752 (declare-function emms-playlist-mode-play-smart "ext:emms-playlist-mode")
753 (declare-function term-line-mode "term")
754 (declare-function term-char-mode "term")
755 (declare-function term-send-input "term")
756 (declare-function term-send-eof "term")
757 (declare-function Info-index-nodes "info" (&optional file))
758 (declare-function Info-goto-node "info" (&optional fork))
759 (declare-function Info-find-node "info.el" (filename nodename &optional no-going-back))
760 (declare-function elscreen-find-screen-by-buffer "ext:elscreen.el" (buffer &optional create))
761 (declare-function elscreen-find-file "ext:elscreen.el" (filename))
762 (declare-function elscreen-goto "ext:elscreen.el" (screen))
763 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
764 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
765 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
766 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
767 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
768 (declare-function bbdb "ext:bbdb-com")
769 (declare-function bbdb-current-record "ext:bbdb-com")
770 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
771 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
772 (declare-function bbdb-current-record "ext:bbdb-com")
773 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
774 (declare-function bbdb-records "ext:bbdb-com"
775 (&optional dont-check-disk already-in-db-buffer))
776 (declare-function eshell-read-aliases-list "em-alias")
777 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
778 (declare-function eshell-bol "esh-mode")
779 (declare-function eldoc-current-symbol "eldoc")
780 (declare-function eldoc-get-fnsym-args-string "eldoc" (sym &optional index))
781 (declare-function eldoc-get-var-docstring "eldoc" (sym))
782 (declare-function eldoc-fnsym-in-current-sexp "eldoc")
783 (declare-function find-library-name "find-func.el" (library))
784 (declare-function adoc-construct "ext:auto-document.el" (buf))
785 (declare-function adoc-first-line "ext:auto-document.el" (str))
786 (declare-function adoc-prin1-to-string "ext:auto-document.el" (object))
787 (declare-function secure-hash "ext:fns.c" (algorithm object &optional start end binary))
791 ;;; compatibility
794 (unless (fboundp 'window-system)
795 (defun window-system (&optional arg)
796 window-system))
800 ;;; Customize
803 (defgroup anything-config nil
804 "Predefined configurations for `anything.el'."
805 :group 'anything)
807 (defcustom anything-c-adaptive-history-file
808 "~/.emacs.d/anything-c-adaptive-history"
809 "Path of file where history information is stored."
810 :type 'string
811 :group 'anything-config)
813 (defcustom anything-c-adaptive-history-length 50
814 "Maximum number of candidates stored for a source."
815 :type 'number
816 :group 'anything-config)
818 (defcustom anything-c-google-suggest-url
819 "http://google.com/complete/search?output=toolbar&q="
820 "URL used for looking up Google suggestions."
821 :type 'string
822 :group 'anything-config)
824 (defcustom anything-c-google-suggest-search-url
825 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
826 "URL used for Google searching."
827 :type 'string
828 :group 'anything-config)
830 (defcustom anything-google-suggest-use-curl-p nil
831 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
832 Otherwise `url-retrieve-synchronously' is used."
833 :type 'boolean
834 :group 'anything-config)
836 (defcustom anything-c-yahoo-suggest-url
837 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
838 "Url used for looking up Yahoo suggestions."
839 :type 'string
840 :group 'anything-config)
842 (defcustom anything-c-yahoo-suggest-search-url
843 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
844 "Url used for Yahoo searching."
845 :type 'string
846 :group 'anything-config)
848 (defcustom anything-c-boring-buffer-regexp
849 (rx (or
850 (group bos " ")
851 ;; anything-buffers
852 "*anything" "*ac-mode"
853 ;; echo area
854 " *Echo Area" " *Minibuf"))
855 "The regexp that match boring buffers.
856 Buffer candidates matching this regular expression will be
857 filtered from the list of candidates if the
858 `anything-c-skip-boring-buffers' candidate transformer is used, or
859 they will be displayed with face `file-name-shadow' if
860 `anything-c-shadow-boring-buffers' is used."
861 :type 'string
862 :group 'anything-config)
863 ;; (string-match anything-c-boring-buffer-regexp "buf")
864 ;; (string-match anything-c-boring-buffer-regexp " hidden")
865 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
867 (defcustom anything-c-boring-file-regexp
868 (rx (or
869 ;; Boring directories
870 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
871 ;; Boring files
872 (and line-start ".#")
873 (and (or ".class" ".la" ".o" "~") eol)))
874 "The regexp that match boring files.
875 File candidates matching this regular expression will be
876 filtered from the list of candidates if the
877 `anything-c-skip-boring-files' candidate transformer is used, or
878 they will be displayed with face `file-name-shadow' if
879 `anything-c-shadow-boring-files' is used."
880 :type 'string
881 :group 'anything-config)
883 (defcustom anything-kill-ring-threshold 10
884 "*Minimum length to be listed by `anything-c-source-kill-ring'."
885 :type 'integer
886 :group 'anything-config)
888 (defcustom anything-c-kill-ring-max-lines-number nil
889 "Max number of lines displayed per candidate in kill-ring browser.
890 If nil or zero, don't truncate candidate, show all."
891 :type 'integer
892 :group 'anything-config)
894 (defcustom anything-su-or-sudo "su"
895 "What command to use for root access."
896 :type 'string
897 :group 'anything-config)
899 (defcustom anything-for-files-prefered-list
900 '(anything-c-source-ffap-line
901 anything-c-source-ffap-guesser
902 anything-c-source-buffers-list
903 anything-c-source-recentf
904 anything-c-source-bookmarks
905 anything-c-source-file-cache
906 anything-c-source-files-in-current-dir+
907 anything-c-source-locate)
908 "Your prefered sources to find files."
909 :type 'list
910 :group 'anything-config)
912 (defcustom anything-create--actions-private nil
913 "User defined actions for `anything-create' / `anything-c-source-create'.
914 It is a list of (DISPLAY . FUNCTION) pairs like `action'
915 attribute of `anything-sources'.
917 It is prepended to predefined pairs."
918 :type 'list
919 :group 'anything-config)
921 (defcustom anything-allow-skipping-current-buffer t
922 "Show current buffer or not in anything buffer"
923 :type 'boolean
924 :group 'anything-config)
926 (defcustom anything-c-enable-eval-defun-hack t
927 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
928 This hack is invoked when pressing C-M-x in the form \
929 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
930 :type 'boolean
931 :group 'anything-config)
933 (defcustom anything-tramp-verbose 0
934 "*Just like `tramp-verbose' but specific to anything.
935 When set to 0 don't show tramp messages in anything.
936 If you want to have the default tramp messages set it to 3."
937 :type 'integer
938 :group 'anything-config)
940 (defcustom anything-raise-command nil
941 "*A shell command to jump to a window running specific program.
942 Need external program wmctrl.
943 This will be use with `format', so use something like \"wmctrl -xa %s\"."
944 :type 'string
945 :group 'anything-config)
947 (defun anything-set-anything-command-map-prefix-key (var key)
948 (declare (special anything-command-map-prefix-key))
949 (when (boundp 'anything-command-map-prefix-key)
950 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
951 (setq anything-command-map-prefix-key key)
952 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
953 'anything-command-map))
955 (defcustom anything-command-map-prefix-key "<f5> a"
956 "*The prefix key for all `anything-command-map' commands.
958 !!WARNING!!
959 This default value is very likely to be changed,
960 because it is under discussion."
961 :type 'string
962 :set 'anything-set-anything-command-map-prefix-key
963 :group 'anything-config)
965 (defcustom anything-c-browse-code-regexp-lisp
966 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
967 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
968 "*Regexp used to parse lisp buffer when browsing code."
969 :type 'string
970 :group 'anything-config)
972 (defcustom anything-c-browse-code-regexp-python
973 "\\<def\\>\\|\\<class\\>"
974 "*Regexp used to parse python buffer when browsing code."
975 :type 'string
976 :group 'anything-config)
978 (defcustom anything-c-browse-code-regexp-alist
979 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
980 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
981 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
982 (python-mode . ,anything-c-browse-code-regexp-python))
983 "*Alist to store regexps for browsing code corresponding \
984 to a specific `major-mode'."
985 :type 'list
986 :group 'anything-config)
988 (defcustom anything-c-external-programs-associations nil
989 "*Alist to store externals programs associated with file extension.
990 This variable overhide setting in .mailcap file.
991 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
992 :type 'list
993 :group 'anything-config)
995 (defcustom anything-ff-auto-update-initial-value t
996 "Auto update when only one candidate directory is matched.
997 This is the default value when starting `anything-find-files'."
998 :group 'anything-config
999 :type 'boolean)
1001 (defcustom anything-c-copy-async-prefered-emacs "emacs"
1002 "Path to the emacs you want to use for copying async.
1003 Emacs versions < 24 fail to copy directory due to a bug not fixed
1004 in `copy-directory'."
1005 :group 'anything-config
1006 :type 'string)
1008 (defcustom anything-ff-lynx-style-map t
1009 "Use arrow keys to navigate with `anything-find-files'.
1010 You will have to restart Emacs or reeval `anything-find-files-map'
1011 and `anything-c-read-file-map' for this take effect."
1012 :group 'anything-config
1013 :type 'boolean)
1015 (defcustom anything-ff-history-max-length 100
1016 "*Number of elements shown in `anything-find-files' history."
1017 :group 'anything-config
1018 :type 'integer)
1020 (defcustom anything-ff-smart-completion t
1021 "Try to complete filenames smarter when non--nil.
1022 See `anything-ff-transform-fname-for-completion' for more info."
1023 :group 'anything-config
1024 :type 'boolean)
1026 (defcustom anything-ff-default-kbsize 1024.0
1027 "Default Kbsize to use for showing files size.
1028 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1029 :group 'anything-config
1030 :type 'float)
1032 (defcustom anything-ff-tramp-not-fancy t
1033 "No colors when listing remote files when set to non--nil.
1034 This make listing much faster, specially on slow machines."
1035 :group 'anything-config
1036 :type 'boolean)
1038 (defcustom anything-ff-exif-data-program "exiftran"
1039 "*Program used to extract exif data of an image file."
1040 :group 'anything-config
1041 :type 'string)
1043 (defcustom anything-ff-exif-data-program-args "-d"
1044 "*Arguments used for `anything-ff-exif-data-program'."
1045 :group 'anything-config
1046 :type 'string)
1048 (defcustom anything-c-grep-use-ioccur-style-keys t
1049 "Use Arrow keys to jump to occurences."
1050 :group 'anything-config
1051 :type 'boolean)
1053 (defcustom anything-c-pdfgrep-default-read-command "xpdf '%f' %p"
1054 "Default command to read pdf files from pdfgrep.
1055 Where '%f' format spec is filename and '%p' is page number"
1056 :group 'anything-config
1057 :type 'string)
1059 (defcustom anything-c-etags-tag-file-name "TAGS"
1060 "Etags tag file name."
1061 :type 'string
1062 :group 'anything-config)
1064 (defcustom anything-c-etags-tag-file-search-limit 10
1065 "The limit level of directory to search tag file.
1066 Don't search tag file deeply if outside this value."
1067 :type 'number
1068 :group 'anything-config)
1070 (defcustom anything-c-etags-use-regexp-search nil
1071 "When non--nil search etags candidates by regexp.
1072 This disable anything-match-plugin when enabled.
1073 When nil search is performed directly on patter and *match-plugin is used
1074 if available. You can customize `anything-c-etags-search-regexp'."
1075 :group 'anything-config
1076 :type 'boolean)
1078 (defcustom anything-c-etags-search-regexp "^.+: .+ \\<%s"
1079 "Regexp that match tags in an anything etags buffer.
1080 The format spec is replaced by pattern.
1081 This regexp have no effect when `anything-c-etags-use-regexp-search'
1082 is nil."
1083 :group 'anything-config
1084 :type 'regexp)
1086 (defcustom anything-c-filelist-file-name nil
1087 "Filename of file list.
1088 Accept a list of string for multiple files.
1090 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1091 File list is created by make-filelist.rb script.
1093 Usage:
1094 ruby make-filelist.rb > /tmp/all.filelist
1096 Then
1097 ;; Assume that /tmp is ramdisk or tmpfs
1098 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1099 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1101 :type 'string
1102 :group 'anything-config)
1104 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1105 'anything-c-show-info-in-mode-line
1106 "A function to display eldoc info.
1107 Should take one arg: the string to display."
1108 :group 'anything-config
1109 :type 'symbol)
1111 (defcustom anything-c-turn-on-show-completion t
1112 "Display candidate in buffer while moving selection when non--nil."
1113 :group 'anything-config
1114 :type 'boolean)
1116 (defcustom anything-lisp-completion-or-indent-delay 0.6
1117 "After this delay `anything-lisp-completion-counter' is reset to 0.
1118 This allow to indent again without completing lisp symbol after this delay.
1119 Default is 0.6 seconds."
1120 :group 'anything-config
1121 :type 'number)
1123 (defcustom anything-c-default-external-file-browser "nautilus"
1124 "Default external file browser for your system.
1125 Directories will be opened externally with it.
1126 Set to nil if you do not have external file browser
1127 or do not want to use it."
1128 :group 'anything-config
1129 :type 'string)
1131 (defcustom anything-c-use-adaptative-sorting nil
1132 "*Wheter to use or not adaptative sorting.
1133 Even if a source use it, it will have no effect when set to nil."
1134 :type 'boolean
1135 :group 'anything-config)
1137 (defcustom anything-ff-newfile-prompt-p t
1138 "Whether Prompt or not when creating new file.
1139 This set `ffap-newfile-prompt'."
1140 :type 'boolean
1141 :group 'anything-config)
1144 (defcustom anything-ff-avfs-directory nil
1145 "*The default avfs directory, usually '.avfs'.
1146 When this is set you will be able to expand archive filenames with `C-z'
1147 inside an avfs directory mounted with mountavfs.
1148 See <http://sourceforge.net/projects/avf/>."
1149 :type 'boolean
1150 :group 'anything-config)
1152 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1153 "*Minimal list of compressed files extension."
1154 :type 'list
1155 :group 'anything-config)
1157 (defcustom anything-locate-db-file-regexp "m?locate\.db$"
1158 "Default regexp to match locate database.
1159 If nil Search in all files."
1160 :type 'string
1161 :group 'anything-config)
1163 (defcustom anything-c-show-info-in-mode-line-delay 12
1164 "Eldoc will show info in mode-line during this delay if user is idle."
1165 :type 'integer
1166 :group 'anything-config)
1168 (defcustom anything-c-copy-files-async-log-file "/tmp/dired.log"
1169 "The file used to communicate with two emacs when copying files async."
1170 :type 'string
1171 :group 'anything-config)
1173 (defcustom anything-ff-printer-list nil
1174 "A list of available printers on your system.
1175 When non--nil let you choose a printer to print file.
1176 Otherwise when nil the variable `printer-name' will be used.
1177 On Unix based systems you can use `anything-ff-find-printers' to
1178 find a list of available printers."
1179 :type 'list
1180 :group 'anything-config)
1182 (defcustom anything-ff-transformer-show-only-basename nil
1183 "Show only basename of candidates in `anything-find-files'.
1184 This can be toggled at anytime from `anything-find-files' with \
1185 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1186 :type 'boolean
1187 :group 'anything-config)
1189 (defcustom anything-ff-quick-delete-dont-prompt-for-deletion nil
1190 "Don't ask in persistent deletion of files when non--nil."
1191 :group 'anything-config
1192 :type 'boolean)
1194 (defcustom anything-completing-read-handlers-alist
1195 '((describe-function . anything-completing-read-symbols)
1196 (describe-variable . anything-completing-read-symbols)
1197 (debug-on-entry . anything-completing-read-symbols)
1198 (find-function . anything-completing-read-symbols)
1199 (trace-function . anything-completing-read-symbols)
1200 (trace-function-background . anything-completing-read-symbols)
1201 (find-tag . anything-completing-read-with-cands-in-buffer)
1202 (ffap-alternate-file . nil))
1203 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1204 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1205 where key and value are symbols.
1207 Each key is an Emacs command that use originaly `completing-read'.
1209 Each value maybe an anything function that take same arguments as
1210 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1211 anything source and BUFFER the name of the buffer we will use.
1212 This function prefix name must start by \"anything\".
1214 See `anything-completing-read-symbols' for example.
1216 If the value of an entry is nil completion will fall back to
1217 emacs vanilla behavior.
1218 e.g If you want to disable anything completion for `describe-function':
1219 \(describe-function . nil\).
1221 Ido is also supported, you can use `ido-completing-read' and
1222 `ido-read-file-name' as value of an entry or just 'ido.
1223 e.g ido completion for `find-file':
1224 \(find-file . ido\)
1225 same as
1226 \(find-file . ido-read-file-name\)
1227 Note that you don't need to enable `ido-mode' for this to work."
1228 :group 'anything-config
1229 :type '(alist :key-type symbol :value-type symbol))
1233 ;;; General internal variables
1235 ;; Some internals variable that need to be loaded
1236 ;; here to avoid compiler warnings.
1237 (defvar anything-c-external-commands-list nil
1238 "A list of all external commands the user can execute. If this
1239 variable is not set by the user, it will be calculated
1240 automatically.")
1242 (defvar anything-c-show-completion-overlay nil)
1244 (defvar anything-c-locate-command
1245 (case system-type
1246 ('gnu/linux "locate -i -r %s")
1247 ('berkeley-unix "locate -i %s")
1248 ('windows-nt "es -i -r %s")
1249 (t "locate %s"))
1250 "A list of arguments for locate program.
1251 The \"-r\" option must be the last option.")
1254 ;;; Faces
1257 (defface anything-buffer-saved-out
1258 '((t (:foreground "red")))
1259 "*Face used for buffer files modified outside of emacs."
1260 :group 'anything-config)
1262 (defface anything-buffer-not-saved
1263 '((t (:foreground "Indianred2")))
1264 "*Face used for buffer files not already saved on disk."
1265 :group 'anything-config)
1267 (defface anything-ff-prefix
1268 '((t (:background "yellow" :foreground "black")))
1269 "*Face used to prefix new file or url paths in `anything-find-files'."
1270 :group 'anything-config)
1272 (defface anything-ff-executable
1273 '((t (:foreground "green")))
1274 "*Face used for executable files in `anything-find-files'."
1275 :group 'anything-config)
1277 (defface anything-ff-directory
1278 '((t (:foreground "DarkRed" :background "LightGray")))
1279 "*Face used for directories in `anything-find-files'."
1280 :group 'anything-config)
1282 (defface anything-ff-symlink
1283 '((t (:foreground "DarkOrange")))
1284 "*Face used for symlinks in `anything-find-files'."
1285 :group 'anything-config)
1287 (defface anything-ff-invalid-symlink
1288 '((t (:foreground "black" :background "red")))
1289 "*Face used for invalid symlinks in `anything-find-files'."
1290 :group 'anything-config)
1292 (defface anything-ff-file
1293 '((t (:foreground "CadetBlue" :underline t)))
1294 "*Face used for file names in `anything-find-files'."
1295 :group 'anything-config)
1297 (defface anything-grep-match
1298 '((t (:inherit match)))
1299 "Face used to highlight grep matches."
1300 :group 'anything-config)
1302 (defface anything-grep-file
1303 '((t (:foreground "BlueViolet" :underline t)))
1304 "Face used to highlight grep results filenames."
1305 :group 'anything-config)
1307 (defface anything-grep-lineno
1308 '((t (:foreground "Darkorange1")))
1309 "Face used to highlight grep number lines."
1310 :group 'anything-config)
1312 (defface anything-grep-running
1313 '((t (:foreground "Red")))
1314 "Face used in mode line when grep is running."
1315 :group 'anything-config)
1317 (defface anything-grep-finish
1318 '((t (:foreground "Green")))
1319 "Face used in mode line when grep is finish."
1320 :group 'anything-config)
1322 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1323 "*Face used in anything-M-x to show keybinding."
1324 :group 'anything)
1326 (defface anything-bmkext-info
1327 '((t (:foreground "green")))
1328 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1329 :group 'anything)
1331 (defface anything-bmkext-w3m
1332 '((t (:foreground "yellow")))
1333 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1334 :group 'anything)
1336 (defface anything-bmkext-gnus
1337 '((t (:foreground "magenta")))
1338 "*Face used for Gnus bookmarks."
1339 :group 'anything)
1341 (defface anything-bmkext-man
1342 '((t (:foreground "Orange4")))
1343 "*Face used for Woman/man bookmarks."
1344 :group 'anything)
1346 (defface anything-bmkext-no--file
1347 '((t (:foreground "grey")))
1348 "*Face used for non--file bookmarks."
1349 :group 'anything)
1351 (defface anything-bmkext-file
1352 '((t (:foreground "Deepskyblue2")))
1353 "*Face used for non--file bookmarks."
1354 :group 'anything)
1356 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1357 "Face for su/sudo bookmarks."
1358 :group 'anything)
1360 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1361 "Face for w3m bookmarks" :group 'anything)
1363 (defface anything-emms-playlist
1364 '((t (:foreground "Springgreen4" :underline t)))
1365 "*Face used for tracks in current emms playlist."
1366 :group 'anything)
1368 (defface anything-apt-installed
1369 '((t (:foreground "green")))
1370 "*Face used for apt installed candidates."
1371 :group 'anything)
1373 (defface anything-gentoo-match-face '((t (:foreground "red")))
1374 "Face for anything-gentoo installed packages."
1375 :group 'traverse-faces)
1377 (defface anything-lisp-show-completion
1378 '((t (:background "DarkSlateGray")))
1379 "*Face used for showing candidates in `anything-lisp-completion'."
1380 :group 'anything-config)
1382 (defface anything-lisp-completion-info
1383 '((t (:foreground "red")))
1384 "*Face used for showing info in `anything-lisp-completion'."
1385 :group 'anything-config)
1387 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1388 "Face for source header in the anything buffer." :group 'anything)
1390 ;;;###autoload
1391 (defun anything-configuration ()
1392 "Customize `anything'."
1393 (interactive)
1394 (customize-group "anything-config"))
1398 ;;; Anything-command-map
1401 ;;;###autoload
1402 (defvar anything-command-map)
1403 (define-prefix-command 'anything-command-map)
1406 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1407 (define-key anything-command-map (kbd "a") 'anything-c-apropos)
1408 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1409 (define-key anything-command-map (kbd "l") 'anything-locate)
1410 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1411 (define-key anything-command-map (kbd "r") 'anything-regexp)
1412 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1413 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1414 (define-key anything-command-map (kbd "#") 'anything-emms)
1415 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1416 (define-key anything-command-map (kbd "t") 'anything-top)
1417 (define-key anything-command-map (kbd "i") 'anything-imenu)
1418 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1419 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1420 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1421 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1422 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1423 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1424 (define-key anything-command-map (kbd "f") 'anything-for-files)
1425 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1426 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1427 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1428 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1429 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1430 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1431 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1432 (define-key anything-command-map (kbd "c") 'anything-colors)
1433 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1434 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1435 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1436 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1437 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1438 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1439 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1440 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1441 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1442 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1444 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1445 ;; minibuffer-local-filename-must-match-map.
1446 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1447 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1448 (dolist (map (list minibuffer-local-filename-completion-map
1449 minibuffer-local-completion-map
1450 minibuffer-local-must-match-filename-map
1451 minibuffer-local-filename-must-match-map
1452 minibuffer-local-map
1453 minibuffer-local-isearch-map
1454 minibuffer-local-must-match-map
1455 minibuffer-local-ns-map))
1456 (define-key map "\C-r" 'anything-minibuffer-history))
1460 ;;; Menu
1463 (easy-menu-define nil global-map
1464 "`anything' menu"
1465 '("Anything"
1466 ["All anything commands" anything-execute-anything-command t]
1467 ["Find any Files/Buffers" anything-for-files t]
1468 ["Anything Everywhere (Toggle)" ac-mode t]
1469 "----"
1470 ("Files:"
1471 ["Find files" anything-find-files t]
1472 ["Recent Files" anything-recentf t]
1473 ["Locate" anything-locate t]
1474 ["Bookmarks" anything-c-pp-bookmarks t])
1475 ("Buffers:"
1476 ["Find buffers" anything-buffers-list t])
1477 ("Commands:"
1478 ["Emacs Commands" anything-M-x t]
1479 ["Externals Commands" anything-c-run-external-command t])
1480 ("Help:"
1481 ["Anything Apropos" anything-c-apropos t])
1482 ("Info:"
1483 ["Info at point" anything-info-at-point t]
1484 ["Emacs Manual index" anything-info-emacs t]
1485 ["Gnus Manual index" anything-info-gnus t])
1486 ("Org:"
1487 ["Org keywords" anything-org-keywords t]
1488 ["Org headlines" anything-org-headlines t])
1489 ("Tools:"
1490 ["Occur" anything-occur t]
1491 ["Grep" anything-do-grep t]
1492 ["Etags" anything-c-etags-select t]
1493 ["Lisp complete at point" anything-lisp-completion-at-point t]
1494 ["Browse Kill ring" anything-show-kill-ring t]
1495 ["Browse register" anything-register t]
1496 ["Browse code" anything-browse-code t]
1497 ["Mark Ring" anything-all-mark-rings t]
1498 ["Regexp handler" anything-regexp t]
1499 ["Colors & Faces" anything-colors t]
1500 ["Show xfonts" anything-select-xfont t]
1501 ["Ucs Symbols" anything-ucs t]
1502 ["Imenu" anything-imenu t]
1503 ["Google Suggest" anything-google-suggest t]
1504 ["Eval expression" anything-eval-expression-with-eldoc t]
1505 ["Calcul expression" anything-calcul-expression t]
1506 ["Man pages" anything-man-woman t]
1507 ["Top externals process" anything-top t]
1508 ["Emacs internals process" anything-list-emacs-process t])
1509 "----"
1510 ["Prefered Options" anything-configuration t]))
1512 ;;; Anything map add ons
1515 (define-key anything-map (kbd "C-x C-f") 'anything-quit-and-find-file)
1516 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1517 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
1520 ;;; Specialized keymaps
1523 (defvar anything-c-buffer-map
1524 (let ((map (copy-keymap anything-map)))
1525 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1526 ;; No need to have separate command for grep and zgrep
1527 ;; as we don't use recursivity for buffers.
1528 ;; So use zgrep for both as it is capable to handle non--compressed files.
1529 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1530 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1531 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1532 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1533 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1534 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1535 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1536 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1537 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1538 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1539 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1540 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1541 (define-key map (kbd "M-a") 'anything-mark-all)
1542 (when (locate-library "elscreen")
1543 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1544 (delq nil map))
1545 "Keymap for buffer sources in anything.")
1547 (defvar anything-find-files-map
1548 (let ((map (copy-keymap anything-map)))
1549 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1550 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1551 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1552 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1553 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1554 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1555 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1556 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1557 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1558 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1559 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1560 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1561 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1562 (define-key map (kbd "<deletechar>") 'anything-ff-persistent-delete)
1563 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1564 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1565 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1566 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1567 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1568 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1569 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1570 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1571 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1572 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1573 (define-key map (kbd "C-c ?") 'anything-ff-help)
1574 (define-key map (kbd "C-}") 'anything-narrow-window)
1575 (define-key map (kbd "C-{") 'anything-enlarge-window)
1576 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1577 (define-key map (kbd "M-a") 'anything-mark-all)
1578 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1579 (define-key map (kbd "M-u") 'anything-unmark-all)
1580 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1581 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1582 ;; Next 2 have no effect if candidate is not an image file.
1583 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1584 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1585 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1586 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1587 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1588 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1589 (when anything-ff-lynx-style-map
1590 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1591 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1592 (delq nil map))
1593 "Keymap for `anything-find-files'.")
1595 (defvar anything-c-read-file-map
1596 (let ((map (copy-keymap anything-map)))
1597 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1598 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1599 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1600 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1601 (when anything-ff-lynx-style-map
1602 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1603 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1604 (define-key map (kbd "<M-left>") 'anything-previous-source)
1605 (define-key map (kbd "<M-right>") 'anything-next-source))
1606 (delq nil map))
1607 "Keymap for `anything-c-read-file-name'.")
1609 (defvar anything-generic-files-map
1610 (let ((map (copy-keymap anything-map)))
1611 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1612 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1613 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1614 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1615 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1616 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1617 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1618 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1619 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1620 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1621 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1622 map)
1623 "Generic Keymap for files.")
1625 (defvar anything-c-grep-map
1626 (let ((map (copy-keymap anything-map)))
1627 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1628 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1629 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1630 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1631 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1632 (when anything-c-grep-use-ioccur-style-keys
1633 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1634 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1635 (define-key map (kbd "C-c ?") 'anything-grep-help)
1636 (delq nil map))
1637 "Keymap used in Grep sources.")
1639 (defvar anything-c-pdfgrep-map
1640 (let ((map (copy-keymap anything-map)))
1641 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1642 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1643 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1644 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1645 map)
1646 "Keymap used in pdfgrep.")
1648 (defvar anything-c-etags-map
1649 (let ((map (copy-keymap anything-map)))
1650 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1651 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1652 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1653 (define-key map (kbd "C-c ?") 'anything-etags-help)
1654 map)
1655 "Keymap used in Etags.")
1657 (defvar anything-eval-expression-map
1658 (let ((map (copy-keymap anything-map)))
1659 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1660 (define-key map (kbd "<tab>") 'lisp-indent-line)
1661 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1662 (define-key map (kbd "C-p") 'previous-line)
1663 (define-key map (kbd "C-n") 'next-line)
1664 (define-key map (kbd "<up>") 'previous-line)
1665 (define-key map (kbd "<down>") 'next-line)
1666 (define-key map (kbd "<right>") 'forward-char)
1667 (define-key map (kbd "<left>") 'backward-char)
1668 map))
1670 (defvar anything-c-ucs-map
1671 (let ((map (copy-keymap anything-map)))
1672 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1673 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1674 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1675 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1676 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1677 map)
1678 "Keymap for `anything-ucs'.")
1682 ;;; Embeded documentation.
1685 (defun anything-c-list-preconfigured-anything ()
1686 "Collect preconfigured anything functions in this file."
1687 (loop with doc
1688 with sym
1689 for entry in (cdr (assoc
1690 (file-truename (locate-library "anything-config"))
1691 load-history))
1692 if (and (consp entry)
1693 (eq (car entry) 'defun)
1694 (string-match "^Preconfigured.+$"
1695 (setq doc (or (documentation (setq sym (cdr entry)))
1696 ""))))
1697 collect (cons sym (match-string 0 doc))))
1699 (defun anything-c-format-preconfigured-anything ()
1700 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1701 (anything-c-list-preconfigured-anything)))
1703 ;;; Global help message - Used by `anything-help'
1706 (setq anything-help-message
1707 (lambda ()
1708 (concat
1709 "\\<anything-map>"
1710 "`anything' is QuickSilver-like candidate-selection framework.
1712 Narrow the list by typing some pattern,
1713 Multiple patterns are allowed by splitting by space.
1714 Select with natural Emacs operations, choose with RET.
1716 If you have any problems, press C-c C-x C-b!!
1717 Feel free to send bug reports. I'll fix them.
1718 The steps are described in the beginning of anything.el file.
1720 == Basic Operations ==
1721 C-p, Up: Previous Line
1722 C-n, Down : Next Line
1723 M-v, PageUp : Previous Page
1724 C-v, PageDown : Next Page
1725 Enter : Execute first (default) action / Select
1726 M-< : First Line
1727 M-> : Last Line
1728 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1729 M-PageDown, C-M-v : Next Page (other-window)
1731 Tab, C-i : Show action list
1732 Left : Previous Source
1733 Right, C-o : Next Source
1734 C-k : Delete pattern
1735 C-z : Persistent Action (Execute action with anything session kept)
1736 C-c C-x C-b: Send a bug report
1738 == Shortcuts For 2nd/3rd Action ==
1739 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1740 \\[anything-select-3rd-action] : Execute 3rd Action
1742 == Visible Marks ==
1743 Visible marks store candidate. Some actions uses marked candidates.
1745 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1746 \\[anything-prev-visible-mark] : Previous Mark
1747 \\[anything-next-visible-mark] : Next Mark
1749 == Miscellaneous Commands ==
1750 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1751 \\[anything-quit-and-find-file] : Drop into `find-file'
1752 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1753 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1754 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1755 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1756 \\[anything-force-update] : Recalculate And Redisplay Candidates
1758 == Global Commands ==
1759 \\<global-map>\\[anything-resume] revives last `anything' session.
1760 It is very useful, so you should bind any key.
1762 Single source is executed by \\[anything-call-source].
1764 == Preconfigured `anything' ==
1765 Preconfigured `anything' is commands that uses `anything' interface.
1766 You can use them without configuration.
1769 (apply 'concat (anything-c-format-preconfigured-anything))
1771 Enjoy!")))
1773 ;;; `anything-buffer-list' help
1776 ;;;###autoload
1777 (defun anything-c-buffer-help ()
1778 "Help command for anything buffers."
1779 (interactive)
1780 (let ((anything-help-message "== Anything Buffer ==
1781 \nTips:
1782 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1783 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1784 \nSpecific commands for `anything-buffers-list':
1785 \\<anything-c-buffer-map>
1786 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1787 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1788 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1789 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1790 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1791 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1792 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1793 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1794 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1795 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1796 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1797 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1798 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1799 \\[anything-mark-all]\t\t->Mark all.
1800 \\[anything-c-buffer-help]\t\t->Display this help.
1801 \n== Anything Map ==
1802 \\{anything-map}
1804 (anything-help)))
1807 ;;; Find files help (`anything-find-files')
1810 ;;;###autoload
1811 (defun anything-ff-help ()
1812 "Help command for `anything-find-files'."
1813 (interactive)
1814 (let ((anything-help-message "== Anything Find Files ==
1815 \nTips:
1816 \n- Enter `~/' at end of pattern to quickly reach home directory.
1817 - Enter `/' at end of pattern to quickly reach root of your file system.
1818 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1819 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1820 - Use `C-u C-z' to watch an image.
1821 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1822 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1824 \nSpecific commands for `anything-find-files':
1825 \\<anything-find-files-map>
1826 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1827 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1828 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1829 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1830 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1831 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1832 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1833 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1834 \\[anything-ff-run-load-file]\t\t->Load File.
1835 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1836 \\[anything-ff-run-delete-file]\t\t->Delete File.
1837 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1838 \\[anything-ff-persistent-delete]\t->Delete file without quitting.
1839 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1840 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1841 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1842 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1843 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1844 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1845 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1846 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1847 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1848 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1849 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1850 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1851 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1852 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1853 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1854 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1855 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1856 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1857 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1858 \\[anything-narrow-window]\t\t->Narrow anything window.
1859 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1860 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1861 \\[anything-ff-help]\t\t->Display this help info.
1862 \n== Anything Map ==
1863 \\{anything-map}
1865 (anything-help)))
1867 ;;; Help for `anything-c-read-file-name'
1870 ;;;###autoload
1871 (defun anything-read-file-name-help ()
1872 (interactive)
1873 (let ((anything-help-message "== Anything read file name Map ==\
1874 \nSpecific commands for anything-c-read-file-name:
1875 \\<anything-c-read-file-map>
1876 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1877 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1878 \\[anything-next-source]\t\t->Goto next source.
1879 \\[anything-previous-source]\t->Goto previous source.
1880 \\[anything-read-file-name-help]\t\t->Display this help info.
1881 \n== Anything Map ==
1882 \\{anything-map}
1884 (anything-help)))
1886 ;;; Generic file help - Used by locate.
1889 ;;;###autoload
1890 (defun anything-generic-file-help ()
1891 (interactive)
1892 (let ((anything-help-message "== Anything Generic files Map ==\
1893 \nSpecific commands for anything locate and others files sources:
1894 \\<anything-generic-files-map>
1895 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1896 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1897 \\[anything-ff-run-delete-file]\t\t->Delete file.
1898 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1899 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1900 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1901 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1902 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1903 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1904 \nLocate tips:
1905 You can add after writing search pattern any of the locate command line options.
1906 e.g -b, -e, -n <number>...etc.
1907 See Man locate for more infos.
1908 \n== Anything Map ==
1909 \\{anything-map}"))
1910 (anything-help)))
1913 ;;; Grep help
1916 ;;;###autoload
1917 (defun anything-grep-help ()
1918 (interactive)
1919 (let ((anything-help-message "== Anything Grep Map ==\
1920 \nSpecific commands for Grep and Etags:
1921 \\<anything-c-grep-map>
1922 \\[anything-c-goto-next-file]\t->Next File.
1923 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1924 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1925 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1926 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1927 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1928 \\[anything-grep-help]\t\t->Show this help.
1929 \n== Anything Map ==
1930 \\{anything-map}"))
1931 (anything-help)))
1933 ;;; Pdf grep help
1936 ;;;###autoload
1937 (defun anything-pdfgrep-help ()
1938 (interactive)
1939 (let ((anything-help-message "== Anything PdfGrep Map ==\
1940 \nSpecific commands for Pdf Grep:
1941 \\<anything-c-pdfgrep-map>
1942 \\[anything-c-goto-next-file]\t->Next File.
1943 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1944 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1945 \\[anything-pdfgrep-help]\t\t->Show this help.
1946 \n== Anything Map ==
1947 \\{anything-map}"))
1948 (anything-help)))
1950 ;;; Etags help
1953 ;;;###autoload
1954 (defun anything-etags-help ()
1955 "The help function for etags."
1956 (interactive)
1957 (let ((anything-help-message "== Anything Etags Map ==\
1958 \nSpecific commands for Etags:
1959 \\<anything-c-etags-map>
1960 \\[anything-c-goto-next-file]\t->Next File.
1961 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1962 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1963 \\[anything-etags-help]\t\t->Show this help.
1964 \n== Anything Map ==
1965 \\{anything-map}"))
1966 (anything-help)))
1968 ;;; Ucs help
1971 (defun anything-c-ucs-help ()
1972 "Help command for `anything-ucs'."
1973 (interactive)
1974 (let ((anything-help-message "== Anything Ucs ==
1975 \nSpecific commands for `anything-ucs':
1976 \\<anything-c-ucs-map>
1977 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1978 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1979 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1980 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1981 \\[anything-c-ucs-help]\t\t->Show this help.
1983 \n== Anything Map ==
1984 \\{anything-map}
1986 (anything-help)))
1990 ;;; Mode line strings
1993 (defvar anything-buffer-mode-line-string
1994 '("Buffer(s)"
1995 "\\<anything-c-buffer-map>\
1996 \\[anything-c-buffer-help]:Help, \
1997 \\<anything-map>\
1998 \\[anything-select-action]:Acts,\
1999 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2000 \\[anything-select-3rd-action]:NthAct,\
2001 \\[anything-send-bug-report-from-anything]:BugReport."
2002 "String displayed in mode-line in `anything-c-source-buffers-list'"))
2004 (defvar anything-ff-mode-line-string
2005 "\\<anything-find-files-map>\
2006 \\[anything-ff-help]:Help, \
2007 \\[anything-send-bug-report-from-anything]:BugReport, \
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 "String displayed in mode-line in `anything-c-source-find-files'")
2014 (defvar anything-read-file-name-mode-line-string
2015 "\\<anything-c-read-file-map>\
2016 \\[anything-read-file-name-help]:Help, \
2017 \\<anything-map>\
2018 \\[anything-select-action]:Acts,\
2019 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2020 \\[anything-select-3rd-action]:NthAct"
2021 "String displayed in mode-line in `anything-c-source-find-files'")
2023 (defvar anything-generic-file-mode-line-string
2024 "\\<anything-generic-files-map>\
2025 \\[anything-generic-file-help]:Help, \
2026 \\<anything-map>\
2027 \\[anything-select-action]:Acts,\
2028 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2029 \\[anything-select-3rd-action]:NthAct,\
2030 \\[anything-send-bug-report-from-anything]:BugReport."
2031 "String displayed in mode-line in Locate.")
2033 (defvar anything-grep-mode-line-string
2034 "\\<anything-c-grep-map>\
2035 \\[anything-grep-help]:Help,\
2036 \\<anything-map>\
2037 \\[anything-select-action]:Acts,\
2038 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2039 \\[anything-select-3rd-action]:NthAct,\
2040 \\[anything-send-bug-report-from-anything]:BugReport."
2041 "String displayed in mode-line in `anything-do-grep'.")
2043 (defvar anything-pdfgrep-mode-line-string
2044 "\\<anything-c-pdfgrep-map>\
2045 \\[anything-pdfgrep-help]:Help,\
2046 \\<anything-map>\
2047 \\[anything-select-action]:Acts,\
2048 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2049 \\[anything-select-3rd-action]:NthAct,\
2050 \\[anything-send-bug-report-from-anything]:BugReport."
2051 "String displayed in mode-line in `anything-do-pdfgrep'.")
2053 (defvar anything-etags-mode-line-string
2054 "\\<anything-c-etags-map>\
2055 \\[anything-etags-help]:Help,\
2056 \\<anything-map>\
2057 \\[anything-select-action]:Acts,\
2058 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2059 \\[anything-select-3rd-action]:NthAct,\
2060 \\[anything-send-bug-report-from-anything]:BugReport."
2061 "String displayed in mode-line in `anything-c-etags-select'.")
2064 (defvar anything-c-ucs-mode-line-string
2065 "\\<anything-c-ucs-map>\
2066 \\[anything-c-ucs-help]:Help, \
2067 \\<anything-map>\
2068 \\[anything-select-action]:Acts,\
2069 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2070 \\[anything-select-3rd-action]:NthAct."
2071 "String displayed in mode-line in `anything-ucs'.")
2075 ;;; Utilities Functions
2078 (defun anything-ff-find-printers ()
2079 "Return a list of available printers on Unix systems."
2080 (let ((printer-list (with-temp-buffer
2081 (call-process "lpstat" nil t nil "-a")
2082 (split-string (buffer-string) "\n"))))
2083 (loop for p in printer-list
2084 for printer = (car (split-string p))
2085 when printer
2086 collect printer)))
2088 ;; Shut up byte compiler in emacs24*.
2089 (defun anything-c-switch-to-buffer (buffer-or-name)
2090 "Same as `switch-to-buffer' whithout warnings at compile time."
2091 (with-no-warnings
2092 (switch-to-buffer buffer-or-name)))
2094 (defsubst* anything-c-position (item seq &key (test 'eq))
2095 "A simple and faster replacement of CL `position'."
2096 (loop for i in seq for index from 0
2097 when (funcall test i item) return index))
2099 (defun anything-c-get-pid-from-process-name (process-name)
2100 "Get pid from running process PROCESS-NAME."
2101 (loop with process-list = (list-system-processes)
2102 for pid in process-list
2103 for process = (assoc-default 'comm (process-attributes pid))
2104 when (and process (string-match process-name process))
2105 return pid))
2107 (defun* anything-current-buffer-narrowed-p (&optional
2108 (buffer anything-current-buffer))
2109 "Check if BUFFER is narrowed.
2110 Default is `anything-current-buffer'."
2111 (with-current-buffer buffer
2112 (let ((beg (point-min))
2113 (end (point-max))
2114 (total (buffer-size)))
2115 (or (/= beg 1) (/= end (1+ total))))))
2117 (defun anything-region-active-p ()
2118 (and transient-mark-mode mark-active (/= (mark) (point))))
2120 (defun anything-goto-line (lineno)
2121 "Goto LINENO opening only outline headline if needed."
2122 (goto-char (point-min)) (forward-line (1- lineno))
2123 (when (or (eq major-mode 'org-mode)
2124 (and (boundp 'outline-minor-mode)
2125 outline-minor-mode))
2126 (require 'org) ; On some old Emacs versions org may not be loaded.
2127 (org-reveal))
2128 (anything-match-line-color-current-line) (sit-for 0.3)
2129 (anything-match-line-cleanup))
2131 (defun anything-show-this-source-only ()
2132 "Show all candidates of this source."
2133 (interactive)
2134 (setq anything-candidate-number-limit nil)
2135 (anything-set-source-filter
2136 (list (assoc-default 'name (anything-get-current-source)))))
2138 ;;;###autoload
2139 (defun anything-test-sources ()
2140 "List all anything sources for test.
2141 The output is sexps which are evaluated by \\[eval-last-sexp]."
2142 (interactive)
2143 (with-output-to-temp-buffer "*Anything Test Sources*"
2144 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2145 (apropos-internal "^anything-c-source" #'boundp))
2146 (pop-to-buffer standard-output)))
2148 (defun anything-nest (&rest same-as-anything)
2149 "Nested `anything'. If you use `anything' within `anything', use it."
2150 (with-selected-window (anything-window)
2151 (let (anything-current-position
2152 anything-current-buffer
2153 (orig-anything-buffer anything-buffer)
2154 anything-pattern
2155 anything-buffer
2156 anything-sources
2157 anything-compiled-sources
2158 anything-buffer-chars-modified-tick
2159 (anything-samewindow t)
2160 (enable-recursive-minibuffers t))
2161 (unwind-protect
2162 (apply #'anything same-as-anything)
2163 (anything-initialize-overlays orig-anything-buffer)
2164 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2166 (defun anything-displaying-source-names ()
2167 "Display sources name."
2168 (with-current-buffer anything-buffer
2169 (goto-char (point-min))
2170 (loop with pos
2171 while (setq pos (next-single-property-change (point) 'anything-header))
2172 do (goto-char pos)
2173 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2174 do (forward-line 1))))
2176 ;; [Obsolete]
2177 (defun anything-select-source ()
2178 "[OBSOLETE] Select source."
2179 (interactive)
2180 (let ((default (assoc-default 'name (anything-get-current-source)))
2181 (source-names (anything-displaying-source-names))
2182 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2183 (anything-get-sources))))
2184 (setq anything-candidate-number-limit 9999)
2185 (anything-aif
2186 (let (anything-source-filter)
2187 (anything-nest '(((name . "Anything Source")
2188 (candidates . source-names)
2189 (action . identity))
2190 ((name . "Anything Source (ALL)")
2191 (candidates . all-source-names)
2192 (action . identity)))
2193 nil "Source: " nil
2194 default "*anything select source*"))
2195 (anything-set-source-filter (list it))
2196 (anything-set-source-filter nil))))
2198 (defun anything-c-match-on-file-name (candidate)
2199 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2200 (string-match anything-pattern (file-name-nondirectory candidate)))
2202 (defun anything-c-match-on-directory-name (candidate)
2203 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2204 (anything-aif (file-name-directory candidate)
2205 (string-match anything-pattern it)))
2207 (defun anything-c-match-on-basename (candidate)
2208 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2209 (string-match anything-pattern (anything-c-basename candidate)))
2211 (defun anything-c-string-match (candidate)
2212 "Return non-nil if `anything-pattern' match CANDIDATE.
2213 The match is done with `string-match'."
2214 (string-match anything-pattern candidate))
2216 (defun anything-c-skip-entries (list regexp)
2217 "Remove entries which matches REGEXP from LIST."
2218 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2219 list))
2221 (defun anything-c-shadow-entries (list regexp)
2222 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2223 (mapcar (lambda (file)
2224 ;; Add shadow face property to boring files.
2225 (let ((face (if (facep 'file-name-shadow)
2226 'file-name-shadow
2227 ;; fall back to default on XEmacs
2228 'default)))
2229 (if (string-match regexp file)
2230 (setq file (propertize file 'face face))))
2231 file)
2232 list))
2234 (defsubst anything-c-stringify (str-or-sym)
2235 "Get string of STR-OR-SYM."
2236 (if (stringp str-or-sym)
2237 str-or-sym
2238 (symbol-name str-or-sym)))
2240 (defsubst anything-c-symbolify (str-or-sym)
2241 "Get symbol of STR-OR-SYM."
2242 (if (symbolp str-or-sym)
2243 str-or-sym
2244 (intern str-or-sym)))
2246 (defun anything-c-describe-function (func)
2247 "FUNC is symbol or string."
2248 (describe-function (anything-c-symbolify func)))
2250 (defun anything-c-describe-variable (var)
2251 "VAR is symbol or string."
2252 (describe-variable (anything-c-symbolify var)))
2254 (defun anything-c-find-function (func)
2255 "FUNC is symbol or string."
2256 (find-function (anything-c-symbolify func)))
2258 (defun anything-c-find-variable (var)
2259 "VAR is symbol or string."
2260 (find-variable (anything-c-symbolify var)))
2262 (defun anything-c-kill-new (candidate &optional replace)
2263 "CANDIDATE is symbol or string.
2264 See `kill-new' for argument REPLACE."
2265 (kill-new (anything-c-stringify candidate) replace))
2267 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2268 "Remove duplicates elements in list SEQ.
2269 This is same as `remove-duplicates' but with memoisation.
2270 It is much faster, especially in large lists.
2271 A test function can be provided with TEST argument key.
2272 Default is `eq'."
2273 (let ((cont (make-hash-table :test test)))
2274 (loop for elm in seq
2275 unless (gethash elm cont)
2276 do (puthash elm elm cont)
2277 finally return
2278 (loop for i being the hash-values in cont collect i))))
2280 (defadvice eval-defun (after anything-source-hack activate)
2281 "Allow immediate execution of anything source when evaling it.
2282 See `anything-c-enable-eval-defun-hack'."
2283 (when anything-c-enable-eval-defun-hack
2284 (let ((varsym (save-excursion
2285 (beginning-of-defun)
2286 (forward-char 1)
2287 (when (memq (read (current-buffer)) '(defvar setq))
2288 (read (current-buffer))))))
2289 (when (string-match "^anything-c-source-" (symbol-name varsym))
2290 (anything varsym)))))
2291 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2294 ;; Move this function from anything.el and redefine here
2295 ;; to avoid an unneeded defadvice.
2296 (defun anything-quit-and-find-file ()
2297 "Drop into `anything-find-files' from `anything'.
2298 If current selection is a buffer or a file, `anything-find-files'
2299 from its directory."
2300 (interactive)
2301 (anything-run-after-quit
2302 (lambda (f)
2303 (if (file-exists-p f)
2304 (anything-find-files-1 (file-name-directory f)
2305 (if anything-ff-transformer-show-only-basename
2306 (anything-c-basename f) f))
2307 (anything-find-files-1 f)))
2308 (anything-aif (get-buffer (anything-get-selection))
2309 (or (buffer-file-name it)
2310 (car (rassoc it dired-buffers))
2311 (and (with-current-buffer it
2312 (eq major-mode 'org-agenda-mode))
2313 org-directory
2314 (expand-file-name org-directory))
2315 default-directory)
2316 (let ((sel (anything-get-selection)))
2317 (if (file-exists-p sel)
2318 (expand-file-name sel)
2319 default-directory)))))
2322 (defmacro* anything-c-walk-directory (directory &key path (directories t) match)
2323 "Walk through DIRECTORY tree.
2324 PATH can be one of basename, relative, or full.
2325 DIRECTORIES when non--nil (default) return also directories names, otherwise
2326 skip directories names.
2327 MATCH match only filenames matching regexp MATCH."
2328 `(let (result
2329 (fn (case ,path
2330 (basename 'file-name-nondirectory)
2331 (relative 'file-relative-name)
2332 (full 'identity)
2333 (t 'file-name-nondirectory))))
2334 (labels ((ls-R (dir)
2335 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2336 for f in ls
2337 if (file-directory-p f)
2338 do (progn (when ,directories
2339 (push (funcall fn f) result))
2340 ;; Don't recurse in directory symlink.
2341 (unless (file-symlink-p f)
2342 (ls-R f)))
2343 else do
2344 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2345 (push (funcall fn f) result)))))
2346 (ls-R ,directory)
2347 (nreverse result))))
2349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2351 ;;; Anything regexp.
2354 (defvar anything-build-regexp-history nil)
2355 (defun anything-c-query-replace-regexp (candidate)
2356 "Query replace regexp from `anything-regexp'.
2357 With a prefix arg replace only matches surrounded by word boundaries,
2358 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2359 (let ((regexp (funcall (anything-attr 'regexp))))
2360 (apply 'query-replace-regexp
2361 (anything-c-query-replace-args regexp))))
2363 (defun anything-c-kill-regexp-as-sexp (candidate)
2364 "Kill regexp in a format usable in lisp code."
2365 (anything-c-regexp-kill-new
2366 (prin1-to-string (funcall (anything-attr 'regexp)))))
2368 (defun anything-c-kill-regexp (candidate)
2369 "Kill regexp as it is in `anything-pattern'."
2370 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2372 (defun anything-c-query-replace-args (regexp)
2373 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2374 (let ((region-only (anything-region-active-p)))
2375 (list
2376 regexp
2377 (query-replace-read-to regexp
2378 (format "Query replace %sregexp %s"
2379 (if anything-current-prefix-arg "word " "")
2380 (if region-only "in region " ""))
2382 anything-current-prefix-arg
2383 (when region-only (region-beginning))
2384 (when region-only (region-end)))))
2386 (defvar anything-c-source-regexp
2387 '((name . "Regexp Builder")
2388 (init . (lambda ()
2389 (anything-candidate-buffer anything-current-buffer)))
2390 (candidates-in-buffer)
2391 (get-line . anything-c-regexp-get-line)
2392 (persistent-action . anything-c-regexp-persistent-action)
2393 (persistent-help . "Show this line")
2394 (multiline)
2395 (delayed)
2396 (requires-pattern . 2)
2397 (mode-line . "Press TAB to select action.")
2398 (regexp . (lambda () anything-input))
2399 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
2400 ("Query Replace Regexp (C-u Not inside word.)"
2401 . anything-c-query-replace-regexp)
2402 ("Kill Regexp" . anything-c-kill-regexp)))))
2404 (defun anything-c-regexp-get-line (s e)
2405 (propertize
2406 (apply 'concat
2407 ;; Line contents
2408 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
2409 ;; subexps
2410 (loop for i from 0 to (1- (/ (length (match-data)) 2))
2411 collect (format "\n %s'%s'"
2412 (if (zerop i) "Group 0: " (format "Group %d: " i))
2413 (match-string i))))
2414 ;; match beginning
2415 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2416 ;; It is implementation problem of candidates-in-buffer.
2417 'anything-realvalue
2418 (1- s)))
2420 (defun anything-c-regexp-persistent-action (pt)
2421 (goto-char pt)
2422 (anything-persistent-highlight-point))
2424 (defun anything-c-regexp-kill-new (input)
2425 (kill-new input)
2426 (message "Killed: %s" input))
2430 ;;; Toggle all marks.
2433 ;;;###autoload
2434 (defun anything-mark-all ()
2435 "Mark all visible unmarked candidates in current source."
2436 (interactive)
2437 (with-anything-window
2438 (save-excursion
2439 (goto-char (anything-get-previous-header-pos))
2440 (anything-next-line)
2441 (let* ((next-head (anything-get-next-header-pos))
2442 (end (and next-head
2443 (save-excursion
2444 (goto-char next-head)
2445 (forward-line -1)
2446 (point))))
2447 (maxpoint (or end (point-max))))
2448 (while (< (point) maxpoint)
2449 (anything-mark-current-line)
2450 (let ((prefix (get-text-property (point-at-bol) 'display))
2451 (bn (anything-c-basename (anything-get-selection)))
2452 (src (assoc-default 'name (anything-get-current-source))))
2453 (when (and (not (anything-this-visible-mark))
2454 (not (or (string= prefix "[?]")
2455 (string= prefix "[@]"))))
2456 ;; Don't mark possibles directories ending with . or ..
2457 ;; and also autosave files/links.
2458 (unless
2459 (and (or (anything-file-completion-source-p)
2460 (equal src "Files from Current Directory"))
2461 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
2462 (anything-make-visible-mark))))
2463 (forward-line 1) (end-of-line))))
2464 (anything-mark-current-line)
2465 (message "%s candidates marked" (length anything-marked-candidates))))
2467 ;;;###autoload
2468 (defun anything-unmark-all ()
2469 "Unmark all candidates in all sources of current anything session."
2470 (interactive)
2471 (with-anything-window
2472 (let ((len (length anything-marked-candidates)))
2473 (save-excursion
2474 (anything-clear-visible-mark))
2475 (setq anything-marked-candidates nil)
2476 (anything-mark-current-line)
2477 (message "%s candidates unmarked" len))))
2479 ;;;###autoload
2480 (defun anything-toggle-all-marks ()
2481 "Toggle all marks.
2482 Mark all visible candidates of current source or unmark all candidates
2483 visible or invisible in all sources of current anything session"
2484 (interactive)
2485 (let ((marked (anything-marked-candidates)))
2486 (if (and (>= (length marked) 1)
2487 (with-anything-window anything-visible-mark-overlays))
2488 (anything-unmark-all)
2489 (anything-mark-all))))
2493 ;;; Buffers
2496 (defun anything-c-buffer-list ()
2497 "Return the list of names of buffers with boring buffers filtered out.
2498 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2499 The first buffer in the list will be the last recently used
2500 buffer that is not the current buffer."
2501 (let ((buffers (mapcar 'buffer-name (buffer-list))))
2502 (append (cdr buffers) (list (car buffers)))))
2504 (defvar anything-c-source-buffers
2505 '((name . "Buffers")
2506 (candidates . anything-c-buffer-list)
2507 (type . buffer)))
2508 ;; (anything 'anything-c-source-buffers)
2510 (defvar anything-c-source-buffer-not-found
2511 '((name . "Create buffer")
2512 (dummy)
2513 (filtered-candidate-transformer (lambda (cands source)
2514 (list anything-pattern)))
2515 (action . (lambda (candidate)
2516 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
2517 ;; (anything 'anything-c-source-buffer-not-found)
2519 ;;; Buffers-list (was buffers+)
2522 (eval-when-compile (require 'dired))
2524 (defun anything-c-highlight-buffers (buffers)
2525 (loop for i in buffers
2526 for buf = (get-buffer i)
2527 for bfname = (buffer-file-name buf)
2528 collect
2529 (cond (;; A dired buffer.
2530 (rassoc buf dired-buffers)
2531 (propertize i 'face 'anything-ff-directory
2532 'help-echo (car (rassoc buf dired-buffers))))
2533 ;; A buffer file modified somewhere outside of emacs.
2534 ((and bfname (not (file-remote-p bfname))
2535 (file-exists-p bfname)
2536 (not (verify-visited-file-modtime buf)))
2537 (propertize i 'face 'anything-buffer-saved-out
2538 'help-echo bfname))
2539 ;; A new buffer file not already saved on disk.
2540 ((and bfname (not (file-remote-p bfname))
2541 (not (verify-visited-file-modtime buf)))
2542 (propertize i 'face 'anything-buffer-not-saved
2543 'help-echo bfname))
2544 ;; A Remote buffer file modified and not saved on disk.
2545 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
2546 (let ((prefix (propertize
2547 " " 'display
2548 (propertize "@ " 'face 'anything-ff-prefix))))
2549 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
2550 'help-echo bfname)) i)))
2551 ;; A buffer file modified and not saved on disk.
2552 ((and bfname (buffer-modified-p buf))
2553 (propertize i 'face 'anything-ff-symlink
2554 'help-echo bfname))
2555 ;; A remote buffer file not modified and saved on disk.
2556 ((and bfname (file-remote-p bfname))
2557 (let ((prefix (propertize
2558 " " 'display
2559 (propertize "@ " 'face 'anything-ff-prefix))))
2560 (cons (concat prefix (propertize i 'face 'font-lock-type-face
2561 'help-echo bfname)) i)))
2562 ;; A buffer file not modified and saved on disk.
2563 (bfname
2564 (propertize i 'face 'font-lock-type-face
2565 'help-echo bfname))
2566 ;; Any non--file buffer.
2567 (t (propertize i 'face 'italic)))))
2570 (defvar anything-c-source-buffers-list
2571 '((name . "Buffers")
2572 (candidates . anything-c-buffer-list)
2573 (type . buffer)
2574 (match anything-c-buffer-match-major-mode)
2575 (diff-action . anything-buffer-toggle-diff)
2576 (revert-action . anything-buffer-revert-and-update)
2577 (save-action . anything-buffer-save-and-update)
2578 (candidate-transformer
2579 anything-c-skip-current-buffer
2580 anything-c-skip-boring-buffers
2581 anything-c-highlight-buffers)
2582 (persistent-action . anything-c-buffers-list-persistent-action)
2583 (volatile)
2584 (mode-line . anything-buffer-mode-line-string)
2585 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2586 ;; (anything 'anything-c-source-buffers-list)
2588 (defun anything-c-buffer-match-major-mode (candidate)
2589 "Match maybe buffer by major-mode.
2590 If you give a major-mode or partial major-mode,
2591 it will list all buffers of this major-mode and/or buffers with name
2592 matching this major-mode.
2593 If you add a space after major-mode and then a space,
2594 it will match all buffers of the major-mode
2595 before space matching pattern after space.
2596 If you give a pattern which doesn't match a major-mode, it will search buffer
2597 with name matching pattern."
2598 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
2599 (buf (get-buffer cand)))
2600 (when buf
2601 (with-current-buffer buf
2602 (let ((mjm (symbol-name major-mode))
2603 (split (split-string anything-pattern)))
2604 (cond ((string-match "\\s-$" anything-pattern)
2605 (string-match (car split) mjm))
2606 ((string-match "\\s-" anything-pattern)
2607 (and (string-match (car split) mjm)
2608 (string-match (cadr split) cand)))
2609 (t (or (string-match anything-pattern mjm)
2610 (string-match anything-pattern cand)))))))))
2612 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
2613 "Query replace in marked buffers.
2614 If REGEXP-FLAG is given use `query-replace-regexp'."
2615 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
2616 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
2617 (bufs (anything-marked-candidates)))
2618 (loop
2619 with replace = (query-replace-read-from prompt regexp-flag)
2620 with tostring = (unless (consp replace)
2621 (query-replace-read-to
2622 replace prompt regexp-flag))
2623 for buf in bufs
2625 (save-window-excursion
2626 (anything-c-switch-to-buffer buf)
2627 (save-excursion
2628 (let ((case-fold-search t))
2629 (goto-char (point-min))
2630 (if (consp replace)
2631 (apply fn (list (car replace) (cdr replace)))
2632 (apply fn (list replace tostring)))))))))
2634 (defun anything-c-buffer-query-replace-regexp (candidate)
2635 (anything-c-buffer-query-replace-1 'regexp))
2637 (defun anything-c-buffer-query-replace (candidate)
2638 (anything-c-buffer-query-replace-1))
2640 (defun anything-buffer-toggle-diff (candidate)
2641 "Toggle diff buffer CANDIDATE with it's file."
2642 (if (get-buffer-window "*Diff*")
2643 (kill-buffer "*Diff*")
2644 (diff-buffer-with-file (get-buffer candidate))))
2646 ;;;###autoload
2647 (defun anything-buffer-diff-persistent ()
2648 "Toggle diff buffer without quitting anything."
2649 (interactive)
2650 (anything-execute-persistent-action 'diff-action))
2652 (defun anything-buffer-revert-and-update (candidate)
2653 (let ((marked (anything-marked-candidates)))
2654 (loop for buf in marked do (anything-revert-buffer buf))
2655 (anything-force-update candidate)))
2657 ;;;###autoload
2658 (defun anything-buffer-revert-persistent ()
2659 "Revert buffer without quitting anything."
2660 (interactive)
2661 (anything-execute-persistent-action 'revert-action 'onewindow))
2663 (defun anything-buffer-save-and-update (candidate)
2664 (let ((marked (anything-marked-candidates))
2665 (enable-recursive-minibuffers t))
2666 (loop for buf in marked do
2667 (with-current-buffer (get-buffer buf)
2668 (save-buffer)))
2669 (anything-force-update candidate)))
2671 ;;;###autoload
2672 (defun anything-buffer-save-persistent ()
2673 "Save buffer without quitting anything."
2674 (interactive)
2675 (anything-execute-persistent-action 'save-action 'onewindow))
2677 ;;;###autoload
2678 (defun anything-buffer-run-kill-buffers ()
2679 "Run kill buffer action from `anything-c-source-buffers-list'."
2680 (interactive)
2681 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
2683 ;;;###autoload
2684 (defun anything-buffer-run-grep ()
2685 "Run Grep action from `anything-c-source-buffers-list'."
2686 (interactive)
2687 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
2689 ;;;###autoload
2690 (defun anything-buffer-run-zgrep ()
2691 "Run Grep action from `anything-c-source-buffers-list'."
2692 (interactive)
2693 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
2695 ;;;###autoload
2696 (defun anything-buffer-run-query-replace-regexp ()
2697 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2698 (interactive)
2699 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
2701 ;;;###autoload
2702 (defun anything-buffer-run-query-replace ()
2703 "Run Query replace action from `anything-c-source-buffers-list'."
2704 (interactive)
2705 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
2707 ;;;###autoload
2708 (defun anything-buffer-switch-other-window ()
2709 "Run switch to other window action from `anything-c-source-buffers-list'."
2710 (interactive)
2711 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
2713 ;;;###autoload
2714 (defun anything-buffer-switch-other-frame ()
2715 "Run switch to other frame action from `anything-c-source-buffers-list'."
2716 (interactive)
2717 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
2719 ;;;###autoload
2720 (defun anything-buffer-switch-to-elscreen ()
2721 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2722 (interactive)
2723 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
2725 ;;;###autoload
2726 (defun anything-buffer-run-ediff ()
2727 "Run ediff action from `anything-c-source-buffers-list'."
2728 (interactive)
2729 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
2731 (defun anything-buffer-run-ediff-merge ()
2732 "Run ediff action from `anything-c-source-buffers-list'."
2733 (interactive)
2734 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
2736 (defun anything-c-buffers-persistent-kill (buffer)
2737 "Persistent action to kill buffer."
2738 (with-current-buffer (get-buffer buffer)
2739 (if (and (buffer-modified-p)
2740 (buffer-file-name (current-buffer)))
2741 (progn
2742 (save-buffer)
2743 (kill-buffer buffer))
2744 (kill-buffer buffer)))
2745 (anything-delete-current-selection))
2747 (defun anything-c-buffers-list-persistent-action (candidate)
2748 (if current-prefix-arg
2749 (anything-c-buffers-persistent-kill candidate)
2750 (anything-c-switch-to-buffer candidate)))
2753 ;;;; <File>
2756 ;;; File name history
2757 (defvar anything-c-source-file-name-history
2758 '((name . "File Name History")
2759 (candidates . file-name-history)
2760 (match anything-c-match-on-basename)
2761 (type . file)))
2762 ;; (anything 'anything-c-source-file-name-history)
2764 ;;; Files in current dir
2767 (defvar anything-c-source-files-in-current-dir
2768 '((name . "Files from Current Directory")
2769 (candidates . (lambda ()
2770 (with-anything-current-buffer
2771 (directory-files (anything-c-current-directory)))))
2772 ;; volatile is not needed, I think.
2773 (type . file)))
2774 ;; (anything 'anything-c-source-files-in-current-dir)
2776 (defun anything-c-highlight-files (files)
2777 (loop for i in files
2778 if (file-directory-p i)
2779 collect (propertize (file-name-nondirectory i)
2780 'face 'anything-ff-directory
2781 'help-echo (expand-file-name i))
2782 else
2783 collect (propertize (file-name-nondirectory i)
2784 'face 'anything-ff-file
2785 'help-echo (expand-file-name i))))
2787 (defvar anything-c-source-files-in-current-dir+
2788 '((name . "Files from Current Directory")
2789 (candidates . (lambda ()
2790 (with-anything-current-buffer
2791 (directory-files (anything-c-current-directory) t))))
2792 (candidate-transformer anything-c-highlight-files)
2793 ;; volatile is not needed, I think.
2794 (type . file)))
2795 ;; (anything 'anything-c-source-files-in-current-dir+)
2799 ;;; Anything-find-files - The anything files browser.
2802 ;; Internal.
2803 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
2804 "*The doc that is inserted in the Name header of a find-files or dired source.")
2805 (defvar anything-ff-auto-update-flag nil
2806 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2807 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2808 (defvar anything-ff-last-expanded nil
2809 "Store last expanded directory or file.")
2810 (defvar anything-ff-default-directory nil)
2811 (defvar anything-ff-history nil)
2812 (defvar anything-ff-cand-to-mark nil)
2815 (defvar anything-c-source-find-files
2816 `((name . "Find Files")
2817 (header-name . (lambda (name)
2818 (concat name anything-c-find-files-doc-header)))
2819 ;; It is needed for filenames with capital letters
2820 (disable-shortcuts)
2821 (init . (lambda ()
2822 (setq anything-ff-auto-update-flag
2823 anything-ff-auto-update-initial-value)))
2824 (candidates . anything-find-files-get-candidates)
2825 (filtered-candidate-transformer anything-c-find-files-transformer)
2826 (image-action1 . anything-ff-rotate-image-left)
2827 (image-action2 . anything-ff-rotate-image-right)
2828 (toggle-basename . anything-ff-toggle-basename)
2829 (properties-action . anything-ff-properties)
2830 (toggle-auto-update . anything-ff-toggle-auto-update)
2831 (kill-buffer-fname . anything-ff-kill-buffer-fname)
2832 ;(quick-delete . anything-ff-quick-delete)
2833 (persistent-action . anything-find-files-persistent-action)
2834 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2835 (mode-line . anything-ff-mode-line-string)
2836 (volatile)
2837 (candidate-number-limit . 9999)
2838 (action-transformer . anything-find-files-action-transformer)
2839 (action
2840 . ,(delq
2842 `(("Find File" . anything-c-find-file-or-marked)
2843 ("Find file in Dired" . anything-c-point-file-in-dired)
2844 ,(and (locate-library "elscreen")
2845 '("Find file in Elscreen" . anything-elscreen-find-file))
2846 ,(and (locate-library "popwin")
2847 '("Find file in popup window" . popwin:find-file))
2848 ("Checksum File" . anything-ff-checksum)
2849 ("Complete at point `M-tab'"
2850 . anything-c-insert-file-name-completion-at-point)
2851 ("Open file externally `C-c C-x, C-u to choose'"
2852 . anything-c-open-file-externally)
2853 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
2854 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
2855 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
2856 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
2857 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2858 . anything-find-files-eshell-command-on-file)
2859 ("Find file as root" . anything-find-file-as-root)
2860 ("Find file in hex dump" . hexl-find-file)
2861 ("Ediff File `C-='" . anything-find-files-ediff-files)
2862 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
2863 ("Delete File(s) `M-D'" . anything-delete-marked-files)
2864 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
2865 ("Copy file(s) Async" . anything-ff-copy-async)
2866 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
2867 ("Serial rename files" . anything-ff-serial-rename)
2868 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
2869 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
2870 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
2871 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
2872 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
2873 ("Find file other window `C-o'" . find-file-other-window)
2874 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
2875 ("Find file other frame `C-c C-o'" . find-file-other-frame)
2876 ("Print File `C-c p'" . anything-ff-print)
2877 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
2878 ;; (anything 'anything-c-source-find-files)
2880 (defun anything-find-files-set-prompt-for-action (action files)
2881 "Set prompt for action ACTION for FILES."
2882 (let ((len (length files)))
2883 (format "%s *%s File(s)\n%s to: "
2884 action len
2885 (mapconcat (lambda (f)
2886 (format "- %s\n" f)) files ""))))
2888 (defun anything-dwim-target-directory ()
2889 "Return value of `default-directory' of buffer in other window.
2890 If there is only one window return the value ot `default-directory'
2891 for current buffer."
2892 (with-anything-current-buffer
2893 (let ((num-windows (length (window-list))))
2894 (if (> num-windows 1)
2895 (save-window-excursion
2896 (other-window 1)
2897 default-directory)
2898 (car anything-ff-history)))))
2900 (defun anything-find-files-do-action (action)
2901 "Generic function for creating action from `anything-c-source-find-files'.
2902 ACTION must be an action supported by `anything-dired-action'."
2903 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
2904 (anything-marked-candidates)))
2905 (cand (anything-get-selection)) ; Target
2906 (prompt (anything-find-files-set-prompt-for-action
2907 (capitalize (symbol-name action)) ifiles))
2908 (parg anything-current-prefix-arg)
2909 (dest (anything-c-read-file-name
2910 prompt
2911 :preselect (if anything-ff-transformer-show-only-basename
2912 (anything-c-basename cand) cand)
2913 :initial-input (anything-dwim-target-directory)
2914 :history (anything-find-files-history :comp-read nil))))
2915 (anything-dired-action
2916 dest :files ifiles :action action :follow parg)))
2918 (defun anything-find-files-copy (candidate)
2919 "Copy files from `anything-find-files'."
2920 (anything-find-files-do-action 'copy))
2922 (defun anything-find-files-rename (candidate)
2923 "Rename files from `anything-find-files'."
2924 (anything-find-files-do-action 'rename))
2926 (defun anything-find-files-symlink (candidate)
2927 "Symlink files from `anything-find-files'."
2928 (anything-find-files-do-action 'symlink))
2930 (defun anything-find-files-relsymlink (candidate)
2931 "Relsymlink files from `anything-find-files'."
2932 (anything-find-files-do-action 'relsymlink))
2934 (defun anything-find-files-hardlink (candidate)
2935 "Hardlink files from `anything-find-files'."
2936 (anything-find-files-do-action 'hardlink))
2938 (defun anything-find-files-byte-compile (candidate)
2939 "Byte compile elisp files from `anything-find-files'."
2940 (let ((files (anything-marked-candidates))
2941 (parg anything-current-prefix-arg))
2942 (loop for fname in files
2943 do (byte-compile-file fname parg))))
2945 (defun anything-find-files-load-files (candidate)
2946 "Load elisp files from `anything-find-files'."
2947 (let ((files (anything-marked-candidates)))
2948 (loop for fname in files
2949 do (load fname))))
2951 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
2952 "Generic function to ediff/merge files in `anything-find-files'."
2953 (let ((bname (anything-c-basename candidate))
2954 (prompt (if merge "Ediff Merge `%s' With File: "
2955 "Ediff `%s' With File: "))
2956 (fun (if merge 'ediff-merge-files 'ediff-files)))
2957 (funcall fun
2958 candidate
2959 (condition-case quit
2960 (anything-c-read-file-name
2961 (format prompt bname))
2962 (quit ;; Hit C-g ask user to fallback to locate.
2963 (if (y-or-n-p "Search file for ediff with locate? ")
2964 (anything-c-locate-read-file-name
2965 (format prompt bname)
2966 ;; Check if -b option is available.
2967 (if (and (eq system-type 'windows-nt)
2968 (string-match "^es" anything-c-locate-command))
2969 bname
2970 (concat bname " -b")))
2971 (error "Error: Ediff Operation aborted")))))))
2973 (defun anything-find-files-ediff-files (candidate)
2974 (anything-find-files-ediff-files-1 candidate))
2976 (defun anything-find-files-ediff-merge-files (candidate)
2977 (anything-find-files-ediff-files-1 candidate 'merge))
2979 (defun anything-find-files-grep (candidate)
2980 "Default action to grep files from `anything-find-files'."
2981 (anything-do-grep-1 (anything-marked-candidates)
2982 anything-current-prefix-arg))
2984 (defun anything-ff-zgrep (candidate)
2985 "Default action to zgrep files from `anything-find-files'."
2986 (let ((prefarg anything-current-prefix-arg)
2987 (ls (anything-marked-candidates)))
2988 (anything-ff-zgrep-1 ls prefarg)))
2990 (defun anything-ff-pdfgrep (candidate)
2991 "Default action to pdfgrep files from `anything-find-files'."
2992 (let ((cands (loop for file in (anything-marked-candidates)
2993 if (or (string= (file-name-extension file) "pdf")
2994 (string= (file-name-extension file) "PDF"))
2995 collect file))
2996 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
2997 (when cands
2998 (anything-do-pdfgrep-1 cands))))
3000 (defun anything-ff-etags-select (candidate)
3001 "Default action to jump to etags from `anything-find-files'."
3002 (when (get-buffer anything-action-buffer)
3003 (kill-buffer anything-action-buffer))
3004 (let ((default-directory anything-ff-default-directory))
3005 (anything-c-etags-select anything-current-prefix-arg)))
3007 (defun anything-find-files-switch-to-hist (candidate)
3008 "Switch to anything-find-files history."
3009 (anything-find-files t))
3011 ;;; Asynchronous copy of files.
3014 (defun anything-c-copy-files-async-1 (flist dest)
3015 "Copy a list of Files FLIST to DEST asynchronously.
3016 It use another emacs process to do the job.
3017 Communication with background emacs is done with temp file
3018 `anything-c-copy-files-async-log-file'."
3019 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3020 "-Q" "--batch" "--eval"
3021 (format "(progn
3022 (require 'dired) (require 'cl)
3023 (let ((dired-recursive-copies 'always)
3024 failures success
3025 (ovw-count 0)
3026 (cpf-count 0))
3027 (dolist (f '%S)
3028 (condition-case err
3029 (let ((file-exists (file-exists-p
3030 (expand-file-name
3031 (file-name-nondirectory (directory-file-name f))
3032 (file-name-directory
3033 (file-name-as-directory \"%s\"))))))
3034 (dired-copy-file f \"%s\" t)
3035 (if file-exists
3036 (progn (push (cons \"Overwriting\" f) success)
3037 (incf ovw-count))
3038 (push (cons \"Copying\" f) success)
3039 (incf cpf-count)))
3040 (file-error
3041 (push (dired-make-relative
3042 (expand-file-name
3043 (file-name-nondirectory (directory-file-name f))
3044 (file-name-directory \"%s\")))
3045 failures))))
3046 (with-current-buffer (find-file-noselect \"%s\")
3047 (erase-buffer)
3048 (when failures
3049 (dolist (fail (reverse failures))
3050 (insert (concat \"Failed to copy \" fail \"\n\"))))
3051 (when success
3052 (loop for (a . s) in (reverse success) do
3053 (insert (concat a \" \" s \" to %s done\n\"))))
3054 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3055 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3056 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3057 (save-buffer))))"
3058 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3060 (defun anything-c-copy-async-with-log (flist dest)
3061 "Copy file list FLIST to DEST showing log.
3062 Log is send to `anything-c-copy-files-async-log-file'.
3063 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3064 (declare (special auto-revert-interval))
3065 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3066 (set (make-local-variable 'auto-revert-interval) 1)
3067 (erase-buffer)
3068 (insert "Wait copying files...\n")
3069 (sit-for 0.5) (save-buffer)
3070 (goto-char (point-max))
3071 (auto-revert-mode 1)
3072 (anything-c-copy-files-async-1 flist dest))
3074 (defun anything-ff-copy-async (candidate)
3075 "Anything find files action to copy files async.
3076 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3077 (let* ((flist (anything-marked-candidates))
3078 (dest (anything-c-read-file-name
3079 (anything-find-files-set-prompt-for-action
3080 "Copy Async" flist)
3081 :preselect candidate
3082 :initial-input (car anything-ff-history)
3083 :history (anything-find-files-history :comp-read nil))))
3084 (anything-c-copy-async-with-log flist dest)))
3086 (defvar eshell-command-aliases-list nil)
3087 (defvar anything-eshell-command-on-file-input-history nil)
3088 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3089 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3091 Basename of CANDIDATE can be a wild-card.
3092 If MAP is given run `eshell-command' on all marked files at once,
3093 Otherwise, run `eshell-command' on each marked files.
3095 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3096 `eshell-command-aliases-list' will not be loaded first time you use this."
3097 (when (or eshell-command-aliases-list
3098 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3099 (and eshell-command-aliases-list (eshell-read-aliases-list))
3100 (let* ((cand-list (anything-marked-candidates))
3101 (default-directory (or anything-ff-default-directory
3102 ;; If candidate is an url *-ff-default-directory is nil
3103 ;; so keep value of default-directory.
3104 default-directory))
3105 (command (anything-comp-read
3106 "Command: "
3107 (loop for (a . c) in eshell-command-aliases-list
3108 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3109 collect (propertize a 'help-echo (car c)) into ls
3110 finally return (sort ls 'string<))
3111 :buffer "*esh command on file*"
3112 :name "Eshell command"
3113 :input-history
3114 'anything-eshell-command-on-file-input-history))
3115 (com-value (car (assoc-default command eshell-command-aliases-list))))
3116 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3117 (> (length cand-list) 1))
3118 ;; Run eshell-command with ALL marked files as arguments.
3119 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3120 (eshell-command (format "%s %s" command mapfiles)))
3121 ;; Run eshell-command on EACH marked files.
3122 (loop
3123 for i in cand-list
3124 for bn = (anything-c-basename i)
3125 for files = (if (and bn (string-match "^\*" bn))
3126 ;; Assume if fname is a wildcard
3127 ;; cand-list have a length of 1.
3128 (mapconcat
3129 'shell-quote-argument
3130 (file-expand-wildcards i t) " ")
3131 (format "'%s'" i))
3132 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3133 ;; This allow to enter other args AFTER filename
3134 ;; i.e <command %s some_more_args>
3135 (format command files)
3136 (format "%s %s" command files))
3137 do (eshell-command com))))))
3139 (defun anything-find-files-eshell-command-on-file (candidate)
3140 "Run `eshell-command' on CANDIDATE or marked candidates.
3141 See `anything-find-files-eshell-command-on-file-1' for more info."
3142 (anything-find-files-eshell-command-on-file-1
3143 candidate anything-current-prefix-arg))
3145 (defun anything-ff-switch-to-eshell (candidate)
3146 "Switch to eshell and cd to `anything-ff-default-directory'."
3147 (flet ((cd-eshell ()
3148 (goto-char (point-max))
3149 (insert
3150 (format "cd '%s'" anything-ff-default-directory))
3151 (eshell-send-input)))
3152 (if (get-buffer "*eshell*")
3153 (progn
3154 (anything-c-switch-to-buffer "*eshell*")
3155 (cd-eshell))
3156 (call-interactively 'eshell)
3157 (cd-eshell))))
3159 (defun anything-ff-serial-rename-action (method)
3160 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3161 See `anything-ff-serial-rename-1'."
3162 (let* ((cands (anything-marked-candidates))
3163 (name (read-string "NewName: "))
3164 (start (read-number "StartAtNumber: "))
3165 (extension (read-string "Extension: " (file-name-extension (car cands))))
3166 (dir (expand-file-name
3167 (anything-c-read-file-name
3168 "Serial Rename to directory: " :initial-input
3169 (expand-file-name anything-ff-default-directory)))))
3170 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3171 (length cands) dir name))
3172 (anything-ff-serial-rename-1 dir cands name start extension :method method)
3173 (anything-find-files-1 dir))))
3175 (defun anything-ff-member-directory-p (file directory)
3176 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3177 (cur-dir (expand-file-name (file-name-as-directory directory))))
3178 (string= dir-file cur-dir)))
3180 (defun* anything-ff-serial-rename-1
3181 (directory collection new-name start-at-num extension &key (method 'rename))
3182 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3183 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3184 EXTENSION is the file extension to use, in empty prompt,
3185 reuse the original extension of file.
3186 METHOD can be one of rename, copy or symlink.
3187 Files will be renamed if they are files of current directory, otherwise they
3188 will be treated with METHOD.
3189 Default METHOD is rename."
3190 ;; Maybe remove directories selected by error in collection.
3191 (setq collection (remove-if 'file-directory-p collection))
3192 (flet ((symlink-file (file dest)
3193 (let ((flist (list file)))
3194 (anything-dired-action
3195 dest :action 'symlink :files flist))))
3197 (let* ((tmp-dir (file-name-as-directory
3198 (concat (file-name-as-directory directory)
3199 (symbol-name (gensym "tmp")))))
3200 (fn (case method
3201 (copy 'copy-file)
3202 (symlink 'symlink-file)
3203 (rename 'rename-file)
3204 (t (error "Error: Unknow method %s" method)))))
3205 (make-directory tmp-dir)
3206 (loop for i in collection
3207 for count from start-at-num
3208 for fnum = (if (< count 10) "0%s" "%s")
3209 for nname = (concat tmp-dir new-name (format fnum count)
3210 (if (not (string= extension ""))
3211 (format ".%s" (replace-regexp-in-string
3212 "[.]" "" extension))
3213 (file-name-extension i 'dot)))
3214 do (if (anything-ff-member-directory-p i directory)
3215 (rename-file i nname)
3216 (funcall fn i nname)))
3217 (loop with dirlist = (directory-files
3218 tmp-dir t directory-files-no-dot-files-regexp)
3219 for f in dirlist do
3220 (if (file-symlink-p f)
3221 (symlink-file (file-truename f)
3222 (concat (file-name-as-directory directory)
3223 (anything-c-basename f)))
3224 (rename-file f directory)))
3225 (delete-directory tmp-dir t))))
3227 (defun anything-ff-serial-rename (candidate)
3228 "Serial rename all marked files to `anything-ff-default-directory'.
3229 Rename only file of current directory, and symlink files coming from
3230 other directories.
3231 See `anything-ff-serial-rename-1'."
3232 (anything-ff-serial-rename-action 'rename))
3234 (defun anything-ff-serial-rename-by-symlink (candidate)
3235 "Serial rename all marked files to `anything-ff-default-directory'.
3236 Rename only file of current directory, and symlink files coming from
3237 other directories.
3238 See `anything-ff-serial-rename-1'."
3239 (anything-ff-serial-rename-action 'symlink))
3241 (defun anything-ff-serial-rename-by-copying (candidate)
3242 "Serial rename all marked files to `anything-ff-default-directory'.
3243 Rename only file of current directory, and copy files coming from
3244 other directories.
3245 See `anything-ff-serial-rename-1'."
3246 (anything-ff-serial-rename-action 'copy))
3248 (defun anything-c-quit-and-execute-action (action)
3249 "Quit current anything session and execute ACTION."
3250 (setq anything-saved-action action)
3251 (anything-exit-minibuffer))
3253 (defun anything-ff-toggle-auto-update (candidate)
3254 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3255 (message "[Auto expansion %s]"
3256 (if anything-ff-auto-update-flag "enabled" "disabled")))
3258 ;;;###autoload
3259 (defun anything-ff-run-toggle-auto-update ()
3260 (interactive)
3261 (anything-execute-persistent-action 'toggle-auto-update))
3263 ;;;###autoload
3264 (defun anything-ff-run-switch-to-history ()
3265 "Run Switch to history action from `anything-c-source-find-files'."
3266 (interactive)
3267 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3269 ;;;###autoload
3270 (defun anything-ff-run-grep ()
3271 "Run Grep action from `anything-c-source-find-files'."
3272 (interactive)
3273 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3275 ;;;###autoload
3276 (defun anything-ff-run-pdfgrep ()
3277 "Run Pdfgrep action from `anything-c-source-find-files'."
3278 (interactive)
3279 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3281 ;;;###autoload
3282 (defun anything-ff-run-zgrep ()
3283 "Run Grep action from `anything-c-source-find-files'."
3284 (interactive)
3285 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3287 ;;;###autoload
3288 (defun anything-ff-run-copy-file ()
3289 "Run Copy file action from `anything-c-source-find-files'."
3290 (interactive)
3291 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3293 ;;;###autoload
3294 (defun anything-ff-run-rename-file ()
3295 "Run Rename file action from `anything-c-source-find-files'."
3296 (interactive)
3297 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3299 ;;;###autoload
3300 (defun anything-ff-run-byte-compile-file ()
3301 "Run Byte compile file action from `anything-c-source-find-files'."
3302 (interactive)
3303 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3305 ;;;###autoload
3306 (defun anything-ff-run-load-file ()
3307 "Run Load file action from `anything-c-source-find-files'."
3308 (interactive)
3309 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3311 ;;;###autoload
3312 (defun anything-ff-run-eshell-command-on-file ()
3313 "Run eshell command on file action from `anything-c-source-find-files'."
3314 (interactive)
3315 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3317 ;;;###autoload
3318 (defun anything-ff-run-ediff-file ()
3319 "Run Ediff file action from `anything-c-source-find-files'."
3320 (interactive)
3321 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3323 ;;;###autoload
3324 (defun anything-ff-run-ediff-merge-file ()
3325 "Run Ediff merge file action from `anything-c-source-find-files'."
3326 (interactive)
3327 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3329 ;;;###autoload
3330 (defun anything-ff-run-symlink-file ()
3331 "Run Symlink file action from `anything-c-source-find-files'."
3332 (interactive)
3333 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3335 ;;;###autoload
3336 (defun anything-ff-run-delete-file ()
3337 "Run Delete file action from `anything-c-source-find-files'."
3338 (interactive)
3339 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3341 ;;;###autoload
3342 (defun anything-ff-run-complete-fn-at-point ()
3343 "Run complete file name action from `anything-c-source-find-files'."
3344 (interactive)
3345 (anything-c-quit-and-execute-action
3346 'anything-c-insert-file-name-completion-at-point))
3348 ;;;###autoload
3349 (defun anything-ff-run-switch-to-eshell ()
3350 "Run switch to eshell action from `anything-c-source-find-files'."
3351 (interactive)
3352 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3354 ;;;###autoload
3355 (defun anything-ff-run-switch-other-window ()
3356 "Run switch to other window action from `anything-c-source-find-files'."
3357 (interactive)
3358 (anything-c-quit-and-execute-action 'find-file-other-window))
3360 ;;;###autoload
3361 (defun anything-ff-run-switch-other-frame ()
3362 "Run switch to other frame action from `anything-c-source-find-files'."
3363 (interactive)
3364 (anything-c-quit-and-execute-action 'find-file-other-frame))
3366 ;;;###autoload
3367 (defun anything-ff-run-open-file-externally ()
3368 "Run open file externally command action from `anything-c-source-find-files'."
3369 (interactive)
3370 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3372 (defun anything-ff-locate (candidate)
3373 "Locate action function for `anything-find-files'."
3374 (let ((input (concat (anything-c-basename
3375 (expand-file-name
3376 candidate
3377 anything-ff-default-directory))
3378 ;; The locate '-b' option doesn't exists
3379 ;; in everything.
3380 (unless (and (eq system-type 'windows-nt)
3381 (string-match "^es" anything-c-locate-command))
3382 " -b")))
3383 (anything-mp-highlight-delay 0.7))
3384 (anything-locate-1 anything-current-prefix-arg input)))
3386 ;;;###autoload
3387 (defun anything-ff-run-locate ()
3388 "Run locate action from `anything-c-source-find-files'."
3389 (interactive)
3390 (anything-c-quit-and-execute-action 'anything-ff-locate))
3392 ;;;###autoload
3393 (defun anything-ff-run-gnus-attach-files ()
3394 "Run gnus attach files command action from `anything-c-source-find-files'."
3395 (interactive)
3396 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
3398 ;;;###autoload
3399 (defun anything-ff-run-etags ()
3400 "Run Etags command action from `anything-c-source-find-files'."
3401 (interactive)
3402 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
3405 (defun anything-ff-print (candidate)
3406 "Print marked files.
3407 You have to set in order
3408 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3410 e.g:
3411 \(setq lpr-command \"gtklp\"\)
3412 \(setq lpr-switches '(\"-P\")\)
3413 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3415 Same as `dired-do-print' but for anything."
3416 (let* ((file-list (anything-marked-candidates))
3417 (len (length file-list))
3418 (printer-name (if anything-ff-printer-list
3419 (anything-comp-read
3420 "Printer: " anything-ff-printer-list)
3421 printer-name))
3422 (command (read-string
3423 (format "Print *%s File(s):\n%s with: "
3425 (mapconcat
3426 (lambda (f) (format "- %s\n" f))
3427 file-list ""))
3428 (when (and lpr-command
3429 (or lpr-switches
3430 printer-name))
3431 (mapconcat 'identity
3432 (cons lpr-command
3433 (append (if (stringp lpr-switches)
3434 (list lpr-switches)
3435 lpr-switches)
3436 (list printer-name)))
3437 " "))))
3438 (file-args (mapconcat #'(lambda (x)
3439 (format "'%s'" x))
3440 file-list " "))
3441 (cmd-line (concat command " " file-args)))
3442 (if command
3443 (start-process-shell-command "anything-print" nil cmd-line)
3444 (error "Error: Please verify your printer settings in Emacs."))))
3446 ;;;###autoload
3447 (defun anything-ff-run-print-file ()
3448 "Run Print file action from `anything-c-source-find-files'."
3449 (interactive)
3450 (anything-c-quit-and-execute-action 'anything-ff-print))
3452 (defun anything-ff-checksum (file)
3453 "Calculate the checksum of FILE.
3454 Provide completion on different algorithms to use on Emacs24.
3455 On Emacs23 only 'sha1' is available.
3456 The checksum is copied to kill-ring."
3457 (let ((algo-list (and (fboundp 'secure-hash)
3458 '(md5 sha1 sha224 sha256 sha384 sha512))))
3459 (kill-new
3460 (if algo-list
3461 (secure-hash (intern
3462 (anything-comp-read
3463 "Algorithm: " algo-list))
3464 file)
3465 (sha1 (with-temp-buffer
3466 (insert-file-contents file)
3467 (buffer-string)))))
3468 (message "Checksum copied to kill-ring.")))
3470 (defun anything-ff-toggle-basename (candidate)
3471 (setq anything-ff-transformer-show-only-basename
3472 (not anything-ff-transformer-show-only-basename))
3473 (let ((target (if anything-ff-transformer-show-only-basename
3474 (anything-c-basename candidate) candidate)))
3475 (anything-force-update target)))
3477 (defun anything-ff-run-toggle-basename ()
3478 (interactive)
3479 (anything-execute-persistent-action 'toggle-basename))
3481 (defun* anything-reduce-file-name (fname level &key unix-close expand)
3482 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3483 If LEVEL is positive reduce from end else from beginning.
3484 If UNIX-CLOSE is non--nil close filename with /.
3485 If EXPAND is non--nil expand-file-name."
3486 (let* ((exp-fname (expand-file-name fname))
3487 (fname-list (split-string (if (or (string= fname "~/") expand)
3488 exp-fname fname) "/" t))
3489 (len (length fname-list))
3490 (pop-list (if (< level 0)
3491 (subseq fname-list (* level -1))
3492 (subseq fname-list 0 (- len level))))
3493 (result (mapconcat 'identity pop-list "/"))
3494 (empty (string= result "")))
3495 (when unix-close (setq result (concat result "/")))
3496 (if (string-match "^~" result)
3497 (if (string= result "~/") "~/" result)
3498 (if (< level 0)
3499 (if empty "../" (concat "../" result))
3500 (cond ((eq system-type 'windows-nt)
3501 (if empty "c:/" result))
3502 (empty "/")
3504 (concat "/" result)))))))
3506 ;; Internal
3507 (defvar anything-file-completion-sources
3508 '("Find Files" "Read File Name"
3509 "Read File Name History" "Copy Files"
3510 "Rename Files" "Symlink Files"
3511 "Hardlink Files" "Write File" "Insert File")
3512 "Sources that use the *find-files mechanism can be added here.
3513 You should not modify this yourself and know what you do if you do so.")
3515 (defun anything-file-completion-source-p ()
3516 "Test if current source is a dired or find-files source."
3517 (let ((cur-source (cdr (assoc 'name (anything-get-current-source)))))
3518 (loop for i in anything-file-completion-sources
3519 thereis (string= cur-source i))))
3521 (defun anything-find-files-down-one-level (arg)
3522 "Go down one level like unix command `cd ..'.
3523 If prefix numeric arg is given go ARG level down."
3524 (interactive "p")
3525 (when (and (anything-file-completion-source-p)
3526 (not (anything-ff-invalid-tramp-name-p)))
3527 (with-anything-window
3528 (setq anything-follow-mode nil))
3529 ;; When going to precedent level we want to be at the line
3530 ;; corresponding to actual directory, so store this info
3531 ;; in `anything-ff-last-expanded'.
3532 (if (and (not (file-directory-p anything-pattern))
3533 (file-exists-p anything-pattern))
3534 (setq anything-ff-last-expanded anything-pattern)
3535 (setq anything-ff-last-expanded anything-ff-default-directory))
3536 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3537 :unix-close t :expand t)))
3538 (anything-set-pattern new-pattern))))
3540 (defun anything-ff-retrieve-last-expanded ()
3541 "Move overlay to last visited directory `anything-ff-last-expanded'.
3542 This happen after using `anything-find-files-down-one-level',
3543 or hitting C-z on \"..\"."
3544 (when (and anything-ff-last-expanded
3545 (anything-file-completion-source-p))
3546 (let ((dirname (if anything-ff-transformer-show-only-basename
3547 (anything-c-basename
3548 (directory-file-name anything-ff-last-expanded))
3549 (directory-file-name anything-ff-last-expanded))))
3550 (with-anything-window
3551 (when (or (re-search-forward (concat dirname "$") nil t)
3552 (re-search-forward
3553 (concat anything-ff-last-expanded "$") nil t))
3554 (forward-line 0)
3555 (anything-mark-current-line)))
3556 (setq anything-ff-last-expanded nil))))
3557 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
3559 ;; Auto-update - anything-find-files auto expansion of directories.
3561 (defun anything-ff-update-when-only-one-matched ()
3562 "Expand to directory when sole completion.
3563 When only one candidate is remaining and it is a directory,
3564 expand to this directory."
3565 (when (and anything-ff-auto-update-flag
3566 (anything-file-completion-source-p)
3567 (not (anything-ff-invalid-tramp-name-p)))
3568 (let* ((history-p (string= (assoc-default
3569 'name (anything-get-current-source))
3570 "Read File Name History"))
3571 (pat (if (string-match tramp-file-name-regexp
3572 anything-pattern)
3573 (anything-create-tramp-name anything-pattern)
3574 anything-pattern))
3575 (completed-p (string= (file-name-as-directory pat)
3576 anything-ff-default-directory)))
3577 (when (and (or
3578 ;; Only one candidate remaining
3579 ;; and at least 2 char in basename.
3580 (and (<= (anything-approximate-candidate-number) 2)
3581 (>= (length (anything-c-basename anything-pattern)) 2))
3582 ;; Already completed.
3583 completed-p)
3584 (not history-p)) ; Don't try to auto complete in history.
3585 (with-anything-window
3586 (let ((cur-cand (prog2
3587 (unless completed-p
3588 ;; Only one non--existing candidate
3589 ;; and one directory candidate, move to it.
3590 (anything-next-line))
3591 (anything-get-selection))))
3592 (when (file-directory-p cur-cand)
3593 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
3594 ;; Maybe we are here because completed-p is true
3595 ;; but check this again to be sure. (Windows fix)
3596 (<= (anything-approximate-candidate-number) 2)) ; [2]
3597 ;; If after going to next line the candidate
3598 ;; is not one of "." or ".." [1]
3599 ;; and only one candidate is remaining [2],
3600 ;; assume candidate is a new directory to expand, and do it.
3601 (anything-set-pattern (file-name-as-directory cur-cand))
3602 ;; The candidate is one of "." or ".."
3603 ;; that mean we have entered the last letter of the directory name
3604 ;; in prompt, so expansion is already done, just add the "/" at end
3605 ;; of name unless anything-pattern ends with "."
3606 ;; (i.e we are writing something starting with ".")
3607 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
3608 (anything-set-pattern
3609 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3610 (expand-file-name (file-name-as-directory anything-pattern)))))
3611 (anything-check-minibuffer-input-1))))))))
3612 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
3614 ;; Allow expanding to home directory or root
3615 ;; when entering respectively "~/" or "//" at end of pattern.
3616 ;; e.g /home/thierry/labo/anything-config-qp/~/
3617 ;; will expand to "~/"
3618 ;; and /home/thierry/labo/anything-config-qp//
3619 ;; will expand to "/"
3620 (defun anything-ff-auto-expand-to-home-or-root ()
3621 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3622 This happen only in function using sources that are
3623 `anything-file-completion-source-p' compliant."
3624 (when (and (anything-file-completion-source-p)
3625 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3626 anything-pattern))
3627 (let ((match (match-string 1 anything-pattern)))
3628 (cond ((string= match "//")
3629 (if (eq system-type 'windows-nt)
3630 (setq anything-pattern "c:/")
3631 (setq anything-pattern "/")))
3632 ((string= match "/~/")
3633 (if (eq system-type 'windows-nt)
3634 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
3635 (setq anything-pattern "~/")))
3636 ((string= match "/./")
3637 (setq anything-pattern
3638 (with-anything-current-buffer
3639 (expand-file-name default-directory))))))
3640 (setq anything-ff-default-directory anything-pattern)
3641 ;; For some reasons, i must use here with-current-buffer => mini buffer
3642 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3643 (with-current-buffer (window-buffer (minibuffer-window))
3644 (delete-minibuffer-contents)
3645 (insert anything-pattern))))
3647 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
3649 (defun anything-c-point-file-in-dired (file)
3650 "Put point on filename FILE in dired buffer."
3651 (dired (file-name-directory file))
3652 (dired-goto-file file))
3654 (defun anything-create-tramp-name (fname)
3655 "Build filename for `anything-pattern' like /su:: or /sudo::."
3656 (apply #'tramp-make-tramp-file-name
3657 (loop with v = (tramp-dissect-file-name fname)
3658 for i across v collect i)))
3660 (defun* anything-ff-tramp-hostnames (&optional (pattern anything-pattern))
3661 "Get a list of hosts for tramp method found in `anything-pattern'.
3662 Argument PATTERN default to `anything-pattern', it is here only for debugging
3663 purpose."
3664 (when (string-match tramp-file-name-regexp pattern)
3665 (let ((method (match-string 1 pattern))
3666 (tn (match-string 0 pattern))
3667 (all-methods (mapcar 'car tramp-methods)))
3668 (remove-duplicates
3669 (loop for (f . h) in (tramp-get-completion-function method)
3670 append (loop for e in (funcall f (car h))
3671 for host = (and (consp e) (cadr e))
3672 when (and host (not (member host all-methods)))
3673 collect (concat tn host)))
3674 :test 'equal))))
3676 (defun anything-ff-before-action-hook-fn ()
3677 "Exit anything when user try to execute action on an invalid tramp fname."
3678 (let ((cand (anything-get-selection)))
3679 (when (and (anything-file-completion-source-p)
3680 (anything-ff-invalid-tramp-name-p cand) ; Check candidate.
3681 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3682 (error "Error: Unknow file or directory `%s'" cand))))
3683 (add-hook 'anything-before-action-hook 'anything-ff-before-action-hook-fn)
3685 (defun* anything-ff-invalid-tramp-name-p (&optional (pattern anything-pattern))
3686 "Return non--nil when PATTERN is an invalid tramp filename."
3687 (string= (anything-ff-set-pattern pattern)
3688 "Invalid tramp file name"))
3690 (defun anything-ff-set-pattern (pattern)
3691 "Handle tramp filenames in `anything-pattern'."
3692 (let ((methods (mapcar 'car tramp-methods))
3693 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3694 cur-method tramp-name)
3695 (cond ((string= pattern "") "")
3696 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern)
3697 (with-anything-current-buffer
3698 (expand-file-name default-directory)))
3699 ((string-match ".*\\(~//\\|//\\)$" pattern)
3700 (if (eq system-type 'windows-nt) "c:/" "/"))
3701 ((string-match "^~\\|.*/~/$" pattern)
3702 (let* ((home (expand-file-name (getenv "HOME"))))
3703 (replace-match home nil t pattern)))
3704 ;; Match "/method:maybe_hostname:"
3705 ((and (string-match reg pattern)
3706 (setq cur-method (match-string 1 pattern))
3707 (member cur-method methods))
3708 (setq tramp-name (anything-create-tramp-name
3709 (match-string 0 pattern)))
3710 (replace-match tramp-name nil t pattern))
3711 ;; Match "/hostname:"
3712 ((and (string-match tramp-file-name-regexp pattern)
3713 (setq cur-method (match-string 1 pattern))
3714 (and cur-method (not (member cur-method methods))))
3715 (setq tramp-name (anything-create-tramp-name
3716 (match-string 0 pattern)))
3717 (replace-match tramp-name nil t pattern))
3718 ;; Match "/method:" in this case don't try to connect.
3719 ((and (not (string-match reg pattern))
3720 (string-match tramp-file-name-regexp pattern)
3721 (member (match-string 1 pattern) methods))
3722 "Invalid tramp file name") ; Write in anything-buffer.
3723 ;; PATTERN is a directory, end it with "/".
3724 ;; This will make PATTERN not ending yet with "/"
3725 ;; candidate for `anything-ff-default-directory',
3726 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3727 ;; when descending level.
3728 ((file-directory-p pattern)
3729 (file-name-as-directory pattern))
3730 ;; Return PATTERN unchanged.
3731 (t pattern))))
3733 (defun anything-find-files-get-candidates ()
3734 "Create candidate list for `anything-c-source-find-files'."
3735 (let* ((path (anything-ff-set-pattern anything-pattern))
3736 (path-name-dir (if (file-directory-p path)
3737 (file-name-as-directory path)
3738 (file-name-directory path)))
3739 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
3740 (set-text-properties 0 (length path) nil path)
3741 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3742 ;; like that the actual value (e.g /ssh:) is passed to
3743 ;; `anything-ff-tramp-hostnames'.
3744 (unless (string= path "Invalid tramp file name")
3745 (setq anything-pattern (anything-ff-transform-fname-for-completion path)))
3746 (setq anything-ff-default-directory
3747 (if (string= anything-pattern "")
3748 (if (eq system-type 'windows-nt) "c:/" "/")
3749 (unless (string-match ffap-url-regexp path)
3750 ;; If path is an url *default-directory have to be nil.
3751 path-name-dir)))
3752 (cond ((string= path "Invalid tramp file name")
3753 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3754 (prog2
3755 ;; `anything-pattern' have not been modified yet.
3756 ;; Set it here to the value of `path' that should be now
3757 ;; "Invalid tramp file name" and set the candidates list
3758 ;; to ("Invalid tramp file name") to make `anything-pattern'
3759 ;; match single candidate "Invalid tramp file name".
3760 (setq anything-pattern path)
3761 ;; "Invalid tramp file name" is now printed
3762 ;; in `anything-buffer'.
3763 (list path))))
3764 ((or (file-regular-p path)
3765 (and (not (file-exists-p path)) (string-match "/$" path))
3766 (and ffap-url-regexp (string-match ffap-url-regexp path)))
3767 (list path))
3768 ((string= path "") (directory-files "/" t))
3769 ((and (file-directory-p path) (not (file-readable-p path)))
3770 (list (format "Opening directory: access denied, `%s'" path)))
3771 ((file-directory-p path) (directory-files path t))
3773 (append (list path) (directory-files path-name-dir t))))))
3775 (defun anything-ff-transform-fname-for-completion (fname)
3776 "Return FNAME with it's basename modified as a regexp.
3777 e.g foo => f.*o.*o .
3778 If basename contain one or more space or FNAME is a valid directory name
3779 return FNAME unchanged."
3780 (let ((bn (anything-c-basename fname)))
3781 (if (or (not anything-ff-smart-completion)
3782 (string-match "\\s-" bn)
3783 (string-match "/$" fname) ; Allow mkdir.
3784 (file-directory-p fname))
3785 fname ; Fall back to match-plugin.
3786 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
3787 (mapconcat 'identity (split-string bn "" t) ".*") bn))
3788 (concat (file-name-directory fname) bn))))
3790 (defun anything-ff-save-history ()
3791 "Store the last value of `anything-ff-default-directory' \
3792 in `anything-ff-history'."
3793 (when (and anything-ff-default-directory
3794 (anything-file-completion-source-p))
3795 (push anything-ff-default-directory anything-ff-history)))
3796 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
3798 (defun anything-ff-valid-symlink-p (file)
3799 (file-exists-p (file-truename file)))
3801 (defun anything-ff-properties (candidate)
3802 "Show file properties of CANDIDATE in a tooltip or message."
3803 (let ((type (anything-ff-attributes candidate :type t))
3804 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
3805 (if (window-system)
3806 (tooltip-show
3807 (concat
3808 (anything-c-basename candidate) ": \n"
3809 "Type: " type "\n"
3810 (when (string= type "symlink")
3811 (format "True name: '%s'\n"
3812 (cond ((string-match "^\.#" (anything-c-basename candidate))
3813 "Autosave symlink")
3814 ((anything-ff-valid-symlink-p candidate)
3815 (file-truename candidate))
3816 (t "Invalid Symlink"))))
3817 dired-line))
3818 (message dired-line) (sit-for 5))))
3820 ;;;###autoload
3821 (defun anything-ff-properties-persistent ()
3822 "Show properties without quitting anything."
3823 (interactive)
3824 (anything-execute-persistent-action 'properties-action))
3826 (defun anything-ff-kill-buffer-fname (candidate)
3827 (let* ((buf (get-file-buffer candidate))
3828 (buf-name (buffer-name buf)))
3829 (if buf
3830 (progn
3831 (kill-buffer buf) (message "Buffer `%s' killed" buf))
3832 (message "No buffer to kill"))))
3834 ;;;###autoload
3835 (defun anything-ff-persistent-delete ()
3836 "Delete current candidate without quitting."
3837 (interactive)
3838 (anything-attrset 'quick-delete 'anything-ff-quick-delete)
3839 (anything-execute-persistent-action 'quick-delete))
3841 (defun anything-ff-quick-delete (candidate)
3842 "Delete file CANDIDATE without quitting."
3843 (let ((presel (prog1 (save-excursion
3844 (anything-previous-line)
3845 (anything-get-selection))
3846 (anything-mark-current-line))))
3847 (setq presel (if (and anything-ff-transformer-show-only-basename
3848 (not (string-match-p "[.]\\{1,2\\}" presel)))
3849 (anything-c-basename presel) presel))
3850 (if anything-ff-quick-delete-dont-prompt-for-deletion
3851 (anything-c-delete-file candidate)
3852 (save-window-excursion
3853 (when (y-or-n-p (format "Really Delete file `%s'? " candidate))
3854 (anything-c-delete-file candidate))))
3855 (anything-force-update presel)))
3857 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3858 "Find file CANDIDATE or kill it's buffer if it is visible.
3859 Never kill `anything-current-buffer'.
3860 Never kill buffer modified.
3861 This is called normally on third hit of \
3862 \\<anything-map>\\[anything-execute-persistent-action]
3863 in `anything-find-files-persistent-action'."
3864 (let* ((buf (get-file-buffer candidate))
3865 (buf-name (buffer-name buf)))
3866 (if (and buf (get-buffer-window buf)
3867 (not (eq buf (get-buffer anything-current-buffer)))
3868 (not (buffer-modified-p buf)))
3869 (progn
3870 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
3871 (find-file candidate))))
3873 ;;;###autoload
3874 (defun anything-ff-run-kill-buffer-persistent ()
3875 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3876 (interactive)
3877 (anything-execute-persistent-action 'kill-buffer-fname))
3879 (defun anything-ff-human-size (size)
3880 "Return a string showing SIZE of a file in human readable form.
3881 SIZE can be an integer or a float depending it's value.
3882 `file-attributes' will take care of that to avoid overflow error.
3883 KBSIZE if a floating point number, default value is 1024.0."
3884 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
3885 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
3886 (K (cons "K" (/ size anything-ff-default-kbsize)))
3887 (B (cons "B" size)))
3888 (loop with result = B
3889 for (a . b) in
3890 (loop for (x . y) in (list M G K B)
3891 unless (< y 1) collect (cons x y))
3892 when (< b (cdr result)) do (setq result (cons a b))
3893 finally return (if (string= (car result) "B")
3894 (format "%s" size)
3895 (format "%.1f%s" (cdr result) (car result))))))
3897 (defun* anything-ff-attributes
3898 (file &key type links uid gid access-time modif-time
3899 status size mode gid-change inode device-num dired human-size)
3900 "Easy interface for `file-attributes'."
3901 (let ((all (destructuring-bind
3902 (type links uid gid access-time modif-time
3903 status size mode gid-change inode device-num)
3904 (file-attributes file 'string)
3905 (list :type type
3906 :links links
3907 :uid uid
3908 :gid gid
3909 :access-time access-time
3910 :modif-time modif-time
3911 :status status
3912 :size size
3913 :mode mode
3914 :gid-change gid-change
3915 :inode inode
3916 :device-num device-num))))
3917 (cond (type
3918 (let ((result (getf all :type)))
3919 (cond ((stringp result)
3920 "symlink")
3921 (result "directory")
3922 (t "file"))))
3923 (links (getf all :links))
3924 (uid (getf all :uid))
3925 (gid (getf all :gid))
3926 (access-time
3927 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
3928 (modif-time
3929 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
3930 (status
3931 (format-time-string "%Y-%m-%d %R" (getf all :status)))
3932 (size (if human-size (anything-ff-human-size (getf all :size))
3933 (getf all :size)))
3934 (mode (getf all :mode))
3935 (gid-change (getf all :gid-change))
3936 (inode (getf all :inode))
3937 (device-num (getf all :device-num))
3938 (dired
3939 (concat
3940 (getf all :mode) " "
3941 (number-to-string (getf all :links)) " "
3942 (getf all :uid) ":"
3943 (getf all :gid) " "
3944 (if human-size (anything-ff-human-size (getf all :size))
3945 (int-to-string (getf all :size))) " "
3946 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
3947 (t all))))
3949 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
3950 "Return filename FNAME maybe prefixed with [?] or [@].
3951 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3952 existing filename or valid symlink and there is no need to test it.
3953 NEW-FILE when non--nil mean FNAME is a non existing file and
3954 return FNAME prefixed with [?]."
3955 (let* ((prefix-new (propertize
3956 " " 'display
3957 (propertize "[?]" 'face 'anything-ff-prefix)))
3958 (prefix-url (propertize
3959 " " 'display
3960 (propertize "[@]" 'face 'anything-ff-prefix))))
3961 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
3962 ((string-match ffap-url-regexp fname)
3963 (concat prefix-url " " fname))
3964 ((or new-file (not (file-exists-p fname)))
3965 (concat prefix-new " " fname)))))
3967 (defun anything-c-find-files-transformer (files sources)
3968 "Transformer for `anything-c-source-find-files'.
3969 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3970 is non--nil."
3971 (if (and (string-match tramp-file-name-regexp anything-pattern)
3972 anything-ff-tramp-not-fancy)
3973 (if anything-ff-transformer-show-only-basename
3974 (loop for i in files collect
3975 (if (string-match "[.]\\{1,2\\}$" i)
3976 i (cons (anything-c-basename i) i)))
3977 files)
3978 (anything-ff-highlight-files files sources)))
3980 (defun anything-ff-highlight-files (files sources)
3981 "Candidate transformer for `anything-c-source-find-files' without icons."
3982 (loop for i in files
3983 for disp = (if (and anything-ff-transformer-show-only-basename
3984 (not (string-match "[.]\\{1,2\\}$" i))
3985 (not (string-match ffap-url-regexp i)))
3986 (anything-c-basename i) i)
3987 collect
3988 (cond ((and (stringp (car (file-attributes i)))
3989 (not (anything-ff-valid-symlink-p i))
3990 (not (string-match "^\.#" (anything-c-basename i))))
3991 (cons (anything-ff-prefix-filename
3992 (propertize disp 'face 'anything-ff-invalid-symlink) t)
3994 ((stringp (car (file-attributes i)))
3995 (cons (anything-ff-prefix-filename
3996 (propertize disp 'face 'anything-ff-symlink) t)
3998 ((eq t (car (file-attributes i)))
3999 (cons (anything-ff-prefix-filename
4000 (propertize disp 'face 'anything-ff-directory) t)
4002 ((file-executable-p i)
4003 (cons (anything-ff-prefix-filename
4004 (propertize disp 'face 'anything-ff-executable) t)
4006 ((file-exists-p i)
4007 (cons (anything-ff-prefix-filename
4008 (propertize disp 'face 'anything-ff-file) t)
4011 (cons (anything-ff-prefix-filename
4012 (propertize disp 'face 'anything-ff-file) nil 'new-file)
4013 i)))))
4015 (defun anything-find-files-action-transformer (actions candidate)
4016 "Action transformer for `anything-c-source-find-files'."
4017 (cond ((with-anything-current-buffer
4018 (eq major-mode 'message-mode))
4019 (append (subseq actions 0 4)
4020 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
4021 (subseq actions 4)))
4022 ((string-match (image-file-name-regexp) candidate)
4023 (append (subseq actions 0 4)
4024 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
4025 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
4026 (subseq actions 4)))
4027 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4028 (car it) candidate))
4029 (append (subseq actions 0 4)
4030 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4031 . anything-find-files-byte-compile)
4032 ("Load File(s) `M-L'" . anything-find-files-load-files))
4033 (subseq actions 4)))
4034 ((and (string-match "\.html?$" candidate)
4035 (file-exists-p candidate))
4036 (append (subseq actions 0 4)
4037 '(("Browse url file" . browse-url-of-file))
4038 (subseq actions 5)))
4039 ((or (string= (file-name-extension candidate) "pdf")
4040 (string= (file-name-extension candidate) "PDF"))
4041 (append (subseq actions 0 4)
4042 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
4043 (subseq actions 5)))
4044 (t actions)))
4046 (defun anything-ff-gnus-attach-files (candidate)
4047 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4048 (let ((flist (anything-marked-candidates)))
4049 (gnus-dired-attach flist)))
4051 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4052 "Rotate current image at NUM-ARG degrees.
4053 This is a destructive operation on FILE made by external tool mogrify."
4054 (declare (special image-dired-display-image-buffer))
4055 (setq file (file-truename file)) ; For symlinked images.
4056 ;; When FILE is not an image-file, do nothing.
4057 (when (string-match (image-file-name-regexp) file)
4058 (if (executable-find "mogrify")
4059 (progn
4060 (shell-command (format "mogrify -rotate %s %s"
4061 (or num-arg 90)
4062 (shell-quote-argument file)))
4063 (when (buffer-live-p image-dired-display-image-buffer)
4064 (kill-buffer image-dired-display-image-buffer))
4065 (image-dired-display-image file)
4066 (message nil)
4067 (display-buffer (get-buffer image-dired-display-image-buffer)))
4068 (error "mogrify not found"))))
4070 (defun anything-ff-rotate-image-left (candidate)
4071 "Rotate image file CANDIDATE left.
4072 This affect directly file CANDIDATE."
4073 (anything-ff-rotate-current-image-1 candidate -90))
4075 (defun anything-ff-rotate-image-right (candidate)
4076 "Rotate image file CANDIDATE right.
4077 This affect directly file CANDIDATE."
4078 (anything-ff-rotate-current-image-1 candidate))
4080 (defun anything-ff-rotate-left-persistent ()
4081 "Rotate image left without quitting anything."
4082 (interactive)
4083 (anything-execute-persistent-action 'image-action1))
4085 (defun anything-ff-rotate-right-persistent ()
4086 "Rotate image right without quitting anything."
4087 (interactive)
4088 (anything-execute-persistent-action 'image-action2))
4090 (defun anything-ff-exif-data (candidate)
4091 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4092 (if (and anything-ff-exif-data-program
4093 (executable-find anything-ff-exif-data-program))
4094 (shell-command-to-string (format "%s %s %s"
4095 anything-ff-exif-data-program
4096 anything-ff-exif-data-program-args
4097 candidate))
4098 (format "No program %s found to extract exif"
4099 anything-ff-exif-data-program)))
4101 (defun anything-find-files-persistent-action (candidate)
4102 "Open subtree CANDIDATE without quitting anything.
4103 If CANDIDATE is not a directory expand CANDIDATE filename.
4104 If CANDIDATE is alone, open file CANDIDATE filename.
4105 That's mean:
4106 First hit on C-z expand CANDIDATE second hit open file.
4107 If a prefix arg is given or `anything-follow-mode' is on open file."
4108 (let ((follow (buffer-local-value
4109 'anything-follow-mode
4110 (get-buffer-create anything-buffer)))
4111 (new-pattern (anything-get-selection))
4112 (num-lines-buf (with-current-buffer anything-buffer
4113 (count-lines (point-min) (point-max)))))
4114 (flet ((insert-in-minibuffer (fname)
4115 (with-selected-window (minibuffer-window)
4116 (unless follow
4117 (delete-minibuffer-contents)
4118 (set-text-properties 0 (length fname) nil fname)
4119 (insert fname)))))
4120 (cond ((and (string= (anything-ff-set-pattern anything-pattern)
4121 "Invalid tramp file name")
4122 (string-match tramp-file-name-regexp candidate))
4123 ;; First hit insert hostname and
4124 ;; second hit insert ":" and expand.
4125 (if (string= candidate anything-pattern)
4126 (insert-in-minibuffer (concat candidate ":"))
4127 (insert-in-minibuffer candidate)))
4128 (;; A symlink directory, expand it's truename.
4129 (and (file-directory-p candidate) (file-symlink-p candidate))
4130 (insert-in-minibuffer (file-name-as-directory
4131 (file-truename
4132 (expand-file-name candidate)))))
4133 ;; A directory, open it.
4134 ((file-directory-p candidate)
4135 (when (string= (anything-c-basename candidate) "..")
4136 (setq anything-ff-last-expanded anything-ff-default-directory))
4137 (insert-in-minibuffer (file-name-as-directory
4138 (expand-file-name candidate))))
4139 ;; A symlink file, expand to it's true name. (first hit)
4140 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4141 (insert-in-minibuffer (file-truename candidate)))
4142 ;; A regular file, expand it, (first hit)
4143 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4144 (insert-in-minibuffer new-pattern))
4145 ;; An image file and it is the second hit on C-z,
4146 ;; show the file in `image-dired'.
4147 ((string-match (image-file-name-regexp) candidate)
4148 (when (buffer-live-p image-dired-display-image-buffer)
4149 (kill-buffer image-dired-display-image-buffer))
4150 (image-dired-display-image candidate)
4151 (message nil)
4152 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4153 (with-current-buffer image-dired-display-image-buffer
4154 (let ((exif-data (anything-ff-exif-data candidate)))
4155 (image-dired-update-property 'help-echo exif-data))))
4156 ;; Allow browsing archive on avfs fs.
4157 ;; Assume volume is already mounted with mountavfs.
4158 ((and anything-ff-avfs-directory
4159 (string-match
4160 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4161 (file-name-directory candidate))
4162 (anything-ff-file-compressed-p candidate))
4163 (insert-in-minibuffer (concat candidate "#")))
4164 ;; On second hit we open file.
4165 ;; On Third hit we kill it's buffer maybe.
4167 (anything-ff-kill-or-find-buffer-fname candidate))))))
4169 (defun anything-ff-file-compressed-p (candidate)
4170 "Whether CANDIDATE is a compressed file or not."
4171 (member (file-name-extension candidate)
4172 anything-ff-file-compressed-list))
4174 (defun anything-c-insert-file-name-completion-at-point (candidate)
4175 "Insert file name completion at point."
4176 (with-anything-current-buffer
4177 (if buffer-read-only
4178 (error "Error: Buffer `%s' is read-only" (buffer-name))
4179 (let* ((end (point))
4180 (guess (substring-no-properties (thing-at-point 'filename)))
4181 (beg (- (point) (length guess)))
4182 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4183 (string-match-p "^[^\~]" guess))))
4184 (set-text-properties 0 (length candidate) nil candidate)
4185 (if (and guess (not (string= guess ""))
4186 (string-match-p "^~\\|/.*" guess))
4187 (progn
4188 (delete-region beg end)
4189 (insert (if full-path-p
4190 (expand-file-name candidate)
4191 (abbreviate-file-name candidate))))
4192 (error "Aborting completion: No valid file name at point"))))))
4194 (defun* anything-find-files-history (&key (comp-read t))
4195 "The `anything-find-files' history.
4196 Show the first `anything-ff-history-max-length' elements of
4197 `anything-ff-history' in an `anything-comp-read'."
4198 (let ((history (when anything-ff-history
4199 (anything-fast-remove-dups anything-ff-history
4200 :test 'equal))))
4201 (when history
4202 (setq anything-ff-history
4203 (if (>= (length history) anything-ff-history-max-length)
4204 (subseq history 0 anything-ff-history-max-length)
4205 history))
4206 (if comp-read
4207 (anything-comp-read
4208 "Switch to Directory: "
4209 anything-ff-history
4210 :name "Anything Find Files History"
4211 :must-match t)
4212 anything-ff-history))))
4214 (defun anything-find-files-1 (fname &optional preselect)
4215 "Find FNAME with `anything' completion.
4216 Like `find-file' but with `anything' support.
4217 Use it for non--interactive calls of `anything-find-files'."
4218 (when (get-buffer anything-action-buffer)
4219 (kill-buffer anything-action-buffer))
4220 (let ((anything-mp-highlight-delay nil)
4221 ;; Be sure we don't erase the precedent minibuffer if some.
4222 (anything-ff-auto-update-initial-value
4223 (not (minibuffer-window-active-p (minibuffer-window))))
4224 anything-samewindow)
4225 (anything :sources 'anything-c-source-find-files
4226 :input fname
4227 :preselect preselect
4228 :keymap anything-find-files-map
4229 :prompt "Find Files or Url: "
4230 :buffer "*Anything Find Files*")))
4233 (defun anything-find-files-initial-input (&optional input)
4234 "Return INPUT if present, otherwise try to guess it."
4235 (or (and input (expand-file-name input))
4236 (anything-find-files-input
4237 (ffap-guesser)
4238 (thing-at-point 'filename))))
4240 (defun anything-find-files-input (fap tap)
4241 "Default input of `anything-find-files'."
4242 (let* ((def-dir (anything-c-current-directory))
4243 (lib (anything-find-library-at-point))
4244 (url (anything-ff-find-url-at-point))
4245 (file-p (and fap (not (string= fap ""))
4246 (file-exists-p fap)
4247 tap (not (string= tap ""))
4248 (file-exists-p
4249 (file-name-directory (expand-file-name tap def-dir))))))
4250 (cond (lib) ; e.g we are inside a require sexp.
4251 (url) ; String at point is an hyperlink.
4252 (file-p (expand-file-name tap def-dir))
4253 (t (and (not (string= fap "")) fap)))))
4255 (defun anything-c-current-directory ()
4256 "Return current-directory name at point.
4257 Useful in dired buffers when there is inserted subdirs."
4258 (if (eq major-mode 'dired-mode)
4259 (dired-current-directory)
4260 default-directory))
4262 (defun anything-ff-find-url-at-point ()
4263 "Try to find link to an url in text-property at point."
4264 (let* ((he (get-text-property (point) 'help-echo))
4265 (ov (overlays-at (point)))
4266 (ov-he (and ov (overlay-get
4267 (car (overlays-at (point))) 'help-echo)))
4268 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4269 (nt-prop (get-text-property (point) 'nt-link)))
4270 ;; Org link.
4271 (when (and (stringp he) (string-match "^LINK: " he))
4272 (setq he (replace-match "" t t he)))
4273 (loop for i in (list he ov-he w3m-l nt-prop)
4274 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4276 (defun anything-find-library-at-point ()
4277 "Try to find library path at point.
4278 Find inside `require' and `declare-function' sexp."
4279 (require 'find-func)
4280 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4281 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4282 (sexp (and beg-sexp end-sexp
4283 (buffer-substring-no-properties
4284 (1+ beg-sexp) (1- end-sexp)))))
4285 (ignore-errors
4286 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4287 (find-library-name
4288 (replace-regexp-in-string
4289 "'\\|\)\\|\(" ""
4290 ;; If require use third arg, ignore it,
4291 ;; always use library path found in `load-path'.
4292 (second (split-string (match-string 0 sexp))))))
4293 ((and sexp (string-match-p "^declare-function" sexp))
4294 (find-library-name
4295 (replace-regexp-in-string
4296 "\"\\|ext:" ""
4297 (third (split-string sexp)))))
4298 (t nil)))))
4300 ;;; Anything completion for `write-file'.==> C-x C-w
4301 (defvar anything-c-source-write-file
4302 `((name . "Write File")
4303 (header-name . (lambda (name)
4304 (concat name anything-c-find-files-doc-header)))
4305 ;; It is needed for filenames with capital letters
4306 (disable-shortcuts)
4307 (candidates . anything-find-files-get-candidates)
4308 (filtered-candidate-transformer anything-c-find-files-transformer)
4309 (persistent-action . anything-find-files-persistent-action)
4310 (persistent-help . "Expand Candidate")
4311 (volatile)
4312 (action .
4313 (("Write File" . (lambda (candidate)
4314 (write-file candidate 'confirm)))))))
4316 ;;; Anything completion for `insert-file'.==> C-x i
4317 (defvar anything-c-source-insert-file
4318 `((name . "Insert File")
4319 (header-name . (lambda (name)
4320 (concat name anything-c-find-files-doc-header)))
4321 ;; It is needed for filenames with capital letters
4322 (disable-shortcuts)
4323 (candidates . anything-find-files-get-candidates)
4324 (filtered-candidate-transformer anything-c-find-files-transformer)
4325 (persistent-action . anything-find-files-persistent-action)
4326 (persistent-help . "Expand Candidate")
4327 (volatile)
4328 (action .
4329 (("Insert File" . (lambda (candidate)
4330 (when (y-or-n-p (format "Really insert %s in %s "
4331 candidate anything-current-buffer))
4332 (insert-file-contents candidate))))))))
4334 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4335 (defvar anything-c-source-copy-files
4336 `((name . "Copy Files")
4337 (header-name . (lambda (name)
4338 (concat name anything-c-find-files-doc-header)))
4339 ;; It is needed for filenames with capital letters
4340 (disable-shortcuts)
4341 (candidates . anything-find-files-get-candidates)
4342 (filtered-candidate-transformer anything-c-find-files-transformer)
4343 (persistent-action . anything-find-files-persistent-action)
4344 (persistent-help . "Expand Candidate")
4345 (volatile)
4346 (action .
4347 (("Copy File"
4348 . (lambda (candidate)
4349 (anything-dired-action candidate :action 'copy)))
4350 ("Copy and Follow"
4351 . (lambda (candidate)
4352 (anything-dired-action candidate :action 'copy :follow t)))))))
4355 (defvar anything-c-source-rename-files
4356 `((name . "Rename Files")
4357 (header-name . (lambda (name)
4358 (concat name anything-c-find-files-doc-header)))
4359 ;; It is needed for filenames with capital letters
4360 (disable-shortcuts)
4361 (candidates . anything-find-files-get-candidates)
4362 (filtered-candidate-transformer anything-c-find-files-transformer)
4363 (persistent-action . anything-find-files-persistent-action)
4364 (persistent-help . "Expand Candidate")
4365 (volatile)
4366 (action .
4367 (("Rename File"
4368 . (lambda (candidate)
4369 (anything-dired-action candidate :action 'rename)))
4370 ("Rename and Follow"
4371 . (lambda (candidate)
4372 (anything-dired-action candidate :action 'rename :follow t)))))))
4374 (defvar anything-c-source-symlink-files
4375 `((name . "Symlink Files")
4376 (header-name . (lambda (name)
4377 (concat name anything-c-find-files-doc-header)))
4378 ;; It is needed for filenames with capital letters
4379 (disable-shortcuts)
4380 (candidates . anything-find-files-get-candidates)
4381 (filtered-candidate-transformer anything-c-find-files-transformer)
4382 (persistent-action . anything-find-files-persistent-action)
4383 (persistent-help . "Expand Candidate")
4384 (volatile)
4385 (action
4386 . (("Symlink File"
4387 . (lambda (candidate)
4388 (anything-dired-action candidate :action 'symlink)))
4389 ("RelSymlink File"
4390 . (lambda (candidate)
4391 (anything-dired-action candidate :action 'relsymlink)))))))
4394 (defvar anything-c-source-hardlink-files
4395 `((name . "Hardlink Files")
4396 (header-name . (lambda (name)
4397 (concat name anything-c-find-files-doc-header)))
4398 ;; It is needed for filenames with capital letters
4399 (disable-shortcuts)
4400 (candidates . anything-find-files-get-candidates)
4401 (filtered-candidate-transformer anything-c-find-files-transformer)
4402 (persistent-action . anything-find-files-persistent-action)
4403 (persistent-help . "Expand Candidate")
4404 (volatile)
4405 (action
4406 . (("Hardlink File"
4407 . (lambda (candidate)
4408 (anything-dired-action candidate :action 'hardlink)))))))
4410 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4411 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4412 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4413 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4414 (let ((fn (case action
4415 ('copy 'dired-copy-file)
4416 ('rename 'dired-rename-file)
4417 ('symlink 'make-symbolic-link)
4418 ('relsymlink 'dired-make-relative-symlink)
4419 ('hardlink 'dired-hardlink)))
4420 (marker (case action
4421 ((copy rename) dired-keep-marker-copy)
4422 ('symlink dired-keep-marker-symlink)
4423 ('relsymlink dired-keep-marker-relsymlink)
4424 ('hardlink dired-keep-marker-hardlink)))
4425 (dirflag (and (= (length files) 1)
4426 (file-directory-p (car files))
4427 (not (file-directory-p candidate)))))
4428 (dired-create-files
4429 fn (symbol-name action) files
4430 ;; CANDIDATE is the destination.
4431 (if (file-directory-p candidate)
4432 ;; When CANDIDATE is a directory, build file-name in this directory.
4433 ;; Else we use CANDIDATE.
4434 #'(lambda (from)
4435 (expand-file-name (file-name-nondirectory from) candidate))
4436 #'(lambda (from) candidate))
4437 marker)
4438 (push (file-name-as-directory
4439 (if (file-directory-p candidate)
4440 candidate (file-name-directory candidate)))
4441 anything-ff-history)
4442 (when (and follow (not (get-buffer dired-log-buffer)))
4443 (let ((target (directory-file-name candidate)))
4444 (unwind-protect
4445 (progn
4446 (setq anything-ff-cand-to-mark
4447 (anything-get-dest-fnames-from-list files candidate dirflag))
4448 (if (and dirflag (eq action 'rename))
4449 (anything-find-files-1 (file-name-directory target)
4450 (if anything-ff-transformer-show-only-basename
4451 (anything-c-basename target) target))
4452 (anything-find-files-1 (expand-file-name candidate))))
4453 (setq anything-ff-cand-to-mark nil))))))
4456 (defun anything-c-basename (fname)
4457 "Resolve basename of file or directory named FNAME."
4458 (file-name-nondirectory (directory-file-name fname)))
4460 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4461 "Transform filenames of FLIST to abs of DEST-CAND.
4462 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4463 members of FLIST."
4464 ;; At this point files have been renamed/copied at destination.
4465 ;; That's mean DEST-CAND exists.
4466 (loop
4467 with dest = (expand-file-name dest-cand)
4468 for src in flist
4469 for basename-src = (anything-c-basename src)
4470 for fname = (cond (rename-dir-flag (directory-file-name dest))
4471 ((file-directory-p dest)
4472 (concat (file-name-as-directory dest) basename-src))
4473 (t dest))
4474 when (file-exists-p fname)
4475 collect fname into tmp-list
4476 finally return (sort tmp-list 'string<)))
4478 (defun anything-ff-maybe-mark-candidates ()
4479 "Mark all candidates of list `anything-ff-cand-to-mark'."
4480 (when (and (string= (assoc-default 'name (anything-get-current-source))
4481 (assoc-default 'name anything-c-source-find-files))
4482 anything-ff-cand-to-mark)
4483 (with-anything-window
4484 (while anything-ff-cand-to-mark
4485 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
4486 (progn
4487 (anything-make-visible-mark)
4488 (anything-next-line)
4489 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
4490 (anything-next-line)))
4491 (unless (anything-this-visible-mark)
4492 (anything-prev-visible-mark)))))
4494 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
4496 (defun* anything-dired-do-action-on-file (&key action)
4497 (let* ((files (dired-get-marked-files))
4498 (len (length files))
4499 (fname (if (> len 1)
4500 (format "* %d Files" len)
4501 (car files)))
4502 (source (case action
4503 ('copy 'anything-c-source-copy-files)
4504 ('rename 'anything-c-source-rename-files)
4505 ('symlink 'anything-c-source-symlink-files)
4506 ('hardlink 'anything-c-source-hardlink-files)))
4507 (prompt-fm (case action
4508 ('copy "Copy %s to: ")
4509 ('rename "Rename %s to: ")
4510 ('symlink "Symlink %s to: ")
4511 ('hardlink "Hardlink %s to: ")))
4512 (buffer (case action
4513 ('copy "*Anything Copy Files*")
4514 ('rename "*Anything Rename Files*")
4515 ('symlink "*Anything Symlink Files*")
4516 ('hardlink "*Anything Hardlink Files*")))
4517 (anything-mp-highlight-delay nil))
4518 (anything :sources source
4519 :input (or (dired-dwim-target-directory)
4520 (expand-file-name (anything-c-current-directory)))
4521 :preselect (dired-get-filename)
4522 :prompt (format prompt-fm fname)
4523 :keymap anything-c-read-file-map
4524 :buffer buffer)))
4526 ;;;###autoload
4527 (define-minor-mode anything-dired-mode ()
4528 "Enable anything completion in Dired functions.
4529 Bindings affected are C, R, S, H.
4530 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4531 :group 'anything-config
4532 :global t
4533 (if anything-dired-mode
4534 (progn
4535 (substitute-key-definition
4536 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
4537 (substitute-key-definition
4538 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
4539 (substitute-key-definition
4540 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
4541 (substitute-key-definition
4542 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
4543 (substitute-key-definition
4544 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
4545 (substitute-key-definition
4546 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
4547 (substitute-key-definition
4548 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
4549 (substitute-key-definition
4550 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
4552 (defalias 'anything-dired-bindings 'anything-dired-mode)
4554 (defun* anything-c-read-file-name (prompt
4555 &key
4556 (name "Read File Name")
4557 (initial-input (expand-file-name default-directory))
4558 (buffer "*Anything Completions*")
4559 test
4560 (preselect nil)
4561 (history nil)
4562 (marked-candidates nil)
4563 (alistp t)
4564 (persistent-action 'anything-find-files-persistent-action)
4565 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4566 "Anything `read-file-name' emulation.
4567 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4568 (when (get-buffer anything-action-buffer)
4569 (kill-buffer anything-action-buffer))
4570 (let ((anything-mp-highlight-delay nil)
4571 ;; Be sure we don't erase the underlying minibuffer if some.
4572 (anything-ff-auto-update-initial-value
4573 (not (minibuffer-window-active-p (minibuffer-window))))
4574 anything-same-window
4575 (hist (and history (anything-comp-read-get-candidates
4576 history nil nil alistp))))
4577 (flet ((action-fn (candidate)
4578 (if marked-candidates
4579 (anything-marked-candidates)
4580 (identity candidate))))
4581 (or (anything
4582 :sources
4583 `(((name . ,(format "%s History" name))
4584 (header-name . (lambda (name)
4585 (concat name anything-c-find-files-doc-header)))
4586 (disable-shortcuts)
4587 (mode-line . anything-read-file-name-mode-line-string)
4588 (candidates . hist)
4589 (persistent-action . ,persistent-action)
4590 (persistent-help . ,persistent-help)
4591 (action . ,'action-fn))
4592 ((name . ,name)
4593 (header-name . (lambda (name)
4594 (concat name anything-c-find-files-doc-header)))
4595 ;; It is needed for filenames with capital letters
4596 (disable-shortcuts)
4597 (mode-line . anything-read-file-name-mode-line-string)
4598 (candidates . (lambda ()
4599 (let ((seq (anything-find-files-get-candidates)))
4600 (if test
4601 (loop for fname in seq
4602 when (funcall test fname) collect fname)
4603 seq))))
4604 (filtered-candidate-transformer anything-c-find-files-transformer)
4605 (persistent-action . ,persistent-action)
4606 (candidate-number-limit . 9999)
4607 (toggle-auto-update . anything-ff-toggle-auto-update)
4608 (persistent-help . ,persistent-help)
4609 (volatile)
4610 (action . ,'action-fn)))
4611 :input initial-input
4612 :prompt prompt
4613 :keymap anything-c-read-file-map
4614 :resume 'noresume
4615 :buffer buffer
4616 :preselect preselect)
4617 (keyboard-quit)))))
4620 ;;; File Cache
4621 (defvar anything-c-file-cache-initialized-p nil)
4623 (defvar anything-c-file-cache-files nil)
4625 (defvar anything-c-source-file-cache
4626 '((name . "File Cache")
4627 (init
4628 . (lambda ()
4629 (require 'filecache nil t)
4630 (unless anything-c-file-cache-initialized-p
4631 (setq anything-c-file-cache-files
4632 (loop for item in file-cache-alist append
4633 (destructuring-bind (base &rest dirs) item
4634 (loop for dir in dirs collect
4635 (concat dir base)))))
4636 (defadvice file-cache-add-file (after file-cache-list activate)
4637 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
4638 (setq anything-c-file-cache-initialized-p t))))
4639 (candidates . anything-c-file-cache-files)
4640 (match anything-c-match-on-basename)
4641 (type . file)))
4642 ;; (anything 'anything-c-source-file-cache)
4645 ;;; Locate
4648 ;; NOTE for WINDOZE users:
4649 ;; You have to install Everything with his command line interface here:
4650 ;; http://www.voidtools.com/download.php
4652 (defun anything-locate-1 (&optional localdb init)
4653 "Generic function to run Locate.
4654 if LOCALDB is non--nil search and use a local locate db file.
4655 INIT is a string to use as initial input in prompt.
4656 See `anything-locate-with-db' and `anything-locate'."
4657 (anything-locate-with-db
4658 (and localdb
4659 (anything-c-read-file-name
4660 "LocateDBFiles: "
4661 :marked-candidates t
4662 :preselect anything-locate-db-file-regexp
4663 :test #'(lambda (x)
4664 (if anything-locate-db-file-regexp
4665 ;; Select only locate db files and directories
4666 ;; to allow navigation.
4667 (or (string-match
4668 anything-locate-db-file-regexp x)
4669 (file-directory-p x))
4670 x))))
4671 init))
4672 ;; (anything-locate-1 t)
4674 (defun anything-locate-with-db (&optional db initial-input)
4675 "Run locate -d DB.
4676 If DB is not given or nil use locate without -d option.
4677 Argument DB can be given as a string or list of db files.
4678 Argument INITIAL-INPUT is a string to use as initial-input.
4679 See also `anything-locate'."
4680 (when (and db (stringp db)) (setq db (list db)))
4681 (let ((anything-c-locate-command
4682 (if db
4683 (replace-regexp-in-string
4684 "locate"
4685 (format "locate -d %s"
4686 (mapconcat 'identity
4687 ;; Remove eventually
4688 ;; marked directories by error.
4689 (loop for i in db
4690 unless (file-directory-p i)
4691 collect i) ":"))
4692 anything-c-locate-command)
4693 anything-c-locate-command)))
4694 (anything :sources 'anything-c-source-locate
4695 :buffer "*anything locate*"
4696 :input initial-input
4697 :keymap anything-generic-files-map)))
4698 ;; (anything-locate-with-db "~/locate.db")
4700 (defun anything-c-locate-init ()
4701 "Initialize async locate process for `anything-c-source-locate'."
4702 (setq mode-line-format
4703 '(" " mode-line-buffer-identification " "
4704 (line-number-mode "%l") " "
4705 (:eval (propertize "(Locate Process Running) "
4706 'face '((:foreground "red"))))))
4707 (prog1
4708 (start-process-shell-command "locate-process" nil
4709 (format anything-c-locate-command
4710 anything-pattern))
4711 (set-process-sentinel (get-process "locate-process")
4712 #'(lambda (process event)
4713 (when (string= event "finished\n")
4714 (with-anything-window
4715 (force-mode-line-update nil)
4716 (anything-update-move-first-line)))))))
4718 (defvar anything-c-source-locate
4719 '((name . "Locate")
4720 (candidates . anything-c-locate-init)
4721 (type . file)
4722 (properties-action . anything-ff-properties)
4723 (requires-pattern . 3)
4724 (candidate-number-limit . 9999)
4725 (mode-line . anything-generic-file-mode-line-string)
4726 (delayed))
4727 "Find files matching the current input pattern with locate.")
4728 ;; (anything 'anything-c-source-locate)
4730 (defun anything-c-locate-read-file-name (prompt &optional init)
4731 "Search a file with locate and return it's filename.
4732 Use argument PROMPT and INIT for `anything' arguments
4733 prompt and input."
4734 (anything :sources
4735 '((name . "Locate")
4736 (candidates . anything-c-locate-init)
4737 (action . identity)
4738 (properties-action . anything-ff-properties)
4739 (requires-pattern . 3)
4740 (candidate-number-limit . 9999)
4741 (mode-line . anything-generic-file-mode-line-string)
4742 (delayed))
4743 :prompt prompt
4744 :input init
4745 :buffer "*anything locate rfn*"))
4749 ;;; Anything Incremental Grep.
4752 ;; Allow to grep incrementally with anything interface.
4753 ;; It allow also to Grep files recursively without using 'find' shell command.
4754 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4755 (defvar anything-c-grep-default-command
4756 "grep -d skip %e -niH -e %p %f"
4757 "Default grep format command for `anything-do-grep-1'.
4758 Where:
4759 '%e' format spec is for --exclude or --include grep options.
4760 '%p' format spec is for pattern.
4761 '%f' format spec is for filenames.")
4763 (defvar anything-c-grep-default-recurse-command
4764 "grep -d recurse %e -niH -e %p %f"
4765 "Default recursive grep format command for `anything-do-grep-1'.
4766 See `anything-c-grep-default-command' for format specs.")
4768 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
4770 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
4772 (defvar anything-c-grep-default-function 'anything-c-grep-init)
4774 (defvar anything-c-grep-debug-command-line nil
4775 "Turn on anything grep command-line debugging when non--nil.")
4777 (defvar anything-c-zgrep-recurse-flag nil)
4779 (defvar anything-c-grep-history nil)
4781 (defvar anything-c-grep-max-length-history 100
4782 "*Max number of elements to save in `anything-c-grep-history'.")
4784 (defun anything-c-grep-prepare-candidates (candidates)
4785 "Prepare filenames and directories CANDIDATES for grep command line."
4786 ;; If one or more candidate is a directory, search in all files
4787 ;; of this candidate (e.g /home/user/directory/*).
4788 ;; If r option is enabled search also in subdidrectories.
4789 ;; We need here to expand wildcards to support crap windows filenames
4790 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4791 (if anything-c-zgrep-recurse-flag
4792 (mapconcat 'shell-quote-argument candidates " ")
4793 (loop for i in candidates append
4794 (cond ( ;; Candidate is a directory and we use recursion.
4795 (and (file-directory-p i)
4796 (anything-c-grep-recurse-p))
4797 (list (expand-file-name i)))
4798 ;; Candidate is a directory, search in all files.
4799 ((file-directory-p i)
4800 (file-expand-wildcards
4801 (concat (file-name-as-directory (expand-file-name i)) "*") t))
4802 ;; Candidate is a file or wildcard and we use recursion, use the
4803 ;; current directory instead of candidate.
4804 ((and (or (file-exists-p i) (string-match "\*" i))
4805 (anything-c-grep-recurse-p))
4806 (list (expand-file-name
4807 (directory-file-name ; Needed for windoze.
4808 (file-name-directory (directory-file-name i))))))
4809 ;; Candidate use wildcard.
4810 ((string-match "^\*" (anything-c-basename i))
4811 (file-expand-wildcards i t))
4812 ;; Else should be one or more file.
4813 (t (list i))) into all-files
4814 finally return
4815 (mapconcat 'shell-quote-argument all-files " "))))
4817 (defun anything-c-grep-recurse-p ()
4818 "Check if `anything-do-grep-1' have switched to recursive."
4819 (let ((args (replace-regexp-in-string
4820 "grep" "" anything-c-grep-default-command)))
4821 (string-match-p "r\\|recurse" args)))
4823 (defun anything-c-grep-init (only-files &optional include zgrep)
4824 "Start an asynchronous grep process in ONLY-FILES list."
4825 (let* ((fnargs (anything-c-grep-prepare-candidates
4826 (if (file-remote-p anything-ff-default-directory)
4827 (mapcar #'(lambda (x)
4828 (file-remote-p x 'localname))
4829 only-files)
4830 only-files)))
4831 (ignored-files (mapconcat
4832 #'(lambda (x)
4833 (concat "--exclude=" (shell-quote-argument x)))
4834 grep-find-ignored-files " "))
4835 (ignored-dirs (mapconcat
4836 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4837 #'(lambda (x)
4838 (concat "--exclude-dir=" (shell-quote-argument x)))
4839 grep-find-ignored-directories " "))
4840 (exclude (if (anything-c-grep-recurse-p)
4841 (concat (or include ignored-files) " " ignored-dirs)
4842 ignored-files))
4843 (cmd-line (format-spec
4844 anything-c-grep-default-command
4845 (delq nil
4846 (list (unless zgrep (cons ?e exclude))
4847 (cons ?p (shell-quote-argument anything-pattern))
4848 (cons ?f fnargs))))))
4849 (when anything-c-grep-debug-command-line
4850 (with-current-buffer (get-buffer-create "*any grep debug*")
4851 (goto-char (point-max))
4852 (insert (concat ">>> " cmd-line "\n\n"))))
4853 (setq mode-line-format
4854 '(" " mode-line-buffer-identification " "
4855 (line-number-mode "%l") " "
4856 (:eval (when (get-process "grep-process")
4857 (propertize "[Grep Process Running] "
4858 'face 'anything-grep-running)))))
4859 (force-mode-line-update nil)
4860 (prog1
4861 (let ((default-directory anything-ff-default-directory))
4862 (start-file-process-shell-command "grep-process" nil cmd-line))
4863 (message nil)
4864 (set-process-sentinel
4865 (get-process "grep-process")
4866 #'(lambda (process event)
4867 (when (string= event "finished\n")
4868 (with-anything-window
4869 (anything-update-move-first-line)
4870 (setq mode-line-format
4871 '(" " mode-line-buffer-identification " "
4872 (line-number-mode "%l") " "
4873 (:eval (propertize
4874 (format "[Grep Process Finished - (%s results)] "
4875 (let ((nlines (1- (count-lines
4876 (point-min)
4877 (point-max)))))
4878 (if (> nlines 0) nlines 0)))
4879 'face 'anything-grep-finish))))
4880 (force-mode-line-update nil))))))))
4882 (defun anything-c-grep-action (candidate &optional where mark)
4883 "Define a default action for `anything-do-grep' on CANDIDATE.
4884 WHERE can be one of other-window, elscreen, other-frame."
4885 (let* ((split (anything-c-grep-split-line candidate))
4886 (lineno (string-to-number (nth 1 split)))
4887 (loc-fname (car split))
4888 (tramp-method (file-remote-p anything-ff-default-directory 'method))
4889 (tramp-host (file-remote-p anything-ff-default-directory 'host))
4890 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
4891 (fname (if tramp-host
4892 (concat tramp-prefix loc-fname) loc-fname)))
4893 (case where
4894 (other-window (find-file-other-window fname))
4895 (elscreen (anything-elscreen-find-file fname))
4896 (other-frame (find-file-other-frame fname))
4897 (t (find-file fname)))
4898 (anything-goto-line lineno)
4899 (when mark
4900 (set-marker (mark-marker) (point))
4901 (push-mark (point) 'nomsg))
4902 ;; Save history
4903 (unless (or anything-in-persistent-action
4904 (string= anything-pattern ""))
4905 (setq anything-c-grep-history
4906 (cons anything-pattern
4907 (delete anything-pattern anything-c-grep-history)))
4908 (when (> (length anything-c-grep-history)
4909 anything-c-grep-max-length-history)
4910 (setq anything-c-grep-history
4911 (delete (car (last anything-c-grep-history))
4912 anything-c-grep-history))))))
4914 (defun anything-c-grep-other-window (candidate)
4915 "Jump to result in other window from anything grep."
4916 (anything-c-grep-action candidate 'other-window))
4918 (defun anything-c-grep-other-frame (candidate)
4919 "Jump to result in other frame from anything grep."
4920 (anything-c-grep-action candidate 'other-frame))
4922 (defun anything-c-grep-jump-elscreen (candidate)
4923 "Jump to result in elscreen from anything grep."
4924 (anything-c-grep-action candidate 'elscreen))
4926 (defun anything-c-grep-save-results (candidate)
4927 "Save anything grep result in a `grep-mode' buffer."
4928 (let ((buf "*grep*")
4929 new-buf)
4930 (when (get-buffer buf)
4931 (setq new-buf (read-string "GrepBufferName: " buf))
4932 (loop for b in (anything-c-buffer-list)
4933 when (and (string= new-buf b)
4934 (not (y-or-n-p
4935 (format "Buffer `%s' already exists overwrite? "
4936 new-buf))))
4937 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
4938 (setq buf new-buf))
4939 (with-current-buffer (get-buffer-create buf)
4940 (let ((inhibit-read-only t))
4941 (erase-buffer)
4942 (insert "-*- mode: grep -*-\n\n"
4943 (format "Grep Results for `%s':\n\n" anything-pattern))
4944 (save-excursion
4945 (insert (with-current-buffer anything-buffer
4946 (forward-line 1)
4947 (buffer-substring (point) (point-max))))
4948 (grep-mode))))
4949 (message "Anything Grep Results saved in `%s' buffer" buf)))
4951 (defun anything-c-grep-persistent-action (candidate)
4952 "Persistent action for `anything-do-grep'.
4953 With a prefix arg record CANDIDATE in `mark-ring'."
4954 (if current-prefix-arg
4955 (anything-c-grep-action candidate nil 'mark)
4956 (anything-c-grep-action candidate))
4957 (anything-match-line-color-current-line))
4959 (defun anything-c-grep-guess-extensions (files)
4960 "Try to guess file extensions in FILES list when using grep recurse.
4961 These extensions will be added to command line with --include arg of grep."
4962 (loop
4963 with glob-list = nil
4964 with lst = (if (file-directory-p (car files))
4965 (directory-files
4966 (car files) nil
4967 directory-files-no-dot-files-regexp)
4968 files)
4969 for i in lst
4970 for ext = (file-name-extension i t)
4971 for glob = (and ext (not (string= ext ""))
4972 (concat "*" ext))
4973 unless (or (not glob)
4974 (member glob glob-list)
4975 (member glob grep-find-ignored-files))
4976 collect glob into glob-list
4977 finally return glob-list))
4979 (defun anything-do-grep-1 (only &optional recurse zgrep)
4980 "Launch grep with a list of ONLY files.
4981 When RECURSE is given use -r option of grep and prompt user
4982 to set the --include args of grep.
4983 You can give more than one arg separated by space.
4984 e.g *.el *.py *.tex.
4985 If it's empty --exclude `grep-find-ignored-files' is used instead."
4986 (let* ((anything-compile-source-functions
4987 ;; rule out anything-match-plugin because the input is one regexp.
4988 (delq 'anything-compile-source--match-plugin
4989 (copy-sequence anything-compile-source-functions)))
4990 (exts (anything-c-grep-guess-extensions only))
4991 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
4992 (include-files (and recurse (not zgrep)
4993 (read-string "OnlyExt(*.[ext]): "
4994 globs)))
4995 ;; Set `minibuffer-history' AFTER includes-files
4996 ;; to avoid storing wild-cards here.
4997 (minibuffer-history anything-c-grep-history)
4998 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
4999 (recurse anything-c-grep-default-recurse-command)
5000 (zgrep anything-c-default-zgrep-command)
5001 (t anything-c-grep-default-command)))
5002 ;; Disable match-plugin and use here own highlighting.
5003 (anything-mp-highlight-delay nil))
5004 (when include-files
5005 (setq include-files
5006 (and (not (string= include-files ""))
5007 (mapconcat #'(lambda (x)
5008 (concat "--include=" (shell-quote-argument x)))
5009 (split-string include-files) " "))))
5010 ;; When called as action from an other source e.g *-find-files
5011 ;; we have to kill action buffer.
5012 (when (get-buffer anything-action-buffer)
5013 (kill-buffer anything-action-buffer))
5014 ;; `anything-find-files' haven't already started,
5015 ;; give a default value to `anything-ff-default-directory'.
5016 (setq anything-ff-default-directory (or anything-ff-default-directory
5017 default-directory))
5018 (anything
5019 :sources
5020 `(((name . "Grep (C-c ? Help)")
5021 (candidates
5022 . (lambda ()
5023 (funcall anything-c-grep-default-function only include-files zgrep)))
5024 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5025 (candidate-number-limit . 9999)
5026 (mode-line . anything-grep-mode-line-string)
5027 (jump-persistent . anything-c-grep-persistent-action)
5028 (action . ,(delq
5030 `(("Find File" . anything-c-grep-action)
5031 ("Find file other frame" . anything-c-grep-other-frame)
5032 ,(and (locate-library "elscreen")
5033 '("Find file in Elscreen"
5034 . anything-c-grep-jump-elscreen))
5035 ("Save results in grep buffer" . anything-c-grep-save-results)
5036 ("Find file other window" . anything-c-grep-other-window))))
5037 (persistent-action . anything-c-grep-persistent-action)
5038 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5039 (requires-pattern . 3)
5040 (delayed)))
5041 :keymap anything-c-grep-map
5042 :buffer "*anything grep*")))
5044 (defun anything-ff-zgrep-1 (flist recursive)
5045 (unwind-protect
5046 (let* ((def-dir (or anything-ff-default-directory
5047 default-directory))
5048 (only (if recursive
5049 (or (gethash def-dir anything-c-rzgrep-cache)
5050 (puthash
5051 def-dir
5052 (anything-c-walk-directory
5053 def-dir
5054 :directories nil
5055 :path 'full
5056 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5057 anything-c-rzgrep-cache))
5058 flist)))
5059 (when recursive (setq anything-c-zgrep-recurse-flag t))
5060 (anything-do-grep-1 only recursive 'zgrep))
5061 (setq anything-c-zgrep-recurse-flag nil)))
5063 (defun anything-c-grep-split-line (line)
5064 "Split a grep output line."
5065 (let (beg fname lineno str)
5066 ;; Don't print until grep line is valid.
5067 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5068 (with-temp-buffer
5069 (insert line)
5070 (goto-char (point-min))
5071 (setq beg (point))
5072 (forward-char 2)
5073 (re-search-forward ":" nil t)
5074 (setq fname (buffer-substring-no-properties beg (1- (point))))
5075 (setq beg (point))
5076 (re-search-forward ":" nil t)
5077 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5078 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5079 (list fname lineno str))))
5081 (defun anything-c-grep-cand-transformer (candidates sources)
5082 "Filtered candidate transformer function for `anything-do-grep'."
5083 (loop for i in candidates
5084 for split = (and i (anything-c-grep-split-line i))
5085 for fname = (car split)
5086 for lineno = (nth 1 split)
5087 for str = (nth 2 split)
5088 when (and fname lineno str)
5089 collect
5090 (cons (concat (propertize (file-name-nondirectory fname)
5091 'face 'anything-grep-file
5092 'help-echo fname) ":"
5093 (propertize lineno 'face 'anything-grep-lineno) ":"
5094 (anything-c-grep-highlight-match str))
5095 i)))
5097 (defun anything-c-grep-highlight-match (str)
5098 "Highlight in string STR all occurences matching `anything-pattern'."
5099 (condition-case nil
5100 (with-temp-buffer
5101 (insert str)
5102 (goto-char (point-min))
5103 (while (and (re-search-forward anything-pattern nil t)
5104 (> (- (match-end 0) (match-beginning 0)) 0))
5105 (add-text-properties
5106 (match-beginning 0) (match-end 0)
5107 '(face anything-grep-match)))
5108 (buffer-string))
5109 (error nil)))
5111 ;; Go to next or precedent file (common to etags and grep).
5112 (defun anything-c-goto-next-or-prec-file (n)
5113 "Go to next or precedent candidate file in anything grep/etags buffers.
5114 If N is positive go forward otherwise go backward."
5115 (with-anything-window
5116 (let* ((current-line-list (split-string
5117 (buffer-substring
5118 (point-at-bol)
5119 (point-at-eol)) ":"))
5120 (current-fname (nth 0 current-line-list))
5121 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5122 (catch 'break
5123 (while (not (funcall fn-b-o-f))
5124 (forward-line n) ; Go forward or backward depending of n value.
5125 (unless (search-forward current-fname (point-at-eol) t)
5126 (anything-mark-current-line)
5127 (throw 'break nil))))
5128 (cond ((and (eq n 1) (eobp))
5129 (re-search-backward ".")
5130 (forward-line 0)
5131 (anything-mark-current-line))
5132 ((and (< n 1) (bobp))
5133 (forward-line 1)
5134 (anything-mark-current-line))))))
5136 ;;;###autoload
5137 (defun anything-c-goto-precedent-file ()
5138 "Go to precedent file in anything grep/etags buffers."
5139 (interactive)
5140 (anything-c-goto-next-or-prec-file -1))
5142 ;;;###autoload
5143 (defun anything-c-goto-next-file ()
5144 "Go to precedent file in anything grep/etags buffers."
5145 (interactive)
5146 (anything-c-goto-next-or-prec-file 1))
5148 ;;;###autoload
5149 (defun anything-c-grep-run-persistent-action ()
5150 "Run grep persistent action from `anything-do-grep-1'."
5151 (interactive)
5152 (anything-execute-persistent-action 'jump-persistent))
5154 ;;;###autoload
5155 (defun anything-c-grep-run-default-action ()
5156 "Run grep default action from `anything-do-grep-1'."
5157 (interactive)
5158 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5160 ;;;###autoload
5161 (defun anything-c-grep-run-other-window-action ()
5162 "Run grep goto other window action from `anything-do-grep-1'."
5163 (interactive)
5164 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5166 ;;;###autoload
5167 (defun anything-c-grep-run-save-buffer ()
5168 "Run grep save results action from `anything-do-grep-1'."
5169 (interactive)
5170 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5172 ;; Grep buffers
5173 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5174 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5175 If one of selected buffers is not a file--buffer,
5176 it is ignored and grep will run on all others file--buffers.
5177 If only one candidate is selected and it is not a file--buffer,
5178 switch to this buffer and run `anything-occur'.
5179 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5180 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5181 (cands (if prefarg
5182 (buffer-list)
5183 (anything-marked-candidates)))
5184 (win-conf (current-window-configuration))
5185 ;; Non--fname buffers are ignored.
5186 (bufs (loop for buf in cands
5187 for fname = (buffer-file-name (get-buffer buf))
5188 when fname
5189 collect (expand-file-name fname))))
5190 (if bufs
5191 (if zgrep
5192 (anything-do-grep-1 bufs nil 'zgrep)
5193 (anything-do-grep-1 bufs))
5194 ;; bufs is empty, thats mean we have only CANDIDATE
5195 ;; and it is not a buffer-filename, fallback to occur.
5196 (anything-c-switch-to-buffer candidate)
5197 (when (get-buffer anything-action-buffer)
5198 (kill-buffer anything-action-buffer))
5199 (anything-occur)
5200 (when (eq anything-exit-status 1)
5201 (set-window-configuration win-conf)))))
5203 (defun anything-c-grep-buffers (candidate)
5204 "Action to grep buffers."
5205 (anything-c-grep-buffers-1 candidate))
5207 (defun anything-c-zgrep-buffers (candidate)
5208 "Action to zgrep buffers."
5209 (anything-c-grep-buffers-1 candidate 'zgrep))
5212 ;;; Anything interface for pdfgrep
5213 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5214 ;; and a pdf-reader (e.g xpdf) are needed.
5216 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5217 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5218 (defvar anything-c-pdfgrep-debug-command-line nil)
5220 (defun anything-c-pdfgrep-init (only-files)
5221 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5222 (let* ((fnargs (anything-c-grep-prepare-candidates
5223 (if (file-remote-p anything-ff-default-directory)
5224 (mapcar #'(lambda (x)
5225 (file-remote-p x 'localname))
5226 only-files)
5227 only-files)))
5228 (cmd-line (format anything-c-pdfgrep-default-command
5229 anything-pattern
5230 fnargs)))
5231 (when anything-c-pdfgrep-debug-command-line
5232 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5233 (goto-char (point-max))
5234 (insert (concat ">>> " cmd-line "\n\n"))))
5235 (setq mode-line-format
5236 '(" " mode-line-buffer-identification " "
5237 (line-number-mode "%l") " "
5238 (:eval (propertize "(Pdfgrep Process Running) "
5239 'face '((:foreground "red"))))))
5240 (prog1
5241 (let ((default-directory anything-ff-default-directory))
5242 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5243 (message nil)
5244 (set-process-sentinel
5245 (get-process "pdfgrep-process")
5246 #'(lambda (process event)
5247 (when (string= event "finished\n")
5248 (with-anything-window
5249 (anything-update-move-first-line))
5250 (force-mode-line-update nil)))))))
5253 (defun anything-do-pdfgrep-1 (only)
5254 "Launch pdfgrep with a list of ONLY files."
5255 (unless (executable-find "pdfgrep")
5256 (error "Error: No such program `pdfgrep'."))
5257 (let* ((anything-compile-source-functions
5258 ;; rule out anything-match-plugin because the input is one regexp.
5259 (delq 'anything-compile-source--match-plugin
5260 (copy-sequence anything-compile-source-functions)))
5261 ;; Disable match-plugin and use here own highlighting.
5262 (anything-mp-highlight-delay nil))
5263 ;; When called as action from an other source e.g *-find-files
5264 ;; we have to kill action buffer.
5265 (when (get-buffer anything-action-buffer)
5266 (kill-buffer anything-action-buffer))
5267 ;; If `anything-find-files' haven't already started,
5268 ;; give a default value to `anything-ff-default-directory'.
5269 (setq anything-ff-default-directory (or anything-ff-default-directory
5270 default-directory))
5271 (anything
5272 :sources
5273 `(((name . "PdfGrep")
5274 (candidates
5275 . (lambda ()
5276 (funcall anything-c-pdfgrep-default-function only)))
5277 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5278 (candidate-number-limit . 9999)
5279 (mode-line . anything-pdfgrep-mode-line-string)
5280 (action . anything-c-pdfgrep-action)
5281 (persistent-help . "Jump to PDF Page")
5282 (requires-pattern . 3)
5283 (delayed)))
5284 :keymap anything-c-pdfgrep-map
5285 :buffer "*anything grep*")))
5288 (defun anything-c-pdfgrep-action (candidate)
5289 (let* ((split (anything-c-grep-split-line candidate))
5290 (pageno (nth 1 split))
5291 (fname (car split)))
5292 (start-file-process-shell-command
5293 "pdf-reader" nil
5294 (format-spec anything-c-pdfgrep-default-read-command
5295 (list (cons ?f fname) (cons ?p pageno))))))
5297 (defun anything-do-pdfgrep ()
5298 (interactive)
5299 (let ((only (anything-c-read-file-name
5300 "Search in file(s): "
5301 :marked-candidates t
5302 :test #'(lambda (file)
5303 (or (string= (file-name-extension file) "pdf")
5304 (string= (file-name-extension file) "PDF")
5305 (file-directory-p file)))
5306 :preselect (or (dired-get-filename nil t)
5307 (buffer-file-name (current-buffer)))))
5308 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5309 (anything-do-pdfgrep-1 only)))
5312 ;; Yank text at point.
5315 ;; Internal
5316 (defvar anything-yank-point nil)
5318 ;;;###autoload
5319 (defun anything-yank-text-at-point ()
5320 "Yank text at point in minibuffer."
5321 (interactive)
5322 (let (input)
5323 (flet ((insert-in-minibuffer (word)
5324 (with-selected-window (minibuffer-window)
5325 (let ((str anything-pattern))
5326 (delete-minibuffer-contents)
5327 (set-text-properties 0 (length word) nil word)
5328 (insert (concat str word))))))
5329 (with-anything-current-buffer
5330 ;; Start to initial point if C-w have never been hit.
5331 (unless anything-yank-point (setq anything-yank-point (point)))
5332 (and anything-yank-point (goto-char anything-yank-point))
5333 (forward-word 1)
5334 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5335 (setq anything-yank-point (point))) ; End of last forward-word
5336 (insert-in-minibuffer input))))
5338 (defun anything-reset-yank-point ()
5339 (setq anything-yank-point nil))
5341 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5342 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5345 ;;; Recentf files
5348 (defvar anything-c-source-recentf
5349 '((name . "Recentf")
5350 (init . (lambda ()
5351 (require 'recentf)
5352 (or recentf-mode (recentf-mode 1))))
5353 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5354 (candidates . recentf-list)
5355 (match anything-c-match-on-basename)
5356 (type . file))
5357 "See (info \"(emacs)File Conveniences\").
5358 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5359 ;; (anything 'anything-c-source-recentf)
5361 ;;; ffap
5362 (eval-when-compile (require 'ffap))
5363 (defvar anything-c-source-ffap-guesser
5364 '((name . "File at point")
5365 (init . (lambda () (require 'ffap)))
5366 (candidates . (lambda ()
5367 (anything-aif
5368 (with-anything-current-buffer
5369 (ffap-guesser))
5370 (list it))))
5371 (type . file)))
5372 ;; (anything 'anything-c-source-ffap-guesser)
5374 ;;; ffap with line number
5375 (defun anything-c-ffap-file-line-at-point ()
5376 "Get (FILENAME . LINENO) at point."
5377 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5378 (save-excursion
5379 (beginning-of-line)
5380 (when (and (search-forward it nil t)
5381 (looking-at ":\\([0-9]+\\)"))
5382 (cons it (string-to-number (match-string 1)))))))
5384 (defvar anything-c-ffap-line-location nil
5385 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5386 It is cleared after jumping line.")
5388 (defun anything-c-ffap-line-candidates ()
5389 (with-anything-current-buffer
5390 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5391 (when anything-c-ffap-line-location
5392 (destructuring-bind (file . line) anything-c-ffap-line-location
5393 (list (cons (format "%s (line %d)" file line) file)))))
5395 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5396 (defun anything-c-ffap-line-goto-line ()
5397 (when (car anything-c-ffap-line-location)
5398 (unwind-protect
5399 (ignore-errors
5400 (with-selected-window
5401 (get-buffer-window
5402 (get-file-buffer (car anything-c-ffap-line-location)))
5403 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5404 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5405 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5407 (defvar anything-c-source-ffap-line
5408 '((name . "File/Lineno at point")
5409 (init . (lambda () (require 'ffap)))
5410 (candidates . anything-c-ffap-line-candidates)
5411 (type . file)))
5412 ;; (anything 'anything-c-source-ffap-line)
5414 ;;; list of files gleaned from every dired buffer
5415 (defun anything-c-files-in-all-dired-candidates ()
5416 (save-excursion
5417 (mapcan
5418 (lambda (dir)
5419 (cond ((listp dir) ;filelist
5420 dir)
5421 ((equal "" (file-name-nondirectory dir)) ;dir
5422 (directory-files dir t))
5423 (t ;wildcard
5424 (file-expand-wildcards dir t))))
5425 (delq nil
5426 (mapcar (lambda (buf)
5427 (set-buffer buf)
5428 (when (eq major-mode 'dired-mode)
5429 (if (consp dired-directory)
5430 (cdr dired-directory) ;filelist
5431 dired-directory))) ;dir or wildcard
5432 (buffer-list))))))
5433 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5435 (defvar anything-c-source-files-in-all-dired
5436 '((name . "Files in all dired buffer.")
5437 (candidates . anything-c-files-in-all-dired-candidates)
5438 (type . file)))
5439 ;; (anything 'anything-c-source-files-in-all-dired)
5441 (defvar anything-c-source-filelist
5442 '((name . "FileList")
5443 (grep-candidates . anything-c-filelist-file-name)
5444 (candidate-number-limit . 200)
5445 (requires-pattern . 4)
5446 (type . file))
5447 "Source to find files instantly.
5448 See `anything-c-filelist-file-name' docstring for usage.")
5451 ;;;; <info>
5452 ;;; Info pages
5453 (defvar anything-c-info-pages nil
5454 "All info pages on system.
5455 Will be calculated the first time you invoke anything with this
5456 source.")
5458 (defun anything-c-info-pages-init ()
5459 "Collect candidates for initial Info node Top."
5460 (if anything-c-info-pages
5461 anything-c-info-pages
5462 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5463 topics)
5464 (require 'info)
5465 (with-temp-buffer
5466 (Info-find-node "dir" "top")
5467 (goto-char (point-min))
5468 (while (re-search-forward info-topic-regexp nil t)
5469 (push (match-string-no-properties 1) topics))
5470 (kill-buffer))
5471 (setq anything-c-info-pages topics))))
5473 (defvar anything-c-source-info-pages
5474 `((name . "Info Pages")
5475 (init . anything-c-info-pages-init)
5476 (candidates . anything-c-info-pages)
5477 (action . (("Show with Info" .(lambda (node-str)
5478 (info (replace-regexp-in-string
5479 "^[^:]+: " "" node-str))))))
5480 (requires-pattern . 2)))
5481 ;; (anything 'anything-c-source-info-pages)
5484 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5485 (defun anything-c-describe-attributes (anything-attribute)
5486 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5487 Same as `anything-describe-anything-attribute' but with anything completion."
5488 (interactive (list (intern
5489 (anything-comp-read
5490 "Describe anything attribute: "
5491 (mapcar 'symbol-name anything-additional-attributes)
5492 :must-match t
5493 :persistent-action
5494 #'(lambda (candidate)
5495 (with-output-to-temp-buffer "*Help*"
5496 (princ (get (intern candidate) 'anything-attrdoc))))))))
5497 (with-output-to-temp-buffer "*Help*"
5498 (princ (get anything-attribute 'anything-attrdoc))))
5501 ;;; Use info-index plug-in.
5504 ;; Note that `name' attribute is not needed since
5505 ;; `anything-c-insert-summary' have been removed.
5506 ;; Info Elisp
5507 (defvar anything-c-source-info-elisp
5508 '((name . "Info index: elisp")
5509 (info-index . "elisp")))
5510 ;; (anything 'anything-c-source-info-elisp)
5512 ;; Info-Common-Lisp
5513 (defvar anything-c-source-info-cl
5514 '((name . "Info index: cl")
5515 (info-index . "cl")))
5516 ;; (anything 'anything-c-source-info-cl)
5518 ;; Info Index org
5519 (defvar anything-c-source-info-org
5520 '((name . "Info index: org")
5521 (info-index . "org")))
5522 ;; (anything 'anything-c-source-info-org)
5524 ;; Info Index gnus
5525 (defvar anything-c-source-info-gnus
5526 '((name . "Info index: Gnus")
5527 (info-index . "gnus")))
5529 ;; Info Index ratpoison
5530 (defvar anything-c-source-info-ratpoison
5531 '((name . "Info index: ratpoison")
5532 (info-index . "ratpoison")))
5533 ;; (anything 'anything-c-source-info-ratpoison)
5535 ;; Info Index zsh
5536 (defvar anything-c-source-info-zsh
5537 '((name . "Info index: zsh")
5538 (info-index . "zsh")))
5539 ;; (anything 'anything-c-source-info-zsh)
5541 ;; Info Index bash
5542 (defvar anything-c-source-info-bash
5543 '((name . "Info index: bash")
5544 (info-index . "bash")))
5545 ;; (anything 'anything-c-source-info-bash)
5547 ;; Info Index coreutils
5548 (defvar anything-c-source-info-coreutils
5549 '((name . "Info index: coreutils")
5550 (info-index . "coreutils")))
5551 ;; (anything 'anything-c-source-info-coreutils)
5553 ;; Info Index fileutils
5554 (defvar anything-c-source-info-fileutils
5555 '((name . "Info index: fileutils")
5556 (info-index . "fileutils")))
5557 ;; (anything 'anything-c-source-info-fileutils)
5559 ;; Info Index find
5560 (defvar anything-c-source-info-find
5561 '((name . "Info index: find")
5562 (info-index . "find")))
5563 ;; (anything 'anything-c-source-info-find)
5565 ;; Info Index sh-utils
5566 (defvar anything-c-source-info-sh-utils
5567 '((name . "Info index: sh-utils")
5568 (info-index . "sh-utils")))
5569 ;; (anything 'anything-c-source-info-sh-utils)
5571 ;; Info Index textutils
5572 (defvar anything-c-source-info-textutils
5573 '((name . "Info index: textutils")
5574 (info-index . "textutils")))
5575 ;; (anything 'anything-c-source-info-textutils)
5577 ;; Info Index libc
5578 (defvar anything-c-source-info-libc
5579 '((name . "Info index: libc")
5580 (info-index . "libc")))
5581 ;; (anything 'anything-c-source-info-libc)
5583 ;; Info Index make
5584 (defvar anything-c-source-info-make
5585 '((name . "Info index: make")
5586 (info-index . "make")))
5587 ;; (anything 'anything-c-source-info-make)
5589 ;; Info Index automake
5590 (defvar anything-c-source-info-automake
5591 '((name . "Info index: automake")
5592 (info-index . "automake")))
5593 ;; (anything 'anything-c-source-info-automake)
5595 ;; Info Index autoconf
5596 (defvar anything-c-source-info-autoconf
5597 '((name . "Info index: autoconf")
5598 (info-index . "autoconf")))
5599 ;; (anything 'anything-c-source-info-autoconf)
5601 ;; Info Index emacs-lisp-intro
5602 (defvar anything-c-source-info-emacs-lisp-intro
5603 '((name . "Info index: emacs-lisp-intro")
5604 (info-index . "emacs-lisp-intro")))
5605 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5607 ;; Info Index emacs
5608 (defvar anything-c-source-info-emacs
5609 '((name . "Info index: emacs")
5610 (info-index . "emacs")))
5611 ;; (anything 'anything-c-source-info-emacs)
5613 ;; Info Index elib
5614 (defvar anything-c-source-info-elib
5615 '((name . "Info index: elib")
5616 (info-index . "elib")))
5617 ;; (anything 'anything-c-source-info-elib)
5619 ;; Info Index eieio
5620 (defvar anything-c-source-info-eieio
5621 '((name . "Info index: eieio")
5622 (info-index . "eieio")))
5623 ;; (anything 'anything-c-source-info-eieio)
5625 ;; Info Index gauche-refe
5626 (defvar anything-c-source-info-gauche-refe
5627 '((name . "Info index: gauche")
5628 (info-index . "gauche-refe")))
5629 ;; (anything 'anything-c-source-info-gauche-refe)
5631 ;; Info Index guile
5632 (defvar anything-c-source-info-guile
5633 '((name . "Info index: guile")
5634 (info-index . "guile")))
5635 ;; (anything 'anything-c-source-info-guile)
5637 ;; Info Index guile-tut
5638 (defvar anything-c-source-info-guile-tut
5639 '((name . "Info index: guile-tut")
5640 (info-index . "guile-tut")))
5641 ;; (anything 'anything-c-source-info-guile-tut)
5643 ;; Info Index goops
5644 (defvar anything-c-source-info-goops
5645 '((name . "Info index: goops")
5646 (info-index . "goops")))
5647 ;; (anything 'anything-c-source-info-goops)
5649 ;; Info Index screen
5650 (defvar anything-c-source-info-screen
5651 '((name . "Info index: screen")
5652 (info-index . "screen")
5653 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5654 ;; (anything 'anything-c-source-info-screen)
5656 ;; Info Index latex
5657 (defvar anything-c-source-info-latex
5658 '((name . "Info index: latex")
5659 (info-index . "latex")))
5660 ;; (anything 'anything-c-source-info-latex)
5662 ;; Info Index gawk
5663 (defvar anything-c-source-info-gawk
5664 '((name . "Info index: gawk")
5665 (info-index . "gawk")))
5666 ;; (anything 'anything-c-source-info-gawk)
5668 ;; Info Index sed
5669 (defvar anything-c-source-info-sed
5670 '((name . "Info index: sed")
5671 (info-index . "sed")))
5672 ;; (anything 'anything-c-source-info-sed)
5674 ;; Info Index m4
5675 (defvar anything-c-source-info-m4
5676 '((name . "Info index: m4")
5677 (info-index . "m4")))
5678 ;; (anything 'anything-c-source-info-m4)
5680 ;; Info Index wget
5681 (defvar anything-c-source-info-wget
5682 '((name . "Info index: wget")
5683 (info-index . "wget")))
5684 ;; (anything 'anything-c-source-info-wget)
5686 ;; Info Index binutils
5687 (defvar anything-c-source-info-binutils
5688 '((name . "Info index: binutils")
5689 (info-index . "binutils")))
5690 ;; (anything 'anything-c-source-info-binutils)
5692 ;; Info Index as
5693 (defvar anything-c-source-info-as
5694 '((name . "Info index: as")
5695 (info-index . "as")))
5696 ;; (anything 'anything-c-source-info-as)
5698 ;; Info Index bfd
5699 (defvar anything-c-source-info-bfd
5700 '((name . "Info index: bfd")
5701 (info-index . "bfd")))
5702 ;; (anything 'anything-c-source-info-bfd)
5704 ;; Info Index gprof
5705 (defvar anything-c-source-info-gprof
5706 '((name . "Info index: gprof")
5707 (info-index . "gprof")))
5708 ;; (anything 'anything-c-source-info-gprof)
5710 ;; Info Index ld
5711 (defvar anything-c-source-info-ld
5712 '((name . "Info index: ld")
5713 (info-index . "ld")))
5714 ;; (anything 'anything-c-source-info-ld)
5716 ;; Info Index diff
5717 (defvar anything-c-source-info-diff
5718 '((name . "Info index: diff")
5719 (info-index . "diff")))
5720 ;; (anything 'anything-c-source-info-diff)
5722 ;; Info Index flex
5723 (defvar anything-c-source-info-flex
5724 '((name . "Info index: flex")
5725 (info-index . "flex")))
5726 ;; (anything 'anything-c-source-info-flex)
5728 ;; Info Index grep
5729 (defvar anything-c-source-info-grep
5730 '((name . "Info index: grep")
5731 (info-index . "grep")))
5732 ;; (anything 'anything-c-source-info-grep)
5734 ;; Info Index gzip
5735 (defvar anything-c-source-info-gzip
5736 '((name . "Info index: gzip")
5737 (info-index . "gzip")))
5738 ;; (anything 'anything-c-source-info-gzip)
5740 ;; Info Index libtool
5741 (defvar anything-c-source-info-libtool
5742 '((name . "Info index: libtool")
5743 (info-index . "libtool")))
5744 ;; (anything 'anything-c-source-info-libtool)
5746 ;; Info Index texinfo
5747 (defvar anything-c-source-info-texinfo
5748 '((name . "Info index: texinfo")
5749 (info-index . "texinfo")))
5750 ;; (anything 'anything-c-source-info-texinfo)
5752 ;; Info Index info
5753 (defvar anything-c-source-info-info
5754 '((name . "Info index: info")
5755 (info-index . "info")))
5756 ;; (anything 'anything-c-source-info-info)
5758 ;; Info Index gdb
5759 (defvar anything-c-source-info-gdb
5760 '((name . "Info index: gdb")
5761 (info-index . "gdb")))
5762 ;; (anything 'anything-c-source-info-gdb)
5764 ;; Info Index stabs
5765 (defvar anything-c-source-info-stabs
5766 '((name . "Info index: stabs")
5767 (info-index . "stabs")))
5768 ;; (anything 'anything-c-source-info-stabs)
5770 ;; Info Index cvsbook
5771 (defvar anything-c-source-info-cvsbook
5772 '((name . "Info index: cvsbook")
5773 (info-index . "cvsbook")))
5774 ;; (anything 'anything-c-source-info-cvsbook)
5776 ;; Info Index cvs
5777 (defvar anything-c-source-info-cvs
5778 '((name . "Info index: cvs")
5779 (info-index . "cvs")))
5780 ;; (anything 'anything-c-source-info-cvs)
5782 ;; Info Index bison
5783 (defvar anything-c-source-info-bison
5784 '((name . "Info index: bison")
5785 (info-index . "bison")))
5786 ;; (anything 'anything-c-source-info-bison)
5788 ;; Info Index id-utils
5789 (defvar anything-c-source-info-id-utils
5790 '((name . "Info index: id-utils")
5791 (info-index . "id-utils")))
5792 ;; (anything 'anything-c-source-info-id-utils)
5794 ;; Info Index global
5795 (defvar anything-c-source-info-global
5796 '((name . "Info index: global")
5797 (info-index . "global")))
5798 ;; (anything 'anything-c-source-info-global)
5801 ;;; Man and woman UI
5804 (defvar anything-c-man-pages nil
5805 "All man pages on system.
5806 Will be calculated the first time you invoke anything with this
5807 source.")
5809 (defun anything-c-man-default-action (candidate)
5810 "Default action for jumping to a woman or man page from anything."
5811 (let ((wfiles (woman-file-name-all-completions candidate)))
5812 (condition-case err
5813 (if (> (length wfiles) 1)
5814 (woman-find-file
5815 (anything-comp-read
5816 "ManFile: " wfiles :must-match t))
5817 (woman candidate))
5818 ;; If woman is unable to format correctly
5819 ;; use man instead.
5820 (error (kill-buffer) ; Kill woman buffer.
5821 (let ((Man-notify-method 'meek))
5822 (Man-getpage-in-background candidate))))))
5824 (defvar anything-c-source-man-pages
5825 `((name . "Manual Pages")
5826 (candidates . (lambda ()
5827 (if anything-c-man-pages
5828 anything-c-man-pages
5829 ;; XEmacs doesn't have a woman :)
5830 (setq anything-c-man-pages
5831 (ignore-errors
5832 (require 'woman)
5833 (woman-file-name "")
5834 (sort (mapcar 'car woman-topic-all-completions)
5835 'string-lessp))))))
5836 (action ("Show with Woman" . anything-c-man-default-action))
5837 ;; Woman does not work OS X
5838 ;; http://xahlee.org/emacs/modernization_man_page.html
5839 (action-transformer . (lambda (actions candidate)
5840 (if (eq system-type 'darwin)
5841 '(("Show with Man" . man))
5842 actions)))
5843 (requires-pattern . 2)))
5844 ;; (anything 'anything-c-source-man-pages)
5847 ;;;; <Command>
5848 ;;; Anything M-x - Enhanced M-x UI
5851 ;; Another replacement of `M-x' that act exactly like the
5852 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5853 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5854 ;; anything invocation.
5855 ;; Documentation of commands available without quitting,
5856 ;; Show keybindings of commands.
5857 ;; Show history.
5858 (defvar anything-M-x-input-history nil)
5860 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
5861 "Return alist of MODE-MAP."
5862 (loop for key being the key-seqs of mode-map using (key-bindings com)
5863 for str-key = (key-description key)
5864 for ismenu = (string-match "<menu-bar>" str-key)
5865 unless ismenu collect (cons str-key com)))
5867 (defun anything-get-mode-map-from-mode (mode)
5868 "Guess the mode-map name according to MODE.
5869 Some modes don't use conventional mode-map name
5870 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5871 Return nil if no mode-map found."
5872 (loop
5873 ;; Start with a conventional mode-map name.
5874 with mode-map = (intern-soft (format "%s-map" mode))
5875 with mode-string = (symbol-name mode)
5876 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
5877 while (not mode-map)
5878 for count downfrom (length mode-name)
5879 ;; Return when no result after parsing entire string.
5880 when (eq count 0) return nil
5881 for sub-name = (substring mode-name 0 count)
5882 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
5883 finally return mode-map))
5885 (defun anything-M-x-current-mode-map-alist ()
5886 "Return mode-map alist of current `major-mode'."
5887 (let ((map (anything-get-mode-map-from-mode major-mode)))
5888 (when (and map (boundp map))
5889 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
5892 (defun anything-M-x-transformer (candidates sources)
5893 "filtered-candidate-transformer to show bindings in emacs commands.
5894 Show global bindings and local bindings according to current `major-mode'."
5895 (with-anything-current-buffer
5896 (loop
5897 with local-map = (anything-M-x-current-mode-map-alist)
5898 for cand in candidates
5899 for local-key = (car (rassq cand local-map))
5900 for key = (substitute-command-keys (format "\\[%s]" cand))
5901 collect
5902 (cons (cond ((and (string-match "^M-x" key) local-key)
5903 (format "%s (%s)"
5904 cand (propertize
5905 local-key
5906 'face 'anything-M-x-key-face)))
5907 ((string-match "^M-x" key) cand)
5908 (t (format "%s (%s)"
5909 cand (propertize
5911 'face 'anything-M-x-key-face))))
5912 cand) into ls
5913 finally return
5914 (sort ls #'(lambda (x y) (string-lessp (car x) (car y)))))))
5917 ;;; Complex command history
5920 (defvar anything-c-source-complex-command-history
5921 '((name . "Complex Command History")
5922 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
5923 (type . sexp)))
5924 ;; (anything 'anything-c-source-complex-command-history)
5926 ;;; M-x history (not related to `anything-M-x')
5929 (defvar anything-c-source-extended-command-history
5930 '((name . "Emacs Commands History")
5931 (candidates . extended-command-history)
5932 (type . command)))
5933 ;; (anything 'anything-c-source-extended-command-history)
5935 ;;; Emacs commands (Basic source for emacs commands)
5938 (defvar anything-c-source-emacs-commands
5939 '((name . "Emacs Commands")
5940 (candidates . (lambda ()
5941 (let (commands)
5942 (mapatoms (lambda (a)
5943 (if (commandp a)
5944 (push (symbol-name a)
5945 commands))))
5946 (sort commands 'string-lessp))))
5947 (type . command)
5948 (requires-pattern . 2))
5949 "Source for completing and invoking Emacs commands.
5950 A command is a function with interactive spec that can
5951 be invoked with `M-x'.
5953 To get non-interactive functions listed, use
5954 `anything-c-source-emacs-functions'.")
5955 ;; (anything 'anything-c-source-emacs-commands)
5958 ;;;; <Function>
5959 ;;; Emacs functions
5962 (defvar anything-c-source-emacs-functions
5963 '((name . "Emacs Functions")
5964 (candidates . (lambda ()
5965 (let (commands)
5966 (mapatoms (lambda (a)
5967 (if (functionp a)
5968 (push (symbol-name a) commands))))
5969 (sort commands 'string-lessp))))
5970 (type . function)
5971 (requires-pattern . 2))
5972 "Source for completing Emacs functions.")
5973 ;; (anything 'anything-c-source-emacs-functions)
5975 ;;; With abbrev expansion
5976 ;;; Similar to my exec-abbrev-cmd.el
5977 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5978 (defvar anything-c-function-abbrev-regexp nil
5979 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5980 Regexp built from the current `anything-pattern' interpreting it
5981 as abbreviation.
5982 Only for internal use.")
5984 (defun anything-c-match-function-by-abbrev (candidate)
5985 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5987 Abbreviations are made by taking the first character from each
5988 word in the function's name, e.g. \"bb\" is an abbrev for
5989 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5990 (string-match anything-c-function-abbrev-regexp candidate))
5992 (defvar anything-c-source-emacs-functions-with-abbrevs
5993 (append anything-c-source-emacs-functions
5994 '((match anything-c-match-function-by-abbrev
5995 anything-c-string-match))
5996 '((init
5997 . (lambda ()
5998 (defadvice anything-update
5999 (before anything-c-update-function-abbrev-regexp activate)
6000 (let ((char-list (append anything-pattern nil))
6001 (str "^"))
6002 (dolist (c char-list)
6003 (setq str (concat str (list c) "[^-]*-")))
6004 (setq str (concat (substring str 0 (1- (length str))) "$"))
6005 (setq anything-c-function-abbrev-regexp str))))))))
6006 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6008 (defvar anything-c-source-advice
6009 '((name . "Function Advice")
6010 (candidates . anything-c-advice-candidates)
6011 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
6012 (persistent-action . anything-c-advice-persistent-action)
6013 (multiline)
6014 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
6015 ;; (anything 'anything-c-source-advice)
6016 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6017 ;; (testadvice)
6019 (defun anything-c-advice-candidates ()
6020 (require 'advice)
6021 (loop for (fname) in ad-advised-functions
6022 for function = (intern fname)
6023 append
6024 (loop for class in ad-advice-classes append
6025 (loop for advice in (ad-get-advice-info-field function class)
6026 for enabled = (ad-advice-enabled advice)
6027 collect
6028 (cons (format
6029 "%s %s %s"
6030 (if enabled "Enabled " "Disabled")
6031 (propertize fname 'face 'font-lock-function-name-face)
6032 (ad-make-single-advice-docstring advice class nil))
6033 (list function class advice))))))
6035 (defun anything-c-advice-persistent-action (func-class-advice)
6036 (if current-prefix-arg
6037 (anything-c-advice-toggle func-class-advice)
6038 (describe-function (car func-class-advice))))
6040 (defun anything-c-advice-toggle (func-class-advice)
6041 (destructuring-bind (function class advice) func-class-advice
6042 (cond ((ad-advice-enabled advice)
6043 (ad-advice-set-enabled advice nil)
6044 (message "Disabled"))
6045 (t ;disabled
6046 (ad-advice-set-enabled advice t)
6047 (message "Enabled")))
6048 (ad-activate function)
6049 (and anything-in-persistent-action
6050 (anything-c-advice-update-current-display-string))))
6052 (defun anything-c-advice-update-current-display-string ()
6053 (anything-edit-current-selection
6054 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6055 ((looking-at "Enabled") "Disabled")))
6056 realvalue)
6057 (when newword
6058 (delete-region (point) (progn (forward-word 1) (point)))
6059 (insert newword)))))
6062 ;;;; <Variable>
6063 ;;; Emacs variables
6066 (defvar anything-c-source-emacs-variables
6067 '((name . "Emacs Variables")
6068 (candidates . (lambda ()
6069 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6070 (type . variable)
6071 (requires-pattern . 2))
6072 "Source for completing Emacs variables.")
6073 ;; (anything 'anything-c-source-emacs-variables)
6076 ;;; LaCarte
6077 (defvar anything-c-source-lacarte
6078 '((name . "Lacarte")
6079 (init . (lambda () (require 'lacarte )))
6080 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6081 (candidate-number-limit . 9999)
6082 (action . anything-c-call-interactively))
6083 "Needs lacarte.el.
6085 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6086 ;; (anything 'anything-c-source-lacarte)
6089 ;;; Bookmarks
6092 ;; Bind some faces for bookmarks.
6093 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6094 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6095 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6097 (eval-when-compile (require 'bookmark))
6098 (defvar anything-c-source-bookmarks
6099 '((name . "Bookmarks")
6100 (init . (lambda ()
6101 (require 'bookmark)))
6102 (candidates . bookmark-all-names)
6103 (type . bookmark))
6104 "See (info \"(emacs)Bookmarks\").")
6105 ;; (anything 'anything-c-source-bookmarks)
6107 ;;; bookmark-set
6108 (defvar anything-c-source-bookmark-set
6109 '((name . "Set Bookmark")
6110 (dummy)
6111 (action . bookmark-set))
6112 "See (info \"(emacs)Bookmarks\").")
6113 ;; (anything 'anything-c-source-bookmark-set)
6115 ;;; Visible Bookmarks
6116 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6119 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6120 (defvar anything-c-source-bm
6121 '((name . "Visible Bookmarks")
6122 (init . anything-c-bm-init)
6123 (candidates-in-buffer)
6124 (type . line))
6125 "Needs bm.el.
6127 http://www.nongnu.org/bm/")
6129 (defun anything-c-bm-init ()
6130 "Init function for `anything-c-source-bm'."
6131 (when (require 'bm nil t)
6132 (with-no-warnings
6133 (let ((bookmarks (bm-lists))
6134 (buf (anything-candidate-buffer 'global)))
6135 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6136 '< :key 'overlay-start))
6137 (let ((start (overlay-start bm))
6138 (end (overlay-end bm))
6139 (annotation (or (overlay-get bm 'annotation) "")))
6140 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6141 (let ((str (format "%5d: [%s]: %s\n"
6142 (line-number-at-pos start)
6143 annotation
6144 (buffer-substring start (1- end)))))
6145 (with-current-buffer buf (insert str))))))))))
6147 ;;; Special bookmarks
6148 (defvar anything-c-source-bookmarks-ssh
6149 '((name . "Bookmarks-ssh")
6150 (init . (lambda ()
6151 (require 'bookmark)))
6152 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6153 (type . bookmark))
6154 "See (info \"(emacs)Bookmarks\").")
6155 ;; (anything 'anything-c-source-bookmarks-ssh)
6157 (defvar anything-c-source-bookmarks-su
6158 '((name . "Bookmarks-root")
6159 (init . (lambda ()
6160 (require 'bookmark)))
6161 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6162 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6164 (type . bookmark))
6165 "See (info \"(emacs)Bookmarks\").")
6166 ;; (anything 'anything-c-source-bookmarks-su)
6168 (defvar anything-c-source-bookmarks-local
6169 '((name . "Bookmarks-Local")
6170 (init . (lambda ()
6171 (require 'bookmark)))
6172 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6173 (filtered-candidate-transformer
6174 anything-c-adaptive-sort
6175 anything-c-highlight-bookmark)
6176 (type . bookmark))
6177 "See (info \"(emacs)Bookmarks\").")
6178 ;; (anything 'anything-c-source-bookmarks-local)
6180 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6181 (let* ((lis-all (bookmark-all-names))
6182 (lis-loc (cond (local (loop for i in lis-all
6183 unless (string-match "^(ssh)\\|^(su)" i)
6184 collect i))
6185 (su (loop for i in lis-all
6186 when (string-match "^(su)" i)
6187 collect i))
6188 (sudo (loop for i in lis-all
6189 when (string-match "^(sudo)" i)
6190 collect i))
6191 (ssh (loop for i in lis-all
6192 when (string-match "^(ssh)" i)
6193 collect i)))))
6194 (sort lis-loc 'string-lessp)))
6196 (defun anything-c-bookmark-root-logged-p ()
6197 (catch 'break
6198 (dolist (i (mapcar #'buffer-name (buffer-list)))
6199 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6200 (throw 'break t)))))
6202 (defun anything-c-highlight-bookmark-su (files source)
6203 (if (anything-c-bookmark-root-logged-p)
6204 (anything-c-highlight-bookmark files source)
6205 (anything-c-highlight-not-logged files source)))
6207 (defun anything-c-highlight-not-logged (files source)
6208 (loop for i in files
6209 collect (propertize i 'face anything-c-bookmarks-face3)))
6211 (defun anything-c-highlight-bookmark (bookmarks source)
6212 "Used as `candidate-transformer' to colorize bookmarks.
6213 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6214 (loop for i in bookmarks
6215 for isfile = (bookmark-get-filename i)
6216 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6217 (bmkext-get-buffer-name i))
6218 for handlerp = (and (fboundp 'bookmark-get-handler)
6219 (bookmark-get-handler i))
6220 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6221 (bmkext-w3m-bookmark-p i))
6222 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6223 (bmkext-gnus-bookmark-p i))
6224 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6225 (bmkext-man-bookmark-p i))
6226 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6227 (bmkext-woman-bookmark-p i))
6228 for handlerp = (bookmark-get-handler i)
6229 for isannotation = (bookmark-get-annotation i)
6230 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6231 for isinfo = (eq handlerp 'Info-bookmark-jump)
6232 ;; Add a * if bookmark have annotation
6233 if (and isannotation (not (string-equal isannotation "")))
6234 do (setq i (concat "*" i))
6235 collect (cond (;; info buffers
6236 isinfo
6237 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6238 (;; w3m buffers
6239 isw3m
6240 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6241 (;; gnus buffers
6242 isgnus
6243 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6244 (;; Man Woman
6245 (or iswoman isman)
6246 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6247 (;; Addressbook
6248 isabook
6249 (propertize i 'face '((:foreground "Tomato"))))
6250 (;; directories
6251 (and isfile (file-directory-p isfile))
6252 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6253 (;; regular files
6255 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6259 ;;; Sources to filter bookmark-extensions bookmarks.
6262 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6263 ;; If you want to enable google-maps in addressbook you will need
6264 ;; Julien Danjou google-maps-el package available here:
6265 ;; http://julien.danjou.info/google-maps-el.html
6267 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6268 "Return a filtered `bookmark-alist' sorted alphabetically."
6269 (loop
6270 with alist = (if args
6271 (apply #'(lambda (x) (funcall fn x)) args)
6272 (funcall fn))
6273 for i in alist
6274 for b = (car i)
6275 collect b into sa
6276 finally return (sort sa 'string-lessp)))
6278 ;;; Addressbook.
6281 (defvar anything-c-source-bmkext-addressbook
6282 '((name . "Bookmark Addressbook")
6283 (init . (lambda ()
6284 (require 'bookmark-extensions)
6285 (bookmark-maybe-load-default-file)))
6286 (candidates . anything-c-bmkext-addressbook-setup-alist)
6287 (persistent-action
6288 . (lambda (candidate)
6289 (let ((bmk (anything-bookmark-get-bookmark-from-name
6290 candidate)))
6291 (bookmark--jump-via bmk 'pop-to-buffer))))
6292 (persistent-help . "Show contact - Prefix with C-u to append")
6293 (filtered-candidate-transformer
6294 anything-c-adaptive-sort
6295 anything-c-highlight-bookmark)
6296 (action . (("Show Contact(s)"
6297 . (lambda (candidate)
6298 (let* ((contacts (anything-marked-candidates))
6299 (current-prefix-arg (or anything-current-prefix-arg
6300 (> (length contacts) 1))))
6301 (bookmark-jump
6302 (anything-bookmark-get-bookmark-from-name (car contacts)))
6303 (anything-aif (cdr contacts)
6304 (loop for bmk in it do
6305 (bookmark-jump
6306 (anything-bookmark-get-bookmark-from-name bmk)))))))
6307 ("Send Mail"
6308 . (lambda (candidate)
6309 (let* ((contacts (anything-marked-candidates))
6310 (bmk (anything-bookmark-get-bookmark-from-name
6311 (car contacts)))
6312 (append (message-buffers)))
6313 (if append
6314 (addressbook-set-mail-buffer1 bmk 'append)
6315 (addressbook-set-mail-buffer1 bmk))
6316 (setq contacts (cdr contacts))
6317 (when contacts
6318 (loop for bmk in contacts do
6319 (addressbook-set-mail-buffer1 bmk 'append))))))
6320 ("Edit Bookmark"
6321 . (lambda (candidate)
6322 (let ((bmk (anything-bookmark-get-bookmark-from-name
6323 candidate)))
6324 (addressbook-bookmark-edit
6325 (assoc bmk bookmark-alist)))))
6326 ("Insert Email at point"
6327 . (lambda (candidate)
6328 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6329 candidate))
6330 (mlist (split-string
6331 (assoc-default
6332 'email (assoc bmk bookmark-alist))
6333 ", ")))
6334 (insert
6335 (if (> (length mlist) 1)
6336 (anything-comp-read
6337 "Insert Mail Address: " mlist :must-match t)
6338 (car mlist))))))
6339 ("Show annotation"
6340 . (lambda (candidate)
6341 (let ((bmk (anything-bookmark-get-bookmark-from-name
6342 candidate)))
6343 (bookmark-show-annotation bmk))))
6344 ("Edit annotation"
6345 . (lambda (candidate)
6346 (let ((bmk (anything-bookmark-get-bookmark-from-name
6347 candidate)))
6348 (bookmark-edit-annotation bmk))))
6349 ("Show Google map"
6350 . (lambda (candidate)
6351 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6352 candidate))
6353 (full-bmk (assoc bmk bookmark-alist)))
6354 (addressbook-google-map full-bmk))))))))
6357 (defun anything-c-bmkext-addressbook-setup-alist ()
6358 "Specialized filter function for bookmarks w3m."
6359 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6361 ;; W3m bookmarks from bookmark-extensions.
6362 (defvar anything-c-source-bookmark-w3m
6363 '((name . "Bookmark W3m")
6364 (init . (lambda ()
6365 (require 'bookmark-extensions)
6366 (bookmark-maybe-load-default-file)))
6367 (candidates . anything-c-bookmark-w3m-setup-alist)
6368 (filtered-candidate-transformer
6369 anything-c-adaptive-sort
6370 anything-c-highlight-bookmark)
6371 (type . bookmark)))
6372 ;; (anything 'anything-c-source-bookmark-w3m)
6374 (defun anything-c-bookmark-w3m-setup-alist ()
6375 "Specialized filter function for bookmarks w3m."
6376 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6378 ;; Images
6379 (defvar anything-c-source-bookmark-images
6380 '((name . "Bookmark Images")
6381 (init . (lambda ()
6382 (require 'bookmark-extensions)
6383 (bookmark-maybe-load-default-file)))
6384 (candidates . anything-c-bookmark-images-setup-alist)
6385 (filtered-candidate-transformer
6386 anything-c-adaptive-sort
6387 anything-c-highlight-bookmark)
6388 (type . bookmark)))
6389 ;; (anything 'anything-c-source-bookmark-images)
6391 (defun anything-c-bookmark-images-setup-alist ()
6392 "Specialized filter function for images bookmarks."
6393 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6395 ;; Woman Man
6396 (defvar anything-c-source-bookmark-man
6397 '((name . "Bookmark Woman&Man")
6398 (init . (lambda ()
6399 (require 'bookmark-extensions)
6400 (bookmark-maybe-load-default-file)))
6401 (candidates . anything-c-bookmark-man-setup-alist)
6402 (filtered-candidate-transformer
6403 anything-c-adaptive-sort
6404 anything-c-highlight-bookmark)
6405 (type . bookmark)))
6406 ;; (anything 'anything-c-source-bookmark-man)
6408 (defun anything-c-bookmark-man-setup-alist ()
6409 "Specialized filter function for bookmarks w3m."
6410 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6411 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6413 ;; Gnus
6414 (defvar anything-c-source-bookmark-gnus
6415 '((name . "Bookmark Gnus")
6416 (init . (lambda ()
6417 (require 'bookmark-extensions)
6418 (bookmark-maybe-load-default-file)))
6419 (candidates . anything-c-bookmark-gnus-setup-alist)
6420 (filtered-candidate-transformer
6421 anything-c-adaptive-sort
6422 anything-c-highlight-bookmark)
6423 (type . bookmark)))
6424 ;; (anything 'anything-c-source-bookmark-gnus)
6426 (defun anything-c-bookmark-gnus-setup-alist ()
6427 "Specialized filter function for bookmarks gnus."
6428 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6430 ;; Info
6431 (defvar anything-c-source-bookmark-info
6432 '((name . "Bookmark Info")
6433 (init . (lambda ()
6434 (require 'bookmark-extensions)
6435 (bookmark-maybe-load-default-file)))
6436 (candidates . anything-c-bookmark-info-setup-alist)
6437 (filtered-candidate-transformer
6438 anything-c-adaptive-sort
6439 anything-c-highlight-bookmark)
6440 (type . bookmark)))
6441 ;; (anything 'anything-c-source-bookmark-info)
6443 (defun anything-c-bookmark-info-setup-alist ()
6444 "Specialized filter function for bookmarks info."
6445 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6447 ;; Local Files&directories
6448 (defvar anything-c-source-bookmark-files&dirs
6449 '((name . "Bookmark Files&Directories")
6450 (init . (lambda ()
6451 (require 'bookmark-extensions)
6452 (bookmark-maybe-load-default-file)))
6453 (candidates . anything-c-bookmark-local-files-setup-alist)
6454 (filtered-candidate-transformer
6455 anything-c-adaptive-sort
6456 anything-c-highlight-bookmark)
6457 (type . bookmark)))
6458 ;; (anything 'anything-c-source-bookmark-files&dirs)
6460 (defun anything-c-bookmark-local-files-setup-alist ()
6461 "Specialized filter function for bookmarks locals files."
6462 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6464 ;; Su Files&directories
6465 (defvar anything-c-source-bookmark-su-files&dirs
6466 '((name . "Bookmark Root-Files&Directories")
6467 (init . (lambda ()
6468 (require 'bookmark-extensions)
6469 (bookmark-maybe-load-default-file)))
6470 (candidates . anything-c-bookmark-su-files-setup-alist)
6471 (filtered-candidate-transformer
6472 anything-c-adaptive-sort
6473 anything-c-highlight-bookmark-su)
6474 (type . bookmark)))
6475 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6477 (defun anything-c-bookmark-su-files-setup-alist ()
6478 "Specialized filter function for bookmarks su/sudo files."
6479 (declare (special bmkext-su-or-sudo-regexp))
6480 (loop
6481 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6482 for i in l
6483 for isfile = (bookmark-get-filename i)
6484 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6485 (save-match-data
6486 (string-match tramp-file-name-regexp isfile)))
6487 for issu = (and istramp
6488 (string-match bmkext-su-or-sudo-regexp isfile))
6489 if issu
6490 collect i))
6492 ;; Ssh Files&directories
6493 (defvar anything-c-source-bookmark-ssh-files&dirs
6494 '((name . "Bookmark Ssh-Files&Directories")
6495 (init . (lambda ()
6496 (require 'bookmark-extensions)
6497 (bookmark-maybe-load-default-file)))
6498 (candidates . anything-c-bookmark-ssh-files-setup-alist)
6499 (filtered-candidate-transformer . anything-c-adaptive-sort)
6500 (type . bookmark)))
6501 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6503 (defun anything-c-bookmark-ssh-files-setup-alist ()
6504 "Specialized filter function for bookmarks ssh files."
6505 (loop
6506 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
6507 for i in l
6508 for isfile = (bookmark-get-filename i)
6509 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
6510 (save-match-data
6511 (string-match tramp-file-name-regexp isfile)))
6512 for isssh = (and istramp
6513 (string-match "/ssh:" isfile))
6514 if isssh
6515 collect i))
6519 ;;; Firefox bookmarks
6522 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6523 ;; (only for firefox versions >=3)
6524 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6525 ;; to true:
6526 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6527 ;; You should have now:
6528 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6530 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6531 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6533 (defun anything-get-firefox-user-init-dir ()
6534 "Guess the default Firefox user directory name."
6535 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6536 (moz-user-dir
6537 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
6538 (goto-char (point-min))
6539 (prog1
6540 (when (search-forward "Path=" nil t)
6541 (buffer-substring-no-properties (point) (point-at-eol)))
6542 (kill-buffer)))))
6543 (file-name-as-directory (concat moz-dir moz-user-dir))))
6545 (defun anything-guess-firefox-bookmark-file ()
6546 "Return the path of the Firefox bookmarks file."
6547 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6549 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
6550 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6551 (let (bookmarks-alist url title)
6552 (with-temp-buffer
6553 (insert-file-contents file)
6554 (goto-char (point-min))
6555 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
6556 (forward-line 0)
6557 (when (re-search-forward url-regexp nil t)
6558 (setq url (match-string 0)))
6559 (when (re-search-forward bmk-regexp nil t)
6560 (setq title (match-string 1)))
6561 (push (cons title url) bookmarks-alist)
6562 (forward-line)))
6563 (nreverse bookmarks-alist)))
6565 (defvar anything-c-firefox-bookmarks-alist nil)
6566 (defvar anything-c-source-firefox-bookmarks
6567 '((name . "Firefox Bookmarks")
6568 (init . (lambda ()
6569 (setq anything-c-firefox-bookmarks-alist
6570 (anything-html-bookmarks-to-alist
6571 (anything-guess-firefox-bookmark-file)
6572 anything-firefox-bookmark-url-regexp
6573 anything-firefox-bookmarks-regexp))))
6574 (candidates . (lambda ()
6575 (mapcar #'car anything-c-firefox-bookmarks-alist)))
6576 (filtered-candidate-transformer
6577 anything-c-adaptive-sort
6578 anything-c-highlight-firefox-bookmarks)
6579 (action . (("Browse Url Firefox"
6580 . (lambda (candidate)
6581 (browse-url-firefox
6582 (anything-c-firefox-bookmarks-get-value candidate))))
6583 ("Browse Url w3m"
6584 . (lambda (candidate)
6585 (w3m-browse-url
6586 (anything-c-firefox-bookmarks-get-value candidate))))
6587 ("Copy Url"
6588 . (lambda (elm)
6589 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
6591 ;; (anything 'anything-c-source-firefox-bookmarks)
6593 (defun anything-c-firefox-bookmarks-get-value (elm)
6594 (assoc-default elm anything-c-firefox-bookmarks-alist))
6596 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
6597 (loop for i in bookmarks
6598 collect (propertize
6599 i 'face '((:foreground "YellowGreen"))
6600 'help-echo (anything-c-firefox-bookmarks-get-value i))))
6604 ;;; W3m bookmark - anything interface.
6607 ;; Some users have the emacs-w3m library in load-path
6608 ;; without having the w3m executable :-;
6609 ;; So check if w3m program is present before trying to load
6610 ;; emacs-w3m.
6611 (eval-when-compile
6612 (when (executable-find "w3m")
6613 (require 'w3m-bookmark nil t)))
6615 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
6616 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
6617 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6618 (defvar anything-c-w3m-bookmarks-alist nil)
6619 (defvar anything-c-source-w3m-bookmarks
6620 '((name . "W3m Bookmarks")
6621 (init . (lambda ()
6622 (setq anything-c-w3m-bookmarks-alist
6623 (anything-html-bookmarks-to-alist
6624 w3m-bookmark-file
6625 anything-w3m-bookmark-url-regexp
6626 anything-w3m-bookmarks-regexp))))
6627 (candidates . (lambda ()
6628 (mapcar #'car anything-c-w3m-bookmarks-alist)))
6629 (filtered-candidate-transformer
6630 anything-c-adaptive-sort
6631 anything-c-highlight-w3m-bookmarks)
6632 (action . (("Browse Url"
6633 . (lambda (candidate)
6634 (anything-c-w3m-browse-bookmark candidate)))
6635 ("Copy Url"
6636 . (lambda (elm)
6637 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
6638 ("Browse Url Firefox"
6639 . (lambda (candidate)
6640 (anything-c-w3m-browse-bookmark candidate t)))
6641 ("Delete Bookmark"
6642 . (lambda (candidate)
6643 (anything-c-w3m-delete-bookmark candidate)))
6644 ("Rename Bookmark"
6645 . (lambda (candidate)
6646 (anything-c-w3m-rename-bookmark candidate)))))
6647 (persistent-action . (lambda (candidate)
6648 (if current-prefix-arg
6649 (anything-c-w3m-browse-bookmark candidate t)
6650 (anything-c-w3m-browse-bookmark candidate nil t))))
6651 (persistent-help . "Open URL with emacs-w3m in new tab / \
6652 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6653 "Needs w3m and emacs-w3m.
6655 http://w3m.sourceforge.net/
6656 http://emacs-w3m.namazu.org/")
6658 ;; (anything 'anything-c-source-w3m-bookmarks)
6660 (defun anything-c-w3m-bookmarks-get-value (elm)
6661 (replace-regexp-in-string
6662 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
6664 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
6665 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
6666 (arg (and (eq fn 'w3m-browse-url) new-tab)))
6667 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
6669 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
6670 (loop for i in bookmarks
6671 collect (propertize
6672 i 'face 'anything-w3m-bookmarks-face
6673 'help-echo (anything-c-w3m-bookmarks-get-value i))))
6676 (defun anything-c-w3m-delete-bookmark (elm)
6677 "Delete w3m bookmark from `w3m-bookmark-file'."
6678 (with-current-buffer
6679 (find-file-literally w3m-bookmark-file)
6680 (goto-char (point-min))
6681 (when (re-search-forward elm nil t)
6682 (beginning-of-line)
6683 (delete-region (point)
6684 (line-end-position))
6685 (delete-blank-lines))
6686 (save-buffer)
6687 (kill-buffer)))
6689 (defun anything-c-w3m-rename-bookmark (elm)
6690 "Rename w3m bookmark in `w3m-bookmark-file'."
6691 (let* ((old-title (replace-regexp-in-string ">" "" elm))
6692 (new-title (read-string "NewTitle: " old-title)))
6693 (with-current-buffer
6694 (find-file-literally w3m-bookmark-file)
6695 (goto-char (point-min))
6696 (when (re-search-forward (concat elm "<") nil t)
6697 (goto-char (1- (point)))
6698 (delete-char (- (length old-title)))
6699 (insert new-title))
6700 (save-buffer)
6701 (kill-buffer))))
6704 ;;;; <Library>
6705 ;;; Elisp library scan
6708 (defvar anything-c-source-elisp-library-scan
6709 '((name . "Elisp libraries (Scan)")
6710 (init . (anything-c-elisp-library-scan-init))
6711 (candidates-in-buffer)
6712 (action ("Find library"
6713 . (lambda (candidate) (find-file (find-library-name candidate))))
6714 ("Find library other window"
6715 . (lambda (candidate)
6716 (find-file-other-window (find-library-name candidate))))
6717 ("Load library"
6718 . (lambda (candidate) (load-library candidate))))))
6719 ;; (anything 'anything-c-source-elisp-library-scan)
6721 (defun anything-c-elisp-library-scan-init ()
6722 "Init anything buffer status."
6723 (let ((anything-buffer (anything-candidate-buffer 'global))
6724 (library-list (anything-c-elisp-library-scan-list)))
6725 (with-current-buffer anything-buffer
6726 (dolist (library library-list)
6727 (insert (format "%s\n" library))))))
6729 (defun anything-c-elisp-library-scan-list (&optional dirs string)
6730 "Do completion for file names passed to `locate-file'.
6731 DIRS is directory to search path.
6732 STRING is string to match."
6733 ;; Use `load-path' as path when ignore `dirs'.
6734 (or dirs (setq dirs load-path))
6735 ;; Init with blank when ignore `string'.
6736 (or string (setq string ""))
6737 ;; Get library list.
6738 (let ((string-dir (file-name-directory string))
6739 ;; File regexp that suffix match `load-file-rep-suffixes'.
6740 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
6741 name
6742 names)
6743 (dolist (dir dirs)
6744 (unless dir
6745 (setq dir default-directory))
6746 (if string-dir
6747 (setq dir (expand-file-name string-dir dir)))
6748 (when (file-directory-p dir)
6749 (dolist (file (file-name-all-completions
6750 (file-name-nondirectory string) dir))
6751 ;; Suffixes match `load-file-rep-suffixes'.
6752 (setq name (if string-dir (concat string-dir file) file))
6753 (if (string-match match-regexp name)
6754 (add-to-list 'names name)))))
6755 names))
6758 ;;;; <Programming>
6762 ;;; Imenu
6765 (defvar anything-c-imenu-delimiter " / ")
6767 (defvar anything-c-imenu-index-filter nil)
6768 (make-variable-buffer-local 'anything-c-imenu-index-filter)
6770 (defvar anything-c-cached-imenu-alist nil)
6771 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
6773 (defvar anything-c-cached-imenu-candidates nil)
6774 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
6776 (defvar anything-c-cached-imenu-tick nil)
6777 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
6779 (eval-when-compile (require 'imenu))
6780 (setq imenu-auto-rescan t)
6782 (defun anything-imenu-create-candidates (entry)
6783 "Create candidates with ENTRY."
6784 (if (listp (cdr entry))
6785 (mapcan
6786 (lambda (sub)
6787 (if (consp (cdr sub))
6788 (mapcar
6789 (lambda (subentry)
6790 (concat (car entry) anything-c-imenu-delimiter subentry))
6791 (anything-imenu-create-candidates sub))
6792 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
6793 (cdr entry))
6794 (list entry)))
6796 (defvar anything-c-source-imenu
6797 '((name . "Imenu")
6798 (init . (lambda () (require 'imenu)))
6799 (candidates . anything-c-imenu-candidates)
6800 (persistent-action . (lambda (elm)
6801 (anything-c-imenu-default-action elm)
6802 (unless (fboundp 'semantic-imenu-tag-overlay)
6803 (anything-match-line-color-current-line))))
6804 (persistent-help . "Show this entry")
6805 (action . anything-c-imenu-default-action))
6806 "See (info \"(emacs)Imenu\")")
6808 ;; (anything 'anything-c-source-imenu)
6810 (defun anything-c-imenu-candidates ()
6811 (with-anything-current-buffer
6812 (let ((tick (buffer-modified-tick)))
6813 (if (eq anything-c-cached-imenu-tick tick)
6814 anything-c-cached-imenu-candidates
6815 (setq imenu--index-alist nil)
6816 (setq anything-c-cached-imenu-tick tick
6817 anything-c-cached-imenu-candidates
6818 (ignore-errors
6819 (mapcan
6820 'anything-imenu-create-candidates
6821 (setq anything-c-cached-imenu-alist
6822 (let ((index (imenu--make-index-alist)))
6823 (if anything-c-imenu-index-filter
6824 (funcall anything-c-imenu-index-filter index)
6825 index))))))
6826 (setq anything-c-cached-imenu-candidates
6827 (mapcar #'(lambda (x)
6828 (if (stringp x)
6830 (car x)))
6831 anything-c-cached-imenu-candidates))))))
6833 (setq imenu-default-goto-function 'imenu-default-goto-function)
6834 (defun anything-c-imenu-default-action (elm)
6835 "The default action for `anything-c-source-imenu'."
6836 (let ((path (split-string elm anything-c-imenu-delimiter))
6837 (alist anything-c-cached-imenu-alist))
6838 (dolist (elm path)
6839 (setq alist (assoc elm alist)))
6840 (imenu alist)))
6844 ;;; Ctags
6847 (defvar anything-c-ctags-modes
6848 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6849 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6850 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
6852 (defun anything-c-source-ctags-init ()
6853 (when (and buffer-file-name
6854 (memq major-mode anything-c-ctags-modes)
6855 (anything-current-buffer-is-modified))
6856 (with-current-buffer (anything-candidate-buffer 'local)
6857 (call-process-shell-command
6858 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
6859 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6860 anything-buffer-file-name)
6861 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
6862 nil (current-buffer))
6863 (goto-char (point-min))
6864 (forward-line 2)
6865 (delete-region (point-min) (point))
6866 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
6867 for lineno-start = (point)
6868 for lineno = (buffer-substring
6869 lineno-start
6870 (1- (search-forward "," (point-at-eol) t)))
6872 (beginning-of-line)
6873 (insert (format "%5s:" lineno))
6874 (search-forward "\177" (point-at-eol) t)
6875 (delete-region (1- (point)) (point-at-eol))
6876 (forward-line 1)))))
6878 (defvar anything-c-source-ctags
6879 '((name . "Exuberant ctags")
6880 (init . anything-c-source-ctags-init)
6881 (candidates-in-buffer)
6882 (adjust)
6883 (type . line))
6884 "Needs Exuberant Ctags.
6886 http://ctags.sourceforge.net/")
6887 ;; (anything 'anything-c-source-ctags)
6890 ;;; Etags
6893 ;; anything-etags.el is deprecated, if this file is found,
6894 ;; warn user at compile time.
6895 (eval-when-compile
6896 (when (locate-library "anything-etags.el")
6897 (display-warning
6898 '(anything-config)
6899 "You are using obsolete library `anything-etags.el' and should remove it."
6900 :warning)))
6902 (defvar anything-c-etags-tag-file-dir nil
6903 "Etags file directory.")
6904 (defvar anything-c-etags-mtime-alist nil
6905 "Store the last modification time of etags files here.")
6906 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
6907 "Cache content of etags files used here for faster access.")
6909 (defun anything-c-etags-get-tag-file (&optional directory)
6910 "Return the path of etags file if found."
6911 ;; Get tag file from `default-directory' or upper directory.
6912 (let ((current-dir (anything-c-etags-find-tag-file-directory
6913 (or directory default-directory))))
6914 ;; Return nil if not find tag file.
6915 (when current-dir
6916 ;; Set tag file directory.
6917 (setq anything-c-etags-tag-file-dir current-dir)
6918 (expand-file-name anything-c-etags-tag-file-name current-dir))))
6920 (defun anything-c-etags-find-tag-file-directory (current-dir)
6921 "Try to find the directory containing tag file.
6922 If not found in CURRENT-DIR search in upper directory."
6923 (flet ((file-exists? (dir)
6924 (let ((tag-path (expand-file-name
6925 anything-c-etags-tag-file-name dir)))
6926 (and (stringp tag-path)
6927 (file-exists-p tag-path)
6928 (file-readable-p tag-path)))))
6929 (loop with count = 0
6930 until (file-exists? current-dir)
6931 ;; Return nil if outside the value of
6932 ;; `anything-c-etags-tag-file-search-limit'.
6933 if (= count anything-c-etags-tag-file-search-limit)
6934 do (return nil)
6935 ;; Or search upper directories.
6936 else
6937 do (incf count)
6938 (setq current-dir (expand-file-name (concat current-dir "../")))
6939 finally return current-dir)))
6941 (defun anything-c-source-etags-header-name (x)
6942 "Create header name for this anything etags session."
6943 (concat "Etags in "
6944 (with-anything-current-buffer
6945 (anything-c-etags-get-tag-file))))
6947 (defmacro anything-c-etags-create-buffer (file)
6948 "Create the `anything-buffer' based on contents of etags tag FILE."
6949 `(let* ((tag-fname ,file)
6951 (split (with-current-buffer (find-file-noselect tag-fname)
6952 (prog1
6953 (split-string (buffer-string) "\n" 'omit-nulls)
6954 (setq max (line-number-at-pos (point-max)))
6955 (kill-buffer))))
6956 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
6957 (loop
6958 with fname
6959 with cand
6960 for i in split for count from 0
6961 for elm = (unless (string-match "^\x0c" i)
6962 (anything-aif (string-match "\177" i)
6963 (substring i 0 it)
6965 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
6966 (setq fname (match-string 1 elm)))
6967 (elm (setq cand (concat fname ": " elm)))
6968 (t (setq cand nil)))
6969 when cand do (progn
6970 (insert (concat cand "\n"))
6971 (progress-reporter-update progress-reporter count)))))
6973 (defun anything-c-etags-init ()
6974 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6975 If no entry in cache, create one."
6976 (let ((tagfile (anything-c-etags-get-tag-file)))
6977 (when tagfile
6978 (with-current-buffer (anything-candidate-buffer 'global)
6979 (anything-aif (gethash tagfile anything-c-etags-cache)
6980 ;; An entry is present in cache, insert it.
6981 (insert it)
6982 ;; No entry, create a new buffer using content of tag file (slower).
6983 (anything-c-etags-create-buffer tagfile)
6984 ;; Store content of buffer in cache.
6985 (puthash tagfile (buffer-string) anything-c-etags-cache)
6986 ;; Store or set the last modification of tag file.
6987 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
6988 ;; If an entry exists modify it.
6989 (setcdr it (anything-c-etags-mtime tagfile))
6990 ;; No entry create a new one.
6991 (add-to-list 'anything-c-etags-mtime-alist
6992 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
6994 (defvar anything-c-source-etags-select
6995 '((name . "Etags")
6996 (header-name . anything-c-source-etags-header-name)
6997 (init . anything-c-etags-init)
6998 (candidates-in-buffer)
6999 (search . (anything-c-etags-search-fn))
7000 (mode-line . anything-etags-mode-line-string)
7001 (action . anything-c-etags-default-action)
7002 (persistent-action . (lambda (candidate)
7003 (anything-c-etags-default-action candidate)
7004 (anything-match-line-color-current-line))))
7005 "Anything source for Etags.")
7007 (defun anything-c-etags-search-fn (pattern)
7008 "Search function for `anything-c-source-etags-select'."
7009 (re-search-forward
7010 (if anything-c-etags-use-regexp-search
7011 (format anything-c-etags-search-regexp pattern)
7012 pattern)
7013 nil t))
7015 (defun anything-c-etags-default-action (candidate)
7016 "Anything default action to jump to an etags entry."
7017 (let* ((split (split-string candidate ": "))
7018 (fname (expand-file-name
7019 (car split) anything-c-etags-tag-file-dir))
7020 (elm (cadr split)))
7021 (find-file fname)
7022 (goto-char (point-min))
7023 (search-forward elm nil t)
7024 (goto-char (match-beginning 0))))
7026 (defun anything-c-etags-mtime (file)
7027 "Last modification time of etags tag FILE."
7028 (cadr (nth 5 (file-attributes file))))
7030 (defun anything-c-etags-file-modified-p (file)
7031 "Check if tag FILE have been modified in this session.
7032 If FILE is nil return nil."
7033 (let ((last-modif (and file
7034 (assoc-default file anything-c-etags-mtime-alist))))
7035 (and last-modif
7036 (/= last-modif (anything-c-etags-mtime file)))))
7040 ;;; Semantic
7043 (defvar anything-semantic-candidates nil)
7045 (defun anything-semantic-construct-candidates (tags depth)
7046 (when (require 'semantic nil t)
7047 (apply
7048 'append
7049 (mapcar
7050 (lambda (tag)
7051 (if (listp tag)
7052 (let ((type (semantic-tag-type tag))
7053 (class (semantic-tag-class tag)))
7054 (if (or (and (stringp type)
7055 (or (string= type "class")
7056 (string= type "namespace")))
7057 (eq class 'function)
7058 (eq class 'variable))
7059 (cons (cons (concat (make-string (* depth 2) ?\s)
7060 (semantic-format-tag-summarize tag nil t))
7061 tag)
7062 (anything-semantic-construct-candidates
7063 (semantic-tag-components tag) (1+ depth)))))))
7064 tags))))
7066 (defun anything-semantic-default-action (candidate)
7067 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7068 (semantic-go-to-tag tag)))
7070 (defvar anything-c-source-semantic
7071 '((name . "Semantic Tags")
7072 (init . (lambda ()
7073 (setq anything-semantic-candidates
7074 (ignore-errors (anything-semantic-construct-candidates
7075 (semantic-fetch-tags) 0)))))
7076 (candidates . (lambda ()
7077 (if anything-semantic-candidates
7078 (mapcar 'car anything-semantic-candidates))))
7079 (persistent-action . (lambda (elm)
7080 (anything-semantic-default-action elm)
7081 (anything-match-line-color-current-line)))
7082 (persistent-help . "Show this entry")
7083 (action . anything-semantic-default-action)
7084 "Needs semantic in CEDET.
7086 http://cedet.sourceforge.net/semantic.shtml
7087 http://cedet.sourceforge.net/"))
7089 ;; (anything 'anything-c-source-semantic)
7092 ;;; Anything interface of `simple-call-tree.el'.
7094 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7096 ;; Function is called by
7097 (defvar anything-c-source-simple-call-tree-functions-callers
7098 '((name . "Function is called by")
7099 (init . anything-c-simple-call-tree-functions-callers-init)
7100 (multiline)
7101 (candidates . anything-c-simple-call-tree-candidates)
7102 (persistent-action . anything-c-simple-call-tree-persistent-action)
7103 (persistent-help . "Show function definitions by rotation")
7104 (action ("Find definition selected by persistent-action" .
7105 anything-c-simple-call-tree-find-definition)))
7106 "Needs simple-call-tree.el.
7107 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7109 (defvar anything-c-simple-call-tree-tick nil)
7110 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7111 (defun anything-c-simple-call-tree-analyze-maybe ()
7112 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7113 (simple-call-tree-analyze)
7114 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7116 (defun anything-c-simple-call-tree-init-base (function message)
7117 (require 'simple-call-tree)
7118 (with-no-warnings
7119 (when (anything-current-buffer-is-modified)
7120 (anything-c-simple-call-tree-analyze-maybe)
7121 (let ((list (funcall function simple-call-tree-alist)))
7122 (with-current-buffer (anything-candidate-buffer 'local)
7123 (dolist (entry list)
7124 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7125 (insert (car entry) message
7126 (if (string= funcs " ")
7127 " no functions."
7128 funcs)
7129 "\n\n"))))))))
7131 (defun anything-c-simple-call-tree-functions-callers-init ()
7132 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7133 " is called by\n"))
7135 (defun anything-c-simple-call-tree-candidates ()
7136 (with-current-buffer (anything-candidate-buffer)
7137 (split-string (buffer-string) "\n\n")))
7139 (defvar anything-c-simple-call-tree-related-functions nil)
7140 (defvar anything-c-simple-call-tree-function-index 0)
7141 (defun anything-c-simple-call-tree-persistent-action (candidate)
7142 (unless (eq last-command 'anything-execute-persistent-action)
7143 (setq anything-c-simple-call-tree-related-functions
7144 (delete "no functions."
7145 (split-string
7146 (replace-regexp-in-string " \\| is called by\\| calls "
7147 "" candidate)
7148 "\n")))
7149 (setq anything-c-simple-call-tree-function-index -1))
7150 (incf anything-c-simple-call-tree-function-index)
7151 (anything-c-simple-call-tree-find-definition candidate))
7153 (defun anything-c-simple-call-tree-find-definition (candidate)
7154 (find-function
7155 (intern
7156 (nth (mod anything-c-simple-call-tree-function-index
7157 (length anything-c-simple-call-tree-related-functions))
7158 anything-c-simple-call-tree-related-functions))))
7160 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7162 ;;; Function calls
7163 (defvar anything-c-source-simple-call-tree-callers-functions
7164 '((name . "Function calls")
7165 (init . anything-c-simple-call-tree-callers-functions-init)
7166 (multiline)
7167 (candidates . anything-c-simple-call-tree-candidates)
7168 (persistent-action . anything-c-simple-call-tree-persistent-action)
7169 (persistent-help . "Show function definitions by rotation")
7170 (action ("Find definition selected by persistent-action" .
7171 anything-c-simple-call-tree-find-definition)))
7172 "Needs simple-call-tree.el.
7173 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7175 (defun anything-c-simple-call-tree-callers-functions-init ()
7176 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7178 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7182 ;;; Anything UI of auto-document.el
7184 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7186 ;; Commands/Options with doc
7187 (defvar anything-c-auto-document-data nil)
7188 (make-variable-buffer-local 'anything-c-auto-document-data)
7189 (defvar anything-c-source-commands-and-options-in-file
7190 '((name . "Commands/Options in file")
7191 (header-name
7192 . (lambda (x) (format "Commands/Options in %s"
7193 (buffer-local-value 'buffer-file-name
7194 anything-current-buffer))))
7195 (candidates . anything-command-and-options-candidates)
7196 (multiline)
7197 (action . imenu))
7198 "List Commands and Options with doc. It needs auto-document.el .
7200 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7202 (eval-when-compile (require 'auto-document nil t))
7203 (defun anything-command-and-options-candidates ()
7204 (with-anything-current-buffer
7205 (when (and (require 'auto-document nil t)
7206 (eq major-mode 'emacs-lisp-mode)
7207 (or (anything-current-buffer-is-modified)
7208 (not anything-c-auto-document-data)))
7209 (or imenu--index-alist (imenu--make-index-alist t))
7210 (setq anything-c-auto-document-data
7211 (destructuring-bind (commands options)
7212 (adoc-construct anything-current-buffer)
7213 (append
7214 (loop for (command . doc) in commands
7215 for cmdname = (symbol-name command)
7216 collect
7217 (cons
7218 (format "Command: %s\n %s"
7219 (propertize cmdname 'face font-lock-function-name-face)
7220 (adoc-first-line doc))
7221 (assoc cmdname imenu--index-alist)))
7222 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7223 for (option doc default) in options
7224 for optname = (symbol-name option)
7225 collect
7226 (cons
7227 (format "Option: %s\n %s\n default = %s"
7228 (propertize optname 'face font-lock-variable-name-face)
7229 (adoc-first-line doc)
7230 (adoc-prin1-to-string default))
7231 (assoc optname
7232 var-alist)))))))
7233 anything-c-auto-document-data))
7235 ;; (anything 'anything-c-source-commands-and-options-in-file)
7238 ;;;; <Color and Face>
7241 ;;; Customize Face
7244 (defvar anything-c-source-customize-face
7245 '((name . "Customize Face")
7246 (init . (lambda ()
7247 (unless (anything-candidate-buffer)
7248 (save-window-excursion (list-faces-display))
7249 (anything-candidate-buffer (get-buffer "*Faces*")))))
7250 (candidates-in-buffer)
7251 (get-line . buffer-substring)
7252 (action . (lambda (line)
7253 (customize-face (intern (car (split-string line))))))
7254 (requires-pattern . 3))
7255 "See (info \"(emacs)Faces\")")
7256 ;; (anything 'anything-c-source-customize-face)
7258 ;;; Colors browser
7261 (defvar anything-c-source-colors
7262 '((name . "Colors")
7263 (init . (lambda () (unless (anything-candidate-buffer)
7264 (save-window-excursion (list-colors-display))
7265 (anything-candidate-buffer (get-buffer "*Colors*")))))
7266 (candidates-in-buffer)
7267 (get-line . buffer-substring)
7268 (action
7269 ("Copy Name" . (lambda (candidate)
7270 (kill-new (anything-c-colors-get-name candidate))))
7271 ("Copy RGB" . (lambda (candidate)
7272 (kill-new (anything-c-colors-get-rgb candidate))))
7273 ("Insert Name" . (lambda (candidate)
7274 (with-anything-current-buffer
7275 (insert (anything-c-colors-get-name candidate)))))
7276 ("Insert RGB" . (lambda (candidate)
7277 (with-anything-current-buffer
7278 (insert (anything-c-colors-get-rgb candidate))))))))
7279 ;; (anything 'anything-c-source-colors)
7281 (defun anything-c-colors-get-name (candidate)
7282 "Get color name."
7283 (replace-regexp-in-string
7284 " " ""
7285 (with-temp-buffer
7286 (insert (capitalize candidate))
7287 (goto-char (point-min))
7288 (search-forward-regexp "\\s-\\{2,\\}")
7289 (delete-region (point) (point-max))
7290 (buffer-string))))
7292 (defun anything-c-colors-get-rgb (candidate)
7293 "Get color RGB."
7294 (replace-regexp-in-string
7295 " " ""
7296 (with-temp-buffer
7297 (insert (capitalize candidate))
7298 (goto-char (point-max))
7299 (search-backward-regexp "\\s-\\{2,\\}")
7300 (delete-region (point) (point-min))
7301 (buffer-string))))
7304 ;;;; <Search Engine>
7305 ;;; Tracker desktop search
7306 (defvar anything-c-source-tracker-search
7307 '((name . "Tracker Search")
7308 (candidates . (lambda ()
7309 (start-process "tracker-search-process" nil
7310 "tracker-search"
7311 anything-pattern)))
7312 (type . file)
7313 (requires-pattern . 3)
7314 (delayed))
7315 "Source for retrieving files matching the current input pattern
7316 with the tracker desktop search.")
7317 ;; (anything 'anything-c-source-tracker-search)
7319 ;;; Spotlight (MacOS X desktop search)
7320 (defvar anything-c-source-mac-spotlight
7321 '((name . "mdfind")
7322 (candidates
7323 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7324 (type . file)
7325 (requires-pattern . 3)
7326 (delayed))
7327 "Source for retrieving files via Spotlight's command line
7328 utility mdfind.")
7329 ;; (anything 'anything-c-source-mac-spotlight)
7331 ;;; Picklist
7332 (defvar anything-c-source-picklist
7333 '((name . "Picklist")
7334 (candidates . (lambda () (mapcar 'car picklist-list)))
7335 (type . file)))
7336 ;; (anything 'anything-c-source-picklist)
7340 ;;; Kill ring
7343 (defvar anything-c-source-kill-ring
7344 '((name . "Kill Ring")
7345 (init . (lambda () (anything-attrset 'last-command last-command)))
7346 (candidates . anything-c-kill-ring-candidates)
7347 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7348 (action . anything-c-kill-ring-action)
7349 (last-command)
7350 (migemo)
7351 (multiline))
7352 "Source for browse and insert contents of kill-ring.")
7354 (defun anything-c-kill-ring-candidates ()
7355 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7356 unless (or (< (length kill) anything-kill-ring-threshold)
7357 (string-match "^[\\s\\t]+$" kill))
7358 collect kill))
7360 (defun anything-c-kill-ring-transformer (candidates source)
7361 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7362 (loop for i in candidates
7363 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7364 if (and anything-c-kill-ring-max-lines-number
7365 (> nlines anything-c-kill-ring-max-lines-number))
7366 collect (cons
7367 (with-temp-buffer
7368 (insert i)
7369 (goto-char (point-min))
7370 (concat
7371 (buffer-substring
7372 (point-min)
7373 (save-excursion
7374 (forward-line anything-c-kill-ring-max-lines-number)
7375 (point)))
7376 "[...]")) i)
7377 else collect i))
7379 (defun anything-c-kill-ring-action (str)
7380 "Insert STR in `kill-ring' and set STR to the head.
7381 If this action is executed just after `yank',
7382 replace with STR as yanked string."
7383 (setq kill-ring (delete str kill-ring))
7384 (if (not (eq (anything-attr 'last-command) 'yank))
7385 (insert-for-yank str)
7386 ;; from `yank-pop'
7387 (let ((inhibit-read-only t)
7388 (before (< (point) (mark t))))
7389 (if before
7390 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7391 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7392 (setq yank-undo-function nil)
7393 (set-marker (mark-marker) (point) (current-buffer))
7394 (insert-for-yank str)
7395 ;; Set the window start back where it was in the yank command,
7396 ;; if possible.
7397 (set-window-start (selected-window) yank-window-start t)
7398 (if before
7399 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7400 ;; It is cleaner to avoid activation, even though the command
7401 ;; loop would deactivate the mark because we inserted text.
7402 (goto-char (prog1 (mark t)
7403 (set-marker (mark-marker) (point) (current-buffer)))))))
7404 (kill-new str))
7406 ;; (anything 'anything-c-source-kill-ring)
7409 ;;;; <Mark ring>
7410 ;; DO NOT include these sources in `anything-sources' use
7411 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7412 ;; `anything-all-mark-rings' instead.
7414 (defun anything-c-source-mark-ring-candidates ()
7415 (flet ((get-marks (pos)
7416 (save-excursion
7417 (goto-char pos)
7418 (beginning-of-line)
7419 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7420 (when (string= "" line)
7421 (setq line "<EMPTY LINE>"))
7422 (format "%7d: %s" (line-number-at-pos) line)))))
7423 (with-anything-current-buffer
7424 (loop
7425 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7426 with recip = nil
7427 for i in marks
7428 for m = (get-marks i)
7429 unless (member m recip)
7430 collect m into recip
7431 finally return recip))))
7433 (defvar anything-mark-ring-cache nil)
7434 (defvar anything-c-source-mark-ring
7435 '((name . "mark-ring")
7436 (init . (lambda ()
7437 (setq anything-mark-ring-cache
7438 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7439 (candidates . (lambda ()
7440 (anything-aif anything-mark-ring-cache
7441 it)))
7442 (action . (("Goto line"
7443 . (lambda (candidate)
7444 (anything-goto-line (string-to-number candidate))))))
7445 (persistent-action . (lambda (candidate)
7446 (anything-goto-line (string-to-number candidate))
7447 (anything-match-line-color-current-line)))
7448 (persistent-help . "Show this line")))
7450 ;; (anything 'anything-c-source-mark-ring)
7452 ;;; Global-mark-ring
7453 (defvar anything-c-source-global-mark-ring
7454 '((name . "global-mark-ring")
7455 (candidates . anything-c-source-global-mark-ring-candidates)
7456 (action . (("Goto line"
7457 . (lambda (candidate)
7458 (let ((items (split-string candidate ":")))
7459 (anything-c-switch-to-buffer (second items))
7460 (anything-goto-line (string-to-number (car items))))))))
7461 (persistent-action . (lambda (candidate)
7462 (let ((items (split-string candidate ":")))
7463 (anything-c-switch-to-buffer (second items))
7464 (anything-goto-line (string-to-number (car items)))
7465 (anything-match-line-color-current-line))))
7466 (persistent-help . "Show this line")))
7468 (defun anything-c-source-global-mark-ring-candidates ()
7469 (flet ((buf-fn (m)
7470 (with-current-buffer (marker-buffer m)
7471 (goto-char m)
7472 (beginning-of-line)
7473 (let (line)
7474 (if (string= "" line)
7475 (setq line "<EMPTY LINE>")
7476 (setq line (car (split-string (thing-at-point 'line)
7477 "[\n\r]"))))
7478 (format "%7d:%s: %s"
7479 (line-number-at-pos) (marker-buffer m) line)))))
7480 (loop
7481 with marks = global-mark-ring
7482 with recip = nil
7483 for i in marks
7484 for gm = (unless (or (string-match
7485 "^ " (format "%s" (marker-buffer i)))
7486 (null (marker-buffer i)))
7487 (buf-fn i))
7488 when (and gm (not (member gm recip)))
7489 collect gm into recip
7490 finally return recip)))
7492 ;; (anything 'anything-c-source-global-mark-ring)
7495 ;;;; <Register>
7496 ;;; Insert from register
7497 (defvar anything-c-source-register
7498 '((name . "Registers")
7499 (candidates . anything-c-register-candidates)
7500 (action-transformer . anything-c-register-action-transformer)
7501 (multiline)
7502 (action))
7503 "See (info \"(emacs)Registers\")")
7505 (defun anything-c-register-candidates ()
7506 "Collecting register contents and appropriate commands."
7507 (loop for (char . val) in register-alist
7508 for key = (single-key-description char)
7509 for string-actions =
7510 (cond
7511 ((numberp val)
7512 (list (int-to-string val)
7513 'insert-register
7514 'increment-register))
7515 ((markerp val)
7516 (let ((buf (marker-buffer val)))
7517 (if (null buf)
7518 (list "a marker in no buffer")
7519 (list (concat
7520 "a buffer position:"
7521 (buffer-name buf)
7522 ", position "
7523 (int-to-string (marker-position val)))
7524 'jump-to-register
7525 'insert-register))))
7526 ((and (consp val) (window-configuration-p (car val)))
7527 (list "window configuration."
7528 'jump-to-register))
7529 ((and (consp val) (frame-configuration-p (car val)))
7530 (list "frame configuration."
7531 'jump-to-register))
7532 ((and (consp val) (eq (car val) 'file))
7533 (list (concat "file:"
7534 (prin1-to-string (cdr val))
7535 ".")
7536 'jump-to-register))
7537 ((and (consp val) (eq (car val) 'file-query))
7538 (list (concat "file:a file-query reference: file "
7539 (car (cdr val))
7540 ", position "
7541 (int-to-string (car (cdr (cdr val))))
7542 ".")
7543 'jump-to-register))
7544 ((consp val)
7545 (let ((lines (format "%4d" (length val))))
7546 (list (format "%s: %s\n" lines
7547 (truncate-string-to-width
7548 (mapconcat 'identity (list (car val))
7549 ;; (mapconcat (lambda (y) y) val
7550 "^J") (- (window-width) 15)))
7551 'insert-register)))
7552 ((stringp val)
7553 (list ;; without properties
7554 (substring-no-properties val)
7555 'insert-register
7556 'append-to-register
7557 'prepend-to-register))
7559 "GARBAGE!"))
7560 collect (cons (format "register %3s: %s" key (car string-actions))
7561 (cons char (cdr string-actions)))))
7563 (defun anything-c-register-action-transformer (actions register-and-functions)
7564 "Decide actions by the contents of register."
7565 (loop with func-actions =
7566 '((insert-register
7567 "Insert Register" .
7568 (lambda (c) (insert-register (car c))))
7569 (jump-to-register
7570 "Jump to Register" .
7571 (lambda (c) (jump-to-register (car c))))
7572 (append-to-register
7573 "Append Region to Register" .
7574 (lambda (c) (append-to-register
7575 (car c) (region-beginning) (region-end))))
7576 (prepend-to-register
7577 "Prepend Region to Register" .
7578 (lambda (c) (prepend-to-register
7579 (car c) (region-beginning) (region-end))))
7580 (increment-register
7581 "Increment Prefix Arg to Register" .
7582 (lambda (c) (increment-register
7583 anything-current-prefix-arg (car c)))))
7584 for func in (cdr register-and-functions)
7585 for cell = (assq func func-actions)
7586 when cell
7587 collect (cdr cell)))
7589 ;; (anything 'anything-c-source-register)
7592 ;;; Latex completion
7593 (defun anything-c-latex-math-candidates ()
7594 "Collect candidates for latex math completion."
7595 (declare (special LaTeX-math-menu))
7596 (loop for i in (cddr LaTeX-math-menu)
7597 for elm = (loop for s in i when (vectorp s)
7598 collect (cons (aref s 0) (aref s 1)))
7599 append elm))
7601 (defvar anything-c-source-latex-math
7602 '((name . "Latex Math Menu")
7603 (init . (lambda ()
7604 (with-anything-current-buffer
7605 (LaTeX-math-mode 1))))
7606 (candidate-number-limit . 9999)
7607 (candidates . anything-c-latex-math-candidates)
7608 (action . (lambda (candidate)
7609 (call-interactively candidate)))))
7612 ;;;; <Headline Extraction>
7613 (defvar anything-c-source-fixme
7614 '((name . "TODO/FIXME/DRY comments")
7615 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7616 (adjust)
7617 (recenter))
7618 "Show TODO/FIXME/DRY comments in current file.")
7619 ;; (anything 'anything-c-source-fixme)
7621 (defvar anything-c-source-rd-headline
7622 '((name . "RD HeadLine")
7623 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7624 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
7625 (migemo)
7626 (subexp . 1))
7627 "Show RD headlines.
7629 RD is Ruby's POD.
7630 http://en.wikipedia.org/wiki/Ruby_Document_format")
7631 ;; (anything 'anything-c-source-rd-headline)
7633 (defvar anything-c-source-oddmuse-headline
7634 '((name . "Oddmuse HeadLine")
7635 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7636 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7637 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
7638 (migemo)
7639 (subexp . 1))
7640 "Show Oddmuse headlines, such as EmacsWiki.")
7641 ;; (anything 'anything-c-source-oddmuse-headline)
7643 (defvar anything-c-source-emacs-source-defun
7644 '((name . "Emacs Source DEFUN")
7645 (headline . "DEFUN\\|DEFVAR")
7646 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
7647 (or buffer-file-name ""))))
7648 "Show DEFUN/DEFVAR in Emacs C source file.")
7649 ;; (anything 'anything-c-source-emacs-source-defun)
7651 (defvar anything-c-source-emacs-lisp-expectations
7652 '((name . "Emacs Lisp Expectations")
7653 (headline . "(desc[ ]\\|(expectations")
7654 (condition . (eq major-mode 'emacs-lisp-mode)))
7655 "Show descriptions (desc) in Emacs Lisp Expectations.
7657 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7658 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7660 (defvar anything-c-source-emacs-lisp-toplevels
7661 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7662 (headline . "^(\\|(@\\*\\|^;;;;")
7663 (get-line . buffer-substring)
7664 (condition . (eq major-mode 'emacs-lisp-mode))
7665 (adjust))
7666 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7667 linkd.el is optional because linkd stars are extracted by regexp.
7668 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7669 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7672 ;;; Anything yaoddmuse
7674 ;; Be sure to have yaoddmuse.el installed
7675 ;; install-elisp may be required if you want to install elisp file from here.
7676 (defvar anything-yaoddmuse-use-cache-file nil)
7677 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
7678 (defvar anything-c-yaoddmuse-ew-cache nil)
7680 (defun anything-yaoddmuse-get-candidates ()
7681 (declare (special yaoddmuse-pages-hash))
7682 (if anything-yaoddmuse-use-cache-file
7683 (ignore-errors
7684 (unless anything-c-yaoddmuse-ew-cache
7685 (load anything-c-yaoddmuse-cache-file)
7686 (setq anything-c-yaoddmuse-ew-cache
7687 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7688 anything-c-yaoddmuse-ew-cache)
7689 (yaoddmuse-update-pagename t)
7690 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7692 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7693 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
7694 (candidates . anything-yaoddmuse-get-candidates)
7695 (action . (("Edit page" . (lambda (candidate)
7696 (yaoddmuse-edit "EmacsWiki" candidate)))
7697 ("Browse page"
7698 . (lambda (candidate)
7699 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7700 ("Browse page other window"
7701 . (lambda (candidate)
7702 (if (one-window-p)
7703 (split-window-vertically))
7704 (yaoddmuse-browse-page "EmacsWiki" candidate)))
7705 ("Browse diff"
7706 . (lambda (candidate)
7707 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
7708 ("Copy URL"
7709 . (lambda (candidate)
7710 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
7711 (message "Have copy page %s's URL to yank." candidate)))
7712 ("Create page"
7713 . (lambda (candidate)
7714 (yaoddmuse-edit "EmacsWiki" anything-input)))
7715 ("Update cache"
7716 . (lambda (candidate)
7717 (if anything-yaoddmuse-use-cache-file
7718 (progn
7719 (anything-yaoddmuse-cache-pages t)
7720 (setq anything-c-yaoddmuse-ew-cache
7721 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
7722 (yaoddmuse-update-pagename))))))
7723 (action-transformer anything-c-yaoddmuse-action-transformer))
7724 "Needs yaoddmuse.el.
7726 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7728 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7730 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7731 '((name . "Yaoddmuse Post library (EmacsWiki)")
7732 (init . (anything-yaoddmuse-init))
7733 (candidates-in-buffer)
7734 (action . (("Post library and Browse"
7735 . (lambda (candidate)
7736 (yaoddmuse-post-file
7737 (find-library-name candidate)
7738 "EmacsWiki"
7739 (file-name-nondirectory (find-library-name candidate))
7740 nil t)))
7741 ("Post library"
7742 . (lambda (candidate)
7743 (yaoddmuse-post-file
7744 (find-library-name candidate)
7745 "EmacsWiki"
7746 (file-name-nondirectory
7747 (find-library-name candidate))))))))
7748 "Needs yaoddmuse.el.
7750 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7752 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7754 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
7755 "Allow the use of `install-elisp' only on elisp files."
7756 (if (string-match "\.el$" candidate)
7757 (append actions '(("Install Elisp"
7758 . (lambda (elm)
7759 (install-elisp-from-emacswiki elm)))))
7760 actions))
7762 ;;;###autoload
7763 (defun anything-yaoddmuse-cache-pages (&optional load)
7764 "Fetch the list of files on emacswiki and create cache file.
7765 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7766 (interactive)
7767 (declare (special yaoddmuse-pages-hash))
7768 (yaoddmuse-update-pagename)
7769 (save-excursion
7770 (find-file anything-c-yaoddmuse-cache-file)
7771 (erase-buffer)
7772 (insert "(puthash \"EmacsWiki\" '(")
7773 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
7775 (insert (concat "(\"" (car i) "\") ")))
7776 (insert ") yaoddmuse-pages-hash)\n")
7777 (save-buffer)
7778 (kill-buffer (current-buffer))
7779 (when (or current-prefix-arg
7780 load)
7781 (load anything-c-yaoddmuse-cache-file))))
7783 (defun anything-yaoddmuse-init ()
7784 "Init anything buffer status."
7785 (let ((anything-buffer (anything-candidate-buffer 'global))
7786 (library-list (yaoddmuse-get-library-list)))
7787 (with-current-buffer anything-buffer
7788 ;; Insert library name.
7789 (dolist (library library-list)
7790 (insert (format "%s\n" library)))
7791 ;; Sort lines.
7792 (sort-lines nil (point-min) (point-max)))))
7795 ;;; Eev anchors
7796 (defvar anything-c-source-eev-anchor
7797 '((name . "Anchors")
7798 (candidates
7799 . (lambda ()
7800 (ignore-errors
7801 (with-anything-current-buffer
7802 (loop initially (goto-char (point-min))
7803 while (re-search-forward
7804 (format ee-anchor-format "\\([^\.].+\\)") nil t)
7805 for anchor = (match-string-no-properties 1)
7806 collect (cons (format "%5d:%s"
7807 (line-number-at-pos (match-beginning 0))
7808 (format ee-anchor-format anchor))
7809 anchor))))))
7810 (persistent-action . (lambda (item)
7811 (ee-to item)
7812 (anything-match-line-color-current-line)))
7813 (persistent-help . "Show this entry")
7814 (action . (("Goto link" . ee-to)))))
7815 ;; (anything 'anything-c-source-eev-anchor)
7818 ;;; Org headlines
7821 (defvar anything-c-source-org-headline
7822 `((name . "Org HeadLine")
7823 (headline
7824 ,@(mapcar
7825 (lambda (num)
7826 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7827 num))
7828 (number-sequence 1 8)))
7829 (condition . (eq major-mode 'org-mode))
7830 (migemo)
7831 (subexp . 1)
7832 (persistent-action . (lambda (elm)
7833 (anything-c-action-line-goto elm)
7834 (org-cycle)))
7835 (action-transformer
7836 . (lambda (actions candidate)
7837 '(("Go to Line" . anything-c-action-line-goto)
7838 ("Refile to this Headline" . anything-c-org-headline-refile)
7839 ("Insert Link to This Headline"
7840 . anything-c-org-headline-insert-link-to-headline)))))
7841 "Show Org headlines.
7842 org-mode is very very much extended text-mode/outline-mode.
7844 See (find-library \"org.el\")
7845 See http://orgmode.org for the latest version.")
7846 ;; (anything 'anything-c-source-org-headline)
7848 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7849 (insert
7850 (save-excursion
7851 (anything-goto-line (car lineno-and-content))
7852 (and (looking-at org-complex-heading-regexp)
7853 (org-make-link-string (concat "*" (match-string 4)))))))
7855 (defun anything-c-org-headline-refile (lineno-and-content)
7856 "Refile current org entry to LINENO-AND-CONTENT."
7857 (with-anything-current-buffer
7858 (org-cut-subtree)
7859 (anything-goto-line (car lineno-and-content))
7860 (org-end-of-subtree t t)
7861 (let ((org-yank-adjusted-subtrees t))
7862 (org-yank))))
7865 ;;; Org keywords
7868 (defvar anything-c-source-org-keywords
7869 '((name . "Org Keywords")
7870 (init . anything-c-org-keywords-init)
7871 (candidates . anything-c-org-keywords-candidates)
7872 (action . anything-c-org-keywords-insert)
7873 (persistent-action . anything-c-org-keywords-show-help)
7874 (persistent-help . "Show an example and info page to describe this keyword.")
7875 (keywords-examples)
7876 (keywords)))
7877 ;; (anything 'anything-c-source-org-keywords)
7879 (defvar anything-c-org-keywords-info-location
7880 '(("#+TITLE:" . "(org)Export options")
7881 ("#+AUTHOR:" . "(org)Export options")
7882 ("#+DATE:" . "(org)Export options")
7883 ("#+EMAIL:" . "(org)Export options")
7884 ("#+DESCRIPTION:" . "(org)Export options")
7885 ("#+KEYWORDS:" . "(org)Export options")
7886 ("#+LANGUAGE:" . "(org)Export options")
7887 ("#+TEXT:" . "(org)Export options")
7888 ("#+TEXT:" . "(org)Export options")
7889 ("#+OPTIONS:" . "(org)Export options")
7890 ("#+BIND:" . "(org)Export options")
7891 ("#+LINK_UP:" . "(org)Export options")
7892 ("#+LINK_HOME:" . "(org)Export options")
7893 ("#+LATEX_HEADER:" . "(org)Export options")
7894 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
7895 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
7896 ("#+INFOJS_OPT" . "(org)Javascript support")
7897 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
7898 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
7899 ("#+ORGTBL" . "(org)Radio tables")
7900 ("#+HTML:" . "(org)Quoting HTML tags")
7901 ("#+LaTeX:" . "(org)Quoting LaTeX code")
7902 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
7903 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
7904 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
7905 ("#+BEGIN_VERSE" . "(org)Paragraphs")
7906 ("#+BEGIN_SRC" . "(org)Literal examples")
7907 ("#+CAPTION" . "(org)Tables in HTML export")
7908 ("#+LABEL" . "(org)Tables in LaTeX export")
7909 ("#+ATTR_HTML" . "(org)Links")
7910 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
7912 (defun anything-c-org-keywords-init ()
7913 (unless (anything-attr 'keywords-examples)
7914 (require 'org)
7915 (anything-attrset 'keywords-examples
7916 (append
7917 (mapcar
7918 (lambda (x)
7919 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
7920 (cons (match-string 2 x) (match-string 1 x)))
7921 (org-split-string (org-get-current-options) "\n"))
7922 (mapcar 'list org-additional-option-like-keywords)))
7923 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
7925 (defun anything-c-org-keywords-candidates ()
7926 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
7927 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
7928 (anything-attr 'keywords)))
7930 (defun anything-c-org-keywords-insert (keyword)
7931 (cond ((and (string-match "BEGIN" keyword)
7932 (anything-region-active-p))
7933 (let ((beg (region-beginning))
7934 (end (region-end)))
7935 (goto-char end)
7936 (insert "\n#+" (replace-regexp-in-string
7937 "BEGIN" "END" keyword) "\n")
7938 (goto-char beg)
7939 (insert "#+" keyword " ")
7940 (save-excursion (insert "\n"))))
7941 ((string-match "BEGIN" keyword)
7942 (insert "#+" keyword " ")
7943 (save-excursion
7944 (insert "\n#+" (replace-regexp-in-string
7945 "BEGIN" "END" keyword) "\n")))
7946 (t (insert "#+" keyword " "))))
7948 (defun anything-c-org-keywords-show-help (keyword)
7949 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
7950 "(org)In-buffer settings"))
7951 (search-forward (concat "#+" keyword) nil t)
7952 (anything-persistent-highlight-point)
7953 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
7957 ;;; bbdb
7960 (defvar bbdb-records)
7961 (defvar bbdb-buffer-name)
7963 (defun anything-c-bbdb-candidates ()
7964 "Return a list of all names in the bbdb database. The format
7965 is \"Firstname Lastname\"."
7966 (mapcar (lambda (bbdb-record)
7967 (replace-regexp-in-string
7968 "\\s-+$" ""
7969 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
7970 (bbdb-records)))
7972 (defun anything-c-bbdb-create-contact (actions candidate)
7973 "Action transformer that returns only an entry to add the
7974 current `anything-pattern' as new contact. All other actions are
7975 removed."
7976 (if (string= candidate "*Add to contacts*")
7977 '(("Add to contacts" . (lambda (actions)
7978 (bbdb-create-internal
7979 (read-from-minibuffer "Name: " anything-c-bbdb-name)
7980 (read-from-minibuffer "Company: ")
7981 (read-from-minibuffer "Email: ")
7984 (read-from-minibuffer "Note: ")))))
7985 actions))
7987 (defun anything-c-bbdb-get-record (candidate)
7988 "Return record that match CANDIDATE."
7989 (bbdb candidate nil)
7990 (set-buffer "*BBDB*")
7991 (bbdb-current-record))
7993 (defvar anything-c-bbdb-name nil
7994 "Only for internal use.")
7996 (defvar anything-c-source-bbdb
7997 '((name . "BBDB")
7998 (candidates . anything-c-bbdb-candidates)
7999 (action ("Send a mail" . anything-c-bbdb-compose-mail)
8000 ("View person's data" . anything-c-bbdb-view-person-action))
8001 (filtered-candidate-transformer . (lambda (candidates source)
8002 (setq anything-c-bbdb-name anything-pattern)
8003 (if (not candidates)
8004 (list "*Add to contacts*")
8005 candidates)))
8006 (action-transformer . (lambda (actions candidate)
8007 (anything-c-bbdb-create-contact actions candidate))))
8008 "Needs BBDB.
8010 http://bbdb.sourceforge.net/")
8011 ;; (anything 'anything-c-source-bbdb)
8013 (defun anything-c-bbdb-view-person-action (candidate)
8014 "View BBDB data of single CANDIDATE or marked candidates."
8015 (anything-aif (anything-marked-candidates)
8016 (let ((bbdb-append-records (length it)))
8017 (dolist (i it)
8018 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
8019 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
8021 (defun anything-c-bbdb-collect-mail-addresses ()
8022 "Return a list of all mail addresses of records in bbdb buffer."
8023 (with-current-buffer bbdb-buffer-name
8024 (loop for i in bbdb-records
8025 if (bbdb-record-net (car i))
8026 collect (bbdb-dwim-net-address (car i)))))
8028 (defun anything-c-bbdb-compose-mail (candidate)
8029 "Compose a mail with all records of bbdb buffer."
8030 (anything-c-bbdb-view-person-action candidate)
8031 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8032 (address-str (mapconcat 'identity address-list ",\n ")))
8033 (compose-mail address-str)))
8036 ;;; Evaluation Result
8039 ;; Internal
8040 (defvar anything-eldoc-active-minibuffers-list nil)
8041 (defvar anything-eval-expression-input-history nil)
8043 (defvar anything-c-source-evaluation-result
8044 '((name . "Evaluation Result")
8045 (disable-shortcuts)
8046 (dummy)
8047 (multiline)
8048 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8049 (filtered-candidate-transformer . (lambda (candidates source)
8050 (list
8051 (condition-case nil
8052 (with-anything-current-buffer
8053 (pp-to-string
8054 (eval (read anything-pattern))))
8055 (error "Error")))))
8056 (action . (("Copy result to kill-ring" . (lambda (candidate)
8057 (with-current-buffer anything-buffer
8058 (let ((end (save-excursion
8059 (goto-char (point-max))
8060 (search-backward "\n")
8061 (point))))
8062 (kill-region (point) end)))))
8063 ("copy sexp to kill-ring" . (lambda (candidate)
8064 (kill-new anything-input)))))))
8065 ;; (anything 'anything-c-source-evaluation-result)
8067 (defun anything-eval-new-line-and-indent ()
8068 (interactive)
8069 (newline) (lisp-indent-line))
8071 (defun anything-eldoc-store-minibuffer ()
8072 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8073 (with-selected-window (minibuffer-window)
8074 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8076 (defun anything-eldoc-show-in-eval ()
8077 "Return eldoc in mode-line for current minibuffer input."
8078 (let ((buf (with-selected-window (minibuffer-window)
8079 (buffer-name))))
8080 (when (member buf anything-eldoc-active-minibuffers-list)
8081 (let* ((str-all (with-current-buffer buf
8082 (minibuffer-completion-contents)))
8083 (sym (when str-all
8084 (with-temp-buffer
8085 (insert str-all)
8086 (goto-char (point-max))
8087 (unless (looking-back ")\\|\"") (forward-char -1))
8088 (eldoc-current-symbol))))
8089 (info-fn (eldoc-fnsym-in-current-sexp))
8090 (doc (or (eldoc-get-var-docstring sym)
8091 (eldoc-get-fnsym-args-string
8092 (car info-fn) (cadr info-fn)))))
8093 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8095 (defun anything-c-show-info-in-mode-line (str)
8096 "Display string STR in mode-line."
8097 (save-window-excursion
8098 (with-current-buffer anything-buffer
8099 (let ((mode-line-format (concat " " str)))
8100 (force-mode-line-update)
8101 (sit-for anything-c-show-info-in-mode-line-delay))
8102 (force-mode-line-update))))
8104 ;;; Calculation Result
8107 (defvar anything-c-source-calculation-result
8108 '((name . "Calculation Result")
8109 (dummy)
8110 (filtered-candidate-transformer . (lambda (candidates source)
8111 (list
8112 (condition-case nil
8113 (calc-eval anything-pattern)
8114 (error "error")))))
8115 (action ("Copy result to kill-ring" . kill-new))))
8116 ;; (anything 'anything-c-source-calculation-result)
8119 ;;; Google Suggestions
8122 ;; Internal
8123 (defvar anything-ggs-max-length-real-flag 0)
8124 (defvar anything-ggs-max-length-num-flag 0)
8126 (defun anything-c-google-suggest-fetch (input)
8127 "Fetch suggestions for INPUT from XML buffer.
8128 Return an alist with elements like (data . number_results)."
8129 (setq anything-ggs-max-length-real-flag 0
8130 anything-ggs-max-length-num-flag 0)
8131 (let ((request (concat anything-c-google-suggest-url
8132 (url-hexify-string input))))
8133 (flet ((fetch ()
8134 (loop
8135 with result-alist = (xml-get-children
8136 (car (xml-parse-region
8137 (point-min) (point-max)))
8138 'CompleteSuggestion)
8139 for i in result-alist
8140 for data = (cdr (caadr (assoc 'suggestion i)))
8141 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8142 for lqueries = (length (anything-c-ggs-set-number-result
8143 nqueries))
8144 for ldata = (length data)
8146 (progn
8147 (when (> ldata anything-ggs-max-length-real-flag)
8148 (setq anything-ggs-max-length-real-flag ldata))
8149 (when (> lqueries anything-ggs-max-length-num-flag)
8150 (setq anything-ggs-max-length-num-flag lqueries)))
8151 collect (cons data nqueries) into cont
8152 finally return cont)))
8153 (if anything-google-suggest-use-curl-p
8154 (with-temp-buffer
8155 (call-process "curl" nil t nil request)
8156 (fetch))
8157 (with-current-buffer
8158 (url-retrieve-synchronously request)
8159 (fetch))))))
8161 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8162 "Set candidates with result and number of google results found."
8163 (let ((suggestions
8164 (loop with suggested-results = (anything-c-google-suggest-fetch
8165 (or (and request-prefix
8166 (concat request-prefix " " anything-pattern))
8167 anything-pattern))
8168 for (real . numresult) in suggested-results
8169 ;; Prepare number of results with ","
8170 for fnumresult = (anything-c-ggs-set-number-result numresult)
8171 ;; Calculate number of spaces to add before fnumresult
8172 ;; if it is smaller than longest result
8173 ;; `anything-ggs-max-length-num-flag'.
8174 ;; e.g 1,234,567
8175 ;; 345,678
8176 ;; To be sure it is aligned properly.
8177 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8178 (- anything-ggs-max-length-num-flag (length fnumresult))
8180 ;; Add now the spaces before fnumresult.
8181 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8182 for interval = (- anything-ggs-max-length-real-flag (length real))
8183 for spaces = (make-string (+ 2 interval) ? )
8184 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8185 collect (cons display real))))
8186 (if (loop for (disp . dat) in suggestions
8187 thereis (equal dat anything-pattern))
8188 suggestions
8189 ;; if there is no suggestion exactly matching the input then
8190 ;; prepend a Search on Google item to the list
8191 (append
8192 suggestions
8193 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8194 anything-input))))))
8196 (defun anything-c-ggs-set-number-result (num)
8197 (if num
8198 (progn
8199 (and (numberp num) (setq num (number-to-string num)))
8200 (loop for i in (reverse (split-string num "" t))
8201 for count from 1
8202 append (list i) into C
8203 when (= count 3)
8204 append (list ",") into C
8205 and do (setq count 0)
8206 finally return
8207 (replace-regexp-in-string
8208 "^," "" (mapconcat 'identity (reverse C) ""))))
8209 "?"))
8211 (defvar anything-c-google-suggest-default-browser-function nil
8212 "*The browse url function you prefer to use with google suggest.
8213 When nil, use the first browser function available
8214 See `anything-browse-url-default-browser-alist'.")
8216 (defun anything-c-google-suggest-action (candidate)
8217 "Default action to jump to a google suggested candidate."
8218 (let ((arg (concat anything-c-google-suggest-search-url
8219 (url-hexify-string candidate))))
8220 (anything-aif anything-c-google-suggest-default-browser-function
8221 (funcall it arg)
8222 (anything-c-browse-url arg))))
8224 (defvar anything-c-google-suggest-default-function
8225 'anything-c-google-suggest-set-candidates
8226 "Default function to use in anything google suggest.")
8228 (defvar anything-c-source-google-suggest
8229 '((name . "Google Suggest")
8230 (candidates . (lambda ()
8231 (funcall anything-c-google-suggest-default-function)))
8232 (action . (("Google Search" . anything-c-google-suggest-action)))
8233 (volatile)
8234 (requires-pattern . 3)
8235 (delayed)))
8237 (defun anything-c-google-suggest-emacs-lisp ()
8238 "Try to emacs lisp complete with google suggestions."
8239 (anything-c-google-suggest-set-candidates "emacs lisp"))
8241 ;; (anything 'anything-c-source-google-suggest)
8243 ;;; Yahoo suggestions
8246 (defun anything-c-yahoo-suggest-fetch (input)
8247 "Fetch Yahoo suggestions for INPUT from XML buffer.
8248 Return an alist with elements like (data . number_results)."
8249 (let ((request (concat anything-c-yahoo-suggest-url
8250 (url-hexify-string input))))
8251 (flet ((fetch ()
8252 (loop
8253 with result-alist = (xml-get-children
8254 (car (xml-parse-region (point-min) (point-max)))
8255 'Result)
8256 for i in result-alist
8257 collect (caddr i))))
8258 (with-current-buffer
8259 (url-retrieve-synchronously request)
8260 (fetch)))))
8262 (defun anything-c-yahoo-suggest-set-candidates ()
8263 "Set candidates with Yahoo results found."
8264 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8265 (or suggestions
8266 (append
8267 suggestions
8268 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8269 anything-input))))))
8271 (defun anything-c-yahoo-suggest-action (candidate)
8272 "Default action to jump to a Yahoo suggested candidate."
8273 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8274 (url-hexify-string candidate))))
8276 (defvar anything-c-source-yahoo-suggest
8277 '((name . "Yahoo Suggest")
8278 (candidates . anything-c-yahoo-suggest-set-candidates)
8279 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8280 (volatile)
8281 (requires-pattern . 3)
8282 (delayed)))
8284 ;; (anything 'anything-c-source-yahoo-suggest)
8287 ;;; Web browser functions.
8290 (require 'browse-url)
8291 ;; If default setting of `w3m-command' is not
8292 ;; what you want you and you modify it, you will have to reeval
8293 ;; also `anything-browse-url-default-browser-alist'.
8294 (defvar w3m-command "/usr/bin/w3m")
8295 (defvar anything-c-home-url "http://www.google.fr"
8296 "*Default url to use as home url.")
8298 (defvar ac-browse-url-chromium-program "chromium-browser")
8299 (defvar ac-browse-url-uzbl-program "uzbl-browser")
8300 (defvar anything-browse-url-default-browser-alist
8301 `((,w3m-command . w3m-browse-url)
8302 (,browse-url-firefox-program . browse-url-firefox)
8303 (,ac-browse-url-chromium-program . ac-browse-url-chromium)
8304 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl)
8305 (,browse-url-kde-program . browse-url-kde)
8306 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8307 (,browse-url-mozilla-program . browse-url-mozilla)
8308 (,browse-url-galeon-program . browse-url-galeon)
8309 (,browse-url-netscape-program . browse-url-netscape)
8310 (,browse-url-mosaic-program . browse-url-mosaic)
8311 (,browse-url-xterm-program . browse-url-text-xterm))
8312 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8314 (defun* anything-c-generic-browser (url name &rest args)
8315 "Browse URL with NAME browser."
8316 (let ((proc (concat name " " url)))
8317 (message "Starting %s..." name)
8318 (apply 'start-process proc nil name
8319 (append args (list url)))
8320 (set-process-sentinel
8321 (get-process proc)
8322 #'(lambda (process event)
8323 (when (string= event "finished\n")
8324 (message "%s process %s" process event))))))
8326 (defun ac-browse-url-chromium (url)
8327 "Browse URL with google chrome browser."
8328 (interactive "sURL: ")
8329 (anything-c-generic-browser
8330 url ac-browse-url-chromium-program))
8332 (defun ac-browse-url-uzbl (url &optional ignore)
8333 "Browse URL with uzbl browser."
8334 (interactive "sURL: ")
8335 (anything-c-generic-browser url ac-browse-url-uzbl-program "-u"))
8337 (defun anything-browse-url-default-browser (url &rest args)
8338 "Find the first available browser and ask it to load URL."
8339 (let ((default-browser-fn
8340 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8341 thereis (and exe (executable-find exe) fn))))
8342 (if default-browser-fn
8343 (apply default-browser-fn url args)
8344 (error "No usable browser found"))))
8346 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8347 "Default command to browse URL."
8348 (if browse-url-browser-function
8349 (browse-url url)
8350 (anything-browse-url-default-browser url)))
8353 ;;; Surfraw
8355 ;; Need external program surfraw.
8356 ;; <http://surfraw.alioth.debian.org/>
8358 (defvar anything-surfraw-default-browser-function nil
8359 "*The browse url function you prefer to use with surfraw.
8360 When nil, fallback to `browse-url-browser-function'.")
8362 ;; Internal
8363 (defvar anything-surfraw-engines-history nil)
8364 (defvar anything-surfraw-input-history nil)
8366 (defun anything-c-build-elvi-list ()
8367 "Return list of all engines and descriptions handled by surfraw."
8368 (cdr
8369 (with-temp-buffer
8370 (call-process "surfraw" nil t nil
8371 "-elvi")
8372 (split-string (buffer-string) "\n"))))
8375 ;;; Emms
8378 (defun anything-emms-stream-edit-bookmark (elm)
8379 "Change the information of current emms-stream bookmark from anything."
8380 (declare (special emms-stream-list))
8381 (let* ((cur-buf anything-current-buffer)
8382 (bookmark (assoc elm emms-stream-list))
8383 (name (read-from-minibuffer "Description: "
8384 (nth 0 bookmark)))
8385 (url (read-from-minibuffer "URL: "
8386 (nth 1 bookmark)))
8387 (fd (read-from-minibuffer "Feed Descriptor: "
8388 (int-to-string (nth 2 bookmark))))
8389 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8390 (format "%s" (car (last bookmark))))))
8391 (save-excursion
8392 (emms-streams)
8393 (when (re-search-forward (concat "^" name) nil t)
8394 (beginning-of-line)
8395 (emms-stream-delete-bookmark)
8396 (emms-stream-add-bookmark name url (string-to-number fd) type)
8397 (emms-stream-save-bookmarks-file)
8398 (emms-stream-quit)
8399 (anything-c-switch-to-buffer cur-buf)))))
8401 (defun anything-emms-stream-delete-bookmark (elm)
8402 "Delete an emms-stream bookmark from anything."
8403 (let* ((cur-buf anything-current-buffer)
8404 (bookmark (assoc elm emms-stream-list))
8405 (name (nth 0 bookmark)))
8406 (save-excursion
8407 (emms-streams)
8408 (when (re-search-forward (concat "^" name) nil t)
8409 (beginning-of-line)
8410 (emms-stream-delete-bookmark)
8411 (emms-stream-save-bookmarks-file)
8412 (emms-stream-quit)
8413 (anything-c-switch-to-buffer cur-buf)))))
8415 (defvar anything-c-source-emms-streams
8416 '((name . "Emms Streams")
8417 (init . (lambda ()
8418 (emms-stream-init)))
8419 (candidates . (lambda ()
8420 (declare (special emms-stream-list))
8421 (mapcar 'car emms-stream-list)))
8422 (action . (("Play" . (lambda (elm)
8423 (declare (special emms-stream-list))
8424 (let* ((stream (assoc elm emms-stream-list))
8425 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8426 (url (second stream)))
8427 (funcall fn url))))
8428 ("Delete" . anything-emms-stream-delete-bookmark)
8429 ("Edit" . anything-emms-stream-edit-bookmark)))
8430 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8431 ;; (anything 'anything-c-source-emms-streams)
8433 ;; Don't forget to set `emms-source-file-default-directory'
8434 (defvar anything-c-source-emms-dired
8435 '((name . "Music Directory")
8436 (candidates . (lambda ()
8437 (cddr (directory-files emms-source-file-default-directory))))
8438 (action .
8439 (("Play Directory" . (lambda (item)
8440 (emms-play-directory
8441 (expand-file-name
8442 item
8443 emms-source-file-default-directory))))
8444 ("Open dired in file's directory" . (lambda (item)
8445 (anything-c-open-dired
8446 (expand-file-name
8447 item
8448 emms-source-file-default-directory))))))
8449 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8450 ;; (anything 'anything-c-source-emms-dired)
8453 (defun anything-c-emms-files-modifier (candidates source)
8454 (let ((current-playlist (with-current-emms-playlist
8455 (loop
8456 with cur-list = (emms-playlist-tracks-in-region
8457 (point-min) (point-max))
8458 for i in cur-list
8459 collect (assoc-default 'name i)))))
8460 (loop for i in candidates
8461 if (member (cdr i) current-playlist)
8462 collect (cons (propertize (car i)
8463 'face 'anything-emms-playlist)
8464 (cdr i)) into lis
8465 else collect i into lis
8466 finally return lis)))
8468 (defun anything-c-emms-play-current-playlist ()
8469 "Play current playlist."
8470 (with-current-emms-playlist
8471 (emms-playlist-first)
8472 (emms-playlist-mode-play-smart)))
8474 (defvar anything-c-source-emms-files
8475 '((name . "Emms files")
8476 (candidates . (lambda ()
8477 (loop for v being the hash-values in emms-cache-db
8478 for name = (assoc-default 'name v)
8479 for artist = (or (assoc-default 'info-artist v) "unknown")
8480 for genre = (or (assoc-default 'info-genre v) "unknown")
8481 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
8482 for song = (or (assoc-default 'info-title v) "unknown")
8483 for info = (concat artist " - " genre " - " tracknum ": " song)
8484 unless (string-match "^http:" name) collect (cons info name))))
8485 (filtered-candidate-transformer . anything-c-emms-files-modifier)
8486 (action . (("Play file" . emms-play-file)
8487 ("Add to Playlist and play (C-u clear current)"
8488 . (lambda (candidate)
8489 (when anything-current-prefix-arg
8490 (emms-playlist-current-clear))
8491 (emms-playlist-new)
8492 (mapc 'emms-add-playlist-file (anything-marked-candidates))
8493 (unless emms-player-playing-p
8494 (anything-c-emms-play-current-playlist))))))))
8496 ;; (anything 'anything-c-source-emms-files)
8499 ;;; Jabber Contacts (jabber.el)
8500 (defun anything-c-jabber-online-contacts ()
8501 "List online Jabber contacts."
8502 (with-no-warnings
8503 (let (jids)
8504 (dolist (item (jabber-concat-rosters) jids)
8505 (when (get item 'connected)
8506 (push (if (get item 'name)
8507 (cons (get item 'name) item)
8508 (cons (symbol-name item) item)) jids))))))
8510 (defvar anything-c-source-jabber-contacts
8511 '((name . "Jabber Contacts")
8512 (init . (lambda () (require 'jabber)))
8513 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
8514 (action . (lambda (x)
8515 (jabber-chat-with
8516 (jabber-read-account)
8517 (symbol-name
8518 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
8519 ;; (anything 'anything-c-source-jabber-contacts)
8523 ;;; Call source.
8524 (defvar anything-source-select-buffer "*anything source select*")
8525 (defvar anything-c-source-call-source
8526 `((name . "Call anything source")
8527 (candidate-number-limit)
8528 (candidates
8529 . (lambda ()
8530 (loop for vname in (all-completions "anything-c-source-" obarray)
8531 for var = (intern vname)
8532 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
8533 if name collect
8534 (cons (format "%s `%s'"
8535 name (propertize vname 'face 'font-lock-variable-name-face))
8536 var))))
8537 (action
8538 . (("Invoke anything with selected source"
8540 (lambda (candidate)
8541 (setq anything-candidate-number-limit 9999)
8542 (anything candidate nil nil nil nil
8543 anything-source-select-buffer)))
8544 ("Describe variable" . describe-variable)
8545 ("Find variable" . find-variable)))
8546 (persistent-action . describe-variable)
8547 (persistent-help . "Show description of this source")))
8548 ;; (anything 'anything-c-source-call-source)
8550 (defun anything-call-source-from-anything ()
8551 "Call anything source within `anything' session."
8552 (interactive)
8553 (setq anything-input-idle-delay 0)
8554 (anything-set-sources '(anything-c-source-call-source)))
8556 ;;; Execute Preconfigured anything.
8557 (defvar anything-c-source-anything-commands
8558 '((name . "Preconfigured Anything")
8559 (candidates . anything-c-anything-commands-candidates)
8560 (type . command)
8561 (candidate-number-limit)))
8562 ;; (anything 'anything-c-source-anything-commands)
8564 (defun anything-c-anything-commands-candidates ()
8565 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
8566 collect (cons (if (where-is-internal cmd nil t)
8567 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
8568 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
8569 cmd)))
8572 ;;; Occur
8575 (defun anything-c-occur-init ()
8576 "Create the initial anything occur buffer.
8577 If region is active use region as buffer contents
8578 instead of whole buffer."
8579 (with-current-buffer (anything-candidate-buffer 'global)
8580 (erase-buffer)
8581 (let ((buf-contents
8582 (with-anything-current-buffer
8583 (if (anything-region-active-p)
8584 (buffer-substring (region-beginning) (region-end))
8585 (buffer-substring (point-min) (point-max))))))
8586 (insert buf-contents))))
8588 (defun anything-c-occur-get-line (s e)
8589 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
8591 (defun anything-c-occur-query-replace-regexp (candidate)
8592 "Query replace regexp starting from CANDIDATE.
8593 If region is active ignore CANDIDATE and replace only in region.
8594 With a prefix arg replace only matches surrounded by word boundaries,
8595 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8596 (let ((regexp anything-input))
8597 (unless (anything-region-active-p)
8598 (anything-c-action-line-goto candidate))
8599 (apply 'query-replace-regexp
8600 (anything-c-query-replace-args regexp))))
8602 (defvar anything-c-source-occur
8603 '((name . "Occur")
8604 (init . anything-c-occur-init)
8605 (candidates-in-buffer)
8606 (migemo)
8607 (get-line . anything-c-occur-get-line)
8608 (display-to-real . anything-c-display-to-real-line)
8609 (action . (("Go to Line" . anything-c-action-line-goto)
8610 ("Query replace regexp (C-u Not inside word.)"
8611 . anything-c-occur-query-replace-regexp)))
8612 (recenter)
8613 (requires-pattern . 1)
8614 (delayed)
8615 (volatile)))
8616 ;; (anything 'anything-c-source-occur)
8619 ;;; Anything browse code.
8620 (defun anything-c-browse-code-get-line (beg end)
8621 "Select line if it match the regexp corresponding to current `major-mode'.
8622 Line is parsed for BEG position to END position."
8623 (let ((str-line (buffer-substring beg end))
8624 (regexp (assoc-default major-mode
8625 anything-c-browse-code-regexp-alist))
8626 (num-line (if (string= anything-pattern "") beg (1- beg))))
8627 (when (and regexp (string-match regexp str-line))
8628 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
8631 (defvar anything-c-source-browse-code
8632 '((name . "Browse code")
8633 (init . (lambda ()
8634 (anything-candidate-buffer anything-current-buffer)
8635 (with-anything-current-buffer
8636 (jit-lock-fontify-now))))
8637 (candidate-number-limit . 9999)
8638 (candidates-in-buffer)
8639 (get-line . anything-c-browse-code-get-line)
8640 (type . line)
8641 (recenter)))
8644 ;; Do many actions for input
8645 (defvar anything-c-source-create
8646 '((name . "Create")
8647 (dummy)
8648 (action)
8649 (action-transformer . anything-create--actions))
8650 "Do many create actions from `anything-pattern'.
8651 See also `anything-create--actions'.")
8652 ;; (anything 'anything-c-source-create)
8654 (defun anything-create-from-anything ()
8655 "Run `anything-create' from `anything' as a fallback."
8656 (interactive)
8657 (anything-run-after-quit 'anything-create nil anything-pattern))
8659 (defun anything-create--actions (&rest ignored)
8660 "Default actions for `anything-create' / `anything-c-source-create'."
8661 (remove-if-not
8662 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
8663 (append anything-create--actions-private
8664 '(("find-file" . find-file)
8665 ("find-file other window" . find-file-other-window)
8666 ("New buffer" . anything-c-switch-to-buffer)
8667 ("New buffer other window" . switch-to-buffer-other-window)
8668 ("Bookmark Set" . bookmark-set)
8669 ("Set Register" .
8670 (lambda (x) (set-register (read-char "Register: ") x)))
8671 ("Insert Linkd star" . linkd-insert-star)
8672 ("Insert Linkd Tag" . linkd-insert-tag)
8673 ("Insert Linkd Link" . linkd-insert-link)
8674 ("Insert Linkd Lisp" . linkd-insert-lisp)
8675 ("Insert Linkd Wiki" . linkd-insert-wiki)
8676 ("Google Search" . google)))))
8679 ;; Minibuffer History
8682 (defvar anything-c-source-minibuffer-history
8683 '((name . "Minibuffer History")
8684 (header-name . (lambda (name)
8685 (format "%s (%s)" name minibuffer-history-variable)))
8686 (candidates
8687 . (lambda ()
8688 (let ((history (loop
8689 for i in (symbol-value minibuffer-history-variable)
8690 unless (string= "" i) collect i)))
8691 (if (consp (car history))
8692 (mapcar 'prin1-to-string history)
8693 history))))
8694 (migemo)
8695 (action . insert)))
8696 ;; (anything 'anything-c-source-minibuffer-history)
8699 ;;; Elscreen
8702 (defvar anything-c-source-elscreen
8703 '((name . "Elscreen")
8704 (candidates . (lambda ()
8705 (if (cdr (elscreen-get-screen-to-name-alist))
8706 (sort
8707 (loop for sname in (elscreen-get-screen-to-name-alist)
8708 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
8709 finally (return lst))
8710 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
8711 (action . (("Change Screen".
8712 (lambda (candidate)
8713 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
8714 ("Kill Screen(s)".
8715 (lambda (candidate)
8716 (dolist (i (anything-marked-candidates))
8717 (elscreen-goto (- (aref i 1) (aref "0" 0)))
8718 (elscreen-kill))))
8719 ("Only Screen".
8720 (lambda (candidate)
8721 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
8722 (elscreen-kill-others)))))))
8723 ;; (anything 'anything-c-source-elscreen)
8726 ;;;; <System>
8728 ;;; Top (process)
8729 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
8730 "Top command (batch mode). %s is replaced with `frame-width'.")
8731 (defvar anything-c-source-top
8732 '((name . "Top (Press C-c C-u to refresh)")
8733 (init . anything-c-top-init)
8734 (candidates-in-buffer)
8735 (display-to-real . anything-c-top-display-to-real)
8736 (update . anything-c-top-update)
8737 (persistent-action . anything-c-top-sh-persistent-action)
8738 (persistent-help . "SIGTERM")
8739 (action
8740 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
8741 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
8742 ("Copy PID" . (lambda (pid) (kill-new pid))))))
8743 ;; (anything 'anything-c-source-top)
8745 (defun anything-c-top-sh (cmd)
8746 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
8748 (defun anything-c-top-sh-persistent-action (pid)
8749 (delete-other-windows)
8750 (anything-c-top-sh (format "kill -TERM %s" pid))
8751 (anything-force-update))
8753 (defun anything-c-top-init ()
8754 (with-current-buffer (anything-candidate-buffer 'global)
8755 (call-process-shell-command
8756 (format anything-c-top-command
8757 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
8758 nil (current-buffer))))
8760 (defun anything-c-top-display-to-real (line)
8761 (car (split-string line)))
8763 (defun anything-c-top-update ()
8764 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
8765 (anything-c-top-init)))
8767 ;;; Timers
8768 (defvar anything-c-source-absolute-time-timers
8769 '((name . "Absolute Time Timers")
8770 (candidates . timer-list)
8771 (type . timer)))
8772 ;; (anything 'anything-c-source-absolute-time-timers)
8774 (defvar anything-c-source-idle-time-timers
8775 '((name . "Idle Time Timers")
8776 (candidates . timer-idle-list)
8777 (type . timer)))
8778 ;; (anything 'anything-c-source-idle-time-timers)
8780 (defun anything-c-timer-real-to-display (timer)
8781 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
8782 (append timer nil) ;use `append' to convert vector->list
8783 (format "%s repeat=%5S %s(%s)"
8784 (let ((time (list t1 t2 t3)))
8785 (if idle-delay
8786 (format-time-string "idle-for=%5s" time)
8787 (format-time-string "%m/%d %T" time)))
8788 repeat-delay
8789 func
8790 (mapconcat 'prin1-to-string args " "))))
8792 ;;; X RandR resolution change
8793 ;;; FIXME I do not care multi-display.
8794 (defvar anything-c-xrandr-output "VGA")
8795 (defvar anything-c-xrandr-screen "0")
8796 (defvar anything-c-source-xrandr-change-resolution
8797 '((name . "Change Resolution")
8798 (candidates
8799 . (lambda ()
8800 (with-temp-buffer
8801 (call-process "xrandr" nil (current-buffer) nil
8802 "--screen" anything-c-xrandr-screen "-q")
8803 (goto-char 1)
8804 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
8805 collect (match-string 1)))))
8806 (action
8807 ("Change Resolution" . (lambda (mode)
8808 (call-process "xrandr" nil nil nil
8809 "--screen" anything-c-xrandr-screen
8810 "--output" anything-c-xrandr-output
8811 "--mode" mode))))))
8812 ;; (anything 'anything-c-source-xrandr-change-resolution)
8814 ;;; Xfont selection
8817 (defun anything-c-persistent-xfont-action (elm)
8818 "Show current font temporarily"
8819 (let ((current-font (cdr (assoc 'font (frame-parameters))))
8820 (default-font elm))
8821 (unwind-protect
8822 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
8823 (set-frame-font current-font))))
8825 (defvar anything-c-xfonts-cache nil)
8826 (defvar anything-c-source-xfonts
8827 '((name . "X Fonts")
8828 (init . (lambda ()
8829 (unless anything-c-xfonts-cache
8830 (setq anything-c-xfonts-cache
8831 (x-list-fonts "*")))))
8832 (candidates . anything-c-xfonts-cache)
8833 (action . (("Copy to kill ring" . (lambda (elm)
8834 (kill-new elm)))
8835 ("Set Font" . (lambda (elm)
8836 (kill-new elm)
8837 (set-frame-font elm 'keep-size)
8838 (message "New font have been copied to kill ring")))))
8839 (persistent-action . anything-c-persistent-xfont-action)
8840 (persistent-help . "Switch to this font temporarily")))
8841 ;; (anything 'anything-c-source-xfonts)
8843 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8846 (defvar anything-c-ucs-max-len 0)
8847 (defun anything-c-calculate-ucs-max-len ()
8848 "Calculate the length of longest `ucs-names' candidate."
8849 (loop with count = 0
8850 for (n . v) in (ucs-names)
8851 for len = (length n)
8852 if (> len count)
8853 do (setq count len)
8854 finally return count))
8856 (defun anything-c-ucs-init ()
8857 "Initialize an anything buffer with ucs symbols.
8858 Only math* symbols are collected."
8859 (unless (> anything-c-ucs-max-len 0)
8860 (setq anything-c-ucs-max-len
8861 (anything-c-calculate-ucs-max-len)))
8862 (with-current-buffer (anything-candidate-buffer
8863 (get-buffer-create "*anything ucs*"))
8864 ;; `ucs-names' fn will not run again, data is cached in
8865 ;; var `ucs-names'.
8866 (loop for (n . v) in (ucs-names)
8867 for len = (length n)
8868 for diff = (+ (- anything-c-ucs-max-len len) 2)
8869 unless (string= "" n)
8870 do (progn (insert (concat
8871 n ":"
8872 (make-string
8873 diff ? )))
8874 (ucs-insert v)
8875 (insert "\n")))))
8877 (defun anything-c-ucs-forward-char (candidate)
8878 (with-anything-current-buffer
8879 (forward-char 1)))
8881 (defun anything-c-ucs-backward-char (candidate)
8882 (with-anything-current-buffer
8883 (forward-char -1)))
8885 (defun anything-c-ucs-delete-backward (candidate)
8886 (with-anything-current-buffer
8887 (delete-char -1)))
8889 (defun anything-c-ucs-insert-char (candidate)
8890 (with-anything-current-buffer
8891 (insert
8892 (replace-regexp-in-string
8893 " " ""
8894 (cadr (split-string candidate ":"))))))
8896 (defun anything-c-ucs-persistent-insert ()
8897 (interactive)
8898 (anything-execute-persistent-action 'action-insert))
8900 (defun anything-c-ucs-persistent-forward ()
8901 (interactive)
8902 (anything-execute-persistent-action 'action-forward))
8904 (defun anything-c-ucs-persistent-backward ()
8905 (interactive)
8906 (anything-execute-persistent-action 'action-back))
8908 (defun anything-c-ucs-persistent-delete ()
8909 (interactive)
8910 (anything-execute-persistent-action 'action-delete))
8912 (defvar anything-c-source-ucs
8913 '((name . "Ucs names")
8914 (init . anything-c-ucs-init)
8915 (candidate-number-limit . 9999)
8916 (candidates-in-buffer)
8917 (mode-line . anything-c-ucs-mode-line-string)
8918 (action-insert . anything-c-ucs-insert-char)
8919 (action-forward . anything-c-ucs-forward-char)
8920 (action-back . anything-c-ucs-backward-char)
8921 (action-delete . anything-c-ucs-delete-backward)
8922 (action . (("Insert" . anything-c-ucs-insert-char)
8923 ("Forward char" . anything-c-ucs-forward-char)
8924 ("Backward char" . anything-c-ucs-backward-char)
8925 ("Delete char backward" . anything-c-ucs-delete-backward))))
8926 "Source for collecting `ucs-names' math symbols.")
8929 ;;; Emacs process
8932 (defvar anything-c-source-emacs-process
8933 '((name . "Emacs Process")
8934 (candidates . (lambda () (mapcar #'process-name (process-list))))
8935 (persistent-action . (lambda (elm)
8936 (delete-process (get-process elm))
8937 (anything-delete-current-selection)))
8938 (persistent-help . "Kill Process")
8939 (action ("Kill Process" . (lambda (elm)
8940 (delete-process (get-process elm)))))))
8941 ;; (anything 'anything-c-source-emacs-process)
8943 ;;; World time
8946 (defvar anything-c-source-time-world
8947 '((name . "Time World List")
8948 (init . (lambda ()
8949 (let ((anything-buffer (anything-candidate-buffer 'global)))
8950 (with-current-buffer anything-buffer
8951 (display-time-world-display display-time-world-list)))))
8952 (candidates-in-buffer)))
8956 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8959 (defvar anything-c-source-apt
8960 '((name . "APT")
8961 (init . anything-c-apt-init)
8962 (candidates-in-buffer)
8963 (candidate-transformer anything-c-apt-candidate-transformer)
8964 (display-to-real . anything-c-apt-display-to-real)
8965 (requires-pattern . 2)
8966 (update . anything-c-apt-refresh)
8967 (action
8968 ("Show package description" . anything-c-apt-cache-show)
8969 ("Install package" . anything-c-apt-install)
8970 ("Remove package" . anything-c-apt-uninstall)
8971 ("Purge package" . anything-c-apt-purge))
8972 (persistent-action . anything-c-apt-persistent-action)
8973 (persistent-help . "Show package description")))
8974 ;; (anything 'anything-c-source-apt)
8976 (defvar anything-c-apt-query "emacs")
8977 (defvar anything-c-apt-search-command "apt-cache search '%s'")
8978 (defvar anything-c-apt-show-command "apt-cache show '%s'")
8979 (defvar anything-c-apt-installed-packages nil)
8980 (defvar anything-c-apt-all-packages nil)
8981 (defvar anything-c-apt-input-history nil)
8983 (defun anything-c-apt-refresh ()
8984 "Refresh installed candidates list."
8985 (setq anything-c-apt-installed-packages nil)
8986 (setq anything-c-apt-all-packages nil))
8988 (defun anything-c-apt-persistent-action (candidate)
8989 "Persistent action for APT source."
8990 (anything-c-apt-cache-show candidate))
8992 (defun anything-c-apt-candidate-transformer (candidates)
8993 "Show installed candidates in a different color."
8994 (loop
8995 with all
8996 for cand in candidates
8997 for name = (anything-c-apt-display-to-real cand)
8998 if (member name anything-c-apt-installed-packages)
8999 collect (propertize cand 'face 'anything-apt-installed) into all
9000 else collect cand into all finally return all))
9002 (defun anything-c-apt-init ()
9003 "Initialize list of debian packages."
9004 (let ((query ""))
9005 (unless (and anything-c-apt-installed-packages
9006 anything-c-apt-all-packages)
9007 (message "Loading package list...")
9008 (setq anything-c-apt-installed-packages
9009 (with-temp-buffer
9010 (call-process-shell-command "dpkg --get-selections"
9011 nil (current-buffer))
9012 (loop for i in (split-string (buffer-string) "\n" t)
9013 collect (car (split-string i)))))
9014 (setq anything-c-apt-all-packages
9015 (with-current-buffer
9016 (anything-candidate-buffer
9017 (get-buffer-create (format "*anything-apt*")))
9018 (erase-buffer)
9019 (call-process-shell-command
9020 (format anything-c-apt-search-command query)
9021 nil (current-buffer))))
9022 (message "Loading package list done")
9023 (sit-for 0.5))))
9025 (defun anything-c-apt-display-to-real (line)
9026 "Return only name of a debian package.
9027 LINE is displayed like:
9028 package name - description."
9029 (car (split-string line " - ")))
9031 (defun anything-c-shell-command-if-needed (command)
9032 "Run shell command COMMAND to describe package.
9033 If a buffer named COMMAND already exists, just switch to it."
9034 (let ((buf (get-buffer command)))
9035 (anything-c-switch-to-buffer (get-buffer-create command))
9036 (unless buf (insert (shell-command-to-string command)))))
9038 (defun anything-c-apt-cache-show (package)
9039 "Show information on apt package PACKAGE."
9040 (anything-c-shell-command-if-needed
9041 (format anything-c-apt-show-command package)))
9043 (defun anything-c-apt-install (package)
9044 "Run 'apt-get install' shell command on PACKAGE."
9045 (anything-c-apt-generic-action :action 'install))
9047 (defun anything-c-apt-uninstall (package)
9048 "Run 'apt-get remove' shell command on PACKAGE."
9049 (anything-c-apt-generic-action :action 'uninstall))
9051 (defun anything-c-apt-purge (package)
9052 "Run 'apt-get purge' shell command on PACKAGE."
9053 (anything-c-apt-generic-action :action 'purge))
9055 (defun* anything-c-apt-generic-action (&key action)
9056 "Run 'apt-get ACTION'.
9057 Support install, remove and purge actions."
9058 (ansi-term (getenv "SHELL") "anything apt")
9059 (term-line-mode)
9060 (let ((command (case action
9061 ('install "sudo apt-get install ")
9062 ('uninstall "sudo apt-get remove ")
9063 ('purge "sudo apt-get purge ")
9064 (t (error "Unknow action"))))
9065 (beg (point))
9067 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9068 (anything-marked-candidates) " ")))
9069 (goto-char (point-max))
9070 (insert (concat command cand-list))
9071 (setq end (point))
9072 (if (y-or-n-p (format "%s package" (symbol-name action)))
9073 (progn
9074 (setq anything-c-external-commands-list nil)
9075 (setq anything-c-apt-installed-packages nil)
9076 (term-char-mode) (term-send-input))
9077 (delete-region beg end) (term-send-eof) (kill-buffer))))
9079 ;; (anything-c-apt-install "jed")
9082 ;;; Anything UI for gentoo portage.
9085 (defvar anything-c-gentoo-use-flags nil)
9086 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9087 (defvar anything-c-cache-gentoo nil)
9088 (defvar anything-c-cache-world nil)
9089 (defvar anything-c-source-gentoo
9090 '((name . "Portage sources")
9091 (init . (lambda ()
9092 (get-buffer-create anything-c-gentoo-buffer)
9093 (unless anything-c-cache-gentoo
9094 (anything-c-gentoo-setup-cache))
9095 (unless anything-c-cache-world
9096 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9097 (anything-c-gentoo-init-list)))
9098 (candidates-in-buffer)
9099 (match . identity)
9100 (candidate-transformer anything-c-highlight-world)
9101 (action . (("Show package" . (lambda (elm)
9102 (anything-c-gentoo-eshell-action elm "eix")))
9103 ("Show history" . (lambda (elm)
9104 (if (member elm anything-c-cache-world)
9105 (anything-c-gentoo-eshell-action elm "genlop -qe")
9106 (message "No infos on packages not yet installed"))))
9107 ("Copy in kill-ring" . kill-new)
9108 ("insert at point" . insert)
9109 ("Browse HomePage" . (lambda (elm)
9110 (let ((urls (anything-c-gentoo-get-url elm)))
9111 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9112 ("Show extra infos" . (lambda (elm)
9113 (if (member elm anything-c-cache-world)
9114 (anything-c-gentoo-eshell-action elm "genlop -qi")
9115 (message "No infos on packages not yet installed"))))
9116 ("Show use flags" . (lambda (elm)
9117 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9118 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9119 (font-lock-mode 1)))
9120 ("Run emerge pretend" . (lambda (elm)
9121 (anything-c-gentoo-eshell-action elm "emerge -p")))
9122 ("Emerge" . (lambda (elm)
9123 (anything-gentoo-install elm :action 'install)))
9124 ("Unmerge" . (lambda (elm)
9125 (anything-gentoo-install elm :action 'uninstall)))
9126 ("Show dependencies" . (lambda (elm)
9127 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9128 ("Show related files" . (lambda (elm)
9129 (anything-c-gentoo-default-action elm "equery" "files")))
9130 ("Refresh" . (lambda (elm)
9131 (anything-c-gentoo-setup-cache)
9132 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9134 ;; (anything 'anything-c-source-gentoo)
9136 (defun* anything-gentoo-install (candidate &key action)
9137 (setq anything-c-external-commands-list nil)
9138 (ansi-term (getenv "SHELL") "Gentoo emerge")
9139 (term-line-mode)
9140 (let ((command (case action
9141 ('install "sudo emerge -av ")
9142 ('uninstall "sudo emerge -avC ")
9143 (t (error "Unknow action"))))
9144 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9145 (beg (point)) end)
9146 (goto-char (point-max))
9147 (insert (concat command elms))
9148 (setq end (point))
9149 (term-char-mode) (term-send-input)))
9151 (defun anything-c-gentoo-default-action (elm command &rest args)
9152 "Gentoo default action that use `anything-c-gentoo-buffer'."
9153 (if (member elm anything-c-cache-world)
9154 (progn
9155 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9156 (erase-buffer)
9157 (let ((com-list (append args (list elm))))
9158 (apply #'call-process command nil t nil
9159 com-list)))
9160 (message "No infos on packages not yet installed")))
9162 (defvar anything-c-source-use-flags
9163 '((name . "Use Flags")
9164 (init . (lambda ()
9165 (unless anything-c-gentoo-use-flags
9166 (anything-c-gentoo-setup-use-flags-cache))
9167 (anything-c-gentoo-get-use)))
9168 (candidates-in-buffer)
9169 (match . identity)
9170 (candidate-transformer anything-c-highlight-local-use)
9171 (action . (("Description"
9172 . (lambda (elm)
9173 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9174 (erase-buffer)
9175 (apply #'call-process "euse" nil t nil
9176 `("-i"
9177 ,elm))
9178 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9179 (font-lock-mode 1)))
9180 ("Enable"
9181 . (lambda (elm)
9182 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9183 ("Disable"
9184 . (lambda (elm)
9185 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9186 ("Remove"
9187 . (lambda (elm)
9188 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9189 ("Show which dep use this flag"
9190 . (lambda (elm)
9191 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9192 (erase-buffer)
9193 (apply #'call-process "equery" nil t nil
9194 `("-C"
9196 ,elm))))))))
9199 ;; (anything 'anything-c-source-use-flags)
9201 (defun anything-c-gentoo-init-list ()
9202 "Initialize buffer with all packages in Portage."
9203 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9204 (buf (anything-candidate-buffer 'portage-buf)))
9205 (with-current-buffer buf
9206 (dolist (i anything-c-cache-gentoo)
9207 (insert (concat i "\n"))))))
9209 (defun anything-c-gentoo-setup-cache ()
9210 "Set up `anything-c-cache-gentoo'"
9211 (setq anything-c-cache-gentoo
9212 (split-string (with-temp-buffer
9213 (call-process "eix" nil t nil
9214 "--only-names")
9215 (buffer-string)))))
9217 (defun anything-c-gentoo-eshell-action (elm command)
9218 (when (get-buffer "*EShell Command Output*")
9219 (kill-buffer "*EShell Command Output*"))
9220 (message "Wait searching...")
9221 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9222 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9223 (progn
9224 (save-window-excursion
9225 (pop-to-buffer "*scratch*")
9226 (eshell-command (format "%s %s" command elm)))
9227 (pop-to-buffer "*EShell Command Output*"))
9228 (eshell-command (format "%s %s" command elm)))))
9230 (defun anything-c-gentoo-get-use ()
9231 "Initialize buffer with all use flags."
9232 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9233 (buf (anything-candidate-buffer 'use-buf)))
9234 (with-current-buffer buf
9235 (dolist (i anything-c-gentoo-use-flags)
9236 (insert (concat i "\n"))))))
9239 (defun anything-c-gentoo-setup-use-flags-cache ()
9240 "Setup `anything-c-gentoo-use-flags'"
9241 (setq anything-c-gentoo-use-flags
9242 (split-string (with-temp-buffer
9243 (call-process "eix" nil t nil
9244 "--print-all-useflags")
9245 (buffer-string)))))
9247 (defun anything-c-gentoo-get-url (elm)
9248 "Return a list of urls from eix output."
9249 (loop
9250 with url-list = (split-string
9251 (with-temp-buffer
9252 (call-process "eix" nil t nil
9253 elm "--format" "<homepage>\n")
9254 (buffer-string)))
9255 with all
9256 for i in url-list
9257 when (and (string-match "^http://.*" i)
9258 (not (member i all)))
9259 collect i into all
9260 finally return all))
9262 (defun anything-c-gentoo-get-world ()
9263 "Return list of all installed package on your system."
9264 (split-string (with-temp-buffer
9265 (call-process "qlist" nil t nil
9266 "-I")
9267 (buffer-string))))
9269 (defun anything-c-gentoo-get-local-use ()
9270 (split-string (with-temp-buffer
9271 (call-process "portageq" nil t nil
9272 "envvar"
9273 "USE")
9274 (buffer-string))))
9277 (defun anything-c-highlight-world (eix)
9278 "Highlight all installed package."
9279 (loop for i in eix
9280 if (member i anything-c-cache-world)
9281 collect (propertize i 'face 'anything-gentoo-match-face)
9282 else
9283 collect i))
9285 (defun anything-c-highlight-local-use (use-flags)
9286 (let ((local-uses (anything-c-gentoo-get-local-use)))
9287 (loop for i in use-flags
9288 if (member i local-uses)
9289 collect (propertize i 'face 'anything-gentoo-match-face)
9290 else
9291 collect i)))
9295 ;;; Anything ratpoison UI
9298 (defvar anything-c-source-ratpoison-commands
9299 '((name . "Ratpoison Commands")
9300 (init . anything-c-ratpoison-commands-init)
9301 (candidates-in-buffer)
9302 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9303 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9304 (candidate-number-limit)))
9305 ;; (anything 'anything-c-source-ratpoison-commands)
9307 (defun anything-c-ratpoison-commands-init ()
9308 (unless (anything-candidate-buffer)
9309 (with-current-buffer (anything-candidate-buffer 'global)
9310 ;; with ratpoison prefix key
9311 (save-excursion
9312 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9313 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9314 (replace-match "<ratpoison> \\1: \\2"))
9315 (goto-char (point-max))
9316 ;; direct binding
9317 (save-excursion
9318 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9319 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9320 (replace-match "\\1: \\2")))))
9322 (defun anything-c-ratpoison-commands-display-to-real (display)
9323 (and (string-match ": " display)
9324 (substring display (match-end 0))))
9326 (defun anything-c-ratpoison-commands-execute (candidate)
9327 (call-process "ratpoison" nil nil nil "-ic" candidate))
9331 ;;; Anything `completing-read' replacement
9334 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9335 "Convert COLLECTION to list removing elements that don't match TEST.
9336 See `anything-comp-read' about supported COLLECTION arguments.
9338 SORT-FN is a predicate to sort COLLECTION.
9340 ALISTP when non--nil will not use `all-completions' to collect
9341 candidates because it doesn't handle alists correctly for anything.
9342 i.e In `all-completions' the keys \(cars of elements\)
9343 are the possible completions. In anything we want to use the cdr instead
9344 like \(display . real\).
9348 \(setq A '((a . 1) (b . 2) (c . 3)))
9349 ==>((a . 1) (b . 2) (c . 3))
9350 \(anything-comp-read \"test: \" A :alistp nil
9351 :exec-when-only-one t
9352 :initial-input \"a\")
9353 ==>\"a\"
9354 \(anything-comp-read \"test: \" A :alistp t
9355 :exec-when-only-one t
9356 :initial-input \"1\")
9357 ==>\"1\"
9359 See docstring of `all-completions' for more info.
9361 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9362 (let ((cands
9363 (cond ((and (eq collection obarray) test)
9364 (all-completions "" collection test))
9365 ((and (vectorp collection) test)
9366 (loop for i across collection when (funcall test i) collect i))
9367 ((vectorp collection)
9368 (loop for i across collection collect i))
9369 ((and alistp test)
9370 (loop for i in collection when (funcall test i) collect i))
9371 ((and (symbolp collection) (boundp collection))
9372 (symbol-value collection))
9373 (alistp collection)
9374 ((and collection test)
9375 (all-completions "" collection test))
9376 (t (all-completions "" collection)))))
9377 (if sort-fn (sort cands sort-fn) cands)))
9379 (defun anything-cr-default-transformer (candidates source)
9380 "Default filter candidate function for `anything-comp-read'.
9381 Do nothing, just return candidate list unmodified."
9382 candidates)
9384 (defun* anything-comp-read (prompt collection
9385 &key
9386 test
9387 initial-input
9388 default
9389 preselect
9390 (buffer "*Anything Completions*")
9391 must-match
9392 (requires-pattern 0)
9393 (history nil)
9394 input-history
9395 (persistent-action nil)
9396 (persistent-help "DoNothing")
9397 (name "Anything Completions")
9398 candidates-in-buffer
9399 exec-when-only-one
9400 (volatile t)
9401 sort
9402 (fc-transformer 'anything-cr-default-transformer)
9403 (marked-candidates nil)
9404 (alistp t))
9405 "Anything `completing-read' replacement.
9407 - PROMPT is the prompt name to use.
9409 - COLLECTION can be a list, vector, obarray or hash-table.
9410 It can be also a function that receives three arguments:
9411 the values string, predicate and t. See `all-completions' for more details.
9413 Keys description:
9415 - TEST: A predicate called with one arg i.e candidate.
9417 - INITIAL-INPUT: Same as input arg in `anything'.
9419 - PRESELECT: See preselect arg of `anything'.
9421 - DEFAULT: This option is used only for compatibility with regular
9422 Emacs `completing-read'.
9424 - BUFFER: Name of anything-buffer.
9426 - MUST-MATCH: Candidate selected must be one of COLLECTION.
9428 - REQUIRES-PATTERN: Same as anything attribute, default is 0.
9430 - HISTORY: A list containing specific history, default is nil.
9431 When it is non--nil, all elements of HISTORY are displayed in
9432 a special source before COLLECTION.
9434 - INPUT-HISTORY: A symbol. the minibuffer input history will be
9435 stored there, if nil or not provided, `minibuffer-history'
9436 will be used instead.
9438 - PERSISTENT-ACTION: A function called with one arg i.e candidate.
9440 - PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9442 - NAME: The name related to this local source.
9444 - EXEC-WHEN-ONLY-ONE: Bound `anything-execute-action-at-once-if-one'
9445 to non--nil. (possibles values are t or nil).
9447 - VOLATILE: Use volatile attribute \(enabled by default\).
9449 - SORT: A predicate to give to `sort' e.g `string-lessp'.
9451 - FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9453 - MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9455 - ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9457 - CANDIDATES-IN-BUFFER: when non--nil use a source build with
9458 `anything-candidates-in-buffer' which is much faster. It is enabled by default.
9459 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9461 Any prefix args passed during `anything-comp-read' invocation will be recorded
9462 in `anything-current-prefix-arg', otherwise if prefix args where given before
9463 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9464 That's mean you can pass prefix args before or after calling a command
9465 that use `anything-comp-read' See `anything-M-x' for example."
9466 (when (get-buffer anything-action-buffer)
9467 (kill-buffer anything-action-buffer))
9468 (flet ((action-fn (candidate)
9469 (if marked-candidates
9470 (anything-marked-candidates)
9471 (identity candidate))))
9472 (let* ((src-hist `((name . ,(format "%s History" name))
9473 (candidates
9474 . (lambda ()
9475 (let ((all (anything-comp-read-get-candidates
9476 history nil nil ,alistp)))
9477 (anything-fast-remove-dups
9478 (if (and default (not (string= default "")))
9479 (delq nil (cons default (delete default all)))
9480 all)
9481 :test 'equal))))
9482 (filtered-candidate-transformer
9483 . (lambda (candidates sources)
9484 (loop for i in candidates
9485 do (set-text-properties 0 (length i) nil i)
9486 collect i)))
9487 (persistent-action . ,persistent-action)
9488 (persistent-help . ,persistent-help)
9489 (action . ,'action-fn)))
9490 (src `((name . ,name)
9491 (candidates
9492 . (lambda ()
9493 (let ((cands (anything-comp-read-get-candidates
9494 collection test sort alistp)))
9495 (unless (or must-match (string= anything-pattern ""))
9496 (setq cands (append (list anything-pattern) cands)))
9497 (if (and default (not (string= default "")))
9498 (delq nil (cons default (delete default cands)))
9499 cands))))
9500 (filtered-candidate-transformer ,fc-transformer)
9501 (requires-pattern . ,requires-pattern)
9502 (persistent-action . ,persistent-action)
9503 (persistent-help . ,persistent-help)
9504 (action . ,'action-fn)))
9505 (src-1 `((name . ,name)
9506 (init
9507 . (lambda ()
9508 (let ((cands (anything-comp-read-get-candidates
9509 collection test sort alistp)))
9510 (unless (or must-match (string= anything-pattern ""))
9511 (setq cands (append (list anything-pattern) cands)))
9512 (with-current-buffer (anything-candidate-buffer 'global)
9513 (loop for i in
9514 (if (and default (not (string= default "")))
9515 (delq nil (cons default (delete default cands)))
9516 cands)
9517 do (insert (concat i "\n")))))))
9518 (candidates-in-buffer)
9519 (filtered-candidate-transformer ,fc-transformer)
9520 (requires-pattern . ,requires-pattern)
9521 (persistent-action . ,persistent-action)
9522 (persistent-help . ,persistent-help)
9523 (action . ,'action-fn)))
9524 (src-list (list src-hist
9525 (if candidates-in-buffer
9526 src-1
9527 (if volatile
9528 (append src '((volatile)))
9529 src))))
9530 (anything-execute-action-at-once-if-one exec-when-only-one))
9532 (anything
9533 :sources src-list
9534 :input initial-input
9535 :default default
9536 :preselect preselect
9537 :prompt prompt
9538 :resume 'noresume
9539 :history input-history
9540 :buffer buffer)
9541 (unless (or (eq anything-exit-status 1) must-match)
9542 default)
9543 (keyboard-quit)))))
9545 ;; Generic completing-read
9547 ;; Support also function as collection.
9548 ;; e.g M-x man is supported.
9549 ;; Support hash-table and vectors as collection.
9550 ;; NOTE:
9551 ;; Some crap emacs functions may not be supported
9552 ;; like ffap-alternate-file (bad use of completing-read)
9553 ;; and maybe others.
9554 ;; Provide a mode `anything-completion-mode' which turn on
9555 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9557 (defvar anything-completion-mode-string " AC")
9559 (defvar anything-completion-mode-quit-message
9560 "Anything completion disabled")
9562 (defvar anything-completion-mode-start-message
9563 "Anything completion enabled")
9565 ;;; Specialized handlers
9568 (defun anything-completing-read-symbols
9569 (prompt collection test require-match init
9570 hist default inherit-input-method name buffer)
9571 "Specialized function for fast symbols completion in `ac-mode'."
9573 (anything
9574 :sources `((name . ,name)
9575 (init . (lambda ()
9576 (with-current-buffer (anything-candidate-buffer 'global)
9577 (goto-char (point-min))
9578 (when (and default (stringp default)
9579 ;; Some defaults args result as
9580 ;; (symbol-name nil) == "nil".
9581 ;; e.g debug-on-entry.
9582 (not (string= default "nil"))
9583 (not (string= default "")))
9584 (insert (concat default "\n")))
9585 (loop with all = (all-completions "" collection test)
9586 for sym in all
9587 unless (and default (eq sym default))
9588 do (insert (concat sym "\n"))))))
9589 (persistent-action . anything-lisp-completion-persistent-action)
9590 (persistent-help . "Show brief doc in mode-line")
9591 (candidates-in-buffer)
9592 (action . identity))
9593 :prompt prompt
9594 :buffer buffer
9595 :input init
9596 :history hist
9597 :resume 'noresume
9598 :default (or default ""))
9599 (keyboard-quit)))
9602 ;;; Generic completing read
9605 (defun anything-completing-read-default-1
9606 (prompt collection test require-match
9607 init hist default inherit-input-method
9608 name buffer &optional cands-in-buffer exec-when-only-one)
9609 "Call `anything-comp-read' with same args as `completing-read'.
9610 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9611 method which is faster.
9612 It should be used when candidate list don't need to rebuild dynamically."
9613 (let ((history (or (car-safe hist) hist)))
9614 (anything-comp-read
9615 prompt collection
9616 :test test
9617 :history history
9618 :input-history history
9619 :must-match require-match
9620 :alistp nil ; Be sure `all-completions' is used.
9621 :name name
9622 :candidates-in-buffer cands-in-buffer
9623 :exec-when-only-one exec-when-only-one
9624 :buffer buffer
9625 ;; If DEF is not provided, fallback to empty string
9626 ;; to avoid `thing-at-point' to be appended on top of list
9627 :default (or default "")
9628 :initial-input init)))
9630 (defun anything-completing-read-with-cands-in-buffer
9631 (prompt collection test require-match
9632 init hist default inherit-input-method
9633 name buffer)
9634 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9635 ;; Some commands like find-tag may use `read-file-name' from inside
9636 ;; the calculation of collection. in this case it clash with
9637 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9638 ;; So (re)calculate collection outside of main anything-session.
9639 (let ((cands (all-completions "" collection)))
9640 (anything-completing-read-default-1 prompt cands test require-match
9641 init hist default inherit-input-method
9642 name buffer t)))
9644 (defun* anything-completing-read-default
9645 (prompt collection &optional
9646 predicate require-match
9647 initial-input hist def
9648 inherit-input-method)
9649 "An anything replacement of `completing-read'.
9650 This function should be used only as a `completing-read-function'.
9652 Don't use it directly, use instead `anything-comp-read' in your programs.
9654 See documentation of `completing-read' and `all-completions' for details."
9655 (declare (special anything-completion-mode))
9656 (let* ((current-command this-command)
9657 (str-command (symbol-name current-command))
9658 (buf-name (format "*ac-mode-%s*" str-command))
9659 (entry (assq current-command
9660 anything-completing-read-handlers-alist))
9661 (def-com (cdr-safe entry))
9662 (str-defcom (and def-com (symbol-name def-com)))
9663 (def-args (list prompt collection predicate require-match
9664 initial-input hist def inherit-input-method))
9665 ;; Append the two extra args needed to set the buffer and source name
9666 ;; in anything specialized functions.
9667 (any-args (append def-args (list str-command buf-name)))
9668 anything-completion-mode-start-message ; Be quiet
9669 anything-completion-mode-quit-message
9670 (minibuffer-completion-table collection)
9671 (minibuffer-completion-predicate predicate))
9672 (when (eq def-com 'ido) (setq def-com 'ido-completing-read))
9673 (unless (or (not entry) def-com)
9674 ;; An entry in *read-handlers-alist exists but have
9675 ;; a nil value, so we exit from here, disable `ac-mode'
9676 ;; and run the command again with it original behavior.
9677 ;; `ac-mode' will be restored on exit.
9678 (return-from anything-completing-read-default
9679 (unwind-protect
9680 (progn
9681 (ac-mode -1)
9682 (call-interactively current-command))
9683 (ac-mode 1))))
9684 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9685 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9686 (when (or (eq def-com 'completing-read)
9687 ;; All specialized functions are prefixed by "anything"
9688 (and (stringp str-defcom)
9689 (not (string-match "^anything" str-defcom))))
9690 (ac-mode -1))
9691 (unwind-protect
9692 (cond (;; An anything specialized function exists, run it.
9693 (and def-com anything-completion-mode)
9694 (apply def-com any-args))
9695 (;; Try to handle `ido-completing-read' everywhere.
9696 (and def-com (eq def-com 'ido-completing-read))
9697 (setcar (memq collection def-args)
9698 (all-completions "" collection predicate))
9699 (apply def-com def-args))
9700 (;; User set explicitely `completing-read' or something similar
9701 ;; in *read-handlers-alist, use this with exactly the same
9702 ;; args as in `completing-read'.
9703 ;; If we are here `anything-completion-mode' is now disabled.
9704 def-com
9705 (apply def-com def-args))
9706 (t ; Fall back to classic `anything-comp-read'.
9707 (anything-completing-read-default-1
9708 prompt collection predicate require-match
9709 initial-input hist def inherit-input-method
9710 str-command buf-name)))
9711 (ac-mode 1)
9712 ;; When exiting minibuffer, `this-command' is set to
9713 ;; `anything-exit-minibuffer', which is unwanted when starting
9714 ;; on another `completing-read', so restore `this-command' to
9715 ;; initial value when exiting.
9716 (setq this-command current-command))))
9718 (defun* anything-generic-read-file-name
9719 (prompt &optional dir default-filename mustmatch initial predicate)
9720 "An anything replacement of `read-file-name'."
9721 (declare (special anything-completion-mode))
9722 (let* ((default (and default-filename
9723 (if (listp default-filename)
9724 (car default-filename)
9725 default-filename)))
9726 (init (or default initial dir default-directory))
9727 (ini-input (and init (expand-file-name init)))
9728 (current-command this-command)
9729 (str-command (symbol-name current-command))
9730 (anything-file-completion-sources
9731 (cons str-command
9732 (remove str-command anything-file-completion-sources)))
9733 (buf-name (format "*ac-mode-%s*" str-command))
9734 (entry (assq current-command
9735 anything-completing-read-handlers-alist))
9736 (def-com (cdr-safe entry))
9737 (str-defcom (symbol-name def-com))
9738 (def-args (list prompt dir default-filename mustmatch initial predicate))
9739 ;; Append the two extra args needed to set the buffer and source name
9740 ;; in anything specialized functions.
9741 (any-args (append def-args (list str-command buf-name)))
9742 (ido-state ido-mode)
9743 anything-completion-mode-start-message ; Be quiet
9744 anything-completion-mode-quit-message ; Same here
9745 fname)
9746 ;; Some functions that normally call `completing-read' can switch
9747 ;; brutally to `read-file-name' (e.g find-tag), in this case
9748 ;; the anything specialized function will fail because it is build
9749 ;; for `completing-read', so set it to 'incompatible to be sure
9750 ;; we switch to `anything-c-read-file-name' and don't try to call it
9751 ;; with wrong number of args.
9752 (when (and def-com (> (length (help-function-arglist def-com)) 8))
9753 (setq def-com 'incompatible))
9754 (when (eq def-com 'ido) (setq def-com 'ido-read-file-name))
9755 (unless (or (not entry) def-com)
9756 (return-from anything-completing-read-default
9757 (unwind-protect
9758 (progn
9759 (ac-mode -1)
9760 (call-interactively current-command))
9761 (ac-mode 1))))
9762 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9763 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9764 (when (or (eq def-com 'read-file-name)
9765 (eq def-com 'ido-read-file-name)
9766 (and (stringp str-defcom)
9767 (not (string-match "^anything" str-defcom))))
9768 (ac-mode -1))
9769 (unwind-protect
9770 (setq fname
9771 (cond (;; A specialized function exists, run it
9772 ;; with the two extra args specific to anything..
9773 (and def-com anything-completion-mode
9774 (not (eq def-com 'ido-read-file-name))
9775 (not (eq def-com 'incompatible)))
9776 (apply def-com any-args))
9777 (;; Def-com value is `ido-read-file-name'
9778 ;; run it with default args.
9779 (and def-com (eq def-com 'ido-read-file-name))
9780 (ido-mode 1)
9781 (apply def-com def-args))
9782 (;; Def-com value is `read-file-name'
9783 ;; run it with default args.
9784 (eq def-com 'read-file-name)
9785 (apply def-com def-args))
9786 (t ; Fall back to classic `anything-c-read-file-name'.
9787 (anything-c-read-file-name
9788 prompt
9789 :name str-command
9790 :buffer buf-name
9791 :initial-input (expand-file-name init dir)
9792 :alistp nil
9793 :test predicate))))
9794 (ac-mode 1)
9795 (ido-mode (if ido-state 1 -1))
9796 ;; Same comment as in `anything-completing-read-default'.
9797 (setq this-command current-command))
9798 (if (and mustmatch (not (file-exists-p fname)))
9799 (if (y-or-n-p "File does not exists, create buffer?")
9800 fname (error "Abort file does not exists"))
9801 fname)))
9803 ;;;###autoload
9804 (define-minor-mode anything-completion-mode
9805 "Toggle generic anything completion.
9807 All functions in Emacs that use `completing-read'
9808 or `read-file-name' and friends will use anything interface
9809 when this mode is turned on.
9810 However you can modify this behavior for functions of your choice
9811 with `anything-completing-read-handlers-alist'.
9813 Called with a positive arg, turn on unconditionally, with a
9814 negative arg turn off.
9815 You can turn it on with `ac-mode'.
9817 Some crap emacs functions may not be supported,
9818 e.g `ffap-alternate-file' and maybe others
9819 You can add such functions to `anything-completing-read-handlers-alist'
9820 with a nil value.
9822 Note: This mode will work only partially on Emacs23."
9823 :group 'anything
9824 :global t
9825 :lighter anything-completion-mode-string
9826 (declare (special completing-read-function))
9827 (if anything-completion-mode
9828 (progn
9829 (setq completing-read-function 'anything-completing-read-default
9830 read-file-name-function 'anything-generic-read-file-name)
9831 (message anything-completion-mode-start-message))
9832 (setq completing-read-function (and (fboundp 'completing-read-default)
9833 'completing-read-default)
9834 read-file-name-function (and (fboundp 'read-file-name-default)
9835 'read-file-name-default))
9836 (message anything-completion-mode-quit-message)))
9838 (defalias 'ac-mode 'anything-completion-mode)
9842 ;;; Eshell completion.
9844 ;; Enable like this in .emacs:
9846 ;; (add-hook 'eshell-mode-hook
9847 ;; #'(lambda ()
9848 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9850 (defvar anything-c-source-esh
9851 '((name . "Eshell completions")
9852 (init . (lambda ()
9853 (setq pcomplete-current-completions nil
9854 pcomplete-last-completion-raw nil)
9855 ;; Eshell-command add this hook in all minibuffers
9856 ;; Remove it for the anything one. (Fixed in Emacs24)
9857 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9858 (candidates . anything-esh-get-candidates)
9859 (action . anything-ec-insert))
9860 "Anything source for Eshell completion.")
9862 ;; Internal.
9863 (defvar anything-ec-target "")
9864 (defun anything-ec-insert (candidate)
9865 "Insert CANDIDATE at point.
9866 This is the same as `ac-insert', just inlined here for compatibility."
9867 (let ((pt (point)))
9868 (when (and anything-ec-target
9869 (search-backward anything-ec-target nil t)
9870 (string= (buffer-substring (point) pt) anything-ec-target))
9871 (delete-region (point) pt)))
9872 (insert candidate))
9874 (defun anything-esh-get-candidates ()
9875 "Get candidates for eshell completion using `pcomplete'."
9876 (catch 'pcompleted
9877 (let* ((pcomplete-stub)
9878 pcomplete-seen pcomplete-norm-func
9879 pcomplete-args pcomplete-last pcomplete-index
9880 (pcomplete-autolist pcomplete-autolist)
9881 (pcomplete-suffix-list pcomplete-suffix-list))
9882 (with-anything-current-buffer
9883 (loop
9884 with table = (pcomplete-completions)
9885 with entry = (condition-case nil
9886 ;; For Emacs24
9887 (try-completion anything-pattern (pcomplete-entries))
9888 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9889 (error
9891 (let ((fc (car (last (pcomplete-parse-arguments)))))
9892 ;; Check if last arg require fname completion.
9893 (and (file-name-directory fc) fc))))
9894 for i in (if (listp table) table ; Emacs23 or commands.
9895 (all-completions pcomplete-stub table)) ; Emacs24
9896 for file-cand = (and entry
9897 (if (file-remote-p i) i
9898 (expand-file-name i (file-name-directory entry))))
9899 if (and file-cand (or (file-remote-p file-cand) (file-exists-p file-cand)))
9900 collect file-cand into ls
9901 else collect i into ls
9902 finally return
9903 (if (and entry (not (string= entry "")) (file-exists-p entry))
9904 (append (list (expand-file-name entry default-directory)) ls) ls))))))
9906 ;;; Eshell history.
9909 (defvar anything-c-source-eshell-history
9910 '((name . "Eshell history")
9911 (init . (lambda ()
9912 (let (eshell-hist-ignoredups)
9913 ;; Write the content's of ring to file.
9914 (eshell-write-history eshell-history-file-name t)
9915 (with-current-buffer (anything-candidate-buffer 'global)
9916 (insert-file-contents eshell-history-file-name)))
9917 ;; Same comment as in `anything-c-source-esh'
9918 (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
9919 (candidates-in-buffer)
9920 (filtered-candidate-transformer . (lambda (candidates sources)
9921 (reverse candidates)))
9922 (candidate-number-limit . 9999)
9923 (action . (lambda (candidate)
9924 (eshell-kill-input)
9925 (insert candidate))))
9926 "Anything source for Eshell history.")
9929 ;;; Show completion - an alternative of anything-show-completion.el.
9931 ;; Provide show completion with macro `with-anything-show-completion'.
9934 ;; Called each time cursor move in anything-buffer.
9935 (defun anything-c-show-completion ()
9936 (with-anything-current-buffer
9937 (overlay-put anything-c-show-completion-overlay
9938 'display (anything-get-selection))))
9940 (defun anything-c-show-completion-init-overlay (beg end)
9941 (and anything-c-turn-on-show-completion
9942 (setq anything-c-show-completion-overlay (make-overlay beg end))
9943 (overlay-put anything-c-show-completion-overlay
9944 'face 'anything-lisp-show-completion)))
9946 (defmacro with-anything-show-completion (beg end &rest body)
9947 "Show anything candidate in an overlay at point.
9948 BEG and END are the beginning and end position of the current completion
9949 in `anything-current-buffer'.
9950 BODY is an anything call where we want to enable show completion.
9951 If `anything-c-turn-on-show-completion' is nil just do nothing."
9952 (declare (indent 2) (debug t))
9953 `(let ((anything-move-selection-after-hook
9954 (and anything-c-turn-on-show-completion
9955 (append (list 'anything-c-show-completion)
9956 anything-move-selection-after-hook))))
9957 (unwind-protect
9958 (progn (anything-c-show-completion-init-overlay ,beg ,end)
9959 ,@body)
9960 (and anything-c-turn-on-show-completion
9961 (delete-overlay anything-c-show-completion-overlay)))))
9964 ;;; Lisp symbol completion.
9967 ;;;###autoload
9968 (defun anything-lisp-completion-at-point ()
9969 "Anything lisp symbol completion at point."
9970 (interactive)
9971 (let* ((data (lisp-completion-at-point))
9972 (beg (car data))
9973 (end (point)) ; 'cadr data' is wrong when no space after point.
9974 (plist (nthcdr 3 data))
9975 (pred (plist-get plist :predicate))
9976 (lgst-len 0)
9977 (target (and beg end (buffer-substring-no-properties beg end)))
9978 (candidates (all-completions target (nth 2 data) pred))
9979 (anything-quit-if-no-candidate t)
9980 (anything-execute-action-at-once-if-one t)
9981 (anything-match-plugin-enabled
9982 (member 'anything-compile-source--match-plugin
9983 anything-compile-source-functions)))
9984 (if candidates
9985 (with-anything-show-completion beg end
9986 ;; Overlay is initialized now in anything-current-buffer.
9987 (anything
9988 :sources
9989 '((name . "Lisp completion")
9990 (init . (lambda ()
9991 (with-current-buffer (anything-candidate-buffer 'global)
9992 (loop for sym in candidates
9993 for len = (length sym)
9994 when (> len lgst-len) do (setq lgst-len len)
9995 do (insert (concat sym "\n"))))))
9996 (candidates-in-buffer)
9997 (persistent-action . anything-lisp-completion-persistent-action)
9998 (persistent-help . "Show brief doc in mode-line")
9999 (filtered-candidate-transformer anything-lisp-completion-transformer)
10000 (action . (lambda (candidate)
10001 (delete-region beg end)
10002 (insert candidate))))
10003 :input (if anything-match-plugin-enabled (concat target " ") target)))
10004 (message "[No Match]"))))
10006 (defun anything-lisp-completion-persistent-action (candidate)
10007 (let ((cursor-in-echo-area t)
10008 mode-line-in-non-selected-windows)
10009 (anything-c-show-info-in-mode-line
10010 (propertize
10011 (anything-c-get-first-line-documentation
10012 (intern candidate))
10013 'face 'anything-lisp-completion-info))))
10015 (defun anything-lisp-completion-transformer (candidates source)
10016 "Anything candidates transformer for lisp completion."
10017 (declare (special lgst-len))
10018 (loop for c in candidates
10019 for sym = (intern c)
10020 for annot = (cond ((commandp sym) " (Com)")
10021 ((fboundp sym) " (Fun)")
10022 ((boundp sym) " (Var)")
10023 ((facep sym) " (Face)"))
10024 for spaces = (make-string (- lgst-len (length c)) ? )
10025 collect (cons (concat c spaces annot) c)))
10027 (defun anything-c-get-first-line-documentation (sym)
10028 "Return first line documentation of symbol SYM.
10029 If SYM is not documented, return \"Not documented\"."
10030 (let ((doc (cond ((fboundp sym)
10031 (documentation sym t))
10032 ((boundp sym)
10033 (documentation-property sym 'variable-documentation t))
10034 ((facep sym)
10035 (face-documentation sym))
10036 (t nil))))
10037 (if (and doc (not (string= doc ""))
10038 ;; `documentation' return "\n\n(args...)"
10039 ;; for CL-style functions.
10040 (not (string-match-p "^\n\n" doc)))
10041 (car (split-string doc "\n"))
10042 "Not documented")))
10044 ;;; File completion.
10046 ;; Complete file name at point.
10047 (defun anything-c-thing-before-point ()
10048 "Get symbol name before point.
10049 Borrowed from anything-complete.el, inlined here for compatibility."
10050 (save-excursion
10051 (let ((beg (point)))
10052 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10053 (when (re-search-backward
10054 "\\_<" (field-beginning nil nil (point-at-bol)) t)
10055 (buffer-substring-no-properties beg (match-end 0))))))
10057 ;;;###autoload
10058 (defun anything-c-complete-file-name-at-point ()
10059 "Complete file name at point."
10060 (interactive)
10061 (let* ((init (substring-no-properties (thing-at-point 'filename)))
10062 (end (point))
10063 (beg (- (point) (length init)))
10064 (anything-quit-if-no-candidate t)
10065 (anything-execute-action-at-once-if-one t)
10066 completion)
10067 (with-anything-show-completion beg end
10068 (setq completion (anything-c-read-file-name "FileName: "
10069 :initial-input init)))
10070 (anything-c-insert-file-name-completion-at-point completion)))
10072 ;; Internal
10073 (defvar anything-lisp-completion-counter 0)
10074 ;;;###autoload
10075 (defun anything-lisp-completion-at-point-or-indent (arg)
10076 "First call indent and second call complete lisp symbol.
10077 The second call should happen before `anything-lisp-completion-or-indent-delay',
10078 after this delay, next call will indent again.
10079 After completion, next call is always indent.
10080 See that like click and double mouse click.
10081 One hit indent, two quick hits maybe indent and complete."
10082 (interactive "P")
10083 ;; Be sure `indent-for-tab-command' will not try
10084 ;; to use `completion-at-point'.
10085 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10086 t tab-always-indent)))
10087 (incf anything-lisp-completion-counter)
10088 (unwind-protect
10089 (if (> anything-lisp-completion-counter 1)
10090 (anything-lisp-completion-or-file-name-at-point)
10091 (indent-for-tab-command arg))
10092 ;; After `anything-lisp-completion-or-indent-delay' seconds
10093 ;; reset to 0.
10094 (run-with-timer anything-lisp-completion-or-indent-delay nil
10095 #'(lambda ()
10096 (setq anything-lisp-completion-counter 0)))
10097 ;; Always reset to 0 at second hit.
10098 (when (eq anything-lisp-completion-counter 2)
10099 (setq anything-lisp-completion-counter 0)))))
10101 ;;;###autoload
10102 (defun anything-lisp-completion-or-file-name-at-point ()
10103 "Complete lisp symbol or filename at point.
10104 Filename completion happen if filename is started in
10105 or between double quotes."
10106 (interactive)
10107 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10108 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10109 (save-excursion (search-backward "\"" (point-at-bol) t)))
10110 (anything-c-complete-file-name-at-point)
10111 (anything-lisp-completion-at-point))))
10113 (defun anything-c-apropos-init (test default)
10114 "Init candidates buffer for `anything-c-apropos' sources."
10115 (with-current-buffer (anything-candidate-buffer 'global)
10116 (goto-char (point-min))
10117 (when (and default (stringp default)
10118 ;; Some defaults args result as
10119 ;; (symbol-name nil) == "nil".
10120 ;; e.g debug-on-entry.
10121 (not (string= default "nil"))
10122 (funcall test (intern default)))
10123 (insert (concat default "\n")))
10124 (loop with all = (all-completions "" obarray test)
10125 for sym in all
10126 unless (and default (eq sym default))
10127 do (insert (concat sym "\n")))))
10130 ;;; Run Externals commands within Emacs with anything completion
10133 (defvar anything-external-command-history nil)
10135 (defun anything-c-external-commands-list-1 (&optional sort)
10136 "Returns a list of all external commands the user can execute.
10137 If `anything-c-external-commands-list' is non-nil it will
10138 return its contents. Else it calculates all external commands
10139 and sets `anything-c-external-commands-list'."
10140 (if anything-c-external-commands-list
10141 anything-c-external-commands-list
10142 (setq anything-c-external-commands-list
10143 (loop
10144 with paths = (split-string (getenv "PATH") path-separator)
10145 with completions = ()
10146 for dir in paths
10147 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10148 for lsdir = (loop for i in (directory-files dir t)
10149 for bn = (file-name-nondirectory i)
10150 when (and (not (member bn completions))
10151 (not (file-directory-p i))
10152 (file-executable-p i))
10153 collect bn)
10154 append lsdir into completions
10155 finally return (if sort (sort completions 'string-lessp) completions)))))
10157 (defun anything-run-or-raise (exe &optional file)
10158 "Generic command that run asynchronously EXE.
10159 If EXE is already running just jump to his window if `anything-raise-command'
10160 is non--nil.
10161 When FILE argument is provided run EXE with FILE.
10162 In this case EXE must be provided as \"EXE %s\"."
10163 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10164 "%s" "" exe))))
10165 (proc (if file (concat real-com " " file) real-com)))
10166 (if (get-process proc)
10167 (if anything-raise-command
10168 (shell-command (format anything-raise-command real-com))
10169 (error "Error: %s is already running" real-com))
10170 (when (loop for i in anything-c-external-commands-list thereis real-com)
10171 (message "Starting %s..." real-com)
10172 (if file
10173 (start-process-shell-command
10174 proc nil (format exe (shell-quote-argument file)))
10175 (start-process-shell-command proc nil real-com))
10176 (set-process-sentinel
10177 (get-process proc)
10178 #'(lambda (process event)
10179 (when (and (string= event "finished\n")
10180 anything-raise-command
10181 (not (anything-c-get-pid-from-process-name real-com)))
10182 (shell-command (format anything-raise-command "emacs")))
10183 (message "%s process...Finished." process))))
10184 (setq anything-c-external-commands-list
10185 (cons real-com
10186 (delete real-com anything-c-external-commands-list))))))
10190 ;;; Generic action functions
10193 (defun anything-c-file-buffers (filename)
10194 "Returns a list of buffer names corresponding to FILENAME."
10195 (let ((name (expand-file-name filename))
10196 (buf-list ()))
10197 (dolist (buf (buffer-list) buf-list)
10198 (let ((bfn (buffer-file-name buf)))
10199 (when (and bfn (string= name bfn))
10200 (push (buffer-name buf) buf-list))))))
10202 (defun anything-revert-buffer (candidate)
10203 (with-current-buffer candidate
10204 (when (or (buffer-modified-p)
10205 (not (verify-visited-file-modtime
10206 (get-buffer candidate))))
10207 (revert-buffer t t))))
10209 (defun anything-revert-marked-buffers (ignore)
10210 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10212 (defun anything-kill-marked-buffers (ignore)
10213 (mapc 'kill-buffer (anything-marked-candidates)))
10215 (defun anything-c-delete-file (file)
10216 "Delete the given file after querying the user.
10217 Ask to kill buffers associated with that file, too."
10218 (let ((buffers (anything-c-file-buffers file)))
10219 (if (< emacs-major-version 24)
10220 ;; `dired-delete-file' in Emacs versions < 24
10221 ;; doesn't support delete-by-moving-to-trash
10222 ;; so use `delete-directory' and `delete-file'
10223 ;; that handle it.
10224 (cond ((and (not (file-symlink-p file))
10225 (file-directory-p file)
10226 (directory-files file t dired-re-no-dot))
10227 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10228 (delete-directory file 'recursive)))
10229 ((and (not (file-symlink-p file))
10230 (file-directory-p file))
10231 (delete-directory file))
10232 (t (delete-file file)))
10233 (dired-delete-file
10234 file 'dired-recursive-deletes delete-by-moving-to-trash))
10235 (when buffers
10236 (dolist (buf buffers)
10237 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10238 (kill-buffer buf))))))
10240 (defun anything-get-mailcap-for-file (filename)
10241 "Get the command to use for FILENAME from mailcap files.
10242 The command is like <command %s> and is meant to use with `format'."
10243 (mailcap-parse-mailcaps)
10244 (let* ((ext (file-name-extension filename))
10245 (mime (when ext (mailcap-extension-to-mime ext)))
10246 (result (when mime (mailcap-mime-info mime))))
10247 ;; If elisp file have no associations in .mailcap
10248 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10249 (when (stringp result) result)))
10251 (defun anything-get-default-program-for-file (filename)
10252 "Try to find a default program to open FILENAME.
10253 Try first in `anything-c-external-programs-associations' and then in mailcap file
10254 if nothing found return nil."
10255 (let* ((ext (file-name-extension filename))
10256 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10257 (cond ((and def-prog (not (string= def-prog "")))
10258 (concat def-prog " %s"))
10259 ((and anything-c-default-external-file-browser
10260 (file-directory-p filename))
10261 (concat anything-c-default-external-file-browser " %s"))
10262 (t (anything-get-mailcap-for-file filename)))))
10264 (defun anything-c-open-file-externally (file)
10265 "Open FILE with an external program.
10266 Try to guess which program to use with `anything-get-default-program-for-file'.
10267 If not found or a prefix arg is given query the user which tool to use."
10268 (let* ((fname (expand-file-name file))
10269 (collection (anything-c-external-commands-list-1 'sort))
10270 (def-prog (anything-get-default-program-for-file fname))
10271 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10272 ;; Prefix arg or no default program.
10273 (prog1
10274 (anything-comp-read
10275 "Program: " collection
10276 :must-match t
10277 :name "Open file Externally"
10278 :history anything-external-command-history)
10279 ;; Always prompt to set this program as default.
10280 (setq def-prog nil))
10281 ;; No prefix arg or default program exists.
10282 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10283 (program (concat real-prog-name " %s")))
10284 (unless (or def-prog ; Association exists, no need to record it.
10285 ;; Don't try to record non--filenames associations (e.g urls).
10286 (not (file-exists-p fname)))
10287 (when
10288 (y-or-n-p
10289 (format
10290 "Do you want to make `%s' the default program for this kind of files? "
10291 real-prog-name))
10292 (anything-aif (assoc (file-name-extension fname)
10293 anything-c-external-programs-associations)
10294 (setq anything-c-external-programs-associations
10295 (delete it anything-c-external-programs-associations)))
10296 (push (cons (file-name-extension fname)
10297 (read-string
10298 "Program (Add args maybe and confirm): " real-prog-name))
10299 anything-c-external-programs-associations)
10300 (customize-save-variable 'anything-c-external-programs-associations
10301 anything-c-external-programs-associations)))
10302 (anything-run-or-raise program file)
10303 (setq anything-external-command-history
10304 (cons real-prog-name
10305 (delete real-prog-name
10306 (loop for i in anything-external-command-history
10307 when (executable-find i) collect i))))))
10309 (defun anything-c-find-file-or-marked (candidate)
10310 "Open file CANDIDATE or open anything marked files in background."
10311 (let ((marked (anything-marked-candidates))
10312 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10313 (find-file-wildcards nil))
10314 (if (> (length marked) 1)
10315 ;; Open all marked files in background and display
10316 ;; the first one.
10317 (progn (mapc 'find-file-noselect (cdr marked))
10318 (find-file (car marked)))
10319 (if (and (not (file-exists-p candidate))
10320 (and ffap-url-regexp
10321 (not (string-match ffap-url-regexp candidate)))
10322 (string-match "/$" candidate))
10323 ;; A a non--existing filename ending with /
10324 ;; Create a directory and jump to it.
10325 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10326 (let ((dirfname (directory-file-name candidate)))
10327 (if (file-exists-p dirfname)
10328 (error "Mkdir: Unable to create directory `%s': file exists."
10329 (anything-c-basename dirfname))
10330 (make-directory candidate 'parent)))
10331 (anything-find-files-1 candidate))
10332 ;; A non--existing filename NOT ending with / or
10333 ;; an existing filename, create or jump to it.
10334 (find-file-at-point (car marked))))))
10336 (defun anything-delete-marked-files (ignore)
10337 (let* ((files (anything-marked-candidates))
10338 (len (length files)))
10339 (if (not (y-or-n-p
10340 (format "Delete *%s File(s):\n%s"
10342 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10343 (message "(No deletions performed)")
10344 (dolist (i files)
10345 (set-text-properties 0 (length i) nil i)
10346 (anything-c-delete-file i))
10347 (message "%s File(s) deleted" len))))
10349 (defun anything-ediff-marked-buffers (candidate &optional merge)
10350 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10351 With optional arg MERGE call `ediff-merge-buffers'."
10352 (let ((lg-lst (length (anything-marked-candidates)))
10353 buf1 buf2)
10354 (case lg-lst
10356 (error "Error:You have to mark at least 1 buffer"))
10358 (setq buf1 anything-current-buffer
10359 buf2 (first (anything-marked-candidates))))
10361 (setq buf1 (first (anything-marked-candidates))
10362 buf2 (second (anything-marked-candidates))))
10364 (error "Error:To much buffers marked!")))
10365 (if merge
10366 (ediff-merge-buffers buf1 buf2)
10367 (ediff-buffers buf1 buf2))))
10369 (defun anything-ediff-marked-buffers-merge (candidate)
10370 "Ediff merge `anything-current-buffer' with CANDIDATE.
10371 See `anything-ediff-marked-buffers'."
10372 (anything-ediff-marked-buffers candidate t))
10374 (defun anything-bookmark-get-bookmark-from-name (bmk)
10375 "Return bookmark name even if it is a bookmark with annotation.
10376 e.g prepended with *.
10377 Return nil if bmk is not a valid bookmark."
10378 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10379 (if (assoc bookmark bookmark-alist)
10380 bookmark
10381 (when (assoc bmk bookmark-alist)
10382 bmk))))
10384 (defun anything-delete-marked-bookmarks (ignore)
10385 "Delete this bookmark or all marked bookmarks."
10386 (dolist (i (anything-marked-candidates))
10387 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10388 'batch)))
10390 (defun anything-require-or-error (feature function)
10391 (or (require feature nil t)
10392 (error "Need %s to use `%s'." feature function)))
10394 (defun anything-find-buffer-on-elscreen (candidate)
10395 "Open buffer in new screen, if marked buffers open all in elscreens."
10396 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10397 (anything-aif (anything-marked-candidates)
10398 (dolist (i it)
10399 (let ((target-screen (elscreen-find-screen-by-buffer
10400 (get-buffer i) 'create)))
10401 (elscreen-goto target-screen)))
10402 (let ((target-screen (elscreen-find-screen-by-buffer
10403 (get-buffer candidate) 'create)))
10404 (elscreen-goto target-screen))))
10406 (defun anything-elscreen-find-file (file)
10407 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10408 (elscreen-find-file file))
10410 ;;;###autoload
10411 (defun w32-shell-execute-open-file (file)
10412 (interactive "fOpen file:")
10413 (with-no-warnings
10414 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10415 "/" "\\"
10416 (replace-regexp-in-string ; strip cygdrive paths
10417 "/cygdrive/\\(.\\)" "\\1:"
10418 file nil nil) nil t))))
10420 (defun anything-c-open-file-with-default-tool (file)
10421 "Open FILE with the default tool on this platform."
10422 (if (eq system-type 'windows-nt)
10423 (w32-shell-execute-open-file file)
10424 (start-process "anything-c-open-file-with-default-tool"
10426 (cond ((eq system-type 'gnu/linux)
10427 "xdg-open")
10428 ((or (eq system-type 'darwin) ;; Mac OS X
10429 (eq system-type 'macos)) ;; Mac OS 9
10430 "open"))
10431 file)))
10433 (defun anything-c-open-dired (file)
10434 "Opens a dired buffer in FILE's directory. If FILE is a
10435 directory, open this directory."
10436 (if (file-directory-p file)
10437 (dired file)
10438 (dired (file-name-directory file))
10439 (dired-goto-file file)))
10441 (defun anything-c-display-to-real-line (candidate)
10442 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10443 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10444 (error "Line number not found")))
10446 (defun anything-c-action-line-goto (lineno-and-content)
10447 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10448 (append lineno-and-content
10449 (list (if (and (anything-attr-defined 'target-file)
10450 (not anything-in-persistent-action))
10451 'find-file-other-window
10452 'find-file)))))
10454 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10455 (apply #'anything-goto-file-line
10456 (if (stringp file-line-content)
10457 ;; Case: filtered-candidate-transformer is skipped
10458 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10459 file-line-content)))
10461 (require 'compile)
10462 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10463 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10465 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10466 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10467 (let ((filename (match-string 1 candidate))
10468 (lineno (match-string 2 candidate))
10469 (content (match-string 3 candidate)))
10470 (cons (format "%s:%s\n %s"
10471 (propertize filename 'face compilation-info-face)
10472 (propertize lineno 'face compilation-line-face)
10473 content)
10474 (list (expand-file-name
10475 filename
10476 (or (anything-interpret-value (anything-attr 'default-directory))
10477 (and (anything-candidate-buffer)
10478 (buffer-local-value
10479 'default-directory (anything-candidate-buffer)))))
10480 (string-to-number lineno) content)))))
10482 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10483 (anything-aif (anything-attr 'before-jump-hook)
10484 (funcall it))
10485 (when file (funcall find-file-function file))
10486 (if (anything-attr-defined 'adjust)
10487 (anything-c-goto-line-with-adjustment lineno content)
10488 (anything-goto-line lineno))
10489 (unless (anything-attr-defined 'recenter)
10490 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10491 (anything-aif (anything-attr 'after-jump-hook)
10492 (funcall it))
10493 (when anything-in-persistent-action
10494 (anything-match-line-color-current-line)))
10496 (defun anything-find-file-as-root (candidate)
10497 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10499 (defun anything-find-many-files (ignore)
10500 (mapc 'find-file (anything-marked-candidates)))
10502 ;; borrowed from etags.el
10503 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10504 (defun anything-c-goto-line-with-adjustment (line line-content)
10505 (let ((startpos)
10506 offset found pat)
10507 ;; This constant is 1/2 the initial search window.
10508 ;; There is no sense in making it too small,
10509 ;; since just going around the loop once probably
10510 ;; costs about as much as searching 2000 chars.
10511 (setq offset 1000
10512 found nil
10513 pat (concat (if (eq selective-display t)
10514 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10515 (regexp-quote line-content)))
10516 ;; If no char pos was given, try the given line number.
10517 (setq startpos (progn (anything-goto-line line) (point)))
10518 (or startpos (setq startpos (point-min)))
10519 ;; First see if the tag is right at the specified location.
10520 (goto-char startpos)
10521 (setq found (looking-at pat))
10522 (while (and (not found)
10523 (progn
10524 (goto-char (- startpos offset))
10525 (not (bobp))))
10526 (setq found
10527 (re-search-forward pat (+ startpos offset) t)
10528 offset (* 3 offset))) ; expand search window
10529 (or found
10530 (re-search-forward pat nil t)
10531 (error "not found")))
10532 ;; Position point at the right place
10533 ;; if the search string matched an extra Ctrl-m at the beginning.
10534 (and (eq selective-display t)
10535 (looking-at "\^m")
10536 (forward-char 1))
10537 (beginning-of-line))
10539 (anything-document-attribute 'default-directory "type . file-line"
10540 "`default-directory' to interpret file.")
10541 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10542 "Function to call before jumping to the target location.")
10543 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10544 "Function to call after jumping to the target location.")
10545 (anything-document-attribute 'adjust "type . file-line"
10546 "Search around line matching line contents.")
10547 (anything-document-attribute 'recenter "type . file-line / line"
10548 "`recenter' after jumping.")
10549 (anything-document-attribute 'target-file "type . line"
10550 "Goto line of target-file.")
10552 ;;;###autoload
10553 (defun anything-c-call-interactively (cmd-or-name)
10554 "Execute CMD-OR-NAME as Emacs command.
10555 It is added to `extended-command-history'.
10556 `anything-current-prefix-arg' is used as the command's prefix argument."
10557 (setq extended-command-history
10558 (cons (anything-c-stringify cmd-or-name)
10559 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10560 (let ((current-prefix-arg anything-current-prefix-arg)
10561 (cmd (anything-c-symbolify cmd-or-name)))
10562 (if (stringp (symbol-function cmd))
10563 (execute-kbd-macro (symbol-function cmd))
10564 (setq this-command cmd)
10565 (call-interactively cmd))))
10567 ;;;###autoload
10568 (defun anything-c-set-variable (var)
10569 "Set value to VAR interactively."
10570 (interactive)
10571 (let ((sym (anything-c-symbolify var)))
10572 (set sym (eval-minibuffer (format "Set %s: " var)
10573 (prin1-to-string (symbol-value sym))))))
10574 ;; (setq hh 12)
10575 ;; (anything-c-set-variable 'hh)
10579 ;;; Persistent Action Helpers
10582 (defvar anything-match-line-overlay-face nil)
10583 (defvar anything-match-line-overlay nil)
10585 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10586 "Highlight and underline current position"
10587 (let ((args (list (or start (line-beginning-position))
10588 (or end (1+ (line-end-position)))
10589 buf)))
10590 (if (not anything-match-line-overlay)
10591 (setq anything-match-line-overlay (apply 'make-overlay args))
10592 (apply 'move-overlay anything-match-line-overlay args)))
10593 (overlay-put anything-match-line-overlay
10594 'face (or face anything-match-line-overlay-face))
10595 (when rec
10596 (goto-char start)
10597 (recenter)))
10599 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10602 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10604 (defun anything-match-line-cleanup ()
10605 (when anything-match-line-overlay
10606 (delete-overlay anything-match-line-overlay)
10607 (setq anything-match-line-overlay nil)))
10609 (defun anything-match-line-update ()
10610 (when anything-match-line-overlay
10611 (delete-overlay anything-match-line-overlay)
10612 (anything-match-line-color-current-line)))
10614 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10615 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10618 ;;; Actions Transformers
10621 ;;; Files
10622 (defun anything-c-transform-file-load-el (actions candidate)
10623 "Add action to load the file CANDIDATE if it is an emacs lisp
10624 file. Else return ACTIONS unmodified."
10625 (if (member (file-name-extension candidate) '("el" "elc"))
10626 (append actions '(("Load Emacs Lisp File" . load-file)))
10627 actions))
10629 (defun anything-c-transform-file-browse-url (actions candidate)
10630 "Add an action to browse the file CANDIDATE if it in a html
10631 file or URL. Else return ACTIONS unmodified."
10632 (let ((browse-action '("Browse with Browser" . browse-url)))
10633 (cond ((string-match "^http\\|^ftp" candidate)
10634 (cons browse-action actions))
10635 ((string-match "\\.html?$" candidate)
10636 (append actions (list browse-action)))
10637 (t actions))))
10639 ;;; Function
10640 (defun anything-c-transform-function-call-interactively (actions candidate)
10641 "Add an action to call the function CANDIDATE interactively if
10642 it is a command. Else return ACTIONS unmodified."
10643 (if (commandp (intern-soft candidate))
10644 (append actions '(("Call Interactively"
10646 anything-c-call-interactively)))
10647 actions))
10649 ;;;; S-Expressions
10650 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10651 "If CANDIDATE's `car' is a command, then add an action to
10652 evaluate it and put it onto the `command-history'."
10653 (if (commandp (car (read candidate)))
10654 ;; Make it first entry
10655 (cons '("Eval and put onto command-history" .
10656 (lambda (sexp)
10657 (let ((sym (read sexp)))
10658 (eval sym)
10659 (setq command-history
10660 (cons sym command-history)))))
10661 actions)
10662 actions))
10665 ;;; Candidate Transformers
10668 ;;; Buffers
10669 (defun anything-c-skip-boring-buffers (buffers)
10670 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10672 (defun anything-c-skip-current-buffer (buffers)
10673 (if anything-allow-skipping-current-buffer
10674 (remove (buffer-name anything-current-buffer) buffers)
10675 buffers))
10677 (defun anything-c-shadow-boring-buffers (buffers)
10678 "Buffers matching `anything-c-boring-buffer-regexp' will be
10679 displayed with the `file-name-shadow' face if available."
10680 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10682 (defvar anything-c-buffer-display-string-functions
10683 '(anything-c-buffer-display-string--compilation
10684 anything-c-buffer-display-string--shell
10685 anything-c-buffer-display-string--eshell)
10686 "Functions to setup display string for buffer.
10688 Function has one argument, buffer name.
10689 If it returns string, use it.
10690 If it returns nil, display buffer name.
10691 See `anything-c-buffer-display-string--compilation' for example.")
10693 (defun anything-c-transform-buffer-display-string (buffers)
10694 "Setup display string for buffer candidates
10695 using `anything-c-buffer-display-string-functions'."
10696 (loop for buf in buffers
10697 if (consp buf)
10698 collect buf
10699 else
10700 for disp = (progn (set-buffer buf)
10701 (run-hook-with-args-until-success
10702 'anything-c-buffer-display-string-functions buf))
10703 collect (if disp (cons disp buf) buf)))
10705 (defun anything-c-buffer-display-string--compilation (buf)
10706 (anything-aif (car compilation-arguments)
10707 (format "%s: %s [%s]" buf it default-directory)))
10709 (defun anything-c-buffer-display-string--eshell (buf)
10710 (declare (special eshell-history-ring))
10711 (when (eq major-mode 'eshell-mode)
10712 (format "%s: %s [%s]" buf
10713 (ignore-errors (ring-ref eshell-history-ring 0))
10714 default-directory)))
10716 (defun anything-c-buffer-display-string--shell (buf)
10717 (when (eq major-mode 'shell-mode)
10718 (format "%s: %s [%s]" buf
10719 (ignore-errors (ring-ref comint-input-ring 0))
10720 default-directory)))
10722 ;;; Files
10723 (defun anything-c-shadow-boring-files (files)
10724 "Files matching `anything-c-boring-file-regexp' will be
10725 displayed with the `file-name-shadow' face if available."
10726 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10728 (defun anything-c-skip-boring-files (files)
10729 "Files matching `anything-c-boring-file-regexp' will be skipped."
10730 (anything-c-skip-entries files anything-c-boring-file-regexp))
10731 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10733 (defun anything-c-skip-current-file (files)
10734 "Current file will be skipped."
10735 (remove (buffer-file-name anything-current-buffer) files))
10737 (defun anything-c-w32-pathname-transformer (args)
10738 "Change undesirable features of windows pathnames to ones more acceptable to
10739 other candidate transformers."
10740 (if (eq system-type 'windows-nt)
10741 (mapcar (lambda (x)
10742 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10743 (mapcar (lambda (y)
10744 (replace-regexp-in-string "\\\\" "/" y)) args))
10745 args))
10747 (defun anything-c-shorten-home-path (files)
10748 "Replaces /home/user with ~."
10749 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10750 (getenv "HOME"))))
10751 (mapcar (lambda (file)
10752 (if (and (stringp file) (string-match home file))
10753 (cons (replace-match "~" nil nil file) file)
10754 file))
10755 files)))
10757 ;;; Functions
10758 (defun anything-c-mark-interactive-functions (functions)
10759 "Mark interactive functions (commands) with (i) after the function name."
10760 (let (list)
10761 (loop for function in functions
10762 do (push (cons (concat function
10763 (when (commandp (intern-soft function)) " (i)"))
10764 function)
10765 list)
10766 finally (return (nreverse list)))))
10769 ;;; Adaptive Sorting of Candidates
10772 ;; Internal
10773 (defvar anything-c-adaptive-done nil
10774 "nil if history information is not yet stored for the current
10775 selection.")
10777 (defvar anything-c-adaptive-history nil
10778 "Contains the stored history information.
10779 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10781 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10782 "Reset `anything-c-adaptive-done' when anything is started."
10783 (when anything-c-use-adaptative-sorting
10784 (setq anything-c-adaptive-done nil)))
10786 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10787 "Store history information when action is executed on selected candidate."
10788 (when anything-c-use-adaptative-sorting
10789 (anything-c-adaptive-store-selection)))
10791 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10792 "Store history information when the user goes to the action buffer."
10793 (when anything-c-use-adaptative-sorting
10794 (anything-c-adaptive-store-selection)))
10796 (defun anything-c-source-use-adaptative-p (&optional source-name)
10797 "Return current source only if it use adaptative history, nil otherwise."
10798 (when anything-c-use-adaptative-sorting
10799 (let* ((source (or source-name (anything-get-current-source)))
10800 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10801 (assoc (assoc-default 'type source)
10802 anything-type-attributes))
10803 (assoc-default 'candidate-transformer
10804 (assoc (assoc-default 'type source)
10805 anything-type-attributes))
10806 (assoc-default 'filtered-candidate-transformer source)
10807 (assoc-default 'candidate-transformer source))))
10808 (if (listp adapt-source)
10809 (when (member 'anything-c-adaptive-sort adapt-source) source)
10810 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
10812 (defun anything-c-adaptive-store-selection ()
10813 "Store history information for the selected candidate."
10814 (unless anything-c-adaptive-done
10815 (setq anything-c-adaptive-done t)
10816 (let ((source (anything-c-source-use-adaptative-p)))
10817 (when source
10818 (let* ((source-name (or (assoc-default 'type source)
10819 (assoc-default 'name source)))
10820 (source-info (or (assoc source-name anything-c-adaptive-history)
10821 (progn
10822 (push (list source-name) anything-c-adaptive-history)
10823 (car anything-c-adaptive-history))))
10824 (selection (anything-get-selection))
10825 (selection-info (progn
10826 (setcdr source-info
10827 (cons
10828 (let ((found (assoc selection (cdr source-info))))
10829 (if (not found)
10830 ;; new entry
10831 (list selection)
10833 ;; move entry to the beginning of the
10834 ;; list, so that it doesn't get
10835 ;; trimmed when the history is
10836 ;; truncated
10837 (setcdr source-info
10838 (delete found (cdr source-info)))
10839 found))
10840 (cdr source-info)))
10841 (cadr source-info)))
10842 (pattern-info (progn
10843 (setcdr selection-info
10844 (cons
10845 (let ((found (assoc anything-pattern (cdr selection-info))))
10846 (if (not found)
10847 ;; new entry
10848 (cons anything-pattern 0)
10850 ;; move entry to the beginning of the
10851 ;; list, so if two patterns used the
10852 ;; same number of times then the one
10853 ;; used last appears first in the list
10854 (setcdr selection-info
10855 (delete found (cdr selection-info)))
10856 found))
10857 (cdr selection-info)))
10858 (cadr selection-info))))
10860 ;; increase usage count
10861 (setcdr pattern-info (1+ (cdr pattern-info)))
10863 ;; truncate history if needed
10864 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
10865 (setcdr selection-info
10866 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
10868 (defun anything-c-adaptative-maybe-load-history ()
10869 (when (and anything-c-use-adaptative-sorting
10870 (file-readable-p anything-c-adaptive-history-file))
10871 (load-file anything-c-adaptive-history-file)))
10873 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
10874 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
10876 (defun anything-c-adaptive-save-history (&optional arg)
10877 "Save history information to file given by `anything-c-adaptive-history-file'."
10878 (interactive "p")
10879 (when anything-c-use-adaptative-sorting
10880 (with-temp-buffer
10881 (insert
10882 ";; -*- mode: emacs-lisp -*-\n"
10883 ";; History entries used for anything adaptive display.\n")
10884 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
10885 (current-buffer))
10886 (insert ?\n)
10887 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10888 (unless arg 'quiet)))))
10890 (defun anything-c-adaptive-sort (candidates source)
10891 "Sort the CANDIDATES for SOURCE by usage frequency.
10892 This is a filtered candidate transformer you can use for the
10893 attribute `filtered-candidate-transformer' of a source in
10894 `anything-sources' or a type in `anything-type-attributes'."
10895 (let* ((source-name (or (assoc-default 'type source)
10896 (assoc-default 'name source)))
10897 (source-info (assoc source-name anything-c-adaptive-history)))
10898 (if source-info
10899 (let ((usage
10900 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10901 ;; pairs
10902 (mapcar (lambda (candidate-info)
10903 (let ((count 0))
10904 (dolist (pattern-info (cdr candidate-info))
10905 (if (not (equal (car pattern-info)
10906 anything-pattern))
10907 (incf count (cdr pattern-info))
10909 ;; if current pattern is equal to the previously
10910 ;; used one then this candidate has priority
10911 ;; (that's why its count is boosted by 10000) and
10912 ;; it only has to compete with other candidates
10913 ;; which were also selected with the same pattern
10914 (setq count (+ 10000 (cdr pattern-info)))
10915 (return)))
10916 (cons (car candidate-info) count)))
10917 (cdr source-info)))
10918 sorted)
10919 (if (and usage (consp usage))
10920 ;; sort the list in descending order, so candidates with highest
10921 ;; priorty come first
10922 (progn
10923 (setq usage (sort usage (lambda (first second)
10924 (> (cdr first) (cdr second)))))
10926 ;; put those candidates first which have the highest usage count
10927 (dolist (info usage)
10928 (when (member* (car info) candidates
10929 :test 'anything-c-adaptive-compare)
10930 (push (car info) sorted)
10931 (setq candidates (remove* (car info) candidates
10932 :test 'anything-c-adaptive-compare))))
10934 ;; and append the rest
10935 (append (reverse sorted) candidates nil))
10936 (message "Your `%s' is maybe corrupted or too old, \
10937 you should reinitialize it with `anything-c-reset-adaptative-history'"
10938 anything-c-adaptive-history-file)
10939 (sit-for 1)
10940 candidates))
10941 ;; if there is no information stored for this source then do nothing
10942 candidates)))
10944 ;;;###autoload
10945 (defun anything-c-reset-adaptative-history ()
10946 "Delete all `anything-c-adaptive-history' and his file.
10947 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10948 (interactive)
10949 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10950 (setq anything-c-adaptive-history nil)
10951 (delete-file anything-c-adaptive-history-file)))
10953 (defun anything-c-adaptive-compare (x y)
10954 "Compare candidates X and Y taking into account that the
10955 candidate can be in (DISPLAY . REAL) format."
10956 (equal (if (listp x)
10957 (cdr x)
10959 (if (listp y)
10960 (cdr y)
10961 y)))
10965 ;;; Outliner
10968 (defvar anything-outline-goto-near-line-flag t)
10969 (defvar anything-outline-using nil)
10970 (defun anything-after-update-hook--outline ()
10971 (if (and (eq anything-outline-using t)
10972 (eq anything-outline-goto-near-line-flag t))
10973 (anything-outline-goto-near-line)))
10974 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
10976 (defun anything-outline-goto-near-line ()
10977 (with-anything-window
10978 ;; TODO need consideration whether to update position by every input.
10979 (when t ; (equal anything-pattern "")
10980 (anything-goto-line 2)
10981 (let ((lineno (with-anything-current-buffer
10982 (line-number-at-pos (car anything-current-position)))))
10983 (block exit
10984 (while (<= (progn (skip-chars-forward " ")
10985 (or (number-at-point) lineno))
10986 lineno)
10987 (forward-line 1)
10988 (when (eobp)
10989 (forward-line -1)
10990 (return-from exit))))
10991 (forward-line -1)
10992 (and (bobp) (forward-line 1))
10993 (and (anything-pos-header-line-p) (forward-line -2))
10994 (anything-mark-current-line)))))
10998 ;;; Plug-in
11001 ;; Plug-in: info-index
11002 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
11003 (let (result)
11004 (unless (anything-candidate-buffer)
11005 (save-window-excursion
11006 (info file)
11007 (let (Info-history
11008 (tobuf (anything-candidate-buffer 'global))
11009 (infobuf (current-buffer))
11010 s e)
11011 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
11012 (Info-goto-node node)
11013 (goto-char (point-min))
11014 (while (search-forward "\n* " nil t)
11015 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
11016 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
11017 (setq s (point-at-bol)
11018 e (point-at-eol))
11019 (with-current-buffer tobuf
11020 (insert-buffer-substring infobuf s e)
11021 (insert "\n"))))))))))
11023 (defun anything-c-info-goto (node-line)
11024 (Info-goto-node (car node-line))
11025 (anything-goto-line (cdr node-line)))
11027 (defun anything-c-info-display-to-real (line)
11028 (and (string-match
11029 ;; This regexp is stolen from Info-apropos-matches
11030 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
11031 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
11032 (string-to-number (or (match-string 3 line) "1")))))
11034 (defun anything-c-make-info-source (source file)
11035 `(,@source
11036 (name . ,(concat "Info Index: " file))
11037 (info-file . ,file)
11038 (init . anything-c-info-init)
11039 (display-to-real . anything-c-info-display-to-real)
11040 (get-line . buffer-substring)
11041 (candidates-in-buffer)
11042 (action ("Goto node" . anything-c-info-goto))))
11044 (defun anything-compile-source--info-index (source)
11045 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
11046 (anything-c-make-info-source source it)
11047 source))
11048 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
11050 (anything-document-attribute 'info-index "info-index plugin"
11051 "Create a source of info index very easily.
11053 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11055 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
11056 "Index nodes of info file.
11058 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11059 Some info files are missing index specification.
11061 ex. See `anything-c-source-info-screen'.")
11063 ;; Plug-in: candidates-file
11064 (defun anything-compile-source--candidates-file (source)
11065 (if (assoc-default 'candidates-file source)
11066 `((init anything-p-candidats-file-init
11067 ,@(let ((orig-init (assoc-default 'init source)))
11068 (cond ((null orig-init) nil)
11069 ((functionp orig-init) (list orig-init))
11070 (t orig-init))))
11071 (candidates-in-buffer)
11072 ,@source)
11073 source))
11074 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11076 (defun anything-p-candidats-file-init ()
11077 (destructuring-bind (file &optional updating)
11078 (anything-mklist (anything-attr 'candidates-file))
11079 (setq file (anything-interpret-value file))
11080 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11081 (when updating
11082 (buffer-disable-undo)
11083 (font-lock-mode -1)
11084 (auto-revert-mode 1)))))
11086 (anything-document-attribute 'candidates-file "candidates-file plugin"
11087 "Use a file as the candidates buffer.
11089 1st argument is a filename, string or function name or variable name.
11090 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11092 ;; Plug-in: headline
11093 (defun anything-compile-source--anything-headline (source)
11094 (if (assoc-default 'headline source)
11095 (append '((init . anything-headline-init)
11096 (get-line . buffer-substring)
11097 (type . line))
11098 source
11099 '((candidates-in-buffer)
11100 (persistent-help . "Show this line")))
11101 source))
11102 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11104 (defun anything-headline-init ()
11105 (when (and (anything-current-buffer-is-modified)
11106 (with-anything-current-buffer
11107 (eval (or (anything-attr 'condition) t))))
11108 (anything-headline-make-candidate-buffer
11109 (anything-interpret-value (anything-attr 'headline))
11110 (anything-interpret-value (anything-attr 'subexp)))))
11112 (anything-document-attribute 'headline "Headline plug-in"
11113 "Regexp string for anything-headline to scan.")
11114 (anything-document-attribute 'condition "Headline plug-in"
11115 "A sexp representing the condition to use anything-headline.")
11116 (anything-document-attribute 'subexp "Headline plug-in"
11117 "Display (match-string-no-properties subexp).")
11119 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11120 ;; of regexps.
11122 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11123 ;; 2. Sort this list by start-of-match.
11124 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11126 ;; It's quite brilliantly written.
11130 (defun anything-headline-get-candidates (regexp subexp)
11131 (with-anything-current-buffer
11132 (save-excursion
11133 (goto-char (point-min))
11134 (if (functionp regexp) (setq regexp (funcall regexp)))
11135 (let (hierarchy curhead)
11136 (flet ((matched ()
11137 (if (numberp subexp)
11138 (cons (match-string-no-properties subexp) (match-beginning subexp))
11139 (cons (buffer-substring (point-at-bol) (point-at-eol))
11140 (point-at-bol))))
11141 (hierarchies (headlines)
11142 (1+ (loop for (_ . hierarchy) in headlines
11143 maximize hierarchy)))
11144 (vector-0-n (v n)
11145 (loop for i from 0 to hierarchy
11146 collecting (aref curhead i)))
11147 (arrange (headlines)
11148 (unless (null headlines) ; FIX headlines empty bug!
11149 (loop with curhead = (make-vector (hierarchies headlines) "")
11150 for ((str . pt) . hierarchy) in headlines
11151 do (aset curhead hierarchy str)
11152 collecting
11153 (cons
11154 (format "H%d:%s" (1+ hierarchy)
11155 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11156 pt)))))
11157 (if (listp regexp)
11158 (arrange
11159 (sort
11160 (loop for re in regexp
11161 for hierarchy from 0
11162 do (goto-char (point-min))
11163 appending
11164 (loop
11165 while (re-search-forward re nil t)
11166 collect (cons (matched) hierarchy)))
11167 (lambda (a b) (> (cdar b) (cdar a)))))
11168 (loop while (re-search-forward regexp nil t)
11169 collect (matched))))))))
11172 (defun anything-headline-make-candidate-buffer (regexp subexp)
11173 (with-current-buffer (anything-candidate-buffer 'local)
11174 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11175 do (insert
11176 (format "%5d:%s\n"
11177 (with-anything-current-buffer
11178 (line-number-at-pos pos))
11179 content)))))
11181 (defun anything-headline-goto-position (pos recenter)
11182 (goto-char pos)
11183 (unless recenter
11184 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11187 ;; Plug-in: persistent-help
11188 (defun anything-compile-source--persistent-help (source)
11189 (append source '((header-line . anything-persistent-help-string))))
11190 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11192 (defun anything-persistent-help-string ()
11193 (substitute-command-keys
11194 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11195 (or (anything-interpret-value (anything-attr 'persistent-help))
11196 (anything-aif (or (assoc-default 'persistent-action
11197 (anything-get-current-source))
11198 (assoc-default 'action
11199 (anything-get-current-source)))
11200 (cond ((symbolp it) (symbol-name it))
11201 ((listp it) (or (ignore-errors (caar it)) ""))))
11203 " (keeping session)")))
11205 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11206 "A string to explain persistent-action of this source.
11207 It also accepts a function or a variable name.")
11209 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11211 ;; Plug-in: Type customize
11212 (defun anything-c-uniq-list (lst)
11213 "Like `remove-duplicates' in CL.
11214 But cut deeper duplicates and test by `equal'. "
11215 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11216 (defvar anything-additional-type-attributes nil)
11217 (defun anything-c-arrange-type-attribute (type spec)
11218 "Override type attributes by `define-anything-type-attribute'.
11220 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11222 Example: Set `play-sound-file' as default action
11223 (anything-c-arrange-type-attribute 'file
11224 '((action (\"Play sound\" . play-sound-file)
11225 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11228 (add-to-list 'anything-additional-type-attributes
11229 (cons type
11230 (loop with typeattr = (assoc-default type anything-type-attributes)
11231 for (attr . value) in spec
11232 if (listp value)
11233 collect (cons attr
11234 (anything-c-uniq-list
11235 (loop for v in value
11236 if (eq v 'REST)
11237 append (assoc-default attr typeattr)
11238 else
11239 collect v)))
11240 else
11241 collect (cons attr value)))))
11242 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11244 (defun anything-compile-source--type-customize (source)
11245 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11246 (append it source)
11247 source))
11248 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11250 ;; Plug-in: default-action
11251 (defun anything-compile-source--default-action (source)
11252 (anything-aif (assoc-default 'default-action source)
11253 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11254 source)
11255 source))
11256 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11257 (anything-document-attribute 'default-action "default-action plug-in"
11258 "Default action.")
11261 ;;; Toggle anything-match-plugin
11264 (defvar anything-mp-initial-highlight-delay nil)
11266 ;;;###autoload
11267 (defun anything-c-toggle-match-plugin ()
11268 "Toggle anything-match-plugin."
11269 (interactive)
11270 (let ((anything-match-plugin-enabled
11271 (member 'anything-compile-source--match-plugin
11272 anything-compile-source-functions)))
11273 (flet ((disable-match-plugin ()
11274 (setq anything-compile-source-functions
11275 (delq 'anything-compile-source--match-plugin
11276 anything-compile-source-functions))
11277 (setq anything-mp-initial-highlight-delay
11278 anything-mp-highlight-delay)
11279 (setq anything-mp-highlight-delay nil))
11280 (enable-match-plugin ()
11281 (require 'anything-match-plugin)
11282 (unless anything-mp-initial-highlight-delay
11283 (setq anything-mp-initial-highlight-delay
11284 anything-mp-highlight-delay))
11285 (setq anything-compile-source-functions
11286 (cons 'anything-compile-source--match-plugin
11287 anything-compile-source-functions))
11288 (unless anything-mp-highlight-delay
11289 (setq anything-mp-highlight-delay
11290 anything-mp-initial-highlight-delay))))
11291 (if anything-match-plugin-enabled
11292 (when (y-or-n-p "Really disable match-plugin? ")
11293 (disable-match-plugin)
11294 (message "Anything-match-plugin disabled"))
11295 (when (y-or-n-p "Really enable match-plugin? ")
11296 (enable-match-plugin)
11297 (message "Anything-match-plugin enabled"))))))
11301 ;;; Type Attributes
11304 (define-anything-type-attribute 'buffer
11305 `((action
11306 ("Switch to buffer" . anything-c-switch-to-buffer)
11307 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11308 ("Switch to buffer other window" . switch-to-buffer-other-window)
11309 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11310 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11311 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11312 ("Query replace" . anything-c-buffer-query-replace)
11313 ("View buffer" . view-buffer)
11314 ("Display buffer" . display-buffer)
11315 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11316 ("Revert buffer(s)" . anything-revert-marked-buffers)
11317 ("Insert buffer" . insert-buffer)
11318 ("Kill buffer(s)" . anything-kill-marked-buffers)
11319 ("Diff with file" . diff-buffer-with-file)
11320 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11321 ("Ediff Merge marked buffers" . (lambda (candidate)
11322 (anything-ediff-marked-buffers candidate t))))
11323 (persistent-help . "Show this buffer")
11324 (candidate-transformer anything-c-skip-current-buffer
11325 anything-c-skip-boring-buffers
11326 anything-c-transform-buffer-display-string))
11327 "Buffer or buffer name.")
11329 (define-anything-type-attribute 'file
11330 `((action
11331 ("Find file" . anything-find-many-files)
11332 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11333 ("Find file as root" . anything-find-file-as-root)
11334 ("Find file other window" . find-file-other-window)
11335 ("Find file other frame" . find-file-other-frame)
11336 ("Open dired in file's directory" . anything-c-open-dired)
11337 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11338 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11339 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11340 ("Checksum File" . anything-ff-checksum)
11341 ("Ediff File" . anything-find-files-ediff-files)
11342 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11343 ("View file" . view-file)
11344 ("Insert file" . insert-file)
11345 ("Delete file(s)" . anything-delete-marked-files)
11346 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11347 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11348 ("Find file in hex dump" . hexl-find-file))
11349 (persistent-help . "Show this file")
11350 (action-transformer anything-c-transform-file-load-el
11351 anything-c-transform-file-browse-url)
11352 (candidate-transformer anything-c-w32-pathname-transformer
11353 anything-c-skip-current-file
11354 anything-c-skip-boring-files
11355 anything-c-shorten-home-path))
11356 "File name.")
11358 (let ((actions '(("Describe command" . describe-function)
11359 ("Add command to kill ring" . anything-c-kill-new)
11360 ("Go to command's definition" . find-function)
11361 ("Debug on entry" . debug-on-entry)
11362 ("Cancel debug on entry" . cancel-debug-on-entry)
11363 ("Trace function" . trace-function)
11364 ("Trace function (background)" . trace-function-background)
11365 ("Untrace function" . untrace-function))))
11366 (define-anything-type-attribute 'command
11367 `((action ("Call interactively" . anything-c-call-interactively)
11368 ,@actions)
11369 ;; Sort commands according to their usage count.
11370 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11371 (coerce . anything-c-symbolify)
11372 (persistent-action . describe-function))
11373 "Command. (string or symbol)")
11375 (define-anything-type-attribute 'function
11376 `((action . ,actions)
11377 (action-transformer anything-c-transform-function-call-interactively)
11378 (candidate-transformer anything-c-mark-interactive-functions)
11379 (coerce . anything-c-symbolify))
11380 "Function. (string or symbol)"))
11382 (define-anything-type-attribute 'variable
11383 '((action ("Describe variable" . describe-variable)
11384 ("Add variable to kill ring" . anything-c-kill-new)
11385 ("Go to variable's definition" . find-variable)
11386 ("Set variable" . anything-c-set-variable))
11387 (coerce . anything-c-symbolify))
11388 "Variable.")
11390 (define-anything-type-attribute 'sexp
11391 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11392 ("Add s-expression to kill ring" . kill-new))
11393 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11394 "String representing S-Expressions.")
11396 (define-anything-type-attribute 'bookmark
11397 `((coerce . anything-bookmark-get-bookmark-from-name)
11398 (action
11399 ("Jump to bookmark" . (lambda (bookmark)
11400 (let ((current-prefix-arg anything-current-prefix-arg))
11401 (bookmark-jump bookmark))
11402 (anything-update)))
11403 ("Jump to BM other window" . (lambda (bookmark)
11404 (bookmark-jump-other-window bookmark)
11405 (anything-update)))
11406 ("Bookmark edit annotation" . bookmark-edit-annotation)
11407 ("Bookmark show annotation" . bookmark-show-annotation)
11408 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11409 ,@(and (locate-library "bookmark-extensions")
11410 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11411 ("Rename bookmark" . bookmark-rename)
11412 ("Relocate bookmark" . bookmark-relocate)))
11413 "Bookmark name.")
11415 (define-anything-type-attribute 'line
11416 '((display-to-real . anything-c-display-to-real-line)
11417 (action ("Go to Line" . anything-c-action-line-goto)))
11418 "LINENO:CONTENT string, eg. \" 16:foo\".
11420 Optional `target-file' attribute is a name of target file.
11422 Optional `before-jump-hook' attribute is a function with no
11423 arguments which is called before jumping to position.
11425 Optional `after-jump-hook' attribute is a function with no
11426 arguments which is called after jumping to position.
11428 If `adjust' attribute is specified, searches the line whose
11429 content is CONTENT near the LINENO.
11431 If `recenter' attribute is specified, the line is displayed at
11432 the center of window, otherwise at the top of window.
11435 (define-anything-type-attribute 'file-line
11436 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11437 (multiline)
11438 (action ("Go to" . anything-c-action-file-line-goto)))
11439 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11441 Optional `default-directory' attribute is a default-directory
11442 FILENAME is interpreted.
11444 Optional `before-jump-hook' attribute is a function with no
11445 arguments which is called before jumping to position.
11447 Optional `after-jump-hook' attribute is a function with no
11448 arguments which is called after jumping to position.
11450 If `adjust' attribute is specified, searches the line whose
11451 content is CONTENT near the LINENO.
11453 If `recenter' attribute is specified, the line is displayed at
11454 the center of window, otherwise at the top of window.
11457 (define-anything-type-attribute 'timer
11458 '((real-to-display . anything-c-timer-real-to-display)
11459 (action ("Cancel Timer" . cancel-timer)
11460 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11461 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11462 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11463 (persistent-help . "Describe Function"))
11464 "Timer.")
11467 ;;; Default `anything-sources'
11468 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11469 ;; tend to invoke M-x anything directly. So I offer default setting.
11470 (setq anything-sources
11471 '(anything-c-source-buffers-list
11472 anything-c-source-recentf
11473 anything-c-source-files-in-current-dir+))
11476 ;;; Preconfigured Anything
11479 ;;;###autoload
11480 (defun anything-mini ()
11481 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11482 (interactive)
11483 (anything-other-buffer '(anything-c-source-buffers-list
11484 anything-c-source-recentf
11485 anything-c-source-buffer-not-found)
11486 "*anything mini*"))
11487 ;;;###autoload
11488 (defun anything-for-files ()
11489 "Preconfigured `anything' for opening files.
11490 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11491 (interactive)
11492 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
11494 ;;;###autoload
11495 (defun anything-recentf ()
11496 "Preconfigured `anything' for `recentf'."
11497 (interactive)
11498 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
11500 ;;;###autoload
11501 (defun anything-info-at-point (arg)
11502 "Preconfigured `anything' for searching info at point.
11503 With a prefix-arg insert symbol at point."
11504 (interactive "P")
11505 (let ((anything-c-google-suggest-default-function
11506 'anything-c-google-suggest-emacs-lisp))
11507 (anything :sources '(anything-c-source-info-elisp
11508 anything-c-source-info-cl
11509 anything-c-source-info-pages
11510 anything-c-source-google-suggest)
11511 :input (and arg (thing-at-point 'symbol))
11512 :buffer "*anything info*")))
11514 ;;;###autoload
11515 (defun anything-info-emacs ()
11516 "Preconfigured anything for Emacs manual index."
11517 (interactive)
11518 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
11520 ;;;###autoload
11521 (defun anything-show-kill-ring ()
11522 "Preconfigured `anything' for `kill-ring'.
11523 It is drop-in replacement of `yank-pop'.
11524 You may bind this command to M-y.
11525 First call open the kill-ring browser, next calls move to next line."
11526 (interactive)
11527 (let ((buf "*anything kill-ring*"))
11528 (if (get-buffer-window buf)
11529 (with-anything-window
11530 (if (eq (overlay-end anything-selection-overlay) (point-max))
11531 (anything-beginning-of-buffer)
11532 (anything-next-line)))
11533 (anything-other-buffer 'anything-c-source-kill-ring buf))))
11535 ;;;###autoload
11536 (defun anything-minibuffer-history ()
11537 "Preconfigured `anything' for `minibuffer-history'."
11538 (interactive)
11539 (let ((enable-recursive-minibuffers t))
11540 (anything-other-buffer 'anything-c-source-minibuffer-history
11541 "*anything minibuffer-history*")))
11543 ;;;###autoload
11544 (defun anything-gentoo ()
11545 "Preconfigured `anything' for gentoo linux."
11546 (interactive)
11547 (anything-other-buffer '(anything-c-source-gentoo
11548 anything-c-source-use-flags)
11549 "*anything gentoo*"))
11551 ;;;###autoload
11552 (defun anything-imenu ()
11553 "Preconfigured `anything' for `imenu'."
11554 (interactive)
11555 (anything :sources 'anything-c-source-imenu
11556 :buffer "*anything imenu*"))
11558 ;;;###autoload
11559 (defun anything-google-suggest ()
11560 "Preconfigured `anything' for google search with google suggest."
11561 (interactive)
11562 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
11564 ;;;###autoload
11565 (defun anything-yahoo-suggest ()
11566 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11567 (interactive)
11568 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
11570 ;;; Converted from anything-show-*-only
11571 ;;;###autoload
11572 (defun anything-for-buffers ()
11573 "Preconfigured `anything' for buffer."
11574 (interactive)
11575 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
11577 ;;;###autoload
11578 (defun anything-buffers-list ()
11579 "Enhanced preconfigured `anything' for buffer."
11580 (interactive)
11581 (anything :sources '(anything-c-source-buffers-list
11582 anything-c-source-buffer-not-found)
11583 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
11585 ;;;###autoload
11586 (defun anything-bbdb ()
11587 "Preconfigured `anything' for BBDB.
11589 Needs BBDB.
11591 http://bbdb.sourceforge.net/"
11592 (interactive)
11593 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
11595 ;;;###autoload
11596 (defun anything-locate (arg)
11597 "Preconfigured `anything' for Locate.
11598 Note: you can add locate options after entering pattern.
11599 See 'man locate' for valid options.
11601 You can specify a specific database with prefix argument ARG \(C-u\).
11602 Many databases can be used: navigate and mark them.
11603 See also `anything-locate-with-db'.
11605 To create a user specific db, use
11606 \"updatedb -l 0 -o db_path -U directory\".
11607 Where db_path is a filename matched by
11608 `anything-locate-db-file-regexp'."
11609 (interactive "P")
11610 (anything-locate-1 arg))
11612 ;;;###autoload
11613 (defun anything-w3m-bookmarks ()
11614 "Preconfigured `anything' for w3m bookmark.
11616 Needs w3m and emacs-w3m.
11618 http://w3m.sourceforge.net/
11619 http://emacs-w3m.namazu.org/"
11620 (interactive)
11621 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11622 "*anything w3m bookmarks*"))
11624 ;;;###autoload
11625 (defun anything-firefox-bookmarks ()
11626 "Preconfigured `anything' for firefox bookmark.
11627 You will have to enable html bookmarks in firefox:
11628 open about:config in firefox and double click on this line to enable value \
11629 to true:
11631 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11633 You should have now:
11635 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11637 After closing firefox, you will be able to browse you bookmarks.
11639 (interactive)
11640 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11641 "*Anything Firefox*"))
11643 ;;;###autoload
11644 (defun anything-colors ()
11645 "Preconfigured `anything' for color."
11646 (interactive)
11647 (anything-other-buffer
11648 '(anything-c-source-colors anything-c-source-customize-face)
11649 "*anything colors*"))
11651 ;;;###autoload
11652 (defun anything-bookmarks ()
11653 "Preconfigured `anything' for bookmarks."
11654 (interactive)
11655 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
11657 ;;;###autoload
11658 (defun anything-c-pp-bookmarks ()
11659 "Preconfigured `anything' for bookmarks (pretty-printed)."
11660 (interactive)
11661 (anything-other-buffer '(anything-c-source-bookmarks-local
11662 anything-c-source-bookmarks-su
11663 anything-c-source-bookmarks-ssh)
11664 "*anything pp bookmarks*"))
11666 ;;;###autoload
11667 (defun anything-c-insert-latex-math ()
11668 "Preconfigured anything for latex math symbols completion."
11669 (interactive)
11670 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
11672 ;;;###autoload
11673 (defun anything-register ()
11674 "Preconfigured `anything' for Emacs registers."
11675 (interactive)
11676 (anything-other-buffer 'anything-c-source-register "*anything register*"))
11678 ;;;###autoload
11679 (defun anything-man-woman ()
11680 "Preconfigured `anything' for Man and Woman pages."
11681 (interactive)
11682 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
11684 ;;;###autoload
11685 (defun anything-org-keywords ()
11686 "Preconfigured `anything' for org keywords."
11687 (interactive)
11688 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
11690 ;;;###autoload
11691 (defun anything-emms ()
11692 "Preconfigured `anything' for emms sources."
11693 (interactive)
11694 (anything :sources '(anything-c-source-emms-streams
11695 anything-c-source-emms-files
11696 anything-c-source-emms-dired)
11697 :buffer "*Anything Emms*"))
11699 ;;;###autoload
11700 (defun anything-eev-anchors ()
11701 "Preconfigured `anything' for eev anchors."
11702 (interactive)
11703 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
11705 ;;;###autoload
11706 (defun anything-bm-list ()
11707 "Preconfigured `anything' for visible bookmarks.
11709 Needs bm.el
11711 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11712 (interactive)
11713 (let ((anything-outline-using t))
11714 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
11716 ;;;###autoload
11717 (defun anything-timers ()
11718 "Preconfigured `anything' for timers."
11719 (interactive)
11720 (anything-other-buffer '(anything-c-source-absolute-time-timers
11721 anything-c-source-idle-time-timers)
11722 "*anything timers*"))
11724 ;;;###autoload
11725 (defun anything-list-emacs-process ()
11726 "Preconfigured `anything' for emacs process."
11727 (interactive)
11728 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
11730 ;;;###autoload
11731 (defun anything-occur ()
11732 "Preconfigured Anything for Occur source.
11733 If region is active, search only in region,
11734 otherwise search in whole buffer."
11735 (interactive)
11736 (let ((anything-compile-source-functions
11737 ;; rule out anything-match-plugin because the input is one regexp.
11738 (delq 'anything-compile-source--match-plugin
11739 (copy-sequence anything-compile-source-functions))))
11740 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
11742 ;;;###autoload
11743 (defun anything-browse-code ()
11744 "Preconfigured anything to browse code."
11745 (interactive)
11746 (anything :sources 'anything-c-source-browse-code
11747 :buffer "*anything browse code*"
11748 :default (thing-at-point 'symbol)))
11750 ;;;###autoload
11751 (defun anything-org-headlines ()
11752 "Preconfigured anything to show org headlines."
11753 (interactive)
11754 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
11756 ;;;###autoload
11757 (defun anything-info-gnus ()
11758 "Preconfigured anything to browse Gnus Manual."
11759 (interactive)
11760 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
11762 ;;;###autoload
11763 (defun anything-regexp ()
11764 "Preconfigured anything to build regexps.
11765 `query-replace-regexp' can be run from there against found regexp."
11766 (interactive)
11767 (save-restriction
11768 (let ((anything-compile-source-functions
11769 ;; rule out anything-match-plugin because the input is one regexp.
11770 (delq 'anything-compile-source--match-plugin
11771 (copy-sequence anything-compile-source-functions))))
11772 (when (and (anything-region-active-p)
11773 ;; Don't narrow to region if buffer is already narrowed.
11774 (not (anything-current-buffer-narrowed-p)))
11775 (narrow-to-region (region-beginning) (region-end)))
11776 (anything :sources anything-c-source-regexp
11777 :buffer "*anything regexp*"
11778 :prompt "Regexp: "
11779 :history 'anything-build-regexp-history))))
11781 (defun anything-c-copy-files-async ()
11782 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11783 (interactive)
11784 (let* ((flist (anything-c-read-file-name
11785 "Copy File async: "
11786 :marked-candidates t))
11787 (dest (anything-c-read-file-name
11788 "Copy File async To: "
11789 :preselect (car flist)
11790 :initial-input (car anything-ff-history)
11791 :history (anything-find-files-history :comp-read nil))))
11792 (anything-c-copy-async-with-log flist dest)))
11794 ;;;###autoload
11795 (defun anything-find-files (arg)
11796 "Preconfigured `anything' for anything implementation of `find-file'.
11797 Called with a prefix arg show history if some.
11798 Don't call it from programs, use `anything-find-files-1' instead.
11799 This is the starting point for nearly all actions you can do on files."
11800 (interactive "P")
11801 (let ((any-input (if (and arg anything-ff-history)
11802 (anything-find-files-history)
11803 (anything-find-files-initial-input)))
11804 (presel (buffer-file-name (current-buffer))))
11805 (when (and (eq major-mode 'org-agenda-mode)
11806 org-directory
11807 (not any-input))
11808 (setq any-input (expand-file-name org-directory)))
11809 (set-text-properties 0 (length any-input) nil any-input)
11810 (if any-input
11811 (anything-find-files-1 any-input)
11812 (setq any-input (expand-file-name (anything-c-current-directory)))
11813 (anything-find-files-1
11814 any-input (if anything-ff-transformer-show-only-basename
11815 (and presel (anything-c-basename presel))
11816 presel)))))
11818 ;;;###autoload
11819 (defun anything-write-file ()
11820 "Preconfigured `anything' providing completion for `write-file'."
11821 (interactive)
11822 (let ((anything-mp-highlight-delay nil))
11823 (anything :sources 'anything-c-source-write-file
11824 :input (expand-file-name default-directory)
11825 :prompt "Write buffer to file: "
11826 :buffer "*Anything write file*")))
11828 ;;;###autoload
11829 (defun anything-insert-file ()
11830 "Preconfigured `anything' providing completion for `insert-file'."
11831 (interactive)
11832 (let ((anything-mp-highlight-delay nil))
11833 (anything :sources 'anything-c-source-insert-file
11834 :input (expand-file-name default-directory)
11835 :prompt "Insert file: "
11836 :buffer "*Anything insert file*")))
11838 ;;;###autoload
11839 (defun anything-dired-rename-file ()
11840 "Preconfigured `anything' to rename files from dired."
11841 (interactive)
11842 (anything-dired-do-action-on-file :action 'rename))
11844 ;;;###autoload
11845 (defun anything-dired-copy-file ()
11846 "Preconfigured `anything' to copy files from dired."
11847 (interactive)
11848 (anything-dired-do-action-on-file :action 'copy))
11850 ;;;###autoload
11851 (defun anything-dired-symlink-file ()
11852 "Preconfigured `anything' to symlink files from dired."
11853 (interactive)
11854 (anything-dired-do-action-on-file :action 'symlink))
11856 ;;;###autoload
11857 (defun anything-dired-hardlink-file ()
11858 "Preconfigured `anything' to hardlink files from dired."
11859 (interactive)
11860 (anything-dired-do-action-on-file :action 'hardlink))
11862 ;;;###autoload
11863 (defun anything-do-grep ()
11864 "Preconfigured anything for grep.
11865 Contrarily to Emacs `grep' no default directory is given, but
11866 the full path of candidates in ONLY.
11867 That allow to grep different files not only in `default-directory' but anywhere
11868 by marking them (C-<SPACE>). If one or more directory is selected
11869 grep will search in all files of these directories.
11870 You can use also wildcard in the base name of candidate.
11871 If a prefix arg is given use the -r option of grep.
11872 The prefix arg can be passed before or after start.
11873 See also `anything-do-grep-1'."
11874 (interactive)
11875 (let ((only (anything-c-read-file-name
11876 "Search in file(s): "
11877 :marked-candidates t
11878 :preselect (or (dired-get-filename nil t)
11879 (buffer-file-name (current-buffer)))))
11880 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
11881 (anything-do-grep-1 only prefarg)))
11883 ;;;###autoload
11884 (defun anything-do-zgrep (candidate)
11885 "Preconfigured anything for zgrep."
11886 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
11887 (ls (anything-c-read-file-name
11888 "Search in file(s): "
11889 :marked-candidates t
11890 :preselect (or (dired-get-filename nil t)
11891 (buffer-file-name (current-buffer))))))
11892 (anything-ff-zgrep-1 ls prefarg)))
11894 (defun anything-c-etags-select (arg)
11895 "Preconfigured anything for etags.
11896 Called with one prefix arg use symbol at point as initial input.
11897 Called with two prefix arg reinitialize cache.
11898 If tag file have been modified reinitialize cache."
11899 (interactive "P")
11900 (let ((tag (anything-c-etags-get-tag-file))
11901 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
11902 (anything-quit-if-no-candidate t)
11903 (anything-execute-action-at-once-if-one t)
11904 (anything-compile-source-functions
11905 (if anything-c-etags-use-regexp-search
11906 ;; rule out anything-match-plugin because the input is one regexp.
11907 (delq 'anything-compile-source--match-plugin
11908 (copy-sequence anything-compile-source-functions))
11909 anything-compile-source-functions)))
11910 (when (or (equal arg '(16))
11911 (and anything-c-etags-mtime-alist
11912 (anything-c-etags-file-modified-p tag)))
11913 (remhash tag anything-c-etags-cache))
11914 (if (and tag (file-exists-p tag))
11915 (anything :sources 'anything-c-source-etags-select
11916 :keymap anything-c-etags-map
11917 :input init
11918 :buffer "*anything etags*")
11919 (message "Error: No tag file found, please create one with etags shell command."))))
11921 ;;;###autoload
11922 (defun anything-filelist ()
11923 "Preconfigured `anything' to open files instantly.
11925 See `anything-c-filelist-file-name' docstring for usage."
11926 (interactive)
11927 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
11929 ;;;###autoload
11930 (defun anything-filelist+ ()
11931 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11933 This is a replacement for `anything-for-files'.
11934 See `anything-c-filelist-file-name' docstring for usage."
11935 (interactive)
11936 (anything-other-buffer
11937 '(anything-c-source-ffap-line
11938 anything-c-source-ffap-guesser
11939 anything-c-source-buffers-list
11940 anything-c-source-recentf
11941 anything-c-source-bookmarks
11942 anything-c-source-file-cache
11943 anything-c-source-filelist)
11944 "*anything file list*"))
11946 ;;;###autoload
11947 (defun anything-M-x ()
11948 "Preconfigured `anything' for Emacs commands.
11949 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11950 (interactive)
11951 (let* (in-help
11952 help-cand
11953 special-display-buffer-names
11954 special-display-regexps
11955 anything-persistent-action-use-special-display
11956 (history (loop with hist
11957 for i in extended-command-history
11958 for com = (intern i)
11959 when (fboundp com)
11960 collect i into hist finally return hist)))
11961 (flet ((pers-help (candidate)
11962 (let ((hbuf (get-buffer (help-buffer))))
11963 (if (and in-help (string= candidate help-cand))
11964 (progn
11965 ;; When M-x is started from a help buffer,
11966 ;; Don't kill it as it is anything-current-buffer.
11967 (unless (equal hbuf anything-current-buffer)
11968 (kill-buffer hbuf))
11969 (setq in-help nil))
11970 ;; Be sure anything-current-buffer
11971 ;; have not a dedicated window.
11972 (set-window-dedicated-p
11973 (get-buffer-window anything-current-buffer) nil)
11974 (describe-function (intern candidate))
11975 (message nil) ; Erase the new stupid message Type "q"[...]
11976 (setq in-help t))
11977 (setq help-cand candidate))))
11978 (let* ((command
11980 (anything
11981 :sources
11982 `(((name . "Emacs Commands history")
11983 (candidates . ,history)
11984 (filtered-candidate-transformer
11985 . (lambda (candidates sources)
11986 (loop for i in candidates
11987 do (set-text-properties 0 (length i) nil i)
11988 collect i)))
11989 (persistent-action . pers-help)
11990 (persistent-help . "Describe this command")
11991 (action . identity))
11992 ((name . "Emacs Commands")
11993 (init
11994 . (lambda ()
11995 (with-current-buffer (anything-candidate-buffer 'global)
11996 (goto-char (point-min))
11997 (loop
11998 for sym in (all-completions "" obarray 'commandp)
11999 do (insert (concat sym "\n"))))))
12000 (persistent-action . pers-help)
12001 (persistent-help . "Describe this command")
12002 (filtered-candidate-transformer . anything-M-x-transformer)
12003 (candidates-in-buffer)
12004 (action . identity)))
12005 :resume 'noresume
12006 :history 'anything-M-x-input-history
12007 :buffer "*anything M-x*")
12008 (keyboard-quit)))
12009 (sym-com (intern command)))
12010 (unless current-prefix-arg
12011 (setq current-prefix-arg anything-current-prefix-arg))
12012 ;; Avoid having `this-command' set to *exit-minibuffer.
12013 (setq this-command sym-com)
12014 (call-interactively sym-com)
12015 (setq extended-command-history
12016 (cons command (delete command history)))))))
12018 ;;;###autoload
12019 (defun anything-manage-advice ()
12020 "Preconfigured `anything' to disable/enable function advices."
12021 (interactive)
12022 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
12024 ;;;###autoload
12025 (defun anything-bookmark-ext ()
12026 "Preconfigured `anything' for bookmark-extensions sources.
12027 Needs bookmark-ext.el:
12028 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
12029 Contain also `anything-c-source-google-suggest'."
12030 (interactive)
12031 (anything
12032 :sources
12033 '(anything-c-source-bookmark-files&dirs
12034 anything-c-source-bookmark-w3m
12035 anything-c-source-google-suggest
12036 anything-c-source-bmkext-addressbook
12037 anything-c-source-bookmark-gnus
12038 anything-c-source-bookmark-info
12039 anything-c-source-bookmark-man
12040 anything-c-source-bookmark-images
12041 anything-c-source-bookmark-su-files&dirs
12042 anything-c-source-bookmark-ssh-files&dirs)
12043 :prompt "SearchBookmark: "
12044 :buffer "*anything bmkext*"))
12046 ;;;###autoload
12047 (defun anything-simple-call-tree ()
12048 "Preconfigured `anything' for simple-call-tree. List function relationships.
12050 Needs simple-call-tree.el.
12051 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
12052 (interactive)
12053 (anything-other-buffer
12054 '(anything-c-source-simple-call-tree-functions-callers
12055 anything-c-source-simple-call-tree-callers-functions)
12056 "*anything simple-call-tree*"))
12058 ;;;###autoload
12059 (defun anything-mark-ring ()
12060 "Preconfigured `anything' for `anything-c-source-mark-ring'."
12061 (interactive)
12062 (anything :sources 'anything-c-source-mark-ring))
12064 ;;;###autoload
12065 (defun anything-global-mark-ring ()
12066 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12067 (interactive)
12068 (anything :sources 'anything-c-source-global-mark-ring))
12070 ;;;###autoload
12071 (defun anything-all-mark-rings ()
12072 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12073 `anything-c-source-mark-ring'."
12074 (interactive)
12075 (anything :sources '(anything-c-source-mark-ring
12076 anything-c-source-global-mark-ring)))
12078 ;;;###autoload
12079 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12080 "Preconfigured `anything' to edit or view EmacsWiki page.
12082 Needs yaoddmuse.el.
12084 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12085 (interactive)
12086 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
12088 ;;;###autoload
12089 (defun anything-yaoddmuse-emacswiki-post-library ()
12090 "Preconfigured `anything' to post library to EmacsWiki.
12092 Needs yaoddmuse.el.
12094 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12095 (interactive)
12096 (anything :sources 'anything-c-source-yaoddmuse-emacswiki-post-library))
12098 ;;;###autoload
12099 (defun anything-eval-expression (arg)
12100 "Preconfigured anything for `anything-c-source-evaluation-result'."
12101 (interactive "P")
12102 (anything :sources 'anything-c-source-evaluation-result
12103 :input (when arg (thing-at-point 'sexp))
12104 :buffer "*anything eval*"
12105 :history 'anything-eval-expression-input-history
12106 :keymap anything-eval-expression-map))
12108 ;;;###autoload
12109 (defun anything-eval-expression-with-eldoc ()
12110 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12111 (interactive)
12112 (declare (special eldoc-idle-delay))
12113 (let ((timer (run-with-idle-timer eldoc-idle-delay
12114 'repeat 'anything-eldoc-show-in-eval))
12115 (minibuffer-completing-symbol t) ; Enable lisp completion.
12116 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
12117 (unwind-protect
12118 (minibuffer-with-setup-hook
12119 'anything-eldoc-store-minibuffer
12120 (call-interactively 'anything-eval-expression))
12121 (and timer (cancel-timer timer))
12122 (setq anything-eldoc-active-minibuffers-list
12123 (cdr anything-eldoc-active-minibuffers-list)))))
12125 ;;;###autoload
12126 (defun anything-calcul-expression ()
12127 "Preconfigured anything for `anything-c-source-calculation-result'."
12128 (interactive)
12129 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
12131 ;;;###autoload
12132 (defun anything-surfraw (pattern engine)
12133 "Preconfigured `anything' to search PATTERN with search ENGINE."
12134 (interactive (list (read-string "SearchFor: "
12135 nil 'anything-surfraw-input-history)
12136 (anything-comp-read
12137 "Engine: "
12138 (anything-c-build-elvi-list)
12139 :must-match t
12140 :name "Surfraw Search Engines"
12141 :history anything-surfraw-engines-history)))
12142 (let* ((engine-nodesc (car (split-string engine)))
12143 (url (with-temp-buffer
12144 (apply 'call-process "surfraw" nil t nil
12145 ;;JAVE
12146 (append (list engine-nodesc "-p") (split-string pattern)))
12147 (replace-regexp-in-string
12148 "\n" "" (buffer-string))))
12149 (browse-url-browser-function (or anything-surfraw-default-browser-function
12150 browse-url-browser-function)))
12151 (if (string= engine-nodesc "W")
12152 (anything-c-browse-url)
12153 (anything-c-browse-url url)
12154 (setq anything-surfraw-engines-history
12155 (cons engine (delete engine anything-surfraw-engines-history))))))
12157 ;;;###autoload
12158 (defun anything-call-source ()
12159 "Preconfigured `anything' to call anything source."
12160 (interactive)
12161 (anything :sources 'anything-c-source-call-source
12162 :buffer anything-source-select-buffer))
12164 ;;;###autoload
12165 (defun anything-execute-anything-command ()
12166 "Preconfigured `anything' to execute preconfigured `anything'."
12167 (interactive)
12168 (anything-other-buffer 'anything-c-source-anything-commands
12169 "*anything commands*"))
12171 ;;;###autoload
12172 (defun anything-create (&optional string initial-input)
12173 "Preconfigured `anything' to do many create actions from STRING.
12174 See also `anything-create--actions'."
12175 (interactive)
12176 (setq string (or string (read-string "Create Anything: " initial-input)))
12177 (anything :sources '(((name . "Anything Create")
12178 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
12179 (candidates . anything-create--actions)
12180 (candidate-number-limit)
12181 (action . (lambda (func) (funcall func string)))))))
12183 ;;;###autoload
12184 (defun anything-top ()
12185 "Preconfigured `anything' for top command."
12186 (interactive)
12187 (let ((anything-samewindow t)
12188 (anything-enable-shortcuts)
12189 (anything-display-function 'anything-default-display-buffer)
12190 (anything-candidate-number-limit 9999))
12191 (save-window-excursion
12192 (delete-other-windows)
12193 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
12195 ;;;###autoload
12196 (defun anything-select-xfont ()
12197 "Preconfigured `anything' to select Xfont."
12198 (interactive)
12199 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
12201 ;;;###autoload
12202 (defun anything-world-time ()
12203 "Preconfigured `anything' to show world time."
12204 (interactive)
12205 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
12207 ;;;###autoload
12208 (defun anything-apt (arg)
12209 "Preconfigured `anything' : frontend of APT package manager.
12210 With a prefix arg reload cache."
12211 (interactive "P")
12212 (let ((query (read-string "Search Package: " nil 'anything-c-apt-input-history)))
12213 (when arg (anything-c-apt-refresh))
12214 (anything :sources 'anything-c-source-apt
12215 :prompt "Search Package: "
12216 :input query
12217 :history 'anything-c-apt-input-history)))
12219 ;;;###autoload
12220 (defun anything-esh-pcomplete ()
12221 "Preconfigured anything to provide anything completion in eshell."
12222 (interactive)
12223 (let* ((anything-quit-if-no-candidate t)
12224 (anything-execute-action-at-once-if-one t)
12225 (target (thing-at-point 'symbol))
12226 (end (point))
12227 (beg (or (and target (- end (length target)))
12228 ;; Nothing at point.
12229 (progn (insert " ") (point)))))
12230 (setq anything-ec-target (or target " "))
12231 (with-anything-show-completion beg end
12232 (anything :sources 'anything-c-source-esh
12233 :input (anything-ff-set-pattern ; Handle tramp filenames.
12234 (car (last (ignore-errors ; Needed in lisp symbols completion.
12235 (pcomplete-parse-arguments)))))))))
12237 ;;;###autoload
12238 (defun anything-eshell-history ()
12239 "Preconfigured anything for eshell history."
12240 (interactive)
12241 (let* ((end (point))
12242 (beg (save-excursion (eshell-bol) (point)))
12243 flag-empty)
12244 (when (eq beg end)
12245 (insert " ")
12246 (setq flag-empty t)
12247 (setq end (point)))
12248 (unwind-protect
12249 (with-anything-show-completion beg end
12250 (anything :sources 'anything-c-source-eshell-history
12251 :buffer "*Eshell history*"))
12252 (when (and flag-empty
12253 (looking-back " "))
12254 (delete-char -1)))))
12256 ;;;###autoload
12257 (defun anything-c-run-external-command (program)
12258 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12259 If program is already running exit with error.
12260 You can set your own list of commands with
12261 `anything-c-external-commands-list'."
12262 (interactive (list
12263 (anything-comp-read
12264 "RunProgram: "
12265 (anything-c-external-commands-list-1 'sort)
12266 :must-match t
12267 :name "External Commands"
12268 :history anything-external-command-history)))
12269 (anything-run-or-raise program)
12270 (setq anything-external-command-history
12271 (cons program (delete program
12272 (loop for i in anything-external-command-history
12273 when (executable-find i) collect i)))))
12275 ;;;###autoload
12276 (defun anything-ratpoison-commands ()
12277 "Preconfigured `anything' to execute ratpoison commands."
12278 (interactive)
12279 (anything-other-buffer 'anything-c-source-ratpoison-commands
12280 "*anything ratpoison commands*"))
12282 ;;;###autoload
12283 (defun anything-ucs ()
12284 "Preconfigured anything for `ucs-names' math symbols."
12285 (interactive)
12286 (anything :sources 'anything-c-source-ucs
12287 :keymap anything-c-ucs-map))
12289 ;;;###autoload
12290 (defun anything-c-apropos ()
12291 "Preconfigured anything to describe commands, functions, variables and faces."
12292 (interactive)
12293 (let ((default (thing-at-point 'symbol)))
12294 (anything :sources
12295 `(((name . "Commands")
12296 (init . (lambda ()
12297 (anything-c-apropos-init 'commandp ,default)))
12298 (persistent-action . anything-lisp-completion-persistent-action)
12299 (persistent-help . "Show brief doc in mode-line")
12300 (candidates-in-buffer)
12301 (action . (lambda (candidate)
12302 (describe-function (intern candidate)))))
12303 ((name . "Functions")
12304 (init . (lambda ()
12305 (anything-c-apropos-init #'(lambda (x) (and (fboundp x)
12306 (not (commandp x))))
12307 ,default)))
12308 (persistent-action . anything-lisp-completion-persistent-action)
12309 (persistent-help . "Show brief doc in mode-line")
12310 (candidates-in-buffer)
12311 (action . (lambda (candidate)
12312 (describe-function (intern candidate)))))
12313 ((name . "Variables")
12314 (init . (lambda ()
12315 (anything-c-apropos-init 'boundp ,default)))
12316 (persistent-action . anything-lisp-completion-persistent-action)
12317 (persistent-help . "Show brief doc in mode-line")
12318 (candidates-in-buffer)
12319 (action . (lambda (candidate)
12320 (describe-variable (intern candidate)))))
12321 ((name . "Faces")
12322 (init . (lambda ()
12323 (anything-c-apropos-init 'facep ,default)))
12324 (persistent-action . anything-lisp-completion-persistent-action)
12325 (persistent-help . "Show brief doc in mode-line")
12326 (candidates-in-buffer)
12327 (filtered-candidate-transformer . (lambda (candidates source)
12328 (loop for c in candidates
12329 collect (propertize c 'face (intern c)))))
12330 (action . (lambda (candidate)
12331 (describe-face (intern candidate)))))
12332 ((name . "Anything attributes")
12333 (candidates . (lambda ()
12334 (mapcar 'symbol-name anything-additional-attributes)))
12335 (action . (lambda (candidate)
12336 (with-output-to-temp-buffer "*Help*"
12337 (princ (get (intern candidate) 'anything-attrdoc))))))))))
12340 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12343 (provide 'anything-config)
12345 ;;; Local Variables:
12346 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12347 ;;; End:
12349 ;; How to save (DO NOT REMOVE!!)
12350 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12351 ;;; anything-config.el ends here
12353 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12354 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12355 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12356 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12357 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12358 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12359 ;;; LocalWords: dotimes Thierry online vname
12360 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12361 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12362 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12363 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12364 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12365 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12366 ;;; LocalWords: startpos noselect dont desc