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'.
106 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
107 ;; `anything-for-files'
108 ;; Preconfigured `anything' for opening files.
109 ;; `anything-recentf'
110 ;; Preconfigured `anything' for `recentf'.
111 ;; `anything-info-at-point'
112 ;; Preconfigured `anything' for searching info at point.
113 ;; `anything-info-emacs'
114 ;; Preconfigured anything for Emacs manual index.
115 ;; `anything-show-kill-ring'
116 ;; Preconfigured `anything' for `kill-ring'.
117 ;; `anything-minibuffer-history'
118 ;; Preconfigured `anything' for `minibuffer-history'.
120 ;; Preconfigured `anything' for gentoo linux.
122 ;; Preconfigured `anything' for `imenu'.
123 ;; `anything-google-suggest'
124 ;; Preconfigured `anything' for google search with google suggest.
125 ;; `anything-yahoo-suggest'
126 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
127 ;; `anything-for-buffers'
128 ;; Preconfigured `anything' for buffer.
129 ;; `anything-buffers-list'
130 ;; Enhanced preconfigured `anything' for buffer.
132 ;; Preconfigured `anything' for BBDB.
134 ;; Preconfigured `anything' for Locate.
135 ;; `anything-w3m-bookmarks'
136 ;; Preconfigured `anything' for w3m bookmark.
137 ;; `anything-firefox-bookmarks'
138 ;; Preconfigured `anything' for firefox bookmark.
140 ;; Preconfigured `anything' for color.
141 ;; `anything-bookmarks'
142 ;; Preconfigured `anything' for bookmarks.
143 ;; `anything-c-pp-bookmarks'
144 ;; Preconfigured `anything' for bookmarks (pretty-printed).
145 ;; `anything-c-insert-latex-math'
146 ;; Preconfigured anything for latex math symbols completion.
147 ;; `anything-register'
148 ;; Preconfigured `anything' for Emacs registers.
149 ;; `anything-man-woman'
150 ;; Preconfigured `anything' for Man and Woman pages.
151 ;; `anything-org-keywords'
152 ;; Preconfigured `anything' for org keywords.
154 ;; Preconfigured `anything' for emms sources.
155 ;; `anything-eev-anchors'
156 ;; Preconfigured `anything' for eev anchors.
157 ;; `anything-bm-list'
158 ;; Preconfigured `anything' for visible bookmarks.
160 ;; Preconfigured `anything' for timers.
161 ;; `anything-list-emacs-process'
162 ;; Preconfigured `anything' for emacs process.
164 ;; Preconfigured Anything for Occur source.
165 ;; `anything-browse-code'
166 ;; Preconfigured anything to browse code.
167 ;; `anything-org-headlines'
168 ;; Preconfigured anything to show org headlines.
169 ;; `anything-info-gnus'
170 ;; Preconfigured anything to browse Gnus Manual.
172 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
173 ;; `anything-c-copy-files-async'
174 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
175 ;; `anything-find-files'
176 ;; Preconfigured `anything' for anything implementation of `find-file'.
177 ;; `anything-write-file'
178 ;; Preconfigured `anything' providing completion for `write-file'.
179 ;; `anything-insert-file'
180 ;; Preconfigured `anything' providing completion for `insert-file'.
181 ;; `anything-dired-rename-file'
182 ;; Preconfigured `anything' to rename files from dired.
183 ;; `anything-dired-copy-file'
184 ;; Preconfigured `anything' to copy files from dired.
185 ;; `anything-dired-symlink-file'
186 ;; Preconfigured `anything' to symlink files from dired.
187 ;; `anything-dired-hardlink-file'
188 ;; Preconfigured `anything' to hardlink files from dired.
189 ;; `anything-do-grep'
190 ;; Preconfigured anything for grep.
191 ;; `anything-c-etags-select'
192 ;; Preconfigured anything for etags.
193 ;; `anything-filelist'
194 ;; Preconfigured `anything' to open files instantly.
195 ;; `anything-filelist+'
196 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
198 ;; Preconfigured `anything' for Emacs commands.
199 ;; `anything-manage-advice'
200 ;; Preconfigured `anything' to disable/enable function advices.
201 ;; `anything-bookmark-ext'
202 ;; Preconfigured `anything' for bookmark-extensions sources.
203 ;; `anything-simple-call-tree'
204 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
205 ;; `anything-mark-ring'
206 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
207 ;; `anything-global-mark-ring'
208 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
209 ;; `anything-all-mark-rings'
210 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
211 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
212 ;; Preconfigured `anything' to edit or view EmacsWiki page.
213 ;; `anything-yaoddmuse-emacswiki-post-library'
214 ;; Preconfigured `anything' to post library to EmacsWiki.
215 ;; `anything-eval-expression'
216 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
217 ;; `anything-eval-expression-with-eldoc'
218 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
219 ;; `anything-calcul-expression'
220 ;; Preconfigured anything for `anything-c-source-calculation-result'.
221 ;; `anything-surfraw'
222 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
223 ;; `anything-call-source'
224 ;; Preconfigured `anything' to call anything source.
225 ;; `anything-execute-anything-command'
226 ;; Preconfigured `anything' to execute preconfigured `anything'.
228 ;; Preconfigured `anything' to do many create actions from STRING.
230 ;; Preconfigured `anything' for top command.
231 ;; `anything-select-xfont'
232 ;; Preconfigured `anything' to select Xfont.
233 ;; `anything-world-time'
234 ;; Preconfigured `anything' to show world time.
236 ;; Preconfigured `anything' : frontend of APT package manager.
237 ;; `anything-esh-pcomplete'
238 ;; Preconfigured anything to provide anything completion in eshell.
239 ;; `anything-eshell-history'
240 ;; Preconfigured anything for eshell history.
241 ;; `anything-c-run-external-command'
242 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
243 ;; `anything-ratpoison-commands'
244 ;; Preconfigured `anything' to execute ratpoison commands.
246 ;; Preconfigured anything for `ucs-names' math symbols.
247 ;; `anything-show-this-source-only'
248 ;; Show all candidates of this source.
249 ;; `anything-test-sources'
250 ;; List all anything sources for test.
251 ;; `anything-select-source'
252 ;; [OBSOLETE] Select source.
253 ;; `anything-mark-all'
254 ;; Mark all visible unmarked candidates in current source.
255 ;; `anything-unmark-all'
256 ;; Unmark all candidates in all sources of current anything session.
257 ;; `anything-toggle-all-marks'
259 ;; `anything-buffer-diff-persistent'
260 ;; Toggle diff buffer without quitting anything.
261 ;; `anything-buffer-revert-persistent'
262 ;; Revert buffer without quitting anything.
263 ;; `anything-buffer-save-persistent'
264 ;; Save buffer without quitting anything.
265 ;; `anything-buffer-run-kill-buffers'
266 ;; Run kill buffer action from `anything-c-source-buffers-list'.
267 ;; `anything-buffer-run-grep'
268 ;; Run Grep action from `anything-c-source-buffers-list'.
269 ;; `anything-buffer-run-zgrep'
270 ;; Run Grep action from `anything-c-source-buffers-list'.
271 ;; `anything-buffer-run-query-replace-regexp'
272 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
273 ;; `anything-buffer-run-query-replace'
274 ;; Run Query replace action from `anything-c-source-buffers-list'.
275 ;; `anything-buffer-switch-other-window'
276 ;; Run switch to other window action from `anything-c-source-buffers-list'.
277 ;; `anything-buffer-switch-other-frame'
278 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
279 ;; `anything-buffer-switch-to-elscreen'
280 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
281 ;; `anything-buffer-run-ediff'
282 ;; Run ediff action from `anything-c-source-buffers-list'.
283 ;; `anything-buffer-run-ediff-merge'
284 ;; Run ediff action from `anything-c-source-buffers-list'.
285 ;; `anything-ff-run-toggle-auto-update'
287 ;; `anything-ff-run-switch-to-history'
288 ;; Run Switch to history action from `anything-c-source-find-files'.
289 ;; `anything-ff-run-grep'
290 ;; Run Grep action from `anything-c-source-find-files'.
291 ;; `anything-ff-run-pdfgrep'
292 ;; Run Pdfgrep action from `anything-c-source-find-files'.
293 ;; `anything-ff-run-zgrep'
294 ;; Run Grep action from `anything-c-source-find-files'.
295 ;; `anything-ff-run-copy-file'
296 ;; Run Copy file action from `anything-c-source-find-files'.
297 ;; `anything-ff-run-rename-file'
298 ;; Run Rename file action from `anything-c-source-find-files'.
299 ;; `anything-ff-run-byte-compile-file'
300 ;; Run Byte compile file action from `anything-c-source-find-files'.
301 ;; `anything-ff-run-load-file'
302 ;; Run Load file action from `anything-c-source-find-files'.
303 ;; `anything-ff-run-eshell-command-on-file'
304 ;; Run eshell command on file action from `anything-c-source-find-files'.
305 ;; `anything-ff-run-ediff-file'
306 ;; Run Ediff file action from `anything-c-source-find-files'.
307 ;; `anything-ff-run-ediff-merge-file'
308 ;; Run Ediff merge file action from `anything-c-source-find-files'.
309 ;; `anything-ff-run-symlink-file'
310 ;; Run Symlink file action from `anything-c-source-find-files'.
311 ;; `anything-ff-run-delete-file'
312 ;; Run Delete file action from `anything-c-source-find-files'.
313 ;; `anything-ff-run-complete-fn-at-point'
314 ;; Run complete file name action from `anything-c-source-find-files'.
315 ;; `anything-ff-run-switch-to-eshell'
316 ;; Run switch to eshell action from `anything-c-source-find-files'.
317 ;; `anything-ff-run-switch-other-window'
318 ;; Run switch to other window action from `anything-c-source-find-files'.
319 ;; `anything-ff-run-switch-other-frame'
320 ;; Run switch to other frame action from `anything-c-source-find-files'.
321 ;; `anything-ff-run-open-file-externally'
322 ;; Run open file externally command action from `anything-c-source-find-files'.
323 ;; `anything-ff-run-locate'
324 ;; Run locate action from `anything-c-source-find-files'.
325 ;; `anything-ff-run-gnus-attach-files'
326 ;; Run gnus attach files command action from `anything-c-source-find-files'.
327 ;; `anything-ff-run-etags'
328 ;; Run Etags command action from `anything-c-source-find-files'.
329 ;; `anything-ff-run-print-file'
330 ;; Run Print file action from `anything-c-source-find-files'.
331 ;; `anything-ff-run-toggle-basename'
333 ;; `anything-find-files-down-one-level'
334 ;; Go down one level like unix command `cd ..'.
335 ;; `anything-ff-properties-persistent'
336 ;; Show properties without quitting anything.
337 ;; `anything-ff-run-kill-buffer-persistent'
338 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
339 ;; `anything-ff-rotate-left-persistent'
340 ;; Rotate image left without quitting anything.
341 ;; `anything-ff-rotate-right-persistent'
342 ;; Rotate image right without quitting anything.
343 ;; `anything-c-goto-precedent-file'
344 ;; Go to precedent file in anything grep/etags buffers.
345 ;; `anything-c-goto-next-file'
346 ;; Go to precedent file in anything grep/etags buffers.
347 ;; `anything-c-grep-run-persistent-action'
348 ;; Run grep persistent action from `anything-do-grep-1'.
349 ;; `anything-c-grep-run-default-action'
350 ;; Run grep default action from `anything-do-grep-1'.
351 ;; `anything-c-grep-run-other-window-action'
352 ;; Run grep goto other window action from `anything-do-grep-1'.
353 ;; `anything-c-grep-run-save-buffer'
354 ;; Run grep save results action from `anything-do-grep-1'.
355 ;; `anything-do-pdfgrep'
357 ;; `anything-yank-text-at-point'
358 ;; Yank text at point in minibuffer.
359 ;; `anything-c-describe-attributes'
360 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
361 ;; `anything-yaoddmuse-cache-pages'
362 ;; Fetch the list of files on emacswiki and create cache file.
363 ;; `anything-eval-new-line-and-indent'
365 ;; `anything-call-source-from-anything'
366 ;; Call anything source within `anything' session.
367 ;; `anything-create-from-anything'
368 ;; Run `anything-create' from `anything' as a fallback.
369 ;; `anything-c-ucs-persistent-insert'
371 ;; `anything-c-ucs-persistent-forward'
373 ;; `anything-c-ucs-persistent-backward'
375 ;; `anything-c-ucs-persistent-delete'
377 ;; `anything-lisp-completion-at-point'
378 ;; Anything lisp symbol completion at point.
379 ;; `anything-c-complete-file-name-at-point'
380 ;; Complete file name at point.
381 ;; `anything-lisp-completion-at-point-or-indent'
382 ;; First call indent and second call complete lisp symbol.
383 ;; `anything-lisp-completion-or-file-name-at-point'
384 ;; Complete lisp symbol or filename at point.
385 ;; `anything-c-set-variable'
386 ;; Set value to VAR interactively.
387 ;; `anything-c-adaptive-save-history'
388 ;; Save history information to file given by `anything-c-adaptive-history-file'.
389 ;; `anything-c-reset-adaptative-history'
390 ;; Delete all `anything-c-adaptive-history' and his file.
391 ;; `anything-c-toggle-match-plugin'
392 ;; Toggle anything-match-plugin.
394 ;; * User variables defined here:
395 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
396 ;; `anything-c-adaptive-history-file'
397 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
398 ;; `anything-c-adaptive-history-length'
400 ;; `anything-c-google-suggest-url'
401 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
402 ;; `anything-c-google-suggest-search-url'
403 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
404 ;; `anything-google-suggest-use-curl-p'
405 ;; Default Value: nil
406 ;; `anything-c-yahoo-suggest-url'
407 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
408 ;; `anything-c-yahoo-suggest-search-url'
409 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
410 ;; `anything-c-boring-buffer-regexp'
411 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
412 ;; `anything-c-boring-file-regexp'
413 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
414 ;; `anything-kill-ring-threshold'
416 ;; `anything-c-kill-ring-max-lines-number'
417 ;; Default Value: nil
418 ;; `anything-su-or-sudo'
419 ;; Default Value: "su"
420 ;; `anything-for-files-prefered-list'
421 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
422 ;; `anything-create--actions-private'
423 ;; Default Value: nil
424 ;; `anything-allow-skipping-current-buffer'
426 ;; `anything-c-enable-eval-defun-hack'
428 ;; `anything-tramp-verbose'
430 ;; `anything-raise-command'
431 ;; Default Value: nil
432 ;; `anything-command-map-prefix-key'
433 ;; Default Value: "<f5> a"
434 ;; `anything-c-browse-code-regexp-lisp'
435 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
436 ;; `anything-c-browse-code-regexp-python'
437 ;; Default Value: "\\<def\\>\\|\\<class\\>"
438 ;; `anything-c-browse-code-regexp-alist'
439 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
440 ;; `anything-c-external-programs-associations'
441 ;; Default Value: nil
442 ;; `anything-ff-auto-update-initial-value'
444 ;; `anything-c-copy-async-prefered-emacs'
445 ;; Default Value: "emacs"
446 ;; `anything-ff-lynx-style-map'
448 ;; `anything-ff-history-max-length'
449 ;; Default Value: 100
450 ;; `anything-ff-smart-completion'
452 ;; `anything-ff-default-kbsize'
453 ;; Default Value: 1024.0
454 ;; `anything-ff-tramp-not-fancy'
456 ;; `anything-ff-exif-data-program'
457 ;; Default Value: "exiftran"
458 ;; `anything-ff-exif-data-program-args'
459 ;; Default Value: "-d"
460 ;; `anything-c-grep-use-ioccur-style-keys'
462 ;; `anything-c-pdfgrep-default-read-command'
463 ;; Default Value: "xpdf '%f' %p"
464 ;; `anything-c-etags-tag-file-name'
465 ;; Default Value: "TAGS"
466 ;; `anything-c-etags-tag-file-search-limit'
468 ;; `anything-c-etags-use-regexp-search'
469 ;; Default Value: nil
470 ;; `anything-c-filelist-file-name'
471 ;; Default Value: nil
472 ;; `anything-c-eldoc-in-minibuffer-show-fn'
473 ;; Default Value: anything-c-eldoc-show-in-mode-line
474 ;; `anything-c-turn-on-show-completion'
476 ;; `anything-lisp-completion-or-indent-delay'
477 ;; Default Value: 0.6
478 ;; `anything-c-default-external-file-browser'
479 ;; Default Value: "nautilus"
480 ;; `anything-c-use-adaptative-sorting'
481 ;; Default Value: nil
482 ;; `anything-ff-newfile-prompt-p'
484 ;; `anything-ff-avfs-directory'
485 ;; Default Value: nil
486 ;; `anything-ff-file-compressed-list'
487 ;; Default Value: ("gz" "bz2" "zip" "7z")
488 ;; `anything-locate-db-file-regexp'
489 ;; Default Value: "m?locate.db$"
490 ;; `anything-c-eldoc-show-in-mode-line-delay'
492 ;; `anything-c-copy-files-async-log-file'
493 ;; Default Value: "/tmp/dired.log"
494 ;; `anything-ff-printer-list'
495 ;; Default Value: nil
496 ;; `anything-ff-transformer-show-only-basename'
497 ;; Default Value: nil
499 ;; * Anything sources defined here:
500 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
501 ;; `anything-c-source-regexp' (Regexp Builder)
502 ;; `anything-c-source-buffers' (Buffers)
503 ;; `anything-c-source-buffer-not-found' (Create buffer)
504 ;; `anything-c-source-buffers-list' (Buffers)
505 ;; `anything-c-source-file-name-history' (File Name History)
506 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
507 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
508 ;; `anything-c-source-find-files' (Find Files)
509 ;; `anything-c-source-write-file' (Write File)
510 ;; `anything-c-source-insert-file' (Insert File)
511 ;; `anything-c-source-copy-files' (Copy Files)
512 ;; `anything-c-source-symlink-files' (Symlink Files)
513 ;; `anything-c-source-hardlink-files' (Hardlink Files)
514 ;; `anything-c-source-file-cache' (File Cache)
515 ;; `anything-c-source-locate' (Locate)
516 ;; `anything-c-source-recentf' (Recentf)
517 ;; `anything-c-source-ffap-guesser' (File at point)
518 ;; `anything-c-source-ffap-line' (File/Lineno at point)
519 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
520 ;; `anything-c-source-filelist' (FileList)
521 ;; `anything-c-source-info-pages' (Info Pages)
522 ;; `anything-c-source-info-elisp' (Info index: elisp)
523 ;; `anything-c-source-info-cl' (Info index: cl)
524 ;; `anything-c-source-info-org' (Info index: org)
525 ;; `anything-c-source-info-gnus' (Info index: Gnus)
526 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
527 ;; `anything-c-source-info-zsh' (Info index: zsh)
528 ;; `anything-c-source-info-bash' (Info index: bash)
529 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
530 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
531 ;; `anything-c-source-info-find' (Info index: find)
532 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
533 ;; `anything-c-source-info-textutils' (Info index: textutils)
534 ;; `anything-c-source-info-libc' (Info index: libc)
535 ;; `anything-c-source-info-make' (Info index: make)
536 ;; `anything-c-source-info-automake' (Info index: automake)
537 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
538 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
539 ;; `anything-c-source-info-emacs' (Info index: emacs)
540 ;; `anything-c-source-info-elib' (Info index: elib)
541 ;; `anything-c-source-info-eieio' (Info index: eieio)
542 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
543 ;; `anything-c-source-info-guile' (Info index: guile)
544 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
545 ;; `anything-c-source-info-goops' (Info index: goops)
546 ;; `anything-c-source-info-screen' (Info index: screen)
547 ;; `anything-c-source-info-latex' (Info index: latex)
548 ;; `anything-c-source-info-gawk' (Info index: gawk)
549 ;; `anything-c-source-info-sed' (Info index: sed)
550 ;; `anything-c-source-info-m4' (Info index: m4)
551 ;; `anything-c-source-info-wget' (Info index: wget)
552 ;; `anything-c-source-info-binutils' (Info index: binutils)
553 ;; `anything-c-source-info-as' (Info index: as)
554 ;; `anything-c-source-info-bfd' (Info index: bfd)
555 ;; `anything-c-source-info-gprof' (Info index: gprof)
556 ;; `anything-c-source-info-ld' (Info index: ld)
557 ;; `anything-c-source-info-diff' (Info index: diff)
558 ;; `anything-c-source-info-flex' (Info index: flex)
559 ;; `anything-c-source-info-grep' (Info index: grep)
560 ;; `anything-c-source-info-gzip' (Info index: gzip)
561 ;; `anything-c-source-info-libtool' (Info index: libtool)
562 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
563 ;; `anything-c-source-info-info' (Info index: info)
564 ;; `anything-c-source-info-gdb' (Info index: gdb)
565 ;; `anything-c-source-info-stabs' (Info index: stabs)
566 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
567 ;; `anything-c-source-info-cvs' (Info index: cvs)
568 ;; `anything-c-source-info-bison' (Info index: bison)
569 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
570 ;; `anything-c-source-info-global' (Info index: global)
571 ;; `anything-c-source-man-pages' (Manual Pages)
572 ;; `anything-c-source-complex-command-history' (Complex Command History)
573 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
574 ;; `anything-c-source-emacs-commands' (Emacs Commands)
575 ;; `anything-c-source-lacarte' (Lacarte)
576 ;; `anything-c-source-emacs-functions' (Emacs Functions)
577 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
578 ;; `anything-c-source-advice' (Function Advice)
579 ;; `anything-c-source-emacs-variables' (Emacs Variables)
580 ;; `anything-c-source-bookmarks' (Bookmarks)
581 ;; `anything-c-source-bookmark-set' (Set Bookmark)
582 ;; `anything-c-source-bm' (Visible Bookmarks)
583 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
584 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
585 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
586 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
587 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
588 ;; `anything-c-source-bookmark-images' (Bookmark Images)
589 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
590 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
591 ;; `anything-c-source-bookmark-info' (Bookmark Info)
592 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
593 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
594 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
595 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
596 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
597 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
598 ;; `anything-c-source-imenu' (Imenu)
599 ;; `anything-c-source-ctags' (Exuberant ctags)
600 ;; `anything-c-source-etags-select' (Etags)
601 ;; `anything-c-source-semantic' (Semantic Tags)
602 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
603 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
604 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
605 ;; `anything-c-source-customize-face' (Customize Face)
606 ;; `anything-c-source-colors' (Colors)
607 ;; `anything-c-source-tracker-search' (Tracker Search)
608 ;; `anything-c-source-mac-spotlight' (mdfind)
609 ;; `anything-c-source-picklist' (Picklist)
610 ;; `anything-c-source-kill-ring' (Kill Ring)
611 ;; `anything-c-source-mark-ring' (mark-ring)
612 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
613 ;; `anything-c-source-register' (Registers)
614 ;; `anything-c-source-latex-math' (Latex Math Menu)
615 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
616 ;; `anything-c-source-rd-headline' (RD HeadLine)
617 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
618 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
619 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
620 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
621 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
622 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
623 ;; `anything-c-source-eev-anchor' (Anchors)
624 ;; `anything-c-source-org-headline' (Org HeadLine)
625 ;; `anything-c-source-org-keywords' (Org Keywords)
626 ;; `anything-c-source-bbdb' (BBDB)
627 ;; `anything-c-source-evaluation-result' (Evaluation Result)
628 ;; `anything-c-source-calculation-result' (Calculation Result)
629 ;; `anything-c-source-google-suggest' (Google Suggest)
630 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
631 ;; `anything-c-source-emms-streams' (Emms Streams)
632 ;; `anything-c-source-emms-dired' (Music Directory)
633 ;; `anything-c-source-emms-files' (Emms files)
634 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
635 ;; `anything-c-source-call-source' (Call anything source)
636 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
637 ;; `anything-c-source-occur' (Occur)
638 ;; `anything-c-source-browse-code' (Browse code)
639 ;; `anything-c-source-create' (Create)
640 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
641 ;; `anything-c-source-elscreen' (Elscreen)
642 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
643 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
644 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
645 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
646 ;; `anything-c-source-xfonts' (X Fonts)
647 ;; `anything-c-source-ucs' (Ucs names)
648 ;; `anything-c-source-emacs-process' (Emacs Process)
649 ;; `anything-c-source-time-world' (Time World List)
650 ;; `anything-c-source-apt' (APT)
651 ;; `anything-c-source-gentoo' (Portage sources)
652 ;; `anything-c-source-use-flags' (Use Flags)
653 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
654 ;; `anything-c-source-esh' (Eshell completions)
655 ;; `anything-c-source-eshell-history' (Eshell history)
657 ;; *** END auto-documentation
661 ;; Install developer-tools/autodoc.el and
662 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
663 ;; This function generates anything-c-source-* / functions / options list.
665 ;; [EVAL IT] (autodoc-update-all)
667 ;; Please write details documentation about function, then others will
668 ;; read code more easier. -- Andy Stewart
674 ;; Change log of this file is found at
675 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
677 ;; Change log of this project is found at
678 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
683 ;; Tassilo Horn <tassilo@member.fsf.org>
684 ;; Vagn Johansen <gonz808@hotmail.com>
685 ;; Mathias Dahl <mathias.dahl@gmail.com>
686 ;; Bill Clementson <billclem@gmail.com>
687 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
688 ;; Drew Adams <drew.adams@oracle.com>
689 ;; Jason McBrayer <jmcbray@carcosa.net>
690 ;; Andy Stewart <lazycat.manatee@gmail.com>
691 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
692 ;; rubikitch <rubikitch@ruby-lang.org>
693 ;; Scott Vokes <vokes.s@gmail.com>
694 ;; Kenichirou Oyama <k1lowxb@gmail.com>
699 ;; - Fix documentation, now many functions haven't documentations.
718 (eval-when-compile (require 'org
)) ; Shut up byte compiler about org-directory.
719 (eval-when-compile (require 'semantic nil t
))
720 (require 'anything-match-plugin
)
724 ;;; Declare external functions
727 (declare-function gnus-dired-attach
"ext:gnus-dired.el" (files-to-attach))
728 (declare-function image-dired-display-image
"image-dired.el" (file &optional original-size
))
729 (declare-function image-dired-update-property
"image-dired.el" (prop value
))
730 (declare-function woman-file-name-all-completions
"woman.el" (topic))
731 (declare-function Man-getpage-in-background
"man.el" (topic))
732 (declare-function simple-call-tree-analyze
"ext:simple-call-tree.el" (&optional test
))
733 (declare-function yaoddmuse-update-pagename
"ext:yaoddmuse.el" (&optional unforced
))
734 (declare-function yaoddmuse-get-library-list
"ext:yaoddmuse.el" (&optional dirs string
))
735 (declare-function org-get-current-options
"ext:org-exp.el")
736 (declare-function emms-streams
"ext:emms-streams")
737 (declare-function emms-stream-delete-bookmark
"ext:emms-streams")
738 (declare-function emms-stream-add-bookmark
"ext:emms-streams" (name url fd type
))
739 (declare-function emms-stream-save-bookmarks-file
"ext:emms-streams")
740 (declare-function emms-stream-quit
"ext:emms-streams")
741 (declare-function with-current-emms-playlist
"ext:emms" (&rest body
))
742 (declare-function emms-playlist-tracks-in-region
"ext:emms" (beg end
))
743 (declare-function emms-playlist-first
"ext:emms")
744 (declare-function emms-playlist-mode-play-smart
"ext:emms-playlist-mode")
745 (declare-function term-line-mode
"term")
746 (declare-function term-char-mode
"term")
747 (declare-function term-send-input
"term")
748 (declare-function term-send-eof
"term")
749 (declare-function Info-index-nodes
"info" (&optional file
))
750 (declare-function Info-goto-node
"info" (&optional fork
))
751 (declare-function Info-find-node
"info.el" (filename nodename
&optional no-going-back
))
752 (declare-function elscreen-find-screen-by-buffer
"ext:elscreen.el" (buffer &optional create
))
753 (declare-function elscreen-find-file
"ext:elscreen.el" (filename))
754 (declare-function elscreen-goto
"ext:elscreen.el" (screen))
755 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
756 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
757 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
758 (declare-function semantic-tag-type
"ext:tag-file.el" (tag) t
)
759 (declare-function semantic-tag-class
"ext:tag-file.el" (tag) t
)
760 (declare-function bbdb
"ext:bbdb-com")
761 (declare-function bbdb-current-record
"ext:bbdb-com")
762 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
763 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
764 (declare-function bbdb-current-record
"ext:bbdb-com")
765 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
766 (declare-function bbdb-records
"ext:bbdb-com"
767 (&optional dont-check-disk already-in-db-buffer
))
768 (declare-function eshell-read-aliases-list
"em-alias")
769 (declare-function eshell-send-input
"esh-mode" (&optional use-region queue-p no-newline
))
770 (declare-function eshell-bol
"esh-mode")
771 (declare-function eldoc-current-symbol
"eldoc")
772 (declare-function eldoc-get-fnsym-args-string
"eldoc" (sym &optional index
))
773 (declare-function eldoc-get-var-docstring
"eldoc" (sym))
774 (declare-function eldoc-fnsym-in-current-sexp
"eldoc")
775 (declare-function find-library-name
"find-func.el" (library))
776 (declare-function adoc-construct
"ext:auto-document.el" (buf))
777 (declare-function adoc-first-line
"ext:auto-document.el" (str))
778 (declare-function adoc-prin1-to-string
"ext:auto-document.el" (object))
779 (declare-function secure-hash
"ext:fns.c" (algorithm object
&optional start end binary
))
786 (unless (fboundp 'window-system
)
787 (defun window-system (&optional arg
)
795 (defgroup anything-config nil
796 "Predefined configurations for `anything.el'."
799 (defcustom anything-c-adaptive-history-file
800 "~/.emacs.d/anything-c-adaptive-history"
801 "Path of file where history information is stored."
803 :group
'anything-config
)
805 (defcustom anything-c-adaptive-history-length
50
806 "Maximum number of candidates stored for a source."
808 :group
'anything-config
)
810 (defcustom anything-c-google-suggest-url
811 "http://google.com/complete/search?output=toolbar&q="
812 "URL used for looking up Google suggestions."
814 :group
'anything-config
)
816 (defcustom anything-c-google-suggest-search-url
817 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
818 "URL used for Google searching."
820 :group
'anything-config
)
822 (defcustom anything-google-suggest-use-curl-p nil
823 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
824 Otherwise `url-retrieve-synchronously' is used."
826 :group
'anything-config
)
828 (defcustom anything-c-yahoo-suggest-url
829 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
830 "Url used for looking up Yahoo suggestions."
832 :group
'anything-config
)
834 (defcustom anything-c-yahoo-suggest-search-url
835 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
836 "Url used for Yahoo searching."
838 :group
'anything-config
)
840 (defcustom anything-c-boring-buffer-regexp
846 " *Echo Area" " *Minibuf"))
847 "The regexp that match boring buffers.
848 Buffer candidates matching this regular expression will be
849 filtered from the list of candidates if the
850 `anything-c-skip-boring-buffers' candidate transformer is used, or
851 they will be displayed with face `file-name-shadow' if
852 `anything-c-shadow-boring-buffers' is used."
854 :group
'anything-config
)
855 ;; (string-match anything-c-boring-buffer-regexp "buf")
856 ;; (string-match anything-c-boring-buffer-regexp " hidden")
857 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
859 (defcustom anything-c-boring-file-regexp
861 ;; Boring directories
862 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
864 (and line-start
".#")
865 (and (or ".class" ".la" ".o" "~") eol
)))
866 "The regexp that match boring files.
867 File candidates matching this regular expression will be
868 filtered from the list of candidates if the
869 `anything-c-skip-boring-files' candidate transformer is used, or
870 they will be displayed with face `file-name-shadow' if
871 `anything-c-shadow-boring-files' is used."
873 :group
'anything-config
)
875 (defcustom anything-kill-ring-threshold
10
876 "*Minimum length to be listed by `anything-c-source-kill-ring'."
878 :group
'anything-config
)
880 (defcustom anything-c-kill-ring-max-lines-number nil
881 "Max number of lines displayed per candidate in kill-ring browser.
882 If nil or zero, don't truncate candidate, show all."
884 :group
'anything-config
)
886 (defcustom anything-su-or-sudo
"su"
887 "What command to use for root access."
889 :group
'anything-config
)
891 (defcustom anything-for-files-prefered-list
892 '(anything-c-source-ffap-line
893 anything-c-source-ffap-guesser
894 anything-c-source-buffers-list
895 anything-c-source-recentf
896 anything-c-source-bookmarks
897 anything-c-source-file-cache
898 anything-c-source-files-in-current-dir
+
899 anything-c-source-locate
)
900 "Your prefered sources to find files."
902 :group
'anything-config
)
904 (defcustom anything-create--actions-private nil
905 "User defined actions for `anything-create' / `anything-c-source-create'.
906 It is a list of (DISPLAY . FUNCTION) pairs like `action'
907 attribute of `anything-sources'.
909 It is prepended to predefined pairs."
911 :group
'anything-config
)
913 (defcustom anything-allow-skipping-current-buffer t
914 "Show current buffer or not in anything buffer"
916 :group
'anything-config
)
918 (defcustom anything-c-enable-eval-defun-hack t
919 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
920 This hack is invoked when pressing C-M-x in the form \
921 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
923 :group
'anything-config
)
925 (defcustom anything-tramp-verbose
0
926 "*Just like `tramp-verbose' but specific to anything.
927 When set to 0 don't show tramp messages in anything.
928 If you want to have the default tramp messages set it to 3."
930 :group
'anything-config
)
932 (defcustom anything-raise-command nil
933 "*A shell command to jump to a window running specific program.
934 Need external program wmctrl.
935 This will be use with `format', so use something like \"wmctrl -xa %s\"."
937 :group
'anything-config
)
939 (defun anything-set-anything-command-map-prefix-key (var key
)
940 (declare (special anything-command-map-prefix-key
))
941 (when (boundp 'anything-command-map-prefix-key
)
942 (global-unset-key (read-kbd-macro anything-command-map-prefix-key
)))
943 (setq anything-command-map-prefix-key key
)
944 (global-set-key (read-kbd-macro anything-command-map-prefix-key
)
945 'anything-command-map
))
947 (defcustom anything-command-map-prefix-key
"<f5> a"
948 "*The prefix key for all `anything-command-map' commands.
951 This default value is very likely to be changed,
952 because it is under discussion."
954 :set
'anything-set-anything-command-map-prefix-key
955 :group
'anything-config
)
957 (defcustom anything-c-browse-code-regexp-lisp
958 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
959 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
960 "*Regexp used to parse lisp buffer when browsing code."
962 :group
'anything-config
)
964 (defcustom anything-c-browse-code-regexp-python
965 "\\<def\\>\\|\\<class\\>"
966 "*Regexp used to parse python buffer when browsing code."
968 :group
'anything-config
)
970 (defcustom anything-c-browse-code-regexp-alist
971 `((lisp-interaction-mode .
,anything-c-browse-code-regexp-lisp
)
972 (emacs-lisp-mode .
,anything-c-browse-code-regexp-lisp
)
973 (lisp-mode .
,anything-c-browse-code-regexp-lisp
)
974 (python-mode .
,anything-c-browse-code-regexp-python
))
975 "*Alist to store regexps for browsing code corresponding \
976 to a specific `major-mode'."
978 :group
'anything-config
)
980 (defcustom anything-c-external-programs-associations nil
981 "*Alist to store externals programs associated with file extension.
982 This variable overhide setting in .mailcap file.
983 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
985 :group
'anything-config
)
987 (defcustom anything-ff-auto-update-initial-value t
988 "Auto update when only one candidate directory is matched.
989 This is the default value when starting `anything-find-files'."
990 :group
'anything-config
993 (defcustom anything-c-copy-async-prefered-emacs
"emacs"
994 "Path to the emacs you want to use for copying async.
995 Emacs versions < 24 fail to copy directory due to a bug not fixed
996 in `copy-directory'."
997 :group
'anything-config
1000 (defcustom anything-ff-lynx-style-map t
1001 "Use arrow keys to navigate with `anything-find-files'.
1002 You will have to restart Emacs or reeval `anything-find-files-map'
1003 and `anything-c-read-file-map' for this take effect."
1004 :group
'anything-config
1007 (defcustom anything-ff-history-max-length
100
1008 "*Number of elements shown in `anything-find-files' history."
1009 :group
'anything-config
1012 (defcustom anything-ff-smart-completion t
1013 "Try to complete filenames smarter when non--nil.
1014 See `anything-ff-transform-fname-for-completion' for more info."
1015 :group
'anything-config
1018 (defcustom anything-ff-default-kbsize
1024.0
1019 "Default Kbsize to use for showing files size.
1020 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1021 :group
'anything-config
1024 (defcustom anything-ff-tramp-not-fancy t
1025 "No colors when listing remote files when set to non--nil.
1026 This make listing much faster, specially on slow machines."
1027 :group
'anything-config
1030 (defcustom anything-ff-exif-data-program
"exiftran"
1031 "*Program used to extract exif data of an image file."
1032 :group
'anything-config
1035 (defcustom anything-ff-exif-data-program-args
"-d"
1036 "*Arguments used for `anything-ff-exif-data-program'."
1037 :group
'anything-config
1040 (defcustom anything-c-grep-use-ioccur-style-keys t
1041 "Use Arrow keys to jump to occurences."
1042 :group
'anything-config
1045 (defcustom anything-c-pdfgrep-default-read-command
"xpdf '%f' %p"
1046 "Default command to read pdf files from pdfgrep.
1047 Where '%f' format spec is filename and '%p' is page number"
1048 :group
'anything-config
1051 (defcustom anything-c-etags-tag-file-name
"TAGS"
1052 "Etags tag file name."
1054 :group
'anything-config
)
1056 (defcustom anything-c-etags-tag-file-search-limit
10
1057 "The limit level of directory to search tag file.
1058 Don't search tag file deeply if outside this value."
1060 :group
'anything-config
)
1062 (defcustom anything-c-etags-use-regexp-search nil
1063 "When non--nil search etags candidates by regexp.
1064 This disable anything-match-plugin when enabled.
1065 When nil search is performed literally and *match-plugin is used
1067 :group
'anything-config
1070 (defcustom anything-c-filelist-file-name nil
1071 "Filename of file list.
1072 Accept a list of string for multiple files.
1074 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1075 File list is created by make-filelist.rb script.
1078 ruby make-filelist.rb > /tmp/all.filelist
1081 ;; Assume that /tmp is ramdisk or tmpfs
1082 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1083 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1086 :group
'anything-config
)
1088 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1089 'anything-c-eldoc-show-in-mode-line
1090 "A function to display eldoc info.
1091 Should take one arg: the string to display."
1092 :group
'anything-config
1095 (defcustom anything-c-turn-on-show-completion t
1096 "Display candidate in buffer while moving selection when non--nil."
1097 :group
'anything-config
1100 (defcustom anything-lisp-completion-or-indent-delay
0.6
1101 "After this delay `anything-lisp-completion-counter' is reset to 0.
1102 This allow to indent again without completing lisp symbol after this delay.
1103 Default is 0.6 seconds."
1104 :group
'anything-config
1107 (defcustom anything-c-default-external-file-browser
"nautilus"
1108 "Default external file browser for your system.
1109 Directories will be opened externally with it.
1110 Set to nil if you do not have external file browser
1111 or do not want to use it."
1112 :group
'anything-config
1115 (defcustom anything-c-use-adaptative-sorting nil
1116 "*Wheter to use or not adaptative sorting.
1117 Even if a source use it, it will have no effect when set to nil."
1119 :group
'anything-config
)
1121 (defcustom anything-ff-newfile-prompt-p t
1122 "Whether Prompt or not when creating new file.
1123 This set `ffap-newfile-prompt'."
1125 :group
'anything-config
)
1128 (defcustom anything-ff-avfs-directory nil
1129 "*The default avfs directory, usually '.avfs'.
1130 When this is set you will be able to expand archive filenames with `C-z'
1131 inside an avfs directory mounted with mountavfs.
1132 See <http://sourceforge.net/projects/avf/>."
1134 :group
'anything-config
)
1136 (defcustom anything-ff-file-compressed-list
'("gz" "bz2" "zip" "7z")
1137 "*Minimal list of compressed files extension."
1139 :group
'anything-config
)
1141 (defcustom anything-locate-db-file-regexp
"m?locate\.db$"
1142 "Default regexp to match locate database.
1143 If nil Search in all files."
1145 :group
'anything-config
)
1147 (defcustom anything-c-eldoc-show-in-mode-line-delay
12
1148 "Eldoc will show info in mode-line during this delay if user is idle."
1150 :group
'anything-config
)
1152 (defcustom anything-c-copy-files-async-log-file
"/tmp/dired.log"
1153 "The file used to communicate with two emacs when copying files async."
1155 :group
'anything-config
)
1157 (defcustom anything-ff-printer-list nil
1158 "A list of available printers on your system.
1159 When non--nil let you choose a printer to print file.
1160 Otherwise when nil the variable `printer-name' will be used.
1161 On Unix based systems you can use `anything-ff-find-printers' to
1162 find a list of available printers."
1164 :group
'anything-config
)
1166 (defcustom anything-ff-transformer-show-only-basename nil
1167 "Show only basename of candidates in `anything-find-files'.
1168 This can be toggled at anytime from `anything-find-files' with \
1169 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1171 :group
'anything-config
)
1173 (defcustom anything-completing-read-handlers-alist
1174 '((describe-function . anything-completing-read-symbols
)
1175 (describe-variable . anything-completing-read-symbols
)
1176 (debug-on-entry . anything-completing-read-symbols
)
1177 (find-function . anything-completing-read-symbols
)
1178 (trace-function . anything-completing-read-symbols
)
1179 (trace-function-background . anything-completing-read-symbols
)
1180 (ffap-alternate-file . nil
))
1181 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1182 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1183 where key and value are symbols.
1185 Each key is an Emacs command that use originaly `completing-read'.
1187 Each value maybe an anything function that take same arguments as
1188 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1189 anything source and BUFFER the name of the buffer we will use.
1190 This function prefix name must start by \"anything\".
1192 See `anything-completing-read-symbols' for example.
1194 If the value of an entry is nil completion will fall back to
1195 emacs vanilla behavior.
1196 e.g If you want to disable anything completion for `describe-function':
1197 \(describe-function . nil\).
1199 Ido is also supported, you can use `ido-completing-read' and
1200 `ido-read-file-name' as value of an entry or just 'ido.
1201 e.g ido completion for `find-file':
1204 \(find-file . ido-read-file-name\)
1205 Note that you don't need to enable `ido-mode' for this to work."
1206 :group
'anything-config
1207 :type
'(alist :key-type symbol
:value-type symbol
))
1211 ;;; General internal variables
1213 ;; Some internals variable that need to be loaded
1214 ;; here to avoid compiler warnings.
1215 (defvar anything-c-external-commands-list nil
1216 "A list of all external commands the user can execute. If this
1217 variable is not set by the user, it will be calculated
1220 (defvar anything-c-show-completion-overlay nil
)
1222 (defvar anything-c-locate-command
1224 ('gnu
/linux
"locate -i -r %s")
1225 ('berkeley-unix
"locate -i %s")
1226 ('windows-nt
"es -i -r %s")
1228 "A list of arguments for locate program.
1229 The \"-r\" option must be the last option.")
1235 (defface anything-buffer-saved-out
1236 '((t (:foreground
"red")))
1237 "*Face used for buffer files modified outside of emacs."
1238 :group
'anything-config
)
1240 (defface anything-buffer-not-saved
1241 '((t (:foreground
"Indianred2")))
1242 "*Face used for buffer files not already saved on disk."
1243 :group
'anything-config
)
1245 (defface anything-ff-prefix
1246 '((t (:background
"yellow" :foreground
"black")))
1247 "*Face used to prefix new file or url paths in `anything-find-files'."
1248 :group
'anything-config
)
1250 (defface anything-ff-executable
1251 '((t (:foreground
"green")))
1252 "*Face used for executable files in `anything-find-files'."
1253 :group
'anything-config
)
1255 (defface anything-ff-directory
1256 '((t (:foreground
"DarkRed" :background
"LightGray")))
1257 "*Face used for directories in `anything-find-files'."
1258 :group
'anything-config
)
1260 (defface anything-ff-symlink
1261 '((t (:foreground
"DarkOrange")))
1262 "*Face used for symlinks in `anything-find-files'."
1263 :group
'anything-config
)
1265 (defface anything-ff-invalid-symlink
1266 '((t (:foreground
"black" :background
"red")))
1267 "*Face used for invalid symlinks in `anything-find-files'."
1268 :group
'anything-config
)
1270 (defface anything-ff-file
1271 '((t (:foreground
"CadetBlue" :underline t
)))
1272 "*Face used for file names in `anything-find-files'."
1273 :group
'anything-config
)
1275 (defface anything-grep-match
1276 '((t (:inherit match
)))
1277 "Face used to highlight grep matches."
1278 :group
'anything-config
)
1280 (defface anything-grep-file
1281 '((t (:foreground
"BlueViolet" :underline t
)))
1282 "Face used to highlight grep results filenames."
1283 :group
'anything-config
)
1285 (defface anything-grep-lineno
1286 '((t (:foreground
"Darkorange1")))
1287 "Face used to highlight grep number lines."
1288 :group
'anything-config
)
1290 (defface anything-grep-running
1291 '((t (:foreground
"Red")))
1292 "Face used in mode line when grep is running."
1293 :group
'anything-config
)
1295 (defface anything-grep-finish
1296 '((t (:foreground
"Green")))
1297 "Face used in mode line when grep is finish."
1298 :group
'anything-config
)
1300 (defface anything-M-x-key-face
'((t (:foreground
"orange" :underline t
)))
1301 "*Face used in anything-M-x to show keybinding."
1304 (defface anything-bmkext-info
1305 '((t (:foreground
"green")))
1306 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1309 (defface anything-bmkext-w3m
1310 '((t (:foreground
"yellow")))
1311 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1314 (defface anything-bmkext-gnus
1315 '((t (:foreground
"magenta")))
1316 "*Face used for Gnus bookmarks."
1319 (defface anything-bmkext-man
1320 '((t (:foreground
"Orange4")))
1321 "*Face used for Woman/man bookmarks."
1324 (defface anything-bmkext-no--file
1325 '((t (:foreground
"grey")))
1326 "*Face used for non--file bookmarks."
1329 (defface anything-bmkext-file
1330 '((t (:foreground
"Deepskyblue2")))
1331 "*Face used for non--file bookmarks."
1334 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
1335 "Face for su/sudo bookmarks."
1338 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
1339 "Face for w3m bookmarks" :group
'anything
)
1341 (defface anything-emms-playlist
1342 '((t (:foreground
"Springgreen4" :underline t
)))
1343 "*Face used for tracks in current emms playlist."
1346 (defface anything-apt-installed
1347 '((t (:foreground
"green")))
1348 "*Face used for apt installed candidates."
1351 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
1352 "Face for anything-gentoo installed packages."
1353 :group
'traverse-faces
)
1355 (defface anything-lisp-show-completion
1356 '((t (:background
"DarkSlateGray")))
1357 "*Face used for showing candidates in `anything-lisp-completion'."
1358 :group
'anything-config
)
1360 (defface anything-lisp-completion-info
1361 '((t (:foreground
"red")))
1362 "*Face used for showing info in `anything-lisp-completion'."
1363 :group
'anything-config
)
1365 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
1366 "Face for source header in the anything buffer." :group
'anything
)
1369 (defun anything-configuration ()
1370 "Customize `anything'."
1372 (customize-group "anything-config"))
1376 ;;; Anything-command-map
1380 (defvar anything-command-map
)
1381 (define-prefix-command 'anything-command-map
)
1384 (define-key anything-command-map
(kbd "<SPC>") 'anything-execute-anything-command
)
1385 (define-key anything-command-map
(kbd "a") 'anything-c-apropos
)
1386 (define-key anything-command-map
(kbd "e") 'anything-c-etags-select
)
1387 (define-key anything-command-map
(kbd "l") 'anything-locate
)
1388 (define-key anything-command-map
(kbd "s") 'anything-surfraw
)
1389 (define-key anything-command-map
(kbd "r") 'anything-regexp
)
1390 (define-key anything-command-map
(kbd "w") 'anything-w3m-bookmarks
)
1391 (define-key anything-command-map
(kbd "x") 'anything-firefox-bookmarks
)
1392 (define-key anything-command-map
(kbd "#") 'anything-emms
)
1393 (define-key anything-command-map
(kbd "m") 'anything-man-woman
)
1394 (define-key anything-command-map
(kbd "t") 'anything-top
)
1395 (define-key anything-command-map
(kbd "i") 'anything-imenu
)
1396 (define-key anything-command-map
(kbd "<tab>") 'anything-lisp-completion-at-point
)
1397 (define-key anything-command-map
(kbd "p") 'anything-list-emacs-process
)
1398 (define-key anything-command-map
(kbd "C-x r b") 'anything-c-pp-bookmarks
)
1399 (define-key anything-command-map
(kbd "M-y") 'anything-show-kill-ring
)
1400 (define-key anything-command-map
(kbd "C-c <SPC>") 'anything-all-mark-rings
)
1401 (define-key anything-command-map
(kbd "C-x C-f") 'anything-find-files
)
1402 (define-key anything-command-map
(kbd "f") 'anything-for-files
)
1403 (define-key anything-command-map
(kbd "C-:") 'anything-eval-expression-with-eldoc
)
1404 (define-key anything-command-map
(kbd "C-,") 'anything-calcul-expression
)
1405 (define-key anything-command-map
(kbd "M-x") 'anything-M-x
)
1406 (define-key anything-command-map
(kbd "C-x C-w") 'anything-write-file
)
1407 (define-key anything-command-map
(kbd "C-x i") 'anything-insert-file
)
1408 (define-key anything-command-map
(kbd "M-s o") 'anything-occur
)
1409 (define-key anything-command-map
(kbd "M-g s") 'anything-do-grep
)
1410 (define-key anything-command-map
(kbd "c") 'anything-colors
)
1411 (define-key anything-command-map
(kbd "F") 'anything-select-xfont
)
1412 (define-key anything-command-map
(kbd "C-c f") 'anything-recentf
)
1413 (define-key anything-command-map
(kbd "C-c g") 'anything-google-suggest
)
1414 (define-key anything-command-map
(kbd "h i") 'anything-info-at-point
)
1415 (define-key anything-command-map
(kbd "h r") 'anything-info-emacs
)
1416 (define-key anything-command-map
(kbd "h g") 'anything-info-gnus
)
1417 (define-key anything-command-map
(kbd "C-x C-b") 'anything-buffers-list
)
1418 (define-key anything-command-map
(kbd "C-c C-b") 'anything-browse-code
)
1419 (define-key anything-command-map
(kbd "C-x r i") 'anything-register
)
1420 (define-key anything-command-map
(kbd "C-c C-x") 'anything-c-run-external-command
)
1422 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1423 ;; minibuffer-local-filename-must-match-map.
1424 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
1425 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
1426 (dolist (map (list minibuffer-local-filename-completion-map
1427 minibuffer-local-completion-map
1428 minibuffer-local-must-match-filename-map
1429 minibuffer-local-filename-must-match-map
1430 minibuffer-local-map
1431 minibuffer-local-isearch-map
1432 minibuffer-local-must-match-map
1433 minibuffer-local-ns-map
))
1434 (define-key map
"\C-r" 'anything-minibuffer-history
))
1441 (easy-menu-define nil global-map
1444 ["All anything commands" anything-execute-anything-command t
]
1445 ["Find any Files/Buffers" anything-for-files t
]
1446 ["Anything Everywhere" ac-mode t
]
1449 ["Find files" anything-find-files t
]
1450 ["Recent Files" anything-recentf t
]
1451 ["Locate" anything-locate t
]
1452 ["Bookmarks" anything-c-pp-bookmarks t
])
1454 ["Find buffers" anything-buffers-list t
])
1456 ["Emacs Commands" anything-M-x t
]
1457 ["Externals Commands" anything-c-run-external-command t
])
1459 ["Anything Apropos" anything-c-apropos t
])
1461 ["Info at point" anything-info-at-point t
]
1462 ["Emacs Manual index" anything-info-emacs t
]
1463 ["Gnus Manual index" anything-info-gnus t
])
1465 ["Org keywords" anything-org-keywords t
]
1466 ["Org headlines" anything-org-headlines t
])
1468 ["Occur" anything-occur t
]
1469 ["Grep" anything-do-grep t
]
1470 ["Etags" anything-c-etags-select t
]
1471 ["Lisp complete at point" anything-lisp-completion-at-point t
]
1472 ["Browse Kill ring" anything-show-kill-ring t
]
1473 ["Browse register" anything-register t
]
1474 ["Browse code" anything-browse-code t
]
1475 ["Mark Ring" anything-all-mark-rings t
]
1476 ["Regexp handler" anything-regexp t
]
1477 ["Colors & Faces" anything-colors t
]
1478 ["Show xfonts" anything-select-xfont t
]
1479 ["Ucs Symbols" anything-ucs t
]
1480 ["Imenu" anything-imenu t
]
1481 ["Google Suggest" anything-google-suggest t
]
1482 ["Eval expression" anything-eval-expression-with-eldoc t
]
1483 ["Calcul expression" anything-calcul-expression t
]
1484 ["Man pages" anything-man-woman t
]
1485 ["Top externals process" anything-top t
]
1486 ["Emacs internals process" anything-list-emacs-process t
])
1488 ["Prefered Options" anything-configuration t
]))
1490 ;;; Anything map add ons
1493 (define-key anything-map
(kbd "C-x C-f") 'anything-quit-and-find-file
)
1494 (define-key anything-map
(kbd "M-m") 'anything-toggle-all-marks
)
1495 (define-key anything-map
(kbd "C-w") 'anything-yank-text-at-point
)
1498 ;;; Specialized keymaps
1501 (defvar anything-c-buffer-map
1502 (let ((map (copy-keymap anything-map
)))
1503 (define-key map
(kbd "C-c ?") 'anything-c-buffer-help
)
1504 ;; No need to have separate command for grep and zgrep
1505 ;; as we don't use recursivity for buffers.
1506 ;; So use zgrep for both as it is capable to handle non--compressed files.
1507 (define-key map
(kbd "M-g s") 'anything-buffer-run-zgrep
)
1508 (define-key map
(kbd "C-o") 'anything-buffer-switch-other-window
)
1509 (define-key map
(kbd "C-c C-o") 'anything-buffer-switch-other-frame
)
1510 (define-key map
(kbd "C-c =") 'anything-buffer-run-ediff
)
1511 (define-key map
(kbd "M-=") 'anything-buffer-run-ediff-merge
)
1512 (define-key map
(kbd "C-=") 'anything-buffer-diff-persistent
)
1513 (define-key map
(kbd "M-U") 'anything-buffer-revert-persistent
)
1514 (define-key map
(kbd "M-D") 'anything-buffer-run-kill-buffers
)
1515 (define-key map
(kbd "C-x C-s") 'anything-buffer-save-persistent
)
1516 (define-key map
(kbd "C-M-%") 'anything-buffer-run-query-replace-regexp
)
1517 (define-key map
(kbd "M-%") 'anything-buffer-run-query-replace
)
1518 (define-key map
(kbd "M-m") 'anything-toggle-all-marks
)
1519 (define-key map
(kbd "M-a") 'anything-mark-all
)
1520 (when (locate-library "elscreen")
1521 (define-key map
(kbd "<C-tab>") 'anything-buffer-switch-to-elscreen
))
1523 "Keymap for buffer sources in anything.")
1525 (defvar anything-find-files-map
1526 (let ((map (copy-keymap anything-map
)))
1527 (define-key map
(kbd "C-]") 'anything-ff-run-toggle-basename
)
1528 (define-key map
(kbd "C-x C-f") 'anything-ff-run-locate
)
1529 (define-key map
(kbd "M-g s") 'anything-ff-run-grep
)
1530 (define-key map
(kbd "M-g p") 'anything-ff-run-pdfgrep
)
1531 (define-key map
(kbd "M-g z") 'anything-ff-run-zgrep
)
1532 (define-key map
(kbd "M-.") 'anything-ff-run-etags
)
1533 (define-key map
(kbd "M-R") 'anything-ff-run-rename-file
)
1534 (define-key map
(kbd "M-C") 'anything-ff-run-copy-file
)
1535 (define-key map
(kbd "M-B") 'anything-ff-run-byte-compile-file
)
1536 (define-key map
(kbd "M-L") 'anything-ff-run-load-file
)
1537 (define-key map
(kbd "M-S") 'anything-ff-run-symlink-file
)
1538 (define-key map
(kbd "M-D") 'anything-ff-run-delete-file
)
1539 (define-key map
(kbd "M-K") 'anything-ff-run-kill-buffer-persistent
)
1540 (define-key map
(kbd "M-e") 'anything-ff-run-switch-to-eshell
)
1541 (define-key map
(kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point
)
1542 (define-key map
(kbd "C-o") 'anything-ff-run-switch-other-window
)
1543 (define-key map
(kbd "C-c C-o") 'anything-ff-run-switch-other-frame
)
1544 (define-key map
(kbd "C-c C-x") 'anything-ff-run-open-file-externally
)
1545 (define-key map
(kbd "M-!") 'anything-ff-run-eshell-command-on-file
)
1546 (define-key map
(kbd "C-=") 'anything-ff-run-ediff-file
)
1547 (define-key map
(kbd "C-c =") 'anything-ff-run-ediff-merge-file
)
1548 (define-key map
(kbd "M-p") 'anything-ff-run-switch-to-history
)
1549 (define-key map
(kbd "M-i") 'anything-ff-properties-persistent
)
1550 (define-key map
(kbd "C-c ?") 'anything-ff-help
)
1551 (define-key map
(kbd "C-}") 'anything-narrow-window
)
1552 (define-key map
(kbd "C-{") 'anything-enlarge-window
)
1553 (define-key map
(kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update
)
1554 (define-key map
(kbd "M-a") 'anything-mark-all
)
1555 (define-key map
(kbd "M-m") 'anything-toggle-all-marks
)
1556 (define-key map
(kbd "M-u") 'anything-unmark-all
)
1557 (define-key map
(kbd "C-c C-a") 'anything-ff-run-gnus-attach-files
)
1558 (define-key map
(kbd "C-c p") 'anything-ff-run-print-file
)
1559 ;; Next 2 have no effect if candidate is not an image file.
1560 (define-key map
(kbd "M-l") 'anything-ff-rotate-left-persistent
)
1561 (define-key map
(kbd "M-r") 'anything-ff-rotate-right-persistent
)
1562 (define-key map
(kbd "C-.") 'anything-find-files-down-one-level
)
1563 (define-key map
(kbd "C-l") 'anything-find-files-down-one-level
)
1564 (define-key map
(kbd "C-h C-b") 'anything-send-bug-report-from-anything
)
1565 (define-key map
(kbd "C-h C-d") 'anything-debug-output
)
1566 (when anything-ff-lynx-style-map
1567 (define-key map
(kbd "<left>") 'anything-find-files-down-one-level
)
1568 (define-key map
(kbd "<right>") 'anything-execute-persistent-action
))
1570 "Keymap for `anything-find-files'.")
1572 (defvar anything-c-read-file-map
1573 (let ((map (copy-keymap anything-map
)))
1574 (define-key map
(kbd "C-.") 'anything-find-files-down-one-level
)
1575 (define-key map
(kbd "C-l") 'anything-find-files-down-one-level
)
1576 (define-key map
(kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update
)
1577 (define-key map
(kbd "C-c ?") 'anything-read-file-name-help
)
1578 (when anything-ff-lynx-style-map
1579 (define-key map
(kbd "<left>") 'anything-find-files-down-one-level
)
1580 (define-key map
(kbd "<right>") 'anything-execute-persistent-action
)
1581 (define-key map
(kbd "<M-left>") 'anything-previous-source
)
1582 (define-key map
(kbd "<M-right>") 'anything-next-source
))
1584 "Keymap for `anything-c-read-file-name'.")
1586 (defvar anything-generic-files-map
1587 (let ((map (copy-keymap anything-map
)))
1588 (define-key map
(kbd "M-g s") 'anything-ff-run-grep
)
1589 (define-key map
(kbd "M-g z") 'anything-ff-run-zgrep
)
1590 (define-key map
(kbd "M-g p") 'anything-ff-run-pdfgrep
)
1591 (define-key map
(kbd "M-D") 'anything-ff-run-delete-file
)
1592 (define-key map
(kbd "C-=") 'anything-ff-run-ediff-file
)
1593 (define-key map
(kbd "C-c =") 'anything-ff-run-ediff-merge-file
)
1594 (define-key map
(kbd "C-o") 'anything-ff-run-switch-other-window
)
1595 (define-key map
(kbd "M-i") 'anything-ff-properties-persistent
)
1596 (define-key map
(kbd "C-c C-x") 'anything-ff-run-open-file-externally
)
1597 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1598 (define-key map
(kbd "C-c ?") 'anything-generic-file-help
)
1600 "Generic Keymap for files.")
1602 (defvar anything-c-grep-map
1603 (let ((map (copy-keymap anything-map
)))
1604 (define-key map
(kbd "M-<down>") 'anything-c-goto-next-file
)
1605 (define-key map
(kbd "M-<up>") 'anything-c-goto-precedent-file
)
1606 (define-key map
(kbd "C-o") 'anything-c-grep-run-other-window-action
)
1607 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1608 (define-key map
(kbd "C-x C-s") 'anything-c-grep-run-save-buffer
)
1609 (when anything-c-grep-use-ioccur-style-keys
1610 (define-key map
(kbd "<right>") 'anything-c-grep-run-persistent-action
)
1611 (define-key map
(kbd "<left>") 'anything-c-grep-run-default-action
))
1612 (define-key map
(kbd "C-c ?") 'anything-grep-help
)
1614 "Keymap used in Grep sources.")
1616 (defvar anything-c-pdfgrep-map
1617 (let ((map (copy-keymap anything-map
)))
1618 (define-key map
(kbd "M-<down>") 'anything-c-goto-next-file
)
1619 (define-key map
(kbd "M-<up>") 'anything-c-goto-precedent-file
)
1620 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1621 (define-key map
(kbd "C-c ?") 'anything-pdfgrep-help
)
1623 "Keymap used in pdfgrep.")
1625 (defvar anything-c-etags-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-w") 'anything-yank-text-at-point
)
1630 (define-key map
(kbd "C-c ?") 'anything-etags-help
)
1632 "Keymap used in Etags.")
1634 (defvar anything-eval-expression-map
1635 (let ((map (copy-keymap anything-map
)))
1636 (define-key map
(kbd "<C-return>") 'anything-eval-new-line-and-indent
)
1637 (define-key map
(kbd "<tab>") 'lisp-indent-line
)
1638 (define-key map
(kbd "<C-tab>") 'lisp-complete-symbol
)
1639 (define-key map
(kbd "C-p") 'previous-line
)
1640 (define-key map
(kbd "C-n") 'next-line
)
1641 (define-key map
(kbd "<up>") 'previous-line
)
1642 (define-key map
(kbd "<down>") 'next-line
)
1643 (define-key map
(kbd "<right>") 'forward-char
)
1644 (define-key map
(kbd "<left>") 'backward-char
)
1647 (defvar anything-c-ucs-map
1648 (let ((map (copy-keymap anything-map
)))
1649 (define-key map
(kbd "<C-backspace>") 'anything-c-ucs-persistent-delete
)
1650 (define-key map
(kbd "<C-left>") 'anything-c-ucs-persistent-backward
)
1651 (define-key map
(kbd "<C-right>") 'anything-c-ucs-persistent-forward
)
1652 (define-key map
(kbd "<C-return>") 'anything-c-ucs-persistent-insert
)
1653 (define-key map
(kbd "C-c ?") 'anything-c-ucs-help
)
1655 "Keymap for `anything-ucs'.")
1659 ;;; Embeded documentation.
1662 (defun anything-c-list-preconfigured-anything ()
1663 "Collect preconfigured anything functions in this file."
1666 for entry in
(cdr (assoc
1667 (file-truename (locate-library "anything-config"))
1669 if
(and (consp entry
)
1670 (eq (car entry
) 'defun
)
1671 (string-match "^Preconfigured.+$"
1672 (setq doc
(or (documentation (setq sym
(cdr entry
)))
1674 collect
(cons sym
(match-string 0 doc
))))
1676 (defun anything-c-format-preconfigured-anything ()
1677 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x
) (cdr x
)))
1678 (anything-c-list-preconfigured-anything)))
1680 ;;; Global help message - Used by `anything-help'
1683 (setq anything-help-message
1687 "`anything' is QuickSilver-like candidate-selection framework.
1689 Narrow the list by typing some pattern,
1690 Multiple patterns are allowed by splitting by space.
1691 Select with natural Emacs operations, choose with RET.
1693 If you have any problems, press C-c C-x C-b!!
1694 Feel free to send bug reports. I'll fix them.
1695 The steps are described in the beginning of anything.el file.
1697 == Basic Operations ==
1698 C-p, Up: Previous Line
1699 C-n, Down : Next Line
1700 M-v, PageUp : Previous Page
1701 C-v, PageDown : Next Page
1702 Enter : Execute first (default) action / Select
1705 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1706 M-PageDown, C-M-v : Next Page (other-window)
1708 Tab, C-i : Show action list
1709 Left : Previous Source
1710 Right, C-o : Next Source
1711 C-k : Delete pattern
1712 C-z : Persistent Action (Execute action with anything session kept)
1713 C-c C-x C-b: Send a bug report
1715 == Shortcuts For 2nd/3rd Action ==
1716 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1717 \\[anything-select-3rd-action] : Execute 3rd Action
1720 Visible marks store candidate. Some actions uses marked candidates.
1722 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1723 \\[anything-prev-visible-mark] : Previous Mark
1724 \\[anything-next-visible-mark] : Next Mark
1726 == Miscellaneous Commands ==
1727 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1728 \\[anything-quit-and-find-file] : Drop into `find-file'
1729 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1730 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1731 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1732 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1733 \\[anything-force-update] : Recalculate And Redisplay Candidates
1735 == Global Commands ==
1736 \\<global-map>\\[anything-resume] revives last `anything' session.
1737 It is very useful, so you should bind any key.
1739 Single source is executed by \\[anything-call-source].
1741 == Preconfigured `anything' ==
1742 Preconfigured `anything' is commands that uses `anything' interface.
1743 You can use them without configuration.
1746 (apply 'concat
(anything-c-format-preconfigured-anything))
1750 ;;; `anything-buffer-list' help
1754 (defun anything-c-buffer-help ()
1755 "Help command for anything buffers."
1757 (let ((anything-help-message "== Anything Buffer ==
1759 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1760 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1761 \nSpecific commands for `anything-buffers-list':
1762 \\<anything-c-buffer-map>
1763 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1764 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1765 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1766 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1767 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1768 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1769 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1770 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1771 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1772 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1773 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1774 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1775 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1776 \\[anything-mark-all]\t\t->Mark all.
1777 \\[anything-c-buffer-help]\t\t->Display this help.
1778 \n== Anything Map ==
1784 ;;; Find files help (`anything-find-files')
1788 (defun anything-ff-help ()
1789 "Help command for `anything-find-files'."
1791 (let ((anything-help-message "== Anything Find Files ==
1793 \n- Enter `~/' at end of pattern to quickly reach home directory.
1794 - Enter `/' at end of pattern to quickly reach root of your file system.
1795 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1796 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1797 - Use `C-u C-z' to watch an image.
1798 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1799 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1801 \nSpecific commands for `anything-find-files':
1802 \\<anything-find-files-map>
1803 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1804 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1805 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1806 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1807 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1808 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1809 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1810 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1811 \\[anything-ff-run-load-file]\t\t->Load File.
1812 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1813 \\[anything-ff-run-delete-file]\t\t->Delete File.
1814 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1815 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1816 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1817 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1818 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1819 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1820 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1821 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1822 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1823 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1824 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1825 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1826 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1827 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1828 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1829 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1830 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1831 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1832 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1833 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1834 \\[anything-narrow-window]\t\t->Narrow anything window.
1835 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1836 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1837 \\[anything-ff-help]\t\t->Display this help info.
1838 \n== Anything Map ==
1843 ;;; Help for `anything-c-read-file-name'
1847 (defun anything-read-file-name-help ()
1849 (let ((anything-help-message "== Anything read file name Map ==\
1850 \nSpecific commands for anything-c-read-file-name:
1851 \\<anything-c-read-file-map>
1852 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1853 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1854 \\[anything-next-source]\t\t->Goto next source.
1855 \\[anything-previous-source]\t->Goto previous source.
1856 \\[anything-read-file-name-help]\t\t->Display this help info.
1857 \n== Anything Map ==
1862 ;;; Generic file help - Used by locate.
1866 (defun anything-generic-file-help ()
1868 (let ((anything-help-message "== Anything Generic files Map ==\
1869 \nSpecific commands for anything locate and others files sources:
1870 \\<anything-generic-files-map>
1871 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1872 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1873 \\[anything-ff-run-delete-file]\t\t->Delete file.
1874 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1875 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1876 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1877 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1878 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1879 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1881 You can add after writing search pattern any of the locate command line options.
1882 e.g -b, -e, -n <number>...etc.
1883 See Man locate for more infos.
1884 \n== Anything Map ==
1893 (defun anything-grep-help ()
1895 (let ((anything-help-message "== Anything Grep Map ==\
1896 \nSpecific commands for Grep and Etags:
1897 \\<anything-c-grep-map>
1898 \\[anything-c-goto-next-file]\t->Next File.
1899 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1900 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1901 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1902 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1903 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1904 \\[anything-grep-help]\t\t->Show this help.
1905 \n== Anything Map ==
1913 (defun anything-pdfgrep-help ()
1915 (let ((anything-help-message "== Anything PdfGrep Map ==\
1916 \nSpecific commands for Pdf Grep:
1917 \\<anything-c-pdfgrep-map>
1918 \\[anything-c-goto-next-file]\t->Next File.
1919 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1920 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1921 \\[anything-pdfgrep-help]\t\t->Show this help.
1922 \n== Anything Map ==
1930 (defun anything-etags-help ()
1931 "The help function for etags."
1933 (let ((anything-help-message "== Anything Etags Map ==\
1934 \nSpecific commands for Etags:
1935 \\<anything-c-etags-map>
1936 \\[anything-c-goto-next-file]\t->Next File.
1937 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1938 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1939 \\[anything-etags-help]\t\t->Show this help.
1940 \n== Anything Map ==
1947 (defun anything-c-ucs-help ()
1948 "Help command for `anything-ucs'."
1950 (let ((anything-help-message "== Anything Ucs ==
1951 \nSpecific commands for `anything-ucs':
1952 \\<anything-c-ucs-map>
1953 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1954 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1955 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1956 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1957 \\[anything-c-ucs-help]\t\t->Show this help.
1959 \n== Anything Map ==
1966 ;;; Mode line strings
1969 (defvar anything-buffer-mode-line-string
1971 "\\<anything-c-buffer-map>\
1972 \\[anything-c-buffer-help]:Help, \
1974 \\[anything-select-action]:Acts,\
1975 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1976 \\[anything-select-3rd-action]:NthAct,\
1977 \\[anything-send-bug-report-from-anything]:BugReport."
1978 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1980 (defvar anything-ff-mode-line-string
1981 "\\<anything-find-files-map>\
1982 \\[anything-ff-help]:Help, \
1983 \\[anything-send-bug-report-from-anything]:BugReport, \
1985 \\[anything-select-action]:Acts, \
1986 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1987 \\[anything-select-3rd-action]:NthAct"
1988 "String displayed in mode-line in `anything-c-source-find-files'")
1990 (defvar anything-read-file-name-mode-line-string
1991 "\\<anything-c-read-file-map>\
1992 \\[anything-read-file-name-help]:Help, \
1994 \\[anything-select-action]:Acts,\
1995 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1996 \\[anything-select-3rd-action]:NthAct"
1997 "String displayed in mode-line in `anything-c-source-find-files'")
1999 (defvar anything-generic-file-mode-line-string
2000 "\\<anything-generic-files-map>\
2001 \\[anything-generic-file-help]:Help, \
2003 \\[anything-select-action]:Acts,\
2004 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2005 \\[anything-select-3rd-action]:NthAct,\
2006 \\[anything-send-bug-report-from-anything]:BugReport."
2007 "String displayed in mode-line in Locate.")
2009 (defvar anything-grep-mode-line-string
2010 "\\<anything-c-grep-map>\
2011 \\[anything-grep-help]:Help,\
2013 \\[anything-select-action]:Acts,\
2014 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2015 \\[anything-select-3rd-action]:NthAct,\
2016 \\[anything-send-bug-report-from-anything]:BugReport."
2017 "String displayed in mode-line in `anything-do-grep'.")
2019 (defvar anything-pdfgrep-mode-line-string
2020 "\\<anything-c-pdfgrep-map>\
2021 \\[anything-pdfgrep-help]:Help,\
2023 \\[anything-select-action]:Acts,\
2024 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2025 \\[anything-select-3rd-action]:NthAct,\
2026 \\[anything-send-bug-report-from-anything]:BugReport."
2027 "String displayed in mode-line in `anything-do-pdfgrep'.")
2029 (defvar anything-etags-mode-line-string
2030 "\\<anything-c-etags-map>\
2031 \\[anything-etags-help]:Help,\
2033 \\[anything-select-action]:Acts,\
2034 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2035 \\[anything-select-3rd-action]:NthAct,\
2036 \\[anything-send-bug-report-from-anything]:BugReport."
2037 "String displayed in mode-line in `anything-c-etags-select'.")
2040 (defvar anything-c-ucs-mode-line-string
2041 "\\<anything-c-ucs-map>\
2042 \\[anything-c-ucs-help]:Help, \
2044 \\[anything-select-action]:Acts,\
2045 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2046 \\[anything-select-3rd-action]:NthAct."
2047 "String displayed in mode-line in `anything-ucs'.")
2051 ;;; Utilities Functions
2054 (defun anything-ff-find-printers ()
2055 "Return a list of available printers on Unix systems."
2056 (let ((printer-list (with-temp-buffer
2057 (call-process "lpstat" nil t nil
"-a")
2058 (split-string (buffer-string) "\n"))))
2059 (loop for p in printer-list
2060 for printer
= (car (split-string p
))
2064 ;; Shut up byte compiler in emacs24*.
2065 (defun anything-c-switch-to-buffer (buffer-or-name)
2066 "Same as `switch-to-buffer' whithout warnings at compile time."
2068 (switch-to-buffer buffer-or-name
)))
2070 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
2071 "A simple and faster replacement of CL `position'."
2072 (loop for i in seq for index from
0
2073 when
(funcall test i item
) return index
))
2075 (defun anything-c-get-pid-from-process-name (process-name)
2076 "Get pid from running process PROCESS-NAME."
2077 (loop with process-list
= (list-system-processes)
2078 for pid in process-list
2079 for process
= (assoc-default 'comm
(process-attributes pid
))
2080 when
(and process
(string-match process-name process
))
2083 (defun* anything-current-buffer-narrowed-p
(&optional
2084 (buffer anything-current-buffer
))
2085 "Check if BUFFER is narrowed.
2086 Default is `anything-current-buffer'."
2087 (with-current-buffer buffer
2088 (let ((beg (point-min))
2090 (total (buffer-size)))
2091 (or (/= beg
1) (/= end
(1+ total
))))))
2093 (defun anything-region-active-p ()
2094 (and transient-mark-mode mark-active
(/= (mark) (point))))
2096 (defun anything-goto-line (lineno)
2097 "Goto LINENO opening only outline headline if needed."
2098 (goto-char (point-min)) (forward-line (1- lineno
))
2099 (when (or (eq major-mode
'org-mode
)
2100 (and (boundp 'outline-minor-mode
)
2101 outline-minor-mode
))
2102 (require 'org
) ; On some old Emacs versions org may not be loaded.
2104 (anything-match-line-color-current-line) (sit-for 0.3)
2105 (anything-match-line-cleanup))
2107 (defun anything-show-this-source-only ()
2108 "Show all candidates of this source."
2110 (setq anything-candidate-number-limit nil
)
2111 (anything-set-source-filter
2112 (list (assoc-default 'name
(anything-get-current-source)))))
2115 (defun anything-test-sources ()
2116 "List all anything sources for test.
2117 The output is sexps which are evaluated by \\[eval-last-sexp]."
2119 (with-output-to-temp-buffer "*Anything Test Sources*"
2120 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
2121 (apropos-internal "^anything-c-source" #'boundp
))
2122 (pop-to-buffer standard-output
)))
2124 (defun anything-nest (&rest same-as-anything
)
2125 "Nested `anything'. If you use `anything' within `anything', use it."
2126 (with-selected-window (anything-window)
2127 (let (anything-current-position
2128 anything-current-buffer
2129 (orig-anything-buffer anything-buffer
)
2133 anything-compiled-sources
2134 anything-buffer-chars-modified-tick
2135 (anything-samewindow t
)
2136 (enable-recursive-minibuffers t
))
2138 (apply #'anything same-as-anything
)
2139 (anything-initialize-overlays orig-anything-buffer
)
2140 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
2142 (defun anything-displaying-source-names ()
2143 "Display sources name."
2144 (with-current-buffer anything-buffer
2145 (goto-char (point-min))
2147 while
(setq pos
(next-single-property-change (point) 'anything-header
))
2149 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
2150 do
(forward-line 1))))
2153 (defun anything-select-source ()
2154 "[OBSOLETE] Select source."
2156 (let ((default (assoc-default 'name
(anything-get-current-source)))
2157 (source-names (anything-displaying-source-names))
2158 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
2159 (anything-get-sources))))
2160 (setq anything-candidate-number-limit
9999)
2162 (let (anything-source-filter)
2163 (anything-nest '(((name .
"Anything Source")
2164 (candidates . source-names
)
2165 (action . identity
))
2166 ((name .
"Anything Source (ALL)")
2167 (candidates . all-source-names
)
2168 (action . identity
)))
2170 default
"*anything select source*"))
2171 (anything-set-source-filter (list it
))
2172 (anything-set-source-filter nil
))))
2174 (defun anything-c-match-on-file-name (candidate)
2175 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2176 (string-match anything-pattern
(file-name-nondirectory candidate
)))
2178 (defun anything-c-match-on-directory-name (candidate)
2179 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2180 (anything-aif (file-name-directory candidate
)
2181 (string-match anything-pattern it
)))
2183 (defun anything-c-match-on-basename (candidate)
2184 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2185 (string-match anything-pattern
(anything-c-basename candidate
)))
2187 (defun anything-c-string-match (candidate)
2188 "Return non-nil if `anything-pattern' match CANDIDATE.
2189 The match is done with `string-match'."
2190 (string-match anything-pattern candidate
))
2192 (defun anything-c-skip-entries (list regexp
)
2193 "Remove entries which matches REGEXP from LIST."
2194 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
2197 (defun anything-c-shadow-entries (list regexp
)
2198 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2199 (mapcar (lambda (file)
2200 ;; Add shadow face property to boring files.
2201 (let ((face (if (facep 'file-name-shadow
)
2203 ;; fall back to default on XEmacs
2205 (if (string-match regexp file
)
2206 (setq file
(propertize file
'face face
))))
2210 (defsubst anything-c-stringify
(str-or-sym)
2211 "Get string of STR-OR-SYM."
2212 (if (stringp str-or-sym
)
2214 (symbol-name str-or-sym
)))
2216 (defsubst anything-c-symbolify
(str-or-sym)
2217 "Get symbol of STR-OR-SYM."
2218 (if (symbolp str-or-sym
)
2220 (intern str-or-sym
)))
2222 (defun anything-c-describe-function (func)
2223 "FUNC is symbol or string."
2224 (describe-function (anything-c-symbolify func
)))
2226 (defun anything-c-describe-variable (var)
2227 "VAR is symbol or string."
2228 (describe-variable (anything-c-symbolify var
)))
2230 (defun anything-c-find-function (func)
2231 "FUNC is symbol or string."
2232 (find-function (anything-c-symbolify func
)))
2234 (defun anything-c-find-variable (var)
2235 "VAR is symbol or string."
2236 (find-variable (anything-c-symbolify var
)))
2238 (defun anything-c-kill-new (candidate &optional replace
)
2239 "CANDIDATE is symbol or string.
2240 See `kill-new' for argument REPLACE."
2241 (kill-new (anything-c-stringify candidate
) replace
))
2243 (defun* anything-fast-remove-dups
(seq &key
(test 'eq
))
2244 "Remove duplicates elements in list SEQ.
2245 This is same as `remove-duplicates' but with memoisation.
2246 It is much faster, especially in large lists.
2247 A test function can be provided with TEST argument key.
2249 (let ((cont (make-hash-table :test test
)))
2250 (loop for elm in seq
2251 unless
(gethash elm cont
)
2252 do
(puthash elm elm cont
)
2254 (loop for i being the hash-values in cont collect i
))))
2256 (defadvice eval-defun
(after anything-source-hack activate
)
2257 "Allow immediate execution of anything source when evaling it.
2258 See `anything-c-enable-eval-defun-hack'."
2259 (when anything-c-enable-eval-defun-hack
2260 (let ((varsym (save-excursion
2261 (beginning-of-defun)
2263 (when (memq (read (current-buffer)) '(defvar setq
))
2264 (read (current-buffer))))))
2265 (when (string-match "^anything-c-source-" (symbol-name varsym
))
2266 (anything varsym
)))))
2267 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2270 ;; Move this function from anything.el and redefine here
2271 ;; to avoid an unneeded defadvice.
2272 (defun anything-quit-and-find-file ()
2273 "Drop into `anything-find-files' from `anything'.
2274 If current selection is a buffer or a file, `anything-find-files'
2275 from its directory."
2277 (anything-run-after-quit
2279 (if (file-exists-p f
)
2280 (anything-find-files-1 (file-name-directory f
)
2281 (if anything-ff-transformer-show-only-basename
2282 (anything-c-basename f
) f
))
2283 (anything-find-files-1 f
)))
2284 (anything-aif (get-buffer (anything-get-selection))
2285 (or (buffer-file-name it
)
2286 (car (rassoc it dired-buffers
))
2287 (and (with-current-buffer it
2288 (eq major-mode
'org-agenda-mode
))
2290 (expand-file-name org-directory
))
2292 (let ((sel (anything-get-selection)))
2293 (if (file-exists-p sel
)
2294 (expand-file-name sel
)
2295 default-directory
)))))
2298 (defmacro* anything-c-walk-directory
(directory &key path
(directories t
) match
)
2299 "Walk through DIRECTORY tree.
2300 PATH can be one of basename, relative, or full.
2301 DIRECTORIES when non--nil (default) return also directories names, otherwise
2302 skip directories names.
2303 MATCH match only filenames matching regexp MATCH."
2306 (basename 'file-name-nondirectory
)
2307 (relative 'file-relative-name
)
2309 (t 'file-name-nondirectory
))))
2310 (labels ((ls-R (dir)
2311 (loop with ls
= (directory-files dir t directory-files-no-dot-files-regexp
)
2313 if
(file-directory-p f
)
2314 do
(progn (when ,directories
2315 (push (funcall fn f
) result
))
2316 ;; Don't recurse in directory symlink.
2317 (unless (file-symlink-p f
)
2320 (unless (and ,match
(not (string-match ,match
(file-name-nondirectory f
))))
2321 (push (funcall fn f
) result
)))))
2323 (nreverse result
))))
2325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2327 ;;; Anything regexp.
2330 (defun anything-c-query-replace-regexp (candidate)
2331 "Query replace regexp from `anything-regexp'.
2332 With a prefix arg replace only matches surrounded by word boundaries,
2333 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2334 (let ((regexp (funcall (anything-attr 'regexp
))))
2335 (apply 'query-replace-regexp
2336 (anything-c-query-replace-args regexp
))))
2338 (defun anything-c-kill-regexp-as-sexp (candidate)
2339 "Kill regexp in a format usable in lisp code."
2340 (anything-c-regexp-kill-new
2341 (prin1-to-string (funcall (anything-attr 'regexp
)))))
2343 (defun anything-c-kill-regexp (candidate)
2344 "Kill regexp as it is in `anything-pattern'."
2345 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
2347 (defun anything-c-query-replace-args (regexp)
2348 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2349 (let ((region-only (anything-region-active-p)))
2352 (query-replace-read-to regexp
2353 (format "Query replace %sregexp %s"
2354 (if anything-current-prefix-arg
"word " "")
2355 (if region-only
"in region " ""))
2357 anything-current-prefix-arg
2358 (when region-only
(region-beginning))
2359 (when region-only
(region-end)))))
2361 (defvar anything-c-source-regexp
2362 '((name .
"Regexp Builder")
2364 (anything-candidate-buffer anything-current-buffer
)))
2365 (candidates-in-buffer)
2366 (get-line . anything-c-regexp-get-line
)
2367 (persistent-action . anything-c-regexp-persistent-action
)
2368 (persistent-help .
"Show this line")
2371 (requires-pattern .
2)
2372 (mode-line .
"Press TAB to select action.")
2373 (regexp .
(lambda () anything-input
))
2374 (action .
(("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
2375 ("Query Replace Regexp (C-u Not inside word.)"
2376 . anything-c-query-replace-regexp
)
2377 ("Kill Regexp" . anything-c-kill-regexp
)))))
2379 (defun anything-c-regexp-get-line (s e
)
2383 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
2385 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
2386 collect
(format "\n %s'%s'"
2387 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
2390 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2391 ;; It is implementation problem of candidates-in-buffer.
2395 (defun anything-c-regexp-persistent-action (pt)
2397 (anything-persistent-highlight-point))
2399 (defun anything-c-regexp-kill-new (input)
2401 (message "Killed: %s" input
))
2405 ;;; Toggle all marks.
2409 (defun anything-mark-all ()
2410 "Mark all visible unmarked candidates in current source."
2412 (with-anything-window
2414 (goto-char (anything-get-previous-header-pos))
2415 (anything-next-line)
2416 (let* ((next-head (anything-get-next-header-pos))
2419 (goto-char next-head
)
2422 (maxpoint (or end
(point-max))))
2423 (while (< (point) maxpoint
)
2424 (anything-mark-current-line)
2425 (let ((prefix (get-text-property (point-at-bol) 'display
))
2426 (bn (anything-c-basename (anything-get-selection)))
2427 (src (assoc-default 'name
(anything-get-current-source))))
2428 (when (and (not (anything-this-visible-mark))
2429 (not (or (string= prefix
"[?]")
2430 (string= prefix
"[@]"))))
2431 ;; Don't mark possibles directories ending with . or ..
2432 ;; and also autosave files/links.
2434 (and (or (anything-file-completion-source-p)
2435 (equal src
"Files from Current Directory"))
2436 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn
))
2437 (anything-make-visible-mark))))
2438 (forward-line 1) (end-of-line))))
2439 (anything-mark-current-line)
2440 (message "%s candidates marked" (length anything-marked-candidates
))))
2443 (defun anything-unmark-all ()
2444 "Unmark all candidates in all sources of current anything session."
2446 (with-anything-window
2447 (let ((len (length anything-marked-candidates
)))
2449 (anything-clear-visible-mark))
2450 (setq anything-marked-candidates nil
)
2451 (anything-mark-current-line)
2452 (message "%s candidates unmarked" len
))))
2455 (defun anything-toggle-all-marks ()
2457 Mark all visible candidates of current source or unmark all candidates
2458 visible or invisible in all sources of current anything session"
2460 (let ((marked (anything-marked-candidates)))
2461 (if (and (>= (length marked
) 1)
2462 (with-anything-window anything-visible-mark-overlays
))
2463 (anything-unmark-all)
2464 (anything-mark-all))))
2471 (defun anything-c-buffer-list ()
2472 "Return the list of names of buffers with boring buffers filtered out.
2473 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2474 The first buffer in the list will be the last recently used
2475 buffer that is not the current buffer."
2476 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
2477 (append (cdr buffers
) (list (car buffers
)))))
2479 (defvar anything-c-source-buffers
2480 '((name .
"Buffers")
2481 (candidates . anything-c-buffer-list
)
2483 ;; (anything 'anything-c-source-buffers)
2485 (defvar anything-c-source-buffer-not-found
2486 '((name .
"Create buffer")
2488 (filtered-candidate-transformer (lambda (cands source
)
2489 (list anything-pattern
)))
2490 (action .
(lambda (candidate)
2491 (anything-c-switch-to-buffer (get-buffer-create candidate
))))))
2492 ;; (anything 'anything-c-source-buffer-not-found)
2494 ;;; Buffers-list (was buffers+)
2497 (eval-when-compile (require 'dired
))
2499 (defun anything-c-highlight-buffers (buffers)
2500 (loop for i in buffers
2501 for buf
= (get-buffer i
)
2502 for bfname
= (buffer-file-name buf
)
2504 (cond (;; A dired buffer.
2505 (rassoc buf dired-buffers
)
2506 (propertize i
'face
'anything-ff-directory
2507 'help-echo
(car (rassoc buf dired-buffers
))))
2508 ;; A buffer file modified somewhere outside of emacs.
2509 ((and bfname
(not (file-remote-p bfname
))
2510 (file-exists-p bfname
)
2511 (not (verify-visited-file-modtime buf
)))
2512 (propertize i
'face
'anything-buffer-saved-out
2514 ;; A new buffer file not already saved on disk.
2515 ((and bfname
(not (file-remote-p bfname
))
2516 (not (verify-visited-file-modtime buf
)))
2517 (propertize i
'face
'anything-buffer-not-saved
2519 ;; A Remote buffer file modified and not saved on disk.
2520 ((and bfname
(file-remote-p bfname
) (buffer-modified-p buf
))
2521 (let ((prefix (propertize
2523 (propertize "@ " 'face
'anything-ff-prefix
))))
2524 (cons (concat prefix
(propertize i
'face
'anything-ff-symlink
2525 'help-echo bfname
)) i
)))
2526 ;; A buffer file modified and not saved on disk.
2527 ((and bfname
(buffer-modified-p buf
))
2528 (propertize i
'face
'anything-ff-symlink
2530 ;; A remote buffer file not modified and saved on disk.
2531 ((and bfname
(file-remote-p bfname
))
2532 (let ((prefix (propertize
2534 (propertize "@ " 'face
'anything-ff-prefix
))))
2535 (cons (concat prefix
(propertize i
'face
'font-lock-type-face
2536 'help-echo bfname
)) i
)))
2537 ;; A buffer file not modified and saved on disk.
2539 (propertize i
'face
'font-lock-type-face
2541 ;; Any non--file buffer.
2542 (t (propertize i
'face
'italic
)))))
2545 (defvar anything-c-source-buffers-list
2546 '((name .
"Buffers")
2547 (candidates . anything-c-buffer-list
)
2549 (match anything-c-buffer-match-major-mode
)
2550 (diff-action . anything-buffer-toggle-diff
)
2551 (revert-action . anything-buffer-revert-and-update
)
2552 (save-action . anything-buffer-save-and-update
)
2553 (candidate-transformer anything-c-skip-current-buffer
2554 anything-c-skip-boring-buffers
2555 anything-c-highlight-buffers
)
2556 (persistent-action . anything-c-buffers-list-persistent-action
)
2558 (mode-line . anything-buffer-mode-line-string
)
2559 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2560 ;; (anything 'anything-c-source-buffers-list)
2562 (defun anything-c-buffer-match-major-mode (candidate)
2563 "Match maybe buffer by major-mode.
2564 If you give a major-mode or partial major-mode,
2565 it will list all buffers of this major-mode and/or buffers with name
2566 matching this major-mode.
2567 If you add a space after major-mode and then a space,
2568 it will match all buffers of the major-mode
2569 before space matching pattern after space.
2570 If you give a pattern which doesn't match a major-mode, it will search buffer
2571 with name matching pattern."
2572 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate
))
2573 (buf (get-buffer cand
)))
2575 (with-current-buffer buf
2576 (let ((mjm (symbol-name major-mode
))
2577 (split (split-string anything-pattern
)))
2578 (cond ((string-match "\\s-$" anything-pattern
)
2579 (string-match (car split
) mjm
))
2580 ((string-match "\\s-" anything-pattern
)
2581 (and (string-match (car split
) mjm
)
2582 (string-match (cadr split
) cand
)))
2583 (t (or (string-match anything-pattern mjm
)
2584 (string-match anything-pattern cand
)))))))))
2586 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag
)
2587 "Query replace in marked buffers.
2588 If REGEXP-FLAG is given use `query-replace-regexp'."
2589 (let ((fn (if regexp-flag
'query-replace-regexp
'query-replace
))
2590 (prompt (if regexp-flag
"Query replace regexp" "Query replace"))
2591 (bufs (anything-marked-candidates)))
2593 with replace
= (query-replace-read-from prompt regexp-flag
)
2594 with tostring
= (unless (consp replace
)
2595 (query-replace-read-to
2596 replace prompt regexp-flag
))
2599 (save-window-excursion
2600 (anything-c-switch-to-buffer buf
)
2602 (let ((case-fold-search t
))
2603 (goto-char (point-min))
2605 (apply fn
(list (car replace
) (cdr replace
)))
2606 (apply fn
(list replace tostring
)))))))))
2608 (defun anything-c-buffer-query-replace-regexp (candidate)
2609 (anything-c-buffer-query-replace-1 'regexp
))
2611 (defun anything-c-buffer-query-replace (candidate)
2612 (anything-c-buffer-query-replace-1))
2614 (defun anything-buffer-toggle-diff (candidate)
2615 "Toggle diff buffer CANDIDATE with it's file."
2616 (if (get-buffer-window "*Diff*")
2617 (kill-buffer "*Diff*")
2618 (diff-buffer-with-file (get-buffer candidate
))))
2621 (defun anything-buffer-diff-persistent ()
2622 "Toggle diff buffer without quitting anything."
2624 (anything-execute-persistent-action 'diff-action
))
2626 (defun anything-buffer-revert-and-update (candidate)
2627 (let ((marked (anything-marked-candidates)))
2628 (loop for buf in marked do
(anything-revert-buffer buf
))
2629 (anything-force-update candidate
)))
2632 (defun anything-buffer-revert-persistent ()
2633 "Revert buffer without quitting anything."
2635 (anything-execute-persistent-action 'revert-action
'onewindow
))
2637 (defun anything-buffer-save-and-update (candidate)
2638 (let ((marked (anything-marked-candidates))
2639 (enable-recursive-minibuffers t
))
2640 (loop for buf in marked do
2641 (with-current-buffer (get-buffer buf
)
2643 (anything-force-update candidate
)))
2646 (defun anything-buffer-save-persistent ()
2647 "Save buffer without quitting anything."
2649 (anything-execute-persistent-action 'save-action
'onewindow
))
2652 (defun anything-buffer-run-kill-buffers ()
2653 "Run kill buffer action from `anything-c-source-buffers-list'."
2655 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers
))
2658 (defun anything-buffer-run-grep ()
2659 "Run Grep action from `anything-c-source-buffers-list'."
2661 (anything-c-quit-and-execute-action 'anything-c-grep-buffers
))
2664 (defun anything-buffer-run-zgrep ()
2665 "Run Grep action from `anything-c-source-buffers-list'."
2667 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers
))
2670 (defun anything-buffer-run-query-replace-regexp ()
2671 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2673 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp
))
2676 (defun anything-buffer-run-query-replace ()
2677 "Run Query replace action from `anything-c-source-buffers-list'."
2679 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace
))
2682 (defun anything-buffer-switch-other-window ()
2683 "Run switch to other window action from `anything-c-source-buffers-list'."
2685 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window
))
2688 (defun anything-buffer-switch-other-frame ()
2689 "Run switch to other frame action from `anything-c-source-buffers-list'."
2691 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame
))
2694 (defun anything-buffer-switch-to-elscreen ()
2695 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2697 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen
))
2700 (defun anything-buffer-run-ediff ()
2701 "Run ediff action from `anything-c-source-buffers-list'."
2703 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers
))
2705 (defun anything-buffer-run-ediff-merge ()
2706 "Run ediff action from `anything-c-source-buffers-list'."
2708 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge
))
2710 (defun anything-c-buffers-persistent-kill (buffer)
2711 "Persistent action to kill buffer."
2712 (with-current-buffer (get-buffer buffer
)
2713 (if (and (buffer-modified-p)
2714 (buffer-file-name (current-buffer)))
2717 (kill-buffer buffer
))
2718 (kill-buffer buffer
)))
2719 (anything-delete-current-selection))
2721 (defun anything-c-buffers-list-persistent-action (candidate)
2722 (if current-prefix-arg
2723 (anything-c-buffers-persistent-kill candidate
)
2724 (anything-c-switch-to-buffer candidate
)))
2730 ;;; File name history
2731 (defvar anything-c-source-file-name-history
2732 '((name .
"File Name History")
2733 (candidates . file-name-history
)
2734 (match anything-c-match-on-basename
)
2736 ;; (anything 'anything-c-source-file-name-history)
2738 ;;; Files in current dir
2741 (defvar anything-c-source-files-in-current-dir
2742 '((name .
"Files from Current Directory")
2743 (candidates .
(lambda ()
2744 (with-anything-current-buffer
2745 (directory-files (anything-c-current-directory)))))
2746 ;; volatile is not needed, I think.
2748 ;; (anything 'anything-c-source-files-in-current-dir)
2750 (defun anything-c-highlight-files (files)
2751 (loop for i in files
2752 if
(file-directory-p i
)
2753 collect
(propertize (file-name-nondirectory i
)
2754 'face
'anything-ff-directory
2755 'help-echo
(expand-file-name i
))
2757 collect
(propertize (file-name-nondirectory i
)
2758 'face
'anything-ff-file
2759 'help-echo
(expand-file-name i
))))
2761 (defvar anything-c-source-files-in-current-dir
+
2762 '((name .
"Files from Current Directory")
2763 (candidates .
(lambda ()
2764 (with-anything-current-buffer
2765 (directory-files (anything-c-current-directory) t
))))
2766 (candidate-transformer anything-c-highlight-files
)
2767 ;; volatile is not needed, I think.
2769 ;; (anything 'anything-c-source-files-in-current-dir+)
2773 ;;; Anything-find-files - The anything files browser.
2777 (defvar anything-c-find-files-doc-header
" (`C-l': Go to precedent level)"
2778 "*The doc that is inserted in the Name header of a find-files or dired source.")
2779 (defvar anything-ff-auto-update-flag nil
2780 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2781 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2782 (defvar anything-ff-last-expanded nil
2783 "Store last expanded directory or file.")
2784 (defvar anything-ff-default-directory nil
)
2785 (defvar anything-ff-history nil
)
2786 (defvar anything-ff-cand-to-mark nil
)
2789 (defvar anything-c-source-find-files
2790 `((name .
"Find Files")
2791 (header-name .
(lambda (name)
2792 (concat name anything-c-find-files-doc-header
)))
2793 ;; It is needed for filenames with capital letters
2796 (setq anything-ff-auto-update-flag
2797 anything-ff-auto-update-initial-value
)))
2798 (candidates . anything-find-files-get-candidates
)
2799 (filtered-candidate-transformer anything-c-find-files-transformer
)
2800 (image-action1 . anything-ff-rotate-image-left
)
2801 (image-action2 . anything-ff-rotate-image-right
)
2802 (toggle-basename . anything-ff-toggle-basename
)
2803 (properties-action . anything-ff-properties
)
2804 (toggle-auto-update . anything-ff-toggle-auto-update
)
2805 (kill-buffer-fname . anything-ff-kill-buffer-fname
)
2806 (persistent-action . anything-find-files-persistent-action
)
2807 (persistent-help .
"Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2808 (mode-line . anything-ff-mode-line-string
)
2810 (candidate-number-limit .
9999)
2811 (action-transformer . anything-find-files-action-transformer
)
2815 `(("Find File" . anything-c-find-file-or-marked
)
2816 ("Find file in Dired" . anything-c-point-file-in-dired
)
2817 ,(and (locate-library "elscreen")
2818 '("Find file in Elscreen" . anything-elscreen-find-file
))
2819 ,(and (locate-library "popwin")
2820 '("Find file in popup window" . popwin
:find-file
))
2821 ("Checksum File" . anything-ff-checksum
)
2822 ("Complete at point `M-tab'"
2823 . anything-c-insert-file-name-completion-at-point
)
2824 ("Open file externally `C-c C-x, C-u to choose'"
2825 . anything-c-open-file-externally
)
2826 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep
)
2827 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep
)
2828 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell
)
2829 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select
)
2830 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2831 . anything-find-files-eshell-command-on-file
)
2832 ("Find file as root" . anything-find-file-as-root
)
2833 ("Find file in hex dump" . hexl-find-file
)
2834 ("Ediff File `C-='" . anything-find-files-ediff-files
)
2835 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files
)
2836 ("Delete File(s) `M-D'" . anything-delete-marked-files
)
2837 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy
)
2838 ("Copy file(s) Async" . anything-ff-copy-async
)
2839 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename
)
2840 ("Serial rename files" . anything-ff-serial-rename
)
2841 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink
)
2842 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying
)
2843 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink
)
2844 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink
)
2845 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink
)
2846 ("Find file other window `C-o'" . find-file-other-window
)
2847 ("Switch to history `M-p'" . anything-find-files-switch-to-hist
)
2848 ("Find file other frame `C-c C-o'" . find-file-other-frame
)
2849 ("Print File `C-c p'" . anything-ff-print
)
2850 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate
))))))
2851 ;; (anything 'anything-c-source-find-files)
2853 (defun anything-find-files-set-prompt-for-action (action files
)
2854 "Set prompt for action ACTION for FILES."
2855 (let ((len (length files
)))
2856 (format "%s *%s File(s)\n%s to: "
2858 (mapconcat (lambda (f)
2859 (format "- %s\n" f
)) files
""))))
2861 (defun anything-dwim-target-directory ()
2862 "Return value of `default-directory' of buffer in other window.
2863 If there is only one window return the value ot `default-directory'
2864 for current buffer."
2865 (with-anything-current-buffer
2866 (let ((num-windows (length (window-list))))
2867 (if (> num-windows
1)
2868 (save-window-excursion
2871 (car anything-ff-history
)))))
2873 (defun anything-find-files-do-action (action)
2874 "Generic function for creating action from `anything-c-source-find-files'.
2875 ACTION must be an action supported by `anything-dired-action'."
2876 (let* ((ifiles (mapcar 'expand-file-name
; Allow modify '/foo/.' -> '/foo'
2877 (anything-marked-candidates)))
2878 (cand (anything-get-selection)) ; Target
2879 (prompt (anything-find-files-set-prompt-for-action
2880 (capitalize (symbol-name action
)) ifiles
))
2881 (parg anything-current-prefix-arg
)
2882 (dest (anything-c-read-file-name
2884 :preselect
(if anything-ff-transformer-show-only-basename
2885 (anything-c-basename cand
) cand
)
2886 :initial-input
(anything-dwim-target-directory)
2887 :history
(anything-find-files-history :comp-read nil
))))
2888 (anything-dired-action
2889 dest
:files ifiles
:action action
:follow parg
)))
2891 (defun anything-find-files-copy (candidate)
2892 "Copy files from `anything-find-files'."
2893 (anything-find-files-do-action 'copy
))
2895 (defun anything-find-files-rename (candidate)
2896 "Rename files from `anything-find-files'."
2897 (anything-find-files-do-action 'rename
))
2899 (defun anything-find-files-symlink (candidate)
2900 "Symlink files from `anything-find-files'."
2901 (anything-find-files-do-action 'symlink
))
2903 (defun anything-find-files-relsymlink (candidate)
2904 "Relsymlink files from `anything-find-files'."
2905 (anything-find-files-do-action 'relsymlink
))
2907 (defun anything-find-files-hardlink (candidate)
2908 "Hardlink files from `anything-find-files'."
2909 (anything-find-files-do-action 'hardlink
))
2911 (defun anything-find-files-byte-compile (candidate)
2912 "Byte compile elisp files from `anything-find-files'."
2913 (let ((files (anything-marked-candidates))
2914 (parg anything-current-prefix-arg
))
2915 (loop for fname in files
2916 do
(byte-compile-file fname parg
))))
2918 (defun anything-find-files-load-files (candidate)
2919 "Load elisp files from `anything-find-files'."
2920 (let ((files (anything-marked-candidates)))
2921 (loop for fname in files
2924 (defun anything-find-files-ediff-files-1 (candidate &optional merge
)
2925 "Generic function to ediff/merge files in `anything-find-files'."
2926 (let ((bname (anything-c-basename candidate
))
2927 (prompt (if merge
"Ediff Merge `%s' With File: "
2928 "Ediff `%s' With File: "))
2929 (fun (if merge
'ediff-merge-files
'ediff-files
)))
2932 (condition-case quit
2933 (anything-c-read-file-name
2934 (format prompt bname
))
2935 (quit ;; Hit C-g ask user to fallback to locate.
2936 (if (y-or-n-p "Search file for ediff with locate? ")
2937 (anything-c-locate-read-file-name
2938 (format prompt bname
)
2939 ;; Check if -b option is available.
2940 (if (and (eq system-type
'windows-nt
)
2941 (string-match "^es" anything-c-locate-command
))
2943 (concat bname
" -b")))
2944 (error "Error: Ediff Operation aborted")))))))
2946 (defun anything-find-files-ediff-files (candidate)
2947 (anything-find-files-ediff-files-1 candidate
))
2949 (defun anything-find-files-ediff-merge-files (candidate)
2950 (anything-find-files-ediff-files-1 candidate
'merge
))
2952 (defun anything-find-files-grep (candidate)
2953 "Default action to grep files from `anything-find-files'."
2954 (anything-do-grep-1 (anything-marked-candidates)
2955 anything-current-prefix-arg
))
2957 (defun anything-ff-zgrep (candidate)
2958 "Default action to zgrep files from `anything-find-files'."
2959 (let ((prefarg anything-current-prefix-arg
)
2960 (ls (anything-marked-candidates)))
2961 (anything-ff-zgrep-1 ls prefarg
)))
2963 (defun anything-ff-pdfgrep (candidate)
2964 "Default action to pdfgrep files from `anything-find-files'."
2965 (let ((cands (loop for file in
(anything-marked-candidates)
2966 if
(or (string= (file-name-extension file
) "pdf")
2967 (string= (file-name-extension file
) "PDF"))
2969 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init
))
2971 (anything-do-pdfgrep-1 cands
))))
2973 (defun anything-ff-etags-select (candidate)
2974 "Default action to jump to etags from `anything-find-files'."
2975 (when (get-buffer anything-action-buffer
)
2976 (kill-buffer anything-action-buffer
))
2977 (let ((default-directory anything-ff-default-directory
))
2978 (anything-c-etags-select anything-current-prefix-arg
)))
2980 (defun anything-find-files-switch-to-hist (candidate)
2981 "Switch to anything-find-files history."
2982 (anything-find-files t
))
2984 ;;; Asynchronous copy of files.
2987 (defun anything-c-copy-files-async-1 (flist dest
)
2988 "Copy a list of Files FLIST to DEST asynchronously.
2989 It use another emacs process to do the job.
2990 Communication with background emacs is done with temp file
2991 `anything-c-copy-files-async-log-file'."
2992 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
2993 "-Q" "--batch" "--eval"
2995 (require 'dired) (require 'cl)
2996 (let ((dired-recursive-copies 'always)
3002 (let ((file-exists (file-exists-p
3004 (file-name-nondirectory (directory-file-name f))
3005 (file-name-directory
3006 (file-name-as-directory \"%s\"))))))
3007 (dired-copy-file f \"%s\" t)
3009 (progn (push (cons \"Overwriting\" f) success)
3011 (push (cons \"Copying\" f) success)
3014 (push (dired-make-relative
3016 (file-name-nondirectory (directory-file-name f))
3017 (file-name-directory \"%s\")))
3019 (with-current-buffer (find-file-noselect \"%s\")
3022 (dolist (fail (reverse failures))
3023 (insert (concat \"Failed to copy \" fail \"\n\"))))
3025 (loop for (a . s) in (reverse success) do
3026 (insert (concat a \" \" s \" to %s done\n\"))))
3027 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3028 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3029 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3031 flist dest dest dest anything-c-copy-files-async-log-file dest
)))
3033 (defun anything-c-copy-async-with-log (flist dest
)
3034 "Copy file list FLIST to DEST showing log.
3035 Log is send to `anything-c-copy-files-async-log-file'.
3036 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3037 (declare (special auto-revert-interval
))
3038 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file
))
3039 (set (make-local-variable 'auto-revert-interval
) 1)
3041 (insert "Wait copying files...\n")
3042 (sit-for 0.5) (save-buffer)
3043 (goto-char (point-max))
3044 (auto-revert-mode 1)
3045 (anything-c-copy-files-async-1 flist dest
))
3047 (defun anything-ff-copy-async (candidate)
3048 "Anything find files action to copy files async.
3049 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3050 (let* ((flist (anything-marked-candidates))
3051 (dest (anything-c-read-file-name
3052 (anything-find-files-set-prompt-for-action
3054 :preselect candidate
3055 :initial-input
(car anything-ff-history
)
3056 :history
(anything-find-files-history :comp-read nil
))))
3057 (anything-c-copy-async-with-log flist dest
)))
3059 (defvar eshell-command-aliases-list nil
)
3060 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map
)
3061 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3063 Basename of CANDIDATE can be a wild-card.
3064 If MAP is given run `eshell-command' on all marked files at once,
3065 Otherwise, run `eshell-command' on each marked files.
3067 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3068 `eshell-command-aliases-list' will not be loaded first time you use this."
3069 (when (or eshell-command-aliases-list
3070 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3071 (and eshell-command-aliases-list
(eshell-read-aliases-list))
3072 (let* ((cand-list (anything-marked-candidates))
3073 (default-directory (or anything-ff-default-directory
3074 ;; If candidate is an url *-ff-default-directory is nil
3075 ;; so keep value of default-directory.
3077 (command (anything-comp-read
3079 (loop for
(a . c
) in eshell-command-aliases-list
3080 when
(string-match "\\(\\$1\\|\\$\\*\\)$" (car c
))
3081 collect
(propertize a
'help-echo
(car c
)) into ls
3082 finally return
(sort ls
'string
<))))
3083 (com-value (car (assoc-default command eshell-command-aliases-list
))))
3084 (if (and (or map
(and com-value
(string-match "\\$\\*$" com-value
)))
3085 (> (length cand-list
) 1))
3086 ;; Run eshell-command with ALL marked files as arguments.
3087 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list
" ")))
3088 (eshell-command (format "%s %s" command mapfiles
)))
3089 ;; Run eshell-command on EACH marked files.
3092 for bn
= (anything-c-basename i
)
3093 for files
= (if (and bn
(string-match "^\*" bn
))
3094 ;; Assume if fname is a wildcard
3095 ;; cand-list have a length of 1.
3097 'shell-quote-argument
3098 (file-expand-wildcards i t
) " ")
3100 for com
= (if (string-match "'%s'\\|\"%s\"\\|%s" command
)
3101 ;; This allow to enter other args AFTER filename
3102 ;; i.e <command %s some_more_args>
3103 (format command files
)
3104 (format "%s %s" command files
))
3105 do
(eshell-command com
))))))
3107 (defun anything-find-files-eshell-command-on-file (candidate)
3108 "Run `eshell-command' on CANDIDATE or marked candidates.
3109 See `anything-find-files-eshell-command-on-file-1' for more info."
3110 (anything-find-files-eshell-command-on-file-1
3111 candidate anything-current-prefix-arg
))
3113 (defun anything-ff-switch-to-eshell (candidate)
3114 "Switch to eshell and cd to `anything-ff-default-directory'."
3115 (flet ((cd-eshell ()
3116 (goto-char (point-max))
3118 (format "cd '%s'" anything-ff-default-directory
))
3119 (eshell-send-input)))
3120 (if (get-buffer "*eshell*")
3122 (anything-c-switch-to-buffer "*eshell*")
3124 (call-interactively 'eshell
)
3127 (defun anything-ff-serial-rename-action (method)
3128 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3129 See `anything-ff-serial-rename-1'."
3130 (let* ((cands (anything-marked-candidates))
3131 (name (read-string "NewName: "))
3132 (start (read-number "StartAtNumber: "))
3133 (extension (read-string "Extension: " (file-name-extension (car cands
))))
3134 (dir (expand-file-name
3135 (anything-c-read-file-name
3136 "Serial Rename to directory: " :initial-input
3137 (expand-file-name anything-ff-default-directory
)))))
3138 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3139 (length cands
) dir name
))
3140 (anything-ff-serial-rename-1 dir cands name start extension
:method method
)
3141 (anything-find-files-1 dir
))))
3143 (defun anything-ff-member-directory-p (file directory
)
3144 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file
))))
3145 (cur-dir (expand-file-name (file-name-as-directory directory
))))
3146 (string= dir-file cur-dir
)))
3148 (defun* anything-ff-serial-rename-1
3149 (directory collection new-name start-at-num extension
&key
(method 'rename
))
3150 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3151 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3152 EXTENSION is the file extension to use, in empty prompt,
3153 reuse the original extension of file.
3154 METHOD can be one of rename, copy or symlink.
3155 Files will be renamed if they are files of current directory, otherwise they
3156 will be treated with METHOD.
3157 Default METHOD is rename."
3158 ;; Maybe remove directories selected by error in collection.
3159 (setq collection
(remove-if 'file-directory-p collection
))
3160 (flet ((symlink-file (file dest
)
3161 (let ((flist (list file
)))
3162 (anything-dired-action
3163 dest
:action
'symlink
:files flist
))))
3165 (let* ((tmp-dir (file-name-as-directory
3166 (concat (file-name-as-directory directory
)
3167 (symbol-name (gensym "tmp")))))
3170 (symlink 'symlink-file
)
3171 (rename 'rename-file
)
3172 (t (error "Error: Unknow method %s" method
)))))
3173 (make-directory tmp-dir
)
3174 (loop for i in collection
3175 for count from start-at-num
3176 for fnum
= (if (< count
10) "0%s" "%s")
3177 for nname
= (concat tmp-dir new-name
(format fnum count
)
3178 (if (not (string= extension
""))
3179 (format ".%s" (replace-regexp-in-string
3180 "[.]" "" extension
))
3181 (file-name-extension i
'dot
)))
3182 do
(if (anything-ff-member-directory-p i directory
)
3183 (rename-file i nname
)
3184 (funcall fn i nname
)))
3185 (loop with dirlist
= (directory-files
3186 tmp-dir t directory-files-no-dot-files-regexp
)
3188 (if (file-symlink-p f
)
3189 (symlink-file (file-truename f
)
3190 (concat (file-name-as-directory directory
)
3191 (anything-c-basename f
)))
3192 (rename-file f directory
)))
3193 (delete-directory tmp-dir t
))))
3195 (defun anything-ff-serial-rename (candidate)
3196 "Serial rename all marked files to `anything-ff-default-directory'.
3197 Rename only file of current directory, and symlink files coming from
3199 See `anything-ff-serial-rename-1'."
3200 (anything-ff-serial-rename-action 'rename
))
3202 (defun anything-ff-serial-rename-by-symlink (candidate)
3203 "Serial rename all marked files to `anything-ff-default-directory'.
3204 Rename only file of current directory, and symlink files coming from
3206 See `anything-ff-serial-rename-1'."
3207 (anything-ff-serial-rename-action 'symlink
))
3209 (defun anything-ff-serial-rename-by-copying (candidate)
3210 "Serial rename all marked files to `anything-ff-default-directory'.
3211 Rename only file of current directory, and copy files coming from
3213 See `anything-ff-serial-rename-1'."
3214 (anything-ff-serial-rename-action 'copy
))
3216 (defun anything-c-quit-and-execute-action (action)
3217 "Quit current anything session and execute ACTION."
3218 (setq anything-saved-action action
)
3219 (anything-exit-minibuffer))
3221 (defun anything-ff-toggle-auto-update (candidate)
3222 (setq anything-ff-auto-update-flag
(not anything-ff-auto-update-flag
))
3223 (message "[Auto expansion %s]"
3224 (if anything-ff-auto-update-flag
"enabled" "disabled")))
3227 (defun anything-ff-run-toggle-auto-update ()
3229 (anything-execute-persistent-action 'toggle-auto-update
))
3232 (defun anything-ff-run-switch-to-history ()
3233 "Run Switch to history action from `anything-c-source-find-files'."
3235 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist
))
3238 (defun anything-ff-run-grep ()
3239 "Run Grep action from `anything-c-source-find-files'."
3241 (anything-c-quit-and-execute-action 'anything-find-files-grep
))
3244 (defun anything-ff-run-pdfgrep ()
3245 "Run Pdfgrep action from `anything-c-source-find-files'."
3247 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep
))
3250 (defun anything-ff-run-zgrep ()
3251 "Run Grep action from `anything-c-source-find-files'."
3253 (anything-c-quit-and-execute-action 'anything-ff-zgrep
))
3256 (defun anything-ff-run-copy-file ()
3257 "Run Copy file action from `anything-c-source-find-files'."
3259 (anything-c-quit-and-execute-action 'anything-find-files-copy
))
3262 (defun anything-ff-run-rename-file ()
3263 "Run Rename file action from `anything-c-source-find-files'."
3265 (anything-c-quit-and-execute-action 'anything-find-files-rename
))
3268 (defun anything-ff-run-byte-compile-file ()
3269 "Run Byte compile file action from `anything-c-source-find-files'."
3271 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile
))
3274 (defun anything-ff-run-load-file ()
3275 "Run Load file action from `anything-c-source-find-files'."
3277 (anything-c-quit-and-execute-action 'anything-find-files-load-files
))
3280 (defun anything-ff-run-eshell-command-on-file ()
3281 "Run eshell command on file action from `anything-c-source-find-files'."
3283 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file
))
3286 (defun anything-ff-run-ediff-file ()
3287 "Run Ediff file action from `anything-c-source-find-files'."
3289 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files
))
3292 (defun anything-ff-run-ediff-merge-file ()
3293 "Run Ediff merge file action from `anything-c-source-find-files'."
3295 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files
))
3298 (defun anything-ff-run-symlink-file ()
3299 "Run Symlink file action from `anything-c-source-find-files'."
3301 (anything-c-quit-and-execute-action 'anything-find-files-symlink
))
3304 (defun anything-ff-run-delete-file ()
3305 "Run Delete file action from `anything-c-source-find-files'."
3307 (anything-c-quit-and-execute-action 'anything-delete-marked-files
))
3310 (defun anything-ff-run-complete-fn-at-point ()
3311 "Run complete file name action from `anything-c-source-find-files'."
3313 (anything-c-quit-and-execute-action
3314 'anything-c-insert-file-name-completion-at-point
))
3317 (defun anything-ff-run-switch-to-eshell ()
3318 "Run switch to eshell action from `anything-c-source-find-files'."
3320 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell
))
3323 (defun anything-ff-run-switch-other-window ()
3324 "Run switch to other window action from `anything-c-source-find-files'."
3326 (anything-c-quit-and-execute-action 'find-file-other-window
))
3329 (defun anything-ff-run-switch-other-frame ()
3330 "Run switch to other frame action from `anything-c-source-find-files'."
3332 (anything-c-quit-and-execute-action 'find-file-other-frame
))
3335 (defun anything-ff-run-open-file-externally ()
3336 "Run open file externally command action from `anything-c-source-find-files'."
3338 (anything-c-quit-and-execute-action 'anything-c-open-file-externally
))
3340 (defun anything-ff-locate (candidate)
3341 "Locate action function for `anything-find-files'."
3342 (let ((input (concat (anything-c-basename
3345 anything-ff-default-directory
))
3346 ;; The locate '-b' option doesn't exists
3348 (unless (and (eq system-type
'windows-nt
)
3349 (string-match "^es" anything-c-locate-command
))
3351 (anything-mp-highlight-delay 0.7))
3352 (anything-locate-1 anything-current-prefix-arg input
)))
3355 (defun anything-ff-run-locate ()
3356 "Run locate action from `anything-c-source-find-files'."
3358 (anything-c-quit-and-execute-action 'anything-ff-locate
))
3361 (defun anything-ff-run-gnus-attach-files ()
3362 "Run gnus attach files command action from `anything-c-source-find-files'."
3364 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files
))
3367 (defun anything-ff-run-etags ()
3368 "Run Etags command action from `anything-c-source-find-files'."
3370 (anything-c-quit-and-execute-action 'anything-ff-etags-select
))
3373 (defun anything-ff-print (candidate)
3374 "Print marked files.
3375 You have to set in order
3376 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3379 \(setq lpr-command \"gtklp\"\)
3380 \(setq lpr-switches '(\"-P\")\)
3381 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3383 Same as `dired-do-print' but for anything."
3384 (let* ((file-list (anything-marked-candidates))
3385 (len (length file-list
))
3386 (printer-name (if anything-ff-printer-list
3388 "Printer: " anything-ff-printer-list
)
3390 (command (read-string
3391 (format "Print *%s File(s):\n%s with: "
3394 (lambda (f) (format "- %s\n" f
))
3396 (when (and lpr-command
3399 (mapconcat 'identity
3401 (append (if (stringp lpr-switches
)
3404 (list printer-name
)))
3406 (file-args (mapconcat #'(lambda (x)
3409 (cmd-line (concat command
" " file-args
)))
3411 (start-process-shell-command "anything-print" nil cmd-line
)
3412 (error "Error: Please verify your printer settings in Emacs."))))
3415 (defun anything-ff-run-print-file ()
3416 "Run Print file action from `anything-c-source-find-files'."
3418 (anything-c-quit-and-execute-action 'anything-ff-print
))
3420 (defun anything-ff-checksum (file)
3421 "Calculate the checksum of FILE.
3422 Provide completion on different algorithms to use on Emacs24.
3423 On Emacs23 only 'sha1' is available.
3424 The checksum is copied to kill-ring."
3425 (let ((algo-list (and (fboundp 'secure-hash
)
3426 '(md5 sha1 sha224 sha256 sha384 sha512
))))
3429 (secure-hash (intern
3431 "Algorithm: " algo-list
))
3433 (sha1 (with-temp-buffer
3434 (insert-file-contents file
)
3436 (message "Checksum copied to kill-ring.")))
3438 (defun anything-ff-toggle-basename (candidate)
3439 (setq anything-ff-transformer-show-only-basename
3440 (not anything-ff-transformer-show-only-basename
))
3441 (let ((target (if anything-ff-transformer-show-only-basename
3442 (anything-c-basename candidate
) candidate
)))
3443 (anything-force-update target
)))
3445 (defun anything-ff-run-toggle-basename ()
3447 (anything-execute-persistent-action 'toggle-basename
))
3449 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
3450 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3451 If LEVEL is positive reduce from end else from beginning.
3452 If UNIX-CLOSE is non--nil close filename with /.
3453 If EXPAND is non--nil expand-file-name."
3454 (let* ((exp-fname (expand-file-name fname
))
3455 (fname-list (split-string (if (or (string= fname
"~/") expand
)
3456 exp-fname fname
) "/" t
))
3457 (len (length fname-list
))
3458 (pop-list (if (< level
0)
3459 (subseq fname-list
(* level -
1))
3460 (subseq fname-list
0 (- len level
))))
3461 (result (mapconcat 'identity pop-list
"/"))
3462 (empty (string= result
"")))
3463 (when unix-close
(setq result
(concat result
"/")))
3464 (if (string-match "^~" result
)
3465 (if (string= result
"~/") "~/" result
)
3467 (if empty
"../" (concat "../" result
))
3468 (cond ((eq system-type
'windows-nt
)
3469 (if empty
"c:/" result
))
3472 (concat "/" result
)))))))
3475 (defvar anything-file-completion-sources
3476 '("Find Files" "find-file" "Copy Files"
3477 "dired-do-copy" "dired-do-rename"
3478 "dired-do-symlink" "dired-do-hardlink"
3479 "write-file" "insert-file" "dired"
3480 "find-alternate-file" "find-alternate-file-other-window"
3481 "find-file-read-only" "list-directory"
3482 "Read File Name History" "mml-attach-file"
3483 "Rename Files" "Symlink Files"
3484 "Hardlink Files" "Write File"
3485 "Insert File" "Read File Name")
3486 "Sources that use the *find-files mechanism can be added here.
3487 You should not modify this yourself and know what you do if you do so.")
3489 (defun anything-file-completion-source-p ()
3490 "Test if current source is a dired or find-files source."
3491 (let ((cur-source (cdr (assoc 'name
(anything-get-current-source)))))
3492 (loop for i in anything-file-completion-sources
3493 thereis
(string= cur-source i
))))
3495 (defun anything-find-files-down-one-level (arg)
3496 "Go down one level like unix command `cd ..'.
3497 If prefix numeric arg is given go ARG level down."
3499 (when (and (anything-file-completion-source-p)
3500 (not (anything-ff-invalid-tramp-name-p)))
3501 (with-anything-window
3502 (setq anything-follow-mode nil
))
3503 ;; When going to precedent level we want to be at the line
3504 ;; corresponding to actual directory, so store this info
3505 ;; in `anything-ff-last-expanded'.
3506 (if (and (not (file-directory-p anything-pattern
))
3507 (file-exists-p anything-pattern
))
3508 (setq anything-ff-last-expanded anything-pattern
)
3509 (setq anything-ff-last-expanded anything-ff-default-directory
))
3510 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3511 :unix-close t
:expand t
)))
3512 (anything-set-pattern new-pattern
))))
3514 (defun anything-ff-retrieve-last-expanded ()
3515 "Move overlay to last visited directory `anything-ff-last-expanded'.
3516 This happen after using `anything-find-files-down-one-level',
3517 or hitting C-z on \"..\"."
3518 (when (and anything-ff-last-expanded
3519 (anything-file-completion-source-p))
3520 (let ((dirname (if anything-ff-transformer-show-only-basename
3521 (anything-c-basename
3522 (directory-file-name anything-ff-last-expanded
))
3523 (directory-file-name anything-ff-last-expanded
))))
3524 (with-anything-window
3525 (when (or (re-search-forward (concat dirname
"$") nil t
)
3527 (concat anything-ff-last-expanded
"$") nil t
))
3529 (anything-mark-current-line)))
3530 (setq anything-ff-last-expanded nil
))))
3531 (add-hook 'anything-after-update-hook
'anything-ff-retrieve-last-expanded
)
3533 ;; Auto-update - anything-find-files auto expansion of directories.
3535 (defun anything-ff-update-when-only-one-matched ()
3536 "Expand to directory when sole completion.
3537 When only one candidate is remaining and it is a directory,
3538 expand to this directory."
3539 (when (and anything-ff-auto-update-flag
3540 (anything-file-completion-source-p)
3541 (not (anything-ff-invalid-tramp-name-p)))
3542 (let* ((history-p (string= (assoc-default
3543 'name
(anything-get-current-source))
3544 "Read File Name History"))
3545 (pat (if (string-match tramp-file-name-regexp
3547 (anything-create-tramp-name anything-pattern
)
3549 (completed-p (string= (file-name-as-directory pat
)
3550 anything-ff-default-directory
)))
3552 ;; Only one candidate remaining
3553 ;; and at least 2 char in basename.
3554 (and (<= (anything-approximate-candidate-number) 2)
3555 (>= (length (anything-c-basename anything-pattern
)) 2))
3556 ;; Already completed.
3558 (not history-p
)) ; Don't try to auto complete in history.
3559 (with-anything-window
3560 (let ((cur-cand (prog2
3562 ;; Only one non--existing candidate
3563 ;; and one directory candidate, move to it.
3564 (anything-next-line))
3565 (anything-get-selection))))
3566 (when (file-directory-p cur-cand
)
3567 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand
)) ; [1]
3568 ;; Maybe we are here because completed-p is true
3569 ;; but check this again to be sure. (Windows fix)
3570 (<= (anything-approximate-candidate-number) 2)) ; [2]
3571 ;; If after going to next line the candidate
3572 ;; is not one of "." or ".." [1]
3573 ;; and only one candidate is remaining [2],
3574 ;; assume candidate is a new directory to expand, and do it.
3575 (anything-set-pattern (file-name-as-directory cur-cand
))
3576 ;; The candidate is one of "." or ".."
3577 ;; that mean we have entered the last letter of the directory name
3578 ;; in prompt, so expansion is already done, just add the "/" at end
3579 ;; of name unless anything-pattern ends with "."
3580 ;; (i.e we are writing something starting with ".")
3581 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern
)
3582 (anything-set-pattern
3583 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3584 (expand-file-name (file-name-as-directory anything-pattern
)))))
3585 (anything-check-minibuffer-input-1))))))))
3586 (add-hook 'anything-after-update-hook
'anything-ff-update-when-only-one-matched
)
3588 ;; Allow expanding to home directory or root
3589 ;; when entering respectively "~/" or "//" at end of pattern.
3590 ;; e.g /home/thierry/labo/anything-config-qp/~/
3591 ;; will expand to "~/"
3592 ;; and /home/thierry/labo/anything-config-qp//
3593 ;; will expand to "/"
3594 (defun anything-ff-auto-expand-to-home-or-root ()
3595 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3596 This happen only in function using sources that are
3597 `anything-file-completion-source-p' compliant."
3598 (when (and (anything-file-completion-source-p)
3599 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3601 (let ((match (match-string 1 anything-pattern
)))
3602 (cond ((string= match
"//")
3603 (if (eq system-type
'windows-nt
)
3604 (setq anything-pattern
"c:/")
3605 (setq anything-pattern
"/")))
3606 ((string= match
"/~/")
3607 (if (eq system-type
'windows-nt
)
3608 (setq anything-pattern
(file-name-as-directory (getenv "HOME")))
3609 (setq anything-pattern
"~/")))
3610 ((string= match
"/./")
3611 (setq anything-pattern
3612 (with-anything-current-buffer
3613 (expand-file-name default-directory
))))))
3614 (setq anything-ff-default-directory anything-pattern
)
3615 ;; For some reasons, i must use here with-current-buffer => mini buffer
3616 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3617 (with-current-buffer (window-buffer (minibuffer-window))
3618 (delete-minibuffer-contents)
3619 (insert anything-pattern
))))
3621 (add-hook 'anything-after-update-hook
'anything-ff-auto-expand-to-home-or-root
)
3623 (defun anything-c-point-file-in-dired (file)
3624 "Put point on filename FILE in dired buffer."
3625 (dired (file-name-directory file
))
3626 (dired-goto-file file
))
3628 (defun anything-create-tramp-name (fname)
3629 "Build filename for `anything-pattern' like /su:: or /sudo::."
3630 (apply #'tramp-make-tramp-file-name
3631 (loop with v
= (tramp-dissect-file-name fname
)
3632 for i across v collect i
)))
3634 (defun* anything-ff-tramp-hostnames
(&optional
(pattern anything-pattern
))
3635 "Get a list of hosts for tramp method found in `anything-pattern'.
3636 Argument PATTERN default to `anything-pattern', it is here only for debugging
3638 (when (string-match tramp-file-name-regexp pattern
)
3639 (let ((method (match-string 1 pattern
))
3640 (tn (match-string 0 pattern
))
3641 (all-methods (mapcar 'car tramp-methods
)))
3643 (loop for
(f . h
) in
(tramp-get-completion-function method
)
3644 append
(loop for e in
(funcall f
(car h
))
3645 for host
= (and (consp e
) (cadr e
))
3646 when
(and host
(not (member host all-methods
)))
3647 collect
(concat tn host
)))
3650 (defun anything-ff-before-action-hook-fn ()
3651 "Exit anything when user try to execute action on an invalid tramp fname."
3652 (let ((cand (anything-get-selection)))
3653 (when (and (anything-file-completion-source-p)
3654 (anything-ff-invalid-tramp-name-p cand
) ; Check candidate.
3655 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3656 (error "Error: Unknow file or directory `%s'" cand
))))
3657 (add-hook 'anything-before-action-hook
'anything-ff-before-action-hook-fn
)
3659 (defun* anything-ff-invalid-tramp-name-p
(&optional
(pattern anything-pattern
))
3660 "Return non--nil when PATTERN is an invalid tramp filename."
3661 (string= (anything-ff-set-pattern pattern
)
3662 "Invalid tramp file name"))
3664 (defun anything-ff-set-pattern (pattern)
3665 "Handle tramp filenames in `anything-pattern'."
3666 (let ((methods (mapcar 'car tramp-methods
))
3667 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3668 cur-method tramp-name
)
3669 (cond ((string= pattern
"") "")
3670 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern
)
3671 (with-anything-current-buffer
3672 (expand-file-name default-directory
)))
3673 ((string-match ".*\\(~//\\|//\\)$" pattern
)
3674 (if (eq system-type
'windows-nt
) "c:/" "/"))
3675 ((string-match "^~\\|.*/~/$" pattern
)
3676 (let* ((home (expand-file-name (getenv "HOME"))))
3677 (replace-match home nil t pattern
)))
3678 ;; Match "/method:maybe_hostname:"
3679 ((and (string-match reg pattern
)
3680 (setq cur-method
(match-string 1 pattern
))
3681 (member cur-method methods
))
3682 (setq tramp-name
(anything-create-tramp-name
3683 (match-string 0 pattern
)))
3684 (replace-match tramp-name nil t pattern
))
3685 ;; Match "/hostname:"
3686 ((and (string-match tramp-file-name-regexp pattern
)
3687 (setq cur-method
(match-string 1 pattern
))
3688 (and cur-method
(not (member cur-method methods
))))
3689 (setq tramp-name
(anything-create-tramp-name
3690 (match-string 0 pattern
)))
3691 (replace-match tramp-name nil t pattern
))
3692 ;; Match "/method:" in this case don't try to connect.
3693 ((and (not (string-match reg pattern
))
3694 (string-match tramp-file-name-regexp pattern
)
3695 (member (match-string 1 pattern
) methods
))
3696 "Invalid tramp file name") ; Write in anything-buffer.
3697 ;; PATTERN is a directory, end it with "/".
3698 ;; This will make PATTERN not ending yet with "/"
3699 ;; candidate for `anything-ff-default-directory',
3700 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3701 ;; when descending level.
3702 ((file-directory-p pattern
)
3703 (file-name-as-directory pattern
))
3704 ;; Return PATTERN unchanged.
3707 (defun anything-find-files-get-candidates ()
3708 "Create candidate list for `anything-c-source-find-files'."
3709 (let* ((path (anything-ff-set-pattern anything-pattern
))
3710 (path-name-dir (if (file-directory-p path
)
3711 (file-name-as-directory path
)
3712 (file-name-directory path
)))
3713 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
3714 (set-text-properties 0 (length path
) nil path
)
3715 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3716 ;; like that the actual value (e.g /ssh:) is passed to
3717 ;; `anything-ff-tramp-hostnames'.
3718 (unless (string= path
"Invalid tramp file name")
3719 (setq anything-pattern
(anything-ff-transform-fname-for-completion path
)))
3720 (setq anything-ff-default-directory
3721 (if (string= anything-pattern
"")
3722 (if (eq system-type
'windows-nt
) "c:/" "/")
3723 (unless (string-match ffap-url-regexp path
)
3724 ;; If path is an url *default-directory have to be nil.
3726 (cond ((string= path
"Invalid tramp file name")
3727 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3729 ;; `anything-pattern' have not been modified yet.
3730 ;; Set it here to the value of `path' that should be now
3731 ;; "Invalid tramp file name" and set the candidates list
3732 ;; to ("Invalid tramp file name") to make `anything-pattern'
3733 ;; match single candidate "Invalid tramp file name".
3734 (setq anything-pattern path
)
3735 ;; "Invalid tramp file name" is now printed
3736 ;; in `anything-buffer'.
3738 ((or (file-regular-p path
)
3739 (and (not (file-exists-p path
)) (string-match "/$" path
))
3740 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
3742 ((string= path
"") (directory-files "/" t
))
3743 ((and (file-directory-p path
) (not (file-readable-p path
)))
3744 (list (format "Opening directory: access denied, `%s'" path
)))
3745 ((file-directory-p path
) (directory-files path t
))
3747 (append (list path
) (directory-files path-name-dir t
))))))
3749 (defun anything-ff-transform-fname-for-completion (fname)
3750 "Return FNAME with it's basename modified as a regexp.
3751 e.g foo => f.*o.*o .
3752 If basename contain one or more space or FNAME is a valid directory name
3753 return FNAME unchanged."
3754 (let ((bn (anything-c-basename fname
)))
3755 (if (or (not anything-ff-smart-completion
)
3756 (string-match "\\s-" bn
)
3757 (string-match "/$" fname
) ; Allow mkdir.
3758 (file-directory-p fname
))
3759 fname
; Fall back to match-plugin.
3760 (setq bn
(if (> (length bn
) 2) ; Normal completion on first 2 char.
3761 (mapconcat 'identity
(split-string bn
"" t
) ".*") bn
))
3762 (concat (file-name-directory fname
) bn
))))
3764 (defun anything-ff-save-history ()
3765 "Store the last value of `anything-ff-default-directory' \
3766 in `anything-ff-history'."
3767 (when (and anything-ff-default-directory
3768 (anything-file-completion-source-p))
3769 (push anything-ff-default-directory anything-ff-history
)))
3770 (add-hook 'anything-cleanup-hook
'anything-ff-save-history
)
3772 (defun anything-ff-valid-symlink-p (file)
3773 (file-exists-p (file-truename file
)))
3775 (defun anything-ff-properties (candidate)
3776 "Show file properties of CANDIDATE in a tooltip or message."
3777 (let ((type (anything-ff-attributes candidate
:type t
))
3778 (dired-line (anything-ff-attributes candidate
:dired t
:human-size t
)))
3782 (anything-c-basename candidate
) ": \n"
3784 (when (string= type
"symlink")
3785 (format "True name: '%s'\n"
3786 (cond ((string-match "^\.#" (anything-c-basename candidate
))
3788 ((anything-ff-valid-symlink-p candidate
)
3789 (file-truename candidate
))
3790 (t "Invalid Symlink"))))
3792 (message dired-line
) (sit-for 5))))
3795 (defun anything-ff-properties-persistent ()
3796 "Show properties without quitting anything."
3798 (anything-execute-persistent-action 'properties-action
))
3800 (defun anything-ff-kill-buffer-fname (candidate)
3801 (let* ((buf (get-file-buffer candidate
))
3802 (buf-name (buffer-name buf
)))
3805 (kill-buffer buf
) (message "Buffer `%s' killed" buf
))
3806 (message "No buffer to kill"))))
3808 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3809 "Find file CANDIDATE or kill it's buffer if it is visible.
3810 Never kill `anything-current-buffer'.
3811 Never kill buffer modified.
3812 This is called normally on third hit of \
3813 \\<anything-map>\\[anything-execute-persistent-action]
3814 in `anything-find-files-persistent-action'."
3815 (let* ((buf (get-file-buffer candidate
))
3816 (buf-name (buffer-name buf
)))
3817 (if (and buf
(get-buffer-window buf
)
3818 (not (eq buf
(get-buffer anything-current-buffer
)))
3819 (not (buffer-modified-p buf
)))
3821 (kill-buffer buf
) (message "Buffer `%s' killed" buf-name
))
3822 (find-file candidate
))))
3825 (defun anything-ff-run-kill-buffer-persistent ()
3826 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3828 (anything-execute-persistent-action 'kill-buffer-fname
))
3830 (defun anything-ff-human-size (size)
3831 "Return a string showing SIZE of a file in human readable form.
3832 SIZE can be an integer or a float depending it's value.
3833 `file-attributes' will take care of that to avoid overflow error.
3834 KBSIZE if a floating point number, default value is 1024.0."
3835 (let ((M (cons "M" (/ size
(expt anything-ff-default-kbsize
2))))
3836 (G (cons "G" (/ size
(expt anything-ff-default-kbsize
3))))
3837 (K (cons "K" (/ size anything-ff-default-kbsize
)))
3838 (B (cons "B" size
)))
3839 (loop with result
= B
3841 (loop for
(x . y
) in
(list M G K B
)
3842 unless
(< y
1) collect
(cons x y
))
3843 when
(< b
(cdr result
)) do
(setq result
(cons a b
))
3844 finally return
(if (string= (car result
) "B")
3846 (format "%.1f%s" (cdr result
) (car result
))))))
3848 (defun* anything-ff-attributes
3849 (file &key type links uid gid access-time modif-time
3850 status size mode gid-change inode device-num dired human-size
)
3851 "Easy interface for `file-attributes'."
3852 (let ((all (destructuring-bind
3853 (type links uid gid access-time modif-time
3854 status size mode gid-change inode device-num
)
3855 (file-attributes file
'string
)
3860 :access-time access-time
3861 :modif-time modif-time
3865 :gid-change gid-change
3867 :device-num device-num
))))
3869 (let ((result (getf all
:type
)))
3870 (cond ((stringp result
)
3872 (result "directory")
3874 (links (getf all
:links
))
3875 (uid (getf all
:uid
))
3876 (gid (getf all
:gid
))
3878 (format-time-string "%Y-%m-%d %R" (getf all
:access-time
)))
3880 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
)))
3882 (format-time-string "%Y-%m-%d %R" (getf all
:status
)))
3883 (size (if human-size
(anything-ff-human-size (getf all
:size
))
3885 (mode (getf all
:mode
))
3886 (gid-change (getf all
:gid-change
))
3887 (inode (getf all
:inode
))
3888 (device-num (getf all
:device-num
))
3891 (getf all
:mode
) " "
3892 (number-to-string (getf all
:links
)) " "
3895 (if human-size
(anything-ff-human-size (getf all
:size
))
3896 (int-to-string (getf all
:size
))) " "
3897 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
))))
3900 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file
)
3901 "Return filename FNAME maybe prefixed with [?] or [@].
3902 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
3903 existing filename or valid symlink and there is no need to test it.
3904 NEW-FILE when non--nil mean FNAME is a non existing file and
3905 return FNAME prefixed with [?]."
3906 (let* ((prefix-new (propertize
3908 (propertize "[?]" 'face
'anything-ff-prefix
)))
3909 (prefix-url (propertize
3911 (propertize "[@]" 'face
'anything-ff-prefix
))))
3912 (cond ((or file-or-symlinkp
(file-exists-p fname
)) fname
)
3913 ((string-match ffap-url-regexp fname
)
3914 (concat prefix-url
" " fname
))
3915 ((or new-file
(not (file-exists-p fname
)))
3916 (concat prefix-new
" " fname
)))))
3918 (defun anything-c-find-files-transformer (files sources
)
3919 "Transformer for `anything-c-source-find-files'.
3920 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
3922 (if (and (string-match tramp-file-name-regexp anything-pattern
)
3923 anything-ff-tramp-not-fancy
)
3924 (if anything-ff-transformer-show-only-basename
3925 (loop for i in files collect
3926 (if (string-match "[.]\\{1,2\\}$" i
)
3927 i
(cons (anything-c-basename i
) i
)))
3929 (anything-ff-highlight-files files sources
)))
3931 (defun anything-ff-highlight-files (files sources
)
3932 "Candidate transformer for `anything-c-source-find-files' without icons."
3933 (loop for i in files
3934 for disp
= (if (and anything-ff-transformer-show-only-basename
3935 (not (string-match "[.]\\{1,2\\}$" i
))
3936 (not (string-match ffap-url-regexp i
)))
3937 (anything-c-basename i
) i
)
3939 (cond ((and (stringp (car (file-attributes i
)))
3940 (not (anything-ff-valid-symlink-p i
))
3941 (not (string-match "^\.#" (anything-c-basename i
))))
3942 (cons (anything-ff-prefix-filename
3943 (propertize disp
'face
'anything-ff-invalid-symlink
) t
)
3945 ((stringp (car (file-attributes i
)))
3946 (cons (anything-ff-prefix-filename
3947 (propertize disp
'face
'anything-ff-symlink
) t
)
3949 ((eq t
(car (file-attributes i
)))
3950 (cons (anything-ff-prefix-filename
3951 (propertize disp
'face
'anything-ff-directory
) t
)
3953 ((file-executable-p i
)
3954 (cons (anything-ff-prefix-filename
3955 (propertize disp
'face
'anything-ff-executable
) t
)
3958 (cons (anything-ff-prefix-filename
3959 (propertize disp
'face
'anything-ff-file
) t
)
3962 (cons (anything-ff-prefix-filename
3963 (propertize disp
'face
'anything-ff-file
) nil
'new-file
)
3966 (defun anything-find-files-action-transformer (actions candidate
)
3967 "Action transformer for `anything-c-source-find-files'."
3968 (cond ((with-anything-current-buffer
3969 (eq major-mode
'message-mode
))
3970 (append (subseq actions
0 4)
3971 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files
))
3972 (subseq actions
4)))
3973 ((string-match (image-file-name-regexp) candidate
)
3974 (append (subseq actions
0 4)
3975 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right
)
3976 ("Rotate image left `M-l'" . anything-ff-rotate-image-left
))
3977 (subseq actions
4)))
3978 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
3979 (car it
) candidate
))
3980 (append (subseq actions
0 4)
3981 '(("Byte compile lisp file(s) `M-B, C-u to load'"
3982 . anything-find-files-byte-compile
)
3983 ("Load File(s) `M-L'" . anything-find-files-load-files
))
3984 (subseq actions
4)))
3985 ((and (string-match "\.html?$" candidate
)
3986 (file-exists-p candidate
))
3987 (append (subseq actions
0 4)
3988 '(("Browse url file" . browse-url-of-file
))
3989 (subseq actions
5)))
3990 ((or (string= (file-name-extension candidate
) "pdf")
3991 (string= (file-name-extension candidate
) "PDF"))
3992 (append (subseq actions
0 4)
3993 '(("Pdfgrep File(s)" . anything-ff-pdfgrep
))
3994 (subseq actions
5)))
3997 (defun anything-ff-gnus-attach-files (candidate)
3998 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
3999 (let ((flist (anything-marked-candidates)))
4000 (gnus-dired-attach flist
)))
4002 (defun anything-ff-rotate-current-image-1 (file &optional num-arg
)
4003 "Rotate current image at NUM-ARG degrees.
4004 This is a destructive operation on FILE made by external tool mogrify."
4005 (declare (special image-dired-display-image-buffer
))
4006 (setq file
(file-truename file
)) ; For symlinked images.
4007 ;; When FILE is not an image-file, do nothing.
4008 (when (string-match (image-file-name-regexp) file
)
4009 (if (executable-find "mogrify")
4011 (shell-command (format "mogrify -rotate %s %s"
4013 (shell-quote-argument file
)))
4014 (when (buffer-live-p image-dired-display-image-buffer
)
4015 (kill-buffer image-dired-display-image-buffer
))
4016 (image-dired-display-image file
)
4018 (display-buffer (get-buffer image-dired-display-image-buffer
)))
4019 (error "mogrify not found"))))
4021 (defun anything-ff-rotate-image-left (candidate)
4022 "Rotate image file CANDIDATE left.
4023 This affect directly file CANDIDATE."
4024 (anything-ff-rotate-current-image-1 candidate -
90))
4026 (defun anything-ff-rotate-image-right (candidate)
4027 "Rotate image file CANDIDATE right.
4028 This affect directly file CANDIDATE."
4029 (anything-ff-rotate-current-image-1 candidate
))
4031 (defun anything-ff-rotate-left-persistent ()
4032 "Rotate image left without quitting anything."
4034 (anything-execute-persistent-action 'image-action1
))
4036 (defun anything-ff-rotate-right-persistent ()
4037 "Rotate image right without quitting anything."
4039 (anything-execute-persistent-action 'image-action2
))
4041 (defun anything-ff-exif-data (candidate)
4042 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4043 (if (and anything-ff-exif-data-program
4044 (executable-find anything-ff-exif-data-program
))
4045 (shell-command-to-string (format "%s %s %s"
4046 anything-ff-exif-data-program
4047 anything-ff-exif-data-program-args
4049 (format "No program %s found to extract exif"
4050 anything-ff-exif-data-program
)))
4052 (defun anything-find-files-persistent-action (candidate)
4053 "Open subtree CANDIDATE without quitting anything.
4054 If CANDIDATE is not a directory expand CANDIDATE filename.
4055 If CANDIDATE is alone, open file CANDIDATE filename.
4057 First hit on C-z expand CANDIDATE second hit open file.
4058 If a prefix arg is given or `anything-follow-mode' is on open file."
4059 (let ((follow (buffer-local-value
4060 'anything-follow-mode
4061 (get-buffer-create anything-buffer
)))
4062 (new-pattern (anything-get-selection))
4063 (num-lines-buf (with-current-buffer anything-buffer
4064 (count-lines (point-min) (point-max)))))
4065 (flet ((insert-in-minibuffer (fname)
4066 (with-selected-window (minibuffer-window)
4068 (delete-minibuffer-contents)
4069 (set-text-properties 0 (length fname
) nil fname
)
4071 (cond ((and (string= (anything-ff-set-pattern anything-pattern
)
4072 "Invalid tramp file name")
4073 (string-match tramp-file-name-regexp candidate
))
4074 ;; First hit insert hostname and
4075 ;; second hit insert ":" and expand.
4076 (if (string= candidate anything-pattern
)
4077 (insert-in-minibuffer (concat candidate
":"))
4078 (insert-in-minibuffer candidate
)))
4079 (;; A symlink directory, expand it's truename.
4080 (and (file-directory-p candidate
) (file-symlink-p candidate
))
4081 (insert-in-minibuffer (file-name-as-directory
4083 (expand-file-name candidate
)))))
4084 ;; A directory, open it.
4085 ((file-directory-p candidate
)
4086 (when (string= (anything-c-basename candidate
) "..")
4087 (setq anything-ff-last-expanded anything-ff-default-directory
))
4088 (insert-in-minibuffer (file-name-as-directory
4089 (expand-file-name candidate
))))
4090 ;; A symlink file, expand to it's true name. (first hit)
4091 ((and (file-symlink-p candidate
) (not current-prefix-arg
) (not follow
))
4092 (insert-in-minibuffer (file-truename candidate
)))
4093 ;; A regular file, expand it, (first hit)
4094 ((and (>= num-lines-buf
3) (not current-prefix-arg
) (not follow
))
4095 (insert-in-minibuffer new-pattern
))
4096 ;; An image file and it is the second hit on C-z,
4097 ;; show the file in `image-dired'.
4098 ((string-match (image-file-name-regexp) candidate
)
4099 (when (buffer-live-p image-dired-display-image-buffer
)
4100 (kill-buffer image-dired-display-image-buffer
))
4101 (image-dired-display-image candidate
)
4103 (anything-c-switch-to-buffer image-dired-display-image-buffer
)
4104 (with-current-buffer image-dired-display-image-buffer
4105 (let ((exif-data (anything-ff-exif-data candidate
)))
4106 (image-dired-update-property 'help-echo exif-data
))))
4107 ;; Allow browsing archive on avfs fs.
4108 ;; Assume volume is already mounted with mountavfs.
4109 ((and anything-ff-avfs-directory
4111 (regexp-quote (expand-file-name anything-ff-avfs-directory
))
4112 (file-name-directory candidate
))
4113 (anything-ff-file-compressed-p candidate
))
4114 (insert-in-minibuffer (concat candidate
"#")))
4115 ;; On second hit we open file.
4116 ;; On Third hit we kill it's buffer maybe.
4118 (anything-ff-kill-or-find-buffer-fname candidate
))))))
4120 (defun anything-ff-file-compressed-p (candidate)
4121 "Whether CANDIDATE is a compressed file or not."
4122 (member (file-name-extension candidate
)
4123 anything-ff-file-compressed-list
))
4125 (defun anything-c-insert-file-name-completion-at-point (candidate)
4126 "Insert file name completion at point."
4127 (with-anything-current-buffer
4128 (if buffer-read-only
4129 (error "Error: Buffer `%s' is read-only" (buffer-name))
4130 (let* ((end (point))
4131 (guess (substring-no-properties (thing-at-point 'filename
)))
4132 (beg (- (point) (length guess
)))
4133 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess
)
4134 (string-match-p "^[^\~]" guess
))))
4135 (set-text-properties 0 (length candidate
) nil candidate
)
4136 (if (and guess
(not (string= guess
""))
4137 (string-match-p "^~\\|/.*" guess
))
4139 (delete-region beg end
)
4140 (insert (if full-path-p
4141 (expand-file-name candidate
)
4142 (abbreviate-file-name candidate
))))
4143 (error "Aborting completion: No valid file name at point"))))))
4145 (defun* anything-find-files-history
(&key
(comp-read t
))
4146 "The `anything-find-files' history.
4147 Show the first `anything-ff-history-max-length' elements of
4148 `anything-ff-history' in an `anything-comp-read'."
4149 (let ((history (when anything-ff-history
4150 (anything-fast-remove-dups anything-ff-history
4153 (setq anything-ff-history
4154 (if (>= (length history
) anything-ff-history-max-length
)
4155 (subseq history
0 anything-ff-history-max-length
)
4159 "Switch to Directory: "
4161 :name
"Anything Find Files History"
4163 anything-ff-history
))))
4165 (defun anything-find-files-1 (fname &optional preselect
)
4166 "Find FNAME with `anything' completion.
4167 Like `find-file' but with `anything' support.
4168 Use it for non--interactive calls of `anything-find-files'."
4169 (when (get-buffer anything-action-buffer
)
4170 (kill-buffer anything-action-buffer
))
4171 (let ((anything-mp-highlight-delay nil
)
4172 ;; Be sure we don't erase the precedent minibuffer if some.
4173 (anything-ff-auto-update-initial-value
4174 (not (minibuffer-window-active-p (minibuffer-window))))
4175 anything-samewindow
)
4176 (anything :sources
'anything-c-source-find-files
4178 :preselect preselect
4179 :keymap anything-find-files-map
4180 :prompt
"Find Files or Url: "
4181 :buffer
"*Anything Find Files*")))
4184 (defun anything-find-files-initial-input (&optional input
)
4185 "Return INPUT if present, otherwise try to guess it."
4186 (or (and input
(expand-file-name input
))
4187 (anything-find-files-input
4189 (thing-at-point 'filename
))))
4191 (defun anything-find-files-input (fap tap
)
4192 "Default input of `anything-find-files'."
4193 (let* ((def-dir (anything-c-current-directory))
4194 (lib (anything-find-library-at-point))
4195 (url (anything-ff-find-url-at-point))
4196 (file-p (and fap
(not (string= fap
""))
4198 tap
(not (string= tap
""))
4200 (file-name-directory (expand-file-name tap def-dir
))))))
4201 (cond (lib) ; e.g we are inside a require sexp.
4202 (url) ; String at point is an hyperlink.
4203 (file-p (expand-file-name tap def-dir
))
4204 (t (and (not (string= fap
"")) fap
)))))
4206 (defun anything-c-current-directory ()
4207 "Return current-directory name at point.
4208 Useful in dired buffers when there is inserted subdirs."
4209 (if (eq major-mode
'dired-mode
)
4210 (dired-current-directory)
4213 (defun anything-ff-find-url-at-point ()
4214 "Try to find link to an url in text-property at point."
4215 (let* ((he (get-text-property (point) 'help-echo
))
4216 (ov (overlays-at (point)))
4217 (ov-he (and ov
(overlay-get
4218 (car (overlays-at (point))) 'help-echo
)))
4219 (w3m-l (get-text-property (point) 'w3m-href-anchor
))
4220 (nt-prop (get-text-property (point) 'nt-link
)))
4222 (when (and (stringp he
) (string-match "^LINK: " he
))
4223 (setq he
(replace-match "" t t he
)))
4224 (loop for i in
(list he ov-he w3m-l nt-prop
)
4225 thereis
(and (stringp i
) (string-match ffap-url-regexp i
) i
))))
4227 (defun anything-find-library-at-point ()
4228 "Try to find library path at point.
4229 Find inside `require' and `declare-function' sexp."
4230 (require 'find-func
)
4231 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
4232 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
4233 (sexp (and beg-sexp end-sexp
4234 (buffer-substring-no-properties
4235 (1+ beg-sexp
) (1- end-sexp
)))))
4237 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
4239 (replace-regexp-in-string
4241 ;; If require use third arg, ignore it,
4242 ;; always use library path found in `load-path'.
4243 (second (split-string (match-string 0 sexp
))))))
4244 ((and sexp
(string-match-p "^declare-function" sexp
))
4246 (replace-regexp-in-string
4248 (third (split-string sexp
)))))
4251 ;;; Anything completion for `write-file'.==> C-x C-w
4252 (defvar anything-c-source-write-file
4253 `((name .
"Write File")
4254 (header-name .
(lambda (name)
4255 (concat name anything-c-find-files-doc-header
)))
4256 ;; It is needed for filenames with capital letters
4258 (candidates . anything-find-files-get-candidates
)
4259 (filtered-candidate-transformer anything-c-find-files-transformer
)
4260 (persistent-action . anything-find-files-persistent-action
)
4261 (persistent-help .
"Expand Candidate")
4264 (("Write File" .
(lambda (candidate)
4265 (write-file candidate
'confirm
)))))))
4267 ;;; Anything completion for `insert-file'.==> C-x i
4268 (defvar anything-c-source-insert-file
4269 `((name .
"Insert File")
4270 (header-name .
(lambda (name)
4271 (concat name anything-c-find-files-doc-header
)))
4272 ;; It is needed for filenames with capital letters
4274 (candidates . anything-find-files-get-candidates
)
4275 (filtered-candidate-transformer anything-c-find-files-transformer
)
4276 (persistent-action . anything-find-files-persistent-action
)
4277 (persistent-help .
"Expand Candidate")
4280 (("Insert File" .
(lambda (candidate)
4281 (when (y-or-n-p (format "Really insert %s in %s "
4282 candidate anything-current-buffer
))
4283 (insert-file-contents candidate
))))))))
4285 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4286 (defvar anything-c-source-copy-files
4287 `((name .
"Copy Files")
4288 (header-name .
(lambda (name)
4289 (concat name anything-c-find-files-doc-header
)))
4290 ;; It is needed for filenames with capital letters
4292 (candidates . anything-find-files-get-candidates
)
4293 (filtered-candidate-transformer anything-c-find-files-transformer
)
4294 (persistent-action . anything-find-files-persistent-action
)
4295 (persistent-help .
"Expand Candidate")
4299 .
(lambda (candidate)
4300 (anything-dired-action candidate
:action
'copy
)))
4302 .
(lambda (candidate)
4303 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
4306 (defvar anything-c-source-rename-files
4307 `((name .
"Rename Files")
4308 (header-name .
(lambda (name)
4309 (concat name anything-c-find-files-doc-header
)))
4310 ;; It is needed for filenames with capital letters
4312 (candidates . anything-find-files-get-candidates
)
4313 (filtered-candidate-transformer anything-c-find-files-transformer
)
4314 (persistent-action . anything-find-files-persistent-action
)
4315 (persistent-help .
"Expand Candidate")
4319 .
(lambda (candidate)
4320 (anything-dired-action candidate
:action
'rename
)))
4321 ("Rename and Follow"
4322 .
(lambda (candidate)
4323 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
4325 (defvar anything-c-source-symlink-files
4326 `((name .
"Symlink Files")
4327 (header-name .
(lambda (name)
4328 (concat name anything-c-find-files-doc-header
)))
4329 ;; It is needed for filenames with capital letters
4331 (candidates . anything-find-files-get-candidates
)
4332 (filtered-candidate-transformer anything-c-find-files-transformer
)
4333 (persistent-action . anything-find-files-persistent-action
)
4334 (persistent-help .
"Expand Candidate")
4338 .
(lambda (candidate)
4339 (anything-dired-action candidate
:action
'symlink
)))
4341 .
(lambda (candidate)
4342 (anything-dired-action candidate
:action
'relsymlink
)))))))
4345 (defvar anything-c-source-hardlink-files
4346 `((name .
"Hardlink Files")
4347 (header-name .
(lambda (name)
4348 (concat name anything-c-find-files-doc-header
)))
4349 ;; It is needed for filenames with capital letters
4351 (candidates . anything-find-files-get-candidates
)
4352 (filtered-candidate-transformer anything-c-find-files-transformer
)
4353 (persistent-action . anything-find-files-persistent-action
)
4354 (persistent-help .
"Expand Candidate")
4358 .
(lambda (candidate)
4359 (anything-dired-action candidate
:action
'hardlink
)))))))
4361 (defun* anything-dired-action
(candidate &key action follow
(files (dired-get-marked-files)))
4362 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4363 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4364 (when (get-buffer dired-log-buffer
) (kill-buffer dired-log-buffer
))
4365 (let ((fn (case action
4366 ('copy
'dired-copy-file
)
4367 ('rename
'dired-rename-file
)
4368 ('symlink
'make-symbolic-link
)
4369 ('relsymlink
'dired-make-relative-symlink
)
4370 ('hardlink
'dired-hardlink
)))
4371 (marker (case action
4372 ((copy rename
) dired-keep-marker-copy
)
4373 ('symlink dired-keep-marker-symlink
)
4374 ('relsymlink dired-keep-marker-relsymlink
)
4375 ('hardlink dired-keep-marker-hardlink
)))
4376 (dirflag (and (= (length files
) 1)
4377 (file-directory-p (car files
))
4378 (not (file-directory-p candidate
)))))
4380 fn
(symbol-name action
) files
4381 ;; CANDIDATE is the destination.
4382 (if (file-directory-p candidate
)
4383 ;; When CANDIDATE is a directory, build file-name in this directory.
4384 ;; Else we use CANDIDATE.
4386 (expand-file-name (file-name-nondirectory from
) candidate
))
4387 #'(lambda (from) candidate
))
4389 (when (and follow
(not (get-buffer dired-log-buffer
)))
4390 (let ((target (directory-file-name candidate
)))
4393 (setq anything-ff-cand-to-mark
4394 (anything-get-dest-fnames-from-list files candidate dirflag
))
4395 (if (and dirflag
(eq action
'rename
))
4396 (anything-find-files-1 (file-name-directory target
)
4397 (if anything-ff-transformer-show-only-basename
4398 (anything-c-basename target
) target
))
4399 (anything-find-files-1 (expand-file-name candidate
))))
4400 (setq anything-ff-cand-to-mark nil
))))))
4403 (defun anything-c-basename (fname)
4404 "Resolve basename of file or directory named FNAME."
4405 (file-name-nondirectory (directory-file-name fname
)))
4407 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag
)
4408 "Transform filenames of FLIST to abs of DEST-CAND.
4409 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4411 ;; At this point files have been renamed/copied at destination.
4412 ;; That's mean DEST-CAND exists.
4414 with dest
= (expand-file-name dest-cand
)
4416 for basename-src
= (anything-c-basename src
)
4417 for fname
= (cond (rename-dir-flag (directory-file-name dest
))
4418 ((file-directory-p dest
)
4419 (concat (file-name-as-directory dest
) basename-src
))
4421 when
(file-exists-p fname
)
4422 collect fname into tmp-list
4423 finally return
(sort tmp-list
'string
<)))
4425 (defun anything-ff-maybe-mark-candidates ()
4426 "Mark all candidates of list `anything-ff-cand-to-mark'."
4427 (when (and (string= (assoc-default 'name
(anything-get-current-source))
4428 (assoc-default 'name anything-c-source-find-files
))
4429 anything-ff-cand-to-mark
)
4430 (with-anything-window
4431 (while anything-ff-cand-to-mark
4432 (if (string= (car anything-ff-cand-to-mark
) (anything-get-selection))
4434 (anything-make-visible-mark)
4435 (anything-next-line)
4436 (setq anything-ff-cand-to-mark
(cdr anything-ff-cand-to-mark
)))
4437 (anything-next-line)))
4438 (unless (anything-this-visible-mark)
4439 (anything-prev-visible-mark)))))
4441 (add-hook 'anything-after-update-hook
#'anything-ff-maybe-mark-candidates
)
4443 (defun* anything-dired-do-action-on-file
(&key action
)
4444 (let* ((files (dired-get-marked-files))
4445 (len (length files
))
4446 (fname (if (> len
1)
4447 (format "* %d Files" len
)
4449 (source (case action
4450 ('copy
'anything-c-source-copy-files
)
4451 ('rename
'anything-c-source-rename-files
)
4452 ('symlink
'anything-c-source-symlink-files
)
4453 ('hardlink
'anything-c-source-hardlink-files
)))
4454 (prompt-fm (case action
4455 ('copy
"Copy %s to: ")
4456 ('rename
"Rename %s to: ")
4457 ('symlink
"Symlink %s to: ")
4458 ('hardlink
"Hardlink %s to: ")))
4459 (buffer (case action
4460 ('copy
"*Anything Copy Files*")
4461 ('rename
"*Anything Rename Files*")
4462 ('symlink
"*Anything Symlink Files*")
4463 ('hardlink
"*Anything Hardlink Files*")))
4464 (anything-mp-highlight-delay nil
))
4465 (anything :sources source
4466 :input
(or (dired-dwim-target-directory)
4467 (expand-file-name (anything-c-current-directory)))
4468 :preselect
(dired-get-filename)
4469 :prompt
(format prompt-fm fname
)
4470 :keymap anything-c-read-file-map
4474 (define-minor-mode anything-dired-mode
()
4475 "Enable anything completion in Dired functions.
4476 Bindings affected are C, R, S, H.
4477 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4478 :group
'anything-config
4480 (if anything-dired-mode
4482 (substitute-key-definition
4483 'dired-do-copy
'anything-dired-copy-file dired-mode-map
)
4484 (substitute-key-definition
4485 'dired-do-rename
'anything-dired-rename-file dired-mode-map
)
4486 (substitute-key-definition
4487 'dired-do-symlink
'anything-dired-symlink-file dired-mode-map
)
4488 (substitute-key-definition
4489 'dired-do-hardlink
'anything-dired-hardlink-file dired-mode-map
))
4490 (substitute-key-definition
4491 'anything-dired-copy-file
'dired-do-copy dired-mode-map
)
4492 (substitute-key-definition
4493 'anything-dired-rename-file
'dired-do-rename dired-mode-map
)
4494 (substitute-key-definition
4495 'anything-dired-symlink-file
'dired-do-symlink dired-mode-map
)
4496 (substitute-key-definition
4497 'anything-dired-hardlink-file
'dired-do-hardlink dired-mode-map
)))
4499 (defalias 'anything-dired-bindings
'anything-dired-mode
)
4501 (defun* anything-c-read-file-name
(prompt
4503 (name "Read File Name")
4504 (initial-input (expand-file-name default-directory
))
4505 (buffer "*Anything Completions*")
4509 (marked-candidates nil
)
4511 (persistent-action 'anything-find-files-persistent-action
)
4512 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4513 "Anything `read-file-name' emulation.
4514 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4515 (when (get-buffer anything-action-buffer
)
4516 (kill-buffer anything-action-buffer
))
4517 (let ((anything-mp-highlight-delay nil
)
4518 ;; Be sure we don't erase the underlying minibuffer if some.
4519 (anything-ff-auto-update-initial-value
4520 (not (minibuffer-window-active-p (minibuffer-window))))
4521 anything-same-window
)
4522 (flet ((action-fn (candidate)
4523 (if marked-candidates
4524 (anything-marked-candidates)
4525 (identity candidate
))))
4528 `(((name .
,(format "%s History" name
))
4529 (header-name .
(lambda (name)
4530 (concat name anything-c-find-files-doc-header
)))
4532 (mode-line . anything-read-file-name-mode-line-string
)
4533 (candidates .
(lambda ()
4534 (anything-comp-read-get-candidates history nil nil alistp
)))
4535 (persistent-action .
,persistent-action
)
4536 (persistent-help .
,persistent-help
)
4537 (action .
,'action-fn
))
4539 (header-name .
(lambda (name)
4540 (concat name anything-c-find-files-doc-header
)))
4541 ;; It is needed for filenames with capital letters
4543 (mode-line . anything-read-file-name-mode-line-string
)
4544 (candidates .
(lambda ()
4545 (let ((seq (anything-find-files-get-candidates)))
4547 (loop for fname in seq
4548 when
(funcall test fname
) collect fname
)
4550 (filtered-candidate-transformer anything-c-find-files-transformer
)
4551 (persistent-action .
,persistent-action
)
4552 (candidate-number-limit .
9999)
4553 (toggle-auto-update . anything-ff-toggle-auto-update
)
4554 (persistent-help .
,persistent-help
)
4556 (action .
,'action-fn
)))
4557 :input initial-input
4559 :keymap anything-c-read-file-map
4562 :preselect preselect
)
4567 (defvar anything-c-file-cache-initialized-p nil
)
4569 (defvar anything-c-file-cache-files nil
)
4571 (defvar anything-c-source-file-cache
4572 '((name .
"File Cache")
4575 (require 'filecache nil t
)
4576 (unless anything-c-file-cache-initialized-p
4577 (setq anything-c-file-cache-files
4578 (loop for item in file-cache-alist append
4579 (destructuring-bind (base &rest dirs
) item
4580 (loop for dir in dirs collect
4581 (concat dir base
)))))
4582 (defadvice file-cache-add-file
(after file-cache-list activate
)
4583 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
4584 (setq anything-c-file-cache-initialized-p t
))))
4585 (candidates . anything-c-file-cache-files
)
4586 (match anything-c-match-on-basename
)
4588 ;; (anything 'anything-c-source-file-cache)
4594 ;; NOTE for WINDOZE users:
4595 ;; You have to install Everything with his command line interface here:
4596 ;; http://www.voidtools.com/download.php
4598 (defun anything-locate-1 (&optional localdb init
)
4599 "Generic function to run Locate.
4600 if LOCALDB is non--nil search and use a local locate db file.
4601 INIT is a string to use as initial input in prompt.
4602 See `anything-locate-with-db' and `anything-locate'."
4603 (anything-locate-with-db
4605 (anything-c-read-file-name
4607 :marked-candidates t
4608 :preselect anything-locate-db-file-regexp
4610 (if anything-locate-db-file-regexp
4611 ;; Select only locate db files and directories
4612 ;; to allow navigation.
4614 anything-locate-db-file-regexp x
)
4615 (file-directory-p x
))
4618 ;; (anything-locate-1 t)
4620 (defun anything-locate-with-db (&optional db initial-input
)
4622 If DB is not given or nil use locate without -d option.
4623 Argument DB can be given as a string or list of db files.
4624 Argument INITIAL-INPUT is a string to use as initial-input.
4625 See also `anything-locate'."
4626 (when (and db
(stringp db
)) (setq db
(list db
)))
4627 (let ((anything-c-locate-command
4629 (replace-regexp-in-string
4631 (format "locate -d %s"
4632 (mapconcat 'identity
4633 ;; Remove eventually
4634 ;; marked directories by error.
4636 unless
(file-directory-p i
)
4638 anything-c-locate-command
)
4639 anything-c-locate-command
)))
4640 (anything :sources
'anything-c-source-locate
4641 :buffer
"*anything locate*"
4642 :input initial-input
4643 :keymap anything-generic-files-map
)))
4644 ;; (anything-locate-with-db "~/locate.db")
4646 (defun anything-c-locate-init ()
4647 "Initialize async locate process for `anything-c-source-locate'."
4648 (setq mode-line-format
4649 '(" " mode-line-buffer-identification
" "
4650 (line-number-mode "%l") " "
4651 (:eval
(propertize "(Locate Process Running) "
4652 'face
'((:foreground
"red"))))))
4654 (start-process-shell-command "locate-process" nil
4655 (format anything-c-locate-command
4657 (set-process-sentinel (get-process "locate-process")
4658 #'(lambda (process event
)
4659 (when (string= event
"finished\n")
4660 (with-anything-window
4661 (force-mode-line-update nil
)
4662 (anything-update-move-first-line)))))))
4664 (defvar anything-c-source-locate
4666 (candidates . anything-c-locate-init
)
4668 (properties-action . anything-ff-properties
)
4669 (requires-pattern .
3)
4670 (candidate-number-limit .
9999)
4671 (mode-line . anything-generic-file-mode-line-string
)
4673 "Find files matching the current input pattern with locate.")
4674 ;; (anything 'anything-c-source-locate)
4676 (defun anything-c-locate-read-file-name (prompt &optional init
)
4677 "Search a file with locate and return it's filename.
4678 Use argument PROMPT and INIT for `anything' arguments
4682 (candidates . anything-c-locate-init
)
4684 (properties-action . anything-ff-properties
)
4685 (requires-pattern .
3)
4686 (candidate-number-limit .
9999)
4687 (mode-line . anything-generic-file-mode-line-string
)
4691 :buffer
"*anything locate rfn*"))
4695 ;;; Anything Incremental Grep.
4698 ;; Allow to grep incrementally with anything interface.
4699 ;; It allow also to Grep files recursively without using 'find' shell command.
4700 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4701 (defvar anything-c-grep-default-command
4702 "grep -d skip %e -niH -e %p %f"
4703 "Default grep format command for `anything-do-grep-1'.
4705 '%e' format spec is for --exclude or --include grep options.
4706 '%p' format spec is for pattern.
4707 '%f' format spec is for filenames.")
4709 (defvar anything-c-grep-default-recurse-command
4710 "grep -d recurse %e -niH -e %p %f"
4711 "Default recursive grep format command for `anything-do-grep-1'.
4712 See `anything-c-grep-default-command' for format specs.")
4714 (defvar anything-c-default-zgrep-command
"zgrep -niH -e %p %f")
4716 (defvar anything-c-rzgrep-cache
(make-hash-table :test
'equal
))
4718 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
4720 (defvar anything-c-grep-debug-command-line nil
4721 "Turn on anything grep command-line debugging when non--nil.")
4723 (defvar anything-c-zgrep-recurse-flag nil
)
4725 (defvar anything-c-grep-history nil
)
4727 (defvar anything-c-grep-max-length-history
100
4728 "*Max number of elements to save in `anything-c-grep-history'.")
4730 (defun anything-c-grep-prepare-candidates (candidates)
4731 "Prepare filenames and directories CANDIDATES for grep command line."
4732 ;; If one or more candidate is a directory, search in all files
4733 ;; of this candidate (e.g /home/user/directory/*).
4734 ;; If r option is enabled search also in subdidrectories.
4735 ;; We need here to expand wildcards to support crap windows filenames
4736 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4737 (if anything-c-zgrep-recurse-flag
4738 (mapconcat 'shell-quote-argument candidates
" ")
4739 (loop for i in candidates append
4740 (cond ( ;; Candidate is a directory and we use recursion.
4741 (and (file-directory-p i
)
4742 (anything-c-grep-recurse-p))
4743 (list (expand-file-name i
)))
4744 ;; Candidate is a directory, search in all files.
4745 ((file-directory-p i
)
4746 (file-expand-wildcards
4747 (concat (file-name-as-directory (expand-file-name i
)) "*") t
))
4748 ;; Candidate is a file or wildcard and we use recursion, use the
4749 ;; current directory instead of candidate.
4750 ((and (or (file-exists-p i
) (string-match "\*" i
))
4751 (anything-c-grep-recurse-p))
4752 (list (expand-file-name
4753 (directory-file-name ; Needed for windoze.
4754 (file-name-directory (directory-file-name i
))))))
4755 ;; Candidate use wildcard.
4756 ((string-match "^\*" (anything-c-basename i
))
4757 (file-expand-wildcards i t
))
4758 ;; Else should be one or more file.
4759 (t (list i
))) into all-files
4761 (mapconcat 'shell-quote-argument all-files
" "))))
4763 (defun anything-c-grep-recurse-p ()
4764 "Check if `anything-do-grep-1' have switched to recursive."
4765 (let ((args (replace-regexp-in-string
4766 "grep" "" anything-c-grep-default-command
)))
4767 (string-match-p "r\\|recurse" args
)))
4769 (defun anything-c-grep-init (only-files &optional include zgrep
)
4770 "Start an asynchronous grep process in ONLY-FILES list."
4771 (let* ((fnargs (anything-c-grep-prepare-candidates
4772 (if (file-remote-p anything-ff-default-directory
)
4773 (mapcar #'(lambda (x)
4774 (file-remote-p x
'localname
))
4777 (ignored-files (mapconcat
4779 (concat "--exclude=" (shell-quote-argument x
)))
4780 grep-find-ignored-files
" "))
4781 (ignored-dirs (mapconcat
4782 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4784 (concat "--exclude-dir=" (shell-quote-argument x
)))
4785 grep-find-ignored-directories
" "))
4786 (exclude (if (anything-c-grep-recurse-p)
4787 (concat (or include ignored-files
) " " ignored-dirs
)
4789 (cmd-line (format-spec
4790 anything-c-grep-default-command
4792 (list (unless zgrep
(cons ?e exclude
))
4793 (cons ?p
(shell-quote-argument anything-pattern
))
4794 (cons ?f fnargs
))))))
4795 (when anything-c-grep-debug-command-line
4796 (with-current-buffer (get-buffer-create "*any grep debug*")
4797 (goto-char (point-max))
4798 (insert (concat ">>> " cmd-line
"\n\n"))))
4799 (setq mode-line-format
4800 '(" " mode-line-buffer-identification
" "
4801 (line-number-mode "%l") " "
4802 (:eval
(when (get-process "grep-process")
4803 (propertize "[Grep Process Running] "
4804 'face
'anything-grep-running
)))))
4805 (force-mode-line-update nil
)
4807 (let ((default-directory anything-ff-default-directory
))
4808 (start-file-process-shell-command "grep-process" nil cmd-line
))
4810 (set-process-sentinel
4811 (get-process "grep-process")
4812 #'(lambda (process event
)
4813 (when (string= event
"finished\n")
4814 (with-anything-window
4815 (anything-update-move-first-line)
4816 (setq mode-line-format
4817 '(" " mode-line-buffer-identification
" "
4818 (line-number-mode "%l") " "
4820 (format "[Grep Process Finished - (%s results)] "
4821 (let ((nlines (1- (count-lines
4824 (if (> nlines
0) nlines
0)))
4825 'face
'anything-grep-finish
))))
4826 (force-mode-line-update nil
))))))))
4828 (defun anything-c-grep-action (candidate &optional where mark
)
4829 "Define a default action for `anything-do-grep' on CANDIDATE.
4830 WHERE can be one of other-window, elscreen, other-frame."
4831 (let* ((split (anything-c-grep-split-line candidate
))
4832 (lineno (string-to-number (nth 1 split
)))
4833 (loc-fname (car split
))
4834 (tramp-method (file-remote-p anything-ff-default-directory
'method
))
4835 (tramp-host (file-remote-p anything-ff-default-directory
'host
))
4836 (tramp-prefix (concat "/" tramp-method
":" tramp-host
":"))
4837 (fname (if tramp-host
4838 (concat tramp-prefix loc-fname
) loc-fname
)))
4840 (other-window (find-file-other-window fname
))
4841 (elscreen (anything-elscreen-find-file fname
))
4842 (other-frame (find-file-other-frame fname
))
4843 (t (find-file fname
)))
4844 (anything-goto-line lineno
)
4846 (set-marker (mark-marker) (point))
4847 (push-mark (point) 'nomsg
))
4849 (unless (or anything-in-persistent-action
4850 (string= anything-pattern
""))
4851 (setq anything-c-grep-history
4852 (cons anything-pattern
4853 (delete anything-pattern anything-c-grep-history
)))
4854 (when (> (length anything-c-grep-history
)
4855 anything-c-grep-max-length-history
)
4856 (setq anything-c-grep-history
4857 (delete (car (last anything-c-grep-history
))
4858 anything-c-grep-history
))))))
4860 (defun anything-c-grep-other-window (candidate)
4861 "Jump to result in other window from anything grep."
4862 (anything-c-grep-action candidate
'other-window
))
4864 (defun anything-c-grep-other-frame (candidate)
4865 "Jump to result in other frame from anything grep."
4866 (anything-c-grep-action candidate
'other-frame
))
4868 (defun anything-c-grep-jump-elscreen (candidate)
4869 "Jump to result in elscreen from anything grep."
4870 (anything-c-grep-action candidate
'elscreen
))
4872 (defun anything-c-grep-save-results (candidate)
4873 "Save anything grep result in a `grep-mode' buffer."
4874 (let ((buf "*grep*")
4876 (when (get-buffer buf
)
4877 (setq new-buf
(read-string "GrepBufferName: " buf
))
4878 (loop for b in
(anything-c-buffer-list)
4879 when
(and (string= new-buf b
)
4881 (format "Buffer `%s' already exists overwrite? "
4883 do
(setq new-buf
(read-string "GrepBufferName: " "*grep ")))
4885 (with-current-buffer (get-buffer-create buf
)
4886 (let ((inhibit-read-only t
))
4888 (insert "-*- mode: grep -*-\n\n"
4889 (format "Grep Results for `%s':\n\n" anything-pattern
))
4891 (insert (with-current-buffer anything-buffer
4893 (buffer-substring (point) (point-max))))
4895 (message "Anything Grep Results saved in `%s' buffer" buf
)))
4897 (defun anything-c-grep-persistent-action (candidate)
4898 "Persistent action for `anything-do-grep'.
4899 With a prefix arg record CANDIDATE in `mark-ring'."
4900 (if current-prefix-arg
4901 (anything-c-grep-action candidate nil
'mark
)
4902 (anything-c-grep-action candidate
))
4903 (anything-match-line-color-current-line))
4905 (defun anything-c-grep-guess-extensions (files)
4906 "Try to guess file extensions in FILES list when using grep recurse.
4907 These extensions will be added to command line with --include arg of grep."
4909 with glob-list
= nil
4910 with lst
= (if (file-directory-p (car files
))
4913 directory-files-no-dot-files-regexp
)
4916 for ext
= (file-name-extension i t
)
4917 for glob
= (and ext
(not (string= ext
""))
4919 unless
(or (not glob
)
4920 (member glob glob-list
)
4921 (member glob grep-find-ignored-files
))
4922 collect glob into glob-list
4923 finally return glob-list
))
4925 (defun anything-do-grep-1 (only &optional recurse zgrep
)
4926 "Launch grep with a list of ONLY files.
4927 When RECURSE is given use -r option of grep and prompt user
4928 to set the --include args of grep.
4929 You can give more than one arg separated by space.
4930 e.g *.el *.py *.tex.
4931 If it's empty --exclude `grep-find-ignored-files' is used instead."
4932 (let* ((anything-compile-source-functions
4933 ;; rule out anything-match-plugin because the input is one regexp.
4934 (delq 'anything-compile-source--match-plugin
4935 (copy-sequence anything-compile-source-functions
)))
4936 (exts (anything-c-grep-guess-extensions only
))
4937 (globs (and (not zgrep
) (mapconcat 'identity exts
" ")))
4938 (include-files (and recurse
(not zgrep
)
4939 (read-string "OnlyExt(*.[ext]): "
4941 ;; Set `minibuffer-history' AFTER includes-files
4942 ;; to avoid storing wild-cards here.
4943 (minibuffer-history anything-c-grep-history
)
4944 (anything-c-grep-default-command (cond ((and recurse zgrep
) anything-c-default-zgrep-command
)
4945 (recurse anything-c-grep-default-recurse-command
)
4946 (zgrep anything-c-default-zgrep-command
)
4947 (t anything-c-grep-default-command
)))
4948 ;; Disable match-plugin and use here own highlighting.
4949 (anything-mp-highlight-delay nil
))
4952 (and (not (string= include-files
""))
4953 (mapconcat #'(lambda (x)
4954 (concat "--include=" (shell-quote-argument x
)))
4955 (split-string include-files
) " "))))
4956 ;; When called as action from an other source e.g *-find-files
4957 ;; we have to kill action buffer.
4958 (when (get-buffer anything-action-buffer
)
4959 (kill-buffer anything-action-buffer
))
4960 ;; `anything-find-files' haven't already started,
4961 ;; give a default value to `anything-ff-default-directory'.
4962 (setq anything-ff-default-directory
(or anything-ff-default-directory
4966 `(((name .
"Grep (C-c ? Help)")
4969 (funcall anything-c-grep-default-function only include-files zgrep
)))
4970 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
4971 (candidate-number-limit .
9999)
4972 (mode-line . anything-grep-mode-line-string
)
4973 (jump-persistent . anything-c-grep-persistent-action
)
4976 `(("Find File" . anything-c-grep-action
)
4977 ("Find file other frame" . anything-c-grep-other-frame
)
4978 ,(and (locate-library "elscreen")
4979 '("Find file in Elscreen"
4980 . anything-c-grep-jump-elscreen
))
4981 ("Save results in grep buffer" . anything-c-grep-save-results
)
4982 ("Find file other window" . anything-c-grep-other-window
))))
4983 (persistent-action . anything-c-grep-persistent-action
)
4984 (persistent-help .
"Jump to line (`C-u' Record in mark ring)")
4985 (requires-pattern .
3)
4987 :keymap anything-c-grep-map
4988 :buffer
"*anything grep*")))
4990 (defun anything-ff-zgrep-1 (flist recursive
)
4992 (let* ((def-dir (or anything-ff-default-directory
4995 (or (gethash def-dir anything-c-rzgrep-cache
)
4998 (anything-c-walk-directory
5002 :match
".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5003 anything-c-rzgrep-cache
))
5005 (when recursive
(setq anything-c-zgrep-recurse-flag t
))
5006 (anything-do-grep-1 only recursive
'zgrep
))
5007 (setq anything-c-zgrep-recurse-flag nil
)))
5009 (defun anything-c-grep-split-line (line)
5010 "Split a grep output line."
5011 (let (beg fname lineno str
)
5012 ;; Don't print until grep line is valid.
5013 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line
)
5016 (goto-char (point-min))
5019 (re-search-forward ":" nil t
)
5020 (setq fname
(buffer-substring-no-properties beg
(1- (point))))
5022 (re-search-forward ":" nil t
)
5023 (setq lineno
(buffer-substring-no-properties beg
(1- (point))))
5024 (setq str
(buffer-substring-no-properties (point) (point-at-eol))))
5025 (list fname lineno str
))))
5027 (defun anything-c-grep-cand-transformer (candidates sources
)
5028 "Filtered candidate transformer function for `anything-do-grep'."
5029 (loop for i in candidates
5030 for split
= (and i
(anything-c-grep-split-line i
))
5031 for fname
= (car split
)
5032 for lineno
= (nth 1 split
)
5033 for str
= (nth 2 split
)
5034 when
(and fname lineno str
)
5036 (cons (concat (propertize (file-name-nondirectory fname
)
5037 'face
'anything-grep-file
5038 'help-echo fname
) ":"
5039 (propertize lineno
'face
'anything-grep-lineno
) ":"
5040 (anything-c-grep-highlight-match str
))
5043 (defun anything-c-grep-highlight-match (str)
5044 "Highlight in string STR all occurences matching `anything-pattern'."
5048 (goto-char (point-min))
5049 (while (and (re-search-forward anything-pattern nil t
)
5050 (> (- (match-end 0) (match-beginning 0)) 0))
5051 (add-text-properties
5052 (match-beginning 0) (match-end 0)
5053 '(face anything-grep-match
)))
5057 ;; Go to next or precedent file (common to etags and grep).
5058 (defun anything-c-goto-next-or-prec-file (n)
5059 "Go to next or precedent candidate file in anything grep/etags buffers.
5060 If N is positive go forward otherwise go backward."
5061 (with-anything-window
5062 (let* ((current-line-list (split-string
5065 (point-at-eol)) ":"))
5066 (current-fname (nth 0 current-line-list
))
5067 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
)))
5069 (while (not (funcall fn-b-o-f
))
5070 (forward-line n
) ; Go forward or backward depending of n value.
5071 (unless (search-forward current-fname
(point-at-eol) t
)
5072 (anything-mark-current-line)
5073 (throw 'break nil
))))
5074 (cond ((and (eq n
1) (eobp))
5075 (re-search-backward ".")
5077 (anything-mark-current-line))
5078 ((and (< n
1) (bobp))
5080 (anything-mark-current-line))))))
5083 (defun anything-c-goto-precedent-file ()
5084 "Go to precedent file in anything grep/etags buffers."
5086 (anything-c-goto-next-or-prec-file -
1))
5089 (defun anything-c-goto-next-file ()
5090 "Go to precedent file in anything grep/etags buffers."
5092 (anything-c-goto-next-or-prec-file 1))
5095 (defun anything-c-grep-run-persistent-action ()
5096 "Run grep persistent action from `anything-do-grep-1'."
5098 (anything-execute-persistent-action 'jump-persistent
))
5101 (defun anything-c-grep-run-default-action ()
5102 "Run grep default action from `anything-do-grep-1'."
5104 (anything-c-quit-and-execute-action 'anything-c-grep-action
))
5107 (defun anything-c-grep-run-other-window-action ()
5108 "Run grep goto other window action from `anything-do-grep-1'."
5110 (anything-c-quit-and-execute-action 'anything-c-grep-other-window
))
5113 (defun anything-c-grep-run-save-buffer ()
5114 "Run grep save results action from `anything-do-grep-1'."
5116 (anything-c-quit-and-execute-action 'anything-c-grep-save-results
))
5119 (defun anything-c-grep-buffers-1 (candidate &optional zgrep
)
5120 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5121 If one of selected buffers is not a file--buffer,
5122 it is ignored and grep will run on all others file--buffers.
5123 If only one candidate is selected and it is not a file--buffer,
5124 switch to this buffer and run `anything-occur'.
5125 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5126 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
5129 (anything-marked-candidates)))
5130 (win-conf (current-window-configuration))
5131 ;; Non--fname buffers are ignored.
5132 (bufs (loop for buf in cands
5133 for fname
= (buffer-file-name (get-buffer buf
))
5135 collect
(expand-file-name fname
))))
5138 (anything-do-grep-1 bufs nil
'zgrep
)
5139 (anything-do-grep-1 bufs
))
5140 ;; bufs is empty, thats mean we have only CANDIDATE
5141 ;; and it is not a buffer-filename, fallback to occur.
5142 (anything-c-switch-to-buffer candidate
)
5143 (when (get-buffer anything-action-buffer
)
5144 (kill-buffer anything-action-buffer
))
5146 (when (eq anything-exit-status
1)
5147 (set-window-configuration win-conf
)))))
5149 (defun anything-c-grep-buffers (candidate)
5150 "Action to grep buffers."
5151 (anything-c-grep-buffers-1 candidate
))
5153 (defun anything-c-zgrep-buffers (candidate)
5154 "Action to zgrep buffers."
5155 (anything-c-grep-buffers-1 candidate
'zgrep
))
5158 ;;; Anything interface for pdfgrep
5159 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5160 ;; and a pdf-reader (e.g xpdf) are needed.
5162 (defvar anything-c-pdfgrep-default-command
"pdfgrep --color never -niH %s %s")
5163 (defvar anything-c-pdfgrep-default-function
'anything-c-pdfgrep-init
)
5164 (defvar anything-c-pdfgrep-debug-command-line nil
)
5166 (defun anything-c-pdfgrep-init (only-files)
5167 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5168 (let* ((fnargs (anything-c-grep-prepare-candidates
5169 (if (file-remote-p anything-ff-default-directory
)
5170 (mapcar #'(lambda (x)
5171 (file-remote-p x
'localname
))
5174 (cmd-line (format anything-c-pdfgrep-default-command
5177 (when anything-c-pdfgrep-debug-command-line
5178 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5179 (goto-char (point-max))
5180 (insert (concat ">>> " cmd-line
"\n\n"))))
5181 (setq mode-line-format
5182 '(" " mode-line-buffer-identification
" "
5183 (line-number-mode "%l") " "
5184 (:eval
(propertize "(Pdfgrep Process Running) "
5185 'face
'((:foreground
"red"))))))
5187 (let ((default-directory anything-ff-default-directory
))
5188 (start-file-process-shell-command "pdfgrep-process" nil cmd-line
))
5190 (set-process-sentinel
5191 (get-process "pdfgrep-process")
5192 #'(lambda (process event
)
5193 (when (string= event
"finished\n")
5194 (with-anything-window
5195 (anything-update-move-first-line))
5196 (force-mode-line-update nil
)))))))
5199 (defun anything-do-pdfgrep-1 (only)
5200 "Launch pdfgrep with a list of ONLY files."
5201 (unless (executable-find "pdfgrep")
5202 (error "Error: No such program `pdfgrep'."))
5203 (let* ((anything-compile-source-functions
5204 ;; rule out anything-match-plugin because the input is one regexp.
5205 (delq 'anything-compile-source--match-plugin
5206 (copy-sequence anything-compile-source-functions
)))
5207 ;; Disable match-plugin and use here own highlighting.
5208 (anything-mp-highlight-delay nil
))
5209 ;; When called as action from an other source e.g *-find-files
5210 ;; we have to kill action buffer.
5211 (when (get-buffer anything-action-buffer
)
5212 (kill-buffer anything-action-buffer
))
5213 ;; If `anything-find-files' haven't already started,
5214 ;; give a default value to `anything-ff-default-directory'.
5215 (setq anything-ff-default-directory
(or anything-ff-default-directory
5219 `(((name .
"PdfGrep")
5222 (funcall anything-c-pdfgrep-default-function only
)))
5223 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
5224 (candidate-number-limit .
9999)
5225 (mode-line . anything-pdfgrep-mode-line-string
)
5226 (action . anything-c-pdfgrep-action
)
5227 (persistent-help .
"Jump to PDF Page")
5228 (requires-pattern .
3)
5230 :keymap anything-c-pdfgrep-map
5231 :buffer
"*anything grep*")))
5234 (defun anything-c-pdfgrep-action (candidate)
5235 (let* ((split (anything-c-grep-split-line candidate
))
5236 (pageno (nth 1 split
))
5237 (fname (car split
)))
5238 (start-file-process-shell-command
5240 (format-spec anything-c-pdfgrep-default-read-command
5241 (list (cons ?f fname
) (cons ?p pageno
))))))
5243 (defun anything-do-pdfgrep ()
5245 (let ((only (anything-c-read-file-name
5246 "Search in file(s): "
5247 :marked-candidates t
5248 :test
#'(lambda (file)
5249 (or (string= (file-name-extension file
) "pdf")
5250 (string= (file-name-extension file
) "PDF")
5251 (file-directory-p file
)))
5252 :preselect
(or (dired-get-filename nil t
)
5253 (buffer-file-name (current-buffer)))))
5254 (anything-c-grep-default-function 'anything-c-pdfgrep-init
))
5255 (anything-do-pdfgrep-1 only
)))
5258 ;; Yank text at point.
5262 (defvar anything-yank-point nil
)
5265 (defun anything-yank-text-at-point ()
5266 "Yank text at point in minibuffer."
5269 (flet ((insert-in-minibuffer (word)
5270 (with-selected-window (minibuffer-window)
5271 (let ((str anything-pattern
))
5272 (delete-minibuffer-contents)
5273 (set-text-properties 0 (length word
) nil word
)
5274 (insert (concat str word
))))))
5275 (with-anything-current-buffer
5276 ;; Start to initial point if C-w have never been hit.
5277 (unless anything-yank-point
(setq anything-yank-point
(point)))
5278 (and anything-yank-point
(goto-char anything-yank-point
))
5280 (setq input
(buffer-substring-no-properties anything-yank-point
(point)))
5281 (setq anything-yank-point
(point))) ; End of last forward-word
5282 (insert-in-minibuffer input
))))
5284 (defun anything-reset-yank-point ()
5285 (setq anything-yank-point nil
))
5287 (add-hook 'anything-after-persistent-action-hook
'anything-reset-yank-point
)
5288 (add-hook 'anything-cleanup-hook
'anything-reset-yank-point
)
5294 (defvar anything-c-source-recentf
5295 '((name .
"Recentf")
5298 (or recentf-mode
(recentf-mode 1))))
5299 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5300 (candidates . recentf-list
)
5301 (match anything-c-match-on-basename
)
5303 "See (info \"(emacs)File Conveniences\").
5304 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5305 ;; (anything 'anything-c-source-recentf)
5308 (eval-when-compile (require 'ffap
))
5309 (defvar anything-c-source-ffap-guesser
5310 '((name .
"File at point")
5311 (init .
(lambda () (require 'ffap
)))
5312 (candidates .
(lambda ()
5314 (with-anything-current-buffer
5318 ;; (anything 'anything-c-source-ffap-guesser)
5320 ;;; ffap with line number
5321 (defun anything-c-ffap-file-line-at-point ()
5322 "Get (FILENAME . LINENO) at point."
5323 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5326 (when (and (search-forward it nil t
)
5327 (looking-at ":\\([0-9]+\\)"))
5328 (cons it
(string-to-number (match-string 1)))))))
5330 (defvar anything-c-ffap-line-location nil
5331 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5332 It is cleared after jumping line.")
5334 (defun anything-c-ffap-line-candidates ()
5335 (with-anything-current-buffer
5336 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
5337 (when anything-c-ffap-line-location
5338 (destructuring-bind (file . line
) anything-c-ffap-line-location
5339 (list (cons (format "%s (line %d)" file line
) file
)))))
5341 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5342 (defun anything-c-ffap-line-goto-line ()
5343 (when (car anything-c-ffap-line-location
)
5346 (with-selected-window
5348 (get-file-buffer (car anything-c-ffap-line-location
)))
5349 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
5350 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
5351 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
5353 (defvar anything-c-source-ffap-line
5354 '((name .
"File/Lineno at point")
5355 (init .
(lambda () (require 'ffap
)))
5356 (candidates . anything-c-ffap-line-candidates
)
5358 ;; (anything 'anything-c-source-ffap-line)
5360 ;;; list of files gleaned from every dired buffer
5361 (defun anything-c-files-in-all-dired-candidates ()
5365 (cond ((listp dir
) ;filelist
5367 ((equal "" (file-name-nondirectory dir
)) ;dir
5368 (directory-files dir t
))
5370 (file-expand-wildcards dir t
))))
5372 (mapcar (lambda (buf)
5374 (when (eq major-mode
'dired-mode
)
5375 (if (consp dired-directory
)
5376 (cdr dired-directory
) ;filelist
5377 dired-directory
))) ;dir or wildcard
5379 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5381 (defvar anything-c-source-files-in-all-dired
5382 '((name .
"Files in all dired buffer.")
5383 (candidates . anything-c-files-in-all-dired-candidates
)
5385 ;; (anything 'anything-c-source-files-in-all-dired)
5387 (defvar anything-c-source-filelist
5388 '((name .
"FileList")
5389 (grep-candidates . anything-c-filelist-file-name
)
5390 (candidate-number-limit .
200)
5391 (requires-pattern .
4)
5393 "Source to find files instantly.
5394 See `anything-c-filelist-file-name' docstring for usage.")
5399 (defvar anything-c-info-pages nil
5400 "All info pages on system.
5401 Will be calculated the first time you invoke anything with this
5404 (defun anything-c-info-pages-init ()
5405 "Collect candidates for initial Info node Top."
5406 (if anything-c-info-pages
5407 anything-c-info-pages
5408 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5412 (Info-find-node "dir" "top")
5413 (goto-char (point-min))
5414 (while (re-search-forward info-topic-regexp nil t
)
5415 (push (match-string-no-properties 1) topics
))
5417 (setq anything-c-info-pages topics
))))
5419 (defvar anything-c-source-info-pages
5420 `((name .
"Info Pages")
5421 (init . anything-c-info-pages-init
)
5422 (candidates . anything-c-info-pages
)
5423 (action .
(("Show with Info" .
(lambda (node-str)
5424 (info (replace-regexp-in-string
5425 "^[^:]+: " "" node-str
))))))
5426 (requires-pattern .
2)))
5427 ;; (anything 'anything-c-source-info-pages)
5430 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5431 (defun anything-c-describe-attributes (anything-attribute)
5432 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5433 Same as `anything-describe-anything-attribute' but with anything completion."
5434 (interactive (list (intern
5436 "Describe anything attribute: "
5437 (mapcar 'symbol-name anything-additional-attributes
)
5440 #'(lambda (candidate)
5441 (with-output-to-temp-buffer "*Help*"
5442 (princ (get (intern candidate
) 'anything-attrdoc
))))))))
5443 (with-output-to-temp-buffer "*Help*"
5444 (princ (get anything-attribute
'anything-attrdoc
))))
5447 ;;; Use info-index plug-in.
5450 ;; Note that `name' attribute is not needed since
5451 ;; `anything-c-insert-summary' have been removed.
5453 (defvar anything-c-source-info-elisp
5454 '((name .
"Info index: elisp")
5455 (info-index .
"elisp")))
5456 ;; (anything 'anything-c-source-info-elisp)
5459 (defvar anything-c-source-info-cl
5460 '((name .
"Info index: cl")
5461 (info-index .
"cl")))
5462 ;; (anything 'anything-c-source-info-cl)
5465 (defvar anything-c-source-info-org
5466 '((name .
"Info index: org")
5467 (info-index .
"org")))
5468 ;; (anything 'anything-c-source-info-org)
5471 (defvar anything-c-source-info-gnus
5472 '((name .
"Info index: Gnus")
5473 (info-index .
"gnus")))
5475 ;; Info Index ratpoison
5476 (defvar anything-c-source-info-ratpoison
5477 '((name .
"Info index: ratpoison")
5478 (info-index .
"ratpoison")))
5479 ;; (anything 'anything-c-source-info-ratpoison)
5482 (defvar anything-c-source-info-zsh
5483 '((name .
"Info index: zsh")
5484 (info-index .
"zsh")))
5485 ;; (anything 'anything-c-source-info-zsh)
5488 (defvar anything-c-source-info-bash
5489 '((name .
"Info index: bash")
5490 (info-index .
"bash")))
5491 ;; (anything 'anything-c-source-info-bash)
5493 ;; Info Index coreutils
5494 (defvar anything-c-source-info-coreutils
5495 '((name .
"Info index: coreutils")
5496 (info-index .
"coreutils")))
5497 ;; (anything 'anything-c-source-info-coreutils)
5499 ;; Info Index fileutils
5500 (defvar anything-c-source-info-fileutils
5501 '((name .
"Info index: fileutils")
5502 (info-index .
"fileutils")))
5503 ;; (anything 'anything-c-source-info-fileutils)
5506 (defvar anything-c-source-info-find
5507 '((name .
"Info index: find")
5508 (info-index .
"find")))
5509 ;; (anything 'anything-c-source-info-find)
5511 ;; Info Index sh-utils
5512 (defvar anything-c-source-info-sh-utils
5513 '((name .
"Info index: sh-utils")
5514 (info-index .
"sh-utils")))
5515 ;; (anything 'anything-c-source-info-sh-utils)
5517 ;; Info Index textutils
5518 (defvar anything-c-source-info-textutils
5519 '((name .
"Info index: textutils")
5520 (info-index .
"textutils")))
5521 ;; (anything 'anything-c-source-info-textutils)
5524 (defvar anything-c-source-info-libc
5525 '((name .
"Info index: libc")
5526 (info-index .
"libc")))
5527 ;; (anything 'anything-c-source-info-libc)
5530 (defvar anything-c-source-info-make
5531 '((name .
"Info index: make")
5532 (info-index .
"make")))
5533 ;; (anything 'anything-c-source-info-make)
5535 ;; Info Index automake
5536 (defvar anything-c-source-info-automake
5537 '((name .
"Info index: automake")
5538 (info-index .
"automake")))
5539 ;; (anything 'anything-c-source-info-automake)
5541 ;; Info Index autoconf
5542 (defvar anything-c-source-info-autoconf
5543 '((name .
"Info index: autoconf")
5544 (info-index .
"autoconf")))
5545 ;; (anything 'anything-c-source-info-autoconf)
5547 ;; Info Index emacs-lisp-intro
5548 (defvar anything-c-source-info-emacs-lisp-intro
5549 '((name .
"Info index: emacs-lisp-intro")
5550 (info-index .
"emacs-lisp-intro")))
5551 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5554 (defvar anything-c-source-info-emacs
5555 '((name .
"Info index: emacs")
5556 (info-index .
"emacs")))
5557 ;; (anything 'anything-c-source-info-emacs)
5560 (defvar anything-c-source-info-elib
5561 '((name .
"Info index: elib")
5562 (info-index .
"elib")))
5563 ;; (anything 'anything-c-source-info-elib)
5566 (defvar anything-c-source-info-eieio
5567 '((name .
"Info index: eieio")
5568 (info-index .
"eieio")))
5569 ;; (anything 'anything-c-source-info-eieio)
5571 ;; Info Index gauche-refe
5572 (defvar anything-c-source-info-gauche-refe
5573 '((name .
"Info index: gauche")
5574 (info-index .
"gauche-refe")))
5575 ;; (anything 'anything-c-source-info-gauche-refe)
5578 (defvar anything-c-source-info-guile
5579 '((name .
"Info index: guile")
5580 (info-index .
"guile")))
5581 ;; (anything 'anything-c-source-info-guile)
5583 ;; Info Index guile-tut
5584 (defvar anything-c-source-info-guile-tut
5585 '((name .
"Info index: guile-tut")
5586 (info-index .
"guile-tut")))
5587 ;; (anything 'anything-c-source-info-guile-tut)
5590 (defvar anything-c-source-info-goops
5591 '((name .
"Info index: goops")
5592 (info-index .
"goops")))
5593 ;; (anything 'anything-c-source-info-goops)
5595 ;; Info Index screen
5596 (defvar anything-c-source-info-screen
5597 '((name .
"Info index: screen")
5598 (info-index .
"screen")
5599 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5600 ;; (anything 'anything-c-source-info-screen)
5603 (defvar anything-c-source-info-latex
5604 '((name .
"Info index: latex")
5605 (info-index .
"latex")))
5606 ;; (anything 'anything-c-source-info-latex)
5609 (defvar anything-c-source-info-gawk
5610 '((name .
"Info index: gawk")
5611 (info-index .
"gawk")))
5612 ;; (anything 'anything-c-source-info-gawk)
5615 (defvar anything-c-source-info-sed
5616 '((name .
"Info index: sed")
5617 (info-index .
"sed")))
5618 ;; (anything 'anything-c-source-info-sed)
5621 (defvar anything-c-source-info-m4
5622 '((name .
"Info index: m4")
5623 (info-index .
"m4")))
5624 ;; (anything 'anything-c-source-info-m4)
5627 (defvar anything-c-source-info-wget
5628 '((name .
"Info index: wget")
5629 (info-index .
"wget")))
5630 ;; (anything 'anything-c-source-info-wget)
5632 ;; Info Index binutils
5633 (defvar anything-c-source-info-binutils
5634 '((name .
"Info index: binutils")
5635 (info-index .
"binutils")))
5636 ;; (anything 'anything-c-source-info-binutils)
5639 (defvar anything-c-source-info-as
5640 '((name .
"Info index: as")
5641 (info-index .
"as")))
5642 ;; (anything 'anything-c-source-info-as)
5645 (defvar anything-c-source-info-bfd
5646 '((name .
"Info index: bfd")
5647 (info-index .
"bfd")))
5648 ;; (anything 'anything-c-source-info-bfd)
5651 (defvar anything-c-source-info-gprof
5652 '((name .
"Info index: gprof")
5653 (info-index .
"gprof")))
5654 ;; (anything 'anything-c-source-info-gprof)
5657 (defvar anything-c-source-info-ld
5658 '((name .
"Info index: ld")
5659 (info-index .
"ld")))
5660 ;; (anything 'anything-c-source-info-ld)
5663 (defvar anything-c-source-info-diff
5664 '((name .
"Info index: diff")
5665 (info-index .
"diff")))
5666 ;; (anything 'anything-c-source-info-diff)
5669 (defvar anything-c-source-info-flex
5670 '((name .
"Info index: flex")
5671 (info-index .
"flex")))
5672 ;; (anything 'anything-c-source-info-flex)
5675 (defvar anything-c-source-info-grep
5676 '((name .
"Info index: grep")
5677 (info-index .
"grep")))
5678 ;; (anything 'anything-c-source-info-grep)
5681 (defvar anything-c-source-info-gzip
5682 '((name .
"Info index: gzip")
5683 (info-index .
"gzip")))
5684 ;; (anything 'anything-c-source-info-gzip)
5686 ;; Info Index libtool
5687 (defvar anything-c-source-info-libtool
5688 '((name .
"Info index: libtool")
5689 (info-index .
"libtool")))
5690 ;; (anything 'anything-c-source-info-libtool)
5692 ;; Info Index texinfo
5693 (defvar anything-c-source-info-texinfo
5694 '((name .
"Info index: texinfo")
5695 (info-index .
"texinfo")))
5696 ;; (anything 'anything-c-source-info-texinfo)
5699 (defvar anything-c-source-info-info
5700 '((name .
"Info index: info")
5701 (info-index .
"info")))
5702 ;; (anything 'anything-c-source-info-info)
5705 (defvar anything-c-source-info-gdb
5706 '((name .
"Info index: gdb")
5707 (info-index .
"gdb")))
5708 ;; (anything 'anything-c-source-info-gdb)
5711 (defvar anything-c-source-info-stabs
5712 '((name .
"Info index: stabs")
5713 (info-index .
"stabs")))
5714 ;; (anything 'anything-c-source-info-stabs)
5716 ;; Info Index cvsbook
5717 (defvar anything-c-source-info-cvsbook
5718 '((name .
"Info index: cvsbook")
5719 (info-index .
"cvsbook")))
5720 ;; (anything 'anything-c-source-info-cvsbook)
5723 (defvar anything-c-source-info-cvs
5724 '((name .
"Info index: cvs")
5725 (info-index .
"cvs")))
5726 ;; (anything 'anything-c-source-info-cvs)
5729 (defvar anything-c-source-info-bison
5730 '((name .
"Info index: bison")
5731 (info-index .
"bison")))
5732 ;; (anything 'anything-c-source-info-bison)
5734 ;; Info Index id-utils
5735 (defvar anything-c-source-info-id-utils
5736 '((name .
"Info index: id-utils")
5737 (info-index .
"id-utils")))
5738 ;; (anything 'anything-c-source-info-id-utils)
5740 ;; Info Index global
5741 (defvar anything-c-source-info-global
5742 '((name .
"Info index: global")
5743 (info-index .
"global")))
5744 ;; (anything 'anything-c-source-info-global)
5747 ;;; Man and woman UI
5750 (defvar anything-c-man-pages nil
5751 "All man pages on system.
5752 Will be calculated the first time you invoke anything with this
5755 (defun anything-c-man-default-action (candidate)
5756 "Default action for jumping to a woman or man page from anything."
5757 (let ((wfiles (woman-file-name-all-completions candidate
)))
5759 (if (> (length wfiles
) 1)
5762 "ManFile: " wfiles
:must-match t
))
5764 ;; If woman is unable to format correctly
5766 (error (kill-buffer) ; Kill woman buffer.
5767 (let ((Man-notify-method 'meek
))
5768 (Man-getpage-in-background candidate
))))))
5770 (defvar anything-c-source-man-pages
5771 `((name .
"Manual Pages")
5772 (candidates .
(lambda ()
5773 (if anything-c-man-pages
5774 anything-c-man-pages
5775 ;; XEmacs doesn't have a woman :)
5776 (setq anything-c-man-pages
5779 (woman-file-name "")
5780 (sort (mapcar 'car woman-topic-all-completions
)
5782 (action ("Show with Woman" . anything-c-man-default-action
))
5783 ;; Woman does not work OS X
5784 ;; http://xahlee.org/emacs/modernization_man_page.html
5785 (action-transformer .
(lambda (actions candidate
)
5786 (if (eq system-type
'darwin
)
5787 '(("Show with Man" . man
))
5789 (requires-pattern .
2)))
5790 ;; (anything 'anything-c-source-man-pages)
5794 ;;; Anything M-x - Enhanced M-x UI
5797 ;; Another replacement of `M-x' that act exactly like the
5798 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5799 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5800 ;; anything invocation.
5801 ;; Documentation of commands available without quitting,
5802 ;; Show keybindings of commands.
5804 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
5805 "Return alist of MODE-MAP."
5806 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
5807 for str-key
= (key-description key
)
5808 for ismenu
= (string-match "<menu-bar>" str-key
)
5809 unless ismenu collect
(cons str-key com
)))
5811 (defun anything-get-mode-map-from-mode (mode)
5812 "Guess the mode-map name according to MODE.
5813 Some modes don't use conventional mode-map name
5814 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5815 Return nil if no mode-map found."
5817 ;; Start with a conventional mode-map name.
5818 with mode-map
= (intern-soft (format "%s-map" mode
))
5819 with mode-string
= (symbol-name mode
)
5820 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
5821 while
(not mode-map
)
5822 for count downfrom
(length mode-name
)
5823 ;; Return when no result after parsing entire string.
5824 when
(eq count
0) return nil
5825 for sub-name
= (substring mode-name
0 count
)
5826 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
5827 finally return mode-map
))
5829 (defun anything-M-x-current-mode-map-alist ()
5830 "Return mode-map alist of current `major-mode'."
5831 (let ((map (anything-get-mode-map-from-mode major-mode
)))
5832 (when (and map
(boundp map
))
5833 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
5836 (defun anything-M-x-transformer (candidates sources
)
5837 "filtered-candidate-transformer to show bindings in emacs commands.
5838 Show global bindings and local bindings according to current `major-mode'."
5839 (with-anything-current-buffer
5841 with local-map
= (anything-M-x-current-mode-map-alist)
5842 for cand in candidates
5843 for local-key
= (car (rassq cand local-map
))
5844 for key
= (substitute-command-keys (format "\\[%s]" cand
))
5846 (cons (cond ((and (string-match "^M-x" key
) local-key
)
5850 'face
'anything-M-x-key-face
)))
5851 ((string-match "^M-x" key
) cand
)
5852 (t (format "%s (%s)"
5855 'face
'anything-M-x-key-face
))))
5858 (sort ls
#'(lambda (x y
) (string-lessp (car x
) (car y
)))))))
5861 ;;; Complex command history
5864 (defvar anything-c-source-complex-command-history
5865 '((name .
"Complex Command History")
5866 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
5868 ;; (anything 'anything-c-source-complex-command-history)
5870 ;;; M-x history (not related to `anything-M-x')
5873 (defvar anything-c-source-extended-command-history
5874 '((name .
"Emacs Commands History")
5875 (candidates . extended-command-history
)
5877 ;; (anything 'anything-c-source-extended-command-history)
5879 ;;; Emacs commands (Basic source for emacs commands)
5882 (defvar anything-c-source-emacs-commands
5883 '((name .
"Emacs Commands")
5884 (candidates .
(lambda ()
5886 (mapatoms (lambda (a)
5888 (push (symbol-name a
)
5890 (sort commands
'string-lessp
))))
5892 (requires-pattern .
2))
5893 "Source for completing and invoking Emacs commands.
5894 A command is a function with interactive spec that can
5895 be invoked with `M-x'.
5897 To get non-interactive functions listed, use
5898 `anything-c-source-emacs-functions'.")
5899 ;; (anything 'anything-c-source-emacs-commands)
5906 (defvar anything-c-source-emacs-functions
5907 '((name .
"Emacs Functions")
5908 (candidates .
(lambda ()
5910 (mapatoms (lambda (a)
5912 (push (symbol-name a
) commands
))))
5913 (sort commands
'string-lessp
))))
5915 (requires-pattern .
2))
5916 "Source for completing Emacs functions.")
5917 ;; (anything 'anything-c-source-emacs-functions)
5919 ;;; With abbrev expansion
5920 ;;; Similar to my exec-abbrev-cmd.el
5921 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5922 (defvar anything-c-function-abbrev-regexp nil
5923 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5924 Regexp built from the current `anything-pattern' interpreting it
5926 Only for internal use.")
5928 (defun anything-c-match-function-by-abbrev (candidate)
5929 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5931 Abbreviations are made by taking the first character from each
5932 word in the function's name, e.g. \"bb\" is an abbrev for
5933 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5934 (string-match anything-c-function-abbrev-regexp candidate
))
5936 (defvar anything-c-source-emacs-functions-with-abbrevs
5937 (append anything-c-source-emacs-functions
5938 '((match anything-c-match-function-by-abbrev
5939 anything-c-string-match
))
5942 (defadvice anything-update
5943 (before anything-c-update-function-abbrev-regexp activate
)
5944 (let ((char-list (append anything-pattern nil
))
5946 (dolist (c char-list
)
5947 (setq str
(concat str
(list c
) "[^-]*-")))
5948 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
5949 (setq anything-c-function-abbrev-regexp str
))))))))
5950 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5952 (defvar anything-c-source-advice
5953 '((name .
"Function Advice")
5954 (candidates . anything-c-advice-candidates
)
5955 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
5956 ;; (real-to-display . anything-c-advice-real-to-display)
5957 (persistent-action . anything-c-advice-persistent-action
)
5958 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
5959 ;; (anything 'anything-c-source-advice)
5960 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5963 (defun anything-c-advice-candidates ()
5965 (loop for
(fname) in ad-advised-functions
5966 for function
= (intern fname
)
5968 (loop for class in ad-advice-classes append
5969 (loop for advice in
(ad-get-advice-info-field function class
)
5970 for enabled
= (ad-advice-enabled advice
)
5974 (if enabled
"Enabled " "Disabled")
5975 (propertize fname
'face
'font-lock-function-name-face
)
5976 (ad-make-single-advice-docstring advice class nil
))
5977 (list function class advice
))))))
5979 (defun anything-c-advice-persistent-action (func-class-advice)
5980 (if current-prefix-arg
5981 (anything-c-advice-toggle func-class-advice
)
5982 (describe-function (car func-class-advice
))))
5984 (defun anything-c-advice-toggle (func-class-advice)
5985 (destructuring-bind (function class advice
) func-class-advice
5986 (cond ((ad-advice-enabled advice
)
5987 (ad-advice-set-enabled advice nil
)
5988 (message "Disabled"))
5990 (ad-advice-set-enabled advice t
)
5991 (message "Enabled")))
5992 (ad-activate function
)
5993 (and anything-in-persistent-action
5994 (anything-c-advice-update-current-display-string))))
5996 (defun anything-c-advice-update-current-display-string ()
5997 (anything-edit-current-selection
5998 (let ((newword (cond ((looking-at "Disabled") "Enabled")
5999 ((looking-at "Enabled") "Disabled")))
6002 (delete-region (point) (progn (forward-word 1) (point)))
6003 (insert newword
)))))
6010 (defvar anything-c-source-emacs-variables
6011 '((name .
"Emacs Variables")
6012 (candidates .
(lambda ()
6013 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
6015 (requires-pattern .
2))
6016 "Source for completing Emacs variables.")
6017 ;; (anything 'anything-c-source-emacs-variables)
6021 (defvar anything-c-source-lacarte
6022 '((name .
"Lacarte")
6023 (init .
(lambda () (require 'lacarte
)))
6024 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6025 (candidate-number-limit .
9999)
6026 (action . anything-c-call-interactively
))
6029 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6030 ;; (anything 'anything-c-source-lacarte)
6036 ;; Bind some faces for bookmarks.
6037 (defvar anything-c-bookmarks-face1
'anything-ff-directory
)
6038 (defvar anything-c-bookmarks-face2
'anything-ff-file
)
6039 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
6041 (eval-when-compile (require 'bookmark
))
6042 (defvar anything-c-source-bookmarks
6043 '((name .
"Bookmarks")
6045 (require 'bookmark
)))
6046 (candidates . bookmark-all-names
)
6048 "See (info \"(emacs)Bookmarks\").")
6049 ;; (anything 'anything-c-source-bookmarks)
6052 (defvar anything-c-source-bookmark-set
6053 '((name .
"Set Bookmark")
6055 (action . bookmark-set
))
6056 "See (info \"(emacs)Bookmarks\").")
6057 ;; (anything 'anything-c-source-bookmark-set)
6059 ;;; Visible Bookmarks
6060 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6063 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6064 (defvar anything-c-source-bm
6065 '((name .
"Visible Bookmarks")
6066 (init . anything-c-bm-init
)
6067 (candidates-in-buffer)
6071 http://www.nongnu.org/bm/")
6073 (defun anything-c-bm-init ()
6074 "Init function for `anything-c-source-bm'."
6075 (when (require 'bm nil t
)
6077 (let ((bookmarks (bm-lists))
6078 (buf (anything-candidate-buffer 'global
)))
6079 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
6080 '< :key
'overlay-start
))
6081 (let ((start (overlay-start bm
))
6082 (end (overlay-end bm
))
6083 (annotation (or (overlay-get bm
'annotation
) "")))
6084 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
6085 (let ((str (format "%5d: [%s]: %s\n"
6086 (line-number-at-pos start
)
6088 (buffer-substring start
(1- end
)))))
6089 (with-current-buffer buf
(insert str
))))))))))
6091 ;;; Special bookmarks
6092 (defvar anything-c-source-bookmarks-ssh
6093 '((name .
"Bookmarks-ssh")
6095 (require 'bookmark
)))
6096 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
6098 "See (info \"(emacs)Bookmarks\").")
6099 ;; (anything 'anything-c-source-bookmarks-ssh)
6101 (defvar anything-c-source-bookmarks-su
6102 '((name .
"Bookmarks-root")
6104 (require 'bookmark
)))
6105 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
6106 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
6109 "See (info \"(emacs)Bookmarks\").")
6110 ;; (anything 'anything-c-source-bookmarks-su)
6112 (defvar anything-c-source-bookmarks-local
6113 '((name .
"Bookmarks-Local")
6115 (require 'bookmark
)))
6116 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
6117 (filtered-candidate-transformer
6118 anything-c-adaptive-sort
6119 anything-c-highlight-bookmark
)
6121 "See (info \"(emacs)Bookmarks\").")
6122 ;; (anything 'anything-c-source-bookmarks-local)
6124 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
6125 (let* ((lis-all (bookmark-all-names))
6126 (lis-loc (cond (local (loop for i in lis-all
6127 unless
(string-match "^(ssh)\\|^(su)" i
)
6129 (su (loop for i in lis-all
6130 when
(string-match "^(su)" i
)
6132 (sudo (loop for i in lis-all
6133 when
(string-match "^(sudo)" i
)
6135 (ssh (loop for i in lis-all
6136 when
(string-match "^(ssh)" i
)
6138 (sort lis-loc
'string-lessp
)))
6140 (defun anything-c-bookmark-root-logged-p ()
6142 (dolist (i (mapcar #'buffer-name
(buffer-list)))
6143 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
6144 (throw 'break t
)))))
6146 (defun anything-c-highlight-bookmark-su (files source
)
6147 (if (anything-c-bookmark-root-logged-p)
6148 (anything-c-highlight-bookmark files source
)
6149 (anything-c-highlight-not-logged files source
)))
6151 (defun anything-c-highlight-not-logged (files source
)
6152 (loop for i in files
6153 collect
(propertize i
'face anything-c-bookmarks-face3
)))
6155 (defun anything-c-highlight-bookmark (bookmarks source
)
6156 "Used as `candidate-transformer' to colorize bookmarks.
6157 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6158 (loop for i in bookmarks
6159 for isfile
= (bookmark-get-filename i
)
6160 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
6161 (bmkext-get-buffer-name i
))
6162 for handlerp
= (and (fboundp 'bookmark-get-handler
)
6163 (bookmark-get-handler i
))
6164 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
6165 (bmkext-w3m-bookmark-p i
))
6166 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
6167 (bmkext-gnus-bookmark-p i
))
6168 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
6169 (bmkext-man-bookmark-p i
))
6170 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
6171 (bmkext-woman-bookmark-p i
))
6172 for handlerp
= (bookmark-get-handler i
)
6173 for isannotation
= (bookmark-get-annotation i
)
6174 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
6175 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
6176 ;; Add a * if bookmark have annotation
6177 if
(and isannotation
(not (string-equal isannotation
"")))
6178 do
(setq i
(concat "*" i
))
6179 collect
(cond (;; info buffers
6181 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
6184 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
6187 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
6190 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
6193 (propertize i
'face
'((:foreground
"Tomato"))))
6195 (and isfile
(file-directory-p isfile
))
6196 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
6199 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
6203 ;;; Sources to filter bookmark-extensions bookmarks.
6206 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6207 ;; If you want to enable google-maps in addressbook you will need
6208 ;; Julien Danjou google-maps-el package available here:
6209 ;; http://julien.danjou.info/google-maps-el.html
6211 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
6212 "Return a filtered `bookmark-alist' sorted alphabetically."
6214 with alist
= (if args
6215 (apply #'(lambda (x) (funcall fn x
)) args
)
6220 finally return
(sort sa
'string-lessp
)))
6225 (defvar anything-c-source-bmkext-addressbook
6226 '((name .
"Bookmark Addressbook")
6228 (require 'bookmark-extensions
)
6229 (bookmark-maybe-load-default-file)))
6230 (candidates . anything-c-bmkext-addressbook-setup-alist
)
6232 .
(lambda (candidate)
6233 (let ((bmk (anything-bookmark-get-bookmark-from-name
6235 (bookmark--jump-via bmk
'pop-to-buffer
))))
6236 (persistent-help .
"Show contact - Prefix with C-u to append")
6237 (filtered-candidate-transformer
6238 anything-c-adaptive-sort
6239 anything-c-highlight-bookmark
)
6240 (action .
(("Show Contact(s)"
6241 .
(lambda (candidate)
6242 (let* ((contacts (anything-marked-candidates))
6243 (current-prefix-arg (or anything-current-prefix-arg
6244 (> (length contacts
) 1))))
6246 (anything-bookmark-get-bookmark-from-name (car contacts
)))
6247 (anything-aif (cdr contacts
)
6248 (loop for bmk in it do
6250 (anything-bookmark-get-bookmark-from-name bmk
)))))))
6252 .
(lambda (candidate)
6253 (let* ((contacts (anything-marked-candidates))
6254 (bmk (anything-bookmark-get-bookmark-from-name
6256 (append (message-buffers)))
6258 (addressbook-set-mail-buffer1 bmk
'append
)
6259 (addressbook-set-mail-buffer1 bmk
))
6260 (setq contacts
(cdr contacts
))
6262 (loop for bmk in contacts do
6263 (addressbook-set-mail-buffer1 bmk
'append
))))))
6265 .
(lambda (candidate)
6266 (let ((bmk (anything-bookmark-get-bookmark-from-name
6268 (addressbook-bookmark-edit
6269 (assoc bmk bookmark-alist
)))))
6270 ("Insert Email at point"
6271 .
(lambda (candidate)
6272 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6274 (mlist (split-string
6276 'email
(assoc bmk bookmark-alist
))
6279 (if (> (length mlist
) 1)
6281 "Insert Mail Address: " mlist
:must-match t
)
6284 .
(lambda (candidate)
6285 (let ((bmk (anything-bookmark-get-bookmark-from-name
6287 (bookmark-show-annotation bmk
))))
6289 .
(lambda (candidate)
6290 (let ((bmk (anything-bookmark-get-bookmark-from-name
6292 (bookmark-edit-annotation bmk
))))
6294 .
(lambda (candidate)
6295 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6297 (full-bmk (assoc bmk bookmark-alist
)))
6298 (addressbook-google-map full-bmk
))))))))
6301 (defun anything-c-bmkext-addressbook-setup-alist ()
6302 "Specialized filter function for bookmarks w3m."
6303 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
6305 ;; W3m bookmarks from bookmark-extensions.
6306 (defvar anything-c-source-bookmark-w3m
6307 '((name .
"Bookmark W3m")
6309 (require 'bookmark-extensions
)
6310 (bookmark-maybe-load-default-file)))
6311 (candidates . anything-c-bookmark-w3m-setup-alist
)
6312 (filtered-candidate-transformer
6313 anything-c-adaptive-sort
6314 anything-c-highlight-bookmark
)
6316 ;; (anything 'anything-c-source-bookmark-w3m)
6318 (defun anything-c-bookmark-w3m-setup-alist ()
6319 "Specialized filter function for bookmarks w3m."
6320 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
6323 (defvar anything-c-source-bookmark-images
6324 '((name .
"Bookmark Images")
6326 (require 'bookmark-extensions
)
6327 (bookmark-maybe-load-default-file)))
6328 (candidates . anything-c-bookmark-images-setup-alist
)
6329 (filtered-candidate-transformer
6330 anything-c-adaptive-sort
6331 anything-c-highlight-bookmark
)
6333 ;; (anything 'anything-c-source-bookmark-images)
6335 (defun anything-c-bookmark-images-setup-alist ()
6336 "Specialized filter function for images bookmarks."
6337 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
6340 (defvar anything-c-source-bookmark-man
6341 '((name .
"Bookmark Woman&Man")
6343 (require 'bookmark-extensions
)
6344 (bookmark-maybe-load-default-file)))
6345 (candidates . anything-c-bookmark-man-setup-alist
)
6346 (filtered-candidate-transformer
6347 anything-c-adaptive-sort
6348 anything-c-highlight-bookmark
)
6350 ;; (anything 'anything-c-source-bookmark-man)
6352 (defun anything-c-bookmark-man-setup-alist ()
6353 "Specialized filter function for bookmarks w3m."
6354 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
6355 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
6358 (defvar anything-c-source-bookmark-gnus
6359 '((name .
"Bookmark Gnus")
6361 (require 'bookmark-extensions
)
6362 (bookmark-maybe-load-default-file)))
6363 (candidates . anything-c-bookmark-gnus-setup-alist
)
6364 (filtered-candidate-transformer
6365 anything-c-adaptive-sort
6366 anything-c-highlight-bookmark
)
6368 ;; (anything 'anything-c-source-bookmark-gnus)
6370 (defun anything-c-bookmark-gnus-setup-alist ()
6371 "Specialized filter function for bookmarks gnus."
6372 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
6375 (defvar anything-c-source-bookmark-info
6376 '((name .
"Bookmark Info")
6378 (require 'bookmark-extensions
)
6379 (bookmark-maybe-load-default-file)))
6380 (candidates . anything-c-bookmark-info-setup-alist
)
6381 (filtered-candidate-transformer
6382 anything-c-adaptive-sort
6383 anything-c-highlight-bookmark
)
6385 ;; (anything 'anything-c-source-bookmark-info)
6387 (defun anything-c-bookmark-info-setup-alist ()
6388 "Specialized filter function for bookmarks info."
6389 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
6391 ;; Local Files&directories
6392 (defvar anything-c-source-bookmark-files
&dirs
6393 '((name .
"Bookmark Files&Directories")
6395 (require 'bookmark-extensions
)
6396 (bookmark-maybe-load-default-file)))
6397 (candidates . anything-c-bookmark-local-files-setup-alist
)
6398 (filtered-candidate-transformer
6399 anything-c-adaptive-sort
6400 anything-c-highlight-bookmark
)
6402 ;; (anything 'anything-c-source-bookmark-files&dirs)
6404 (defun anything-c-bookmark-local-files-setup-alist ()
6405 "Specialized filter function for bookmarks locals files."
6406 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
6408 ;; Su Files&directories
6409 (defvar anything-c-source-bookmark-su-files
&dirs
6410 '((name .
"Bookmark Root-Files&Directories")
6412 (require 'bookmark-extensions
)
6413 (bookmark-maybe-load-default-file)))
6414 (candidates . anything-c-bookmark-su-files-setup-alist
)
6415 (filtered-candidate-transformer
6416 anything-c-adaptive-sort
6417 anything-c-highlight-bookmark-su
)
6419 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6421 (defun anything-c-bookmark-su-files-setup-alist ()
6422 "Specialized filter function for bookmarks su/sudo files."
6423 (declare (special bmkext-su-or-sudo-regexp
))
6425 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6427 for isfile
= (bookmark-get-filename i
)
6428 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
6430 (string-match tramp-file-name-regexp isfile
)))
6431 for issu
= (and istramp
6432 (string-match bmkext-su-or-sudo-regexp isfile
))
6436 ;; Ssh Files&directories
6437 (defvar anything-c-source-bookmark-ssh-files
&dirs
6438 '((name .
"Bookmark Ssh-Files&Directories")
6440 (require 'bookmark-extensions
)
6441 (bookmark-maybe-load-default-file)))
6442 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
6443 (filtered-candidate-transformer . anything-c-adaptive-sort
)
6445 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6447 (defun anything-c-bookmark-ssh-files-setup-alist ()
6448 "Specialized filter function for bookmarks ssh files."
6450 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6452 for isfile
= (bookmark-get-filename i
)
6453 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
6455 (string-match tramp-file-name-regexp isfile
)))
6456 for isssh
= (and istramp
6457 (string-match "/ssh:" isfile
))
6463 ;;; Firefox bookmarks
6466 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6467 ;; (only for firefox versions >=3)
6468 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6470 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6471 ;; You should have now:
6472 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6474 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6475 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
6477 (defun anything-get-firefox-user-init-dir ()
6478 "Guess the default Firefox user directory name."
6479 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6481 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
6482 (goto-char (point-min))
6484 (when (search-forward "Path=" nil t
)
6485 (buffer-substring-no-properties (point) (point-at-eol)))
6487 (file-name-as-directory (concat moz-dir moz-user-dir
))))
6489 (defun anything-guess-firefox-bookmark-file ()
6490 "Return the path of the Firefox bookmarks file."
6491 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6493 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
6494 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6495 (let (bookmarks-alist url title
)
6497 (insert-file-contents file
)
6498 (goto-char (point-min))
6499 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
6501 (when (re-search-forward url-regexp nil t
)
6502 (setq url
(match-string 0)))
6503 (when (re-search-forward bmk-regexp nil t
)
6504 (setq title
(match-string 1)))
6505 (push (cons title url
) bookmarks-alist
)
6507 (nreverse bookmarks-alist
)))
6509 (defvar anything-c-firefox-bookmarks-alist nil
)
6510 (defvar anything-c-source-firefox-bookmarks
6511 '((name .
"Firefox Bookmarks")
6513 (setq anything-c-firefox-bookmarks-alist
6514 (anything-html-bookmarks-to-alist
6515 (anything-guess-firefox-bookmark-file)
6516 anything-firefox-bookmark-url-regexp
6517 anything-firefox-bookmarks-regexp
))))
6518 (candidates .
(lambda ()
6519 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
6520 (filtered-candidate-transformer
6521 anything-c-adaptive-sort
6522 anything-c-highlight-firefox-bookmarks
)
6523 (action .
(("Browse Url Firefox"
6524 .
(lambda (candidate)
6526 (anything-c-firefox-bookmarks-get-value candidate
))))
6528 .
(lambda (candidate)
6530 (anything-c-firefox-bookmarks-get-value candidate
))))
6533 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
6535 ;; (anything 'anything-c-source-firefox-bookmarks)
6537 (defun anything-c-firefox-bookmarks-get-value (elm)
6538 (assoc-default elm anything-c-firefox-bookmarks-alist
))
6540 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
6541 (loop for i in bookmarks
6543 i
'face
'((:foreground
"YellowGreen"))
6544 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
6548 ;;; W3m bookmark - anything interface.
6551 ;; Some users have the emacs-w3m library in load-path
6552 ;; without having the w3m executable :-;
6553 ;; So check if w3m program is present before trying to load
6556 (when (executable-find "w3m")
6557 (require 'w3m-bookmark nil t
)))
6559 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html")
6560 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
6561 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6562 (defvar anything-c-w3m-bookmarks-alist nil
)
6563 (defvar anything-c-source-w3m-bookmarks
6564 '((name .
"W3m Bookmarks")
6566 (setq anything-c-w3m-bookmarks-alist
6567 (anything-html-bookmarks-to-alist
6569 anything-w3m-bookmark-url-regexp
6570 anything-w3m-bookmarks-regexp
))))
6571 (candidates .
(lambda ()
6572 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
6573 (filtered-candidate-transformer
6574 anything-c-adaptive-sort
6575 anything-c-highlight-w3m-bookmarks
)
6576 (action .
(("Browse Url"
6577 .
(lambda (candidate)
6578 (anything-c-w3m-browse-bookmark candidate
)))
6581 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
6582 ("Browse Url Firefox"
6583 .
(lambda (candidate)
6584 (anything-c-w3m-browse-bookmark candidate t
)))
6586 .
(lambda (candidate)
6587 (anything-c-w3m-delete-bookmark candidate
)))
6589 .
(lambda (candidate)
6590 (anything-c-w3m-rename-bookmark candidate
)))))
6591 (persistent-action .
(lambda (candidate)
6592 (if current-prefix-arg
6593 (anything-c-w3m-browse-bookmark candidate t
)
6594 (anything-c-w3m-browse-bookmark candidate nil t
))))
6595 (persistent-help .
"Open URL with emacs-w3m in new tab / \
6596 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6597 "Needs w3m and emacs-w3m.
6599 http://w3m.sourceforge.net/
6600 http://emacs-w3m.namazu.org/")
6602 ;; (anything 'anything-c-source-w3m-bookmarks)
6604 (defun anything-c-w3m-bookmarks-get-value (elm)
6605 (replace-regexp-in-string
6606 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
6608 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
6609 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
6610 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
6611 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
6613 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
6614 (loop for i in bookmarks
6616 i
'face
'anything-w3m-bookmarks-face
6617 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
6620 (defun anything-c-w3m-delete-bookmark (elm)
6621 "Delete w3m bookmark from `w3m-bookmark-file'."
6622 (with-current-buffer
6623 (find-file-literally w3m-bookmark-file
)
6624 (goto-char (point-min))
6625 (when (re-search-forward elm nil t
)
6627 (delete-region (point)
6628 (line-end-position))
6629 (delete-blank-lines))
6633 (defun anything-c-w3m-rename-bookmark (elm)
6634 "Rename w3m bookmark in `w3m-bookmark-file'."
6635 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
6636 (new-title (read-string "NewTitle: " old-title
)))
6637 (with-current-buffer
6638 (find-file-literally w3m-bookmark-file
)
6639 (goto-char (point-min))
6640 (when (re-search-forward (concat elm
"<") nil t
)
6641 (goto-char (1- (point)))
6642 (delete-char (- (length old-title
)))
6649 ;;; Elisp library scan
6652 (defvar anything-c-source-elisp-library-scan
6653 '((name .
"Elisp libraries (Scan)")
6654 (init .
(anything-c-elisp-library-scan-init))
6655 (candidates-in-buffer)
6656 (action ("Find library"
6657 .
(lambda (candidate) (find-file (find-library-name candidate
))))
6658 ("Find library other window"
6659 .
(lambda (candidate)
6660 (find-file-other-window (find-library-name candidate
))))
6662 .
(lambda (candidate) (load-library candidate
))))))
6663 ;; (anything 'anything-c-source-elisp-library-scan)
6665 (defun anything-c-elisp-library-scan-init ()
6666 "Init anything buffer status."
6667 (let ((anything-buffer (anything-candidate-buffer 'global
))
6668 (library-list (anything-c-elisp-library-scan-list)))
6669 (with-current-buffer anything-buffer
6670 (dolist (library library-list
)
6671 (insert (format "%s\n" library
))))))
6673 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
6674 "Do completion for file names passed to `locate-file'.
6675 DIRS is directory to search path.
6676 STRING is string to match."
6677 ;; Use `load-path' as path when ignore `dirs'.
6678 (or dirs
(setq dirs load-path
))
6679 ;; Init with blank when ignore `string'.
6680 (or string
(setq string
""))
6681 ;; Get library list.
6682 (let ((string-dir (file-name-directory string
))
6683 ;; File regexp that suffix match `load-file-rep-suffixes'.
6684 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
6689 (setq dir default-directory
))
6691 (setq dir
(expand-file-name string-dir dir
)))
6692 (when (file-directory-p dir
)
6693 (dolist (file (file-name-all-completions
6694 (file-name-nondirectory string
) dir
))
6695 ;; Suffixes match `load-file-rep-suffixes'.
6696 (setq name
(if string-dir
(concat string-dir file
) file
))
6697 (if (string-match match-regexp name
)
6698 (add-to-list 'names name
)))))
6709 (defvar anything-c-imenu-delimiter
" / ")
6711 (defvar anything-c-imenu-index-filter nil
)
6712 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
6714 (defvar anything-c-cached-imenu-alist nil
)
6715 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
6717 (defvar anything-c-cached-imenu-candidates nil
)
6718 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
6720 (defvar anything-c-cached-imenu-tick nil
)
6721 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
6723 (eval-when-compile (require 'imenu
))
6724 (setq imenu-auto-rescan t
)
6726 (defun anything-imenu-create-candidates (entry)
6727 "Create candidates with ENTRY."
6728 (if (listp (cdr entry
))
6731 (if (consp (cdr sub
))
6734 (concat (car entry
) anything-c-imenu-delimiter subentry
))
6735 (anything-imenu-create-candidates sub
))
6736 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
6740 (defvar anything-c-source-imenu
6742 (init .
(lambda () (require 'imenu
)))
6743 (candidates . anything-c-imenu-candidates
)
6744 (persistent-action .
(lambda (elm)
6745 (anything-c-imenu-default-action elm
)
6746 (unless (fboundp 'semantic-imenu-tag-overlay
)
6747 (anything-match-line-color-current-line))))
6748 (persistent-help .
"Show this entry")
6749 (action . anything-c-imenu-default-action
))
6750 "See (info \"(emacs)Imenu\")")
6752 ;; (anything 'anything-c-source-imenu)
6754 (defun anything-c-imenu-candidates ()
6755 (with-anything-current-buffer
6756 (let ((tick (buffer-modified-tick)))
6757 (if (eq anything-c-cached-imenu-tick tick
)
6758 anything-c-cached-imenu-candidates
6759 (setq imenu--index-alist nil
)
6760 (setq anything-c-cached-imenu-tick tick
6761 anything-c-cached-imenu-candidates
6764 'anything-imenu-create-candidates
6765 (setq anything-c-cached-imenu-alist
6766 (let ((index (imenu--make-index-alist)))
6767 (if anything-c-imenu-index-filter
6768 (funcall anything-c-imenu-index-filter index
)
6770 (setq anything-c-cached-imenu-candidates
6771 (mapcar #'(lambda (x)
6775 anything-c-cached-imenu-candidates
))))))
6777 (setq imenu-default-goto-function
'imenu-default-goto-function
)
6778 (defun anything-c-imenu-default-action (elm)
6779 "The default action for `anything-c-source-imenu'."
6780 (let ((path (split-string elm anything-c-imenu-delimiter
))
6781 (alist anything-c-cached-imenu-alist
))
6783 (setq alist
(assoc elm alist
)))
6791 (defvar anything-c-ctags-modes
6792 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6793 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6794 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
6796 (defun anything-c-source-ctags-init ()
6797 (when (and buffer-file-name
6798 (memq major-mode anything-c-ctags-modes
)
6799 (anything-current-buffer-is-modified))
6800 (with-current-buffer (anything-candidate-buffer 'local
)
6801 (call-process-shell-command
6802 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
6803 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6804 anything-buffer-file-name
)
6805 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
6806 nil
(current-buffer))
6807 (goto-char (point-min))
6809 (delete-region (point-min) (point))
6810 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
6811 for lineno-start
= (point)
6812 for lineno
= (buffer-substring
6814 (1- (search-forward "," (point-at-eol) t
)))
6817 (insert (format "%5s:" lineno
))
6818 (search-forward "\177" (point-at-eol) t
)
6819 (delete-region (1- (point)) (point-at-eol))
6820 (forward-line 1)))))
6822 (defvar anything-c-source-ctags
6823 '((name .
"Exuberant ctags")
6824 (init . anything-c-source-ctags-init
)
6825 (candidates-in-buffer)
6828 "Needs Exuberant Ctags.
6830 http://ctags.sourceforge.net/")
6831 ;; (anything 'anything-c-source-ctags)
6837 ;; anything-etags.el is deprecated, if this file is found,
6838 ;; warn user at compile time.
6840 (when (locate-library "anything-etags.el")
6843 "You are using obsolete library `anything-etags.el' and should remove it."
6846 (defvar anything-c-etags-tag-file-dir nil
6847 "Etags file directory.")
6848 (defvar anything-c-etags-mtime-alist nil
6849 "Store the last modification time of etags files here.")
6850 (defvar anything-c-etags-cache
(make-hash-table :test
'equal
)
6851 "Cache content of etags files used here for faster access.")
6853 (defun anything-c-etags-get-tag-file (&optional directory
)
6854 "Return the path of etags file if found."
6855 ;; Get tag file from `default-directory' or upper directory.
6856 (let ((current-dir (anything-c-etags-find-tag-file-directory
6857 (or directory default-directory
))))
6858 ;; Return nil if not find tag file.
6860 ;; Set tag file directory.
6861 (setq anything-c-etags-tag-file-dir current-dir
)
6862 (expand-file-name anything-c-etags-tag-file-name current-dir
))))
6864 (defun anything-c-etags-find-tag-file-directory (current-dir)
6865 "Try to find the directory containing tag file.
6866 If not found in CURRENT-DIR search in upper directory."
6867 (flet ((file-exists?
(dir)
6868 (let ((tag-path (expand-file-name
6869 anything-c-etags-tag-file-name dir
)))
6870 (and (stringp tag-path
)
6871 (file-exists-p tag-path
)
6872 (file-readable-p tag-path
)))))
6873 (loop with count
= 0
6874 until
(file-exists? current-dir
)
6875 ;; Return nil if outside the value of
6876 ;; `anything-c-etags-tag-file-search-limit'.
6877 if
(= count anything-c-etags-tag-file-search-limit
)
6879 ;; Or search upper directories.
6882 (setq current-dir
(expand-file-name (concat current-dir
"../")))
6883 finally return current-dir
)))
6885 (defun anything-c-source-etags-header-name (x)
6886 "Create header name for this anything etags session."
6888 (with-anything-current-buffer
6889 (anything-c-etags-get-tag-file))))
6891 (defmacro anything-c-etags-create-buffer
(file)
6892 "Create the `anything-buffer' based on contents of etags tag FILE."
6893 `(let* ((tag-fname ,file
)
6895 (split (with-current-buffer (find-file-noselect tag-fname
)
6897 (split-string (buffer-string) "\n" 'omit-nulls
)
6898 (setq max
(line-number-at-pos (point-max)))
6900 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max
)))
6904 for i in split for count from
0
6905 for elm
= (unless (string-match "^\x0c" i
)
6906 (anything-aif (string-match "\177" i
)
6909 do
(cond ((and elm
(string-match "^\\(.+\\),[0-9]+" elm
))
6910 (setq fname
(match-string 1 elm
)))
6911 (elm (setq cand
(concat fname
": " elm
)))
6912 (t (setq cand nil
)))
6914 (insert (concat cand
"\n"))
6915 (progress-reporter-update progress-reporter count
)))))
6917 (defun anything-c-etags-init ()
6918 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6919 If no entry in cache, create one."
6920 (let ((tagfile (anything-c-etags-get-tag-file)))
6922 (with-current-buffer (anything-candidate-buffer 'global
)
6923 (anything-aif (gethash tagfile anything-c-etags-cache
)
6924 ;; An entry is present in cache, insert it.
6926 ;; No entry, create a new buffer using content of tag file (slower).
6927 (anything-c-etags-create-buffer tagfile
)
6928 ;; Store content of buffer in cache.
6929 (puthash tagfile
(buffer-string) anything-c-etags-cache
)
6930 ;; Store or set the last modification of tag file.
6931 (anything-aif (assoc tagfile anything-c-etags-mtime-alist
)
6932 ;; If an entry exists modify it.
6933 (setcdr it
(anything-c-etags-mtime tagfile
))
6934 ;; No entry create a new one.
6935 (add-to-list 'anything-c-etags-mtime-alist
6936 (cons tagfile
(anything-c-etags-mtime tagfile
)))))))))
6938 (defvar anything-c-source-etags-select
6940 (header-name . anything-c-source-etags-header-name
)
6941 (init . anything-c-etags-init
)
6942 (candidates-in-buffer)
6943 (search .
(anything-c-etags-search-fn))
6944 (mode-line . anything-etags-mode-line-string
)
6945 (action . anything-c-etags-default-action
)
6946 (persistent-action .
(lambda (candidate)
6947 (anything-c-etags-default-action candidate
)
6948 (anything-match-line-color-current-line))))
6949 "Anything source for Etags.")
6951 (defun anything-c-etags-search-fn (pattern bound noerror
)
6952 "Search function for `anything-c-source-etags-select'."
6954 (if anything-c-etags-use-regexp-search
(concat "\\_<" pattern
) pattern
)
6957 (defun anything-c-etags-default-action (candidate)
6958 "Anything default action to jump to an etags entry."
6959 (let* ((split (split-string candidate
": "))
6960 (fname (expand-file-name
6961 (car split
) anything-c-etags-tag-file-dir
))
6964 (goto-char (point-min))
6965 (search-forward elm nil t
)
6966 (goto-char (match-beginning 0))))
6968 (defun anything-c-etags-mtime (file)
6969 "Last modification time of etags tag FILE."
6970 (cadr (nth 5 (file-attributes file
))))
6972 (defun anything-c-etags-file-modified-p (file)
6973 "Check if tag FILE have been modified in this session.
6974 If FILE is nil return nil."
6975 (let ((last-modif (and file
6976 (assoc-default file anything-c-etags-mtime-alist
))))
6978 (/= last-modif
(anything-c-etags-mtime file
)))))
6985 (defvar anything-semantic-candidates nil
)
6987 (defun anything-semantic-construct-candidates (tags depth
)
6988 (when (require 'semantic nil t
)
6994 (let ((type (semantic-tag-type tag
))
6995 (class (semantic-tag-class tag
)))
6996 (if (or (and (stringp type
)
6997 (or (string= type
"class")
6998 (string= type
"namespace")))
6999 (eq class
'function
)
7000 (eq class
'variable
))
7001 (cons (cons (concat (make-string (* depth
2) ?\s
)
7002 (semantic-format-tag-summarize tag nil t
))
7004 (anything-semantic-construct-candidates
7005 (semantic-tag-components tag
) (1+ depth
)))))))
7008 (defun anything-semantic-default-action (candidate)
7009 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
7010 (semantic-go-to-tag tag
)))
7012 (defvar anything-c-source-semantic
7013 '((name .
"Semantic Tags")
7015 (setq anything-semantic-candidates
7016 (ignore-errors (anything-semantic-construct-candidates
7017 (semantic-fetch-tags) 0)))))
7018 (candidates .
(lambda ()
7019 (if anything-semantic-candidates
7020 (mapcar 'car anything-semantic-candidates
))))
7021 (persistent-action .
(lambda (elm)
7022 (anything-semantic-default-action elm
)
7023 (anything-match-line-color-current-line)))
7024 (persistent-help .
"Show this entry")
7025 (action . anything-semantic-default-action
)
7026 "Needs semantic in CEDET.
7028 http://cedet.sourceforge.net/semantic.shtml
7029 http://cedet.sourceforge.net/"))
7031 ;; (anything 'anything-c-source-semantic)
7034 ;;; Anything interface of `simple-call-tree.el'.
7036 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7038 ;; Function is called by
7039 (defvar anything-c-source-simple-call-tree-functions-callers
7040 '((name .
"Function is called by")
7041 (init . anything-c-simple-call-tree-functions-callers-init
)
7043 (candidates . anything-c-simple-call-tree-candidates
)
7044 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7045 (persistent-help .
"Show function definitions by rotation")
7046 (action ("Find definition selected by persistent-action" .
7047 anything-c-simple-call-tree-find-definition
)))
7048 "Needs simple-call-tree.el.
7049 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7051 (defvar anything-c-simple-call-tree-tick nil
)
7052 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
7053 (defun anything-c-simple-call-tree-analyze-maybe ()
7054 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
7055 (simple-call-tree-analyze)
7056 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
7058 (defun anything-c-simple-call-tree-init-base (function message
)
7059 (require 'simple-call-tree
)
7061 (when (anything-current-buffer-is-modified)
7062 (anything-c-simple-call-tree-analyze-maybe)
7063 (let ((list (funcall function simple-call-tree-alist
)))
7064 (with-current-buffer (anything-candidate-buffer 'local
)
7065 (dolist (entry list
)
7066 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
7067 (insert (car entry
) message
7068 (if (string= funcs
" ")
7073 (defun anything-c-simple-call-tree-functions-callers-init ()
7074 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7077 (defun anything-c-simple-call-tree-candidates ()
7078 (with-current-buffer (anything-candidate-buffer)
7079 (split-string (buffer-string) "\n\n")))
7081 (defvar anything-c-simple-call-tree-related-functions nil
)
7082 (defvar anything-c-simple-call-tree-function-index
0)
7083 (defun anything-c-simple-call-tree-persistent-action (candidate)
7084 (unless (eq last-command
'anything-execute-persistent-action
)
7085 (setq anything-c-simple-call-tree-related-functions
7086 (delete "no functions."
7088 (replace-regexp-in-string " \\| is called by\\| calls "
7091 (setq anything-c-simple-call-tree-function-index -
1))
7092 (incf anything-c-simple-call-tree-function-index
)
7093 (anything-c-simple-call-tree-find-definition candidate
))
7095 (defun anything-c-simple-call-tree-find-definition (candidate)
7098 (nth (mod anything-c-simple-call-tree-function-index
7099 (length anything-c-simple-call-tree-related-functions
))
7100 anything-c-simple-call-tree-related-functions
))))
7102 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7105 (defvar anything-c-source-simple-call-tree-callers-functions
7106 '((name .
"Function calls")
7107 (init . anything-c-simple-call-tree-callers-functions-init
)
7109 (candidates . anything-c-simple-call-tree-candidates
)
7110 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7111 (persistent-help .
"Show function definitions by rotation")
7112 (action ("Find definition selected by persistent-action" .
7113 anything-c-simple-call-tree-find-definition
)))
7114 "Needs simple-call-tree.el.
7115 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7117 (defun anything-c-simple-call-tree-callers-functions-init ()
7118 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
7120 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7124 ;;; Anything UI of auto-document.el
7126 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7128 ;; Commands/Options with doc
7129 (defvar anything-c-auto-document-data nil
)
7130 (make-variable-buffer-local 'anything-c-auto-document-data
)
7131 (defvar anything-c-source-commands-and-options-in-file
7132 '((name .
"Commands/Options in file")
7134 .
(lambda (x) (format "Commands/Options in %s"
7135 (buffer-local-value 'buffer-file-name
7136 anything-current-buffer
))))
7137 (candidates . anything-command-and-options-candidates
)
7140 "List Commands and Options with doc. It needs auto-document.el .
7142 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7144 (eval-when-compile (require 'auto-document nil t
))
7145 (defun anything-command-and-options-candidates ()
7146 (with-anything-current-buffer
7147 (when (and (require 'auto-document nil t
)
7148 (eq major-mode
'emacs-lisp-mode
)
7149 (or (anything-current-buffer-is-modified)
7150 (not anything-c-auto-document-data
)))
7151 (or imenu--index-alist
(imenu--make-index-alist t
))
7152 (setq anything-c-auto-document-data
7153 (destructuring-bind (commands options
)
7154 (adoc-construct anything-current-buffer
)
7156 (loop for
(command . doc
) in commands
7157 for cmdname
= (symbol-name command
)
7160 (format "Command: %s\n %s"
7161 (propertize cmdname
'face font-lock-function-name-face
)
7162 (adoc-first-line doc
))
7163 (assoc cmdname imenu--index-alist
)))
7164 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
7165 for
(option doc default
) in options
7166 for optname
= (symbol-name option
)
7169 (format "Option: %s\n %s\n default = %s"
7170 (propertize optname
'face font-lock-variable-name-face
)
7171 (adoc-first-line doc
)
7172 (adoc-prin1-to-string default
))
7175 anything-c-auto-document-data
))
7177 ;; (anything 'anything-c-source-commands-and-options-in-file)
7180 ;;;; <Color and Face>
7186 (defvar anything-c-source-customize-face
7187 '((name .
"Customize Face")
7189 (unless (anything-candidate-buffer)
7190 (save-window-excursion (list-faces-display))
7191 (anything-candidate-buffer (get-buffer "*Faces*")))))
7192 (candidates-in-buffer)
7193 (get-line . buffer-substring
)
7194 (action .
(lambda (line)
7195 (customize-face (intern (car (split-string line
))))))
7196 (requires-pattern .
3))
7197 "See (info \"(emacs)Faces\")")
7198 ;; (anything 'anything-c-source-customize-face)
7203 (defvar anything-c-source-colors
7205 (init .
(lambda () (unless (anything-candidate-buffer)
7206 (save-window-excursion (list-colors-display))
7207 (anything-candidate-buffer (get-buffer "*Colors*")))))
7208 (candidates-in-buffer)
7209 (get-line . buffer-substring
)
7211 ("Copy Name" .
(lambda (candidate)
7212 (kill-new (anything-c-colors-get-name candidate
))))
7213 ("Copy RGB" .
(lambda (candidate)
7214 (kill-new (anything-c-colors-get-rgb candidate
))))
7215 ("Insert Name" .
(lambda (candidate)
7216 (with-anything-current-buffer
7217 (insert (anything-c-colors-get-name candidate
)))))
7218 ("Insert RGB" .
(lambda (candidate)
7219 (with-anything-current-buffer
7220 (insert (anything-c-colors-get-rgb candidate
))))))))
7221 ;; (anything 'anything-c-source-colors)
7223 (defun anything-c-colors-get-name (candidate)
7225 (replace-regexp-in-string
7228 (insert (capitalize candidate
))
7229 (goto-char (point-min))
7230 (search-forward-regexp "\\s-\\{2,\\}")
7231 (delete-region (point) (point-max))
7234 (defun anything-c-colors-get-rgb (candidate)
7236 (replace-regexp-in-string
7239 (insert (capitalize candidate
))
7240 (goto-char (point-max))
7241 (search-backward-regexp "\\s-\\{2,\\}")
7242 (delete-region (point) (point-min))
7246 ;;;; <Search Engine>
7247 ;;; Tracker desktop search
7248 (defvar anything-c-source-tracker-search
7249 '((name .
"Tracker Search")
7250 (candidates .
(lambda ()
7251 (start-process "tracker-search-process" nil
7255 (requires-pattern .
3)
7257 "Source for retrieving files matching the current input pattern
7258 with the tracker desktop search.")
7259 ;; (anything 'anything-c-source-tracker-search)
7261 ;;; Spotlight (MacOS X desktop search)
7262 (defvar anything-c-source-mac-spotlight
7265 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
7267 (requires-pattern .
3)
7269 "Source for retrieving files via Spotlight's command line
7271 ;; (anything 'anything-c-source-mac-spotlight)
7274 (defvar anything-c-source-picklist
7275 '((name .
"Picklist")
7276 (candidates .
(lambda () (mapcar 'car picklist-list
)))
7278 ;; (anything 'anything-c-source-picklist)
7285 (defvar anything-c-source-kill-ring
7286 '((name .
"Kill Ring")
7287 (init .
(lambda () (anything-attrset 'last-command last-command
)))
7288 (candidates . anything-c-kill-ring-candidates
)
7289 (filtered-candidate-transformer anything-c-kill-ring-transformer
)
7290 (action . anything-c-kill-ring-action
)
7294 "Source for browse and insert contents of kill-ring.")
7296 (defun anything-c-kill-ring-candidates ()
7297 (loop for kill in
(anything-fast-remove-dups kill-ring
:test
'equal
)
7298 unless
(or (< (length kill
) anything-kill-ring-threshold
)
7299 (string-match "^[\\s\\t]+$" kill
))
7302 (defun anything-c-kill-ring-transformer (candidates source
)
7303 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7304 (loop for i in candidates
7305 for nlines
= (with-temp-buffer (insert i
) (count-lines (point-min) (point-max)))
7306 if
(and anything-c-kill-ring-max-lines-number
7307 (> nlines anything-c-kill-ring-max-lines-number
))
7311 (goto-char (point-min))
7316 (forward-line anything-c-kill-ring-max-lines-number
)
7321 (defun anything-c-kill-ring-action (str)
7322 "Insert STR in `kill-ring' and set STR to the head.
7323 If this action is executed just after `yank',
7324 replace with STR as yanked string."
7325 (setq kill-ring
(delete str kill-ring
))
7326 (if (not (eq (anything-attr 'last-command
) 'yank
))
7327 (insert-for-yank str
)
7329 (let ((inhibit-read-only t
)
7330 (before (< (point) (mark t
))))
7332 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
7333 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
7334 (setq yank-undo-function nil
)
7335 (set-marker (mark-marker) (point) (current-buffer))
7336 (insert-for-yank str
)
7337 ;; Set the window start back where it was in the yank command,
7339 (set-window-start (selected-window) yank-window-start t
)
7341 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7342 ;; It is cleaner to avoid activation, even though the command
7343 ;; loop would deactivate the mark because we inserted text.
7344 (goto-char (prog1 (mark t
)
7345 (set-marker (mark-marker) (point) (current-buffer)))))))
7348 ;; (anything 'anything-c-source-kill-ring)
7352 ;; DO NOT include these sources in `anything-sources' use
7353 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7354 ;; `anything-all-mark-rings' instead.
7356 (defun anything-c-source-mark-ring-candidates ()
7357 (flet ((get-marks (pos)
7361 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
7362 (when (string= "" line
)
7363 (setq line
"<EMPTY LINE>"))
7364 (format "%7d: %s" (line-number-at-pos) line
)))))
7365 (with-anything-current-buffer
7367 with marks
= (if (mark) (cons (mark-marker) mark-ring
) mark-ring
)
7370 for m
= (get-marks i
)
7371 unless
(member m recip
)
7372 collect m into recip
7373 finally return recip
))))
7375 (defvar anything-mark-ring-cache nil
)
7376 (defvar anything-c-source-mark-ring
7377 '((name .
"mark-ring")
7379 (setq anything-mark-ring-cache
7380 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7381 (candidates .
(lambda ()
7382 (anything-aif anything-mark-ring-cache
7384 (action .
(("Goto line"
7385 .
(lambda (candidate)
7386 (anything-goto-line (string-to-number candidate
))))))
7387 (persistent-action .
(lambda (candidate)
7388 (anything-goto-line (string-to-number candidate
))
7389 (anything-match-line-color-current-line)))
7390 (persistent-help .
"Show this line")))
7392 ;; (anything 'anything-c-source-mark-ring)
7394 ;;; Global-mark-ring
7395 (defvar anything-c-source-global-mark-ring
7396 '((name .
"global-mark-ring")
7397 (candidates . anything-c-source-global-mark-ring-candidates
)
7398 (action .
(("Goto line"
7399 .
(lambda (candidate)
7400 (let ((items (split-string candidate
":")))
7401 (anything-c-switch-to-buffer (second items
))
7402 (anything-goto-line (string-to-number (car items
))))))))
7403 (persistent-action .
(lambda (candidate)
7404 (let ((items (split-string candidate
":")))
7405 (anything-c-switch-to-buffer (second items
))
7406 (anything-goto-line (string-to-number (car items
)))
7407 (anything-match-line-color-current-line))))
7408 (persistent-help .
"Show this line")))
7410 (defun anything-c-source-global-mark-ring-candidates ()
7412 (with-current-buffer (marker-buffer m
)
7416 (if (string= "" line
)
7417 (setq line
"<EMPTY LINE>")
7418 (setq line
(car (split-string (thing-at-point 'line
)
7420 (format "%7d:%s: %s"
7421 (line-number-at-pos) (marker-buffer m
) line
)))))
7423 with marks
= global-mark-ring
7426 for gm
= (unless (or (string-match
7427 "^ " (format "%s" (marker-buffer i
)))
7428 (null (marker-buffer i
)))
7430 when
(and gm
(not (member gm recip
)))
7431 collect gm into recip
7432 finally return recip
)))
7434 ;; (anything 'anything-c-source-global-mark-ring)
7438 ;;; Insert from register
7439 (defvar anything-c-source-register
7440 '((name .
"Registers")
7441 (candidates . anything-c-register-candidates
)
7442 (action-transformer . anything-c-register-action-transformer
)
7445 "See (info \"(emacs)Registers\")")
7447 (defun anything-c-register-candidates ()
7448 "Collecting register contents and appropriate commands."
7449 (loop for
(char . val
) in register-alist
7450 for key
= (single-key-description char
)
7451 for string-actions
=
7454 (list (int-to-string val
)
7456 'increment-register
))
7458 (let ((buf (marker-buffer val
)))
7460 (list "a marker in no buffer")
7462 "a buffer position:"
7465 (int-to-string (marker-position val
)))
7467 'insert-register
))))
7468 ((and (consp val
) (window-configuration-p (car val
)))
7469 (list "window configuration."
7471 ((and (consp val
) (frame-configuration-p (car val
)))
7472 (list "frame configuration."
7474 ((and (consp val
) (eq (car val
) 'file
))
7475 (list (concat "file:"
7476 (prin1-to-string (cdr val
))
7479 ((and (consp val
) (eq (car val
) 'file-query
))
7480 (list (concat "file:a file-query reference: file "
7483 (int-to-string (car (cdr (cdr val
))))
7487 (let ((lines (format "%4d" (length val
))))
7488 (list (format "%s: %s\n" lines
7489 (truncate-string-to-width
7490 (mapconcat 'identity
(list (car val
))
7491 ;; (mapconcat (lambda (y) y) val
7492 "^J") (- (window-width) 15)))
7495 (list ;; without properties
7496 (substring-no-properties val
)
7499 'prepend-to-register
))
7502 collect
(cons (format "register %3s: %s" key
(car string-actions
))
7503 (cons char
(cdr string-actions
)))))
7505 (defun anything-c-register-action-transformer (actions register-and-functions
)
7506 "Decide actions by the contents of register."
7507 (loop with func-actions
=
7510 (lambda (c) (insert-register (car c
))))
7512 "Jump to Register" .
7513 (lambda (c) (jump-to-register (car c
))))
7515 "Append Region to Register" .
7516 (lambda (c) (append-to-register
7517 (car c
) (region-beginning) (region-end))))
7518 (prepend-to-register
7519 "Prepend Region to Register" .
7520 (lambda (c) (prepend-to-register
7521 (car c
) (region-beginning) (region-end))))
7523 "Increment Prefix Arg to Register" .
7524 (lambda (c) (increment-register
7525 anything-current-prefix-arg
(car c
)))))
7526 for func in
(cdr register-and-functions
)
7527 for cell
= (assq func func-actions
)
7529 collect
(cdr cell
)))
7531 ;; (anything 'anything-c-source-register)
7534 ;;; Latex completion
7535 (defun anything-c-latex-math-candidates ()
7536 "Collect candidates for latex math completion."
7537 (declare (special LaTeX-math-menu
))
7538 (loop for i in
(cddr LaTeX-math-menu
)
7539 for elm
= (loop for s in i when
(vectorp s
)
7540 collect
(cons (aref s
0) (aref s
1)))
7543 (defvar anything-c-source-latex-math
7544 '((name .
"Latex Math Menu")
7546 (with-anything-current-buffer
7547 (LaTeX-math-mode 1))))
7548 (candidate-number-limit .
9999)
7549 (candidates . anything-c-latex-math-candidates
)
7550 (action .
(lambda (candidate)
7551 (call-interactively candidate
)))))
7554 ;;;; <Headline Extraction>
7555 (defvar anything-c-source-fixme
7556 '((name .
"TODO/FIXME/DRY comments")
7557 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7560 "Show TODO/FIXME/DRY comments in current file.")
7561 ;; (anything 'anything-c-source-fixme)
7563 (defvar anything-c-source-rd-headline
7564 '((name .
"RD HeadLine")
7565 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7566 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
7572 http://en.wikipedia.org/wiki/Ruby_Document_format")
7573 ;; (anything 'anything-c-source-rd-headline)
7575 (defvar anything-c-source-oddmuse-headline
7576 '((name .
"Oddmuse HeadLine")
7577 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7578 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7579 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
7582 "Show Oddmuse headlines, such as EmacsWiki.")
7583 ;; (anything 'anything-c-source-oddmuse-headline)
7585 (defvar anything-c-source-emacs-source-defun
7586 '((name .
"Emacs Source DEFUN")
7587 (headline .
"DEFUN\\|DEFVAR")
7588 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
7589 (or buffer-file-name
""))))
7590 "Show DEFUN/DEFVAR in Emacs C source file.")
7591 ;; (anything 'anything-c-source-emacs-source-defun)
7593 (defvar anything-c-source-emacs-lisp-expectations
7594 '((name .
"Emacs Lisp Expectations")
7595 (headline .
"(desc[ ]\\|(expectations")
7596 (condition .
(eq major-mode
'emacs-lisp-mode
)))
7597 "Show descriptions (desc) in Emacs Lisp Expectations.
7599 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7600 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7602 (defvar anything-c-source-emacs-lisp-toplevels
7603 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7604 (headline .
"^(\\|(@\\*\\|^;;;;")
7605 (get-line . buffer-substring
)
7606 (condition .
(eq major-mode
'emacs-lisp-mode
))
7608 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7609 linkd.el is optional because linkd stars are extracted by regexp.
7610 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7611 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7614 ;;; Anything yaoddmuse
7616 ;; Be sure to have yaoddmuse.el installed
7617 ;; install-elisp may be required if you want to install elisp file from here.
7618 (defvar anything-yaoddmuse-use-cache-file nil
)
7619 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
7620 (defvar anything-c-yaoddmuse-ew-cache nil
)
7622 (defun anything-yaoddmuse-get-candidates ()
7623 (declare (special yaoddmuse-pages-hash
))
7624 (if anything-yaoddmuse-use-cache-file
7626 (unless anything-c-yaoddmuse-ew-cache
7627 (load anything-c-yaoddmuse-cache-file
)
7628 (setq anything-c-yaoddmuse-ew-cache
7629 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7630 anything-c-yaoddmuse-ew-cache
)
7631 (yaoddmuse-update-pagename t
)
7632 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7634 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7635 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
7636 (candidates . anything-yaoddmuse-get-candidates
)
7637 (action .
(("Edit page" .
(lambda (candidate)
7638 (yaoddmuse-edit "EmacsWiki" candidate
)))
7640 .
(lambda (candidate)
7641 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
7642 ("Browse page other window"
7643 .
(lambda (candidate)
7645 (split-window-vertically))
7646 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
7648 .
(lambda (candidate)
7649 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
7651 .
(lambda (candidate)
7652 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
7653 (message "Have copy page %s's URL to yank." candidate
)))
7655 .
(lambda (candidate)
7656 (yaoddmuse-edit "EmacsWiki" anything-input
)))
7658 .
(lambda (candidate)
7659 (if anything-yaoddmuse-use-cache-file
7661 (anything-yaoddmuse-cache-pages t
)
7662 (setq anything-c-yaoddmuse-ew-cache
7663 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7664 (yaoddmuse-update-pagename))))))
7665 (action-transformer anything-c-yaoddmuse-action-transformer
))
7666 "Needs yaoddmuse.el.
7668 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7670 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7672 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7673 '((name .
"Yaoddmuse Post library (EmacsWiki)")
7674 (init .
(anything-yaoddmuse-init))
7675 (candidates-in-buffer)
7676 (action .
(("Post library and Browse"
7677 .
(lambda (candidate)
7678 (yaoddmuse-post-file
7679 (find-library-name candidate
)
7681 (file-name-nondirectory (find-library-name candidate
))
7684 .
(lambda (candidate)
7685 (yaoddmuse-post-file
7686 (find-library-name candidate
)
7688 (file-name-nondirectory
7689 (find-library-name candidate
))))))))
7690 "Needs yaoddmuse.el.
7692 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7694 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7696 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
7697 "Allow the use of `install-elisp' only on elisp files."
7698 (if (string-match "\.el$" candidate
)
7699 (append actions
'(("Install Elisp"
7701 (install-elisp-from-emacswiki elm
)))))
7705 (defun anything-yaoddmuse-cache-pages (&optional load
)
7706 "Fetch the list of files on emacswiki and create cache file.
7707 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7709 (declare (special yaoddmuse-pages-hash
))
7710 (yaoddmuse-update-pagename)
7712 (find-file anything-c-yaoddmuse-cache-file
)
7714 (insert "(puthash \"EmacsWiki\" '(")
7715 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
7717 (insert (concat "(\"" (car i
) "\") ")))
7718 (insert ") yaoddmuse-pages-hash)\n")
7720 (kill-buffer (current-buffer))
7721 (when (or current-prefix-arg
7723 (load anything-c-yaoddmuse-cache-file
))))
7725 (defun anything-yaoddmuse-init ()
7726 "Init anything buffer status."
7727 (let ((anything-buffer (anything-candidate-buffer 'global
))
7728 (library-list (yaoddmuse-get-library-list)))
7729 (with-current-buffer anything-buffer
7730 ;; Insert library name.
7731 (dolist (library library-list
)
7732 (insert (format "%s\n" library
)))
7734 (sort-lines nil
(point-min) (point-max)))))
7738 (defvar anything-c-source-eev-anchor
7739 '((name .
"Anchors")
7743 (with-anything-current-buffer
7744 (loop initially
(goto-char (point-min))
7745 while
(re-search-forward
7746 (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
7747 for anchor
= (match-string-no-properties 1)
7748 collect
(cons (format "%5d:%s"
7749 (line-number-at-pos (match-beginning 0))
7750 (format ee-anchor-format anchor
))
7752 (persistent-action .
(lambda (item)
7754 (anything-match-line-color-current-line)))
7755 (persistent-help .
"Show this entry")
7756 (action .
(("Goto link" . ee-to
)))))
7757 ;; (anything 'anything-c-source-eev-anchor)
7763 (defvar anything-c-source-org-headline
7764 `((name .
"Org HeadLine")
7768 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7770 (number-sequence 1 8)))
7771 (condition .
(eq major-mode
'org-mode
))
7774 (persistent-action .
(lambda (elm)
7775 (anything-c-action-line-goto elm
)
7778 .
(lambda (actions candidate
)
7779 '(("Go to Line" . anything-c-action-line-goto
)
7780 ("Refile to this Headline" . anything-c-org-headline-refile
)
7781 ("Insert Link to This Headline"
7782 . anything-c-org-headline-insert-link-to-headline
)))))
7783 "Show Org headlines.
7784 org-mode is very very much extended text-mode/outline-mode.
7786 See (find-library \"org.el\")
7787 See http://orgmode.org for the latest version.")
7788 ;; (anything 'anything-c-source-org-headline)
7790 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7793 (anything-goto-line (car lineno-and-content
))
7794 (and (looking-at org-complex-heading-regexp
)
7795 (org-make-link-string (concat "*" (match-string 4)))))))
7797 (defun anything-c-org-headline-refile (lineno-and-content)
7798 "Refile current org entry to LINENO-AND-CONTENT."
7799 (with-anything-current-buffer
7801 (anything-goto-line (car lineno-and-content
))
7802 (org-end-of-subtree t t
)
7803 (let ((org-yank-adjusted-subtrees t
))
7810 (defvar anything-c-source-org-keywords
7811 '((name .
"Org Keywords")
7812 (init . anything-c-org-keywords-init
)
7813 (candidates . anything-c-org-keywords-candidates
)
7814 (action . anything-c-org-keywords-insert
)
7815 (persistent-action . anything-c-org-keywords-show-help
)
7816 (persistent-help .
"Show an example and info page to describe this keyword.")
7819 ;; (anything 'anything-c-source-org-keywords)
7821 (defvar anything-c-org-keywords-info-location
7822 '(("#+TITLE:" .
"(org)Export options")
7823 ("#+AUTHOR:" .
"(org)Export options")
7824 ("#+DATE:" .
"(org)Export options")
7825 ("#+EMAIL:" .
"(org)Export options")
7826 ("#+DESCRIPTION:" .
"(org)Export options")
7827 ("#+KEYWORDS:" .
"(org)Export options")
7828 ("#+LANGUAGE:" .
"(org)Export options")
7829 ("#+TEXT:" .
"(org)Export options")
7830 ("#+TEXT:" .
"(org)Export options")
7831 ("#+OPTIONS:" .
"(org)Export options")
7832 ("#+BIND:" .
"(org)Export options")
7833 ("#+LINK_UP:" .
"(org)Export options")
7834 ("#+LINK_HOME:" .
"(org)Export options")
7835 ("#+LATEX_HEADER:" .
"(org)Export options")
7836 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
7837 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
7838 ("#+INFOJS_OPT" .
"(org)Javascript support")
7839 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
7840 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
7841 ("#+ORGTBL" .
"(org)Radio tables")
7842 ("#+HTML:" .
"(org)Quoting HTML tags")
7843 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
7844 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
7845 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
7846 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
7847 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
7848 ("#+BEGIN_SRC" .
"(org)Literal examples")
7849 ("#+CAPTION" .
"(org)Tables in HTML export")
7850 ("#+LABEL" .
"(org)Tables in LaTeX export")
7851 ("#+ATTR_HTML" .
"(org)Links")
7852 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
7854 (defun anything-c-org-keywords-init ()
7855 (unless (anything-attr 'keywords-examples
)
7857 (anything-attrset 'keywords-examples
7861 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
7862 (cons (match-string 2 x
) (match-string 1 x
)))
7863 (org-split-string (org-get-current-options) "\n"))
7864 (mapcar 'list org-additional-option-like-keywords
)))
7865 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
7867 (defun anything-c-org-keywords-candidates ()
7868 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
7869 (eq (buffer-local-value 'major-mode anything-current-buffer
) 'message-mode
))
7870 (anything-attr 'keywords
)))
7872 (defun anything-c-org-keywords-insert (keyword)
7873 (cond ((and (string-match "BEGIN" keyword
)
7874 (anything-region-active-p))
7875 (let ((beg (region-beginning))
7878 (insert "\n#+" (replace-regexp-in-string
7879 "BEGIN" "END" keyword
) "\n")
7881 (insert "#+" keyword
" ")
7882 (save-excursion (insert "\n"))))
7883 ((string-match "BEGIN" keyword
)
7884 (insert "#+" keyword
" ")
7886 (insert "\n#+" (replace-regexp-in-string
7887 "BEGIN" "END" keyword
) "\n")))
7888 (t (insert "#+" keyword
" "))))
7890 (defun anything-c-org-keywords-show-help (keyword)
7891 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
7892 "(org)In-buffer settings"))
7893 (search-forward (concat "#+" keyword
) nil t
)
7894 (anything-persistent-highlight-point)
7895 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
7902 (defvar bbdb-records
)
7903 (defvar bbdb-buffer-name
)
7905 (defun anything-c-bbdb-candidates ()
7906 "Return a list of all names in the bbdb database. The format
7907 is \"Firstname Lastname\"."
7908 (mapcar (lambda (bbdb-record)
7909 (replace-regexp-in-string
7911 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
7914 (defun anything-c-bbdb-create-contact (actions candidate
)
7915 "Action transformer that returns only an entry to add the
7916 current `anything-pattern' as new contact. All other actions are
7918 (if (string= candidate
"*Add to contacts*")
7919 '(("Add to contacts" .
(lambda (actions)
7920 (bbdb-create-internal
7921 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
7922 (read-from-minibuffer "Company: ")
7923 (read-from-minibuffer "Email: ")
7926 (read-from-minibuffer "Note: ")))))
7929 (defun anything-c-bbdb-get-record (candidate)
7930 "Return record that match CANDIDATE."
7931 (bbdb candidate nil
)
7932 (set-buffer "*BBDB*")
7933 (bbdb-current-record))
7935 (defvar anything-c-bbdb-name nil
7936 "Only for internal use.")
7938 (defvar anything-c-source-bbdb
7940 (candidates . anything-c-bbdb-candidates
)
7941 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
7942 ("View person's data" . anything-c-bbdb-view-person-action
))
7943 (filtered-candidate-transformer .
(lambda (candidates source
)
7944 (setq anything-c-bbdb-name anything-pattern
)
7945 (if (not candidates
)
7946 (list "*Add to contacts*")
7948 (action-transformer .
(lambda (actions candidate
)
7949 (anything-c-bbdb-create-contact actions candidate
))))
7952 http://bbdb.sourceforge.net/")
7953 ;; (anything 'anything-c-source-bbdb)
7955 (defun anything-c-bbdb-view-person-action (candidate)
7956 "View BBDB data of single CANDIDATE or marked candidates."
7957 (anything-aif (anything-marked-candidates)
7958 (let ((bbdb-append-records (length it
)))
7960 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
7961 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
7963 (defun anything-c-bbdb-collect-mail-addresses ()
7964 "Return a list of all mail addresses of records in bbdb buffer."
7965 (with-current-buffer bbdb-buffer-name
7966 (loop for i in bbdb-records
7967 if
(bbdb-record-net (car i
))
7968 collect
(bbdb-dwim-net-address (car i
)))))
7970 (defun anything-c-bbdb-compose-mail (candidate)
7971 "Compose a mail with all records of bbdb buffer."
7972 (anything-c-bbdb-view-person-action candidate
)
7973 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7974 (address-str (mapconcat 'identity address-list
",\n ")))
7975 (compose-mail address-str
)))
7978 ;;; Evaluation Result
7982 (defvar anything-eldoc-active-minibuffers-list nil
)
7984 (defvar anything-c-source-evaluation-result
7985 '((name .
"Evaluation Result")
7989 (mode-line .
"C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
7990 (filtered-candidate-transformer .
(lambda (candidates source
)
7993 (with-anything-current-buffer
7995 (eval (read anything-pattern
))))
7997 (action .
(("Copy result to kill-ring" .
(lambda (candidate)
7998 (with-current-buffer anything-buffer
7999 (let ((end (save-excursion
8000 (goto-char (point-max))
8001 (search-backward "\n")
8003 (kill-region (point) end
)))))
8004 ("copy sexp to kill-ring" .
(lambda (candidate)
8005 (kill-new anything-input
)))))))
8006 ;; (anything 'anything-c-source-evaluation-result)
8008 (defun anything-eval-new-line-and-indent ()
8010 (newline) (lisp-indent-line))
8012 (defun anything-eldoc-store-minibuffer ()
8013 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8014 (with-selected-window (minibuffer-window)
8015 (push (buffer-name) anything-eldoc-active-minibuffers-list
)))
8017 (defun anything-eldoc-show-in-eval ()
8018 "Return eldoc in mode-line for current minibuffer input."
8019 (let ((buf (with-selected-window (minibuffer-window)
8021 (when (member buf anything-eldoc-active-minibuffers-list
)
8022 (let* ((str-all (with-current-buffer buf
8023 (minibuffer-completion-contents)))
8027 (goto-char (point-max))
8028 (unless (looking-back ")\\|\"") (forward-char -
1))
8029 (eldoc-current-symbol))))
8030 (info-fn (eldoc-fnsym-in-current-sexp))
8031 (doc (or (eldoc-get-var-docstring sym
)
8032 (eldoc-get-fnsym-args-string
8033 (car info-fn
) (cadr info-fn
)))))
8034 (when doc
(funcall anything-c-eldoc-in-minibuffer-show-fn doc
))))))
8036 (defun anything-c-eldoc-show-in-mode-line (str)
8037 "Show string STR in mode-line."
8038 (save-window-excursion
8039 (with-current-buffer anything-buffer
8040 (let ((mode-line-format (concat " " str
)))
8041 (force-mode-line-update)
8042 (sit-for anything-c-eldoc-show-in-mode-line-delay
))
8043 (force-mode-line-update))))
8045 ;;; Calculation Result
8048 (defvar anything-c-source-calculation-result
8049 '((name .
"Calculation Result")
8051 (filtered-candidate-transformer .
(lambda (candidates source
)
8054 (calc-eval anything-pattern
)
8056 (action ("Copy result to kill-ring" . kill-new
))))
8057 ;; (anything 'anything-c-source-calculation-result)
8060 ;;; Google Suggestions
8064 (defvar anything-ggs-max-length-real-flag
0)
8065 (defvar anything-ggs-max-length-num-flag
0)
8067 (defun anything-c-google-suggest-fetch (input)
8068 "Fetch suggestions for INPUT from XML buffer.
8069 Return an alist with elements like (data . number_results)."
8070 (setq anything-ggs-max-length-real-flag
0
8071 anything-ggs-max-length-num-flag
0)
8072 (let ((request (concat anything-c-google-suggest-url
8073 (url-hexify-string input
))))
8076 with result-alist
= (xml-get-children
8077 (car (xml-parse-region
8078 (point-min) (point-max)))
8079 'CompleteSuggestion
)
8080 for i in result-alist
8081 for data
= (cdr (caadr (assoc 'suggestion i
)))
8082 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
8083 for lqueries
= (length (anything-c-ggs-set-number-result
8085 for ldata
= (length data
)
8088 (when (> ldata anything-ggs-max-length-real-flag
)
8089 (setq anything-ggs-max-length-real-flag ldata
))
8090 (when (> lqueries anything-ggs-max-length-num-flag
)
8091 (setq anything-ggs-max-length-num-flag lqueries
)))
8092 collect
(cons data nqueries
) into cont
8093 finally return cont
)))
8094 (if anything-google-suggest-use-curl-p
8096 (call-process "curl" nil t nil request
)
8098 (with-current-buffer
8099 (url-retrieve-synchronously request
)
8102 (defun anything-c-google-suggest-set-candidates (&optional request-prefix
)
8103 "Set candidates with result and number of google results found."
8105 (loop with suggested-results
= (anything-c-google-suggest-fetch
8106 (or (and request-prefix
8107 (concat request-prefix
" " anything-pattern
))
8109 for
(real . numresult
) in suggested-results
8110 ;; Prepare number of results with ","
8111 for fnumresult
= (anything-c-ggs-set-number-result numresult
)
8112 ;; Calculate number of spaces to add before fnumresult
8113 ;; if it is smaller than longest result
8114 ;; `anything-ggs-max-length-num-flag'.
8117 ;; To be sure it is aligned properly.
8118 for nspaces
= (if (< (length fnumresult
) anything-ggs-max-length-num-flag
)
8119 (- anything-ggs-max-length-num-flag
(length fnumresult
))
8121 ;; Add now the spaces before fnumresult.
8122 for align-fnumresult
= (concat (make-string nspaces ?
) fnumresult
)
8123 for interval
= (- anything-ggs-max-length-real-flag
(length real
))
8124 for spaces
= (make-string (+ 2 interval
) ?
)
8125 for display
= (format "%s%s(%s results)" real spaces align-fnumresult
)
8126 collect
(cons display real
))))
8127 (if (loop for
(disp . dat
) in suggestions
8128 thereis
(equal dat anything-pattern
))
8130 ;; if there is no suggestion exactly matching the input then
8131 ;; prepend a Search on Google item to the list
8134 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
8135 anything-input
))))))
8137 (defun anything-c-ggs-set-number-result (num)
8140 (and (numberp num
) (setq num
(number-to-string num
)))
8141 (loop for i in
(reverse (split-string num
"" t
))
8143 append
(list i
) into C
8145 append
(list ",") into C
8146 and do
(setq count
0)
8148 (replace-regexp-in-string
8149 "^," "" (mapconcat 'identity
(reverse C
) ""))))
8152 (defvar anything-c-google-suggest-default-browser-function nil
8153 "*The browse url function you prefer to use with google suggest.
8154 When nil, use the first browser function available
8155 See `anything-browse-url-default-browser-alist'.")
8157 (defun anything-c-google-suggest-action (candidate)
8158 "Default action to jump to a google suggested candidate."
8159 (let ((arg (concat anything-c-google-suggest-search-url
8160 (url-hexify-string candidate
))))
8161 (anything-aif anything-c-google-suggest-default-browser-function
8163 (anything-c-browse-url arg
))))
8165 (defvar anything-c-google-suggest-default-function
8166 'anything-c-google-suggest-set-candidates
8167 "Default function to use in anything google suggest.")
8169 (defvar anything-c-source-google-suggest
8170 '((name .
"Google Suggest")
8171 (candidates .
(lambda ()
8172 (funcall anything-c-google-suggest-default-function
)))
8173 (action .
(("Google Search" . anything-c-google-suggest-action
)))
8175 (requires-pattern .
3)
8178 (defun anything-c-google-suggest-emacs-lisp ()
8179 "Try to emacs lisp complete with google suggestions."
8180 (anything-c-google-suggest-set-candidates "emacs lisp"))
8182 ;; (anything 'anything-c-source-google-suggest)
8184 ;;; Yahoo suggestions
8187 (defun anything-c-yahoo-suggest-fetch (input)
8188 "Fetch Yahoo suggestions for INPUT from XML buffer.
8189 Return an alist with elements like (data . number_results)."
8190 (let ((request (concat anything-c-yahoo-suggest-url
8191 (url-hexify-string input
))))
8194 with result-alist
= (xml-get-children
8195 (car (xml-parse-region (point-min) (point-max)))
8197 for i in result-alist
8198 collect
(caddr i
))))
8199 (with-current-buffer
8200 (url-retrieve-synchronously request
)
8203 (defun anything-c-yahoo-suggest-set-candidates ()
8204 "Set candidates with Yahoo results found."
8205 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
8209 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
8210 anything-input
))))))
8212 (defun anything-c-yahoo-suggest-action (candidate)
8213 "Default action to jump to a Yahoo suggested candidate."
8214 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8215 (url-hexify-string candidate
))))
8217 (defvar anything-c-source-yahoo-suggest
8218 '((name .
"Yahoo Suggest")
8219 (candidates . anything-c-yahoo-suggest-set-candidates
)
8220 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
8222 (requires-pattern .
3)
8225 ;; (anything 'anything-c-source-yahoo-suggest)
8228 ;;; Web browser functions.
8231 (require 'browse-url
)
8232 ;; If default setting of `w3m-command' is not
8233 ;; what you want you and you modify it, you will have to reeval
8234 ;; also `anything-browse-url-default-browser-alist'.
8235 (defvar w3m-command
"/usr/bin/w3m")
8236 (defvar anything-c-home-url
"http://www.google.fr"
8237 "*Default url to use as home url.")
8239 (defvar ac-browse-url-chromium-program
"chromium-browser")
8240 (defvar ac-browse-url-uzbl-program
"uzbl-browser")
8241 (defvar anything-browse-url-default-browser-alist
8242 `((,w3m-command . w3m-browse-url
)
8243 (,browse-url-firefox-program . browse-url-firefox
)
8244 (,ac-browse-url-chromium-program . ac-browse-url-chromium
)
8245 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl
)
8246 (,browse-url-kde-program . browse-url-kde
)
8247 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
8248 (,browse-url-mozilla-program . browse-url-mozilla
)
8249 (,browse-url-galeon-program . browse-url-galeon
)
8250 (,browse-url-netscape-program . browse-url-netscape
)
8251 (,browse-url-mosaic-program . browse-url-mosaic
)
8252 (,browse-url-xterm-program . browse-url-text-xterm
))
8253 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8255 (defun* anything-c-generic-browser
(url name
&rest args
)
8256 "Browse URL with NAME browser."
8257 (let ((proc (concat name
" " url
)))
8258 (message "Starting %s..." name
)
8259 (apply 'start-process proc nil name
8260 (append args
(list url
)))
8261 (set-process-sentinel
8263 #'(lambda (process event
)
8264 (when (string= event
"finished\n")
8265 (message "%s process %s" process event
))))))
8267 (defun ac-browse-url-chromium (url)
8268 "Browse URL with google chrome browser."
8269 (interactive "sURL: ")
8270 (anything-c-generic-browser
8271 url ac-browse-url-chromium-program
))
8273 (defun ac-browse-url-uzbl (url &optional ignore
)
8274 "Browse URL with uzbl browser."
8275 (interactive "sURL: ")
8276 (anything-c-generic-browser url ac-browse-url-uzbl-program
"-u"))
8278 (defun anything-browse-url-default-browser (url &rest args
)
8279 "Find the first available browser and ask it to load URL."
8280 (let ((default-browser-fn
8281 (loop for
(exe . fn
) in anything-browse-url-default-browser-alist
8282 thereis
(and exe
(executable-find exe
) fn
))))
8283 (if default-browser-fn
8284 (apply default-browser-fn url args
)
8285 (error "No usable browser found"))))
8287 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
8288 "Default command to browse URL."
8289 (if browse-url-browser-function
8291 (anything-browse-url-default-browser url
)))
8296 ;; Need external program surfraw.
8297 ;; <http://surfraw.alioth.debian.org/>
8299 (defvar anything-surfraw-default-browser-function nil
8300 "*The browse url function you prefer to use with surfraw.
8301 When nil, fallback to `browse-url-browser-function'.")
8304 (defvar anything-surfraw-engines-history nil
)
8306 (defun anything-c-build-elvi-list ()
8307 "Return list of all engines and descriptions handled by surfraw."
8310 (call-process "surfraw" nil t nil
8312 (split-string (buffer-string) "\n"))))
8318 (defun anything-emms-stream-edit-bookmark (elm)
8319 "Change the information of current emms-stream bookmark from anything."
8320 (declare (special emms-stream-list
))
8321 (let* ((cur-buf anything-current-buffer
)
8322 (bookmark (assoc elm emms-stream-list
))
8323 (name (read-from-minibuffer "Description: "
8325 (url (read-from-minibuffer "URL: "
8327 (fd (read-from-minibuffer "Feed Descriptor: "
8328 (int-to-string (nth 2 bookmark
))))
8329 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8330 (format "%s" (car (last bookmark
))))))
8333 (when (re-search-forward (concat "^" name
) nil t
)
8335 (emms-stream-delete-bookmark)
8336 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
8337 (emms-stream-save-bookmarks-file)
8339 (anything-c-switch-to-buffer cur-buf
)))))
8341 (defun anything-emms-stream-delete-bookmark (elm)
8342 "Delete an emms-stream bookmark from anything."
8343 (let* ((cur-buf anything-current-buffer
)
8344 (bookmark (assoc elm emms-stream-list
))
8345 (name (nth 0 bookmark
)))
8348 (when (re-search-forward (concat "^" name
) nil t
)
8350 (emms-stream-delete-bookmark)
8351 (emms-stream-save-bookmarks-file)
8353 (anything-c-switch-to-buffer cur-buf
)))))
8355 (defvar anything-c-source-emms-streams
8356 '((name .
"Emms Streams")
8358 (emms-stream-init)))
8359 (candidates .
(lambda ()
8360 (declare (special emms-stream-list
))
8361 (mapcar 'car emms-stream-list
)))
8362 (action .
(("Play" .
(lambda (elm)
8363 (declare (special emms-stream-list
))
8364 (let* ((stream (assoc elm emms-stream-list
))
8365 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
8366 (url (second stream
)))
8368 ("Delete" . anything-emms-stream-delete-bookmark
)
8369 ("Edit" . anything-emms-stream-edit-bookmark
)))
8370 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8371 ;; (anything 'anything-c-source-emms-streams)
8373 ;; Don't forget to set `emms-source-file-default-directory'
8374 (defvar anything-c-source-emms-dired
8375 '((name .
"Music Directory")
8376 (candidates .
(lambda ()
8377 (cddr (directory-files emms-source-file-default-directory
))))
8379 (("Play Directory" .
(lambda (item)
8380 (emms-play-directory
8383 emms-source-file-default-directory
))))
8384 ("Open dired in file's directory" .
(lambda (item)
8385 (anything-c-open-dired
8388 emms-source-file-default-directory
))))))
8389 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8390 ;; (anything 'anything-c-source-emms-dired)
8393 (defun anything-c-emms-files-modifier (candidates source
)
8394 (let ((current-playlist (with-current-emms-playlist
8396 with cur-list
= (emms-playlist-tracks-in-region
8397 (point-min) (point-max))
8399 collect
(assoc-default 'name i
)))))
8400 (loop for i in candidates
8401 if
(member (cdr i
) current-playlist
)
8402 collect
(cons (propertize (car i
)
8403 'face
'anything-emms-playlist
)
8405 else collect i into lis
8406 finally return lis
)))
8408 (defun anything-c-emms-play-current-playlist ()
8409 "Play current playlist."
8410 (with-current-emms-playlist
8411 (emms-playlist-first)
8412 (emms-playlist-mode-play-smart)))
8414 (defvar anything-c-source-emms-files
8415 '((name .
"Emms files")
8416 (candidates .
(lambda ()
8417 (loop for v being the hash-values in emms-cache-db
8418 for name
= (assoc-default 'name v
)
8419 for artist
= (or (assoc-default 'info-artist v
) "unknown")
8420 for genre
= (or (assoc-default 'info-genre v
) "unknown")
8421 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
8422 for song
= (or (assoc-default 'info-title v
) "unknown")
8423 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
8424 unless
(string-match "^http:" name
) collect
(cons info name
))))
8425 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
8426 (action .
(("Play file" . emms-play-file
)
8427 ("Add to Playlist and play (C-u clear current)"
8428 .
(lambda (candidate)
8429 (when anything-current-prefix-arg
8430 (emms-playlist-current-clear))
8432 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
8433 (unless emms-player-playing-p
8434 (anything-c-emms-play-current-playlist))))))))
8436 ;; (anything 'anything-c-source-emms-files)
8439 ;;; Jabber Contacts (jabber.el)
8440 (defun anything-c-jabber-online-contacts ()
8441 "List online Jabber contacts."
8444 (dolist (item (jabber-concat-rosters) jids
)
8445 (when (get item
'connected
)
8446 (push (if (get item
'name
)
8447 (cons (get item
'name
) item
)
8448 (cons (symbol-name item
) item
)) jids
))))))
8450 (defvar anything-c-source-jabber-contacts
8451 '((name .
"Jabber Contacts")
8452 (init .
(lambda () (require 'jabber
)))
8453 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
8454 (action .
(lambda (x)
8456 (jabber-read-account)
8458 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
8459 ;; (anything 'anything-c-source-jabber-contacts)
8464 (defvar anything-source-select-buffer
"*anything source select*")
8465 (defvar anything-c-source-call-source
8466 `((name .
"Call anything source")
8467 (candidate-number-limit)
8470 (loop for vname in
(all-completions "anything-c-source-" obarray
)
8471 for var
= (intern vname
)
8472 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
8474 (cons (format "%s `%s'"
8475 name
(propertize vname
'face
'font-lock-variable-name-face
))
8478 .
(("Invoke anything with selected source"
8481 (setq anything-candidate-number-limit
9999)
8482 (anything candidate nil nil nil nil
8483 anything-source-select-buffer
)))
8484 ("Describe variable" . describe-variable
)
8485 ("Find variable" . find-variable
)))
8486 (persistent-action . describe-variable
)
8487 (persistent-help .
"Show description of this source")))
8488 ;; (anything 'anything-c-source-call-source)
8490 (defun anything-call-source-from-anything ()
8491 "Call anything source within `anything' session."
8493 (setq anything-input-idle-delay
0)
8494 (anything-set-sources '(anything-c-source-call-source)))
8496 ;;; Execute Preconfigured anything.
8497 (defvar anything-c-source-anything-commands
8498 '((name .
"Preconfigured Anything")
8499 (candidates . anything-c-anything-commands-candidates
)
8501 (candidate-number-limit)))
8502 ;; (anything 'anything-c-source-anything-commands)
8504 (defun anything-c-anything-commands-candidates ()
8505 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
8506 collect
(cons (if (where-is-internal cmd nil t
)
8507 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
8508 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
8515 (defun anything-c-occur-init ()
8516 "Create the initial anything occur buffer.
8517 If region is active use region as buffer contents
8518 instead of whole buffer."
8519 (with-current-buffer (anything-candidate-buffer 'global
)
8522 (with-anything-current-buffer
8523 (if (anything-region-active-p)
8524 (buffer-substring (region-beginning) (region-end))
8525 (buffer-substring (point-min) (point-max))))))
8526 (insert buf-contents
))))
8528 (defun anything-c-occur-get-line (s e
)
8529 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
8531 (defun anything-c-occur-query-replace-regexp (candidate)
8532 "Query replace regexp starting from CANDIDATE.
8533 If region is active ignore CANDIDATE and replace only in region.
8534 With a prefix arg replace only matches surrounded by word boundaries,
8535 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8536 (let ((regexp anything-input
))
8537 (unless (anything-region-active-p)
8538 (anything-c-action-line-goto candidate
))
8539 (apply 'query-replace-regexp
8540 (anything-c-query-replace-args regexp
))))
8542 (defvar anything-c-source-occur
8544 (init . anything-c-occur-init
)
8545 (candidates-in-buffer)
8547 (get-line . anything-c-occur-get-line
)
8548 (display-to-real . anything-c-display-to-real-line
)
8549 (action .
(("Go to Line" . anything-c-action-line-goto
)
8550 ("Query replace regexp (C-u Not inside word.)"
8551 . anything-c-occur-query-replace-regexp
)))
8553 (requires-pattern .
1)
8556 ;; (anything 'anything-c-source-occur)
8559 ;;; Anything browse code.
8560 (defun anything-c-browse-code-get-line (beg end
)
8561 "Select line if it match the regexp corresponding to current `major-mode'.
8562 Line is parsed for BEG position to END position."
8563 (let ((str-line (buffer-substring beg end
))
8564 (regexp (assoc-default major-mode
8565 anything-c-browse-code-regexp-alist
))
8566 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
8567 (when (and regexp
(string-match regexp str-line
))
8568 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
8571 (defvar anything-c-source-browse-code
8572 '((name .
"Browse code")
8574 (anything-candidate-buffer anything-current-buffer
)
8575 (with-anything-current-buffer
8576 (jit-lock-fontify-now))))
8577 (candidate-number-limit .
9999)
8578 (candidates-in-buffer)
8579 (get-line . anything-c-browse-code-get-line
)
8584 ;; Do many actions for input
8585 (defvar anything-c-source-create
8589 (action-transformer . anything-create--actions
))
8590 "Do many create actions from `anything-pattern'.
8591 See also `anything-create--actions'.")
8592 ;; (anything 'anything-c-source-create)
8594 (defun anything-create-from-anything ()
8595 "Run `anything-create' from `anything' as a fallback."
8597 (anything-run-after-quit 'anything-create nil anything-pattern
))
8599 (defun anything-create--actions (&rest ignored
)
8600 "Default actions for `anything-create' / `anything-c-source-create'."
8602 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
8603 (append anything-create--actions-private
8604 '(("find-file" . find-file
)
8605 ("find-file other window" . find-file-other-window
)
8606 ("New buffer" . anything-c-switch-to-buffer
)
8607 ("New buffer other window" . switch-to-buffer-other-window
)
8608 ("Bookmark Set" . bookmark-set
)
8610 (lambda (x) (set-register (read-char "Register: ") x
)))
8611 ("Insert Linkd star" . linkd-insert-star
)
8612 ("Insert Linkd Tag" . linkd-insert-tag
)
8613 ("Insert Linkd Link" . linkd-insert-link
)
8614 ("Insert Linkd Lisp" . linkd-insert-lisp
)
8615 ("Insert Linkd Wiki" . linkd-insert-wiki
)
8616 ("Google Search" . google
)))))
8619 ;; Minibuffer History
8622 (defvar anything-c-source-minibuffer-history
8623 '((name .
"Minibuffer History")
8624 (header-name .
(lambda (name)
8625 (format "%s (%s)" name minibuffer-history-variable
)))
8628 (let ((history (loop
8629 for i in
(symbol-value minibuffer-history-variable
)
8630 unless
(string= "" i
) collect i
)))
8631 (if (consp (car history
))
8632 (mapcar 'prin1-to-string history
)
8636 ;; (anything 'anything-c-source-minibuffer-history)
8642 (defvar anything-c-source-elscreen
8643 '((name .
"Elscreen")
8644 (candidates .
(lambda ()
8645 (if (cdr (elscreen-get-screen-to-name-alist))
8647 (loop for sname in
(elscreen-get-screen-to-name-alist)
8648 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
8649 finally
(return lst
))
8650 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
8651 (action .
(("Change Screen".
8653 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
8656 (dolist (i (anything-marked-candidates))
8657 (elscreen-goto (- (aref i
1) (aref "0" 0)))
8661 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
8662 (elscreen-kill-others)))))))
8663 ;; (anything 'anything-c-source-elscreen)
8669 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
8670 "Top command (batch mode). %s is replaced with `frame-width'.")
8671 (defvar anything-c-source-top
8672 '((name .
"Top (Press C-c C-u to refresh)")
8673 (init . anything-c-top-init
)
8674 (candidates-in-buffer)
8675 (display-to-real . anything-c-top-display-to-real
)
8676 (update . anything-c-top-update
)
8677 (persistent-action . anything-c-top-sh-persistent-action
)
8678 (persistent-help .
"SIGTERM")
8680 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
8681 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
8682 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
8683 ;; (anything 'anything-c-source-top)
8685 (defun anything-c-top-sh (cmd)
8686 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
8688 (defun anything-c-top-sh-persistent-action (pid)
8689 (delete-other-windows)
8690 (anything-c-top-sh (format "kill -TERM %s" pid
))
8691 (anything-force-update))
8693 (defun anything-c-top-init ()
8694 (with-current-buffer (anything-candidate-buffer 'global
)
8695 (call-process-shell-command
8696 (format anything-c-top-command
8697 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
8698 nil
(current-buffer))))
8700 (defun anything-c-top-display-to-real (line)
8701 (car (split-string line
)))
8703 (defun anything-c-top-update ()
8704 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
8705 (anything-c-top-init)))
8708 (defvar anything-c-source-absolute-time-timers
8709 '((name .
"Absolute Time Timers")
8710 (candidates . timer-list
)
8712 ;; (anything 'anything-c-source-absolute-time-timers)
8714 (defvar anything-c-source-idle-time-timers
8715 '((name .
"Idle Time Timers")
8716 (candidates . timer-idle-list
)
8718 ;; (anything 'anything-c-source-idle-time-timers)
8720 (defun anything-c-timer-real-to-display (timer)
8721 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
8722 (append timer nil
) ;use `append' to convert vector->list
8723 (format "%s repeat=%5S %s(%s)"
8724 (let ((time (list t1 t2 t3
)))
8726 (format-time-string "idle-for=%5s" time
)
8727 (format-time-string "%m/%d %T" time
)))
8730 (mapconcat 'prin1-to-string args
" "))))
8732 ;;; X RandR resolution change
8733 ;;; FIXME I do not care multi-display.
8734 (defvar anything-c-xrandr-output
"VGA")
8735 (defvar anything-c-xrandr-screen
"0")
8736 (defvar anything-c-source-xrandr-change-resolution
8737 '((name .
"Change Resolution")
8741 (call-process "xrandr" nil
(current-buffer) nil
8742 "--screen" anything-c-xrandr-screen
"-q")
8744 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
8745 collect
(match-string 1)))))
8747 ("Change Resolution" .
(lambda (mode)
8748 (call-process "xrandr" nil nil nil
8749 "--screen" anything-c-xrandr-screen
8750 "--output" anything-c-xrandr-output
8752 ;; (anything 'anything-c-source-xrandr-change-resolution)
8757 (defun anything-c-persistent-xfont-action (elm)
8758 "Show current font temporarily"
8759 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
8762 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
8763 (set-frame-font current-font
))))
8765 (defvar anything-c-xfonts-cache nil
)
8766 (defvar anything-c-source-xfonts
8767 '((name .
"X Fonts")
8769 (unless anything-c-xfonts-cache
8770 (setq anything-c-xfonts-cache
8771 (x-list-fonts "*")))))
8772 (candidates . anything-c-xfonts-cache
)
8773 (action .
(("Copy to kill ring" .
(lambda (elm)
8775 ("Set Font" .
(lambda (elm)
8777 (set-frame-font elm
'keep-size
)
8778 (message "New font have been copied to kill ring")))))
8779 (persistent-action . anything-c-persistent-xfont-action
)
8780 (persistent-help .
"Switch to this font temporarily")))
8781 ;; (anything 'anything-c-source-xfonts)
8783 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8786 (defvar anything-c-ucs-max-len
0)
8787 (defun anything-c-calculate-ucs-max-len ()
8788 "Calculate the length of longest `ucs-names' candidate."
8789 (loop with count
= 0
8790 for
(n . v
) in
(ucs-names)
8791 for len
= (length n
)
8794 finally return count
))
8796 (defun anything-c-ucs-init ()
8797 "Initialize an anything buffer with ucs symbols.
8798 Only math* symbols are collected."
8799 (unless (> anything-c-ucs-max-len
0)
8800 (setq anything-c-ucs-max-len
8801 (anything-c-calculate-ucs-max-len)))
8802 (with-current-buffer (anything-candidate-buffer
8803 (get-buffer-create "*anything ucs*"))
8804 ;; `ucs-names' fn will not run again, data is cached in
8806 (loop for
(n . v
) in
(ucs-names)
8807 for len
= (length n
)
8808 for diff
= (+ (- anything-c-ucs-max-len len
) 2)
8809 unless
(string= "" n
)
8810 do
(progn (insert (concat
8817 (defun anything-c-ucs-forward-char (candidate)
8818 (with-anything-current-buffer
8821 (defun anything-c-ucs-backward-char (candidate)
8822 (with-anything-current-buffer
8825 (defun anything-c-ucs-delete-backward (candidate)
8826 (with-anything-current-buffer
8829 (defun anything-c-ucs-insert-char (candidate)
8830 (with-anything-current-buffer
8832 (replace-regexp-in-string
8834 (cadr (split-string candidate
":"))))))
8836 (defun anything-c-ucs-persistent-insert ()
8838 (anything-execute-persistent-action 'action-insert
))
8840 (defun anything-c-ucs-persistent-forward ()
8842 (anything-execute-persistent-action 'action-forward
))
8844 (defun anything-c-ucs-persistent-backward ()
8846 (anything-execute-persistent-action 'action-back
))
8848 (defun anything-c-ucs-persistent-delete ()
8850 (anything-execute-persistent-action 'action-delete
))
8852 (defvar anything-c-source-ucs
8853 '((name .
"Ucs names")
8854 (init . anything-c-ucs-init
)
8855 (candidate-number-limit .
9999)
8856 (candidates-in-buffer)
8857 (mode-line . anything-c-ucs-mode-line-string
)
8858 (action-insert . anything-c-ucs-insert-char
)
8859 (action-forward . anything-c-ucs-forward-char
)
8860 (action-back . anything-c-ucs-backward-char
)
8861 (action-delete . anything-c-ucs-delete-backward
)
8862 (action .
(("Insert" . anything-c-ucs-insert-char
)
8863 ("Forward char" . anything-c-ucs-forward-char
)
8864 ("Backward char" . anything-c-ucs-backward-char
)
8865 ("Delete char backward" . anything-c-ucs-delete-backward
))))
8866 "Source for collecting `ucs-names' math symbols.")
8872 (defvar anything-c-source-emacs-process
8873 '((name .
"Emacs Process")
8874 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
8875 (persistent-action .
(lambda (elm)
8876 (delete-process (get-process elm
))
8877 (anything-delete-current-selection)))
8878 (persistent-help .
"Kill Process")
8879 (action ("Kill Process" .
(lambda (elm)
8880 (delete-process (get-process elm
)))))))
8881 ;; (anything 'anything-c-source-emacs-process)
8886 (defvar anything-c-source-time-world
8887 '((name .
"Time World List")
8889 (let ((anything-buffer (anything-candidate-buffer 'global
)))
8890 (with-current-buffer anything-buffer
8891 (display-time-world-display display-time-world-list
)))))
8892 (candidates-in-buffer)))
8896 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8899 (defvar anything-c-source-apt
8901 (init . anything-c-apt-init
)
8902 (candidates-in-buffer)
8903 (candidate-transformer anything-c-apt-candidate-transformer
)
8904 (display-to-real . anything-c-apt-display-to-real
)
8905 (requires-pattern .
2)
8906 (update . anything-c-apt-refresh
)
8908 ("Show package description" . anything-c-apt-cache-show
)
8909 ("Install package" . anything-c-apt-install
)
8910 ("Remove package" . anything-c-apt-uninstall
)
8911 ("Purge package" . anything-c-apt-purge
))
8912 (persistent-action . anything-c-apt-persistent-action
)
8913 (persistent-help .
"Show package description")))
8914 ;; (anything 'anything-c-source-apt)
8916 (defvar anything-c-apt-query
"emacs")
8917 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
8918 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
8919 (defvar anything-c-apt-installed-packages nil
)
8920 (defvar anything-c-apt-all-packages nil
)
8923 (defun anything-c-apt-refresh ()
8924 "Refresh installed candidates list."
8925 (setq anything-c-apt-installed-packages nil
)
8926 (setq anything-c-apt-all-packages nil
))
8928 (defun anything-c-apt-persistent-action (candidate)
8929 "Persistent action for APT source."
8930 (anything-c-apt-cache-show candidate
))
8932 (defun anything-c-apt-candidate-transformer (candidates)
8933 "Show installed candidates in a different color."
8936 for cand in candidates
8937 for name
= (anything-c-apt-display-to-real cand
)
8938 if
(member name anything-c-apt-installed-packages
)
8939 collect
(propertize cand
'face
'anything-apt-installed
) into all
8940 else collect cand into all finally return all
))
8942 (defun anything-c-apt-init ()
8943 "Initialize list of debian packages."
8945 (unless (and anything-c-apt-installed-packages
8946 anything-c-apt-all-packages
)
8947 (message "Loading package list...")
8948 (setq anything-c-apt-installed-packages
8950 (call-process-shell-command "dpkg --get-selections"
8951 nil
(current-buffer))
8952 (loop for i in
(split-string (buffer-string) "\n" t
)
8953 collect
(car (split-string i
)))))
8954 (setq anything-c-apt-all-packages
8955 (with-current-buffer
8956 (anything-candidate-buffer
8957 (get-buffer-create (format "*anything-apt*")))
8959 (call-process-shell-command
8960 (format anything-c-apt-search-command query
)
8961 nil
(current-buffer))))
8962 (message "Loading package list done")
8965 (defun anything-c-apt-display-to-real (line)
8966 "Return only name of a debian package.
8967 LINE is displayed like:
8968 package name - description."
8969 (car (split-string line
" - ")))
8971 (defun anything-c-shell-command-if-needed (command)
8972 "Run shell command COMMAND to describe package.
8973 If a buffer named COMMAND already exists, just switch to it."
8974 (let ((buf (get-buffer command
)))
8975 (anything-c-switch-to-buffer (get-buffer-create command
))
8976 (unless buf
(insert (shell-command-to-string command
)))))
8978 (defun anything-c-apt-cache-show (package)
8979 "Show information on apt package PACKAGE."
8980 (anything-c-shell-command-if-needed
8981 (format anything-c-apt-show-command package
)))
8983 (defun anything-c-apt-install (package)
8984 "Run 'apt-get install' shell command on PACKAGE."
8985 (anything-c-apt-generic-action :action
'install
))
8987 (defun anything-c-apt-uninstall (package)
8988 "Run 'apt-get remove' shell command on PACKAGE."
8989 (anything-c-apt-generic-action :action
'uninstall
))
8991 (defun anything-c-apt-purge (package)
8992 "Run 'apt-get purge' shell command on PACKAGE."
8993 (anything-c-apt-generic-action :action
'purge
))
8995 (defun* anything-c-apt-generic-action
(&key action
)
8996 "Run 'apt-get ACTION'.
8997 Support install, remove and purge actions."
8998 (ansi-term (getenv "SHELL") "anything apt")
9000 (let ((command (case action
9001 ('install
"sudo apt-get install ")
9002 ('uninstall
"sudo apt-get remove ")
9003 ('purge
"sudo apt-get purge ")
9004 (t (error "Unknow action"))))
9007 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x
))
9008 (anything-marked-candidates) " ")))
9009 (goto-char (point-max))
9010 (insert (concat command cand-list
))
9012 (if (y-or-n-p (format "%s package" (symbol-name action
)))
9014 (setq anything-c-external-commands-list nil
)
9015 (setq anything-c-apt-installed-packages nil
)
9016 (term-char-mode) (term-send-input))
9017 (delete-region beg end
) (term-send-eof) (kill-buffer))))
9019 ;; (anything-c-apt-install "jed")
9022 ;;; Anything UI for gentoo portage.
9025 (defvar anything-c-gentoo-use-flags nil
)
9026 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
9027 (defvar anything-c-cache-gentoo nil
)
9028 (defvar anything-c-cache-world nil
)
9029 (defvar anything-c-source-gentoo
9030 '((name .
"Portage sources")
9032 (get-buffer-create anything-c-gentoo-buffer
)
9033 (unless anything-c-cache-gentoo
9034 (anything-c-gentoo-setup-cache))
9035 (unless anything-c-cache-world
9036 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
9037 (anything-c-gentoo-init-list)))
9038 (candidates-in-buffer)
9040 (candidate-transformer anything-c-highlight-world
)
9041 (action .
(("Show package" .
(lambda (elm)
9042 (anything-c-gentoo-eshell-action elm
"eix")))
9043 ("Show history" .
(lambda (elm)
9044 (if (member elm anything-c-cache-world
)
9045 (anything-c-gentoo-eshell-action elm
"genlop -qe")
9046 (message "No infos on packages not yet installed"))))
9047 ("Copy in kill-ring" . kill-new
)
9048 ("insert at point" . insert
)
9049 ("Browse HomePage" .
(lambda (elm)
9050 (let ((urls (anything-c-gentoo-get-url elm
)))
9051 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
9052 ("Show extra infos" .
(lambda (elm)
9053 (if (member elm anything-c-cache-world
)
9054 (anything-c-gentoo-eshell-action elm
"genlop -qi")
9055 (message "No infos on packages not yet installed"))))
9056 ("Show use flags" .
(lambda (elm)
9057 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
9058 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
9059 (font-lock-mode 1)))
9060 ("Run emerge pretend" .
(lambda (elm)
9061 (anything-c-gentoo-eshell-action elm
"emerge -p")))
9062 ("Emerge" .
(lambda (elm)
9063 (anything-gentoo-install elm
:action
'install
)))
9064 ("Unmerge" .
(lambda (elm)
9065 (anything-gentoo-install elm
:action
'uninstall
)))
9066 ("Show dependencies" .
(lambda (elm)
9067 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
9068 ("Show related files" .
(lambda (elm)
9069 (anything-c-gentoo-default-action elm
"equery" "files")))
9070 ("Refresh" .
(lambda (elm)
9071 (anything-c-gentoo-setup-cache)
9072 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
9074 ;; (anything 'anything-c-source-gentoo)
9076 (defun* anything-gentoo-install
(candidate &key action
)
9077 (setq anything-c-external-commands-list nil
)
9078 (ansi-term (getenv "SHELL") "Gentoo emerge")
9080 (let ((command (case action
9081 ('install
"sudo emerge -av ")
9082 ('uninstall
"sudo emerge -avC ")
9083 (t (error "Unknow action"))))
9084 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
9086 (goto-char (point-max))
9087 (insert (concat command elms
))
9089 (term-char-mode) (term-send-input)))
9091 (defun anything-c-gentoo-default-action (elm command
&rest args
)
9092 "Gentoo default action that use `anything-c-gentoo-buffer'."
9093 (if (member elm anything-c-cache-world
)
9095 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9097 (let ((com-list (append args
(list elm
))))
9098 (apply #'call-process command nil t nil
9100 (message "No infos on packages not yet installed")))
9102 (defvar anything-c-source-use-flags
9103 '((name .
"Use Flags")
9105 (unless anything-c-gentoo-use-flags
9106 (anything-c-gentoo-setup-use-flags-cache))
9107 (anything-c-gentoo-get-use)))
9108 (candidates-in-buffer)
9110 (candidate-transformer anything-c-highlight-local-use
)
9111 (action .
(("Description"
9113 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9115 (apply #'call-process
"euse" nil t nil
9118 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
9119 (font-lock-mode 1)))
9122 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
9125 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
9128 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
9129 ("Show which dep use this flag"
9131 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9133 (apply #'call-process
"equery" nil t nil
9139 ;; (anything 'anything-c-source-use-flags)
9141 (defun anything-c-gentoo-init-list ()
9142 "Initialize buffer with all packages in Portage."
9143 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9144 (buf (anything-candidate-buffer 'portage-buf
)))
9145 (with-current-buffer buf
9146 (dolist (i anything-c-cache-gentoo
)
9147 (insert (concat i
"\n"))))))
9149 (defun anything-c-gentoo-setup-cache ()
9150 "Set up `anything-c-cache-gentoo'"
9151 (setq anything-c-cache-gentoo
9152 (split-string (with-temp-buffer
9153 (call-process "eix" nil t nil
9157 (defun anything-c-gentoo-eshell-action (elm command
)
9158 (when (get-buffer "*EShell Command Output*")
9159 (kill-buffer "*EShell Command Output*"))
9160 (message "Wait searching...")
9161 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
9162 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
9164 (save-window-excursion
9165 (pop-to-buffer "*scratch*")
9166 (eshell-command (format "%s %s" command elm
)))
9167 (pop-to-buffer "*EShell Command Output*"))
9168 (eshell-command (format "%s %s" command elm
)))))
9170 (defun anything-c-gentoo-get-use ()
9171 "Initialize buffer with all use flags."
9172 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9173 (buf (anything-candidate-buffer 'use-buf
)))
9174 (with-current-buffer buf
9175 (dolist (i anything-c-gentoo-use-flags
)
9176 (insert (concat i
"\n"))))))
9179 (defun anything-c-gentoo-setup-use-flags-cache ()
9180 "Setup `anything-c-gentoo-use-flags'"
9181 (setq anything-c-gentoo-use-flags
9182 (split-string (with-temp-buffer
9183 (call-process "eix" nil t nil
9184 "--print-all-useflags")
9187 (defun anything-c-gentoo-get-url (elm)
9188 "Return a list of urls from eix output."
9190 with url-list
= (split-string
9192 (call-process "eix" nil t nil
9193 elm
"--format" "<homepage>\n")
9197 when
(and (string-match "^http://.*" i
)
9198 (not (member i all
)))
9200 finally return all
))
9202 (defun anything-c-gentoo-get-world ()
9203 "Return list of all installed package on your system."
9204 (split-string (with-temp-buffer
9205 (call-process "qlist" nil t nil
9209 (defun anything-c-gentoo-get-local-use ()
9210 (split-string (with-temp-buffer
9211 (call-process "portageq" nil t nil
9217 (defun anything-c-highlight-world (eix)
9218 "Highlight all installed package."
9220 if
(member i anything-c-cache-world
)
9221 collect
(propertize i
'face
'anything-gentoo-match-face
)
9225 (defun anything-c-highlight-local-use (use-flags)
9226 (let ((local-uses (anything-c-gentoo-get-local-use)))
9227 (loop for i in use-flags
9228 if
(member i local-uses
)
9229 collect
(propertize i
'face
'anything-gentoo-match-face
)
9235 ;;; Anything ratpoison UI
9238 (defvar anything-c-source-ratpoison-commands
9239 '((name .
"Ratpoison Commands")
9240 (init . anything-c-ratpoison-commands-init
)
9241 (candidates-in-buffer)
9242 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
9243 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
9244 (candidate-number-limit)))
9245 ;; (anything 'anything-c-source-ratpoison-commands)
9247 (defun anything-c-ratpoison-commands-init ()
9248 (unless (anything-candidate-buffer)
9249 (with-current-buffer (anything-candidate-buffer 'global
)
9250 ;; with ratpoison prefix key
9252 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
9253 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9254 (replace-match "<ratpoison> \\1: \\2"))
9255 (goto-char (point-max))
9258 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
9259 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9260 (replace-match "\\1: \\2")))))
9262 (defun anything-c-ratpoison-commands-display-to-real (display)
9263 (and (string-match ": " display
)
9264 (substring display
(match-end 0))))
9266 (defun anything-c-ratpoison-commands-execute (candidate)
9267 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
9271 ;;; Anything `completing-read' replacement
9274 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp
)
9275 "Convert COLLECTION to list removing elements that don't match TEST.
9276 See `anything-comp-read' about supported COLLECTION arguments.
9278 SORT-FN is a predicate to sort COLLECTION.
9280 ALISTP when non--nil will not use `all-completions' to collect
9281 candidates because it doesn't handle alists correctly for anything.
9282 i.e In `all-completions' the keys \(cars of elements\)
9283 are the possible completions. In anything we want to use the cdr instead
9284 like \(display . real\).
9285 See docstring of `all-completions' for more info.
9287 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9289 (cond ((and (eq collection obarray
) test
)
9290 (all-completions "" collection test
))
9291 ((and (vectorp collection
) test
)
9292 (loop for i across collection when
(funcall test i
) collect i
))
9293 ((vectorp collection
)
9294 (loop for i across collection collect i
))
9296 (loop for i in collection when
(funcall test i
) collect i
))
9297 ((and (symbolp collection
) (boundp collection
))
9298 (symbol-value collection
))
9300 ((and collection test
)
9301 (all-completions "" collection test
))
9302 (t (all-completions "" collection
)))))
9303 (if sort-fn
(sort cands sort-fn
) cands
)))
9305 (defun anything-cr-default-transformer (candidates source
)
9306 "Default filter candidate function for `anything-comp-read'.
9307 Do nothing, just return candidate list unmodified."
9310 (defun* anything-comp-read
(prompt collection
9316 (buffer "*Anything Completions*")
9318 (requires-pattern 0)
9320 (persistent-action nil
)
9321 (persistent-help "DoNothing")
9322 (name "Anything Completions")
9325 (fc-transformer 'anything-cr-default-transformer
)
9326 (marked-candidates nil
)
9328 "Anything `completing-read' emulation.
9329 PROMPT is the prompt name to use.
9330 COLLECTION can be a list, vector, obarray or hash-table.
9331 It can be also a function that receives three arguments:
9332 the values string, predicate and t. See `all-completions' for more details.
9336 TEST: A predicate called with one arg i.e candidate.
9337 INITIAL-INPUT: Same as initial-input arg in `anything'.
9338 PRESELECT: See preselect arg of `anything'.
9339 DEFAULT: This option is used only for compatibility with regular
9340 Emacs `completing-read'.
9341 BUFFER: Name of anything-buffer.
9342 MUST-MATCH: Candidate selected must be one of COLLECTION.
9343 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9344 HISTORY: A list containing specific history, default is nil.
9345 When it is non--nil, all elements of HISTORY are displayed in
9346 a special source before COLLECTION.
9347 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9348 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9349 NAME: The name related to this local source.
9350 VOLATILE: Use volatile attribute \(enabled by default\).
9351 SORT: A predicate to give to `sort' e.g `string-lessp'.
9352 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9353 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9354 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9356 Any prefix args passed during `anything-comp-read' invocation will be recorded
9357 in `anything-current-prefix-arg', otherwise if prefix args where given before
9358 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9359 That's mean you can pass prefix args before or after calling a command
9360 that use `anything-comp-read' See `anything-M-x' for example."
9361 (when (get-buffer anything-action-buffer
)
9362 (kill-buffer anything-action-buffer
))
9363 (flet ((action-fn (candidate)
9364 (if marked-candidates
9365 (anything-marked-candidates)
9366 (identity candidate
))))
9367 (let ((hist `((name .
,(format "%s History" name
))
9370 (let ((all (anything-comp-read-get-candidates
9371 history nil nil
,alistp
)))
9372 (anything-fast-remove-dups
9373 (if (and default
(not (string= default
"")))
9374 (delq nil
(cons default
(delete default all
)))
9377 (filtered-candidate-transformer
9378 .
(lambda (candidates sources
)
9379 (loop for i in candidates
9380 do
(set-text-properties 0 (length i
) nil i
)
9382 (persistent-action .
,persistent-action
)
9383 (persistent-help .
,persistent-help
)
9384 (action .
,'action-fn
)))
9385 (src `((name .
,name
)
9388 (let ((cands (anything-comp-read-get-candidates
9389 collection test sort alistp
)))
9390 (unless (or must-match
(string= anything-pattern
""))
9391 (setq cands
(append (list anything-pattern
) cands
)))
9392 (if (and default
(not (string= default
"")))
9393 (delq nil
(cons default
(delete default cands
)))
9395 (filtered-candidate-transformer ,fc-transformer
)
9396 (requires-pattern .
,requires-pattern
)
9397 (persistent-action .
,persistent-action
)
9398 (persistent-help .
,persistent-help
)
9399 (action .
,'action-fn
))))
9400 (when volatile
(setq src
(append src
'((volatile)))))
9402 :sources
`(,hist
,src
)
9403 :input initial-input
9405 :preselect preselect
9410 (unless must-match default
)
9413 ;; Generic completing-read
9415 ;; Support also function as collection.
9416 ;; e.g M-x man is supported.
9417 ;; Support hash-table and vectors as collection.
9419 ;; Some crap emacs functions may not be supported
9420 ;; like ffap-alternate-file (bad use of completing-read)
9421 ;; and maybe others.
9422 ;; Provide a mode `anything-completion-mode' which turn on
9423 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9425 (defvar anything-completion-mode-string
" AC")
9427 (defvar anything-completion-mode-quit-message
9428 "Anything completion disabled")
9430 (defvar anything-completion-mode-start-message
9431 "Anything completion enabled")
9433 ;;; Specialized handlers
9436 (defun anything-completing-read-symbols
9437 (prompt collection test require-match init
9438 hist default inherit-input-method name buffer
)
9439 "Specialized function for fast symbols completion in `ac-mode'."
9442 :sources
`((name .
,name
)
9444 (with-current-buffer (anything-candidate-buffer 'global
)
9445 (goto-char (point-min))
9446 (when (and default
(stringp default
)
9447 ;; Some defaults args result as
9448 ;; (symbol-name nil) == "nil".
9449 ;; e.g debug-on-entry.
9450 (not (string= default
"nil")))
9451 (insert (concat default
"\n")))
9452 (loop with all
= (all-completions "" collection test
)
9454 unless
(and default
(eq sym default
))
9455 do
(insert (concat sym
"\n"))))))
9456 (persistent-action . anything-lisp-completion-persistent-action
)
9457 (persistent-help .
"Show brief doc in mode-line")
9458 (candidates-in-buffer)
9459 (action . identity
))
9465 :default
(or default
""))
9469 ;;; Generic completing read
9472 (defun anything-completing-read-default-1
9473 (prompt collection test require-match
9474 init hist default inherit-input-method
9479 :fc-transformer
#'(lambda (candidates source
)
9480 ;; In regular `completing-read'
9481 ;; when a candidate is a cons cell
9482 ;; the car is used. Anything use
9483 ;; normally the cdr, so modify that
9484 ;; to fit `completing-read'.
9485 (loop for i in candidates
9486 for cand
= (if (consp i
) (car i
) i
)
9487 do
(set-text-properties 0 (length cand
) nil cand
)
9489 :history
(or (car-safe hist
) hist
)
9490 :must-match require-match
9494 ;; If DEF is not provided, fallback to empty string
9495 ;; to avoid `thing-at-point' to be appended on top of list
9496 :default
(or default
"")
9497 :initial-input init
))
9499 (defun* anything-completing-read-default
9500 (prompt collection
&optional
9501 predicate require-match
9502 initial-input hist def
9503 inherit-input-method
)
9504 "An anything replacement of `completing-read'.
9505 This function should be used only as a `completing-read-function'.
9507 Don't use it directly, use instead `anything-comp-read' in your programs \
9508 which is more powerful.
9510 See documentation of `completing-read' and `all-completions' for details."
9511 (declare (special anything-completion-mode
))
9512 (let* ((current-command this-command
)
9513 (str-command (symbol-name current-command
))
9514 (buf-name (format "*ac-mode-%s*" str-command
))
9515 (entry (assq current-command
9516 anything-completing-read-handlers-alist
))
9517 (def-com (cdr-safe entry
))
9518 (str-defcom (and def-com
(symbol-name def-com
)))
9519 (def-args (list prompt collection predicate require-match
9520 initial-input hist def inherit-input-method
))
9521 ;; Append the two extra args needed to set the buffer and source name
9522 ;; in anything specialized functions.
9523 (any-args (append def-args
(list str-command buf-name
)))
9524 anything-completion-mode-start-message
; Be quiet
9525 anything-completion-mode-quit-message
)
9526 (when (eq def-com
'ido
) (setq def-com
'ido-completing-read
))
9527 (unless (or (not entry
) def-com
)
9528 ;; An entry in *read-handlers-alist exists but have
9529 ;; a nil value, so we exit from here, disable `ac-mode'
9530 ;; and run the command again with it original behavior.
9531 ;; `ac-mode' will be restored on exit.
9532 (return-from anything-completing-read-default
9536 (call-interactively current-command
))
9538 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9539 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9540 (when (or (eq def-com
'completing-read
)
9541 ;; All specialized functions are prefixed by "anything"
9542 (and (stringp str-defcom
)
9543 (not (string-match "^anything" str-defcom
))))
9546 (cond (;; An anything specialized function exists, run it.
9547 (and def-com anything-completion-mode
)
9548 (apply def-com any-args
))
9549 (;; Try to handle `ido-completing-read' everywhere.
9550 (and def-com
(eq def-com
'ido-completing-read
))
9551 (setcar (memq collection def-args
)
9552 (all-completions "" collection predicate
))
9553 (apply def-com def-args
))
9554 (;; User set explicitely `completing-read' or something similar
9555 ;; in *read-handlers-alist, use this with exactly the same
9556 ;; args as in `completing-read'.
9557 ;; If we are here `anything-completion-mode' is now disabled.
9559 (apply def-com def-args
))
9560 (t ; Fall back to classic `anything-comp-read'.
9561 (anything-completing-read-default-1
9562 prompt collection predicate require-match
9563 initial-input hist def inherit-input-method
9564 str-command buf-name
)))
9566 ;; When exiting minibuffer, `this-command' is set to
9567 ;; `anything-exit-minibuffer', which is unwanted when starting
9568 ;; on another `completing-read', so restore `this-command' to
9569 ;; initial value when exiting.
9570 (setq this-command current-command
))))
9572 (defun* anything-generic-read-file-name
9573 (prompt &optional dir default-filename mustmatch initial predicate
)
9574 "An anything replacement of `read-file-name'."
9575 (declare (special anything-completion-mode
))
9576 (let* ((default (and default-filename
9577 (if (listp default-filename
)
9578 (car default-filename
)
9580 (init (or default initial dir default-directory
))
9581 (ini-input (and init
(expand-file-name init
)))
9582 (current-command this-command
)
9583 (str-command (symbol-name current-command
))
9584 (buf-name (format "*ac-mode-%s*" str-command
))
9585 (entry (assq current-command
9586 anything-completing-read-handlers-alist
))
9587 (def-com (cdr-safe entry
))
9588 (str-defcom (symbol-name def-com
))
9589 (def-args (list prompt dir default-filename mustmatch initial predicate
))
9590 ;; Append the two extra args needed to set the buffer and source name
9591 ;; in anything specialized functions.
9592 (any-args (append def-args
(list str-command buf-name
)))
9593 (ido-state ido-mode
)
9594 anything-completion-mode-start-message
; Be quiet
9595 anything-completion-mode-quit-message
; Same here
9597 (when (eq def-com
'ido
) (setq def-com
'ido-read-file-name
))
9598 (unless (or (not entry
) def-com
)
9599 (return-from anything-completing-read-default
9603 (call-interactively current-command
))
9605 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9606 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9607 (when (or (eq def-com
'read-file-name
)
9608 (eq def-com
'ido-read-file-name
)
9609 (and (stringp str-defcom
)
9610 (not (string-match "^anything" str-defcom
))))
9614 (cond (;; A specialized function exists, run it
9615 ;; with the two extra args specific to anything..
9616 (and def-com anything-completion-mode
9617 (not (eq def-com
'ido-read-file-name
)))
9618 (apply def-com any-args
))
9619 (;; Def-com value is `ido-read-file-name'
9620 ;; run it with default args.
9621 (and def-com
(eq def-com
'ido-read-file-name
))
9623 (apply def-com def-args
))
9624 (;; Def-com value is `read-file-name'
9625 ;; run it with default args.
9627 (apply def-com def-args
))
9628 (t ; Fall back to classic `anything-c-read-file-name'.
9629 (anything-c-read-file-name
9633 :initial-input
(expand-file-name init dir
)
9637 (ido-mode (if ido-state
1 -
1))
9638 ;; Same comment as in `anything-completing-read-default'.
9639 (setq this-command current-command
))
9640 (if (and mustmatch
(not (file-exists-p fname
)))
9641 (if (y-or-n-p "File does not exists, create buffer?")
9642 fname
(error "Abort file does not exists"))
9646 (define-minor-mode anything-completion-mode
9647 "Toggle generic anything completion.
9649 All functions in Emacs that use `completing-read'
9650 or `read-file-name' and friends will use anything interface
9651 when this mode is turned on.
9652 However you can modify this behavior for functions of your choice
9653 with `anything-completing-read-handlers-alist'.
9655 Called with a positive arg, turn on inconditionnaly, with a
9656 negative arg turn off.
9657 You can turn it on with `ac-mode'.
9659 Some crap emacs functions may not be supported,
9660 e.g `ffap-alternate-file' and maybe others
9661 You can add such functions to `anything-completing-read-handlers-alist'
9664 Note: This mode will work only partially on Emacs23."
9667 :lighter anything-completion-mode-string
9668 (declare (special completing-read-function
))
9669 (if anything-completion-mode
9671 (setq completing-read-function
'anything-completing-read-default
9672 read-file-name-function
'anything-generic-read-file-name
)
9673 (message anything-completion-mode-start-message
))
9674 (setq completing-read-function
(and (fboundp 'completing-read-default
)
9675 'completing-read-default
)
9676 read-file-name-function
(and (fboundp 'read-file-name-default
)
9677 'read-file-name-default
))
9678 (message anything-completion-mode-quit-message
)))
9680 (defalias 'ac-mode
'anything-completion-mode
)
9684 ;;; Eshell completion.
9686 ;; Enable like this in .emacs:
9688 ;; (add-hook 'eshell-mode-hook
9690 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9692 (defvar anything-c-source-esh
9693 '((name .
"Eshell completions")
9695 (setq pcomplete-current-completions nil
9696 pcomplete-last-completion-raw nil
)
9697 ;; Eshell-command add this hook in all minibuffers
9698 ;; Remove it for the anything one. (Fixed in Emacs24)
9699 (remove-hook 'minibuffer-setup-hook
'eshell-mode
)))
9700 (candidates . anything-esh-get-candidates
)
9701 (action . anything-ec-insert
))
9702 "Anything source for Eshell completion.")
9705 (defvar anything-ec-target
"")
9706 (defun anything-ec-insert (candidate)
9707 "Insert CANDIDATE at point.
9708 This is the same as `ac-insert', just inlined here for compatibility."
9710 (when (and anything-ec-target
9711 (search-backward anything-ec-target nil t
)
9712 (string= (buffer-substring (point) pt
) anything-ec-target
))
9713 (delete-region (point) pt
)))
9716 (defun anything-esh-get-candidates ()
9717 "Get candidates for eshell completion using `pcomplete'."
9719 (let* ((pcomplete-stub)
9720 pcomplete-seen pcomplete-norm-func
9721 pcomplete-args pcomplete-last pcomplete-index
9722 (pcomplete-autolist pcomplete-autolist
)
9723 (pcomplete-suffix-list pcomplete-suffix-list
))
9724 (with-anything-current-buffer
9726 with table
= (pcomplete-completions)
9727 with entry
= (condition-case nil
9729 (try-completion anything-pattern
(pcomplete-entries))
9730 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9733 (let ((fc (car (last (pcomplete-parse-arguments)))))
9734 ;; Check if last arg require fname completion.
9735 (and (file-name-directory fc
) fc
))))
9736 for i in
(if (listp table
) table
; Emacs23 or commands.
9737 (all-completions pcomplete-stub table
)) ; Emacs24
9738 for file-cand
= (and entry
9739 (if (file-remote-p i
) i
9740 (expand-file-name i
(file-name-directory entry
))))
9741 if
(and file-cand
(or (file-remote-p file-cand
) (file-exists-p file-cand
)))
9742 collect file-cand into ls
9743 else collect i into ls
9745 (if (and entry
(not (string= entry
"")) (file-exists-p entry
))
9746 (append (list (expand-file-name entry default-directory
)) ls
) ls
))))))
9751 (defvar anything-c-source-eshell-history
9752 '((name .
"Eshell history")
9754 (let (eshell-hist-ignoredups)
9755 ;; Dump the content's of hist file
9756 ;; to `eshell-history-ring'.
9757 (eshell-read-history eshell-history-file-name
)
9758 ;; And now write the content's of ring to file.
9759 (eshell-write-history eshell-history-file-name t
)
9760 (with-current-buffer (anything-candidate-buffer 'global
)
9761 (insert-file-contents eshell-history-file-name
)))
9762 ;; Same comment as in `anything-c-source-esh'
9763 (remove-hook 'minibuffer-setup-hook
'eshell-mode
)))
9764 (candidates-in-buffer)
9765 (filtered-candidate-transformer .
(lambda (candidates sources
)
9766 (reverse candidates
)))
9767 (candidate-number-limit .
9999)
9768 (action .
(lambda (candidate)
9770 (insert candidate
))))
9771 "Anything source for Eshell history.")
9774 ;;; Show completion - an alternative of anything-show-completion.el.
9776 ;; Provide show completion with macro `with-anything-show-completion'.
9779 ;; Called each time cursor move in anything-buffer.
9780 (defun anything-c-show-completion ()
9781 (with-anything-current-buffer
9782 (overlay-put anything-c-show-completion-overlay
9783 'display
(anything-get-selection))))
9785 (defun anything-c-show-completion-init-overlay (beg end
)
9786 (and anything-c-turn-on-show-completion
9787 (setq anything-c-show-completion-overlay
(make-overlay beg end
))
9788 (overlay-put anything-c-show-completion-overlay
9789 'face
'anything-lisp-show-completion
)))
9791 (defmacro with-anything-show-completion
(beg end
&rest body
)
9792 "Show anything candidate in an overlay at point.
9793 BEG and END are the beginning and end position of the current completion
9794 in `anything-current-buffer'.
9795 BODY is an anything call where we want to enable show completion.
9796 If `anything-c-turn-on-show-completion' is nil just do nothing."
9797 (declare (indent 2) (debug t
))
9798 `(let ((anything-move-selection-after-hook
9799 (and anything-c-turn-on-show-completion
9800 (append (list 'anything-c-show-completion
)
9801 anything-move-selection-after-hook
))))
9803 (progn (anything-c-show-completion-init-overlay ,beg
,end
)
9805 (and anything-c-turn-on-show-completion
9806 (delete-overlay anything-c-show-completion-overlay
)))))
9809 ;;; Lisp symbol completion.
9813 (defun anything-lisp-completion-at-point ()
9814 "Anything lisp symbol completion at point."
9816 (let* ((data (lisp-completion-at-point))
9818 (end (point)) ; 'cadr data' is wrong when no space after point.
9819 (plist (nthcdr 3 data
))
9820 (pred (plist-get plist
:predicate
))
9822 (target (and beg end
(buffer-substring-no-properties beg end
)))
9823 (candidates (all-completions target
(nth 2 data
) pred
))
9824 (anything-quit-if-no-candidate t
)
9825 (anything-execute-action-at-once-if-one t
)
9826 (anything-match-plugin-enabled
9827 (member 'anything-compile-source--match-plugin
9828 anything-compile-source-functions
)))
9830 (with-anything-show-completion beg end
9831 ;; Overlay is initialized now in anything-current-buffer.
9834 '((name .
"Lisp completion")
9836 (with-current-buffer (anything-candidate-buffer 'global
)
9837 (loop for sym in candidates
9838 for len
= (length sym
)
9839 when
(> len lgst-len
) do
(setq lgst-len len
)
9840 do
(insert (concat sym
"\n"))))))
9841 (candidates-in-buffer)
9842 (persistent-action . anything-lisp-completion-persistent-action
)
9843 (persistent-help .
"Show brief doc in mode-line")
9844 (filtered-candidate-transformer anything-lisp-completion-transformer
)
9845 (action .
(lambda (candidate)
9846 (delete-region beg end
)
9847 (insert candidate
))))
9848 :input
(if anything-match-plugin-enabled
(concat target
" ") target
)))
9849 (message "[No Match]"))))
9851 (defun anything-lisp-completion-persistent-action (candidate)
9852 (let ((cursor-in-echo-area t
)
9853 mode-line-in-non-selected-windows
)
9854 (anything-c-eldoc-show-in-mode-line
9856 (anything-c-get-first-line-documentation
9858 'face
'anything-lisp-completion-info
))))
9860 (defun anything-lisp-completion-transformer (candidates source
)
9861 "Anything candidates transformer for lisp completion."
9862 (declare (special lgst-len
))
9863 (loop for c in candidates
9864 for sym
= (intern c
)
9865 for annot
= (cond ((commandp sym
) " (Com)")
9866 ((fboundp sym
) " (Fun)")
9867 ((boundp sym
) " (Var)")
9868 ((facep sym
) " (Face)"))
9869 for spaces
= (make-string (- lgst-len
(length c
)) ?
)
9870 collect
(cons (concat c spaces annot
) c
)))
9872 (defun anything-c-get-first-line-documentation (sym)
9873 "Return first line documentation of symbol SYM.
9874 If SYM is not documented, return \"Not documented\"."
9875 (let ((doc (cond ((fboundp sym
)
9876 (documentation sym t
))
9878 (documentation-property sym
'variable-documentation t
))
9880 (face-documentation sym
))
9882 (if (and doc
(not (string= doc
""))
9883 ;; `documentation' return "\n\n(args...)"
9884 ;; for CL-style functions.
9885 (not (string-match-p "^\n\n" doc
)))
9886 (car (split-string doc
"\n"))
9889 ;;; File completion.
9891 ;; Complete file name at point.
9892 (defun anything-c-thing-before-point ()
9893 "Get symbol name before point.
9894 Borrowed from anything-complete.el, inlined here for compatibility."
9896 (let ((beg (point)))
9897 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9898 (when (re-search-backward
9899 "\\_<" (field-beginning nil nil
(point-at-bol)) t
)
9900 (buffer-substring-no-properties beg
(match-end 0))))))
9903 (defun anything-c-complete-file-name-at-point ()
9904 "Complete file name at point."
9906 (let* ((init (substring-no-properties (thing-at-point 'filename
)))
9908 (beg (- (point) (length init
)))
9909 (anything-quit-if-no-candidate t
)
9910 (anything-execute-action-at-once-if-one t
)
9912 (with-anything-show-completion beg end
9913 (setq completion
(anything-c-read-file-name "FileName: "
9914 :initial-input init
)))
9915 (anything-c-insert-file-name-completion-at-point completion
)))
9918 (defvar anything-lisp-completion-counter
0)
9920 (defun anything-lisp-completion-at-point-or-indent (arg)
9921 "First call indent and second call complete lisp symbol.
9922 The second call should happen before `anything-lisp-completion-or-indent-delay',
9923 after this delay, next call will indent again.
9924 After completion, next call is always indent.
9925 See that like click and double mouse click.
9926 One hit indent, two quick hits maybe indent and complete."
9928 ;; Be sure `indent-for-tab-command' will not try
9929 ;; to use `completion-at-point'.
9930 (let ((tab-always-indent (if (eq tab-always-indent
'complete
)
9931 t tab-always-indent
)))
9932 (incf anything-lisp-completion-counter
)
9934 (if (> anything-lisp-completion-counter
1)
9935 (anything-lisp-completion-or-file-name-at-point)
9936 (indent-for-tab-command arg
))
9937 ;; After `anything-lisp-completion-or-indent-delay' seconds
9939 (run-with-timer anything-lisp-completion-or-indent-delay nil
9941 (setq anything-lisp-completion-counter
0)))
9942 ;; Always reset to 0 at second hit.
9943 (when (eq anything-lisp-completion-counter
2)
9944 (setq anything-lisp-completion-counter
0)))))
9947 (defun anything-lisp-completion-or-file-name-at-point ()
9948 "Complete lisp symbol or filename at point.
9949 Filename completion happen if filename is started in
9950 or between double quotes."
9952 (let ((tap (substring-no-properties (thing-at-point 'filename
))))
9953 (if (and tap
(string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap
)
9954 (save-excursion (search-backward "\"" (point-at-bol) t
)))
9955 (anything-c-complete-file-name-at-point)
9956 (anything-lisp-completion-at-point))))
9958 (defun anything-c-apropos-init (test default
)
9959 "Init candidates buffer for `anything-c-apropos' sources."
9960 (with-current-buffer (anything-candidate-buffer 'global
)
9961 (goto-char (point-min))
9962 (when (and default
(stringp default
)
9963 ;; Some defaults args result as
9964 ;; (symbol-name nil) == "nil".
9965 ;; e.g debug-on-entry.
9966 (not (string= default
"nil"))
9967 (funcall test
(intern default
)))
9968 (insert (concat default
"\n")))
9969 (loop with all
= (all-completions "" obarray test
)
9971 unless
(and default
(eq sym default
))
9972 do
(insert (concat sym
"\n")))))
9975 ;;; Run Externals commands within Emacs with anything completion
9978 (defvar anything-external-command-history nil
)
9980 (defun anything-c-external-commands-list-1 (&optional sort
)
9981 "Returns a list of all external commands the user can execute.
9982 If `anything-c-external-commands-list' is non-nil it will
9983 return its contents. Else it calculates all external commands
9984 and sets `anything-c-external-commands-list'."
9985 (if anything-c-external-commands-list
9986 anything-c-external-commands-list
9987 (setq anything-c-external-commands-list
9989 with paths
= (split-string (getenv "PATH") path-separator
)
9990 with completions
= ()
9992 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
9993 for lsdir
= (loop for i in
(directory-files dir t
)
9994 for bn
= (file-name-nondirectory i
)
9995 when
(and (not (member bn completions
))
9996 (not (file-directory-p i
))
9997 (file-executable-p i
))
9999 append lsdir into completions
10000 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
10002 (defun anything-run-or-raise (exe &optional file
)
10003 "Generic command that run asynchronously EXE.
10004 If EXE is already running just jump to his window if `anything-raise-command'
10006 When FILE argument is provided run EXE with FILE.
10007 In this case EXE must be provided as \"EXE %s\"."
10008 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10010 (proc (if file
(concat real-com
" " file
) real-com
)))
10011 (if (get-process proc
)
10012 (if anything-raise-command
10013 (shell-command (format anything-raise-command real-com
))
10014 (error "Error: %s is already running" real-com
))
10015 (when (loop for i in anything-c-external-commands-list thereis real-com
)
10016 (message "Starting %s..." real-com
)
10018 (start-process-shell-command
10019 proc nil
(format exe
(shell-quote-argument file
)))
10020 (start-process-shell-command proc nil real-com
))
10021 (set-process-sentinel
10023 #'(lambda (process event
)
10024 (when (and (string= event
"finished\n")
10025 anything-raise-command
10026 (not (anything-c-get-pid-from-process-name real-com
)))
10027 (shell-command (format anything-raise-command
"emacs")))
10028 (message "%s process...Finished." process
))))
10029 (setq anything-c-external-commands-list
10031 (delete real-com anything-c-external-commands-list
))))))
10035 ;;; Generic action functions
10038 (defun anything-c-file-buffers (filename)
10039 "Returns a list of buffer names corresponding to FILENAME."
10040 (let ((name (expand-file-name filename
))
10042 (dolist (buf (buffer-list) buf-list
)
10043 (let ((bfn (buffer-file-name buf
)))
10044 (when (and bfn
(string= name bfn
))
10045 (push (buffer-name buf
) buf-list
))))))
10047 (defun anything-revert-buffer (candidate)
10048 (with-current-buffer candidate
10049 (when (or (buffer-modified-p)
10050 (not (verify-visited-file-modtime
10051 (get-buffer candidate
))))
10052 (revert-buffer t t
))))
10054 (defun anything-revert-marked-buffers (ignore)
10055 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
10057 (defun anything-kill-marked-buffers (ignore)
10058 (mapc 'kill-buffer
(anything-marked-candidates)))
10060 (defun anything-c-delete-file (file)
10061 "Delete the given file after querying the user.
10062 Ask to kill buffers associated with that file, too."
10063 (let ((buffers (anything-c-file-buffers file
)))
10064 (if (< emacs-major-version
24)
10065 ;; `dired-delete-file' in Emacs versions < 24
10066 ;; doesn't support delete-by-moving-to-trash
10067 ;; so use `delete-directory' and `delete-file'
10069 (cond ((and (not (file-symlink-p file
))
10070 (file-directory-p file
)
10071 (directory-files file t dired-re-no-dot
))
10072 (when (y-or-n-p (format "Recursive delete of `%s'? " file
))
10073 (delete-directory file
'recursive
)))
10074 ((and (not (file-symlink-p file
))
10075 (file-directory-p file
))
10076 (delete-directory file
))
10077 (t (delete-file file
)))
10079 file
'dired-recursive-deletes delete-by-moving-to-trash
))
10081 (dolist (buf buffers
)
10082 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
10083 (kill-buffer buf
))))))
10085 (defun anything-get-mailcap-for-file (filename)
10086 "Get the command to use for FILENAME from mailcap files.
10087 The command is like <command %s> and is meant to use with `format'."
10088 (mailcap-parse-mailcaps)
10089 (let* ((ext (file-name-extension filename
))
10090 (mime (when ext
(mailcap-extension-to-mime ext
)))
10091 (result (when mime
(mailcap-mime-info mime
))))
10092 ;; If elisp file have no associations in .mailcap
10093 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10094 (when (stringp result
) result
)))
10096 (defun anything-get-default-program-for-file (filename)
10097 "Try to find a default program to open FILENAME.
10098 Try first in `anything-c-external-programs-associations' and then in mailcap file
10099 if nothing found return nil."
10100 (let* ((ext (file-name-extension filename
))
10101 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
10102 (cond ((and def-prog
(not (string= def-prog
"")))
10103 (concat def-prog
" %s"))
10104 ((and anything-c-default-external-file-browser
10105 (file-directory-p filename
))
10106 (concat anything-c-default-external-file-browser
" %s"))
10107 (t (anything-get-mailcap-for-file filename
)))))
10109 (defun anything-c-open-file-externally (file)
10110 "Open FILE with an external program.
10111 Try to guess which program to use with `anything-get-default-program-for-file'.
10112 If not found or a prefix arg is given query the user which tool to use."
10113 (let* ((fname (expand-file-name file
))
10114 (collection (anything-c-external-commands-list-1 'sort
))
10115 (def-prog (anything-get-default-program-for-file fname
))
10116 (real-prog-name (if (or anything-current-prefix-arg
(not def-prog
))
10117 ;; Prefix arg or no default program.
10119 (anything-comp-read
10120 "Program: " collection
10122 :name
"Open file Externally"
10123 :history anything-external-command-history
)
10124 ;; Always prompt to set this program as default.
10125 (setq def-prog nil
))
10126 ;; No prefix arg or default program exists.
10127 (replace-regexp-in-string " %s\\| '%s'" "" def-prog
)))
10128 (program (concat real-prog-name
" %s")))
10129 (unless (or def-prog
; Association exists, no need to record it.
10130 ;; Don't try to record non--filenames associations (e.g urls).
10131 (not (file-exists-p fname
)))
10135 "Do you want to make `%s' the default program for this kind of files? "
10137 (anything-aif (assoc (file-name-extension fname
)
10138 anything-c-external-programs-associations
)
10139 (setq anything-c-external-programs-associations
10140 (delete it anything-c-external-programs-associations
)))
10141 (push (cons (file-name-extension fname
)
10143 "Program (Add args maybe and confirm): " real-prog-name
))
10144 anything-c-external-programs-associations
)
10145 (customize-save-variable 'anything-c-external-programs-associations
10146 anything-c-external-programs-associations
)))
10147 (anything-run-or-raise program file
)
10148 (setq anything-external-command-history
10149 (cons real-prog-name
10150 (delete real-prog-name
10151 (loop for i in anything-external-command-history
10152 when
(executable-find i
) collect i
))))))
10154 (defun anything-c-find-file-or-marked (candidate)
10155 "Open file CANDIDATE or open anything marked files in background."
10156 (let ((marked (anything-marked-candidates))
10157 (ffap-newfile-prompt anything-ff-newfile-prompt-p
)
10158 (find-file-wildcards nil
))
10159 (if (> (length marked
) 1)
10160 ;; Open all marked files in background and display
10162 (progn (mapc 'find-file-noselect
(cdr marked
))
10163 (find-file (car marked
)))
10164 (if (and (not (file-exists-p candidate
))
10165 (and ffap-url-regexp
10166 (not (string-match ffap-url-regexp candidate
)))
10167 (string-match "/$" candidate
))
10168 ;; A a non--existing filename ending with /
10169 ;; Create a directory and jump to it.
10170 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
10171 (let ((dirfname (directory-file-name candidate
)))
10172 (if (file-exists-p dirfname
)
10173 (error "Mkdir: Unable to create directory `%s': file exists."
10174 (anything-c-basename dirfname
))
10175 (make-directory candidate
'parent
)))
10176 (anything-find-files-1 candidate
))
10177 ;; A non--existing filename NOT ending with / or
10178 ;; an existing filename, create or jump to it.
10179 (find-file-at-point (car marked
))))))
10181 (defun anything-delete-marked-files (ignore)
10182 (let* ((files (anything-marked-candidates))
10183 (len (length files
)))
10185 (format "Delete *%s File(s):\n%s"
10187 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
10188 (message "(No deletions performed)")
10190 (set-text-properties 0 (length i
) nil i
)
10191 (anything-c-delete-file i
))
10192 (message "%s File(s) deleted" len
))))
10194 (defun anything-ediff-marked-buffers (candidate &optional merge
)
10195 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10196 With optional arg MERGE call `ediff-merge-buffers'."
10197 (let ((lg-lst (length (anything-marked-candidates)))
10201 (error "Error:You have to mark at least 1 buffer"))
10203 (setq buf1 anything-current-buffer
10204 buf2
(first (anything-marked-candidates))))
10206 (setq buf1
(first (anything-marked-candidates))
10207 buf2
(second (anything-marked-candidates))))
10209 (error "Error:To much buffers marked!")))
10211 (ediff-merge-buffers buf1 buf2
)
10212 (ediff-buffers buf1 buf2
))))
10214 (defun anything-ediff-marked-buffers-merge (candidate)
10215 "Ediff merge `anything-current-buffer' with CANDIDATE.
10216 See `anything-ediff-marked-buffers'."
10217 (anything-ediff-marked-buffers candidate t
))
10219 (defun anything-bookmark-get-bookmark-from-name (bmk)
10220 "Return bookmark name even if it is a bookmark with annotation.
10221 e.g prepended with *.
10222 Return nil if bmk is not a valid bookmark."
10223 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
10224 (if (assoc bookmark bookmark-alist
)
10226 (when (assoc bmk bookmark-alist
)
10229 (defun anything-delete-marked-bookmarks (ignore)
10230 "Delete this bookmark or all marked bookmarks."
10231 (dolist (i (anything-marked-candidates))
10232 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
10235 (defun anything-require-or-error (feature function
)
10236 (or (require feature nil t
)
10237 (error "Need %s to use `%s'." feature function
)))
10239 (defun anything-find-buffer-on-elscreen (candidate)
10240 "Open buffer in new screen, if marked buffers open all in elscreens."
10241 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
10242 (anything-aif (anything-marked-candidates)
10244 (let ((target-screen (elscreen-find-screen-by-buffer
10245 (get-buffer i
) 'create
)))
10246 (elscreen-goto target-screen
)))
10247 (let ((target-screen (elscreen-find-screen-by-buffer
10248 (get-buffer candidate
) 'create
)))
10249 (elscreen-goto target-screen
))))
10251 (defun anything-elscreen-find-file (file)
10252 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
10253 (elscreen-find-file file
))
10256 (defun w32-shell-execute-open-file (file)
10257 (interactive "fOpen file:")
10259 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10261 (replace-regexp-in-string ; strip cygdrive paths
10262 "/cygdrive/\\(.\\)" "\\1:"
10263 file nil nil
) nil t
))))
10265 (defun anything-c-open-file-with-default-tool (file)
10266 "Open FILE with the default tool on this platform."
10267 (if (eq system-type
'windows-nt
)
10268 (w32-shell-execute-open-file file
)
10269 (start-process "anything-c-open-file-with-default-tool"
10271 (cond ((eq system-type
'gnu
/linux
)
10273 ((or (eq system-type
'darwin
) ;; Mac OS X
10274 (eq system-type
'macos
)) ;; Mac OS 9
10278 (defun anything-c-open-dired (file)
10279 "Opens a dired buffer in FILE's directory. If FILE is a
10280 directory, open this directory."
10281 (if (file-directory-p file
)
10283 (dired (file-name-directory file
))
10284 (dired-goto-file file
)))
10286 (defun anything-c-display-to-real-line (candidate)
10287 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
10288 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
10289 (error "Line number not found")))
10291 (defun anything-c-action-line-goto (lineno-and-content)
10292 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
10293 (append lineno-and-content
10294 (list (if (and (anything-attr-defined 'target-file
)
10295 (not anything-in-persistent-action
))
10296 'find-file-other-window
10299 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
10300 (apply #'anything-goto-file-line
10301 (if (stringp file-line-content
)
10302 ;; Case: filtered-candidate-transformer is skipped
10303 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
10304 file-line-content
)))
10307 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
10308 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
10310 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10311 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
10312 (let ((filename (match-string 1 candidate
))
10313 (lineno (match-string 2 candidate
))
10314 (content (match-string 3 candidate
)))
10315 (cons (format "%s:%s\n %s"
10316 (propertize filename
'face compilation-info-face
)
10317 (propertize lineno
'face compilation-line-face
)
10319 (list (expand-file-name
10321 (or (anything-interpret-value (anything-attr 'default-directory
))
10322 (and (anything-candidate-buffer)
10323 (buffer-local-value
10324 'default-directory
(anything-candidate-buffer)))))
10325 (string-to-number lineno
) content
)))))
10327 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
10328 (anything-aif (anything-attr 'before-jump-hook
)
10330 (when file
(funcall find-file-function file
))
10331 (if (anything-attr-defined 'adjust
)
10332 (anything-c-goto-line-with-adjustment lineno content
)
10333 (anything-goto-line lineno
))
10334 (unless (anything-attr-defined 'recenter
)
10335 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
10336 (anything-aif (anything-attr 'after-jump-hook
)
10338 (when anything-in-persistent-action
10339 (anything-match-line-color-current-line)))
10341 (defun anything-find-file-as-root (candidate)
10342 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
10344 (defun anything-find-many-files (ignore)
10345 (mapc 'find-file
(anything-marked-candidates)))
10347 ;; borrowed from etags.el
10348 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10349 (defun anything-c-goto-line-with-adjustment (line line-content
)
10352 ;; This constant is 1/2 the initial search window.
10353 ;; There is no sense in making it too small,
10354 ;; since just going around the loop once probably
10355 ;; costs about as much as searching 2000 chars.
10358 pat
(concat (if (eq selective-display t
)
10359 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10360 (regexp-quote line-content
)))
10361 ;; If no char pos was given, try the given line number.
10362 (setq startpos
(progn (anything-goto-line line
) (point)))
10363 (or startpos
(setq startpos
(point-min)))
10364 ;; First see if the tag is right at the specified location.
10365 (goto-char startpos
)
10366 (setq found
(looking-at pat
))
10367 (while (and (not found
)
10369 (goto-char (- startpos offset
))
10372 (re-search-forward pat
(+ startpos offset
) t
)
10373 offset
(* 3 offset
))) ; expand search window
10375 (re-search-forward pat nil t
)
10376 (error "not found")))
10377 ;; Position point at the right place
10378 ;; if the search string matched an extra Ctrl-m at the beginning.
10379 (and (eq selective-display t
)
10382 (beginning-of-line))
10384 (anything-document-attribute 'default-directory
"type . file-line"
10385 "`default-directory' to interpret file.")
10386 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
10387 "Function to call before jumping to the target location.")
10388 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
10389 "Function to call after jumping to the target location.")
10390 (anything-document-attribute 'adjust
"type . file-line"
10391 "Search around line matching line contents.")
10392 (anything-document-attribute 'recenter
"type . file-line / line"
10393 "`recenter' after jumping.")
10394 (anything-document-attribute 'target-file
"type . line"
10395 "Goto line of target-file.")
10398 (defun anything-c-call-interactively (cmd-or-name)
10399 "Execute CMD-OR-NAME as Emacs command.
10400 It is added to `extended-command-history'.
10401 `anything-current-prefix-arg' is used as the command's prefix argument."
10402 (setq extended-command-history
10403 (cons (anything-c-stringify cmd-or-name
)
10404 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
10405 (let ((current-prefix-arg anything-current-prefix-arg
)
10406 (cmd (anything-c-symbolify cmd-or-name
)))
10407 (if (stringp (symbol-function cmd
))
10408 (execute-kbd-macro (symbol-function cmd
))
10409 (setq this-command cmd
)
10410 (call-interactively cmd
))))
10413 (defun anything-c-set-variable (var)
10414 "Set value to VAR interactively."
10416 (let ((sym (anything-c-symbolify var
)))
10417 (set sym
(eval-minibuffer (format "Set %s: " var
)
10418 (prin1-to-string (symbol-value sym
))))))
10420 ;; (anything-c-set-variable 'hh)
10424 ;;; Persistent Action Helpers
10427 (defvar anything-match-line-overlay-face nil
)
10428 (defvar anything-match-line-overlay nil
)
10430 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
10431 "Highlight and underline current position"
10432 (let ((args (list (or start
(line-beginning-position))
10433 (or end
(1+ (line-end-position)))
10435 (if (not anything-match-line-overlay
)
10436 (setq anything-match-line-overlay
(apply 'make-overlay args
))
10437 (apply 'move-overlay anything-match-line-overlay args
)))
10438 (overlay-put anything-match-line-overlay
10439 'face
(or face anything-match-line-overlay-face
))
10444 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
10447 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
10449 (defun anything-match-line-cleanup ()
10450 (when anything-match-line-overlay
10451 (delete-overlay anything-match-line-overlay
)
10452 (setq anything-match-line-overlay nil
)))
10454 (defun anything-match-line-update ()
10455 (when anything-match-line-overlay
10456 (delete-overlay anything-match-line-overlay
)
10457 (anything-match-line-color-current-line)))
10459 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
10460 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
10463 ;;; Actions Transformers
10467 (defun anything-c-transform-file-load-el (actions candidate
)
10468 "Add action to load the file CANDIDATE if it is an emacs lisp
10469 file. Else return ACTIONS unmodified."
10470 (if (member (file-name-extension candidate
) '("el" "elc"))
10471 (append actions
'(("Load Emacs Lisp File" . load-file
)))
10474 (defun anything-c-transform-file-browse-url (actions candidate
)
10475 "Add an action to browse the file CANDIDATE if it in a html
10476 file or URL. Else return ACTIONS unmodified."
10477 (let ((browse-action '("Browse with Browser" . browse-url
)))
10478 (cond ((string-match "^http\\|^ftp" candidate
)
10479 (cons browse-action actions
))
10480 ((string-match "\\.html?$" candidate
)
10481 (append actions
(list browse-action
)))
10485 (defun anything-c-transform-function-call-interactively (actions candidate
)
10486 "Add an action to call the function CANDIDATE interactively if
10487 it is a command. Else return ACTIONS unmodified."
10488 (if (commandp (intern-soft candidate
))
10489 (append actions
'(("Call Interactively"
10491 anything-c-call-interactively
)))
10495 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
10496 "If CANDIDATE's `car' is a command, then add an action to
10497 evaluate it and put it onto the `command-history'."
10498 (if (commandp (car (read candidate
)))
10499 ;; Make it first entry
10500 (cons '("Eval and put onto command-history" .
10502 (let ((sym (read sexp
)))
10504 (setq command-history
10505 (cons sym command-history
)))))
10510 ;;; Candidate Transformers
10514 (defun anything-c-skip-boring-buffers (buffers)
10515 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
10517 (defun anything-c-skip-current-buffer (buffers)
10518 (if anything-allow-skipping-current-buffer
10519 (remove (buffer-name anything-current-buffer
) buffers
)
10522 (defun anything-c-shadow-boring-buffers (buffers)
10523 "Buffers matching `anything-c-boring-buffer-regexp' will be
10524 displayed with the `file-name-shadow' face if available."
10525 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
10527 (defvar anything-c-buffer-display-string-functions
10528 '(anything-c-buffer-display-string--compilation
10529 anything-c-buffer-display-string--shell
10530 anything-c-buffer-display-string--eshell
)
10531 "Functions to setup display string for buffer.
10533 Function has one argument, buffer name.
10534 If it returns string, use it.
10535 If it returns nil, display buffer name.
10536 See `anything-c-buffer-display-string--compilation' for example.")
10538 (defun anything-c-transform-buffer-display-string (buffers)
10539 "Setup display string for buffer candidates
10540 using `anything-c-buffer-display-string-functions'."
10541 (loop for buf in buffers
10545 for disp
= (progn (set-buffer buf
)
10546 (run-hook-with-args-until-success
10547 'anything-c-buffer-display-string-functions buf
))
10548 collect
(if disp
(cons disp buf
) buf
)))
10550 (defun anything-c-buffer-display-string--compilation (buf)
10551 (anything-aif (car compilation-arguments
)
10552 (format "%s: %s [%s]" buf it default-directory
)))
10554 (defun anything-c-buffer-display-string--eshell (buf)
10555 (declare (special eshell-history-ring
))
10556 (when (eq major-mode
'eshell-mode
)
10557 (format "%s: %s [%s]" buf
10558 (ignore-errors (ring-ref eshell-history-ring
0))
10559 default-directory
)))
10561 (defun anything-c-buffer-display-string--shell (buf)
10562 (when (eq major-mode
'shell-mode
)
10563 (format "%s: %s [%s]" buf
10564 (ignore-errors (ring-ref comint-input-ring
0))
10565 default-directory
)))
10568 (defun anything-c-shadow-boring-files (files)
10569 "Files matching `anything-c-boring-file-regexp' will be
10570 displayed with the `file-name-shadow' face if available."
10571 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
10573 (defun anything-c-skip-boring-files (files)
10574 "Files matching `anything-c-boring-file-regexp' will be skipped."
10575 (anything-c-skip-entries files anything-c-boring-file-regexp
))
10576 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10578 (defun anything-c-skip-current-file (files)
10579 "Current file will be skipped."
10580 (remove (buffer-file-name anything-current-buffer
) files
))
10582 (defun anything-c-w32-pathname-transformer (args)
10583 "Change undesirable features of windows pathnames to ones more acceptable to
10584 other candidate transformers."
10585 (if (eq system-type
'windows-nt
)
10586 (mapcar (lambda (x)
10587 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
10588 (mapcar (lambda (y)
10589 (replace-regexp-in-string "\\\\" "/" y
)) args
))
10592 (defun anything-c-shorten-home-path (files)
10593 "Replaces /home/user with ~."
10594 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10596 (mapcar (lambda (file)
10597 (if (and (stringp file
) (string-match home file
))
10598 (cons (replace-match "~" nil nil file
) file
)
10603 (defun anything-c-mark-interactive-functions (functions)
10604 "Mark interactive functions (commands) with (i) after the function name."
10606 (loop for function in functions
10607 do
(push (cons (concat function
10608 (when (commandp (intern-soft function
)) " (i)"))
10611 finally
(return (nreverse list
)))))
10614 ;;; Adaptive Sorting of Candidates
10618 (defvar anything-c-adaptive-done nil
10619 "nil if history information is not yet stored for the current
10622 (defvar anything-c-adaptive-history nil
10623 "Contains the stored history information.
10624 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10626 (defadvice anything-initial-setup
(before anything-c-adaptive-initialize activate
)
10627 "Reset `anything-c-adaptive-done' when anything is started."
10628 (when anything-c-use-adaptative-sorting
10629 (setq anything-c-adaptive-done nil
)))
10631 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
10632 "Store history information when action is executed on selected candidate."
10633 (when anything-c-use-adaptative-sorting
10634 (anything-c-adaptive-store-selection)))
10636 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
10637 "Store history information when the user goes to the action buffer."
10638 (when anything-c-use-adaptative-sorting
10639 (anything-c-adaptive-store-selection)))
10641 (defun anything-c-source-use-adaptative-p (&optional source-name
)
10642 "Return current source only if it use adaptative history, nil otherwise."
10643 (when anything-c-use-adaptative-sorting
10644 (let* ((source (or source-name
(anything-get-current-source)))
10645 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10646 (assoc (assoc-default 'type source
)
10647 anything-type-attributes
))
10648 (assoc-default 'candidate-transformer
10649 (assoc (assoc-default 'type source
)
10650 anything-type-attributes
))
10651 (assoc-default 'filtered-candidate-transformer source
)
10652 (assoc-default 'candidate-transformer source
))))
10653 (if (listp adapt-source
)
10654 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
10655 (when (eq adapt-source
'anything-c-adaptive-sort
) source
)))))
10657 (defun anything-c-adaptive-store-selection ()
10658 "Store history information for the selected candidate."
10659 (unless anything-c-adaptive-done
10660 (setq anything-c-adaptive-done t
)
10661 (let ((source (anything-c-source-use-adaptative-p)))
10663 (let* ((source-name (or (assoc-default 'type source
)
10664 (assoc-default 'name source
)))
10665 (source-info (or (assoc source-name anything-c-adaptive-history
)
10667 (push (list source-name
) anything-c-adaptive-history
)
10668 (car anything-c-adaptive-history
))))
10669 (selection (anything-get-selection))
10670 (selection-info (progn
10671 (setcdr source-info
10673 (let ((found (assoc selection
(cdr source-info
))))
10678 ;; move entry to the beginning of the
10679 ;; list, so that it doesn't get
10680 ;; trimmed when the history is
10682 (setcdr source-info
10683 (delete found
(cdr source-info
)))
10685 (cdr source-info
)))
10686 (cadr source-info
)))
10687 (pattern-info (progn
10688 (setcdr selection-info
10690 (let ((found (assoc anything-pattern
(cdr selection-info
))))
10693 (cons anything-pattern
0)
10695 ;; move entry to the beginning of the
10696 ;; list, so if two patterns used the
10697 ;; same number of times then the one
10698 ;; used last appears first in the list
10699 (setcdr selection-info
10700 (delete found
(cdr selection-info
)))
10702 (cdr selection-info
)))
10703 (cadr selection-info
))))
10705 ;; increase usage count
10706 (setcdr pattern-info
(1+ (cdr pattern-info
)))
10708 ;; truncate history if needed
10709 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
10710 (setcdr selection-info
10711 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
10713 (defun anything-c-adaptative-maybe-load-history ()
10714 (when (and anything-c-use-adaptative-sorting
10715 (file-readable-p anything-c-adaptive-history-file
))
10716 (load-file anything-c-adaptive-history-file
)))
10718 (add-hook 'emacs-startup-hook
'anything-c-adaptative-maybe-load-history
)
10719 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
10721 (defun anything-c-adaptive-save-history (&optional arg
)
10722 "Save history information to file given by `anything-c-adaptive-history-file'."
10724 (when anything-c-use-adaptative-sorting
10727 ";; -*- mode: emacs-lisp -*-\n"
10728 ";; History entries used for anything adaptive display.\n")
10729 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
10732 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10733 (unless arg
'quiet
)))))
10735 (defun anything-c-adaptive-sort (candidates source
)
10736 "Sort the CANDIDATES for SOURCE by usage frequency.
10737 This is a filtered candidate transformer you can use for the
10738 attribute `filtered-candidate-transformer' of a source in
10739 `anything-sources' or a type in `anything-type-attributes'."
10740 (let* ((source-name (or (assoc-default 'type source
)
10741 (assoc-default 'name source
)))
10742 (source-info (assoc source-name anything-c-adaptive-history
)))
10745 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10747 (mapcar (lambda (candidate-info)
10749 (dolist (pattern-info (cdr candidate-info
))
10750 (if (not (equal (car pattern-info
)
10752 (incf count
(cdr pattern-info
))
10754 ;; if current pattern is equal to the previously
10755 ;; used one then this candidate has priority
10756 ;; (that's why its count is boosted by 10000) and
10757 ;; it only has to compete with other candidates
10758 ;; which were also selected with the same pattern
10759 (setq count
(+ 10000 (cdr pattern-info
)))
10761 (cons (car candidate-info
) count
)))
10762 (cdr source-info
)))
10764 (if (and usage
(consp usage
))
10765 ;; sort the list in descending order, so candidates with highest
10766 ;; priorty come first
10768 (setq usage
(sort usage
(lambda (first second
)
10769 (> (cdr first
) (cdr second
)))))
10771 ;; put those candidates first which have the highest usage count
10772 (dolist (info usage
)
10773 (when (member* (car info
) candidates
10774 :test
'anything-c-adaptive-compare
)
10775 (push (car info
) sorted
)
10776 (setq candidates
(remove* (car info
) candidates
10777 :test
'anything-c-adaptive-compare
))))
10779 ;; and append the rest
10780 (append (reverse sorted
) candidates nil
))
10781 (message "Your `%s' is maybe corrupted or too old, \
10782 you should reinitialize it with `anything-c-reset-adaptative-history'"
10783 anything-c-adaptive-history-file
)
10786 ;; if there is no information stored for this source then do nothing
10790 (defun anything-c-reset-adaptative-history ()
10791 "Delete all `anything-c-adaptive-history' and his file.
10792 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10794 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10795 (setq anything-c-adaptive-history nil
)
10796 (delete-file anything-c-adaptive-history-file
)))
10798 (defun anything-c-adaptive-compare (x y
)
10799 "Compare candidates X and Y taking into account that the
10800 candidate can be in (DISPLAY . REAL) format."
10801 (equal (if (listp x
)
10813 (defvar anything-outline-goto-near-line-flag t
)
10814 (defvar anything-outline-using nil
)
10815 (defun anything-after-update-hook--outline ()
10816 (if (and (eq anything-outline-using t
)
10817 (eq anything-outline-goto-near-line-flag t
))
10818 (anything-outline-goto-near-line)))
10819 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
10821 (defun anything-outline-goto-near-line ()
10822 (with-anything-window
10823 ;; TODO need consideration whether to update position by every input.
10824 (when t
; (equal anything-pattern "")
10825 (anything-goto-line 2)
10826 (let ((lineno (with-anything-current-buffer
10827 (line-number-at-pos (car anything-current-position
)))))
10829 (while (<= (progn (skip-chars-forward " ")
10830 (or (number-at-point) lineno
))
10835 (return-from exit
))))
10837 (and (bobp) (forward-line 1))
10838 (and (anything-pos-header-line-p) (forward-line -
2))
10839 (anything-mark-current-line)))))
10846 ;; Plug-in: info-index
10847 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
10849 (unless (anything-candidate-buffer)
10850 (save-window-excursion
10853 (tobuf (anything-candidate-buffer 'global
))
10854 (infobuf (current-buffer))
10856 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
10857 (Info-goto-node node
)
10858 (goto-char (point-min))
10859 (while (search-forward "\n* " nil t
)
10860 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
10861 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
10862 (setq s
(point-at-bol)
10864 (with-current-buffer tobuf
10865 (insert-buffer-substring infobuf s e
)
10866 (insert "\n"))))))))))
10868 (defun anything-c-info-goto (node-line)
10869 (Info-goto-node (car node-line
))
10870 (anything-goto-line (cdr node-line
)))
10872 (defun anything-c-info-display-to-real (line)
10874 ;; This regexp is stolen from Info-apropos-matches
10875 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
10876 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
10877 (string-to-number (or (match-string 3 line
) "1")))))
10879 (defun anything-c-make-info-source (source file
)
10881 (name .
,(concat "Info Index: " file
))
10882 (info-file .
,file
)
10883 (init . anything-c-info-init
)
10884 (display-to-real . anything-c-info-display-to-real
)
10885 (get-line . buffer-substring
)
10886 (candidates-in-buffer)
10887 (action ("Goto node" . anything-c-info-goto
))))
10889 (defun anything-compile-source--info-index (source)
10890 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
10891 (anything-c-make-info-source source it
)
10893 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
10895 (anything-document-attribute 'info-index
"info-index plugin"
10896 "Create a source of info index very easily.
10898 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10900 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
10901 "Index nodes of info file.
10903 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10904 Some info files are missing index specification.
10906 ex. See `anything-c-source-info-screen'.")
10908 ;; Plug-in: candidates-file
10909 (defun anything-compile-source--candidates-file (source)
10910 (if (assoc-default 'candidates-file source
)
10911 `((init anything-p-candidats-file-init
10912 ,@(let ((orig-init (assoc-default 'init source
)))
10913 (cond ((null orig-init
) nil
)
10914 ((functionp orig-init
) (list orig-init
))
10916 (candidates-in-buffer)
10919 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
10921 (defun anything-p-candidats-file-init ()
10922 (destructuring-bind (file &optional updating
)
10923 (anything-mklist (anything-attr 'candidates-file
))
10924 (setq file
(anything-interpret-value file
))
10925 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
10927 (buffer-disable-undo)
10928 (font-lock-mode -
1)
10929 (auto-revert-mode 1)))))
10931 (anything-document-attribute 'candidates-file
"candidates-file plugin"
10932 "Use a file as the candidates buffer.
10934 1st argument is a filename, string or function name or variable name.
10935 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
10937 ;; Plug-in: headline
10938 (defun anything-compile-source--anything-headline (source)
10939 (if (assoc-default 'headline source
)
10940 (append '((init . anything-headline-init
)
10941 (get-line . buffer-substring
)
10944 '((candidates-in-buffer)
10945 (persistent-help .
"Show this line")))
10947 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
10949 (defun anything-headline-init ()
10950 (when (and (anything-current-buffer-is-modified)
10951 (with-anything-current-buffer
10952 (eval (or (anything-attr 'condition
) t
))))
10953 (anything-headline-make-candidate-buffer
10954 (anything-interpret-value (anything-attr 'headline
))
10955 (anything-interpret-value (anything-attr 'subexp
)))))
10957 (anything-document-attribute 'headline
"Headline plug-in"
10958 "Regexp string for anything-headline to scan.")
10959 (anything-document-attribute 'condition
"Headline plug-in"
10960 "A sexp representing the condition to use anything-headline.")
10961 (anything-document-attribute 'subexp
"Headline plug-in"
10962 "Display (match-string-no-properties subexp).")
10964 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
10967 ;; 1. Create list of ((title . start-of-match) . hiearchy)
10968 ;; 2. Sort this list by start-of-match.
10969 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
10971 ;; It's quite brilliantly written.
10975 (defun anything-headline-get-candidates (regexp subexp
)
10976 (with-anything-current-buffer
10978 (goto-char (point-min))
10979 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
10980 (let (hierarchy curhead
)
10982 (if (numberp subexp
)
10983 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
10984 (cons (buffer-substring (point-at-bol) (point-at-eol))
10986 (hierarchies (headlines)
10987 (1+ (loop for
(_ . hierarchy
) in headlines
10988 maximize hierarchy
)))
10990 (loop for i from
0 to hierarchy
10991 collecting
(aref curhead i
)))
10992 (arrange (headlines)
10993 (unless (null headlines
) ; FIX headlines empty bug!
10994 (loop with curhead
= (make-vector (hierarchies headlines
) "")
10995 for
((str . pt
) . hierarchy
) in headlines
10996 do
(aset curhead hierarchy str
)
10999 (format "H%d:%s" (1+ hierarchy
)
11000 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
11005 (loop for re in regexp
11006 for hierarchy from
0
11007 do
(goto-char (point-min))
11010 while
(re-search-forward re nil t
)
11011 collect
(cons (matched) hierarchy
)))
11012 (lambda (a b
) (> (cdar b
) (cdar a
)))))
11013 (loop while
(re-search-forward regexp nil t
)
11014 collect
(matched))))))))
11017 (defun anything-headline-make-candidate-buffer (regexp subexp
)
11018 (with-current-buffer (anything-candidate-buffer 'local
)
11019 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
11022 (with-anything-current-buffer
11023 (line-number-at-pos pos
))
11026 (defun anything-headline-goto-position (pos recenter
)
11029 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
11032 ;; Plug-in: persistent-help
11033 (defun anything-compile-source--persistent-help (source)
11034 (append source
'((header-line . anything-persistent-help-string
))))
11035 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
11037 (defun anything-persistent-help-string ()
11038 (substitute-command-keys
11039 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11040 (or (anything-interpret-value (anything-attr 'persistent-help
))
11041 (anything-aif (or (assoc-default 'persistent-action
11042 (anything-get-current-source))
11043 (assoc-default 'action
11044 (anything-get-current-source)))
11045 (cond ((symbolp it
) (symbol-name it
))
11046 ((listp it
) (or (ignore-errors (caar it
)) ""))))
11048 " (keeping session)")))
11050 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
11051 "A string to explain persistent-action of this source.
11052 It also accepts a function or a variable name.")
11054 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11056 ;; Plug-in: Type customize
11057 (defun anything-c-uniq-list (lst)
11058 "Like `remove-duplicates' in CL.
11059 But cut deeper duplicates and test by `equal'. "
11060 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
11061 (defvar anything-additional-type-attributes nil
)
11062 (defun anything-c-arrange-type-attribute (type spec
)
11063 "Override type attributes by `define-anything-type-attribute'.
11065 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11067 Example: Set `play-sound-file' as default action
11068 (anything-c-arrange-type-attribute 'file
11069 '((action (\"Play sound\" . play-sound-file)
11070 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11073 (add-to-list 'anything-additional-type-attributes
11075 (loop with typeattr
= (assoc-default type anything-type-attributes
)
11076 for
(attr . value
) in spec
11079 (anything-c-uniq-list
11080 (loop for v in value
11082 append
(assoc-default attr typeattr
)
11086 collect
(cons attr value
)))))
11087 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
11089 (defun anything-compile-source--type-customize (source)
11090 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
11093 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
11095 ;; Plug-in: default-action
11096 (defun anything-compile-source--default-action (source)
11097 (anything-aif (assoc-default 'default-action source
)
11098 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
11101 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
11102 (anything-document-attribute 'default-action
"default-action plug-in"
11106 ;;; Toggle anything-match-plugin
11109 (defvar anything-mp-initial-highlight-delay nil
)
11112 (defun anything-c-toggle-match-plugin ()
11113 "Toggle anything-match-plugin."
11115 (let ((anything-match-plugin-enabled
11116 (member 'anything-compile-source--match-plugin
11117 anything-compile-source-functions
)))
11118 (flet ((disable-match-plugin ()
11119 (setq anything-compile-source-functions
11120 (delq 'anything-compile-source--match-plugin
11121 anything-compile-source-functions
))
11122 (setq anything-mp-initial-highlight-delay
11123 anything-mp-highlight-delay
)
11124 (setq anything-mp-highlight-delay nil
))
11125 (enable-match-plugin ()
11126 (require 'anything-match-plugin
)
11127 (unless anything-mp-initial-highlight-delay
11128 (setq anything-mp-initial-highlight-delay
11129 anything-mp-highlight-delay
))
11130 (setq anything-compile-source-functions
11131 (cons 'anything-compile-source--match-plugin
11132 anything-compile-source-functions
))
11133 (unless anything-mp-highlight-delay
11134 (setq anything-mp-highlight-delay
11135 anything-mp-initial-highlight-delay
))))
11136 (if anything-match-plugin-enabled
11137 (when (y-or-n-p "Really disable match-plugin? ")
11138 (disable-match-plugin)
11139 (message "Anything-match-plugin disabled"))
11140 (when (y-or-n-p "Really enable match-plugin? ")
11141 (enable-match-plugin)
11142 (message "Anything-match-plugin enabled"))))))
11146 ;;; Type Attributes
11149 (define-anything-type-attribute 'buffer
11151 ("Switch to buffer" . anything-c-switch-to-buffer
)
11152 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin
:popup-buffer
))
11153 ("Switch to buffer other window" . switch-to-buffer-other-window
)
11154 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)
11155 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
11156 ("Query replace regexp" . anything-c-buffer-query-replace-regexp
)
11157 ("Query replace" . anything-c-buffer-query-replace
)
11158 ("View buffer" . view-buffer
)
11159 ("Display buffer" . display-buffer
)
11160 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers
)
11161 ("Revert buffer(s)" . anything-revert-marked-buffers
)
11162 ("Insert buffer" . insert-buffer
)
11163 ("Kill buffer(s)" . anything-kill-marked-buffers
)
11164 ("Diff with file" . diff-buffer-with-file
)
11165 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
11166 ("Ediff Merge marked buffers" .
(lambda (candidate)
11167 (anything-ediff-marked-buffers candidate t
))))
11168 (persistent-help .
"Show this buffer")
11169 (candidate-transformer anything-c-skip-current-buffer
11170 anything-c-skip-boring-buffers
11171 anything-c-transform-buffer-display-string
))
11172 "Buffer or buffer name.")
11174 (define-anything-type-attribute 'file
11176 ("Find file" . anything-find-many-files
)
11177 ,(and (locate-library "popwin") '("Find file in popup window" . popwin
:find-file
))
11178 ("Find file as root" . anything-find-file-as-root
)
11179 ("Find file other window" . find-file-other-window
)
11180 ("Find file other frame" . find-file-other-frame
)
11181 ("Open dired in file's directory" . anything-c-open-dired
)
11182 ("Grep File(s) `C-u recurse'" . anything-find-files-grep
)
11183 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep
)
11184 ("Pdfgrep File(s)" . anything-ff-pdfgrep
)
11185 ("Checksum File" . anything-ff-checksum
)
11186 ("Ediff File" . anything-find-files-ediff-files
)
11187 ("Ediff Merge File" . anything-find-files-ediff-merge-files
)
11188 ("View file" . view-file
)
11189 ("Insert file" . insert-file
)
11190 ("Delete file(s)" . anything-delete-marked-files
)
11191 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
11192 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
11193 ("Find file in hex dump" . hexl-find-file
))
11194 (persistent-help .
"Show this file")
11195 (action-transformer anything-c-transform-file-load-el
11196 anything-c-transform-file-browse-url
)
11197 (candidate-transformer anything-c-w32-pathname-transformer
11198 anything-c-skip-current-file
11199 anything-c-skip-boring-files
11200 anything-c-shorten-home-path
))
11203 (let ((actions '(("Describe command" . describe-function
)
11204 ("Add command to kill ring" . anything-c-kill-new
)
11205 ("Go to command's definition" . find-function
)
11206 ("Debug on entry" . debug-on-entry
)
11207 ("Cancel debug on entry" . cancel-debug-on-entry
)
11208 ("Trace function" . trace-function
)
11209 ("Trace function (background)" . trace-function-background
)
11210 ("Untrace function" . untrace-function
))))
11211 (define-anything-type-attribute 'command
11212 `((action ("Call interactively" . anything-c-call-interactively
)
11214 ;; Sort commands according to their usage count.
11215 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11216 (coerce . anything-c-symbolify
)
11217 (persistent-action . describe-function
))
11218 "Command. (string or symbol)")
11220 (define-anything-type-attribute 'function
11221 `((action .
,actions
)
11222 (action-transformer anything-c-transform-function-call-interactively
)
11223 (candidate-transformer anything-c-mark-interactive-functions
)
11224 (coerce . anything-c-symbolify
))
11225 "Function. (string or symbol)"))
11227 (define-anything-type-attribute 'variable
11228 '((action ("Describe variable" . describe-variable
)
11229 ("Add variable to kill ring" . anything-c-kill-new
)
11230 ("Go to variable's definition" . find-variable
)
11231 ("Set variable" . anything-c-set-variable
))
11232 (coerce . anything-c-symbolify
))
11235 (define-anything-type-attribute 'sexp
11236 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
11237 ("Add s-expression to kill ring" . kill-new
))
11238 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
11239 "String representing S-Expressions.")
11241 (define-anything-type-attribute 'bookmark
11242 `((coerce . anything-bookmark-get-bookmark-from-name
)
11244 ("Jump to bookmark" .
(lambda (bookmark)
11245 (let ((current-prefix-arg anything-current-prefix-arg
))
11246 (bookmark-jump bookmark
))
11247 (anything-update)))
11248 ("Jump to BM other window" .
(lambda (bookmark)
11249 (bookmark-jump-other-window bookmark
)
11250 (anything-update)))
11251 ("Bookmark edit annotation" . bookmark-edit-annotation
)
11252 ("Bookmark show annotation" . bookmark-show-annotation
)
11253 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
11254 ,@(and (locate-library "bookmark-extensions")
11255 `(("Edit Bookmark" . bmkext-edit-bookmark
)))
11256 ("Rename bookmark" . bookmark-rename
)
11257 ("Relocate bookmark" . bookmark-relocate
)))
11260 (define-anything-type-attribute 'line
11261 '((display-to-real . anything-c-display-to-real-line
)
11262 (action ("Go to Line" . anything-c-action-line-goto
)))
11263 "LINENO:CONTENT string, eg. \" 16:foo\".
11265 Optional `target-file' attribute is a name of target file.
11267 Optional `before-jump-hook' attribute is a function with no
11268 arguments which is called before jumping to position.
11270 Optional `after-jump-hook' attribute is a function with no
11271 arguments which is called after jumping to position.
11273 If `adjust' attribute is specified, searches the line whose
11274 content is CONTENT near the LINENO.
11276 If `recenter' attribute is specified, the line is displayed at
11277 the center of window, otherwise at the top of window.
11280 (define-anything-type-attribute 'file-line
11281 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
11283 (action ("Go to" . anything-c-action-file-line-goto
)))
11284 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11286 Optional `default-directory' attribute is a default-directory
11287 FILENAME is interpreted.
11289 Optional `before-jump-hook' attribute is a function with no
11290 arguments which is called before jumping to position.
11292 Optional `after-jump-hook' attribute is a function with no
11293 arguments which is called after jumping to position.
11295 If `adjust' attribute is specified, searches the line whose
11296 content is CONTENT near the LINENO.
11298 If `recenter' attribute is specified, the line is displayed at
11299 the center of window, otherwise at the top of window.
11302 (define-anything-type-attribute 'timer
11303 '((real-to-display . anything-c-timer-real-to-display
)
11304 (action ("Cancel Timer" . cancel-timer
)
11305 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
11306 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
11307 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
11308 (persistent-help .
"Describe Function"))
11312 ;;; Default `anything-sources'
11313 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11314 ;; tend to invoke M-x anything directly. So I offer default setting.
11315 (setq anything-sources
11316 '(anything-c-source-buffers-list
11317 anything-c-source-recentf
11318 anything-c-source-files-in-current-dir
+))
11321 ;;; Preconfigured Anything
11325 (defun anything-mini ()
11326 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11328 (anything-other-buffer '(anything-c-source-buffers-list
11329 anything-c-source-recentf
11330 anything-c-source-buffer-not-found
)
11331 "*anything mini*"))
11333 (defun anything-for-files ()
11334 "Preconfigured `anything' for opening files.
11335 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11337 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
11340 (defun anything-recentf ()
11341 "Preconfigured `anything' for `recentf'."
11343 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
11346 (defun anything-info-at-point (arg)
11347 "Preconfigured `anything' for searching info at point.
11348 With a prefix-arg insert symbol at point."
11350 (let ((anything-c-google-suggest-default-function
11351 'anything-c-google-suggest-emacs-lisp
))
11352 (anything :sources
'(anything-c-source-info-elisp
11353 anything-c-source-info-cl
11354 anything-c-source-info-pages
11355 anything-c-source-google-suggest
)
11356 :input
(and arg
(thing-at-point 'symbol
))
11357 :buffer
"*anything info*")))
11360 (defun anything-info-emacs ()
11361 "Preconfigured anything for Emacs manual index."
11363 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
11366 (defun anything-show-kill-ring ()
11367 "Preconfigured `anything' for `kill-ring'.
11368 It is drop-in replacement of `yank-pop'.
11369 You may bind this command to M-y.
11370 First call open the kill-ring browser, next calls move to next line."
11372 (let ((buf "*anything kill-ring*"))
11373 (if (get-buffer-window buf
)
11374 (with-anything-window
11375 (if (eq (overlay-end anything-selection-overlay
) (point-max))
11376 (anything-beginning-of-buffer)
11377 (anything-next-line)))
11378 (anything-other-buffer 'anything-c-source-kill-ring buf
))))
11381 (defun anything-minibuffer-history ()
11382 "Preconfigured `anything' for `minibuffer-history'."
11384 (let ((enable-recursive-minibuffers t
))
11385 (anything-other-buffer 'anything-c-source-minibuffer-history
11386 "*anything minibuffer-history*")))
11389 (defun anything-gentoo ()
11390 "Preconfigured `anything' for gentoo linux."
11392 (anything-other-buffer '(anything-c-source-gentoo
11393 anything-c-source-use-flags
)
11394 "*anything gentoo*"))
11397 (defun anything-imenu ()
11398 "Preconfigured `anything' for `imenu'."
11400 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
11403 (defun anything-google-suggest ()
11404 "Preconfigured `anything' for google search with google suggest."
11406 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
11409 (defun anything-yahoo-suggest ()
11410 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11412 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
11414 ;;; Converted from anything-show-*-only
11416 (defun anything-for-buffers ()
11417 "Preconfigured `anything' for buffer."
11419 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
11422 (defun anything-buffers-list ()
11423 "Enhanced preconfigured `anything' for buffer."
11425 (anything :sources
'(anything-c-source-buffers-list
11426 anything-c-source-buffer-not-found
)
11427 :buffer
"*anything buffers*" :keymap anything-c-buffer-map
))
11430 (defun anything-bbdb ()
11431 "Preconfigured `anything' for BBDB.
11435 http://bbdb.sourceforge.net/"
11437 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
11440 (defun anything-locate (arg)
11441 "Preconfigured `anything' for Locate.
11442 Note: you can add locate options after entering pattern.
11443 See 'man locate' for valid options.
11445 You can specify a specific database with prefix argument ARG \(C-u\).
11446 Many databases can be used: navigate and mark them.
11447 See also `anything-locate-with-db'.
11449 To create a user specific db, use
11450 \"updatedb -l 0 -o db_path -U directory\".
11451 Where db_path is a filename matched by
11452 `anything-locate-db-file-regexp'."
11454 (anything-locate-1 arg
))
11457 (defun anything-w3m-bookmarks ()
11458 "Preconfigured `anything' for w3m bookmark.
11460 Needs w3m and emacs-w3m.
11462 http://w3m.sourceforge.net/
11463 http://emacs-w3m.namazu.org/"
11465 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11466 "*anything w3m bookmarks*"))
11469 (defun anything-firefox-bookmarks ()
11470 "Preconfigured `anything' for firefox bookmark.
11471 You will have to enable html bookmarks in firefox:
11472 open about:config in firefox and double click on this line to enable value \
11475 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11477 You should have now:
11479 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11481 After closing firefox, you will be able to browse you bookmarks.
11484 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11485 "*Anything Firefox*"))
11488 (defun anything-colors ()
11489 "Preconfigured `anything' for color."
11491 (anything-other-buffer
11492 '(anything-c-source-colors anything-c-source-customize-face
)
11493 "*anything colors*"))
11496 (defun anything-bookmarks ()
11497 "Preconfigured `anything' for bookmarks."
11499 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
11502 (defun anything-c-pp-bookmarks ()
11503 "Preconfigured `anything' for bookmarks (pretty-printed)."
11505 (anything-other-buffer '(anything-c-source-bookmarks-local
11506 anything-c-source-bookmarks-su
11507 anything-c-source-bookmarks-ssh
)
11508 "*anything pp bookmarks*"))
11511 (defun anything-c-insert-latex-math ()
11512 "Preconfigured anything for latex math symbols completion."
11514 (anything-other-buffer 'anything-c-source-latex-math
"*anything latex*"))
11517 (defun anything-register ()
11518 "Preconfigured `anything' for Emacs registers."
11520 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
11523 (defun anything-man-woman ()
11524 "Preconfigured `anything' for Man and Woman pages."
11526 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
11529 (defun anything-org-keywords ()
11530 "Preconfigured `anything' for org keywords."
11532 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
11535 (defun anything-emms ()
11536 "Preconfigured `anything' for emms sources."
11538 (anything '(anything-c-source-emms-streams
11539 anything-c-source-emms-files
11540 anything-c-source-emms-dired
)
11542 "*Anything Emms*"))
11545 (defun anything-eev-anchors ()
11546 "Preconfigured `anything' for eev anchors."
11548 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
11551 (defun anything-bm-list ()
11552 "Preconfigured `anything' for visible bookmarks.
11556 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11558 (let ((anything-outline-using t
))
11559 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
11562 (defun anything-timers ()
11563 "Preconfigured `anything' for timers."
11565 (anything-other-buffer '(anything-c-source-absolute-time-timers
11566 anything-c-source-idle-time-timers
)
11567 "*anything timers*"))
11570 (defun anything-list-emacs-process ()
11571 "Preconfigured `anything' for emacs process."
11573 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
11576 (defun anything-occur ()
11577 "Preconfigured Anything for Occur source.
11578 If region is active, search only in region,
11579 otherwise search in whole buffer."
11581 (let ((anything-compile-source-functions
11582 ;; rule out anything-match-plugin because the input is one regexp.
11583 (delq 'anything-compile-source--match-plugin
11584 (copy-sequence anything-compile-source-functions
))))
11585 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
11588 (defun anything-browse-code ()
11589 "Preconfigured anything to browse code."
11591 (anything-other-buffer 'anything-c-source-browse-code
"*Browse code*"))
11594 (defun anything-org-headlines ()
11595 "Preconfigured anything to show org headlines."
11597 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
11600 (defun anything-info-gnus ()
11601 "Preconfigured anything to browse Gnus Manual."
11603 (anything-other-buffer 'anything-c-source-info-gnus
"*info Gnus*"))
11606 (defun anything-regexp ()
11607 "Preconfigured anything to build regexps and run query-replace-regexp \
11611 (let ((anything-compile-source-functions
11612 ;; rule out anything-match-plugin because the input is one regexp.
11613 (delq 'anything-compile-source--match-plugin
11614 (copy-sequence anything-compile-source-functions
))))
11615 (when (and (anything-region-active-p)
11616 ;; Don't narrow to region if buffer is already narrowed.
11617 (not (anything-current-buffer-narrowed-p)))
11618 (narrow-to-region (region-beginning) (region-end)))
11620 anything-c-source-regexp
11621 :buffer
"*anything regexp*"
11622 :prompt
"Regexp: "))))
11624 (defun anything-c-copy-files-async ()
11625 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11627 (let* ((flist (anything-c-read-file-name
11628 "Copy File async: "
11629 :marked-candidates t
))
11630 (dest (anything-c-read-file-name
11631 "Copy File async To: "
11632 :preselect
(car flist
)
11633 :initial-input
(car anything-ff-history
)
11634 :history
(anything-find-files-history :comp-read nil
))))
11635 (anything-c-copy-async-with-log flist dest
)))
11638 (defun anything-find-files (arg)
11639 "Preconfigured `anything' for anything implementation of `find-file'.
11640 Called with a prefix arg show history if some.
11641 Don't call it from programs, use `anything-find-files-1' instead.
11642 This is the starting point for nearly all actions you can do on files."
11644 (let ((any-input (if (and arg anything-ff-history
)
11645 (anything-find-files-history)
11646 (anything-find-files-initial-input)))
11647 (presel (buffer-file-name (current-buffer))))
11648 (when (and (eq major-mode
'org-agenda-mode
)
11651 (setq any-input
(expand-file-name org-directory
)))
11652 (set-text-properties 0 (length any-input
) nil any-input
)
11654 (anything-find-files-1 any-input
)
11655 (setq any-input
(expand-file-name (anything-c-current-directory)))
11656 (anything-find-files-1
11657 any-input
(if anything-ff-transformer-show-only-basename
11658 (and presel
(anything-c-basename presel
))
11662 (defun anything-write-file ()
11663 "Preconfigured `anything' providing completion for `write-file'."
11665 (let ((anything-mp-highlight-delay nil
))
11666 (anything :sources
'anything-c-source-write-file
11667 :input
(expand-file-name default-directory
)
11668 :prompt
"Write buffer to file: "
11669 :buffer
"*Anything write file*")))
11672 (defun anything-insert-file ()
11673 "Preconfigured `anything' providing completion for `insert-file'."
11675 (let ((anything-mp-highlight-delay nil
))
11676 (anything :sources
'anything-c-source-insert-file
11677 :input
(expand-file-name default-directory
)
11678 :prompt
"Insert file: "
11679 :buffer
"*Anything insert file*")))
11682 (defun anything-dired-rename-file ()
11683 "Preconfigured `anything' to rename files from dired."
11685 (anything-dired-do-action-on-file :action
'rename
))
11688 (defun anything-dired-copy-file ()
11689 "Preconfigured `anything' to copy files from dired."
11691 (anything-dired-do-action-on-file :action
'copy
))
11694 (defun anything-dired-symlink-file ()
11695 "Preconfigured `anything' to symlink files from dired."
11697 (anything-dired-do-action-on-file :action
'symlink
))
11700 (defun anything-dired-hardlink-file ()
11701 "Preconfigured `anything' to hardlink files from dired."
11703 (anything-dired-do-action-on-file :action
'hardlink
))
11706 (defun anything-do-grep ()
11707 "Preconfigured anything for grep.
11708 Contrarily to Emacs `grep' no default directory is given, but
11709 the full path of candidates in ONLY.
11710 That allow to grep different files not only in `default-directory' but anywhere
11711 by marking them (C-<SPACE>). If one or more directory is selected
11712 grep will search in all files of these directories.
11713 You can use also wildcard in the base name of candidate.
11714 If a prefix arg is given use the -r option of grep.
11715 The prefix arg can be passed before or after start.
11716 See also `anything-do-grep-1'."
11718 (let ((only (anything-c-read-file-name
11719 "Search in file(s): "
11720 :marked-candidates t
11721 :preselect
(or (dired-get-filename nil t
)
11722 (buffer-file-name (current-buffer)))))
11723 (prefarg (or current-prefix-arg anything-current-prefix-arg
)))
11724 (anything-do-grep-1 only prefarg
)))
11727 (defun anything-do-zgrep (candidate)
11728 "Preconfigured anything for zgrep."
11729 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
11730 (ls (anything-c-read-file-name
11731 "Search in file(s): "
11732 :marked-candidates t
11733 :preselect
(or (dired-get-filename nil t
)
11734 (buffer-file-name (current-buffer))))))
11735 (anything-ff-zgrep-1 ls prefarg
)))
11737 (defun anything-c-etags-select (arg)
11738 "Preconfigured anything for etags.
11739 Called with one prefix arg use symbol at point as initial input.
11740 Called with two prefix arg reinitialize cache.
11741 If tag file have been modified reinitialize cache."
11743 (let ((tag (anything-c-etags-get-tag-file))
11744 (init (and (equal arg
'(4)) (thing-at-point 'symbol
)))
11745 (anything-quit-if-no-candidate t
)
11746 (anything-execute-action-at-once-if-one t
)
11747 (anything-compile-source-functions
11748 (if anything-c-etags-use-regexp-search
11749 ;; rule out anything-match-plugin because the input is one regexp.
11750 (delq 'anything-compile-source--match-plugin
11751 (copy-sequence anything-compile-source-functions
))
11752 anything-compile-source-functions
)))
11753 (when (or (equal arg
'(16))
11754 (and anything-c-etags-mtime-alist
11755 (anything-c-etags-file-modified-p tag
)))
11756 (remhash tag anything-c-etags-cache
))
11757 (if (and tag
(file-exists-p tag
))
11758 (anything :sources
'anything-c-source-etags-select
11759 :keymap anything-c-etags-map
11761 :buffer
"*anything etags*")
11762 (message "Error: No tag file found, please create one with etags shell command."))))
11765 (defun anything-filelist ()
11766 "Preconfigured `anything' to open files instantly.
11768 See `anything-c-filelist-file-name' docstring for usage."
11770 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
11773 (defun anything-filelist+ ()
11774 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11776 This is a replacement for `anything-for-files'.
11777 See `anything-c-filelist-file-name' docstring for usage."
11779 (anything-other-buffer
11780 '(anything-c-source-ffap-line
11781 anything-c-source-ffap-guesser
11782 anything-c-source-buffers-list
11783 anything-c-source-recentf
11784 anything-c-source-bookmarks
11785 anything-c-source-file-cache
11786 anything-c-source-filelist
)
11787 "*anything file list*"))
11790 (defun anything-M-x ()
11791 "Preconfigured `anything' for Emacs commands.
11792 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11796 anything-persistent-action-use-special-display
11797 (history (loop with hist
11798 for i in extended-command-history
11799 for com
= (intern i
)
11801 collect i into hist finally return hist
)))
11802 (flet ((pers-help (candidate)
11803 (let ((hbuf (get-buffer (help-buffer))))
11804 (if (and in-help
(string= candidate help-cand
))
11806 ;; When M-x is started from a help buffer,
11807 ;; Don't kill it as it is anything-current-buffer.
11808 (unless (equal hbuf anything-current-buffer
)
11809 (kill-buffer hbuf
))
11810 (setq in-help nil
))
11811 ;; Be sure anything-current-buffer
11812 ;; have not a dedicated window.
11813 (set-window-dedicated-p
11814 (get-buffer-window anything-current-buffer
) nil
)
11815 (describe-function (intern candidate
))
11816 (message nil
) ; Erase the new stupid message Type "q"[...]
11818 (setq help-cand candidate
))))
11823 '(((name .
"Emacs Commands history")
11824 (candidates . history
)
11825 (filtered-candidate-transformer
11826 .
(lambda (candidates sources
)
11827 (loop for i in candidates
11828 do
(set-text-properties 0 (length i
) nil i
)
11830 (persistent-action . pers-help
)
11831 (persistent-help .
"Describe this command")
11832 (action . identity
))
11833 ((name .
"Emacs Commands")
11836 (with-current-buffer (anything-candidate-buffer 'global
)
11837 (goto-char (point-min))
11839 for sym in
(all-completions "" obarray
'commandp
)
11840 do
(insert (concat sym
"\n"))))))
11841 (persistent-action . pers-help
)
11842 (persistent-help .
"Describe this command")
11843 (filtered-candidate-transformer . anything-M-x-transformer
)
11844 (candidates-in-buffer)
11845 (action . identity
)))
11846 :buffer
"*anything M-x*")
11848 (sym-com (intern command
)))
11849 (unless current-prefix-arg
11850 (setq current-prefix-arg anything-current-prefix-arg
))
11851 ;; Avoid having `this-command' set to *exit-minibuffer.
11852 (setq this-command sym-com
)
11853 (call-interactively sym-com
)
11854 (setq extended-command-history
11855 (cons command
(delete command history
)))))))
11858 (defun anything-manage-advice ()
11859 "Preconfigured `anything' to disable/enable function advices."
11861 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
11864 (defun anything-bookmark-ext ()
11865 "Preconfigured `anything' for bookmark-extensions sources.
11866 Needs bookmark-ext.el:
11867 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11868 Contain also `anything-c-source-google-suggest'."
11872 '(anything-c-source-bookmark-files&dirs
11873 anything-c-source-bookmark-w3m
11874 anything-c-source-google-suggest
11875 anything-c-source-bmkext-addressbook
11876 anything-c-source-bookmark-gnus
11877 anything-c-source-bookmark-info
11878 anything-c-source-bookmark-man
11879 anything-c-source-bookmark-images
11880 anything-c-source-bookmark-su-files
&dirs
11881 anything-c-source-bookmark-ssh-files
&dirs
)
11882 :prompt
"SearchBookmark: "
11883 :buffer
"*anything bmkext*"))
11886 (defun anything-simple-call-tree ()
11887 "Preconfigured `anything' for simple-call-tree. List function relationships.
11889 Needs simple-call-tree.el.
11890 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11892 (anything-other-buffer
11893 '(anything-c-source-simple-call-tree-functions-callers
11894 anything-c-source-simple-call-tree-callers-functions
)
11895 "*anything simple-call-tree*"))
11898 (defun anything-mark-ring ()
11899 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11901 (anything 'anything-c-source-mark-ring
))
11904 (defun anything-global-mark-ring ()
11905 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
11907 (anything 'anything-c-source-global-mark-ring
))
11910 (defun anything-all-mark-rings ()
11911 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
11912 `anything-c-source-mark-ring'."
11914 (anything '(anything-c-source-mark-ring
11915 anything-c-source-global-mark-ring
)))
11918 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
11919 "Preconfigured `anything' to edit or view EmacsWiki page.
11921 Needs yaoddmuse.el.
11923 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11925 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
11928 (defun anything-yaoddmuse-emacswiki-post-library ()
11929 "Preconfigured `anything' to post library to EmacsWiki.
11931 Needs yaoddmuse.el.
11933 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11935 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
11938 (defun anything-eval-expression (arg)
11939 "Preconfigured anything for `anything-c-source-evaluation-result'."
11941 (anything :sources
'anything-c-source-evaluation-result
11942 :input
(when arg
(thing-at-point 'sexp
))
11943 :buffer
"*anything eval*"
11944 :keymap anything-eval-expression-map
))
11947 (defun anything-eval-expression-with-eldoc ()
11948 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
11950 (declare (special eldoc-idle-delay
))
11951 (let ((timer (run-with-idle-timer eldoc-idle-delay
11952 'repeat
'anything-eldoc-show-in-eval
))
11953 (minibuffer-completing-symbol t
) ; Enable lisp completion.
11954 (completion-cycle-threshold t
)) ; Always cycle, no pesty completion buffer (emacs24 only).
11956 (minibuffer-with-setup-hook
11957 'anything-eldoc-store-minibuffer
11958 (call-interactively 'anything-eval-expression
))
11959 (and timer
(cancel-timer timer
))
11960 (setq anything-eldoc-active-minibuffers-list
11961 (cdr anything-eldoc-active-minibuffers-list
)))))
11964 (defun anything-calcul-expression ()
11965 "Preconfigured anything for `anything-c-source-calculation-result'."
11967 (anything-other-buffer 'anything-c-source-calculation-result
"*anything calcul*"))
11970 (defun anything-surfraw (pattern engine
)
11971 "Preconfigured `anything' to search PATTERN with search ENGINE."
11972 (interactive (list (read-string "SearchFor: ")
11973 (anything-comp-read
11975 (anything-c-build-elvi-list)
11977 :name
"Surfraw Search Engines"
11978 :history anything-surfraw-engines-history
)))
11979 (let* ((engine-nodesc (car (split-string engine
)))
11980 (url (with-temp-buffer
11981 (apply 'call-process
"surfraw" nil t nil
11983 (append (list engine-nodesc
"-p") (split-string pattern
)))
11984 (replace-regexp-in-string
11985 "\n" "" (buffer-string))))
11986 (browse-url-browser-function (or anything-surfraw-default-browser-function
11987 browse-url-browser-function
)))
11988 (if (string= engine-nodesc
"W")
11989 (anything-c-browse-url)
11990 (anything-c-browse-url url
)
11991 (setq anything-surfraw-engines-history
11992 (cons engine
(delete engine anything-surfraw-engines-history
))))))
11995 (defun anything-call-source ()
11996 "Preconfigured `anything' to call anything source."
11998 (anything 'anything-c-source-call-source nil nil nil nil
11999 anything-source-select-buffer
))
12002 (defun anything-execute-anything-command ()
12003 "Preconfigured `anything' to execute preconfigured `anything'."
12005 (anything-other-buffer 'anything-c-source-anything-commands
12006 "*anything commands*"))
12009 (defun anything-create (&optional string initial-input
)
12010 "Preconfigured `anything' to do many create actions from STRING.
12011 See also `anything-create--actions'."
12013 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
12014 (anything '(((name .
"Anything Create")
12015 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
12016 (candidates . anything-create--actions
)
12017 (candidate-number-limit)
12018 (action .
(lambda (func) (funcall func string
)))))))
12021 (defun anything-top ()
12022 "Preconfigured `anything' for top command."
12024 (let ((anything-samewindow t
)
12025 (anything-enable-shortcuts)
12026 (anything-display-function 'anything-default-display-buffer
)
12027 (anything-candidate-number-limit 9999))
12028 (save-window-excursion
12029 (delete-other-windows)
12030 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
12033 (defun anything-select-xfont ()
12034 "Preconfigured `anything' to select Xfont."
12036 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
12039 (defun anything-world-time ()
12040 "Preconfigured `anything' to show world time."
12042 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
12045 (defun anything-apt (arg query
)
12046 "Preconfigured `anything' : frontend of APT package manager.
12047 With a prefix arg reload cache."
12048 (interactive "P\nsSearch Package: ")
12050 (setq anything-c-apt-installed-packages nil
)
12051 (setq anything-c-apt-all-packages nil
))
12052 (anything :sources
'anything-c-source-apt
12053 :prompt
"Search Package: " :input query
))
12056 (defun anything-esh-pcomplete ()
12057 "Preconfigured anything to provide anything completion in eshell."
12059 (let* ((anything-quit-if-no-candidate t
)
12060 (anything-execute-action-at-once-if-one t
)
12061 (target (thing-at-point 'symbol
))
12063 (beg (or (and target
(- end
(length target
)))
12064 ;; Nothing at point.
12065 (progn (insert " ") (point)))))
12066 (setq anything-ec-target
(or target
" "))
12067 (with-anything-show-completion beg end
12068 (anything :sources
'anything-c-source-esh
12069 :input
(anything-ff-set-pattern ; Handle tramp filenames.
12070 (car (last (ignore-errors ; Needed in lisp symbols completion.
12071 (pcomplete-parse-arguments)))))))))
12074 (defun anything-eshell-history ()
12075 "Preconfigured anything for eshell history."
12077 (let* ((end (point))
12078 (beg (save-excursion (eshell-bol) (point)))
12082 (setq flag-empty t
)
12083 (setq end
(point)))
12085 (with-anything-show-completion beg end
12086 (anything :sources
'anything-c-source-eshell-history
12087 :buffer
"*Eshell history*"))
12088 (when (and flag-empty
12089 (looking-back " "))
12090 (delete-char -
1)))))
12093 (defun anything-c-run-external-command (program)
12094 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12095 If program is already running exit with error.
12096 You can set your own list of commands with
12097 `anything-c-external-commands-list'."
12099 (anything-comp-read
12101 (anything-c-external-commands-list-1 'sort
)
12103 :name
"External Commands"
12104 :history anything-external-command-history
)))
12105 (anything-run-or-raise program
)
12106 (setq anything-external-command-history
12107 (cons program
(delete program
12108 (loop for i in anything-external-command-history
12109 when
(executable-find i
) collect i
)))))
12112 (defun anything-ratpoison-commands ()
12113 "Preconfigured `anything' to execute ratpoison commands."
12115 (anything-other-buffer 'anything-c-source-ratpoison-commands
12116 "*anything ratpoison commands*"))
12119 (defun anything-ucs ()
12120 "Preconfigured anything for `ucs-names' math symbols."
12122 (anything :sources
'anything-c-source-ucs
12123 :keymap anything-c-ucs-map
))
12126 (defun anything-c-apropos ()
12127 "Preconfigured anything to describe commands, functions, variables and faces."
12129 (let ((default (thing-at-point 'symbol
)))
12131 `(((name .
"Commands")
12133 (anything-c-apropos-init 'commandp
,default
)))
12134 (persistent-action . anything-lisp-completion-persistent-action
)
12135 (persistent-help .
"Show brief doc in mode-line")
12136 (candidates-in-buffer)
12137 (action .
(lambda (candidate)
12138 (describe-function (intern candidate
)))))
12139 ((name .
"Functions")
12141 (anything-c-apropos-init #'(lambda (x) (and (fboundp x
)
12142 (not (commandp x
))))
12144 (persistent-action . anything-lisp-completion-persistent-action
)
12145 (persistent-help .
"Show brief doc in mode-line")
12146 (candidates-in-buffer)
12147 (action .
(lambda (candidate)
12148 (describe-function (intern candidate
)))))
12149 ((name .
"Variables")
12151 (anything-c-apropos-init 'boundp
,default
)))
12152 (persistent-action . anything-lisp-completion-persistent-action
)
12153 (persistent-help .
"Show brief doc in mode-line")
12154 (candidates-in-buffer)
12155 (action .
(lambda (candidate)
12156 (describe-variable (intern candidate
)))))
12159 (anything-c-apropos-init 'facep
,default
)))
12160 (persistent-action . anything-lisp-completion-persistent-action
)
12161 (persistent-help .
"Show brief doc in mode-line")
12162 (candidates-in-buffer)
12163 (filtered-candidate-transformer .
(lambda (candidates source
)
12164 (loop for c in candidates
12165 collect
(propertize c
'face
(intern c
)))))
12166 (action .
(lambda (candidate)
12167 (describe-face (intern candidate
)))))
12168 ((name .
"Anything attributes")
12169 (candidates .
(lambda ()
12170 (mapcar 'symbol-name anything-additional-attributes
)))
12171 (action .
(lambda (candidate)
12172 (with-output-to-temp-buffer "*Help*"
12173 (princ (get (intern candidate
) 'anything-attrdoc
))))))))))
12176 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12179 (provide 'anything-config
)
12181 ;;; Local Variables:
12182 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12185 ;; How to save (DO NOT REMOVE!!)
12186 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12187 ;;; anything-config.el ends here
12189 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12190 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12191 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12192 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12193 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12194 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12195 ;;; LocalWords: dotimes Thierry online vname
12196 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12197 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12198 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12199 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12200 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12201 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12202 ;;; LocalWords: startpos noselect dont desc