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
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)
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.
50 ;; If this file does not work, upgrade anything.el!
51 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
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 ()
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)
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.
92 ;; Help command for `anything-find-files'.
93 ;; `anything-read-file-name-help'
95 ;; `anything-generic-file-help'
97 ;; `anything-grep-help'
99 ;; `anything-pdfgrep-help'
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'
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'
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'
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'
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'
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'
231 ;; `anything-c-ucs-persistent-forward'
233 ;; `anything-c-ucs-persistent-backward'
235 ;; `anything-c-ucs-persistent-delete'
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.
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'.
268 ;; Preconfigured `anything' for gentoo linux.
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.
280 ;; Preconfigured `anything' for BBDB.
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.
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.
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.
308 ;; Preconfigured `anything' for timers.
309 ;; `anything-list-emacs-process'
310 ;; Preconfigured `anything' for emacs process.
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.
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.
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'.
376 ;; Preconfigured `anything' to do many create actions from STRING.
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.
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.
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'
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'
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'
430 ;; `anything-c-enable-eval-defun-hack'
432 ;; `anything-tramp-verbose'
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'
448 ;; `anything-c-copy-async-prefered-emacs'
449 ;; Default Value: "emacs"
450 ;; `anything-ff-lynx-style-map'
452 ;; `anything-ff-history-max-length'
453 ;; Default Value: 100
454 ;; `anything-ff-smart-completion'
456 ;; `anything-ff-default-kbsize'
457 ;; Default Value: 1024.0
458 ;; `anything-ff-tramp-not-fancy'
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'
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'
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'
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'
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'
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
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
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
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>
707 ;; - Fix documentation, now many functions haven't documentations.
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
))
794 (unless (fboundp 'window-system
)
795 (defun window-system (&optional arg
)
803 (defgroup anything-config nil
804 "Predefined configurations for `anything.el'."
807 (defcustom anything-c-adaptive-history-file
808 "~/.emacs.d/anything-c-adaptive-history"
809 "Path of file where history information is stored."
811 :group
'anything-config
)
813 (defcustom anything-c-adaptive-history-length
50
814 "Maximum number of candidates stored for a source."
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."
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."
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."
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."
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."
846 :group
'anything-config
)
848 (defcustom anything-c-boring-buffer-regexp
852 "*anything" "*ac-mode"
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."
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
869 ;; Boring directories
870 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
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."
881 :group
'anything-config
)
883 (defcustom anything-kill-ring-threshold
10
884 "*Minimum length to be listed by `anything-c-source-kill-ring'."
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."
892 :group
'anything-config
)
894 (defcustom anything-su-or-sudo
"su"
895 "What command to use for root access."
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."
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."
919 :group
'anything-config
)
921 (defcustom anything-allow-skipping-current-buffer t
922 "Show current buffer or not in anything buffer"
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 ...)."
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."
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\"."
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.
959 This default value is very likely to be changed,
960 because it is under discussion."
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."
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."
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'."
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\"\)\) "
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
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
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
1015 (defcustom anything-ff-history-max-length
100
1016 "*Number of elements shown in `anything-find-files' history."
1017 :group
'anything-config
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
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
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
1038 (defcustom anything-ff-exif-data-program
"exiftran"
1039 "*Program used to extract exif data of an image file."
1040 :group
'anything-config
1043 (defcustom anything-ff-exif-data-program-args
"-d"
1044 "*Arguments used for `anything-ff-exif-data-program'."
1045 :group
'anything-config
1048 (defcustom anything-c-grep-use-ioccur-style-keys t
1049 "Use Arrow keys to jump to occurences."
1050 :group
'anything-config
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
1059 (defcustom anything-c-etags-tag-file-name
"TAGS"
1060 "Etags tag file name."
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."
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
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'
1083 :group
'anything-config
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.
1094 ruby make-filelist.rb > /tmp/all.filelist
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\"\)
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
1111 (defcustom anything-c-turn-on-show-completion t
1112 "Display candidate in buffer while moving selection when non--nil."
1113 :group
'anything-config
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
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
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."
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'."
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/>."
1150 :group
'anything-config
)
1152 (defcustom anything-ff-file-compressed-list
'("gz" "bz2" "zip" "7z")
1153 "*Minimal list of compressed files extension."
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."
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."
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."
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."
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]."
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
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':
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
1242 (defvar anything-c-show-completion-overlay nil
)
1244 (defvar anything-c-locate-command
1246 ('gnu
/linux
"locate -i -r %s")
1247 ('berkeley-unix
"locate -i %s")
1248 ('windows-nt
"es -i -r %s")
1250 "A list of arguments for locate program.
1251 The \"-r\" option must be the last option.")
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."
1326 (defface anything-bmkext-info
1327 '((t (:foreground
"green")))
1328 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1331 (defface anything-bmkext-w3m
1332 '((t (:foreground
"yellow")))
1333 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1336 (defface anything-bmkext-gnus
1337 '((t (:foreground
"magenta")))
1338 "*Face used for Gnus bookmarks."
1341 (defface anything-bmkext-man
1342 '((t (:foreground
"Orange4")))
1343 "*Face used for Woman/man bookmarks."
1346 (defface anything-bmkext-no--file
1347 '((t (:foreground
"grey")))
1348 "*Face used for non--file bookmarks."
1351 (defface anything-bmkext-file
1352 '((t (:foreground
"Deepskyblue2")))
1353 "*Face used for non--file bookmarks."
1356 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
1357 "Face for su/sudo bookmarks."
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."
1368 (defface anything-apt-installed
1369 '((t (:foreground
"green")))
1370 "*Face used for apt installed candidates."
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
)
1391 (defun anything-configuration ()
1392 "Customize `anything'."
1394 (customize-group "anything-config"))
1398 ;;; Anything-command-map
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
))
1463 (easy-menu-define nil global-map
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
]
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
])
1476 ["Find buffers" anything-buffers-list t
])
1478 ["Emacs Commands" anything-M-x t
]
1479 ["Externals Commands" anything-c-run-external-command t
])
1481 ["Anything Apropos" anything-c-apropos t
])
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
])
1487 ["Org keywords" anything-org-keywords t
]
1488 ["Org headlines" anything-org-headlines t
])
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
])
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
))
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
))
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
))
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
)
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
)
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
)
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
)
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
)
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
)
1678 "Keymap for `anything-ucs'.")
1682 ;;; Embeded documentation.
1685 (defun anything-c-list-preconfigured-anything ()
1686 "Collect preconfigured anything functions in this file."
1689 for entry in
(cdr (assoc
1690 (file-truename (locate-library "anything-config"))
1692 if
(and (consp entry
)
1693 (eq (car entry
) 'defun
)
1694 (string-match "^Preconfigured.+$"
1695 (setq doc
(or (documentation (setq sym
(cdr entry
)))
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
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
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
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))
1773 ;;; `anything-buffer-list' help
1777 (defun anything-c-buffer-help ()
1778 "Help command for anything buffers."
1780 (let ((anything-help-message "== Anything Buffer ==
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 ==
1807 ;;; Find files help (`anything-find-files')
1811 (defun anything-ff-help ()
1812 "Help command for `anything-find-files'."
1814 (let ((anything-help-message "== Anything Find Files ==
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 ==
1867 ;;; Help for `anything-c-read-file-name'
1871 (defun anything-read-file-name-help ()
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 ==
1886 ;;; Generic file help - Used by locate.
1890 (defun anything-generic-file-help ()
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).
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 ==
1917 (defun anything-grep-help ()
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 ==
1937 (defun anything-pdfgrep-help ()
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 ==
1954 (defun anything-etags-help ()
1955 "The help function for etags."
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 ==
1971 (defun anything-c-ucs-help ()
1972 "Help command for `anything-ucs'."
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 ==
1990 ;;; Mode line strings
1993 (defvar anything-buffer-mode-line-string
1995 "\\<anything-c-buffer-map>\
1996 \\[anything-c-buffer-help]:Help, \
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, \
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, \
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, \
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,\
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,\
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,\
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, \
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
))
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."
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
))
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))
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.
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."
2134 (setq anything-candidate-number-limit nil
)
2135 (anything-set-source-filter
2136 (list (assoc-default 'name
(anything-get-current-source)))))
2139 (defun anything-test-sources ()
2140 "List all anything sources for test.
2141 The output is sexps which are evaluated by \\[eval-last-sexp]."
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
)
2157 anything-compiled-sources
2158 anything-buffer-chars-modified-tick
2159 (anything-samewindow t
)
2160 (enable-recursive-minibuffers t
))
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))
2171 while
(setq pos
(next-single-property-change (point) 'anything-header
))
2173 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
2174 do
(forward-line 1))))
2177 (defun anything-select-source ()
2178 "[OBSOLETE] Select source."
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)
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
)))
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
)))
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
)
2227 ;; fall back to default on XEmacs
2229 (if (string-match regexp file
)
2230 (setq file
(propertize file
'face face
))))
2234 (defsubst anything-c-stringify
(str-or-sym)
2235 "Get string of STR-OR-SYM."
2236 (if (stringp 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
)
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.
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
)
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)
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."
2301 (anything-run-after-quit
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
))
2314 (expand-file-name org-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."
2330 (basename 'file-name-nondirectory
)
2331 (relative 'file-relative-name
)
2333 (t 'file-name-nondirectory
))))
2334 (labels ((ls-R (dir)
2335 (loop with ls
= (directory-files dir t directory-files-no-dot-files-regexp
)
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
)
2344 (unless (and ,match
(not (string-match ,match
(file-name-nondirectory f
))))
2345 (push (funcall fn f
) result
)))))
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)))
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")
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")
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
)
2408 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
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
))
2415 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2416 ;; It is implementation problem of candidates-in-buffer.
2420 (defun anything-c-regexp-persistent-action (pt)
2422 (anything-persistent-highlight-point))
2424 (defun anything-c-regexp-kill-new (input)
2426 (message "Killed: %s" input
))
2430 ;;; Toggle all marks.
2434 (defun anything-mark-all ()
2435 "Mark all visible unmarked candidates in current source."
2437 (with-anything-window
2439 (goto-char (anything-get-previous-header-pos))
2440 (anything-next-line)
2441 (let* ((next-head (anything-get-next-header-pos))
2444 (goto-char next-head
)
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.
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
))))
2468 (defun anything-unmark-all ()
2469 "Unmark all candidates in all sources of current anything session."
2471 (with-anything-window
2472 (let ((len (length anything-marked-candidates
)))
2474 (anything-clear-visible-mark))
2475 (setq anything-marked-candidates nil
)
2476 (anything-mark-current-line)
2477 (message "%s candidates unmarked" len
))))
2480 (defun anything-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"
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))))
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
)
2508 ;; (anything 'anything-c-source-buffers)
2510 (defvar anything-c-source-buffer-not-found
2511 '((name .
"Create buffer")
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
)
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
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
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
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
2555 ;; A remote buffer file not modified and saved on disk.
2556 ((and bfname
(file-remote-p bfname
))
2557 (let ((prefix (propertize
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.
2564 (propertize i
'face
'font-lock-type-face
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
)
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
)
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
)))
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)))
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
))
2625 (save-window-excursion
2626 (anything-c-switch-to-buffer buf
)
2628 (let ((case-fold-search t
))
2629 (goto-char (point-min))
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
))))
2647 (defun anything-buffer-diff-persistent ()
2648 "Toggle diff buffer without quitting anything."
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
)))
2658 (defun anything-buffer-revert-persistent ()
2659 "Revert buffer without quitting anything."
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
)
2669 (anything-force-update candidate
)))
2672 (defun anything-buffer-save-persistent ()
2673 "Save buffer without quitting anything."
2675 (anything-execute-persistent-action 'save-action
'onewindow
))
2678 (defun anything-buffer-run-kill-buffers ()
2679 "Run kill buffer action from `anything-c-source-buffers-list'."
2681 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers
))
2684 (defun anything-buffer-run-grep ()
2685 "Run Grep action from `anything-c-source-buffers-list'."
2687 (anything-c-quit-and-execute-action 'anything-c-grep-buffers
))
2690 (defun anything-buffer-run-zgrep ()
2691 "Run Grep action from `anything-c-source-buffers-list'."
2693 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers
))
2696 (defun anything-buffer-run-query-replace-regexp ()
2697 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2699 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp
))
2702 (defun anything-buffer-run-query-replace ()
2703 "Run Query replace action from `anything-c-source-buffers-list'."
2705 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace
))
2708 (defun anything-buffer-switch-other-window ()
2709 "Run switch to other window action from `anything-c-source-buffers-list'."
2711 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window
))
2714 (defun anything-buffer-switch-other-frame ()
2715 "Run switch to other frame action from `anything-c-source-buffers-list'."
2717 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame
))
2720 (defun anything-buffer-switch-to-elscreen ()
2721 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2723 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen
))
2726 (defun anything-buffer-run-ediff ()
2727 "Run ediff action from `anything-c-source-buffers-list'."
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'."
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)))
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
)))
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
)
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.
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
))
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.
2795 ;; (anything 'anything-c-source-files-in-current-dir+)
2799 ;;; Anything-find-files - The anything files browser.
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
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 (persistent-action . anything-find-files-persistent-action
)
2827 (persistent-help .
"Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2828 (mode-line . anything-ff-mode-line-string
)
2830 (candidate-number-limit .
9999)
2831 (action-transformer . anything-find-files-action-transformer
)
2835 `(("Find File" . anything-c-find-file-or-marked
)
2836 ("Find file in Dired" . anything-c-point-file-in-dired
)
2837 ,(and (locate-library "elscreen")
2838 '("Find file in Elscreen" . anything-elscreen-find-file
))
2839 ,(and (locate-library "popwin")
2840 '("Find file in popup window" . popwin
:find-file
))
2841 ("Checksum File" . anything-ff-checksum
)
2842 ("Complete at point `M-tab'"
2843 . anything-c-insert-file-name-completion-at-point
)
2844 ("Open file externally `C-c C-x, C-u to choose'"
2845 . anything-c-open-file-externally
)
2846 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep
)
2847 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep
)
2848 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell
)
2849 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select
)
2850 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2851 . anything-find-files-eshell-command-on-file
)
2852 ("Find file as root" . anything-find-file-as-root
)
2853 ("Find file in hex dump" . hexl-find-file
)
2854 ("Ediff File `C-='" . anything-find-files-ediff-files
)
2855 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files
)
2856 ("Delete File(s) `M-D'" . anything-delete-marked-files
)
2857 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy
)
2858 ("Copy file(s) Async" . anything-ff-copy-async
)
2859 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename
)
2860 ("Serial rename files" . anything-ff-serial-rename
)
2861 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink
)
2862 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying
)
2863 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink
)
2864 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink
)
2865 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink
)
2866 ("Find file other window `C-o'" . find-file-other-window
)
2867 ("Switch to history `M-p'" . anything-find-files-switch-to-hist
)
2868 ("Find file other frame `C-c C-o'" . find-file-other-frame
)
2869 ("Print File `C-c p'" . anything-ff-print
)
2870 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate
))))))
2871 ;; (anything 'anything-c-source-find-files)
2873 (defun anything-find-files-set-prompt-for-action (action files
)
2874 "Set prompt for action ACTION for FILES."
2875 (let ((len (length files
)))
2876 (format "%s *%s File(s)\n%s to: "
2878 (mapconcat (lambda (f)
2879 (format "- %s\n" f
)) files
""))))
2881 (defun anything-dwim-target-directory ()
2882 "Return value of `default-directory' of buffer in other window.
2883 If there is only one window return the value ot `default-directory'
2884 for current buffer."
2885 (with-anything-current-buffer
2886 (let ((num-windows (length (window-list))))
2887 (if (> num-windows
1)
2888 (save-window-excursion
2891 (car anything-ff-history
)))))
2893 (defun anything-find-files-do-action (action)
2894 "Generic function for creating action from `anything-c-source-find-files'.
2895 ACTION must be an action supported by `anything-dired-action'."
2896 (let* ((ifiles (mapcar 'expand-file-name
; Allow modify '/foo/.' -> '/foo'
2897 (anything-marked-candidates)))
2898 (cand (anything-get-selection)) ; Target
2899 (prompt (anything-find-files-set-prompt-for-action
2900 (capitalize (symbol-name action
)) ifiles
))
2901 (parg anything-current-prefix-arg
)
2902 (dest (anything-c-read-file-name
2904 :preselect
(if anything-ff-transformer-show-only-basename
2905 (anything-c-basename cand
) cand
)
2906 :initial-input
(anything-dwim-target-directory)
2907 :history
(anything-find-files-history :comp-read nil
))))
2908 (anything-dired-action
2909 dest
:files ifiles
:action action
:follow parg
)))
2911 (defun anything-find-files-copy (candidate)
2912 "Copy files from `anything-find-files'."
2913 (anything-find-files-do-action 'copy
))
2915 (defun anything-find-files-rename (candidate)
2916 "Rename files from `anything-find-files'."
2917 (anything-find-files-do-action 'rename
))
2919 (defun anything-find-files-symlink (candidate)
2920 "Symlink files from `anything-find-files'."
2921 (anything-find-files-do-action 'symlink
))
2923 (defun anything-find-files-relsymlink (candidate)
2924 "Relsymlink files from `anything-find-files'."
2925 (anything-find-files-do-action 'relsymlink
))
2927 (defun anything-find-files-hardlink (candidate)
2928 "Hardlink files from `anything-find-files'."
2929 (anything-find-files-do-action 'hardlink
))
2931 (defun anything-find-files-byte-compile (candidate)
2932 "Byte compile elisp files from `anything-find-files'."
2933 (let ((files (anything-marked-candidates))
2934 (parg anything-current-prefix-arg
))
2935 (loop for fname in files
2936 do
(byte-compile-file fname parg
))))
2938 (defun anything-find-files-load-files (candidate)
2939 "Load elisp files from `anything-find-files'."
2940 (let ((files (anything-marked-candidates)))
2941 (loop for fname in files
2944 (defun anything-find-files-ediff-files-1 (candidate &optional merge
)
2945 "Generic function to ediff/merge files in `anything-find-files'."
2946 (let ((bname (anything-c-basename candidate
))
2947 (prompt (if merge
"Ediff Merge `%s' With File: "
2948 "Ediff `%s' With File: "))
2949 (fun (if merge
'ediff-merge-files
'ediff-files
)))
2952 (condition-case quit
2953 (anything-c-read-file-name
2954 (format prompt bname
))
2955 (quit ;; Hit C-g ask user to fallback to locate.
2956 (if (y-or-n-p "Search file for ediff with locate? ")
2957 (anything-c-locate-read-file-name
2958 (format prompt bname
)
2959 ;; Check if -b option is available.
2960 (if (and (eq system-type
'windows-nt
)
2961 (string-match "^es" anything-c-locate-command
))
2963 (concat bname
" -b")))
2964 (error "Error: Ediff Operation aborted")))))))
2966 (defun anything-find-files-ediff-files (candidate)
2967 (anything-find-files-ediff-files-1 candidate
))
2969 (defun anything-find-files-ediff-merge-files (candidate)
2970 (anything-find-files-ediff-files-1 candidate
'merge
))
2972 (defun anything-find-files-grep (candidate)
2973 "Default action to grep files from `anything-find-files'."
2974 (anything-do-grep-1 (anything-marked-candidates)
2975 anything-current-prefix-arg
))
2977 (defun anything-ff-zgrep (candidate)
2978 "Default action to zgrep files from `anything-find-files'."
2979 (let ((prefarg anything-current-prefix-arg
)
2980 (ls (anything-marked-candidates)))
2981 (anything-ff-zgrep-1 ls prefarg
)))
2983 (defun anything-ff-pdfgrep (candidate)
2984 "Default action to pdfgrep files from `anything-find-files'."
2985 (let ((cands (loop for file in
(anything-marked-candidates)
2986 if
(or (string= (file-name-extension file
) "pdf")
2987 (string= (file-name-extension file
) "PDF"))
2989 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init
))
2991 (anything-do-pdfgrep-1 cands
))))
2993 (defun anything-ff-etags-select (candidate)
2994 "Default action to jump to etags from `anything-find-files'."
2995 (when (get-buffer anything-action-buffer
)
2996 (kill-buffer anything-action-buffer
))
2997 (let ((default-directory anything-ff-default-directory
))
2998 (anything-c-etags-select anything-current-prefix-arg
)))
3000 (defun anything-find-files-switch-to-hist (candidate)
3001 "Switch to anything-find-files history."
3002 (anything-find-files t
))
3004 ;;; Asynchronous copy of files.
3007 (defun anything-c-copy-files-async-1 (flist dest
)
3008 "Copy a list of Files FLIST to DEST asynchronously.
3009 It use another emacs process to do the job.
3010 Communication with background emacs is done with temp file
3011 `anything-c-copy-files-async-log-file'."
3012 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3013 "-Q" "--batch" "--eval"
3015 (require 'dired) (require 'cl)
3016 (let ((dired-recursive-copies 'always)
3022 (let ((file-exists (file-exists-p
3024 (file-name-nondirectory (directory-file-name f))
3025 (file-name-directory
3026 (file-name-as-directory \"%s\"))))))
3027 (dired-copy-file f \"%s\" t)
3029 (progn (push (cons \"Overwriting\" f) success)
3031 (push (cons \"Copying\" f) success)
3034 (push (dired-make-relative
3036 (file-name-nondirectory (directory-file-name f))
3037 (file-name-directory \"%s\")))
3039 (with-current-buffer (find-file-noselect \"%s\")
3042 (dolist (fail (reverse failures))
3043 (insert (concat \"Failed to copy \" fail \"\n\"))))
3045 (loop for (a . s) in (reverse success) do
3046 (insert (concat a \" \" s \" to %s done\n\"))))
3047 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3048 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3049 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3051 flist dest dest dest anything-c-copy-files-async-log-file dest
)))
3053 (defun anything-c-copy-async-with-log (flist dest
)
3054 "Copy file list FLIST to DEST showing log.
3055 Log is send to `anything-c-copy-files-async-log-file'.
3056 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3057 (declare (special auto-revert-interval
))
3058 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file
))
3059 (set (make-local-variable 'auto-revert-interval
) 1)
3061 (insert "Wait copying files...\n")
3062 (sit-for 0.5) (save-buffer)
3063 (goto-char (point-max))
3064 (auto-revert-mode 1)
3065 (anything-c-copy-files-async-1 flist dest
))
3067 (defun anything-ff-copy-async (candidate)
3068 "Anything find files action to copy files async.
3069 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3070 (let* ((flist (anything-marked-candidates))
3071 (dest (anything-c-read-file-name
3072 (anything-find-files-set-prompt-for-action
3074 :preselect candidate
3075 :initial-input
(car anything-ff-history
)
3076 :history
(anything-find-files-history :comp-read nil
))))
3077 (anything-c-copy-async-with-log flist dest
)))
3079 (defvar eshell-command-aliases-list nil
)
3080 (defvar anything-eshell-command-on-file-input-history nil
)
3081 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map
)
3082 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3084 Basename of CANDIDATE can be a wild-card.
3085 If MAP is given run `eshell-command' on all marked files at once,
3086 Otherwise, run `eshell-command' on each marked files.
3088 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3089 `eshell-command-aliases-list' will not be loaded first time you use this."
3090 (when (or eshell-command-aliases-list
3091 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3092 (and eshell-command-aliases-list
(eshell-read-aliases-list))
3093 (let* ((cand-list (anything-marked-candidates))
3094 (default-directory (or anything-ff-default-directory
3095 ;; If candidate is an url *-ff-default-directory is nil
3096 ;; so keep value of default-directory.
3098 (command (anything-comp-read
3100 (loop for
(a . c
) in eshell-command-aliases-list
3101 when
(string-match "\\(\\$1\\|\\$\\*\\)$" (car c
))
3102 collect
(propertize a
'help-echo
(car c
)) into ls
3103 finally return
(sort ls
'string
<))
3104 :buffer
"*esh command on file*"
3105 :name
"Eshell command"
3107 'anything-eshell-command-on-file-input-history
))
3108 (com-value (car (assoc-default command eshell-command-aliases-list
))))
3109 (if (and (or map
(and com-value
(string-match "\\$\\*$" com-value
)))
3110 (> (length cand-list
) 1))
3111 ;; Run eshell-command with ALL marked files as arguments.
3112 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list
" ")))
3113 (eshell-command (format "%s %s" command mapfiles
)))
3114 ;; Run eshell-command on EACH marked files.
3117 for bn
= (anything-c-basename i
)
3118 for files
= (if (and bn
(string-match "^\*" bn
))
3119 ;; Assume if fname is a wildcard
3120 ;; cand-list have a length of 1.
3122 'shell-quote-argument
3123 (file-expand-wildcards i t
) " ")
3125 for com
= (if (string-match "'%s'\\|\"%s\"\\|%s" command
)
3126 ;; This allow to enter other args AFTER filename
3127 ;; i.e <command %s some_more_args>
3128 (format command files
)
3129 (format "%s %s" command files
))
3130 do
(eshell-command com
))))))
3132 (defun anything-find-files-eshell-command-on-file (candidate)
3133 "Run `eshell-command' on CANDIDATE or marked candidates.
3134 See `anything-find-files-eshell-command-on-file-1' for more info."
3135 (anything-find-files-eshell-command-on-file-1
3136 candidate anything-current-prefix-arg
))
3138 (defun anything-ff-switch-to-eshell (candidate)
3139 "Switch to eshell and cd to `anything-ff-default-directory'."
3140 (flet ((cd-eshell ()
3141 (goto-char (point-max))
3143 (format "cd '%s'" anything-ff-default-directory
))
3144 (eshell-send-input)))
3145 (if (get-buffer "*eshell*")
3147 (anything-c-switch-to-buffer "*eshell*")
3149 (call-interactively 'eshell
)
3152 (defun anything-ff-serial-rename-action (method)
3153 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3154 See `anything-ff-serial-rename-1'."
3155 (let* ((cands (anything-marked-candidates))
3156 (name (read-string "NewName: "))
3157 (start (read-number "StartAtNumber: "))
3158 (extension (read-string "Extension: " (file-name-extension (car cands
))))
3159 (dir (expand-file-name
3160 (anything-c-read-file-name
3161 "Serial Rename to directory: " :initial-input
3162 (expand-file-name anything-ff-default-directory
)))))
3163 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3164 (length cands
) dir name
))
3165 (anything-ff-serial-rename-1 dir cands name start extension
:method method
)
3166 (anything-find-files-1 dir
))))
3168 (defun anything-ff-member-directory-p (file directory
)
3169 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file
))))
3170 (cur-dir (expand-file-name (file-name-as-directory directory
))))
3171 (string= dir-file cur-dir
)))
3173 (defun* anything-ff-serial-rename-1
3174 (directory collection new-name start-at-num extension
&key
(method 'rename
))
3175 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3176 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3177 EXTENSION is the file extension to use, in empty prompt,
3178 reuse the original extension of file.
3179 METHOD can be one of rename, copy or symlink.
3180 Files will be renamed if they are files of current directory, otherwise they
3181 will be treated with METHOD.
3182 Default METHOD is rename."
3183 ;; Maybe remove directories selected by error in collection.
3184 (setq collection
(remove-if 'file-directory-p collection
))
3185 (flet ((symlink-file (file dest
)
3186 (let ((flist (list file
)))
3187 (anything-dired-action
3188 dest
:action
'symlink
:files flist
))))
3190 (let* ((tmp-dir (file-name-as-directory
3191 (concat (file-name-as-directory directory
)
3192 (symbol-name (gensym "tmp")))))
3195 (symlink 'symlink-file
)
3196 (rename 'rename-file
)
3197 (t (error "Error: Unknow method %s" method
)))))
3198 (make-directory tmp-dir
)
3199 (loop for i in collection
3200 for count from start-at-num
3201 for fnum
= (if (< count
10) "0%s" "%s")
3202 for nname
= (concat tmp-dir new-name
(format fnum count
)
3203 (if (not (string= extension
""))
3204 (format ".%s" (replace-regexp-in-string
3205 "[.]" "" extension
))
3206 (file-name-extension i
'dot
)))
3207 do
(if (anything-ff-member-directory-p i directory
)
3208 (rename-file i nname
)
3209 (funcall fn i nname
)))
3210 (loop with dirlist
= (directory-files
3211 tmp-dir t directory-files-no-dot-files-regexp
)
3213 (if (file-symlink-p f
)
3214 (symlink-file (file-truename f
)
3215 (concat (file-name-as-directory directory
)
3216 (anything-c-basename f
)))
3217 (rename-file f directory
)))
3218 (delete-directory tmp-dir t
))))
3220 (defun anything-ff-serial-rename (candidate)
3221 "Serial rename all marked files to `anything-ff-default-directory'.
3222 Rename only file of current directory, and symlink files coming from
3224 See `anything-ff-serial-rename-1'."
3225 (anything-ff-serial-rename-action 'rename
))
3227 (defun anything-ff-serial-rename-by-symlink (candidate)
3228 "Serial rename all marked files to `anything-ff-default-directory'.
3229 Rename only file of current directory, and symlink files coming from
3231 See `anything-ff-serial-rename-1'."
3232 (anything-ff-serial-rename-action 'symlink
))
3234 (defun anything-ff-serial-rename-by-copying (candidate)
3235 "Serial rename all marked files to `anything-ff-default-directory'.
3236 Rename only file of current directory, and copy files coming from
3238 See `anything-ff-serial-rename-1'."
3239 (anything-ff-serial-rename-action 'copy
))
3241 (defun anything-c-quit-and-execute-action (action)
3242 "Quit current anything session and execute ACTION."
3243 (setq anything-saved-action action
)
3244 (anything-exit-minibuffer))
3246 (defun anything-ff-toggle-auto-update (candidate)
3247 (setq anything-ff-auto-update-flag
(not anything-ff-auto-update-flag
))
3248 (message "[Auto expansion %s]"
3249 (if anything-ff-auto-update-flag
"enabled" "disabled")))
3252 (defun anything-ff-run-toggle-auto-update ()
3254 (anything-attrset 'toggle-auto-update
'anything-ff-toggle-auto-update
)
3255 (anything-execute-persistent-action 'toggle-auto-update
))
3258 (defun anything-ff-run-switch-to-history ()
3259 "Run Switch to history action from `anything-c-source-find-files'."
3261 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist
))
3264 (defun anything-ff-run-grep ()
3265 "Run Grep action from `anything-c-source-find-files'."
3267 (anything-c-quit-and-execute-action 'anything-find-files-grep
))
3270 (defun anything-ff-run-pdfgrep ()
3271 "Run Pdfgrep action from `anything-c-source-find-files'."
3273 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep
))
3276 (defun anything-ff-run-zgrep ()
3277 "Run Grep action from `anything-c-source-find-files'."
3279 (anything-c-quit-and-execute-action 'anything-ff-zgrep
))
3282 (defun anything-ff-run-copy-file ()
3283 "Run Copy file action from `anything-c-source-find-files'."
3285 (anything-c-quit-and-execute-action 'anything-find-files-copy
))
3288 (defun anything-ff-run-rename-file ()
3289 "Run Rename file action from `anything-c-source-find-files'."
3291 (anything-c-quit-and-execute-action 'anything-find-files-rename
))
3294 (defun anything-ff-run-byte-compile-file ()
3295 "Run Byte compile file action from `anything-c-source-find-files'."
3297 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile
))
3300 (defun anything-ff-run-load-file ()
3301 "Run Load file action from `anything-c-source-find-files'."
3303 (anything-c-quit-and-execute-action 'anything-find-files-load-files
))
3306 (defun anything-ff-run-eshell-command-on-file ()
3307 "Run eshell command on file action from `anything-c-source-find-files'."
3309 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file
))
3312 (defun anything-ff-run-ediff-file ()
3313 "Run Ediff file action from `anything-c-source-find-files'."
3315 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files
))
3318 (defun anything-ff-run-ediff-merge-file ()
3319 "Run Ediff merge file action from `anything-c-source-find-files'."
3321 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files
))
3324 (defun anything-ff-run-symlink-file ()
3325 "Run Symlink file action from `anything-c-source-find-files'."
3327 (anything-c-quit-and-execute-action 'anything-find-files-symlink
))
3330 (defun anything-ff-run-delete-file ()
3331 "Run Delete file action from `anything-c-source-find-files'."
3333 (anything-c-quit-and-execute-action 'anything-delete-marked-files
))
3336 (defun anything-ff-run-complete-fn-at-point ()
3337 "Run complete file name action from `anything-c-source-find-files'."
3339 (anything-c-quit-and-execute-action
3340 'anything-c-insert-file-name-completion-at-point
))
3343 (defun anything-ff-run-switch-to-eshell ()
3344 "Run switch to eshell action from `anything-c-source-find-files'."
3346 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell
))
3349 (defun anything-ff-run-switch-other-window ()
3350 "Run switch to other window action from `anything-c-source-find-files'."
3352 (anything-c-quit-and-execute-action 'find-file-other-window
))
3355 (defun anything-ff-run-switch-other-frame ()
3356 "Run switch to other frame action from `anything-c-source-find-files'."
3358 (anything-c-quit-and-execute-action 'find-file-other-frame
))
3361 (defun anything-ff-run-open-file-externally ()
3362 "Run open file externally command action from `anything-c-source-find-files'."
3364 (anything-c-quit-and-execute-action 'anything-c-open-file-externally
))
3366 (defun anything-ff-locate (candidate)
3367 "Locate action function for `anything-find-files'."
3368 (let ((input (concat (anything-c-basename
3371 anything-ff-default-directory
))
3372 ;; The locate '-b' option doesn't exists
3374 (unless (and (eq system-type
'windows-nt
)
3375 (string-match "^es" anything-c-locate-command
))
3377 (anything-mp-highlight-delay 0.7))
3378 (anything-locate-1 anything-current-prefix-arg input
)))
3381 (defun anything-ff-run-locate ()
3382 "Run locate action from `anything-c-source-find-files'."
3384 (anything-c-quit-and-execute-action 'anything-ff-locate
))
3387 (defun anything-ff-run-gnus-attach-files ()
3388 "Run gnus attach files command action from `anything-c-source-find-files'."
3390 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files
))
3393 (defun anything-ff-run-etags ()
3394 "Run Etags command action from `anything-c-source-find-files'."
3396 (anything-c-quit-and-execute-action 'anything-ff-etags-select
))
3399 (defun anything-ff-print (candidate)
3400 "Print marked files.
3401 You have to set in order
3402 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3405 \(setq lpr-command \"gtklp\"\)
3406 \(setq lpr-switches '(\"-P\")\)
3407 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3409 Same as `dired-do-print' but for anything."
3410 (let* ((file-list (anything-marked-candidates))
3411 (len (length file-list
))
3412 (printer-name (if anything-ff-printer-list
3414 "Printer: " anything-ff-printer-list
)
3416 (command (read-string
3417 (format "Print *%s File(s):\n%s with: "
3420 (lambda (f) (format "- %s\n" f
))
3422 (when (and lpr-command
3425 (mapconcat 'identity
3427 (append (if (stringp lpr-switches
)
3430 (list printer-name
)))
3432 (file-args (mapconcat #'(lambda (x)
3435 (cmd-line (concat command
" " file-args
)))
3437 (start-process-shell-command "anything-print" nil cmd-line
)
3438 (error "Error: Please verify your printer settings in Emacs."))))
3441 (defun anything-ff-run-print-file ()
3442 "Run Print file action from `anything-c-source-find-files'."
3444 (anything-c-quit-and-execute-action 'anything-ff-print
))
3446 (defun anything-ff-checksum (file)
3447 "Calculate the checksum of FILE.
3448 Provide completion on different algorithms to use on Emacs24.
3449 On Emacs23 only 'sha1' is available.
3450 The checksum is copied to kill-ring."
3451 (let ((algo-list (and (fboundp 'secure-hash
)
3452 '(md5 sha1 sha224 sha256 sha384 sha512
))))
3455 (secure-hash (intern
3457 "Algorithm: " algo-list
))
3459 (sha1 (with-temp-buffer
3460 (insert-file-contents file
)
3462 (message "Checksum copied to kill-ring.")))
3464 (defun anything-ff-toggle-basename (candidate)
3465 (setq anything-ff-transformer-show-only-basename
3466 (not anything-ff-transformer-show-only-basename
))
3467 (let ((target (if anything-ff-transformer-show-only-basename
3468 (anything-c-basename candidate
) candidate
)))
3469 (anything-force-update target
)))
3471 (defun anything-ff-run-toggle-basename ()
3473 (anything-attrset 'toggle-basename
'anything-ff-toggle-basename
)
3474 (anything-execute-persistent-action 'toggle-basename
))
3476 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
3477 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3478 If LEVEL is positive reduce from end else from beginning.
3479 If UNIX-CLOSE is non--nil close filename with /.
3480 If EXPAND is non--nil expand-file-name."
3481 (let* ((exp-fname (expand-file-name fname
))
3482 (fname-list (split-string (if (or (string= fname
"~/") expand
)
3483 exp-fname fname
) "/" t
))
3484 (len (length fname-list
))
3485 (pop-list (if (< level
0)
3486 (subseq fname-list
(* level -
1))
3487 (subseq fname-list
0 (- len level
))))
3488 (result (mapconcat 'identity pop-list
"/"))
3489 (empty (string= result
"")))
3490 (when unix-close
(setq result
(concat result
"/")))
3491 (if (string-match "^~" result
)
3492 (if (string= result
"~/") "~/" result
)
3494 (if empty
"../" (concat "../" result
))
3495 (cond ((eq system-type
'windows-nt
)
3496 (if empty
"c:/" result
))
3499 (concat "/" result
)))))))
3502 (defvar anything-file-completion-sources
3503 '("Find Files" "Read File Name"
3504 "Read File Name History" "Copy Files"
3505 "Rename Files" "Symlink Files"
3506 "Hardlink Files" "Write File" "Insert File")
3507 "Sources that use the *find-files mechanism can be added here.
3508 You should not modify this yourself and know what you do if you do so.")
3510 (defun anything-file-completion-source-p ()
3511 "Test if current source is a dired or find-files source."
3512 (let ((cur-source (cdr (assoc 'name
(anything-get-current-source)))))
3513 (loop for i in anything-file-completion-sources
3514 thereis
(string= cur-source i
))))
3516 (defun anything-find-files-down-one-level (arg)
3517 "Go down one level like unix command `cd ..'.
3518 If prefix numeric arg is given go ARG level down."
3520 (when (and (anything-file-completion-source-p)
3521 (not (anything-ff-invalid-tramp-name-p)))
3522 (with-anything-window
3523 (setq anything-follow-mode nil
))
3524 ;; When going to precedent level we want to be at the line
3525 ;; corresponding to actual directory, so store this info
3526 ;; in `anything-ff-last-expanded'.
3527 (if (and (not (file-directory-p anything-pattern
))
3528 (file-exists-p anything-pattern
))
3529 (setq anything-ff-last-expanded anything-pattern
)
3530 (setq anything-ff-last-expanded anything-ff-default-directory
))
3531 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3532 :unix-close t
:expand t
)))
3533 (anything-set-pattern new-pattern
))))
3535 (defun anything-ff-retrieve-last-expanded ()
3536 "Move overlay to last visited directory `anything-ff-last-expanded'.
3537 This happen after using `anything-find-files-down-one-level',
3538 or hitting C-z on \"..\"."
3539 (when (and anything-ff-last-expanded
3540 (anything-file-completion-source-p))
3541 (let ((dirname (if anything-ff-transformer-show-only-basename
3542 (anything-c-basename
3543 (directory-file-name anything-ff-last-expanded
))
3544 (directory-file-name anything-ff-last-expanded
))))
3545 (with-anything-window
3546 (when (or (re-search-forward (concat dirname
"$") nil t
)
3548 (concat anything-ff-last-expanded
"$") nil t
))
3550 (anything-mark-current-line)))
3551 (setq anything-ff-last-expanded nil
))))
3552 (add-hook 'anything-after-update-hook
'anything-ff-retrieve-last-expanded
)
3554 ;; Auto-update - anything-find-files auto expansion of directories.
3556 (defun anything-ff-update-when-only-one-matched ()
3557 "Expand to directory when sole completion.
3558 When only one candidate is remaining and it is a directory,
3559 expand to this directory."
3560 (when (and anything-ff-auto-update-flag
3561 (anything-file-completion-source-p)
3562 (not (anything-ff-invalid-tramp-name-p)))
3563 (let* ((history-p (string= (assoc-default
3564 'name
(anything-get-current-source))
3565 "Read File Name History"))
3566 (pat (if (string-match tramp-file-name-regexp
3568 (anything-create-tramp-name anything-pattern
)
3570 (completed-p (string= (file-name-as-directory pat
)
3571 anything-ff-default-directory
)))
3573 ;; Only one candidate remaining
3574 ;; and at least 2 char in basename.
3575 (and (<= (anything-approximate-candidate-number) 2)
3576 (>= (length (anything-c-basename anything-pattern
)) 2))
3577 ;; Already completed.
3579 (not history-p
)) ; Don't try to auto complete in history.
3580 (with-anything-window
3581 (let ((cur-cand (prog2
3583 ;; Only one non--existing candidate
3584 ;; and one directory candidate, move to it.
3585 (anything-next-line))
3586 (anything-get-selection))))
3587 (when (file-directory-p cur-cand
)
3588 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand
)) ; [1]
3589 ;; Maybe we are here because completed-p is true
3590 ;; but check this again to be sure. (Windows fix)
3591 (<= (anything-approximate-candidate-number) 2)) ; [2]
3592 ;; If after going to next line the candidate
3593 ;; is not one of "." or ".." [1]
3594 ;; and only one candidate is remaining [2],
3595 ;; assume candidate is a new directory to expand, and do it.
3596 (anything-set-pattern (file-name-as-directory cur-cand
))
3597 ;; The candidate is one of "." or ".."
3598 ;; that mean we have entered the last letter of the directory name
3599 ;; in prompt, so expansion is already done, just add the "/" at end
3600 ;; of name unless anything-pattern ends with "."
3601 ;; (i.e we are writing something starting with ".")
3602 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern
)
3603 (anything-set-pattern
3604 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3605 (expand-file-name (file-name-as-directory anything-pattern
)))))
3606 (anything-check-minibuffer-input-1))))))))
3607 (add-hook 'anything-after-update-hook
'anything-ff-update-when-only-one-matched
)
3609 ;; Allow expanding to home directory or root
3610 ;; when entering respectively "~/" or "//" at end of pattern.
3611 ;; e.g /home/thierry/labo/anything-config-qp/~/
3612 ;; will expand to "~/"
3613 ;; and /home/thierry/labo/anything-config-qp//
3614 ;; will expand to "/"
3615 (defun anything-ff-auto-expand-to-home-or-root ()
3616 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3617 This happen only in function using sources that are
3618 `anything-file-completion-source-p' compliant."
3619 (when (and (anything-file-completion-source-p)
3620 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3622 (let ((match (match-string 1 anything-pattern
)))
3623 (cond ((string= match
"//")
3624 (if (eq system-type
'windows-nt
)
3625 (setq anything-pattern
"c:/")
3626 (setq anything-pattern
"/")))
3627 ((string= match
"/~/")
3628 (if (eq system-type
'windows-nt
)
3629 (setq anything-pattern
(file-name-as-directory (getenv "HOME")))
3630 (setq anything-pattern
"~/")))
3631 ((string= match
"/./")
3632 (setq anything-pattern
3633 (with-anything-current-buffer
3634 (expand-file-name default-directory
))))))
3635 (setq anything-ff-default-directory anything-pattern
)
3636 ;; For some reasons, i must use here with-current-buffer => mini buffer
3637 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3638 (with-current-buffer (window-buffer (minibuffer-window))
3639 (delete-minibuffer-contents)
3640 (insert anything-pattern
))))
3642 (add-hook 'anything-after-update-hook
'anything-ff-auto-expand-to-home-or-root
)
3644 (defun anything-c-point-file-in-dired (file)
3645 "Put point on filename FILE in dired buffer."
3646 (dired (file-name-directory file
))
3647 (dired-goto-file file
))
3649 (defun anything-create-tramp-name (fname)
3650 "Build filename for `anything-pattern' like /su:: or /sudo::."
3651 (apply #'tramp-make-tramp-file-name
3652 (loop with v
= (tramp-dissect-file-name fname
)
3653 for i across v collect i
)))
3655 (defun* anything-ff-tramp-hostnames
(&optional
(pattern anything-pattern
))
3656 "Get a list of hosts for tramp method found in `anything-pattern'.
3657 Argument PATTERN default to `anything-pattern', it is here only for debugging
3659 (when (string-match tramp-file-name-regexp pattern
)
3660 (let ((method (match-string 1 pattern
))
3661 (tn (match-string 0 pattern
))
3662 (all-methods (mapcar 'car tramp-methods
)))
3664 (loop for
(f . h
) in
(tramp-get-completion-function method
)
3665 append
(loop for e in
(funcall f
(car h
))
3666 for host
= (and (consp e
) (cadr e
))
3667 when
(and host
(not (member host all-methods
)))
3668 collect
(concat tn host
)))
3671 (defun anything-ff-before-action-hook-fn ()
3672 "Exit anything when user try to execute action on an invalid tramp fname."
3673 (let ((cand (anything-get-selection)))
3674 (when (and (anything-file-completion-source-p)
3675 (anything-ff-invalid-tramp-name-p cand
) ; Check candidate.
3676 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3677 (error "Error: Unknow file or directory `%s'" cand
))))
3678 (add-hook 'anything-before-action-hook
'anything-ff-before-action-hook-fn
)
3680 (defun* anything-ff-invalid-tramp-name-p
(&optional
(pattern anything-pattern
))
3681 "Return non--nil when PATTERN is an invalid tramp filename."
3682 (string= (anything-ff-set-pattern pattern
)
3683 "Invalid tramp file name"))
3685 (defun anything-ff-set-pattern (pattern)
3686 "Handle tramp filenames in `anything-pattern'."
3687 (let ((methods (mapcar 'car tramp-methods
))
3688 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3689 cur-method tramp-name
)
3690 (cond ((string= pattern
"") "")
3691 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern
)
3692 (with-anything-current-buffer
3693 (expand-file-name default-directory
)))
3694 ((string-match ".*\\(~//\\|//\\)$" pattern
)
3695 (if (eq system-type
'windows-nt
) "c:/" "/"))
3696 ((string-match "^~\\|.*/~/$" pattern
)
3697 (let* ((home (expand-file-name (getenv "HOME"))))
3698 (replace-match home nil t pattern
)))
3699 ;; Match "/method:maybe_hostname:"
3700 ((and (string-match reg pattern
)
3701 (setq cur-method
(match-string 1 pattern
))
3702 (member cur-method methods
))
3703 (setq tramp-name
(anything-create-tramp-name
3704 (match-string 0 pattern
)))
3705 (replace-match tramp-name nil t pattern
))
3706 ;; Match "/hostname:"
3707 ((and (string-match tramp-file-name-regexp pattern
)
3708 (setq cur-method
(match-string 1 pattern
))
3709 (and cur-method
(not (member cur-method methods
))))
3710 (setq tramp-name
(anything-create-tramp-name
3711 (match-string 0 pattern
)))
3712 (replace-match tramp-name nil t pattern
))
3713 ;; Match "/method:" in this case don't try to connect.
3714 ((and (not (string-match reg pattern
))
3715 (string-match tramp-file-name-regexp pattern
)
3716 (member (match-string 1 pattern
) methods
))
3717 "Invalid tramp file name") ; Write in anything-buffer.
3718 ;; PATTERN is a directory, end it with "/".
3719 ;; This will make PATTERN not ending yet with "/"
3720 ;; candidate for `anything-ff-default-directory',
3721 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3722 ;; when descending level.
3723 ((file-directory-p pattern
)
3724 (file-name-as-directory pattern
))
3725 ;; Return PATTERN unchanged.
3728 (defun anything-find-files-get-candidates ()
3729 "Create candidate list for `anything-c-source-find-files'."
3730 (let* ((path (anything-ff-set-pattern anything-pattern
))
3731 (path-name-dir (if (file-directory-p path
)
3732 (file-name-as-directory path
)
3733 (file-name-directory path
)))
3734 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
3735 (set-text-properties 0 (length path
) nil path
)
3736 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3737 ;; like that the actual value (e.g /ssh:) is passed to
3738 ;; `anything-ff-tramp-hostnames'.
3739 (unless (string= path
"Invalid tramp file name")
3740 (setq anything-pattern
(anything-ff-transform-fname-for-completion path
)))
3741 (setq anything-ff-default-directory
3742 (if (string= anything-pattern
"")
3743 (if (eq system-type
'windows-nt
) "c:/" "/")
3744 (unless (string-match ffap-url-regexp path
)
3745 ;; If path is an url *default-directory have to be nil.
3747 (cond ((string= path
"Invalid tramp file name")
3748 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3750 ;; `anything-pattern' have not been modified yet.
3751 ;; Set it here to the value of `path' that should be now
3752 ;; "Invalid tramp file name" and set the candidates list
3753 ;; to ("Invalid tramp file name") to make `anything-pattern'
3754 ;; match single candidate "Invalid tramp file name".
3755 (setq anything-pattern path
)
3756 ;; "Invalid tramp file name" is now printed
3757 ;; in `anything-buffer'.
3759 ((or (file-regular-p path
)
3760 (and (not (file-exists-p path
)) (string-match "/$" path
))
3761 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
3763 ((string= path
"") (directory-files "/" t
))
3764 ((and (file-directory-p path
) (not (file-readable-p path
)))
3765 (list (format "Opening directory: access denied, `%s'" path
)))
3766 ((file-directory-p path
) (directory-files path t
))
3768 (append (list path
) (directory-files path-name-dir t
))))))
3770 (defun anything-ff-transform-fname-for-completion (fname)
3771 "Return FNAME with it's basename modified as a regexp.
3772 e.g foo => f.*o.*o .
3773 If basename contain one or more space or FNAME is a valid directory name
3774 return FNAME unchanged."
3775 (let ((bn (anything-c-basename fname
)))
3776 (if (or (not anything-ff-smart-completion
)
3777 (string-match "\\s-" bn
)
3778 (string-match "/$" fname
) ; Allow mkdir.
3779 (file-directory-p fname
))
3780 fname
; Fall back to match-plugin.
3781 (setq bn
(if (> (length bn
) 2) ; Normal completion on first 2 char.
3782 (mapconcat 'identity
(split-string bn
"" t
) ".*") bn
))
3783 (concat (file-name-directory fname
) bn
))))
3785 (defun anything-ff-save-history ()
3786 "Store the last value of `anything-ff-default-directory' \
3787 in `anything-ff-history'."
3788 (when (and anything-ff-default-directory
3789 (anything-file-completion-source-p))
3790 (push anything-ff-default-directory anything-ff-history
)))
3791 (add-hook 'anything-cleanup-hook
'anything-ff-save-history
)
3793 (defun anything-ff-valid-symlink-p (file)
3794 (file-exists-p (file-truename file
)))
3796 (defun anything-ff-properties (candidate)
3797 "Show file properties of CANDIDATE in a tooltip or message."
3798 (let ((type (anything-ff-attributes candidate
:type t
))
3799 (dired-line (anything-ff-attributes candidate
:dired t
:human-size t
)))
3803 (anything-c-basename candidate
) ": \n"
3805 (when (string= type
"symlink")
3806 (format "True name: '%s'\n"
3807 (cond ((string-match "^\.#" (anything-c-basename candidate
))
3809 ((anything-ff-valid-symlink-p candidate
)
3810 (file-truename candidate
))
3811 (t "Invalid Symlink"))))
3813 (message dired-line
) (sit-for 5))))
3816 (defun anything-ff-properties-persistent ()
3817 "Show properties without quitting anything."
3819 (anything-attrset 'properties-action
'anything-ff-properties
)
3820 (anything-execute-persistent-action 'properties-action
))
3823 (defun anything-ff-persistent-delete ()
3824 "Delete current candidate without quitting."
3826 (anything-attrset 'quick-delete
'anything-ff-quick-delete
)
3827 (anything-execute-persistent-action 'quick-delete
))
3829 (defun anything-ff-quick-delete (candidate)
3830 "Delete file CANDIDATE without quitting."
3831 (let ((presel (prog1 (save-excursion
3833 (anything-next-line)
3834 (setq sel
(anything-get-selection))
3835 (if (string= sel candidate
)
3836 (progn (anything-previous-line)
3837 (anything-get-selection))
3839 (anything-mark-current-line))))
3840 (setq presel
(if (and anything-ff-transformer-show-only-basename
3841 (not (string-match-p "[.]\\{1,2\\}$" presel
)))
3842 (anything-c-basename presel
) presel
))
3843 (if anything-ff-quick-delete-dont-prompt-for-deletion
3844 (anything-c-delete-file candidate
)
3845 (save-window-excursion
3846 (when (y-or-n-p (format "Really Delete file `%s'? " candidate
))
3847 (anything-c-delete-file candidate
))))
3848 (anything-force-update presel
)))
3850 (defun anything-ff-kill-buffer-fname (candidate)
3851 (let* ((buf (get-file-buffer candidate
))
3852 (buf-name (buffer-name buf
)))
3855 (kill-buffer buf
) (message "Buffer `%s' killed" buf
))
3856 (message "No buffer to kill"))))
3858 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3859 "Find file CANDIDATE or kill it's buffer if it is visible.
3860 Never kill `anything-current-buffer'.
3861 Never kill buffer modified.
3862 This is called normally on third hit of \
3863 \\<anything-map>\\[anything-execute-persistent-action]
3864 in `anything-find-files-persistent-action'."
3865 (let* ((buf (get-file-buffer candidate
))
3866 (buf-name (buffer-name buf
)))
3867 (if (and buf
(get-buffer-window buf
)
3868 (not (eq buf
(get-buffer anything-current-buffer
)))
3869 (not (buffer-modified-p buf
)))
3871 (kill-buffer buf
) (message "Buffer `%s' killed" buf-name
))
3872 (find-file candidate
))))
3875 (defun anything-ff-run-kill-buffer-persistent ()
3876 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3878 (anything-attrset 'kill-buffer-fname
'anything-ff-kill-buffer-fname
)
3879 (anything-execute-persistent-action 'kill-buffer-fname
))
3881 (defun anything-ff-human-size (size)
3882 "Return a string showing SIZE of a file in human readable form.
3883 SIZE can be an integer or a float depending it's value.
3884 `file-attributes' will take care of that to avoid overflow error.
3885 KBSIZE if a floating point number, default value is 1024.0."
3886 (let ((M (cons "M" (/ size
(expt anything-ff-default-kbsize
2))))
3887 (G (cons "G" (/ size
(expt anything-ff-default-kbsize
3))))
3888 (K (cons "K" (/ size anything-ff-default-kbsize
)))
3889 (B (cons "B" size
)))
3890 (loop with result
= B
3892 (loop for
(x . y
) in
(list M G K B
)
3893 unless
(< y
1) collect
(cons x y
))
3894 when
(< b
(cdr result
)) do
(setq result
(cons a b
))
3895 finally return
(if (string= (car result
) "B")
3897 (format "%.1f%s" (cdr result
) (car result
))))))
3899 (defun* anything-ff-attributes
3900 (file &key type links uid gid access-time modif-time
3901 status size mode gid-change inode device-num dired human-size
)
3902 "Easy interface for `file-attributes'."
3903 (let ((all (destructuring-bind
3904 (type links uid gid access-time modif-time
3905 status size mode gid-change inode device-num
)
3906 (file-attributes file
'string
)
3911 :access-time access-time
3912 :modif-time modif-time
3916 :gid-change gid-change
3918 :device-num device-num
))))
3920 (let ((result (getf all
:type
)))
3921 (cond ((stringp result
)
3923 (result "directory")
3925 (links (getf all
:links
))
3926 (uid (getf all
:uid
))
3927 (gid (getf all
:gid
))
3929 (format-time-string "%Y-%m-%d %R" (getf all
:access-time
)))
3931 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
)))
3933 (format-time-string "%Y-%m-%d %R" (getf all
:status
)))
3934 (size (if human-size
(anything-ff-human-size (getf all
:size
))
3936 (mode (getf all
:mode
))
3937 (gid-change (getf all
:gid-change
))
3938 (inode (getf all
:inode
))
3939 (device-num (getf all
:device-num
))
3942 (getf all
:mode
) " "
3943 (number-to-string (getf all
:links
)) " "
3946 (if human-size
(anything-ff-human-size (getf all
:size
))
3947 (int-to-string (getf all
:size
))) " "
3948 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
))))
3951 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file
)
3952 "Return filename FNAME maybe prefixed with [?] or [@].
3953 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3954 existing filename or valid symlink and there is no need to test it.
3955 NEW-FILE when non--nil mean FNAME is a non existing file and
3956 return FNAME prefixed with [?]."
3957 (let* ((prefix-new (propertize
3959 (propertize "[?]" 'face
'anything-ff-prefix
)))
3960 (prefix-url (propertize
3962 (propertize "[@]" 'face
'anything-ff-prefix
))))
3963 (cond ((or file-or-symlinkp
(file-exists-p fname
)) fname
)
3964 ((string-match ffap-url-regexp fname
)
3965 (concat prefix-url
" " fname
))
3966 ((or new-file
(not (file-exists-p fname
)))
3967 (concat prefix-new
" " fname
)))))
3969 (defun anything-c-find-files-transformer (files sources
)
3970 "Transformer for `anything-c-source-find-files'.
3971 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3973 (if (and (string-match tramp-file-name-regexp anything-pattern
)
3974 anything-ff-tramp-not-fancy
)
3975 (if anything-ff-transformer-show-only-basename
3976 (loop for i in files collect
3977 (if (string-match "[.]\\{1,2\\}$" i
)
3978 i
(cons (anything-c-basename i
) i
)))
3980 (anything-ff-highlight-files files sources
)))
3982 (defun anything-ff-highlight-files (files sources
)
3983 "Candidate transformer for `anything-c-source-find-files' without icons."
3984 (loop for i in files
3985 for disp
= (if (and anything-ff-transformer-show-only-basename
3986 (not (string-match "[.]\\{1,2\\}$" i
))
3987 (not (string-match ffap-url-regexp i
)))
3988 (anything-c-basename i
) i
)
3990 (cond ((and (stringp (car (file-attributes i
)))
3991 (not (anything-ff-valid-symlink-p i
))
3992 (not (string-match "^\.#" (anything-c-basename i
))))
3993 (cons (anything-ff-prefix-filename
3994 (propertize disp
'face
'anything-ff-invalid-symlink
) t
)
3996 ((stringp (car (file-attributes i
)))
3997 (cons (anything-ff-prefix-filename
3998 (propertize disp
'face
'anything-ff-symlink
) t
)
4000 ((eq t
(car (file-attributes i
)))
4001 (cons (anything-ff-prefix-filename
4002 (propertize disp
'face
'anything-ff-directory
) t
)
4004 ((file-executable-p i
)
4005 (cons (anything-ff-prefix-filename
4006 (propertize disp
'face
'anything-ff-executable
) t
)
4009 (cons (anything-ff-prefix-filename
4010 (propertize disp
'face
'anything-ff-file
) t
)
4013 (cons (anything-ff-prefix-filename
4014 (propertize disp
'face
'anything-ff-file
) nil
'new-file
)
4017 (defun anything-find-files-action-transformer (actions candidate
)
4018 "Action transformer for `anything-c-source-find-files'."
4019 (cond ((with-anything-current-buffer
4020 (eq major-mode
'message-mode
))
4021 (append (subseq actions
0 4)
4022 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files
))
4023 (subseq actions
4)))
4024 ((string-match (image-file-name-regexp) candidate
)
4025 (append (subseq actions
0 4)
4026 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right
)
4027 ("Rotate image left `M-l'" . anything-ff-rotate-image-left
))
4028 (subseq actions
4)))
4029 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4030 (car it
) candidate
))
4031 (append (subseq actions
0 4)
4032 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4033 . anything-find-files-byte-compile
)
4034 ("Load File(s) `M-L'" . anything-find-files-load-files
))
4035 (subseq actions
4)))
4036 ((and (string-match "\.html?$" candidate
)
4037 (file-exists-p candidate
))
4038 (append (subseq actions
0 4)
4039 '(("Browse url file" . browse-url-of-file
))
4040 (subseq actions
5)))
4041 ((or (string= (file-name-extension candidate
) "pdf")
4042 (string= (file-name-extension candidate
) "PDF"))
4043 (append (subseq actions
0 4)
4044 '(("Pdfgrep File(s)" . anything-ff-pdfgrep
))
4045 (subseq actions
5)))
4048 (defun anything-ff-gnus-attach-files (candidate)
4049 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4050 (let ((flist (anything-marked-candidates)))
4051 (gnus-dired-attach flist
)))
4053 (defun anything-ff-rotate-current-image-1 (file &optional num-arg
)
4054 "Rotate current image at NUM-ARG degrees.
4055 This is a destructive operation on FILE made by external tool mogrify."
4056 (declare (special image-dired-display-image-buffer
))
4057 (setq file
(file-truename file
)) ; For symlinked images.
4058 ;; When FILE is not an image-file, do nothing.
4059 (when (string-match (image-file-name-regexp) file
)
4060 (if (executable-find "mogrify")
4062 (shell-command (format "mogrify -rotate %s %s"
4064 (shell-quote-argument file
)))
4065 (when (buffer-live-p image-dired-display-image-buffer
)
4066 (kill-buffer image-dired-display-image-buffer
))
4067 (image-dired-display-image file
)
4069 (display-buffer (get-buffer image-dired-display-image-buffer
)))
4070 (error "mogrify not found"))))
4072 (defun anything-ff-rotate-image-left (candidate)
4073 "Rotate image file CANDIDATE left.
4074 This affect directly file CANDIDATE."
4075 (anything-ff-rotate-current-image-1 candidate -
90))
4077 (defun anything-ff-rotate-image-right (candidate)
4078 "Rotate image file CANDIDATE right.
4079 This affect directly file CANDIDATE."
4080 (anything-ff-rotate-current-image-1 candidate
))
4082 (defun anything-ff-rotate-left-persistent ()
4083 "Rotate image left without quitting anything."
4085 (anything-attrset 'image-action1
'anything-ff-rotate-image-left
)
4086 (anything-execute-persistent-action 'image-action1
))
4088 (defun anything-ff-rotate-right-persistent ()
4089 "Rotate image right without quitting anything."
4091 (anything-attrset 'image-action2
'anything-ff-rotate-image-right
)
4092 (anything-execute-persistent-action 'image-action2
))
4094 (defun anything-ff-exif-data (candidate)
4095 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4096 (if (and anything-ff-exif-data-program
4097 (executable-find anything-ff-exif-data-program
))
4098 (shell-command-to-string (format "%s %s %s"
4099 anything-ff-exif-data-program
4100 anything-ff-exif-data-program-args
4102 (format "No program %s found to extract exif"
4103 anything-ff-exif-data-program
)))
4105 (defun anything-find-files-persistent-action (candidate)
4106 "Open subtree CANDIDATE without quitting anything.
4107 If CANDIDATE is not a directory expand CANDIDATE filename.
4108 If CANDIDATE is alone, open file CANDIDATE filename.
4110 First hit on C-z expand CANDIDATE second hit open file.
4111 If a prefix arg is given or `anything-follow-mode' is on open file."
4112 (let ((follow (buffer-local-value
4113 'anything-follow-mode
4114 (get-buffer-create anything-buffer
)))
4115 (new-pattern (anything-get-selection))
4116 (num-lines-buf (with-current-buffer anything-buffer
4117 (count-lines (point-min) (point-max)))))
4118 (flet ((insert-in-minibuffer (fname)
4119 (with-selected-window (minibuffer-window)
4121 (delete-minibuffer-contents)
4122 (set-text-properties 0 (length fname
) nil fname
)
4124 (cond ((and (string= (anything-ff-set-pattern anything-pattern
)
4125 "Invalid tramp file name")
4126 (string-match tramp-file-name-regexp candidate
))
4127 ;; First hit insert hostname and
4128 ;; second hit insert ":" and expand.
4129 (if (string= candidate anything-pattern
)
4130 (insert-in-minibuffer (concat candidate
":"))
4131 (insert-in-minibuffer candidate
)))
4132 (;; A symlink directory, expand it's truename.
4133 (and (file-directory-p candidate
) (file-symlink-p candidate
))
4134 (insert-in-minibuffer (file-name-as-directory
4136 (expand-file-name candidate
)))))
4137 ;; A directory, open it.
4138 ((file-directory-p candidate
)
4139 (when (string= (anything-c-basename candidate
) "..")
4140 (setq anything-ff-last-expanded anything-ff-default-directory
))
4141 (insert-in-minibuffer (file-name-as-directory
4142 (expand-file-name candidate
))))
4143 ;; A symlink file, expand to it's true name. (first hit)
4144 ((and (file-symlink-p candidate
) (not current-prefix-arg
) (not follow
))
4145 (insert-in-minibuffer (file-truename candidate
)))
4146 ;; A regular file, expand it, (first hit)
4147 ((and (>= num-lines-buf
3) (not current-prefix-arg
) (not follow
))
4148 (insert-in-minibuffer new-pattern
))
4149 ;; An image file and it is the second hit on C-z,
4150 ;; show the file in `image-dired'.
4151 ((string-match (image-file-name-regexp) candidate
)
4152 (when (buffer-live-p image-dired-display-image-buffer
)
4153 (kill-buffer image-dired-display-image-buffer
))
4154 (image-dired-display-image candidate
)
4156 (anything-c-switch-to-buffer image-dired-display-image-buffer
)
4157 (with-current-buffer image-dired-display-image-buffer
4158 (let ((exif-data (anything-ff-exif-data candidate
)))
4159 (image-dired-update-property 'help-echo exif-data
))))
4160 ;; Allow browsing archive on avfs fs.
4161 ;; Assume volume is already mounted with mountavfs.
4162 ((and anything-ff-avfs-directory
4164 (regexp-quote (expand-file-name anything-ff-avfs-directory
))
4165 (file-name-directory candidate
))
4166 (anything-ff-file-compressed-p candidate
))
4167 (insert-in-minibuffer (concat candidate
"#")))
4168 ;; On second hit we open file.
4169 ;; On Third hit we kill it's buffer maybe.
4171 (anything-ff-kill-or-find-buffer-fname candidate
))))))
4173 (defun anything-ff-file-compressed-p (candidate)
4174 "Whether CANDIDATE is a compressed file or not."
4175 (member (file-name-extension candidate
)
4176 anything-ff-file-compressed-list
))
4178 (defun anything-c-insert-file-name-completion-at-point (candidate)
4179 "Insert file name completion at point."
4180 (with-anything-current-buffer
4181 (if buffer-read-only
4182 (error "Error: Buffer `%s' is read-only" (buffer-name))
4183 (let* ((end (point))
4184 (guess (substring-no-properties (thing-at-point 'filename
)))
4185 (beg (- (point) (length guess
)))
4186 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess
)
4187 (string-match-p "^[^\~]" guess
))))
4188 (set-text-properties 0 (length candidate
) nil candidate
)
4189 (if (and guess
(not (string= guess
""))
4190 (string-match-p "^~\\|/.*" guess
))
4192 (delete-region beg end
)
4193 (insert (if full-path-p
4194 (expand-file-name candidate
)
4195 (abbreviate-file-name candidate
))))
4196 (error "Aborting completion: No valid file name at point"))))))
4198 (defun* anything-find-files-history
(&key
(comp-read t
))
4199 "The `anything-find-files' history.
4200 Show the first `anything-ff-history-max-length' elements of
4201 `anything-ff-history' in an `anything-comp-read'."
4202 (let ((history (when anything-ff-history
4203 (anything-fast-remove-dups anything-ff-history
4206 (setq anything-ff-history
4207 (if (>= (length history
) anything-ff-history-max-length
)
4208 (subseq history
0 anything-ff-history-max-length
)
4212 "Switch to Directory: "
4214 :name
"Anything Find Files History"
4216 anything-ff-history
))))
4218 (defun anything-find-files-1 (fname &optional preselect
)
4219 "Find FNAME with `anything' completion.
4220 Like `find-file' but with `anything' support.
4221 Use it for non--interactive calls of `anything-find-files'."
4222 (when (get-buffer anything-action-buffer
)
4223 (kill-buffer anything-action-buffer
))
4224 (let ((anything-mp-highlight-delay nil
)
4225 ;; Be sure we don't erase the precedent minibuffer if some.
4226 (anything-ff-auto-update-initial-value
4227 (not (minibuffer-window-active-p (minibuffer-window))))
4228 anything-samewindow
)
4229 (anything :sources
'anything-c-source-find-files
4231 :preselect preselect
4232 :keymap anything-find-files-map
4233 :prompt
"Find Files or Url: "
4234 :buffer
"*Anything Find Files*")))
4237 (defun anything-find-files-initial-input (&optional input
)
4238 "Return INPUT if present, otherwise try to guess it."
4239 (or (and input
(expand-file-name input
))
4240 (anything-find-files-input
4242 (thing-at-point 'filename
))))
4244 (defun anything-find-files-input (fap tap
)
4245 "Default input of `anything-find-files'."
4246 (let* ((def-dir (anything-c-current-directory))
4247 (lib (anything-find-library-at-point))
4248 (url (anything-ff-find-url-at-point))
4249 (file-p (and fap
(not (string= fap
""))
4251 tap
(not (string= tap
""))
4253 (file-name-directory (expand-file-name tap def-dir
))))))
4254 (cond (lib) ; e.g we are inside a require sexp.
4255 (url) ; String at point is an hyperlink.
4256 (file-p (expand-file-name tap def-dir
))
4257 (t (and (not (string= fap
"")) fap
)))))
4259 (defun anything-c-current-directory ()
4260 "Return current-directory name at point.
4261 Useful in dired buffers when there is inserted subdirs."
4262 (if (eq major-mode
'dired-mode
)
4263 (dired-current-directory)
4266 (defun anything-ff-find-url-at-point ()
4267 "Try to find link to an url in text-property at point."
4268 (let* ((he (get-text-property (point) 'help-echo
))
4269 (ov (overlays-at (point)))
4270 (ov-he (and ov
(overlay-get
4271 (car (overlays-at (point))) 'help-echo
)))
4272 (w3m-l (get-text-property (point) 'w3m-href-anchor
))
4273 (nt-prop (get-text-property (point) 'nt-link
)))
4275 (when (and (stringp he
) (string-match "^LINK: " he
))
4276 (setq he
(replace-match "" t t he
)))
4277 (loop for i in
(list he ov-he w3m-l nt-prop
)
4278 thereis
(and (stringp i
) (string-match ffap-url-regexp i
) i
))))
4280 (defun anything-find-library-at-point ()
4281 "Try to find library path at point.
4282 Find inside `require' and `declare-function' sexp."
4283 (require 'find-func
)
4284 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
4285 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
4286 (sexp (and beg-sexp end-sexp
4287 (buffer-substring-no-properties
4288 (1+ beg-sexp
) (1- end-sexp
)))))
4290 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
4292 (replace-regexp-in-string
4294 ;; If require use third arg, ignore it,
4295 ;; always use library path found in `load-path'.
4296 (second (split-string (match-string 0 sexp
))))))
4297 ((and sexp
(string-match-p "^declare-function" sexp
))
4299 (replace-regexp-in-string
4301 (third (split-string sexp
)))))
4304 ;;; Anything completion for `write-file'.==> C-x C-w
4305 (defvar anything-c-source-write-file
4306 `((name .
"Write File")
4307 (header-name .
(lambda (name)
4308 (concat name anything-c-find-files-doc-header
)))
4309 ;; It is needed for filenames with capital letters
4311 (candidates . anything-find-files-get-candidates
)
4312 (filtered-candidate-transformer anything-c-find-files-transformer
)
4313 (persistent-action . anything-find-files-persistent-action
)
4314 (persistent-help .
"Expand Candidate")
4317 (("Write File" .
(lambda (candidate)
4318 (write-file candidate
'confirm
)))))))
4320 ;;; Anything completion for `insert-file'.==> C-x i
4321 (defvar anything-c-source-insert-file
4322 `((name .
"Insert File")
4323 (header-name .
(lambda (name)
4324 (concat name anything-c-find-files-doc-header
)))
4325 ;; It is needed for filenames with capital letters
4327 (candidates . anything-find-files-get-candidates
)
4328 (filtered-candidate-transformer anything-c-find-files-transformer
)
4329 (persistent-action . anything-find-files-persistent-action
)
4330 (persistent-help .
"Expand Candidate")
4333 (("Insert File" .
(lambda (candidate)
4334 (when (y-or-n-p (format "Really insert %s in %s "
4335 candidate anything-current-buffer
))
4336 (insert-file-contents candidate
))))))))
4338 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4339 (defvar anything-c-source-copy-files
4340 `((name .
"Copy Files")
4341 (header-name .
(lambda (name)
4342 (concat name anything-c-find-files-doc-header
)))
4343 ;; It is needed for filenames with capital letters
4345 (candidates . anything-find-files-get-candidates
)
4346 (filtered-candidate-transformer anything-c-find-files-transformer
)
4347 (persistent-action . anything-find-files-persistent-action
)
4348 (persistent-help .
"Expand Candidate")
4352 .
(lambda (candidate)
4353 (anything-dired-action candidate
:action
'copy
)))
4355 .
(lambda (candidate)
4356 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
4359 (defvar anything-c-source-rename-files
4360 `((name .
"Rename Files")
4361 (header-name .
(lambda (name)
4362 (concat name anything-c-find-files-doc-header
)))
4363 ;; It is needed for filenames with capital letters
4365 (candidates . anything-find-files-get-candidates
)
4366 (filtered-candidate-transformer anything-c-find-files-transformer
)
4367 (persistent-action . anything-find-files-persistent-action
)
4368 (persistent-help .
"Expand Candidate")
4372 .
(lambda (candidate)
4373 (anything-dired-action candidate
:action
'rename
)))
4374 ("Rename and Follow"
4375 .
(lambda (candidate)
4376 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
4378 (defvar anything-c-source-symlink-files
4379 `((name .
"Symlink Files")
4380 (header-name .
(lambda (name)
4381 (concat name anything-c-find-files-doc-header
)))
4382 ;; It is needed for filenames with capital letters
4384 (candidates . anything-find-files-get-candidates
)
4385 (filtered-candidate-transformer anything-c-find-files-transformer
)
4386 (persistent-action . anything-find-files-persistent-action
)
4387 (persistent-help .
"Expand Candidate")
4391 .
(lambda (candidate)
4392 (anything-dired-action candidate
:action
'symlink
)))
4394 .
(lambda (candidate)
4395 (anything-dired-action candidate
:action
'relsymlink
)))))))
4398 (defvar anything-c-source-hardlink-files
4399 `((name .
"Hardlink Files")
4400 (header-name .
(lambda (name)
4401 (concat name anything-c-find-files-doc-header
)))
4402 ;; It is needed for filenames with capital letters
4404 (candidates . anything-find-files-get-candidates
)
4405 (filtered-candidate-transformer anything-c-find-files-transformer
)
4406 (persistent-action . anything-find-files-persistent-action
)
4407 (persistent-help .
"Expand Candidate")
4411 .
(lambda (candidate)
4412 (anything-dired-action candidate
:action
'hardlink
)))))))
4414 (defun* anything-dired-action
(candidate &key action follow
(files (dired-get-marked-files)))
4415 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4416 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4417 (when (get-buffer dired-log-buffer
) (kill-buffer dired-log-buffer
))
4418 (let ((fn (case action
4419 ('copy
'dired-copy-file
)
4420 ('rename
'dired-rename-file
)
4421 ('symlink
'make-symbolic-link
)
4422 ('relsymlink
'dired-make-relative-symlink
)
4423 ('hardlink
'dired-hardlink
)))
4424 (marker (case action
4425 ((copy rename
) dired-keep-marker-copy
)
4426 ('symlink dired-keep-marker-symlink
)
4427 ('relsymlink dired-keep-marker-relsymlink
)
4428 ('hardlink dired-keep-marker-hardlink
)))
4429 (dirflag (and (= (length files
) 1)
4430 (file-directory-p (car files
))
4431 (not (file-directory-p candidate
)))))
4433 fn
(symbol-name action
) files
4434 ;; CANDIDATE is the destination.
4435 (if (file-directory-p candidate
)
4436 ;; When CANDIDATE is a directory, build file-name in this directory.
4437 ;; Else we use CANDIDATE.
4439 (expand-file-name (file-name-nondirectory from
) candidate
))
4440 #'(lambda (from) candidate
))
4442 (push (file-name-as-directory
4443 (if (file-directory-p candidate
)
4444 candidate
(file-name-directory candidate
)))
4445 anything-ff-history
)
4446 (when (and follow
(not (get-buffer dired-log-buffer
)))
4447 (let ((target (directory-file-name candidate
)))
4450 (setq anything-ff-cand-to-mark
4451 (anything-get-dest-fnames-from-list files candidate dirflag
))
4452 (if (and dirflag
(eq action
'rename
))
4453 (anything-find-files-1 (file-name-directory target
)
4454 (if anything-ff-transformer-show-only-basename
4455 (anything-c-basename target
) target
))
4456 (anything-find-files-1 (expand-file-name candidate
))))
4457 (setq anything-ff-cand-to-mark nil
))))))
4460 (defun anything-c-basename (fname)
4461 "Resolve basename of file or directory named FNAME."
4462 (file-name-nondirectory (directory-file-name fname
)))
4464 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag
)
4465 "Transform filenames of FLIST to abs of DEST-CAND.
4466 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4468 ;; At this point files have been renamed/copied at destination.
4469 ;; That's mean DEST-CAND exists.
4471 with dest
= (expand-file-name dest-cand
)
4473 for basename-src
= (anything-c-basename src
)
4474 for fname
= (cond (rename-dir-flag (directory-file-name dest
))
4475 ((file-directory-p dest
)
4476 (concat (file-name-as-directory dest
) basename-src
))
4478 when
(file-exists-p fname
)
4479 collect fname into tmp-list
4480 finally return
(sort tmp-list
'string
<)))
4482 (defun anything-ff-maybe-mark-candidates ()
4483 "Mark all candidates of list `anything-ff-cand-to-mark'."
4484 (when (and (string= (assoc-default 'name
(anything-get-current-source))
4485 (assoc-default 'name anything-c-source-find-files
))
4486 anything-ff-cand-to-mark
)
4487 (with-anything-window
4488 (while anything-ff-cand-to-mark
4489 (if (string= (car anything-ff-cand-to-mark
) (anything-get-selection))
4491 (anything-make-visible-mark)
4492 (anything-next-line)
4493 (setq anything-ff-cand-to-mark
(cdr anything-ff-cand-to-mark
)))
4494 (anything-next-line)))
4495 (unless (anything-this-visible-mark)
4496 (anything-prev-visible-mark)))))
4498 (add-hook 'anything-after-update-hook
#'anything-ff-maybe-mark-candidates
)
4500 (defun* anything-dired-do-action-on-file
(&key action
)
4501 (let* ((files (dired-get-marked-files))
4502 (len (length files
))
4503 (fname (if (> len
1)
4504 (format "* %d Files" len
)
4506 (source (case action
4507 ('copy
'anything-c-source-copy-files
)
4508 ('rename
'anything-c-source-rename-files
)
4509 ('symlink
'anything-c-source-symlink-files
)
4510 ('hardlink
'anything-c-source-hardlink-files
)))
4511 (prompt-fm (case action
4512 ('copy
"Copy %s to: ")
4513 ('rename
"Rename %s to: ")
4514 ('symlink
"Symlink %s to: ")
4515 ('hardlink
"Hardlink %s to: ")))
4516 (buffer (case action
4517 ('copy
"*Anything Copy Files*")
4518 ('rename
"*Anything Rename Files*")
4519 ('symlink
"*Anything Symlink Files*")
4520 ('hardlink
"*Anything Hardlink Files*")))
4521 (anything-mp-highlight-delay nil
))
4522 (anything :sources source
4523 :input
(or (dired-dwim-target-directory)
4524 (expand-file-name (anything-c-current-directory)))
4525 :preselect
(dired-get-filename)
4526 :prompt
(format prompt-fm fname
)
4527 :keymap anything-c-read-file-map
4531 (define-minor-mode anything-dired-mode
()
4532 "Enable anything completion in Dired functions.
4533 Bindings affected are C, R, S, H.
4534 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4535 :group
'anything-config
4537 (if anything-dired-mode
4539 (substitute-key-definition
4540 'dired-do-copy
'anything-dired-copy-file dired-mode-map
)
4541 (substitute-key-definition
4542 'dired-do-rename
'anything-dired-rename-file dired-mode-map
)
4543 (substitute-key-definition
4544 'dired-do-symlink
'anything-dired-symlink-file dired-mode-map
)
4545 (substitute-key-definition
4546 'dired-do-hardlink
'anything-dired-hardlink-file dired-mode-map
))
4547 (substitute-key-definition
4548 'anything-dired-copy-file
'dired-do-copy dired-mode-map
)
4549 (substitute-key-definition
4550 'anything-dired-rename-file
'dired-do-rename dired-mode-map
)
4551 (substitute-key-definition
4552 'anything-dired-symlink-file
'dired-do-symlink dired-mode-map
)
4553 (substitute-key-definition
4554 'anything-dired-hardlink-file
'dired-do-hardlink dired-mode-map
)))
4556 (defalias 'anything-dired-bindings
'anything-dired-mode
)
4558 (defun* anything-c-read-file-name
(prompt
4560 (name "Read File Name")
4561 (initial-input (expand-file-name default-directory
))
4562 (buffer "*Anything Completions*")
4566 (marked-candidates nil
)
4568 (persistent-action 'anything-find-files-persistent-action
)
4569 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4570 "Anything `read-file-name' emulation.
4571 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4572 (when (get-buffer anything-action-buffer
)
4573 (kill-buffer anything-action-buffer
))
4574 (let ((anything-mp-highlight-delay nil
)
4575 ;; Be sure we don't erase the underlying minibuffer if some.
4576 (anything-ff-auto-update-initial-value
4577 (not (minibuffer-window-active-p (minibuffer-window))))
4578 anything-same-window
4579 (hist (and history
(anything-comp-read-get-candidates
4580 history nil nil alistp
))))
4581 (flet ((action-fn (candidate)
4582 (if marked-candidates
4583 (anything-marked-candidates)
4584 (identity candidate
))))
4587 `(((name .
,(format "%s History" name
))
4588 (header-name .
(lambda (name)
4589 (concat name anything-c-find-files-doc-header
)))
4591 (mode-line . anything-read-file-name-mode-line-string
)
4593 (persistent-action .
,persistent-action
)
4594 (persistent-help .
,persistent-help
)
4595 (action .
,'action-fn
))
4597 (header-name .
(lambda (name)
4598 (concat name anything-c-find-files-doc-header
)))
4599 ;; It is needed for filenames with capital letters
4601 (mode-line . anything-read-file-name-mode-line-string
)
4602 (candidates .
(lambda ()
4603 (let ((seq (anything-find-files-get-candidates)))
4605 (loop for fname in seq
4606 when
(funcall test fname
) collect fname
)
4608 (filtered-candidate-transformer anything-c-find-files-transformer
)
4609 (persistent-action .
,persistent-action
)
4610 (candidate-number-limit .
9999)
4611 (toggle-auto-update . anything-ff-toggle-auto-update
)
4612 (persistent-help .
,persistent-help
)
4614 (action .
,'action-fn
)))
4615 :input initial-input
4617 :keymap anything-c-read-file-map
4620 :preselect preselect
)
4625 (defvar anything-c-file-cache-initialized-p nil
)
4627 (defvar anything-c-file-cache-files nil
)
4629 (defvar anything-c-source-file-cache
4630 '((name .
"File Cache")
4633 (require 'filecache nil t
)
4634 (unless anything-c-file-cache-initialized-p
4635 (setq anything-c-file-cache-files
4636 (loop for item in file-cache-alist append
4637 (destructuring-bind (base &rest dirs
) item
4638 (loop for dir in dirs collect
4639 (concat dir base
)))))
4640 (defadvice file-cache-add-file
(after file-cache-list activate
)
4641 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
4642 (setq anything-c-file-cache-initialized-p t
))))
4643 (candidates . anything-c-file-cache-files
)
4644 (match anything-c-match-on-basename
)
4646 ;; (anything 'anything-c-source-file-cache)
4652 ;; NOTE for WINDOZE users:
4653 ;; You have to install Everything with his command line interface here:
4654 ;; http://www.voidtools.com/download.php
4656 (defun anything-locate-1 (&optional localdb init
)
4657 "Generic function to run Locate.
4658 if LOCALDB is non--nil search and use a local locate db file.
4659 INIT is a string to use as initial input in prompt.
4660 See `anything-locate-with-db' and `anything-locate'."
4661 (anything-locate-with-db
4663 (anything-c-read-file-name
4665 :marked-candidates t
4666 :preselect anything-locate-db-file-regexp
4668 (if anything-locate-db-file-regexp
4669 ;; Select only locate db files and directories
4670 ;; to allow navigation.
4672 anything-locate-db-file-regexp x
)
4673 (file-directory-p x
))
4676 ;; (anything-locate-1 t)
4678 (defun anything-locate-with-db (&optional db initial-input
)
4680 If DB is not given or nil use locate without -d option.
4681 Argument DB can be given as a string or list of db files.
4682 Argument INITIAL-INPUT is a string to use as initial-input.
4683 See also `anything-locate'."
4684 (when (and db
(stringp db
)) (setq db
(list db
)))
4685 (let ((anything-c-locate-command
4687 (replace-regexp-in-string
4689 (format "locate -d %s"
4690 (mapconcat 'identity
4691 ;; Remove eventually
4692 ;; marked directories by error.
4694 unless
(file-directory-p i
)
4696 anything-c-locate-command
)
4697 anything-c-locate-command
)))
4698 (anything :sources
'anything-c-source-locate
4699 :buffer
"*anything locate*"
4700 :input initial-input
4701 :keymap anything-generic-files-map
)))
4702 ;; (anything-locate-with-db "~/locate.db")
4704 (defun anything-c-locate-init ()
4705 "Initialize async locate process for `anything-c-source-locate'."
4706 (setq mode-line-format
4707 '(" " mode-line-buffer-identification
" "
4708 (line-number-mode "%l") " "
4709 (:eval
(propertize "(Locate Process Running) "
4710 'face
'((:foreground
"red"))))))
4712 (start-process-shell-command "locate-process" nil
4713 (format anything-c-locate-command
4715 (set-process-sentinel (get-process "locate-process")
4716 #'(lambda (process event
)
4717 (when (string= event
"finished\n")
4718 (with-anything-window
4719 (force-mode-line-update nil
)
4720 (anything-update-move-first-line)))))))
4722 (defvar anything-c-source-locate
4724 (candidates . anything-c-locate-init
)
4726 (properties-action . anything-ff-properties
)
4727 (requires-pattern .
3)
4728 (candidate-number-limit .
9999)
4729 (mode-line . anything-generic-file-mode-line-string
)
4731 "Find files matching the current input pattern with locate.")
4732 ;; (anything 'anything-c-source-locate)
4734 (defun anything-c-locate-read-file-name (prompt &optional init
)
4735 "Search a file with locate and return it's filename.
4736 Use argument PROMPT and INIT for `anything' arguments
4740 (candidates . anything-c-locate-init
)
4742 (properties-action . anything-ff-properties
)
4743 (requires-pattern .
3)
4744 (candidate-number-limit .
9999)
4745 (mode-line . anything-generic-file-mode-line-string
)
4749 :buffer
"*anything locate rfn*"))
4753 ;;; Anything Incremental Grep.
4756 ;; Allow to grep incrementally with anything interface.
4757 ;; It allow also to Grep files recursively without using 'find' shell command.
4758 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4759 (defvar anything-c-grep-default-command
4760 "grep -d skip %e -niH -e %p %f"
4761 "Default grep format command for `anything-do-grep-1'.
4763 '%e' format spec is for --exclude or --include grep options.
4764 '%p' format spec is for pattern.
4765 '%f' format spec is for filenames.")
4767 (defvar anything-c-grep-default-recurse-command
4768 "grep -d recurse %e -niH -e %p %f"
4769 "Default recursive grep format command for `anything-do-grep-1'.
4770 See `anything-c-grep-default-command' for format specs.")
4772 (defvar anything-c-default-zgrep-command
"zgrep -niH -e %p %f")
4774 (defvar anything-c-rzgrep-cache
(make-hash-table :test
'equal
))
4776 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
4778 (defvar anything-c-grep-debug-command-line nil
4779 "Turn on anything grep command-line debugging when non--nil.")
4781 (defvar anything-c-zgrep-recurse-flag nil
)
4783 (defvar anything-c-grep-history nil
)
4785 (defvar anything-c-grep-max-length-history
100
4786 "*Max number of elements to save in `anything-c-grep-history'.")
4788 (defun anything-c-grep-prepare-candidates (candidates)
4789 "Prepare filenames and directories CANDIDATES for grep command line."
4790 ;; If one or more candidate is a directory, search in all files
4791 ;; of this candidate (e.g /home/user/directory/*).
4792 ;; If r option is enabled search also in subdidrectories.
4793 ;; We need here to expand wildcards to support crap windows filenames
4794 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4795 (if anything-c-zgrep-recurse-flag
4796 (mapconcat 'shell-quote-argument candidates
" ")
4797 (loop for i in candidates append
4798 (cond ( ;; Candidate is a directory and we use recursion.
4799 (and (file-directory-p i
)
4800 (anything-c-grep-recurse-p))
4801 (list (expand-file-name i
)))
4802 ;; Candidate is a directory, search in all files.
4803 ((file-directory-p i
)
4804 (file-expand-wildcards
4805 (concat (file-name-as-directory (expand-file-name i
)) "*") t
))
4806 ;; Candidate is a file or wildcard and we use recursion, use the
4807 ;; current directory instead of candidate.
4808 ((and (or (file-exists-p i
) (string-match "\*" i
))
4809 (anything-c-grep-recurse-p))
4810 (list (expand-file-name
4811 (directory-file-name ; Needed for windoze.
4812 (file-name-directory (directory-file-name i
))))))
4813 ;; Candidate use wildcard.
4814 ((string-match "^\*" (anything-c-basename i
))
4815 (file-expand-wildcards i t
))
4816 ;; Else should be one or more file.
4817 (t (list i
))) into all-files
4819 (mapconcat 'shell-quote-argument all-files
" "))))
4821 (defun anything-c-grep-recurse-p ()
4822 "Check if `anything-do-grep-1' have switched to recursive."
4823 (let ((args (replace-regexp-in-string
4824 "grep" "" anything-c-grep-default-command
)))
4825 (string-match-p "r\\|recurse" args
)))
4827 (defun anything-c-grep-init (only-files &optional include zgrep
)
4828 "Start an asynchronous grep process in ONLY-FILES list."
4829 (let* ((fnargs (anything-c-grep-prepare-candidates
4830 (if (file-remote-p anything-ff-default-directory
)
4831 (mapcar #'(lambda (x)
4832 (file-remote-p x
'localname
))
4835 (ignored-files (mapconcat
4837 (concat "--exclude=" (shell-quote-argument x
)))
4838 grep-find-ignored-files
" "))
4839 (ignored-dirs (mapconcat
4840 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4842 (concat "--exclude-dir=" (shell-quote-argument x
)))
4843 grep-find-ignored-directories
" "))
4844 (exclude (if (anything-c-grep-recurse-p)
4845 (concat (or include ignored-files
) " " ignored-dirs
)
4847 (cmd-line (format-spec
4848 anything-c-grep-default-command
4850 (list (unless zgrep
(cons ?e exclude
))
4851 (cons ?p
(shell-quote-argument anything-pattern
))
4852 (cons ?f fnargs
))))))
4853 (when anything-c-grep-debug-command-line
4854 (with-current-buffer (get-buffer-create "*any grep debug*")
4855 (goto-char (point-max))
4856 (insert (concat ">>> " cmd-line
"\n\n"))))
4857 (setq mode-line-format
4858 '(" " mode-line-buffer-identification
" "
4859 (line-number-mode "%l") " "
4860 (:eval
(when (get-process "grep-process")
4861 (propertize "[Grep Process Running] "
4862 'face
'anything-grep-running
)))))
4863 (force-mode-line-update nil
)
4865 (let ((default-directory anything-ff-default-directory
))
4866 (start-file-process-shell-command "grep-process" nil cmd-line
))
4868 (set-process-sentinel
4869 (get-process "grep-process")
4870 #'(lambda (process event
)
4871 (when (string= event
"finished\n")
4872 (with-anything-window
4873 (anything-update-move-first-line)
4874 (setq mode-line-format
4875 '(" " mode-line-buffer-identification
" "
4876 (line-number-mode "%l") " "
4878 (format "[Grep Process Finished - (%s results)] "
4879 (let ((nlines (1- (count-lines
4882 (if (> nlines
0) nlines
0)))
4883 'face
'anything-grep-finish
))))
4884 (force-mode-line-update nil
))))))))
4886 (defun anything-c-grep-action (candidate &optional where mark
)
4887 "Define a default action for `anything-do-grep' on CANDIDATE.
4888 WHERE can be one of other-window, elscreen, other-frame."
4889 (let* ((split (anything-c-grep-split-line candidate
))
4890 (lineno (string-to-number (nth 1 split
)))
4891 (loc-fname (car split
))
4892 (tramp-method (file-remote-p anything-ff-default-directory
'method
))
4893 (tramp-host (file-remote-p anything-ff-default-directory
'host
))
4894 (tramp-prefix (concat "/" tramp-method
":" tramp-host
":"))
4895 (fname (if tramp-host
4896 (concat tramp-prefix loc-fname
) loc-fname
)))
4898 (other-window (find-file-other-window fname
))
4899 (elscreen (anything-elscreen-find-file fname
))
4900 (other-frame (find-file-other-frame fname
))
4901 (t (find-file fname
)))
4902 (anything-goto-line lineno
)
4904 (set-marker (mark-marker) (point))
4905 (push-mark (point) 'nomsg
))
4907 (unless (or anything-in-persistent-action
4908 (string= anything-pattern
""))
4909 (setq anything-c-grep-history
4910 (cons anything-pattern
4911 (delete anything-pattern anything-c-grep-history
)))
4912 (when (> (length anything-c-grep-history
)
4913 anything-c-grep-max-length-history
)
4914 (setq anything-c-grep-history
4915 (delete (car (last anything-c-grep-history
))
4916 anything-c-grep-history
))))))
4918 (defun anything-c-grep-other-window (candidate)
4919 "Jump to result in other window from anything grep."
4920 (anything-c-grep-action candidate
'other-window
))
4922 (defun anything-c-grep-other-frame (candidate)
4923 "Jump to result in other frame from anything grep."
4924 (anything-c-grep-action candidate
'other-frame
))
4926 (defun anything-c-grep-jump-elscreen (candidate)
4927 "Jump to result in elscreen from anything grep."
4928 (anything-c-grep-action candidate
'elscreen
))
4930 (defun anything-c-grep-save-results (candidate)
4931 "Save anything grep result in a `grep-mode' buffer."
4932 (let ((buf "*grep*")
4934 (when (get-buffer buf
)
4935 (setq new-buf
(read-string "GrepBufferName: " buf
))
4936 (loop for b in
(anything-c-buffer-list)
4937 when
(and (string= new-buf b
)
4939 (format "Buffer `%s' already exists overwrite? "
4941 do
(setq new-buf
(read-string "GrepBufferName: " "*grep ")))
4943 (with-current-buffer (get-buffer-create buf
)
4944 (let ((inhibit-read-only t
))
4946 (insert "-*- mode: grep -*-\n\n"
4947 (format "Grep Results for `%s':\n\n" anything-pattern
))
4949 (insert (with-current-buffer anything-buffer
4951 (buffer-substring (point) (point-max))))
4953 (message "Anything Grep Results saved in `%s' buffer" buf
)))
4955 (defun anything-c-grep-persistent-action (candidate)
4956 "Persistent action for `anything-do-grep'.
4957 With a prefix arg record CANDIDATE in `mark-ring'."
4958 (if current-prefix-arg
4959 (anything-c-grep-action candidate nil
'mark
)
4960 (anything-c-grep-action candidate
))
4961 (anything-match-line-color-current-line))
4963 (defun anything-c-grep-guess-extensions (files)
4964 "Try to guess file extensions in FILES list when using grep recurse.
4965 These extensions will be added to command line with --include arg of grep."
4967 with glob-list
= nil
4968 with lst
= (if (file-directory-p (car files
))
4971 directory-files-no-dot-files-regexp
)
4974 for ext
= (file-name-extension i t
)
4975 for glob
= (and ext
(not (string= ext
""))
4977 unless
(or (not glob
)
4978 (member glob glob-list
)
4979 (member glob grep-find-ignored-files
))
4980 collect glob into glob-list
4981 finally return glob-list
))
4983 (defun anything-do-grep-1 (only &optional recurse zgrep
)
4984 "Launch grep with a list of ONLY files.
4985 When RECURSE is given use -r option of grep and prompt user
4986 to set the --include args of grep.
4987 You can give more than one arg separated by space.
4988 e.g *.el *.py *.tex.
4989 If it's empty --exclude `grep-find-ignored-files' is used instead."
4990 (let* ((anything-compile-source-functions
4991 ;; rule out anything-match-plugin because the input is one regexp.
4992 (delq 'anything-compile-source--match-plugin
4993 (copy-sequence anything-compile-source-functions
)))
4994 (exts (anything-c-grep-guess-extensions only
))
4995 (globs (and (not zgrep
) (mapconcat 'identity exts
" ")))
4996 (include-files (and recurse
(not zgrep
)
4997 (read-string "OnlyExt(*.[ext]): "
4999 ;; Set `minibuffer-history' AFTER includes-files
5000 ;; to avoid storing wild-cards here.
5001 (minibuffer-history anything-c-grep-history
)
5002 (anything-c-grep-default-command (cond ((and recurse zgrep
) anything-c-default-zgrep-command
)
5003 (recurse anything-c-grep-default-recurse-command
)
5004 (zgrep anything-c-default-zgrep-command
)
5005 (t anything-c-grep-default-command
)))
5006 ;; Disable match-plugin and use here own highlighting.
5007 (anything-mp-highlight-delay nil
))
5010 (and (not (string= include-files
""))
5011 (mapconcat #'(lambda (x)
5012 (concat "--include=" (shell-quote-argument x
)))
5013 (split-string include-files
) " "))))
5014 ;; When called as action from an other source e.g *-find-files
5015 ;; we have to kill action buffer.
5016 (when (get-buffer anything-action-buffer
)
5017 (kill-buffer anything-action-buffer
))
5018 ;; `anything-find-files' haven't already started,
5019 ;; give a default value to `anything-ff-default-directory'.
5020 (setq anything-ff-default-directory
(or anything-ff-default-directory
5024 `(((name .
"Grep (C-c ? Help)")
5027 (funcall anything-c-grep-default-function only include-files zgrep
)))
5028 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
5029 (candidate-number-limit .
9999)
5030 (mode-line . anything-grep-mode-line-string
)
5031 (jump-persistent . anything-c-grep-persistent-action
)
5034 `(("Find File" . anything-c-grep-action
)
5035 ("Find file other frame" . anything-c-grep-other-frame
)
5036 ,(and (locate-library "elscreen")
5037 '("Find file in Elscreen"
5038 . anything-c-grep-jump-elscreen
))
5039 ("Save results in grep buffer" . anything-c-grep-save-results
)
5040 ("Find file other window" . anything-c-grep-other-window
))))
5041 (persistent-action . anything-c-grep-persistent-action
)
5042 (persistent-help .
"Jump to line (`C-u' Record in mark ring)")
5043 (requires-pattern .
3)
5045 :keymap anything-c-grep-map
5046 :buffer
"*anything grep*")))
5048 (defun anything-ff-zgrep-1 (flist recursive
)
5050 (let* ((def-dir (or anything-ff-default-directory
5053 (or (gethash def-dir anything-c-rzgrep-cache
)
5056 (anything-c-walk-directory
5060 :match
".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5061 anything-c-rzgrep-cache
))
5063 (when recursive
(setq anything-c-zgrep-recurse-flag t
))
5064 (anything-do-grep-1 only recursive
'zgrep
))
5065 (setq anything-c-zgrep-recurse-flag nil
)))
5067 (defun anything-c-grep-split-line (line)
5068 "Split a grep output line."
5069 (let (beg fname lineno str
)
5070 ;; Don't print until grep line is valid.
5071 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line
)
5074 (goto-char (point-min))
5077 (re-search-forward ":" nil t
)
5078 (setq fname
(buffer-substring-no-properties beg
(1- (point))))
5080 (re-search-forward ":" nil t
)
5081 (setq lineno
(buffer-substring-no-properties beg
(1- (point))))
5082 (setq str
(buffer-substring-no-properties (point) (point-at-eol))))
5083 (list fname lineno str
))))
5085 (defun anything-c-grep-cand-transformer (candidates sources
)
5086 "Filtered candidate transformer function for `anything-do-grep'."
5087 (loop for i in candidates
5088 for split
= (and i
(anything-c-grep-split-line i
))
5089 for fname
= (car split
)
5090 for lineno
= (nth 1 split
)
5091 for str
= (nth 2 split
)
5092 when
(and fname lineno str
)
5094 (cons (concat (propertize (file-name-nondirectory fname
)
5095 'face
'anything-grep-file
5096 'help-echo fname
) ":"
5097 (propertize lineno
'face
'anything-grep-lineno
) ":"
5098 (anything-c-grep-highlight-match str
))
5101 (defun anything-c-grep-highlight-match (str)
5102 "Highlight in string STR all occurences matching `anything-pattern'."
5106 (goto-char (point-min))
5107 (while (and (re-search-forward anything-pattern nil t
)
5108 (> (- (match-end 0) (match-beginning 0)) 0))
5109 (add-text-properties
5110 (match-beginning 0) (match-end 0)
5111 '(face anything-grep-match
)))
5115 ;; Go to next or precedent file (common to etags and grep).
5116 (defun anything-c-goto-next-or-prec-file (n)
5117 "Go to next or precedent candidate file in anything grep/etags buffers.
5118 If N is positive go forward otherwise go backward."
5119 (with-anything-window
5120 (let* ((current-line-list (split-string
5123 (point-at-eol)) ":"))
5124 (current-fname (nth 0 current-line-list
))
5125 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
)))
5127 (while (not (funcall fn-b-o-f
))
5128 (forward-line n
) ; Go forward or backward depending of n value.
5129 (unless (search-forward current-fname
(point-at-eol) t
)
5130 (anything-mark-current-line)
5131 (throw 'break nil
))))
5132 (cond ((and (eq n
1) (eobp))
5133 (re-search-backward ".")
5135 (anything-mark-current-line))
5136 ((and (< n
1) (bobp))
5138 (anything-mark-current-line))))))
5141 (defun anything-c-goto-precedent-file ()
5142 "Go to precedent file in anything grep/etags buffers."
5144 (anything-c-goto-next-or-prec-file -
1))
5147 (defun anything-c-goto-next-file ()
5148 "Go to precedent file in anything grep/etags buffers."
5150 (anything-c-goto-next-or-prec-file 1))
5153 (defun anything-c-grep-run-persistent-action ()
5154 "Run grep persistent action from `anything-do-grep-1'."
5156 (anything-execute-persistent-action 'jump-persistent
))
5159 (defun anything-c-grep-run-default-action ()
5160 "Run grep default action from `anything-do-grep-1'."
5162 (anything-c-quit-and-execute-action 'anything-c-grep-action
))
5165 (defun anything-c-grep-run-other-window-action ()
5166 "Run grep goto other window action from `anything-do-grep-1'."
5168 (anything-c-quit-and-execute-action 'anything-c-grep-other-window
))
5171 (defun anything-c-grep-run-save-buffer ()
5172 "Run grep save results action from `anything-do-grep-1'."
5174 (anything-c-quit-and-execute-action 'anything-c-grep-save-results
))
5177 (defun anything-c-grep-buffers-1 (candidate &optional zgrep
)
5178 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5179 If one of selected buffers is not a file--buffer,
5180 it is ignored and grep will run on all others file--buffers.
5181 If only one candidate is selected and it is not a file--buffer,
5182 switch to this buffer and run `anything-occur'.
5183 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5184 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
5187 (anything-marked-candidates)))
5188 (win-conf (current-window-configuration))
5189 ;; Non--fname buffers are ignored.
5190 (bufs (loop for buf in cands
5191 for fname
= (buffer-file-name (get-buffer buf
))
5193 collect
(expand-file-name fname
))))
5196 (anything-do-grep-1 bufs nil
'zgrep
)
5197 (anything-do-grep-1 bufs
))
5198 ;; bufs is empty, thats mean we have only CANDIDATE
5199 ;; and it is not a buffer-filename, fallback to occur.
5200 (anything-c-switch-to-buffer candidate
)
5201 (when (get-buffer anything-action-buffer
)
5202 (kill-buffer anything-action-buffer
))
5204 (when (eq anything-exit-status
1)
5205 (set-window-configuration win-conf
)))))
5207 (defun anything-c-grep-buffers (candidate)
5208 "Action to grep buffers."
5209 (anything-c-grep-buffers-1 candidate
))
5211 (defun anything-c-zgrep-buffers (candidate)
5212 "Action to zgrep buffers."
5213 (anything-c-grep-buffers-1 candidate
'zgrep
))
5216 ;;; Anything interface for pdfgrep
5217 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5218 ;; and a pdf-reader (e.g xpdf) are needed.
5220 (defvar anything-c-pdfgrep-default-command
"pdfgrep --color never -niH %s %s")
5221 (defvar anything-c-pdfgrep-default-function
'anything-c-pdfgrep-init
)
5222 (defvar anything-c-pdfgrep-debug-command-line nil
)
5224 (defun anything-c-pdfgrep-init (only-files)
5225 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5226 (let* ((fnargs (anything-c-grep-prepare-candidates
5227 (if (file-remote-p anything-ff-default-directory
)
5228 (mapcar #'(lambda (x)
5229 (file-remote-p x
'localname
))
5232 (cmd-line (format anything-c-pdfgrep-default-command
5235 (when anything-c-pdfgrep-debug-command-line
5236 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5237 (goto-char (point-max))
5238 (insert (concat ">>> " cmd-line
"\n\n"))))
5239 (setq mode-line-format
5240 '(" " mode-line-buffer-identification
" "
5241 (line-number-mode "%l") " "
5242 (:eval
(propertize "(Pdfgrep Process Running) "
5243 'face
'((:foreground
"red"))))))
5245 (let ((default-directory anything-ff-default-directory
))
5246 (start-file-process-shell-command "pdfgrep-process" nil cmd-line
))
5248 (set-process-sentinel
5249 (get-process "pdfgrep-process")
5250 #'(lambda (process event
)
5251 (when (string= event
"finished\n")
5252 (with-anything-window
5253 (anything-update-move-first-line))
5254 (force-mode-line-update nil
)))))))
5257 (defun anything-do-pdfgrep-1 (only)
5258 "Launch pdfgrep with a list of ONLY files."
5259 (unless (executable-find "pdfgrep")
5260 (error "Error: No such program `pdfgrep'."))
5261 (let* ((anything-compile-source-functions
5262 ;; rule out anything-match-plugin because the input is one regexp.
5263 (delq 'anything-compile-source--match-plugin
5264 (copy-sequence anything-compile-source-functions
)))
5265 ;; Disable match-plugin and use here own highlighting.
5266 (anything-mp-highlight-delay nil
))
5267 ;; When called as action from an other source e.g *-find-files
5268 ;; we have to kill action buffer.
5269 (when (get-buffer anything-action-buffer
)
5270 (kill-buffer anything-action-buffer
))
5271 ;; If `anything-find-files' haven't already started,
5272 ;; give a default value to `anything-ff-default-directory'.
5273 (setq anything-ff-default-directory
(or anything-ff-default-directory
5277 `(((name .
"PdfGrep")
5280 (funcall anything-c-pdfgrep-default-function only
)))
5281 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
5282 (candidate-number-limit .
9999)
5283 (mode-line . anything-pdfgrep-mode-line-string
)
5284 (action . anything-c-pdfgrep-action
)
5285 (persistent-help .
"Jump to PDF Page")
5286 (requires-pattern .
3)
5288 :keymap anything-c-pdfgrep-map
5289 :buffer
"*anything grep*")))
5292 (defun anything-c-pdfgrep-action (candidate)
5293 (let* ((split (anything-c-grep-split-line candidate
))
5294 (pageno (nth 1 split
))
5295 (fname (car split
)))
5296 (start-file-process-shell-command
5298 (format-spec anything-c-pdfgrep-default-read-command
5299 (list (cons ?f fname
) (cons ?p pageno
))))))
5301 (defun anything-do-pdfgrep ()
5303 (let ((only (anything-c-read-file-name
5304 "Search in file(s): "
5305 :marked-candidates t
5306 :test
#'(lambda (file)
5307 (or (string= (file-name-extension file
) "pdf")
5308 (string= (file-name-extension file
) "PDF")
5309 (file-directory-p file
)))
5310 :preselect
(or (dired-get-filename nil t
)
5311 (buffer-file-name (current-buffer)))))
5312 (anything-c-grep-default-function 'anything-c-pdfgrep-init
))
5313 (anything-do-pdfgrep-1 only
)))
5316 ;; Yank text at point.
5320 (defvar anything-yank-point nil
)
5323 (defun anything-yank-text-at-point ()
5324 "Yank text at point in minibuffer."
5327 (flet ((insert-in-minibuffer (word)
5328 (with-selected-window (minibuffer-window)
5329 (let ((str anything-pattern
))
5330 (delete-minibuffer-contents)
5331 (set-text-properties 0 (length word
) nil word
)
5332 (insert (concat str word
))))))
5333 (with-anything-current-buffer
5334 ;; Start to initial point if C-w have never been hit.
5335 (unless anything-yank-point
(setq anything-yank-point
(point)))
5336 (and anything-yank-point
(goto-char anything-yank-point
))
5338 (setq input
(buffer-substring-no-properties anything-yank-point
(point)))
5339 (setq anything-yank-point
(point))) ; End of last forward-word
5340 (insert-in-minibuffer input
))))
5342 (defun anything-reset-yank-point ()
5343 (setq anything-yank-point nil
))
5345 (add-hook 'anything-after-persistent-action-hook
'anything-reset-yank-point
)
5346 (add-hook 'anything-cleanup-hook
'anything-reset-yank-point
)
5352 (defvar anything-c-source-recentf
5353 '((name .
"Recentf")
5356 (or recentf-mode
(recentf-mode 1))))
5357 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5358 (candidates . recentf-list
)
5359 (match anything-c-match-on-basename
)
5361 "See (info \"(emacs)File Conveniences\").
5362 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5363 ;; (anything 'anything-c-source-recentf)
5366 (eval-when-compile (require 'ffap
))
5367 (defvar anything-c-source-ffap-guesser
5368 '((name .
"File at point")
5369 (init .
(lambda () (require 'ffap
)))
5370 (candidates .
(lambda ()
5372 (with-anything-current-buffer
5376 ;; (anything 'anything-c-source-ffap-guesser)
5378 ;;; ffap with line number
5379 (defun anything-c-ffap-file-line-at-point ()
5380 "Get (FILENAME . LINENO) at point."
5381 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5384 (when (and (search-forward it nil t
)
5385 (looking-at ":\\([0-9]+\\)"))
5386 (cons it
(string-to-number (match-string 1)))))))
5388 (defvar anything-c-ffap-line-location nil
5389 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5390 It is cleared after jumping line.")
5392 (defun anything-c-ffap-line-candidates ()
5393 (with-anything-current-buffer
5394 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
5395 (when anything-c-ffap-line-location
5396 (destructuring-bind (file . line
) anything-c-ffap-line-location
5397 (list (cons (format "%s (line %d)" file line
) file
)))))
5399 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5400 (defun anything-c-ffap-line-goto-line ()
5401 (when (car anything-c-ffap-line-location
)
5404 (with-selected-window
5406 (get-file-buffer (car anything-c-ffap-line-location
)))
5407 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
5408 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
5409 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
5411 (defvar anything-c-source-ffap-line
5412 '((name .
"File/Lineno at point")
5413 (init .
(lambda () (require 'ffap
)))
5414 (candidates . anything-c-ffap-line-candidates
)
5416 ;; (anything 'anything-c-source-ffap-line)
5418 ;;; list of files gleaned from every dired buffer
5419 (defun anything-c-files-in-all-dired-candidates ()
5423 (cond ((listp dir
) ;filelist
5425 ((equal "" (file-name-nondirectory dir
)) ;dir
5426 (directory-files dir t
))
5428 (file-expand-wildcards dir t
))))
5430 (mapcar (lambda (buf)
5432 (when (eq major-mode
'dired-mode
)
5433 (if (consp dired-directory
)
5434 (cdr dired-directory
) ;filelist
5435 dired-directory
))) ;dir or wildcard
5437 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5439 (defvar anything-c-source-files-in-all-dired
5440 '((name .
"Files in all dired buffer.")
5441 (candidates . anything-c-files-in-all-dired-candidates
)
5443 ;; (anything 'anything-c-source-files-in-all-dired)
5445 (defvar anything-c-source-filelist
5446 '((name .
"FileList")
5447 (grep-candidates . anything-c-filelist-file-name
)
5448 (candidate-number-limit .
200)
5449 (requires-pattern .
4)
5451 "Source to find files instantly.
5452 See `anything-c-filelist-file-name' docstring for usage.")
5457 (defvar anything-c-info-pages nil
5458 "All info pages on system.
5459 Will be calculated the first time you invoke anything with this
5462 (defun anything-c-info-pages-init ()
5463 "Collect candidates for initial Info node Top."
5464 (if anything-c-info-pages
5465 anything-c-info-pages
5466 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5470 (Info-find-node "dir" "top")
5471 (goto-char (point-min))
5472 (while (re-search-forward info-topic-regexp nil t
)
5473 (push (match-string-no-properties 1) topics
))
5475 (setq anything-c-info-pages topics
))))
5477 (defvar anything-c-source-info-pages
5478 `((name .
"Info Pages")
5479 (init . anything-c-info-pages-init
)
5480 (candidates . anything-c-info-pages
)
5481 (action .
(("Show with Info" .
(lambda (node-str)
5482 (info (replace-regexp-in-string
5483 "^[^:]+: " "" node-str
))))))
5484 (requires-pattern .
2)))
5485 ;; (anything 'anything-c-source-info-pages)
5488 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5489 (defun anything-c-describe-attributes (anything-attribute)
5490 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5491 Same as `anything-describe-anything-attribute' but with anything completion."
5492 (interactive (list (intern
5494 "Describe anything attribute: "
5495 (mapcar 'symbol-name anything-additional-attributes
)
5498 #'(lambda (candidate)
5499 (with-output-to-temp-buffer "*Help*"
5500 (princ (get (intern candidate
) 'anything-attrdoc
))))))))
5501 (with-output-to-temp-buffer "*Help*"
5502 (princ (get anything-attribute
'anything-attrdoc
))))
5505 ;;; Use info-index plug-in.
5508 ;; Note that `name' attribute is not needed since
5509 ;; `anything-c-insert-summary' have been removed.
5511 (defvar anything-c-source-info-elisp
5512 '((name .
"Info index: elisp")
5513 (info-index .
"elisp")))
5514 ;; (anything 'anything-c-source-info-elisp)
5517 (defvar anything-c-source-info-cl
5518 '((name .
"Info index: cl")
5519 (info-index .
"cl")))
5520 ;; (anything 'anything-c-source-info-cl)
5523 (defvar anything-c-source-info-org
5524 '((name .
"Info index: org")
5525 (info-index .
"org")))
5526 ;; (anything 'anything-c-source-info-org)
5529 (defvar anything-c-source-info-gnus
5530 '((name .
"Info index: Gnus")
5531 (info-index .
"gnus")))
5533 ;; Info Index ratpoison
5534 (defvar anything-c-source-info-ratpoison
5535 '((name .
"Info index: ratpoison")
5536 (info-index .
"ratpoison")))
5537 ;; (anything 'anything-c-source-info-ratpoison)
5540 (defvar anything-c-source-info-zsh
5541 '((name .
"Info index: zsh")
5542 (info-index .
"zsh")))
5543 ;; (anything 'anything-c-source-info-zsh)
5546 (defvar anything-c-source-info-bash
5547 '((name .
"Info index: bash")
5548 (info-index .
"bash")))
5549 ;; (anything 'anything-c-source-info-bash)
5551 ;; Info Index coreutils
5552 (defvar anything-c-source-info-coreutils
5553 '((name .
"Info index: coreutils")
5554 (info-index .
"coreutils")))
5555 ;; (anything 'anything-c-source-info-coreutils)
5557 ;; Info Index fileutils
5558 (defvar anything-c-source-info-fileutils
5559 '((name .
"Info index: fileutils")
5560 (info-index .
"fileutils")))
5561 ;; (anything 'anything-c-source-info-fileutils)
5564 (defvar anything-c-source-info-find
5565 '((name .
"Info index: find")
5566 (info-index .
"find")))
5567 ;; (anything 'anything-c-source-info-find)
5569 ;; Info Index sh-utils
5570 (defvar anything-c-source-info-sh-utils
5571 '((name .
"Info index: sh-utils")
5572 (info-index .
"sh-utils")))
5573 ;; (anything 'anything-c-source-info-sh-utils)
5575 ;; Info Index textutils
5576 (defvar anything-c-source-info-textutils
5577 '((name .
"Info index: textutils")
5578 (info-index .
"textutils")))
5579 ;; (anything 'anything-c-source-info-textutils)
5582 (defvar anything-c-source-info-libc
5583 '((name .
"Info index: libc")
5584 (info-index .
"libc")))
5585 ;; (anything 'anything-c-source-info-libc)
5588 (defvar anything-c-source-info-make
5589 '((name .
"Info index: make")
5590 (info-index .
"make")))
5591 ;; (anything 'anything-c-source-info-make)
5593 ;; Info Index automake
5594 (defvar anything-c-source-info-automake
5595 '((name .
"Info index: automake")
5596 (info-index .
"automake")))
5597 ;; (anything 'anything-c-source-info-automake)
5599 ;; Info Index autoconf
5600 (defvar anything-c-source-info-autoconf
5601 '((name .
"Info index: autoconf")
5602 (info-index .
"autoconf")))
5603 ;; (anything 'anything-c-source-info-autoconf)
5605 ;; Info Index emacs-lisp-intro
5606 (defvar anything-c-source-info-emacs-lisp-intro
5607 '((name .
"Info index: emacs-lisp-intro")
5608 (info-index .
"emacs-lisp-intro")))
5609 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5612 (defvar anything-c-source-info-emacs
5613 '((name .
"Info index: emacs")
5614 (info-index .
"emacs")))
5615 ;; (anything 'anything-c-source-info-emacs)
5618 (defvar anything-c-source-info-elib
5619 '((name .
"Info index: elib")
5620 (info-index .
"elib")))
5621 ;; (anything 'anything-c-source-info-elib)
5624 (defvar anything-c-source-info-eieio
5625 '((name .
"Info index: eieio")
5626 (info-index .
"eieio")))
5627 ;; (anything 'anything-c-source-info-eieio)
5629 ;; Info Index gauche-refe
5630 (defvar anything-c-source-info-gauche-refe
5631 '((name .
"Info index: gauche")
5632 (info-index .
"gauche-refe")))
5633 ;; (anything 'anything-c-source-info-gauche-refe)
5636 (defvar anything-c-source-info-guile
5637 '((name .
"Info index: guile")
5638 (info-index .
"guile")))
5639 ;; (anything 'anything-c-source-info-guile)
5641 ;; Info Index guile-tut
5642 (defvar anything-c-source-info-guile-tut
5643 '((name .
"Info index: guile-tut")
5644 (info-index .
"guile-tut")))
5645 ;; (anything 'anything-c-source-info-guile-tut)
5648 (defvar anything-c-source-info-goops
5649 '((name .
"Info index: goops")
5650 (info-index .
"goops")))
5651 ;; (anything 'anything-c-source-info-goops)
5653 ;; Info Index screen
5654 (defvar anything-c-source-info-screen
5655 '((name .
"Info index: screen")
5656 (info-index .
"screen")
5657 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5658 ;; (anything 'anything-c-source-info-screen)
5661 (defvar anything-c-source-info-latex
5662 '((name .
"Info index: latex")
5663 (info-index .
"latex")))
5664 ;; (anything 'anything-c-source-info-latex)
5667 (defvar anything-c-source-info-gawk
5668 '((name .
"Info index: gawk")
5669 (info-index .
"gawk")))
5670 ;; (anything 'anything-c-source-info-gawk)
5673 (defvar anything-c-source-info-sed
5674 '((name .
"Info index: sed")
5675 (info-index .
"sed")))
5676 ;; (anything 'anything-c-source-info-sed)
5679 (defvar anything-c-source-info-m4
5680 '((name .
"Info index: m4")
5681 (info-index .
"m4")))
5682 ;; (anything 'anything-c-source-info-m4)
5685 (defvar anything-c-source-info-wget
5686 '((name .
"Info index: wget")
5687 (info-index .
"wget")))
5688 ;; (anything 'anything-c-source-info-wget)
5690 ;; Info Index binutils
5691 (defvar anything-c-source-info-binutils
5692 '((name .
"Info index: binutils")
5693 (info-index .
"binutils")))
5694 ;; (anything 'anything-c-source-info-binutils)
5697 (defvar anything-c-source-info-as
5698 '((name .
"Info index: as")
5699 (info-index .
"as")))
5700 ;; (anything 'anything-c-source-info-as)
5703 (defvar anything-c-source-info-bfd
5704 '((name .
"Info index: bfd")
5705 (info-index .
"bfd")))
5706 ;; (anything 'anything-c-source-info-bfd)
5709 (defvar anything-c-source-info-gprof
5710 '((name .
"Info index: gprof")
5711 (info-index .
"gprof")))
5712 ;; (anything 'anything-c-source-info-gprof)
5715 (defvar anything-c-source-info-ld
5716 '((name .
"Info index: ld")
5717 (info-index .
"ld")))
5718 ;; (anything 'anything-c-source-info-ld)
5721 (defvar anything-c-source-info-diff
5722 '((name .
"Info index: diff")
5723 (info-index .
"diff")))
5724 ;; (anything 'anything-c-source-info-diff)
5727 (defvar anything-c-source-info-flex
5728 '((name .
"Info index: flex")
5729 (info-index .
"flex")))
5730 ;; (anything 'anything-c-source-info-flex)
5733 (defvar anything-c-source-info-grep
5734 '((name .
"Info index: grep")
5735 (info-index .
"grep")))
5736 ;; (anything 'anything-c-source-info-grep)
5739 (defvar anything-c-source-info-gzip
5740 '((name .
"Info index: gzip")
5741 (info-index .
"gzip")))
5742 ;; (anything 'anything-c-source-info-gzip)
5744 ;; Info Index libtool
5745 (defvar anything-c-source-info-libtool
5746 '((name .
"Info index: libtool")
5747 (info-index .
"libtool")))
5748 ;; (anything 'anything-c-source-info-libtool)
5750 ;; Info Index texinfo
5751 (defvar anything-c-source-info-texinfo
5752 '((name .
"Info index: texinfo")
5753 (info-index .
"texinfo")))
5754 ;; (anything 'anything-c-source-info-texinfo)
5757 (defvar anything-c-source-info-info
5758 '((name .
"Info index: info")
5759 (info-index .
"info")))
5760 ;; (anything 'anything-c-source-info-info)
5763 (defvar anything-c-source-info-gdb
5764 '((name .
"Info index: gdb")
5765 (info-index .
"gdb")))
5766 ;; (anything 'anything-c-source-info-gdb)
5769 (defvar anything-c-source-info-stabs
5770 '((name .
"Info index: stabs")
5771 (info-index .
"stabs")))
5772 ;; (anything 'anything-c-source-info-stabs)
5774 ;; Info Index cvsbook
5775 (defvar anything-c-source-info-cvsbook
5776 '((name .
"Info index: cvsbook")
5777 (info-index .
"cvsbook")))
5778 ;; (anything 'anything-c-source-info-cvsbook)
5781 (defvar anything-c-source-info-cvs
5782 '((name .
"Info index: cvs")
5783 (info-index .
"cvs")))
5784 ;; (anything 'anything-c-source-info-cvs)
5787 (defvar anything-c-source-info-bison
5788 '((name .
"Info index: bison")
5789 (info-index .
"bison")))
5790 ;; (anything 'anything-c-source-info-bison)
5792 ;; Info Index id-utils
5793 (defvar anything-c-source-info-id-utils
5794 '((name .
"Info index: id-utils")
5795 (info-index .
"id-utils")))
5796 ;; (anything 'anything-c-source-info-id-utils)
5798 ;; Info Index global
5799 (defvar anything-c-source-info-global
5800 '((name .
"Info index: global")
5801 (info-index .
"global")))
5802 ;; (anything 'anything-c-source-info-global)
5805 ;;; Man and woman UI
5808 (defvar anything-c-man-pages nil
5809 "All man pages on system.
5810 Will be calculated the first time you invoke anything with this
5813 (defun anything-c-man-default-action (candidate)
5814 "Default action for jumping to a woman or man page from anything."
5815 (let ((wfiles (woman-file-name-all-completions candidate
)))
5817 (if (> (length wfiles
) 1)
5820 "ManFile: " wfiles
:must-match t
))
5822 ;; If woman is unable to format correctly
5824 (error (kill-buffer) ; Kill woman buffer.
5825 (let ((Man-notify-method 'meek
))
5826 (Man-getpage-in-background candidate
))))))
5828 (defvar anything-c-source-man-pages
5829 `((name .
"Manual Pages")
5830 (candidates .
(lambda ()
5831 (if anything-c-man-pages
5832 anything-c-man-pages
5833 ;; XEmacs doesn't have a woman :)
5834 (setq anything-c-man-pages
5837 (woman-file-name "")
5838 (sort (mapcar 'car woman-topic-all-completions
)
5840 (action ("Show with Woman" . anything-c-man-default-action
))
5841 ;; Woman does not work OS X
5842 ;; http://xahlee.org/emacs/modernization_man_page.html
5843 (action-transformer .
(lambda (actions candidate
)
5844 (if (eq system-type
'darwin
)
5845 '(("Show with Man" . man
))
5847 (requires-pattern .
2)))
5848 ;; (anything 'anything-c-source-man-pages)
5852 ;;; Anything M-x - Enhanced M-x UI
5855 ;; Another replacement of `M-x' that act exactly like the
5856 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5857 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5858 ;; anything invocation.
5859 ;; Documentation of commands available without quitting,
5860 ;; Show keybindings of commands.
5862 (defvar anything-M-x-input-history nil
)
5864 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
5865 "Return alist of MODE-MAP."
5866 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
5867 for str-key
= (key-description key
)
5868 for ismenu
= (string-match "<menu-bar>" str-key
)
5869 unless ismenu collect
(cons str-key com
)))
5871 (defun anything-get-mode-map-from-mode (mode)
5872 "Guess the mode-map name according to MODE.
5873 Some modes don't use conventional mode-map name
5874 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5875 Return nil if no mode-map found."
5877 ;; Start with a conventional mode-map name.
5878 with mode-map
= (intern-soft (format "%s-map" mode
))
5879 with mode-string
= (symbol-name mode
)
5880 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
5881 while
(not mode-map
)
5882 for count downfrom
(length mode-name
)
5883 ;; Return when no result after parsing entire string.
5884 when
(eq count
0) return nil
5885 for sub-name
= (substring mode-name
0 count
)
5886 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
5887 finally return mode-map
))
5889 (defun anything-M-x-current-mode-map-alist ()
5890 "Return mode-map alist of current `major-mode'."
5891 (let ((map (anything-get-mode-map-from-mode major-mode
)))
5892 (when (and map
(boundp map
))
5893 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
5896 (defun anything-M-x-transformer (candidates sources
)
5897 "filtered-candidate-transformer to show bindings in emacs commands.
5898 Show global bindings and local bindings according to current `major-mode'."
5899 (with-anything-current-buffer
5901 with local-map
= (anything-M-x-current-mode-map-alist)
5902 for cand in candidates
5903 for local-key
= (car (rassq cand local-map
))
5904 for key
= (substitute-command-keys (format "\\[%s]" cand
))
5906 (cons (cond ((and (string-match "^M-x" key
) local-key
)
5910 'face
'anything-M-x-key-face
)))
5911 ((string-match "^M-x" key
) cand
)
5912 (t (format "%s (%s)"
5915 'face
'anything-M-x-key-face
))))
5918 (sort ls
#'(lambda (x y
) (string-lessp (car x
) (car y
)))))))
5921 ;;; Complex command history
5924 (defvar anything-c-source-complex-command-history
5925 '((name .
"Complex Command History")
5926 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
5928 ;; (anything 'anything-c-source-complex-command-history)
5930 ;;; M-x history (not related to `anything-M-x')
5933 (defvar anything-c-source-extended-command-history
5934 '((name .
"Emacs Commands History")
5935 (candidates . extended-command-history
)
5937 ;; (anything 'anything-c-source-extended-command-history)
5939 ;;; Emacs commands (Basic source for emacs commands)
5942 (defvar anything-c-source-emacs-commands
5943 '((name .
"Emacs Commands")
5944 (candidates .
(lambda ()
5946 (mapatoms (lambda (a)
5948 (push (symbol-name a
)
5950 (sort commands
'string-lessp
))))
5952 (requires-pattern .
2))
5953 "Source for completing and invoking Emacs commands.
5954 A command is a function with interactive spec that can
5955 be invoked with `M-x'.
5957 To get non-interactive functions listed, use
5958 `anything-c-source-emacs-functions'.")
5959 ;; (anything 'anything-c-source-emacs-commands)
5966 (defvar anything-c-source-emacs-functions
5967 '((name .
"Emacs Functions")
5968 (candidates .
(lambda ()
5970 (mapatoms (lambda (a)
5972 (push (symbol-name a
) commands
))))
5973 (sort commands
'string-lessp
))))
5975 (requires-pattern .
2))
5976 "Source for completing Emacs functions.")
5977 ;; (anything 'anything-c-source-emacs-functions)
5979 ;;; With abbrev expansion
5980 ;;; Similar to my exec-abbrev-cmd.el
5981 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5982 (defvar anything-c-function-abbrev-regexp nil
5983 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5984 Regexp built from the current `anything-pattern' interpreting it
5986 Only for internal use.")
5988 (defun anything-c-match-function-by-abbrev (candidate)
5989 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5991 Abbreviations are made by taking the first character from each
5992 word in the function's name, e.g. \"bb\" is an abbrev for
5993 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5994 (string-match anything-c-function-abbrev-regexp candidate
))
5996 (defvar anything-c-source-emacs-functions-with-abbrevs
5997 (append anything-c-source-emacs-functions
5998 '((match anything-c-match-function-by-abbrev
5999 anything-c-string-match
))
6002 (defadvice anything-update
6003 (before anything-c-update-function-abbrev-regexp activate
)
6004 (let ((char-list (append anything-pattern nil
))
6006 (dolist (c char-list
)
6007 (setq str
(concat str
(list c
) "[^-]*-")))
6008 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
6009 (setq anything-c-function-abbrev-regexp str
))))))))
6010 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6012 (defvar anything-c-source-advice
6013 '((name .
"Function Advice")
6014 (candidates . anything-c-advice-candidates
)
6015 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
6016 (persistent-action . anything-c-advice-persistent-action
)
6018 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
6019 ;; (anything 'anything-c-source-advice)
6020 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6023 (defun anything-c-advice-candidates ()
6025 (loop for
(fname) in ad-advised-functions
6026 for function
= (intern fname
)
6028 (loop for class in ad-advice-classes append
6029 (loop for advice in
(ad-get-advice-info-field function class
)
6030 for enabled
= (ad-advice-enabled advice
)
6034 (if enabled
"Enabled " "Disabled")
6035 (propertize fname
'face
'font-lock-function-name-face
)
6036 (ad-make-single-advice-docstring advice class nil
))
6037 (list function class advice
))))))
6039 (defun anything-c-advice-persistent-action (func-class-advice)
6040 (if current-prefix-arg
6041 (anything-c-advice-toggle func-class-advice
)
6042 (describe-function (car func-class-advice
))))
6044 (defun anything-c-advice-toggle (func-class-advice)
6045 (destructuring-bind (function class advice
) func-class-advice
6046 (cond ((ad-advice-enabled advice
)
6047 (ad-advice-set-enabled advice nil
)
6048 (message "Disabled"))
6050 (ad-advice-set-enabled advice t
)
6051 (message "Enabled")))
6052 (ad-activate function
)
6053 (and anything-in-persistent-action
6054 (anything-c-advice-update-current-display-string))))
6056 (defun anything-c-advice-update-current-display-string ()
6057 (anything-edit-current-selection
6058 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6059 ((looking-at "Enabled") "Disabled")))
6062 (delete-region (point) (progn (forward-word 1) (point)))
6063 (insert newword
)))))
6070 (defvar anything-c-source-emacs-variables
6071 '((name .
"Emacs Variables")
6072 (candidates .
(lambda ()
6073 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
6075 (requires-pattern .
2))
6076 "Source for completing Emacs variables.")
6077 ;; (anything 'anything-c-source-emacs-variables)
6081 (defvar anything-c-source-lacarte
6082 '((name .
"Lacarte")
6083 (init .
(lambda () (require 'lacarte
)))
6084 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6085 (candidate-number-limit .
9999)
6086 (action . anything-c-call-interactively
))
6089 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6090 ;; (anything 'anything-c-source-lacarte)
6096 ;; Bind some faces for bookmarks.
6097 (defvar anything-c-bookmarks-face1
'anything-ff-directory
)
6098 (defvar anything-c-bookmarks-face2
'anything-ff-file
)
6099 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
6101 (eval-when-compile (require 'bookmark
))
6102 (defvar anything-c-source-bookmarks
6103 '((name .
"Bookmarks")
6105 (require 'bookmark
)))
6106 (candidates . bookmark-all-names
)
6108 "See (info \"(emacs)Bookmarks\").")
6109 ;; (anything 'anything-c-source-bookmarks)
6112 (defvar anything-c-source-bookmark-set
6113 '((name .
"Set Bookmark")
6115 (action . bookmark-set
))
6116 "See (info \"(emacs)Bookmarks\").")
6117 ;; (anything 'anything-c-source-bookmark-set)
6119 ;;; Visible Bookmarks
6120 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6123 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6124 (defvar anything-c-source-bm
6125 '((name .
"Visible Bookmarks")
6126 (init . anything-c-bm-init
)
6127 (candidates-in-buffer)
6131 http://www.nongnu.org/bm/")
6133 (defun anything-c-bm-init ()
6134 "Init function for `anything-c-source-bm'."
6135 (when (require 'bm nil t
)
6137 (let ((bookmarks (bm-lists))
6138 (buf (anything-candidate-buffer 'global
)))
6139 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
6140 '< :key
'overlay-start
))
6141 (let ((start (overlay-start bm
))
6142 (end (overlay-end bm
))
6143 (annotation (or (overlay-get bm
'annotation
) "")))
6144 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
6145 (let ((str (format "%5d: [%s]: %s\n"
6146 (line-number-at-pos start
)
6148 (buffer-substring start
(1- end
)))))
6149 (with-current-buffer buf
(insert str
))))))))))
6151 ;;; Special bookmarks
6152 (defvar anything-c-source-bookmarks-ssh
6153 '((name .
"Bookmarks-ssh")
6155 (require 'bookmark
)))
6156 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
6158 "See (info \"(emacs)Bookmarks\").")
6159 ;; (anything 'anything-c-source-bookmarks-ssh)
6161 (defvar anything-c-source-bookmarks-su
6162 '((name .
"Bookmarks-root")
6164 (require 'bookmark
)))
6165 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
6166 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
6169 "See (info \"(emacs)Bookmarks\").")
6170 ;; (anything 'anything-c-source-bookmarks-su)
6172 (defvar anything-c-source-bookmarks-local
6173 '((name .
"Bookmarks-Local")
6175 (require 'bookmark
)))
6176 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
6177 (filtered-candidate-transformer
6178 anything-c-adaptive-sort
6179 anything-c-highlight-bookmark
)
6181 "See (info \"(emacs)Bookmarks\").")
6182 ;; (anything 'anything-c-source-bookmarks-local)
6184 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
6185 (let* ((lis-all (bookmark-all-names))
6186 (lis-loc (cond (local (loop for i in lis-all
6187 unless
(string-match "^(ssh)\\|^(su)" i
)
6189 (su (loop for i in lis-all
6190 when
(string-match "^(su)" i
)
6192 (sudo (loop for i in lis-all
6193 when
(string-match "^(sudo)" i
)
6195 (ssh (loop for i in lis-all
6196 when
(string-match "^(ssh)" i
)
6198 (sort lis-loc
'string-lessp
)))
6200 (defun anything-c-bookmark-root-logged-p ()
6202 (dolist (i (mapcar #'buffer-name
(buffer-list)))
6203 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
6204 (throw 'break t
)))))
6206 (defun anything-c-highlight-bookmark-su (files source
)
6207 (if (anything-c-bookmark-root-logged-p)
6208 (anything-c-highlight-bookmark files source
)
6209 (anything-c-highlight-not-logged files source
)))
6211 (defun anything-c-highlight-not-logged (files source
)
6212 (loop for i in files
6213 collect
(propertize i
'face anything-c-bookmarks-face3
)))
6215 (defun anything-c-highlight-bookmark (bookmarks source
)
6216 "Used as `candidate-transformer' to colorize bookmarks.
6217 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6218 (loop for i in bookmarks
6219 for isfile
= (bookmark-get-filename i
)
6220 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
6221 (bmkext-get-buffer-name i
))
6222 for handlerp
= (and (fboundp 'bookmark-get-handler
)
6223 (bookmark-get-handler i
))
6224 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
6225 (bmkext-w3m-bookmark-p i
))
6226 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
6227 (bmkext-gnus-bookmark-p i
))
6228 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
6229 (bmkext-man-bookmark-p i
))
6230 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
6231 (bmkext-woman-bookmark-p i
))
6232 for handlerp
= (bookmark-get-handler i
)
6233 for isannotation
= (bookmark-get-annotation i
)
6234 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
6235 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
6236 ;; Add a * if bookmark have annotation
6237 if
(and isannotation
(not (string-equal isannotation
"")))
6238 do
(setq i
(concat "*" i
))
6239 collect
(cond (;; info buffers
6241 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
6244 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
6247 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
6250 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
6253 (propertize i
'face
'((:foreground
"Tomato"))))
6255 (and isfile
(file-directory-p isfile
))
6256 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
6259 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
6263 ;;; Sources to filter bookmark-extensions bookmarks.
6266 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6267 ;; If you want to enable google-maps in addressbook you will need
6268 ;; Julien Danjou google-maps-el package available here:
6269 ;; http://julien.danjou.info/google-maps-el.html
6271 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
6272 "Return a filtered `bookmark-alist' sorted alphabetically."
6274 with alist
= (if args
6275 (apply #'(lambda (x) (funcall fn x
)) args
)
6280 finally return
(sort sa
'string-lessp
)))
6285 (defvar anything-c-source-bmkext-addressbook
6286 '((name .
"Bookmark Addressbook")
6288 (require 'bookmark-extensions
)
6289 (bookmark-maybe-load-default-file)))
6290 (candidates . anything-c-bmkext-addressbook-setup-alist
)
6292 .
(lambda (candidate)
6293 (let ((bmk (anything-bookmark-get-bookmark-from-name
6295 (bookmark--jump-via bmk
'pop-to-buffer
))))
6296 (persistent-help .
"Show contact - Prefix with C-u to append")
6297 (filtered-candidate-transformer
6298 anything-c-adaptive-sort
6299 anything-c-highlight-bookmark
)
6300 (action .
(("Show Contact(s)"
6301 .
(lambda (candidate)
6302 (let* ((contacts (anything-marked-candidates))
6303 (current-prefix-arg (or anything-current-prefix-arg
6304 (> (length contacts
) 1))))
6306 (anything-bookmark-get-bookmark-from-name (car contacts
)))
6307 (anything-aif (cdr contacts
)
6308 (loop for bmk in it do
6310 (anything-bookmark-get-bookmark-from-name bmk
)))))))
6312 .
(lambda (candidate)
6313 (let* ((contacts (anything-marked-candidates))
6314 (bmk (anything-bookmark-get-bookmark-from-name
6316 (append (message-buffers)))
6318 (addressbook-set-mail-buffer1 bmk
'append
)
6319 (addressbook-set-mail-buffer1 bmk
))
6320 (setq contacts
(cdr contacts
))
6322 (loop for bmk in contacts do
6323 (addressbook-set-mail-buffer1 bmk
'append
))))))
6325 .
(lambda (candidate)
6326 (let ((bmk (anything-bookmark-get-bookmark-from-name
6328 (addressbook-bookmark-edit
6329 (assoc bmk bookmark-alist
)))))
6330 ("Insert Email at point"
6331 .
(lambda (candidate)
6332 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6334 (mlist (split-string
6336 'email
(assoc bmk bookmark-alist
))
6339 (if (> (length mlist
) 1)
6341 "Insert Mail Address: " mlist
:must-match t
)
6344 .
(lambda (candidate)
6345 (let ((bmk (anything-bookmark-get-bookmark-from-name
6347 (bookmark-show-annotation bmk
))))
6349 .
(lambda (candidate)
6350 (let ((bmk (anything-bookmark-get-bookmark-from-name
6352 (bookmark-edit-annotation bmk
))))
6354 .
(lambda (candidate)
6355 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6357 (full-bmk (assoc bmk bookmark-alist
)))
6358 (addressbook-google-map full-bmk
))))))))
6361 (defun anything-c-bmkext-addressbook-setup-alist ()
6362 "Specialized filter function for bookmarks w3m."
6363 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
6365 ;; W3m bookmarks from bookmark-extensions.
6366 (defvar anything-c-source-bookmark-w3m
6367 '((name .
"Bookmark W3m")
6369 (require 'bookmark-extensions
)
6370 (bookmark-maybe-load-default-file)))
6371 (candidates . anything-c-bookmark-w3m-setup-alist
)
6372 (filtered-candidate-transformer
6373 anything-c-adaptive-sort
6374 anything-c-highlight-bookmark
)
6376 ;; (anything 'anything-c-source-bookmark-w3m)
6378 (defun anything-c-bookmark-w3m-setup-alist ()
6379 "Specialized filter function for bookmarks w3m."
6380 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
6383 (defvar anything-c-source-bookmark-images
6384 '((name .
"Bookmark Images")
6386 (require 'bookmark-extensions
)
6387 (bookmark-maybe-load-default-file)))
6388 (candidates . anything-c-bookmark-images-setup-alist
)
6389 (filtered-candidate-transformer
6390 anything-c-adaptive-sort
6391 anything-c-highlight-bookmark
)
6393 ;; (anything 'anything-c-source-bookmark-images)
6395 (defun anything-c-bookmark-images-setup-alist ()
6396 "Specialized filter function for images bookmarks."
6397 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
6400 (defvar anything-c-source-bookmark-man
6401 '((name .
"Bookmark Woman&Man")
6403 (require 'bookmark-extensions
)
6404 (bookmark-maybe-load-default-file)))
6405 (candidates . anything-c-bookmark-man-setup-alist
)
6406 (filtered-candidate-transformer
6407 anything-c-adaptive-sort
6408 anything-c-highlight-bookmark
)
6410 ;; (anything 'anything-c-source-bookmark-man)
6412 (defun anything-c-bookmark-man-setup-alist ()
6413 "Specialized filter function for bookmarks w3m."
6414 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
6415 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
6418 (defvar anything-c-source-bookmark-gnus
6419 '((name .
"Bookmark Gnus")
6421 (require 'bookmark-extensions
)
6422 (bookmark-maybe-load-default-file)))
6423 (candidates . anything-c-bookmark-gnus-setup-alist
)
6424 (filtered-candidate-transformer
6425 anything-c-adaptive-sort
6426 anything-c-highlight-bookmark
)
6428 ;; (anything 'anything-c-source-bookmark-gnus)
6430 (defun anything-c-bookmark-gnus-setup-alist ()
6431 "Specialized filter function for bookmarks gnus."
6432 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
6435 (defvar anything-c-source-bookmark-info
6436 '((name .
"Bookmark Info")
6438 (require 'bookmark-extensions
)
6439 (bookmark-maybe-load-default-file)))
6440 (candidates . anything-c-bookmark-info-setup-alist
)
6441 (filtered-candidate-transformer
6442 anything-c-adaptive-sort
6443 anything-c-highlight-bookmark
)
6445 ;; (anything 'anything-c-source-bookmark-info)
6447 (defun anything-c-bookmark-info-setup-alist ()
6448 "Specialized filter function for bookmarks info."
6449 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
6451 ;; Local Files&directories
6452 (defvar anything-c-source-bookmark-files
&dirs
6453 '((name .
"Bookmark Files&Directories")
6455 (require 'bookmark-extensions
)
6456 (bookmark-maybe-load-default-file)))
6457 (candidates . anything-c-bookmark-local-files-setup-alist
)
6458 (filtered-candidate-transformer
6459 anything-c-adaptive-sort
6460 anything-c-highlight-bookmark
)
6462 ;; (anything 'anything-c-source-bookmark-files&dirs)
6464 (defun anything-c-bookmark-local-files-setup-alist ()
6465 "Specialized filter function for bookmarks locals files."
6466 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
6468 ;; Su Files&directories
6469 (defvar anything-c-source-bookmark-su-files
&dirs
6470 '((name .
"Bookmark Root-Files&Directories")
6472 (require 'bookmark-extensions
)
6473 (bookmark-maybe-load-default-file)))
6474 (candidates . anything-c-bookmark-su-files-setup-alist
)
6475 (filtered-candidate-transformer
6476 anything-c-adaptive-sort
6477 anything-c-highlight-bookmark-su
)
6479 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6481 (defun anything-c-bookmark-su-files-setup-alist ()
6482 "Specialized filter function for bookmarks su/sudo files."
6483 (declare (special bmkext-su-or-sudo-regexp
))
6485 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6487 for isfile
= (bookmark-get-filename i
)
6488 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
6490 (string-match tramp-file-name-regexp isfile
)))
6491 for issu
= (and istramp
6492 (string-match bmkext-su-or-sudo-regexp isfile
))
6496 ;; Ssh Files&directories
6497 (defvar anything-c-source-bookmark-ssh-files
&dirs
6498 '((name .
"Bookmark Ssh-Files&Directories")
6500 (require 'bookmark-extensions
)
6501 (bookmark-maybe-load-default-file)))
6502 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
6503 (filtered-candidate-transformer . anything-c-adaptive-sort
)
6505 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6507 (defun anything-c-bookmark-ssh-files-setup-alist ()
6508 "Specialized filter function for bookmarks ssh files."
6510 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6512 for isfile
= (bookmark-get-filename i
)
6513 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
6515 (string-match tramp-file-name-regexp isfile
)))
6516 for isssh
= (and istramp
6517 (string-match "/ssh:" isfile
))
6523 ;;; Firefox bookmarks
6526 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6527 ;; (only for firefox versions >=3)
6528 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6530 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6531 ;; You should have now:
6532 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6534 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6535 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
6537 (defun anything-get-firefox-user-init-dir ()
6538 "Guess the default Firefox user directory name."
6539 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6541 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
6542 (goto-char (point-min))
6544 (when (search-forward "Path=" nil t
)
6545 (buffer-substring-no-properties (point) (point-at-eol)))
6547 (file-name-as-directory (concat moz-dir moz-user-dir
))))
6549 (defun anything-guess-firefox-bookmark-file ()
6550 "Return the path of the Firefox bookmarks file."
6551 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6553 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
6554 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6555 (let (bookmarks-alist url title
)
6557 (insert-file-contents file
)
6558 (goto-char (point-min))
6559 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
6561 (when (re-search-forward url-regexp nil t
)
6562 (setq url
(match-string 0)))
6563 (when (re-search-forward bmk-regexp nil t
)
6564 (setq title
(match-string 1)))
6565 (push (cons title url
) bookmarks-alist
)
6567 (nreverse bookmarks-alist
)))
6569 (defvar anything-c-firefox-bookmarks-alist nil
)
6570 (defvar anything-c-source-firefox-bookmarks
6571 '((name .
"Firefox Bookmarks")
6573 (setq anything-c-firefox-bookmarks-alist
6574 (anything-html-bookmarks-to-alist
6575 (anything-guess-firefox-bookmark-file)
6576 anything-firefox-bookmark-url-regexp
6577 anything-firefox-bookmarks-regexp
))))
6578 (candidates .
(lambda ()
6579 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
6580 (filtered-candidate-transformer
6581 anything-c-adaptive-sort
6582 anything-c-highlight-firefox-bookmarks
)
6583 (action .
(("Browse Url Firefox"
6584 .
(lambda (candidate)
6586 (anything-c-firefox-bookmarks-get-value candidate
))))
6588 .
(lambda (candidate)
6590 (anything-c-firefox-bookmarks-get-value candidate
))))
6593 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
6595 ;; (anything 'anything-c-source-firefox-bookmarks)
6597 (defun anything-c-firefox-bookmarks-get-value (elm)
6598 (assoc-default elm anything-c-firefox-bookmarks-alist
))
6600 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
6601 (loop for i in bookmarks
6603 i
'face
'((:foreground
"YellowGreen"))
6604 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
6608 ;;; W3m bookmark - anything interface.
6611 ;; Some users have the emacs-w3m library in load-path
6612 ;; without having the w3m executable :-;
6613 ;; So check if w3m program is present before trying to load
6616 (when (executable-find "w3m")
6617 (require 'w3m-bookmark nil t
)))
6619 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html")
6620 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
6621 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6622 (defvar anything-c-w3m-bookmarks-alist nil
)
6623 (defvar anything-c-source-w3m-bookmarks
6624 '((name .
"W3m Bookmarks")
6626 (setq anything-c-w3m-bookmarks-alist
6627 (anything-html-bookmarks-to-alist
6629 anything-w3m-bookmark-url-regexp
6630 anything-w3m-bookmarks-regexp
))))
6631 (candidates .
(lambda ()
6632 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
6633 (filtered-candidate-transformer
6634 anything-c-adaptive-sort
6635 anything-c-highlight-w3m-bookmarks
)
6636 (action .
(("Browse Url"
6637 .
(lambda (candidate)
6638 (anything-c-w3m-browse-bookmark candidate
)))
6641 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
6642 ("Browse Url Firefox"
6643 .
(lambda (candidate)
6644 (anything-c-w3m-browse-bookmark candidate t
)))
6646 .
(lambda (candidate)
6647 (anything-c-w3m-delete-bookmark candidate
)))
6649 .
(lambda (candidate)
6650 (anything-c-w3m-rename-bookmark candidate
)))))
6651 (persistent-action .
(lambda (candidate)
6652 (if current-prefix-arg
6653 (anything-c-w3m-browse-bookmark candidate t
)
6654 (anything-c-w3m-browse-bookmark candidate nil t
))))
6655 (persistent-help .
"Open URL with emacs-w3m in new tab / \
6656 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6657 "Needs w3m and emacs-w3m.
6659 http://w3m.sourceforge.net/
6660 http://emacs-w3m.namazu.org/")
6662 ;; (anything 'anything-c-source-w3m-bookmarks)
6664 (defun anything-c-w3m-bookmarks-get-value (elm)
6665 (replace-regexp-in-string
6666 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
6668 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
6669 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
6670 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
6671 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
6673 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
6674 (loop for i in bookmarks
6676 i
'face
'anything-w3m-bookmarks-face
6677 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
6680 (defun anything-c-w3m-delete-bookmark (elm)
6681 "Delete w3m bookmark from `w3m-bookmark-file'."
6682 (with-current-buffer
6683 (find-file-literally w3m-bookmark-file
)
6684 (goto-char (point-min))
6685 (when (re-search-forward elm nil t
)
6687 (delete-region (point)
6688 (line-end-position))
6689 (delete-blank-lines))
6693 (defun anything-c-w3m-rename-bookmark (elm)
6694 "Rename w3m bookmark in `w3m-bookmark-file'."
6695 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
6696 (new-title (read-string "NewTitle: " old-title
)))
6697 (with-current-buffer
6698 (find-file-literally w3m-bookmark-file
)
6699 (goto-char (point-min))
6700 (when (re-search-forward (concat elm
"<") nil t
)
6701 (goto-char (1- (point)))
6702 (delete-char (- (length old-title
)))
6709 ;;; Elisp library scan
6712 (defvar anything-c-source-elisp-library-scan
6713 '((name .
"Elisp libraries (Scan)")
6714 (init .
(anything-c-elisp-library-scan-init))
6715 (candidates-in-buffer)
6716 (action ("Find library"
6717 .
(lambda (candidate) (find-file (find-library-name candidate
))))
6718 ("Find library other window"
6719 .
(lambda (candidate)
6720 (find-file-other-window (find-library-name candidate
))))
6722 .
(lambda (candidate) (load-library candidate
))))))
6723 ;; (anything 'anything-c-source-elisp-library-scan)
6725 (defun anything-c-elisp-library-scan-init ()
6726 "Init anything buffer status."
6727 (let ((anything-buffer (anything-candidate-buffer 'global
))
6728 (library-list (anything-c-elisp-library-scan-list)))
6729 (with-current-buffer anything-buffer
6730 (dolist (library library-list
)
6731 (insert (format "%s\n" library
))))))
6733 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
6734 "Do completion for file names passed to `locate-file'.
6735 DIRS is directory to search path.
6736 STRING is string to match."
6737 ;; Use `load-path' as path when ignore `dirs'.
6738 (or dirs
(setq dirs load-path
))
6739 ;; Init with blank when ignore `string'.
6740 (or string
(setq string
""))
6741 ;; Get library list.
6742 (let ((string-dir (file-name-directory string
))
6743 ;; File regexp that suffix match `load-file-rep-suffixes'.
6744 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
6749 (setq dir default-directory
))
6751 (setq dir
(expand-file-name string-dir dir
)))
6752 (when (file-directory-p dir
)
6753 (dolist (file (file-name-all-completions
6754 (file-name-nondirectory string
) dir
))
6755 ;; Suffixes match `load-file-rep-suffixes'.
6756 (setq name
(if string-dir
(concat string-dir file
) file
))
6757 (if (string-match match-regexp name
)
6758 (add-to-list 'names name
)))))
6769 (defvar anything-c-imenu-delimiter
" / ")
6771 (defvar anything-c-imenu-index-filter nil
)
6772 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
6774 (defvar anything-c-cached-imenu-alist nil
)
6775 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
6777 (defvar anything-c-cached-imenu-candidates nil
)
6778 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
6780 (defvar anything-c-cached-imenu-tick nil
)
6781 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
6783 (eval-when-compile (require 'imenu
))
6784 (setq imenu-auto-rescan t
)
6786 (defun anything-imenu-create-candidates (entry)
6787 "Create candidates with ENTRY."
6788 (if (listp (cdr entry
))
6791 (if (consp (cdr sub
))
6794 (concat (car entry
) anything-c-imenu-delimiter subentry
))
6795 (anything-imenu-create-candidates sub
))
6796 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
6800 (defvar anything-c-source-imenu
6802 (init .
(lambda () (require 'imenu
)))
6803 (candidates . anything-c-imenu-candidates
)
6804 (persistent-action .
(lambda (elm)
6805 (anything-c-imenu-default-action elm
)
6806 (unless (fboundp 'semantic-imenu-tag-overlay
)
6807 (anything-match-line-color-current-line))))
6808 (persistent-help .
"Show this entry")
6809 (action . anything-c-imenu-default-action
))
6810 "See (info \"(emacs)Imenu\")")
6812 ;; (anything 'anything-c-source-imenu)
6814 (defun anything-c-imenu-candidates ()
6815 (with-anything-current-buffer
6816 (let ((tick (buffer-modified-tick)))
6817 (if (eq anything-c-cached-imenu-tick tick
)
6818 anything-c-cached-imenu-candidates
6819 (setq imenu--index-alist nil
)
6820 (setq anything-c-cached-imenu-tick tick
6821 anything-c-cached-imenu-candidates
6824 'anything-imenu-create-candidates
6825 (setq anything-c-cached-imenu-alist
6826 (let ((index (imenu--make-index-alist)))
6827 (if anything-c-imenu-index-filter
6828 (funcall anything-c-imenu-index-filter index
)
6830 (setq anything-c-cached-imenu-candidates
6831 (mapcar #'(lambda (x)
6835 anything-c-cached-imenu-candidates
))))))
6837 (setq imenu-default-goto-function
'imenu-default-goto-function
)
6838 (defun anything-c-imenu-default-action (elm)
6839 "The default action for `anything-c-source-imenu'."
6840 (let ((path (split-string elm anything-c-imenu-delimiter
))
6841 (alist anything-c-cached-imenu-alist
))
6843 (setq alist
(assoc elm alist
)))
6851 (defvar anything-c-ctags-modes
6852 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6853 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6854 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
6856 (defun anything-c-source-ctags-init ()
6857 (when (and buffer-file-name
6858 (memq major-mode anything-c-ctags-modes
)
6859 (anything-current-buffer-is-modified))
6860 (with-current-buffer (anything-candidate-buffer 'local
)
6861 (call-process-shell-command
6862 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
6863 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6864 anything-buffer-file-name
)
6865 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
6866 nil
(current-buffer))
6867 (goto-char (point-min))
6869 (delete-region (point-min) (point))
6870 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
6871 for lineno-start
= (point)
6872 for lineno
= (buffer-substring
6874 (1- (search-forward "," (point-at-eol) t
)))
6877 (insert (format "%5s:" lineno
))
6878 (search-forward "\177" (point-at-eol) t
)
6879 (delete-region (1- (point)) (point-at-eol))
6880 (forward-line 1)))))
6882 (defvar anything-c-source-ctags
6883 '((name .
"Exuberant ctags")
6884 (init . anything-c-source-ctags-init
)
6885 (candidates-in-buffer)
6888 "Needs Exuberant Ctags.
6890 http://ctags.sourceforge.net/")
6891 ;; (anything 'anything-c-source-ctags)
6897 ;; anything-etags.el is deprecated, if this file is found,
6898 ;; warn user at compile time.
6900 (when (locate-library "anything-etags.el")
6903 "You are using obsolete library `anything-etags.el' and should remove it."
6906 (defvar anything-c-etags-tag-file-dir nil
6907 "Etags file directory.")
6908 (defvar anything-c-etags-mtime-alist nil
6909 "Store the last modification time of etags files here.")
6910 (defvar anything-c-etags-cache
(make-hash-table :test
'equal
)
6911 "Cache content of etags files used here for faster access.")
6913 (defun anything-c-etags-get-tag-file (&optional directory
)
6914 "Return the path of etags file if found."
6915 ;; Get tag file from `default-directory' or upper directory.
6916 (let ((current-dir (anything-c-etags-find-tag-file-directory
6917 (or directory default-directory
))))
6918 ;; Return nil if not find tag file.
6920 ;; Set tag file directory.
6921 (setq anything-c-etags-tag-file-dir current-dir
)
6922 (expand-file-name anything-c-etags-tag-file-name current-dir
))))
6924 (defun anything-c-etags-find-tag-file-directory (current-dir)
6925 "Try to find the directory containing tag file.
6926 If not found in CURRENT-DIR search in upper directory."
6927 (flet ((file-exists?
(dir)
6928 (let ((tag-path (expand-file-name
6929 anything-c-etags-tag-file-name dir
)))
6930 (and (stringp tag-path
)
6931 (file-exists-p tag-path
)
6932 (file-readable-p tag-path
)))))
6933 (loop with count
= 0
6934 until
(file-exists? current-dir
)
6935 ;; Return nil if outside the value of
6936 ;; `anything-c-etags-tag-file-search-limit'.
6937 if
(= count anything-c-etags-tag-file-search-limit
)
6939 ;; Or search upper directories.
6942 (setq current-dir
(expand-file-name (concat current-dir
"../")))
6943 finally return current-dir
)))
6945 (defun anything-c-source-etags-header-name (x)
6946 "Create header name for this anything etags session."
6948 (with-anything-current-buffer
6949 (anything-c-etags-get-tag-file))))
6951 (defmacro anything-c-etags-create-buffer
(file)
6952 "Create the `anything-buffer' based on contents of etags tag FILE."
6953 `(let* ((tag-fname ,file
)
6955 (split (with-current-buffer (find-file-noselect tag-fname
)
6957 (split-string (buffer-string) "\n" 'omit-nulls
)
6958 (setq max
(line-number-at-pos (point-max)))
6960 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max
)))
6964 for i in split for count from
0
6965 for elm
= (unless (string-match "^\x0c" i
)
6966 (anything-aif (string-match "\177" i
)
6969 do
(cond ((and elm
(string-match "^\\(.+\\),[0-9]+" elm
))
6970 (setq fname
(match-string 1 elm
)))
6971 (elm (setq cand
(concat fname
": " elm
)))
6972 (t (setq cand nil
)))
6974 (insert (concat cand
"\n"))
6975 (progress-reporter-update progress-reporter count
)))))
6977 (defun anything-c-etags-init ()
6978 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6979 If no entry in cache, create one."
6980 (let ((tagfile (anything-c-etags-get-tag-file)))
6982 (with-current-buffer (anything-candidate-buffer 'global
)
6983 (anything-aif (gethash tagfile anything-c-etags-cache
)
6984 ;; An entry is present in cache, insert it.
6986 ;; No entry, create a new buffer using content of tag file (slower).
6987 (anything-c-etags-create-buffer tagfile
)
6988 ;; Store content of buffer in cache.
6989 (puthash tagfile
(buffer-string) anything-c-etags-cache
)
6990 ;; Store or set the last modification of tag file.
6991 (anything-aif (assoc tagfile anything-c-etags-mtime-alist
)
6992 ;; If an entry exists modify it.
6993 (setcdr it
(anything-c-etags-mtime tagfile
))
6994 ;; No entry create a new one.
6995 (add-to-list 'anything-c-etags-mtime-alist
6996 (cons tagfile
(anything-c-etags-mtime tagfile
)))))))))
6998 (defvar anything-c-source-etags-select
7000 (header-name . anything-c-source-etags-header-name
)
7001 (init . anything-c-etags-init
)
7002 (candidates-in-buffer)
7003 (search .
(anything-c-etags-search-fn))
7004 (mode-line . anything-etags-mode-line-string
)
7005 (action . anything-c-etags-default-action
)
7006 (persistent-action .
(lambda (candidate)
7007 (anything-c-etags-default-action candidate
)
7008 (anything-match-line-color-current-line))))
7009 "Anything source for Etags.")
7011 (defun anything-c-etags-search-fn (pattern)
7012 "Search function for `anything-c-source-etags-select'."
7014 (if anything-c-etags-use-regexp-search
7015 (format anything-c-etags-search-regexp pattern
)
7019 (defun anything-c-etags-default-action (candidate)
7020 "Anything default action to jump to an etags entry."
7021 (let* ((split (split-string candidate
": "))
7022 (fname (expand-file-name
7023 (car split
) anything-c-etags-tag-file-dir
))
7026 (goto-char (point-min))
7027 (search-forward elm nil t
)
7028 (goto-char (match-beginning 0))))
7030 (defun anything-c-etags-mtime (file)
7031 "Last modification time of etags tag FILE."
7032 (cadr (nth 5 (file-attributes file
))))
7034 (defun anything-c-etags-file-modified-p (file)
7035 "Check if tag FILE have been modified in this session.
7036 If FILE is nil return nil."
7037 (let ((last-modif (and file
7038 (assoc-default file anything-c-etags-mtime-alist
))))
7040 (/= last-modif
(anything-c-etags-mtime file
)))))
7047 (defvar anything-semantic-candidates nil
)
7049 (defun anything-semantic-construct-candidates (tags depth
)
7050 (when (require 'semantic nil t
)
7056 (let ((type (semantic-tag-type tag
))
7057 (class (semantic-tag-class tag
)))
7058 (if (or (and (stringp type
)
7059 (or (string= type
"class")
7060 (string= type
"namespace")))
7061 (eq class
'function
)
7062 (eq class
'variable
))
7063 (cons (cons (concat (make-string (* depth
2) ?\s
)
7064 (semantic-format-tag-summarize tag nil t
))
7066 (anything-semantic-construct-candidates
7067 (semantic-tag-components tag
) (1+ depth
)))))))
7070 (defun anything-semantic-default-action (candidate)
7071 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
7072 (semantic-go-to-tag tag
)))
7074 (defvar anything-c-source-semantic
7075 '((name .
"Semantic Tags")
7077 (setq anything-semantic-candidates
7078 (ignore-errors (anything-semantic-construct-candidates
7079 (semantic-fetch-tags) 0)))))
7080 (candidates .
(lambda ()
7081 (if anything-semantic-candidates
7082 (mapcar 'car anything-semantic-candidates
))))
7083 (persistent-action .
(lambda (elm)
7084 (anything-semantic-default-action elm
)
7085 (anything-match-line-color-current-line)))
7086 (persistent-help .
"Show this entry")
7087 (action . anything-semantic-default-action
)
7088 "Needs semantic in CEDET.
7090 http://cedet.sourceforge.net/semantic.shtml
7091 http://cedet.sourceforge.net/"))
7093 ;; (anything 'anything-c-source-semantic)
7096 ;;; Anything interface of `simple-call-tree.el'.
7098 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7100 ;; Function is called by
7101 (defvar anything-c-source-simple-call-tree-functions-callers
7102 '((name .
"Function is called by")
7103 (init . anything-c-simple-call-tree-functions-callers-init
)
7105 (candidates . anything-c-simple-call-tree-candidates
)
7106 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7107 (persistent-help .
"Show function definitions by rotation")
7108 (action ("Find definition selected by persistent-action" .
7109 anything-c-simple-call-tree-find-definition
)))
7110 "Needs simple-call-tree.el.
7111 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7113 (defvar anything-c-simple-call-tree-tick nil
)
7114 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
7115 (defun anything-c-simple-call-tree-analyze-maybe ()
7116 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
7117 (simple-call-tree-analyze)
7118 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
7120 (defun anything-c-simple-call-tree-init-base (function message
)
7121 (require 'simple-call-tree
)
7123 (when (anything-current-buffer-is-modified)
7124 (anything-c-simple-call-tree-analyze-maybe)
7125 (let ((list (funcall function simple-call-tree-alist
)))
7126 (with-current-buffer (anything-candidate-buffer 'local
)
7127 (dolist (entry list
)
7128 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
7129 (insert (car entry
) message
7130 (if (string= funcs
" ")
7135 (defun anything-c-simple-call-tree-functions-callers-init ()
7136 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7139 (defun anything-c-simple-call-tree-candidates ()
7140 (with-current-buffer (anything-candidate-buffer)
7141 (split-string (buffer-string) "\n\n")))
7143 (defvar anything-c-simple-call-tree-related-functions nil
)
7144 (defvar anything-c-simple-call-tree-function-index
0)
7145 (defun anything-c-simple-call-tree-persistent-action (candidate)
7146 (unless (eq last-command
'anything-execute-persistent-action
)
7147 (setq anything-c-simple-call-tree-related-functions
7148 (delete "no functions."
7150 (replace-regexp-in-string " \\| is called by\\| calls "
7153 (setq anything-c-simple-call-tree-function-index -
1))
7154 (incf anything-c-simple-call-tree-function-index
)
7155 (anything-c-simple-call-tree-find-definition candidate
))
7157 (defun anything-c-simple-call-tree-find-definition (candidate)
7160 (nth (mod anything-c-simple-call-tree-function-index
7161 (length anything-c-simple-call-tree-related-functions
))
7162 anything-c-simple-call-tree-related-functions
))))
7164 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7167 (defvar anything-c-source-simple-call-tree-callers-functions
7168 '((name .
"Function calls")
7169 (init . anything-c-simple-call-tree-callers-functions-init
)
7171 (candidates . anything-c-simple-call-tree-candidates
)
7172 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7173 (persistent-help .
"Show function definitions by rotation")
7174 (action ("Find definition selected by persistent-action" .
7175 anything-c-simple-call-tree-find-definition
)))
7176 "Needs simple-call-tree.el.
7177 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7179 (defun anything-c-simple-call-tree-callers-functions-init ()
7180 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
7182 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7186 ;;; Anything UI of auto-document.el
7188 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7190 ;; Commands/Options with doc
7191 (defvar anything-c-auto-document-data nil
)
7192 (make-variable-buffer-local 'anything-c-auto-document-data
)
7193 (defvar anything-c-source-commands-and-options-in-file
7194 '((name .
"Commands/Options in file")
7196 .
(lambda (x) (format "Commands/Options in %s"
7197 (buffer-local-value 'buffer-file-name
7198 anything-current-buffer
))))
7199 (candidates . anything-command-and-options-candidates
)
7202 "List Commands and Options with doc. It needs auto-document.el .
7204 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7206 (eval-when-compile (require 'auto-document nil t
))
7207 (defun anything-command-and-options-candidates ()
7208 (with-anything-current-buffer
7209 (when (and (require 'auto-document nil t
)
7210 (eq major-mode
'emacs-lisp-mode
)
7211 (or (anything-current-buffer-is-modified)
7212 (not anything-c-auto-document-data
)))
7213 (or imenu--index-alist
(imenu--make-index-alist t
))
7214 (setq anything-c-auto-document-data
7215 (destructuring-bind (commands options
)
7216 (adoc-construct anything-current-buffer
)
7218 (loop for
(command . doc
) in commands
7219 for cmdname
= (symbol-name command
)
7222 (format "Command: %s\n %s"
7223 (propertize cmdname
'face font-lock-function-name-face
)
7224 (adoc-first-line doc
))
7225 (assoc cmdname imenu--index-alist
)))
7226 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
7227 for
(option doc default
) in options
7228 for optname
= (symbol-name option
)
7231 (format "Option: %s\n %s\n default = %s"
7232 (propertize optname
'face font-lock-variable-name-face
)
7233 (adoc-first-line doc
)
7234 (adoc-prin1-to-string default
))
7237 anything-c-auto-document-data
))
7239 ;; (anything 'anything-c-source-commands-and-options-in-file)
7242 ;;;; <Color and Face>
7248 (defvar anything-c-source-customize-face
7249 '((name .
"Customize Face")
7251 (unless (anything-candidate-buffer)
7252 (save-window-excursion (list-faces-display))
7253 (anything-candidate-buffer (get-buffer "*Faces*")))))
7254 (candidates-in-buffer)
7255 (get-line . buffer-substring
)
7256 (action .
(lambda (line)
7257 (customize-face (intern (car (split-string line
))))))
7258 (requires-pattern .
3))
7259 "See (info \"(emacs)Faces\")")
7260 ;; (anything 'anything-c-source-customize-face)
7265 (defvar anything-c-source-colors
7267 (init .
(lambda () (unless (anything-candidate-buffer)
7268 (save-window-excursion (list-colors-display))
7269 (anything-candidate-buffer (get-buffer "*Colors*")))))
7270 (candidates-in-buffer)
7271 (get-line . buffer-substring
)
7273 ("Copy Name" .
(lambda (candidate)
7274 (kill-new (anything-c-colors-get-name candidate
))))
7275 ("Copy RGB" .
(lambda (candidate)
7276 (kill-new (anything-c-colors-get-rgb candidate
))))
7277 ("Insert Name" .
(lambda (candidate)
7278 (with-anything-current-buffer
7279 (insert (anything-c-colors-get-name candidate
)))))
7280 ("Insert RGB" .
(lambda (candidate)
7281 (with-anything-current-buffer
7282 (insert (anything-c-colors-get-rgb candidate
))))))))
7283 ;; (anything 'anything-c-source-colors)
7285 (defun anything-c-colors-get-name (candidate)
7287 (replace-regexp-in-string
7290 (insert (capitalize candidate
))
7291 (goto-char (point-min))
7292 (search-forward-regexp "\\s-\\{2,\\}")
7293 (delete-region (point) (point-max))
7296 (defun anything-c-colors-get-rgb (candidate)
7298 (replace-regexp-in-string
7301 (insert (capitalize candidate
))
7302 (goto-char (point-max))
7303 (search-backward-regexp "\\s-\\{2,\\}")
7304 (delete-region (point) (point-min))
7308 ;;;; <Search Engine>
7309 ;;; Tracker desktop search
7310 (defvar anything-c-source-tracker-search
7311 '((name .
"Tracker Search")
7312 (candidates .
(lambda ()
7313 (start-process "tracker-search-process" nil
7317 (requires-pattern .
3)
7319 "Source for retrieving files matching the current input pattern
7320 with the tracker desktop search.")
7321 ;; (anything 'anything-c-source-tracker-search)
7323 ;;; Spotlight (MacOS X desktop search)
7324 (defvar anything-c-source-mac-spotlight
7327 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
7329 (requires-pattern .
3)
7331 "Source for retrieving files via Spotlight's command line
7333 ;; (anything 'anything-c-source-mac-spotlight)
7336 (defvar anything-c-source-picklist
7337 '((name .
"Picklist")
7338 (candidates .
(lambda () (mapcar 'car picklist-list
)))
7340 ;; (anything 'anything-c-source-picklist)
7347 (defvar anything-c-source-kill-ring
7348 '((name .
"Kill Ring")
7349 (init .
(lambda () (anything-attrset 'last-command last-command
)))
7350 (candidates . anything-c-kill-ring-candidates
)
7351 (filtered-candidate-transformer anything-c-kill-ring-transformer
)
7352 (action . anything-c-kill-ring-action
)
7356 "Source for browse and insert contents of kill-ring.")
7358 (defun anything-c-kill-ring-candidates ()
7359 (loop for kill in
(anything-fast-remove-dups kill-ring
:test
'equal
)
7360 unless
(or (< (length kill
) anything-kill-ring-threshold
)
7361 (string-match "^[\\s\\t]+$" kill
))
7364 (defun anything-c-kill-ring-transformer (candidates source
)
7365 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7366 (loop for i in candidates
7367 for nlines
= (with-temp-buffer (insert i
) (count-lines (point-min) (point-max)))
7368 if
(and anything-c-kill-ring-max-lines-number
7369 (> nlines anything-c-kill-ring-max-lines-number
))
7373 (goto-char (point-min))
7378 (forward-line anything-c-kill-ring-max-lines-number
)
7383 (defun anything-c-kill-ring-action (str)
7384 "Insert STR in `kill-ring' and set STR to the head.
7385 If this action is executed just after `yank',
7386 replace with STR as yanked string."
7387 (setq kill-ring
(delete str kill-ring
))
7388 (if (not (eq (anything-attr 'last-command
) 'yank
))
7389 (insert-for-yank str
)
7391 (let ((inhibit-read-only t
)
7392 (before (< (point) (mark t
))))
7394 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
7395 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
7396 (setq yank-undo-function nil
)
7397 (set-marker (mark-marker) (point) (current-buffer))
7398 (insert-for-yank str
)
7399 ;; Set the window start back where it was in the yank command,
7401 (set-window-start (selected-window) yank-window-start t
)
7403 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7404 ;; It is cleaner to avoid activation, even though the command
7405 ;; loop would deactivate the mark because we inserted text.
7406 (goto-char (prog1 (mark t
)
7407 (set-marker (mark-marker) (point) (current-buffer)))))))
7410 ;; (anything 'anything-c-source-kill-ring)
7414 ;; DO NOT include these sources in `anything-sources' use
7415 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7416 ;; `anything-all-mark-rings' instead.
7418 (defun anything-c-source-mark-ring-candidates ()
7419 (flet ((get-marks (pos)
7423 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
7424 (when (string= "" line
)
7425 (setq line
"<EMPTY LINE>"))
7426 (format "%7d: %s" (line-number-at-pos) line
)))))
7427 (with-anything-current-buffer
7429 with marks
= (if (mark) (cons (mark-marker) mark-ring
) mark-ring
)
7432 for m
= (get-marks i
)
7433 unless
(member m recip
)
7434 collect m into recip
7435 finally return recip
))))
7437 (defvar anything-mark-ring-cache nil
)
7438 (defvar anything-c-source-mark-ring
7439 '((name .
"mark-ring")
7441 (setq anything-mark-ring-cache
7442 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7443 (candidates .
(lambda ()
7444 (anything-aif anything-mark-ring-cache
7446 (action .
(("Goto line"
7447 .
(lambda (candidate)
7448 (anything-goto-line (string-to-number candidate
))))))
7449 (persistent-action .
(lambda (candidate)
7450 (anything-goto-line (string-to-number candidate
))
7451 (anything-match-line-color-current-line)))
7452 (persistent-help .
"Show this line")))
7454 ;; (anything 'anything-c-source-mark-ring)
7456 ;;; Global-mark-ring
7457 (defvar anything-c-source-global-mark-ring
7458 '((name .
"global-mark-ring")
7459 (candidates . anything-c-source-global-mark-ring-candidates
)
7460 (action .
(("Goto line"
7461 .
(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 (persistent-action .
(lambda (candidate)
7466 (let ((items (split-string candidate
":")))
7467 (anything-c-switch-to-buffer (second items
))
7468 (anything-goto-line (string-to-number (car items
)))
7469 (anything-match-line-color-current-line))))
7470 (persistent-help .
"Show this line")))
7472 (defun anything-c-source-global-mark-ring-candidates ()
7474 (with-current-buffer (marker-buffer m
)
7478 (if (string= "" line
)
7479 (setq line
"<EMPTY LINE>")
7480 (setq line
(car (split-string (thing-at-point 'line
)
7482 (format "%7d:%s: %s"
7483 (line-number-at-pos) (marker-buffer m
) line
)))))
7485 with marks
= global-mark-ring
7488 for gm
= (unless (or (string-match
7489 "^ " (format "%s" (marker-buffer i
)))
7490 (null (marker-buffer i
)))
7492 when
(and gm
(not (member gm recip
)))
7493 collect gm into recip
7494 finally return recip
)))
7496 ;; (anything 'anything-c-source-global-mark-ring)
7500 ;;; Insert from register
7501 (defvar anything-c-source-register
7502 '((name .
"Registers")
7503 (candidates . anything-c-register-candidates
)
7504 (action-transformer . anything-c-register-action-transformer
)
7507 "See (info \"(emacs)Registers\")")
7509 (defun anything-c-register-candidates ()
7510 "Collecting register contents and appropriate commands."
7511 (loop for
(char . val
) in register-alist
7512 for key
= (single-key-description char
)
7513 for string-actions
=
7516 (list (int-to-string val
)
7518 'increment-register
))
7520 (let ((buf (marker-buffer val
)))
7522 (list "a marker in no buffer")
7524 "a buffer position:"
7527 (int-to-string (marker-position val
)))
7529 'insert-register
))))
7530 ((and (consp val
) (window-configuration-p (car val
)))
7531 (list "window configuration."
7533 ((and (consp val
) (frame-configuration-p (car val
)))
7534 (list "frame configuration."
7536 ((and (consp val
) (eq (car val
) 'file
))
7537 (list (concat "file:"
7538 (prin1-to-string (cdr val
))
7541 ((and (consp val
) (eq (car val
) 'file-query
))
7542 (list (concat "file:a file-query reference: file "
7545 (int-to-string (car (cdr (cdr val
))))
7549 (let ((lines (format "%4d" (length val
))))
7550 (list (format "%s: %s\n" lines
7551 (truncate-string-to-width
7552 (mapconcat 'identity
(list (car val
))
7553 ;; (mapconcat (lambda (y) y) val
7554 "^J") (- (window-width) 15)))
7557 (list ;; without properties
7558 (substring-no-properties val
)
7561 'prepend-to-register
))
7564 collect
(cons (format "register %3s: %s" key
(car string-actions
))
7565 (cons char
(cdr string-actions
)))))
7567 (defun anything-c-register-action-transformer (actions register-and-functions
)
7568 "Decide actions by the contents of register."
7569 (loop with func-actions
=
7572 (lambda (c) (insert-register (car c
))))
7574 "Jump to Register" .
7575 (lambda (c) (jump-to-register (car c
))))
7577 "Append Region to Register" .
7578 (lambda (c) (append-to-register
7579 (car c
) (region-beginning) (region-end))))
7580 (prepend-to-register
7581 "Prepend Region to Register" .
7582 (lambda (c) (prepend-to-register
7583 (car c
) (region-beginning) (region-end))))
7585 "Increment Prefix Arg to Register" .
7586 (lambda (c) (increment-register
7587 anything-current-prefix-arg
(car c
)))))
7588 for func in
(cdr register-and-functions
)
7589 for cell
= (assq func func-actions
)
7591 collect
(cdr cell
)))
7593 ;; (anything 'anything-c-source-register)
7596 ;;; Latex completion
7597 (defun anything-c-latex-math-candidates ()
7598 "Collect candidates for latex math completion."
7599 (declare (special LaTeX-math-menu
))
7600 (loop for i in
(cddr LaTeX-math-menu
)
7601 for elm
= (loop for s in i when
(vectorp s
)
7602 collect
(cons (aref s
0) (aref s
1)))
7605 (defvar anything-c-source-latex-math
7606 '((name .
"Latex Math Menu")
7608 (with-anything-current-buffer
7609 (LaTeX-math-mode 1))))
7610 (candidate-number-limit .
9999)
7611 (candidates . anything-c-latex-math-candidates
)
7612 (action .
(lambda (candidate)
7613 (call-interactively candidate
)))))
7616 ;;;; <Headline Extraction>
7617 (defvar anything-c-source-fixme
7618 '((name .
"TODO/FIXME/DRY comments")
7619 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7622 "Show TODO/FIXME/DRY comments in current file.")
7623 ;; (anything 'anything-c-source-fixme)
7625 (defvar anything-c-source-rd-headline
7626 '((name .
"RD HeadLine")
7627 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7628 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
7634 http://en.wikipedia.org/wiki/Ruby_Document_format")
7635 ;; (anything 'anything-c-source-rd-headline)
7637 (defvar anything-c-source-oddmuse-headline
7638 '((name .
"Oddmuse HeadLine")
7639 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7640 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7641 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
7644 "Show Oddmuse headlines, such as EmacsWiki.")
7645 ;; (anything 'anything-c-source-oddmuse-headline)
7647 (defvar anything-c-source-emacs-source-defun
7648 '((name .
"Emacs Source DEFUN")
7649 (headline .
"DEFUN\\|DEFVAR")
7650 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
7651 (or buffer-file-name
""))))
7652 "Show DEFUN/DEFVAR in Emacs C source file.")
7653 ;; (anything 'anything-c-source-emacs-source-defun)
7655 (defvar anything-c-source-emacs-lisp-expectations
7656 '((name .
"Emacs Lisp Expectations")
7657 (headline .
"(desc[ ]\\|(expectations")
7658 (condition .
(eq major-mode
'emacs-lisp-mode
)))
7659 "Show descriptions (desc) in Emacs Lisp Expectations.
7661 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7662 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7664 (defvar anything-c-source-emacs-lisp-toplevels
7665 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7666 (headline .
"^(\\|(@\\*\\|^;;;;")
7667 (get-line . buffer-substring
)
7668 (condition .
(eq major-mode
'emacs-lisp-mode
))
7670 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7671 linkd.el is optional because linkd stars are extracted by regexp.
7672 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7673 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7676 ;;; Anything yaoddmuse
7678 ;; Be sure to have yaoddmuse.el installed
7679 ;; install-elisp may be required if you want to install elisp file from here.
7680 (defvar anything-yaoddmuse-use-cache-file nil
)
7681 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
7682 (defvar anything-c-yaoddmuse-ew-cache nil
)
7684 (defun anything-yaoddmuse-get-candidates ()
7685 (declare (special yaoddmuse-pages-hash
))
7686 (if anything-yaoddmuse-use-cache-file
7688 (unless anything-c-yaoddmuse-ew-cache
7689 (load anything-c-yaoddmuse-cache-file
)
7690 (setq anything-c-yaoddmuse-ew-cache
7691 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7692 anything-c-yaoddmuse-ew-cache
)
7693 (yaoddmuse-update-pagename t
)
7694 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7696 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7697 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
7698 (candidates . anything-yaoddmuse-get-candidates
)
7699 (action .
(("Edit page" .
(lambda (candidate)
7700 (yaoddmuse-edit "EmacsWiki" candidate
)))
7702 .
(lambda (candidate)
7703 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
7704 ("Browse page other window"
7705 .
(lambda (candidate)
7707 (split-window-vertically))
7708 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
7710 .
(lambda (candidate)
7711 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
7713 .
(lambda (candidate)
7714 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
7715 (message "Have copy page %s's URL to yank." candidate
)))
7717 .
(lambda (candidate)
7718 (yaoddmuse-edit "EmacsWiki" anything-input
)))
7720 .
(lambda (candidate)
7721 (if anything-yaoddmuse-use-cache-file
7723 (anything-yaoddmuse-cache-pages t
)
7724 (setq anything-c-yaoddmuse-ew-cache
7725 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7726 (yaoddmuse-update-pagename))))))
7727 (action-transformer anything-c-yaoddmuse-action-transformer
))
7728 "Needs yaoddmuse.el.
7730 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7732 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7734 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7735 '((name .
"Yaoddmuse Post library (EmacsWiki)")
7736 (init .
(anything-yaoddmuse-init))
7737 (candidates-in-buffer)
7738 (action .
(("Post library and Browse"
7739 .
(lambda (candidate)
7740 (yaoddmuse-post-file
7741 (find-library-name candidate
)
7743 (file-name-nondirectory (find-library-name candidate
))
7746 .
(lambda (candidate)
7747 (yaoddmuse-post-file
7748 (find-library-name candidate
)
7750 (file-name-nondirectory
7751 (find-library-name candidate
))))))))
7752 "Needs yaoddmuse.el.
7754 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7756 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7758 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
7759 "Allow the use of `install-elisp' only on elisp files."
7760 (if (string-match "\.el$" candidate
)
7761 (append actions
'(("Install Elisp"
7763 (install-elisp-from-emacswiki elm
)))))
7767 (defun anything-yaoddmuse-cache-pages (&optional load
)
7768 "Fetch the list of files on emacswiki and create cache file.
7769 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7771 (declare (special yaoddmuse-pages-hash
))
7772 (yaoddmuse-update-pagename)
7774 (find-file anything-c-yaoddmuse-cache-file
)
7776 (insert "(puthash \"EmacsWiki\" '(")
7777 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
7779 (insert (concat "(\"" (car i
) "\") ")))
7780 (insert ") yaoddmuse-pages-hash)\n")
7782 (kill-buffer (current-buffer))
7783 (when (or current-prefix-arg
7785 (load anything-c-yaoddmuse-cache-file
))))
7787 (defun anything-yaoddmuse-init ()
7788 "Init anything buffer status."
7789 (let ((anything-buffer (anything-candidate-buffer 'global
))
7790 (library-list (yaoddmuse-get-library-list)))
7791 (with-current-buffer anything-buffer
7792 ;; Insert library name.
7793 (dolist (library library-list
)
7794 (insert (format "%s\n" library
)))
7796 (sort-lines nil
(point-min) (point-max)))))
7800 (defvar anything-c-source-eev-anchor
7801 '((name .
"Anchors")
7805 (with-anything-current-buffer
7806 (loop initially
(goto-char (point-min))
7807 while
(re-search-forward
7808 (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
7809 for anchor
= (match-string-no-properties 1)
7810 collect
(cons (format "%5d:%s"
7811 (line-number-at-pos (match-beginning 0))
7812 (format ee-anchor-format anchor
))
7814 (persistent-action .
(lambda (item)
7816 (anything-match-line-color-current-line)))
7817 (persistent-help .
"Show this entry")
7818 (action .
(("Goto link" . ee-to
)))))
7819 ;; (anything 'anything-c-source-eev-anchor)
7825 (defvar anything-c-source-org-headline
7826 `((name .
"Org HeadLine")
7830 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7832 (number-sequence 1 8)))
7833 (condition .
(eq major-mode
'org-mode
))
7836 (persistent-action .
(lambda (elm)
7837 (anything-c-action-line-goto elm
)
7840 .
(lambda (actions candidate
)
7841 '(("Go to Line" . anything-c-action-line-goto
)
7842 ("Refile to this Headline" . anything-c-org-headline-refile
)
7843 ("Insert Link to This Headline"
7844 . anything-c-org-headline-insert-link-to-headline
)))))
7845 "Show Org headlines.
7846 org-mode is very very much extended text-mode/outline-mode.
7848 See (find-library \"org.el\")
7849 See http://orgmode.org for the latest version.")
7850 ;; (anything 'anything-c-source-org-headline)
7852 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7855 (anything-goto-line (car lineno-and-content
))
7856 (and (looking-at org-complex-heading-regexp
)
7857 (org-make-link-string (concat "*" (match-string 4)))))))
7859 (defun anything-c-org-headline-refile (lineno-and-content)
7860 "Refile current org entry to LINENO-AND-CONTENT."
7861 (with-anything-current-buffer
7863 (anything-goto-line (car lineno-and-content
))
7864 (org-end-of-subtree t t
)
7865 (let ((org-yank-adjusted-subtrees t
))
7872 (defvar anything-c-source-org-keywords
7873 '((name .
"Org Keywords")
7874 (init . anything-c-org-keywords-init
)
7875 (candidates . anything-c-org-keywords-candidates
)
7876 (action . anything-c-org-keywords-insert
)
7877 (persistent-action . anything-c-org-keywords-show-help
)
7878 (persistent-help .
"Show an example and info page to describe this keyword.")
7881 ;; (anything 'anything-c-source-org-keywords)
7883 (defvar anything-c-org-keywords-info-location
7884 '(("#+TITLE:" .
"(org)Export options")
7885 ("#+AUTHOR:" .
"(org)Export options")
7886 ("#+DATE:" .
"(org)Export options")
7887 ("#+EMAIL:" .
"(org)Export options")
7888 ("#+DESCRIPTION:" .
"(org)Export options")
7889 ("#+KEYWORDS:" .
"(org)Export options")
7890 ("#+LANGUAGE:" .
"(org)Export options")
7891 ("#+TEXT:" .
"(org)Export options")
7892 ("#+TEXT:" .
"(org)Export options")
7893 ("#+OPTIONS:" .
"(org)Export options")
7894 ("#+BIND:" .
"(org)Export options")
7895 ("#+LINK_UP:" .
"(org)Export options")
7896 ("#+LINK_HOME:" .
"(org)Export options")
7897 ("#+LATEX_HEADER:" .
"(org)Export options")
7898 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
7899 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
7900 ("#+INFOJS_OPT" .
"(org)Javascript support")
7901 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
7902 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
7903 ("#+ORGTBL" .
"(org)Radio tables")
7904 ("#+HTML:" .
"(org)Quoting HTML tags")
7905 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
7906 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
7907 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
7908 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
7909 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
7910 ("#+BEGIN_SRC" .
"(org)Literal examples")
7911 ("#+CAPTION" .
"(org)Tables in HTML export")
7912 ("#+LABEL" .
"(org)Tables in LaTeX export")
7913 ("#+ATTR_HTML" .
"(org)Links")
7914 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
7916 (defun anything-c-org-keywords-init ()
7917 (unless (anything-attr 'keywords-examples
)
7919 (anything-attrset 'keywords-examples
7923 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
7924 (cons (match-string 2 x
) (match-string 1 x
)))
7925 (org-split-string (org-get-current-options) "\n"))
7926 (mapcar 'list org-additional-option-like-keywords
)))
7927 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
7929 (defun anything-c-org-keywords-candidates ()
7930 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
7931 (eq (buffer-local-value 'major-mode anything-current-buffer
) 'message-mode
))
7932 (anything-attr 'keywords
)))
7934 (defun anything-c-org-keywords-insert (keyword)
7935 (cond ((and (string-match "BEGIN" keyword
)
7936 (anything-region-active-p))
7937 (let ((beg (region-beginning))
7940 (insert "\n#+" (replace-regexp-in-string
7941 "BEGIN" "END" keyword
) "\n")
7943 (insert "#+" keyword
" ")
7944 (save-excursion (insert "\n"))))
7945 ((string-match "BEGIN" keyword
)
7946 (insert "#+" keyword
" ")
7948 (insert "\n#+" (replace-regexp-in-string
7949 "BEGIN" "END" keyword
) "\n")))
7950 (t (insert "#+" keyword
" "))))
7952 (defun anything-c-org-keywords-show-help (keyword)
7953 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
7954 "(org)In-buffer settings"))
7955 (search-forward (concat "#+" keyword
) nil t
)
7956 (anything-persistent-highlight-point)
7957 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
7964 (defvar bbdb-records
)
7965 (defvar bbdb-buffer-name
)
7967 (defun anything-c-bbdb-candidates ()
7968 "Return a list of all names in the bbdb database. The format
7969 is \"Firstname Lastname\"."
7970 (mapcar (lambda (bbdb-record)
7971 (replace-regexp-in-string
7973 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
7976 (defun anything-c-bbdb-create-contact (actions candidate
)
7977 "Action transformer that returns only an entry to add the
7978 current `anything-pattern' as new contact. All other actions are
7980 (if (string= candidate
"*Add to contacts*")
7981 '(("Add to contacts" .
(lambda (actions)
7982 (bbdb-create-internal
7983 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
7984 (read-from-minibuffer "Company: ")
7985 (read-from-minibuffer "Email: ")
7988 (read-from-minibuffer "Note: ")))))
7991 (defun anything-c-bbdb-get-record (candidate)
7992 "Return record that match CANDIDATE."
7993 (bbdb candidate nil
)
7994 (set-buffer "*BBDB*")
7995 (bbdb-current-record))
7997 (defvar anything-c-bbdb-name nil
7998 "Only for internal use.")
8000 (defvar anything-c-source-bbdb
8002 (candidates . anything-c-bbdb-candidates
)
8003 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
8004 ("View person's data" . anything-c-bbdb-view-person-action
))
8005 (filtered-candidate-transformer .
(lambda (candidates source
)
8006 (setq anything-c-bbdb-name anything-pattern
)
8007 (if (not candidates
)
8008 (list "*Add to contacts*")
8010 (action-transformer .
(lambda (actions candidate
)
8011 (anything-c-bbdb-create-contact actions candidate
))))
8014 http://bbdb.sourceforge.net/")
8015 ;; (anything 'anything-c-source-bbdb)
8017 (defun anything-c-bbdb-view-person-action (candidate)
8018 "View BBDB data of single CANDIDATE or marked candidates."
8019 (anything-aif (anything-marked-candidates)
8020 (let ((bbdb-append-records (length it
)))
8022 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
8023 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
8025 (defun anything-c-bbdb-collect-mail-addresses ()
8026 "Return a list of all mail addresses of records in bbdb buffer."
8027 (with-current-buffer bbdb-buffer-name
8028 (loop for i in bbdb-records
8029 if
(bbdb-record-net (car i
))
8030 collect
(bbdb-dwim-net-address (car i
)))))
8032 (defun anything-c-bbdb-compose-mail (candidate)
8033 "Compose a mail with all records of bbdb buffer."
8034 (anything-c-bbdb-view-person-action candidate
)
8035 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8036 (address-str (mapconcat 'identity address-list
",\n ")))
8037 (compose-mail address-str
)))
8040 ;;; Evaluation Result
8044 (defvar anything-eldoc-active-minibuffers-list nil
)
8045 (defvar anything-eval-expression-input-history nil
)
8047 (defvar anything-c-source-evaluation-result
8048 '((name .
"Evaluation Result")
8052 (mode-line .
"C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8053 (filtered-candidate-transformer .
(lambda (candidates source
)
8056 (with-anything-current-buffer
8058 (eval (read anything-pattern
))))
8060 (action .
(("Copy result to kill-ring" .
(lambda (candidate)
8061 (with-current-buffer anything-buffer
8062 (let ((end (save-excursion
8063 (goto-char (point-max))
8064 (search-backward "\n")
8066 (kill-region (point) end
)))))
8067 ("copy sexp to kill-ring" .
(lambda (candidate)
8068 (kill-new anything-input
)))))))
8069 ;; (anything 'anything-c-source-evaluation-result)
8071 (defun anything-eval-new-line-and-indent ()
8073 (newline) (lisp-indent-line))
8075 (defun anything-eldoc-store-minibuffer ()
8076 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8077 (with-selected-window (minibuffer-window)
8078 (push (buffer-name) anything-eldoc-active-minibuffers-list
)))
8080 (defun anything-eldoc-show-in-eval ()
8081 "Return eldoc in mode-line for current minibuffer input."
8082 (let ((buf (with-selected-window (minibuffer-window)
8084 (when (member buf anything-eldoc-active-minibuffers-list
)
8085 (let* ((str-all (with-current-buffer buf
8086 (minibuffer-completion-contents)))
8090 (goto-char (point-max))
8091 (unless (looking-back ")\\|\"") (forward-char -
1))
8092 (eldoc-current-symbol))))
8093 (info-fn (eldoc-fnsym-in-current-sexp))
8094 (doc (or (eldoc-get-var-docstring sym
)
8095 (eldoc-get-fnsym-args-string
8096 (car info-fn
) (cadr info-fn
)))))
8097 (when doc
(funcall anything-c-eldoc-in-minibuffer-show-fn doc
))))))
8099 (defun anything-c-show-info-in-mode-line (str)
8100 "Display string STR in mode-line."
8101 (save-window-excursion
8102 (with-current-buffer anything-buffer
8103 (let ((mode-line-format (concat " " str
)))
8104 (force-mode-line-update)
8105 (sit-for anything-c-show-info-in-mode-line-delay
))
8106 (force-mode-line-update))))
8108 ;;; Calculation Result
8111 (defvar anything-c-source-calculation-result
8112 '((name .
"Calculation Result")
8114 (filtered-candidate-transformer .
(lambda (candidates source
)
8117 (calc-eval anything-pattern
)
8119 (action ("Copy result to kill-ring" . kill-new
))))
8120 ;; (anything 'anything-c-source-calculation-result)
8123 ;;; Google Suggestions
8127 (defvar anything-ggs-max-length-real-flag
0)
8128 (defvar anything-ggs-max-length-num-flag
0)
8130 (defun anything-c-google-suggest-fetch (input)
8131 "Fetch suggestions for INPUT from XML buffer.
8132 Return an alist with elements like (data . number_results)."
8133 (setq anything-ggs-max-length-real-flag
0
8134 anything-ggs-max-length-num-flag
0)
8135 (let ((request (concat anything-c-google-suggest-url
8136 (url-hexify-string input
))))
8139 with result-alist
= (xml-get-children
8140 (car (xml-parse-region
8141 (point-min) (point-max)))
8142 'CompleteSuggestion
)
8143 for i in result-alist
8144 for data
= (cdr (caadr (assoc 'suggestion i
)))
8145 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
8146 for lqueries
= (length (anything-c-ggs-set-number-result
8148 for ldata
= (length data
)
8151 (when (> ldata anything-ggs-max-length-real-flag
)
8152 (setq anything-ggs-max-length-real-flag ldata
))
8153 (when (> lqueries anything-ggs-max-length-num-flag
)
8154 (setq anything-ggs-max-length-num-flag lqueries
)))
8155 collect
(cons data nqueries
) into cont
8156 finally return cont
)))
8157 (if anything-google-suggest-use-curl-p
8159 (call-process "curl" nil t nil request
)
8161 (with-current-buffer
8162 (url-retrieve-synchronously request
)
8165 (defun anything-c-google-suggest-set-candidates (&optional request-prefix
)
8166 "Set candidates with result and number of google results found."
8168 (loop with suggested-results
= (anything-c-google-suggest-fetch
8169 (or (and request-prefix
8170 (concat request-prefix
" " anything-pattern
))
8172 for
(real . numresult
) in suggested-results
8173 ;; Prepare number of results with ","
8174 for fnumresult
= (anything-c-ggs-set-number-result numresult
)
8175 ;; Calculate number of spaces to add before fnumresult
8176 ;; if it is smaller than longest result
8177 ;; `anything-ggs-max-length-num-flag'.
8180 ;; To be sure it is aligned properly.
8181 for nspaces
= (if (< (length fnumresult
) anything-ggs-max-length-num-flag
)
8182 (- anything-ggs-max-length-num-flag
(length fnumresult
))
8184 ;; Add now the spaces before fnumresult.
8185 for align-fnumresult
= (concat (make-string nspaces ?
) fnumresult
)
8186 for interval
= (- anything-ggs-max-length-real-flag
(length real
))
8187 for spaces
= (make-string (+ 2 interval
) ?
)
8188 for display
= (format "%s%s(%s results)" real spaces align-fnumresult
)
8189 collect
(cons display real
))))
8190 (if (loop for
(disp . dat
) in suggestions
8191 thereis
(equal dat anything-pattern
))
8193 ;; if there is no suggestion exactly matching the input then
8194 ;; prepend a Search on Google item to the list
8197 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
8198 anything-input
))))))
8200 (defun anything-c-ggs-set-number-result (num)
8203 (and (numberp num
) (setq num
(number-to-string num
)))
8204 (loop for i in
(reverse (split-string num
"" t
))
8206 append
(list i
) into C
8208 append
(list ",") into C
8209 and do
(setq count
0)
8211 (replace-regexp-in-string
8212 "^," "" (mapconcat 'identity
(reverse C
) ""))))
8215 (defvar anything-c-google-suggest-default-browser-function nil
8216 "*The browse url function you prefer to use with google suggest.
8217 When nil, use the first browser function available
8218 See `anything-browse-url-default-browser-alist'.")
8220 (defun anything-c-google-suggest-action (candidate)
8221 "Default action to jump to a google suggested candidate."
8222 (let ((arg (concat anything-c-google-suggest-search-url
8223 (url-hexify-string candidate
))))
8224 (anything-aif anything-c-google-suggest-default-browser-function
8226 (anything-c-browse-url arg
))))
8228 (defvar anything-c-google-suggest-default-function
8229 'anything-c-google-suggest-set-candidates
8230 "Default function to use in anything google suggest.")
8232 (defvar anything-c-source-google-suggest
8233 '((name .
"Google Suggest")
8234 (candidates .
(lambda ()
8235 (funcall anything-c-google-suggest-default-function
)))
8236 (action .
(("Google Search" . anything-c-google-suggest-action
)))
8238 (requires-pattern .
3)
8241 (defun anything-c-google-suggest-emacs-lisp ()
8242 "Try to emacs lisp complete with google suggestions."
8243 (anything-c-google-suggest-set-candidates "emacs lisp"))
8245 ;; (anything 'anything-c-source-google-suggest)
8247 ;;; Yahoo suggestions
8250 (defun anything-c-yahoo-suggest-fetch (input)
8251 "Fetch Yahoo suggestions for INPUT from XML buffer.
8252 Return an alist with elements like (data . number_results)."
8253 (let ((request (concat anything-c-yahoo-suggest-url
8254 (url-hexify-string input
))))
8257 with result-alist
= (xml-get-children
8258 (car (xml-parse-region (point-min) (point-max)))
8260 for i in result-alist
8261 collect
(caddr i
))))
8262 (with-current-buffer
8263 (url-retrieve-synchronously request
)
8266 (defun anything-c-yahoo-suggest-set-candidates ()
8267 "Set candidates with Yahoo results found."
8268 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
8272 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
8273 anything-input
))))))
8275 (defun anything-c-yahoo-suggest-action (candidate)
8276 "Default action to jump to a Yahoo suggested candidate."
8277 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8278 (url-hexify-string candidate
))))
8280 (defvar anything-c-source-yahoo-suggest
8281 '((name .
"Yahoo Suggest")
8282 (candidates . anything-c-yahoo-suggest-set-candidates
)
8283 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
8285 (requires-pattern .
3)
8288 ;; (anything 'anything-c-source-yahoo-suggest)
8291 ;;; Web browser functions.
8294 (require 'browse-url
)
8295 ;; If default setting of `w3m-command' is not
8296 ;; what you want you and you modify it, you will have to reeval
8297 ;; also `anything-browse-url-default-browser-alist'.
8298 (defvar w3m-command
"/usr/bin/w3m")
8299 (defvar anything-c-home-url
"http://www.google.fr"
8300 "*Default url to use as home url.")
8302 (defvar ac-browse-url-chromium-program
"chromium-browser")
8303 (defvar ac-browse-url-uzbl-program
"uzbl-browser")
8304 (defvar anything-browse-url-default-browser-alist
8305 `((,w3m-command . w3m-browse-url
)
8306 (,browse-url-firefox-program . browse-url-firefox
)
8307 (,ac-browse-url-chromium-program . ac-browse-url-chromium
)
8308 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl
)
8309 (,browse-url-kde-program . browse-url-kde
)
8310 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
8311 (,browse-url-mozilla-program . browse-url-mozilla
)
8312 (,browse-url-galeon-program . browse-url-galeon
)
8313 (,browse-url-netscape-program . browse-url-netscape
)
8314 (,browse-url-mosaic-program . browse-url-mosaic
)
8315 (,browse-url-xterm-program . browse-url-text-xterm
))
8316 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8318 (defun* anything-c-generic-browser
(url name
&rest args
)
8319 "Browse URL with NAME browser."
8320 (let ((proc (concat name
" " url
)))
8321 (message "Starting %s..." name
)
8322 (apply 'start-process proc nil name
8323 (append args
(list url
)))
8324 (set-process-sentinel
8326 #'(lambda (process event
)
8327 (when (string= event
"finished\n")
8328 (message "%s process %s" process event
))))))
8330 (defun ac-browse-url-chromium (url)
8331 "Browse URL with google chrome browser."
8332 (interactive "sURL: ")
8333 (anything-c-generic-browser
8334 url ac-browse-url-chromium-program
))
8336 (defun ac-browse-url-uzbl (url &optional ignore
)
8337 "Browse URL with uzbl browser."
8338 (interactive "sURL: ")
8339 (anything-c-generic-browser url ac-browse-url-uzbl-program
"-u"))
8341 (defun anything-browse-url-default-browser (url &rest args
)
8342 "Find the first available browser and ask it to load URL."
8343 (let ((default-browser-fn
8344 (loop for
(exe . fn
) in anything-browse-url-default-browser-alist
8345 thereis
(and exe
(executable-find exe
) fn
))))
8346 (if default-browser-fn
8347 (apply default-browser-fn url args
)
8348 (error "No usable browser found"))))
8350 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
8351 "Default command to browse URL."
8352 (if browse-url-browser-function
8354 (anything-browse-url-default-browser url
)))
8359 ;; Need external program surfraw.
8360 ;; <http://surfraw.alioth.debian.org/>
8362 (defvar anything-surfraw-default-browser-function nil
8363 "*The browse url function you prefer to use with surfraw.
8364 When nil, fallback to `browse-url-browser-function'.")
8367 (defvar anything-surfraw-engines-history nil
)
8368 (defvar anything-surfraw-input-history nil
)
8370 (defun anything-c-build-elvi-list ()
8371 "Return list of all engines and descriptions handled by surfraw."
8374 (call-process "surfraw" nil t nil
8376 (split-string (buffer-string) "\n"))))
8382 (defun anything-emms-stream-edit-bookmark (elm)
8383 "Change the information of current emms-stream bookmark from anything."
8384 (declare (special emms-stream-list
))
8385 (let* ((cur-buf anything-current-buffer
)
8386 (bookmark (assoc elm emms-stream-list
))
8387 (name (read-from-minibuffer "Description: "
8389 (url (read-from-minibuffer "URL: "
8391 (fd (read-from-minibuffer "Feed Descriptor: "
8392 (int-to-string (nth 2 bookmark
))))
8393 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8394 (format "%s" (car (last bookmark
))))))
8397 (when (re-search-forward (concat "^" name
) nil t
)
8399 (emms-stream-delete-bookmark)
8400 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
8401 (emms-stream-save-bookmarks-file)
8403 (anything-c-switch-to-buffer cur-buf
)))))
8405 (defun anything-emms-stream-delete-bookmark (elm)
8406 "Delete an emms-stream bookmark from anything."
8407 (let* ((cur-buf anything-current-buffer
)
8408 (bookmark (assoc elm emms-stream-list
))
8409 (name (nth 0 bookmark
)))
8412 (when (re-search-forward (concat "^" name
) nil t
)
8414 (emms-stream-delete-bookmark)
8415 (emms-stream-save-bookmarks-file)
8417 (anything-c-switch-to-buffer cur-buf
)))))
8419 (defvar anything-c-source-emms-streams
8420 '((name .
"Emms Streams")
8422 (emms-stream-init)))
8423 (candidates .
(lambda ()
8424 (declare (special emms-stream-list
))
8425 (mapcar 'car emms-stream-list
)))
8426 (action .
(("Play" .
(lambda (elm)
8427 (declare (special emms-stream-list
))
8428 (let* ((stream (assoc elm emms-stream-list
))
8429 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
8430 (url (second stream
)))
8432 ("Delete" . anything-emms-stream-delete-bookmark
)
8433 ("Edit" . anything-emms-stream-edit-bookmark
)))
8434 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8435 ;; (anything 'anything-c-source-emms-streams)
8437 ;; Don't forget to set `emms-source-file-default-directory'
8438 (defvar anything-c-source-emms-dired
8439 '((name .
"Music Directory")
8440 (candidates .
(lambda ()
8441 (cddr (directory-files emms-source-file-default-directory
))))
8443 (("Play Directory" .
(lambda (item)
8444 (emms-play-directory
8447 emms-source-file-default-directory
))))
8448 ("Open dired in file's directory" .
(lambda (item)
8449 (anything-c-open-dired
8452 emms-source-file-default-directory
))))))
8453 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8454 ;; (anything 'anything-c-source-emms-dired)
8457 (defun anything-c-emms-files-modifier (candidates source
)
8458 (let ((current-playlist (with-current-emms-playlist
8460 with cur-list
= (emms-playlist-tracks-in-region
8461 (point-min) (point-max))
8463 collect
(assoc-default 'name i
)))))
8464 (loop for i in candidates
8465 if
(member (cdr i
) current-playlist
)
8466 collect
(cons (propertize (car i
)
8467 'face
'anything-emms-playlist
)
8469 else collect i into lis
8470 finally return lis
)))
8472 (defun anything-c-emms-play-current-playlist ()
8473 "Play current playlist."
8474 (with-current-emms-playlist
8475 (emms-playlist-first)
8476 (emms-playlist-mode-play-smart)))
8478 (defvar anything-c-source-emms-files
8479 '((name .
"Emms files")
8480 (candidates .
(lambda ()
8481 (loop for v being the hash-values in emms-cache-db
8482 for name
= (assoc-default 'name v
)
8483 for artist
= (or (assoc-default 'info-artist v
) "unknown")
8484 for genre
= (or (assoc-default 'info-genre v
) "unknown")
8485 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
8486 for song
= (or (assoc-default 'info-title v
) "unknown")
8487 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
8488 unless
(string-match "^http:" name
) collect
(cons info name
))))
8489 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
8490 (action .
(("Play file" . emms-play-file
)
8491 ("Add to Playlist and play (C-u clear current)"
8492 .
(lambda (candidate)
8493 (when anything-current-prefix-arg
8494 (emms-playlist-current-clear))
8496 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
8497 (unless emms-player-playing-p
8498 (anything-c-emms-play-current-playlist))))))))
8500 ;; (anything 'anything-c-source-emms-files)
8503 ;;; Jabber Contacts (jabber.el)
8504 (defun anything-c-jabber-online-contacts ()
8505 "List online Jabber contacts."
8508 (dolist (item (jabber-concat-rosters) jids
)
8509 (when (get item
'connected
)
8510 (push (if (get item
'name
)
8511 (cons (get item
'name
) item
)
8512 (cons (symbol-name item
) item
)) jids
))))))
8514 (defvar anything-c-source-jabber-contacts
8515 '((name .
"Jabber Contacts")
8516 (init .
(lambda () (require 'jabber
)))
8517 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
8518 (action .
(lambda (x)
8520 (jabber-read-account)
8522 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
8523 ;; (anything 'anything-c-source-jabber-contacts)
8528 (defvar anything-source-select-buffer
"*anything source select*")
8529 (defvar anything-c-source-call-source
8530 `((name .
"Call anything source")
8531 (candidate-number-limit)
8534 (loop for vname in
(all-completions "anything-c-source-" obarray
)
8535 for var
= (intern vname
)
8536 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
8538 (cons (format "%s `%s'"
8539 name
(propertize vname
'face
'font-lock-variable-name-face
))
8542 .
(("Invoke anything with selected source"
8545 (setq anything-candidate-number-limit
9999)
8546 (anything candidate nil nil nil nil
8547 anything-source-select-buffer
)))
8548 ("Describe variable" . describe-variable
)
8549 ("Find variable" . find-variable
)))
8550 (persistent-action . describe-variable
)
8551 (persistent-help .
"Show description of this source")))
8552 ;; (anything 'anything-c-source-call-source)
8554 (defun anything-call-source-from-anything ()
8555 "Call anything source within `anything' session."
8557 (setq anything-input-idle-delay
0)
8558 (anything-set-sources '(anything-c-source-call-source)))
8560 ;;; Execute Preconfigured anything.
8561 (defvar anything-c-source-anything-commands
8562 '((name .
"Preconfigured Anything")
8563 (candidates . anything-c-anything-commands-candidates
)
8565 (candidate-number-limit)))
8566 ;; (anything 'anything-c-source-anything-commands)
8568 (defun anything-c-anything-commands-candidates ()
8569 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
8570 collect
(cons (if (where-is-internal cmd nil t
)
8571 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
8572 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
8579 (defun anything-c-occur-init ()
8580 "Create the initial anything occur buffer.
8581 If region is active use region as buffer contents
8582 instead of whole buffer."
8583 (with-current-buffer (anything-candidate-buffer 'global
)
8586 (with-anything-current-buffer
8587 (if (anything-region-active-p)
8588 (buffer-substring (region-beginning) (region-end))
8589 (buffer-substring (point-min) (point-max))))))
8590 (insert buf-contents
))))
8592 (defun anything-c-occur-get-line (s e
)
8593 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
8595 (defun anything-c-occur-query-replace-regexp (candidate)
8596 "Query replace regexp starting from CANDIDATE.
8597 If region is active ignore CANDIDATE and replace only in region.
8598 With a prefix arg replace only matches surrounded by word boundaries,
8599 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8600 (let ((regexp anything-input
))
8601 (unless (anything-region-active-p)
8602 (anything-c-action-line-goto candidate
))
8603 (apply 'query-replace-regexp
8604 (anything-c-query-replace-args regexp
))))
8606 (defvar anything-c-source-occur
8608 (init . anything-c-occur-init
)
8609 (candidates-in-buffer)
8611 (get-line . anything-c-occur-get-line
)
8612 (display-to-real . anything-c-display-to-real-line
)
8613 (action .
(("Go to Line" . anything-c-action-line-goto
)
8614 ("Query replace regexp (C-u Not inside word.)"
8615 . anything-c-occur-query-replace-regexp
)))
8617 (requires-pattern .
1)
8620 ;; (anything 'anything-c-source-occur)
8623 ;;; Anything browse code.
8624 (defun anything-c-browse-code-get-line (beg end
)
8625 "Select line if it match the regexp corresponding to current `major-mode'.
8626 Line is parsed for BEG position to END position."
8627 (let ((str-line (buffer-substring beg end
))
8628 (regexp (assoc-default major-mode
8629 anything-c-browse-code-regexp-alist
))
8630 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
8631 (when (and regexp
(string-match regexp str-line
))
8632 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
8635 (defvar anything-c-source-browse-code
8636 '((name .
"Browse code")
8638 (anything-candidate-buffer anything-current-buffer
)
8639 (with-anything-current-buffer
8640 (jit-lock-fontify-now))))
8641 (candidate-number-limit .
9999)
8642 (candidates-in-buffer)
8643 (get-line . anything-c-browse-code-get-line
)
8648 ;; Do many actions for input
8649 (defvar anything-c-source-create
8653 (action-transformer . anything-create--actions
))
8654 "Do many create actions from `anything-pattern'.
8655 See also `anything-create--actions'.")
8656 ;; (anything 'anything-c-source-create)
8658 (defun anything-create-from-anything ()
8659 "Run `anything-create' from `anything' as a fallback."
8661 (anything-run-after-quit 'anything-create nil anything-pattern
))
8663 (defun anything-create--actions (&rest ignored
)
8664 "Default actions for `anything-create' / `anything-c-source-create'."
8666 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
8667 (append anything-create--actions-private
8668 '(("find-file" . find-file
)
8669 ("find-file other window" . find-file-other-window
)
8670 ("New buffer" . anything-c-switch-to-buffer
)
8671 ("New buffer other window" . switch-to-buffer-other-window
)
8672 ("Bookmark Set" . bookmark-set
)
8674 (lambda (x) (set-register (read-char "Register: ") x
)))
8675 ("Insert Linkd star" . linkd-insert-star
)
8676 ("Insert Linkd Tag" . linkd-insert-tag
)
8677 ("Insert Linkd Link" . linkd-insert-link
)
8678 ("Insert Linkd Lisp" . linkd-insert-lisp
)
8679 ("Insert Linkd Wiki" . linkd-insert-wiki
)
8680 ("Google Search" . google
)))))
8683 ;; Minibuffer History
8686 (defvar anything-c-source-minibuffer-history
8687 '((name .
"Minibuffer History")
8688 (header-name .
(lambda (name)
8689 (format "%s (%s)" name minibuffer-history-variable
)))
8692 (let ((history (loop
8693 for i in
(symbol-value minibuffer-history-variable
)
8694 unless
(string= "" i
) collect i
)))
8695 (if (consp (car history
))
8696 (mapcar 'prin1-to-string history
)
8700 ;; (anything 'anything-c-source-minibuffer-history)
8706 (defvar anything-c-source-elscreen
8707 '((name .
"Elscreen")
8708 (candidates .
(lambda ()
8709 (if (cdr (elscreen-get-screen-to-name-alist))
8711 (loop for sname in
(elscreen-get-screen-to-name-alist)
8712 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
8713 finally
(return lst
))
8714 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
8715 (action .
(("Change Screen".
8717 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
8720 (dolist (i (anything-marked-candidates))
8721 (elscreen-goto (- (aref i
1) (aref "0" 0)))
8725 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
8726 (elscreen-kill-others)))))))
8727 ;; (anything 'anything-c-source-elscreen)
8733 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
8734 "Top command (batch mode). %s is replaced with `frame-width'.")
8735 (defvar anything-c-source-top
8736 '((name .
"Top (Press C-c C-u to refresh)")
8737 (init . anything-c-top-init
)
8738 (candidates-in-buffer)
8739 (display-to-real . anything-c-top-display-to-real
)
8740 (update . anything-c-top-update
)
8741 (persistent-action . anything-c-top-sh-persistent-action
)
8742 (persistent-help .
"SIGTERM")
8744 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
8745 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
8746 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
8747 ;; (anything 'anything-c-source-top)
8749 (defun anything-c-top-sh (cmd)
8750 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
8752 (defun anything-c-top-sh-persistent-action (pid)
8753 (delete-other-windows)
8754 (anything-c-top-sh (format "kill -TERM %s" pid
))
8755 (anything-force-update))
8757 (defun anything-c-top-init ()
8758 (with-current-buffer (anything-candidate-buffer 'global
)
8759 (call-process-shell-command
8760 (format anything-c-top-command
8761 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
8762 nil
(current-buffer))))
8764 (defun anything-c-top-display-to-real (line)
8765 (car (split-string line
)))
8767 (defun anything-c-top-update ()
8768 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
8769 (anything-c-top-init)))
8772 (defvar anything-c-source-absolute-time-timers
8773 '((name .
"Absolute Time Timers")
8774 (candidates . timer-list
)
8776 ;; (anything 'anything-c-source-absolute-time-timers)
8778 (defvar anything-c-source-idle-time-timers
8779 '((name .
"Idle Time Timers")
8780 (candidates . timer-idle-list
)
8782 ;; (anything 'anything-c-source-idle-time-timers)
8784 (defun anything-c-timer-real-to-display (timer)
8785 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
8786 (append timer nil
) ;use `append' to convert vector->list
8787 (format "%s repeat=%5S %s(%s)"
8788 (let ((time (list t1 t2 t3
)))
8790 (format-time-string "idle-for=%5s" time
)
8791 (format-time-string "%m/%d %T" time
)))
8794 (mapconcat 'prin1-to-string args
" "))))
8796 ;;; X RandR resolution change
8797 ;;; FIXME I do not care multi-display.
8798 (defvar anything-c-xrandr-output
"VGA")
8799 (defvar anything-c-xrandr-screen
"0")
8800 (defvar anything-c-source-xrandr-change-resolution
8801 '((name .
"Change Resolution")
8805 (call-process "xrandr" nil
(current-buffer) nil
8806 "--screen" anything-c-xrandr-screen
"-q")
8808 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
8809 collect
(match-string 1)))))
8811 ("Change Resolution" .
(lambda (mode)
8812 (call-process "xrandr" nil nil nil
8813 "--screen" anything-c-xrandr-screen
8814 "--output" anything-c-xrandr-output
8816 ;; (anything 'anything-c-source-xrandr-change-resolution)
8821 (defun anything-c-persistent-xfont-action (elm)
8822 "Show current font temporarily"
8823 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
8826 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
8827 (set-frame-font current-font
))))
8829 (defvar anything-c-xfonts-cache nil
)
8830 (defvar anything-c-source-xfonts
8831 '((name .
"X Fonts")
8833 (unless anything-c-xfonts-cache
8834 (setq anything-c-xfonts-cache
8835 (x-list-fonts "*")))))
8836 (candidates . anything-c-xfonts-cache
)
8837 (action .
(("Copy to kill ring" .
(lambda (elm)
8839 ("Set Font" .
(lambda (elm)
8841 (set-frame-font elm
'keep-size
)
8842 (message "New font have been copied to kill ring")))))
8843 (persistent-action . anything-c-persistent-xfont-action
)
8844 (persistent-help .
"Switch to this font temporarily")))
8845 ;; (anything 'anything-c-source-xfonts)
8847 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8850 (defvar anything-c-ucs-max-len
0)
8851 (defun anything-c-calculate-ucs-max-len ()
8852 "Calculate the length of longest `ucs-names' candidate."
8853 (loop with count
= 0
8854 for
(n . v
) in
(ucs-names)
8855 for len
= (length n
)
8858 finally return count
))
8860 (defun anything-c-ucs-init ()
8861 "Initialize an anything buffer with ucs symbols.
8862 Only math* symbols are collected."
8863 (unless (> anything-c-ucs-max-len
0)
8864 (setq anything-c-ucs-max-len
8865 (anything-c-calculate-ucs-max-len)))
8866 (with-current-buffer (anything-candidate-buffer
8867 (get-buffer-create "*anything ucs*"))
8868 ;; `ucs-names' fn will not run again, data is cached in
8870 (loop for
(n . v
) in
(ucs-names)
8871 for len
= (length n
)
8872 for diff
= (+ (- anything-c-ucs-max-len len
) 2)
8873 unless
(string= "" n
)
8874 do
(progn (insert (concat
8881 (defun anything-c-ucs-forward-char (candidate)
8882 (with-anything-current-buffer
8885 (defun anything-c-ucs-backward-char (candidate)
8886 (with-anything-current-buffer
8889 (defun anything-c-ucs-delete-backward (candidate)
8890 (with-anything-current-buffer
8893 (defun anything-c-ucs-insert-char (candidate)
8894 (with-anything-current-buffer
8896 (replace-regexp-in-string
8898 (cadr (split-string candidate
":"))))))
8900 (defun anything-c-ucs-persistent-insert ()
8902 (anything-execute-persistent-action 'action-insert
))
8904 (defun anything-c-ucs-persistent-forward ()
8906 (anything-execute-persistent-action 'action-forward
))
8908 (defun anything-c-ucs-persistent-backward ()
8910 (anything-execute-persistent-action 'action-back
))
8912 (defun anything-c-ucs-persistent-delete ()
8914 (anything-execute-persistent-action 'action-delete
))
8916 (defvar anything-c-source-ucs
8917 '((name .
"Ucs names")
8918 (init . anything-c-ucs-init
)
8919 (candidate-number-limit .
9999)
8920 (candidates-in-buffer)
8921 (mode-line . anything-c-ucs-mode-line-string
)
8922 (action-insert . anything-c-ucs-insert-char
)
8923 (action-forward . anything-c-ucs-forward-char
)
8924 (action-back . anything-c-ucs-backward-char
)
8925 (action-delete . anything-c-ucs-delete-backward
)
8926 (action .
(("Insert" . anything-c-ucs-insert-char
)
8927 ("Forward char" . anything-c-ucs-forward-char
)
8928 ("Backward char" . anything-c-ucs-backward-char
)
8929 ("Delete char backward" . anything-c-ucs-delete-backward
))))
8930 "Source for collecting `ucs-names' math symbols.")
8936 (defvar anything-c-source-emacs-process
8937 '((name .
"Emacs Process")
8938 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
8939 (persistent-action .
(lambda (elm)
8940 (delete-process (get-process elm
))
8941 (anything-delete-current-selection)))
8942 (persistent-help .
"Kill Process")
8943 (action ("Kill Process" .
(lambda (elm)
8944 (delete-process (get-process elm
)))))))
8945 ;; (anything 'anything-c-source-emacs-process)
8950 (defvar anything-c-source-time-world
8951 '((name .
"Time World List")
8953 (let ((anything-buffer (anything-candidate-buffer 'global
)))
8954 (with-current-buffer anything-buffer
8955 (display-time-world-display display-time-world-list
)))))
8956 (candidates-in-buffer)))
8960 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8963 (defvar anything-c-source-apt
8965 (init . anything-c-apt-init
)
8966 (candidates-in-buffer)
8967 (candidate-transformer anything-c-apt-candidate-transformer
)
8968 (display-to-real . anything-c-apt-display-to-real
)
8969 (requires-pattern .
2)
8970 (update . anything-c-apt-refresh
)
8972 ("Show package description" . anything-c-apt-cache-show
)
8973 ("Install package" . anything-c-apt-install
)
8974 ("Remove package" . anything-c-apt-uninstall
)
8975 ("Purge package" . anything-c-apt-purge
))
8976 (persistent-action . anything-c-apt-persistent-action
)
8977 (persistent-help .
"Show package description")))
8978 ;; (anything 'anything-c-source-apt)
8980 (defvar anything-c-apt-query
"emacs")
8981 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
8982 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
8983 (defvar anything-c-apt-installed-packages nil
)
8984 (defvar anything-c-apt-all-packages nil
)
8985 (defvar anything-c-apt-input-history nil
)
8987 (defun anything-c-apt-refresh ()
8988 "Refresh installed candidates list."
8989 (setq anything-c-apt-installed-packages nil
)
8990 (setq anything-c-apt-all-packages nil
))
8992 (defun anything-c-apt-persistent-action (candidate)
8993 "Persistent action for APT source."
8994 (anything-c-apt-cache-show candidate
))
8996 (defun anything-c-apt-candidate-transformer (candidates)
8997 "Show installed candidates in a different color."
9000 for cand in candidates
9001 for name
= (anything-c-apt-display-to-real cand
)
9002 if
(member name anything-c-apt-installed-packages
)
9003 collect
(propertize cand
'face
'anything-apt-installed
) into all
9004 else collect cand into all finally return all
))
9006 (defun anything-c-apt-init ()
9007 "Initialize list of debian packages."
9009 (unless (and anything-c-apt-installed-packages
9010 anything-c-apt-all-packages
)
9011 (message "Loading package list...")
9012 (setq anything-c-apt-installed-packages
9014 (call-process-shell-command "dpkg --get-selections"
9015 nil
(current-buffer))
9016 (loop for i in
(split-string (buffer-string) "\n" t
)
9017 collect
(car (split-string i
)))))
9018 (setq anything-c-apt-all-packages
9019 (with-current-buffer
9020 (anything-candidate-buffer
9021 (get-buffer-create (format "*anything-apt*")))
9023 (call-process-shell-command
9024 (format anything-c-apt-search-command query
)
9025 nil
(current-buffer))))
9026 (message "Loading package list done")
9029 (defun anything-c-apt-display-to-real (line)
9030 "Return only name of a debian package.
9031 LINE is displayed like:
9032 package name - description."
9033 (car (split-string line
" - ")))
9035 (defun anything-c-shell-command-if-needed (command)
9036 "Run shell command COMMAND to describe package.
9037 If a buffer named COMMAND already exists, just switch to it."
9038 (let ((buf (get-buffer command
)))
9039 (anything-c-switch-to-buffer (get-buffer-create command
))
9040 (unless buf
(insert (shell-command-to-string command
)))))
9042 (defun anything-c-apt-cache-show (package)
9043 "Show information on apt package PACKAGE."
9044 (anything-c-shell-command-if-needed
9045 (format anything-c-apt-show-command package
)))
9047 (defun anything-c-apt-install (package)
9048 "Run 'apt-get install' shell command on PACKAGE."
9049 (anything-c-apt-generic-action :action
'install
))
9051 (defun anything-c-apt-uninstall (package)
9052 "Run 'apt-get remove' shell command on PACKAGE."
9053 (anything-c-apt-generic-action :action
'uninstall
))
9055 (defun anything-c-apt-purge (package)
9056 "Run 'apt-get purge' shell command on PACKAGE."
9057 (anything-c-apt-generic-action :action
'purge
))
9059 (defun* anything-c-apt-generic-action
(&key action
)
9060 "Run 'apt-get ACTION'.
9061 Support install, remove and purge actions."
9062 (ansi-term (getenv "SHELL") "anything apt")
9064 (let ((command (case action
9065 ('install
"sudo apt-get install ")
9066 ('uninstall
"sudo apt-get remove ")
9067 ('purge
"sudo apt-get purge ")
9068 (t (error "Unknow action"))))
9071 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x
))
9072 (anything-marked-candidates) " ")))
9073 (goto-char (point-max))
9074 (insert (concat command cand-list
))
9076 (if (y-or-n-p (format "%s package" (symbol-name action
)))
9078 (setq anything-c-external-commands-list nil
)
9079 (setq anything-c-apt-installed-packages nil
)
9080 (term-char-mode) (term-send-input))
9081 (delete-region beg end
) (term-send-eof) (kill-buffer))))
9083 ;; (anything-c-apt-install "jed")
9086 ;;; Anything UI for gentoo portage.
9089 (defvar anything-c-gentoo-use-flags nil
)
9090 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
9091 (defvar anything-c-cache-gentoo nil
)
9092 (defvar anything-c-cache-world nil
)
9093 (defvar anything-c-source-gentoo
9094 '((name .
"Portage sources")
9096 (get-buffer-create anything-c-gentoo-buffer
)
9097 (unless anything-c-cache-gentoo
9098 (anything-c-gentoo-setup-cache))
9099 (unless anything-c-cache-world
9100 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
9101 (anything-c-gentoo-init-list)))
9102 (candidates-in-buffer)
9104 (candidate-transformer anything-c-highlight-world
)
9105 (action .
(("Show package" .
(lambda (elm)
9106 (anything-c-gentoo-eshell-action elm
"eix")))
9107 ("Show history" .
(lambda (elm)
9108 (if (member elm anything-c-cache-world
)
9109 (anything-c-gentoo-eshell-action elm
"genlop -qe")
9110 (message "No infos on packages not yet installed"))))
9111 ("Copy in kill-ring" . kill-new
)
9112 ("insert at point" . insert
)
9113 ("Browse HomePage" .
(lambda (elm)
9114 (let ((urls (anything-c-gentoo-get-url elm
)))
9115 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
9116 ("Show extra infos" .
(lambda (elm)
9117 (if (member elm anything-c-cache-world
)
9118 (anything-c-gentoo-eshell-action elm
"genlop -qi")
9119 (message "No infos on packages not yet installed"))))
9120 ("Show use flags" .
(lambda (elm)
9121 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
9122 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
9123 (font-lock-mode 1)))
9124 ("Run emerge pretend" .
(lambda (elm)
9125 (anything-c-gentoo-eshell-action elm
"emerge -p")))
9126 ("Emerge" .
(lambda (elm)
9127 (anything-gentoo-install elm
:action
'install
)))
9128 ("Unmerge" .
(lambda (elm)
9129 (anything-gentoo-install elm
:action
'uninstall
)))
9130 ("Show dependencies" .
(lambda (elm)
9131 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
9132 ("Show related files" .
(lambda (elm)
9133 (anything-c-gentoo-default-action elm
"equery" "files")))
9134 ("Refresh" .
(lambda (elm)
9135 (anything-c-gentoo-setup-cache)
9136 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
9138 ;; (anything 'anything-c-source-gentoo)
9140 (defun* anything-gentoo-install
(candidate &key action
)
9141 (setq anything-c-external-commands-list nil
)
9142 (ansi-term (getenv "SHELL") "Gentoo emerge")
9144 (let ((command (case action
9145 ('install
"sudo emerge -av ")
9146 ('uninstall
"sudo emerge -avC ")
9147 (t (error "Unknow action"))))
9148 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
9150 (goto-char (point-max))
9151 (insert (concat command elms
))
9153 (term-char-mode) (term-send-input)))
9155 (defun anything-c-gentoo-default-action (elm command
&rest args
)
9156 "Gentoo default action that use `anything-c-gentoo-buffer'."
9157 (if (member elm anything-c-cache-world
)
9159 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9161 (let ((com-list (append args
(list elm
))))
9162 (apply #'call-process command nil t nil
9164 (message "No infos on packages not yet installed")))
9166 (defvar anything-c-source-use-flags
9167 '((name .
"Use Flags")
9169 (unless anything-c-gentoo-use-flags
9170 (anything-c-gentoo-setup-use-flags-cache))
9171 (anything-c-gentoo-get-use)))
9172 (candidates-in-buffer)
9174 (candidate-transformer anything-c-highlight-local-use
)
9175 (action .
(("Description"
9177 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9179 (apply #'call-process
"euse" nil t nil
9182 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
9183 (font-lock-mode 1)))
9186 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
9189 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
9192 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
9193 ("Show which dep use this flag"
9195 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9197 (apply #'call-process
"equery" nil t nil
9203 ;; (anything 'anything-c-source-use-flags)
9205 (defun anything-c-gentoo-init-list ()
9206 "Initialize buffer with all packages in Portage."
9207 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9208 (buf (anything-candidate-buffer 'portage-buf
)))
9209 (with-current-buffer buf
9210 (dolist (i anything-c-cache-gentoo
)
9211 (insert (concat i
"\n"))))))
9213 (defun anything-c-gentoo-setup-cache ()
9214 "Set up `anything-c-cache-gentoo'"
9215 (setq anything-c-cache-gentoo
9216 (split-string (with-temp-buffer
9217 (call-process "eix" nil t nil
9221 (defun anything-c-gentoo-eshell-action (elm command
)
9222 (when (get-buffer "*EShell Command Output*")
9223 (kill-buffer "*EShell Command Output*"))
9224 (message "Wait searching...")
9225 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
9226 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
9228 (save-window-excursion
9229 (pop-to-buffer "*scratch*")
9230 (eshell-command (format "%s %s" command elm
)))
9231 (pop-to-buffer "*EShell Command Output*"))
9232 (eshell-command (format "%s %s" command elm
)))))
9234 (defun anything-c-gentoo-get-use ()
9235 "Initialize buffer with all use flags."
9236 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9237 (buf (anything-candidate-buffer 'use-buf
)))
9238 (with-current-buffer buf
9239 (dolist (i anything-c-gentoo-use-flags
)
9240 (insert (concat i
"\n"))))))
9243 (defun anything-c-gentoo-setup-use-flags-cache ()
9244 "Setup `anything-c-gentoo-use-flags'"
9245 (setq anything-c-gentoo-use-flags
9246 (split-string (with-temp-buffer
9247 (call-process "eix" nil t nil
9248 "--print-all-useflags")
9251 (defun anything-c-gentoo-get-url (elm)
9252 "Return a list of urls from eix output."
9254 with url-list
= (split-string
9256 (call-process "eix" nil t nil
9257 elm
"--format" "<homepage>\n")
9261 when
(and (string-match "^http://.*" i
)
9262 (not (member i all
)))
9264 finally return all
))
9266 (defun anything-c-gentoo-get-world ()
9267 "Return list of all installed package on your system."
9268 (split-string (with-temp-buffer
9269 (call-process "qlist" nil t nil
9273 (defun anything-c-gentoo-get-local-use ()
9274 (split-string (with-temp-buffer
9275 (call-process "portageq" nil t nil
9281 (defun anything-c-highlight-world (eix)
9282 "Highlight all installed package."
9284 if
(member i anything-c-cache-world
)
9285 collect
(propertize i
'face
'anything-gentoo-match-face
)
9289 (defun anything-c-highlight-local-use (use-flags)
9290 (let ((local-uses (anything-c-gentoo-get-local-use)))
9291 (loop for i in use-flags
9292 if
(member i local-uses
)
9293 collect
(propertize i
'face
'anything-gentoo-match-face
)
9299 ;;; Anything ratpoison UI
9302 (defvar anything-c-source-ratpoison-commands
9303 '((name .
"Ratpoison Commands")
9304 (init . anything-c-ratpoison-commands-init
)
9305 (candidates-in-buffer)
9306 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
9307 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
9308 (candidate-number-limit)))
9309 ;; (anything 'anything-c-source-ratpoison-commands)
9311 (defun anything-c-ratpoison-commands-init ()
9312 (unless (anything-candidate-buffer)
9313 (with-current-buffer (anything-candidate-buffer 'global
)
9314 ;; with ratpoison prefix key
9316 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
9317 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9318 (replace-match "<ratpoison> \\1: \\2"))
9319 (goto-char (point-max))
9322 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
9323 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9324 (replace-match "\\1: \\2")))))
9326 (defun anything-c-ratpoison-commands-display-to-real (display)
9327 (and (string-match ": " display
)
9328 (substring display
(match-end 0))))
9330 (defun anything-c-ratpoison-commands-execute (candidate)
9331 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
9335 ;;; Anything `completing-read' replacement
9338 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp
)
9339 "Convert COLLECTION to list removing elements that don't match TEST.
9340 See `anything-comp-read' about supported COLLECTION arguments.
9342 SORT-FN is a predicate to sort COLLECTION.
9344 ALISTP when non--nil will not use `all-completions' to collect
9345 candidates because it doesn't handle alists correctly for anything.
9346 i.e In `all-completions' the keys \(cars of elements\)
9347 are the possible completions. In anything we want to use the cdr instead
9348 like \(display . real\).
9352 \(setq A '((a . 1) (b . 2) (c . 3)))
9353 ==>((a . 1) (b . 2) (c . 3))
9354 \(anything-comp-read \"test: \" A :alistp nil
9355 :exec-when-only-one t
9356 :initial-input \"a\")
9358 \(anything-comp-read \"test: \" A :alistp t
9359 :exec-when-only-one t
9360 :initial-input \"1\")
9363 See docstring of `all-completions' for more info.
9365 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9367 (cond ((and (eq collection obarray
) test
)
9368 (all-completions "" collection test
))
9369 ((and (vectorp collection
) test
)
9370 (loop for i across collection when
(funcall test i
) collect i
))
9371 ((vectorp collection
)
9372 (loop for i across collection collect i
))
9374 (loop for i in collection when
(funcall test i
) collect i
))
9375 ((and (symbolp collection
) (boundp collection
))
9376 (symbol-value collection
))
9378 ((and collection test
)
9379 (all-completions "" collection test
))
9380 (t (all-completions "" collection
)))))
9381 (if sort-fn
(sort cands sort-fn
) cands
)))
9383 (defun anything-cr-default-transformer (candidates source
)
9384 "Default filter candidate function for `anything-comp-read'.
9385 Do nothing, just return candidate list unmodified."
9388 (defun* anything-comp-read
(prompt collection
9394 (buffer "*Anything Completions*")
9396 (requires-pattern 0)
9399 (persistent-action nil
)
9400 (persistent-help "DoNothing")
9401 (name "Anything Completions")
9402 candidates-in-buffer
9406 (fc-transformer 'anything-cr-default-transformer
)
9407 (marked-candidates nil
)
9409 "Anything `completing-read' replacement.
9411 - PROMPT is the prompt name to use.
9413 - COLLECTION can be a list, vector, obarray or hash-table.
9414 It can be also a function that receives three arguments:
9415 the values string, predicate and t. See `all-completions' for more details.
9419 - TEST: A predicate called with one arg i.e candidate.
9421 - INITIAL-INPUT: Same as input arg in `anything'.
9423 - PRESELECT: See preselect arg of `anything'.
9425 - DEFAULT: This option is used only for compatibility with regular
9426 Emacs `completing-read'.
9428 - BUFFER: Name of anything-buffer.
9430 - MUST-MATCH: Candidate selected must be one of COLLECTION.
9432 - REQUIRES-PATTERN: Same as anything attribute, default is 0.
9434 - HISTORY: A list containing specific history, default is nil.
9435 When it is non--nil, all elements of HISTORY are displayed in
9436 a special source before COLLECTION.
9438 - INPUT-HISTORY: A symbol. the minibuffer input history will be
9439 stored there, if nil or not provided, `minibuffer-history'
9440 will be used instead.
9442 - PERSISTENT-ACTION: A function called with one arg i.e candidate.
9444 - PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9446 - NAME: The name related to this local source.
9448 - EXEC-WHEN-ONLY-ONE: Bound `anything-execute-action-at-once-if-one'
9449 to non--nil. (possibles values are t or nil).
9451 - VOLATILE: Use volatile attribute \(enabled by default\).
9453 - SORT: A predicate to give to `sort' e.g `string-lessp'.
9455 - FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9457 - MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9459 - ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9461 - CANDIDATES-IN-BUFFER: when non--nil use a source build with
9462 `anything-candidates-in-buffer' which is much faster. It is enabled by default.
9463 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9465 Any prefix args passed during `anything-comp-read' invocation will be recorded
9466 in `anything-current-prefix-arg', otherwise if prefix args where given before
9467 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9468 That's mean you can pass prefix args before or after calling a command
9469 that use `anything-comp-read' See `anything-M-x' for example."
9470 (when (get-buffer anything-action-buffer
)
9471 (kill-buffer anything-action-buffer
))
9472 (flet ((action-fn (candidate)
9473 (if marked-candidates
9474 (anything-marked-candidates)
9475 (identity candidate
))))
9476 (let* ((src-hist `((name .
,(format "%s History" name
))
9479 (let ((all (anything-comp-read-get-candidates
9480 history nil nil
,alistp
)))
9481 (anything-fast-remove-dups
9482 (if (and default
(not (string= default
"")))
9483 (delq nil
(cons default
(delete default all
)))
9486 (filtered-candidate-transformer
9487 .
(lambda (candidates sources
)
9488 (loop for i in candidates
9489 do
(set-text-properties 0 (length i
) nil i
)
9491 (persistent-action .
,persistent-action
)
9492 (persistent-help .
,persistent-help
)
9493 (action .
,'action-fn
)))
9494 (src `((name .
,name
)
9497 (let ((cands (anything-comp-read-get-candidates
9498 collection test sort alistp
)))
9499 (unless (or must-match
(string= anything-pattern
""))
9500 (setq cands
(append (list anything-pattern
) cands
)))
9501 (if (and default
(not (string= default
"")))
9502 (delq nil
(cons default
(delete default cands
)))
9504 (filtered-candidate-transformer ,fc-transformer
)
9505 (requires-pattern .
,requires-pattern
)
9506 (persistent-action .
,persistent-action
)
9507 (persistent-help .
,persistent-help
)
9508 (action .
,'action-fn
)))
9509 (src-1 `((name .
,name
)
9512 (let ((cands (anything-comp-read-get-candidates
9513 collection test sort alistp
)))
9514 (unless (or must-match
(string= anything-pattern
""))
9515 (setq cands
(append (list anything-pattern
) cands
)))
9516 (with-current-buffer (anything-candidate-buffer 'global
)
9518 (if (and default
(not (string= default
"")))
9519 (delq nil
(cons default
(delete default cands
)))
9521 do
(insert (concat i
"\n")))))))
9522 (candidates-in-buffer)
9523 (filtered-candidate-transformer ,fc-transformer
)
9524 (requires-pattern .
,requires-pattern
)
9525 (persistent-action .
,persistent-action
)
9526 (persistent-help .
,persistent-help
)
9527 (action .
,'action-fn
)))
9528 (src-list (list src-hist
9529 (if candidates-in-buffer
9532 (append src
'((volatile)))
9534 (anything-execute-action-at-once-if-one exec-when-only-one
))
9538 :input initial-input
9540 :preselect preselect
9543 :history input-history
9545 (unless (or (eq anything-exit-status
1) must-match
)
9549 ;; Generic completing-read
9551 ;; Support also function as collection.
9552 ;; e.g M-x man is supported.
9553 ;; Support hash-table and vectors as collection.
9555 ;; Some crap emacs functions may not be supported
9556 ;; like ffap-alternate-file (bad use of completing-read)
9557 ;; and maybe others.
9558 ;; Provide a mode `anything-completion-mode' which turn on
9559 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9561 (defvar anything-completion-mode-string
" AC")
9563 (defvar anything-completion-mode-quit-message
9564 "Anything completion disabled")
9566 (defvar anything-completion-mode-start-message
9567 "Anything completion enabled")
9569 ;;; Specialized handlers
9572 (defun anything-completing-read-symbols
9573 (prompt collection test require-match init
9574 hist default inherit-input-method name buffer
)
9575 "Specialized function for fast symbols completion in `ac-mode'."
9578 :sources
`((name .
,name
)
9580 (with-current-buffer (anything-candidate-buffer 'global
)
9581 (goto-char (point-min))
9582 (when (and default
(stringp default
)
9583 ;; Some defaults args result as
9584 ;; (symbol-name nil) == "nil".
9585 ;; e.g debug-on-entry.
9586 (not (string= default
"nil"))
9587 (not (string= default
"")))
9588 (insert (concat default
"\n")))
9589 (loop with all
= (all-completions "" collection test
)
9591 unless
(and default
(eq sym default
))
9592 do
(insert (concat sym
"\n"))))))
9593 (persistent-action . anything-lisp-completion-persistent-action
)
9594 (persistent-help .
"Show brief doc in mode-line")
9595 (candidates-in-buffer)
9596 (action . identity
))
9602 :default
(or default
""))
9606 ;;; Generic completing read
9609 (defun anything-completing-read-default-1
9610 (prompt collection test require-match
9611 init hist default inherit-input-method
9612 name buffer
&optional cands-in-buffer exec-when-only-one
)
9613 "Call `anything-comp-read' with same args as `completing-read'.
9614 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9615 method which is faster.
9616 It should be used when candidate list don't need to rebuild dynamically."
9617 (let ((history (or (car-safe hist
) hist
)))
9622 :input-history history
9623 :must-match require-match
9624 :alistp nil
; Be sure `all-completions' is used.
9626 :candidates-in-buffer cands-in-buffer
9627 :exec-when-only-one exec-when-only-one
9629 ;; If DEF is not provided, fallback to empty string
9630 ;; to avoid `thing-at-point' to be appended on top of list
9631 :default
(or default
"")
9632 :initial-input init
)))
9634 (defun anything-completing-read-with-cands-in-buffer
9635 (prompt collection test require-match
9636 init hist default inherit-input-method
9638 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9639 ;; Some commands like find-tag may use `read-file-name' from inside
9640 ;; the calculation of collection. in this case it clash with
9641 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9642 ;; So (re)calculate collection outside of main anything-session.
9643 (let ((cands (all-completions "" collection
)))
9644 (anything-completing-read-default-1 prompt cands test require-match
9645 init hist default inherit-input-method
9648 (defun* anything-completing-read-default
9649 (prompt collection
&optional
9650 predicate require-match
9651 initial-input hist def
9652 inherit-input-method
)
9653 "An anything replacement of `completing-read'.
9654 This function should be used only as a `completing-read-function'.
9656 Don't use it directly, use instead `anything-comp-read' in your programs.
9658 See documentation of `completing-read' and `all-completions' for details."
9659 (declare (special anything-completion-mode
))
9660 (let* ((current-command this-command
)
9661 (str-command (symbol-name current-command
))
9662 (buf-name (format "*ac-mode-%s*" str-command
))
9663 (entry (assq current-command
9664 anything-completing-read-handlers-alist
))
9665 (def-com (cdr-safe entry
))
9666 (str-defcom (and def-com
(symbol-name def-com
)))
9667 (def-args (list prompt collection predicate require-match
9668 initial-input hist def inherit-input-method
))
9669 ;; Append the two extra args needed to set the buffer and source name
9670 ;; in anything specialized functions.
9671 (any-args (append def-args
(list str-command buf-name
)))
9672 anything-completion-mode-start-message
; Be quiet
9673 anything-completion-mode-quit-message
9674 (minibuffer-completion-table collection
)
9675 (minibuffer-completion-predicate predicate
))
9676 (when (eq def-com
'ido
) (setq def-com
'ido-completing-read
))
9677 (unless (or (not entry
) def-com
)
9678 ;; An entry in *read-handlers-alist exists but have
9679 ;; a nil value, so we exit from here, disable `ac-mode'
9680 ;; and run the command again with it original behavior.
9681 ;; `ac-mode' will be restored on exit.
9682 (return-from anything-completing-read-default
9686 (call-interactively current-command
))
9688 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9689 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9690 (when (or (eq def-com
'completing-read
)
9691 ;; All specialized functions are prefixed by "anything"
9692 (and (stringp str-defcom
)
9693 (not (string-match "^anything" str-defcom
))))
9696 (cond (;; An anything specialized function exists, run it.
9697 (and def-com anything-completion-mode
)
9698 (apply def-com any-args
))
9699 (;; Try to handle `ido-completing-read' everywhere.
9700 (and def-com
(eq def-com
'ido-completing-read
))
9701 (setcar (memq collection def-args
)
9702 (all-completions "" collection predicate
))
9703 (apply def-com def-args
))
9704 (;; User set explicitely `completing-read' or something similar
9705 ;; in *read-handlers-alist, use this with exactly the same
9706 ;; args as in `completing-read'.
9707 ;; If we are here `anything-completion-mode' is now disabled.
9709 (apply def-com def-args
))
9710 (t ; Fall back to classic `anything-comp-read'.
9711 (anything-completing-read-default-1
9712 prompt collection predicate require-match
9713 initial-input hist def inherit-input-method
9714 str-command buf-name
)))
9716 ;; When exiting minibuffer, `this-command' is set to
9717 ;; `anything-exit-minibuffer', which is unwanted when starting
9718 ;; on another `completing-read', so restore `this-command' to
9719 ;; initial value when exiting.
9720 (setq this-command current-command
))))
9722 (defun* anything-generic-read-file-name
9723 (prompt &optional dir default-filename mustmatch initial predicate
)
9724 "An anything replacement of `read-file-name'."
9725 (declare (special anything-completion-mode
))
9726 (let* ((default (and default-filename
9727 (if (listp default-filename
)
9728 (car default-filename
)
9730 (init (or default initial dir default-directory
))
9731 (ini-input (and init
(expand-file-name init
)))
9732 (current-command this-command
)
9733 (str-command (symbol-name current-command
))
9734 (anything-file-completion-sources
9736 (remove str-command anything-file-completion-sources
)))
9737 (buf-name (format "*ac-mode-%s*" str-command
))
9738 (entry (assq current-command
9739 anything-completing-read-handlers-alist
))
9740 (def-com (cdr-safe entry
))
9741 (str-defcom (symbol-name def-com
))
9742 (def-args (list prompt dir default-filename mustmatch initial predicate
))
9743 ;; Append the two extra args needed to set the buffer and source name
9744 ;; in anything specialized functions.
9745 (any-args (append def-args
(list str-command buf-name
)))
9746 (ido-state ido-mode
)
9747 anything-completion-mode-start-message
; Be quiet
9748 anything-completion-mode-quit-message
; Same here
9750 ;; Some functions that normally call `completing-read' can switch
9751 ;; brutally to `read-file-name' (e.g find-tag), in this case
9752 ;; the anything specialized function will fail because it is build
9753 ;; for `completing-read', so set it to 'incompatible to be sure
9754 ;; we switch to `anything-c-read-file-name' and don't try to call it
9755 ;; with wrong number of args.
9756 (when (and def-com
(> (length (help-function-arglist def-com
)) 8))
9757 (setq def-com
'incompatible
))
9758 (when (eq def-com
'ido
) (setq def-com
'ido-read-file-name
))
9759 (unless (or (not entry
) def-com
)
9760 (return-from anything-completing-read-default
9764 (call-interactively current-command
))
9766 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9767 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9768 (when (or (eq def-com
'read-file-name
)
9769 (eq def-com
'ido-read-file-name
)
9770 (and (stringp str-defcom
)
9771 (not (string-match "^anything" str-defcom
))))
9775 (cond (;; A specialized function exists, run it
9776 ;; with the two extra args specific to anything..
9777 (and def-com anything-completion-mode
9778 (not (eq def-com
'ido-read-file-name
))
9779 (not (eq def-com
'incompatible
)))
9780 (apply def-com any-args
))
9781 (;; Def-com value is `ido-read-file-name'
9782 ;; run it with default args.
9783 (and def-com
(eq def-com
'ido-read-file-name
))
9785 (apply def-com def-args
))
9786 (;; Def-com value is `read-file-name'
9787 ;; run it with default args.
9788 (eq def-com
'read-file-name
)
9789 (apply def-com def-args
))
9790 (t ; Fall back to classic `anything-c-read-file-name'.
9791 (anything-c-read-file-name
9795 :initial-input
(expand-file-name init dir
)
9799 (ido-mode (if ido-state
1 -
1))
9800 ;; Same comment as in `anything-completing-read-default'.
9801 (setq this-command current-command
))
9802 (if (and mustmatch
(not (file-exists-p fname
)))
9803 (if (y-or-n-p "File does not exists, create buffer?")
9804 fname
(error "Abort file does not exists"))
9808 (define-minor-mode anything-completion-mode
9809 "Toggle generic anything completion.
9811 All functions in Emacs that use `completing-read'
9812 or `read-file-name' and friends will use anything interface
9813 when this mode is turned on.
9814 However you can modify this behavior for functions of your choice
9815 with `anything-completing-read-handlers-alist'.
9817 Called with a positive arg, turn on unconditionally, with a
9818 negative arg turn off.
9819 You can turn it on with `ac-mode'.
9821 Some crap emacs functions may not be supported,
9822 e.g `ffap-alternate-file' and maybe others
9823 You can add such functions to `anything-completing-read-handlers-alist'
9826 Note: This mode will work only partially on Emacs23."
9829 :lighter anything-completion-mode-string
9830 (declare (special completing-read-function
))
9831 (if anything-completion-mode
9833 (setq completing-read-function
'anything-completing-read-default
9834 read-file-name-function
'anything-generic-read-file-name
)
9835 (message anything-completion-mode-start-message
))
9836 (setq completing-read-function
(and (fboundp 'completing-read-default
)
9837 'completing-read-default
)
9838 read-file-name-function
(and (fboundp 'read-file-name-default
)
9839 'read-file-name-default
))
9840 (message anything-completion-mode-quit-message
)))
9842 (defalias 'ac-mode
'anything-completion-mode
)
9846 ;;; Eshell completion.
9848 ;; Enable like this in .emacs:
9850 ;; (add-hook 'eshell-mode-hook
9852 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9854 (defvar anything-c-source-esh
9855 '((name .
"Eshell completions")
9857 (setq pcomplete-current-completions nil
9858 pcomplete-last-completion-raw nil
)
9859 ;; Eshell-command add this hook in all minibuffers
9860 ;; Remove it for the anything one. (Fixed in Emacs24)
9861 (remove-hook 'minibuffer-setup-hook
'eshell-mode
)))
9862 (candidates . anything-esh-get-candidates
)
9863 (action . anything-ec-insert
))
9864 "Anything source for Eshell completion.")
9867 (defvar anything-ec-target
"")
9868 (defun anything-ec-insert (candidate)
9869 "Insert CANDIDATE at point.
9870 This is the same as `ac-insert', just inlined here for compatibility."
9872 (when (and anything-ec-target
9873 (search-backward anything-ec-target nil t
)
9874 (string= (buffer-substring (point) pt
) anything-ec-target
))
9875 (delete-region (point) pt
)))
9878 (defun anything-esh-get-candidates ()
9879 "Get candidates for eshell completion using `pcomplete'."
9881 (let* ((pcomplete-stub)
9882 pcomplete-seen pcomplete-norm-func
9883 pcomplete-args pcomplete-last pcomplete-index
9884 (pcomplete-autolist pcomplete-autolist
)
9885 (pcomplete-suffix-list pcomplete-suffix-list
))
9886 (with-anything-current-buffer
9888 with table
= (pcomplete-completions)
9889 with entry
= (condition-case nil
9891 (try-completion anything-pattern
(pcomplete-entries))
9892 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9895 (let ((fc (car (last (pcomplete-parse-arguments)))))
9896 ;; Check if last arg require fname completion.
9897 (and (file-name-directory fc
) fc
))))
9898 for i in
(if (listp table
) table
; Emacs23 or commands.
9899 (all-completions pcomplete-stub table
)) ; Emacs24
9900 for file-cand
= (and entry
9901 (if (file-remote-p i
) i
9902 (expand-file-name i
(file-name-directory entry
))))
9903 if
(and file-cand
(or (file-remote-p file-cand
) (file-exists-p file-cand
)))
9904 collect file-cand into ls
9905 else collect i into ls
9907 (if (and entry
(not (string= entry
"")) (file-exists-p entry
))
9908 (append (list (expand-file-name entry default-directory
)) ls
) ls
))))))
9913 (defvar anything-c-source-eshell-history
9914 '((name .
"Eshell history")
9916 (let (eshell-hist-ignoredups)
9917 ;; Write the content's of ring to file.
9918 (eshell-write-history eshell-history-file-name t
)
9919 (with-current-buffer (anything-candidate-buffer 'global
)
9920 (insert-file-contents eshell-history-file-name
)))
9921 ;; Same comment as in `anything-c-source-esh'
9922 (remove-hook 'minibuffer-setup-hook
'eshell-mode
)))
9923 (candidates-in-buffer)
9924 (filtered-candidate-transformer .
(lambda (candidates sources
)
9925 (reverse candidates
)))
9926 (candidate-number-limit .
9999)
9927 (action .
(lambda (candidate)
9929 (insert candidate
))))
9930 "Anything source for Eshell history.")
9933 ;;; Show completion - an alternative of anything-show-completion.el.
9935 ;; Provide show completion with macro `with-anything-show-completion'.
9938 ;; Called each time cursor move in anything-buffer.
9939 (defun anything-c-show-completion ()
9940 (with-anything-current-buffer
9941 (overlay-put anything-c-show-completion-overlay
9942 'display
(anything-get-selection))))
9944 (defun anything-c-show-completion-init-overlay (beg end
)
9945 (and anything-c-turn-on-show-completion
9946 (setq anything-c-show-completion-overlay
(make-overlay beg end
))
9947 (overlay-put anything-c-show-completion-overlay
9948 'face
'anything-lisp-show-completion
)))
9950 (defmacro with-anything-show-completion
(beg end
&rest body
)
9951 "Show anything candidate in an overlay at point.
9952 BEG and END are the beginning and end position of the current completion
9953 in `anything-current-buffer'.
9954 BODY is an anything call where we want to enable show completion.
9955 If `anything-c-turn-on-show-completion' is nil just do nothing."
9956 (declare (indent 2) (debug t
))
9957 `(let ((anything-move-selection-after-hook
9958 (and anything-c-turn-on-show-completion
9959 (append (list 'anything-c-show-completion
)
9960 anything-move-selection-after-hook
))))
9962 (progn (anything-c-show-completion-init-overlay ,beg
,end
)
9964 (and anything-c-turn-on-show-completion
9965 (delete-overlay anything-c-show-completion-overlay
)))))
9968 ;;; Lisp symbol completion.
9972 (defun anything-lisp-completion-at-point ()
9973 "Anything lisp symbol completion at point."
9975 (let* ((data (lisp-completion-at-point))
9977 (end (point)) ; 'cadr data' is wrong when no space after point.
9978 (plist (nthcdr 3 data
))
9979 (pred (plist-get plist
:predicate
))
9981 (target (and beg end
(buffer-substring-no-properties beg end
)))
9982 (candidates (all-completions target
(nth 2 data
) pred
))
9983 (anything-quit-if-no-candidate t
)
9984 (anything-execute-action-at-once-if-one t
)
9985 (anything-match-plugin-enabled
9986 (member 'anything-compile-source--match-plugin
9987 anything-compile-source-functions
)))
9989 (with-anything-show-completion beg end
9990 ;; Overlay is initialized now in anything-current-buffer.
9993 '((name .
"Lisp completion")
9995 (with-current-buffer (anything-candidate-buffer 'global
)
9996 (loop for sym in candidates
9997 for len
= (length sym
)
9998 when
(> len lgst-len
) do
(setq lgst-len len
)
9999 do
(insert (concat sym
"\n"))))))
10000 (candidates-in-buffer)
10001 (persistent-action . anything-lisp-completion-persistent-action
)
10002 (persistent-help .
"Show brief doc in mode-line")
10003 (filtered-candidate-transformer anything-lisp-completion-transformer
)
10004 (action .
(lambda (candidate)
10005 (delete-region beg end
)
10006 (insert candidate
))))
10007 :input
(if anything-match-plugin-enabled
(concat target
" ") target
)))
10008 (message "[No Match]"))))
10010 (defun anything-lisp-completion-persistent-action (candidate)
10011 (let ((cursor-in-echo-area t
)
10012 mode-line-in-non-selected-windows
)
10013 (anything-c-show-info-in-mode-line
10015 (anything-c-get-first-line-documentation
10016 (intern candidate
))
10017 'face
'anything-lisp-completion-info
))))
10019 (defun anything-lisp-completion-transformer (candidates source
)
10020 "Anything candidates transformer for lisp completion."
10021 (declare (special lgst-len
))
10022 (loop for c in candidates
10023 for sym
= (intern c
)
10024 for annot
= (cond ((commandp sym
) " (Com)")
10025 ((fboundp sym
) " (Fun)")
10026 ((boundp sym
) " (Var)")
10027 ((facep sym
) " (Face)"))
10028 for spaces
= (make-string (- lgst-len
(length c
)) ?
)
10029 collect
(cons (concat c spaces annot
) c
)))
10031 (defun anything-c-get-first-line-documentation (sym)
10032 "Return first line documentation of symbol SYM.
10033 If SYM is not documented, return \"Not documented\"."
10034 (let ((doc (cond ((fboundp sym
)
10035 (documentation sym t
))
10037 (documentation-property sym
'variable-documentation t
))
10039 (face-documentation sym
))
10041 (if (and doc
(not (string= doc
""))
10042 ;; `documentation' return "\n\n(args...)"
10043 ;; for CL-style functions.
10044 (not (string-match-p "^\n\n" doc
)))
10045 (car (split-string doc
"\n"))
10046 "Not documented")))
10048 ;;; File completion.
10050 ;; Complete file name at point.
10051 (defun anything-c-thing-before-point ()
10052 "Get symbol name before point.
10053 Borrowed from anything-complete.el, inlined here for compatibility."
10055 (let ((beg (point)))
10056 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10057 (when (re-search-backward
10058 "\\_<" (field-beginning nil nil
(point-at-bol)) t
)
10059 (buffer-substring-no-properties beg
(match-end 0))))))
10062 (defun anything-c-complete-file-name-at-point ()
10063 "Complete file name at point."
10065 (let* ((init (substring-no-properties (thing-at-point 'filename
)))
10067 (beg (- (point) (length init
)))
10068 (anything-quit-if-no-candidate t
)
10069 (anything-execute-action-at-once-if-one t
)
10071 (with-anything-show-completion beg end
10072 (setq completion
(anything-c-read-file-name "FileName: "
10073 :initial-input init
)))
10074 (anything-c-insert-file-name-completion-at-point completion
)))
10077 (defvar anything-lisp-completion-counter
0)
10079 (defun anything-lisp-completion-at-point-or-indent (arg)
10080 "First call indent and second call complete lisp symbol.
10081 The second call should happen before `anything-lisp-completion-or-indent-delay',
10082 after this delay, next call will indent again.
10083 After completion, next call is always indent.
10084 See that like click and double mouse click.
10085 One hit indent, two quick hits maybe indent and complete."
10087 ;; Be sure `indent-for-tab-command' will not try
10088 ;; to use `completion-at-point'.
10089 (let ((tab-always-indent (if (eq tab-always-indent
'complete
)
10090 t tab-always-indent
)))
10091 (incf anything-lisp-completion-counter
)
10093 (if (> anything-lisp-completion-counter
1)
10094 (anything-lisp-completion-or-file-name-at-point)
10095 (indent-for-tab-command arg
))
10096 ;; After `anything-lisp-completion-or-indent-delay' seconds
10098 (run-with-timer anything-lisp-completion-or-indent-delay nil
10100 (setq anything-lisp-completion-counter
0)))
10101 ;; Always reset to 0 at second hit.
10102 (when (eq anything-lisp-completion-counter
2)
10103 (setq anything-lisp-completion-counter
0)))))
10106 (defun anything-lisp-completion-or-file-name-at-point ()
10107 "Complete lisp symbol or filename at point.
10108 Filename completion happen if filename is started in
10109 or between double quotes."
10111 (let ((tap (substring-no-properties (thing-at-point 'filename
))))
10112 (if (and tap
(string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap
)
10113 (save-excursion (search-backward "\"" (point-at-bol) t
)))
10114 (anything-c-complete-file-name-at-point)
10115 (anything-lisp-completion-at-point))))
10117 (defun anything-c-apropos-init (test default
)
10118 "Init candidates buffer for `anything-c-apropos' sources."
10119 (with-current-buffer (anything-candidate-buffer 'global
)
10120 (goto-char (point-min))
10121 (when (and default
(stringp default
)
10122 ;; Some defaults args result as
10123 ;; (symbol-name nil) == "nil".
10124 ;; e.g debug-on-entry.
10125 (not (string= default
"nil"))
10126 (funcall test
(intern default
)))
10127 (insert (concat default
"\n")))
10128 (loop with all
= (all-completions "" obarray test
)
10130 unless
(and default
(eq sym default
))
10131 do
(insert (concat sym
"\n")))))
10134 ;;; Run Externals commands within Emacs with anything completion
10137 (defvar anything-external-command-history nil
)
10139 (defun anything-c-external-commands-list-1 (&optional sort
)
10140 "Returns a list of all external commands the user can execute.
10141 If `anything-c-external-commands-list' is non-nil it will
10142 return its contents. Else it calculates all external commands
10143 and sets `anything-c-external-commands-list'."
10144 (if anything-c-external-commands-list
10145 anything-c-external-commands-list
10146 (setq anything-c-external-commands-list
10148 with paths
= (split-string (getenv "PATH") path-separator
)
10149 with completions
= ()
10151 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
10152 for lsdir
= (loop for i in
(directory-files dir t
)
10153 for bn
= (file-name-nondirectory i
)
10154 when
(and (not (member bn completions
))
10155 (not (file-directory-p i
))
10156 (file-executable-p i
))
10158 append lsdir into completions
10159 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
10161 (defun anything-run-or-raise (exe &optional file
)
10162 "Generic command that run asynchronously EXE.
10163 If EXE is already running just jump to his window if `anything-raise-command'
10165 When FILE argument is provided run EXE with FILE.
10166 In this case EXE must be provided as \"EXE %s\"."
10167 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10169 (proc (if file
(concat real-com
" " file
) real-com
)))
10170 (if (get-process proc
)
10171 (if anything-raise-command
10172 (shell-command (format anything-raise-command real-com
))
10173 (error "Error: %s is already running" real-com
))
10174 (when (loop for i in anything-c-external-commands-list thereis real-com
)
10175 (message "Starting %s..." real-com
)
10177 (start-process-shell-command
10178 proc nil
(format exe
(shell-quote-argument file
)))
10179 (start-process-shell-command proc nil real-com
))
10180 (set-process-sentinel
10182 #'(lambda (process event
)
10183 (when (and (string= event
"finished\n")
10184 anything-raise-command
10185 (not (anything-c-get-pid-from-process-name real-com
)))
10186 (shell-command (format anything-raise-command
"emacs")))
10187 (message "%s process...Finished." process
))))
10188 (setq anything-c-external-commands-list
10190 (delete real-com anything-c-external-commands-list
))))))
10194 ;;; Generic action functions
10197 (defun anything-c-file-buffers (filename)
10198 "Returns a list of buffer names corresponding to FILENAME."
10199 (let ((name (expand-file-name filename
))
10201 (dolist (buf (buffer-list) buf-list
)
10202 (let ((bfn (buffer-file-name buf
)))
10203 (when (and bfn
(string= name bfn
))
10204 (push (buffer-name buf
) buf-list
))))))
10206 (defun anything-revert-buffer (candidate)
10207 (with-current-buffer candidate
10208 (when (or (buffer-modified-p)
10209 (not (verify-visited-file-modtime
10210 (get-buffer candidate
))))
10211 (revert-buffer t t
))))
10213 (defun anything-revert-marked-buffers (ignore)
10214 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
10216 (defun anything-kill-marked-buffers (ignore)
10217 (mapc 'kill-buffer
(anything-marked-candidates)))
10219 (defun anything-c-delete-file (file)
10220 "Delete the given file after querying the user.
10221 Ask to kill buffers associated with that file, too."
10222 (let ((buffers (anything-c-file-buffers file
)))
10223 (if (< emacs-major-version
24)
10224 ;; `dired-delete-file' in Emacs versions < 24
10225 ;; doesn't support delete-by-moving-to-trash
10226 ;; so use `delete-directory' and `delete-file'
10228 (cond ((and (not (file-symlink-p file
))
10229 (file-directory-p file
)
10230 (directory-files file t dired-re-no-dot
))
10231 (when (y-or-n-p (format "Recursive delete of `%s'? " file
))
10232 (delete-directory file
'recursive
)))
10233 ((and (not (file-symlink-p file
))
10234 (file-directory-p file
))
10235 (delete-directory file
))
10236 (t (delete-file file
)))
10238 file
'dired-recursive-deletes delete-by-moving-to-trash
))
10240 (dolist (buf buffers
)
10241 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
10242 (kill-buffer buf
))))))
10244 (defun anything-get-mailcap-for-file (filename)
10245 "Get the command to use for FILENAME from mailcap files.
10246 The command is like <command %s> and is meant to use with `format'."
10247 (mailcap-parse-mailcaps)
10248 (let* ((ext (file-name-extension filename
))
10249 (mime (when ext
(mailcap-extension-to-mime ext
)))
10250 (result (when mime
(mailcap-mime-info mime
))))
10251 ;; If elisp file have no associations in .mailcap
10252 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10253 (when (stringp result
) result
)))
10255 (defun anything-get-default-program-for-file (filename)
10256 "Try to find a default program to open FILENAME.
10257 Try first in `anything-c-external-programs-associations' and then in mailcap file
10258 if nothing found return nil."
10259 (let* ((ext (file-name-extension filename
))
10260 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
10261 (cond ((and def-prog
(not (string= def-prog
"")))
10262 (concat def-prog
" %s"))
10263 ((and anything-c-default-external-file-browser
10264 (file-directory-p filename
))
10265 (concat anything-c-default-external-file-browser
" %s"))
10266 (t (anything-get-mailcap-for-file filename
)))))
10268 (defun anything-c-open-file-externally (file)
10269 "Open FILE with an external program.
10270 Try to guess which program to use with `anything-get-default-program-for-file'.
10271 If not found or a prefix arg is given query the user which tool to use."
10272 (let* ((fname (expand-file-name file
))
10273 (collection (anything-c-external-commands-list-1 'sort
))
10274 (def-prog (anything-get-default-program-for-file fname
))
10275 (real-prog-name (if (or anything-current-prefix-arg
(not def-prog
))
10276 ;; Prefix arg or no default program.
10278 (anything-comp-read
10279 "Program: " collection
10281 :name
"Open file Externally"
10282 :history anything-external-command-history
)
10283 ;; Always prompt to set this program as default.
10284 (setq def-prog nil
))
10285 ;; No prefix arg or default program exists.
10286 (replace-regexp-in-string " %s\\| '%s'" "" def-prog
)))
10287 (program (concat real-prog-name
" %s")))
10288 (unless (or def-prog
; Association exists, no need to record it.
10289 ;; Don't try to record non--filenames associations (e.g urls).
10290 (not (file-exists-p fname
)))
10294 "Do you want to make `%s' the default program for this kind of files? "
10296 (anything-aif (assoc (file-name-extension fname
)
10297 anything-c-external-programs-associations
)
10298 (setq anything-c-external-programs-associations
10299 (delete it anything-c-external-programs-associations
)))
10300 (push (cons (file-name-extension fname
)
10302 "Program (Add args maybe and confirm): " real-prog-name
))
10303 anything-c-external-programs-associations
)
10304 (customize-save-variable 'anything-c-external-programs-associations
10305 anything-c-external-programs-associations
)))
10306 (anything-run-or-raise program file
)
10307 (setq anything-external-command-history
10308 (cons real-prog-name
10309 (delete real-prog-name
10310 (loop for i in anything-external-command-history
10311 when
(executable-find i
) collect i
))))))
10313 (defun anything-c-find-file-or-marked (candidate)
10314 "Open file CANDIDATE or open anything marked files in background."
10315 (let ((marked (anything-marked-candidates))
10316 (ffap-newfile-prompt anything-ff-newfile-prompt-p
)
10317 (find-file-wildcards nil
))
10318 (if (> (length marked
) 1)
10319 ;; Open all marked files in background and display
10321 (progn (mapc 'find-file-noselect
(cdr marked
))
10322 (find-file (car marked
)))
10323 (if (and (not (file-exists-p candidate
))
10324 (and ffap-url-regexp
10325 (not (string-match ffap-url-regexp candidate
)))
10326 (string-match "/$" candidate
))
10327 ;; A a non--existing filename ending with /
10328 ;; Create a directory and jump to it.
10329 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
10330 (let ((dirfname (directory-file-name candidate
)))
10331 (if (file-exists-p dirfname
)
10332 (error "Mkdir: Unable to create directory `%s': file exists."
10333 (anything-c-basename dirfname
))
10334 (make-directory candidate
'parent
)))
10335 (anything-find-files-1 candidate
))
10336 ;; A non--existing filename NOT ending with / or
10337 ;; an existing filename, create or jump to it.
10338 (find-file-at-point (car marked
))))))
10340 (defun anything-delete-marked-files (ignore)
10341 (let* ((files (anything-marked-candidates))
10342 (len (length files
)))
10344 (format "Delete *%s File(s):\n%s"
10346 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
10347 (message "(No deletions performed)")
10349 (set-text-properties 0 (length i
) nil i
)
10350 (anything-c-delete-file i
))
10351 (message "%s File(s) deleted" len
))))
10353 (defun anything-ediff-marked-buffers (candidate &optional merge
)
10354 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10355 With optional arg MERGE call `ediff-merge-buffers'."
10356 (let ((lg-lst (length (anything-marked-candidates)))
10360 (error "Error:You have to mark at least 1 buffer"))
10362 (setq buf1 anything-current-buffer
10363 buf2
(first (anything-marked-candidates))))
10365 (setq buf1
(first (anything-marked-candidates))
10366 buf2
(second (anything-marked-candidates))))
10368 (error "Error:To much buffers marked!")))
10370 (ediff-merge-buffers buf1 buf2
)
10371 (ediff-buffers buf1 buf2
))))
10373 (defun anything-ediff-marked-buffers-merge (candidate)
10374 "Ediff merge `anything-current-buffer' with CANDIDATE.
10375 See `anything-ediff-marked-buffers'."
10376 (anything-ediff-marked-buffers candidate t
))
10378 (defun anything-bookmark-get-bookmark-from-name (bmk)
10379 "Return bookmark name even if it is a bookmark with annotation.
10380 e.g prepended with *.
10381 Return nil if bmk is not a valid bookmark."
10382 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
10383 (if (assoc bookmark bookmark-alist
)
10385 (when (assoc bmk bookmark-alist
)
10388 (defun anything-delete-marked-bookmarks (ignore)
10389 "Delete this bookmark or all marked bookmarks."
10390 (dolist (i (anything-marked-candidates))
10391 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
10394 (defun anything-require-or-error (feature function
)
10395 (or (require feature nil t
)
10396 (error "Need %s to use `%s'." feature function
)))
10398 (defun anything-find-buffer-on-elscreen (candidate)
10399 "Open buffer in new screen, if marked buffers open all in elscreens."
10400 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
10401 (anything-aif (anything-marked-candidates)
10403 (let ((target-screen (elscreen-find-screen-by-buffer
10404 (get-buffer i
) 'create
)))
10405 (elscreen-goto target-screen
)))
10406 (let ((target-screen (elscreen-find-screen-by-buffer
10407 (get-buffer candidate
) 'create
)))
10408 (elscreen-goto target-screen
))))
10410 (defun anything-elscreen-find-file (file)
10411 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
10412 (elscreen-find-file file
))
10415 (defun w32-shell-execute-open-file (file)
10416 (interactive "fOpen file:")
10418 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10420 (replace-regexp-in-string ; strip cygdrive paths
10421 "/cygdrive/\\(.\\)" "\\1:"
10422 file nil nil
) nil t
))))
10424 (defun anything-c-open-file-with-default-tool (file)
10425 "Open FILE with the default tool on this platform."
10426 (if (eq system-type
'windows-nt
)
10427 (w32-shell-execute-open-file file
)
10428 (start-process "anything-c-open-file-with-default-tool"
10430 (cond ((eq system-type
'gnu
/linux
)
10432 ((or (eq system-type
'darwin
) ;; Mac OS X
10433 (eq system-type
'macos
)) ;; Mac OS 9
10437 (defun anything-c-open-dired (file)
10438 "Opens a dired buffer in FILE's directory. If FILE is a
10439 directory, open this directory."
10440 (if (file-directory-p file
)
10442 (dired (file-name-directory file
))
10443 (dired-goto-file file
)))
10445 (defun anything-c-display-to-real-line (candidate)
10446 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
10447 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
10448 (error "Line number not found")))
10450 (defun anything-c-action-line-goto (lineno-and-content)
10451 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
10452 (append lineno-and-content
10453 (list (if (and (anything-attr-defined 'target-file
)
10454 (not anything-in-persistent-action
))
10455 'find-file-other-window
10458 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
10459 (apply #'anything-goto-file-line
10460 (if (stringp file-line-content
)
10461 ;; Case: filtered-candidate-transformer is skipped
10462 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
10463 file-line-content
)))
10466 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
10467 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
10469 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10470 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
10471 (let ((filename (match-string 1 candidate
))
10472 (lineno (match-string 2 candidate
))
10473 (content (match-string 3 candidate
)))
10474 (cons (format "%s:%s\n %s"
10475 (propertize filename
'face compilation-info-face
)
10476 (propertize lineno
'face compilation-line-face
)
10478 (list (expand-file-name
10480 (or (anything-interpret-value (anything-attr 'default-directory
))
10481 (and (anything-candidate-buffer)
10482 (buffer-local-value
10483 'default-directory
(anything-candidate-buffer)))))
10484 (string-to-number lineno
) content
)))))
10486 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
10487 (anything-aif (anything-attr 'before-jump-hook
)
10489 (when file
(funcall find-file-function file
))
10490 (if (anything-attr-defined 'adjust
)
10491 (anything-c-goto-line-with-adjustment lineno content
)
10492 (anything-goto-line lineno
))
10493 (unless (anything-attr-defined 'recenter
)
10494 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
10495 (anything-aif (anything-attr 'after-jump-hook
)
10497 (when anything-in-persistent-action
10498 (anything-match-line-color-current-line)))
10500 (defun anything-find-file-as-root (candidate)
10501 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
10503 (defun anything-find-many-files (ignore)
10504 (mapc 'find-file
(anything-marked-candidates)))
10506 ;; borrowed from etags.el
10507 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10508 (defun anything-c-goto-line-with-adjustment (line line-content
)
10511 ;; This constant is 1/2 the initial search window.
10512 ;; There is no sense in making it too small,
10513 ;; since just going around the loop once probably
10514 ;; costs about as much as searching 2000 chars.
10517 pat
(concat (if (eq selective-display t
)
10518 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10519 (regexp-quote line-content
)))
10520 ;; If no char pos was given, try the given line number.
10521 (setq startpos
(progn (anything-goto-line line
) (point)))
10522 (or startpos
(setq startpos
(point-min)))
10523 ;; First see if the tag is right at the specified location.
10524 (goto-char startpos
)
10525 (setq found
(looking-at pat
))
10526 (while (and (not found
)
10528 (goto-char (- startpos offset
))
10531 (re-search-forward pat
(+ startpos offset
) t
)
10532 offset
(* 3 offset
))) ; expand search window
10534 (re-search-forward pat nil t
)
10535 (error "not found")))
10536 ;; Position point at the right place
10537 ;; if the search string matched an extra Ctrl-m at the beginning.
10538 (and (eq selective-display t
)
10541 (beginning-of-line))
10543 (anything-document-attribute 'default-directory
"type . file-line"
10544 "`default-directory' to interpret file.")
10545 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
10546 "Function to call before jumping to the target location.")
10547 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
10548 "Function to call after jumping to the target location.")
10549 (anything-document-attribute 'adjust
"type . file-line"
10550 "Search around line matching line contents.")
10551 (anything-document-attribute 'recenter
"type . file-line / line"
10552 "`recenter' after jumping.")
10553 (anything-document-attribute 'target-file
"type . line"
10554 "Goto line of target-file.")
10557 (defun anything-c-call-interactively (cmd-or-name)
10558 "Execute CMD-OR-NAME as Emacs command.
10559 It is added to `extended-command-history'.
10560 `anything-current-prefix-arg' is used as the command's prefix argument."
10561 (setq extended-command-history
10562 (cons (anything-c-stringify cmd-or-name
)
10563 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
10564 (let ((current-prefix-arg anything-current-prefix-arg
)
10565 (cmd (anything-c-symbolify cmd-or-name
)))
10566 (if (stringp (symbol-function cmd
))
10567 (execute-kbd-macro (symbol-function cmd
))
10568 (setq this-command cmd
)
10569 (call-interactively cmd
))))
10572 (defun anything-c-set-variable (var)
10573 "Set value to VAR interactively."
10575 (let ((sym (anything-c-symbolify var
)))
10576 (set sym
(eval-minibuffer (format "Set %s: " var
)
10577 (prin1-to-string (symbol-value sym
))))))
10579 ;; (anything-c-set-variable 'hh)
10583 ;;; Persistent Action Helpers
10586 (defvar anything-match-line-overlay-face nil
)
10587 (defvar anything-match-line-overlay nil
)
10589 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
10590 "Highlight and underline current position"
10591 (let ((args (list (or start
(line-beginning-position))
10592 (or end
(1+ (line-end-position)))
10594 (if (not anything-match-line-overlay
)
10595 (setq anything-match-line-overlay
(apply 'make-overlay args
))
10596 (apply 'move-overlay anything-match-line-overlay args
)))
10597 (overlay-put anything-match-line-overlay
10598 'face
(or face anything-match-line-overlay-face
))
10603 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
10606 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
10608 (defun anything-match-line-cleanup ()
10609 (when anything-match-line-overlay
10610 (delete-overlay anything-match-line-overlay
)
10611 (setq anything-match-line-overlay nil
)))
10613 (defun anything-match-line-update ()
10614 (when anything-match-line-overlay
10615 (delete-overlay anything-match-line-overlay
)
10616 (anything-match-line-color-current-line)))
10618 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
10619 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
10622 ;;; Actions Transformers
10626 (defun anything-c-transform-file-load-el (actions candidate
)
10627 "Add action to load the file CANDIDATE if it is an emacs lisp
10628 file. Else return ACTIONS unmodified."
10629 (if (member (file-name-extension candidate
) '("el" "elc"))
10630 (append actions
'(("Load Emacs Lisp File" . load-file
)))
10633 (defun anything-c-transform-file-browse-url (actions candidate
)
10634 "Add an action to browse the file CANDIDATE if it in a html
10635 file or URL. Else return ACTIONS unmodified."
10636 (let ((browse-action '("Browse with Browser" . browse-url
)))
10637 (cond ((string-match "^http\\|^ftp" candidate
)
10638 (cons browse-action actions
))
10639 ((string-match "\\.html?$" candidate
)
10640 (append actions
(list browse-action
)))
10644 (defun anything-c-transform-function-call-interactively (actions candidate
)
10645 "Add an action to call the function CANDIDATE interactively if
10646 it is a command. Else return ACTIONS unmodified."
10647 (if (commandp (intern-soft candidate
))
10648 (append actions
'(("Call Interactively"
10650 anything-c-call-interactively
)))
10654 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
10655 "If CANDIDATE's `car' is a command, then add an action to
10656 evaluate it and put it onto the `command-history'."
10657 (if (commandp (car (read candidate
)))
10658 ;; Make it first entry
10659 (cons '("Eval and put onto command-history" .
10661 (let ((sym (read sexp
)))
10663 (setq command-history
10664 (cons sym command-history
)))))
10669 ;;; Candidate Transformers
10673 (defun anything-c-skip-boring-buffers (buffers)
10674 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
10676 (defun anything-c-skip-current-buffer (buffers)
10677 (if anything-allow-skipping-current-buffer
10678 (remove (buffer-name anything-current-buffer
) buffers
)
10681 (defun anything-c-shadow-boring-buffers (buffers)
10682 "Buffers matching `anything-c-boring-buffer-regexp' will be
10683 displayed with the `file-name-shadow' face if available."
10684 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
10686 (defvar anything-c-buffer-display-string-functions
10687 '(anything-c-buffer-display-string--compilation
10688 anything-c-buffer-display-string--shell
10689 anything-c-buffer-display-string--eshell
)
10690 "Functions to setup display string for buffer.
10692 Function has one argument, buffer name.
10693 If it returns string, use it.
10694 If it returns nil, display buffer name.
10695 See `anything-c-buffer-display-string--compilation' for example.")
10697 (defun anything-c-transform-buffer-display-string (buffers)
10698 "Setup display string for buffer candidates
10699 using `anything-c-buffer-display-string-functions'."
10700 (loop for buf in buffers
10704 for disp
= (progn (set-buffer buf
)
10705 (run-hook-with-args-until-success
10706 'anything-c-buffer-display-string-functions buf
))
10707 collect
(if disp
(cons disp buf
) buf
)))
10709 (defun anything-c-buffer-display-string--compilation (buf)
10710 (anything-aif (car compilation-arguments
)
10711 (format "%s: %s [%s]" buf it default-directory
)))
10713 (defun anything-c-buffer-display-string--eshell (buf)
10714 (declare (special eshell-history-ring
))
10715 (when (eq major-mode
'eshell-mode
)
10716 (format "%s: %s [%s]" buf
10717 (ignore-errors (ring-ref eshell-history-ring
0))
10718 default-directory
)))
10720 (defun anything-c-buffer-display-string--shell (buf)
10721 (when (eq major-mode
'shell-mode
)
10722 (format "%s: %s [%s]" buf
10723 (ignore-errors (ring-ref comint-input-ring
0))
10724 default-directory
)))
10727 (defun anything-c-shadow-boring-files (files)
10728 "Files matching `anything-c-boring-file-regexp' will be
10729 displayed with the `file-name-shadow' face if available."
10730 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
10732 (defun anything-c-skip-boring-files (files)
10733 "Files matching `anything-c-boring-file-regexp' will be skipped."
10734 (anything-c-skip-entries files anything-c-boring-file-regexp
))
10735 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10737 (defun anything-c-skip-current-file (files)
10738 "Current file will be skipped."
10739 (remove (buffer-file-name anything-current-buffer
) files
))
10741 (defun anything-c-w32-pathname-transformer (args)
10742 "Change undesirable features of windows pathnames to ones more acceptable to
10743 other candidate transformers."
10744 (if (eq system-type
'windows-nt
)
10745 (mapcar (lambda (x)
10746 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
10747 (mapcar (lambda (y)
10748 (replace-regexp-in-string "\\\\" "/" y
)) args
))
10751 (defun anything-c-shorten-home-path (files)
10752 "Replaces /home/user with ~."
10753 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10755 (mapcar (lambda (file)
10756 (if (and (stringp file
) (string-match home file
))
10757 (cons (replace-match "~" nil nil file
) file
)
10762 (defun anything-c-mark-interactive-functions (functions)
10763 "Mark interactive functions (commands) with (i) after the function name."
10765 (loop for function in functions
10766 do
(push (cons (concat function
10767 (when (commandp (intern-soft function
)) " (i)"))
10770 finally
(return (nreverse list
)))))
10773 ;;; Adaptive Sorting of Candidates
10777 (defvar anything-c-adaptive-done nil
10778 "nil if history information is not yet stored for the current
10781 (defvar anything-c-adaptive-history nil
10782 "Contains the stored history information.
10783 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10785 (defadvice anything-initial-setup
(before anything-c-adaptive-initialize activate
)
10786 "Reset `anything-c-adaptive-done' when anything is started."
10787 (when anything-c-use-adaptative-sorting
10788 (setq anything-c-adaptive-done nil
)))
10790 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
10791 "Store history information when action is executed on selected candidate."
10792 (when anything-c-use-adaptative-sorting
10793 (anything-c-adaptive-store-selection)))
10795 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
10796 "Store history information when the user goes to the action buffer."
10797 (when anything-c-use-adaptative-sorting
10798 (anything-c-adaptive-store-selection)))
10800 (defun anything-c-source-use-adaptative-p (&optional source-name
)
10801 "Return current source only if it use adaptative history, nil otherwise."
10802 (when anything-c-use-adaptative-sorting
10803 (let* ((source (or source-name
(anything-get-current-source)))
10804 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10805 (assoc (assoc-default 'type source
)
10806 anything-type-attributes
))
10807 (assoc-default 'candidate-transformer
10808 (assoc (assoc-default 'type source
)
10809 anything-type-attributes
))
10810 (assoc-default 'filtered-candidate-transformer source
)
10811 (assoc-default 'candidate-transformer source
))))
10812 (if (listp adapt-source
)
10813 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
10814 (when (eq adapt-source
'anything-c-adaptive-sort
) source
)))))
10816 (defun anything-c-adaptive-store-selection ()
10817 "Store history information for the selected candidate."
10818 (unless anything-c-adaptive-done
10819 (setq anything-c-adaptive-done t
)
10820 (let ((source (anything-c-source-use-adaptative-p)))
10822 (let* ((source-name (or (assoc-default 'type source
)
10823 (assoc-default 'name source
)))
10824 (source-info (or (assoc source-name anything-c-adaptive-history
)
10826 (push (list source-name
) anything-c-adaptive-history
)
10827 (car anything-c-adaptive-history
))))
10828 (selection (anything-get-selection))
10829 (selection-info (progn
10830 (setcdr source-info
10832 (let ((found (assoc selection
(cdr source-info
))))
10837 ;; move entry to the beginning of the
10838 ;; list, so that it doesn't get
10839 ;; trimmed when the history is
10841 (setcdr source-info
10842 (delete found
(cdr source-info
)))
10844 (cdr source-info
)))
10845 (cadr source-info
)))
10846 (pattern-info (progn
10847 (setcdr selection-info
10849 (let ((found (assoc anything-pattern
(cdr selection-info
))))
10852 (cons anything-pattern
0)
10854 ;; move entry to the beginning of the
10855 ;; list, so if two patterns used the
10856 ;; same number of times then the one
10857 ;; used last appears first in the list
10858 (setcdr selection-info
10859 (delete found
(cdr selection-info
)))
10861 (cdr selection-info
)))
10862 (cadr selection-info
))))
10864 ;; increase usage count
10865 (setcdr pattern-info
(1+ (cdr pattern-info
)))
10867 ;; truncate history if needed
10868 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
10869 (setcdr selection-info
10870 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
10872 (defun anything-c-adaptative-maybe-load-history ()
10873 (when (and anything-c-use-adaptative-sorting
10874 (file-readable-p anything-c-adaptive-history-file
))
10875 (load-file anything-c-adaptive-history-file
)))
10877 (add-hook 'emacs-startup-hook
'anything-c-adaptative-maybe-load-history
)
10878 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
10880 (defun anything-c-adaptive-save-history (&optional arg
)
10881 "Save history information to file given by `anything-c-adaptive-history-file'."
10883 (when anything-c-use-adaptative-sorting
10886 ";; -*- mode: emacs-lisp -*-\n"
10887 ";; History entries used for anything adaptive display.\n")
10888 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
10891 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10892 (unless arg
'quiet
)))))
10894 (defun anything-c-adaptive-sort (candidates source
)
10895 "Sort the CANDIDATES for SOURCE by usage frequency.
10896 This is a filtered candidate transformer you can use for the
10897 attribute `filtered-candidate-transformer' of a source in
10898 `anything-sources' or a type in `anything-type-attributes'."
10899 (let* ((source-name (or (assoc-default 'type source
)
10900 (assoc-default 'name source
)))
10901 (source-info (assoc source-name anything-c-adaptive-history
)))
10904 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10906 (mapcar (lambda (candidate-info)
10908 (dolist (pattern-info (cdr candidate-info
))
10909 (if (not (equal (car pattern-info
)
10911 (incf count
(cdr pattern-info
))
10913 ;; if current pattern is equal to the previously
10914 ;; used one then this candidate has priority
10915 ;; (that's why its count is boosted by 10000) and
10916 ;; it only has to compete with other candidates
10917 ;; which were also selected with the same pattern
10918 (setq count
(+ 10000 (cdr pattern-info
)))
10920 (cons (car candidate-info
) count
)))
10921 (cdr source-info
)))
10923 (if (and usage
(consp usage
))
10924 ;; sort the list in descending order, so candidates with highest
10925 ;; priorty come first
10927 (setq usage
(sort usage
(lambda (first second
)
10928 (> (cdr first
) (cdr second
)))))
10930 ;; put those candidates first which have the highest usage count
10931 (dolist (info usage
)
10932 (when (member* (car info
) candidates
10933 :test
'anything-c-adaptive-compare
)
10934 (push (car info
) sorted
)
10935 (setq candidates
(remove* (car info
) candidates
10936 :test
'anything-c-adaptive-compare
))))
10938 ;; and append the rest
10939 (append (reverse sorted
) candidates nil
))
10940 (message "Your `%s' is maybe corrupted or too old, \
10941 you should reinitialize it with `anything-c-reset-adaptative-history'"
10942 anything-c-adaptive-history-file
)
10945 ;; if there is no information stored for this source then do nothing
10949 (defun anything-c-reset-adaptative-history ()
10950 "Delete all `anything-c-adaptive-history' and his file.
10951 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10953 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10954 (setq anything-c-adaptive-history nil
)
10955 (delete-file anything-c-adaptive-history-file
)))
10957 (defun anything-c-adaptive-compare (x y
)
10958 "Compare candidates X and Y taking into account that the
10959 candidate can be in (DISPLAY . REAL) format."
10960 (equal (if (listp x
)
10972 (defvar anything-outline-goto-near-line-flag t
)
10973 (defvar anything-outline-using nil
)
10974 (defun anything-after-update-hook--outline ()
10975 (if (and (eq anything-outline-using t
)
10976 (eq anything-outline-goto-near-line-flag t
))
10977 (anything-outline-goto-near-line)))
10978 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
10980 (defun anything-outline-goto-near-line ()
10981 (with-anything-window
10982 ;; TODO need consideration whether to update position by every input.
10983 (when t
; (equal anything-pattern "")
10984 (anything-goto-line 2)
10985 (let ((lineno (with-anything-current-buffer
10986 (line-number-at-pos (car anything-current-position
)))))
10988 (while (<= (progn (skip-chars-forward " ")
10989 (or (number-at-point) lineno
))
10994 (return-from exit
))))
10996 (and (bobp) (forward-line 1))
10997 (and (anything-pos-header-line-p) (forward-line -
2))
10998 (anything-mark-current-line)))))
11005 ;; Plug-in: info-index
11006 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
11008 (unless (anything-candidate-buffer)
11009 (save-window-excursion
11012 (tobuf (anything-candidate-buffer 'global
))
11013 (infobuf (current-buffer))
11015 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
11016 (Info-goto-node node
)
11017 (goto-char (point-min))
11018 (while (search-forward "\n* " nil t
)
11019 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
11020 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
11021 (setq s
(point-at-bol)
11023 (with-current-buffer tobuf
11024 (insert-buffer-substring infobuf s e
)
11025 (insert "\n"))))))))))
11027 (defun anything-c-info-goto (node-line)
11028 (Info-goto-node (car node-line
))
11029 (anything-goto-line (cdr node-line
)))
11031 (defun anything-c-info-display-to-real (line)
11033 ;; This regexp is stolen from Info-apropos-matches
11034 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
11035 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
11036 (string-to-number (or (match-string 3 line
) "1")))))
11038 (defun anything-c-make-info-source (source file
)
11040 (name .
,(concat "Info Index: " file
))
11041 (info-file .
,file
)
11042 (init . anything-c-info-init
)
11043 (display-to-real . anything-c-info-display-to-real
)
11044 (get-line . buffer-substring
)
11045 (candidates-in-buffer)
11046 (action ("Goto node" . anything-c-info-goto
))))
11048 (defun anything-compile-source--info-index (source)
11049 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
11050 (anything-c-make-info-source source it
)
11052 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
11054 (anything-document-attribute 'info-index
"info-index plugin"
11055 "Create a source of info index very easily.
11057 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11059 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
11060 "Index nodes of info file.
11062 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11063 Some info files are missing index specification.
11065 ex. See `anything-c-source-info-screen'.")
11067 ;; Plug-in: candidates-file
11068 (defun anything-compile-source--candidates-file (source)
11069 (if (assoc-default 'candidates-file source
)
11070 `((init anything-p-candidats-file-init
11071 ,@(let ((orig-init (assoc-default 'init source
)))
11072 (cond ((null orig-init
) nil
)
11073 ((functionp orig-init
) (list orig-init
))
11075 (candidates-in-buffer)
11078 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
11080 (defun anything-p-candidats-file-init ()
11081 (destructuring-bind (file &optional updating
)
11082 (anything-mklist (anything-attr 'candidates-file
))
11083 (setq file
(anything-interpret-value file
))
11084 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
11086 (buffer-disable-undo)
11087 (font-lock-mode -
1)
11088 (auto-revert-mode 1)))))
11090 (anything-document-attribute 'candidates-file
"candidates-file plugin"
11091 "Use a file as the candidates buffer.
11093 1st argument is a filename, string or function name or variable name.
11094 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11096 ;; Plug-in: headline
11097 (defun anything-compile-source--anything-headline (source)
11098 (if (assoc-default 'headline source
)
11099 (append '((init . anything-headline-init
)
11100 (get-line . buffer-substring
)
11103 '((candidates-in-buffer)
11104 (persistent-help .
"Show this line")))
11106 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
11108 (defun anything-headline-init ()
11109 (when (and (anything-current-buffer-is-modified)
11110 (with-anything-current-buffer
11111 (eval (or (anything-attr 'condition
) t
))))
11112 (anything-headline-make-candidate-buffer
11113 (anything-interpret-value (anything-attr 'headline
))
11114 (anything-interpret-value (anything-attr 'subexp
)))))
11116 (anything-document-attribute 'headline
"Headline plug-in"
11117 "Regexp string for anything-headline to scan.")
11118 (anything-document-attribute 'condition
"Headline plug-in"
11119 "A sexp representing the condition to use anything-headline.")
11120 (anything-document-attribute 'subexp
"Headline plug-in"
11121 "Display (match-string-no-properties subexp).")
11123 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11126 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11127 ;; 2. Sort this list by start-of-match.
11128 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11130 ;; It's quite brilliantly written.
11134 (defun anything-headline-get-candidates (regexp subexp
)
11135 (with-anything-current-buffer
11137 (goto-char (point-min))
11138 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
11139 (let (hierarchy curhead
)
11141 (if (numberp subexp
)
11142 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
11143 (cons (buffer-substring (point-at-bol) (point-at-eol))
11145 (hierarchies (headlines)
11146 (1+ (loop for
(_ . hierarchy
) in headlines
11147 maximize hierarchy
)))
11149 (loop for i from
0 to hierarchy
11150 collecting
(aref curhead i
)))
11151 (arrange (headlines)
11152 (unless (null headlines
) ; FIX headlines empty bug!
11153 (loop with curhead
= (make-vector (hierarchies headlines
) "")
11154 for
((str . pt
) . hierarchy
) in headlines
11155 do
(aset curhead hierarchy str
)
11158 (format "H%d:%s" (1+ hierarchy
)
11159 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
11164 (loop for re in regexp
11165 for hierarchy from
0
11166 do
(goto-char (point-min))
11169 while
(re-search-forward re nil t
)
11170 collect
(cons (matched) hierarchy
)))
11171 (lambda (a b
) (> (cdar b
) (cdar a
)))))
11172 (loop while
(re-search-forward regexp nil t
)
11173 collect
(matched))))))))
11176 (defun anything-headline-make-candidate-buffer (regexp subexp
)
11177 (with-current-buffer (anything-candidate-buffer 'local
)
11178 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
11181 (with-anything-current-buffer
11182 (line-number-at-pos pos
))
11185 (defun anything-headline-goto-position (pos recenter
)
11188 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
11191 ;; Plug-in: persistent-help
11192 (defun anything-compile-source--persistent-help (source)
11193 (append source
'((header-line . anything-persistent-help-string
))))
11194 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
11196 (defun anything-persistent-help-string ()
11197 (substitute-command-keys
11198 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11199 (or (anything-interpret-value (anything-attr 'persistent-help
))
11200 (anything-aif (or (assoc-default 'persistent-action
11201 (anything-get-current-source))
11202 (assoc-default 'action
11203 (anything-get-current-source)))
11204 (cond ((symbolp it
) (symbol-name it
))
11205 ((listp it
) (or (ignore-errors (caar it
)) ""))))
11207 " (keeping session)")))
11209 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
11210 "A string to explain persistent-action of this source.
11211 It also accepts a function or a variable name.")
11213 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11215 ;; Plug-in: Type customize
11216 (defun anything-c-uniq-list (lst)
11217 "Like `remove-duplicates' in CL.
11218 But cut deeper duplicates and test by `equal'. "
11219 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
11220 (defvar anything-additional-type-attributes nil
)
11221 (defun anything-c-arrange-type-attribute (type spec
)
11222 "Override type attributes by `define-anything-type-attribute'.
11224 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11226 Example: Set `play-sound-file' as default action
11227 (anything-c-arrange-type-attribute 'file
11228 '((action (\"Play sound\" . play-sound-file)
11229 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11232 (add-to-list 'anything-additional-type-attributes
11234 (loop with typeattr
= (assoc-default type anything-type-attributes
)
11235 for
(attr . value
) in spec
11238 (anything-c-uniq-list
11239 (loop for v in value
11241 append
(assoc-default attr typeattr
)
11245 collect
(cons attr value
)))))
11246 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
11248 (defun anything-compile-source--type-customize (source)
11249 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
11252 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
11254 ;; Plug-in: default-action
11255 (defun anything-compile-source--default-action (source)
11256 (anything-aif (assoc-default 'default-action source
)
11257 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
11260 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
11261 (anything-document-attribute 'default-action
"default-action plug-in"
11265 ;;; Toggle anything-match-plugin
11268 (defvar anything-mp-initial-highlight-delay nil
)
11271 (defun anything-c-toggle-match-plugin ()
11272 "Toggle anything-match-plugin."
11274 (let ((anything-match-plugin-enabled
11275 (member 'anything-compile-source--match-plugin
11276 anything-compile-source-functions
)))
11277 (flet ((disable-match-plugin ()
11278 (setq anything-compile-source-functions
11279 (delq 'anything-compile-source--match-plugin
11280 anything-compile-source-functions
))
11281 (setq anything-mp-initial-highlight-delay
11282 anything-mp-highlight-delay
)
11283 (setq anything-mp-highlight-delay nil
))
11284 (enable-match-plugin ()
11285 (require 'anything-match-plugin
)
11286 (unless anything-mp-initial-highlight-delay
11287 (setq anything-mp-initial-highlight-delay
11288 anything-mp-highlight-delay
))
11289 (setq anything-compile-source-functions
11290 (cons 'anything-compile-source--match-plugin
11291 anything-compile-source-functions
))
11292 (unless anything-mp-highlight-delay
11293 (setq anything-mp-highlight-delay
11294 anything-mp-initial-highlight-delay
))))
11295 (if anything-match-plugin-enabled
11296 (when (y-or-n-p "Really disable match-plugin? ")
11297 (disable-match-plugin)
11298 (message "Anything-match-plugin disabled"))
11299 (when (y-or-n-p "Really enable match-plugin? ")
11300 (enable-match-plugin)
11301 (message "Anything-match-plugin enabled"))))))
11305 ;;; Type Attributes
11308 (define-anything-type-attribute 'buffer
11310 ("Switch to buffer" . anything-c-switch-to-buffer
)
11311 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin
:popup-buffer
))
11312 ("Switch to buffer other window" . switch-to-buffer-other-window
)
11313 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)
11314 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
11315 ("Query replace regexp" . anything-c-buffer-query-replace-regexp
)
11316 ("Query replace" . anything-c-buffer-query-replace
)
11317 ("View buffer" . view-buffer
)
11318 ("Display buffer" . display-buffer
)
11319 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers
)
11320 ("Revert buffer(s)" . anything-revert-marked-buffers
)
11321 ("Insert buffer" . insert-buffer
)
11322 ("Kill buffer(s)" . anything-kill-marked-buffers
)
11323 ("Diff with file" . diff-buffer-with-file
)
11324 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
11325 ("Ediff Merge marked buffers" .
(lambda (candidate)
11326 (anything-ediff-marked-buffers candidate t
))))
11327 (persistent-help .
"Show this buffer")
11328 (candidate-transformer anything-c-skip-current-buffer
11329 anything-c-skip-boring-buffers
11330 anything-c-transform-buffer-display-string
))
11331 "Buffer or buffer name.")
11333 (define-anything-type-attribute 'file
11335 ("Find file" . anything-find-many-files
)
11336 ,(and (locate-library "popwin") '("Find file in popup window" . popwin
:find-file
))
11337 ("Find file as root" . anything-find-file-as-root
)
11338 ("Find file other window" . find-file-other-window
)
11339 ("Find file other frame" . find-file-other-frame
)
11340 ("Open dired in file's directory" . anything-c-open-dired
)
11341 ("Grep File(s) `C-u recurse'" . anything-find-files-grep
)
11342 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep
)
11343 ("Pdfgrep File(s)" . anything-ff-pdfgrep
)
11344 ("Checksum File" . anything-ff-checksum
)
11345 ("Ediff File" . anything-find-files-ediff-files
)
11346 ("Ediff Merge File" . anything-find-files-ediff-merge-files
)
11347 ("View file" . view-file
)
11348 ("Insert file" . insert-file
)
11349 ("Delete file(s)" . anything-delete-marked-files
)
11350 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
11351 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
11352 ("Find file in hex dump" . hexl-find-file
))
11353 (persistent-help .
"Show this file")
11354 (action-transformer anything-c-transform-file-load-el
11355 anything-c-transform-file-browse-url
)
11356 (candidate-transformer anything-c-w32-pathname-transformer
11357 anything-c-skip-current-file
11358 anything-c-skip-boring-files
11359 anything-c-shorten-home-path
))
11362 (let ((actions '(("Describe command" . describe-function
)
11363 ("Add command to kill ring" . anything-c-kill-new
)
11364 ("Go to command's definition" . find-function
)
11365 ("Debug on entry" . debug-on-entry
)
11366 ("Cancel debug on entry" . cancel-debug-on-entry
)
11367 ("Trace function" . trace-function
)
11368 ("Trace function (background)" . trace-function-background
)
11369 ("Untrace function" . untrace-function
))))
11370 (define-anything-type-attribute 'command
11371 `((action ("Call interactively" . anything-c-call-interactively
)
11373 ;; Sort commands according to their usage count.
11374 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11375 (coerce . anything-c-symbolify
)
11376 (persistent-action . describe-function
))
11377 "Command. (string or symbol)")
11379 (define-anything-type-attribute 'function
11380 `((action .
,actions
)
11381 (action-transformer anything-c-transform-function-call-interactively
)
11382 (candidate-transformer anything-c-mark-interactive-functions
)
11383 (coerce . anything-c-symbolify
))
11384 "Function. (string or symbol)"))
11386 (define-anything-type-attribute 'variable
11387 '((action ("Describe variable" . describe-variable
)
11388 ("Add variable to kill ring" . anything-c-kill-new
)
11389 ("Go to variable's definition" . find-variable
)
11390 ("Set variable" . anything-c-set-variable
))
11391 (coerce . anything-c-symbolify
))
11394 (define-anything-type-attribute 'sexp
11395 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
11396 ("Add s-expression to kill ring" . kill-new
))
11397 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
11398 "String representing S-Expressions.")
11400 (define-anything-type-attribute 'bookmark
11401 `((coerce . anything-bookmark-get-bookmark-from-name
)
11403 ("Jump to bookmark" .
(lambda (bookmark)
11404 (let ((current-prefix-arg anything-current-prefix-arg
))
11405 (bookmark-jump bookmark
))
11406 (anything-update)))
11407 ("Jump to BM other window" .
(lambda (bookmark)
11408 (bookmark-jump-other-window bookmark
)
11409 (anything-update)))
11410 ("Bookmark edit annotation" . bookmark-edit-annotation
)
11411 ("Bookmark show annotation" . bookmark-show-annotation
)
11412 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
11413 ,@(and (locate-library "bookmark-extensions")
11414 `(("Edit Bookmark" . bmkext-edit-bookmark
)))
11415 ("Rename bookmark" . bookmark-rename
)
11416 ("Relocate bookmark" . bookmark-relocate
)))
11419 (define-anything-type-attribute 'line
11420 '((display-to-real . anything-c-display-to-real-line
)
11421 (action ("Go to Line" . anything-c-action-line-goto
)))
11422 "LINENO:CONTENT string, eg. \" 16:foo\".
11424 Optional `target-file' attribute is a name of target file.
11426 Optional `before-jump-hook' attribute is a function with no
11427 arguments which is called before jumping to position.
11429 Optional `after-jump-hook' attribute is a function with no
11430 arguments which is called after jumping to position.
11432 If `adjust' attribute is specified, searches the line whose
11433 content is CONTENT near the LINENO.
11435 If `recenter' attribute is specified, the line is displayed at
11436 the center of window, otherwise at the top of window.
11439 (define-anything-type-attribute 'file-line
11440 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
11442 (action ("Go to" . anything-c-action-file-line-goto
)))
11443 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11445 Optional `default-directory' attribute is a default-directory
11446 FILENAME is interpreted.
11448 Optional `before-jump-hook' attribute is a function with no
11449 arguments which is called before jumping to position.
11451 Optional `after-jump-hook' attribute is a function with no
11452 arguments which is called after jumping to position.
11454 If `adjust' attribute is specified, searches the line whose
11455 content is CONTENT near the LINENO.
11457 If `recenter' attribute is specified, the line is displayed at
11458 the center of window, otherwise at the top of window.
11461 (define-anything-type-attribute 'timer
11462 '((real-to-display . anything-c-timer-real-to-display
)
11463 (action ("Cancel Timer" . cancel-timer
)
11464 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
11465 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
11466 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
11467 (persistent-help .
"Describe Function"))
11471 ;;; Default `anything-sources'
11472 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11473 ;; tend to invoke M-x anything directly. So I offer default setting.
11474 (setq anything-sources
11475 '(anything-c-source-buffers-list
11476 anything-c-source-recentf
11477 anything-c-source-files-in-current-dir
+))
11480 ;;; Preconfigured Anything
11484 (defun anything-mini ()
11485 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11487 (anything-other-buffer '(anything-c-source-buffers-list
11488 anything-c-source-recentf
11489 anything-c-source-buffer-not-found
)
11490 "*anything mini*"))
11492 (defun anything-for-files ()
11493 "Preconfigured `anything' for opening files.
11494 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11496 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
11499 (defun anything-recentf ()
11500 "Preconfigured `anything' for `recentf'."
11502 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
11505 (defun anything-info-at-point (arg)
11506 "Preconfigured `anything' for searching info at point.
11507 With a prefix-arg insert symbol at point."
11509 (let ((anything-c-google-suggest-default-function
11510 'anything-c-google-suggest-emacs-lisp
))
11511 (anything :sources
'(anything-c-source-info-elisp
11512 anything-c-source-info-cl
11513 anything-c-source-info-pages
11514 anything-c-source-google-suggest
)
11515 :input
(and arg
(thing-at-point 'symbol
))
11516 :buffer
"*anything info*")))
11519 (defun anything-info-emacs ()
11520 "Preconfigured anything for Emacs manual index."
11522 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
11525 (defun anything-show-kill-ring ()
11526 "Preconfigured `anything' for `kill-ring'.
11527 It is drop-in replacement of `yank-pop'.
11528 You may bind this command to M-y.
11529 First call open the kill-ring browser, next calls move to next line."
11531 (let ((buf "*anything kill-ring*"))
11532 (if (get-buffer-window buf
)
11533 (with-anything-window
11534 (if (eq (overlay-end anything-selection-overlay
) (point-max))
11535 (anything-beginning-of-buffer)
11536 (anything-next-line)))
11537 (anything-other-buffer 'anything-c-source-kill-ring buf
))))
11540 (defun anything-minibuffer-history ()
11541 "Preconfigured `anything' for `minibuffer-history'."
11543 (let ((enable-recursive-minibuffers t
))
11544 (anything-other-buffer 'anything-c-source-minibuffer-history
11545 "*anything minibuffer-history*")))
11548 (defun anything-gentoo ()
11549 "Preconfigured `anything' for gentoo linux."
11551 (anything-other-buffer '(anything-c-source-gentoo
11552 anything-c-source-use-flags
)
11553 "*anything gentoo*"))
11556 (defun anything-imenu ()
11557 "Preconfigured `anything' for `imenu'."
11559 (anything :sources
'anything-c-source-imenu
11560 :buffer
"*anything imenu*"))
11563 (defun anything-google-suggest ()
11564 "Preconfigured `anything' for google search with google suggest."
11566 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
11569 (defun anything-yahoo-suggest ()
11570 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11572 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
11574 ;;; Converted from anything-show-*-only
11576 (defun anything-for-buffers ()
11577 "Preconfigured `anything' for buffer."
11579 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
11582 (defun anything-buffers-list ()
11583 "Enhanced preconfigured `anything' for buffer."
11585 (anything :sources
'(anything-c-source-buffers-list
11586 anything-c-source-buffer-not-found
)
11587 :buffer
"*anything buffers*" :keymap anything-c-buffer-map
))
11590 (defun anything-bbdb ()
11591 "Preconfigured `anything' for BBDB.
11595 http://bbdb.sourceforge.net/"
11597 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
11600 (defun anything-locate (arg)
11601 "Preconfigured `anything' for Locate.
11602 Note: you can add locate options after entering pattern.
11603 See 'man locate' for valid options.
11605 You can specify a specific database with prefix argument ARG \(C-u\).
11606 Many databases can be used: navigate and mark them.
11607 See also `anything-locate-with-db'.
11609 To create a user specific db, use
11610 \"updatedb -l 0 -o db_path -U directory\".
11611 Where db_path is a filename matched by
11612 `anything-locate-db-file-regexp'."
11614 (anything-locate-1 arg
))
11617 (defun anything-w3m-bookmarks ()
11618 "Preconfigured `anything' for w3m bookmark.
11620 Needs w3m and emacs-w3m.
11622 http://w3m.sourceforge.net/
11623 http://emacs-w3m.namazu.org/"
11625 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11626 "*anything w3m bookmarks*"))
11629 (defun anything-firefox-bookmarks ()
11630 "Preconfigured `anything' for firefox bookmark.
11631 You will have to enable html bookmarks in firefox:
11632 open about:config in firefox and double click on this line to enable value \
11635 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11637 You should have now:
11639 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11641 After closing firefox, you will be able to browse you bookmarks.
11644 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11645 "*Anything Firefox*"))
11648 (defun anything-colors ()
11649 "Preconfigured `anything' for color."
11651 (anything-other-buffer
11652 '(anything-c-source-colors anything-c-source-customize-face
)
11653 "*anything colors*"))
11656 (defun anything-bookmarks ()
11657 "Preconfigured `anything' for bookmarks."
11659 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
11662 (defun anything-c-pp-bookmarks ()
11663 "Preconfigured `anything' for bookmarks (pretty-printed)."
11665 (anything-other-buffer '(anything-c-source-bookmarks-local
11666 anything-c-source-bookmarks-su
11667 anything-c-source-bookmarks-ssh
)
11668 "*anything pp bookmarks*"))
11671 (defun anything-c-insert-latex-math ()
11672 "Preconfigured anything for latex math symbols completion."
11674 (anything-other-buffer 'anything-c-source-latex-math
"*anything latex*"))
11677 (defun anything-register ()
11678 "Preconfigured `anything' for Emacs registers."
11680 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
11683 (defun anything-man-woman ()
11684 "Preconfigured `anything' for Man and Woman pages."
11686 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
11689 (defun anything-org-keywords ()
11690 "Preconfigured `anything' for org keywords."
11692 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
11695 (defun anything-emms ()
11696 "Preconfigured `anything' for emms sources."
11698 (anything :sources
'(anything-c-source-emms-streams
11699 anything-c-source-emms-files
11700 anything-c-source-emms-dired
)
11701 :buffer
"*Anything Emms*"))
11704 (defun anything-eev-anchors ()
11705 "Preconfigured `anything' for eev anchors."
11707 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
11710 (defun anything-bm-list ()
11711 "Preconfigured `anything' for visible bookmarks.
11715 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11717 (let ((anything-outline-using t
))
11718 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
11721 (defun anything-timers ()
11722 "Preconfigured `anything' for timers."
11724 (anything-other-buffer '(anything-c-source-absolute-time-timers
11725 anything-c-source-idle-time-timers
)
11726 "*anything timers*"))
11729 (defun anything-list-emacs-process ()
11730 "Preconfigured `anything' for emacs process."
11732 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
11735 (defun anything-occur ()
11736 "Preconfigured Anything for Occur source.
11737 If region is active, search only in region,
11738 otherwise search in whole buffer."
11740 (let ((anything-compile-source-functions
11741 ;; rule out anything-match-plugin because the input is one regexp.
11742 (delq 'anything-compile-source--match-plugin
11743 (copy-sequence anything-compile-source-functions
))))
11744 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
11747 (defun anything-browse-code ()
11748 "Preconfigured anything to browse code."
11750 (anything :sources
'anything-c-source-browse-code
11751 :buffer
"*anything browse code*"
11752 :default
(thing-at-point 'symbol
)))
11755 (defun anything-org-headlines ()
11756 "Preconfigured anything to show org headlines."
11758 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
11761 (defun anything-info-gnus ()
11762 "Preconfigured anything to browse Gnus Manual."
11764 (anything-other-buffer 'anything-c-source-info-gnus
"*info Gnus*"))
11767 (defun anything-regexp ()
11768 "Preconfigured anything to build regexps.
11769 `query-replace-regexp' can be run from there against found regexp."
11772 (let ((anything-compile-source-functions
11773 ;; rule out anything-match-plugin because the input is one regexp.
11774 (delq 'anything-compile-source--match-plugin
11775 (copy-sequence anything-compile-source-functions
))))
11776 (when (and (anything-region-active-p)
11777 ;; Don't narrow to region if buffer is already narrowed.
11778 (not (anything-current-buffer-narrowed-p)))
11779 (narrow-to-region (region-beginning) (region-end)))
11780 (anything :sources anything-c-source-regexp
11781 :buffer
"*anything regexp*"
11783 :history
'anything-build-regexp-history
))))
11785 (defun anything-c-copy-files-async ()
11786 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11788 (let* ((flist (anything-c-read-file-name
11789 "Copy File async: "
11790 :marked-candidates t
))
11791 (dest (anything-c-read-file-name
11792 "Copy File async To: "
11793 :preselect
(car flist
)
11794 :initial-input
(car anything-ff-history
)
11795 :history
(anything-find-files-history :comp-read nil
))))
11796 (anything-c-copy-async-with-log flist dest
)))
11799 (defun anything-find-files (arg)
11800 "Preconfigured `anything' for anything implementation of `find-file'.
11801 Called with a prefix arg show history if some.
11802 Don't call it from programs, use `anything-find-files-1' instead.
11803 This is the starting point for nearly all actions you can do on files."
11805 (let ((any-input (if (and arg anything-ff-history
)
11806 (anything-find-files-history)
11807 (anything-find-files-initial-input)))
11808 (presel (buffer-file-name (current-buffer))))
11809 (when (and (eq major-mode
'org-agenda-mode
)
11812 (setq any-input
(expand-file-name org-directory
)))
11813 (set-text-properties 0 (length any-input
) nil any-input
)
11815 (anything-find-files-1 any-input
)
11816 (setq any-input
(expand-file-name (anything-c-current-directory)))
11817 (anything-find-files-1
11818 any-input
(if anything-ff-transformer-show-only-basename
11819 (and presel
(anything-c-basename presel
))
11823 (defun anything-write-file ()
11824 "Preconfigured `anything' providing completion for `write-file'."
11826 (let ((anything-mp-highlight-delay nil
))
11827 (anything :sources
'anything-c-source-write-file
11828 :input
(expand-file-name default-directory
)
11829 :prompt
"Write buffer to file: "
11830 :buffer
"*Anything write file*")))
11833 (defun anything-insert-file ()
11834 "Preconfigured `anything' providing completion for `insert-file'."
11836 (let ((anything-mp-highlight-delay nil
))
11837 (anything :sources
'anything-c-source-insert-file
11838 :input
(expand-file-name default-directory
)
11839 :prompt
"Insert file: "
11840 :buffer
"*Anything insert file*")))
11843 (defun anything-dired-rename-file ()
11844 "Preconfigured `anything' to rename files from dired."
11846 (anything-dired-do-action-on-file :action
'rename
))
11849 (defun anything-dired-copy-file ()
11850 "Preconfigured `anything' to copy files from dired."
11852 (anything-dired-do-action-on-file :action
'copy
))
11855 (defun anything-dired-symlink-file ()
11856 "Preconfigured `anything' to symlink files from dired."
11858 (anything-dired-do-action-on-file :action
'symlink
))
11861 (defun anything-dired-hardlink-file ()
11862 "Preconfigured `anything' to hardlink files from dired."
11864 (anything-dired-do-action-on-file :action
'hardlink
))
11867 (defun anything-do-grep ()
11868 "Preconfigured anything for grep.
11869 Contrarily to Emacs `grep' no default directory is given, but
11870 the full path of candidates in ONLY.
11871 That allow to grep different files not only in `default-directory' but anywhere
11872 by marking them (C-<SPACE>). If one or more directory is selected
11873 grep will search in all files of these directories.
11874 You can use also wildcard in the base name of candidate.
11875 If a prefix arg is given use the -r option of grep.
11876 The prefix arg can be passed before or after start.
11877 See also `anything-do-grep-1'."
11879 (let ((only (anything-c-read-file-name
11880 "Search in file(s): "
11881 :marked-candidates t
11882 :preselect
(or (dired-get-filename nil t
)
11883 (buffer-file-name (current-buffer)))))
11884 (prefarg (or current-prefix-arg anything-current-prefix-arg
)))
11885 (anything-do-grep-1 only prefarg
)))
11888 (defun anything-do-zgrep (candidate)
11889 "Preconfigured anything for zgrep."
11890 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
11891 (ls (anything-c-read-file-name
11892 "Search in file(s): "
11893 :marked-candidates t
11894 :preselect
(or (dired-get-filename nil t
)
11895 (buffer-file-name (current-buffer))))))
11896 (anything-ff-zgrep-1 ls prefarg
)))
11898 (defun anything-c-etags-select (arg)
11899 "Preconfigured anything for etags.
11900 Called with one prefix arg use symbol at point as initial input.
11901 Called with two prefix arg reinitialize cache.
11902 If tag file have been modified reinitialize cache."
11904 (let ((tag (anything-c-etags-get-tag-file))
11905 (init (and (equal arg
'(4)) (thing-at-point 'symbol
)))
11906 (anything-quit-if-no-candidate t
)
11907 (anything-execute-action-at-once-if-one t
)
11908 (anything-compile-source-functions
11909 (if anything-c-etags-use-regexp-search
11910 ;; rule out anything-match-plugin because the input is one regexp.
11911 (delq 'anything-compile-source--match-plugin
11912 (copy-sequence anything-compile-source-functions
))
11913 anything-compile-source-functions
)))
11914 (when (or (equal arg
'(16))
11915 (and anything-c-etags-mtime-alist
11916 (anything-c-etags-file-modified-p tag
)))
11917 (remhash tag anything-c-etags-cache
))
11918 (if (and tag
(file-exists-p tag
))
11919 (anything :sources
'anything-c-source-etags-select
11920 :keymap anything-c-etags-map
11922 :buffer
"*anything etags*")
11923 (message "Error: No tag file found, please create one with etags shell command."))))
11926 (defun anything-filelist ()
11927 "Preconfigured `anything' to open files instantly.
11929 See `anything-c-filelist-file-name' docstring for usage."
11931 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
11934 (defun anything-filelist+ ()
11935 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11937 This is a replacement for `anything-for-files'.
11938 See `anything-c-filelist-file-name' docstring for usage."
11940 (anything-other-buffer
11941 '(anything-c-source-ffap-line
11942 anything-c-source-ffap-guesser
11943 anything-c-source-buffers-list
11944 anything-c-source-recentf
11945 anything-c-source-bookmarks
11946 anything-c-source-file-cache
11947 anything-c-source-filelist
)
11948 "*anything file list*"))
11951 (defun anything-M-x ()
11952 "Preconfigured `anything' for Emacs commands.
11953 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11957 special-display-buffer-names
11958 special-display-regexps
11959 anything-persistent-action-use-special-display
11960 (history (loop with hist
11961 for i in extended-command-history
11962 for com
= (intern i
)
11964 collect i into hist finally return hist
)))
11965 (flet ((pers-help (candidate)
11966 (let ((hbuf (get-buffer (help-buffer))))
11967 (if (and in-help
(string= candidate help-cand
))
11969 ;; When M-x is started from a help buffer,
11970 ;; Don't kill it as it is anything-current-buffer.
11971 (unless (equal hbuf anything-current-buffer
)
11972 (kill-buffer hbuf
))
11973 (setq in-help nil
))
11974 ;; Be sure anything-current-buffer
11975 ;; have not a dedicated window.
11976 (set-window-dedicated-p
11977 (get-buffer-window anything-current-buffer
) nil
)
11978 (describe-function (intern candidate
))
11979 (message nil
) ; Erase the new stupid message Type "q"[...]
11981 (setq help-cand candidate
))))
11986 `(((name .
"Emacs Commands history")
11987 (candidates .
,history
)
11988 (filtered-candidate-transformer
11989 .
(lambda (candidates sources
)
11990 (loop for i in candidates
11991 do
(set-text-properties 0 (length i
) nil i
)
11993 (persistent-action . pers-help
)
11994 (persistent-help .
"Describe this command")
11995 (action . identity
))
11996 ((name .
"Emacs Commands")
11999 (with-current-buffer (anything-candidate-buffer 'global
)
12000 (goto-char (point-min))
12002 for sym in
(all-completions "" obarray
'commandp
)
12003 do
(insert (concat sym
"\n"))))))
12004 (persistent-action . pers-help
)
12005 (persistent-help .
"Describe this command")
12006 (filtered-candidate-transformer . anything-M-x-transformer
)
12007 (candidates-in-buffer)
12008 (action . identity
)))
12010 :history
'anything-M-x-input-history
12011 :buffer
"*anything M-x*")
12013 (sym-com (intern command
)))
12014 (unless current-prefix-arg
12015 (setq current-prefix-arg anything-current-prefix-arg
))
12016 ;; Avoid having `this-command' set to *exit-minibuffer.
12017 (setq this-command sym-com
)
12018 (call-interactively sym-com
)
12019 (setq extended-command-history
12020 (cons command
(delete command history
)))))))
12023 (defun anything-manage-advice ()
12024 "Preconfigured `anything' to disable/enable function advices."
12026 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
12029 (defun anything-bookmark-ext ()
12030 "Preconfigured `anything' for bookmark-extensions sources.
12031 Needs bookmark-ext.el:
12032 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
12033 Contain also `anything-c-source-google-suggest'."
12037 '(anything-c-source-bookmark-files&dirs
12038 anything-c-source-bookmark-w3m
12039 anything-c-source-google-suggest
12040 anything-c-source-bmkext-addressbook
12041 anything-c-source-bookmark-gnus
12042 anything-c-source-bookmark-info
12043 anything-c-source-bookmark-man
12044 anything-c-source-bookmark-images
12045 anything-c-source-bookmark-su-files
&dirs
12046 anything-c-source-bookmark-ssh-files
&dirs
)
12047 :prompt
"SearchBookmark: "
12048 :buffer
"*anything bmkext*"))
12051 (defun anything-simple-call-tree ()
12052 "Preconfigured `anything' for simple-call-tree. List function relationships.
12054 Needs simple-call-tree.el.
12055 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
12057 (anything-other-buffer
12058 '(anything-c-source-simple-call-tree-functions-callers
12059 anything-c-source-simple-call-tree-callers-functions
)
12060 "*anything simple-call-tree*"))
12063 (defun anything-mark-ring ()
12064 "Preconfigured `anything' for `anything-c-source-mark-ring'."
12066 (anything :sources
'anything-c-source-mark-ring
))
12069 (defun anything-global-mark-ring ()
12070 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12072 (anything :sources
'anything-c-source-global-mark-ring
))
12075 (defun anything-all-mark-rings ()
12076 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12077 `anything-c-source-mark-ring'."
12079 (anything :sources
'(anything-c-source-mark-ring
12080 anything-c-source-global-mark-ring
)))
12083 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12084 "Preconfigured `anything' to edit or view EmacsWiki page.
12086 Needs yaoddmuse.el.
12088 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12090 (anything :sources
'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
12093 (defun anything-yaoddmuse-emacswiki-post-library ()
12094 "Preconfigured `anything' to post library to EmacsWiki.
12096 Needs yaoddmuse.el.
12098 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12100 (anything :sources
'anything-c-source-yaoddmuse-emacswiki-post-library
))
12103 (defun anything-eval-expression (arg)
12104 "Preconfigured anything for `anything-c-source-evaluation-result'."
12106 (anything :sources
'anything-c-source-evaluation-result
12107 :input
(when arg
(thing-at-point 'sexp
))
12108 :buffer
"*anything eval*"
12109 :history
'anything-eval-expression-input-history
12110 :keymap anything-eval-expression-map
))
12113 (defun anything-eval-expression-with-eldoc ()
12114 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12116 (declare (special eldoc-idle-delay
))
12117 (let ((timer (run-with-idle-timer eldoc-idle-delay
12118 'repeat
'anything-eldoc-show-in-eval
))
12119 (minibuffer-completing-symbol t
) ; Enable lisp completion.
12120 (completion-cycle-threshold t
)) ; Always cycle, no pesty completion buffer (emacs24 only).
12122 (minibuffer-with-setup-hook
12123 'anything-eldoc-store-minibuffer
12124 (call-interactively 'anything-eval-expression
))
12125 (and timer
(cancel-timer timer
))
12126 (setq anything-eldoc-active-minibuffers-list
12127 (cdr anything-eldoc-active-minibuffers-list
)))))
12130 (defun anything-calcul-expression ()
12131 "Preconfigured anything for `anything-c-source-calculation-result'."
12133 (anything-other-buffer 'anything-c-source-calculation-result
"*anything calcul*"))
12136 (defun anything-surfraw (pattern engine
)
12137 "Preconfigured `anything' to search PATTERN with search ENGINE."
12138 (interactive (list (read-string "SearchFor: "
12139 nil
'anything-surfraw-input-history
)
12140 (anything-comp-read
12142 (anything-c-build-elvi-list)
12144 :name
"Surfraw Search Engines"
12145 :history anything-surfraw-engines-history
)))
12146 (let* ((engine-nodesc (car (split-string engine
)))
12147 (url (with-temp-buffer
12148 (apply 'call-process
"surfraw" nil t nil
12150 (append (list engine-nodesc
"-p") (split-string pattern
)))
12151 (replace-regexp-in-string
12152 "\n" "" (buffer-string))))
12153 (browse-url-browser-function (or anything-surfraw-default-browser-function
12154 browse-url-browser-function
)))
12155 (if (string= engine-nodesc
"W")
12156 (anything-c-browse-url)
12157 (anything-c-browse-url url
)
12158 (setq anything-surfraw-engines-history
12159 (cons engine
(delete engine anything-surfraw-engines-history
))))))
12162 (defun anything-call-source ()
12163 "Preconfigured `anything' to call anything source."
12165 (anything :sources
'anything-c-source-call-source
12166 :buffer anything-source-select-buffer
))
12169 (defun anything-execute-anything-command ()
12170 "Preconfigured `anything' to execute preconfigured `anything'."
12172 (anything-other-buffer 'anything-c-source-anything-commands
12173 "*anything commands*"))
12176 (defun anything-create (&optional string initial-input
)
12177 "Preconfigured `anything' to do many create actions from STRING.
12178 See also `anything-create--actions'."
12180 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
12181 (anything :sources
'(((name .
"Anything Create")
12182 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
12183 (candidates . anything-create--actions
)
12184 (candidate-number-limit)
12185 (action .
(lambda (func) (funcall func string
)))))))
12188 (defun anything-top ()
12189 "Preconfigured `anything' for top command."
12191 (let ((anything-samewindow t
)
12192 (anything-enable-shortcuts)
12193 (anything-display-function 'anything-default-display-buffer
)
12194 (anything-candidate-number-limit 9999))
12195 (save-window-excursion
12196 (delete-other-windows)
12197 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
12200 (defun anything-select-xfont ()
12201 "Preconfigured `anything' to select Xfont."
12203 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
12206 (defun anything-world-time ()
12207 "Preconfigured `anything' to show world time."
12209 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
12212 (defun anything-apt (arg)
12213 "Preconfigured `anything' : frontend of APT package manager.
12214 With a prefix arg reload cache."
12216 (let ((query (read-string "Search Package: " nil
'anything-c-apt-input-history
)))
12217 (when arg
(anything-c-apt-refresh))
12218 (anything :sources
'anything-c-source-apt
12219 :prompt
"Search Package: "
12221 :history
'anything-c-apt-input-history
)))
12224 (defun anything-esh-pcomplete ()
12225 "Preconfigured anything to provide anything completion in eshell."
12227 (let* ((anything-quit-if-no-candidate t
)
12228 (anything-execute-action-at-once-if-one t
)
12229 (target (thing-at-point 'symbol
))
12231 (beg (or (and target
(- end
(length target
)))
12232 ;; Nothing at point.
12233 (progn (insert " ") (point)))))
12234 (setq anything-ec-target
(or target
" "))
12235 (with-anything-show-completion beg end
12236 (anything :sources
'anything-c-source-esh
12237 :input
(anything-ff-set-pattern ; Handle tramp filenames.
12238 (car (last (ignore-errors ; Needed in lisp symbols completion.
12239 (pcomplete-parse-arguments)))))))))
12242 (defun anything-eshell-history ()
12243 "Preconfigured anything for eshell history."
12245 (let* ((end (point))
12246 (beg (save-excursion (eshell-bol) (point)))
12250 (setq flag-empty t
)
12251 (setq end
(point)))
12253 (with-anything-show-completion beg end
12254 (anything :sources
'anything-c-source-eshell-history
12255 :buffer
"*Eshell history*"))
12256 (when (and flag-empty
12257 (looking-back " "))
12258 (delete-char -
1)))))
12261 (defun anything-c-run-external-command (program)
12262 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12263 If program is already running exit with error.
12264 You can set your own list of commands with
12265 `anything-c-external-commands-list'."
12267 (anything-comp-read
12269 (anything-c-external-commands-list-1 'sort
)
12271 :name
"External Commands"
12272 :history anything-external-command-history
)))
12273 (anything-run-or-raise program
)
12274 (setq anything-external-command-history
12275 (cons program
(delete program
12276 (loop for i in anything-external-command-history
12277 when
(executable-find i
) collect i
)))))
12280 (defun anything-ratpoison-commands ()
12281 "Preconfigured `anything' to execute ratpoison commands."
12283 (anything-other-buffer 'anything-c-source-ratpoison-commands
12284 "*anything ratpoison commands*"))
12287 (defun anything-ucs ()
12288 "Preconfigured anything for `ucs-names' math symbols."
12290 (anything :sources
'anything-c-source-ucs
12291 :keymap anything-c-ucs-map
))
12294 (defun anything-c-apropos ()
12295 "Preconfigured anything to describe commands, functions, variables and faces."
12297 (let ((default (thing-at-point 'symbol
)))
12299 `(((name .
"Commands")
12301 (anything-c-apropos-init 'commandp
,default
)))
12302 (persistent-action . anything-lisp-completion-persistent-action
)
12303 (persistent-help .
"Show brief doc in mode-line")
12304 (candidates-in-buffer)
12305 (action .
(lambda (candidate)
12306 (describe-function (intern candidate
)))))
12307 ((name .
"Functions")
12309 (anything-c-apropos-init #'(lambda (x) (and (fboundp x
)
12310 (not (commandp x
))))
12312 (persistent-action . anything-lisp-completion-persistent-action
)
12313 (persistent-help .
"Show brief doc in mode-line")
12314 (candidates-in-buffer)
12315 (action .
(lambda (candidate)
12316 (describe-function (intern candidate
)))))
12317 ((name .
"Variables")
12319 (anything-c-apropos-init 'boundp
,default
)))
12320 (persistent-action . anything-lisp-completion-persistent-action
)
12321 (persistent-help .
"Show brief doc in mode-line")
12322 (candidates-in-buffer)
12323 (action .
(lambda (candidate)
12324 (describe-variable (intern candidate
)))))
12327 (anything-c-apropos-init 'facep
,default
)))
12328 (persistent-action . anything-lisp-completion-persistent-action
)
12329 (persistent-help .
"Show brief doc in mode-line")
12330 (candidates-in-buffer)
12331 (filtered-candidate-transformer .
(lambda (candidates source
)
12332 (loop for c in candidates
12333 collect
(propertize c
'face
(intern c
)))))
12334 (action .
(lambda (candidate)
12335 (describe-face (intern candidate
)))))
12336 ((name .
"Anything attributes")
12337 (candidates .
(lambda ()
12338 (mapcar 'symbol-name anything-additional-attributes
)))
12339 (action .
(lambda (candidate)
12340 (with-output-to-temp-buffer "*Help*"
12341 (princ (get (intern candidate
) 'anything-attrdoc
))))))))))
12344 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12347 (provide 'anything-config
)
12349 ;;; Local Variables:
12350 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12353 ;; How to save (DO NOT REMOVE!!)
12354 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12355 ;;; anything-config.el ends here
12357 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12358 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12359 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12360 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12361 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12362 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12363 ;;; LocalWords: dotimes Thierry online vname
12364 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12365 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12366 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12367 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12368 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12369 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12370 ;;; LocalWords: startpos noselect dont desc