* anything-config.el Bugfix find-file can't create new file.
[anything-config.git] / anything-config.el
blob9a0eb07a0427b3db7feb40324cf7ebd834b113ac
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
15 ;; Version: 0.4.1
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:
22 ;; `anything'
25 ;;; This file is NOT part of GNU Emacs
27 ;;; License
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)
32 ;; any later version.
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.
44 ;;; !NOTICE!
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
49 ;;; Commentary:
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 ()
59 ;; (interactive)
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)
68 ;; " *my-anything*"))
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'.
84 ;; `anything-mini'
85 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
86 ;; `anything-for-files'
87 ;; Preconfigured `anything' for opening files.
88 ;; `anything-recentf'
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'.
98 ;; `anything-gentoo'
99 ;; Preconfigured `anything' for gentoo linux.
100 ;; `anything-imenu'
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.
110 ;; `anything-bbdb'
111 ;; Preconfigured `anything' for BBDB.
112 ;; `anything-locate'
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.
118 ;; `anything-colors'
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.
132 ;; `anything-emms'
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.
138 ;; `anything-timers'
139 ;; Preconfigured `anything' for timers.
140 ;; `anything-list-emacs-process'
141 ;; Preconfigured `anything' for emacs process.
142 ;; `anything-occur'
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.
150 ;; `anything-regexp'
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'
155 ;; 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'
161 ;; 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'
191 ;; Not documented.
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'
259 ;; Not documented.
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'
267 ;; Not documented.
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'
277 ;; Not documented.
278 ;; `anything-do-pdfgrep'
279 ;; Not documented.
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).
292 ;; `anything-M-x'
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'
315 ;; Not documented.
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.
330 ;; `anything-create'
331 ;; Preconfigured `anything' to do many create actions from STRING.
332 ;; `anything-top'
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.
338 ;; `anything-apt'
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'
370 ;; Default Value: 50
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'
386 ;; Default Value: 10
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'
394 ;; Default Value: t
395 ;; `anything-c-enable-eval-defun-hack'
396 ;; Default Value: t
397 ;; `anything-tramp-verbose'
398 ;; Default Value: 0
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'
416 ;; Default Value: t
417 ;; `anything-c-copy-async-prefered-emacs'
418 ;; Default Value: "emacs"
419 ;; `anything-ff-lynx-style-map'
420 ;; Default Value: t
421 ;; `anything-ff-history-max-length'
422 ;; Default Value: 100
423 ;; `anything-ff-smart-completion'
424 ;; Default Value: t
425 ;; `anything-ff-default-kbsize'
426 ;; Default Value: 1024.0
427 ;; `anything-ff-tramp-not-fancy'
428 ;; Default Value: t
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'
434 ;; Default Value: t
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'
440 ;; Default Value: 10
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'
446 ;; Default Value: t
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'
454 ;; Default Value: t
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
615 ;;; Change log:
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
623 ;;; Contributors:
625 ;; Tamas Patrovics
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>
639 ;;; For Maintainers:
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
654 ;;; TODO
656 ;; - Fix documentation, now many functions haven't documentations.
659 ;;; Code:
662 ;;; Require
665 (require 'anything)
666 (require 'thingatpt)
667 (require 'ffap)
668 (require 'cl)
669 (require 'dired-aux)
670 (require 'dired-x)
671 (require 'tramp)
672 (require 'grep)
673 (require 'url)
674 (require 'xml)
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))
737 ;;; compatibility
740 (unless (fboundp 'window-system)
741 (defun window-system (&optional arg)
742 window-system))
746 ;;; Customize
749 (defgroup anything-config nil
750 "Predefined configurations for `anything.el'."
751 :group 'anything)
753 (defcustom anything-c-adaptive-history-file
754 "~/.emacs.d/anything-c-adaptive-history"
755 "Path of file where history information is stored."
756 :type 'string
757 :group 'anything-config)
759 (defcustom anything-c-adaptive-history-length 50
760 "Maximum number of candidates stored for a source."
761 :type 'number
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."
767 :type 'string
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."
773 :type 'string
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."
779 :type 'boolean
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."
785 :type 'string
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."
791 :type 'string
792 :group 'anything-config)
794 (defcustom anything-c-boring-buffer-regexp
795 (rx (or
796 (group bos " ")
797 ;; anything-buffer
798 "*anything"
799 ;; echo area
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."
807 :type 'string
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
814 (rx (or
815 ;; Boring directories
816 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
817 ;; Boring files
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."
826 :type 'string
827 :group 'anything-config)
829 (defcustom anything-kill-ring-threshold 10
830 "*Minimum length to be listed by `anything-c-source-kill-ring'."
831 :type 'integer
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."
837 :type 'integer
838 :group 'anything-config)
840 (defcustom anything-su-or-sudo "su"
841 "What command to use for root access."
842 :type 'string
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."
855 :type 'list
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."
864 :type 'list
865 :group 'anything-config)
867 (defcustom anything-allow-skipping-current-buffer t
868 "Show current buffer or not in anything buffer"
869 :type 'boolean
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 ...)."
876 :type 'boolean
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."
883 :type 'integer
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\"."
890 :type 'string
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.
904 !!WARNING!!
905 This default value is very likely to be changed,
906 because it is under discussion."
907 :type 'string
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."
915 :type 'string
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."
921 :type 'string
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'."
931 :type 'list
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\"\)\) "
938 :type 'list
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
945 :type 'boolean)
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
952 :type 'string)
954 (defcustom anything-ff-lynx-style-map t
955 "Use arrow keys to navigate with `anything-find-files'."
956 :group 'anything-config
957 :type 'boolean)
959 (defcustom anything-ff-history-max-length 100
960 "*Number of elements shown in `anything-find-files' history."
961 :group 'anything-config
962 :type 'integer)
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
968 :type 'boolean)
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
974 :type 'float)
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
980 :type 'boolean)
982 (defcustom anything-ff-exif-data-program "exiftran"
983 "*Program used to extract exif data of an image file."
984 :group 'anything-config
985 :type 'string)
987 (defcustom anything-ff-exif-data-program-args "-d"
988 "*Arguments used for `anything-ff-exif-data-program'."
989 :group 'anything-config
990 :type 'string)
992 (defcustom anything-c-grep-use-ioccur-style-keys t
993 "Use Arrow keys to jump to occurences."
994 :group 'anything-config
995 :type 'boolean)
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
1001 :type 'string)
1003 (defcustom anything-c-etags-tag-file-name "TAGS"
1004 "Etags tag file name."
1005 :type 'string
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."
1011 :type 'number
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
1018 if available."
1019 :group 'anything-config
1020 :type 'boolean)
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.
1029 Usage:
1030 ruby make-filelist.rb > /tmp/all.filelist
1032 Then
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\"\)
1037 :type 'string
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
1045 :type 'symbol)
1047 (defcustom anything-c-turn-on-show-completion t
1048 "Display candidate in buffer while moving selection when non--nil."
1049 :group 'anything-config
1050 :type 'boolean)
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
1057 :type 'number)
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
1065 :type 'string)
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."
1070 :type 'boolean
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'."
1076 :type 'boolean
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/>."
1085 :type 'boolean
1086 :group 'anything-config)
1088 (defcustom anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
1089 "*Minimal list of compressed files extension."
1090 :type 'list
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."
1096 :type 'string
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."
1101 :type 'integer
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."
1106 :type 'string
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."
1115 :type 'list
1116 :group 'anything-config)
1118 (defcustom anything-ff-transformer-show-only-basename nil
1119 "Show only basename of candidates in `anything-find-files'.
1120 This can be toggled at anytime from `anything-find-files' with \
1121 \\<anything-find-files-map>0\\[anything-ff-run-toggle-basename]."
1122 :type 'boolean
1123 :group 'anything-config)
1127 ;;; General internal variables
1130 (defvar anything-c-external-commands-list nil
1131 "A list of all external commands the user can execute. If this
1132 variable is not set by the user, it will be calculated
1133 automatically.")
1137 ;;; Faces
1140 (defface anything-buffer-saved-out
1141 '((t (:foreground "red")))
1142 "*Face used for buffer files modified outside of emacs."
1143 :group 'anything-config)
1145 (defface anything-buffer-not-saved
1146 '((t (:foreground "Indianred2")))
1147 "*Face used for buffer files not already saved on disk."
1148 :group 'anything-config)
1150 (defface anything-ff-prefix
1151 '((t (:background "yellow" :foreground "black")))
1152 "*Face used to prefix new file or url paths in `anything-find-files'."
1153 :group 'anything-config)
1155 (defface anything-ff-executable
1156 '((t (:foreground "green")))
1157 "*Face used for executable files in `anything-find-files'."
1158 :group 'anything-config)
1160 (defface anything-ff-directory
1161 '((t (:foreground "DarkRed" :background "LightGray")))
1162 "*Face used for directories in `anything-find-files'."
1163 :group 'anything-config)
1165 (defface anything-ff-symlink
1166 '((t (:foreground "DarkOrange")))
1167 "*Face used for symlinks in `anything-find-files'."
1168 :group 'anything-config)
1170 (defface anything-ff-invalid-symlink
1171 '((t (:foreground "black" :background "red")))
1172 "*Face used for invalid symlinks in `anything-find-files'."
1173 :group 'anything-config)
1175 (defface anything-ff-file
1176 '((t (:foreground "CadetBlue" :underline t)))
1177 "*Face used for file names in `anything-find-files'."
1178 :group 'anything-config)
1180 (defface anything-grep-match
1181 '((t (:inherit match)))
1182 "Face used to highlight grep matches."
1183 :group 'anything-config)
1185 (defface anything-grep-file
1186 '((t (:foreground "BlueViolet" :underline t)))
1187 "Face used to highlight grep results filenames."
1188 :group 'anything-config)
1190 (defface anything-grep-lineno
1191 '((t (:foreground "Darkorange1")))
1192 "Face used to highlight grep number lines."
1193 :group 'anything-config)
1195 (defface anything-grep-running
1196 '((t (:foreground "Red")))
1197 "Face used in mode line when grep is running."
1198 :group 'anything-config)
1200 (defface anything-grep-finish
1201 '((t (:foreground "Green")))
1202 "Face used in mode line when grep is finish."
1203 :group 'anything-config)
1205 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
1206 "*Face used in anything-M-x to show keybinding."
1207 :group 'anything)
1209 (defface anything-bmkext-info
1210 '((t (:foreground "green")))
1211 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1212 :group 'anything)
1214 (defface anything-bmkext-w3m
1215 '((t (:foreground "yellow")))
1216 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1217 :group 'anything)
1219 (defface anything-bmkext-gnus
1220 '((t (:foreground "magenta")))
1221 "*Face used for Gnus bookmarks."
1222 :group 'anything)
1224 (defface anything-bmkext-man
1225 '((t (:foreground "Orange4")))
1226 "*Face used for Woman/man bookmarks."
1227 :group 'anything)
1229 (defface anything-bmkext-no--file
1230 '((t (:foreground "grey")))
1231 "*Face used for non--file bookmarks."
1232 :group 'anything)
1234 (defface anything-bmkext-file
1235 '((t (:foreground "Deepskyblue2")))
1236 "*Face used for non--file bookmarks."
1237 :group 'anything)
1239 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1240 "Face for su/sudo bookmarks."
1241 :group 'anything)
1243 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1244 "Face for w3m bookmarks" :group 'anything)
1246 (defface anything-emms-playlist
1247 '((t (:foreground "Springgreen4" :underline t)))
1248 "*Face used for tracks in current emms playlist."
1249 :group 'anything)
1251 (defface anything-apt-installed
1252 '((t (:foreground "green")))
1253 "*Face used for apt installed candidates."
1254 :group 'anything)
1256 (defface anything-gentoo-match-face '((t (:foreground "red")))
1257 "Face for anything-gentoo installed packages."
1258 :group 'traverse-faces)
1260 (defface anything-lisp-show-completion
1261 '((t (:background "DarkSlateGray")))
1262 "*Face used for showing candidates in `anything-lisp-completion'."
1263 :group 'anything-config)
1265 (defface anything-lisp-completion-info
1266 '((t (:foreground "red")))
1267 "*Face used for showing info in `anything-lisp-completion'."
1268 :group 'anything-config)
1270 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
1271 "Face for source header in the anything buffer." :group 'anything)
1273 ;;;###autoload
1274 (defun anything-configuration ()
1275 "Customize `anything'."
1276 (interactive)
1277 (customize-group "anything-config"))
1281 ;;; Anything-command-map
1284 ;;;###autoload
1285 (defvar anything-command-map)
1286 (define-prefix-command 'anything-command-map)
1289 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
1290 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
1291 (define-key anything-command-map (kbd "l") 'anything-locate)
1292 (define-key anything-command-map (kbd "s") 'anything-surfraw)
1293 (define-key anything-command-map (kbd "r") 'anything-regexp)
1294 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
1295 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
1296 (define-key anything-command-map (kbd "#") 'anything-emms)
1297 (define-key anything-command-map (kbd "m") 'anything-man-woman)
1298 (define-key anything-command-map (kbd "t") 'anything-top)
1299 (define-key anything-command-map (kbd "i") 'anything-imenu)
1300 (define-key anything-command-map (kbd "<tab>") 'anything-lisp-completion-at-point)
1301 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
1302 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
1303 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
1304 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
1305 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
1306 (define-key anything-command-map (kbd "f") 'anything-for-files)
1307 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
1308 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
1309 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
1310 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
1311 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
1312 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
1313 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
1314 (define-key anything-command-map (kbd "c") 'anything-colors)
1315 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
1316 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
1317 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
1318 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
1319 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
1320 (define-key anything-command-map (kbd "h g") 'anything-info-gnus)
1321 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers-list)
1322 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
1323 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
1324 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
1326 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
1327 ;; minibuffer-local-filename-must-match-map.
1328 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
1329 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
1330 (dolist (map (list minibuffer-local-filename-completion-map
1331 minibuffer-local-completion-map
1332 minibuffer-local-must-match-filename-map
1333 minibuffer-local-filename-must-match-map
1334 minibuffer-local-map
1335 minibuffer-local-isearch-map
1336 minibuffer-local-must-match-map
1337 minibuffer-local-ns-map))
1338 (define-key map "\C-r" 'anything-minibuffer-history))
1342 ;;; Menu
1345 (easy-menu-define nil global-map
1346 "`anything' menu"
1347 '("Anything"
1348 ["All anything commands" anything-execute-anything-command t]
1349 ["Find any Files/Buffers" anything-for-files t]
1350 "----"
1351 ("Files:"
1352 ["Find files" anything-find-files t]
1353 ["Recent Files" anything-recentf t]
1354 ["Locate" anything-locate t]
1355 ["Bookmarks" anything-c-pp-bookmarks t])
1356 ("Buffers:"
1357 ["Find buffers" anything-buffers-list t])
1358 ("Commands:"
1359 ["Emacs Commands" anything-M-x t]
1360 ["Externals Commands" anything-c-run-external-command t])
1361 ("Info:"
1362 ["Info at point" anything-info-at-point t]
1363 ["Emacs Manual index" anything-info-emacs t]
1364 ["Gnus Manual index" anything-info-gnus t])
1365 ("Org:"
1366 ["Org keywords" anything-org-keywords t]
1367 ["Org headlines" anything-org-headlines t])
1368 ("Tools:"
1369 ["Occur" anything-occur t]
1370 ["Grep" anything-do-grep t]
1371 ["Etags" anything-c-etags-select t]
1372 ["Lisp complete at point" anything-lisp-completion-at-point t]
1373 ["Browse Kill ring" anything-show-kill-ring t]
1374 ["Browse register" anything-register t]
1375 ["Browse code" anything-browse-code t]
1376 ["Mark Ring" anything-all-mark-rings t]
1377 ["Regexp handler" anything-regexp t]
1378 ["Colors & Faces" anything-colors t]
1379 ["Show xfonts" anything-select-xfont t]
1380 ["Ucs Symbols" anything-ucs t]
1381 ["Imenu" anything-imenu t]
1382 ["Google Suggest" anything-google-suggest t]
1383 ["Eval expression" anything-eval-expression-with-eldoc t]
1384 ["Calcul expression" anything-calcul-expression t]
1385 ["Man pages" anything-man-woman t]
1386 ["Top externals process" anything-top t]
1387 ["Emacs internals process" anything-list-emacs-process t])
1388 "----"
1389 ["Prefered Options" anything-configuration t]))
1393 ;;; Specialized keymaps
1396 (defvar anything-c-buffer-map
1397 (let ((map (copy-keymap anything-map)))
1398 (define-key map (kbd "C-c ?") 'anything-c-buffer-help)
1399 ;; No need to have separate command for grep and zgrep
1400 ;; as we don't use recursivity for buffers.
1401 ;; So use zgrep for both as it is capable to handle non--compressed files.
1402 (define-key map (kbd "M-g s") 'anything-buffer-run-zgrep)
1403 (define-key map (kbd "C-o") 'anything-buffer-switch-other-window)
1404 (define-key map (kbd "C-c C-o") 'anything-buffer-switch-other-frame)
1405 (define-key map (kbd "C-c =") 'anything-buffer-run-ediff)
1406 (define-key map (kbd "M-=") 'anything-buffer-run-ediff-merge)
1407 (define-key map (kbd "C-=") 'anything-buffer-diff-persistent)
1408 (define-key map (kbd "M-U") 'anything-buffer-revert-persistent)
1409 (define-key map (kbd "M-D") 'anything-buffer-run-kill-buffers)
1410 (define-key map (kbd "C-x C-s") 'anything-buffer-save-persistent)
1411 (define-key map (kbd "C-M-%") 'anything-buffer-run-query-replace-regexp)
1412 (define-key map (kbd "M-%") 'anything-buffer-run-query-replace)
1413 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1414 (define-key map (kbd "M-a") 'anything-mark-all)
1415 (when (locate-library "elscreen")
1416 (define-key map (kbd "<C-tab>") 'anything-buffer-switch-to-elscreen))
1417 (delq nil map))
1418 "Keymap for buffer sources in anything.")
1420 (defvar anything-find-files-map
1421 (let ((map (copy-keymap anything-map)))
1422 (define-key map (kbd "C-]") 'anything-ff-run-toggle-basename)
1423 (define-key map (kbd "C-x C-f") 'anything-ff-run-locate)
1424 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1425 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1426 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1427 (define-key map (kbd "M-.") 'anything-ff-run-etags)
1428 (define-key map (kbd "M-R") 'anything-ff-run-rename-file)
1429 (define-key map (kbd "M-C") 'anything-ff-run-copy-file)
1430 (define-key map (kbd "M-B") 'anything-ff-run-byte-compile-file)
1431 (define-key map (kbd "M-L") 'anything-ff-run-load-file)
1432 (define-key map (kbd "M-S") 'anything-ff-run-symlink-file)
1433 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1434 (define-key map (kbd "M-K") 'anything-ff-run-kill-buffer-persistent)
1435 (define-key map (kbd "M-e") 'anything-ff-run-switch-to-eshell)
1436 (define-key map (kbd "<M-tab>") 'anything-ff-run-complete-fn-at-point)
1437 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1438 (define-key map (kbd "C-c C-o") 'anything-ff-run-switch-other-frame)
1439 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1440 (define-key map (kbd "M-!") 'anything-ff-run-eshell-command-on-file)
1441 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1442 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1443 (define-key map (kbd "M-p") 'anything-ff-run-switch-to-history)
1444 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1445 (define-key map (kbd "C-c ?") 'anything-ff-help)
1446 (define-key map (kbd "C-}") 'anything-narrow-window)
1447 (define-key map (kbd "C-{") 'anything-enlarge-window)
1448 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1449 (define-key map (kbd "M-a") 'anything-mark-all)
1450 (define-key map (kbd "M-m") 'anything-toggle-all-marks)
1451 (define-key map (kbd "M-u") 'anything-unmark-all)
1452 (define-key map (kbd "C-c C-a") 'anything-ff-run-gnus-attach-files)
1453 (define-key map (kbd "C-c p") 'anything-ff-run-print-file)
1454 ;; Next 2 have no effect if candidate is not an image file.
1455 (define-key map (kbd "M-l") 'anything-ff-rotate-left-persistent)
1456 (define-key map (kbd "M-r") 'anything-ff-rotate-right-persistent)
1457 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1458 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1459 (define-key map (kbd "C-h C-b") 'anything-send-bug-report-from-anything)
1460 (define-key map (kbd "C-h C-d") 'anything-debug-output)
1461 (when anything-ff-lynx-style-map
1462 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1463 (define-key map (kbd "<right>") 'anything-execute-persistent-action))
1464 (delq nil map))
1465 "Keymap for `anything-find-files'.")
1467 (defvar anything-c-read-file-map
1468 (let ((map (copy-keymap anything-map)))
1469 (define-key map (kbd "C-.") 'anything-find-files-down-one-level)
1470 (define-key map (kbd "C-l") 'anything-find-files-down-one-level)
1471 (define-key map (kbd "C-<backspace>") 'anything-ff-run-toggle-auto-update)
1472 (define-key map (kbd "C-c ?") 'anything-read-file-name-help)
1473 (when anything-ff-lynx-style-map
1474 (define-key map (kbd "<left>") 'anything-find-files-down-one-level)
1475 (define-key map (kbd "<right>") 'anything-execute-persistent-action)
1476 (define-key map (kbd "<M-left>") 'anything-previous-source)
1477 (define-key map (kbd "<M-right>") 'anything-next-source))
1478 (delq nil map))
1479 "Keymap for `anything-c-read-file-name'.")
1481 (defvar anything-generic-files-map
1482 (let ((map (copy-keymap anything-map)))
1483 (define-key map (kbd "M-g s") 'anything-ff-run-grep)
1484 (define-key map (kbd "M-g z") 'anything-ff-run-zgrep)
1485 (define-key map (kbd "M-g p") 'anything-ff-run-pdfgrep)
1486 (define-key map (kbd "M-D") 'anything-ff-run-delete-file)
1487 (define-key map (kbd "C-=") 'anything-ff-run-ediff-file)
1488 (define-key map (kbd "C-c =") 'anything-ff-run-ediff-merge-file)
1489 (define-key map (kbd "C-o") 'anything-ff-run-switch-other-window)
1490 (define-key map (kbd "M-i") 'anything-ff-properties-persistent)
1491 (define-key map (kbd "C-c C-x") 'anything-ff-run-open-file-externally)
1492 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1493 (define-key map (kbd "C-c ?") 'anything-generic-file-help)
1494 map)
1495 "Generic Keymap for files.")
1497 (defvar anything-c-grep-map
1498 (let ((map (copy-keymap anything-map)))
1499 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1500 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1501 (define-key map (kbd "C-o") 'anything-c-grep-run-other-window-action)
1502 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1503 (define-key map (kbd "C-x C-s") 'anything-c-grep-run-save-buffer)
1504 (when anything-c-grep-use-ioccur-style-keys
1505 (define-key map (kbd "<right>") 'anything-c-grep-run-persistent-action)
1506 (define-key map (kbd "<left>") 'anything-c-grep-run-default-action))
1507 (define-key map (kbd "C-c ?") 'anything-grep-help)
1508 (delq nil map))
1509 "Keymap used in Grep sources.")
1511 (defvar anything-c-pdfgrep-map
1512 (let ((map (copy-keymap anything-map)))
1513 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1514 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1515 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1516 (define-key map (kbd "C-c ?") 'anything-pdfgrep-help)
1517 map)
1518 "Keymap used in pdfgrep.")
1520 (defvar anything-c-etags-map
1521 (let ((map (copy-keymap anything-map)))
1522 (define-key map (kbd "M-<down>") 'anything-c-goto-next-file)
1523 (define-key map (kbd "M-<up>") 'anything-c-goto-precedent-file)
1524 (define-key map (kbd "C-w") 'anything-yank-text-at-point)
1525 (define-key map (kbd "C-c ?") 'anything-etags-help)
1526 map)
1527 "Keymap used in Etags.")
1529 (defvar anything-eval-expression-map
1530 (let ((map (copy-keymap anything-map)))
1531 (define-key map (kbd "<C-return>") 'anything-eval-new-line-and-indent)
1532 (define-key map (kbd "<tab>") 'lisp-indent-line)
1533 (define-key map (kbd "<C-tab>") 'lisp-complete-symbol)
1534 (define-key map (kbd "C-p") 'previous-line)
1535 (define-key map (kbd "C-n") 'next-line)
1536 (define-key map (kbd "<up>") 'previous-line)
1537 (define-key map (kbd "<down>") 'next-line)
1538 (define-key map (kbd "<right>") 'forward-char)
1539 (define-key map (kbd "<left>") 'backward-char)
1540 map))
1542 (defvar anything-c-ucs-map
1543 (let ((map (copy-keymap anything-map)))
1544 (define-key map (kbd "<C-backspace>") 'anything-c-ucs-persistent-delete)
1545 (define-key map (kbd "<C-left>") 'anything-c-ucs-persistent-backward)
1546 (define-key map (kbd "<C-right>") 'anything-c-ucs-persistent-forward)
1547 (define-key map (kbd "<C-return>") 'anything-c-ucs-persistent-insert)
1548 (define-key map (kbd "C-c ?") 'anything-c-ucs-help)
1549 map)
1550 "Keymap for `anything-ucs'.")
1554 ;;; Embeded documentation.
1557 (defun anything-c-list-preconfigured-anything ()
1558 "Collect preconfigured anything functions in this file."
1559 (loop with doc
1560 with sym
1561 for entry in (cdr (assoc
1562 (file-truename (locate-library "anything-config"))
1563 load-history))
1564 if (and (consp entry)
1565 (eq (car entry) 'defun)
1566 (string-match "^Preconfigured.+$"
1567 (setq doc (or (documentation (setq sym (cdr entry)))
1568 ""))))
1569 collect (cons sym (match-string 0 doc))))
1571 (defun anything-c-format-preconfigured-anything ()
1572 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
1573 (anything-c-list-preconfigured-anything)))
1575 ;;; Global help message - Used by `anything-help'
1578 (setq anything-help-message
1579 (lambda ()
1580 (concat
1581 "\\<anything-map>"
1582 "`anything' is QuickSilver-like candidate-selection framework.
1584 Narrow the list by typing some pattern,
1585 Multiple patterns are allowed by splitting by space.
1586 Select with natural Emacs operations, choose with RET.
1588 If you have any problems, press C-c C-x C-b!!
1589 Feel free to send bug reports. I'll fix them.
1590 The steps are described in the beginning of anything.el file.
1592 == Basic Operations ==
1593 C-p, Up: Previous Line
1594 C-n, Down : Next Line
1595 M-v, PageUp : Previous Page
1596 C-v, PageDown : Next Page
1597 Enter : Execute first (default) action / Select
1598 M-< : First Line
1599 M-> : Last Line
1600 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
1601 M-PageDown, C-M-v : Next Page (other-window)
1603 Tab, C-i : Show action list
1604 Left : Previous Source
1605 Right, C-o : Next Source
1606 C-k : Delete pattern
1607 C-z : Persistent Action (Execute action with anything session kept)
1608 C-c C-x C-b: Send a bug report
1610 == Shortcuts For 2nd/3rd Action ==
1611 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
1612 \\[anything-select-3rd-action] : Execute 3rd Action
1614 == Visible Marks ==
1615 Visible marks store candidate. Some actions uses marked candidates.
1617 \\[anything-toggle-visible-mark] : Toggle Visible Mark
1618 \\[anything-prev-visible-mark] : Previous Mark
1619 \\[anything-next-visible-mark] : Next Mark
1621 == Miscellaneous Commands ==
1622 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
1623 \\[anything-quit-and-find-file] : Drop into `find-file'
1624 \\[anything-delete-current-selection] : Delete Selected Item (visually)
1625 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
1626 \\[anything-yank-selection] : Yank Selected Item Into Pattern
1627 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
1628 \\[anything-force-update] : Recalculate And Redisplay Candidates
1630 == Global Commands ==
1631 \\<global-map>\\[anything-resume] revives last `anything' session.
1632 It is very useful, so you should bind any key.
1634 Single source is executed by \\[anything-call-source].
1636 == Preconfigured `anything' ==
1637 Preconfigured `anything' is commands that uses `anything' interface.
1638 You can use them without configuration.
1641 (apply 'concat (anything-c-format-preconfigured-anything))
1643 Enjoy!")))
1645 ;;; `anything-buffer-list' help
1648 ;;;###autoload
1649 (defun anything-c-buffer-help ()
1650 "Help command for anything buffers."
1651 (interactive)
1652 (let ((anything-help-message "== Anything Buffer ==
1653 \nTips:
1654 You can enter a partial name of major-mode (e.g lisp, sh) to narrow down buffers.
1655 Enter then a space and a pattern to narrow down to buffers matching this pattern.
1656 \nSpecific commands for `anything-buffers-list':
1657 \\<anything-c-buffer-map>
1658 \\[anything-buffer-run-zgrep]\t\t->Grep Buffer(s) works as zgrep too. (C-u grep all buffers but non--file buffers).
1659 \\[anything-buffer-switch-other-window]\t\t->Switch other window.
1660 \\[anything-buffer-switch-other-frame]\t\t->Switch other frame.
1661 \\[anything-buffer-run-query-replace-regexp]\t\t->Query replace regexp in marked buffers.
1662 \\[anything-buffer-run-query-replace]\t\t->Query replace in marked buffers.
1663 \\[anything-buffer-switch-to-elscreen]\t\t->Find buffer in Elscreen.
1664 \\[anything-buffer-run-ediff]\t\t->Ediff current buffer with candidate. If two marked buffers ediff those buffers.
1665 \\[anything-buffer-run-ediff-merge]\t\t->Ediff merge current buffer with candidate. If two marked buffers ediff merge those buffers.
1666 \\[anything-buffer-diff-persistent]\t\t->Toggle Diff buffer with saved file without quitting.
1667 \\[anything-buffer-revert-persistent]\t\t->Revert buffer without quitting.
1668 \\[anything-buffer-save-persistent]\t\t->Save buffer without quitting.
1669 \\[anything-buffer-run-kill-buffers]\t\t->Delete marked buffers and quit.
1670 \\[anything-toggle-all-marks]\t\t->Toggle all marks.
1671 \\[anything-mark-all]\t\t->Mark all.
1672 \\[anything-c-buffer-help]\t\t->Display this help.
1673 \n== Anything Map ==
1674 \\{anything-map}
1676 (anything-help)))
1679 ;;; Find files help (`anything-find-files')
1682 ;;;###autoload
1683 (defun anything-ff-help ()
1684 "Help command for `anything-find-files'."
1685 (interactive)
1686 (let ((anything-help-message "== Anything Find Files ==
1687 \nTips:
1688 \nEnter \"~/\" at anytime to reach home directory.
1689 Enter \"/\" at anytime to reach root of your file system.
1690 You can complete with partial basename \(e.g \"fb\" will complete \"foobar\"\).
1691 Use `C-u C-z' to watch an image.
1692 To browse images directories turn on `anything-follow-mode'.
1693 \nSpecific commands for `anything-find-files':
1694 \\<anything-find-files-map>
1695 \\[anything-ff-run-locate]\t\t->Run Locate on basename of candidate (C-u to specify locate db).
1696 \\[anything-ff-run-grep]\t\t->Run Grep (C-u Recursive).
1697 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1698 \\[anything-ff-run-zgrep]\t\t->Run zgrep (C-u Recursive).
1699 \\[anything-ff-run-etags]\t\t->Run Etags (C-u use thing-at-point `C-u C-u' reload cache)
1700 \\[anything-ff-run-rename-file]\t\t->Rename File (C-u Follow).
1701 \\[anything-ff-run-copy-file]\t\t->Copy File (C-u Follow).
1702 \\[anything-ff-run-byte-compile-file]\t\t->Byte Compile File (C-u Load).
1703 \\[anything-ff-run-load-file]\t\t->Load File.
1704 \\[anything-ff-run-symlink-file]\t\t->Symlink File.
1705 \\[anything-ff-run-delete-file]\t\t->Delete File.
1706 \\[anything-ff-run-kill-buffer-persistent]\t\t->Kill buffer candidate without quitting.
1707 \\[anything-ff-run-switch-to-eshell]\t\t->Switch to Eshell.
1708 \\[anything-ff-run-eshell-command-on-file]\t\t->Eshell command on file (C-u Run on all marked files at once).
1709 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1710 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1711 \\[anything-ff-run-complete-fn-at-point]\t\t->Complete file name at point.
1712 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1713 \\[anything-ff-run-switch-other-frame]\t\t->Switch other frame.
1714 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1715 \\[anything-ff-rotate-left-persistent]\t\t->Rotate Image Left.
1716 \\[anything-ff-rotate-right-persistent]\t\t->Rotate Image Right.
1717 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1718 \\[anything-ff-run-switch-to-history]\t\t->Switch to anything find-files history.
1719 \\[anything-ff-properties-persistent]\t\t->Show file properties in a tooltip.
1720 \\[anything-mark-all]\t\t->Mark all visibles candidates.
1721 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1722 \\[anything-unmark-all]\t\t->Unmark all candidates, visibles and invisibles.
1723 \\[anything-ff-run-gnus-attach-files]\t\t->Gnus attach files to message buffer.
1724 \\[anything-ff-run-print-file]\t\t->Print file with default printer.
1725 \\[anything-enlarge-window]\t\t->Enlarge anything window.
1726 \\[anything-narrow-window]\t\t->Narrow anything window.
1727 \\[anything-ff-run-toggle-basename]\t\t->Toggle basename/fullpath.
1728 \\[anything-send-bug-report-from-anything]\t\t->Send Bug report.
1729 \\[anything-ff-help]\t\t->Display this help info.
1730 \n== Anything Map ==
1731 \\{anything-map}
1733 (anything-help)))
1735 ;;; Help for `anything-c-read-file-name'
1738 ;;;###autoload
1739 (defun anything-read-file-name-help ()
1740 (interactive)
1741 (let ((anything-help-message "== Anything read file name Map ==\
1742 \nSpecific commands for anything-c-read-file-name:
1743 \\<anything-c-read-file-map>
1744 \\[anything-find-files-down-one-level]\t\t->Go down precedent directory.
1745 \\[anything-ff-run-toggle-auto-update]\t->Toggle auto expansion of directories.
1746 \\[anything-next-source]\t\t->Goto next source.
1747 \\[anything-previous-source]\t->Goto previous source.
1748 \\[anything-read-file-name-help]\t\t->Display this help info.
1749 \n== Anything Map ==
1750 \\{anything-map}
1752 (anything-help)))
1754 ;;; Generic file help - Used by locate.
1757 ;;;###autoload
1758 (defun anything-generic-file-help ()
1759 (interactive)
1760 (let ((anything-help-message "== Anything Generic files Map ==\
1761 \nSpecific commands for anything locate and others files sources:
1762 \\<anything-generic-files-map>
1763 \\[anything-ff-run-grep]\t\t->Run grep (C-u recurse).
1764 \\[anything-ff-run-pdfgrep]\t\t->Run Pdfgrep on marked files.
1765 \\[anything-ff-run-delete-file]\t\t->Delete file.
1766 \\[anything-ff-run-ediff-file]\t\t->Ediff file.
1767 \\[anything-ff-run-ediff-merge-file]\t\t->Ediff merge file.
1768 \\[anything-ff-run-switch-other-window]\t\t->Switch other window.
1769 \\[anything-ff-properties-persistent]\t\t->Show file properties.
1770 \\[anything-yank-text-at-point]\t\t->Yank text at point.
1771 \\[anything-ff-run-open-file-externally]\t\t->Open file with external program (C-u to choose).
1772 \nLocate tips:
1773 You can add after writing search pattern any of the locate command line options.
1774 e.g -b, -e, -n <number>...etc.
1775 See Man locate for more infos.
1776 \n== Anything Map ==
1777 \\{anything-map}"))
1778 (anything-help)))
1781 ;;; Grep help
1784 ;;;###autoload
1785 (defun anything-grep-help ()
1786 (interactive)
1787 (let ((anything-help-message "== Anything Grep Map ==\
1788 \nSpecific commands for Grep and Etags:
1789 \\<anything-c-grep-map>
1790 \\[anything-c-goto-next-file]\t->Next File.
1791 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1792 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1793 \\[anything-c-grep-run-other-window-action]\t\t->Jump other window.
1794 \\[anything-c-grep-run-persistent-action]\t\t->Run persistent action (Same as `C-z').
1795 \\[anything-c-grep-run-default-action]\t\t->Run default action (Same as RET).
1796 \\[anything-grep-help]\t\t->Show this help.
1797 \n== Anything Map ==
1798 \\{anything-map}"))
1799 (anything-help)))
1801 ;;; Pdf grep help
1804 ;;;###autoload
1805 (defun anything-pdfgrep-help ()
1806 (interactive)
1807 (let ((anything-help-message "== Anything PdfGrep Map ==\
1808 \nSpecific commands for Pdf Grep:
1809 \\<anything-c-pdfgrep-map>
1810 \\[anything-c-goto-next-file]\t->Next File.
1811 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1812 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1813 \\[anything-pdfgrep-help]\t\t->Show this help.
1814 \n== Anything Map ==
1815 \\{anything-map}"))
1816 (anything-help)))
1818 ;;; Etags help
1821 ;;;###autoload
1822 (defun anything-etags-help ()
1823 "The help function for etags."
1824 (interactive)
1825 (let ((anything-help-message "== Anything Etags Map ==\
1826 \nSpecific commands for Etags:
1827 \\<anything-c-etags-map>
1828 \\[anything-c-goto-next-file]\t->Next File.
1829 \\[anything-c-goto-precedent-file]\t\t->Precedent File.
1830 \\[anything-yank-text-at-point]\t\t->Yank Text at point in minibuffer.
1831 \\[anything-etags-help]\t\t->Show this help.
1832 \n== Anything Map ==
1833 \\{anything-map}"))
1834 (anything-help)))
1836 ;;; Ucs help
1839 (defun anything-c-ucs-help ()
1840 "Help command for `anything-ucs'."
1841 (interactive)
1842 (let ((anything-help-message "== Anything Ucs ==
1843 \nSpecific commands for `anything-ucs':
1844 \\<anything-c-ucs-map>
1845 \\[anything-c-ucs-persistent-insert]\t->Insert char.
1846 \\[anything-c-ucs-persistent-forward]\t->Forward char.
1847 \\[anything-c-ucs-persistent-backward]\t->Backward char.
1848 \\[anything-c-ucs-persistent-delete]\t->Delete char backward.
1849 \\[anything-c-ucs-help]\t\t->Show this help.
1851 \n== Anything Map ==
1852 \\{anything-map}
1854 (anything-help)))
1858 ;;; Mode line strings
1861 (defvar anything-buffer-mode-line-string
1862 '("Buffer(s)"
1863 "\\<anything-c-buffer-map>\
1864 \\[anything-c-buffer-help]:Help, \
1865 \\<anything-map>\
1866 \\[anything-select-action]:Acts,\
1867 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1868 \\[anything-select-3rd-action]:NthAct,\
1869 \\[anything-send-bug-report-from-anything]:BugReport."
1870 "String displayed in mode-line in `anything-c-source-buffers-list'"))
1872 (defvar anything-ff-mode-line-string
1873 "\\<anything-find-files-map>\
1874 \\[anything-ff-help]:Help, \
1875 \\[anything-send-bug-report-from-anything]:BugReport, \
1876 \\<anything-map>\
1877 \\[anything-select-action]:Acts, \
1878 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1879 \\[anything-select-3rd-action]:NthAct"
1880 "String displayed in mode-line in `anything-c-source-find-files'")
1882 (defvar anything-read-file-name-mode-line-string
1883 "\\<anything-c-read-file-map>\
1884 \\[anything-read-file-name-help]:Help, \
1885 \\<anything-map>\
1886 \\[anything-select-action]:Acts,\
1887 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1888 \\[anything-select-3rd-action]:NthAct"
1889 "String displayed in mode-line in `anything-c-source-find-files'")
1891 (defvar anything-generic-file-mode-line-string
1892 "\\<anything-generic-files-map>\
1893 \\[anything-generic-file-help]:Help, \
1894 \\<anything-map>\
1895 \\[anything-select-action]:Acts,\
1896 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1897 \\[anything-select-3rd-action]:NthAct,\
1898 \\[anything-send-bug-report-from-anything]:BugReport."
1899 "String displayed in mode-line in Locate.")
1901 (defvar anything-grep-mode-line-string
1902 "\\<anything-c-grep-map>\
1903 \\[anything-grep-help]:Help,\
1904 \\<anything-map>\
1905 \\[anything-select-action]:Acts,\
1906 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1907 \\[anything-select-3rd-action]:NthAct,\
1908 \\[anything-send-bug-report-from-anything]:BugReport."
1909 "String displayed in mode-line in `anything-do-grep'.")
1911 (defvar anything-pdfgrep-mode-line-string
1912 "\\<anything-c-pdfgrep-map>\
1913 \\[anything-pdfgrep-help]:Help,\
1914 \\<anything-map>\
1915 \\[anything-select-action]:Acts,\
1916 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1917 \\[anything-select-3rd-action]:NthAct,\
1918 \\[anything-send-bug-report-from-anything]:BugReport."
1919 "String displayed in mode-line in `anything-do-pdfgrep'.")
1921 (defvar anything-etags-mode-line-string
1922 "\\<anything-c-etags-map>\
1923 \\[anything-etags-help]:Help,\
1924 \\<anything-map>\
1925 \\[anything-select-action]:Acts,\
1926 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1927 \\[anything-select-3rd-action]:NthAct,\
1928 \\[anything-send-bug-report-from-anything]:BugReport."
1929 "String displayed in mode-line in `anything-c-etags-select'.")
1932 (defvar anything-c-ucs-mode-line-string
1933 "\\<anything-c-ucs-map>\
1934 \\[anything-c-ucs-help]:Help, \
1935 \\<anything-map>\
1936 \\[anything-select-action]:Acts,\
1937 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
1938 \\[anything-select-3rd-action]:NthAct."
1939 "String displayed in mode-line in `anything-ucs'.")
1943 ;;; Preconfigured Anything
1946 ;;;###autoload
1947 (defun anything-mini ()
1948 "Preconfigured `anything' lightweight version \(buffer -> recentf\)."
1949 (interactive)
1950 (anything-other-buffer '(anything-c-source-buffers-list anything-c-source-recentf)
1951 "*anything mini*"))
1952 ;;;###autoload
1953 (defun anything-for-files ()
1954 "Preconfigured `anything' for opening files.
1955 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate."
1956 (interactive)
1957 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
1959 ;;;###autoload
1960 (defun anything-recentf ()
1961 "Preconfigured `anything' for `recentf'."
1962 (interactive)
1963 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
1965 ;;;###autoload
1966 (defun anything-info-at-point (arg)
1967 "Preconfigured `anything' for searching info at point.
1968 With a prefix-arg insert symbol at point."
1969 (interactive "P")
1970 (let ((anything-c-google-suggest-default-function
1971 'anything-c-google-suggest-emacs-lisp))
1972 (anything :sources'(anything-c-source-info-elisp
1973 anything-c-source-info-cl
1974 anything-c-source-info-pages
1975 anything-c-source-google-suggest)
1976 :input (and arg (thing-at-point 'symbol))
1977 :buffer "*anything info*")))
1979 ;;;###autoload
1980 (defun anything-info-emacs ()
1981 "Preconfigured anything for Emacs manual index."
1982 (interactive)
1983 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
1985 ;;;###autoload
1986 (defun anything-show-kill-ring ()
1987 "Preconfigured `anything' for `kill-ring'.
1988 It is drop-in replacement of `yank-pop'.
1989 You may bind this command to M-y.
1990 First call open the kill-ring browser, next calls move to next line."
1991 (interactive)
1992 (let ((buf "*anything kill-ring*"))
1993 (if (get-buffer-window buf)
1994 (with-anything-window
1995 (if (eq (overlay-end anything-selection-overlay) (point-max))
1996 (anything-beginning-of-buffer)
1997 (anything-next-line)))
1998 (anything-other-buffer 'anything-c-source-kill-ring buf))))
2000 ;;;###autoload
2001 (defun anything-minibuffer-history ()
2002 "Preconfigured `anything' for `minibuffer-history'."
2003 (interactive)
2004 (let ((enable-recursive-minibuffers t))
2005 (anything-other-buffer 'anything-c-source-minibuffer-history
2006 "*anything minibuffer-history*")))
2008 ;;;###autoload
2009 (defun anything-gentoo ()
2010 "Preconfigured `anything' for gentoo linux."
2011 (interactive)
2012 (anything-other-buffer '(anything-c-source-gentoo
2013 anything-c-source-use-flags)
2014 "*anything gentoo*"))
2016 ;;;###autoload
2017 (defun anything-imenu ()
2018 "Preconfigured `anything' for `imenu'."
2019 (interactive)
2020 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
2022 ;;;###autoload
2023 (defun anything-google-suggest ()
2024 "Preconfigured `anything' for google search with google suggest."
2025 (interactive)
2026 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
2028 ;;;###autoload
2029 (defun anything-yahoo-suggest ()
2030 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
2031 (interactive)
2032 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
2034 ;;; Converted from anything-show-*-only
2035 ;;;###autoload
2036 (defun anything-for-buffers ()
2037 "Preconfigured `anything' for buffer."
2038 (interactive)
2039 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
2041 ;;;###autoload
2042 (defun anything-buffers-list ()
2043 "Enhanced preconfigured `anything' for buffer."
2044 (interactive)
2045 (anything :sources '(anything-c-source-buffers-list
2046 anything-c-source-buffer-not-found)
2047 :buffer "*anything buffers*" :keymap anything-c-buffer-map))
2049 ;;;###autoload
2050 (defun anything-bbdb ()
2051 "Preconfigured `anything' for BBDB.
2053 Needs BBDB.
2055 http://bbdb.sourceforge.net/"
2056 (interactive)
2057 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
2059 ;;;###autoload
2060 (defun anything-locate (arg)
2061 "Preconfigured `anything' for Locate.
2062 Note: you can add locate options after entering pattern.
2063 See 'man locate' for valid options.
2065 You can specify a specific database with prefix argument ARG \(C-u\).
2066 Many databases can be used: navigate and mark them.
2067 See also `anything-locate-with-db'.
2069 To create a user specific db, use
2070 \"updatedb -l 0 -o db_path -U directory\".
2071 Where db_path is a filename matched by
2072 `anything-locate-db-file-regexp'."
2073 (interactive "P")
2074 (anything-locate-1 arg))
2076 ;;;###autoload
2077 (defun anything-w3m-bookmarks ()
2078 "Preconfigured `anything' for w3m bookmark.
2080 Needs w3m and emacs-w3m.
2082 http://w3m.sourceforge.net/
2083 http://emacs-w3m.namazu.org/"
2084 (interactive)
2085 (anything-other-buffer 'anything-c-source-w3m-bookmarks
2086 "*anything w3m bookmarks*"))
2088 ;;;###autoload
2089 (defun anything-firefox-bookmarks ()
2090 "Preconfigured `anything' for firefox bookmark.
2091 You will have to enable html bookmarks in firefox:
2092 open about:config in firefox and double click on this line to enable value \
2093 to true:
2095 user_pref(\"browser.bookmarks.autoExportHTML\", false);
2097 You should have now:
2099 user_pref(\"browser.bookmarks.autoExportHTML\", true);
2101 After closing firefox, you will be able to browse you bookmarks.
2103 (interactive)
2104 (anything-other-buffer 'anything-c-source-firefox-bookmarks
2105 "*Anything Firefox*"))
2107 ;;;###autoload
2108 (defun anything-colors ()
2109 "Preconfigured `anything' for color."
2110 (interactive)
2111 (anything-other-buffer
2112 '(anything-c-source-colors anything-c-source-customize-face)
2113 "*anything colors*"))
2115 ;;;###autoload
2116 (defun anything-bookmarks ()
2117 "Preconfigured `anything' for bookmarks."
2118 (interactive)
2119 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
2121 ;;;###autoload
2122 (defun anything-c-pp-bookmarks ()
2123 "Preconfigured `anything' for bookmarks (pretty-printed)."
2124 (interactive)
2125 (anything-other-buffer '(anything-c-source-bookmarks-local
2126 anything-c-source-bookmarks-su
2127 anything-c-source-bookmarks-ssh)
2128 "*anything pp bookmarks*"))
2130 ;;;###autoload
2131 (defun anything-c-insert-latex-math ()
2132 "Preconfigured anything for latex math symbols completion."
2133 (interactive)
2134 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
2136 ;;;###autoload
2137 (defun anything-register ()
2138 "Preconfigured `anything' for Emacs registers."
2139 (interactive)
2140 (anything-other-buffer 'anything-c-source-register "*anything register*"))
2142 ;;;###autoload
2143 (defun anything-man-woman ()
2144 "Preconfigured `anything' for Man and Woman pages."
2145 (interactive)
2146 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
2148 ;;;###autoload
2149 (defun anything-org-keywords ()
2150 "Preconfigured `anything' for org keywords."
2151 (interactive)
2152 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
2154 ;;;###autoload
2155 (defun anything-emms ()
2156 "Preconfigured `anything' for emms sources."
2157 (interactive)
2158 (anything '(anything-c-source-emms-streams
2159 anything-c-source-emms-files
2160 anything-c-source-emms-dired)
2161 nil nil nil nil
2162 "*Anything Emms*"))
2164 ;;;###autoload
2165 (defun anything-eev-anchors ()
2166 "Preconfigured `anything' for eev anchors."
2167 (interactive)
2168 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
2170 ;;;###autoload
2171 (defun anything-bm-list ()
2172 "Preconfigured `anything' for visible bookmarks.
2174 Needs bm.el
2176 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
2177 (interactive)
2178 (let ((anything-outline-using t))
2179 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
2181 ;;;###autoload
2182 (defun anything-timers ()
2183 "Preconfigured `anything' for timers."
2184 (interactive)
2185 (anything-other-buffer '(anything-c-source-absolute-time-timers
2186 anything-c-source-idle-time-timers)
2187 "*anything timers*"))
2189 ;;;###autoload
2190 (defun anything-list-emacs-process ()
2191 "Preconfigured `anything' for emacs process."
2192 (interactive)
2193 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
2195 ;;;###autoload
2196 (defun anything-occur ()
2197 "Preconfigured Anything for Occur source.
2198 If region is active, search only in region,
2199 otherwise search in whole buffer."
2200 (interactive)
2201 (let ((anything-compile-source-functions
2202 ;; rule out anything-match-plugin because the input is one regexp.
2203 (delq 'anything-compile-source--match-plugin
2204 (copy-sequence anything-compile-source-functions))))
2205 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
2207 ;;;###autoload
2208 (defun anything-browse-code ()
2209 "Preconfigured anything to browse code."
2210 (interactive)
2211 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
2213 ;;;###autoload
2214 (defun anything-org-headlines ()
2215 "Preconfigured anything to show org headlines."
2216 (interactive)
2217 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
2219 ;;;###autoload
2220 (defun anything-info-gnus ()
2221 "Preconfigured anything to browse Gnus Manual."
2222 (interactive)
2223 (anything-other-buffer 'anything-c-source-info-gnus "*info Gnus*"))
2225 ;;;###autoload
2226 (defun anything-regexp ()
2227 "Preconfigured anything to build regexps and run query-replace-regexp \
2228 against."
2229 (interactive)
2230 (save-restriction
2231 (let ((anything-compile-source-functions
2232 ;; rule out anything-match-plugin because the input is one regexp.
2233 (delq 'anything-compile-source--match-plugin
2234 (copy-sequence anything-compile-source-functions))))
2235 (when (and (anything-region-active-p)
2236 ;; Don't narrow to region if buffer is already narrowed.
2237 (not (anything-current-buffer-narrowed-p)))
2238 (narrow-to-region (region-beginning) (region-end)))
2239 (anything :sources
2240 anything-c-source-regexp
2241 :buffer "*anything regexp*"
2242 :prompt "Regexp: "))))
2244 (defun anything-c-copy-files-async ()
2245 "Preconfigured anything to copy file list FLIST to DEST asynchronously."
2246 (interactive)
2247 (let* ((flist (anything-c-read-file-name
2248 "Copy File async: "
2249 :marked-candidates t))
2250 (dest (anything-c-read-file-name
2251 "Copy File async To: "
2252 :preselect (car flist)
2253 :initial-input (car anything-ff-history)
2254 :history (anything-find-files-history :comp-read nil))))
2255 (anything-c-copy-async-with-log flist dest)))
2257 ;;;###autoload
2258 (defun anything-find-files (arg)
2259 "Preconfigured `anything' for anything implementation of `find-file'.
2260 Called with a prefix arg show history if some.
2261 Don't call it from programs, use `anything-find-files-1' instead.
2262 This is the starting point for nearly all actions you can do on files."
2263 (interactive "P")
2264 (let ((any-input (if (and arg anything-ff-history)
2265 (anything-find-files-history)
2266 (anything-find-files-initial-input)))
2267 (presel (buffer-file-name (current-buffer))))
2268 (when (and (eq major-mode 'org-agenda-mode)
2269 org-directory
2270 (not any-input))
2271 (setq any-input (expand-file-name org-directory)))
2272 (set-text-properties 0 (length any-input) nil any-input)
2273 (if any-input
2274 (anything-find-files-1 any-input)
2275 (setq any-input (expand-file-name (anything-c-current-directory)))
2276 (anything-find-files-1
2277 any-input (if anything-ff-transformer-show-only-basename
2278 (and presel (anything-c-basename presel))
2279 presel)))))
2281 ;;;###autoload
2282 (defun anything-write-file ()
2283 "Preconfigured `anything' providing completion for `write-file'."
2284 (interactive)
2285 (let ((anything-mp-highlight-delay nil))
2286 (anything :sources 'anything-c-source-write-file
2287 :input (expand-file-name default-directory)
2288 :prompt "Write buffer to file: "
2289 :buffer "*Anything write file*")))
2291 ;;;###autoload
2292 (defun anything-insert-file ()
2293 "Preconfigured `anything' providing completion for `insert-file'."
2294 (interactive)
2295 (let ((anything-mp-highlight-delay nil))
2296 (anything :sources 'anything-c-source-insert-file
2297 :input (expand-file-name default-directory)
2298 :prompt "Insert file: "
2299 :buffer "*Anything insert file*")))
2301 ;;;###autoload
2302 (defun anything-dired-rename-file ()
2303 "Preconfigured `anything' to rename files from dired."
2304 (interactive)
2305 (anything-dired-do-action-on-file :action 'rename))
2307 ;;;###autoload
2308 (defun anything-dired-copy-file ()
2309 "Preconfigured `anything' to copy files from dired."
2310 (interactive)
2311 (anything-dired-do-action-on-file :action 'copy))
2313 ;;;###autoload
2314 (defun anything-dired-symlink-file ()
2315 "Preconfigured `anything' to symlink files from dired."
2316 (interactive)
2317 (anything-dired-do-action-on-file :action 'symlink))
2319 ;;;###autoload
2320 (defun anything-dired-hardlink-file ()
2321 "Preconfigured `anything' to hardlink files from dired."
2322 (interactive)
2323 (anything-dired-do-action-on-file :action 'hardlink))
2325 ;;;###autoload
2326 (defun anything-do-grep ()
2327 "Preconfigured anything for grep.
2328 Contrarily to Emacs `grep' no default directory is given, but
2329 the full path of candidates in ONLY.
2330 That allow to grep different files not only in `default-directory' but anywhere
2331 by marking them (C-<SPACE>). If one or more directory is selected
2332 grep will search in all files of these directories.
2333 You can use also wildcard in the base name of candidate.
2334 If a prefix arg is given use the -r option of grep.
2335 The prefix arg can be passed before or after start.
2336 See also `anything-do-grep-1'."
2337 (interactive)
2338 (let ((only (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 (prefarg (or current-prefix-arg anything-current-prefix-arg)))
2344 (anything-do-grep-1 only prefarg)))
2346 ;;;###autoload
2347 (defun anything-do-zgrep (candidate)
2348 "Preconfigured anything for zgrep."
2349 (let ((prefarg (or current-prefix-arg anything-current-prefix-arg))
2350 (ls (anything-c-read-file-name
2351 "Search in file(s): "
2352 :marked-candidates t
2353 :preselect (or (dired-get-filename nil t)
2354 (buffer-file-name (current-buffer))))))
2355 (anything-ff-zgrep-1 ls prefarg)))
2357 (defun anything-c-etags-select (arg)
2358 "Preconfigured anything for etags.
2359 Called with one prefix arg use symbol at point as initial input.
2360 Called with two prefix arg reinitialize cache.
2361 If tag file have been modified reinitialize cache."
2362 (interactive "P")
2363 (let ((tag (anything-c-etags-get-tag-file))
2364 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
2365 (anything-quit-if-no-candidate t)
2366 (anything-execute-action-at-once-if-one t)
2367 (anything-compile-source-functions
2368 (if anything-c-etags-use-regexp-search
2369 ;; rule out anything-match-plugin because the input is one regexp.
2370 (delq 'anything-compile-source--match-plugin
2371 (copy-sequence anything-compile-source-functions))
2372 anything-compile-source-functions)))
2373 (when (or (equal arg '(16))
2374 (and anything-c-etags-mtime-alist
2375 (anything-c-etags-file-modified-p tag)))
2376 (remhash tag anything-c-etags-cache))
2377 (if (and tag (file-exists-p tag))
2378 (anything :sources 'anything-c-source-etags-select
2379 :keymap anything-c-etags-map
2380 :input init
2381 :buffer "*anything etags*")
2382 (message "Error: No tag file found, please create one with etags shell command."))))
2384 ;;;###autoload
2385 (defun anything-filelist ()
2386 "Preconfigured `anything' to open files instantly.
2388 See `anything-c-filelist-file-name' docstring for usage."
2389 (interactive)
2390 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
2392 ;;;###autoload
2393 (defun anything-filelist+ ()
2394 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
2396 This is a replacement for `anything-for-files'.
2397 See `anything-c-filelist-file-name' docstring for usage."
2398 (interactive)
2399 (anything-other-buffer
2400 '(anything-c-source-ffap-line
2401 anything-c-source-ffap-guesser
2402 anything-c-source-buffers-list
2403 anything-c-source-recentf
2404 anything-c-source-bookmarks
2405 anything-c-source-file-cache
2406 anything-c-source-filelist)
2407 "*anything file list*"))
2409 ;;;###autoload
2410 (defun anything-M-x ()
2411 "Preconfigured `anything' for Emacs commands.
2412 It is `anything' replacement of regular `M-x' `execute-extended-command'."
2413 (interactive)
2414 (let* (in-help
2415 help-cand
2416 anything-persistent-action-use-special-display
2417 (history (loop with hist
2418 for i in extended-command-history
2419 for com = (intern i)
2420 when (fboundp com)
2421 collect i into hist finally return hist))
2422 (command (anything-comp-read
2423 "M-x " obarray
2424 :test 'commandp
2425 :must-match t
2426 :requires-pattern 2
2427 :name "Emacs Commands"
2428 :persistent-action
2429 #'(lambda (candidate)
2430 (let ((hbuf (get-buffer (help-buffer))))
2431 (if (and in-help (string= candidate help-cand))
2432 (progn
2433 ;; When M-x is started from a help buffer,
2434 ;; Don't kill it as it is anything-current-buffer.
2435 (unless (equal hbuf anything-current-buffer)
2436 (kill-buffer hbuf))
2437 (setq in-help nil))
2438 ;; Be sure anything-current-buffer have not a dedicated window.
2439 (set-window-dedicated-p
2440 (get-buffer-window anything-current-buffer) nil)
2441 (describe-function (intern candidate))
2442 (message nil) ; Erase the new stupid message Type "q"[...]
2443 (setq in-help t))
2444 (setq help-cand candidate)))
2445 :persistent-help "Describe this command"
2446 :history history
2447 :sort 'string-lessp
2448 :fc-transformer 'anything-M-x-transformer)))
2449 (unless current-prefix-arg (setq current-prefix-arg anything-current-prefix-arg))
2450 (call-interactively (intern command))
2451 (setq extended-command-history (cons command (delete command history)))))
2453 ;;;###autoload
2454 (defun anything-manage-advice ()
2455 "Preconfigured `anything' to disable/enable function advices."
2456 (interactive)
2457 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
2459 ;;;###autoload
2460 (defun anything-bookmark-ext ()
2461 "Preconfigured `anything' for bookmark-extensions sources.
2462 Needs bookmark-ext.el:
2463 <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>.
2464 Contain also `anything-c-source-google-suggest'."
2465 (interactive)
2466 (anything
2467 :sources
2468 '(anything-c-source-bookmark-files&dirs
2469 anything-c-source-bookmark-w3m
2470 anything-c-source-google-suggest
2471 anything-c-source-bmkext-addressbook
2472 anything-c-source-bookmark-gnus
2473 anything-c-source-bookmark-info
2474 anything-c-source-bookmark-man
2475 anything-c-source-bookmark-images
2476 anything-c-source-bookmark-su-files&dirs
2477 anything-c-source-bookmark-ssh-files&dirs)
2478 :prompt "SearchBookmark: "
2479 :buffer "*anything bmkext*"))
2481 ;;;###autoload
2482 (defun anything-simple-call-tree ()
2483 "Preconfigured `anything' for simple-call-tree. List function relationships.
2485 Needs simple-call-tree.el.
2486 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
2487 (interactive)
2488 (anything-other-buffer
2489 '(anything-c-source-simple-call-tree-functions-callers
2490 anything-c-source-simple-call-tree-callers-functions)
2491 "*anything simple-call-tree*"))
2493 ;;;###autoload
2494 (defun anything-mark-ring ()
2495 "Preconfigured `anything' for `anything-c-source-mark-ring'."
2496 (interactive)
2497 (anything 'anything-c-source-mark-ring))
2499 ;;;###autoload
2500 (defun anything-global-mark-ring ()
2501 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
2502 (interactive)
2503 (anything 'anything-c-source-global-mark-ring))
2505 ;;;###autoload
2506 (defun anything-all-mark-rings ()
2507 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
2508 `anything-c-source-mark-ring'."
2509 (interactive)
2510 (anything '(anything-c-source-mark-ring
2511 anything-c-source-global-mark-ring)))
2513 ;;;###autoload
2514 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
2515 "Preconfigured `anything' to edit or view EmacsWiki page.
2517 Needs yaoddmuse.el.
2519 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
2520 (interactive)
2521 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
2523 ;;;###autoload
2524 (defun anything-yaoddmuse-emacswiki-post-library ()
2525 "Preconfigured `anything' to post library to EmacsWiki.
2527 Needs yaoddmuse.el.
2529 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
2530 (interactive)
2531 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
2533 ;;;###autoload
2534 (defun anything-eval-expression (arg)
2535 "Preconfigured anything for `anything-c-source-evaluation-result'."
2536 (interactive "P")
2537 (anything :sources 'anything-c-source-evaluation-result
2538 :input (when arg (thing-at-point 'sexp))
2539 :buffer "*anything eval*"
2540 :keymap anything-eval-expression-map))
2542 ;;;###autoload
2543 (defun anything-eval-expression-with-eldoc ()
2544 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
2545 (interactive)
2546 (declare (special eldoc-idle-delay))
2547 (let ((timer (run-with-idle-timer eldoc-idle-delay
2548 'repeat 'anything-eldoc-show-in-eval))
2549 (minibuffer-completing-symbol t) ; Enable lisp completion.
2550 (completion-cycle-threshold t)) ; Always cycle, no pesty completion buffer (emacs24 only).
2551 (unwind-protect
2552 (minibuffer-with-setup-hook
2553 'anything-eldoc-store-minibuffer
2554 (call-interactively 'anything-eval-expression))
2555 (and timer (cancel-timer timer))
2556 (setq anything-eldoc-active-minibuffers-list
2557 (cdr anything-eldoc-active-minibuffers-list)))))
2559 ;;;###autoload
2560 (defun anything-calcul-expression ()
2561 "Preconfigured anything for `anything-c-source-calculation-result'."
2562 (interactive)
2563 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
2565 ;;;###autoload
2566 (defun anything-surfraw (pattern engine)
2567 "Preconfigured `anything' to search PATTERN with search ENGINE."
2568 (interactive (list (read-string "SearchFor: ")
2569 (anything-comp-read
2570 "Engine: "
2571 (anything-c-build-elvi-list)
2572 :must-match t
2573 :name "Surfraw Search Engines"
2574 :history anything-surfraw-engines-history)))
2575 (let* ((engine-nodesc (car (split-string engine)))
2576 (url (with-temp-buffer
2577 (apply 'call-process "surfraw" nil t nil
2578 ;;JAVE
2579 (append (list engine-nodesc "-p") (split-string pattern)))
2580 (replace-regexp-in-string
2581 "\n" "" (buffer-string))))
2582 (browse-url-browser-function (or anything-surfraw-default-browser-function
2583 browse-url-browser-function)))
2584 (if (string= engine-nodesc "W")
2585 (anything-c-browse-url)
2586 (anything-c-browse-url url)
2587 (setq anything-surfraw-engines-history
2588 (cons engine (delete engine anything-surfraw-engines-history))))))
2590 ;;;###autoload
2591 (defun anything-call-source ()
2592 "Preconfigured `anything' to call anything source."
2593 (interactive)
2594 (anything 'anything-c-source-call-source nil nil nil nil
2595 anything-source-select-buffer))
2597 ;;;###autoload
2598 (defun anything-execute-anything-command ()
2599 "Preconfigured `anything' to execute preconfigured `anything'."
2600 (interactive)
2601 (anything-other-buffer 'anything-c-source-anything-commands
2602 "*anything commands*"))
2604 ;;;###autoload
2605 (defun anything-create (&optional string initial-input)
2606 "Preconfigured `anything' to do many create actions from STRING.
2607 See also `anything-create--actions'."
2608 (interactive)
2609 (setq string (or string (read-string "Create Anything: " initial-input)))
2610 (anything '(((name . "Anything Create")
2611 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
2612 (candidates . anything-create--actions)
2613 (candidate-number-limit)
2614 (action . (lambda (func) (funcall func string)))))))
2616 ;;;###autoload
2617 (defun anything-top ()
2618 "Preconfigured `anything' for top command."
2619 (interactive)
2620 (let ((anything-samewindow t)
2621 (anything-enable-shortcuts)
2622 (anything-display-function 'anything-default-display-buffer)
2623 (anything-candidate-number-limit 9999))
2624 (save-window-excursion
2625 (delete-other-windows)
2626 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
2628 ;;;###autoload
2629 (defun anything-select-xfont ()
2630 "Preconfigured `anything' to select Xfont."
2631 (interactive)
2632 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
2634 ;;;###autoload
2635 (defun anything-world-time ()
2636 "Preconfigured `anything' to show world time."
2637 (interactive)
2638 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
2640 ;;;###autoload
2641 (defun anything-apt (arg query)
2642 "Preconfigured `anything' : frontend of APT package manager.
2643 With a prefix arg reload cache."
2644 (interactive "P\nsSearch Package: ")
2645 (when arg
2646 (setq anything-c-apt-installed-packages nil)
2647 (setq anything-c-apt-all-packages nil))
2648 (anything :sources 'anything-c-source-apt
2649 :prompt "Search Package: " :input query))
2651 ;;;###autoload
2652 (defun anything-esh-pcomplete ()
2653 "Preconfigured anything to provide anything completion in eshell."
2654 (interactive)
2655 (let* ((anything-quit-if-no-candidate t)
2656 (anything-execute-action-at-once-if-one t)
2657 (target (thing-at-point 'symbol))
2658 (end (point))
2659 (beg (or (and target (- end (length target)))
2660 ;; Nothing at point.
2661 (progn (insert " ") (point)))))
2662 (setq anything-ec-target (or target " "))
2663 (with-anything-show-completion beg end
2664 (anything :sources 'anything-c-source-esh
2665 :input (anything-ff-set-pattern ; Handle tramp filenames.
2666 (car (last (ignore-errors ; Needed in lisp symbols completion.
2667 (pcomplete-parse-arguments)))))))))
2669 ;;;###autoload
2670 (defun anything-eshell-history ()
2671 "Preconfigured anything for eshell history."
2672 (interactive)
2673 (let* ((end (point))
2674 (beg (progn (save-excursion (insert " ") (point)))))
2675 (with-anything-show-completion beg end
2676 (anything-other-buffer anything-c-source-eshell-history "*Eshell history*"))))
2678 ;;;###autoload
2679 (defun anything-c-run-external-command (program)
2680 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
2681 If program is already running exit with error.
2682 You can set your own list of commands with
2683 `anything-c-external-commands-list'."
2684 (interactive (list
2685 (anything-comp-read
2686 "RunProgram: "
2687 (anything-c-external-commands-list-1 'sort)
2688 :must-match t
2689 :name "External Commands"
2690 :history anything-external-command-history)))
2691 (anything-run-or-raise program)
2692 (setq anything-external-command-history
2693 (cons program (delete program
2694 (loop for i in anything-external-command-history
2695 when (executable-find i) collect i)))))
2697 ;;;###autoload
2698 (defun anything-ratpoison-commands ()
2699 "Preconfigured `anything' to execute ratpoison commands."
2700 (interactive)
2701 (anything-other-buffer 'anything-c-source-ratpoison-commands
2702 "*anything ratpoison commands*"))
2704 ;;;###autoload
2705 (defun anything-ucs ()
2706 "Preconfigured anything for `ucs-names' math symbols."
2707 (interactive)
2708 (anything :sources 'anything-c-source-ucs
2709 :keymap anything-c-ucs-map))
2713 ;;; Utilities Functions
2716 (defun anything-ff-find-printers ()
2717 "Return a list of available printers on Unix systems."
2718 (let ((printer-list (with-temp-buffer
2719 (call-process "lpstat" nil t nil "-a")
2720 (split-string (buffer-string) "\n"))))
2721 (loop for p in printer-list
2722 for printer = (car (split-string p))
2723 when printer
2724 collect printer)))
2726 ;; Shut up byte compiler in emacs24*.
2727 (defun anything-c-switch-to-buffer (buffer-or-name)
2728 "Same as `switch-to-buffer' whithout warnings at compile time."
2729 (with-no-warnings
2730 (switch-to-buffer buffer-or-name)))
2732 (defsubst* anything-c-position (item seq &key (test 'eq))
2733 "A simple and faster replacement of CL `position'."
2734 (loop for i in seq for index from 0
2735 when (funcall test i item) return index))
2737 (defun anything-c-get-pid-from-process-name (process-name)
2738 "Get pid from running process PROCESS-NAME."
2739 (loop with process-list = (list-system-processes)
2740 for pid in process-list
2741 for process = (assoc-default 'comm (process-attributes pid))
2742 when (and process (string-match process-name process))
2743 return pid))
2745 (defun* anything-current-buffer-narrowed-p (&optional
2746 (buffer anything-current-buffer))
2747 "Check if BUFFER is narrowed.
2748 Default is `anything-current-buffer'."
2749 (with-current-buffer buffer
2750 (let ((beg (point-min))
2751 (end (point-max))
2752 (total (buffer-size)))
2753 (or (/= beg 1) (/= end (1+ total))))))
2755 (defun anything-region-active-p ()
2756 (and transient-mark-mode mark-active (/= (mark) (point))))
2758 (defun anything-goto-line (lineno)
2759 "Goto LINENO opening only outline headline if needed."
2760 (goto-char (point-min)) (forward-line (1- lineno))
2761 (when (or (eq major-mode 'org-mode)
2762 (and (boundp 'outline-minor-mode)
2763 outline-minor-mode))
2764 (org-reveal))
2765 (anything-match-line-color-current-line) (sit-for 0.3)
2766 (anything-match-line-cleanup))
2768 (defun anything-show-this-source-only ()
2769 "Show all candidates of this source."
2770 (interactive)
2771 (setq anything-candidate-number-limit nil)
2772 (anything-set-source-filter
2773 (list (assoc-default 'name (anything-get-current-source)))))
2775 ;;;###autoload
2776 (defun anything-test-sources ()
2777 "List all anything sources for test.
2778 The output is sexps which are evaluated by \\[eval-last-sexp]."
2779 (interactive)
2780 (with-output-to-temp-buffer "*Anything Test Sources*"
2781 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
2782 (apropos-internal "^anything-c-source" #'boundp))
2783 (pop-to-buffer standard-output)))
2785 (defun anything-nest (&rest same-as-anything)
2786 "Nested `anything'. If you use `anything' within `anything', use it."
2787 (with-selected-window (anything-window)
2788 (let (anything-current-position
2789 anything-current-buffer
2790 (orig-anything-buffer anything-buffer)
2791 anything-pattern
2792 anything-buffer
2793 anything-sources
2794 anything-compiled-sources
2795 anything-buffer-chars-modified-tick
2796 (anything-samewindow t)
2797 (enable-recursive-minibuffers t))
2798 (unwind-protect
2799 (apply #'anything same-as-anything)
2800 (anything-initialize-overlays orig-anything-buffer)
2801 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
2803 (defun anything-displaying-source-names ()
2804 "Display sources name."
2805 (with-current-buffer anything-buffer
2806 (goto-char (point-min))
2807 (loop with pos
2808 while (setq pos (next-single-property-change (point) 'anything-header))
2809 do (goto-char pos)
2810 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
2811 do (forward-line 1))))
2813 ;; [Obsolete]
2814 (defun anything-select-source ()
2815 "[OBSOLETE] Select source."
2816 (interactive)
2817 (let ((default (assoc-default 'name (anything-get-current-source)))
2818 (source-names (anything-displaying-source-names))
2819 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
2820 (anything-get-sources))))
2821 (setq anything-candidate-number-limit 9999)
2822 (anything-aif
2823 (let (anything-source-filter)
2824 (anything-nest '(((name . "Anything Source")
2825 (candidates . source-names)
2826 (action . identity))
2827 ((name . "Anything Source (ALL)")
2828 (candidates . all-source-names)
2829 (action . identity)))
2830 nil "Source: " nil
2831 default "*anything select source*"))
2832 (anything-set-source-filter (list it))
2833 (anything-set-source-filter nil))))
2835 (defun anything-c-match-on-file-name (candidate)
2836 "Return non-nil if `anything-pattern' match basename of filename CANDIDATE."
2837 (string-match anything-pattern (file-name-nondirectory candidate)))
2839 (defun anything-c-match-on-directory-name (candidate)
2840 "Return non-nil if `anything-pattern' match directory part of CANDIDATE."
2841 (anything-aif (file-name-directory candidate)
2842 (string-match anything-pattern it)))
2844 (defun anything-c-string-match (candidate)
2845 "Return non-nil if `anything-pattern' match CANDIDATE.
2846 The match is done with `string-match'."
2847 (string-match anything-pattern candidate))
2849 (defun anything-c-skip-entries (list regexp)
2850 "Remove entries which matches REGEXP from LIST."
2851 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
2852 list))
2854 (defun anything-c-shadow-entries (list regexp)
2855 "Display elements of LIST matching REGEXP with the `file-name-shadow' face."
2856 (mapcar (lambda (file)
2857 ;; Add shadow face property to boring files.
2858 (let ((face (if (facep 'file-name-shadow)
2859 'file-name-shadow
2860 ;; fall back to default on XEmacs
2861 'default)))
2862 (if (string-match regexp file)
2863 (setq file (propertize file 'face face))))
2864 file)
2865 list))
2867 (defsubst anything-c-stringify (str-or-sym)
2868 "Get string of STR-OR-SYM."
2869 (if (stringp str-or-sym)
2870 str-or-sym
2871 (symbol-name str-or-sym)))
2873 (defsubst anything-c-symbolify (str-or-sym)
2874 "Get symbol of STR-OR-SYM."
2875 (if (symbolp str-or-sym)
2876 str-or-sym
2877 (intern str-or-sym)))
2879 (defun anything-c-describe-function (func)
2880 "FUNC is symbol or string."
2881 (describe-function (anything-c-symbolify func)))
2883 (defun anything-c-describe-variable (var)
2884 "VAR is symbol or string."
2885 (describe-variable (anything-c-symbolify var)))
2887 (defun anything-c-find-function (func)
2888 "FUNC is symbol or string."
2889 (find-function (anything-c-symbolify func)))
2891 (defun anything-c-find-variable (var)
2892 "VAR is symbol or string."
2893 (find-variable (anything-c-symbolify var)))
2895 (defun anything-c-kill-new (candidate &optional replace)
2896 "CANDIDATE is symbol or string.
2897 See `kill-new' for argument REPLACE."
2898 (kill-new (anything-c-stringify candidate) replace))
2900 (defun* anything-fast-remove-dups (seq &key (test 'eq))
2901 "Remove duplicates elements in list SEQ.
2902 This is same as `remove-duplicates' but with memoisation.
2903 It is much faster, especially in large lists.
2904 A test function can be provided with TEST argument key.
2905 Default is `eq'."
2906 (let ((cont (make-hash-table :test test)))
2907 (loop for elm in seq
2908 unless (gethash elm cont)
2909 do (puthash elm elm cont)
2910 finally return
2911 (loop for i being the hash-values in cont collect i))))
2913 (defadvice eval-defun (after anything-source-hack activate)
2914 "Allow immediate execution of anything source when evaling it.
2915 See `anything-c-enable-eval-defun-hack'."
2916 (when anything-c-enable-eval-defun-hack
2917 (let ((varsym (save-excursion
2918 (beginning-of-defun)
2919 (forward-char 1)
2920 (when (memq (read (current-buffer)) '(defvar setq))
2921 (read (current-buffer))))))
2922 (when (string-match "^anything-c-source-" (symbol-name varsym))
2923 (anything varsym)))))
2924 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
2926 (defadvice anything-quit-and-find-file (around use-anything-find-files activate)
2927 "Let `anything-quit-and-find-file' take advantage of `anything-find-files'."
2928 (interactive)
2929 (anything-run-after-quit
2930 (lambda (f)
2931 (if (file-exists-p f)
2932 (anything-find-files-1 (file-name-directory f)
2933 (if anything-ff-transformer-show-only-basename
2934 (anything-c-basename f) f))
2935 (anything-find-files-1 f)))
2936 (anything-aif (get-buffer (anything-get-selection))
2937 (or (buffer-file-name it)
2938 (car (rassoc it dired-buffers))
2939 (and (with-current-buffer it
2940 (eq major-mode 'org-agenda-mode))
2941 org-directory
2942 (expand-file-name org-directory))
2943 default-directory)
2944 (let ((sel (anything-get-selection)))
2945 (if (file-exists-p sel)
2946 (expand-file-name sel)
2947 default-directory)))))
2949 (defmacro* anything-c-walk-directory (directory &key (path 'basename) (directories t) match)
2950 "Walk through DIRECTORY tree.
2951 PATH can be one of basename, relative, or full.
2952 DIRECTORIES when non--nil (default) return also directories names, otherwise
2953 skip directories names.
2954 MATCH match only filenames matching regexp MATCH."
2955 `(let (result
2956 (fn (case ,path
2957 (basename 'file-name-nondirectory)
2958 (relative 'file-relative-name)
2959 (full 'identity)
2960 (t (error "Error: Invalid path spec `%s', must be one of basename, relative or full." ,path)))))
2961 (labels ((ls-R (dir)
2962 (loop with ls = (directory-files dir t directory-files-no-dot-files-regexp)
2963 for f in ls
2964 if (file-directory-p f)
2965 do (progn (when ,directories
2966 (push (funcall fn f) result))
2967 ;; Don't recurse in directory symlink.
2968 (unless (file-symlink-p f)
2969 (ls-R f)))
2970 else do
2971 (unless (and ,match (not (string-match ,match (file-name-nondirectory f))))
2972 (push (funcall fn f) result)))))
2973 (ls-R ,directory)
2974 (nreverse result))))
2976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2978 ;;; Anything regexp.
2981 (defun anything-c-query-replace-regexp (candidate)
2982 "Query replace regexp from `anything-regexp'.
2983 With a prefix arg replace only matches surrounded by word boundaries,
2984 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
2985 (let ((regexp (funcall (anything-attr 'regexp))))
2986 (apply 'query-replace-regexp
2987 (anything-c-query-replace-args regexp))))
2989 (defun anything-c-kill-regexp-as-sexp (candidate)
2990 "Kill regexp in a format usable in lisp code."
2991 (anything-c-regexp-kill-new
2992 (prin1-to-string (funcall (anything-attr 'regexp)))))
2994 (defun anything-c-kill-regexp (candidate)
2995 "Kill regexp as it is in `anything-pattern'."
2996 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
2998 (defun anything-c-query-replace-args (regexp)
2999 "create arguments of `query-replace-regexp' action in `anything-regexp'."
3000 (let ((region-only (anything-region-active-p)))
3001 (list
3002 regexp
3003 (query-replace-read-to regexp
3004 (format "Query replace %sregexp %s"
3005 (if anything-current-prefix-arg "word " "")
3006 (if region-only "in region " ""))
3008 anything-current-prefix-arg
3009 (when region-only (region-beginning))
3010 (when region-only (region-end)))))
3012 (defvar anything-c-source-regexp
3013 '((name . "Regexp Builder")
3014 (init . (lambda ()
3015 (anything-candidate-buffer anything-current-buffer)))
3016 (candidates-in-buffer)
3017 (get-line . anything-c-regexp-get-line)
3018 (persistent-action . anything-c-regexp-persistent-action)
3019 (persistent-help . "Show this line")
3020 (multiline)
3021 (delayed)
3022 (requires-pattern . 2)
3023 (mode-line . "Press TAB to select action.")
3024 (regexp . (lambda () anything-input))
3025 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
3026 ("Query Replace Regexp (C-u Not inside word.)"
3027 . anything-c-query-replace-regexp)
3028 ("Kill Regexp" . anything-c-kill-regexp)))))
3030 (defun anything-c-regexp-get-line (s e)
3031 (propertize
3032 (apply 'concat
3033 ;; Line contents
3034 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
3035 ;; subexps
3036 (loop for i from 0 to (1- (/ (length (match-data)) 2))
3037 collect (format "\n %s'%s'"
3038 (if (zerop i) "Group 0: " (format "Group %d: " i))
3039 (match-string i))))
3040 ;; match beginning
3041 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
3042 ;; It is implementation problem of candidates-in-buffer.
3043 'anything-realvalue
3044 (1- s)))
3046 (defun anything-c-regexp-persistent-action (pt)
3047 (goto-char pt)
3048 (anything-persistent-highlight-point))
3050 (defun anything-c-regexp-kill-new (input)
3051 (kill-new input)
3052 (message "Killed: %s" input))
3056 ;;; Toggle all marks.
3059 ;;;###autoload
3060 (defun anything-mark-all ()
3061 "Mark all visible unmarked candidates in current source."
3062 (interactive)
3063 (with-anything-window
3064 (save-excursion
3065 (goto-char (anything-get-previous-header-pos))
3066 (anything-next-line)
3067 (let* ((next-head (anything-get-next-header-pos))
3068 (end (and next-head
3069 (save-excursion
3070 (goto-char next-head)
3071 (forward-line -1)
3072 (point))))
3073 (maxpoint (or end (point-max))))
3074 (while (< (point) maxpoint)
3075 (anything-mark-current-line)
3076 (let ((prefix (get-text-property (point-at-bol) 'display))
3077 (bn (anything-c-basename (anything-get-selection)))
3078 (src (assoc-default 'name (anything-get-current-source))))
3079 (when (and (not (anything-this-visible-mark))
3080 (not (or (string= prefix "[?]")
3081 (string= prefix "[@]"))))
3082 ;; Don't mark possibles directories ending with . or ..
3083 ;; and also autosave files/links.
3084 (unless
3085 (and (or (anything-file-completion-source-p)
3086 (equal src "Files from Current Directory"))
3087 (string-match "^\\.#.*\\|^#.*#$\\|\\.$" bn))
3088 (anything-make-visible-mark))))
3089 (forward-line 1) (end-of-line))))
3090 (anything-mark-current-line)
3091 (message "%s candidates marked" (length anything-marked-candidates))))
3093 ;;;###autoload
3094 (defun anything-unmark-all ()
3095 "Unmark all candidates in all sources of current anything session."
3096 (interactive)
3097 (with-anything-window
3098 (let ((len (length anything-marked-candidates)))
3099 (save-excursion
3100 (anything-clear-visible-mark))
3101 (setq anything-marked-candidates nil)
3102 (anything-mark-current-line)
3103 (message "%s candidates unmarked" len))))
3105 ;;;###autoload
3106 (defun anything-toggle-all-marks ()
3107 "Toggle all marks.
3108 Mark all visible candidates of current source or unmark all candidates
3109 visible or invisible in all sources of current anything session"
3110 (interactive)
3111 (let ((marked (anything-marked-candidates)))
3112 (if (and (>= (length marked) 1)
3113 (with-anything-window anything-visible-mark-overlays))
3114 (anything-unmark-all)
3115 (anything-mark-all))))
3117 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
3121 ;;; Buffers
3124 (defun anything-c-buffer-list ()
3125 "Return the list of names of buffers with boring buffers filtered out.
3126 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
3127 The first buffer in the list will be the last recently used
3128 buffer that is not the current buffer."
3129 (let ((buffers (mapcar 'buffer-name (buffer-list))))
3130 (append (cdr buffers) (list (car buffers)))))
3132 (defvar anything-c-source-buffers
3133 '((name . "Buffers")
3134 (candidates . anything-c-buffer-list)
3135 (type . buffer)))
3136 ;; (anything 'anything-c-source-buffers)
3138 (defvar anything-c-source-buffer-not-found
3139 '((name . "Create buffer")
3140 (dummy)
3141 (filtered-candidate-transformer (lambda (cands source)
3142 (list anything-pattern)))
3143 (action . (lambda (candidate)
3144 (anything-c-switch-to-buffer (get-buffer-create candidate))))))
3145 ;; (anything 'anything-c-source-buffer-not-found)
3147 ;;; Buffers-list (was buffers+)
3150 (eval-when-compile (require 'dired))
3152 (defun anything-c-highlight-buffers (buffers)
3153 (loop for i in buffers
3154 for buf = (get-buffer i)
3155 for bfname = (buffer-file-name buf)
3156 collect
3157 (cond (;; A dired buffer.
3158 (rassoc buf dired-buffers)
3159 (propertize i 'face 'anything-ff-directory
3160 'help-echo (car (rassoc buf dired-buffers))))
3161 ;; A buffer file modified somewhere outside of emacs.
3162 ((and bfname (not (file-remote-p bfname))
3163 (file-exists-p bfname)
3164 (not (verify-visited-file-modtime buf)))
3165 (propertize i 'face 'anything-buffer-saved-out
3166 'help-echo bfname))
3167 ;; A new buffer file not already saved on disk.
3168 ((and bfname (not (file-remote-p bfname))
3169 (not (verify-visited-file-modtime buf)))
3170 (propertize i 'face 'anything-buffer-not-saved
3171 'help-echo bfname))
3172 ;; A Remote buffer file modified and not saved on disk.
3173 ((and bfname (file-remote-p bfname) (buffer-modified-p buf))
3174 (let ((prefix (propertize
3175 " " 'display
3176 (propertize "@ " 'face 'anything-ff-prefix))))
3177 (cons (concat prefix (propertize i 'face 'anything-ff-symlink
3178 'help-echo bfname)) i)))
3179 ;; A buffer file modified and not saved on disk.
3180 ((and bfname (buffer-modified-p buf))
3181 (propertize i 'face 'anything-ff-symlink
3182 'help-echo bfname))
3183 ;; A remote buffer file not modified and saved on disk.
3184 ((and bfname (file-remote-p bfname))
3185 (let ((prefix (propertize
3186 " " 'display
3187 (propertize "@ " 'face 'anything-ff-prefix))))
3188 (cons (concat prefix (propertize i 'face 'font-lock-type-face
3189 'help-echo bfname)) i)))
3190 ;; A buffer file not modified and saved on disk.
3191 (bfname
3192 (propertize i 'face 'font-lock-type-face
3193 'help-echo bfname))
3194 ;; Any non--file buffer.
3195 (t (propertize i 'face 'italic)))))
3198 (defvar anything-c-source-buffers-list
3199 '((name . "Buffers")
3200 (candidates . anything-c-buffer-list)
3201 (type . buffer)
3202 (match anything-c-buffer-match-major-mode)
3203 (diff-action . anything-buffer-toggle-diff)
3204 (revert-action . anything-buffer-revert-and-update)
3205 (save-action . anything-buffer-save-and-update)
3206 (candidate-transformer anything-c-skip-current-buffer
3207 anything-c-skip-boring-buffers
3208 anything-c-highlight-buffers)
3209 (persistent-action . anything-c-buffers-list-persistent-action)
3210 (volatile)
3211 (mode-line . anything-buffer-mode-line-string)
3212 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
3213 ;; (anything 'anything-c-source-buffers-list)
3215 (defun anything-c-buffer-match-major-mode (candidate)
3216 "Match maybe buffer by major-mode.
3217 If you give a major-mode or partial major-mode,
3218 it will list all buffers of this major-mode and/or buffers with name
3219 matching this major-mode.
3220 If you add a space after major-mode and then a space,
3221 it will match all buffers of the major-mode
3222 before space matching pattern after space.
3223 If you give a pattern which doesn't match a major-mode, it will search buffer
3224 with name matching pattern."
3225 (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
3226 (buf (get-buffer cand)))
3227 (when buf
3228 (with-current-buffer buf
3229 (let ((mjm (symbol-name major-mode))
3230 (split (split-string anything-pattern)))
3231 (cond ((string-match "\\s-$" anything-pattern)
3232 (string-match (car split) mjm))
3233 ((string-match "\\s-" anything-pattern)
3234 (and (string-match (car split) mjm)
3235 (string-match (cadr split) cand)))
3236 (t (or (string-match anything-pattern mjm)
3237 (string-match anything-pattern cand)))))))))
3239 (defun anything-c-buffer-query-replace-1 (&optional regexp-flag)
3240 "Query replace in marked buffers.
3241 If REGEXP-FLAG is given use `query-replace-regexp'."
3242 (let ((fn (if regexp-flag 'query-replace-regexp 'query-replace))
3243 (prompt (if regexp-flag "Query replace regexp" "Query replace"))
3244 (bufs (anything-marked-candidates)))
3245 (loop
3246 with replace = (query-replace-read-from prompt regexp-flag)
3247 with tostring = (unless (consp replace)
3248 (query-replace-read-to
3249 replace prompt regexp-flag))
3250 for buf in bufs
3252 (save-window-excursion
3253 (anything-c-switch-to-buffer buf)
3254 (save-excursion
3255 (let ((case-fold-search t))
3256 (goto-char (point-min))
3257 (if (consp replace)
3258 (apply fn (list (car replace) (cdr replace)))
3259 (apply fn (list replace tostring)))))))))
3261 (defun anything-c-buffer-query-replace-regexp (candidate)
3262 (anything-c-buffer-query-replace-1 'regexp))
3264 (defun anything-c-buffer-query-replace (candidate)
3265 (anything-c-buffer-query-replace-1))
3267 (defun anything-buffer-toggle-diff (candidate)
3268 "Toggle diff buffer CANDIDATE with it's file."
3269 (if (get-buffer-window "*Diff*")
3270 (kill-buffer "*Diff*")
3271 (diff-buffer-with-file (get-buffer candidate))))
3273 ;;;###autoload
3274 (defun anything-buffer-diff-persistent ()
3275 "Toggle diff buffer without quitting anything."
3276 (interactive)
3277 (anything-execute-persistent-action 'diff-action))
3279 (defun anything-buffer-revert-and-update (candidate)
3280 (let ((marked (anything-marked-candidates)))
3281 (loop for buf in marked do (anything-revert-buffer buf))
3282 (anything-force-update)
3283 (anything-c-recenter-window)))
3285 ;;;###autoload
3286 (defun anything-buffer-revert-persistent ()
3287 "Revert buffer without quitting anything."
3288 (interactive)
3289 (anything-execute-persistent-action 'revert-action 'onewindow))
3291 (defun anything-buffer-save-and-update (candidate)
3292 (let ((marked (anything-marked-candidates))
3293 (enable-recursive-minibuffers t))
3294 (loop for buf in marked do
3295 (with-current-buffer (get-buffer buf)
3296 (save-buffer)))
3297 (anything-force-update)
3298 (anything-c-recenter-window)))
3300 ;;;###autoload
3301 (defun anything-buffer-save-persistent ()
3302 "Save buffer without quitting anything."
3303 (interactive)
3304 (anything-execute-persistent-action 'save-action 'onewindow))
3306 ;;;###autoload
3307 (defun anything-buffer-run-kill-buffers ()
3308 "Run kill buffer action from `anything-c-source-buffers-list'."
3309 (interactive)
3310 (anything-c-quit-and-execute-action 'anything-kill-marked-buffers))
3312 ;;;###autoload
3313 (defun anything-buffer-run-grep ()
3314 "Run Grep action from `anything-c-source-buffers-list'."
3315 (interactive)
3316 (anything-c-quit-and-execute-action 'anything-c-grep-buffers))
3318 ;;;###autoload
3319 (defun anything-buffer-run-zgrep ()
3320 "Run Grep action from `anything-c-source-buffers-list'."
3321 (interactive)
3322 (anything-c-quit-and-execute-action 'anything-c-zgrep-buffers))
3324 ;;;###autoload
3325 (defun anything-buffer-run-query-replace-regexp ()
3326 "Run Query replace regexp action from `anything-c-source-buffers-list'."
3327 (interactive)
3328 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace-regexp))
3330 ;;;###autoload
3331 (defun anything-buffer-run-query-replace ()
3332 "Run Query replace action from `anything-c-source-buffers-list'."
3333 (interactive)
3334 (anything-c-quit-and-execute-action 'anything-c-buffer-query-replace))
3336 ;;;###autoload
3337 (defun anything-buffer-switch-other-window ()
3338 "Run switch to other window action from `anything-c-source-buffers-list'."
3339 (interactive)
3340 (anything-c-quit-and-execute-action 'switch-to-buffer-other-window))
3342 ;;;###autoload
3343 (defun anything-buffer-switch-other-frame ()
3344 "Run switch to other frame action from `anything-c-source-buffers-list'."
3345 (interactive)
3346 (anything-c-quit-and-execute-action 'switch-to-buffer-other-frame))
3348 ;;;###autoload
3349 (defun anything-buffer-switch-to-elscreen ()
3350 "Run switch to elscreen action from `anything-c-source-buffers-list'."
3351 (interactive)
3352 (anything-c-quit-and-execute-action 'anything-find-buffer-on-elscreen))
3354 ;;;###autoload
3355 (defun anything-buffer-run-ediff ()
3356 "Run ediff action from `anything-c-source-buffers-list'."
3357 (interactive)
3358 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers))
3360 (defun anything-buffer-run-ediff-merge ()
3361 "Run ediff action from `anything-c-source-buffers-list'."
3362 (interactive)
3363 (anything-c-quit-and-execute-action 'anything-ediff-marked-buffers-merge))
3365 (defun anything-c-buffers-persistent-kill (buffer)
3366 "Persistent action to kill buffer."
3367 (with-current-buffer (get-buffer buffer)
3368 (if (and (buffer-modified-p)
3369 (buffer-file-name (current-buffer)))
3370 (progn
3371 (save-buffer)
3372 (kill-buffer buffer))
3373 (kill-buffer buffer)))
3374 (anything-delete-current-selection))
3376 (defun anything-c-recenter-window ()
3377 "Make visible current selection by recentering anything window."
3378 (with-anything-window (recenter)))
3380 (defun anything-c-buffers-list-persistent-action (candidate)
3381 (if current-prefix-arg
3382 (anything-c-buffers-persistent-kill candidate)
3383 (anything-c-switch-to-buffer candidate)))
3386 ;;;; <File>
3389 ;;; File name history
3390 (defvar anything-c-source-file-name-history
3391 '((name . "File Name History")
3392 (candidates . file-name-history)
3393 (match anything-c-match-on-file-name
3394 anything-c-match-on-directory-name)
3395 (type . file)))
3396 ;; (anything 'anything-c-source-file-name-history)
3398 ;;; Files in current dir
3401 (defvar anything-c-source-files-in-current-dir
3402 '((name . "Files from Current Directory")
3403 (candidates . (lambda ()
3404 (with-anything-current-buffer
3405 (directory-files (anything-c-current-directory)))))
3406 ;; volatile is not needed, I think.
3407 (type . file)))
3408 ;; (anything 'anything-c-source-files-in-current-dir)
3410 (defun anything-c-highlight-files (files)
3411 (loop for i in files
3412 if (file-directory-p i)
3413 collect (propertize (file-name-nondirectory i)
3414 'face 'anything-ff-directory
3415 'help-echo (expand-file-name i))
3416 else
3417 collect (propertize (file-name-nondirectory i)
3418 'face 'anything-ff-file
3419 'help-echo (expand-file-name i))))
3421 (defvar anything-c-source-files-in-current-dir+
3422 '((name . "Files from Current Directory")
3423 (candidates . (lambda ()
3424 (with-anything-current-buffer
3425 (directory-files (anything-c-current-directory) t))))
3426 (candidate-transformer anything-c-highlight-files)
3427 ;; volatile is not needed, I think.
3428 (type . file)))
3429 ;; (anything 'anything-c-source-files-in-current-dir+)
3433 ;;; Anything-find-files - The anything files browser.
3436 ;; Internal.
3437 (defvar anything-c-find-files-doc-header " (`C-l': Go to precedent level)"
3438 "*The doc that is inserted in the Name header of a find-files or dired source.")
3439 (defvar anything-ff-auto-update-flag nil
3440 "Internal, flag to turn on/off auto-update in `anything-find-files'.
3441 Don't set it directly, use instead `anything-ff-auto-update-initial-value'.")
3442 (defvar anything-ff-last-expanded nil
3443 "Store last expanded directory or file.")
3444 (defvar anything-ff-default-directory nil)
3445 (defvar anything-ff-history nil)
3446 (defvar anything-ff-cand-to-mark nil)
3449 (defvar anything-c-source-find-files
3450 `((name . "Find Files")
3451 (header-name . (lambda (name)
3452 (concat name anything-c-find-files-doc-header)))
3453 ;; It is needed for filenames with capital letters
3454 (disable-shortcuts)
3455 (init . (lambda ()
3456 (setq anything-ff-auto-update-flag
3457 anything-ff-auto-update-initial-value)))
3458 (candidates . anything-find-files-get-candidates)
3459 (filtered-candidate-transformer anything-c-find-files-transformer)
3460 (image-action1 . anything-ff-rotate-image-left)
3461 (image-action2 . anything-ff-rotate-image-right)
3462 (toggle-basename . anything-ff-toggle-basename)
3463 (properties-action . anything-ff-properties)
3464 (toggle-auto-update . anything-ff-toggle-auto-update)
3465 (kill-buffer-fname . anything-ff-kill-buffer-fname)
3466 (persistent-action . anything-find-files-persistent-action)
3467 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
3468 (mode-line . anything-ff-mode-line-string)
3469 (volatile)
3470 (candidate-number-limit . 9999)
3471 (action-transformer . anything-find-files-action-transformer)
3472 (action
3473 . ,(delq
3475 `(("Find File" . anything-c-find-file-or-marked)
3476 ("Find file in Dired" . anything-c-point-file-in-dired)
3477 ,(and (locate-library "elscreen")
3478 '("Find file in Elscreen" . anything-elscreen-find-file))
3479 ,(and (locate-library "popwin")
3480 '("Find file in popup window" . popwin:find-file))
3481 ("Checksum File" . anything-ff-checksum)
3482 ("Complete at point `M-tab'"
3483 . anything-c-insert-file-name-completion-at-point)
3484 ("Open file externally `C-c C-x, C-u to choose'"
3485 . anything-c-open-file-externally)
3486 ("Grep File(s) `M-g s, C-u Recurse'" . anything-find-files-grep)
3487 ("Zgrep File(s) `M-g z, C-u Recurse'" . anything-ff-zgrep)
3488 ("Switch to Eshell `M-e'" . anything-ff-switch-to-eshell)
3489 ("Etags `M-., C-u tap, C-u C-u reload tag file'" . anything-ff-etags-select)
3490 ("Eshell command on file(s) `M-!, C-u run on all marked at once.'"
3491 . anything-find-files-eshell-command-on-file)
3492 ("Find file as root" . anything-find-file-as-root)
3493 ("Find file in hex dump" . hexl-find-file)
3494 ("Ediff File `C-='" . anything-find-files-ediff-files)
3495 ("Ediff Merge File `C-c ='" . anything-find-files-ediff-merge-files)
3496 ("Delete File(s) `M-D'" . anything-delete-marked-files)
3497 ("Copy file(s) `M-C, C-u to follow'" . anything-find-files-copy)
3498 ("Copy file(s) Async" . anything-ff-copy-async)
3499 ("Rename file(s) `M-R, C-u to follow'" . anything-find-files-rename)
3500 ("Serial rename files" . anything-ff-serial-rename)
3501 ("Serial rename by symlinking files" . anything-ff-serial-rename-by-symlink)
3502 ("Serial rename by copying files" . anything-ff-serial-rename-by-copying)
3503 ("Symlink files(s) `M-S, C-u to follow'" . anything-find-files-symlink)
3504 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
3505 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
3506 ("Find file other window `C-o'" . find-file-other-window)
3507 ("Switch to history `M-p'" . anything-find-files-switch-to-hist)
3508 ("Find file other frame `C-c C-o'" . find-file-other-frame)
3509 ("Print File `C-c p'" . anything-ff-print)
3510 ("Locate `C-x C-f, C-u to specify locate db'" . anything-ff-locate))))))
3511 ;; (anything 'anything-c-source-find-files)
3513 (defun anything-find-files-set-prompt-for-action (prompt files)
3514 "Set prompt for action in `anything-find-files'."
3515 (let ((len (length files)))
3516 (if (> len 1)
3517 (format "%s * %d Files to: " prompt len)
3518 (format "%s %s to: " prompt (car files)))))
3520 (defun anything-dwim-target-directory ()
3521 "Return value of `default-directory' of buffer in other window.
3522 If there is only one window return the value ot `default-directory'
3523 for current buffer."
3524 (with-anything-current-buffer
3525 (let ((num-windows (length (window-list))))
3526 (if (> num-windows 1)
3527 (save-window-excursion
3528 (other-window 1)
3529 default-directory)
3530 (car anything-ff-history)))))
3532 (defun anything-find-files-do-action (action)
3533 "Generic function for creating action from `anything-c-source-find-files'.
3534 ACTION must be an action supported by `anything-dired-action'."
3535 (let* ((ifiles (mapcar 'expand-file-name ; Allow modify '/foo/.' -> '/foo'
3536 (anything-marked-candidates)))
3537 (cand (anything-get-selection)) ; Target
3538 (prompt (anything-find-files-set-prompt-for-action
3539 (capitalize (symbol-name action)) ifiles))
3540 (parg anything-current-prefix-arg)
3541 (dest (anything-c-read-file-name
3542 prompt
3543 :preselect (if anything-ff-transformer-show-only-basename
3544 (anything-c-basename cand) cand)
3545 :initial-input (anything-dwim-target-directory)
3546 :history (anything-find-files-history :comp-read nil)))
3547 (win-conf (current-window-configuration)))
3548 (unwind-protect
3549 (let ((default-directory anything-ff-default-directory))
3550 (anything-dired-action
3551 dest :files ifiles :action action :follow parg))
3552 ;; Don't reset win-conf when following.
3553 (unless parg (set-window-configuration win-conf)))))
3555 (defun anything-find-files-copy (candidate)
3556 "Copy files from `anything-find-files'."
3557 (anything-find-files-do-action 'copy))
3559 (defun anything-find-files-rename (candidate)
3560 "Rename files from `anything-find-files'."
3561 (anything-find-files-do-action 'rename))
3563 (defun anything-find-files-symlink (candidate)
3564 "Symlink files from `anything-find-files'."
3565 (anything-find-files-do-action 'symlink))
3567 (defun anything-find-files-relsymlink (candidate)
3568 "Relsymlink files from `anything-find-files'."
3569 (anything-find-files-do-action 'relsymlink))
3571 (defun anything-find-files-hardlink (candidate)
3572 "Hardlink files from `anything-find-files'."
3573 (anything-find-files-do-action 'hardlink))
3575 (defun anything-find-files-byte-compile (candidate)
3576 "Byte compile elisp files from `anything-find-files'."
3577 (let ((files (anything-marked-candidates))
3578 (parg anything-current-prefix-arg))
3579 (loop for fname in files
3580 do (byte-compile-file fname parg))))
3582 (defun anything-find-files-load-files (candidate)
3583 "Load elisp files from `anything-find-files'."
3584 (let ((files (anything-marked-candidates)))
3585 (loop for fname in files
3586 do (load fname))))
3588 (defun anything-find-files-ediff-files-1 (candidate &optional merge)
3589 "Generic function to ediff/merge files in `anything-find-files'."
3590 (let ((bname (anything-c-basename candidate))
3591 (prompt (if merge "Ediff Merge `%s' With File: "
3592 "Ediff `%s' With File: "))
3593 (fun (if merge 'ediff-merge-files 'ediff-files)))
3594 (funcall fun
3595 candidate
3596 (condition-case quit
3597 (anything-c-read-file-name
3598 (format prompt bname))
3599 (quit ;; Hit C-g ask user to fallback to locate.
3600 (if (y-or-n-p "Search file for ediff with locate? ")
3601 (anything-c-locate-read-file-name
3602 (format prompt bname)
3603 ;; Check if -b option is available.
3604 (if (and (eq system-type 'windows-nt)
3605 (string-match "^es" anything-c-locate-command))
3606 bname
3607 (concat bname " -b")))
3608 (error "Error: Ediff Operation aborted")))))))
3610 (defun anything-find-files-ediff-files (candidate)
3611 (anything-find-files-ediff-files-1 candidate))
3613 (defun anything-find-files-ediff-merge-files (candidate)
3614 (anything-find-files-ediff-files-1 candidate 'merge))
3616 (defun anything-find-files-grep (candidate)
3617 "Default action to grep files from `anything-find-files'."
3618 (anything-do-grep-1 (anything-marked-candidates)
3619 anything-current-prefix-arg))
3621 (defun anything-ff-zgrep (candidate)
3622 "Default action to zgrep files from `anything-find-files'."
3623 (let ((prefarg anything-current-prefix-arg)
3624 (ls (anything-marked-candidates)))
3625 (anything-ff-zgrep-1 ls prefarg)))
3627 (defun anything-ff-pdfgrep (candidate)
3628 "Default action to pdfgrep files from `anything-find-files'."
3629 (let ((cands (loop for file in (anything-marked-candidates)
3630 if (or (string= (file-name-extension file) "pdf")
3631 (string= (file-name-extension file) "PDF"))
3632 collect file))
3633 (anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init))
3634 (when cands
3635 (anything-do-pdfgrep-1 cands))))
3637 (defun anything-ff-etags-select (candidate)
3638 "Default action to jump to etags from `anything-find-files'."
3639 (when (get-buffer anything-action-buffer)
3640 (kill-buffer anything-action-buffer))
3641 (let ((default-directory anything-ff-default-directory))
3642 (anything-c-etags-select anything-current-prefix-arg)))
3644 (defun anything-find-files-switch-to-hist (candidate)
3645 "Switch to anything-find-files history."
3646 (anything-find-files t))
3648 ;;; Asynchronous copy of files.
3651 (defun anything-c-copy-files-async-1 (flist dest)
3652 "Copy a list of Files FLIST to DEST asynchronously.
3653 It use another emacs process to do the job.
3654 Communication with background emacs is done with temp file
3655 `anything-c-copy-files-async-log-file'."
3656 (start-file-process "emacs-batch" nil anything-c-copy-async-prefered-emacs
3657 "-Q" "--batch" "--eval"
3658 (format "(progn
3659 (require 'dired) (require 'cl)
3660 (let ((dired-recursive-copies 'always)
3661 failures success
3662 (ovw-count 0)
3663 (cpf-count 0))
3664 (dolist (f '%S)
3665 (condition-case err
3666 (let ((file-exists (file-exists-p
3667 (expand-file-name
3668 (file-name-nondirectory (directory-file-name f))
3669 (file-name-directory
3670 (file-name-as-directory \"%s\"))))))
3671 (dired-copy-file f \"%s\" t)
3672 (if file-exists
3673 (progn (push (cons \"Overwriting\" f) success)
3674 (incf ovw-count))
3675 (push (cons \"Copying\" f) success)
3676 (incf cpf-count)))
3677 (file-error
3678 (push (dired-make-relative
3679 (expand-file-name
3680 (file-name-nondirectory (directory-file-name f))
3681 (file-name-directory \"%s\")))
3682 failures))))
3683 (with-current-buffer (find-file-noselect \"%s\")
3684 (erase-buffer)
3685 (when failures
3686 (dolist (fail (reverse failures))
3687 (insert (concat \"Failed to copy \" fail \"\n\"))))
3688 (when success
3689 (loop for (a . s) in (reverse success) do
3690 (insert (concat a \" \" s \" to %s done\n\"))))
3691 (and (/= cpf-count 0) (insert (concat (int-to-string cpf-count) \" File(s) Copied\n\")))
3692 (and (/= ovw-count 0) (insert (concat (int-to-string ovw-count) \" File(s) Overwrited\n\")))
3693 (and failures (insert (concat (int-to-string (length failures)) \" File(s) Failed to copy\n\")))
3694 (save-buffer))))"
3695 flist dest dest dest anything-c-copy-files-async-log-file dest)))
3697 (defun anything-c-copy-async-with-log (flist dest)
3698 "Copy file list FLIST to DEST showing log.
3699 Log is send to `anything-c-copy-files-async-log-file'.
3700 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3701 (declare (special auto-revert-interval))
3702 (pop-to-buffer (find-file-noselect anything-c-copy-files-async-log-file))
3703 (set (make-local-variable 'auto-revert-interval) 1)
3704 (erase-buffer)
3705 (insert "Wait copying files...\n")
3706 (sit-for 0.5) (save-buffer)
3707 (goto-char (point-max))
3708 (auto-revert-mode 1)
3709 (anything-c-copy-files-async-1 flist dest))
3711 (defun anything-ff-copy-async (candidate)
3712 "Anything find files action to copy files async.
3713 Copying is done asynchronously with `anything-c-copy-files-async-1'."
3714 (let ((flist (anything-marked-candidates))
3715 (dest (anything-c-read-file-name
3716 "Copy File(s) async To: "
3717 :preselect candidate
3718 :initial-input (car anything-ff-history)
3719 :history (anything-find-files-history :comp-read nil))))
3720 (anything-c-copy-async-with-log flist dest)))
3722 (defvar eshell-command-aliases-list nil)
3723 (defun anything-find-files-eshell-command-on-file-1 (candidate &optional map)
3724 "Run `eshell-command' on CANDIDATE or marked candidates possibly with an eshell alias.
3726 Basename of CANDIDATE can be a wild-card.
3727 If MAP is given run `eshell-command' on all marked files at once,
3728 Otherwise, run `eshell-command' on each marked files.
3730 If `eshell' or `eshell-command' have not been run once, or if you have no eshell aliases
3731 `eshell-command-aliases-list' will not be loaded first time you use this."
3732 (when (or eshell-command-aliases-list
3733 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
3734 (and eshell-command-aliases-list (eshell-read-aliases-list))
3735 (let* ((cand-list (anything-marked-candidates))
3736 (default-directory (or anything-ff-default-directory
3737 ;; If candidate is an url *-ff-default-directory is nil
3738 ;; so keep value of default-directory.
3739 default-directory))
3740 (command (anything-comp-read
3741 "Command: "
3742 (loop for (a . c) in eshell-command-aliases-list
3743 when (string-match "\\(\\$1\\|\\$\\*\\)$" (car c))
3744 collect (propertize a 'help-echo (car c)) into ls
3745 finally return (sort ls 'string<))))
3746 (com-value (car (assoc-default command eshell-command-aliases-list))))
3747 (if (and (or map (and com-value (string-match "\\$\\*$" com-value)))
3748 (> (length cand-list) 1))
3749 ;; Run eshell-command with ALL marked files as arguments.
3750 (let ((mapfiles (mapconcat 'shell-quote-argument cand-list " ")))
3751 (eshell-command (format "%s %s" command mapfiles)))
3752 ;; Run eshell-command on EACH marked files.
3753 (loop
3754 for i in cand-list
3755 for bn = (anything-c-basename i)
3756 for files = (if (and bn (string-match "^\*" bn))
3757 ;; Assume if fname is a wildcard
3758 ;; cand-list have a length of 1.
3759 (mapconcat
3760 'shell-quote-argument
3761 (file-expand-wildcards i t) " ")
3762 (format "'%s'" i))
3763 for com = (if (string-match "'%s'\\|\"%s\"\\|%s" command)
3764 ;; This allow to enter other args AFTER filename
3765 ;; i.e <command %s some_more_args>
3766 (format command files)
3767 (format "%s %s" command files))
3768 do (eshell-command com))))))
3770 (defun anything-find-files-eshell-command-on-file (candidate)
3771 "Run `eshell-command' on CANDIDATE or marked candidates.
3772 See `anything-find-files-eshell-command-on-file-1' for more info."
3773 (anything-find-files-eshell-command-on-file-1
3774 candidate anything-current-prefix-arg))
3776 (defun anything-ff-switch-to-eshell (candidate)
3777 "Switch to eshell and cd to `anything-ff-default-directory'."
3778 (flet ((cd-eshell ()
3779 (goto-char (point-max))
3780 (insert
3781 (format "cd '%s'" anything-ff-default-directory))
3782 (eshell-send-input)))
3783 (if (get-buffer "*eshell*")
3784 (progn
3785 (anything-c-switch-to-buffer "*eshell*")
3786 (cd-eshell))
3787 (call-interactively 'eshell)
3788 (cd-eshell))))
3790 (defun anything-ff-serial-rename-action (method)
3791 "Rename all marked files to `anything-ff-default-directory' with METHOD.
3792 See `anything-ff-serial-rename-1'."
3793 (let ((cands (anything-marked-candidates))
3794 (name (read-string "NewName: "))
3795 (start (read-number "StartAtNumber: "))
3796 (dir (expand-file-name
3797 (anything-c-read-file-name
3798 "Serial Rename to directory: " :initial-input
3799 (expand-file-name anything-ff-default-directory)))))
3800 (when (y-or-n-p (format "Serial Rename %s *files to `%s' with prefix `%s'? "
3801 (length cands) dir name))
3802 (anything-ff-serial-rename-1 dir cands name start :method method)
3803 (anything-find-files-1 dir))))
3805 (defun anything-ff-member-directory-p (file directory)
3806 (let ((dir-file (expand-file-name (file-name-as-directory (file-name-directory file))))
3807 (cur-dir (expand-file-name (file-name-as-directory directory))))
3808 (string= dir-file cur-dir)))
3810 (defun* anything-ff-serial-rename-1
3811 (directory collection new-name start-at-num &key (method 'rename))
3812 "rename files in COLLECTION to DIRECTORY with the prefix name NEW-NAME.
3813 Rename start at number START-AT-NUM - ex: prefixname-01.jpg.
3814 METHOD can be one of rename, copy or symlink.
3815 Files will be renamed if they are files of current directory, otherwise they
3816 will be treated with METHOD.
3817 Default METHOD is rename."
3818 ;; Maybe remove directories selected by error in collection.
3819 (setq collection (remove-if 'file-directory-p collection))
3820 (flet ((symlink-file (file dest)
3821 (let ((flist (list file)))
3822 (anything-dired-action
3823 dest :action 'symlink :files flist))))
3825 (let* ((tmp-dir (file-name-as-directory
3826 (concat (file-name-as-directory directory)
3827 (symbol-name (gensym "tmp")))))
3828 (fn (case method
3829 (copy 'copy-file)
3830 (symlink 'symlink-file)
3831 (rename 'rename-file)
3832 (t (error "Error: Unknow method %s" method)))))
3833 (make-directory tmp-dir)
3834 (loop for i in collection
3835 for count from start-at-num
3836 for fnum = (if (< count 10) "0%s" "%s")
3837 for nname = (concat tmp-dir new-name (format fnum count)
3838 (file-name-extension i 'dot))
3839 do (if (anything-ff-member-directory-p i directory)
3840 (rename-file i nname)
3841 (funcall fn i nname)))
3842 (loop with dirlist = (directory-files
3843 tmp-dir t directory-files-no-dot-files-regexp)
3844 for f in dirlist do
3845 (if (file-symlink-p f)
3846 (symlink-file (file-truename f)
3847 (concat (file-name-as-directory directory)
3848 (anything-c-basename f)))
3849 (rename-file f directory)))
3850 (delete-directory tmp-dir t))))
3852 (defun anything-ff-serial-rename (candidate)
3853 "Serial rename all marked files to `anything-ff-default-directory'.
3854 Rename only file of current directory, and symlink files coming from
3855 other directories.
3856 See `anything-ff-serial-rename-1'."
3857 (anything-ff-serial-rename-action 'rename))
3859 (defun anything-ff-serial-rename-by-symlink (candidate)
3860 "Serial rename all marked files to `anything-ff-default-directory'.
3861 Rename only file of current directory, and symlink files coming from
3862 other directories.
3863 See `anything-ff-serial-rename-1'."
3864 (anything-ff-serial-rename-action 'symlink))
3866 (defun anything-ff-serial-rename-by-copying (candidate)
3867 "Serial rename all marked files to `anything-ff-default-directory'.
3868 Rename only file of current directory, and copy files coming from
3869 other directories.
3870 See `anything-ff-serial-rename-1'."
3871 (anything-ff-serial-rename-action 'copy))
3873 (defun anything-c-quit-and-execute-action (action)
3874 "Quit current anything session and execute ACTION."
3875 (setq anything-saved-action action)
3876 (anything-exit-minibuffer))
3878 (defun anything-ff-toggle-auto-update (candidate)
3879 (setq anything-ff-auto-update-flag (not anything-ff-auto-update-flag))
3880 (message "[Auto expansion %s]"
3881 (if anything-ff-auto-update-flag "enabled" "disabled")))
3883 ;;;###autoload
3884 (defun anything-ff-run-toggle-auto-update ()
3885 (interactive)
3886 (anything-execute-persistent-action 'toggle-auto-update))
3888 ;;;###autoload
3889 (defun anything-ff-run-switch-to-history ()
3890 "Run Switch to history action from `anything-c-source-find-files'."
3891 (interactive)
3892 (anything-c-quit-and-execute-action 'anything-find-files-switch-to-hist))
3894 ;;;###autoload
3895 (defun anything-ff-run-grep ()
3896 "Run Grep action from `anything-c-source-find-files'."
3897 (interactive)
3898 (anything-c-quit-and-execute-action 'anything-find-files-grep))
3900 ;;;###autoload
3901 (defun anything-ff-run-pdfgrep ()
3902 "Run Pdfgrep action from `anything-c-source-find-files'."
3903 (interactive)
3904 (anything-c-quit-and-execute-action 'anything-ff-pdfgrep))
3906 ;;;###autoload
3907 (defun anything-ff-run-zgrep ()
3908 "Run Grep action from `anything-c-source-find-files'."
3909 (interactive)
3910 (anything-c-quit-and-execute-action 'anything-ff-zgrep))
3912 ;;;###autoload
3913 (defun anything-ff-run-copy-file ()
3914 "Run Copy file action from `anything-c-source-find-files'."
3915 (interactive)
3916 (anything-c-quit-and-execute-action 'anything-find-files-copy))
3918 ;;;###autoload
3919 (defun anything-ff-run-rename-file ()
3920 "Run Rename file action from `anything-c-source-find-files'."
3921 (interactive)
3922 (anything-c-quit-and-execute-action 'anything-find-files-rename))
3924 ;;;###autoload
3925 (defun anything-ff-run-byte-compile-file ()
3926 "Run Byte compile file action from `anything-c-source-find-files'."
3927 (interactive)
3928 (anything-c-quit-and-execute-action 'anything-find-files-byte-compile))
3930 ;;;###autoload
3931 (defun anything-ff-run-load-file ()
3932 "Run Load file action from `anything-c-source-find-files'."
3933 (interactive)
3934 (anything-c-quit-and-execute-action 'anything-find-files-load-files))
3936 ;;;###autoload
3937 (defun anything-ff-run-eshell-command-on-file ()
3938 "Run eshell command on file action from `anything-c-source-find-files'."
3939 (interactive)
3940 (anything-c-quit-and-execute-action 'anything-find-files-eshell-command-on-file))
3942 ;;;###autoload
3943 (defun anything-ff-run-ediff-file ()
3944 "Run Ediff file action from `anything-c-source-find-files'."
3945 (interactive)
3946 (anything-c-quit-and-execute-action 'anything-find-files-ediff-files))
3948 ;;;###autoload
3949 (defun anything-ff-run-ediff-merge-file ()
3950 "Run Ediff merge file action from `anything-c-source-find-files'."
3951 (interactive)
3952 (anything-c-quit-and-execute-action 'anything-find-files-ediff-merge-files))
3954 ;;;###autoload
3955 (defun anything-ff-run-symlink-file ()
3956 "Run Symlink file action from `anything-c-source-find-files'."
3957 (interactive)
3958 (anything-c-quit-and-execute-action 'anything-find-files-symlink))
3960 ;;;###autoload
3961 (defun anything-ff-run-delete-file ()
3962 "Run Delete file action from `anything-c-source-find-files'."
3963 (interactive)
3964 (anything-c-quit-and-execute-action 'anything-delete-marked-files))
3966 ;;;###autoload
3967 (defun anything-ff-run-complete-fn-at-point ()
3968 "Run complete file name action from `anything-c-source-find-files'."
3969 (interactive)
3970 (anything-c-quit-and-execute-action
3971 'anything-c-insert-file-name-completion-at-point))
3973 ;;;###autoload
3974 (defun anything-ff-run-switch-to-eshell ()
3975 "Run switch to eshell action from `anything-c-source-find-files'."
3976 (interactive)
3977 (anything-c-quit-and-execute-action 'anything-ff-switch-to-eshell))
3979 ;;;###autoload
3980 (defun anything-ff-run-switch-other-window ()
3981 "Run switch to other window action from `anything-c-source-find-files'."
3982 (interactive)
3983 (anything-c-quit-and-execute-action 'find-file-other-window))
3985 ;;;###autoload
3986 (defun anything-ff-run-switch-other-frame ()
3987 "Run switch to other frame action from `anything-c-source-find-files'."
3988 (interactive)
3989 (anything-c-quit-and-execute-action 'find-file-other-frame))
3991 ;;;###autoload
3992 (defun anything-ff-run-open-file-externally ()
3993 "Run open file externally command action from `anything-c-source-find-files'."
3994 (interactive)
3995 (anything-c-quit-and-execute-action 'anything-c-open-file-externally))
3997 (defun anything-ff-locate (candidate)
3998 "Locate action function for `anything-find-files'."
3999 (let ((input (concat (anything-c-basename
4000 (expand-file-name
4001 candidate
4002 anything-ff-default-directory))
4003 ;; The locate '-b' option doesn't exists
4004 ;; in everything.
4005 (unless (and (eq system-type 'windows-nt)
4006 (string-match "^es" anything-c-locate-command))
4007 " -b")))
4008 (anything-mp-highlight-delay 0.7))
4009 (anything-locate-1 anything-current-prefix-arg input)))
4011 ;;;###autoload
4012 (defun anything-ff-run-locate ()
4013 "Run locate action from `anything-c-source-find-files'."
4014 (interactive)
4015 (anything-c-quit-and-execute-action 'anything-ff-locate))
4017 ;;;###autoload
4018 (defun anything-ff-run-gnus-attach-files ()
4019 "Run gnus attach files command action from `anything-c-source-find-files'."
4020 (interactive)
4021 (anything-c-quit-and-execute-action 'anything-ff-gnus-attach-files))
4023 ;;;###autoload
4024 (defun anything-ff-run-etags ()
4025 "Run Etags command action from `anything-c-source-find-files'."
4026 (interactive)
4027 (anything-c-quit-and-execute-action 'anything-ff-etags-select))
4030 (defun anything-ff-print (candidate)
4031 "Print marked files.
4032 You have to set in order
4033 variables `lpr-command',`lpr-switches' and/or `printer-name'.
4035 e.g:
4036 \(setq lpr-command \"gtklp\"\)
4037 \(setq lpr-switches '(\"-P\")\)
4038 \(setq printer-name \"Epson-Stylus-Photo-R265\"\)
4040 Same as `dired-do-print' but for anything."
4041 (let* ((file-list (anything-marked-candidates))
4042 (len (length file-list))
4043 (printer-name (if anything-ff-printer-list
4044 (anything-comp-read
4045 "Printer: " anything-ff-printer-list)
4046 printer-name))
4047 (command (read-string
4048 (format "Print *%s File(s):\n%s with: "
4050 (mapconcat
4051 (lambda (f) (format "- %s\n" f))
4052 file-list ""))
4053 (when (and lpr-command
4054 (or lpr-switches
4055 printer-name))
4056 (mapconcat 'identity
4057 (cons lpr-command
4058 (append (if (stringp lpr-switches)
4059 (list lpr-switches)
4060 lpr-switches)
4061 (list printer-name)))
4062 " "))))
4063 (file-args (mapconcat #'(lambda (x)
4064 (format "'%s'" x))
4065 file-list " "))
4066 (cmd-line (concat command " " file-args)))
4067 (if command
4068 (start-process-shell-command "anything-print" nil cmd-line)
4069 (error "Error: Please verify your printer settings in Emacs."))))
4071 ;;;###autoload
4072 (defun anything-ff-run-print-file ()
4073 "Run Print file action from `anything-c-source-find-files'."
4074 (interactive)
4075 (anything-c-quit-and-execute-action 'anything-ff-print))
4077 (defun anything-ff-checksum (file)
4078 "Calculate the checksum of FILE.
4079 Provide completion on different algorithms to use on Emacs24.
4080 On Emacs23 only 'sha1' is available.
4081 The checksum is copied to kill-ring."
4082 (let ((algo-list (and (fboundp 'secure-hash)
4083 '(md5 sha1 sha224 sha256 sha384 sha512))))
4084 (kill-new
4085 (if algo-list
4086 (secure-hash (intern
4087 (anything-comp-read
4088 "Algorithm: " algo-list))
4089 file)
4090 (sha1 (with-temp-buffer
4091 (insert-file-contents file)
4092 (buffer-string)))))
4093 (message "Checksum copied to kill-ring.")))
4095 (defun anything-ff-toggle-basename (candidate)
4096 (setq anything-ff-transformer-show-only-basename
4097 (not anything-ff-transformer-show-only-basename))
4098 (save-excursion
4099 (anything-force-update)))
4101 (defun anything-ff-run-toggle-basename ()
4102 (interactive)
4103 (anything-execute-persistent-action 'toggle-basename))
4105 (defun* anything-reduce-file-name (fname level &key unix-close expand)
4106 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
4107 If LEVEL is positive reduce from end else from beginning.
4108 If UNIX-CLOSE is non--nil close filename with /.
4109 If EXPAND is non--nil expand-file-name."
4110 (let* ((exp-fname (expand-file-name fname))
4111 (fname-list (split-string (if (or (string= fname "~/") expand)
4112 exp-fname fname) "/" t))
4113 (len (length fname-list))
4114 (pop-list (if (< level 0)
4115 (subseq fname-list (* level -1))
4116 (subseq fname-list 0 (- len level))))
4117 (result (mapconcat 'identity pop-list "/"))
4118 (empty (string= result "")))
4119 (when unix-close (setq result (concat result "/")))
4120 (if (string-match "^~" result)
4121 (if (string= result "~/") "~/" result)
4122 (if (< level 0)
4123 (if empty "../" (concat "../" result))
4124 (cond ((eq system-type 'windows-nt)
4125 (if empty "c:/" result))
4126 (empty "/")
4128 (concat "/" result)))))))
4130 (defun anything-file-completion-source-p ()
4131 "Test if current source is a dired or find-files source."
4132 (let ((ff-sources '("Find Files" "Copy Files"
4133 "Read File Name History"
4134 "Rename Files" "Symlink Files"
4135 "Hardlink Files" "Write File"
4136 "Insert File" "Read file name"))
4137 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
4138 (loop for i in ff-sources thereis (string= cur-source i))))
4140 (defun anything-find-files-down-one-level (arg)
4141 "Go down one level like unix command `cd ..'.
4142 If prefix numeric arg is given go ARG level down."
4143 (interactive "p")
4144 (with-anything-window
4145 (setq anything-follow-mode nil))
4146 ;; When going to precedent level we want to be at the line
4147 ;; corresponding to actual directory, so store this info
4148 ;; in `anything-ff-last-expanded'.
4149 (if (and (not (file-directory-p anything-pattern))
4150 (file-exists-p anything-pattern))
4151 (setq anything-ff-last-expanded anything-pattern)
4152 (setq anything-ff-last-expanded anything-ff-default-directory))
4153 (when (anything-file-completion-source-p)
4154 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
4155 :unix-close t :expand t)))
4156 (anything-set-pattern new-pattern))))
4158 (defun anything-ff-retrieve-last-expanded ()
4159 "Move overlay to last visited directory `anything-ff-last-expanded'.
4160 This happen after using `anything-find-files-down-one-level',
4161 or hitting C-z on \"..\"."
4162 (when (and anything-ff-last-expanded
4163 (anything-file-completion-source-p))
4164 (let ((dirname (if anything-ff-transformer-show-only-basename
4165 (anything-c-basename
4166 (directory-file-name anything-ff-last-expanded))
4167 (directory-file-name anything-ff-last-expanded))))
4168 (with-anything-window
4169 (when (or (re-search-forward (concat dirname "$") nil t)
4170 (re-search-forward
4171 (concat anything-ff-last-expanded "$") nil t))
4172 (forward-line 0)
4173 (anything-mark-current-line)))
4174 (setq anything-ff-last-expanded nil))))
4175 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
4177 ;; Auto-update - anything-find-files auto expansion of directories.
4179 (defun anything-ff-update-when-only-one-matched ()
4180 "Expand to directory when sole completion.
4181 When only one candidate is remaining and it is a directory,
4182 expand to this directory."
4183 (let ((history-p (string= (assoc-default
4184 'name (anything-get-current-source))
4185 "Read File Name History"))
4186 (completed-p (string= (file-name-as-directory anything-pattern)
4187 anything-ff-default-directory)))
4188 (when (and anything-ff-auto-update-flag
4189 (or (and (anything-file-completion-source-p)
4190 (<= (anything-approximate-candidate-number) 2)
4191 (>= (length (anything-c-basename anything-pattern)) 2))
4192 completed-p)
4193 (not history-p))
4194 (with-anything-window
4195 (and (not completed-p) (anything-next-line))
4196 (let ((cur-cand (anything-get-selection)))
4197 (when (file-directory-p cur-cand)
4198 (if (and (not (string-match "^.*[.]\\{1,2\\}$" cur-cand)) ; [1]
4199 ;; Maybe we are here because completed-p is true
4200 ;; So check this again to be sure.
4201 ;; (this happen only on windows dirs)
4202 (<= (anything-approximate-candidate-number) 2)) ; [2]
4203 ;; If after going to next line the candidate is not "." or ".." [1]
4204 ;; and only one candidate is remaining [2],
4205 ;; assume candidate is a new directory to expand, and do it.
4206 (anything-set-pattern (file-name-as-directory cur-cand))
4207 ;; The candidate is one of "." or ".." (it should be "..").
4208 ;; that mean we have entered the last letter of the directory name
4209 ;; in prompt, so expansion is already done, just add the "/" at end
4210 ;; of name unless anything-pattern ends with "."
4211 (unless (string-match "^.*[.]\\{1\\}$" anything-pattern)
4212 (anything-set-pattern (file-name-as-directory anything-pattern))))
4213 (anything-check-minibuffer-input-1)))))))
4214 (add-hook 'anything-after-update-hook 'anything-ff-update-when-only-one-matched)
4216 ;; Allow expanding to home directory or root
4217 ;; when entering respectively "~/" or "//" at end of pattern.
4218 ;; e.g /home/thierry/labo/anything-config-qp/~/
4219 ;; will expand to "~/"
4220 ;; and /home/thierry/labo/anything-config-qp//
4221 ;; will expand to "/"
4222 (defun anything-ff-auto-expand-to-home-or-root ()
4223 "Goto home or root directory when adding ~/ or / at end of pattern.
4224 This happen only in function using sources that are
4225 `anything-file-completion-source-p' compliant."
4226 (when (and (anything-file-completion-source-p)
4227 (string-match ".*\\(/~/\\|/\\{2\\}\\)$" anything-pattern))
4228 (let ((match (match-string 1 anything-pattern)))
4229 (cond ((string= match "//")
4230 (if (eq system-type 'windows-nt)
4231 (setq anything-pattern "c:/")
4232 (setq anything-pattern "/")))
4233 ((string= match "/~/")
4234 (if (eq system-type 'windows-nt)
4235 (setq anything-pattern (file-name-as-directory (getenv "HOME")))
4236 (setq anything-pattern "~/")))))
4237 (setq anything-ff-default-directory anything-pattern)
4238 ;; For some reasons, i must use here with-current-buffer => mini buffer
4239 ;; and not `anything-set-pattern' that use with-selected-window => mini win.
4240 (with-current-buffer (window-buffer (minibuffer-window))
4241 (delete-minibuffer-contents)
4242 (insert anything-pattern))))
4244 (add-hook 'anything-after-update-hook 'anything-ff-auto-expand-to-home-or-root)
4246 (defun anything-c-point-file-in-dired (file)
4247 "Put point on filename FILE in dired buffer."
4248 (dired (file-name-directory file))
4249 (dired-goto-file file))
4251 (defun anything-create-tramp-name (fname)
4252 "Build filename for `anything-pattern' like /su:: or /sudo::."
4253 (apply #'tramp-make-tramp-file-name
4254 (loop with v = (tramp-dissect-file-name fname)
4255 for i across v collect i)))
4257 (defun anything-ff-set-pattern (pattern)
4258 "Handle tramp filenames in `anything-pattern'."
4259 (let ((methods (mapcar 'car tramp-methods))
4260 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
4261 cur-method tramp-name)
4262 (cond ((string= pattern "") "")
4263 ((string-match ".*\\(~//\\|//\\)$" pattern)
4264 (if (eq system-type 'windows-nt) "c:/" "/"))
4265 ((string-match "^~\\|.*/~/$" pattern)
4266 (let* ((home (getenv "HOME"))
4267 (replace (if (eq system-type 'windows-nt)
4268 (replace-regexp-in-string
4269 "\\\\" "/" home)
4270 home)))
4271 (replace-match replace nil t pattern)))
4272 ;; Match "/method:maybe_hostname:"
4273 ((and (string-match reg pattern)
4274 (setq cur-method (match-string 1 pattern))
4275 (member cur-method methods))
4276 (setq tramp-name (anything-create-tramp-name
4277 (match-string 0 pattern)))
4278 (replace-match tramp-name nil t pattern))
4279 ;; Match "/hostname:"
4280 ((and (string-match tramp-file-name-regexp pattern)
4281 (setq cur-method (match-string 1 pattern))
4282 (and cur-method (not (member cur-method methods))))
4283 (setq tramp-name (anything-create-tramp-name
4284 (match-string 0 pattern)))
4285 (replace-match tramp-name nil t pattern))
4286 ;; Match "/method:" in this case don't try to connect.
4287 ((and (not (string-match reg pattern))
4288 (string-match tramp-file-name-regexp pattern)
4289 (member (match-string 1 pattern) methods))
4290 "Invalid tramp file name") ; Write in anything-buffer.
4291 ;; PATTERN is a directory, end it with "/".
4292 ;; This will make PATTERN not ending yet with "/"
4293 ;; candidate for `anything-ff-default-directory',
4294 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
4295 ;; when descending level.
4296 ((file-directory-p pattern)
4297 (file-name-as-directory pattern))
4298 ;; Return PATTERN unchanged.
4299 (t pattern))))
4302 (defun anything-find-files-get-candidates ()
4303 "Create candidate list for `anything-c-source-find-files'."
4304 (let* ((path (anything-ff-set-pattern anything-pattern))
4305 (path-name-dir (if (file-directory-p path)
4306 (file-name-as-directory path)
4307 (file-name-directory path)))
4308 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
4309 (set-text-properties 0 (length path) nil path)
4310 (setq anything-pattern (anything-ff-transform-fname-for-completion path))
4311 (setq anything-ff-default-directory
4312 (if (string= anything-pattern "")
4313 (if (eq system-type 'windows-nt) "c:/" "/")
4314 (unless (string-match ffap-url-regexp path)
4315 path-name-dir)))
4316 (cond ((or (string= path "Invalid tramp file name")
4317 (file-regular-p path)
4318 (and (not (file-exists-p path)) (string-match "/$" path))
4319 (and ffap-url-regexp (string-match ffap-url-regexp path)))
4320 (list path))
4321 ((string= path "") (directory-files "/" t))
4322 ((and (file-directory-p path) (not (file-readable-p path)))
4323 (list (format "Opening directory: access denied, `%s'" path)))
4324 ((file-directory-p path) (directory-files path t))
4326 (append (list path) (directory-files path-name-dir t))))))
4328 (defun anything-ff-transform-fname-for-completion (fname)
4329 "Return FNAME with it's basename modified as a regexp.
4330 e.g foo => f.*o.*o .
4331 If basename contain one or more space or FNAME is a valid directory name
4332 return FNAME unchanged."
4333 (let ((bn (anything-c-basename fname)))
4334 (if (or (not anything-ff-smart-completion)
4335 (string-match "\\s-" bn)
4336 (string-match "/$" fname) ; Allow mkdir.
4337 (file-directory-p fname))
4338 fname ; Fall back to match-plugin.
4339 (setq bn (if (> (length bn) 2) ; Normal completion on first 2 char.
4340 (mapconcat 'identity (split-string bn "" t) ".*") bn))
4341 (concat (file-name-directory fname) bn))))
4343 (defun anything-ff-save-history ()
4344 "Store the last value of `anything-ff-default-directory' \
4345 in `anything-ff-history'."
4346 (when (and anything-ff-default-directory
4347 (anything-file-completion-source-p))
4348 (push anything-ff-default-directory anything-ff-history)))
4349 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
4351 (defun anything-ff-valid-symlink-p (file)
4352 (file-exists-p (file-truename file)))
4354 (defun anything-ff-properties (candidate)
4355 "Show file properties of CANDIDATE in a tooltip or message."
4356 (let ((type (anything-ff-attributes candidate :type t))
4357 (dired-line (anything-ff-attributes candidate :dired t :human-size t)))
4358 (if (window-system)
4359 (tooltip-show
4360 (concat
4361 (anything-c-basename candidate) ": \n"
4362 "Type: " type "\n"
4363 (when (string= type "symlink")
4364 (format "True name: '%s'\n"
4365 (cond ((string-match "^\.#" (anything-c-basename candidate))
4366 "Autosave symlink")
4367 ((anything-ff-valid-symlink-p candidate)
4368 (file-truename candidate))
4369 (t "Invalid Symlink"))))
4370 dired-line))
4371 (message dired-line) (sit-for 5))))
4373 ;;;###autoload
4374 (defun anything-ff-properties-persistent ()
4375 "Show properties without quitting anything."
4376 (interactive)
4377 (anything-execute-persistent-action 'properties-action))
4379 (defun anything-ff-kill-buffer-fname (candidate)
4380 (let* ((buf (get-file-buffer candidate))
4381 (buf-name (buffer-name buf)))
4382 (if buf
4383 (progn
4384 (kill-buffer buf) (message "Buffer `%s' killed" buf))
4385 (message "No buffer to kill"))))
4387 (defun anything-ff-kill-or-find-buffer-fname (candidate)
4388 "Find file CANDIDATE or kill it's buffer if it is visible.
4389 Never kill `anything-current-buffer'.
4390 Never kill buffer modified.
4391 This is called normally on third hit of \
4392 \\<anything-map>\\[anything-execute-persistent-action]
4393 in `anything-find-files-persistent-action'."
4394 (let* ((buf (get-file-buffer candidate))
4395 (buf-name (buffer-name buf)))
4396 (if (and buf (get-buffer-window buf)
4397 (not (eq buf (get-buffer anything-current-buffer)))
4398 (not (buffer-modified-p buf)))
4399 (progn
4400 (kill-buffer buf) (message "Buffer `%s' killed" buf-name))
4401 (find-file candidate))))
4403 ;;;###autoload
4404 (defun anything-ff-run-kill-buffer-persistent ()
4405 "Execute `anything-ff-kill-buffer-fname' whitout quitting."
4406 (interactive)
4407 (anything-execute-persistent-action 'kill-buffer-fname))
4409 (defun anything-ff-human-size (size)
4410 "Return a string showing SIZE of a file in human readable form.
4411 SIZE can be an integer or a float depending it's value.
4412 `file-attributes' will take care of that to avoid overflow error.
4413 KBSIZE if a floating point number, default value is 1024.0."
4414 (let ((M (cons "M" (/ size (expt anything-ff-default-kbsize 2))))
4415 (G (cons "G" (/ size (expt anything-ff-default-kbsize 3))))
4416 (K (cons "K" (/ size anything-ff-default-kbsize)))
4417 (B (cons "B" size)))
4418 (loop with result = B
4419 for (a . b) in
4420 (loop for (x . y) in (list M G K B)
4421 unless (< y 1) collect (cons x y))
4422 when (< b (cdr result)) do (setq result (cons a b))
4423 finally return (if (string= (car result) "B")
4424 (format "%s" size)
4425 (format "%.1f%s" (cdr result) (car result))))))
4427 (defun* anything-ff-attributes
4428 (file &key type links uid gid access-time modif-time
4429 status size mode gid-change inode device-num dired human-size)
4430 "Easy interface for `file-attributes'."
4431 (let ((all (destructuring-bind
4432 (type links uid gid access-time modif-time
4433 status size mode gid-change inode device-num)
4434 (file-attributes file 'string)
4435 (list :type type
4436 :links links
4437 :uid uid
4438 :gid gid
4439 :access-time access-time
4440 :modif-time modif-time
4441 :status status
4442 :size size
4443 :mode mode
4444 :gid-change gid-change
4445 :inode inode
4446 :device-num device-num))))
4447 (cond (type
4448 (let ((result (getf all :type)))
4449 (cond ((stringp result)
4450 "symlink")
4451 (result "directory")
4452 (t "file"))))
4453 (links (getf all :links))
4454 (uid (getf all :uid))
4455 (gid (getf all :gid))
4456 (access-time
4457 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
4458 (modif-time
4459 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
4460 (status
4461 (format-time-string "%Y-%m-%d %R" (getf all :status)))
4462 (size (if human-size (anything-ff-human-size (getf all :size))
4463 (getf all :size)))
4464 (mode (getf all :mode))
4465 (gid-change (getf all :gid-change))
4466 (inode (getf all :inode))
4467 (device-num (getf all :device-num))
4468 (dired
4469 (concat
4470 (getf all :mode) " "
4471 (number-to-string (getf all :links)) " "
4472 (getf all :uid) ":"
4473 (getf all :gid) " "
4474 (if human-size (anything-ff-human-size (getf all :size))
4475 (int-to-string (getf all :size))) " "
4476 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
4477 (t all))))
4479 (defun anything-ff-prefix-filename (fname &optional file-or-symlinkp new-file)
4480 "Return filename FNAME maybe prefixed with [?] or [@].
4481 If FILE-OR-SYMLINKP is non--nil this mean we assume FNAME is an
4482 existing filename or valid symlink and there is no need to test it.
4483 NEW-FILE when non--nil mean FNAME is a non existing file and
4484 return FNAME prefixed with [?]."
4485 (let* ((prefix-new (propertize
4486 " " 'display
4487 (propertize "[?]" 'face 'anything-ff-prefix)))
4488 (prefix-url (propertize
4489 " " 'display
4490 (propertize "[@]" 'face 'anything-ff-prefix))))
4491 (cond ((or file-or-symlinkp (file-exists-p fname)) fname)
4492 ((string-match ffap-url-regexp fname)
4493 (concat prefix-url " " fname))
4494 ((or new-file (not (file-exists-p fname)))
4495 (concat prefix-new " " fname)))))
4497 (defun anything-c-find-files-transformer (files sources)
4498 "Transformer for `anything-c-source-find-files'.
4499 Tramp files are not highlighted unless `anything-ff-tramp-not-fancy'
4500 is non--nil."
4501 (if (and (string-match tramp-file-name-regexp anything-pattern)
4502 anything-ff-tramp-not-fancy)
4503 (if anything-ff-transformer-show-only-basename
4504 (loop for i in files collect
4505 (if (string-match "[.]\\{1,2\\}$" i)
4506 i (cons (anything-c-basename i) i)))
4507 files)
4508 (anything-ff-highlight-files files sources)))
4510 (defun anything-ff-highlight-files (files sources)
4511 "Candidate transformer for `anything-c-source-find-files' without icons."
4512 (loop for i in files
4513 for disp = (if (and anything-ff-transformer-show-only-basename
4514 (not (string-match "[.]\\{1,2\\}$" i))
4515 (not (string-match ffap-url-regexp i)))
4516 (anything-c-basename i) i)
4517 collect
4518 (cond ((and (stringp (car (file-attributes i)))
4519 (not (anything-ff-valid-symlink-p i))
4520 (not (string-match "^\.#" (anything-c-basename i))))
4521 (cons (anything-ff-prefix-filename
4522 (propertize disp 'face 'anything-ff-invalid-symlink) t)
4524 ((stringp (car (file-attributes i)))
4525 (cons (anything-ff-prefix-filename
4526 (propertize disp 'face 'anything-ff-symlink) t)
4528 ((eq t (car (file-attributes i)))
4529 (cons (anything-ff-prefix-filename
4530 (propertize disp 'face 'anything-ff-directory) t)
4532 ((file-executable-p i)
4533 (cons (anything-ff-prefix-filename
4534 (propertize disp 'face 'anything-ff-executable) t)
4536 ((file-exists-p i)
4537 (cons (anything-ff-prefix-filename
4538 (propertize disp 'face 'anything-ff-file) t)
4541 (cons (anything-ff-prefix-filename
4542 (propertize disp 'face 'anything-ff-file) nil 'new-file)
4543 i)))))
4545 (defun anything-find-files-action-transformer (actions candidate)
4546 "Action transformer for `anything-c-source-find-files'."
4547 (cond ((with-anything-current-buffer
4548 (eq major-mode 'message-mode))
4549 (append (subseq actions 0 4)
4550 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
4551 (subseq actions 4)))
4552 ((string-match (image-file-name-regexp) candidate)
4553 (append (subseq actions 0 4)
4554 '(("Rotate image right `M-r'" . anything-ff-rotate-image-right)
4555 ("Rotate image left `M-l'" . anything-ff-rotate-image-left))
4556 (subseq actions 4)))
4557 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
4558 (car it) candidate))
4559 (append (subseq actions 0 4)
4560 '(("Byte compile lisp file(s) `M-B, C-u to load'"
4561 . anything-find-files-byte-compile)
4562 ("Load File(s) `M-L'" . anything-find-files-load-files))
4563 (subseq actions 4)))
4564 ((and (string-match "\.html?$" candidate)
4565 (file-exists-p candidate))
4566 (append (subseq actions 0 4)
4567 '(("Browse url file" . browse-url-of-file))
4568 (subseq actions 5)))
4569 ((or (string= (file-name-extension candidate) "pdf")
4570 (string= (file-name-extension candidate) "PDF"))
4571 (append (subseq actions 0 4)
4572 '(("Pdfgrep File(s)" . anything-ff-pdfgrep))
4573 (subseq actions 5)))
4574 (t actions)))
4576 (defun anything-ff-gnus-attach-files (candidate)
4577 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
4578 (let ((flist (anything-marked-candidates)))
4579 (gnus-dired-attach flist)))
4581 (defun anything-ff-rotate-current-image-1 (file &optional num-arg)
4582 "Rotate current image at NUM-ARG degrees.
4583 This is a destructive operation on FILE made by external tool mogrify."
4584 (declare (special image-dired-display-image-buffer))
4585 (setq file (file-truename file)) ; For symlinked images.
4586 ;; When FILE is not an image-file, do nothing.
4587 (when (string-match (image-file-name-regexp) file)
4588 (if (executable-find "mogrify")
4589 (progn
4590 (shell-command (format "mogrify -rotate %s %s"
4591 (or num-arg 90)
4592 (shell-quote-argument file)))
4593 (when (buffer-live-p image-dired-display-image-buffer)
4594 (kill-buffer image-dired-display-image-buffer))
4595 (image-dired-display-image file)
4596 (message nil)
4597 (display-buffer (get-buffer image-dired-display-image-buffer)))
4598 (error "mogrify not found"))))
4600 (defun anything-ff-rotate-image-left (candidate)
4601 "Rotate image file CANDIDATE left.
4602 This affect directly file CANDIDATE."
4603 (anything-ff-rotate-current-image-1 candidate -90))
4605 (defun anything-ff-rotate-image-right (candidate)
4606 "Rotate image file CANDIDATE right.
4607 This affect directly file CANDIDATE."
4608 (anything-ff-rotate-current-image-1 candidate))
4610 (defun anything-ff-rotate-left-persistent ()
4611 "Rotate image left without quitting anything."
4612 (interactive)
4613 (anything-execute-persistent-action 'image-action1))
4615 (defun anything-ff-rotate-right-persistent ()
4616 "Rotate image right without quitting anything."
4617 (interactive)
4618 (anything-execute-persistent-action 'image-action2))
4620 (defun anything-ff-exif-data (candidate)
4621 "Extract exif data from file CANDIDATE using `anything-ff-exif-data-program'."
4622 (if (and anything-ff-exif-data-program
4623 (executable-find anything-ff-exif-data-program))
4624 (shell-command-to-string (format "%s %s %s"
4625 anything-ff-exif-data-program
4626 anything-ff-exif-data-program-args
4627 candidate))
4628 (format "No program %s found to extract exif"
4629 anything-ff-exif-data-program)))
4631 (defun anything-find-files-persistent-action (candidate)
4632 "Open subtree CANDIDATE without quitting anything.
4633 If CANDIDATE is not a directory expand CANDIDATE filename.
4634 If CANDIDATE is alone, open file CANDIDATE filename.
4635 That's mean:
4636 First hit on C-z expand CANDIDATE second hit open file.
4637 If a prefix arg is given or `anything-follow-mode' is on open file."
4638 (let ((follow (buffer-local-value
4639 'anything-follow-mode
4640 (get-buffer-create anything-buffer)))
4641 (new-pattern (anything-get-selection))
4642 (num-lines-buf (with-current-buffer anything-buffer
4643 (count-lines (point-min) (point-max)))))
4644 (flet ((insert-in-minibuffer (fname)
4645 (with-selected-window (minibuffer-window)
4646 (unless follow
4647 (delete-minibuffer-contents)
4648 (set-text-properties 0 (length fname) nil fname)
4649 (insert fname)))))
4650 (cond (;; A symlink directory, expand it's truename.
4651 (and (file-directory-p candidate) (file-symlink-p candidate))
4652 (insert-in-minibuffer (file-name-as-directory
4653 (file-truename
4654 (expand-file-name candidate)))))
4655 ;; A directory, open it.
4656 ((file-directory-p candidate)
4657 (when (string= (anything-c-basename candidate) "..")
4658 (setq anything-ff-last-expanded anything-ff-default-directory))
4659 (insert-in-minibuffer (file-name-as-directory
4660 (expand-file-name candidate))))
4661 ;; A symlink file, expand to it's true name. (first hit)
4662 ((and (file-symlink-p candidate) (not current-prefix-arg) (not follow))
4663 (insert-in-minibuffer (file-truename candidate)))
4664 ;; A regular file, expand it, (first hit)
4665 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
4666 (insert-in-minibuffer new-pattern))
4667 ;; An image file and it is the second hit on C-z,
4668 ;; show the file in `image-dired'.
4669 ((string-match (image-file-name-regexp) candidate)
4670 (when (buffer-live-p image-dired-display-image-buffer)
4671 (kill-buffer image-dired-display-image-buffer))
4672 (image-dired-display-image candidate)
4673 (message nil)
4674 (anything-c-switch-to-buffer image-dired-display-image-buffer)
4675 (with-current-buffer image-dired-display-image-buffer
4676 (let ((exif-data (anything-ff-exif-data candidate)))
4677 (image-dired-update-property 'help-echo exif-data))))
4678 ;; Allow browsing archive on avfs fs.
4679 ;; Assume volume is already mounted with mountavfs.
4680 ((and anything-ff-avfs-directory
4681 (string-match
4682 (regexp-quote (expand-file-name anything-ff-avfs-directory))
4683 (file-name-directory candidate))
4684 (anything-ff-file-compressed-p candidate))
4685 (insert-in-minibuffer (concat candidate "#")))
4686 ;; On second hit we open file.
4687 ;; On Third hit we kill it's buffer maybe.
4689 (anything-ff-kill-or-find-buffer-fname candidate))))))
4691 (defun anything-ff-file-compressed-p (candidate)
4692 "Whether CANDIDATE is a compressed file or not."
4693 (member (file-name-extension candidate)
4694 anything-ff-file-compressed-list))
4696 (defun anything-c-insert-file-name-completion-at-point (candidate)
4697 "Insert file name completion at point."
4698 (with-anything-current-buffer
4699 (if buffer-read-only
4700 (error "Error: Buffer `%s' is read-only" (buffer-name))
4701 (let* ((end (point))
4702 (guess (substring-no-properties (thing-at-point 'filename)))
4703 (beg (- (point) (length guess)))
4704 (full-path-p (or (string-match-p (concat "^" (getenv "HOME")) guess)
4705 (string-match-p "^[^\~]" guess))))
4706 (set-text-properties 0 (length candidate) nil candidate)
4707 (if (and guess (not (string= guess ""))
4708 (string-match-p "^~\\|/.*" guess))
4709 (progn
4710 (delete-region beg end)
4711 (insert (if full-path-p
4712 (expand-file-name candidate)
4713 (abbreviate-file-name candidate))))
4714 (error "Aborting completion: No valid file name at point"))))))
4716 (defun* anything-find-files-history (&key (comp-read t))
4717 "The `anything-find-files' history.
4718 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
4719 in an `anything-comp-read'."
4720 (let ((history (when anything-ff-history
4721 (loop with dup for i in anything-ff-history
4722 ;; Remove duplicate and not existing files.
4723 ;; Keep remote files.
4724 unless (or (member i dup)
4725 (and (not (file-remote-p i))
4726 (not (file-exists-p i))))
4727 collect i into dup
4728 finally return dup)))) ; Remove dups.
4729 (when history
4730 (setq anything-ff-history
4731 (if (>= (length history) anything-ff-history-max-length)
4732 (subseq history 0 anything-ff-history-max-length)
4733 history))
4734 (if comp-read
4735 (anything-comp-read
4736 "Switch to Directory: "
4737 anything-ff-history
4738 :name "Anything Find Files History"
4739 :must-match t)
4740 anything-ff-history))))
4742 (defun anything-find-files-1 (fname &optional preselect)
4743 "Find FNAME with `anything' completion.
4744 Like `find-file' but with `anything' support.
4745 Use it for non--interactive calls of `anything-find-files'."
4746 (when (get-buffer anything-action-buffer)
4747 (kill-buffer anything-action-buffer))
4748 (let ((anything-mp-highlight-delay nil)
4749 ;; Be sure we don't erase the precedent minibuffer if some.
4750 (anything-ff-auto-update-initial-value
4751 (not (minibuffer-window-active-p (minibuffer-window))))
4752 anything-samewindow)
4753 (anything :sources 'anything-c-source-find-files
4754 :input fname
4755 :preselect preselect
4756 :keymap anything-find-files-map
4757 :prompt "Find Files or Url: "
4758 :buffer "*Anything Find Files*")))
4761 (defun anything-find-files-initial-input (&optional input)
4762 "Return INPUT if present, otherwise try to guess it."
4763 (or (and input (expand-file-name input))
4764 (anything-find-files-input
4765 (ffap-guesser)
4766 (thing-at-point 'filename))))
4768 (defun anything-find-files-input (fap tap)
4769 "Default input of `anything-find-files'."
4770 (let* ((def-dir (anything-c-current-directory))
4771 (lib (anything-find-library-at-point))
4772 (url (anything-ff-find-url-at-point))
4773 (file-p (and fap (not (string= fap ""))
4774 (file-exists-p fap)
4775 tap (not (string= tap ""))
4776 (file-exists-p
4777 (file-name-directory (expand-file-name tap def-dir))))))
4778 (cond (lib) ; e.g we are inside a require sexp.
4779 (url) ; String at point is an hyperlink.
4780 (file-p (expand-file-name tap def-dir))
4781 (t (and (not (string= fap "")) fap)))))
4783 (defun anything-c-current-directory ()
4784 "Return current-directory name at point.
4785 Useful in dired buffers when there is inserted subdirs."
4786 (if (eq major-mode 'dired-mode)
4787 (dired-current-directory)
4788 default-directory))
4790 (defun anything-ff-find-url-at-point ()
4791 "Try to find link to an url in text-property at point."
4792 (let* ((he (get-text-property (point) 'help-echo))
4793 (ov (overlays-at (point)))
4794 (ov-he (and ov (overlay-get
4795 (car (overlays-at (point))) 'help-echo)))
4796 (w3m-l (get-text-property (point) 'w3m-href-anchor))
4797 (nt-prop (get-text-property (point) 'nt-link)))
4798 ;; Org link.
4799 (when (and (stringp he) (string-match "^LINK: " he))
4800 (setq he (replace-match "" t t he)))
4801 (loop for i in (list he ov-he w3m-l nt-prop)
4802 thereis (and (stringp i) (string-match ffap-url-regexp i) i))))
4804 (defun anything-find-library-at-point ()
4805 "Try to find library path at point.
4806 Find inside `require' and `declare-function' sexp."
4807 (require 'find-func)
4808 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
4809 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
4810 (sexp (and beg-sexp end-sexp
4811 (buffer-substring-no-properties
4812 (1+ beg-sexp) (1- end-sexp)))))
4813 (ignore-errors
4814 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
4815 (find-library-name
4816 (replace-regexp-in-string
4817 "'\\|\)\\|\(" ""
4818 ;; If require use third arg, ignore it,
4819 ;; always use library path found in `load-path'.
4820 (second (split-string (match-string 0 sexp))))))
4821 ((and sexp (string-match-p "^declare-function" sexp))
4822 (find-library-name
4823 (replace-regexp-in-string
4824 "\"\\|ext:" ""
4825 (third (split-string sexp)))))
4826 (t nil)))))
4828 ;;; Anything completion for `write-file'.==> C-x C-w
4829 (defvar anything-c-source-write-file
4830 `((name . "Write File")
4831 (header-name . (lambda (name)
4832 (concat name anything-c-find-files-doc-header)))
4833 ;; It is needed for filenames with capital letters
4834 (disable-shortcuts)
4835 (candidates . anything-find-files-get-candidates)
4836 (filtered-candidate-transformer anything-c-find-files-transformer)
4837 (persistent-action . anything-find-files-persistent-action)
4838 (persistent-help . "Expand Candidate")
4839 (volatile)
4840 (action .
4841 (("Write File" . (lambda (candidate)
4842 (write-file candidate 'confirm)))))))
4844 ;;; Anything completion for `insert-file'.==> C-x i
4845 (defvar anything-c-source-insert-file
4846 `((name . "Insert File")
4847 (header-name . (lambda (name)
4848 (concat name anything-c-find-files-doc-header)))
4849 ;; It is needed for filenames with capital letters
4850 (disable-shortcuts)
4851 (candidates . anything-find-files-get-candidates)
4852 (filtered-candidate-transformer anything-c-find-files-transformer)
4853 (persistent-action . anything-find-files-persistent-action)
4854 (persistent-help . "Expand Candidate")
4855 (volatile)
4856 (action .
4857 (("Insert File" . (lambda (candidate)
4858 (when (y-or-n-p (format "Really insert %s in %s "
4859 candidate anything-current-buffer))
4860 (insert-file-contents candidate))))))))
4862 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
4863 (defvar anything-c-source-copy-files
4864 `((name . "Copy Files")
4865 (header-name . (lambda (name)
4866 (concat name anything-c-find-files-doc-header)))
4867 ;; It is needed for filenames with capital letters
4868 (disable-shortcuts)
4869 (candidates . anything-find-files-get-candidates)
4870 (filtered-candidate-transformer anything-c-find-files-transformer)
4871 (persistent-action . anything-find-files-persistent-action)
4872 (persistent-help . "Expand Candidate")
4873 (volatile)
4874 (action .
4875 (("Copy File"
4876 . (lambda (candidate)
4877 (anything-dired-action candidate :action 'copy)))
4878 ("Copy and Follow"
4879 . (lambda (candidate)
4880 (anything-dired-action candidate :action 'copy :follow t)))))))
4883 (defvar anything-c-source-rename-files
4884 `((name . "Rename Files")
4885 (header-name . (lambda (name)
4886 (concat name anything-c-find-files-doc-header)))
4887 ;; It is needed for filenames with capital letters
4888 (disable-shortcuts)
4889 (candidates . anything-find-files-get-candidates)
4890 (filtered-candidate-transformer anything-c-find-files-transformer)
4891 (persistent-action . anything-find-files-persistent-action)
4892 (persistent-help . "Expand Candidate")
4893 (volatile)
4894 (action .
4895 (("Rename File"
4896 . (lambda (candidate)
4897 (anything-dired-action candidate :action 'rename)))
4898 ("Rename and Follow"
4899 . (lambda (candidate)
4900 (anything-dired-action candidate :action 'rename :follow t)))))))
4902 (defvar anything-c-source-symlink-files
4903 `((name . "Symlink Files")
4904 (header-name . (lambda (name)
4905 (concat name anything-c-find-files-doc-header)))
4906 ;; It is needed for filenames with capital letters
4907 (disable-shortcuts)
4908 (candidates . anything-find-files-get-candidates)
4909 (filtered-candidate-transformer anything-c-find-files-transformer)
4910 (persistent-action . anything-find-files-persistent-action)
4911 (persistent-help . "Expand Candidate")
4912 (volatile)
4913 (action
4914 . (("Symlink File"
4915 . (lambda (candidate)
4916 (anything-dired-action candidate :action 'symlink)))
4917 ("RelSymlink File"
4918 . (lambda (candidate)
4919 (anything-dired-action candidate :action 'relsymlink)))))))
4922 (defvar anything-c-source-hardlink-files
4923 `((name . "Hardlink Files")
4924 (header-name . (lambda (name)
4925 (concat name anything-c-find-files-doc-header)))
4926 ;; It is needed for filenames with capital letters
4927 (disable-shortcuts)
4928 (candidates . anything-find-files-get-candidates)
4929 (filtered-candidate-transformer anything-c-find-files-transformer)
4930 (persistent-action . anything-find-files-persistent-action)
4931 (persistent-help . "Expand Candidate")
4932 (volatile)
4933 (action
4934 . (("Hardlink File"
4935 . (lambda (candidate)
4936 (anything-dired-action candidate :action 'hardlink)))))))
4938 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
4939 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
4940 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
4941 (when (get-buffer dired-log-buffer) (kill-buffer dired-log-buffer))
4942 (let ((fn (case action
4943 ('copy 'dired-copy-file)
4944 ('rename 'dired-rename-file)
4945 ('symlink 'make-symbolic-link)
4946 ('relsymlink 'dired-make-relative-symlink)
4947 ('hardlink 'dired-hardlink)))
4948 (marker (case action
4949 ((copy rename) dired-keep-marker-copy)
4950 ('symlink dired-keep-marker-symlink)
4951 ('relsymlink dired-keep-marker-relsymlink)
4952 ('hardlink dired-keep-marker-hardlink)))
4953 (dirflag (and (= (length files) 1)
4954 (file-directory-p (car files))
4955 (not (file-directory-p candidate)))))
4956 (dired-create-files
4957 fn (symbol-name action) files
4958 ;; CANDIDATE is the destination.
4959 (if (file-directory-p candidate)
4960 ;; When CANDIDATE is a directory, build file-name in this directory.
4961 ;; Else we use CANDIDATE.
4962 #'(lambda (from)
4963 (expand-file-name (file-name-nondirectory from) candidate))
4964 #'(lambda (from) candidate))
4965 marker)
4966 (when (and follow (not (get-buffer dired-log-buffer)))
4967 (let ((target (directory-file-name candidate)))
4968 (unwind-protect
4969 (progn
4970 (setq anything-ff-cand-to-mark
4971 (anything-get-dest-fnames-from-list files candidate dirflag))
4972 (if (and dirflag (eq action 'rename))
4973 (anything-find-files-1 (file-name-directory target)
4974 (if anything-ff-transformer-show-only-basename
4975 (anything-c-basename target) target))
4976 (anything-find-files-1 (expand-file-name candidate))))
4977 (setq anything-ff-cand-to-mark nil))))))
4980 (defun anything-c-basename (fname)
4981 "Resolve basename of file or directory named FNAME."
4982 (file-name-nondirectory (directory-file-name fname)))
4984 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
4985 "Transform filenames of FLIST to abs of DEST-CAND.
4986 If RENAME-DIR-FLAG is non--nil collect the `directory-file-name' of transformed
4987 members of FLIST."
4988 ;; At this point files have been renamed/copied at destination.
4989 ;; That's mean DEST-CAND exists.
4990 (loop
4991 with dest = (expand-file-name dest-cand)
4992 for src in flist
4993 for basename-src = (anything-c-basename src)
4994 for fname = (cond (rename-dir-flag (directory-file-name dest))
4995 ((file-directory-p dest)
4996 (concat (file-name-as-directory dest) basename-src))
4997 (t dest))
4998 when (file-exists-p fname)
4999 collect fname into tmp-list
5000 finally return (sort tmp-list 'string<)))
5002 (defun anything-ff-maybe-mark-candidates ()
5003 "Mark all candidates of list `anything-ff-cand-to-mark'."
5004 (when (and (string= (assoc-default 'name (anything-get-current-source))
5005 (assoc-default 'name anything-c-source-find-files))
5006 anything-ff-cand-to-mark)
5007 (with-anything-window
5008 (while anything-ff-cand-to-mark
5009 (if (string= (car anything-ff-cand-to-mark) (anything-get-selection))
5010 (progn
5011 (anything-make-visible-mark)
5012 (anything-next-line)
5013 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
5014 (anything-next-line)))
5015 (unless (anything-this-visible-mark)
5016 (anything-prev-visible-mark)))))
5018 (add-hook 'anything-after-update-hook #'anything-ff-maybe-mark-candidates)
5020 (defun* anything-dired-do-action-on-file (&key action)
5021 (let* ((files (dired-get-marked-files))
5022 (len (length files))
5023 (fname (if (> len 1)
5024 (format "* %d Files" len)
5025 (car files)))
5026 (source (case action
5027 ('copy 'anything-c-source-copy-files)
5028 ('rename 'anything-c-source-rename-files)
5029 ('symlink 'anything-c-source-symlink-files)
5030 ('hardlink 'anything-c-source-hardlink-files)))
5031 (prompt-fm (case action
5032 ('copy "Copy %s to: ")
5033 ('rename "Rename %s to: ")
5034 ('symlink "Symlink %s to: ")
5035 ('hardlink "Hardlink %s to: ")))
5036 (buffer (case action
5037 ('copy "*Anything Copy Files*")
5038 ('rename "*Anything Rename Files*")
5039 ('symlink "*Anything Symlink Files*")
5040 ('hardlink "*Anything Hardlink Files*")))
5041 (anything-mp-highlight-delay nil))
5042 (anything :sources source
5043 :input (or (dired-dwim-target-directory)
5044 (expand-file-name (anything-c-current-directory)))
5045 :preselect (dired-get-filename)
5046 :prompt (format prompt-fm fname)
5047 :keymap anything-c-read-file-map
5048 :buffer buffer)))
5050 ;;;###autoload
5051 (define-minor-mode anything-dired-mode ()
5052 "Enable anything completion in Dired functions.
5053 Bindings affected are C, R, S, H."
5054 :group 'anything-config
5055 :global t
5056 (if anything-dired-mode
5057 (progn
5058 (substitute-key-definition
5059 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
5060 (substitute-key-definition
5061 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
5062 (substitute-key-definition
5063 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
5064 (substitute-key-definition
5065 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map))
5066 (substitute-key-definition
5067 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
5068 (substitute-key-definition
5069 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
5070 (substitute-key-definition
5071 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
5072 (substitute-key-definition
5073 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)))
5075 (defalias 'anything-dired-bindings 'anything-dired-mode)
5077 (defun* anything-c-read-file-name (prompt
5078 &key
5079 (initial-input (expand-file-name default-directory))
5080 (buffer "*Anything Completions*")
5081 test
5082 (preselect nil)
5083 (history nil)
5084 (marked-candidates nil)
5085 (alistp t)
5086 (persistent-action 'anything-find-files-persistent-action)
5087 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
5088 "Anything `read-file-name' emulation.
5089 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
5090 (when (get-buffer anything-action-buffer)
5091 (kill-buffer anything-action-buffer))
5092 (let ((anything-mp-highlight-delay nil)
5093 ;; Be sure we don't erase the underlying minibuffer if some.
5094 (anything-ff-auto-update-initial-value
5095 (not (minibuffer-window-active-p (minibuffer-window))))
5096 anything-same-window)
5097 (flet ((action-fn (candidate)
5098 (if marked-candidates
5099 (anything-marked-candidates)
5100 (identity candidate))))
5101 (or (anything
5102 :sources
5103 `(((name . "Read File Name History")
5104 (header-name . (lambda (name)
5105 (concat name anything-c-find-files-doc-header)))
5106 (disable-shortcuts)
5107 (mode-line . anything-read-file-name-mode-line-string)
5108 (candidates . (lambda ()
5109 (anything-comp-read-get-candidates history nil nil alistp)))
5110 (persistent-action . ,persistent-action)
5111 (persistent-help . ,persistent-help)
5112 (action . ,'action-fn))
5113 ((name . "Read file name")
5114 (header-name . (lambda (name)
5115 (concat name anything-c-find-files-doc-header)))
5116 ;; It is needed for filenames with capital letters
5117 (disable-shortcuts)
5118 (mode-line . anything-read-file-name-mode-line-string)
5119 (candidates . (lambda ()
5120 (let ((seq (anything-find-files-get-candidates)))
5121 (if test
5122 (loop
5123 for fname in seq when (funcall test fname)
5124 collect fname into ls
5125 finally return
5126 (append (list anything-pattern) ls))
5127 seq))))
5128 (filtered-candidate-transformer anything-c-find-files-transformer)
5129 (persistent-action . ,persistent-action)
5130 (candidate-number-limit . 9999)
5131 (toggle-auto-update . anything-ff-toggle-auto-update)
5132 (persistent-help . ,persistent-help)
5133 (volatile)
5134 (action . ,'action-fn)))
5135 :input initial-input
5136 :prompt prompt
5137 :keymap anything-c-read-file-map
5138 :resume 'noresume
5139 :buffer buffer
5140 :preselect preselect)
5141 (keyboard-quit)))))
5144 ;;; File Cache
5145 (defvar anything-c-file-cache-initialized-p nil)
5147 (defvar anything-c-file-cache-files nil)
5149 (defvar anything-c-source-file-cache
5150 '((name . "File Cache")
5151 (init
5152 . (lambda ()
5153 (require 'filecache nil t)
5154 (unless anything-c-file-cache-initialized-p
5155 (setq anything-c-file-cache-files
5156 (loop for item in file-cache-alist append
5157 (destructuring-bind (base &rest dirs) item
5158 (loop for dir in dirs collect
5159 (concat dir base)))))
5160 (defadvice file-cache-add-file (after file-cache-list activate)
5161 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
5162 (setq anything-c-file-cache-initialized-p t))))
5163 (candidates . anything-c-file-cache-files)
5164 (match anything-c-match-on-file-name
5165 anything-c-match-on-directory-name)
5166 (type . file)))
5167 ;; (anything 'anything-c-source-file-cache)
5170 ;;; Locate
5173 ;; NOTE for WINDOZE users:
5174 ;; You have to install Everything with his command line interface here:
5175 ;; http://www.voidtools.com/download.php
5177 (defvar anything-c-locate-command
5178 (case system-type
5179 ('gnu/linux "locate -i -r %s")
5180 ('berkeley-unix "locate -i %s")
5181 ('windows-nt "es -i -r %s")
5182 (t "locate %s"))
5183 "A list of arguments for locate program.
5184 The \"-r\" option must be the last option.")
5186 (defun anything-locate-1 (&optional localdb init)
5187 "Generic function to run Locate.
5188 if LOCALDB is non--nil search and use a local locate db file.
5189 INIT is a string to use as initial input in prompt.
5190 See `anything-locate-with-db' and `anything-locate'."
5191 (anything-locate-with-db
5192 (and localdb
5193 (anything-c-read-file-name
5194 "LocateDBFiles: "
5195 :marked-candidates t
5196 :preselect anything-locate-db-file-regexp
5197 :test #'(lambda (x)
5198 (if anything-locate-db-file-regexp
5199 ;; Select only locate db files and directories
5200 ;; to allow navigation.
5201 (or (string-match
5202 anything-locate-db-file-regexp x)
5203 (file-directory-p x))
5204 x))))
5205 init))
5206 ;; (anything-locate-1 t)
5208 (defun anything-locate-with-db (&optional db initial-input)
5209 "Run locate -d DB.
5210 If DB is not given or nil use locate without -d option.
5211 Argument DB can be given as a string or list of db files.
5212 Argument INITIAL-INPUT is a string to use as initial-input.
5213 See also `anything-locate'."
5214 (when (and db (stringp db)) (setq db (list db)))
5215 (let ((anything-c-locate-command
5216 (if db
5217 (replace-regexp-in-string
5218 "locate"
5219 (format "locate -d %s"
5220 (mapconcat 'identity
5221 ;; Remove eventually
5222 ;; marked directories by error.
5223 (loop for i in db
5224 unless (file-directory-p i)
5225 collect i) ":"))
5226 anything-c-locate-command)
5227 anything-c-locate-command)))
5228 (anything :sources 'anything-c-source-locate
5229 :buffer "*anything locate*"
5230 :input initial-input
5231 :keymap anything-generic-files-map)))
5232 ;; (anything-locate-with-db "~/locate.db")
5234 (defun anything-c-locate-init ()
5235 "Initialize async locate process for `anything-c-source-locate'."
5236 (setq mode-line-format
5237 '(" " mode-line-buffer-identification " "
5238 (line-number-mode "%l") " "
5239 (:eval (propertize "(Locate Process Running) "
5240 'face '((:foreground "red"))))))
5241 (prog1
5242 (start-process-shell-command "locate-process" nil
5243 (format anything-c-locate-command
5244 anything-pattern))
5245 (set-process-sentinel (get-process "locate-process")
5246 #'(lambda (process event)
5247 (when (string= event "finished\n")
5248 (with-anything-window
5249 (force-mode-line-update nil)
5250 (anything-update-move-first-line)))))))
5252 (defvar anything-c-source-locate
5253 '((name . "Locate")
5254 (candidates . anything-c-locate-init)
5255 (type . file)
5256 (properties-action . anything-ff-properties)
5257 (requires-pattern . 3)
5258 (candidate-number-limit . 9999)
5259 (mode-line . anything-generic-file-mode-line-string)
5260 (delayed))
5261 "Find files matching the current input pattern with locate.")
5262 ;; (anything 'anything-c-source-locate)
5264 (defun anything-c-locate-read-file-name (prompt &optional init)
5265 "Search a file with locate and return it's filename.
5266 Use argument PROMPT and INIT for `anything' arguments
5267 prompt and input."
5268 (anything :sources
5269 '((name . "Locate")
5270 (candidates . anything-c-locate-init)
5271 (action . identity)
5272 (properties-action . anything-ff-properties)
5273 (requires-pattern . 3)
5274 (candidate-number-limit . 9999)
5275 (mode-line . anything-generic-file-mode-line-string)
5276 (delayed))
5277 :prompt prompt
5278 :input init
5279 :buffer "*anything locate rfn*"))
5283 ;;; Anything Incremental Grep.
5286 ;; Allow to grep incrementally with anything interface.
5287 ;; It allow also to Grep files recursively without using 'find' shell command.
5288 ;; On Windows you will need at least Grep version 2.5.4 of Gnuwin32.
5289 (defvar anything-c-grep-default-command
5290 "grep -d skip %e -niH -e %p %f"
5291 "Default grep format command for `anything-do-grep-1'.
5292 Where:
5293 '%e' format spec is for --exclude or --include grep options.
5294 '%p' format spec is for pattern.
5295 '%f' format spec is for filenames.")
5297 (defvar anything-c-grep-default-recurse-command
5298 "grep -d recurse %e -niH -e %p %f"
5299 "Default recursive grep format command for `anything-do-grep-1'.
5300 See `anything-c-grep-default-command' for format specs.")
5302 (defvar anything-c-default-zgrep-command "zgrep -niH -e %p %f")
5304 (defvar anything-c-rzgrep-cache (make-hash-table :test 'equal))
5306 (defvar anything-c-grep-default-function 'anything-c-grep-init)
5308 (defvar anything-c-grep-debug-command-line nil
5309 "Turn on anything grep command-line debugging when non--nil.")
5311 (defvar anything-c-zgrep-recurse-flag nil)
5313 (defvar anything-c-grep-history nil)
5315 (defvar anything-c-grep-max-length-history 100
5316 "*Max number of elements to save in `anything-c-grep-history'.")
5318 (defun anything-c-grep-prepare-candidates (candidates)
5319 "Prepare filenames and directories CANDIDATES for grep command line."
5320 ;; If one or more candidate is a directory, search in all files
5321 ;; of this candidate (e.g /home/user/directory/*).
5322 ;; If r option is enabled search also in subdidrectories.
5323 ;; We need here to expand wildcards to support crap windows filenames
5324 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
5325 (if anything-c-zgrep-recurse-flag
5326 (mapconcat 'shell-quote-argument candidates " ")
5327 (loop for i in candidates append
5328 (cond ( ;; Candidate is a directory and we use recursion.
5329 (and (file-directory-p i)
5330 (anything-c-grep-recurse-p))
5331 (list (expand-file-name i)))
5332 ;; Candidate is a directory, search in all files.
5333 ((file-directory-p i)
5334 (file-expand-wildcards
5335 (concat (file-name-as-directory (expand-file-name i)) "*") t))
5336 ;; Candidate is a file or wildcard and we use recursion, use the
5337 ;; current directory instead of candidate.
5338 ((and (or (file-exists-p i) (string-match "\*" i))
5339 (anything-c-grep-recurse-p))
5340 (list (expand-file-name
5341 (directory-file-name ; Needed for windoze.
5342 (file-name-directory (directory-file-name i))))))
5343 ;; Candidate use wildcard.
5344 ((string-match "^\*" (anything-c-basename i))
5345 (file-expand-wildcards i t))
5346 ;; Else should be one or more file.
5347 (t (list i))) into all-files
5348 finally return
5349 (mapconcat 'shell-quote-argument all-files " "))))
5351 (defun anything-c-grep-recurse-p ()
5352 "Check if `anything-do-grep-1' have switched to recursive."
5353 (let ((args (replace-regexp-in-string
5354 "grep" "" anything-c-grep-default-command)))
5355 (string-match-p "r\\|recurse" args)))
5357 (defun anything-c-grep-init (only-files &optional include zgrep)
5358 "Start an asynchronous grep process in ONLY-FILES list."
5359 (let* ((fnargs (anything-c-grep-prepare-candidates
5360 (if (file-remote-p anything-ff-default-directory)
5361 (mapcar #'(lambda (x)
5362 (file-remote-p x 'localname))
5363 only-files)
5364 only-files)))
5365 (ignored-files (mapconcat
5366 #'(lambda (x)
5367 (concat "--exclude=" (shell-quote-argument x)))
5368 grep-find-ignored-files " "))
5369 (ignored-dirs (mapconcat
5370 ;; Need grep version 2.5.4 of Gnuwin32 on windoze.
5371 #'(lambda (x)
5372 (concat "--exclude-dir=" (shell-quote-argument x)))
5373 grep-find-ignored-directories " "))
5374 (exclude (if (anything-c-grep-recurse-p)
5375 (concat (or include ignored-files) " " ignored-dirs)
5376 ignored-files))
5377 (cmd-line (format-spec
5378 anything-c-grep-default-command
5379 (delq nil
5380 (list (unless zgrep (cons ?e exclude))
5381 (cons ?p (shell-quote-argument anything-pattern))
5382 (cons ?f fnargs))))))
5383 (when anything-c-grep-debug-command-line
5384 (with-current-buffer (get-buffer-create "*any grep debug*")
5385 (goto-char (point-max))
5386 (insert (concat ">>> " cmd-line "\n\n"))))
5387 (setq mode-line-format
5388 '(" " mode-line-buffer-identification " "
5389 (line-number-mode "%l") " "
5390 (:eval (when (get-process "grep-process")
5391 (propertize "[Grep Process Running] "
5392 'face 'anything-grep-running)))))
5393 (force-mode-line-update nil)
5394 (prog1
5395 (let ((default-directory anything-ff-default-directory))
5396 (start-file-process-shell-command "grep-process" nil cmd-line))
5397 (message nil)
5398 (set-process-sentinel
5399 (get-process "grep-process")
5400 #'(lambda (process event)
5401 (when (string= event "finished\n")
5402 (with-anything-window
5403 (anything-update-move-first-line)
5404 (setq mode-line-format
5405 '(" " mode-line-buffer-identification " "
5406 (line-number-mode "%l") " "
5407 (:eval (propertize
5408 (format "[Grep Process Finished - (%s results)] "
5409 (let ((nlines (1- (count-lines
5410 (point-min)
5411 (point-max)))))
5412 (if (> nlines 0) nlines 0)))
5413 'face 'anything-grep-finish))))
5414 (force-mode-line-update nil))))))))
5416 (defun anything-c-grep-action (candidate &optional where mark)
5417 "Define a default action for `anything-do-grep' on CANDIDATE.
5418 WHERE can be one of other-window, elscreen, other-frame."
5419 (let* ((split (anything-c-grep-split-line candidate))
5420 (lineno (string-to-number (nth 1 split)))
5421 (loc-fname (car split))
5422 (tramp-method (file-remote-p anything-ff-default-directory 'method))
5423 (tramp-host (file-remote-p anything-ff-default-directory 'host))
5424 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
5425 (fname (if tramp-host
5426 (concat tramp-prefix loc-fname) loc-fname)))
5427 (case where
5428 (other-window (find-file-other-window fname))
5429 (elscreen (anything-elscreen-find-file fname))
5430 (other-frame (find-file-other-frame fname))
5431 (t (find-file fname)))
5432 (anything-goto-line lineno)
5433 (when mark
5434 (set-marker (mark-marker) (point))
5435 (push-mark (point) 'nomsg))
5436 ;; Save history
5437 (unless (or anything-in-persistent-action
5438 (string= anything-pattern ""))
5439 (setq anything-c-grep-history
5440 (cons anything-pattern
5441 (delete anything-pattern anything-c-grep-history)))
5442 (when (> (length anything-c-grep-history)
5443 anything-c-grep-max-length-history)
5444 (setq anything-c-grep-history
5445 (delete (car (last anything-c-grep-history))
5446 anything-c-grep-history))))))
5448 (defun anything-c-grep-other-window (candidate)
5449 "Jump to result in other window from anything grep."
5450 (anything-c-grep-action candidate 'other-window))
5452 (defun anything-c-grep-other-frame (candidate)
5453 "Jump to result in other frame from anything grep."
5454 (anything-c-grep-action candidate 'other-frame))
5456 (defun anything-c-grep-jump-elscreen (candidate)
5457 "Jump to result in elscreen from anything grep."
5458 (anything-c-grep-action candidate 'elscreen))
5460 (defun anything-c-grep-save-results (candidate)
5461 "Save anything grep result in a `grep-mode' buffer."
5462 (let ((buf "*grep*")
5463 new-buf)
5464 (when (get-buffer buf)
5465 (setq new-buf (read-string "GrepBufferName: " buf))
5466 (loop for b in (anything-c-buffer-list)
5467 when (and (string= new-buf b)
5468 (not (y-or-n-p
5469 (format "Buffer `%s' already exists overwrite? "
5470 new-buf))))
5471 do (setq new-buf (read-string "GrepBufferName: " "*grep ")))
5472 (setq buf new-buf))
5473 (with-current-buffer (get-buffer-create buf)
5474 (let ((inhibit-read-only t))
5475 (erase-buffer)
5476 (insert "-*- mode: grep -*-\n\n"
5477 (format "Grep Results for `%s':\n\n" anything-pattern))
5478 (save-excursion
5479 (insert (with-current-buffer anything-buffer
5480 (forward-line 1)
5481 (buffer-substring (point) (point-max))))
5482 (grep-mode))))
5483 (message "Anything Grep Results saved in `%s' buffer" buf)))
5485 (defun anything-c-grep-persistent-action (candidate)
5486 "Persistent action for `anything-do-grep'.
5487 With a prefix arg record CANDIDATE in `mark-ring'."
5488 (if current-prefix-arg
5489 (anything-c-grep-action candidate nil 'mark)
5490 (anything-c-grep-action candidate))
5491 (anything-match-line-color-current-line))
5493 (defun anything-c-grep-guess-extensions (files)
5494 "Try to guess file extensions in FILES list when using grep recurse.
5495 These extensions will be added to command line with --include arg of grep."
5496 (loop
5497 with glob-list = nil
5498 with lst = (if (file-directory-p (car files))
5499 (directory-files
5500 (car files) nil
5501 directory-files-no-dot-files-regexp)
5502 files)
5503 for i in lst
5504 for ext = (file-name-extension i t)
5505 for glob = (and ext (not (string= ext ""))
5506 (concat "*" ext))
5507 unless (or (not glob)
5508 (member glob glob-list)
5509 (member glob grep-find-ignored-files))
5510 collect glob into glob-list
5511 finally return glob-list))
5513 (defun anything-do-grep-1 (only &optional recurse zgrep)
5514 "Launch grep with a list of ONLY files.
5515 When RECURSE is given use -r option of grep and prompt user
5516 to set the --include args of grep.
5517 You can give more than one arg separated by space.
5518 e.g *.el *.py *.tex.
5519 If it's empty --exclude `grep-find-ignored-files' is used instead."
5520 (let* ((anything-compile-source-functions
5521 ;; rule out anything-match-plugin because the input is one regexp.
5522 (delq 'anything-compile-source--match-plugin
5523 (copy-sequence anything-compile-source-functions)))
5524 (exts (anything-c-grep-guess-extensions only))
5525 (globs (and (not zgrep) (mapconcat 'identity exts " ")))
5526 (include-files (and recurse (not zgrep)
5527 (read-string "OnlyExt(*.[ext]): "
5528 globs)))
5529 ;; Set `minibuffer-history' AFTER includes-files
5530 ;; to avoid storing wild-cards here.
5531 (minibuffer-history anything-c-grep-history)
5532 (anything-c-grep-default-command (cond ((and recurse zgrep) anything-c-default-zgrep-command)
5533 (recurse anything-c-grep-default-recurse-command)
5534 (zgrep anything-c-default-zgrep-command)
5535 (t anything-c-grep-default-command)))
5536 ;; Disable match-plugin and use here own highlighting.
5537 (anything-mp-highlight-delay nil))
5538 (when include-files
5539 (setq include-files
5540 (and (not (string= include-files ""))
5541 (mapconcat #'(lambda (x)
5542 (concat "--include=" (shell-quote-argument x)))
5543 (split-string include-files) " "))))
5544 ;; When called as action from an other source e.g *-find-files
5545 ;; we have to kill action buffer.
5546 (when (get-buffer anything-action-buffer)
5547 (kill-buffer anything-action-buffer))
5548 ;; `anything-find-files' haven't already started,
5549 ;; give a default value to `anything-ff-default-directory'.
5550 (setq anything-ff-default-directory (or anything-ff-default-directory
5551 default-directory))
5552 (anything
5553 :sources
5554 `(((name . "Grep (C-c ? Help)")
5555 (candidates
5556 . (lambda ()
5557 (funcall anything-c-grep-default-function only include-files zgrep)))
5558 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5559 (candidate-number-limit . 9999)
5560 (mode-line . anything-grep-mode-line-string)
5561 (jump-persistent . anything-c-grep-persistent-action)
5562 (action . ,(delq
5564 `(("Find File" . anything-c-grep-action)
5565 ("Find file other frame" . anything-c-grep-other-frame)
5566 ,(and (locate-library "elscreen")
5567 '("Find file in Elscreen"
5568 . anything-c-grep-jump-elscreen))
5569 ("Save results in grep buffer" . anything-c-grep-save-results)
5570 ("Find file other window" . anything-c-grep-other-window))))
5571 (persistent-action . anything-c-grep-persistent-action)
5572 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
5573 (requires-pattern . 3)
5574 (delayed)))
5575 :keymap anything-c-grep-map
5576 :buffer "*anything grep*")))
5578 (defun anything-ff-zgrep-1 (flist recursive)
5579 (unwind-protect
5580 (let* ((def-dir (or anything-ff-default-directory
5581 default-directory))
5582 (only (if recursive
5583 (or (gethash def-dir anything-c-rzgrep-cache)
5584 (puthash
5585 def-dir
5586 (anything-c-walk-directory
5587 def-dir
5588 :directories nil
5589 :path 'full
5590 :match ".*\\(\.gz\\|\.bz\\|\.xz\\|\.lzma\\)$")
5591 anything-c-rzgrep-cache))
5592 flist)))
5593 (when recursive (setq anything-c-zgrep-recurse-flag t))
5594 (anything-do-grep-1 only recursive 'zgrep))
5595 (setq anything-c-zgrep-recurse-flag nil)))
5597 (defun anything-c-grep-split-line (line)
5598 "Split a grep output line."
5599 (let (beg fname lineno str)
5600 ;; Don't print until grep line is valid.
5601 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
5602 (with-temp-buffer
5603 (insert line)
5604 (goto-char (point-min))
5605 (setq beg (point))
5606 (forward-char 2)
5607 (re-search-forward ":" nil t)
5608 (setq fname (buffer-substring-no-properties beg (1- (point))))
5609 (setq beg (point))
5610 (re-search-forward ":" nil t)
5611 (setq lineno (buffer-substring-no-properties beg (1- (point))))
5612 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
5613 (list fname lineno str))))
5615 (defun anything-c-grep-cand-transformer (candidates sources)
5616 "Filtered candidate transformer function for `anything-do-grep'."
5617 (loop for i in candidates
5618 for split = (and i (anything-c-grep-split-line i))
5619 for fname = (car split)
5620 for lineno = (nth 1 split)
5621 for str = (nth 2 split)
5622 when (and fname lineno str)
5623 collect
5624 (cons (concat (propertize (file-name-nondirectory fname)
5625 'face 'anything-grep-file
5626 'help-echo fname) ":"
5627 (propertize lineno 'face 'anything-grep-lineno) ":"
5628 (anything-c-grep-highlight-match str))
5629 i)))
5631 (defun anything-c-grep-highlight-match (str)
5632 "Highlight in string STR all occurences matching `anything-pattern'."
5633 (condition-case nil
5634 (with-temp-buffer
5635 (insert str)
5636 (goto-char (point-min))
5637 (while (and (re-search-forward anything-pattern nil t)
5638 (> (- (match-end 0) (match-beginning 0)) 0))
5639 (add-text-properties
5640 (match-beginning 0) (match-end 0)
5641 '(face anything-grep-match)))
5642 (buffer-string))
5643 (error nil)))
5645 ;; Go to next or precedent file (common to etags and grep).
5646 (defun anything-c-goto-next-or-prec-file (n)
5647 "Go to next or precedent candidate file in anything grep/etags buffers.
5648 If N is positive go forward otherwise go backward."
5649 (with-anything-window
5650 (let* ((current-line-list (split-string
5651 (buffer-substring
5652 (point-at-bol)
5653 (point-at-eol)) ":"))
5654 (current-fname (nth 0 current-line-list))
5655 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
5656 (catch 'break
5657 (while (not (funcall fn-b-o-f))
5658 (forward-line n) ; Go forward or backward depending of n value.
5659 (unless (search-forward current-fname (point-at-eol) t)
5660 (anything-mark-current-line)
5661 (throw 'break nil))))
5662 (cond ((and (eq n 1) (eobp))
5663 (re-search-backward ".")
5664 (forward-line 0)
5665 (anything-mark-current-line))
5666 ((and (< n 1) (bobp))
5667 (forward-line 1)
5668 (anything-mark-current-line))))))
5670 ;;;###autoload
5671 (defun anything-c-goto-precedent-file ()
5672 "Go to precedent file in anything grep/etags buffers."
5673 (interactive)
5674 (anything-c-goto-next-or-prec-file -1))
5676 ;;;###autoload
5677 (defun anything-c-goto-next-file ()
5678 "Go to precedent file in anything grep/etags buffers."
5679 (interactive)
5680 (anything-c-goto-next-or-prec-file 1))
5682 ;;;###autoload
5683 (defun anything-c-grep-run-persistent-action ()
5684 "Run grep persistent action from `anything-do-grep-1'."
5685 (interactive)
5686 (anything-execute-persistent-action 'jump-persistent))
5688 ;;;###autoload
5689 (defun anything-c-grep-run-default-action ()
5690 "Run grep default action from `anything-do-grep-1'."
5691 (interactive)
5692 (anything-c-quit-and-execute-action 'anything-c-grep-action))
5694 ;;;###autoload
5695 (defun anything-c-grep-run-other-window-action ()
5696 "Run grep goto other window action from `anything-do-grep-1'."
5697 (interactive)
5698 (anything-c-quit-and-execute-action 'anything-c-grep-other-window))
5700 ;;;###autoload
5701 (defun anything-c-grep-run-save-buffer ()
5702 "Run grep save results action from `anything-do-grep-1'."
5703 (interactive)
5704 (anything-c-quit-and-execute-action 'anything-c-grep-save-results))
5706 ;; Grep buffers
5707 (defun anything-c-grep-buffers-1 (candidate &optional zgrep)
5708 "Run grep on all file--buffers or CANDIDATE if it is a file--buffer.
5709 If one of selected buffers is not a file--buffer,
5710 it is ignored and grep will run on all others file--buffers.
5711 If only one candidate is selected and it is not a file--buffer,
5712 switch to this buffer and run `anything-occur'.
5713 If a prefix arg is given run grep on all buffers ignoring non--file-buffers."
5714 (let* ((prefarg (or current-prefix-arg anything-current-prefix-arg))
5715 (cands (if prefarg
5716 (buffer-list)
5717 (anything-marked-candidates)))
5718 (win-conf (current-window-configuration))
5719 ;; Non--fname buffers are ignored.
5720 (bufs (loop for buf in cands
5721 for fname = (buffer-file-name (get-buffer buf))
5722 when fname
5723 collect (expand-file-name fname))))
5724 (if bufs
5725 (if zgrep
5726 (anything-do-grep-1 bufs nil 'zgrep)
5727 (anything-do-grep-1 bufs))
5728 ;; bufs is empty, thats mean we have only CANDIDATE
5729 ;; and it is not a buffer-filename, fallback to occur.
5730 (anything-c-switch-to-buffer candidate)
5731 (when (get-buffer anything-action-buffer)
5732 (kill-buffer anything-action-buffer))
5733 (anything-occur)
5734 (when (eq anything-exit-status 1)
5735 (set-window-configuration win-conf)))))
5737 (defun anything-c-grep-buffers (candidate)
5738 "Action to grep buffers."
5739 (anything-c-grep-buffers-1 candidate))
5741 (defun anything-c-zgrep-buffers (candidate)
5742 "Action to zgrep buffers."
5743 (anything-c-grep-buffers-1 candidate 'zgrep))
5746 ;;; Anything interface for pdfgrep
5747 ;; pdfgrep program <http://pdfgrep.sourceforge.net/>
5748 ;; and a pdf-reader (e.g xpdf) are needed.
5750 (defvar anything-c-pdfgrep-default-command "pdfgrep --color never -niH %s %s")
5751 (defvar anything-c-pdfgrep-default-function 'anything-c-pdfgrep-init)
5752 (defvar anything-c-pdfgrep-debug-command-line nil)
5754 (defun anything-c-pdfgrep-init (only-files)
5755 "Start an asynchronous pdfgrep process in ONLY-FILES list."
5756 (let* ((fnargs (anything-c-grep-prepare-candidates
5757 (if (file-remote-p anything-ff-default-directory)
5758 (mapcar #'(lambda (x)
5759 (file-remote-p x 'localname))
5760 only-files)
5761 only-files)))
5762 (cmd-line (format anything-c-pdfgrep-default-command
5763 anything-pattern
5764 fnargs)))
5765 (when anything-c-pdfgrep-debug-command-line
5766 (with-current-buffer (get-buffer-create "*any pdfgrep debug*")
5767 (goto-char (point-max))
5768 (insert (concat ">>> " cmd-line "\n\n"))))
5769 (setq mode-line-format
5770 '(" " mode-line-buffer-identification " "
5771 (line-number-mode "%l") " "
5772 (:eval (propertize "(Pdfgrep Process Running) "
5773 'face '((:foreground "red"))))))
5774 (prog1
5775 (let ((default-directory anything-ff-default-directory))
5776 (start-file-process-shell-command "pdfgrep-process" nil cmd-line))
5777 (message nil)
5778 (set-process-sentinel
5779 (get-process "pdfgrep-process")
5780 #'(lambda (process event)
5781 (when (string= event "finished\n")
5782 (with-anything-window
5783 (anything-update-move-first-line))
5784 (force-mode-line-update nil)))))))
5787 (defun anything-do-pdfgrep-1 (only)
5788 "Launch pdfgrep with a list of ONLY files."
5789 (unless (executable-find "pdfgrep")
5790 (error "Error: No such program `pdfgrep'."))
5791 (let* ((anything-compile-source-functions
5792 ;; rule out anything-match-plugin because the input is one regexp.
5793 (delq 'anything-compile-source--match-plugin
5794 (copy-sequence anything-compile-source-functions)))
5795 ;; Disable match-plugin and use here own highlighting.
5796 (anything-mp-highlight-delay nil))
5797 ;; When called as action from an other source e.g *-find-files
5798 ;; we have to kill action buffer.
5799 (when (get-buffer anything-action-buffer)
5800 (kill-buffer anything-action-buffer))
5801 ;; If `anything-find-files' haven't already started,
5802 ;; give a default value to `anything-ff-default-directory'.
5803 (setq anything-ff-default-directory (or anything-ff-default-directory
5804 default-directory))
5805 (anything
5806 :sources
5807 `(((name . "PdfGrep")
5808 (candidates
5809 . (lambda ()
5810 (funcall anything-c-pdfgrep-default-function only)))
5811 (filtered-candidate-transformer anything-c-grep-cand-transformer)
5812 (candidate-number-limit . 9999)
5813 (mode-line . anything-pdfgrep-mode-line-string)
5814 (action . anything-c-pdfgrep-action)
5815 (persistent-help . "Jump to PDF Page")
5816 (requires-pattern . 3)
5817 (delayed)))
5818 :keymap anything-c-pdfgrep-map
5819 :buffer "*anything grep*")))
5822 (defun anything-c-pdfgrep-action (candidate)
5823 (let* ((split (anything-c-grep-split-line candidate))
5824 (pageno (nth 1 split))
5825 (fname (car split)))
5826 (start-file-process-shell-command
5827 "pdf-reader" nil
5828 (format-spec anything-c-pdfgrep-default-read-command
5829 (list (cons ?f fname) (cons ?p pageno))))))
5831 (defun anything-do-pdfgrep ()
5832 (interactive)
5833 (let ((only (anything-c-read-file-name
5834 "Search in file(s): "
5835 :marked-candidates t
5836 :test #'(lambda (file)
5837 (or (string= (file-name-extension file) "pdf")
5838 (string= (file-name-extension file) "PDF")
5839 (file-directory-p file)))
5840 :preselect (or (dired-get-filename nil t)
5841 (buffer-file-name (current-buffer)))))
5842 (anything-c-grep-default-function 'anything-c-pdfgrep-init))
5843 (anything-do-pdfgrep-1 only)))
5846 ;; Yank text at point.
5849 ;; Internal
5850 (defvar anything-yank-point nil)
5852 ;;;###autoload
5853 (defun anything-yank-text-at-point ()
5854 "Yank text at point in minibuffer."
5855 (interactive)
5856 (let (input)
5857 (flet ((insert-in-minibuffer (word)
5858 (with-selected-window (minibuffer-window)
5859 (let ((str anything-pattern))
5860 (delete-minibuffer-contents)
5861 (set-text-properties 0 (length word) nil word)
5862 (insert (concat str word))))))
5863 (with-anything-current-buffer
5864 ;; Start to initial point if C-w have never been hit.
5865 (unless anything-yank-point (setq anything-yank-point (point)))
5866 (and anything-yank-point (goto-char anything-yank-point))
5867 (forward-word 1)
5868 (setq input (buffer-substring-no-properties anything-yank-point (point)))
5869 (setq anything-yank-point (point))) ; End of last forward-word
5870 (insert-in-minibuffer input))))
5872 (defun anything-reset-yank-point ()
5873 (setq anything-yank-point nil))
5875 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
5876 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
5877 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
5880 ;;; Recentf files
5883 (defvar anything-c-source-recentf
5884 '((name . "Recentf")
5885 (init . (lambda ()
5886 (require 'recentf)
5887 (or recentf-mode (recentf-mode 1))
5888 ;; Big value empowers anything/recentf
5889 (when (and (numberp recentf-max-saved-items)
5890 (<= recentf-max-saved-items 20))
5891 (setq recentf-max-saved-items 500))))
5892 (candidates . recentf-list)
5893 (match anything-c-match-on-file-name
5894 anything-c-match-on-directory-name)
5895 (type . file))
5896 "See (info \"(emacs)File Conveniences\").
5897 if `recentf-max-saved-items' is too small, set it to 500.")
5898 ;; (anything 'anything-c-source-recentf)
5900 ;;; ffap
5901 (eval-when-compile (require 'ffap))
5902 (defvar anything-c-source-ffap-guesser
5903 '((name . "File at point")
5904 (init . (lambda () (require 'ffap)))
5905 (candidates . (lambda ()
5906 (anything-aif
5907 (with-anything-current-buffer
5908 (ffap-guesser))
5909 (list it))))
5910 (type . file)))
5911 ;; (anything 'anything-c-source-ffap-guesser)
5913 ;;; ffap with line number
5914 (defun anything-c-ffap-file-line-at-point ()
5915 "Get (FILENAME . LINENO) at point."
5916 (anything-aif (let (ffap-alist) (ffap-file-at-point))
5917 (save-excursion
5918 (beginning-of-line)
5919 (when (and (search-forward it nil t)
5920 (looking-at ":\\([0-9]+\\)"))
5921 (cons it (string-to-number (match-string 1)))))))
5923 (defvar anything-c-ffap-line-location nil
5924 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
5925 It is cleared after jumping line.")
5927 (defun anything-c-ffap-line-candidates ()
5928 (with-anything-current-buffer
5929 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
5930 (when anything-c-ffap-line-location
5931 (destructuring-bind (file . line) anything-c-ffap-line-location
5932 (list (cons (format "%s (line %d)" file line) file)))))
5934 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
5935 (defun anything-c-ffap-line-goto-line ()
5936 (when (car anything-c-ffap-line-location)
5937 (unwind-protect
5938 (ignore-errors
5939 (with-selected-window
5940 (get-buffer-window
5941 (get-file-buffer (car anything-c-ffap-line-location)))
5942 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
5943 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
5944 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
5946 (defvar anything-c-source-ffap-line
5947 '((name . "File/Lineno at point")
5948 (init . (lambda () (require 'ffap)))
5949 (candidates . anything-c-ffap-line-candidates)
5950 (type . file)))
5951 ;; (anything 'anything-c-source-ffap-line)
5953 ;;; list of files gleaned from every dired buffer
5954 (defun anything-c-files-in-all-dired-candidates ()
5955 (save-excursion
5956 (mapcan
5957 (lambda (dir)
5958 (cond ((listp dir) ;filelist
5959 dir)
5960 ((equal "" (file-name-nondirectory dir)) ;dir
5961 (directory-files dir t))
5962 (t ;wildcard
5963 (file-expand-wildcards dir t))))
5964 (delq nil
5965 (mapcar (lambda (buf)
5966 (set-buffer buf)
5967 (when (eq major-mode 'dired-mode)
5968 (if (consp dired-directory)
5969 (cdr dired-directory) ;filelist
5970 dired-directory))) ;dir or wildcard
5971 (buffer-list))))))
5972 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
5974 (defvar anything-c-source-files-in-all-dired
5975 '((name . "Files in all dired buffer.")
5976 (candidates . anything-c-files-in-all-dired-candidates)
5977 (type . file)))
5978 ;; (anything 'anything-c-source-files-in-all-dired)
5980 (defvar anything-c-source-filelist
5981 '((name . "FileList")
5982 (grep-candidates . anything-c-filelist-file-name)
5983 (candidate-number-limit . 200)
5984 (requires-pattern . 4)
5985 (type . file))
5986 "Source to find files instantly.
5987 See `anything-c-filelist-file-name' docstring for usage.")
5990 ;;;; <info>
5991 ;;; Info pages
5992 (defvar anything-c-info-pages nil
5993 "All info pages on system.
5994 Will be calculated the first time you invoke anything with this
5995 source.")
5997 (defvar anything-c-source-info-pages
5998 `((name . "Info Pages")
5999 (candidates
6000 . (lambda ()
6001 (if anything-c-info-pages
6002 anything-c-info-pages
6003 (setq anything-c-info-pages
6004 (save-window-excursion
6005 (save-excursion
6006 (require 'info)
6007 (Info-find-node "dir" "top")
6008 (goto-char (point-min))
6009 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
6010 topics)
6011 (while (re-search-forward info-topic-regexp nil t)
6012 (add-to-list 'topics (match-string-no-properties 1)))
6013 (goto-char (point-min))
6014 (Info-exit)
6015 topics)))))))
6016 (action . (("Show with Info" .(lambda (node-str)
6017 (info (replace-regexp-in-string
6018 "^[^:]+: " "" node-str))))))
6019 (requires-pattern . 2)))
6020 ;; (anything 'anything-c-source-info-pages)
6023 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
6024 (defun anything-c-describe-attributes (anything-attribute)
6025 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
6026 Same as `anything-describe-anything-attribute' but with anything completion."
6027 (interactive (list (intern
6028 (anything-comp-read
6029 "Describe anything attribute: "
6030 (mapcar 'symbol-name anything-additional-attributes)
6031 :must-match t
6032 :persistent-action
6033 #'(lambda (candidate)
6034 (with-output-to-temp-buffer "*Help*"
6035 (princ (get (intern candidate) 'anything-attrdoc))))))))
6036 (with-output-to-temp-buffer "*Help*"
6037 (princ (get anything-attribute 'anything-attrdoc))))
6040 ;;; Use info-index plug-in.
6043 ;; Note that `name' attribute is not needed since
6044 ;; `anything-c-insert-summary' have been removed.
6045 ;; Info Elisp
6046 (defvar anything-c-source-info-elisp
6047 '((name . "Info index: elisp")
6048 (info-index . "elisp")))
6049 ;; (anything 'anything-c-source-info-elisp)
6051 ;; Info-Common-Lisp
6052 (defvar anything-c-source-info-cl
6053 '((name . "Info index: cl")
6054 (info-index . "cl")))
6055 ;; (anything 'anything-c-source-info-cl)
6057 ;; Info Index org
6058 (defvar anything-c-source-info-org
6059 '((name . "Info index: org")
6060 (info-index . "org")))
6061 ;; (anything 'anything-c-source-info-org)
6063 ;; Info Index gnus
6064 (defvar anything-c-source-info-gnus
6065 '((name . "Info index: Gnus")
6066 (info-index . "gnus")))
6068 ;; Info Index ratpoison
6069 (defvar anything-c-source-info-ratpoison
6070 '((name . "Info index: ratpoison")
6071 (info-index . "ratpoison")))
6072 ;; (anything 'anything-c-source-info-ratpoison)
6074 ;; Info Index zsh
6075 (defvar anything-c-source-info-zsh
6076 '((name . "Info index: zsh")
6077 (info-index . "zsh")))
6078 ;; (anything 'anything-c-source-info-zsh)
6080 ;; Info Index bash
6081 (defvar anything-c-source-info-bash
6082 '((name . "Info index: bash")
6083 (info-index . "bash")))
6084 ;; (anything 'anything-c-source-info-bash)
6086 ;; Info Index coreutils
6087 (defvar anything-c-source-info-coreutils
6088 '((name . "Info index: coreutils")
6089 (info-index . "coreutils")))
6090 ;; (anything 'anything-c-source-info-coreutils)
6092 ;; Info Index fileutils
6093 (defvar anything-c-source-info-fileutils
6094 '((name . "Info index: fileutils")
6095 (info-index . "fileutils")))
6096 ;; (anything 'anything-c-source-info-fileutils)
6098 ;; Info Index find
6099 (defvar anything-c-source-info-find
6100 '((name . "Info index: find")
6101 (info-index . "find")))
6102 ;; (anything 'anything-c-source-info-find)
6104 ;; Info Index sh-utils
6105 (defvar anything-c-source-info-sh-utils
6106 '((name . "Info index: sh-utils")
6107 (info-index . "sh-utils")))
6108 ;; (anything 'anything-c-source-info-sh-utils)
6110 ;; Info Index textutils
6111 (defvar anything-c-source-info-textutils
6112 '((name . "Info index: textutils")
6113 (info-index . "textutils")))
6114 ;; (anything 'anything-c-source-info-textutils)
6116 ;; Info Index libc
6117 (defvar anything-c-source-info-libc
6118 '((name . "Info index: libc")
6119 (info-index . "libc")))
6120 ;; (anything 'anything-c-source-info-libc)
6122 ;; Info Index make
6123 (defvar anything-c-source-info-make
6124 '((name . "Info index: make")
6125 (info-index . "make")))
6126 ;; (anything 'anything-c-source-info-make)
6128 ;; Info Index automake
6129 (defvar anything-c-source-info-automake
6130 '((name . "Info index: automake")
6131 (info-index . "automake")))
6132 ;; (anything 'anything-c-source-info-automake)
6134 ;; Info Index autoconf
6135 (defvar anything-c-source-info-autoconf
6136 '((name . "Info index: autoconf")
6137 (info-index . "autoconf")))
6138 ;; (anything 'anything-c-source-info-autoconf)
6140 ;; Info Index emacs-lisp-intro
6141 (defvar anything-c-source-info-emacs-lisp-intro
6142 '((name . "Info index: emacs-lisp-intro")
6143 (info-index . "emacs-lisp-intro")))
6144 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
6146 ;; Info Index emacs
6147 (defvar anything-c-source-info-emacs
6148 '((name . "Info index: emacs")
6149 (info-index . "emacs")))
6150 ;; (anything 'anything-c-source-info-emacs)
6152 ;; Info Index elib
6153 (defvar anything-c-source-info-elib
6154 '((name . "Info index: elib")
6155 (info-index . "elib")))
6156 ;; (anything 'anything-c-source-info-elib)
6158 ;; Info Index eieio
6159 (defvar anything-c-source-info-eieio
6160 '((name . "Info index: eieio")
6161 (info-index . "eieio")))
6162 ;; (anything 'anything-c-source-info-eieio)
6164 ;; Info Index gauche-refe
6165 (defvar anything-c-source-info-gauche-refe
6166 '((name . "Info index: gauche")
6167 (info-index . "gauche-refe")))
6168 ;; (anything 'anything-c-source-info-gauche-refe)
6170 ;; Info Index guile
6171 (defvar anything-c-source-info-guile
6172 '((name . "Info index: guile")
6173 (info-index . "guile")))
6174 ;; (anything 'anything-c-source-info-guile)
6176 ;; Info Index guile-tut
6177 (defvar anything-c-source-info-guile-tut
6178 '((name . "Info index: guile-tut")
6179 (info-index . "guile-tut")))
6180 ;; (anything 'anything-c-source-info-guile-tut)
6182 ;; Info Index goops
6183 (defvar anything-c-source-info-goops
6184 '((name . "Info index: goops")
6185 (info-index . "goops")))
6186 ;; (anything 'anything-c-source-info-goops)
6188 ;; Info Index screen
6189 (defvar anything-c-source-info-screen
6190 '((name . "Info index: screen")
6191 (info-index . "screen")
6192 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
6193 ;; (anything 'anything-c-source-info-screen)
6195 ;; Info Index latex
6196 (defvar anything-c-source-info-latex
6197 '((name . "Info index: latex")
6198 (info-index . "latex")))
6199 ;; (anything 'anything-c-source-info-latex)
6201 ;; Info Index gawk
6202 (defvar anything-c-source-info-gawk
6203 '((name . "Info index: gawk")
6204 (info-index . "gawk")))
6205 ;; (anything 'anything-c-source-info-gawk)
6207 ;; Info Index sed
6208 (defvar anything-c-source-info-sed
6209 '((name . "Info index: sed")
6210 (info-index . "sed")))
6211 ;; (anything 'anything-c-source-info-sed)
6213 ;; Info Index m4
6214 (defvar anything-c-source-info-m4
6215 '((name . "Info index: m4")
6216 (info-index . "m4")))
6217 ;; (anything 'anything-c-source-info-m4)
6219 ;; Info Index wget
6220 (defvar anything-c-source-info-wget
6221 '((name . "Info index: wget")
6222 (info-index . "wget")))
6223 ;; (anything 'anything-c-source-info-wget)
6225 ;; Info Index binutils
6226 (defvar anything-c-source-info-binutils
6227 '((name . "Info index: binutils")
6228 (info-index . "binutils")))
6229 ;; (anything 'anything-c-source-info-binutils)
6231 ;; Info Index as
6232 (defvar anything-c-source-info-as
6233 '((name . "Info index: as")
6234 (info-index . "as")))
6235 ;; (anything 'anything-c-source-info-as)
6237 ;; Info Index bfd
6238 (defvar anything-c-source-info-bfd
6239 '((name . "Info index: bfd")
6240 (info-index . "bfd")))
6241 ;; (anything 'anything-c-source-info-bfd)
6243 ;; Info Index gprof
6244 (defvar anything-c-source-info-gprof
6245 '((name . "Info index: gprof")
6246 (info-index . "gprof")))
6247 ;; (anything 'anything-c-source-info-gprof)
6249 ;; Info Index ld
6250 (defvar anything-c-source-info-ld
6251 '((name . "Info index: ld")
6252 (info-index . "ld")))
6253 ;; (anything 'anything-c-source-info-ld)
6255 ;; Info Index diff
6256 (defvar anything-c-source-info-diff
6257 '((name . "Info index: diff")
6258 (info-index . "diff")))
6259 ;; (anything 'anything-c-source-info-diff)
6261 ;; Info Index flex
6262 (defvar anything-c-source-info-flex
6263 '((name . "Info index: flex")
6264 (info-index . "flex")))
6265 ;; (anything 'anything-c-source-info-flex)
6267 ;; Info Index grep
6268 (defvar anything-c-source-info-grep
6269 '((name . "Info index: grep")
6270 (info-index . "grep")))
6271 ;; (anything 'anything-c-source-info-grep)
6273 ;; Info Index gzip
6274 (defvar anything-c-source-info-gzip
6275 '((name . "Info index: gzip")
6276 (info-index . "gzip")))
6277 ;; (anything 'anything-c-source-info-gzip)
6279 ;; Info Index libtool
6280 (defvar anything-c-source-info-libtool
6281 '((name . "Info index: libtool")
6282 (info-index . "libtool")))
6283 ;; (anything 'anything-c-source-info-libtool)
6285 ;; Info Index texinfo
6286 (defvar anything-c-source-info-texinfo
6287 '((name . "Info index: texinfo")
6288 (info-index . "texinfo")))
6289 ;; (anything 'anything-c-source-info-texinfo)
6291 ;; Info Index info
6292 (defvar anything-c-source-info-info
6293 '((name . "Info index: info")
6294 (info-index . "info")))
6295 ;; (anything 'anything-c-source-info-info)
6297 ;; Info Index gdb
6298 (defvar anything-c-source-info-gdb
6299 '((name . "Info index: gdb")
6300 (info-index . "gdb")))
6301 ;; (anything 'anything-c-source-info-gdb)
6303 ;; Info Index stabs
6304 (defvar anything-c-source-info-stabs
6305 '((name . "Info index: stabs")
6306 (info-index . "stabs")))
6307 ;; (anything 'anything-c-source-info-stabs)
6309 ;; Info Index cvsbook
6310 (defvar anything-c-source-info-cvsbook
6311 '((name . "Info index: cvsbook")
6312 (info-index . "cvsbook")))
6313 ;; (anything 'anything-c-source-info-cvsbook)
6315 ;; Info Index cvs
6316 (defvar anything-c-source-info-cvs
6317 '((name . "Info index: cvs")
6318 (info-index . "cvs")))
6319 ;; (anything 'anything-c-source-info-cvs)
6321 ;; Info Index bison
6322 (defvar anything-c-source-info-bison
6323 '((name . "Info index: bison")
6324 (info-index . "bison")))
6325 ;; (anything 'anything-c-source-info-bison)
6327 ;; Info Index id-utils
6328 (defvar anything-c-source-info-id-utils
6329 '((name . "Info index: id-utils")
6330 (info-index . "id-utils")))
6331 ;; (anything 'anything-c-source-info-id-utils)
6333 ;; Info Index global
6334 (defvar anything-c-source-info-global
6335 '((name . "Info index: global")
6336 (info-index . "global")))
6337 ;; (anything 'anything-c-source-info-global)
6340 ;;;; <Help>
6341 ;;; Man and woman UI
6344 (defvar anything-c-man-pages nil
6345 "All man pages on system.
6346 Will be calculated the first time you invoke anything with this
6347 source.")
6349 (defun anything-c-man-default-action (candidate)
6350 "Default action for jumping to a woman or man page from anything."
6351 (let ((wfiles (woman-file-name-all-completions candidate)))
6352 (condition-case err
6353 (if (> (length wfiles) 1)
6354 (woman-find-file
6355 (anything-comp-read
6356 "ManFile: " wfiles :must-match t))
6357 (woman candidate))
6358 ;; If woman is unable to format correctly
6359 ;; use man instead.
6360 (error (kill-buffer) ; Kill woman buffer.
6361 (let ((Man-notify-method 'meek))
6362 (Man-getpage-in-background candidate))))))
6364 (defvar anything-c-source-man-pages
6365 `((name . "Manual Pages")
6366 (candidates . (lambda ()
6367 (if anything-c-man-pages
6368 anything-c-man-pages
6369 ;; XEmacs doesn't have a woman :)
6370 (setq anything-c-man-pages
6371 (ignore-errors
6372 (require 'woman)
6373 (woman-file-name "")
6374 (sort (mapcar 'car woman-topic-all-completions)
6375 'string-lessp))))))
6376 (action ("Show with Woman" . anything-c-man-default-action))
6377 ;; Woman does not work OS X
6378 ;; http://xahlee.org/emacs/modernization_man_page.html
6379 (action-transformer . (lambda (actions candidate)
6380 (if (eq system-type 'darwin)
6381 '(("Show with Man" . man))
6382 actions)))
6383 (requires-pattern . 2)))
6384 ;; (anything 'anything-c-source-man-pages)
6387 ;;;; <Command>
6388 ;;; Complex command history
6391 (defvar anything-c-source-complex-command-history
6392 '((name . "Complex Command History")
6393 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
6394 (type . sexp)))
6395 ;; (anything 'anything-c-source-complex-command-history)
6397 ;;; M-x history (not related to `anything-M-x')
6400 (defvar anything-c-source-extended-command-history
6401 '((name . "Emacs Commands History")
6402 (candidates . extended-command-history)
6403 (type . command)))
6404 ;; (anything 'anything-c-source-extended-command-history)
6406 ;;; Emacs commands (Basic source for emacs commands)
6409 (defvar anything-c-source-emacs-commands
6410 '((name . "Emacs Commands")
6411 (candidates . (lambda ()
6412 (let (commands)
6413 (mapatoms (lambda (a)
6414 (if (commandp a)
6415 (push (symbol-name a)
6416 commands))))
6417 (sort commands 'string-lessp))))
6418 (type . command)
6419 (requires-pattern . 2))
6420 "Source for completing and invoking Emacs commands.
6421 A command is a function with interactive spec that can
6422 be invoked with `M-x'.
6424 To get non-interactive functions listed, use
6425 `anything-c-source-emacs-functions'.")
6426 ;; (anything 'anything-c-source-emacs-commands)
6429 ;;; Anything M-x - Enhanced M-x UI
6432 ;; Another replacement of `M-x' that act exactly like the
6433 ;; vanilla Emacs one, no problem of windows configuration, prefix args
6434 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
6435 ;; anything invocation.
6436 ;; Documentation of commands available without quitting,
6437 ;; Show keybindings of commands.
6438 ;; Show history.
6439 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
6440 "Return alist of MODE-MAP."
6441 (loop for key being the key-seqs of mode-map using (key-bindings com)
6442 for str-key = (key-description key)
6443 for ismenu = (string-match "<menu-bar>" str-key)
6444 unless ismenu collect (cons str-key com)))
6446 (defun anything-get-mode-map-from-mode (mode)
6447 "Guess the mode-map name according to MODE.
6448 Some modes don't use conventional mode-map name
6449 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
6450 Return nil if no mode-map found."
6451 (loop
6452 ;; Start with a conventional mode-map name.
6453 with mode-map = (intern-soft (format "%s-map" mode))
6454 with mode-string = (symbol-name mode)
6455 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
6456 while (not mode-map)
6457 for count downfrom (length mode-name)
6458 ;; Return when no result after parsing entire string.
6459 when (eq count 0) return nil
6460 for sub-name = (substring mode-name 0 count)
6461 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
6462 finally return mode-map))
6464 (defun anything-M-x-current-mode-map-alist ()
6465 "Return mode-map alist of current `major-mode'."
6466 (let ((map (anything-get-mode-map-from-mode major-mode)))
6467 (when (and map (boundp map))
6468 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
6471 (defun anything-M-x-transformer (candidates sources)
6472 "filtered-candidate-transformer to show bindings in emacs commands.
6473 Show global bindings and local bindings according to current `major-mode'."
6474 (with-anything-current-buffer
6475 (loop
6476 with local-map = (anything-M-x-current-mode-map-alist)
6477 for cand in candidates
6478 for local-key = (car (rassq cand local-map))
6479 for key = (substitute-command-keys (format "\\[%s]" cand))
6480 collect
6481 (cons (cond ((and (string-match "^M-x" key) local-key)
6482 (format "%s (%s)"
6483 cand (propertize
6484 local-key
6485 'face 'anything-M-x-key-face)))
6486 ((string-match "^M-x" key) cand)
6487 (t (format "%s (%s)"
6488 cand (propertize
6490 'face 'anything-M-x-key-face)))) cand))))
6493 ;;; LaCarte
6494 (defvar anything-c-source-lacarte
6495 '((name . "Lacarte")
6496 (init . (lambda () (require 'lacarte )))
6497 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
6498 (candidate-number-limit . 9999)
6499 (action . anything-c-call-interactively))
6500 "Needs lacarte.el.
6502 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
6503 ;; (anything 'anything-c-source-lacarte)
6506 ;;;; <Function>
6507 ;;; Emacs functions
6510 (defvar anything-c-source-emacs-functions
6511 '((name . "Emacs Functions")
6512 (candidates . (lambda ()
6513 (let (commands)
6514 (mapatoms (lambda (a)
6515 (if (functionp a)
6516 (push (symbol-name a) commands))))
6517 (sort commands 'string-lessp))))
6518 (type . function)
6519 (requires-pattern . 2))
6520 "Source for completing Emacs functions.")
6521 ;; (anything 'anything-c-source-emacs-functions)
6523 ;;; With abbrev expansion
6524 ;;; Similar to my exec-abbrev-cmd.el
6525 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
6526 (defvar anything-c-function-abbrev-regexp nil
6527 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
6528 Regexp built from the current `anything-pattern' interpreting it
6529 as abbreviation.
6530 Only for internal use.")
6532 (defun anything-c-match-function-by-abbrev (candidate)
6533 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
6535 Abbreviations are made by taking the first character from each
6536 word in the function's name, e.g. \"bb\" is an abbrev for
6537 `bury-buffer', \"stb\" is an abbrev for `anything-c-switch-to-buffer'."
6538 (string-match anything-c-function-abbrev-regexp candidate))
6540 (defvar anything-c-source-emacs-functions-with-abbrevs
6541 (append anything-c-source-emacs-functions
6542 '((match anything-c-match-function-by-abbrev
6543 anything-c-string-match))
6544 '((init
6545 . (lambda ()
6546 (defadvice anything-update
6547 (before anything-c-update-function-abbrev-regexp activate)
6548 (let ((char-list (append anything-pattern nil))
6549 (str "^"))
6550 (dolist (c char-list)
6551 (setq str (concat str (list c) "[^-]*-")))
6552 (setq str (concat (substring str 0 (1- (length str))) "$"))
6553 (setq anything-c-function-abbrev-regexp str))))))))
6554 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
6556 (defvar anything-c-source-advice
6557 '((name . "Function Advice")
6558 (candidates . anything-c-advice-candidates)
6559 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
6560 ;; (real-to-display . anything-c-advice-real-to-display)
6561 (persistent-action . anything-c-advice-persistent-action)
6562 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
6563 ;; (anything 'anything-c-source-advice)
6564 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
6565 ;; (testadvice)
6567 (defun anything-c-advice-candidates ()
6568 (require 'advice)
6569 (loop for (fname) in ad-advised-functions
6570 for function = (intern fname)
6571 append
6572 (loop for class in ad-advice-classes append
6573 (loop for advice in (ad-get-advice-info-field function class)
6574 for enabled = (ad-advice-enabled advice)
6575 collect
6576 (cons (format
6577 "%s %s %s"
6578 (if enabled "Enabled " "Disabled")
6579 (propertize fname 'face 'font-lock-function-name-face)
6580 (ad-make-single-advice-docstring advice class nil))
6581 (list function class advice))))))
6583 (defun anything-c-advice-persistent-action (func-class-advice)
6584 (if current-prefix-arg
6585 (anything-c-advice-toggle func-class-advice)
6586 (describe-function (car func-class-advice))))
6588 (defun anything-c-advice-toggle (func-class-advice)
6589 (destructuring-bind (function class advice) func-class-advice
6590 (cond ((ad-advice-enabled advice)
6591 (ad-advice-set-enabled advice nil)
6592 (message "Disabled"))
6593 (t ;disabled
6594 (ad-advice-set-enabled advice t)
6595 (message "Enabled")))
6596 (ad-activate function)
6597 (and anything-in-persistent-action
6598 (anything-c-advice-update-current-display-string))))
6600 (defun anything-c-advice-update-current-display-string ()
6601 (anything-edit-current-selection
6602 (let ((newword (cond ((looking-at "Disabled") "Enabled")
6603 ((looking-at "Enabled") "Disabled")))
6604 realvalue)
6605 (when newword
6606 (delete-region (point) (progn (forward-word 1) (point)))
6607 (insert newword)))))
6610 ;;;; <Variable>
6611 ;;; Emacs variables
6614 (defvar anything-c-source-emacs-variables
6615 '((name . "Emacs Variables")
6616 (candidates . (lambda ()
6617 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
6618 (type . variable)
6619 (requires-pattern . 2))
6620 "Source for completing Emacs variables.")
6621 ;; (anything 'anything-c-source-emacs-variables)
6624 ;;; Bookmarks
6627 ;; Bind some faces for bookmarks.
6628 (defvar anything-c-bookmarks-face1 'anything-ff-directory)
6629 (defvar anything-c-bookmarks-face2 'anything-ff-file)
6630 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
6632 (eval-when-compile (require 'bookmark))
6633 (defvar anything-c-source-bookmarks
6634 '((name . "Bookmarks")
6635 (init . (lambda ()
6636 (require 'bookmark)))
6637 (candidates . bookmark-all-names)
6638 (type . bookmark))
6639 "See (info \"(emacs)Bookmarks\").")
6640 ;; (anything 'anything-c-source-bookmarks)
6642 ;;; bookmark-set
6643 (defvar anything-c-source-bookmark-set
6644 '((name . "Set Bookmark")
6645 (dummy)
6646 (action . bookmark-set))
6647 "See (info \"(emacs)Bookmarks\").")
6648 ;; (anything 'anything-c-source-bookmark-set)
6650 ;;; Visible Bookmarks
6651 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
6654 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
6655 (defvar anything-c-source-bm
6656 '((name . "Visible Bookmarks")
6657 (init . anything-c-bm-init)
6658 (candidates-in-buffer)
6659 (type . line))
6660 "Needs bm.el.
6662 http://www.nongnu.org/bm/")
6664 (defun anything-c-bm-init ()
6665 "Init function for `anything-c-source-bm'."
6666 (when (require 'bm nil t)
6667 (with-no-warnings
6668 (let ((bookmarks (bm-lists))
6669 (buf (anything-candidate-buffer 'global)))
6670 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
6671 '< :key 'overlay-start))
6672 (let ((start (overlay-start bm))
6673 (end (overlay-end bm))
6674 (annotation (or (overlay-get bm 'annotation) "")))
6675 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
6676 (let ((str (format "%5d: [%s]: %s\n"
6677 (line-number-at-pos start)
6678 annotation
6679 (buffer-substring start (1- end)))))
6680 (with-current-buffer buf (insert str))))))))))
6682 ;;; Special bookmarks
6683 (defvar anything-c-source-bookmarks-ssh
6684 '((name . "Bookmarks-ssh")
6685 (init . (lambda ()
6686 (require 'bookmark)))
6687 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
6688 (type . bookmark))
6689 "See (info \"(emacs)Bookmarks\").")
6690 ;; (anything 'anything-c-source-bookmarks-ssh)
6692 (defvar anything-c-source-bookmarks-su
6693 '((name . "Bookmarks-root")
6694 (init . (lambda ()
6695 (require 'bookmark)))
6696 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
6697 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
6699 (type . bookmark))
6700 "See (info \"(emacs)Bookmarks\").")
6701 ;; (anything 'anything-c-source-bookmarks-su)
6703 (defvar anything-c-source-bookmarks-local
6704 '((name . "Bookmarks-Local")
6705 (init . (lambda ()
6706 (require 'bookmark)))
6707 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
6708 (filtered-candidate-transformer
6709 anything-c-adaptive-sort
6710 anything-c-highlight-bookmark)
6711 (type . bookmark))
6712 "See (info \"(emacs)Bookmarks\").")
6713 ;; (anything 'anything-c-source-bookmarks-local)
6715 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
6716 (let* ((lis-all (bookmark-all-names))
6717 (lis-loc (cond (local (loop for i in lis-all
6718 unless (string-match "^(ssh)\\|^(su)" i)
6719 collect i))
6720 (su (loop for i in lis-all
6721 when (string-match "^(su)" i)
6722 collect i))
6723 (sudo (loop for i in lis-all
6724 when (string-match "^(sudo)" i)
6725 collect i))
6726 (ssh (loop for i in lis-all
6727 when (string-match "^(ssh)" i)
6728 collect i)))))
6729 (sort lis-loc 'string-lessp)))
6731 (defun anything-c-bookmark-root-logged-p ()
6732 (catch 'break
6733 (dolist (i (mapcar #'buffer-name (buffer-list)))
6734 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
6735 (throw 'break t)))))
6737 (defun anything-c-highlight-bookmark-su (files source)
6738 (if (anything-c-bookmark-root-logged-p)
6739 (anything-c-highlight-bookmark files source)
6740 (anything-c-highlight-not-logged files source)))
6742 (defun anything-c-highlight-not-logged (files source)
6743 (loop for i in files
6744 collect (propertize i 'face anything-c-bookmarks-face3)))
6746 (defun anything-c-highlight-bookmark (bookmarks source)
6747 "Used as `candidate-transformer' to colorize bookmarks.
6748 Work both with standard Emacs bookmarks and bookmark-extensions.el."
6749 (loop for i in bookmarks
6750 for isfile = (bookmark-get-filename i)
6751 for bufp = (and (fboundp 'bmkext-get-buffer-name)
6752 (bmkext-get-buffer-name i))
6753 for handlerp = (and (fboundp 'bookmark-get-handler)
6754 (bookmark-get-handler i))
6755 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
6756 (bmkext-w3m-bookmark-p i))
6757 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
6758 (bmkext-gnus-bookmark-p i))
6759 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
6760 (bmkext-man-bookmark-p i))
6761 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
6762 (bmkext-woman-bookmark-p i))
6763 for handlerp = (bookmark-get-handler i)
6764 for isannotation = (bookmark-get-annotation i)
6765 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
6766 for isinfo = (eq handlerp 'Info-bookmark-jump)
6767 ;; Add a * if bookmark have annotation
6768 if (and isannotation (not (string-equal isannotation "")))
6769 do (setq i (concat "*" i))
6770 collect (cond (;; info buffers
6771 isinfo
6772 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
6773 (;; w3m buffers
6774 isw3m
6775 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
6776 (;; gnus buffers
6777 isgnus
6778 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
6779 (;; Man Woman
6780 (or iswoman isman)
6781 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
6782 (;; Addressbook
6783 isabook
6784 (propertize i 'face '((:foreground "Tomato"))))
6785 (;; directories
6786 (and isfile (file-directory-p isfile))
6787 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
6788 (;; regular files
6790 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
6794 ;;; Sources to filter bookmark-extensions bookmarks.
6797 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
6798 ;; If you want to enable google-maps in addressbook you will need
6799 ;; Julien Danjou google-maps-el package available here:
6800 ;; http://julien.danjou.info/google-maps-el.html
6802 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
6803 "Return a filtered `bookmark-alist' sorted alphabetically."
6804 (loop
6805 with alist = (if args
6806 (apply #'(lambda (x) (funcall fn x)) args)
6807 (funcall fn))
6808 for i in alist
6809 for b = (car i)
6810 collect b into sa
6811 finally return (sort sa 'string-lessp)))
6813 ;;; Addressbook.
6816 (defvar anything-c-source-bmkext-addressbook
6817 '((name . "Bookmark Addressbook")
6818 (init . (lambda ()
6819 (require 'bookmark-extensions)
6820 (bookmark-maybe-load-default-file)))
6821 (candidates . anything-c-bmkext-addressbook-setup-alist)
6822 (persistent-action
6823 . (lambda (candidate)
6824 (let ((bmk (anything-bookmark-get-bookmark-from-name
6825 candidate)))
6826 (bookmark--jump-via bmk 'pop-to-buffer))))
6827 (persistent-help . "Show contact - Prefix with C-u to append")
6828 (filtered-candidate-transformer
6829 anything-c-adaptive-sort
6830 anything-c-highlight-bookmark)
6831 (action . (("Show Contact(s)"
6832 . (lambda (candidate)
6833 (let* ((contacts (anything-marked-candidates))
6834 (current-prefix-arg (or anything-current-prefix-arg
6835 (> (length contacts) 1))))
6836 (bookmark-jump
6837 (anything-bookmark-get-bookmark-from-name (car contacts)))
6838 (anything-aif (cdr contacts)
6839 (loop for bmk in it do
6840 (bookmark-jump
6841 (anything-bookmark-get-bookmark-from-name bmk)))))))
6842 ("Send Mail"
6843 . (lambda (candidate)
6844 (let* ((contacts (anything-marked-candidates))
6845 (bmk (anything-bookmark-get-bookmark-from-name
6846 (car contacts)))
6847 (append (message-buffers)))
6848 (if append
6849 (addressbook-set-mail-buffer1 bmk 'append)
6850 (addressbook-set-mail-buffer1 bmk))
6851 (setq contacts (cdr contacts))
6852 (when contacts
6853 (loop for bmk in contacts do
6854 (addressbook-set-mail-buffer1 bmk 'append))))))
6855 ("Edit Bookmark"
6856 . (lambda (candidate)
6857 (let ((bmk (anything-bookmark-get-bookmark-from-name
6858 candidate)))
6859 (addressbook-bookmark-edit
6860 (assoc bmk bookmark-alist)))))
6861 ("Insert Email at point"
6862 . (lambda (candidate)
6863 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6864 candidate))
6865 (mlist (split-string
6866 (assoc-default
6867 'email (assoc bmk bookmark-alist))
6868 ", ")))
6869 (insert
6870 (if (> (length mlist) 1)
6871 (anything-comp-read
6872 "Insert Mail Address: " mlist :must-match t)
6873 (car mlist))))))
6874 ("Show annotation"
6875 . (lambda (candidate)
6876 (let ((bmk (anything-bookmark-get-bookmark-from-name
6877 candidate)))
6878 (bookmark-show-annotation bmk))))
6879 ("Edit annotation"
6880 . (lambda (candidate)
6881 (let ((bmk (anything-bookmark-get-bookmark-from-name
6882 candidate)))
6883 (bookmark-edit-annotation bmk))))
6884 ("Show Google map"
6885 . (lambda (candidate)
6886 (let* ((bmk (anything-bookmark-get-bookmark-from-name
6887 candidate))
6888 (full-bmk (assoc bmk bookmark-alist)))
6889 (addressbook-google-map full-bmk))))))))
6892 (defun anything-c-bmkext-addressbook-setup-alist ()
6893 "Specialized filter function for bookmarks w3m."
6894 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
6896 ;; W3m bookmarks from bookmark-extensions.
6897 (defvar anything-c-source-bookmark-w3m
6898 '((name . "Bookmark W3m")
6899 (init . (lambda ()
6900 (require 'bookmark-extensions)
6901 (bookmark-maybe-load-default-file)))
6902 (candidates . anything-c-bookmark-w3m-setup-alist)
6903 (filtered-candidate-transformer
6904 anything-c-adaptive-sort
6905 anything-c-highlight-bookmark)
6906 (type . bookmark)))
6907 ;; (anything 'anything-c-source-bookmark-w3m)
6909 (defun anything-c-bookmark-w3m-setup-alist ()
6910 "Specialized filter function for bookmarks w3m."
6911 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
6913 ;; Images
6914 (defvar anything-c-source-bookmark-images
6915 '((name . "Bookmark Images")
6916 (init . (lambda ()
6917 (require 'bookmark-extensions)
6918 (bookmark-maybe-load-default-file)))
6919 (candidates . anything-c-bookmark-images-setup-alist)
6920 (filtered-candidate-transformer
6921 anything-c-adaptive-sort
6922 anything-c-highlight-bookmark)
6923 (type . bookmark)))
6924 ;; (anything 'anything-c-source-bookmark-images)
6926 (defun anything-c-bookmark-images-setup-alist ()
6927 "Specialized filter function for images bookmarks."
6928 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
6930 ;; Woman Man
6931 (defvar anything-c-source-bookmark-man
6932 '((name . "Bookmark Woman&Man")
6933 (init . (lambda ()
6934 (require 'bookmark-extensions)
6935 (bookmark-maybe-load-default-file)))
6936 (candidates . anything-c-bookmark-man-setup-alist)
6937 (filtered-candidate-transformer
6938 anything-c-adaptive-sort
6939 anything-c-highlight-bookmark)
6940 (type . bookmark)))
6941 ;; (anything 'anything-c-source-bookmark-man)
6943 (defun anything-c-bookmark-man-setup-alist ()
6944 "Specialized filter function for bookmarks w3m."
6945 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
6946 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
6948 ;; Gnus
6949 (defvar anything-c-source-bookmark-gnus
6950 '((name . "Bookmark Gnus")
6951 (init . (lambda ()
6952 (require 'bookmark-extensions)
6953 (bookmark-maybe-load-default-file)))
6954 (candidates . anything-c-bookmark-gnus-setup-alist)
6955 (filtered-candidate-transformer
6956 anything-c-adaptive-sort
6957 anything-c-highlight-bookmark)
6958 (type . bookmark)))
6959 ;; (anything 'anything-c-source-bookmark-gnus)
6961 (defun anything-c-bookmark-gnus-setup-alist ()
6962 "Specialized filter function for bookmarks gnus."
6963 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
6965 ;; Info
6966 (defvar anything-c-source-bookmark-info
6967 '((name . "Bookmark Info")
6968 (init . (lambda ()
6969 (require 'bookmark-extensions)
6970 (bookmark-maybe-load-default-file)))
6971 (candidates . anything-c-bookmark-info-setup-alist)
6972 (filtered-candidate-transformer
6973 anything-c-adaptive-sort
6974 anything-c-highlight-bookmark)
6975 (type . bookmark)))
6976 ;; (anything 'anything-c-source-bookmark-info)
6978 (defun anything-c-bookmark-info-setup-alist ()
6979 "Specialized filter function for bookmarks info."
6980 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
6982 ;; Local Files&directories
6983 (defvar anything-c-source-bookmark-files&dirs
6984 '((name . "Bookmark Files&Directories")
6985 (init . (lambda ()
6986 (require 'bookmark-extensions)
6987 (bookmark-maybe-load-default-file)))
6988 (candidates . anything-c-bookmark-local-files-setup-alist)
6989 (filtered-candidate-transformer
6990 anything-c-adaptive-sort
6991 anything-c-highlight-bookmark)
6992 (type . bookmark)))
6993 ;; (anything 'anything-c-source-bookmark-files&dirs)
6995 (defun anything-c-bookmark-local-files-setup-alist ()
6996 "Specialized filter function for bookmarks locals files."
6997 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
6999 ;; Su Files&directories
7000 (defvar anything-c-source-bookmark-su-files&dirs
7001 '((name . "Bookmark Root-Files&Directories")
7002 (init . (lambda ()
7003 (require 'bookmark-extensions)
7004 (bookmark-maybe-load-default-file)))
7005 (candidates . anything-c-bookmark-su-files-setup-alist)
7006 (filtered-candidate-transformer
7007 anything-c-adaptive-sort
7008 anything-c-highlight-bookmark-su)
7009 (type . bookmark)))
7010 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
7012 (defun anything-c-bookmark-su-files-setup-alist ()
7013 "Specialized filter function for bookmarks su/sudo files."
7014 (declare (special bmkext-su-or-sudo-regexp))
7015 (loop
7016 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
7017 for i in l
7018 for isfile = (bookmark-get-filename i)
7019 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
7020 (save-match-data
7021 (string-match tramp-file-name-regexp isfile)))
7022 for issu = (and istramp
7023 (string-match bmkext-su-or-sudo-regexp isfile))
7024 if issu
7025 collect i))
7027 ;; Ssh Files&directories
7028 (defvar anything-c-source-bookmark-ssh-files&dirs
7029 '((name . "Bookmark Ssh-Files&Directories")
7030 (init . (lambda ()
7031 (require 'bookmark-extensions)
7032 (bookmark-maybe-load-default-file)))
7033 (candidates . anything-c-bookmark-ssh-files-setup-alist)
7034 (filtered-candidate-transformer . anything-c-adaptive-sort)
7035 (type . bookmark)))
7036 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
7038 (defun anything-c-bookmark-ssh-files-setup-alist ()
7039 "Specialized filter function for bookmarks ssh files."
7040 (loop
7041 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
7042 for i in l
7043 for isfile = (bookmark-get-filename i)
7044 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
7045 (save-match-data
7046 (string-match tramp-file-name-regexp isfile)))
7047 for isssh = (and istramp
7048 (string-match "/ssh:" isfile))
7049 if isssh
7050 collect i))
7054 ;;; Firefox bookmarks
7057 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
7058 ;; (only for firefox versions >=3)
7059 ;; To achieve that, open about:config in firefox and double click on this line to enable value
7060 ;; to true:
7061 ;; user_pref("browser.bookmarks.autoExportHTML", false);
7062 ;; You should have now:
7063 ;; user_pref("browser.bookmarks.autoExportHTML", true);
7065 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
7066 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
7068 (defun anything-get-firefox-user-init-dir ()
7069 "Guess the default Firefox user directory name."
7070 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
7071 (moz-user-dir
7072 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
7073 (goto-char (point-min))
7074 (prog1
7075 (when (search-forward "Path=" nil t)
7076 (buffer-substring-no-properties (point) (point-at-eol)))
7077 (kill-buffer)))))
7078 (file-name-as-directory (concat moz-dir moz-user-dir))))
7080 (defun anything-guess-firefox-bookmark-file ()
7081 "Return the path of the Firefox bookmarks file."
7082 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
7084 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
7085 "Parse html bookmark FILE and return an alist with (title . url) as elements."
7086 (let (bookmarks-alist url title)
7087 (with-temp-buffer
7088 (insert-file-contents file)
7089 (goto-char (point-min))
7090 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
7091 (forward-line 0)
7092 (when (re-search-forward url-regexp nil t)
7093 (setq url (match-string 0)))
7094 (when (re-search-forward bmk-regexp nil t)
7095 (setq title (match-string 1)))
7096 (push (cons title url) bookmarks-alist)
7097 (forward-line)))
7098 (nreverse bookmarks-alist)))
7100 (defvar anything-c-firefox-bookmarks-alist nil)
7101 (defvar anything-c-source-firefox-bookmarks
7102 '((name . "Firefox Bookmarks")
7103 (init . (lambda ()
7104 (setq anything-c-firefox-bookmarks-alist
7105 (anything-html-bookmarks-to-alist
7106 (anything-guess-firefox-bookmark-file)
7107 anything-firefox-bookmark-url-regexp
7108 anything-firefox-bookmarks-regexp))))
7109 (candidates . (lambda ()
7110 (mapcar #'car anything-c-firefox-bookmarks-alist)))
7111 (filtered-candidate-transformer
7112 anything-c-adaptive-sort
7113 anything-c-highlight-firefox-bookmarks)
7114 (action . (("Browse Url Firefox"
7115 . (lambda (candidate)
7116 (browse-url-firefox
7117 (anything-c-firefox-bookmarks-get-value candidate))))
7118 ("Browse Url w3m"
7119 . (lambda (candidate)
7120 (w3m-browse-url
7121 (anything-c-firefox-bookmarks-get-value candidate))))
7122 ("Copy Url"
7123 . (lambda (elm)
7124 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
7126 ;; (anything 'anything-c-source-firefox-bookmarks)
7128 (defun anything-c-firefox-bookmarks-get-value (elm)
7129 (assoc-default elm anything-c-firefox-bookmarks-alist))
7131 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
7132 (loop for i in bookmarks
7133 collect (propertize
7134 i 'face '((:foreground "YellowGreen"))
7135 'help-echo (anything-c-firefox-bookmarks-get-value i))))
7139 ;;; W3m bookmark - anything interface.
7142 ;; Some users have the emacs-w3m library in load-path
7143 ;; without having the w3m executable :-;
7144 ;; So check if w3m program is present before trying to load
7145 ;; emacs-w3m.
7146 (eval-when-compile
7147 (when (executable-find "w3m")
7148 (require 'w3m-bookmark nil t)))
7150 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
7151 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
7152 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
7153 (defvar anything-c-w3m-bookmarks-alist nil)
7154 (defvar anything-c-source-w3m-bookmarks
7155 '((name . "W3m Bookmarks")
7156 (init . (lambda ()
7157 (setq anything-c-w3m-bookmarks-alist
7158 (anything-html-bookmarks-to-alist
7159 w3m-bookmark-file
7160 anything-w3m-bookmark-url-regexp
7161 anything-w3m-bookmarks-regexp))))
7162 (candidates . (lambda ()
7163 (mapcar #'car anything-c-w3m-bookmarks-alist)))
7164 (filtered-candidate-transformer
7165 anything-c-adaptive-sort
7166 anything-c-highlight-w3m-bookmarks)
7167 (action . (("Browse Url"
7168 . (lambda (candidate)
7169 (anything-c-w3m-browse-bookmark candidate)))
7170 ("Copy Url"
7171 . (lambda (elm)
7172 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
7173 ("Browse Url Firefox"
7174 . (lambda (candidate)
7175 (anything-c-w3m-browse-bookmark candidate t)))
7176 ("Delete Bookmark"
7177 . (lambda (candidate)
7178 (anything-c-w3m-delete-bookmark candidate)))
7179 ("Rename Bookmark"
7180 . (lambda (candidate)
7181 (anything-c-w3m-rename-bookmark candidate)))))
7182 (persistent-action . (lambda (candidate)
7183 (if current-prefix-arg
7184 (anything-c-w3m-browse-bookmark candidate t)
7185 (anything-c-w3m-browse-bookmark candidate nil t))))
7186 (persistent-help . "Open URL with emacs-w3m in new tab / \
7187 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
7188 "Needs w3m and emacs-w3m.
7190 http://w3m.sourceforge.net/
7191 http://emacs-w3m.namazu.org/")
7193 ;; (anything 'anything-c-source-w3m-bookmarks)
7195 (defun anything-c-w3m-bookmarks-get-value (elm)
7196 (replace-regexp-in-string
7197 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
7199 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
7200 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
7201 (arg (and (eq fn 'w3m-browse-url) new-tab)))
7202 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
7204 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
7205 (loop for i in bookmarks
7206 collect (propertize
7207 i 'face 'anything-w3m-bookmarks-face
7208 'help-echo (anything-c-w3m-bookmarks-get-value i))))
7211 (defun anything-c-w3m-delete-bookmark (elm)
7212 "Delete w3m bookmark from `w3m-bookmark-file'."
7213 (with-current-buffer
7214 (find-file-literally w3m-bookmark-file)
7215 (goto-char (point-min))
7216 (when (re-search-forward elm nil t)
7217 (beginning-of-line)
7218 (delete-region (point)
7219 (line-end-position))
7220 (delete-blank-lines))
7221 (save-buffer)
7222 (kill-buffer)))
7224 (defun anything-c-w3m-rename-bookmark (elm)
7225 "Rename w3m bookmark in `w3m-bookmark-file'."
7226 (let* ((old-title (replace-regexp-in-string ">" "" elm))
7227 (new-title (read-string "NewTitle: " old-title)))
7228 (with-current-buffer
7229 (find-file-literally w3m-bookmark-file)
7230 (goto-char (point-min))
7231 (when (re-search-forward (concat elm "<") nil t)
7232 (goto-char (1- (point)))
7233 (delete-char (- (length old-title)))
7234 (insert new-title))
7235 (save-buffer)
7236 (kill-buffer))))
7239 ;;;; <Library>
7240 ;;; Elisp library scan
7243 (defvar anything-c-source-elisp-library-scan
7244 '((name . "Elisp libraries (Scan)")
7245 (init . (anything-c-elisp-library-scan-init))
7246 (candidates-in-buffer)
7247 (action ("Find library"
7248 . (lambda (candidate) (find-file (find-library-name candidate))))
7249 ("Find library other window"
7250 . (lambda (candidate)
7251 (find-file-other-window (find-library-name candidate))))
7252 ("Load library"
7253 . (lambda (candidate) (load-library candidate))))))
7254 ;; (anything 'anything-c-source-elisp-library-scan)
7256 (defun anything-c-elisp-library-scan-init ()
7257 "Init anything buffer status."
7258 (let ((anything-buffer (anything-candidate-buffer 'global))
7259 (library-list (anything-c-elisp-library-scan-list)))
7260 (with-current-buffer anything-buffer
7261 (dolist (library library-list)
7262 (insert (format "%s\n" library))))))
7264 (defun anything-c-elisp-library-scan-list (&optional dirs string)
7265 "Do completion for file names passed to `locate-file'.
7266 DIRS is directory to search path.
7267 STRING is string to match."
7268 ;; Use `load-path' as path when ignore `dirs'.
7269 (or dirs (setq dirs load-path))
7270 ;; Init with blank when ignore `string'.
7271 (or string (setq string ""))
7272 ;; Get library list.
7273 (let ((string-dir (file-name-directory string))
7274 ;; File regexp that suffix match `load-file-rep-suffixes'.
7275 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
7276 name
7277 names)
7278 (dolist (dir dirs)
7279 (unless dir
7280 (setq dir default-directory))
7281 (if string-dir
7282 (setq dir (expand-file-name string-dir dir)))
7283 (when (file-directory-p dir)
7284 (dolist (file (file-name-all-completions
7285 (file-name-nondirectory string) dir))
7286 ;; Suffixes match `load-file-rep-suffixes'.
7287 (setq name (if string-dir (concat string-dir file) file))
7288 (if (string-match match-regexp name)
7289 (add-to-list 'names name)))))
7290 names))
7293 ;;;; <Programming>
7297 ;;; Imenu
7300 (defvar anything-c-imenu-delimiter " / ")
7302 (defvar anything-c-imenu-index-filter nil)
7303 (make-variable-buffer-local 'anything-c-imenu-index-filter)
7305 (defvar anything-c-cached-imenu-alist nil)
7306 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
7308 (defvar anything-c-cached-imenu-candidates nil)
7309 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
7311 (defvar anything-c-cached-imenu-tick nil)
7312 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
7314 (eval-when-compile (require 'imenu))
7315 (setq imenu-auto-rescan t)
7317 (defun anything-imenu-create-candidates (entry)
7318 "Create candidates with ENTRY."
7319 (if (listp (cdr entry))
7320 (mapcan
7321 (lambda (sub)
7322 (if (consp (cdr sub))
7323 (mapcar
7324 (lambda (subentry)
7325 (concat (car entry) anything-c-imenu-delimiter subentry))
7326 (anything-imenu-create-candidates sub))
7327 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
7328 (cdr entry))
7329 (list entry)))
7331 (defvar anything-c-source-imenu
7332 '((name . "Imenu")
7333 (init . (lambda () (require 'imenu)))
7334 (candidates . anything-c-imenu-candidates)
7335 (persistent-action . (lambda (elm)
7336 (anything-c-imenu-default-action elm)
7337 (unless (fboundp 'semantic-imenu-tag-overlay)
7338 (anything-match-line-color-current-line))))
7339 (persistent-help . "Show this entry")
7340 (action . anything-c-imenu-default-action))
7341 "See (info \"(emacs)Imenu\")")
7343 ;; (anything 'anything-c-source-imenu)
7345 (defun anything-c-imenu-candidates ()
7346 (with-anything-current-buffer
7347 (let ((tick (buffer-modified-tick)))
7348 (if (eq anything-c-cached-imenu-tick tick)
7349 anything-c-cached-imenu-candidates
7350 (setq imenu--index-alist nil)
7351 (setq anything-c-cached-imenu-tick tick
7352 anything-c-cached-imenu-candidates
7353 (ignore-errors
7354 (mapcan
7355 'anything-imenu-create-candidates
7356 (setq anything-c-cached-imenu-alist
7357 (let ((index (imenu--make-index-alist)))
7358 (if anything-c-imenu-index-filter
7359 (funcall anything-c-imenu-index-filter index)
7360 index))))))
7361 (setq anything-c-cached-imenu-candidates
7362 (mapcar #'(lambda (x)
7363 (if (stringp x)
7365 (car x)))
7366 anything-c-cached-imenu-candidates))))))
7368 (setq imenu-default-goto-function 'imenu-default-goto-function)
7369 (defun anything-c-imenu-default-action (elm)
7370 "The default action for `anything-c-source-imenu'."
7371 (let ((path (split-string elm anything-c-imenu-delimiter))
7372 (alist anything-c-cached-imenu-alist))
7373 (dolist (elm path)
7374 (setq alist (assoc elm alist)))
7375 (imenu alist)))
7379 ;;; Ctags
7382 (defvar anything-c-ctags-modes
7383 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
7384 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
7385 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
7387 (defun anything-c-source-ctags-init ()
7388 (when (and buffer-file-name
7389 (memq major-mode anything-c-ctags-modes)
7390 (anything-current-buffer-is-modified))
7391 (with-current-buffer (anything-candidate-buffer 'local)
7392 (call-process-shell-command
7393 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
7394 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
7395 anything-buffer-file-name)
7396 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
7397 nil (current-buffer))
7398 (goto-char (point-min))
7399 (forward-line 2)
7400 (delete-region (point-min) (point))
7401 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
7402 for lineno-start = (point)
7403 for lineno = (buffer-substring
7404 lineno-start
7405 (1- (search-forward "," (point-at-eol) t)))
7407 (beginning-of-line)
7408 (insert (format "%5s:" lineno))
7409 (search-forward "\177" (point-at-eol) t)
7410 (delete-region (1- (point)) (point-at-eol))
7411 (forward-line 1)))))
7413 (defvar anything-c-source-ctags
7414 '((name . "Exuberant ctags")
7415 (init . anything-c-source-ctags-init)
7416 (candidates-in-buffer)
7417 (adjust)
7418 (type . line))
7419 "Needs Exuberant Ctags.
7421 http://ctags.sourceforge.net/")
7422 ;; (anything 'anything-c-source-ctags)
7425 ;;; Etags
7428 ;; anything-etags.el is deprecated, if this file is found,
7429 ;; warn user at compile time.
7430 (eval-when-compile
7431 (when (locate-library "anything-etags.el")
7432 (display-warning
7433 '(anything-config)
7434 "You are using obsolete library `anything-etags.el' and should remove it."
7435 :warning)))
7437 (defvar anything-c-etags-tag-file-dir nil
7438 "Etags file directory.")
7439 (defvar anything-c-etags-mtime-alist nil
7440 "Store the last modification time of etags files here.")
7441 (defvar anything-c-etags-cache (make-hash-table :test 'equal)
7442 "Cache content of etags files used here for faster access.")
7444 (defun anything-c-etags-get-tag-file (&optional directory)
7445 "Return the path of etags file if found."
7446 ;; Get tag file from `default-directory' or upper directory.
7447 (let ((current-dir (anything-c-etags-find-tag-file-directory
7448 (or directory default-directory))))
7449 ;; Return nil if not find tag file.
7450 (when current-dir
7451 ;; Set tag file directory.
7452 (setq anything-c-etags-tag-file-dir current-dir)
7453 (expand-file-name anything-c-etags-tag-file-name current-dir))))
7455 (defun anything-c-etags-find-tag-file-directory (current-dir)
7456 "Try to find the directory containing tag file.
7457 If not found in CURRENT-DIR search in upper directory."
7458 (flet ((file-exists? (dir)
7459 (let ((tag-path (expand-file-name
7460 anything-c-etags-tag-file-name dir)))
7461 (and (stringp tag-path)
7462 (file-exists-p tag-path)
7463 (file-readable-p tag-path)))))
7464 (loop with count = 0
7465 until (file-exists? current-dir)
7466 ;; Return nil if outside the value of
7467 ;; `anything-c-etags-tag-file-search-limit'.
7468 if (= count anything-c-etags-tag-file-search-limit)
7469 do (return nil)
7470 ;; Or search upper directories.
7471 else
7472 do (incf count)
7473 (setq current-dir (expand-file-name (concat current-dir "../")))
7474 finally return current-dir)))
7476 (defun anything-c-source-etags-header-name (x)
7477 "Create header name for this anything etags session."
7478 (concat "Etags in "
7479 (with-anything-current-buffer
7480 (anything-c-etags-get-tag-file))))
7482 (defmacro anything-c-etags-create-buffer (file)
7483 "Create the `anything-buffer' based on contents of etags tag FILE."
7484 `(let* ((tag-fname ,file)
7486 (split (with-current-buffer (find-file-noselect tag-fname)
7487 (prog1
7488 (split-string (buffer-string) "\n" 'omit-nulls)
7489 (setq max (line-number-at-pos (point-max)))
7490 (kill-buffer))))
7491 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
7492 (loop
7493 with fname
7494 with cand
7495 for i in split for count from 0
7496 for elm = (unless (string-match "^\x0c" i)
7497 (anything-aif (string-match "\177" i)
7498 (substring i 0 it)
7500 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
7501 (setq fname (match-string 1 elm)))
7502 (elm (setq cand (concat fname ": " elm)))
7503 (t (setq cand nil)))
7504 when cand do (progn
7505 (insert (concat cand "\n"))
7506 (progress-reporter-update progress-reporter count)))))
7508 (defun anything-c-etags-init ()
7509 "Feed `anything-buffer' using `anything-c-etags-cache' or tag file.
7510 If no entry in cache, create one."
7511 (let ((tagfile (anything-c-etags-get-tag-file)))
7512 (when tagfile
7513 (with-current-buffer (anything-candidate-buffer 'global)
7514 (anything-aif (gethash tagfile anything-c-etags-cache)
7515 ;; An entry is present in cache, insert it.
7516 (insert it)
7517 ;; No entry, create a new buffer using content of tag file (slower).
7518 (anything-c-etags-create-buffer tagfile)
7519 ;; Store content of buffer in cache.
7520 (puthash tagfile (buffer-string) anything-c-etags-cache)
7521 ;; Store or set the last modification of tag file.
7522 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
7523 ;; If an entry exists modify it.
7524 (setcdr it (anything-c-etags-mtime tagfile))
7525 ;; No entry create a new one.
7526 (add-to-list 'anything-c-etags-mtime-alist
7527 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
7529 (defvar anything-c-source-etags-select
7530 '((name . "Etags")
7531 (header-name . anything-c-source-etags-header-name)
7532 (init . anything-c-etags-init)
7533 (candidates-in-buffer)
7534 (search . (anything-c-etags-search-fn))
7535 (mode-line . anything-etags-mode-line-string)
7536 (action . anything-c-etags-default-action)
7537 (persistent-action . (lambda (candidate)
7538 (anything-c-etags-default-action candidate)
7539 (anything-match-line-color-current-line))))
7540 "Anything source for Etags.")
7542 (defun anything-c-etags-search-fn (pattern bound noerror)
7543 "Search function for `anything-c-source-etags-select'."
7544 (re-search-forward
7545 (if anything-c-etags-use-regexp-search (concat "\\_<" pattern) pattern)
7546 bound noerror))
7548 (defun anything-c-etags-default-action (candidate)
7549 "Anything default action to jump to an etags entry."
7550 (let* ((split (split-string candidate ": "))
7551 (fname (expand-file-name
7552 (car split) anything-c-etags-tag-file-dir))
7553 (elm (cadr split)))
7554 (find-file fname)
7555 (goto-char (point-min))
7556 (search-forward elm nil t)
7557 (goto-char (match-beginning 0))))
7559 (defun anything-c-etags-mtime (file)
7560 "Last modification time of etags tag FILE."
7561 (cadr (nth 5 (file-attributes file))))
7563 (defun anything-c-etags-file-modified-p (file)
7564 "Check if tag FILE have been modified in this session.
7565 If FILE is nil return nil."
7566 (let ((last-modif (and file
7567 (assoc-default file anything-c-etags-mtime-alist))))
7568 (and last-modif
7569 (/= last-modif (anything-c-etags-mtime file)))))
7573 ;;; Semantic
7576 (defvar anything-semantic-candidates nil)
7578 (defun anything-semantic-construct-candidates (tags depth)
7579 (when (require 'semantic nil t)
7580 (apply
7581 'append
7582 (mapcar
7583 (lambda (tag)
7584 (if (listp tag)
7585 (let ((type (semantic-tag-type tag))
7586 (class (semantic-tag-class tag)))
7587 (if (or (and (stringp type)
7588 (or (string= type "class")
7589 (string= type "namespace")))
7590 (eq class 'function)
7591 (eq class 'variable))
7592 (cons (cons (concat (make-string (* depth 2) ?\s)
7593 (semantic-format-tag-summarize tag nil t))
7594 tag)
7595 (anything-semantic-construct-candidates
7596 (semantic-tag-components tag) (1+ depth)))))))
7597 tags))))
7599 (defun anything-semantic-default-action (candidate)
7600 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
7601 (semantic-go-to-tag tag)))
7603 (defvar anything-c-source-semantic
7604 '((name . "Semantic Tags")
7605 (init . (lambda ()
7606 (setq anything-semantic-candidates
7607 (ignore-errors (anything-semantic-construct-candidates
7608 (semantic-fetch-tags) 0)))))
7609 (candidates . (lambda ()
7610 (if anything-semantic-candidates
7611 (mapcar 'car anything-semantic-candidates))))
7612 (persistent-action . (lambda (elm)
7613 (anything-semantic-default-action elm)
7614 (anything-match-line-color-current-line)))
7615 (persistent-help . "Show this entry")
7616 (action . anything-semantic-default-action)
7617 "Needs semantic in CEDET.
7619 http://cedet.sourceforge.net/semantic.shtml
7620 http://cedet.sourceforge.net/"))
7622 ;; (anything 'anything-c-source-semantic)
7625 ;;; Anything interface of `simple-call-tree.el'.
7627 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el>
7629 ;; Function is called by
7630 (defvar anything-c-source-simple-call-tree-functions-callers
7631 '((name . "Function is called by")
7632 (init . anything-c-simple-call-tree-functions-callers-init)
7633 (multiline)
7634 (candidates . anything-c-simple-call-tree-candidates)
7635 (persistent-action . anything-c-simple-call-tree-persistent-action)
7636 (persistent-help . "Show function definitions by rotation")
7637 (action ("Find definition selected by persistent-action" .
7638 anything-c-simple-call-tree-find-definition)))
7639 "Needs simple-call-tree.el.
7640 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7642 (defvar anything-c-simple-call-tree-tick nil)
7643 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
7644 (defun anything-c-simple-call-tree-analyze-maybe ()
7645 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
7646 (simple-call-tree-analyze)
7647 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
7649 (defun anything-c-simple-call-tree-init-base (function message)
7650 (require 'simple-call-tree)
7651 (with-no-warnings
7652 (when (anything-current-buffer-is-modified)
7653 (anything-c-simple-call-tree-analyze-maybe)
7654 (let ((list (funcall function simple-call-tree-alist)))
7655 (with-current-buffer (anything-candidate-buffer 'local)
7656 (dolist (entry list)
7657 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
7658 (insert (car entry) message
7659 (if (string= funcs " ")
7660 " no functions."
7661 funcs)
7662 "\n\n"))))))))
7664 (defun anything-c-simple-call-tree-functions-callers-init ()
7665 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
7666 " is called by\n"))
7668 (defun anything-c-simple-call-tree-candidates ()
7669 (with-current-buffer (anything-candidate-buffer)
7670 (split-string (buffer-string) "\n\n")))
7672 (defvar anything-c-simple-call-tree-related-functions nil)
7673 (defvar anything-c-simple-call-tree-function-index 0)
7674 (defun anything-c-simple-call-tree-persistent-action (candidate)
7675 (unless (eq last-command 'anything-execute-persistent-action)
7676 (setq anything-c-simple-call-tree-related-functions
7677 (delete "no functions."
7678 (split-string
7679 (replace-regexp-in-string " \\| is called by\\| calls "
7680 "" candidate)
7681 "\n")))
7682 (setq anything-c-simple-call-tree-function-index -1))
7683 (incf anything-c-simple-call-tree-function-index)
7684 (anything-c-simple-call-tree-find-definition candidate))
7686 (defun anything-c-simple-call-tree-find-definition (candidate)
7687 (find-function
7688 (intern
7689 (nth (mod anything-c-simple-call-tree-function-index
7690 (length anything-c-simple-call-tree-related-functions))
7691 anything-c-simple-call-tree-related-functions))))
7693 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
7695 ;;; Function calls
7696 (defvar anything-c-source-simple-call-tree-callers-functions
7697 '((name . "Function calls")
7698 (init . anything-c-simple-call-tree-callers-functions-init)
7699 (multiline)
7700 (candidates . anything-c-simple-call-tree-candidates)
7701 (persistent-action . anything-c-simple-call-tree-persistent-action)
7702 (persistent-help . "Show function definitions by rotation")
7703 (action ("Find definition selected by persistent-action" .
7704 anything-c-simple-call-tree-find-definition)))
7705 "Needs simple-call-tree.el.
7706 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
7708 (defun anything-c-simple-call-tree-callers-functions-init ()
7709 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
7711 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
7715 ;;; Anything UI of auto-document.el
7717 ;; <http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el>
7719 ;; Commands/Options with doc
7720 (defvar anything-c-auto-document-data nil)
7721 (make-variable-buffer-local 'anything-c-auto-document-data)
7722 (defvar anything-c-source-commands-and-options-in-file
7723 '((name . "Commands/Options in file")
7724 (header-name
7725 . (lambda (x) (format "Commands/Options in %s"
7726 (buffer-local-value 'buffer-file-name
7727 anything-current-buffer))))
7728 (candidates . anything-command-and-options-candidates)
7729 (multiline)
7730 (action . imenu))
7731 "List Commands and Options with doc. It needs auto-document.el .
7733 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
7735 (eval-when-compile (require 'auto-document nil t))
7736 (defun anything-command-and-options-candidates ()
7737 (with-anything-current-buffer
7738 (when (and (require 'auto-document nil t)
7739 (eq major-mode 'emacs-lisp-mode)
7740 (or (anything-current-buffer-is-modified)
7741 (not anything-c-auto-document-data)))
7742 (or imenu--index-alist (imenu--make-index-alist t))
7743 (setq anything-c-auto-document-data
7744 (destructuring-bind (commands options)
7745 (adoc-construct anything-current-buffer)
7746 (append
7747 (loop for (command . doc) in commands
7748 for cmdname = (symbol-name command)
7749 collect
7750 (cons
7751 (format "Command: %s\n %s"
7752 (propertize cmdname 'face font-lock-function-name-face)
7753 (adoc-first-line doc))
7754 (assoc cmdname imenu--index-alist)))
7755 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
7756 for (option doc default) in options
7757 for optname = (symbol-name option)
7758 collect
7759 (cons
7760 (format "Option: %s\n %s\n default = %s"
7761 (propertize optname 'face font-lock-variable-name-face)
7762 (adoc-first-line doc)
7763 (adoc-prin1-to-string default))
7764 (assoc optname
7765 var-alist)))))))
7766 anything-c-auto-document-data))
7768 ;; (anything 'anything-c-source-commands-and-options-in-file)
7771 ;;;; <Color and Face>
7774 ;;; Customize Face
7777 (defvar anything-c-source-customize-face
7778 '((name . "Customize Face")
7779 (init . (lambda ()
7780 (unless (anything-candidate-buffer)
7781 (save-window-excursion (list-faces-display))
7782 (anything-candidate-buffer (get-buffer "*Faces*")))))
7783 (candidates-in-buffer)
7784 (get-line . buffer-substring)
7785 (action . (lambda (line)
7786 (customize-face (intern (car (split-string line))))))
7787 (requires-pattern . 3))
7788 "See (info \"(emacs)Faces\")")
7789 ;; (anything 'anything-c-source-customize-face)
7791 ;;; Colors browser
7794 (defvar anything-c-source-colors
7795 '((name . "Colors")
7796 (init . (lambda () (unless (anything-candidate-buffer)
7797 (save-window-excursion (list-colors-display))
7798 (anything-candidate-buffer (get-buffer "*Colors*")))))
7799 (candidates-in-buffer)
7800 (get-line . buffer-substring)
7801 (action
7802 ("Copy Name" . (lambda (candidate)
7803 (kill-new (anything-c-colors-get-name candidate))))
7804 ("Copy RGB" . (lambda (candidate)
7805 (kill-new (anything-c-colors-get-rgb candidate))))
7806 ("Insert Name" . (lambda (candidate)
7807 (with-anything-current-buffer
7808 (insert (anything-c-colors-get-name candidate)))))
7809 ("Insert RGB" . (lambda (candidate)
7810 (with-anything-current-buffer
7811 (insert (anything-c-colors-get-rgb candidate))))))))
7812 ;; (anything 'anything-c-source-colors)
7814 (defun anything-c-colors-get-name (candidate)
7815 "Get color name."
7816 (replace-regexp-in-string
7817 " " ""
7818 (with-temp-buffer
7819 (insert (capitalize candidate))
7820 (goto-char (point-min))
7821 (search-forward-regexp "\\s-\\{2,\\}")
7822 (delete-region (point) (point-max))
7823 (buffer-string))))
7825 (defun anything-c-colors-get-rgb (candidate)
7826 "Get color RGB."
7827 (replace-regexp-in-string
7828 " " ""
7829 (with-temp-buffer
7830 (insert (capitalize candidate))
7831 (goto-char (point-max))
7832 (search-backward-regexp "\\s-\\{2,\\}")
7833 (delete-region (point) (point-min))
7834 (buffer-string))))
7837 ;;;; <Search Engine>
7838 ;;; Tracker desktop search
7839 (defvar anything-c-source-tracker-search
7840 '((name . "Tracker Search")
7841 (candidates . (lambda ()
7842 (start-process "tracker-search-process" nil
7843 "tracker-search"
7844 anything-pattern)))
7845 (type . file)
7846 (requires-pattern . 3)
7847 (delayed))
7848 "Source for retrieving files matching the current input pattern
7849 with the tracker desktop search.")
7850 ;; (anything 'anything-c-source-tracker-search)
7852 ;;; Spotlight (MacOS X desktop search)
7853 (defvar anything-c-source-mac-spotlight
7854 '((name . "mdfind")
7855 (candidates
7856 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
7857 (type . file)
7858 (requires-pattern . 3)
7859 (delayed))
7860 "Source for retrieving files via Spotlight's command line
7861 utility mdfind.")
7862 ;; (anything 'anything-c-source-mac-spotlight)
7864 ;;; Picklist
7865 (defvar anything-c-source-picklist
7866 '((name . "Picklist")
7867 (candidates . (lambda () (mapcar 'car picklist-list)))
7868 (type . file)))
7869 ;; (anything 'anything-c-source-picklist)
7873 ;;; Kill ring
7876 (defvar anything-c-source-kill-ring
7877 '((name . "Kill Ring")
7878 (init . (lambda () (anything-attrset 'last-command last-command)))
7879 (candidates . anything-c-kill-ring-candidates)
7880 (filtered-candidate-transformer anything-c-kill-ring-transformer)
7881 (action . anything-c-kill-ring-action)
7882 (last-command)
7883 (migemo)
7884 (multiline))
7885 "Source for browse and insert contents of kill-ring.")
7887 (defun anything-c-kill-ring-candidates ()
7888 (loop for kill in (anything-fast-remove-dups kill-ring :test 'equal)
7889 unless (or (< (length kill) anything-kill-ring-threshold)
7890 (string-match "^[\\s\\t]+$" kill))
7891 collect kill))
7893 (defun anything-c-kill-ring-transformer (candidates source)
7894 "Display only the `anything-c-kill-ring-max-lines-number' lines of candidate."
7895 (loop for i in candidates
7896 for nlines = (with-temp-buffer (insert i) (count-lines (point-min) (point-max)))
7897 if (and anything-c-kill-ring-max-lines-number
7898 (> nlines anything-c-kill-ring-max-lines-number))
7899 collect (cons
7900 (with-temp-buffer
7901 (insert i)
7902 (goto-char (point-min))
7903 (concat
7904 (buffer-substring
7905 (point-min)
7906 (save-excursion
7907 (forward-line anything-c-kill-ring-max-lines-number)
7908 (point)))
7909 "[...]")) i)
7910 else collect i))
7912 (defun anything-c-kill-ring-action (str)
7913 "Insert STR in `kill-ring' and set STR to the head.
7914 If this action is executed just after `yank',
7915 replace with STR as yanked string."
7916 (setq kill-ring (delete str kill-ring))
7917 (if (not (eq (anything-attr 'last-command) 'yank))
7918 (insert-for-yank str)
7919 ;; from `yank-pop'
7920 (let ((inhibit-read-only t)
7921 (before (< (point) (mark t))))
7922 (if before
7923 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
7924 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
7925 (setq yank-undo-function nil)
7926 (set-marker (mark-marker) (point) (current-buffer))
7927 (insert-for-yank str)
7928 ;; Set the window start back where it was in the yank command,
7929 ;; if possible.
7930 (set-window-start (selected-window) yank-window-start t)
7931 (if before
7932 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
7933 ;; It is cleaner to avoid activation, even though the command
7934 ;; loop would deactivate the mark because we inserted text.
7935 (goto-char (prog1 (mark t)
7936 (set-marker (mark-marker) (point) (current-buffer)))))))
7937 (kill-new str))
7939 ;; (anything 'anything-c-source-kill-ring)
7942 ;;;; <Mark ring>
7943 ;; DO NOT include these sources in `anything-sources' use
7944 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
7945 ;; `anything-all-mark-rings' instead.
7947 (defun anything-c-source-mark-ring-candidates ()
7948 (flet ((get-marks (pos)
7949 (save-excursion
7950 (goto-char pos)
7951 (beginning-of-line)
7952 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
7953 (when (string= "" line)
7954 (setq line "<EMPTY LINE>"))
7955 (format "%7d: %s" (line-number-at-pos) line)))))
7956 (with-anything-current-buffer
7957 (loop
7958 with marks = (if (mark) (cons (mark-marker) mark-ring) mark-ring)
7959 with recip = nil
7960 for i in marks
7961 for m = (get-marks i)
7962 unless (member m recip)
7963 collect m into recip
7964 finally return recip))))
7966 (defvar anything-mark-ring-cache nil)
7967 (defvar anything-c-source-mark-ring
7968 '((name . "mark-ring")
7969 (init . (lambda ()
7970 (setq anything-mark-ring-cache
7971 (ignore-errors (anything-c-source-mark-ring-candidates)))))
7972 (candidates . (lambda ()
7973 (anything-aif anything-mark-ring-cache
7974 it)))
7975 (action . (("Goto line"
7976 . (lambda (candidate)
7977 (anything-goto-line (string-to-number candidate))))))
7978 (persistent-action . (lambda (candidate)
7979 (anything-goto-line (string-to-number candidate))
7980 (anything-match-line-color-current-line)))
7981 (persistent-help . "Show this line")))
7983 ;; (anything 'anything-c-source-mark-ring)
7985 ;;; Global-mark-ring
7986 (defvar anything-c-source-global-mark-ring
7987 '((name . "global-mark-ring")
7988 (candidates . anything-c-source-global-mark-ring-candidates)
7989 (action . (("Goto line"
7990 . (lambda (candidate)
7991 (let ((items (split-string candidate ":")))
7992 (anything-c-switch-to-buffer (second items))
7993 (anything-goto-line (string-to-number (car items))))))))
7994 (persistent-action . (lambda (candidate)
7995 (let ((items (split-string candidate ":")))
7996 (anything-c-switch-to-buffer (second items))
7997 (anything-goto-line (string-to-number (car items)))
7998 (anything-match-line-color-current-line))))
7999 (persistent-help . "Show this line")))
8001 (defun anything-c-source-global-mark-ring-candidates ()
8002 (flet ((buf-fn (m)
8003 (with-current-buffer (marker-buffer m)
8004 (goto-char m)
8005 (beginning-of-line)
8006 (let (line)
8007 (if (string= "" line)
8008 (setq line "<EMPTY LINE>")
8009 (setq line (car (split-string (thing-at-point 'line)
8010 "[\n\r]"))))
8011 (format "%7d:%s: %s"
8012 (line-number-at-pos) (marker-buffer m) line)))))
8013 (loop
8014 with marks = global-mark-ring
8015 with recip = nil
8016 for i in marks
8017 for gm = (unless (or (string-match
8018 "^ " (format "%s" (marker-buffer i)))
8019 (null (marker-buffer i)))
8020 (buf-fn i))
8021 when (and gm (not (member gm recip)))
8022 collect gm into recip
8023 finally return recip)))
8025 ;; (anything 'anything-c-source-global-mark-ring)
8028 ;;;; <Register>
8029 ;;; Insert from register
8030 (defvar anything-c-source-register
8031 '((name . "Registers")
8032 (candidates . anything-c-register-candidates)
8033 (action-transformer . anything-c-register-action-transformer)
8034 (multiline)
8035 (action))
8036 "See (info \"(emacs)Registers\")")
8038 (defun anything-c-register-candidates ()
8039 "Collecting register contents and appropriate commands."
8040 (loop for (char . val) in register-alist
8041 for key = (single-key-description char)
8042 for string-actions =
8043 (cond
8044 ((numberp val)
8045 (list (int-to-string val)
8046 'insert-register
8047 'increment-register))
8048 ((markerp val)
8049 (let ((buf (marker-buffer val)))
8050 (if (null buf)
8051 (list "a marker in no buffer")
8052 (list (concat
8053 "a buffer position:"
8054 (buffer-name buf)
8055 ", position "
8056 (int-to-string (marker-position val)))
8057 'jump-to-register
8058 'insert-register))))
8059 ((and (consp val) (window-configuration-p (car val)))
8060 (list "window configuration."
8061 'jump-to-register))
8062 ((and (consp val) (frame-configuration-p (car val)))
8063 (list "frame configuration."
8064 'jump-to-register))
8065 ((and (consp val) (eq (car val) 'file))
8066 (list (concat "file:"
8067 (prin1-to-string (cdr val))
8068 ".")
8069 'jump-to-register))
8070 ((and (consp val) (eq (car val) 'file-query))
8071 (list (concat "file:a file-query reference: file "
8072 (car (cdr val))
8073 ", position "
8074 (int-to-string (car (cdr (cdr val))))
8075 ".")
8076 'jump-to-register))
8077 ((consp val)
8078 (let ((lines (format "%4d" (length val))))
8079 (list (format "%s: %s\n" lines
8080 (truncate-string-to-width
8081 (mapconcat 'identity (list (car val))
8082 ;; (mapconcat (lambda (y) y) val
8083 "^J") (- (window-width) 15)))
8084 'insert-register)))
8085 ((stringp val)
8086 (list ;; without properties
8087 (substring-no-properties val)
8088 'insert-register
8089 'append-to-register
8090 'prepend-to-register))
8092 "GARBAGE!"))
8093 collect (cons (format "register %3s: %s" key (car string-actions))
8094 (cons char (cdr string-actions)))))
8096 (defun anything-c-register-action-transformer (actions register-and-functions)
8097 "Decide actions by the contents of register."
8098 (loop with func-actions =
8099 '((insert-register
8100 "Insert Register" .
8101 (lambda (c) (insert-register (car c))))
8102 (jump-to-register
8103 "Jump to Register" .
8104 (lambda (c) (jump-to-register (car c))))
8105 (append-to-register
8106 "Append Region to Register" .
8107 (lambda (c) (append-to-register
8108 (car c) (region-beginning) (region-end))))
8109 (prepend-to-register
8110 "Prepend Region to Register" .
8111 (lambda (c) (prepend-to-register
8112 (car c) (region-beginning) (region-end))))
8113 (increment-register
8114 "Increment Prefix Arg to Register" .
8115 (lambda (c) (increment-register
8116 anything-current-prefix-arg (car c)))))
8117 for func in (cdr register-and-functions)
8118 for cell = (assq func func-actions)
8119 when cell
8120 collect (cdr cell)))
8122 ;; (anything 'anything-c-source-register)
8125 ;;; Latex completion
8126 (defun anything-c-latex-math-candidates ()
8127 "Collect candidates for latex math completion."
8128 (declare (special LaTeX-math-menu))
8129 (loop for i in (cddr LaTeX-math-menu)
8130 for elm = (loop for s in i when (vectorp s)
8131 collect (cons (aref s 0) (aref s 1)))
8132 append elm))
8134 (defvar anything-c-source-latex-math
8135 '((name . "Latex Math Menu")
8136 (init . (lambda ()
8137 (with-anything-current-buffer
8138 (LaTeX-math-mode 1))))
8139 (candidate-number-limit . 9999)
8140 (candidates . anything-c-latex-math-candidates)
8141 (action . (lambda (candidate)
8142 (call-interactively candidate)))))
8145 ;;;; <Headline Extraction>
8146 (defvar anything-c-source-fixme
8147 '((name . "TODO/FIXME/DRY comments")
8148 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
8149 (adjust)
8150 (recenter))
8151 "Show TODO/FIXME/DRY comments in current file.")
8152 ;; (anything 'anything-c-source-fixme)
8154 (defvar anything-c-source-rd-headline
8155 '((name . "RD HeadLine")
8156 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
8157 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
8158 (migemo)
8159 (subexp . 1))
8160 "Show RD headlines.
8162 RD is Ruby's POD.
8163 http://en.wikipedia.org/wiki/Ruby_Document_format")
8164 ;; (anything 'anything-c-source-rd-headline)
8166 (defvar anything-c-source-oddmuse-headline
8167 '((name . "Oddmuse HeadLine")
8168 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
8169 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
8170 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
8171 (migemo)
8172 (subexp . 1))
8173 "Show Oddmuse headlines, such as EmacsWiki.")
8174 ;; (anything 'anything-c-source-oddmuse-headline)
8176 (defvar anything-c-source-emacs-source-defun
8177 '((name . "Emacs Source DEFUN")
8178 (headline . "DEFUN\\|DEFVAR")
8179 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
8180 (or buffer-file-name ""))))
8181 "Show DEFUN/DEFVAR in Emacs C source file.")
8182 ;; (anything 'anything-c-source-emacs-source-defun)
8184 (defvar anything-c-source-emacs-lisp-expectations
8185 '((name . "Emacs Lisp Expectations")
8186 (headline . "(desc[ ]\\|(expectations")
8187 (condition . (eq major-mode 'emacs-lisp-mode)))
8188 "Show descriptions (desc) in Emacs Lisp Expectations.
8190 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
8191 ;; (anything 'anything-c-source-emacs-lisp-expectations)
8193 (defvar anything-c-source-emacs-lisp-toplevels
8194 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
8195 (headline . "^(\\|(@\\*\\|^;;;;")
8196 (get-line . buffer-substring)
8197 (condition . (eq major-mode 'emacs-lisp-mode))
8198 (adjust))
8199 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
8200 linkd.el is optional because linkd stars are extracted by regexp.
8201 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
8202 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
8205 ;;; Anything yaoddmuse
8207 ;; Be sure to have yaoddmuse.el installed
8208 ;; install-elisp may be required if you want to install elisp file from here.
8209 (defvar anything-yaoddmuse-use-cache-file nil)
8210 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
8211 (defvar anything-c-yaoddmuse-ew-cache nil)
8213 (defun anything-yaoddmuse-get-candidates ()
8214 (declare (special yaoddmuse-pages-hash))
8215 (if anything-yaoddmuse-use-cache-file
8216 (ignore-errors
8217 (unless anything-c-yaoddmuse-ew-cache
8218 (load anything-c-yaoddmuse-cache-file)
8219 (setq anything-c-yaoddmuse-ew-cache
8220 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
8221 anything-c-yaoddmuse-ew-cache)
8222 (yaoddmuse-update-pagename t)
8223 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
8225 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
8226 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
8227 (candidates . anything-yaoddmuse-get-candidates)
8228 (action . (("Edit page" . (lambda (candidate)
8229 (yaoddmuse-edit "EmacsWiki" candidate)))
8230 ("Browse page"
8231 . (lambda (candidate)
8232 (yaoddmuse-browse-page "EmacsWiki" candidate)))
8233 ("Browse page other window"
8234 . (lambda (candidate)
8235 (if (one-window-p)
8236 (split-window-vertically))
8237 (yaoddmuse-browse-page "EmacsWiki" candidate)))
8238 ("Browse diff"
8239 . (lambda (candidate)
8240 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
8241 ("Copy URL"
8242 . (lambda (candidate)
8243 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
8244 (message "Have copy page %s's URL to yank." candidate)))
8245 ("Create page"
8246 . (lambda (candidate)
8247 (yaoddmuse-edit "EmacsWiki" anything-input)))
8248 ("Update cache"
8249 . (lambda (candidate)
8250 (if anything-yaoddmuse-use-cache-file
8251 (progn
8252 (anything-yaoddmuse-cache-pages t)
8253 (setq anything-c-yaoddmuse-ew-cache
8254 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
8255 (yaoddmuse-update-pagename))))))
8256 (action-transformer anything-c-yaoddmuse-action-transformer))
8257 "Needs yaoddmuse.el.
8259 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
8261 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
8263 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
8264 '((name . "Yaoddmuse Post library (EmacsWiki)")
8265 (init . (anything-yaoddmuse-init))
8266 (candidates-in-buffer)
8267 (action . (("Post library and Browse"
8268 . (lambda (candidate)
8269 (yaoddmuse-post-file
8270 (find-library-name candidate)
8271 "EmacsWiki"
8272 (file-name-nondirectory (find-library-name candidate))
8273 nil t)))
8274 ("Post library"
8275 . (lambda (candidate)
8276 (yaoddmuse-post-file
8277 (find-library-name candidate)
8278 "EmacsWiki"
8279 (file-name-nondirectory
8280 (find-library-name candidate))))))))
8281 "Needs yaoddmuse.el.
8283 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
8285 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
8287 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
8288 "Allow the use of `install-elisp' only on elisp files."
8289 (if (string-match "\.el$" candidate)
8290 (append actions '(("Install Elisp"
8291 . (lambda (elm)
8292 (install-elisp-from-emacswiki elm)))))
8293 actions))
8295 ;;;###autoload
8296 (defun anything-yaoddmuse-cache-pages (&optional load)
8297 "Fetch the list of files on emacswiki and create cache file.
8298 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
8299 (interactive)
8300 (declare (special yaoddmuse-pages-hash))
8301 (yaoddmuse-update-pagename)
8302 (save-excursion
8303 (find-file anything-c-yaoddmuse-cache-file)
8304 (erase-buffer)
8305 (insert "(puthash \"EmacsWiki\" '(")
8306 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
8308 (insert (concat "(\"" (car i) "\") ")))
8309 (insert ") yaoddmuse-pages-hash)\n")
8310 (save-buffer)
8311 (kill-buffer (current-buffer))
8312 (when (or current-prefix-arg
8313 load)
8314 (load anything-c-yaoddmuse-cache-file))))
8316 (defun anything-yaoddmuse-init ()
8317 "Init anything buffer status."
8318 (let ((anything-buffer (anything-candidate-buffer 'global))
8319 (library-list (yaoddmuse-get-library-list)))
8320 (with-current-buffer anything-buffer
8321 ;; Insert library name.
8322 (dolist (library library-list)
8323 (insert (format "%s\n" library)))
8324 ;; Sort lines.
8325 (sort-lines nil (point-min) (point-max)))))
8328 ;;; Eev anchors
8329 (defvar anything-c-source-eev-anchor
8330 '((name . "Anchors")
8331 (candidates
8332 . (lambda ()
8333 (ignore-errors
8334 (with-anything-current-buffer
8335 (loop initially (goto-char (point-min))
8336 while (re-search-forward
8337 (format ee-anchor-format "\\([^\.].+\\)") nil t)
8338 for anchor = (match-string-no-properties 1)
8339 collect (cons (format "%5d:%s"
8340 (line-number-at-pos (match-beginning 0))
8341 (format ee-anchor-format anchor))
8342 anchor))))))
8343 (persistent-action . (lambda (item)
8344 (ee-to item)
8345 (anything-match-line-color-current-line)))
8346 (persistent-help . "Show this entry")
8347 (action . (("Goto link" . ee-to)))))
8348 ;; (anything 'anything-c-source-eev-anchor)
8351 ;;; Org headlines
8354 (defvar anything-c-source-org-headline
8355 `((name . "Org HeadLine")
8356 (headline ,@(mapcar (lambda (num)
8357 (format "^\\*\\{%d\\} \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
8358 num))
8359 (number-sequence 1 8)))
8360 (condition . (eq major-mode 'org-mode))
8361 (migemo)
8362 (subexp . 1)
8363 (persistent-action . (lambda (elm)
8364 (anything-c-action-line-goto elm)
8365 (org-cycle)))
8366 (action-transformer
8367 . (lambda (actions candidate)
8368 '(("Go to Line" . anything-c-action-line-goto)
8369 ("Insert Link to This Headline"
8370 . anything-c-org-headline-insert-link-to-headline)))))
8371 "Show Org headlines.
8372 org-mode is very very much extended text-mode/outline-mode.
8374 See (find-library \"org.el\")
8375 See http://orgmode.org for the latest version.")
8377 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
8378 (insert
8379 (save-excursion
8380 (anything-goto-line (car lineno-and-content))
8381 (and (looking-at org-complex-heading-regexp)
8382 (org-make-link-string (concat "*" (match-string 4)))))))
8383 ;; (anything 'anything-c-source-org-headline)
8385 ;;; Org keywords
8388 (defvar anything-c-source-org-keywords
8389 '((name . "Org Keywords")
8390 (init . anything-c-org-keywords-init)
8391 (candidates . anything-c-org-keywords-candidates)
8392 (action . anything-c-org-keywords-insert)
8393 (persistent-action . anything-c-org-keywords-show-help)
8394 (persistent-help . "Show an example and info page to describe this keyword.")
8395 (keywords-examples)
8396 (keywords)))
8397 ;; (anything 'anything-c-source-org-keywords)
8399 (defvar anything-c-org-keywords-info-location
8400 '(("#+TITLE:" . "(org)Export options")
8401 ("#+AUTHOR:" . "(org)Export options")
8402 ("#+DATE:" . "(org)Export options")
8403 ("#+EMAIL:" . "(org)Export options")
8404 ("#+DESCRIPTION:" . "(org)Export options")
8405 ("#+KEYWORDS:" . "(org)Export options")
8406 ("#+LANGUAGE:" . "(org)Export options")
8407 ("#+TEXT:" . "(org)Export options")
8408 ("#+TEXT:" . "(org)Export options")
8409 ("#+OPTIONS:" . "(org)Export options")
8410 ("#+BIND:" . "(org)Export options")
8411 ("#+LINK_UP:" . "(org)Export options")
8412 ("#+LINK_HOME:" . "(org)Export options")
8413 ("#+LATEX_HEADER:" . "(org)Export options")
8414 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
8415 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
8416 ("#+INFOJS_OPT" . "(org)Javascript support")
8417 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
8418 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
8419 ("#+ORGTBL" . "(org)Radio tables")
8420 ("#+HTML:" . "(org)Quoting HTML tags")
8421 ("#+LaTeX:" . "(org)Quoting LaTeX code")
8422 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
8423 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
8424 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
8425 ("#+BEGIN_VERSE" . "(org)Paragraphs")
8426 ("#+BEGIN_SRC" . "(org)Literal examples")
8427 ("#+CAPTION" . "(org)Tables in HTML export")
8428 ("#+LABEL" . "(org)Tables in LaTeX export")
8429 ("#+ATTR_HTML" . "(org)Links")
8430 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
8432 (defun anything-c-org-keywords-init ()
8433 (unless (anything-attr 'keywords-examples)
8434 (require 'org)
8435 (anything-attrset 'keywords-examples
8436 (append
8437 (mapcar
8438 (lambda (x)
8439 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
8440 (cons (match-string 2 x) (match-string 1 x)))
8441 (org-split-string (org-get-current-options) "\n"))
8442 (mapcar 'list org-additional-option-like-keywords)))
8443 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
8445 (defun anything-c-org-keywords-candidates ()
8446 (and (or (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
8447 (eq (buffer-local-value 'major-mode anything-current-buffer) 'message-mode))
8448 (anything-attr 'keywords)))
8450 (defun anything-c-org-keywords-insert (keyword)
8451 (cond ((and (string-match "BEGIN" keyword)
8452 (anything-region-active-p))
8453 (let ((beg (region-beginning))
8454 (end (region-end)))
8455 (goto-char end)
8456 (insert "\n#+" (replace-regexp-in-string
8457 "BEGIN" "END" keyword) "\n")
8458 (goto-char beg)
8459 (insert "#+" keyword " ")
8460 (save-excursion (insert "\n"))))
8461 ((string-match "BEGIN" keyword)
8462 (insert "#+" keyword " ")
8463 (save-excursion
8464 (insert "\n#+" (replace-regexp-in-string
8465 "BEGIN" "END" keyword) "\n")))
8466 (t (insert "#+" keyword " "))))
8468 (defun anything-c-org-keywords-show-help (keyword)
8469 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
8470 "(org)In-buffer settings"))
8471 (search-forward (concat "#+" keyword) nil t)
8472 (anything-persistent-highlight-point)
8473 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
8477 ;;; bbdb
8480 (defvar bbdb-records)
8481 (defvar bbdb-buffer-name)
8483 (defun anything-c-bbdb-candidates ()
8484 "Return a list of all names in the bbdb database. The format
8485 is \"Firstname Lastname\"."
8486 (mapcar (lambda (bbdb-record)
8487 (replace-regexp-in-string
8488 "\\s-+$" ""
8489 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
8490 (bbdb-records)))
8492 (defun anything-c-bbdb-create-contact (actions candidate)
8493 "Action transformer that returns only an entry to add the
8494 current `anything-pattern' as new contact. All other actions are
8495 removed."
8496 (if (string= candidate "*Add to contacts*")
8497 '(("Add to contacts" . (lambda (actions)
8498 (bbdb-create-internal
8499 (read-from-minibuffer "Name: " anything-c-bbdb-name)
8500 (read-from-minibuffer "Company: ")
8501 (read-from-minibuffer "Email: ")
8504 (read-from-minibuffer "Note: ")))))
8505 actions))
8507 (defun anything-c-bbdb-get-record (candidate)
8508 "Return record that match CANDIDATE."
8509 (bbdb candidate nil)
8510 (set-buffer "*BBDB*")
8511 (bbdb-current-record))
8513 (defvar anything-c-bbdb-name nil
8514 "Only for internal use.")
8516 (defvar anything-c-source-bbdb
8517 '((name . "BBDB")
8518 (candidates . anything-c-bbdb-candidates)
8519 (action ("Send a mail" . anything-c-bbdb-compose-mail)
8520 ("View person's data" . anything-c-bbdb-view-person-action))
8521 (filtered-candidate-transformer . (lambda (candidates source)
8522 (setq anything-c-bbdb-name anything-pattern)
8523 (if (not candidates)
8524 (list "*Add to contacts*")
8525 candidates)))
8526 (action-transformer . (lambda (actions candidate)
8527 (anything-c-bbdb-create-contact actions candidate))))
8528 "Needs BBDB.
8530 http://bbdb.sourceforge.net/")
8531 ;; (anything 'anything-c-source-bbdb)
8533 (defun anything-c-bbdb-view-person-action (candidate)
8534 "View BBDB data of single CANDIDATE or marked candidates."
8535 (anything-aif (anything-marked-candidates)
8536 (let ((bbdb-append-records (length it)))
8537 (dolist (i it)
8538 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
8539 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
8541 (defun anything-c-bbdb-collect-mail-addresses ()
8542 "Return a list of all mail addresses of records in bbdb buffer."
8543 (with-current-buffer bbdb-buffer-name
8544 (loop for i in bbdb-records
8545 if (bbdb-record-net (car i))
8546 collect (bbdb-dwim-net-address (car i)))))
8548 (defun anything-c-bbdb-compose-mail (candidate)
8549 "Compose a mail with all records of bbdb buffer."
8550 (anything-c-bbdb-view-person-action candidate)
8551 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
8552 (address-str (mapconcat 'identity address-list ",\n ")))
8553 (compose-mail address-str)))
8556 ;;; Evaluation Result
8559 ;; Internal
8560 (defvar anything-eldoc-active-minibuffers-list nil)
8562 (defvar anything-c-source-evaluation-result
8563 '((name . "Evaluation Result")
8564 (disable-shortcuts)
8565 (dummy)
8566 (multiline)
8567 (mode-line . "C-RET: nl-and-indent, tab: reindent, C-tab:complete, C-p/n: next/prec-line.")
8568 (filtered-candidate-transformer . (lambda (candidates source)
8569 (list
8570 (condition-case nil
8571 (with-anything-current-buffer
8572 (pp-to-string
8573 (eval (read anything-pattern))))
8574 (error "Error")))))
8575 (action . (("Copy result to kill-ring" . (lambda (candidate)
8576 (with-current-buffer anything-buffer
8577 (let ((end (save-excursion
8578 (goto-char (point-max))
8579 (search-backward "\n")
8580 (point))))
8581 (kill-region (point) end)))))
8582 ("copy sexp to kill-ring" . (lambda (candidate)
8583 (kill-new anything-input)))))))
8584 ;; (anything 'anything-c-source-evaluation-result)
8586 (defun anything-eval-new-line-and-indent ()
8587 (interactive)
8588 (newline) (lisp-indent-line))
8590 (defun anything-eldoc-store-minibuffer ()
8591 "Store minibuffer buffer name in `anything-eldoc-active-minibuffers-list'."
8592 (with-selected-window (minibuffer-window)
8593 (push (buffer-name) anything-eldoc-active-minibuffers-list)))
8595 (defun anything-eldoc-show-in-eval ()
8596 "Return eldoc in mode-line for current minibuffer input."
8597 (let ((buf (with-selected-window (minibuffer-window)
8598 (buffer-name))))
8599 (when (member buf anything-eldoc-active-minibuffers-list)
8600 (let* ((str-all (with-current-buffer buf
8601 (minibuffer-completion-contents)))
8602 (sym (when str-all
8603 (with-temp-buffer
8604 (insert str-all)
8605 (goto-char (point-max))
8606 (unless (looking-back ")\\|\"") (forward-char -1))
8607 (eldoc-current-symbol))))
8608 (info-fn (eldoc-fnsym-in-current-sexp))
8609 (doc (or (eldoc-get-var-docstring sym)
8610 (eldoc-get-fnsym-args-string
8611 (car info-fn) (cadr info-fn)))))
8612 (when doc (funcall anything-c-eldoc-in-minibuffer-show-fn doc))))))
8614 (defun anything-c-eldoc-show-in-mode-line (str)
8615 "Show string STR in mode-line."
8616 (save-window-excursion
8617 (with-current-buffer anything-buffer
8618 (let ((mode-line-format (concat " " str)))
8619 (force-mode-line-update)
8620 (sit-for anything-c-eldoc-show-in-mode-line-delay))
8621 (force-mode-line-update))))
8623 ;;; Calculation Result
8626 (defvar anything-c-source-calculation-result
8627 '((name . "Calculation Result")
8628 (dummy)
8629 (filtered-candidate-transformer . (lambda (candidates source)
8630 (list
8631 (condition-case nil
8632 (calc-eval anything-pattern)
8633 (error "error")))))
8634 (action ("Copy result to kill-ring" . kill-new))))
8635 ;; (anything 'anything-c-source-calculation-result)
8638 ;;; Google Suggestions
8641 ;; Internal
8642 (defvar anything-ggs-max-length-real-flag 0)
8643 (defvar anything-ggs-max-length-num-flag 0)
8645 (defun anything-c-google-suggest-fetch (input)
8646 "Fetch suggestions for INPUT from XML buffer.
8647 Return an alist with elements like (data . number_results)."
8648 (setq anything-ggs-max-length-real-flag 0
8649 anything-ggs-max-length-num-flag 0)
8650 (let ((request (concat anything-c-google-suggest-url
8651 (url-hexify-string input))))
8652 (flet ((fetch ()
8653 (loop
8654 with result-alist = (xml-get-children
8655 (car (xml-parse-region
8656 (point-min) (point-max)))
8657 'CompleteSuggestion)
8658 for i in result-alist
8659 for data = (cdr (caadr (assoc 'suggestion i)))
8660 for nqueries = (cdr (caadr (assoc 'num_queries i)))
8661 for lqueries = (length (anything-c-ggs-set-number-result
8662 nqueries))
8663 for ldata = (length data)
8665 (progn
8666 (when (> ldata anything-ggs-max-length-real-flag)
8667 (setq anything-ggs-max-length-real-flag ldata))
8668 (when (> lqueries anything-ggs-max-length-num-flag)
8669 (setq anything-ggs-max-length-num-flag lqueries)))
8670 collect (cons data nqueries) into cont
8671 finally return cont)))
8672 (if anything-google-suggest-use-curl-p
8673 (with-temp-buffer
8674 (call-process "curl" nil t nil request)
8675 (fetch))
8676 (with-current-buffer
8677 (url-retrieve-synchronously request)
8678 (fetch))))))
8680 (defun anything-c-google-suggest-set-candidates (&optional request-prefix)
8681 "Set candidates with result and number of google results found."
8682 (let ((suggestions
8683 (loop with suggested-results = (anything-c-google-suggest-fetch
8684 (or (and request-prefix
8685 (concat request-prefix " " anything-pattern))
8686 anything-pattern))
8687 for (real . numresult) in suggested-results
8688 ;; Prepare number of results with ","
8689 for fnumresult = (anything-c-ggs-set-number-result numresult)
8690 ;; Calculate number of spaces to add before fnumresult
8691 ;; if it is smaller than longest result
8692 ;; `anything-ggs-max-length-num-flag'.
8693 ;; e.g 1,234,567
8694 ;; 345,678
8695 ;; To be sure it is aligned properly.
8696 for nspaces = (if (< (length fnumresult) anything-ggs-max-length-num-flag)
8697 (- anything-ggs-max-length-num-flag (length fnumresult))
8699 ;; Add now the spaces before fnumresult.
8700 for align-fnumresult = (concat (make-string nspaces ? ) fnumresult)
8701 for interval = (- anything-ggs-max-length-real-flag (length real))
8702 for spaces = (make-string (+ 2 interval) ? )
8703 for display = (format "%s%s(%s results)" real spaces align-fnumresult)
8704 collect (cons display real))))
8705 (if (loop for (disp . dat) in suggestions
8706 thereis (equal dat anything-pattern))
8707 suggestions
8708 ;; if there is no suggestion exactly matching the input then
8709 ;; prepend a Search on Google item to the list
8710 (append
8711 suggestions
8712 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
8713 anything-input))))))
8715 (defun anything-c-ggs-set-number-result (num)
8716 (if num
8717 (progn
8718 (and (numberp num) (setq num (number-to-string num)))
8719 (loop for i in (reverse (split-string num "" t))
8720 for count from 1
8721 append (list i) into C
8722 when (= count 3)
8723 append (list ",") into C
8724 and do (setq count 0)
8725 finally return
8726 (replace-regexp-in-string
8727 "^," "" (mapconcat 'identity (reverse C) ""))))
8728 "?"))
8730 (defvar anything-c-google-suggest-default-browser-function nil
8731 "*The browse url function you prefer to use with google suggest.
8732 When nil, use the first browser function available
8733 See `anything-browse-url-default-browser-alist'.")
8735 (defun anything-c-google-suggest-action (candidate)
8736 "Default action to jump to a google suggested candidate."
8737 (let ((arg (concat anything-c-google-suggest-search-url
8738 (url-hexify-string candidate))))
8739 (anything-aif anything-c-google-suggest-default-browser-function
8740 (funcall it arg)
8741 (anything-c-browse-url arg))))
8743 (defvar anything-c-google-suggest-default-function
8744 'anything-c-google-suggest-set-candidates
8745 "Default function to use in anything google suggest.")
8747 (defvar anything-c-source-google-suggest
8748 '((name . "Google Suggest")
8749 (candidates . (lambda ()
8750 (funcall anything-c-google-suggest-default-function)))
8751 (action . (("Google Search" . anything-c-google-suggest-action)))
8752 (volatile)
8753 (requires-pattern . 3)
8754 (delayed)))
8756 (defun anything-c-google-suggest-emacs-lisp ()
8757 "Try to emacs lisp complete with google suggestions."
8758 (anything-c-google-suggest-set-candidates "emacs lisp"))
8760 ;; (anything 'anything-c-source-google-suggest)
8762 ;;; Yahoo suggestions
8765 (defun anything-c-yahoo-suggest-fetch (input)
8766 "Fetch Yahoo suggestions for INPUT from XML buffer.
8767 Return an alist with elements like (data . number_results)."
8768 (let ((request (concat anything-c-yahoo-suggest-url
8769 (url-hexify-string input))))
8770 (flet ((fetch ()
8771 (loop
8772 with result-alist = (xml-get-children
8773 (car (xml-parse-region (point-min) (point-max)))
8774 'Result)
8775 for i in result-alist
8776 collect (caddr i))))
8777 (with-current-buffer
8778 (url-retrieve-synchronously request)
8779 (fetch)))))
8781 (defun anything-c-yahoo-suggest-set-candidates ()
8782 "Set candidates with Yahoo results found."
8783 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
8784 (or suggestions
8785 (append
8786 suggestions
8787 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
8788 anything-input))))))
8790 (defun anything-c-yahoo-suggest-action (candidate)
8791 "Default action to jump to a Yahoo suggested candidate."
8792 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
8793 (url-hexify-string candidate))))
8795 (defvar anything-c-source-yahoo-suggest
8796 '((name . "Yahoo Suggest")
8797 (candidates . anything-c-yahoo-suggest-set-candidates)
8798 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
8799 (volatile)
8800 (requires-pattern . 3)
8801 (delayed)))
8803 ;; (anything 'anything-c-source-yahoo-suggest)
8806 ;;; Web browser functions.
8809 (require 'browse-url)
8810 ;; If default setting of `w3m-command' is not
8811 ;; what you want you and you modify it, you will have to reeval
8812 ;; also `anything-browse-url-default-browser-alist'.
8813 (defvar w3m-command "/usr/bin/w3m")
8814 (defvar anything-c-home-url "http://www.google.fr"
8815 "*Default url to use as home url.")
8817 (defvar browse-url-chromium-program "chromium-browser")
8818 (defvar browse-url-uzbl-program "uzbl-browser")
8819 (defvar anything-browse-url-default-browser-alist
8820 `((,w3m-command . w3m-browse-url)
8821 (,browse-url-firefox-program . browse-url-firefox)
8822 (,browse-url-chromium-program . browse-url-chromium)
8823 (,browse-url-uzbl-program . browse-url-uzbl)
8824 (,browse-url-kde-program . browse-url-kde)
8825 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
8826 (,browse-url-mozilla-program . browse-url-mozilla)
8827 (,browse-url-galeon-program . browse-url-galeon)
8828 (,browse-url-netscape-program . browse-url-netscape)
8829 (,browse-url-mosaic-program . browse-url-mosaic)
8830 (,browse-url-xterm-program . browse-url-text-xterm))
8831 "*Alist of (executable . function) to try to find a suitable url browser.")
8833 (defun* anything-c-generic-browser (url name &rest args)
8834 "Browse URL with NAME browser."
8835 (let ((proc (concat name " " url)))
8836 (message "Starting %s..." name)
8837 (apply 'start-process proc nil name
8838 (append args (list url)))
8839 (set-process-sentinel
8840 (get-process proc)
8841 #'(lambda (process event)
8842 (when (string= event "finished\n")
8843 (message "%s process %s" process event))))))
8845 (defun browse-url-chromium (url)
8846 "Browse URL with google chrome browser."
8847 (interactive "sURL: ")
8848 (anything-c-generic-browser
8849 url browse-url-chromium-program))
8851 (defun browse-url-uzbl (url &optional ignore)
8852 "Browse URL with uzbl browser."
8853 (interactive "sURL: ")
8854 (anything-c-generic-browser url browse-url-uzbl-program "-u"))
8856 (defun anything-browse-url-default-browser (url &rest args)
8857 "Find the first available browser and ask it to load URL."
8858 (let ((default-browser-fn
8859 (loop for (exe . fn) in anything-browse-url-default-browser-alist
8860 thereis (and exe (executable-find exe) fn))))
8861 (if default-browser-fn
8862 (apply default-browser-fn url args)
8863 (error "No usable browser found"))))
8865 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
8866 "Default command to browse URL."
8867 (if browse-url-browser-function
8868 (browse-url url)
8869 (anything-browse-url-default-browser url)))
8872 ;;; Surfraw
8874 ;; Need external program surfraw.
8875 ;; <http://surfraw.alioth.debian.org/>
8877 (defvar anything-surfraw-default-browser-function nil
8878 "*The browse url function you prefer to use with surfraw.
8879 When nil, fallback to `browse-url-browser-function'.")
8881 ;; Internal
8882 (defvar anything-surfraw-engines-history nil)
8884 (defun anything-c-build-elvi-list ()
8885 "Return list of all engines and descriptions handled by surfraw."
8886 (cdr
8887 (with-temp-buffer
8888 (call-process "surfraw" nil t nil
8889 "-elvi")
8890 (split-string (buffer-string) "\n"))))
8893 ;;; Emms
8896 (defun anything-emms-stream-edit-bookmark (elm)
8897 "Change the information of current emms-stream bookmark from anything."
8898 (declare (special emms-stream-list))
8899 (let* ((cur-buf anything-current-buffer)
8900 (bookmark (assoc elm emms-stream-list))
8901 (name (read-from-minibuffer "Description: "
8902 (nth 0 bookmark)))
8903 (url (read-from-minibuffer "URL: "
8904 (nth 1 bookmark)))
8905 (fd (read-from-minibuffer "Feed Descriptor: "
8906 (int-to-string (nth 2 bookmark))))
8907 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
8908 (format "%s" (car (last bookmark))))))
8909 (save-excursion
8910 (emms-streams)
8911 (when (re-search-forward (concat "^" name) nil t)
8912 (beginning-of-line)
8913 (emms-stream-delete-bookmark)
8914 (emms-stream-add-bookmark name url (string-to-number fd) type)
8915 (emms-stream-save-bookmarks-file)
8916 (emms-stream-quit)
8917 (anything-c-switch-to-buffer cur-buf)))))
8919 (defun anything-emms-stream-delete-bookmark (elm)
8920 "Delete an emms-stream bookmark from anything."
8921 (let* ((cur-buf anything-current-buffer)
8922 (bookmark (assoc elm emms-stream-list))
8923 (name (nth 0 bookmark)))
8924 (save-excursion
8925 (emms-streams)
8926 (when (re-search-forward (concat "^" name) nil t)
8927 (beginning-of-line)
8928 (emms-stream-delete-bookmark)
8929 (emms-stream-save-bookmarks-file)
8930 (emms-stream-quit)
8931 (anything-c-switch-to-buffer cur-buf)))))
8933 (defvar anything-c-source-emms-streams
8934 '((name . "Emms Streams")
8935 (init . (lambda ()
8936 (emms-stream-init)))
8937 (candidates . (lambda ()
8938 (declare (special emms-stream-list))
8939 (mapcar 'car emms-stream-list)))
8940 (action . (("Play" . (lambda (elm)
8941 (declare (special emms-stream-list))
8942 (let* ((stream (assoc elm emms-stream-list))
8943 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
8944 (url (second stream)))
8945 (funcall fn url))))
8946 ("Delete" . anything-emms-stream-delete-bookmark)
8947 ("Edit" . anything-emms-stream-edit-bookmark)))
8948 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8949 ;; (anything 'anything-c-source-emms-streams)
8951 ;; Don't forget to set `emms-source-file-default-directory'
8952 (defvar anything-c-source-emms-dired
8953 '((name . "Music Directory")
8954 (candidates . (lambda ()
8955 (cddr (directory-files emms-source-file-default-directory))))
8956 (action .
8957 (("Play Directory" . (lambda (item)
8958 (emms-play-directory
8959 (expand-file-name
8960 item
8961 emms-source-file-default-directory))))
8962 ("Open dired in file's directory" . (lambda (item)
8963 (anything-c-open-dired
8964 (expand-file-name
8965 item
8966 emms-source-file-default-directory))))))
8967 (filtered-candidate-transformer . anything-c-adaptive-sort)))
8968 ;; (anything 'anything-c-source-emms-dired)
8971 (defun anything-c-emms-files-modifier (candidates source)
8972 (let ((current-playlist (with-current-emms-playlist
8973 (loop
8974 with cur-list = (emms-playlist-tracks-in-region
8975 (point-min) (point-max))
8976 for i in cur-list
8977 collect (assoc-default 'name i)))))
8978 (loop for i in candidates
8979 if (member (cdr i) current-playlist)
8980 collect (cons (propertize (car i)
8981 'face 'anything-emms-playlist)
8982 (cdr i)) into lis
8983 else collect i into lis
8984 finally return lis)))
8986 (defun anything-c-emms-play-current-playlist ()
8987 "Play current playlist."
8988 (with-current-emms-playlist
8989 (emms-playlist-first)
8990 (emms-playlist-mode-play-smart)))
8992 (defvar anything-c-source-emms-files
8993 '((name . "Emms files")
8994 (candidates . (lambda ()
8995 (loop for v being the hash-values in emms-cache-db
8996 for name = (assoc-default 'name v)
8997 for artist = (or (assoc-default 'info-artist v) "unknown")
8998 for genre = (or (assoc-default 'info-genre v) "unknown")
8999 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
9000 for song = (or (assoc-default 'info-title v) "unknown")
9001 for info = (concat artist " - " genre " - " tracknum ": " song)
9002 unless (string-match "^http:" name) collect (cons info name))))
9003 (filtered-candidate-transformer . anything-c-emms-files-modifier)
9004 (action . (("Play file" . emms-play-file)
9005 ("Add to Playlist and play (C-u clear current)"
9006 . (lambda (candidate)
9007 (when anything-current-prefix-arg
9008 (emms-playlist-current-clear))
9009 (emms-playlist-new)
9010 (mapc 'emms-add-playlist-file (anything-marked-candidates))
9011 (unless emms-player-playing-p
9012 (anything-c-emms-play-current-playlist))))))))
9014 ;; (anything 'anything-c-source-emms-files)
9017 ;;; Jabber Contacts (jabber.el)
9018 (defun anything-c-jabber-online-contacts ()
9019 "List online Jabber contacts."
9020 (with-no-warnings
9021 (let (jids)
9022 (dolist (item (jabber-concat-rosters) jids)
9023 (when (get item 'connected)
9024 (push (if (get item 'name)
9025 (cons (get item 'name) item)
9026 (cons (symbol-name item) item)) jids))))))
9028 (defvar anything-c-source-jabber-contacts
9029 '((name . "Jabber Contacts")
9030 (init . (lambda () (require 'jabber)))
9031 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
9032 (action . (lambda (x)
9033 (jabber-chat-with
9034 (jabber-read-account)
9035 (symbol-name
9036 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
9037 ;; (anything 'anything-c-source-jabber-contacts)
9041 ;;; Call source.
9042 (defvar anything-source-select-buffer "*anything source select*")
9043 (defvar anything-c-source-call-source
9044 `((name . "Call anything source")
9045 (candidate-number-limit)
9046 (candidates
9047 . (lambda ()
9048 (loop for vname in (all-completions "anything-c-source-" obarray)
9049 for var = (intern vname)
9050 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
9051 if name collect
9052 (cons (format "%s `%s'"
9053 name (propertize vname 'face 'font-lock-variable-name-face))
9054 var))))
9055 (action
9056 . (("Invoke anything with selected source"
9058 (lambda (candidate)
9059 (setq anything-candidate-number-limit 9999)
9060 (anything candidate nil nil nil nil
9061 anything-source-select-buffer)))
9062 ("Describe variable" . describe-variable)
9063 ("Find variable" . find-variable)))
9064 (persistent-action . describe-variable)
9065 (persistent-help . "Show description of this source")))
9066 ;; (anything 'anything-c-source-call-source)
9068 (defun anything-call-source-from-anything ()
9069 "Call anything source within `anything' session."
9070 (interactive)
9071 (setq anything-input-idle-delay 0)
9072 (anything-set-sources '(anything-c-source-call-source)))
9074 ;;; Execute Preconfigured anything.
9075 (defvar anything-c-source-anything-commands
9076 '((name . "Preconfigured Anything")
9077 (candidates . anything-c-anything-commands-candidates)
9078 (type . command)
9079 (candidate-number-limit)))
9080 ;; (anything 'anything-c-source-anything-commands)
9082 (defun anything-c-anything-commands-candidates ()
9083 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
9084 collect (cons (if (where-is-internal cmd nil t)
9085 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
9086 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
9087 cmd)))
9090 ;;; Occur
9093 (defun anything-c-occur-init ()
9094 "Create the initial anything occur buffer.
9095 If region is active use region as buffer contents
9096 instead of whole buffer."
9097 (with-current-buffer (anything-candidate-buffer 'global)
9098 (erase-buffer)
9099 (let ((buf-contents
9100 (with-anything-current-buffer
9101 (if (anything-region-active-p)
9102 (buffer-substring (region-beginning) (region-end))
9103 (buffer-substring (point-min) (point-max))))))
9104 (insert buf-contents))))
9106 (defun anything-c-occur-get-line (s e)
9107 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
9109 (defun anything-c-occur-query-replace-regexp (candidate)
9110 "Query replace regexp starting from CANDIDATE.
9111 If region is active ignore CANDIDATE and replace only in region.
9112 With a prefix arg replace only matches surrounded by word boundaries,
9113 i.e Don't replace inside a word, regexp is surrounded with \\bregexp\\b."
9114 (let ((regexp anything-input))
9115 (unless (anything-region-active-p)
9116 (anything-c-action-line-goto candidate))
9117 (apply 'query-replace-regexp
9118 (anything-c-query-replace-args regexp))))
9120 (defvar anything-c-source-occur
9121 '((name . "Occur")
9122 (init . anything-c-occur-init)
9123 (candidates-in-buffer)
9124 (migemo)
9125 (get-line . anything-c-occur-get-line)
9126 (display-to-real . anything-c-display-to-real-line)
9127 (action . (("Go to Line" . anything-c-action-line-goto)
9128 ("Query replace regexp (C-u Not inside word.)"
9129 . anything-c-occur-query-replace-regexp)))
9130 (recenter)
9131 (requires-pattern . 1)
9132 (delayed)
9133 (volatile)))
9134 ;; (anything 'anything-c-source-occur)
9137 ;;; Anything browse code.
9138 (defun anything-c-browse-code-get-line (beg end)
9139 "Select line if it match the regexp corresponding to current `major-mode'.
9140 Line is parsed for BEG position to END position."
9141 (let ((str-line (buffer-substring beg end))
9142 (regexp (assoc-default major-mode
9143 anything-c-browse-code-regexp-alist))
9144 (num-line (if (string= anything-pattern "") beg (1- beg))))
9145 (when (and regexp (string-match regexp str-line))
9146 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
9149 (defvar anything-c-source-browse-code
9150 '((name . "Browse code")
9151 (init . (lambda ()
9152 (anything-candidate-buffer anything-current-buffer)
9153 (with-anything-current-buffer
9154 (jit-lock-fontify-now))))
9155 (candidate-number-limit . 9999)
9156 (candidates-in-buffer)
9157 (get-line . anything-c-browse-code-get-line)
9158 (type . line)
9159 (recenter)))
9162 ;; Do many actions for input
9163 (defvar anything-c-source-create
9164 '((name . "Create")
9165 (dummy)
9166 (action)
9167 (action-transformer . anything-create--actions))
9168 "Do many create actions from `anything-pattern'.
9169 See also `anything-create--actions'.")
9170 ;; (anything 'anything-c-source-create)
9172 (defun anything-create-from-anything ()
9173 "Run `anything-create' from `anything' as a fallback."
9174 (interactive)
9175 (anything-run-after-quit 'anything-create nil anything-pattern))
9177 (defun anything-create--actions (&rest ignored)
9178 "Default actions for `anything-create' / `anything-c-source-create'."
9179 (remove-if-not
9180 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
9181 (append anything-create--actions-private
9182 '(("find-file" . find-file)
9183 ("find-file other window" . find-file-other-window)
9184 ("New buffer" . anything-c-switch-to-buffer)
9185 ("New buffer other window" . switch-to-buffer-other-window)
9186 ("Bookmark Set" . bookmark-set)
9187 ("Set Register" .
9188 (lambda (x) (set-register (read-char "Register: ") x)))
9189 ("Insert Linkd star" . linkd-insert-star)
9190 ("Insert Linkd Tag" . linkd-insert-tag)
9191 ("Insert Linkd Link" . linkd-insert-link)
9192 ("Insert Linkd Lisp" . linkd-insert-lisp)
9193 ("Insert Linkd Wiki" . linkd-insert-wiki)
9194 ("Google Search" . google)))))
9197 ;; Minibuffer History
9200 (defvar anything-c-source-minibuffer-history
9201 '((name . "Minibuffer History")
9202 (header-name . (lambda (name)
9203 (format "%s (%s)" name minibuffer-history-variable)))
9204 (candidates
9205 . (lambda ()
9206 (let ((history (loop
9207 for i in (symbol-value minibuffer-history-variable)
9208 unless (string= "" i) collect i)))
9209 (if (consp (car history))
9210 (mapcar 'prin1-to-string history)
9211 history))))
9212 (migemo)
9213 (action . insert)))
9214 ;; (anything 'anything-c-source-minibuffer-history)
9217 ;;; Elscreen
9220 (defvar anything-c-source-elscreen
9221 '((name . "Elscreen")
9222 (candidates . (lambda ()
9223 (if (cdr (elscreen-get-screen-to-name-alist))
9224 (sort
9225 (loop for sname in (elscreen-get-screen-to-name-alist)
9226 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
9227 finally (return lst))
9228 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
9229 (action . (("Change Screen".
9230 (lambda (candidate)
9231 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
9232 ("Kill Screen(s)".
9233 (lambda (candidate)
9234 (dolist (i (anything-marked-candidates))
9235 (elscreen-goto (- (aref i 1) (aref "0" 0)))
9236 (elscreen-kill))))
9237 ("Only Screen".
9238 (lambda (candidate)
9239 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
9240 (elscreen-kill-others)))))))
9241 ;; (anything 'anything-c-source-elscreen)
9244 ;;;; <System>
9246 ;;; Top (process)
9247 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
9248 "Top command (batch mode). %s is replaced with `frame-width'.")
9249 (defvar anything-c-source-top
9250 '((name . "Top (Press C-c C-u to refresh)")
9251 (init . anything-c-top-init)
9252 (candidates-in-buffer)
9253 (display-to-real . anything-c-top-display-to-real)
9254 (update . anything-c-top-update)
9255 (persistent-action . anything-c-top-sh-persistent-action)
9256 (persistent-help . "SIGTERM")
9257 (action
9258 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
9259 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
9260 ("Copy PID" . (lambda (pid) (kill-new pid))))))
9261 ;; (anything 'anything-c-source-top)
9263 (defun anything-c-top-sh (cmd)
9264 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
9266 (defun anything-c-top-sh-persistent-action (pid)
9267 (delete-other-windows)
9268 (anything-c-top-sh (format "kill -TERM %s" pid))
9269 (anything-force-update))
9271 (defun anything-c-top-init ()
9272 (with-current-buffer (anything-candidate-buffer 'global)
9273 (call-process-shell-command
9274 (format anything-c-top-command
9275 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
9276 nil (current-buffer))))
9278 (defun anything-c-top-display-to-real (line)
9279 (car (split-string line)))
9281 (defun anything-c-top-update ()
9282 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
9283 (anything-c-top-init)))
9285 ;;; Timers
9286 (defvar anything-c-source-absolute-time-timers
9287 '((name . "Absolute Time Timers")
9288 (candidates . timer-list)
9289 (type . timer)))
9290 ;; (anything 'anything-c-source-absolute-time-timers)
9292 (defvar anything-c-source-idle-time-timers
9293 '((name . "Idle Time Timers")
9294 (candidates . timer-idle-list)
9295 (type . timer)))
9296 ;; (anything 'anything-c-source-idle-time-timers)
9298 (defun anything-c-timer-real-to-display (timer)
9299 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
9300 (append timer nil) ;use `append' to convert vector->list
9301 (format "%s repeat=%5S %s(%s)"
9302 (let ((time (list t1 t2 t3)))
9303 (if idle-delay
9304 (format-time-string "idle-for=%5s" time)
9305 (format-time-string "%m/%d %T" time)))
9306 repeat-delay
9307 func
9308 (mapconcat 'prin1-to-string args " "))))
9310 ;;; X RandR resolution change
9311 ;;; FIXME I do not care multi-display.
9312 (defvar anything-c-xrandr-output "VGA")
9313 (defvar anything-c-xrandr-screen "0")
9314 (defvar anything-c-source-xrandr-change-resolution
9315 '((name . "Change Resolution")
9316 (candidates
9317 . (lambda ()
9318 (with-temp-buffer
9319 (call-process "xrandr" nil (current-buffer) nil
9320 "--screen" anything-c-xrandr-screen "-q")
9321 (goto-char 1)
9322 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
9323 collect (match-string 1)))))
9324 (action
9325 ("Change Resolution" . (lambda (mode)
9326 (call-process "xrandr" nil nil nil
9327 "--screen" anything-c-xrandr-screen
9328 "--output" anything-c-xrandr-output
9329 "--mode" mode))))))
9330 ;; (anything 'anything-c-source-xrandr-change-resolution)
9332 ;;; Xfont selection
9335 (defun anything-c-persistent-xfont-action (elm)
9336 "Show current font temporarily"
9337 (let ((current-font (cdr (assoc 'font (frame-parameters))))
9338 (default-font elm))
9339 (unwind-protect
9340 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
9341 (set-frame-font current-font))))
9343 (defvar anything-c-xfonts-cache nil)
9344 (defvar anything-c-source-xfonts
9345 '((name . "X Fonts")
9346 (init . (lambda ()
9347 (unless anything-c-xfonts-cache
9348 (setq anything-c-xfonts-cache
9349 (x-list-fonts "*")))))
9350 (candidates . anything-c-xfonts-cache)
9351 (action . (("Copy to kill ring" . (lambda (elm)
9352 (kill-new elm)))
9353 ("Set Font" . (lambda (elm)
9354 (kill-new elm)
9355 (set-frame-font elm 'keep-size)
9356 (message "New font have been copied to kill ring")))))
9357 (persistent-action . anything-c-persistent-xfont-action)
9358 (persistent-help . "Switch to this font temporarily")))
9359 ;; (anything 'anything-c-source-xfonts)
9361 ;;; 𝕌𝕔𝕤 𝕊𝕪𝕞𝕓𝕠𝕝 𝕔𝕠𝕞𝕡𝕝𝕖𝕥𝕚𝕠𝕟
9364 (defvar anything-c-ucs-max-len 0)
9365 (defun anything-c-calculate-ucs-max-len ()
9366 "Calculate the length of longest `ucs-names' candidate."
9367 (loop with count = 0
9368 for (n . v) in (ucs-names)
9369 for len = (length n)
9370 if (> len count)
9371 do (setq count len)
9372 finally return count))
9374 (defun anything-c-ucs-init ()
9375 "Initialize an anything buffer with ucs symbols.
9376 Only math* symbols are collected."
9377 (unless (> anything-c-ucs-max-len 0)
9378 (setq anything-c-ucs-max-len
9379 (anything-c-calculate-ucs-max-len)))
9380 (with-current-buffer (anything-candidate-buffer
9381 (get-buffer-create "*anything ucs*"))
9382 ;; `ucs-names' fn will not run again, data is cached in
9383 ;; var `ucs-names'.
9384 (loop for (n . v) in (ucs-names)
9385 for len = (length n)
9386 for diff = (+ (- anything-c-ucs-max-len len) 2)
9387 unless (string= "" n)
9388 do (progn (insert (concat
9389 n ":"
9390 (make-string
9391 diff ? )))
9392 (ucs-insert v)
9393 (insert "\n")))))
9395 (defun anything-c-ucs-forward-char (candidate)
9396 (with-anything-current-buffer
9397 (forward-char 1)))
9399 (defun anything-c-ucs-backward-char (candidate)
9400 (with-anything-current-buffer
9401 (forward-char -1)))
9403 (defun anything-c-ucs-delete-backward (candidate)
9404 (with-anything-current-buffer
9405 (delete-char -1)))
9407 (defun anything-c-ucs-insert-char (candidate)
9408 (with-anything-current-buffer
9409 (insert
9410 (replace-regexp-in-string
9411 " " ""
9412 (cadr (split-string candidate ":"))))))
9414 (defun anything-c-ucs-persistent-insert ()
9415 (interactive)
9416 (anything-execute-persistent-action 'action-insert))
9418 (defun anything-c-ucs-persistent-forward ()
9419 (interactive)
9420 (anything-execute-persistent-action 'action-forward))
9422 (defun anything-c-ucs-persistent-backward ()
9423 (interactive)
9424 (anything-execute-persistent-action 'action-back))
9426 (defun anything-c-ucs-persistent-delete ()
9427 (interactive)
9428 (anything-execute-persistent-action 'action-delete))
9430 (defvar anything-c-source-ucs
9431 '((name . "Ucs names")
9432 (init . anything-c-ucs-init)
9433 (candidate-number-limit . 9999)
9434 (candidates-in-buffer)
9435 (mode-line . anything-c-ucs-mode-line-string)
9436 (action-insert . anything-c-ucs-insert-char)
9437 (action-forward . anything-c-ucs-forward-char)
9438 (action-back . anything-c-ucs-backward-char)
9439 (action-delete . anything-c-ucs-delete-backward)
9440 (action . (("Insert" . anything-c-ucs-insert-char)
9441 ("Forward char" . anything-c-ucs-forward-char)
9442 ("Backward char" . anything-c-ucs-backward-char)
9443 ("Delete char backward" . anything-c-ucs-delete-backward))))
9444 "Source for collecting `ucs-names' math symbols.")
9447 ;;; Emacs process
9450 (defvar anything-c-source-emacs-process
9451 '((name . "Emacs Process")
9452 (candidates . (lambda () (mapcar #'process-name (process-list))))
9453 (persistent-action . (lambda (elm)
9454 (delete-process (get-process elm))
9455 (anything-delete-current-selection)))
9456 (persistent-help . "Kill Process")
9457 (action ("Kill Process" . (lambda (elm)
9458 (delete-process (get-process elm)))))))
9459 ;; (anything 'anything-c-source-emacs-process)
9461 ;;; World time
9464 (defvar anything-c-source-time-world
9465 '((name . "Time World List")
9466 (init . (lambda ()
9467 (let ((anything-buffer (anything-candidate-buffer 'global)))
9468 (with-current-buffer anything-buffer
9469 (display-time-world-display display-time-world-list)))))
9470 (candidates-in-buffer)))
9474 ;;; Anything interface for Debian/Ubuntu packages (apt-*)
9477 (defvar anything-c-source-apt
9478 '((name . "APT")
9479 (init . anything-c-apt-init)
9480 (candidates-in-buffer)
9481 (candidate-transformer anything-c-apt-candidate-transformer)
9482 (display-to-real . anything-c-apt-display-to-real)
9483 (requires-pattern . 2)
9484 (delayed)
9485 (action
9486 ("Show package description" . anything-c-apt-cache-show)
9487 ("Install package" . anything-c-apt-install)
9488 ("Remove package" . anything-c-apt-uninstall)
9489 ("Purge package" . anything-c-apt-purge))
9490 (persistent-action . anything-c-apt-persistent-action)
9491 (persistent-help . "Show - C-u Refresh")))
9492 ;; (anything 'anything-c-source-apt)
9494 (defvar anything-c-apt-query "emacs")
9495 (defvar anything-c-apt-search-command "apt-cache search '%s'")
9496 (defvar anything-c-apt-show-command "apt-cache show '%s'")
9497 (defvar anything-c-apt-installed-packages nil)
9498 (defvar anything-c-apt-all-packages nil)
9501 (defun anything-c-apt-refresh ()
9502 "Refresh installed candidates list."
9503 (setq anything-c-apt-installed-packages nil)
9504 (setq anything-c-apt-all-packages nil)
9505 (anything-force-update))
9507 (defun anything-c-apt-persistent-action (candidate)
9508 "Persistent action for APT source."
9509 (if current-prefix-arg
9510 (anything-c-apt-refresh)
9511 (anything-c-apt-cache-show candidate)))
9513 (defun anything-c-apt-candidate-transformer (candidates)
9514 "Show installed candidates in a different color."
9515 (loop
9516 with all
9517 for cand in candidates
9518 for name = (anything-c-apt-display-to-real cand)
9519 if (member name anything-c-apt-installed-packages)
9520 collect (propertize cand 'face 'anything-apt-installed) into all
9521 else collect cand into all finally return all))
9523 (defun anything-c-apt-init ()
9524 "Initialize list of debian packages."
9525 (let ((query ""))
9526 (unless (and anything-c-apt-installed-packages
9527 anything-c-apt-all-packages)
9528 (message "Loading package list...")
9529 (setq anything-c-apt-installed-packages
9530 (with-temp-buffer
9531 (call-process-shell-command "dpkg --get-selections"
9532 nil (current-buffer))
9533 (loop for i in (split-string (buffer-string) "\n" t)
9534 collect (car (split-string i)))))
9535 (setq anything-c-apt-all-packages
9536 (with-current-buffer
9537 (anything-candidate-buffer
9538 (get-buffer-create (format "*anything-apt*")))
9539 (erase-buffer)
9540 (call-process-shell-command
9541 (format anything-c-apt-search-command query)
9542 nil (current-buffer))))
9543 (message "Loading package list done")
9544 (sit-for 0.5))))
9546 (defun anything-c-apt-display-to-real (line)
9547 "Return only name of a debian package.
9548 LINE is displayed like:
9549 package name - description."
9550 (car (split-string line " - ")))
9552 (defun anything-c-shell-command-if-needed (command)
9553 "Run shell command COMMAND to describe package.
9554 If a buffer named COMMAND already exists, just switch to it."
9555 (let ((buf (get-buffer command)))
9556 (anything-c-switch-to-buffer (get-buffer-create command))
9557 (unless buf (insert (shell-command-to-string command)))))
9559 (defun anything-c-apt-cache-show (package)
9560 "Show information on apt package PACKAGE."
9561 (anything-c-shell-command-if-needed
9562 (format anything-c-apt-show-command package)))
9564 (defun anything-c-apt-install (package)
9565 "Run 'apt-get install' shell command on PACKAGE."
9566 (anything-c-apt-generic-action :action 'install))
9568 (defun anything-c-apt-uninstall (package)
9569 "Run 'apt-get remove' shell command on PACKAGE."
9570 (anything-c-apt-generic-action :action 'uninstall))
9572 (defun anything-c-apt-purge (package)
9573 "Run 'apt-get purge' shell command on PACKAGE."
9574 (anything-c-apt-generic-action :action 'purge))
9576 (defun* anything-c-apt-generic-action (&key action)
9577 "Run 'apt-get ACTION'.
9578 Support install, remove and purge actions."
9579 (ansi-term (getenv "SHELL") "anything apt")
9580 (term-line-mode)
9581 (let ((command (case action
9582 ('install "sudo apt-get install ")
9583 ('uninstall "sudo apt-get remove ")
9584 ('purge "sudo apt-get purge ")
9585 (t (error "Unknow action"))))
9586 (beg (point))
9588 (cand-list (mapconcat #'(lambda (x) (format "'%s'" x))
9589 (anything-marked-candidates) " ")))
9590 (goto-char (point-max))
9591 (insert (concat command cand-list))
9592 (setq end (point))
9593 (if (y-or-n-p (format "%s package" (symbol-name action)))
9594 (progn
9595 (setq anything-c-external-commands-list nil)
9596 (setq anything-c-apt-installed-packages nil)
9597 (term-char-mode) (term-send-input))
9598 (delete-region beg end) (term-send-eof) (kill-buffer))))
9600 ;; (anything-c-apt-install "jed")
9603 ;;; Anything UI for gentoo portage.
9606 (defvar anything-c-gentoo-use-flags nil)
9607 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
9608 (defvar anything-c-cache-gentoo nil)
9609 (defvar anything-c-cache-world nil)
9610 (defvar anything-c-source-gentoo
9611 '((name . "Portage sources")
9612 (init . (lambda ()
9613 (get-buffer-create anything-c-gentoo-buffer)
9614 (unless anything-c-cache-gentoo
9615 (anything-c-gentoo-setup-cache))
9616 (unless anything-c-cache-world
9617 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
9618 (anything-c-gentoo-init-list)))
9619 (candidates-in-buffer)
9620 (match . identity)
9621 (candidate-transformer anything-c-highlight-world)
9622 (action . (("Show package" . (lambda (elm)
9623 (anything-c-gentoo-eshell-action elm "eix")))
9624 ("Show history" . (lambda (elm)
9625 (if (member elm anything-c-cache-world)
9626 (anything-c-gentoo-eshell-action elm "genlop -qe")
9627 (message "No infos on packages not yet installed"))))
9628 ("Copy in kill-ring" . kill-new)
9629 ("insert at point" . insert)
9630 ("Browse HomePage" . (lambda (elm)
9631 (let ((urls (anything-c-gentoo-get-url elm)))
9632 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
9633 ("Show extra infos" . (lambda (elm)
9634 (if (member elm anything-c-cache-world)
9635 (anything-c-gentoo-eshell-action elm "genlop -qi")
9636 (message "No infos on packages not yet installed"))))
9637 ("Show use flags" . (lambda (elm)
9638 (anything-c-gentoo-default-action elm "equery" "-C" "u")
9639 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
9640 (font-lock-mode 1)))
9641 ("Run emerge pretend" . (lambda (elm)
9642 (anything-c-gentoo-eshell-action elm "emerge -p")))
9643 ("Emerge" . (lambda (elm)
9644 (anything-gentoo-install elm :action 'install)))
9645 ("Unmerge" . (lambda (elm)
9646 (anything-gentoo-install elm :action 'uninstall)))
9647 ("Show dependencies" . (lambda (elm)
9648 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
9649 ("Show related files" . (lambda (elm)
9650 (anything-c-gentoo-default-action elm "equery" "files")))
9651 ("Refresh" . (lambda (elm)
9652 (anything-c-gentoo-setup-cache)
9653 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
9655 ;; (anything 'anything-c-source-gentoo)
9657 (defun* anything-gentoo-install (candidate &key action)
9658 (setq anything-c-external-commands-list nil)
9659 (ansi-term (getenv "SHELL") "Gentoo emerge")
9660 (term-line-mode)
9661 (let ((command (case action
9662 ('install "sudo emerge -av ")
9663 ('uninstall "sudo emerge -avC ")
9664 (t (error "Unknow action"))))
9665 (elms (mapconcat 'identity (anything-marked-candidates) " "))
9666 (beg (point)) end)
9667 (goto-char (point-max))
9668 (insert (concat command elms))
9669 (setq end (point))
9670 (term-char-mode) (term-send-input)))
9672 (defun anything-c-gentoo-default-action (elm command &rest args)
9673 "Gentoo default action that use `anything-c-gentoo-buffer'."
9674 (if (member elm anything-c-cache-world)
9675 (progn
9676 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9677 (erase-buffer)
9678 (let ((com-list (append args (list elm))))
9679 (apply #'call-process command nil t nil
9680 com-list)))
9681 (message "No infos on packages not yet installed")))
9683 (defvar anything-c-source-use-flags
9684 '((name . "Use Flags")
9685 (init . (lambda ()
9686 (unless anything-c-gentoo-use-flags
9687 (anything-c-gentoo-setup-use-flags-cache))
9688 (anything-c-gentoo-get-use)))
9689 (candidates-in-buffer)
9690 (match . identity)
9691 (candidate-transformer anything-c-highlight-local-use)
9692 (action . (("Description"
9693 . (lambda (elm)
9694 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9695 (erase-buffer)
9696 (apply #'call-process "euse" nil t nil
9697 `("-i"
9698 ,elm))
9699 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
9700 (font-lock-mode 1)))
9701 ("Enable"
9702 . (lambda (elm)
9703 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
9704 ("Disable"
9705 . (lambda (elm)
9706 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
9707 ("Remove"
9708 . (lambda (elm)
9709 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
9710 ("Show which dep use this flag"
9711 . (lambda (elm)
9712 (anything-c-switch-to-buffer anything-c-gentoo-buffer)
9713 (erase-buffer)
9714 (apply #'call-process "equery" nil t nil
9715 `("-C"
9717 ,elm))))))))
9720 ;; (anything 'anything-c-source-use-flags)
9722 (defun anything-c-gentoo-init-list ()
9723 "Initialize buffer with all packages in Portage."
9724 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
9725 (buf (anything-candidate-buffer 'portage-buf)))
9726 (with-current-buffer buf
9727 (dolist (i anything-c-cache-gentoo)
9728 (insert (concat i "\n"))))))
9730 (defun anything-c-gentoo-setup-cache ()
9731 "Set up `anything-c-cache-gentoo'"
9732 (setq anything-c-cache-gentoo
9733 (split-string (with-temp-buffer
9734 (call-process "eix" nil t nil
9735 "--only-names")
9736 (buffer-string)))))
9738 (defun anything-c-gentoo-eshell-action (elm command)
9739 (when (get-buffer "*EShell Command Output*")
9740 (kill-buffer "*EShell Command Output*"))
9741 (message "Wait searching...")
9742 (let ((buf-fname (buffer-file-name anything-current-buffer)))
9743 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
9744 (progn
9745 (save-window-excursion
9746 (pop-to-buffer "*scratch*")
9747 (eshell-command (format "%s %s" command elm)))
9748 (pop-to-buffer "*EShell Command Output*"))
9749 (eshell-command (format "%s %s" command elm)))))
9751 (defun anything-c-gentoo-get-use ()
9752 "Initialize buffer with all use flags."
9753 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
9754 (buf (anything-candidate-buffer 'use-buf)))
9755 (with-current-buffer buf
9756 (dolist (i anything-c-gentoo-use-flags)
9757 (insert (concat i "\n"))))))
9760 (defun anything-c-gentoo-setup-use-flags-cache ()
9761 "Setup `anything-c-gentoo-use-flags'"
9762 (setq anything-c-gentoo-use-flags
9763 (split-string (with-temp-buffer
9764 (call-process "eix" nil t nil
9765 "--print-all-useflags")
9766 (buffer-string)))))
9768 (defun anything-c-gentoo-get-url (elm)
9769 "Return a list of urls from eix output."
9770 (loop
9771 with url-list = (split-string
9772 (with-temp-buffer
9773 (call-process "eix" nil t nil
9774 elm "--format" "<homepage>\n")
9775 (buffer-string)))
9776 with all
9777 for i in url-list
9778 when (and (string-match "^http://.*" i)
9779 (not (member i all)))
9780 collect i into all
9781 finally return all))
9783 (defun anything-c-gentoo-get-world ()
9784 "Return list of all installed package on your system."
9785 (split-string (with-temp-buffer
9786 (call-process "qlist" nil t nil
9787 "-I")
9788 (buffer-string))))
9790 (defun anything-c-gentoo-get-local-use ()
9791 (split-string (with-temp-buffer
9792 (call-process "portageq" nil t nil
9793 "envvar"
9794 "USE")
9795 (buffer-string))))
9798 (defun anything-c-highlight-world (eix)
9799 "Highlight all installed package."
9800 (loop for i in eix
9801 if (member i anything-c-cache-world)
9802 collect (propertize i 'face 'anything-gentoo-match-face)
9803 else
9804 collect i))
9806 (defun anything-c-highlight-local-use (use-flags)
9807 (let ((local-uses (anything-c-gentoo-get-local-use)))
9808 (loop for i in use-flags
9809 if (member i local-uses)
9810 collect (propertize i 'face 'anything-gentoo-match-face)
9811 else
9812 collect i)))
9816 ;;; Anything ratpoison UI
9819 (defvar anything-c-source-ratpoison-commands
9820 '((name . "Ratpoison Commands")
9821 (init . anything-c-ratpoison-commands-init)
9822 (candidates-in-buffer)
9823 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
9824 (display-to-real . anything-c-ratpoison-commands-display-to-real)
9825 (candidate-number-limit)))
9826 ;; (anything 'anything-c-source-ratpoison-commands)
9828 (defun anything-c-ratpoison-commands-init ()
9829 (unless (anything-candidate-buffer)
9830 (with-current-buffer (anything-candidate-buffer 'global)
9831 ;; with ratpoison prefix key
9832 (save-excursion
9833 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
9834 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9835 (replace-match "<ratpoison> \\1: \\2"))
9836 (goto-char (point-max))
9837 ;; direct binding
9838 (save-excursion
9839 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
9840 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
9841 (replace-match "\\1: \\2")))))
9843 (defun anything-c-ratpoison-commands-display-to-real (display)
9844 (and (string-match ": " display)
9845 (substring display (match-end 0))))
9847 (defun anything-c-ratpoison-commands-execute (candidate)
9848 (call-process "ratpoison" nil nil nil "-ic" candidate))
9852 ;;; Anything `completing-read' replacement
9855 (defun anything-comp-read-get-candidates (collection &optional test sort-fn alistp)
9856 "Convert COLLECTION to list removing elements that don't match TEST.
9857 SORT-FN is a predicate to sort COLLECTION.
9858 ALISTP is a flag to not use `all-completions' which doesn't handle alists correctly\
9859 for anything.
9860 If collection is an `obarray', a TEST is needed. See `obarray'."
9861 (let ((cands
9862 (cond ((and (eq collection obarray) test)
9863 (all-completions "" collection test))
9864 ((and (vectorp collection) test)
9865 (loop for i across collection when (funcall test i) collect i))
9866 ((vectorp collection)
9867 (loop for i across collection collect i))
9868 ((and alistp test)
9869 (loop for i in collection when (funcall test i) collect i))
9870 (alistp collection)
9871 ((and collection test)
9872 (all-completions "" collection test))
9873 (t (all-completions "" collection)))))
9874 (if sort-fn (sort cands sort-fn) cands)))
9876 (defun anything-cr-default-transformer (candidates source)
9877 "Default filter candidate function for `anything-comp-read'.
9878 Do nothing, just return candidate list unmodified."
9879 candidates)
9881 (defun* anything-comp-read (prompt collection
9882 &key
9883 test
9884 initial-input
9885 default
9886 preselect
9887 (buffer "*Anything Completions*")
9888 must-match
9889 (requires-pattern 0)
9890 (history nil)
9891 (persistent-action nil)
9892 (persistent-help "DoNothing")
9893 (name "Anything Completions")
9894 (volatile t)
9895 sort
9896 (fc-transformer 'anything-cr-default-transformer)
9897 (marked-candidates nil)
9898 (alistp t))
9899 "Anything `completing-read' emulation.
9900 PROMPT is the prompt name to use.
9901 COLLECTION can be a list, vector, obarray or hash-table.
9902 Keys:
9904 TEST: A predicate called with one arg i.e candidate.
9905 INITIAL-INPUT: Same as initial-input arg in `anything'.
9906 PRESELECT: See preselect arg of `anything'.
9907 DEFAULT: This option is used only for compatibility with regular
9908 Emacs `completing-read'.
9909 BUFFER: Name of anything-buffer.
9910 MUST-MATCH: Candidate selected must be one of COLLECTION.
9911 REQUIRES-PATTERN: Same as anything attribute, default is 0.
9912 HISTORY: A list containing specific history, default is nil.
9913 When it is non--nil, all elements of HISTORY are displayed in
9914 anything-buffer before COLLECTION.
9915 PERSISTENT-ACTION: A function called with one arg i.e candidate.
9916 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
9917 NAME: The name related to this local source.
9918 VOLATILE: Use volatile attribute.
9919 SORT: A predicate to give to `sort' e.g `string-lessp'.
9920 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
9921 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
9922 ALISTP: when non--nil \(default\) cdr of alist is returned otherwise it is the car.
9924 Any prefix args passed during `anything-comp-read' invocation will be recorded
9925 in `anything-current-prefix-arg', otherwise if prefix args where given before
9926 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
9927 That's mean you can pass prefix arg before or after calling
9928 a command that use `anything-comp-read'.
9929 It support now also a function as argument, See `all-completions' for more details."
9930 (when (get-buffer anything-action-buffer)
9931 (kill-buffer anything-action-buffer))
9932 (flet ((action-fn (candidate)
9933 (if marked-candidates
9934 (anything-marked-candidates)
9935 (identity candidate))))
9936 (let ((hist `((name . ,(format "%s History" name))
9937 (candidates . (lambda ()
9938 (let ((all (anything-comp-read-get-candidates
9939 history nil nil ,alistp)))
9940 (anything-fast-remove-dups
9941 (if (and default (not (string= default "")))
9942 (delq nil (cons default (delete default all)))
9943 all)
9944 :test 'equal))))
9945 (persistent-action . ,persistent-action)
9946 (persistent-help . ,persistent-help)
9947 (action . ,'action-fn)))
9948 (src `((name . ,name)
9949 (candidates
9950 . (lambda ()
9951 (let ((cands (anything-comp-read-get-candidates
9952 collection test sort alistp)))
9953 (unless (or must-match (string= anything-pattern ""))
9954 (setq cands (append (list anything-pattern) cands)))
9955 (if (and default (not (string= default "")))
9956 (delq nil (cons default (delete default cands)))
9957 cands))))
9958 (filtered-candidate-transformer ,fc-transformer)
9959 (requires-pattern . ,requires-pattern)
9960 (persistent-action . ,persistent-action)
9961 (persistent-help . ,persistent-help)
9962 (action . ,'action-fn))))
9963 (when volatile (setq src (append src '((volatile)))))
9964 (or (anything
9965 :sources `(,hist ,src)
9966 :input initial-input
9967 :default default
9968 :preselect preselect
9969 :prompt prompt
9970 :resume 'noresume
9971 :buffer buffer)
9972 (keyboard-quit)))))
9974 ;; Generic completing-read
9976 ;; Support also function as collection.
9977 ;; e.g M-x man is supported.
9978 ;; Support hash-table and vectors as collection.
9979 ;; NOTE:
9980 ;; Some crap emacs functions may not be supported
9981 ;; like ffap-alternate-file (bad use of completing-read)
9982 ;; and maybe others.
9983 ;; Provide a mode `anything-completion-mode' which turn on
9984 ;; anything in all `completing-read' and `read-file-name' in Emacs.
9986 (defun anything-completing-read-default
9987 (prompt collection &optional
9988 predicate require-match
9989 initial-input hist def
9990 inherit-input-method)
9991 "An anything replacement of `completing-read'.
9992 This function should be used only as a `completing-read-function'.
9994 Don't use it directly, use instead `anything-comp-read' in your programs \
9995 which is more powerful.
9997 See documentation of `completing-read' and `all-completions' for details."
9998 (let ((init initial-input)
9999 (anything-candidate-number-limit 9999))
10000 (anything-comp-read
10001 prompt collection
10002 :test predicate
10003 :fc-transformer #'(lambda (candidates source)
10004 (loop for i in candidates
10005 if (consp i) collect (car i)
10006 else collect i))
10007 :history (eval (or (car-safe hist) hist))
10008 :must-match require-match
10009 :alistp nil
10010 ;; If DEF is not provided, fallback to empty string
10011 ;; to avoid `thing-at-point' to be appended on top of list
10012 :default (or def "")
10013 :initial-input init)))
10015 (defun anything-generic-read-file-name
10016 (prompt &optional dir default-filename mustmatch initial predicate)
10017 "An anything replacement of `read-file-name'."
10018 (let* ((default (and default-filename
10019 (if (listp default-filename)
10020 (car default-filename)
10021 default-filename)))
10022 (init (or default initial dir default-directory))
10023 (ini-input (and init (expand-file-name init)))
10024 (anything-ff-auto-update-flag nil)
10025 (fname (anything-c-read-file-name
10026 prompt
10027 :initial-input (expand-file-name init dir)
10028 :alistp nil
10029 :test predicate)))
10030 (if mustmatch
10031 (if (y-or-n-p "File does not exists, create buffer?")
10032 fname (error "Abort file does not exists"))
10033 fname)))
10035 (defvar anything-completion-mode-string " AC")
10036 ;;;###autoload
10037 (define-minor-mode anything-completion-mode
10038 "Toggle generic anything completion.
10039 All functions in Emacs that use `completing-read'
10040 or `read-file-name' and friends will use anything interface
10041 when this mode is turned on.
10042 Called with a positive arg, turn on inconditionnaly, with a
10043 negative arg turn off.
10044 You can turn it on with `ac-mode'.
10046 Some crap emacs functions may not be supported,
10047 e.g `ffap-alternate-file' and maybe others."
10048 :group 'anything
10049 :global t
10050 :lighter anything-completion-mode-string
10051 (declare (special completing-read-function))
10052 (if anything-completion-mode
10053 (progn
10054 (setq completing-read-function 'anything-completing-read-default
10055 read-file-name-function 'anything-generic-read-file-name)
10056 (message "Anything completion enabled"))
10057 (setq completing-read-function 'completing-read-default
10058 read-file-name-function 'read-file-name-default)
10059 (message "Anything completion disabled")))
10061 (defalias 'ac-mode 'anything-completion-mode)
10065 ;;; Eshell completion.
10067 ;; Enable like this in .emacs:
10069 ;; (add-hook 'eshell-mode-hook
10070 ;; #'(lambda ()
10071 ;; (define-key eshell-mode-map [remap pcomplete] 'anything-esh-pcomplete)))
10073 (defvar anything-c-source-esh
10074 '((name . "Eshell completions")
10075 (init . (lambda ()
10076 (setq pcomplete-current-completions nil
10077 pcomplete-last-completion-raw nil)))
10078 (candidates . anything-esh-get-candidates)
10079 (action . anything-ec-insert))
10080 "Anything source for Eshell completion.")
10082 ;; Internal.
10083 (defvar anything-ec-target "")
10084 (defun anything-ec-insert (candidate)
10085 "Insert CANDIDATE at point.
10086 This is the same as `ac-insert', just inlined here for compatibility."
10087 (let ((pt (point)))
10088 (when (and anything-ec-target
10089 (search-backward anything-ec-target nil t)
10090 (string= (buffer-substring (point) pt) anything-ec-target))
10091 (delete-region (point) pt)))
10092 (insert candidate))
10094 (defun anything-esh-get-candidates ()
10095 "Get candidates for eshell completion using `pcomplete'."
10096 (catch 'pcompleted
10097 (let* ((pcomplete-stub)
10098 pcomplete-seen pcomplete-norm-func
10099 pcomplete-args pcomplete-last pcomplete-index
10100 (pcomplete-autolist pcomplete-autolist)
10101 (pcomplete-suffix-list pcomplete-suffix-list))
10102 (with-anything-current-buffer
10103 (loop
10104 with table = (pcomplete-completions)
10105 with entry = (condition-case nil
10106 ;; For Emacs24
10107 (funcall (pcomplete-entries) anything-pattern nil nil)
10108 ;; Fall back to this in Emacs23 as pcomplete-entries seem broken.
10109 (error
10111 (let ((fc (car (last (pcomplete-parse-arguments)))))
10112 ;; Check if last arg require fname completion.
10113 (and (file-name-directory fc) fc))))
10114 for i in (if (listp table) table ; Emacs23 or commands.
10115 (all-completions pcomplete-stub table)) ; Emacs24
10116 for file-cand = (and entry (expand-file-name i (file-name-directory entry)))
10117 if (and file-cand (file-exists-p file-cand)) collect file-cand into ls
10118 else collect i into ls
10119 finally return
10120 (if (and entry (not (string= entry "")) (file-exists-p entry))
10121 (append (list (expand-file-name entry default-directory)) ls) ls))))))
10123 ;;; Eshell history.
10126 (defvar anything-c-source-eshell-history
10127 '((name . "Eshell history")
10128 (init . (lambda ()
10129 (with-current-buffer (anything-candidate-buffer 'global)
10130 (insert-file-contents eshell-history-file-name))))
10131 (candidates-in-buffer)
10132 (filtered-candidate-transformer . (lambda (candidates sources)
10133 (reverse candidates)))
10134 (candidate-number-limit . 9999)
10135 (action . (lambda (candidate)
10136 (insert candidate))))
10137 "Anything source for Eshell history.")
10140 ;;; Show completion - an alternative of anything-show-completion.el.
10142 ;; Provide show completion with macro `with-anything-show-completion'.
10145 ;; Internal
10146 (defvar anything-c-show-completion-overlay nil)
10148 ;; Called each time cursor move in anything-buffer.
10149 (defun anything-c-show-completion ()
10150 (with-anything-current-buffer
10151 (overlay-put anything-c-show-completion-overlay
10152 'display (anything-get-selection))))
10154 (defun anything-c-show-completion-init-overlay (beg end)
10155 (with-anything-current-buffer
10156 (and anything-c-turn-on-show-completion
10157 (setq anything-c-show-completion-overlay (make-overlay beg end))
10158 (overlay-put anything-c-show-completion-overlay
10159 'face 'anything-lisp-show-completion))))
10161 (defmacro with-anything-show-completion (beg end &rest body)
10162 "Show anything candidate in an overlay at point.
10163 BEG and END are the beginning and end position of the current completion
10164 in `anything-current-buffer'.
10165 BODY is an anything call where we want to enable show completion.
10166 If `anything-c-turn-on-show-completion' is nil just do nothing."
10167 (declare (indent 2) (debug t))
10168 `(let ((anything-move-selection-after-hook
10169 (and anything-c-turn-on-show-completion
10170 (append (list 'anything-c-show-completion)
10171 anything-move-selection-after-hook))))
10172 (unwind-protect
10173 (progn (anything-c-show-completion-init-overlay ,beg ,end)
10174 ,@body)
10175 (and anything-c-turn-on-show-completion
10176 (delete-overlay anything-c-show-completion-overlay)))))
10179 ;;; Lisp symbol completion.
10182 ;;;###autoload
10183 (defun anything-lisp-completion-at-point ()
10184 "Anything lisp symbol completion at point."
10185 (interactive)
10186 (let* ((data (lisp-completion-at-point))
10187 (beg (car data))
10188 (end (point)) ; 'cadr data' is wrong when no space after point.
10189 (plist (nthcdr 3 data))
10190 (pred (plist-get plist :predicate))
10191 (lgst-len 0)
10192 (target (and beg end (buffer-substring-no-properties beg end)))
10193 (candidates (all-completions target (nth 2 data) pred))
10194 (anything-quit-if-no-candidate t)
10195 (anything-execute-action-at-once-if-one t)
10196 (anything-match-plugin-enabled
10197 (member 'anything-compile-source--match-plugin
10198 anything-compile-source-functions)))
10199 (if candidates
10200 (with-anything-show-completion beg end
10201 ;; Overlay is initialized now in anything-current-buffer.
10202 (anything
10203 :sources
10204 '((name . "Lisp completion")
10205 (init . (lambda ()
10206 (with-current-buffer (anything-candidate-buffer 'global)
10207 (loop for sym in candidates
10208 for len = (length sym)
10209 when (> len lgst-len) do (setq lgst-len len)
10210 do (insert (concat sym "\n"))))))
10211 (candidates-in-buffer)
10212 (persistent-action . (lambda (candidate)
10213 (let ((cursor-in-echo-area t)
10214 mode-line-in-non-selected-windows)
10215 (anything-c-eldoc-show-in-mode-line
10216 (propertize
10217 (anything-c-get-first-line-documentation
10218 (intern candidate))
10219 'face 'anything-lisp-completion-info)))))
10220 (persistent-help . "Show brief doc in mode-line")
10221 (filtered-candidate-transformer anything-lisp-completion-transformer)
10222 (action . (lambda (candidate)
10223 (delete-region beg end)
10224 (insert candidate))))
10225 :input (if anything-match-plugin-enabled (concat target " ") target)))
10226 (message "[No Match]"))))
10228 (defun anything-lisp-completion-transformer (candidates source)
10229 "Anything candidates transformer for lisp completion."
10230 (declare (special lgst-len))
10231 (loop for c in candidates
10232 for sym = (intern c)
10233 for annot = (cond ((commandp sym) " (Com)")
10234 ((fboundp sym) " (Fun)")
10235 ((boundp sym) " (Var)")
10236 ((facep sym) " (Face)"))
10237 for spaces = (make-string (- lgst-len (length c)) ? )
10238 collect (cons (concat c spaces annot) c)))
10240 (defun anything-c-get-first-line-documentation (sym)
10241 "Return first line documentation of symbol SYM.
10242 If SYM is not documented, return \"Not documented\"."
10243 (let ((doc (cond ((fboundp sym)
10244 (documentation sym t))
10245 ((boundp sym)
10246 (documentation-property sym 'variable-documentation t))
10247 ((facep sym)
10248 (face-documentation sym))
10249 (t nil))))
10250 (if (and doc (not (string= doc ""))
10251 ;; `documentation' return "\n\n(args...)"
10252 ;; for CL-style functions.
10253 (not (string-match-p "^\n\n" doc)))
10254 (car (split-string doc "\n"))
10255 "Not documented")))
10257 ;;; File completion.
10259 ;; Complete file name at point.
10260 (defun anything-c-thing-before-point ()
10261 "Get symbol name before point.
10262 Borrowed from anything-complete.el, inlined here for compatibility."
10263 (save-excursion
10264 (let ((beg (point)))
10265 ;; older regexp "\(\\|\\s-\\|^\\|\\_<\\|\r\\|'\\|#'"
10266 (when (re-search-backward
10267 "\\_<" (field-beginning nil nil (point-at-bol)) t)
10268 (buffer-substring-no-properties beg (match-end 0))))))
10270 ;;;###autoload
10271 (defun anything-c-complete-file-name-at-point ()
10272 "Complete file name at point."
10273 (interactive)
10274 (let* ((init (substring-no-properties (thing-at-point 'filename)))
10275 (end (point))
10276 (beg (- (point) (length init)))
10277 (anything-quit-if-no-candidate t)
10278 (anything-execute-action-at-once-if-one t)
10279 completion)
10280 (with-anything-show-completion beg end
10281 (setq completion (anything-c-read-file-name "FileName: "
10282 :initial-input init)))
10283 (anything-c-insert-file-name-completion-at-point completion)))
10285 ;; Internal
10286 (defvar anything-lisp-completion-counter 0)
10287 ;;;###autoload
10288 (defun anything-lisp-completion-at-point-or-indent (arg)
10289 "First call indent and second call complete lisp symbol.
10290 The second call should happen before `anything-lisp-completion-or-indent-delay',
10291 after this delay, next call will indent again.
10292 After completion, next call is always indent.
10293 See that like click and double mouse click.
10294 One hit indent, two quick hits maybe indent and complete."
10295 (interactive "P")
10296 ;; Be sure `indent-for-tab-command' will not try
10297 ;; to use `completion-at-point'.
10298 (let ((tab-always-indent (if (eq tab-always-indent 'complete)
10299 t tab-always-indent)))
10300 (incf anything-lisp-completion-counter)
10301 (unwind-protect
10302 (if (> anything-lisp-completion-counter 1)
10303 (anything-lisp-completion-or-file-name-at-point)
10304 (indent-for-tab-command arg))
10305 ;; After `anything-lisp-completion-or-indent-delay' seconds
10306 ;; reset to 0.
10307 (run-with-timer anything-lisp-completion-or-indent-delay nil
10308 #'(lambda ()
10309 (setq anything-lisp-completion-counter 0)))
10310 ;; Always reset to 0 at second hit.
10311 (when (eq anything-lisp-completion-counter 2)
10312 (setq anything-lisp-completion-counter 0)))))
10314 ;;;###autoload
10315 (defun anything-lisp-completion-or-file-name-at-point ()
10316 "Complete lisp symbol or filename at point.
10317 Filename completion happen if filename is started in
10318 or between double quotes."
10319 (interactive)
10320 (let ((tap (substring-no-properties (thing-at-point 'filename))))
10321 (if (and tap (string-match "^\\(~/\\|/\\|[a-zA-Z]\:/\\).*" tap)
10322 (save-excursion (search-backward "\"" (point-at-bol) t)))
10323 (anything-c-complete-file-name-at-point)
10324 (anything-lisp-completion-at-point))))
10328 ;;; Run Externals commands within Emacs with anything completion
10331 (defvar anything-external-command-history nil)
10333 (defun anything-c-external-commands-list-1 (&optional sort)
10334 "Returns a list of all external commands the user can execute.
10335 If `anything-c-external-commands-list' is non-nil it will
10336 return its contents. Else it calculates all external commands
10337 and sets `anything-c-external-commands-list'."
10338 (if anything-c-external-commands-list
10339 anything-c-external-commands-list
10340 (setq anything-c-external-commands-list
10341 (loop
10342 with paths = (split-string (getenv "PATH") path-separator)
10343 with completions = ()
10344 for dir in paths
10345 when (and (file-exists-p dir) (file-accessible-directory-p dir))
10346 for lsdir = (loop for i in (directory-files dir t)
10347 for bn = (file-name-nondirectory i)
10348 when (and (not (member bn completions))
10349 (not (file-directory-p i))
10350 (file-executable-p i))
10351 collect bn)
10352 append lsdir into completions
10353 finally return (if sort (sort completions 'string-lessp) completions)))))
10355 (defun anything-run-or-raise (exe &optional file)
10356 "Generic command that run asynchronously EXE.
10357 If EXE is already running just jump to his window if `anything-raise-command'
10358 is non--nil.
10359 When FILE argument is provided run EXE with FILE.
10360 In this case EXE must be provided as \"EXE %s\"."
10361 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string
10362 "'%s'" "" exe))))
10363 (proc (if file (concat real-com " " file) real-com)))
10364 (if (get-process proc)
10365 (if anything-raise-command
10366 (shell-command (format anything-raise-command real-com))
10367 (error "Error: %s is already running" real-com))
10368 (when (loop for i in anything-c-external-commands-list thereis real-com)
10369 (message "Starting %s..." real-com)
10370 (if file
10371 (start-process-shell-command proc nil (format exe file))
10372 (start-process-shell-command proc nil real-com))
10373 (set-process-sentinel
10374 (get-process proc)
10375 #'(lambda (process event)
10376 (when (and (string= event "finished\n")
10377 anything-raise-command
10378 (not (anything-c-get-pid-from-process-name real-com)))
10379 (shell-command (format anything-raise-command "emacs")))
10380 (message "%s process...Finished." process))))
10381 (setq anything-c-external-commands-list
10382 (cons real-com
10383 (delete real-com anything-c-external-commands-list))))))
10387 ;;; Generic action functions
10390 (defun anything-c-file-buffers (filename)
10391 "Returns a list of buffer names corresponding to FILENAME."
10392 (let ((name (expand-file-name filename))
10393 (buf-list ()))
10394 (dolist (buf (buffer-list) buf-list)
10395 (let ((bfn (buffer-file-name buf)))
10396 (when (and bfn (string= name bfn))
10397 (push (buffer-name buf) buf-list))))))
10399 (defun anything-revert-buffer (candidate)
10400 (with-current-buffer candidate
10401 (when (or (buffer-modified-p)
10402 (not (verify-visited-file-modtime
10403 (get-buffer candidate))))
10404 (revert-buffer t t))))
10406 (defun anything-revert-marked-buffers (ignore)
10407 (mapc 'anything-revert-buffer (anything-marked-candidates)))
10409 (defun anything-kill-marked-buffers (ignore)
10410 (mapc 'kill-buffer (anything-marked-candidates)))
10412 (defun anything-c-delete-file (file)
10413 "Delete the given file after querying the user.
10414 Ask to kill buffers associated with that file, too."
10415 (let ((buffers (anything-c-file-buffers file)))
10416 (if (< emacs-major-version 24)
10417 ;; `dired-delete-file' in Emacs versions < 24
10418 ;; doesn't support delete-by-moving-to-trash
10419 ;; so use `delete-directory' and `delete-file'
10420 ;; that handle it.
10421 (cond ((and (not (file-symlink-p file))
10422 (file-directory-p file)
10423 (directory-files file t dired-re-no-dot))
10424 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
10425 (delete-directory file 'recursive)))
10426 ((and (not (file-symlink-p file))
10427 (file-directory-p file))
10428 (delete-directory file))
10429 (t (delete-file file)))
10430 (dired-delete-file
10431 file 'dired-recursive-deletes delete-by-moving-to-trash))
10432 (when buffers
10433 (dolist (buf buffers)
10434 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
10435 (kill-buffer buf))))))
10437 (defun anything-get-mailcap-for-file (filename)
10438 "Get the command to use for FILENAME from mailcap files.
10439 The command is like <command %s> and is meant to use with `format'."
10440 (mailcap-parse-mailcaps)
10441 (let* ((ext (file-name-extension filename))
10442 (mime (when ext (mailcap-extension-to-mime ext)))
10443 (result (when mime (mailcap-mime-info mime))))
10444 ;; If elisp file have no associations in .mailcap
10445 ;; `mailcap-maybe-eval' is returned, in this case just return nil.
10446 (when (stringp result) result)))
10448 (defun anything-get-default-program-for-file (filename)
10449 "Try to find a default program to open FILENAME.
10450 Try first in `anything-c-external-programs-associations' and then in mailcap file
10451 if nothing found return nil."
10452 (let* ((ext (file-name-extension filename))
10453 (def-prog (assoc-default ext anything-c-external-programs-associations)))
10454 (cond ((and def-prog (not (string= def-prog "")))
10455 (concat def-prog " %s"))
10456 ((and anything-c-default-external-file-browser
10457 (file-directory-p filename))
10458 (concat anything-c-default-external-file-browser " %s"))
10459 (t (anything-get-mailcap-for-file filename)))))
10461 (defun anything-c-open-file-externally (file)
10462 "Open FILE with an external program.
10463 Try to guess which program to use with `anything-get-default-program-for-file'.
10464 If not found or a prefix arg is given query the user which tool to use."
10465 (let* ((fname (expand-file-name file))
10466 (collection (anything-c-external-commands-list-1 'sort))
10467 (def-prog (anything-get-default-program-for-file fname))
10468 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
10469 ;; Prefix arg or no default program.
10470 (prog1
10471 (anything-comp-read
10472 "Program: " collection
10473 :must-match t
10474 :name "Open file Externally"
10475 :history anything-external-command-history)
10476 ;; Always prompt to set this program as default.
10477 (setq def-prog nil))
10478 ;; No prefix arg or default program exists.
10479 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
10480 (program (concat real-prog-name " '%s'")))
10481 (unless (or def-prog ; Association exists, no need to record it.
10482 ;; Don't try to record non--filenames associations (e.g urls).
10483 (not (file-exists-p fname)))
10484 (when
10485 (y-or-n-p
10486 (format
10487 "Do you want to make `%s' the default program for this kind of files? "
10488 real-prog-name))
10489 (anything-aif (assoc (file-name-extension fname)
10490 anything-c-external-programs-associations)
10491 (setq anything-c-external-programs-associations
10492 (delete it anything-c-external-programs-associations)))
10493 (push (cons (file-name-extension fname)
10494 (read-string
10495 "Program (Add args maybe and confirm): " real-prog-name))
10496 anything-c-external-programs-associations)
10497 (customize-save-variable 'anything-c-external-programs-associations
10498 anything-c-external-programs-associations)))
10499 (anything-run-or-raise program file)
10500 (setq anything-external-command-history
10501 (cons real-prog-name
10502 (delete real-prog-name
10503 (loop for i in anything-external-command-history
10504 when (executable-find i) collect i))))))
10507 (defun anything-c-find-file-or-marked (candidate)
10508 "Open file CANDIDATE or open anything marked files in background."
10509 (let ((marked (anything-marked-candidates))
10510 (ffap-newfile-prompt anything-ff-newfile-prompt-p)
10511 (find-file-wildcards nil))
10512 (if (> (length marked) 1)
10513 ;; Open all marked files in background and display
10514 ;; the first one.
10515 (progn (mapc 'find-file-noselect (cdr marked))
10516 (find-file (car marked)))
10517 (if (and (not (file-exists-p candidate))
10518 (and ffap-url-regexp
10519 (not (string-match ffap-url-regexp candidate)))
10520 (string-match "/$" candidate))
10521 ;; A a non--existing filename ending with /
10522 ;; Create a directory and jump to it.
10523 (when (y-or-n-p (format "Create directory `%s'? " candidate))
10524 (let ((dirfname (directory-file-name candidate)))
10525 (if (file-exists-p dirfname)
10526 (error "Mkdir: Unable to create directory `%s': file exists."
10527 (anything-c-basename dirfname))
10528 (make-directory candidate 'parent)))
10529 (anything-find-files-1 candidate))
10530 ;; A non--existing filename NOT ending with / or
10531 ;; an existing filename, create or jump to it.
10532 (find-file-at-point (car marked))))))
10534 (defun anything-delete-marked-files (ignore)
10535 (let* ((files (anything-marked-candidates))
10536 (len (length files)))
10537 (if (not (y-or-n-p
10538 (format "Delete *%s File(s):\n%s"
10540 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
10541 (message "(No deletions performed)")
10542 (dolist (i files)
10543 (set-text-properties 0 (length i) nil i)
10544 (anything-c-delete-file i))
10545 (message "%s File(s) deleted" len))))
10547 (defun anything-ediff-marked-buffers (candidate &optional merge)
10548 "Ediff 2 marked buffers or CANDIDATE and `anything-current-buffer'.
10549 With optional arg MERGE call `ediff-merge-buffers'."
10550 (let ((lg-lst (length (anything-marked-candidates)))
10551 buf1 buf2)
10552 (case lg-lst
10554 (error "Error:You have to mark at least 1 buffer"))
10556 (setq buf1 anything-current-buffer
10557 buf2 (first (anything-marked-candidates))))
10559 (setq buf1 (first (anything-marked-candidates))
10560 buf2 (second (anything-marked-candidates))))
10562 (error "Error:To much buffers marked!")))
10563 (if merge
10564 (ediff-merge-buffers buf1 buf2)
10565 (ediff-buffers buf1 buf2))))
10567 (defun anything-ediff-marked-buffers-merge (candidate)
10568 "Ediff merge `anything-current-buffer' with CANDIDATE.
10569 See `anything-ediff-marked-buffers'."
10570 (anything-ediff-marked-buffers candidate t))
10572 (defun anything-bookmark-get-bookmark-from-name (bmk)
10573 "Return bookmark name even if it is a bookmark with annotation.
10574 e.g prepended with *.
10575 Return nil if bmk is not a valid bookmark."
10576 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
10577 (if (assoc bookmark bookmark-alist)
10578 bookmark
10579 (when (assoc bmk bookmark-alist)
10580 bmk))))
10582 (defun anything-delete-marked-bookmarks (ignore)
10583 "Delete this bookmark or all marked bookmarks."
10584 (dolist (i (anything-marked-candidates))
10585 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
10586 'batch)))
10588 (defun anything-require-or-error (feature function)
10589 (or (require feature nil t)
10590 (error "Need %s to use `%s'." feature function)))
10592 (defun anything-find-buffer-on-elscreen (candidate)
10593 "Open buffer in new screen, if marked buffers open all in elscreens."
10594 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
10595 (anything-aif (anything-marked-candidates)
10596 (dolist (i it)
10597 (let ((target-screen (elscreen-find-screen-by-buffer
10598 (get-buffer i) 'create)))
10599 (elscreen-goto target-screen)))
10600 (let ((target-screen (elscreen-find-screen-by-buffer
10601 (get-buffer candidate) 'create)))
10602 (elscreen-goto target-screen))))
10604 (defun anything-elscreen-find-file (file)
10605 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
10606 (elscreen-find-file file))
10608 ;;;###autoload
10609 (defun w32-shell-execute-open-file (file)
10610 (interactive "fOpen file:")
10611 (with-no-warnings
10612 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
10613 "/" "\\"
10614 (replace-regexp-in-string ; strip cygdrive paths
10615 "/cygdrive/\\(.\\)" "\\1:"
10616 file nil nil) nil t))))
10618 (defun anything-c-open-file-with-default-tool (file)
10619 "Open FILE with the default tool on this platform."
10620 (if (eq system-type 'windows-nt)
10621 (w32-shell-execute-open-file file)
10622 (start-process "anything-c-open-file-with-default-tool"
10624 (cond ((eq system-type 'gnu/linux)
10625 "xdg-open")
10626 ((or (eq system-type 'darwin) ;; Mac OS X
10627 (eq system-type 'macos)) ;; Mac OS 9
10628 "open"))
10629 file)))
10631 (defun anything-c-open-dired (file)
10632 "Opens a dired buffer in FILE's directory. If FILE is a
10633 directory, open this directory."
10634 (if (file-directory-p file)
10635 (dired file)
10636 (dired (file-name-directory file))
10637 (dired-goto-file file)))
10639 (defun anything-c-display-to-real-line (candidate)
10640 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
10641 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
10642 (error "Line number not found")))
10644 (defun anything-c-action-line-goto (lineno-and-content)
10645 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
10646 (append lineno-and-content
10647 (list (if (and (anything-attr-defined 'target-file)
10648 (not anything-in-persistent-action))
10649 'find-file-other-window
10650 'find-file)))))
10652 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
10653 (apply #'anything-goto-file-line
10654 (if (stringp file-line-content)
10655 ;; Case: filtered-candidate-transformer is skipped
10656 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
10657 file-line-content)))
10659 (require 'compile)
10660 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
10661 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
10663 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
10664 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
10665 (let ((filename (match-string 1 candidate))
10666 (lineno (match-string 2 candidate))
10667 (content (match-string 3 candidate)))
10668 (cons (format "%s:%s\n %s"
10669 (propertize filename 'face compilation-info-face)
10670 (propertize lineno 'face compilation-line-face)
10671 content)
10672 (list (expand-file-name
10673 filename
10674 (or (anything-interpret-value (anything-attr 'default-directory))
10675 (and (anything-candidate-buffer)
10676 (buffer-local-value
10677 'default-directory (anything-candidate-buffer)))))
10678 (string-to-number lineno) content)))))
10680 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
10681 (anything-aif (anything-attr 'before-jump-hook)
10682 (funcall it))
10683 (when file (funcall find-file-function file))
10684 (if (anything-attr-defined 'adjust)
10685 (anything-c-goto-line-with-adjustment lineno content)
10686 (anything-goto-line lineno))
10687 (unless (anything-attr-defined 'recenter)
10688 (set-window-start (get-buffer-window anything-current-buffer) (point)))
10689 (anything-aif (anything-attr 'after-jump-hook)
10690 (funcall it))
10691 (when anything-in-persistent-action
10692 (anything-match-line-color-current-line)))
10694 (defun anything-find-file-as-root (candidate)
10695 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
10697 (defun anything-find-many-files (ignore)
10698 (mapc 'find-file (anything-marked-candidates)))
10700 ;; borrowed from etags.el
10701 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
10702 (defun anything-c-goto-line-with-adjustment (line line-content)
10703 (let ((startpos)
10704 offset found pat)
10705 ;; This constant is 1/2 the initial search window.
10706 ;; There is no sense in making it too small,
10707 ;; since just going around the loop once probably
10708 ;; costs about as much as searching 2000 chars.
10709 (setq offset 1000
10710 found nil
10711 pat (concat (if (eq selective-display t)
10712 "\\(^\\|\^m\\) *" "^ *") ;allow indent
10713 (regexp-quote line-content)))
10714 ;; If no char pos was given, try the given line number.
10715 (setq startpos (progn (anything-goto-line line) (point)))
10716 (or startpos (setq startpos (point-min)))
10717 ;; First see if the tag is right at the specified location.
10718 (goto-char startpos)
10719 (setq found (looking-at pat))
10720 (while (and (not found)
10721 (progn
10722 (goto-char (- startpos offset))
10723 (not (bobp))))
10724 (setq found
10725 (re-search-forward pat (+ startpos offset) t)
10726 offset (* 3 offset))) ; expand search window
10727 (or found
10728 (re-search-forward pat nil t)
10729 (error "not found")))
10730 ;; Position point at the right place
10731 ;; if the search string matched an extra Ctrl-m at the beginning.
10732 (and (eq selective-display t)
10733 (looking-at "\^m")
10734 (forward-char 1))
10735 (beginning-of-line))
10737 (anything-document-attribute 'default-directory "type . file-line"
10738 "`default-directory' to interpret file.")
10739 (anything-document-attribute 'before-jump-hook "type . file-line / line"
10740 "Function to call before jumping to the target location.")
10741 (anything-document-attribute 'after-jump-hook "type . file-line / line"
10742 "Function to call after jumping to the target location.")
10743 (anything-document-attribute 'adjust "type . file-line"
10744 "Search around line matching line contents.")
10745 (anything-document-attribute 'recenter "type . file-line / line"
10746 "`recenter' after jumping.")
10747 (anything-document-attribute 'target-file "type . line"
10748 "Goto line of target-file.")
10750 ;;;###autoload
10751 (defun anything-c-call-interactively (cmd-or-name)
10752 "Execute CMD-OR-NAME as Emacs command.
10753 It is added to `extended-command-history'.
10754 `anything-current-prefix-arg' is used as the command's prefix argument."
10755 (setq extended-command-history
10756 (cons (anything-c-stringify cmd-or-name)
10757 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
10758 (let ((current-prefix-arg anything-current-prefix-arg)
10759 (cmd (anything-c-symbolify cmd-or-name)))
10760 (if (stringp (symbol-function cmd))
10761 (execute-kbd-macro (symbol-function cmd))
10762 (setq this-command cmd)
10763 (call-interactively cmd))))
10765 ;;;###autoload
10766 (defun anything-c-set-variable (var)
10767 "Set value to VAR interactively."
10768 (interactive)
10769 (let ((sym (anything-c-symbolify var)))
10770 (set sym (eval-minibuffer (format "Set %s: " var)
10771 (prin1-to-string (symbol-value sym))))))
10772 ;; (setq hh 12)
10773 ;; (anything-c-set-variable 'hh)
10777 ;;; Persistent Action Helpers
10780 (defvar anything-match-line-overlay-face nil)
10781 (defvar anything-match-line-overlay nil)
10783 (defun anything-match-line-color-current-line (&optional start end buf face rec)
10784 "Highlight and underline current position"
10785 (let ((args (list (or start (line-beginning-position))
10786 (or end (1+ (line-end-position)))
10787 buf)))
10788 (if (not anything-match-line-overlay)
10789 (setq anything-match-line-overlay (apply 'make-overlay args))
10790 (apply 'move-overlay anything-match-line-overlay args)))
10791 (overlay-put anything-match-line-overlay
10792 'face (or face anything-match-line-overlay-face))
10793 (when rec
10794 (goto-char start)
10795 (recenter)))
10797 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
10800 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
10802 (defun anything-match-line-cleanup ()
10803 (when anything-match-line-overlay
10804 (delete-overlay anything-match-line-overlay)
10805 (setq anything-match-line-overlay nil)))
10807 (defun anything-match-line-update ()
10808 (when anything-match-line-overlay
10809 (delete-overlay anything-match-line-overlay)
10810 (anything-match-line-color-current-line)))
10812 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
10813 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
10816 ;;; Actions Transformers
10819 ;;; Files
10820 (defun anything-c-transform-file-load-el (actions candidate)
10821 "Add action to load the file CANDIDATE if it is an emacs lisp
10822 file. Else return ACTIONS unmodified."
10823 (if (member (file-name-extension candidate) '("el" "elc"))
10824 (append actions '(("Load Emacs Lisp File" . load-file)))
10825 actions))
10827 (defun anything-c-transform-file-browse-url (actions candidate)
10828 "Add an action to browse the file CANDIDATE if it in a html
10829 file or URL. Else return ACTIONS unmodified."
10830 (let ((browse-action '("Browse with Browser" . browse-url)))
10831 (cond ((string-match "^http\\|^ftp" candidate)
10832 (cons browse-action actions))
10833 ((string-match "\\.html?$" candidate)
10834 (append actions (list browse-action)))
10835 (t actions))))
10837 ;;; Function
10838 (defun anything-c-transform-function-call-interactively (actions candidate)
10839 "Add an action to call the function CANDIDATE interactively if
10840 it is a command. Else return ACTIONS unmodified."
10841 (if (commandp (intern-soft candidate))
10842 (append actions '(("Call Interactively"
10844 anything-c-call-interactively)))
10845 actions))
10847 ;;;; S-Expressions
10848 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
10849 "If CANDIDATE's `car' is a command, then add an action to
10850 evaluate it and put it onto the `command-history'."
10851 (if (commandp (car (read candidate)))
10852 ;; Make it first entry
10853 (cons '("Eval and put onto command-history" .
10854 (lambda (sexp)
10855 (let ((sym (read sexp)))
10856 (eval sym)
10857 (setq command-history
10858 (cons sym command-history)))))
10859 actions)
10860 actions))
10863 ;;; Candidate Transformers
10866 ;;; Buffers
10867 (defun anything-c-skip-boring-buffers (buffers)
10868 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
10870 (defun anything-c-skip-current-buffer (buffers)
10871 (if anything-allow-skipping-current-buffer
10872 (remove (buffer-name anything-current-buffer) buffers)
10873 buffers))
10875 (defun anything-c-shadow-boring-buffers (buffers)
10876 "Buffers matching `anything-c-boring-buffer-regexp' will be
10877 displayed with the `file-name-shadow' face if available."
10878 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
10880 (defvar anything-c-buffer-display-string-functions
10881 '(anything-c-buffer-display-string--compilation
10882 anything-c-buffer-display-string--shell
10883 anything-c-buffer-display-string--eshell)
10884 "Functions to setup display string for buffer.
10886 Function has one argument, buffer name.
10887 If it returns string, use it.
10888 If it returns nil, display buffer name.
10889 See `anything-c-buffer-display-string--compilation' for example.")
10891 (defun anything-c-transform-buffer-display-string (buffers)
10892 "Setup display string for buffer candidates
10893 using `anything-c-buffer-display-string-functions'."
10894 (loop for buf in buffers
10895 if (consp buf)
10896 collect buf
10897 else
10898 for disp = (progn (set-buffer buf)
10899 (run-hook-with-args-until-success
10900 'anything-c-buffer-display-string-functions buf))
10901 collect (if disp (cons disp buf) buf)))
10903 (defun anything-c-buffer-display-string--compilation (buf)
10904 (anything-aif (car compilation-arguments)
10905 (format "%s: %s [%s]" buf it default-directory)))
10907 (defun anything-c-buffer-display-string--eshell (buf)
10908 (declare (special eshell-history-ring))
10909 (when (eq major-mode 'eshell-mode)
10910 (format "%s: %s [%s]" buf
10911 (ignore-errors (ring-ref eshell-history-ring 0))
10912 default-directory)))
10914 (defun anything-c-buffer-display-string--shell (buf)
10915 (when (eq major-mode 'shell-mode)
10916 (format "%s: %s [%s]" buf
10917 (ignore-errors (ring-ref comint-input-ring 0))
10918 default-directory)))
10920 ;;; Files
10921 (defun anything-c-shadow-boring-files (files)
10922 "Files matching `anything-c-boring-file-regexp' will be
10923 displayed with the `file-name-shadow' face if available."
10924 (anything-c-shadow-entries files anything-c-boring-file-regexp))
10926 (defun anything-c-skip-boring-files (files)
10927 "Files matching `anything-c-boring-file-regexp' will be skipped."
10928 (anything-c-skip-entries files anything-c-boring-file-regexp))
10929 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
10931 (defun anything-c-skip-current-file (files)
10932 "Current file will be skipped."
10933 (remove (buffer-file-name anything-current-buffer) files))
10935 (defun anything-c-w32-pathname-transformer (args)
10936 "Change undesirable features of windows pathnames to ones more acceptable to
10937 other candidate transformers."
10938 (if (eq system-type 'windows-nt)
10939 (mapcar (lambda (x)
10940 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
10941 (mapcar (lambda (y)
10942 (replace-regexp-in-string "\\\\" "/" y)) args))
10943 args))
10945 (defun anything-c-shorten-home-path (files)
10946 "Replaces /home/user with ~."
10947 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
10948 (getenv "HOME"))))
10949 (mapcar (lambda (file)
10950 (if (and (stringp file) (string-match home file))
10951 (cons (replace-match "~" nil nil file) file)
10952 file))
10953 files)))
10955 ;;; Functions
10956 (defun anything-c-mark-interactive-functions (functions)
10957 "Mark interactive functions (commands) with (i) after the function name."
10958 (let (list)
10959 (loop for function in functions
10960 do (push (cons (concat function
10961 (when (commandp (intern-soft function)) " (i)"))
10962 function)
10963 list)
10964 finally (return (nreverse list)))))
10967 ;;; Adaptive Sorting of Candidates
10970 ;; Internal
10971 (defvar anything-c-adaptive-done nil
10972 "nil if history information is not yet stored for the current
10973 selection.")
10975 (defvar anything-c-adaptive-history nil
10976 "Contains the stored history information.
10977 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
10979 (defadvice anything-initial-setup (before anything-c-adaptive-initialize activate)
10980 "Reset `anything-c-adaptive-done' when anything is started."
10981 (when anything-c-use-adaptative-sorting
10982 (setq anything-c-adaptive-done nil)))
10984 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
10985 "Store history information when action is executed on selected candidate."
10986 (when anything-c-use-adaptative-sorting
10987 (anything-c-adaptive-store-selection)))
10989 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
10990 "Store history information when the user goes to the action buffer."
10991 (when anything-c-use-adaptative-sorting
10992 (anything-c-adaptive-store-selection)))
10994 (defun anything-c-source-use-adaptative-p (&optional source-name)
10995 "Return current source only if it use adaptative history, nil otherwise."
10996 (when anything-c-use-adaptative-sorting
10997 (let* ((source (or source-name (anything-get-current-source)))
10998 (adapt-source (or (assoc-default 'filtered-candidate-transformer
10999 (assoc (assoc-default 'type source)
11000 anything-type-attributes))
11001 (assoc-default 'candidate-transformer
11002 (assoc (assoc-default 'type source)
11003 anything-type-attributes))
11004 (assoc-default 'filtered-candidate-transformer source)
11005 (assoc-default 'candidate-transformer source))))
11006 (if (listp adapt-source)
11007 (when (member 'anything-c-adaptive-sort adapt-source) source)
11008 (when (eq adapt-source 'anything-c-adaptive-sort) source)))))
11010 (defun anything-c-adaptive-store-selection ()
11011 "Store history information for the selected candidate."
11012 (unless anything-c-adaptive-done
11013 (setq anything-c-adaptive-done t)
11014 (let ((source (anything-c-source-use-adaptative-p)))
11015 (when source
11016 (let* ((source-name (or (assoc-default 'type source)
11017 (assoc-default 'name source)))
11018 (source-info (or (assoc source-name anything-c-adaptive-history)
11019 (progn
11020 (push (list source-name) anything-c-adaptive-history)
11021 (car anything-c-adaptive-history))))
11022 (selection (anything-get-selection))
11023 (selection-info (progn
11024 (setcdr source-info
11025 (cons
11026 (let ((found (assoc selection (cdr source-info))))
11027 (if (not found)
11028 ;; new entry
11029 (list selection)
11031 ;; move entry to the beginning of the
11032 ;; list, so that it doesn't get
11033 ;; trimmed when the history is
11034 ;; truncated
11035 (setcdr source-info
11036 (delete found (cdr source-info)))
11037 found))
11038 (cdr source-info)))
11039 (cadr source-info)))
11040 (pattern-info (progn
11041 (setcdr selection-info
11042 (cons
11043 (let ((found (assoc anything-pattern (cdr selection-info))))
11044 (if (not found)
11045 ;; new entry
11046 (cons anything-pattern 0)
11048 ;; move entry to the beginning of the
11049 ;; list, so if two patterns used the
11050 ;; same number of times then the one
11051 ;; used last appears first in the list
11052 (setcdr selection-info
11053 (delete found (cdr selection-info)))
11054 found))
11055 (cdr selection-info)))
11056 (cadr selection-info))))
11058 ;; increase usage count
11059 (setcdr pattern-info (1+ (cdr pattern-info)))
11061 ;; truncate history if needed
11062 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
11063 (setcdr selection-info
11064 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
11066 (defun anything-c-adaptative-maybe-load-history ()
11067 (when (and anything-c-use-adaptative-sorting
11068 (file-readable-p anything-c-adaptive-history-file))
11069 (load-file anything-c-adaptive-history-file)))
11071 (add-hook 'emacs-startup-hook 'anything-c-adaptative-maybe-load-history)
11072 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
11074 (defun anything-c-adaptive-save-history (&optional arg)
11075 "Save history information to file given by `anything-c-adaptive-history-file'."
11076 (interactive "p")
11077 (when anything-c-use-adaptative-sorting
11078 (with-temp-buffer
11079 (insert
11080 ";; -*- mode: emacs-lisp -*-\n"
11081 ";; History entries used for anything adaptive display.\n")
11082 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
11083 (current-buffer))
11084 (insert ?\n)
11085 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
11086 (unless arg 'quiet)))))
11088 (defun anything-c-adaptive-sort (candidates source)
11089 "Sort the CANDIDATES for SOURCE by usage frequency.
11090 This is a filtered candidate transformer you can use for the
11091 attribute `filtered-candidate-transformer' of a source in
11092 `anything-sources' or a type in `anything-type-attributes'."
11093 (let* ((source-name (or (assoc-default 'type source)
11094 (assoc-default 'name source)))
11095 (source-info (assoc source-name anything-c-adaptive-history)))
11096 (if source-info
11097 (let ((usage
11098 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
11099 ;; pairs
11100 (mapcar (lambda (candidate-info)
11101 (let ((count 0))
11102 (dolist (pattern-info (cdr candidate-info))
11103 (if (not (equal (car pattern-info)
11104 anything-pattern))
11105 (incf count (cdr pattern-info))
11107 ;; if current pattern is equal to the previously
11108 ;; used one then this candidate has priority
11109 ;; (that's why its count is boosted by 10000) and
11110 ;; it only has to compete with other candidates
11111 ;; which were also selected with the same pattern
11112 (setq count (+ 10000 (cdr pattern-info)))
11113 (return)))
11114 (cons (car candidate-info) count)))
11115 (cdr source-info)))
11116 sorted)
11117 (if (and usage (consp usage))
11118 ;; sort the list in descending order, so candidates with highest
11119 ;; priorty come first
11120 (progn
11121 (setq usage (sort usage (lambda (first second)
11122 (> (cdr first) (cdr second)))))
11124 ;; put those candidates first which have the highest usage count
11125 (dolist (info usage)
11126 (when (member* (car info) candidates
11127 :test 'anything-c-adaptive-compare)
11128 (push (car info) sorted)
11129 (setq candidates (remove* (car info) candidates
11130 :test 'anything-c-adaptive-compare))))
11132 ;; and append the rest
11133 (append (reverse sorted) candidates nil))
11134 (message "Your `%s' is maybe corrupted or too old, \
11135 you should reinitialize it with `anything-c-reset-adaptative-history'"
11136 anything-c-adaptive-history-file)
11137 (sit-for 1)
11138 candidates))
11139 ;; if there is no information stored for this source then do nothing
11140 candidates)))
11142 ;;;###autoload
11143 (defun anything-c-reset-adaptative-history ()
11144 "Delete all `anything-c-adaptive-history' and his file.
11145 Useful when you have a old or corrupted `anything-c-adaptive-history-file'."
11146 (interactive)
11147 (when (y-or-n-p "Really delete all your `anything-c-adaptive-history'? ")
11148 (setq anything-c-adaptive-history nil)
11149 (delete-file anything-c-adaptive-history-file)))
11151 (defun anything-c-adaptive-compare (x y)
11152 "Compare candidates X and Y taking into account that the
11153 candidate can be in (DISPLAY . REAL) format."
11154 (equal (if (listp x)
11155 (cdr x)
11157 (if (listp y)
11158 (cdr y)
11159 y)))
11163 ;;; Outliner
11166 (defvar anything-outline-goto-near-line-flag t)
11167 (defvar anything-outline-using nil)
11168 (defun anything-after-update-hook--outline ()
11169 (if (and (eq anything-outline-using t)
11170 (eq anything-outline-goto-near-line-flag t))
11171 (anything-outline-goto-near-line)))
11172 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
11174 (defun anything-outline-goto-near-line ()
11175 (with-anything-window
11176 ;; TODO need consideration whether to update position by every input.
11177 (when t ; (equal anything-pattern "")
11178 (anything-goto-line 2)
11179 (let ((lineno (with-anything-current-buffer
11180 (line-number-at-pos (car anything-current-position)))))
11181 (block exit
11182 (while (<= (progn (skip-chars-forward " ")
11183 (or (number-at-point) lineno))
11184 lineno)
11185 (forward-line 1)
11186 (when (eobp)
11187 (forward-line -1)
11188 (return-from exit))))
11189 (forward-line -1)
11190 (and (bobp) (forward-line 1))
11191 (and (anything-pos-header-line-p) (forward-line -2))
11192 (anything-mark-current-line)))))
11196 ;;; Plug-in
11199 ;; Plug-in: info-index
11200 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
11201 (let (result)
11202 (unless (anything-candidate-buffer)
11203 (save-window-excursion
11204 (info file)
11205 (let (Info-history
11206 (tobuf (anything-candidate-buffer 'global))
11207 (infobuf (current-buffer))
11208 s e)
11209 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
11210 (Info-goto-node node)
11211 (goto-char (point-min))
11212 (while (search-forward "\n* " nil t)
11213 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
11214 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
11215 (setq s (point-at-bol)
11216 e (point-at-eol))
11217 (with-current-buffer tobuf
11218 (insert-buffer-substring infobuf s e)
11219 (insert "\n"))))))))))
11221 (defun anything-c-info-goto (node-line)
11222 (Info-goto-node (car node-line))
11223 (anything-goto-line (cdr node-line)))
11225 (defun anything-c-info-display-to-real (line)
11226 (and (string-match
11227 ;; This regexp is stolen from Info-apropos-matches
11228 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
11229 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
11230 (string-to-number (or (match-string 3 line) "1")))))
11232 (defun anything-c-make-info-source (source file)
11233 `(,@source
11234 (name . ,(concat "Info Index: " file))
11235 (info-file . ,file)
11236 (init . anything-c-info-init)
11237 (display-to-real . anything-c-info-display-to-real)
11238 (get-line . buffer-substring)
11239 (candidates-in-buffer)
11240 (action ("Goto node" . anything-c-info-goto))))
11242 (defun anything-compile-source--info-index (source)
11243 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
11244 (anything-c-make-info-source source it)
11245 source))
11246 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
11248 (anything-document-attribute 'info-index "info-index plugin"
11249 "Create a source of info index very easily.
11251 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
11253 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
11254 "Index nodes of info file.
11256 If it is omitted, `Info-index-nodes' is used to collect index nodes.
11257 Some info files are missing index specification.
11259 ex. See `anything-c-source-info-screen'.")
11261 ;; Plug-in: candidates-file
11262 (defun anything-compile-source--candidates-file (source)
11263 (if (assoc-default 'candidates-file source)
11264 `((init anything-p-candidats-file-init
11265 ,@(let ((orig-init (assoc-default 'init source)))
11266 (cond ((null orig-init) nil)
11267 ((functionp orig-init) (list orig-init))
11268 (t orig-init))))
11269 (candidates-in-buffer)
11270 ,@source)
11271 source))
11272 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
11274 (defun anything-p-candidats-file-init ()
11275 (destructuring-bind (file &optional updating)
11276 (anything-mklist (anything-attr 'candidates-file))
11277 (setq file (anything-interpret-value file))
11278 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
11279 (when updating
11280 (buffer-disable-undo)
11281 (font-lock-mode -1)
11282 (auto-revert-mode 1)))))
11284 (anything-document-attribute 'candidates-file "candidates-file plugin"
11285 "Use a file as the candidates buffer.
11287 1st argument is a filename, string or function name or variable name.
11288 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
11290 ;; Plug-in: headline
11291 (defun anything-compile-source--anything-headline (source)
11292 (if (assoc-default 'headline source)
11293 (append '((init . anything-headline-init)
11294 (get-line . buffer-substring)
11295 (type . line))
11296 source
11297 '((candidates-in-buffer)
11298 (persistent-help . "Show this line")))
11299 source))
11300 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
11302 (defun anything-headline-init ()
11303 (when (and (anything-current-buffer-is-modified)
11304 (with-anything-current-buffer
11305 (eval (or (anything-attr 'condition) t))))
11306 (anything-headline-make-candidate-buffer
11307 (anything-interpret-value (anything-attr 'headline))
11308 (anything-interpret-value (anything-attr 'subexp)))))
11310 (anything-document-attribute 'headline "Headline plug-in"
11311 "Regexp string for anything-headline to scan.")
11312 (anything-document-attribute 'condition "Headline plug-in"
11313 "A sexp representing the condition to use anything-headline.")
11314 (anything-document-attribute 'subexp "Headline plug-in"
11315 "Display (match-string-no-properties subexp).")
11317 ;; Le Wang: Note on how `anything-head-line-get-candidates' works with a list
11318 ;; of regexps.
11320 ;; 1. Create list of ((title . start-of-match) . hiearchy)
11321 ;; 2. Sort this list by start-of-match.
11322 ;; 3. Go through sorted list and return titles that reflect full hiearchy.
11324 ;; It's quite brilliantly written.
11328 (defun anything-headline-get-candidates (regexp subexp)
11329 (with-anything-current-buffer
11330 (save-excursion
11331 (goto-char (point-min))
11332 (if (functionp regexp) (setq regexp (funcall regexp)))
11333 (let (hierarchy curhead)
11334 (flet ((matched ()
11335 (if (numberp subexp)
11336 (cons (match-string-no-properties subexp) (match-beginning subexp))
11337 (cons (buffer-substring (point-at-bol) (point-at-eol))
11338 (point-at-bol))))
11339 (hierarchies (headlines)
11340 (1+ (loop for (_ . hierarchy) in headlines
11341 maximize hierarchy)))
11342 (vector-0-n (v n)
11343 (loop for i from 0 to hierarchy
11344 collecting (aref curhead i)))
11345 (arrange (headlines)
11346 (unless (null headlines) ; FIX headlines empty bug!
11347 (loop with curhead = (make-vector (hierarchies headlines) "")
11348 for ((str . pt) . hierarchy) in headlines
11349 do (aset curhead hierarchy str)
11350 collecting
11351 (cons
11352 (format "H%d:%s" (1+ hierarchy)
11353 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
11354 pt)))))
11355 (if (listp regexp)
11356 (arrange
11357 (sort
11358 (loop for re in regexp
11359 for hierarchy from 0
11360 do (goto-char (point-min))
11361 appending
11362 (loop
11363 while (re-search-forward re nil t)
11364 collect (cons (matched) hierarchy)))
11365 (lambda (a b) (> (cdar b) (cdar a)))))
11366 (loop while (re-search-forward regexp nil t)
11367 collect (matched))))))))
11370 (defun anything-headline-make-candidate-buffer (regexp subexp)
11371 (with-current-buffer (anything-candidate-buffer 'local)
11372 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
11373 do (insert
11374 (format "%5d:%s\n"
11375 (with-anything-current-buffer
11376 (line-number-at-pos pos))
11377 content)))))
11379 (defun anything-headline-goto-position (pos recenter)
11380 (goto-char pos)
11381 (unless recenter
11382 (set-window-start (get-buffer-window anything-current-buffer) (point))))
11385 ;; Plug-in: persistent-help
11386 (defun anything-compile-source--persistent-help (source)
11387 (append source '((header-line . anything-persistent-help-string))))
11388 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
11390 (defun anything-persistent-help-string ()
11391 (substitute-command-keys
11392 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
11393 (or (anything-interpret-value (anything-attr 'persistent-help))
11394 (anything-aif (or (assoc-default 'persistent-action
11395 (anything-get-current-source))
11396 (assoc-default 'action
11397 (anything-get-current-source)))
11398 (cond ((symbolp it) (symbol-name it))
11399 ((listp it) (or (ignore-errors (caar it)) ""))))
11401 " (keeping session)")))
11403 (anything-document-attribute 'persistent-help "persistent-help plug-in"
11404 "A string to explain persistent-action of this source.
11405 It also accepts a function or a variable name.")
11407 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
11409 ;; Plug-in: Type customize
11410 (defun anything-c-uniq-list (lst)
11411 "Like `remove-duplicates' in CL.
11412 But cut deeper duplicates and test by `equal'. "
11413 (reverse (remove-duplicates (reverse lst) :test 'equal)))
11414 (defvar anything-additional-type-attributes nil)
11415 (defun anything-c-arrange-type-attribute (type spec)
11416 "Override type attributes by `define-anything-type-attribute'.
11418 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
11420 Example: Set `play-sound-file' as default action
11421 (anything-c-arrange-type-attribute 'file
11422 '((action (\"Play sound\" . play-sound-file)
11423 REST ;; Rest of actions (find-file, find-file-other-window, ...)
11426 (add-to-list 'anything-additional-type-attributes
11427 (cons type
11428 (loop with typeattr = (assoc-default type anything-type-attributes)
11429 for (attr . value) in spec
11430 if (listp value)
11431 collect (cons attr
11432 (anything-c-uniq-list
11433 (loop for v in value
11434 if (eq v 'REST)
11435 append (assoc-default attr typeattr)
11436 else
11437 collect v)))
11438 else
11439 collect (cons attr value)))))
11440 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
11442 (defun anything-compile-source--type-customize (source)
11443 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
11444 (append it source)
11445 source))
11446 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
11448 ;; Plug-in: default-action
11449 (defun anything-compile-source--default-action (source)
11450 (anything-aif (assoc-default 'default-action source)
11451 (append `((action ,it ,@(remove it (assoc-default 'action source))))
11452 source)
11453 source))
11454 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
11455 (anything-document-attribute 'default-action "default-action plug-in"
11456 "Default action.")
11459 ;;; Toggle anything-match-plugin
11462 (defvar anything-mp-initial-highlight-delay nil)
11464 ;;;###autoload
11465 (defun anything-c-toggle-match-plugin ()
11466 "Toggle anything-match-plugin."
11467 (interactive)
11468 (let ((anything-match-plugin-enabled
11469 (member 'anything-compile-source--match-plugin
11470 anything-compile-source-functions)))
11471 (flet ((disable-match-plugin ()
11472 (setq anything-compile-source-functions
11473 (delq 'anything-compile-source--match-plugin
11474 anything-compile-source-functions))
11475 (setq anything-mp-initial-highlight-delay
11476 anything-mp-highlight-delay)
11477 (setq anything-mp-highlight-delay nil))
11478 (enable-match-plugin ()
11479 (require 'anything-match-plugin)
11480 (unless anything-mp-initial-highlight-delay
11481 (setq anything-mp-initial-highlight-delay
11482 anything-mp-highlight-delay))
11483 (setq anything-compile-source-functions
11484 (cons 'anything-compile-source--match-plugin
11485 anything-compile-source-functions))
11486 (unless anything-mp-highlight-delay
11487 (setq anything-mp-highlight-delay
11488 anything-mp-initial-highlight-delay))))
11489 (if anything-match-plugin-enabled
11490 (when (y-or-n-p "Really disable match-plugin? ")
11491 (disable-match-plugin)
11492 (message "Anything-match-plugin disabled"))
11493 (when (y-or-n-p "Really enable match-plugin? ")
11494 (enable-match-plugin)
11495 (message "Anything-match-plugin enabled"))))))
11499 ;;; Type Attributes
11502 (define-anything-type-attribute 'buffer
11503 `((action
11504 ("Switch to buffer" . anything-c-switch-to-buffer)
11505 ,(and (locate-library "popwin") '("Switch to buffer in popup window" . popwin:popup-buffer))
11506 ("Switch to buffer other window" . switch-to-buffer-other-window)
11507 ("Switch to buffer other frame" . switch-to-buffer-other-frame)
11508 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
11509 ("Query replace regexp" . anything-c-buffer-query-replace-regexp)
11510 ("Query replace" . anything-c-buffer-query-replace)
11511 ("View buffer" . view-buffer)
11512 ("Display buffer" . display-buffer)
11513 ("Grep buffers (C-u grep all buffers)" . anything-c-grep-buffers)
11514 ("Revert buffer(s)" . anything-revert-marked-buffers)
11515 ("Insert buffer" . insert-buffer)
11516 ("Kill buffer(s)" . anything-kill-marked-buffers)
11517 ("Diff with file" . diff-buffer-with-file)
11518 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
11519 ("Ediff Merge marked buffers" . (lambda (candidate)
11520 (anything-ediff-marked-buffers candidate t))))
11521 (persistent-help . "Show this buffer")
11522 (candidate-transformer anything-c-skip-current-buffer
11523 anything-c-skip-boring-buffers
11524 anything-c-transform-buffer-display-string))
11525 "Buffer or buffer name.")
11527 (define-anything-type-attribute 'file
11528 `((action
11529 ("Find file" . anything-find-many-files)
11530 ,(and (locate-library "popwin") '("Find file in popup window" . popwin:find-file))
11531 ("Find file as root" . anything-find-file-as-root)
11532 ("Find file other window" . find-file-other-window)
11533 ("Find file other frame" . find-file-other-frame)
11534 ("Open dired in file's directory" . anything-c-open-dired)
11535 ("Grep File(s) `C-u recurse'" . anything-find-files-grep)
11536 ("Zgrep File(s) `C-u Recurse'" . anything-ff-zgrep)
11537 ("Pdfgrep File(s)" . anything-ff-pdfgrep)
11538 ("Checksum File" . anything-ff-checksum)
11539 ("Ediff File" . anything-find-files-ediff-files)
11540 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
11541 ("View file" . view-file)
11542 ("Insert file" . insert-file)
11543 ("Delete file(s)" . anything-delete-marked-files)
11544 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
11545 ("Open file with default tool" . anything-c-open-file-with-default-tool)
11546 ("Find file in hex dump" . hexl-find-file))
11547 (persistent-help . "Show this file")
11548 (action-transformer anything-c-transform-file-load-el
11549 anything-c-transform-file-browse-url)
11550 (candidate-transformer anything-c-w32-pathname-transformer
11551 anything-c-skip-current-file
11552 anything-c-skip-boring-files
11553 anything-c-shorten-home-path))
11554 "File name.")
11556 (let ((actions '(("Describe command" . describe-function)
11557 ("Add command to kill ring" . anything-c-kill-new)
11558 ("Go to command's definition" . find-function)
11559 ("Debug on entry" . debug-on-entry)
11560 ("Cancel debug on entry" . cancel-debug-on-entry)
11561 ("Trace function" . trace-function)
11562 ("Trace function (background)" . trace-function-background)
11563 ("Untrace function" . untrace-function))))
11564 (define-anything-type-attribute 'command
11565 `((action ("Call interactively" . anything-c-call-interactively)
11566 ,@actions)
11567 ;; Sort commands according to their usage count.
11568 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
11569 (coerce . anything-c-symbolify)
11570 (persistent-action . describe-function))
11571 "Command. (string or symbol)")
11573 (define-anything-type-attribute 'function
11574 `((action . ,actions)
11575 (action-transformer anything-c-transform-function-call-interactively)
11576 (candidate-transformer anything-c-mark-interactive-functions)
11577 (coerce . anything-c-symbolify))
11578 "Function. (string or symbol)"))
11580 (define-anything-type-attribute 'variable
11581 '((action ("Describe variable" . describe-variable)
11582 ("Add variable to kill ring" . anything-c-kill-new)
11583 ("Go to variable's definition" . find-variable)
11584 ("Set variable" . anything-c-set-variable))
11585 (coerce . anything-c-symbolify))
11586 "Variable.")
11588 (define-anything-type-attribute 'sexp
11589 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
11590 ("Add s-expression to kill ring" . kill-new))
11591 (action-transformer anything-c-transform-sexp-eval-command-sexp))
11592 "String representing S-Expressions.")
11594 (define-anything-type-attribute 'bookmark
11595 `((coerce . anything-bookmark-get-bookmark-from-name)
11596 (action
11597 ("Jump to bookmark" . (lambda (bookmark)
11598 (let ((current-prefix-arg anything-current-prefix-arg))
11599 (bookmark-jump bookmark))
11600 (anything-update)))
11601 ("Jump to BM other window" . (lambda (bookmark)
11602 (bookmark-jump-other-window bookmark)
11603 (anything-update)))
11604 ("Bookmark edit annotation" . bookmark-edit-annotation)
11605 ("Bookmark show annotation" . bookmark-show-annotation)
11606 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
11607 ,@(and (locate-library "bookmark-extensions")
11608 `(("Edit Bookmark" . bmkext-edit-bookmark)))
11609 ("Rename bookmark" . bookmark-rename)
11610 ("Relocate bookmark" . bookmark-relocate)))
11611 "Bookmark name.")
11613 (define-anything-type-attribute 'line
11614 '((display-to-real . anything-c-display-to-real-line)
11615 (action ("Go to Line" . anything-c-action-line-goto)))
11616 "LINENO:CONTENT string, eg. \" 16:foo\".
11618 Optional `target-file' attribute is a name of target file.
11620 Optional `before-jump-hook' attribute is a function with no
11621 arguments which is called before jumping to position.
11623 Optional `after-jump-hook' attribute is a function with no
11624 arguments which is called after jumping to position.
11626 If `adjust' attribute is specified, searches the line whose
11627 content is CONTENT near the LINENO.
11629 If `recenter' attribute is specified, the line is displayed at
11630 the center of window, otherwise at the top of window.
11633 (define-anything-type-attribute 'file-line
11634 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
11635 (multiline)
11636 (action ("Go to" . anything-c-action-file-line-goto)))
11637 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
11639 Optional `default-directory' attribute is a default-directory
11640 FILENAME is interpreted.
11642 Optional `before-jump-hook' attribute is a function with no
11643 arguments which is called before jumping to position.
11645 Optional `after-jump-hook' attribute is a function with no
11646 arguments which is called after jumping to position.
11648 If `adjust' attribute is specified, searches the line whose
11649 content is CONTENT near the LINENO.
11651 If `recenter' attribute is specified, the line is displayed at
11652 the center of window, otherwise at the top of window.
11655 (define-anything-type-attribute 'timer
11656 '((real-to-display . anything-c-timer-real-to-display)
11657 (action ("Cancel Timer" . cancel-timer)
11658 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
11659 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
11660 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
11661 (persistent-help . "Describe Function"))
11662 "Timer.")
11664 ;;;; Default `anything-sources'
11665 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
11666 ;; tend to invoke M-x anything directly. So I offer default setting.
11667 (setq anything-sources
11668 '(anything-c-source-buffers-list
11669 anything-c-source-recentf
11670 anything-c-source-files-in-current-dir+))
11672 ;;; Unit tests are now in ../developer-tools/unit-test-anything-config.el.
11674 (provide 'anything-config)
11676 ;;; Local Variables:
11677 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
11678 ;;; End:
11680 ;; How to save (DO NOT REMOVE!!)
11681 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
11682 ;;; anything-config.el ends here
11684 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
11685 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
11686 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
11687 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
11688 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
11689 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
11690 ;;; LocalWords: dotimes Thierry online vname
11691 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
11692 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
11693 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
11694 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
11695 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
11696 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
11697 ;;; LocalWords: startpos noselect dont desc