1 ;;; anything-config.el --- Predefined configurations for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Predefined configurations for `anything.el'
6 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
7 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
8 ;; rubikitch <rubikitch@ruby-lang.org>
9 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
10 ;; Copyright (C) 2007 ~ 2011, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009 ~ 2011, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009 ~ 2011, Thierry Volpiatto, all rights reserved.
14 ;; Created: 2009-02-16 21:38:23
16 ;; X-URL: http://repo.or.cz/w/anything-config.git
17 ;; Keywords: anything, anything-config
18 ;; Compatibility: GNU Emacs 22 ~ 24
20 ;; Features that might be required by this library:
25 ;;; This file is NOT part of GNU Emacs
29 ;; This program is free software; you can redistribute it and/or modify
30 ;; it under the terms of the GNU General Public License as published by
31 ;; the Free Software Foundation; either version 3, or (at your option)
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;; GNU General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING. If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
51 ;; Predefined configurations for `anything.el'
53 ;; For quick start, try `anything-for-files' to open files.
55 ;; To configure anything you should define anything command
56 ;; with your favorite sources, like below:
58 ;; (defun my-anything ()
60 ;; (anything-other-buffer
61 ;; '(anything-c-source-buffers
62 ;; anything-c-source-file-name-history
63 ;; anything-c-source-info-pages
64 ;; anything-c-source-info-elisp
65 ;; anything-c-source-man-pages
66 ;; anything-c-source-locate
67 ;; anything-c-source-emacs-commands)
70 ;; Then type M-x my-anything to use sources.
72 ;; Defining own command is better than setup `anything-sources'
73 ;; directly, because you can define multiple anything commands with
74 ;; different sources. Each anything command should have own anything
75 ;; buffer, because M-x anything-resume revives anything command.
77 ;;; Autodoc documentation:
78 ;; ---------------------
80 ;; * Commands defined here are:
81 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
82 ;; `anything-configuration'
83 ;; Customize `anything'.
85 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
86 ;; `anything-for-files'
87 ;; Preconfigured `anything' for opening files.
89 ;; Preconfigured `anything' for `recentf'.
90 ;; `anything-info-at-point'
91 ;; Preconfigured `anything' for searching info at point.
92 ;; `anything-info-emacs'
93 ;; Preconfigured anything for Emacs manual index.
94 ;; `anything-show-kill-ring'
95 ;; Preconfigured `anything' for `kill-ring'.
96 ;; `anything-minibuffer-history'
97 ;; Preconfigured `anything' for `minibuffer-history'.
99 ;; Preconfigured `anything' for gentoo linux.
101 ;; Preconfigured `anything' for `imenu'.
102 ;; `anything-google-suggest'
103 ;; Preconfigured `anything' for google search with google suggest.
104 ;; `anything-yahoo-suggest'
105 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
106 ;; `anything-for-buffers'
107 ;; Preconfigured `anything' for buffer.
108 ;; `anything-buffers-list'
109 ;; Enhanced preconfigured `anything' for buffer.
111 ;; Preconfigured `anything' for BBDB.
113 ;; Preconfigured `anything' for Locate.
114 ;; `anything-w3m-bookmarks'
115 ;; Preconfigured `anything' for w3m bookmark.
116 ;; `anything-firefox-bookmarks'
117 ;; Preconfigured `anything' for firefox bookmark.
119 ;; Preconfigured `anything' for color.
120 ;; `anything-bookmarks'
121 ;; Preconfigured `anything' for bookmarks.
122 ;; `anything-c-pp-bookmarks'
123 ;; Preconfigured `anything' for bookmarks (pretty-printed).
124 ;; `anything-c-insert-latex-math'
125 ;; Preconfigured anything for latex math symbols completion.
126 ;; `anything-register'
127 ;; Preconfigured `anything' for Emacs registers.
128 ;; `anything-man-woman'
129 ;; Preconfigured `anything' for Man and Woman pages.
130 ;; `anything-org-keywords'
131 ;; Preconfigured `anything' for org keywords.
133 ;; Preconfigured `anything' for emms sources.
134 ;; `anything-eev-anchors'
135 ;; Preconfigured `anything' for eev anchors.
136 ;; `anything-bm-list'
137 ;; Preconfigured `anything' for visible bookmarks.
139 ;; Preconfigured `anything' for timers.
140 ;; `anything-list-emacs-process'
141 ;; Preconfigured `anything' for emacs process.
143 ;; Preconfigured Anything for Occur source.
144 ;; `anything-browse-code'
145 ;; Preconfigured anything to browse code.
146 ;; `anything-org-headlines'
147 ;; Preconfigured anything to show org headlines.
148 ;; `anything-info-gnus'
149 ;; Preconfigured anything to browse Gnus Manual.
151 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
152 ;; `anything-test-sources'
153 ;; List all anything sources for test.
154 ;; `anything-select-source'
156 ;; `anything-mark-all'
157 ;; Mark all visible unmarked candidates in current source.
158 ;; `anything-unmark-all'
159 ;; Unmark all candidates in all sources of current anything session.
160 ;; `anything-toggle-all-marks'
162 ;; `anything-c-buffer-help'
163 ;; Help command for anything buffers.
164 ;; `anything-buffer-diff-persistent'
165 ;; Toggle diff buffer without quitting anything.
166 ;; `anything-buffer-revert-persistent'
167 ;; Revert buffer without quitting anything.
168 ;; `anything-buffer-save-persistent'
169 ;; Save buffer without quitting anything.
170 ;; `anything-buffer-run-kill-buffers'
171 ;; Run kill buffer action from `anything-c-source-buffers-list'.
172 ;; `anything-buffer-run-grep'
173 ;; Run Grep action from `anything-c-source-buffers-list'.
174 ;; `anything-buffer-run-zgrep'
175 ;; Run Grep action from `anything-c-source-buffers-list'.
176 ;; `anything-buffer-run-query-replace-regexp'
177 ;; Run Query replace regexp action from `anything-c-source-buffers-list'.
178 ;; `anything-buffer-run-query-replace'
179 ;; Run Query replace action from `anything-c-source-buffers-list'.
180 ;; `anything-buffer-switch-other-window'
181 ;; Run switch to other window action from `anything-c-source-buffers-list'.
182 ;; `anything-buffer-switch-other-frame'
183 ;; Run switch to other frame action from `anything-c-source-buffers-list'.
184 ;; `anything-buffer-switch-to-elscreen'
185 ;; Run switch to elscreen action from `anything-c-source-buffers-list'.
186 ;; `anything-c-copy-files-async'
187 ;; Preconfigured anything to copy file list FLIST to DEST asynchronously.
188 ;; `anything-ff-help'
189 ;; Help command for `anything-find-files'.
190 ;; `anything-ff-run-toggle-auto-update'
192 ;; `anything-ff-run-switch-to-history'
193 ;; Run Switch to history action from `anything-c-source-find-files'.
194 ;; `anything-ff-run-grep'
195 ;; Run Grep action from `anything-c-source-find-files'.
196 ;; `anything-ff-run-pdfgrep'
197 ;; Run Pdfgrep action from `anything-c-source-find-files'.
198 ;; `anything-ff-run-zgrep'
199 ;; Run Grep action from `anything-c-source-find-files'.
200 ;; `anything-ff-run-copy-file'
201 ;; Run Copy file action from `anything-c-source-find-files'.
202 ;; `anything-ff-run-rename-file'
203 ;; Run Rename file action from `anything-c-source-find-files'.
204 ;; `anything-ff-run-byte-compile-file'
205 ;; Run Byte compile file action from `anything-c-source-find-files'.
206 ;; `anything-ff-run-load-file'
207 ;; Run Load file action from `anything-c-source-find-files'.
208 ;; `anything-ff-run-eshell-command-on-file'
209 ;; Run eshell command on file action from `anything-c-source-find-files'.
210 ;; `anything-ff-run-ediff-file'
211 ;; Run Ediff file action from `anything-c-source-find-files'.
212 ;; `anything-ff-run-ediff-merge-file'
213 ;; Run Ediff merge file action from `anything-c-source-find-files'.
214 ;; `anything-ff-run-symlink-file'
215 ;; Run Symlink file action from `anything-c-source-find-files'.
216 ;; `anything-ff-run-delete-file'
217 ;; Run Delete file action from `anything-c-source-find-files'.
218 ;; `anything-ff-run-complete-fn-at-point'
219 ;; Run complete file name action from `anything-c-source-find-files'.
220 ;; `anything-ff-run-switch-to-eshell'
221 ;; Run switch to eshell action from `anything-c-source-find-files'.
222 ;; `anything-ff-run-switch-other-window'
223 ;; Run switch to other window action from `anything-c-source-find-files'.
224 ;; `anything-ff-run-switch-other-frame'
225 ;; Run switch to other frame action from `anything-c-source-find-files'.
226 ;; `anything-ff-run-open-file-externally'
227 ;; Run open file externally command action from `anything-c-source-find-files'.
228 ;; `anything-ff-run-gnus-attach-files'
229 ;; Run gnus attach files command action from `anything-c-source-find-files'.
230 ;; `anything-ff-run-etags'
231 ;; Run Etags command action from `anything-c-source-find-files'.
232 ;; `anything-ff-run-print-file'
233 ;; Run Print file action from `anything-c-source-find-files'.
234 ;; `anything-find-files-down-one-level'
235 ;; Go down one level like unix command `cd ..'.
236 ;; `anything-ff-properties-persistent'
237 ;; Show properties without quitting anything.
238 ;; `anything-ff-run-kill-buffer-persistent'
239 ;; Execute `anything-ff-kill-buffer-fname' whitout quitting.
240 ;; `anything-ff-rotate-left-persistent'
241 ;; Rotate image left without quitting anything.
242 ;; `anything-ff-rotate-right-persistent'
243 ;; Rotate image right without quitting anything.
244 ;; `anything-find-files'
245 ;; Preconfigured `anything' for anything implementation of `find-file'.
246 ;; `anything-write-file'
247 ;; Preconfigured `anything' providing completion for `write-file'.
248 ;; `anything-insert-file'
249 ;; Preconfigured `anything' providing completion for `insert-file'.
250 ;; `anything-dired-rename-file'
251 ;; Preconfigured `anything' to rename files from dired.
252 ;; `anything-dired-copy-file'
253 ;; Preconfigured `anything' to copy files from dired.
254 ;; `anything-dired-symlink-file'
255 ;; Preconfigured `anything' to symlink files from dired.
256 ;; `anything-dired-hardlink-file'
257 ;; Preconfigured `anything' to hardlink files from dired.
258 ;; `anything-generic-file-help'
260 ;; `anything-do-grep'
261 ;; Preconfigured anything for grep.
262 ;; `anything-c-goto-precedent-file'
263 ;; Go to precedent file in anything grep/etags buffers.
264 ;; `anything-c-goto-next-file'
265 ;; Go to precedent file in anything grep/etags buffers.
266 ;; `anything-grep-help'
268 ;; `anything-c-grep-run-persistent-action'
269 ;; Run grep persistent action from `anything-do-grep-1'.
270 ;; `anything-c-grep-run-default-action'
271 ;; Run grep default action from `anything-do-grep-1'.
272 ;; `anything-c-grep-run-other-window-action'
273 ;; Run grep goto other window action from `anything-do-grep-1'.
274 ;; `anything-c-grep-run-save-buffer'
275 ;; Run grep save results action from `anything-do-grep-1'.
276 ;; `anything-pdfgrep-help'
278 ;; `anything-do-pdfgrep'
280 ;; `anything-yank-text-at-point'
281 ;; Yank text at point in minibuffer.
282 ;; `anything-etags-help'
283 ;; The help function for etags.
284 ;; `anything-c-etags-select'
285 ;; Preconfigured anything for etags.
286 ;; `anything-filelist'
287 ;; Preconfigured `anything' to open files instantly.
288 ;; `anything-filelist+'
289 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
290 ;; `anything-c-describe-attributes'
291 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
293 ;; Preconfigured `anything' for Emacs commands.
294 ;; `anything-manage-advice'
295 ;; Preconfigured `anything' to disable/enable function advices.
296 ;; `anything-bookmark-ext'
297 ;; Preconfigured `anything' for bookmark-extensions sources.
298 ;; `anything-simple-call-tree'
299 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
300 ;; `anything-mark-ring'
301 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
302 ;; `anything-global-mark-ring'
303 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
304 ;; `anything-all-mark-rings'
305 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
306 ;; `anything-yaoddmuse-cache-pages'
307 ;; Fetch the list of files on emacswiki and create cache file.
308 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
309 ;; Preconfigured `anything' to edit or view EmacsWiki page.
310 ;; `anything-yaoddmuse-emacswiki-post-library'
311 ;; Preconfigured `anything' to post library to EmacsWiki.
312 ;; `anything-eval-expression'
313 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
314 ;; `anything-eval-new-line-and-indent'
316 ;; `anything-eval-expression-with-eldoc'
317 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
318 ;; `anything-calcul-expression'
319 ;; Preconfigured anything for `anything-c-source-calculation-result'.
320 ;; `anything-surfraw'
321 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
322 ;; `anything-call-source'
323 ;; Preconfigured `anything' to call anything source.
324 ;; `anything-call-source-from-anything'
325 ;; Call anything source within `anything' session.
326 ;; `anything-execute-anything-command'
327 ;; Preconfigured `anything' to execute preconfigured `anything'.
328 ;; `anything-create-from-anything'
329 ;; Run `anything-create' from `anything' as a fallback.
331 ;; Preconfigured `anything' to do many create actions from STRING.
333 ;; Preconfigured `anything' for top command.
334 ;; `anything-select-xfont'
335 ;; Preconfigured `anything' to select Xfont.
336 ;; `anything-world-time'
337 ;; Preconfigured `anything' to show world time.
339 ;; Preconfigured `anything' : frontend of APT package manager.
340 ;; `anything-esh-pcomplete'
341 ;; Preconfigured anything to provide anything completion in eshell.
342 ;; `anything-eshell-history'
343 ;; Preconfigured anything for eshell history.
344 ;; `anything-lisp-completion-at-point'
345 ;; Anything lisp symbol completion at point.
346 ;; `anything-lisp-completion-at-point-or-indent'
347 ;; First call indent and second call complete lisp symbol.
348 ;; `anything-c-complete-file-name-at-point'
349 ;; Complete file name at point.
350 ;; `anything-c-run-external-command'
351 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
352 ;; `anything-ratpoison-commands'
353 ;; Preconfigured `anything' to execute ratpoison commands.
354 ;; `anything-c-set-variable'
355 ;; Set value to VAR interactively.
356 ;; `anything-c-adaptive-save-history'
357 ;; Save history information to file given by `anything-c-adaptive-history-file'.
358 ;; `anything-c-reset-adaptative-history'
359 ;; Delete all `anything-c-adaptive-history' and his file.
360 ;; `anything-c-toggle-match-plugin'
361 ;; Toggle anything-match-plugin.
363 ;; * User variables defined here:
364 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
365 ;; `anything-c-use-standard-keys'
366 ;; Default Value: nil
367 ;; `anything-c-adaptive-history-file'
368 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
369 ;; `anything-c-adaptive-history-length'
371 ;; `anything-c-google-suggest-url'
372 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
373 ;; `anything-c-google-suggest-search-url'
374 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
375 ;; `anything-google-suggest-use-curl-p'
376 ;; Default Value: nil
377 ;; `anything-c-yahoo-suggest-url'
378 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
379 ;; `anything-c-yahoo-suggest-search-url'
380 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
381 ;; `anything-c-boring-buffer-regexp'
382 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
383 ;; `anything-c-boring-file-regexp'
384 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
385 ;; `anything-kill-ring-threshold'
387 ;; `anything-su-or-sudo'
388 ;; Default Value: "su"
389 ;; `anything-for-files-prefered-list'
390 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
391 ;; `anything-create--actions-private'
392 ;; Default Value: nil
393 ;; `anything-allow-skipping-current-buffer'
395 ;; `anything-c-enable-eval-defun-hack'
397 ;; `anything-tramp-verbose'
399 ;; `anything-raise-command'
400 ;; Default Value: nil
401 ;; `anything-command-map-prefix-key'
402 ;; Default Value: "<f5> a"
403 ;; `anything-c-find-files-show-icons'
404 ;; Default Value: nil
405 ;; `anything-c-find-files-icons-directory'
406 ;; Default Value: "/usr/local/share/emacs/24.0.50/etc/images/tree-widget/default"
407 ;; `anything-c-browse-code-regexp-lisp'
408 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
409 ;; `anything-c-browse-code-regexp-python'
410 ;; Default Value: "\\<def\\>\\|\\<class\\>"
411 ;; `anything-c-browse-code-regexp-alist'
412 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
413 ;; `anything-c-external-programs-associations'
414 ;; Default Value: nil
415 ;; `anything-ff-auto-update-initial-value'
417 ;; `anything-c-copy-async-prefered-emacs'
418 ;; Default Value: "emacs"
419 ;; `anything-ff-lynx-style-map'
421 ;; `anything-ff-history-max-length'
422 ;; Default Value: 100
423 ;; `anything-ff-smart-completion'
425 ;; `anything-ff-default-kbsize'
426 ;; Default Value: 1024.0
427 ;; `anything-ff-tramp-not-fancy'
429 ;; `anything-ff-exif-data-program'
430 ;; Default Value: "exiftran"
431 ;; `anything-ff-exif-data-program-args'
432 ;; Default Value: "-d"
433 ;; `anything-c-grep-use-ioccur-style-keys'
435 ;; `anything-c-pdfgrep-default-read-command'
436 ;; Default Value: "xpdf '%f' %p"
437 ;; `anything-c-etags-tag-file-name'
438 ;; Default Value: "TAGS"
439 ;; `anything-c-etags-tag-file-search-limit'
441 ;; `anything-c-filelist-file-name'
442 ;; Default Value: nil
443 ;; `anything-c-eldoc-in-minibuffer-show-fn'
444 ;; Default Value: anything-c-eldoc-show-in-mode-line
445 ;; `anything-c-turn-on-show-completion'
447 ;; `anything-lisp-completion-or-indent-delay'
448 ;; Default Value: 0.6
449 ;; `anything-c-default-external-file-browser'
450 ;; Default Value: "nautilus"
451 ;; `anything-c-use-adaptative-sorting'
452 ;; Default Value: nil
453 ;; `anything-ff-newfile-prompt-p'
456 ;; * Anything sources defined here:
457 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
458 ;; `anything-c-source-regexp' (Regexp Builder)
459 ;; `anything-c-source-buffers' (Buffers)
460 ;; `anything-c-source-buffer-not-found' (Create buffer)
461 ;; `anything-c-source-buffers-list' (Buffers)
462 ;; `anything-c-source-file-name-history' (File Name History)
463 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
464 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
465 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
466 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
467 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
468 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
469 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
470 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
471 ;; `anything-c-source-file-cache' (File Cache)
472 ;; `anything-c-source-locate' (Locate)
473 ;; `anything-c-source-etags-select' (Etags)
474 ;; `anything-c-source-recentf' (Recentf)
475 ;; `anything-c-source-ffap-guesser' (File at point)
476 ;; `anything-c-source-ffap-line' (File/Lineno at point)
477 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
478 ;; `anything-c-source-filelist' (FileList)
479 ;; `anything-c-source-info-pages' (Info Pages)
480 ;; `anything-c-source-info-elisp' (Info index: elisp)
481 ;; `anything-c-source-info-cl' (Info index: cl)
482 ;; `anything-c-source-info-org' (Info index: org)
483 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
484 ;; `anything-c-source-info-zsh' (Info index: zsh)
485 ;; `anything-c-source-info-bash' (Info index: bash)
486 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
487 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
488 ;; `anything-c-source-info-find' (Info index: find)
489 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
490 ;; `anything-c-source-info-textutils' (Info index: textutils)
491 ;; `anything-c-source-info-libc' (Info index: libc)
492 ;; `anything-c-source-info-make' (Info index: make)
493 ;; `anything-c-source-info-automake' (Info index: automake)
494 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
495 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
496 ;; `anything-c-source-info-emacs' (Info index: emacs)
497 ;; `anything-c-source-info-elib' (Info index: elib)
498 ;; `anything-c-source-info-eieio' (Info index: eieio)
499 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
500 ;; `anything-c-source-info-guile' (Info index: guile)
501 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
502 ;; `anything-c-source-info-goops' (Info index: goops)
503 ;; `anything-c-source-info-screen' (Info index: screen)
504 ;; `anything-c-source-info-latex' (Info index: latex)
505 ;; `anything-c-source-info-gawk' (Info index: gawk)
506 ;; `anything-c-source-info-sed' (Info index: sed)
507 ;; `anything-c-source-info-m4' (Info index: m4)
508 ;; `anything-c-source-info-wget' (Info index: wget)
509 ;; `anything-c-source-info-binutils' (Info index: binutils)
510 ;; `anything-c-source-info-as' (Info index: as)
511 ;; `anything-c-source-info-bfd' (Info index: bfd)
512 ;; `anything-c-source-info-gprof' (Info index: gprof)
513 ;; `anything-c-source-info-ld' (Info index: ld)
514 ;; `anything-c-source-info-diff' (Info index: diff)
515 ;; `anything-c-source-info-flex' (Info index: flex)
516 ;; `anything-c-source-info-grep' (Info index: grep)
517 ;; `anything-c-source-info-gzip' (Info index: gzip)
518 ;; `anything-c-source-info-libtool' (Info index: libtool)
519 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
520 ;; `anything-c-source-info-info' (Info index: info)
521 ;; `anything-c-source-info-gdb' (Info index: gdb)
522 ;; `anything-c-source-info-stabs' (Info index: stabs)
523 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
524 ;; `anything-c-source-info-cvs' (Info index: cvs)
525 ;; `anything-c-source-info-bison' (Info index: bison)
526 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
527 ;; `anything-c-source-info-global' (Info index: global)
528 ;; `anything-c-source-man-pages' (Manual Pages)
529 ;; `anything-c-source-complex-command-history' (Complex Command History)
530 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
531 ;; `anything-c-source-emacs-commands' (Emacs Commands)
532 ;; `anything-c-source-lacarte' (Lacarte)
533 ;; `anything-c-source-emacs-functions' (Emacs Functions)
534 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
535 ;; `anything-c-source-advice' (Function Advice)
536 ;; `anything-c-source-emacs-variables' (Emacs Variables)
537 ;; `anything-c-source-bookmarks' (Bookmarks)
538 ;; `anything-c-source-bookmark-set' (Set Bookmark)
539 ;; `anything-c-source-bm' (Visible Bookmarks)
540 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
541 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
542 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
543 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
544 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
545 ;; `anything-c-source-bookmark-images' (Bookmark Images)
546 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
547 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
548 ;; `anything-c-source-bookmark-info' (Bookmark Info)
549 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
550 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
551 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
552 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
553 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
554 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
555 ;; `anything-c-source-imenu' (Imenu)
556 ;; `anything-c-source-ctags' (Exuberant ctags)
557 ;; `anything-c-source-semantic' (Semantic Tags)
558 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
559 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
560 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
561 ;; `anything-c-source-customize-face' (Customize Face)
562 ;; `anything-c-source-colors' (Colors)
563 ;; `anything-c-source-tracker-search' (Tracker Search)
564 ;; `anything-c-source-mac-spotlight' (mdfind)
565 ;; `anything-c-source-kill-ring' (Kill Ring)
566 ;; `anything-c-source-mark-ring' (mark-ring)
567 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
568 ;; `anything-c-source-register' (Registers)
569 ;; `anything-c-source-latex-math' (Latex Math Menu)
570 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
571 ;; `anything-c-source-rd-headline' (RD HeadLine)
572 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
573 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
574 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
575 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
576 ;; `anything-c-source-org-headline' (Org HeadLine)
577 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
578 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
579 ;; `anything-c-source-eev-anchor' (Anchors)
580 ;; `anything-c-source-org-keywords' (Org Keywords)
581 ;; `anything-c-source-picklist' (Picklist)
582 ;; `anything-c-source-bbdb' (BBDB)
583 ;; `anything-c-source-evaluation-result' (Evaluation Result)
584 ;; `anything-c-source-calculation-result' (Calculation Result)
585 ;; `anything-c-source-google-suggest' (Google Suggest)
586 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
587 ;; `anything-c-source-emms-streams' (Emms Streams)
588 ;; `anything-c-source-emms-dired' (Music Directory)
589 ;; `anything-c-source-emms-files' (Emms files)
590 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
591 ;; `anything-c-source-call-source' (Call anything source)
592 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
593 ;; `anything-c-source-occur' (Occur)
594 ;; `anything-c-source-browse-code' (Browse code)
595 ;; `anything-c-source-create' (Create)
596 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
597 ;; `anything-c-source-elscreen' (Elscreen)
598 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
599 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
600 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
601 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
602 ;; `anything-c-source-xfonts' (X Fonts)
603 ;; `anything-c-source-time-world' (Time World List)
604 ;; `anything-c-source-apt' (APT)
605 ;; `anything-c-source-gentoo' (Portage sources)
606 ;; `anything-c-source-use-flags' (Use Flags)
607 ;; `anything-c-source-emacs-process' (Emacs Process)
608 ;; `anything-c-source-esh' (Eshell completions)
609 ;; `anything-c-source-eshell-history' (Eshell history)
610 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
612 ;; *** END auto-documentation
617 ;; Change log of this file is found at
618 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
620 ;; Change log of this project is found at
621 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
626 ;; Tassilo Horn <tassilo@member.fsf.org>
627 ;; Vagn Johansen <gonz808@hotmail.com>
628 ;; Mathias Dahl <mathias.dahl@gmail.com>
629 ;; Bill Clementson <billclem@gmail.com>
630 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
631 ;; Drew Adams <drew.adams@oracle.com>
632 ;; Jason McBrayer <jmcbray@carcosa.net>
633 ;; Andy Stewart <lazycat.manatee@gmail.com>
634 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
635 ;; rubikitch <rubikitch@ruby-lang.org>
636 ;; Scott Vokes <vokes.s@gmail.com>
637 ;; Kenichirou Oyama <k1lowxb@gmail.com>
641 ;; Evaluate (autodoc-update-all) before commit. This function
642 ;; generates anything-c-source-* / functions / options list.
644 ;; Install also developer-tools/autodoc.el
645 ;; And eval it or run interactively.
647 ;; [EVAL IT] (autodoc-update-all)
649 ;; Please write details documentation about function, then others will
650 ;; read code more easier. -- Andy Stewart
656 ;; - Fix documentation, now many functions haven't documentations.
675 (eval-when-compile (require 'org
)) ; Shut up byte compiler about org-directory.
676 (eval-when-compile (require 'semantic nil t
))
677 (require 'anything-match-plugin
)
681 ;;; Declare external functions
684 (declare-function gnus-dired-attach
"ext:gnus-dired.el" (files-to-attach))
685 (declare-function image-dired-display-image
"image-dired.el" (file &optional original-size
))
686 (declare-function image-dired-update-property
"image-dired.el" (prop value
))
687 (declare-function woman-file-name-all-completions
"woman.el" (topic))
688 (declare-function Man-getpage-in-background
"man.el" (topic))
689 (declare-function simple-call-tree-analyze
"ext:simple-call-tree.el" (&optional test
))
690 (declare-function yaoddmuse-update-pagename
"ext:yaoddmuse.el" (&optional unforced
))
691 (declare-function yaoddmuse-get-library-list
"ext:yaoddmuse.el" (&optional dirs string
))
692 (declare-function org-get-current-options
"ext:org-exp.el")
693 (declare-function emms-streams
"ext:emms-streams")
694 (declare-function emms-stream-delete-bookmark
"ext:emms-streams")
695 (declare-function emms-stream-add-bookmark
"ext:emms-streams" (name url fd type
))
696 (declare-function emms-stream-save-bookmarks-file
"ext:emms-streams")
697 (declare-function emms-stream-quit
"ext:emms-streams")
698 (declare-function with-current-emms-playlist
"ext:emms" (&rest body
))
699 (declare-function emms-playlist-tracks-in-region
"ext:emms" (beg end
))
700 (declare-function emms-playlist-first
"ext:emms")
701 (declare-function emms-playlist-mode-play-smart
"ext:emms-playlist-mode")
702 (declare-function term-line-mode
"term")
703 (declare-function term-char-mode
"term")
704 (declare-function term-send-input
"term")
705 (declare-function term-send-eof
"term")
706 (declare-function Info-index-nodes
"info" (&optional file
))
707 (declare-function Info-goto-node
"info" (&optional fork
))
708 (declare-function elscreen-find-screen-by-buffer
"ext:elscreen.el" (buffer &optional create
))
709 (declare-function elscreen-find-file
"ext:elscreen.el" (filename))
710 (declare-function elscreen-goto
"ext:elscreen.el" (screen))
711 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
712 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
713 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
714 (declare-function semantic-tag-type
"ext:tag-file.el" (tag) t
)
715 (declare-function semantic-tag-class
"ext:tag-file.el" (tag) t
)
716 (declare-function bbdb
"ext:bbdb-com")
717 (declare-function bbdb-current-record
"ext:bbdb-com")
718 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
719 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
720 (declare-function bbdb-current-record
"ext:bbdb-com")
721 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
722 (declare-function bbdb-records
"ext:bbdb-com"
723 (&optional dont-check-disk already-in-db-buffer
))
724 (declare-function eshell-read-aliases-list
"em-alias")
725 (declare-function eshell-send-input
"esh-mode" (&optional use-region queue-p no-newline
))
726 (declare-function eldoc-current-symbol
"eldoc")
727 (declare-function eldoc-get-fnsym-args-string
"eldoc" (sym &optional index
))
728 (declare-function eldoc-get-var-docstring
"eldoc" (sym))
729 (declare-function eldoc-fnsym-in-current-sexp
"eldoc")
730 (declare-function find-library-name
"find-func.el" (library))
731 (declare-function adoc-construct
"ext:auto-document.el" (buf))
732 (declare-function adoc-first-line
"ext:auto-document.el" (str))
733 (declare-function adoc-prin1-to-string
"ext:auto-document.el" (object))
740 (unless (fboundp 'window-system
)
741 (defun window-system (&optional arg
)
749 (defgroup anything-config nil
750 "Predefined configurations for `anything.el'."
753 (defcustom anything-c-adaptive-history-file
754 "~/.emacs.d/anything-c-adaptive-history"
755 "Path of file where history information is stored."
757 :group
'anything-config
)
759 (defcustom anything-c-adaptive-history-length
50
760 "Maximum number of candidates stored for a source."
762 :group
'anything-config
)
764 (defcustom anything-c-google-suggest-url
765 "http://google.com/complete/search?output=toolbar&q="
766 "URL used for looking up Google suggestions."
768 :group
'anything-config
)
770 (defcustom anything-c-google-suggest-search-url
771 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
772 "URL used for Google searching."
774 :group
'anything-config
)
776 (defcustom anything-google-suggest-use-curl-p nil
777 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
778 Otherwise `url-retrieve-synchronously' is used."
780 :group
'anything-config
)
782 (defcustom anything-c-yahoo-suggest-url
783 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
784 "Url used for looking up Yahoo suggestions."
786 :group
'anything-config
)
788 (defcustom anything-c-yahoo-suggest-search-url
789 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
790 "Url used for Yahoo searching."
792 :group
'anything-config
)
794 (defcustom anything-c-boring-buffer-regexp
800 " *Echo Area" " *Minibuf"))
801 "The regexp that match boring buffers.
802 Buffer candidates matching this regular expression will be
803 filtered from the list of candidates if the
804 `anything-c-skip-boring-buffers' candidate transformer is used, or
805 they will be displayed with face `file-name-shadow' if
806 `anything-c-shadow-boring-buffers' is used."
808 :group
'anything-config
)
809 ;; (string-match anything-c-boring-buffer-regexp "buf")
810 ;; (string-match anything-c-boring-buffer-regexp " hidden")
811 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
813 (defcustom anything-c-boring-file-regexp
815 ;; Boring directories
816 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
818 (and line-start
".#")
819 (and (or ".class" ".la" ".o" "~") eol
)))
820 "The regexp that match boring files.
821 File candidates matching this regular expression will be
822 filtered from the list of candidates if the
823 `anything-c-skip-boring-files' candidate transformer is used, or
824 they will be displayed with face `file-name-shadow' if
825 `anything-c-shadow-boring-files' is used."
827 :group
'anything-config
)
829 (defcustom anything-kill-ring-threshold
10
830 "*Minimum length to be listed by `anything-c-source-kill-ring'."
832 :group
'anything-config
)
834 (defcustom anything-c-kill-ring-max-lines-number nil
835 "Max number of lines displayed per candidate in kill-ring browser.
836 If nil or zero, don't truncate candidate, show all."
838 :group
'anything-config
)
840 (defcustom anything-su-or-sudo
"su"
841 "What command to use for root access."
843 :group
'anything-config
)
845 (defcustom anything-for-files-prefered-list
846 '(anything-c-source-ffap-line
847 anything-c-source-ffap-guesser
848 anything-c-source-buffers-list
849 anything-c-source-recentf
850 anything-c-source-bookmarks
851 anything-c-source-file-cache
852 anything-c-source-files-in-current-dir
+
853 anything-c-source-locate
)
854 "Your prefered sources to find files."
856 :group
'anything-config
)
858 (defcustom anything-create--actions-private nil
859 "User defined actions for `anything-create' / `anything-c-source-create'.
860 It is a list of (DISPLAY . FUNCTION) pairs like `action'
861 attribute of `anything-sources'.
863 It is prepended to predefined pairs."
865 :group
'anything-config
)
867 (defcustom anything-allow-skipping-current-buffer t
868 "Show current buffer or not in anything buffer"
870 :group
'anything-config
)
872 (defcustom anything-c-enable-eval-defun-hack t
873 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
874 This hack is invoked when pressing C-M-x in the form \
875 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
877 :group
'anything-config
)
879 (defcustom anything-tramp-verbose
0
880 "*Just like `tramp-verbose' but specific to anything.
881 When set to 0 don't show tramp messages in anything.
882 If you want to have the default tramp messages set it to 3."
884 :group
'anything-config
)
886 (defcustom anything-raise-command nil
887 "*A shell command to jump to a window running specific program.
888 Need external program wmctrl.
889 This will be use with `format', so use something like \"wmctrl -xa %s\"."
891 :group
'anything-config
)
893 (defun anything-set-anything-command-map-prefix-key (var key
)
894 (declare (special anything-command-map-prefix-key
))
895 (when (boundp 'anything-command-map-prefix-key
)
896 (global-unset-key (read-kbd-macro anything-command-map-prefix-key
)))
897 (setq anything-command-map-prefix-key key
)
898 (global-set-key (read-kbd-macro anything-command-map-prefix-key
)
899 'anything-command-map
))
901 (defcustom anything-command-map-prefix-key
"<f5> a"
902 "*The prefix key for all `anything-command-map' commands.
905 This default value is very likely to be changed,
906 because it is under discussion."
908 :set
'anything-set-anything-command-map-prefix-key
909 :group
'anything-config
)
911 (defcustom anything-c-browse-code-regexp-lisp
912 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
913 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
914 "*Regexp used to parse lisp buffer when browsing code."
916 :group
'anything-config
)
918 (defcustom anything-c-browse-code-regexp-python
919 "\\<def\\>\\|\\<class\\>"
920 "*Regexp used to parse python buffer when browsing code."
922 :group
'anything-config
)
924 (defcustom anything-c-browse-code-regexp-alist
925 `((lisp-interaction-mode .
,anything-c-browse-code-regexp-lisp
)
926 (emacs-lisp-mode .
,anything-c-browse-code-regexp-lisp
)
927 (lisp-mode .
,anything-c-browse-code-regexp-lisp
)
928 (python-mode .
,anything-c-browse-code-regexp-python
))
929 "*Alist to store regexps for browsing code corresponding \
930 to a specific `major-mode'."
932 :group
'anything-config
)
934 (defcustom anything-c-external-programs-associations nil
935 "*Alist to store externals programs associated with file extension.
936 This variable overhide setting in .mailcap file.
937 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
939 :group
'anything-config
)
941 (defcustom anything-ff-auto-update-initial-value t
942 "Auto update when only one candidate directory is matched.
943 This is the default value when starting `anything-find-files'."
944 :group
'anything-config
947 (defcustom anything-c-copy-async-prefered-emacs
"emacs"
948 "Path to the emacs you want to use for copying async.
949 Emacs versions < 24 fail to copy directory due to a bug not fixed
950 in `copy-directory'."
951 :group
'anything-config
954 (defcustom anything-ff-lynx-style-map t
955 "Use arrow keys to navigate with `anything-find-files'."
956 :group
'anything-config
959 (defcustom anything-ff-history-max-length
100
960 "*Number of elements shown in `anything-find-files' history."
961 :group
'anything-config
964 (defcustom anything-ff-smart-completion t
965 "Try to complete filenames smarter when non--nil.
966 See `anything-ff-transform-fname-for-completion' for more info."
967 :group
'anything-config
970 (defcustom anything-ff-default-kbsize
1024.0
971 "Default Kbsize to use for showing files size.
972 It is a float, usually 1024.0 but could be 1000.0 on some systems."
973 :group
'anything-config
976 (defcustom anything-ff-tramp-not-fancy t
977 "No colors when listing remote files when set to non--nil.
978 This make listing much faster, specially on slow machines."
979 :group
'anything-config
982 (defcustom anything-ff-exif-data-program
"exiftran"
983 "*Program used to extract exif data of an image file."
984 :group
'anything-config
987 (defcustom anything-ff-exif-data-program-args
"-d"
988 "*Arguments used for `anything-ff-exif-data-program'."
989 :group
'anything-config
992 (defcustom anything-c-grep-use-ioccur-style-keys t
993 "Use Arrow keys to jump to occurences."
994 :group
'anything-config
997 (defcustom anything-c-pdfgrep-default-read-command
"xpdf '%f' %p"
998 "Default command to read pdf files from pdfgrep.
999 Where '%f' format spec is filename and '%p' is page number"
1000 :group
'anything-config
1003 (defcustom anything-c-etags-tag-file-name
"TAGS"
1004 "Etags tag file name."
1006 :group
'anything-config
)
1008 (defcustom anything-c-etags-tag-file-search-limit
10
1009 "The limit level of directory to search tag file.
1010 Don't search tag file deeply if outside this value."
1012 :group
'anything-config
)
1014 (defcustom anything-c-etags-use-regexp-search nil
1015 "When non--nil search etags candidates by regexp.
1016 This disable anything-match-plugin when enabled.
1017 When nil search is performed literally and *match-plugin is used
1019 :group
'anything-config
1022 (defcustom anything-c-filelist-file-name nil
1023 "Filename of file list.
1024 Accept a list of string for multiple files.
1026 This file tend to be very large \(> 100MB\) and recommend to be in ramdisk for speed.
1027 File list is created by make-filelist.rb script.
1030 ruby make-filelist.rb > /tmp/all.filelist
1033 ;; Assume that /tmp is ramdisk or tmpfs
1034 \(setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\"\)
1035 \(setq anything-c-filelist-file-name \"/tmp/all.filelist\"\)
1038 :group
'anything-config
)
1040 (defcustom anything-c-eldoc-in-minibuffer-show-fn
1041 'anything-c-eldoc-show-in-mode-line
1042 "A function to display eldoc info.
1043 Should take one arg: the string to display."
1044 :group
'anything-config
1047 (defcustom anything-c-turn-on-show-completion t
1048 "Display candidate in buffer while moving selection when non--nil."
1049 :group
'anything-config
1052 (defcustom anything-lisp-completion-or-indent-delay
0.6
1053 "After this delay `anything-lisp-completion-counter' is reset to 0.
1054 This allow to indent again without completing lisp symbol after this delay.
1055 Default is 0.6 seconds."
1056 :group
'anything-config
1059 (defcustom anything-c-default-external-file-browser
"nautilus"
1060 "Default external file browser for your system.
1061 Directories will be opened externally with it.
1062 Set to nil if you do not have external file browser
1063 or do not want to use it."
1064 :group
'anything-config
1067 (defcustom anything-c-use-adaptative-sorting nil
1068 "*Wheter to use or not adaptative sorting.
1069 Even if a source use it, it will have no effect when set to nil."
1071 :group
'anything-config
)
1073 (defcustom anything-ff-newfile-prompt-p t
1074 "Whether Prompt or not when creating new file.
1075 This set `ffap-newfile-prompt'."
1077 :group
'anything-config
)
1080 (defcustom anything-ff-avfs-directory nil
1081 "*The default avfs directory, usually '.avfs'.
1082 When this is set you will be able to expand archive filenames with `C-z'
1083 inside an avfs directory mounted with mountavfs.
1084 See <http://sourceforge.net/projects/avf/>."
1086 :group
'anything-config
)
1088 (defcustom anything-ff-file-compressed-list
'("gz" "bz2" "zip" "7z")
1089 "*Minimal list of compressed files extension."
1091 :group
'anything-config
)
1093 (defcustom anything-locate-db-file-regexp
"m?locate\.db$"
1094 "Default regexp to match locate database.
1095 If nil Search in all files."
1097 :group
'anything-config
)
1099 (defcustom anything-c-eldoc-show-in-mode-line-delay
12
1100 "Eldoc will show info in mode-line during this delay if user is idle."
1102 :group
'anything-config
)
1104 (defcustom anything-c-copy-files-async-log-file
"/tmp/dired.log"
1105 "The file used to communicate with two emacs when copying files async."
1107 :group
'anything-config
)
1109 (defcustom anything-ff-printer-list nil
1110 "A list of available printers on your system.
1111 When non--nil let you choose a printer to print file.
1112 Otherwise when nil the variable `printer-name' will be used.
1113 On Unix based systems you can use `anything-ff-find-printers' to
1114 find a list of available printers."
1116 :group
'anything-config
)
1120 ;;; General internal variables
1123 (defvar anything-c-external-commands-list nil
1124 "A list of all external commands the user can execute. If this
1125 variable is not set by the user, it will be calculated
1132 (defface anything-buffer-saved-out
1133 '((t (:foreground
"red")))
1134 "*Face used for buffer files modified outside of emacs."
1135 :group
'anything-config
)
1137 (defface anything-buffer-not-saved
1138 '((t (:foreground
"Indianred2")))
1139 "*Face used for buffer files not already saved on disk."
1140 :group
'anything-config
)
1142 (defface anything-ff-prefix
1143 '((t (:background
"yellow" :foreground
"black")))
1144 "*Face used to prefix new file or url paths in `anything-find-files'."
1145 :group
'anything-config
)
1147 (defface anything-ff-executable
1148 '((t (:foreground
"green")))
1149 "*Face used for executable files in `anything-find-files'."
1150 :group
'anything-config
)
1152 (defface anything-ff-directory
1153 '((t (:foreground
"DarkRed" :background
"LightGray")))
1154 "*Face used for directories in `anything-find-files'."
1155 :group
'anything-config
)
1157 (defface anything-ff-symlink
1158 '((t (:foreground
"DarkOrange")))
1159 "*Face used for symlinks in `anything-find-files'."
1160 :group
'anything-config
)
1162 (defface anything-ff-invalid-symlink
1163 '((t (:foreground
"black" :background
"red")))
1164 "*Face used for invalid symlinks in `anything-find-files'."
1165 :group
'anything-config
)
1167 (defface anything-ff-file
1168 '((t (:foreground
"CadetBlue" :underline t
)))
1169 "*Face used for file names in `anything-find-files'."
1170 :group
'anything-config
)
1172 (defface anything-grep-match
1173 '((t (:inherit match
)))
1174 "Face used to highlight grep matches."
1175 :group
'anything-config
)
1177 (defface anything-grep-file
1178 '((t (:foreground
"BlueViolet" :underline t
)))
1179 "Face used to highlight grep results filenames."
1180 :group
'anything-config
)
1182 (defface anything-grep-lineno
1183 '((t (:foreground
"Darkorange1")))
1184 "Face used to highlight grep number lines."
1185 :group
'anything-config
)
1187 (defface anything-grep-running
1188 '((t (:foreground
"Red")))
1189 "Face used in mode line when grep is running."
1190 :group
'anything-config
)
1192 (defface anything-grep-finish
1193 '((t (:foreground
"Green")))
1194 "Face used in mode line when grep is finish."
1195 :group
'anything-config
)
1197 (defface anything-M-x-key-face
'((t (:foreground
"orange" :underline t
)))
1198 "*Face used in anything-M-x to show keybinding."
1201 (defface anything-bmkext-info
1202 '((t (:foreground
"green")))
1203 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1206 (defface anything-bmkext-w3m
1207 '((t (:foreground
"yellow")))
1208 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1211 (defface anything-bmkext-gnus
1212 '((t (:foreground
"magenta")))
1213 "*Face used for Gnus bookmarks."
1216 (defface anything-bmkext-man
1217 '((t (:foreground
"Orange4")))
1218 "*Face used for Woman/man bookmarks."
1221 (defface anything-bmkext-no--file
1222 '((t (:foreground
"grey")))
1223 "*Face used for non--file bookmarks."
1226 (defface anything-bmkext-file
1227 '((t (:foreground
"Deepskyblue2")))
1228 "*Face used for non--file bookmarks."
1231 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
1232 "Face for su/sudo bookmarks."
1235 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
1236 "Face for w3m bookmarks" :group
'anything
)
1238 (defface anything-emms-playlist
1239 '((t (:foreground
"Springgreen4" :underline t
)))
1240 "*Face used for tracks in current emms playlist."
1243 (defface anything-apt-installed
1244 '((t (:foreground
"green")))
1245 "*Face used for apt installed candidates."
1248 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
1249 "Face for anything-gentoo installed packages."
1250 :group
'traverse-faces
)
1252 (defface anything-lisp-show-completion
1253 '((t (:background
"DarkSlateGray")))
1254 "*Face used for showing candidates in `anything-lisp-completion'."
1255 :group
'anything-config
)
1257 (defface anything-lisp-completion-info
1258 '((t (:foreground
"red")))
1259 "*Face used for showing info in `anything-lisp-completion'."
1260 :group
'anything-config
)
1262 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
1263 "Face for source header in the anything buffer." :group
'anything
)
1266 (defun anything-configuration ()
1267 "Customize `anything'."
1269 (customize-group "anything-config"))
1273 ;;; Anything-command-map
1277 (defvar anything-command-map
)
1278 (define-prefix-command 'anything-command-map
)
1281 (define-key anything-command-map
(kbd "<SPC>") 'anything-execute-anything-command
)
1282 (define-key anything-command-map
(kbd "e") 'anything-c-etags-select
)
1283 (define-key anything-command-map
(kbd "l") 'anything-locate
)
1284 (define-key anything-command-map
(kbd "s") 'anything-surfraw
)
1285 (define-key anything-command-map
(kbd "r") 'anything-regexp
)
1286 (define-key anything-command-map
(kbd "w") 'anything-w3m-bookmarks
)
1287 (define-key anything-command-map
(kbd "x") 'anything-firefox-bookmarks
)
1288 (define-key anything-command-map
(kbd "#") 'anything-emms
)
1289 (define-key anything-command-map
(kbd "m") 'anything-man-woman
)
1290 (define-key anything-command-map
(kbd "t") 'anything-top
)
1291 (define-key anything-command-map
(kbd "i") 'anything-imenu
)
1292 (define-key anything-command-map
(kbd "<tab>") 'anything-lisp-completion-at-point
)
1293 (define-key anything-command-map
(kbd "p") 'anything-list-emacs-process
)
1294 (define-key anything-command-map
(kbd "C-x r b") 'anything-c-pp-bookmarks
)
1295 (define-key anything-command-map
(kbd "M-y") 'anything-show-kill-ring
)
1296 (define-key anything-command-map
(kbd "C-c <SPC>") 'anything-all-mark-rings
)
1297 (define-key anything-command-map
(kbd "C-x C-f") 'anything-find-files
)
1298 (define-key anything-command-map
(kbd "f") 'anything-for-files
)
1299 (define-key anything-command-map
(kbd "C-:") 'anything-eval-expression-with-eldoc
)
1300 (define-key anything-command-map
(kbd "C-,") 'anything-calcul-expression
)
1301 (define-key anything-command-map
(kbd "M-x") 'anything-M-x
)
1302 (define-key anything-command-map
(kbd "C-x C-w") 'anything-write-file
)
1303 (define-key anything-command-map
(kbd "C-x i") 'anything-insert-file
)
1304 (define-key anything-command-map
(kbd "M-s o") 'anything-occur
)
1305 (define-key anything-command-map
(kbd "M-g s") 'anything-do-grep
)
1306 (define-key anything-command-map
(kbd "c") 'anything-colors
)
1307 (define-key anything-command-map
(kbd "F") 'anything-select-xfont
)
1308 (define-key anything-command-map
(kbd "C-c f") 'anything-recentf
)
1309 (define-key anything-command-map
(kbd "C-c g") 'anything-google-suggest
)
1310 (define-key anything-command-map
(kbd "h i") 'anything-info-at-point
)
1311 (define-key anything-command-map
(kbd "h r") 'anything-info-emacs
)
1312 (define-key anything-command-map
(kbd "h g") 'anything-info-gnus
)
1313 (define-key anything-command-map
(kbd "C-x C-b") 'anything-buffers-list
)
1314 (define-key anything-command-map
(kbd "C-c C-b") 'anything-browse-code
)
1315 (define-key anything-command-map
(kbd "C-x r i") 'anything-register
)
1316 (define-key anything-command-map
(kbd "C-c C-x") 'anything-c-run-external-command
)
1318 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1319 ;; minibuffer-local-filename-must-match-map.
1320 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
1321 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
1322 (dolist (map (list minibuffer-local-filename-completion-map
1323 minibuffer-local-completion-map
1324 minibuffer-local-must-match-filename-map
1325 minibuffer-local-filename-must-match-map
1326 minibuffer-local-map
1327 minibuffer-local-isearch-map
1328 minibuffer-local-must-match-map
1329 minibuffer-local-ns-map
))
1330 (define-key map
"\C-r" 'anything-minibuffer-history
))
1337 (easy-menu-define nil global-map
1340 ["All anything commands" anything-execute-anything-command t
]
1341 ["Find any Files/Buffers" anything-for-files t
]
1344 ["Find files" anything-find-files t
]
1345 ["Recent Files" anything-recentf t
]
1346 ["Locate" anything-locate t
]
1347 ["Bookmarks" anything-c-pp-bookmarks t
])
1349 ["Find buffers" anything-buffers-list t
])
1351 ["Emacs Commands" anything-M-x t
]
1352 ["Externals Commands" anything-c-run-external-command t
])
1354 ["Info at point" anything-info-at-point t
]
1355 ["Emacs Manual index" anything-info-emacs t
]
1356 ["Gnus Manual index" anything-info-gnus t
])
1358 ["Org keywords" anything-org-keywords t
]
1359 ["Org headlines" anything-org-headlines t
])
1361 ["Occur" anything-occur t
]
1362 ["Grep" anything-do-grep t
]
1363 ["Etags" anything-c-etags-select t
]
1364 ["Lisp complete at point" anything-lisp-completion-at-point t
]
1365 ["Browse Kill ring" anything-show-kill-ring t
]
1366 ["Browse register" anything-register t
]
1367 ["Browse code" anything-browse-code t
]
1368 ["Mark Ring" anything-all-mark-rings t
]
1369 ["Regexp handler" anything-regexp t
]
1370 ["Colors & Faces" anything-colors t
]
1371 ["Show xfonts" anything-select-xfont t
]
1372 ["Ucs Symbols" anything-ucs t
]
1373 ["Imenu" anything-imenu t
]
1374 ["Google Suggest" anything-google-suggest t
]
1375 ["Eval expression" anything-eval-expression-with-eldoc t
]
1376 ["Calcul expression" anything-calcul-expression t
]
1377 ["Man pages" anything-man-woman t
]
1378 ["Top externals process" anything-top t
]
1379 ["Emacs internals process" anything-list-emacs-process t
])
1381 ["Prefered Options" anything-configuration t
]))
1385 ;;; Specialized keymaps
1388 (defvar anything-c-buffer-map
1389 (let ((map (copy-keymap anything-map
)))
1390 (define-key map
(kbd "C-c ?") 'anything-c-buffer-help
)
1391 ;; No need to have separate command for grep and zgrep
1392 ;; as we don't use recursivity for buffers.
1393 ;; So use zgrep for both as it is capable to handle non--compressed files.
1394 (define-key map
(kbd "M-g s") 'anything-buffer-run-zgrep
)
1395 (define-key map
(kbd "C-o") 'anything-buffer-switch-other-window
)
1396 (define-key map
(kbd "C-c C-o") 'anything-buffer-switch-other-frame
)
1397 (define-key map
(kbd "C-c =") 'anything-buffer-run-ediff
)
1398 (define-key map
(kbd "M-=") 'anything-buffer-run-ediff-merge
)
1399 (define-key map
(kbd "C-=") 'anything-buffer-diff-persistent
)
1400 (define-key map
(kbd "M-U") 'anything-buffer-revert-persistent
)
1401 (define-key map
(kbd "M-D") 'anything-buffer-run-kill-buffers
)
1402 (define-key map
(kbd "C-x C-s") 'anything-buffer-save-persistent
)
1403 (define-key map
(kbd "C-M-%") 'anything-buffer-run-query-replace-regexp
)
1404 (define-key map
(kbd "M-%") 'anything-buffer-run-query-replace
)
1405 (define-key map
(kbd "M-m") 'anything-toggle-all-marks
)
1406 (define-key map
(kbd "M-a") 'anything-mark-all
)
1407 (when (locate-library "elscreen")
1408 (define-key map
(kbd "<C-tab>") 'anything-buffer-switch-to-elscreen
))
1410 "Keymap for buffer sources in anything.")
1412 (defvar anything-find-files-map
1413 (let ((map (copy-keymap anything-map
)))
1414 (define-key map
(kbd "C-]") 'anything-ff-run-toggle-basename
)
1415 (define-key map
(kbd "C-x C-f") 'anything-ff-run-locate
)
1416 (define-key map
(kbd "M-g s") 'anything-ff-run-grep
)
1417 (define-key map
(kbd "M-g p") 'anything-ff-run-pdfgrep
)
1418 (define-key map
(kbd "M-g z") 'anything-ff-run-zgrep
)
1419 (define-key map
(kbd "M-.") 'anything-ff-run-etags
)
1420 (define-key map
(kbd "M-R") 'anything-ff-run-rename-file
)
1421 (define-key map
(kbd "M-C") 'anything-ff-run-copy-file
)
1422 (define-key map
(kbd "M-B") 'anything-ff-run-byte-compile-file
)
1423 (define-key map
(kbd "M-L") 'anything-ff-run-load-file
)
1424 (define-key map
(kbd "M-S") 'anything-ff-run-symlink-file
)
1425 (define-key map
(kbd "M-D") 'anything-ff-run-delete-file
)
1426 (define-key map
(kbd "M-K") 'anything-ff-run-kill-buffer-persistent
)
1427 (define-key map
(kbd "M-e") 'anything-ff-run-switch-to-eshell
)
1428 (define-key map
(kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point
)
1429 (define-key map
(kbd "C-o") 'anything-ff-run-switch-other-window
)
1430 (define-key map
(kbd "C-c C-o") 'anything-ff-run-switch-other-frame
)
1431 (define-key map
(kbd "C-c C-x") 'anything-ff-run-open-file-externally
)
1432 (define-key map
(kbd "M-!") 'anything-ff-run-eshell-command-on-file
)
1433 (define-key map
(kbd "C-=") 'anything-ff-run-ediff-file
)
1434 (define-key map
(kbd "C-c =") 'anything-ff-run-ediff-merge-file
)
1435 (define-key map
(kbd "M-p") 'anything-ff-run-switch-to-history
)
1436 (define-key map
(kbd "M-i") 'anything-ff-properties-persistent
)
1437 (define-key map
(kbd "C-c ?") 'anything-ff-help
)
1438 (define-key map
(kbd "C-}") 'anything-narrow-window
)
1439 (define-key map
(kbd "C-{") 'anything-enlarge-window
)
1440 (define-key map
(kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update
)
1441 (define-key map
(kbd "M-a") 'anything-mark-all
)
1442 (define-key map
(kbd "M-m") 'anything-toggle-all-marks
)
1443 (define-key map
(kbd "M-u") 'anything-unmark-all
)
1444 (define-key map
(kbd "C-c C-a") 'anything-ff-run-gnus-attach-files
)
1445 (define-key map
(kbd "C-c p") 'anything-ff-run-print-file
)
1446 ;; Next 2 have no effect if candidate is not an image file.
1447 (define-key map
(kbd "M-l") 'anything-ff-rotate-left-persistent
)
1448 (define-key map
(kbd "M-r") 'anything-ff-rotate-right-persistent
)
1449 (define-key map
(kbd "C-.") 'anything-find-files-down-one-level
)
1450 (define-key map
(kbd "C-l") 'anything-find-files-down-one-level
)
1451 (define-key map
(kbd "C-h C-b") 'anything-send-bug-report-from-anything
)
1452 (define-key map
(kbd "C-h C-d") 'anything-debug-output
)
1453 (when anything-ff-lynx-style-map
1454 (define-key map
(kbd "<left>") 'anything-find-files-down-one-level
)
1455 (define-key map
(kbd "<right>") 'anything-execute-persistent-action
))
1457 "Keymap for `anything-find-files'.")
1459 (defvar anything-c-read-file-map
1460 (let ((map (copy-keymap anything-map
)))
1461 (define-key map
(kbd "C-.") 'anything-find-files-down-one-level
)
1462 (define-key map
(kbd "C-l") 'anything-find-files-down-one-level
)
1463 (define-key map
(kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update
)
1464 (define-key map
(kbd "C-c ?") 'anything-read-file-name-help
)
1465 (when anything-ff-lynx-style-map
1466 (define-key map
(kbd "<left>") 'anything-find-files-down-one-level
)
1467 (define-key map
(kbd "<right>") 'anything-execute-persistent-action
)
1468 (define-key map
(kbd "<M-left>") 'anything-previous-source
)
1469 (define-key map
(kbd "<M-right>") 'anything-next-source
))
1471 "Keymap for `anything-c-read-file-name'.")
1473 (defvar anything-generic-files-map
1474 (let ((map (copy-keymap anything-map
)))
1475 (define-key map
(kbd "M-g s") 'anything-ff-run-grep
)
1476 (define-key map
(kbd "M-g z") 'anything-ff-run-zgrep
)
1477 (define-key map
(kbd "M-g p") 'anything-ff-run-pdfgrep
)
1478 (define-key map
(kbd "M-D") 'anything-ff-run-delete-file
)
1479 (define-key map
(kbd "C-o") 'anything-ff-run-switch-other-window
)
1480 (define-key map
(kbd "M-i") 'anything-ff-properties-persistent
)
1481 (define-key map
(kbd "C-c C-x") 'anything-ff-run-open-file-externally
)
1482 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1483 (define-key map
(kbd "C-c ?") 'anything-generic-file-help
)
1485 "Generic Keymap for files.")
1487 (defvar anything-c-grep-map
1488 (let ((map (copy-keymap anything-map
)))
1489 (define-key map
(kbd "M-<down>") 'anything-c-goto-next-file
)
1490 (define-key map
(kbd "M-<up>") 'anything-c-goto-precedent-file
)
1491 (define-key map
(kbd "C-o") 'anything-c-grep-run-other-window-action
)
1492 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1493 (define-key map
(kbd "C-x C-s") 'anything-c-grep-run-save-buffer
)
1494 (when anything-c-grep-use-ioccur-style-keys
1495 (define-key map
(kbd "<right>") 'anything-c-grep-run-persistent-action
)
1496 (define-key map
(kbd "<left>") 'anything-c-grep-run-default-action
))
1497 (define-key map
(kbd "C-c ?") 'anything-grep-help
)
1499 "Keymap used in Grep sources.")
1501 (defvar anything-c-pdfgrep-map
1502 (let ((map (copy-keymap anything-map
)))
1503 (define-key map
(kbd "M-<down>") 'anything-c-goto-next-file
)
1504 (define-key map
(kbd "M-<up>") 'anything-c-goto-precedent-file
)
1505 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1506 (define-key map
(kbd "C-c ?") 'anything-pdfgrep-help
)
1508 "Keymap used in pdfgrep.")
1510 (defvar anything-c-etags-map
1511 (let ((map (copy-keymap anything-map
)))
1512 (define-key map
(kbd "M-<down>") 'anything-c-goto-next-file
)
1513 (define-key map
(kbd "M-<up>") 'anything-c-goto-precedent-file
)
1514 (define-key map
(kbd "C-w") 'anything-yank-text-at-point
)
1515 (define-key map
(kbd "C-c ?") 'anything-etags-help
)
1517 "Keymap used in Etags.")
1519 (defvar anything-eval-expression-map
1520 (let ((map (copy-keymap anything-map
)))
1521 (define-key map
(kbd "<C-return>") 'anything-eval-new-line-and-indent
)
1522 (define-key map
(kbd "<tab>") 'lisp-indent-line
)
1523 (define-key map
(kbd "<C-tab>") 'lisp-complete-symbol
)
1524 (define-key map
(kbd "C-p") 'previous-line
)
1525 (define-key map
(kbd "C-n") 'next-line
)
1526 (define-key map
(kbd "<up>") 'previous-line
)
1527 (define-key map
(kbd "<down>") 'next-line
)
1528 (define-key map
(kbd "<right>") 'forward-char
)
1529 (define-key map
(kbd "<left>") 'backward-char
)
1532 (defvar anything-c-ucs-map
1533 (let ((map (copy-keymap anything-map
)))
1534 (define-key map
(kbd "<C-backspace>") 'anything-c-ucs-persistent-delete
)
1535 (define-key map
(kbd "<C-left>") 'anything-c-ucs-persistent-backward
)
1536 (define-key map
(kbd "<C-right>") 'anything-c-ucs-persistent-forward
)
1537 (define-key map
(kbd "<C-return>") 'anything-c-ucs-persistent-insert
)
1538 (define-key map
(kbd "C-c ?") 'anything-c-ucs-help
)
1540 "Keymap for `anything-ucs'.")
1544 ;;; Embeded documentation.
1547 (defun anything-c-list-preconfigured-anything ()
1548 "Collect preconfigured anything functions in this file."
1551 for entry in
(cdr (assoc
1552 (file-truename (locate-library "anything-config"))
1554 if
(and (consp entry
)
1555 (eq (car entry
) 'defun
)
1556 (string-match "^Preconfigured.+$"
1557 (setq doc
(or (documentation (setq sym
(cdr entry
)))
1559 collect
(cons sym
(match-string 0 doc
))))
1561 (defun anything-c-format-preconfigured-anything ()
1562 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x
) (cdr x
)))
1563 (anything-c-list-preconfigured-anything)))
1565 ;;; Global help message - Used by `anything-help'
1568 (setq anything-help-message
1572 "`anything' is QuickSilver-like candidate-selection framework.
1574 Narrow the list by typing some pattern,
1575 Multiple patterns are allowed by splitting by space.
1576 Select with natural Emacs operations, choose with RET.
1578 If you have any problems, press C-c C-x C-b!!
1579 Feel free to send bug reports. I'll fix them.
1580 The steps are described in the beginning of anything.el file.
1582 == Basic Operations ==
1583 C-p, Up: Previous Line
1584 C-n, Down : Next Line
1585 M-v, PageUp : Previous Page
1586 C-v, PageDown : Next Page
1587 Enter : Execute first (default) action / Select
1590 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1591 M-PageDown, C-M-v : Next Page (other-window)
1593 Tab, C-i : Show action list
1594 Left : Previous Source
1595 Right, C-o : Next Source
1596 C-k : Delete pattern
1597 C-z : Persistent Action (Execute action with anything session kept)
1598 C-c C-x C-b: Send a bug report
1600 == Shortcuts For 2nd/3rd Action ==
1601 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1602 \\[anything-select-3rd-action] : Execute 3rd Action
1605 Visible marks store candidate. Some actions uses marked candidates.
1607 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1608 \\[anything-prev-visible-mark] : Previous Mark
1609 \\[anything-next-visible-mark] : Next Mark
1611 == Miscellaneous Commands ==
1612 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1613 \\[anything-quit-and-find-file] : Drop into `find-file'
1614 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1615 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1616 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1617 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1618 \\[anything-force-update] : Recalculate And Redisplay Candidates
1620 == Global Commands ==
1621 \\<global-map>\\[anything-resume] revives last `anything' session.
1622 It is very useful, so you should bind any key.
1624 Single source is executed by \\[anything-call-source].
1626 == Preconfigured `anything' ==
1627 Preconfigured `anything' is commands that uses `anything' interface.
1628 You can use them without configuration.
1631 (apply 'concat
(anything-c-format-preconfigured-anything))
1635 ;;; `anything-buffer-list' help
1639 (defun anything-c-buffer-help ()
1640 "Help command for anything buffers."
1642 (let ((anything-help-message "== Anything Buffer ==
1644 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1645 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1646 \nSpecific commands for `anything-buffers-list':
1647 \\<anything-c-buffer-map>
1648 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1649 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1650 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1651 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1652 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1653 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1654 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1655 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1656 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1657 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1658 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1659 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1660 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1661 \\[anything-mark-all]\t\t->Mark all.
1662 \\[anything-c-buffer-help]\t\t->Display this help.
1663 \n== Anything Map ==
1669 ;;; Find files help (`anything-find-files')
1673 (defun anything-ff-help ()
1674 "Help command for `anything-find-files'."
1676 (let ((anything-help-message "== Anything Find Files ==
1678 \nEnter \"~/\" at anytime to reach home directory.
1679 Enter \"/\" at anytime to reach root of your file system.
1680 You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1681 Use `C-u C-z' to watch an image.
1682 To browse images directories turn on `anything-follow-mode'.
1683 \nSpecific commands for `anything-find-files':
1684 \\<anything-find-files-map>
1685 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1686 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1687 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1688 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1689 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1690 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1691 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1692 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1693 \\[anything-ff-run-load-file]\t\t->Load File.
1694 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1695 \\[anything-ff-run-delete-file]\t\t->Delete File.
1696 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1697 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1698 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1699 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1700 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1701 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1702 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1703 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1704 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1705 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1706 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1707 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1708 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1709 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1710 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1711 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1712 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1713 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1714 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1715 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1716 \\[anything-narrow-window]\t\t->Narrow anything window.
1717 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1718 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1719 \\[anything-ff-help]\t\t->Display this help info.
1720 \n== Anything Map ==
1725 ;;; Help for `anything-c-read-file-name'
1729 (defun anything-read-file-name-help ()
1731 (let ((anything-help-message "== Anything read file name Map ==\
1732 \nSpecific commands for anything-c-read-file-name:
1733 \\<anything-c-read-file-map>
1734 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1735 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1736 \\[anything-next-source]\t\t->Goto next source.
1737 \\[anything-previous-source]\t->Goto previous source.
1738 \\[anything-read-file-name-help]\t\t->Display this help info.
1739 \n== Anything Map ==
1744 ;;; Generic file help - Used by locate.
1748 (defun anything-generic-file-help ()
1750 (let ((anything-help-message "== Anything Generic files Map ==\
1751 \nSpecific commands for anything locate and others files sources:
1752 \\<anything-generic-files-map>
1753 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1754 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1755 \\[anything-ff-run-delete-file]\t\t->Delete file.
1756 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1757 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1758 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1759 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1761 You can add after writing search pattern any of the locate command line options.
1762 e.g -b, -e, -n <number>...etc.
1763 See Man locate for more infos.
1764 \n== Anything Map ==
1773 (defun anything-grep-help ()
1775 (let ((anything-help-message "== Anything Grep Map ==\
1776 \nSpecific commands for Grep and Etags:
1777 \\<anything-c-grep-map>
1778 \\[anything-c-goto-next-file]\t->Next File.
1779 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1780 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1781 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1782 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1783 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1784 \\[anything-grep-help]\t\t->Show this help.
1785 \n== Anything Map ==
1793 (defun anything-pdfgrep-help ()
1795 (let ((anything-help-message "== Anything PdfGrep Map ==\
1796 \nSpecific commands for Pdf Grep:
1797 \\<anything-c-pdfgrep-map>
1798 \\[anything-c-goto-next-file]\t->Next File.
1799 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1800 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1801 \\[anything-pdfgrep-help]\t\t->Show this help.
1802 \n== Anything Map ==
1810 (defun anything-etags-help ()
1811 "The help function for etags."
1813 (let ((anything-help-message "== Anything Etags Map ==\
1814 \nSpecific commands for Etags:
1815 \\<anything-c-etags-map>
1816 \\[anything-c-goto-next-file]\t->Next File.
1817 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1818 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1819 \\[anything-etags-help]\t\t->Show this help.
1820 \n== Anything Map ==
1827 (defun anything-c-ucs-help ()
1828 "Help command for `anything-ucs'."
1830 (let ((anything-help-message "== Anything Ucs ==
1831 \nSpecific commands for `anything-ucs':
1832 \\<anything-c-ucs-map>
1833 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1834 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1835 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1836 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1837 \\[anything-c-ucs-help]\t\t->Show this help.
1839 \n== Anything Map ==
1846 ;;; Mode line strings
1849 (defvar anything-buffer-mode-line-string
1851 "\\<anything-c-buffer-map>\
1852 \\[anything-c-buffer-help]:Help, \
1854 \\[anything-select-action]:Acts,\
1855 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1856 \\[anything-select-3rd-action]:NthAct,\
1857 \\[anything-send-bug-report-from-anything]:BugReport."
1858 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1860 (defvar anything-ff-mode-line-string
1861 "\\<anything-find-files-map>\
1862 \\[anything-ff-help]:Help, \
1863 \\[anything-send-bug-report-from-anything]:BugReport, \
1865 \\[anything-select-action]:Acts, \
1866 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1867 \\[anything-select-3rd-action]:NthAct"
1868 "String displayed in mode-line in `anything-c-source-find-files'")
1870 (defvar anything-read-file-name-mode-line-string
1871 "\\<anything-c-read-file-map>\
1872 \\[anything-read-file-name-help]:Help, \
1874 \\[anything-select-action]:Acts,\
1875 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1876 \\[anything-select-3rd-action]:NthAct"
1877 "String displayed in mode-line in `anything-c-source-find-files'")
1879 (defvar anything-generic-file-mode-line-string
1880 "\\<anything-generic-files-map>\
1881 \\[anything-generic-file-help]:Help, \
1883 \\[anything-select-action]:Acts,\
1884 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1885 \\[anything-select-3rd-action]:NthAct,\
1886 \\[anything-send-bug-report-from-anything]:BugReport."
1887 "String displayed in mode-line in Locate.")
1889 (defvar anything-grep-mode-line-string
1890 "\\<anything-c-grep-map>\
1891 \\[anything-grep-help]:Help,\
1893 \\[anything-select-action]:Acts,\
1894 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1895 \\[anything-select-3rd-action]:NthAct,\
1896 \\[anything-send-bug-report-from-anything]:BugReport."
1897 "String displayed in mode-line in `anything-do-grep'.")
1899 (defvar anything-pdfgrep-mode-line-string
1900 "\\<anything-c-pdfgrep-map>\
1901 \\[anything-pdfgrep-help]:Help,\
1903 \\[anything-select-action]:Acts,\
1904 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1905 \\[anything-select-3rd-action]:NthAct,\
1906 \\[anything-send-bug-report-from-anything]:BugReport."
1907 "String displayed in mode-line in `anything-do-pdfgrep'.")
1909 (defvar anything-etags-mode-line-string
1910 "\\<anything-c-etags-map>\
1911 \\[anything-etags-help]:Help,\
1913 \\[anything-select-action]:Acts,\
1914 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1915 \\[anything-select-3rd-action]:NthAct,\
1916 \\[anything-send-bug-report-from-anything]:BugReport."
1917 "String displayed in mode-line in `anything-c-etags-select'.")
1920 (defvar anything-c-ucs-mode-line-string
1921 "\\<anything-c-ucs-map>\
1922 \\[anything-c-ucs-help]:Help, \
1924 \\[anything-select-action]:Acts,\
1925 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1926 \\[anything-select-3rd-action]:NthAct."
1927 "String displayed in mode-line in `anything-ucs'.")
1931 ;;; Preconfigured Anything
1935 (defun anything-mini ()
1936 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
1938 (anything-other-buffer '(anything-c-source-buffers-list anything-c-source-recentf
)
1941 (defun anything-for-files ()
1942 "Preconfigured `anything' for opening files.
1943 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
1945 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
1948 (defun anything-recentf ()
1949 "Preconfigured `anything' for `recentf'."
1951 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
1954 (defun anything-info-at-point (arg)
1955 "Preconfigured `anything' for searching info at point.
1956 With a prefix-arg insert symbol at point."
1958 (let ((anything-c-google-suggest-default-function
1959 'anything-c-google-suggest-emacs-lisp
))
1960 (anything :sources
'(anything-c-source-info-elisp
1961 anything-c-source-info-cl
1962 anything-c-source-info-pages
1963 anything-c-source-google-suggest
)
1964 :input
(and arg
(thing-at-point 'symbol
))
1965 :buffer
"*anything info*")))
1968 (defun anything-info-emacs ()
1969 "Preconfigured anything for Emacs manual index."
1971 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
1974 (defun anything-show-kill-ring ()
1975 "Preconfigured `anything' for `kill-ring'.
1976 It is drop-in replacement of `yank-pop'.
1977 You may bind this command to M-y.
1978 First call open the kill-ring browser, next calls move to next line."
1980 (let ((buf "*anything kill-ring*"))
1981 (if (get-buffer-window buf
)
1982 (with-anything-window
1983 (if (eq (overlay-end anything-selection-overlay
) (point-max))
1984 (anything-beginning-of-buffer)
1985 (anything-next-line)))
1986 (anything-other-buffer 'anything-c-source-kill-ring buf
))))
1989 (defun anything-minibuffer-history ()
1990 "Preconfigured `anything' for `minibuffer-history'."
1992 (let ((enable-recursive-minibuffers t
))
1993 (anything-other-buffer 'anything-c-source-minibuffer-history
1994 "*anything minibuffer-history*")))
1997 (defun anything-gentoo ()
1998 "Preconfigured `anything' for gentoo linux."
2000 (anything-other-buffer '(anything-c-source-gentoo
2001 anything-c-source-use-flags
)
2002 "*anything gentoo*"))
2005 (defun anything-imenu ()
2006 "Preconfigured `anything' for `imenu'."
2008 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
2011 (defun anything-google-suggest ()
2012 "Preconfigured `anything' for google search with google suggest."
2014 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
2017 (defun anything-yahoo-suggest ()
2018 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
2020 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
2022 ;;; Converted from anything-show-*-only
2024 (defun anything-for-buffers ()
2025 "Preconfigured `anything' for buffer."
2027 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
2030 (defun anything-buffers-list ()
2031 "Enhanced preconfigured `anything' for buffer."
2033 (anything :sources
'(anything-c-source-buffers-list
2034 anything-c-source-buffer-not-found
)
2035 :buffer
"*anything buffers*" :keymap anything-c-buffer-map
))
2038 (defun anything-bbdb ()
2039 "Preconfigured `anything' for BBDB.
2043 http://bbdb.sourceforge.net/"
2045 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
2048 (defun anything-locate (arg)
2049 "Preconfigured `anything' for Locate.
2050 Note: you can add locate options after entering pattern.
2051 See 'man locate' for valid options.
2053 You can specify a specific database with prefix argument ARG \(C-u\).
2054 Many databases can be used: navigate and mark them.
2055 See also `anything-locate-with-db'.
2057 To create a user specific db, use
2058 \"updatedb -l 0 -o db_path -U directory\".
2059 Where db_path is a filename matched by
2060 `anything-locate-db-file-regexp'."
2062 (anything-locate-1 arg
))
2065 (defun anything-w3m-bookmarks ()
2066 "Preconfigured `anything' for w3m bookmark.
2068 Needs w3m and emacs-w3m.
2070 http://w3m.sourceforge.net/
2071 http://emacs-w3m.namazu.org/"
2073 (anything-other-buffer 'anything-c-source-w3m-bookmarks
2074 "*anything w3m bookmarks*"))
2077 (defun anything-firefox-bookmarks ()
2078 "Preconfigured `anything' for firefox bookmark.
2079 You will have to enable html bookmarks in firefox:
2080 open about:config in firefox and double click on this line to enable value \
2083 user_pref(\"browser.bookmarks.autoExportHTML\", false);
2085 You should have now:
2087 user_pref(\"browser.bookmarks.autoExportHTML\", true);
2089 After closing firefox, you will be able to browse you bookmarks.
2092 (anything-other-buffer 'anything-c-source-firefox-bookmarks
2093 "*Anything Firefox*"))
2096 (defun anything-colors ()
2097 "Preconfigured `anything' for color."
2099 (anything-other-buffer
2100 '(anything-c-source-colors anything-c-source-customize-face
)
2101 "*anything colors*"))
2104 (defun anything-bookmarks ()
2105 "Preconfigured `anything' for bookmarks."
2107 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
2110 (defun anything-c-pp-bookmarks ()
2111 "Preconfigured `anything' for bookmarks (pretty-printed)."
2113 (anything-other-buffer '(anything-c-source-bookmarks-local
2114 anything-c-source-bookmarks-su
2115 anything-c-source-bookmarks-ssh
)
2116 "*anything pp bookmarks*"))
2119 (defun anything-c-insert-latex-math ()
2120 "Preconfigured anything for latex math symbols completion."
2122 (anything-other-buffer 'anything-c-source-latex-math
"*anything latex*"))
2125 (defun anything-register ()
2126 "Preconfigured `anything' for Emacs registers."
2128 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
2131 (defun anything-man-woman ()
2132 "Preconfigured `anything' for Man and Woman pages."
2134 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
2137 (defun anything-org-keywords ()
2138 "Preconfigured `anything' for org keywords."
2140 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
2143 (defun anything-emms ()
2144 "Preconfigured `anything' for emms sources."
2146 (anything '(anything-c-source-emms-streams
2147 anything-c-source-emms-files
2148 anything-c-source-emms-dired
)
2153 (defun anything-eev-anchors ()
2154 "Preconfigured `anything' for eev anchors."
2156 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
2159 (defun anything-bm-list ()
2160 "Preconfigured `anything' for visible bookmarks.
2164 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
2166 (let ((anything-outline-using t
))
2167 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
2170 (defun anything-timers ()
2171 "Preconfigured `anything' for timers."
2173 (anything-other-buffer '(anything-c-source-absolute-time-timers
2174 anything-c-source-idle-time-timers
)
2175 "*anything timers*"))
2178 (defun anything-list-emacs-process ()
2179 "Preconfigured `anything' for emacs process."
2181 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
2184 (defun anything-occur ()
2185 "Preconfigured Anything for Occur source.
2186 If region is active, search only in region,
2187 otherwise search in whole buffer."
2189 (let ((anything-compile-source-functions
2190 ;; rule out anything-match-plugin because the input is one regexp.
2191 (delq 'anything-compile-source--match-plugin
2192 (copy-sequence anything-compile-source-functions
))))
2193 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
2196 (defun anything-browse-code ()
2197 "Preconfigured anything to browse code."
2199 (anything-other-buffer 'anything-c-source-browse-code
"*Browse code*"))
2202 (defun anything-org-headlines ()
2203 "Preconfigured anything to show org headlines."
2205 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
2208 (defun anything-info-gnus ()
2209 "Preconfigured anything to browse Gnus Manual."
2211 (anything-other-buffer 'anything-c-source-info-gnus
"*info Gnus*"))
2214 (defun anything-regexp ()
2215 "Preconfigured anything to build regexps and run query-replace-regexp \
2219 (let ((anything-compile-source-functions
2220 ;; rule out anything-match-plugin because the input is one regexp.
2221 (delq 'anything-compile-source--match-plugin
2222 (copy-sequence anything-compile-source-functions
))))
2223 (when (and (anything-region-active-p)
2224 ;; Don't narrow to region if buffer is already narrowed.
2225 (not (anything-current-buffer-narrowed-p)))
2226 (narrow-to-region (region-beginning) (region-end)))
2228 anything-c-source-regexp
2229 :buffer
"*anything regexp*"
2230 :prompt
"Regexp: "))))
2232 (defun anything-c-copy-files-async ()
2233 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
2235 (let* ((flist (anything-c-read-file-name
2237 :marked-candidates t
))
2238 (dest (anything-c-read-file-name
2239 "Copy File async To: "
2240 :preselect
(car flist
)
2241 :initial-input
(car anything-ff-history
)
2242 :history
(anything-find-files-history :comp-read nil
))))
2243 (anything-c-copy-async-with-log flist dest
)))
2246 (defun anything-find-files (arg)
2247 "Preconfigured `anything' for anything implementation of `find-file'.
2248 Called with a prefix arg show history if some.
2249 Don't call it from programs, use `anything-find-files-1' instead.
2250 This is the starting point for nearly all actions you can do on files."
2252 (let ((any-input (if (and arg anything-ff-history
)
2253 (anything-find-files-history)
2254 (anything-find-files-initial-input)))
2255 (presel (buffer-file-name (current-buffer))))
2256 (when (and (eq major-mode
'org-agenda-mode
)
2259 (setq any-input
(expand-file-name org-directory
)))
2260 (set-text-properties 0 (length any-input
) nil any-input
)
2262 (anything-find-files-1 any-input
)
2263 (setq any-input
(expand-file-name (anything-c-current-directory)))
2264 (anything-find-files-1
2265 any-input
(if anything-ff-transformer-show-only-basename
2266 (and presel
(anything-c-basename presel
))
2270 (defun anything-write-file ()
2271 "Preconfigured `anything' providing completion for `write-file'."
2273 (let ((anything-mp-highlight-delay nil
))
2274 (anything :sources
'anything-c-source-write-file
2275 :input
(expand-file-name default-directory
)
2276 :prompt
"Write buffer to file: "
2277 :buffer
"*Anything write file*")))
2280 (defun anything-insert-file ()
2281 "Preconfigured `anything' providing completion for `insert-file'."
2283 (let ((anything-mp-highlight-delay nil
))
2284 (anything :sources
'anything-c-source-insert-file
2285 :input
(expand-file-name default-directory
)
2286 :prompt
"Insert file: "
2287 :buffer
"*Anything insert file*")))
2290 (defun anything-dired-rename-file ()
2291 "Preconfigured `anything' to rename files from dired."
2293 (anything-dired-do-action-on-file :action
'rename
))
2296 (defun anything-dired-copy-file ()
2297 "Preconfigured `anything' to copy files from dired."
2299 (anything-dired-do-action-on-file :action
'copy
))
2302 (defun anything-dired-symlink-file ()
2303 "Preconfigured `anything' to symlink files from dired."
2305 (anything-dired-do-action-on-file :action
'symlink
))
2308 (defun anything-dired-hardlink-file ()
2309 "Preconfigured `anything' to hardlink files from dired."
2311 (anything-dired-do-action-on-file :action
'hardlink
))
2314 (defun anything-do-grep ()
2315 "Preconfigured anything for grep.
2316 Contrarily to Emacs `grep' no default directory is given, but
2317 the full path of candidates in ONLY.
2318 That allow to grep different files not only in `default-directory' but anywhere
2319 by marking them (C-<SPACE>). If one or more directory is selected
2320 grep will search in all files of these directories.
2321 You can use also wildcard in the base name of candidate.
2322 If a prefix arg is given use the -r option of grep.
2323 The prefix arg can be passed before or after start.
2324 See also `anything-do-grep-1'."
2326 (let ((only (anything-c-read-file-name
2327 "Search in file(s): "
2328 :marked-candidates t
2329 :preselect
(or (dired-get-filename nil t
)
2330 (buffer-file-name (current-buffer)))))
2331 (prefarg (or current-prefix-arg anything-current-prefix-arg
)))
2332 (anything-do-grep-1 only prefarg
)))
2335 (defun anything-do-zgrep (candidate)
2336 "Preconfigured anything for zgrep."
2337 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
2338 (ls (anything-c-read-file-name
2339 "Search in file(s): "
2340 :marked-candidates t
2341 :preselect
(or (dired-get-filename nil t
)
2342 (buffer-file-name (current-buffer))))))
2343 (anything-ff-zgrep-1 ls prefarg
)))
2345 (defun anything-c-etags-select (arg)
2346 "Preconfigured anything for etags.
2347 Called with one prefix arg use symbol at point as initial input.
2348 Called with two prefix arg reinitialize cache.
2349 If tag file have been modified reinitialize cache."
2351 (let ((tag (anything-c-etags-get-tag-file))
2352 (init (and (equal arg
'(4)) (thing-at-point 'symbol
)))
2353 (anything-quit-if-no-candidate t
)
2354 (anything-execute-action-at-once-if-one t
)
2355 (anything-compile-source-functions
2356 (if anything-c-etags-use-regexp-search
2357 ;; rule out anything-match-plugin because the input is one regexp.
2358 (delq 'anything-compile-source--match-plugin
2359 (copy-sequence anything-compile-source-functions
))
2360 anything-compile-source-functions
)))
2361 (when (or (equal arg
'(16))
2362 (and anything-c-etags-mtime-alist
2363 (anything-c-etags-file-modified-p tag
)))
2364 (remhash tag anything-c-etags-cache
))
2365 (if (and tag
(file-exists-p tag
))
2366 (anything :sources
'anything-c-source-etags-select
2367 :keymap anything-c-etags-map
2369 :buffer
"*anything etags*")
2370 (message "Error: No tag file found, please create one with etags shell command."))))
2373 (defun anything-filelist ()
2374 "Preconfigured `anything' to open files instantly.
2376 See `anything-c-filelist-file-name' docstring for usage."
2378 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
2381 (defun anything-filelist+ ()
2382 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
2384 This is a replacement for `anything-for-files'.
2385 See `anything-c-filelist-file-name' docstring for usage."
2387 (anything-other-buffer
2388 '(anything-c-source-ffap-line
2389 anything-c-source-ffap-guesser
2390 anything-c-source-buffers-list
2391 anything-c-source-recentf
2392 anything-c-source-bookmarks
2393 anything-c-source-file-cache
2394 anything-c-source-filelist
)
2395 "*anything file list*"))
2398 (defun anything-M-x ()
2399 "Preconfigured `anything' for Emacs commands.
2400 It is `anything' replacement of regular `M-x' `execute-extended-command'."
2404 anything-persistent-action-use-special-display
2405 (history (loop with hist
2406 for i in extended-command-history
2407 for com
= (intern i
)
2408 when
(and (fboundp com
) (not (member i hist
)))
2409 collect i into hist finally return hist
))
2410 (command (anything-comp-read
2415 :name
"Emacs Commands"
2417 #'(lambda (candidate)
2418 (let ((hbuf (get-buffer (help-buffer))))
2419 (if (and in-help
(string= candidate help-cand
))
2421 ;; When M-x is started from a help buffer,
2422 ;; Don't kill it as it is anything-current-buffer.
2423 (unless (equal hbuf anything-current-buffer
)
2426 ;; Be sure anything-current-buffer have not a dedicated window.
2427 (set-window-dedicated-p
2428 (get-buffer-window anything-current-buffer
) nil
)
2429 (describe-function (intern candidate
))
2430 (message nil
) ; Erase the new stupid message Type "q"[...]
2432 (setq help-cand candidate
)))
2433 :persistent-help
"Describe this command"
2436 :fc-transformer
'anything-M-x-transformer
)))
2437 (unless current-prefix-arg
(setq current-prefix-arg anything-current-prefix-arg
))
2438 (call-interactively (intern command
))
2439 (setq extended-command-history
(cons command
(delete command history
)))))
2442 (defun anything-manage-advice ()
2443 "Preconfigured `anything' to disable/enable function advices."
2445 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
2448 (defun anything-bookmark-ext ()
2449 "Preconfigured `anything' for bookmark-extensions sources.
2450 Needs bookmark-ext.el:
2451 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
2452 Contain also `anything-c-source-google-suggest'."
2456 '(anything-c-source-bookmark-files&dirs
2457 anything-c-source-bookmark-w3m
2458 anything-c-source-google-suggest
2459 anything-c-source-bmkext-addressbook
2460 anything-c-source-bookmark-gnus
2461 anything-c-source-bookmark-info
2462 anything-c-source-bookmark-man
2463 anything-c-source-bookmark-images
2464 anything-c-source-bookmark-su-files
&dirs
2465 anything-c-source-bookmark-ssh-files
&dirs
)
2466 :prompt
"SearchBookmark: "
2467 :buffer
"*anything bmkext*"))
2470 (defun anything-simple-call-tree ()
2471 "Preconfigured `anything' for simple-call-tree. List function relationships.
2473 Needs simple-call-tree.el.
2474 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
2476 (anything-other-buffer
2477 '(anything-c-source-simple-call-tree-functions-callers
2478 anything-c-source-simple-call-tree-callers-functions
)
2479 "*anything simple-call-tree*"))
2482 (defun anything-mark-ring ()
2483 "Preconfigured `anything' for `anything-c-source-mark-ring'."
2485 (anything 'anything-c-source-mark-ring
))
2488 (defun anything-global-mark-ring ()
2489 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
2491 (anything 'anything-c-source-global-mark-ring
))
2494 (defun anything-all-mark-rings ()
2495 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
2496 `anything-c-source-mark-ring'."
2498 (anything '(anything-c-source-mark-ring
2499 anything-c-source-global-mark-ring
)))
2502 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
2503 "Preconfigured `anything' to edit or view EmacsWiki page.
2507 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
2509 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
2512 (defun anything-yaoddmuse-emacswiki-post-library ()
2513 "Preconfigured `anything' to post library to EmacsWiki.
2517 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
2519 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
2522 (defun anything-eval-expression (arg)
2523 "Preconfigured anything for `anything-c-source-evaluation-result'."
2525 (anything :sources
'anything-c-source-evaluation-result
2526 :input
(when arg
(thing-at-point 'sexp
))
2527 :buffer
"*anything eval*"
2528 :keymap anything-eval-expression-map
))
2531 (defun anything-eval-expression-with-eldoc ()
2532 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
2534 (declare (special eldoc-idle-delay
))
2535 (let ((timer (run-with-idle-timer eldoc-idle-delay
2536 'repeat
'anything-eldoc-show-in-eval
))
2537 (minibuffer-completing-symbol t
) ; Enable lisp completion.
2538 (completion-cycle-threshold t
)) ; Always cycle, no pesty completion buffer (emacs24 only).
2540 (minibuffer-with-setup-hook
2541 'anything-eldoc-store-minibuffer
2542 (call-interactively 'anything-eval-expression
))
2543 (and timer
(cancel-timer timer
))
2544 (setq anything-eldoc-active-minibuffers-list
2545 (cdr anything-eldoc-active-minibuffers-list
)))))
2548 (defun anything-calcul-expression ()
2549 "Preconfigured anything for `anything-c-source-calculation-result'."
2551 (anything-other-buffer 'anything-c-source-calculation-result
"*anything calcul*"))
2554 (defun anything-surfraw (pattern engine
)
2555 "Preconfigured `anything' to search PATTERN with search ENGINE."
2556 (interactive (list (read-string "SearchFor: ")
2559 (anything-c-build-elvi-list)
2561 :name
"Surfraw Search Engines"
2562 :history anything-surfraw-engines-history
)))
2563 (let* ((engine-nodesc (car (split-string engine
)))
2564 (url (with-temp-buffer
2565 (apply 'call-process
"surfraw" nil t nil
2567 (append (list engine-nodesc
"-p") (split-string pattern
)))
2568 (replace-regexp-in-string
2569 "\n" "" (buffer-string))))
2570 (browse-url-browser-function (or anything-surfraw-default-browser-function
2571 browse-url-browser-function
)))
2572 (if (string= engine-nodesc
"W")
2573 (anything-c-browse-url)
2574 (anything-c-browse-url url
)
2575 (setq anything-surfraw-engines-history
2576 (cons engine
(delete engine anything-surfraw-engines-history
))))))
2579 (defun anything-call-source ()
2580 "Preconfigured `anything' to call anything source."
2582 (anything 'anything-c-source-call-source nil nil nil nil
2583 anything-source-select-buffer
))
2586 (defun anything-execute-anything-command ()
2587 "Preconfigured `anything' to execute preconfigured `anything'."
2589 (anything-other-buffer 'anything-c-source-anything-commands
2590 "*anything commands*"))
2593 (defun anything-create (&optional string initial-input
)
2594 "Preconfigured `anything' to do many create actions from STRING.
2595 See also `anything-create--actions'."
2597 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
2598 (anything '(((name .
"Anything Create")
2599 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
2600 (candidates . anything-create--actions
)
2601 (candidate-number-limit)
2602 (action .
(lambda (func) (funcall func string
)))))))
2605 (defun anything-top ()
2606 "Preconfigured `anything' for top command."
2608 (let ((anything-samewindow t
)
2609 (anything-enable-shortcuts)
2610 (anything-display-function 'anything-default-display-buffer
)
2611 (anything-candidate-number-limit 9999))
2612 (save-window-excursion
2613 (delete-other-windows)
2614 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
2617 (defun anything-select-xfont ()
2618 "Preconfigured `anything' to select Xfont."
2620 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
2623 (defun anything-world-time ()
2624 "Preconfigured `anything' to show world time."
2626 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
2629 (defun anything-apt (arg query
)
2630 "Preconfigured `anything' : frontend of APT package manager.
2631 With a prefix arg reload cache."
2632 (interactive "P\nsSearch Package: ")
2634 (setq anything-c-apt-installed-packages nil
)
2635 (setq anything-c-apt-all-packages nil
))
2636 (anything :sources
'anything-c-source-apt
2637 :prompt
"Search Package: " :input query
))
2640 (defun anything-esh-pcomplete ()
2641 "Preconfigured anything to provide anything completion in eshell."
2643 (let* ((anything-quit-if-no-candidate t
)
2644 (anything-execute-action-at-once-if-one t
)
2645 (target (thing-at-point 'symbol
))
2647 (beg (or (and target
(- end
(length target
)))
2648 ;; Nothing at point.
2649 (progn (insert " ") (point)))))
2650 (setq anything-ec-target
(or target
" "))
2651 (with-anything-show-completion beg end
2652 (anything :sources
'anything-c-source-esh
2653 :input
(anything-ff-set-pattern ; Handle tramp filenames.
2654 (car (last (ignore-errors ; Needed in lisp symbols completion.
2655 (pcomplete-parse-arguments)))))))))
2658 (defun anything-eshell-history ()
2659 "Preconfigured anything for eshell history."
2661 (let* ((end (point))
2662 (beg (progn (save-excursion (insert " ") (point)))))
2663 (with-anything-show-completion beg end
2664 (anything-other-buffer anything-c-source-eshell-history
"*Eshell history*"))))
2667 (defun anything-c-run-external-command (program)
2668 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
2669 If program is already running exit with error.
2670 You can set your own list of commands with
2671 `anything-c-external-commands-list'."
2675 (anything-c-external-commands-list-1 'sort
)
2677 :name
"External Commands"
2678 :history anything-external-command-history
)))
2679 (anything-run-or-raise program
)
2680 (setq anything-external-command-history
2681 (cons program
(delete program
2682 (loop for i in anything-external-command-history
2683 when
(executable-find i
) collect i
)))))
2686 (defun anything-ratpoison-commands ()
2687 "Preconfigured `anything' to execute ratpoison commands."
2689 (anything-other-buffer 'anything-c-source-ratpoison-commands
2690 "*anything ratpoison commands*"))
2693 (defun anything-ucs ()
2694 "Preconfigured anything for `ucs-names' math symbols."
2696 (anything :sources
'anything-c-source-ucs
2697 :keymap anything-c-ucs-map
))
2701 ;;; Utilities Functions
2704 (defun anything-ff-find-printers ()
2705 "Return a list of available printers on Unix systems."
2706 (let ((printer-list (with-temp-buffer
2707 (call-process "lpstat" nil t nil
"-a")
2708 (split-string (buffer-string) "\n"))))
2709 (loop for p in printer-list
2710 for printer
= (car (split-string p
))
2714 ;; Shut up byte compiler in emacs24*.
2715 (defun anything-c-switch-to-buffer (buffer-or-name)
2716 "Same as `switch-to-buffer' whithout warnings at compile time."
2718 (switch-to-buffer buffer-or-name
)))
2720 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
2721 "A simple and faster replacement of CL `position'."
2722 (loop for i in seq for index from
0
2723 when
(funcall test i item
) return index
))
2725 (defun anything-c-get-pid-from-process-name (process-name)
2726 "Get pid from running process PROCESS-NAME."
2727 (loop with process-list
= (list-system-processes)
2728 for pid in process-list
2729 for process
= (assoc-default 'comm
(process-attributes pid
))
2730 when
(and process
(string-match process-name process
))
2733 (defun* anything-current-buffer-narrowed-p
(&optional
2734 (buffer anything-current-buffer
))
2735 "Check if BUFFER is narrowed.
2736 Default is `anything-current-buffer'."
2737 (with-current-buffer buffer
2738 (let ((beg (point-min))
2740 (total (buffer-size)))
2741 (or (/= beg
1) (/= end
(1+ total
))))))
2743 (defun anything-region-active-p ()
2744 (and transient-mark-mode mark-active
(/= (mark) (point))))
2746 (defun anything-goto-line (lineno)
2747 "Goto LINENO opening only outline headline if needed."
2748 (goto-char (point-min)) (forward-line (1- lineno
))
2749 (when (or (eq major-mode
'org-mode
)
2750 (and (boundp 'outline-minor-mode
)
2751 outline-minor-mode
))
2753 (anything-match-line-color-current-line) (sit-for 0.3)
2754 (anything-match-line-cleanup))
2756 (defun anything-show-this-source-only ()
2757 "Show all candidates of this source."
2759 (setq anything-candidate-number-limit nil
)
2760 (anything-set-source-filter
2761 (list (assoc-default 'name
(anything-get-current-source)))))
2764 (defun anything-test-sources ()
2765 "List all anything sources for test.
2766 The output is sexps which are evaluated by \\[eval-last-sexp]."
2768 (with-output-to-temp-buffer "*Anything Test Sources*"
2769 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
2770 (apropos-internal "^anything-c-source" #'boundp
))
2771 (pop-to-buffer standard-output
)))
2773 (defun anything-nest (&rest same-as-anything
)
2774 "Nested `anything'. If you use `anything' within `anything', use it."
2775 (with-selected-window (anything-window)
2776 (let (anything-current-position
2777 anything-current-buffer
2778 (orig-anything-buffer anything-buffer
)
2782 anything-compiled-sources
2783 anything-buffer-chars-modified-tick
2784 (anything-samewindow t
)
2785 (enable-recursive-minibuffers t
))
2787 (apply #'anything same-as-anything
)
2788 (anything-initialize-overlays orig-anything-buffer
)
2789 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
2791 (defun anything-displaying-source-names ()
2792 "Display sources name."
2793 (with-current-buffer anything-buffer
2794 (goto-char (point-min))
2796 while
(setq pos
(next-single-property-change (point) 'anything-header
))
2798 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
2799 do
(forward-line 1))))
2802 (defun anything-select-source ()
2803 "[OBSOLETE] Select source."
2805 (let ((default (assoc-default 'name
(anything-get-current-source)))
2806 (source-names (anything-displaying-source-names))
2807 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
2808 (anything-get-sources))))
2809 (setq anything-candidate-number-limit
9999)
2811 (let (anything-source-filter)
2812 (anything-nest '(((name .
"Anything Source")
2813 (candidates . source-names
)
2814 (action . identity
))
2815 ((name .
"Anything Source (ALL)")
2816 (candidates . all-source-names
)
2817 (action . identity
)))
2819 default
"*anything select source*"))
2820 (anything-set-source-filter (list it
))
2821 (anything-set-source-filter nil
))))
2823 (defun anything-c-match-on-file-name (candidate)
2824 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2825 (string-match anything-pattern
(file-name-nondirectory candidate
)))
2827 (defun anything-c-match-on-directory-name (candidate)
2828 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2829 (anything-aif (file-name-directory candidate
)
2830 (string-match anything-pattern it
)))
2832 (defun anything-c-string-match (candidate)
2833 "Return non-nil if `anything-pattern' match CANDIDATE.
2834 The match is done with `string-match'."
2835 (string-match anything-pattern candidate
))
2837 (defun anything-c-skip-entries (list regexp
)
2838 "Remove entries which matches REGEXP from LIST."
2839 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
2842 (defun anything-c-shadow-entries (list regexp
)
2843 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2844 (mapcar (lambda (file)
2845 ;; Add shadow face property to boring files.
2846 (let ((face (if (facep 'file-name-shadow
)
2848 ;; fall back to default on XEmacs
2850 (if (string-match regexp file
)
2851 (setq file
(propertize file
'face face
))))
2855 (defsubst anything-c-stringify
(str-or-sym)
2856 "Get string of STR-OR-SYM."
2857 (if (stringp str-or-sym
)
2859 (symbol-name str-or-sym
)))
2861 (defsubst anything-c-symbolify
(str-or-sym)
2862 "Get symbol of STR-OR-SYM."
2863 (if (symbolp str-or-sym
)
2865 (intern str-or-sym
)))
2867 (defun anything-c-describe-function (func)
2868 "FUNC is symbol or string."
2869 (describe-function (anything-c-symbolify func
)))
2871 (defun anything-c-describe-variable (var)
2872 "VAR is symbol or string."
2873 (describe-variable (anything-c-symbolify var
)))
2875 (defun anything-c-find-function (func)
2876 "FUNC is symbol or string."
2877 (find-function (anything-c-symbolify func
)))
2879 (defun anything-c-find-variable (var)
2880 "VAR is symbol or string."
2881 (find-variable (anything-c-symbolify var
)))
2883 (defun anything-c-kill-new (candidate &optional replace
)
2884 "CANDIDATE is symbol or string.
2885 See `kill-new' for argument REPLACE."
2886 (kill-new (anything-c-stringify candidate
) replace
))
2888 (defun* anything-fast-remove-dups
(seq &key
(test 'eq
))
2889 "Remove duplicates elements in list SEQ.
2890 This is same as `remove-duplicates' but with memoisation.
2891 It is much faster, especially in large lists.
2892 A test function can be provided with TEST argument key.
2894 (let ((cont (make-hash-table :test test
)))
2895 (loop for elm in seq
2896 unless
(gethash elm cont
)
2897 do
(puthash elm elm cont
)
2899 (loop for i being the hash-values in cont collect i
))))
2901 (defadvice eval-defun
(after anything-source-hack activate
)
2902 "Allow immediate execution of anything source when evaling it.
2903 See `anything-c-enable-eval-defun-hack'."
2904 (when anything-c-enable-eval-defun-hack
2905 (let ((varsym (save-excursion
2906 (beginning-of-defun)
2908 (when (memq (read (current-buffer)) '(defvar setq
))
2909 (read (current-buffer))))))
2910 (when (string-match "^anything-c-source-" (symbol-name varsym
))
2911 (anything varsym
)))))
2912 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2914 (defadvice anything-quit-and-find-file
(around use-anything-find-files activate
)
2915 "Let `anything-quit-and-find-file' take advantage of `anything-find-files'."
2917 (anything-run-after-quit
2919 (if (file-exists-p f
)
2920 (anything-find-files-1 (file-name-directory f
)
2921 (if anything-ff-transformer-show-only-basename
2922 (anything-c-basename f
) f
))
2923 (anything-find-files-1 f
)))
2924 (anything-aif (get-buffer (anything-get-selection))
2925 (or (buffer-file-name it
)
2926 (car (rassoc it dired-buffers
))
2927 (and (with-current-buffer it
2928 (eq major-mode
'org-agenda-mode
))
2930 (expand-file-name org-directory
))
2932 (let ((sel (anything-get-selection)))
2933 (if (file-exists-p sel
)
2934 (expand-file-name sel
)
2935 default-directory
)))))
2937 (defmacro* anything-c-walk-directory
(directory &key
(path 'basename
) (directories t
) match
)
2938 "Walk through DIRECTORY tree.
2939 PATH can be one of basename, relative, or full.
2940 DIRECTORIES when non--nil (default) return also directories names, otherwise
2941 skip directories names.
2942 MATCH match only filenames matching regexp MATCH."
2945 (basename 'file-name-nondirectory
)
2946 (relative 'file-relative-name
)
2948 (t (error "Error: Invalid path spec `%s', must be one of basename, relative or full." ,path
)))))
2949 (labels ((ls-R (dir)
2950 (loop with ls
= (directory-files dir t directory-files-no-dot-files-regexp
)
2952 if
(file-directory-p f
)
2953 do
(progn (when ,directories
2954 (push (funcall fn f
) result
))
2955 ;; Don't recurse in directory symlink.
2956 (unless (file-symlink-p f
)
2959 (unless (and ,match
(not (string-match ,match
(file-name-nondirectory f
))))
2960 (push (funcall fn f
) result
)))))
2962 (nreverse result
))))
2964 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2966 ;;; Anything regexp.
2969 (defun anything-c-query-replace-regexp (candidate)
2970 "Query replace regexp from `anything-regexp'.
2971 With a prefix arg replace only matches surrounded by word boundaries,
2972 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2973 (let ((regexp (funcall (anything-attr 'regexp
))))
2974 (apply 'query-replace-regexp
2975 (anything-c-query-replace-args regexp
))))
2977 (defun anything-c-kill-regexp-as-sexp (candidate)
2978 "Kill regexp in a format usable in lisp code."
2979 (anything-c-regexp-kill-new
2980 (prin1-to-string (funcall (anything-attr 'regexp
)))))
2982 (defun anything-c-kill-regexp (candidate)
2983 "Kill regexp as it is in `anything-pattern'."
2984 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
2986 (defun anything-c-query-replace-args (regexp)
2987 "create arguments of `query-replace-regexp' action in `anything-regexp'."
2988 (let ((region-only (anything-region-active-p)))
2991 (query-replace-read-to regexp
2992 (format "Query replace %sregexp %s"
2993 (if anything-current-prefix-arg
"word " "")
2994 (if region-only
"in region " ""))
2996 anything-current-prefix-arg
2997 (when region-only
(region-beginning))
2998 (when region-only
(region-end)))))
3000 (defvar anything-c-source-regexp
3001 '((name .
"Regexp Builder")
3003 (anything-candidate-buffer anything-current-buffer
)))
3004 (candidates-in-buffer)
3005 (get-line . anything-c-regexp-get-line
)
3006 (persistent-action . anything-c-regexp-persistent-action
)
3007 (persistent-help .
"Show this line")
3010 (requires-pattern .
2)
3011 (mode-line .
"Press TAB to select action.")
3012 (regexp .
(lambda () anything-input
))
3013 (action .
(("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
3014 ("Query Replace Regexp (C-u Not inside word.)"
3015 . anything-c-query-replace-regexp
)
3016 ("Kill Regexp" . anything-c-kill-regexp
)))))
3018 (defun anything-c-regexp-get-line (s e
)
3022 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
3024 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
3025 collect
(format "\n %s'%s'"
3026 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
3029 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
3030 ;; It is implementation problem of candidates-in-buffer.
3034 (defun anything-c-regexp-persistent-action (pt)
3036 (anything-persistent-highlight-point))
3038 (defun anything-c-regexp-kill-new (input)
3040 (message "Killed: %s" input
))
3044 ;;; Toggle all marks.
3048 (defun anything-mark-all ()
3049 "Mark all visible unmarked candidates in current source."
3051 (with-anything-window
3053 (goto-char (anything-get-previous-header-pos))
3054 (anything-next-line)
3055 (let* ((next-head (anything-get-next-header-pos))
3058 (goto-char next-head
)
3061 (maxpoint (or end
(point-max))))
3062 (while (< (point) maxpoint
)
3063 (anything-mark-current-line)
3064 (let ((prefix (get-text-property (point-at-bol) 'display
))
3065 (bn (anything-c-basename (anything-get-selection)))
3066 (src (assoc-default 'name
(anything-get-current-source))))
3067 (when (and (not (anything-this-visible-mark))
3068 (not (or (string= prefix
"[?]")
3069 (string= prefix
"[@]"))))
3070 ;; Don't mark possibles directories ending with . or ..
3071 ;; and also autosave files/links.
3073 (and (or (anything-file-completion-source-p)
3074 (equal src
"Files from Current Directory"))
3075 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn
))
3076 (anything-make-visible-mark))))
3077 (forward-line 1) (end-of-line))))
3078 (anything-mark-current-line)
3079 (message "%s candidates marked" (length anything-marked-candidates
))))
3082 (defun anything-unmark-all ()
3083 "Unmark all candidates in all sources of current anything session."
3085 (with-anything-window
3086 (let ((len (length anything-marked-candidates
)))
3088 (anything-clear-visible-mark))
3089 (setq anything-marked-candidates nil
)
3090 (anything-mark-current-line)
3091 (message "%s candidates unmarked" len
))))
3094 (defun anything-toggle-all-marks ()
3096 Mark all visible candidates of current source or unmark all candidates
3097 visible or invisible in all sources of current anything session"
3099 (let ((marked (anything-marked-candidates)))
3100 (if (and (>= (length marked
) 1)
3101 (with-anything-window anything-visible-mark-overlays
))
3102 (anything-unmark-all)
3103 (anything-mark-all))))
3105 (define-key anything-map
(kbd "M-m") 'anything-toggle-all-marks
)
3112 (defun anything-c-buffer-list ()
3113 "Return the list of names of buffers with boring buffers filtered out.
3114 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
3115 The first buffer in the list will be the last recently used
3116 buffer that is not the current buffer."
3117 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
3118 (append (cdr buffers
) (list (car buffers
)))))
3120 (defvar anything-c-source-buffers
3121 '((name .
"Buffers")
3122 (candidates . anything-c-buffer-list
)
3124 ;; (anything 'anything-c-source-buffers)
3126 (defvar anything-c-source-buffer-not-found
3127 '((name .
"Create buffer")
3129 (filtered-candidate-transformer (lambda (cands source
)
3130 (list anything-pattern
)))
3131 (action .
(lambda (candidate)
3132 (anything-c-switch-to-buffer (get-buffer-create candidate
))))))
3133 ;; (anything 'anything-c-source-buffer-not-found)
3135 ;;; Buffers-list (was buffers+)
3138 (eval-when-compile (require 'dired
))
3140 (defun anything-c-highlight-buffers (buffers)
3141 (loop for i in buffers
3142 for buf
= (get-buffer i
)
3143 for bfname
= (buffer-file-name buf
)
3145 (cond (;; A dired buffer.
3146 (rassoc buf dired-buffers
)
3147 (propertize i
'face
'anything-ff-directory
3148 'help-echo
(car (rassoc buf dired-buffers
))))
3149 ;; A buffer file modified somewhere outside of emacs.
3150 ((and bfname
(not (file-remote-p bfname
))
3151 (file-exists-p bfname
)
3152 (not (verify-visited-file-modtime buf
)))
3153 (propertize i
'face
'anything-buffer-saved-out
3155 ;; A new buffer file not already saved on disk.
3156 ((and bfname
(not (file-remote-p bfname
))
3157 (not (verify-visited-file-modtime buf
)))
3158 (propertize i
'face
'anything-buffer-not-saved
3160 ;; A Remote buffer file modified and not saved on disk.
3161 ((and bfname
(file-remote-p bfname
) (buffer-modified-p buf
))
3162 (let ((prefix (propertize
3164 (propertize "@ " 'face
'anything-ff-prefix
))))
3165 (cons (concat prefix
(propertize i
'face
'anything-ff-symlink
3166 'help-echo bfname
)) i
)))
3167 ;; A buffer file modified and not saved on disk.
3168 ((and bfname
(buffer-modified-p buf
))
3169 (propertize i
'face
'anything-ff-symlink
3171 ;; A remote buffer file not modified and saved on disk.
3172 ((and bfname
(file-remote-p bfname
))
3173 (let ((prefix (propertize
3175 (propertize "@ " 'face
'anything-ff-prefix
))))
3176 (cons (concat prefix
(propertize i
'face
'font-lock-type-face
3177 'help-echo bfname
)) i
)))
3178 ;; A buffer file not modified and saved on disk.
3180 (propertize i
'face
'font-lock-type-face
3182 ;; Any non--file buffer.
3183 (t (propertize i
'face
'italic
)))))
3186 (defvar anything-c-source-buffers-list
3187 '((name .
"Buffers")
3188 (candidates . anything-c-buffer-list
)
3190 (match anything-c-buffer-match-major-mode
)
3191 (diff-action . anything-buffer-toggle-diff
)
3192 (revert-action . anything-buffer-revert-and-update
)
3193 (save-action . anything-buffer-save-and-update
)
3194 (candidate-transformer anything-c-skip-current-buffer
3195 anything-c-skip-boring-buffers
3196 anything-c-highlight-buffers
)
3197 (persistent-action . anything-c-buffers-list-persistent-action
)
3199 (mode-line . anything-buffer-mode-line-string
)
3200 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
3201 ;; (anything 'anything-c-source-buffers-list)
3203 (defun anything-c-buffer-match-major-mode (candidate)
3204 "Match maybe buffer by major-mode.
3205 If you give a major-mode or partial major-mode,
3206 it will list all buffers of this major-mode and/or buffers with name
3207 matching this major-mode.
3208 If you add a space after major-mode and then a space,
3209 it will match all buffers of the major-mode
3210 before space matching pattern after space.
3211 If you give a pattern which doesn't match a major-mode, it will search buffer
3212 with name matching pattern."
3213 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate
))
3214 (buf (get-buffer cand
)))
3216 (with-current-buffer buf
3217 (let ((mjm (symbol-name major-mode
))
3218 (split (split-string anything-pattern
)))
3219 (cond ((string-match "\\s-$" anything-pattern
)
3220 (string-match (car split
) mjm
))
3221 ((string-match "\\s-" anything-pattern
)
3222 (and (string-match (car split
) mjm
)
3223 (string-match (cadr split
) cand
)))
3224 (t (or (string-match anything-pattern mjm
)
3225 (string-match anything-pattern cand
)))))))))
3227 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag
)
3228 "Query replace in marked buffers.
3229 If REGEXP-FLAG is given use `query-replace-regexp'."
3230 (let ((fn (if regexp-flag
'query-replace-regexp
'query-replace
))
3231 (prompt (if regexp-flag
"Query replace regexp" "Query replace"))
3232 (bufs (anything-marked-candidates)))
3234 with replace
= (query-replace-read-from prompt regexp-flag
)
3235 with tostring
= (unless (consp replace
)
3236 (query-replace-read-to
3237 replace prompt regexp-flag
))
3240 (save-window-excursion
3241 (anything-c-switch-to-buffer buf
)
3243 (let ((case-fold-search t
))
3244 (goto-char (point-min))
3246 (apply fn
(list (car replace
) (cdr replace
)))
3247 (apply fn
(list replace tostring
)))))))))
3249 (defun anything-c-buffer-query-replace-regexp (candidate)
3250 (anything-c-buffer-query-replace-1 'regexp
))
3252 (defun anything-c-buffer-query-replace (candidate)
3253 (anything-c-buffer-query-replace-1))
3255 (defun anything-buffer-toggle-diff (candidate)
3256 "Toggle diff buffer CANDIDATE with it's file."
3257 (if (get-buffer-window "*Diff*")
3258 (kill-buffer "*Diff*")
3259 (diff-buffer-with-file (get-buffer candidate
))))
3262 (defun anything-buffer-diff-persistent ()
3263 "Toggle diff buffer without quitting anything."
3265 (anything-execute-persistent-action 'diff-action
))
3267 (defun anything-buffer-revert-and-update (candidate)
3268 (let ((marked (anything-marked-candidates)))
3269 (loop for buf in marked do
(anything-revert-buffer buf
))
3270 (anything-force-update)
3271 (anything-c-recenter-window)))
3274 (defun anything-buffer-revert-persistent ()
3275 "Revert buffer without quitting anything."
3277 (anything-execute-persistent-action 'revert-action
'onewindow
))
3279 (defun anything-buffer-save-and-update (candidate)
3280 (let ((marked (anything-marked-candidates))
3281 (enable-recursive-minibuffers t
))
3282 (loop for buf in marked do
3283 (with-current-buffer (get-buffer buf
)
3285 (anything-force-update)
3286 (anything-c-recenter-window)))
3289 (defun anything-buffer-save-persistent ()
3290 "Save buffer without quitting anything."
3292 (anything-execute-persistent-action 'save-action
'onewindow
))
3295 (defun anything-buffer-run-kill-buffers ()
3296 "Run kill buffer action from `anything-c-source-buffers-list'."
3298 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers
))
3301 (defun anything-buffer-run-grep ()
3302 "Run Grep action from `anything-c-source-buffers-list'."
3304 (anything-c-quit-and-execute-action 'anything-c-grep-buffers
))
3307 (defun anything-buffer-run-zgrep ()
3308 "Run Grep action from `anything-c-source-buffers-list'."
3310 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers
))
3313 (defun anything-buffer-run-query-replace-regexp ()
3314 "Run Query replace regexp action from `anything-c-source-buffers-list'."
3316 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp
))
3319 (defun anything-buffer-run-query-replace ()
3320 "Run Query replace action from `anything-c-source-buffers-list'."
3322 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace
))
3325 (defun anything-buffer-switch-other-window ()
3326 "Run switch to other window action from `anything-c-source-buffers-list'."
3328 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window
))
3331 (defun anything-buffer-switch-other-frame ()
3332 "Run switch to other frame action from `anything-c-source-buffers-list'."
3334 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame
))
3337 (defun anything-buffer-switch-to-elscreen ()
3338 "Run switch to elscreen action from `anything-c-source-buffers-list'."
3340 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen
))
3343 (defun anything-buffer-run-ediff ()
3344 "Run ediff action from `anything-c-source-buffers-list'."
3346 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers
))
3348 (defun anything-buffer-run-ediff-merge ()
3349 "Run ediff action from `anything-c-source-buffers-list'."
3351 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge
))
3353 (defun anything-c-buffers-persistent-kill (buffer)
3354 "Persistent action to kill buffer."
3355 (with-current-buffer (get-buffer buffer
)
3356 (if (and (buffer-modified-p)
3357 (buffer-file-name (current-buffer)))
3360 (kill-buffer buffer
))
3361 (kill-buffer buffer
)))
3362 (anything-delete-current-selection))
3364 (defun anything-c-recenter-window ()
3365 "Make visible current selection by recentering anything window."
3366 (with-anything-window (recenter)))
3368 (defun anything-c-buffers-list-persistent-action (candidate)
3369 (if current-prefix-arg
3370 (anything-c-buffers-persistent-kill candidate
)
3371 (anything-c-switch-to-buffer candidate
)))
3377 ;;; File name history
3378 (defvar anything-c-source-file-name-history
3379 '((name .
"File Name History")
3380 (candidates . file-name-history
)
3381 (match anything-c-match-on-file-name
3382 anything-c-match-on-directory-name
)
3384 ;; (anything 'anything-c-source-file-name-history)
3386 ;;; Files in current dir
3389 (defvar anything-c-source-files-in-current-dir
3390 '((name .
"Files from Current Directory")
3391 (candidates .
(lambda ()
3392 (with-anything-current-buffer
3393 (directory-files (anything-c-current-directory)))))
3394 ;; volatile is not needed, I think.
3396 ;; (anything 'anything-c-source-files-in-current-dir)
3398 (defun anything-c-highlight-files (files)
3399 (loop for i in files
3400 if
(file-directory-p i
)
3401 collect
(propertize (file-name-nondirectory i
)
3402 'face
'anything-ff-directory
3403 'help-echo
(expand-file-name i
))
3405 collect
(propertize (file-name-nondirectory i
)
3406 'face
'anything-ff-file
3407 'help-echo
(expand-file-name i
))))
3409 (defvar anything-c-source-files-in-current-dir
+
3410 '((name .
"Files from Current Directory")
3411 (candidates .
(lambda ()
3412 (with-anything-current-buffer
3413 (directory-files (anything-c-current-directory) t
))))
3414 (candidate-transformer anything-c-highlight-files
)
3415 ;; volatile is not needed, I think.
3417 ;; (anything 'anything-c-source-files-in-current-dir+)
3421 ;;; Anything-find-files - The anything files browser.
3425 (defvar anything-c-find-files-doc-header
" (`C-l': Go to precedent level)"
3426 "*The doc that is inserted in the Name header of a find-files or dired source.")
3427 (defvar anything-ff-auto-update-flag nil
3428 "Internal, flag to turn on/off auto-update in `anything-find-files'.
3429 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
3430 (defvar anything-ff-last-expanded nil
3431 "Store last expanded directory or file.")
3432 (defvar anything-ff-default-directory nil
)
3433 (defvar anything-ff-history nil
)
3434 (defvar anything-ff-cand-to-mark nil
)
3437 (defvar anything-c-source-find-files
3438 `((name .
"Find Files")
3439 (header-name .
(lambda (name)
3440 (concat name anything-c-find-files-doc-header
)))
3441 ;; It is needed for filenames with capital letters
3444 (setq anything-ff-auto-update-flag
3445 anything-ff-auto-update-initial-value
)))
3446 (candidates . anything-find-files-get-candidates
)
3447 (filtered-candidate-transformer anything-c-find-files-transformer
)
3448 (image-action1 . anything-ff-rotate-image-left
)
3449 (image-action2 . anything-ff-rotate-image-right
)
3450 (toggle-basename . anything-ff-toggle-basename
)
3451 (properties-action . anything-ff-properties
)
3452 (toggle-auto-update . anything-ff-toggle-auto-update
)
3453 (kill-buffer-fname . anything-ff-kill-buffer-fname
)
3454 (persistent-action . anything-find-files-persistent-action
)
3455 (persistent-help .
"Hit1 Expand Candidate, Hit2 or (C-u) Find file")
3456 (mode-line . anything-ff-mode-line-string
)
3458 (candidate-number-limit .
9999)
3459 (action-transformer . anything-find-files-action-transformer
)
3463 `(("Find File" . anything-c-find-file-or-marked
)
3464 ("Find file in Dired" . anything-c-point-file-in-dired
)
3465 ,(and (locate-library "elscreen")
3466 '("Find file in Elscreen" . anything-elscreen-find-file
))
3467 ,(and (locate-library "popwin")
3468 '("Find file in popup window" . popwin
:find-file
))
3469 ("Checksum File" . anything-ff-checksum
)
3470 ("Complete at point `M-tab'"
3471 . anything-c-insert-file-name-completion-at-point
)
3472 ("Open file externally `C-c C-x, C-u to choose'"
3473 . anything-c-open-file-externally
)
3474 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep
)
3475 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep
)
3476 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell
)
3477 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select
)
3478 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
3479 . anything-find-files-eshell-command-on-file
)
3480 ("Find file as root" . anything-find-file-as-root
)
3481 ("Find file in hex dump" . hexl-find-file
)
3482 ("Ediff File `C-='" . anything-find-files-ediff-files
)
3483 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files
)
3484 ("Delete File(s) `M-D'" . anything-delete-marked-files
)
3485 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy
)
3486 ("Copy file(s) Async" . anything-ff-copy-async
)
3487 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename
)
3488 ("Serial rename files" . anything-ff-serial-rename
)
3489 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink
)
3490 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying
)
3491 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink
)
3492 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink
)
3493 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink
)
3494 ("Find file other window `C-o'" . find-file-other-window
)
3495 ("Switch to history `M-p'" . anything-find-files-switch-to-hist
)
3496 ("Find file other frame `C-c C-o'" . find-file-other-frame
)
3497 ("Print File `C-c p'" . anything-ff-print
)
3498 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate
))))))
3499 ;; (anything 'anything-c-source-find-files)
3501 (defun anything-find-files-set-prompt-for-action (prompt files
)
3502 "Set prompt for action in `anything-find-files'."
3503 (let ((len (length files
)))
3505 (format "%s * %d Files to: " prompt len
)
3506 (format "%s %s to: " prompt
(car files
)))))
3508 (defun anything-dwim-target-directory ()
3509 "Return value of `default-directory' of buffer in other window.
3510 If there is only one window return the value ot `default-directory'
3511 for current buffer."
3512 (with-anything-current-buffer
3513 (let ((num-windows (length (window-list))))
3514 (if (> num-windows
1)
3515 (save-window-excursion
3518 (car anything-ff-history
)))))
3520 (defun anything-find-files-do-action (action)
3521 "Generic function for creating action from `anything-c-source-find-files'.
3522 ACTION must be an action supported by `anything-dired-action'."
3523 (let* ((ifiles (mapcar 'expand-file-name
; Allow modify '/foo/.' -> '/foo'
3524 (anything-marked-candidates)))
3525 (cand (anything-get-selection)) ; Target
3526 (prompt (anything-find-files-set-prompt-for-action
3527 (capitalize (symbol-name action
)) ifiles
))
3528 (parg anything-current-prefix-arg
)
3529 (dest (anything-c-read-file-name
3531 :preselect
(if anything-ff-transformer-show-only-basename
3532 (anything-c-basename cand
) cand
)
3533 :initial-input
(anything-dwim-target-directory)
3534 :history
(anything-find-files-history :comp-read nil
)))
3535 (win-conf (current-window-configuration)))
3537 (let ((default-directory anything-ff-default-directory
))
3538 (anything-dired-action
3539 dest
:files ifiles
:action action
:follow parg
))
3540 ;; Don't reset win-conf when following.
3541 (unless parg
(set-window-configuration win-conf
)))))
3543 (defun anything-find-files-copy (candidate)
3544 "Copy files from `anything-find-files'."
3545 (anything-find-files-do-action 'copy
))
3547 (defun anything-find-files-rename (candidate)
3548 "Rename files from `anything-find-files'."
3549 (anything-find-files-do-action 'rename
))
3551 (defun anything-find-files-symlink (candidate)
3552 "Symlink files from `anything-find-files'."
3553 (anything-find-files-do-action 'symlink
))
3555 (defun anything-find-files-relsymlink (candidate)
3556 "Relsymlink files from `anything-find-files'."
3557 (anything-find-files-do-action 'relsymlink
))
3559 (defun anything-find-files-hardlink (candidate)
3560 "Hardlink files from `anything-find-files'."
3561 (anything-find-files-do-action 'hardlink
))
3563 (defun anything-find-files-byte-compile (candidate)
3564 "Byte compile elisp files from `anything-find-files'."
3565 (let ((files (anything-marked-candidates))
3566 (parg anything-current-prefix-arg
))
3567 (loop for fname in files
3568 do
(byte-compile-file fname parg
))))
3570 (defun anything-find-files-load-files (candidate)
3571 "Load elisp files from `anything-find-files'."
3572 (let ((files (anything-marked-candidates)))
3573 (loop for fname in files
3576 (defun anything-find-files-ediff-files-1 (candidate &optional merge
)
3577 "Generic function to ediff/merge files in `anything-find-files'."
3578 (let ((bname (anything-c-basename candidate
))
3579 (prompt (if merge
"Ediff Merge `%s' With File: "
3580 "Ediff `%s' With File: "))
3581 (fun (if merge
'ediff-merge-files
'ediff-files
)))
3584 (condition-case quit
3585 (anything-c-read-file-name
3586 (format prompt bname
))
3588 (if (y-or-n-p "Search file for ediff with locate? ")
3589 (anything-c-locate-read-file-name
3590 (format prompt bname
) (concat bname
" -b"))
3591 (error "Error: Ediff Operation aborted")))))))
3593 (defun anything-find-files-ediff-files (candidate)
3594 (anything-find-files-ediff-files-1 candidate
))
3596 (defun anything-find-files-ediff-merge-files (candidate)
3597 (anything-find-files-ediff-files-1 candidate
'merge
))
3599 (defun anything-find-files-grep (candidate)
3600 "Default action to grep files from `anything-find-files'."
3601 (anything-do-grep-1 (anything-marked-candidates)
3602 anything-current-prefix-arg
))
3604 (defun anything-ff-zgrep (candidate)
3605 "Default action to zgrep files from `anything-find-files'."
3606 (let ((prefarg anything-current-prefix-arg
)
3607 (ls (anything-marked-candidates)))
3608 (anything-ff-zgrep-1 ls prefarg
)))
3610 (defun anything-ff-pdfgrep (candidate)
3611 "Default action to pdfgrep files from `anything-find-files'."
3612 (let ((cands (loop for file in
(anything-marked-candidates)
3613 if
(or (string= (file-name-extension file
) "pdf")
3614 (string= (file-name-extension file
) "PDF"))
3616 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init
))
3618 (anything-do-pdfgrep-1 cands
))))
3620 (defun anything-ff-etags-select (candidate)
3621 "Default action to jump to etags from `anything-find-files'."
3622 (when (get-buffer anything-action-buffer
)
3623 (kill-buffer anything-action-buffer
))
3624 (let ((default-directory anything-ff-default-directory
))
3625 (anything-c-etags-select anything-current-prefix-arg
)))
3627 (defun anything-find-files-switch-to-hist (candidate)
3628 "Switch to anything-find-files history."
3629 (anything-find-files t
))
3631 ;;; Asynchronous copy of files.
3634 (defun anything-c-copy-files-async-1 (flist dest
)
3635 "Copy a list of Files FLIST to DEST asynchronously.
3636 It use another emacs process to do the job.
3637 Communication with background emacs is done with temp file
3638 `anything-c-copy-files-async-log-file'."
3639 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3640 "-Q" "--batch" "--eval"
3642 (require 'dired) (require 'cl)
3643 (let ((dired-recursive-copies 'always)
3649 (let ((file-exists (file-exists-p
3651 (file-name-nondirectory (directory-file-name f))
3652 (file-name-directory
3653 (file-name-as-directory \"%s\"))))))
3654 (dired-copy-file f \"%s\" t)
3656 (progn (push (cons \"Overwriting\" f) success)
3658 (push (cons \"Copying\" f) success)
3661 (push (dired-make-relative
3663 (file-name-nondirectory (directory-file-name f))
3664 (file-name-directory \"%s\")))
3666 (with-current-buffer (find-file-noselect \"%s\")
3669 (dolist (fail (reverse failures))
3670 (insert (concat \"Failed to copy \" fail \"\n\"))))
3672 (loop for (a . s) in (reverse success) do
3673 (insert (concat a \" \" s \" to %s done\n\"))))
3674 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3675 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3676 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3678 flist dest dest dest anything-c-copy-files-async-log-file dest
)))
3680 (defun anything-c-copy-async-with-log (flist dest
)
3681 "Copy file list FLIST to DEST showing log.
3682 Log is send to `anything-c-copy-files-async-log-file'.
3683 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3684 (declare (special auto-revert-interval
))
3685 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file
))
3686 (set (make-local-variable 'auto-revert-interval
) 1)
3688 (insert "Wait copying files...\n")
3689 (sit-for 0.5) (save-buffer)
3690 (goto-char (point-max))
3691 (auto-revert-mode 1)
3692 (anything-c-copy-files-async-1 flist dest
))
3694 (defun anything-ff-copy-async (candidate)
3695 "Anything find files action to copy files async.
3696 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3697 (let ((flist (anything-marked-candidates))
3698 (dest (anything-c-read-file-name
3699 "Copy File(s) async To: "
3700 :preselect candidate
3701 :initial-input
(car anything-ff-history
)
3702 :history
(anything-find-files-history :comp-read nil
))))
3703 (anything-c-copy-async-with-log flist dest
)))
3705 (defvar eshell-command-aliases-list nil
)
3706 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map
)
3707 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3709 Basename of CANDIDATE can be a wild-card.
3710 If MAP is given run `eshell-command' on all marked files at once,
3711 Otherwise, run `eshell-command' on each marked files.
3713 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3714 `eshell-command-aliases-list' will not be loaded first time you use this."
3715 (when (or eshell-command-aliases-list
3716 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3717 (and eshell-command-aliases-list
(eshell-read-aliases-list))
3718 (let* ((cand-list (anything-marked-candidates))
3719 (default-directory (or anything-ff-default-directory
3720 ;; If candidate is an url *-ff-default-directory is nil
3721 ;; so keep value of default-directory.
3723 (command (anything-comp-read
3725 (loop for
(a . c
) in eshell-command-aliases-list
3726 when
(string-match "\\(\\$1\\|\\$\\*\\)$" (car c
))
3727 collect
(propertize a
'help-echo
(car c
)) into ls
3728 finally return
(sort ls
'string
<))))
3729 (com-value (car (assoc-default command eshell-command-aliases-list
))))
3730 (if (and (or map
(and com-value
(string-match "\\$\\*$" com-value
)))
3731 (> (length cand-list
) 1))
3732 ;; Run eshell-command with ALL marked files as arguments.
3733 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list
" ")))
3734 (eshell-command (format "%s %s" command mapfiles
)))
3735 ;; Run eshell-command on EACH marked files.
3738 for bn
= (anything-c-basename i
)
3739 for files
= (if (and bn
(string-match "^\*" bn
))
3740 ;; Assume if fname is a wildcard
3741 ;; cand-list have a length of 1.
3743 'shell-quote-argument
3744 (file-expand-wildcards i t
) " ")
3746 for com
= (if (string-match "'%s'\\|\"%s\"\\|%s" command
)
3747 ;; This allow to enter other args AFTER filename
3748 ;; i.e <command %s some_more_args>
3749 (format command files
)
3750 (format "%s %s" command files
))
3751 do
(eshell-command com
))))))
3753 (defun anything-find-files-eshell-command-on-file (candidate)
3754 "Run `eshell-command' on CANDIDATE or marked candidates.
3755 See `anything-find-files-eshell-command-on-file-1' for more info."
3756 (anything-find-files-eshell-command-on-file-1
3757 candidate anything-current-prefix-arg
))
3759 (defun anything-ff-switch-to-eshell (candidate)
3760 "Switch to eshell and cd to `anything-ff-default-directory'."
3761 (flet ((cd-eshell ()
3762 (goto-char (point-max))
3764 (format "cd '%s'" anything-ff-default-directory
))
3765 (eshell-send-input)))
3766 (if (get-buffer "*eshell*")
3768 (anything-c-switch-to-buffer "*eshell*")
3770 (call-interactively 'eshell
)
3773 (defun anything-ff-serial-rename-action (method)
3774 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3775 See `anything-ff-serial-rename-1'."
3776 (let ((cands (anything-marked-candidates))
3777 (name (read-string "NewName: "))
3778 (start (read-number "StartAtNumber: "))
3779 (dir (expand-file-name
3780 (anything-c-read-file-name
3781 "Serial Rename to directory: " :initial-input
3782 (expand-file-name anything-ff-default-directory
)))))
3783 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3784 (length cands
) dir name
))
3785 (anything-ff-serial-rename-1 dir cands name start
:method method
)
3786 (anything-find-files-1 dir
))))
3788 (defun anything-ff-member-directory-p (file directory
)
3789 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file
))))
3790 (cur-dir (expand-file-name (file-name-as-directory directory
))))
3791 (string= dir-file cur-dir
)))
3793 (defun* anything-ff-serial-rename-1
3794 (directory collection new-name start-at-num
&key
(method 'rename
))
3795 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3796 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3797 METHOD can be one of rename, copy or symlink.
3798 Files will be renamed if they are files of current directory, otherwise they
3799 will be treated with METHOD.
3800 Default METHOD is rename."
3801 ;; Maybe remove directories selected by error in collection.
3802 (setq collection
(remove-if 'file-directory-p collection
))
3803 (flet ((symlink-file (file dest
)
3804 (let ((flist (list file
)))
3805 (anything-dired-action
3806 dest
:action
'symlink
:files flist
))))
3808 (let* ((tmp-dir (file-name-as-directory
3809 (concat (file-name-as-directory directory
)
3810 (symbol-name (gensym "tmp")))))
3813 (symlink 'symlink-file
)
3814 (rename 'rename-file
)
3815 (t (error "Error: Unknow method %s" method
)))))
3816 (make-directory tmp-dir
)
3817 (loop for i in collection
3818 for count from start-at-num
3819 for fnum
= (if (< count
10) "0%s" "%s")
3820 for nname
= (concat tmp-dir new-name
(format fnum count
)
3821 (file-name-extension i
'dot
))
3822 do
(if (anything-ff-member-directory-p i directory
)
3823 (rename-file i nname
)
3824 (funcall fn i nname
)))
3825 (loop with dirlist
= (directory-files
3826 tmp-dir t directory-files-no-dot-files-regexp
)
3828 (if (file-symlink-p f
)
3829 (symlink-file (file-truename f
)
3830 (concat (file-name-as-directory directory
)
3831 (anything-c-basename f
)))
3832 (rename-file f directory
)))
3833 (delete-directory tmp-dir t
))))
3835 (defun anything-ff-serial-rename (candidate)
3836 "Serial rename all marked files to `anything-ff-default-directory'.
3837 Rename only file of current directory, and symlink files coming from
3839 See `anything-ff-serial-rename-1'."
3840 (anything-ff-serial-rename-action 'rename
))
3842 (defun anything-ff-serial-rename-by-symlink (candidate)
3843 "Serial rename all marked files to `anything-ff-default-directory'.
3844 Rename only file of current directory, and symlink files coming from
3846 See `anything-ff-serial-rename-1'."
3847 (anything-ff-serial-rename-action 'symlink
))
3849 (defun anything-ff-serial-rename-by-copying (candidate)
3850 "Serial rename all marked files to `anything-ff-default-directory'.
3851 Rename only file of current directory, and copy files coming from
3853 See `anything-ff-serial-rename-1'."
3854 (anything-ff-serial-rename-action 'copy
))
3856 (defun anything-c-quit-and-execute-action (action)
3857 "Quit current anything session and execute ACTION."
3858 (setq anything-saved-action action
)
3859 (anything-exit-minibuffer))
3861 (defun anything-ff-toggle-auto-update (candidate)
3862 (setq anything-ff-auto-update-flag
(not anything-ff-auto-update-flag
))
3863 (message "[Auto expansion %s]"
3864 (if anything-ff-auto-update-flag
"enabled" "disabled")))
3867 (defun anything-ff-run-toggle-auto-update ()
3869 (anything-execute-persistent-action 'toggle-auto-update
))
3872 (defun anything-ff-run-switch-to-history ()
3873 "Run Switch to history action from `anything-c-source-find-files'."
3875 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist
))
3878 (defun anything-ff-run-grep ()
3879 "Run Grep action from `anything-c-source-find-files'."
3881 (anything-c-quit-and-execute-action 'anything-find-files-grep
))
3884 (defun anything-ff-run-pdfgrep ()
3885 "Run Pdfgrep action from `anything-c-source-find-files'."
3887 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep
))
3890 (defun anything-ff-run-zgrep ()
3891 "Run Grep action from `anything-c-source-find-files'."
3893 (anything-c-quit-and-execute-action 'anything-ff-zgrep
))
3896 (defun anything-ff-run-copy-file ()
3897 "Run Copy file action from `anything-c-source-find-files'."
3899 (anything-c-quit-and-execute-action 'anything-find-files-copy
))
3902 (defun anything-ff-run-rename-file ()
3903 "Run Rename file action from `anything-c-source-find-files'."
3905 (anything-c-quit-and-execute-action 'anything-find-files-rename
))
3908 (defun anything-ff-run-byte-compile-file ()
3909 "Run Byte compile file action from `anything-c-source-find-files'."
3911 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile
))
3914 (defun anything-ff-run-load-file ()
3915 "Run Load file action from `anything-c-source-find-files'."
3917 (anything-c-quit-and-execute-action 'anything-find-files-load-files
))
3920 (defun anything-ff-run-eshell-command-on-file ()
3921 "Run eshell command on file action from `anything-c-source-find-files'."
3923 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file
))
3926 (defun anything-ff-run-ediff-file ()
3927 "Run Ediff file action from `anything-c-source-find-files'."
3929 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files
))
3932 (defun anything-ff-run-ediff-merge-file ()
3933 "Run Ediff merge file action from `anything-c-source-find-files'."
3935 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files
))
3938 (defun anything-ff-run-symlink-file ()
3939 "Run Symlink file action from `anything-c-source-find-files'."
3941 (anything-c-quit-and-execute-action 'anything-find-files-symlink
))
3944 (defun anything-ff-run-delete-file ()
3945 "Run Delete file action from `anything-c-source-find-files'."
3947 (anything-c-quit-and-execute-action 'anything-delete-marked-files
))
3950 (defun anything-ff-run-complete-fn-at-point ()
3951 "Run complete file name action from `anything-c-source-find-files'."
3953 (anything-c-quit-and-execute-action
3954 'anything-c-insert-file-name-completion-at-point
))
3957 (defun anything-ff-run-switch-to-eshell ()
3958 "Run switch to eshell action from `anything-c-source-find-files'."
3960 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell
))
3963 (defun anything-ff-run-switch-other-window ()
3964 "Run switch to other window action from `anything-c-source-find-files'."
3966 (anything-c-quit-and-execute-action 'find-file-other-window
))
3969 (defun anything-ff-run-switch-other-frame ()
3970 "Run switch to other frame action from `anything-c-source-find-files'."
3972 (anything-c-quit-and-execute-action 'find-file-other-frame
))
3975 (defun anything-ff-run-open-file-externally ()
3976 "Run open file externally command action from `anything-c-source-find-files'."
3978 (anything-c-quit-and-execute-action 'anything-c-open-file-externally
))
3980 (defun anything-ff-locate (candidate)
3981 "Locate action function for `anything-find-files'."
3982 (let ((input (concat (anything-c-basename
3985 anything-ff-default-directory
))
3986 ;; The locate '-b' option doesn't exists
3988 (unless (and (eq system-type
'windows-nt
)
3989 (string-match "^es" anything-c-locate-command
))
3991 (anything-mp-highlight-delay 0.7))
3992 (anything-locate-1 anything-current-prefix-arg input
)))
3995 (defun anything-ff-run-locate ()
3996 "Run locate action from `anything-c-source-find-files'."
3998 (anything-c-quit-and-execute-action 'anything-ff-locate
))
4001 (defun anything-ff-run-gnus-attach-files ()
4002 "Run gnus attach files command action from `anything-c-source-find-files'."
4004 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files
))
4007 (defun anything-ff-run-etags ()
4008 "Run Etags command action from `anything-c-source-find-files'."
4010 (anything-c-quit-and-execute-action 'anything-ff-etags-select
))
4013 (defun anything-ff-print (candidate)
4014 "Print marked files.
4015 You have to set in order
4016 variables `lpr-command',`lpr-switches' and/or `printer-name'.
4019 \(setq lpr-command \"gtklp\"\)
4020 \(setq lpr-switches '(\"-P\")\)
4021 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
4023 Same as `dired-do-print' but for anything."
4024 (let* ((file-list (anything-marked-candidates))
4025 (len (length file-list
))
4026 (printer-name (if anything-ff-printer-list
4028 "Printer: " anything-ff-printer-list
)
4030 (command (read-string
4031 (format "Print *%s File(s):\n%s with: "
4034 (lambda (f) (format "- %s\n" f
))
4036 (when (and lpr-command
4039 (mapconcat 'identity
4041 (append (if (stringp lpr-switches
)
4044 (list printer-name
)))
4046 (file-args (mapconcat #'(lambda (x)
4049 (cmd-line (concat command
" " file-args
)))
4051 (start-process-shell-command "anything-print" nil cmd-line
)
4052 (error "Error: Please verify your printer settings in Emacs."))))
4055 (defun anything-ff-run-print-file ()
4056 "Run Print file action from `anything-c-source-find-files'."
4058 (anything-c-quit-and-execute-action 'anything-ff-print
))
4060 (defun* anything-ff-checksum
(file)
4061 "Calculate the checksum of FILE with completion on algorithms to use.
4062 The checksum is copied to kill-ring."
4063 (let ((algo-list '(md5 sha1 sha224 sha256 sha384 sha512
)))
4065 (secure-hash (intern
4067 "Algorithm: " algo-list
))
4069 (message "Checksum copied to kill-ring.")))
4071 (defun anything-ff-toggle-basename (candidate)
4072 (setq anything-ff-transformer-show-only-basename
4073 (not anything-ff-transformer-show-only-basename
))
4075 (anything-force-update)))
4077 (defun anything-ff-run-toggle-basename ()
4079 (anything-execute-persistent-action 'toggle-basename
))
4081 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
4082 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
4083 If LEVEL is positive reduce from end else from beginning.
4084 If UNIX-CLOSE is non--nil close filename with /.
4085 If EXPAND is non--nil expand-file-name."
4086 (let* ((exp-fname (expand-file-name fname
))
4087 (fname-list (split-string (if (or (string= fname
"~/") expand
)
4088 exp-fname fname
) "/" t
))
4089 (len (length fname-list
))
4090 (pop-list (if (< level
0)
4091 (subseq fname-list
(* level -
1))
4092 (subseq fname-list
0 (- len level
))))
4093 (result (mapconcat 'identity pop-list
"/"))
4094 (empty (string= result
"")))
4095 (when unix-close
(setq result
(concat result
"/")))
4096 (if (string-match "^~" result
)
4097 (if (string= result
"~/") "~/" result
)
4099 (if empty
"../" (concat "../" result
))
4100 (cond ((eq system-type
'windows-nt
)
4101 (if empty
"c:/" result
))
4104 (concat "/" result
)))))))
4106 (defun anything-file-completion-source-p ()
4107 "Test if current source is a dired or find-files source."
4108 (let ((ff-sources '("Find Files" "Copy Files"
4109 "Read File Name History"
4110 "Rename Files" "Symlink Files"
4111 "Hardlink Files" "Write File"
4112 "Insert File" "Read file name"))
4113 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
4114 (loop for i in ff-sources thereis
(string= cur-source i
))))
4116 (defun anything-find-files-down-one-level (arg)
4117 "Go down one level like unix command `cd ..'.
4118 If prefix numeric arg is given go ARG level down."
4120 (with-anything-window
4121 (setq anything-follow-mode nil
))
4122 ;; When going to precedent level we want to be at the line
4123 ;; corresponding to actual directory, so store this info
4124 ;; in `anything-ff-last-expanded'.
4125 (if (and (not (file-directory-p anything-pattern
))
4126 (file-exists-p anything-pattern
))
4127 (setq anything-ff-last-expanded anything-pattern
)
4128 (setq anything-ff-last-expanded anything-ff-default-directory
))
4129 (when (anything-file-completion-source-p)
4130 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
4131 :unix-close t
:expand t
)))
4132 (anything-set-pattern new-pattern
))))
4134 (defun anything-ff-retrieve-last-expanded ()
4135 "Move overlay to last visited directory `anything-ff-last-expanded'.
4136 This happen after using `anything-find-files-down-one-level',
4137 or hitting C-z on \"..\"."
4138 (when (and anything-ff-last-expanded
4139 (anything-file-completion-source-p))
4140 (let ((dirname (if anything-ff-transformer-show-only-basename
4141 (anything-c-basename
4142 (directory-file-name anything-ff-last-expanded
))
4143 (directory-file-name anything-ff-last-expanded
))))
4144 (with-anything-window
4145 (when (or (re-search-forward (concat dirname
"$") nil t
)
4147 (concat anything-ff-last-expanded
"$") nil t
))
4149 (anything-mark-current-line)))
4150 (setq anything-ff-last-expanded nil
))))
4151 (add-hook 'anything-after-update-hook
'anything-ff-retrieve-last-expanded
)
4153 ;; Auto-update - anything-find-files auto expansion of directories.
4155 (defun anything-ff-update-when-only-one-matched ()
4156 "Expand to directory when sole completion.
4157 When only one candidate is remaining and it is a directory,
4158 expand to this directory."
4159 (let ((history-p (string= (assoc-default
4160 'name
(anything-get-current-source))
4161 "Read File Name History"))
4162 (completed-p (string= (file-name-as-directory anything-pattern
)
4163 anything-ff-default-directory
)))
4164 (when (and anything-ff-auto-update-flag
4165 (or (and (anything-file-completion-source-p)
4166 (<= (anything-approximate-candidate-number) 2)
4167 (>= (length (anything-c-basename anything-pattern
)) 2))
4170 (with-anything-window
4171 (and (not completed-p
) (anything-next-line))
4172 (let ((cur-cand (anything-get-selection)))
4173 (when (file-directory-p cur-cand
)
4174 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand
)) ; [1]
4175 ;; Maybe we are here because completed-p is true
4176 ;; So check this again to be sure.
4177 ;; (this happen only on windows dirs)
4178 (<= (anything-approximate-candidate-number) 2)) ; [2]
4179 ;; If after going to next line the candidate is not "." or ".." [1]
4180 ;; and only one candidate is remaining [2],
4181 ;; assume candidate is a new directory to expand, and do it.
4182 (anything-set-pattern (file-name-as-directory cur-cand
))
4183 ;; The candidate is one of "." or ".." (it should be "..").
4184 ;; that mean we have entered the last letter of the directory name
4185 ;; in prompt, so expansion is already done, just add the "/" at end
4186 ;; of name unless anything-pattern ends with "."
4187 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern
)
4188 (anything-set-pattern (file-name-as-directory anything-pattern
))))
4189 (anything-check-minibuffer-input-1)))))))
4190 (add-hook 'anything-after-update-hook
'anything-ff-update-when-only-one-matched
)
4192 ;; Allow expanding to home directory or root
4193 ;; when entering respectively "~/" or "//" at end of pattern.
4194 ;; e.g /home/thierry/labo/anything-config-qp/~/
4195 ;; will expand to "~/"
4196 ;; and /home/thierry/labo/anything-config-qp//
4197 ;; will expand to "/"
4198 (defun anything-ff-auto-expand-to-home-or-root ()
4199 "Goto home or root directory when adding ~/ or / at end of pattern.
4200 This happen only in function using sources that are
4201 `anything-file-completion-source-p' compliant."
4202 (when (and (anything-file-completion-source-p)
4203 (string-match ".*\\(/~/\\|/\\{2\\}\\)$" anything-pattern
))
4204 (let ((match (match-string 1 anything-pattern
)))
4205 (cond ((string= match
"//")
4206 (if (eq system-type
'windows-nt
)
4207 (setq anything-pattern
"c:/")
4208 (setq anything-pattern
"/")))
4209 ((string= match
"/~/")
4210 (if (eq system-type
'windows-nt
)
4211 (setq anything-pattern
(file-name-as-directory (getenv "HOME")))
4212 (setq anything-pattern
"~/")))))
4213 (setq anything-ff-default-directory anything-pattern
)
4214 ;; For some reasons, i must use here with-current-buffer => mini buffer
4215 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
4216 (with-current-buffer (window-buffer (minibuffer-window))
4217 (delete-minibuffer-contents)
4218 (insert anything-pattern
))))
4220 (add-hook 'anything-after-update-hook
'anything-ff-auto-expand-to-home-or-root
)
4222 (defun anything-c-point-file-in-dired (file)
4223 "Put point on filename FILE in dired buffer."
4224 (dired (file-name-directory file
))
4225 (dired-goto-file file
))
4227 (defun anything-create-tramp-name (fname)
4228 "Build filename for `anything-pattern' like /su:: or /sudo::."
4229 (apply #'tramp-make-tramp-file-name
4230 (loop with v
= (tramp-dissect-file-name fname
)
4231 for i across v collect i
)))
4233 (defun anything-ff-set-pattern (pattern)
4234 "Handle tramp filenames in `anything-pattern'."
4235 (let ((methods (mapcar 'car tramp-methods
))
4236 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
4237 cur-method tramp-name
)
4238 (cond ((string= pattern
"") "")
4239 ((string-match ".*\\(~//\\|//\\)$" pattern
)
4240 (if (eq system-type
'windows-nt
) "c:/" "/"))
4241 ((string-match "^~\\|.*/~/$" pattern
)
4242 (let* ((home (getenv "HOME"))
4243 (replace (if (eq system-type
'windows-nt
)
4244 (replace-regexp-in-string
4247 (replace-match replace nil t pattern
)))
4248 ;; Match "/method:maybe_hostname:"
4249 ((and (string-match reg pattern
)
4250 (setq cur-method
(match-string 1 pattern
))
4251 (member cur-method methods
))
4252 (setq tramp-name
(anything-create-tramp-name
4253 (match-string 0 pattern
)))
4254 (replace-match tramp-name nil t pattern
))
4255 ;; Match "/hostname:"
4256 ((and (string-match tramp-file-name-regexp pattern
)
4257 (setq cur-method
(match-string 1 pattern
))
4258 (and cur-method
(not (member cur-method methods
))))
4259 (setq tramp-name
(anything-create-tramp-name
4260 (match-string 0 pattern
)))
4261 (replace-match tramp-name nil t pattern
))
4262 ;; Match "/method:" in this case don't try to connect.
4263 ((and (not (string-match reg pattern
))
4264 (string-match tramp-file-name-regexp pattern
)
4265 (member (match-string 1 pattern
) methods
))
4266 "Invalid tramp file name") ; Write in anything-buffer.
4267 ;; PATTERN is a directory, end it with "/".
4268 ;; This will make PATTERN not ending yet with "/"
4269 ;; candidate for `anything-ff-default-directory',
4270 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
4271 ;; when descending level.
4272 ((file-directory-p pattern
)
4273 (file-name-as-directory pattern
))
4274 ;; Return PATTERN unchanged.
4278 (defun anything-find-files-get-candidates ()
4279 "Create candidate list for `anything-c-source-find-files'."
4280 (let* ((path (anything-ff-set-pattern anything-pattern
))
4281 (path-name-dir (if (file-directory-p path
)
4282 (file-name-as-directory path
)
4283 (file-name-directory path
)))
4284 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
4285 (set-text-properties 0 (length path
) nil path
)
4286 (setq anything-pattern
(anything-ff-transform-fname-for-completion path
))
4287 (setq anything-ff-default-directory
4288 (if (string= anything-pattern
"")
4289 (if (eq system-type
'windows-nt
) "c:/" "/")
4290 (unless (string-match ffap-url-regexp path
)
4292 (cond ((or (string= path
"Invalid tramp file name")
4293 (file-regular-p path
)
4294 (and (not (file-exists-p path
)) (string-match "/$" path
))
4295 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
4297 ((string= path
"") (directory-files "/" t
))
4298 ((and (file-directory-p path
) (not (file-readable-p path
)))
4299 (list (format "Opening directory: access denied, `%s'" path
)))
4300 ((file-directory-p path
) (directory-files path t
))
4302 (append (list path
) (directory-files path-name-dir t
))))))
4304 (defun anything-ff-transform-fname-for-completion (fname)
4305 "Return FNAME with it's basename modified as a regexp.
4306 e.g foo => f.*o.*o .
4307 If basename contain one or more space or FNAME is a valid directory name
4308 return FNAME unchanged."
4309 (let ((bn (anything-c-basename fname
)))
4310 (if (or (not anything-ff-smart-completion
)
4311 (string-match "\\s-" bn
)
4312 (string-match "/$" fname
) ; Allow mkdir.
4313 (file-directory-p fname
))
4314 fname
; Fall back to match-plugin.
4315 (setq bn
(if (> (length bn
) 2) ; Normal completion on first 2 char.
4316 (mapconcat 'identity
(split-string bn
"" t
) ".*") bn
))
4317 (concat (file-name-directory fname
) bn
))))
4319 (defun anything-ff-save-history ()
4320 "Store the last value of `anything-ff-default-directory' \
4321 in `anything-ff-history'."
4322 (when (and anything-ff-default-directory
4323 (anything-file-completion-source-p))
4324 (push anything-ff-default-directory anything-ff-history
)))
4325 (add-hook 'anything-cleanup-hook
'anything-ff-save-history
)
4327 (defun anything-ff-valid-symlink-p (file)
4328 (file-exists-p (file-truename file
)))
4330 (defun anything-ff-properties (candidate)
4331 "Show file properties of CANDIDATE in a tooltip or message."
4332 (let ((type (anything-ff-attributes candidate
:type t
))
4333 (dired-line (anything-ff-attributes candidate
:dired t
:human-size t
)))
4337 (anything-c-basename candidate
) ": \n"
4339 (when (string= type
"symlink")
4340 (format "True name: '%s'\n"
4341 (cond ((string-match "^\.#" (anything-c-basename candidate
))
4343 ((anything-ff-valid-symlink-p candidate
)
4344 (file-truename candidate
))
4345 (t "Invalid Symlink"))))
4347 (message dired-line
) (sit-for 5))))
4350 (defun anything-ff-properties-persistent ()
4351 "Show properties without quitting anything."
4353 (anything-execute-persistent-action 'properties-action
))
4355 (defun anything-ff-kill-buffer-fname (candidate)
4356 (let* ((buf (get-file-buffer candidate
))
4357 (buf-name (buffer-name buf
)))
4360 (kill-buffer buf
) (message "Buffer `%s' killed" buf
))
4361 (message "No buffer to kill"))))
4363 (defun anything-ff-kill-or-find-buffer-fname (candidate)
4364 "Find file CANDIDATE or kill it's buffer if it is visible.
4365 Never kill `anything-current-buffer'.
4366 Never kill buffer modified.
4367 This is called normally on third hit of \
4368 \\<anything-map>\\[anything-execute-persistent-action]
4369 in `anything-find-files-persistent-action'."
4370 (let* ((buf (get-file-buffer candidate
))
4371 (buf-name (buffer-name buf
)))
4372 (if (and buf
(get-buffer-window buf
)
4373 (not (eq buf
(get-buffer anything-current-buffer
)))
4374 (not (buffer-modified-p buf
)))
4376 (kill-buffer buf
) (message "Buffer `%s' killed" buf-name
))
4377 (find-file candidate
))))
4380 (defun anything-ff-run-kill-buffer-persistent ()
4381 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
4383 (anything-execute-persistent-action 'kill-buffer-fname
))
4385 (defun anything-ff-human-size (size)
4386 "Return a string showing SIZE of a file in human readable form.
4387 SIZE can be an integer or a float depending it's value.
4388 `file-attributes' will take care of that to avoid overflow error.
4389 KBSIZE if a floating point number, default value is 1024.0."
4390 (let ((M (cons "M" (/ size
(expt anything-ff-default-kbsize
2))))
4391 (G (cons "G" (/ size
(expt anything-ff-default-kbsize
3))))
4392 (K (cons "K" (/ size anything-ff-default-kbsize
)))
4393 (B (cons "B" size
)))
4394 (loop with result
= B
4396 (loop for
(x . y
) in
(list M G K B
)
4397 unless
(< y
1) collect
(cons x y
))
4398 when
(< b
(cdr result
)) do
(setq result
(cons a b
))
4399 finally return
(if (string= (car result
) "B")
4401 (format "%.1f%s" (cdr result
) (car result
))))))
4403 (defun* anything-ff-attributes
4404 (file &key type links uid gid access-time modif-time
4405 status size mode gid-change inode device-num dired human-size
)
4406 "Easy interface for `file-attributes'."
4407 (let ((all (destructuring-bind
4408 (type links uid gid access-time modif-time
4409 status size mode gid-change inode device-num
)
4410 (file-attributes file
'string
)
4415 :access-time access-time
4416 :modif-time modif-time
4420 :gid-change gid-change
4422 :device-num device-num
))))
4424 (let ((result (getf all
:type
)))
4425 (cond ((stringp result
)
4427 (result "directory")
4429 (links (getf all
:links
))
4430 (uid (getf all
:uid
))
4431 (gid (getf all
:gid
))
4433 (format-time-string "%Y-%m-%d %R" (getf all
:access-time
)))
4435 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
)))
4437 (format-time-string "%Y-%m-%d %R" (getf all
:status
)))
4438 (size (if human-size
(anything-ff-human-size (getf all
:size
))
4440 (mode (getf all
:mode
))
4441 (gid-change (getf all
:gid-change
))
4442 (inode (getf all
:inode
))
4443 (device-num (getf all
:device-num
))
4446 (getf all
:mode
) " "
4447 (number-to-string (getf all
:links
)) " "
4450 (if human-size
(anything-ff-human-size (getf all
:size
))
4451 (int-to-string (getf all
:size
))) " "
4452 (format-time-string "%Y-%m-%d %R" (getf all
:modif-time
))))
4455 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file
)
4456 "Return filename FNAME maybe prefixed with [?] or [@].
4457 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
4458 existing filename or valid symlink and there is no need to test it.
4459 NEW-FILE when non--nil mean FNAME is a non existing file and
4460 return FNAME prefixed with [?]."
4461 (let* ((prefix-new (propertize
4463 (propertize "[?]" 'face
'anything-ff-prefix
)))
4464 (prefix-url (propertize
4466 (propertize "[@]" 'face
'anything-ff-prefix
))))
4467 (cond ((or file-or-symlinkp
(file-exists-p fname
)) fname
)
4468 ((string-match ffap-url-regexp fname
)
4469 (concat prefix-url
" " fname
))
4470 ((or new-file
(not (file-exists-p fname
)))
4471 (concat prefix-new
" " fname
)))))
4473 (defun anything-c-find-files-transformer (files sources
)
4474 "Transformer for `anything-c-source-find-files'.
4475 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
4477 (if (and (string-match tramp-file-name-regexp anything-pattern
)
4478 anything-ff-tramp-not-fancy
)
4479 (if anything-ff-transformer-show-only-basename
4480 (loop for i in files collect
4481 (if (string-match "[.]\\{1,2\\}$" i
)
4482 i
(cons (anything-c-basename i
) i
)))
4484 (anything-ff-highlight-files files sources
)))
4486 (defvar anything-ff-transformer-show-only-basename nil
)
4487 (defun anything-ff-highlight-files (files sources
)
4488 "Candidate transformer for `anything-c-source-find-files' without icons."
4489 (loop for i in files
4490 for disp
= (if (and anything-ff-transformer-show-only-basename
4491 (not (string-match "[.]\\{1,2\\}$" i
))
4492 (not (string-match ffap-url-regexp i
)))
4493 (anything-c-basename i
) i
)
4495 (cond ((and (stringp (car (file-attributes i
)))
4496 (not (anything-ff-valid-symlink-p i
))
4497 (not (string-match "^\.#" (anything-c-basename i
))))
4498 (cons (anything-ff-prefix-filename
4499 (propertize disp
'face
'anything-ff-invalid-symlink
) t
)
4501 ((stringp (car (file-attributes i
)))
4502 (cons (anything-ff-prefix-filename
4503 (propertize disp
'face
'anything-ff-symlink
) t
)
4505 ((eq t
(car (file-attributes i
)))
4506 (cons (anything-ff-prefix-filename
4507 (propertize disp
'face
'anything-ff-directory
) t
)
4509 ((file-executable-p i
)
4510 (cons (anything-ff-prefix-filename
4511 (propertize disp
'face
'anything-ff-executable
) t
)
4514 (cons (anything-ff-prefix-filename
4515 (propertize disp
'face
'anything-ff-file
) t
)
4518 (cons (anything-ff-prefix-filename
4519 (propertize disp
'face
'anything-ff-file
) nil
'new-file
)
4522 (defun anything-find-files-action-transformer (actions candidate
)
4523 "Action transformer for `anything-c-source-find-files'."
4524 (cond ((with-anything-current-buffer
4525 (eq major-mode
'message-mode
))
4526 (append (subseq actions
0 4)
4527 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files
))
4528 (subseq actions
4)))
4529 ((string-match (image-file-name-regexp) candidate
)
4530 (append (subseq actions
0 4)
4531 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right
)
4532 ("Rotate image left `M-l'" . anything-ff-rotate-image-left
))
4533 (subseq actions
4)))
4534 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4535 (car it
) candidate
))
4536 (append (subseq actions
0 4)
4537 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4538 . anything-find-files-byte-compile
)
4539 ("Load File(s) `M-L'" . anything-find-files-load-files
))
4540 (subseq actions
4)))
4541 ((and (string-match "\.html?$" candidate
)
4542 (file-exists-p candidate
))
4543 (append (subseq actions
0 4)
4544 '(("Browse url file" . browse-url-of-file
))
4545 (subseq actions
5)))
4546 ((or (string= (file-name-extension candidate
) "pdf")
4547 (string= (file-name-extension candidate
) "PDF"))
4548 (append (subseq actions
0 4)
4549 '(("Pdfgrep File(s)" . anything-ff-pdfgrep
))
4550 (subseq actions
5)))
4553 (defun anything-ff-gnus-attach-files (candidate)
4554 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4555 (let ((flist (anything-marked-candidates)))
4556 (gnus-dired-attach flist
)))
4558 (defun anything-ff-rotate-current-image-1 (file &optional num-arg
)
4559 "Rotate current image at NUM-ARG degrees.
4560 This is a destructive operation on FILE made by external tool mogrify."
4561 (declare (special image-dired-display-image-buffer
))
4562 (setq file
(file-truename file
)) ; For symlinked images.
4563 ;; When FILE is not an image-file, do nothing.
4564 (when (string-match (image-file-name-regexp) file
)
4565 (if (executable-find "mogrify")
4567 (shell-command (format "mogrify -rotate %s %s"
4569 (shell-quote-argument file
)))
4570 (when (buffer-live-p image-dired-display-image-buffer
)
4571 (kill-buffer image-dired-display-image-buffer
))
4572 (image-dired-display-image file
)
4574 (display-buffer (get-buffer image-dired-display-image-buffer
)))
4575 (error "mogrify not found"))))
4577 (defun anything-ff-rotate-image-left (candidate)
4578 "Rotate image file CANDIDATE left.
4579 This affect directly file CANDIDATE."
4580 (anything-ff-rotate-current-image-1 candidate -
90))
4582 (defun anything-ff-rotate-image-right (candidate)
4583 "Rotate image file CANDIDATE right.
4584 This affect directly file CANDIDATE."
4585 (anything-ff-rotate-current-image-1 candidate
))
4587 (defun anything-ff-rotate-left-persistent ()
4588 "Rotate image left without quitting anything."
4590 (anything-execute-persistent-action 'image-action1
))
4592 (defun anything-ff-rotate-right-persistent ()
4593 "Rotate image right without quitting anything."
4595 (anything-execute-persistent-action 'image-action2
))
4597 (defun anything-ff-exif-data (candidate)
4598 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4599 (if (and anything-ff-exif-data-program
4600 (executable-find anything-ff-exif-data-program
))
4601 (shell-command-to-string (format "%s %s %s"
4602 anything-ff-exif-data-program
4603 anything-ff-exif-data-program-args
4605 (format "No program %s found to extract exif"
4606 anything-ff-exif-data-program
)))
4608 (defun anything-find-files-persistent-action (candidate)
4609 "Open subtree CANDIDATE without quitting anything.
4610 If CANDIDATE is not a directory expand CANDIDATE filename.
4611 If CANDIDATE is alone, open file CANDIDATE filename.
4613 First hit on C-z expand CANDIDATE second hit open file.
4614 If a prefix arg is given or `anything-follow-mode' is on open file."
4615 (let ((follow (buffer-local-value
4616 'anything-follow-mode
4617 (get-buffer-create anything-buffer
)))
4618 (new-pattern (anything-get-selection))
4619 (num-lines-buf (with-current-buffer anything-buffer
4620 (count-lines (point-min) (point-max)))))
4621 (flet ((insert-in-minibuffer (fname)
4622 (with-selected-window (minibuffer-window)
4624 (delete-minibuffer-contents)
4625 (set-text-properties 0 (length fname
) nil fname
)
4627 (cond (;; A symlink directory, expand it's truename.
4628 (and (file-directory-p candidate
) (file-symlink-p candidate
))
4629 (insert-in-minibuffer (file-name-as-directory
4631 (expand-file-name candidate
)))))
4632 ;; A directory, open it.
4633 ((file-directory-p candidate
)
4634 (when (string= (anything-c-basename candidate
) "..")
4635 (setq anything-ff-last-expanded anything-ff-default-directory
))
4636 (insert-in-minibuffer (file-name-as-directory
4637 (expand-file-name candidate
))))
4638 ;; A symlink file, expand to it's true name. (first hit)
4639 ((and (file-symlink-p candidate
) (not current-prefix-arg
) (not follow
))
4640 (insert-in-minibuffer (file-truename candidate
)))
4641 ;; A regular file, expand it, (first hit)
4642 ((and (>= num-lines-buf
3) (not current-prefix-arg
) (not follow
))
4643 (insert-in-minibuffer new-pattern
))
4644 ;; An image file and it is the second hit on C-z,
4645 ;; show the file in `image-dired'.
4646 ((string-match (image-file-name-regexp) candidate
)
4647 (when (buffer-live-p image-dired-display-image-buffer
)
4648 (kill-buffer image-dired-display-image-buffer
))
4649 (image-dired-display-image candidate
)
4651 (anything-c-switch-to-buffer image-dired-display-image-buffer
)
4652 (with-current-buffer image-dired-display-image-buffer
4653 (let ((exif-data (anything-ff-exif-data candidate
)))
4654 (image-dired-update-property 'help-echo exif-data
))))
4655 ;; Allow browsing archive on avfs fs.
4656 ;; Assume volume is already mounted with mountavfs.
4657 ((and anything-ff-avfs-directory
4659 (regexp-quote (expand-file-name anything-ff-avfs-directory
))
4660 (file-name-directory candidate
))
4661 (anything-ff-file-compressed-p candidate
))
4662 (insert-in-minibuffer (concat candidate
"#")))
4663 ;; On second hit we open file.
4664 ;; On Third hit we kill it's buffer maybe.
4666 (anything-ff-kill-or-find-buffer-fname candidate
))))))
4668 (defun anything-ff-file-compressed-p (candidate)
4669 "Whether CANDIDATE is a compressed file or not."
4670 (member (file-name-extension candidate
)
4671 anything-ff-file-compressed-list
))
4673 (defun anything-c-insert-file-name-completion-at-point (candidate)
4674 "Insert file name completion at point."
4675 (with-anything-current-buffer
4676 (if buffer-read-only
4677 (error "Error: Buffer `%s' is read-only" (buffer-name))
4678 (let* ((end (point))
4679 (guess (substring-no-properties (thing-at-point 'filename
)))
4680 (beg (- (point) (length guess
)))
4681 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess
)
4682 (string-match-p "^[^\~]" guess
))))
4683 (set-text-properties 0 (length candidate
) nil candidate
)
4684 (if (and guess
(not (string= guess
""))
4685 (string-match-p "^~\\|/.*" guess
))
4687 (delete-region beg end
)
4688 (insert (if full-path-p
4689 (expand-file-name candidate
)
4690 (abbreviate-file-name candidate
))))
4691 (error "Aborting completion: No valid file name at point"))))))
4693 (defun* anything-find-files-history
(&key
(comp-read t
))
4694 "The `anything-find-files' history.
4695 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
4696 in an `anything-comp-read'."
4697 (let ((history (when anything-ff-history
4698 (loop with dup for i in anything-ff-history
4699 ;; Remove duplicate and not existing files.
4700 ;; Keep remote files.
4701 unless
(or (member i dup
)
4702 (and (not (file-remote-p i
))
4703 (not (file-exists-p i
))))
4705 finally return dup
)))) ; Remove dups.
4707 (setq anything-ff-history
4708 (if (>= (length history
) anything-ff-history-max-length
)
4709 (subseq history
0 anything-ff-history-max-length
)
4713 "Switch to Directory: "
4715 :name
"Anything Find Files History"
4717 anything-ff-history
))))
4719 (defun anything-find-files-1 (fname &optional preselect
)
4720 "Find FNAME with `anything' completion.
4721 Like `find-file' but with `anything' support.
4722 Use it for non--interactive calls of `anything-find-files'."
4723 (when (get-buffer anything-action-buffer
)
4724 (kill-buffer anything-action-buffer
))
4725 (let ((anything-mp-highlight-delay nil
)
4726 ;; Be sure we don't erase the precedent minibuffer if some.
4727 (anything-ff-auto-update-initial-value
4728 (not (minibuffer-window-active-p (minibuffer-window))))
4729 anything-samewindow
)
4730 (anything :sources
'anything-c-source-find-files
4732 :preselect preselect
4733 :keymap anything-find-files-map
4734 :prompt
"Find Files or Url: "
4735 :buffer
"*Anything Find Files*")))
4738 (defun anything-find-files-initial-input (&optional input
)
4739 "Return INPUT if present, otherwise try to guess it."
4740 (or (and input
(expand-file-name input
))
4741 (anything-find-files-input
4743 (thing-at-point 'filename
))))
4745 (defun anything-find-files-input (fap tap
)
4746 "Default input of `anything-find-files'."
4747 (let* ((def-dir (anything-c-current-directory))
4748 (lib (anything-find-library-at-point))
4749 (url (anything-ff-find-url-at-point))
4750 (file-p (and fap
(not (string= fap
""))
4752 tap
(not (string= tap
""))
4754 (file-name-directory (expand-file-name tap def-dir
))))))
4755 (cond (lib) ; e.g we are inside a require sexp.
4756 (url) ; String at point is an hyperlink.
4757 (file-p (expand-file-name tap def-dir
))
4758 (t (and (not (string= fap
"")) fap
)))))
4760 (defun anything-c-current-directory ()
4761 "Return current-directory name at point.
4762 Useful in dired buffers when there is inserted subdirs."
4763 (if (eq major-mode
'dired-mode
)
4764 (dired-current-directory)
4767 (defun anything-ff-find-url-at-point ()
4768 "Try to find link to an url in text-property at point."
4769 (let* ((he (get-text-property (point) 'help-echo
))
4770 (ov (overlays-at (point)))
4771 (ov-he (and ov
(overlay-get
4772 (car (overlays-at (point))) 'help-echo
)))
4773 (w3m-l (get-text-property (point) 'w3m-href-anchor
))
4774 (nt-prop (get-text-property (point) 'nt-link
)))
4776 (when (and (stringp he
) (string-match "^LINK: " he
))
4777 (setq he
(replace-match "" t t he
)))
4778 (loop for i in
(list he ov-he w3m-l nt-prop
)
4779 thereis
(and (stringp i
) (string-match ffap-url-regexp i
) i
))))
4781 (defun anything-find-library-at-point ()
4782 "Try to find library path at point.
4783 Find inside `require' and `declare-function' sexp."
4784 (require 'find-func
)
4785 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
4786 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
4787 (sexp (and beg-sexp end-sexp
4788 (buffer-substring-no-properties
4789 (1+ beg-sexp
) (1- end-sexp
)))))
4791 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
4793 (replace-regexp-in-string
4795 ;; If require use third arg, ignore it,
4796 ;; always use library path found in `load-path'.
4797 (second (split-string (match-string 0 sexp
))))))
4798 ((and sexp
(string-match-p "^declare-function" sexp
))
4800 (replace-regexp-in-string
4802 (third (split-string sexp
)))))
4805 ;;; Anything completion for `write-file'.==> C-x C-w
4806 (defvar anything-c-source-write-file
4807 `((name .
"Write File")
4808 (header-name .
(lambda (name)
4809 (concat name anything-c-find-files-doc-header
)))
4810 ;; It is needed for filenames with capital letters
4812 (candidates . anything-find-files-get-candidates
)
4813 (filtered-candidate-transformer anything-c-find-files-transformer
)
4814 (persistent-action . anything-find-files-persistent-action
)
4815 (persistent-help .
"Expand Candidate")
4818 (("Write File" .
(lambda (candidate)
4819 (write-file candidate
'confirm
)))))))
4821 ;;; Anything completion for `insert-file'.==> C-x i
4822 (defvar anything-c-source-insert-file
4823 `((name .
"Insert File")
4824 (header-name .
(lambda (name)
4825 (concat name anything-c-find-files-doc-header
)))
4826 ;; It is needed for filenames with capital letters
4828 (candidates . anything-find-files-get-candidates
)
4829 (filtered-candidate-transformer anything-c-find-files-transformer
)
4830 (persistent-action . anything-find-files-persistent-action
)
4831 (persistent-help .
"Expand Candidate")
4834 (("Insert File" .
(lambda (candidate)
4835 (when (y-or-n-p (format "Really insert %s in %s "
4836 candidate anything-current-buffer
))
4837 (insert-file-contents candidate
))))))))
4839 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4840 (defvar anything-c-source-copy-files
4841 `((name .
"Copy Files")
4842 (header-name .
(lambda (name)
4843 (concat name anything-c-find-files-doc-header
)))
4844 ;; It is needed for filenames with capital letters
4846 (candidates . anything-find-files-get-candidates
)
4847 (filtered-candidate-transformer anything-c-find-files-transformer
)
4848 (persistent-action . anything-find-files-persistent-action
)
4849 (persistent-help .
"Expand Candidate")
4853 .
(lambda (candidate)
4854 (anything-dired-action candidate
:action
'copy
)))
4856 .
(lambda (candidate)
4857 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
4860 (defvar anything-c-source-rename-files
4861 `((name .
"Rename Files")
4862 (header-name .
(lambda (name)
4863 (concat name anything-c-find-files-doc-header
)))
4864 ;; It is needed for filenames with capital letters
4866 (candidates . anything-find-files-get-candidates
)
4867 (filtered-candidate-transformer anything-c-find-files-transformer
)
4868 (persistent-action . anything-find-files-persistent-action
)
4869 (persistent-help .
"Expand Candidate")
4873 .
(lambda (candidate)
4874 (anything-dired-action candidate
:action
'rename
)))
4875 ("Rename and Follow"
4876 .
(lambda (candidate)
4877 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
4879 (defvar anything-c-source-symlink-files
4880 `((name .
"Symlink Files")
4881 (header-name .
(lambda (name)
4882 (concat name anything-c-find-files-doc-header
)))
4883 ;; It is needed for filenames with capital letters
4885 (candidates . anything-find-files-get-candidates
)
4886 (filtered-candidate-transformer anything-c-find-files-transformer
)
4887 (persistent-action . anything-find-files-persistent-action
)
4888 (persistent-help .
"Expand Candidate")
4892 .
(lambda (candidate)
4893 (anything-dired-action candidate
:action
'symlink
)))
4895 .
(lambda (candidate)
4896 (anything-dired-action candidate
:action
'relsymlink
)))))))
4899 (defvar anything-c-source-hardlink-files
4900 `((name .
"Hardlink Files")
4901 (header-name .
(lambda (name)
4902 (concat name anything-c-find-files-doc-header
)))
4903 ;; It is needed for filenames with capital letters
4905 (candidates . anything-find-files-get-candidates
)
4906 (filtered-candidate-transformer anything-c-find-files-transformer
)
4907 (persistent-action . anything-find-files-persistent-action
)
4908 (persistent-help .
"Expand Candidate")
4912 .
(lambda (candidate)
4913 (anything-dired-action candidate
:action
'hardlink
)))))))
4915 (defun* anything-dired-action
(candidate &key action follow
(files (dired-get-marked-files)))
4916 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4917 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4918 (when (get-buffer dired-log-buffer
) (kill-buffer dired-log-buffer
))
4919 (let ((fn (case action
4920 ('copy
'dired-copy-file
)
4921 ('rename
'dired-rename-file
)
4922 ('symlink
'make-symbolic-link
)
4923 ('relsymlink
'dired-make-relative-symlink
)
4924 ('hardlink
'dired-hardlink
)))
4925 (marker (case action
4926 ((copy rename
) dired-keep-marker-copy
)
4927 ('symlink dired-keep-marker-symlink
)
4928 ('relsymlink dired-keep-marker-relsymlink
)
4929 ('hardlink dired-keep-marker-hardlink
)))
4930 (dirflag (and (= (length files
) 1)
4931 (file-directory-p (car files
))
4932 (not (file-directory-p candidate
)))))
4934 fn
(symbol-name action
) files
4935 ;; CANDIDATE is the destination.
4936 (if (file-directory-p candidate
)
4937 ;; When CANDIDATE is a directory, build file-name in this directory.
4938 ;; Else we use CANDIDATE.
4940 (expand-file-name (file-name-nondirectory from
) candidate
))
4941 #'(lambda (from) candidate
))
4943 (when (and follow
(not (get-buffer dired-log-buffer
)))
4944 (let ((target (directory-file-name candidate
)))
4947 (setq anything-ff-cand-to-mark
4948 (anything-get-dest-fnames-from-list files candidate dirflag
))
4949 (if (and dirflag
(eq action
'rename
))
4950 (anything-find-files-1 (file-name-directory target
)
4951 (if anything-ff-transformer-show-only-basename
4952 (anything-c-basename target
) target
))
4953 (anything-find-files-1 (expand-file-name candidate
))))
4954 (setq anything-ff-cand-to-mark nil
))))))
4957 (defun anything-c-basename (fname)
4958 "Resolve basename of file or directory named FNAME."
4959 (file-name-nondirectory (directory-file-name fname
)))
4961 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag
)
4962 "Transform filenames of FLIST to abs of DEST-CAND.
4963 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4965 ;; At this point files have been renamed/copied at destination.
4966 ;; That's mean DEST-CAND exists.
4968 with dest
= (expand-file-name dest-cand
)
4970 for basename-src
= (anything-c-basename src
)
4971 for fname
= (cond (rename-dir-flag (directory-file-name dest
))
4972 ((file-directory-p dest
)
4973 (concat (file-name-as-directory dest
) basename-src
))
4975 when
(file-exists-p fname
)
4976 collect fname into tmp-list
4977 finally return
(sort tmp-list
'string
<)))
4979 (defun anything-ff-maybe-mark-candidates ()
4980 "Mark all candidates of list `anything-ff-cand-to-mark'."
4981 (when (and (string= (assoc-default 'name
(anything-get-current-source))
4982 (assoc-default 'name anything-c-source-find-files
))
4983 anything-ff-cand-to-mark
)
4984 (with-anything-window
4985 (while anything-ff-cand-to-mark
4986 (if (string= (car anything-ff-cand-to-mark
) (anything-get-selection))
4988 (anything-make-visible-mark)
4989 (anything-next-line)
4990 (setq anything-ff-cand-to-mark
(cdr anything-ff-cand-to-mark
)))
4991 (anything-next-line)))
4992 (unless (anything-this-visible-mark)
4993 (anything-prev-visible-mark)))))
4995 (add-hook 'anything-after-update-hook
#'anything-ff-maybe-mark-candidates
)
4997 (defun* anything-dired-do-action-on-file
(&key action
)
4998 (let* ((files (dired-get-marked-files))
4999 (len (length files
))
5000 (fname (if (> len
1)
5001 (format "* %d Files" len
)
5003 (source (case action
5004 ('copy
'anything-c-source-copy-files
)
5005 ('rename
'anything-c-source-rename-files
)
5006 ('symlink
'anything-c-source-symlink-files
)
5007 ('hardlink
'anything-c-source-hardlink-files
)))
5008 (prompt-fm (case action
5009 ('copy
"Copy %s to: ")
5010 ('rename
"Rename %s to: ")
5011 ('symlink
"Symlink %s to: ")
5012 ('hardlink
"Hardlink %s to: ")))
5013 (buffer (case action
5014 ('copy
"*Anything Copy Files*")
5015 ('rename
"*Anything Rename Files*")
5016 ('symlink
"*Anything Symlink Files*")
5017 ('hardlink
"*Anything Hardlink Files*")))
5018 (anything-mp-highlight-delay nil
))
5019 (anything :sources source
5020 :input
(or (dired-dwim-target-directory)
5021 (expand-file-name (anything-c-current-directory)))
5022 :preselect
(dired-get-filename)
5023 :prompt
(format prompt-fm fname
)
5024 :keymap anything-c-read-file-map
5028 (define-minor-mode anything-dired-mode
()
5029 "Enable anything completion in Dired functions.
5030 Bindings affected are C, R, S, H."
5031 :group
'anything-config
5033 (if anything-dired-mode
5035 (substitute-key-definition
5036 'dired-do-copy
'anything-dired-copy-file dired-mode-map
)
5037 (substitute-key-definition
5038 'dired-do-rename
'anything-dired-rename-file dired-mode-map
)
5039 (substitute-key-definition
5040 'dired-do-symlink
'anything-dired-symlink-file dired-mode-map
)
5041 (substitute-key-definition
5042 'dired-do-hardlink
'anything-dired-hardlink-file dired-mode-map
))
5043 (substitute-key-definition
5044 'anything-dired-copy-file
'dired-do-copy dired-mode-map
)
5045 (substitute-key-definition
5046 'anything-dired-rename-file
'dired-do-rename dired-mode-map
)
5047 (substitute-key-definition
5048 'anything-dired-symlink-file
'dired-do-symlink dired-mode-map
)
5049 (substitute-key-definition
5050 'anything-dired-hardlink-file
'dired-do-hardlink dired-mode-map
)))
5052 (defalias 'anything-dired-bindings
'anything-dired-mode
)
5054 (defun* anything-c-read-file-name
(prompt
5056 (initial-input (expand-file-name default-directory
))
5057 (buffer "*Anything Completions*")
5062 (marked-candidates nil
)
5064 (persistent-action 'anything-find-files-persistent-action
)
5065 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
5066 "Anything `read-file-name' emulation.
5067 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
5068 (when (get-buffer anything-action-buffer
)
5069 (kill-buffer anything-action-buffer
))
5070 (let ((anything-mp-highlight-delay nil
)
5071 ;; Be sure we don't erase the underlying minibuffer if some.
5072 (anything-ff-auto-update-initial-value
5073 (not (minibuffer-window-active-p (minibuffer-window))))
5074 anything-same-window
)
5075 (flet ((action-fn (candidate)
5076 (if marked-candidates
5077 (anything-marked-candidates)
5078 (identity candidate
))))
5081 `(((name .
"Read File Name History")
5082 (header-name .
(lambda (name)
5083 (concat name anything-c-find-files-doc-header
)))
5085 (mode-line . anything-read-file-name-mode-line-string
)
5086 (candidates .
(lambda ()
5087 (anything-comp-read-get-candidates history nil nil alistp
)))
5088 (persistent-action .
,persistent-action
)
5089 (persistent-help .
,persistent-help
)
5090 (action .
,'action-fn
))
5091 ((name .
"Read file name")
5092 (header-name .
(lambda (name)
5093 (concat name anything-c-find-files-doc-header
)))
5094 ;; It is needed for filenames with capital letters
5096 (mode-line . anything-read-file-name-mode-line-string
)
5097 (candidates .
(lambda ()
5098 (let ((seq (anything-find-files-get-candidates)))
5101 for fname in seq when
(funcall test fname
)
5102 collect fname into ls
5105 (append (list anything-pattern
) ls
)))
5107 (if (file-exists-p (car seq
)) seq
(cdr seq
))
5109 (filtered-candidate-transformer anything-c-find-files-transformer
)
5110 (persistent-action .
,persistent-action
)
5111 (candidate-number-limit .
9999)
5112 (toggle-auto-update . anything-ff-toggle-auto-update
)
5113 (persistent-help .
,persistent-help
)
5115 (action .
,'action-fn
)))
5116 :input initial-input
5118 :keymap anything-c-read-file-map
5121 :preselect preselect
)
5126 (defvar anything-c-file-cache-initialized-p nil
)
5128 (defvar anything-c-file-cache-files nil
)
5130 (defvar anything-c-source-file-cache
5131 '((name .
"File Cache")
5134 (require 'filecache nil t
)
5135 (unless anything-c-file-cache-initialized-p
5136 (setq anything-c-file-cache-files
5137 (loop for item in file-cache-alist append
5138 (destructuring-bind (base &rest dirs
) item
5139 (loop for dir in dirs collect
5140 (concat dir base
)))))
5141 (defadvice file-cache-add-file
(after file-cache-list activate
)
5142 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
5143 (setq anything-c-file-cache-initialized-p t
))))
5144 (candidates . anything-c-file-cache-files
)
5145 (match anything-c-match-on-file-name
5146 anything-c-match-on-directory-name
)
5148 ;; (anything 'anything-c-source-file-cache)
5154 ;; NOTE for WINDOZE users:
5155 ;; You have to install Everything with his command line interface here:
5156 ;; http://www.voidtools.com/download.php
5158 (defvar anything-c-locate-command
5160 ('gnu
/linux
"locate -i -r %s")
5161 ('berkeley-unix
"locate -i %s")
5162 ('windows-nt
"es -i -r %s")
5164 "A list of arguments for locate program.
5165 The \"-r\" option must be the last option.")
5167 (defun anything-locate-1 (&optional localdb init
)
5168 "Generic function to run Locate.
5169 if LOCALDB is non--nil search and use a local locate db file.
5170 INIT is a string to use as initial input in prompt.
5171 See `anything-locate-with-db' and `anything-locate'."
5172 (anything-locate-with-db
5174 (anything-c-read-file-name
5176 :marked-candidates t
5177 :preselect anything-locate-db-file-regexp
5179 (if anything-locate-db-file-regexp
5180 ;; Select only locate db files and directories
5181 ;; to allow navigation.
5183 anything-locate-db-file-regexp x
)
5184 (file-directory-p x
))
5187 ;; (anything-locate-1 t)
5189 (defun anything-locate-with-db (&optional db initial-input
)
5191 If DB is not given or nil use locate without -d option.
5192 Argument DB can be given as a string or list of db files.
5193 Argument INITIAL-INPUT is a string to use as initial-input.
5194 See also `anything-locate'."
5195 (when (and db
(stringp db
)) (setq db
(list db
)))
5196 (let ((anything-c-locate-command
5198 (replace-regexp-in-string
5200 (format "locate -d %s"
5201 (mapconcat 'identity
5202 ;; Remove eventually
5203 ;; marked directories by error.
5205 unless
(file-directory-p i
)
5207 anything-c-locate-command
)
5208 anything-c-locate-command
)))
5209 (anything :sources
'anything-c-source-locate
5210 :buffer
"*anything locate*"
5211 :input initial-input
5212 :keymap anything-generic-files-map
)))
5213 ;; (anything-locate-with-db "~/locate.db")
5215 (defun anything-c-locate-init ()
5216 "Initialize async locate process for `anything-c-source-locate'."
5217 (setq mode-line-format
5218 '(" " mode-line-buffer-identification
" "
5219 (line-number-mode "%l") " "
5220 (:eval
(propertize "(Locate Process Running) "
5221 'face
'((:foreground
"red"))))))
5223 (start-process-shell-command "locate-process" nil
5224 (format anything-c-locate-command
5226 (set-process-sentinel (get-process "locate-process")
5227 #'(lambda (process event
)
5228 (when (string= event
"finished\n")
5229 (with-anything-window
5230 (force-mode-line-update nil
)
5231 (anything-update-move-first-line)))))))
5233 (defvar anything-c-source-locate
5235 (candidates . anything-c-locate-init
)
5237 (properties-action . anything-ff-properties
)
5238 (requires-pattern .
3)
5239 (candidate-number-limit .
9999)
5240 (mode-line . anything-generic-file-mode-line-string
)
5242 "Find files matching the current input pattern with locate.")
5243 ;; (anything 'anything-c-source-locate)
5245 (defun anything-c-locate-read-file-name (prompt &optional init
)
5246 "Search a file with locate and return it's filename.
5247 Use argument PROMPT and INIT for `anything' arguments
5251 (candidates . anything-c-locate-init
)
5253 (properties-action . anything-ff-properties
)
5254 (requires-pattern .
3)
5255 (candidate-number-limit .
9999)
5256 (mode-line . anything-generic-file-mode-line-string
)
5260 :buffer
"*anything locate rfn*"))
5264 ;;; Anything Incremental Grep.
5267 ;; Allow to grep incrementally with anything interface.
5268 ;; It allow also to Grep files recursively without using 'find' shell command.
5269 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
5270 (defvar anything-c-grep-default-command
5271 "grep -d skip %e -niH -e %p %f"
5272 "Default grep format command for `anything-do-grep-1'.
5274 '%e' format spec is for --exclude or --include grep options.
5275 '%p' format spec is for pattern.
5276 '%f' format spec is for filenames.")
5278 (defvar anything-c-grep-default-recurse-command
5279 "grep -d recurse %e -niH -e %p %f"
5280 "Default recursive grep format command for `anything-do-grep-1'.
5281 See `anything-c-grep-default-command' for format specs.")
5283 (defvar anything-c-default-zgrep-command
"zgrep -niH -e %p %f")
5285 (defvar anything-c-rzgrep-cache
(make-hash-table :test
'equal
))
5287 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
5289 (defvar anything-c-grep-debug-command-line nil
5290 "Turn on anything grep command-line debugging when non--nil.")
5292 (defvar anything-c-zgrep-recurse-flag nil
)
5294 (defvar anything-c-grep-history nil
)
5296 (defvar anything-c-grep-max-length-history
100
5297 "*Max number of elements to save in `anything-c-grep-history'.")
5299 (defun anything-c-grep-prepare-candidates (candidates)
5300 "Prepare filenames and directories CANDIDATES for grep command line."
5301 ;; If one or more candidate is a directory, search in all files
5302 ;; of this candidate (e.g /home/user/directory/*).
5303 ;; If r option is enabled search also in subdidrectories.
5304 ;; We need here to expand wildcards to support crap windows filenames
5305 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
5306 (if anything-c-zgrep-recurse-flag
5307 (mapconcat 'shell-quote-argument candidates
" ")
5308 (loop for i in candidates append
5309 (cond ( ;; Candidate is a directory and we use recursion.
5310 (and (file-directory-p i
)
5311 (anything-c-grep-recurse-p))
5312 (list (expand-file-name i
)))
5313 ;; Candidate is a directory, search in all files.
5314 ((file-directory-p i
)
5315 (file-expand-wildcards
5316 (concat (file-name-as-directory (expand-file-name i
)) "*") t
))
5317 ;; Candidate is a file or wildcard and we use recursion, use the
5318 ;; current directory instead of candidate.
5319 ((and (or (file-exists-p i
) (string-match "\*" i
))
5320 (anything-c-grep-recurse-p))
5321 (list (expand-file-name
5322 (directory-file-name ; Needed for windoze.
5323 (file-name-directory (directory-file-name i
))))))
5324 ;; Candidate use wildcard.
5325 ((string-match "^\*" (anything-c-basename i
))
5326 (file-expand-wildcards i t
))
5327 ;; Else should be one or more file.
5328 (t (list i
))) into all-files
5330 (mapconcat 'shell-quote-argument all-files
" "))))
5332 (defun anything-c-grep-recurse-p ()
5333 "Check if `anything-do-grep-1' have switched to recursive."
5334 (let ((args (replace-regexp-in-string
5335 "grep" "" anything-c-grep-default-command
)))
5336 (string-match-p "r\\|recurse" args
)))
5338 (defun anything-c-grep-init (only-files &optional include zgrep
)
5339 "Start an asynchronous grep process in ONLY-FILES list."
5340 (let* ((fnargs (anything-c-grep-prepare-candidates
5341 (if (file-remote-p anything-ff-default-directory
)
5342 (mapcar #'(lambda (x)
5343 (file-remote-p x
'localname
))
5346 (ignored-files (mapconcat
5348 (concat "--exclude=" (shell-quote-argument x
)))
5349 grep-find-ignored-files
" "))
5350 (ignored-dirs (mapconcat
5351 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
5353 (concat "--exclude-dir=" (shell-quote-argument x
)))
5354 grep-find-ignored-directories
" "))
5355 (exclude (if (anything-c-grep-recurse-p)
5356 (concat (or include ignored-files
) " " ignored-dirs
)
5358 (cmd-line (format-spec
5359 anything-c-grep-default-command
5361 (list (unless zgrep
(cons ?e exclude
))
5362 (cons ?p
(shell-quote-argument anything-pattern
))
5363 (cons ?f fnargs
))))))
5364 (when anything-c-grep-debug-command-line
5365 (with-current-buffer (get-buffer-create "*any grep debug*")
5366 (goto-char (point-max))
5367 (insert (concat ">>> " cmd-line
"\n\n"))))
5368 (setq mode-line-format
5369 '(" " mode-line-buffer-identification
" "
5370 (line-number-mode "%l") " "
5371 (:eval
(when (get-process "grep-process")
5372 (propertize "[Grep Process Running] "
5373 'face
'anything-grep-running
)))))
5374 (force-mode-line-update nil
)
5376 (let ((default-directory anything-ff-default-directory
))
5377 (start-file-process-shell-command "grep-process" nil cmd-line
))
5379 (set-process-sentinel
5380 (get-process "grep-process")
5381 #'(lambda (process event
)
5382 (when (string= event
"finished\n")
5383 (with-anything-window
5384 (anything-update-move-first-line)
5385 (setq mode-line-format
5386 '(" " mode-line-buffer-identification
" "
5387 (line-number-mode "%l") " "
5389 (format "[Grep Process Finished - (%s results)] "
5390 (let ((nlines (1- (count-lines
5393 (if (> nlines
0) nlines
0)))
5394 'face
'anything-grep-finish
))))
5395 (force-mode-line-update nil
))))))))
5397 (defun anything-c-grep-action (candidate &optional where mark
)
5398 "Define a default action for `anything-do-grep' on CANDIDATE.
5399 WHERE can be one of other-window, elscreen, other-frame."
5400 (let* ((split (anything-c-grep-split-line candidate
))
5401 (lineno (string-to-number (nth 1 split
)))
5402 (loc-fname (car split
))
5403 (tramp-method (file-remote-p anything-ff-default-directory
'method
))
5404 (tramp-host (file-remote-p anything-ff-default-directory
'host
))
5405 (tramp-prefix (concat "/" tramp-method
":" tramp-host
":"))
5406 (fname (if tramp-host
5407 (concat tramp-prefix loc-fname
) loc-fname
)))
5409 (other-window (find-file-other-window fname
))
5410 (elscreen (anything-elscreen-find-file fname
))
5411 (other-frame (find-file-other-frame fname
))
5412 (t (find-file fname
)))
5413 (anything-goto-line lineno
)
5415 (set-marker (mark-marker) (point))
5416 (push-mark (point) 'nomsg
))
5418 (unless (or anything-in-persistent-action
5419 (string= anything-pattern
""))
5420 (setq anything-c-grep-history
5421 (cons anything-pattern
5422 (delete anything-pattern anything-c-grep-history
)))
5423 (when (> (length anything-c-grep-history
)
5424 anything-c-grep-max-length-history
)
5425 (setq anything-c-grep-history
5426 (delete (car (last anything-c-grep-history
))
5427 anything-c-grep-history
))))))
5429 (defun anything-c-grep-other-window (candidate)
5430 "Jump to result in other window from anything grep."
5431 (anything-c-grep-action candidate
'other-window
))
5433 (defun anything-c-grep-other-frame (candidate)
5434 "Jump to result in other frame from anything grep."
5435 (anything-c-grep-action candidate
'other-frame
))
5437 (defun anything-c-grep-jump-elscreen (candidate)
5438 "Jump to result in elscreen from anything grep."
5439 (anything-c-grep-action candidate
'elscreen
))
5441 (defun anything-c-grep-save-results (candidate)
5442 "Save anything grep result in a `grep-mode' buffer."
5443 (let ((buf "*grep*")
5445 (when (get-buffer buf
)
5446 (setq new-buf
(read-string "GrepBufferName: " buf
))
5447 (loop for b in
(anything-c-buffer-list)
5448 when
(and (string= new-buf b
)
5450 (format "Buffer `%s' already exists overwrite? "
5452 do
(setq new-buf
(read-string "GrepBufferName: " "*grep ")))
5454 (with-current-buffer (get-buffer-create buf
)
5455 (let ((inhibit-read-only t
))
5457 (insert "-*- mode: grep -*-\n\n"
5458 (format "Grep Results for `%s':\n\n" anything-pattern
))
5460 (insert (with-current-buffer anything-buffer
5462 (buffer-substring (point) (point-max))))
5464 (message "Anything Grep Results saved in `%s' buffer" buf
)))
5466 (defun anything-c-grep-persistent-action (candidate)
5467 "Persistent action for `anything-do-grep'.
5468 With a prefix arg record CANDIDATE in `mark-ring'."
5469 (if current-prefix-arg
5470 (anything-c-grep-action candidate nil
'mark
)
5471 (anything-c-grep-action candidate
))
5472 (anything-match-line-color-current-line))
5474 (defun anything-c-grep-guess-extensions (files)
5475 "Try to guess file extensions in FILES list when using grep recurse.
5476 These extensions will be added to command line with --include arg of grep."
5478 with glob-list
= nil
5479 with lst
= (if (file-directory-p (car files
))
5482 directory-files-no-dot-files-regexp
)
5485 for ext
= (file-name-extension i t
)
5486 for glob
= (and ext
(not (string= ext
""))
5488 unless
(or (not glob
)
5489 (member glob glob-list
)
5490 (member glob grep-find-ignored-files
))
5491 collect glob into glob-list
5492 finally return glob-list
))
5494 (defun anything-do-grep-1 (only &optional recurse zgrep
)
5495 "Launch grep with a list of ONLY files.
5496 When RECURSE is given use -r option of grep and prompt user
5497 to set the --include args of grep.
5498 You can give more than one arg separated by space.
5499 e.g *.el *.py *.tex.
5500 If it's empty --exclude `grep-find-ignored-files' is used instead."
5501 (let* ((anything-compile-source-functions
5502 ;; rule out anything-match-plugin because the input is one regexp.
5503 (delq 'anything-compile-source--match-plugin
5504 (copy-sequence anything-compile-source-functions
)))
5505 (exts (anything-c-grep-guess-extensions only
))
5506 (globs (and (not zgrep
) (mapconcat 'identity exts
" ")))
5507 (include-files (and recurse
(not zgrep
)
5508 (read-string "OnlyExt(*.[ext]): "
5510 ;; Set `minibuffer-history' AFTER includes-files
5511 ;; to avoid storing wild-cards here.
5512 (minibuffer-history anything-c-grep-history
)
5513 (anything-c-grep-default-command (cond ((and recurse zgrep
) anything-c-default-zgrep-command
)
5514 (recurse anything-c-grep-default-recurse-command
)
5515 (zgrep anything-c-default-zgrep-command
)
5516 (t anything-c-grep-default-command
)))
5517 ;; Disable match-plugin and use here own highlighting.
5518 (anything-mp-highlight-delay nil
))
5521 (and (not (string= include-files
""))
5522 (mapconcat #'(lambda (x)
5523 (concat "--include=" (shell-quote-argument x
)))
5524 (split-string include-files
) " "))))
5525 ;; When called as action from an other source e.g *-find-files
5526 ;; we have to kill action buffer.
5527 (when (get-buffer anything-action-buffer
)
5528 (kill-buffer anything-action-buffer
))
5529 ;; `anything-find-files' haven't already started,
5530 ;; give a default value to `anything-ff-default-directory'.
5531 (setq anything-ff-default-directory
(or anything-ff-default-directory
5535 `(((name .
"Grep (C-c ? Help)")
5538 (funcall anything-c-grep-default-function only include-files zgrep
)))
5539 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
5540 (candidate-number-limit .
9999)
5541 (mode-line . anything-grep-mode-line-string
)
5542 (jump-persistent . anything-c-grep-persistent-action
)
5545 `(("Find File" . anything-c-grep-action
)
5546 ("Find file other frame" . anything-c-grep-other-frame
)
5547 ,(and (locate-library "elscreen")
5548 '("Find file in Elscreen"
5549 . anything-c-grep-jump-elscreen
))
5550 ("Save results in grep buffer" . anything-c-grep-save-results
)
5551 ("Find file other window" . anything-c-grep-other-window
))))
5552 (persistent-action . anything-c-grep-persistent-action
)
5553 (persistent-help .
"Jump to line (`C-u' Record in mark ring)")
5554 (requires-pattern .
3)
5556 :keymap anything-c-grep-map
5557 :buffer
"*anything grep*")))
5559 (defun anything-ff-zgrep-1 (flist recursive
)
5561 (let* ((def-dir (or anything-ff-default-directory
5564 (or (gethash def-dir anything-c-rzgrep-cache
)
5567 (anything-c-walk-directory
5571 :match
".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5572 anything-c-rzgrep-cache
))
5574 (when recursive
(setq anything-c-zgrep-recurse-flag t
))
5575 (anything-do-grep-1 only recursive
'zgrep
))
5576 (setq anything-c-zgrep-recurse-flag nil
)))
5578 (defun anything-c-grep-split-line (line)
5579 "Split a grep output line."
5580 (let (beg fname lineno str
)
5581 ;; Don't print until grep line is valid.
5582 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line
)
5585 (goto-char (point-min))
5588 (re-search-forward ":" nil t
)
5589 (setq fname
(buffer-substring-no-properties beg
(1- (point))))
5591 (re-search-forward ":" nil t
)
5592 (setq lineno
(buffer-substring-no-properties beg
(1- (point))))
5593 (setq str
(buffer-substring-no-properties (point) (point-at-eol))))
5594 (list fname lineno str
))))
5596 (defun anything-c-grep-cand-transformer (candidates sources
)
5597 "Filtered candidate transformer function for `anything-do-grep'."
5598 (loop for i in candidates
5599 for split
= (and i
(anything-c-grep-split-line i
))
5600 for fname
= (car split
)
5601 for lineno
= (nth 1 split
)
5602 for str
= (nth 2 split
)
5603 when
(and fname lineno str
)
5605 (cons (concat (propertize (file-name-nondirectory fname
)
5606 'face
'anything-grep-file
5607 'help-echo fname
) ":"
5608 (propertize lineno
'face
'anything-grep-lineno
) ":"
5609 (anything-c-grep-highlight-match str
))
5612 (defun anything-c-grep-highlight-match (str)
5613 "Highlight in string STR all occurences matching `anything-pattern'."
5617 (goto-char (point-min))
5618 (while (and (re-search-forward anything-pattern nil t
)
5619 (> (- (match-end 0) (match-beginning 0)) 0))
5620 (add-text-properties
5621 (match-beginning 0) (match-end 0)
5622 '(face anything-grep-match
)))
5626 ;; Go to next or precedent file (common to etags and grep).
5627 (defun anything-c-goto-next-or-prec-file (n)
5628 "Go to next or precedent candidate file in anything grep/etags buffers.
5629 If N is positive go forward otherwise go backward."
5630 (with-anything-window
5631 (let* ((current-line-list (split-string
5634 (point-at-eol)) ":"))
5635 (current-fname (nth 0 current-line-list
))
5636 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
)))
5638 (while (not (funcall fn-b-o-f
))
5639 (forward-line n
) ; Go forward or backward depending of n value.
5640 (unless (search-forward current-fname
(point-at-eol) t
)
5641 (anything-mark-current-line)
5642 (throw 'break nil
))))
5643 (cond ((and (eq n
1) (eobp))
5644 (re-search-backward ".")
5646 (anything-mark-current-line))
5647 ((and (< n
1) (bobp))
5649 (anything-mark-current-line))))))
5652 (defun anything-c-goto-precedent-file ()
5653 "Go to precedent file in anything grep/etags buffers."
5655 (anything-c-goto-next-or-prec-file -
1))
5658 (defun anything-c-goto-next-file ()
5659 "Go to precedent file in anything grep/etags buffers."
5661 (anything-c-goto-next-or-prec-file 1))
5664 (defun anything-c-grep-run-persistent-action ()
5665 "Run grep persistent action from `anything-do-grep-1'."
5667 (anything-execute-persistent-action 'jump-persistent
))
5670 (defun anything-c-grep-run-default-action ()
5671 "Run grep default action from `anything-do-grep-1'."
5673 (anything-c-quit-and-execute-action 'anything-c-grep-action
))
5676 (defun anything-c-grep-run-other-window-action ()
5677 "Run grep goto other window action from `anything-do-grep-1'."
5679 (anything-c-quit-and-execute-action 'anything-c-grep-other-window
))
5682 (defun anything-c-grep-run-save-buffer ()
5683 "Run grep save results action from `anything-do-grep-1'."
5685 (anything-c-quit-and-execute-action 'anything-c-grep-save-results
))
5688 (defun anything-c-grep-buffers-1 (candidate &optional zgrep
)
5689 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5690 If one of selected buffers is not a file--buffer,
5691 it is ignored and grep will run on all others file--buffers.
5692 If only one candidate is selected and it is not a file--buffer,
5693 switch to this buffer and run `anything-occur'.
5694 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5695 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg
))
5698 (anything-marked-candidates)))
5699 (win-conf (current-window-configuration))
5700 ;; Non--fname buffers are ignored.
5701 (bufs (loop for buf in cands
5702 for fname
= (buffer-file-name (get-buffer buf
))
5704 collect
(expand-file-name fname
))))
5707 (anything-do-grep-1 bufs nil
'zgrep
)
5708 (anything-do-grep-1 bufs
))
5709 ;; bufs is empty, thats mean we have only CANDIDATE
5710 ;; and it is not a buffer-filename, fallback to occur.
5711 (anything-c-switch-to-buffer candidate
)
5712 (when (get-buffer anything-action-buffer
)
5713 (kill-buffer anything-action-buffer
))
5715 (when (eq anything-exit-status
1)
5716 (set-window-configuration win-conf
)))))
5718 (defun anything-c-grep-buffers (candidate)
5719 "Action to grep buffers."
5720 (anything-c-grep-buffers-1 candidate
))
5722 (defun anything-c-zgrep-buffers (candidate)
5723 "Action to zgrep buffers."
5724 (anything-c-grep-buffers-1 candidate
'zgrep
))
5727 ;;; Anything interface for pdfgrep
5728 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5729 ;; and a pdf-reader (e.g xpdf) are needed.
5731 (defvar anything-c-pdfgrep-default-command
"pdfgrep --color never -niH %s %s")
5732 (defvar anything-c-pdfgrep-default-function
'anything-c-pdfgrep-init
)
5733 (defvar anything-c-pdfgrep-debug-command-line nil
)
5735 (defun anything-c-pdfgrep-init (only-files)
5736 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5737 (let* ((fnargs (anything-c-grep-prepare-candidates
5738 (if (file-remote-p anything-ff-default-directory
)
5739 (mapcar #'(lambda (x)
5740 (file-remote-p x
'localname
))
5743 (cmd-line (format anything-c-pdfgrep-default-command
5746 (when anything-c-pdfgrep-debug-command-line
5747 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5748 (goto-char (point-max))
5749 (insert (concat ">>> " cmd-line
"\n\n"))))
5750 (setq mode-line-format
5751 '(" " mode-line-buffer-identification
" "
5752 (line-number-mode "%l") " "
5753 (:eval
(propertize "(Pdfgrep Process Running) "
5754 'face
'((:foreground
"red"))))))
5756 (let ((default-directory anything-ff-default-directory
))
5757 (start-file-process-shell-command "pdfgrep-process" nil cmd-line
))
5759 (set-process-sentinel
5760 (get-process "pdfgrep-process")
5761 #'(lambda (process event
)
5762 (when (string= event
"finished\n")
5763 (with-anything-window
5764 (anything-update-move-first-line))
5765 (force-mode-line-update nil
)))))))
5768 (defun anything-do-pdfgrep-1 (only)
5769 "Launch pdfgrep with a list of ONLY files."
5770 (unless (executable-find "pdfgrep")
5771 (error "Error: No such program `pdfgrep'."))
5772 (let* ((anything-compile-source-functions
5773 ;; rule out anything-match-plugin because the input is one regexp.
5774 (delq 'anything-compile-source--match-plugin
5775 (copy-sequence anything-compile-source-functions
)))
5776 ;; Disable match-plugin and use here own highlighting.
5777 (anything-mp-highlight-delay nil
))
5778 ;; When called as action from an other source e.g *-find-files
5779 ;; we have to kill action buffer.
5780 (when (get-buffer anything-action-buffer
)
5781 (kill-buffer anything-action-buffer
))
5782 ;; If `anything-find-files' haven't already started,
5783 ;; give a default value to `anything-ff-default-directory'.
5784 (setq anything-ff-default-directory
(or anything-ff-default-directory
5788 `(((name .
"PdfGrep")
5791 (funcall anything-c-pdfgrep-default-function only
)))
5792 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
5793 (candidate-number-limit .
9999)
5794 (mode-line . anything-pdfgrep-mode-line-string
)
5795 (action . anything-c-pdfgrep-action
)
5796 (persistent-help .
"Jump to PDF Page")
5797 (requires-pattern .
3)
5799 :keymap anything-c-pdfgrep-map
5800 :buffer
"*anything grep*")))
5803 (defun anything-c-pdfgrep-action (candidate)
5804 (let* ((split (anything-c-grep-split-line candidate
))
5805 (pageno (nth 1 split
))
5806 (fname (car split
)))
5807 (start-file-process-shell-command
5809 (format-spec anything-c-pdfgrep-default-read-command
5810 (list (cons ?f fname
) (cons ?p pageno
))))))
5812 (defun anything-do-pdfgrep ()
5814 (let ((only (anything-c-read-file-name
5815 "Search in file(s): "
5816 :marked-candidates t
5817 :test
#'(lambda (file)
5818 (or (string= (file-name-extension file
) "pdf")
5819 (string= (file-name-extension file
) "PDF")
5820 (file-directory-p file
)))
5821 :preselect
(or (dired-get-filename nil t
)
5822 (buffer-file-name (current-buffer)))))
5823 (anything-c-grep-default-function 'anything-c-pdfgrep-init
))
5824 (anything-do-pdfgrep-1 only
)))
5827 ;; Yank text at point.
5831 (defvar anything-yank-point nil
)
5834 (defun anything-yank-text-at-point ()
5835 "Yank text at point in minibuffer."
5838 (flet ((insert-in-minibuffer (word)
5839 (with-selected-window (minibuffer-window)
5840 (let ((str anything-pattern
))
5841 (delete-minibuffer-contents)
5842 (set-text-properties 0 (length word
) nil word
)
5843 (insert (concat str word
))))))
5844 (with-anything-current-buffer
5845 ;; Start to initial point if C-w have never been hit.
5846 (unless anything-yank-point
(setq anything-yank-point
(point)))
5847 (and anything-yank-point
(goto-char anything-yank-point
))
5849 (setq input
(buffer-substring-no-properties anything-yank-point
(point)))
5850 (setq anything-yank-point
(point))) ; End of last forward-word
5851 (insert-in-minibuffer input
))))
5853 (defun anything-reset-yank-point ()
5854 (setq anything-yank-point nil
))
5856 (add-hook 'anything-after-persistent-action-hook
'anything-reset-yank-point
)
5857 (add-hook 'anything-cleanup-hook
'anything-reset-yank-point
)
5858 (define-key anything-map
(kbd "C-w") 'anything-yank-text-at-point
)
5864 (defvar anything-c-source-recentf
5865 '((name .
"Recentf")
5868 (or recentf-mode
(recentf-mode 1))
5869 ;; Big value empowers anything/recentf
5870 (when (and (numberp recentf-max-saved-items
)
5871 (<= recentf-max-saved-items
20))
5872 (setq recentf-max-saved-items
500))))
5873 (candidates . recentf-list
)
5874 (match anything-c-match-on-file-name
5875 anything-c-match-on-directory-name
)
5877 "See (info \"(emacs)File Conveniences\").
5878 if `recentf-max-saved-items' is too small, set it to 500.")
5879 ;; (anything 'anything-c-source-recentf)
5882 (eval-when-compile (require 'ffap
))
5883 (defvar anything-c-source-ffap-guesser
5884 '((name .
"File at point")
5885 (init .
(lambda () (require 'ffap
)))
5886 (candidates .
(lambda ()
5888 (with-anything-current-buffer
5892 ;; (anything 'anything-c-source-ffap-guesser)
5894 ;;; ffap with line number
5895 (defun anything-c-ffap-file-line-at-point ()
5896 "Get (FILENAME . LINENO) at point."
5897 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5900 (when (and (search-forward it nil t
)
5901 (looking-at ":\\([0-9]+\\)"))
5902 (cons it
(string-to-number (match-string 1)))))))
5904 (defvar anything-c-ffap-line-location nil
5905 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5906 It is cleared after jumping line.")
5908 (defun anything-c-ffap-line-candidates ()
5909 (with-anything-current-buffer
5910 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
5911 (when anything-c-ffap-line-location
5912 (destructuring-bind (file . line
) anything-c-ffap-line-location
5913 (list (cons (format "%s (line %d)" file line
) file
)))))
5915 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5916 (defun anything-c-ffap-line-goto-line ()
5917 (when (car anything-c-ffap-line-location
)
5920 (with-selected-window
5922 (get-file-buffer (car anything-c-ffap-line-location
)))
5923 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
5924 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
5925 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
5927 (defvar anything-c-source-ffap-line
5928 '((name .
"File/Lineno at point")
5929 (init .
(lambda () (require 'ffap
)))
5930 (candidates . anything-c-ffap-line-candidates
)
5932 ;; (anything 'anything-c-source-ffap-line)
5934 ;;; list of files gleaned from every dired buffer
5935 (defun anything-c-files-in-all-dired-candidates ()
5939 (cond ((listp dir
) ;filelist
5941 ((equal "" (file-name-nondirectory dir
)) ;dir
5942 (directory-files dir t
))
5944 (file-expand-wildcards dir t
))))
5946 (mapcar (lambda (buf)
5948 (when (eq major-mode
'dired-mode
)
5949 (if (consp dired-directory
)
5950 (cdr dired-directory
) ;filelist
5951 dired-directory
))) ;dir or wildcard
5953 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5955 (defvar anything-c-source-files-in-all-dired
5956 '((name .
"Files in all dired buffer.")
5957 (candidates . anything-c-files-in-all-dired-candidates
)
5959 ;; (anything 'anything-c-source-files-in-all-dired)
5961 (defvar anything-c-source-filelist
5962 '((name .
"FileList")
5963 (grep-candidates . anything-c-filelist-file-name
)
5964 (candidate-number-limit .
200)
5965 (requires-pattern .
4)
5967 "Source to find files instantly.
5968 See `anything-c-filelist-file-name' docstring for usage.")
5973 (defvar anything-c-info-pages nil
5974 "All info pages on system.
5975 Will be calculated the first time you invoke anything with this
5978 (defvar anything-c-source-info-pages
5979 `((name .
"Info Pages")
5982 (if anything-c-info-pages
5983 anything-c-info-pages
5984 (setq anything-c-info-pages
5985 (save-window-excursion
5988 (Info-find-node "dir" "top")
5989 (goto-char (point-min))
5990 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
5992 (while (re-search-forward info-topic-regexp nil t
)
5993 (add-to-list 'topics
(match-string-no-properties 1)))
5994 (goto-char (point-min))
5997 (action .
(("Show with Info" .
(lambda (node-str)
5998 (info (replace-regexp-in-string
5999 "^[^:]+: " "" node-str
))))))
6000 (requires-pattern .
2)))
6001 ;; (anything 'anything-c-source-info-pages)
6004 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
6005 (defun anything-c-describe-attributes (anything-attribute)
6006 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
6007 Same as `anything-describe-anything-attribute' but with anything completion."
6008 (interactive (list (intern
6010 "Describe anything attribute: "
6011 (mapcar 'symbol-name anything-additional-attributes
)
6014 #'(lambda (candidate)
6015 (with-output-to-temp-buffer "*Help*"
6016 (princ (get (intern candidate
) 'anything-attrdoc
))))))))
6017 (with-output-to-temp-buffer "*Help*"
6018 (princ (get anything-attribute
'anything-attrdoc
))))
6021 ;;; Use info-index plug-in.
6024 ;; Note that `name' attribute is not needed since
6025 ;; `anything-c-insert-summary' have been removed.
6027 (defvar anything-c-source-info-elisp
6028 '((name .
"Info index: elisp")
6029 (info-index .
"elisp")))
6030 ;; (anything 'anything-c-source-info-elisp)
6033 (defvar anything-c-source-info-cl
6034 '((name .
"Info index: cl")
6035 (info-index .
"cl")))
6036 ;; (anything 'anything-c-source-info-cl)
6039 (defvar anything-c-source-info-org
6040 '((name .
"Info index: org")
6041 (info-index .
"org")))
6042 ;; (anything 'anything-c-source-info-org)
6045 (defvar anything-c-source-info-gnus
6046 '((name .
"Info index: Gnus")
6047 (info-index .
"gnus")))
6049 ;; Info Index ratpoison
6050 (defvar anything-c-source-info-ratpoison
6051 '((name .
"Info index: ratpoison")
6052 (info-index .
"ratpoison")))
6053 ;; (anything 'anything-c-source-info-ratpoison)
6056 (defvar anything-c-source-info-zsh
6057 '((name .
"Info index: zsh")
6058 (info-index .
"zsh")))
6059 ;; (anything 'anything-c-source-info-zsh)
6062 (defvar anything-c-source-info-bash
6063 '((name .
"Info index: bash")
6064 (info-index .
"bash")))
6065 ;; (anything 'anything-c-source-info-bash)
6067 ;; Info Index coreutils
6068 (defvar anything-c-source-info-coreutils
6069 '((name .
"Info index: coreutils")
6070 (info-index .
"coreutils")))
6071 ;; (anything 'anything-c-source-info-coreutils)
6073 ;; Info Index fileutils
6074 (defvar anything-c-source-info-fileutils
6075 '((name .
"Info index: fileutils")
6076 (info-index .
"fileutils")))
6077 ;; (anything 'anything-c-source-info-fileutils)
6080 (defvar anything-c-source-info-find
6081 '((name .
"Info index: find")
6082 (info-index .
"find")))
6083 ;; (anything 'anything-c-source-info-find)
6085 ;; Info Index sh-utils
6086 (defvar anything-c-source-info-sh-utils
6087 '((name .
"Info index: sh-utils")
6088 (info-index .
"sh-utils")))
6089 ;; (anything 'anything-c-source-info-sh-utils)
6091 ;; Info Index textutils
6092 (defvar anything-c-source-info-textutils
6093 '((name .
"Info index: textutils")
6094 (info-index .
"textutils")))
6095 ;; (anything 'anything-c-source-info-textutils)
6098 (defvar anything-c-source-info-libc
6099 '((name .
"Info index: libc")
6100 (info-index .
"libc")))
6101 ;; (anything 'anything-c-source-info-libc)
6104 (defvar anything-c-source-info-make
6105 '((name .
"Info index: make")
6106 (info-index .
"make")))
6107 ;; (anything 'anything-c-source-info-make)
6109 ;; Info Index automake
6110 (defvar anything-c-source-info-automake
6111 '((name .
"Info index: automake")
6112 (info-index .
"automake")))
6113 ;; (anything 'anything-c-source-info-automake)
6115 ;; Info Index autoconf
6116 (defvar anything-c-source-info-autoconf
6117 '((name .
"Info index: autoconf")
6118 (info-index .
"autoconf")))
6119 ;; (anything 'anything-c-source-info-autoconf)
6121 ;; Info Index emacs-lisp-intro
6122 (defvar anything-c-source-info-emacs-lisp-intro
6123 '((name .
"Info index: emacs-lisp-intro")
6124 (info-index .
"emacs-lisp-intro")))
6125 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
6128 (defvar anything-c-source-info-emacs
6129 '((name .
"Info index: emacs")
6130 (info-index .
"emacs")))
6131 ;; (anything 'anything-c-source-info-emacs)
6134 (defvar anything-c-source-info-elib
6135 '((name .
"Info index: elib")
6136 (info-index .
"elib")))
6137 ;; (anything 'anything-c-source-info-elib)
6140 (defvar anything-c-source-info-eieio
6141 '((name .
"Info index: eieio")
6142 (info-index .
"eieio")))
6143 ;; (anything 'anything-c-source-info-eieio)
6145 ;; Info Index gauche-refe
6146 (defvar anything-c-source-info-gauche-refe
6147 '((name .
"Info index: gauche")
6148 (info-index .
"gauche-refe")))
6149 ;; (anything 'anything-c-source-info-gauche-refe)
6152 (defvar anything-c-source-info-guile
6153 '((name .
"Info index: guile")
6154 (info-index .
"guile")))
6155 ;; (anything 'anything-c-source-info-guile)
6157 ;; Info Index guile-tut
6158 (defvar anything-c-source-info-guile-tut
6159 '((name .
"Info index: guile-tut")
6160 (info-index .
"guile-tut")))
6161 ;; (anything 'anything-c-source-info-guile-tut)
6164 (defvar anything-c-source-info-goops
6165 '((name .
"Info index: goops")
6166 (info-index .
"goops")))
6167 ;; (anything 'anything-c-source-info-goops)
6169 ;; Info Index screen
6170 (defvar anything-c-source-info-screen
6171 '((name .
"Info index: screen")
6172 (info-index .
"screen")
6173 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
6174 ;; (anything 'anything-c-source-info-screen)
6177 (defvar anything-c-source-info-latex
6178 '((name .
"Info index: latex")
6179 (info-index .
"latex")))
6180 ;; (anything 'anything-c-source-info-latex)
6183 (defvar anything-c-source-info-gawk
6184 '((name .
"Info index: gawk")
6185 (info-index .
"gawk")))
6186 ;; (anything 'anything-c-source-info-gawk)
6189 (defvar anything-c-source-info-sed
6190 '((name .
"Info index: sed")
6191 (info-index .
"sed")))
6192 ;; (anything 'anything-c-source-info-sed)
6195 (defvar anything-c-source-info-m4
6196 '((name .
"Info index: m4")
6197 (info-index .
"m4")))
6198 ;; (anything 'anything-c-source-info-m4)
6201 (defvar anything-c-source-info-wget
6202 '((name .
"Info index: wget")
6203 (info-index .
"wget")))
6204 ;; (anything 'anything-c-source-info-wget)
6206 ;; Info Index binutils
6207 (defvar anything-c-source-info-binutils
6208 '((name .
"Info index: binutils")
6209 (info-index .
"binutils")))
6210 ;; (anything 'anything-c-source-info-binutils)
6213 (defvar anything-c-source-info-as
6214 '((name .
"Info index: as")
6215 (info-index .
"as")))
6216 ;; (anything 'anything-c-source-info-as)
6219 (defvar anything-c-source-info-bfd
6220 '((name .
"Info index: bfd")
6221 (info-index .
"bfd")))
6222 ;; (anything 'anything-c-source-info-bfd)
6225 (defvar anything-c-source-info-gprof
6226 '((name .
"Info index: gprof")
6227 (info-index .
"gprof")))
6228 ;; (anything 'anything-c-source-info-gprof)
6231 (defvar anything-c-source-info-ld
6232 '((name .
"Info index: ld")
6233 (info-index .
"ld")))
6234 ;; (anything 'anything-c-source-info-ld)
6237 (defvar anything-c-source-info-diff
6238 '((name .
"Info index: diff")
6239 (info-index .
"diff")))
6240 ;; (anything 'anything-c-source-info-diff)
6243 (defvar anything-c-source-info-flex
6244 '((name .
"Info index: flex")
6245 (info-index .
"flex")))
6246 ;; (anything 'anything-c-source-info-flex)
6249 (defvar anything-c-source-info-grep
6250 '((name .
"Info index: grep")
6251 (info-index .
"grep")))
6252 ;; (anything 'anything-c-source-info-grep)
6255 (defvar anything-c-source-info-gzip
6256 '((name .
"Info index: gzip")
6257 (info-index .
"gzip")))
6258 ;; (anything 'anything-c-source-info-gzip)
6260 ;; Info Index libtool
6261 (defvar anything-c-source-info-libtool
6262 '((name .
"Info index: libtool")
6263 (info-index .
"libtool")))
6264 ;; (anything 'anything-c-source-info-libtool)
6266 ;; Info Index texinfo
6267 (defvar anything-c-source-info-texinfo
6268 '((name .
"Info index: texinfo")
6269 (info-index .
"texinfo")))
6270 ;; (anything 'anything-c-source-info-texinfo)
6273 (defvar anything-c-source-info-info
6274 '((name .
"Info index: info")
6275 (info-index .
"info")))
6276 ;; (anything 'anything-c-source-info-info)
6279 (defvar anything-c-source-info-gdb
6280 '((name .
"Info index: gdb")
6281 (info-index .
"gdb")))
6282 ;; (anything 'anything-c-source-info-gdb)
6285 (defvar anything-c-source-info-stabs
6286 '((name .
"Info index: stabs")
6287 (info-index .
"stabs")))
6288 ;; (anything 'anything-c-source-info-stabs)
6290 ;; Info Index cvsbook
6291 (defvar anything-c-source-info-cvsbook
6292 '((name .
"Info index: cvsbook")
6293 (info-index .
"cvsbook")))
6294 ;; (anything 'anything-c-source-info-cvsbook)
6297 (defvar anything-c-source-info-cvs
6298 '((name .
"Info index: cvs")
6299 (info-index .
"cvs")))
6300 ;; (anything 'anything-c-source-info-cvs)
6303 (defvar anything-c-source-info-bison
6304 '((name .
"Info index: bison")
6305 (info-index .
"bison")))
6306 ;; (anything 'anything-c-source-info-bison)
6308 ;; Info Index id-utils
6309 (defvar anything-c-source-info-id-utils
6310 '((name .
"Info index: id-utils")
6311 (info-index .
"id-utils")))
6312 ;; (anything 'anything-c-source-info-id-utils)
6314 ;; Info Index global
6315 (defvar anything-c-source-info-global
6316 '((name .
"Info index: global")
6317 (info-index .
"global")))
6318 ;; (anything 'anything-c-source-info-global)
6322 ;;; Man and woman UI
6325 (defvar anything-c-man-pages nil
6326 "All man pages on system.
6327 Will be calculated the first time you invoke anything with this
6330 (defun anything-c-man-default-action (candidate)
6331 "Default action for jumping to a woman or man page from anything."
6332 (let ((wfiles (woman-file-name-all-completions candidate
)))
6334 (if (> (length wfiles
) 1)
6337 "ManFile: " wfiles
:must-match t
))
6339 ;; If woman is unable to format correctly
6341 (error (kill-buffer) ; Kill woman buffer.
6342 (let ((Man-notify-method 'meek
))
6343 (Man-getpage-in-background candidate
))))))
6345 (defvar anything-c-source-man-pages
6346 `((name .
"Manual Pages")
6347 (candidates .
(lambda ()
6348 (if anything-c-man-pages
6349 anything-c-man-pages
6350 ;; XEmacs doesn't have a woman :)
6351 (setq anything-c-man-pages
6354 (woman-file-name "")
6355 (sort (mapcar 'car woman-topic-all-completions
)
6357 (action ("Show with Woman" . anything-c-man-default-action
))
6358 ;; Woman does not work OS X
6359 ;; http://xahlee.org/emacs/modernization_man_page.html
6360 (action-transformer .
(lambda (actions candidate
)
6361 (if (eq system-type
'darwin
)
6362 '(("Show with Man" . man
))
6364 (requires-pattern .
2)))
6365 ;; (anything 'anything-c-source-man-pages)
6369 ;;; Complex command history
6372 (defvar anything-c-source-complex-command-history
6373 '((name .
"Complex Command History")
6374 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
6376 ;; (anything 'anything-c-source-complex-command-history)
6378 ;;; M-x history (not related to `anything-M-x')
6381 (defvar anything-c-source-extended-command-history
6382 '((name .
"Emacs Commands History")
6383 (candidates . extended-command-history
)
6385 ;; (anything 'anything-c-source-extended-command-history)
6387 ;;; Emacs commands (Basic source for emacs commands)
6390 (defvar anything-c-source-emacs-commands
6391 '((name .
"Emacs Commands")
6392 (candidates .
(lambda ()
6394 (mapatoms (lambda (a)
6396 (push (symbol-name a
)
6398 (sort commands
'string-lessp
))))
6400 (requires-pattern .
2))
6401 "Source for completing and invoking Emacs commands.
6402 A command is a function with interactive spec that can
6403 be invoked with `M-x'.
6405 To get non-interactive functions listed, use
6406 `anything-c-source-emacs-functions'.")
6407 ;; (anything 'anything-c-source-emacs-commands)
6410 ;;; Anything M-x - Enhanced M-x UI
6413 ;; Another replacement of `M-x' that act exactly like the
6414 ;; vanilla Emacs one, no problem of windows configuration, prefix args
6415 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
6416 ;; anything invocation.
6417 ;; Documentation of commands available without quitting,
6418 ;; Show keybindings of commands.
6420 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
6421 "Return alist of MODE-MAP."
6422 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
6423 for str-key
= (key-description key
)
6424 for ismenu
= (string-match "<menu-bar>" str-key
)
6425 unless ismenu collect
(cons str-key com
)))
6427 (defun anything-get-mode-map-from-mode (mode)
6428 "Guess the mode-map name according to MODE.
6429 Some modes don't use conventional mode-map name
6430 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
6431 Return nil if no mode-map found."
6433 ;; Start with a conventional mode-map name.
6434 with mode-map
= (intern-soft (format "%s-map" mode
))
6435 with mode-string
= (symbol-name mode
)
6436 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
6437 while
(not mode-map
)
6438 for count downfrom
(length mode-name
)
6439 ;; Return when no result after parsing entire string.
6440 when
(eq count
0) return nil
6441 for sub-name
= (substring mode-name
0 count
)
6442 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
6443 finally return mode-map
))
6445 (defun anything-M-x-current-mode-map-alist ()
6446 "Return mode-map alist of current `major-mode'."
6447 (let ((map (anything-get-mode-map-from-mode major-mode
)))
6448 (when (and map
(boundp map
))
6449 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
6452 (defun anything-M-x-transformer (candidates sources
)
6453 "filtered-candidate-transformer to show bindings in emacs commands.
6454 Show global bindings and local bindings according to current `major-mode'."
6455 (with-anything-current-buffer
6457 with local-map
= (anything-M-x-current-mode-map-alist)
6458 for cand in candidates
6459 for local-key
= (car (rassq cand local-map
))
6460 for key
= (substitute-command-keys (format "\\[%s]" cand
))
6462 (cons (cond ((and (string-match "^M-x" key
) local-key
)
6466 'face
'anything-M-x-key-face
)))
6467 ((string-match "^M-x" key
) cand
)
6468 (t (format "%s (%s)"
6471 'face
'anything-M-x-key-face
)))) cand
))))
6475 (defvar anything-c-source-lacarte
6476 '((name .
"Lacarte")
6477 (init .
(lambda () (require 'lacarte
)))
6478 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6479 (candidate-number-limit .
9999)
6480 (action . anything-c-call-interactively
))
6483 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6484 ;; (anything 'anything-c-source-lacarte)
6491 (defvar anything-c-source-emacs-functions
6492 '((name .
"Emacs Functions")
6493 (candidates .
(lambda ()
6495 (mapatoms (lambda (a)
6497 (push (symbol-name a
) commands
))))
6498 (sort commands
'string-lessp
))))
6500 (requires-pattern .
2))
6501 "Source for completing Emacs functions.")
6502 ;; (anything 'anything-c-source-emacs-functions)
6504 ;;; With abbrev expansion
6505 ;;; Similar to my exec-abbrev-cmd.el
6506 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
6507 (defvar anything-c-function-abbrev-regexp nil
6508 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
6509 Regexp built from the current `anything-pattern' interpreting it
6511 Only for internal use.")
6513 (defun anything-c-match-function-by-abbrev (candidate)
6514 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
6516 Abbreviations are made by taking the first character from each
6517 word in the function's name, e.g. \"bb\" is an abbrev for
6518 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
6519 (string-match anything-c-function-abbrev-regexp candidate
))
6521 (defvar anything-c-source-emacs-functions-with-abbrevs
6522 (append anything-c-source-emacs-functions
6523 '((match anything-c-match-function-by-abbrev
6524 anything-c-string-match
))
6527 (defadvice anything-update
6528 (before anything-c-update-function-abbrev-regexp activate
)
6529 (let ((char-list (append anything-pattern nil
))
6531 (dolist (c char-list
)
6532 (setq str
(concat str
(list c
) "[^-]*-")))
6533 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
6534 (setq anything-c-function-abbrev-regexp str
))))))))
6535 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6537 (defvar anything-c-source-advice
6538 '((name .
"Function Advice")
6539 (candidates . anything-c-advice-candidates
)
6540 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
6541 ;; (real-to-display . anything-c-advice-real-to-display)
6542 (persistent-action . anything-c-advice-persistent-action
)
6543 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
6544 ;; (anything 'anything-c-source-advice)
6545 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6548 (defun anything-c-advice-candidates ()
6550 (loop for
(fname) in ad-advised-functions
6551 for function
= (intern fname
)
6553 (loop for class in ad-advice-classes append
6554 (loop for advice in
(ad-get-advice-info-field function class
)
6555 for enabled
= (ad-advice-enabled advice
)
6559 (if enabled
"Enabled " "Disabled")
6560 (propertize fname
'face
'font-lock-function-name-face
)
6561 (ad-make-single-advice-docstring advice class nil
))
6562 (list function class advice
))))))
6564 (defun anything-c-advice-persistent-action (func-class-advice)
6565 (if current-prefix-arg
6566 (anything-c-advice-toggle func-class-advice
)
6567 (describe-function (car func-class-advice
))))
6569 (defun anything-c-advice-toggle (func-class-advice)
6570 (destructuring-bind (function class advice
) func-class-advice
6571 (cond ((ad-advice-enabled advice
)
6572 (ad-advice-set-enabled advice nil
)
6573 (message "Disabled"))
6575 (ad-advice-set-enabled advice t
)
6576 (message "Enabled")))
6577 (ad-activate function
)
6578 (and anything-in-persistent-action
6579 (anything-c-advice-update-current-display-string))))
6581 (defun anything-c-advice-update-current-display-string ()
6582 (anything-edit-current-selection
6583 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6584 ((looking-at "Enabled") "Disabled")))
6587 (delete-region (point) (progn (forward-word 1) (point)))
6588 (insert newword
)))))
6595 (defvar anything-c-source-emacs-variables
6596 '((name .
"Emacs Variables")
6597 (candidates .
(lambda ()
6598 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
6600 (requires-pattern .
2))
6601 "Source for completing Emacs variables.")
6602 ;; (anything 'anything-c-source-emacs-variables)
6608 ;; Bind some faces for bookmarks.
6609 (defvar anything-c-bookmarks-face1
'anything-ff-directory
)
6610 (defvar anything-c-bookmarks-face2
'anything-ff-file
)
6611 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
6613 (eval-when-compile (require 'bookmark
))
6614 (defvar anything-c-source-bookmarks
6615 '((name .
"Bookmarks")
6617 (require 'bookmark
)))
6618 (candidates . bookmark-all-names
)
6620 "See (info \"(emacs)Bookmarks\").")
6621 ;; (anything 'anything-c-source-bookmarks)
6624 (defvar anything-c-source-bookmark-set
6625 '((name .
"Set Bookmark")
6627 (action . bookmark-set
))
6628 "See (info \"(emacs)Bookmarks\").")
6629 ;; (anything 'anything-c-source-bookmark-set)
6631 ;;; Visible Bookmarks
6632 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6635 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6636 (defvar anything-c-source-bm
6637 '((name .
"Visible Bookmarks")
6638 (init . anything-c-bm-init
)
6639 (candidates-in-buffer)
6643 http://www.nongnu.org/bm/")
6645 (defun anything-c-bm-init ()
6646 "Init function for `anything-c-source-bm'."
6647 (when (require 'bm nil t
)
6649 (let ((bookmarks (bm-lists))
6650 (buf (anything-candidate-buffer 'global
)))
6651 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
6652 '< :key
'overlay-start
))
6653 (let ((start (overlay-start bm
))
6654 (end (overlay-end bm
))
6655 (annotation (or (overlay-get bm
'annotation
) "")))
6656 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
6657 (let ((str (format "%5d: [%s]: %s\n"
6658 (line-number-at-pos start
)
6660 (buffer-substring start
(1- end
)))))
6661 (with-current-buffer buf
(insert str
))))))))))
6663 ;;; Special bookmarks
6664 (defvar anything-c-source-bookmarks-ssh
6665 '((name .
"Bookmarks-ssh")
6667 (require 'bookmark
)))
6668 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
6670 "See (info \"(emacs)Bookmarks\").")
6671 ;; (anything 'anything-c-source-bookmarks-ssh)
6673 (defvar anything-c-source-bookmarks-su
6674 '((name .
"Bookmarks-root")
6676 (require 'bookmark
)))
6677 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
6678 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
6681 "See (info \"(emacs)Bookmarks\").")
6682 ;; (anything 'anything-c-source-bookmarks-su)
6684 (defvar anything-c-source-bookmarks-local
6685 '((name .
"Bookmarks-Local")
6687 (require 'bookmark
)))
6688 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
6689 (filtered-candidate-transformer
6690 anything-c-adaptive-sort
6691 anything-c-highlight-bookmark
)
6693 "See (info \"(emacs)Bookmarks\").")
6694 ;; (anything 'anything-c-source-bookmarks-local)
6696 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
6697 (let* ((lis-all (bookmark-all-names))
6698 (lis-loc (cond (local (loop for i in lis-all
6699 unless
(string-match "^(ssh)\\|^(su)" i
)
6701 (su (loop for i in lis-all
6702 when
(string-match "^(su)" i
)
6704 (sudo (loop for i in lis-all
6705 when
(string-match "^(sudo)" i
)
6707 (ssh (loop for i in lis-all
6708 when
(string-match "^(ssh)" i
)
6710 (sort lis-loc
'string-lessp
)))
6712 (defun anything-c-bookmark-root-logged-p ()
6714 (dolist (i (mapcar #'buffer-name
(buffer-list)))
6715 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
6716 (throw 'break t
)))))
6718 (defun anything-c-highlight-bookmark-su (files source
)
6719 (if (anything-c-bookmark-root-logged-p)
6720 (anything-c-highlight-bookmark files source
)
6721 (anything-c-highlight-not-logged files source
)))
6723 (defun anything-c-highlight-not-logged (files source
)
6724 (loop for i in files
6725 collect
(propertize i
'face anything-c-bookmarks-face3
)))
6727 (defun anything-c-highlight-bookmark (bookmarks source
)
6728 "Used as `candidate-transformer' to colorize bookmarks.
6729 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6730 (loop for i in bookmarks
6731 for isfile
= (bookmark-get-filename i
)
6732 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
6733 (bmkext-get-buffer-name i
))
6734 for handlerp
= (and (fboundp 'bookmark-get-handler
)
6735 (bookmark-get-handler i
))
6736 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
6737 (bmkext-w3m-bookmark-p i
))
6738 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
6739 (bmkext-gnus-bookmark-p i
))
6740 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
6741 (bmkext-man-bookmark-p i
))
6742 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
6743 (bmkext-woman-bookmark-p i
))
6744 for handlerp
= (bookmark-get-handler i
)
6745 for isannotation
= (bookmark-get-annotation i
)
6746 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
6747 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
6748 ;; Add a * if bookmark have annotation
6749 if
(and isannotation
(not (string-equal isannotation
"")))
6750 do
(setq i
(concat "*" i
))
6751 collect
(cond (;; info buffers
6753 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
6756 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
6759 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
6762 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
6765 (propertize i
'face
'((:foreground
"Tomato"))))
6767 (and isfile
(file-directory-p isfile
))
6768 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
6771 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
6775 ;;; Sources to filter bookmark-extensions bookmarks.
6778 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6779 ;; If you want to enable google-maps in addressbook you will need
6780 ;; Julien Danjou google-maps-el package available here:
6781 ;; http://julien.danjou.info/google-maps-el.html
6783 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
6784 "Return a filtered `bookmark-alist' sorted alphabetically."
6786 with alist
= (if args
6787 (apply #'(lambda (x) (funcall fn x
)) args
)
6792 finally return
(sort sa
'string-lessp
)))
6797 (defvar anything-c-source-bmkext-addressbook
6798 '((name .
"Bookmark Addressbook")
6800 (require 'bookmark-extensions
)
6801 (bookmark-maybe-load-default-file)))
6802 (candidates . anything-c-bmkext-addressbook-setup-alist
)
6804 .
(lambda (candidate)
6805 (let ((bmk (anything-bookmark-get-bookmark-from-name
6807 (bookmark--jump-via bmk
'pop-to-buffer
))))
6808 (persistent-help .
"Show contact - Prefix with C-u to append")
6809 (filtered-candidate-transformer
6810 anything-c-adaptive-sort
6811 anything-c-highlight-bookmark
)
6812 (action .
(("Show Contact(s)"
6813 .
(lambda (candidate)
6814 (let* ((contacts (anything-marked-candidates))
6815 (current-prefix-arg (or anything-current-prefix-arg
6816 (> (length contacts
) 1))))
6818 (anything-bookmark-get-bookmark-from-name (car contacts
)))
6819 (anything-aif (cdr contacts
)
6820 (loop for bmk in it do
6822 (anything-bookmark-get-bookmark-from-name bmk
)))))))
6824 .
(lambda (candidate)
6825 (let* ((contacts (anything-marked-candidates))
6826 (bmk (anything-bookmark-get-bookmark-from-name
6828 (append (message-buffers)))
6830 (addressbook-set-mail-buffer1 bmk
'append
)
6831 (addressbook-set-mail-buffer1 bmk
))
6832 (setq contacts
(cdr contacts
))
6834 (loop for bmk in contacts do
6835 (addressbook-set-mail-buffer1 bmk
'append
))))))
6837 .
(lambda (candidate)
6838 (let ((bmk (anything-bookmark-get-bookmark-from-name
6840 (addressbook-bookmark-edit
6841 (assoc bmk bookmark-alist
)))))
6842 ("Insert Email at point"
6843 .
(lambda (candidate)
6844 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6846 (mlist (split-string
6848 'email
(assoc bmk bookmark-alist
))
6851 (if (> (length mlist
) 1)
6853 "Insert Mail Address: " mlist
:must-match t
)
6856 .
(lambda (candidate)
6857 (let ((bmk (anything-bookmark-get-bookmark-from-name
6859 (bookmark-show-annotation bmk
))))
6861 .
(lambda (candidate)
6862 (let ((bmk (anything-bookmark-get-bookmark-from-name
6864 (bookmark-edit-annotation bmk
))))
6866 .
(lambda (candidate)
6867 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6869 (full-bmk (assoc bmk bookmark-alist
)))
6870 (addressbook-google-map full-bmk
))))))))
6873 (defun anything-c-bmkext-addressbook-setup-alist ()
6874 "Specialized filter function for bookmarks w3m."
6875 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
6877 ;; W3m bookmarks from bookmark-extensions.
6878 (defvar anything-c-source-bookmark-w3m
6879 '((name .
"Bookmark W3m")
6881 (require 'bookmark-extensions
)
6882 (bookmark-maybe-load-default-file)))
6883 (candidates . anything-c-bookmark-w3m-setup-alist
)
6884 (filtered-candidate-transformer
6885 anything-c-adaptive-sort
6886 anything-c-highlight-bookmark
)
6888 ;; (anything 'anything-c-source-bookmark-w3m)
6890 (defun anything-c-bookmark-w3m-setup-alist ()
6891 "Specialized filter function for bookmarks w3m."
6892 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
6895 (defvar anything-c-source-bookmark-images
6896 '((name .
"Bookmark Images")
6898 (require 'bookmark-extensions
)
6899 (bookmark-maybe-load-default-file)))
6900 (candidates . anything-c-bookmark-images-setup-alist
)
6901 (filtered-candidate-transformer
6902 anything-c-adaptive-sort
6903 anything-c-highlight-bookmark
)
6905 ;; (anything 'anything-c-source-bookmark-images)
6907 (defun anything-c-bookmark-images-setup-alist ()
6908 "Specialized filter function for images bookmarks."
6909 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
6912 (defvar anything-c-source-bookmark-man
6913 '((name .
"Bookmark Woman&Man")
6915 (require 'bookmark-extensions
)
6916 (bookmark-maybe-load-default-file)))
6917 (candidates . anything-c-bookmark-man-setup-alist
)
6918 (filtered-candidate-transformer
6919 anything-c-adaptive-sort
6920 anything-c-highlight-bookmark
)
6922 ;; (anything 'anything-c-source-bookmark-man)
6924 (defun anything-c-bookmark-man-setup-alist ()
6925 "Specialized filter function for bookmarks w3m."
6926 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
6927 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
6930 (defvar anything-c-source-bookmark-gnus
6931 '((name .
"Bookmark Gnus")
6933 (require 'bookmark-extensions
)
6934 (bookmark-maybe-load-default-file)))
6935 (candidates . anything-c-bookmark-gnus-setup-alist
)
6936 (filtered-candidate-transformer
6937 anything-c-adaptive-sort
6938 anything-c-highlight-bookmark
)
6940 ;; (anything 'anything-c-source-bookmark-gnus)
6942 (defun anything-c-bookmark-gnus-setup-alist ()
6943 "Specialized filter function for bookmarks gnus."
6944 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
6947 (defvar anything-c-source-bookmark-info
6948 '((name .
"Bookmark Info")
6950 (require 'bookmark-extensions
)
6951 (bookmark-maybe-load-default-file)))
6952 (candidates . anything-c-bookmark-info-setup-alist
)
6953 (filtered-candidate-transformer
6954 anything-c-adaptive-sort
6955 anything-c-highlight-bookmark
)
6957 ;; (anything 'anything-c-source-bookmark-info)
6959 (defun anything-c-bookmark-info-setup-alist ()
6960 "Specialized filter function for bookmarks info."
6961 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
6963 ;; Local Files&directories
6964 (defvar anything-c-source-bookmark-files
&dirs
6965 '((name .
"Bookmark Files&Directories")
6967 (require 'bookmark-extensions
)
6968 (bookmark-maybe-load-default-file)))
6969 (candidates . anything-c-bookmark-local-files-setup-alist
)
6970 (filtered-candidate-transformer
6971 anything-c-adaptive-sort
6972 anything-c-highlight-bookmark
)
6974 ;; (anything 'anything-c-source-bookmark-files&dirs)
6976 (defun anything-c-bookmark-local-files-setup-alist ()
6977 "Specialized filter function for bookmarks locals files."
6978 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
6980 ;; Su Files&directories
6981 (defvar anything-c-source-bookmark-su-files
&dirs
6982 '((name .
"Bookmark Root-Files&Directories")
6984 (require 'bookmark-extensions
)
6985 (bookmark-maybe-load-default-file)))
6986 (candidates . anything-c-bookmark-su-files-setup-alist
)
6987 (filtered-candidate-transformer
6988 anything-c-adaptive-sort
6989 anything-c-highlight-bookmark-su
)
6991 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
6993 (defun anything-c-bookmark-su-files-setup-alist ()
6994 "Specialized filter function for bookmarks su/sudo files."
6995 (declare (special bmkext-su-or-sudo-regexp
))
6997 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
6999 for isfile
= (bookmark-get-filename i
)
7000 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
7002 (string-match tramp-file-name-regexp isfile
)))
7003 for issu
= (and istramp
7004 (string-match bmkext-su-or-sudo-regexp isfile
))
7008 ;; Ssh Files&directories
7009 (defvar anything-c-source-bookmark-ssh-files
&dirs
7010 '((name .
"Bookmark Ssh-Files&Directories")
7012 (require 'bookmark-extensions
)
7013 (bookmark-maybe-load-default-file)))
7014 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
7015 (filtered-candidate-transformer . anything-c-adaptive-sort
)
7017 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
7019 (defun anything-c-bookmark-ssh-files-setup-alist ()
7020 "Specialized filter function for bookmarks ssh files."
7022 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
7024 for isfile
= (bookmark-get-filename i
)
7025 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
7027 (string-match tramp-file-name-regexp isfile
)))
7028 for isssh
= (and istramp
7029 (string-match "/ssh:" isfile
))
7035 ;;; Firefox bookmarks
7038 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
7039 ;; (only for firefox versions >=3)
7040 ;; To achieve that, open about:config in firefox and double click on this line to enable value
7042 ;; user_pref("browser.bookmarks.autoExportHTML", false);
7043 ;; You should have now:
7044 ;; user_pref("browser.bookmarks.autoExportHTML", true);
7046 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
7047 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
7049 (defun anything-get-firefox-user-init-dir ()
7050 "Guess the default Firefox user directory name."
7051 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
7053 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
7054 (goto-char (point-min))
7056 (when (search-forward "Path=" nil t
)
7057 (buffer-substring-no-properties (point) (point-at-eol)))
7059 (file-name-as-directory (concat moz-dir moz-user-dir
))))
7061 (defun anything-guess-firefox-bookmark-file ()
7062 "Return the path of the Firefox bookmarks file."
7063 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
7065 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
7066 "Parse html bookmark FILE and return an alist with (title . url) as elements."
7067 (let (bookmarks-alist url title
)
7069 (insert-file-contents file
)
7070 (goto-char (point-min))
7071 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
7073 (when (re-search-forward url-regexp nil t
)
7074 (setq url
(match-string 0)))
7075 (when (re-search-forward bmk-regexp nil t
)
7076 (setq title
(match-string 1)))
7077 (push (cons title url
) bookmarks-alist
)
7079 (nreverse bookmarks-alist
)))
7081 (defvar anything-c-firefox-bookmarks-alist nil
)
7082 (defvar anything-c-source-firefox-bookmarks
7083 '((name .
"Firefox Bookmarks")
7085 (setq anything-c-firefox-bookmarks-alist
7086 (anything-html-bookmarks-to-alist
7087 (anything-guess-firefox-bookmark-file)
7088 anything-firefox-bookmark-url-regexp
7089 anything-firefox-bookmarks-regexp
))))
7090 (candidates .
(lambda ()
7091 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
7092 (filtered-candidate-transformer
7093 anything-c-adaptive-sort
7094 anything-c-highlight-firefox-bookmarks
)
7095 (action .
(("Browse Url Firefox"
7096 .
(lambda (candidate)
7098 (anything-c-firefox-bookmarks-get-value candidate
))))
7100 .
(lambda (candidate)
7102 (anything-c-firefox-bookmarks-get-value candidate
))))
7105 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
7107 ;; (anything 'anything-c-source-firefox-bookmarks)
7109 (defun anything-c-firefox-bookmarks-get-value (elm)
7110 (assoc-default elm anything-c-firefox-bookmarks-alist
))
7112 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
7113 (loop for i in bookmarks
7115 i
'face
'((:foreground
"YellowGreen"))
7116 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
7120 ;;; W3m bookmark - anything interface.
7123 ;; Some users have the emacs-w3m library in load-path
7124 ;; without having the w3m executable :-;
7125 ;; So check if w3m program is present before trying to load
7128 (when (executable-find "w3m")
7129 (require 'w3m-bookmark nil t
)))
7131 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html")
7132 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
7133 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
7134 (defvar anything-c-w3m-bookmarks-alist nil
)
7135 (defvar anything-c-source-w3m-bookmarks
7136 '((name .
"W3m Bookmarks")
7138 (setq anything-c-w3m-bookmarks-alist
7139 (anything-html-bookmarks-to-alist
7141 anything-w3m-bookmark-url-regexp
7142 anything-w3m-bookmarks-regexp
))))
7143 (candidates .
(lambda ()
7144 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
7145 (filtered-candidate-transformer
7146 anything-c-adaptive-sort
7147 anything-c-highlight-w3m-bookmarks
)
7148 (action .
(("Browse Url"
7149 .
(lambda (candidate)
7150 (anything-c-w3m-browse-bookmark candidate
)))
7153 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
7154 ("Browse Url Firefox"
7155 .
(lambda (candidate)
7156 (anything-c-w3m-browse-bookmark candidate t
)))
7158 .
(lambda (candidate)
7159 (anything-c-w3m-delete-bookmark candidate
)))
7161 .
(lambda (candidate)
7162 (anything-c-w3m-rename-bookmark candidate
)))))
7163 (persistent-action .
(lambda (candidate)
7164 (if current-prefix-arg
7165 (anything-c-w3m-browse-bookmark candidate t
)
7166 (anything-c-w3m-browse-bookmark candidate nil t
))))
7167 (persistent-help .
"Open URL with emacs-w3m in new tab / \
7168 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
7169 "Needs w3m and emacs-w3m.
7171 http://w3m.sourceforge.net/
7172 http://emacs-w3m.namazu.org/")
7174 ;; (anything 'anything-c-source-w3m-bookmarks)
7176 (defun anything-c-w3m-bookmarks-get-value (elm)
7177 (replace-regexp-in-string
7178 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
7180 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
7181 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
7182 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
7183 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
7185 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
7186 (loop for i in bookmarks
7188 i
'face
'anything-w3m-bookmarks-face
7189 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
7192 (defun anything-c-w3m-delete-bookmark (elm)
7193 "Delete w3m bookmark from `w3m-bookmark-file'."
7194 (with-current-buffer
7195 (find-file-literally w3m-bookmark-file
)
7196 (goto-char (point-min))
7197 (when (re-search-forward elm nil t
)
7199 (delete-region (point)
7200 (line-end-position))
7201 (delete-blank-lines))
7205 (defun anything-c-w3m-rename-bookmark (elm)
7206 "Rename w3m bookmark in `w3m-bookmark-file'."
7207 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
7208 (new-title (read-string "NewTitle: " old-title
)))
7209 (with-current-buffer
7210 (find-file-literally w3m-bookmark-file
)
7211 (goto-char (point-min))
7212 (when (re-search-forward (concat elm
"<") nil t
)
7213 (goto-char (1- (point)))
7214 (delete-char (- (length old-title
)))
7221 ;;; Elisp library scan
7224 (defvar anything-c-source-elisp-library-scan
7225 '((name .
"Elisp libraries (Scan)")
7226 (init .
(anything-c-elisp-library-scan-init))
7227 (candidates-in-buffer)
7228 (action ("Find library"
7229 .
(lambda (candidate) (find-file (find-library-name candidate
))))
7230 ("Find library other window"
7231 .
(lambda (candidate)
7232 (find-file-other-window (find-library-name candidate
))))
7234 .
(lambda (candidate) (load-library candidate
))))))
7235 ;; (anything 'anything-c-source-elisp-library-scan)
7237 (defun anything-c-elisp-library-scan-init ()
7238 "Init anything buffer status."
7239 (let ((anything-buffer (anything-candidate-buffer 'global
))
7240 (library-list (anything-c-elisp-library-scan-list)))
7241 (with-current-buffer anything-buffer
7242 (dolist (library library-list
)
7243 (insert (format "%s\n" library
))))))
7245 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
7246 "Do completion for file names passed to `locate-file'.
7247 DIRS is directory to search path.
7248 STRING is string to match."
7249 ;; Use `load-path' as path when ignore `dirs'.
7250 (or dirs
(setq dirs load-path
))
7251 ;; Init with blank when ignore `string'.
7252 (or string
(setq string
""))
7253 ;; Get library list.
7254 (let ((string-dir (file-name-directory string
))
7255 ;; File regexp that suffix match `load-file-rep-suffixes'.
7256 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
7261 (setq dir default-directory
))
7263 (setq dir
(expand-file-name string-dir dir
)))
7264 (when (file-directory-p dir
)
7265 (dolist (file (file-name-all-completions
7266 (file-name-nondirectory string
) dir
))
7267 ;; Suffixes match `load-file-rep-suffixes'.
7268 (setq name
(if string-dir
(concat string-dir file
) file
))
7269 (if (string-match match-regexp name
)
7270 (add-to-list 'names name
)))))
7281 (defvar anything-c-imenu-delimiter
" / ")
7283 (defvar anything-c-imenu-index-filter nil
)
7284 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
7286 (defvar anything-c-cached-imenu-alist nil
)
7287 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
7289 (defvar anything-c-cached-imenu-candidates nil
)
7290 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
7292 (defvar anything-c-cached-imenu-tick nil
)
7293 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
7295 (eval-when-compile (require 'imenu
))
7296 (setq imenu-auto-rescan t
)
7298 (defun anything-imenu-create-candidates (entry)
7299 "Create candidates with ENTRY."
7300 (if (listp (cdr entry
))
7303 (if (consp (cdr sub
))
7306 (concat (car entry
) anything-c-imenu-delimiter subentry
))
7307 (anything-imenu-create-candidates sub
))
7308 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
7312 (defvar anything-c-source-imenu
7314 (init .
(lambda () (require 'imenu
)))
7315 (candidates . anything-c-imenu-candidates
)
7316 (persistent-action .
(lambda (elm)
7317 (anything-c-imenu-default-action elm
)
7318 (unless (fboundp 'semantic-imenu-tag-overlay
)
7319 (anything-match-line-color-current-line))))
7320 (persistent-help .
"Show this entry")
7321 (action . anything-c-imenu-default-action
))
7322 "See (info \"(emacs)Imenu\")")
7324 ;; (anything 'anything-c-source-imenu)
7326 (defun anything-c-imenu-candidates ()
7327 (with-anything-current-buffer
7328 (let ((tick (buffer-modified-tick)))
7329 (if (eq anything-c-cached-imenu-tick tick
)
7330 anything-c-cached-imenu-candidates
7331 (setq imenu--index-alist nil
)
7332 (setq anything-c-cached-imenu-tick tick
7333 anything-c-cached-imenu-candidates
7336 'anything-imenu-create-candidates
7337 (setq anything-c-cached-imenu-alist
7338 (let ((index (imenu--make-index-alist)))
7339 (if anything-c-imenu-index-filter
7340 (funcall anything-c-imenu-index-filter index
)
7342 (setq anything-c-cached-imenu-candidates
7343 (mapcar #'(lambda (x)
7347 anything-c-cached-imenu-candidates
))))))
7349 (setq imenu-default-goto-function
'imenu-default-goto-function
)
7350 (defun anything-c-imenu-default-action (elm)
7351 "The default action for `anything-c-source-imenu'."
7352 (let ((path (split-string elm anything-c-imenu-delimiter
))
7353 (alist anything-c-cached-imenu-alist
))
7355 (setq alist
(assoc elm alist
)))
7363 (defvar anything-c-ctags-modes
7364 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
7365 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
7366 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
7368 (defun anything-c-source-ctags-init ()
7369 (when (and buffer-file-name
7370 (memq major-mode anything-c-ctags-modes
)
7371 (anything-current-buffer-is-modified))
7372 (with-current-buffer (anything-candidate-buffer 'local
)
7373 (call-process-shell-command
7374 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
7375 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
7376 anything-buffer-file-name
)
7377 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
7378 nil
(current-buffer))
7379 (goto-char (point-min))
7381 (delete-region (point-min) (point))
7382 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
7383 for lineno-start
= (point)
7384 for lineno
= (buffer-substring
7386 (1- (search-forward "," (point-at-eol) t
)))
7389 (insert (format "%5s:" lineno
))
7390 (search-forward "\177" (point-at-eol) t
)
7391 (delete-region (1- (point)) (point-at-eol))
7392 (forward-line 1)))))
7394 (defvar anything-c-source-ctags
7395 '((name .
"Exuberant ctags")
7396 (init . anything-c-source-ctags-init
)
7397 (candidates-in-buffer)
7400 "Needs Exuberant Ctags.
7402 http://ctags.sourceforge.net/")
7403 ;; (anything 'anything-c-source-ctags)
7409 ;; anything-etags.el is deprecated, if this file is found,
7410 ;; warn user at compile time.
7412 (when (locate-library "anything-etags.el")
7415 "You are using obsolete library `anything-etags.el' and should remove it."
7418 (defvar anything-c-etags-tag-file-dir nil
7419 "Etags file directory.")
7420 (defvar anything-c-etags-mtime-alist nil
7421 "Store the last modification time of etags files here.")
7422 (defvar anything-c-etags-cache
(make-hash-table :test
'equal
)
7423 "Cache content of etags files used here for faster access.")
7425 (defun anything-c-etags-get-tag-file (&optional directory
)
7426 "Return the path of etags file if found."
7427 ;; Get tag file from `default-directory' or upper directory.
7428 (let ((current-dir (anything-c-etags-find-tag-file-directory
7429 (or directory default-directory
))))
7430 ;; Return nil if not find tag file.
7432 ;; Set tag file directory.
7433 (setq anything-c-etags-tag-file-dir current-dir
)
7434 (expand-file-name anything-c-etags-tag-file-name current-dir
))))
7436 (defun anything-c-etags-find-tag-file-directory (current-dir)
7437 "Try to find the directory containing tag file.
7438 If not found in CURRENT-DIR search in upper directory."
7439 (flet ((file-exists?
(dir)
7440 (let ((tag-path (expand-file-name
7441 anything-c-etags-tag-file-name dir
)))
7442 (and (stringp tag-path
)
7443 (file-exists-p tag-path
)
7444 (file-readable-p tag-path
)))))
7445 (loop with count
= 0
7446 until
(file-exists? current-dir
)
7447 ;; Return nil if outside the value of
7448 ;; `anything-c-etags-tag-file-search-limit'.
7449 if
(= count anything-c-etags-tag-file-search-limit
)
7451 ;; Or search upper directories.
7454 (setq current-dir
(expand-file-name (concat current-dir
"../")))
7455 finally return current-dir
)))
7457 (defun anything-c-source-etags-header-name (x)
7458 "Create header name for this anything etags session."
7460 (with-anything-current-buffer
7461 (anything-c-etags-get-tag-file))))
7463 (defmacro anything-c-etags-create-buffer
(file)
7464 "Create the `anything-buffer' based on contents of etags tag FILE."
7465 `(let* ((tag-fname ,file
)
7467 (split (with-current-buffer (find-file-noselect tag-fname
)
7469 (split-string (buffer-string) "\n" 'omit-nulls
)
7470 (setq max
(line-number-at-pos (point-max)))
7472 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max
)))
7476 for i in split for count from
0
7477 for elm
= (unless (string-match "^\x0c" i
)
7478 (anything-aif (string-match "\177" i
)
7481 do
(cond ((and elm
(string-match "^\\(.+\\),[0-9]+" elm
))
7482 (setq fname
(match-string 1 elm
)))
7483 (elm (setq cand
(concat fname
": " elm
)))
7484 (t (setq cand nil
)))
7486 (insert (concat cand
"\n"))
7487 (progress-reporter-update progress-reporter count
)))))
7489 (defun anything-c-etags-init ()
7490 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
7491 If no entry in cache, create one."
7492 (let ((tagfile (anything-c-etags-get-tag-file)))
7494 (with-current-buffer (anything-candidate-buffer 'global
)
7495 (anything-aif (gethash tagfile anything-c-etags-cache
)
7496 ;; An entry is present in cache, insert it.
7498 ;; No entry, create a new buffer using content of tag file (slower).
7499 (anything-c-etags-create-buffer tagfile
)
7500 ;; Store content of buffer in cache.
7501 (puthash tagfile
(buffer-string) anything-c-etags-cache
)
7502 ;; Store or set the last modification of tag file.
7503 (anything-aif (assoc tagfile anything-c-etags-mtime-alist
)
7504 ;; If an entry exists modify it.
7505 (setcdr it
(anything-c-etags-mtime tagfile
))
7506 ;; No entry create a new one.
7507 (add-to-list 'anything-c-etags-mtime-alist
7508 (cons tagfile
(anything-c-etags-mtime tagfile
)))))))))
7510 (defvar anything-c-source-etags-select
7512 (header-name . anything-c-source-etags-header-name
)
7513 (init . anything-c-etags-init
)
7514 (candidates-in-buffer)
7515 (search .
(anything-c-etags-search-fn))
7516 (mode-line . anything-etags-mode-line-string
)
7517 (action . anything-c-etags-default-action
)
7518 (persistent-action .
(lambda (candidate)
7519 (anything-c-etags-default-action candidate
)
7520 (anything-match-line-color-current-line))))
7521 "Anything source for Etags.")
7523 (defun anything-c-etags-search-fn (pattern bound noerror
)
7524 "Search function for `anything-c-source-etags-select'."
7526 (if anything-c-etags-use-regexp-search
(concat "\\_<" pattern
) pattern
)
7529 (defun anything-c-etags-default-action (candidate)
7530 "Anything default action to jump to an etags entry."
7531 (let* ((split (split-string candidate
": "))
7532 (fname (expand-file-name
7533 (car split
) anything-c-etags-tag-file-dir
))
7536 (goto-char (point-min))
7537 (search-forward elm nil t
)
7538 (goto-char (match-beginning 0))))
7540 (defun anything-c-etags-mtime (file)
7541 "Last modification time of etags tag FILE."
7542 (cadr (nth 5 (file-attributes file
))))
7544 (defun anything-c-etags-file-modified-p (file)
7545 "Check if tag FILE have been modified in this session.
7546 If FILE is nil return nil."
7547 (let ((last-modif (and file
7548 (assoc-default file anything-c-etags-mtime-alist
))))
7550 (/= last-modif
(anything-c-etags-mtime file
)))))
7557 (defvar anything-semantic-candidates nil
)
7559 (defun anything-semantic-construct-candidates (tags depth
)
7560 (when (require 'semantic nil t
)
7566 (let ((type (semantic-tag-type tag
))
7567 (class (semantic-tag-class tag
)))
7568 (if (or (and (stringp type
)
7569 (or (string= type
"class")
7570 (string= type
"namespace")))
7571 (eq class
'function
)
7572 (eq class
'variable
))
7573 (cons (cons (concat (make-string (* depth
2) ?\s
)
7574 (semantic-format-tag-summarize tag nil t
))
7576 (anything-semantic-construct-candidates
7577 (semantic-tag-components tag
) (1+ depth
)))))))
7580 (defun anything-semantic-default-action (candidate)
7581 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
7582 (semantic-go-to-tag tag
)))
7584 (defvar anything-c-source-semantic
7585 '((name .
"Semantic Tags")
7587 (setq anything-semantic-candidates
7588 (ignore-errors (anything-semantic-construct-candidates
7589 (semantic-fetch-tags) 0)))))
7590 (candidates .
(lambda ()
7591 (if anything-semantic-candidates
7592 (mapcar 'car anything-semantic-candidates
))))
7593 (persistent-action .
(lambda (elm)
7594 (anything-semantic-default-action elm
)
7595 (anything-match-line-color-current-line)))
7596 (persistent-help .
"Show this entry")
7597 (action . anything-semantic-default-action
)
7598 "Needs semantic in CEDET.
7600 http://cedet.sourceforge.net/semantic.shtml
7601 http://cedet.sourceforge.net/"))
7603 ;; (anything 'anything-c-source-semantic)
7606 ;;; Anything interface of `simple-call-tree.el'.
7608 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7610 ;; Function is called by
7611 (defvar anything-c-source-simple-call-tree-functions-callers
7612 '((name .
"Function is called by")
7613 (init . anything-c-simple-call-tree-functions-callers-init
)
7615 (candidates . anything-c-simple-call-tree-candidates
)
7616 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7617 (persistent-help .
"Show function definitions by rotation")
7618 (action ("Find definition selected by persistent-action" .
7619 anything-c-simple-call-tree-find-definition
)))
7620 "Needs simple-call-tree.el.
7621 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7623 (defvar anything-c-simple-call-tree-tick nil
)
7624 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
7625 (defun anything-c-simple-call-tree-analyze-maybe ()
7626 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
7627 (simple-call-tree-analyze)
7628 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
7630 (defun anything-c-simple-call-tree-init-base (function message
)
7631 (require 'simple-call-tree
)
7633 (when (anything-current-buffer-is-modified)
7634 (anything-c-simple-call-tree-analyze-maybe)
7635 (let ((list (funcall function simple-call-tree-alist
)))
7636 (with-current-buffer (anything-candidate-buffer 'local
)
7637 (dolist (entry list
)
7638 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
7639 (insert (car entry
) message
7640 (if (string= funcs
" ")
7645 (defun anything-c-simple-call-tree-functions-callers-init ()
7646 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7649 (defun anything-c-simple-call-tree-candidates ()
7650 (with-current-buffer (anything-candidate-buffer)
7651 (split-string (buffer-string) "\n\n")))
7653 (defvar anything-c-simple-call-tree-related-functions nil
)
7654 (defvar anything-c-simple-call-tree-function-index
0)
7655 (defun anything-c-simple-call-tree-persistent-action (candidate)
7656 (unless (eq last-command
'anything-execute-persistent-action
)
7657 (setq anything-c-simple-call-tree-related-functions
7658 (delete "no functions."
7660 (replace-regexp-in-string " \\| is called by\\| calls "
7663 (setq anything-c-simple-call-tree-function-index -
1))
7664 (incf anything-c-simple-call-tree-function-index
)
7665 (anything-c-simple-call-tree-find-definition candidate
))
7667 (defun anything-c-simple-call-tree-find-definition (candidate)
7670 (nth (mod anything-c-simple-call-tree-function-index
7671 (length anything-c-simple-call-tree-related-functions
))
7672 anything-c-simple-call-tree-related-functions
))))
7674 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7677 (defvar anything-c-source-simple-call-tree-callers-functions
7678 '((name .
"Function calls")
7679 (init . anything-c-simple-call-tree-callers-functions-init
)
7681 (candidates . anything-c-simple-call-tree-candidates
)
7682 (persistent-action . anything-c-simple-call-tree-persistent-action
)
7683 (persistent-help .
"Show function definitions by rotation")
7684 (action ("Find definition selected by persistent-action" .
7685 anything-c-simple-call-tree-find-definition
)))
7686 "Needs simple-call-tree.el.
7687 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7689 (defun anything-c-simple-call-tree-callers-functions-init ()
7690 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
7692 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7696 ;;; Anything UI of auto-document.el
7698 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7700 ;; Commands/Options with doc
7701 (defvar anything-c-auto-document-data nil
)
7702 (make-variable-buffer-local 'anything-c-auto-document-data
)
7703 (defvar anything-c-source-commands-and-options-in-file
7704 '((name .
"Commands/Options in file")
7706 .
(lambda (x) (format "Commands/Options in %s"
7707 (buffer-local-value 'buffer-file-name
7708 anything-current-buffer
))))
7709 (candidates . anything-command-and-options-candidates
)
7712 "List Commands and Options with doc. It needs auto-document.el .
7714 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7716 (eval-when-compile (require 'auto-document nil t
))
7717 (defun anything-command-and-options-candidates ()
7718 (with-anything-current-buffer
7719 (when (and (require 'auto-document nil t
)
7720 (eq major-mode
'emacs-lisp-mode
)
7721 (or (anything-current-buffer-is-modified)
7722 (not anything-c-auto-document-data
)))
7723 (or imenu--index-alist
(imenu--make-index-alist t
))
7724 (setq anything-c-auto-document-data
7725 (destructuring-bind (commands options
)
7726 (adoc-construct anything-current-buffer
)
7728 (loop for
(command . doc
) in commands
7729 for cmdname
= (symbol-name command
)
7732 (format "Command: %s\n %s"
7733 (propertize cmdname
'face font-lock-function-name-face
)
7734 (adoc-first-line doc
))
7735 (assoc cmdname imenu--index-alist
)))
7736 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
7737 for
(option doc default
) in options
7738 for optname
= (symbol-name option
)
7741 (format "Option: %s\n %s\n default = %s"
7742 (propertize optname
'face font-lock-variable-name-face
)
7743 (adoc-first-line doc
)
7744 (adoc-prin1-to-string default
))
7747 anything-c-auto-document-data
))
7749 ;; (anything 'anything-c-source-commands-and-options-in-file)
7752 ;;;; <Color and Face>
7758 (defvar anything-c-source-customize-face
7759 '((name .
"Customize Face")
7761 (unless (anything-candidate-buffer)
7762 (save-window-excursion (list-faces-display))
7763 (anything-candidate-buffer (get-buffer "*Faces*")))))
7764 (candidates-in-buffer)
7765 (get-line . buffer-substring
)
7766 (action .
(lambda (line)
7767 (customize-face (intern (car (split-string line
))))))
7768 (requires-pattern .
3))
7769 "See (info \"(emacs)Faces\")")
7770 ;; (anything 'anything-c-source-customize-face)
7775 (defvar anything-c-source-colors
7777 (init .
(lambda () (unless (anything-candidate-buffer)
7778 (save-window-excursion (list-colors-display))
7779 (anything-candidate-buffer (get-buffer "*Colors*")))))
7780 (candidates-in-buffer)
7781 (get-line . buffer-substring
)
7783 ("Copy Name" .
(lambda (candidate)
7784 (kill-new (anything-c-colors-get-name candidate
))))
7785 ("Copy RGB" .
(lambda (candidate)
7786 (kill-new (anything-c-colors-get-rgb candidate
))))
7787 ("Insert Name" .
(lambda (candidate)
7788 (with-anything-current-buffer
7789 (insert (anything-c-colors-get-name candidate
)))))
7790 ("Insert RGB" .
(lambda (candidate)
7791 (with-anything-current-buffer
7792 (insert (anything-c-colors-get-rgb candidate
))))))))
7793 ;; (anything 'anything-c-source-colors)
7795 (defun anything-c-colors-get-name (candidate)
7797 (replace-regexp-in-string
7800 (insert (capitalize candidate
))
7801 (goto-char (point-min))
7802 (search-forward-regexp "\\s-\\{2,\\}")
7803 (delete-region (point) (point-max))
7806 (defun anything-c-colors-get-rgb (candidate)
7808 (replace-regexp-in-string
7811 (insert (capitalize candidate
))
7812 (goto-char (point-max))
7813 (search-backward-regexp "\\s-\\{2,\\}")
7814 (delete-region (point) (point-min))
7818 ;;;; <Search Engine>
7819 ;;; Tracker desktop search
7820 (defvar anything-c-source-tracker-search
7821 '((name .
"Tracker Search")
7822 (candidates .
(lambda ()
7823 (start-process "tracker-search-process" nil
7827 (requires-pattern .
3)
7829 "Source for retrieving files matching the current input pattern
7830 with the tracker desktop search.")
7831 ;; (anything 'anything-c-source-tracker-search)
7833 ;;; Spotlight (MacOS X desktop search)
7834 (defvar anything-c-source-mac-spotlight
7837 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
7839 (requires-pattern .
3)
7841 "Source for retrieving files via Spotlight's command line
7843 ;; (anything 'anything-c-source-mac-spotlight)
7846 (defvar anything-c-source-picklist
7847 '((name .
"Picklist")
7848 (candidates .
(lambda () (mapcar 'car picklist-list
)))
7850 ;; (anything 'anything-c-source-picklist)
7857 (defvar anything-c-source-kill-ring
7858 '((name .
"Kill Ring")
7859 (init .
(lambda () (anything-attrset 'last-command last-command
)))
7860 (candidates . anything-c-kill-ring-candidates
)
7861 (filtered-candidate-transformer anything-c-kill-ring-transformer
)
7862 (action . anything-c-kill-ring-action
)
7866 "Source for browse and insert contents of kill-ring.")
7868 (defun anything-c-kill-ring-candidates ()
7869 (loop for kill in
(anything-fast-remove-dups kill-ring
:test
'equal
)
7870 unless
(or (< (length kill
) anything-kill-ring-threshold
)
7871 (string-match "^[\\s\\t]+$" kill
))
7874 (defun anything-c-kill-ring-transformer (candidates source
)
7875 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7876 (loop for i in candidates
7877 for nlines
= (with-temp-buffer (insert i
) (count-lines (point-min) (point-max)))
7878 if
(and anything-c-kill-ring-max-lines-number
7879 (> nlines anything-c-kill-ring-max-lines-number
))
7883 (goto-char (point-min))
7888 (forward-line anything-c-kill-ring-max-lines-number
)
7893 (defun anything-c-kill-ring-action (str)
7894 "Insert STR in `kill-ring' and set STR to the head.
7895 If this action is executed just after `yank',
7896 replace with STR as yanked string."
7897 (setq kill-ring
(delete str kill-ring
))
7898 (if (not (eq (anything-attr 'last-command
) 'yank
))
7899 (insert-for-yank str
)
7901 (let ((inhibit-read-only t
)
7902 (before (< (point) (mark t
))))
7904 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
7905 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
7906 (setq yank-undo-function nil
)
7907 (set-marker (mark-marker) (point) (current-buffer))
7908 (insert-for-yank str
)
7909 ;; Set the window start back where it was in the yank command,
7911 (set-window-start (selected-window) yank-window-start t
)
7913 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7914 ;; It is cleaner to avoid activation, even though the command
7915 ;; loop would deactivate the mark because we inserted text.
7916 (goto-char (prog1 (mark t
)
7917 (set-marker (mark-marker) (point) (current-buffer)))))))
7920 ;; (anything 'anything-c-source-kill-ring)
7924 ;; DO NOT include these sources in `anything-sources' use
7925 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7926 ;; `anything-all-mark-rings' instead.
7928 (defun anything-c-source-mark-ring-candidates ()
7929 (flet ((get-marks (pos)
7933 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
7934 (when (string= "" line
)
7935 (setq line
"<EMPTY LINE>"))
7936 (format "%7d: %s" (line-number-at-pos) line
)))))
7937 (with-anything-current-buffer
7939 with marks
= (if (mark) (cons (mark-marker) mark-ring
) mark-ring
)
7942 for m
= (get-marks i
)
7943 unless
(member m recip
)
7944 collect m into recip
7945 finally return recip
))))
7947 (defvar anything-mark-ring-cache nil
)
7948 (defvar anything-c-source-mark-ring
7949 '((name .
"mark-ring")
7951 (setq anything-mark-ring-cache
7952 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7953 (candidates .
(lambda ()
7954 (anything-aif anything-mark-ring-cache
7956 (action .
(("Goto line"
7957 .
(lambda (candidate)
7958 (anything-goto-line (string-to-number candidate
))))))
7959 (persistent-action .
(lambda (candidate)
7960 (anything-goto-line (string-to-number candidate
))
7961 (anything-match-line-color-current-line)))
7962 (persistent-help .
"Show this line")))
7964 ;; (anything 'anything-c-source-mark-ring)
7966 ;;; Global-mark-ring
7967 (defvar anything-c-source-global-mark-ring
7968 '((name .
"global-mark-ring")
7969 (candidates . anything-c-source-global-mark-ring-candidates
)
7970 (action .
(("Goto line"
7971 .
(lambda (candidate)
7972 (let ((items (split-string candidate
":")))
7973 (anything-c-switch-to-buffer (second items
))
7974 (anything-goto-line (string-to-number (car items
))))))))
7975 (persistent-action .
(lambda (candidate)
7976 (let ((items (split-string candidate
":")))
7977 (anything-c-switch-to-buffer (second items
))
7978 (anything-goto-line (string-to-number (car items
)))
7979 (anything-match-line-color-current-line))))
7980 (persistent-help .
"Show this line")))
7982 (defun anything-c-source-global-mark-ring-candidates ()
7984 (with-current-buffer (marker-buffer m
)
7988 (if (string= "" line
)
7989 (setq line
"<EMPTY LINE>")
7990 (setq line
(car (split-string (thing-at-point 'line
)
7992 (format "%7d:%s: %s"
7993 (line-number-at-pos) (marker-buffer m
) line
)))))
7995 with marks
= global-mark-ring
7998 for gm
= (unless (or (string-match
7999 "^ " (format "%s" (marker-buffer i
)))
8000 (null (marker-buffer i
)))
8002 when
(and gm
(not (member gm recip
)))
8003 collect gm into recip
8004 finally return recip
)))
8006 ;; (anything 'anything-c-source-global-mark-ring)
8010 ;;; Insert from register
8011 (defvar anything-c-source-register
8012 '((name .
"Registers")
8013 (candidates . anything-c-register-candidates
)
8014 (action-transformer . anything-c-register-action-transformer
)
8017 "See (info \"(emacs)Registers\")")
8019 (defun anything-c-register-candidates ()
8020 "Collecting register contents and appropriate commands."
8021 (loop for
(char . val
) in register-alist
8022 for key
= (single-key-description char
)
8023 for string-actions
=
8026 (list (int-to-string val
)
8028 'increment-register
))
8030 (let ((buf (marker-buffer val
)))
8032 (list "a marker in no buffer")
8034 "a buffer position:"
8037 (int-to-string (marker-position val
)))
8039 'insert-register
))))
8040 ((and (consp val
) (window-configuration-p (car val
)))
8041 (list "window configuration."
8043 ((and (consp val
) (frame-configuration-p (car val
)))
8044 (list "frame configuration."
8046 ((and (consp val
) (eq (car val
) 'file
))
8047 (list (concat "file:"
8048 (prin1-to-string (cdr val
))
8051 ((and (consp val
) (eq (car val
) 'file-query
))
8052 (list (concat "file:a file-query reference: file "
8055 (int-to-string (car (cdr (cdr val
))))
8059 (let ((lines (format "%4d" (length val
))))
8060 (list (format "%s: %s\n" lines
8061 (truncate-string-to-width
8062 (mapconcat 'identity
(list (car val
))
8063 ;; (mapconcat (lambda (y) y) val
8064 "^J") (- (window-width) 15)))
8067 (list ;; without properties
8068 (substring-no-properties val
)
8071 'prepend-to-register
))
8074 collect
(cons (format "register %3s: %s" key
(car string-actions
))
8075 (cons char
(cdr string-actions
)))))
8077 (defun anything-c-register-action-transformer (actions register-and-functions
)
8078 "Decide actions by the contents of register."
8079 (loop with func-actions
=
8082 (lambda (c) (insert-register (car c
))))
8084 "Jump to Register" .
8085 (lambda (c) (jump-to-register (car c
))))
8087 "Append Region to Register" .
8088 (lambda (c) (append-to-register
8089 (car c
) (region-beginning) (region-end))))
8090 (prepend-to-register
8091 "Prepend Region to Register" .
8092 (lambda (c) (prepend-to-register
8093 (car c
) (region-beginning) (region-end))))
8095 "Increment Prefix Arg to Register" .
8096 (lambda (c) (increment-register
8097 anything-current-prefix-arg
(car c
)))))
8098 for func in
(cdr register-and-functions
)
8099 for cell
= (assq func func-actions
)
8101 collect
(cdr cell
)))
8103 ;; (anything 'anything-c-source-register)
8106 ;;; Latex completion
8107 (defun anything-c-latex-math-candidates ()
8108 "Collect candidates for latex math completion."
8109 (declare (special LaTeX-math-menu
))
8110 (loop for i in
(cddr LaTeX-math-menu
)
8111 for elm
= (loop for s in i when
(vectorp s
)
8112 collect
(cons (aref s
0) (aref s
1)))
8115 (defvar anything-c-source-latex-math
8116 '((name .
"Latex Math Menu")
8118 (with-anything-current-buffer
8119 (LaTeX-math-mode 1))))
8120 (candidate-number-limit .
9999)
8121 (candidates . anything-c-latex-math-candidates
)
8122 (action .
(lambda (candidate)
8123 (call-interactively candidate
)))))
8126 ;;;; <Headline Extraction>
8127 (defvar anything-c-source-fixme
8128 '((name .
"TODO/FIXME/DRY comments")
8129 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
8132 "Show TODO/FIXME/DRY comments in current file.")
8133 ;; (anything 'anything-c-source-fixme)
8135 (defvar anything-c-source-rd-headline
8136 '((name .
"RD HeadLine")
8137 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
8138 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
8144 http://en.wikipedia.org/wiki/Ruby_Document_format")
8145 ;; (anything 'anything-c-source-rd-headline)
8147 (defvar anything-c-source-oddmuse-headline
8148 '((name .
"Oddmuse HeadLine")
8149 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
8150 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
8151 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
8154 "Show Oddmuse headlines, such as EmacsWiki.")
8155 ;; (anything 'anything-c-source-oddmuse-headline)
8157 (defvar anything-c-source-emacs-source-defun
8158 '((name .
"Emacs Source DEFUN")
8159 (headline .
"DEFUN\\|DEFVAR")
8160 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
8161 (or buffer-file-name
""))))
8162 "Show DEFUN/DEFVAR in Emacs C source file.")
8163 ;; (anything 'anything-c-source-emacs-source-defun)
8165 (defvar anything-c-source-emacs-lisp-expectations
8166 '((name .
"Emacs Lisp Expectations")
8167 (headline .
"(desc[ ]\\|(expectations")
8168 (condition .
(eq major-mode
'emacs-lisp-mode
)))
8169 "Show descriptions (desc) in Emacs Lisp Expectations.
8171 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
8172 ;; (anything 'anything-c-source-emacs-lisp-expectations)
8174 (defvar anything-c-source-emacs-lisp-toplevels
8175 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
8176 (headline .
"^(\\|(@\\*\\|^;;;;")
8177 (get-line . buffer-substring
)
8178 (condition .
(eq major-mode
'emacs-lisp-mode
))
8180 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
8181 linkd.el is optional because linkd stars are extracted by regexp.
8182 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
8183 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
8186 ;;; Anything yaoddmuse
8188 ;; Be sure to have yaoddmuse.el installed
8189 ;; install-elisp may be required if you want to install elisp file from here.
8190 (defvar anything-yaoddmuse-use-cache-file nil
)
8191 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
8192 (defvar anything-c-yaoddmuse-ew-cache nil
)
8194 (defun anything-yaoddmuse-get-candidates ()
8195 (declare (special yaoddmuse-pages-hash
))
8196 (if anything-yaoddmuse-use-cache-file
8198 (unless anything-c-yaoddmuse-ew-cache
8199 (load anything-c-yaoddmuse-cache-file
)
8200 (setq anything-c-yaoddmuse-ew-cache
8201 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
8202 anything-c-yaoddmuse-ew-cache
)
8203 (yaoddmuse-update-pagename t
)
8204 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
8206 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
8207 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
8208 (candidates . anything-yaoddmuse-get-candidates
)
8209 (action .
(("Edit page" .
(lambda (candidate)
8210 (yaoddmuse-edit "EmacsWiki" candidate
)))
8212 .
(lambda (candidate)
8213 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
8214 ("Browse page other window"
8215 .
(lambda (candidate)
8217 (split-window-vertically))
8218 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
8220 .
(lambda (candidate)
8221 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
8223 .
(lambda (candidate)
8224 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
8225 (message "Have copy page %s's URL to yank." candidate
)))
8227 .
(lambda (candidate)
8228 (yaoddmuse-edit "EmacsWiki" anything-input
)))
8230 .
(lambda (candidate)
8231 (if anything-yaoddmuse-use-cache-file
8233 (anything-yaoddmuse-cache-pages t
)
8234 (setq anything-c-yaoddmuse-ew-cache
8235 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
8236 (yaoddmuse-update-pagename))))))
8237 (action-transformer anything-c-yaoddmuse-action-transformer
))
8238 "Needs yaoddmuse.el.
8240 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
8242 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
8244 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
8245 '((name .
"Yaoddmuse Post library (EmacsWiki)")
8246 (init .
(anything-yaoddmuse-init))
8247 (candidates-in-buffer)
8248 (action .
(("Post library and Browse"
8249 .
(lambda (candidate)
8250 (yaoddmuse-post-file
8251 (find-library-name candidate
)
8253 (file-name-nondirectory (find-library-name candidate
))
8256 .
(lambda (candidate)
8257 (yaoddmuse-post-file
8258 (find-library-name candidate
)
8260 (file-name-nondirectory
8261 (find-library-name candidate
))))))))
8262 "Needs yaoddmuse.el.
8264 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
8266 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
8268 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
8269 "Allow the use of `install-elisp' only on elisp files."
8270 (if (string-match "\.el$" candidate
)
8271 (append actions
'(("Install Elisp"
8273 (install-elisp-from-emacswiki elm
)))))
8277 (defun anything-yaoddmuse-cache-pages (&optional load
)
8278 "Fetch the list of files on emacswiki and create cache file.
8279 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
8281 (declare (special yaoddmuse-pages-hash
))
8282 (yaoddmuse-update-pagename)
8284 (find-file anything-c-yaoddmuse-cache-file
)
8286 (insert "(puthash \"EmacsWiki\" '(")
8287 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
8289 (insert (concat "(\"" (car i
) "\") ")))
8290 (insert ") yaoddmuse-pages-hash)\n")
8292 (kill-buffer (current-buffer))
8293 (when (or current-prefix-arg
8295 (load anything-c-yaoddmuse-cache-file
))))
8297 (defun anything-yaoddmuse-init ()
8298 "Init anything buffer status."
8299 (let ((anything-buffer (anything-candidate-buffer 'global
))
8300 (library-list (yaoddmuse-get-library-list)))
8301 (with-current-buffer anything-buffer
8302 ;; Insert library name.
8303 (dolist (library library-list
)
8304 (insert (format "%s\n" library
)))
8306 (sort-lines nil
(point-min) (point-max)))))
8310 (defvar anything-c-source-eev-anchor
8311 '((name .
"Anchors")
8315 (with-anything-current-buffer
8316 (loop initially
(goto-char (point-min))
8317 while
(re-search-forward
8318 (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
8319 for anchor
= (match-string-no-properties 1)
8320 collect
(cons (format "%5d:%s"
8321 (line-number-at-pos (match-beginning 0))
8322 (format ee-anchor-format anchor
))
8324 (persistent-action .
(lambda (item)
8326 (anything-match-line-color-current-line)))
8327 (persistent-help .
"Show this entry")
8328 (action .
(("Goto link" . ee-to
)))))
8329 ;; (anything 'anything-c-source-eev-anchor)
8335 (defvar anything-c-source-org-headline
8336 `((name .
"Org HeadLine")
8337 (headline ,@(mapcar (lambda (num)
8338 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
8340 (number-sequence 1 8)))
8341 (condition .
(eq major-mode
'org-mode
))
8344 (persistent-action .
(lambda (elm)
8345 (anything-c-action-line-goto elm
)
8348 .
(lambda (actions candidate
)
8349 '(("Go to Line" . anything-c-action-line-goto
)
8350 ("Insert Link to This Headline"
8351 . anything-c-org-headline-insert-link-to-headline
)))))
8352 "Show Org headlines.
8353 org-mode is very very much extended text-mode/outline-mode.
8355 See (find-library \"org.el\")
8356 See http://orgmode.org for the latest version.")
8358 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
8361 (anything-goto-line (car lineno-and-content
))
8362 (and (looking-at org-complex-heading-regexp
)
8363 (org-make-link-string (concat "*" (match-string 4)))))))
8364 ;; (anything 'anything-c-source-org-headline)
8369 (defvar anything-c-source-org-keywords
8370 '((name .
"Org Keywords")
8371 (init . anything-c-org-keywords-init
)
8372 (candidates . anything-c-org-keywords-candidates
)
8373 (action . anything-c-org-keywords-insert
)
8374 (persistent-action . anything-c-org-keywords-show-help
)
8375 (persistent-help .
"Show an example and info page to describe this keyword.")
8378 ;; (anything 'anything-c-source-org-keywords)
8380 (defvar anything-c-org-keywords-info-location
8381 '(("#+TITLE:" .
"(org)Export options")
8382 ("#+AUTHOR:" .
"(org)Export options")
8383 ("#+DATE:" .
"(org)Export options")
8384 ("#+EMAIL:" .
"(org)Export options")
8385 ("#+DESCRIPTION:" .
"(org)Export options")
8386 ("#+KEYWORDS:" .
"(org)Export options")
8387 ("#+LANGUAGE:" .
"(org)Export options")
8388 ("#+TEXT:" .
"(org)Export options")
8389 ("#+TEXT:" .
"(org)Export options")
8390 ("#+OPTIONS:" .
"(org)Export options")
8391 ("#+BIND:" .
"(org)Export options")
8392 ("#+LINK_UP:" .
"(org)Export options")
8393 ("#+LINK_HOME:" .
"(org)Export options")
8394 ("#+LATEX_HEADER:" .
"(org)Export options")
8395 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
8396 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
8397 ("#+INFOJS_OPT" .
"(org)Javascript support")
8398 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
8399 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
8400 ("#+ORGTBL" .
"(org)Radio tables")
8401 ("#+HTML:" .
"(org)Quoting HTML tags")
8402 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
8403 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
8404 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
8405 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
8406 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
8407 ("#+BEGIN_SRC" .
"(org)Literal examples")
8408 ("#+CAPTION" .
"(org)Tables in HTML export")
8409 ("#+LABEL" .
"(org)Tables in LaTeX export")
8410 ("#+ATTR_HTML" .
"(org)Links")
8411 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
8413 (defun anything-c-org-keywords-init ()
8414 (unless (anything-attr 'keywords-examples
)
8416 (anything-attrset 'keywords-examples
8420 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
8421 (cons (match-string 2 x
) (match-string 1 x
)))
8422 (org-split-string (org-get-current-options) "\n"))
8423 (mapcar 'list org-additional-option-like-keywords
)))
8424 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
8426 (defun anything-c-org-keywords-candidates ()
8427 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
8428 (eq (buffer-local-value 'major-mode anything-current-buffer
) 'message-mode
))
8429 (anything-attr 'keywords
)))
8431 (defun anything-c-org-keywords-insert (keyword)
8432 (cond ((and (string-match "BEGIN" keyword
)
8433 (anything-region-active-p))
8434 (let ((beg (region-beginning))
8437 (insert "\n#+" (replace-regexp-in-string
8438 "BEGIN" "END" keyword
) "\n")
8440 (insert "#+" keyword
" ")
8441 (save-excursion (insert "\n"))))
8442 ((string-match "BEGIN" keyword
)
8443 (insert "#+" keyword
" ")
8445 (insert "\n#+" (replace-regexp-in-string
8446 "BEGIN" "END" keyword
) "\n")))
8447 (t (insert "#+" keyword
" "))))
8449 (defun anything-c-org-keywords-show-help (keyword)
8450 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
8451 "(org)In-buffer settings"))
8452 (search-forward (concat "#+" keyword
) nil t
)
8453 (anything-persistent-highlight-point)
8454 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
8461 (defvar bbdb-records
)
8462 (defvar bbdb-buffer-name
)
8464 (defun anything-c-bbdb-candidates ()
8465 "Return a list of all names in the bbdb database. The format
8466 is \"Firstname Lastname\"."
8467 (mapcar (lambda (bbdb-record)
8468 (replace-regexp-in-string
8470 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
8473 (defun anything-c-bbdb-create-contact (actions candidate
)
8474 "Action transformer that returns only an entry to add the
8475 current `anything-pattern' as new contact. All other actions are
8477 (if (string= candidate
"*Add to contacts*")
8478 '(("Add to contacts" .
(lambda (actions)
8479 (bbdb-create-internal
8480 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
8481 (read-from-minibuffer "Company: ")
8482 (read-from-minibuffer "Email: ")
8485 (read-from-minibuffer "Note: ")))))
8488 (defun anything-c-bbdb-get-record (candidate)
8489 "Return record that match CANDIDATE."
8490 (bbdb candidate nil
)
8491 (set-buffer "*BBDB*")
8492 (bbdb-current-record))
8494 (defvar anything-c-bbdb-name nil
8495 "Only for internal use.")
8497 (defvar anything-c-source-bbdb
8499 (candidates . anything-c-bbdb-candidates
)
8500 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
8501 ("View person's data" . anything-c-bbdb-view-person-action
))
8502 (filtered-candidate-transformer .
(lambda (candidates source
)
8503 (setq anything-c-bbdb-name anything-pattern
)
8504 (if (not candidates
)
8505 (list "*Add to contacts*")
8507 (action-transformer .
(lambda (actions candidate
)
8508 (anything-c-bbdb-create-contact actions candidate
))))
8511 http://bbdb.sourceforge.net/")
8512 ;; (anything 'anything-c-source-bbdb)
8514 (defun anything-c-bbdb-view-person-action (candidate)
8515 "View BBDB data of single CANDIDATE or marked candidates."
8516 (anything-aif (anything-marked-candidates)
8517 (let ((bbdb-append-records (length it
)))
8519 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
8520 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
8522 (defun anything-c-bbdb-collect-mail-addresses ()
8523 "Return a list of all mail addresses of records in bbdb buffer."
8524 (with-current-buffer bbdb-buffer-name
8525 (loop for i in bbdb-records
8526 if
(bbdb-record-net (car i
))
8527 collect
(bbdb-dwim-net-address (car i
)))))
8529 (defun anything-c-bbdb-compose-mail (candidate)
8530 "Compose a mail with all records of bbdb buffer."
8531 (anything-c-bbdb-view-person-action candidate
)
8532 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8533 (address-str (mapconcat 'identity address-list
",\n ")))
8534 (compose-mail address-str
)))
8537 ;;; Evaluation Result
8541 (defvar anything-eldoc-active-minibuffers-list nil
)
8543 (defvar anything-c-source-evaluation-result
8544 '((name .
"Evaluation Result")
8548 (mode-line .
"C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8549 (filtered-candidate-transformer .
(lambda (candidates source
)
8552 (with-anything-current-buffer
8554 (eval (read anything-pattern
))))
8556 (action .
(("Copy result to kill-ring" .
(lambda (candidate)
8557 (with-current-buffer anything-buffer
8558 (let ((end (save-excursion
8559 (goto-char (point-max))
8560 (search-backward "\n")
8562 (kill-region (point) end
)))))
8563 ("copy sexp to kill-ring" .
(lambda (candidate)
8564 (kill-new anything-input
)))))))
8565 ;; (anything 'anything-c-source-evaluation-result)
8567 (defun anything-eval-new-line-and-indent ()
8569 (newline) (lisp-indent-line))
8571 (defun anything-eldoc-store-minibuffer ()
8572 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8573 (with-selected-window (minibuffer-window)
8574 (push (buffer-name) anything-eldoc-active-minibuffers-list
)))
8576 (defun anything-eldoc-show-in-eval ()
8577 "Return eldoc in mode-line for current minibuffer input."
8578 (let ((buf (with-selected-window (minibuffer-window)
8580 (when (member buf anything-eldoc-active-minibuffers-list
)
8581 (let* ((str-all (with-current-buffer buf
8582 (minibuffer-completion-contents)))
8586 (goto-char (point-max))
8587 (unless (looking-back ")\\|\"") (forward-char -
1))
8588 (eldoc-current-symbol))))
8589 (info-fn (eldoc-fnsym-in-current-sexp))
8590 (doc (or (eldoc-get-var-docstring sym
)
8591 (eldoc-get-fnsym-args-string
8592 (car info-fn
) (cadr info-fn
)))))
8593 (when doc
(funcall anything-c-eldoc-in-minibuffer-show-fn doc
))))))
8595 (defun anything-c-eldoc-show-in-mode-line (str)
8596 "Show string STR in mode-line."
8597 (save-window-excursion
8598 (with-current-buffer anything-buffer
8599 (let ((mode-line-format (concat " " str
)))
8600 (force-mode-line-update)
8601 (sit-for anything-c-eldoc-show-in-mode-line-delay
))
8602 (force-mode-line-update))))
8604 ;;; Calculation Result
8607 (defvar anything-c-source-calculation-result
8608 '((name .
"Calculation Result")
8610 (filtered-candidate-transformer .
(lambda (candidates source
)
8613 (calc-eval anything-pattern
)
8615 (action ("Copy result to kill-ring" . kill-new
))))
8616 ;; (anything 'anything-c-source-calculation-result)
8619 ;;; Google Suggestions
8623 (defvar anything-ggs-max-length-real-flag
0)
8624 (defvar anything-ggs-max-length-num-flag
0)
8626 (defun anything-c-google-suggest-fetch (input)
8627 "Fetch suggestions for INPUT from XML buffer.
8628 Return an alist with elements like (data . number_results)."
8629 (setq anything-ggs-max-length-real-flag
0
8630 anything-ggs-max-length-num-flag
0)
8631 (let ((request (concat anything-c-google-suggest-url
8632 (url-hexify-string input
))))
8635 with result-alist
= (xml-get-children
8636 (car (xml-parse-region
8637 (point-min) (point-max)))
8638 'CompleteSuggestion
)
8639 for i in result-alist
8640 for data
= (cdr (caadr (assoc 'suggestion i
)))
8641 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
8642 for lqueries
= (length (anything-c-ggs-set-number-result
8644 for ldata
= (length data
)
8647 (when (> ldata anything-ggs-max-length-real-flag
)
8648 (setq anything-ggs-max-length-real-flag ldata
))
8649 (when (> lqueries anything-ggs-max-length-num-flag
)
8650 (setq anything-ggs-max-length-num-flag lqueries
)))
8651 collect
(cons data nqueries
) into cont
8652 finally return cont
)))
8653 (if anything-google-suggest-use-curl-p
8655 (call-process "curl" nil t nil request
)
8657 (with-current-buffer
8658 (url-retrieve-synchronously request
)
8661 (defun anything-c-google-suggest-set-candidates (&optional request-prefix
)
8662 "Set candidates with result and number of google results found."
8664 (loop with suggested-results
= (anything-c-google-suggest-fetch
8665 (or (and request-prefix
8666 (concat request-prefix
" " anything-pattern
))
8668 for
(real . numresult
) in suggested-results
8669 ;; Prepare number of results with ","
8670 for fnumresult
= (anything-c-ggs-set-number-result numresult
)
8671 ;; Calculate number of spaces to add before fnumresult
8672 ;; if it is smaller than longest result
8673 ;; `anything-ggs-max-length-num-flag'.
8676 ;; To be sure it is aligned properly.
8677 for nspaces
= (if (< (length fnumresult
) anything-ggs-max-length-num-flag
)
8678 (- anything-ggs-max-length-num-flag
(length fnumresult
))
8680 ;; Add now the spaces before fnumresult.
8681 for align-fnumresult
= (concat (make-string nspaces ?
) fnumresult
)
8682 for interval
= (- anything-ggs-max-length-real-flag
(length real
))
8683 for spaces
= (make-string (+ 2 interval
) ?
)
8684 for display
= (format "%s%s(%s results)" real spaces align-fnumresult
)
8685 collect
(cons display real
))))
8686 (if (loop for
(disp . dat
) in suggestions
8687 thereis
(equal dat anything-pattern
))
8689 ;; if there is no suggestion exactly matching the input then
8690 ;; prepend a Search on Google item to the list
8693 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
8694 anything-input
))))))
8696 (defun anything-c-ggs-set-number-result (num)
8699 (and (numberp num
) (setq num
(number-to-string num
)))
8700 (loop for i in
(reverse (split-string num
"" t
))
8702 append
(list i
) into C
8704 append
(list ",") into C
8705 and do
(setq count
0)
8707 (replace-regexp-in-string
8708 "^," "" (mapconcat 'identity
(reverse C
) ""))))
8711 (defvar anything-c-google-suggest-default-browser-function nil
8712 "*The browse url function you prefer to use with google suggest.
8713 When nil, use the first browser function available
8714 See `anything-browse-url-default-browser-alist'.")
8716 (defun anything-c-google-suggest-action (candidate)
8717 "Default action to jump to a google suggested candidate."
8718 (let ((arg (concat anything-c-google-suggest-search-url
8719 (url-hexify-string candidate
))))
8720 (anything-aif anything-c-google-suggest-default-browser-function
8722 (anything-c-browse-url arg
))))
8724 (defvar anything-c-google-suggest-default-function
8725 'anything-c-google-suggest-set-candidates
8726 "Default function to use in anything google suggest.")
8728 (defvar anything-c-source-google-suggest
8729 '((name .
"Google Suggest")
8730 (candidates .
(lambda ()
8731 (funcall anything-c-google-suggest-default-function
)))
8732 (action .
(("Google Search" . anything-c-google-suggest-action
)))
8734 (requires-pattern .
3)
8737 (defun anything-c-google-suggest-emacs-lisp ()
8738 "Try to emacs lisp complete with google suggestions."
8739 (anything-c-google-suggest-set-candidates "emacs lisp"))
8741 ;; (anything 'anything-c-source-google-suggest)
8743 ;;; Yahoo suggestions
8746 (defun anything-c-yahoo-suggest-fetch (input)
8747 "Fetch Yahoo suggestions for INPUT from XML buffer.
8748 Return an alist with elements like (data . number_results)."
8749 (let ((request (concat anything-c-yahoo-suggest-url
8750 (url-hexify-string input
))))
8753 with result-alist
= (xml-get-children
8754 (car (xml-parse-region (point-min) (point-max)))
8756 for i in result-alist
8757 collect
(caddr i
))))
8758 (with-current-buffer
8759 (url-retrieve-synchronously request
)
8762 (defun anything-c-yahoo-suggest-set-candidates ()
8763 "Set candidates with Yahoo results found."
8764 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
8768 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
8769 anything-input
))))))
8771 (defun anything-c-yahoo-suggest-action (candidate)
8772 "Default action to jump to a Yahoo suggested candidate."
8773 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8774 (url-hexify-string candidate
))))
8776 (defvar anything-c-source-yahoo-suggest
8777 '((name .
"Yahoo Suggest")
8778 (candidates . anything-c-yahoo-suggest-set-candidates
)
8779 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
8781 (requires-pattern .
3)
8784 ;; (anything 'anything-c-source-yahoo-suggest)
8787 ;;; Web browser functions.
8790 (require 'browse-url
)
8791 ;; If default setting of `w3m-command' is not
8792 ;; what you want you and you modify it, you will have to reeval
8793 ;; also `anything-browse-url-default-browser-alist'.
8794 (defvar w3m-command
"/usr/bin/w3m")
8795 (defvar anything-c-home-url
"http://www.google.fr"
8796 "*Default url to use as home url.")
8798 (defvar browse-url-chromium-program
"chromium-browser")
8799 (defvar browse-url-uzbl-program
"uzbl-browser")
8800 (defvar anything-browse-url-default-browser-alist
8801 `((,w3m-command . w3m-browse-url
)
8802 (,browse-url-firefox-program . browse-url-firefox
)
8803 (,browse-url-chromium-program . browse-url-chromium
)
8804 (,browse-url-uzbl-program . browse-url-uzbl
)
8805 (,browse-url-kde-program . browse-url-kde
)
8806 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
8807 (,browse-url-mozilla-program . browse-url-mozilla
)
8808 (,browse-url-galeon-program . browse-url-galeon
)
8809 (,browse-url-netscape-program . browse-url-netscape
)
8810 (,browse-url-mosaic-program . browse-url-mosaic
)
8811 (,browse-url-xterm-program . browse-url-text-xterm
))
8812 "*Alist of (executable . function) to try to find a suitable url browser.")
8814 (defun* anything-c-generic-browser
(url name
&rest args
)
8815 "Browse URL with NAME browser."
8816 (let ((proc (concat name
" " url
)))
8817 (message "Starting %s..." name
)
8818 (apply 'start-process proc nil name
8819 (append args
(list url
)))
8820 (set-process-sentinel
8822 #'(lambda (process event
)
8823 (when (string= event
"finished\n")
8824 (message "%s process %s" process event
))))))
8826 (defun browse-url-chromium (url)
8827 "Browse URL with google chrome browser."
8828 (interactive "sURL: ")
8829 (anything-c-generic-browser
8830 url browse-url-chromium-program
))
8832 (defun browse-url-uzbl (url &optional ignore
)
8833 "Browse URL with uzbl browser."
8834 (interactive "sURL: ")
8835 (anything-c-generic-browser url browse-url-uzbl-program
"-u"))
8837 (defun anything-browse-url-default-browser (url &rest args
)
8838 "Find the first available browser and ask it to load URL."
8839 (let ((default-browser-fn
8840 (loop for
(exe . fn
) in anything-browse-url-default-browser-alist
8841 thereis
(and exe
(executable-find exe
) fn
))))
8842 (if default-browser-fn
8843 (apply default-browser-fn url args
)
8844 (error "No usable browser found"))))
8846 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
8847 "Default command to browse URL."
8848 (if browse-url-browser-function
8850 (anything-browse-url-default-browser url
)))
8855 ;; Need external program surfraw.
8856 ;; <http://surfraw.alioth.debian.org/>
8858 (defvar anything-surfraw-default-browser-function nil
8859 "*The browse url function you prefer to use with surfraw.
8860 When nil, fallback to `browse-url-browser-function'.")
8863 (defvar anything-surfraw-engines-history nil
)
8865 (defun anything-c-build-elvi-list ()
8866 "Return list of all engines and descriptions handled by surfraw."
8869 (call-process "surfraw" nil t nil
8871 (split-string (buffer-string) "\n"))))
8877 (defun anything-emms-stream-edit-bookmark (elm)
8878 "Change the information of current emms-stream bookmark from anything."
8879 (declare (special emms-stream-list
))
8880 (let* ((cur-buf anything-current-buffer
)
8881 (bookmark (assoc elm emms-stream-list
))
8882 (name (read-from-minibuffer "Description: "
8884 (url (read-from-minibuffer "URL: "
8886 (fd (read-from-minibuffer "Feed Descriptor: "
8887 (int-to-string (nth 2 bookmark
))))
8888 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8889 (format "%s" (car (last bookmark
))))))
8892 (when (re-search-forward (concat "^" name
) nil t
)
8894 (emms-stream-delete-bookmark)
8895 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
8896 (emms-stream-save-bookmarks-file)
8898 (anything-c-switch-to-buffer cur-buf
)))))
8900 (defun anything-emms-stream-delete-bookmark (elm)
8901 "Delete an emms-stream bookmark from anything."
8902 (let* ((cur-buf anything-current-buffer
)
8903 (bookmark (assoc elm emms-stream-list
))
8904 (name (nth 0 bookmark
)))
8907 (when (re-search-forward (concat "^" name
) nil t
)
8909 (emms-stream-delete-bookmark)
8910 (emms-stream-save-bookmarks-file)
8912 (anything-c-switch-to-buffer cur-buf
)))))
8914 (defvar anything-c-source-emms-streams
8915 '((name .
"Emms Streams")
8917 (emms-stream-init)))
8918 (candidates .
(lambda ()
8919 (declare (special emms-stream-list
))
8920 (mapcar 'car emms-stream-list
)))
8921 (action .
(("Play" .
(lambda (elm)
8922 (declare (special emms-stream-list
))
8923 (let* ((stream (assoc elm emms-stream-list
))
8924 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
8925 (url (second stream
)))
8927 ("Delete" . anything-emms-stream-delete-bookmark
)
8928 ("Edit" . anything-emms-stream-edit-bookmark
)))
8929 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8930 ;; (anything 'anything-c-source-emms-streams)
8932 ;; Don't forget to set `emms-source-file-default-directory'
8933 (defvar anything-c-source-emms-dired
8934 '((name .
"Music Directory")
8935 (candidates .
(lambda ()
8936 (cddr (directory-files emms-source-file-default-directory
))))
8938 (("Play Directory" .
(lambda (item)
8939 (emms-play-directory
8942 emms-source-file-default-directory
))))
8943 ("Open dired in file's directory" .
(lambda (item)
8944 (anything-c-open-dired
8947 emms-source-file-default-directory
))))))
8948 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
8949 ;; (anything 'anything-c-source-emms-dired)
8952 (defun anything-c-emms-files-modifier (candidates source
)
8953 (let ((current-playlist (with-current-emms-playlist
8955 with cur-list
= (emms-playlist-tracks-in-region
8956 (point-min) (point-max))
8958 collect
(assoc-default 'name i
)))))
8959 (loop for i in candidates
8960 if
(member (cdr i
) current-playlist
)
8961 collect
(cons (propertize (car i
)
8962 'face
'anything-emms-playlist
)
8964 else collect i into lis
8965 finally return lis
)))
8967 (defun anything-c-emms-play-current-playlist ()
8968 "Play current playlist."
8969 (with-current-emms-playlist
8970 (emms-playlist-first)
8971 (emms-playlist-mode-play-smart)))
8973 (defvar anything-c-source-emms-files
8974 '((name .
"Emms files")
8975 (candidates .
(lambda ()
8976 (loop for v being the hash-values in emms-cache-db
8977 for name
= (assoc-default 'name v
)
8978 for artist
= (or (assoc-default 'info-artist v
) "unknown")
8979 for genre
= (or (assoc-default 'info-genre v
) "unknown")
8980 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
8981 for song
= (or (assoc-default 'info-title v
) "unknown")
8982 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
8983 unless
(string-match "^http:" name
) collect
(cons info name
))))
8984 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
8985 (action .
(("Play file" . emms-play-file
)
8986 ("Add to Playlist and play (C-u clear current)"
8987 .
(lambda (candidate)
8988 (when anything-current-prefix-arg
8989 (emms-playlist-current-clear))
8991 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
8992 (unless emms-player-playing-p
8993 (anything-c-emms-play-current-playlist))))))))
8995 ;; (anything 'anything-c-source-emms-files)
8998 ;;; Jabber Contacts (jabber.el)
8999 (defun anything-c-jabber-online-contacts ()
9000 "List online Jabber contacts."
9003 (dolist (item (jabber-concat-rosters) jids
)
9004 (when (get item
'connected
)
9005 (push (if (get item
'name
)
9006 (cons (get item
'name
) item
)
9007 (cons (symbol-name item
) item
)) jids
))))))
9009 (defvar anything-c-source-jabber-contacts
9010 '((name .
"Jabber Contacts")
9011 (init .
(lambda () (require 'jabber
)))
9012 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
9013 (action .
(lambda (x)
9015 (jabber-read-account)
9017 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
9018 ;; (anything 'anything-c-source-jabber-contacts)
9023 (defvar anything-source-select-buffer
"*anything source select*")
9024 (defvar anything-c-source-call-source
9025 `((name .
"Call anything source")
9026 (candidate-number-limit)
9029 (loop for vname in
(all-completions "anything-c-source-" obarray
)
9030 for var
= (intern vname
)
9031 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
9033 (cons (format "%s `%s'"
9034 name
(propertize vname
'face
'font-lock-variable-name-face
))
9037 .
(("Invoke anything with selected source"
9040 (setq anything-candidate-number-limit
9999)
9041 (anything candidate nil nil nil nil
9042 anything-source-select-buffer
)))
9043 ("Describe variable" . describe-variable
)
9044 ("Find variable" . find-variable
)))
9045 (persistent-action . describe-variable
)
9046 (persistent-help .
"Show description of this source")))
9047 ;; (anything 'anything-c-source-call-source)
9049 (defun anything-call-source-from-anything ()
9050 "Call anything source within `anything' session."
9052 (setq anything-input-idle-delay
0)
9053 (anything-set-sources '(anything-c-source-call-source)))
9055 ;;; Execute Preconfigured anything.
9056 (defvar anything-c-source-anything-commands
9057 '((name .
"Preconfigured Anything")
9058 (candidates . anything-c-anything-commands-candidates
)
9060 (candidate-number-limit)))
9061 ;; (anything 'anything-c-source-anything-commands)
9063 (defun anything-c-anything-commands-candidates ()
9064 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
9065 collect
(cons (if (where-is-internal cmd nil t
)
9066 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
9067 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
9074 (defun anything-c-occur-init ()
9075 "Create the initial anything occur buffer.
9076 If region is active use region as buffer contents
9077 instead of whole buffer."
9078 (with-current-buffer (anything-candidate-buffer 'global
)
9081 (with-anything-current-buffer
9082 (if (anything-region-active-p)
9083 (buffer-substring (region-beginning) (region-end))
9084 (buffer-substring (point-min) (point-max))))))
9085 (insert buf-contents
))))
9087 (defun anything-c-occur-get-line (s e
)
9088 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
9090 (defun anything-c-occur-query-replace-regexp (candidate)
9091 "Query replace regexp starting from CANDIDATE.
9092 If region is active ignore CANDIDATE and replace only in region.
9093 With a prefix arg replace only matches surrounded by word boundaries,
9094 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
9095 (let ((regexp anything-input
))
9096 (unless (anything-region-active-p)
9097 (anything-c-action-line-goto candidate
))
9098 (apply 'query-replace-regexp
9099 (anything-c-query-replace-args regexp
))))
9101 (defvar anything-c-source-occur
9103 (init . anything-c-occur-init
)
9104 (candidates-in-buffer)
9106 (get-line . anything-c-occur-get-line
)
9107 (display-to-real . anything-c-display-to-real-line
)
9108 (action .
(("Go to Line" . anything-c-action-line-goto
)
9109 ("Query replace regexp (C-u Not inside word.)"
9110 . anything-c-occur-query-replace-regexp
)))
9112 (requires-pattern .
1)
9115 ;; (anything 'anything-c-source-occur)
9118 ;;; Anything browse code.
9119 (defun anything-c-browse-code-get-line (beg end
)
9120 "Select line if it match the regexp corresponding to current `major-mode'.
9121 Line is parsed for BEG position to END position."
9122 (let ((str-line (buffer-substring beg end
))
9123 (regexp (assoc-default major-mode
9124 anything-c-browse-code-regexp-alist
))
9125 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
9126 (when (and regexp
(string-match regexp str-line
))
9127 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
9130 (defvar anything-c-source-browse-code
9131 '((name .
"Browse code")
9133 (anything-candidate-buffer anything-current-buffer
)
9134 (with-anything-current-buffer
9135 (jit-lock-fontify-now))))
9136 (candidate-number-limit .
9999)
9137 (candidates-in-buffer)
9138 (get-line . anything-c-browse-code-get-line
)
9143 ;; Do many actions for input
9144 (defvar anything-c-source-create
9148 (action-transformer . anything-create--actions
))
9149 "Do many create actions from `anything-pattern'.
9150 See also `anything-create--actions'.")
9151 ;; (anything 'anything-c-source-create)
9153 (defun anything-create-from-anything ()
9154 "Run `anything-create' from `anything' as a fallback."
9156 (anything-run-after-quit 'anything-create nil anything-pattern
))
9158 (defun anything-create--actions (&rest ignored
)
9159 "Default actions for `anything-create' / `anything-c-source-create'."
9161 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
9162 (append anything-create--actions-private
9163 '(("find-file" . find-file
)
9164 ("find-file other window" . find-file-other-window
)
9165 ("New buffer" . anything-c-switch-to-buffer
)
9166 ("New buffer other window" . switch-to-buffer-other-window
)
9167 ("Bookmark Set" . bookmark-set
)
9169 (lambda (x) (set-register (read-char "Register: ") x
)))
9170 ("Insert Linkd star" . linkd-insert-star
)
9171 ("Insert Linkd Tag" . linkd-insert-tag
)
9172 ("Insert Linkd Link" . linkd-insert-link
)
9173 ("Insert Linkd Lisp" . linkd-insert-lisp
)
9174 ("Insert Linkd Wiki" . linkd-insert-wiki
)
9175 ("Google Search" . google
)))))
9178 ;; Minibuffer History
9181 (defvar anything-c-source-minibuffer-history
9182 '((name .
"Minibuffer History")
9183 (header-name .
(lambda (name)
9184 (format "%s (%s)" name minibuffer-history-variable
)))
9187 (let ((history (loop
9188 for i in
(symbol-value minibuffer-history-variable
)
9189 unless
(string= "" i
) collect i
)))
9190 (if (consp (car history
))
9191 (mapcar 'prin1-to-string history
)
9195 ;; (anything 'anything-c-source-minibuffer-history)
9201 (defvar anything-c-source-elscreen
9202 '((name .
"Elscreen")
9203 (candidates .
(lambda ()
9204 (if (cdr (elscreen-get-screen-to-name-alist))
9206 (loop for sname in
(elscreen-get-screen-to-name-alist)
9207 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
9208 finally
(return lst
))
9209 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
9210 (action .
(("Change Screen".
9212 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
9215 (dolist (i (anything-marked-candidates))
9216 (elscreen-goto (- (aref i
1) (aref "0" 0)))
9220 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
9221 (elscreen-kill-others)))))))
9222 ;; (anything 'anything-c-source-elscreen)
9228 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
9229 "Top command (batch mode). %s is replaced with `frame-width'.")
9230 (defvar anything-c-source-top
9231 '((name .
"Top (Press C-c C-u to refresh)")
9232 (init . anything-c-top-init
)
9233 (candidates-in-buffer)
9234 (display-to-real . anything-c-top-display-to-real
)
9235 (update . anything-c-top-update
)
9236 (persistent-action . anything-c-top-sh-persistent-action
)
9237 (persistent-help .
"SIGTERM")
9239 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
9240 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
9241 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
9242 ;; (anything 'anything-c-source-top)
9244 (defun anything-c-top-sh (cmd)
9245 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
9247 (defun anything-c-top-sh-persistent-action (pid)
9248 (delete-other-windows)
9249 (anything-c-top-sh (format "kill -TERM %s" pid
))
9250 (anything-force-update))
9252 (defun anything-c-top-init ()
9253 (with-current-buffer (anything-candidate-buffer 'global
)
9254 (call-process-shell-command
9255 (format anything-c-top-command
9256 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
9257 nil
(current-buffer))))
9259 (defun anything-c-top-display-to-real (line)
9260 (car (split-string line
)))
9262 (defun anything-c-top-update ()
9263 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
9264 (anything-c-top-init)))
9267 (defvar anything-c-source-absolute-time-timers
9268 '((name .
"Absolute Time Timers")
9269 (candidates . timer-list
)
9271 ;; (anything 'anything-c-source-absolute-time-timers)
9273 (defvar anything-c-source-idle-time-timers
9274 '((name .
"Idle Time Timers")
9275 (candidates . timer-idle-list
)
9277 ;; (anything 'anything-c-source-idle-time-timers)
9279 (defun anything-c-timer-real-to-display (timer)
9280 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
9281 (append timer nil
) ;use `append' to convert vector->list
9282 (format "%s repeat=%5S %s(%s)"
9283 (let ((time (list t1 t2 t3
)))
9285 (format-time-string "idle-for=%5s" time
)
9286 (format-time-string "%m/%d %T" time
)))
9289 (mapconcat 'prin1-to-string args
" "))))
9291 ;;; X RandR resolution change
9292 ;;; FIXME I do not care multi-display.
9293 (defvar anything-c-xrandr-output
"VGA")
9294 (defvar anything-c-xrandr-screen
"0")
9295 (defvar anything-c-source-xrandr-change-resolution
9296 '((name .
"Change Resolution")
9300 (call-process "xrandr" nil
(current-buffer) nil
9301 "--screen" anything-c-xrandr-screen
"-q")
9303 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
9304 collect
(match-string 1)))))
9306 ("Change Resolution" .
(lambda (mode)
9307 (call-process "xrandr" nil nil nil
9308 "--screen" anything-c-xrandr-screen
9309 "--output" anything-c-xrandr-output
9311 ;; (anything 'anything-c-source-xrandr-change-resolution)
9316 (defun anything-c-persistent-xfont-action (elm)
9317 "Show current font temporarily"
9318 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
9321 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
9322 (set-frame-font current-font
))))
9324 (defvar anything-c-xfonts-cache nil
)
9325 (defvar anything-c-source-xfonts
9326 '((name .
"X Fonts")
9328 (unless anything-c-xfonts-cache
9329 (setq anything-c-xfonts-cache
9330 (x-list-fonts "*")))))
9331 (candidates . anything-c-xfonts-cache
)
9332 (action .
(("Copy to kill ring" .
(lambda (elm)
9334 ("Set Font" .
(lambda (elm)
9336 (set-frame-font elm
'keep-size
)
9337 (message "New font have been copied to kill ring")))))
9338 (persistent-action . anything-c-persistent-xfont-action
)
9339 (persistent-help .
"Switch to this font temporarily")))
9340 ;; (anything 'anything-c-source-xfonts)
9342 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
9345 (defvar anything-c-ucs-max-len
0)
9346 (defun anything-c-calculate-ucs-max-len ()
9347 "Calculate the length of longest `ucs-names' candidate."
9348 (loop with count
= 0
9349 for
(n . v
) in
(ucs-names)
9350 for len
= (length n
)
9353 finally return count
))
9355 (defun anything-c-ucs-init ()
9356 "Initialize an anything buffer with ucs symbols.
9357 Only math* symbols are collected."
9358 (unless (> anything-c-ucs-max-len
0)
9359 (setq anything-c-ucs-max-len
9360 (anything-c-calculate-ucs-max-len)))
9361 (with-current-buffer (anything-candidate-buffer
9362 (get-buffer-create "*anything ucs*"))
9363 ;; `ucs-names' fn will not run again, data is cached in
9365 (loop for
(n . v
) in
(ucs-names)
9366 for len
= (length n
)
9367 for diff
= (+ (- anything-c-ucs-max-len len
) 2)
9368 unless
(string= "" n
)
9369 do
(progn (insert (concat
9376 (defun anything-c-ucs-forward-char (candidate)
9377 (with-anything-current-buffer
9380 (defun anything-c-ucs-backward-char (candidate)
9381 (with-anything-current-buffer
9384 (defun anything-c-ucs-delete-backward (candidate)
9385 (with-anything-current-buffer
9388 (defun anything-c-ucs-insert-char (candidate)
9389 (with-anything-current-buffer
9391 (replace-regexp-in-string
9393 (cadr (split-string candidate
":"))))))
9395 (defun anything-c-ucs-persistent-insert ()
9397 (anything-execute-persistent-action 'action-insert
))
9399 (defun anything-c-ucs-persistent-forward ()
9401 (anything-execute-persistent-action 'action-forward
))
9403 (defun anything-c-ucs-persistent-backward ()
9405 (anything-execute-persistent-action 'action-back
))
9407 (defun anything-c-ucs-persistent-delete ()
9409 (anything-execute-persistent-action 'action-delete
))
9411 (defvar anything-c-source-ucs
9412 '((name .
"Ucs names")
9413 (init . anything-c-ucs-init
)
9414 (candidate-number-limit .
9999)
9415 (candidates-in-buffer)
9416 (mode-line . anything-c-ucs-mode-line-string
)
9417 (action-insert . anything-c-ucs-insert-char
)
9418 (action-forward . anything-c-ucs-forward-char
)
9419 (action-back . anything-c-ucs-backward-char
)
9420 (action-delete . anything-c-ucs-delete-backward
)
9421 (action .
(("Insert" . anything-c-ucs-insert-char
)
9422 ("Forward char" . anything-c-ucs-forward-char
)
9423 ("Backward char" . anything-c-ucs-backward-char
)
9424 ("Delete char backward" . anything-c-ucs-delete-backward
))))
9425 "Source for collecting `ucs-names' math symbols.")
9431 (defvar anything-c-source-emacs-process
9432 '((name .
"Emacs Process")
9433 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
9434 (persistent-action .
(lambda (elm)
9435 (delete-process (get-process elm
))
9436 (anything-delete-current-selection)))
9437 (persistent-help .
"Kill Process")
9438 (action ("Kill Process" .
(lambda (elm)
9439 (delete-process (get-process elm
)))))))
9440 ;; (anything 'anything-c-source-emacs-process)
9445 (defvar anything-c-source-time-world
9446 '((name .
"Time World List")
9448 (let ((anything-buffer (anything-candidate-buffer 'global
)))
9449 (with-current-buffer anything-buffer
9450 (display-time-world-display display-time-world-list
)))))
9451 (candidates-in-buffer)))
9455 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
9458 (defvar anything-c-source-apt
9460 (init . anything-c-apt-init
)
9461 (candidates-in-buffer)
9462 (candidate-transformer anything-c-apt-candidate-transformer
)
9463 (display-to-real . anything-c-apt-display-to-real
)
9464 (requires-pattern .
2)
9467 ("Show package description" . anything-c-apt-cache-show
)
9468 ("Install package" . anything-c-apt-install
)
9469 ("Remove package" . anything-c-apt-uninstall
)
9470 ("Purge package" . anything-c-apt-purge
))
9471 (persistent-action . anything-c-apt-persistent-action
)
9472 (persistent-help .
"Show - C-u Refresh")))
9473 ;; (anything 'anything-c-source-apt)
9475 (defvar anything-c-apt-query
"emacs")
9476 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
9477 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
9478 (defvar anything-c-apt-installed-packages nil
)
9479 (defvar anything-c-apt-all-packages nil
)
9482 (defun anything-c-apt-refresh ()
9483 "Refresh installed candidates list."
9484 (setq anything-c-apt-installed-packages nil
)
9485 (setq anything-c-apt-all-packages nil
)
9486 (anything-force-update))
9488 (defun anything-c-apt-persistent-action (candidate)
9489 "Persistent action for APT source."
9490 (if current-prefix-arg
9491 (anything-c-apt-refresh)
9492 (anything-c-apt-cache-show candidate
)))
9494 (defun anything-c-apt-candidate-transformer (candidates)
9495 "Show installed candidates in a different color."
9498 for cand in candidates
9499 for name
= (anything-c-apt-display-to-real cand
)
9500 if
(member name anything-c-apt-installed-packages
)
9501 collect
(propertize cand
'face
'anything-apt-installed
) into all
9502 else collect cand into all finally return all
))
9504 (defun anything-c-apt-init ()
9505 "Initialize list of debian packages."
9507 (unless (and anything-c-apt-installed-packages
9508 anything-c-apt-all-packages
)
9509 (message "Loading package list...")
9510 (setq anything-c-apt-installed-packages
9512 (call-process-shell-command "dpkg --get-selections"
9513 nil
(current-buffer))
9514 (loop for i in
(split-string (buffer-string) "\n" t
)
9515 collect
(car (split-string i
)))))
9516 (setq anything-c-apt-all-packages
9517 (with-current-buffer
9518 (anything-candidate-buffer
9519 (get-buffer-create (format "*anything-apt*")))
9521 (call-process-shell-command
9522 (format anything-c-apt-search-command query
)
9523 nil
(current-buffer))))
9524 (message "Loading package list done")
9527 (defun anything-c-apt-display-to-real (line)
9528 "Return only name of a debian package.
9529 LINE is displayed like:
9530 package name - description."
9531 (car (split-string line
" - ")))
9533 (defun anything-c-shell-command-if-needed (command)
9534 "Run shell command COMMAND to describe package.
9535 If a buffer named COMMAND already exists, just switch to it."
9536 (let ((buf (get-buffer command
)))
9537 (anything-c-switch-to-buffer (get-buffer-create command
))
9538 (unless buf
(insert (shell-command-to-string command
)))))
9540 (defun anything-c-apt-cache-show (package)
9541 "Show information on apt package PACKAGE."
9542 (anything-c-shell-command-if-needed
9543 (format anything-c-apt-show-command package
)))
9545 (defun anything-c-apt-install (package)
9546 "Run 'apt-get install' shell command on PACKAGE."
9547 (anything-c-apt-generic-action :action
'install
))
9549 (defun anything-c-apt-uninstall (package)
9550 "Run 'apt-get remove' shell command on PACKAGE."
9551 (anything-c-apt-generic-action :action
'uninstall
))
9553 (defun anything-c-apt-purge (package)
9554 "Run 'apt-get purge' shell command on PACKAGE."
9555 (anything-c-apt-generic-action :action
'purge
))
9557 (defun* anything-c-apt-generic-action
(&key action
)
9558 "Run 'apt-get ACTION'.
9559 Support install, remove and purge actions."
9560 (ansi-term (getenv "SHELL") "anything apt")
9562 (let ((command (case action
9563 ('install
"sudo apt-get install ")
9564 ('uninstall
"sudo apt-get remove ")
9565 ('purge
"sudo apt-get purge ")
9566 (t (error "Unknow action"))))
9569 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x
))
9570 (anything-marked-candidates) " ")))
9571 (goto-char (point-max))
9572 (insert (concat command cand-list
))
9574 (if (y-or-n-p (format "%s package" (symbol-name action
)))
9576 (setq anything-c-external-commands-list nil
)
9577 (setq anything-c-apt-installed-packages nil
)
9578 (term-char-mode) (term-send-input))
9579 (delete-region beg end
) (term-send-eof) (kill-buffer))))
9581 ;; (anything-c-apt-install "jed")
9584 ;;; Anything UI for gentoo portage.
9587 (defvar anything-c-gentoo-use-flags nil
)
9588 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
9589 (defvar anything-c-cache-gentoo nil
)
9590 (defvar anything-c-cache-world nil
)
9591 (defvar anything-c-source-gentoo
9592 '((name .
"Portage sources")
9594 (get-buffer-create anything-c-gentoo-buffer
)
9595 (unless anything-c-cache-gentoo
9596 (anything-c-gentoo-setup-cache))
9597 (unless anything-c-cache-world
9598 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
9599 (anything-c-gentoo-init-list)))
9600 (candidates-in-buffer)
9602 (candidate-transformer anything-c-highlight-world
)
9603 (action .
(("Show package" .
(lambda (elm)
9604 (anything-c-gentoo-eshell-action elm
"eix")))
9605 ("Show history" .
(lambda (elm)
9606 (if (member elm anything-c-cache-world
)
9607 (anything-c-gentoo-eshell-action elm
"genlop -qe")
9608 (message "No infos on packages not yet installed"))))
9609 ("Copy in kill-ring" . kill-new
)
9610 ("insert at point" . insert
)
9611 ("Browse HomePage" .
(lambda (elm)
9612 (let ((urls (anything-c-gentoo-get-url elm
)))
9613 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
9614 ("Show extra infos" .
(lambda (elm)
9615 (if (member elm anything-c-cache-world
)
9616 (anything-c-gentoo-eshell-action elm
"genlop -qi")
9617 (message "No infos on packages not yet installed"))))
9618 ("Show use flags" .
(lambda (elm)
9619 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
9620 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
9621 (font-lock-mode 1)))
9622 ("Run emerge pretend" .
(lambda (elm)
9623 (anything-c-gentoo-eshell-action elm
"emerge -p")))
9624 ("Emerge" .
(lambda (elm)
9625 (anything-gentoo-install elm
:action
'install
)))
9626 ("Unmerge" .
(lambda (elm)
9627 (anything-gentoo-install elm
:action
'uninstall
)))
9628 ("Show dependencies" .
(lambda (elm)
9629 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
9630 ("Show related files" .
(lambda (elm)
9631 (anything-c-gentoo-default-action elm
"equery" "files")))
9632 ("Refresh" .
(lambda (elm)
9633 (anything-c-gentoo-setup-cache)
9634 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
9636 ;; (anything 'anything-c-source-gentoo)
9638 (defun* anything-gentoo-install
(candidate &key action
)
9639 (setq anything-c-external-commands-list nil
)
9640 (ansi-term (getenv "SHELL") "Gentoo emerge")
9642 (let ((command (case action
9643 ('install
"sudo emerge -av ")
9644 ('uninstall
"sudo emerge -avC ")
9645 (t (error "Unknow action"))))
9646 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
9648 (goto-char (point-max))
9649 (insert (concat command elms
))
9651 (term-char-mode) (term-send-input)))
9653 (defun anything-c-gentoo-default-action (elm command
&rest args
)
9654 "Gentoo default action that use `anything-c-gentoo-buffer'."
9655 (if (member elm anything-c-cache-world
)
9657 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9659 (let ((com-list (append args
(list elm
))))
9660 (apply #'call-process command nil t nil
9662 (message "No infos on packages not yet installed")))
9664 (defvar anything-c-source-use-flags
9665 '((name .
"Use Flags")
9667 (unless anything-c-gentoo-use-flags
9668 (anything-c-gentoo-setup-use-flags-cache))
9669 (anything-c-gentoo-get-use)))
9670 (candidates-in-buffer)
9672 (candidate-transformer anything-c-highlight-local-use
)
9673 (action .
(("Description"
9675 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9677 (apply #'call-process
"euse" nil t nil
9680 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
9681 (font-lock-mode 1)))
9684 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
9687 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
9690 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
9691 ("Show which dep use this flag"
9693 (anything-c-switch-to-buffer anything-c-gentoo-buffer
)
9695 (apply #'call-process
"equery" nil t nil
9701 ;; (anything 'anything-c-source-use-flags)
9703 (defun anything-c-gentoo-init-list ()
9704 "Initialize buffer with all packages in Portage."
9705 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9706 (buf (anything-candidate-buffer 'portage-buf
)))
9707 (with-current-buffer buf
9708 (dolist (i anything-c-cache-gentoo
)
9709 (insert (concat i
"\n"))))))
9711 (defun anything-c-gentoo-setup-cache ()
9712 "Set up `anything-c-cache-gentoo'"
9713 (setq anything-c-cache-gentoo
9714 (split-string (with-temp-buffer
9715 (call-process "eix" nil t nil
9719 (defun anything-c-gentoo-eshell-action (elm command
)
9720 (when (get-buffer "*EShell Command Output*")
9721 (kill-buffer "*EShell Command Output*"))
9722 (message "Wait searching...")
9723 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
9724 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
9726 (save-window-excursion
9727 (pop-to-buffer "*scratch*")
9728 (eshell-command (format "%s %s" command elm
)))
9729 (pop-to-buffer "*EShell Command Output*"))
9730 (eshell-command (format "%s %s" command elm
)))))
9732 (defun anything-c-gentoo-get-use ()
9733 "Initialize buffer with all use flags."
9734 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9735 (buf (anything-candidate-buffer 'use-buf
)))
9736 (with-current-buffer buf
9737 (dolist (i anything-c-gentoo-use-flags
)
9738 (insert (concat i
"\n"))))))
9741 (defun anything-c-gentoo-setup-use-flags-cache ()
9742 "Setup `anything-c-gentoo-use-flags'"
9743 (setq anything-c-gentoo-use-flags
9744 (split-string (with-temp-buffer
9745 (call-process "eix" nil t nil
9746 "--print-all-useflags")
9749 (defun anything-c-gentoo-get-url (elm)
9750 "Return a list of urls from eix output."
9752 with url-list
= (split-string
9754 (call-process "eix" nil t nil
9755 elm
"--format" "<homepage>\n")
9759 when
(and (string-match "^http://.*" i
)
9760 (not (member i all
)))
9762 finally return all
))
9764 (defun anything-c-gentoo-get-world ()
9765 "Return list of all installed package on your system."
9766 (split-string (with-temp-buffer
9767 (call-process "qlist" nil t nil
9771 (defun anything-c-gentoo-get-local-use ()
9772 (split-string (with-temp-buffer
9773 (call-process "portageq" nil t nil
9779 (defun anything-c-highlight-world (eix)
9780 "Highlight all installed package."
9782 if
(member i anything-c-cache-world
)
9783 collect
(propertize i
'face
'anything-gentoo-match-face
)
9787 (defun anything-c-highlight-local-use (use-flags)
9788 (let ((local-uses (anything-c-gentoo-get-local-use)))
9789 (loop for i in use-flags
9790 if
(member i local-uses
)
9791 collect
(propertize i
'face
'anything-gentoo-match-face
)
9797 ;;; Anything ratpoison UI
9800 (defvar anything-c-source-ratpoison-commands
9801 '((name .
"Ratpoison Commands")
9802 (init . anything-c-ratpoison-commands-init
)
9803 (candidates-in-buffer)
9804 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
9805 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
9806 (candidate-number-limit)))
9807 ;; (anything 'anything-c-source-ratpoison-commands)
9809 (defun anything-c-ratpoison-commands-init ()
9810 (unless (anything-candidate-buffer)
9811 (with-current-buffer (anything-candidate-buffer 'global
)
9812 ;; with ratpoison prefix key
9814 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
9815 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9816 (replace-match "<ratpoison> \\1: \\2"))
9817 (goto-char (point-max))
9820 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
9821 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
9822 (replace-match "\\1: \\2")))))
9824 (defun anything-c-ratpoison-commands-display-to-real (display)
9825 (and (string-match ": " display
)
9826 (substring display
(match-end 0))))
9828 (defun anything-c-ratpoison-commands-execute (candidate)
9829 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
9833 ;;; Anything `completing-read' replacement
9836 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp
)
9837 "Convert COLLECTION to list removing elements that don't match TEST.
9838 SORT-FN is a predicate to sort COLLECTION.
9839 ALISTP is a flag to not use `all-completions' which doesn't handle alists correctly\
9841 If collection is an `obarray', a TEST is needed. See `obarray'."
9843 (cond ((and (eq collection obarray
) test
)
9844 (all-completions "" collection test
))
9845 ((and (vectorp collection
) test
)
9846 (loop for i across collection when
(funcall test i
) collect i
))
9847 ((vectorp collection
)
9848 (loop for i across collection collect i
))
9850 (loop for i in collection when
(funcall test i
) collect i
))
9852 ((and collection test
)
9853 (all-completions "" collection test
))
9854 (t (all-completions "" collection
)))))
9855 (if sort-fn
(sort cands sort-fn
) cands
)))
9857 (defun anything-cr-default-transformer (candidates source
)
9858 "Default filter candidate function for `anything-comp-read'.
9859 Do nothing, just return candidate list unmodified."
9862 (defun* anything-comp-read
(prompt collection
9868 (buffer "*Anything Completions*")
9870 (requires-pattern 0)
9872 (persistent-action nil
)
9873 (persistent-help "DoNothing")
9874 (name "Anything Completions")
9877 (fc-transformer 'anything-cr-default-transformer
)
9878 (marked-candidates nil
)
9880 "Anything `completing-read' emulation.
9881 PROMPT is the prompt name to use.
9882 COLLECTION can be a list, vector, obarray or hash-table.
9885 TEST: A predicate called with one arg i.e candidate.
9886 INITIAL-INPUT: Same as initial-input arg in `anything'.
9887 PRESELECT: See preselect arg of `anything'.
9888 DEFAULT: This option is used only for compatibility with regular
9889 Emacs `completing-read'.
9890 BUFFER: Name of anything-buffer.
9891 MUST-MATCH: Candidate selected must be one of COLLECTION.
9892 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9893 HISTORY: A list containing specific history, default is nil.
9894 When it is non--nil, all elements of HISTORY are displayed in
9895 anything-buffer before COLLECTION.
9896 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9897 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9898 NAME: The name related to this local source.
9899 VOLATILE: Use volatile attribute.
9900 SORT: A predicate to give to `sort' e.g `string-lessp'.
9901 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9902 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9903 ALISTP: when non--nil \(default\) cdr of alist is returned otherwise it is the car.
9905 Any prefix args passed during `anything-comp-read' invocation will be recorded
9906 in `anything-current-prefix-arg', otherwise if prefix args where given before
9907 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9908 That's mean you can pass prefix arg before or after calling
9909 a command that use `anything-comp-read'.
9910 It support now also a function as argument, See `all-completions' for more details."
9911 (when (get-buffer anything-action-buffer
)
9912 (kill-buffer anything-action-buffer
))
9913 (flet ((action-fn (candidate)
9914 (if marked-candidates
9915 (anything-marked-candidates)
9916 (identity candidate
))))
9917 (let ((hist `((name .
,(format "%s History" name
))
9918 (candidates .
(lambda ()
9919 (let ((all (anything-comp-read-get-candidates
9920 history nil nil
,alistp
)))
9921 (if (and default
(not (string= default
"")))
9922 (delq nil
(cons default
(delete default all
)))
9924 (persistent-action .
,persistent-action
)
9925 (persistent-help .
,persistent-help
)
9926 (action .
,'action-fn
)))
9927 (src `((name .
,name
)
9930 (let ((cands (anything-comp-read-get-candidates
9931 collection test sort alistp
)))
9932 (unless (or must-match
(string= anything-pattern
""))
9933 (setq cands
(append (list anything-pattern
) cands
)))
9934 (if (and default
(not (string= default
"")))
9935 (delq nil
(cons default
(delete default cands
)))
9937 (filtered-candidate-transformer ,fc-transformer
)
9938 (requires-pattern .
,requires-pattern
)
9939 (persistent-action .
,persistent-action
)
9940 (persistent-help .
,persistent-help
)
9941 (action .
,'action-fn
))))
9942 (when volatile
(setq src
(append src
'((volatile)))))
9944 :sources
`(,hist
,src
)
9945 :input initial-input
9947 :preselect preselect
9953 ;; Generic completing-read
9955 ;; Support also function as collection.
9956 ;; e.g M-x man is supported.
9957 ;; Support hash-table and vectors as collection.
9959 ;; Some crap emacs functions may not be supported
9960 ;; like ffap-alternate-file (bad use of completing-read)
9961 ;; and maybe others.
9962 ;; Provide a mode `anything-completion-mode' which turn on
9963 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9965 (defun anything-completing-read-default
9966 (prompt collection
&optional
9967 predicate require-match
9968 initial-input hist def
9969 inherit-input-method
)
9970 "An anything replacement of `completing-read'.
9971 This function should be used only as a `completing-read-function'.
9973 Don't use it directly, use instead `anything-comp-read' in your programs \
9974 which is more powerful.
9976 See documentation of `completing-read' and `all-completions' for details."
9977 (let ((init initial-input
)
9978 (anything-candidate-number-limit 9999))
9982 :fc-transformer
#'(lambda (candidates source
)
9983 (loop for i in candidates
9984 if
(consp i
) collect
(car i
)
9986 :history
(eval (or (car-safe hist
) hist
))
9987 :must-match require-match
9991 :initial-input init
)))
9993 (defun anything-generic-read-file-name
9994 (prompt &optional dir default-filename mustmatch initial predicate
)
9995 "An anything replacement of `read-file-name'."
9996 (let* ((default (and default-filename
9997 (if (listp default-filename
)
9998 (car default-filename
)
10000 (init (or default initial dir default-directory
))
10001 (ini-input (and init
(expand-file-name init
)))
10002 (anything-ff-auto-update-flag nil
))
10003 (anything-c-read-file-name prompt
10004 :initial-input
(expand-file-name init dir
)
10006 :must-match mustmatch
10009 (defvar anything-completion-mode-string
" AC")
10011 (define-minor-mode anything-completion-mode
10012 "Toggle generic anything completion.
10013 All functions in Emacs that use `completing-read'
10014 or `read-file-name' and friends will use anything interface
10015 when this mode is turned on.
10016 Called with a positive arg, turn on inconditionnaly, with a
10017 negative arg turn off.
10018 You can turn it on with `ac-mode'.
10020 Some crap emacs functions may not be supported,
10021 e.g `ffap-alternate-file' and maybe others."
10024 :lighter anything-completion-mode-string
10025 (declare (special completing-read-function
))
10026 (if anything-completion-mode
10028 (setq completing-read-function
'anything-completing-read-default
10029 read-file-name-function
'anything-generic-read-file-name
)
10030 (message "Anything completion enabled"))
10031 (setq completing-read-function
'completing-read-default
10032 read-file-name-function
'read-file-name-default
)
10033 (message "Anything completion disabled")))
10035 (defalias 'ac-mode
'anything-completion-mode
)
10039 ;;; Eshell completion.
10041 ;; Enable like this in .emacs:
10043 ;; (add-hook 'eshell-mode-hook
10045 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
10047 (defvar anything-c-source-esh
10048 '((name .
"Eshell completions")
10050 (setq pcomplete-current-completions nil
10051 pcomplete-last-completion-raw nil
)))
10052 (candidates . anything-esh-get-candidates
)
10053 (action . anything-ec-insert
))
10054 "Anything source for Eshell completion.")
10057 (defvar anything-ec-target
"")
10058 (defun anything-ec-insert (candidate)
10059 "Insert CANDIDATE at point.
10060 This is the same as `ac-insert', just inlined here for compatibility."
10061 (let ((pt (point)))
10062 (when (and anything-ec-target
10063 (search-backward anything-ec-target nil t
)
10064 (string= (buffer-substring (point) pt
) anything-ec-target
))
10065 (delete-region (point) pt
)))
10066 (insert candidate
))
10068 (defun anything-esh-get-candidates ()
10069 "Get candidates for eshell completion using `pcomplete'."
10071 (let* ((pcomplete-stub)
10072 pcomplete-seen pcomplete-norm-func
10073 pcomplete-args pcomplete-last pcomplete-index
10074 (pcomplete-autolist pcomplete-autolist
)
10075 (pcomplete-suffix-list pcomplete-suffix-list
))
10076 (with-anything-current-buffer
10078 with table
= (pcomplete-completions)
10079 with entry
= (condition-case nil
10081 (funcall (pcomplete-entries) anything-pattern nil nil
)
10082 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
10085 (let ((fc (car (last (pcomplete-parse-arguments)))))
10086 ;; Check if last arg require fname completion.
10087 (and (file-name-directory fc
) fc
))))
10088 for i in
(if (listp table
) table
; Emacs23 or commands.
10089 (all-completions pcomplete-stub table
)) ; Emacs24
10090 for file-cand
= (and entry
(expand-file-name i
(file-name-directory entry
)))
10091 if
(and file-cand
(file-exists-p file-cand
)) collect file-cand into ls
10092 else collect i into ls
10094 (if (and entry
(not (string= entry
"")) (file-exists-p entry
))
10095 (append (list (expand-file-name entry default-directory
)) ls
) ls
))))))
10097 ;;; Eshell history.
10100 (defvar anything-c-source-eshell-history
10101 '((name .
"Eshell history")
10103 (with-current-buffer (anything-candidate-buffer 'global
)
10104 (insert-file-contents eshell-history-file-name
))))
10105 (candidates-in-buffer)
10106 (filtered-candidate-transformer .
(lambda (candidates sources
)
10107 (reverse candidates
)))
10108 (candidate-number-limit .
9999)
10109 (action .
(lambda (candidate)
10110 (insert candidate
))))
10111 "Anything source for Eshell history.")
10114 ;;; Show completion - an alternative of anything-show-completion.el.
10116 ;; Provide show completion with macro `with-anything-show-completion'.
10120 (defvar anything-c-show-completion-overlay nil
)
10122 ;; Called each time cursor move in anything-buffer.
10123 (defun anything-c-show-completion ()
10124 (with-anything-current-buffer
10125 (overlay-put anything-c-show-completion-overlay
10126 'display
(anything-get-selection))))
10128 (defun anything-c-show-completion-init-overlay (beg end
)
10129 (with-anything-current-buffer
10130 (and anything-c-turn-on-show-completion
10131 (setq anything-c-show-completion-overlay
(make-overlay beg end
))
10132 (overlay-put anything-c-show-completion-overlay
10133 'face
'anything-lisp-show-completion
))))
10135 (defmacro with-anything-show-completion
(beg end
&rest body
)
10136 "Show anything candidate in an overlay at point.
10137 BEG and END are the beginning and end position of the current completion
10138 in `anything-current-buffer'.
10139 BODY is an anything call where we want to enable show completion.
10140 If `anything-c-turn-on-show-completion' is nil just do nothing."
10141 (declare (indent 2) (debug t
))
10142 `(let ((anything-move-selection-after-hook
10143 (and anything-c-turn-on-show-completion
10144 (append (list 'anything-c-show-completion
)
10145 anything-move-selection-after-hook
))))
10147 (progn (anything-c-show-completion-init-overlay ,beg
,end
)
10149 (and anything-c-turn-on-show-completion
10150 (delete-overlay anything-c-show-completion-overlay
)))))
10153 ;;; Lisp symbol completion.
10157 (defun anything-lisp-completion-at-point ()
10158 "Anything lisp symbol completion at point."
10160 (let* ((data (lisp-completion-at-point))
10162 (end (point)) ; 'cadr data' is wrong when no space after point.
10163 (plist (nthcdr 3 data
))
10164 (pred (plist-get plist
:predicate
))
10166 (target (and beg end
(buffer-substring-no-properties beg end
)))
10167 (candidates (all-completions target
(nth 2 data
) pred
))
10168 (anything-quit-if-no-candidate t
)
10169 (anything-execute-action-at-once-if-one t
)
10170 (anything-match-plugin-enabled
10171 (member 'anything-compile-source--match-plugin
10172 anything-compile-source-functions
)))
10174 (with-anything-show-completion beg end
10175 ;; Overlay is initialized now in anything-current-buffer.
10178 '((name .
"Lisp completion")
10180 (with-current-buffer (anything-candidate-buffer 'global
)
10181 (loop for sym in candidates
10182 for len
= (length sym
)
10183 when
(> len lgst-len
) do
(setq lgst-len len
)
10184 do
(insert (concat sym
"\n"))))))
10185 (candidates-in-buffer)
10186 (persistent-action .
(lambda (candidate)
10187 (let ((cursor-in-echo-area t
)
10188 mode-line-in-non-selected-windows
)
10189 (anything-c-eldoc-show-in-mode-line
10191 (anything-c-get-first-line-documentation
10192 (intern candidate
))
10193 'face
'anything-lisp-completion-info
)))))
10194 (persistent-help .
"Show brief doc in mode-line")
10195 (filtered-candidate-transformer anything-lisp-completion-transformer
)
10196 (action .
(lambda (candidate)
10197 (delete-region beg end
)
10198 (insert candidate
))))
10199 :input
(if anything-match-plugin-enabled
(concat target
" ") target
)))
10200 (message "[No Match]"))))
10202 (defun anything-lisp-completion-transformer (candidates source
)
10203 "Anything candidates transformer for lisp completion."
10204 (declare (special lgst-len
))
10205 (loop for c in candidates
10206 for sym
= (intern c
)
10207 for annot
= (cond ((commandp sym
) " (Com)")
10208 ((fboundp sym
) " (Fun)")
10209 ((boundp sym
) " (Var)")
10210 ((facep sym
) " (Face)"))
10211 for spaces
= (make-string (- lgst-len
(length c
)) ?
)
10212 collect
(cons (concat c spaces annot
) c
)))
10214 (defun anything-c-get-first-line-documentation (sym)
10215 "Return first line documentation of symbol SYM.
10216 If SYM is not documented, return \"Not documented\"."
10217 (let ((doc (cond ((fboundp sym
)
10218 (documentation sym t
))
10220 (documentation-property sym
'variable-documentation t
))
10222 (face-documentation sym
))
10224 (if (and doc
(not (string= doc
""))
10225 ;; `documentation' return "\n\n(args...)"
10226 ;; for CL-style functions.
10227 (not (string-match-p "^\n\n" doc
)))
10228 (car (split-string doc
"\n"))
10229 "Not documented")))
10231 ;;; File completion.
10233 ;; Complete file name at point.
10234 (defun anything-c-thing-before-point ()
10235 "Get symbol name before point.
10236 Borrowed from anything-complete.el, inlined here for compatibility."
10238 (let ((beg (point)))
10239 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10240 (when (re-search-backward
10241 "\\_<" (field-beginning nil nil
(point-at-bol)) t
)
10242 (buffer-substring-no-properties beg
(match-end 0))))))
10245 (defun anything-c-complete-file-name-at-point ()
10246 "Complete file name at point."
10248 (let* ((init (substring-no-properties (thing-at-point 'filename
)))
10250 (beg (- (point) (length init
)))
10251 (anything-quit-if-no-candidate t
)
10252 (anything-execute-action-at-once-if-one t
)
10254 (with-anything-show-completion beg end
10255 (setq completion
(anything-c-read-file-name "FileName: "
10256 :initial-input init
10258 (anything-c-insert-file-name-completion-at-point completion
)))
10261 (defvar anything-lisp-completion-counter
0)
10263 (defun anything-lisp-completion-at-point-or-indent (arg)
10264 "First call indent and second call complete lisp symbol.
10265 The second call should happen before `anything-lisp-completion-or-indent-delay',
10266 after this delay, next call will indent again.
10267 After completion, next call is always indent.
10268 See that like click and double mouse click.
10269 One hit indent, two quick hits maybe indent and complete."
10271 ;; Be sure `indent-for-tab-command' will not try
10272 ;; to use `completion-at-point'.
10273 (let ((tab-always-indent (if (eq tab-always-indent
'complete
)
10274 t tab-always-indent
)))
10275 (incf anything-lisp-completion-counter
)
10277 (if (> anything-lisp-completion-counter
1)
10278 (anything-lisp-completion-or-file-name-at-point)
10279 (indent-for-tab-command arg
))
10280 ;; After `anything-lisp-completion-or-indent-delay' seconds
10282 (run-with-timer anything-lisp-completion-or-indent-delay nil
10284 (setq anything-lisp-completion-counter
0)))
10285 ;; Always reset to 0 at second hit.
10286 (when (eq anything-lisp-completion-counter
2)
10287 (setq anything-lisp-completion-counter
0)))))
10290 (defun anything-lisp-completion-or-file-name-at-point ()
10291 "Complete lisp symbol or filename at point.
10292 Filename completion happen if filename is started in
10293 or between double quotes."
10295 (let ((tap (substring-no-properties (thing-at-point 'filename
))))
10296 (if (and tap
(string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap
)
10297 (save-excursion (search-backward "\"" (point-at-bol) t
)))
10298 (anything-c-complete-file-name-at-point)
10299 (anything-lisp-completion-at-point))))
10303 ;;; Run Externals commands within Emacs with anything completion
10306 (defvar anything-external-command-history nil
)
10308 (defun anything-c-external-commands-list-1 (&optional sort
)
10309 "Returns a list of all external commands the user can execute.
10310 If `anything-c-external-commands-list' is non-nil it will
10311 return its contents. Else it calculates all external commands
10312 and sets `anything-c-external-commands-list'."
10313 (if anything-c-external-commands-list
10314 anything-c-external-commands-list
10315 (setq anything-c-external-commands-list
10317 with paths
= (split-string (getenv "PATH") path-separator
)
10318 with completions
= ()
10320 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
10321 for lsdir
= (loop for i in
(directory-files dir t
)
10322 for bn
= (file-name-nondirectory i
)
10323 when
(and (not (member bn completions
))
10324 (not (file-directory-p i
))
10325 (file-executable-p i
))
10327 append lsdir into completions
10328 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
10330 (defun anything-run-or-raise (exe &optional file
)
10331 "Generic command that run asynchronously EXE.
10332 If EXE is already running just jump to his window if `anything-raise-command'
10334 When FILE argument is provided run EXE with FILE.
10335 In this case EXE must be provided as \"EXE %s\"."
10336 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10338 (proc (if file
(concat real-com
" " file
) real-com
)))
10339 (if (get-process proc
)
10340 (if anything-raise-command
10341 (shell-command (format anything-raise-command real-com
))
10342 (error "Error: %s is already running" real-com
))
10343 (when (loop for i in anything-c-external-commands-list thereis real-com
)
10344 (message "Starting %s..." real-com
)
10346 (start-process-shell-command proc nil
(format exe file
))
10347 (start-process-shell-command proc nil real-com
))
10348 (set-process-sentinel
10350 #'(lambda (process event
)
10351 (when (and (string= event
"finished\n")
10352 anything-raise-command
10353 (not (anything-c-get-pid-from-process-name real-com
)))
10354 (shell-command (format anything-raise-command
"emacs")))
10355 (message "%s process...Finished." process
))))
10356 (setq anything-c-external-commands-list
10358 (delete real-com anything-c-external-commands-list
))))))
10362 ;;; Generic action functions
10365 (defun anything-c-file-buffers (filename)
10366 "Returns a list of buffer names corresponding to FILENAME."
10367 (let ((name (expand-file-name filename
))
10369 (dolist (buf (buffer-list) buf-list
)
10370 (let ((bfn (buffer-file-name buf
)))
10371 (when (and bfn
(string= name bfn
))
10372 (push (buffer-name buf
) buf-list
))))))
10374 (defun anything-revert-buffer (candidate)
10375 (with-current-buffer candidate
10376 (when (or (buffer-modified-p)
10377 (not (verify-visited-file-modtime
10378 (get-buffer candidate
))))
10379 (revert-buffer t t
))))
10381 (defun anything-revert-marked-buffers (ignore)
10382 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
10384 (defun anything-kill-marked-buffers (ignore)
10385 (mapc 'kill-buffer
(anything-marked-candidates)))
10387 (defun anything-c-delete-file (file)
10388 "Delete the given file after querying the user.
10389 Ask to kill buffers associated with that file, too."
10390 (let ((buffers (anything-c-file-buffers file
)))
10391 (if (< emacs-major-version
24)
10392 ;; `dired-delete-file' in Emacs versions < 24
10393 ;; doesn't support delete-by-moving-to-trash
10394 ;; so use `delete-directory' and `delete-file'
10396 (cond ((and (not (file-symlink-p file
))
10397 (file-directory-p file
)
10398 (directory-files file t dired-re-no-dot
))
10399 (when (y-or-n-p (format "Recursive delete of `%s'? " file
))
10400 (delete-directory file
'recursive
)))
10401 ((and (not (file-symlink-p file
))
10402 (file-directory-p file
))
10403 (delete-directory file
))
10404 (t (delete-file file
)))
10406 file
'dired-recursive-deletes delete-by-moving-to-trash
))
10408 (dolist (buf buffers
)
10409 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
10410 (kill-buffer buf
))))))
10412 (defun anything-get-mailcap-for-file (filename)
10413 "Get the command to use for FILENAME from mailcap files.
10414 The command is like <command %s> and is meant to use with `format'."
10415 (mailcap-parse-mailcaps)
10416 (let* ((ext (file-name-extension filename
))
10417 (mime (when ext
(mailcap-extension-to-mime ext
)))
10418 (result (when mime
(mailcap-mime-info mime
))))
10419 ;; If elisp file have no associations in .mailcap
10420 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10421 (when (stringp result
) result
)))
10423 (defun anything-get-default-program-for-file (filename)
10424 "Try to find a default program to open FILENAME.
10425 Try first in `anything-c-external-programs-associations' and then in mailcap file
10426 if nothing found return nil."
10427 (let* ((ext (file-name-extension filename
))
10428 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
10429 (cond ((and def-prog
(not (string= def-prog
"")))
10430 (concat def-prog
" %s"))
10431 ((and anything-c-default-external-file-browser
10432 (file-directory-p filename
))
10433 (concat anything-c-default-external-file-browser
" %s"))
10434 (t (anything-get-mailcap-for-file filename
)))))
10436 (defun anything-c-open-file-externally (file)
10437 "Open FILE with an external program.
10438 Try to guess which program to use with `anything-get-default-program-for-file'.
10439 If not found or a prefix arg is given query the user which tool to use."
10440 (let* ((fname (expand-file-name file
))
10441 (collection (anything-c-external-commands-list-1 'sort
))
10442 (def-prog (anything-get-default-program-for-file fname
))
10443 (real-prog-name (if (or anything-current-prefix-arg
(not def-prog
))
10444 ;; Prefix arg or no default program.
10446 (anything-comp-read
10447 "Program: " collection
10449 :name
"Open file Externally"
10450 :history anything-external-command-history
)
10451 ;; Always prompt to set this program as default.
10452 (setq def-prog nil
))
10453 ;; No prefix arg or default program exists.
10454 (replace-regexp-in-string " %s\\| '%s'" "" def-prog
)))
10455 (program (concat real-prog-name
" '%s'")))
10456 (unless (or def-prog
; Association exists, no need to record it.
10457 ;; Don't try to record non--filenames associations (e.g urls).
10458 (not (file-exists-p fname
)))
10462 "Do you want to make `%s' the default program for this kind of files? "
10464 (anything-aif (assoc (file-name-extension fname
)
10465 anything-c-external-programs-associations
)
10466 (setq anything-c-external-programs-associations
10467 (delete it anything-c-external-programs-associations
)))
10468 (push (cons (file-name-extension fname
)
10470 "Program (Add args maybe and confirm): " real-prog-name
))
10471 anything-c-external-programs-associations
)
10472 (customize-save-variable 'anything-c-external-programs-associations
10473 anything-c-external-programs-associations
)))
10474 (anything-run-or-raise program file
)
10475 (setq anything-external-command-history
10476 (cons real-prog-name
10477 (delete real-prog-name
10478 (loop for i in anything-external-command-history
10479 when
(executable-find i
) collect i
))))))
10482 (defun anything-c-find-file-or-marked (candidate)
10483 "Open file CANDIDATE or open anything marked files in background."
10484 (let ((marked (anything-marked-candidates))
10485 (ffap-newfile-prompt anything-ff-newfile-prompt-p
)
10486 (find-file-wildcards nil
))
10487 (if (> (length marked
) 1)
10488 ;; Open all marked files in background and display
10490 (progn (mapc 'find-file-noselect
(cdr marked
))
10491 (find-file (car marked
)))
10492 (if (and (not (file-exists-p candidate
))
10493 (and ffap-url-regexp
10494 (not (string-match ffap-url-regexp candidate
)))
10495 (string-match "/$" candidate
))
10496 ;; A a non--existing filename ending with /
10497 ;; Create a directory and jump to it.
10498 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
10499 (let ((dirfname (directory-file-name candidate
)))
10500 (if (file-exists-p dirfname
)
10501 (error "Mkdir: Unable to create directory `%s': file exists."
10502 (anything-c-basename dirfname
))
10503 (make-directory candidate
'parent
)))
10504 (anything-find-files-1 candidate
))
10505 ;; A non--existing filename NOT ending with / or
10506 ;; an existing filename, create or jump to it.
10507 (find-file-at-point (car marked
))))))
10509 (defun anything-delete-marked-files (ignore)
10510 (let* ((files (anything-marked-candidates))
10511 (len (length files
)))
10513 (format "Delete *%s File(s):\n%s"
10515 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
10516 (message "(No deletions performed)")
10518 (set-text-properties 0 (length i
) nil i
)
10519 (anything-c-delete-file i
))
10520 (message "%s File(s) deleted" len
))))
10522 (defun anything-ediff-marked-buffers (candidate &optional merge
)
10523 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10524 With optional arg MERGE call `ediff-merge-buffers'."
10525 (let ((lg-lst (length (anything-marked-candidates)))
10529 (error "Error:You have to mark at least 1 buffer"))
10531 (setq buf1 anything-current-buffer
10532 buf2
(first (anything-marked-candidates))))
10534 (setq buf1
(first (anything-marked-candidates))
10535 buf2
(second (anything-marked-candidates))))
10537 (error "Error:To much buffers marked!")))
10539 (ediff-merge-buffers buf1 buf2
)
10540 (ediff-buffers buf1 buf2
))))
10542 (defun anything-ediff-marked-buffers-merge (candidate)
10543 "Ediff merge `anything-current-buffer' with CANDIDATE.
10544 See `anything-ediff-marked-buffers'."
10545 (anything-ediff-marked-buffers candidate t
))
10547 (defun anything-bookmark-get-bookmark-from-name (bmk)
10548 "Return bookmark name even if it is a bookmark with annotation.
10549 e.g prepended with *.
10550 Return nil if bmk is not a valid bookmark."
10551 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
10552 (if (assoc bookmark bookmark-alist
)
10554 (when (assoc bmk bookmark-alist
)
10557 (defun anything-delete-marked-bookmarks (ignore)
10558 "Delete this bookmark or all marked bookmarks."
10559 (dolist (i (anything-marked-candidates))
10560 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
10563 (defun anything-require-or-error (feature function
)
10564 (or (require feature nil t
)
10565 (error "Need %s to use `%s'." feature function
)))
10567 (defun anything-find-buffer-on-elscreen (candidate)
10568 "Open buffer in new screen, if marked buffers open all in elscreens."
10569 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
10570 (anything-aif (anything-marked-candidates)
10572 (let ((target-screen (elscreen-find-screen-by-buffer
10573 (get-buffer i
) 'create
)))
10574 (elscreen-goto target-screen
)))
10575 (let ((target-screen (elscreen-find-screen-by-buffer
10576 (get-buffer candidate
) 'create
)))
10577 (elscreen-goto target-screen
))))
10579 (defun anything-elscreen-find-file (file)
10580 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
10581 (elscreen-find-file file
))
10584 (defun w32-shell-execute-open-file (file)
10585 (interactive "fOpen file:")
10587 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10589 (replace-regexp-in-string ; strip cygdrive paths
10590 "/cygdrive/\\(.\\)" "\\1:"
10591 file nil nil
) nil t
))))
10593 (defun anything-c-open-file-with-default-tool (file)
10594 "Open FILE with the default tool on this platform."
10595 (if (eq system-type
'windows-nt
)
10596 (w32-shell-execute-open-file file
)
10597 (start-process "anything-c-open-file-with-default-tool"
10599 (cond ((eq system-type
'gnu
/linux
)
10601 ((or (eq system-type
'darwin
) ;; Mac OS X
10602 (eq system-type
'macos
)) ;; Mac OS 9
10606 (defun anything-c-open-dired (file)
10607 "Opens a dired buffer in FILE's directory. If FILE is a
10608 directory, open this directory."
10609 (if (file-directory-p file
)
10611 (dired (file-name-directory file
))
10612 (dired-goto-file file
)))
10614 (defun anything-c-display-to-real-line (candidate)
10615 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
10616 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
10617 (error "Line number not found")))
10619 (defun anything-c-action-line-goto (lineno-and-content)
10620 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
10621 (append lineno-and-content
10622 (list (if (and (anything-attr-defined 'target-file
)
10623 (not anything-in-persistent-action
))
10624 'find-file-other-window
10627 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
10628 (apply #'anything-goto-file-line
10629 (if (stringp file-line-content
)
10630 ;; Case: filtered-candidate-transformer is skipped
10631 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
10632 file-line-content
)))
10635 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
10636 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
10638 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10639 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
10640 (let ((filename (match-string 1 candidate
))
10641 (lineno (match-string 2 candidate
))
10642 (content (match-string 3 candidate
)))
10643 (cons (format "%s:%s\n %s"
10644 (propertize filename
'face compilation-info-face
)
10645 (propertize lineno
'face compilation-line-face
)
10647 (list (expand-file-name
10649 (or (anything-interpret-value (anything-attr 'default-directory
))
10650 (and (anything-candidate-buffer)
10651 (buffer-local-value
10652 'default-directory
(anything-candidate-buffer)))))
10653 (string-to-number lineno
) content
)))))
10655 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
10656 (anything-aif (anything-attr 'before-jump-hook
)
10658 (when file
(funcall find-file-function file
))
10659 (if (anything-attr-defined 'adjust
)
10660 (anything-c-goto-line-with-adjustment lineno content
)
10661 (anything-goto-line lineno
))
10662 (unless (anything-attr-defined 'recenter
)
10663 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
10664 (anything-aif (anything-attr 'after-jump-hook
)
10666 (when anything-in-persistent-action
10667 (anything-match-line-color-current-line)))
10669 (defun anything-find-file-as-root (candidate)
10670 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
10672 (defun anything-find-many-files (ignore)
10673 (mapc 'find-file
(anything-marked-candidates)))
10675 ;; borrowed from etags.el
10676 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10677 (defun anything-c-goto-line-with-adjustment (line line-content
)
10680 ;; This constant is 1/2 the initial search window.
10681 ;; There is no sense in making it too small,
10682 ;; since just going around the loop once probably
10683 ;; costs about as much as searching 2000 chars.
10686 pat
(concat (if (eq selective-display t
)
10687 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10688 (regexp-quote line-content
)))
10689 ;; If no char pos was given, try the given line number.
10690 (setq startpos
(progn (anything-goto-line line
) (point)))
10691 (or startpos
(setq startpos
(point-min)))
10692 ;; First see if the tag is right at the specified location.
10693 (goto-char startpos
)
10694 (setq found
(looking-at pat
))
10695 (while (and (not found
)
10697 (goto-char (- startpos offset
))
10700 (re-search-forward pat
(+ startpos offset
) t
)
10701 offset
(* 3 offset
))) ; expand search window
10703 (re-search-forward pat nil t
)
10704 (error "not found")))
10705 ;; Position point at the right place
10706 ;; if the search string matched an extra Ctrl-m at the beginning.
10707 (and (eq selective-display t
)
10710 (beginning-of-line))
10712 (anything-document-attribute 'default-directory
"type . file-line"
10713 "`default-directory' to interpret file.")
10714 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
10715 "Function to call before jumping to the target location.")
10716 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
10717 "Function to call after jumping to the target location.")
10718 (anything-document-attribute 'adjust
"type . file-line"
10719 "Search around line matching line contents.")
10720 (anything-document-attribute 'recenter
"type . file-line / line"
10721 "`recenter' after jumping.")
10722 (anything-document-attribute 'target-file
"type . line"
10723 "Goto line of target-file.")
10726 (defun anything-c-call-interactively (cmd-or-name)
10727 "Execute CMD-OR-NAME as Emacs command.
10728 It is added to `extended-command-history'.
10729 `anything-current-prefix-arg' is used as the command's prefix argument."
10730 (setq extended-command-history
10731 (cons (anything-c-stringify cmd-or-name
)
10732 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
10733 (let ((current-prefix-arg anything-current-prefix-arg
)
10734 (cmd (anything-c-symbolify cmd-or-name
)))
10735 (if (stringp (symbol-function cmd
))
10736 (execute-kbd-macro (symbol-function cmd
))
10737 (setq this-command cmd
)
10738 (call-interactively cmd
))))
10741 (defun anything-c-set-variable (var)
10742 "Set value to VAR interactively."
10744 (let ((sym (anything-c-symbolify var
)))
10745 (set sym
(eval-minibuffer (format "Set %s: " var
)
10746 (prin1-to-string (symbol-value sym
))))))
10748 ;; (anything-c-set-variable 'hh)
10752 ;;; Persistent Action Helpers
10755 (defvar anything-match-line-overlay-face nil
)
10756 (defvar anything-match-line-overlay nil
)
10758 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
10759 "Highlight and underline current position"
10760 (let ((args (list (or start
(line-beginning-position))
10761 (or end
(1+ (line-end-position)))
10763 (if (not anything-match-line-overlay
)
10764 (setq anything-match-line-overlay
(apply 'make-overlay args
))
10765 (apply 'move-overlay anything-match-line-overlay args
)))
10766 (overlay-put anything-match-line-overlay
10767 'face
(or face anything-match-line-overlay-face
))
10772 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
10775 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
10777 (defun anything-match-line-cleanup ()
10778 (when anything-match-line-overlay
10779 (delete-overlay anything-match-line-overlay
)
10780 (setq anything-match-line-overlay nil
)))
10782 (defun anything-match-line-update ()
10783 (when anything-match-line-overlay
10784 (delete-overlay anything-match-line-overlay
)
10785 (anything-match-line-color-current-line)))
10787 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
10788 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
10791 ;;; Actions Transformers
10795 (defun anything-c-transform-file-load-el (actions candidate
)
10796 "Add action to load the file CANDIDATE if it is an emacs lisp
10797 file. Else return ACTIONS unmodified."
10798 (if (member (file-name-extension candidate
) '("el" "elc"))
10799 (append actions
'(("Load Emacs Lisp File" . load-file
)))
10802 (defun anything-c-transform-file-browse-url (actions candidate
)
10803 "Add an action to browse the file CANDIDATE if it in a html
10804 file or URL. Else return ACTIONS unmodified."
10805 (let ((browse-action '("Browse with Browser" . browse-url
)))
10806 (cond ((string-match "^http\\|^ftp" candidate
)
10807 (cons browse-action actions
))
10808 ((string-match "\\.html?$" candidate
)
10809 (append actions
(list browse-action
)))
10813 (defun anything-c-transform-function-call-interactively (actions candidate
)
10814 "Add an action to call the function CANDIDATE interactively if
10815 it is a command. Else return ACTIONS unmodified."
10816 (if (commandp (intern-soft candidate
))
10817 (append actions
'(("Call Interactively"
10819 anything-c-call-interactively
)))
10823 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
10824 "If CANDIDATE's `car' is a command, then add an action to
10825 evaluate it and put it onto the `command-history'."
10826 (if (commandp (car (read candidate
)))
10827 ;; Make it first entry
10828 (cons '("Eval and put onto command-history" .
10830 (let ((sym (read sexp
)))
10832 (setq command-history
10833 (cons sym command-history
)))))
10838 ;;; Candidate Transformers
10842 (defun anything-c-skip-boring-buffers (buffers)
10843 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
10845 (defun anything-c-skip-current-buffer (buffers)
10846 (if anything-allow-skipping-current-buffer
10847 (remove (buffer-name anything-current-buffer
) buffers
)
10850 (defun anything-c-shadow-boring-buffers (buffers)
10851 "Buffers matching `anything-c-boring-buffer-regexp' will be
10852 displayed with the `file-name-shadow' face if available."
10853 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
10855 (defvar anything-c-buffer-display-string-functions
10856 '(anything-c-buffer-display-string--compilation
10857 anything-c-buffer-display-string--shell
10858 anything-c-buffer-display-string--eshell
)
10859 "Functions to setup display string for buffer.
10861 Function has one argument, buffer name.
10862 If it returns string, use it.
10863 If it returns nil, display buffer name.
10864 See `anything-c-buffer-display-string--compilation' for example.")
10866 (defun anything-c-transform-buffer-display-string (buffers)
10867 "Setup display string for buffer candidates
10868 using `anything-c-buffer-display-string-functions'."
10869 (loop for buf in buffers
10873 for disp
= (progn (set-buffer buf
)
10874 (run-hook-with-args-until-success
10875 'anything-c-buffer-display-string-functions buf
))
10876 collect
(if disp
(cons disp buf
) buf
)))
10878 (defun anything-c-buffer-display-string--compilation (buf)
10879 (anything-aif (car compilation-arguments
)
10880 (format "%s: %s [%s]" buf it default-directory
)))
10882 (defun anything-c-buffer-display-string--eshell (buf)
10883 (declare (special eshell-history-ring
))
10884 (when (eq major-mode
'eshell-mode
)
10885 (format "%s: %s [%s]" buf
10886 (ignore-errors (ring-ref eshell-history-ring
0))
10887 default-directory
)))
10889 (defun anything-c-buffer-display-string--shell (buf)
10890 (when (eq major-mode
'shell-mode
)
10891 (format "%s: %s [%s]" buf
10892 (ignore-errors (ring-ref comint-input-ring
0))
10893 default-directory
)))
10896 (defun anything-c-shadow-boring-files (files)
10897 "Files matching `anything-c-boring-file-regexp' will be
10898 displayed with the `file-name-shadow' face if available."
10899 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
10901 (defun anything-c-skip-boring-files (files)
10902 "Files matching `anything-c-boring-file-regexp' will be skipped."
10903 (anything-c-skip-entries files anything-c-boring-file-regexp
))
10904 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10906 (defun anything-c-skip-current-file (files)
10907 "Current file will be skipped."
10908 (remove (buffer-file-name anything-current-buffer
) files
))
10910 (defun anything-c-w32-pathname-transformer (args)
10911 "Change undesirable features of windows pathnames to ones more acceptable to
10912 other candidate transformers."
10913 (if (eq system-type
'windows-nt
)
10914 (mapcar (lambda (x)
10915 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
10916 (mapcar (lambda (y)
10917 (replace-regexp-in-string "\\\\" "/" y
)) args
))
10920 (defun anything-c-shorten-home-path (files)
10921 "Replaces /home/user with ~."
10922 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10924 (mapcar (lambda (file)
10925 (if (and (stringp file
) (string-match home file
))
10926 (cons (replace-match "~" nil nil file
) file
)
10931 (defun anything-c-mark-interactive-functions (functions)
10932 "Mark interactive functions (commands) with (i) after the function name."
10934 (loop for function in functions
10935 do
(push (cons (concat function
10936 (when (commandp (intern-soft function
)) " (i)"))
10939 finally
(return (nreverse list
)))))
10942 ;;; Adaptive Sorting of Candidates
10946 (defvar anything-c-adaptive-done nil
10947 "nil if history information is not yet stored for the current
10950 (defvar anything-c-adaptive-history nil
10951 "Contains the stored history information.
10952 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10954 (defadvice anything-initial-setup
(before anything-c-adaptive-initialize activate
)
10955 "Reset `anything-c-adaptive-done' when anything is started."
10956 (when anything-c-use-adaptative-sorting
10957 (setq anything-c-adaptive-done nil
)))
10959 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
10960 "Store history information when action is executed on selected candidate."
10961 (when anything-c-use-adaptative-sorting
10962 (anything-c-adaptive-store-selection)))
10964 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
10965 "Store history information when the user goes to the action buffer."
10966 (when anything-c-use-adaptative-sorting
10967 (anything-c-adaptive-store-selection)))
10969 (defun anything-c-source-use-adaptative-p (&optional source-name
)
10970 "Return current source only if it use adaptative history, nil otherwise."
10971 (when anything-c-use-adaptative-sorting
10972 (let* ((source (or source-name
(anything-get-current-source)))
10973 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10974 (assoc (assoc-default 'type source
)
10975 anything-type-attributes
))
10976 (assoc-default 'candidate-transformer
10977 (assoc (assoc-default 'type source
)
10978 anything-type-attributes
))
10979 (assoc-default 'filtered-candidate-transformer source
)
10980 (assoc-default 'candidate-transformer source
))))
10981 (if (listp adapt-source
)
10982 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
10983 (when (eq adapt-source
'anything-c-adaptive-sort
) source
)))))
10985 (defun anything-c-adaptive-store-selection ()
10986 "Store history information for the selected candidate."
10987 (unless anything-c-adaptive-done
10988 (setq anything-c-adaptive-done t
)
10989 (let ((source (anything-c-source-use-adaptative-p)))
10991 (let* ((source-name (or (assoc-default 'type source
)
10992 (assoc-default 'name source
)))
10993 (source-info (or (assoc source-name anything-c-adaptive-history
)
10995 (push (list source-name
) anything-c-adaptive-history
)
10996 (car anything-c-adaptive-history
))))
10997 (selection (anything-get-selection))
10998 (selection-info (progn
10999 (setcdr source-info
11001 (let ((found (assoc selection
(cdr source-info
))))
11006 ;; move entry to the beginning of the
11007 ;; list, so that it doesn't get
11008 ;; trimmed when the history is
11010 (setcdr source-info
11011 (delete found
(cdr source-info
)))
11013 (cdr source-info
)))
11014 (cadr source-info
)))
11015 (pattern-info (progn
11016 (setcdr selection-info
11018 (let ((found (assoc anything-pattern
(cdr selection-info
))))
11021 (cons anything-pattern
0)
11023 ;; move entry to the beginning of the
11024 ;; list, so if two patterns used the
11025 ;; same number of times then the one
11026 ;; used last appears first in the list
11027 (setcdr selection-info
11028 (delete found
(cdr selection-info
)))
11030 (cdr selection-info
)))
11031 (cadr selection-info
))))
11033 ;; increase usage count
11034 (setcdr pattern-info
(1+ (cdr pattern-info
)))
11036 ;; truncate history if needed
11037 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
11038 (setcdr selection-info
11039 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
11041 (defun anything-c-adaptative-maybe-load-history ()
11042 (when (and anything-c-use-adaptative-sorting
11043 (file-readable-p anything-c-adaptive-history-file
))
11044 (load-file anything-c-adaptive-history-file
)))
11046 (add-hook 'emacs-startup-hook
'anything-c-adaptative-maybe-load-history
)
11047 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
11049 (defun anything-c-adaptive-save-history (&optional arg
)
11050 "Save history information to file given by `anything-c-adaptive-history-file'."
11052 (when anything-c-use-adaptative-sorting
11055 ";; -*- mode: emacs-lisp -*-\n"
11056 ";; History entries used for anything adaptive display.\n")
11057 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
11060 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
11061 (unless arg
'quiet
)))))
11063 (defun anything-c-adaptive-sort (candidates source
)
11064 "Sort the CANDIDATES for SOURCE by usage frequency.
11065 This is a filtered candidate transformer you can use for the
11066 attribute `filtered-candidate-transformer' of a source in
11067 `anything-sources' or a type in `anything-type-attributes'."
11068 (let* ((source-name (or (assoc-default 'type source
)
11069 (assoc-default 'name source
)))
11070 (source-info (assoc source-name anything-c-adaptive-history
)))
11073 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
11075 (mapcar (lambda (candidate-info)
11077 (dolist (pattern-info (cdr candidate-info
))
11078 (if (not (equal (car pattern-info
)
11080 (incf count
(cdr pattern-info
))
11082 ;; if current pattern is equal to the previously
11083 ;; used one then this candidate has priority
11084 ;; (that's why its count is boosted by 10000) and
11085 ;; it only has to compete with other candidates
11086 ;; which were also selected with the same pattern
11087 (setq count
(+ 10000 (cdr pattern-info
)))
11089 (cons (car candidate-info
) count
)))
11090 (cdr source-info
)))
11092 (if (and usage
(consp usage
))
11093 ;; sort the list in descending order, so candidates with highest
11094 ;; priorty come first
11096 (setq usage
(sort usage
(lambda (first second
)
11097 (> (cdr first
) (cdr second
)))))
11099 ;; put those candidates first which have the highest usage count
11100 (dolist (info usage
)
11101 (when (member* (car info
) candidates
11102 :test
'anything-c-adaptive-compare
)
11103 (push (car info
) sorted
)
11104 (setq candidates
(remove* (car info
) candidates
11105 :test
'anything-c-adaptive-compare
))))
11107 ;; and append the rest
11108 (append (reverse sorted
) candidates nil
))
11109 (message "Your `%s' is maybe corrupted or too old, \
11110 you should reinitialize it with `anything-c-reset-adaptative-history'"
11111 anything-c-adaptive-history-file
)
11114 ;; if there is no information stored for this source then do nothing
11118 (defun anything-c-reset-adaptative-history ()
11119 "Delete all `anything-c-adaptive-history' and his file.
11120 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
11122 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
11123 (setq anything-c-adaptive-history nil
)
11124 (delete-file anything-c-adaptive-history-file
)))
11126 (defun anything-c-adaptive-compare (x y
)
11127 "Compare candidates X and Y taking into account that the
11128 candidate can be in (DISPLAY . REAL) format."
11129 (equal (if (listp x
)
11141 (defvar anything-outline-goto-near-line-flag t
)
11142 (defvar anything-outline-using nil
)
11143 (defun anything-after-update-hook--outline ()
11144 (if (and (eq anything-outline-using t
)
11145 (eq anything-outline-goto-near-line-flag t
))
11146 (anything-outline-goto-near-line)))
11147 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
11149 (defun anything-outline-goto-near-line ()
11150 (with-anything-window
11151 ;; TODO need consideration whether to update position by every input.
11152 (when t
; (equal anything-pattern "")
11153 (anything-goto-line 2)
11154 (let ((lineno (with-anything-current-buffer
11155 (line-number-at-pos (car anything-current-position
)))))
11157 (while (<= (progn (skip-chars-forward " ")
11158 (or (number-at-point) lineno
))
11163 (return-from exit
))))
11165 (and (bobp) (forward-line 1))
11166 (and (anything-pos-header-line-p) (forward-line -
2))
11167 (anything-mark-current-line)))))
11174 ;; Plug-in: info-index
11175 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
11177 (unless (anything-candidate-buffer)
11178 (save-window-excursion
11181 (tobuf (anything-candidate-buffer 'global
))
11182 (infobuf (current-buffer))
11184 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
11185 (Info-goto-node node
)
11186 (goto-char (point-min))
11187 (while (search-forward "\n* " nil t
)
11188 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
11189 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
11190 (setq s
(point-at-bol)
11192 (with-current-buffer tobuf
11193 (insert-buffer-substring infobuf s e
)
11194 (insert "\n"))))))))))
11196 (defun anything-c-info-goto (node-line)
11197 (Info-goto-node (car node-line
))
11198 (anything-goto-line (cdr node-line
)))
11200 (defun anything-c-info-display-to-real (line)
11202 ;; This regexp is stolen from Info-apropos-matches
11203 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
11204 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
11205 (string-to-number (or (match-string 3 line
) "1")))))
11207 (defun anything-c-make-info-source (source file
)
11209 (name .
,(concat "Info Index: " file
))
11210 (info-file .
,file
)
11211 (init . anything-c-info-init
)
11212 (display-to-real . anything-c-info-display-to-real
)
11213 (get-line . buffer-substring
)
11214 (candidates-in-buffer)
11215 (action ("Goto node" . anything-c-info-goto
))))
11217 (defun anything-compile-source--info-index (source)
11218 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
11219 (anything-c-make-info-source source it
)
11221 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
11223 (anything-document-attribute 'info-index
"info-index plugin"
11224 "Create a source of info index very easily.
11226 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11228 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
11229 "Index nodes of info file.
11231 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11232 Some info files are missing index specification.
11234 ex. See `anything-c-source-info-screen'.")
11236 ;; Plug-in: candidates-file
11237 (defun anything-compile-source--candidates-file (source)
11238 (if (assoc-default 'candidates-file source
)
11239 `((init anything-p-candidats-file-init
11240 ,@(let ((orig-init (assoc-default 'init source
)))
11241 (cond ((null orig-init
) nil
)
11242 ((functionp orig-init
) (list orig-init
))
11244 (candidates-in-buffer)
11247 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
11249 (defun anything-p-candidats-file-init ()
11250 (destructuring-bind (file &optional updating
)
11251 (anything-mklist (anything-attr 'candidates-file
))
11252 (setq file
(anything-interpret-value file
))
11253 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
11255 (buffer-disable-undo)
11256 (font-lock-mode -
1)
11257 (auto-revert-mode 1)))))
11259 (anything-document-attribute 'candidates-file
"candidates-file plugin"
11260 "Use a file as the candidates buffer.
11262 1st argument is a filename, string or function name or variable name.
11263 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11265 ;; Plug-in: headline
11266 (defun anything-compile-source--anything-headline (source)
11267 (if (assoc-default 'headline source
)
11268 (append '((init . anything-headline-init
)
11269 (get-line . buffer-substring
)
11272 '((candidates-in-buffer)
11273 (persistent-help .
"Show this line")))
11275 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
11277 (defun anything-headline-init ()
11278 (when (and (anything-current-buffer-is-modified)
11279 (with-anything-current-buffer
11280 (eval (or (anything-attr 'condition
) t
))))
11281 (anything-headline-make-candidate-buffer
11282 (anything-interpret-value (anything-attr 'headline
))
11283 (anything-interpret-value (anything-attr 'subexp
)))))
11285 (anything-document-attribute 'headline
"Headline plug-in"
11286 "Regexp string for anything-headline to scan.")
11287 (anything-document-attribute 'condition
"Headline plug-in"
11288 "A sexp representing the condition to use anything-headline.")
11289 (anything-document-attribute 'subexp
"Headline plug-in"
11290 "Display (match-string-no-properties subexp).")
11292 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11295 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11296 ;; 2. Sort this list by start-of-match.
11297 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11299 ;; It's quite brilliantly written.
11303 (defun anything-headline-get-candidates (regexp subexp
)
11304 (with-anything-current-buffer
11306 (goto-char (point-min))
11307 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
11308 (let (hierarchy curhead
)
11310 (if (numberp subexp
)
11311 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
11312 (cons (buffer-substring (point-at-bol) (point-at-eol))
11314 (hierarchies (headlines)
11315 (1+ (loop for
(_ . hierarchy
) in headlines
11316 maximize hierarchy
)))
11318 (loop for i from
0 to hierarchy
11319 collecting
(aref curhead i
)))
11320 (arrange (headlines)
11321 (unless (null headlines
) ; FIX headlines empty bug!
11322 (loop with curhead
= (make-vector (hierarchies headlines
) "")
11323 for
((str . pt
) . hierarchy
) in headlines
11324 do
(aset curhead hierarchy str
)
11327 (format "H%d:%s" (1+ hierarchy
)
11328 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
11333 (loop for re in regexp
11334 for hierarchy from
0
11335 do
(goto-char (point-min))
11338 while
(re-search-forward re nil t
)
11339 collect
(cons (matched) hierarchy
)))
11340 (lambda (a b
) (> (cdar b
) (cdar a
)))))
11341 (loop while
(re-search-forward regexp nil t
)
11342 collect
(matched))))))))
11345 (defun anything-headline-make-candidate-buffer (regexp subexp
)
11346 (with-current-buffer (anything-candidate-buffer 'local
)
11347 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
11350 (with-anything-current-buffer
11351 (line-number-at-pos pos
))
11354 (defun anything-headline-goto-position (pos recenter
)
11357 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
11360 ;; Plug-in: persistent-help
11361 (defun anything-compile-source--persistent-help (source)
11362 (append source
'((header-line . anything-persistent-help-string
))))
11363 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
11365 (defun anything-persistent-help-string ()
11366 (substitute-command-keys
11367 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11368 (or (anything-interpret-value (anything-attr 'persistent-help
))
11369 (anything-aif (or (assoc-default 'persistent-action
11370 (anything-get-current-source))
11371 (assoc-default 'action
11372 (anything-get-current-source)))
11373 (cond ((symbolp it
) (symbol-name it
))
11374 ((listp it
) (or (ignore-errors (caar it
)) ""))))
11376 " (keeping session)")))
11378 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
11379 "A string to explain persistent-action of this source.
11380 It also accepts a function or a variable name.")
11382 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11384 ;; Plug-in: Type customize
11385 (defun anything-c-uniq-list (lst)
11386 "Like `remove-duplicates' in CL.
11387 But cut deeper duplicates and test by `equal'. "
11388 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
11389 (defvar anything-additional-type-attributes nil
)
11390 (defun anything-c-arrange-type-attribute (type spec
)
11391 "Override type attributes by `define-anything-type-attribute'.
11393 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11395 Example: Set `play-sound-file' as default action
11396 (anything-c-arrange-type-attribute 'file
11397 '((action (\"Play sound\" . play-sound-file)
11398 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11401 (add-to-list 'anything-additional-type-attributes
11403 (loop with typeattr
= (assoc-default type anything-type-attributes
)
11404 for
(attr . value
) in spec
11407 (anything-c-uniq-list
11408 (loop for v in value
11410 append
(assoc-default attr typeattr
)
11414 collect
(cons attr value
)))))
11415 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
11417 (defun anything-compile-source--type-customize (source)
11418 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
11421 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
11423 ;; Plug-in: default-action
11424 (defun anything-compile-source--default-action (source)
11425 (anything-aif (assoc-default 'default-action source
)
11426 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
11429 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
11430 (anything-document-attribute 'default-action
"default-action plug-in"
11434 ;;; Toggle anything-match-plugin
11437 (defvar anything-mp-initial-highlight-delay nil
)
11440 (defun anything-c-toggle-match-plugin ()
11441 "Toggle anything-match-plugin."
11443 (let ((anything-match-plugin-enabled
11444 (member 'anything-compile-source--match-plugin
11445 anything-compile-source-functions
)))
11446 (flet ((disable-match-plugin ()
11447 (setq anything-compile-source-functions
11448 (delq 'anything-compile-source--match-plugin
11449 anything-compile-source-functions
))
11450 (setq anything-mp-initial-highlight-delay
11451 anything-mp-highlight-delay
)
11452 (setq anything-mp-highlight-delay nil
))
11453 (enable-match-plugin ()
11454 (require 'anything-match-plugin
)
11455 (unless anything-mp-initial-highlight-delay
11456 (setq anything-mp-initial-highlight-delay
11457 anything-mp-highlight-delay
))
11458 (setq anything-compile-source-functions
11459 (cons 'anything-compile-source--match-plugin
11460 anything-compile-source-functions
))
11461 (unless anything-mp-highlight-delay
11462 (setq anything-mp-highlight-delay
11463 anything-mp-initial-highlight-delay
))))
11464 (if anything-match-plugin-enabled
11465 (when (y-or-n-p "Really disable match-plugin? ")
11466 (disable-match-plugin)
11467 (message "Anything-match-plugin disabled"))
11468 (when (y-or-n-p "Really enable match-plugin? ")
11469 (enable-match-plugin)
11470 (message "Anything-match-plugin enabled"))))))
11474 ;;; Type Attributes
11477 (define-anything-type-attribute 'buffer
11479 ("Switch to buffer" . anything-c-switch-to-buffer
)
11480 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin
:popup-buffer
))
11481 ("Switch to buffer other window" . switch-to-buffer-other-window
)
11482 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)
11483 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
11484 ("Query replace regexp" . anything-c-buffer-query-replace-regexp
)
11485 ("Query replace" . anything-c-buffer-query-replace
)
11486 ("View buffer" . view-buffer
)
11487 ("Display buffer" . display-buffer
)
11488 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers
)
11489 ("Revert buffer(s)" . anything-revert-marked-buffers
)
11490 ("Insert buffer" . insert-buffer
)
11491 ("Kill buffer(s)" . anything-kill-marked-buffers
)
11492 ("Diff with file" . diff-buffer-with-file
)
11493 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
11494 ("Ediff Merge marked buffers" .
(lambda (candidate)
11495 (anything-ediff-marked-buffers candidate t
))))
11496 (persistent-help .
"Show this buffer")
11497 (candidate-transformer anything-c-skip-current-buffer
11498 anything-c-skip-boring-buffers
11499 anything-c-transform-buffer-display-string
))
11500 "Buffer or buffer name.")
11502 (define-anything-type-attribute 'file
11504 ("Find file" . anything-find-many-files
)
11505 ,(and (locate-library "popwin") '("Find file in popup window" . popwin
:find-file
))
11506 ("Find file as root" . anything-find-file-as-root
)
11507 ("Find file other window" . find-file-other-window
)
11508 ("Find file other frame" . find-file-other-frame
)
11509 ("Open dired in file's directory" . anything-c-open-dired
)
11510 ("Grep File(s) `C-u recurse'" . anything-find-files-grep
)
11511 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep
)
11512 ("Pdfgrep File(s)" . anything-ff-pdfgrep
)
11513 ("Checksum File" . anything-ff-checksum
)
11514 ("View file" . view-file
)
11515 ("Insert file" . insert-file
)
11516 ("Delete file(s)" . anything-delete-marked-files
)
11517 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
11518 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
11519 ("Find file in hex dump" . hexl-find-file
))
11520 (persistent-help .
"Show this file")
11521 (action-transformer anything-c-transform-file-load-el
11522 anything-c-transform-file-browse-url
)
11523 (candidate-transformer anything-c-w32-pathname-transformer
11524 anything-c-skip-current-file
11525 anything-c-skip-boring-files
11526 anything-c-shorten-home-path
))
11529 (let ((actions '(("Describe command" . describe-function
)
11530 ("Add command to kill ring" . anything-c-kill-new
)
11531 ("Go to command's definition" . find-function
)
11532 ("Debug on entry" . debug-on-entry
)
11533 ("Cancel debug on entry" . cancel-debug-on-entry
)
11534 ("Trace function" . trace-function
)
11535 ("Trace function (background)" . trace-function-background
)
11536 ("Untrace function" . untrace-function
))))
11537 (define-anything-type-attribute 'command
11538 `((action ("Call interactively" . anything-c-call-interactively
)
11540 ;; Sort commands according to their usage count.
11541 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11542 (coerce . anything-c-symbolify
)
11543 (persistent-action . describe-function
))
11544 "Command. (string or symbol)")
11546 (define-anything-type-attribute 'function
11547 `((action .
,actions
)
11548 (action-transformer anything-c-transform-function-call-interactively
)
11549 (candidate-transformer anything-c-mark-interactive-functions
)
11550 (coerce . anything-c-symbolify
))
11551 "Function. (string or symbol)"))
11553 (define-anything-type-attribute 'variable
11554 '((action ("Describe variable" . describe-variable
)
11555 ("Add variable to kill ring" . anything-c-kill-new
)
11556 ("Go to variable's definition" . find-variable
)
11557 ("Set variable" . anything-c-set-variable
))
11558 (coerce . anything-c-symbolify
))
11561 (define-anything-type-attribute 'sexp
11562 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
11563 ("Add s-expression to kill ring" . kill-new
))
11564 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
11565 "String representing S-Expressions.")
11567 (define-anything-type-attribute 'bookmark
11568 `((coerce . anything-bookmark-get-bookmark-from-name
)
11570 ("Jump to bookmark" .
(lambda (bookmark)
11571 (let ((current-prefix-arg anything-current-prefix-arg
))
11572 (bookmark-jump bookmark
))
11573 (anything-update)))
11574 ("Jump to BM other window" .
(lambda (bookmark)
11575 (bookmark-jump-other-window bookmark
)
11576 (anything-update)))
11577 ("Bookmark edit annotation" . bookmark-edit-annotation
)
11578 ("Bookmark show annotation" . bookmark-show-annotation
)
11579 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
11580 ,@(and (locate-library "bookmark-extensions")
11581 `(("Edit Bookmark" . bmkext-edit-bookmark
)))
11582 ("Rename bookmark" . bookmark-rename
)
11583 ("Relocate bookmark" . bookmark-relocate
)))
11586 (define-anything-type-attribute 'line
11587 '((display-to-real . anything-c-display-to-real-line
)
11588 (action ("Go to Line" . anything-c-action-line-goto
)))
11589 "LINENO:CONTENT string, eg. \" 16:foo\".
11591 Optional `target-file' attribute is a name of target file.
11593 Optional `before-jump-hook' attribute is a function with no
11594 arguments which is called before jumping to position.
11596 Optional `after-jump-hook' attribute is a function with no
11597 arguments which is called after jumping to position.
11599 If `adjust' attribute is specified, searches the line whose
11600 content is CONTENT near the LINENO.
11602 If `recenter' attribute is specified, the line is displayed at
11603 the center of window, otherwise at the top of window.
11606 (define-anything-type-attribute 'file-line
11607 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
11609 (action ("Go to" . anything-c-action-file-line-goto
)))
11610 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11612 Optional `default-directory' attribute is a default-directory
11613 FILENAME is interpreted.
11615 Optional `before-jump-hook' attribute is a function with no
11616 arguments which is called before jumping to position.
11618 Optional `after-jump-hook' attribute is a function with no
11619 arguments which is called after jumping to position.
11621 If `adjust' attribute is specified, searches the line whose
11622 content is CONTENT near the LINENO.
11624 If `recenter' attribute is specified, the line is displayed at
11625 the center of window, otherwise at the top of window.
11628 (define-anything-type-attribute 'timer
11629 '((real-to-display . anything-c-timer-real-to-display
)
11630 (action ("Cancel Timer" . cancel-timer
)
11631 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
11632 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
11633 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
11634 (persistent-help .
"Describe Function"))
11637 ;;;; Default `anything-sources'
11638 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11639 ;; tend to invoke M-x anything directly. So I offer default setting.
11640 (setq anything-sources
11641 '(anything-c-source-buffers-list
11642 anything-c-source-recentf
11643 anything-c-source-files-in-current-dir
+))
11645 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
11647 (provide 'anything-config
)
11649 ;;; Local Variables:
11650 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
11653 ;; How to save (DO NOT REMOVE!!)
11654 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
11655 ;;; anything-config.el ends here
11657 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
11658 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
11659 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
11660 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
11661 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
11662 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
11663 ;;; LocalWords: dotimes Thierry online vname
11664 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
11665 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
11666 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
11667 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
11668 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
11669 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
11670 ;;; LocalWords: startpos noselect dont desc