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" "visit-tags-table")
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-1 :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-1 :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 (hist (and history
(anything-comp-read-get-candidates
4523 history nil nil alistp
))))
4524 (flet ((action-fn (candidate)
4525 (if marked-candidates
4526 (anything-marked-candidates)
4527 (identity candidate
))))
4530 `(((name .
,(format "%s History" name
))
4531 (header-name .
(lambda (name)
4532 (concat name anything-c-find-files-doc-header
)))
4534 (mode-line . anything-read-file-name-mode-line-string
)
4536 (persistent-action .
,persistent-action
)
4537 (persistent-help .
,persistent-help
)
4538 (action .
,'action-fn
))
4540 (header-name .
(lambda (name)
4541 (concat name anything-c-find-files-doc-header
)))
4542 ;; It is needed for filenames with capital letters
4544 (mode-line . anything-read-file-name-mode-line-string
)
4545 (candidates .
(lambda ()
4546 (let ((seq (anything-find-files-get-candidates)))
4548 (loop for fname in seq
4549 when
(funcall test fname
) collect fname
)
4551 (filtered-candidate-transformer anything-c-find-files-transformer
)
4552 (persistent-action .
,persistent-action
)
4553 (candidate-number-limit .
9999)
4554 (toggle-auto-update . anything-ff-toggle-auto-update
)
4555 (persistent-help .
,persistent-help
)
4557 (action .
,'action-fn
)))
4558 :input initial-input
4560 :keymap anything-c-read-file-map
4563 :preselect preselect
)
4568 (defvar anything-c-file-cache-initialized-p nil
)
4570 (defvar anything-c-file-cache-files nil
)
4572 (defvar anything-c-source-file-cache
4573 '((name .
"File Cache")
4576 (require 'filecache nil t
)
4577 (unless anything-c-file-cache-initialized-p
4578 (setq anything-c-file-cache-files
4579 (loop for item in file-cache-alist append
4580 (destructuring-bind (base &rest dirs
) item
4581 (loop for dir in dirs collect
4582 (concat dir base
)))))
4583 (defadvice file-cache-add-file
(after file-cache-list activate
)
4584 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
4585 (setq anything-c-file-cache-initialized-p t
))))
4586 (candidates . anything-c-file-cache-files
)
4587 (match anything-c-match-on-basename
)
4589 ;; (anything 'anything-c-source-file-cache)
4595 ;; NOTE for WINDOZE users:
4596 ;; You have to install Everything with his command line interface here:
4597 ;; http://www.voidtools.com/download.php
4599 (defun anything-locate-1 (&optional localdb init
)
4600 "Generic function to run Locate.
4601 if LOCALDB is non--nil search and use a local locate db file.
4602 INIT is a string to use as initial input in prompt.
4603 See `anything-locate-with-db' and `anything-locate'."
4604 (anything-locate-with-db
4606 (anything-c-read-file-name
4608 :marked-candidates t
4609 :preselect anything-locate-db-file-regexp
4611 (if anything-locate-db-file-regexp
4612 ;; Select only locate db files and directories
4613 ;; to allow navigation.
4615 anything-locate-db-file-regexp x
)
4616 (file-directory-p x
))
4619 ;; (anything-locate-1 t)
4621 (defun anything-locate-with-db (&optional db initial-input
)
4623 If DB is not given or nil use locate without -d option.
4624 Argument DB can be given as a string or list of db files.
4625 Argument INITIAL-INPUT is a string to use as initial-input.
4626 See also `anything-locate'."
4627 (when (and db
(stringp db
)) (setq db
(list db
)))
4628 (let ((anything-c-locate-command
4630 (replace-regexp-in-string
4632 (format "locate -d %s"
4633 (mapconcat 'identity
4634 ;; Remove eventually
4635 ;; marked directories by error.
4637 unless
(file-directory-p i
)
4639 anything-c-locate-command
)
4640 anything-c-locate-command
)))
4641 (anything-1 :sources
'anything-c-source-locate
4642 :buffer
"*anything locate*"
4643 :input initial-input
4644 :keymap anything-generic-files-map
)))
4645 ;; (anything-locate-with-db "~/locate.db")
4647 (defun anything-c-locate-init ()
4648 "Initialize async locate process for `anything-c-source-locate'."
4649 (setq mode-line-format
4650 '(" " mode-line-buffer-identification
" "
4651 (line-number-mode "%l") " "
4652 (:eval
(propertize "(Locate Process Running) "
4653 'face
'((:foreground
"red"))))))
4655 (start-process-shell-command "locate-process" nil
4656 (format anything-c-locate-command
4658 (set-process-sentinel (get-process "locate-process")
4659 #'(lambda (process event
)
4660 (when (string= event
"finished\n")
4661 (with-anything-window
4662 (force-mode-line-update nil
)
4663 (anything-update-move-first-line)))))))
4665 (defvar anything-c-source-locate
4667 (candidates . anything-c-locate-init
)
4669 (properties-action . anything-ff-properties
)
4670 (requires-pattern .
3)
4671 (candidate-number-limit .
9999)
4672 (mode-line . anything-generic-file-mode-line-string
)
4674 "Find files matching the current input pattern with locate.")
4675 ;; (anything 'anything-c-source-locate)
4677 (defun anything-c-locate-read-file-name (prompt &optional init
)
4678 "Search a file with locate and return it's filename.
4679 Use argument PROMPT and INIT for `anything' arguments
4681 (anything-1 :sources
4683 (candidates . anything-c-locate-init
)
4685 (properties-action . anything-ff-properties
)
4686 (requires-pattern .
3)
4687 (candidate-number-limit .
9999)
4688 (mode-line . anything-generic-file-mode-line-string
)
4692 :buffer
"*anything locate rfn*"))
4696 ;;; Anything Incremental Grep.
4699 ;; Allow to grep incrementally with anything interface.
4700 ;; It allow also to Grep files recursively without using 'find' shell command.
4701 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4702 (defvar anything-c-grep-default-command
4703 "grep -d skip %e -niH -e %p %f"
4704 "Default grep format command for `anything-do-grep-1'.
4706 '%e' format spec is for --exclude or --include grep options.
4707 '%p' format spec is for pattern.
4708 '%f' format spec is for filenames.")
4710 (defvar anything-c-grep-default-recurse-command
4711 "grep -d recurse %e -niH -e %p %f"
4712 "Default recursive grep format command for `anything-do-grep-1'.
4713 See `anything-c-grep-default-command' for format specs.")
4715 (defvar anything-c-default-zgrep-command
"zgrep -niH -e %p %f")
4717 (defvar anything-c-rzgrep-cache
(make-hash-table :test
'equal
))
4719 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
4721 (defvar anything-c-grep-debug-command-line nil
4722 "Turn on anything grep command-line debugging when non--nil.")
4724 (defvar anything-c-zgrep-recurse-flag nil
)
4726 (defvar anything-c-grep-history nil
)
4728 (defvar anything-c-grep-max-length-history
100
4729 "*Max number of elements to save in `anything-c-grep-history'.")
4731 (defun anything-c-grep-prepare-candidates (candidates)
4732 "Prepare filenames and directories CANDIDATES for grep command line."
4733 ;; If one or more candidate is a directory, search in all files
4734 ;; of this candidate (e.g /home/user/directory/*).
4735 ;; If r option is enabled search also in subdidrectories.
4736 ;; We need here to expand wildcards to support crap windows filenames
4737 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4738 (if anything-c-zgrep-recurse-flag
4739 (mapconcat 'shell-quote-argument candidates
" ")
4740 (loop for i in candidates append
4741 (cond ( ;; Candidate is a directory and we use recursion.
4742 (and (file-directory-p i
)
4743 (anything-c-grep-recurse-p))
4744 (list (expand-file-name i
)))
4745 ;; Candidate is a directory, search in all files.
4746 ((file-directory-p i
)
4747 (file-expand-wildcards
4748 (concat (file-name-as-directory (expand-file-name i
)) "*") t
))
4749 ;; Candidate is a file or wildcard and we use recursion, use the
4750 ;; current directory instead of candidate.
4751 ((and (or (file-exists-p i
) (string-match "\*" i
))
4752 (anything-c-grep-recurse-p))
4753 (list (expand-file-name
4754 (directory-file-name ; Needed for windoze.
4755 (file-name-directory (directory-file-name i
))))))
4756 ;; Candidate use wildcard.
4757 ((string-match "^\*" (anything-c-basename i
))
4758 (file-expand-wildcards i t
))
4759 ;; Else should be one or more file.
4760 (t (list i
))) into all-files
4762 (mapconcat 'shell-quote-argument all-files
" "))))
4764 (defun anything-c-grep-recurse-p ()
4765 "Check if `anything-do-grep-1' have switched to recursive."
4766 (let ((args (replace-regexp-in-string
4767 "grep" "" anything-c-grep-default-command
)))
4768 (string-match-p "r\\|recurse" args
)))
4770 (defun anything-c-grep-init (only-files &optional include zgrep
)
4771 "Start an asynchronous grep process in ONLY-FILES list."
4772 (let* ((fnargs (anything-c-grep-prepare-candidates
4773 (if (file-remote-p anything-ff-default-directory
)
4774 (mapcar #'(lambda (x)
4775 (file-remote-p x
'localname
))
4778 (ignored-files (mapconcat
4780 (concat "--exclude=" (shell-quote-argument x
)))
4781 grep-find-ignored-files
" "))
4782 (ignored-dirs (mapconcat
4783 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4785 (concat "--exclude-dir=" (shell-quote-argument x
)))
4786 grep-find-ignored-directories
" "))
4787 (exclude (if (anything-c-grep-recurse-p)
4788 (concat (or include ignored-files
) " " ignored-dirs
)
4790 (cmd-line (format-spec
4791 anything-c-grep-default-command
4793 (list (unless zgrep
(cons ?e exclude
))
4794 (cons ?p
(shell-quote-argument anything-pattern
))
4795 (cons ?f fnargs
))))))
4796 (when anything-c-grep-debug-command-line
4797 (with-current-buffer (get-buffer-create "*any grep debug*")
4798 (goto-char (point-max))
4799 (insert (concat ">>> " cmd-line
"\n\n"))))
4800 (setq mode-line-format
4801 '(" " mode-line-buffer-identification
" "
4802 (line-number-mode "%l") " "
4803 (:eval
(when (get-process "grep-process")
4804 (propertize "[Grep Process Running] "
4805 'face
'anything-grep-running
)))))
4806 (force-mode-line-update nil
)
4808 (let ((default-directory anything-ff-default-directory
))
4809 (start-file-process-shell-command "grep-process" nil cmd-line
))
4811 (set-process-sentinel
4812 (get-process "grep-process")
4813 #'(lambda (process event
)
4814 (when (string= event
"finished\n")
4815 (with-anything-window
4816 (anything-update-move-first-line)
4817 (setq mode-line-format
4818 '(" " mode-line-buffer-identification
" "
4819 (line-number-mode "%l") " "
4821 (format "[Grep Process Finished - (%s results)] "
4822 (let ((nlines (1- (count-lines
4825 (if (> nlines
0) nlines
0)))
4826 'face
'anything-grep-finish
))))
4827 (force-mode-line-update nil
))))))))
4829 (defun anything-c-grep-action (candidate &optional where mark
)
4830 "Define a default action for `anything-do-grep' on CANDIDATE.
4831 WHERE can be one of other-window, elscreen, other-frame."
4832 (let* ((split (anything-c-grep-split-line candidate
))
4833 (lineno (string-to-number (nth 1 split
)))
4834 (loc-fname (car split
))
4835 (tramp-method (file-remote-p anything-ff-default-directory
'method
))
4836 (tramp-host (file-remote-p anything-ff-default-directory
'host
))
4837 (tramp-prefix (concat "/" tramp-method
":" tramp-host
":"))
4838 (fname (if tramp-host
4839 (concat tramp-prefix loc-fname
) loc-fname
)))
4841 (other-window (find-file-other-window fname
))
4842 (elscreen (anything-elscreen-find-file fname
))
4843 (other-frame (find-file-other-frame fname
))
4844 (t (find-file fname
)))
4845 (anything-goto-line lineno
)
4847 (set-marker (mark-marker) (point))
4848 (push-mark (point) 'nomsg
))
4850 (unless (or anything-in-persistent-action
4851 (string= anything-pattern
""))
4852 (setq anything-c-grep-history
4853 (cons anything-pattern
4854 (delete anything-pattern anything-c-grep-history
)))
4855 (when (> (length anything-c-grep-history
)
4856 anything-c-grep-max-length-history
)
4857 (setq anything-c-grep-history
4858 (delete (car (last anything-c-grep-history
))
4859 anything-c-grep-history
))))))
4861 (defun anything-c-grep-other-window (candidate)
4862 "Jump to result in other window from anything grep."
4863 (anything-c-grep-action candidate
'other-window
))
4865 (defun anything-c-grep-other-frame (candidate)
4866 "Jump to result in other frame from anything grep."
4867 (anything-c-grep-action candidate
'other-frame
))
4869 (defun anything-c-grep-jump-elscreen (candidate)
4870 "Jump to result in elscreen from anything grep."
4871 (anything-c-grep-action candidate
'elscreen
))
4873 (defun anything-c-grep-save-results (candidate)
4874 "Save anything grep result in a `grep-mode' buffer."
4875 (let ((buf "*grep*")
4877 (when (get-buffer buf
)
4878 (setq new-buf
(read-string "GrepBufferName: " buf
))
4879 (loop for b in
(anything-c-buffer-list)
4880 when
(and (string= new-buf b
)
4882 (format "Buffer `%s' already exists overwrite? "
4884 do
(setq new-buf
(read-string "GrepBufferName: " "*grep ")))
4886 (with-current-buffer (get-buffer-create buf
)
4887 (let ((inhibit-read-only t
))
4889 (insert "-*- mode: grep -*-\n\n"
4890 (format "Grep Results for `%s':\n\n" anything-pattern
))
4892 (insert (with-current-buffer anything-buffer
4894 (buffer-substring (point) (point-max))))
4896 (message "Anything Grep Results saved in `%s' buffer" buf
)))
4898 (defun anything-c-grep-persistent-action (candidate)
4899 "Persistent action for `anything-do-grep'.
4900 With a prefix arg record CANDIDATE in `mark-ring'."
4901 (if current-prefix-arg
4902 (anything-c-grep-action candidate nil
'mark
)
4903 (anything-c-grep-action candidate
))
4904 (anything-match-line-color-current-line))
4906 (defun anything-c-grep-guess-extensions (files)
4907 "Try to guess file extensions in FILES list when using grep recurse.
4908 These extensions will be added to command line with --include arg of grep."
4910 with glob-list
= nil
4911 with lst
= (if (file-directory-p (car files
))
4914 directory-files-no-dot-files-regexp
)
4917 for ext
= (file-name-extension i t
)
4918 for glob
= (and ext
(not (string= ext
""))
4920 unless
(or (not glob
)
4921 (member glob glob-list
)
4922 (member glob grep-find-ignored-files
))
4923 collect glob into glob-list
4924 finally return glob-list
))
4926 (defun anything-do-grep-1 (only &optional recurse zgrep
)
4927 "Launch grep with a list of ONLY files.
4928 When RECURSE is given use -r option of grep and prompt user
4929 to set the --include args of grep.
4930 You can give more than one arg separated by space.
4931 e.g *.el *.py *.tex.
4932 If it's empty --exclude `grep-find-ignored-files' is used instead."
4933 (let* ((anything-compile-source-functions
4934 ;; rule out anything-match-plugin because the input is one regexp.
4935 (delq 'anything-compile-source--match-plugin
4936 (copy-sequence anything-compile-source-functions
)))
4937 (exts (anything-c-grep-guess-extensions only
))
4938 (globs (and (not zgrep
) (mapconcat 'identity exts
" ")))
4939 (include-files (and recurse
(not zgrep
)
4940 (read-string "OnlyExt(*.[ext]): "
4942 ;; Set `minibuffer-history' AFTER includes-files
4943 ;; to avoid storing wild-cards here.
4944 (minibuffer-history anything-c-grep-history
)
4945 (anything-c-grep-default-command (cond ((and recurse zgrep
) anything-c-default-zgrep-command
)
4946 (recurse anything-c-grep-default-recurse-command
)
4947 (zgrep anything-c-default-zgrep-command
)
4948 (t anything-c-grep-default-command
)))
4949 ;; Disable match-plugin and use here own highlighting.
4950 (anything-mp-highlight-delay nil
))
4953 (and (not (string= include-files
""))
4954 (mapconcat #'(lambda (x)
4955 (concat "--include=" (shell-quote-argument x
)))
4956 (split-string include-files
) " "))))
4957 ;; When called as action from an other source e.g *-find-files
4958 ;; we have to kill action buffer.
4959 (when (get-buffer anything-action-buffer
)
4960 (kill-buffer anything-action-buffer
))
4961 ;; `anything-find-files' haven't already started,
4962 ;; give a default value to `anything-ff-default-directory'.
4963 (setq anything-ff-default-directory
(or anything-ff-default-directory
4967 `(((name .
"Grep (C-c ? Help)")
4970 (funcall anything-c-grep-default-function only include-files zgrep
)))
4971 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
4972 (candidate-number-limit .
9999)
4973 (mode-line . anything-grep-mode-line-string
)
4974 (jump-persistent . anything-c-grep-persistent-action
)
4977 `(("Find File" . anything-c-grep-action
)
4978 ("Find file other frame" . anything-c-grep-other-frame
)
4979 ,(and (locate-library "elscreen")
4980 '("Find file in Elscreen"
4981 . anything-c-grep-jump-elscreen
))
4982 ("Save results in grep buffer" . anything-c-grep-save-results
)
4983 ("Find file other window" . anything-c-grep-other-window
))))
4984 (persistent-action . anything-c-grep-persistent-action
)
4985 (persistent-help .
"Jump to line (`C-u' Record in mark ring)")
4986 (requires-pattern .
3)
4988 :keymap anything-c-grep-map
4989 :buffer
"*anything grep*")))
4991 (defun anything-ff-zgrep-1 (flist recursive
)
4993 (let* ((def-dir (or anything-ff-default-directory
4996 (or (gethash def-dir anything-c-rzgrep-cache
)
4999 (anything-c-walk-directory
5003 :match
".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5004 anything-c-rzgrep-cache
))
5006 (when recursive
(setq anything-c-zgrep-recurse-flag t
))
5007 (anything-do-grep-1 only recursive
'zgrep
))
5008 (setq anything-c-zgrep-recurse-flag nil
)))
5010 (defun anything-c-grep-split-line (line)
5011 "Split a grep output line."
5012 (let (beg fname lineno str
)
5013 ;; Don't print until grep line is valid.
5014 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line
)
5017 (goto-char (point-min))
5020 (re-search-forward ":" nil t
)
5021 (setq fname
(buffer-substring-no-properties beg
(1- (point))))
5023 (re-search-forward ":" nil t
)
5024 (setq lineno
(buffer-substring-no-properties beg
(1- (point))))
5025 (setq str
(buffer-substring-no-properties (point) (point-at-eol))))
5026 (list fname lineno str
))))
5028 (defun anything-c-grep-cand-transformer (candidates sources
)
5029 "Filtered candidate transformer function for `anything-do-grep'."
5030 (loop for i in candidates
5031 for split
= (and i
(anything-c-grep-split-line i
))
5032 for fname
= (car split
)
5033 for lineno
= (nth 1 split
)
5034 for str
= (nth 2 split
)
5035 when
(and fname lineno str
)
5037 (cons (concat (propertize (file-name-nondirectory fname
)
5038 'face
'anything-grep-file
5039 'help-echo fname
) ":"
5040 (propertize lineno
'face
'anything-grep-lineno
) ":"
5041 (anything-c-grep-highlight-match str
))
5044 (defun anything-c-grep-highlight-match (str)
5045 "Highlight in string STR all occurences matching `anything-pattern'."
5049 (goto-char (point-min))
5050 (while (and (re-search-forward anything-pattern nil t
)
5051 (> (- (match-end 0) (match-beginning 0)) 0))
5052 (add-text-properties
5053 (match-beginning 0) (match-end 0)
5054 '(face anything-grep-match
)))
5058 ;; Go to next or precedent file (common to etags and grep).
5059 (defun anything-c-goto-next-or-prec-file (n)
5060 "Go to next or precedent candidate file in anything grep/etags buffers.
5061 If N is positive go forward otherwise go backward."
5062 (with-anything-window
5063 (let* ((current-line-list (split-string
5066 (point-at-eol)) ":"))
5067 (current-fname (nth 0 current-line-list
))
5068 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
)))
5070 (while (not (funcall fn-b-o-f
))
5071 (forward-line n
) ; Go forward or backward depending of n value.
5072 (unless (search-forward current-fname
(point-at-eol) t
)
5073 (anything-mark-current-line)
5074 (throw 'break nil
))))
5075 (cond ((and (eq n
1) (eobp))
5076 (re-search-backward ".")
5078 (anything-mark-current-line))
5079 ((and (< n
1) (bobp))
5081 (anything-mark-current-line))))))
5084 (defun anything-c-goto-precedent-file ()
5085 "Go to precedent file in anything grep/etags buffers."
5087 (anything-c-goto-next-or-prec-file -
1))
5090 (defun anything-c-goto-next-file ()
5091 "Go to precedent file in anything grep/etags buffers."
5093 (anything-c-goto-next-or-prec-file 1))
5096 (defun anything-c-grep-run-persistent-action ()
5097 "Run grep persistent action from `anything-do-grep-1'."
5099 (anything-execute-persistent-action 'jump-persistent
))
5102 (defun anything-c-grep-run-default-action ()
5103 "Run grep default action from `anything-do-grep-1'."
5105 (anything-c-quit-and-execute-action 'anything-c-grep-action
))
5108 (defun anything-c-grep-run-other-window-action ()
5109 "Run grep goto other window action from `anything-do-grep-1'."
5111 (anything-c-quit-and-execute-action 'anything-c-grep-other-window
))
5114 (defun anything-c-grep-run-save-buffer ()
5115 "Run grep save results action from `anything-do-grep-1'."
5117 (anything-c-quit-and-execute-action 'anything-c-grep-save-results
))
5120 (defun anything-c-grep-buffers-1 (candidate &optional zgrep
)
5121 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5122 If one of selected buffers is not a file--buffer,
5123 it is ignored and grep will run on all others file--buffers.
5124 If only one candidate is selected and it is not a file--buffer,
5125 switch to this buffer and run `anything-occur'.
5126 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5127 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
5130 (anything-marked-candidates)))
5131 (win-conf (current-window-configuration))
5132 ;; Non--fname buffers are ignored.
5133 (bufs (loop for buf in cands
5134 for fname
= (buffer-file-name (get-buffer buf
))
5136 collect
(expand-file-name fname
))))
5139 (anything-do-grep-1 bufs nil
'zgrep
)
5140 (anything-do-grep-1 bufs
))
5141 ;; bufs is empty, thats mean we have only CANDIDATE
5142 ;; and it is not a buffer-filename, fallback to occur.
5143 (anything-c-switch-to-buffer candidate
)
5144 (when (get-buffer anything-action-buffer
)
5145 (kill-buffer anything-action-buffer
))
5147 (when (eq anything-exit-status
1)
5148 (set-window-configuration win-conf
)))))
5150 (defun anything-c-grep-buffers (candidate)
5151 "Action to grep buffers."
5152 (anything-c-grep-buffers-1 candidate
))
5154 (defun anything-c-zgrep-buffers (candidate)
5155 "Action to zgrep buffers."
5156 (anything-c-grep-buffers-1 candidate
'zgrep
))
5159 ;;; Anything interface for pdfgrep
5160 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5161 ;; and a pdf-reader (e.g xpdf) are needed.
5163 (defvar anything-c-pdfgrep-default-command
"pdfgrep --color never -niH %s %s")
5164 (defvar anything-c-pdfgrep-default-function
'anything-c-pdfgrep-init
)
5165 (defvar anything-c-pdfgrep-debug-command-line nil
)
5167 (defun anything-c-pdfgrep-init (only-files)
5168 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5169 (let* ((fnargs (anything-c-grep-prepare-candidates
5170 (if (file-remote-p anything-ff-default-directory
)
5171 (mapcar #'(lambda (x)
5172 (file-remote-p x
'localname
))
5175 (cmd-line (format anything-c-pdfgrep-default-command
5178 (when anything-c-pdfgrep-debug-command-line
5179 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5180 (goto-char (point-max))
5181 (insert (concat ">>> " cmd-line
"\n\n"))))
5182 (setq mode-line-format
5183 '(" " mode-line-buffer-identification
" "
5184 (line-number-mode "%l") " "
5185 (:eval
(propertize "(Pdfgrep Process Running) "
5186 'face
'((:foreground
"red"))))))
5188 (let ((default-directory anything-ff-default-directory
))
5189 (start-file-process-shell-command "pdfgrep-process" nil cmd-line
))
5191 (set-process-sentinel
5192 (get-process "pdfgrep-process")
5193 #'(lambda (process event
)
5194 (when (string= event
"finished\n")
5195 (with-anything-window
5196 (anything-update-move-first-line))
5197 (force-mode-line-update nil
)))))))
5200 (defun anything-do-pdfgrep-1 (only)
5201 "Launch pdfgrep with a list of ONLY files."
5202 (unless (executable-find "pdfgrep")
5203 (error "Error: No such program `pdfgrep'."))
5204 (let* ((anything-compile-source-functions
5205 ;; rule out anything-match-plugin because the input is one regexp.
5206 (delq 'anything-compile-source--match-plugin
5207 (copy-sequence anything-compile-source-functions
)))
5208 ;; Disable match-plugin and use here own highlighting.
5209 (anything-mp-highlight-delay nil
))
5210 ;; When called as action from an other source e.g *-find-files
5211 ;; we have to kill action buffer.
5212 (when (get-buffer anything-action-buffer
)
5213 (kill-buffer anything-action-buffer
))
5214 ;; If `anything-find-files' haven't already started,
5215 ;; give a default value to `anything-ff-default-directory'.
5216 (setq anything-ff-default-directory
(or anything-ff-default-directory
5220 `(((name .
"PdfGrep")
5223 (funcall anything-c-pdfgrep-default-function only
)))
5224 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
5225 (candidate-number-limit .
9999)
5226 (mode-line . anything-pdfgrep-mode-line-string
)
5227 (action . anything-c-pdfgrep-action
)
5228 (persistent-help .
"Jump to PDF Page")
5229 (requires-pattern .
3)
5231 :keymap anything-c-pdfgrep-map
5232 :buffer
"*anything grep*")))
5235 (defun anything-c-pdfgrep-action (candidate)
5236 (let* ((split (anything-c-grep-split-line candidate
))
5237 (pageno (nth 1 split
))
5238 (fname (car split
)))
5239 (start-file-process-shell-command
5241 (format-spec anything-c-pdfgrep-default-read-command
5242 (list (cons ?f fname
) (cons ?p pageno
))))))
5244 (defun anything-do-pdfgrep ()
5246 (let ((only (anything-c-read-file-name
5247 "Search in file(s): "
5248 :marked-candidates t
5249 :test
#'(lambda (file)
5250 (or (string= (file-name-extension file
) "pdf")
5251 (string= (file-name-extension file
) "PDF")
5252 (file-directory-p file
)))
5253 :preselect
(or (dired-get-filename nil t
)
5254 (buffer-file-name (current-buffer)))))
5255 (anything-c-grep-default-function 'anything-c-pdfgrep-init
))
5256 (anything-do-pdfgrep-1 only
)))
5259 ;; Yank text at point.
5263 (defvar anything-yank-point nil
)
5266 (defun anything-yank-text-at-point ()
5267 "Yank text at point in minibuffer."
5270 (flet ((insert-in-minibuffer (word)
5271 (with-selected-window (minibuffer-window)
5272 (let ((str anything-pattern
))
5273 (delete-minibuffer-contents)
5274 (set-text-properties 0 (length word
) nil word
)
5275 (insert (concat str word
))))))
5276 (with-anything-current-buffer
5277 ;; Start to initial point if C-w have never been hit.
5278 (unless anything-yank-point
(setq anything-yank-point
(point)))
5279 (and anything-yank-point
(goto-char anything-yank-point
))
5281 (setq input
(buffer-substring-no-properties anything-yank-point
(point)))
5282 (setq anything-yank-point
(point))) ; End of last forward-word
5283 (insert-in-minibuffer input
))))
5285 (defun anything-reset-yank-point ()
5286 (setq anything-yank-point nil
))
5288 (add-hook 'anything-after-persistent-action-hook
'anything-reset-yank-point
)
5289 (add-hook 'anything-cleanup-hook
'anything-reset-yank-point
)
5295 (defvar anything-c-source-recentf
5296 '((name .
"Recentf")
5299 (or recentf-mode
(recentf-mode 1))))
5300 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5301 (candidates . recentf-list
)
5302 (match anything-c-match-on-basename
)
5304 "See (info \"(emacs)File Conveniences\").
5305 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5306 ;; (anything 'anything-c-source-recentf)
5309 (eval-when-compile (require 'ffap
))
5310 (defvar anything-c-source-ffap-guesser
5311 '((name .
"File at point")
5312 (init .
(lambda () (require 'ffap
)))
5313 (candidates .
(lambda ()
5315 (with-anything-current-buffer
5319 ;; (anything 'anything-c-source-ffap-guesser)
5321 ;;; ffap with line number
5322 (defun anything-c-ffap-file-line-at-point ()
5323 "Get (FILENAME . LINENO) at point."
5324 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5327 (when (and (search-forward it nil t
)
5328 (looking-at ":\\([0-9]+\\)"))
5329 (cons it
(string-to-number (match-string 1)))))))
5331 (defvar anything-c-ffap-line-location nil
5332 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5333 It is cleared after jumping line.")
5335 (defun anything-c-ffap-line-candidates ()
5336 (with-anything-current-buffer
5337 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
5338 (when anything-c-ffap-line-location
5339 (destructuring-bind (file . line
) anything-c-ffap-line-location
5340 (list (cons (format "%s (line %d)" file line
) file
)))))
5342 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5343 (defun anything-c-ffap-line-goto-line ()
5344 (when (car anything-c-ffap-line-location
)
5347 (with-selected-window
5349 (get-file-buffer (car anything-c-ffap-line-location
)))
5350 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
5351 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
5352 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
5354 (defvar anything-c-source-ffap-line
5355 '((name .
"File/Lineno at point")
5356 (init .
(lambda () (require 'ffap
)))
5357 (candidates . anything-c-ffap-line-candidates
)
5359 ;; (anything 'anything-c-source-ffap-line)
5361 ;;; list of files gleaned from every dired buffer
5362 (defun anything-c-files-in-all-dired-candidates ()
5366 (cond ((listp dir
) ;filelist
5368 ((equal "" (file-name-nondirectory dir
)) ;dir
5369 (directory-files dir t
))
5371 (file-expand-wildcards dir t
))))
5373 (mapcar (lambda (buf)
5375 (when (eq major-mode
'dired-mode
)
5376 (if (consp dired-directory
)
5377 (cdr dired-directory
) ;filelist
5378 dired-directory
))) ;dir or wildcard
5380 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5382 (defvar anything-c-source-files-in-all-dired
5383 '((name .
"Files in all dired buffer.")
5384 (candidates . anything-c-files-in-all-dired-candidates
)
5386 ;; (anything 'anything-c-source-files-in-all-dired)
5388 (defvar anything-c-source-filelist
5389 '((name .
"FileList")
5390 (grep-candidates . anything-c-filelist-file-name
)
5391 (candidate-number-limit .
200)
5392 (requires-pattern .
4)
5394 "Source to find files instantly.
5395 See `anything-c-filelist-file-name' docstring for usage.")
5400 (defvar anything-c-info-pages nil
5401 "All info pages on system.
5402 Will be calculated the first time you invoke anything with this
5405 (defun anything-c-info-pages-init ()
5406 "Collect candidates for initial Info node Top."
5407 (if anything-c-info-pages
5408 anything-c-info-pages
5409 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5413 (Info-find-node "dir" "top")
5414 (goto-char (point-min))
5415 (while (re-search-forward info-topic-regexp nil t
)
5416 (push (match-string-no-properties 1) topics
))
5418 (setq anything-c-info-pages topics
))))
5420 (defvar anything-c-source-info-pages
5421 `((name .
"Info Pages")
5422 (init . anything-c-info-pages-init
)
5423 (candidates . anything-c-info-pages
)
5424 (action .
(("Show with Info" .
(lambda (node-str)
5425 (info (replace-regexp-in-string
5426 "^[^:]+: " "" node-str
))))))
5427 (requires-pattern .
2)))
5428 ;; (anything 'anything-c-source-info-pages)
5431 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5432 (defun anything-c-describe-attributes (anything-attribute)
5433 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5434 Same as `anything-describe-anything-attribute' but with anything completion."
5435 (interactive (list (intern
5437 "Describe anything attribute: "
5438 (mapcar 'symbol-name anything-additional-attributes
)
5441 #'(lambda (candidate)
5442 (with-output-to-temp-buffer "*Help*"
5443 (princ (get (intern candidate
) 'anything-attrdoc
))))))))
5444 (with-output-to-temp-buffer "*Help*"
5445 (princ (get anything-attribute
'anything-attrdoc
))))
5448 ;;; Use info-index plug-in.
5451 ;; Note that `name' attribute is not needed since
5452 ;; `anything-c-insert-summary' have been removed.
5454 (defvar anything-c-source-info-elisp
5455 '((name .
"Info index: elisp")
5456 (info-index .
"elisp")))
5457 ;; (anything 'anything-c-source-info-elisp)
5460 (defvar anything-c-source-info-cl
5461 '((name .
"Info index: cl")
5462 (info-index .
"cl")))
5463 ;; (anything 'anything-c-source-info-cl)
5466 (defvar anything-c-source-info-org
5467 '((name .
"Info index: org")
5468 (info-index .
"org")))
5469 ;; (anything 'anything-c-source-info-org)
5472 (defvar anything-c-source-info-gnus
5473 '((name .
"Info index: Gnus")
5474 (info-index .
"gnus")))
5476 ;; Info Index ratpoison
5477 (defvar anything-c-source-info-ratpoison
5478 '((name .
"Info index: ratpoison")
5479 (info-index .
"ratpoison")))
5480 ;; (anything 'anything-c-source-info-ratpoison)
5483 (defvar anything-c-source-info-zsh
5484 '((name .
"Info index: zsh")
5485 (info-index .
"zsh")))
5486 ;; (anything 'anything-c-source-info-zsh)
5489 (defvar anything-c-source-info-bash
5490 '((name .
"Info index: bash")
5491 (info-index .
"bash")))
5492 ;; (anything 'anything-c-source-info-bash)
5494 ;; Info Index coreutils
5495 (defvar anything-c-source-info-coreutils
5496 '((name .
"Info index: coreutils")
5497 (info-index .
"coreutils")))
5498 ;; (anything 'anything-c-source-info-coreutils)
5500 ;; Info Index fileutils
5501 (defvar anything-c-source-info-fileutils
5502 '((name .
"Info index: fileutils")
5503 (info-index .
"fileutils")))
5504 ;; (anything 'anything-c-source-info-fileutils)
5507 (defvar anything-c-source-info-find
5508 '((name .
"Info index: find")
5509 (info-index .
"find")))
5510 ;; (anything 'anything-c-source-info-find)
5512 ;; Info Index sh-utils
5513 (defvar anything-c-source-info-sh-utils
5514 '((name .
"Info index: sh-utils")
5515 (info-index .
"sh-utils")))
5516 ;; (anything 'anything-c-source-info-sh-utils)
5518 ;; Info Index textutils
5519 (defvar anything-c-source-info-textutils
5520 '((name .
"Info index: textutils")
5521 (info-index .
"textutils")))
5522 ;; (anything 'anything-c-source-info-textutils)
5525 (defvar anything-c-source-info-libc
5526 '((name .
"Info index: libc")
5527 (info-index .
"libc")))
5528 ;; (anything 'anything-c-source-info-libc)
5531 (defvar anything-c-source-info-make
5532 '((name .
"Info index: make")
5533 (info-index .
"make")))
5534 ;; (anything 'anything-c-source-info-make)
5536 ;; Info Index automake
5537 (defvar anything-c-source-info-automake
5538 '((name .
"Info index: automake")
5539 (info-index .
"automake")))
5540 ;; (anything 'anything-c-source-info-automake)
5542 ;; Info Index autoconf
5543 (defvar anything-c-source-info-autoconf
5544 '((name .
"Info index: autoconf")
5545 (info-index .
"autoconf")))
5546 ;; (anything 'anything-c-source-info-autoconf)
5548 ;; Info Index emacs-lisp-intro
5549 (defvar anything-c-source-info-emacs-lisp-intro
5550 '((name .
"Info index: emacs-lisp-intro")
5551 (info-index .
"emacs-lisp-intro")))
5552 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5555 (defvar anything-c-source-info-emacs
5556 '((name .
"Info index: emacs")
5557 (info-index .
"emacs")))
5558 ;; (anything 'anything-c-source-info-emacs)
5561 (defvar anything-c-source-info-elib
5562 '((name .
"Info index: elib")
5563 (info-index .
"elib")))
5564 ;; (anything 'anything-c-source-info-elib)
5567 (defvar anything-c-source-info-eieio
5568 '((name .
"Info index: eieio")
5569 (info-index .
"eieio")))
5570 ;; (anything 'anything-c-source-info-eieio)
5572 ;; Info Index gauche-refe
5573 (defvar anything-c-source-info-gauche-refe
5574 '((name .
"Info index: gauche")
5575 (info-index .
"gauche-refe")))
5576 ;; (anything 'anything-c-source-info-gauche-refe)
5579 (defvar anything-c-source-info-guile
5580 '((name .
"Info index: guile")
5581 (info-index .
"guile")))
5582 ;; (anything 'anything-c-source-info-guile)
5584 ;; Info Index guile-tut
5585 (defvar anything-c-source-info-guile-tut
5586 '((name .
"Info index: guile-tut")
5587 (info-index .
"guile-tut")))
5588 ;; (anything 'anything-c-source-info-guile-tut)
5591 (defvar anything-c-source-info-goops
5592 '((name .
"Info index: goops")
5593 (info-index .
"goops")))
5594 ;; (anything 'anything-c-source-info-goops)
5596 ;; Info Index screen
5597 (defvar anything-c-source-info-screen
5598 '((name .
"Info index: screen")
5599 (info-index .
"screen")
5600 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5601 ;; (anything 'anything-c-source-info-screen)
5604 (defvar anything-c-source-info-latex
5605 '((name .
"Info index: latex")
5606 (info-index .
"latex")))
5607 ;; (anything 'anything-c-source-info-latex)
5610 (defvar anything-c-source-info-gawk
5611 '((name .
"Info index: gawk")
5612 (info-index .
"gawk")))
5613 ;; (anything 'anything-c-source-info-gawk)
5616 (defvar anything-c-source-info-sed
5617 '((name .
"Info index: sed")
5618 (info-index .
"sed")))
5619 ;; (anything 'anything-c-source-info-sed)
5622 (defvar anything-c-source-info-m4
5623 '((name .
"Info index: m4")
5624 (info-index .
"m4")))
5625 ;; (anything 'anything-c-source-info-m4)
5628 (defvar anything-c-source-info-wget
5629 '((name .
"Info index: wget")
5630 (info-index .
"wget")))
5631 ;; (anything 'anything-c-source-info-wget)
5633 ;; Info Index binutils
5634 (defvar anything-c-source-info-binutils
5635 '((name .
"Info index: binutils")
5636 (info-index .
"binutils")))
5637 ;; (anything 'anything-c-source-info-binutils)
5640 (defvar anything-c-source-info-as
5641 '((name .
"Info index: as")
5642 (info-index .
"as")))
5643 ;; (anything 'anything-c-source-info-as)
5646 (defvar anything-c-source-info-bfd
5647 '((name .
"Info index: bfd")
5648 (info-index .
"bfd")))
5649 ;; (anything 'anything-c-source-info-bfd)
5652 (defvar anything-c-source-info-gprof
5653 '((name .
"Info index: gprof")
5654 (info-index .
"gprof")))
5655 ;; (anything 'anything-c-source-info-gprof)
5658 (defvar anything-c-source-info-ld
5659 '((name .
"Info index: ld")
5660 (info-index .
"ld")))
5661 ;; (anything 'anything-c-source-info-ld)
5664 (defvar anything-c-source-info-diff
5665 '((name .
"Info index: diff")
5666 (info-index .
"diff")))
5667 ;; (anything 'anything-c-source-info-diff)
5670 (defvar anything-c-source-info-flex
5671 '((name .
"Info index: flex")
5672 (info-index .
"flex")))
5673 ;; (anything 'anything-c-source-info-flex)
5676 (defvar anything-c-source-info-grep
5677 '((name .
"Info index: grep")
5678 (info-index .
"grep")))
5679 ;; (anything 'anything-c-source-info-grep)
5682 (defvar anything-c-source-info-gzip
5683 '((name .
"Info index: gzip")
5684 (info-index .
"gzip")))
5685 ;; (anything 'anything-c-source-info-gzip)
5687 ;; Info Index libtool
5688 (defvar anything-c-source-info-libtool
5689 '((name .
"Info index: libtool")
5690 (info-index .
"libtool")))
5691 ;; (anything 'anything-c-source-info-libtool)
5693 ;; Info Index texinfo
5694 (defvar anything-c-source-info-texinfo
5695 '((name .
"Info index: texinfo")
5696 (info-index .
"texinfo")))
5697 ;; (anything 'anything-c-source-info-texinfo)
5700 (defvar anything-c-source-info-info
5701 '((name .
"Info index: info")
5702 (info-index .
"info")))
5703 ;; (anything 'anything-c-source-info-info)
5706 (defvar anything-c-source-info-gdb
5707 '((name .
"Info index: gdb")
5708 (info-index .
"gdb")))
5709 ;; (anything 'anything-c-source-info-gdb)
5712 (defvar anything-c-source-info-stabs
5713 '((name .
"Info index: stabs")
5714 (info-index .
"stabs")))
5715 ;; (anything 'anything-c-source-info-stabs)
5717 ;; Info Index cvsbook
5718 (defvar anything-c-source-info-cvsbook
5719 '((name .
"Info index: cvsbook")
5720 (info-index .
"cvsbook")))
5721 ;; (anything 'anything-c-source-info-cvsbook)
5724 (defvar anything-c-source-info-cvs
5725 '((name .
"Info index: cvs")
5726 (info-index .
"cvs")))
5727 ;; (anything 'anything-c-source-info-cvs)
5730 (defvar anything-c-source-info-bison
5731 '((name .
"Info index: bison")
5732 (info-index .
"bison")))
5733 ;; (anything 'anything-c-source-info-bison)
5735 ;; Info Index id-utils
5736 (defvar anything-c-source-info-id-utils
5737 '((name .
"Info index: id-utils")
5738 (info-index .
"id-utils")))
5739 ;; (anything 'anything-c-source-info-id-utils)
5741 ;; Info Index global
5742 (defvar anything-c-source-info-global
5743 '((name .
"Info index: global")
5744 (info-index .
"global")))
5745 ;; (anything 'anything-c-source-info-global)
5748 ;;; Man and woman UI
5751 (defvar anything-c-man-pages nil
5752 "All man pages on system.
5753 Will be calculated the first time you invoke anything with this
5756 (defun anything-c-man-default-action (candidate)
5757 "Default action for jumping to a woman or man page from anything."
5758 (let ((wfiles (woman-file-name-all-completions candidate
)))
5760 (if (> (length wfiles
) 1)
5763 "ManFile: " wfiles
:must-match t
))
5765 ;; If woman is unable to format correctly
5767 (error (kill-buffer) ; Kill woman buffer.
5768 (let ((Man-notify-method 'meek
))
5769 (Man-getpage-in-background candidate
))))))
5771 (defvar anything-c-source-man-pages
5772 `((name .
"Manual Pages")
5773 (candidates .
(lambda ()
5774 (if anything-c-man-pages
5775 anything-c-man-pages
5776 ;; XEmacs doesn't have a woman :)
5777 (setq anything-c-man-pages
5780 (woman-file-name "")
5781 (sort (mapcar 'car woman-topic-all-completions
)
5783 (action ("Show with Woman" . anything-c-man-default-action
))
5784 ;; Woman does not work OS X
5785 ;; http://xahlee.org/emacs/modernization_man_page.html
5786 (action-transformer .
(lambda (actions candidate
)
5787 (if (eq system-type
'darwin
)
5788 '(("Show with Man" . man
))
5790 (requires-pattern .
2)))
5791 ;; (anything 'anything-c-source-man-pages)
5795 ;;; Anything M-x - Enhanced M-x UI
5798 ;; Another replacement of `M-x' that act exactly like the
5799 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5800 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5801 ;; anything invocation.
5802 ;; Documentation of commands available without quitting,
5803 ;; Show keybindings of commands.
5805 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
5806 "Return alist of MODE-MAP."
5807 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
5808 for str-key
= (key-description key
)
5809 for ismenu
= (string-match "<menu-bar>" str-key
)
5810 unless ismenu collect
(cons str-key com
)))
5812 (defun anything-get-mode-map-from-mode (mode)
5813 "Guess the mode-map name according to MODE.
5814 Some modes don't use conventional mode-map name
5815 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5816 Return nil if no mode-map found."
5818 ;; Start with a conventional mode-map name.
5819 with mode-map
= (intern-soft (format "%s-map" mode
))
5820 with mode-string
= (symbol-name mode
)
5821 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
5822 while
(not mode-map
)
5823 for count downfrom
(length mode-name
)
5824 ;; Return when no result after parsing entire string.
5825 when
(eq count
0) return nil
5826 for sub-name
= (substring mode-name
0 count
)
5827 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
5828 finally return mode-map
))
5830 (defun anything-M-x-current-mode-map-alist ()
5831 "Return mode-map alist of current `major-mode'."
5832 (let ((map (anything-get-mode-map-from-mode major-mode
)))
5833 (when (and map
(boundp map
))
5834 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
5837 (defun anything-M-x-transformer (candidates sources
)
5838 "filtered-candidate-transformer to show bindings in emacs commands.
5839 Show global bindings and local bindings according to current `major-mode'."
5840 (with-anything-current-buffer
5842 with local-map
= (anything-M-x-current-mode-map-alist)
5843 for cand in candidates
5844 for local-key
= (car (rassq cand local-map
))
5845 for key
= (substitute-command-keys (format "\\[%s]" cand
))
5847 (cons (cond ((and (string-match "^M-x" key
) local-key
)
5851 'face
'anything-M-x-key-face
)))
5852 ((string-match "^M-x" key
) cand
)
5853 (t (format "%s (%s)"
5856 'face
'anything-M-x-key-face
))))
5859 (sort ls
#'(lambda (x y
) (string-lessp (car x
) (car y
)))))))
5862 ;;; Complex command history
5865 (defvar anything-c-source-complex-command-history
5866 '((name .
"Complex Command History")
5867 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
5869 ;; (anything 'anything-c-source-complex-command-history)
5871 ;;; M-x history (not related to `anything-M-x')
5874 (defvar anything-c-source-extended-command-history
5875 '((name .
"Emacs Commands History")
5876 (candidates . extended-command-history
)
5878 ;; (anything 'anything-c-source-extended-command-history)
5880 ;;; Emacs commands (Basic source for emacs commands)
5883 (defvar anything-c-source-emacs-commands
5884 '((name .
"Emacs Commands")
5885 (candidates .
(lambda ()
5887 (mapatoms (lambda (a)
5889 (push (symbol-name a
)
5891 (sort commands
'string-lessp
))))
5893 (requires-pattern .
2))
5894 "Source for completing and invoking Emacs commands.
5895 A command is a function with interactive spec that can
5896 be invoked with `M-x'.
5898 To get non-interactive functions listed, use
5899 `anything-c-source-emacs-functions'.")
5900 ;; (anything 'anything-c-source-emacs-commands)
5907 (defvar anything-c-source-emacs-functions
5908 '((name .
"Emacs Functions")
5909 (candidates .
(lambda ()
5911 (mapatoms (lambda (a)
5913 (push (symbol-name a
) commands
))))
5914 (sort commands
'string-lessp
))))
5916 (requires-pattern .
2))
5917 "Source for completing Emacs functions.")
5918 ;; (anything 'anything-c-source-emacs-functions)
5920 ;;; With abbrev expansion
5921 ;;; Similar to my exec-abbrev-cmd.el
5922 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
5923 (defvar anything-c-function-abbrev-regexp nil
5924 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
5925 Regexp built from the current `anything-pattern' interpreting it
5927 Only for internal use.")
5929 (defun anything-c-match-function-by-abbrev (candidate)
5930 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
5932 Abbreviations are made by taking the first character from each
5933 word in the function's name, e.g. \"bb\" is an abbrev for
5934 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
5935 (string-match anything-c-function-abbrev-regexp candidate
))
5937 (defvar anything-c-source-emacs-functions-with-abbrevs
5938 (append anything-c-source-emacs-functions
5939 '((match anything-c-match-function-by-abbrev
5940 anything-c-string-match
))
5943 (defadvice anything-update
5944 (before anything-c-update-function-abbrev-regexp activate
)
5945 (let ((char-list (append anything-pattern nil
))
5947 (dolist (c char-list
)
5948 (setq str
(concat str
(list c
) "[^-]*-")))
5949 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
5950 (setq anything-c-function-abbrev-regexp str
))))))))
5951 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
5953 (defvar anything-c-source-advice
5954 '((name .
"Function Advice")
5955 (candidates . anything-c-advice-candidates
)
5956 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
5957 ;; (real-to-display . anything-c-advice-real-to-display)
5958 (persistent-action . anything-c-advice-persistent-action
)
5959 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
5960 ;; (anything 'anything-c-source-advice)
5961 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
5964 (defun anything-c-advice-candidates ()
5966 (loop for
(fname) in ad-advised-functions
5967 for function
= (intern fname
)
5969 (loop for class in ad-advice-classes append
5970 (loop for advice in
(ad-get-advice-info-field function class
)
5971 for enabled
= (ad-advice-enabled advice
)
5975 (if enabled
"Enabled " "Disabled")
5976 (propertize fname
'face
'font-lock-function-name-face
)
5977 (ad-make-single-advice-docstring advice class nil
))
5978 (list function class advice
))))))
5980 (defun anything-c-advice-persistent-action (func-class-advice)
5981 (if current-prefix-arg
5982 (anything-c-advice-toggle func-class-advice
)
5983 (describe-function (car func-class-advice
))))
5985 (defun anything-c-advice-toggle (func-class-advice)
5986 (destructuring-bind (function class advice
) func-class-advice
5987 (cond ((ad-advice-enabled advice
)
5988 (ad-advice-set-enabled advice nil
)
5989 (message "Disabled"))
5991 (ad-advice-set-enabled advice t
)
5992 (message "Enabled")))
5993 (ad-activate function
)
5994 (and anything-in-persistent-action
5995 (anything-c-advice-update-current-display-string))))
5997 (defun anything-c-advice-update-current-display-string ()
5998 (anything-edit-current-selection
5999 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6000 ((looking-at "Enabled") "Disabled")))
6003 (delete-region (point) (progn (forward-word 1) (point)))
6004 (insert newword
)))))
6011 (defvar anything-c-source-emacs-variables
6012 '((name .
"Emacs Variables")
6013 (candidates .
(lambda ()
6014 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
6016 (requires-pattern .
2))
6017 "Source for completing Emacs variables.")
6018 ;; (anything 'anything-c-source-emacs-variables)
6022 (defvar anything-c-source-lacarte
6023 '((name .
"Lacarte")
6024 (init .
(lambda () (require 'lacarte
)))
6025 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6026 (candidate-number-limit .
9999)
6027 (action . anything-c-call-interactively
))
6030 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6031 ;; (anything 'anything-c-source-lacarte)
6037 ;; Bind some faces for bookmarks.
6038 (defvar anything-c-bookmarks-face1
'anything-ff-directory
)
6039 (defvar anything-c-bookmarks-face2
'anything-ff-file
)
6040 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
6042 (eval-when-compile (require 'bookmark
))
6043 (defvar anything-c-source-bookmarks
6044 '((name .
"Bookmarks")
6046 (require 'bookmark
)))
6047 (candidates . bookmark-all-names
)
6049 "See (info \"(emacs)Bookmarks\").")
6050 ;; (anything 'anything-c-source-bookmarks)
6053 (defvar anything-c-source-bookmark-set
6054 '((name .
"Set Bookmark")
6056 (action . bookmark-set
))
6057 "See (info \"(emacs)Bookmarks\").")
6058 ;; (anything 'anything-c-source-bookmark-set)
6060 ;;; Visible Bookmarks
6061 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6064 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6065 (defvar anything-c-source-bm
6066 '((name .
"Visible Bookmarks")
6067 (init . anything-c-bm-init
)
6068 (candidates-in-buffer)
6072 http://www.nongnu.org/bm/")
6074 (defun anything-c-bm-init ()
6075 "Init function for `anything-c-source-bm'."
6076 (when (require 'bm nil t
)
6078 (let ((bookmarks (bm-lists))
6079 (buf (anything-candidate-buffer 'global
)))
6080 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
6081 '< :key
'overlay-start
))
6082 (let ((start (overlay-start bm
))
6083 (end (overlay-end bm
))
6084 (annotation (or (overlay-get bm
'annotation
) "")))
6085 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
6086 (let ((str (format "%5d: [%s]: %s\n"
6087 (line-number-at-pos start
)
6089 (buffer-substring start
(1- end
)))))
6090 (with-current-buffer buf
(insert str
))))))))))
6092 ;;; Special bookmarks
6093 (defvar anything-c-source-bookmarks-ssh
6094 '((name .
"Bookmarks-ssh")
6096 (require 'bookmark
)))
6097 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
6099 "See (info \"(emacs)Bookmarks\").")
6100 ;; (anything 'anything-c-source-bookmarks-ssh)
6102 (defvar anything-c-source-bookmarks-su
6103 '((name .
"Bookmarks-root")
6105 (require 'bookmark
)))
6106 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
6107 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
6110 "See (info \"(emacs)Bookmarks\").")
6111 ;; (anything 'anything-c-source-bookmarks-su)
6113 (defvar anything-c-source-bookmarks-local
6114 '((name .
"Bookmarks-Local")
6116 (require 'bookmark
)))
6117 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
6118 (filtered-candidate-transformer
6119 anything-c-adaptive-sort
6120 anything-c-highlight-bookmark
)
6122 "See (info \"(emacs)Bookmarks\").")
6123 ;; (anything 'anything-c-source-bookmarks-local)
6125 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
6126 (let* ((lis-all (bookmark-all-names))
6127 (lis-loc (cond (local (loop for i in lis-all
6128 unless
(string-match "^(ssh)\\|^(su)" i
)
6130 (su (loop for i in lis-all
6131 when
(string-match "^(su)" i
)
6133 (sudo (loop for i in lis-all
6134 when
(string-match "^(sudo)" i
)
6136 (ssh (loop for i in lis-all
6137 when
(string-match "^(ssh)" i
)
6139 (sort lis-loc
'string-lessp
)))
6141 (defun anything-c-bookmark-root-logged-p ()
6143 (dolist (i (mapcar #'buffer-name
(buffer-list)))
6144 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
6145 (throw 'break t
)))))
6147 (defun anything-c-highlight-bookmark-su (files source
)
6148 (if (anything-c-bookmark-root-logged-p)
6149 (anything-c-highlight-bookmark files source
)
6150 (anything-c-highlight-not-logged files source
)))
6152 (defun anything-c-highlight-not-logged (files source
)
6153 (loop for i in files
6154 collect
(propertize i
'face anything-c-bookmarks-face3
)))
6156 (defun anything-c-highlight-bookmark (bookmarks source
)
6157 "Used as `candidate-transformer' to colorize bookmarks.
6158 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6159 (loop for i in bookmarks
6160 for isfile
= (bookmark-get-filename i
)
6161 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
6162 (bmkext-get-buffer-name i
))
6163 for handlerp
= (and (fboundp 'bookmark-get-handler
)
6164 (bookmark-get-handler i
))
6165 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
6166 (bmkext-w3m-bookmark-p i
))
6167 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
6168 (bmkext-gnus-bookmark-p i
))
6169 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
6170 (bmkext-man-bookmark-p i
))
6171 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
6172 (bmkext-woman-bookmark-p i
))
6173 for handlerp
= (bookmark-get-handler i
)
6174 for isannotation
= (bookmark-get-annotation i
)
6175 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
6176 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
6177 ;; Add a * if bookmark have annotation
6178 if
(and isannotation
(not (string-equal isannotation
"")))
6179 do
(setq i
(concat "*" i
))
6180 collect
(cond (;; info buffers
6182 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
6185 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
6188 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
6191 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
6194 (propertize i
'face
'((:foreground
"Tomato"))))
6196 (and isfile
(file-directory-p isfile
))
6197 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
6200 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
6204 ;;; Sources to filter bookmark-extensions bookmarks.
6207 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6208 ;; If you want to enable google-maps in addressbook you will need
6209 ;; Julien Danjou google-maps-el package available here:
6210 ;; http://julien.danjou.info/google-maps-el.html
6212 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
6213 "Return a filtered `bookmark-alist' sorted alphabetically."
6215 with alist
= (if args
6216 (apply #'(lambda (x) (funcall fn x
)) args
)
6221 finally return
(sort sa
'string-lessp
)))
6226 (defvar anything-c-source-bmkext-addressbook
6227 '((name .
"Bookmark Addressbook")
6229 (require 'bookmark-extensions
)
6230 (bookmark-maybe-load-default-file)))
6231 (candidates . anything-c-bmkext-addressbook-setup-alist
)
6233 .
(lambda (candidate)
6234 (let ((bmk (anything-bookmark-get-bookmark-from-name
6236 (bookmark--jump-via bmk
'pop-to-buffer
))))
6237 (persistent-help .
"Show contact - Prefix with C-u to append")
6238 (filtered-candidate-transformer
6239 anything-c-adaptive-sort
6240 anything-c-highlight-bookmark
)
6241 (action .
(("Show Contact(s)"
6242 .
(lambda (candidate)
6243 (let* ((contacts (anything-marked-candidates))
6244 (current-prefix-arg (or anything-current-prefix-arg
6245 (> (length contacts
) 1))))
6247 (anything-bookmark-get-bookmark-from-name (car contacts
)))
6248 (anything-aif (cdr contacts
)
6249 (loop for bmk in it do
6251 (anything-bookmark-get-bookmark-from-name bmk
)))))))
6253 .
(lambda (candidate)
6254 (let* ((contacts (anything-marked-candidates))
6255 (bmk (anything-bookmark-get-bookmark-from-name
6257 (append (message-buffers)))
6259 (addressbook-set-mail-buffer1 bmk
'append
)
6260 (addressbook-set-mail-buffer1 bmk
))
6261 (setq contacts
(cdr contacts
))
6263 (loop for bmk in contacts do
6264 (addressbook-set-mail-buffer1 bmk
'append
))))))
6266 .
(lambda (candidate)
6267 (let ((bmk (anything-bookmark-get-bookmark-from-name
6269 (addressbook-bookmark-edit
6270 (assoc bmk bookmark-alist
)))))
6271 ("Insert Email at point"
6272 .
(lambda (candidate)
6273 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6275 (mlist (split-string
6277 'email
(assoc bmk bookmark-alist
))
6280 (if (> (length mlist
) 1)
6282 "Insert Mail Address: " mlist
:must-match t
)
6285 .
(lambda (candidate)
6286 (let ((bmk (anything-bookmark-get-bookmark-from-name
6288 (bookmark-show-annotation bmk
))))
6290 .
(lambda (candidate)
6291 (let ((bmk (anything-bookmark-get-bookmark-from-name
6293 (bookmark-edit-annotation bmk
))))
6295 .
(lambda (candidate)
6296 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6298 (full-bmk (assoc bmk bookmark-alist
)))
6299 (addressbook-google-map full-bmk
))))))))
6302 (defun anything-c-bmkext-addressbook-setup-alist ()
6303 "Specialized filter function for bookmarks w3m."
6304 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
6306 ;; W3m bookmarks from bookmark-extensions.
6307 (defvar anything-c-source-bookmark-w3m
6308 '((name .
"Bookmark W3m")
6310 (require 'bookmark-extensions
)
6311 (bookmark-maybe-load-default-file)))
6312 (candidates . anything-c-bookmark-w3m-setup-alist
)
6313 (filtered-candidate-transformer
6314 anything-c-adaptive-sort
6315 anything-c-highlight-bookmark
)
6317 ;; (anything 'anything-c-source-bookmark-w3m)
6319 (defun anything-c-bookmark-w3m-setup-alist ()
6320 "Specialized filter function for bookmarks w3m."
6321 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
6324 (defvar anything-c-source-bookmark-images
6325 '((name .
"Bookmark Images")
6327 (require 'bookmark-extensions
)
6328 (bookmark-maybe-load-default-file)))
6329 (candidates . anything-c-bookmark-images-setup-alist
)
6330 (filtered-candidate-transformer
6331 anything-c-adaptive-sort
6332 anything-c-highlight-bookmark
)
6334 ;; (anything 'anything-c-source-bookmark-images)
6336 (defun anything-c-bookmark-images-setup-alist ()
6337 "Specialized filter function for images bookmarks."
6338 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
6341 (defvar anything-c-source-bookmark-man
6342 '((name .
"Bookmark Woman&Man")
6344 (require 'bookmark-extensions
)
6345 (bookmark-maybe-load-default-file)))
6346 (candidates . anything-c-bookmark-man-setup-alist
)
6347 (filtered-candidate-transformer
6348 anything-c-adaptive-sort
6349 anything-c-highlight-bookmark
)
6351 ;; (anything 'anything-c-source-bookmark-man)
6353 (defun anything-c-bookmark-man-setup-alist ()
6354 "Specialized filter function for bookmarks w3m."
6355 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
6356 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
6359 (defvar anything-c-source-bookmark-gnus
6360 '((name .
"Bookmark Gnus")
6362 (require 'bookmark-extensions
)
6363 (bookmark-maybe-load-default-file)))
6364 (candidates . anything-c-bookmark-gnus-setup-alist
)
6365 (filtered-candidate-transformer
6366 anything-c-adaptive-sort
6367 anything-c-highlight-bookmark
)
6369 ;; (anything 'anything-c-source-bookmark-gnus)
6371 (defun anything-c-bookmark-gnus-setup-alist ()
6372 "Specialized filter function for bookmarks gnus."
6373 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
6376 (defvar anything-c-source-bookmark-info
6377 '((name .
"Bookmark Info")
6379 (require 'bookmark-extensions
)
6380 (bookmark-maybe-load-default-file)))
6381 (candidates . anything-c-bookmark-info-setup-alist
)
6382 (filtered-candidate-transformer
6383 anything-c-adaptive-sort
6384 anything-c-highlight-bookmark
)
6386 ;; (anything 'anything-c-source-bookmark-info)
6388 (defun anything-c-bookmark-info-setup-alist ()
6389 "Specialized filter function for bookmarks info."
6390 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
6392 ;; Local Files&directories
6393 (defvar anything-c-source-bookmark-files
&dirs
6394 '((name .
"Bookmark Files&Directories")
6396 (require 'bookmark-extensions
)
6397 (bookmark-maybe-load-default-file)))
6398 (candidates . anything-c-bookmark-local-files-setup-alist
)
6399 (filtered-candidate-transformer
6400 anything-c-adaptive-sort
6401 anything-c-highlight-bookmark
)
6403 ;; (anything 'anything-c-source-bookmark-files&dirs)
6405 (defun anything-c-bookmark-local-files-setup-alist ()
6406 "Specialized filter function for bookmarks locals files."
6407 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
6409 ;; Su Files&directories
6410 (defvar anything-c-source-bookmark-su-files
&dirs
6411 '((name .
"Bookmark Root-Files&Directories")
6413 (require 'bookmark-extensions
)
6414 (bookmark-maybe-load-default-file)))
6415 (candidates . anything-c-bookmark-su-files-setup-alist
)
6416 (filtered-candidate-transformer
6417 anything-c-adaptive-sort
6418 anything-c-highlight-bookmark-su
)
6420 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6422 (defun anything-c-bookmark-su-files-setup-alist ()
6423 "Specialized filter function for bookmarks su/sudo files."
6424 (declare (special bmkext-su-or-sudo-regexp
))
6426 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6428 for isfile
= (bookmark-get-filename i
)
6429 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
6431 (string-match tramp-file-name-regexp isfile
)))
6432 for issu
= (and istramp
6433 (string-match bmkext-su-or-sudo-regexp isfile
))
6437 ;; Ssh Files&directories
6438 (defvar anything-c-source-bookmark-ssh-files
&dirs
6439 '((name .
"Bookmark Ssh-Files&Directories")
6441 (require 'bookmark-extensions
)
6442 (bookmark-maybe-load-default-file)))
6443 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
6444 (filtered-candidate-transformer . anything-c-adaptive-sort
)
6446 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6448 (defun anything-c-bookmark-ssh-files-setup-alist ()
6449 "Specialized filter function for bookmarks ssh files."
6451 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6453 for isfile
= (bookmark-get-filename i
)
6454 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
6456 (string-match tramp-file-name-regexp isfile
)))
6457 for isssh
= (and istramp
6458 (string-match "/ssh:" isfile
))
6464 ;;; Firefox bookmarks
6467 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6468 ;; (only for firefox versions >=3)
6469 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6471 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6472 ;; You should have now:
6473 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6475 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6476 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
6478 (defun anything-get-firefox-user-init-dir ()
6479 "Guess the default Firefox user directory name."
6480 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6482 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
6483 (goto-char (point-min))
6485 (when (search-forward "Path=" nil t
)
6486 (buffer-substring-no-properties (point) (point-at-eol)))
6488 (file-name-as-directory (concat moz-dir moz-user-dir
))))
6490 (defun anything-guess-firefox-bookmark-file ()
6491 "Return the path of the Firefox bookmarks file."
6492 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6494 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
6495 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6496 (let (bookmarks-alist url title
)
6498 (insert-file-contents file
)
6499 (goto-char (point-min))
6500 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
6502 (when (re-search-forward url-regexp nil t
)
6503 (setq url
(match-string 0)))
6504 (when (re-search-forward bmk-regexp nil t
)
6505 (setq title
(match-string 1)))
6506 (push (cons title url
) bookmarks-alist
)
6508 (nreverse bookmarks-alist
)))
6510 (defvar anything-c-firefox-bookmarks-alist nil
)
6511 (defvar anything-c-source-firefox-bookmarks
6512 '((name .
"Firefox Bookmarks")
6514 (setq anything-c-firefox-bookmarks-alist
6515 (anything-html-bookmarks-to-alist
6516 (anything-guess-firefox-bookmark-file)
6517 anything-firefox-bookmark-url-regexp
6518 anything-firefox-bookmarks-regexp
))))
6519 (candidates .
(lambda ()
6520 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
6521 (filtered-candidate-transformer
6522 anything-c-adaptive-sort
6523 anything-c-highlight-firefox-bookmarks
)
6524 (action .
(("Browse Url Firefox"
6525 .
(lambda (candidate)
6527 (anything-c-firefox-bookmarks-get-value candidate
))))
6529 .
(lambda (candidate)
6531 (anything-c-firefox-bookmarks-get-value candidate
))))
6534 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
6536 ;; (anything 'anything-c-source-firefox-bookmarks)
6538 (defun anything-c-firefox-bookmarks-get-value (elm)
6539 (assoc-default elm anything-c-firefox-bookmarks-alist
))
6541 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
6542 (loop for i in bookmarks
6544 i
'face
'((:foreground
"YellowGreen"))
6545 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
6549 ;;; W3m bookmark - anything interface.
6552 ;; Some users have the emacs-w3m library in load-path
6553 ;; without having the w3m executable :-;
6554 ;; So check if w3m program is present before trying to load
6557 (when (executable-find "w3m")
6558 (require 'w3m-bookmark nil t
)))
6560 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html")
6561 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
6562 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6563 (defvar anything-c-w3m-bookmarks-alist nil
)
6564 (defvar anything-c-source-w3m-bookmarks
6565 '((name .
"W3m Bookmarks")
6567 (setq anything-c-w3m-bookmarks-alist
6568 (anything-html-bookmarks-to-alist
6570 anything-w3m-bookmark-url-regexp
6571 anything-w3m-bookmarks-regexp
))))
6572 (candidates .
(lambda ()
6573 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
6574 (filtered-candidate-transformer
6575 anything-c-adaptive-sort
6576 anything-c-highlight-w3m-bookmarks
)
6577 (action .
(("Browse Url"
6578 .
(lambda (candidate)
6579 (anything-c-w3m-browse-bookmark candidate
)))
6582 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
6583 ("Browse Url Firefox"
6584 .
(lambda (candidate)
6585 (anything-c-w3m-browse-bookmark candidate t
)))
6587 .
(lambda (candidate)
6588 (anything-c-w3m-delete-bookmark candidate
)))
6590 .
(lambda (candidate)
6591 (anything-c-w3m-rename-bookmark candidate
)))))
6592 (persistent-action .
(lambda (candidate)
6593 (if current-prefix-arg
6594 (anything-c-w3m-browse-bookmark candidate t
)
6595 (anything-c-w3m-browse-bookmark candidate nil t
))))
6596 (persistent-help .
"Open URL with emacs-w3m in new tab / \
6597 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6598 "Needs w3m and emacs-w3m.
6600 http://w3m.sourceforge.net/
6601 http://emacs-w3m.namazu.org/")
6603 ;; (anything 'anything-c-source-w3m-bookmarks)
6605 (defun anything-c-w3m-bookmarks-get-value (elm)
6606 (replace-regexp-in-string
6607 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
6609 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
6610 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
6611 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
6612 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
6614 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
6615 (loop for i in bookmarks
6617 i
'face
'anything-w3m-bookmarks-face
6618 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
6621 (defun anything-c-w3m-delete-bookmark (elm)
6622 "Delete w3m bookmark from `w3m-bookmark-file'."
6623 (with-current-buffer
6624 (find-file-literally w3m-bookmark-file
)
6625 (goto-char (point-min))
6626 (when (re-search-forward elm nil t
)
6628 (delete-region (point)
6629 (line-end-position))
6630 (delete-blank-lines))
6634 (defun anything-c-w3m-rename-bookmark (elm)
6635 "Rename w3m bookmark in `w3m-bookmark-file'."
6636 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
6637 (new-title (read-string "NewTitle: " old-title
)))
6638 (with-current-buffer
6639 (find-file-literally w3m-bookmark-file
)
6640 (goto-char (point-min))
6641 (when (re-search-forward (concat elm
"<") nil t
)
6642 (goto-char (1- (point)))
6643 (delete-char (- (length old-title
)))
6650 ;;; Elisp library scan
6653 (defvar anything-c-source-elisp-library-scan
6654 '((name .
"Elisp libraries (Scan)")
6655 (init .
(anything-c-elisp-library-scan-init))
6656 (candidates-in-buffer)
6657 (action ("Find library"
6658 .
(lambda (candidate) (find-file (find-library-name candidate
))))
6659 ("Find library other window"
6660 .
(lambda (candidate)
6661 (find-file-other-window (find-library-name candidate
))))
6663 .
(lambda (candidate) (load-library candidate
))))))
6664 ;; (anything 'anything-c-source-elisp-library-scan)
6666 (defun anything-c-elisp-library-scan-init ()
6667 "Init anything buffer status."
6668 (let ((anything-buffer (anything-candidate-buffer 'global
))
6669 (library-list (anything-c-elisp-library-scan-list)))
6670 (with-current-buffer anything-buffer
6671 (dolist (library library-list
)
6672 (insert (format "%s\n" library
))))))
6674 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
6675 "Do completion for file names passed to `locate-file'.
6676 DIRS is directory to search path.
6677 STRING is string to match."
6678 ;; Use `load-path' as path when ignore `dirs'.
6679 (or dirs
(setq dirs load-path
))
6680 ;; Init with blank when ignore `string'.
6681 (or string
(setq string
""))
6682 ;; Get library list.
6683 (let ((string-dir (file-name-directory string
))
6684 ;; File regexp that suffix match `load-file-rep-suffixes'.
6685 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
6690 (setq dir default-directory
))
6692 (setq dir
(expand-file-name string-dir dir
)))
6693 (when (file-directory-p dir
)
6694 (dolist (file (file-name-all-completions
6695 (file-name-nondirectory string
) dir
))
6696 ;; Suffixes match `load-file-rep-suffixes'.
6697 (setq name
(if string-dir
(concat string-dir file
) file
))
6698 (if (string-match match-regexp name
)
6699 (add-to-list 'names name
)))))
6710 (defvar anything-c-imenu-delimiter
" / ")
6712 (defvar anything-c-imenu-index-filter nil
)
6713 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
6715 (defvar anything-c-cached-imenu-alist nil
)
6716 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
6718 (defvar anything-c-cached-imenu-candidates nil
)
6719 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
6721 (defvar anything-c-cached-imenu-tick nil
)
6722 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
6724 (eval-when-compile (require 'imenu
))
6725 (setq imenu-auto-rescan t
)
6727 (defun anything-imenu-create-candidates (entry)
6728 "Create candidates with ENTRY."
6729 (if (listp (cdr entry
))
6732 (if (consp (cdr sub
))
6735 (concat (car entry
) anything-c-imenu-delimiter subentry
))
6736 (anything-imenu-create-candidates sub
))
6737 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
6741 (defvar anything-c-source-imenu
6743 (init .
(lambda () (require 'imenu
)))
6744 (candidates . anything-c-imenu-candidates
)
6745 (persistent-action .
(lambda (elm)
6746 (anything-c-imenu-default-action elm
)
6747 (unless (fboundp 'semantic-imenu-tag-overlay
)
6748 (anything-match-line-color-current-line))))
6749 (persistent-help .
"Show this entry")
6750 (action . anything-c-imenu-default-action
))
6751 "See (info \"(emacs)Imenu\")")
6753 ;; (anything 'anything-c-source-imenu)
6755 (defun anything-c-imenu-candidates ()
6756 (with-anything-current-buffer
6757 (let ((tick (buffer-modified-tick)))
6758 (if (eq anything-c-cached-imenu-tick tick
)
6759 anything-c-cached-imenu-candidates
6760 (setq imenu--index-alist nil
)
6761 (setq anything-c-cached-imenu-tick tick
6762 anything-c-cached-imenu-candidates
6765 'anything-imenu-create-candidates
6766 (setq anything-c-cached-imenu-alist
6767 (let ((index (imenu--make-index-alist)))
6768 (if anything-c-imenu-index-filter
6769 (funcall anything-c-imenu-index-filter index
)
6771 (setq anything-c-cached-imenu-candidates
6772 (mapcar #'(lambda (x)
6776 anything-c-cached-imenu-candidates
))))))
6778 (setq imenu-default-goto-function
'imenu-default-goto-function
)
6779 (defun anything-c-imenu-default-action (elm)
6780 "The default action for `anything-c-source-imenu'."
6781 (let ((path (split-string elm anything-c-imenu-delimiter
))
6782 (alist anything-c-cached-imenu-alist
))
6784 (setq alist
(assoc elm alist
)))
6792 (defvar anything-c-ctags-modes
6793 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6794 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6795 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
6797 (defun anything-c-source-ctags-init ()
6798 (when (and buffer-file-name
6799 (memq major-mode anything-c-ctags-modes
)
6800 (anything-current-buffer-is-modified))
6801 (with-current-buffer (anything-candidate-buffer 'local
)
6802 (call-process-shell-command
6803 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
6804 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6805 anything-buffer-file-name
)
6806 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
6807 nil
(current-buffer))
6808 (goto-char (point-min))
6810 (delete-region (point-min) (point))
6811 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
6812 for lineno-start
= (point)
6813 for lineno
= (buffer-substring
6815 (1- (search-forward "," (point-at-eol) t
)))
6818 (insert (format "%5s:" lineno
))
6819 (search-forward "\177" (point-at-eol) t
)
6820 (delete-region (1- (point)) (point-at-eol))
6821 (forward-line 1)))))
6823 (defvar anything-c-source-ctags
6824 '((name .
"Exuberant ctags")
6825 (init . anything-c-source-ctags-init
)
6826 (candidates-in-buffer)
6829 "Needs Exuberant Ctags.
6831 http://ctags.sourceforge.net/")
6832 ;; (anything 'anything-c-source-ctags)
6838 ;; anything-etags.el is deprecated, if this file is found,
6839 ;; warn user at compile time.
6841 (when (locate-library "anything-etags.el")
6844 "You are using obsolete library `anything-etags.el' and should remove it."
6847 (defvar anything-c-etags-tag-file-dir nil
6848 "Etags file directory.")
6849 (defvar anything-c-etags-mtime-alist nil
6850 "Store the last modification time of etags files here.")
6851 (defvar anything-c-etags-cache
(make-hash-table :test
'equal
)
6852 "Cache content of etags files used here for faster access.")
6854 (defun anything-c-etags-get-tag-file (&optional directory
)
6855 "Return the path of etags file if found."
6856 ;; Get tag file from `default-directory' or upper directory.
6857 (let ((current-dir (anything-c-etags-find-tag-file-directory
6858 (or directory default-directory
))))
6859 ;; Return nil if not find tag file.
6861 ;; Set tag file directory.
6862 (setq anything-c-etags-tag-file-dir current-dir
)
6863 (expand-file-name anything-c-etags-tag-file-name current-dir
))))
6865 (defun anything-c-etags-find-tag-file-directory (current-dir)
6866 "Try to find the directory containing tag file.
6867 If not found in CURRENT-DIR search in upper directory."
6868 (flet ((file-exists?
(dir)
6869 (let ((tag-path (expand-file-name
6870 anything-c-etags-tag-file-name dir
)))
6871 (and (stringp tag-path
)
6872 (file-exists-p tag-path
)
6873 (file-readable-p tag-path
)))))
6874 (loop with count
= 0
6875 until
(file-exists? current-dir
)
6876 ;; Return nil if outside the value of
6877 ;; `anything-c-etags-tag-file-search-limit'.
6878 if
(= count anything-c-etags-tag-file-search-limit
)
6880 ;; Or search upper directories.
6883 (setq current-dir
(expand-file-name (concat current-dir
"../")))
6884 finally return current-dir
)))
6886 (defun anything-c-source-etags-header-name (x)
6887 "Create header name for this anything etags session."
6889 (with-anything-current-buffer
6890 (anything-c-etags-get-tag-file))))
6892 (defmacro anything-c-etags-create-buffer
(file)
6893 "Create the `anything-buffer' based on contents of etags tag FILE."
6894 `(let* ((tag-fname ,file
)
6896 (split (with-current-buffer (find-file-noselect tag-fname
)
6898 (split-string (buffer-string) "\n" 'omit-nulls
)
6899 (setq max
(line-number-at-pos (point-max)))
6901 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max
)))
6905 for i in split for count from
0
6906 for elm
= (unless (string-match "^\x0c" i
)
6907 (anything-aif (string-match "\177" i
)
6910 do
(cond ((and elm
(string-match "^\\(.+\\),[0-9]+" elm
))
6911 (setq fname
(match-string 1 elm
)))
6912 (elm (setq cand
(concat fname
": " elm
)))
6913 (t (setq cand nil
)))
6915 (insert (concat cand
"\n"))
6916 (progress-reporter-update progress-reporter count
)))))
6918 (defun anything-c-etags-init ()
6919 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
6920 If no entry in cache, create one."
6921 (let ((tagfile (anything-c-etags-get-tag-file)))
6923 (with-current-buffer (anything-candidate-buffer 'global
)
6924 (anything-aif (gethash tagfile anything-c-etags-cache
)
6925 ;; An entry is present in cache, insert it.
6927 ;; No entry, create a new buffer using content of tag file (slower).
6928 (anything-c-etags-create-buffer tagfile
)
6929 ;; Store content of buffer in cache.
6930 (puthash tagfile
(buffer-string) anything-c-etags-cache
)
6931 ;; Store or set the last modification of tag file.
6932 (anything-aif (assoc tagfile anything-c-etags-mtime-alist
)
6933 ;; If an entry exists modify it.
6934 (setcdr it
(anything-c-etags-mtime tagfile
))
6935 ;; No entry create a new one.
6936 (add-to-list 'anything-c-etags-mtime-alist
6937 (cons tagfile
(anything-c-etags-mtime tagfile
)))))))))
6939 (defvar anything-c-source-etags-select
6941 (header-name . anything-c-source-etags-header-name
)
6942 (init . anything-c-etags-init
)
6943 (candidates-in-buffer)
6944 (search .
(anything-c-etags-search-fn))
6945 (mode-line . anything-etags-mode-line-string
)
6946 (action . anything-c-etags-default-action
)
6947 (persistent-action .
(lambda (candidate)
6948 (anything-c-etags-default-action candidate
)
6949 (anything-match-line-color-current-line))))
6950 "Anything source for Etags.")
6952 (defun anything-c-etags-search-fn (pattern bound noerror
)
6953 "Search function for `anything-c-source-etags-select'."
6955 (if anything-c-etags-use-regexp-search
(concat "\\_<" pattern
) pattern
)
6958 (defun anything-c-etags-default-action (candidate)
6959 "Anything default action to jump to an etags entry."
6960 (let* ((split (split-string candidate
": "))
6961 (fname (expand-file-name
6962 (car split
) anything-c-etags-tag-file-dir
))
6965 (goto-char (point-min))
6966 (search-forward elm nil t
)
6967 (goto-char (match-beginning 0))))
6969 (defun anything-c-etags-mtime (file)
6970 "Last modification time of etags tag FILE."
6971 (cadr (nth 5 (file-attributes file
))))
6973 (defun anything-c-etags-file-modified-p (file)
6974 "Check if tag FILE have been modified in this session.
6975 If FILE is nil return nil."
6976 (let ((last-modif (and file
6977 (assoc-default file anything-c-etags-mtime-alist
))))
6979 (/= last-modif
(anything-c-etags-mtime file
)))))
6986 (defvar anything-semantic-candidates nil
)
6988 (defun anything-semantic-construct-candidates (tags depth
)
6989 (when (require 'semantic nil t
)
6995 (let ((type (semantic-tag-type tag
))
6996 (class (semantic-tag-class tag
)))
6997 (if (or (and (stringp type
)
6998 (or (string= type
"class")
6999 (string= type
"namespace")))
7000 (eq class
'function
)
7001 (eq class
'variable
))
7002 (cons (cons (concat (make-string (* depth
2) ?\s
)
7003 (semantic-format-tag-summarize tag nil t
))
7005 (anything-semantic-construct-candidates
7006 (semantic-tag-components tag
) (1+ depth
)))))))
7009 (defun anything-semantic-default-action (candidate)
7010 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
7011 (semantic-go-to-tag tag
)))
7013 (defvar anything-c-source-semantic
7014 '((name .
"Semantic Tags")
7016 (setq anything-semantic-candidates
7017 (ignore-errors (anything-semantic-construct-candidates
7018 (semantic-fetch-tags) 0)))))
7019 (candidates .
(lambda ()
7020 (if anything-semantic-candidates
7021 (mapcar 'car anything-semantic-candidates
))))
7022 (persistent-action .
(lambda (elm)
7023 (anything-semantic-default-action elm
)
7024 (anything-match-line-color-current-line)))
7025 (persistent-help .
"Show this entry")
7026 (action . anything-semantic-default-action
)
7027 "Needs semantic in CEDET.
7029 http://cedet.sourceforge.net/semantic.shtml
7030 http://cedet.sourceforge.net/"))
7032 ;; (anything 'anything-c-source-semantic)
7035 ;;; Anything interface of `simple-call-tree.el'.
7037 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7039 ;; Function is called by
7040 (defvar anything-c-source-simple-call-tree-functions-callers
7041 '((name .
"Function is called by")
7042 (init . anything-c-simple-call-tree-functions-callers-init
)
7044 (candidates . anything-c-simple-call-tree-candidates
)
7045 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7046 (persistent-help .
"Show function definitions by rotation")
7047 (action ("Find definition selected by persistent-action" .
7048 anything-c-simple-call-tree-find-definition
)))
7049 "Needs simple-call-tree.el.
7050 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7052 (defvar anything-c-simple-call-tree-tick nil
)
7053 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
7054 (defun anything-c-simple-call-tree-analyze-maybe ()
7055 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
7056 (simple-call-tree-analyze)
7057 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
7059 (defun anything-c-simple-call-tree-init-base (function message
)
7060 (require 'simple-call-tree
)
7062 (when (anything-current-buffer-is-modified)
7063 (anything-c-simple-call-tree-analyze-maybe)
7064 (let ((list (funcall function simple-call-tree-alist
)))
7065 (with-current-buffer (anything-candidate-buffer 'local
)
7066 (dolist (entry list
)
7067 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
7068 (insert (car entry
) message
7069 (if (string= funcs
" ")
7074 (defun anything-c-simple-call-tree-functions-callers-init ()
7075 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7078 (defun anything-c-simple-call-tree-candidates ()
7079 (with-current-buffer (anything-candidate-buffer)
7080 (split-string (buffer-string) "\n\n")))
7082 (defvar anything-c-simple-call-tree-related-functions nil
)
7083 (defvar anything-c-simple-call-tree-function-index
0)
7084 (defun anything-c-simple-call-tree-persistent-action (candidate)
7085 (unless (eq last-command
'anything-execute-persistent-action
)
7086 (setq anything-c-simple-call-tree-related-functions
7087 (delete "no functions."
7089 (replace-regexp-in-string " \\| is called by\\| calls "
7092 (setq anything-c-simple-call-tree-function-index -
1))
7093 (incf anything-c-simple-call-tree-function-index
)
7094 (anything-c-simple-call-tree-find-definition candidate
))
7096 (defun anything-c-simple-call-tree-find-definition (candidate)
7099 (nth (mod anything-c-simple-call-tree-function-index
7100 (length anything-c-simple-call-tree-related-functions
))
7101 anything-c-simple-call-tree-related-functions
))))
7103 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7106 (defvar anything-c-source-simple-call-tree-callers-functions
7107 '((name .
"Function calls")
7108 (init . anything-c-simple-call-tree-callers-functions-init
)
7110 (candidates . anything-c-simple-call-tree-candidates
)
7111 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7112 (persistent-help .
"Show function definitions by rotation")
7113 (action ("Find definition selected by persistent-action" .
7114 anything-c-simple-call-tree-find-definition
)))
7115 "Needs simple-call-tree.el.
7116 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7118 (defun anything-c-simple-call-tree-callers-functions-init ()
7119 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
7121 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7125 ;;; Anything UI of auto-document.el
7127 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7129 ;; Commands/Options with doc
7130 (defvar anything-c-auto-document-data nil
)
7131 (make-variable-buffer-local 'anything-c-auto-document-data
)
7132 (defvar anything-c-source-commands-and-options-in-file
7133 '((name .
"Commands/Options in file")
7135 .
(lambda (x) (format "Commands/Options in %s"
7136 (buffer-local-value 'buffer-file-name
7137 anything-current-buffer
))))
7138 (candidates . anything-command-and-options-candidates
)
7141 "List Commands and Options with doc. It needs auto-document.el .
7143 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7145 (eval-when-compile (require 'auto-document nil t
))
7146 (defun anything-command-and-options-candidates ()
7147 (with-anything-current-buffer
7148 (when (and (require 'auto-document nil t
)
7149 (eq major-mode
'emacs-lisp-mode
)
7150 (or (anything-current-buffer-is-modified)
7151 (not anything-c-auto-document-data
)))
7152 (or imenu--index-alist
(imenu--make-index-alist t
))
7153 (setq anything-c-auto-document-data
7154 (destructuring-bind (commands options
)
7155 (adoc-construct anything-current-buffer
)
7157 (loop for
(command . doc
) in commands
7158 for cmdname
= (symbol-name command
)
7161 (format "Command: %s\n %s"
7162 (propertize cmdname
'face font-lock-function-name-face
)
7163 (adoc-first-line doc
))
7164 (assoc cmdname imenu--index-alist
)))
7165 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
7166 for
(option doc default
) in options
7167 for optname
= (symbol-name option
)
7170 (format "Option: %s\n %s\n default = %s"
7171 (propertize optname
'face font-lock-variable-name-face
)
7172 (adoc-first-line doc
)
7173 (adoc-prin1-to-string default
))
7176 anything-c-auto-document-data
))
7178 ;; (anything 'anything-c-source-commands-and-options-in-file)
7181 ;;;; <Color and Face>
7187 (defvar anything-c-source-customize-face
7188 '((name .
"Customize Face")
7190 (unless (anything-candidate-buffer)
7191 (save-window-excursion (list-faces-display))
7192 (anything-candidate-buffer (get-buffer "*Faces*")))))
7193 (candidates-in-buffer)
7194 (get-line . buffer-substring
)
7195 (action .
(lambda (line)
7196 (customize-face (intern (car (split-string line
))))))
7197 (requires-pattern .
3))
7198 "See (info \"(emacs)Faces\")")
7199 ;; (anything 'anything-c-source-customize-face)
7204 (defvar anything-c-source-colors
7206 (init .
(lambda () (unless (anything-candidate-buffer)
7207 (save-window-excursion (list-colors-display))
7208 (anything-candidate-buffer (get-buffer "*Colors*")))))
7209 (candidates-in-buffer)
7210 (get-line . buffer-substring
)
7212 ("Copy Name" .
(lambda (candidate)
7213 (kill-new (anything-c-colors-get-name candidate
))))
7214 ("Copy RGB" .
(lambda (candidate)
7215 (kill-new (anything-c-colors-get-rgb candidate
))))
7216 ("Insert Name" .
(lambda (candidate)
7217 (with-anything-current-buffer
7218 (insert (anything-c-colors-get-name candidate
)))))
7219 ("Insert RGB" .
(lambda (candidate)
7220 (with-anything-current-buffer
7221 (insert (anything-c-colors-get-rgb candidate
))))))))
7222 ;; (anything 'anything-c-source-colors)
7224 (defun anything-c-colors-get-name (candidate)
7226 (replace-regexp-in-string
7229 (insert (capitalize candidate
))
7230 (goto-char (point-min))
7231 (search-forward-regexp "\\s-\\{2,\\}")
7232 (delete-region (point) (point-max))
7235 (defun anything-c-colors-get-rgb (candidate)
7237 (replace-regexp-in-string
7240 (insert (capitalize candidate
))
7241 (goto-char (point-max))
7242 (search-backward-regexp "\\s-\\{2,\\}")
7243 (delete-region (point) (point-min))
7247 ;;;; <Search Engine>
7248 ;;; Tracker desktop search
7249 (defvar anything-c-source-tracker-search
7250 '((name .
"Tracker Search")
7251 (candidates .
(lambda ()
7252 (start-process "tracker-search-process" nil
7256 (requires-pattern .
3)
7258 "Source for retrieving files matching the current input pattern
7259 with the tracker desktop search.")
7260 ;; (anything 'anything-c-source-tracker-search)
7262 ;;; Spotlight (MacOS X desktop search)
7263 (defvar anything-c-source-mac-spotlight
7266 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
7268 (requires-pattern .
3)
7270 "Source for retrieving files via Spotlight's command line
7272 ;; (anything 'anything-c-source-mac-spotlight)
7275 (defvar anything-c-source-picklist
7276 '((name .
"Picklist")
7277 (candidates .
(lambda () (mapcar 'car picklist-list
)))
7279 ;; (anything 'anything-c-source-picklist)
7286 (defvar anything-c-source-kill-ring
7287 '((name .
"Kill Ring")
7288 (init .
(lambda () (anything-attrset 'last-command last-command
)))
7289 (candidates . anything-c-kill-ring-candidates
)
7290 (filtered-candidate-transformer anything-c-kill-ring-transformer
)
7291 (action . anything-c-kill-ring-action
)
7295 "Source for browse and insert contents of kill-ring.")
7297 (defun anything-c-kill-ring-candidates ()
7298 (loop for kill in
(anything-fast-remove-dups kill-ring
:test
'equal
)
7299 unless
(or (< (length kill
) anything-kill-ring-threshold
)
7300 (string-match "^[\\s\\t]+$" kill
))
7303 (defun anything-c-kill-ring-transformer (candidates source
)
7304 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7305 (loop for i in candidates
7306 for nlines
= (with-temp-buffer (insert i
) (count-lines (point-min) (point-max)))
7307 if
(and anything-c-kill-ring-max-lines-number
7308 (> nlines anything-c-kill-ring-max-lines-number
))
7312 (goto-char (point-min))
7317 (forward-line anything-c-kill-ring-max-lines-number
)
7322 (defun anything-c-kill-ring-action (str)
7323 "Insert STR in `kill-ring' and set STR to the head.
7324 If this action is executed just after `yank',
7325 replace with STR as yanked string."
7326 (setq kill-ring
(delete str kill-ring
))
7327 (if (not (eq (anything-attr 'last-command
) 'yank
))
7328 (insert-for-yank str
)
7330 (let ((inhibit-read-only t
)
7331 (before (< (point) (mark t
))))
7333 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
7334 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
7335 (setq yank-undo-function nil
)
7336 (set-marker (mark-marker) (point) (current-buffer))
7337 (insert-for-yank str
)
7338 ;; Set the window start back where it was in the yank command,
7340 (set-window-start (selected-window) yank-window-start t
)
7342 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7343 ;; It is cleaner to avoid activation, even though the command
7344 ;; loop would deactivate the mark because we inserted text.
7345 (goto-char (prog1 (mark t
)
7346 (set-marker (mark-marker) (point) (current-buffer)))))))
7349 ;; (anything 'anything-c-source-kill-ring)
7353 ;; DO NOT include these sources in `anything-sources' use
7354 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7355 ;; `anything-all-mark-rings' instead.
7357 (defun anything-c-source-mark-ring-candidates ()
7358 (flet ((get-marks (pos)
7362 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
7363 (when (string= "" line
)
7364 (setq line
"<EMPTY LINE>"))
7365 (format "%7d: %s" (line-number-at-pos) line
)))))
7366 (with-anything-current-buffer
7368 with marks
= (if (mark) (cons (mark-marker) mark-ring
) mark-ring
)
7371 for m
= (get-marks i
)
7372 unless
(member m recip
)
7373 collect m into recip
7374 finally return recip
))))
7376 (defvar anything-mark-ring-cache nil
)
7377 (defvar anything-c-source-mark-ring
7378 '((name .
"mark-ring")
7380 (setq anything-mark-ring-cache
7381 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7382 (candidates .
(lambda ()
7383 (anything-aif anything-mark-ring-cache
7385 (action .
(("Goto line"
7386 .
(lambda (candidate)
7387 (anything-goto-line (string-to-number candidate
))))))
7388 (persistent-action .
(lambda (candidate)
7389 (anything-goto-line (string-to-number candidate
))
7390 (anything-match-line-color-current-line)))
7391 (persistent-help .
"Show this line")))
7393 ;; (anything 'anything-c-source-mark-ring)
7395 ;;; Global-mark-ring
7396 (defvar anything-c-source-global-mark-ring
7397 '((name .
"global-mark-ring")
7398 (candidates . anything-c-source-global-mark-ring-candidates
)
7399 (action .
(("Goto line"
7400 .
(lambda (candidate)
7401 (let ((items (split-string candidate
":")))
7402 (anything-c-switch-to-buffer (second items
))
7403 (anything-goto-line (string-to-number (car items
))))))))
7404 (persistent-action .
(lambda (candidate)
7405 (let ((items (split-string candidate
":")))
7406 (anything-c-switch-to-buffer (second items
))
7407 (anything-goto-line (string-to-number (car items
)))
7408 (anything-match-line-color-current-line))))
7409 (persistent-help .
"Show this line")))
7411 (defun anything-c-source-global-mark-ring-candidates ()
7413 (with-current-buffer (marker-buffer m
)
7417 (if (string= "" line
)
7418 (setq line
"<EMPTY LINE>")
7419 (setq line
(car (split-string (thing-at-point 'line
)
7421 (format "%7d:%s: %s"
7422 (line-number-at-pos) (marker-buffer m
) line
)))))
7424 with marks
= global-mark-ring
7427 for gm
= (unless (or (string-match
7428 "^ " (format "%s" (marker-buffer i
)))
7429 (null (marker-buffer i
)))
7431 when
(and gm
(not (member gm recip
)))
7432 collect gm into recip
7433 finally return recip
)))
7435 ;; (anything 'anything-c-source-global-mark-ring)
7439 ;;; Insert from register
7440 (defvar anything-c-source-register
7441 '((name .
"Registers")
7442 (candidates . anything-c-register-candidates
)
7443 (action-transformer . anything-c-register-action-transformer
)
7446 "See (info \"(emacs)Registers\")")
7448 (defun anything-c-register-candidates ()
7449 "Collecting register contents and appropriate commands."
7450 (loop for
(char . val
) in register-alist
7451 for key
= (single-key-description char
)
7452 for string-actions
=
7455 (list (int-to-string val
)
7457 'increment-register
))
7459 (let ((buf (marker-buffer val
)))
7461 (list "a marker in no buffer")
7463 "a buffer position:"
7466 (int-to-string (marker-position val
)))
7468 'insert-register
))))
7469 ((and (consp val
) (window-configuration-p (car val
)))
7470 (list "window configuration."
7472 ((and (consp val
) (frame-configuration-p (car val
)))
7473 (list "frame configuration."
7475 ((and (consp val
) (eq (car val
) 'file
))
7476 (list (concat "file:"
7477 (prin1-to-string (cdr val
))
7480 ((and (consp val
) (eq (car val
) 'file-query
))
7481 (list (concat "file:a file-query reference: file "
7484 (int-to-string (car (cdr (cdr val
))))
7488 (let ((lines (format "%4d" (length val
))))
7489 (list (format "%s: %s\n" lines
7490 (truncate-string-to-width
7491 (mapconcat 'identity
(list (car val
))
7492 ;; (mapconcat (lambda (y) y) val
7493 "^J") (- (window-width) 15)))
7496 (list ;; without properties
7497 (substring-no-properties val
)
7500 'prepend-to-register
))
7503 collect
(cons (format "register %3s: %s" key
(car string-actions
))
7504 (cons char
(cdr string-actions
)))))
7506 (defun anything-c-register-action-transformer (actions register-and-functions
)
7507 "Decide actions by the contents of register."
7508 (loop with func-actions
=
7511 (lambda (c) (insert-register (car c
))))
7513 "Jump to Register" .
7514 (lambda (c) (jump-to-register (car c
))))
7516 "Append Region to Register" .
7517 (lambda (c) (append-to-register
7518 (car c
) (region-beginning) (region-end))))
7519 (prepend-to-register
7520 "Prepend Region to Register" .
7521 (lambda (c) (prepend-to-register
7522 (car c
) (region-beginning) (region-end))))
7524 "Increment Prefix Arg to Register" .
7525 (lambda (c) (increment-register
7526 anything-current-prefix-arg
(car c
)))))
7527 for func in
(cdr register-and-functions
)
7528 for cell
= (assq func func-actions
)
7530 collect
(cdr cell
)))
7532 ;; (anything 'anything-c-source-register)
7535 ;;; Latex completion
7536 (defun anything-c-latex-math-candidates ()
7537 "Collect candidates for latex math completion."
7538 (declare (special LaTeX-math-menu
))
7539 (loop for i in
(cddr LaTeX-math-menu
)
7540 for elm
= (loop for s in i when
(vectorp s
)
7541 collect
(cons (aref s
0) (aref s
1)))
7544 (defvar anything-c-source-latex-math
7545 '((name .
"Latex Math Menu")
7547 (with-anything-current-buffer
7548 (LaTeX-math-mode 1))))
7549 (candidate-number-limit .
9999)
7550 (candidates . anything-c-latex-math-candidates
)
7551 (action .
(lambda (candidate)
7552 (call-interactively candidate
)))))
7555 ;;;; <Headline Extraction>
7556 (defvar anything-c-source-fixme
7557 '((name .
"TODO/FIXME/DRY comments")
7558 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7561 "Show TODO/FIXME/DRY comments in current file.")
7562 ;; (anything 'anything-c-source-fixme)
7564 (defvar anything-c-source-rd-headline
7565 '((name .
"RD HeadLine")
7566 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7567 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
7573 http://en.wikipedia.org/wiki/Ruby_Document_format")
7574 ;; (anything 'anything-c-source-rd-headline)
7576 (defvar anything-c-source-oddmuse-headline
7577 '((name .
"Oddmuse HeadLine")
7578 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7579 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7580 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
7583 "Show Oddmuse headlines, such as EmacsWiki.")
7584 ;; (anything 'anything-c-source-oddmuse-headline)
7586 (defvar anything-c-source-emacs-source-defun
7587 '((name .
"Emacs Source DEFUN")
7588 (headline .
"DEFUN\\|DEFVAR")
7589 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
7590 (or buffer-file-name
""))))
7591 "Show DEFUN/DEFVAR in Emacs C source file.")
7592 ;; (anything 'anything-c-source-emacs-source-defun)
7594 (defvar anything-c-source-emacs-lisp-expectations
7595 '((name .
"Emacs Lisp Expectations")
7596 (headline .
"(desc[ ]\\|(expectations")
7597 (condition .
(eq major-mode
'emacs-lisp-mode
)))
7598 "Show descriptions (desc) in Emacs Lisp Expectations.
7600 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7601 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7603 (defvar anything-c-source-emacs-lisp-toplevels
7604 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7605 (headline .
"^(\\|(@\\*\\|^;;;;")
7606 (get-line . buffer-substring
)
7607 (condition .
(eq major-mode
'emacs-lisp-mode
))
7609 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7610 linkd.el is optional because linkd stars are extracted by regexp.
7611 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7612 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7615 ;;; Anything yaoddmuse
7617 ;; Be sure to have yaoddmuse.el installed
7618 ;; install-elisp may be required if you want to install elisp file from here.
7619 (defvar anything-yaoddmuse-use-cache-file nil
)
7620 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
7621 (defvar anything-c-yaoddmuse-ew-cache nil
)
7623 (defun anything-yaoddmuse-get-candidates ()
7624 (declare (special yaoddmuse-pages-hash
))
7625 (if anything-yaoddmuse-use-cache-file
7627 (unless anything-c-yaoddmuse-ew-cache
7628 (load anything-c-yaoddmuse-cache-file
)
7629 (setq anything-c-yaoddmuse-ew-cache
7630 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7631 anything-c-yaoddmuse-ew-cache
)
7632 (yaoddmuse-update-pagename t
)
7633 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7635 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7636 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
7637 (candidates . anything-yaoddmuse-get-candidates
)
7638 (action .
(("Edit page" .
(lambda (candidate)
7639 (yaoddmuse-edit "EmacsWiki" candidate
)))
7641 .
(lambda (candidate)
7642 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
7643 ("Browse page other window"
7644 .
(lambda (candidate)
7646 (split-window-vertically))
7647 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
7649 .
(lambda (candidate)
7650 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
7652 .
(lambda (candidate)
7653 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
7654 (message "Have copy page %s's URL to yank." candidate
)))
7656 .
(lambda (candidate)
7657 (yaoddmuse-edit "EmacsWiki" anything-input
)))
7659 .
(lambda (candidate)
7660 (if anything-yaoddmuse-use-cache-file
7662 (anything-yaoddmuse-cache-pages t
)
7663 (setq anything-c-yaoddmuse-ew-cache
7664 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7665 (yaoddmuse-update-pagename))))))
7666 (action-transformer anything-c-yaoddmuse-action-transformer
))
7667 "Needs yaoddmuse.el.
7669 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7671 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7673 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7674 '((name .
"Yaoddmuse Post library (EmacsWiki)")
7675 (init .
(anything-yaoddmuse-init))
7676 (candidates-in-buffer)
7677 (action .
(("Post library and Browse"
7678 .
(lambda (candidate)
7679 (yaoddmuse-post-file
7680 (find-library-name candidate
)
7682 (file-name-nondirectory (find-library-name candidate
))
7685 .
(lambda (candidate)
7686 (yaoddmuse-post-file
7687 (find-library-name candidate
)
7689 (file-name-nondirectory
7690 (find-library-name candidate
))))))))
7691 "Needs yaoddmuse.el.
7693 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7695 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7697 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
7698 "Allow the use of `install-elisp' only on elisp files."
7699 (if (string-match "\.el$" candidate
)
7700 (append actions
'(("Install Elisp"
7702 (install-elisp-from-emacswiki elm
)))))
7706 (defun anything-yaoddmuse-cache-pages (&optional load
)
7707 "Fetch the list of files on emacswiki and create cache file.
7708 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7710 (declare (special yaoddmuse-pages-hash
))
7711 (yaoddmuse-update-pagename)
7713 (find-file anything-c-yaoddmuse-cache-file
)
7715 (insert "(puthash \"EmacsWiki\" '(")
7716 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
7718 (insert (concat "(\"" (car i
) "\") ")))
7719 (insert ") yaoddmuse-pages-hash)\n")
7721 (kill-buffer (current-buffer))
7722 (when (or current-prefix-arg
7724 (load anything-c-yaoddmuse-cache-file
))))
7726 (defun anything-yaoddmuse-init ()
7727 "Init anything buffer status."
7728 (let ((anything-buffer (anything-candidate-buffer 'global
))
7729 (library-list (yaoddmuse-get-library-list)))
7730 (with-current-buffer anything-buffer
7731 ;; Insert library name.
7732 (dolist (library library-list
)
7733 (insert (format "%s\n" library
)))
7735 (sort-lines nil
(point-min) (point-max)))))
7739 (defvar anything-c-source-eev-anchor
7740 '((name .
"Anchors")
7744 (with-anything-current-buffer
7745 (loop initially
(goto-char (point-min))
7746 while
(re-search-forward
7747 (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
7748 for anchor
= (match-string-no-properties 1)
7749 collect
(cons (format "%5d:%s"
7750 (line-number-at-pos (match-beginning 0))
7751 (format ee-anchor-format anchor
))
7753 (persistent-action .
(lambda (item)
7755 (anything-match-line-color-current-line)))
7756 (persistent-help .
"Show this entry")
7757 (action .
(("Goto link" . ee-to
)))))
7758 ;; (anything 'anything-c-source-eev-anchor)
7764 (defvar anything-c-source-org-headline
7765 `((name .
"Org HeadLine")
7769 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7771 (number-sequence 1 8)))
7772 (condition .
(eq major-mode
'org-mode
))
7775 (persistent-action .
(lambda (elm)
7776 (anything-c-action-line-goto elm
)
7779 .
(lambda (actions candidate
)
7780 '(("Go to Line" . anything-c-action-line-goto
)
7781 ("Refile to this Headline" . anything-c-org-headline-refile
)
7782 ("Insert Link to This Headline"
7783 . anything-c-org-headline-insert-link-to-headline
)))))
7784 "Show Org headlines.
7785 org-mode is very very much extended text-mode/outline-mode.
7787 See (find-library \"org.el\")
7788 See http://orgmode.org for the latest version.")
7789 ;; (anything 'anything-c-source-org-headline)
7791 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7794 (anything-goto-line (car lineno-and-content
))
7795 (and (looking-at org-complex-heading-regexp
)
7796 (org-make-link-string (concat "*" (match-string 4)))))))
7798 (defun anything-c-org-headline-refile (lineno-and-content)
7799 "Refile current org entry to LINENO-AND-CONTENT."
7800 (with-anything-current-buffer
7802 (anything-goto-line (car lineno-and-content
))
7803 (org-end-of-subtree t t
)
7804 (let ((org-yank-adjusted-subtrees t
))
7811 (defvar anything-c-source-org-keywords
7812 '((name .
"Org Keywords")
7813 (init . anything-c-org-keywords-init
)
7814 (candidates . anything-c-org-keywords-candidates
)
7815 (action . anything-c-org-keywords-insert
)
7816 (persistent-action . anything-c-org-keywords-show-help
)
7817 (persistent-help .
"Show an example and info page to describe this keyword.")
7820 ;; (anything 'anything-c-source-org-keywords)
7822 (defvar anything-c-org-keywords-info-location
7823 '(("#+TITLE:" .
"(org)Export options")
7824 ("#+AUTHOR:" .
"(org)Export options")
7825 ("#+DATE:" .
"(org)Export options")
7826 ("#+EMAIL:" .
"(org)Export options")
7827 ("#+DESCRIPTION:" .
"(org)Export options")
7828 ("#+KEYWORDS:" .
"(org)Export options")
7829 ("#+LANGUAGE:" .
"(org)Export options")
7830 ("#+TEXT:" .
"(org)Export options")
7831 ("#+TEXT:" .
"(org)Export options")
7832 ("#+OPTIONS:" .
"(org)Export options")
7833 ("#+BIND:" .
"(org)Export options")
7834 ("#+LINK_UP:" .
"(org)Export options")
7835 ("#+LINK_HOME:" .
"(org)Export options")
7836 ("#+LATEX_HEADER:" .
"(org)Export options")
7837 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
7838 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
7839 ("#+INFOJS_OPT" .
"(org)Javascript support")
7840 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
7841 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
7842 ("#+ORGTBL" .
"(org)Radio tables")
7843 ("#+HTML:" .
"(org)Quoting HTML tags")
7844 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
7845 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
7846 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
7847 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
7848 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
7849 ("#+BEGIN_SRC" .
"(org)Literal examples")
7850 ("#+CAPTION" .
"(org)Tables in HTML export")
7851 ("#+LABEL" .
"(org)Tables in LaTeX export")
7852 ("#+ATTR_HTML" .
"(org)Links")
7853 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
7855 (defun anything-c-org-keywords-init ()
7856 (unless (anything-attr 'keywords-examples
)
7858 (anything-attrset 'keywords-examples
7862 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
7863 (cons (match-string 2 x
) (match-string 1 x
)))
7864 (org-split-string (org-get-current-options) "\n"))
7865 (mapcar 'list org-additional-option-like-keywords
)))
7866 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
7868 (defun anything-c-org-keywords-candidates ()
7869 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
7870 (eq (buffer-local-value 'major-mode anything-current-buffer
) 'message-mode
))
7871 (anything-attr 'keywords
)))
7873 (defun anything-c-org-keywords-insert (keyword)
7874 (cond ((and (string-match "BEGIN" keyword
)
7875 (anything-region-active-p))
7876 (let ((beg (region-beginning))
7879 (insert "\n#+" (replace-regexp-in-string
7880 "BEGIN" "END" keyword
) "\n")
7882 (insert "#+" keyword
" ")
7883 (save-excursion (insert "\n"))))
7884 ((string-match "BEGIN" keyword
)
7885 (insert "#+" keyword
" ")
7887 (insert "\n#+" (replace-regexp-in-string
7888 "BEGIN" "END" keyword
) "\n")))
7889 (t (insert "#+" keyword
" "))))
7891 (defun anything-c-org-keywords-show-help (keyword)
7892 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
7893 "(org)In-buffer settings"))
7894 (search-forward (concat "#+" keyword
) nil t
)
7895 (anything-persistent-highlight-point)
7896 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
7903 (defvar bbdb-records
)
7904 (defvar bbdb-buffer-name
)
7906 (defun anything-c-bbdb-candidates ()
7907 "Return a list of all names in the bbdb database. The format
7908 is \"Firstname Lastname\"."
7909 (mapcar (lambda (bbdb-record)
7910 (replace-regexp-in-string
7912 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
7915 (defun anything-c-bbdb-create-contact (actions candidate
)
7916 "Action transformer that returns only an entry to add the
7917 current `anything-pattern' as new contact. All other actions are
7919 (if (string= candidate
"*Add to contacts*")
7920 '(("Add to contacts" .
(lambda (actions)
7921 (bbdb-create-internal
7922 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
7923 (read-from-minibuffer "Company: ")
7924 (read-from-minibuffer "Email: ")
7927 (read-from-minibuffer "Note: ")))))
7930 (defun anything-c-bbdb-get-record (candidate)
7931 "Return record that match CANDIDATE."
7932 (bbdb candidate nil
)
7933 (set-buffer "*BBDB*")
7934 (bbdb-current-record))
7936 (defvar anything-c-bbdb-name nil
7937 "Only for internal use.")
7939 (defvar anything-c-source-bbdb
7941 (candidates . anything-c-bbdb-candidates
)
7942 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
7943 ("View person's data" . anything-c-bbdb-view-person-action
))
7944 (filtered-candidate-transformer .
(lambda (candidates source
)
7945 (setq anything-c-bbdb-name anything-pattern
)
7946 (if (not candidates
)
7947 (list "*Add to contacts*")
7949 (action-transformer .
(lambda (actions candidate
)
7950 (anything-c-bbdb-create-contact actions candidate
))))
7953 http://bbdb.sourceforge.net/")
7954 ;; (anything 'anything-c-source-bbdb)
7956 (defun anything-c-bbdb-view-person-action (candidate)
7957 "View BBDB data of single CANDIDATE or marked candidates."
7958 (anything-aif (anything-marked-candidates)
7959 (let ((bbdb-append-records (length it
)))
7961 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
7962 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
7964 (defun anything-c-bbdb-collect-mail-addresses ()
7965 "Return a list of all mail addresses of records in bbdb buffer."
7966 (with-current-buffer bbdb-buffer-name
7967 (loop for i in bbdb-records
7968 if
(bbdb-record-net (car i
))
7969 collect
(bbdb-dwim-net-address (car i
)))))
7971 (defun anything-c-bbdb-compose-mail (candidate)
7972 "Compose a mail with all records of bbdb buffer."
7973 (anything-c-bbdb-view-person-action candidate
)
7974 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
7975 (address-str (mapconcat 'identity address-list
",\n ")))
7976 (compose-mail address-str
)))
7979 ;;; Evaluation Result
7983 (defvar anything-eldoc-active-minibuffers-list nil
)
7985 (defvar anything-c-source-evaluation-result
7986 '((name .
"Evaluation Result")
7990 (mode-line .
"C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
7991 (filtered-candidate-transformer .
(lambda (candidates source
)
7994 (with-anything-current-buffer
7996 (eval (read anything-pattern
))))
7998 (action .
(("Copy result to kill-ring" .
(lambda (candidate)
7999 (with-current-buffer anything-buffer
8000 (let ((end (save-excursion
8001 (goto-char (point-max))
8002 (search-backward "\n")
8004 (kill-region (point) end
)))))
8005 ("copy sexp to kill-ring" .
(lambda (candidate)
8006 (kill-new anything-input
)))))))
8007 ;; (anything 'anything-c-source-evaluation-result)
8009 (defun anything-eval-new-line-and-indent ()
8011 (newline) (lisp-indent-line))
8013 (defun anything-eldoc-store-minibuffer ()
8014 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8015 (with-selected-window (minibuffer-window)
8016 (push (buffer-name) anything-eldoc-active-minibuffers-list
)))
8018 (defun anything-eldoc-show-in-eval ()
8019 "Return eldoc in mode-line for current minibuffer input."
8020 (let ((buf (with-selected-window (minibuffer-window)
8022 (when (member buf anything-eldoc-active-minibuffers-list
)
8023 (let* ((str-all (with-current-buffer buf
8024 (minibuffer-completion-contents)))
8028 (goto-char (point-max))
8029 (unless (looking-back ")\\|\"") (forward-char -
1))
8030 (eldoc-current-symbol))))
8031 (info-fn (eldoc-fnsym-in-current-sexp))
8032 (doc (or (eldoc-get-var-docstring sym
)
8033 (eldoc-get-fnsym-args-string
8034 (car info-fn
) (cadr info-fn
)))))
8035 (when doc
(funcall anything-c-eldoc-in-minibuffer-show-fn doc
))))))
8037 (defun anything-c-eldoc-show-in-mode-line (str)
8038 "Show string STR in mode-line."
8039 (save-window-excursion
8040 (with-current-buffer anything-buffer
8041 (let ((mode-line-format (concat " " str
)))
8042 (force-mode-line-update)
8043 (sit-for anything-c-eldoc-show-in-mode-line-delay
))
8044 (force-mode-line-update))))
8046 ;;; Calculation Result
8049 (defvar anything-c-source-calculation-result
8050 '((name .
"Calculation Result")
8052 (filtered-candidate-transformer .
(lambda (candidates source
)
8055 (calc-eval anything-pattern
)
8057 (action ("Copy result to kill-ring" . kill-new
))))
8058 ;; (anything 'anything-c-source-calculation-result)
8061 ;;; Google Suggestions
8065 (defvar anything-ggs-max-length-real-flag
0)
8066 (defvar anything-ggs-max-length-num-flag
0)
8068 (defun anything-c-google-suggest-fetch (input)
8069 "Fetch suggestions for INPUT from XML buffer.
8070 Return an alist with elements like (data . number_results)."
8071 (setq anything-ggs-max-length-real-flag
0
8072 anything-ggs-max-length-num-flag
0)
8073 (let ((request (concat anything-c-google-suggest-url
8074 (url-hexify-string input
))))
8077 with result-alist
= (xml-get-children
8078 (car (xml-parse-region
8079 (point-min) (point-max)))
8080 'CompleteSuggestion
)
8081 for i in result-alist
8082 for data
= (cdr (caadr (assoc 'suggestion i
)))
8083 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
8084 for lqueries
= (length (anything-c-ggs-set-number-result
8086 for ldata
= (length data
)
8089 (when (> ldata anything-ggs-max-length-real-flag
)
8090 (setq anything-ggs-max-length-real-flag ldata
))
8091 (when (> lqueries anything-ggs-max-length-num-flag
)
8092 (setq anything-ggs-max-length-num-flag lqueries
)))
8093 collect
(cons data nqueries
) into cont
8094 finally return cont
)))
8095 (if anything-google-suggest-use-curl-p
8097 (call-process "curl" nil t nil request
)
8099 (with-current-buffer
8100 (url-retrieve-synchronously request
)
8103 (defun anything-c-google-suggest-set-candidates (&optional request-prefix
)
8104 "Set candidates with result and number of google results found."
8106 (loop with suggested-results
= (anything-c-google-suggest-fetch
8107 (or (and request-prefix
8108 (concat request-prefix
" " anything-pattern
))
8110 for
(real . numresult
) in suggested-results
8111 ;; Prepare number of results with ","
8112 for fnumresult
= (anything-c-ggs-set-number-result numresult
)
8113 ;; Calculate number of spaces to add before fnumresult
8114 ;; if it is smaller than longest result
8115 ;; `anything-ggs-max-length-num-flag'.
8118 ;; To be sure it is aligned properly.
8119 for nspaces
= (if (< (length fnumresult
) anything-ggs-max-length-num-flag
)
8120 (- anything-ggs-max-length-num-flag
(length fnumresult
))
8122 ;; Add now the spaces before fnumresult.
8123 for align-fnumresult
= (concat (make-string nspaces ?
) fnumresult
)
8124 for interval
= (- anything-ggs-max-length-real-flag
(length real
))
8125 for spaces
= (make-string (+ 2 interval
) ?
)
8126 for display
= (format "%s%s(%s results)" real spaces align-fnumresult
)
8127 collect
(cons display real
))))
8128 (if (loop for
(disp . dat
) in suggestions
8129 thereis
(equal dat anything-pattern
))
8131 ;; if there is no suggestion exactly matching the input then
8132 ;; prepend a Search on Google item to the list
8135 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
8136 anything-input
))))))
8138 (defun anything-c-ggs-set-number-result (num)
8141 (and (numberp num
) (setq num
(number-to-string num
)))
8142 (loop for i in
(reverse (split-string num
"" t
))
8144 append
(list i
) into C
8146 append
(list ",") into C
8147 and do
(setq count
0)
8149 (replace-regexp-in-string
8150 "^," "" (mapconcat 'identity
(reverse C
) ""))))
8153 (defvar anything-c-google-suggest-default-browser-function nil
8154 "*The browse url function you prefer to use with google suggest.
8155 When nil, use the first browser function available
8156 See `anything-browse-url-default-browser-alist'.")
8158 (defun anything-c-google-suggest-action (candidate)
8159 "Default action to jump to a google suggested candidate."
8160 (let ((arg (concat anything-c-google-suggest-search-url
8161 (url-hexify-string candidate
))))
8162 (anything-aif anything-c-google-suggest-default-browser-function
8164 (anything-c-browse-url arg
))))
8166 (defvar anything-c-google-suggest-default-function
8167 'anything-c-google-suggest-set-candidates
8168 "Default function to use in anything google suggest.")
8170 (defvar anything-c-source-google-suggest
8171 '((name .
"Google Suggest")
8172 (candidates .
(lambda ()
8173 (funcall anything-c-google-suggest-default-function
)))
8174 (action .
(("Google Search" . anything-c-google-suggest-action
)))
8176 (requires-pattern .
3)
8179 (defun anything-c-google-suggest-emacs-lisp ()
8180 "Try to emacs lisp complete with google suggestions."
8181 (anything-c-google-suggest-set-candidates "emacs lisp"))
8183 ;; (anything 'anything-c-source-google-suggest)
8185 ;;; Yahoo suggestions
8188 (defun anything-c-yahoo-suggest-fetch (input)
8189 "Fetch Yahoo suggestions for INPUT from XML buffer.
8190 Return an alist with elements like (data . number_results)."
8191 (let ((request (concat anything-c-yahoo-suggest-url
8192 (url-hexify-string input
))))
8195 with result-alist
= (xml-get-children
8196 (car (xml-parse-region (point-min) (point-max)))
8198 for i in result-alist
8199 collect
(caddr i
))))
8200 (with-current-buffer
8201 (url-retrieve-synchronously request
)
8204 (defun anything-c-yahoo-suggest-set-candidates ()
8205 "Set candidates with Yahoo results found."
8206 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
8210 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
8211 anything-input
))))))
8213 (defun anything-c-yahoo-suggest-action (candidate)
8214 "Default action to jump to a Yahoo suggested candidate."
8215 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8216 (url-hexify-string candidate
))))
8218 (defvar anything-c-source-yahoo-suggest
8219 '((name .
"Yahoo Suggest")
8220 (candidates . anything-c-yahoo-suggest-set-candidates
)
8221 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
8223 (requires-pattern .
3)
8226 ;; (anything 'anything-c-source-yahoo-suggest)
8229 ;;; Web browser functions.
8232 (require 'browse-url
)
8233 ;; If default setting of `w3m-command' is not
8234 ;; what you want you and you modify it, you will have to reeval
8235 ;; also `anything-browse-url-default-browser-alist'.
8236 (defvar w3m-command
"/usr/bin/w3m")
8237 (defvar anything-c-home-url
"http://www.google.fr"
8238 "*Default url to use as home url.")
8240 (defvar ac-browse-url-chromium-program
"chromium-browser")
8241 (defvar ac-browse-url-uzbl-program
"uzbl-browser")
8242 (defvar anything-browse-url-default-browser-alist
8243 `((,w3m-command . w3m-browse-url
)
8244 (,browse-url-firefox-program . browse-url-firefox
)
8245 (,ac-browse-url-chromium-program . ac-browse-url-chromium
)
8246 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl
)
8247 (,browse-url-kde-program . browse-url-kde
)
8248 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
8249 (,browse-url-mozilla-program . browse-url-mozilla
)
8250 (,browse-url-galeon-program . browse-url-galeon
)
8251 (,browse-url-netscape-program . browse-url-netscape
)
8252 (,browse-url-mosaic-program . browse-url-mosaic
)
8253 (,browse-url-xterm-program . browse-url-text-xterm
))
8254 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8256 (defun* anything-c-generic-browser
(url name
&rest args
)
8257 "Browse URL with NAME browser."
8258 (let ((proc (concat name
" " url
)))
8259 (message "Starting %s..." name
)
8260 (apply 'start-process proc nil name
8261 (append args
(list url
)))
8262 (set-process-sentinel
8264 #'(lambda (process event
)
8265 (when (string= event
"finished\n")
8266 (message "%s process %s" process event
))))))
8268 (defun ac-browse-url-chromium (url)
8269 "Browse URL with google chrome browser."
8270 (interactive "sURL: ")
8271 (anything-c-generic-browser
8272 url ac-browse-url-chromium-program
))
8274 (defun ac-browse-url-uzbl (url &optional ignore
)
8275 "Browse URL with uzbl browser."
8276 (interactive "sURL: ")
8277 (anything-c-generic-browser url ac-browse-url-uzbl-program
"-u"))
8279 (defun anything-browse-url-default-browser (url &rest args
)
8280 "Find the first available browser and ask it to load URL."
8281 (let ((default-browser-fn
8282 (loop for
(exe . fn
) in anything-browse-url-default-browser-alist
8283 thereis
(and exe
(executable-find exe
) fn
))))
8284 (if default-browser-fn
8285 (apply default-browser-fn url args
)
8286 (error "No usable browser found"))))
8288 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
8289 "Default command to browse URL."
8290 (if browse-url-browser-function
8292 (anything-browse-url-default-browser url
)))
8297 ;; Need external program surfraw.
8298 ;; <http://surfraw.alioth.debian.org/>
8300 (defvar anything-surfraw-default-browser-function nil
8301 "*The browse url function you prefer to use with surfraw.
8302 When nil, fallback to `browse-url-browser-function'.")
8305 (defvar anything-surfraw-engines-history nil
)
8307 (defun anything-c-build-elvi-list ()
8308 "Return list of all engines and descriptions handled by surfraw."
8311 (call-process "surfraw" nil t nil
8313 (split-string (buffer-string) "\n"))))
8319 (defun anything-emms-stream-edit-bookmark (elm)
8320 "Change the information of current emms-stream bookmark from anything."
8321 (declare (special emms-stream-list
))
8322 (let* ((cur-buf anything-current-buffer
)
8323 (bookmark (assoc elm emms-stream-list
))
8324 (name (read-from-minibuffer "Description: "
8326 (url (read-from-minibuffer "URL: "
8328 (fd (read-from-minibuffer "Feed Descriptor: "
8329 (int-to-string (nth 2 bookmark
))))
8330 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8331 (format "%s" (car (last bookmark
))))))
8334 (when (re-search-forward (concat "^" name
) nil t
)
8336 (emms-stream-delete-bookmark)
8337 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
8338 (emms-stream-save-bookmarks-file)
8340 (anything-c-switch-to-buffer cur-buf
)))))
8342 (defun anything-emms-stream-delete-bookmark (elm)
8343 "Delete an emms-stream bookmark from anything."
8344 (let* ((cur-buf anything-current-buffer
)
8345 (bookmark (assoc elm emms-stream-list
))
8346 (name (nth 0 bookmark
)))
8349 (when (re-search-forward (concat "^" name
) nil t
)
8351 (emms-stream-delete-bookmark)
8352 (emms-stream-save-bookmarks-file)
8354 (anything-c-switch-to-buffer cur-buf
)))))
8356 (defvar anything-c-source-emms-streams
8357 '((name .
"Emms Streams")
8359 (emms-stream-init)))
8360 (candidates .
(lambda ()
8361 (declare (special emms-stream-list
))
8362 (mapcar 'car emms-stream-list
)))
8363 (action .
(("Play" .
(lambda (elm)
8364 (declare (special emms-stream-list
))
8365 (let* ((stream (assoc elm emms-stream-list
))
8366 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
8367 (url (second stream
)))
8369 ("Delete" . anything-emms-stream-delete-bookmark
)
8370 ("Edit" . anything-emms-stream-edit-bookmark
)))
8371 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8372 ;; (anything 'anything-c-source-emms-streams)
8374 ;; Don't forget to set `emms-source-file-default-directory'
8375 (defvar anything-c-source-emms-dired
8376 '((name .
"Music Directory")
8377 (candidates .
(lambda ()
8378 (cddr (directory-files emms-source-file-default-directory
))))
8380 (("Play Directory" .
(lambda (item)
8381 (emms-play-directory
8384 emms-source-file-default-directory
))))
8385 ("Open dired in file's directory" .
(lambda (item)
8386 (anything-c-open-dired
8389 emms-source-file-default-directory
))))))
8390 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8391 ;; (anything 'anything-c-source-emms-dired)
8394 (defun anything-c-emms-files-modifier (candidates source
)
8395 (let ((current-playlist (with-current-emms-playlist
8397 with cur-list
= (emms-playlist-tracks-in-region
8398 (point-min) (point-max))
8400 collect
(assoc-default 'name i
)))))
8401 (loop for i in candidates
8402 if
(member (cdr i
) current-playlist
)
8403 collect
(cons (propertize (car i
)
8404 'face
'anything-emms-playlist
)
8406 else collect i into lis
8407 finally return lis
)))
8409 (defun anything-c-emms-play-current-playlist ()
8410 "Play current playlist."
8411 (with-current-emms-playlist
8412 (emms-playlist-first)
8413 (emms-playlist-mode-play-smart)))
8415 (defvar anything-c-source-emms-files
8416 '((name .
"Emms files")
8417 (candidates .
(lambda ()
8418 (loop for v being the hash-values in emms-cache-db
8419 for name
= (assoc-default 'name v
)
8420 for artist
= (or (assoc-default 'info-artist v
) "unknown")
8421 for genre
= (or (assoc-default 'info-genre v
) "unknown")
8422 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
8423 for song
= (or (assoc-default 'info-title v
) "unknown")
8424 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
8425 unless
(string-match "^http:" name
) collect
(cons info name
))))
8426 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
8427 (action .
(("Play file" . emms-play-file
)
8428 ("Add to Playlist and play (C-u clear current)"
8429 .
(lambda (candidate)
8430 (when anything-current-prefix-arg
8431 (emms-playlist-current-clear))
8433 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
8434 (unless emms-player-playing-p
8435 (anything-c-emms-play-current-playlist))))))))
8437 ;; (anything 'anything-c-source-emms-files)
8440 ;;; Jabber Contacts (jabber.el)
8441 (defun anything-c-jabber-online-contacts ()
8442 "List online Jabber contacts."
8445 (dolist (item (jabber-concat-rosters) jids
)
8446 (when (get item
'connected
)
8447 (push (if (get item
'name
)
8448 (cons (get item
'name
) item
)
8449 (cons (symbol-name item
) item
)) jids
))))))
8451 (defvar anything-c-source-jabber-contacts
8452 '((name .
"Jabber Contacts")
8453 (init .
(lambda () (require 'jabber
)))
8454 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
8455 (action .
(lambda (x)
8457 (jabber-read-account)
8459 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
8460 ;; (anything 'anything-c-source-jabber-contacts)
8465 (defvar anything-source-select-buffer
"*anything source select*")
8466 (defvar anything-c-source-call-source
8467 `((name .
"Call anything source")
8468 (candidate-number-limit)
8471 (loop for vname in
(all-completions "anything-c-source-" obarray
)
8472 for var
= (intern vname
)
8473 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
8475 (cons (format "%s `%s'"
8476 name
(propertize vname
'face
'font-lock-variable-name-face
))
8479 .
(("Invoke anything with selected source"
8482 (setq anything-candidate-number-limit
9999)
8483 (anything candidate nil nil nil nil
8484 anything-source-select-buffer
)))
8485 ("Describe variable" . describe-variable
)
8486 ("Find variable" . find-variable
)))
8487 (persistent-action . describe-variable
)
8488 (persistent-help .
"Show description of this source")))
8489 ;; (anything 'anything-c-source-call-source)
8491 (defun anything-call-source-from-anything ()
8492 "Call anything source within `anything' session."
8494 (setq anything-input-idle-delay
0)
8495 (anything-set-sources '(anything-c-source-call-source)))
8497 ;;; Execute Preconfigured anything.
8498 (defvar anything-c-source-anything-commands
8499 '((name .
"Preconfigured Anything")
8500 (candidates . anything-c-anything-commands-candidates
)
8502 (candidate-number-limit)))
8503 ;; (anything 'anything-c-source-anything-commands)
8505 (defun anything-c-anything-commands-candidates ()
8506 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
8507 collect
(cons (if (where-is-internal cmd nil t
)
8508 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
8509 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
8516 (defun anything-c-occur-init ()
8517 "Create the initial anything occur buffer.
8518 If region is active use region as buffer contents
8519 instead of whole buffer."
8520 (with-current-buffer (anything-candidate-buffer 'global
)
8523 (with-anything-current-buffer
8524 (if (anything-region-active-p)
8525 (buffer-substring (region-beginning) (region-end))
8526 (buffer-substring (point-min) (point-max))))))
8527 (insert buf-contents
))))
8529 (defun anything-c-occur-get-line (s e
)
8530 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
8532 (defun anything-c-occur-query-replace-regexp (candidate)
8533 "Query replace regexp starting from CANDIDATE.
8534 If region is active ignore CANDIDATE and replace only in region.
8535 With a prefix arg replace only matches surrounded by word boundaries,
8536 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8537 (let ((regexp anything-input
))
8538 (unless (anything-region-active-p)
8539 (anything-c-action-line-goto candidate
))
8540 (apply 'query-replace-regexp
8541 (anything-c-query-replace-args regexp
))))
8543 (defvar anything-c-source-occur
8545 (init . anything-c-occur-init
)
8546 (candidates-in-buffer)
8548 (get-line . anything-c-occur-get-line
)
8549 (display-to-real . anything-c-display-to-real-line
)
8550 (action .
(("Go to Line" . anything-c-action-line-goto
)
8551 ("Query replace regexp (C-u Not inside word.)"
8552 . anything-c-occur-query-replace-regexp
)))
8554 (requires-pattern .
1)
8557 ;; (anything 'anything-c-source-occur)
8560 ;;; Anything browse code.
8561 (defun anything-c-browse-code-get-line (beg end
)
8562 "Select line if it match the regexp corresponding to current `major-mode'.
8563 Line is parsed for BEG position to END position."
8564 (let ((str-line (buffer-substring beg end
))
8565 (regexp (assoc-default major-mode
8566 anything-c-browse-code-regexp-alist
))
8567 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
8568 (when (and regexp
(string-match regexp str-line
))
8569 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
8572 (defvar anything-c-source-browse-code
8573 '((name .
"Browse code")
8575 (anything-candidate-buffer anything-current-buffer
)
8576 (with-anything-current-buffer
8577 (jit-lock-fontify-now))))
8578 (candidate-number-limit .
9999)
8579 (candidates-in-buffer)
8580 (get-line . anything-c-browse-code-get-line
)
8585 ;; Do many actions for input
8586 (defvar anything-c-source-create
8590 (action-transformer . anything-create--actions
))
8591 "Do many create actions from `anything-pattern'.
8592 See also `anything-create--actions'.")
8593 ;; (anything 'anything-c-source-create)
8595 (defun anything-create-from-anything ()
8596 "Run `anything-create' from `anything' as a fallback."
8598 (anything-run-after-quit 'anything-create nil anything-pattern
))
8600 (defun anything-create--actions (&rest ignored
)
8601 "Default actions for `anything-create' / `anything-c-source-create'."
8603 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
8604 (append anything-create--actions-private
8605 '(("find-file" . find-file
)
8606 ("find-file other window" . find-file-other-window
)
8607 ("New buffer" . anything-c-switch-to-buffer
)
8608 ("New buffer other window" . switch-to-buffer-other-window
)
8609 ("Bookmark Set" . bookmark-set
)
8611 (lambda (x) (set-register (read-char "Register: ") x
)))
8612 ("Insert Linkd star" . linkd-insert-star
)
8613 ("Insert Linkd Tag" . linkd-insert-tag
)
8614 ("Insert Linkd Link" . linkd-insert-link
)
8615 ("Insert Linkd Lisp" . linkd-insert-lisp
)
8616 ("Insert Linkd Wiki" . linkd-insert-wiki
)
8617 ("Google Search" . google
)))))
8620 ;; Minibuffer History
8623 (defvar anything-c-source-minibuffer-history
8624 '((name .
"Minibuffer History")
8625 (header-name .
(lambda (name)
8626 (format "%s (%s)" name minibuffer-history-variable
)))
8629 (let ((history (loop
8630 for i in
(symbol-value minibuffer-history-variable
)
8631 unless
(string= "" i
) collect i
)))
8632 (if (consp (car history
))
8633 (mapcar 'prin1-to-string history
)
8637 ;; (anything 'anything-c-source-minibuffer-history)
8643 (defvar anything-c-source-elscreen
8644 '((name .
"Elscreen")
8645 (candidates .
(lambda ()
8646 (if (cdr (elscreen-get-screen-to-name-alist))
8648 (loop for sname in
(elscreen-get-screen-to-name-alist)
8649 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
8650 finally
(return lst
))
8651 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
8652 (action .
(("Change Screen".
8654 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
8657 (dolist (i (anything-marked-candidates))
8658 (elscreen-goto (- (aref i
1) (aref "0" 0)))
8662 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
8663 (elscreen-kill-others)))))))
8664 ;; (anything 'anything-c-source-elscreen)
8670 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
8671 "Top command (batch mode). %s is replaced with `frame-width'.")
8672 (defvar anything-c-source-top
8673 '((name .
"Top (Press C-c C-u to refresh)")
8674 (init . anything-c-top-init
)
8675 (candidates-in-buffer)
8676 (display-to-real . anything-c-top-display-to-real
)
8677 (update . anything-c-top-update
)
8678 (persistent-action . anything-c-top-sh-persistent-action
)
8679 (persistent-help .
"SIGTERM")
8681 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
8682 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
8683 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
8684 ;; (anything 'anything-c-source-top)
8686 (defun anything-c-top-sh (cmd)
8687 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
8689 (defun anything-c-top-sh-persistent-action (pid)
8690 (delete-other-windows)
8691 (anything-c-top-sh (format "kill -TERM %s" pid
))
8692 (anything-force-update))
8694 (defun anything-c-top-init ()
8695 (with-current-buffer (anything-candidate-buffer 'global
)
8696 (call-process-shell-command
8697 (format anything-c-top-command
8698 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
8699 nil
(current-buffer))))
8701 (defun anything-c-top-display-to-real (line)
8702 (car (split-string line
)))
8704 (defun anything-c-top-update ()
8705 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
8706 (anything-c-top-init)))
8709 (defvar anything-c-source-absolute-time-timers
8710 '((name .
"Absolute Time Timers")
8711 (candidates . timer-list
)
8713 ;; (anything 'anything-c-source-absolute-time-timers)
8715 (defvar anything-c-source-idle-time-timers
8716 '((name .
"Idle Time Timers")
8717 (candidates . timer-idle-list
)
8719 ;; (anything 'anything-c-source-idle-time-timers)
8721 (defun anything-c-timer-real-to-display (timer)
8722 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
8723 (append timer nil
) ;use `append' to convert vector->list
8724 (format "%s repeat=%5S %s(%s)"
8725 (let ((time (list t1 t2 t3
)))
8727 (format-time-string "idle-for=%5s" time
)
8728 (format-time-string "%m/%d %T" time
)))
8731 (mapconcat 'prin1-to-string args
" "))))
8733 ;;; X RandR resolution change
8734 ;;; FIXME I do not care multi-display.
8735 (defvar anything-c-xrandr-output
"VGA")
8736 (defvar anything-c-xrandr-screen
"0")
8737 (defvar anything-c-source-xrandr-change-resolution
8738 '((name .
"Change Resolution")
8742 (call-process "xrandr" nil
(current-buffer) nil
8743 "--screen" anything-c-xrandr-screen
"-q")
8745 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
8746 collect
(match-string 1)))))
8748 ("Change Resolution" .
(lambda (mode)
8749 (call-process "xrandr" nil nil nil
8750 "--screen" anything-c-xrandr-screen
8751 "--output" anything-c-xrandr-output
8753 ;; (anything 'anything-c-source-xrandr-change-resolution)
8758 (defun anything-c-persistent-xfont-action (elm)
8759 "Show current font temporarily"
8760 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
8763 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
8764 (set-frame-font current-font
))))
8766 (defvar anything-c-xfonts-cache nil
)
8767 (defvar anything-c-source-xfonts
8768 '((name .
"X Fonts")
8770 (unless anything-c-xfonts-cache
8771 (setq anything-c-xfonts-cache
8772 (x-list-fonts "*")))))
8773 (candidates . anything-c-xfonts-cache
)
8774 (action .
(("Copy to kill ring" .
(lambda (elm)
8776 ("Set Font" .
(lambda (elm)
8778 (set-frame-font elm
'keep-size
)
8779 (message "New font have been copied to kill ring")))))
8780 (persistent-action . anything-c-persistent-xfont-action
)
8781 (persistent-help .
"Switch to this font temporarily")))
8782 ;; (anything 'anything-c-source-xfonts)
8784 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8787 (defvar anything-c-ucs-max-len
0)
8788 (defun anything-c-calculate-ucs-max-len ()
8789 "Calculate the length of longest `ucs-names' candidate."
8790 (loop with count
= 0
8791 for
(n . v
) in
(ucs-names)
8792 for len
= (length n
)
8795 finally return count
))
8797 (defun anything-c-ucs-init ()
8798 "Initialize an anything buffer with ucs symbols.
8799 Only math* symbols are collected."
8800 (unless (> anything-c-ucs-max-len
0)
8801 (setq anything-c-ucs-max-len
8802 (anything-c-calculate-ucs-max-len)))
8803 (with-current-buffer (anything-candidate-buffer
8804 (get-buffer-create "*anything ucs*"))
8805 ;; `ucs-names' fn will not run again, data is cached in
8807 (loop for
(n . v
) in
(ucs-names)
8808 for len
= (length n
)
8809 for diff
= (+ (- anything-c-ucs-max-len len
) 2)
8810 unless
(string= "" n
)
8811 do
(progn (insert (concat
8818 (defun anything-c-ucs-forward-char (candidate)
8819 (with-anything-current-buffer
8822 (defun anything-c-ucs-backward-char (candidate)
8823 (with-anything-current-buffer
8826 (defun anything-c-ucs-delete-backward (candidate)
8827 (with-anything-current-buffer
8830 (defun anything-c-ucs-insert-char (candidate)
8831 (with-anything-current-buffer
8833 (replace-regexp-in-string
8835 (cadr (split-string candidate
":"))))))
8837 (defun anything-c-ucs-persistent-insert ()
8839 (anything-execute-persistent-action 'action-insert
))
8841 (defun anything-c-ucs-persistent-forward ()
8843 (anything-execute-persistent-action 'action-forward
))
8845 (defun anything-c-ucs-persistent-backward ()
8847 (anything-execute-persistent-action 'action-back
))
8849 (defun anything-c-ucs-persistent-delete ()
8851 (anything-execute-persistent-action 'action-delete
))
8853 (defvar anything-c-source-ucs
8854 '((name .
"Ucs names")
8855 (init . anything-c-ucs-init
)
8856 (candidate-number-limit .
9999)
8857 (candidates-in-buffer)
8858 (mode-line . anything-c-ucs-mode-line-string
)
8859 (action-insert . anything-c-ucs-insert-char
)
8860 (action-forward . anything-c-ucs-forward-char
)
8861 (action-back . anything-c-ucs-backward-char
)
8862 (action-delete . anything-c-ucs-delete-backward
)
8863 (action .
(("Insert" . anything-c-ucs-insert-char
)
8864 ("Forward char" . anything-c-ucs-forward-char
)
8865 ("Backward char" . anything-c-ucs-backward-char
)
8866 ("Delete char backward" . anything-c-ucs-delete-backward
))))
8867 "Source for collecting `ucs-names' math symbols.")
8873 (defvar anything-c-source-emacs-process
8874 '((name .
"Emacs Process")
8875 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
8876 (persistent-action .
(lambda (elm)
8877 (delete-process (get-process elm
))
8878 (anything-delete-current-selection)))
8879 (persistent-help .
"Kill Process")
8880 (action ("Kill Process" .
(lambda (elm)
8881 (delete-process (get-process elm
)))))))
8882 ;; (anything 'anything-c-source-emacs-process)
8887 (defvar anything-c-source-time-world
8888 '((name .
"Time World List")
8890 (let ((anything-buffer (anything-candidate-buffer 'global
)))
8891 (with-current-buffer anything-buffer
8892 (display-time-world-display display-time-world-list
)))))
8893 (candidates-in-buffer)))
8897 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
8900 (defvar anything-c-source-apt
8902 (init . anything-c-apt-init
)
8903 (candidates-in-buffer)
8904 (candidate-transformer anything-c-apt-candidate-transformer
)
8905 (display-to-real . anything-c-apt-display-to-real
)
8906 (requires-pattern .
2)
8907 (update . anything-c-apt-refresh
)
8909 ("Show package description" . anything-c-apt-cache-show
)
8910 ("Install package" . anything-c-apt-install
)
8911 ("Remove package" . anything-c-apt-uninstall
)
8912 ("Purge package" . anything-c-apt-purge
))
8913 (persistent-action . anything-c-apt-persistent-action
)
8914 (persistent-help .
"Show package description")))
8915 ;; (anything 'anything-c-source-apt)
8917 (defvar anything-c-apt-query
"emacs")
8918 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
8919 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
8920 (defvar anything-c-apt-installed-packages nil
)
8921 (defvar anything-c-apt-all-packages nil
)
8924 (defun anything-c-apt-refresh ()
8925 "Refresh installed candidates list."
8926 (setq anything-c-apt-installed-packages nil
)
8927 (setq anything-c-apt-all-packages nil
))
8929 (defun anything-c-apt-persistent-action (candidate)
8930 "Persistent action for APT source."
8931 (anything-c-apt-cache-show candidate
))
8933 (defun anything-c-apt-candidate-transformer (candidates)
8934 "Show installed candidates in a different color."
8937 for cand in candidates
8938 for name
= (anything-c-apt-display-to-real cand
)
8939 if
(member name anything-c-apt-installed-packages
)
8940 collect
(propertize cand
'face
'anything-apt-installed
) into all
8941 else collect cand into all finally return all
))
8943 (defun anything-c-apt-init ()
8944 "Initialize list of debian packages."
8946 (unless (and anything-c-apt-installed-packages
8947 anything-c-apt-all-packages
)
8948 (message "Loading package list...")
8949 (setq anything-c-apt-installed-packages
8951 (call-process-shell-command "dpkg --get-selections"
8952 nil
(current-buffer))
8953 (loop for i in
(split-string (buffer-string) "\n" t
)
8954 collect
(car (split-string i
)))))
8955 (setq anything-c-apt-all-packages
8956 (with-current-buffer
8957 (anything-candidate-buffer
8958 (get-buffer-create (format "*anything-apt*")))
8960 (call-process-shell-command
8961 (format anything-c-apt-search-command query
)
8962 nil
(current-buffer))))
8963 (message "Loading package list done")
8966 (defun anything-c-apt-display-to-real (line)
8967 "Return only name of a debian package.
8968 LINE is displayed like:
8969 package name - description."
8970 (car (split-string line
" - ")))
8972 (defun anything-c-shell-command-if-needed (command)
8973 "Run shell command COMMAND to describe package.
8974 If a buffer named COMMAND already exists, just switch to it."
8975 (let ((buf (get-buffer command
)))
8976 (anything-c-switch-to-buffer (get-buffer-create command
))
8977 (unless buf
(insert (shell-command-to-string command
)))))
8979 (defun anything-c-apt-cache-show (package)
8980 "Show information on apt package PACKAGE."
8981 (anything-c-shell-command-if-needed
8982 (format anything-c-apt-show-command package
)))
8984 (defun anything-c-apt-install (package)
8985 "Run 'apt-get install' shell command on PACKAGE."
8986 (anything-c-apt-generic-action :action
'install
))
8988 (defun anything-c-apt-uninstall (package)
8989 "Run 'apt-get remove' shell command on PACKAGE."
8990 (anything-c-apt-generic-action :action
'uninstall
))
8992 (defun anything-c-apt-purge (package)
8993 "Run 'apt-get purge' shell command on PACKAGE."
8994 (anything-c-apt-generic-action :action
'purge
))
8996 (defun* anything-c-apt-generic-action
(&key action
)
8997 "Run 'apt-get ACTION'.
8998 Support install, remove and purge actions."
8999 (ansi-term (getenv "SHELL") "anything apt")
9001 (let ((command (case action
9002 ('install
"sudo apt-get install ")
9003 ('uninstall
"sudo apt-get remove ")
9004 ('purge
"sudo apt-get purge ")
9005 (t (error "Unknow action"))))
9008 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x
))
9009 (anything-marked-candidates) " ")))
9010 (goto-char (point-max))
9011 (insert (concat command cand-list
))
9013 (if (y-or-n-p (format "%s package" (symbol-name action
)))
9015 (setq anything-c-external-commands-list nil
)
9016 (setq anything-c-apt-installed-packages nil
)
9017 (term-char-mode) (term-send-input))
9018 (delete-region beg end
) (term-send-eof) (kill-buffer))))
9020 ;; (anything-c-apt-install "jed")
9023 ;;; Anything UI for gentoo portage.
9026 (defvar anything-c-gentoo-use-flags nil
)
9027 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
9028 (defvar anything-c-cache-gentoo nil
)
9029 (defvar anything-c-cache-world nil
)
9030 (defvar anything-c-source-gentoo
9031 '((name .
"Portage sources")
9033 (get-buffer-create anything-c-gentoo-buffer
)
9034 (unless anything-c-cache-gentoo
9035 (anything-c-gentoo-setup-cache))
9036 (unless anything-c-cache-world
9037 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
9038 (anything-c-gentoo-init-list)))
9039 (candidates-in-buffer)
9041 (candidate-transformer anything-c-highlight-world
)
9042 (action .
(("Show package" .
(lambda (elm)
9043 (anything-c-gentoo-eshell-action elm
"eix")))
9044 ("Show history" .
(lambda (elm)
9045 (if (member elm anything-c-cache-world
)
9046 (anything-c-gentoo-eshell-action elm
"genlop -qe")
9047 (message "No infos on packages not yet installed"))))
9048 ("Copy in kill-ring" . kill-new
)
9049 ("insert at point" . insert
)
9050 ("Browse HomePage" .
(lambda (elm)
9051 (let ((urls (anything-c-gentoo-get-url elm
)))
9052 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
9053 ("Show extra infos" .
(lambda (elm)
9054 (if (member elm anything-c-cache-world
)
9055 (anything-c-gentoo-eshell-action elm
"genlop -qi")
9056 (message "No infos on packages not yet installed"))))
9057 ("Show use flags" .
(lambda (elm)
9058 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
9059 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
9060 (font-lock-mode 1)))
9061 ("Run emerge pretend" .
(lambda (elm)
9062 (anything-c-gentoo-eshell-action elm
"emerge -p")))
9063 ("Emerge" .
(lambda (elm)
9064 (anything-gentoo-install elm
:action
'install
)))
9065 ("Unmerge" .
(lambda (elm)
9066 (anything-gentoo-install elm
:action
'uninstall
)))
9067 ("Show dependencies" .
(lambda (elm)
9068 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
9069 ("Show related files" .
(lambda (elm)
9070 (anything-c-gentoo-default-action elm
"equery" "files")))
9071 ("Refresh" .
(lambda (elm)
9072 (anything-c-gentoo-setup-cache)
9073 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
9075 ;; (anything 'anything-c-source-gentoo)
9077 (defun* anything-gentoo-install
(candidate &key action
)
9078 (setq anything-c-external-commands-list nil
)
9079 (ansi-term (getenv "SHELL") "Gentoo emerge")
9081 (let ((command (case action
9082 ('install
"sudo emerge -av ")
9083 ('uninstall
"sudo emerge -avC ")
9084 (t (error "Unknow action"))))
9085 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
9087 (goto-char (point-max))
9088 (insert (concat command elms
))
9090 (term-char-mode) (term-send-input)))
9092 (defun anything-c-gentoo-default-action (elm command
&rest args
)
9093 "Gentoo default action that use `anything-c-gentoo-buffer'."
9094 (if (member elm anything-c-cache-world
)
9096 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9098 (let ((com-list (append args
(list elm
))))
9099 (apply #'call-process command nil t nil
9101 (message "No infos on packages not yet installed")))
9103 (defvar anything-c-source-use-flags
9104 '((name .
"Use Flags")
9106 (unless anything-c-gentoo-use-flags
9107 (anything-c-gentoo-setup-use-flags-cache))
9108 (anything-c-gentoo-get-use)))
9109 (candidates-in-buffer)
9111 (candidate-transformer anything-c-highlight-local-use
)
9112 (action .
(("Description"
9114 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9116 (apply #'call-process
"euse" nil t nil
9119 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
9120 (font-lock-mode 1)))
9123 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
9126 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
9129 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
9130 ("Show which dep use this flag"
9132 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9134 (apply #'call-process
"equery" nil t nil
9140 ;; (anything 'anything-c-source-use-flags)
9142 (defun anything-c-gentoo-init-list ()
9143 "Initialize buffer with all packages in Portage."
9144 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9145 (buf (anything-candidate-buffer 'portage-buf
)))
9146 (with-current-buffer buf
9147 (dolist (i anything-c-cache-gentoo
)
9148 (insert (concat i
"\n"))))))
9150 (defun anything-c-gentoo-setup-cache ()
9151 "Set up `anything-c-cache-gentoo'"
9152 (setq anything-c-cache-gentoo
9153 (split-string (with-temp-buffer
9154 (call-process "eix" nil t nil
9158 (defun anything-c-gentoo-eshell-action (elm command
)
9159 (when (get-buffer "*EShell Command Output*")
9160 (kill-buffer "*EShell Command Output*"))
9161 (message "Wait searching...")
9162 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
9163 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
9165 (save-window-excursion
9166 (pop-to-buffer "*scratch*")
9167 (eshell-command (format "%s %s" command elm
)))
9168 (pop-to-buffer "*EShell Command Output*"))
9169 (eshell-command (format "%s %s" command elm
)))))
9171 (defun anything-c-gentoo-get-use ()
9172 "Initialize buffer with all use flags."
9173 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9174 (buf (anything-candidate-buffer 'use-buf
)))
9175 (with-current-buffer buf
9176 (dolist (i anything-c-gentoo-use-flags
)
9177 (insert (concat i
"\n"))))))
9180 (defun anything-c-gentoo-setup-use-flags-cache ()
9181 "Setup `anything-c-gentoo-use-flags'"
9182 (setq anything-c-gentoo-use-flags
9183 (split-string (with-temp-buffer
9184 (call-process "eix" nil t nil
9185 "--print-all-useflags")
9188 (defun anything-c-gentoo-get-url (elm)
9189 "Return a list of urls from eix output."
9191 with url-list
= (split-string
9193 (call-process "eix" nil t nil
9194 elm
"--format" "<homepage>\n")
9198 when
(and (string-match "^http://.*" i
)
9199 (not (member i all
)))
9201 finally return all
))
9203 (defun anything-c-gentoo-get-world ()
9204 "Return list of all installed package on your system."
9205 (split-string (with-temp-buffer
9206 (call-process "qlist" nil t nil
9210 (defun anything-c-gentoo-get-local-use ()
9211 (split-string (with-temp-buffer
9212 (call-process "portageq" nil t nil
9218 (defun anything-c-highlight-world (eix)
9219 "Highlight all installed package."
9221 if
(member i anything-c-cache-world
)
9222 collect
(propertize i
'face
'anything-gentoo-match-face
)
9226 (defun anything-c-highlight-local-use (use-flags)
9227 (let ((local-uses (anything-c-gentoo-get-local-use)))
9228 (loop for i in use-flags
9229 if
(member i local-uses
)
9230 collect
(propertize i
'face
'anything-gentoo-match-face
)
9236 ;;; Anything ratpoison UI
9239 (defvar anything-c-source-ratpoison-commands
9240 '((name .
"Ratpoison Commands")
9241 (init . anything-c-ratpoison-commands-init
)
9242 (candidates-in-buffer)
9243 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
9244 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
9245 (candidate-number-limit)))
9246 ;; (anything 'anything-c-source-ratpoison-commands)
9248 (defun anything-c-ratpoison-commands-init ()
9249 (unless (anything-candidate-buffer)
9250 (with-current-buffer (anything-candidate-buffer 'global
)
9251 ;; with ratpoison prefix key
9253 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
9254 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9255 (replace-match "<ratpoison> \\1: \\2"))
9256 (goto-char (point-max))
9259 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
9260 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9261 (replace-match "\\1: \\2")))))
9263 (defun anything-c-ratpoison-commands-display-to-real (display)
9264 (and (string-match ": " display
)
9265 (substring display
(match-end 0))))
9267 (defun anything-c-ratpoison-commands-execute (candidate)
9268 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
9272 ;;; Anything `completing-read' replacement
9275 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp
)
9276 "Convert COLLECTION to list removing elements that don't match TEST.
9277 See `anything-comp-read' about supported COLLECTION arguments.
9279 SORT-FN is a predicate to sort COLLECTION.
9281 ALISTP when non--nil will not use `all-completions' to collect
9282 candidates because it doesn't handle alists correctly for anything.
9283 i.e In `all-completions' the keys \(cars of elements\)
9284 are the possible completions. In anything we want to use the cdr instead
9285 like \(display . real\).
9286 See docstring of `all-completions' for more info.
9288 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9290 (cond ((and (eq collection obarray
) test
)
9291 (all-completions "" collection test
))
9292 ((and (vectorp collection
) test
)
9293 (loop for i across collection when
(funcall test i
) collect i
))
9294 ((vectorp collection
)
9295 (loop for i across collection collect i
))
9297 (loop for i in collection when
(funcall test i
) collect i
))
9298 ((and (symbolp collection
) (boundp collection
))
9299 (symbol-value collection
))
9301 ((and collection test
)
9302 (all-completions "" collection test
))
9303 (t (all-completions "" collection
)))))
9304 (if sort-fn
(sort cands sort-fn
) cands
)))
9306 (defun anything-cr-default-transformer (candidates source
)
9307 "Default filter candidate function for `anything-comp-read'.
9308 Do nothing, just return candidate list unmodified."
9311 (defun* anything-comp-read
(prompt collection
9317 (buffer "*Anything Completions*")
9319 (requires-pattern 0)
9321 (persistent-action nil
)
9322 (persistent-help "DoNothing")
9323 (name "Anything Completions")
9324 candidates-in-buffer
9327 (fc-transformer 'anything-cr-default-transformer
)
9328 (marked-candidates nil
)
9330 "Anything `completing-read' emulation.
9332 PROMPT is the prompt name to use.
9333 COLLECTION can be a list, vector, obarray or hash-table.
9334 It can be also a function that receives three arguments:
9335 the values string, predicate and t. See `all-completions' for more details.
9339 TEST: A predicate called with one arg i.e candidate.
9340 INITIAL-INPUT: Same as initial-input arg in `anything'.
9341 PRESELECT: See preselect arg of `anything'.
9342 DEFAULT: This option is used only for compatibility with regular
9343 Emacs `completing-read'.
9344 BUFFER: Name of anything-buffer.
9345 MUST-MATCH: Candidate selected must be one of COLLECTION.
9346 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9347 HISTORY: A list containing specific history, default is nil.
9348 When it is non--nil, all elements of HISTORY are displayed in
9349 a special source before COLLECTION.
9350 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9351 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9352 NAME: The name related to this local source.
9353 VOLATILE: Use volatile attribute \(enabled by default\).
9354 SORT: A predicate to give to `sort' e.g `string-lessp'.
9355 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9356 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9357 ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9358 CANDIDATES-IN-BUFFER: when non--nil use a source build with
9359 `anything-candidates-in-buffer' which is much faster. It is enabled by default.
9360 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9362 Any prefix args passed during `anything-comp-read' invocation will be recorded
9363 in `anything-current-prefix-arg', otherwise if prefix args where given before
9364 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9365 That's mean you can pass prefix args before or after calling a command
9366 that use `anything-comp-read' See `anything-M-x' for example."
9367 (when (get-buffer anything-action-buffer
)
9368 (kill-buffer anything-action-buffer
))
9369 (flet ((action-fn (candidate)
9370 (if marked-candidates
9371 (anything-marked-candidates)
9372 (identity candidate
))))
9373 (let* ((hist `((name .
,(format "%s History" name
))
9376 (let ((all (anything-comp-read-get-candidates
9377 history nil nil
,alistp
)))
9378 (anything-fast-remove-dups
9379 (if (and default
(not (string= default
"")))
9380 (delq nil
(cons default
(delete default all
)))
9383 (filtered-candidate-transformer
9384 .
(lambda (candidates sources
)
9385 (loop for i in candidates
9386 do
(set-text-properties 0 (length i
) nil i
)
9388 (persistent-action .
,persistent-action
)
9389 (persistent-help .
,persistent-help
)
9390 (action .
,'action-fn
)))
9391 (src `((name .
,name
)
9394 (let ((cands (anything-comp-read-get-candidates
9395 collection test sort alistp
)))
9396 (unless (or must-match
(string= anything-pattern
""))
9397 (setq cands
(append (list anything-pattern
) cands
)))
9398 (if (and default
(not (string= default
"")))
9399 (delq nil
(cons default
(delete default cands
)))
9401 (filtered-candidate-transformer ,fc-transformer
)
9402 (requires-pattern .
,requires-pattern
)
9403 (persistent-action .
,persistent-action
)
9404 (persistent-help .
,persistent-help
)
9405 (action .
,'action-fn
)))
9406 (src-1 `((name .
,name
)
9409 (let ((cands (anything-comp-read-get-candidates
9410 collection test sort alistp
)))
9411 (unless (or must-match
(string= anything-pattern
""))
9412 (setq cands
(append (list anything-pattern
) cands
)))
9413 (with-current-buffer (anything-candidate-buffer 'global
)
9415 (if (and default
(not (string= default
"")))
9416 (delq nil
(cons default
(delete default cands
)))
9418 do
(insert (concat i
"\n")))))))
9419 (candidates-in-buffer)
9420 (filtered-candidate-transformer ,fc-transformer
)
9421 (requires-pattern .
,requires-pattern
)
9422 (persistent-action .
,persistent-action
)
9423 (persistent-help .
,persistent-help
)
9424 (action .
,'action-fn
)))
9425 (src-list (list hist
(if candidates-in-buffer src-1 src
))))
9426 ;; Volatile will have no effect if CANDIDATES-IN-BUFFER is non--nil.
9427 (when volatile
(setq src
(append src
'((volatile)))))
9431 :input initial-input
9433 :preselect preselect
9438 (unless (or (eq anything-exit-status
1) must-match
)
9442 ;; Generic completing-read
9444 ;; Support also function as collection.
9445 ;; e.g M-x man is supported.
9446 ;; Support hash-table and vectors as collection.
9448 ;; Some crap emacs functions may not be supported
9449 ;; like ffap-alternate-file (bad use of completing-read)
9450 ;; and maybe others.
9451 ;; Provide a mode `anything-completion-mode' which turn on
9452 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9454 (defvar anything-completion-mode-string
" AC")
9456 (defvar anything-completion-mode-quit-message
9457 "Anything completion disabled")
9459 (defvar anything-completion-mode-start-message
9460 "Anything completion enabled")
9462 ;;; Specialized handlers
9465 (defun anything-completing-read-symbols
9466 (prompt collection test require-match init
9467 hist default inherit-input-method name buffer
)
9468 "Specialized function for fast symbols completion in `ac-mode'."
9471 :sources
`((name .
,name
)
9473 (with-current-buffer (anything-candidate-buffer 'global
)
9474 (goto-char (point-min))
9475 (when (and default
(stringp default
)
9476 ;; Some defaults args result as
9477 ;; (symbol-name nil) == "nil".
9478 ;; e.g debug-on-entry.
9479 (not (string= default
"nil")))
9480 (insert (concat default
"\n")))
9481 (loop with all
= (all-completions "" collection test
)
9483 unless
(and default
(eq sym default
))
9484 do
(insert (concat sym
"\n"))))))
9485 (persistent-action . anything-lisp-completion-persistent-action
)
9486 (persistent-help .
"Show brief doc in mode-line")
9487 (candidates-in-buffer)
9488 (action . identity
))
9494 :default
(or default
""))
9498 ;;; Generic completing read
9501 (defun anything-completing-read-default-1
9502 (prompt collection test require-match
9503 init hist default inherit-input-method
9508 :fc-transformer
#'(lambda (candidates source
)
9509 ;; In regular `completing-read'
9510 ;; when a candidate is a cons cell
9511 ;; the car is used. Anything use
9512 ;; normally the cdr, so modify that
9513 ;; to fit `completing-read'.
9514 (loop for i in candidates
9515 for cand
= (if (consp i
) (car i
) i
)
9516 do
(set-text-properties 0 (length cand
) nil cand
)
9518 :history
(or (car-safe hist
) hist
)
9519 :must-match require-match
9523 ;; If DEF is not provided, fallback to empty string
9524 ;; to avoid `thing-at-point' to be appended on top of list
9525 :default
(or default
"")
9526 :initial-input init
))
9528 (defun* anything-completing-read-default
9529 (prompt collection
&optional
9530 predicate require-match
9531 initial-input hist def
9532 inherit-input-method
)
9533 "An anything replacement of `completing-read'.
9534 This function should be used only as a `completing-read-function'.
9536 Don't use it directly, use instead `anything-comp-read' in your programs \
9537 which is more powerful.
9539 See documentation of `completing-read' and `all-completions' for details."
9540 (declare (special anything-completion-mode
))
9541 (let* ((current-command this-command
)
9542 (str-command (symbol-name current-command
))
9543 (buf-name (format "*ac-mode-%s*" str-command
))
9544 (entry (assq current-command
9545 anything-completing-read-handlers-alist
))
9546 (def-com (cdr-safe entry
))
9547 (str-defcom (and def-com
(symbol-name def-com
)))
9548 (def-args (list prompt collection predicate require-match
9549 initial-input hist def inherit-input-method
))
9550 ;; Append the two extra args needed to set the buffer and source name
9551 ;; in anything specialized functions.
9552 (any-args (append def-args
(list str-command buf-name
)))
9553 anything-completion-mode-start-message
; Be quiet
9554 anything-completion-mode-quit-message
9555 (minibuffer-completion-table collection
)
9556 (minibuffer-completion-predicate predicate
))
9557 (when (eq def-com
'ido
) (setq def-com
'ido-completing-read
))
9558 (unless (or (not entry
) def-com
)
9559 ;; An entry in *read-handlers-alist exists but have
9560 ;; a nil value, so we exit from here, disable `ac-mode'
9561 ;; and run the command again with it original behavior.
9562 ;; `ac-mode' will be restored on exit.
9563 (return-from anything-completing-read-default
9567 (call-interactively current-command
))
9569 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9570 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9571 (when (or (eq def-com
'completing-read
)
9572 ;; All specialized functions are prefixed by "anything"
9573 (and (stringp str-defcom
)
9574 (not (string-match "^anything" str-defcom
))))
9577 (cond (;; An anything specialized function exists, run it.
9578 (and def-com anything-completion-mode
)
9579 (apply def-com any-args
))
9580 (;; Try to handle `ido-completing-read' everywhere.
9581 (and def-com
(eq def-com
'ido-completing-read
))
9582 (setcar (memq collection def-args
)
9583 (all-completions "" collection predicate
))
9584 (apply def-com def-args
))
9585 (;; User set explicitely `completing-read' or something similar
9586 ;; in *read-handlers-alist, use this with exactly the same
9587 ;; args as in `completing-read'.
9588 ;; If we are here `anything-completion-mode' is now disabled.
9590 (apply def-com def-args
))
9591 (t ; Fall back to classic `anything-comp-read'.
9592 (anything-completing-read-default-1
9593 prompt collection predicate require-match
9594 initial-input hist def inherit-input-method
9595 str-command buf-name
)))
9597 ;; When exiting minibuffer, `this-command' is set to
9598 ;; `anything-exit-minibuffer', which is unwanted when starting
9599 ;; on another `completing-read', so restore `this-command' to
9600 ;; initial value when exiting.
9601 (setq this-command current-command
))))
9603 (defun* anything-generic-read-file-name
9604 (prompt &optional dir default-filename mustmatch initial predicate
)
9605 "An anything replacement of `read-file-name'."
9606 (declare (special anything-completion-mode
))
9607 (let* ((default (and default-filename
9608 (if (listp default-filename
)
9609 (car default-filename
)
9611 (init (or default initial dir default-directory
))
9612 (ini-input (and init
(expand-file-name init
)))
9613 (current-command this-command
)
9614 (str-command (symbol-name current-command
))
9615 (buf-name (format "*ac-mode-%s*" str-command
))
9616 (entry (assq current-command
9617 anything-completing-read-handlers-alist
))
9618 (def-com (cdr-safe entry
))
9619 (str-defcom (symbol-name def-com
))
9620 (def-args (list prompt dir default-filename mustmatch initial predicate
))
9621 ;; Append the two extra args needed to set the buffer and source name
9622 ;; in anything specialized functions.
9623 (any-args (append def-args
(list str-command buf-name
)))
9624 (ido-state ido-mode
)
9625 anything-completion-mode-start-message
; Be quiet
9626 anything-completion-mode-quit-message
; Same here
9628 (when (eq def-com
'ido
) (setq def-com
'ido-read-file-name
))
9629 (unless (or (not entry
) def-com
)
9630 (return-from anything-completing-read-default
9634 (call-interactively current-command
))
9636 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9637 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9638 (when (or (eq def-com
'read-file-name
)
9639 (eq def-com
'ido-read-file-name
)
9640 (and (stringp str-defcom
)
9641 (not (string-match "^anything" str-defcom
))))
9645 (cond (;; A specialized function exists, run it
9646 ;; with the two extra args specific to anything..
9647 (and def-com anything-completion-mode
9648 (not (eq def-com
'ido-read-file-name
)))
9649 (apply def-com any-args
))
9650 (;; Def-com value is `ido-read-file-name'
9651 ;; run it with default args.
9652 (and def-com
(eq def-com
'ido-read-file-name
))
9654 (apply def-com def-args
))
9655 (;; Def-com value is `read-file-name'
9656 ;; run it with default args.
9658 (apply def-com def-args
))
9659 (t ; Fall back to classic `anything-c-read-file-name'.
9660 (anything-c-read-file-name
9664 :initial-input
(expand-file-name init dir
)
9668 (ido-mode (if ido-state
1 -
1))
9669 ;; Same comment as in `anything-completing-read-default'.
9670 (setq this-command current-command
))
9671 (if (and mustmatch
(not (file-exists-p fname
)))
9672 (if (y-or-n-p "File does not exists, create buffer?")
9673 fname
(error "Abort file does not exists"))
9677 (define-minor-mode anything-completion-mode
9678 "Toggle generic anything completion.
9680 All functions in Emacs that use `completing-read'
9681 or `read-file-name' and friends will use anything interface
9682 when this mode is turned on.
9683 However you can modify this behavior for functions of your choice
9684 with `anything-completing-read-handlers-alist'.
9686 Called with a positive arg, turn on inconditionnaly, with a
9687 negative arg turn off.
9688 You can turn it on with `ac-mode'.
9690 Some crap emacs functions may not be supported,
9691 e.g `ffap-alternate-file' and maybe others
9692 You can add such functions to `anything-completing-read-handlers-alist'
9695 Note: This mode will work only partially on Emacs23."
9698 :lighter anything-completion-mode-string
9699 (declare (special completing-read-function
))
9700 (if anything-completion-mode
9702 (setq completing-read-function
'anything-completing-read-default
9703 read-file-name-function
'anything-generic-read-file-name
)
9704 (message anything-completion-mode-start-message
))
9705 (setq completing-read-function
(and (fboundp 'completing-read-default
)
9706 'completing-read-default
)
9707 read-file-name-function
(and (fboundp 'read-file-name-default
)
9708 'read-file-name-default
))
9709 (message anything-completion-mode-quit-message
)))
9711 (defalias 'ac-mode
'anything-completion-mode
)
9715 ;;; Eshell completion.
9717 ;; Enable like this in .emacs:
9719 ;; (add-hook 'eshell-mode-hook
9721 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9723 (defvar anything-c-source-esh
9724 '((name .
"Eshell completions")
9726 (setq pcomplete-current-completions nil
9727 pcomplete-last-completion-raw nil
)
9728 ;; Eshell-command add this hook in all minibuffers
9729 ;; Remove it for the anything one. (Fixed in Emacs24)
9730 (remove-hook 'minibuffer-setup-hook
'eshell-mode
)))
9731 (candidates . anything-esh-get-candidates
)
9732 (action . anything-ec-insert
))
9733 "Anything source for Eshell completion.")
9736 (defvar anything-ec-target
"")
9737 (defun anything-ec-insert (candidate)
9738 "Insert CANDIDATE at point.
9739 This is the same as `ac-insert', just inlined here for compatibility."
9741 (when (and anything-ec-target
9742 (search-backward anything-ec-target nil t
)
9743 (string= (buffer-substring (point) pt
) anything-ec-target
))
9744 (delete-region (point) pt
)))
9747 (defun anything-esh-get-candidates ()
9748 "Get candidates for eshell completion using `pcomplete'."
9750 (let* ((pcomplete-stub)
9751 pcomplete-seen pcomplete-norm-func
9752 pcomplete-args pcomplete-last pcomplete-index
9753 (pcomplete-autolist pcomplete-autolist
)
9754 (pcomplete-suffix-list pcomplete-suffix-list
))
9755 (with-anything-current-buffer
9757 with table
= (pcomplete-completions)
9758 with entry
= (condition-case nil
9760 (try-completion anything-pattern
(pcomplete-entries))
9761 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
9764 (let ((fc (car (last (pcomplete-parse-arguments)))))
9765 ;; Check if last arg require fname completion.
9766 (and (file-name-directory fc
) fc
))))
9767 for i in
(if (listp table
) table
; Emacs23 or commands.
9768 (all-completions pcomplete-stub table
)) ; Emacs24
9769 for file-cand
= (and entry
9770 (if (file-remote-p i
) i
9771 (expand-file-name i
(file-name-directory entry
))))
9772 if
(and file-cand
(or (file-remote-p file-cand
) (file-exists-p file-cand
)))
9773 collect file-cand into ls
9774 else collect i into ls
9776 (if (and entry
(not (string= entry
"")) (file-exists-p entry
))
9777 (append (list (expand-file-name entry default-directory
)) ls
) ls
))))))
9782 (defvar anything-c-source-eshell-history
9783 '((name .
"Eshell history")
9785 (let (eshell-hist-ignoredups)
9786 ;; Dump the content's of hist file
9787 ;; to `eshell-history-ring'.
9788 (eshell-read-history eshell-history-file-name
)
9789 ;; And now write the content's of ring to file.
9790 (eshell-write-history eshell-history-file-name t
)
9791 (with-current-buffer (anything-candidate-buffer 'global
)
9792 (insert-file-contents eshell-history-file-name
)))
9793 ;; Same comment as in `anything-c-source-esh'
9794 (remove-hook 'minibuffer-setup-hook
'eshell-mode
)))
9795 (candidates-in-buffer)
9796 (filtered-candidate-transformer .
(lambda (candidates sources
)
9797 (reverse candidates
)))
9798 (candidate-number-limit .
9999)
9799 (action .
(lambda (candidate)
9801 (insert candidate
))))
9802 "Anything source for Eshell history.")
9805 ;;; Show completion - an alternative of anything-show-completion.el.
9807 ;; Provide show completion with macro `with-anything-show-completion'.
9810 ;; Called each time cursor move in anything-buffer.
9811 (defun anything-c-show-completion ()
9812 (with-anything-current-buffer
9813 (overlay-put anything-c-show-completion-overlay
9814 'display
(anything-get-selection))))
9816 (defun anything-c-show-completion-init-overlay (beg end
)
9817 (and anything-c-turn-on-show-completion
9818 (setq anything-c-show-completion-overlay
(make-overlay beg end
))
9819 (overlay-put anything-c-show-completion-overlay
9820 'face
'anything-lisp-show-completion
)))
9822 (defmacro with-anything-show-completion
(beg end
&rest body
)
9823 "Show anything candidate in an overlay at point.
9824 BEG and END are the beginning and end position of the current completion
9825 in `anything-current-buffer'.
9826 BODY is an anything call where we want to enable show completion.
9827 If `anything-c-turn-on-show-completion' is nil just do nothing."
9828 (declare (indent 2) (debug t
))
9829 `(let ((anything-move-selection-after-hook
9830 (and anything-c-turn-on-show-completion
9831 (append (list 'anything-c-show-completion
)
9832 anything-move-selection-after-hook
))))
9834 (progn (anything-c-show-completion-init-overlay ,beg
,end
)
9836 (and anything-c-turn-on-show-completion
9837 (delete-overlay anything-c-show-completion-overlay
)))))
9840 ;;; Lisp symbol completion.
9844 (defun anything-lisp-completion-at-point ()
9845 "Anything lisp symbol completion at point."
9847 (let* ((data (lisp-completion-at-point))
9849 (end (point)) ; 'cadr data' is wrong when no space after point.
9850 (plist (nthcdr 3 data
))
9851 (pred (plist-get plist
:predicate
))
9853 (target (and beg end
(buffer-substring-no-properties beg end
)))
9854 (candidates (all-completions target
(nth 2 data
) pred
))
9855 (anything-quit-if-no-candidate t
)
9856 (anything-execute-action-at-once-if-one t
)
9857 (anything-match-plugin-enabled
9858 (member 'anything-compile-source--match-plugin
9859 anything-compile-source-functions
)))
9861 (with-anything-show-completion beg end
9862 ;; Overlay is initialized now in anything-current-buffer.
9865 '((name .
"Lisp completion")
9867 (with-current-buffer (anything-candidate-buffer 'global
)
9868 (loop for sym in candidates
9869 for len
= (length sym
)
9870 when
(> len lgst-len
) do
(setq lgst-len len
)
9871 do
(insert (concat sym
"\n"))))))
9872 (candidates-in-buffer)
9873 (persistent-action . anything-lisp-completion-persistent-action
)
9874 (persistent-help .
"Show brief doc in mode-line")
9875 (filtered-candidate-transformer anything-lisp-completion-transformer
)
9876 (action .
(lambda (candidate)
9877 (delete-region beg end
)
9878 (insert candidate
))))
9879 :input
(if anything-match-plugin-enabled
(concat target
" ") target
)))
9880 (message "[No Match]"))))
9882 (defun anything-lisp-completion-persistent-action (candidate)
9883 (let ((cursor-in-echo-area t
)
9884 mode-line-in-non-selected-windows
)
9885 (anything-c-eldoc-show-in-mode-line
9887 (anything-c-get-first-line-documentation
9889 'face
'anything-lisp-completion-info
))))
9891 (defun anything-lisp-completion-transformer (candidates source
)
9892 "Anything candidates transformer for lisp completion."
9893 (declare (special lgst-len
))
9894 (loop for c in candidates
9895 for sym
= (intern c
)
9896 for annot
= (cond ((commandp sym
) " (Com)")
9897 ((fboundp sym
) " (Fun)")
9898 ((boundp sym
) " (Var)")
9899 ((facep sym
) " (Face)"))
9900 for spaces
= (make-string (- lgst-len
(length c
)) ?
)
9901 collect
(cons (concat c spaces annot
) c
)))
9903 (defun anything-c-get-first-line-documentation (sym)
9904 "Return first line documentation of symbol SYM.
9905 If SYM is not documented, return \"Not documented\"."
9906 (let ((doc (cond ((fboundp sym
)
9907 (documentation sym t
))
9909 (documentation-property sym
'variable-documentation t
))
9911 (face-documentation sym
))
9913 (if (and doc
(not (string= doc
""))
9914 ;; `documentation' return "\n\n(args...)"
9915 ;; for CL-style functions.
9916 (not (string-match-p "^\n\n" doc
)))
9917 (car (split-string doc
"\n"))
9920 ;;; File completion.
9922 ;; Complete file name at point.
9923 (defun anything-c-thing-before-point ()
9924 "Get symbol name before point.
9925 Borrowed from anything-complete.el, inlined here for compatibility."
9927 (let ((beg (point)))
9928 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
9929 (when (re-search-backward
9930 "\\_<" (field-beginning nil nil
(point-at-bol)) t
)
9931 (buffer-substring-no-properties beg
(match-end 0))))))
9934 (defun anything-c-complete-file-name-at-point ()
9935 "Complete file name at point."
9937 (let* ((init (substring-no-properties (thing-at-point 'filename
)))
9939 (beg (- (point) (length init
)))
9940 (anything-quit-if-no-candidate t
)
9941 (anything-execute-action-at-once-if-one t
)
9943 (with-anything-show-completion beg end
9944 (setq completion
(anything-c-read-file-name "FileName: "
9945 :initial-input init
)))
9946 (anything-c-insert-file-name-completion-at-point completion
)))
9949 (defvar anything-lisp-completion-counter
0)
9951 (defun anything-lisp-completion-at-point-or-indent (arg)
9952 "First call indent and second call complete lisp symbol.
9953 The second call should happen before `anything-lisp-completion-or-indent-delay',
9954 after this delay, next call will indent again.
9955 After completion, next call is always indent.
9956 See that like click and double mouse click.
9957 One hit indent, two quick hits maybe indent and complete."
9959 ;; Be sure `indent-for-tab-command' will not try
9960 ;; to use `completion-at-point'.
9961 (let ((tab-always-indent (if (eq tab-always-indent
'complete
)
9962 t tab-always-indent
)))
9963 (incf anything-lisp-completion-counter
)
9965 (if (> anything-lisp-completion-counter
1)
9966 (anything-lisp-completion-or-file-name-at-point)
9967 (indent-for-tab-command arg
))
9968 ;; After `anything-lisp-completion-or-indent-delay' seconds
9970 (run-with-timer anything-lisp-completion-or-indent-delay nil
9972 (setq anything-lisp-completion-counter
0)))
9973 ;; Always reset to 0 at second hit.
9974 (when (eq anything-lisp-completion-counter
2)
9975 (setq anything-lisp-completion-counter
0)))))
9978 (defun anything-lisp-completion-or-file-name-at-point ()
9979 "Complete lisp symbol or filename at point.
9980 Filename completion happen if filename is started in
9981 or between double quotes."
9983 (let ((tap (substring-no-properties (thing-at-point 'filename
))))
9984 (if (and tap
(string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap
)
9985 (save-excursion (search-backward "\"" (point-at-bol) t
)))
9986 (anything-c-complete-file-name-at-point)
9987 (anything-lisp-completion-at-point))))
9989 (defun anything-c-apropos-init (test default
)
9990 "Init candidates buffer for `anything-c-apropos' sources."
9991 (with-current-buffer (anything-candidate-buffer 'global
)
9992 (goto-char (point-min))
9993 (when (and default
(stringp default
)
9994 ;; Some defaults args result as
9995 ;; (symbol-name nil) == "nil".
9996 ;; e.g debug-on-entry.
9997 (not (string= default
"nil"))
9998 (funcall test
(intern default
)))
9999 (insert (concat default
"\n")))
10000 (loop with all
= (all-completions "" obarray test
)
10002 unless
(and default
(eq sym default
))
10003 do
(insert (concat sym
"\n")))))
10006 ;;; Run Externals commands within Emacs with anything completion
10009 (defvar anything-external-command-history nil
)
10011 (defun anything-c-external-commands-list-1 (&optional sort
)
10012 "Returns a list of all external commands the user can execute.
10013 If `anything-c-external-commands-list' is non-nil it will
10014 return its contents. Else it calculates all external commands
10015 and sets `anything-c-external-commands-list'."
10016 (if anything-c-external-commands-list
10017 anything-c-external-commands-list
10018 (setq anything-c-external-commands-list
10020 with paths
= (split-string (getenv "PATH") path-separator
)
10021 with completions
= ()
10023 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
10024 for lsdir
= (loop for i in
(directory-files dir t
)
10025 for bn
= (file-name-nondirectory i
)
10026 when
(and (not (member bn completions
))
10027 (not (file-directory-p i
))
10028 (file-executable-p i
))
10030 append lsdir into completions
10031 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
10033 (defun anything-run-or-raise (exe &optional file
)
10034 "Generic command that run asynchronously EXE.
10035 If EXE is already running just jump to his window if `anything-raise-command'
10037 When FILE argument is provided run EXE with FILE.
10038 In this case EXE must be provided as \"EXE %s\"."
10039 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10041 (proc (if file
(concat real-com
" " file
) real-com
)))
10042 (if (get-process proc
)
10043 (if anything-raise-command
10044 (shell-command (format anything-raise-command real-com
))
10045 (error "Error: %s is already running" real-com
))
10046 (when (loop for i in anything-c-external-commands-list thereis real-com
)
10047 (message "Starting %s..." real-com
)
10049 (start-process-shell-command
10050 proc nil
(format exe
(shell-quote-argument file
)))
10051 (start-process-shell-command proc nil real-com
))
10052 (set-process-sentinel
10054 #'(lambda (process event
)
10055 (when (and (string= event
"finished\n")
10056 anything-raise-command
10057 (not (anything-c-get-pid-from-process-name real-com
)))
10058 (shell-command (format anything-raise-command
"emacs")))
10059 (message "%s process...Finished." process
))))
10060 (setq anything-c-external-commands-list
10062 (delete real-com anything-c-external-commands-list
))))))
10066 ;;; Generic action functions
10069 (defun anything-c-file-buffers (filename)
10070 "Returns a list of buffer names corresponding to FILENAME."
10071 (let ((name (expand-file-name filename
))
10073 (dolist (buf (buffer-list) buf-list
)
10074 (let ((bfn (buffer-file-name buf
)))
10075 (when (and bfn
(string= name bfn
))
10076 (push (buffer-name buf
) buf-list
))))))
10078 (defun anything-revert-buffer (candidate)
10079 (with-current-buffer candidate
10080 (when (or (buffer-modified-p)
10081 (not (verify-visited-file-modtime
10082 (get-buffer candidate
))))
10083 (revert-buffer t t
))))
10085 (defun anything-revert-marked-buffers (ignore)
10086 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
10088 (defun anything-kill-marked-buffers (ignore)
10089 (mapc 'kill-buffer
(anything-marked-candidates)))
10091 (defun anything-c-delete-file (file)
10092 "Delete the given file after querying the user.
10093 Ask to kill buffers associated with that file, too."
10094 (let ((buffers (anything-c-file-buffers file
)))
10095 (if (< emacs-major-version
24)
10096 ;; `dired-delete-file' in Emacs versions < 24
10097 ;; doesn't support delete-by-moving-to-trash
10098 ;; so use `delete-directory' and `delete-file'
10100 (cond ((and (not (file-symlink-p file
))
10101 (file-directory-p file
)
10102 (directory-files file t dired-re-no-dot
))
10103 (when (y-or-n-p (format "Recursive delete of `%s'? " file
))
10104 (delete-directory file
'recursive
)))
10105 ((and (not (file-symlink-p file
))
10106 (file-directory-p file
))
10107 (delete-directory file
))
10108 (t (delete-file file
)))
10110 file
'dired-recursive-deletes delete-by-moving-to-trash
))
10112 (dolist (buf buffers
)
10113 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
10114 (kill-buffer buf
))))))
10116 (defun anything-get-mailcap-for-file (filename)
10117 "Get the command to use for FILENAME from mailcap files.
10118 The command is like <command %s> and is meant to use with `format'."
10119 (mailcap-parse-mailcaps)
10120 (let* ((ext (file-name-extension filename
))
10121 (mime (when ext
(mailcap-extension-to-mime ext
)))
10122 (result (when mime
(mailcap-mime-info mime
))))
10123 ;; If elisp file have no associations in .mailcap
10124 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10125 (when (stringp result
) result
)))
10127 (defun anything-get-default-program-for-file (filename)
10128 "Try to find a default program to open FILENAME.
10129 Try first in `anything-c-external-programs-associations' and then in mailcap file
10130 if nothing found return nil."
10131 (let* ((ext (file-name-extension filename
))
10132 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
10133 (cond ((and def-prog
(not (string= def-prog
"")))
10134 (concat def-prog
" %s"))
10135 ((and anything-c-default-external-file-browser
10136 (file-directory-p filename
))
10137 (concat anything-c-default-external-file-browser
" %s"))
10138 (t (anything-get-mailcap-for-file filename
)))))
10140 (defun anything-c-open-file-externally (file)
10141 "Open FILE with an external program.
10142 Try to guess which program to use with `anything-get-default-program-for-file'.
10143 If not found or a prefix arg is given query the user which tool to use."
10144 (let* ((fname (expand-file-name file
))
10145 (collection (anything-c-external-commands-list-1 'sort
))
10146 (def-prog (anything-get-default-program-for-file fname
))
10147 (real-prog-name (if (or anything-current-prefix-arg
(not def-prog
))
10148 ;; Prefix arg or no default program.
10150 (anything-comp-read
10151 "Program: " collection
10153 :name
"Open file Externally"
10154 :history anything-external-command-history
)
10155 ;; Always prompt to set this program as default.
10156 (setq def-prog nil
))
10157 ;; No prefix arg or default program exists.
10158 (replace-regexp-in-string " %s\\| '%s'" "" def-prog
)))
10159 (program (concat real-prog-name
" %s")))
10160 (unless (or def-prog
; Association exists, no need to record it.
10161 ;; Don't try to record non--filenames associations (e.g urls).
10162 (not (file-exists-p fname
)))
10166 "Do you want to make `%s' the default program for this kind of files? "
10168 (anything-aif (assoc (file-name-extension fname
)
10169 anything-c-external-programs-associations
)
10170 (setq anything-c-external-programs-associations
10171 (delete it anything-c-external-programs-associations
)))
10172 (push (cons (file-name-extension fname
)
10174 "Program (Add args maybe and confirm): " real-prog-name
))
10175 anything-c-external-programs-associations
)
10176 (customize-save-variable 'anything-c-external-programs-associations
10177 anything-c-external-programs-associations
)))
10178 (anything-run-or-raise program file
)
10179 (setq anything-external-command-history
10180 (cons real-prog-name
10181 (delete real-prog-name
10182 (loop for i in anything-external-command-history
10183 when
(executable-find i
) collect i
))))))
10185 (defun anything-c-find-file-or-marked (candidate)
10186 "Open file CANDIDATE or open anything marked files in background."
10187 (let ((marked (anything-marked-candidates))
10188 (ffap-newfile-prompt anything-ff-newfile-prompt-p
)
10189 (find-file-wildcards nil
))
10190 (if (> (length marked
) 1)
10191 ;; Open all marked files in background and display
10193 (progn (mapc 'find-file-noselect
(cdr marked
))
10194 (find-file (car marked
)))
10195 (if (and (not (file-exists-p candidate
))
10196 (and ffap-url-regexp
10197 (not (string-match ffap-url-regexp candidate
)))
10198 (string-match "/$" candidate
))
10199 ;; A a non--existing filename ending with /
10200 ;; Create a directory and jump to it.
10201 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
10202 (let ((dirfname (directory-file-name candidate
)))
10203 (if (file-exists-p dirfname
)
10204 (error "Mkdir: Unable to create directory `%s': file exists."
10205 (anything-c-basename dirfname
))
10206 (make-directory candidate
'parent
)))
10207 (anything-find-files-1 candidate
))
10208 ;; A non--existing filename NOT ending with / or
10209 ;; an existing filename, create or jump to it.
10210 (find-file-at-point (car marked
))))))
10212 (defun anything-delete-marked-files (ignore)
10213 (let* ((files (anything-marked-candidates))
10214 (len (length files
)))
10216 (format "Delete *%s File(s):\n%s"
10218 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
10219 (message "(No deletions performed)")
10221 (set-text-properties 0 (length i
) nil i
)
10222 (anything-c-delete-file i
))
10223 (message "%s File(s) deleted" len
))))
10225 (defun anything-ediff-marked-buffers (candidate &optional merge
)
10226 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10227 With optional arg MERGE call `ediff-merge-buffers'."
10228 (let ((lg-lst (length (anything-marked-candidates)))
10232 (error "Error:You have to mark at least 1 buffer"))
10234 (setq buf1 anything-current-buffer
10235 buf2
(first (anything-marked-candidates))))
10237 (setq buf1
(first (anything-marked-candidates))
10238 buf2
(second (anything-marked-candidates))))
10240 (error "Error:To much buffers marked!")))
10242 (ediff-merge-buffers buf1 buf2
)
10243 (ediff-buffers buf1 buf2
))))
10245 (defun anything-ediff-marked-buffers-merge (candidate)
10246 "Ediff merge `anything-current-buffer' with CANDIDATE.
10247 See `anything-ediff-marked-buffers'."
10248 (anything-ediff-marked-buffers candidate t
))
10250 (defun anything-bookmark-get-bookmark-from-name (bmk)
10251 "Return bookmark name even if it is a bookmark with annotation.
10252 e.g prepended with *.
10253 Return nil if bmk is not a valid bookmark."
10254 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
10255 (if (assoc bookmark bookmark-alist
)
10257 (when (assoc bmk bookmark-alist
)
10260 (defun anything-delete-marked-bookmarks (ignore)
10261 "Delete this bookmark or all marked bookmarks."
10262 (dolist (i (anything-marked-candidates))
10263 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
10266 (defun anything-require-or-error (feature function
)
10267 (or (require feature nil t
)
10268 (error "Need %s to use `%s'." feature function
)))
10270 (defun anything-find-buffer-on-elscreen (candidate)
10271 "Open buffer in new screen, if marked buffers open all in elscreens."
10272 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
10273 (anything-aif (anything-marked-candidates)
10275 (let ((target-screen (elscreen-find-screen-by-buffer
10276 (get-buffer i
) 'create
)))
10277 (elscreen-goto target-screen
)))
10278 (let ((target-screen (elscreen-find-screen-by-buffer
10279 (get-buffer candidate
) 'create
)))
10280 (elscreen-goto target-screen
))))
10282 (defun anything-elscreen-find-file (file)
10283 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
10284 (elscreen-find-file file
))
10287 (defun w32-shell-execute-open-file (file)
10288 (interactive "fOpen file:")
10290 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10292 (replace-regexp-in-string ; strip cygdrive paths
10293 "/cygdrive/\\(.\\)" "\\1:"
10294 file nil nil
) nil t
))))
10296 (defun anything-c-open-file-with-default-tool (file)
10297 "Open FILE with the default tool on this platform."
10298 (if (eq system-type
'windows-nt
)
10299 (w32-shell-execute-open-file file
)
10300 (start-process "anything-c-open-file-with-default-tool"
10302 (cond ((eq system-type
'gnu
/linux
)
10304 ((or (eq system-type
'darwin
) ;; Mac OS X
10305 (eq system-type
'macos
)) ;; Mac OS 9
10309 (defun anything-c-open-dired (file)
10310 "Opens a dired buffer in FILE's directory. If FILE is a
10311 directory, open this directory."
10312 (if (file-directory-p file
)
10314 (dired (file-name-directory file
))
10315 (dired-goto-file file
)))
10317 (defun anything-c-display-to-real-line (candidate)
10318 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
10319 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
10320 (error "Line number not found")))
10322 (defun anything-c-action-line-goto (lineno-and-content)
10323 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
10324 (append lineno-and-content
10325 (list (if (and (anything-attr-defined 'target-file
)
10326 (not anything-in-persistent-action
))
10327 'find-file-other-window
10330 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
10331 (apply #'anything-goto-file-line
10332 (if (stringp file-line-content
)
10333 ;; Case: filtered-candidate-transformer is skipped
10334 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
10335 file-line-content
)))
10338 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
10339 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
10341 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10342 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
10343 (let ((filename (match-string 1 candidate
))
10344 (lineno (match-string 2 candidate
))
10345 (content (match-string 3 candidate
)))
10346 (cons (format "%s:%s\n %s"
10347 (propertize filename
'face compilation-info-face
)
10348 (propertize lineno
'face compilation-line-face
)
10350 (list (expand-file-name
10352 (or (anything-interpret-value (anything-attr 'default-directory
))
10353 (and (anything-candidate-buffer)
10354 (buffer-local-value
10355 'default-directory
(anything-candidate-buffer)))))
10356 (string-to-number lineno
) content
)))))
10358 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
10359 (anything-aif (anything-attr 'before-jump-hook
)
10361 (when file
(funcall find-file-function file
))
10362 (if (anything-attr-defined 'adjust
)
10363 (anything-c-goto-line-with-adjustment lineno content
)
10364 (anything-goto-line lineno
))
10365 (unless (anything-attr-defined 'recenter
)
10366 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
10367 (anything-aif (anything-attr 'after-jump-hook
)
10369 (when anything-in-persistent-action
10370 (anything-match-line-color-current-line)))
10372 (defun anything-find-file-as-root (candidate)
10373 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
10375 (defun anything-find-many-files (ignore)
10376 (mapc 'find-file
(anything-marked-candidates)))
10378 ;; borrowed from etags.el
10379 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10380 (defun anything-c-goto-line-with-adjustment (line line-content
)
10383 ;; This constant is 1/2 the initial search window.
10384 ;; There is no sense in making it too small,
10385 ;; since just going around the loop once probably
10386 ;; costs about as much as searching 2000 chars.
10389 pat
(concat (if (eq selective-display t
)
10390 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10391 (regexp-quote line-content
)))
10392 ;; If no char pos was given, try the given line number.
10393 (setq startpos
(progn (anything-goto-line line
) (point)))
10394 (or startpos
(setq startpos
(point-min)))
10395 ;; First see if the tag is right at the specified location.
10396 (goto-char startpos
)
10397 (setq found
(looking-at pat
))
10398 (while (and (not found
)
10400 (goto-char (- startpos offset
))
10403 (re-search-forward pat
(+ startpos offset
) t
)
10404 offset
(* 3 offset
))) ; expand search window
10406 (re-search-forward pat nil t
)
10407 (error "not found")))
10408 ;; Position point at the right place
10409 ;; if the search string matched an extra Ctrl-m at the beginning.
10410 (and (eq selective-display t
)
10413 (beginning-of-line))
10415 (anything-document-attribute 'default-directory
"type . file-line"
10416 "`default-directory' to interpret file.")
10417 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
10418 "Function to call before jumping to the target location.")
10419 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
10420 "Function to call after jumping to the target location.")
10421 (anything-document-attribute 'adjust
"type . file-line"
10422 "Search around line matching line contents.")
10423 (anything-document-attribute 'recenter
"type . file-line / line"
10424 "`recenter' after jumping.")
10425 (anything-document-attribute 'target-file
"type . line"
10426 "Goto line of target-file.")
10429 (defun anything-c-call-interactively (cmd-or-name)
10430 "Execute CMD-OR-NAME as Emacs command.
10431 It is added to `extended-command-history'.
10432 `anything-current-prefix-arg' is used as the command's prefix argument."
10433 (setq extended-command-history
10434 (cons (anything-c-stringify cmd-or-name
)
10435 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
10436 (let ((current-prefix-arg anything-current-prefix-arg
)
10437 (cmd (anything-c-symbolify cmd-or-name
)))
10438 (if (stringp (symbol-function cmd
))
10439 (execute-kbd-macro (symbol-function cmd
))
10440 (setq this-command cmd
)
10441 (call-interactively cmd
))))
10444 (defun anything-c-set-variable (var)
10445 "Set value to VAR interactively."
10447 (let ((sym (anything-c-symbolify var
)))
10448 (set sym
(eval-minibuffer (format "Set %s: " var
)
10449 (prin1-to-string (symbol-value sym
))))))
10451 ;; (anything-c-set-variable 'hh)
10455 ;;; Persistent Action Helpers
10458 (defvar anything-match-line-overlay-face nil
)
10459 (defvar anything-match-line-overlay nil
)
10461 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
10462 "Highlight and underline current position"
10463 (let ((args (list (or start
(line-beginning-position))
10464 (or end
(1+ (line-end-position)))
10466 (if (not anything-match-line-overlay
)
10467 (setq anything-match-line-overlay
(apply 'make-overlay args
))
10468 (apply 'move-overlay anything-match-line-overlay args
)))
10469 (overlay-put anything-match-line-overlay
10470 'face
(or face anything-match-line-overlay-face
))
10475 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
10478 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
10480 (defun anything-match-line-cleanup ()
10481 (when anything-match-line-overlay
10482 (delete-overlay anything-match-line-overlay
)
10483 (setq anything-match-line-overlay nil
)))
10485 (defun anything-match-line-update ()
10486 (when anything-match-line-overlay
10487 (delete-overlay anything-match-line-overlay
)
10488 (anything-match-line-color-current-line)))
10490 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
10491 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
10494 ;;; Actions Transformers
10498 (defun anything-c-transform-file-load-el (actions candidate
)
10499 "Add action to load the file CANDIDATE if it is an emacs lisp
10500 file. Else return ACTIONS unmodified."
10501 (if (member (file-name-extension candidate
) '("el" "elc"))
10502 (append actions
'(("Load Emacs Lisp File" . load-file
)))
10505 (defun anything-c-transform-file-browse-url (actions candidate
)
10506 "Add an action to browse the file CANDIDATE if it in a html
10507 file or URL. Else return ACTIONS unmodified."
10508 (let ((browse-action '("Browse with Browser" . browse-url
)))
10509 (cond ((string-match "^http\\|^ftp" candidate
)
10510 (cons browse-action actions
))
10511 ((string-match "\\.html?$" candidate
)
10512 (append actions
(list browse-action
)))
10516 (defun anything-c-transform-function-call-interactively (actions candidate
)
10517 "Add an action to call the function CANDIDATE interactively if
10518 it is a command. Else return ACTIONS unmodified."
10519 (if (commandp (intern-soft candidate
))
10520 (append actions
'(("Call Interactively"
10522 anything-c-call-interactively
)))
10526 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
10527 "If CANDIDATE's `car' is a command, then add an action to
10528 evaluate it and put it onto the `command-history'."
10529 (if (commandp (car (read candidate
)))
10530 ;; Make it first entry
10531 (cons '("Eval and put onto command-history" .
10533 (let ((sym (read sexp
)))
10535 (setq command-history
10536 (cons sym command-history
)))))
10541 ;;; Candidate Transformers
10545 (defun anything-c-skip-boring-buffers (buffers)
10546 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
10548 (defun anything-c-skip-current-buffer (buffers)
10549 (if anything-allow-skipping-current-buffer
10550 (remove (buffer-name anything-current-buffer
) buffers
)
10553 (defun anything-c-shadow-boring-buffers (buffers)
10554 "Buffers matching `anything-c-boring-buffer-regexp' will be
10555 displayed with the `file-name-shadow' face if available."
10556 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
10558 (defvar anything-c-buffer-display-string-functions
10559 '(anything-c-buffer-display-string--compilation
10560 anything-c-buffer-display-string--shell
10561 anything-c-buffer-display-string--eshell
)
10562 "Functions to setup display string for buffer.
10564 Function has one argument, buffer name.
10565 If it returns string, use it.
10566 If it returns nil, display buffer name.
10567 See `anything-c-buffer-display-string--compilation' for example.")
10569 (defun anything-c-transform-buffer-display-string (buffers)
10570 "Setup display string for buffer candidates
10571 using `anything-c-buffer-display-string-functions'."
10572 (loop for buf in buffers
10576 for disp
= (progn (set-buffer buf
)
10577 (run-hook-with-args-until-success
10578 'anything-c-buffer-display-string-functions buf
))
10579 collect
(if disp
(cons disp buf
) buf
)))
10581 (defun anything-c-buffer-display-string--compilation (buf)
10582 (anything-aif (car compilation-arguments
)
10583 (format "%s: %s [%s]" buf it default-directory
)))
10585 (defun anything-c-buffer-display-string--eshell (buf)
10586 (declare (special eshell-history-ring
))
10587 (when (eq major-mode
'eshell-mode
)
10588 (format "%s: %s [%s]" buf
10589 (ignore-errors (ring-ref eshell-history-ring
0))
10590 default-directory
)))
10592 (defun anything-c-buffer-display-string--shell (buf)
10593 (when (eq major-mode
'shell-mode
)
10594 (format "%s: %s [%s]" buf
10595 (ignore-errors (ring-ref comint-input-ring
0))
10596 default-directory
)))
10599 (defun anything-c-shadow-boring-files (files)
10600 "Files matching `anything-c-boring-file-regexp' will be
10601 displayed with the `file-name-shadow' face if available."
10602 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
10604 (defun anything-c-skip-boring-files (files)
10605 "Files matching `anything-c-boring-file-regexp' will be skipped."
10606 (anything-c-skip-entries files anything-c-boring-file-regexp
))
10607 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10609 (defun anything-c-skip-current-file (files)
10610 "Current file will be skipped."
10611 (remove (buffer-file-name anything-current-buffer
) files
))
10613 (defun anything-c-w32-pathname-transformer (args)
10614 "Change undesirable features of windows pathnames to ones more acceptable to
10615 other candidate transformers."
10616 (if (eq system-type
'windows-nt
)
10617 (mapcar (lambda (x)
10618 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
10619 (mapcar (lambda (y)
10620 (replace-regexp-in-string "\\\\" "/" y
)) args
))
10623 (defun anything-c-shorten-home-path (files)
10624 "Replaces /home/user with ~."
10625 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10627 (mapcar (lambda (file)
10628 (if (and (stringp file
) (string-match home file
))
10629 (cons (replace-match "~" nil nil file
) file
)
10634 (defun anything-c-mark-interactive-functions (functions)
10635 "Mark interactive functions (commands) with (i) after the function name."
10637 (loop for function in functions
10638 do
(push (cons (concat function
10639 (when (commandp (intern-soft function
)) " (i)"))
10642 finally
(return (nreverse list
)))))
10645 ;;; Adaptive Sorting of Candidates
10649 (defvar anything-c-adaptive-done nil
10650 "nil if history information is not yet stored for the current
10653 (defvar anything-c-adaptive-history nil
10654 "Contains the stored history information.
10655 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10657 (defadvice anything-initial-setup
(before anything-c-adaptive-initialize activate
)
10658 "Reset `anything-c-adaptive-done' when anything is started."
10659 (when anything-c-use-adaptative-sorting
10660 (setq anything-c-adaptive-done nil
)))
10662 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
10663 "Store history information when action is executed on selected candidate."
10664 (when anything-c-use-adaptative-sorting
10665 (anything-c-adaptive-store-selection)))
10667 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
10668 "Store history information when the user goes to the action buffer."
10669 (when anything-c-use-adaptative-sorting
10670 (anything-c-adaptive-store-selection)))
10672 (defun anything-c-source-use-adaptative-p (&optional source-name
)
10673 "Return current source only if it use adaptative history, nil otherwise."
10674 (when anything-c-use-adaptative-sorting
10675 (let* ((source (or source-name
(anything-get-current-source)))
10676 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10677 (assoc (assoc-default 'type source
)
10678 anything-type-attributes
))
10679 (assoc-default 'candidate-transformer
10680 (assoc (assoc-default 'type source
)
10681 anything-type-attributes
))
10682 (assoc-default 'filtered-candidate-transformer source
)
10683 (assoc-default 'candidate-transformer source
))))
10684 (if (listp adapt-source
)
10685 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
10686 (when (eq adapt-source
'anything-c-adaptive-sort
) source
)))))
10688 (defun anything-c-adaptive-store-selection ()
10689 "Store history information for the selected candidate."
10690 (unless anything-c-adaptive-done
10691 (setq anything-c-adaptive-done t
)
10692 (let ((source (anything-c-source-use-adaptative-p)))
10694 (let* ((source-name (or (assoc-default 'type source
)
10695 (assoc-default 'name source
)))
10696 (source-info (or (assoc source-name anything-c-adaptive-history
)
10698 (push (list source-name
) anything-c-adaptive-history
)
10699 (car anything-c-adaptive-history
))))
10700 (selection (anything-get-selection))
10701 (selection-info (progn
10702 (setcdr source-info
10704 (let ((found (assoc selection
(cdr source-info
))))
10709 ;; move entry to the beginning of the
10710 ;; list, so that it doesn't get
10711 ;; trimmed when the history is
10713 (setcdr source-info
10714 (delete found
(cdr source-info
)))
10716 (cdr source-info
)))
10717 (cadr source-info
)))
10718 (pattern-info (progn
10719 (setcdr selection-info
10721 (let ((found (assoc anything-pattern
(cdr selection-info
))))
10724 (cons anything-pattern
0)
10726 ;; move entry to the beginning of the
10727 ;; list, so if two patterns used the
10728 ;; same number of times then the one
10729 ;; used last appears first in the list
10730 (setcdr selection-info
10731 (delete found
(cdr selection-info
)))
10733 (cdr selection-info
)))
10734 (cadr selection-info
))))
10736 ;; increase usage count
10737 (setcdr pattern-info
(1+ (cdr pattern-info
)))
10739 ;; truncate history if needed
10740 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
10741 (setcdr selection-info
10742 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
10744 (defun anything-c-adaptative-maybe-load-history ()
10745 (when (and anything-c-use-adaptative-sorting
10746 (file-readable-p anything-c-adaptive-history-file
))
10747 (load-file anything-c-adaptive-history-file
)))
10749 (add-hook 'emacs-startup-hook
'anything-c-adaptative-maybe-load-history
)
10750 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
10752 (defun anything-c-adaptive-save-history (&optional arg
)
10753 "Save history information to file given by `anything-c-adaptive-history-file'."
10755 (when anything-c-use-adaptative-sorting
10758 ";; -*- mode: emacs-lisp -*-\n"
10759 ";; History entries used for anything adaptive display.\n")
10760 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
10763 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
10764 (unless arg
'quiet
)))))
10766 (defun anything-c-adaptive-sort (candidates source
)
10767 "Sort the CANDIDATES for SOURCE by usage frequency.
10768 This is a filtered candidate transformer you can use for the
10769 attribute `filtered-candidate-transformer' of a source in
10770 `anything-sources' or a type in `anything-type-attributes'."
10771 (let* ((source-name (or (assoc-default 'type source
)
10772 (assoc-default 'name source
)))
10773 (source-info (assoc source-name anything-c-adaptive-history
)))
10776 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
10778 (mapcar (lambda (candidate-info)
10780 (dolist (pattern-info (cdr candidate-info
))
10781 (if (not (equal (car pattern-info
)
10783 (incf count
(cdr pattern-info
))
10785 ;; if current pattern is equal to the previously
10786 ;; used one then this candidate has priority
10787 ;; (that's why its count is boosted by 10000) and
10788 ;; it only has to compete with other candidates
10789 ;; which were also selected with the same pattern
10790 (setq count
(+ 10000 (cdr pattern-info
)))
10792 (cons (car candidate-info
) count
)))
10793 (cdr source-info
)))
10795 (if (and usage
(consp usage
))
10796 ;; sort the list in descending order, so candidates with highest
10797 ;; priorty come first
10799 (setq usage
(sort usage
(lambda (first second
)
10800 (> (cdr first
) (cdr second
)))))
10802 ;; put those candidates first which have the highest usage count
10803 (dolist (info usage
)
10804 (when (member* (car info
) candidates
10805 :test
'anything-c-adaptive-compare
)
10806 (push (car info
) sorted
)
10807 (setq candidates
(remove* (car info
) candidates
10808 :test
'anything-c-adaptive-compare
))))
10810 ;; and append the rest
10811 (append (reverse sorted
) candidates nil
))
10812 (message "Your `%s' is maybe corrupted or too old, \
10813 you should reinitialize it with `anything-c-reset-adaptative-history'"
10814 anything-c-adaptive-history-file
)
10817 ;; if there is no information stored for this source then do nothing
10821 (defun anything-c-reset-adaptative-history ()
10822 "Delete all `anything-c-adaptive-history' and his file.
10823 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
10825 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
10826 (setq anything-c-adaptive-history nil
)
10827 (delete-file anything-c-adaptive-history-file
)))
10829 (defun anything-c-adaptive-compare (x y
)
10830 "Compare candidates X and Y taking into account that the
10831 candidate can be in (DISPLAY . REAL) format."
10832 (equal (if (listp x
)
10844 (defvar anything-outline-goto-near-line-flag t
)
10845 (defvar anything-outline-using nil
)
10846 (defun anything-after-update-hook--outline ()
10847 (if (and (eq anything-outline-using t
)
10848 (eq anything-outline-goto-near-line-flag t
))
10849 (anything-outline-goto-near-line)))
10850 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
10852 (defun anything-outline-goto-near-line ()
10853 (with-anything-window
10854 ;; TODO need consideration whether to update position by every input.
10855 (when t
; (equal anything-pattern "")
10856 (anything-goto-line 2)
10857 (let ((lineno (with-anything-current-buffer
10858 (line-number-at-pos (car anything-current-position
)))))
10860 (while (<= (progn (skip-chars-forward " ")
10861 (or (number-at-point) lineno
))
10866 (return-from exit
))))
10868 (and (bobp) (forward-line 1))
10869 (and (anything-pos-header-line-p) (forward-line -
2))
10870 (anything-mark-current-line)))))
10877 ;; Plug-in: info-index
10878 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
10880 (unless (anything-candidate-buffer)
10881 (save-window-excursion
10884 (tobuf (anything-candidate-buffer 'global
))
10885 (infobuf (current-buffer))
10887 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
10888 (Info-goto-node node
)
10889 (goto-char (point-min))
10890 (while (search-forward "\n* " nil t
)
10891 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
10892 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
10893 (setq s
(point-at-bol)
10895 (with-current-buffer tobuf
10896 (insert-buffer-substring infobuf s e
)
10897 (insert "\n"))))))))))
10899 (defun anything-c-info-goto (node-line)
10900 (Info-goto-node (car node-line
))
10901 (anything-goto-line (cdr node-line
)))
10903 (defun anything-c-info-display-to-real (line)
10905 ;; This regexp is stolen from Info-apropos-matches
10906 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
10907 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
10908 (string-to-number (or (match-string 3 line
) "1")))))
10910 (defun anything-c-make-info-source (source file
)
10912 (name .
,(concat "Info Index: " file
))
10913 (info-file .
,file
)
10914 (init . anything-c-info-init
)
10915 (display-to-real . anything-c-info-display-to-real
)
10916 (get-line . buffer-substring
)
10917 (candidates-in-buffer)
10918 (action ("Goto node" . anything-c-info-goto
))))
10920 (defun anything-compile-source--info-index (source)
10921 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
10922 (anything-c-make-info-source source it
)
10924 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
10926 (anything-document-attribute 'info-index
"info-index plugin"
10927 "Create a source of info index very easily.
10929 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
10931 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
10932 "Index nodes of info file.
10934 If it is omitted, `Info-index-nodes' is used to collect index nodes.
10935 Some info files are missing index specification.
10937 ex. See `anything-c-source-info-screen'.")
10939 ;; Plug-in: candidates-file
10940 (defun anything-compile-source--candidates-file (source)
10941 (if (assoc-default 'candidates-file source
)
10942 `((init anything-p-candidats-file-init
10943 ,@(let ((orig-init (assoc-default 'init source
)))
10944 (cond ((null orig-init
) nil
)
10945 ((functionp orig-init
) (list orig-init
))
10947 (candidates-in-buffer)
10950 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
10952 (defun anything-p-candidats-file-init ()
10953 (destructuring-bind (file &optional updating
)
10954 (anything-mklist (anything-attr 'candidates-file
))
10955 (setq file
(anything-interpret-value file
))
10956 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
10958 (buffer-disable-undo)
10959 (font-lock-mode -
1)
10960 (auto-revert-mode 1)))))
10962 (anything-document-attribute 'candidates-file
"candidates-file plugin"
10963 "Use a file as the candidates buffer.
10965 1st argument is a filename, string or function name or variable name.
10966 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
10968 ;; Plug-in: headline
10969 (defun anything-compile-source--anything-headline (source)
10970 (if (assoc-default 'headline source
)
10971 (append '((init . anything-headline-init
)
10972 (get-line . buffer-substring
)
10975 '((candidates-in-buffer)
10976 (persistent-help .
"Show this line")))
10978 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
10980 (defun anything-headline-init ()
10981 (when (and (anything-current-buffer-is-modified)
10982 (with-anything-current-buffer
10983 (eval (or (anything-attr 'condition
) t
))))
10984 (anything-headline-make-candidate-buffer
10985 (anything-interpret-value (anything-attr 'headline
))
10986 (anything-interpret-value (anything-attr 'subexp
)))))
10988 (anything-document-attribute 'headline
"Headline plug-in"
10989 "Regexp string for anything-headline to scan.")
10990 (anything-document-attribute 'condition
"Headline plug-in"
10991 "A sexp representing the condition to use anything-headline.")
10992 (anything-document-attribute 'subexp
"Headline plug-in"
10993 "Display (match-string-no-properties subexp).")
10995 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
10998 ;; 1. Create list of ((title . start-of-match) . hiearchy)
10999 ;; 2. Sort this list by start-of-match.
11000 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11002 ;; It's quite brilliantly written.
11006 (defun anything-headline-get-candidates (regexp subexp
)
11007 (with-anything-current-buffer
11009 (goto-char (point-min))
11010 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
11011 (let (hierarchy curhead
)
11013 (if (numberp subexp
)
11014 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
11015 (cons (buffer-substring (point-at-bol) (point-at-eol))
11017 (hierarchies (headlines)
11018 (1+ (loop for
(_ . hierarchy
) in headlines
11019 maximize hierarchy
)))
11021 (loop for i from
0 to hierarchy
11022 collecting
(aref curhead i
)))
11023 (arrange (headlines)
11024 (unless (null headlines
) ; FIX headlines empty bug!
11025 (loop with curhead
= (make-vector (hierarchies headlines
) "")
11026 for
((str . pt
) . hierarchy
) in headlines
11027 do
(aset curhead hierarchy str
)
11030 (format "H%d:%s" (1+ hierarchy
)
11031 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
11036 (loop for re in regexp
11037 for hierarchy from
0
11038 do
(goto-char (point-min))
11041 while
(re-search-forward re nil t
)
11042 collect
(cons (matched) hierarchy
)))
11043 (lambda (a b
) (> (cdar b
) (cdar a
)))))
11044 (loop while
(re-search-forward regexp nil t
)
11045 collect
(matched))))))))
11048 (defun anything-headline-make-candidate-buffer (regexp subexp
)
11049 (with-current-buffer (anything-candidate-buffer 'local
)
11050 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
11053 (with-anything-current-buffer
11054 (line-number-at-pos pos
))
11057 (defun anything-headline-goto-position (pos recenter
)
11060 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
11063 ;; Plug-in: persistent-help
11064 (defun anything-compile-source--persistent-help (source)
11065 (append source
'((header-line . anything-persistent-help-string
))))
11066 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
11068 (defun anything-persistent-help-string ()
11069 (substitute-command-keys
11070 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11071 (or (anything-interpret-value (anything-attr 'persistent-help
))
11072 (anything-aif (or (assoc-default 'persistent-action
11073 (anything-get-current-source))
11074 (assoc-default 'action
11075 (anything-get-current-source)))
11076 (cond ((symbolp it
) (symbol-name it
))
11077 ((listp it
) (or (ignore-errors (caar it
)) ""))))
11079 " (keeping session)")))
11081 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
11082 "A string to explain persistent-action of this source.
11083 It also accepts a function or a variable name.")
11085 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11087 ;; Plug-in: Type customize
11088 (defun anything-c-uniq-list (lst)
11089 "Like `remove-duplicates' in CL.
11090 But cut deeper duplicates and test by `equal'. "
11091 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
11092 (defvar anything-additional-type-attributes nil
)
11093 (defun anything-c-arrange-type-attribute (type spec
)
11094 "Override type attributes by `define-anything-type-attribute'.
11096 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11098 Example: Set `play-sound-file' as default action
11099 (anything-c-arrange-type-attribute 'file
11100 '((action (\"Play sound\" . play-sound-file)
11101 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11104 (add-to-list 'anything-additional-type-attributes
11106 (loop with typeattr
= (assoc-default type anything-type-attributes
)
11107 for
(attr . value
) in spec
11110 (anything-c-uniq-list
11111 (loop for v in value
11113 append
(assoc-default attr typeattr
)
11117 collect
(cons attr value
)))))
11118 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
11120 (defun anything-compile-source--type-customize (source)
11121 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
11124 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
11126 ;; Plug-in: default-action
11127 (defun anything-compile-source--default-action (source)
11128 (anything-aif (assoc-default 'default-action source
)
11129 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
11132 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
11133 (anything-document-attribute 'default-action
"default-action plug-in"
11137 ;;; Toggle anything-match-plugin
11140 (defvar anything-mp-initial-highlight-delay nil
)
11143 (defun anything-c-toggle-match-plugin ()
11144 "Toggle anything-match-plugin."
11146 (let ((anything-match-plugin-enabled
11147 (member 'anything-compile-source--match-plugin
11148 anything-compile-source-functions
)))
11149 (flet ((disable-match-plugin ()
11150 (setq anything-compile-source-functions
11151 (delq 'anything-compile-source--match-plugin
11152 anything-compile-source-functions
))
11153 (setq anything-mp-initial-highlight-delay
11154 anything-mp-highlight-delay
)
11155 (setq anything-mp-highlight-delay nil
))
11156 (enable-match-plugin ()
11157 (require 'anything-match-plugin
)
11158 (unless anything-mp-initial-highlight-delay
11159 (setq anything-mp-initial-highlight-delay
11160 anything-mp-highlight-delay
))
11161 (setq anything-compile-source-functions
11162 (cons 'anything-compile-source--match-plugin
11163 anything-compile-source-functions
))
11164 (unless anything-mp-highlight-delay
11165 (setq anything-mp-highlight-delay
11166 anything-mp-initial-highlight-delay
))))
11167 (if anything-match-plugin-enabled
11168 (when (y-or-n-p "Really disable match-plugin? ")
11169 (disable-match-plugin)
11170 (message "Anything-match-plugin disabled"))
11171 (when (y-or-n-p "Really enable match-plugin? ")
11172 (enable-match-plugin)
11173 (message "Anything-match-plugin enabled"))))))
11177 ;;; Type Attributes
11180 (define-anything-type-attribute 'buffer
11182 ("Switch to buffer" . anything-c-switch-to-buffer
)
11183 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin
:popup-buffer
))
11184 ("Switch to buffer other window" . switch-to-buffer-other-window
)
11185 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)
11186 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
11187 ("Query replace regexp" . anything-c-buffer-query-replace-regexp
)
11188 ("Query replace" . anything-c-buffer-query-replace
)
11189 ("View buffer" . view-buffer
)
11190 ("Display buffer" . display-buffer
)
11191 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers
)
11192 ("Revert buffer(s)" . anything-revert-marked-buffers
)
11193 ("Insert buffer" . insert-buffer
)
11194 ("Kill buffer(s)" . anything-kill-marked-buffers
)
11195 ("Diff with file" . diff-buffer-with-file
)
11196 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
11197 ("Ediff Merge marked buffers" .
(lambda (candidate)
11198 (anything-ediff-marked-buffers candidate t
))))
11199 (persistent-help .
"Show this buffer")
11200 (candidate-transformer anything-c-skip-current-buffer
11201 anything-c-skip-boring-buffers
11202 anything-c-transform-buffer-display-string
))
11203 "Buffer or buffer name.")
11205 (define-anything-type-attribute 'file
11207 ("Find file" . anything-find-many-files
)
11208 ,(and (locate-library "popwin") '("Find file in popup window" . popwin
:find-file
))
11209 ("Find file as root" . anything-find-file-as-root
)
11210 ("Find file other window" . find-file-other-window
)
11211 ("Find file other frame" . find-file-other-frame
)
11212 ("Open dired in file's directory" . anything-c-open-dired
)
11213 ("Grep File(s) `C-u recurse'" . anything-find-files-grep
)
11214 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep
)
11215 ("Pdfgrep File(s)" . anything-ff-pdfgrep
)
11216 ("Checksum File" . anything-ff-checksum
)
11217 ("Ediff File" . anything-find-files-ediff-files
)
11218 ("Ediff Merge File" . anything-find-files-ediff-merge-files
)
11219 ("View file" . view-file
)
11220 ("Insert file" . insert-file
)
11221 ("Delete file(s)" . anything-delete-marked-files
)
11222 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
11223 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
11224 ("Find file in hex dump" . hexl-find-file
))
11225 (persistent-help .
"Show this file")
11226 (action-transformer anything-c-transform-file-load-el
11227 anything-c-transform-file-browse-url
)
11228 (candidate-transformer anything-c-w32-pathname-transformer
11229 anything-c-skip-current-file
11230 anything-c-skip-boring-files
11231 anything-c-shorten-home-path
))
11234 (let ((actions '(("Describe command" . describe-function
)
11235 ("Add command to kill ring" . anything-c-kill-new
)
11236 ("Go to command's definition" . find-function
)
11237 ("Debug on entry" . debug-on-entry
)
11238 ("Cancel debug on entry" . cancel-debug-on-entry
)
11239 ("Trace function" . trace-function
)
11240 ("Trace function (background)" . trace-function-background
)
11241 ("Untrace function" . untrace-function
))))
11242 (define-anything-type-attribute 'command
11243 `((action ("Call interactively" . anything-c-call-interactively
)
11245 ;; Sort commands according to their usage count.
11246 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11247 (coerce . anything-c-symbolify
)
11248 (persistent-action . describe-function
))
11249 "Command. (string or symbol)")
11251 (define-anything-type-attribute 'function
11252 `((action .
,actions
)
11253 (action-transformer anything-c-transform-function-call-interactively
)
11254 (candidate-transformer anything-c-mark-interactive-functions
)
11255 (coerce . anything-c-symbolify
))
11256 "Function. (string or symbol)"))
11258 (define-anything-type-attribute 'variable
11259 '((action ("Describe variable" . describe-variable
)
11260 ("Add variable to kill ring" . anything-c-kill-new
)
11261 ("Go to variable's definition" . find-variable
)
11262 ("Set variable" . anything-c-set-variable
))
11263 (coerce . anything-c-symbolify
))
11266 (define-anything-type-attribute 'sexp
11267 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
11268 ("Add s-expression to kill ring" . kill-new
))
11269 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
11270 "String representing S-Expressions.")
11272 (define-anything-type-attribute 'bookmark
11273 `((coerce . anything-bookmark-get-bookmark-from-name
)
11275 ("Jump to bookmark" .
(lambda (bookmark)
11276 (let ((current-prefix-arg anything-current-prefix-arg
))
11277 (bookmark-jump bookmark
))
11278 (anything-update)))
11279 ("Jump to BM other window" .
(lambda (bookmark)
11280 (bookmark-jump-other-window bookmark
)
11281 (anything-update)))
11282 ("Bookmark edit annotation" . bookmark-edit-annotation
)
11283 ("Bookmark show annotation" . bookmark-show-annotation
)
11284 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
11285 ,@(and (locate-library "bookmark-extensions")
11286 `(("Edit Bookmark" . bmkext-edit-bookmark
)))
11287 ("Rename bookmark" . bookmark-rename
)
11288 ("Relocate bookmark" . bookmark-relocate
)))
11291 (define-anything-type-attribute 'line
11292 '((display-to-real . anything-c-display-to-real-line
)
11293 (action ("Go to Line" . anything-c-action-line-goto
)))
11294 "LINENO:CONTENT string, eg. \" 16:foo\".
11296 Optional `target-file' attribute is a name of target file.
11298 Optional `before-jump-hook' attribute is a function with no
11299 arguments which is called before jumping to position.
11301 Optional `after-jump-hook' attribute is a function with no
11302 arguments which is called after jumping to position.
11304 If `adjust' attribute is specified, searches the line whose
11305 content is CONTENT near the LINENO.
11307 If `recenter' attribute is specified, the line is displayed at
11308 the center of window, otherwise at the top of window.
11311 (define-anything-type-attribute 'file-line
11312 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
11314 (action ("Go to" . anything-c-action-file-line-goto
)))
11315 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11317 Optional `default-directory' attribute is a default-directory
11318 FILENAME is interpreted.
11320 Optional `before-jump-hook' attribute is a function with no
11321 arguments which is called before jumping to position.
11323 Optional `after-jump-hook' attribute is a function with no
11324 arguments which is called after jumping to position.
11326 If `adjust' attribute is specified, searches the line whose
11327 content is CONTENT near the LINENO.
11329 If `recenter' attribute is specified, the line is displayed at
11330 the center of window, otherwise at the top of window.
11333 (define-anything-type-attribute 'timer
11334 '((real-to-display . anything-c-timer-real-to-display
)
11335 (action ("Cancel Timer" . cancel-timer
)
11336 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
11337 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
11338 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
11339 (persistent-help .
"Describe Function"))
11343 ;;; Default `anything-sources'
11344 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11345 ;; tend to invoke M-x anything directly. So I offer default setting.
11346 (setq anything-sources
11347 '(anything-c-source-buffers-list
11348 anything-c-source-recentf
11349 anything-c-source-files-in-current-dir
+))
11352 ;;; Preconfigured Anything
11356 (defun anything-mini ()
11357 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11359 (anything-other-buffer '(anything-c-source-buffers-list
11360 anything-c-source-recentf
11361 anything-c-source-buffer-not-found
)
11362 "*anything mini*"))
11364 (defun anything-for-files ()
11365 "Preconfigured `anything' for opening files.
11366 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11368 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
11371 (defun anything-recentf ()
11372 "Preconfigured `anything' for `recentf'."
11374 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
11377 (defun anything-info-at-point (arg)
11378 "Preconfigured `anything' for searching info at point.
11379 With a prefix-arg insert symbol at point."
11381 (let ((anything-c-google-suggest-default-function
11382 'anything-c-google-suggest-emacs-lisp
))
11383 (anything-1 :sources
'(anything-c-source-info-elisp
11384 anything-c-source-info-cl
11385 anything-c-source-info-pages
11386 anything-c-source-google-suggest
)
11387 :input
(and arg
(thing-at-point 'symbol
))
11388 :buffer
"*anything info*")))
11391 (defun anything-info-emacs ()
11392 "Preconfigured anything for Emacs manual index."
11394 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
11397 (defun anything-show-kill-ring ()
11398 "Preconfigured `anything' for `kill-ring'.
11399 It is drop-in replacement of `yank-pop'.
11400 You may bind this command to M-y.
11401 First call open the kill-ring browser, next calls move to next line."
11403 (let ((buf "*anything kill-ring*"))
11404 (if (get-buffer-window buf
)
11405 (with-anything-window
11406 (if (eq (overlay-end anything-selection-overlay
) (point-max))
11407 (anything-beginning-of-buffer)
11408 (anything-next-line)))
11409 (anything-other-buffer 'anything-c-source-kill-ring buf
))))
11412 (defun anything-minibuffer-history ()
11413 "Preconfigured `anything' for `minibuffer-history'."
11415 (let ((enable-recursive-minibuffers t
))
11416 (anything-other-buffer 'anything-c-source-minibuffer-history
11417 "*anything minibuffer-history*")))
11420 (defun anything-gentoo ()
11421 "Preconfigured `anything' for gentoo linux."
11423 (anything-other-buffer '(anything-c-source-gentoo
11424 anything-c-source-use-flags
)
11425 "*anything gentoo*"))
11428 (defun anything-imenu ()
11429 "Preconfigured `anything' for `imenu'."
11431 (anything-1 :sources
'anything-c-source-imenu
11432 :buffer
"*anything imenu*"))
11435 (defun anything-google-suggest ()
11436 "Preconfigured `anything' for google search with google suggest."
11438 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
11441 (defun anything-yahoo-suggest ()
11442 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11444 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
11446 ;;; Converted from anything-show-*-only
11448 (defun anything-for-buffers ()
11449 "Preconfigured `anything' for buffer."
11451 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
11454 (defun anything-buffers-list ()
11455 "Enhanced preconfigured `anything' for buffer."
11457 (anything-1 :sources
'(anything-c-source-buffers-list
11458 anything-c-source-buffer-not-found
)
11459 :buffer
"*anything buffers*" :keymap anything-c-buffer-map
))
11462 (defun anything-bbdb ()
11463 "Preconfigured `anything' for BBDB.
11467 http://bbdb.sourceforge.net/"
11469 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
11472 (defun anything-locate (arg)
11473 "Preconfigured `anything' for Locate.
11474 Note: you can add locate options after entering pattern.
11475 See 'man locate' for valid options.
11477 You can specify a specific database with prefix argument ARG \(C-u\).
11478 Many databases can be used: navigate and mark them.
11479 See also `anything-locate-with-db'.
11481 To create a user specific db, use
11482 \"updatedb -l 0 -o db_path -U directory\".
11483 Where db_path is a filename matched by
11484 `anything-locate-db-file-regexp'."
11486 (anything-locate-1 arg
))
11489 (defun anything-w3m-bookmarks ()
11490 "Preconfigured `anything' for w3m bookmark.
11492 Needs w3m and emacs-w3m.
11494 http://w3m.sourceforge.net/
11495 http://emacs-w3m.namazu.org/"
11497 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11498 "*anything w3m bookmarks*"))
11501 (defun anything-firefox-bookmarks ()
11502 "Preconfigured `anything' for firefox bookmark.
11503 You will have to enable html bookmarks in firefox:
11504 open about:config in firefox and double click on this line to enable value \
11507 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11509 You should have now:
11511 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11513 After closing firefox, you will be able to browse you bookmarks.
11516 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11517 "*Anything Firefox*"))
11520 (defun anything-colors ()
11521 "Preconfigured `anything' for color."
11523 (anything-other-buffer
11524 '(anything-c-source-colors anything-c-source-customize-face
)
11525 "*anything colors*"))
11528 (defun anything-bookmarks ()
11529 "Preconfigured `anything' for bookmarks."
11531 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
11534 (defun anything-c-pp-bookmarks ()
11535 "Preconfigured `anything' for bookmarks (pretty-printed)."
11537 (anything-other-buffer '(anything-c-source-bookmarks-local
11538 anything-c-source-bookmarks-su
11539 anything-c-source-bookmarks-ssh
)
11540 "*anything pp bookmarks*"))
11543 (defun anything-c-insert-latex-math ()
11544 "Preconfigured anything for latex math symbols completion."
11546 (anything-other-buffer 'anything-c-source-latex-math
"*anything latex*"))
11549 (defun anything-register ()
11550 "Preconfigured `anything' for Emacs registers."
11552 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
11555 (defun anything-man-woman ()
11556 "Preconfigured `anything' for Man and Woman pages."
11558 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
11561 (defun anything-org-keywords ()
11562 "Preconfigured `anything' for org keywords."
11564 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
11567 (defun anything-emms ()
11568 "Preconfigured `anything' for emms sources."
11570 (anything-1 :sources
'(anything-c-source-emms-streams
11571 anything-c-source-emms-files
11572 anything-c-source-emms-dired
)
11573 :buffer
"*Anything Emms*"))
11576 (defun anything-eev-anchors ()
11577 "Preconfigured `anything' for eev anchors."
11579 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
11582 (defun anything-bm-list ()
11583 "Preconfigured `anything' for visible bookmarks.
11587 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11589 (let ((anything-outline-using t
))
11590 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
11593 (defun anything-timers ()
11594 "Preconfigured `anything' for timers."
11596 (anything-other-buffer '(anything-c-source-absolute-time-timers
11597 anything-c-source-idle-time-timers
)
11598 "*anything timers*"))
11601 (defun anything-list-emacs-process ()
11602 "Preconfigured `anything' for emacs process."
11604 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
11607 (defun anything-occur ()
11608 "Preconfigured Anything for Occur source.
11609 If region is active, search only in region,
11610 otherwise search in whole buffer."
11612 (let ((anything-compile-source-functions
11613 ;; rule out anything-match-plugin because the input is one regexp.
11614 (delq 'anything-compile-source--match-plugin
11615 (copy-sequence anything-compile-source-functions
))))
11616 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
11619 (defun anything-browse-code ()
11620 "Preconfigured anything to browse code."
11622 (anything-1 :sources
'anything-c-source-browse-code
11623 :buffer
"*anything browse code*"
11624 :default
(thing-at-point 'symbol
)))
11627 (defun anything-org-headlines ()
11628 "Preconfigured anything to show org headlines."
11630 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
11633 (defun anything-info-gnus ()
11634 "Preconfigured anything to browse Gnus Manual."
11636 (anything-other-buffer 'anything-c-source-info-gnus
"*info Gnus*"))
11639 (defun anything-regexp ()
11640 "Preconfigured anything to build regexps and run query-replace-regexp \
11644 (let ((anything-compile-source-functions
11645 ;; rule out anything-match-plugin because the input is one regexp.
11646 (delq 'anything-compile-source--match-plugin
11647 (copy-sequence anything-compile-source-functions
))))
11648 (when (and (anything-region-active-p)
11649 ;; Don't narrow to region if buffer is already narrowed.
11650 (not (anything-current-buffer-narrowed-p)))
11651 (narrow-to-region (region-beginning) (region-end)))
11652 (anything-1 :sources anything-c-source-regexp
11653 :buffer
"*anything regexp*"
11654 :prompt
"Regexp: "))))
11656 (defun anything-c-copy-files-async ()
11657 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11659 (let* ((flist (anything-c-read-file-name
11660 "Copy File async: "
11661 :marked-candidates t
))
11662 (dest (anything-c-read-file-name
11663 "Copy File async To: "
11664 :preselect
(car flist
)
11665 :initial-input
(car anything-ff-history
)
11666 :history
(anything-find-files-history :comp-read nil
))))
11667 (anything-c-copy-async-with-log flist dest
)))
11670 (defun anything-find-files (arg)
11671 "Preconfigured `anything' for anything implementation of `find-file'.
11672 Called with a prefix arg show history if some.
11673 Don't call it from programs, use `anything-find-files-1' instead.
11674 This is the starting point for nearly all actions you can do on files."
11676 (let ((any-input (if (and arg anything-ff-history
)
11677 (anything-find-files-history)
11678 (anything-find-files-initial-input)))
11679 (presel (buffer-file-name (current-buffer))))
11680 (when (and (eq major-mode
'org-agenda-mode
)
11683 (setq any-input
(expand-file-name org-directory
)))
11684 (set-text-properties 0 (length any-input
) nil any-input
)
11686 (anything-find-files-1 any-input
)
11687 (setq any-input
(expand-file-name (anything-c-current-directory)))
11688 (anything-find-files-1
11689 any-input
(if anything-ff-transformer-show-only-basename
11690 (and presel
(anything-c-basename presel
))
11694 (defun anything-write-file ()
11695 "Preconfigured `anything' providing completion for `write-file'."
11697 (let ((anything-mp-highlight-delay nil
))
11698 (anything-1 :sources
'anything-c-source-write-file
11699 :input
(expand-file-name default-directory
)
11700 :prompt
"Write buffer to file: "
11701 :buffer
"*Anything write file*")))
11704 (defun anything-insert-file ()
11705 "Preconfigured `anything' providing completion for `insert-file'."
11707 (let ((anything-mp-highlight-delay nil
))
11708 (anything-1 :sources
'anything-c-source-insert-file
11709 :input
(expand-file-name default-directory
)
11710 :prompt
"Insert file: "
11711 :buffer
"*Anything insert file*")))
11714 (defun anything-dired-rename-file ()
11715 "Preconfigured `anything' to rename files from dired."
11717 (anything-dired-do-action-on-file :action
'rename
))
11720 (defun anything-dired-copy-file ()
11721 "Preconfigured `anything' to copy files from dired."
11723 (anything-dired-do-action-on-file :action
'copy
))
11726 (defun anything-dired-symlink-file ()
11727 "Preconfigured `anything' to symlink files from dired."
11729 (anything-dired-do-action-on-file :action
'symlink
))
11732 (defun anything-dired-hardlink-file ()
11733 "Preconfigured `anything' to hardlink files from dired."
11735 (anything-dired-do-action-on-file :action
'hardlink
))
11738 (defun anything-do-grep ()
11739 "Preconfigured anything for grep.
11740 Contrarily to Emacs `grep' no default directory is given, but
11741 the full path of candidates in ONLY.
11742 That allow to grep different files not only in `default-directory' but anywhere
11743 by marking them (C-<SPACE>). If one or more directory is selected
11744 grep will search in all files of these directories.
11745 You can use also wildcard in the base name of candidate.
11746 If a prefix arg is given use the -r option of grep.
11747 The prefix arg can be passed before or after start.
11748 See also `anything-do-grep-1'."
11750 (let ((only (anything-c-read-file-name
11751 "Search in file(s): "
11752 :marked-candidates t
11753 :preselect
(or (dired-get-filename nil t
)
11754 (buffer-file-name (current-buffer)))))
11755 (prefarg (or current-prefix-arg anything-current-prefix-arg
)))
11756 (anything-do-grep-1 only prefarg
)))
11759 (defun anything-do-zgrep (candidate)
11760 "Preconfigured anything for zgrep."
11761 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
11762 (ls (anything-c-read-file-name
11763 "Search in file(s): "
11764 :marked-candidates t
11765 :preselect
(or (dired-get-filename nil t
)
11766 (buffer-file-name (current-buffer))))))
11767 (anything-ff-zgrep-1 ls prefarg
)))
11769 (defun anything-c-etags-select (arg)
11770 "Preconfigured anything for etags.
11771 Called with one prefix arg use symbol at point as initial input.
11772 Called with two prefix arg reinitialize cache.
11773 If tag file have been modified reinitialize cache."
11775 (let ((tag (anything-c-etags-get-tag-file))
11776 (init (and (equal arg
'(4)) (thing-at-point 'symbol
)))
11777 (anything-quit-if-no-candidate t
)
11778 (anything-execute-action-at-once-if-one t
)
11779 (anything-compile-source-functions
11780 (if anything-c-etags-use-regexp-search
11781 ;; rule out anything-match-plugin because the input is one regexp.
11782 (delq 'anything-compile-source--match-plugin
11783 (copy-sequence anything-compile-source-functions
))
11784 anything-compile-source-functions
)))
11785 (when (or (equal arg
'(16))
11786 (and anything-c-etags-mtime-alist
11787 (anything-c-etags-file-modified-p tag
)))
11788 (remhash tag anything-c-etags-cache
))
11789 (if (and tag
(file-exists-p tag
))
11790 (anything-1 :sources
'anything-c-source-etags-select
11791 :keymap anything-c-etags-map
11793 :buffer
"*anything etags*")
11794 (message "Error: No tag file found, please create one with etags shell command."))))
11797 (defun anything-filelist ()
11798 "Preconfigured `anything' to open files instantly.
11800 See `anything-c-filelist-file-name' docstring for usage."
11802 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
11805 (defun anything-filelist+ ()
11806 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
11808 This is a replacement for `anything-for-files'.
11809 See `anything-c-filelist-file-name' docstring for usage."
11811 (anything-other-buffer
11812 '(anything-c-source-ffap-line
11813 anything-c-source-ffap-guesser
11814 anything-c-source-buffers-list
11815 anything-c-source-recentf
11816 anything-c-source-bookmarks
11817 anything-c-source-file-cache
11818 anything-c-source-filelist
)
11819 "*anything file list*"))
11822 (defun anything-M-x ()
11823 "Preconfigured `anything' for Emacs commands.
11824 It is `anything' replacement of regular `M-x' `execute-extended-command'."
11828 special-display-buffer-names
11829 special-display-regexps
11830 anything-persistent-action-use-special-display
11831 (history (loop with hist
11832 for i in extended-command-history
11833 for com
= (intern i
)
11835 collect i into hist finally return hist
)))
11836 (flet ((pers-help (candidate)
11837 (let ((hbuf (get-buffer (help-buffer))))
11838 (if (and in-help
(string= candidate help-cand
))
11840 ;; When M-x is started from a help buffer,
11841 ;; Don't kill it as it is anything-current-buffer.
11842 (unless (equal hbuf anything-current-buffer
)
11843 (kill-buffer hbuf
))
11844 (setq in-help nil
))
11845 ;; Be sure anything-current-buffer
11846 ;; have not a dedicated window.
11847 (set-window-dedicated-p
11848 (get-buffer-window anything-current-buffer
) nil
)
11849 (describe-function (intern candidate
))
11850 (message nil
) ; Erase the new stupid message Type "q"[...]
11852 (setq help-cand candidate
))))
11857 `(((name .
"Emacs Commands history")
11858 (candidates .
,history
)
11859 (filtered-candidate-transformer
11860 .
(lambda (candidates sources
)
11861 (loop for i in candidates
11862 do
(set-text-properties 0 (length i
) nil i
)
11864 (persistent-action . pers-help
)
11865 (persistent-help .
"Describe this command")
11866 (action . identity
))
11867 ((name .
"Emacs Commands")
11870 (with-current-buffer (anything-candidate-buffer 'global
)
11871 (goto-char (point-min))
11873 for sym in
(all-completions "" obarray
'commandp
)
11874 do
(insert (concat sym
"\n"))))))
11875 (persistent-action . pers-help
)
11876 (persistent-help .
"Describe this command")
11877 (filtered-candidate-transformer . anything-M-x-transformer
)
11878 (candidates-in-buffer)
11879 (action . identity
)))
11881 :buffer
"*anything M-x*")
11883 (sym-com (intern command
)))
11884 (unless current-prefix-arg
11885 (setq current-prefix-arg anything-current-prefix-arg
))
11886 ;; Avoid having `this-command' set to *exit-minibuffer.
11887 (setq this-command sym-com
)
11888 (call-interactively sym-com
)
11889 (setq extended-command-history
11890 (cons command
(delete command history
)))))))
11893 (defun anything-manage-advice ()
11894 "Preconfigured `anything' to disable/enable function advices."
11896 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
11899 (defun anything-bookmark-ext ()
11900 "Preconfigured `anything' for bookmark-extensions sources.
11901 Needs bookmark-ext.el:
11902 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
11903 Contain also `anything-c-source-google-suggest'."
11907 '(anything-c-source-bookmark-files&dirs
11908 anything-c-source-bookmark-w3m
11909 anything-c-source-google-suggest
11910 anything-c-source-bmkext-addressbook
11911 anything-c-source-bookmark-gnus
11912 anything-c-source-bookmark-info
11913 anything-c-source-bookmark-man
11914 anything-c-source-bookmark-images
11915 anything-c-source-bookmark-su-files
&dirs
11916 anything-c-source-bookmark-ssh-files
&dirs
)
11917 :prompt
"SearchBookmark: "
11918 :buffer
"*anything bmkext*"))
11921 (defun anything-simple-call-tree ()
11922 "Preconfigured `anything' for simple-call-tree. List function relationships.
11924 Needs simple-call-tree.el.
11925 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
11927 (anything-other-buffer
11928 '(anything-c-source-simple-call-tree-functions-callers
11929 anything-c-source-simple-call-tree-callers-functions
)
11930 "*anything simple-call-tree*"))
11933 (defun anything-mark-ring ()
11934 "Preconfigured `anything' for `anything-c-source-mark-ring'."
11936 (anything-1 :sources
'anything-c-source-mark-ring
))
11939 (defun anything-global-mark-ring ()
11940 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
11942 (anything-1 :sources
'anything-c-source-global-mark-ring
))
11945 (defun anything-all-mark-rings ()
11946 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
11947 `anything-c-source-mark-ring'."
11949 (anything-1 :sources
'(anything-c-source-mark-ring
11950 anything-c-source-global-mark-ring
)))
11953 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
11954 "Preconfigured `anything' to edit or view EmacsWiki page.
11956 Needs yaoddmuse.el.
11958 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11960 (anything-1 :sources
'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
11963 (defun anything-yaoddmuse-emacswiki-post-library ()
11964 "Preconfigured `anything' to post library to EmacsWiki.
11966 Needs yaoddmuse.el.
11968 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
11970 (anything-1 :sources
'anything-c-source-yaoddmuse-emacswiki-post-library
))
11973 (defun anything-eval-expression (arg)
11974 "Preconfigured anything for `anything-c-source-evaluation-result'."
11976 (anything-1 :sources
'anything-c-source-evaluation-result
11977 :input
(when arg
(thing-at-point 'sexp
))
11978 :buffer
"*anything eval*"
11979 :keymap anything-eval-expression-map
))
11982 (defun anything-eval-expression-with-eldoc ()
11983 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
11985 (declare (special eldoc-idle-delay
))
11986 (let ((timer (run-with-idle-timer eldoc-idle-delay
11987 'repeat
'anything-eldoc-show-in-eval
))
11988 (minibuffer-completing-symbol t
) ; Enable lisp completion.
11989 (completion-cycle-threshold t
)) ; Always cycle, no pesty completion buffer (emacs24 only).
11991 (minibuffer-with-setup-hook
11992 'anything-eldoc-store-minibuffer
11993 (call-interactively 'anything-eval-expression
))
11994 (and timer
(cancel-timer timer
))
11995 (setq anything-eldoc-active-minibuffers-list
11996 (cdr anything-eldoc-active-minibuffers-list
)))))
11999 (defun anything-calcul-expression ()
12000 "Preconfigured anything for `anything-c-source-calculation-result'."
12002 (anything-other-buffer 'anything-c-source-calculation-result
"*anything calcul*"))
12005 (defun anything-surfraw (pattern engine
)
12006 "Preconfigured `anything' to search PATTERN with search ENGINE."
12007 (interactive (list (read-string "SearchFor: ")
12008 (anything-comp-read
12010 (anything-c-build-elvi-list)
12012 :name
"Surfraw Search Engines"
12013 :history anything-surfraw-engines-history
)))
12014 (let* ((engine-nodesc (car (split-string engine
)))
12015 (url (with-temp-buffer
12016 (apply 'call-process
"surfraw" nil t nil
12018 (append (list engine-nodesc
"-p") (split-string pattern
)))
12019 (replace-regexp-in-string
12020 "\n" "" (buffer-string))))
12021 (browse-url-browser-function (or anything-surfraw-default-browser-function
12022 browse-url-browser-function
)))
12023 (if (string= engine-nodesc
"W")
12024 (anything-c-browse-url)
12025 (anything-c-browse-url url
)
12026 (setq anything-surfraw-engines-history
12027 (cons engine
(delete engine anything-surfraw-engines-history
))))))
12030 (defun anything-call-source ()
12031 "Preconfigured `anything' to call anything source."
12033 (anything-1 :sources
'anything-c-source-call-source
12034 :buffer anything-source-select-buffer
))
12037 (defun anything-execute-anything-command ()
12038 "Preconfigured `anything' to execute preconfigured `anything'."
12040 (anything-other-buffer 'anything-c-source-anything-commands
12041 "*anything commands*"))
12044 (defun anything-create (&optional string initial-input
)
12045 "Preconfigured `anything' to do many create actions from STRING.
12046 See also `anything-create--actions'."
12048 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
12049 (anything-1 :sources
'(((name .
"Anything Create")
12050 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
12051 (candidates . anything-create--actions
)
12052 (candidate-number-limit)
12053 (action .
(lambda (func) (funcall func string
)))))))
12056 (defun anything-top ()
12057 "Preconfigured `anything' for top command."
12059 (let ((anything-samewindow t
)
12060 (anything-enable-shortcuts)
12061 (anything-display-function 'anything-default-display-buffer
)
12062 (anything-candidate-number-limit 9999))
12063 (save-window-excursion
12064 (delete-other-windows)
12065 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
12068 (defun anything-select-xfont ()
12069 "Preconfigured `anything' to select Xfont."
12071 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
12074 (defun anything-world-time ()
12075 "Preconfigured `anything' to show world time."
12077 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
12080 (defun anything-apt (arg query
)
12081 "Preconfigured `anything' : frontend of APT package manager.
12082 With a prefix arg reload cache."
12083 (interactive "P\nsSearch Package: ")
12085 (setq anything-c-apt-installed-packages nil
)
12086 (setq anything-c-apt-all-packages nil
))
12087 (anything-1 :sources
'anything-c-source-apt
12088 :prompt
"Search Package: " :input query
))
12091 (defun anything-esh-pcomplete ()
12092 "Preconfigured anything to provide anything completion in eshell."
12094 (let* ((anything-quit-if-no-candidate t
)
12095 (anything-execute-action-at-once-if-one t
)
12096 (target (thing-at-point 'symbol
))
12098 (beg (or (and target
(- end
(length target
)))
12099 ;; Nothing at point.
12100 (progn (insert " ") (point)))))
12101 (setq anything-ec-target
(or target
" "))
12102 (with-anything-show-completion beg end
12103 (anything-1 :sources
'anything-c-source-esh
12104 :input
(anything-ff-set-pattern ; Handle tramp filenames.
12105 (car (last (ignore-errors ; Needed in lisp symbols completion.
12106 (pcomplete-parse-arguments)))))))))
12109 (defun anything-eshell-history ()
12110 "Preconfigured anything for eshell history."
12112 (let* ((end (point))
12113 (beg (save-excursion (eshell-bol) (point)))
12117 (setq flag-empty t
)
12118 (setq end
(point)))
12120 (with-anything-show-completion beg end
12121 (anything-1 :sources
'anything-c-source-eshell-history
12122 :buffer
"*Eshell history*"))
12123 (when (and flag-empty
12124 (looking-back " "))
12125 (delete-char -
1)))))
12128 (defun anything-c-run-external-command (program)
12129 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12130 If program is already running exit with error.
12131 You can set your own list of commands with
12132 `anything-c-external-commands-list'."
12134 (anything-comp-read
12136 (anything-c-external-commands-list-1 'sort
)
12138 :name
"External Commands"
12139 :history anything-external-command-history
)))
12140 (anything-run-or-raise program
)
12141 (setq anything-external-command-history
12142 (cons program
(delete program
12143 (loop for i in anything-external-command-history
12144 when
(executable-find i
) collect i
)))))
12147 (defun anything-ratpoison-commands ()
12148 "Preconfigured `anything' to execute ratpoison commands."
12150 (anything-other-buffer 'anything-c-source-ratpoison-commands
12151 "*anything ratpoison commands*"))
12154 (defun anything-ucs ()
12155 "Preconfigured anything for `ucs-names' math symbols."
12157 (anything-1 :sources
'anything-c-source-ucs
12158 :keymap anything-c-ucs-map
))
12161 (defun anything-c-apropos ()
12162 "Preconfigured anything to describe commands, functions, variables and faces."
12164 (let ((default (thing-at-point 'symbol
)))
12165 (anything-1 :sources
12166 `(((name .
"Commands")
12168 (anything-c-apropos-init 'commandp
,default
)))
12169 (persistent-action . anything-lisp-completion-persistent-action
)
12170 (persistent-help .
"Show brief doc in mode-line")
12171 (candidates-in-buffer)
12172 (action .
(lambda (candidate)
12173 (describe-function (intern candidate
)))))
12174 ((name .
"Functions")
12176 (anything-c-apropos-init #'(lambda (x) (and (fboundp x
)
12177 (not (commandp x
))))
12179 (persistent-action . anything-lisp-completion-persistent-action
)
12180 (persistent-help .
"Show brief doc in mode-line")
12181 (candidates-in-buffer)
12182 (action .
(lambda (candidate)
12183 (describe-function (intern candidate
)))))
12184 ((name .
"Variables")
12186 (anything-c-apropos-init 'boundp
,default
)))
12187 (persistent-action . anything-lisp-completion-persistent-action
)
12188 (persistent-help .
"Show brief doc in mode-line")
12189 (candidates-in-buffer)
12190 (action .
(lambda (candidate)
12191 (describe-variable (intern candidate
)))))
12194 (anything-c-apropos-init 'facep
,default
)))
12195 (persistent-action . anything-lisp-completion-persistent-action
)
12196 (persistent-help .
"Show brief doc in mode-line")
12197 (candidates-in-buffer)
12198 (filtered-candidate-transformer .
(lambda (candidates source
)
12199 (loop for c in candidates
12200 collect
(propertize c
'face
(intern c
)))))
12201 (action .
(lambda (candidate)
12202 (describe-face (intern candidate
)))))
12203 ((name .
"Anything attributes")
12204 (candidates .
(lambda ()
12205 (mapcar 'symbol-name anything-additional-attributes
)))
12206 (action .
(lambda (candidate)
12207 (with-output-to-temp-buffer "*Help*"
12208 (princ (get (intern candidate
) 'anything-attrdoc
))))))))))
12211 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12214 (provide 'anything-config
)
12216 ;;; Local Variables:
12217 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12220 ;; How to save (DO NOT REMOVE!!)
12221 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12222 ;;; anything-config.el ends here
12224 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12225 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12226 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12227 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12228 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12229 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12230 ;;; LocalWords: dotimes Thierry online vname
12231 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12232 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12233 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12234 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12235 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12236 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12237 ;;; LocalWords: startpos noselect dont desc