1 ;;; anything-config.el --- Applications libary for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Applications libary for `anything.el'
7 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
9 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
10 ;; rubikitch <rubikitch@ruby-lang.org>
11 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
12 ;; Copyright (C) 2007 ~ 2011, Tassilo Horn, all rights reserved.
13 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
14 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
15 ;; Copyright (C) 2009 ~ 2011, Thierry Volpiatto, all rights reserved.
17 ;; Created: 2009-02-16 21:38:23
19 ;; X-URL: http://repo.or.cz/w/anything-config.git
21 ;; MailingList: https://groups.google.com/group/emacs-anything?hl=en
23 ;; Keywords: anything, anything-config
25 ;; Compatibility: GNU Emacs 22 ~ 24
27 ;; Dependencies: `anything.el'
29 ;;; This file is NOT part of GNU Emacs
33 ;; This program is free software; you can redistribute it and/or modify
34 ;; it under the terms of the GNU General Public License as published by
35 ;; the Free Software Foundation; either version 3, or (at your option)
38 ;; This program is distributed in the hope that it will be useful,
39 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
40 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 ;; GNU General Public License for more details.
43 ;; You should have received a copy of the GNU General Public License
44 ;; along with this program; see the file COPYING. If not, write to
45 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
46 ;; Floor, Boston, MA 02110-1301, USA.
50 ;; If this file does not work, upgrade anything.el!
51 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
55 ;; Predefined configurations for `anything.el'
57 ;; For quick start, try `anything-for-files' to open files.
59 ;; To configure anything you should define anything command
60 ;; with your favorite sources, like below:
62 ;; (defun my-anything ()
64 ;; (anything-other-buffer
65 ;; '(anything-c-source-buffers
66 ;; anything-c-source-file-name-history
67 ;; anything-c-source-info-pages
68 ;; anything-c-source-info-elisp
69 ;; anything-c-source-man-pages
70 ;; anything-c-source-locate
71 ;; anything-c-source-emacs-commands)
74 ;; Then type M-x my-anything to use sources.
76 ;; Defining own command is better than setup `anything-sources'
77 ;; directly, because you can define multiple anything commands with
78 ;; different sources. Each anything command should have own anything
79 ;; buffer, because M-x anything-resume revives anything command.
82 ;;; Autodoc documentation:
83 ;; ---------------------
85 ;; * Commands defined here are:
86 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
87 ;; `anything-configuration'
88 ;; Customize `anything'.
89 ;; `anything-c-buffer-help'
90 ;; Help command for anything buffers.
92 ;; Help command for `anything-find-files'.
93 ;; `anything-read-file-name-help'
95 ;; `anything-generic-file-help'
97 ;; `anything-grep-help'
99 ;; `anything-pdfgrep-help'
101 ;; `anything-etags-help'
102 ;; The help function for etags.
103 ;; `anything-c-ucs-help'
104 ;; Help command for `anything-ucs'.
105 ;; `anything-show-this-source-only'
106 ;; Show all candidates of this source.
107 ;; `anything-test-sources'
108 ;; List all anything sources for test.
109 ;; `anything-select-source'
110 ;; [OBSOLETE] Select source.
111 ;; `anything-quit-and-find-file'
112 ;; Drop into `anything-find-files' from `anything'.
113 ;; `anything-mark-all'
114 ;; Mark all visible unmarked candidates in current source.
115 ;; `anything-unmark-all'
116 ;; Unmark all candidates in all sources of current anything session.
117 ;; `anything-toggle-all-marks'
119 ;; `anything-buffer-diff-persistent'
120 ;; Toggle diff buffer without quitting anything.
121 ;; `anything-buffer-revert-persistent'
122 ;; Revert buffer without quitting anything.
123 ;; `anything-buffer-save-persistent'
124 ;; Save buffer without quitting anything.
125 ;; `anything-buffer-run-kill-buffers'
126 ;; Run kill buffer action from `anything-c-source-buffers-list'.
127 ;; `anything-buffer-run-grep'
128 ;; Run Grep action from `anything-c-source-buffers-list'.
129 ;; `anything-buffer-run-zgrep'
130 ;; Run Grep action from `anything-c-source-buffers-list'.
131 ;; `anything-buffer-run-query-replace-regexp'
132 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
133 ;; `anything-buffer-run-query-replace'
134 ;; Run Query replace action from `anything-c-source-buffers-list'.
135 ;; `anything-buffer-switch-other-window'
136 ;; Run switch to other window action from `anything-c-source-buffers-list'.
137 ;; `anything-buffer-switch-other-frame'
138 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
139 ;; `anything-buffer-switch-to-elscreen'
140 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
141 ;; `anything-buffer-run-ediff'
142 ;; Run ediff action from `anything-c-source-buffers-list'.
143 ;; `anything-buffer-run-ediff-merge'
144 ;; Run ediff action from `anything-c-source-buffers-list'.
145 ;; `anything-ff-run-toggle-auto-update'
147 ;; `anything-ff-run-switch-to-history'
148 ;; Run Switch to history action from `anything-c-source-find-files'.
149 ;; `anything-ff-run-grep'
150 ;; Run Grep action from `anything-c-source-find-files'.
151 ;; `anything-ff-run-pdfgrep'
152 ;; Run Pdfgrep action from `anything-c-source-find-files'.
153 ;; `anything-ff-run-zgrep'
154 ;; Run Grep action from `anything-c-source-find-files'.
155 ;; `anything-ff-run-copy-file'
156 ;; Run Copy file action from `anything-c-source-find-files'.
157 ;; `anything-ff-run-rename-file'
158 ;; Run Rename file action from `anything-c-source-find-files'.
159 ;; `anything-ff-run-byte-compile-file'
160 ;; Run Byte compile file action from `anything-c-source-find-files'.
161 ;; `anything-ff-run-load-file'
162 ;; Run Load file action from `anything-c-source-find-files'.
163 ;; `anything-ff-run-eshell-command-on-file'
164 ;; Run eshell command on file action from `anything-c-source-find-files'.
165 ;; `anything-ff-run-ediff-file'
166 ;; Run Ediff file action from `anything-c-source-find-files'.
167 ;; `anything-ff-run-ediff-merge-file'
168 ;; Run Ediff merge file action from `anything-c-source-find-files'.
169 ;; `anything-ff-run-symlink-file'
170 ;; Run Symlink file action from `anything-c-source-find-files'.
171 ;; `anything-ff-run-delete-file'
172 ;; Run Delete file action from `anything-c-source-find-files'.
173 ;; `anything-ff-run-complete-fn-at-point'
174 ;; Run complete file name action from `anything-c-source-find-files'.
175 ;; `anything-ff-run-switch-to-eshell'
176 ;; Run switch to eshell action from `anything-c-source-find-files'.
177 ;; `anything-ff-run-switch-other-window'
178 ;; Run switch to other window action from `anything-c-source-find-files'.
179 ;; `anything-ff-run-switch-other-frame'
180 ;; Run switch to other frame action from `anything-c-source-find-files'.
181 ;; `anything-ff-run-open-file-externally'
182 ;; Run open file externally command action from `anything-c-source-find-files'.
183 ;; `anything-ff-run-locate'
184 ;; Run locate action from `anything-c-source-find-files'.
185 ;; `anything-ff-run-gnus-attach-files'
186 ;; Run gnus attach files command action from `anything-c-source-find-files'.
187 ;; `anything-ff-run-etags'
188 ;; Run Etags command action from `anything-c-source-find-files'.
189 ;; `anything-ff-run-print-file'
190 ;; Run Print file action from `anything-c-source-find-files'.
191 ;; `anything-ff-run-toggle-basename'
193 ;; `anything-find-files-down-one-level'
194 ;; Go down one level like unix command `cd ..'.
195 ;; `anything-ff-properties-persistent'
196 ;; Show properties without quitting anything.
197 ;; `anything-ff-run-kill-buffer-persistent'
198 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
199 ;; `anything-ff-rotate-left-persistent'
200 ;; Rotate image left without quitting anything.
201 ;; `anything-ff-rotate-right-persistent'
202 ;; Rotate image right without quitting anything.
203 ;; `anything-c-goto-precedent-file'
204 ;; Go to precedent file in anything grep/etags buffers.
205 ;; `anything-c-goto-next-file'
206 ;; Go to precedent file in anything grep/etags buffers.
207 ;; `anything-c-grep-run-persistent-action'
208 ;; Run grep persistent action from `anything-do-grep-1'.
209 ;; `anything-c-grep-run-default-action'
210 ;; Run grep default action from `anything-do-grep-1'.
211 ;; `anything-c-grep-run-other-window-action'
212 ;; Run grep goto other window action from `anything-do-grep-1'.
213 ;; `anything-c-grep-run-save-buffer'
214 ;; Run grep save results action from `anything-do-grep-1'.
215 ;; `anything-do-pdfgrep'
217 ;; `anything-yank-text-at-point'
218 ;; Yank text at point in minibuffer.
219 ;; `anything-c-describe-attributes'
220 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
221 ;; `anything-yaoddmuse-cache-pages'
222 ;; Fetch the list of files on emacswiki and create cache file.
223 ;; `anything-eval-new-line-and-indent'
225 ;; `anything-call-source-from-anything'
226 ;; Call anything source within `anything' session.
227 ;; `anything-create-from-anything'
228 ;; Run `anything-create' from `anything' as a fallback.
229 ;; `anything-c-ucs-persistent-insert'
231 ;; `anything-c-ucs-persistent-forward'
233 ;; `anything-c-ucs-persistent-backward'
235 ;; `anything-c-ucs-persistent-delete'
237 ;; `anything-lisp-completion-at-point'
238 ;; Anything lisp symbol completion at point.
239 ;; `anything-c-complete-file-name-at-point'
240 ;; Complete file name at point.
241 ;; `anything-lisp-completion-at-point-or-indent'
242 ;; First call indent and second call complete lisp symbol.
243 ;; `anything-lisp-completion-or-file-name-at-point'
244 ;; Complete lisp symbol or filename at point.
245 ;; `anything-c-set-variable'
246 ;; Set value to VAR interactively.
247 ;; `anything-c-adaptive-save-history'
248 ;; Save history information to file given by `anything-c-adaptive-history-file'.
249 ;; `anything-c-reset-adaptative-history'
250 ;; Delete all `anything-c-adaptive-history' and his file.
251 ;; `anything-c-toggle-match-plugin'
252 ;; Toggle anything-match-plugin.
254 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
255 ;; `anything-for-files'
256 ;; Preconfigured `anything' for opening files.
257 ;; `anything-recentf'
258 ;; Preconfigured `anything' for `recentf'.
259 ;; `anything-info-at-point'
260 ;; Preconfigured `anything' for searching info at point.
261 ;; `anything-info-emacs'
262 ;; Preconfigured anything for Emacs manual index.
263 ;; `anything-show-kill-ring'
264 ;; Preconfigured `anything' for `kill-ring'.
265 ;; `anything-minibuffer-history'
266 ;; Preconfigured `anything' for `minibuffer-history'.
268 ;; Preconfigured `anything' for gentoo linux.
270 ;; Preconfigured `anything' for `imenu'.
271 ;; `anything-google-suggest'
272 ;; Preconfigured `anything' for google search with google suggest.
273 ;; `anything-yahoo-suggest'
274 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
275 ;; `anything-for-buffers'
276 ;; Preconfigured `anything' for buffer.
277 ;; `anything-buffers-list'
278 ;; Enhanced preconfigured `anything' for buffer.
280 ;; Preconfigured `anything' for BBDB.
282 ;; Preconfigured `anything' for Locate.
283 ;; `anything-w3m-bookmarks'
284 ;; Preconfigured `anything' for w3m bookmark.
285 ;; `anything-firefox-bookmarks'
286 ;; Preconfigured `anything' for firefox bookmark.
288 ;; Preconfigured `anything' for color.
289 ;; `anything-bookmarks'
290 ;; Preconfigured `anything' for bookmarks.
291 ;; `anything-c-pp-bookmarks'
292 ;; Preconfigured `anything' for bookmarks (pretty-printed).
293 ;; `anything-c-insert-latex-math'
294 ;; Preconfigured anything for latex math symbols completion.
295 ;; `anything-register'
296 ;; Preconfigured `anything' for Emacs registers.
297 ;; `anything-man-woman'
298 ;; Preconfigured `anything' for Man and Woman pages.
299 ;; `anything-org-keywords'
300 ;; Preconfigured `anything' for org keywords.
302 ;; Preconfigured `anything' for emms sources.
303 ;; `anything-eev-anchors'
304 ;; Preconfigured `anything' for eev anchors.
305 ;; `anything-bm-list'
306 ;; Preconfigured `anything' for visible bookmarks.
308 ;; Preconfigured `anything' for timers.
309 ;; `anything-list-emacs-process'
310 ;; Preconfigured `anything' for emacs process.
312 ;; Preconfigured Anything for Occur source.
313 ;; `anything-browse-code'
314 ;; Preconfigured anything to browse code.
315 ;; `anything-org-headlines'
316 ;; Preconfigured anything to show org headlines.
317 ;; `anything-info-gnus'
318 ;; Preconfigured anything to browse Gnus Manual.
320 ;; Preconfigured anything to build regexps.
321 ;; `anything-c-copy-files-async'
322 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
323 ;; `anything-find-files'
324 ;; Preconfigured `anything' for anything implementation of `find-file'.
325 ;; `anything-write-file'
326 ;; Preconfigured `anything' providing completion for `write-file'.
327 ;; `anything-insert-file'
328 ;; Preconfigured `anything' providing completion for `insert-file'.
329 ;; `anything-dired-rename-file'
330 ;; Preconfigured `anything' to rename files from dired.
331 ;; `anything-dired-copy-file'
332 ;; Preconfigured `anything' to copy files from dired.
333 ;; `anything-dired-symlink-file'
334 ;; Preconfigured `anything' to symlink files from dired.
335 ;; `anything-dired-hardlink-file'
336 ;; Preconfigured `anything' to hardlink files from dired.
337 ;; `anything-do-grep'
338 ;; Preconfigured anything for grep.
339 ;; `anything-c-etags-select'
340 ;; Preconfigured anything for etags.
341 ;; `anything-filelist'
342 ;; Preconfigured `anything' to open files instantly.
343 ;; `anything-filelist+'
344 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
346 ;; Preconfigured `anything' for Emacs commands.
347 ;; `anything-manage-advice'
348 ;; Preconfigured `anything' to disable/enable function advices.
349 ;; `anything-bookmark-ext'
350 ;; Preconfigured `anything' for bookmark-extensions sources.
351 ;; `anything-simple-call-tree'
352 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
353 ;; `anything-mark-ring'
354 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
355 ;; `anything-global-mark-ring'
356 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
357 ;; `anything-all-mark-rings'
358 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
359 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
360 ;; Preconfigured `anything' to edit or view EmacsWiki page.
361 ;; `anything-yaoddmuse-emacswiki-post-library'
362 ;; Preconfigured `anything' to post library to EmacsWiki.
363 ;; `anything-eval-expression'
364 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
365 ;; `anything-eval-expression-with-eldoc'
366 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
367 ;; `anything-calcul-expression'
368 ;; Preconfigured anything for `anything-c-source-calculation-result'.
369 ;; `anything-surfraw'
370 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
371 ;; `anything-call-source'
372 ;; Preconfigured `anything' to call anything source.
373 ;; `anything-execute-anything-command'
374 ;; Preconfigured `anything' to execute preconfigured `anything'.
376 ;; Preconfigured `anything' to do many create actions from STRING.
378 ;; Preconfigured `anything' for top command.
379 ;; `anything-select-xfont'
380 ;; Preconfigured `anything' to select Xfont.
381 ;; `anything-world-time'
382 ;; Preconfigured `anything' to show world time.
384 ;; Preconfigured `anything' : frontend of APT package manager.
385 ;; `anything-esh-pcomplete'
386 ;; Preconfigured anything to provide anything completion in eshell.
387 ;; `anything-eshell-history'
388 ;; Preconfigured anything for eshell history.
389 ;; `anything-c-run-external-command'
390 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
391 ;; `anything-ratpoison-commands'
392 ;; Preconfigured `anything' to execute ratpoison commands.
394 ;; Preconfigured anything for `ucs-names' math symbols.
395 ;; `anything-c-apropos'
396 ;; Preconfigured anything to describe commands, functions, variables and faces.
398 ;; * User variables defined here:
399 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
400 ;; `anything-c-adaptive-history-file'
401 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
402 ;; `anything-c-adaptive-history-length'
404 ;; `anything-c-google-suggest-url'
405 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
406 ;; `anything-c-google-suggest-search-url'
407 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
408 ;; `anything-google-suggest-use-curl-p'
409 ;; Default Value: nil
410 ;; `anything-c-yahoo-suggest-url'
411 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
412 ;; `anything-c-yahoo-suggest-search-url'
413 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
414 ;; `anything-c-boring-buffer-regexp'
415 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\|\\*ac-mode\\| \\*Echo Area\\| \\*Minibuf"
416 ;; `anything-c-boring-file-regexp'
417 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
418 ;; `anything-kill-ring-threshold'
420 ;; `anything-c-kill-ring-max-lines-number'
421 ;; Default Value: nil
422 ;; `anything-su-or-sudo'
423 ;; Default Value: "su"
424 ;; `anything-for-files-prefered-list'
425 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
426 ;; `anything-create--actions-private'
427 ;; Default Value: nil
428 ;; `anything-allow-skipping-current-buffer'
430 ;; `anything-c-enable-eval-defun-hack'
432 ;; `anything-tramp-verbose'
434 ;; `anything-raise-command'
435 ;; Default Value: nil
436 ;; `anything-command-map-prefix-key'
437 ;; Default Value: "<f5> a"
438 ;; `anything-c-browse-code-regexp-lisp'
439 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
440 ;; `anything-c-browse-code-regexp-python'
441 ;; Default Value: "\\<def\\>\\|\\<class\\>"
442 ;; `anything-c-browse-code-regexp-alist'
443 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
444 ;; `anything-c-external-programs-associations'
445 ;; Default Value: nil
446 ;; `anything-ff-auto-update-initial-value'
448 ;; `anything-c-copy-async-prefered-emacs'
449 ;; Default Value: "emacs"
450 ;; `anything-ff-lynx-style-map'
452 ;; `anything-ff-history-max-length'
453 ;; Default Value: 100
454 ;; `anything-ff-smart-completion'
456 ;; `anything-ff-default-kbsize'
457 ;; Default Value: 1024.0
458 ;; `anything-ff-tramp-not-fancy'
460 ;; `anything-ff-exif-data-program'
461 ;; Default Value: "exiftran"
462 ;; `anything-ff-exif-data-program-args'
463 ;; Default Value: "-d"
464 ;; `anything-c-grep-use-ioccur-style-keys'
466 ;; `anything-c-pdfgrep-default-read-command'
467 ;; Default Value: "xpdf '%f' %p"
468 ;; `anything-c-etags-tag-file-name'
469 ;; Default Value: "TAGS"
470 ;; `anything-c-etags-tag-file-search-limit'
472 ;; `anything-c-etags-use-regexp-search'
473 ;; Default Value: nil
474 ;; `anything-c-etags-search-regexp'
475 ;; Default Value: "^.+: .+ \\<%s"
476 ;; `anything-c-filelist-file-name'
477 ;; Default Value: nil
478 ;; `anything-c-eldoc-in-minibuffer-show-fn'
479 ;; Default Value: anything-c-show-info-in-mode-line
480 ;; `anything-c-turn-on-show-completion'
482 ;; `anything-lisp-completion-or-indent-delay'
483 ;; Default Value: 0.6
484 ;; `anything-c-default-external-file-browser'
485 ;; Default Value: "nautilus"
486 ;; `anything-c-use-adaptative-sorting'
487 ;; Default Value: nil
488 ;; `anything-ff-newfile-prompt-p'
490 ;; `anything-ff-avfs-directory'
491 ;; Default Value: nil
492 ;; `anything-ff-file-compressed-list'
493 ;; Default Value: ("gz" "bz2" "zip" "7z")
494 ;; `anything-locate-db-file-regexp'
495 ;; Default Value: "m?locate.db$"
496 ;; `anything-c-show-info-in-mode-line-delay'
498 ;; `anything-c-copy-files-async-log-file'
499 ;; Default Value: "/tmp/dired.log"
500 ;; `anything-ff-printer-list'
501 ;; Default Value: nil
502 ;; `anything-ff-transformer-show-only-basename'
503 ;; Default Value: nil
504 ;; `anything-completing-read-handlers-alist'
505 ;; Default Value: ((describe-function . anything-completing-read-symbols) (describe-variabl [...]
507 ;; * Anything sources defined here:
508 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
509 ;; `anything-c-source-regexp' (Regexp Builder)
510 ;; `anything-c-source-buffers' (Buffers)
511 ;; `anything-c-source-buffer-not-found' (Create buffer)
512 ;; `anything-c-source-buffers-list' (Buffers)
513 ;; `anything-c-source-file-name-history' (File Name History)
514 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
515 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
516 ;; `anything-c-source-find-files' (Find Files)
517 ;; `anything-c-source-write-file' (Write File)
518 ;; `anything-c-source-insert-file' (Insert File)
519 ;; `anything-c-source-copy-files' (Copy Files)
520 ;; `anything-c-source-symlink-files' (Symlink Files)
521 ;; `anything-c-source-hardlink-files' (Hardlink Files)
522 ;; `anything-c-source-file-cache' (File Cache)
523 ;; `anything-c-source-locate' (Locate)
524 ;; `anything-c-source-recentf' (Recentf)
525 ;; `anything-c-source-ffap-guesser' (File at point)
526 ;; `anything-c-source-ffap-line' (File/Lineno at point)
527 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
528 ;; `anything-c-source-filelist' (FileList)
529 ;; `anything-c-source-info-pages' (Info Pages)
530 ;; `anything-c-source-info-elisp' (Info index: elisp)
531 ;; `anything-c-source-info-cl' (Info index: cl)
532 ;; `anything-c-source-info-org' (Info index: org)
533 ;; `anything-c-source-info-gnus' (Info index: Gnus)
534 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
535 ;; `anything-c-source-info-zsh' (Info index: zsh)
536 ;; `anything-c-source-info-bash' (Info index: bash)
537 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
538 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
539 ;; `anything-c-source-info-find' (Info index: find)
540 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
541 ;; `anything-c-source-info-textutils' (Info index: textutils)
542 ;; `anything-c-source-info-libc' (Info index: libc)
543 ;; `anything-c-source-info-make' (Info index: make)
544 ;; `anything-c-source-info-automake' (Info index: automake)
545 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
546 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
547 ;; `anything-c-source-info-emacs' (Info index: emacs)
548 ;; `anything-c-source-info-elib' (Info index: elib)
549 ;; `anything-c-source-info-eieio' (Info index: eieio)
550 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
551 ;; `anything-c-source-info-guile' (Info index: guile)
552 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
553 ;; `anything-c-source-info-goops' (Info index: goops)
554 ;; `anything-c-source-info-screen' (Info index: screen)
555 ;; `anything-c-source-info-latex' (Info index: latex)
556 ;; `anything-c-source-info-gawk' (Info index: gawk)
557 ;; `anything-c-source-info-sed' (Info index: sed)
558 ;; `anything-c-source-info-m4' (Info index: m4)
559 ;; `anything-c-source-info-wget' (Info index: wget)
560 ;; `anything-c-source-info-binutils' (Info index: binutils)
561 ;; `anything-c-source-info-as' (Info index: as)
562 ;; `anything-c-source-info-bfd' (Info index: bfd)
563 ;; `anything-c-source-info-gprof' (Info index: gprof)
564 ;; `anything-c-source-info-ld' (Info index: ld)
565 ;; `anything-c-source-info-diff' (Info index: diff)
566 ;; `anything-c-source-info-flex' (Info index: flex)
567 ;; `anything-c-source-info-grep' (Info index: grep)
568 ;; `anything-c-source-info-gzip' (Info index: gzip)
569 ;; `anything-c-source-info-libtool' (Info index: libtool)
570 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
571 ;; `anything-c-source-info-info' (Info index: info)
572 ;; `anything-c-source-info-gdb' (Info index: gdb)
573 ;; `anything-c-source-info-stabs' (Info index: stabs)
574 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
575 ;; `anything-c-source-info-cvs' (Info index: cvs)
576 ;; `anything-c-source-info-bison' (Info index: bison)
577 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
578 ;; `anything-c-source-info-global' (Info index: global)
579 ;; `anything-c-source-man-pages' (Manual Pages)
580 ;; `anything-c-source-complex-command-history' (Complex Command History)
581 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
582 ;; `anything-c-source-emacs-commands' (Emacs Commands)
583 ;; `anything-c-source-emacs-functions' (Emacs Functions)
584 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
585 ;; `anything-c-source-advice' (Function Advice)
586 ;; `anything-c-source-emacs-variables' (Emacs Variables)
587 ;; `anything-c-source-lacarte' (Lacarte)
588 ;; `anything-c-source-bookmarks' (Bookmarks)
589 ;; `anything-c-source-bookmark-set' (Set Bookmark)
590 ;; `anything-c-source-bm' (Visible Bookmarks)
591 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
592 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
593 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
594 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
595 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
596 ;; `anything-c-source-bookmark-images' (Bookmark Images)
597 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
598 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
599 ;; `anything-c-source-bookmark-info' (Bookmark Info)
600 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
601 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
602 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
603 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
604 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
605 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
606 ;; `anything-c-source-imenu' (Imenu)
607 ;; `anything-c-source-ctags' (Exuberant ctags)
608 ;; `anything-c-source-etags-select' (Etags)
609 ;; `anything-c-source-semantic' (Semantic Tags)
610 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
611 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
612 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
613 ;; `anything-c-source-customize-face' (Customize Face)
614 ;; `anything-c-source-colors' (Colors)
615 ;; `anything-c-source-tracker-search' (Tracker Search)
616 ;; `anything-c-source-mac-spotlight' (mdfind)
617 ;; `anything-c-source-picklist' (Picklist)
618 ;; `anything-c-source-kill-ring' (Kill Ring)
619 ;; `anything-c-source-mark-ring' (mark-ring)
620 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
621 ;; `anything-c-source-register' (Registers)
622 ;; `anything-c-source-latex-math' (Latex Math Menu)
623 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
624 ;; `anything-c-source-rd-headline' (RD HeadLine)
625 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
626 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
627 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
628 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
629 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
630 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
631 ;; `anything-c-source-eev-anchor' (Anchors)
632 ;; `anything-c-source-org-headline' (Org HeadLine)
633 ;; `anything-c-source-org-keywords' (Org Keywords)
634 ;; `anything-c-source-bbdb' (BBDB)
635 ;; `anything-c-source-evaluation-result' (Evaluation Result)
636 ;; `anything-c-source-calculation-result' (Calculation Result)
637 ;; `anything-c-source-google-suggest' (Google Suggest)
638 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
639 ;; `anything-c-source-emms-streams' (Emms Streams)
640 ;; `anything-c-source-emms-dired' (Music Directory)
641 ;; `anything-c-source-emms-files' (Emms files)
642 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
643 ;; `anything-c-source-call-source' (Call anything source)
644 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
645 ;; `anything-c-source-occur' (Occur)
646 ;; `anything-c-source-browse-code' (Browse code)
647 ;; `anything-c-source-create' (Create)
648 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
649 ;; `anything-c-source-elscreen' (Elscreen)
650 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
651 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
652 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
653 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
654 ;; `anything-c-source-xfonts' (X Fonts)
655 ;; `anything-c-source-ucs' (Ucs names)
656 ;; `anything-c-source-emacs-process' (Emacs Process)
657 ;; `anything-c-source-time-world' (Time World List)
658 ;; `anything-c-source-apt' (APT)
659 ;; `anything-c-source-gentoo' (Portage sources)
660 ;; `anything-c-source-use-flags' (Use Flags)
661 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
662 ;; `anything-c-source-esh' (Eshell completions)
663 ;; `anything-c-source-eshell-history' (Eshell history)
665 ;; *** END auto-documentation
669 ;; Install developer-tools/autodoc.el and
670 ;; Evaluate (autodoc-update-all) before commit or run it interactively.
671 ;; This function generates anything-c-source-* / functions / options list.
673 ;; [EVAL IT] (autodoc-update-all)
675 ;; Please write details documentation about function, then others will
676 ;; read code more easier. -- Andy Stewart
682 ;; Change log of this file is found at
683 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
685 ;; Change log of this project is found at
686 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
691 ;; Tassilo Horn <tassilo@member.fsf.org>
692 ;; Vagn Johansen <gonz808@hotmail.com>
693 ;; Mathias Dahl <mathias.dahl@gmail.com>
694 ;; Bill Clementson <billclem@gmail.com>
695 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
696 ;; Drew Adams <drew.adams@oracle.com>
697 ;; Jason McBrayer <jmcbray@carcosa.net>
698 ;; Andy Stewart <lazycat.manatee@gmail.com>
699 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
700 ;; rubikitch <rubikitch@ruby-lang.org>
701 ;; Scott Vokes <vokes.s@gmail.com>
702 ;; Kenichirou Oyama <k1lowxb@gmail.com>
707 ;; - Fix documentation, now many functions haven't documentations.
726 (eval-when-compile (require 'org
)) ; Shut up byte compiler about org-directory.
727 (eval-when-compile (require 'semantic nil t
))
728 (require 'anything-match-plugin
)
732 ;;; Declare external functions
735 (declare-function gnus-dired-attach
"ext:gnus-dired.el" (files-to-attach))
736 (declare-function image-dired-display-image
"image-dired.el" (file &optional original-size
))
737 (declare-function image-dired-update-property
"image-dired.el" (prop value
))
738 (declare-function woman-file-name-all-completions
"woman.el" (topic))
739 (declare-function Man-getpage-in-background
"man.el" (topic))
740 (declare-function simple-call-tree-analyze
"ext:simple-call-tree.el" (&optional test
))
741 (declare-function yaoddmuse-update-pagename
"ext:yaoddmuse.el" (&optional unforced
))
742 (declare-function yaoddmuse-get-library-list
"ext:yaoddmuse.el" (&optional dirs string
))
743 (declare-function org-get-current-options
"ext:org-exp.el")
744 (declare-function emms-streams
"ext:emms-streams")
745 (declare-function emms-stream-delete-bookmark
"ext:emms-streams")
746 (declare-function emms-stream-add-bookmark
"ext:emms-streams" (name url fd type
))
747 (declare-function emms-stream-save-bookmarks-file
"ext:emms-streams")
748 (declare-function emms-stream-quit
"ext:emms-streams")
749 (declare-function with-current-emms-playlist
"ext:emms" (&rest body
))
750 (declare-function emms-playlist-tracks-in-region
"ext:emms" (beg end
))
751 (declare-function emms-playlist-first
"ext:emms")
752 (declare-function emms-playlist-mode-play-smart
"ext:emms-playlist-mode")
753 (declare-function term-line-mode
"term")
754 (declare-function term-char-mode
"term")
755 (declare-function term-send-input
"term")
756 (declare-function term-send-eof
"term")
757 (declare-function Info-index-nodes
"info" (&optional file
))
758 (declare-function Info-goto-node
"info" (&optional fork
))
759 (declare-function Info-find-node
"info.el" (filename nodename
&optional no-going-back
))
760 (declare-function elscreen-find-screen-by-buffer
"ext:elscreen.el" (buffer &optional create
))
761 (declare-function elscreen-find-file
"ext:elscreen.el" (filename))
762 (declare-function elscreen-goto
"ext:elscreen.el" (screen))
763 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
764 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
765 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
766 (declare-function semantic-tag-type
"ext:tag-file.el" (tag) t
)
767 (declare-function semantic-tag-class
"ext:tag-file.el" (tag) t
)
768 (declare-function bbdb
"ext:bbdb-com")
769 (declare-function bbdb-current-record
"ext:bbdb-com")
770 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
771 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
772 (declare-function bbdb-current-record
"ext:bbdb-com")
773 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
774 (declare-function bbdb-records
"ext:bbdb-com"
775 (&optional dont-check-disk already-in-db-buffer
))
776 (declare-function eshell-read-aliases-list
"em-alias")
777 (declare-function eshell-send-input
"esh-mode" (&optional use-region queue-p no-newline
))
778 (declare-function eshell-bol
"esh-mode")
779 (declare-function eldoc-current-symbol
"eldoc")
780 (declare-function eldoc-get-fnsym-args-string
"eldoc" (sym &optional index
))
781 (declare-function eldoc-get-var-docstring
"eldoc" (sym))
782 (declare-function eldoc-fnsym-in-current-sexp
"eldoc")
783 (declare-function find-library-name
"find-func.el" (library))
784 (declare-function adoc-construct
"ext:auto-document.el" (buf))
785 (declare-function adoc-first-line
"ext:auto-document.el" (str))
786 (declare-function adoc-prin1-to-string
"ext:auto-document.el" (object))
787 (declare-function secure-hash
"ext:fns.c" (algorithm object
&optional start end binary
))
788 (declare-function w32-shell-execute
"ext:w32fns.c" (operation document
&optional parameters show-flag
))
794 (unless (fboundp 'window-system
)
795 (defun window-system (&optional arg
)
803 (defgroup anything-config nil
804 "Predefined configurations for `anything.el'."
807 (defcustom anything-c-adaptive-history-file
808 "~/.emacs.d/anything-c-adaptive-history"
809 "Path of file where history information is stored."
811 :group
'anything-config
)
813 (defcustom anything-c-adaptive-history-length
50
814 "Maximum number of candidates stored for a source."
816 :group
'anything-config
)
818 (defcustom anything-c-google-suggest-url
819 "http://google.com/complete/search?output=toolbar&q="
820 "URL used for looking up Google suggestions."
822 :group
'anything-config
)
824 (defcustom anything-c-google-suggest-search-url
825 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
826 "URL used for Google searching."
828 :group
'anything-config
)
830 (defcustom anything-google-suggest-use-curl-p nil
831 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
832 Otherwise `url-retrieve-synchronously' is used."
834 :group
'anything-config
)
836 (defcustom anything-c-yahoo-suggest-url
837 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
838 "Url used for looking up Yahoo suggestions."
840 :group
'anything-config
)
842 (defcustom anything-c-yahoo-suggest-search-url
843 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
844 "Url used for Yahoo searching."
846 :group
'anything-config
)
848 (defcustom anything-c-boring-buffer-regexp
852 "*anything" "*ac-mode"
854 " *Echo Area" " *Minibuf"))
855 "The regexp that match boring buffers.
856 Buffer candidates matching this regular expression will be
857 filtered from the list of candidates if the
858 `anything-c-skip-boring-buffers' candidate transformer is used, or
859 they will be displayed with face `file-name-shadow' if
860 `anything-c-shadow-boring-buffers' is used."
862 :group
'anything-config
)
863 ;; (string-match anything-c-boring-buffer-regexp "buf")
864 ;; (string-match anything-c-boring-buffer-regexp " hidden")
865 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
867 (defcustom anything-c-boring-file-regexp
869 ;; Boring directories
870 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
872 (and line-start
".#")
873 (and (or ".class" ".la" ".o" "~") eol
)))
874 "The regexp that match boring files.
875 File candidates matching this regular expression will be
876 filtered from the list of candidates if the
877 `anything-c-skip-boring-files' candidate transformer is used, or
878 they will be displayed with face `file-name-shadow' if
879 `anything-c-shadow-boring-files' is used."
881 :group
'anything-config
)
883 (defcustom anything-kill-ring-threshold
10
884 "*Minimum length to be listed by `anything-c-source-kill-ring'."
886 :group
'anything-config
)
888 (defcustom anything-c-kill-ring-max-lines-number nil
889 "Max number of lines displayed per candidate in kill-ring browser.
890 If nil or zero, don't truncate candidate, show all."
892 :group
'anything-config
)
894 (defcustom anything-su-or-sudo
"su"
895 "What command to use for root access."
897 :group
'anything-config
)
899 (defcustom anything-for-files-prefered-list
900 '(anything-c-source-ffap-line
901 anything-c-source-ffap-guesser
902 anything-c-source-buffers-list
903 anything-c-source-recentf
904 anything-c-source-bookmarks
905 anything-c-source-file-cache
906 anything-c-source-files-in-current-dir
+
907 anything-c-source-locate
)
908 "Your prefered sources to find files."
910 :group
'anything-config
)
912 (defcustom anything-create--actions-private nil
913 "User defined actions for `anything-create' / `anything-c-source-create'.
914 It is a list of (DISPLAY . FUNCTION) pairs like `action'
915 attribute of `anything-sources'.
917 It is prepended to predefined pairs."
919 :group
'anything-config
)
921 (defcustom anything-allow-skipping-current-buffer t
922 "Show current buffer or not in anything buffer"
924 :group
'anything-config
)
926 (defcustom anything-c-enable-eval-defun-hack t
927 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
928 This hack is invoked when pressing C-M-x in the form \
929 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
931 :group
'anything-config
)
933 (defcustom anything-tramp-verbose
0
934 "*Just like `tramp-verbose' but specific to anything.
935 When set to 0 don't show tramp messages in anything.
936 If you want to have the default tramp messages set it to 3."
938 :group
'anything-config
)
940 (defcustom anything-raise-command nil
941 "*A shell command to jump to a window running specific program.
942 Need external program wmctrl.
943 This will be use with `format', so use something like \"wmctrl -xa %s\"."
945 :group
'anything-config
)
947 (defun anything-set-anything-command-map-prefix-key (var key
)
948 (declare (special anything-command-map-prefix-key
))
949 (when (boundp 'anything-command-map-prefix-key
)
950 (global-unset-key (read-kbd-macro anything-command-map-prefix-key
)))
951 (setq anything-command-map-prefix-key key
)
952 (global-set-key (read-kbd-macro anything-command-map-prefix-key
)
953 'anything-command-map
))
955 (defcustom anything-command-map-prefix-key
"<f5> a"
956 "*The prefix key for all `anything-command-map' commands.
959 This default value is very likely to be changed,
960 because it is under discussion."
962 :set
'anything-set-anything-command-map-prefix-key
963 :group
'anything-config
)
965 (defcustom anything-c-browse-code-regexp-lisp
966 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
967 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
968 "*Regexp used to parse lisp buffer when browsing code."
970 :group
'anything-config
)
972 (defcustom anything-c-browse-code-regexp-python
973 "\\<def\\>\\|\\<class\\>"
974 "*Regexp used to parse python buffer when browsing code."
976 :group
'anything-config
)
978 (defcustom anything-c-browse-code-regexp-alist
979 `((lisp-interaction-mode .
,anything-c-browse-code-regexp-lisp
)
980 (emacs-lisp-mode .
,anything-c-browse-code-regexp-lisp
)
981 (lisp-mode .
,anything-c-browse-code-regexp-lisp
)
982 (python-mode .
,anything-c-browse-code-regexp-python
))
983 "*Alist to store regexps for browsing code corresponding \
984 to a specific `major-mode'."
986 :group
'anything-config
)
988 (defcustom anything-c-external-programs-associations nil
989 "*Alist to store externals programs associated with file extension.
990 This variable overhide setting in .mailcap file.
991 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
993 :group
'anything-config
)
995 (defcustom anything-ff-auto-update-initial-value t
996 "Auto update when only one candidate directory is matched.
997 This is the default value when starting `anything-find-files'."
998 :group
'anything-config
1001 (defcustom anything-c-copy-async-prefered-emacs
"emacs"
1002 "Path to the emacs you want to use for copying async.
1003 Emacs versions < 24 fail to copy directory due to a bug not fixed
1004 in `copy-directory'."
1005 :group
'anything-config
1008 (defcustom anything-ff-lynx-style-map t
1009 "Use arrow keys to navigate with `anything-find-files'.
1010 You will have to restart Emacs or reeval `anything-find-files-map'
1011 and `anything-c-read-file-map' for this take effect."
1012 :group
'anything-config
1015 (defcustom anything-ff-history-max-length
100
1016 "*Number of elements shown in `anything-find-files' history."
1017 :group
'anything-config
1020 (defcustom anything-ff-smart-completion t
1021 "Try to complete filenames smarter when non--nil.
1022 See `anything-ff-transform-fname-for-completion' for more info."
1023 :group
'anything-config
1026 (defcustom anything-ff-default-kbsize
1024.0
1027 "Default Kbsize to use for showing files size.
1028 It is a float, usually 1024.0 but could be 1000.0 on some systems."
1029 :group
'anything-config
1032 (defcustom anything-ff-tramp-not-fancy t
1033 "No colors when listing remote files when set to non--nil.
1034 This make listing much faster, specially on slow machines."
1035 :group
'anything-config
1038 (defcustom anything-ff-exif-data-program
"exiftran"
1039 "*Program used to extract exif data of an image file."
1040 :group
'anything-config
1043 (defcustom anything-ff-exif-data-program-args
"-d"
1044 "*Arguments used for `anything-ff-exif-data-program'."
1045 :group
'anything-config
1048 (defcustom anything-c-grep-use-ioccur-style-keys t
1049 "Use Arrow keys to jump to occurences."
1050 :group
'anything-config
1053 (defcustom anything-c-pdfgrep-default-read-command
"xpdf '%f' %p"
1054 "Default command to read pdf files from pdfgrep.
1055 Where '%f' format spec is filename and '%p' is page number"
1056 :group
'anything-config
1059 (defcustom anything-c-etags-tag-file-name
"TAGS"
1060 "Etags tag file name."
1062 :group
'anything-config
)
1064 (defcustom anything-c-etags-tag-file-search-limit
10
1065 "The limit level of directory to search tag file.
1066 Don't search tag file deeply if outside this value."
1068 :group
'anything-config
)
1070 (defcustom anything-c-etags-use-regexp-search nil
1071 "When non--nil search etags candidates by regexp.
1072 This disable anything-match-plugin when enabled.
1073 When nil search is performed directly on patter and *match-plugin is used
1074 if available. You can customize `anything-c-etags-search-regexp'."
1075 :group
'anything-config
1078 (defcustom anything-c-etags-search-regexp
"^.+: .+ \\<%s"
1079 "Regexp that match tags in an anything etags buffer.
1080 The format spec is replaced by pattern.
1081 This regexp have no effect when `anything-c-etags-use-regexp-search'
1083 :group
'anything-config
1086 (defcustom anything-c-filelist-file-name nil
1087 "Filename of file list.
1088 Accept a list of string for multiple files.
1090 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1091 File list is created by make-filelist.rb script.
1094 ruby make-filelist.rb > /tmp/all.filelist
1097 ;; Assume that /tmp is ramdisk or tmpfs
1098 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1099 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1102 :group
'anything-config
)
1104 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1105 'anything-c-show-info-in-mode-line
1106 "A function to display eldoc info.
1107 Should take one arg: the string to display."
1108 :group
'anything-config
1111 (defcustom anything-c-turn-on-show-completion t
1112 "Display candidate in buffer while moving selection when non--nil."
1113 :group
'anything-config
1116 (defcustom anything-lisp-completion-or-indent-delay
0.6
1117 "After this delay `anything-lisp-completion-counter' is reset to 0.
1118 This allow to indent again without completing lisp symbol after this delay.
1119 Default is 0.6 seconds."
1120 :group
'anything-config
1123 (defcustom anything-c-default-external-file-browser
"nautilus"
1124 "Default external file browser for your system.
1125 Directories will be opened externally with it when
1126 opening file externally in `anything-find-files'.
1127 Set to nil if you do not have external file browser
1128 or do not want to use it.
1129 Windows users should set that to \"explorer.exe\"."
1130 :group
'anything-config
1133 (defcustom anything-c-use-adaptative-sorting nil
1134 "*Wheter to use or not adaptative sorting.
1135 Even if a source use it, it will have no effect when set to nil."
1137 :group
'anything-config
)
1139 (defcustom anything-ff-newfile-prompt-p t
1140 "Whether Prompt or not when creating new file.
1141 This set `ffap-newfile-prompt'."
1143 :group
'anything-config
)
1146 (defcustom anything-ff-avfs-directory nil
1147 "*The default avfs directory, usually '.avfs'.
1148 When this is set you will be able to expand archive filenames with `C-z'
1149 inside an avfs directory mounted with mountavfs.
1150 See <http://sourceforge.net/projects/avf/>."
1152 :group
'anything-config
)
1154 (defcustom anything-ff-file-compressed-list
'("gz" "bz2" "zip" "7z")
1155 "*Minimal list of compressed files extension."
1157 :group
'anything-config
)
1159 (defcustom anything-locate-db-file-regexp
"m?locate\.db$"
1160 "Default regexp to match locate database.
1161 If nil Search in all files."
1163 :group
'anything-config
)
1165 (defcustom anything-c-locate-command nil
1166 "A list of arguments for locate program.
1167 If nil it will be calculated when `anything-locate' startup
1168 with these default values for different systems:
1170 Gnu/linux: \"locate -i -r %s\"
1171 berkeley-unix: \"locate -i %s\"
1172 windows-nt: \"es -i -r %s\"
1173 Others: \"locate %s\"
1175 This string will be passed to format so it should end with `%s'.
1176 The \"-r\" option must be the last option."
1178 :group
'anything-config
)
1180 (defcustom anything-c-show-info-in-mode-line-delay
12
1181 "Eldoc will show info in mode-line during this delay if user is idle."
1183 :group
'anything-config
)
1185 (defcustom anything-c-copy-files-async-log-file
"/tmp/dired.log"
1186 "The file used to communicate with two emacs when copying files async."
1188 :group
'anything-config
)
1190 (defcustom anything-ff-printer-list nil
1191 "A list of available printers on your system.
1192 When non--nil let you choose a printer to print file.
1193 Otherwise when nil the variable `printer-name' will be used.
1194 On Unix based systems (lpstat command needed) you don't need to set this,
1195 `anything-ff-find-printers' will find a list of available printers for you."
1197 :group
'anything-config
)
1199 (defcustom anything-ff-transformer-show-only-basename nil
1200 "Show only basename of candidates in `anything-find-files'.
1201 This can be toggled at anytime from `anything-find-files' with \
1202 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1204 :group
'anything-config
)
1206 (defcustom anything-ff-quick-delete-dont-prompt-for-deletion nil
1207 "Don't ask in persistent deletion of files when non--nil."
1208 :group
'anything-config
1211 (defcustom anything-ff-signal-error-on-dot-files t
1212 "Signal error when file is `.' or `..' on file deletion when non--nil.
1213 Default is non--nil."
1214 :group
'anything-config
1217 (defcustom anything-completing-read-handlers-alist
1218 '((describe-function . anything-completing-read-symbols
)
1219 (describe-variable . anything-completing-read-symbols
)
1220 (debug-on-entry . anything-completing-read-symbols
)
1221 (find-function . anything-completing-read-symbols
)
1222 (trace-function . anything-completing-read-symbols
)
1223 (trace-function-background . anything-completing-read-symbols
)
1224 (find-tag . anything-completing-read-with-cands-in-buffer
)
1225 (ffap-alternate-file . nil
))
1226 "Alist of handlers to replace `completing-read', `read-file-name' in `ac-mode'.
1227 Each entry is a cons cell like \(emacs_command . completing-read_handler\)
1228 where key and value are symbols.
1230 Each key is an Emacs command that use originaly `completing-read'.
1232 Each value maybe an anything function that take same arguments as
1233 `completing-read' plus NAME and BUFFER, where NAME is the name of the new
1234 anything source and BUFFER the name of the buffer we will use.
1235 This function prefix name must start by \"anything\".
1237 See `anything-completing-read-symbols' for example.
1239 If the value of an entry is nil completion will fall back to
1240 emacs vanilla behavior.
1241 e.g If you want to disable anything completion for `describe-function':
1242 \(describe-function . nil\).
1244 Ido is also supported, you can use `ido-completing-read' and
1245 `ido-read-file-name' as value of an entry or just 'ido.
1246 e.g ido completion for `find-file':
1249 \(find-file . ido-read-file-name\)
1250 Note that you don't need to enable `ido-mode' for this to work."
1251 :group
'anything-config
1252 :type
'(alist :key-type symbol
:value-type symbol
))
1256 ;;; General internal variables
1258 ;; Some internals variable that need to be loaded
1259 ;; here to avoid compiler warnings.
1260 (defvar anything-c-external-commands-list nil
1261 "A list of all external commands the user can execute. If this
1262 variable is not set by the user, it will be calculated
1265 (defvar anything-c-show-completion-overlay nil
)
1272 (defface anything-buffer-saved-out
1273 '((t (:foreground
"red")))
1274 "*Face used for buffer files modified outside of emacs."
1275 :group
'anything-config
)
1277 (defface anything-buffer-not-saved
1278 '((t (:foreground
"Indianred2")))
1279 "*Face used for buffer files not already saved on disk."
1280 :group
'anything-config
)
1282 (defface anything-ff-prefix
1283 '((t (:background
"yellow" :foreground
"black")))
1284 "*Face used to prefix new file or url paths in `anything-find-files'."
1285 :group
'anything-config
)
1287 (defface anything-ff-executable
1288 '((t (:foreground
"green")))
1289 "*Face used for executable files in `anything-find-files'."
1290 :group
'anything-config
)
1292 (defface anything-ff-directory
1293 '((t (:foreground
"DarkRed" :background
"LightGray")))
1294 "*Face used for directories in `anything-find-files'."
1295 :group
'anything-config
)
1297 (defface anything-ff-symlink
1298 '((t (:foreground
"DarkOrange")))
1299 "*Face used for symlinks in `anything-find-files'."
1300 :group
'anything-config
)
1302 (defface anything-ff-invalid-symlink
1303 '((t (:foreground
"black" :background
"red")))
1304 "*Face used for invalid symlinks in `anything-find-files'."
1305 :group
'anything-config
)
1307 (defface anything-ff-file
1308 '((t (:foreground
"CadetBlue" :underline t
)))
1309 "*Face used for file names in `anything-find-files'."
1310 :group
'anything-config
)
1312 (defface anything-grep-match
1313 '((t (:inherit match
)))
1314 "Face used to highlight grep matches."
1315 :group
'anything-config
)
1317 (defface anything-grep-file
1318 '((t (:foreground
"BlueViolet" :underline t
)))
1319 "Face used to highlight grep results filenames."
1320 :group
'anything-config
)
1322 (defface anything-grep-lineno
1323 '((t (:foreground
"Darkorange1")))
1324 "Face used to highlight grep number lines."
1325 :group
'anything-config
)
1327 (defface anything-grep-running
1328 '((t (:foreground
"Red")))
1329 "Face used in mode line when grep is running."
1330 :group
'anything-config
)
1332 (defface anything-grep-finish
1333 '((t (:foreground
"Green")))
1334 "Face used in mode line when grep is finish."
1335 :group
'anything-config
)
1337 (defface anything-M-x-key-face
'((t (:foreground
"orange" :underline t
)))
1338 "*Face used in anything-M-x to show keybinding."
1341 (defface anything-bmkext-info
1342 '((t (:foreground
"green")))
1343 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1346 (defface anything-bmkext-w3m
1347 '((t (:foreground
"yellow")))
1348 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1351 (defface anything-bmkext-gnus
1352 '((t (:foreground
"magenta")))
1353 "*Face used for Gnus bookmarks."
1356 (defface anything-bmkext-man
1357 '((t (:foreground
"Orange4")))
1358 "*Face used for Woman/man bookmarks."
1361 (defface anything-bmkext-no--file
1362 '((t (:foreground
"grey")))
1363 "*Face used for non--file bookmarks."
1366 (defface anything-bmkext-file
1367 '((t (:foreground
"Deepskyblue2")))
1368 "*Face used for non--file bookmarks."
1371 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
1372 "Face for su/sudo bookmarks."
1375 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
1376 "Face for w3m bookmarks" :group
'anything
)
1378 (defface anything-emms-playlist
1379 '((t (:foreground
"Springgreen4" :underline t
)))
1380 "*Face used for tracks in current emms playlist."
1383 (defface anything-apt-installed
1384 '((t (:foreground
"green")))
1385 "*Face used for apt installed candidates."
1388 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
1389 "Face for anything-gentoo installed packages."
1390 :group
'traverse-faces
)
1392 (defface anything-lisp-show-completion
1393 '((t (:background
"DarkSlateGray")))
1394 "*Face used for showing candidates in `anything-lisp-completion'."
1395 :group
'anything-config
)
1397 (defface anything-lisp-completion-info
1398 '((t (:foreground
"red")))
1399 "*Face used for showing info in `anything-lisp-completion'."
1400 :group
'anything-config
)
1402 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
1403 "Face for source header in the anything buffer." :group
'anything
)
1406 (defun anything-configuration ()
1407 "Customize `anything'."
1409 (customize-group "anything-config"))
1413 ;;; Anything-command-map
1417 (defvar anything-command-map
)
1418 (define-prefix-command 'anything-command-map
)
1421 (define-key anything-command-map
(kbd "<SPC>") 'anything-execute-anything-command
)
1422 (define-key anything-command-map
(kbd "a") 'anything-c-apropos
)
1423 (define-key anything-command-map
(kbd "e") 'anything-c-etags-select
)
1424 (define-key anything-command-map
(kbd "l") 'anything-locate
)
1425 (define-key anything-command-map
(kbd "s") 'anything-surfraw
)
1426 (define-key anything-command-map
(kbd "r") 'anything-regexp
)
1427 (define-key anything-command-map
(kbd "w") 'anything-w3m-bookmarks
)
1428 (define-key anything-command-map
(kbd "x") 'anything-firefox-bookmarks
)
1429 (define-key anything-command-map
(kbd "#") 'anything-emms
)
1430 (define-key anything-command-map
(kbd "m") 'anything-man-woman
)
1431 (define-key anything-command-map
(kbd "t") 'anything-top
)
1432 (define-key anything-command-map
(kbd "i") 'anything-imenu
)
1433 (define-key anything-command-map
(kbd "<tab>") 'anything-lisp-completion-at-point
)
1434 (define-key anything-command-map
(kbd "p") 'anything-list-emacs-process
)
1435 (define-key anything-command-map
(kbd "C-x r b") 'anything-c-pp-bookmarks
)
1436 (define-key anything-command-map
(kbd "M-y") 'anything-show-kill-ring
)
1437 (define-key anything-command-map
(kbd "C-c <SPC>") 'anything-all-mark-rings
)
1438 (define-key anything-command-map
(kbd "C-x C-f") 'anything-find-files
)
1439 (define-key anything-command-map
(kbd "f") 'anything-for-files
)
1440 (define-key anything-command-map
(kbd "C-:") 'anything-eval-expression-with-eldoc
)
1441 (define-key anything-command-map
(kbd "C-,") 'anything-calcul-expression
)
1442 (define-key anything-command-map
(kbd "M-x") 'anything-M-x
)
1443 (define-key anything-command-map
(kbd "C-x C-w") 'anything-write-file
)
1444 (define-key anything-command-map
(kbd "C-x i") 'anything-insert-file
)
1445 (define-key anything-command-map
(kbd "M-s o") 'anything-occur
)
1446 (define-key anything-command-map
(kbd "M-g s") 'anything-do-grep
)
1447 (define-key anything-command-map
(kbd "c") 'anything-colors
)
1448 (define-key anything-command-map
(kbd "F") 'anything-select-xfont
)
1449 (define-key anything-command-map
(kbd "C-c f") 'anything-recentf
)
1450 (define-key anything-command-map
(kbd "C-c g") 'anything-google-suggest
)
1451 (define-key anything-command-map
(kbd "h i") 'anything-info-at-point
)
1452 (define-key anything-command-map
(kbd "h r") 'anything-info-emacs
)
1453 (define-key anything-command-map
(kbd "h g") 'anything-info-gnus
)
1454 (define-key anything-command-map
(kbd "C-x C-b") 'anything-buffers-list
)
1455 (define-key anything-command-map
(kbd "C-c C-b") 'anything-browse-code
)
1456 (define-key anything-command-map
(kbd "C-x r i") 'anything-register
)
1457 (define-key anything-command-map
(kbd "C-c C-x") 'anything-c-run-external-command
)
1459 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1460 ;; minibuffer-local-filename-must-match-map.
1461 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
1462 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
1463 (dolist (map (list minibuffer-local-filename-completion-map
1464 minibuffer-local-completion-map
1465 minibuffer-local-must-match-filename-map
1466 minibuffer-local-filename-must-match-map
1467 minibuffer-local-map
1468 minibuffer-local-isearch-map
1469 minibuffer-local-must-match-map
1470 minibuffer-local-ns-map
))
1471 (define-key map
"\C-r" 'anything-minibuffer-history
))
1478 (easy-menu-define nil global-map
1481 ["All anything commands" anything-execute-anything-command t
]
1482 ["Find any Files/Buffers" anything-for-files t
]
1483 ["Anything Everywhere (Toggle)" ac-mode t
]
1486 ["Find files" anything-find-files t
]
1487 ["Recent Files" anything-recentf t
]
1488 ["Locate" anything-locate t
]
1489 ["Bookmarks" anything-c-pp-bookmarks t
])
1491 ["Find buffers" anything-buffers-list t
])
1493 ["Emacs Commands" anything-M-x t
]
1494 ["Externals Commands" anything-c-run-external-command t
])
1496 ["Anything Apropos" anything-c-apropos t
])
1498 ["Info at point" anything-info-at-point t
]
1499 ["Emacs Manual index" anything-info-emacs t
]
1500 ["Gnus Manual index" anything-info-gnus t
])
1502 ["Org keywords" anything-org-keywords t
]
1503 ["Org headlines" anything-org-headlines t
])
1505 ["Occur" anything-occur t
]
1506 ["Grep" anything-do-grep t
]
1507 ["Etags" anything-c-etags-select t
]
1508 ["Lisp complete at point" anything-lisp-completion-at-point t
]
1509 ["Browse Kill ring" anything-show-kill-ring t
]
1510 ["Browse register" anything-register t
]
1511 ["Browse code" anything-browse-code t
]
1512 ["Mark Ring" anything-all-mark-rings t
]
1513 ["Regexp handler" anything-regexp t
]
1514 ["Colors & Faces" anything-colors t
]
1515 ["Show xfonts" anything-select-xfont t
]
1516 ["Ucs Symbols" anything-ucs t
]
1517 ["Imenu" anything-imenu t
]
1518 ["Google Suggest" anything-google-suggest t
]
1519 ["Eval expression" anything-eval-expression-with-eldoc t
]
1520 ["Calcul expression" anything-calcul-expression t
]
1521 ["Man pages" anything-man-woman t
]
1522 ["Top externals process" anything-top t
]
1523 ["Emacs internals process" anything-list-emacs-process t
])
1525 ["Prefered Options" anything-configuration t
]))
1527 ;;; Anything map add ons
1530 (define-key anything-map
(kbd "C-x C-f") 'anything-quit-and-find-file
)
1531 (define-key anything-map
(kbd "M-m") 'anything-toggle-all-marks
)
1532 (define-key anything-map
(kbd "C-w") 'anything-yank-text-at-point
)
1535 ;;; Specialized keymaps
1538 (defvar anything-c-buffer-map
1539 (let ((map (copy-keymap anything-map
)))
1540 (define-key map
(kbd "C-c ?") 'anything-c-buffer-help
)
1541 ;; No need to have separate command for grep and zgrep
1542 ;; as we don't use recursivity for buffers.
1543 ;; So use zgrep for both as it is capable to handle non--compressed files.
1544 (define-key map
(kbd "M-g s") 'anything-buffer-run-zgrep
)
1545 (define-key map
(kbd "C-o") 'anything-buffer-switch-other-window
)
1546 (define-key map
(kbd "C-c C-o") 'anything-buffer-switch-other-frame
)
1547 (define-key map
(kbd "C-c =") 'anything-buffer-run-ediff
)
1548 (define-key map
(kbd "M-=") 'anything-buffer-run-ediff-merge
)
1549 (define-key map
(kbd "C-=") 'anything-buffer-diff-persistent
)
1550 (define-key map
(kbd "M-U") 'anything-buffer-revert-persistent
)
1551 (define-key map
(kbd "M-D") 'anything-buffer-run-kill-buffers
)
1552 (define-key map
(kbd "C-x C-s") 'anything-buffer-save-persistent
)
1553 (define-key map
(kbd "C-M-%") 'anything-buffer-run-query-replace-regexp
)
1554 (define-key map
(kbd "M-%") 'anything-buffer-run-query-replace
)
1555 (define-key map
(kbd "M-m") 'anything-toggle-all-marks
)
1556 (define-key map
(kbd "M-a") 'anything-mark-all
)
1557 (when (locate-library "elscreen")
1558 (define-key map
(kbd "<C-tab>") 'anything-buffer-switch-to-elscreen
))
1560 "Keymap for buffer sources in anything.")
1562 (defvar anything-find-files-map
1563 (let ((map (copy-keymap anything-map
)))
1564 (define-key map
(kbd "C-]") 'anything-ff-run-toggle-basename
)
1565 (define-key map
(kbd "C-x C-f") 'anything-ff-run-locate
)
1566 (define-key map
(kbd "M-g s") 'anything-ff-run-grep
)
1567 (define-key map
(kbd "M-g p") 'anything-ff-run-pdfgrep
)
1568 (define-key map
(kbd "M-g z") 'anything-ff-run-zgrep
)
1569 (define-key map
(kbd "M-.") 'anything-ff-run-etags
)
1570 (define-key map
(kbd "M-R") 'anything-ff-run-rename-file
)
1571 (define-key map
(kbd "M-C") 'anything-ff-run-copy-file
)
1572 (define-key map
(kbd "M-B") 'anything-ff-run-byte-compile-file
)
1573 (define-key map
(kbd "M-L") 'anything-ff-run-load-file
)
1574 (define-key map
(kbd "M-S") 'anything-ff-run-symlink-file
)
1575 (define-key map
(kbd "M-D") 'anything-ff-run-delete-file
)
1576 (define-key map
(kbd "M-K") 'anything-ff-run-kill-buffer-persistent
)
1577 (define-key map
(kbd "C-d") 'anything-ff-persistent-delete
)
1578 (define-key map
(kbd "M-e") 'anything-ff-run-switch-to-eshell
)
1579 (define-key map
(kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point
)
1580 (define-key map
(kbd "C-o") 'anything-ff-run-switch-other-window
)
1581 (define-key map
(kbd "C-c C-o") 'anything-ff-run-switch-other-frame
)
1582 (define-key map
(kbd "C-c C-x") 'anything-ff-run-open-file-externally
)
1583 (define-key map
(kbd "M-!") 'anything-ff-run-eshell-command-on-file
)
1584 (define-key map
(kbd "C-=") 'anything-ff-run-ediff-file
)
1585 (define-key map
(kbd "C-c =") 'anything-ff-run-ediff-merge-file
)
1586 (define-key map
(kbd "M-p") 'anything-ff-run-switch-to-history
)
1587 (define-key map
(kbd "M-i") 'anything-ff-properties-persistent
)
1588 (define-key map
(kbd "C-c ?") 'anything-ff-help
)
1589 (define-key map
(kbd "C-}") 'anything-narrow-window
)
1590 (define-key map
(kbd "C-{") 'anything-enlarge-window
)
1591 (define-key map
(kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update
)
1592 (define-key map
(kbd "M-a") 'anything-mark-all
)
1593 (define-key map
(kbd "M-m") 'anything-toggle-all-marks
)
1594 (define-key map
(kbd "M-u") 'anything-unmark-all
)
1595 (define-key map
(kbd "C-c C-a") 'anything-ff-run-gnus-attach-files
)
1596 (define-key map
(kbd "C-c p") 'anything-ff-run-print-file
)
1597 ;; Next 2 have no effect if candidate is not an image file.
1598 (define-key map
(kbd "M-l") 'anything-ff-rotate-left-persistent
)
1599 (define-key map
(kbd "M-r") 'anything-ff-rotate-right-persistent
)
1600 (define-key map
(kbd "C-.") 'anything-find-files-down-one-level
)
1601 (define-key map
(kbd "C-l") 'anything-find-files-down-one-level
)
1602 (define-key map
(kbd "C-h C-b") 'anything-send-bug-report-from-anything
)
1603 (define-key map
(kbd "C-h C-d") 'anything-debug-output
)
1604 (when anything-ff-lynx-style-map
1605 (define-key map
(kbd "<left>") 'anything-find-files-down-one-level
)
1606 (define-key map
(kbd "<right>") 'anything-execute-persistent-action
))
1608 "Keymap for `anything-find-files'.")
1610 (defvar anything-c-read-file-map
1611 (let ((map (copy-keymap anything-map
)))
1612 (define-key map
(kbd "C-.") 'anything-find-files-down-one-level
)
1613 (define-key map
(kbd "C-l") 'anything-find-files-down-one-level
)
1614 (define-key map
(kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update
)
1615 (define-key map
(kbd "C-c ?") 'anything-read-file-name-help
)
1616 (when anything-ff-lynx-style-map
1617 (define-key map
(kbd "<left>") 'anything-find-files-down-one-level
)
1618 (define-key map
(kbd "<right>") 'anything-execute-persistent-action
)
1619 (define-key map
(kbd "<M-left>") 'anything-previous-source
)
1620 (define-key map
(kbd "<M-right>") 'anything-next-source
))
1622 "Keymap for `anything-c-read-file-name'.")
1624 (defvar anything-generic-files-map
1625 (let ((map (copy-keymap anything-map
)))
1626 (define-key map
(kbd "M-g s") 'anything-ff-run-grep
)
1627 (define-key map
(kbd "M-g z") 'anything-ff-run-zgrep
)
1628 (define-key map
(kbd "M-g p") 'anything-ff-run-pdfgrep
)
1629 (define-key map
(kbd "M-D") 'anything-ff-run-delete-file
)
1630 (define-key map
(kbd "C-=") 'anything-ff-run-ediff-file
)
1631 (define-key map
(kbd "C-c =") 'anything-ff-run-ediff-merge-file
)
1632 (define-key map
(kbd "C-o") 'anything-ff-run-switch-other-window
)
1633 (define-key map
(kbd "M-i") 'anything-ff-properties-persistent
)
1634 (define-key map
(kbd "C-c C-x") 'anything-ff-run-open-file-externally
)
1635 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1636 (define-key map
(kbd "C-c ?") 'anything-generic-file-help
)
1638 "Generic Keymap for files.")
1640 (defvar anything-c-grep-map
1641 (let ((map (copy-keymap anything-map
)))
1642 (define-key map
(kbd "M-<down>") 'anything-c-goto-next-file
)
1643 (define-key map
(kbd "M-<up>") 'anything-c-goto-precedent-file
)
1644 (define-key map
(kbd "C-o") 'anything-c-grep-run-other-window-action
)
1645 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1646 (define-key map
(kbd "C-x C-s") 'anything-c-grep-run-save-buffer
)
1647 (when anything-c-grep-use-ioccur-style-keys
1648 (define-key map
(kbd "<right>") 'anything-c-grep-run-persistent-action
)
1649 (define-key map
(kbd "<left>") 'anything-c-grep-run-default-action
))
1650 (define-key map
(kbd "C-c ?") 'anything-grep-help
)
1652 "Keymap used in Grep sources.")
1654 (defvar anything-c-pdfgrep-map
1655 (let ((map (copy-keymap anything-map
)))
1656 (define-key map
(kbd "M-<down>") 'anything-c-goto-next-file
)
1657 (define-key map
(kbd "M-<up>") 'anything-c-goto-precedent-file
)
1658 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1659 (define-key map
(kbd "C-c ?") 'anything-pdfgrep-help
)
1661 "Keymap used in pdfgrep.")
1663 (defvar anything-c-etags-map
1664 (let ((map (copy-keymap anything-map
)))
1665 (define-key map
(kbd "M-<down>") 'anything-c-goto-next-file
)
1666 (define-key map
(kbd "M-<up>") 'anything-c-goto-precedent-file
)
1667 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1668 (define-key map
(kbd "C-c ?") 'anything-etags-help
)
1670 "Keymap used in Etags.")
1672 (defvar anything-eval-expression-map
1673 (let ((map (copy-keymap anything-map
)))
1674 (define-key map
(kbd "<C-return>") 'anything-eval-new-line-and-indent
)
1675 (define-key map
(kbd "<tab>") 'lisp-indent-line
)
1676 (define-key map
(kbd "<C-tab>") 'lisp-complete-symbol
)
1677 (define-key map
(kbd "C-p") 'previous-line
)
1678 (define-key map
(kbd "C-n") 'next-line
)
1679 (define-key map
(kbd "<up>") 'previous-line
)
1680 (define-key map
(kbd "<down>") 'next-line
)
1681 (define-key map
(kbd "<right>") 'forward-char
)
1682 (define-key map
(kbd "<left>") 'backward-char
)
1685 (defvar anything-c-ucs-map
1686 (let ((map (copy-keymap anything-map
)))
1687 (define-key map
(kbd "<C-backspace>") 'anything-c-ucs-persistent-delete
)
1688 (define-key map
(kbd "<C-left>") 'anything-c-ucs-persistent-backward
)
1689 (define-key map
(kbd "<C-right>") 'anything-c-ucs-persistent-forward
)
1690 (define-key map
(kbd "<C-return>") 'anything-c-ucs-persistent-insert
)
1691 (define-key map
(kbd "C-c ?") 'anything-c-ucs-help
)
1693 "Keymap for `anything-ucs'.")
1697 ;;; Embeded documentation.
1700 (defun anything-c-list-preconfigured-anything ()
1701 "Collect preconfigured anything functions in this file."
1704 for entry in
(cdr (assoc
1705 (file-truename (locate-library "anything-config"))
1707 if
(and (consp entry
)
1708 (eq (car entry
) 'defun
)
1709 (string-match "^Preconfigured.+$"
1710 (setq doc
(or (documentation (setq sym
(cdr entry
)))
1712 collect
(cons sym
(match-string 0 doc
))))
1714 (defun anything-c-format-preconfigured-anything ()
1715 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x
) (cdr x
)))
1716 (anything-c-list-preconfigured-anything)))
1718 ;;; Global help message - Used by `anything-help'
1721 (setq anything-help-message
1725 "`anything' is QuickSilver-like candidate-selection framework.
1727 Narrow the list by typing some pattern,
1728 Multiple patterns are allowed by splitting by space.
1729 Select with natural Emacs operations, choose with RET.
1731 If you have any problems, press C-c C-x C-b!!
1732 Feel free to send bug reports. I'll fix them.
1733 The steps are described in the beginning of anything.el file.
1735 == Basic Operations ==
1736 C-p, Up: Previous Line
1737 C-n, Down : Next Line
1738 M-v, PageUp : Previous Page
1739 C-v, PageDown : Next Page
1740 Enter : Execute first (default) action / Select
1743 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1744 M-PageDown, C-M-v : Next Page (other-window)
1746 Tab, C-i : Show action list
1747 Left : Previous Source
1748 Right, C-o : Next Source
1749 C-k : Delete pattern
1750 C-z : Persistent Action (Execute action with anything session kept)
1751 C-c C-x C-b: Send a bug report
1753 == Shortcuts For 2nd/3rd Action ==
1754 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1755 \\[anything-select-3rd-action] : Execute 3rd Action
1758 Visible marks store candidate. Some actions uses marked candidates.
1760 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1761 \\[anything-prev-visible-mark] : Previous Mark
1762 \\[anything-next-visible-mark] : Next Mark
1764 == Miscellaneous Commands ==
1765 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1766 \\[anything-quit-and-find-file] : Drop into `find-file'
1767 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1768 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1769 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1770 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1771 \\[anything-force-update] : Recalculate And Redisplay Candidates
1773 == Global Commands ==
1774 \\<global-map>\\[anything-resume] revives last `anything' session.
1775 It is very useful, so you should bind any key.
1777 Single source is executed by \\[anything-call-source].
1779 == Preconfigured `anything' ==
1780 Preconfigured `anything' is commands that uses `anything' interface.
1781 You can use them without configuration.
1784 (apply 'concat
(anything-c-format-preconfigured-anything))
1788 ;;; `anything-buffer-list' help
1792 (defun anything-c-buffer-help ()
1793 "Help command for anything buffers."
1795 (let ((anything-help-message "== Anything Buffer ==
1797 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1798 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1799 \nSpecific commands for `anything-buffers-list':
1800 \\<anything-c-buffer-map>
1801 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1802 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1803 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1804 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1805 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1806 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1807 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1808 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1809 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1810 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1811 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1812 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1813 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1814 \\[anything-mark-all]\t\t->Mark all.
1815 \\[anything-c-buffer-help]\t\t->Display this help.
1816 \n== Anything Map ==
1822 ;;; Find files help (`anything-find-files')
1826 (defun anything-ff-help ()
1827 "Help command for `anything-find-files'."
1829 (let ((anything-help-message "== Anything Find Files ==
1831 \n- Enter `~/' at end of pattern to quickly reach home directory.
1832 - Enter `/' at end of pattern to quickly reach root of your file system.
1833 - Enter `./' at end of pattern to quickly reach `default-directory' (initial start of session).
1834 - You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1835 - Use `C-u C-z' to watch an image.
1836 - To browse images directories turn on `anything-follow-mode' and navigate with arrow keys.
1837 - When entered ediff, hitting `C-g' will ask you to use locate to find the file to ediff with.
1839 \nSpecific commands for `anything-find-files':
1840 \\<anything-find-files-map>
1841 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1842 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1843 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1844 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1845 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1846 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1847 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1848 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1849 \\[anything-ff-run-load-file]\t\t->Load File.
1850 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1851 \\[anything-ff-run-delete-file]\t\t->Delete File.
1852 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1853 \\[anything-ff-persistent-delete]\t->Delete file without quitting.
1854 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1855 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1856 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1857 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1858 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1859 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1860 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1861 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1862 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1863 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1864 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1865 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1866 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1867 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1868 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1869 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1870 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1871 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1872 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1873 \\[anything-narrow-window]\t\t->Narrow anything window.
1874 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1875 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1876 \\[anything-ff-help]\t\t->Display this help info.
1877 \n== Anything Map ==
1882 ;;; Help for `anything-c-read-file-name'
1886 (defun anything-read-file-name-help ()
1888 (let ((anything-help-message "== Anything read file name Map ==\
1889 \nSpecific commands for anything-c-read-file-name:
1890 \\<anything-c-read-file-map>
1891 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1892 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1893 \\[anything-next-source]\t\t->Goto next source.
1894 \\[anything-previous-source]\t->Goto previous source.
1895 \\[anything-read-file-name-help]\t\t->Display this help info.
1896 \n== Anything Map ==
1901 ;;; Generic file help - Used by locate.
1905 (defun anything-generic-file-help ()
1907 (let ((anything-help-message "== Anything Generic files Map ==\
1908 \nSpecific commands for anything locate and others files sources:
1909 \\<anything-generic-files-map>
1910 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1911 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1912 \\[anything-ff-run-delete-file]\t\t->Delete file.
1913 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1914 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1915 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1916 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1917 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1918 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1920 You can add after writing search pattern any of the locate command line options.
1921 e.g -b, -e, -n <number>...etc.
1922 See Man locate for more infos.
1923 \n== Anything Map ==
1932 (defun anything-grep-help ()
1934 (let ((anything-help-message "== Anything Grep Map ==\
1935 \nSpecific commands for Grep and Etags:
1936 \\<anything-c-grep-map>
1937 \\[anything-c-goto-next-file]\t->Next File.
1938 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1939 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1940 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1941 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1942 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1943 \\[anything-grep-help]\t\t->Show this help.
1944 \n== Anything Map ==
1952 (defun anything-pdfgrep-help ()
1954 (let ((anything-help-message "== Anything PdfGrep Map ==\
1955 \nSpecific commands for Pdf Grep:
1956 \\<anything-c-pdfgrep-map>
1957 \\[anything-c-goto-next-file]\t->Next File.
1958 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1959 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1960 \\[anything-pdfgrep-help]\t\t->Show this help.
1961 \n== Anything Map ==
1969 (defun anything-etags-help ()
1970 "The help function for etags."
1972 (let ((anything-help-message "== Anything Etags Map ==\
1973 \nSpecific commands for Etags:
1974 \\<anything-c-etags-map>
1975 \\[anything-c-goto-next-file]\t->Next File.
1976 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1977 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1978 \\[anything-etags-help]\t\t->Show this help.
1979 \n== Anything Map ==
1986 (defun anything-c-ucs-help ()
1987 "Help command for `anything-ucs'."
1989 (let ((anything-help-message "== Anything Ucs ==
1990 \nSpecific commands for `anything-ucs':
1991 \\<anything-c-ucs-map>
1992 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1993 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1994 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1995 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1996 \\[anything-c-ucs-help]\t\t->Show this help.
1998 \n== Anything Map ==
2005 ;;; Mode line strings
2008 (defvar anything-buffer-mode-line-string
2010 "\\<anything-c-buffer-map>\
2011 \\[anything-c-buffer-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-c-source-buffers-list'"))
2019 (defvar anything-ff-mode-line-string
2020 "\\<anything-find-files-map>\
2021 \\[anything-ff-help]:Help, \
2022 \\[anything-send-bug-report-from-anything]:BugReport, \
2024 \\[anything-select-action]:Acts, \
2025 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2026 \\[anything-select-3rd-action]:NthAct"
2027 "String displayed in mode-line in `anything-c-source-find-files'")
2029 (defvar anything-read-file-name-mode-line-string
2030 "\\<anything-c-read-file-map>\
2031 \\[anything-read-file-name-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 "String displayed in mode-line in `anything-c-source-find-files'")
2038 (defvar anything-generic-file-mode-line-string
2039 "\\<anything-generic-files-map>\
2040 \\[anything-generic-file-help]:Help, \
2042 \\[anything-select-action]:Acts,\
2043 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2044 \\[anything-select-3rd-action]:NthAct,\
2045 \\[anything-send-bug-report-from-anything]:BugReport."
2046 "String displayed in mode-line in Locate.")
2048 (defvar anything-grep-mode-line-string
2049 "\\<anything-c-grep-map>\
2050 \\[anything-grep-help]:Help,\
2052 \\[anything-select-action]:Acts,\
2053 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2054 \\[anything-select-3rd-action]:NthAct,\
2055 \\[anything-send-bug-report-from-anything]:BugReport."
2056 "String displayed in mode-line in `anything-do-grep'.")
2058 (defvar anything-pdfgrep-mode-line-string
2059 "\\<anything-c-pdfgrep-map>\
2060 \\[anything-pdfgrep-help]:Help,\
2062 \\[anything-select-action]:Acts,\
2063 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2064 \\[anything-select-3rd-action]:NthAct,\
2065 \\[anything-send-bug-report-from-anything]:BugReport."
2066 "String displayed in mode-line in `anything-do-pdfgrep'.")
2068 (defvar anything-etags-mode-line-string
2069 "\\<anything-c-etags-map>\
2070 \\[anything-etags-help]:Help,\
2072 \\[anything-select-action]:Acts,\
2073 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2074 \\[anything-select-3rd-action]:NthAct,\
2075 \\[anything-send-bug-report-from-anything]:BugReport."
2076 "String displayed in mode-line in `anything-c-etags-select'.")
2079 (defvar anything-c-ucs-mode-line-string
2080 "\\<anything-c-ucs-map>\
2081 \\[anything-c-ucs-help]:Help, \
2083 \\[anything-select-action]:Acts,\
2084 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
2085 \\[anything-select-3rd-action]:NthAct."
2086 "String displayed in mode-line in `anything-ucs'.")
2090 ;;; Utilities Functions
2093 (defun anything-ff-find-printers ()
2094 "Return a list of available printers on Unix systems."
2095 (when (executable-find "lpstat")
2096 (let ((printer-list (with-temp-buffer
2097 (call-process "lpstat" nil t nil
"-a")
2098 (split-string (buffer-string) "\n"))))
2099 (loop for p in printer-list
2100 for printer
= (car (split-string p
))
2104 ;; Shut up byte compiler in emacs24*.
2105 (defun anything-c-switch-to-buffer (buffer-or-name)
2106 "Same as `switch-to-buffer' whithout warnings at compile time."
2108 (switch-to-buffer buffer-or-name
)))
2110 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
2111 "A simple and faster replacement of CL `position'."
2112 (loop for i in seq for index from
0
2113 when
(funcall test i item
) return index
))
2115 (defun anything-c-get-pid-from-process-name (process-name)
2116 "Get pid from running process PROCESS-NAME."
2117 (loop with process-list
= (list-system-processes)
2118 for pid in process-list
2119 for process
= (assoc-default 'comm
(process-attributes pid
))
2120 when
(and process
(string-match process-name process
))
2123 (defun* anything-current-buffer-narrowed-p
(&optional
2124 (buffer anything-current-buffer
))
2125 "Check if BUFFER is narrowed.
2126 Default is `anything-current-buffer'."
2127 (with-current-buffer buffer
2128 (let ((beg (point-min))
2130 (total (buffer-size)))
2131 (or (/= beg
1) (/= end
(1+ total
))))))
2133 (defun anything-region-active-p ()
2134 (and transient-mark-mode mark-active
(/= (mark) (point))))
2136 (defun anything-goto-line (lineno)
2137 "Goto LINENO opening only outline headline if needed."
2138 (goto-char (point-min)) (forward-line (1- lineno
))
2139 (when (or (eq major-mode
'org-mode
)
2140 (and (boundp 'outline-minor-mode
)
2141 outline-minor-mode
))
2142 (require 'org
) ; On some old Emacs versions org may not be loaded.
2144 (anything-match-line-color-current-line) (sit-for 0.3)
2145 (anything-match-line-cleanup))
2147 (defun anything-show-this-source-only ()
2148 "Show all candidates of this source."
2150 (setq anything-candidate-number-limit nil
)
2151 (anything-set-source-filter
2152 (list (assoc-default 'name
(anything-get-current-source)))))
2155 (defun anything-test-sources ()
2156 "List all anything sources for test.
2157 The output is sexps which are evaluated by \\[eval-last-sexp]."
2159 (with-output-to-temp-buffer "*Anything Test Sources*"
2160 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
2161 (apropos-internal "^anything-c-source" #'boundp
))
2162 (pop-to-buffer standard-output
)))
2164 (defun anything-nest (&rest same-as-anything
)
2165 "Nested `anything'. If you use `anything' within `anything', use it."
2166 (with-selected-window (anything-window)
2167 (let (anything-current-position
2168 anything-current-buffer
2169 (orig-anything-buffer anything-buffer
)
2173 anything-compiled-sources
2174 anything-buffer-chars-modified-tick
2175 (anything-samewindow t
)
2176 (enable-recursive-minibuffers t
))
2178 (apply #'anything same-as-anything
)
2179 (anything-initialize-overlays orig-anything-buffer
)
2180 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
2182 (defun anything-displaying-source-names ()
2183 "Display sources name."
2184 (with-current-buffer anything-buffer
2185 (goto-char (point-min))
2187 while
(setq pos
(next-single-property-change (point) 'anything-header
))
2189 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
2190 do
(forward-line 1))))
2193 (defun anything-select-source ()
2194 "[OBSOLETE] Select source."
2196 (let ((default (assoc-default 'name
(anything-get-current-source)))
2197 (source-names (anything-displaying-source-names))
2198 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
2199 (anything-get-sources))))
2200 (setq anything-candidate-number-limit
9999)
2202 (let (anything-source-filter)
2203 (anything-nest '(((name .
"Anything Source")
2204 (candidates . source-names
)
2205 (action . identity
))
2206 ((name .
"Anything Source (ALL)")
2207 (candidates . all-source-names
)
2208 (action . identity
)))
2210 default
"*anything select source*"))
2211 (anything-set-source-filter (list it
))
2212 (anything-set-source-filter nil
))))
2214 ;; Same as anything-set-pattern but bad written, please fix.
2215 (defun anything-insert-string (str)
2217 (delete-minibuffer-contents)
2221 (defun anything-insert-buffer-name ()
2222 "Insert buffer name."
2224 (anything-insert-string
2225 (with-anything-current-buffer
2226 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
2229 ;; This is not needed because M-n do the same thing now by default
2230 ;; See `anything-read-pattern-maybe'.
2231 ;; (defun anything-insert-symbol ()
2232 ;; "Insert current symbol."
2234 ;; (anything-insert-string
2235 ;; (with-anything-current-buffer
2237 ;; (buffer-substring (beginning-of-thing 'symbol)
2238 ;; (end-of-thing 'symbol))))))
2240 ;; Same as `anything-yank-selection' but wrong because it use
2241 ;; `anything-current-buffer' to get selection.
2242 ;; (defun anything-insert-selection ()
2243 ;; "Insert current selection."
2245 ;; (anything-insert-string
2246 ;; (with-anything-current-buffer
2247 ;; (anything-get-selection))))
2249 (defun anything-c-match-on-file-name (candidate)
2250 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2251 (string-match anything-pattern
(file-name-nondirectory candidate
)))
2253 (defun anything-c-match-on-directory-name (candidate)
2254 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2255 (anything-aif (file-name-directory candidate
)
2256 (string-match anything-pattern it
)))
2258 (defun anything-c-match-on-basename (candidate)
2259 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2260 (string-match anything-pattern
(anything-c-basename candidate
)))
2262 (defun anything-c-string-match (candidate)
2263 "Return non-nil if `anything-pattern' match CANDIDATE.
2264 The match is done with `string-match'."
2265 (string-match anything-pattern candidate
))
2267 (defun anything-c-skip-entries (list regexp
)
2268 "Remove entries which matches REGEXP from LIST."
2269 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
2272 (defun anything-c-shadow-entries (list regexp
)
2273 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2274 (mapcar (lambda (file)
2275 ;; Add shadow face property to boring files.
2276 (let ((face (if (facep 'file-name-shadow
)
2278 ;; fall back to default on XEmacs
2280 (if (string-match regexp file
)
2281 (setq file
(propertize file
'face face
))))
2285 (defsubst anything-c-stringify
(str-or-sym)
2286 "Get string of STR-OR-SYM."
2287 (if (stringp str-or-sym
)
2289 (symbol-name str-or-sym
)))
2291 (defsubst anything-c-symbolify
(str-or-sym)
2292 "Get symbol of STR-OR-SYM."
2293 (if (symbolp str-or-sym
)
2295 (intern str-or-sym
)))
2297 (defun anything-c-describe-function (func)
2298 "FUNC is symbol or string."
2299 (describe-function (anything-c-symbolify func
)))
2301 (defun anything-c-describe-variable (var)
2302 "VAR is symbol or string."
2303 (describe-variable (anything-c-symbolify var
)))
2305 (defun anything-c-find-function (func)
2306 "FUNC is symbol or string."
2307 (find-function (anything-c-symbolify func
)))
2309 (defun anything-c-find-variable (var)
2310 "VAR is symbol or string."
2311 (find-variable (anything-c-symbolify var
)))
2313 (defun anything-c-kill-new (candidate &optional replace
)
2314 "CANDIDATE is symbol or string.
2315 See `kill-new' for argument REPLACE."
2316 (kill-new (anything-c-stringify candidate
) replace
))
2318 (defun* anything-fast-remove-dups
(seq &key
(test 'eq
))
2319 "Remove duplicates elements in list SEQ.
2320 This is same as `remove-duplicates' but with memoisation.
2321 It is much faster, especially in large lists.
2322 A test function can be provided with TEST argument key.
2324 (loop with cont
= (make-hash-table :test test
)
2326 unless
(gethash elm cont
)
2327 do
(puthash elm elm cont
)
2329 (loop for i being the hash-values in cont collect i
)))
2331 (defadvice eval-defun
(after anything-source-hack activate
)
2332 "Allow immediate execution of anything source when evaling it.
2333 See `anything-c-enable-eval-defun-hack'."
2334 (when anything-c-enable-eval-defun-hack
2335 (let ((varsym (save-excursion
2336 (beginning-of-defun)
2338 (when (memq (read (current-buffer)) '(defvar setq
))
2339 (read (current-buffer))))))
2340 (when (string-match "^anything-c-source-" (symbol-name varsym
))
2341 (anything varsym
)))))
2342 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2345 ;; Move this function from anything.el and redefine here
2346 ;; to avoid an unneeded defadvice.
2347 (defun anything-quit-and-find-file ()
2348 "Drop into `anything-find-files' from `anything'.
2349 If current selection is a buffer or a file, `anything-find-files'
2350 from its directory."
2352 (anything-run-after-quit
2354 (if (file-exists-p f
)
2355 (anything-find-files-1 (file-name-directory f
)
2356 (if anything-ff-transformer-show-only-basename
2357 (anything-c-basename f
) f
))
2358 (anything-find-files-1 f
)))
2359 (anything-aif (get-buffer (anything-get-selection))
2360 (or (buffer-file-name it
)
2361 (car (rassoc it dired-buffers
))
2362 (and (with-current-buffer it
2363 (eq major-mode
'org-agenda-mode
))
2365 (expand-file-name org-directory
))
2367 (let ((sel (anything-get-selection)))
2368 (if (file-exists-p sel
)
2369 (expand-file-name sel
)
2370 default-directory
)))))
2373 (defmacro* anything-c-walk-directory
(directory &key path
(directories t
) match
)
2374 "Walk through DIRECTORY tree.
2375 PATH can be one of basename, relative, or full.
2376 DIRECTORIES when non--nil (default) return also directories names, otherwise
2377 skip directories names.
2378 MATCH match only filenames matching regexp MATCH."
2381 (basename 'file-name-nondirectory
)
2382 (relative 'file-relative-name
)
2384 (t 'file-name-nondirectory
))))
2385 (labels ((ls-R (dir)
2386 (loop with ls
= (directory-files dir t directory-files-no-dot-files-regexp
)
2388 if
(file-directory-p f
)
2389 do
(progn (when ,directories
2390 (push (funcall fn f
) result
))
2391 ;; Don't recurse in directory symlink.
2392 (unless (file-symlink-p f
)
2395 (unless (and ,match
(not (string-match ,match
(file-name-nondirectory f
))))
2396 (push (funcall fn f
) result
)))))
2398 (nreverse result
))))
2400 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2402 ;;; Anything regexp.
2405 (defvar anything-build-regexp-history nil
)
2406 (defun anything-c-query-replace-regexp (candidate)
2407 "Query replace regexp from `anything-regexp'.
2408 With a prefix arg replace only matches surrounded by word boundaries,
2409 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2410 (let ((regexp (funcall (anything-attr 'regexp
))))
2411 (apply 'query-replace-regexp
2412 (anything-c-query-replace-args regexp
))))
2414 (defun anything-c-kill-regexp-as-sexp (candidate)
2415 "Kill regexp in a format usable in lisp code."
2416 (anything-c-regexp-kill-new
2417 (prin1-to-string (funcall (anything-attr 'regexp
)))))
2419 (defun anything-c-kill-regexp (candidate)
2420 "Kill regexp as it is in `anything-pattern'."
2421 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
2423 (defun anything-c-query-replace-args (regexp)
2424 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2425 (let ((region-only (anything-region-active-p)))
2428 (query-replace-read-to regexp
2429 (format "Query replace %sregexp %s"
2430 (if anything-current-prefix-arg
"word " "")
2431 (if region-only
"in region " ""))
2433 anything-current-prefix-arg
2434 (when region-only
(region-beginning))
2435 (when region-only
(region-end)))))
2437 (defvar anything-c-source-regexp
2438 '((name .
"Regexp Builder")
2440 (anything-candidate-buffer anything-current-buffer
)))
2441 (candidates-in-buffer)
2442 (get-line . anything-c-regexp-get-line
)
2443 (persistent-action . anything-c-regexp-persistent-action
)
2444 (persistent-help .
"Show this line")
2447 (requires-pattern .
2)
2448 (mode-line .
"Press TAB to select action.")
2449 (regexp .
(lambda () anything-input
))
2450 (action .
(("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
2451 ("Query Replace Regexp (C-u Not inside word.)"
2452 . anything-c-query-replace-regexp
)
2453 ("Kill Regexp" . anything-c-kill-regexp
)))))
2455 (defun anything-c-regexp-get-line (s e
)
2459 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
2461 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
2462 collect
(format "\n %s'%s'"
2463 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
2466 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
2467 ;; It is implementation problem of candidates-in-buffer.
2471 (defun anything-c-regexp-persistent-action (pt)
2473 (anything-persistent-highlight-point))
2475 (defun anything-c-regexp-kill-new (input)
2477 (message "Killed: %s" input
))
2481 ;;; Toggle all marks.
2485 (defun anything-mark-all ()
2486 "Mark all visible unmarked candidates in current source."
2488 (with-anything-window
2490 (goto-char (anything-get-previous-header-pos))
2491 (anything-next-line)
2492 (let* ((next-head (anything-get-next-header-pos))
2495 (goto-char next-head
)
2498 (maxpoint (or end
(point-max))))
2499 (while (< (point) maxpoint
)
2500 (anything-mark-current-line)
2501 (let ((prefix (get-text-property (point-at-bol) 'display
))
2502 (bn (anything-c-basename (anything-get-selection)))
2503 (src (assoc-default 'name
(anything-get-current-source))))
2504 (when (and (not (anything-this-visible-mark))
2505 (not (or (string= prefix
"[?]")
2506 (string= prefix
"[@]"))))
2507 ;; Don't mark possibles directories ending with . or ..
2508 ;; and also autosave files/links.
2510 (and (or (anything-file-completion-source-p)
2511 (equal src
"Files from Current Directory"))
2512 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn
))
2513 (anything-make-visible-mark))))
2514 (forward-line 1) (end-of-line))))
2515 (anything-mark-current-line)
2516 (message "%s candidates marked" (length anything-marked-candidates
))))
2519 (defun anything-unmark-all ()
2520 "Unmark all candidates in all sources of current anything session."
2522 (with-anything-window
2523 (let ((len (length anything-marked-candidates
)))
2525 (anything-clear-visible-mark))
2526 (setq anything-marked-candidates nil
)
2527 (anything-mark-current-line)
2528 (message "%s candidates unmarked" len
))))
2531 (defun anything-toggle-all-marks ()
2533 Mark all visible candidates of current source or unmark all candidates
2534 visible or invisible in all sources of current anything session"
2536 (let ((marked (anything-marked-candidates)))
2537 (if (and (>= (length marked
) 1)
2538 (with-anything-window anything-visible-mark-overlays
))
2539 (anything-unmark-all)
2540 (anything-mark-all))))
2547 (defun anything-c-buffer-list ()
2548 "Return the list of names of buffers with boring buffers filtered out.
2549 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
2550 The first buffer in the list will be the last recently used
2551 buffer that is not the current buffer."
2552 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
2553 (append (cdr buffers
) (list (car buffers
)))))
2555 (defvar anything-c-source-buffers
2556 '((name .
"Buffers")
2557 (candidates . anything-c-buffer-list
)
2559 ;; (anything 'anything-c-source-buffers)
2561 (defvar anything-c-source-buffer-not-found
2562 '((name .
"Create buffer")
2564 (filtered-candidate-transformer (lambda (cands source
)
2565 (list anything-pattern
)))
2566 (action .
(lambda (candidate)
2567 (anything-c-switch-to-buffer (get-buffer-create candidate
))))))
2568 ;; (anything 'anything-c-source-buffer-not-found)
2570 ;;; Buffers-list (was buffers+)
2573 (eval-when-compile (require 'dired
))
2575 (defun anything-c-highlight-buffers (buffers)
2576 (loop for i in buffers
2577 for buf
= (get-buffer i
)
2578 for bfname
= (buffer-file-name buf
)
2580 (cond (;; A dired buffer.
2581 (rassoc buf dired-buffers
)
2582 (propertize i
'face
'anything-ff-directory
2583 'help-echo
(car (rassoc buf dired-buffers
))))
2584 ;; A buffer file modified somewhere outside of emacs.
2585 ((and bfname
(not (file-remote-p bfname
))
2586 (file-exists-p bfname
)
2587 (not (verify-visited-file-modtime buf
)))
2588 (propertize i
'face
'anything-buffer-saved-out
2590 ;; A new buffer file not already saved on disk.
2591 ((and bfname
(not (file-remote-p bfname
))
2592 (not (verify-visited-file-modtime buf
)))
2593 (propertize i
'face
'anything-buffer-not-saved
2595 ;; A Remote buffer file modified and not saved on disk.
2596 ((and bfname
(file-remote-p bfname
) (buffer-modified-p buf
))
2597 (let ((prefix (propertize
2599 (propertize "@ " 'face
'anything-ff-prefix
))))
2600 (cons (concat prefix
(propertize i
'face
'anything-ff-symlink
2601 'help-echo bfname
)) i
)))
2602 ;; A buffer file modified and not saved on disk.
2603 ((and bfname
(buffer-modified-p buf
))
2604 (propertize i
'face
'anything-ff-symlink
2606 ;; A remote buffer file not modified and saved on disk.
2607 ((and bfname
(file-remote-p bfname
))
2608 (let ((prefix (propertize
2610 (propertize "@ " 'face
'anything-ff-prefix
))))
2611 (cons (concat prefix
(propertize i
'face
'font-lock-type-face
2612 'help-echo bfname
)) i
)))
2613 ;; A buffer file not modified and saved on disk.
2615 (propertize i
'face
'font-lock-type-face
2617 ;; Any non--file buffer.
2618 (t (propertize i
'face
'italic
)))))
2621 (defvar anything-c-source-buffers-list
2622 '((name .
"Buffers")
2623 (candidates . anything-c-buffer-list
)
2625 (match anything-c-buffer-match-major-mode
)
2626 (candidate-transformer
2627 anything-c-skip-current-buffer
2628 anything-c-skip-boring-buffers
2629 anything-c-highlight-buffers
)
2630 (persistent-action . anything-c-buffers-list-persistent-action
)
2632 (mode-line . anything-buffer-mode-line-string
)
2633 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
2634 ;; (anything 'anything-c-source-buffers-list)
2636 (defun anything-c-buffer-match-major-mode (candidate)
2637 "Match maybe buffer by major-mode.
2638 If you give a major-mode or partial major-mode,
2639 it will list all buffers of this major-mode and/or buffers with name
2640 matching this major-mode.
2641 If you add a space after major-mode and then a space,
2642 it will match all buffers of the major-mode
2643 before space matching pattern after space.
2644 If you give a pattern which doesn't match a major-mode, it will search buffer
2645 with name matching pattern."
2646 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate
))
2647 (buf (get-buffer cand
)))
2649 (with-current-buffer buf
2650 (let ((mjm (symbol-name major-mode
))
2651 (split (split-string anything-pattern
)))
2652 (cond ((string-match "\\s-$" anything-pattern
)
2653 (string-match (car split
) mjm
))
2654 ((string-match "\\s-" anything-pattern
)
2655 (and (string-match (car split
) mjm
)
2656 (string-match (cadr split
) cand
)))
2657 (t (or (string-match anything-pattern mjm
)
2658 (string-match anything-pattern cand
)))))))))
2660 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag
)
2661 "Query replace in marked buffers.
2662 If REGEXP-FLAG is given use `query-replace-regexp'."
2663 (let ((fn (if regexp-flag
'query-replace-regexp
'query-replace
))
2664 (prompt (if regexp-flag
"Query replace regexp" "Query replace"))
2665 (bufs (anything-marked-candidates)))
2667 with replace
= (query-replace-read-from prompt regexp-flag
)
2668 with tostring
= (unless (consp replace
)
2669 (query-replace-read-to
2670 replace prompt regexp-flag
))
2673 (save-window-excursion
2674 (anything-c-switch-to-buffer buf
)
2676 (let ((case-fold-search t
))
2677 (goto-char (point-min))
2679 (apply fn
(list (car replace
) (cdr replace
)))
2680 (apply fn
(list replace tostring
)))))))))
2682 (defun anything-c-buffer-query-replace-regexp (candidate)
2683 (anything-c-buffer-query-replace-1 'regexp
))
2685 (defun anything-c-buffer-query-replace (candidate)
2686 (anything-c-buffer-query-replace-1))
2688 (defun anything-buffer-toggle-diff (candidate)
2689 "Toggle diff buffer CANDIDATE with it's file."
2690 (if (get-buffer-window "*Diff*")
2691 (kill-buffer "*Diff*")
2692 (diff-buffer-with-file (get-buffer candidate
))))
2695 (defun anything-buffer-diff-persistent ()
2696 "Toggle diff buffer without quitting anything."
2698 (anything-attrset 'diff-action
'anything-buffer-toggle-diff
)
2699 (anything-execute-persistent-action 'diff-action
))
2701 (defun anything-buffer-revert-and-update (candidate)
2702 (let ((marked (anything-marked-candidates)))
2703 (loop for buf in marked do
(anything-revert-buffer buf
))
2704 (anything-force-update candidate
)))
2707 (defun anything-buffer-revert-persistent ()
2708 "Revert buffer without quitting anything."
2710 (anything-attrset 'revert-action
'anything-buffer-revert-and-update
)
2711 (anything-execute-persistent-action 'revert-action
'onewindow
))
2713 (defun anything-buffer-save-and-update (candidate)
2714 (let ((marked (anything-marked-candidates))
2715 (enable-recursive-minibuffers t
))
2716 (loop for buf in marked do
2717 (with-current-buffer (get-buffer buf
)
2719 (anything-force-update candidate
)))
2722 (defun anything-buffer-save-persistent ()
2723 "Save buffer without quitting anything."
2725 (anything-attrset 'save-action
'anything-buffer-save-and-update
)
2726 (anything-execute-persistent-action 'save-action
'onewindow
))
2729 (defun anything-buffer-run-kill-buffers ()
2730 "Run kill buffer action from `anything-c-source-buffers-list'."
2732 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers
))
2735 (defun anything-buffer-run-grep ()
2736 "Run Grep action from `anything-c-source-buffers-list'."
2738 (anything-c-quit-and-execute-action 'anything-c-grep-buffers
))
2741 (defun anything-buffer-run-zgrep ()
2742 "Run Grep action from `anything-c-source-buffers-list'."
2744 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers
))
2747 (defun anything-buffer-run-query-replace-regexp ()
2748 "Run Query replace regexp action from `anything-c-source-buffers-list'."
2750 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp
))
2753 (defun anything-buffer-run-query-replace ()
2754 "Run Query replace action from `anything-c-source-buffers-list'."
2756 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace
))
2759 (defun anything-buffer-switch-other-window ()
2760 "Run switch to other window action from `anything-c-source-buffers-list'."
2762 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window
))
2765 (defun anything-buffer-switch-other-frame ()
2766 "Run switch to other frame action from `anything-c-source-buffers-list'."
2768 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame
))
2771 (defun anything-buffer-switch-to-elscreen ()
2772 "Run switch to elscreen action from `anything-c-source-buffers-list'."
2774 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen
))
2777 (defun anything-buffer-run-ediff ()
2778 "Run ediff action from `anything-c-source-buffers-list'."
2780 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers
))
2782 (defun anything-buffer-run-ediff-merge ()
2783 "Run ediff action from `anything-c-source-buffers-list'."
2785 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge
))
2787 (defun anything-c-buffers-persistent-kill (buffer)
2788 "Persistent action to kill buffer."
2789 (with-current-buffer (get-buffer buffer
)
2790 (if (and (buffer-modified-p)
2791 (buffer-file-name (current-buffer)))
2794 (kill-buffer buffer
))
2795 (kill-buffer buffer
)))
2796 (anything-delete-current-selection))
2798 (defun anything-c-buffers-list-persistent-action (candidate)
2799 (if current-prefix-arg
2800 (anything-c-buffers-persistent-kill candidate
)
2801 (anything-c-switch-to-buffer candidate
)))
2807 ;;; File name history
2808 (defvar anything-c-source-file-name-history
2809 '((name .
"File Name History")
2810 (candidates . file-name-history
)
2811 (match anything-c-match-on-basename
)
2813 ;; (anything 'anything-c-source-file-name-history)
2815 ;;; Files in current dir
2818 (defvar anything-c-source-files-in-current-dir
2819 '((name .
"Files from Current Directory")
2820 (candidates .
(lambda ()
2821 (with-anything-current-buffer
2822 (directory-files (anything-c-current-directory)))))
2823 ;; volatile is not needed, I think.
2825 ;; (anything 'anything-c-source-files-in-current-dir)
2827 (defun anything-c-highlight-files (files)
2828 (loop for i in files
2829 if
(file-directory-p i
)
2830 collect
(propertize (file-name-nondirectory i
)
2831 'face
'anything-ff-directory
2832 'help-echo
(expand-file-name i
))
2834 collect
(propertize (file-name-nondirectory i
)
2835 'face
'anything-ff-file
2836 'help-echo
(expand-file-name i
))))
2838 (defvar anything-c-source-files-in-current-dir
+
2839 '((name .
"Files from Current Directory")
2840 (candidates .
(lambda ()
2841 (with-anything-current-buffer
2842 (directory-files (anything-c-current-directory) t
))))
2843 (candidate-transformer anything-c-highlight-files
)
2844 ;; volatile is not needed, I think.
2846 ;; (anything 'anything-c-source-files-in-current-dir+)
2850 ;;; Anything-find-files - The anything files browser.
2854 (defvar anything-c-find-files-doc-header
" (`C-l': Go to precedent level)"
2855 "*The doc that is inserted in the Name header of a find-files or dired source.")
2856 (defvar anything-ff-auto-update-flag nil
2857 "Internal, flag to turn on/off auto-update in `anything-find-files'.
2858 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
2859 (defvar anything-ff-last-expanded nil
2860 "Store last expanded directory or file.")
2861 (defvar anything-ff-default-directory nil
)
2862 (defvar anything-ff-history nil
)
2863 (defvar anything-ff-cand-to-mark nil
)
2866 (defvar anything-c-source-find-files
2867 `((name .
"Find Files")
2868 (header-name .
(lambda (name)
2869 (concat name anything-c-find-files-doc-header
)))
2870 ;; It is needed for filenames with capital letters
2873 (setq anything-ff-auto-update-flag
2874 anything-ff-auto-update-initial-value
)))
2875 (candidates . anything-find-files-get-candidates
)
2876 (filtered-candidate-transformer anything-c-find-files-transformer
)
2877 (persistent-action . anything-find-files-persistent-action
)
2878 (persistent-help .
"Hit1 Expand Candidate, Hit2 or (C-u) Find file")
2879 (mode-line . anything-ff-mode-line-string
)
2881 (candidate-number-limit .
9999)
2882 (action-transformer . anything-find-files-action-transformer
)
2886 `(("Find File" . anything-c-find-file-or-marked
)
2887 ("Find file in Dired" . anything-c-point-file-in-dired
)
2888 ,(and (locate-library "elscreen")
2889 '("Find file in Elscreen" . anything-elscreen-find-file
))
2890 ,(and (locate-library "popwin")
2891 '("Find file in popup window" . popwin
:find-file
))
2892 ("Checksum File" . anything-ff-checksum
)
2893 ("Complete at point `M-tab'"
2894 . anything-c-insert-file-name-completion-at-point
)
2895 ("Open file externally `C-c C-x, C-u to choose'"
2896 . anything-c-open-file-externally
)
2897 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep
)
2898 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep
)
2899 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell
)
2900 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select
)
2901 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
2902 . anything-find-files-eshell-command-on-file
)
2903 ("Find file as root" . anything-find-file-as-root
)
2904 ("Find file in hex dump" . hexl-find-file
)
2905 ("Ediff File `C-='" . anything-find-files-ediff-files
)
2906 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files
)
2907 ("Delete File(s) `M-D'" . anything-delete-marked-files
)
2908 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy
)
2909 ("Copy file(s) Async" . anything-ff-copy-async
)
2910 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename
)
2911 ("Serial rename files" . anything-ff-serial-rename
)
2912 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink
)
2913 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying
)
2914 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink
)
2915 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink
)
2916 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink
)
2917 ("Find file other window `C-o'" . find-file-other-window
)
2918 ("Switch to history `M-p'" . anything-find-files-switch-to-hist
)
2919 ("Find file other frame `C-c C-o'" . find-file-other-frame
)
2920 ("Print File `C-c p'" . anything-ff-print
)
2921 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate
))))))
2922 ;; (anything 'anything-c-source-find-files)
2924 (defun anything-find-files-set-prompt-for-action (action files
)
2925 "Set prompt for action ACTION for FILES."
2926 (let ((len (length files
)))
2927 (format "%s *%s File(s)\n%s to: "
2929 (mapconcat (lambda (f)
2930 (format "- %s\n" f
)) files
""))))
2932 (defun anything-dwim-target-directory ()
2933 "Return value of `default-directory' of buffer in other window.
2934 If there is only one window return the value ot `default-directory'
2935 for current buffer."
2936 (with-anything-current-buffer
2937 (let ((num-windows (length (window-list))))
2938 (if (> num-windows
1)
2939 (save-selected-window
2942 (car anything-ff-history
)))))
2944 (defun anything-find-files-do-action (action)
2945 "Generic function for creating action from `anything-c-source-find-files'.
2946 ACTION must be an action supported by `anything-dired-action'."
2947 (let* ((ifiles (mapcar 'expand-file-name
; Allow modify '/foo/.' -> '/foo'
2948 (anything-marked-candidates)))
2949 (cand (anything-get-selection)) ; Target
2950 (prompt (anything-find-files-set-prompt-for-action
2951 (capitalize (symbol-name action
)) ifiles
))
2952 (parg anything-current-prefix-arg
)
2953 (dest (anything-c-read-file-name
2955 :preselect
(if anything-ff-transformer-show-only-basename
2956 (anything-c-basename cand
) cand
)
2957 :initial-input
(anything-dwim-target-directory)
2958 :history
(anything-find-files-history :comp-read nil
))))
2959 (anything-dired-action
2960 dest
:files ifiles
:action action
:follow parg
)))
2962 (defun anything-find-files-copy (candidate)
2963 "Copy files from `anything-find-files'."
2964 (anything-find-files-do-action 'copy
))
2966 (defun anything-find-files-rename (candidate)
2967 "Rename files from `anything-find-files'."
2968 (anything-find-files-do-action 'rename
))
2970 (defun anything-find-files-symlink (candidate)
2971 "Symlink files from `anything-find-files'."
2972 (anything-find-files-do-action 'symlink
))
2974 (defun anything-find-files-relsymlink (candidate)
2975 "Relsymlink files from `anything-find-files'."
2976 (anything-find-files-do-action 'relsymlink
))
2978 (defun anything-find-files-hardlink (candidate)
2979 "Hardlink files from `anything-find-files'."
2980 (anything-find-files-do-action 'hardlink
))
2982 (defun anything-find-files-byte-compile (candidate)
2983 "Byte compile elisp files from `anything-find-files'."
2984 (let ((files (anything-marked-candidates))
2985 (parg anything-current-prefix-arg
))
2986 (loop for fname in files
2987 do
(byte-compile-file fname parg
))))
2989 (defun anything-find-files-load-files (candidate)
2990 "Load elisp files from `anything-find-files'."
2991 (let ((files (anything-marked-candidates)))
2992 (loop for fname in files
2995 (defun anything-find-files-ediff-files-1 (candidate &optional merge
)
2996 "Generic function to ediff/merge files in `anything-find-files'."
2997 (let ((bname (anything-c-basename candidate
))
2998 (prompt (if merge
"Ediff Merge `%s' With File: "
2999 "Ediff `%s' With File: "))
3000 (fun (if merge
'ediff-merge-files
'ediff-files
)))
3003 (condition-case quit
3004 (anything-c-read-file-name
3005 (format prompt bname
))
3006 (quit ;; Hit C-g ask user to fallback to locate.
3007 (if (y-or-n-p "Search file for ediff with locate? ")
3008 (anything-c-locate-read-file-name
3009 (format prompt bname
)
3010 ;; Check if -b option is available.
3011 (if (and (eq system-type
'windows-nt
)
3012 (string-match "^es" anything-c-locate-command
))
3014 (concat bname
" -b")))
3015 (error "Error: Ediff Operation aborted")))))))
3017 (defun anything-find-files-ediff-files (candidate)
3018 (anything-find-files-ediff-files-1 candidate
))
3020 (defun anything-find-files-ediff-merge-files (candidate)
3021 (anything-find-files-ediff-files-1 candidate
'merge
))
3023 (defun anything-find-files-grep (candidate)
3024 "Default action to grep files from `anything-find-files'."
3025 (anything-do-grep-1 (anything-marked-candidates)
3026 anything-current-prefix-arg
))
3028 (defun anything-ff-zgrep (candidate)
3029 "Default action to zgrep files from `anything-find-files'."
3030 (let ((prefarg anything-current-prefix-arg
)
3031 (ls (anything-marked-candidates)))
3032 (anything-ff-zgrep-1 ls prefarg
)))
3034 (defun anything-ff-pdfgrep (candidate)
3035 "Default action to pdfgrep files from `anything-find-files'."
3036 (let ((cands (loop for file in
(anything-marked-candidates)
3037 if
(or (string= (file-name-extension file
) "pdf")
3038 (string= (file-name-extension file
) "PDF"))
3040 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init
))
3042 (anything-do-pdfgrep-1 cands
))))
3044 (defun anything-ff-etags-select (candidate)
3045 "Default action to jump to etags from `anything-find-files'."
3046 (when (get-buffer anything-action-buffer
)
3047 (kill-buffer anything-action-buffer
))
3048 (let ((default-directory anything-ff-default-directory
))
3049 (anything-c-etags-select anything-current-prefix-arg
)))
3051 (defun anything-find-files-switch-to-hist (candidate)
3052 "Switch to anything-find-files history."
3053 (anything-find-files t
))
3055 ;;; Asynchronous copy of files.
3058 (defun anything-c-copy-files-async-1 (flist dest
)
3059 "Copy a list of Files FLIST to DEST asynchronously.
3060 It use another emacs process to do the job.
3061 Communication with background emacs is done with temp file
3062 `anything-c-copy-files-async-log-file'."
3063 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3064 "-Q" "--batch" "--eval"
3066 (require 'dired) (require 'cl)
3067 (let ((dired-recursive-copies 'always)
3073 (let ((file-exists (file-exists-p
3075 (file-name-nondirectory (directory-file-name f))
3076 (file-name-directory
3077 (file-name-as-directory \"%s\"))))))
3078 (dired-copy-file f \"%s\" t)
3080 (progn (push (cons \"Overwriting\" f) success)
3082 (push (cons \"Copying\" f) success)
3085 (push (dired-make-relative
3087 (file-name-nondirectory (directory-file-name f))
3088 (file-name-directory \"%s\")))
3090 (with-current-buffer (find-file-noselect \"%s\")
3093 (dolist (fail (reverse failures))
3094 (insert (concat \"Failed to copy \" fail \"\n\"))))
3096 (loop for (a . s) in (reverse success) do
3097 (insert (concat a \" \" s \" to %s done\n\"))))
3098 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3099 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3100 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3102 flist dest dest dest anything-c-copy-files-async-log-file dest
)))
3104 (defun anything-c-copy-async-with-log (flist dest
)
3105 "Copy file list FLIST to DEST showing log.
3106 Log is send to `anything-c-copy-files-async-log-file'.
3107 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3108 (declare (special auto-revert-interval
))
3109 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file
))
3110 (set (make-local-variable 'auto-revert-interval
) 1)
3112 (insert "Wait copying files...\n")
3113 (sit-for 0.5) (save-buffer)
3114 (goto-char (point-max))
3115 (auto-revert-mode 1)
3116 (anything-c-copy-files-async-1 flist dest
))
3118 (defun anything-ff-copy-async (candidate)
3119 "Anything find files action to copy files async.
3120 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3121 (let* ((flist (anything-marked-candidates))
3122 (dest (anything-c-read-file-name
3123 (anything-find-files-set-prompt-for-action
3125 :preselect candidate
3126 :initial-input
(car anything-ff-history
)
3127 :history
(anything-find-files-history :comp-read nil
))))
3128 (anything-c-copy-async-with-log flist dest
)))
3130 (defvar eshell-command-aliases-list nil
)
3131 (defvar anything-eshell-command-on-file-input-history nil
)
3132 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map
)
3133 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3135 Basename of CANDIDATE can be a wild-card.
3136 If MAP is given run `eshell-command' on all marked files at once,
3137 Otherwise, run `eshell-command' on each marked files.
3139 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3140 `eshell-command-aliases-list' will not be loaded first time you use this."
3141 (when (or eshell-command-aliases-list
3142 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3143 (and eshell-command-aliases-list
(eshell-read-aliases-list))
3144 (let* ((cand-list (anything-marked-candidates))
3145 (default-directory (or anything-ff-default-directory
3146 ;; If candidate is an url *-ff-default-directory is nil
3147 ;; so keep value of default-directory.
3149 (command (anything-comp-read
3151 (loop for
(a . c
) in eshell-command-aliases-list
3152 when
(string-match "\\(\\$1\\|\\$\\*\\)$" (car c
))
3153 collect
(propertize a
'help-echo
(car c
)) into ls
3154 finally return
(sort ls
'string
<))
3155 :buffer
"*esh command on file*"
3156 :name
"Eshell command"
3158 'anything-eshell-command-on-file-input-history
))
3159 (com-value (car (assoc-default command eshell-command-aliases-list
))))
3160 (if (and (or map
(and com-value
(string-match "\\$\\*$" com-value
)))
3161 (> (length cand-list
) 1))
3162 ;; Run eshell-command with ALL marked files as arguments.
3163 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list
" ")))
3164 (eshell-command (format "%s %s" command mapfiles
)))
3165 ;; Run eshell-command on EACH marked files.
3168 for bn
= (anything-c-basename i
)
3169 for files
= (if (and bn
(string-match "^\*" bn
))
3170 ;; Assume if fname is a wildcard
3171 ;; cand-list have a length of 1.
3173 'shell-quote-argument
3174 (file-expand-wildcards i t
) " ")
3176 for com
= (if (string-match "'%s'\\|\"%s\"\\|%s" command
)
3177 ;; This allow to enter other args AFTER filename
3178 ;; i.e <command %s some_more_args>
3179 (format command files
)
3180 (format "%s %s" command files
))
3181 do
(eshell-command com
))))))
3183 (defun anything-find-files-eshell-command-on-file (candidate)
3184 "Run `eshell-command' on CANDIDATE or marked candidates.
3185 See `anything-find-files-eshell-command-on-file-1' for more info."
3186 (anything-find-files-eshell-command-on-file-1
3187 candidate anything-current-prefix-arg
))
3189 (defun anything-ff-switch-to-eshell (candidate)
3190 "Switch to eshell and cd to `anything-ff-default-directory'."
3191 (flet ((cd-eshell ()
3192 (goto-char (point-max))
3194 (format "cd '%s'" anything-ff-default-directory
))
3195 (eshell-send-input)))
3196 (if (get-buffer "*eshell*")
3198 (anything-c-switch-to-buffer "*eshell*")
3200 (call-interactively 'eshell
)
3203 (defun anything-ff-serial-rename-action (method)
3204 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3205 See `anything-ff-serial-rename-1'."
3206 (let* ((cands (anything-marked-candidates))
3207 (name (read-string "NewName: "))
3208 (start (read-number "StartAtNumber: "))
3209 (extension (read-string "Extension: " (file-name-extension (car cands
))))
3210 (dir (expand-file-name
3211 (anything-c-read-file-name
3212 "Serial Rename to directory: " :initial-input
3213 (expand-file-name anything-ff-default-directory
)))))
3214 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3215 (length cands
) dir name
))
3216 (anything-ff-serial-rename-1 dir cands name start extension
:method method
)
3217 (anything-find-files-1 dir
))))
3219 (defun anything-ff-member-directory-p (file directory
)
3220 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file
))))
3221 (cur-dir (expand-file-name (file-name-as-directory directory
))))
3222 (string= dir-file cur-dir
)))
3224 (defun* anything-ff-serial-rename-1
3225 (directory collection new-name start-at-num extension
&key
(method 'rename
))
3226 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3227 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3228 EXTENSION is the file extension to use, in empty prompt,
3229 reuse the original extension of file.
3230 METHOD can be one of rename, copy or symlink.
3231 Files will be renamed if they are files of current directory, otherwise they
3232 will be treated with METHOD.
3233 Default METHOD is rename."
3234 ;; Maybe remove directories selected by error in collection.
3235 (setq collection
(remove-if 'file-directory-p collection
))
3236 (flet ((symlink-file (file dest
)
3237 (let ((flist (list file
)))
3238 (anything-dired-action
3239 dest
:action
'symlink
:files flist
))))
3241 (let* ((tmp-dir (file-name-as-directory
3242 (concat (file-name-as-directory directory
)
3243 (symbol-name (gensym "tmp")))))
3246 (symlink 'symlink-file
)
3247 (rename 'rename-file
)
3248 (t (error "Error: Unknow method %s" method
)))))
3249 (make-directory tmp-dir
)
3250 (loop for i in collection
3251 for count from start-at-num
3252 for fnum
= (if (< count
10) "0%s" "%s")
3253 for nname
= (concat tmp-dir new-name
(format fnum count
)
3254 (if (not (string= extension
""))
3255 (format ".%s" (replace-regexp-in-string
3256 "[.]" "" extension
))
3257 (file-name-extension i
'dot
)))
3258 do
(if (anything-ff-member-directory-p i directory
)
3259 (rename-file i nname
)
3260 (funcall fn i nname
)))
3261 (loop with dirlist
= (directory-files
3262 tmp-dir t directory-files-no-dot-files-regexp
)
3264 (if (file-symlink-p f
)
3265 (symlink-file (file-truename f
)
3266 (concat (file-name-as-directory directory
)
3267 (anything-c-basename f
)))
3268 (rename-file f directory
)))
3269 (delete-directory tmp-dir t
))))
3271 (defun anything-ff-serial-rename (candidate)
3272 "Serial rename all marked files to `anything-ff-default-directory'.
3273 Rename only file of current directory, and symlink files coming from
3275 See `anything-ff-serial-rename-1'."
3276 (anything-ff-serial-rename-action 'rename
))
3278 (defun anything-ff-serial-rename-by-symlink (candidate)
3279 "Serial rename all marked files to `anything-ff-default-directory'.
3280 Rename only file of current directory, and symlink files coming from
3282 See `anything-ff-serial-rename-1'."
3283 (anything-ff-serial-rename-action 'symlink
))
3285 (defun anything-ff-serial-rename-by-copying (candidate)
3286 "Serial rename all marked files to `anything-ff-default-directory'.
3287 Rename only file of current directory, and copy files coming from
3289 See `anything-ff-serial-rename-1'."
3290 (anything-ff-serial-rename-action 'copy
))
3292 (defun anything-c-quit-and-execute-action (action)
3293 "Quit current anything session and execute ACTION."
3294 (setq anything-saved-action action
)
3295 (anything-exit-minibuffer))
3297 (defun anything-ff-toggle-auto-update (candidate)
3298 (setq anything-ff-auto-update-flag
(not anything-ff-auto-update-flag
))
3299 (message "[Auto expansion %s]"
3300 (if anything-ff-auto-update-flag
"enabled" "disabled")))
3303 (defun anything-ff-run-toggle-auto-update ()
3305 (anything-attrset 'toggle-auto-update
'anything-ff-toggle-auto-update
)
3306 (anything-execute-persistent-action 'toggle-auto-update
))
3309 (defun anything-ff-run-switch-to-history ()
3310 "Run Switch to history action from `anything-c-source-find-files'."
3312 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist
))
3315 (defun anything-ff-run-grep ()
3316 "Run Grep action from `anything-c-source-find-files'."
3318 (anything-c-quit-and-execute-action 'anything-find-files-grep
))
3321 (defun anything-ff-run-pdfgrep ()
3322 "Run Pdfgrep action from `anything-c-source-find-files'."
3324 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep
))
3327 (defun anything-ff-run-zgrep ()
3328 "Run Grep action from `anything-c-source-find-files'."
3330 (anything-c-quit-and-execute-action 'anything-ff-zgrep
))
3333 (defun anything-ff-run-copy-file ()
3334 "Run Copy file action from `anything-c-source-find-files'."
3336 (anything-c-quit-and-execute-action 'anything-find-files-copy
))
3339 (defun anything-ff-run-rename-file ()
3340 "Run Rename file action from `anything-c-source-find-files'."
3342 (anything-c-quit-and-execute-action 'anything-find-files-rename
))
3345 (defun anything-ff-run-byte-compile-file ()
3346 "Run Byte compile file action from `anything-c-source-find-files'."
3348 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile
))
3351 (defun anything-ff-run-load-file ()
3352 "Run Load file action from `anything-c-source-find-files'."
3354 (anything-c-quit-and-execute-action 'anything-find-files-load-files
))
3357 (defun anything-ff-run-eshell-command-on-file ()
3358 "Run eshell command on file action from `anything-c-source-find-files'."
3360 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file
))
3363 (defun anything-ff-run-ediff-file ()
3364 "Run Ediff file action from `anything-c-source-find-files'."
3366 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files
))
3369 (defun anything-ff-run-ediff-merge-file ()
3370 "Run Ediff merge file action from `anything-c-source-find-files'."
3372 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files
))
3375 (defun anything-ff-run-symlink-file ()
3376 "Run Symlink file action from `anything-c-source-find-files'."
3378 (anything-c-quit-and-execute-action 'anything-find-files-symlink
))
3381 (defun anything-ff-run-delete-file ()
3382 "Run Delete file action from `anything-c-source-find-files'."
3384 (anything-c-quit-and-execute-action 'anything-delete-marked-files
))
3387 (defun anything-ff-run-complete-fn-at-point ()
3388 "Run complete file name action from `anything-c-source-find-files'."
3390 (anything-c-quit-and-execute-action
3391 'anything-c-insert-file-name-completion-at-point
))
3394 (defun anything-ff-run-switch-to-eshell ()
3395 "Run switch to eshell action from `anything-c-source-find-files'."
3397 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell
))
3400 (defun anything-ff-run-switch-other-window ()
3401 "Run switch to other window action from `anything-c-source-find-files'."
3403 (anything-c-quit-and-execute-action 'find-file-other-window
))
3406 (defun anything-ff-run-switch-other-frame ()
3407 "Run switch to other frame action from `anything-c-source-find-files'."
3409 (anything-c-quit-and-execute-action 'find-file-other-frame
))
3412 (defun anything-ff-run-open-file-externally ()
3413 "Run open file externally command action from `anything-c-source-find-files'."
3415 (anything-c-quit-and-execute-action 'anything-c-open-file-externally
))
3417 (defun anything-ff-locate (candidate)
3418 "Locate action function for `anything-find-files'."
3419 (let ((input (concat (anything-c-basename
3422 anything-ff-default-directory
))
3423 ;; The locate '-b' option doesn't exists
3425 (unless (and (eq system-type
'windows-nt
)
3426 (string-match "^es" anything-c-locate-command
))
3428 (anything-mp-highlight-delay 0.7))
3429 (anything-locate-1 anything-current-prefix-arg input
)))
3432 (defun anything-ff-run-locate ()
3433 "Run locate action from `anything-c-source-find-files'."
3435 (anything-c-quit-and-execute-action 'anything-ff-locate
))
3438 (defun anything-ff-run-gnus-attach-files ()
3439 "Run gnus attach files command action from `anything-c-source-find-files'."
3441 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files
))
3444 (defun anything-ff-run-etags ()
3445 "Run Etags command action from `anything-c-source-find-files'."
3447 (anything-c-quit-and-execute-action 'anything-ff-etags-select
))
3450 (defun anything-ff-print (candidate)
3451 "Print marked files.
3452 You have to set in order
3453 variables `lpr-command',`lpr-switches' and/or `printer-name'.
3456 \(setq lpr-command \"gtklp\"\)
3457 \(setq lpr-switches '(\"-P\")\)
3458 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
3460 Same as `dired-do-print' but for anything."
3461 (unless anything-ff-printer-list
3462 (setq anything-ff-printer-list
3463 (anything-ff-find-printers)))
3464 (let* ((file-list (anything-marked-candidates))
3465 (len (length file-list
))
3466 (printer-name (if anything-ff-printer-list
3468 "Printer: " anything-ff-printer-list
)
3470 (command (read-string
3471 (format "Print *%s File(s):\n%s with: "
3474 (lambda (f) (format "- %s\n" f
))
3476 (when (and lpr-command
3479 (mapconcat 'identity
3481 (append (if (stringp lpr-switches
)
3484 (list printer-name
)))
3486 (file-args (mapconcat #'(lambda (x)
3489 (cmd-line (concat command
" " file-args
)))
3491 (start-process-shell-command "anything-print" nil cmd-line
)
3492 (error "Error: Please verify your printer settings in Emacs."))))
3495 (defun anything-ff-run-print-file ()
3496 "Run Print file action from `anything-c-source-find-files'."
3498 (anything-c-quit-and-execute-action 'anything-ff-print
))
3500 (defun anything-ff-checksum (file)
3501 "Calculate the checksum of FILE.
3502 Provide completion on different algorithms to use on Emacs24.
3503 On Emacs23 only 'sha1' is available.
3504 The checksum is copied to kill-ring."
3505 (let ((algo-list (and (fboundp 'secure-hash
)
3506 '(md5 sha1 sha224 sha256 sha384 sha512
))))
3509 (secure-hash (intern
3511 "Algorithm: " algo-list
))
3513 (sha1 (with-temp-buffer
3514 (insert-file-contents file
)
3516 (message "Checksum copied to kill-ring.")))
3518 (defun anything-ff-toggle-basename (candidate)
3519 (setq anything-ff-transformer-show-only-basename
3520 (not anything-ff-transformer-show-only-basename
))
3521 (let ((target (if anything-ff-transformer-show-only-basename
3522 (anything-c-basename candidate
) candidate
)))
3523 (anything-force-update target
)))
3525 (defun anything-ff-run-toggle-basename ()
3527 (anything-attrset 'toggle-basename
'anything-ff-toggle-basename
)
3528 (anything-execute-persistent-action 'toggle-basename
))
3530 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
3531 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
3532 If LEVEL is positive reduce from end else from beginning.
3533 If UNIX-CLOSE is non--nil close filename with /.
3534 If EXPAND is non--nil expand-file-name."
3535 (let* ((exp-fname (expand-file-name fname
))
3536 (fname-list (split-string (if (or (string= fname
"~/") expand
)
3537 exp-fname fname
) "/" t
))
3538 (len (length fname-list
))
3539 (pop-list (if (< level
0)
3540 (subseq fname-list
(* level -
1))
3541 (subseq fname-list
0 (- len level
))))
3542 (result (mapconcat 'identity pop-list
"/"))
3543 (empty (string= result
"")))
3544 (when unix-close
(setq result
(concat result
"/")))
3545 (if (string-match "^~" result
)
3546 (if (string= result
"~/") "~/" result
)
3548 (if empty
"../" (concat "../" result
))
3549 (cond ((eq system-type
'windows-nt
)
3550 (if empty
(expand-file-name "/") ; Expand to "/" or "c:/".
3554 (concat "/" result
)))))))
3557 (defvar anything-file-completion-sources
3558 '("Find Files" "Read File Name"
3559 "Read File Name History" "Copy Files"
3560 "Rename Files" "Symlink Files"
3561 "Hardlink Files" "Write File" "Insert File")
3562 "Sources that use the *find-files mechanism can be added here.
3563 Sources generated by `ac-mode' don't need to be added here, it will
3564 be done automatically.
3565 You should not modify this yourself unless you know what you do.")
3567 (defun anything-file-completion-source-p ()
3568 "Test if current source is a dired or find-files source."
3569 (let ((cur-source (cdr (assoc 'name
(anything-get-current-source)))))
3570 (loop for i in anything-file-completion-sources
3571 thereis
(string= cur-source i
))))
3573 (defun anything-find-files-down-one-level (arg)
3574 "Go down one level like unix command `cd ..'.
3575 If prefix numeric arg is given go ARG level down."
3577 (when (and (anything-file-completion-source-p)
3578 (not (anything-ff-invalid-tramp-name-p)))
3579 (with-anything-window
3580 (setq anything-follow-mode nil
))
3581 ;; When going to precedent level we want to be at the line
3582 ;; corresponding to actual directory, so store this info
3583 ;; in `anything-ff-last-expanded'.
3584 (if (and (not (file-directory-p anything-pattern
))
3585 (file-exists-p anything-pattern
))
3586 (setq anything-ff-last-expanded anything-pattern
)
3587 (setq anything-ff-last-expanded anything-ff-default-directory
))
3588 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
3589 :unix-close t
:expand t
)))
3590 (anything-set-pattern new-pattern
))))
3592 (defun anything-ff-retrieve-last-expanded ()
3593 "Move overlay to last visited directory `anything-ff-last-expanded'.
3594 This happen after using `anything-find-files-down-one-level',
3595 or hitting C-z on \"..\"."
3596 (when (and anything-ff-last-expanded
3597 (anything-file-completion-source-p))
3598 (let ((dirname (if anything-ff-transformer-show-only-basename
3599 (anything-c-basename
3600 (directory-file-name anything-ff-last-expanded
))
3601 (directory-file-name anything-ff-last-expanded
))))
3602 (with-anything-window
3603 (when (or (re-search-forward (concat dirname
"$") nil t
)
3605 (concat anything-ff-last-expanded
"$") nil t
))
3607 (anything-mark-current-line)))
3608 (setq anything-ff-last-expanded nil
))))
3609 (add-hook 'anything-after-update-hook
'anything-ff-retrieve-last-expanded
)
3611 ;; Auto-update - anything-find-files auto expansion of directories.
3613 (defun anything-ff-update-when-only-one-matched ()
3614 "Expand to directory when sole completion.
3615 When only one candidate is remaining and it is a directory,
3616 expand to this directory."
3617 (when (and anything-ff-auto-update-flag
3618 (anything-file-completion-source-p)
3619 (not (anything-ff-invalid-tramp-name-p)))
3620 (let* ((history-p (string= (assoc-default
3621 'name
(anything-get-current-source))
3622 "Read File Name History"))
3623 (pat (if (string-match tramp-file-name-regexp
3625 (anything-create-tramp-name anything-pattern
)
3627 (completed-p (string= (file-name-as-directory pat
)
3628 anything-ff-default-directory
)))
3630 ;; Only one candidate remaining
3631 ;; and at least 2 char in basename.
3632 (and (<= (anything-approximate-candidate-number) 2)
3633 (>= (length (anything-c-basename anything-pattern
)) 2))
3634 ;; Already completed.
3636 (not history-p
)) ; Don't try to auto complete in history.
3637 (with-anything-window
3638 (let ((cur-cand (prog2
3640 ;; Only one non--existing candidate
3641 ;; and one directory candidate, move to it.
3642 (anything-next-line))
3643 (anything-get-selection))))
3644 (when (file-directory-p cur-cand
)
3645 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand
)) ; [1]
3646 ;; Maybe we are here because completed-p is true
3647 ;; but check this again to be sure. (Windows fix)
3648 (<= (anything-approximate-candidate-number) 2)) ; [2]
3649 ;; If after going to next line the candidate
3650 ;; is not one of "." or ".." [1]
3651 ;; and only one candidate is remaining [2],
3652 ;; assume candidate is a new directory to expand, and do it.
3653 (anything-set-pattern (file-name-as-directory cur-cand
))
3654 ;; The candidate is one of "." or ".."
3655 ;; that mean we have entered the last letter of the directory name
3656 ;; in prompt, so expansion is already done, just add the "/" at end
3657 ;; of name unless anything-pattern ends with "."
3658 ;; (i.e we are writing something starting with ".")
3659 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern
)
3660 (anything-set-pattern
3661 ;; Need to expand-file-name to avoid e.g /ssh:host:./ in prompt.
3662 (expand-file-name (file-name-as-directory anything-pattern
)))))
3663 (anything-check-minibuffer-input-1))))))))
3664 (add-hook 'anything-after-update-hook
'anything-ff-update-when-only-one-matched
)
3666 ;; Allow expanding to home directory or root
3667 ;; when entering respectively "~/" or "//" at end of pattern.
3668 ;; e.g /home/thierry/labo/anything-config-qp/~/
3669 ;; will expand to "~/"
3670 ;; and /home/thierry/labo/anything-config-qp//
3671 ;; will expand to "/"
3672 (defun anything-ff-auto-expand-to-home-or-root ()
3673 "Goto home, root or default directory when pattern ends with ~/, /, or ./.
3674 This happen only in function using sources that are
3675 `anything-file-completion-source-p' compliant."
3676 (when (and (anything-file-completion-source-p)
3677 (string-match ".*\\(/~/\\|/\\{2\\}\\|/[.]\\{1\\}/\\)$"
3679 (let ((match (match-string 1 anything-pattern
)))
3680 (cond ((string= match
"//")
3681 ;; Expand to "/" or "c:/"
3682 (setq anything-pattern
(expand-file-name "/")))
3683 ((string= match
"/~/")
3684 (if (eq system-type
'windows-nt
)
3685 (setq anything-pattern
(file-name-as-directory (getenv "HOME")))
3686 (setq anything-pattern
"~/")))
3687 ((string= match
"/./")
3688 (setq anything-pattern
3689 (with-anything-current-buffer
3690 (expand-file-name default-directory
))))))
3691 (setq anything-ff-default-directory anything-pattern
)
3692 ;; For some reasons, i must use here with-current-buffer => mini buffer
3693 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
3694 (with-current-buffer (window-buffer (minibuffer-window))
3695 (delete-minibuffer-contents)
3696 (insert anything-pattern
))))
3698 (add-hook 'anything-after-update-hook
'anything-ff-auto-expand-to-home-or-root
)
3700 (defun anything-c-point-file-in-dired (file)
3701 "Put point on filename FILE in dired buffer."
3702 (dired (file-name-directory file
))
3703 (dired-goto-file file
))
3705 (defun anything-create-tramp-name (fname)
3706 "Build filename for `anything-pattern' like /su:: or /sudo::."
3707 (apply #'tramp-make-tramp-file-name
3708 (loop with v
= (tramp-dissect-file-name fname
)
3709 for i across v collect i
)))
3711 (defun* anything-ff-tramp-hostnames
(&optional
(pattern anything-pattern
))
3712 "Get a list of hosts for tramp method found in `anything-pattern'.
3713 Argument PATTERN default to `anything-pattern', it is here only for debugging
3715 (when (string-match tramp-file-name-regexp pattern
)
3716 (let ((method (match-string 1 pattern
))
3717 (tn (match-string 0 pattern
))
3718 (all-methods (mapcar 'car tramp-methods
)))
3720 (loop for
(f . h
) in
(tramp-get-completion-function method
)
3721 append
(loop for e in
(funcall f
(car h
))
3722 for host
= (and (consp e
) (cadr e
))
3723 when
(and host
(not (member host all-methods
)))
3724 collect
(concat tn host
)))
3727 (defun anything-ff-before-action-hook-fn ()
3728 "Exit anything when user try to execute action on an invalid tramp fname."
3729 (let ((cand (anything-get-selection)))
3730 (when (and (anything-file-completion-source-p)
3731 (anything-ff-invalid-tramp-name-p cand
) ; Check candidate.
3732 (anything-ff-invalid-tramp-name-p)) ; check anything-pattern.
3733 (error "Error: Unknow file or directory `%s'" cand
))))
3734 (add-hook 'anything-before-action-hook
'anything-ff-before-action-hook-fn
)
3736 (defun* anything-ff-invalid-tramp-name-p
(&optional
(pattern anything-pattern
))
3737 "Return non--nil when PATTERN is an invalid tramp filename."
3738 (string= (anything-ff-set-pattern pattern
)
3739 "Invalid tramp file name"))
3741 (defun anything-ff-set-pattern (pattern)
3742 "Handle tramp filenames in `anything-pattern'."
3743 (let ((methods (mapcar 'car tramp-methods
))
3744 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
3745 cur-method tramp-name
)
3746 (cond ((string= pattern
"") "")
3747 ((string-match ".*\\(~?/?[.]\\{1\\}/\\)$" pattern
)
3748 (with-anything-current-buffer
3749 (expand-file-name default-directory
)))
3750 ((string-match ".*\\(~//\\|//\\)$" pattern
)
3751 (expand-file-name "/") ; Expand to "/" or "c:/"
3753 ((string-match "^~\\|.*/~/$" pattern
)
3754 (let* ((home (expand-file-name (getenv "HOME"))))
3755 (replace-match home nil t pattern
)))
3756 ;; Match "/method:maybe_hostname:"
3757 ((and (string-match reg pattern
)
3758 (setq cur-method
(match-string 1 pattern
))
3759 (member cur-method methods
))
3760 (setq tramp-name
(anything-create-tramp-name
3761 (match-string 0 pattern
)))
3762 (replace-match tramp-name nil t pattern
))
3763 ;; Match "/hostname:"
3764 ((and (string-match tramp-file-name-regexp pattern
)
3765 (setq cur-method
(match-string 1 pattern
))
3766 (and cur-method
(not (member cur-method methods
))))
3767 (setq tramp-name
(anything-create-tramp-name
3768 (match-string 0 pattern
)))
3769 (replace-match tramp-name nil t pattern
))
3770 ;; Match "/method:" in this case don't try to connect.
3771 ((and (not (string-match reg pattern
))
3772 (string-match tramp-file-name-regexp pattern
)
3773 (member (match-string 1 pattern
) methods
))
3774 "Invalid tramp file name") ; Write in anything-buffer.
3775 ;; PATTERN is a directory, end it with "/".
3776 ;; This will make PATTERN not ending yet with "/"
3777 ;; candidate for `anything-ff-default-directory',
3778 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
3779 ;; when descending level.
3780 ((file-directory-p pattern
)
3781 (file-name-as-directory pattern
))
3782 ;; Return PATTERN unchanged.
3785 (defun anything-find-files-get-candidates ()
3786 "Create candidate list for `anything-c-source-find-files'."
3787 (let* ((path (anything-ff-set-pattern anything-pattern
))
3788 (path-name-dir (if (file-directory-p path
)
3789 (file-name-as-directory path
)
3790 (file-name-directory path
)))
3791 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
3792 (set-text-properties 0 (length path
) nil path
)
3793 ;; Don't set now `anything-pattern' if `path' == "Invalid tramp file name"
3794 ;; like that the actual value (e.g /ssh:) is passed to
3795 ;; `anything-ff-tramp-hostnames'.
3796 (unless (string= path
"Invalid tramp file name")
3797 (setq anything-pattern
(anything-ff-transform-fname-for-completion path
)))
3798 (setq anything-ff-default-directory
3799 (if (string= anything-pattern
"")
3800 (expand-file-name "/") ; Expand to "/" or "c:/"
3801 (unless (string-match ffap-url-regexp path
)
3802 ;; If path is an url *default-directory have to be nil.
3804 (cond ((string= path
"Invalid tramp file name")
3805 (or (anything-ff-tramp-hostnames) ; Hostnames completion.
3807 ;; `anything-pattern' have not been modified yet.
3808 ;; Set it here to the value of `path' that should be now
3809 ;; "Invalid tramp file name" and set the candidates list
3810 ;; to ("Invalid tramp file name") to make `anything-pattern'
3811 ;; match single candidate "Invalid tramp file name".
3812 (setq anything-pattern path
)
3813 ;; "Invalid tramp file name" is now printed
3814 ;; in `anything-buffer'.
3816 ((or (file-regular-p path
)
3817 (and (not (file-exists-p path
)) (string-match "/$" path
))
3818 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
3820 ((string= path
"") (anything-ff-directory-files "/" t
))
3821 ((and (file-directory-p path
) (not (file-readable-p path
)))
3822 (list (format "Opening directory: access denied, `%s'" path
)))
3823 ((file-directory-p path
) (anything-ff-directory-files path t
))
3825 (append (list path
) (anything-ff-directory-files path-name-dir t
))))))
3827 (defun anything-ff-directory-files (directory &optional full
)
3828 "List contents of DIRECTORY.
3829 Argument FULL mean absolute path.
3830 It is same as `directory-files' but always returns the
3831 dotted filename '.' and '..' on root directories on Windows
3833 (setq directory
(expand-file-name directory
))
3834 (if (string-match "^[a-zA-Z]\\{1\\}:/$" directory
)
3835 (let* ((dot (concat directory
"."))
3836 (dot2 (concat directory
".."))
3841 (directory-files directory full
)))))
3842 (append (list dot dot2
) lsdir
))
3843 (directory-files directory full
)))
3845 (defun anything-ff-transform-fname-for-completion (fname)
3846 "Return FNAME with it's basename modified as a regexp.
3847 e.g foo => f.*o.*o .
3848 If basename contain one or more space or FNAME is a valid directory name
3849 return FNAME unchanged."
3850 (let ((bn (anything-c-basename fname
)))
3851 (if (or (not anything-ff-smart-completion
)
3852 (string-match "\\s-" bn
)
3853 (string-match "/$" fname
) ; Allow mkdir.
3854 (file-directory-p fname
))
3855 fname
; Fall back to match-plugin.
3856 (setq bn
(if (> (length bn
) 2) ; Normal completion on first 2 char.
3857 (mapconcat 'identity
(split-string bn
"" t
) ".*") bn
))
3858 (concat (file-name-directory fname
) bn
))))
3860 (defun anything-ff-save-history ()
3861 "Store the last value of `anything-ff-default-directory' \
3862 in `anything-ff-history'."
3863 (when (and anything-ff-default-directory
3864 (anything-file-completion-source-p))
3865 (push anything-ff-default-directory anything-ff-history
)))
3866 (add-hook 'anything-cleanup-hook
'anything-ff-save-history
)
3868 (defun anything-ff-valid-symlink-p (file)
3869 (file-exists-p (file-truename file
)))
3871 (defun anything-ff-properties (candidate)
3872 "Show file properties of CANDIDATE in a tooltip or message."
3873 (let ((type (anything-ff-attributes candidate
:type t
))
3874 (dired-line (anything-ff-attributes candidate
:dired t
:human-size t
)))
3878 (anything-c-basename candidate
) ": \n"
3880 (when (string= type
"symlink")
3881 (format "True name: '%s'\n"
3882 (cond ((string-match "^\.#" (anything-c-basename candidate
))
3884 ((anything-ff-valid-symlink-p candidate
)
3885 (file-truename candidate
))
3886 (t "Invalid Symlink"))))
3888 (message dired-line
) (sit-for 5))))
3891 (defun anything-ff-properties-persistent ()
3892 "Show properties without quitting anything."
3894 (anything-attrset 'properties-action
'anything-ff-properties
)
3895 (anything-execute-persistent-action 'properties-action
))
3898 (defun anything-ff-persistent-delete ()
3899 "Delete current candidate without quitting."
3901 (anything-attrset 'quick-delete
'anything-ff-quick-delete
)
3902 (anything-execute-persistent-action 'quick-delete
))
3904 (defun anything-ff-dot-file-p (file)
3905 "Check if FILE is `.' or `..'."
3906 (member (anything-c-basename file
) '("." "..")))
3908 (defun anything-ff-quick-delete (candidate)
3909 "Delete file CANDIDATE without quitting."
3910 (if (and anything-ff-signal-error-on-dot-files
3911 (anything-ff-dot-file-p candidate
))
3912 (message "Error: Cannot operate on `.' or `..'")
3913 (let ((presel (prog1 (save-excursion
3915 (anything-next-line)
3916 (setq sel
(anything-get-selection))
3917 (if (string= sel candidate
)
3918 (progn (anything-previous-line)
3919 (anything-get-selection))
3921 (anything-mark-current-line))))
3922 (setq presel
(if (and anything-ff-transformer-show-only-basename
3923 (not (anything-ff-dot-file-p presel
)))
3924 (anything-c-basename presel
) presel
))
3925 (if anything-ff-quick-delete-dont-prompt-for-deletion
3926 (anything-c-delete-file candidate
)
3927 (save-selected-window
3928 (when (y-or-n-p (format "Really Delete file `%s'? " candidate
))
3929 (anything-c-delete-file candidate
))))
3930 (anything-force-update presel
))))
3932 (defun anything-ff-kill-buffer-fname (candidate)
3933 (let* ((buf (get-file-buffer candidate
))
3934 (buf-name (buffer-name buf
)))
3937 (kill-buffer buf
) (message "Buffer `%s' killed" buf
))
3938 (message "No buffer to kill"))))
3940 (defun anything-ff-kill-or-find-buffer-fname (candidate)
3941 "Find file CANDIDATE or kill it's buffer if it is visible.
3942 Never kill `anything-current-buffer'.
3943 Never kill buffer modified.
3944 This is called normally on third hit of \
3945 \\<anything-map>\\[anything-execute-persistent-action]
3946 in `anything-find-files-persistent-action'."
3947 (let* ((buf (get-file-buffer candidate
))
3948 (buf-name (buffer-name buf
)))
3949 (if (and buf
(get-buffer-window buf
)
3950 (not (eq buf
(get-buffer anything-current-buffer
)))
3951 (not (buffer-modified-p buf
)))
3953 (kill-buffer buf
) (message "Buffer `%s' killed" buf-name
))
3954 (find-file candidate
))))
3957 (defun anything-ff-run-kill-buffer-persistent ()
3958 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
3960 (anything-attrset 'kill-buffer-fname
'anything-ff-kill-buffer-fname
)
3961 (anything-execute-persistent-action 'kill-buffer-fname
))
3963 (defun anything-ff-human-size (size)
3964 "Return a string showing SIZE of a file in human readable form.
3965 SIZE can be an integer or a float depending it's value.
3966 `file-attributes' will take care of that to avoid overflow error.
3967 KBSIZE if a floating point number, default value is 1024.0."
3968 (let ((M (cons "M" (/ size
(expt anything-ff-default-kbsize
2))))
3969 (G (cons "G" (/ size
(expt anything-ff-default-kbsize
3))))
3970 (K (cons "K" (/ size anything-ff-default-kbsize
)))
3971 (B (cons "B" size
)))
3972 (loop with result
= B
3974 (loop for
(x . y
) in
(list M G K B
)
3975 unless
(< y
1) collect
(cons x y
))
3976 when
(< b
(cdr result
)) do
(setq result
(cons a b
))
3977 finally return
(if (string= (car result
) "B")
3979 (format "%.1f%s" (cdr result
) (car result
))))))
3981 (defun* anything-ff-attributes
3982 (file &key type links uid gid access-time modif-time
3983 status size mode gid-change inode device-num dired human-size
)
3984 "Easy interface for `file-attributes'."
3985 (let ((all (destructuring-bind
3986 (type links uid gid access-time modif-time
3987 status size mode gid-change inode device-num
)
3988 (file-attributes file
'string
)
3993 :access-time access-time
3994 :modif-time modif-time
3998 :gid-change gid-change
4000 :device-num device-num
))))
4002 (let ((result (getf all
:type
)))
4003 (cond ((stringp result
)
4005 (result "directory")
4007 (links (getf all
:links
))
4008 (uid (getf all
:uid
))
4009 (gid (getf all
:gid
))
4011 (format-time-string "%Y-%m-%d %R" (getf all
:access-time
)))
4013 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
)))
4015 (format-time-string "%Y-%m-%d %R" (getf all
:status
)))
4016 (size (if human-size
(anything-ff-human-size (getf all
:size
))
4018 (mode (getf all
:mode
))
4019 (gid-change (getf all
:gid-change
))
4020 (inode (getf all
:inode
))
4021 (device-num (getf all
:device-num
))
4024 (getf all
:mode
) " "
4025 (number-to-string (getf all
:links
)) " "
4028 (if human-size
(anything-ff-human-size (getf all
:size
))
4029 (int-to-string (getf all
:size
))) " "
4030 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
))))
4033 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file
)
4034 "Return filename FNAME maybe prefixed with [?] or [@].
4035 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
4036 existing filename or valid symlink and there is no need to test it.
4037 NEW-FILE when non--nil mean FNAME is a non existing file and
4038 return FNAME prefixed with [?]."
4039 (let* ((prefix-new (propertize
4041 (propertize "[?]" 'face
'anything-ff-prefix
)))
4042 (prefix-url (propertize
4044 (propertize "[@]" 'face
'anything-ff-prefix
))))
4045 (cond ((or file-or-symlinkp
(file-exists-p fname
)) fname
)
4046 ((string-match ffap-url-regexp fname
)
4047 (concat prefix-url
" " fname
))
4048 ((or new-file
(not (file-exists-p fname
)))
4049 (concat prefix-new
" " fname
)))))
4051 (defun anything-c-find-files-transformer (files sources
)
4052 "Transformer for `anything-c-source-find-files'.
4053 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
4055 (if (and (string-match tramp-file-name-regexp anything-pattern
)
4056 anything-ff-tramp-not-fancy
)
4057 (if anything-ff-transformer-show-only-basename
4058 (loop for i in files collect
4059 (if (string-match "[.]\\{1,2\\}$" i
)
4060 i
(cons (anything-c-basename i
) i
)))
4062 (anything-ff-highlight-files files sources
)))
4064 (defun anything-ff-highlight-files (files sources
)
4065 "Candidate transformer for `anything-c-source-find-files' without icons."
4066 (loop for i in files
4067 for disp
= (if (and anything-ff-transformer-show-only-basename
4068 (not (string-match "[.]\\{1,2\\}$" i
))
4069 (not (string-match ffap-url-regexp i
)))
4070 (anything-c-basename i
) i
)
4072 (cond ((and (stringp (car (file-attributes i
)))
4073 (not (anything-ff-valid-symlink-p i
))
4074 (not (string-match "^\.#" (anything-c-basename i
))))
4075 (cons (anything-ff-prefix-filename
4076 (propertize disp
'face
'anything-ff-invalid-symlink
) t
)
4078 ((stringp (car (file-attributes i
)))
4079 (cons (anything-ff-prefix-filename
4080 (propertize disp
'face
'anything-ff-symlink
) t
)
4082 ((eq t
(car (file-attributes i
)))
4083 (cons (anything-ff-prefix-filename
4084 (propertize disp
'face
'anything-ff-directory
) t
)
4086 ((file-executable-p i
)
4087 (cons (anything-ff-prefix-filename
4088 (propertize disp
'face
'anything-ff-executable
) t
)
4091 (cons (anything-ff-prefix-filename
4092 (propertize disp
'face
'anything-ff-file
) t
)
4095 (cons (anything-ff-prefix-filename
4096 (propertize disp
'face
'anything-ff-file
) nil
'new-file
)
4099 (defun anything-find-files-action-transformer (actions candidate
)
4100 "Action transformer for `anything-c-source-find-files'."
4101 (cond ((with-anything-current-buffer
4102 (eq major-mode
'message-mode
))
4103 (append (subseq actions
0 4)
4104 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files
))
4105 (subseq actions
4)))
4106 ((string-match (image-file-name-regexp) candidate
)
4107 (append (subseq actions
0 4)
4108 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right
)
4109 ("Rotate image left `M-l'" . anything-ff-rotate-image-left
))
4110 (subseq actions
4)))
4111 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4112 (car it
) candidate
))
4113 (append (subseq actions
0 4)
4114 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4115 . anything-find-files-byte-compile
)
4116 ("Load File(s) `M-L'" . anything-find-files-load-files
))
4117 (subseq actions
4)))
4118 ((and (string-match "\.html?$" candidate
)
4119 (file-exists-p candidate
))
4120 (append (subseq actions
0 4)
4121 '(("Browse url file" . browse-url-of-file
))
4122 (subseq actions
5)))
4123 ((or (string= (file-name-extension candidate
) "pdf")
4124 (string= (file-name-extension candidate
) "PDF"))
4125 (append (subseq actions
0 4)
4126 '(("Pdfgrep File(s)" . anything-ff-pdfgrep
))
4127 (subseq actions
5)))
4130 (defun anything-ff-gnus-attach-files (candidate)
4131 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4132 (let ((flist (anything-marked-candidates)))
4133 (gnus-dired-attach flist
)))
4135 (defun anything-ff-rotate-current-image-1 (file &optional num-arg
)
4136 "Rotate current image at NUM-ARG degrees.
4137 This is a destructive operation on FILE made by external tool mogrify."
4138 (declare (special image-dired-display-image-buffer
))
4139 (setq file
(file-truename file
)) ; For symlinked images.
4140 ;; When FILE is not an image-file, do nothing.
4141 (when (string-match (image-file-name-regexp) file
)
4142 (if (executable-find "mogrify")
4144 (shell-command (format "mogrify -rotate %s %s"
4146 (shell-quote-argument file
)))
4147 (when (buffer-live-p image-dired-display-image-buffer
)
4148 (kill-buffer image-dired-display-image-buffer
))
4149 (image-dired-display-image file
)
4151 (display-buffer (get-buffer image-dired-display-image-buffer
)))
4152 (error "mogrify not found"))))
4154 (defun anything-ff-rotate-image-left (candidate)
4155 "Rotate image file CANDIDATE left.
4156 This affect directly file CANDIDATE."
4157 (anything-ff-rotate-current-image-1 candidate -
90))
4159 (defun anything-ff-rotate-image-right (candidate)
4160 "Rotate image file CANDIDATE right.
4161 This affect directly file CANDIDATE."
4162 (anything-ff-rotate-current-image-1 candidate
))
4164 (defun anything-ff-rotate-left-persistent ()
4165 "Rotate image left without quitting anything."
4167 (anything-attrset 'image-action1
'anything-ff-rotate-image-left
)
4168 (anything-execute-persistent-action 'image-action1
))
4170 (defun anything-ff-rotate-right-persistent ()
4171 "Rotate image right without quitting anything."
4173 (anything-attrset 'image-action2
'anything-ff-rotate-image-right
)
4174 (anything-execute-persistent-action 'image-action2
))
4176 (defun anything-ff-exif-data (candidate)
4177 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4178 (if (and anything-ff-exif-data-program
4179 (executable-find anything-ff-exif-data-program
))
4180 (shell-command-to-string (format "%s %s %s"
4181 anything-ff-exif-data-program
4182 anything-ff-exif-data-program-args
4184 (format "No program %s found to extract exif"
4185 anything-ff-exif-data-program
)))
4187 (defun anything-find-files-persistent-action (candidate)
4188 "Open subtree CANDIDATE without quitting anything.
4189 If CANDIDATE is not a directory expand CANDIDATE filename.
4190 If CANDIDATE is alone, open file CANDIDATE filename.
4192 First hit on C-z expand CANDIDATE second hit open file.
4193 If a prefix arg is given or `anything-follow-mode' is on open file."
4194 (let ((follow (buffer-local-value
4195 'anything-follow-mode
4196 (get-buffer-create anything-buffer
)))
4197 (new-pattern (anything-get-selection))
4198 (num-lines-buf (with-current-buffer anything-buffer
4199 (count-lines (point-min) (point-max)))))
4200 (flet ((insert-in-minibuffer (fname)
4201 (with-selected-window (minibuffer-window)
4203 (delete-minibuffer-contents)
4204 (set-text-properties 0 (length fname
) nil fname
)
4206 (cond ((and (string= (anything-ff-set-pattern anything-pattern
)
4207 "Invalid tramp file name")
4208 (string-match tramp-file-name-regexp candidate
))
4209 ;; First hit insert hostname and
4210 ;; second hit insert ":" and expand.
4211 (if (string= candidate anything-pattern
)
4212 (insert-in-minibuffer (concat candidate
":"))
4213 (insert-in-minibuffer candidate
)))
4214 (;; A symlink directory, expand it's truename.
4215 (and (file-directory-p candidate
) (file-symlink-p candidate
))
4216 (insert-in-minibuffer (file-name-as-directory
4218 (expand-file-name candidate
)))))
4219 ;; A directory, open it.
4220 ((file-directory-p candidate
)
4221 (when (string= (anything-c-basename candidate
) "..")
4222 (setq anything-ff-last-expanded anything-ff-default-directory
))
4223 (insert-in-minibuffer (file-name-as-directory
4224 (expand-file-name candidate
))))
4225 ;; A symlink file, expand to it's true name. (first hit)
4226 ((and (file-symlink-p candidate
) (not current-prefix-arg
) (not follow
))
4227 (insert-in-minibuffer (file-truename candidate
)))
4228 ;; A regular file, expand it, (first hit)
4229 ((and (>= num-lines-buf
3) (not current-prefix-arg
) (not follow
))
4230 (insert-in-minibuffer new-pattern
))
4231 ;; An image file and it is the second hit on C-z,
4232 ;; show the file in `image-dired'.
4233 ((string-match (image-file-name-regexp) candidate
)
4234 (when (buffer-live-p image-dired-display-image-buffer
)
4235 (kill-buffer image-dired-display-image-buffer
))
4236 (image-dired-display-image candidate
)
4238 (anything-c-switch-to-buffer image-dired-display-image-buffer
)
4239 (with-current-buffer image-dired-display-image-buffer
4240 (let ((exif-data (anything-ff-exif-data candidate
)))
4241 (image-dired-update-property 'help-echo exif-data
))))
4242 ;; Allow browsing archive on avfs fs.
4243 ;; Assume volume is already mounted with mountavfs.
4244 ((and anything-ff-avfs-directory
4246 (regexp-quote (expand-file-name anything-ff-avfs-directory
))
4247 (file-name-directory candidate
))
4248 (anything-ff-file-compressed-p candidate
))
4249 (insert-in-minibuffer (concat candidate
"#")))
4250 ;; On second hit we open file.
4251 ;; On Third hit we kill it's buffer maybe.
4253 (anything-ff-kill-or-find-buffer-fname candidate
))))))
4255 (defun anything-ff-file-compressed-p (candidate)
4256 "Whether CANDIDATE is a compressed file or not."
4257 (member (file-name-extension candidate
)
4258 anything-ff-file-compressed-list
))
4260 (defun anything-c-insert-file-name-completion-at-point (candidate)
4261 "Insert file name completion at point."
4262 (with-anything-current-buffer
4263 (if buffer-read-only
4264 (error "Error: Buffer `%s' is read-only" (buffer-name))
4265 (let* ((end (point))
4266 (guess (substring-no-properties (thing-at-point 'filename
)))
4267 (beg (- (point) (length guess
)))
4268 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess
)
4269 (string-match-p "^[^\~]" guess
))))
4270 (set-text-properties 0 (length candidate
) nil candidate
)
4271 (if (and guess
(not (string= guess
""))
4272 (string-match-p "^~\\|/.*" guess
))
4274 (delete-region beg end
)
4275 (insert (if full-path-p
4276 (expand-file-name candidate
)
4277 (abbreviate-file-name candidate
))))
4278 (error "Aborting completion: No valid file name at point"))))))
4280 (defun* anything-find-files-history
(&key
(comp-read t
))
4281 "The `anything-find-files' history.
4282 Show the first `anything-ff-history-max-length' elements of
4283 `anything-ff-history' in an `anything-comp-read'."
4284 (let ((history (when anything-ff-history
4285 (anything-fast-remove-dups anything-ff-history
4288 (setq anything-ff-history
4289 (if (>= (length history
) anything-ff-history-max-length
)
4290 (subseq history
0 anything-ff-history-max-length
)
4294 "Switch to Directory: "
4296 :name
"Anything Find Files History"
4298 anything-ff-history
))))
4300 (defun anything-find-files-1 (fname &optional preselect
)
4301 "Find FNAME with `anything' completion.
4302 Like `find-file' but with `anything' support.
4303 Use it for non--interactive calls of `anything-find-files'."
4304 (when (get-buffer anything-action-buffer
)
4305 (kill-buffer anything-action-buffer
))
4306 (let ((anything-mp-highlight-delay nil
)
4307 ;; Be sure we don't erase the precedent minibuffer if some.
4308 (anything-ff-auto-update-initial-value
4309 (not (minibuffer-window-active-p (minibuffer-window))))
4310 anything-samewindow
)
4311 (anything :sources
'anything-c-source-find-files
4313 :preselect preselect
4314 :keymap anything-find-files-map
4315 :prompt
"Find Files or Url: "
4316 :buffer
"*Anything Find Files*")))
4319 (defun anything-find-files-initial-input (&optional input
)
4320 "Return INPUT if present, otherwise try to guess it."
4321 (or (and input
(expand-file-name input
))
4322 (anything-find-files-input
4324 (thing-at-point 'filename
))))
4326 (defun anything-find-files-input (fap tap
)
4327 "Default input of `anything-find-files'."
4328 (let* ((def-dir (anything-c-current-directory))
4329 (lib (anything-find-library-at-point))
4330 (url (anything-ff-find-url-at-point))
4331 (file-p (and fap
(not (string= fap
""))
4333 tap
(not (string= tap
""))
4335 (file-name-directory (expand-file-name tap def-dir
))))))
4336 (cond (lib) ; e.g we are inside a require sexp.
4337 (url) ; String at point is an hyperlink.
4338 (file-p (expand-file-name tap def-dir
))
4339 (t (and (not (string= fap
"")) fap
)))))
4341 (defun anything-c-current-directory ()
4342 "Return current-directory name at point.
4343 Useful in dired buffers when there is inserted subdirs."
4344 (if (eq major-mode
'dired-mode
)
4345 (dired-current-directory)
4348 (defun anything-ff-find-url-at-point ()
4349 "Try to find link to an url in text-property at point."
4350 (let* ((he (get-text-property (point) 'help-echo
))
4351 (ov (overlays-at (point)))
4352 (ov-he (and ov
(overlay-get
4353 (car (overlays-at (point))) 'help-echo
)))
4354 (w3m-l (get-text-property (point) 'w3m-href-anchor
))
4355 (nt-prop (get-text-property (point) 'nt-link
)))
4357 (when (and (stringp he
) (string-match "^LINK: " he
))
4358 (setq he
(replace-match "" t t he
)))
4359 (loop for i in
(list he ov-he w3m-l nt-prop
)
4360 thereis
(and (stringp i
) (string-match ffap-url-regexp i
) i
))))
4362 (defun anything-find-library-at-point ()
4363 "Try to find library path at point.
4364 Find inside `require' and `declare-function' sexp."
4365 (require 'find-func
)
4366 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
4367 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
4368 (sexp (and beg-sexp end-sexp
4369 (buffer-substring-no-properties
4370 (1+ beg-sexp
) (1- end-sexp
)))))
4372 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
4374 (replace-regexp-in-string
4376 ;; If require use third arg, ignore it,
4377 ;; always use library path found in `load-path'.
4378 (second (split-string (match-string 0 sexp
))))))
4379 ((and sexp
(string-match-p "^declare-function" sexp
))
4381 (replace-regexp-in-string
4383 (third (split-string sexp
)))))
4386 ;;; Anything completion for `write-file'.==> C-x C-w
4387 (defvar anything-c-source-write-file
4388 `((name .
"Write File")
4389 (header-name .
(lambda (name)
4390 (concat name anything-c-find-files-doc-header
)))
4391 ;; It is needed for filenames with capital letters
4393 (candidates . anything-find-files-get-candidates
)
4394 (filtered-candidate-transformer anything-c-find-files-transformer
)
4395 (persistent-action . anything-find-files-persistent-action
)
4396 (persistent-help .
"Expand Candidate")
4399 (("Write File" .
(lambda (candidate)
4400 (write-file candidate
'confirm
)))))))
4402 ;;; Anything completion for `insert-file'.==> C-x i
4403 (defvar anything-c-source-insert-file
4404 `((name .
"Insert File")
4405 (header-name .
(lambda (name)
4406 (concat name anything-c-find-files-doc-header
)))
4407 ;; It is needed for filenames with capital letters
4409 (candidates . anything-find-files-get-candidates
)
4410 (filtered-candidate-transformer anything-c-find-files-transformer
)
4411 (persistent-action . anything-find-files-persistent-action
)
4412 (persistent-help .
"Expand Candidate")
4415 (("Insert File" .
(lambda (candidate)
4416 (when (y-or-n-p (format "Really insert %s in %s "
4417 candidate anything-current-buffer
))
4418 (insert-file-contents candidate
))))))))
4420 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4421 (defvar anything-c-source-copy-files
4422 `((name .
"Copy Files")
4423 (header-name .
(lambda (name)
4424 (concat name anything-c-find-files-doc-header
)))
4425 ;; It is needed for filenames with capital letters
4427 (candidates . anything-find-files-get-candidates
)
4428 (filtered-candidate-transformer anything-c-find-files-transformer
)
4429 (persistent-action . anything-find-files-persistent-action
)
4430 (persistent-help .
"Expand Candidate")
4434 .
(lambda (candidate)
4435 (anything-dired-action candidate
:action
'copy
)))
4437 .
(lambda (candidate)
4438 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
4441 (defvar anything-c-source-rename-files
4442 `((name .
"Rename Files")
4443 (header-name .
(lambda (name)
4444 (concat name anything-c-find-files-doc-header
)))
4445 ;; It is needed for filenames with capital letters
4447 (candidates . anything-find-files-get-candidates
)
4448 (filtered-candidate-transformer anything-c-find-files-transformer
)
4449 (persistent-action . anything-find-files-persistent-action
)
4450 (persistent-help .
"Expand Candidate")
4454 .
(lambda (candidate)
4455 (anything-dired-action candidate
:action
'rename
)))
4456 ("Rename and Follow"
4457 .
(lambda (candidate)
4458 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
4460 (defvar anything-c-source-symlink-files
4461 `((name .
"Symlink Files")
4462 (header-name .
(lambda (name)
4463 (concat name anything-c-find-files-doc-header
)))
4464 ;; It is needed for filenames with capital letters
4466 (candidates . anything-find-files-get-candidates
)
4467 (filtered-candidate-transformer anything-c-find-files-transformer
)
4468 (persistent-action . anything-find-files-persistent-action
)
4469 (persistent-help .
"Expand Candidate")
4473 .
(lambda (candidate)
4474 (anything-dired-action candidate
:action
'symlink
)))
4476 .
(lambda (candidate)
4477 (anything-dired-action candidate
:action
'relsymlink
)))))))
4480 (defvar anything-c-source-hardlink-files
4481 `((name .
"Hardlink Files")
4482 (header-name .
(lambda (name)
4483 (concat name anything-c-find-files-doc-header
)))
4484 ;; It is needed for filenames with capital letters
4486 (candidates . anything-find-files-get-candidates
)
4487 (filtered-candidate-transformer anything-c-find-files-transformer
)
4488 (persistent-action . anything-find-files-persistent-action
)
4489 (persistent-help .
"Expand Candidate")
4493 .
(lambda (candidate)
4494 (anything-dired-action candidate
:action
'hardlink
)))))))
4496 (defun* anything-dired-action
(candidate &key action follow
(files (dired-get-marked-files)))
4497 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4498 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4499 (when (get-buffer dired-log-buffer
) (kill-buffer dired-log-buffer
))
4500 (let ((fn (case action
4501 ('copy
'dired-copy-file
)
4502 ('rename
'dired-rename-file
)
4503 ('symlink
'make-symbolic-link
)
4504 ('relsymlink
'dired-make-relative-symlink
)
4505 ('hardlink
'dired-hardlink
)))
4506 (marker (case action
4507 ((copy rename
) dired-keep-marker-copy
)
4508 ('symlink dired-keep-marker-symlink
)
4509 ('relsymlink dired-keep-marker-relsymlink
)
4510 ('hardlink dired-keep-marker-hardlink
)))
4511 (dirflag (and (= (length files
) 1)
4512 (file-directory-p (car files
))
4513 (not (file-directory-p candidate
)))))
4515 fn
(symbol-name action
) files
4516 ;; CANDIDATE is the destination.
4517 (if (file-directory-p candidate
)
4518 ;; When CANDIDATE is a directory, build file-name in this directory.
4519 ;; Else we use CANDIDATE.
4521 (expand-file-name (file-name-nondirectory from
) candidate
))
4522 #'(lambda (from) candidate
))
4524 (push (file-name-as-directory
4525 (if (file-directory-p candidate
)
4526 candidate
(file-name-directory candidate
)))
4527 anything-ff-history
)
4528 (when (and follow
(not (get-buffer dired-log-buffer
)))
4529 (let ((target (directory-file-name candidate
)))
4532 (setq anything-ff-cand-to-mark
4533 (anything-get-dest-fnames-from-list files candidate dirflag
))
4534 (if (and dirflag
(eq action
'rename
))
4535 (anything-find-files-1 (file-name-directory target
)
4536 (if anything-ff-transformer-show-only-basename
4537 (anything-c-basename target
) target
))
4538 (anything-find-files-1 (expand-file-name candidate
))))
4539 (setq anything-ff-cand-to-mark nil
))))))
4542 (defun anything-c-basename (fname)
4543 "Resolve basename of file or directory named FNAME."
4544 (file-name-nondirectory (directory-file-name fname
)))
4546 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag
)
4547 "Transform filenames of FLIST to abs of DEST-CAND.
4548 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4550 ;; At this point files have been renamed/copied at destination.
4551 ;; That's mean DEST-CAND exists.
4553 with dest
= (expand-file-name dest-cand
)
4555 for basename-src
= (anything-c-basename src
)
4556 for fname
= (cond (rename-dir-flag (directory-file-name dest
))
4557 ((file-directory-p dest
)
4558 (concat (file-name-as-directory dest
) basename-src
))
4560 when
(file-exists-p fname
)
4561 collect fname into tmp-list
4562 finally return
(sort tmp-list
'string
<)))
4564 (defun anything-ff-maybe-mark-candidates ()
4565 "Mark all candidates of list `anything-ff-cand-to-mark'."
4566 (when (and (string= (assoc-default 'name
(anything-get-current-source))
4567 (assoc-default 'name anything-c-source-find-files
))
4568 anything-ff-cand-to-mark
)
4569 (with-anything-window
4570 (while anything-ff-cand-to-mark
4571 (if (string= (car anything-ff-cand-to-mark
) (anything-get-selection))
4573 (anything-make-visible-mark)
4574 (anything-next-line)
4575 (setq anything-ff-cand-to-mark
(cdr anything-ff-cand-to-mark
)))
4576 (anything-next-line)))
4577 (unless (anything-this-visible-mark)
4578 (anything-prev-visible-mark)))))
4580 (add-hook 'anything-after-update-hook
#'anything-ff-maybe-mark-candidates
)
4582 (defun* anything-dired-do-action-on-file
(&key action
)
4583 (let* ((files (dired-get-marked-files))
4584 (len (length files
))
4585 (fname (if (> len
1)
4586 (format "* %d Files" len
)
4588 (source (case action
4589 ('copy
'anything-c-source-copy-files
)
4590 ('rename
'anything-c-source-rename-files
)
4591 ('symlink
'anything-c-source-symlink-files
)
4592 ('hardlink
'anything-c-source-hardlink-files
)))
4593 (prompt-fm (case action
4594 ('copy
"Copy %s to: ")
4595 ('rename
"Rename %s to: ")
4596 ('symlink
"Symlink %s to: ")
4597 ('hardlink
"Hardlink %s to: ")))
4598 (buffer (case action
4599 ('copy
"*Anything Copy Files*")
4600 ('rename
"*Anything Rename Files*")
4601 ('symlink
"*Anything Symlink Files*")
4602 ('hardlink
"*Anything Hardlink Files*")))
4603 (anything-mp-highlight-delay nil
))
4604 (anything :sources source
4605 :input
(or (dired-dwim-target-directory)
4606 (expand-file-name (anything-c-current-directory)))
4607 :preselect
(dired-get-filename)
4608 :prompt
(format prompt-fm fname
)
4609 :keymap anything-c-read-file-map
4613 (define-minor-mode anything-dired-mode
()
4614 "Enable anything completion in Dired functions.
4615 Bindings affected are C, R, S, H.
4616 This is deprecated for Emacs24+ users, use `ac-mode' instead."
4617 :group
'anything-config
4619 (if anything-dired-mode
4621 (substitute-key-definition
4622 'dired-do-copy
'anything-dired-copy-file dired-mode-map
)
4623 (substitute-key-definition
4624 'dired-do-rename
'anything-dired-rename-file dired-mode-map
)
4625 (substitute-key-definition
4626 'dired-do-symlink
'anything-dired-symlink-file dired-mode-map
)
4627 (substitute-key-definition
4628 'dired-do-hardlink
'anything-dired-hardlink-file dired-mode-map
))
4629 (substitute-key-definition
4630 'anything-dired-copy-file
'dired-do-copy dired-mode-map
)
4631 (substitute-key-definition
4632 'anything-dired-rename-file
'dired-do-rename dired-mode-map
)
4633 (substitute-key-definition
4634 'anything-dired-symlink-file
'dired-do-symlink dired-mode-map
)
4635 (substitute-key-definition
4636 'anything-dired-hardlink-file
'dired-do-hardlink dired-mode-map
)))
4638 (defalias 'anything-dired-bindings
'anything-dired-mode
)
4640 (defun* anything-c-read-file-name
(prompt
4642 (name "Read File Name")
4643 (initial-input (expand-file-name default-directory
))
4644 (buffer "*Anything Completions*")
4648 (marked-candidates nil
)
4650 (persistent-action 'anything-find-files-persistent-action
)
4651 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
4652 "Anything `read-file-name' emulation.
4653 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
4654 (when (get-buffer anything-action-buffer
)
4655 (kill-buffer anything-action-buffer
))
4656 (let ((anything-mp-highlight-delay nil
)
4657 ;; Be sure we don't erase the underlying minibuffer if some.
4658 (anything-ff-auto-update-initial-value
4659 (not (minibuffer-window-active-p (minibuffer-window))))
4660 anything-same-window
4661 (hist (and history
(anything-comp-read-get-candidates
4662 history nil nil alistp
))))
4663 (flet ((action-fn (candidate)
4664 (if marked-candidates
4665 (anything-marked-candidates)
4666 (identity candidate
))))
4669 `(((name .
,(format "%s History" name
))
4670 (header-name .
(lambda (name)
4671 (concat name anything-c-find-files-doc-header
)))
4673 (mode-line . anything-read-file-name-mode-line-string
)
4675 (persistent-action .
,persistent-action
)
4676 (persistent-help .
,persistent-help
)
4677 (action .
,'action-fn
))
4679 (header-name .
(lambda (name)
4680 (concat name anything-c-find-files-doc-header
)))
4682 (setq anything-ff-auto-update-flag
4683 anything-ff-auto-update-initial-value
)))
4684 ;; It is needed for filenames with capital letters
4686 (mode-line . anything-read-file-name-mode-line-string
)
4687 (candidates .
(lambda ()
4688 (let ((seq (anything-find-files-get-candidates)))
4690 (loop for fname in seq
4691 when
(funcall test fname
) collect fname
)
4693 (filtered-candidate-transformer anything-c-find-files-transformer
)
4694 (persistent-action .
,persistent-action
)
4695 (candidate-number-limit .
9999)
4696 (toggle-auto-update . anything-ff-toggle-auto-update
)
4697 (persistent-help .
,persistent-help
)
4699 (action .
,'action-fn
)))
4700 :input initial-input
4702 :keymap anything-c-read-file-map
4705 :preselect preselect
)
4710 (defvar anything-c-file-cache-initialized-p nil
)
4712 (defvar anything-c-file-cache-files nil
)
4714 (defvar anything-c-source-file-cache
4715 '((name .
"File Cache")
4718 (require 'filecache nil t
)
4719 (unless anything-c-file-cache-initialized-p
4720 (setq anything-c-file-cache-files
4721 (loop for item in file-cache-alist append
4722 (destructuring-bind (base &rest dirs
) item
4723 (loop for dir in dirs collect
4724 (concat dir base
)))))
4725 (defadvice file-cache-add-file
(after file-cache-list activate
)
4726 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
4727 (setq anything-c-file-cache-initialized-p t
))))
4728 (candidates . anything-c-file-cache-files
)
4729 (match anything-c-match-on-basename
)
4731 ;; (anything 'anything-c-source-file-cache)
4737 ;; NOTE for WINDOZE users:
4738 ;; You have to install Everything with his command line interface here:
4739 ;; http://www.voidtools.com/download.php
4741 (defun anything-locate-1 (&optional localdb init
)
4742 "Generic function to run Locate.
4743 if LOCALDB is non--nil search and use a local locate db file.
4744 INIT is a string to use as initial input in prompt.
4745 See `anything-locate-with-db' and `anything-locate'."
4746 (anything-locate-with-db
4748 (anything-c-read-file-name
4750 :marked-candidates t
4751 :preselect anything-locate-db-file-regexp
4753 (if anything-locate-db-file-regexp
4754 ;; Select only locate db files and directories
4755 ;; to allow navigation.
4757 anything-locate-db-file-regexp x
)
4758 (file-directory-p x
))
4761 ;; (anything-locate-1 t)
4763 (defun anything-locate-with-db (&optional db initial-input
)
4765 If DB is not given or nil use locate without -d option.
4766 Argument DB can be given as a string or list of db files.
4767 Argument INITIAL-INPUT is a string to use as initial-input.
4768 See also `anything-locate'."
4769 (when (and db
(stringp db
)) (setq db
(list db
)))
4770 (let ((anything-c-locate-command
4772 (replace-regexp-in-string
4774 (format "locate -d %s"
4775 (mapconcat 'identity
4776 ;; Remove eventually
4777 ;; marked directories by error.
4779 unless
(file-directory-p i
)
4781 anything-c-locate-command
)
4782 anything-c-locate-command
)))
4783 (anything :sources
'anything-c-source-locate
4784 :buffer
"*anything locate*"
4785 :input initial-input
4786 :keymap anything-generic-files-map
)))
4787 ;; (anything-locate-with-db "~/locate.db")
4789 (defun anything-c-locate-init ()
4790 "Initialize async locate process for `anything-c-source-locate'."
4791 (setq mode-line-format
4792 '(" " mode-line-buffer-identification
" "
4793 (line-number-mode "%l") " "
4794 (:eval
(propertize "(Locate Process Running) "
4795 'face
'((:foreground
"red"))))))
4796 (unless anything-c-locate-command
4797 (setq anything-c-locate-command
4799 ('gnu
/linux
"locate -i -r %s")
4800 ('berkeley-unix
"locate -i %s")
4801 ('windows-nt
"es -i -r %s")
4804 (start-process-shell-command "locate-process" nil
4805 (format anything-c-locate-command
4807 (set-process-sentinel (get-process "locate-process")
4808 #'(lambda (process event
)
4809 (when (string= event
"finished\n")
4810 (with-anything-window
4811 (force-mode-line-update nil
)
4812 (anything-update-move-first-line)))))))
4814 (defvar anything-c-source-locate
4816 (candidates . anything-c-locate-init
)
4818 (requires-pattern .
3)
4819 (candidate-number-limit .
9999)
4820 (mode-line . anything-generic-file-mode-line-string
)
4822 "Find files matching the current input pattern with locate.")
4823 ;; (anything 'anything-c-source-locate)
4825 (defun anything-c-locate-read-file-name (prompt &optional init
)
4826 "Search a file with locate and return it's filename.
4827 Use argument PROMPT and INIT for `anything' arguments
4831 (candidates . anything-c-locate-init
)
4833 (requires-pattern .
3)
4834 (candidate-number-limit .
9999)
4835 (mode-line . anything-generic-file-mode-line-string
)
4839 :buffer
"*anything locate rfn*"))
4843 ;;; Anything Incremental Grep.
4846 ;; Allow to grep incrementally with anything interface.
4847 ;; It allow also to Grep files recursively without using 'find' shell command.
4848 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
4849 (defvar anything-c-grep-default-command
4850 "grep -d skip %e -niH -e %p %f"
4851 "Default grep format command for `anything-do-grep-1'.
4853 '%e' format spec is for --exclude or --include grep options.
4854 '%p' format spec is for pattern.
4855 '%f' format spec is for filenames.")
4857 (defvar anything-c-grep-default-recurse-command
4858 "grep -d recurse %e -niH -e %p %f"
4859 "Default recursive grep format command for `anything-do-grep-1'.
4860 See `anything-c-grep-default-command' for format specs.")
4862 (defvar anything-c-default-zgrep-command
"zgrep -niH -e %p %f")
4864 (defvar anything-c-rzgrep-cache
(make-hash-table :test
'equal
))
4866 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
4868 (defvar anything-c-grep-debug-command-line nil
4869 "Turn on anything grep command-line debugging when non--nil.")
4871 (defvar anything-c-zgrep-recurse-flag nil
)
4873 (defvar anything-c-grep-history nil
)
4875 (defvar anything-c-grep-max-length-history
100
4876 "*Max number of elements to save in `anything-c-grep-history'.")
4878 (defun anything-c-grep-prepare-candidates (candidates)
4879 "Prepare filenames and directories CANDIDATES for grep command line."
4880 ;; If one or more candidate is a directory, search in all files
4881 ;; of this candidate (e.g /home/user/directory/*).
4882 ;; If r option is enabled search also in subdidrectories.
4883 ;; We need here to expand wildcards to support crap windows filenames
4884 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
4885 (if anything-c-zgrep-recurse-flag
4886 (mapconcat 'shell-quote-argument candidates
" ")
4887 (loop for i in candidates append
4888 (cond ( ;; Candidate is a directory and we use recursion.
4889 (and (file-directory-p i
)
4890 (anything-c-grep-recurse-p))
4891 (list (expand-file-name i
)))
4892 ;; Candidate is a directory, search in all files.
4893 ((file-directory-p i
)
4894 (file-expand-wildcards
4895 (concat (file-name-as-directory (expand-file-name i
)) "*") t
))
4896 ;; Candidate is a file or wildcard and we use recursion, use the
4897 ;; current directory instead of candidate.
4898 ((and (or (file-exists-p i
) (string-match "\*" i
))
4899 (anything-c-grep-recurse-p))
4900 (list (expand-file-name
4901 (directory-file-name ; Needed for windoze.
4902 (file-name-directory (directory-file-name i
))))))
4903 ;; Candidate use wildcard.
4904 ((string-match "^\*" (anything-c-basename i
))
4905 (file-expand-wildcards i t
))
4906 ;; Else should be one or more file.
4907 (t (list i
))) into all-files
4909 (mapconcat 'shell-quote-argument all-files
" "))))
4911 (defun anything-c-grep-recurse-p ()
4912 "Check if `anything-do-grep-1' have switched to recursive."
4913 (let ((args (replace-regexp-in-string
4914 "grep" "" anything-c-grep-default-command
)))
4915 (string-match-p "r\\|recurse" args
)))
4917 (defun anything-c-grep-init (only-files &optional include zgrep
)
4918 "Start an asynchronous grep process in ONLY-FILES list."
4919 (let* ((fnargs (anything-c-grep-prepare-candidates
4920 (if (file-remote-p anything-ff-default-directory
)
4921 (mapcar #'(lambda (x)
4922 (file-remote-p x
'localname
))
4925 (ignored-files (mapconcat
4927 (concat "--exclude=" (shell-quote-argument x
)))
4928 grep-find-ignored-files
" "))
4929 (ignored-dirs (mapconcat
4930 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
4932 (concat "--exclude-dir=" (shell-quote-argument x
)))
4933 grep-find-ignored-directories
" "))
4934 (exclude (if (anything-c-grep-recurse-p)
4935 (concat (or include ignored-files
) " " ignored-dirs
)
4937 (cmd-line (format-spec
4938 anything-c-grep-default-command
4940 (list (unless zgrep
(cons ?e exclude
))
4941 (cons ?p
(shell-quote-argument anything-pattern
))
4942 (cons ?f fnargs
))))))
4943 (when anything-c-grep-debug-command-line
4944 (with-current-buffer (get-buffer-create "*any grep debug*")
4945 (goto-char (point-max))
4946 (insert (concat ">>> " cmd-line
"\n\n"))))
4947 (setq mode-line-format
4948 '(" " mode-line-buffer-identification
" "
4949 (line-number-mode "%l") " "
4950 (:eval
(when (get-process "grep-process")
4951 (propertize "[Grep Process Running] "
4952 'face
'anything-grep-running
)))))
4953 (force-mode-line-update nil
)
4955 (let ((default-directory anything-ff-default-directory
))
4956 (start-file-process-shell-command "grep-process" nil cmd-line
))
4958 (set-process-sentinel
4959 (get-process "grep-process")
4960 #'(lambda (process event
)
4961 (when (string= event
"finished\n")
4962 (with-anything-window
4963 (anything-update-move-first-line)
4964 (setq mode-line-format
4965 '(" " mode-line-buffer-identification
" "
4966 (line-number-mode "%l") " "
4968 (format "[Grep Process Finished - (%s results)] "
4969 (let ((nlines (1- (count-lines
4972 (if (> nlines
0) nlines
0)))
4973 'face
'anything-grep-finish
))))
4974 (force-mode-line-update nil
))))))))
4976 (defun anything-c-grep-action (candidate &optional where mark
)
4977 "Define a default action for `anything-do-grep' on CANDIDATE.
4978 WHERE can be one of other-window, elscreen, other-frame."
4979 (let* ((split (anything-c-grep-split-line candidate
))
4980 (lineno (string-to-number (nth 1 split
)))
4981 (loc-fname (car split
))
4982 (tramp-method (file-remote-p anything-ff-default-directory
'method
))
4983 (tramp-host (file-remote-p anything-ff-default-directory
'host
))
4984 (tramp-prefix (concat "/" tramp-method
":" tramp-host
":"))
4985 (fname (if tramp-host
4986 (concat tramp-prefix loc-fname
) loc-fname
)))
4988 (other-window (find-file-other-window fname
))
4989 (elscreen (anything-elscreen-find-file fname
))
4990 (other-frame (find-file-other-frame fname
))
4991 (t (find-file fname
)))
4992 (anything-goto-line lineno
)
4994 (set-marker (mark-marker) (point))
4995 (push-mark (point) 'nomsg
))
4997 (unless (or anything-in-persistent-action
4998 (string= anything-pattern
""))
4999 (setq anything-c-grep-history
5000 (cons anything-pattern
5001 (delete anything-pattern anything-c-grep-history
)))
5002 (when (> (length anything-c-grep-history
)
5003 anything-c-grep-max-length-history
)
5004 (setq anything-c-grep-history
5005 (delete (car (last anything-c-grep-history
))
5006 anything-c-grep-history
))))))
5008 (defun anything-c-grep-other-window (candidate)
5009 "Jump to result in other window from anything grep."
5010 (anything-c-grep-action candidate
'other-window
))
5012 (defun anything-c-grep-other-frame (candidate)
5013 "Jump to result in other frame from anything grep."
5014 (anything-c-grep-action candidate
'other-frame
))
5016 (defun anything-c-grep-jump-elscreen (candidate)
5017 "Jump to result in elscreen from anything grep."
5018 (anything-c-grep-action candidate
'elscreen
))
5020 (defun anything-c-grep-save-results (candidate)
5021 "Save anything grep result in a `grep-mode' buffer."
5022 (let ((buf "*grep*")
5024 (when (get-buffer buf
)
5025 (setq new-buf
(read-string "GrepBufferName: " buf
))
5026 (loop for b in
(anything-c-buffer-list)
5027 when
(and (string= new-buf b
)
5029 (format "Buffer `%s' already exists overwrite? "
5031 do
(setq new-buf
(read-string "GrepBufferName: " "*grep ")))
5033 (with-current-buffer (get-buffer-create buf
)
5034 (let ((inhibit-read-only t
))
5036 (insert "-*- mode: grep -*-\n\n"
5037 (format "Grep Results for `%s':\n\n" anything-pattern
))
5039 (insert (with-current-buffer anything-buffer
5041 (buffer-substring (point) (point-max))))
5043 (message "Anything Grep Results saved in `%s' buffer" buf
)))
5045 (defun anything-c-grep-persistent-action (candidate)
5046 "Persistent action for `anything-do-grep'.
5047 With a prefix arg record CANDIDATE in `mark-ring'."
5048 (if current-prefix-arg
5049 (anything-c-grep-action candidate nil
'mark
)
5050 (anything-c-grep-action candidate
))
5051 (anything-match-line-color-current-line))
5053 (defun anything-c-grep-guess-extensions (files)
5054 "Try to guess file extensions in FILES list when using grep recurse.
5055 These extensions will be added to command line with --include arg of grep."
5057 with glob-list
= nil
5058 with lst
= (if (file-directory-p (car files
))
5061 directory-files-no-dot-files-regexp
)
5064 for ext
= (file-name-extension i t
)
5065 for glob
= (and ext
(not (string= ext
""))
5067 unless
(or (not glob
)
5068 (member glob glob-list
)
5069 (member glob grep-find-ignored-files
))
5070 collect glob into glob-list
5071 finally return glob-list
))
5073 (defun anything-do-grep-1 (only &optional recurse zgrep
)
5074 "Launch grep with a list of ONLY files.
5075 When RECURSE is given use -r option of grep and prompt user
5076 to set the --include args of grep.
5077 You can give more than one arg separated by space.
5078 e.g *.el *.py *.tex.
5079 If it's empty --exclude `grep-find-ignored-files' is used instead."
5080 (let* ((anything-compile-source-functions
5081 ;; rule out anything-match-plugin because the input is one regexp.
5082 (delq 'anything-compile-source--match-plugin
5083 (copy-sequence anything-compile-source-functions
)))
5084 (exts (anything-c-grep-guess-extensions only
))
5085 (globs (and (not zgrep
) (mapconcat 'identity exts
" ")))
5086 (include-files (and recurse
(not zgrep
)
5087 (read-string "OnlyExt(*.[ext]): "
5089 ;; Set `minibuffer-history' AFTER includes-files
5090 ;; to avoid storing wild-cards here.
5091 (minibuffer-history anything-c-grep-history
)
5092 (anything-c-grep-default-command (cond ((and recurse zgrep
) anything-c-default-zgrep-command
)
5093 (recurse anything-c-grep-default-recurse-command
)
5094 (zgrep anything-c-default-zgrep-command
)
5095 (t anything-c-grep-default-command
)))
5096 ;; Disable match-plugin and use here own highlighting.
5097 (anything-mp-highlight-delay nil
))
5100 (and (not (string= include-files
""))
5101 (mapconcat #'(lambda (x)
5102 (concat "--include=" (shell-quote-argument x
)))
5103 (split-string include-files
) " "))))
5104 ;; When called as action from an other source e.g *-find-files
5105 ;; we have to kill action buffer.
5106 (when (get-buffer anything-action-buffer
)
5107 (kill-buffer anything-action-buffer
))
5108 ;; `anything-find-files' haven't already started,
5109 ;; give a default value to `anything-ff-default-directory'.
5110 (setq anything-ff-default-directory
(or anything-ff-default-directory
5114 `(((name .
"Grep (C-c ? Help)")
5117 (funcall anything-c-grep-default-function only include-files zgrep
)))
5118 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
5119 (candidate-number-limit .
9999)
5120 (mode-line . anything-grep-mode-line-string
)
5123 `(("Find File" . anything-c-grep-action
)
5124 ("Find file other frame" . anything-c-grep-other-frame
)
5125 ,(and (locate-library "elscreen")
5126 '("Find file in Elscreen"
5127 . anything-c-grep-jump-elscreen
))
5128 ("Save results in grep buffer" . anything-c-grep-save-results
)
5129 ("Find file other window" . anything-c-grep-other-window
))))
5130 (persistent-action . anything-c-grep-persistent-action
)
5131 (persistent-help .
"Jump to line (`C-u' Record in mark ring)")
5132 (requires-pattern .
3)
5134 :keymap anything-c-grep-map
5135 :buffer
"*anything grep*")))
5137 (defun anything-ff-zgrep-1 (flist recursive
)
5139 (let* ((def-dir (or anything-ff-default-directory
5142 (or (gethash def-dir anything-c-rzgrep-cache
)
5145 (anything-c-walk-directory
5149 :match
".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5150 anything-c-rzgrep-cache
))
5152 (when recursive
(setq anything-c-zgrep-recurse-flag t
))
5153 (anything-do-grep-1 only recursive
'zgrep
))
5154 (setq anything-c-zgrep-recurse-flag nil
)))
5156 (defun anything-c-grep-split-line (line)
5157 "Split a grep output line."
5158 (let (beg fname lineno str
)
5159 ;; Don't print until grep line is valid.
5160 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line
)
5163 (goto-char (point-min))
5166 (re-search-forward ":" nil t
)
5167 (setq fname
(buffer-substring-no-properties beg
(1- (point))))
5169 (re-search-forward ":" nil t
)
5170 (setq lineno
(buffer-substring-no-properties beg
(1- (point))))
5171 (setq str
(buffer-substring-no-properties (point) (point-at-eol))))
5172 (list fname lineno str
))))
5174 (defun anything-c-grep-cand-transformer (candidates sources
)
5175 "Filtered candidate transformer function for `anything-do-grep'."
5176 (loop for i in candidates
5177 for split
= (and i
(anything-c-grep-split-line i
))
5178 for fname
= (car split
)
5179 for lineno
= (nth 1 split
)
5180 for str
= (nth 2 split
)
5181 when
(and fname lineno str
)
5183 (cons (concat (propertize (file-name-nondirectory fname
)
5184 'face
'anything-grep-file
5185 'help-echo fname
) ":"
5186 (propertize lineno
'face
'anything-grep-lineno
) ":"
5187 (anything-c-grep-highlight-match str
))
5190 (defun anything-c-grep-highlight-match (str)
5191 "Highlight in string STR all occurences matching `anything-pattern'."
5195 (goto-char (point-min))
5196 (while (and (re-search-forward anything-pattern nil t
)
5197 (> (- (match-end 0) (match-beginning 0)) 0))
5198 (add-text-properties
5199 (match-beginning 0) (match-end 0)
5200 '(face anything-grep-match
)))
5204 ;; Go to next or precedent file (common to etags and grep).
5205 (defun anything-c-goto-next-or-prec-file (n)
5206 "Go to next or precedent candidate file in anything grep/etags buffers.
5207 If N is positive go forward otherwise go backward."
5208 (with-anything-window
5209 (let* ((current-line-list (split-string
5212 (point-at-eol)) ":"))
5213 (current-fname (nth 0 current-line-list
))
5214 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
)))
5216 (while (not (funcall fn-b-o-f
))
5217 (forward-line n
) ; Go forward or backward depending of n value.
5218 (unless (search-forward current-fname
(point-at-eol) t
)
5219 (anything-mark-current-line)
5220 (throw 'break nil
))))
5221 (cond ((and (eq n
1) (eobp))
5222 (re-search-backward ".")
5224 (anything-mark-current-line))
5225 ((and (< n
1) (bobp))
5227 (anything-mark-current-line))))))
5230 (defun anything-c-goto-precedent-file ()
5231 "Go to precedent file in anything grep/etags buffers."
5233 (anything-c-goto-next-or-prec-file -
1))
5236 (defun anything-c-goto-next-file ()
5237 "Go to precedent file in anything grep/etags buffers."
5239 (anything-c-goto-next-or-prec-file 1))
5242 (defun anything-c-grep-run-persistent-action ()
5243 "Run grep persistent action from `anything-do-grep-1'."
5245 (anything-attrset 'jump-persistent
'anything-c-grep-persistent-action
)
5246 (anything-execute-persistent-action 'jump-persistent
))
5249 (defun anything-c-grep-run-default-action ()
5250 "Run grep default action from `anything-do-grep-1'."
5252 (anything-c-quit-and-execute-action 'anything-c-grep-action
))
5255 (defun anything-c-grep-run-other-window-action ()
5256 "Run grep goto other window action from `anything-do-grep-1'."
5258 (anything-c-quit-and-execute-action 'anything-c-grep-other-window
))
5261 (defun anything-c-grep-run-save-buffer ()
5262 "Run grep save results action from `anything-do-grep-1'."
5264 (anything-c-quit-and-execute-action 'anything-c-grep-save-results
))
5267 (defun anything-c-grep-buffers-1 (candidate &optional zgrep
)
5268 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5269 If one of selected buffers is not a file--buffer,
5270 it is ignored and grep will run on all others file--buffers.
5271 If only one candidate is selected and it is not a file--buffer,
5272 switch to this buffer and run `anything-occur'.
5273 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5274 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
5277 (anything-marked-candidates)))
5278 (win-conf (current-window-configuration))
5279 ;; Non--fname buffers are ignored.
5280 (bufs (loop for buf in cands
5281 for fname
= (buffer-file-name (get-buffer buf
))
5283 collect
(expand-file-name fname
))))
5286 (anything-do-grep-1 bufs nil
'zgrep
)
5287 (anything-do-grep-1 bufs
))
5288 ;; bufs is empty, thats mean we have only CANDIDATE
5289 ;; and it is not a buffer-filename, fallback to occur.
5290 (anything-c-switch-to-buffer candidate
)
5291 (when (get-buffer anything-action-buffer
)
5292 (kill-buffer anything-action-buffer
))
5294 (when (eq anything-exit-status
1)
5295 (set-window-configuration win-conf
)))))
5297 (defun anything-c-grep-buffers (candidate)
5298 "Action to grep buffers."
5299 (anything-c-grep-buffers-1 candidate
))
5301 (defun anything-c-zgrep-buffers (candidate)
5302 "Action to zgrep buffers."
5303 (anything-c-grep-buffers-1 candidate
'zgrep
))
5306 ;;; Anything interface for pdfgrep
5307 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5308 ;; and a pdf-reader (e.g xpdf) are needed.
5310 (defvar anything-c-pdfgrep-default-command
"pdfgrep --color never -niH %s %s")
5311 (defvar anything-c-pdfgrep-default-function
'anything-c-pdfgrep-init
)
5312 (defvar anything-c-pdfgrep-debug-command-line nil
)
5314 (defun anything-c-pdfgrep-init (only-files)
5315 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5316 (let* ((fnargs (anything-c-grep-prepare-candidates
5317 (if (file-remote-p anything-ff-default-directory
)
5318 (mapcar #'(lambda (x)
5319 (file-remote-p x
'localname
))
5322 (cmd-line (format anything-c-pdfgrep-default-command
5325 (when anything-c-pdfgrep-debug-command-line
5326 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5327 (goto-char (point-max))
5328 (insert (concat ">>> " cmd-line
"\n\n"))))
5329 (setq mode-line-format
5330 '(" " mode-line-buffer-identification
" "
5331 (line-number-mode "%l") " "
5332 (:eval
(propertize "(Pdfgrep Process Running) "
5333 'face
'((:foreground
"red"))))))
5335 (let ((default-directory anything-ff-default-directory
))
5336 (start-file-process-shell-command "pdfgrep-process" nil cmd-line
))
5338 (set-process-sentinel
5339 (get-process "pdfgrep-process")
5340 #'(lambda (process event
)
5341 (when (string= event
"finished\n")
5342 (with-anything-window
5343 (anything-update-move-first-line))
5344 (force-mode-line-update nil
)))))))
5347 (defun anything-do-pdfgrep-1 (only)
5348 "Launch pdfgrep with a list of ONLY files."
5349 (unless (executable-find "pdfgrep")
5350 (error "Error: No such program `pdfgrep'."))
5351 (let* ((anything-compile-source-functions
5352 ;; rule out anything-match-plugin because the input is one regexp.
5353 (delq 'anything-compile-source--match-plugin
5354 (copy-sequence anything-compile-source-functions
)))
5355 ;; Disable match-plugin and use here own highlighting.
5356 (anything-mp-highlight-delay nil
))
5357 ;; When called as action from an other source e.g *-find-files
5358 ;; we have to kill action buffer.
5359 (when (get-buffer anything-action-buffer
)
5360 (kill-buffer anything-action-buffer
))
5361 ;; If `anything-find-files' haven't already started,
5362 ;; give a default value to `anything-ff-default-directory'.
5363 (setq anything-ff-default-directory
(or anything-ff-default-directory
5367 `(((name .
"PdfGrep")
5370 (funcall anything-c-pdfgrep-default-function only
)))
5371 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
5372 (candidate-number-limit .
9999)
5373 (mode-line . anything-pdfgrep-mode-line-string
)
5374 (action . anything-c-pdfgrep-action
)
5375 (persistent-help .
"Jump to PDF Page")
5376 (requires-pattern .
3)
5378 :keymap anything-c-pdfgrep-map
5379 :buffer
"*anything grep*")))
5382 (defun anything-c-pdfgrep-action (candidate)
5383 (let* ((split (anything-c-grep-split-line candidate
))
5384 (pageno (nth 1 split
))
5385 (fname (car split
)))
5386 (start-file-process-shell-command
5388 (format-spec anything-c-pdfgrep-default-read-command
5389 (list (cons ?f fname
) (cons ?p pageno
))))))
5391 (defun anything-do-pdfgrep ()
5393 (let ((only (anything-c-read-file-name
5394 "Search in file(s): "
5395 :marked-candidates t
5396 :test
#'(lambda (file)
5397 (or (string= (file-name-extension file
) "pdf")
5398 (string= (file-name-extension file
) "PDF")
5399 (file-directory-p file
)))
5400 :preselect
(or (dired-get-filename nil t
)
5401 (buffer-file-name (current-buffer)))))
5402 (anything-c-grep-default-function 'anything-c-pdfgrep-init
))
5403 (anything-do-pdfgrep-1 only
)))
5406 ;; Yank text at point.
5410 (defvar anything-yank-point nil
)
5413 (defun anything-yank-text-at-point ()
5414 "Yank text at point in minibuffer."
5417 (flet ((insert-in-minibuffer (word)
5418 (with-selected-window (minibuffer-window)
5419 (let ((str anything-pattern
))
5420 (delete-minibuffer-contents)
5421 (set-text-properties 0 (length word
) nil word
)
5422 (insert (concat str word
))))))
5423 (with-anything-current-buffer
5424 ;; Start to initial point if C-w have never been hit.
5425 (unless anything-yank-point
(setq anything-yank-point
(point)))
5426 (and anything-yank-point
(goto-char anything-yank-point
))
5428 (setq input
(buffer-substring-no-properties anything-yank-point
(point)))
5429 (setq anything-yank-point
(point))) ; End of last forward-word
5430 (insert-in-minibuffer input
))))
5432 (defun anything-reset-yank-point ()
5433 (setq anything-yank-point nil
))
5435 (add-hook 'anything-after-persistent-action-hook
'anything-reset-yank-point
)
5436 (add-hook 'anything-cleanup-hook
'anything-reset-yank-point
)
5442 (defvar anything-c-source-recentf
5443 '((name .
"Recentf")
5446 (or recentf-mode
(recentf-mode 1))))
5447 (disable-shortcuts) ;; Needed for filenames with capitals letters.
5448 (candidates . recentf-list
)
5449 (match anything-c-match-on-basename
)
5451 "See (info \"(emacs)File Conveniences\").
5452 Set `recentf-max-saved-items' to a bigger value if default is too small.")
5453 ;; (anything 'anything-c-source-recentf)
5456 (eval-when-compile (require 'ffap
))
5457 (defvar anything-c-source-ffap-guesser
5458 '((name .
"File at point")
5459 (init .
(lambda () (require 'ffap
)))
5460 (candidates .
(lambda ()
5462 (with-anything-current-buffer
5466 ;; (anything 'anything-c-source-ffap-guesser)
5468 ;;; ffap with line number
5469 (defun anything-c-ffap-file-line-at-point ()
5470 "Get (FILENAME . LINENO) at point."
5471 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5474 (when (and (search-forward it nil t
)
5475 (looking-at ":\\([0-9]+\\)"))
5476 (cons it
(string-to-number (match-string 1)))))))
5478 (defvar anything-c-ffap-line-location nil
5479 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5480 It is cleared after jumping line.")
5482 (defun anything-c-ffap-line-candidates ()
5483 (with-anything-current-buffer
5484 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
5485 (when anything-c-ffap-line-location
5486 (destructuring-bind (file . line
) anything-c-ffap-line-location
5487 (list (cons (format "%s (line %d)" file line
) file
)))))
5489 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5490 (defun anything-c-ffap-line-goto-line ()
5491 (when (car anything-c-ffap-line-location
)
5494 (with-selected-window
5496 (get-file-buffer (car anything-c-ffap-line-location
)))
5497 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
5498 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
5499 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
5501 (defvar anything-c-source-ffap-line
5502 '((name .
"File/Lineno at point")
5503 (init .
(lambda () (require 'ffap
)))
5504 (candidates . anything-c-ffap-line-candidates
)
5506 ;; (anything 'anything-c-source-ffap-line)
5508 ;;; list of files gleaned from every dired buffer
5509 (defun anything-c-files-in-all-dired-candidates ()
5513 (cond ((listp dir
) ;filelist
5515 ((equal "" (file-name-nondirectory dir
)) ;dir
5516 (directory-files dir t
))
5518 (file-expand-wildcards dir t
))))
5520 (mapcar (lambda (buf)
5522 (when (eq major-mode
'dired-mode
)
5523 (if (consp dired-directory
)
5524 (cdr dired-directory
) ;filelist
5525 dired-directory
))) ;dir or wildcard
5527 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5529 (defvar anything-c-source-files-in-all-dired
5530 '((name .
"Files in all dired buffer.")
5531 (candidates . anything-c-files-in-all-dired-candidates
)
5533 ;; (anything 'anything-c-source-files-in-all-dired)
5535 (defvar anything-c-source-filelist
5536 '((name .
"FileList")
5537 (grep-candidates . anything-c-filelist-file-name
)
5538 (candidate-number-limit .
200)
5539 (requires-pattern .
4)
5541 "Source to find files instantly.
5542 See `anything-c-filelist-file-name' docstring for usage.")
5547 (defvar anything-c-info-pages nil
5548 "All info pages on system.
5549 Will be calculated the first time you invoke anything with this
5552 (defun anything-c-info-pages-init ()
5553 "Collect candidates for initial Info node Top."
5554 (if anything-c-info-pages
5555 anything-c-info-pages
5556 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5560 (Info-find-node "dir" "top")
5561 (goto-char (point-min))
5562 (while (re-search-forward info-topic-regexp nil t
)
5563 (push (match-string-no-properties 1) topics
))
5565 (setq anything-c-info-pages topics
))))
5567 (defvar anything-c-source-info-pages
5568 `((name .
"Info Pages")
5569 (init . anything-c-info-pages-init
)
5570 (candidates . anything-c-info-pages
)
5571 (action .
(("Show with Info" .
(lambda (node-str)
5572 (info (replace-regexp-in-string
5573 "^[^:]+: " "" node-str
))))))
5574 (requires-pattern .
2)))
5575 ;; (anything 'anything-c-source-info-pages)
5578 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
5579 (defun anything-c-describe-attributes (anything-attribute)
5580 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
5581 Same as `anything-describe-anything-attribute' but with anything completion."
5582 (interactive (list (intern
5584 "Describe anything attribute: "
5585 (mapcar 'symbol-name anything-additional-attributes
)
5588 #'(lambda (candidate)
5589 (with-output-to-temp-buffer "*Help*"
5590 (princ (get (intern candidate
) 'anything-attrdoc
))))))))
5591 (with-output-to-temp-buffer "*Help*"
5592 (princ (get anything-attribute
'anything-attrdoc
))))
5595 ;;; Use info-index plug-in.
5598 ;; Note that `name' attribute is not needed since
5599 ;; `anything-c-insert-summary' have been removed.
5601 (defvar anything-c-source-info-elisp
5602 '((name .
"Info index: elisp")
5603 (info-index .
"elisp")))
5604 ;; (anything 'anything-c-source-info-elisp)
5607 (defvar anything-c-source-info-cl
5608 '((name .
"Info index: cl")
5609 (info-index .
"cl")))
5610 ;; (anything 'anything-c-source-info-cl)
5613 (defvar anything-c-source-info-org
5614 '((name .
"Info index: org")
5615 (info-index .
"org")))
5616 ;; (anything 'anything-c-source-info-org)
5619 (defvar anything-c-source-info-gnus
5620 '((name .
"Info index: Gnus")
5621 (info-index .
"gnus")))
5623 ;; Info Index ratpoison
5624 (defvar anything-c-source-info-ratpoison
5625 '((name .
"Info index: ratpoison")
5626 (info-index .
"ratpoison")))
5627 ;; (anything 'anything-c-source-info-ratpoison)
5630 (defvar anything-c-source-info-zsh
5631 '((name .
"Info index: zsh")
5632 (info-index .
"zsh")))
5633 ;; (anything 'anything-c-source-info-zsh)
5636 (defvar anything-c-source-info-bash
5637 '((name .
"Info index: bash")
5638 (info-index .
"bash")))
5639 ;; (anything 'anything-c-source-info-bash)
5641 ;; Info Index coreutils
5642 (defvar anything-c-source-info-coreutils
5643 '((name .
"Info index: coreutils")
5644 (info-index .
"coreutils")))
5645 ;; (anything 'anything-c-source-info-coreutils)
5647 ;; Info Index fileutils
5648 (defvar anything-c-source-info-fileutils
5649 '((name .
"Info index: fileutils")
5650 (info-index .
"fileutils")))
5651 ;; (anything 'anything-c-source-info-fileutils)
5654 (defvar anything-c-source-info-find
5655 '((name .
"Info index: find")
5656 (info-index .
"find")))
5657 ;; (anything 'anything-c-source-info-find)
5659 ;; Info Index sh-utils
5660 (defvar anything-c-source-info-sh-utils
5661 '((name .
"Info index: sh-utils")
5662 (info-index .
"sh-utils")))
5663 ;; (anything 'anything-c-source-info-sh-utils)
5665 ;; Info Index textutils
5666 (defvar anything-c-source-info-textutils
5667 '((name .
"Info index: textutils")
5668 (info-index .
"textutils")))
5669 ;; (anything 'anything-c-source-info-textutils)
5672 (defvar anything-c-source-info-libc
5673 '((name .
"Info index: libc")
5674 (info-index .
"libc")))
5675 ;; (anything 'anything-c-source-info-libc)
5678 (defvar anything-c-source-info-make
5679 '((name .
"Info index: make")
5680 (info-index .
"make")))
5681 ;; (anything 'anything-c-source-info-make)
5683 ;; Info Index automake
5684 (defvar anything-c-source-info-automake
5685 '((name .
"Info index: automake")
5686 (info-index .
"automake")))
5687 ;; (anything 'anything-c-source-info-automake)
5689 ;; Info Index autoconf
5690 (defvar anything-c-source-info-autoconf
5691 '((name .
"Info index: autoconf")
5692 (info-index .
"autoconf")))
5693 ;; (anything 'anything-c-source-info-autoconf)
5695 ;; Info Index emacs-lisp-intro
5696 (defvar anything-c-source-info-emacs-lisp-intro
5697 '((name .
"Info index: emacs-lisp-intro")
5698 (info-index .
"emacs-lisp-intro")))
5699 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
5702 (defvar anything-c-source-info-emacs
5703 '((name .
"Info index: emacs")
5704 (info-index .
"emacs")))
5705 ;; (anything 'anything-c-source-info-emacs)
5708 (defvar anything-c-source-info-elib
5709 '((name .
"Info index: elib")
5710 (info-index .
"elib")))
5711 ;; (anything 'anything-c-source-info-elib)
5714 (defvar anything-c-source-info-eieio
5715 '((name .
"Info index: eieio")
5716 (info-index .
"eieio")))
5717 ;; (anything 'anything-c-source-info-eieio)
5719 ;; Info Index gauche-refe
5720 (defvar anything-c-source-info-gauche-refe
5721 '((name .
"Info index: gauche")
5722 (info-index .
"gauche-refe")))
5723 ;; (anything 'anything-c-source-info-gauche-refe)
5726 (defvar anything-c-source-info-guile
5727 '((name .
"Info index: guile")
5728 (info-index .
"guile")))
5729 ;; (anything 'anything-c-source-info-guile)
5731 ;; Info Index guile-tut
5732 (defvar anything-c-source-info-guile-tut
5733 '((name .
"Info index: guile-tut")
5734 (info-index .
"guile-tut")))
5735 ;; (anything 'anything-c-source-info-guile-tut)
5738 (defvar anything-c-source-info-goops
5739 '((name .
"Info index: goops")
5740 (info-index .
"goops")))
5741 ;; (anything 'anything-c-source-info-goops)
5743 ;; Info Index screen
5744 (defvar anything-c-source-info-screen
5745 '((name .
"Info index: screen")
5746 (info-index .
"screen")
5747 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
5748 ;; (anything 'anything-c-source-info-screen)
5751 (defvar anything-c-source-info-latex
5752 '((name .
"Info index: latex")
5753 (info-index .
"latex")))
5754 ;; (anything 'anything-c-source-info-latex)
5757 (defvar anything-c-source-info-gawk
5758 '((name .
"Info index: gawk")
5759 (info-index .
"gawk")))
5760 ;; (anything 'anything-c-source-info-gawk)
5763 (defvar anything-c-source-info-sed
5764 '((name .
"Info index: sed")
5765 (info-index .
"sed")))
5766 ;; (anything 'anything-c-source-info-sed)
5769 (defvar anything-c-source-info-m4
5770 '((name .
"Info index: m4")
5771 (info-index .
"m4")))
5772 ;; (anything 'anything-c-source-info-m4)
5775 (defvar anything-c-source-info-wget
5776 '((name .
"Info index: wget")
5777 (info-index .
"wget")))
5778 ;; (anything 'anything-c-source-info-wget)
5780 ;; Info Index binutils
5781 (defvar anything-c-source-info-binutils
5782 '((name .
"Info index: binutils")
5783 (info-index .
"binutils")))
5784 ;; (anything 'anything-c-source-info-binutils)
5787 (defvar anything-c-source-info-as
5788 '((name .
"Info index: as")
5789 (info-index .
"as")))
5790 ;; (anything 'anything-c-source-info-as)
5793 (defvar anything-c-source-info-bfd
5794 '((name .
"Info index: bfd")
5795 (info-index .
"bfd")))
5796 ;; (anything 'anything-c-source-info-bfd)
5799 (defvar anything-c-source-info-gprof
5800 '((name .
"Info index: gprof")
5801 (info-index .
"gprof")))
5802 ;; (anything 'anything-c-source-info-gprof)
5805 (defvar anything-c-source-info-ld
5806 '((name .
"Info index: ld")
5807 (info-index .
"ld")))
5808 ;; (anything 'anything-c-source-info-ld)
5811 (defvar anything-c-source-info-diff
5812 '((name .
"Info index: diff")
5813 (info-index .
"diff")))
5814 ;; (anything 'anything-c-source-info-diff)
5817 (defvar anything-c-source-info-flex
5818 '((name .
"Info index: flex")
5819 (info-index .
"flex")))
5820 ;; (anything 'anything-c-source-info-flex)
5823 (defvar anything-c-source-info-grep
5824 '((name .
"Info index: grep")
5825 (info-index .
"grep")))
5826 ;; (anything 'anything-c-source-info-grep)
5829 (defvar anything-c-source-info-gzip
5830 '((name .
"Info index: gzip")
5831 (info-index .
"gzip")))
5832 ;; (anything 'anything-c-source-info-gzip)
5834 ;; Info Index libtool
5835 (defvar anything-c-source-info-libtool
5836 '((name .
"Info index: libtool")
5837 (info-index .
"libtool")))
5838 ;; (anything 'anything-c-source-info-libtool)
5840 ;; Info Index texinfo
5841 (defvar anything-c-source-info-texinfo
5842 '((name .
"Info index: texinfo")
5843 (info-index .
"texinfo")))
5844 ;; (anything 'anything-c-source-info-texinfo)
5847 (defvar anything-c-source-info-info
5848 '((name .
"Info index: info")
5849 (info-index .
"info")))
5850 ;; (anything 'anything-c-source-info-info)
5853 (defvar anything-c-source-info-gdb
5854 '((name .
"Info index: gdb")
5855 (info-index .
"gdb")))
5856 ;; (anything 'anything-c-source-info-gdb)
5859 (defvar anything-c-source-info-stabs
5860 '((name .
"Info index: stabs")
5861 (info-index .
"stabs")))
5862 ;; (anything 'anything-c-source-info-stabs)
5864 ;; Info Index cvsbook
5865 (defvar anything-c-source-info-cvsbook
5866 '((name .
"Info index: cvsbook")
5867 (info-index .
"cvsbook")))
5868 ;; (anything 'anything-c-source-info-cvsbook)
5871 (defvar anything-c-source-info-cvs
5872 '((name .
"Info index: cvs")
5873 (info-index .
"cvs")))
5874 ;; (anything 'anything-c-source-info-cvs)
5877 (defvar anything-c-source-info-bison
5878 '((name .
"Info index: bison")
5879 (info-index .
"bison")))
5880 ;; (anything 'anything-c-source-info-bison)
5882 ;; Info Index id-utils
5883 (defvar anything-c-source-info-id-utils
5884 '((name .
"Info index: id-utils")
5885 (info-index .
"id-utils")))
5886 ;; (anything 'anything-c-source-info-id-utils)
5888 ;; Info Index global
5889 (defvar anything-c-source-info-global
5890 '((name .
"Info index: global")
5891 (info-index .
"global")))
5892 ;; (anything 'anything-c-source-info-global)
5895 ;;; Man and woman UI
5898 (defvar anything-c-man-pages nil
5899 "All man pages on system.
5900 Will be calculated the first time you invoke anything with this
5903 (defun anything-c-man-default-action (candidate)
5904 "Default action for jumping to a woman or man page from anything."
5905 (let ((wfiles (woman-file-name-all-completions candidate
)))
5907 (if (> (length wfiles
) 1)
5910 "ManFile: " wfiles
:must-match t
))
5912 ;; If woman is unable to format correctly
5914 (error (kill-buffer) ; Kill woman buffer.
5915 (let ((Man-notify-method 'meek
))
5916 (Man-getpage-in-background candidate
))))))
5918 (defvar anything-c-source-man-pages
5919 `((name .
"Manual Pages")
5920 (candidates .
(lambda ()
5921 (if anything-c-man-pages
5922 anything-c-man-pages
5923 ;; XEmacs doesn't have a woman :)
5924 (setq anything-c-man-pages
5927 (woman-file-name "")
5928 (sort (mapcar 'car woman-topic-all-completions
)
5930 (action ("Show with Woman" . anything-c-man-default-action
))
5931 ;; Woman does not work OS X
5932 ;; http://xahlee.org/emacs/modernization_man_page.html
5933 (action-transformer .
(lambda (actions candidate
)
5934 (if (eq system-type
'darwin
)
5935 '(("Show with Man" . man
))
5937 (requires-pattern .
2)))
5938 ;; (anything 'anything-c-source-man-pages)
5942 ;;; Anything M-x - Enhanced M-x UI
5945 ;; Another replacement of `M-x' that act exactly like the
5946 ;; vanilla Emacs one, no problem of windows configuration, prefix args
5947 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
5948 ;; anything invocation.
5949 ;; Documentation of commands available without quitting,
5950 ;; Show keybindings of commands.
5952 (defvar anything-M-x-input-history nil
)
5954 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
5955 "Return alist of MODE-MAP."
5956 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
5957 for str-key
= (key-description key
)
5958 for ismenu
= (string-match "<menu-bar>" str-key
)
5959 unless ismenu collect
(cons str-key com
)))
5961 (defun anything-get-mode-map-from-mode (mode)
5962 "Guess the mode-map name according to MODE.
5963 Some modes don't use conventional mode-map name
5964 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
5965 Return nil if no mode-map found."
5967 ;; Start with a conventional mode-map name.
5968 with mode-map
= (intern-soft (format "%s-map" mode
))
5969 with mode-string
= (symbol-name mode
)
5970 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
5971 while
(not mode-map
)
5972 for count downfrom
(length mode-name
)
5973 ;; Return when no result after parsing entire string.
5974 when
(eq count
0) return nil
5975 for sub-name
= (substring mode-name
0 count
)
5976 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
5977 finally return mode-map
))
5979 (defun anything-M-x-current-mode-map-alist ()
5980 "Return mode-map alist of current `major-mode'."
5981 (let ((map (anything-get-mode-map-from-mode major-mode
)))
5982 (when (and map
(boundp map
))
5983 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
5986 (defun anything-M-x-transformer (candidates sources
)
5987 "filtered-candidate-transformer to show bindings in emacs commands.
5988 Show global bindings and local bindings according to current `major-mode'."
5989 (with-anything-current-buffer
5991 with local-map
= (anything-M-x-current-mode-map-alist)
5992 for cand in candidates
5993 for local-key
= (car (rassq cand local-map
))
5994 for key
= (substitute-command-keys (format "\\[%s]" cand
))
5996 (cons (cond ((and (string-match "^M-x" key
) local-key
)
6000 'face
'anything-M-x-key-face
)))
6001 ((string-match "^M-x" key
) cand
)
6002 (t (format "%s (%s)"
6005 'face
'anything-M-x-key-face
))))
6008 (sort ls
#'(lambda (x y
) (string-lessp (car x
) (car y
)))))))
6011 ;;; Complex command history
6014 (defvar anything-c-source-complex-command-history
6015 '((name .
"Complex Command History")
6016 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
6018 ;; (anything 'anything-c-source-complex-command-history)
6020 ;;; M-x history (not related to `anything-M-x')
6023 (defvar anything-c-source-extended-command-history
6024 '((name .
"Emacs Commands History")
6027 (anything-fast-remove-dups extended-command-history
:test
'equal
)))
6029 ;; (anything 'anything-c-source-extended-command-history)
6031 ;;; Emacs commands (Basic source for emacs commands)
6034 (defvar anything-c-source-emacs-commands
6035 '((name .
"Emacs Commands")
6036 (candidates .
(lambda ()
6038 (mapatoms (lambda (a)
6040 (push (symbol-name a
)
6042 (sort commands
'string-lessp
))))
6044 (requires-pattern .
2))
6045 "Source for completing and invoking Emacs commands.
6046 A command is a function with interactive spec that can
6047 be invoked with `M-x'.
6049 To get non-interactive functions listed, use
6050 `anything-c-source-emacs-functions'.")
6051 ;; (anything 'anything-c-source-emacs-commands)
6058 (defvar anything-c-source-emacs-functions
6059 '((name .
"Emacs Functions")
6060 (candidates .
(lambda ()
6062 (mapatoms (lambda (a)
6064 (push (symbol-name a
) commands
))))
6065 (sort commands
'string-lessp
))))
6067 (requires-pattern .
2))
6068 "Source for completing Emacs functions.")
6069 ;; (anything 'anything-c-source-emacs-functions)
6071 ;;; With abbrev expansion
6072 ;;; Similar to my exec-abbrev-cmd.el
6073 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
6074 (defvar anything-c-function-abbrev-regexp nil
6075 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
6076 Regexp built from the current `anything-pattern' interpreting it
6078 Only for internal use.")
6080 (defun anything-c-match-function-by-abbrev (candidate)
6081 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
6083 Abbreviations are made by taking the first character from each
6084 word in the function's name, e.g. \"bb\" is an abbrev for
6085 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
6086 (string-match anything-c-function-abbrev-regexp candidate
))
6088 (defvar anything-c-source-emacs-functions-with-abbrevs
6089 (append anything-c-source-emacs-functions
6090 '((match anything-c-match-function-by-abbrev
6091 anything-c-string-match
))
6094 (defadvice anything-update
6095 (before anything-c-update-function-abbrev-regexp activate
)
6096 (let ((char-list (append anything-pattern nil
))
6098 (dolist (c char-list
)
6099 (setq str
(concat str
(list c
) "[^-]*-")))
6100 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
6101 (setq anything-c-function-abbrev-regexp str
))))))))
6102 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6104 (defvar anything-c-source-advice
6105 '((name .
"Function Advice")
6106 (candidates . anything-c-advice-candidates
)
6107 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
6108 (persistent-action . anything-c-advice-persistent-action
)
6110 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
6111 ;; (anything 'anything-c-source-advice)
6112 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6115 (defun anything-c-advice-candidates ()
6117 (loop for
(fname) in ad-advised-functions
6118 for function
= (intern fname
)
6120 (loop for class in ad-advice-classes append
6121 (loop for advice in
(ad-get-advice-info-field function class
)
6122 for enabled
= (ad-advice-enabled advice
)
6126 (if enabled
"Enabled " "Disabled")
6127 (propertize fname
'face
'font-lock-function-name-face
)
6128 (ad-make-single-advice-docstring advice class nil
))
6129 (list function class advice
))))))
6131 (defun anything-c-advice-persistent-action (func-class-advice)
6132 (if current-prefix-arg
6133 (anything-c-advice-toggle func-class-advice
)
6134 (describe-function (car func-class-advice
))))
6136 (defun anything-c-advice-toggle (func-class-advice)
6137 (destructuring-bind (function class advice
) func-class-advice
6138 (cond ((ad-advice-enabled advice
)
6139 (ad-advice-set-enabled advice nil
)
6140 (message "Disabled"))
6142 (ad-advice-set-enabled advice t
)
6143 (message "Enabled")))
6144 (ad-activate function
)
6145 (and anything-in-persistent-action
6146 (anything-c-advice-update-current-display-string))))
6148 (defun anything-c-advice-update-current-display-string ()
6149 (anything-edit-current-selection
6150 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6151 ((looking-at "Enabled") "Disabled")))
6154 (delete-region (point) (progn (forward-word 1) (point)))
6155 (insert newword
)))))
6162 (defvar anything-c-source-emacs-variables
6163 '((name .
"Emacs Variables")
6164 (candidates .
(lambda ()
6165 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
6167 (requires-pattern .
2))
6168 "Source for completing Emacs variables.")
6169 ;; (anything 'anything-c-source-emacs-variables)
6173 (defvar anything-c-source-lacarte
6174 '((name .
"Lacarte")
6175 (init .
(lambda () (require 'lacarte
)))
6176 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6177 (candidate-number-limit .
9999)
6178 (action . anything-c-call-interactively
))
6181 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6182 ;; (anything 'anything-c-source-lacarte)
6188 ;; Bind some faces for bookmarks.
6189 (defvar anything-c-bookmarks-face1
'anything-ff-directory
)
6190 (defvar anything-c-bookmarks-face2
'anything-ff-file
)
6191 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
6193 (eval-when-compile (require 'bookmark
))
6194 (defvar anything-c-source-bookmarks
6195 '((name .
"Bookmarks")
6197 (require 'bookmark
)))
6198 (candidates . bookmark-all-names
)
6200 "See (info \"(emacs)Bookmarks\").")
6201 ;; (anything 'anything-c-source-bookmarks)
6204 (defvar anything-c-source-bookmark-set
6205 '((name .
"Set Bookmark")
6207 (action . bookmark-set
))
6208 "See (info \"(emacs)Bookmarks\").")
6209 ;; (anything 'anything-c-source-bookmark-set)
6211 ;;; Visible Bookmarks
6212 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6215 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6216 (defvar anything-c-source-bm
6217 '((name .
"Visible Bookmarks")
6218 (init . anything-c-bm-init
)
6219 (candidates-in-buffer)
6223 http://www.nongnu.org/bm/")
6225 (defun anything-c-bm-init ()
6226 "Init function for `anything-c-source-bm'."
6227 (when (require 'bm nil t
)
6229 (let ((bookmarks (bm-lists))
6230 (buf (anything-candidate-buffer 'global
)))
6231 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
6232 '< :key
'overlay-start
))
6233 (let ((start (overlay-start bm
))
6234 (end (overlay-end bm
))
6235 (annotation (or (overlay-get bm
'annotation
) "")))
6236 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
6237 (let ((str (format "%5d: [%s]: %s\n"
6238 (line-number-at-pos start
)
6240 (buffer-substring start
(1- end
)))))
6241 (with-current-buffer buf
(insert str
))))))))))
6243 ;;; Special bookmarks
6244 (defvar anything-c-source-bookmarks-ssh
6245 '((name .
"Bookmarks-ssh")
6247 (require 'bookmark
)))
6248 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
6250 "See (info \"(emacs)Bookmarks\").")
6251 ;; (anything 'anything-c-source-bookmarks-ssh)
6253 (defvar anything-c-source-bookmarks-su
6254 '((name .
"Bookmarks-root")
6256 (require 'bookmark
)))
6257 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
6258 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
6261 "See (info \"(emacs)Bookmarks\").")
6262 ;; (anything 'anything-c-source-bookmarks-su)
6264 (defvar anything-c-source-bookmarks-local
6265 '((name .
"Bookmarks-Local")
6267 (require 'bookmark
)))
6268 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
6269 (filtered-candidate-transformer
6270 anything-c-adaptive-sort
6271 anything-c-highlight-bookmark
)
6273 "See (info \"(emacs)Bookmarks\").")
6274 ;; (anything 'anything-c-source-bookmarks-local)
6276 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
6277 (let* ((lis-all (bookmark-all-names))
6278 (lis-loc (cond (local (loop for i in lis-all
6279 unless
(string-match "^(ssh)\\|^(su)" i
)
6281 (su (loop for i in lis-all
6282 when
(string-match "^(su)" i
)
6284 (sudo (loop for i in lis-all
6285 when
(string-match "^(sudo)" i
)
6287 (ssh (loop for i in lis-all
6288 when
(string-match "^(ssh)" i
)
6290 (sort lis-loc
'string-lessp
)))
6292 (defun anything-c-bookmark-root-logged-p ()
6294 (dolist (i (mapcar #'buffer-name
(buffer-list)))
6295 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
6296 (throw 'break t
)))))
6298 (defun anything-c-highlight-bookmark-su (files source
)
6299 (if (anything-c-bookmark-root-logged-p)
6300 (anything-c-highlight-bookmark files source
)
6301 (anything-c-highlight-not-logged files source
)))
6303 (defun anything-c-highlight-not-logged (files source
)
6304 (loop for i in files
6305 collect
(propertize i
'face anything-c-bookmarks-face3
)))
6307 (defun anything-c-highlight-bookmark (bookmarks source
)
6308 "Used as `candidate-transformer' to colorize bookmarks.
6309 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6310 (loop for i in bookmarks
6311 for isfile
= (bookmark-get-filename i
)
6312 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
6313 (bmkext-get-buffer-name i
))
6314 for handlerp
= (and (fboundp 'bookmark-get-handler
)
6315 (bookmark-get-handler i
))
6316 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
6317 (bmkext-w3m-bookmark-p i
))
6318 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
6319 (bmkext-gnus-bookmark-p i
))
6320 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
6321 (bmkext-man-bookmark-p i
))
6322 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
6323 (bmkext-woman-bookmark-p i
))
6324 for handlerp
= (bookmark-get-handler i
)
6325 for isannotation
= (bookmark-get-annotation i
)
6326 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
6327 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
6328 ;; Add a * if bookmark have annotation
6329 if
(and isannotation
(not (string-equal isannotation
"")))
6330 do
(setq i
(concat "*" i
))
6331 collect
(cond (;; info buffers
6333 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
6336 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
6339 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
6342 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
6345 (propertize i
'face
'((:foreground
"Tomato"))))
6347 (and isfile
(file-directory-p isfile
))
6348 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
6351 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
6355 ;;; Sources to filter bookmark-extensions bookmarks.
6358 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6359 ;; If you want to enable google-maps in addressbook you will need
6360 ;; Julien Danjou google-maps-el package available here:
6361 ;; http://julien.danjou.info/google-maps-el.html
6363 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
6364 "Return a filtered `bookmark-alist' sorted alphabetically."
6366 with alist
= (if args
6367 (apply #'(lambda (x) (funcall fn x
)) args
)
6372 finally return
(sort sa
'string-lessp
)))
6377 (defvar anything-c-source-bmkext-addressbook
6378 '((name .
"Bookmark Addressbook")
6380 (require 'bookmark-extensions
)
6381 (bookmark-maybe-load-default-file)))
6382 (candidates . anything-c-bmkext-addressbook-setup-alist
)
6384 .
(lambda (candidate)
6385 (let ((bmk (anything-bookmark-get-bookmark-from-name
6387 (bookmark--jump-via bmk
'pop-to-buffer
))))
6388 (persistent-help .
"Show contact - Prefix with C-u to append")
6389 (filtered-candidate-transformer
6390 anything-c-adaptive-sort
6391 anything-c-highlight-bookmark
)
6392 (action .
(("Show Contact(s)"
6393 .
(lambda (candidate)
6394 (let* ((contacts (anything-marked-candidates))
6395 (current-prefix-arg (or anything-current-prefix-arg
6396 (> (length contacts
) 1))))
6398 (anything-bookmark-get-bookmark-from-name (car contacts
)))
6399 (anything-aif (cdr contacts
)
6400 (loop for bmk in it do
6402 (anything-bookmark-get-bookmark-from-name bmk
)))))))
6404 .
(lambda (candidate)
6405 (let* ((contacts (anything-marked-candidates))
6406 (bmk (anything-bookmark-get-bookmark-from-name
6408 (append (message-buffers)))
6410 (addressbook-set-mail-buffer1 bmk
'append
)
6411 (addressbook-set-mail-buffer1 bmk
))
6412 (setq contacts
(cdr contacts
))
6414 (loop for bmk in contacts do
6415 (addressbook-set-mail-buffer1 bmk
'append
))))))
6417 .
(lambda (candidate)
6418 (let ((bmk (anything-bookmark-get-bookmark-from-name
6420 (addressbook-bookmark-edit
6421 (assoc bmk bookmark-alist
)))))
6422 ("Insert Email at point"
6423 .
(lambda (candidate)
6424 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6426 (mlist (split-string
6428 'email
(assoc bmk bookmark-alist
))
6431 (if (> (length mlist
) 1)
6433 "Insert Mail Address: " mlist
:must-match t
)
6436 .
(lambda (candidate)
6437 (let ((bmk (anything-bookmark-get-bookmark-from-name
6439 (bookmark-show-annotation bmk
))))
6441 .
(lambda (candidate)
6442 (let ((bmk (anything-bookmark-get-bookmark-from-name
6444 (bookmark-edit-annotation bmk
))))
6446 .
(lambda (candidate)
6447 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6449 (full-bmk (assoc bmk bookmark-alist
)))
6450 (addressbook-google-map full-bmk
))))))))
6453 (defun anything-c-bmkext-addressbook-setup-alist ()
6454 "Specialized filter function for bookmarks w3m."
6455 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
6457 ;; W3m bookmarks from bookmark-extensions.
6458 (defvar anything-c-source-bookmark-w3m
6459 '((name .
"Bookmark W3m")
6461 (require 'bookmark-extensions
)
6462 (bookmark-maybe-load-default-file)))
6463 (candidates . anything-c-bookmark-w3m-setup-alist
)
6464 (filtered-candidate-transformer
6465 anything-c-adaptive-sort
6466 anything-c-highlight-bookmark
)
6468 ;; (anything 'anything-c-source-bookmark-w3m)
6470 (defun anything-c-bookmark-w3m-setup-alist ()
6471 "Specialized filter function for bookmarks w3m."
6472 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
6475 (defvar anything-c-source-bookmark-images
6476 '((name .
"Bookmark Images")
6478 (require 'bookmark-extensions
)
6479 (bookmark-maybe-load-default-file)))
6480 (candidates . anything-c-bookmark-images-setup-alist
)
6481 (filtered-candidate-transformer
6482 anything-c-adaptive-sort
6483 anything-c-highlight-bookmark
)
6485 ;; (anything 'anything-c-source-bookmark-images)
6487 (defun anything-c-bookmark-images-setup-alist ()
6488 "Specialized filter function for images bookmarks."
6489 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
6492 (defvar anything-c-source-bookmark-man
6493 '((name .
"Bookmark Woman&Man")
6495 (require 'bookmark-extensions
)
6496 (bookmark-maybe-load-default-file)))
6497 (candidates . anything-c-bookmark-man-setup-alist
)
6498 (filtered-candidate-transformer
6499 anything-c-adaptive-sort
6500 anything-c-highlight-bookmark
)
6502 ;; (anything 'anything-c-source-bookmark-man)
6504 (defun anything-c-bookmark-man-setup-alist ()
6505 "Specialized filter function for bookmarks w3m."
6506 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
6507 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
6510 (defvar anything-c-source-bookmark-gnus
6511 '((name .
"Bookmark Gnus")
6513 (require 'bookmark-extensions
)
6514 (bookmark-maybe-load-default-file)))
6515 (candidates . anything-c-bookmark-gnus-setup-alist
)
6516 (filtered-candidate-transformer
6517 anything-c-adaptive-sort
6518 anything-c-highlight-bookmark
)
6520 ;; (anything 'anything-c-source-bookmark-gnus)
6522 (defun anything-c-bookmark-gnus-setup-alist ()
6523 "Specialized filter function for bookmarks gnus."
6524 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
6527 (defvar anything-c-source-bookmark-info
6528 '((name .
"Bookmark Info")
6530 (require 'bookmark-extensions
)
6531 (bookmark-maybe-load-default-file)))
6532 (candidates . anything-c-bookmark-info-setup-alist
)
6533 (filtered-candidate-transformer
6534 anything-c-adaptive-sort
6535 anything-c-highlight-bookmark
)
6537 ;; (anything 'anything-c-source-bookmark-info)
6539 (defun anything-c-bookmark-info-setup-alist ()
6540 "Specialized filter function for bookmarks info."
6541 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
6543 ;; Local Files&directories
6544 (defvar anything-c-source-bookmark-files
&dirs
6545 '((name .
"Bookmark Files&Directories")
6547 (require 'bookmark-extensions
)
6548 (bookmark-maybe-load-default-file)))
6549 (candidates . anything-c-bookmark-local-files-setup-alist
)
6550 (filtered-candidate-transformer
6551 anything-c-adaptive-sort
6552 anything-c-highlight-bookmark
)
6554 ;; (anything 'anything-c-source-bookmark-files&dirs)
6556 (defun anything-c-bookmark-local-files-setup-alist ()
6557 "Specialized filter function for bookmarks locals files."
6558 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
6560 ;; Su Files&directories
6561 (defvar anything-c-source-bookmark-su-files
&dirs
6562 '((name .
"Bookmark Root-Files&Directories")
6564 (require 'bookmark-extensions
)
6565 (bookmark-maybe-load-default-file)))
6566 (candidates . anything-c-bookmark-su-files-setup-alist
)
6567 (filtered-candidate-transformer
6568 anything-c-adaptive-sort
6569 anything-c-highlight-bookmark-su
)
6571 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6573 (defun anything-c-bookmark-su-files-setup-alist ()
6574 "Specialized filter function for bookmarks su/sudo files."
6575 (declare (special bmkext-su-or-sudo-regexp
))
6577 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6579 for isfile
= (bookmark-get-filename i
)
6580 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
6582 (string-match tramp-file-name-regexp isfile
)))
6583 for issu
= (and istramp
6584 (string-match bmkext-su-or-sudo-regexp isfile
))
6588 ;; Ssh Files&directories
6589 (defvar anything-c-source-bookmark-ssh-files
&dirs
6590 '((name .
"Bookmark Ssh-Files&Directories")
6592 (require 'bookmark-extensions
)
6593 (bookmark-maybe-load-default-file)))
6594 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
6595 (filtered-candidate-transformer . anything-c-adaptive-sort
)
6597 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
6599 (defun anything-c-bookmark-ssh-files-setup-alist ()
6600 "Specialized filter function for bookmarks ssh files."
6602 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6604 for isfile
= (bookmark-get-filename i
)
6605 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
6607 (string-match tramp-file-name-regexp isfile
)))
6608 for isssh
= (and istramp
6609 (string-match "/ssh:" isfile
))
6615 ;;; Firefox bookmarks
6618 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
6619 ;; (only for firefox versions >=3)
6620 ;; To achieve that, open about:config in firefox and double click on this line to enable value
6622 ;; user_pref("browser.bookmarks.autoExportHTML", false);
6623 ;; You should have now:
6624 ;; user_pref("browser.bookmarks.autoExportHTML", true);
6626 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
6627 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
6629 (defun anything-get-firefox-user-init-dir ()
6630 "Guess the default Firefox user directory name."
6631 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
6633 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
6634 (goto-char (point-min))
6636 (when (search-forward "Path=" nil t
)
6637 (buffer-substring-no-properties (point) (point-at-eol)))
6639 (file-name-as-directory (concat moz-dir moz-user-dir
))))
6641 (defun anything-guess-firefox-bookmark-file ()
6642 "Return the path of the Firefox bookmarks file."
6643 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
6645 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
6646 "Parse html bookmark FILE and return an alist with (title . url) as elements."
6647 (let (bookmarks-alist url title
)
6649 (insert-file-contents file
)
6650 (goto-char (point-min))
6651 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
6653 (when (re-search-forward url-regexp nil t
)
6654 (setq url
(match-string 0)))
6655 (when (re-search-forward bmk-regexp nil t
)
6656 (setq title
(match-string 1)))
6657 (push (cons title url
) bookmarks-alist
)
6659 (nreverse bookmarks-alist
)))
6661 (defvar anything-c-firefox-bookmarks-alist nil
)
6662 (defvar anything-c-source-firefox-bookmarks
6663 '((name .
"Firefox Bookmarks")
6665 (setq anything-c-firefox-bookmarks-alist
6666 (anything-html-bookmarks-to-alist
6667 (anything-guess-firefox-bookmark-file)
6668 anything-firefox-bookmark-url-regexp
6669 anything-firefox-bookmarks-regexp
))))
6670 (candidates .
(lambda ()
6671 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
6672 (filtered-candidate-transformer
6673 anything-c-adaptive-sort
6674 anything-c-highlight-firefox-bookmarks
)
6675 (action .
(("Browse Url Firefox"
6676 .
(lambda (candidate)
6678 (anything-c-firefox-bookmarks-get-value candidate
))))
6680 .
(lambda (candidate)
6682 (anything-c-firefox-bookmarks-get-value candidate
))))
6685 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
6687 ;; (anything 'anything-c-source-firefox-bookmarks)
6689 (defun anything-c-firefox-bookmarks-get-value (elm)
6690 (assoc-default elm anything-c-firefox-bookmarks-alist
))
6692 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
6693 (loop for i in bookmarks
6695 i
'face
'((:foreground
"YellowGreen"))
6696 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
6700 ;;; W3m bookmark - anything interface.
6703 ;; Some users have the emacs-w3m library in load-path
6704 ;; without having the w3m executable :-;
6705 ;; So check if w3m program is present before trying to load
6708 (when (executable-find "w3m")
6709 (require 'w3m-bookmark nil t
)))
6711 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html")
6712 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
6713 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
6714 (defvar anything-c-w3m-bookmarks-alist nil
)
6715 (defvar anything-c-source-w3m-bookmarks
6716 '((name .
"W3m Bookmarks")
6718 (setq anything-c-w3m-bookmarks-alist
6719 (anything-html-bookmarks-to-alist
6721 anything-w3m-bookmark-url-regexp
6722 anything-w3m-bookmarks-regexp
))))
6723 (candidates .
(lambda ()
6724 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
6725 (filtered-candidate-transformer
6726 anything-c-adaptive-sort
6727 anything-c-highlight-w3m-bookmarks
)
6728 (action .
(("Browse Url"
6729 .
(lambda (candidate)
6730 (anything-c-w3m-browse-bookmark candidate
)))
6733 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
6734 ("Browse Url Firefox"
6735 .
(lambda (candidate)
6736 (anything-c-w3m-browse-bookmark candidate t
)))
6738 .
(lambda (candidate)
6739 (anything-c-w3m-delete-bookmark candidate
)))
6741 .
(lambda (candidate)
6742 (anything-c-w3m-rename-bookmark candidate
)))))
6743 (persistent-action .
(lambda (candidate)
6744 (if current-prefix-arg
6745 (anything-c-w3m-browse-bookmark candidate t
)
6746 (anything-c-w3m-browse-bookmark candidate nil t
))))
6747 (persistent-help .
"Open URL with emacs-w3m in new tab / \
6748 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
6749 "Needs w3m and emacs-w3m.
6751 http://w3m.sourceforge.net/
6752 http://emacs-w3m.namazu.org/")
6754 ;; (anything 'anything-c-source-w3m-bookmarks)
6756 (defun anything-c-w3m-bookmarks-get-value (elm)
6757 (replace-regexp-in-string
6758 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
6760 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
6761 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
6762 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
6763 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
6765 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
6766 (loop for i in bookmarks
6768 i
'face
'anything-w3m-bookmarks-face
6769 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
6772 (defun anything-c-w3m-delete-bookmark (elm)
6773 "Delete w3m bookmark from `w3m-bookmark-file'."
6774 (with-current-buffer
6775 (find-file-literally w3m-bookmark-file
)
6776 (goto-char (point-min))
6777 (when (re-search-forward elm nil t
)
6779 (delete-region (point)
6780 (line-end-position))
6781 (delete-blank-lines))
6785 (defun anything-c-w3m-rename-bookmark (elm)
6786 "Rename w3m bookmark in `w3m-bookmark-file'."
6787 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
6788 (new-title (read-string "NewTitle: " old-title
)))
6789 (with-current-buffer
6790 (find-file-literally w3m-bookmark-file
)
6791 (goto-char (point-min))
6792 (when (re-search-forward (concat elm
"<") nil t
)
6793 (goto-char (1- (point)))
6794 (delete-char (- (length old-title
)))
6801 ;;; Elisp library scan
6804 (defvar anything-c-source-elisp-library-scan
6805 '((name .
"Elisp libraries (Scan)")
6806 (init .
(anything-c-elisp-library-scan-init))
6807 (candidates-in-buffer)
6808 (action ("Find library"
6809 .
(lambda (candidate) (find-file (find-library-name candidate
))))
6810 ("Find library other window"
6811 .
(lambda (candidate)
6812 (find-file-other-window (find-library-name candidate
))))
6814 .
(lambda (candidate) (load-library candidate
))))))
6815 ;; (anything 'anything-c-source-elisp-library-scan)
6817 (defun anything-c-elisp-library-scan-init ()
6818 "Init anything buffer status."
6819 (let ((anything-buffer (anything-candidate-buffer 'global
))
6820 (library-list (anything-c-elisp-library-scan-list)))
6821 (with-current-buffer anything-buffer
6822 (dolist (library library-list
)
6823 (insert (format "%s\n" library
))))))
6825 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
6826 "Do completion for file names passed to `locate-file'.
6827 DIRS is directory to search path.
6828 STRING is string to match."
6829 ;; Use `load-path' as path when ignore `dirs'.
6830 (or dirs
(setq dirs load-path
))
6831 ;; Init with blank when ignore `string'.
6832 (or string
(setq string
""))
6833 ;; Get library list.
6834 (let ((string-dir (file-name-directory string
))
6835 ;; File regexp that suffix match `load-file-rep-suffixes'.
6836 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
6841 (setq dir default-directory
))
6843 (setq dir
(expand-file-name string-dir dir
)))
6844 (when (file-directory-p dir
)
6845 (dolist (file (file-name-all-completions
6846 (file-name-nondirectory string
) dir
))
6847 ;; Suffixes match `load-file-rep-suffixes'.
6848 (setq name
(if string-dir
(concat string-dir file
) file
))
6849 (if (string-match match-regexp name
)
6850 (add-to-list 'names name
)))))
6861 (defvar anything-c-imenu-delimiter
" / ")
6863 (defvar anything-c-imenu-index-filter nil
)
6864 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
6866 (defvar anything-c-cached-imenu-alist nil
)
6867 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
6869 (defvar anything-c-cached-imenu-candidates nil
)
6870 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
6872 (defvar anything-c-cached-imenu-tick nil
)
6873 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
6875 (eval-when-compile (require 'imenu
))
6876 (setq imenu-auto-rescan t
)
6878 (defun anything-imenu-create-candidates (entry)
6879 "Create candidates with ENTRY."
6880 (if (listp (cdr entry
))
6883 (if (consp (cdr sub
))
6886 (concat (car entry
) anything-c-imenu-delimiter subentry
))
6887 (anything-imenu-create-candidates sub
))
6888 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
6892 (defvar anything-c-source-imenu
6894 (init .
(lambda () (require 'imenu
)))
6895 (candidates . anything-c-imenu-candidates
)
6896 (persistent-action .
(lambda (elm)
6897 (anything-c-imenu-default-action elm
)
6898 (unless (fboundp 'semantic-imenu-tag-overlay
)
6899 (anything-match-line-color-current-line))))
6900 (persistent-help .
"Show this entry")
6901 (action . anything-c-imenu-default-action
))
6902 "See (info \"(emacs)Imenu\")")
6904 ;; (anything 'anything-c-source-imenu)
6906 (defun anything-c-imenu-candidates ()
6907 (with-anything-current-buffer
6908 (let ((tick (buffer-modified-tick)))
6909 (if (eq anything-c-cached-imenu-tick tick
)
6910 anything-c-cached-imenu-candidates
6911 (setq imenu--index-alist nil
)
6912 (setq anything-c-cached-imenu-tick tick
6913 anything-c-cached-imenu-candidates
6916 'anything-imenu-create-candidates
6917 (setq anything-c-cached-imenu-alist
6918 (let ((index (imenu--make-index-alist)))
6919 (if anything-c-imenu-index-filter
6920 (funcall anything-c-imenu-index-filter index
)
6922 (setq anything-c-cached-imenu-candidates
6923 (mapcar #'(lambda (x)
6927 anything-c-cached-imenu-candidates
))))))
6929 (setq imenu-default-goto-function
'imenu-default-goto-function
)
6930 (defun anything-c-imenu-default-action (elm)
6931 "The default action for `anything-c-source-imenu'."
6932 (let ((path (split-string elm anything-c-imenu-delimiter
))
6933 (alist anything-c-cached-imenu-alist
))
6935 (setq alist
(assoc elm alist
)))
6943 (defvar anything-c-ctags-modes
6944 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
6945 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
6946 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
6948 (defun anything-c-source-ctags-init ()
6949 (when (and buffer-file-name
6950 (memq major-mode anything-c-ctags-modes
)
6951 (anything-current-buffer-is-modified))
6952 (with-current-buffer (anything-candidate-buffer 'local
)
6953 (call-process-shell-command
6954 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
6955 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
6956 anything-buffer-file-name
)
6957 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
6958 nil
(current-buffer))
6959 (goto-char (point-min))
6961 (delete-region (point-min) (point))
6962 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
6963 for lineno-start
= (point)
6964 for lineno
= (buffer-substring
6966 (1- (search-forward "," (point-at-eol) t
)))
6969 (insert (format "%5s:" lineno
))
6970 (search-forward "\177" (point-at-eol) t
)
6971 (delete-region (1- (point)) (point-at-eol))
6972 (forward-line 1)))))
6974 (defvar anything-c-source-ctags
6975 '((name .
"Exuberant ctags")
6976 (init . anything-c-source-ctags-init
)
6977 (candidates-in-buffer)
6980 "Needs Exuberant Ctags.
6982 http://ctags.sourceforge.net/")
6983 ;; (anything 'anything-c-source-ctags)
6989 ;; anything-etags.el is deprecated, if this file is found,
6990 ;; warn user at compile time.
6992 (when (locate-library "anything-etags.el")
6995 "You are using obsolete library `anything-etags.el' and should remove it."
6998 (defvar anything-c-etags-tag-file-dir nil
6999 "Etags file directory.")
7000 (defvar anything-c-etags-mtime-alist nil
7001 "Store the last modification time of etags files here.")
7002 (defvar anything-c-etags-cache
(make-hash-table :test
'equal
)
7003 "Cache content of etags files used here for faster access.")
7005 (defun anything-c-etags-get-tag-file (&optional directory
)
7006 "Return the path of etags file if found."
7007 ;; Get tag file from `default-directory' or upper directory.
7008 (let ((current-dir (anything-c-etags-find-tag-file-directory
7009 (or directory default-directory
))))
7010 ;; Return nil if not find tag file.
7012 ;; Set tag file directory.
7013 (setq anything-c-etags-tag-file-dir current-dir
)
7014 (expand-file-name anything-c-etags-tag-file-name current-dir
))))
7016 (defun anything-c-etags-find-tag-file-directory (current-dir)
7017 "Try to find the directory containing tag file.
7018 If not found in CURRENT-DIR search in upper directory."
7019 (flet ((file-exists?
(dir)
7020 (let ((tag-path (expand-file-name
7021 anything-c-etags-tag-file-name dir
)))
7022 (and (stringp tag-path
)
7023 (file-exists-p tag-path
)
7024 (file-readable-p tag-path
)))))
7025 (loop with count
= 0
7026 until
(file-exists? current-dir
)
7027 ;; Return nil if outside the value of
7028 ;; `anything-c-etags-tag-file-search-limit'.
7029 if
(= count anything-c-etags-tag-file-search-limit
)
7031 ;; Or search upper directories.
7034 (setq current-dir
(expand-file-name (concat current-dir
"../")))
7035 finally return current-dir
)))
7037 (defun anything-c-source-etags-header-name (x)
7038 "Create header name for this anything etags session."
7040 (with-anything-current-buffer
7041 (anything-c-etags-get-tag-file))))
7043 (defmacro anything-c-etags-create-buffer
(file)
7044 "Create the `anything-buffer' based on contents of etags tag FILE."
7045 `(let* ((tag-fname ,file
)
7047 (split (with-current-buffer (find-file-noselect tag-fname
)
7049 (split-string (buffer-string) "\n" 'omit-nulls
)
7050 (setq max
(line-number-at-pos (point-max)))
7052 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max
)))
7056 for i in split for count from
0
7057 for elm
= (unless (string-match "^\x0c" i
)
7058 (anything-aif (string-match "\177" i
)
7061 do
(cond ((and elm
(string-match "^\\(.+\\),[0-9]+" elm
))
7062 (setq fname
(match-string 1 elm
)))
7063 (elm (setq cand
(concat fname
": " elm
)))
7064 (t (setq cand nil
)))
7066 (insert (concat cand
"\n"))
7067 (progress-reporter-update progress-reporter count
)))))
7069 (defun anything-c-etags-init ()
7070 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
7071 If no entry in cache, create one."
7072 (let ((tagfile (anything-c-etags-get-tag-file)))
7074 (with-current-buffer (anything-candidate-buffer 'global
)
7075 (anything-aif (gethash tagfile anything-c-etags-cache
)
7076 ;; An entry is present in cache, insert it.
7078 ;; No entry, create a new buffer using content of tag file (slower).
7079 (anything-c-etags-create-buffer tagfile
)
7080 ;; Store content of buffer in cache.
7081 (puthash tagfile
(buffer-string) anything-c-etags-cache
)
7082 ;; Store or set the last modification of tag file.
7083 (anything-aif (assoc tagfile anything-c-etags-mtime-alist
)
7084 ;; If an entry exists modify it.
7085 (setcdr it
(anything-c-etags-mtime tagfile
))
7086 ;; No entry create a new one.
7087 (add-to-list 'anything-c-etags-mtime-alist
7088 (cons tagfile
(anything-c-etags-mtime tagfile
)))))))))
7090 (defvar anything-c-source-etags-select
7092 (header-name . anything-c-source-etags-header-name
)
7093 (init . anything-c-etags-init
)
7094 (candidates-in-buffer)
7095 (search .
(anything-c-etags-search-fn))
7096 (mode-line . anything-etags-mode-line-string
)
7097 (action . anything-c-etags-default-action
)
7098 (persistent-action .
(lambda (candidate)
7099 (anything-c-etags-default-action candidate
)
7100 (anything-match-line-color-current-line))))
7101 "Anything source for Etags.")
7103 (defun anything-c-etags-search-fn (pattern)
7104 "Search function for `anything-c-source-etags-select'."
7106 (if anything-c-etags-use-regexp-search
7107 (format anything-c-etags-search-regexp pattern
)
7111 (defun anything-c-etags-default-action (candidate)
7112 "Anything default action to jump to an etags entry."
7113 (let* ((split (split-string candidate
": "))
7114 (fname (expand-file-name
7115 (car split
) anything-c-etags-tag-file-dir
))
7118 (goto-char (point-min))
7119 (search-forward elm nil t
)
7120 (goto-char (match-beginning 0))))
7122 (defun anything-c-etags-mtime (file)
7123 "Last modification time of etags tag FILE."
7124 (cadr (nth 5 (file-attributes file
))))
7126 (defun anything-c-etags-file-modified-p (file)
7127 "Check if tag FILE have been modified in this session.
7128 If FILE is nil return nil."
7129 (let ((last-modif (and file
7130 (assoc-default file anything-c-etags-mtime-alist
))))
7132 (/= last-modif
(anything-c-etags-mtime file
)))))
7139 (defvar anything-semantic-candidates nil
)
7141 (defun anything-semantic-construct-candidates (tags depth
)
7142 (when (require 'semantic nil t
)
7148 (let ((type (semantic-tag-type tag
))
7149 (class (semantic-tag-class tag
)))
7150 (if (or (and (stringp type
)
7151 (or (string= type
"class")
7152 (string= type
"namespace")))
7153 (eq class
'function
)
7154 (eq class
'variable
))
7155 (cons (cons (concat (make-string (* depth
2) ?\s
)
7156 (semantic-format-tag-summarize tag nil t
))
7158 (anything-semantic-construct-candidates
7159 (semantic-tag-components tag
) (1+ depth
)))))))
7162 (defun anything-semantic-default-action (candidate)
7163 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
7164 (semantic-go-to-tag tag
)))
7166 (defvar anything-c-source-semantic
7167 '((name .
"Semantic Tags")
7169 (setq anything-semantic-candidates
7170 (ignore-errors (anything-semantic-construct-candidates
7171 (semantic-fetch-tags) 0)))))
7172 (candidates .
(lambda ()
7173 (if anything-semantic-candidates
7174 (mapcar 'car anything-semantic-candidates
))))
7175 (persistent-action .
(lambda (elm)
7176 (anything-semantic-default-action elm
)
7177 (anything-match-line-color-current-line)))
7178 (persistent-help .
"Show this entry")
7179 (action . anything-semantic-default-action
)
7180 "Needs semantic in CEDET.
7182 http://cedet.sourceforge.net/semantic.shtml
7183 http://cedet.sourceforge.net/"))
7185 ;; (anything 'anything-c-source-semantic)
7188 ;;; Anything interface of `simple-call-tree.el'.
7190 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7192 ;; Function is called by
7193 (defvar anything-c-source-simple-call-tree-functions-callers
7194 '((name .
"Function is called by")
7195 (init . anything-c-simple-call-tree-functions-callers-init
)
7197 (candidates . anything-c-simple-call-tree-candidates
)
7198 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7199 (persistent-help .
"Show function definitions by rotation")
7200 (action ("Find definition selected by persistent-action" .
7201 anything-c-simple-call-tree-find-definition
)))
7202 "Needs simple-call-tree.el.
7203 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7205 (defvar anything-c-simple-call-tree-tick nil
)
7206 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
7207 (defun anything-c-simple-call-tree-analyze-maybe ()
7208 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
7209 (simple-call-tree-analyze)
7210 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
7212 (defun anything-c-simple-call-tree-init-base (function message
)
7213 (require 'simple-call-tree
)
7215 (when (anything-current-buffer-is-modified)
7216 (anything-c-simple-call-tree-analyze-maybe)
7217 (let ((list (funcall function simple-call-tree-alist
)))
7218 (with-current-buffer (anything-candidate-buffer 'local
)
7219 (dolist (entry list
)
7220 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
7221 (insert (car entry
) message
7222 (if (string= funcs
" ")
7227 (defun anything-c-simple-call-tree-functions-callers-init ()
7228 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7231 (defun anything-c-simple-call-tree-candidates ()
7232 (with-current-buffer (anything-candidate-buffer)
7233 (split-string (buffer-string) "\n\n")))
7235 (defvar anything-c-simple-call-tree-related-functions nil
)
7236 (defvar anything-c-simple-call-tree-function-index
0)
7237 (defun anything-c-simple-call-tree-persistent-action (candidate)
7238 (unless (eq last-command
'anything-execute-persistent-action
)
7239 (setq anything-c-simple-call-tree-related-functions
7240 (delete "no functions."
7242 (replace-regexp-in-string " \\| is called by\\| calls "
7245 (setq anything-c-simple-call-tree-function-index -
1))
7246 (incf anything-c-simple-call-tree-function-index
)
7247 (anything-c-simple-call-tree-find-definition candidate
))
7249 (defun anything-c-simple-call-tree-find-definition (candidate)
7252 (nth (mod anything-c-simple-call-tree-function-index
7253 (length anything-c-simple-call-tree-related-functions
))
7254 anything-c-simple-call-tree-related-functions
))))
7256 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7259 (defvar anything-c-source-simple-call-tree-callers-functions
7260 '((name .
"Function calls")
7261 (init . anything-c-simple-call-tree-callers-functions-init
)
7263 (candidates . anything-c-simple-call-tree-candidates
)
7264 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7265 (persistent-help .
"Show function definitions by rotation")
7266 (action ("Find definition selected by persistent-action" .
7267 anything-c-simple-call-tree-find-definition
)))
7268 "Needs simple-call-tree.el.
7269 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7271 (defun anything-c-simple-call-tree-callers-functions-init ()
7272 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
7274 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7278 ;;; Anything UI of auto-document.el
7280 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7282 ;; Commands/Options with doc
7283 (defvar anything-c-auto-document-data nil
)
7284 (make-variable-buffer-local 'anything-c-auto-document-data
)
7285 (defvar anything-c-source-commands-and-options-in-file
7286 '((name .
"Commands/Options in file")
7288 .
(lambda (x) (format "Commands/Options in %s"
7289 (buffer-local-value 'buffer-file-name
7290 anything-current-buffer
))))
7291 (candidates . anything-command-and-options-candidates
)
7294 "List Commands and Options with doc. It needs auto-document.el .
7296 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7298 (eval-when-compile (require 'auto-document nil t
))
7299 (defun anything-command-and-options-candidates ()
7300 (with-anything-current-buffer
7301 (when (and (require 'auto-document nil t
)
7302 (eq major-mode
'emacs-lisp-mode
)
7303 (or (anything-current-buffer-is-modified)
7304 (not anything-c-auto-document-data
)))
7305 (or imenu--index-alist
(imenu--make-index-alist t
))
7306 (setq anything-c-auto-document-data
7307 (destructuring-bind (commands options
)
7308 (adoc-construct anything-current-buffer
)
7310 (loop for
(command . doc
) in commands
7311 for cmdname
= (symbol-name command
)
7314 (format "Command: %s\n %s"
7315 (propertize cmdname
'face font-lock-function-name-face
)
7316 (adoc-first-line doc
))
7317 (assoc cmdname imenu--index-alist
)))
7318 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
7319 for
(option doc default
) in options
7320 for optname
= (symbol-name option
)
7323 (format "Option: %s\n %s\n default = %s"
7324 (propertize optname
'face font-lock-variable-name-face
)
7325 (adoc-first-line doc
)
7326 (adoc-prin1-to-string default
))
7329 anything-c-auto-document-data
))
7331 ;; (anything 'anything-c-source-commands-and-options-in-file)
7334 ;;;; <Color and Face>
7340 (defvar anything-c-source-customize-face
7341 '((name .
"Customize Face")
7343 (unless (anything-candidate-buffer)
7344 (save-selected-window
7345 (list-faces-display))
7346 (anything-candidate-buffer (get-buffer "*Faces*")))))
7347 (candidates-in-buffer)
7348 (get-line . buffer-substring
)
7349 (action .
(lambda (line)
7350 (customize-face (intern (car (split-string line
))))))
7351 (requires-pattern .
3))
7352 "See (info \"(emacs)Faces\")")
7353 ;; (anything 'anything-c-source-customize-face)
7358 (defvar anything-c-source-colors
7360 (init .
(lambda () (unless (anything-candidate-buffer)
7361 (save-selected-window
7362 (list-colors-display))
7363 (anything-candidate-buffer (get-buffer "*Colors*")))))
7364 (candidates-in-buffer)
7365 (get-line . buffer-substring
)
7367 ("Copy Name" .
(lambda (candidate)
7368 (kill-new (anything-c-colors-get-name candidate
))))
7369 ("Copy RGB" .
(lambda (candidate)
7370 (kill-new (anything-c-colors-get-rgb candidate
))))
7371 ("Insert Name" .
(lambda (candidate)
7372 (with-anything-current-buffer
7373 (insert (anything-c-colors-get-name candidate
)))))
7374 ("Insert RGB" .
(lambda (candidate)
7375 (with-anything-current-buffer
7376 (insert (anything-c-colors-get-rgb candidate
))))))))
7377 ;; (anything 'anything-c-source-colors)
7379 (defun anything-c-colors-get-name (candidate)
7381 (replace-regexp-in-string
7384 (insert (capitalize candidate
))
7385 (goto-char (point-min))
7386 (search-forward-regexp "\\s-\\{2,\\}")
7387 (delete-region (point) (point-max))
7390 (defun anything-c-colors-get-rgb (candidate)
7392 (replace-regexp-in-string
7395 (insert (capitalize candidate
))
7396 (goto-char (point-max))
7397 (search-backward-regexp "\\s-\\{2,\\}")
7398 (delete-region (point) (point-min))
7402 ;;;; <Search Engine>
7403 ;;; Tracker desktop search
7404 (defvar anything-c-source-tracker-search
7405 '((name .
"Tracker Search")
7406 (candidates .
(lambda ()
7407 (start-process "tracker-search-process" nil
7411 (requires-pattern .
3)
7413 "Source for retrieving files matching the current input pattern
7414 with the tracker desktop search.")
7415 ;; (anything 'anything-c-source-tracker-search)
7417 ;;; Spotlight (MacOS X desktop search)
7418 (defvar anything-c-source-mac-spotlight
7421 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
7423 (requires-pattern .
3)
7425 "Source for retrieving files via Spotlight's command line
7427 ;; (anything 'anything-c-source-mac-spotlight)
7430 (defvar anything-c-source-picklist
7431 '((name .
"Picklist")
7432 (candidates .
(lambda () (mapcar 'car picklist-list
)))
7434 ;; (anything 'anything-c-source-picklist)
7441 (defvar anything-c-source-kill-ring
7442 '((name .
"Kill Ring")
7443 (init .
(lambda () (anything-attrset 'last-command last-command
)))
7444 (candidates . anything-c-kill-ring-candidates
)
7445 (filtered-candidate-transformer anything-c-kill-ring-transformer
)
7446 (action . anything-c-kill-ring-action
)
7450 "Source for browse and insert contents of kill-ring.")
7452 (defun anything-c-kill-ring-candidates ()
7453 (loop for kill in
(anything-fast-remove-dups kill-ring
:test
'equal
)
7454 unless
(or (< (length kill
) anything-kill-ring-threshold
)
7455 (string-match "^[\\s\\t]+$" kill
))
7458 (defun anything-c-kill-ring-transformer (candidates source
)
7459 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7460 (loop for i in candidates
7461 for nlines
= (with-temp-buffer (insert i
) (count-lines (point-min) (point-max)))
7462 if
(and anything-c-kill-ring-max-lines-number
7463 (> nlines anything-c-kill-ring-max-lines-number
))
7467 (goto-char (point-min))
7472 (forward-line anything-c-kill-ring-max-lines-number
)
7477 (defun anything-c-kill-ring-action (str)
7478 "Insert STR in `kill-ring' and set STR to the head.
7479 If this action is executed just after `yank',
7480 replace with STR as yanked string."
7481 (setq kill-ring
(delete str kill-ring
))
7482 (if (not (eq (anything-attr 'last-command
) 'yank
))
7483 (insert-for-yank str
)
7485 (let ((inhibit-read-only t
)
7486 (before (< (point) (mark t
))))
7488 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
7489 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
7490 (setq yank-undo-function nil
)
7491 (set-marker (mark-marker) (point) (current-buffer))
7492 (insert-for-yank str
)
7493 ;; Set the window start back where it was in the yank command,
7495 (set-window-start (selected-window) yank-window-start t
)
7497 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7498 ;; It is cleaner to avoid activation, even though the command
7499 ;; loop would deactivate the mark because we inserted text.
7500 (goto-char (prog1 (mark t
)
7501 (set-marker (mark-marker) (point) (current-buffer)))))))
7504 ;; (anything 'anything-c-source-kill-ring)
7508 ;; DO NOT include these sources in `anything-sources' use
7509 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7510 ;; `anything-all-mark-rings' instead.
7512 (defun anything-c-source-mark-ring-candidates ()
7513 (flet ((get-marks (pos)
7517 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
7518 (when (string= "" line
)
7519 (setq line
"<EMPTY LINE>"))
7520 (format "%7d: %s" (line-number-at-pos) line
)))))
7521 (with-anything-current-buffer
7523 with marks
= (if (mark) (cons (mark-marker) mark-ring
) mark-ring
)
7526 for m
= (get-marks i
)
7527 unless
(member m recip
)
7528 collect m into recip
7529 finally return recip
))))
7531 (defvar anything-mark-ring-cache nil
)
7532 (defvar anything-c-source-mark-ring
7533 '((name .
"mark-ring")
7535 (setq anything-mark-ring-cache
7536 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7537 (candidates .
(lambda ()
7538 (anything-aif anything-mark-ring-cache
7540 (action .
(("Goto line"
7541 .
(lambda (candidate)
7542 (anything-goto-line (string-to-number candidate
))))))
7543 (persistent-action .
(lambda (candidate)
7544 (anything-goto-line (string-to-number candidate
))
7545 (anything-match-line-color-current-line)))
7546 (persistent-help .
"Show this line")))
7548 ;; (anything 'anything-c-source-mark-ring)
7550 ;;; Global-mark-ring
7551 (defvar anything-c-source-global-mark-ring
7552 '((name .
"global-mark-ring")
7553 (candidates . anything-c-source-global-mark-ring-candidates
)
7554 (action .
(("Goto line"
7555 .
(lambda (candidate)
7556 (let ((items (split-string candidate
":")))
7557 (anything-c-switch-to-buffer (second items
))
7558 (anything-goto-line (string-to-number (car items
))))))))
7559 (persistent-action .
(lambda (candidate)
7560 (let ((items (split-string candidate
":")))
7561 (anything-c-switch-to-buffer (second items
))
7562 (anything-goto-line (string-to-number (car items
)))
7563 (anything-match-line-color-current-line))))
7564 (persistent-help .
"Show this line")))
7566 (defun anything-c-source-global-mark-ring-candidates ()
7568 (with-current-buffer (marker-buffer m
)
7572 (if (string= "" line
)
7573 (setq line
"<EMPTY LINE>")
7574 (setq line
(car (split-string (thing-at-point 'line
)
7576 (format "%7d:%s: %s"
7577 (line-number-at-pos) (marker-buffer m
) line
)))))
7579 with marks
= global-mark-ring
7582 for gm
= (unless (or (string-match
7583 "^ " (format "%s" (marker-buffer i
)))
7584 (null (marker-buffer i
)))
7586 when
(and gm
(not (member gm recip
)))
7587 collect gm into recip
7588 finally return recip
)))
7590 ;; (anything 'anything-c-source-global-mark-ring)
7594 ;;; Insert from register
7595 (defvar anything-c-source-register
7596 '((name .
"Registers")
7597 (candidates . anything-c-register-candidates
)
7598 (action-transformer . anything-c-register-action-transformer
)
7601 "See (info \"(emacs)Registers\")")
7603 (defun anything-c-register-candidates ()
7604 "Collecting register contents and appropriate commands."
7605 (loop for
(char . val
) in register-alist
7606 for key
= (single-key-description char
)
7607 for string-actions
=
7610 (list (int-to-string val
)
7612 'increment-register
))
7614 (let ((buf (marker-buffer val
)))
7616 (list "a marker in no buffer")
7618 "a buffer position:"
7621 (int-to-string (marker-position val
)))
7623 'insert-register
))))
7624 ((and (consp val
) (window-configuration-p (car val
)))
7625 (list "window configuration."
7627 ((and (consp val
) (frame-configuration-p (car val
)))
7628 (list "frame configuration."
7630 ((and (consp val
) (eq (car val
) 'file
))
7631 (list (concat "file:"
7632 (prin1-to-string (cdr val
))
7635 ((and (consp val
) (eq (car val
) 'file-query
))
7636 (list (concat "file:a file-query reference: file "
7639 (int-to-string (car (cdr (cdr val
))))
7643 (let ((lines (format "%4d" (length val
))))
7644 (list (format "%s: %s\n" lines
7645 (truncate-string-to-width
7646 (mapconcat 'identity
(list (car val
))
7647 ;; (mapconcat (lambda (y) y) val
7648 "^J") (- (window-width) 15)))
7651 (list ;; without properties
7652 (substring-no-properties val
)
7655 'prepend-to-register
))
7658 collect
(cons (format "register %3s: %s" key
(car string-actions
))
7659 (cons char
(cdr string-actions
)))))
7661 (defun anything-c-register-action-transformer (actions register-and-functions
)
7662 "Decide actions by the contents of register."
7663 (loop with func-actions
=
7666 (lambda (c) (insert-register (car c
))))
7668 "Jump to Register" .
7669 (lambda (c) (jump-to-register (car c
))))
7671 "Append Region to Register" .
7672 (lambda (c) (append-to-register
7673 (car c
) (region-beginning) (region-end))))
7674 (prepend-to-register
7675 "Prepend Region to Register" .
7676 (lambda (c) (prepend-to-register
7677 (car c
) (region-beginning) (region-end))))
7679 "Increment Prefix Arg to Register" .
7680 (lambda (c) (increment-register
7681 anything-current-prefix-arg
(car c
)))))
7682 for func in
(cdr register-and-functions
)
7683 for cell
= (assq func func-actions
)
7685 collect
(cdr cell
)))
7687 ;; (anything 'anything-c-source-register)
7690 ;;; Latex completion
7691 (defun anything-c-latex-math-candidates ()
7692 "Collect candidates for latex math completion."
7693 (declare (special LaTeX-math-menu
))
7694 (loop for i in
(cddr LaTeX-math-menu
)
7695 for elm
= (loop for s in i when
(vectorp s
)
7696 collect
(cons (aref s
0) (aref s
1)))
7699 (defvar anything-c-source-latex-math
7700 '((name .
"Latex Math Menu")
7702 (with-anything-current-buffer
7703 (LaTeX-math-mode 1))))
7704 (candidate-number-limit .
9999)
7705 (candidates . anything-c-latex-math-candidates
)
7706 (action .
(lambda (candidate)
7707 (call-interactively candidate
)))))
7710 ;;;; <Headline Extraction>
7711 (defvar anything-c-source-fixme
7712 '((name .
"TODO/FIXME/DRY comments")
7713 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
7716 "Show TODO/FIXME/DRY comments in current file.")
7717 ;; (anything 'anything-c-source-fixme)
7719 (defvar anything-c-source-rd-headline
7720 '((name .
"RD HeadLine")
7721 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
7722 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
7728 http://en.wikipedia.org/wiki/Ruby_Document_format")
7729 ;; (anything 'anything-c-source-rd-headline)
7731 (defvar anything-c-source-oddmuse-headline
7732 '((name .
"Oddmuse HeadLine")
7733 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
7734 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
7735 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
7738 "Show Oddmuse headlines, such as EmacsWiki.")
7739 ;; (anything 'anything-c-source-oddmuse-headline)
7741 (defvar anything-c-source-emacs-source-defun
7742 '((name .
"Emacs Source DEFUN")
7743 (headline .
"DEFUN\\|DEFVAR")
7744 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
7745 (or buffer-file-name
""))))
7746 "Show DEFUN/DEFVAR in Emacs C source file.")
7747 ;; (anything 'anything-c-source-emacs-source-defun)
7749 (defvar anything-c-source-emacs-lisp-expectations
7750 '((name .
"Emacs Lisp Expectations")
7751 (headline .
"(desc[ ]\\|(expectations")
7752 (condition .
(eq major-mode
'emacs-lisp-mode
)))
7753 "Show descriptions (desc) in Emacs Lisp Expectations.
7755 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7756 ;; (anything 'anything-c-source-emacs-lisp-expectations)
7758 (defvar anything-c-source-emacs-lisp-toplevels
7759 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
7760 (headline .
"^(\\|(@\\*\\|^;;;;")
7761 (get-line . buffer-substring
)
7762 (condition .
(eq major-mode
'emacs-lisp-mode
))
7764 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
7765 linkd.el is optional because linkd stars are extracted by regexp.
7766 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
7767 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
7770 ;;; Anything yaoddmuse
7772 ;; Be sure to have yaoddmuse.el installed
7773 ;; install-elisp may be required if you want to install elisp file from here.
7774 (defvar anything-yaoddmuse-use-cache-file nil
)
7775 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
7776 (defvar anything-c-yaoddmuse-ew-cache nil
)
7778 (defun anything-yaoddmuse-get-candidates ()
7779 (declare (special yaoddmuse-pages-hash
))
7780 (if anything-yaoddmuse-use-cache-file
7782 (unless anything-c-yaoddmuse-ew-cache
7783 (load anything-c-yaoddmuse-cache-file
)
7784 (setq anything-c-yaoddmuse-ew-cache
7785 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7786 anything-c-yaoddmuse-ew-cache
)
7787 (yaoddmuse-update-pagename t
)
7788 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7790 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
7791 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
7792 (candidates . anything-yaoddmuse-get-candidates
)
7793 (action .
(("Edit page" .
(lambda (candidate)
7794 (yaoddmuse-edit "EmacsWiki" candidate
)))
7796 .
(lambda (candidate)
7797 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
7798 ("Browse page other window"
7799 .
(lambda (candidate)
7801 (split-window-vertically))
7802 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
7804 .
(lambda (candidate)
7805 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
7807 .
(lambda (candidate)
7808 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
7809 (message "Have copy page %s's URL to yank." candidate
)))
7811 .
(lambda (candidate)
7812 (yaoddmuse-edit "EmacsWiki" anything-input
)))
7814 .
(lambda (candidate)
7815 (if anything-yaoddmuse-use-cache-file
7817 (anything-yaoddmuse-cache-pages t
)
7818 (setq anything-c-yaoddmuse-ew-cache
7819 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
7820 (yaoddmuse-update-pagename))))))
7821 (action-transformer anything-c-yaoddmuse-action-transformer
))
7822 "Needs yaoddmuse.el.
7824 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7826 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
7828 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
7829 '((name .
"Yaoddmuse Post library (EmacsWiki)")
7830 (init .
(anything-yaoddmuse-init))
7831 (candidates-in-buffer)
7832 (action .
(("Post library and Browse"
7833 .
(lambda (candidate)
7834 (yaoddmuse-post-file
7835 (find-library-name candidate
)
7837 (file-name-nondirectory (find-library-name candidate
))
7840 .
(lambda (candidate)
7841 (yaoddmuse-post-file
7842 (find-library-name candidate
)
7844 (file-name-nondirectory
7845 (find-library-name candidate
))))))))
7846 "Needs yaoddmuse.el.
7848 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
7850 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
7852 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
7853 "Allow the use of `install-elisp' only on elisp files."
7854 (if (string-match "\.el$" candidate
)
7855 (append actions
'(("Install Elisp"
7857 (install-elisp-from-emacswiki elm
)))))
7861 (defun anything-yaoddmuse-cache-pages (&optional load
)
7862 "Fetch the list of files on emacswiki and create cache file.
7863 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
7865 (declare (special yaoddmuse-pages-hash
))
7866 (yaoddmuse-update-pagename)
7868 (find-file anything-c-yaoddmuse-cache-file
)
7870 (insert "(puthash \"EmacsWiki\" '(")
7871 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
7873 (insert (concat "(\"" (car i
) "\") ")))
7874 (insert ") yaoddmuse-pages-hash)\n")
7876 (kill-buffer (current-buffer))
7877 (when (or current-prefix-arg
7879 (load anything-c-yaoddmuse-cache-file
))))
7881 (defun anything-yaoddmuse-init ()
7882 "Init anything buffer status."
7883 (let ((anything-buffer (anything-candidate-buffer 'global
))
7884 (library-list (yaoddmuse-get-library-list)))
7885 (with-current-buffer anything-buffer
7886 ;; Insert library name.
7887 (dolist (library library-list
)
7888 (insert (format "%s\n" library
)))
7890 (sort-lines nil
(point-min) (point-max)))))
7894 (defvar anything-c-source-eev-anchor
7895 '((name .
"Anchors")
7899 (with-anything-current-buffer
7900 (loop initially
(goto-char (point-min))
7901 while
(re-search-forward
7902 (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
7903 for anchor
= (match-string-no-properties 1)
7904 collect
(cons (format "%5d:%s"
7905 (line-number-at-pos (match-beginning 0))
7906 (format ee-anchor-format anchor
))
7908 (persistent-action .
(lambda (item)
7910 (anything-match-line-color-current-line)))
7911 (persistent-help .
"Show this entry")
7912 (action .
(("Goto link" . ee-to
)))))
7913 ;; (anything 'anything-c-source-eev-anchor)
7919 (defvar anything-c-source-org-headline
7920 `((name .
"Org HeadLine")
7924 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
7926 (number-sequence 1 8)))
7927 (condition .
(eq major-mode
'org-mode
))
7930 (persistent-action .
(lambda (elm)
7931 (anything-c-action-line-goto elm
)
7934 .
(lambda (actions candidate
)
7935 '(("Go to Line" . anything-c-action-line-goto
)
7936 ("Refile to this Headline" . anything-c-org-headline-refile
)
7937 ("Insert Link to This Headline"
7938 . anything-c-org-headline-insert-link-to-headline
)))))
7939 "Show Org headlines.
7940 org-mode is very very much extended text-mode/outline-mode.
7942 See (find-library \"org.el\")
7943 See http://orgmode.org for the latest version.")
7944 ;; (anything 'anything-c-source-org-headline)
7946 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
7949 (anything-goto-line (car lineno-and-content
))
7950 (and (looking-at org-complex-heading-regexp
)
7951 (org-make-link-string (concat "*" (match-string 4)))))))
7953 (defun anything-c-org-headline-refile (lineno-and-content)
7954 "Refile current org entry to LINENO-AND-CONTENT."
7955 (with-anything-current-buffer
7957 (anything-goto-line (car lineno-and-content
))
7958 (org-end-of-subtree t t
)
7959 (let ((org-yank-adjusted-subtrees t
))
7966 (defvar anything-c-source-org-keywords
7967 '((name .
"Org Keywords")
7968 (init . anything-c-org-keywords-init
)
7969 (candidates . anything-c-org-keywords-candidates
)
7970 (action . anything-c-org-keywords-insert
)
7971 (persistent-action . anything-c-org-keywords-show-help
)
7972 (persistent-help .
"Show an example and info page to describe this keyword.")
7975 ;; (anything 'anything-c-source-org-keywords)
7977 (defvar anything-c-org-keywords-info-location
7978 '(("#+TITLE:" .
"(org)Export options")
7979 ("#+AUTHOR:" .
"(org)Export options")
7980 ("#+DATE:" .
"(org)Export options")
7981 ("#+EMAIL:" .
"(org)Export options")
7982 ("#+DESCRIPTION:" .
"(org)Export options")
7983 ("#+KEYWORDS:" .
"(org)Export options")
7984 ("#+LANGUAGE:" .
"(org)Export options")
7985 ("#+TEXT:" .
"(org)Export options")
7986 ("#+TEXT:" .
"(org)Export options")
7987 ("#+OPTIONS:" .
"(org)Export options")
7988 ("#+BIND:" .
"(org)Export options")
7989 ("#+LINK_UP:" .
"(org)Export options")
7990 ("#+LINK_HOME:" .
"(org)Export options")
7991 ("#+LATEX_HEADER:" .
"(org)Export options")
7992 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
7993 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
7994 ("#+INFOJS_OPT" .
"(org)Javascript support")
7995 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
7996 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
7997 ("#+ORGTBL" .
"(org)Radio tables")
7998 ("#+HTML:" .
"(org)Quoting HTML tags")
7999 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
8000 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
8001 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
8002 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
8003 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
8004 ("#+BEGIN_SRC" .
"(org)Literal examples")
8005 ("#+CAPTION" .
"(org)Tables in HTML export")
8006 ("#+LABEL" .
"(org)Tables in LaTeX export")
8007 ("#+ATTR_HTML" .
"(org)Links")
8008 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
8010 (defun anything-c-org-keywords-init ()
8011 (unless (anything-attr 'keywords-examples
)
8013 (anything-attrset 'keywords-examples
8017 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
8018 (cons (match-string 2 x
) (match-string 1 x
)))
8019 (org-split-string (org-get-current-options) "\n"))
8020 (mapcar 'list org-additional-option-like-keywords
)))
8021 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
8023 (defun anything-c-org-keywords-candidates ()
8024 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
8025 (eq (buffer-local-value 'major-mode anything-current-buffer
) 'message-mode
))
8026 (anything-attr 'keywords
)))
8028 (defun anything-c-org-keywords-insert (keyword)
8029 (cond ((and (string-match "BEGIN" keyword
)
8030 (anything-region-active-p))
8031 (let ((beg (region-beginning))
8034 (insert "\n#+" (replace-regexp-in-string
8035 "BEGIN" "END" keyword
) "\n")
8037 (insert "#+" keyword
" ")
8038 (save-excursion (insert "\n"))))
8039 ((string-match "BEGIN" keyword
)
8040 (insert "#+" keyword
" ")
8042 (insert "\n#+" (replace-regexp-in-string
8043 "BEGIN" "END" keyword
) "\n")))
8044 (t (insert "#+" keyword
" "))))
8046 (defun anything-c-org-keywords-show-help (keyword)
8047 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
8048 "(org)In-buffer settings"))
8049 (search-forward (concat "#+" keyword
) nil t
)
8050 (anything-persistent-highlight-point)
8051 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
8058 (defvar bbdb-records
)
8059 (defvar bbdb-buffer-name
)
8061 (defun anything-c-bbdb-candidates ()
8062 "Return a list of all names in the bbdb database. The format
8063 is \"Firstname Lastname\"."
8064 (mapcar (lambda (bbdb-record)
8065 (replace-regexp-in-string
8067 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
8070 (defun anything-c-bbdb-create-contact (actions candidate
)
8071 "Action transformer that returns only an entry to add the
8072 current `anything-pattern' as new contact. All other actions are
8074 (if (string= candidate
"*Add to contacts*")
8075 '(("Add to contacts" .
(lambda (actions)
8076 (bbdb-create-internal
8077 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
8078 (read-from-minibuffer "Company: ")
8079 (read-from-minibuffer "Email: ")
8082 (read-from-minibuffer "Note: ")))))
8085 (defun anything-c-bbdb-get-record (candidate)
8086 "Return record that match CANDIDATE."
8087 (bbdb candidate nil
)
8088 (set-buffer "*BBDB*")
8089 (bbdb-current-record))
8091 (defvar anything-c-bbdb-name nil
8092 "Only for internal use.")
8094 (defvar anything-c-source-bbdb
8096 (candidates . anything-c-bbdb-candidates
)
8097 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
8098 ("View person's data" . anything-c-bbdb-view-person-action
))
8099 (filtered-candidate-transformer .
(lambda (candidates source
)
8100 (setq anything-c-bbdb-name anything-pattern
)
8101 (if (not candidates
)
8102 (list "*Add to contacts*")
8104 (action-transformer .
(lambda (actions candidate
)
8105 (anything-c-bbdb-create-contact actions candidate
))))
8108 http://bbdb.sourceforge.net/")
8109 ;; (anything 'anything-c-source-bbdb)
8111 (defun anything-c-bbdb-view-person-action (candidate)
8112 "View BBDB data of single CANDIDATE or marked candidates."
8113 (anything-aif (anything-marked-candidates)
8114 (let ((bbdb-append-records (length it
)))
8116 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
8117 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
8119 (defun anything-c-bbdb-collect-mail-addresses ()
8120 "Return a list of all mail addresses of records in bbdb buffer."
8121 (with-current-buffer bbdb-buffer-name
8122 (loop for i in bbdb-records
8123 if
(bbdb-record-net (car i
))
8124 collect
(bbdb-dwim-net-address (car i
)))))
8126 (defun anything-c-bbdb-compose-mail (candidate)
8127 "Compose a mail with all records of bbdb buffer."
8128 (anything-c-bbdb-view-person-action candidate
)
8129 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8130 (address-str (mapconcat 'identity address-list
",\n ")))
8131 (compose-mail address-str
)))
8134 ;;; Evaluation Result
8138 (defvar anything-eldoc-active-minibuffers-list nil
)
8139 (defvar anything-eval-expression-input-history nil
)
8141 (defvar anything-c-source-evaluation-result
8142 '((name .
"Evaluation Result")
8146 (mode-line .
"C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8147 (filtered-candidate-transformer .
(lambda (candidates source
)
8150 (with-anything-current-buffer
8152 (eval (read anything-pattern
))))
8154 (action .
(("Copy result to kill-ring" .
(lambda (candidate)
8155 (with-current-buffer anything-buffer
8156 (let ((end (save-excursion
8157 (goto-char (point-max))
8158 (search-backward "\n")
8160 (kill-region (point) end
)))))
8161 ("copy sexp to kill-ring" .
(lambda (candidate)
8162 (kill-new anything-input
)))))))
8163 ;; (anything 'anything-c-source-evaluation-result)
8165 (defun anything-eval-new-line-and-indent ()
8167 (newline) (lisp-indent-line))
8169 (defun anything-eldoc-store-minibuffer ()
8170 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8171 (with-selected-window (minibuffer-window)
8172 (push (buffer-name) anything-eldoc-active-minibuffers-list
)))
8174 (defun anything-eldoc-show-in-eval ()
8175 "Return eldoc in mode-line for current minibuffer input."
8176 (let ((buf (with-selected-window (minibuffer-window)
8178 (when (member buf anything-eldoc-active-minibuffers-list
)
8179 (let* ((str-all (with-current-buffer buf
8180 (minibuffer-completion-contents)))
8184 (goto-char (point-max))
8185 (unless (looking-back ")\\|\"") (forward-char -
1))
8186 (eldoc-current-symbol))))
8187 (info-fn (eldoc-fnsym-in-current-sexp))
8188 (doc (or (eldoc-get-var-docstring sym
)
8189 (eldoc-get-fnsym-args-string
8190 (car info-fn
) (cadr info-fn
)))))
8191 (when doc
(funcall anything-c-eldoc-in-minibuffer-show-fn doc
))))))
8193 (defun anything-c-show-info-in-mode-line (str)
8194 "Display string STR in mode-line."
8195 (save-selected-window
8196 (with-current-buffer anything-buffer
8197 (let ((mode-line-format (concat " " str
)))
8198 (force-mode-line-update)
8199 (sit-for anything-c-show-info-in-mode-line-delay
))
8200 (force-mode-line-update))))
8202 ;;; Calculation Result
8205 (defvar anything-c-source-calculation-result
8206 '((name .
"Calculation Result")
8208 (filtered-candidate-transformer .
(lambda (candidates source
)
8211 (calc-eval anything-pattern
)
8213 (action ("Copy result to kill-ring" . kill-new
))))
8214 ;; (anything 'anything-c-source-calculation-result)
8217 ;;; Google Suggestions
8221 (defvar anything-ggs-max-length-real-flag
0)
8222 (defvar anything-ggs-max-length-num-flag
0)
8224 (defun anything-c-google-suggest-fetch (input)
8225 "Fetch suggestions for INPUT from XML buffer.
8226 Return an alist with elements like (data . number_results)."
8227 (setq anything-ggs-max-length-real-flag
0
8228 anything-ggs-max-length-num-flag
0)
8229 (let ((request (concat anything-c-google-suggest-url
8230 (url-hexify-string input
))))
8233 with result-alist
= (xml-get-children
8234 (car (xml-parse-region
8235 (point-min) (point-max)))
8236 'CompleteSuggestion
)
8237 for i in result-alist
8238 for data
= (cdr (caadr (assoc 'suggestion i
)))
8239 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
8240 for lqueries
= (length (anything-c-ggs-set-number-result
8242 for ldata
= (length data
)
8245 (when (> ldata anything-ggs-max-length-real-flag
)
8246 (setq anything-ggs-max-length-real-flag ldata
))
8247 (when (> lqueries anything-ggs-max-length-num-flag
)
8248 (setq anything-ggs-max-length-num-flag lqueries
)))
8249 collect
(cons data nqueries
) into cont
8250 finally return cont
)))
8251 (if anything-google-suggest-use-curl-p
8253 (call-process "curl" nil t nil request
)
8255 (with-current-buffer
8256 (url-retrieve-synchronously request
)
8259 (defun anything-c-google-suggest-set-candidates (&optional request-prefix
)
8260 "Set candidates with result and number of google results found."
8262 (loop with suggested-results
= (anything-c-google-suggest-fetch
8263 (or (and request-prefix
8264 (concat request-prefix
" " anything-pattern
))
8266 for
(real . numresult
) in suggested-results
8267 ;; Prepare number of results with ","
8268 for fnumresult
= (anything-c-ggs-set-number-result numresult
)
8269 ;; Calculate number of spaces to add before fnumresult
8270 ;; if it is smaller than longest result
8271 ;; `anything-ggs-max-length-num-flag'.
8274 ;; To be sure it is aligned properly.
8275 for nspaces
= (if (< (length fnumresult
) anything-ggs-max-length-num-flag
)
8276 (- anything-ggs-max-length-num-flag
(length fnumresult
))
8278 ;; Add now the spaces before fnumresult.
8279 for align-fnumresult
= (concat (make-string nspaces ?
) fnumresult
)
8280 for interval
= (- anything-ggs-max-length-real-flag
(length real
))
8281 for spaces
= (make-string (+ 2 interval
) ?
)
8282 for display
= (format "%s%s(%s results)" real spaces align-fnumresult
)
8283 collect
(cons display real
))))
8284 (if (loop for
(disp . dat
) in suggestions
8285 thereis
(equal dat anything-pattern
))
8287 ;; if there is no suggestion exactly matching the input then
8288 ;; prepend a Search on Google item to the list
8291 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
8292 anything-input
))))))
8294 (defun anything-c-ggs-set-number-result (num)
8297 (and (numberp num
) (setq num
(number-to-string num
)))
8298 (loop for i in
(reverse (split-string num
"" t
))
8300 append
(list i
) into C
8302 append
(list ",") into C
8303 and do
(setq count
0)
8305 (replace-regexp-in-string
8306 "^," "" (mapconcat 'identity
(reverse C
) ""))))
8309 (defvar anything-c-google-suggest-default-browser-function nil
8310 "*The browse url function you prefer to use with google suggest.
8311 When nil, use the first browser function available
8312 See `anything-browse-url-default-browser-alist'.")
8314 (defun anything-c-google-suggest-action (candidate)
8315 "Default action to jump to a google suggested candidate."
8316 (let ((arg (concat anything-c-google-suggest-search-url
8317 (url-hexify-string candidate
))))
8318 (anything-aif anything-c-google-suggest-default-browser-function
8320 (anything-c-browse-url arg
))))
8322 (defvar anything-c-google-suggest-default-function
8323 'anything-c-google-suggest-set-candidates
8324 "Default function to use in anything google suggest.")
8326 (defvar anything-c-source-google-suggest
8327 '((name .
"Google Suggest")
8328 (candidates .
(lambda ()
8329 (funcall anything-c-google-suggest-default-function
)))
8330 (action .
(("Google Search" . anything-c-google-suggest-action
)))
8332 (requires-pattern .
3)
8335 (defun anything-c-google-suggest-emacs-lisp ()
8336 "Try to emacs lisp complete with google suggestions."
8337 (anything-c-google-suggest-set-candidates "emacs lisp"))
8339 ;; (anything 'anything-c-source-google-suggest)
8341 ;;; Yahoo suggestions
8344 (defun anything-c-yahoo-suggest-fetch (input)
8345 "Fetch Yahoo suggestions for INPUT from XML buffer.
8346 Return an alist with elements like (data . number_results)."
8347 (let ((request (concat anything-c-yahoo-suggest-url
8348 (url-hexify-string input
))))
8351 with result-alist
= (xml-get-children
8352 (car (xml-parse-region (point-min) (point-max)))
8354 for i in result-alist
8355 collect
(caddr i
))))
8356 (with-current-buffer
8357 (url-retrieve-synchronously request
)
8360 (defun anything-c-yahoo-suggest-set-candidates ()
8361 "Set candidates with Yahoo results found."
8362 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
8366 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
8367 anything-input
))))))
8369 (defun anything-c-yahoo-suggest-action (candidate)
8370 "Default action to jump to a Yahoo suggested candidate."
8371 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8372 (url-hexify-string candidate
))))
8374 (defvar anything-c-source-yahoo-suggest
8375 '((name .
"Yahoo Suggest")
8376 (candidates . anything-c-yahoo-suggest-set-candidates
)
8377 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
8379 (requires-pattern .
3)
8382 ;; (anything 'anything-c-source-yahoo-suggest)
8385 ;;; Web browser functions.
8388 (require 'browse-url
)
8389 ;; If default setting of `w3m-command' is not
8390 ;; what you want you and you modify it, you will have to reeval
8391 ;; also `anything-browse-url-default-browser-alist'.
8392 (defvar w3m-command
"/usr/bin/w3m")
8393 (defvar anything-c-home-url
"http://www.google.fr"
8394 "*Default url to use as home url.")
8396 (defvar ac-browse-url-chromium-program
"chromium-browser")
8397 (defvar ac-browse-url-uzbl-program
"uzbl-browser")
8398 (defvar anything-browse-url-default-browser-alist
8399 `((,w3m-command . w3m-browse-url
)
8400 (,browse-url-firefox-program . browse-url-firefox
)
8401 (,ac-browse-url-chromium-program . ac-browse-url-chromium
)
8402 (,ac-browse-url-uzbl-program . ac-browse-url-uzbl
)
8403 (,browse-url-kde-program . browse-url-kde
)
8404 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
8405 (,browse-url-mozilla-program . browse-url-mozilla
)
8406 (,browse-url-galeon-program . browse-url-galeon
)
8407 (,browse-url-netscape-program . browse-url-netscape
)
8408 (,browse-url-mosaic-program . browse-url-mosaic
)
8409 (,browse-url-xterm-program . browse-url-text-xterm
))
8410 "*Alist of \(executable . function\) to try to find a suitable url browser.")
8412 (defun* anything-c-generic-browser
(url name
&rest args
)
8413 "Browse URL with NAME browser."
8414 (let ((proc (concat name
" " url
)))
8415 (message "Starting %s..." name
)
8416 (apply 'start-process proc nil name
8417 (append args
(list url
)))
8418 (set-process-sentinel
8420 #'(lambda (process event
)
8421 (when (string= event
"finished\n")
8422 (message "%s process %s" process event
))))))
8424 (defun ac-browse-url-chromium (url)
8425 "Browse URL with google chrome browser."
8426 (interactive "sURL: ")
8427 (anything-c-generic-browser
8428 url ac-browse-url-chromium-program
))
8430 (defun ac-browse-url-uzbl (url &optional ignore
)
8431 "Browse URL with uzbl browser."
8432 (interactive "sURL: ")
8433 (anything-c-generic-browser url ac-browse-url-uzbl-program
"-u"))
8435 (defun anything-browse-url-default-browser (url &rest args
)
8436 "Find the first available browser and ask it to load URL."
8437 (let ((default-browser-fn
8438 (loop for
(exe . fn
) in anything-browse-url-default-browser-alist
8439 thereis
(and exe
(executable-find exe
) fn
))))
8440 (if default-browser-fn
8441 (apply default-browser-fn url args
)
8442 (error "No usable browser found"))))
8444 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
8445 "Default command to browse URL."
8446 (if browse-url-browser-function
8448 (anything-browse-url-default-browser url
)))
8453 ;; Need external program surfraw.
8454 ;; <http://surfraw.alioth.debian.org/>
8456 (defvar anything-surfraw-default-browser-function nil
8457 "*The browse url function you prefer to use with surfraw.
8458 When nil, fallback to `browse-url-browser-function'.")
8461 (defvar anything-surfraw-engines-history nil
)
8462 (defvar anything-surfraw-input-history nil
)
8464 (defun anything-c-build-elvi-list ()
8465 "Return list of all engines and descriptions handled by surfraw."
8468 (call-process "surfraw" nil t nil
8470 (split-string (buffer-string) "\n"))))
8476 (defun anything-emms-stream-edit-bookmark (elm)
8477 "Change the information of current emms-stream bookmark from anything."
8478 (declare (special emms-stream-list
))
8479 (let* ((cur-buf anything-current-buffer
)
8480 (bookmark (assoc elm emms-stream-list
))
8481 (name (read-from-minibuffer "Description: "
8483 (url (read-from-minibuffer "URL: "
8485 (fd (read-from-minibuffer "Feed Descriptor: "
8486 (int-to-string (nth 2 bookmark
))))
8487 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8488 (format "%s" (car (last bookmark
))))))
8491 (when (re-search-forward (concat "^" name
) nil t
)
8493 (emms-stream-delete-bookmark)
8494 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
8495 (emms-stream-save-bookmarks-file)
8497 (anything-c-switch-to-buffer cur-buf
)))))
8499 (defun anything-emms-stream-delete-bookmark (elm)
8500 "Delete an emms-stream bookmark from anything."
8501 (let* ((cur-buf anything-current-buffer
)
8502 (bookmark (assoc elm emms-stream-list
))
8503 (name (nth 0 bookmark
)))
8506 (when (re-search-forward (concat "^" name
) nil t
)
8508 (emms-stream-delete-bookmark)
8509 (emms-stream-save-bookmarks-file)
8511 (anything-c-switch-to-buffer cur-buf
)))))
8513 (defvar anything-c-source-emms-streams
8514 '((name .
"Emms Streams")
8516 (emms-stream-init)))
8517 (candidates .
(lambda ()
8518 (declare (special emms-stream-list
))
8519 (mapcar 'car emms-stream-list
)))
8520 (action .
(("Play" .
(lambda (elm)
8521 (declare (special emms-stream-list
))
8522 (let* ((stream (assoc elm emms-stream-list
))
8523 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
8524 (url (second stream
)))
8526 ("Delete" . anything-emms-stream-delete-bookmark
)
8527 ("Edit" . anything-emms-stream-edit-bookmark
)))
8528 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8529 ;; (anything 'anything-c-source-emms-streams)
8531 ;; Don't forget to set `emms-source-file-default-directory'
8532 (defvar anything-c-source-emms-dired
8533 '((name .
"Music Directory")
8534 (candidates .
(lambda ()
8535 (cddr (directory-files emms-source-file-default-directory
))))
8537 (("Play Directory" .
(lambda (item)
8538 (emms-play-directory
8541 emms-source-file-default-directory
))))
8542 ("Open dired in file's directory" .
(lambda (item)
8543 (anything-c-open-dired
8546 emms-source-file-default-directory
))))))
8547 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8548 ;; (anything 'anything-c-source-emms-dired)
8551 (defun anything-c-emms-files-modifier (candidates source
)
8552 (let ((current-playlist (with-current-emms-playlist
8554 with cur-list
= (emms-playlist-tracks-in-region
8555 (point-min) (point-max))
8557 collect
(assoc-default 'name i
)))))
8558 (loop for i in candidates
8559 if
(member (cdr i
) current-playlist
)
8560 collect
(cons (propertize (car i
)
8561 'face
'anything-emms-playlist
)
8563 else collect i into lis
8564 finally return lis
)))
8566 (defun anything-c-emms-play-current-playlist ()
8567 "Play current playlist."
8568 (with-current-emms-playlist
8569 (emms-playlist-first)
8570 (emms-playlist-mode-play-smart)))
8572 (defvar anything-c-source-emms-files
8573 '((name .
"Emms files")
8574 (candidates .
(lambda ()
8575 (loop for v being the hash-values in emms-cache-db
8576 for name
= (assoc-default 'name v
)
8577 for artist
= (or (assoc-default 'info-artist v
) "unknown")
8578 for genre
= (or (assoc-default 'info-genre v
) "unknown")
8579 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
8580 for song
= (or (assoc-default 'info-title v
) "unknown")
8581 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
8582 unless
(string-match "^http:" name
) collect
(cons info name
))))
8583 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
8584 (action .
(("Play file" . emms-play-file
)
8585 ("Add to Playlist and play (C-u clear current)"
8586 .
(lambda (candidate)
8587 (when anything-current-prefix-arg
8588 (emms-playlist-current-clear))
8590 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
8591 (unless emms-player-playing-p
8592 (anything-c-emms-play-current-playlist))))))))
8594 ;; (anything 'anything-c-source-emms-files)
8597 ;;; Jabber Contacts (jabber.el)
8598 (defun anything-c-jabber-online-contacts ()
8599 "List online Jabber contacts."
8602 (dolist (item (jabber-concat-rosters) jids
)
8603 (when (get item
'connected
)
8604 (push (if (get item
'name
)
8605 (cons (get item
'name
) item
)
8606 (cons (symbol-name item
) item
)) jids
))))))
8608 (defvar anything-c-source-jabber-contacts
8609 '((name .
"Jabber Contacts")
8610 (init .
(lambda () (require 'jabber
)))
8611 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
8612 (action .
(lambda (x)
8614 (jabber-read-account)
8616 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
8617 ;; (anything 'anything-c-source-jabber-contacts)
8622 (defvar anything-source-select-buffer
"*anything source select*")
8623 (defvar anything-c-source-call-source
8624 `((name .
"Call anything source")
8625 (candidate-number-limit)
8628 (loop for vname in
(all-completions "anything-c-source-" obarray
)
8629 for var
= (intern vname
)
8630 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
8632 (cons (format "%s `%s'"
8633 name
(propertize vname
'face
'font-lock-variable-name-face
))
8636 .
(("Invoke anything with selected source"
8639 (setq anything-candidate-number-limit
9999)
8640 (anything candidate nil nil nil nil
8641 anything-source-select-buffer
)))
8642 ("Describe variable" . describe-variable
)
8643 ("Find variable" . find-variable
)))
8644 (persistent-action . describe-variable
)
8645 (persistent-help .
"Show description of this source")))
8646 ;; (anything 'anything-c-source-call-source)
8648 (defun anything-call-source-from-anything ()
8649 "Call anything source within `anything' session."
8651 (setq anything-input-idle-delay
0)
8652 (anything-set-sources '(anything-c-source-call-source)))
8654 ;;; Execute Preconfigured anything.
8655 (defvar anything-c-source-anything-commands
8656 '((name .
"Preconfigured Anything")
8657 (candidates . anything-c-anything-commands-candidates
)
8659 (candidate-number-limit)))
8660 ;; (anything 'anything-c-source-anything-commands)
8662 (defun anything-c-anything-commands-candidates ()
8663 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
8664 collect
(cons (if (where-is-internal cmd nil t
)
8665 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
8666 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
8673 (defun anything-c-occur-init ()
8674 "Create the initial anything occur buffer.
8675 If region is active use region as buffer contents
8676 instead of whole buffer."
8677 (with-current-buffer (anything-candidate-buffer 'global
)
8680 (with-anything-current-buffer
8681 (if (anything-region-active-p)
8682 (buffer-substring (region-beginning) (region-end))
8683 (buffer-substring (point-min) (point-max))))))
8684 (insert buf-contents
))))
8686 (defun anything-c-occur-get-line (s e
)
8687 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
8689 (defun anything-c-occur-query-replace-regexp (candidate)
8690 "Query replace regexp starting from CANDIDATE.
8691 If region is active ignore CANDIDATE and replace only in region.
8692 With a prefix arg replace only matches surrounded by word boundaries,
8693 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
8694 (let ((regexp anything-input
))
8695 (unless (anything-region-active-p)
8696 (anything-c-action-line-goto candidate
))
8697 (apply 'query-replace-regexp
8698 (anything-c-query-replace-args regexp
))))
8700 (defvar anything-c-source-occur
8702 (init . anything-c-occur-init
)
8703 (candidates-in-buffer)
8705 (get-line . anything-c-occur-get-line
)
8706 (display-to-real . anything-c-display-to-real-line
)
8707 (action .
(("Go to Line" . anything-c-action-line-goto
)
8708 ("Query replace regexp (C-u Not inside word.)"
8709 . anything-c-occur-query-replace-regexp
)))
8711 (requires-pattern .
1)
8714 ;; (anything 'anything-c-source-occur)
8717 ;;; Anything browse code.
8718 (defun anything-c-browse-code-get-line (beg end
)
8719 "Select line if it match the regexp corresponding to current `major-mode'.
8720 Line is parsed for BEG position to END position."
8721 (let ((str-line (buffer-substring beg end
))
8722 (regexp (assoc-default major-mode
8723 anything-c-browse-code-regexp-alist
))
8724 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
8725 (when (and regexp
(string-match regexp str-line
))
8726 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
8729 (defvar anything-c-source-browse-code
8730 '((name .
"Browse code")
8732 (anything-candidate-buffer anything-current-buffer
)
8733 (with-anything-current-buffer
8734 (jit-lock-fontify-now))))
8735 (candidate-number-limit .
9999)
8736 (candidates-in-buffer)
8737 (get-line . anything-c-browse-code-get-line
)
8742 ;; Do many actions for input
8743 (defvar anything-c-source-create
8747 (action-transformer . anything-create--actions
))
8748 "Do many create actions from `anything-pattern'.
8749 See also `anything-create--actions'.")
8750 ;; (anything 'anything-c-source-create)
8752 (defun anything-create-from-anything ()
8753 "Run `anything-create' from `anything' as a fallback."
8755 (anything-run-after-quit 'anything-create nil anything-pattern
))
8757 (defun anything-create--actions (&rest ignored
)
8758 "Default actions for `anything-create' / `anything-c-source-create'."
8760 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
8761 (append anything-create--actions-private
8762 '(("find-file" . find-file
)
8763 ("find-file other window" . find-file-other-window
)
8764 ("New buffer" . anything-c-switch-to-buffer
)
8765 ("New buffer other window" . switch-to-buffer-other-window
)
8766 ("Bookmark Set" . bookmark-set
)
8768 (lambda (x) (set-register (read-char "Register: ") x
)))
8769 ("Insert Linkd star" . linkd-insert-star
)
8770 ("Insert Linkd Tag" . linkd-insert-tag
)
8771 ("Insert Linkd Link" . linkd-insert-link
)
8772 ("Insert Linkd Lisp" . linkd-insert-lisp
)
8773 ("Insert Linkd Wiki" . linkd-insert-wiki
)
8774 ("Google Search" . google
)))))
8777 ;; Minibuffer History
8780 (defvar anything-c-source-minibuffer-history
8781 '((name .
"Minibuffer History")
8782 (header-name .
(lambda (name)
8783 (format "%s (%s)" name minibuffer-history-variable
)))
8786 (let ((history (loop for i in
8787 (symbol-value minibuffer-history-variable
)
8788 unless
(string= "" i
) collect i
)))
8789 (if (consp (car history
))
8790 (mapcar 'prin1-to-string history
)
8794 ;; (anything 'anything-c-source-minibuffer-history)
8800 (defvar anything-c-source-elscreen
8801 '((name .
"Elscreen")
8804 (if (cdr (elscreen-get-screen-to-name-alist))
8806 (loop for sname in
(elscreen-get-screen-to-name-alist)
8807 append
(list (format "[%d] %s" (car sname
) (cdr sname
))))
8808 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
8810 .
(("Change Screen" .
8812 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
8815 (dolist (i (anything-marked-candidates))
8816 (elscreen-goto (- (aref i
1) (aref "0" 0)))
8820 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
8821 (elscreen-kill-others)))))))
8822 ;; (anything 'anything-c-source-elscreen)
8828 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
8829 "Top command (batch mode). %s is replaced with `frame-width'.")
8830 (defvar anything-c-source-top
8831 '((name .
"Top (Press C-c C-u to refresh)")
8832 (init . anything-c-top-init
)
8833 (candidates-in-buffer)
8834 (display-to-real . anything-c-top-display-to-real
)
8835 (persistent-action . anything-c-top-sh-persistent-action
)
8836 (persistent-help .
"SIGTERM")
8838 ("kill (TERM)" .
(lambda (pid)
8839 (anything-c-top-sh (format "kill -TERM %s" pid
))))
8840 ("kill (KILL)" .
(lambda (pid)
8841 (anything-c-top-sh (format "kill -KILL %s" pid
))))
8842 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
8843 ;; (anything 'anything-c-source-top)
8845 (defun anything-c-top-sh (cmd)
8846 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
8848 (defun anything-c-top-sh-persistent-action (pid)
8849 (delete-other-windows)
8850 (anything-c-top-sh (format "kill -TERM %s" pid
))
8851 (anything-force-update))
8853 (defun anything-c-top-init ()
8854 (with-current-buffer (anything-candidate-buffer 'global
)
8855 (call-process-shell-command
8856 (format anything-c-top-command
8857 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
8858 nil
(current-buffer))))
8860 (defun anything-c-top-display-to-real (line)
8861 (car (split-string line
)))
8864 (defvar anything-c-source-absolute-time-timers
8865 '((name .
"Absolute Time Timers")
8866 (candidates . timer-list
)
8868 ;; (anything 'anything-c-source-absolute-time-timers)
8870 (defvar anything-c-source-idle-time-timers
8871 '((name .
"Idle Time Timers")
8872 (candidates . timer-idle-list
)
8874 ;; (anything 'anything-c-source-idle-time-timers)
8876 (defun anything-c-timer-real-to-display (timer)
8877 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
8878 (append timer nil
) ;use `append' to convert vector->list
8879 (format "%s repeat=%5S %s(%s)"
8880 (let ((time (list t1 t2 t3
)))
8882 (format-time-string "idle-for=%5s" time
)
8883 (format-time-string "%m/%d %T" time
)))
8886 (mapconcat 'prin1-to-string args
" "))))
8888 ;;; X RandR resolution change
8889 ;;; FIXME I do not care multi-display.
8890 (defvar anything-c-xrandr-output
"VGA")
8891 (defvar anything-c-xrandr-screen
"0")
8892 (defvar anything-c-source-xrandr-change-resolution
8893 '((name .
"Change Resolution")
8897 (call-process "xrandr" nil
(current-buffer) nil
8898 "--screen" anything-c-xrandr-screen
"-q")
8900 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
8901 collect
(match-string 1)))))
8903 ("Change Resolution" .
(lambda (mode)
8904 (call-process "xrandr" nil nil nil
8905 "--screen" anything-c-xrandr-screen
8906 "--output" anything-c-xrandr-output
8908 ;; (anything 'anything-c-source-xrandr-change-resolution)
8913 (defun anything-c-persistent-xfont-action (elm)
8914 "Show current font temporarily"
8915 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
8918 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
8919 (set-frame-font current-font
))))
8921 (defvar anything-c-xfonts-cache nil
)
8922 (defvar anything-c-source-xfonts
8923 '((name .
"X Fonts")
8925 (unless anything-c-xfonts-cache
8926 (setq anything-c-xfonts-cache
8927 (x-list-fonts "*")))))
8928 (candidates . anything-c-xfonts-cache
)
8929 (action .
(("Copy to kill ring" .
(lambda (elm)
8931 ("Set Font" .
(lambda (elm)
8933 (set-frame-font elm
'keep-size
)
8934 (message "New font have been copied to kill ring")))))
8935 (persistent-action . anything-c-persistent-xfont-action
)
8936 (persistent-help .
"Switch to this font temporarily")))
8937 ;; (anything 'anything-c-source-xfonts)
8939 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
8942 (defvar anything-c-ucs-max-len
0)
8943 (defun anything-c-calculate-ucs-max-len ()
8944 "Calculate the length of longest `ucs-names' candidate."
8945 (loop with count
= 0
8946 for
(n . v
) in
(ucs-names)
8947 for len
= (length n
)
8950 finally return count
))
8952 (defun anything-c-ucs-init ()
8953 "Initialize an anything buffer with ucs symbols.
8954 Only math* symbols are collected."
8955 (unless (> anything-c-ucs-max-len
0)
8956 (setq anything-c-ucs-max-len
8957 (anything-c-calculate-ucs-max-len)))
8958 (with-current-buffer (anything-candidate-buffer
8959 (get-buffer-create "*anything ucs*"))
8960 ;; `ucs-names' fn will not run again, data is cached in
8962 (loop for
(n . v
) in
(ucs-names)
8963 for len
= (length n
)
8964 for diff
= (+ (- anything-c-ucs-max-len len
) 2)
8965 unless
(string= "" n
)
8966 do
(progn (insert (concat
8973 (defun anything-c-ucs-forward-char (candidate)
8974 (with-anything-current-buffer
8977 (defun anything-c-ucs-backward-char (candidate)
8978 (with-anything-current-buffer
8981 (defun anything-c-ucs-delete-backward (candidate)
8982 (with-anything-current-buffer
8985 (defun anything-c-ucs-insert-char (candidate)
8986 (with-anything-current-buffer
8988 (replace-regexp-in-string
8990 (cadr (split-string candidate
":"))))))
8992 (defun anything-c-ucs-persistent-insert ()
8994 (anything-attrset 'action-insert
'anything-c-ucs-insert-char
)
8995 (anything-execute-persistent-action 'action-insert
))
8997 (defun anything-c-ucs-persistent-forward ()
8999 (anything-attrset 'action-forward
'anything-c-ucs-forward-char
)
9000 (anything-execute-persistent-action 'action-forward
))
9002 (defun anything-c-ucs-persistent-backward ()
9004 (anything-attrset 'action-back
'anything-c-ucs-backward-char
)
9005 (anything-execute-persistent-action 'action-back
))
9007 (defun anything-c-ucs-persistent-delete ()
9009 (anything-attrset 'action-delete
'anything-c-ucs-delete-backward
)
9010 (anything-execute-persistent-action 'action-delete
))
9012 (defvar anything-c-source-ucs
9013 '((name .
"Ucs names")
9014 (init . anything-c-ucs-init
)
9015 (candidate-number-limit .
9999)
9016 (candidates-in-buffer)
9017 (mode-line . anything-c-ucs-mode-line-string
)
9018 (action .
(("Insert" . anything-c-ucs-insert-char
)
9019 ("Forward char" . anything-c-ucs-forward-char
)
9020 ("Backward char" . anything-c-ucs-backward-char
)
9021 ("Delete char backward" . anything-c-ucs-delete-backward
))))
9022 "Source for collecting `ucs-names' math symbols.")
9028 (defvar anything-c-source-emacs-process
9029 '((name .
"Emacs Process")
9030 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
9031 (persistent-action .
(lambda (elm)
9032 (delete-process (get-process elm
))
9033 (anything-delete-current-selection)))
9034 (persistent-help .
"Kill Process")
9035 (action ("Kill Process" .
(lambda (elm)
9036 (delete-process (get-process elm
)))))))
9037 ;; (anything 'anything-c-source-emacs-process)
9042 (defvar anything-c-source-time-world
9043 '((name .
"Time World List")
9045 (let ((anything-buffer (anything-candidate-buffer 'global
)))
9046 (with-current-buffer anything-buffer
9047 (display-time-world-display display-time-world-list
)))))
9048 (candidates-in-buffer)))
9052 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
9055 (defvar anything-c-source-apt
9057 (init . anything-c-apt-init
)
9058 (candidates-in-buffer)
9059 (candidate-transformer anything-c-apt-candidate-transformer
)
9060 (display-to-real . anything-c-apt-display-to-real
)
9061 (requires-pattern .
2)
9062 (update . anything-c-apt-refresh
)
9064 ("Show package description" . anything-c-apt-cache-show
)
9065 ("Install package" . anything-c-apt-install
)
9066 ("Remove package" . anything-c-apt-uninstall
)
9067 ("Purge package" . anything-c-apt-purge
))
9068 (persistent-action . anything-c-apt-persistent-action
)
9069 (persistent-help .
"Show package description")))
9070 ;; (anything 'anything-c-source-apt)
9072 (defvar anything-c-apt-query
"emacs")
9073 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
9074 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
9075 (defvar anything-c-apt-installed-packages nil
)
9076 (defvar anything-c-apt-all-packages nil
)
9077 (defvar anything-c-apt-input-history nil
)
9079 (defun anything-c-apt-refresh ()
9080 "Refresh installed candidates list."
9081 (setq anything-c-apt-installed-packages nil
)
9082 (setq anything-c-apt-all-packages nil
))
9084 (defun anything-c-apt-persistent-action (candidate)
9085 "Persistent action for APT source."
9086 (anything-c-apt-cache-show candidate
))
9088 (defun anything-c-apt-candidate-transformer (candidates)
9089 "Show installed candidates in a different color."
9092 for cand in candidates
9093 for name
= (anything-c-apt-display-to-real cand
)
9094 if
(member name anything-c-apt-installed-packages
)
9095 collect
(propertize cand
'face
'anything-apt-installed
) into all
9096 else collect cand into all finally return all
))
9098 (defun anything-c-apt-init ()
9099 "Initialize list of debian packages."
9101 (unless (and anything-c-apt-installed-packages
9102 anything-c-apt-all-packages
)
9103 (message "Loading package list...")
9104 (setq anything-c-apt-installed-packages
9106 (call-process-shell-command "dpkg --get-selections"
9107 nil
(current-buffer))
9108 (loop for i in
(split-string (buffer-string) "\n" t
)
9109 collect
(car (split-string i
)))))
9110 (setq anything-c-apt-all-packages
9111 (with-current-buffer
9112 (anything-candidate-buffer
9113 (get-buffer-create (format "*anything-apt*")))
9115 (call-process-shell-command
9116 (format anything-c-apt-search-command query
)
9117 nil
(current-buffer))))
9118 (message "Loading package list done")
9121 (defun anything-c-apt-display-to-real (line)
9122 "Return only name of a debian package.
9123 LINE is displayed like:
9124 package name - description."
9125 (car (split-string line
" - ")))
9127 (defun anything-c-shell-command-if-needed (command)
9128 "Run shell command COMMAND to describe package.
9129 If a buffer named COMMAND already exists, just switch to it."
9130 (let ((buf (get-buffer command
)))
9131 (anything-c-switch-to-buffer (get-buffer-create command
))
9132 (unless buf
(insert (shell-command-to-string command
)))))
9134 (defun anything-c-apt-cache-show (package)
9135 "Show information on apt package PACKAGE."
9136 (anything-c-shell-command-if-needed
9137 (format anything-c-apt-show-command package
)))
9139 (defun anything-c-apt-install (package)
9140 "Run 'apt-get install' shell command on PACKAGE."
9141 (anything-c-apt-generic-action :action
'install
))
9143 (defun anything-c-apt-uninstall (package)
9144 "Run 'apt-get remove' shell command on PACKAGE."
9145 (anything-c-apt-generic-action :action
'uninstall
))
9147 (defun anything-c-apt-purge (package)
9148 "Run 'apt-get purge' shell command on PACKAGE."
9149 (anything-c-apt-generic-action :action
'purge
))
9151 (defun* anything-c-apt-generic-action
(&key action
)
9152 "Run 'apt-get ACTION'.
9153 Support install, remove and purge actions."
9154 (ansi-term (getenv "SHELL") "anything apt")
9156 (let ((command (case action
9157 ('install
"sudo apt-get install ")
9158 ('uninstall
"sudo apt-get remove ")
9159 ('purge
"sudo apt-get purge ")
9160 (t (error "Unknow action"))))
9163 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x
))
9164 (anything-marked-candidates) " ")))
9165 (goto-char (point-max))
9166 (insert (concat command cand-list
))
9168 (if (y-or-n-p (format "%s package" (symbol-name action
)))
9170 (setq anything-c-external-commands-list nil
)
9171 (setq anything-c-apt-installed-packages nil
)
9172 (term-char-mode) (term-send-input))
9173 (delete-region beg end
) (term-send-eof) (kill-buffer))))
9175 ;; (anything-c-apt-install "jed")
9178 ;;; Anything UI for gentoo portage.
9181 (defvar anything-c-gentoo-use-flags nil
)
9182 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
9183 (defvar anything-c-cache-gentoo nil
)
9184 (defvar anything-c-cache-world nil
)
9185 (defvar anything-c-source-gentoo
9186 '((name .
"Portage sources")
9188 (get-buffer-create anything-c-gentoo-buffer
)
9189 (unless anything-c-cache-gentoo
9190 (anything-c-gentoo-setup-cache))
9191 (unless anything-c-cache-world
9192 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
9193 (anything-c-gentoo-init-list)))
9194 (candidates-in-buffer)
9196 (candidate-transformer anything-c-highlight-world
)
9197 (action .
(("Show package" .
(lambda (elm)
9198 (anything-c-gentoo-eshell-action elm
"eix")))
9199 ("Show history" .
(lambda (elm)
9200 (if (member elm anything-c-cache-world
)
9201 (anything-c-gentoo-eshell-action elm
"genlop -qe")
9202 (message "No infos on packages not yet installed"))))
9203 ("Copy in kill-ring" . kill-new
)
9204 ("insert at point" . insert
)
9205 ("Browse HomePage" .
(lambda (elm)
9206 (let ((urls (anything-c-gentoo-get-url elm
)))
9207 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
9208 ("Show extra infos" .
(lambda (elm)
9209 (if (member elm anything-c-cache-world
)
9210 (anything-c-gentoo-eshell-action elm
"genlop -qi")
9211 (message "No infos on packages not yet installed"))))
9212 ("Show use flags" .
(lambda (elm)
9213 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
9214 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
9215 (font-lock-mode 1)))
9216 ("Run emerge pretend" .
(lambda (elm)
9217 (anything-c-gentoo-eshell-action elm
"emerge -p")))
9218 ("Emerge" .
(lambda (elm)
9219 (anything-gentoo-install elm
:action
'install
)))
9220 ("Unmerge" .
(lambda (elm)
9221 (anything-gentoo-install elm
:action
'uninstall
)))
9222 ("Show dependencies" .
(lambda (elm)
9223 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
9224 ("Show related files" .
(lambda (elm)
9225 (anything-c-gentoo-default-action elm
"equery" "files")))
9226 ("Refresh" .
(lambda (elm)
9227 (anything-c-gentoo-setup-cache)
9228 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
9230 ;; (anything 'anything-c-source-gentoo)
9232 (defun* anything-gentoo-install
(candidate &key action
)
9233 (setq anything-c-external-commands-list nil
)
9234 (ansi-term (getenv "SHELL") "Gentoo emerge")
9236 (let ((command (case action
9237 ('install
"sudo emerge -av ")
9238 ('uninstall
"sudo emerge -avC ")
9239 (t (error "Unknow action"))))
9240 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
9242 (goto-char (point-max))
9243 (insert (concat command elms
))
9245 (term-char-mode) (term-send-input)))
9247 (defun anything-c-gentoo-default-action (elm command
&rest args
)
9248 "Gentoo default action that use `anything-c-gentoo-buffer'."
9249 (if (member elm anything-c-cache-world
)
9251 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9253 (let ((com-list (append args
(list elm
))))
9254 (apply #'call-process command nil t nil
9256 (message "No infos on packages not yet installed")))
9258 (defvar anything-c-source-use-flags
9259 '((name .
"Use Flags")
9261 (unless anything-c-gentoo-use-flags
9262 (anything-c-gentoo-setup-use-flags-cache))
9263 (anything-c-gentoo-get-use)))
9264 (candidates-in-buffer)
9266 (candidate-transformer anything-c-highlight-local-use
)
9267 (action .
(("Description"
9269 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9271 (apply #'call-process
"euse" nil t nil
9274 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
9275 (font-lock-mode 1)))
9278 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
9281 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
9284 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
9285 ("Show which dep use this flag"
9287 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9289 (apply #'call-process
"equery" nil t nil
9295 ;; (anything 'anything-c-source-use-flags)
9297 (defun anything-c-gentoo-init-list ()
9298 "Initialize buffer with all packages in Portage."
9299 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9300 (buf (anything-candidate-buffer 'portage-buf
)))
9301 (with-current-buffer buf
9302 (dolist (i anything-c-cache-gentoo
)
9303 (insert (concat i
"\n"))))))
9305 (defun anything-c-gentoo-setup-cache ()
9306 "Set up `anything-c-cache-gentoo'"
9307 (setq anything-c-cache-gentoo
9308 (split-string (with-temp-buffer
9309 (call-process "eix" nil t nil
9313 (defun anything-c-gentoo-eshell-action (elm command
)
9314 (when (get-buffer "*EShell Command Output*")
9315 (kill-buffer "*EShell Command Output*"))
9316 (message "Wait searching...")
9317 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
9318 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
9320 (save-window-excursion
9321 (pop-to-buffer "*scratch*")
9322 (eshell-command (format "%s %s" command elm
)))
9323 (pop-to-buffer "*EShell Command Output*"))
9324 (eshell-command (format "%s %s" command elm
)))))
9326 (defun anything-c-gentoo-get-use ()
9327 "Initialize buffer with all use flags."
9328 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9329 (buf (anything-candidate-buffer 'use-buf
)))
9330 (with-current-buffer buf
9331 (dolist (i anything-c-gentoo-use-flags
)
9332 (insert (concat i
"\n"))))))
9335 (defun anything-c-gentoo-setup-use-flags-cache ()
9336 "Setup `anything-c-gentoo-use-flags'"
9337 (setq anything-c-gentoo-use-flags
9338 (split-string (with-temp-buffer
9339 (call-process "eix" nil t nil
9340 "--print-all-useflags")
9343 (defun anything-c-gentoo-get-url (elm)
9344 "Return a list of urls from eix output."
9346 with url-list
= (split-string
9348 (call-process "eix" nil t nil
9349 elm
"--format" "<homepage>\n")
9353 when
(and (string-match "^http://.*" i
)
9354 (not (member i all
)))
9356 finally return all
))
9358 (defun anything-c-gentoo-get-world ()
9359 "Return list of all installed package on your system."
9360 (split-string (with-temp-buffer
9361 (call-process "qlist" nil t nil
9365 (defun anything-c-gentoo-get-local-use ()
9366 (split-string (with-temp-buffer
9367 (call-process "portageq" nil t nil
9373 (defun anything-c-highlight-world (eix)
9374 "Highlight all installed package."
9376 if
(member i anything-c-cache-world
)
9377 collect
(propertize i
'face
'anything-gentoo-match-face
)
9381 (defun anything-c-highlight-local-use (use-flags)
9382 (let ((local-uses (anything-c-gentoo-get-local-use)))
9383 (loop for i in use-flags
9384 if
(member i local-uses
)
9385 collect
(propertize i
'face
'anything-gentoo-match-face
)
9391 ;;; Anything ratpoison UI
9394 (defvar anything-c-source-ratpoison-commands
9395 '((name .
"Ratpoison Commands")
9396 (init . anything-c-ratpoison-commands-init
)
9397 (candidates-in-buffer)
9398 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
9399 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
9400 (candidate-number-limit)))
9401 ;; (anything 'anything-c-source-ratpoison-commands)
9403 (defun anything-c-ratpoison-commands-init ()
9404 (unless (anything-candidate-buffer)
9405 (with-current-buffer (anything-candidate-buffer 'global
)
9406 ;; with ratpoison prefix key
9408 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
9409 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9410 (replace-match "<ratpoison> \\1: \\2"))
9411 (goto-char (point-max))
9414 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
9415 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9416 (replace-match "\\1: \\2")))))
9418 (defun anything-c-ratpoison-commands-display-to-real (display)
9419 (and (string-match ": " display
)
9420 (substring display
(match-end 0))))
9422 (defun anything-c-ratpoison-commands-execute (candidate)
9423 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
9427 ;;; Anything `completing-read' replacement
9430 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp
)
9431 "Convert COLLECTION to list removing elements that don't match TEST.
9432 See `anything-comp-read' about supported COLLECTION arguments.
9434 SORT-FN is a predicate to sort COLLECTION.
9436 ALISTP when non--nil will not use `all-completions' to collect
9437 candidates because it doesn't handle alists correctly for anything.
9438 i.e In `all-completions' the keys \(cars of elements\)
9439 are the possible completions. In anything we want to use the cdr instead
9440 like \(display . real\).
9444 \(setq A '((a . 1) (b . 2) (c . 3)))
9445 ==>((a . 1) (b . 2) (c . 3))
9446 \(anything-comp-read \"test: \" A :alistp nil
9447 :exec-when-only-one t
9448 :initial-input \"a\")
9450 \(anything-comp-read \"test: \" A :alistp t
9451 :exec-when-only-one t
9452 :initial-input \"1\")
9455 See docstring of `all-completions' for more info.
9457 If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
9459 (cond ((and (eq collection obarray
) test
)
9460 (all-completions "" collection test
))
9461 ((and (vectorp collection
) test
)
9462 (loop for i across collection when
(funcall test i
) collect i
))
9463 ((vectorp collection
)
9464 (loop for i across collection collect i
))
9466 (loop for i in collection when
(funcall test i
) collect i
))
9467 ((and (symbolp collection
) (boundp collection
))
9468 (symbol-value collection
))
9470 ((and collection test
)
9471 (all-completions "" collection test
))
9472 (t (all-completions "" collection
)))))
9473 (if sort-fn
(sort cands sort-fn
) cands
)))
9475 (defun anything-cr-default-transformer (candidates source
)
9476 "Default filter candidate function for `anything-comp-read'.
9477 Do nothing, just return candidate list unmodified."
9480 (defun* anything-comp-read
(prompt collection
9486 (buffer "*Anything Completions*")
9488 (requires-pattern 0)
9491 (persistent-action nil
)
9492 (persistent-help "DoNothing")
9493 (name "Anything Completions")
9494 candidates-in-buffer
9498 (fc-transformer 'anything-cr-default-transformer
)
9499 (marked-candidates nil
)
9501 "Read a string in the minibuffer, with anything completion.
9503 It is anything `completing-read' equivalent.
9505 - PROMPT is the prompt name to use.
9507 - COLLECTION can be a list, vector, obarray or hash-table.
9508 It can be also a function that receives three arguments:
9509 the values string, predicate and t. See `all-completions' for more details.
9513 - TEST: A predicate called with one arg i.e candidate.
9515 - INITIAL-INPUT: Same as input arg in `anything'.
9517 - PRESELECT: See preselect arg of `anything'.
9519 - DEFAULT: This option is used only for compatibility with regular
9520 Emacs `completing-read'.
9522 - BUFFER: Name of anything-buffer.
9524 - MUST-MATCH: Candidate selected must be one of COLLECTION.
9526 - REQUIRES-PATTERN: Same as anything attribute, default is 0.
9528 - HISTORY: A list containing specific history, default is nil.
9529 When it is non--nil, all elements of HISTORY are displayed in
9530 a special source before COLLECTION.
9532 - INPUT-HISTORY: A symbol. the minibuffer input history will be
9533 stored there, if nil or not provided, `minibuffer-history'
9534 will be used instead.
9536 - PERSISTENT-ACTION: A function called with one arg i.e candidate.
9538 - PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9540 - NAME: The name related to this local source.
9542 - EXEC-WHEN-ONLY-ONE: Bound `anything-execute-action-at-once-if-one'
9543 to non--nil. (possibles values are t or nil).
9545 - VOLATILE: Use volatile attribute \(enabled by default\).
9547 - SORT: A predicate to give to `sort' e.g `string-lessp'.
9549 - FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9551 - MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9553 - ALISTP: \(default is non--nil\) See `anything-comp-read-get-candidates'.
9555 - CANDIDATES-IN-BUFFER: when non--nil use a source build with
9556 `anything-candidates-in-buffer' which is much faster.
9557 Argument VOLATILE have no effect when CANDIDATES-IN-BUFFER is non--nil.
9559 Any prefix args passed during `anything-comp-read' invocation will be recorded
9560 in `anything-current-prefix-arg', otherwise if prefix args were given before
9561 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9562 That's mean you can pass prefix args before or after calling a command
9563 that use `anything-comp-read' See `anything-M-x' for example."
9564 (when (get-buffer anything-action-buffer
)
9565 (kill-buffer anything-action-buffer
))
9566 (flet ((action-fn (candidate)
9567 (if marked-candidates
9568 (anything-marked-candidates)
9569 (identity candidate
))))
9570 (let* ((minibuffer-completion-confirm (unless (eq must-match t
)
9572 (keymap (when must-match minibuffer-local-must-match-map
))
9573 (anything-map (make-composed-keymap
9574 ;; Be sure C-g is bound to `anything-keyboard-quit'.
9575 (list '(keymap (7 . anything-keyboard-quit
))
9578 (src-hist `((name .
,(format "%s History" name
))
9581 (let ((all (anything-comp-read-get-candidates
9582 history nil nil
,alistp
)))
9583 (anything-fast-remove-dups
9584 (if (and default
(not (string= default
"")))
9585 (delq nil
(cons default
(delete default all
)))
9588 (filtered-candidate-transformer
9589 .
(lambda (candidates sources
)
9590 (loop for i in candidates
9591 do
(set-text-properties 0 (length i
) nil i
)
9593 (persistent-action .
,persistent-action
)
9594 (persistent-help .
,persistent-help
)
9595 (action .
,'action-fn
)))
9596 (src `((name .
,name
)
9599 (let ((cands (anything-comp-read-get-candidates
9600 collection test sort alistp
)))
9601 (unless (or must-match
(string= anything-pattern
""))
9602 (setq cands
(append (list anything-pattern
) cands
)))
9603 (if (and default
(not (string= default
"")))
9604 (delq nil
(cons default
(delete default cands
)))
9606 (filtered-candidate-transformer ,fc-transformer
)
9607 (requires-pattern .
,requires-pattern
)
9608 (persistent-action .
,persistent-action
)
9609 (persistent-help .
,persistent-help
)
9610 (action .
,'action-fn
)))
9611 (src-1 `((name .
,name
)
9614 (let ((cands (anything-comp-read-get-candidates
9615 collection test sort alistp
)))
9616 (unless (or must-match
(string= anything-pattern
""))
9617 (setq cands
(append (list anything-pattern
) cands
)))
9618 (with-current-buffer (anything-candidate-buffer 'global
)
9620 (if (and default
(not (string= default
"")))
9621 (delq nil
(cons default
(delete default cands
)))
9623 do
(insert (concat i
"\n")))))))
9624 (candidates-in-buffer)
9625 (filtered-candidate-transformer ,fc-transformer
)
9626 (requires-pattern .
,requires-pattern
)
9627 (persistent-action .
,persistent-action
)
9628 (persistent-help .
,persistent-help
)
9629 (action .
,'action-fn
)))
9630 (src-list (list src-hist
9631 (if candidates-in-buffer
9634 (append src
'((volatile)))
9636 (anything-execute-action-at-once-if-one exec-when-only-one
))
9640 :input initial-input
9642 :preselect preselect
9645 :history input-history
9647 (when (and (not (string= anything-pattern
""))
9648 (or (eq must-match
'confirm
)
9649 (eq must-match
'confirm-after-completion
)))
9650 (identity anything-pattern
))
9651 (unless (or (eq anything-exit-status
1) must-match
)
9655 ;; Generic completing-read
9657 ;; Support also function as collection.
9658 ;; e.g M-x man is supported.
9659 ;; Support hash-table and vectors as collection.
9661 ;; Some crap emacs functions may not be supported
9662 ;; like ffap-alternate-file (bad use of completing-read)
9663 ;; and maybe others.
9664 ;; Provide a mode `anything-completion-mode' which turn on
9665 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9667 (defvar anything-completion-mode-string
" AC")
9669 (defvar anything-completion-mode-quit-message
9670 "Anything completion disabled")
9672 (defvar anything-completion-mode-start-message
9673 "Anything completion enabled")
9675 ;;; Specialized handlers
9678 (defun anything-completing-read-symbols
9679 (prompt collection test require-match init
9680 hist default inherit-input-method name buffer
)
9681 "Specialized function for fast symbols completion in `ac-mode'."
9684 :sources
`((name .
,name
)
9686 (with-current-buffer (anything-candidate-buffer 'global
)
9687 (goto-char (point-min))
9688 (when (and default
(stringp default
)
9689 ;; Some defaults args result as
9690 ;; (symbol-name nil) == "nil".
9691 ;; e.g debug-on-entry.
9692 (not (string= default
"nil"))
9693 (not (string= default
"")))
9694 (insert (concat default
"\n")))
9695 (loop with all
= (all-completions "" collection test
)
9697 unless
(and default
(eq sym default
))
9698 do
(insert (concat sym
"\n"))))))
9699 (persistent-action . anything-lisp-completion-persistent-action
)
9700 (persistent-help .
"Show brief doc in mode-line")
9701 (candidates-in-buffer)
9702 (action . identity
))
9708 :default
(or default
""))
9712 ;;; Generic completing read
9715 (defun anything-completing-read-default-1
9716 (prompt collection test require-match
9717 init hist default inherit-input-method
9718 name buffer
&optional cands-in-buffer exec-when-only-one
)
9719 "Call `anything-comp-read' with same args as `completing-read'.
9720 Extra optional arg CANDS-IN-BUFFER mean use `candidates-in-buffer'
9721 method which is faster.
9722 It should be used when candidate list don't need to rebuild dynamically."
9723 (let ((history (or (car-safe hist
) hist
)))
9728 :input-history history
9729 :must-match require-match
9730 :alistp nil
; Be sure `all-completions' is used.
9732 :candidates-in-buffer cands-in-buffer
9733 :exec-when-only-one exec-when-only-one
9735 ;; If DEF is not provided, fallback to empty string
9736 ;; to avoid `thing-at-point' to be appended on top of list
9737 :default
(or default
"")
9738 :initial-input init
)))
9740 (defun anything-completing-read-with-cands-in-buffer
9741 (prompt collection test require-match
9742 init hist default inherit-input-method
9744 "Same as `anything-completing-read-default-1' but use candidates-in-buffer."
9745 ;; Some commands like find-tag may use `read-file-name' from inside
9746 ;; the calculation of collection. in this case it clash with
9747 ;; candidates-in-buffer that reuse precedent data (files) which is wrong.
9748 ;; So (re)calculate collection outside of main anything-session.
9749 (let ((cands (all-completions "" collection
)))
9750 (anything-completing-read-default-1 prompt cands test require-match
9751 init hist default inherit-input-method
9754 (defun* anything-completing-read-default
9755 (prompt collection
&optional
9756 predicate require-match
9757 initial-input hist def
9758 inherit-input-method
)
9759 "An anything replacement of `completing-read'.
9760 This function should be used only as a `completing-read-function'.
9762 Don't use it directly, use instead `anything-comp-read' in your programs.
9764 See documentation of `completing-read' and `all-completions' for details."
9765 (declare (special anything-completion-mode
))
9766 (let* ((current-command this-command
)
9767 (str-command (symbol-name current-command
))
9768 (buf-name (format "*ac-mode-%s*" str-command
))
9769 (entry (assq current-command
9770 anything-completing-read-handlers-alist
))
9771 (def-com (cdr-safe entry
))
9772 (str-defcom (and def-com
(symbol-name def-com
)))
9773 (def-args (list prompt collection predicate require-match
9774 initial-input hist def inherit-input-method
))
9775 ;; Append the two extra args needed to set the buffer and source name
9776 ;; in anything specialized functions.
9777 (any-args (append def-args
(list str-command buf-name
)))
9778 anything-completion-mode-start-message
; Be quiet
9779 anything-completion-mode-quit-message
9780 (minibuffer-completion-table collection
)
9781 (minibuffer-completion-predicate predicate
)
9782 ;; Be sure this pesty *completion* buffer doesn't popup.
9783 (minibuffer-setup-hook (remove 'minibuffer-completion-help
9784 minibuffer-setup-hook
)))
9785 (when (eq def-com
'ido
) (setq def-com
'ido-completing-read
))
9786 (unless (or (not entry
) def-com
)
9787 ;; An entry in *read-handlers-alist exists but have
9788 ;; a nil value, so we exit from here, disable `ac-mode'
9789 ;; and run the command again with it original behavior.
9790 ;; `ac-mode' will be restored on exit.
9791 (return-from anything-completing-read-default
9795 (apply completing-read-function def-args
))
9797 ;; If we use now `completing-read' we MUST turn off `ac-mode'
9798 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9799 (when (or (eq def-com
'completing-read
)
9800 ;; All specialized functions are prefixed by "anything"
9801 (and (stringp str-defcom
)
9802 (not (string-match "^anything" str-defcom
))))
9805 (cond (;; An anything specialized function exists, run it.
9806 (and def-com anything-completion-mode
)
9807 (apply def-com any-args
))
9808 (;; Try to handle `ido-completing-read' everywhere.
9809 (and def-com
(eq def-com
'ido-completing-read
))
9810 (setcar (memq collection def-args
)
9811 (all-completions "" collection predicate
))
9812 (apply def-com def-args
))
9813 (;; User set explicitely `completing-read' or something similar
9814 ;; in *read-handlers-alist, use this with exactly the same
9815 ;; args as in `completing-read'.
9816 ;; If we are here `anything-completion-mode' is now disabled.
9818 (apply def-com def-args
))
9819 (t ; Fall back to classic `anything-comp-read'.
9820 (anything-completing-read-default-1
9821 prompt collection predicate require-match
9822 initial-input hist def inherit-input-method
9823 str-command buf-name
)))
9825 ;; When exiting minibuffer, `this-command' is set to
9826 ;; `anything-exit-minibuffer', which is unwanted when starting
9827 ;; on another `completing-read', so restore `this-command' to
9828 ;; initial value when exiting.
9829 (setq this-command current-command
))))
9831 (defun* anything-generic-read-file-name
9832 (prompt &optional dir default-filename mustmatch initial predicate
)
9833 "An anything replacement of `read-file-name'."
9834 (declare (special anything-completion-mode
))
9835 (let* ((default (and default-filename
9836 (if (listp default-filename
)
9837 (car default-filename
)
9839 (init (or default initial dir default-directory
))
9840 (ini-input (and init
(expand-file-name init
)))
9841 (current-command this-command
)
9842 (str-command (symbol-name current-command
))
9843 (anything-file-completion-sources
9845 (remove str-command anything-file-completion-sources
)))
9846 (buf-name (format "*ac-mode-%s*" str-command
))
9847 (entry (assq current-command
9848 anything-completing-read-handlers-alist
))
9849 (def-com (cdr-safe entry
))
9850 (str-defcom (symbol-name def-com
))
9851 (def-args (list prompt dir default-filename mustmatch initial predicate
))
9852 ;; Append the two extra args needed to set the buffer and source name
9853 ;; in anything specialized functions.
9854 (any-args (append def-args
(list str-command buf-name
)))
9855 (ido-state ido-mode
)
9856 anything-completion-mode-start-message
; Be quiet
9857 anything-completion-mode-quit-message
; Same here
9859 ;; Some functions that normally call `completing-read' can switch
9860 ;; brutally to `read-file-name' (e.g find-tag), in this case
9861 ;; the anything specialized function will fail because it is build
9862 ;; for `completing-read', so set it to 'incompatible to be sure
9863 ;; we switch to `anything-c-read-file-name' and don't try to call it
9864 ;; with wrong number of args.
9865 (when (and def-com
(> (length (help-function-arglist def-com
)) 8))
9866 (setq def-com
'incompatible
))
9867 (when (eq def-com
'ido
) (setq def-com
'ido-read-file-name
))
9868 (unless (or (not entry
) def-com
)
9869 (return-from anything-generic-read-file-name
9873 (apply read-file-name-function def-args
))
9875 ;; If we use now `read-file-name' we MUST turn off `ac-mode'
9876 ;; to avoid infinite recursion and CRASH. It will be reenabled on exit.
9877 (when (or (eq def-com
'read-file-name
)
9878 (eq def-com
'ido-read-file-name
)
9879 (and (stringp str-defcom
)
9880 (not (string-match "^anything" str-defcom
))))
9884 (cond (;; A specialized function exists, run it
9885 ;; with the two extra args specific to anything..
9886 (and def-com anything-completion-mode
9887 (not (eq def-com
'ido-read-file-name
))
9888 (not (eq def-com
'incompatible
)))
9889 (apply def-com any-args
))
9890 (;; Def-com value is `ido-read-file-name'
9891 ;; run it with default args.
9892 (and def-com
(eq def-com
'ido-read-file-name
))
9894 (apply def-com def-args
))
9895 (;; Def-com value is `read-file-name'
9896 ;; run it with default args.
9897 (eq def-com
'read-file-name
)
9898 (apply def-com def-args
))
9899 (t ; Fall back to classic `anything-c-read-file-name'.
9900 (anything-c-read-file-name
9904 :initial-input
(expand-file-name init dir
)
9908 (ido-mode (if ido-state
1 -
1))
9909 ;; Same comment as in `anything-completing-read-default'.
9910 (setq this-command current-command
))
9911 (if (and mustmatch
(not (file-exists-p fname
)))
9912 (if (y-or-n-p "File does not exists, create buffer?")
9913 fname
(error "Abort file does not exists"))
9917 (define-minor-mode anything-completion-mode
9918 "Toggle generic anything completion.
9920 All functions in Emacs that use `completing-read'
9921 or `read-file-name' and friends will use anything interface
9922 when this mode is turned on.
9923 However you can modify this behavior for functions of your choice
9924 with `anything-completing-read-handlers-alist'.
9926 Called with a positive arg, turn on unconditionally, with a
9927 negative arg turn off.
9928 You can turn it on with `ac-mode'.
9930 Some crap emacs functions may not be supported,
9931 e.g `ffap-alternate-file' and maybe others
9932 You can add such functions to `anything-completing-read-handlers-alist'
9935 Note: This mode will work only partially on Emacs23."
9938 :lighter anything-completion-mode-string
9939 (declare (special completing-read-function
))
9940 (if anything-completion-mode
9942 (setq completing-read-function
'anything-completing-read-default
9943 read-file-name-function
'anything-generic-read-file-name
)
9944 (message anything-completion-mode-start-message
))
9945 (setq completing-read-function
(and (fboundp 'completing-read-default
)
9946 'completing-read-default
)
9947 read-file-name-function
(and (fboundp 'read-file-name-default
)
9948 'read-file-name-default
))
9949 (message anything-completion-mode-quit-message
)))
9951 (defalias 'ac-mode
'anything-completion-mode
)
9955 ;;; Eshell completion.
9957 ;; Enable like this in .emacs:
9959 ;; (add-hook 'eshell-mode-hook
9961 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
9963 (defvar anything-c-source-esh
9964 '((name .
"Eshell completions")
9966 (setq pcomplete-current-completions nil
9967 pcomplete-last-completion-raw nil
)
9968 ;; Eshell-command add this hook in all minibuffers
9969 ;; Remove it for the anything one. (Fixed in Emacs24)
9970 (remove-hook 'minibuffer-setup-hook
'eshell-mode
)))
9971 (candidates . anything-esh-get-candidates
)
9972 (action . anything-ec-insert
))
9973 "Anything source for Eshell completion.")
9976 (defvar anything-ec-target
"")
9977 (defun anything-ec-insert (candidate)
9978 "Insert CANDIDATE at point.
9979 This is the same as `ac-insert', just inlined here for compatibility."
9981 (when (and anything-ec-target
9982 (search-backward anything-ec-target nil t
)
9983 (string= (buffer-substring (point) pt
) anything-ec-target
))
9984 (delete-region (point) pt
)))
9987 (defun anything-esh-get-candidates ()
9988 "Get candidates for eshell completion using `pcomplete'."
9990 (let* ((pcomplete-stub)
9991 pcomplete-seen pcomplete-norm-func
9992 pcomplete-args pcomplete-last pcomplete-index
9993 (pcomplete-autolist pcomplete-autolist
)
9994 (pcomplete-suffix-list pcomplete-suffix-list
))
9995 (with-anything-current-buffer
9997 with table
= (pcomplete-completions)
9998 with entry
= (condition-case nil
10000 (try-completion anything-pattern
(pcomplete-entries))
10001 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
10004 (let ((fc (car (last (pcomplete-parse-arguments)))))
10005 ;; Check if last arg require fname completion.
10006 (and (file-name-directory fc
) fc
))))
10007 for i in
(if (listp table
) table
; Emacs23 or commands.
10008 (all-completions pcomplete-stub table
)) ; Emacs24
10009 for file-cand
= (and entry
10010 (if (file-remote-p i
) i
10011 (expand-file-name i
(file-name-directory entry
))))
10012 if
(and file-cand
(or (file-remote-p file-cand
) (file-exists-p file-cand
)))
10013 collect file-cand into ls
10014 else collect i into ls
10016 (if (and entry
(not (string= entry
"")) (file-exists-p entry
))
10017 (append (list (expand-file-name entry default-directory
)) ls
) ls
))))))
10019 ;;; Eshell history.
10022 (defvar anything-c-source-eshell-history
10023 '((name .
"Eshell history")
10025 (let (eshell-hist-ignoredups)
10026 ;; Write the content's of ring to file.
10027 (eshell-write-history eshell-history-file-name t
)
10028 (with-current-buffer (anything-candidate-buffer 'global
)
10029 (insert-file-contents eshell-history-file-name
)))
10030 ;; Same comment as in `anything-c-source-esh'
10031 (remove-hook 'minibuffer-setup-hook
'eshell-mode
)))
10032 (candidates-in-buffer)
10033 (filtered-candidate-transformer .
(lambda (candidates sources
)
10034 (reverse candidates
)))
10035 (candidate-number-limit .
9999)
10036 (action .
(lambda (candidate)
10037 (eshell-kill-input)
10038 (insert candidate
))))
10039 "Anything source for Eshell history.")
10042 ;;; Show completion - an alternative of anything-show-completion.el.
10044 ;; Provide show completion with macro `with-anything-show-completion'.
10047 ;; Called each time cursor move in anything-buffer.
10048 (defun anything-c-show-completion ()
10049 (with-anything-current-buffer
10050 (overlay-put anything-c-show-completion-overlay
10051 'display
(anything-get-selection))))
10053 (defun anything-c-show-completion-init-overlay (beg end
)
10054 (and anything-c-turn-on-show-completion
10055 (setq anything-c-show-completion-overlay
(make-overlay beg end
))
10056 (overlay-put anything-c-show-completion-overlay
10057 'face
'anything-lisp-show-completion
)))
10059 (defmacro with-anything-show-completion
(beg end
&rest body
)
10060 "Show anything candidate in an overlay at point.
10061 BEG and END are the beginning and end position of the current completion
10062 in `anything-current-buffer'.
10063 BODY is an anything call where we want to enable show completion.
10064 If `anything-c-turn-on-show-completion' is nil just do nothing."
10065 (declare (indent 2) (debug t
))
10066 `(let ((anything-move-selection-after-hook
10067 (and anything-c-turn-on-show-completion
10068 (append (list 'anything-c-show-completion
)
10069 anything-move-selection-after-hook
))))
10071 (progn (anything-c-show-completion-init-overlay ,beg
,end
)
10073 (and anything-c-turn-on-show-completion
10074 (delete-overlay anything-c-show-completion-overlay
)))))
10077 ;;; Lisp symbol completion.
10081 (defun anything-lisp-completion-at-point ()
10082 "Anything lisp symbol completion at point."
10084 (let* ((data (lisp-completion-at-point))
10086 (end (point)) ; 'cadr data' is wrong when no space after point.
10087 (plist (nthcdr 3 data
))
10088 (pred (plist-get plist
:predicate
))
10090 (target (and beg end
(buffer-substring-no-properties beg end
)))
10091 (candidates (all-completions target
(nth 2 data
) pred
))
10092 (anything-quit-if-no-candidate t
)
10093 (anything-execute-action-at-once-if-one t
)
10094 (anything-match-plugin-enabled
10095 (member 'anything-compile-source--match-plugin
10096 anything-compile-source-functions
)))
10098 (with-anything-show-completion beg end
10099 ;; Overlay is initialized now in anything-current-buffer.
10102 '((name .
"Lisp completion")
10104 (with-current-buffer (anything-candidate-buffer 'global
)
10105 (loop for sym in candidates
10106 for len
= (length sym
)
10107 when
(> len lgst-len
) do
(setq lgst-len len
)
10108 do
(insert (concat sym
"\n"))))))
10109 (candidates-in-buffer)
10110 (persistent-action . anything-lisp-completion-persistent-action
)
10111 (persistent-help .
"Show brief doc in mode-line")
10112 (filtered-candidate-transformer anything-lisp-completion-transformer
)
10113 (action .
(lambda (candidate)
10114 (delete-region beg end
)
10115 (insert candidate
))))
10116 :input
(if anything-match-plugin-enabled
(concat target
" ") target
)))
10117 (message "[No Match]"))))
10119 (defun anything-lisp-completion-persistent-action (candidate)
10120 (let ((cursor-in-echo-area t
)
10121 mode-line-in-non-selected-windows
)
10122 (anything-c-show-info-in-mode-line
10124 (anything-c-get-first-line-documentation
10125 (intern candidate
))
10126 'face
'anything-lisp-completion-info
))))
10128 (defun anything-lisp-completion-transformer (candidates source
)
10129 "Anything candidates transformer for lisp completion."
10130 (declare (special lgst-len
))
10131 (loop for c in candidates
10132 for sym
= (intern c
)
10133 for annot
= (cond ((commandp sym
) " (Com)")
10134 ((fboundp sym
) " (Fun)")
10135 ((boundp sym
) " (Var)")
10136 ((facep sym
) " (Face)"))
10137 for spaces
= (make-string (- lgst-len
(length c
)) ?
)
10138 collect
(cons (concat c spaces annot
) c
)))
10140 (defun anything-c-get-first-line-documentation (sym)
10141 "Return first line documentation of symbol SYM.
10142 If SYM is not documented, return \"Not documented\"."
10143 (let ((doc (cond ((fboundp sym
)
10144 (documentation sym t
))
10146 (documentation-property sym
'variable-documentation t
))
10148 (face-documentation sym
))
10150 (if (and doc
(not (string= doc
""))
10151 ;; `documentation' return "\n\n(args...)"
10152 ;; for CL-style functions.
10153 (not (string-match-p "^\n\n" doc
)))
10154 (car (split-string doc
"\n"))
10155 "Not documented")))
10157 ;;; File completion.
10159 ;; Complete file name at point.
10160 (defun anything-c-thing-before-point ()
10161 "Get symbol name before point.
10162 Borrowed from anything-complete.el, inlined here for compatibility."
10164 (let ((beg (point)))
10165 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10166 (when (re-search-backward
10167 "\\_<" (field-beginning nil nil
(point-at-bol)) t
)
10168 (buffer-substring-no-properties beg
(match-end 0))))))
10171 (defun anything-c-complete-file-name-at-point ()
10172 "Complete file name at point."
10174 (let* ((init (substring-no-properties (thing-at-point 'filename
)))
10176 (beg (- (point) (length init
)))
10177 (anything-quit-if-no-candidate t
)
10178 (anything-execute-action-at-once-if-one t
)
10180 (with-anything-show-completion beg end
10181 (setq completion
(anything-c-read-file-name "FileName: "
10182 :initial-input init
)))
10183 (anything-c-insert-file-name-completion-at-point completion
)))
10186 (defvar anything-lisp-completion-counter
0)
10188 (defun anything-lisp-completion-at-point-or-indent (arg)
10189 "First call indent and second call complete lisp symbol.
10190 The second call should happen before `anything-lisp-completion-or-indent-delay',
10191 after this delay, next call will indent again.
10192 After completion, next call is always indent.
10193 See that like click and double mouse click.
10194 One hit indent, two quick hits maybe indent and complete."
10196 ;; Be sure `indent-for-tab-command' will not try
10197 ;; to use `completion-at-point'.
10198 (let ((tab-always-indent (if (eq tab-always-indent
'complete
)
10199 t tab-always-indent
)))
10200 (incf anything-lisp-completion-counter
)
10202 (if (> anything-lisp-completion-counter
1)
10203 (anything-lisp-completion-or-file-name-at-point)
10204 (indent-for-tab-command arg
))
10205 ;; After `anything-lisp-completion-or-indent-delay' seconds
10207 (run-with-timer anything-lisp-completion-or-indent-delay nil
10209 (setq anything-lisp-completion-counter
0)))
10210 ;; Always reset to 0 at second hit.
10211 (when (eq anything-lisp-completion-counter
2)
10212 (setq anything-lisp-completion-counter
0)))))
10215 (defun anything-lisp-completion-or-file-name-at-point ()
10216 "Complete lisp symbol or filename at point.
10217 Filename completion happen if filename is started in
10218 or between double quotes."
10220 (let ((tap (substring-no-properties (thing-at-point 'filename
))))
10221 (if (and tap
(string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap
)
10222 (save-excursion (search-backward "\"" (point-at-bol) t
)))
10223 (anything-c-complete-file-name-at-point)
10224 (anything-lisp-completion-at-point))))
10226 (defun anything-c-apropos-init (test default
)
10227 "Init candidates buffer for `anything-c-apropos' sources."
10228 (with-current-buffer (anything-candidate-buffer 'global
)
10229 (goto-char (point-min))
10230 (when (and default
(stringp default
)
10231 ;; Some defaults args result as
10232 ;; (symbol-name nil) == "nil".
10233 ;; e.g debug-on-entry.
10234 (not (string= default
"nil"))
10235 (funcall test
(intern default
)))
10236 (insert (concat default
"\n")))
10237 (loop with all
= (all-completions "" obarray test
)
10239 unless
(and default
(eq sym default
))
10240 do
(insert (concat sym
"\n")))))
10243 ;;; Run Externals commands within Emacs with anything completion
10246 (defvar anything-external-command-history nil
)
10248 (defun anything-c-external-commands-list-1 (&optional sort
)
10249 "Returns a list of all external commands the user can execute.
10250 If `anything-c-external-commands-list' is non-nil it will
10251 return its contents. Else it calculates all external commands
10252 and sets `anything-c-external-commands-list'."
10253 (if anything-c-external-commands-list
10254 anything-c-external-commands-list
10255 (setq anything-c-external-commands-list
10257 with paths
= (split-string (getenv "PATH") path-separator
)
10258 with completions
= ()
10260 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
10261 for lsdir
= (loop for i in
(directory-files dir t
)
10262 for bn
= (file-name-nondirectory i
)
10263 when
(and (not (member bn completions
))
10264 (not (file-directory-p i
))
10265 (file-executable-p i
))
10267 append lsdir into completions
10268 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
10270 (defun anything-run-or-raise (exe &optional file
)
10271 "Generic command that run asynchronously EXE.
10272 If EXE is already running just jump to his window if `anything-raise-command'
10274 When FILE argument is provided run EXE with FILE.
10275 In this case EXE must be provided as \"EXE %s\"."
10276 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10278 (proc (if file
(concat real-com
" " file
) real-com
)))
10279 (if (get-process proc
)
10280 (if anything-raise-command
10281 (shell-command (format anything-raise-command real-com
))
10282 (error "Error: %s is already running" real-com
))
10283 (when (loop for i in anything-c-external-commands-list thereis real-com
)
10284 (message "Starting %s..." real-com
)
10286 (start-process-shell-command
10287 proc nil
(format exe
(shell-quote-argument
10288 (if (eq system-type
'windows-nt
)
10289 (anything-w32-prepare-filename file
)
10291 (start-process-shell-command proc nil real-com
))
10292 (set-process-sentinel
10294 #'(lambda (process event
)
10295 (when (and (string= event
"finished\n")
10296 anything-raise-command
10297 (not (anything-c-get-pid-from-process-name real-com
)))
10298 (shell-command (format anything-raise-command
"emacs")))
10299 (message "%s process...Finished." process
))))
10300 (setq anything-c-external-commands-list
10302 (delete real-com anything-c-external-commands-list
))))))
10306 ;;; Generic action functions
10309 (defun anything-c-file-buffers (filename)
10310 "Returns a list of buffer names corresponding to FILENAME."
10311 (let ((name (expand-file-name filename
))
10313 (dolist (buf (buffer-list) buf-list
)
10314 (let ((bfn (buffer-file-name buf
)))
10315 (when (and bfn
(string= name bfn
))
10316 (push (buffer-name buf
) buf-list
))))))
10318 (defun anything-revert-buffer (candidate)
10319 (with-current-buffer candidate
10320 (when (or (buffer-modified-p)
10321 (not (verify-visited-file-modtime
10322 (get-buffer candidate
))))
10323 (revert-buffer t t
))))
10325 (defun anything-revert-marked-buffers (ignore)
10326 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
10328 (defun anything-kill-marked-buffers (ignore)
10329 (mapc 'kill-buffer
(anything-marked-candidates)))
10331 (defun anything-c-delete-file (file &optional error-if-dot-file-p
)
10332 "Delete the given file after querying the user.
10333 Ask to kill buffers associated with that file, too."
10334 (when (and error-if-dot-file-p
10335 (anything-ff-dot-file-p file
))
10336 (error "Error: Cannot operate on `.' or `..'"))
10337 (let ((buffers (anything-c-file-buffers file
)))
10338 (if (< emacs-major-version
24)
10339 ;; `dired-delete-file' in Emacs versions < 24
10340 ;; doesn't support delete-by-moving-to-trash
10341 ;; so use `delete-directory' and `delete-file'
10343 (cond ((and (not (file-symlink-p file
))
10344 (file-directory-p file
)
10345 (directory-files file t dired-re-no-dot
))
10346 (when (y-or-n-p (format "Recursive delete of `%s'? " file
))
10347 (delete-directory file
'recursive
)))
10348 ((and (not (file-symlink-p file
))
10349 (file-directory-p file
))
10350 (delete-directory file
))
10351 (t (delete-file file
)))
10353 file
'dired-recursive-deletes delete-by-moving-to-trash
))
10355 (dolist (buf buffers
)
10356 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
10357 (kill-buffer buf
))))))
10359 (defun anything-get-mailcap-for-file (filename)
10360 "Get the command to use for FILENAME from mailcap files.
10361 The command is like <command %s> and is meant to use with `format'."
10362 (mailcap-parse-mailcaps)
10363 (let* ((ext (file-name-extension filename
))
10364 (mime (when ext
(mailcap-extension-to-mime ext
)))
10365 (result (when mime
(mailcap-mime-info mime
))))
10366 ;; If elisp file have no associations in .mailcap
10367 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10368 (when (stringp result
) result
)))
10370 (defun anything-get-default-program-for-file (filename)
10371 "Try to find a default program to open FILENAME.
10372 Try first in `anything-c-external-programs-associations' and then in mailcap file
10373 if nothing found return nil."
10374 (let* ((ext (file-name-extension filename
))
10375 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
10376 (cond ((and def-prog
(not (string= def-prog
"")))
10377 (concat def-prog
" %s"))
10378 ((and anything-c-default-external-file-browser
10379 (file-directory-p filename
))
10380 (concat anything-c-default-external-file-browser
" %s"))
10381 (t (anything-get-mailcap-for-file filename
)))))
10383 (defun anything-c-open-file-externally (file)
10384 "Open FILE with an external program.
10385 Try to guess which program to use with `anything-get-default-program-for-file'.
10386 If not found or a prefix arg is given query the user which tool to use."
10387 (let* ((fname (expand-file-name file
))
10388 (collection (anything-c-external-commands-list-1 'sort
))
10389 (def-prog (anything-get-default-program-for-file fname
))
10390 (real-prog-name (if (or anything-current-prefix-arg
(not def-prog
))
10391 ;; Prefix arg or no default program.
10393 (anything-comp-read
10394 "Program: " collection
10396 :name
"Open file Externally"
10397 :history anything-external-command-history
)
10398 ;; Always prompt to set this program as default.
10399 (setq def-prog nil
))
10400 ;; No prefix arg or default program exists.
10401 (replace-regexp-in-string " %s\\| '%s'" "" def-prog
)))
10402 (program (concat real-prog-name
" %s")))
10403 (unless (or def-prog
; Association exists, no need to record it.
10404 ;; Don't try to record non--filenames associations (e.g urls).
10405 (not (file-exists-p fname
)))
10409 "Do you want to make `%s' the default program for this kind of files? "
10411 (anything-aif (assoc (file-name-extension fname
)
10412 anything-c-external-programs-associations
)
10413 (setq anything-c-external-programs-associations
10414 (delete it anything-c-external-programs-associations
)))
10415 (push (cons (file-name-extension fname
)
10417 "Program (Add args maybe and confirm): " real-prog-name
))
10418 anything-c-external-programs-associations
)
10419 (customize-save-variable 'anything-c-external-programs-associations
10420 anything-c-external-programs-associations
)))
10421 (anything-run-or-raise program file
)
10422 (setq anything-external-command-history
10423 (cons real-prog-name
10424 (delete real-prog-name
10425 (loop for i in anything-external-command-history
10426 when
(executable-find i
) collect i
))))))
10428 (defun anything-c-find-file-or-marked (candidate)
10429 "Open file CANDIDATE or open anything marked files in background."
10430 (let ((marked (anything-marked-candidates))
10431 (ffap-newfile-prompt anything-ff-newfile-prompt-p
)
10432 (find-file-wildcards nil
))
10433 (if (> (length marked
) 1)
10434 ;; Open all marked files in background and display
10436 (progn (mapc 'find-file-noselect
(cdr marked
))
10437 (find-file (car marked
)))
10438 (if (and (not (file-exists-p candidate
))
10439 (and ffap-url-regexp
10440 (not (string-match ffap-url-regexp candidate
)))
10441 (string-match "/$" candidate
))
10442 ;; A a non--existing filename ending with /
10443 ;; Create a directory and jump to it.
10444 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
10445 (let ((dirfname (directory-file-name candidate
)))
10446 (if (file-exists-p dirfname
)
10447 (error "Mkdir: Unable to create directory `%s': file exists."
10448 (anything-c-basename dirfname
))
10449 (make-directory candidate
'parent
)))
10450 (anything-find-files-1 candidate
))
10451 ;; A non--existing filename NOT ending with / or
10452 ;; an existing filename, create or jump to it.
10453 (find-file-at-point (car marked
))))))
10455 (defun anything-delete-marked-files (ignore)
10456 (let* ((files (anything-marked-candidates))
10457 (len (length files
)))
10459 (format "Delete *%s File(s):\n%s"
10461 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
10462 (message "(No deletions performed)")
10464 (set-text-properties 0 (length i
) nil i
)
10465 (anything-c-delete-file i anything-ff-signal-error-on-dot-files
))
10466 (message "%s File(s) deleted" len
))))
10468 (defun anything-ediff-marked-buffers (candidate &optional merge
)
10469 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10470 With optional arg MERGE call `ediff-merge-buffers'."
10471 (let ((lg-lst (length (anything-marked-candidates)))
10475 (error "Error:You have to mark at least 1 buffer"))
10477 (setq buf1 anything-current-buffer
10478 buf2
(first (anything-marked-candidates))))
10480 (setq buf1
(first (anything-marked-candidates))
10481 buf2
(second (anything-marked-candidates))))
10483 (error "Error:To much buffers marked!")))
10485 (ediff-merge-buffers buf1 buf2
)
10486 (ediff-buffers buf1 buf2
))))
10488 (defun anything-ediff-marked-buffers-merge (candidate)
10489 "Ediff merge `anything-current-buffer' with CANDIDATE.
10490 See `anything-ediff-marked-buffers'."
10491 (anything-ediff-marked-buffers candidate t
))
10493 (defun anything-bookmark-get-bookmark-from-name (bmk)
10494 "Return bookmark name even if it is a bookmark with annotation.
10495 e.g prepended with *.
10496 Return nil if bmk is not a valid bookmark."
10497 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
10498 (if (assoc bookmark bookmark-alist
)
10500 (when (assoc bmk bookmark-alist
)
10503 (defun anything-delete-marked-bookmarks (ignore)
10504 "Delete this bookmark or all marked bookmarks."
10505 (dolist (i (anything-marked-candidates))
10506 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
10509 (defun anything-require-or-error (feature function
)
10510 (or (require feature nil t
)
10511 (error "Need %s to use `%s'." feature function
)))
10513 (defun anything-find-buffer-on-elscreen (candidate)
10514 "Open buffer in new screen, if marked buffers open all in elscreens."
10515 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
10516 (anything-aif (anything-marked-candidates)
10518 (let ((target-screen (elscreen-find-screen-by-buffer
10519 (get-buffer i
) 'create
)))
10520 (elscreen-goto target-screen
)))
10521 (let ((target-screen (elscreen-find-screen-by-buffer
10522 (get-buffer candidate
) 'create
)))
10523 (elscreen-goto target-screen
))))
10525 (defun anything-elscreen-find-file (file)
10526 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
10527 (elscreen-find-file file
))
10529 (defun anything-w32-prepare-filename (file)
10530 "Convert filename FILE to something usable by external w32 executables."
10531 (replace-regexp-in-string ; For UNC paths
10533 (replace-regexp-in-string ; Strip cygdrive paths
10534 "/cygdrive/\\(.\\)" "\\1:"
10535 file nil nil
) nil t
))
10538 (defun anything-w32-shell-execute-open-file (file)
10539 (interactive "fOpen file:")
10541 (w32-shell-execute "open" (anything-w32-prepare-filename file
))))
10543 (defun anything-c-open-file-with-default-tool (file)
10544 "Open FILE with the default tool on this platform."
10545 (if (eq system-type
'windows-nt
)
10546 (anything-w32-shell-execute-open-file file
)
10547 (start-process "anything-c-open-file-with-default-tool"
10549 (cond ((eq system-type
'gnu
/linux
)
10551 ((or (eq system-type
'darwin
) ;; Mac OS X
10552 (eq system-type
'macos
)) ;; Mac OS 9
10556 (defun anything-c-open-dired (file)
10557 "Opens a dired buffer in FILE's directory. If FILE is a
10558 directory, open this directory."
10559 (if (file-directory-p file
)
10561 (dired (file-name-directory file
))
10562 (dired-goto-file file
)))
10564 (defun anything-c-display-to-real-line (candidate)
10565 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
10566 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
10567 (error "Line number not found")))
10569 (defun anything-c-action-line-goto (lineno-and-content)
10570 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
10571 (append lineno-and-content
10572 (list (if (and (anything-attr-defined 'target-file
)
10573 (not anything-in-persistent-action
))
10574 'find-file-other-window
10577 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
10578 (apply #'anything-goto-file-line
10579 (if (stringp file-line-content
)
10580 ;; Case: filtered-candidate-transformer is skipped
10581 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
10582 file-line-content
)))
10585 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
10586 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
10588 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10589 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
10590 (let ((filename (match-string 1 candidate
))
10591 (lineno (match-string 2 candidate
))
10592 (content (match-string 3 candidate
)))
10593 (cons (format "%s:%s\n %s"
10594 (propertize filename
'face compilation-info-face
)
10595 (propertize lineno
'face compilation-line-face
)
10597 (list (expand-file-name
10599 (or (anything-interpret-value (anything-attr 'default-directory
))
10600 (and (anything-candidate-buffer)
10601 (buffer-local-value
10602 'default-directory
(anything-candidate-buffer)))))
10603 (string-to-number lineno
) content
)))))
10605 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
10606 (anything-aif (anything-attr 'before-jump-hook
)
10608 (when file
(funcall find-file-function file
))
10609 (if (anything-attr-defined 'adjust
)
10610 (anything-c-goto-line-with-adjustment lineno content
)
10611 (anything-goto-line lineno
))
10612 (unless (anything-attr-defined 'recenter
)
10613 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
10614 (anything-aif (anything-attr 'after-jump-hook
)
10616 (when anything-in-persistent-action
10617 (anything-match-line-color-current-line)))
10619 (defun anything-find-file-as-root (candidate)
10620 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
10622 (defun anything-find-many-files (ignore)
10623 (mapc 'find-file
(anything-marked-candidates)))
10625 ;; borrowed from etags.el
10626 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10627 (defun anything-c-goto-line-with-adjustment (line line-content
)
10630 ;; This constant is 1/2 the initial search window.
10631 ;; There is no sense in making it too small,
10632 ;; since just going around the loop once probably
10633 ;; costs about as much as searching 2000 chars.
10636 pat
(concat (if (eq selective-display t
)
10637 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10638 (regexp-quote line-content
)))
10639 ;; If no char pos was given, try the given line number.
10640 (setq startpos
(progn (anything-goto-line line
) (point)))
10641 (or startpos
(setq startpos
(point-min)))
10642 ;; First see if the tag is right at the specified location.
10643 (goto-char startpos
)
10644 (setq found
(looking-at pat
))
10645 (while (and (not found
)
10647 (goto-char (- startpos offset
))
10650 (re-search-forward pat
(+ startpos offset
) t
)
10651 offset
(* 3 offset
))) ; expand search window
10653 (re-search-forward pat nil t
)
10654 (error "not found")))
10655 ;; Position point at the right place
10656 ;; if the search string matched an extra Ctrl-m at the beginning.
10657 (and (eq selective-display t
)
10660 (beginning-of-line))
10662 (anything-document-attribute 'default-directory
"type . file-line"
10663 "`default-directory' to interpret file.")
10664 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
10665 "Function to call before jumping to the target location.")
10666 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
10667 "Function to call after jumping to the target location.")
10668 (anything-document-attribute 'adjust
"type . file-line"
10669 "Search around line matching line contents.")
10670 (anything-document-attribute 'recenter
"type . file-line / line"
10671 "`recenter' after jumping.")
10672 (anything-document-attribute 'target-file
"type . line"
10673 "Goto line of target-file.")
10676 (defun anything-c-call-interactively (cmd-or-name)
10677 "Execute CMD-OR-NAME as Emacs command.
10678 It is added to `extended-command-history'.
10679 `anything-current-prefix-arg' is used as the command's prefix argument."
10680 (setq extended-command-history
10681 (cons (anything-c-stringify cmd-or-name
)
10682 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
10683 (let ((current-prefix-arg anything-current-prefix-arg
)
10684 (cmd (anything-c-symbolify cmd-or-name
)))
10685 (if (stringp (symbol-function cmd
))
10686 (execute-kbd-macro (symbol-function cmd
))
10687 (setq this-command cmd
)
10688 (call-interactively cmd
))))
10691 (defun anything-c-set-variable (var)
10692 "Set value to VAR interactively."
10694 (let ((sym (anything-c-symbolify var
)))
10695 (set sym
(eval-minibuffer (format "Set %s: " var
)
10696 (prin1-to-string (symbol-value sym
))))))
10698 ;; (anything-c-set-variable 'hh)
10702 ;;; Persistent Action Helpers
10705 (defvar anything-match-line-overlay-face nil
)
10706 (defvar anything-match-line-overlay nil
)
10708 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
10709 "Highlight and underline current position"
10710 (let ((args (list (or start
(line-beginning-position))
10711 (or end
(1+ (line-end-position)))
10713 (if (not anything-match-line-overlay
)
10714 (setq anything-match-line-overlay
(apply 'make-overlay args
))
10715 (apply 'move-overlay anything-match-line-overlay args
)))
10716 (overlay-put anything-match-line-overlay
10717 'face
(or face anything-match-line-overlay-face
))
10722 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
10725 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
10727 (defun anything-match-line-cleanup ()
10728 (when anything-match-line-overlay
10729 (delete-overlay anything-match-line-overlay
)
10730 (setq anything-match-line-overlay nil
)))
10732 (defun anything-match-line-update ()
10733 (when anything-match-line-overlay
10734 (delete-overlay anything-match-line-overlay
)
10735 (anything-match-line-color-current-line)))
10737 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
10738 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
10741 ;;; Actions Transformers
10745 (defun anything-c-transform-file-load-el (actions candidate
)
10746 "Add action to load the file CANDIDATE if it is an emacs lisp
10747 file. Else return ACTIONS unmodified."
10748 (if (member (file-name-extension candidate
) '("el" "elc"))
10749 (append actions
'(("Load Emacs Lisp File" . load-file
)))
10752 (defun anything-c-transform-file-browse-url (actions candidate
)
10753 "Add an action to browse the file CANDIDATE if it in a html
10754 file or URL. Else return ACTIONS unmodified."
10755 (let ((browse-action '("Browse with Browser" . browse-url
)))
10756 (cond ((string-match "^http\\|^ftp" candidate
)
10757 (cons browse-action actions
))
10758 ((string-match "\\.html?$" candidate
)
10759 (append actions
(list browse-action
)))
10763 (defun anything-c-transform-function-call-interactively (actions candidate
)
10764 "Add an action to call the function CANDIDATE interactively if
10765 it is a command. Else return ACTIONS unmodified."
10766 (if (commandp (intern-soft candidate
))
10767 (append actions
'(("Call Interactively"
10769 anything-c-call-interactively
)))
10773 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
10774 "If CANDIDATE's `car' is a command, then add an action to
10775 evaluate it and put it onto the `command-history'."
10776 (if (commandp (car (read candidate
)))
10777 ;; Make it first entry
10778 (cons '("Eval and put onto command-history" .
10780 (let ((sym (read sexp
)))
10782 (setq command-history
10783 (cons sym command-history
)))))
10788 ;;; Candidate Transformers
10792 (defun anything-c-skip-boring-buffers (buffers)
10793 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
10795 (defun anything-c-skip-current-buffer (buffers)
10796 (if anything-allow-skipping-current-buffer
10797 (remove (buffer-name anything-current-buffer
) buffers
)
10800 (defun anything-c-shadow-boring-buffers (buffers)
10801 "Buffers matching `anything-c-boring-buffer-regexp' will be
10802 displayed with the `file-name-shadow' face if available."
10803 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
10805 (defvar anything-c-buffer-display-string-functions
10806 '(anything-c-buffer-display-string--compilation
10807 anything-c-buffer-display-string--shell
10808 anything-c-buffer-display-string--eshell
)
10809 "Functions to setup display string for buffer.
10811 Function has one argument, buffer name.
10812 If it returns string, use it.
10813 If it returns nil, display buffer name.
10814 See `anything-c-buffer-display-string--compilation' for example.")
10816 (defun anything-c-transform-buffer-display-string (buffers)
10817 "Setup display string for buffer candidates
10818 using `anything-c-buffer-display-string-functions'."
10819 (loop for buf in buffers
10823 for disp
= (progn (set-buffer buf
)
10824 (run-hook-with-args-until-success
10825 'anything-c-buffer-display-string-functions buf
))
10826 collect
(if disp
(cons disp buf
) buf
)))
10828 (defun anything-c-buffer-display-string--compilation (buf)
10829 (anything-aif (car compilation-arguments
)
10830 (format "%s: %s [%s]" buf it default-directory
)))
10832 (defun anything-c-buffer-display-string--eshell (buf)
10833 (declare (special eshell-history-ring
))
10834 (when (eq major-mode
'eshell-mode
)
10835 (format "%s: %s [%s]" buf
10836 (ignore-errors (ring-ref eshell-history-ring
0))
10837 default-directory
)))
10839 (defun anything-c-buffer-display-string--shell (buf)
10840 (when (eq major-mode
'shell-mode
)
10841 (format "%s: %s [%s]" buf
10842 (ignore-errors (ring-ref comint-input-ring
0))
10843 default-directory
)))
10846 (defun anything-c-shadow-boring-files (files)
10847 "Files matching `anything-c-boring-file-regexp' will be
10848 displayed with the `file-name-shadow' face if available."
10849 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
10851 (defun anything-c-skip-boring-files (files)
10852 "Files matching `anything-c-boring-file-regexp' will be skipped."
10853 (anything-c-skip-entries files anything-c-boring-file-regexp
))
10854 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10856 (defun anything-c-skip-current-file (files)
10857 "Current file will be skipped."
10858 (remove (buffer-file-name anything-current-buffer
) files
))
10860 (defun anything-c-w32-pathname-transformer (args)
10861 "Change undesirable features of windows pathnames to ones more acceptable to
10862 other candidate transformers."
10863 (if (eq system-type
'windows-nt
)
10864 (mapcar (lambda (x)
10865 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
10866 (mapcar (lambda (y)
10867 (replace-regexp-in-string "\\\\" "/" y
)) args
))
10870 (defun anything-c-shorten-home-path (files)
10871 "Replaces /home/user with ~."
10872 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10874 (mapcar (lambda (file)
10875 (if (and (stringp file
) (string-match home file
))
10876 (cons (replace-match "~" nil nil file
) file
)
10881 (defun anything-c-mark-interactive-functions (functions)
10882 "Mark interactive functions (commands) with (i) after the function name."
10884 (loop for function in functions
10885 do
(push (cons (concat function
10886 (when (commandp (intern-soft function
)) " (i)"))
10889 finally
(return (nreverse list
)))))
10892 ;;; Adaptive Sorting of Candidates
10896 (defvar anything-c-adaptive-done nil
10897 "nil if history information is not yet stored for the current
10900 (defvar anything-c-adaptive-history nil
10901 "Contains the stored history information.
10902 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10904 ;; Should run at beginning of `anything-initial-setup'.
10905 (add-hook 'anything-before-initialize-hook
#'(lambda ()
10906 (when anything-c-use-adaptative-sorting
10907 (setq anything-c-adaptive-done nil
))))
10909 ;; Should run at beginning of `anything-exit-minibuffer'.
10910 (add-hook 'anything-before-action-hook
#'(lambda ()
10911 (when anything-c-use-adaptative-sorting
10912 (anything-c-adaptive-store-selection))))
10914 ;; Should run at beginning of `anything-select-action'.
10915 (add-hook 'anything-select-action-hook
#'(lambda ()
10916 (when anything-c-use-adaptative-sorting
10917 (anything-c-adaptive-store-selection))))
10919 (defun anything-c-source-use-adaptative-p (&optional source-name
)
10920 "Return current source only if it use adaptative history, nil otherwise."
10921 (when anything-c-use-adaptative-sorting
10922 (let* ((source (or source-name
(anything-get-current-source)))
10923 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10924 (assoc (assoc-default 'type source
)
10925 anything-type-attributes
))
10926 (assoc-default 'candidate-transformer
10927 (assoc (assoc-default 'type source
)
10928 anything-type-attributes
))
10929 (assoc-default 'filtered-candidate-transformer source
)
10930 (assoc-default 'candidate-transformer source
))))
10931 (if (listp adapt-source
)
10932 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
10933 (when (eq adapt-source
'anything-c-adaptive-sort
) source
)))))
10935 (defun anything-c-adaptive-store-selection ()
10936 "Store history information for the selected candidate."
10937 (unless anything-c-adaptive-done
10938 (setq anything-c-adaptive-done t
)
10939 (let ((source (anything-c-source-use-adaptative-p)))
10941 (let* ((source-name (or (assoc-default 'type source
)
10942 (assoc-default 'name source
)))
10943 (source-info (or (assoc source-name anything-c-adaptive-history
)
10945 (push (list source-name
) anything-c-adaptive-history
)
10946 (car anything-c-adaptive-history
))))
10947 (selection (anything-get-selection))
10948 (selection-info (progn
10949 (setcdr source-info
10951 (let ((found (assoc selection
(cdr source-info
))))
10956 ;; move entry to the beginning of the
10957 ;; list, so that it doesn't get
10958 ;; trimmed when the history is
10960 (setcdr source-info
10961 (delete found
(cdr source-info
)))
10963 (cdr source-info
)))
10964 (cadr source-info
)))
10965 (pattern-info (progn
10966 (setcdr selection-info
10968 (let ((found (assoc anything-pattern
(cdr selection-info
))))
10971 (cons anything-pattern
0)
10973 ;; move entry to the beginning of the
10974 ;; list, so if two patterns used the
10975 ;; same number of times then the one
10976 ;; used last appears first in the list
10977 (setcdr selection-info
10978 (delete found
(cdr selection-info
)))
10980 (cdr selection-info
)))
10981 (cadr selection-info
))))
10983 ;; increase usage count
10984 (setcdr pattern-info
(1+ (cdr pattern-info
)))
10986 ;; truncate history if needed
10987 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
10988 (setcdr selection-info
10989 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
10991 (defun anything-c-adaptative-maybe-load-history ()
10992 (when (and anything-c-use-adaptative-sorting
10993 (file-readable-p anything-c-adaptive-history-file
))
10994 (load-file anything-c-adaptive-history-file
)))
10996 (add-hook 'emacs-startup-hook
'anything-c-adaptative-maybe-load-history
)
10997 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
10999 (defun anything-c-adaptive-save-history (&optional arg
)
11000 "Save history information to file given by `anything-c-adaptive-history-file'."
11002 (when anything-c-use-adaptative-sorting
11005 ";; -*- mode: emacs-lisp -*-\n"
11006 ";; History entries used for anything adaptive display.\n")
11007 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
11010 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
11011 (unless arg
'quiet
)))))
11013 (defun anything-c-adaptive-sort (candidates source
)
11014 "Sort the CANDIDATES for SOURCE by usage frequency.
11015 This is a filtered candidate transformer you can use for the
11016 attribute `filtered-candidate-transformer' of a source in
11017 `anything-sources' or a type in `anything-type-attributes'."
11018 (let* ((source-name (or (assoc-default 'type source
)
11019 (assoc-default 'name source
)))
11020 (source-info (assoc source-name anything-c-adaptive-history
)))
11023 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
11025 (mapcar (lambda (candidate-info)
11027 (dolist (pattern-info (cdr candidate-info
))
11028 (if (not (equal (car pattern-info
)
11030 (incf count
(cdr pattern-info
))
11032 ;; if current pattern is equal to the previously
11033 ;; used one then this candidate has priority
11034 ;; (that's why its count is boosted by 10000) and
11035 ;; it only has to compete with other candidates
11036 ;; which were also selected with the same pattern
11037 (setq count
(+ 10000 (cdr pattern-info
)))
11039 (cons (car candidate-info
) count
)))
11040 (cdr source-info
)))
11042 (if (and usage
(consp usage
))
11043 ;; sort the list in descending order, so candidates with highest
11044 ;; priorty come first
11046 (setq usage
(sort usage
(lambda (first second
)
11047 (> (cdr first
) (cdr second
)))))
11049 ;; put those candidates first which have the highest usage count
11050 (dolist (info usage
)
11051 (when (member* (car info
) candidates
11052 :test
'anything-c-adaptive-compare
)
11053 (push (car info
) sorted
)
11054 (setq candidates
(remove* (car info
) candidates
11055 :test
'anything-c-adaptive-compare
))))
11057 ;; and append the rest
11058 (append (reverse sorted
) candidates nil
))
11059 (message "Your `%s' is maybe corrupted or too old, \
11060 you should reinitialize it with `anything-c-reset-adaptative-history'"
11061 anything-c-adaptive-history-file
)
11064 ;; if there is no information stored for this source then do nothing
11068 (defun anything-c-reset-adaptative-history ()
11069 "Delete all `anything-c-adaptive-history' and his file.
11070 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
11072 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
11073 (setq anything-c-adaptive-history nil
)
11074 (delete-file anything-c-adaptive-history-file
)))
11076 (defun anything-c-adaptive-compare (x y
)
11077 "Compare candidates X and Y taking into account that the
11078 candidate can be in (DISPLAY . REAL) format."
11079 (equal (if (listp x
)
11091 (defvar anything-outline-goto-near-line-flag t
)
11092 (defvar anything-outline-using nil
)
11093 (defun anything-after-update-hook--outline ()
11094 (if (and (eq anything-outline-using t
)
11095 (eq anything-outline-goto-near-line-flag t
))
11096 (anything-outline-goto-near-line)))
11097 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
11099 (defun anything-outline-goto-near-line ()
11100 (with-anything-window
11101 ;; TODO need consideration whether to update position by every input.
11102 (when t
; (equal anything-pattern "")
11103 (anything-goto-line 2)
11104 (let ((lineno (with-anything-current-buffer
11105 (line-number-at-pos (car anything-current-position
)))))
11107 (while (<= (progn (skip-chars-forward " ")
11108 (or (number-at-point) lineno
))
11113 (return-from exit
))))
11115 (and (bobp) (forward-line 1))
11116 (and (anything-pos-header-line-p) (forward-line -
2))
11117 (anything-mark-current-line)))))
11124 ;; Plug-in: info-index
11125 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
11127 (unless (anything-candidate-buffer)
11128 (save-window-excursion
11131 (tobuf (anything-candidate-buffer 'global
))
11132 (infobuf (current-buffer))
11134 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
11135 (Info-goto-node node
)
11136 (goto-char (point-min))
11137 (while (search-forward "\n* " nil t
)
11138 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
11139 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
11140 (setq s
(point-at-bol)
11142 (with-current-buffer tobuf
11143 (insert-buffer-substring infobuf s e
)
11144 (insert "\n"))))))))))
11146 (defun anything-c-info-goto (node-line)
11147 (Info-goto-node (car node-line
))
11148 (anything-goto-line (cdr node-line
)))
11150 (defun anything-c-info-display-to-real (line)
11152 ;; This regexp is stolen from Info-apropos-matches
11153 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
11154 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
11155 (string-to-number (or (match-string 3 line
) "1")))))
11157 (defun anything-c-make-info-source (source file
)
11159 (name .
,(concat "Info Index: " file
))
11160 (info-file .
,file
)
11161 (init . anything-c-info-init
)
11162 (display-to-real . anything-c-info-display-to-real
)
11163 (get-line . buffer-substring
)
11164 (candidates-in-buffer)
11165 (action ("Goto node" . anything-c-info-goto
))))
11167 (defun anything-compile-source--info-index (source)
11168 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
11169 (anything-c-make-info-source source it
)
11171 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
11173 (anything-document-attribute 'info-index
"info-index plugin"
11174 "Create a source of info index very easily.
11176 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11178 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
11179 "Index nodes of info file.
11181 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11182 Some info files are missing index specification.
11184 ex. See `anything-c-source-info-screen'.")
11186 ;; Plug-in: candidates-file
11187 (defun anything-compile-source--candidates-file (source)
11188 (if (assoc-default 'candidates-file source
)
11189 `((init anything-p-candidats-file-init
11190 ,@(let ((orig-init (assoc-default 'init source
)))
11191 (cond ((null orig-init
) nil
)
11192 ((functionp orig-init
) (list orig-init
))
11194 (candidates-in-buffer)
11197 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
11199 (defun anything-p-candidats-file-init ()
11200 (destructuring-bind (file &optional updating
)
11201 (anything-mklist (anything-attr 'candidates-file
))
11202 (setq file
(anything-interpret-value file
))
11203 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
11205 (buffer-disable-undo)
11206 (font-lock-mode -
1)
11207 (auto-revert-mode 1)))))
11209 (anything-document-attribute 'candidates-file
"candidates-file plugin"
11210 "Use a file as the candidates buffer.
11212 1st argument is a filename, string or function name or variable name.
11213 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11215 ;; Plug-in: headline
11216 (defun anything-compile-source--anything-headline (source)
11217 (if (assoc-default 'headline source
)
11218 (append '((init . anything-headline-init
)
11219 (get-line . buffer-substring
)
11222 '((candidates-in-buffer)
11223 (persistent-help .
"Show this line")))
11225 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
11227 (defun anything-headline-init ()
11228 (when (and (anything-current-buffer-is-modified)
11229 (with-anything-current-buffer
11230 (eval (or (anything-attr 'condition
) t
))))
11231 (anything-headline-make-candidate-buffer
11232 (anything-interpret-value (anything-attr 'headline
))
11233 (anything-interpret-value (anything-attr 'subexp
)))))
11235 (anything-document-attribute 'headline
"Headline plug-in"
11236 "Regexp string for anything-headline to scan.")
11237 (anything-document-attribute 'condition
"Headline plug-in"
11238 "A sexp representing the condition to use anything-headline.")
11239 (anything-document-attribute 'subexp
"Headline plug-in"
11240 "Display (match-string-no-properties subexp).")
11242 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11245 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11246 ;; 2. Sort this list by start-of-match.
11247 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11249 ;; It's quite brilliantly written.
11253 (defun anything-headline-get-candidates (regexp subexp
)
11254 (with-anything-current-buffer
11256 (goto-char (point-min))
11257 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
11258 (let (hierarchy curhead
)
11260 (if (numberp subexp
)
11261 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
11262 (cons (buffer-substring (point-at-bol) (point-at-eol))
11264 (hierarchies (headlines)
11265 (1+ (loop for
(_ . hierarchy
) in headlines
11266 maximize hierarchy
)))
11268 (loop for i from
0 to hierarchy
11269 collecting
(aref curhead i
)))
11270 (arrange (headlines)
11271 (unless (null headlines
) ; FIX headlines empty bug!
11272 (loop with curhead
= (make-vector (hierarchies headlines
) "")
11273 for
((str . pt
) . hierarchy
) in headlines
11274 do
(aset curhead hierarchy str
)
11277 (format "H%d:%s" (1+ hierarchy
)
11278 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
11283 (loop for re in regexp
11284 for hierarchy from
0
11285 do
(goto-char (point-min))
11288 while
(re-search-forward re nil t
)
11289 collect
(cons (matched) hierarchy
)))
11290 (lambda (a b
) (> (cdar b
) (cdar a
)))))
11291 (loop while
(re-search-forward regexp nil t
)
11292 collect
(matched))))))))
11295 (defun anything-headline-make-candidate-buffer (regexp subexp
)
11296 (with-current-buffer (anything-candidate-buffer 'local
)
11297 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
11300 (with-anything-current-buffer
11301 (line-number-at-pos pos
))
11304 (defun anything-headline-goto-position (pos recenter
)
11307 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
11310 ;; Plug-in: persistent-help
11311 (defun anything-compile-source--persistent-help (source)
11312 (append source
'((header-line . anything-persistent-help-string
))))
11313 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
11315 (defun anything-persistent-help-string ()
11316 (substitute-command-keys
11317 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11318 (or (anything-interpret-value (anything-attr 'persistent-help
))
11319 (anything-aif (or (assoc-default 'persistent-action
11320 (anything-get-current-source))
11321 (assoc-default 'action
11322 (anything-get-current-source)))
11323 (cond ((symbolp it
) (symbol-name it
))
11324 ((listp it
) (or (ignore-errors (caar it
)) ""))))
11326 " (keeping session)")))
11328 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
11329 "A string to explain persistent-action of this source.
11330 It also accepts a function or a variable name.")
11332 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11334 ;; Plug-in: Type customize
11335 (defun anything-c-uniq-list (lst)
11336 "Like `remove-duplicates' in CL.
11337 But cut deeper duplicates and test by `equal'. "
11338 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
11339 (defvar anything-additional-type-attributes nil
)
11340 (defun anything-c-arrange-type-attribute (type spec
)
11341 "Override type attributes by `define-anything-type-attribute'.
11343 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11345 Example: Set `play-sound-file' as default action
11346 (anything-c-arrange-type-attribute 'file
11347 '((action (\"Play sound\" . play-sound-file)
11348 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11351 (add-to-list 'anything-additional-type-attributes
11353 (loop with typeattr
= (assoc-default type anything-type-attributes
)
11354 for
(attr . value
) in spec
11357 (anything-c-uniq-list
11358 (loop for v in value
11360 append
(assoc-default attr typeattr
)
11364 collect
(cons attr value
)))))
11365 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
11367 (defun anything-compile-source--type-customize (source)
11368 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
11371 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
11373 ;; Plug-in: default-action
11374 (defun anything-compile-source--default-action (source)
11375 (anything-aif (assoc-default 'default-action source
)
11376 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
11379 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
11380 (anything-document-attribute 'default-action
"default-action plug-in"
11384 ;;; Toggle anything-match-plugin
11387 (defvar anything-mp-initial-highlight-delay nil
)
11390 (defun anything-c-toggle-match-plugin ()
11391 "Toggle anything-match-plugin."
11393 (let ((anything-match-plugin-enabled
11394 (member 'anything-compile-source--match-plugin
11395 anything-compile-source-functions
)))
11396 (flet ((disable-match-plugin ()
11397 (setq anything-compile-source-functions
11398 (delq 'anything-compile-source--match-plugin
11399 anything-compile-source-functions
))
11400 (setq anything-mp-initial-highlight-delay
11401 anything-mp-highlight-delay
)
11402 (setq anything-mp-highlight-delay nil
))
11403 (enable-match-plugin ()
11404 (require 'anything-match-plugin
)
11405 (unless anything-mp-initial-highlight-delay
11406 (setq anything-mp-initial-highlight-delay
11407 anything-mp-highlight-delay
))
11408 (setq anything-compile-source-functions
11409 (cons 'anything-compile-source--match-plugin
11410 anything-compile-source-functions
))
11411 (unless anything-mp-highlight-delay
11412 (setq anything-mp-highlight-delay
11413 anything-mp-initial-highlight-delay
))))
11414 (if anything-match-plugin-enabled
11415 (when (y-or-n-p "Really disable match-plugin? ")
11416 (disable-match-plugin)
11417 (message "Anything-match-plugin disabled"))
11418 (when (y-or-n-p "Really enable match-plugin? ")
11419 (enable-match-plugin)
11420 (message "Anything-match-plugin enabled"))))))
11424 ;;; Type Attributes
11427 (define-anything-type-attribute 'buffer
11429 ("Switch to buffer" . anything-c-switch-to-buffer
)
11430 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin
:popup-buffer
))
11431 ("Switch to buffer other window" . switch-to-buffer-other-window
)
11432 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)
11433 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
11434 ("Query replace regexp" . anything-c-buffer-query-replace-regexp
)
11435 ("Query replace" . anything-c-buffer-query-replace
)
11436 ("View buffer" . view-buffer
)
11437 ("Display buffer" . display-buffer
)
11438 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers
)
11439 ("Revert buffer(s)" . anything-revert-marked-buffers
)
11440 ("Insert buffer" . insert-buffer
)
11441 ("Kill buffer(s)" . anything-kill-marked-buffers
)
11442 ("Diff with file" . diff-buffer-with-file
)
11443 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
11444 ("Ediff Merge marked buffers" .
(lambda (candidate)
11445 (anything-ediff-marked-buffers candidate t
))))
11446 (persistent-help .
"Show this buffer")
11447 (candidate-transformer anything-c-skip-current-buffer
11448 anything-c-skip-boring-buffers
11449 anything-c-transform-buffer-display-string
))
11450 "Buffer or buffer name.")
11452 (define-anything-type-attribute 'file
11454 ("Find file" . anything-find-many-files
)
11455 ,(and (locate-library "popwin") '("Find file in popup window" . popwin
:find-file
))
11456 ("Find file as root" . anything-find-file-as-root
)
11457 ("Find file other window" . find-file-other-window
)
11458 ("Find file other frame" . find-file-other-frame
)
11459 ("Open dired in file's directory" . anything-c-open-dired
)
11460 ("Grep File(s) `C-u recurse'" . anything-find-files-grep
)
11461 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep
)
11462 ("Pdfgrep File(s)" . anything-ff-pdfgrep
)
11463 ("Checksum File" . anything-ff-checksum
)
11464 ("Ediff File" . anything-find-files-ediff-files
)
11465 ("Ediff Merge File" . anything-find-files-ediff-merge-files
)
11466 ("View file" . view-file
)
11467 ("Insert file" . insert-file
)
11468 ("Delete file(s)" . anything-delete-marked-files
)
11469 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
11470 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
11471 ("Find file in hex dump" . hexl-find-file
))
11472 (persistent-help .
"Show this file")
11473 (action-transformer anything-c-transform-file-load-el
11474 anything-c-transform-file-browse-url
)
11475 (candidate-transformer anything-c-w32-pathname-transformer
11476 anything-c-skip-current-file
11477 anything-c-skip-boring-files
11478 anything-c-shorten-home-path
))
11481 (let ((actions '(("Describe command" . describe-function
)
11482 ("Add command to kill ring" . anything-c-kill-new
)
11483 ("Go to command's definition" . find-function
)
11484 ("Debug on entry" . debug-on-entry
)
11485 ("Cancel debug on entry" . cancel-debug-on-entry
)
11486 ("Trace function" . trace-function
)
11487 ("Trace function (background)" . trace-function-background
)
11488 ("Untrace function" . untrace-function
))))
11489 (define-anything-type-attribute 'command
11490 `((action ("Call interactively" . anything-c-call-interactively
)
11492 ;; Sort commands according to their usage count.
11493 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11494 (coerce . anything-c-symbolify
)
11495 (persistent-action . describe-function
))
11496 "Command. (string or symbol)")
11498 (define-anything-type-attribute 'function
11499 `((action .
,actions
)
11500 (action-transformer anything-c-transform-function-call-interactively
)
11501 (candidate-transformer anything-c-mark-interactive-functions
)
11502 (coerce . anything-c-symbolify
))
11503 "Function. (string or symbol)"))
11505 (define-anything-type-attribute 'variable
11506 '((action ("Describe variable" . describe-variable
)
11507 ("Add variable to kill ring" . anything-c-kill-new
)
11508 ("Go to variable's definition" . find-variable
)
11509 ("Set variable" . anything-c-set-variable
))
11510 (coerce . anything-c-symbolify
))
11513 (define-anything-type-attribute 'sexp
11514 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
11515 ("Add s-expression to kill ring" . kill-new
))
11516 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
11517 "String representing S-Expressions.")
11519 (define-anything-type-attribute 'bookmark
11520 `((coerce . anything-bookmark-get-bookmark-from-name
)
11522 ("Jump to bookmark" .
(lambda (bookmark)
11523 (let ((current-prefix-arg anything-current-prefix-arg
))
11524 (bookmark-jump bookmark
))
11525 (anything-update)))
11526 ("Jump to BM other window" .
(lambda (bookmark)
11527 (bookmark-jump-other-window bookmark
)
11528 (anything-update)))
11529 ("Bookmark edit annotation" . bookmark-edit-annotation
)
11530 ("Bookmark show annotation" . bookmark-show-annotation
)
11531 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
11532 ,@(and (locate-library "bookmark-extensions")
11533 `(("Edit Bookmark" . bmkext-edit-bookmark
)))
11534 ("Rename bookmark" . bookmark-rename
)
11535 ("Relocate bookmark" . bookmark-relocate
)))
11538 (define-anything-type-attribute 'line
11539 '((display-to-real . anything-c-display-to-real-line
)
11540 (action ("Go to Line" . anything-c-action-line-goto
)))
11541 "LINENO:CONTENT string, eg. \" 16:foo\".
11543 Optional `target-file' attribute is a name of target file.
11545 Optional `before-jump-hook' attribute is a function with no
11546 arguments which is called before jumping to position.
11548 Optional `after-jump-hook' attribute is a function with no
11549 arguments which is called after jumping to position.
11551 If `adjust' attribute is specified, searches the line whose
11552 content is CONTENT near the LINENO.
11554 If `recenter' attribute is specified, the line is displayed at
11555 the center of window, otherwise at the top of window.
11558 (define-anything-type-attribute 'file-line
11559 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
11561 (action ("Go to" . anything-c-action-file-line-goto
)))
11562 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11564 Optional `default-directory' attribute is a default-directory
11565 FILENAME is interpreted.
11567 Optional `before-jump-hook' attribute is a function with no
11568 arguments which is called before jumping to position.
11570 Optional `after-jump-hook' attribute is a function with no
11571 arguments which is called after jumping to position.
11573 If `adjust' attribute is specified, searches the line whose
11574 content is CONTENT near the LINENO.
11576 If `recenter' attribute is specified, the line is displayed at
11577 the center of window, otherwise at the top of window.
11580 (define-anything-type-attribute 'timer
11581 '((real-to-display . anything-c-timer-real-to-display
)
11582 (action ("Cancel Timer" . cancel-timer
)
11583 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
11584 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
11585 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
11586 (persistent-help .
"Describe Function"))
11590 ;;; Default `anything-sources'
11591 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11592 ;; tend to invoke M-x anything directly. So I offer default setting.
11593 (setq anything-sources
11594 '(anything-c-source-buffers-list
11595 anything-c-source-recentf
11596 anything-c-source-files-in-current-dir
+))
11599 ;;; Preconfigured Anything
11603 (defun anything-mini ()
11604 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
11606 (anything-other-buffer '(anything-c-source-buffers-list
11607 anything-c-source-recentf
11608 anything-c-source-buffer-not-found
)
11609 "*anything mini*"))
11611 (defun anything-for-files ()
11612 "Preconfigured `anything' for opening files.
11613 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
11615 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
11618 (defun anything-recentf ()
11619 "Preconfigured `anything' for `recentf'."
11621 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
11624 (defun anything-info-at-point (arg)
11625 "Preconfigured `anything' for searching info at point.
11626 With a prefix-arg insert symbol at point."
11628 (let ((anything-c-google-suggest-default-function
11629 'anything-c-google-suggest-emacs-lisp
))
11630 (anything :sources
'(anything-c-source-info-elisp
11631 anything-c-source-info-cl
11632 anything-c-source-info-pages
11633 anything-c-source-google-suggest
)
11634 :input
(and arg
(thing-at-point 'symbol
))
11635 :buffer
"*anything info*")))
11638 (defun anything-info-emacs ()
11639 "Preconfigured anything for Emacs manual index."
11641 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
11644 (defun anything-show-kill-ring ()
11645 "Preconfigured `anything' for `kill-ring'.
11646 It is drop-in replacement of `yank-pop'.
11647 You may bind this command to M-y.
11648 First call open the kill-ring browser, next calls move to next line."
11650 (let ((buf "*anything kill-ring*"))
11651 (if (get-buffer-window buf
)
11652 (with-anything-window
11653 (if (eq (overlay-end anything-selection-overlay
) (point-max))
11654 (anything-beginning-of-buffer)
11655 (anything-next-line)))
11656 (anything-other-buffer 'anything-c-source-kill-ring buf
))))
11659 (defun anything-minibuffer-history ()
11660 "Preconfigured `anything' for `minibuffer-history'."
11662 (let ((enable-recursive-minibuffers t
))
11663 (anything-other-buffer 'anything-c-source-minibuffer-history
11664 "*anything minibuffer-history*")))
11667 (defun anything-gentoo ()
11668 "Preconfigured `anything' for gentoo linux."
11670 (anything-other-buffer '(anything-c-source-gentoo
11671 anything-c-source-use-flags
)
11672 "*anything gentoo*"))
11675 (defun anything-imenu ()
11676 "Preconfigured `anything' for `imenu'."
11678 (anything :sources
'anything-c-source-imenu
11679 :buffer
"*anything imenu*"))
11682 (defun anything-google-suggest ()
11683 "Preconfigured `anything' for google search with google suggest."
11685 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
11688 (defun anything-yahoo-suggest ()
11689 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
11691 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
11693 ;;; Converted from anything-show-*-only
11695 (defun anything-for-buffers ()
11696 "Preconfigured `anything' for buffer."
11698 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
11701 (defun anything-buffers-list ()
11702 "Enhanced preconfigured `anything' for buffer."
11704 (anything :sources
'(anything-c-source-buffers-list
11705 anything-c-source-buffer-not-found
)
11706 :buffer
"*anything buffers*" :keymap anything-c-buffer-map
))
11709 (defun anything-bbdb ()
11710 "Preconfigured `anything' for BBDB.
11714 http://bbdb.sourceforge.net/"
11716 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
11719 (defun anything-locate (arg)
11720 "Preconfigured `anything' for Locate.
11721 Note: you can add locate options after entering pattern.
11722 See 'man locate' for valid options.
11724 You can specify a specific database with prefix argument ARG \(C-u\).
11725 Many databases can be used: navigate and mark them.
11726 See also `anything-locate-with-db'.
11728 To create a user specific db, use
11729 \"updatedb -l 0 -o db_path -U directory\".
11730 Where db_path is a filename matched by
11731 `anything-locate-db-file-regexp'."
11733 (anything-locate-1 arg
))
11736 (defun anything-w3m-bookmarks ()
11737 "Preconfigured `anything' for w3m bookmark.
11739 Needs w3m and emacs-w3m.
11741 http://w3m.sourceforge.net/
11742 http://emacs-w3m.namazu.org/"
11744 (anything-other-buffer 'anything-c-source-w3m-bookmarks
11745 "*anything w3m bookmarks*"))
11748 (defun anything-firefox-bookmarks ()
11749 "Preconfigured `anything' for firefox bookmark.
11750 You will have to enable html bookmarks in firefox:
11751 open about:config in firefox and double click on this line to enable value \
11754 user_pref(\"browser.bookmarks.autoExportHTML\", false);
11756 You should have now:
11758 user_pref(\"browser.bookmarks.autoExportHTML\", true);
11760 After closing firefox, you will be able to browse you bookmarks.
11763 (anything-other-buffer 'anything-c-source-firefox-bookmarks
11764 "*Anything Firefox*"))
11767 (defun anything-colors ()
11768 "Preconfigured `anything' for color."
11770 (anything-other-buffer
11771 '(anything-c-source-colors anything-c-source-customize-face
)
11772 "*anything colors*"))
11775 (defun anything-bookmarks ()
11776 "Preconfigured `anything' for bookmarks."
11778 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
11781 (defun anything-c-pp-bookmarks ()
11782 "Preconfigured `anything' for bookmarks (pretty-printed)."
11784 (anything-other-buffer '(anything-c-source-bookmarks-local
11785 anything-c-source-bookmarks-su
11786 anything-c-source-bookmarks-ssh
)
11787 "*anything pp bookmarks*"))
11790 (defun anything-c-insert-latex-math ()
11791 "Preconfigured anything for latex math symbols completion."
11793 (anything-other-buffer 'anything-c-source-latex-math
"*anything latex*"))
11796 (defun anything-register ()
11797 "Preconfigured `anything' for Emacs registers."
11799 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
11802 (defun anything-man-woman ()
11803 "Preconfigured `anything' for Man and Woman pages."
11805 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
11808 (defun anything-org-keywords ()
11809 "Preconfigured `anything' for org keywords."
11811 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
11814 (defun anything-emms ()
11815 "Preconfigured `anything' for emms sources."
11817 (anything :sources
'(anything-c-source-emms-streams
11818 anything-c-source-emms-files
11819 anything-c-source-emms-dired
)
11820 :buffer
"*Anything Emms*"))
11823 (defun anything-eev-anchors ()
11824 "Preconfigured `anything' for eev anchors."
11826 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
11829 (defun anything-bm-list ()
11830 "Preconfigured `anything' for visible bookmarks.
11834 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
11836 (let ((anything-outline-using t
))
11837 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
11840 (defun anything-timers ()
11841 "Preconfigured `anything' for timers."
11843 (anything-other-buffer '(anything-c-source-absolute-time-timers
11844 anything-c-source-idle-time-timers
)
11845 "*anything timers*"))
11848 (defun anything-list-emacs-process ()
11849 "Preconfigured `anything' for emacs process."
11851 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
11854 (defun anything-occur ()
11855 "Preconfigured Anything for Occur source.
11856 If region is active, search only in region,
11857 otherwise search in whole buffer."
11859 (let ((anything-compile-source-functions
11860 ;; rule out anything-match-plugin because the input is one regexp.
11861 (delq 'anything-compile-source--match-plugin
11862 (copy-sequence anything-compile-source-functions
))))
11863 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
11866 (defun anything-browse-code ()
11867 "Preconfigured anything to browse code."
11869 (anything :sources
'anything-c-source-browse-code
11870 :buffer
"*anything browse code*"
11871 :default
(thing-at-point 'symbol
)))
11874 (defun anything-org-headlines ()
11875 "Preconfigured anything to show org headlines."
11877 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
11880 (defun anything-info-gnus ()
11881 "Preconfigured anything to browse Gnus Manual."
11883 (anything-other-buffer 'anything-c-source-info-gnus
"*info Gnus*"))
11886 (defun anything-regexp ()
11887 "Preconfigured anything to build regexps.
11888 `query-replace-regexp' can be run from there against found regexp."
11891 (let ((anything-compile-source-functions
11892 ;; rule out anything-match-plugin because the input is one regexp.
11893 (delq 'anything-compile-source--match-plugin
11894 (copy-sequence anything-compile-source-functions
))))
11895 (when (and (anything-region-active-p)
11896 ;; Don't narrow to region if buffer is already narrowed.
11897 (not (anything-current-buffer-narrowed-p)))
11898 (narrow-to-region (region-beginning) (region-end)))
11899 (anything :sources anything-c-source-regexp
11900 :buffer
"*anything regexp*"
11902 :history
'anything-build-regexp-history
))))
11905 (defun anything-c-copy-files-async ()
11906 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
11908 (let* ((flist (anything-c-read-file-name
11909 "Copy File async: "
11910 :marked-candidates t
))
11911 (dest (anything-c-read-file-name
11912 "Copy File async To: "
11913 :preselect
(car flist
)
11914 :initial-input
(car anything-ff-history
)
11915 :history
(anything-find-files-history :comp-read nil
))))
11916 (anything-c-copy-async-with-log flist dest
)))
11919 (defun anything-find-files (arg)
11920 "Preconfigured `anything' for anything implementation of `find-file'.
11921 Called with a prefix arg show history if some.
11922 Don't call it from programs, use `anything-find-files-1' instead.
11923 This is the starting point for nearly all actions you can do on files."
11925 (let ((any-input (if (and arg anything-ff-history
)
11926 (anything-find-files-history)
11927 (anything-find-files-initial-input)))
11928 (presel (buffer-file-name (current-buffer))))
11929 (when (and (eq major-mode
'org-agenda-mode
)
11932 (setq any-input
(expand-file-name org-directory
)))
11933 (set-text-properties 0 (length any-input
) nil any-input
)
11935 (anything-find-files-1 any-input
)
11936 (setq any-input
(expand-file-name (anything-c-current-directory)))
11937 (anything-find-files-1
11938 any-input
(if anything-ff-transformer-show-only-basename
11939 (and presel
(anything-c-basename presel
))
11943 (defun anything-write-file ()
11944 "Preconfigured `anything' providing completion for `write-file'."
11946 (let ((anything-mp-highlight-delay nil
))
11947 (anything :sources
'anything-c-source-write-file
11948 :input
(expand-file-name default-directory
)
11949 :prompt
"Write buffer to file: "
11950 :buffer
"*Anything write file*")))
11953 (defun anything-insert-file ()
11954 "Preconfigured `anything' providing completion for `insert-file'."
11956 (let ((anything-mp-highlight-delay nil
))
11957 (anything :sources
'anything-c-source-insert-file
11958 :input
(expand-file-name default-directory
)
11959 :prompt
"Insert file: "
11960 :buffer
"*Anything insert file*")))
11963 (defun anything-dired-rename-file ()
11964 "Preconfigured `anything' to rename files from dired."
11966 (anything-dired-do-action-on-file :action
'rename
))
11969 (defun anything-dired-copy-file ()
11970 "Preconfigured `anything' to copy files from dired."
11972 (anything-dired-do-action-on-file :action
'copy
))
11975 (defun anything-dired-symlink-file ()
11976 "Preconfigured `anything' to symlink files from dired."
11978 (anything-dired-do-action-on-file :action
'symlink
))
11981 (defun anything-dired-hardlink-file ()
11982 "Preconfigured `anything' to hardlink files from dired."
11984 (anything-dired-do-action-on-file :action
'hardlink
))
11987 (defun anything-do-grep ()
11988 "Preconfigured anything for grep.
11989 Contrarily to Emacs `grep' no default directory is given, but
11990 the full path of candidates in ONLY.
11991 That allow to grep different files not only in `default-directory' but anywhere
11992 by marking them (C-<SPACE>). If one or more directory is selected
11993 grep will search in all files of these directories.
11994 You can use also wildcard in the base name of candidate.
11995 If a prefix arg is given use the -r option of grep.
11996 The prefix arg can be passed before or after start.
11997 See also `anything-do-grep-1'."
11999 (let ((only (anything-c-read-file-name
12000 "Search in file(s): "
12001 :marked-candidates t
12002 :preselect
(or (dired-get-filename nil t
)
12003 (buffer-file-name (current-buffer)))))
12004 (prefarg (or current-prefix-arg anything-current-prefix-arg
)))
12005 (anything-do-grep-1 only prefarg
)))
12008 (defun anything-do-zgrep (candidate)
12009 "Preconfigured anything for zgrep."
12010 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
12011 (ls (anything-c-read-file-name
12012 "Search in file(s): "
12013 :marked-candidates t
12014 :preselect
(or (dired-get-filename nil t
)
12015 (buffer-file-name (current-buffer))))))
12016 (anything-ff-zgrep-1 ls prefarg
)))
12018 (defun anything-c-etags-select (arg)
12019 "Preconfigured anything for etags.
12020 Called with one prefix arg use symbol at point as initial input.
12021 Called with two prefix arg reinitialize cache.
12022 If tag file have been modified reinitialize cache."
12024 (let ((tag (anything-c-etags-get-tag-file))
12025 (init (and (equal arg
'(4)) (thing-at-point 'symbol
)))
12026 (anything-quit-if-no-candidate t
)
12027 (anything-execute-action-at-once-if-one t
)
12028 (anything-compile-source-functions
12029 (if anything-c-etags-use-regexp-search
12030 ;; rule out anything-match-plugin because the input is one regexp.
12031 (delq 'anything-compile-source--match-plugin
12032 (copy-sequence anything-compile-source-functions
))
12033 anything-compile-source-functions
)))
12034 (when (or (equal arg
'(16))
12035 (and anything-c-etags-mtime-alist
12036 (anything-c-etags-file-modified-p tag
)))
12037 (remhash tag anything-c-etags-cache
))
12038 (if (and tag
(file-exists-p tag
))
12039 (anything :sources
'anything-c-source-etags-select
12040 :keymap anything-c-etags-map
12042 :buffer
"*anything etags*")
12043 (message "Error: No tag file found, please create one with etags shell command."))))
12046 (defun anything-filelist ()
12047 "Preconfigured `anything' to open files instantly.
12049 See `anything-c-filelist-file-name' docstring for usage."
12051 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
12054 (defun anything-filelist+ ()
12055 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
12057 This is a replacement for `anything-for-files'.
12058 See `anything-c-filelist-file-name' docstring for usage."
12060 (anything-other-buffer
12061 '(anything-c-source-ffap-line
12062 anything-c-source-ffap-guesser
12063 anything-c-source-buffers-list
12064 anything-c-source-recentf
12065 anything-c-source-bookmarks
12066 anything-c-source-file-cache
12067 anything-c-source-filelist
)
12068 "*anything file list*"))
12071 (defun anything-M-x ()
12072 "Preconfigured `anything' for Emacs commands.
12073 It is `anything' replacement of regular `M-x' `execute-extended-command'."
12077 special-display-buffer-names
12078 special-display-regexps
12079 anything-persistent-action-use-special-display
12080 (history (loop with hist
12081 for i in extended-command-history
12082 for com
= (intern i
)
12084 collect i into hist finally return hist
)))
12085 (flet ((pers-help (candidate)
12086 (let ((hbuf (get-buffer (help-buffer))))
12087 (if (and in-help
(string= candidate help-cand
))
12089 ;; When M-x is started from a help buffer,
12090 ;; Don't kill it as it is anything-current-buffer.
12091 (unless (equal hbuf anything-current-buffer
)
12092 (kill-buffer hbuf
))
12093 (setq in-help nil
))
12094 ;; Be sure anything-current-buffer
12095 ;; have not a dedicated window.
12096 (set-window-dedicated-p
12097 (get-buffer-window anything-current-buffer
) nil
)
12098 (describe-function (intern candidate
))
12099 (message nil
) ; Erase the new stupid message Type "q"[...]
12101 (setq help-cand candidate
))))
12106 `(((name .
"Emacs Commands history")
12107 (candidates .
,history
)
12108 (filtered-candidate-transformer
12109 .
(lambda (candidates sources
)
12110 (loop for i in candidates
12111 do
(set-text-properties 0 (length i
) nil i
)
12113 (persistent-action . pers-help
)
12114 (persistent-help .
"Describe this command")
12115 (action . identity
))
12116 ((name .
"Emacs Commands")
12119 (with-current-buffer (anything-candidate-buffer 'global
)
12120 (goto-char (point-min))
12122 (all-completions "" obarray
'commandp
)
12123 do
(insert (concat sym
"\n"))))))
12124 (persistent-action . pers-help
)
12125 (persistent-help .
"Describe this command")
12126 (filtered-candidate-transformer . anything-M-x-transformer
)
12127 (candidates-in-buffer)
12128 (action . identity
)))
12131 :history
'anything-M-x-input-history
12132 :buffer
"*anything M-x*")
12134 (sym-com (intern command
)))
12135 (unless current-prefix-arg
12136 (setq current-prefix-arg anything-current-prefix-arg
))
12137 ;; Avoid having `this-command' set to *exit-minibuffer.
12138 (setq this-command sym-com
)
12139 (call-interactively sym-com
)
12140 (setq extended-command-history
12141 (cons command
(delete command history
)))))))
12144 (defun anything-manage-advice ()
12145 "Preconfigured `anything' to disable/enable function advices."
12147 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
12150 (defun anything-bookmark-ext ()
12151 "Preconfigured `anything' for bookmark-extensions sources.
12152 Needs bookmark-ext.el:
12153 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
12154 Contain also `anything-c-source-google-suggest'."
12158 '(anything-c-source-bookmark-files&dirs
12159 anything-c-source-bookmark-w3m
12160 anything-c-source-google-suggest
12161 anything-c-source-bmkext-addressbook
12162 anything-c-source-bookmark-gnus
12163 anything-c-source-bookmark-info
12164 anything-c-source-bookmark-man
12165 anything-c-source-bookmark-images
12166 anything-c-source-bookmark-su-files
&dirs
12167 anything-c-source-bookmark-ssh-files
&dirs
)
12168 :prompt
"SearchBookmark: "
12169 :buffer
"*anything bmkext*"))
12172 (defun anything-simple-call-tree ()
12173 "Preconfigured `anything' for simple-call-tree. List function relationships.
12175 Needs simple-call-tree.el.
12176 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
12178 (anything-other-buffer
12179 '(anything-c-source-simple-call-tree-functions-callers
12180 anything-c-source-simple-call-tree-callers-functions
)
12181 "*anything simple-call-tree*"))
12184 (defun anything-mark-ring ()
12185 "Preconfigured `anything' for `anything-c-source-mark-ring'."
12187 (anything :sources
'anything-c-source-mark-ring
))
12190 (defun anything-global-mark-ring ()
12191 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
12193 (anything :sources
'anything-c-source-global-mark-ring
))
12196 (defun anything-all-mark-rings ()
12197 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
12198 `anything-c-source-mark-ring'."
12200 (anything :sources
'(anything-c-source-mark-ring
12201 anything-c-source-global-mark-ring
)))
12204 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
12205 "Preconfigured `anything' to edit or view EmacsWiki page.
12207 Needs yaoddmuse.el.
12209 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12211 (anything :sources
'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
12214 (defun anything-yaoddmuse-emacswiki-post-library ()
12215 "Preconfigured `anything' to post library to EmacsWiki.
12217 Needs yaoddmuse.el.
12219 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
12221 (anything :sources
'anything-c-source-yaoddmuse-emacswiki-post-library
))
12224 (defun anything-eval-expression (arg)
12225 "Preconfigured anything for `anything-c-source-evaluation-result'."
12227 (anything :sources
'anything-c-source-evaluation-result
12228 :input
(when arg
(thing-at-point 'sexp
))
12229 :buffer
"*anything eval*"
12230 :history
'anything-eval-expression-input-history
12231 :keymap anything-eval-expression-map
))
12234 (defun anything-eval-expression-with-eldoc ()
12235 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
12237 (declare (special eldoc-idle-delay
))
12238 (let ((timer (run-with-idle-timer eldoc-idle-delay
12239 'repeat
'anything-eldoc-show-in-eval
))
12240 (minibuffer-completing-symbol t
) ; Enable lisp completion.
12241 (completion-cycle-threshold t
)) ; Always cycle, no pesty completion buffer (emacs24 only).
12243 (minibuffer-with-setup-hook
12244 'anything-eldoc-store-minibuffer
12245 (call-interactively 'anything-eval-expression
))
12246 (and timer
(cancel-timer timer
))
12247 (setq anything-eldoc-active-minibuffers-list
12248 (cdr anything-eldoc-active-minibuffers-list
)))))
12251 (defun anything-calcul-expression ()
12252 "Preconfigured anything for `anything-c-source-calculation-result'."
12254 (anything-other-buffer 'anything-c-source-calculation-result
"*anything calcul*"))
12257 (defun anything-surfraw (pattern engine
)
12258 "Preconfigured `anything' to search PATTERN with search ENGINE."
12259 (interactive (list (read-string "SearchFor: "
12260 nil
'anything-surfraw-input-history
)
12261 (anything-comp-read
12263 (anything-c-build-elvi-list)
12265 :name
"Surfraw Search Engines"
12266 :history anything-surfraw-engines-history
)))
12267 (let* ((engine-nodesc (car (split-string engine
)))
12268 (url (with-temp-buffer
12269 (apply 'call-process
"surfraw" nil t nil
12271 (append (list engine-nodesc
"-p") (split-string pattern
)))
12272 (replace-regexp-in-string
12273 "\n" "" (buffer-string))))
12274 (browse-url-browser-function (or anything-surfraw-default-browser-function
12275 browse-url-browser-function
)))
12276 (if (string= engine-nodesc
"W")
12277 (anything-c-browse-url)
12278 (anything-c-browse-url url
)
12279 (setq anything-surfraw-engines-history
12280 (cons engine
(delete engine anything-surfraw-engines-history
))))))
12283 (defun anything-call-source ()
12284 "Preconfigured `anything' to call anything source."
12286 (anything :sources
'anything-c-source-call-source
12287 :buffer anything-source-select-buffer
))
12290 (defun anything-execute-anything-command ()
12291 "Preconfigured `anything' to execute preconfigured `anything'."
12293 (anything-other-buffer 'anything-c-source-anything-commands
12294 "*anything commands*"))
12297 (defun anything-create (&optional string initial-input
)
12298 "Preconfigured `anything' to do many create actions from STRING.
12299 See also `anything-create--actions'."
12301 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
12302 (anything :sources
'(((name .
"Anything Create")
12303 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
12304 (candidates . anything-create--actions
)
12305 (candidate-number-limit)
12306 (action .
(lambda (func) (funcall func string
)))))))
12309 (defun anything-top ()
12310 "Preconfigured `anything' for top command."
12312 (let ((anything-samewindow t
)
12313 (anything-enable-shortcuts)
12314 (anything-display-function 'anything-default-display-buffer
)
12315 (anything-candidate-number-limit 9999))
12316 (save-window-excursion
12317 (delete-other-windows)
12318 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
12321 (defun anything-select-xfont ()
12322 "Preconfigured `anything' to select Xfont."
12324 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
12327 (defun anything-world-time ()
12328 "Preconfigured `anything' to show world time."
12330 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
12333 (defun anything-apt (arg)
12334 "Preconfigured `anything' : frontend of APT package manager.
12335 With a prefix arg reload cache."
12337 (let ((query (read-string "Search Package: " nil
'anything-c-apt-input-history
)))
12338 (when arg
(anything-c-apt-refresh))
12339 (anything :sources
'anything-c-source-apt
12340 :prompt
"Search Package: "
12342 :history
'anything-c-apt-input-history
)))
12345 (defun anything-esh-pcomplete ()
12346 "Preconfigured anything to provide anything completion in eshell."
12348 (let* ((anything-quit-if-no-candidate t
)
12349 (anything-execute-action-at-once-if-one t
)
12350 (target (thing-at-point 'symbol
))
12352 (beg (or (and target
(- end
(length target
)))
12353 ;; Nothing at point.
12354 (progn (insert " ") (point)))))
12355 (setq anything-ec-target
(or target
" "))
12356 (with-anything-show-completion beg end
12357 (anything :sources
'anything-c-source-esh
12358 :input
(anything-ff-set-pattern ; Handle tramp filenames.
12359 (car (last (ignore-errors ; Needed in lisp symbols completion.
12360 (pcomplete-parse-arguments)))))))))
12363 (defun anything-eshell-history ()
12364 "Preconfigured anything for eshell history."
12366 (let* ((end (point))
12367 (beg (save-excursion (eshell-bol) (point)))
12371 (setq flag-empty t
)
12372 (setq end
(point)))
12374 (with-anything-show-completion beg end
12375 (anything :sources
'anything-c-source-eshell-history
12376 :buffer
"*Eshell history*"))
12377 (when (and flag-empty
12378 (looking-back " "))
12379 (delete-char -
1)))))
12382 (defun anything-c-run-external-command (program)
12383 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
12384 If program is already running exit with error.
12385 You can set your own list of commands with
12386 `anything-c-external-commands-list'."
12388 (anything-comp-read
12390 (anything-c-external-commands-list-1 'sort
)
12392 :name
"External Commands"
12393 :history anything-external-command-history
)))
12394 (anything-run-or-raise program
)
12395 (setq anything-external-command-history
12396 (cons program
(delete program
12397 (loop for i in anything-external-command-history
12398 when
(executable-find i
) collect i
)))))
12401 (defun anything-ratpoison-commands ()
12402 "Preconfigured `anything' to execute ratpoison commands."
12404 (anything-other-buffer 'anything-c-source-ratpoison-commands
12405 "*anything ratpoison commands*"))
12408 (defun anything-ucs ()
12409 "Preconfigured anything for `ucs-names' math symbols."
12411 (anything :sources
'anything-c-source-ucs
12412 :keymap anything-c-ucs-map
))
12415 (defun anything-c-apropos ()
12416 "Preconfigured anything to describe commands, functions, variables and faces."
12418 (let ((default (thing-at-point 'symbol
)))
12420 `(((name .
"Commands")
12422 (anything-c-apropos-init 'commandp
,default
)))
12423 (persistent-action . anything-lisp-completion-persistent-action
)
12424 (persistent-help .
"Show brief doc in mode-line")
12425 (candidates-in-buffer)
12426 (action .
(lambda (candidate)
12427 (describe-function (intern candidate
)))))
12428 ((name .
"Functions")
12430 (anything-c-apropos-init #'(lambda (x) (and (fboundp x
)
12431 (not (commandp x
))))
12433 (persistent-action . anything-lisp-completion-persistent-action
)
12434 (persistent-help .
"Show brief doc in mode-line")
12435 (candidates-in-buffer)
12436 (action .
(lambda (candidate)
12437 (describe-function (intern candidate
)))))
12438 ((name .
"Variables")
12440 (anything-c-apropos-init 'boundp
,default
)))
12441 (persistent-action . anything-lisp-completion-persistent-action
)
12442 (persistent-help .
"Show brief doc in mode-line")
12443 (candidates-in-buffer)
12444 (action .
(lambda (candidate)
12445 (describe-variable (intern candidate
)))))
12448 (anything-c-apropos-init 'facep
,default
)))
12449 (persistent-action . anything-lisp-completion-persistent-action
)
12450 (persistent-help .
"Show brief doc in mode-line")
12451 (candidates-in-buffer)
12452 (filtered-candidate-transformer .
(lambda (candidates source
)
12453 (loop for c in candidates
12454 collect
(propertize c
'face
(intern c
)))))
12455 (action .
(lambda (candidate)
12456 (describe-face (intern candidate
)))))
12457 ((name .
"Anything attributes")
12458 (candidates .
(lambda ()
12459 (mapcar 'symbol-name anything-additional-attributes
)))
12460 (action .
(lambda (candidate)
12461 (with-output-to-temp-buffer "*Help*"
12462 (princ (get (intern candidate
) 'anything-attrdoc
))))))))))
12465 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
12468 (provide 'anything-config
)
12470 ;;; Local Variables:
12471 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
12474 ;; How to save (DO NOT REMOVE!!)
12475 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
12476 ;;; anything-config.el ends here
12478 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
12479 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
12480 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
12481 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
12482 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
12483 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
12484 ;;; LocalWords: dotimes Thierry online vname
12485 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
12486 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
12487 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
12488 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
12489 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
12490 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
12491 ;;; LocalWords: startpos noselect dont desc