anything-config.el (anything-filelist): docstring
[anything-config.git] / anything-config.el
blobab1b7353d5fff08d0e85fbb3f82199393372f331
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 ;; URL: http://www.emacswiki.org/emacs/download/anything-config.el
17 ;; Keywords: anything, anything-config
18 ;; Compatibility: GNU Emacs 22 ~ 23
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-c-describe-anything-bindings'
85 ;; [OBSOLETE] Describe `anything' bindings.
86 ;; `anything-mini'
87 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
88 ;; `anything-for-files'
89 ;; Preconfigured `anything' for opening files.
90 ;; `anything-recentf'
91 ;; Preconfigured `anything' for `recentf'.
92 ;; `anything-info-at-point'
93 ;; Preconfigured `anything' for searching info at point.
94 ;; `anything-info-emacs'
95 ;; Preconfigured anything for Emacs manual index.
96 ;; `anything-show-kill-ring'
97 ;; Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
98 ;; `anything-minibuffer-history'
99 ;; Preconfigured `anything' for `minibuffer-history'.
100 ;; `anything-gentoo'
101 ;; Preconfigured `anything' for gentoo linux.
102 ;; `anything-imenu'
103 ;; Preconfigured `anything' for `imenu'.
104 ;; `anything-google-suggest'
105 ;; Preconfigured `anything' for google search with google suggest.
106 ;; `anything-yahoo-suggest'
107 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
108 ;; `anything-for-buffers'
109 ;; Preconfigured `anything' for buffer.
110 ;; `anything-buffers+'
111 ;; Enhanced preconfigured `anything' for buffer.
112 ;; `anything-bbdb'
113 ;; Preconfigured `anything' for BBDB.
114 ;; `anything-locate'
115 ;; Preconfigured `anything' for Locate.
116 ;; `anything-w3m-bookmarks'
117 ;; Preconfigured `anything' for w3m bookmark.
118 ;; `anything-firefox-bookmarks'
119 ;; Preconfigured `anything' for firefox bookmark.
120 ;; `anything-colors'
121 ;; Preconfigured `anything' for color.
122 ;; `anything-bookmarks'
123 ;; Preconfigured `anything' for bookmarks.
124 ;; `anything-c-pp-bookmarks'
125 ;; Preconfigured `anything' for bookmarks (pretty-printed).
126 ;; `anything-c-insert-latex-math'
127 ;; Preconfigured anything for latex math symbols completion.
128 ;; `anything-register'
129 ;; Preconfigured `anything' for Emacs registers.
130 ;; `anything-man-woman'
131 ;; Preconfigured `anything' for Man and Woman pages.
132 ;; `anything-org-keywords'
133 ;; Preconfigured `anything' for org keywords.
134 ;; `anything-emms'
135 ;; Preconfigured `anything' for emms sources.
136 ;; `anything-eev-anchors'
137 ;; Preconfigured `anything' for eev anchors.
138 ;; `anything-bm-list'
139 ;; Preconfigured `anything' for visible bookmarks.
140 ;; `anything-timers'
141 ;; Preconfigured `anything' for timers.
142 ;; `anything-list-emacs-process'
143 ;; Preconfigured `anything' for emacs process.
144 ;; `anything-occur'
145 ;; Preconfigured Anything for Occur source.
146 ;; `anything-browse-code'
147 ;; Preconfigured anything to browse code.
148 ;; `anything-org-headlines'
149 ;; Preconfigured anything to show org headlines.
150 ;; `anything-kill-buffers'
151 ;; Preconfigured `anything' to kill buffer you selected.
152 ;; `anything-regexp'
153 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
154 ;; `anything-insert-buffer-name'
155 ;; Insert buffer name.
156 ;; `anything-insert-symbol'
157 ;; Insert current symbol.
158 ;; `anything-insert-selection'
159 ;; Insert current selection.
160 ;; `anything-show-buffer-only'
161 ;; [OBSOLETE] Only show sources about buffer.
162 ;; `anything-show-bbdb-only'
163 ;; [OBSOLETE] Only show sources about BBDB.
164 ;; `anything-show-locate-only'
165 ;; [OBSOLETE] Only show sources about Locate.
166 ;; `anything-show-info-only'
167 ;; [OBSOLETE] Only show sources about Info.
168 ;; `anything-show-imenu-only'
169 ;; [OBSOLETE] Only show sources about Imenu.
170 ;; `anything-show-files-only'
171 ;; [OBSOLETE] Only show sources about File.
172 ;; `anything-show-w3m-bookmarks-only'
173 ;; [OBSOLETE] Only show source about w3m bookmark.
174 ;; `anything-show-colors-only'
175 ;; [OBSOLETE] Only show source about color.
176 ;; `anything-show-kill-ring-only'
177 ;; [OBSOLETE] Only show source about kill ring.
178 ;; `anything-show-this-source-only'
179 ;; Only show this source.
180 ;; `anything-test-sources'
181 ;; List all anything sources for test.
182 ;; `anything-select-source'
183 ;; Select source.
184 ;; `anything-toggle-all-marks'
185 ;; Toggle all marks.
186 ;; `anything-find-files-down-one-level'
187 ;; Go down one level like unix command `cd ..'.
188 ;; `anything-find-files'
189 ;; Preconfigured `anything' for anything implementation of `find-file'.
190 ;; `anything-write-file'
191 ;; Preconfigured `anything' providing completion for `write-file'.
192 ;; `anything-insert-file'
193 ;; Preconfigured `anything' providing completion for `insert-file'.
194 ;; `anything-dired-rename-file'
195 ;; Preconfigured `anything' to rename files from dired.
196 ;; `anything-dired-copy-file'
197 ;; Preconfigured `anything' to copy files from dired.
198 ;; `anything-dired-symlink-file'
199 ;; Preconfigured `anything' to symlink files from dired.
200 ;; `anything-dired-hardlink-file'
201 ;; Preconfigured `anything' to hardlink files from dired.
202 ;; `anything-dired-bindings'
203 ;; Replace usual dired commands `C' and `R' by anything ones.
204 ;; `anything-do-grep'
205 ;; Preconfigured anything for grep.
206 ;; `anything-c-grep-precedent-file'
207 ;; Go to precedent file in `anything-do-grep'.
208 ;; `anything-c-grep-next-or-prec-file'
209 ;; Go to next or precedent candidate file in anything grep buffer.
210 ;; `anything-c-etags-select'
211 ;; Preconfigured anything for etags.
212 ;; `anything-filelist'
213 ;; Preconfigured `anything' to open files instantly.
214 ;; `anything-filelist+'
215 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
216 ;; `anything-c-describe-attributes'
217 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
218 ;; `anything-M-x'
219 ;; Preconfigured `anything' for Emacs commands.
220 ;; `anything-manage-advice'
221 ;; Preconfigured `anything' to disable/enable function advices.
222 ;; `anything-bookmark-ext'
223 ;; Preconfigured `anything' for bookmark-extensions sources.
224 ;; `anything-simple-call-tree'
225 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
226 ;; `anything-mark-ring'
227 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
228 ;; `anything-global-mark-ring'
229 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
230 ;; `anything-all-mark-rings'
231 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
232 ;; `anything-yaoddmuse-cache-pages'
233 ;; Fetch the list of files on emacswiki and create cache file.
234 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
235 ;; Preconfigured `anything' to edit or view EmacsWiki page.
236 ;; `anything-yaoddmuse-emacswiki-post-library'
237 ;; Preconfigured `anything' to post library to EmacsWiki.
238 ;; `anything-eval-expression'
239 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
240 ;; `anything-eval-expression-with-eldoc'
241 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
242 ;; `anything-surfraw'
243 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
244 ;; `anything-call-source'
245 ;; Preconfigured `anything' to call anything source.
246 ;; `anything-call-source-from-anything'
247 ;; Call anything source within `anything' session.
248 ;; `anything-execute-anything-command'
249 ;; Preconfigured `anything' to execute preconfigured `anything'.
250 ;; `anything-create-from-anything'
251 ;; Run `anything-create' from `anything' as a fallback.
252 ;; `anything-create'
253 ;; Preconfigured `anything' to do many create actions from STRING.
254 ;; `anything-top'
255 ;; Preconfigured `anything' for top command.
256 ;; `anything-select-xfont'
257 ;; Preconfigured `anything' to select Xfont.
258 ;; `anything-world-time'
259 ;; Preconfigured `anything' to show world time.
260 ;; `anything-apt'
261 ;; Preconfigured `anything' : frontend of APT package manager.
262 ;; `anything-c-shell-command-if-needed'
263 ;; Not documented.
264 ;; `anything-c-run-external-command'
265 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
266 ;; `anything-ratpoison-commands'
267 ;; Preconfigured `anything' to execute ratpoison commands.
268 ;; `anything-c-set-variable'
269 ;; Set value to VAR interactively.
270 ;; `anything-c-adaptive-save-history'
271 ;; Save history information to file given by `anything-c-adaptive-history-file'.
272 ;; `anything-c-toggle-match-plugin'
273 ;; Toggle anything-match-plugin.
275 ;; * User variables defined here:
276 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
277 ;; `anything-c-use-standard-keys'
278 ;; Default Value: nil
279 ;; `anything-c-adaptive-history-file'
280 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
281 ;; `anything-c-adaptive-history-length'
282 ;; Default Value: 50
283 ;; `anything-c-google-suggest-url'
284 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
285 ;; `anything-c-google-suggest-search-url'
286 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
287 ;; `anything-google-suggest-use-curl-p'
288 ;; Default Value: nil
289 ;; `anything-c-yahoo-suggest-url'
290 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
291 ;; `anything-c-yahoo-suggest-search-url'
292 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
293 ;; `anything-c-boring-buffer-regexp'
294 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
295 ;; `anything-c-boring-file-regexp'
296 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
297 ;; `anything-kill-ring-threshold'
298 ;; Default Value: 10
299 ;; `anything-su-or-sudo'
300 ;; Default Value: "su"
301 ;; `anything-for-files-prefered-list'
302 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
303 ;; `anything-create--actions-private'
304 ;; Default Value: nil
305 ;; `anything-allow-skipping-current-buffer'
306 ;; Default Value: t
307 ;; `anything-c-enable-eval-defun-hack'
308 ;; Default Value: t
309 ;; `anything-tramp-verbose'
310 ;; Default Value: 0
311 ;; `anything-raise-command'
312 ;; Default Value: nil
313 ;; `anything-command-map-prefix-key'
314 ;; Default Value: "<f5> a"
315 ;; `anything-c-find-files-show-icons'
316 ;; Default Value: nil
317 ;; `anything-c-find-files-icons-directory'
318 ;; Default Value: "/usr/local/share/emacs/23.2.91/etc/images/tree-widget/default"
319 ;; `anything-c-browse-code-regexp-lisp'
320 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
321 ;; `anything-c-browse-code-regexp-python'
322 ;; Default Value: "\\<def\\>\\|\\<class\\>"
323 ;; `anything-c-browse-code-regexp-alist'
324 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
325 ;; `anything-c-external-programs-associations'
326 ;; Default Value: nil
327 ;; `anything-c-etags-tag-file-name'
328 ;; Default Value: "TAGS"
329 ;; `anything-c-etags-tag-file-search-limit'
330 ;; Default Value: 10
331 ;; `anything-c-filelist-file-name'
332 ;; Default Value: nil
334 ;; * Anything sources defined here:
335 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
336 ;; `anything-c-source-regexp' (Regexp Builder)
337 ;; `anything-c-source-buffers' (Buffers)
338 ;; `anything-c-source-buffer-not-found' (Create buffer)
339 ;; `anything-c-source-buffers+' (Buffers)
340 ;; `anything-c-source-file-name-history' (File Name History)
341 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
342 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
343 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
344 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
345 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
346 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
347 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
348 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
349 ;; `anything-c-source-file-cache-initialized' ()
350 ;; `anything-c-source-file-cache' (File Cache)
351 ;; `anything-c-source-locate' (Locate)
352 ;; `anything-c-source-etags-select' (Etags)
353 ;; `anything-c-source-recentf' (Recentf)
354 ;; `anything-c-source-ffap-guesser' (File at point)
355 ;; `anything-c-source-ffap-line' (File/Lineno at point)
356 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
357 ;; `anything-c-source-filelist' (FileList)
358 ;; `anything-c-source-info-pages' (Info Pages)
359 ;; `anything-c-source-info-elisp' (Info index: elisp)
360 ;; `anything-c-source-info-cl' (Info index: cl)
361 ;; `anything-c-source-info-org' (Info index: org)
362 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
363 ;; `anything-c-source-info-zsh' (Info index: zsh)
364 ;; `anything-c-source-info-bash' (Info index: bash)
365 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
366 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
367 ;; `anything-c-source-info-find' (Info index: find)
368 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
369 ;; `anything-c-source-info-textutils' (Info index: textutils)
370 ;; `anything-c-source-info-libc' (Info index: libc)
371 ;; `anything-c-source-info-make' (Info index: make)
372 ;; `anything-c-source-info-automake' (Info index: automake)
373 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
374 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
375 ;; `anything-c-source-info-emacs' (Info index: emacs)
376 ;; `anything-c-source-info-elib' (Info index: elib)
377 ;; `anything-c-source-info-eieio' (Info index: eieio)
378 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
379 ;; `anything-c-source-info-guile' (Info index: guile)
380 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
381 ;; `anything-c-source-info-goops' (Info index: goops)
382 ;; `anything-c-source-info-screen' (Info index: screen)
383 ;; `anything-c-source-info-latex' (Info index: latex)
384 ;; `anything-c-source-info-gawk' (Info index: gawk)
385 ;; `anything-c-source-info-sed' (Info index: sed)
386 ;; `anything-c-source-info-m4' (Info index: m4)
387 ;; `anything-c-source-info-wget' (Info index: wget)
388 ;; `anything-c-source-info-binutils' (Info index: binutils)
389 ;; `anything-c-source-info-as' (Info index: as)
390 ;; `anything-c-source-info-bfd' (Info index: bfd)
391 ;; `anything-c-source-info-gprof' (Info index: gprof)
392 ;; `anything-c-source-info-ld' (Info index: ld)
393 ;; `anything-c-source-info-diff' (Info index: diff)
394 ;; `anything-c-source-info-flex' (Info index: flex)
395 ;; `anything-c-source-info-grep' (Info index: grep)
396 ;; `anything-c-source-info-gzip' (Info index: gzip)
397 ;; `anything-c-source-info-libtool' (Info index: libtool)
398 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
399 ;; `anything-c-source-info-info' (Info index: info)
400 ;; `anything-c-source-info-gdb' (Info index: gdb)
401 ;; `anything-c-source-info-stabs' (Info index: stabs)
402 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
403 ;; `anything-c-source-info-cvs' (Info index: cvs)
404 ;; `anything-c-source-info-bison' (Info index: bison)
405 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
406 ;; `anything-c-source-info-global' (Info index: global)
407 ;; `anything-c-source-man-pages' (Manual Pages)
408 ;; `anything-c-source-complex-command-history' (Complex Command History)
409 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
410 ;; `anything-c-source-emacs-commands' (Emacs Commands)
411 ;; `anything-c-source-lacarte' (Lacarte)
412 ;; `anything-c-source-emacs-functions' (Emacs Functions)
413 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
414 ;; `anything-c-source-advice' (Function Advice)
415 ;; `anything-c-source-emacs-variables' (Emacs Variables)
416 ;; `anything-c-source-bookmarks' (Bookmarks)
417 ;; `anything-c-source-bookmark-set' (Set Bookmark)
418 ;; `anything-c-source-bm' (Visible Bookmarks)
419 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
420 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
421 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
422 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
423 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
424 ;; `anything-c-source-bookmark-images' (Bookmark Images)
425 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
426 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
427 ;; `anything-c-source-bookmark-info' (Bookmark Info)
428 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
429 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
430 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
431 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
432 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
433 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
434 ;; `anything-c-source-imenu' (Imenu)
435 ;; `anything-c-source-ctags' (Exuberant ctags)
436 ;; `anything-c-source-semantic' (Semantic Tags)
437 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
438 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
439 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
440 ;; `anything-c-source-customize-face' (Customize Face)
441 ;; `anything-c-source-colors' (Colors)
442 ;; `anything-c-source-tracker-search' (Tracker Search)
443 ;; `anything-c-source-mac-spotlight' (mdfind)
444 ;; `anything-c-source-kill-ring' (Kill Ring)
445 ;; `anything-c-source-mark-ring' (mark-ring)
446 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
447 ;; `anything-c-source-register' (Registers)
448 ;; `anything-c-source-latex-math' (Latex Math Menu)
449 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
450 ;; `anything-c-source-rd-headline' (RD HeadLine)
451 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
452 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
453 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
454 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
455 ;; `anything-c-source-org-headline' (Org HeadLine)
456 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
457 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
458 ;; `anything-c-source-eev-anchor' (Anchors)
459 ;; `anything-c-source-org-keywords' (Org Keywords)
460 ;; `anything-c-source-picklist' (Picklist)
461 ;; `anything-c-source-bbdb' (BBDB)
462 ;; `anything-c-source-evaluation-result' (Evaluation Result)
463 ;; `anything-c-source-calculation-result' (Calculation Result)
464 ;; `anything-c-source-google-suggest' (Google Suggest)
465 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
466 ;; `anything-c-source-emms-streams' (Emms Streams)
467 ;; `anything-c-source-emms-dired' (Music Directory)
468 ;; `anything-c-source-emms-files' (Emms files)
469 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
470 ;; `anything-c-source-call-source' (Call anything source)
471 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
472 ;; `anything-c-source-occur' (Occur)
473 ;; `anything-c-source-browse-code' (Browse code)
474 ;; `anything-c-source-create' (Create)
475 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
476 ;; `anything-c-source-elscreen' (Elscreen)
477 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
478 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
479 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
480 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
481 ;; `anything-c-source-xfonts' (X Fonts)
482 ;; `anything-c-source-time-world' (Time World List)
483 ;; `anything-c-source-apt' (APT)
484 ;; `anything-c-source-gentoo' (Portage sources)
485 ;; `anything-c-source-use-flags' (Use Flags)
486 ;; `anything-c-source-emacs-process' (Emacs Process)
487 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
489 ;; *** END auto-documentation
492 ;;; Change log:
494 ;; Change log of this file is found at
495 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
497 ;; Change log of this project is found at
498 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
500 ;;; Contributors:
502 ;; Tamas Patrovics
503 ;; Tassilo Horn <tassilo@member.fsf.org>
504 ;; Vagn Johansen <gonz808@hotmail.com>
505 ;; Mathias Dahl <mathias.dahl@gmail.com>
506 ;; Bill Clementson <billclem@gmail.com>
507 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
508 ;; Drew Adams <drew.adams@oracle.com>
509 ;; Jason McBrayer <jmcbray@carcosa.net>
510 ;; Andy Stewart <lazycat.manatee@gmail.com>
511 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
512 ;; rubikitch <rubikitch@ruby-lang.org>
513 ;; Scott Vokes <vokes.s@gmail.com>
514 ;; Kenichirou Oyama <k1lowxb@gmail.com>
516 ;;; For Maintainers:
518 ;; Evaluate (autodoc-update-all) before commit. This function
519 ;; generates anything-c-source-* / functions / options list.
521 ;; Install also developer-tools/autodoc.el
522 ;; And eval it or run interactively.
524 ;; [EVAL IT] (autodoc-update-all)
526 ;; Please write details documentation about function, then others will
527 ;; read code more easier. -- Andy Stewart
531 ;;; TODO
533 ;; - Fix documentation, now many functions haven't documentations.
536 ;;; Require
537 (require 'anything)
538 (require 'thingatpt)
539 (require 'ffap)
540 (require 'cl)
541 (require 'dired-aux)
542 (require 'tramp)
543 (require 'grep)
545 ;;; Code:
547 ;; version check
548 (let ((version "1.263"))
549 (when (and (string= "1." (substring version 0 2))
550 (string-match "1\.\\([0-9]+\\)" anything-version)
551 (< (string-to-number (match-string 1 anything-version))
552 (string-to-number (substring version 2))))
553 (error "Please update anything.el!!
555 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
557 or M-x install-elisp-from-emacswiki anything.el")))
559 ;; compatibility
560 (unless (fboundp 'window-system)
561 (defun window-system (&optional arg)
562 window-system))
564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
565 (defgroup anything-config nil
566 "Predefined configurations for `anything.el'."
567 :group 'anything)
569 (defcustom anything-c-use-standard-keys nil
570 "Whether use standard keybindings. (no effect)
572 Key definitions in anything-config.el are removed because
573 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
574 minibuffer history, C-s for isearch, etc.
576 If you use `iswitchb' with `anything',
577 evaluate (anything-iswitchb-setup) . Then some bindings that
578 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
579 history, are removed from `anything-map'. "
580 :type 'boolean
581 :group 'anything-config)
583 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
584 "Path of file where history information is stored."
585 :type 'string
586 :group 'anything-config)
588 (defcustom anything-c-adaptive-history-length 50
589 "Maximum number of candidates stored for a source."
590 :type 'number
591 :group 'anything-config)
593 (defcustom anything-c-google-suggest-url
594 "http://google.com/complete/search?output=toolbar&q="
595 "URL used for looking up Google suggestions."
596 :type 'string
597 :group 'anything-config)
599 (defcustom anything-c-google-suggest-search-url
600 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
601 "URL used for Google searching."
602 :type 'string
603 :group 'anything-config)
605 (defcustom anything-google-suggest-use-curl-p nil
606 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
607 Otherwise `url-retrieve-synchronously' is used."
608 :type 'boolean
609 :group 'anything-config)
611 (defcustom anything-c-yahoo-suggest-url
612 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
613 "Url used for looking up Yahoo suggestions."
614 :type 'string
615 :group 'anything-config)
617 (defcustom anything-c-yahoo-suggest-search-url
618 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
619 "Url used for Yahoo searching."
620 :type 'string
621 :group 'anything-config)
623 (defcustom anything-c-boring-buffer-regexp
624 (rx (or
625 (group bos " ")
626 ;; anything-buffer
627 "*anything"
628 ;; echo area
629 " *Echo Area" " *Minibuf"))
630 "The regexp that match boring buffers.
631 Buffer candidates matching this regular expression will be
632 filtered from the list of candidates if the
633 `anything-c-skip-boring-buffers' candidate transformer is used, or
634 they will be displayed with face `file-name-shadow' if
635 `anything-c-shadow-boring-buffers' is used."
636 :type 'string
637 :group 'anything-config)
638 ;; (string-match anything-c-boring-buffer-regexp "buf")
639 ;; (string-match anything-c-boring-buffer-regexp " hidden")
640 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
642 (defcustom anything-c-boring-file-regexp
643 (rx (or
644 ;; Boring directories
645 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
646 ;; Boring files
647 (and line-start ".#")
648 (and (or ".class" ".la" ".o" "~") eol)))
649 "The regexp that match boring files.
650 File candidates matching this regular expression will be
651 filtered from the list of candidates if the
652 `anything-c-skip-boring-files' candidate transformer is used, or
653 they will be displayed with face `file-name-shadow' if
654 `anything-c-shadow-boring-files' is used."
655 :type 'string
656 :group 'anything-config)
658 (defcustom anything-kill-ring-threshold 10
659 "*Minimum length to be listed by `anything-c-source-kill-ring'."
660 :type 'integer
661 :group 'anything-config)
663 (defcustom anything-su-or-sudo "su"
664 "What command to use for root access."
665 :type 'string
666 :group 'anything-config)
668 (defcustom anything-for-files-prefered-list
669 '(anything-c-source-ffap-line
670 anything-c-source-ffap-guesser
671 anything-c-source-buffers+
672 anything-c-source-recentf
673 anything-c-source-bookmarks
674 anything-c-source-file-cache
675 anything-c-source-files-in-current-dir+
676 anything-c-source-locate)
677 "Your prefered sources to find files."
678 :type 'list
679 :group 'anything-config)
681 (defcustom anything-create--actions-private nil
682 "User defined actions for `anything-create' / `anything-c-source-create'.
683 It is a list of (DISPLAY . FUNCTION) pairs like `action'
684 attribute of `anything-sources'.
686 It is prepended to predefined pairs."
687 :type 'list
688 :group 'anything-config)
690 (defcustom anything-allow-skipping-current-buffer t
691 "Show current buffer or not in anything buffer"
692 :type 'boolean
693 :group 'anything-config)
695 (defcustom anything-c-enable-eval-defun-hack t
696 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
697 This hack is invoked when pressing C-M-x in the form \
698 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
699 :type 'boolean
700 :group 'anything-config)
702 (defcustom anything-tramp-verbose 0
703 "*Just like `tramp-verbose' but specific to anything.
704 When set to 0 don't show tramp messages in anything.
705 If you want to have the default tramp messages set it to 3."
706 :type 'integer
707 :group 'anything-config)
709 (defcustom anything-raise-command nil
710 "*A shell command to jump to a window running specific program.
711 Need external program wmctrl.
712 This will be use with `format', so use something like \"wmctrl -xa %s\"."
713 :type 'string
714 :group 'anything-config)
716 (defun anything-set-anything-command-map-prefix-key (var key)
717 (when (boundp 'anything-command-map-prefix-key)
718 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
719 (setq anything-command-map-prefix-key key)
720 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
721 'anything-command-map))
723 (defcustom anything-command-map-prefix-key "<f5> a"
724 "*The prefix key for all `anything-command-map' commands.
726 !!WARNING!!
727 This default value is very likely to be changed,
728 because it is under discussion."
729 :type 'string
730 :set 'anything-set-anything-command-map-prefix-key
731 :group 'anything-config)
733 (defcustom anything-c-find-files-show-icons nil
734 "*Whether show or hide icons in `anything-find-files'."
735 :type 'boolean
736 :group 'anything-config)
738 (defcustom anything-c-find-files-icons-directory
739 (and (window-system)
740 (dolist (i image-load-path)
741 (if (file-directory-p (expand-file-name "tree-widget/default" (eval i)))
742 (return (expand-file-name "tree-widget/default" (eval i))))))
743 "*Default path where to find files and directory icons."
744 :type 'string
745 :group 'anything-config)
747 (defcustom anything-c-browse-code-regexp-lisp
748 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
749 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
750 "*Regexp used to parse lisp buffer when browsing code."
751 :type 'string
752 :group 'anything-config)
754 (defcustom anything-c-browse-code-regexp-python
755 "\\<def\\>\\|\\<class\\>"
756 "*Regexp used to parse python buffer when browsing code."
757 :type 'string
758 :group 'anything-config)
760 (defcustom anything-c-browse-code-regexp-alist
761 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
762 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
763 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
764 (python-mode . ,anything-c-browse-code-regexp-python))
765 "*Alist to store regexps for browsing code corresponding \
766 to a specific `major-mode'."
767 :type 'list
768 :group 'anything-config)
770 (defcustom anything-c-external-programs-associations nil
771 "*Alist to store externals programs associated with file extension.
772 This variable overhide setting in .mailcap file.
773 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
774 :type 'list
775 :group 'anything-config)
777 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
778 ;; TODO: This should be integrated in anything.el instead of having
779 ;; a defadvice here.
781 (defvar anything-current-prefix-arg nil
782 "Record `current-prefix-arg' when exiting minibuffer.
783 It will be cleared at start of next `anything' call when \
784 `anything-before-initialize-hook' is called.")
786 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
787 (unless anything-current-prefix-arg
788 (setq anything-current-prefix-arg current-prefix-arg)))
790 ;; using this hook instead of `anything-after-action-hook'
791 ;; allow to record the prefix args and keep their values
792 ;; when using `anything-comp-read'.
793 ;; i.e when quitting `anything-comp-read' prefix args are preserved
794 ;; for the following action.
795 (add-hook 'anything-before-initialize-hook
796 (lambda () (setq anything-current-prefix-arg nil)))
798 ;;;###autoload
799 (defun anything-configuration ()
800 "Customize `anything'."
801 (interactive)
802 (customize-group "anything-config"))
804 ;;; Anything-command-map
805 ;;;###autoload
806 (defvar anything-command-map)
807 (define-prefix-command 'anything-command-map)
809 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
810 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
811 (define-key anything-command-map (kbd "e") 'anything-c-etags-select)
812 (define-key anything-command-map (kbd "l") 'anything-locate)
813 (define-key anything-command-map (kbd "s") 'anything-surfraw)
814 (define-key anything-command-map (kbd "r") 'anything-regexp)
815 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
816 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
817 (define-key anything-command-map (kbd "#") 'anything-emms)
818 (define-key anything-command-map (kbd "m") 'anything-man-woman)
819 (define-key anything-command-map (kbd "t") 'anything-top)
820 (define-key anything-command-map (kbd "i") 'anything-imenu)
821 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
822 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
823 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
824 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
825 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
826 (define-key anything-command-map (kbd "f") 'anything-for-files)
827 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
828 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
829 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
830 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
831 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
832 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
833 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
834 (define-key anything-command-map (kbd "c") 'anything-colors)
835 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
836 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
837 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
838 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
839 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
840 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers+)
841 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
842 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
843 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
845 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
846 ;; minibuffer-local-filename-must-match-map.
847 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
848 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
849 (dolist (map (list minibuffer-local-filename-completion-map
850 minibuffer-local-completion-map
851 minibuffer-local-must-match-filename-map
852 minibuffer-local-filename-must-match-map
853 minibuffer-local-map
854 minibuffer-local-isearch-map
855 minibuffer-local-must-match-map
856 minibuffer-local-ns-map))
857 (define-key map "\C-r" 'anything-minibuffer-history))
859 ;;; Menu
860 (easy-menu-define nil global-map
861 "`anything' menu"
862 '("Anything"
863 ["All anything commands" anything-execute-anything-command t]
864 ["Find any Files/Buffers" anything-for-files t]
865 "----"
866 ("Files:"
867 ["Find files" anything-find-files t]
868 ["Recent Files" anything-recentf t]
869 ["Locate" anything-locate t]
870 ["Bookmarks" anything-c-pp-bookmarks t])
871 ("Buffers:"
872 ["Find buffers" anything-buffers+ t])
873 ("Commands:"
874 ["Emacs Commands" anything-M-x t]
875 ["Externals Commands" anything-c-run-external-command t])
876 ("Info:"
877 ["Info at point" anything-info-at-point t]
878 ["Emacs Manual index" anything-info-emacs t])
879 ("Org:"
880 ["Org keywords" anything-org-keywords t]
881 ["Org headlines" anything-org-headlines t])
882 ("Tools:"
883 ["Occur" anything-occur t]
884 ["Grep" anything-do-grep t]
885 ["Etags" anything-c-etags-select t]
886 ["Browse Kill ring" anything-show-kill-ring t]
887 ["Browse register" anything-register t]
888 ["Browse code" anything-browse-code t]
889 ["Mark Ring" anything-all-mark-rings t]
890 ["Regexp handler" anything-regexp t]
891 ["Colors & Faces" anything-colors t]
892 ["Show xfonts" anything-select-xfont t]
893 ["Imenu" anything-imenu t]
894 ["Google Suggest" anything-google-suggest t]
895 ["Eval expression" anything-eval-expression-with-eldoc t]
896 ["Calcul expression" anything-calcul-expression t]
897 ["Man pages" anything-man-woman t]
898 ["Top externals process" anything-top t]
899 ["Emacs internals process" anything-list-emacs-process t])
900 "----"
901 ["Prefered Options" anything-configuration t]))
904 ;;; Documentation
905 ;; It is replaced by `anything-help'
906 (defun anything-c-describe-anything-bindings ()
907 "[OBSOLETE] Describe `anything' bindings."
908 (interactive)
909 (anything-run-after-quit
910 #'(lambda ()
911 (with-current-buffer (get-buffer-create "*Anything Help*")
912 (erase-buffer)
913 (insert
914 (substitute-command-keys
915 "The keys that are defined for `anything' are:
916 \\{anything-map}")))
917 (pop-to-buffer "*Anything Help*")
918 (goto-char (point-min)))))
920 ;; Use `describe-mode' key in `global-map'
921 ;; (dolist (k (where-is-internal 'describe-mode global-map))
922 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
924 ;;; Help message
925 (defun anything-c-list-preconfigured-anything ()
926 (loop with doc
927 with sym
928 for entry in (cdr (assoc
929 (file-truename (locate-library "anything-config"))
930 load-history))
931 if (and (consp entry)
932 (eq (car entry) 'defun)
933 (string-match "^Preconfigured.+$"
934 (setq doc (or (documentation (setq sym (cdr entry)))
935 ""))))
936 collect (cons sym (match-string 0 doc))))
938 (defun anything-c-format-preconfigured-anything ()
939 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
940 (anything-c-list-preconfigured-anything)))
942 (setq anything-help-message
943 (lambda ()
944 (concat
945 "\\<anything-map>"
946 "`anything' is QuickSilver-like candidate-selection framework.
948 Narrow the list by typing some pattern,
949 Multiple patterns are allowed by splitting by space.
950 Select with natural Emacs operations, choose with RET.
952 If you have any problems, press C-c C-x C-b!!
953 Feel free to send bug reports. I'll fix them.
954 The steps are described in the beginning of anything.el file.
956 == Basic Operations ==
957 C-p, Up: Previous Line
958 C-n, Down : Next Line
959 M-v, PageUp : Previous Page
960 C-v, PageDown : Next Page
961 Enter : Execute first (default) action / Select
962 M-< : First Line
963 M-> : Last Line
964 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
965 M-PageDown, C-M-v : Next Page (other-window)
967 Tab, C-i : Show action list
968 Left : Previous Source
969 Right, C-o : Next Source
970 C-k : Delete pattern
971 C-z : Persistent Action (Execute action with anything session kept)
972 C-c C-x C-b: Send a bug report
974 == Shortcuts For 2nd/3rd Action ==
975 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
976 \\[anything-select-3rd-action] : Execute 3rd Action
978 == Visible Marks ==
979 Visible marks store candidate. Some actions uses marked candidates.
981 \\[anything-toggle-visible-mark] : Toggle Visible Mark
982 \\[anything-prev-visible-mark] : Previous Mark
983 \\[anything-next-visible-mark] : Next Mark
985 == Miscellaneous Commands ==
986 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
987 \\[anything-quit-and-find-file] : Drop into `find-file'
988 \\[anything-delete-current-selection] : Delete Selected Item (visually)
989 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
990 \\[anything-yank-selection] : Yank Selected Item Into Pattern
991 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
992 \\[anything-force-update] : Recalculate And Redisplay Candidates
994 == Global Commands ==
995 \\<global-map>\\[anything-resume] revives last `anything' session.
996 It is very useful, so you should bind any key.
998 Single source is executed by \\[anything-call-source].
1000 == Preconfigured `anything' ==
1001 Preconfigured `anything' is commands that uses `anything' interface.
1002 You can use them without configuration.
1005 (apply 'concat (anything-c-format-preconfigured-anything))
1007 Enjoy!")))
1009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1010 ;;;###autoload
1011 (defun anything-mini ()
1012 "Preconfigured `anything' lightweight version (buffer -> recentf)."
1013 (interactive)
1014 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf)
1015 "*anything mini*"))
1016 ;;;###autoload
1017 (defun anything-for-files ()
1018 "Preconfigured `anything' for opening files.
1019 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
1020 (interactive)
1021 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
1023 ;;;###autoload
1024 (defun anything-recentf ()
1025 "Preconfigured `anything' for `recentf'."
1026 (interactive)
1027 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
1029 ;;;###autoload
1030 (defun anything-info-at-point ()
1031 "Preconfigured `anything' for searching info at point."
1032 (interactive)
1033 (anything '(anything-c-source-info-elisp
1034 anything-c-source-info-cl
1035 anything-c-source-info-pages)
1036 (thing-at-point 'symbol) nil nil nil "*anything info*"))
1038 ;;;###autoload
1039 (defun anything-info-emacs ()
1040 "Preconfigured anything for Emacs manual index."
1041 (interactive)
1042 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
1044 ;;;###autoload
1045 (defun anything-show-kill-ring ()
1046 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
1047 You may bind this command to M-y."
1048 (interactive)
1049 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
1051 ;;;###autoload
1052 (defun anything-minibuffer-history ()
1053 "Preconfigured `anything' for `minibuffer-history'."
1054 (interactive)
1055 (let ((enable-recursive-minibuffers t))
1056 (anything-other-buffer 'anything-c-source-minibuffer-history
1057 "*anything minibuffer-history*")))
1059 ;;;###autoload
1060 (defun anything-gentoo ()
1061 "Preconfigured `anything' for gentoo linux."
1062 (interactive)
1063 (anything-other-buffer '(anything-c-source-gentoo
1064 anything-c-source-use-flags)
1065 "*anything gentoo*"))
1067 ;;;###autoload
1068 (defun anything-imenu ()
1069 "Preconfigured `anything' for `imenu'."
1070 (interactive)
1071 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
1073 ;;;###autoload
1074 (defun anything-google-suggest ()
1075 "Preconfigured `anything' for google search with google suggest."
1076 (interactive)
1077 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
1079 ;;;###autoload
1080 (defun anything-yahoo-suggest ()
1081 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1082 (interactive)
1083 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
1085 ;;; Converted from anything-show-*-only
1086 ;;;###autoload
1087 (defun anything-for-buffers ()
1088 "Preconfigured `anything' for buffer."
1089 (interactive)
1090 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
1092 ;;;###autoload
1093 (defun anything-buffers+ ()
1094 "Enhanced preconfigured `anything' for buffer."
1095 (interactive)
1096 (anything-other-buffer 'anything-c-source-buffers+ "*anything buffers*"))
1098 ;;;###autoload
1099 (defun anything-bbdb ()
1100 "Preconfigured `anything' for BBDB.
1102 Needs BBDB.
1104 http://bbdb.sourceforge.net/"
1105 (interactive)
1106 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
1108 ;;;###autoload
1109 (defun anything-locate ()
1110 "Preconfigured `anything' for Locate.
1111 Note you can add locate command after entering pattern.
1112 See man locate for more infos."
1113 (interactive)
1114 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
1116 ;;;###autoload
1117 (defun anything-w3m-bookmarks ()
1118 "Preconfigured `anything' for w3m bookmark.
1120 Needs w3m and emacs-w3m.
1122 http://w3m.sourceforge.net/
1123 http://emacs-w3m.namazu.org/"
1124 (interactive)
1125 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1126 "*anything w3m bookmarks*"))
1128 ;;;###autoload
1129 (defun anything-firefox-bookmarks ()
1130 "Preconfigured `anything' for firefox bookmark.
1131 You will have to enable html bookmarks in firefox:
1132 open about:config in firefox and double click on this line to enable value \
1133 to true:
1135 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1137 You should have now:
1139 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1141 After closing firefox, you will be able to browse you bookmarks.
1143 (interactive)
1144 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1145 "*Anything Firefox*"))
1147 ;;;###autoload
1148 (defun anything-colors ()
1149 "Preconfigured `anything' for color."
1150 (interactive)
1151 (anything-other-buffer
1152 '(anything-c-source-colors anything-c-source-customize-face)
1153 "*anything colors*"))
1155 ;;;###autoload
1156 (defun anything-bookmarks ()
1157 "Preconfigured `anything' for bookmarks."
1158 (interactive)
1159 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
1161 ;;;###autoload
1162 (defun anything-c-pp-bookmarks ()
1163 "Preconfigured `anything' for bookmarks (pretty-printed)."
1164 (interactive)
1165 (anything-other-buffer '(anything-c-source-bookmarks-local
1166 anything-c-source-bookmarks-su
1167 anything-c-source-bookmarks-ssh)
1168 "*anything pp bookmarks*"))
1170 ;;;###autoload
1171 (defun anything-c-insert-latex-math ()
1172 "Preconfigured anything for latex math symbols completion."
1173 (interactive)
1174 (anything-other-buffer 'anything-c-source-latex-math "*anything latex*"))
1176 ;;;###autoload
1177 (defun anything-register ()
1178 "Preconfigured `anything' for Emacs registers."
1179 (interactive)
1180 (anything-other-buffer 'anything-c-source-register "*anything register*"))
1182 ;;;###autoload
1183 (defun anything-man-woman ()
1184 "Preconfigured `anything' for Man and Woman pages."
1185 (interactive)
1186 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
1188 ;;;###autoload
1189 (defun anything-org-keywords ()
1190 "Preconfigured `anything' for org keywords."
1191 (interactive)
1192 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
1194 ;;;###autoload
1195 (defun anything-emms ()
1196 "Preconfigured `anything' for emms sources."
1197 (interactive)
1198 (anything '(anything-c-source-emms-streams
1199 anything-c-source-emms-files
1200 anything-c-source-emms-dired)
1201 nil nil nil nil
1202 "*Anything Emms*"))
1204 ;;;###autoload
1205 (defun anything-eev-anchors ()
1206 "Preconfigured `anything' for eev anchors."
1207 (interactive)
1208 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
1210 ;;;###autoload
1211 (defun anything-bm-list ()
1212 "Preconfigured `anything' for visible bookmarks.
1214 Needs bm.el
1216 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1217 (interactive)
1218 (let ((anything-outline-using t))
1219 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
1221 ;;;###autoload
1222 (defun anything-timers ()
1223 "Preconfigured `anything' for timers."
1224 (interactive)
1225 (anything-other-buffer '(anything-c-source-absolute-time-timers
1226 anything-c-source-idle-time-timers)
1227 "*anything timers*"))
1229 ;;;###autoload
1230 (defun anything-list-emacs-process ()
1231 "Preconfigured `anything' for emacs process."
1232 (interactive)
1233 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
1235 ;;;###autoload
1236 (defun anything-occur ()
1237 "Preconfigured Anything for Occur source."
1238 (interactive)
1239 (let ((anything-compile-source-functions
1240 ;; rule out anything-match-plugin because the input is one regexp.
1241 (delq 'anything-compile-source--match-plugin
1242 (copy-sequence anything-compile-source-functions))))
1243 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
1245 ;;;###autoload
1246 (defun anything-browse-code ()
1247 "Preconfigured anything to browse code."
1248 (interactive)
1249 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
1251 ;;;###autoload
1252 (defun anything-org-headlines ()
1253 "Preconfigured anything to show org headlines."
1254 (interactive)
1255 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
1257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1258 ;;; kill buffers
1259 ;;;###autoload
1260 (defun anything-kill-buffers ()
1261 "Preconfigured `anything' to kill buffer you selected."
1262 (interactive)
1263 (anything
1264 '(((name . "Kill Buffers")
1265 (candidates . anything-c-buffer-list)
1266 (action
1267 ("Kill Buffer" . (lambda (candidate)
1268 (kill-buffer candidate)
1269 (anything-kill-buffers)
1270 )))))
1271 nil nil))
1273 ;;; Regexp
1274 (defun anything-c-query-replace-regexp (candidate)
1275 (let ((regexp (funcall (anything-attr 'regexp))))
1276 (apply 'query-replace-regexp
1277 (anything-c-query-replace-args regexp))))
1279 (defun anything-c-kill-regexp-as-sexp (candidate)
1280 (anything-c-regexp-kill-new
1281 (prin1-to-string (funcall (anything-attr 'regexp)))))
1283 (defun anything-c-kill-regexp (candidate)
1284 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
1286 (defun anything-c-query-replace-args (regexp)
1287 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1288 (let ((region-only (anything-region-active-p)))
1289 (list
1290 regexp
1291 (query-replace-read-to regexp
1292 (format "Query replace %s regexp %s"
1293 (if anything-current-prefix-arg "word " "")
1294 (if region-only "in region " ""))
1296 anything-current-prefix-arg
1297 (when region-only (region-beginning))
1298 (when region-only (region-end)))))
1300 (defvar anything-c-source-regexp
1301 '((name . "Regexp Builder")
1302 (init . (lambda ()
1303 (anything-candidate-buffer anything-current-buffer)))
1304 (candidates-in-buffer)
1305 (get-line . anything-c-regexp-get-line)
1306 (persistent-action . anything-c-regexp-persistent-action)
1307 (persistent-help . "Show this line")
1308 (multiline)
1309 (delayed)
1310 (requires-pattern . 2)
1311 (mode-line . "Press TAB to select action.")
1312 ;; RUBIKITCH:
1313 ;; I use here `anything-input' because `anything-pattern' is lost when
1314 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1315 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1316 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1317 ;; Can you fix it?
1318 (regexp . (lambda () anything-input))
1319 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
1320 ("Query Replace Regexp" . anything-c-query-replace-regexp)
1321 ("Kill Regexp" . anything-c-kill-regexp)))))
1323 (defun anything-c-regexp-get-line (s e)
1324 (propertize
1325 (apply 'concat
1326 ;; Line contents
1327 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
1328 ;; subexps
1329 (loop for i from 0 to (1- (/ (length (match-data)) 2))
1330 collect (format "\n %s'%s'"
1331 (if (zerop i) "Group 0: " (format "Group %d: " i))
1332 (match-string i))))
1333 ;; match beginning
1334 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1335 ;; It is implementation problem of candidates-in-buffer.
1336 'anything-realvalue
1337 (1- s)))
1339 (defun anything-goto-line (lineno)
1340 "Goto LINENO without modifying outline visibility if needed."
1341 (flet ((gotoline (numline)
1342 (goto-char (point-min)) (forward-line (1- numline))))
1343 (if (or (eq major-mode 'org-mode)
1344 outline-minor-mode)
1345 (progn
1346 (gotoline lineno)
1347 (org-reveal))
1348 (gotoline lineno))))
1350 (defun anything-c-regexp-persistent-action (pt)
1351 (goto-char pt)
1352 (anything-persistent-highlight-point))
1354 (defun anything-c-regexp-kill-new (input)
1355 (kill-new input)
1356 (message "Killed: %s" input))
1358 (defun anything-region-active-p ()
1359 (and transient-mark-mode mark-active (/= (mark) (point))))
1361 (defun* anything-current-buffer-narrowed-p (&optional
1362 (buffer anything-current-buffer))
1363 "Check if BUFFER is narrowed.
1364 Default is `anything-current-buffer'."
1365 (with-current-buffer buffer
1366 (let ((beg (point-min))
1367 (end (point-max))
1368 (total (buffer-size)))
1369 (or (/= beg 1) (/= end (1+ total))))))
1371 ;;;###autoload
1372 (defun anything-regexp ()
1373 "Preconfigured anything to build regexps and run query-replace-regexp \
1374 against."
1375 (interactive)
1376 (save-restriction
1377 (let ((anything-compile-source-functions
1378 ;; rule out anything-match-plugin because the input is one regexp.
1379 (delq 'anything-compile-source--match-plugin
1380 (copy-sequence anything-compile-source-functions))))
1381 (when (and (anything-region-active-p)
1382 ;; Don't narrow to region if buffer is already narrowed.
1383 (not (anything-current-buffer-narrowed-p)))
1384 (narrow-to-region (region-beginning) (region-end)))
1385 (anything :sources
1386 anything-c-source-regexp
1387 :buffer "*anything regexp*"
1388 :prompt "Regexp: "))))
1391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1393 (defun anything-insert-buffer-name ()
1394 "Insert buffer name."
1395 (interactive)
1396 (anything-insert-string
1397 (with-current-buffer anything-current-buffer
1398 (if buffer-file-name (file-name-nondirectory buffer-file-name)
1399 (buffer-name)))))
1401 (defun anything-insert-symbol ()
1402 "Insert current symbol."
1403 (interactive)
1404 (anything-insert-string
1405 (with-current-buffer anything-current-buffer
1406 (save-excursion
1407 (buffer-substring (beginning-of-thing 'symbol)
1408 (end-of-thing 'symbol))))))
1410 (defun anything-insert-selection ()
1411 "Insert current selection."
1412 (interactive)
1413 (anything-insert-string
1414 (with-current-buffer anything-current-buffer
1415 (anything-get-selection))))
1417 (defun anything-show-buffer-only ()
1418 "[OBSOLETE] Only show sources about buffer.
1419 Use `anything-for-buffers' instead."
1420 (interactive)
1421 (anything-set-source-filter '("Buffers")))
1423 (defun anything-show-bbdb-only ()
1424 "[OBSOLETE] Only show sources about BBDB.
1425 Use `anything-bbdb' instead."
1426 (interactive)
1427 (anything-set-source-filter '("BBDB")))
1429 (defun anything-show-locate-only ()
1430 "[OBSOLETE] Only show sources about Locate.
1431 Use `anything-locate' instead."
1432 (interactive)
1433 (anything-set-source-filter '("Locate")))
1435 (defun anything-show-info-only ()
1436 "[OBSOLETE] Only show sources about Info.
1437 Use `anything-info-at-point' instead."
1438 (interactive)
1439 (anything-set-source-filter '("Info Pages"
1440 "Info Elisp"
1441 "Info Common-Lisp")))
1443 (defun anything-show-imenu-only ()
1444 "[OBSOLETE] Only show sources about Imenu.
1445 Use `anything-imenu' instead."
1446 (interactive)
1447 (anything-set-source-filter '("Imenu")))
1449 (defun anything-show-files-only ()
1450 "[OBSOLETE] Only show sources about File.
1451 Use `anything-for-files' instead."
1452 (interactive)
1453 (anything-set-source-filter '("File Name History"
1454 "Files from Current Directory"
1455 "Recentf")))
1457 (defun anything-show-w3m-bookmarks-only ()
1458 "[OBSOLETE] Only show source about w3m bookmark.
1459 Use `anything-w3m-bookmarks' instead."
1460 (interactive)
1461 (anything-set-source-filter '("W3m Bookmarks")))
1463 (defun anything-show-colors-only ()
1464 "[OBSOLETE] Only show source about color.
1465 Use `anything-colors' instead."
1466 (interactive)
1467 (anything-set-source-filter '("Colors"
1468 "Customize Faces")))
1470 (defun anything-show-kill-ring-only ()
1471 "[OBSOLETE] Only show source about kill ring.
1472 Use `anything-show-kill-ring' instead."
1473 (interactive)
1474 (anything-set-source-filter '("Kill Ring")))
1476 (defun anything-show-this-source-only ()
1477 "Only show this source."
1478 (interactive)
1479 (setq anything-candidate-number-limit 9999)
1480 (anything-set-source-filter
1481 (list (assoc-default 'name (anything-get-current-source)))))
1483 (defun anything-test-sources ()
1484 "List all anything sources for test.
1485 The output is sexps which are evaluated by \\[eval-last-sexp]."
1486 (interactive)
1487 (with-output-to-temp-buffer "*Anything Test Sources*"
1488 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
1489 (apropos-internal "^anything-c-source" #'boundp))
1490 (pop-to-buffer standard-output)))
1492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1493 ;;; For compatibility
1494 (unless (fboundp 'region-active-p)
1495 (defun region-active-p ()
1496 "Return t if Transient Mark mode is enabled and the mark is active.
1498 Most commands that act on the region if it is active and
1499 Transient Mark mode is enabled, and on the text near point
1500 otherwise, should use `use-region-p' instead. That function
1501 checks the value of `use-empty-active-region' as well."
1502 (and transient-mark-mode mark-active)))
1504 (defun anything-nest (&rest same-as-anything)
1505 "Nested `anything'. If you use `anything' within `anything', use it."
1506 (with-selected-window (anything-window)
1507 (let (anything-current-position
1508 anything-current-buffer
1509 (orig-anything-buffer anything-buffer)
1510 anything-pattern
1511 anything-buffer
1512 anything-sources
1513 anything-compiled-sources
1514 anything-buffer-chars-modified-tick
1515 (anything-samewindow t)
1516 (enable-recursive-minibuffers t))
1517 (unwind-protect
1518 (apply #'anything same-as-anything)
1519 (anything-initialize-overlays orig-anything-buffer)
1520 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
1522 (defun anything-displaying-source-names ()
1523 "Display sources name."
1524 (with-current-buffer anything-buffer
1525 (goto-char (point-min))
1526 (loop with pos
1527 while (setq pos (next-single-property-change (point) 'anything-header))
1528 do (goto-char pos)
1529 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1530 do (forward-line 1))))
1532 (defun anything-select-source ()
1533 "Select source."
1534 (interactive)
1535 (let ((default (assoc-default 'name (anything-get-current-source)))
1536 (source-names (anything-displaying-source-names))
1537 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
1538 (anything-get-sources))))
1539 (setq anything-candidate-number-limit 9999)
1540 (anything-aif
1541 (let (anything-source-filter)
1542 (anything-nest '(((name . "Anything Source")
1543 (candidates . source-names)
1544 (action . identity))
1545 ((name . "Anything Source (ALL)")
1546 (candidates . all-source-names)
1547 (action . identity)))
1548 nil "Source: " nil
1549 default "*anything select source*"))
1550 (anything-set-source-filter (list it))
1551 (anything-set-source-filter nil))))
1553 (defun anything-insert-string (str)
1554 "Insert STR."
1555 (delete-minibuffer-contents)
1556 (insert str))
1558 (defun anything-c-match-on-file-name (candidate)
1559 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1560 (string-match anything-pattern (file-name-nondirectory candidate)))
1562 (defun anything-c-match-on-directory-name (candidate)
1563 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1564 (anything-aif (file-name-directory candidate)
1565 (string-match anything-pattern it)))
1567 (defun anything-c-string-match (candidate)
1568 "Return non-nil if `anything-pattern' match CANDIDATE.
1569 The match is done with `string-match'."
1570 (string-match anything-pattern candidate))
1572 ;; `anything-c-compose' is no more needed, it is for compatibility.
1573 (defalias 'anything-c-compose 'anything-compose)
1575 (defun anything-c-skip-entries (list regexp)
1576 "Remove entries which matches REGEXP from LIST."
1577 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
1578 list))
1580 (defun anything-c-shadow-entries (list regexp)
1581 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1582 (mapcar (lambda (file)
1583 ;; Add shadow face property to boring files.
1584 (let ((face (if (facep 'file-name-shadow)
1585 'file-name-shadow
1586 ;; fall back to default on XEmacs
1587 'default)))
1588 (if (string-match regexp file)
1589 (setq file (propertize file 'face face))))
1590 file)
1591 list))
1593 (defsubst anything-c-stringify (str-or-sym)
1594 "Get string of STR-OR-SYM."
1595 (if (stringp str-or-sym)
1596 str-or-sym
1597 (symbol-name str-or-sym)))
1599 (defsubst anything-c-symbolify (str-or-sym)
1600 "Get symbol of STR-OR-SYM."
1601 (if (symbolp str-or-sym)
1602 str-or-sym
1603 (intern str-or-sym)))
1605 (defun anything-c-describe-function (func)
1606 "FUNC is symbol or string."
1607 (describe-function (anything-c-symbolify func)))
1609 (defun anything-c-describe-variable (var)
1610 "VAR is symbol or string."
1611 (describe-variable (anything-c-symbolify var)))
1613 (defun anything-c-find-function (func)
1614 "FUNC is symbol or string."
1615 (find-function (anything-c-symbolify func)))
1617 (defun anything-c-find-variable (var)
1618 "VAR is symbol or string."
1619 (find-variable (anything-c-symbolify var)))
1621 (defun anything-c-kill-new (string &optional replace yank-handler)
1622 "STRING is symbol or string."
1623 (kill-new (anything-c-stringify string) replace yank-handler))
1625 ;;; Toggle all marks.
1627 (defun anything-mark-all ()
1628 "Mark all visible unmarked candidates in current source."
1629 (with-anything-window
1630 (save-excursion
1631 (goto-char (anything-get-previous-header-pos))
1632 (anything-next-line)
1633 (let* ((next-head (anything-get-next-header-pos))
1634 (end (and next-head
1635 (save-excursion
1636 (goto-char next-head)
1637 (forward-line -2)
1638 (point))))
1639 (maxpoint (or end (point-max))))
1640 (while (< (point) maxpoint)
1641 (let ((prefix (get-text-property (point-at-bol) 'display)))
1642 (when (and (not (anything-this-visible-mark))
1643 (not (or (string= prefix "[?]")
1644 (string= prefix "[@]"))))
1645 ;; FIXME: This is a bug in `anything-make-visible-mark'
1646 ;; it should not assume that overlay is on line and
1647 ;; BTW not use `anything-get-selection' to get
1648 ;; the real value of candidate.
1649 ;; So for the moment just mark this line.
1650 (anything-mark-current-line)
1651 ;; Don't mark possibles directories ending with . or ..
1652 (unless (string-match "\\.$" (anything-get-selection))
1653 (anything-make-visible-mark))))
1654 (forward-line 1) (end-of-line))))
1655 (anything-mark-current-line)
1656 (message "%s candidates marked" (length anything-marked-candidates))))
1658 (defun anything-unmark-all ()
1659 "Unmark all candidates in all sources of current anything session."
1660 (with-anything-window
1661 (let ((len (length anything-marked-candidates)))
1662 (save-excursion
1663 (anything-clear-visible-mark))
1664 (setq anything-marked-candidates nil)
1665 (anything-mark-current-line)
1666 (message "%s candidates unmarked" len))))
1668 (defun anything-toggle-all-marks ()
1669 "Toggle all marks.
1670 Mark all visible candidates of current source or unmark all candidates
1671 visible or invisible in all sources of current anything session"
1672 (interactive)
1673 (let ((marked (anything-marked-candidates)))
1674 (if (and (>= (length marked) 1)
1675 (with-anything-window anything-visible-mark-overlays))
1676 (anything-unmark-all)
1677 (anything-mark-all))))
1679 (define-key anything-map (kbd "M-m") 'anything-toggle-all-marks)
1681 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1682 (defadvice eval-defun (after anything-source-hack activate)
1683 "See `anything-c-enable-eval-defun-hack'."
1684 (when anything-c-enable-eval-defun-hack
1685 (let ((varsym (save-excursion
1686 (beginning-of-defun)
1687 (forward-char 1)
1688 (when (memq (read (current-buffer)) '(defvar setq))
1689 (read (current-buffer))))))
1690 (when (string-match "^anything-c-source-" (symbol-name varsym))
1691 (anything varsym)))))
1692 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1695 (defconst anything-c-create-summary-index-regexp
1696 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1697 (defun anything-c-create-summary ()
1698 "Create `anything' summary."
1699 (save-excursion
1700 (goto-char (point-min))
1701 (loop with it
1702 while (re-search-forward anything-c-create-summary-index-regexp nil t)
1703 collect
1704 (cond ((setq it (match-string-no-properties 1))
1705 (cons 'section it))
1706 ((setq it (match-string-no-properties 2))
1707 `(source ,it .
1708 ,(assoc-default 'name (symbol-value (intern it)))))
1709 ((setq it (match-string-no-properties 3))
1710 `(source ,it .
1711 ,(assoc-default 'name (symbol-value (intern it)))))))))
1713 ;; (find-epp (anything-c-create-summary))
1715 (defun anything-c-insert-summary ()
1716 "Insert `anything' summary."
1717 (save-excursion
1718 (goto-char (point-min))
1719 (search-forward ";; Below are complete source list you can setup in")
1720 (forward-line 1)
1721 (delete-region (point)
1722 (progn (search-forward ";;; Change log:" nil t)
1723 (forward-line -1) (point)))
1724 (insert ";;\n")
1725 (loop with beg
1726 for (kind . value) in (anything-c-create-summary)
1727 for i from 0
1728 do (cond ((eq kind 'section)
1729 (unless (zerop i)
1730 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1731 (insert ";; " value ":\n")
1732 (setq beg (point)))
1734 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
1735 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
1736 ;; (anything-c-insert-summary)
1738 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1739 ;;;; <Buffer>
1740 (defun anything-c-buffer-list ()
1741 "Return the list of names of buffers with boring buffers filtered out.
1742 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1743 The first buffer in the list will be the last recently used
1744 buffer that is not the current buffer."
1745 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1746 (append (cdr buffers) (list (car buffers)))))
1748 (defvar anything-c-source-buffers
1749 '((name . "Buffers")
1750 (candidates . anything-c-buffer-list)
1751 (type . buffer)))
1752 ;; (anything 'anything-c-source-buffers)
1754 (defvar anything-c-source-buffer-not-found
1755 '((name . "Create buffer")
1756 (dummy)
1757 (type . buffer)))
1758 ;; (anything 'anything-c-source-buffer-not-found)
1760 ;;; Buffers+
1761 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1762 "*Face used for directory headings in dired buffers."
1763 :group 'anything)
1765 (defface anything-file-name
1766 '((t (:foreground "Blue")))
1767 "*Face used for file names (without suffixes) in dired buffers."
1768 :group 'anything)
1770 (defface anything-dir-priv
1771 '((t (:foreground "DarkRed" :background "LightGray")))
1772 "*Face used for directory privilege indicator (d) in dired buffers."
1773 :group 'anything)
1775 (defvar anything-c-buffers-face1 'anything-dir-priv)
1776 (defvar anything-c-buffers-face2 'font-lock-type-face)
1777 (defvar anything-c-buffers-face3 'italic)
1778 (eval-when-compile (require 'dired))
1779 (defun anything-c-highlight-buffers (buffers)
1780 (require 'dired)
1781 (loop for i in buffers
1782 if (rassoc (get-buffer i) dired-buffers)
1783 collect (propertize i
1784 'face anything-c-buffers-face1
1785 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1786 if (buffer-file-name (get-buffer i))
1787 collect (propertize i
1788 'face anything-c-buffers-face2
1789 'help-echo (buffer-file-name (get-buffer i)))
1790 if (and (not (rassoc (get-buffer i) dired-buffers))
1791 (not (buffer-file-name (get-buffer i))))
1792 collect (propertize i
1793 'face anything-c-buffers-face3)))
1795 (defvar anything-c-source-buffers+
1796 '((name . "Buffers")
1797 (candidates . anything-c-buffer-list)
1798 (type . buffer)
1799 (candidate-transformer anything-c-skip-current-buffer
1800 anything-c-highlight-buffers
1801 anything-c-skip-boring-buffers)
1802 (persistent-action . anything-c-buffers+-persistent-action)
1803 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1805 (defun anything-c-buffers+-persistent-action (name)
1806 (flet ((kill (item)
1807 (with-current-buffer item
1808 (if (and (buffer-modified-p)
1809 (buffer-file-name (current-buffer)))
1810 (progn
1811 (save-buffer)
1812 (kill-buffer item))
1813 (kill-buffer item))))
1814 (goto (item)
1815 (switch-to-buffer item)))
1816 (if current-prefix-arg
1817 (progn
1818 (kill name)
1819 (anything-delete-current-selection))
1820 (goto name))))
1822 ;; (anything 'anything-c-source-buffers+)
1824 (defadvice anything-quit-and-find-file (around use-anything-find-files activate)
1825 "Let `anything-quit-and-find-file' take advantage of `anything-find-files'."
1826 (interactive)
1827 (anything-run-after-quit
1828 (lambda (f)
1829 (anything-find-files1 f))
1830 (anything-aif (get-buffer (anything-get-selection))
1831 (or (buffer-file-name it)
1832 (car (rassoc it dired-buffers))
1833 (and (with-current-buffer it
1834 (eq major-mode 'org-agenda-mode))
1835 org-directory
1836 (expand-file-name org-directory))
1837 default-directory)
1838 (let ((sel (anything-get-selection)))
1839 (if (file-exists-p sel)
1840 (expand-file-name sel)
1841 default-directory)))))
1843 ;;;; <File>
1844 ;;; File name history
1845 (defvar anything-c-source-file-name-history
1846 '((name . "File Name History")
1847 (candidates . file-name-history)
1848 (match anything-c-match-on-file-name
1849 anything-c-match-on-directory-name)
1850 (type . file)))
1851 ;; (anything 'anything-c-source-file-name-history)
1853 ;;; Files in current dir
1854 (defvar anything-c-source-files-in-current-dir
1855 '((name . "Files from Current Directory")
1856 (candidates . (lambda ()
1857 (with-current-buffer anything-current-buffer
1858 (directory-files (anything-c-current-directory)))))
1859 ;; volatile is not needed, I think.
1860 (type . file)))
1861 ;; (anything 'anything-c-source-files-in-current-dir)
1863 (defvar anything-c-files-face1 'anything-dir-priv)
1864 (defvar anything-c-files-face2 'anything-file-name)
1865 (defun anything-c-highlight-files (files)
1866 (loop for i in files
1867 if (file-directory-p i)
1868 collect (propertize (file-name-nondirectory i)
1869 'face anything-c-files-face1
1870 'help-echo (expand-file-name i))
1871 else
1872 collect (propertize (file-name-nondirectory i)
1873 'face anything-c-files-face2
1874 'help-echo (expand-file-name i))))
1877 (defvar anything-c-source-files-in-current-dir+
1878 '((name . "Files from Current Directory")
1879 (candidates . (lambda ()
1880 (with-current-buffer anything-current-buffer
1881 (directory-files (anything-c-current-directory) t))))
1882 (candidate-transformer anything-c-highlight-files)
1883 ;; volatile is not needed, I think.
1884 (type . file)))
1886 ;; (anything 'anything-c-source-files-in-current-dir+)
1888 ;;; Anything replacement of file name completion for `find-file' and friends.
1890 (defvar anything-c-find-files-doc-header (format " (`%s':Go to precedent level)"
1891 (if window-system "C-." "C-l"))
1892 "*The doc that is inserted in the Name header of a find-files or dired source.")
1894 (defvar anything-c-source-find-files
1895 `((name . ,(concat "Find Files" anything-c-find-files-doc-header))
1896 ;; It is needed for filenames with capital letters
1897 (disable-shortcuts)
1898 (init . (lambda ()
1899 (setq ffap-newfile-prompt t)
1900 ;; This is needed when connecting with emacsclient -t
1901 ;; on remote host that have an anything started on a window-system.
1902 ;; i.e when `C-.' is already loaded.
1903 (unless window-system
1904 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))))
1905 (candidates . anything-find-files-get-candidates)
1906 (filtered-candidate-transformer anything-c-find-files-transformer)
1907 (image-action1 . anything-ff-rotate-image-left)
1908 (image-action2 . anything-ff-rotate-image-right)
1909 (persistent-action . anything-find-files-persistent-action)
1910 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
1911 (volatile)
1912 (candidate-number-limit . 9999)
1913 (action-transformer . anything-find-files-action-transformer)
1914 (action
1915 . ,(delq
1917 `(("Find File" . anything-c-find-file-or-marked)
1918 ("Find file in Dired" . anything-c-point-file-in-dired)
1919 ,(and (locate-library "elscreen")
1920 '("Find file in Elscreen" . anything-elscreen-find-file))
1921 ("Complete at point"
1922 . anything-c-insert-file-name-completion-at-point)
1923 ("Open file externally `C-u to choose'"
1924 . anything-c-open-file-externally)
1925 ("Grep File(s) `C-u Recurse'"
1926 . (lambda (candidate)
1927 (if anything-current-prefix-arg
1928 (anything-do-grep1 (anything-marked-candidates) 'recurse)
1929 (anything-do-grep1 (anything-marked-candidates)))))
1930 ("Switch to Eshell" . anything-ff-switch-to-eshell)
1931 ("Eshell command on file(s)" . anything-find-files-eshell-command-on-file)
1932 ("Ediff File" . anything-find-files-ediff-files)
1933 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
1934 ("Delete File(s)" . anything-delete-marked-files)
1935 ("Copy file(s) `C-u to follow'" . anything-find-files-copy)
1936 ("Rename file(s) `C-u to follow'" . anything-find-files-rename)
1937 ("Symlink files(s) `C-u to follow'" . anything-find-files-symlink)
1938 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
1939 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
1940 ("Find file other window" . find-file-other-window)
1941 ("Find file other frame" . find-file-other-frame)
1942 ("Find file as root" . anything-find-file-as-root))))))
1943 ;; (anything 'anything-c-source-find-files)
1945 (defun anything-find-files-set-prompt-for-action (prompt files)
1946 "Set prompt for action in `anything-find-files'."
1947 (let ((len (length files)))
1948 (if (> len 1)
1949 (format "%s * %d Files to: " prompt len)
1950 (format "%s %s to: " prompt (car files)))))
1952 (defun anything-find-files-do-action (action)
1953 "Generic function for creating action from `anything-c-source-find-files'.
1954 ACTION must be an action supported by `anything-dired-action'."
1955 (let* ((ifiles (anything-marked-candidates))
1956 (buf anything-current-buffer)
1957 (prompt (anything-find-files-set-prompt-for-action
1958 (capitalize (symbol-name action)) ifiles))
1959 (parg anything-current-prefix-arg)
1960 (dest (anything-c-read-file-name
1961 prompt
1962 :initial-input (car anything-ff-history)
1963 :history (anything-find-files-history :comp-read nil)))
1964 (win-conf (current-window-configuration)))
1965 (unwind-protect
1966 ;; Create temporarily a dired buffer to call dired functions.
1967 (with-current-buffer (dired anything-ff-default-directory)
1968 (let ((dir-buf (current-buffer)))
1969 (anything-dired-action
1970 dest :files ifiles :action action :follow parg)
1971 ;; If we have started in a dired buffer, don't kill it.
1972 (unless (eq dir-buf (get-buffer buf))
1973 (kill-buffer dir-buf))))
1974 (unless parg (set-window-configuration win-conf)))))
1976 (defun anything-find-files-copy (candidate)
1977 "Copy files from `anything-find-files'."
1978 (anything-find-files-do-action 'copy))
1980 (defun anything-find-files-rename (candidate)
1981 "Rename files from `anything-find-files'."
1982 (anything-find-files-do-action 'rename))
1984 (defun anything-find-files-symlink (candidate)
1985 "Symlink files from `anything-find-files'."
1986 (anything-find-files-do-action 'symlink))
1988 (defun anything-find-files-relsymlink (candidate)
1989 "Relsymlink files from `anything-find-files'."
1990 (anything-find-files-do-action 'relsymlink))
1992 (defun anything-find-files-hardlink (candidate)
1993 "Hardlink files from `anything-find-files'."
1994 (anything-find-files-do-action 'hardlink))
1996 (defun anything-find-files-byte-compile (candidate)
1997 "Byte compile elisp files from `anything-find-files'."
1998 (let ((files (anything-marked-candidates))
1999 (parg anything-current-prefix-arg))
2000 (loop for fname in files
2001 do (byte-compile-file fname parg))))
2003 (defun anything-find-files-load-files (candidate)
2004 "Load elisp files from `anything-find-files'."
2005 (let ((files (anything-marked-candidates)))
2006 (loop for fname in files
2007 do (load fname))))
2009 (defun anything-find-files-ediff-files (candidate)
2010 "Default action to ediff files in `anything-find-files'."
2011 (ediff-files
2012 candidate
2013 (anything-c-read-file-name
2014 (format "Ediff `%s' With File: " (file-name-nondirectory candidate)))))
2016 (defun anything-find-files-ediff-merge-files (candidate)
2017 "Default action to ediff merge files in `anything-find-files'."
2018 (ediff-merge-files
2019 candidate
2020 (anything-c-read-file-name
2021 (format "Ediff Merge `%s' With File: "
2022 (file-name-nondirectory candidate)))))
2024 (defvar eshell-command-aliases-list nil)
2025 (declare-function eshell-read-aliases-list "em-alias")
2026 (defun anything-find-files-eshell-command-on-file (candidate)
2027 "Run `eshell-command' on file CANDIDATE possibly with an eshell alias.
2028 NOTE:
2029 If `eshell' or `eshell-command' have not been run once, `eshell-command-aliases-list'
2030 will not be loaded first time you use this."
2031 (when (or eshell-command-aliases-list
2032 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
2033 (and eshell-command-aliases-list (eshell-read-aliases-list))
2034 (let ((cand-list (anything-marked-candidates))
2035 (default-directory anything-ff-default-directory)
2036 (command (anything-comp-read
2037 "Command: "
2038 (loop for (a . c) in eshell-command-aliases-list
2039 when (string-match "\\$1$" (car c))
2040 collect a))))
2041 (loop
2042 for i in cand-list
2043 for com = (concat command " " (shell-quote-argument i))
2044 do (eshell-command com)))))
2047 (declare-function eshell-send-input "esh-mode" (&optional use-region queue-p no-newline))
2048 (defun anything-ff-switch-to-eshell (candidate)
2049 "Switch to eshell and cd to `anything-ff-default-directory'."
2050 (flet ((cd-eshell ()
2051 (goto-char (point-max))
2052 (insert
2053 (format "cd %s" (shell-quote-argument
2054 anything-ff-default-directory)))
2055 (eshell-send-input)))
2056 (if (get-buffer "*eshell*")
2057 (progn
2058 (switch-to-buffer "*eshell*")
2059 (cd-eshell))
2060 (call-interactively 'eshell)
2061 (cd-eshell))))
2063 (defun* anything-reduce-file-name (fname level &key unix-close expand)
2064 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
2065 If LEVEL is positive reduce from end else from beginning.
2066 If UNIX-CLOSE is non--nil close filename with /.
2067 If EXPAND is non--nil expand-file-name."
2068 (let* ((exp-fname (expand-file-name fname))
2069 (fname-list (split-string (if (or (string= fname "~/") expand)
2070 exp-fname fname) "/" t))
2071 (len (length fname-list))
2072 (pop-list (if (< level 0)
2073 (subseq fname-list (* level -1))
2074 (subseq fname-list 0 (- len level))))
2075 (result (mapconcat 'identity pop-list "/"))
2076 (empty (string= result "")))
2077 (when unix-close (setq result (concat result "/")))
2078 (if (string-match "^~" result)
2079 (if (string= result "~/") "~/" result)
2080 (if (< level 0)
2081 (if empty "../" (concat "../" result))
2082 (cond ((eq system-type 'windows-nt)
2083 (if empty "c:/" result))
2084 (empty "/")
2086 (concat "/" result)))))))
2088 (defun anything-file-completion-source-p ()
2089 "Test if current source is a dired or find-files source."
2090 (let ((ff-sources '("Find Files" "Copy Files"
2091 "Read File Name History"
2092 "Rename Files" "Symlink Files"
2093 "Hardlink Files" "Write File"
2094 "Insert File" "Read file name"))
2095 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
2096 (loop for i in ff-sources
2097 thereis (string= cur-source (concat i anything-c-find-files-doc-header)))))
2099 ;; Internal.
2100 (defvar anything-ff-last-expanded nil
2101 "Store last expanded directory or file in `anything-find-files'.")
2103 (defun anything-find-files-down-one-level (arg)
2104 "Go down one level like unix command `cd ..'.
2105 If prefix numeric arg is given go ARG level down."
2106 (interactive "p")
2107 ;; When going to precedent level we want to be at the line
2108 ;; corresponding to actual directory, so store this info
2109 ;; in `anything-ff-last-expanded'.
2110 (if (and (not (file-directory-p anything-pattern))
2111 (file-exists-p anything-pattern))
2112 (setq anything-ff-last-expanded anything-pattern)
2113 (setq anything-ff-last-expanded anything-ff-default-directory))
2114 (when (anything-file-completion-source-p)
2115 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
2116 :unix-close t :expand t)))
2117 (with-selected-window (minibuffer-window)
2118 (delete-minibuffer-contents)
2119 (insert new-pattern)))))
2121 (defun anything-ff-retrieve-last-expanded ()
2122 "Move overlay to last visited directory `anything-ff-last-expanded'.
2123 This happen after using `anything-find-files-down-one-level',
2124 or hitting C-z on \"..\"."
2125 (when (and anything-ff-last-expanded
2126 (anything-file-completion-source-p))
2127 (let ((dirname (directory-file-name anything-ff-last-expanded)))
2128 (with-anything-window
2129 (when (or (re-search-forward (concat dirname "$") nil t)
2130 (re-search-forward
2131 (concat anything-ff-last-expanded "$") nil t))
2132 (forward-line 0)
2133 (anything-mark-current-line)))
2134 (setq anything-ff-last-expanded nil))))
2135 (add-hook 'anything-after-update-hook 'anything-ff-retrieve-last-expanded)
2137 ;; `C-.' doesn't work in terms use `C-l' instead.
2138 (if window-system
2139 (define-key anything-map (kbd "C-.") 'anything-find-files-down-one-level)
2140 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))
2142 (defun anything-c-point-file-in-dired (file)
2143 "Put point on filename FILE in dired buffer."
2144 (dired (file-name-directory file))
2145 (dired-goto-file file))
2147 (defun anything-create-tramp-name (fname)
2148 "Build filename for `anything-pattern' like /su:: or /sudo::."
2149 (apply #'tramp-make-tramp-file-name
2150 (loop with v = (tramp-dissect-file-name fname)
2151 for i across v collect i)))
2153 (defun anything-ff-set-pattern (pattern)
2154 (let ((methods (mapcar 'car tramp-methods))
2155 (reg "\\`/\\([^[/:]+\\|[^/]+]\\):.*:")
2156 cur-method tramp-name)
2157 (cond ((string= pattern "") "")
2158 ((string-match "^~" pattern)
2159 (replace-match (getenv "HOME") nil t pattern))
2160 ;; Match "/method:maybe_hostname:"
2161 ((and (string-match reg pattern)
2162 (setq cur-method (match-string 1 pattern))
2163 (member cur-method methods))
2164 (setq tramp-name (anything-create-tramp-name
2165 (match-string 0 pattern)))
2166 (replace-match tramp-name nil t pattern))
2167 ;; Match "/hostname:"
2168 ((and (string-match tramp-file-name-regexp pattern)
2169 (setq cur-method (match-string 1 pattern))
2170 (and cur-method (not (member cur-method methods))))
2171 (setq tramp-name (anything-create-tramp-name
2172 (match-string 0 pattern)))
2173 (replace-match tramp-name nil t pattern))
2174 ;; Match "/method:" in this case don't try to connect.
2175 ((and (not (string-match reg pattern))
2176 (string-match tramp-file-name-regexp pattern)
2177 (member (match-string 1 pattern) methods))
2178 "Invalid tramp file name") ; Write in anything-buffer.
2179 ;; PATTERN is a directory, end it with "/".
2180 ;; This will make PATTERN not ending yet with "/"
2181 ;; candidate for `anything-ff-default-directory',
2182 ;; allowing `anything-ff-retrieve-last-expanded' to retrieve it
2183 ;; when descending level.
2184 ((file-directory-p pattern)
2185 (file-name-as-directory pattern))
2186 ;; Return PATTERN unchanged.
2187 (t pattern))))
2189 (defvar anything-ff-default-directory nil)
2190 (defvar anything-ff-history nil)
2191 (defvar anything-ff-history-max-length 30
2192 "*Number of elements shown in `anything-find-files' history.")
2193 (defun anything-find-files-get-candidates ()
2194 "Create candidate list for `anything-c-source-find-files'."
2195 (let* ((path (anything-ff-set-pattern anything-pattern))
2196 (path-name-dir (file-name-directory path))
2197 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
2198 (set-text-properties 0 (length path) nil path)
2199 (if (member 'anything-compile-source--match-plugin
2200 anything-compile-source-functions)
2201 (setq anything-pattern path)
2202 (setq anything-pattern (replace-regexp-in-string " " ".*" path)))
2203 (setq anything-ff-default-directory
2204 (if (string= anything-pattern "")
2205 (if (eq system-type 'windows-nt) "c:/" "/")
2206 (unless (string-match ffap-url-regexp path)
2207 path-name-dir)))
2208 (cond ((or (string= path "Invalid tramp file name")
2209 (file-regular-p path)
2210 (and (not (file-exists-p path)) (string-match "/$" path))
2211 (and ffap-url-regexp (string-match ffap-url-regexp path)))
2212 (list path))
2213 ((string= path "") (directory-files "/" t))
2214 ((and (file-directory-p path) (not (file-readable-p path)))
2215 (list (format "Opening directory: access denied, `%s'" path)))
2216 ((file-directory-p path) (directory-files path t))
2218 (append
2219 (list path)
2220 (directory-files (file-name-directory path) t))))))
2222 (defun anything-ff-save-history ()
2223 "Store the last value of `anything-ff-default-directory' \
2224 in `anything-ff-history'."
2225 (when anything-ff-default-directory
2226 (push anything-ff-default-directory anything-ff-history)))
2227 (add-hook 'anything-cleanup-hook 'anything-ff-save-history)
2229 (defface anything-dired-symlink-face
2230 '((t (:foreground "DarkOrange")))
2231 "*Face used for symlinks in `anything-find-files'."
2232 :group 'anything)
2234 (defface anything-ffiles-prefix-face
2235 '((t (:background "yellow" :foreground "black")))
2236 "*Face used to prefix new file or url paths in `anything-find-files'."
2237 :group 'anything)
2239 (defun* anything-ff-attributes
2240 (file &key type links uid gid access-time modif-time
2241 status size mode gid-change inode device-num dired)
2242 "Easy interface for `file-attributes'."
2243 (let ((all (destructuring-bind
2244 (type links uid gid access-time modif-time
2245 status size mode gid-change inode device-num)
2246 (file-attributes file 'string)
2247 (list :type type
2248 :links links
2249 :uid uid
2250 :gid gid
2251 :access-time access-time
2252 :modif-time modif-time
2253 :status status
2254 :size size
2255 :mode mode
2256 :gid-change gid-change
2257 :inode inode
2258 :device-num device-num))))
2259 (cond (type
2260 (let ((result (getf all :type)))
2261 (cond ((stringp result)
2262 "symlink")
2263 (result "directory")
2264 (t "file"))))
2265 (links (getf all :links))
2266 (uid (getf all :uid))
2267 (gid (getf all :gid))
2268 (access-time
2269 (format-time-string "%Y-%m-%d %R" (getf all :access-time)))
2270 (modif-time
2271 (format-time-string "%Y-%m-%d %R" (getf all :modif-time)))
2272 (status
2273 (format-time-string "%Y-%m-%d %R" (getf all :status)))
2274 (size (getf all :size))
2275 (mode (getf all :mode))
2276 (gid-change (getf all :gid-change))
2277 (inode (getf all :inode))
2278 (device-num (getf all :device-num))
2279 (dired
2280 (concat
2281 (getf all :mode) " "
2282 (number-to-string (getf all :links)) " "
2283 (getf all :uid) ":"
2284 (getf all :gid) " "
2285 (number-to-string (getf all :size)) " "
2286 (format-time-string "%Y-%m-%d %R" (getf all :modif-time))))
2287 (t all))))
2289 (defun anything-c-prefix-filename (fname &optional image)
2290 "Return fname FNAME prefixed with icon IMAGE."
2291 (let* ((img-name (and image (expand-file-name
2292 image anything-c-find-files-icons-directory)))
2293 (img (and image (create-image img-name)))
2294 (prefix-img (and image (propertize " " 'display img)))
2295 (prefix-new (propertize
2296 " " 'display
2297 (propertize "[?]" 'face 'anything-ffiles-prefix-face)))
2298 (prefix-url (propertize
2299 " " 'display
2300 (propertize "[@]" 'face 'anything-ffiles-prefix-face))))
2301 (cond ((or (file-exists-p fname)
2302 (file-symlink-p fname))
2303 (if image (concat prefix-img fname) fname))
2304 ((string-match ffap-url-regexp fname) (concat prefix-url " " fname))
2305 (t (concat prefix-new " " fname)))))
2307 (defun anything-c-find-files-transformer (files sources)
2308 "Selector of transformer to use for `anything-c-source-find-files'."
2309 (if (and (window-system) anything-c-find-files-show-icons)
2310 (anything-c-highlight-ffiles1 files sources)
2311 (anything-c-highlight-ffiles files sources)))
2313 (defun anything-c-highlight-ffiles (files sources)
2314 "Candidate transformer for `anything-c-source-find-files' without icons."
2315 (loop for i in files
2316 collect (cond ((file-symlink-p i)
2317 (cons
2318 (anything-c-prefix-filename
2319 (propertize
2320 i 'face 'anything-dired-symlink-face
2321 'help-echo (file-truename i)))
2323 ((file-directory-p i)
2324 (cons
2325 (anything-c-prefix-filename
2326 (propertize
2327 i 'face anything-c-files-face1
2328 'help-echo (condition-case nil
2329 (anything-ff-attributes i :dired t)
2330 (error nil))))
2333 (cons
2334 (anything-c-prefix-filename
2335 (propertize
2336 i 'face anything-c-files-face2
2337 'help-echo (condition-case nil
2338 (anything-ff-attributes i :dired t)
2339 (error nil))))
2340 i)))))
2342 (defsubst anything-c-highlight-ffiles1 (files sources)
2343 "Candidate transformer for `anything-c-source-find-files' that show icons."
2344 (loop for i in files
2345 for af = (file-name-nondirectory i)
2346 collect (cond ( ;; Files.
2347 (eq nil (car (file-attributes i)))
2348 (cons (anything-c-prefix-filename
2349 (propertize
2350 i 'face anything-c-files-face2
2351 'help-echo (condition-case nil
2352 (anything-ff-attributes i :dired t)
2353 (error nil)))
2354 "leaf.xpm")
2356 ( ;; Empty directories.
2357 (and (eq t (car (file-attributes i)))
2358 ;; Be sure to have permission to list content.
2359 (file-readable-p i)
2360 (eq 0 (length
2361 (directory-files
2362 i nil directory-files-no-dot-files-regexp t))))
2363 (cons (anything-c-prefix-filename
2364 (propertize
2365 i 'face anything-c-files-face1
2366 'help-echo (condition-case nil
2367 (anything-ff-attributes i :dired t)
2368 (error nil)))
2369 "empty.xpm")
2371 ( ;; Open directories.
2372 (and (eq t (car (file-attributes i))) (get-buffer af))
2373 (cons (anything-c-prefix-filename
2374 (propertize
2375 i 'face anything-c-files-face1
2376 'help-echo (condition-case nil
2377 (anything-ff-attributes i :dired t)
2378 (error nil)))
2379 "open.xpm")
2381 (;; Closed directories.
2382 (eq t (car (file-attributes i)))
2383 (cons (anything-c-prefix-filename
2384 (propertize
2385 i 'face anything-c-files-face1
2386 'help-echo (condition-case nil
2387 (anything-ff-attributes i :dired t)
2388 (error nil)))
2389 "close.xpm")
2391 ( ;; Open Symlinks directories.
2392 (and (stringp (car (file-attributes i)))
2393 (file-directory-p i) (get-buffer af))
2394 (cons (anything-c-prefix-filename
2395 (propertize i 'face 'anything-dired-symlink-face
2396 'help-echo (file-truename i)) "open.xpm")
2398 ( ;; Closed Symlinks directories.
2399 (and (stringp (car (file-attributes i)))
2400 (file-directory-p i))
2401 (cons (anything-c-prefix-filename
2402 (propertize i 'face 'anything-dired-symlink-face
2403 'help-echo (file-truename i)) "close.xpm")
2405 ( ;; Files symlinks.
2406 (stringp (car (file-attributes i)))
2407 (cons (anything-c-prefix-filename
2408 (propertize i 'face 'anything-dired-symlink-face
2409 'help-echo (file-truename i))
2410 "leaf.xpm")
2411 i)))))
2413 (defun anything-find-files-action-transformer (actions candidate)
2414 "Action transformer for `anything-c-source-find-files'."
2415 (cond ((with-current-buffer anything-current-buffer
2416 (eq major-mode 'message-mode))
2417 (append (subseq actions 0 4)
2418 '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))
2419 (subseq actions 5)))
2420 ((string-match (image-file-name-regexp) candidate)
2421 (append (subseq actions 0 4)
2422 '(("Rotate image right" . anything-ff-rotate-image-right)
2423 ("Rotate image left" . anything-ff-rotate-image-left))
2424 (subseq actions 5)))
2425 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
2426 (car it) candidate))
2427 (append (subseq actions 0 4);(list (car actions))
2428 '(("Byte compile lisp file(s) `C-u to load'"
2429 . anything-find-files-byte-compile)
2430 ("Load File(s)" . anything-find-files-load-files))
2431 (subseq actions 5)))
2432 ((and (string-match "\.html$" candidate)
2433 (file-exists-p candidate))
2434 (append (subseq actions 0 4)
2435 '(("Browse url file" . browse-url-of-file))
2436 (subseq actions 5)))
2437 (t actions)))
2439 (defun anything-ff-gnus-attach-files (candidate)
2440 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
2441 (let ((flist (anything-marked-candidates)))
2442 (gnus-dired-attach flist)))
2444 (defun anything-ff-rotate-current-image1 (file &optional num-arg)
2445 "Rotate current image at NUM-ARG degrees.
2446 This is a destructive operation on FILE made by external tool mogrify."
2447 ;; When FILE is not an image-file, do nothing.
2448 (when (string-match (image-file-name-regexp) file)
2449 (if (executable-find "mogrify")
2450 (progn
2451 (shell-command (format "mogrify -rotate %s %s" (or num-arg 90) file))
2452 (when (buffer-live-p image-dired-display-image-buffer)
2453 (kill-buffer image-dired-display-image-buffer))
2454 (image-dired-display-image file)
2455 (message nil)
2456 (display-buffer (get-buffer image-dired-display-image-buffer)))
2457 (error "mogrify not found"))))
2459 (defun anything-ff-rotate-image-left (candidate)
2460 "Rotate image file CANDIDATE left.
2461 This affect directly file CANDIDATE."
2462 (anything-ff-rotate-current-image1 candidate -90))
2464 (defun anything-ff-rotate-image-right (candidate)
2465 "Rotate image file CANDIDATE right.
2466 This affect directly file CANDIDATE."
2467 (anything-ff-rotate-current-image1 candidate))
2469 (defun anything-ff-rotate-left-persistent ()
2470 "Rotate image left without quitting anything."
2471 (interactive)
2472 (anything-execute-persistent-action 'image-action1))
2474 (defun anything-ff-rotate-right-persistent ()
2475 "Rotate image right without quitting anything."
2476 (interactive)
2477 (anything-execute-persistent-action 'image-action2))
2479 ;; Have no effect if candidate is not an image file.
2480 (define-key anything-map (kbd "M-l") 'anything-ff-rotate-left-persistent)
2481 (define-key anything-map (kbd "M-r") 'anything-ff-rotate-right-persistent)
2483 (defun anything-find-files-persistent-action (candidate)
2484 "Open subtree CANDIDATE without quitting anything.
2485 If CANDIDATE is not a directory expand CANDIDATE filename.
2486 If CANDIDATE is alone, open file CANDIDATE filename.
2487 That's mean:
2488 First hit on C-z expand CANDIDATE second hit open file.
2489 If a prefix arg is given or `anything-follow-mode' is on open file."
2490 (let ((follow (buffer-local-value
2491 'anything-follow-mode
2492 (get-buffer-create anything-buffer)))
2493 (new-pattern (anything-get-selection))
2494 (num-lines-buf (with-current-buffer anything-buffer
2495 (count-lines (point-min) (point-max)))))
2496 (flet ((insert-in-minibuffer (fname)
2497 (with-selected-window (minibuffer-window)
2498 (unless follow
2499 (delete-minibuffer-contents)
2500 (set-text-properties 0 (length fname) nil fname)
2501 (insert fname)))))
2502 (cond (;; A symlink directory, expand it's truename.
2503 (and (file-directory-p candidate) (file-symlink-p candidate))
2504 (insert-in-minibuffer (file-name-as-directory
2505 (file-truename
2506 (expand-file-name candidate)))))
2507 ;; A directory, open it.
2508 ((file-directory-p candidate)
2509 (when (string= (anything-c-basename candidate) "..")
2510 (setq anything-ff-last-expanded anything-ff-default-directory))
2511 (insert-in-minibuffer (file-name-as-directory
2512 (expand-file-name candidate))))
2513 ;; A symlink file, expand to it's true name. (first hit)
2514 ((file-symlink-p candidate)
2515 (insert-in-minibuffer (file-truename candidate)))
2516 ;; A regular file, expand it, (first hit)
2517 ((and (>= num-lines-buf 3) (not current-prefix-arg) (not follow))
2518 (insert-in-minibuffer new-pattern))
2519 ;; An image file and it is the second hit on C-z,
2520 ;; show the file in `image-dired'.
2521 ((string-match (image-file-name-regexp) candidate)
2522 (when (buffer-live-p image-dired-display-image-buffer)
2523 (kill-buffer image-dired-display-image-buffer))
2524 (image-dired-display-image candidate)
2525 (message nil)
2526 (display-buffer image-dired-display-image-buffer))
2527 ;; Allow browsing archive on avfs fs.
2528 ;; Assume volume is already mounted with mountavfs.
2529 ((and anything-ff-avfs-directory
2530 (string-match
2531 (regexp-quote (expand-file-name anything-ff-avfs-directory))
2532 (file-name-directory candidate))
2533 (anything-ff-file-compressed-p candidate))
2534 (insert-in-minibuffer (concat candidate "#")))
2535 ;; On second hit we open file.
2536 (t (find-file candidate))))))
2538 (defvar anything-ff-avfs-directory nil
2539 "*The default avfs directory, usually '.avfs'.
2540 When this is set you will be able to expand archive filenames with `C-z'
2541 inside an avfs directory mounted with mountavfs.
2542 See <http://sourceforge.net/projects/avf/>.")
2543 (defvar anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
2544 "*Minimal list of compressed files extension.")
2545 (defun anything-ff-file-compressed-p (candidate)
2546 "Whether CANDIDATE is a compressed file or not."
2547 (member (file-name-extension candidate)
2548 anything-ff-file-compressed-list))
2550 (defun anything-c-insert-file-name-completion-at-point (candidate)
2551 "Insert file name completion at point."
2552 (if buffer-read-only
2553 (error "Error: Buffer `%s' is read-only" (buffer-name))
2554 (let* ((end (point))
2555 (guess (thing-at-point 'filename))
2556 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess)
2557 (string-match "^[^\~]" guess))))
2558 (set-text-properties 0 (length candidate) nil candidate)
2559 (if (and guess (not (string= guess "")) (string-match "^~\\|/.*" guess))
2560 (progn
2561 (search-backward guess (- (point) (length guess)))
2562 (delete-region (point) end)
2563 (if full-path-p
2564 (insert (expand-file-name candidate))
2565 (insert (abbreviate-file-name candidate))))
2566 (error "Aborting completion: No valid file name at point")))))
2568 (defun* anything-find-files-history (&key (comp-read t))
2569 "The `anything-find-files' history.
2570 Show the first `anything-ff-history-max-length' elements of `anything-ff-history'
2571 in an `anything-comp-read'."
2572 (let ((history (when anything-ff-history
2573 (loop with dup for i in anything-ff-history
2574 unless (member i dup) collect i into dup
2575 finally return dup)))) ; Remove dups.
2576 (when history
2577 (setq anything-ff-history
2578 (if (>= (length history) anything-ff-history-max-length)
2579 (subseq history 0 anything-ff-history-max-length)
2580 history))
2581 (if comp-read
2582 (anything-comp-read
2583 "Switch to Directory: "
2584 anything-ff-history
2585 :name "Anything Find Files History"
2586 :must-match t)
2587 anything-ff-history))))
2589 (defun anything-find-files-initial-input (&optional input)
2590 "Return INPUT if present, otherwise try to guess it."
2591 (or (and input (expand-file-name input))
2592 (anything-find-files-input
2593 (ffap-guesser)
2594 (thing-at-point 'filename))))
2596 ;;;###autoload
2597 (defun anything-find-files ()
2598 "Preconfigured `anything' for anything implementation of `find-file'.
2599 Called with a prefix arg show history if some.
2600 Don't call it from programs, use `anything-find-files1' instead.
2601 This is the starting point for nearly all actions you can do on files."
2602 (interactive)
2603 (let ((any-input (if (and current-prefix-arg anything-ff-history)
2604 (anything-find-files-history)
2605 (anything-find-files-initial-input))))
2606 (when (and (eq major-mode 'org-agenda-mode)
2607 org-directory
2608 (not any-input))
2609 (setq any-input (expand-file-name org-directory)))
2610 (if any-input
2611 (anything-find-files1 any-input)
2612 (setq any-input (expand-file-name (anything-c-current-directory)))
2613 (anything-find-files1 any-input (buffer-file-name (current-buffer))))))
2615 (defun anything-find-files1 (fname &optional preselect)
2616 "Find FNAME with `anything' completion.
2617 Like `find-file' but with `anything' support.
2618 Use it for non--interactive calls of `anything-find-files'."
2619 (when (get-buffer anything-action-buffer)
2620 (kill-buffer anything-action-buffer))
2621 (let ((anything-mp-highlight-delay nil))
2622 (anything :sources 'anything-c-source-find-files
2623 :input fname
2624 :preselect preselect
2625 :prompt "Find Files or Url: "
2626 :buffer "*Anything Find Files*")))
2628 (defun anything-find-files-input (fap tap)
2629 "Default input of `anything-find-files'."
2630 (let* ((def-dir (anything-c-current-directory))
2631 (lib (anything-find-library-at-point))
2632 (file-p (and fap (file-exists-p fap)
2633 (file-exists-p
2634 (file-name-directory (expand-file-name tap def-dir))))))
2635 (cond (lib)
2636 (file-p (expand-file-name tap def-dir))
2637 (t fap))))
2639 (defun anything-c-current-directory ()
2640 "Return current-directory name at point.
2641 Useful in dired buffers when there is inserted subdirs."
2642 (if (eq major-mode 'dired-mode)
2643 (dired-current-directory)
2644 default-directory))
2646 (defun anything-find-library-at-point ()
2647 "Try to find library path at point.
2648 Find inside `require' and `declare-function' sexp."
2649 (require 'find-func)
2650 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
2651 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
2652 (sexp (and beg-sexp end-sexp
2653 (buffer-substring-no-properties
2654 (1+ beg-sexp) (1- end-sexp)))))
2655 (ignore-errors
2656 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
2657 (find-library-name
2658 (replace-regexp-in-string
2659 "'\\|\)\\|\(" ""
2660 ;; If require use third arg, ignore it,
2661 ;; always use library path found in `load-path'.
2662 (second (split-string (match-string 0 sexp))))))
2663 ((and sexp (string-match-p "^declare-function" sexp))
2664 (find-library-name
2665 (replace-regexp-in-string
2666 "\"\\|ext:" ""
2667 (third (split-string sexp)))))
2668 (t nil)))))
2670 ;;; Anything completion for `write-file'.==> C-x C-w
2671 (defvar anything-c-source-write-file
2672 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
2673 ;; It is needed for filenames with capital letters
2674 (disable-shortcuts)
2675 (candidates . anything-find-files-get-candidates)
2676 (filtered-candidate-transformer anything-c-find-files-transformer)
2677 (persistent-action . anything-find-files-persistent-action)
2678 (persistent-help . "Expand Candidate")
2679 (volatile)
2680 (action .
2681 (("Write File" . (lambda (candidate)
2682 (write-file candidate 'confirm)))))))
2684 ;;;###autoload
2685 (defun anything-write-file ()
2686 "Preconfigured `anything' providing completion for `write-file'."
2687 (interactive)
2688 (anything 'anything-c-source-write-file
2689 (expand-file-name default-directory)
2690 "Write buffer to file: " nil nil "*Anything write file*"))
2692 ;;; Anything completion for `insert-file'.==> C-x i
2693 (defvar anything-c-source-insert-file
2694 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
2695 ;; It is needed for filenames with capital letters
2696 (disable-shortcuts)
2697 (candidates . anything-find-files-get-candidates)
2698 (filtered-candidate-transformer anything-c-find-files-transformer)
2699 (persistent-action . anything-find-files-persistent-action)
2700 (persistent-help . "Expand Candidate")
2701 (volatile)
2702 (action .
2703 (("Insert File" . (lambda (candidate)
2704 (when (y-or-n-p (format "Really insert %s in %s "
2705 candidate anything-current-buffer))
2706 (insert-file-contents candidate))))))))
2708 ;;;###autoload
2709 (defun anything-insert-file ()
2710 "Preconfigured `anything' providing completion for `insert-file'."
2711 (interactive)
2712 (anything 'anything-c-source-insert-file
2713 (expand-file-name default-directory)
2714 "Insert file: " nil nil "*Anything insert file*"))
2716 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2717 (defvar anything-c-source-copy-files
2718 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
2719 ;; It is needed for filenames with capital letters
2720 (disable-shortcuts)
2721 (candidates . anything-find-files-get-candidates)
2722 (filtered-candidate-transformer anything-c-find-files-transformer)
2723 (persistent-action . anything-find-files-persistent-action)
2724 (persistent-help . "Expand Candidate")
2725 (volatile)
2726 (action .
2727 (("Copy File"
2728 . (lambda (candidate)
2729 (anything-dired-action candidate :action 'copy)))
2730 ("Copy and Follow"
2731 . (lambda (candidate)
2732 (anything-dired-action candidate :action 'copy :follow t)))))))
2735 (defvar anything-c-source-rename-files
2736 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
2737 ;; It is needed for filenames with capital letters
2738 (disable-shortcuts)
2739 (candidates . anything-find-files-get-candidates)
2740 (filtered-candidate-transformer anything-c-find-files-transformer)
2741 (persistent-action . anything-find-files-persistent-action)
2742 (persistent-help . "Expand Candidate")
2743 (volatile)
2744 (action .
2745 (("Rename File"
2746 . (lambda (candidate)
2747 (anything-dired-action candidate :action 'rename)))
2748 ("Rename and Follow"
2749 . (lambda (candidate)
2750 (anything-dired-action candidate :action 'rename :follow t)))))))
2752 (defvar anything-c-source-symlink-files
2753 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
2754 ;; It is needed for filenames with capital letters
2755 (disable-shortcuts)
2756 (candidates . anything-find-files-get-candidates)
2757 (filtered-candidate-transformer anything-c-find-files-transformer)
2758 (persistent-action . anything-find-files-persistent-action)
2759 (persistent-help . "Expand Candidate")
2760 (volatile)
2761 (action
2762 . (("Symlink File"
2763 . (lambda (candidate)
2764 (anything-dired-action candidate :action 'symlink)))
2765 ("RelSymlink File"
2766 . (lambda (candidate)
2767 (anything-dired-action candidate :action 'relsymlink)))))))
2770 (defvar anything-c-source-hardlink-files
2771 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
2772 ;; It is needed for filenames with capital letters
2773 (disable-shortcuts)
2774 (candidates . anything-find-files-get-candidates)
2775 (filtered-candidate-transformer anything-c-find-files-transformer)
2776 (persistent-action . anything-find-files-persistent-action)
2777 (persistent-help . "Expand Candidate")
2778 (volatile)
2779 (action
2780 . (("Hardlink File"
2781 . (lambda (candidate)
2782 (anything-dired-action candidate :action 'hardlink)))))))
2785 ;; Emacs bugfix for version < 24.
2786 ;; This fix copying directory recursively from dired and copy-directory
2787 ;; when called interactively and not.
2788 ;; (copy only contents of directory whithout subdir).
2789 (when (< emacs-major-version 24)
2791 (defun copy-directory (directory newname &optional keep-time parents copy-contents-only)
2792 "Copy DIRECTORY to NEWNAME. Both args must be strings.
2793 If NEWNAME names an existing directory, copy DIRECTORY as subdirectory there.
2795 This function always sets the file modes of the output files to match
2796 the corresponding input file.
2798 The third arg KEEP-TIME non-nil means give the output files the same
2799 last-modified time as the old ones. (This works on only some systems.)
2801 A prefix arg makes KEEP-TIME non-nil.
2803 Noninteractively, the last argument PARENTS says whether to
2804 create parent directories if they don't exist. Interactively,
2805 this happens by default."
2806 (interactive
2807 (let ((dir (read-directory-name
2808 "Copy directory: " default-directory default-directory t nil)))
2809 (list dir
2810 (read-file-name
2811 (format "Copy directory %s to: " dir)
2812 default-directory default-directory nil nil)
2813 current-prefix-arg t)))
2814 ;; If default-directory is a remote directory, make sure we find its
2815 ;; copy-directory handler.
2816 (let ((handler (or (find-file-name-handler directory 'copy-directory)
2817 (find-file-name-handler newname 'copy-directory))))
2818 (if handler
2819 (funcall handler 'copy-directory directory newname keep-time parents)
2821 ;; Compute target name.
2822 (setq directory (directory-file-name (expand-file-name directory))
2823 newname (directory-file-name (expand-file-name newname)))
2825 (if (not (file-directory-p newname))
2826 ;; If NEWNAME is not an existing directory, create it; that
2827 ;; is where we will copy the files of DIRECTORY.
2828 (make-directory newname parents)
2829 ;; If NEWNAME is an existing directory, we will copy into
2830 ;; NEWNAME/[DIRECTORY-BASENAME].
2831 (unless copy-contents-only
2832 (setq newname (expand-file-name
2833 (file-name-nondirectory
2834 (directory-file-name directory))
2835 newname))
2836 (and (file-exists-p newname)
2837 (not (file-directory-p newname))
2838 (error "Cannot overwrite non-directory %s with a directory"
2839 newname))
2840 (make-directory newname t)))
2842 ;; Copy recursively.
2843 (dolist (file
2844 ;; We do not want to copy "." and "..".
2845 (directory-files directory 'full
2846 directory-files-no-dot-files-regexp))
2847 (if (file-directory-p file)
2848 (copy-directory file newname keep-time parents)
2849 (let ((target (expand-file-name (file-name-nondirectory file) newname))
2850 (attrs (file-attributes file)))
2851 (if (stringp (car attrs)) ; Symbolic link
2852 (make-symbolic-link (car attrs) target t)
2853 (copy-file file target t keep-time)))))
2855 ;; Set directory attributes.
2856 (set-file-modes newname (file-modes directory))
2857 (when keep-time
2858 (set-file-times newname (nth 5 (file-attributes directory)))))))
2860 (defun dired-copy-file (from to ok-flag)
2861 (when (and (file-directory-p from)
2862 (file-directory-p to))
2863 (setq to (file-name-directory to)))
2864 (dired-handle-overwrite to)
2865 (dired-copy-file-recursive from to ok-flag dired-copy-preserve-time t
2866 dired-recursive-copies)))
2869 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
2870 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2871 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2872 (let ((fn (case action
2873 ('copy 'dired-copy-file)
2874 ('rename 'dired-rename-file)
2875 ('symlink 'make-symbolic-link)
2876 ('relsymlink 'dired-make-relative-symlink)
2877 ('hardlink 'dired-hardlink)))
2878 (marker (case action
2879 ((copy rename) dired-keep-marker-copy)
2880 ('symlink dired-keep-marker-symlink)
2881 ('relsymlink dired-keep-marker-relsymlink)
2882 ('hardlink dired-keep-marker-hardlink)))
2883 (dirflag (and (= (length files) 1)
2884 (file-directory-p (car files))
2885 (not (file-directory-p candidate)))))
2886 (dired-create-files
2887 fn (symbol-name action) files
2888 ;; CANDIDATE is the destination.
2889 (if (file-directory-p candidate)
2890 ;; When CANDIDATE is a directory, build file-name in this directory.
2891 ;; Else we use CANDIDATE.
2892 #'(lambda (from)
2893 (expand-file-name (file-name-nondirectory from) candidate))
2894 #'(lambda (from) candidate))
2895 marker)
2896 (when follow
2897 (let ((moved-flist (anything-get-dest-fnames-from-list files candidate dirflag))
2898 (target (directory-file-name candidate)))
2899 (unwind-protect
2900 (progn
2901 (setq anything-ff-cand-to-mark moved-flist)
2902 (if (and dirflag (eq action 'rename))
2903 (anything-find-files1 (file-name-directory target) target)
2904 (anything-find-files1 candidate)))
2905 (setq anything-ff-cand-to-mark nil))))))
2907 ;; Internal
2908 (defvar anything-ff-cand-to-mark nil)
2910 (defun anything-c-basename (fname)
2911 "Resolve basename of file or directory named FNAME."
2912 (file-name-nondirectory (directory-file-name fname)))
2914 (defun anything-get-dest-fnames-from-list (flist dest-cand rename-dir-flag)
2915 "Transform filenames of FLIST to abs of DEST-CAND."
2916 ;; At this point files have been renamed/copied at destination.
2917 ;; That's mean DEST-CAND exists.
2918 (loop
2919 with dest = (expand-file-name dest-cand)
2920 for src in flist
2921 for basename-src = (anything-c-basename src)
2922 for fname = (cond (rename-dir-flag (directory-file-name dest))
2923 ((file-directory-p dest)
2924 (concat (file-name-as-directory dest) basename-src))
2925 (t dest))
2926 when (file-exists-p fname)
2927 collect fname into tmp-list
2928 finally return (sort tmp-list 'string<)))
2930 (defun anything-c-maybe-mark-candidates ()
2931 "Mark all candidates of list `anything-ff-cand-to-mark'."
2932 (when (and (string= (assoc-default 'name (anything-get-current-source))
2933 (assoc-default 'name anything-c-source-find-files))
2934 anything-ff-cand-to-mark)
2935 (with-anything-window
2936 (while anything-ff-cand-to-mark
2937 (if (search-forward (car anything-ff-cand-to-mark) (point-at-eol) t)
2938 (progn
2939 (anything-mark-current-line)
2940 (anything-make-visible-mark)
2941 (forward-line 1)
2942 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
2943 (forward-line 1)))
2944 (unless (anything-this-visible-mark)
2945 (anything-prev-visible-mark)))))
2947 (add-hook 'anything-after-update-hook #'anything-c-maybe-mark-candidates)
2949 (defun* anything-dired-do-action-on-file (&key action)
2950 (let* ((files (dired-get-marked-files))
2951 (len (length files))
2952 (fname (if (> len 1)
2953 (format "* %d Files" len)
2954 (car files)))
2955 (source (case action
2956 ('copy 'anything-c-source-copy-files)
2957 ('rename 'anything-c-source-rename-files)
2958 ('symlink 'anything-c-source-symlink-files)
2959 ('hardlink 'anything-c-source-hardlink-files)))
2960 (prompt-fm (case action
2961 ('copy "Copy %s to: ")
2962 ('rename "Rename %s to: ")
2963 ('symlink "Symlink %s to: ")
2964 ('hardlink "Hardlink %s to: ")))
2965 (buffer (case action
2966 ('copy "*Anything Copy Files*")
2967 ('rename "*Anything Rename Files*")
2968 ('symlink "*Anything Symlink Files*")
2969 ('hardlink "*Anything Hardlink Files*"))))
2970 (anything source
2971 (or (dired-dwim-target-directory)
2972 (expand-file-name (anything-c-current-directory)))
2973 (format prompt-fm fname) nil nil buffer)))
2976 ;;;###autoload
2977 (defun anything-dired-rename-file ()
2978 "Preconfigured `anything' to rename files from dired."
2979 (interactive)
2980 (anything-dired-do-action-on-file :action 'rename))
2982 ;;;###autoload
2983 (defun anything-dired-copy-file ()
2984 "Preconfigured `anything' to copy files from dired."
2985 (interactive)
2986 (anything-dired-do-action-on-file :action 'copy))
2988 ;;;###autoload
2989 (defun anything-dired-symlink-file ()
2990 "Preconfigured `anything' to symlink files from dired."
2991 (interactive)
2992 (anything-dired-do-action-on-file :action 'symlink))
2994 ;;;###autoload
2995 (defun anything-dired-hardlink-file ()
2996 "Preconfigured `anything' to hardlink files from dired."
2997 (interactive)
2998 (anything-dired-do-action-on-file :action 'hardlink))
3000 (defvar anything-dired-bindings nil)
3001 ;;;###autoload
3002 (defun anything-dired-bindings (&optional arg)
3003 "Replace usual dired commands `C' and `R' by anything ones.
3004 When call interactively toggle dired bindings and anything bindings.
3005 When call non--interactively with arg > 0, enable anything bindings.
3006 You can put (anything-dired-binding 1) in init file to enable anything bindings."
3007 (interactive)
3008 (if (or (and arg (> arg 0)) (not anything-dired-bindings))
3009 ;; Replace dired bindings.
3010 (progn
3011 (substitute-key-definition
3012 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
3013 (substitute-key-definition
3014 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
3015 (substitute-key-definition
3016 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
3017 (substitute-key-definition
3018 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map)
3019 (setq anything-dired-bindings t))
3020 ;; Replace anything bindings.
3021 (substitute-key-definition
3022 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
3023 (substitute-key-definition
3024 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
3025 (substitute-key-definition
3026 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
3027 (substitute-key-definition
3028 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)
3029 (setq anything-dired-bindings nil)))
3031 (defun* anything-c-read-file-name (prompt
3032 &key
3033 (initial-input (expand-file-name default-directory))
3034 (buffer "*Anything Completions*")
3035 test
3036 (history nil)
3037 (marked-candidates nil)
3038 (persistent-action 'anything-find-files-persistent-action)
3039 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
3040 "Anything `read-file-name' emulation.
3041 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
3042 (when (get-buffer anything-action-buffer)
3043 (kill-buffer anything-action-buffer))
3044 (let ((anything-mp-highlight-delay nil))
3045 (flet ((action-fn (candidate)
3046 (if marked-candidates
3047 (anything-marked-candidates)
3048 (identity candidate))))
3049 (or (anything
3050 :sources
3051 `(((name . ,(concat "Read File Name History" anything-c-find-files-doc-header))
3052 (candidates . (lambda ()
3053 (anything-comp-read-get-candidates history)))
3054 (volatile)
3055 (persistent-action . ,persistent-action)
3056 (persistent-help . ,persistent-help)
3057 (action . ,'action-fn))
3058 ((name . ,(concat "Read file name" anything-c-find-files-doc-header))
3059 ;; It is needed for filenames with capital letters
3060 (disable-shortcuts)
3061 (candidates . (lambda ()
3062 (if test
3063 (loop with seq = (anything-find-files-get-candidates)
3064 for fname in seq when (funcall test fname)
3065 collect fname)
3066 (anything-find-files-get-candidates))))
3067 (filtered-candidate-transformer anything-c-find-files-transformer)
3068 (persistent-action . ,persistent-action)
3069 (persistent-help . ,persistent-help)
3070 (volatile)
3071 (action . ,'action-fn)))
3072 :input initial-input
3073 :prompt prompt
3074 :resume 'noresume
3075 :buffer buffer)
3076 (keyboard-quit)))))
3078 ;;; File Cache
3079 (defvar anything-c-source-file-cache-initialized nil)
3081 (defvar anything-c-file-cache-files nil)
3083 (defvar anything-c-source-file-cache
3084 '((name . "File Cache")
3085 (init
3086 . (lambda ()
3087 (require 'filecache nil t)
3088 (unless anything-c-source-file-cache-initialized
3089 (setq anything-c-file-cache-files
3090 (loop for item in file-cache-alist append
3091 (destructuring-bind (base &rest dirs) item
3092 (loop for dir in dirs collect
3093 (concat dir base)))))
3094 (defadvice file-cache-add-file (after file-cache-list activate)
3095 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
3096 (setq anything-c-source-file-cache-initialized t))))
3097 (candidates . anything-c-file-cache-files)
3098 (match anything-c-match-on-file-name
3099 anything-c-match-on-directory-name)
3100 (type . file)))
3101 ;; (anything 'anything-c-source-file-cache)
3103 ;;; Locate
3104 ;; NOTE for WINDOZE users:
3105 ;; You have to install Everything with his command line interface here:
3106 ;; http://www.voidtools.com/download.php
3108 (defvar anything-c-locate-command
3109 (case system-type
3110 ('gnu/linux "locate -i -r %s")
3111 ('berkeley-unix "locate -i %s")
3112 ('windows-nt "es -i -r %s")
3113 (t "locate %s"))
3114 "A list of arguments for locate program.
3115 The \"-r\" option must be the last option.")
3117 (defun anything-c-locate-init ()
3118 "Initialize async locate process for `anything-c-source-locate'."
3119 (setq mode-line-format
3120 '(" " mode-line-buffer-identification " "
3121 (line-number-mode "%l") " "
3122 (:eval (propertize "(Locate Process Running) "
3123 'face '((:foreground "red"))))))
3124 (prog1
3125 (start-process-shell-command "locate-process" nil
3126 (format anything-c-locate-command
3127 anything-pattern))
3128 (set-process-sentinel (get-process "locate-process")
3129 #'(lambda (process event)
3130 (when (string= event "finished\n")
3131 (kill-local-variable 'mode-line-format)
3132 (with-anything-window
3133 (anything-update-move-first-line)))))))
3135 (defvar anything-c-source-locate
3136 '((name . "Locate")
3137 (candidates . anything-c-locate-init)
3138 (type . file)
3139 (requires-pattern . 3)
3140 (delayed))
3141 "Find files matching the current input pattern with locate.")
3143 ;; (anything 'anything-c-source-locate)
3145 ;;; Grep
3146 ;; NOTE: the -d option with skip avoid error on windows.
3147 ;; It have no effect on GNU/Linux.
3148 (defvar anything-c-grep-default-command "grep -d skip -niH -e %s %s %s"
3149 "Default format command for `anything-do-grep'.")
3151 (defvar anything-c-grep-default-function 'anything-c-grep-init)
3153 (defface anything-grep-match
3154 '((t (:inherit match)))
3155 "Face used to highlight grep matches."
3156 :group 'anything)
3158 (defface anything-grep-file
3159 '((t (:foreground "BlueViolet" :underline t)))
3160 "Face used to highlight grep results filenames."
3161 :group 'anything)
3163 (defface anything-grep-lineno
3164 '((t (:foreground "Darkorange1")))
3165 "Face used to highlight grep number lines."
3166 :group 'anything)
3168 (defun anything-c-grep-prepare-candidates (candidates)
3169 "Prepare filenames and directories CANDIDATES for grep command line."
3170 ;; If one or more candidate is a directory, search in all files
3171 ;; of this candidate (e.g /home/user/directory/*).
3172 ;; If r option is enabled search also in subdidrectories.
3173 ;; We need here to expand wildcards to support crap windows filenames
3174 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
3175 (loop for i in candidates append
3176 (cond ((and (file-directory-p i)
3177 (anything-c-grep-recurse-p))
3178 (list (expand-file-name i)))
3179 ((file-directory-p i)
3180 (file-expand-wildcards (concat (file-name-as-directory
3181 (expand-file-name i))
3182 "*") t))
3183 ((string-match "\*" i) (file-expand-wildcards i t))
3184 (t (list i))) into of
3185 finally return
3186 (mapconcat #'(lambda (x) (shell-quote-argument x)) of " ")))
3188 (defun anything-c-grep-recurse-p ()
3189 "Check if `anything-do-grep1' have switched to recursive."
3190 (let ((args (replace-regexp-in-string
3191 "grep" "" anything-c-grep-default-command)))
3192 (string-match-p "r\\|recurse" args)))
3194 (defun anything-c-grep-init (only-files &optional include)
3195 "Start an asynchronous grep process in ONLY-FILES list."
3196 (let* ((fnargs (anything-c-grep-prepare-candidates
3197 (if (file-remote-p anything-ff-default-directory)
3198 (mapcar #'(lambda (x) (file-remote-p x 'localname)) only-files)
3199 only-files)))
3200 (ignored-files (mapconcat
3201 #'(lambda (x)
3202 (concat "--exclude=" (shell-quote-argument x)))
3203 grep-find-ignored-files " "))
3204 (ignored-dirs (mapconcat ; Need grep version 2.5.4 of Gnuwin32 on windoze.
3205 #'(lambda (x)
3206 (concat "--exclude-dir=" (shell-quote-argument x)))
3207 grep-find-ignored-directories " "))
3208 (exclude (if (anything-c-grep-recurse-p)
3209 (concat (or include ignored-files) " " ignored-dirs)
3210 ignored-files)))
3211 (setq mode-line-format
3212 '(" " mode-line-buffer-identification " "
3213 (line-number-mode "%l") " "
3214 (:eval (propertize "(Grep Process Running) "
3215 'face '((:foreground "red"))))))
3216 (prog1
3217 (let ((default-directory anything-ff-default-directory))
3218 (start-file-process-shell-command
3219 "grep-process" nil
3220 (format anything-c-grep-default-command
3221 (shell-quote-argument anything-pattern)
3222 fnargs
3223 exclude)))
3224 (message nil)
3225 (set-process-sentinel
3226 (get-process "grep-process")
3227 #'(lambda (process event)
3228 (when (string= event "finished\n")
3229 (kill-local-variable 'mode-line-format)
3230 (with-anything-window
3231 (anything-update-move-first-line))))))))
3233 (defun anything-c-grep-action (candidate &optional where mark)
3234 "Define a default action for `anything-do-grep' on CANDIDATE.
3235 WHERE can be one of other-window, elscreen, other-frame."
3236 (let* ((split (anything-c-grep-split-line candidate))
3237 (lineno (string-to-number (nth 1 split)))
3238 (loc-fname (car split))
3239 (tramp-method (file-remote-p anything-ff-default-directory 'method))
3240 (tramp-host (file-remote-p anything-ff-default-directory 'host))
3241 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
3242 (fname (if tramp-host (concat tramp-prefix loc-fname) loc-fname)))
3243 (case where
3244 (other-window (find-file-other-window fname))
3245 (elscreen (anything-elscreen-find-file fname))
3246 (other-frame (find-file-other-frame fname))
3247 (t (find-file fname)))
3248 (anything-goto-line lineno)
3249 (set-marker (mark-marker) (point))
3250 (when mark
3251 (push-mark (point) 'nomsg))))
3254 (defun anything-c-grep-persistent-action (candidate)
3255 "Persistent action for `anything-do-grep'.
3256 With a prefix arg record CANDIDATE in `mark-ring'."
3257 (if current-prefix-arg
3258 (anything-c-grep-action candidate nil 'mark)
3259 (anything-c-grep-action candidate))
3260 (anything-match-line-color-current-line))
3262 (defun anything-do-grep1 (only &optional recurse)
3263 "Launch grep with a list of ONLY files.
3264 When RECURSE is given use -r option of grep and prompt user
3265 to set the --include args of grep.
3266 You can give more than one arg separated by space.
3267 e.g *.el *.py *.tex.
3268 If it's empty --exclude `grep-find-ignored-files' is used instead."
3269 (let* ((anything-compile-source-functions
3270 ;; rule out anything-match-plugin because the input is one regexp.
3271 (delq 'anything-compile-source--match-plugin
3272 (copy-sequence anything-compile-source-functions)))
3273 (include-files (and recurse (read-string "OnlyExt(*.[ext]): ")))
3274 (anything-c-grep-default-command (if recurse "grep -nirH -e %s %s %s"
3275 anything-c-grep-default-command))
3276 ;; Disable match-plugin and use here own highlighting.
3277 (anything-mp-highlight-delay nil))
3278 (when include-files
3279 (setq include-files
3280 (and (not (string= include-files ""))
3281 (mapconcat #'(lambda (x)
3282 (concat "--include=" (shell-quote-argument x)))
3283 (split-string include-files) " "))))
3284 ;; When called as action from an other source e.g *-find-files
3285 ;; we have to kill action buffer.
3286 (when (get-buffer anything-action-buffer)
3287 (kill-buffer anything-action-buffer))
3288 (anything
3289 :sources
3290 `(((name . "Grep (M-up/down - next/prec file)")
3291 (candidates
3292 . (lambda () (if include-files
3293 (funcall anything-c-grep-default-function only include-files)
3294 (funcall anything-c-grep-default-function only))))
3295 (filtered-candidate-transformer anything-c-grep-cand-transformer)
3296 (candidate-number-limit . 9999)
3297 (action . ,(delq
3299 `(("Find File" . anything-c-grep-action)
3300 ("Find file other window"
3301 . (lambda (candidate)
3302 (anything-c-grep-action candidate 'other-window)))
3303 ,(and (locate-library "elscreen")
3304 '("Find file in Elscreen"
3305 . (lambda (candidate)
3306 (anything-c-grep-action candidate 'elscreen))))
3307 ("Find file other frame"
3308 . (lambda (candidate)
3309 (anything-c-grep-action candidate 'other-frame))))))
3310 (persistent-action . (lambda (candidate)
3311 (anything-c-grep-persistent-action candidate)))
3312 (persistent-help . "Jump to line (`C-u' Record in mark ring)")
3313 (requires-pattern . 3)
3314 (delayed)))
3315 :buffer "*anything grep*")))
3317 ;;;###autoload
3318 (defun anything-do-grep ()
3319 "Preconfigured anything for grep.
3320 Contrarily to Emacs `grep' no default directory is given, but
3321 the full path of candidates in ONLY.
3322 That allow to grep different files not only in `default-directory' but anywhere
3323 by marking them (C-<SPACE>). If one or more directory is selected
3324 grep will search in all files of these directories.
3325 You can use also wildcard in the base name of candidate.
3326 If a prefix arg is given use the -r option of grep.
3327 See also `anything-do-grep1'."
3328 (interactive)
3329 (let ((only (anything-c-read-file-name
3330 "Search in file(s): " :marked-candidates t))
3331 (prefarg current-prefix-arg))
3332 (anything-do-grep1 only prefarg)))
3334 (defun anything-c-grep-split-line (line)
3335 "Split a grep output line."
3336 (let (beg fname lineno str)
3337 ;; Don't print until grep line is valid.
3338 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
3339 (with-temp-buffer
3340 (insert line)
3341 (goto-char (point-min))
3342 (setq beg (point))
3343 (forward-char 2)
3344 (re-search-forward ":" nil t)
3345 (setq fname (buffer-substring-no-properties beg (1- (point))))
3346 (setq beg (point))
3347 (re-search-forward ":" nil t)
3348 (setq lineno (buffer-substring-no-properties beg (1- (point))))
3349 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
3350 (list fname lineno str))))
3352 (defun anything-c-grep-cand-transformer (candidates sources)
3353 "Filtered candidate transformer function for `anything-do-grep'."
3354 (loop for i in candidates
3355 for split = (and i (anything-c-grep-split-line i))
3356 for fname = (car split)
3357 for lineno = (nth 1 split)
3358 for str = (nth 2 split)
3359 when (and fname lineno str)
3360 collect
3361 (cons (concat (propertize (file-name-nondirectory fname)
3362 'face 'anything-grep-file
3363 'help-echo fname) ":"
3364 (propertize lineno 'face 'anything-grep-lineno) ":"
3365 (anything-c-grep-highlight-match str))
3366 i)))
3368 (defun anything-c-grep-highlight-match (str)
3369 "Highlight in string STR all occurences matching `anything-pattern'."
3370 (condition-case nil
3371 (with-temp-buffer
3372 (insert str)
3373 (goto-char (point-min))
3374 (while (and (re-search-forward anything-pattern nil t)
3375 (> (- (match-end 0) (match-beginning 0)) 0))
3376 (add-text-properties
3377 (match-beginning 0) (match-end 0)
3378 '(face anything-grep-match)))
3379 (buffer-string))
3380 (error nil)))
3382 ;; Go to next or precedent file (common to etags and grep).
3383 (defun anything-c-goto-next-or-prec-file (n)
3384 "Go to next or precedent candidate file in anything grep/etags buffers.
3385 If N is positive go forward otherwise go backward."
3386 (let ((cur-source (assoc-default 'name (anything-get-current-source))))
3387 (with-anything-window
3388 (if (or (string= cur-source "Grep (M-up/down - next/prec file)")
3389 (string-match "^Etags.*" cur-source))
3390 (let* ((current-line-list (split-string
3391 (buffer-substring
3392 (point-at-bol)
3393 (point-at-eol)) ":"))
3394 (current-fname (nth 0 current-line-list))
3395 (fn-b-o-f (if (eq n 1) 'eobp 'bobp)))
3396 (catch 'break
3397 (while (not (funcall fn-b-o-f))
3398 (forward-line n) ; Go forward or backward depending of n value.
3399 (unless (search-forward current-fname (point-at-eol) t)
3400 (anything-mark-current-line)
3401 (throw 'break nil))))
3402 (cond ((and (eq n 1) (eobp))
3403 (re-search-backward ".")
3404 (forward-line 0)
3405 (anything-mark-current-line))
3406 ((and (< n 1) (bobp))
3407 (forward-line 1)
3408 (anything-mark-current-line))))
3409 (if (eq n 1)
3410 (anything-next-line)
3411 (anything-previous-line))))))
3413 ;;;###autoload
3414 (defun anything-c-goto-precedent-file ()
3415 "Go to precedent file in anything grep/etags buffers."
3416 (interactive)
3417 (anything-c-goto-next-or-prec-file -1))
3419 ;;;###autoload
3420 (defun anything-c-goto-next-file ()
3421 "Go to precedent file in anything grep/etags buffers."
3422 (interactive)
3423 (anything-c-goto-next-or-prec-file 1))
3425 ;; This keys affect etags and grep only.
3426 ;; in other sources they do nothing, just going next or precedent line.
3427 (define-key anything-map (kbd "M-<down>") #'anything-c-goto-next-file)
3428 (define-key anything-map (kbd "M-<up>") #'anything-c-goto-precedent-file)
3430 ;; Yank text at point.
3431 (defvar anything-yank-point nil)
3432 ;;;###autoload
3433 (defun anything-yank-text-at-point ()
3434 "Yank text at point in minibuffer."
3435 (interactive)
3436 (let (input)
3437 (flet ((insert-in-minibuffer (word)
3438 (with-selected-window (minibuffer-window)
3439 (let ((str anything-pattern))
3440 (delete-minibuffer-contents)
3441 (set-text-properties 0 (length word) nil word)
3442 (insert (concat str word))))))
3443 (with-current-buffer anything-current-buffer
3444 ;; Start to initial point if C-w have never been hit.
3445 (unless anything-yank-point (setq anything-yank-point (point)))
3446 (and anything-yank-point (goto-char anything-yank-point))
3447 (forward-word 1)
3448 (setq input (buffer-substring-no-properties anything-yank-point (point)))
3449 (setq anything-yank-point (point))) ; End of last forward-word
3450 (insert-in-minibuffer input))))
3452 (defun anything-reset-yank-point ()
3453 (setq anything-yank-point nil))
3455 (add-hook 'anything-after-persistent-action-hook 'anything-reset-yank-point)
3456 (add-hook 'anything-cleanup-hook 'anything-reset-yank-point)
3457 (define-key anything-map (kbd "C-w") 'anything-yank-text-at-point)
3459 ;;; Etags
3460 (eval-when-compile
3461 (when (locate-library "anything-etags.el")
3462 (display-warning
3463 '(anything-config)
3464 "You are using obsolete library `anything-etags.el' and should remove it."
3465 :warning)))
3467 (defcustom anything-c-etags-tag-file-name "TAGS"
3468 "Etags tag file name."
3469 :type 'string
3470 :group 'anything-config)
3472 (defcustom anything-c-etags-tag-file-search-limit 10
3473 "The limit level of directory to search tag file.
3474 Don't search tag file deeply if outside this value."
3475 :type 'number
3476 :group 'anything-config)
3478 (defvar anything-c-etags-tag-file-dir nil
3479 "Etags file directory.")
3480 (defvar anything-c-etags-mtime-alist nil)
3481 (defvar anything-c-etags-cache (make-hash-table :test 'equal))
3483 (defun anything-c-etags-get-tag-file ()
3484 "Get Etags tag file."
3485 ;; Get tag file from `default-directory' or upper directory.
3486 (let ((current-dir (anything-c-etags-find-tag-file default-directory)))
3487 ;; Return nil if not find tag file.
3488 (when current-dir
3489 (setq anything-c-etags-tag-file-dir current-dir) ;set tag file directory
3490 (expand-file-name anything-c-etags-tag-file-name current-dir))))
3492 (defun anything-c-etags-find-tag-file (current-dir)
3493 "Find tag file.
3494 Try to find tag file in upper directory if haven't found in CURRENT-DIR."
3495 (flet ((file-exists? (dir)
3496 (let ((tag-path (expand-file-name anything-c-etags-tag-file-name dir)))
3497 (and (stringp tag-path)
3498 (file-exists-p tag-path)
3499 (file-readable-p tag-path)))))
3500 (loop with count = 0
3501 until (file-exists? current-dir)
3502 ;; Return nil if outside the value of
3503 ;; `anything-c-etags-tag-file-search-limit'.
3504 if (= count anything-c-etags-tag-file-search-limit)
3505 do (return nil)
3506 ;; Or search upper directories.
3507 else
3508 do (incf count)
3509 (setq current-dir (expand-file-name (concat current-dir "../")))
3510 finally return current-dir)))
3512 (defun anything-c-source-etags-header-name (x)
3513 (concat "Etags in "
3514 (with-current-buffer anything-current-buffer
3515 (anything-c-etags-get-tag-file))))
3517 (defmacro anything-c-etags-create-buffer (file)
3518 `(let* ((tag-fname ,file)
3520 (split (with-current-buffer (find-file-noselect tag-fname)
3521 (prog1
3522 (split-string (buffer-string) "\n" 'omit-nulls)
3523 (setq max (line-number-at-pos (point-max)))
3524 (kill-buffer))))
3525 (progress-reporter (make-progress-reporter "Loading tag file..." 0 max)))
3526 (loop
3527 with fname
3528 with cand
3529 for i in split for count from 0
3530 for elm = (unless (string-match "^\x0c" i)
3531 (anything-aif (string-match "\177" i)
3532 (substring i 0 it)
3534 do (cond ((and elm (string-match "^\\(.+\\),[0-9]+" elm))
3535 (setq fname (match-string 1 elm)))
3536 (elm (setq cand (concat fname ": " elm)))
3537 (t (setq cand nil)))
3538 when cand do (progn
3539 (insert (concat cand "\n"))
3540 (progress-reporter-update progress-reporter count)))))
3542 (defun anything-c-etags-init ()
3543 (let ((tagfile (anything-c-etags-get-tag-file)))
3544 (when tagfile
3545 (with-current-buffer (anything-candidate-buffer 'global)
3546 (anything-aif (gethash tagfile anything-c-etags-cache)
3547 (insert it)
3548 (anything-c-etags-create-buffer tagfile)
3549 (puthash tagfile (buffer-string) anything-c-etags-cache)
3550 (anything-aif (assoc tagfile anything-c-etags-mtime-alist)
3551 ;; If an entry exists modify it.
3552 (setcdr it (anything-c-etags-mtime tagfile))
3553 ;; No entry create a new one.
3554 (add-to-list 'anything-c-etags-mtime-alist
3555 (cons tagfile (anything-c-etags-mtime tagfile)))))))))
3557 (defvar anything-c-source-etags-select
3558 '((name . "Etags")
3559 (header-name . anything-c-source-etags-header-name)
3560 (init . anything-c-etags-init)
3561 (candidates-in-buffer)
3562 (action . anything-c-etags-default-action)
3563 (persistent-action . (lambda (candidate)
3564 (anything-c-etags-default-action candidate)
3565 (anything-match-line-color-current-line)))))
3567 (defun anything-c-etags-default-action (candidate)
3568 (let* ((split (split-string candidate ": "))
3569 (fname (expand-file-name
3570 (car split) anything-c-etags-tag-file-dir))
3571 (elm (cadr split)))
3572 (find-file fname)
3573 (goto-char (point-min))
3574 (search-forward elm nil t)
3575 (goto-char (match-beginning 0))))
3577 (defun anything-c-etags-select (arg)
3578 "Preconfigured anything for etags.
3579 Called with one prefix arg use symbol at point as initial input.
3580 Called with two prefix arg reinitialize cache.
3581 If tag file have been modified reinitialize cache."
3582 (interactive "P")
3583 (let ((tag (anything-c-etags-get-tag-file))
3584 (init (and (equal arg '(4)) (thing-at-point 'symbol)))
3585 (anything-quit-if-no-candidate t)
3586 (anything-execute-action-at-once-if-one t))
3587 (when (or (equal arg '(16))
3588 (and anything-c-etags-mtime-alist
3589 (anything-c-etags-file-modified-p tag)))
3590 (remhash tag anything-c-etags-cache))
3591 (if (and tag (file-exists-p tag))
3592 (anything :sources 'anything-c-source-etags-select
3593 :input init
3594 :buffer "*anything etags*")
3595 (message "Error: No tag file found, please create one with etags shell command."))))
3597 (defun anything-c-etags-mtime (file)
3598 "Last modification time of FILE."
3599 (cadr (nth 5 (file-attributes file))))
3601 (defun anything-c-etags-file-modified-p (file)
3602 "Check if tag FILE have been modified in this session.
3603 If FILE is nil return nil."
3604 (let ((last-modif (and file
3605 (assoc-default file anything-c-etags-mtime-alist))))
3606 (and last-modif
3607 (/= last-modif (anything-c-etags-mtime file)))))
3609 ;;; Recentf files
3610 (defvar anything-c-source-recentf
3611 '((name . "Recentf")
3612 (init . (lambda ()
3613 (require 'recentf)
3614 (or recentf-mode (recentf-mode 1))
3615 ;; Big value empowers anything/recentf
3616 (when (and (numberp recentf-max-saved-items)
3617 (<= recentf-max-saved-items 20))
3618 (setq recentf-max-saved-items 500))))
3619 (candidates . recentf-list)
3620 (match anything-c-match-on-file-name
3621 anything-c-match-on-directory-name)
3622 (type . file))
3623 "See (info \"(emacs)File Conveniences\").
3624 if `recentf-max-saved-items' is too small, set it to 500.")
3625 ;; (anything 'anything-c-source-recentf)
3627 ;;; ffap
3628 (eval-when-compile (require 'ffap))
3629 (defvar anything-c-source-ffap-guesser
3630 '((name . "File at point")
3631 (init . (lambda () (require 'ffap)))
3632 (candidates . (lambda ()
3633 (anything-aif
3634 (with-current-buffer anything-current-buffer
3635 (ffap-guesser))
3636 (list it))))
3637 (type . file)))
3638 ;; (anything 'anything-c-source-ffap-guesser)
3640 ;;; ffap with line number
3641 (defun anything-c-ffap-file-line-at-point ()
3642 "Get (FILENAME . LINENO) at point."
3643 (anything-aif (let (ffap-alist) (ffap-file-at-point))
3644 (save-excursion
3645 (beginning-of-line)
3646 (when (and (search-forward it nil t)
3647 (looking-at ":\\([0-9]+\\)"))
3648 (cons it (string-to-number (match-string 1)))))))
3650 (defvar anything-c-ffap-line-location nil
3651 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
3652 It is cleared after jumping line.")
3654 (defun anything-c-ffap-line-candidates ()
3655 (with-current-buffer anything-current-buffer
3656 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
3657 (when anything-c-ffap-line-location
3658 (destructuring-bind (file . line) anything-c-ffap-line-location
3659 (list (cons (format "%s (line %d)" file line) file)))))
3661 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
3662 (defun anything-c-ffap-line-goto-line ()
3663 (when (car anything-c-ffap-line-location)
3664 (unwind-protect
3665 (ignore-errors
3666 (with-selected-window
3667 (get-buffer-window
3668 (get-file-buffer (car anything-c-ffap-line-location)))
3669 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
3670 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
3671 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
3673 (defvar anything-c-source-ffap-line
3674 '((name . "File/Lineno at point")
3675 (init . (lambda () (require 'ffap)))
3676 (candidates . anything-c-ffap-line-candidates)
3677 (type . file)))
3678 ;; (anything 'anything-c-source-ffap-line)
3680 ;;; list of files gleaned from every dired buffer
3681 (defun anything-c-files-in-all-dired-candidates ()
3682 (save-excursion
3683 (mapcan
3684 (lambda (dir)
3685 (cond ((listp dir) ;filelist
3686 dir)
3687 ((equal "" (file-name-nondirectory dir)) ;dir
3688 (directory-files dir t))
3689 (t ;wildcard
3690 (file-expand-wildcards dir t))))
3691 (delq nil
3692 (mapcar (lambda (buf)
3693 (set-buffer buf)
3694 (when (eq major-mode 'dired-mode)
3695 (if (consp dired-directory)
3696 (cdr dired-directory) ;filelist
3697 dired-directory))) ;dir or wildcard
3698 (buffer-list))))))
3699 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
3701 (defvar anything-c-source-files-in-all-dired
3702 '((name . "Files in all dired buffer.")
3703 (candidates . anything-c-files-in-all-dired-candidates)
3704 (type . file)))
3705 ;; (anything 'anything-c-source-files-in-all-dired)
3707 (defcustom anything-c-filelist-file-name nil
3708 "*Filename of file list.
3709 Accept a list of string for multiple files.
3711 This file tend to be very large (> 100MB) and recommend to be in ramdisk for speed.
3712 File list is created by make-filelist.rb script.
3714 Usage:
3715 ruby make-filelist.rb > /tmp/all.filelist
3717 Then
3718 ;; Assume that /tmp is ramdisk or tmpfs
3719 (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")
3720 (setq anything-c-filelist-file-name \"/tmp/all.filelist\")
3722 :type 'string
3723 :group 'anything-config)
3724 (defvar anything-c-source-filelist
3725 '((name . "FileList")
3726 (grep-candidates . anything-c-filelist-file-name)
3727 (candidate-number-limit . 200)
3728 (requires-pattern . 4)
3729 (type . file))
3730 "Source to find files instantly.
3731 See `anything-c-filelist-file-name' docstring for usage.")
3733 ;;;###autoload
3734 (defun anything-filelist ()
3735 "Preconfigured `anything' to open files instantly.
3737 See `anything-c-filelist-file-name' docstring for usage."
3738 (interactive)
3739 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
3741 ;;;###autoload
3742 (defun anything-filelist+ ()
3743 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
3745 This is a replacement for `anything-for-files'.
3746 See `anything-c-filelist-file-name' docstring for usage."
3747 (interactive)
3748 (anything-other-buffer
3749 '(anything-c-source-ffap-line
3750 anything-c-source-ffap-guesser
3751 anything-c-source-buffers+
3752 anything-c-source-recentf
3753 anything-c-source-bookmarks
3754 anything-c-source-file-cache
3755 anything-c-source-filelist)
3756 "*anything file list*"))
3759 ;;;; <info>
3760 ;;; Info pages
3761 (defvar anything-c-info-pages nil
3762 "All info pages on system.
3763 Will be calculated the first time you invoke anything with this
3764 source.")
3766 (defvar anything-c-source-info-pages
3767 `((name . "Info Pages")
3768 (candidates
3769 . (lambda ()
3770 (if anything-c-info-pages
3771 anything-c-info-pages
3772 (setq anything-c-info-pages
3773 (save-window-excursion
3774 (save-excursion
3775 (require 'info)
3776 (Info-find-node "dir" "top")
3777 (goto-char (point-min))
3778 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
3779 topics)
3780 (while (re-search-forward info-topic-regexp nil t)
3781 (add-to-list 'topics (match-string-no-properties 1)))
3782 (goto-char (point-min))
3783 (Info-exit)
3784 topics)))))))
3785 (action . (("Show with Info" .(lambda (node-str)
3786 (info (replace-regexp-in-string
3787 "^[^:]+: " "" node-str))))))
3788 (requires-pattern . 2)))
3789 ;; (anything 'anything-c-source-info-pages)
3792 ;; FIXME should be merged in anything.el with `anything-describe-anything-attribute'.
3793 (defun anything-c-describe-attributes (anything-attribute)
3794 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
3795 Same as `anything-describe-anything-attribute' but with anything completion."
3796 (interactive (list (intern
3797 (anything-comp-read
3798 "Describe anything attribute: "
3799 (mapcar 'symbol-name anything-additional-attributes)
3800 :must-match t
3801 :persistent-action
3802 #'(lambda (candidate)
3803 (with-output-to-temp-buffer "*Help*"
3804 (princ (get (intern candidate) 'anything-attrdoc))))))))
3805 (with-output-to-temp-buffer "*Help*"
3806 (princ (get anything-attribute 'anything-attrdoc))))
3808 ;;; Use info-index plug-in. Note that `name' attribute is
3809 ;;; not needed but `anything-c-insert-summary' uses it.
3810 ;; Info Elisp
3811 (defvar anything-c-source-info-elisp
3812 '((name . "Info index: elisp")
3813 (info-index . "elisp")))
3814 ;; (anything 'anything-c-source-info-elisp)
3816 ;; Info-Common-Lisp
3817 (defvar anything-c-source-info-cl
3818 '((name . "Info index: cl")
3819 (info-index . "cl")))
3820 ;; (anything 'anything-c-source-info-cl)
3822 ;; Info Index org
3823 (defvar anything-c-source-info-org
3824 '((name . "Info index: org")
3825 (info-index . "org")))
3826 ;; (anything 'anything-c-source-info-org)
3828 ;; Info Index ratpoison
3829 (defvar anything-c-source-info-ratpoison
3830 '((name . "Info index: ratpoison")
3831 (info-index . "ratpoison")))
3832 ;; (anything 'anything-c-source-info-ratpoison)
3834 ;; Info Index zsh
3835 (defvar anything-c-source-info-zsh
3836 '((name . "Info index: zsh")
3837 (info-index . "zsh")))
3838 ;; (anything 'anything-c-source-info-zsh)
3840 ;; Info Index bash
3841 (defvar anything-c-source-info-bash
3842 '((name . "Info index: bash")
3843 (info-index . "bash")))
3844 ;; (anything 'anything-c-source-info-bash)
3846 ;; Info Index coreutils
3847 (defvar anything-c-source-info-coreutils
3848 '((name . "Info index: coreutils")
3849 (info-index . "coreutils")))
3850 ;; (anything 'anything-c-source-info-coreutils)
3852 ;; Info Index fileutils
3853 (defvar anything-c-source-info-fileutils
3854 '((name . "Info index: fileutils")
3855 (info-index . "fileutils")))
3856 ;; (anything 'anything-c-source-info-fileutils)
3858 ;; Info Index find
3859 (defvar anything-c-source-info-find
3860 '((name . "Info index: find")
3861 (info-index . "find")))
3862 ;; (anything 'anything-c-source-info-find)
3864 ;; Info Index sh-utils
3865 (defvar anything-c-source-info-sh-utils
3866 '((name . "Info index: sh-utils")
3867 (info-index . "sh-utils")))
3868 ;; (anything 'anything-c-source-info-sh-utils)
3870 ;; Info Index textutils
3871 (defvar anything-c-source-info-textutils
3872 '((name . "Info index: textutils")
3873 (info-index . "textutils")))
3874 ;; (anything 'anything-c-source-info-textutils)
3876 ;; Info Index libc
3877 (defvar anything-c-source-info-libc
3878 '((name . "Info index: libc")
3879 (info-index . "libc")))
3880 ;; (anything 'anything-c-source-info-libc)
3882 ;; Info Index make
3883 (defvar anything-c-source-info-make
3884 '((name . "Info index: make")
3885 (info-index . "make")))
3886 ;; (anything 'anything-c-source-info-make)
3888 ;; Info Index automake
3889 (defvar anything-c-source-info-automake
3890 '((name . "Info index: automake")
3891 (info-index . "automake")))
3892 ;; (anything 'anything-c-source-info-automake)
3894 ;; Info Index autoconf
3895 (defvar anything-c-source-info-autoconf
3896 '((name . "Info index: autoconf")
3897 (info-index . "autoconf")))
3898 ;; (anything 'anything-c-source-info-autoconf)
3900 ;; Info Index emacs-lisp-intro
3901 (defvar anything-c-source-info-emacs-lisp-intro
3902 '((name . "Info index: emacs-lisp-intro")
3903 (info-index . "emacs-lisp-intro")))
3904 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
3906 ;; Info Index emacs
3907 (defvar anything-c-source-info-emacs
3908 '((name . "Info index: emacs")
3909 (info-index . "emacs")))
3910 ;; (anything 'anything-c-source-info-emacs)
3912 ;; Info Index elib
3913 (defvar anything-c-source-info-elib
3914 '((name . "Info index: elib")
3915 (info-index . "elib")))
3916 ;; (anything 'anything-c-source-info-elib)
3918 ;; Info Index eieio
3919 (defvar anything-c-source-info-eieio
3920 '((name . "Info index: eieio")
3921 (info-index . "eieio")))
3922 ;; (anything 'anything-c-source-info-eieio)
3924 ;; Info Index gauche-refe
3925 (defvar anything-c-source-info-gauche-refe
3926 '((name . "Info index: gauche")
3927 (info-index . "gauche-refe")))
3928 ;; (anything 'anything-c-source-info-gauche-refe)
3930 ;; Info Index guile
3931 (defvar anything-c-source-info-guile
3932 '((name . "Info index: guile")
3933 (info-index . "guile")))
3934 ;; (anything 'anything-c-source-info-guile)
3936 ;; Info Index guile-tut
3937 (defvar anything-c-source-info-guile-tut
3938 '((name . "Info index: guile-tut")
3939 (info-index . "guile-tut")))
3940 ;; (anything 'anything-c-source-info-guile-tut)
3942 ;; Info Index goops
3943 (defvar anything-c-source-info-goops
3944 '((name . "Info index: goops")
3945 (info-index . "goops")))
3946 ;; (anything 'anything-c-source-info-goops)
3948 ;; Info Index screen
3949 (defvar anything-c-source-info-screen
3950 '((name . "Info index: screen")
3951 (info-index . "screen")
3952 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
3953 ;; (anything 'anything-c-source-info-screen)
3955 ;; Info Index latex
3956 (defvar anything-c-source-info-latex
3957 '((name . "Info index: latex")
3958 (info-index . "latex")))
3959 ;; (anything 'anything-c-source-info-latex)
3961 ;; Info Index gawk
3962 (defvar anything-c-source-info-gawk
3963 '((name . "Info index: gawk")
3964 (info-index . "gawk")))
3965 ;; (anything 'anything-c-source-info-gawk)
3967 ;; Info Index sed
3968 (defvar anything-c-source-info-sed
3969 '((name . "Info index: sed")
3970 (info-index . "sed")))
3971 ;; (anything 'anything-c-source-info-sed)
3973 ;; Info Index m4
3974 (defvar anything-c-source-info-m4
3975 '((name . "Info index: m4")
3976 (info-index . "m4")))
3977 ;; (anything 'anything-c-source-info-m4)
3979 ;; Info Index wget
3980 (defvar anything-c-source-info-wget
3981 '((name . "Info index: wget")
3982 (info-index . "wget")))
3983 ;; (anything 'anything-c-source-info-wget)
3985 ;; Info Index binutils
3986 (defvar anything-c-source-info-binutils
3987 '((name . "Info index: binutils")
3988 (info-index . "binutils")))
3989 ;; (anything 'anything-c-source-info-binutils)
3991 ;; Info Index as
3992 (defvar anything-c-source-info-as
3993 '((name . "Info index: as")
3994 (info-index . "as")))
3995 ;; (anything 'anything-c-source-info-as)
3997 ;; Info Index bfd
3998 (defvar anything-c-source-info-bfd
3999 '((name . "Info index: bfd")
4000 (info-index . "bfd")))
4001 ;; (anything 'anything-c-source-info-bfd)
4003 ;; Info Index gprof
4004 (defvar anything-c-source-info-gprof
4005 '((name . "Info index: gprof")
4006 (info-index . "gprof")))
4007 ;; (anything 'anything-c-source-info-gprof)
4009 ;; Info Index ld
4010 (defvar anything-c-source-info-ld
4011 '((name . "Info index: ld")
4012 (info-index . "ld")))
4013 ;; (anything 'anything-c-source-info-ld)
4015 ;; Info Index diff
4016 (defvar anything-c-source-info-diff
4017 '((name . "Info index: diff")
4018 (info-index . "diff")))
4019 ;; (anything 'anything-c-source-info-diff)
4021 ;; Info Index flex
4022 (defvar anything-c-source-info-flex
4023 '((name . "Info index: flex")
4024 (info-index . "flex")))
4025 ;; (anything 'anything-c-source-info-flex)
4027 ;; Info Index grep
4028 (defvar anything-c-source-info-grep
4029 '((name . "Info index: grep")
4030 (info-index . "grep")))
4031 ;; (anything 'anything-c-source-info-grep)
4033 ;; Info Index gzip
4034 (defvar anything-c-source-info-gzip
4035 '((name . "Info index: gzip")
4036 (info-index . "gzip")))
4037 ;; (anything 'anything-c-source-info-gzip)
4039 ;; Info Index libtool
4040 (defvar anything-c-source-info-libtool
4041 '((name . "Info index: libtool")
4042 (info-index . "libtool")))
4043 ;; (anything 'anything-c-source-info-libtool)
4045 ;; Info Index texinfo
4046 (defvar anything-c-source-info-texinfo
4047 '((name . "Info index: texinfo")
4048 (info-index . "texinfo")))
4049 ;; (anything 'anything-c-source-info-texinfo)
4051 ;; Info Index info
4052 (defvar anything-c-source-info-info
4053 '((name . "Info index: info")
4054 (info-index . "info")))
4055 ;; (anything 'anything-c-source-info-info)
4057 ;; Info Index gdb
4058 (defvar anything-c-source-info-gdb
4059 '((name . "Info index: gdb")
4060 (info-index . "gdb")))
4061 ;; (anything 'anything-c-source-info-gdb)
4063 ;; Info Index stabs
4064 (defvar anything-c-source-info-stabs
4065 '((name . "Info index: stabs")
4066 (info-index . "stabs")))
4067 ;; (anything 'anything-c-source-info-stabs)
4069 ;; Info Index cvsbook
4070 (defvar anything-c-source-info-cvsbook
4071 '((name . "Info index: cvsbook")
4072 (info-index . "cvsbook")))
4073 ;; (anything 'anything-c-source-info-cvsbook)
4075 ;; Info Index cvs
4076 (defvar anything-c-source-info-cvs
4077 '((name . "Info index: cvs")
4078 (info-index . "cvs")))
4079 ;; (anything 'anything-c-source-info-cvs)
4081 ;; Info Index bison
4082 (defvar anything-c-source-info-bison
4083 '((name . "Info index: bison")
4084 (info-index . "bison")))
4085 ;; (anything 'anything-c-source-info-bison)
4087 ;; Info Index id-utils
4088 (defvar anything-c-source-info-id-utils
4089 '((name . "Info index: id-utils")
4090 (info-index . "id-utils")))
4091 ;; (anything 'anything-c-source-info-id-utils)
4093 ;; Info Index global
4094 (defvar anything-c-source-info-global
4095 '((name . "Info index: global")
4096 (info-index . "global")))
4097 ;; (anything 'anything-c-source-info-global)
4099 ;;;; <Help>
4100 ;;; Man Pages
4101 (defvar anything-c-man-pages nil
4102 "All man pages on system.
4103 Will be calculated the first time you invoke anything with this
4104 source.")
4106 (defun anything-c-man-default-action (candidate)
4107 "Default action for jumping to a woman or man page from anything."
4108 (let ((wfiles (woman-file-name-all-completions candidate)))
4109 (condition-case err
4110 (if (> (length wfiles) 1)
4111 (woman-find-file (anything-comp-read "ManFile: " wfiles
4112 :must-match t))
4113 ;; If woman is unable to format correctly
4114 ;; use man instead.
4115 (woman candidate))
4116 (error (kill-buffer) ; Kill woman buffer.
4117 (man candidate)))))
4119 (defvar anything-c-source-man-pages
4120 `((name . "Manual Pages")
4121 (candidates . (lambda ()
4122 (if anything-c-man-pages
4123 anything-c-man-pages
4124 ;; XEmacs doesn't have a woman :)
4125 (setq anything-c-man-pages
4126 (ignore-errors
4127 (require 'woman)
4128 (woman-file-name "")
4129 (sort (mapcar 'car woman-topic-all-completions)
4130 'string-lessp))))))
4131 (action ("Show with Woman" . anything-c-man-default-action))
4132 ;; Woman does not work OS X
4133 ;; http://xahlee.org/emacs/modernization_man_page.html
4134 (action-transformer . (lambda (actions candidate)
4135 (if (eq system-type 'darwin)
4136 '(("Show with Man" . man))
4137 actions)))
4138 (requires-pattern . 2)))
4139 ;; (anything 'anything-c-source-man-pages)
4141 ;;;; <Command>
4142 ;;; Complex command history
4143 (defvar anything-c-source-complex-command-history
4144 '((name . "Complex Command History")
4145 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
4146 (type . sexp)))
4147 ;; (anything 'anything-c-source-complex-command-history)
4149 ;;; M-x history
4150 (defvar anything-c-source-extended-command-history
4151 '((name . "Emacs Commands History")
4152 (candidates . extended-command-history)
4153 (type . command)))
4154 ;; (anything 'anything-c-source-extended-command-history)
4156 ;;; Emacs commands
4157 (defvar anything-c-source-emacs-commands
4158 '((name . "Emacs Commands")
4159 (candidates . (lambda ()
4160 (let (commands)
4161 (mapatoms (lambda (a)
4162 (if (commandp a)
4163 (push (symbol-name a)
4164 commands))))
4165 (sort commands 'string-lessp))))
4166 (type . command)
4167 (requires-pattern . 2))
4168 "Source for completing and invoking Emacs commands.
4169 A command is a function with interactive spec that can
4170 be invoked with `M-x'.
4172 To get non-interactive functions listed, use
4173 `anything-c-source-emacs-functions'.")
4174 ;; (anything 'anything-c-source-emacs-commands)
4176 ;;; Anything M-x
4178 ;; Another replacement of `M-x' that act exactly like the
4179 ;; vanilla Emacs one, no problem of windows configuration, prefix args
4180 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
4181 ;; anything invocation.
4182 ;;;###autoload
4183 (defun anything-M-x ()
4184 "Preconfigured `anything' for Emacs commands.
4185 It is `anything' replacement of regular `M-x' `execute-extended-command'."
4186 (interactive)
4187 (let* (in-help help-cand
4188 (command (anything-comp-read
4189 "M-x " obarray
4190 :test 'commandp
4191 :must-match t
4192 :requires-pattern 2
4193 :name "Emacs Commands"
4194 :persistent-action
4195 #'(lambda (candidate)
4196 (if (and in-help (string= candidate help-cand))
4197 (progn (kill-buffer "*Help*") (setq in-help nil))
4198 (describe-function (intern candidate))
4199 (setq in-help t))
4200 (setq help-cand candidate))
4201 :persistent-help "Describe this command"
4202 :history extended-command-history
4203 :sort 'string-lessp
4204 :fc-transformer 'anything-M-x-transformer))
4205 (history (loop with hist
4206 for i in extended-command-history
4207 for com = (intern i)
4208 when (and (fboundp com) (not (member i hist)))
4209 collect i into hist finally return hist)))
4210 (unless current-prefix-arg (setq current-prefix-arg anything-current-prefix-arg))
4211 (call-interactively (intern command))
4212 (setq extended-command-history (cons command (delete command history)))))
4214 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
4215 "Return alist of MODE-MAP."
4216 (loop for key being the key-seqs of mode-map using (key-bindings com)
4217 for str-key = (key-description key)
4218 for ismenu = (string-match "<menu-bar>" str-key)
4219 unless ismenu collect (cons str-key com)))
4221 (defun anything-get-mode-map-from-mode (mode)
4222 "Guess the mode-map name according to MODE.
4223 Some modes don't use conventional mode-map name
4224 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
4225 Return nil if no mode-map found."
4226 (loop
4227 ;; Start with a conventional mode-map name.
4228 with mode-map = (intern-soft (format "%s-map" mode))
4229 with mode-string = (symbol-name mode)
4230 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
4231 while (not mode-map)
4232 for count downfrom (length mode-name)
4233 ;; Return when no result after parsing entire string.
4234 when (eq count 0) return nil
4235 for sub-name = (substring mode-name 0 count)
4236 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
4237 finally return mode-map))
4239 (defun anything-M-x-current-mode-map-alist ()
4240 "Return mode-map alist of current `major-mode'."
4241 (let ((map (anything-get-mode-map-from-mode major-mode)))
4242 (when (and map (boundp map))
4243 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
4245 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
4246 "*Face used in anything-M-x to show keybinding."
4247 :group 'anything)
4249 (defun anything-M-x-transformer (candidates sources)
4250 "filtered-candidate-transformer to show bindings in emacs commands.
4251 Show global bindings and local bindings according to current `major-mode'."
4252 (loop
4253 with local-map = (with-current-buffer anything-current-buffer
4254 (anything-M-x-current-mode-map-alist))
4255 for i in candidates
4256 for cand = (symbol-name i)
4257 for local-key = (car (rassq i local-map))
4258 for key = (substitute-command-keys (format "\\[%s]" cand))
4259 collect
4260 (cons (if (string-match "^M-x" key)
4261 (if local-key
4262 (concat
4263 cand " (" (propertize local-key 'face 'anything-M-x-key-face)
4264 ")")
4265 cand)
4266 (concat
4267 cand " (" (propertize key 'face 'anything-M-x-key-face) ")"))
4268 cand)))
4270 ;;; LaCarte
4271 (defvar anything-c-source-lacarte
4272 '((name . "Lacarte")
4273 (init . (lambda () (require 'lacarte )))
4274 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
4275 (candidate-number-limit . 9999)
4276 (action . anything-c-call-interactively))
4277 "Needs lacarte.el.
4279 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
4280 ;; (anything 'anything-c-source-lacarte)
4282 ;;;; <Function>
4283 ;;; Emacs functions
4284 (defvar anything-c-source-emacs-functions
4285 '((name . "Emacs Functions")
4286 (candidates . (lambda ()
4287 (let (commands)
4288 (mapatoms (lambda (a)
4289 (if (functionp a)
4290 (push (symbol-name a) commands))))
4291 (sort commands 'string-lessp))))
4292 (type . function)
4293 (requires-pattern . 2))
4294 "Source for completing Emacs functions.")
4295 ;; (anything 'anything-c-source-emacs-functions)
4297 ;;; With abbrev expansion
4298 ;;; Similar to my exec-abbrev-cmd.el
4299 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
4300 (defvar anything-c-function-abbrev-regexp nil
4301 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
4302 Regexp built from the current `anything-pattern' interpreting it
4303 as abbreviation.
4304 Only for internal use.")
4306 (defun anything-c-match-function-by-abbrev (candidate)
4307 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
4309 Abbreviations are made by taking the first character from each
4310 word in the function's name, e.g. \"bb\" is an abbrev for
4311 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
4312 (string-match anything-c-function-abbrev-regexp candidate))
4314 (defvar anything-c-source-emacs-functions-with-abbrevs
4315 (append anything-c-source-emacs-functions
4316 '((match anything-c-match-function-by-abbrev
4317 anything-c-string-match))
4318 '((init
4319 . (lambda ()
4320 (defadvice anything-update
4321 (before anything-c-update-function-abbrev-regexp activate)
4322 (let ((char-list (append anything-pattern nil))
4323 (str "^"))
4324 (dolist (c char-list)
4325 (setq str (concat str (list c) "[^-]*-")))
4326 (setq str (concat (substring str 0 (1- (length str))) "$"))
4327 (setq anything-c-function-abbrev-regexp str))))))))
4328 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
4330 (defvar anything-c-source-advice
4331 '((name . "Function Advice")
4332 (candidates . anything-c-advice-candidates)
4333 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
4334 ;; (real-to-display . anything-c-advice-real-to-display)
4337 (persistent-action . anything-c-advice-persistent-action)
4338 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
4339 ;; (anything 'anything-c-source-advice)
4340 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
4341 ;; (testadvice)
4343 (defun anything-c-advice-candidates ()
4344 (require 'advice)
4345 (loop for (fname) in ad-advised-functions
4346 for function = (intern fname)
4347 append
4348 (loop for class in ad-advice-classes append
4349 (loop for advice in (ad-get-advice-info-field function class)
4350 for enabled = (ad-advice-enabled advice)
4351 collect
4352 (cons (format
4353 "%s %s %s"
4354 (if enabled "Enabled " "Disabled")
4355 (propertize fname 'face 'font-lock-function-name-face)
4356 (ad-make-single-advice-docstring advice class nil))
4357 (list function class advice))))))
4359 (defun anything-c-advice-persistent-action (func-class-advice)
4360 (if current-prefix-arg
4361 (anything-c-advice-toggle func-class-advice)
4362 (describe-function (car func-class-advice))))
4364 (defun anything-c-advice-toggle (func-class-advice)
4365 (destructuring-bind (function class advice) func-class-advice
4366 (cond ((ad-advice-enabled advice)
4367 (ad-advice-set-enabled advice nil)
4368 (message "Disabled"))
4369 (t ;disabled
4370 (ad-advice-set-enabled advice t)
4371 (message "Enabled")))
4372 (ad-activate function)
4373 (and anything-in-persistent-action
4374 (anything-c-advice-update-current-display-string))))
4376 (defun anything-c-advice-update-current-display-string ()
4377 (anything-edit-current-selection
4378 (let ((newword (cond ((looking-at "Disabled") "Enabled")
4379 ((looking-at "Enabled") "Disabled")))
4380 realvalue)
4381 (when newword
4382 (delete-region (point) (progn (forward-word 1) (point)))
4383 (insert newword)))))
4385 ;;;###autoload
4386 (defun anything-manage-advice ()
4387 "Preconfigured `anything' to disable/enable function advices."
4388 (interactive)
4389 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
4391 ;;;; <Variable>
4392 ;;; Emacs variables
4393 (defvar anything-c-source-emacs-variables
4394 '((name . "Emacs Variables")
4395 (candidates . (lambda ()
4396 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
4397 (type . variable)
4398 (requires-pattern . 2))
4399 "Source for completing Emacs variables.")
4400 ;; (anything 'anything-c-source-emacs-variables)
4402 ;;;; <Bookmark>
4403 ;;; Bookmarks
4404 (eval-when-compile (require 'bookmark))
4405 (defvar anything-c-source-bookmarks
4406 '((name . "Bookmarks")
4407 (init . (lambda ()
4408 (require 'bookmark)))
4409 (candidates . bookmark-all-names)
4410 (type . bookmark))
4411 "See (info \"(emacs)Bookmarks\").")
4412 ;; (anything 'anything-c-source-bookmarks)
4414 ;;; bookmark-set
4415 (defvar anything-c-source-bookmark-set
4416 '((name . "Set Bookmark")
4417 (dummy)
4418 (action . bookmark-set))
4419 "See (info \"(emacs)Bookmarks\").")
4420 ;; (anything 'anything-c-source-bookmark-set)
4422 ;;; Visible Bookmarks
4423 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
4426 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
4427 (defvar anything-c-source-bm
4428 '((name . "Visible Bookmarks")
4429 (init . anything-c-bm-init)
4430 (candidates-in-buffer)
4431 (type . line))
4432 "Needs bm.el.
4434 http://www.nongnu.org/bm/")
4436 (defun anything-c-bm-init ()
4437 "Init function for `anything-c-source-bm'."
4438 (when (require 'bm nil t)
4439 (with-no-warnings
4440 (let ((bookmarks (bm-lists))
4441 (buf (anything-candidate-buffer 'global)))
4442 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
4443 '< :key 'overlay-start))
4444 (let ((start (overlay-start bm))
4445 (end (overlay-end bm))
4446 (annotation (or (overlay-get bm 'annotation) "")))
4447 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
4448 (let ((str (format "%5d: [%s]: %s\n"
4449 (line-number-at-pos start)
4450 annotation
4451 (buffer-substring start (1- end)))))
4452 (with-current-buffer buf (insert str))))))))))
4454 ;;; Special bookmarks
4455 (defvar anything-c-source-bookmarks-ssh
4456 '((name . "Bookmarks-ssh")
4457 (init . (lambda ()
4458 (require 'bookmark)))
4459 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
4460 (type . bookmark))
4461 "See (info \"(emacs)Bookmarks\").")
4462 ;; (anything 'anything-c-source-bookmarks-ssh)
4464 (defvar anything-c-source-bookmarks-su
4465 '((name . "Bookmarks-root")
4466 (init . (lambda ()
4467 (require 'bookmark)))
4468 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
4469 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
4471 (type . bookmark))
4472 "See (info \"(emacs)Bookmarks\").")
4473 ;; (anything 'anything-c-source-bookmarks-su)
4475 (defvar anything-c-source-bookmarks-local
4476 '((name . "Bookmarks-Local")
4477 (init . (lambda ()
4478 (require 'bookmark)))
4479 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
4480 (filtered-candidate-transformer
4481 ;;anything-c-adaptive-sort
4482 anything-c-highlight-bookmark)
4483 (type . bookmark))
4484 "See (info \"(emacs)Bookmarks\").")
4485 ;; (anything 'anything-c-source-bookmarks-local)
4487 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
4488 (let* ((lis-all (bookmark-all-names))
4489 (lis-loc (cond (local (loop for i in lis-all
4490 unless (string-match "^(ssh)\\|^(su)" i)
4491 collect i))
4492 (su (loop for i in lis-all
4493 when (string-match "^(su)" i)
4494 collect i))
4495 (sudo (loop for i in lis-all
4496 when (string-match "^(sudo)" i)
4497 collect i))
4498 (ssh (loop for i in lis-all
4499 when (string-match "^(ssh)" i)
4500 collect i)))))
4501 (sort lis-loc 'string-lessp)))
4503 (defun anything-c-bookmark-root-logged-p ()
4504 (catch 'break
4505 (dolist (i (mapcar #'buffer-name (buffer-list)))
4506 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
4507 (throw 'break t)))))
4509 (defun anything-c-highlight-bookmark-su (files source)
4510 (if (anything-c-bookmark-root-logged-p)
4511 (anything-c-highlight-bookmark files source)
4512 (anything-c-highlight-not-logged files source)))
4514 (defun anything-c-highlight-not-logged (files source)
4515 (loop for i in files
4516 collect (propertize i 'face anything-c-bookmarks-face3)))
4518 (defun anything-c-highlight-bookmark (bookmarks source)
4519 "Used as `candidate-transformer' to colorize bookmarks.
4520 Work both with standard Emacs bookmarks and bookmark-extensions.el."
4521 (loop for i in bookmarks
4522 for isfile = (bookmark-get-filename i)
4523 for bufp = (and (fboundp 'bmkext-get-buffer-name)
4524 (bmkext-get-buffer-name i))
4525 for handlerp = (and (fboundp 'bookmark-get-handler)
4526 (bookmark-get-handler i))
4527 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
4528 (bmkext-w3m-bookmark-p i))
4529 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
4530 (bmkext-gnus-bookmark-p i))
4531 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
4532 (bmkext-man-bookmark-p i))
4533 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
4534 (bmkext-woman-bookmark-p i))
4535 for handlerp = (bookmark-get-handler i)
4536 for isannotation = (bookmark-get-annotation i)
4537 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
4538 for isinfo = (eq handlerp 'Info-bookmark-jump)
4539 ;; Add a * if bookmark have annotation
4540 if (and isannotation (not (string-equal isannotation "")))
4541 do (setq i (concat "*" i))
4542 collect (cond (;; info buffers
4543 isinfo
4544 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
4545 (;; w3m buffers
4546 isw3m
4547 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
4548 (;; gnus buffers
4549 isgnus
4550 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
4551 (;; Man Woman
4552 (or iswoman isman)
4553 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
4554 (;; Addressbook
4555 isabook
4556 (propertize i 'face '((:foreground "Tomato"))))
4557 (;; directories
4558 (and isfile (file-directory-p isfile))
4559 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
4560 (;; regular files
4562 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
4565 ;;; Faces for bookmarks
4566 (defface anything-bmkext-info
4567 '((t (:foreground "green")))
4568 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
4569 :group 'anything)
4571 (defface anything-bmkext-w3m
4572 '((t (:foreground "yellow")))
4573 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
4574 :group 'anything)
4576 (defface anything-bmkext-gnus
4577 '((t (:foreground "magenta")))
4578 "*Face used for Gnus bookmarks."
4579 :group 'anything)
4581 (defface anything-bmkext-man
4582 '((t (:foreground "Orange4")))
4583 "*Face used for Woman/man bookmarks."
4584 :group 'anything)
4586 (defface anything-bmkext-no--file
4587 '((t (:foreground "grey")))
4588 "*Face used for non--file bookmarks."
4589 :group 'anything)
4591 (defface anything-bmkext-file
4592 '((t (:foreground "Deepskyblue2")))
4593 "*Face used for non--file bookmarks."
4594 :group 'anything)
4596 (defface anything-bookmarks-su-face '((t (:foreground "red")))
4597 "Face for su/sudo bookmarks."
4598 :group 'anything)
4600 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
4601 (defvar anything-c-bookmarks-face2 'anything-file-name)
4602 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
4605 ;;; Sources to filter bookmark-extensions bookmarks.
4606 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
4607 ;; If you want to enable google-maps in addressbook you will need
4608 ;; Julien Danjou google-maps-el package available here:
4609 ;; http://julien.danjou.info/google-maps-el.html
4611 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
4612 "Return a filtered `bookmark-alist' sorted alphabetically."
4613 (loop
4614 with alist = (if args
4615 (apply #'(lambda (x) (funcall fn x)) args)
4616 (funcall fn))
4617 for i in alist
4618 for b = (car i)
4619 collect b into sa
4620 finally return (sort sa 'string-lessp)))
4622 ;; Addressbook
4623 (defvar anything-c-source-bmkext-addressbook
4624 '((name . "Bookmark Addressbook")
4625 (init . (lambda ()
4626 (require 'bookmark-extensions)
4627 (bookmark-maybe-load-default-file)))
4628 (candidates . anything-c-bmkext-addressbook-setup-alist)
4629 (persistent-action
4630 . (lambda (candidate)
4631 (let ((bmk (anything-bookmark-get-bookmark-from-name
4632 candidate)))
4633 (bookmark--jump-via bmk 'pop-to-buffer))))
4634 (persistent-help . "Show contact - Prefix with C-u to append")
4635 (filtered-candidate-transformer
4636 ;;anything-c-adaptive-sort
4637 anything-c-highlight-bookmark)
4638 (action . (("Show person's data"
4639 . (lambda (candidate)
4640 (let ((bmk (anything-bookmark-get-bookmark-from-name
4641 candidate))
4642 (current-prefix-arg anything-current-prefix-arg))
4643 (bookmark-jump bmk))))
4644 ("Send Mail"
4645 . (lambda (candidate)
4646 (let ((bmk (anything-bookmark-get-bookmark-from-name
4647 candidate)))
4648 (if anything-current-prefix-arg
4649 (addressbook-set-mail-buffer1 bmk 'append)
4650 (addressbook-set-mail-buffer1 bmk)))))
4651 ("Edit Bookmark"
4652 . (lambda (candidate)
4653 (let ((bmk (anything-bookmark-get-bookmark-from-name
4654 candidate)))
4655 (addressbook-bookmark-edit
4656 (assoc bmk bookmark-alist)))))
4657 ("Insert Email at point"
4658 . (lambda (candidate)
4659 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4660 candidate))
4661 (mlist (split-string
4662 (assoc-default
4663 'email (assoc bmk bookmark-alist))
4664 ", ")))
4665 (insert
4666 (if (> (length mlist) 1)
4667 (anything-comp-read
4668 "Insert Mail Address: " mlist :must-match t)
4669 (car mlist))))))
4670 ("Show annotation"
4671 . (lambda (candidate)
4672 (let ((bmk (anything-bookmark-get-bookmark-from-name
4673 candidate)))
4674 (bookmark-show-annotation bmk))))
4675 ("Edit annotation"
4676 . (lambda (candidate)
4677 (let ((bmk (anything-bookmark-get-bookmark-from-name
4678 candidate)))
4679 (bookmark-edit-annotation bmk))))
4680 ("Show Google map"
4681 . (lambda (candidate)
4682 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4683 candidate))
4684 (full-bmk (assoc bmk bookmark-alist)))
4685 (addressbook-google-map full-bmk))))))))
4688 (defun anything-c-bmkext-addressbook-setup-alist ()
4689 "Specialized filter function for bookmarks w3m."
4690 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
4692 ;; W3m
4693 (defvar anything-c-source-bookmark-w3m
4694 '((name . "Bookmark W3m")
4695 (init . (lambda ()
4696 (require 'bookmark-extensions)
4697 (bookmark-maybe-load-default-file)))
4698 (candidates . anything-c-bookmark-w3m-setup-alist)
4699 (filtered-candidate-transformer
4700 ;;anything-c-adaptive-sort
4701 anything-c-highlight-bookmark)
4702 (type . bookmark)))
4703 ;; (anything 'anything-c-source-bookmark-w3m)
4705 (defun anything-c-bookmark-w3m-setup-alist ()
4706 "Specialized filter function for bookmarks w3m."
4707 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
4709 ;; Images
4710 (defvar anything-c-source-bookmark-images
4711 '((name . "Bookmark Images")
4712 (init . (lambda ()
4713 (require 'bookmark-extensions)
4714 (bookmark-maybe-load-default-file)))
4715 (candidates . anything-c-bookmark-images-setup-alist)
4716 (filtered-candidate-transformer
4717 ;;anything-c-adaptive-sort
4718 anything-c-highlight-bookmark)
4719 (type . bookmark)))
4720 ;; (anything 'anything-c-source-bookmark-images)
4722 (defun anything-c-bookmark-images-setup-alist ()
4723 "Specialized filter function for images bookmarks."
4724 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
4726 ;; Woman Man
4727 (defvar anything-c-source-bookmark-man
4728 '((name . "Bookmark Woman&Man")
4729 (init . (lambda ()
4730 (require 'bookmark-extensions)
4731 (bookmark-maybe-load-default-file)))
4732 (candidates . anything-c-bookmark-man-setup-alist)
4733 (filtered-candidate-transformer
4734 ;;anything-c-adaptive-sort
4735 anything-c-highlight-bookmark)
4736 (type . bookmark)))
4737 ;; (anything 'anything-c-source-bookmark-man)
4739 (defun anything-c-bookmark-man-setup-alist ()
4740 "Specialized filter function for bookmarks w3m."
4741 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
4742 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
4744 ;; Gnus
4745 (defvar anything-c-source-bookmark-gnus
4746 '((name . "Bookmark Gnus")
4747 (init . (lambda ()
4748 (require 'bookmark-extensions)
4749 (bookmark-maybe-load-default-file)))
4750 (candidates . anything-c-bookmark-gnus-setup-alist)
4751 (filtered-candidate-transformer
4752 ;;anything-c-adaptive-sort
4753 anything-c-highlight-bookmark)
4754 (type . bookmark)))
4755 ;; (anything 'anything-c-source-bookmark-gnus)
4757 (defun anything-c-bookmark-gnus-setup-alist ()
4758 "Specialized filter function for bookmarks gnus."
4759 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
4761 ;; Info
4762 (defvar anything-c-source-bookmark-info
4763 '((name . "Bookmark Info")
4764 (init . (lambda ()
4765 (require 'bookmark-extensions)
4766 (bookmark-maybe-load-default-file)))
4767 (candidates . anything-c-bookmark-info-setup-alist)
4768 (filtered-candidate-transformer
4769 ;;anything-c-adaptive-sort
4770 anything-c-highlight-bookmark)
4771 (type . bookmark)))
4772 ;; (anything 'anything-c-source-bookmark-info)
4774 (defun anything-c-bookmark-info-setup-alist ()
4775 "Specialized filter function for bookmarks info."
4776 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
4778 ;; Local Files&directories
4779 (defvar anything-c-source-bookmark-files&dirs
4780 '((name . "Bookmark Files&Directories")
4781 (init . (lambda ()
4782 (require 'bookmark-extensions)
4783 (bookmark-maybe-load-default-file)))
4784 (candidates . anything-c-bookmark-local-files-setup-alist)
4785 (filtered-candidate-transformer
4786 ;;anything-c-adaptive-sort
4787 anything-c-highlight-bookmark)
4788 (type . bookmark)))
4789 ;; (anything 'anything-c-source-bookmark-files&dirs)
4791 (defun anything-c-bookmark-local-files-setup-alist ()
4792 "Specialized filter function for bookmarks locals files."
4793 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
4795 ;; Su Files&directories
4796 (defvar anything-c-source-bookmark-su-files&dirs
4797 '((name . "Bookmark Root-Files&Directories")
4798 (init . (lambda ()
4799 (require 'bookmark-extensions)
4800 (bookmark-maybe-load-default-file)))
4801 (candidates . anything-c-bookmark-su-files-setup-alist)
4802 (filtered-candidate-transformer
4803 ;;anything-c-adaptive-sort
4804 anything-c-highlight-bookmark-su)
4805 (type . bookmark)))
4806 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
4808 (defun anything-c-bookmark-su-files-setup-alist ()
4809 "Specialized filter function for bookmarks su/sudo files."
4810 (loop
4811 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
4812 for i in l
4813 for isfile = (bookmark-get-filename i)
4814 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
4815 (save-match-data
4816 (string-match tramp-file-name-regexp isfile)))
4817 for issu = (and istramp
4818 (string-match bmkext-su-or-sudo-regexp isfile))
4819 if issu
4820 collect i))
4822 ;; Ssh Files&directories
4823 (defvar anything-c-source-bookmark-ssh-files&dirs
4824 '((name . "Bookmark Ssh-Files&Directories")
4825 (init . (lambda ()
4826 (require 'bookmark-extensions)
4827 (bookmark-maybe-load-default-file)))
4828 (candidates . anything-c-bookmark-ssh-files-setup-alist)
4829 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
4830 (type . bookmark)))
4831 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
4833 (defun anything-c-bookmark-ssh-files-setup-alist ()
4834 "Specialized filter function for bookmarks ssh files."
4835 (loop
4836 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
4837 for i in l
4838 for isfile = (bookmark-get-filename i)
4839 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
4840 (save-match-data
4841 (string-match tramp-file-name-regexp isfile)))
4842 for isssh = (and istramp
4843 (string-match "/ssh:" isfile))
4844 if isssh
4845 collect i))
4848 ;; All bookmark-extensions sources.
4849 ;;;###autoload
4850 (defun anything-bookmark-ext ()
4851 "Preconfigured `anything' for bookmark-extensions sources.
4852 Needs bookmark-ext.el
4854 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
4855 (interactive)
4856 (anything
4857 :sources
4858 '(anything-c-source-bookmark-files&dirs
4859 anything-c-source-bookmark-w3m
4860 anything-c-source-bmkext-addressbook
4861 anything-c-source-bookmark-gnus
4862 anything-c-source-bookmark-info
4863 anything-c-source-bookmark-man
4864 anything-c-source-bookmark-images
4865 anything-c-source-bookmark-su-files&dirs
4866 anything-c-source-bookmark-ssh-files&dirs)
4867 :prompt "SearchBookmark: "
4868 :buffer "*anything bmkext*"))
4871 ;; Firefox bookmarks
4872 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
4873 ;; (only for firefox versions >=3)
4874 ;; To achieve that, open about:config in firefox and double click on this line to enable value
4875 ;; to true:
4876 ;; user_pref("browser.bookmarks.autoExportHTML", false);
4877 ;; You should have now:
4878 ;; user_pref("browser.bookmarks.autoExportHTML", true);
4880 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
4881 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
4883 (defun anything-get-firefox-user-init-dir ()
4884 "Guess the default Firefox user directory name."
4885 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
4886 (moz-user-dir
4887 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
4888 (goto-char (point-min))
4889 (prog1
4890 (when (search-forward "Path=" nil t)
4891 (buffer-substring-no-properties (point) (point-at-eol)))
4892 (kill-buffer)))))
4893 (file-name-as-directory (concat moz-dir moz-user-dir))))
4895 (defun anything-guess-firefox-bookmark-file ()
4896 "Return the path of the Firefox bookmarks file."
4897 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
4899 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
4900 "Parse html bookmark FILE and return an alist with (title . url) as elements."
4901 (let (bookmarks-alist url title)
4902 (with-temp-buffer
4903 (insert-file-contents file)
4904 (goto-char (point-min))
4905 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
4906 (forward-line 0)
4907 (when (re-search-forward url-regexp nil t)
4908 (setq url (match-string 0)))
4909 (when (re-search-forward bmk-regexp nil t)
4910 (setq title (match-string 1)))
4911 (push (cons title url) bookmarks-alist)
4912 (forward-line)))
4913 (nreverse bookmarks-alist)))
4915 (defvar anything-c-firefox-bookmarks-alist nil)
4916 (defvar anything-c-source-firefox-bookmarks
4917 '((name . "Firefox Bookmarks")
4918 (init . (lambda ()
4919 (setq anything-c-firefox-bookmarks-alist
4920 (anything-html-bookmarks-to-alist
4921 (anything-guess-firefox-bookmark-file)
4922 anything-firefox-bookmark-url-regexp
4923 anything-firefox-bookmarks-regexp))))
4924 (candidates . (lambda ()
4925 (mapcar #'car anything-c-firefox-bookmarks-alist)))
4926 (filtered-candidate-transformer
4927 ;anything-c-adaptive-sort
4928 anything-c-highlight-firefox-bookmarks)
4929 (action . (("Browse Url Firefox"
4930 . (lambda (candidate)
4931 (browse-url-firefox
4932 (anything-c-firefox-bookmarks-get-value candidate))))
4933 ("Browse Url w3m"
4934 . (lambda (candidate)
4935 (w3m-browse-url
4936 (anything-c-firefox-bookmarks-get-value candidate))))
4937 ("Copy Url"
4938 . (lambda (elm)
4939 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
4941 ;; (anything 'anything-c-source-firefox-bookmarks)
4943 (defun anything-c-firefox-bookmarks-get-value (elm)
4944 (assoc-default elm anything-c-firefox-bookmarks-alist))
4946 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
4947 (loop for i in bookmarks
4948 collect (propertize
4949 i 'face '((:foreground "YellowGreen"))
4950 'help-echo (anything-c-firefox-bookmarks-get-value i))))
4952 ;; W3m bookmark
4953 ;; Bugfix:
4954 ;; Some users have the emacs-w3m library in load-path
4955 ;; without having the w3m executable :-;
4956 ;; So check if w3m program is present before trying to load
4957 ;; emacs-w3m.
4958 (eval-when-compile
4959 (when (executable-find "w3m")
4960 (require 'w3m-bookmark nil t)))
4961 (defvar w3m-bookmark-file "~/.w3m/bookmark.html")
4964 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
4965 "Face for w3m bookmarks" :group 'anything)
4967 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
4968 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
4969 (defvar anything-c-w3m-bookmarks-alist nil)
4970 (defvar anything-c-source-w3m-bookmarks
4971 '((name . "W3m Bookmarks")
4972 (init . (lambda ()
4973 (setq anything-c-w3m-bookmarks-alist
4974 (anything-html-bookmarks-to-alist
4975 w3m-bookmark-file
4976 anything-w3m-bookmark-url-regexp
4977 anything-w3m-bookmarks-regexp))))
4978 (candidates . (lambda ()
4979 (mapcar #'car anything-c-w3m-bookmarks-alist)))
4980 (filtered-candidate-transformer
4981 ;anything-c-adaptive-sort
4982 anything-c-highlight-w3m-bookmarks)
4983 (action . (("Browse Url"
4984 . (lambda (candidate)
4985 (anything-c-w3m-browse-bookmark candidate)))
4986 ("Copy Url"
4987 . (lambda (elm)
4988 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
4989 ("Browse Url Firefox"
4990 . (lambda (candidate)
4991 (anything-c-w3m-browse-bookmark candidate t)))
4992 ("Delete Bookmark"
4993 . (lambda (candidate)
4994 (anything-c-w3m-delete-bookmark candidate)))
4995 ("Rename Bookmark"
4996 . (lambda (candidate)
4997 (anything-c-w3m-rename-bookmark candidate)))))
4998 (persistent-action . (lambda (candidate)
4999 (if current-prefix-arg
5000 (anything-c-w3m-browse-bookmark candidate t)
5001 (anything-c-w3m-browse-bookmark candidate nil t))))
5002 (persistent-help . "Open URL with emacs-w3m in new tab / \
5003 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
5004 "Needs w3m and emacs-w3m.
5006 http://w3m.sourceforge.net/
5007 http://emacs-w3m.namazu.org/")
5009 ;; (anything 'anything-c-source-w3m-bookmarks)
5011 (defun anything-c-w3m-bookmarks-get-value (elm)
5012 (replace-regexp-in-string
5013 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
5015 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
5016 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
5017 (arg (and (eq fn 'w3m-browse-url) new-tab)))
5018 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
5020 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
5021 (loop for i in bookmarks
5022 collect (propertize
5023 i 'face 'anything-w3m-bookmarks-face
5024 'help-echo (anything-c-w3m-bookmarks-get-value i))))
5027 (defun anything-c-w3m-delete-bookmark (elm)
5028 (save-excursion
5029 (find-file-literally w3m-bookmark-file)
5030 (goto-char (point-min))
5031 (when (re-search-forward elm nil t)
5032 (beginning-of-line)
5033 (delete-region (point)
5034 (line-end-position))
5035 (delete-blank-lines))
5036 (save-buffer (current-buffer))
5037 (kill-buffer (current-buffer))))
5039 (defun anything-c-w3m-rename-bookmark (elm)
5040 (let* ((old-title (replace-regexp-in-string ">" "" elm))
5041 (new-title (read-string "NewTitle: " old-title)))
5042 (save-excursion
5043 (find-file-literally w3m-bookmark-file)
5044 (goto-char (point-min))
5045 (when (re-search-forward (concat elm "<") nil t)
5046 (goto-char (1- (point)))
5047 (delete-char (- (length old-title)))
5048 (insert new-title))
5049 (save-buffer (current-buffer))
5050 (kill-buffer (current-buffer)))))
5052 ;;;; <Library>
5053 ;;; Elisp library scan
5054 (defvar anything-c-source-elisp-library-scan
5055 '((name . "Elisp libraries (Scan)")
5056 (init . (anything-c-elisp-library-scan-init))
5057 (candidates-in-buffer)
5058 (action ("Find library"
5059 . (lambda (candidate) (find-file (find-library-name candidate))))
5060 ("Find library other window"
5061 . (lambda (candidate)
5062 (find-file-other-window (find-library-name candidate))))
5063 ("Load library"
5064 . (lambda (candidate) (load-library candidate))))))
5065 ;; (anything 'anything-c-source-elisp-library-scan)
5067 (defun anything-c-elisp-library-scan-init ()
5068 "Init anything buffer status."
5069 (let ((anything-buffer (anything-candidate-buffer 'global))
5070 (library-list (anything-c-elisp-library-scan-list)))
5071 (with-current-buffer anything-buffer
5072 (dolist (library library-list)
5073 (insert (format "%s\n" library))))))
5075 (defun anything-c-elisp-library-scan-list (&optional dirs string)
5076 "Do completion for file names passed to `locate-file'.
5077 DIRS is directory to search path.
5078 STRING is string to match."
5079 ;; Use `load-path' as path when ignore `dirs'.
5080 (or dirs (setq dirs load-path))
5081 ;; Init with blank when ignore `string'.
5082 (or string (setq string ""))
5083 ;; Get library list.
5084 (let ((string-dir (file-name-directory string))
5085 ;; File regexp that suffix match `load-file-rep-suffixes'.
5086 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
5087 name
5088 names)
5089 (dolist (dir dirs)
5090 (unless dir
5091 (setq dir default-directory))
5092 (if string-dir
5093 (setq dir (expand-file-name string-dir dir)))
5094 (when (file-directory-p dir)
5095 (dolist (file (file-name-all-completions
5096 (file-name-nondirectory string) dir))
5097 ;; Suffixes match `load-file-rep-suffixes'.
5098 (setq name (if string-dir (concat string-dir file) file))
5099 (if (string-match match-regexp name)
5100 (add-to-list 'names name)))))
5101 names))
5103 ;;;; <Programming>
5104 ;;; Imenu
5105 (defvar anything-c-imenu-delimiter " / ")
5107 (defvar anything-c-imenu-index-filter nil)
5108 (make-variable-buffer-local 'anything-c-imenu-index-filter)
5110 (defvar anything-c-cached-imenu-alist nil)
5111 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
5113 (defvar anything-c-cached-imenu-candidates nil)
5114 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
5116 (defvar anything-c-cached-imenu-tick nil)
5117 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
5119 (eval-when-compile (require 'imenu))
5120 (setq imenu-auto-rescan t)
5122 (defun anything-imenu-create-candidates (entry)
5123 "Create candidates with ENTRY."
5124 (if (listp (cdr entry))
5125 (mapcan
5126 (lambda (sub)
5127 (if (consp (cdr sub))
5128 (mapcar
5129 (lambda (subentry)
5130 (concat (car entry) anything-c-imenu-delimiter subentry))
5131 (anything-imenu-create-candidates sub))
5132 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
5133 (cdr entry))
5134 (list entry)))
5136 (defvar anything-c-source-imenu
5137 '((name . "Imenu")
5138 (init . (lambda () (require 'imenu)))
5139 (candidates . anything-c-imenu-candidates)
5140 (persistent-action . (lambda (elm)
5141 (anything-c-imenu-default-action elm)
5142 (unless (fboundp 'semantic-imenu-tag-overlay)
5143 (anything-match-line-color-current-line))))
5144 (persistent-help . "Show this entry")
5145 (action . anything-c-imenu-default-action))
5146 "See (info \"(emacs)Imenu\")")
5148 ;; (anything 'anything-c-source-imenu)
5150 (defun anything-c-imenu-candidates ()
5151 (with-current-buffer anything-current-buffer
5152 (let ((tick (buffer-modified-tick)))
5153 (if (eq anything-c-cached-imenu-tick tick)
5154 anything-c-cached-imenu-candidates
5155 (setq imenu--index-alist nil)
5156 (setq anything-c-cached-imenu-tick tick
5157 anything-c-cached-imenu-candidates
5158 (ignore-errors
5159 (mapcan
5160 'anything-imenu-create-candidates
5161 (setq anything-c-cached-imenu-alist
5162 (let ((index (imenu--make-index-alist)))
5163 (if anything-c-imenu-index-filter
5164 (funcall anything-c-imenu-index-filter index)
5165 index))))))
5166 (setq anything-c-cached-imenu-candidates
5167 (mapcar #'(lambda (x)
5168 (if (stringp x)
5170 (car x)))
5171 anything-c-cached-imenu-candidates))))))
5173 (setq imenu-default-goto-function 'imenu-default-goto-function)
5174 (defun anything-c-imenu-default-action (elm)
5175 "The default action for `anything-c-source-imenu'."
5176 (let ((path (split-string elm anything-c-imenu-delimiter))
5177 (alist anything-c-cached-imenu-alist))
5178 (dolist (elm path)
5179 (setq alist (assoc elm alist)))
5180 (imenu alist)))
5182 ;;; Ctags
5183 (defvar anything-c-ctags-modes
5184 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
5185 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
5186 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
5188 (defun anything-c-source-ctags-init ()
5189 (when (and buffer-file-name
5190 (memq major-mode anything-c-ctags-modes)
5191 (anything-current-buffer-is-modified))
5192 (with-current-buffer (anything-candidate-buffer 'local)
5193 (call-process-shell-command
5194 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
5195 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
5196 anything-buffer-file-name)
5197 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
5198 nil (current-buffer))
5199 (goto-char (point-min))
5200 (forward-line 2)
5201 (delete-region (point-min) (point))
5202 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
5203 for lineno-start = (point)
5204 for lineno = (buffer-substring
5205 lineno-start
5206 (1- (search-forward "," (point-at-eol) t)))
5208 (beginning-of-line)
5209 (insert (format "%5s:" lineno))
5210 (search-forward "\177" (point-at-eol) t)
5211 (delete-region (1- (point)) (point-at-eol))
5212 (forward-line 1)))))
5214 (defvar anything-c-source-ctags
5215 '((name . "Exuberant ctags")
5216 (init . anything-c-source-ctags-init)
5217 (candidates-in-buffer)
5218 (adjust)
5219 (type . line))
5220 "Needs Exuberant Ctags.
5222 http://ctags.sourceforge.net/")
5223 ;; (anything 'anything-c-source-ctags)
5225 ;; Semantic
5226 (eval-when-compile (require 'semantic nil t))
5227 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
5228 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
5229 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
5230 (declare-function semantic-tag-type "ext:tag-file.el" (tag) t)
5231 (declare-function semantic-tag-class "ext:tag-file.el" (tag) t)
5232 (defvar anything-semantic-candidates nil)
5234 (defun anything-semantic-construct-candidates (tags depth)
5235 (when (require 'semantic nil t)
5236 (apply
5237 'append
5238 (mapcar
5239 (lambda (tag)
5240 (if (listp tag)
5241 (let ((type (semantic-tag-type tag))
5242 (class (semantic-tag-class tag)))
5243 (if (or (and (stringp type)
5244 (or (string= type "class")
5245 (string= type "namespace")))
5246 (eq class 'function)
5247 (eq class 'variable))
5248 (cons (cons (concat (make-string (* depth 2) ?\s)
5249 (semantic-format-tag-summarize tag nil t))
5250 tag)
5251 (anything-semantic-construct-candidates
5252 (semantic-tag-components tag) (1+ depth)))))))
5253 tags))))
5255 (defun anything-semantic-default-action (candidate)
5256 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
5257 (semantic-go-to-tag tag)))
5259 (defvar anything-c-source-semantic
5260 '((name . "Semantic Tags")
5261 (init . (lambda ()
5262 (setq anything-semantic-candidates
5263 (ignore-errors (anything-semantic-construct-candidates
5264 (semantic-fetch-tags) 0)))))
5265 (candidates . (lambda ()
5266 (if anything-semantic-candidates
5267 (mapcar 'car anything-semantic-candidates))))
5268 (persistent-action . (lambda (elm)
5269 (anything-semantic-default-action elm)
5270 (anything-match-line-color-current-line)))
5271 (persistent-help . "Show this entry")
5272 (action . anything-semantic-default-action)
5273 "Needs semantic in CEDET.
5275 http://cedet.sourceforge.net/semantic.shtml
5276 http://cedet.sourceforge.net/"))
5278 ;; (anything 'anything-c-source-semantic)
5280 ;;; Function is called by
5281 ;;;###autoload
5282 (defun anything-simple-call-tree ()
5283 "Preconfigured `anything' for simple-call-tree. List function relationships.
5285 Needs simple-call-tree.el.
5286 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
5287 (interactive)
5288 (anything-other-buffer
5289 '(anything-c-source-simple-call-tree-functions-callers
5290 anything-c-source-simple-call-tree-callers-functions)
5291 "*anything simple-call-tree*"))
5293 (defvar anything-c-source-simple-call-tree-functions-callers
5294 '((name . "Function is called by")
5295 (init . anything-c-simple-call-tree-functions-callers-init)
5296 (multiline)
5297 (candidates . anything-c-simple-call-tree-candidates)
5298 (persistent-action . anything-c-simple-call-tree-persistent-action)
5299 (persistent-help . "Show function definitions by rotation")
5300 (action ("Find definition selected by persistent-action" .
5301 anything-c-simple-call-tree-find-definition)))
5302 "Needs simple-call-tree.el.
5303 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
5305 (defvar anything-c-simple-call-tree-tick nil)
5306 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
5307 (defun anything-c-simple-call-tree-analyze-maybe ()
5308 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
5309 (simple-call-tree-analyze)
5310 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
5312 (defun anything-c-simple-call-tree-init-base (function message)
5313 (require 'simple-call-tree)
5314 (with-no-warnings
5315 (when (anything-current-buffer-is-modified)
5316 (anything-c-simple-call-tree-analyze-maybe)
5317 (let ((list (funcall function simple-call-tree-alist)))
5318 (with-current-buffer (anything-candidate-buffer 'local)
5319 (dolist (entry list)
5320 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
5321 (insert (car entry) message
5322 (if (string= funcs " ")
5323 " no functions."
5324 funcs)
5325 "\n\n"))))))))
5327 (defun anything-c-simple-call-tree-functions-callers-init ()
5328 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
5329 " is called by\n"))
5331 (defun anything-c-simple-call-tree-candidates ()
5332 (with-current-buffer (anything-candidate-buffer)
5333 (split-string (buffer-string) "\n\n")))
5335 (defvar anything-c-simple-call-tree-related-functions nil)
5336 (defvar anything-c-simple-call-tree-function-index 0)
5337 (defun anything-c-simple-call-tree-persistent-action (candidate)
5338 (unless (eq last-command 'anything-execute-persistent-action)
5339 (setq anything-c-simple-call-tree-related-functions
5340 (delete "no functions."
5341 (split-string
5342 (replace-regexp-in-string " \\| is called by\\| calls "
5343 "" candidate)
5344 "\n")))
5345 (setq anything-c-simple-call-tree-function-index -1))
5346 (incf anything-c-simple-call-tree-function-index)
5347 (anything-c-simple-call-tree-find-definition candidate))
5349 (defun anything-c-simple-call-tree-find-definition (candidate)
5350 (find-function
5351 (intern
5352 (nth (mod anything-c-simple-call-tree-function-index
5353 (length anything-c-simple-call-tree-related-functions))
5354 anything-c-simple-call-tree-related-functions))))
5356 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
5358 ;;; Function calls
5359 (defvar anything-c-source-simple-call-tree-callers-functions
5360 '((name . "Function calls")
5361 (init . anything-c-simple-call-tree-callers-functions-init)
5362 (multiline)
5363 (candidates . anything-c-simple-call-tree-candidates)
5364 (persistent-action . anything-c-simple-call-tree-persistent-action)
5365 (persistent-help . "Show function definitions by rotation")
5366 (action ("Find definition selected by persistent-action" .
5367 anything-c-simple-call-tree-find-definition)))
5368 "Needs simple-call-tree.el.
5369 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
5371 (defun anything-c-simple-call-tree-callers-functions-init ()
5372 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
5374 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
5376 ;;; Commands/Options with doc
5377 (defvar anything-c-auto-document-data nil)
5378 (make-variable-buffer-local 'anything-c-auto-document-data)
5379 (defvar anything-c-source-commands-and-options-in-file
5380 '((name . "Commands/Options in file")
5381 (header-name
5382 . (lambda (x) (format "Commands/Options in %s"
5383 (buffer-local-value 'buffer-file-name
5384 anything-current-buffer))))
5385 (candidates . anything-command-and-options-candidates)
5386 (multiline)
5387 (action . imenu))
5388 "List Commands and Options with doc. It needs auto-document.el .
5390 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
5392 (eval-when-compile (require 'auto-document nil t))
5393 (defun anything-command-and-options-candidates ()
5394 (with-current-buffer anything-current-buffer
5395 (when (and (require 'auto-document nil t)
5396 (eq major-mode 'emacs-lisp-mode)
5397 (or (anything-current-buffer-is-modified)
5398 (not anything-c-auto-document-data)))
5399 (or imenu--index-alist (imenu--make-index-alist t))
5400 (setq anything-c-auto-document-data
5401 (destructuring-bind (commands options)
5402 (adoc-construct anything-current-buffer)
5403 (append
5404 (loop for (command . doc) in commands
5405 for cmdname = (symbol-name command)
5406 collect
5407 (cons
5408 (format "Command: %s\n %s"
5409 (propertize cmdname 'face font-lock-function-name-face)
5410 (adoc-first-line doc))
5411 (assoc cmdname imenu--index-alist)))
5412 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
5413 for (option doc default) in options
5414 for optname = (symbol-name option)
5415 collect
5416 (cons
5417 (format "Option: %s\n %s\n default = %s"
5418 (propertize optname 'face font-lock-variable-name-face)
5419 (adoc-first-line doc)
5420 (adoc-prin1-to-string default))
5421 (assoc optname
5422 var-alist)))))))
5423 anything-c-auto-document-data))
5425 ;; (anything 'anything-c-source-commands-and-options-in-file)
5427 ;;;; <Color and Face>
5428 ;;; Customize Face
5429 (defvar anything-c-source-customize-face
5430 '((name . "Customize Face")
5431 (init . (lambda ()
5432 (unless (anything-candidate-buffer)
5433 (save-window-excursion (list-faces-display))
5434 (anything-candidate-buffer (get-buffer "*Faces*")))))
5435 (candidates-in-buffer)
5436 (get-line . buffer-substring)
5437 (action . (lambda (line)
5438 (customize-face (intern (car (split-string line))))))
5439 (requires-pattern . 3))
5440 "See (info \"(emacs)Faces\")")
5441 ;; (anything 'anything-c-source-customize-face)
5443 ;; Color
5444 (defvar anything-c-source-colors
5445 '((name . "Colors")
5446 (init . (lambda () (unless (anything-candidate-buffer)
5447 (save-window-excursion (list-colors-display))
5448 (anything-candidate-buffer (get-buffer "*Colors*")))))
5449 (candidates-in-buffer)
5450 (get-line . buffer-substring)
5451 (action
5452 ("Copy Name" . (lambda (candidate)
5453 (kill-new (anything-c-colors-get-name candidate))))
5454 ("Copy RGB" . (lambda (candidate)
5455 (kill-new (anything-c-colors-get-rgb candidate))))
5456 ("Insert Name" . (lambda (candidate)
5457 (with-current-buffer anything-current-buffer
5458 (insert (anything-c-colors-get-name candidate)))))
5459 ("Insert RGB" . (lambda (candidate)
5460 (with-current-buffer anything-current-buffer
5461 (insert (anything-c-colors-get-rgb candidate))))))))
5462 ;; (anything 'anything-c-source-colors)
5464 (defun anything-c-colors-get-name (candidate)
5465 "Get color name."
5466 (replace-regexp-in-string
5467 " " ""
5468 (with-temp-buffer
5469 (insert (capitalize candidate))
5470 (goto-char (point-min))
5471 (search-forward-regexp "\\s-\\{2,\\}")
5472 (delete-region (point) (point-max))
5473 (buffer-string))))
5475 (defun anything-c-colors-get-rgb (candidate)
5476 "Get color RGB."
5477 (replace-regexp-in-string
5478 " " ""
5479 (with-temp-buffer
5480 (insert (capitalize candidate))
5481 (goto-char (point-max))
5482 (search-backward-regexp "\\s-\\{2,\\}")
5483 (delete-region (point) (point-min))
5484 (buffer-string))))
5486 ;;;; <Search Engine>
5487 ;;; Tracker desktop search
5488 (defvar anything-c-source-tracker-search
5489 '((name . "Tracker Search")
5490 (candidates . (lambda ()
5491 (start-process "tracker-search-process" nil
5492 "tracker-search"
5493 anything-pattern)))
5494 (type . file)
5495 (requires-pattern . 3)
5496 (delayed))
5497 "Source for retrieving files matching the current input pattern
5498 with the tracker desktop search.")
5499 ;; (anything 'anything-c-source-tracker-search)
5501 ;;; Spotlight (MacOS X desktop search)
5502 (defvar anything-c-source-mac-spotlight
5503 '((name . "mdfind")
5504 (candidates
5505 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
5506 (type . file)
5507 (requires-pattern . 3)
5508 (delayed))
5509 "Source for retrieving files via Spotlight's command line
5510 utility mdfind.")
5511 ;; (anything 'anything-c-source-mac-spotlight)
5514 ;;;; <Kill ring>
5515 ;;; Kill ring
5516 (defvar anything-c-source-kill-ring
5517 '((name . "Kill Ring")
5518 (init . (lambda () (anything-attrset 'last-command last-command)))
5519 (candidates . anything-c-kill-ring-candidates)
5520 (action . anything-c-kill-ring-action)
5521 (last-command)
5522 (migemo)
5523 (multiline))
5524 "Source for browse and insert contents of kill-ring.")
5526 (defun anything-c-kill-ring-candidates ()
5527 (loop for kill in kill-ring
5528 unless (or (< (length kill) anything-kill-ring-threshold)
5529 (string-match "^[\\s\\t]+$" kill))
5530 collect kill))
5532 (defun anything-c-kill-ring-action (str)
5533 "Insert STR in `kill-ring' and set STR to the head.
5534 If this action is executed just after `yank',
5535 replace with STR as yanked string."
5536 (setq kill-ring (delete str kill-ring))
5537 (if (not (eq (anything-attr 'last-command) 'yank))
5538 (insert-for-yank str)
5539 ;; from `yank-pop'
5540 (let ((inhibit-read-only t)
5541 (before (< (point) (mark t))))
5542 (if before
5543 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
5544 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
5545 (setq yank-undo-function nil)
5546 (set-marker (mark-marker) (point) (current-buffer))
5547 (insert-for-yank str)
5548 ;; Set the window start back where it was in the yank command,
5549 ;; if possible.
5550 (set-window-start (selected-window) yank-window-start t)
5551 (if before
5552 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
5553 ;; It is cleaner to avoid activation, even though the command
5554 ;; loop would deactivate the mark because we inserted text.
5555 (goto-char (prog1 (mark t)
5556 (set-marker (mark-marker) (point) (current-buffer)))))))
5557 (kill-new str))
5559 ;; (anything 'anything-c-source-kill-ring)
5561 ;;;; <Mark ring>
5562 ;; DO NOT include these sources in `anything-sources' use
5563 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
5564 ;; `anything-all-mark-rings' instead.
5566 (defun anything-c-source-mark-ring-candidates ()
5567 (flet ((get-marks (pos)
5568 (save-excursion
5569 (goto-char pos)
5570 (beginning-of-line)
5571 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
5572 (when (string= "" line)
5573 (setq line "<EMPTY LINE>"))
5574 (format "%7d: %s" (line-number-at-pos) line)))))
5575 (with-current-buffer anything-current-buffer
5576 (loop
5577 with marks = (cons (mark-marker) mark-ring)
5578 with recip = nil
5579 for i in marks
5580 for m = (get-marks i)
5581 unless (member m recip)
5582 collect m into recip
5583 finally return recip))))
5585 (defvar anything-mark-ring-cache nil)
5586 (defvar anything-c-source-mark-ring
5587 '((name . "mark-ring")
5588 (init . (lambda ()
5589 (setq anything-mark-ring-cache
5590 (ignore-errors (anything-c-source-mark-ring-candidates)))))
5591 (candidates . (lambda ()
5592 (anything-aif anything-mark-ring-cache
5593 it)))
5594 (action . (("Goto line"
5595 . (lambda (candidate)
5596 (anything-goto-line (string-to-number candidate))))))
5597 (persistent-action . (lambda (candidate)
5598 (anything-goto-line (string-to-number candidate))
5599 (anything-match-line-color-current-line)))
5600 (persistent-help . "Show this line")))
5602 ;; (anything 'anything-c-source-mark-ring)
5604 ;;;###autoload
5605 (defun anything-mark-ring ()
5606 "Preconfigured `anything' for `anything-c-source-mark-ring'."
5607 (interactive)
5608 (anything 'anything-c-source-mark-ring))
5610 ;;; Global-mark-ring
5611 (defvar anything-c-source-global-mark-ring
5612 '((name . "global-mark-ring")
5613 (candidates . anything-c-source-global-mark-ring-candidates)
5614 (action . (("Goto line"
5615 . (lambda (candidate)
5616 (let ((items (split-string candidate ":")))
5617 (switch-to-buffer (second items))
5618 (anything-goto-line (string-to-number (car items))))))))
5619 (persistent-action . (lambda (candidate)
5620 (let ((items (split-string candidate ":")))
5621 (switch-to-buffer (second items))
5622 (anything-goto-line (string-to-number (car items)))
5623 (anything-match-line-color-current-line))))
5624 (persistent-help . "Show this line")))
5626 (defun anything-c-source-global-mark-ring-candidates ()
5627 (flet ((buf-fn (m)
5628 (with-current-buffer (marker-buffer m)
5629 (goto-char m)
5630 (beginning-of-line)
5631 (let (line)
5632 (if (string= "" line)
5633 (setq line "<EMPTY LINE>")
5634 (setq line (car (split-string (thing-at-point 'line)
5635 "[\n\r]"))))
5636 (format "%7d:%s: %s"
5637 (line-number-at-pos) (marker-buffer m) line)))))
5638 (loop
5639 with marks = global-mark-ring
5640 with recip = nil
5641 for i in marks
5642 for gm = (unless (or (string-match
5643 "^ " (format "%s" (marker-buffer i)))
5644 (null (marker-buffer i)))
5645 (buf-fn i))
5646 when (and gm (not (member gm recip)))
5647 collect gm into recip
5648 finally return recip)))
5650 ;; (anything 'anything-c-source-global-mark-ring)
5652 ;;;###autoload
5653 (defun anything-global-mark-ring ()
5654 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
5655 (interactive)
5656 (anything 'anything-c-source-global-mark-ring))
5658 ;;;###autoload
5659 (defun anything-all-mark-rings ()
5660 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
5661 `anything-c-source-mark-ring'."
5662 (interactive)
5663 (anything '(anything-c-source-mark-ring
5664 anything-c-source-global-mark-ring)))
5666 ;;;; <Register>
5667 ;;; Insert from register
5668 (defvar anything-c-source-register
5669 '((name . "Registers")
5670 (candidates . anything-c-register-candidates)
5671 (action-transformer . anything-c-register-action-transformer)
5672 (multiline)
5673 (action))
5674 "See (info \"(emacs)Registers\")")
5676 (defun anything-c-register-candidates ()
5677 "Collecting register contents and appropriate commands."
5678 (loop for (char . val) in register-alist
5679 for key = (single-key-description char)
5680 for string-actions =
5681 (cond
5682 ((numberp val)
5683 (list (int-to-string val)
5684 'insert-register
5685 'increment-register))
5686 ((markerp val)
5687 (let ((buf (marker-buffer val)))
5688 (if (null buf)
5689 (list "a marker in no buffer")
5690 (list (concat
5691 "a buffer position:"
5692 (buffer-name buf)
5693 ", position "
5694 (int-to-string (marker-position val)))
5695 'jump-to-register
5696 'insert-register))))
5697 ((and (consp val) (window-configuration-p (car val)))
5698 (list "window configuration."
5699 'jump-to-register))
5700 ((and (consp val) (frame-configuration-p (car val)))
5701 (list "frame configuration."
5702 'jump-to-register))
5703 ((and (consp val) (eq (car val) 'file))
5704 (list (concat "file:"
5705 (prin1-to-string (cdr val))
5706 ".")
5707 'jump-to-register))
5708 ((and (consp val) (eq (car val) 'file-query))
5709 (list (concat "file:a file-query reference: file "
5710 (car (cdr val))
5711 ", position "
5712 (int-to-string (car (cdr (cdr val))))
5713 ".")
5714 'jump-to-register))
5715 ((consp val)
5716 (let ((lines (format "%4d" (length val))))
5717 (list (format "%s: %s\n" lines
5718 (truncate-string-to-width
5719 (mapconcat 'identity (list (car val))
5720 ;; (mapconcat (lambda (y) y) val
5721 "^J") (- (window-width) 15)))
5722 'insert-register)))
5723 ((stringp val)
5724 (list ;; without properties
5725 (substring-no-properties val)
5726 'insert-register
5727 'append-to-register
5728 'prepend-to-register))
5730 "GARBAGE!"))
5731 collect (cons (format "register %3s: %s" key (car string-actions))
5732 (cons char (cdr string-actions)))))
5734 (defun anything-c-register-action-transformer (actions register-and-functions)
5735 "Decide actions by the contents of register."
5736 (loop with func-actions =
5737 '((insert-register
5738 "Insert Register" .
5739 (lambda (c) (insert-register (car c))))
5740 (jump-to-register
5741 "Jump to Register" .
5742 (lambda (c) (jump-to-register (car c))))
5743 (append-to-register
5744 "Append Region to Register" .
5745 (lambda (c) (append-to-register
5746 (car c) (region-beginning) (region-end))))
5747 (prepend-to-register
5748 "Prepend Region to Register" .
5749 (lambda (c) (prepend-to-register
5750 (car c) (region-beginning) (region-end))))
5751 (increment-register
5752 "Increment Prefix Arg to Register" .
5753 (lambda (c) (increment-register
5754 anything-current-prefix-arg (car c)))))
5755 for func in (cdr register-and-functions)
5756 for cell = (assq func func-actions)
5757 when cell
5758 collect (cdr cell)))
5760 ;; (anything 'anything-c-source-register)
5762 ;;; Latex completion
5763 (defun anything-c-latex-math-candidates ()
5764 "Collect candidates for latex math completion."
5765 (loop for i in (cddr LaTeX-math-menu)
5766 for elm = (loop for s in i when (vectorp s)
5767 collect (cons (aref s 0) (aref s 1)))
5768 append elm))
5770 (defvar anything-c-source-latex-math
5771 '((name . "Latex Math Menu")
5772 (init . (lambda ()
5773 (with-current-buffer anything-current-buffer
5774 (LaTeX-math-mode 1))))
5775 (candidate-number-limit . 9999)
5776 (candidates . anything-c-latex-math-candidates)
5777 (action . (lambda (candidate)
5778 (call-interactively candidate)))))
5780 ;;;; <Headline Extraction>
5781 (defvar anything-c-source-fixme
5782 '((name . "TODO/FIXME/DRY comments")
5783 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
5784 (adjust)
5785 (recenter))
5786 "Show TODO/FIXME/DRY comments in current file.")
5787 ;; (anything 'anything-c-source-fixme)
5789 (defvar anything-c-source-rd-headline
5790 '((name . "RD HeadLine")
5791 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
5792 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
5793 (migemo)
5794 (subexp . 1))
5795 "Show RD headlines.
5797 RD is Ruby's POD.
5798 http://en.wikipedia.org/wiki/Ruby_Document_format")
5799 ;; (anything 'anything-c-source-rd-headline)
5801 (defvar anything-c-source-oddmuse-headline
5802 '((name . "Oddmuse HeadLine")
5803 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
5804 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
5805 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
5806 (migemo)
5807 (subexp . 1))
5808 "Show Oddmuse headlines, such as EmacsWiki.")
5809 ;; (anything 'anything-c-source-oddmuse-headline)
5811 (defvar anything-c-source-emacs-source-defun
5812 '((name . "Emacs Source DEFUN")
5813 (headline . "DEFUN\\|DEFVAR")
5814 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
5815 (or buffer-file-name ""))))
5816 "Show DEFUN/DEFVAR in Emacs C source file.")
5817 ;; (anything 'anything-c-source-emacs-source-defun)
5819 (defvar anything-c-source-emacs-lisp-expectations
5820 '((name . "Emacs Lisp Expectations")
5821 (headline . "(desc[ ]\\|(expectations")
5822 (condition . (eq major-mode 'emacs-lisp-mode)))
5823 "Show descriptions (desc) in Emacs Lisp Expectations.
5825 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
5826 ;; (anything 'anything-c-source-emacs-lisp-expectations)
5828 (defvar anything-c-source-emacs-lisp-toplevels
5829 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
5830 (headline . "^(\\|(@\\*\\|^;;;;")
5831 (get-line . buffer-substring)
5832 (condition . (eq major-mode 'emacs-lisp-mode))
5833 (adjust))
5834 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
5835 linkd.el is optional because linkd stars are extracted by regexp.
5836 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
5837 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
5839 (defvar anything-c-source-org-headline
5840 '((name . "Org HeadLine")
5841 (headline
5842 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5843 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5844 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5845 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5846 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5847 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5848 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5849 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
5850 (condition . (eq major-mode 'org-mode))
5851 (migemo)
5852 (subexp . 1)
5853 (persistent-action . (lambda (elm)
5854 (anything-c-action-line-goto elm)
5855 (org-cycle)))
5856 (action-transformer
5857 . (lambda (actions candidate)
5858 '(("Go to Line" . anything-c-action-line-goto)
5859 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
5860 "Show Org headlines.
5861 org-mode is very very much extended text-mode/outline-mode.
5863 See (find-library \"org.el\")
5864 See http://orgmode.org for the latest version.")
5866 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
5867 (insert
5868 (save-excursion
5869 (anything-goto-line (car lineno-and-content))
5870 (and (looking-at org-complex-heading-regexp)
5871 (org-make-link-string (concat "*" (match-string 4)))))))
5873 ;; (anything 'anything-c-source-org-headline)
5875 ;;; Anything yaoddmuse
5876 ;; Be sure to have yaoddmuse.el installed
5877 ;; install-elisp may be required if you want to install elisp file from here.
5878 (defvar anything-yaoddmuse-use-cache-file nil)
5879 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
5880 (defvar anything-c-yaoddmuse-ew-cache nil)
5881 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
5882 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
5883 (candidates . (lambda ()
5884 (if anything-yaoddmuse-use-cache-file
5885 (ignore-errors
5886 (unless anything-c-yaoddmuse-ew-cache
5887 (load anything-c-yaoddmuse-cache-file)
5888 (setq anything-c-yaoddmuse-ew-cache
5889 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
5890 anything-c-yaoddmuse-ew-cache)
5891 (yaoddmuse-update-pagename t)
5892 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
5893 (action . (("Edit page" . (lambda (candidate)
5894 (yaoddmuse-edit "EmacsWiki" candidate)))
5895 ("Browse page" . (lambda (candidate)
5896 (yaoddmuse-browse-page "EmacsWiki" candidate)))
5897 ("Browse page other window" . (lambda (candidate)
5898 (if (one-window-p)
5899 (split-window-vertically))
5900 (yaoddmuse-browse-page "EmacsWiki" candidate)))
5901 ("Browse diff" . (lambda (candidate)
5902 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
5903 ("Copy URL" . (lambda (candidate)
5904 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
5905 (message "Have copy page %s's URL to yank." candidate)))
5906 ("Create page" . (lambda (candidate)
5907 (yaoddmuse-edit "EmacsWiki" anything-input)))
5908 ("Update cache" . (lambda (candidate)
5909 (if anything-yaoddmuse-use-cache-file
5910 (progn
5911 (anything-yaoddmuse-cache-pages t)
5912 (setq anything-c-yaoddmuse-ew-cache
5913 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
5914 (yaoddmuse-update-pagename))))))
5915 (action-transformer anything-c-yaoddmuse-action-transformer))
5916 "Needs yaoddmuse.el.
5918 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5920 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
5922 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
5923 '((name . "Yaoddmuse Post library (EmacsWiki)")
5924 (init . (anything-yaoddmuse-init))
5925 (candidates-in-buffer)
5926 (action . (("Post library and Browse" . (lambda (candidate)
5927 (yaoddmuse-post-file (find-library-name candidate)
5928 "EmacsWiki"
5929 (file-name-nondirectory (find-library-name candidate))
5930 nil t)))
5931 ("Post library" . (lambda (candidate)
5932 (yaoddmuse-post-file (find-library-name candidate)
5933 "EmacsWiki"
5934 (file-name-nondirectory (find-library-name candidate))))))))
5935 "Needs yaoddmuse.el.
5937 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5939 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
5941 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
5942 "Allow the use of `install-elisp' only on elisp files."
5943 (if (string-match "\.el$" candidate)
5944 (append actions '(("Install Elisp" . (lambda (elm)
5945 (install-elisp-from-emacswiki elm)))))
5946 actions))
5948 ;;;###autoload
5949 (defun anything-yaoddmuse-cache-pages (&optional load)
5950 "Fetch the list of files on emacswiki and create cache file.
5951 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
5952 (interactive)
5953 (yaoddmuse-update-pagename)
5954 (save-excursion
5955 (find-file anything-c-yaoddmuse-cache-file)
5956 (erase-buffer)
5957 (insert "(puthash \"EmacsWiki\" '(")
5958 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
5960 (insert (concat "(\"" (car i) "\") ")))
5961 (insert ") yaoddmuse-pages-hash)\n")
5962 (save-buffer)
5963 (kill-buffer (current-buffer))
5964 (when (or current-prefix-arg
5965 load)
5966 (load anything-c-yaoddmuse-cache-file))))
5968 ;;;###autoload
5969 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
5970 "Preconfigured `anything' to edit or view EmacsWiki page.
5972 Needs yaoddmuse.el.
5974 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5975 (interactive)
5976 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
5978 ;;;###autoload
5979 (defun anything-yaoddmuse-emacswiki-post-library ()
5980 "Preconfigured `anything' to post library to EmacsWiki.
5982 Needs yaoddmuse.el.
5984 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5985 (interactive)
5986 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
5988 (defun anything-yaoddmuse-init ()
5989 "Init anything buffer status."
5990 (let ((anything-buffer (anything-candidate-buffer 'global))
5991 (library-list (yaoddmuse-get-library-list)))
5992 (with-current-buffer anything-buffer
5993 ;; Insert library name.
5994 (dolist (library library-list)
5995 (insert (format "%s\n" library)))
5996 ;; Sort lines.
5997 (sort-lines nil (point-min) (point-max)))))
5999 ;;; Eev anchors
6000 (defvar anything-c-source-eev-anchor
6001 '((name . "Anchors")
6002 (candidates
6003 . (lambda ()
6004 (ignore-errors
6005 (with-current-buffer anything-current-buffer
6006 (loop initially (goto-char (point-min))
6007 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
6008 for anchor = (match-string-no-properties 1)
6009 collect (cons (format "%5d:%s"
6010 (line-number-at-pos (match-beginning 0))
6011 (format ee-anchor-format anchor)) anchor))))))
6012 (persistent-action . (lambda (item)
6013 (ee-to item)
6014 (anything-match-line-color-current-line)))
6015 (persistent-help . "Show this entry")
6016 (action . (("Goto link" . ee-to)))))
6017 ;; (anything 'anything-c-source-eev-anchor)
6019 ;;;; <Misc>
6020 ;;; Org keywords
6021 (defvar anything-c-source-org-keywords
6022 '((name . "Org Keywords")
6023 (init . anything-c-org-keywords-init)
6024 (candidates . anything-c-org-keywords-candidates)
6025 (action . anything-c-org-keywords-insert)
6026 (persistent-action . anything-c-org-keywords-show-help)
6027 (persistent-help . "Show an example and info page to describe this keyword.")
6028 (keywords-examples)
6029 (keywords)))
6030 ;; (anything 'anything-c-source-org-keywords)
6031 (defvar anything-c-org-keywords-info-location
6032 '(("#+TITLE:" . "(org)Export options")
6033 ("#+AUTHOR:" . "(org)Export options")
6034 ("#+DATE:" . "(org)Export options")
6035 ("#+EMAIL:" . "(org)Export options")
6036 ("#+DESCRIPTION:" . "(org)Export options")
6037 ("#+KEYWORDS:" . "(org)Export options")
6038 ("#+LANGUAGE:" . "(org)Export options")
6039 ("#+TEXT:" . "(org)Export options")
6040 ("#+TEXT:" . "(org)Export options")
6041 ("#+OPTIONS:" . "(org)Export options")
6042 ("#+BIND:" . "(org)Export options")
6043 ("#+LINK_UP:" . "(org)Export options")
6044 ("#+LINK_HOME:" . "(org)Export options")
6045 ("#+LATEX_HEADER:" . "(org)Export options")
6046 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
6047 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
6048 ("#+INFOJS_OPT" . "(org)Javascript support")
6049 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
6050 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
6051 ("#+ORGTBL" . "(org)Radio tables")
6052 ("#+HTML:" . "(org)Quoting HTML tags")
6053 ("#+LaTeX:" . "(org)Quoting LaTeX code")
6054 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
6055 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
6056 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
6057 ("#+BEGIN_VERSE" . "(org)Paragraphs")
6058 ("#+BEGIN_SRC" . "(org)Literal examples")
6059 ("#+CAPTION" . "(org)Tables in HTML export")
6060 ("#+LABEL" . "(org)Tables in LaTeX export")
6061 ("#+ATTR_HTML" . "(org)Links")
6062 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
6064 (defun anything-c-org-keywords-init ()
6065 (unless (anything-attr 'keywords-examples)
6066 (require 'org)
6067 (anything-attrset 'keywords-examples
6068 (append
6069 (mapcar
6070 (lambda (x)
6071 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
6072 (cons (match-string 2 x) (match-string 1 x)))
6073 (org-split-string (org-get-current-options) "\n"))
6074 (mapcar 'list org-additional-option-like-keywords)))
6075 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
6077 (defun anything-c-org-keywords-candidates ()
6078 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
6079 (anything-attr 'keywords)))
6081 (defun anything-c-org-keywords-insert (keyword)
6082 (cond ((string-match "BEGIN" keyword)
6083 (insert "#+" keyword " ")
6084 (save-excursion
6085 (insert "\n#+" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
6087 (insert "#+" keyword " "))))
6089 (defun anything-c-org-keywords-show-help (keyword)
6090 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
6091 "(org)In-buffer settings"))
6092 (search-forward (concat "#+" keyword) nil t)
6093 (anything-persistent-highlight-point)
6094 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
6097 ;;; Picklist
6098 (defvar anything-c-source-picklist
6099 '((name . "Picklist")
6100 (candidates . (lambda () (mapcar 'car picklist-list)))
6101 (type . file)))
6102 ;; (anything 'anything-c-source-picklist)
6104 ;;; BBDB
6105 (defvar bbdb-records)
6106 (defvar bbdb-buffer-name)
6107 (declare-function bbdb "ext:bbdb-com")
6108 (declare-function bbdb-current-record "ext:bbdb-com")
6109 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
6110 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
6111 (declare-function bbdb-current-record "ext:bbdb-com")
6112 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
6113 (declare-function bbdb-records "ext:bbdb-com"
6114 (&optional dont-check-disk already-in-db-buffer))
6116 (defun anything-c-bbdb-candidates ()
6117 "Return a list of all names in the bbdb database. The format
6118 is \"Firstname Lastname\"."
6119 (mapcar (lambda (bbdb-record)
6120 (replace-regexp-in-string
6121 "\\s-+$" ""
6122 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
6123 (bbdb-records)))
6125 (defun anything-c-bbdb-create-contact (actions candidate)
6126 "Action transformer that returns only an entry to add the
6127 current `anything-pattern' as new contact. All other actions are
6128 removed."
6129 (if (string= candidate "*Add to contacts*")
6130 '(("Add to contacts" . (lambda (actions)
6131 (bbdb-create-internal
6132 (read-from-minibuffer "Name: " anything-c-bbdb-name)
6133 (read-from-minibuffer "Company: ")
6134 (read-from-minibuffer "Email: ")
6137 (read-from-minibuffer "Note: ")))))
6138 actions))
6140 (defun anything-c-bbdb-get-record (candidate)
6141 "Return record that match CANDIDATE."
6142 (bbdb candidate nil)
6143 (set-buffer "*BBDB*")
6144 (bbdb-current-record))
6146 (defvar anything-c-bbdb-name nil
6147 "Only for internal use.")
6149 (defvar anything-c-source-bbdb
6150 '((name . "BBDB")
6151 (candidates . anything-c-bbdb-candidates)
6152 (action ("Send a mail" . anything-c-bbdb-compose-mail)
6153 ("View person's data" . anything-c-bbdb-view-person-action))
6154 (filtered-candidate-transformer . (lambda (candidates source)
6155 (setq anything-c-bbdb-name anything-pattern)
6156 (if (not candidates)
6157 (list "*Add to contacts*")
6158 candidates)))
6159 (action-transformer . (lambda (actions candidate)
6160 (anything-c-bbdb-create-contact actions candidate))))
6161 "Needs BBDB.
6163 http://bbdb.sourceforge.net/")
6164 ;; (anything 'anything-c-source-bbdb)
6166 (defun anything-c-bbdb-view-person-action (candidate)
6167 "View BBDB data of single CANDIDATE or marked candidates."
6168 (anything-aif (anything-marked-candidates)
6169 (let ((bbdb-append-records (length it)))
6170 (dolist (i it)
6171 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
6172 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
6174 (defun anything-c-bbdb-collect-mail-addresses ()
6175 "Return a list of all mail addresses of records in bbdb buffer."
6176 (with-current-buffer bbdb-buffer-name
6177 (loop for i in bbdb-records
6178 if (bbdb-record-net (car i))
6179 collect (bbdb-dwim-net-address (car i)))))
6181 (defun anything-c-bbdb-compose-mail (candidate)
6182 "Compose a mail with all records of bbdb buffer."
6183 (anything-c-bbdb-view-person-action candidate)
6184 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
6185 (address-str (mapconcat 'identity address-list ",\n ")))
6186 (compose-mail address-str)))
6188 ;;; Evaluation Result
6189 (defvar anything-c-source-evaluation-result
6190 '((name . "Evaluation Result")
6191 (disable-shortcuts)
6192 (dummy)
6193 (filtered-candidate-transformer . (lambda (candidates source)
6194 (list
6195 (condition-case nil
6196 (with-current-buffer anything-current-buffer
6197 (pp-to-string
6198 (eval (read anything-pattern))))
6199 (error "Error")))))
6200 (action ("Copy result to kill-ring" . (lambda (candidate)
6201 (with-current-buffer anything-buffer
6202 (let ((end (save-excursion
6203 (goto-char (point-max))
6204 (search-backward "\n")
6205 (point))))
6206 (kill-region (point) end))))))))
6207 ;; (anything 'anything-c-source-evaluation-result)
6209 ;;;###autoload
6210 (defun anything-eval-expression (arg)
6211 "Preconfigured anything for `anything-c-source-evaluation-result'."
6212 (interactive "P")
6213 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
6214 nil nil nil "*anything eval*"))
6216 ;;;###autoload
6217 (defun anything-eval-expression-with-eldoc ()
6218 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
6219 (interactive)
6220 (if (window-system)
6221 (let ((timer (run-with-idle-timer eldoc-idle-delay
6222 'repeat 'anything-eldoc-show-in-eval)))
6223 (unwind-protect
6224 (call-interactively 'anything-eval-expression)
6225 (cancel-timer timer)))
6226 (call-interactively 'anything-eval-expression)))
6228 (defun anything-eldoc-show-in-eval ()
6229 "Return eldoc in a tooltip for current minibuffer input."
6230 (let* ((str-all (minibuffer-completion-contents))
6231 (sym (when str-all
6232 (with-temp-buffer
6233 (insert str-all)
6234 (goto-char (point-max))
6235 (unless (looking-back ")\\|\"") (forward-char -1))
6236 (eldoc-current-symbol))))
6237 (doc (or (eldoc-get-var-docstring sym)
6238 (eldoc-get-fnsym-args-string
6239 (car (eldoc-fnsym-in-current-sexp))))))
6240 (when doc (tooltip-show doc))))
6242 ;;; Calculation Result
6243 (defvar anything-c-source-calculation-result
6244 '((name . "Calculation Result")
6245 (dummy)
6246 (filtered-candidate-transformer . (lambda (candidates source)
6247 (list
6248 (condition-case nil
6249 (calc-eval anything-pattern)
6250 (error "error")))))
6251 (action ("Copy result to kill-ring" . kill-new))))
6252 ;; (anything 'anything-c-source-calculation-result)
6254 ;;;###autoload
6255 (defun anything-calcul-expression ()
6256 "Preconfigured anything for `anything-c-source-calculation-result'."
6257 (interactive)
6258 (anything-other-buffer 'anything-c-source-calculation-result "*anything calcul*"))
6260 ;;; Google Suggestions
6261 (defvar anything-gg-sug-lgh-flag 0)
6262 (defun anything-c-google-suggest-fetch (input)
6263 "Fetch suggestions for INPUT from XML buffer.
6264 Return an alist with elements like (data . number_results)."
6265 (let ((request (concat anything-c-google-suggest-url
6266 (url-hexify-string input))))
6267 (flet ((fetch ()
6268 (loop
6269 with result-alist = (xml-get-children
6270 (car (xml-parse-region (point-min) (point-max)))
6271 'CompleteSuggestion)
6272 for i in result-alist
6273 for data = (cdr (caadr (assoc 'suggestion i)))
6274 for nqueries = (cdr (caadr (assoc 'num_queries i)))
6275 for ldata = (length data)
6277 (when (> ldata anything-gg-sug-lgh-flag)
6278 (setq anything-gg-sug-lgh-flag ldata))
6279 collect (cons data nqueries) into cont
6280 finally return cont)))
6281 (if anything-google-suggest-use-curl-p
6282 (with-temp-buffer
6283 (call-process "curl" nil t nil request)
6284 (fetch))
6285 (with-current-buffer
6286 (url-retrieve-synchronously request)
6287 (fetch))))))
6290 (defun anything-c-google-suggest-set-candidates ()
6291 "Set candidates with result and number of google results found."
6292 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
6293 (setq suggestions (loop for i in suggestions
6294 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
6295 for elm = (concat (car i)
6296 (make-string (+ 2 interval) ? )
6297 "(" (cdr i) " results)")
6298 collect (cons elm (car i))))
6299 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
6300 suggestions
6301 ;; if there is no suggestion exactly matching the input then
6302 ;; prepend a Search on Google item to the list
6303 (append
6304 suggestions
6305 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
6306 anything-input))))))
6309 (defun anything-c-google-suggest-action (candidate)
6310 "Default action to jump to a google suggested candidate."
6311 (anything-c-browse-url (concat anything-c-google-suggest-search-url
6312 (url-hexify-string candidate))))
6315 (defvar anything-c-source-google-suggest
6316 '((name . "Google Suggest")
6317 (candidates . anything-c-google-suggest-set-candidates)
6318 (action . (("Google Search" . anything-c-google-suggest-action)))
6319 (volatile)
6320 (requires-pattern . 3)
6321 (delayed)))
6323 ;; (anything 'anything-c-source-google-suggest)
6325 ;;; Yahoo suggestions
6327 (defun anything-c-yahoo-suggest-fetch (input)
6328 "Fetch Yahoo suggestions for INPUT from XML buffer.
6329 Return an alist with elements like (data . number_results)."
6330 (let ((request (concat anything-c-yahoo-suggest-url
6331 (url-hexify-string input))))
6332 (flet ((fetch ()
6333 (loop
6334 with result-alist = (xml-get-children
6335 (car (xml-parse-region (point-min) (point-max)))
6336 'Result)
6337 for i in result-alist
6338 collect (caddr i))))
6339 (with-current-buffer
6340 (url-retrieve-synchronously request)
6341 (fetch)))))
6343 (defun anything-c-yahoo-suggest-set-candidates ()
6344 "Set candidates with Yahoo results found."
6345 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
6346 (or suggestions
6347 (append
6348 suggestions
6349 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
6350 anything-input))))))
6352 (defun anything-c-yahoo-suggest-action (candidate)
6353 "Default action to jump to a Yahoo suggested candidate."
6354 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
6355 (url-hexify-string candidate))))
6357 (defvar anything-c-source-yahoo-suggest
6358 '((name . "Yahoo Suggest")
6359 (candidates . anything-c-yahoo-suggest-set-candidates)
6360 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
6361 (volatile)
6362 (requires-pattern . 3)
6363 (delayed)))
6365 ;; (anything 'anything-c-source-yahoo-suggest)
6367 ;;; Surfraw
6368 ;;; Need external program surfraw.
6369 ;;; http://surfraw.alioth.debian.org/
6370 ;; user variables
6371 (require 'browse-url)
6372 (defvar w3m-command nil)
6373 (defvar anything-c-home-url "http://www.google.fr"
6374 "*Default url to use as home url.")
6376 (defvar browse-url-chromium-program "chromium-bin")
6377 (defvar anything-browse-url-default-browser-alist
6378 `((,w3m-command . w3m-browse-url)
6379 (,browse-url-firefox-program . browse-url-firefox)
6380 (,browse-url-chromium-program . browse-url-chromium)
6381 (,browse-url-kde-program . browse-url-kde)
6382 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
6383 (,browse-url-mozilla-program . browse-url-mozilla)
6384 (,browse-url-galeon-program . browse-url-galeon)
6385 (,browse-url-netscape-program . browse-url-netscape)
6386 (,browse-url-mosaic-program . browse-url-mosaic)
6387 (,browse-url-xterm-program . browse-url-text-xterm))
6388 "*Alist of (executable . function) to try to find a suitable url browser.")
6390 (defun* anything-c-generic-browser (url name &rest args)
6391 (let ((proc (concat name " " url)))
6392 (message "Starting %s..." name)
6393 (apply 'start-process proc nil name
6394 (append args (list url)))
6395 (set-process-sentinel
6396 (get-process proc)
6397 #'(lambda (process event)
6398 (when (string= event "finished\n")
6399 (message "%s process %s" process event))))))
6401 (defun browse-url-chromium (url)
6402 (interactive "sURL: ")
6403 (anything-c-generic-browser
6404 url browse-url-chromium-program
6405 "--enable-plugins"))
6407 (defun anything-browse-url-default-browser (url &rest args)
6408 "Find a suitable browser and ask it to load URL."
6409 (let ((default-browser (loop
6410 for i in anything-browse-url-default-browser-alist
6411 thereis (and (car i) (executable-find (car i))))))
6412 (if default-browser
6413 (apply default-browser url args)
6414 (error "No usable browser found"))))
6416 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
6417 "Default command to browse URL."
6418 (if browse-url-browser-function
6419 (funcall browse-url-browser-function url)
6420 (anything-browse-url-default-browser url)))
6422 (defun anything-c-build-elvi-list ()
6423 "Return list of all engines and descriptions handled by surfraw."
6424 (cdr
6425 (with-temp-buffer
6426 (call-process "surfraw" nil t nil
6427 "-elvi")
6428 (split-string (buffer-string) "\n"))))
6430 (defvar anything-surfraw-default-browser-function nil
6431 "*The browse url function you prefer to use with surfraw.
6432 When nil, fallback to `browse-url-browser-function'.")
6433 (defvar anything-surfraw-engines-history nil)
6434 ;;;###autoload
6435 (defun anything-surfraw (pattern engine)
6436 "Preconfigured `anything' to search PATTERN with search ENGINE."
6437 (interactive (list (read-string "SearchFor: ")
6438 (anything-comp-read
6439 "Engine: "
6440 (anything-c-build-elvi-list)
6441 :must-match t
6442 :name "Surfraw Search Engines"
6443 :history anything-surfraw-engines-history)))
6444 (let* ((engine-nodesc (car (split-string engine)))
6445 (url (with-temp-buffer
6446 (apply 'call-process "surfraw" nil t nil
6447 (list engine-nodesc "-p" pattern))
6448 (replace-regexp-in-string
6449 "\n" "" (buffer-string))))
6450 (browse-url-browser-function (or anything-surfraw-default-browser-function
6451 browse-url-browser-function)))
6452 (if (string= engine-nodesc "W")
6453 (anything-c-browse-url)
6454 (anything-c-browse-url url)
6455 (setq anything-surfraw-engines-history
6456 (cons engine (delete engine anything-surfraw-engines-history))))))
6458 ;;; Emms
6460 (defun anything-emms-stream-edit-bookmark (elm)
6461 "Change the information of current emms-stream bookmark from anything."
6462 (let* ((cur-buf anything-current-buffer)
6463 (bookmark (assoc elm emms-stream-list))
6464 (name (read-from-minibuffer "Description: "
6465 (nth 0 bookmark)))
6466 (url (read-from-minibuffer "URL: "
6467 (nth 1 bookmark)))
6468 (fd (read-from-minibuffer "Feed Descriptor: "
6469 (int-to-string (nth 2 bookmark))))
6470 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
6471 (format "%s" (car (last bookmark))))))
6472 (save-excursion
6473 (emms-streams)
6474 (when (re-search-forward (concat "^" name) nil t)
6475 (beginning-of-line)
6476 (emms-stream-delete-bookmark)
6477 (emms-stream-add-bookmark name url (string-to-number fd) type)
6478 (emms-stream-save-bookmarks-file)
6479 (emms-stream-quit)
6480 (switch-to-buffer cur-buf)))))
6482 (defun anything-emms-stream-delete-bookmark (elm)
6483 "Delete an emms-stream bookmark from anything."
6484 (let* ((cur-buf anything-current-buffer)
6485 (bookmark (assoc elm emms-stream-list))
6486 (name (nth 0 bookmark)))
6487 (save-excursion
6488 (emms-streams)
6489 (when (re-search-forward (concat "^" name) nil t)
6490 (beginning-of-line)
6491 (emms-stream-delete-bookmark)
6492 (emms-stream-save-bookmarks-file)
6493 (emms-stream-quit)
6494 (switch-to-buffer cur-buf)))))
6496 (defvar anything-c-source-emms-streams
6497 '((name . "Emms Streams")
6498 (init . (lambda ()
6499 (emms-stream-init)))
6500 (candidates . (lambda ()
6501 (mapcar 'car emms-stream-list)))
6502 (action . (("Play" . (lambda (elm)
6503 (let* ((stream (assoc elm emms-stream-list))
6504 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
6505 (url (second stream)))
6506 (funcall fn url))))
6507 ("Delete" . anything-emms-stream-delete-bookmark)
6508 ("Edit" . anything-emms-stream-edit-bookmark)))))
6509 ;(filtered-candidate-transformer . anything-c-adaptive-sort)))
6510 ;; (anything 'anything-c-source-emms-streams)
6512 ;; Don't forget to set `emms-source-file-default-directory'
6513 (defvar anything-c-source-emms-dired
6514 '((name . "Music Directory")
6515 (candidates . (lambda ()
6516 (cddr (directory-files emms-source-file-default-directory))))
6517 (action .
6518 (("Play Directory" . (lambda (item)
6519 (emms-play-directory
6520 (expand-file-name
6521 item
6522 emms-source-file-default-directory))))
6523 ("Open dired in file's directory" . (lambda (item)
6524 (anything-c-open-dired
6525 (expand-file-name
6526 item
6527 emms-source-file-default-directory))))))))
6528 ;(filtered-candidate-transformer . anything-c-adaptive-sort)))
6529 ;; (anything 'anything-c-source-emms-dired)
6531 (defface anything-emms-playlist
6532 '((t (:foreground "Springgreen4" :underline t)))
6533 "*Face used for tracks in current emms playlist."
6534 :group 'anything)
6536 (defun anything-c-emms-files-modifier (candidates source)
6537 (let ((current-playlist (with-current-emms-playlist
6538 (loop
6539 with cur-list = (emms-playlist-tracks-in-region
6540 (point-min) (point-max))
6541 for i in cur-list
6542 collect (assoc-default 'name i)))))
6543 (loop for i in candidates
6544 if (member (cdr i) current-playlist)
6545 collect (cons (propertize (car i)
6546 'face 'anything-emms-playlist)
6547 (cdr i)) into lis
6548 else collect i into lis
6549 finally return lis)))
6551 (defun anything-c-emms-play-current-playlist ()
6552 "Play current playlist."
6553 (with-current-emms-playlist
6554 (emms-playlist-first)
6555 (emms-playlist-mode-play-smart)))
6557 (defvar anything-c-source-emms-files
6558 '((name . "Emms files")
6559 (candidates . (lambda ()
6560 (loop for v being the hash-values in emms-cache-db
6561 for name = (assoc-default 'name v)
6562 for artist = (or (assoc-default 'info-artist v) "unknown")
6563 for genre = (or (assoc-default 'info-genre v) "unknown")
6564 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
6565 for song = (or (assoc-default 'info-title v) "unknown")
6566 for info = (concat artist " - " genre " - " tracknum ": " song)
6567 unless (string-match "^http:" name) collect (cons info name))))
6568 (filtered-candidate-transformer . anything-c-emms-files-modifier)
6569 (action . (("Play file" . emms-play-file)
6570 ("Add to Playlist and play (C-u clear current)"
6571 . (lambda (candidate)
6572 (when anything-current-prefix-arg
6573 (emms-playlist-current-clear))
6574 (emms-playlist-new)
6575 (mapc 'emms-add-playlist-file (anything-marked-candidates))
6576 (unless emms-player-playing-p
6577 (anything-c-emms-play-current-playlist))))))))
6579 ;; (anything 'anything-c-source-emms-files)
6581 ;;; Jabber Contacts (jabber.el)
6582 (defun anything-c-jabber-online-contacts ()
6583 "List online Jabber contacts."
6584 (with-no-warnings
6585 (let (jids)
6586 (dolist (item (jabber-concat-rosters) jids)
6587 (when (get item 'connected)
6588 (push (if (get item 'name)
6589 (cons (get item 'name) item)
6590 (cons (symbol-name item) item)) jids))))))
6592 (defvar anything-c-source-jabber-contacts
6593 '((name . "Jabber Contacts")
6594 (init . (lambda () (require 'jabber)))
6595 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
6596 (action . (lambda (x)
6597 (jabber-chat-with
6598 (jabber-read-account)
6599 (symbol-name
6600 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
6601 ;; (anything 'anything-c-source-jabber-contacts)
6604 ;;; Call source.
6605 (defvar anything-source-select-buffer "*anything source select*")
6606 (defvar anything-c-source-call-source
6607 `((name . "Call anything source")
6608 (candidate-number-limit)
6609 (candidates . (lambda ()
6610 (loop for vname in (all-completions "anything-c-source-" obarray)
6611 for var = (intern vname)
6612 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
6613 if name collect (cons (format "%s `%s'"
6614 name (propertize vname 'face 'font-lock-variable-name-face))
6615 var))))
6616 (action . (("Invoke anything with selected source" .
6617 (lambda (candidate)
6618 (setq anything-candidate-number-limit 9999)
6619 (anything candidate nil nil nil nil
6620 anything-source-select-buffer)))
6621 ("Describe variable" . describe-variable)
6622 ("Find variable" . find-variable)))
6623 (persistent-action . describe-variable)
6624 (persistent-help . "Show description of this source")))
6625 ;; (anything 'anything-c-source-call-source)
6627 ;;;###autoload
6628 (defun anything-call-source ()
6629 "Preconfigured `anything' to call anything source."
6630 (interactive)
6631 (anything 'anything-c-source-call-source nil nil nil nil
6632 anything-source-select-buffer))
6634 (defun anything-call-source-from-anything ()
6635 "Call anything source within `anything' session."
6636 (interactive)
6637 (setq anything-input-idle-delay 0)
6638 (anything-set-sources '(anything-c-source-call-source)))
6640 ;;; Execute Preconfigured anything.
6641 (defvar anything-c-source-anything-commands
6642 '((name . "Preconfigured Anything")
6643 (candidates . anything-c-anything-commands-candidates)
6644 (type . command)
6645 (candidate-number-limit)))
6646 ;; (anything 'anything-c-source-anything-commands)
6648 (defun anything-c-anything-commands-candidates ()
6649 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
6650 collect (cons (if (where-is-internal cmd nil t)
6651 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
6652 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
6653 cmd)))
6655 ;;;###autoload
6656 (defun anything-execute-anything-command ()
6657 "Preconfigured `anything' to execute preconfigured `anything'."
6658 (interactive)
6659 (anything-other-buffer 'anything-c-source-anything-commands
6660 "*anything commands*"))
6662 ;; Occur
6663 (defun anything-c-occur-init ()
6664 (anything-candidate-buffer anything-current-buffer))
6666 (defun anything-c-occur-get-line (s e)
6667 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
6669 (defvar anything-c-source-occur
6670 '((name . "Occur")
6671 (init . anything-c-occur-init)
6672 (candidates-in-buffer)
6673 (migemo)
6674 (get-line . anything-c-occur-get-line)
6675 (type . line)
6676 (recenter)
6677 (requires-pattern . 1)
6678 (delayed)
6679 (volatile)))
6680 ;; (anything 'anything-c-source-occur)
6682 ;;; Anything browse code.
6683 (defun anything-c-browse-code-get-line (beg end)
6684 "Select line if it match the regexp corresponding to current `major-mode'.
6685 Line is parsed for BEG position to END position."
6686 (let ((str-line (buffer-substring beg end))
6687 (regexp (assoc-default major-mode
6688 anything-c-browse-code-regexp-alist))
6689 (num-line (if (string= anything-pattern "") beg (1- beg))))
6690 (when (and regexp (string-match regexp str-line))
6691 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
6694 (defvar anything-c-source-browse-code
6695 '((name . "Browse code")
6696 (init . (lambda ()
6697 (anything-candidate-buffer anything-current-buffer)
6698 (with-current-buffer anything-current-buffer
6699 (jit-lock-fontify-now))))
6700 (candidate-number-limit . 9999)
6701 (candidates-in-buffer)
6702 (get-line . anything-c-browse-code-get-line)
6703 (type . line)
6704 (recenter)))
6706 ;; Do many actions for input
6707 (defvar anything-c-source-create
6708 '((name . "Create")
6709 (dummy)
6710 (action)
6711 (action-transformer . anything-create--actions))
6712 "Do many create actions from `anything-pattern'.
6713 See also `anything-create--actions'.")
6714 ;; (anything 'anything-c-source-create)
6716 (defun anything-create-from-anything ()
6717 "Run `anything-create' from `anything' as a fallback."
6718 (interactive)
6719 (anything-run-after-quit 'anything-create nil anything-pattern))
6721 ;;;###autoload
6722 (defun anything-create (&optional string initial-input)
6723 "Preconfigured `anything' to do many create actions from STRING.
6724 See also `anything-create--actions'."
6725 (interactive)
6726 (setq string (or string (read-string "Create Anything: " initial-input)))
6727 (anything '(((name . "Anything Create")
6728 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
6729 (candidates . anything-create--actions)
6730 (candidate-number-limit)
6731 (action . (lambda (func) (funcall func string)))))))
6733 (defun anything-create--actions (&rest ignored)
6734 "Default actions for `anything-create' / `anything-c-source-create'."
6735 (remove-if-not
6736 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
6737 (append anything-create--actions-private
6738 '(("find-file" . find-file)
6739 ("find-file other window" . find-file-other-window)
6740 ("New buffer" . switch-to-buffer)
6741 ("New buffer other window" . switch-to-buffer-other-window)
6742 ("Bookmark Set" . bookmark-set)
6743 ("Set Register" .
6744 (lambda (x) (set-register (read-char "Register: ") x)))
6745 ("Insert Linkd star" . linkd-insert-star)
6746 ("Insert Linkd Tag" . linkd-insert-tag)
6747 ("Insert Linkd Link" . linkd-insert-link)
6748 ("Insert Linkd Lisp" . linkd-insert-lisp)
6749 ("Insert Linkd Wiki" . linkd-insert-wiki)
6750 ("Google Search" . google)))))
6752 ;; Minibuffer History
6753 (defvar anything-c-source-minibuffer-history
6754 '((name . "Minibuffer History")
6755 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
6756 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
6757 (if (consp (car history))
6758 (mapcar 'prin1-to-string history)
6759 history))))
6760 (migemo)
6761 (action . insert)))
6762 ;; (anything 'anything-c-source-minibuffer-history)
6764 ;; elscreen
6765 (defvar anything-c-source-elscreen
6766 '((name . "Elscreen")
6767 (candidates . (lambda ()
6768 (if (cdr (elscreen-get-screen-to-name-alist))
6769 (sort
6770 (loop for sname in (elscreen-get-screen-to-name-alist)
6771 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
6772 finally (return lst))
6773 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
6774 (action . (("Change Screen".
6775 (lambda (candidate)
6776 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
6777 ("Kill Screen(s)".
6778 (lambda (candidate)
6779 (dolist (i (anything-marked-candidates))
6780 (elscreen-goto (- (aref i 1) (aref "0" 0)))
6781 (elscreen-kill))))
6782 ("Only Screen".
6783 (lambda (candidate)
6784 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
6785 (elscreen-kill-others)))))))
6786 ;; (anything 'anything-c-source-elscreen)
6788 ;;;; <System>
6790 ;;; Top (process)
6791 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
6792 "Top command (batch mode). %s is replaced with `frame-width'.")
6793 (defvar anything-c-source-top
6794 '((name . "Top (Press C-c C-u to refresh)")
6795 (init . anything-c-top-init)
6796 (candidates-in-buffer)
6797 (display-to-real . anything-c-top-display-to-real)
6798 (update . anything-c-top-update)
6799 (persistent-action . anything-c-top-sh-persistent-action)
6800 (persistent-help . "SIGTERM")
6801 (action
6802 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
6803 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
6804 ("Copy PID" . (lambda (pid) (kill-new pid))))))
6805 ;; (anything 'anything-c-source-top)
6807 (defun anything-c-top-sh (cmd)
6808 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
6810 (defun anything-c-top-sh-persistent-action (pid)
6811 (delete-other-windows)
6812 (anything-c-top-sh (format "kill -TERM %s" pid))
6813 (anything-force-update))
6815 (defun anything-c-top-init ()
6816 (with-current-buffer (anything-candidate-buffer 'global)
6817 (call-process-shell-command
6818 (format anything-c-top-command
6819 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
6820 nil (current-buffer))))
6822 (defun anything-c-top-display-to-real (line)
6823 (car (split-string line)))
6825 (defun anything-c-top-update ()
6826 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
6827 (anything-c-top-init)))
6829 ;;;###autoload
6830 (defun anything-top ()
6831 "Preconfigured `anything' for top command."
6832 (interactive)
6833 (let ((anything-samewindow t)
6834 (anything-enable-shortcuts)
6835 (anything-display-function 'anything-default-display-buffer)
6836 (anything-candidate-number-limit 9999))
6837 (save-window-excursion
6838 (delete-other-windows)
6839 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
6841 ;;; Timers
6842 (defvar anything-c-source-absolute-time-timers
6843 '((name . "Absolute Time Timers")
6844 (candidates . timer-list)
6845 (type . timer)))
6846 ;; (anything 'anything-c-source-absolute-time-timers)
6848 (defvar anything-c-source-idle-time-timers
6849 '((name . "Idle Time Timers")
6850 (candidates . timer-idle-list)
6851 (type . timer)))
6852 ;; (anything 'anything-c-source-idle-time-timers)
6854 (defun anything-c-timer-real-to-display (timer)
6855 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
6856 (append timer nil) ;use `append' to convert vector->list
6857 (format "%s repeat=%5S %s(%s)"
6858 (let ((time (list t1 t2 t3)))
6859 (if idle-delay
6860 (format-time-string "idle-for=%5s" time)
6861 (format-time-string "%m/%d %T" time)))
6862 repeat-delay
6863 func
6864 (mapconcat 'prin1-to-string args " "))))
6866 ;;; X RandR resolution change
6867 ;;; FIXME I do not care multi-display.
6868 (defvar anything-c-xrandr-output "VGA")
6869 (defvar anything-c-xrandr-screen "0")
6870 (defvar anything-c-source-xrandr-change-resolution
6871 '((name . "Change Resolution")
6872 (candidates
6873 . (lambda ()
6874 (with-temp-buffer
6875 (call-process "xrandr" nil (current-buffer) nil
6876 "--screen" anything-c-xrandr-screen "-q")
6877 (goto-char 1)
6878 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
6879 collect (match-string 1)))))
6880 (action
6881 ("Change Resolution" . (lambda (mode)
6882 (call-process "xrandr" nil nil nil
6883 "--screen" anything-c-xrandr-screen
6884 "--output" anything-c-xrandr-output
6885 "--mode" mode))))))
6886 ;; (anything 'anything-c-source-xrandr-change-resolution)
6888 ;;; Xfont selection
6889 (defun anything-c-persistent-xfont-action (elm)
6890 "Show current font temporarily"
6891 (let ((current-font (cdr (assoc 'font (frame-parameters))))
6892 (default-font elm))
6893 (unwind-protect
6894 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
6895 (set-frame-font current-font))))
6897 (defvar anything-c-xfonts-cache nil)
6898 (defvar anything-c-source-xfonts
6899 '((name . "X Fonts")
6900 (init . (lambda ()
6901 (unless anything-c-xfonts-cache
6902 (setq anything-c-xfonts-cache
6903 (x-list-fonts "*")))))
6904 (candidates . anything-c-xfonts-cache)
6905 (action . (("Copy to kill ring" . (lambda (elm)
6906 (kill-new elm)))
6907 ("Set Font" . (lambda (elm)
6908 (kill-new elm)
6909 (set-frame-font elm 'keep-size)
6910 (message "New font have been copied to kill ring")))))
6911 (persistent-action . anything-c-persistent-xfont-action)
6912 (persistent-help . "Switch to this font temporarily")))
6914 ;;;###autoload
6915 (defun anything-select-xfont ()
6916 "Preconfigured `anything' to select Xfont."
6917 (interactive)
6918 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
6920 ;; (anything 'anything-c-source-xfonts)
6922 ;;; World time
6924 (defvar anything-c-source-time-world
6925 '((name . "Time World List")
6926 (init . (lambda ()
6927 (let ((anything-buffer (anything-candidate-buffer 'global)))
6928 (with-current-buffer anything-buffer
6929 (display-time-world-display display-time-world-list)))))
6930 (candidates-in-buffer)))
6932 ;;;###autoload
6933 (defun anything-world-time ()
6934 "Preconfigured `anything' to show world time."
6935 (interactive)
6936 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
6938 ;;; Source for Debian/Ubuntu users
6939 (defvar anything-c-source-apt
6940 '((name . "APT")
6941 (init . anything-c-apt-init)
6942 (candidates-in-buffer)
6943 (candidate-transformer anything-c-apt-candidate-transformer)
6944 (display-to-real . anything-c-apt-display-to-real)
6945 (candidate-number-limit . 9999)
6946 (action
6947 ("Show package description" . anything-c-apt-cache-show)
6948 ("Install package" . anything-c-apt-install)
6949 ("Remove package" . anything-c-apt-uninstall)
6950 ("Purge package" . anything-c-apt-purge))
6951 (persistent-action . anything-c-apt-persistent-action)
6952 (persistent-help . "Show - C-u Refresh")))
6953 ;; (anything 'anything-c-source-apt)
6955 (defvar anything-c-apt-query "emacs")
6956 (defvar anything-c-apt-search-command "apt-cache search '%s'")
6957 (defvar anything-c-apt-show-command "apt-cache show '%s'")
6958 (defvar anything-c-apt-installed-packages nil)
6960 (defface anything-apt-installed
6961 '((t (:foreground "green")))
6962 "*Face used for apt installed candidates."
6963 :group 'anything)
6965 (defun anything-c-apt-refresh ()
6966 "Refresh installed candidates list."
6967 (setq anything-c-apt-installed-packages nil)
6968 (anything-force-update))
6970 (defun anything-c-apt-persistent-action (candidate)
6971 "Persistent action for APT source."
6972 (if current-prefix-arg
6973 (anything-c-apt-refresh)
6974 (anything-c-apt-cache-show candidate)))
6976 ;;;###autoload
6977 (defun anything-apt (query)
6978 "Preconfigured `anything' : frontend of APT package manager."
6979 (interactive "sAPT search: ")
6980 (let ((anything-c-apt-query query))
6981 (anything 'anything-c-source-apt)))
6983 (defun anything-c-apt-candidate-transformer (candidates)
6984 "Show installed candidates in a different color."
6985 (loop
6986 with all
6987 for cand in candidates
6988 for name = (anything-c-apt-display-to-real cand)
6989 if (member name anything-c-apt-installed-packages)
6990 collect (propertize cand 'face 'anything-apt-installed) into all
6991 else collect cand into all finally return all))
6993 (defun anything-c-apt-init ()
6994 "Initialize list of debian packages."
6995 (unless anything-c-apt-installed-packages
6996 (message "Updating installed candidate list...")
6997 (setq anything-c-apt-installed-packages
6998 (with-temp-buffer
6999 (call-process-shell-command "dpkg --get-selections"
7000 nil (current-buffer))
7001 (loop for i in (split-string (buffer-string) "\n" t)
7002 collect (car (split-string i))))))
7003 (with-current-buffer
7004 (anything-candidate-buffer
7005 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
7006 (erase-buffer)
7007 (call-process-shell-command
7008 (format anything-c-apt-search-command anything-c-apt-query)
7009 nil (current-buffer)))
7010 (message "Updating installed candidate list...done"))
7012 (defun anything-c-apt-display-to-real (line)
7013 "Return only name of a debian package.
7014 LINE is displayed like:
7015 package name - description."
7016 (car (split-string line " - ")))
7018 ;;;###autoload
7019 (defun anything-c-shell-command-if-needed (command)
7020 (interactive "sShell command: ")
7021 (if (get-buffer command) ; if the buffer already exists
7022 (switch-to-buffer command) ; then just switch to it
7023 (switch-to-buffer command) ; otherwise create it
7024 (insert (shell-command-to-string command))))
7026 (defun anything-c-apt-cache-show (package)
7027 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
7029 (defun anything-c-apt-install (package)
7030 (anything-c-apt-install1 package :action 'install))
7032 (defun anything-c-apt-uninstall (package)
7033 (anything-c-apt-install1 package :action 'uninstall))
7035 (defun anything-c-apt-purge (package)
7036 (anything-c-apt-install1 package :action 'purge))
7038 (defun* anything-c-apt-install1 (candidate &key action)
7039 (ansi-term (getenv "SHELL") "anything apt")
7040 (term-line-mode)
7041 (let ((command (case action
7042 ('install "sudo apt-get install '%s'")
7043 ('uninstall "sudo apt-get remove '%s'")
7044 ('purge "sudo apt-get purge '%s'")
7045 (t (error "Unknow action"))))
7046 (beg (point)) end)
7047 (goto-char (point-max))
7048 (insert (format command candidate))
7049 (setq end (point))
7050 (if (y-or-n-p (format "%s package" (symbol-name action)))
7051 (progn
7052 (setq anything-c-external-commands-list nil)
7053 (setq anything-c-apt-installed-packages nil)
7054 (term-char-mode) (term-send-input))
7055 (delete-region beg end) (term-send-eof) (kill-buffer))))
7057 ;; (anything-c-apt-install "jed")
7059 ;;; Sources for gentoo users
7060 (defvar anything-c-gentoo-use-flags nil)
7061 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
7062 (defvar anything-c-cache-gentoo nil)
7063 (defvar anything-c-cache-world nil)
7064 (defvar anything-c-source-gentoo
7065 '((name . "Portage sources")
7066 (init . (lambda ()
7067 (get-buffer-create anything-c-gentoo-buffer)
7068 (unless anything-c-cache-gentoo
7069 (anything-c-gentoo-setup-cache))
7070 (unless anything-c-cache-world
7071 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
7072 (anything-c-gentoo-init-list)))
7073 (candidates-in-buffer)
7074 (match . identity)
7075 (candidate-transformer anything-c-highlight-world)
7076 (action . (("Show package" . (lambda (elm)
7077 (anything-c-gentoo-eshell-action elm "eix")))
7078 ("Show history" . (lambda (elm)
7079 (if (member elm anything-c-cache-world)
7080 (anything-c-gentoo-eshell-action elm "genlop -qe")
7081 (message "No infos on packages not yet installed"))))
7082 ("Copy in kill-ring" . kill-new)
7083 ("insert at point" . insert)
7084 ("Browse HomePage" . (lambda (elm)
7085 (let ((urls (anything-c-gentoo-get-url elm)))
7086 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
7087 ("Show extra infos" . (lambda (elm)
7088 (if (member elm anything-c-cache-world)
7089 (anything-c-gentoo-eshell-action elm "genlop -qi")
7090 (message "No infos on packages not yet installed"))))
7091 ("Show use flags" . (lambda (elm)
7092 (anything-c-gentoo-default-action elm "equery" "-C" "u")
7093 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
7094 (font-lock-mode 1)))
7095 ("Run emerge pretend" . (lambda (elm)
7096 (anything-c-gentoo-eshell-action elm "emerge -p")))
7097 ("Emerge" . (lambda (elm)
7098 (anything-gentoo-install elm :action 'install)))
7099 ("Unmerge" . (lambda (elm)
7100 (anything-gentoo-install elm :action 'uninstall)))
7101 ("Show dependencies" . (lambda (elm)
7102 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
7103 ("Show related files" . (lambda (elm)
7104 (anything-c-gentoo-default-action elm "equery" "files")))
7105 ("Refresh" . (lambda (elm)
7106 (anything-c-gentoo-setup-cache)
7107 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
7109 ;; (anything 'anything-c-source-gentoo)
7111 (defun* anything-gentoo-install (candidate &key action)
7112 (setq anything-c-external-commands-list nil)
7113 (ansi-term (getenv "SHELL") "Gentoo emerge")
7114 (term-line-mode)
7115 (let ((command (case action
7116 ('install "sudo emerge -av ")
7117 ('uninstall "sudo emerge -avC ")
7118 (t (error "Unknow action"))))
7119 (elms (mapconcat 'identity (anything-marked-candidates) " "))
7120 (beg (point)) end)
7121 (goto-char (point-max))
7122 (insert (concat command elms))
7123 (setq end (point))
7124 (term-char-mode) (term-send-input)))
7126 (defun anything-c-gentoo-default-action (elm command &rest args)
7127 "Gentoo default action that use `anything-c-gentoo-buffer'."
7128 (if (member elm anything-c-cache-world)
7129 (progn
7130 (switch-to-buffer anything-c-gentoo-buffer)
7131 (erase-buffer)
7132 (let ((com-list (append args (list elm))))
7133 (apply #'call-process command nil t nil
7134 com-list)))
7135 (message "No infos on packages not yet installed")))
7137 (defvar anything-c-source-use-flags
7138 '((name . "Use Flags")
7139 (init . (lambda ()
7140 (unless anything-c-gentoo-use-flags
7141 (anything-c-gentoo-setup-use-flags-cache))
7142 (anything-c-gentoo-get-use)))
7143 (candidates-in-buffer)
7144 (match . identity)
7145 (candidate-transformer anything-c-highlight-local-use)
7146 (action . (("Description"
7147 . (lambda (elm)
7148 (switch-to-buffer anything-c-gentoo-buffer)
7149 (erase-buffer)
7150 (apply #'call-process "euse" nil t nil
7151 `("-i"
7152 ,elm))
7153 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
7154 (font-lock-mode 1)))
7155 ("Enable"
7156 . (lambda (elm)
7157 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
7158 ("Disable"
7159 . (lambda (elm)
7160 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
7161 ("Remove"
7162 . (lambda (elm)
7163 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
7164 ("Show which dep use this flag"
7165 . (lambda (elm)
7166 (switch-to-buffer anything-c-gentoo-buffer)
7167 (erase-buffer)
7168 (apply #'call-process "equery" nil t nil
7169 `("-C"
7171 ,elm))))))))
7174 ;; (anything 'anything-c-source-use-flags)
7176 (defun anything-c-gentoo-init-list ()
7177 "Initialize buffer with all packages in Portage."
7178 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
7179 (buf (anything-candidate-buffer 'portage-buf)))
7180 (with-current-buffer buf
7181 (dolist (i anything-c-cache-gentoo)
7182 (insert (concat i "\n"))))))
7184 (defun anything-c-gentoo-setup-cache ()
7185 "Set up `anything-c-cache-gentoo'"
7186 (setq anything-c-cache-gentoo
7187 (split-string (with-temp-buffer
7188 (call-process "eix" nil t nil
7189 "--only-names")
7190 (buffer-string)))))
7192 (defun anything-c-gentoo-eshell-action (elm command)
7193 (when (get-buffer "*EShell Command Output*")
7194 (kill-buffer "*EShell Command Output*"))
7195 (message "Wait searching...")
7196 (let ((buf-fname (buffer-file-name anything-current-buffer)))
7197 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
7198 (progn
7199 (save-window-excursion
7200 (pop-to-buffer "*scratch*")
7201 (eshell-command (format "%s %s" command elm)))
7202 (pop-to-buffer "*EShell Command Output*"))
7203 (eshell-command (format "%s %s" command elm)))))
7205 (defun anything-c-gentoo-get-use ()
7206 "Initialize buffer with all use flags."
7207 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
7208 (buf (anything-candidate-buffer 'use-buf)))
7209 (with-current-buffer buf
7210 (dolist (i anything-c-gentoo-use-flags)
7211 (insert (concat i "\n"))))))
7214 (defun anything-c-gentoo-setup-use-flags-cache ()
7215 "Setup `anything-c-gentoo-use-flags'"
7216 (setq anything-c-gentoo-use-flags
7217 (split-string (with-temp-buffer
7218 (call-process "eix" nil t nil
7219 "--print-all-useflags")
7220 (buffer-string)))))
7222 (defun anything-c-gentoo-get-url (elm)
7223 "Return a list of urls from eix output."
7224 (loop
7225 with url-list = (split-string
7226 (with-temp-buffer
7227 (call-process "eix" nil t nil
7228 elm "--format" "<homepage>\n")
7229 (buffer-string)))
7230 with all
7231 for i in url-list
7232 when (and (string-match "^http://.*" i)
7233 (not (member i all)))
7234 collect i into all
7235 finally return all))
7237 (defun anything-c-gentoo-get-world ()
7238 "Return list of all installed package on your system."
7239 (split-string (with-temp-buffer
7240 (call-process "qlist" nil t nil
7241 "-I")
7242 (buffer-string))))
7244 (defun anything-c-gentoo-get-local-use ()
7245 (split-string (with-temp-buffer
7246 (call-process "portageq" nil t nil
7247 "envvar"
7248 "USE")
7249 (buffer-string))))
7251 (defface anything-gentoo-match-face '((t (:foreground "red")))
7252 "Face for anything-gentoo installed packages."
7253 :group 'traverse-faces)
7255 (defun anything-c-highlight-world (eix)
7256 "Highlight all installed package."
7257 (loop for i in eix
7258 if (member i anything-c-cache-world)
7259 collect (propertize i 'face 'anything-gentoo-match-face)
7260 else
7261 collect i))
7263 (defun anything-c-highlight-local-use (use-flags)
7264 (let ((local-uses (anything-c-gentoo-get-local-use)))
7265 (loop for i in use-flags
7266 if (member i local-uses)
7267 collect (propertize i 'face 'anything-gentoo-match-face)
7268 else
7269 collect i)))
7271 (defvar anything-c-source-emacs-process
7272 '((name . "Emacs Process")
7273 (candidates . (lambda () (mapcar #'process-name (process-list))))
7274 (persistent-action . (lambda (elm)
7275 (delete-process (get-process elm))
7276 (anything-delete-current-selection)))
7277 (persistent-help . "Kill Process")
7278 (action ("Kill Process" . (lambda (elm)
7279 (delete-process (get-process elm)))))))
7281 ;; (anything 'anything-c-source-emacs-process)
7283 ;; Run Externals commands within Emacs
7284 (defmacro* anything-comp-hash-get-items (hash-table &key test)
7285 "Get the list of all keys/values of hash-table."
7286 `(let ((li-items ()))
7287 (maphash #'(lambda (x y)
7288 (if ,test
7289 (when (funcall ,test y)
7290 (push (list x y) li-items))
7291 (push (list x y) li-items)))
7292 ,hash-table)
7293 li-items))
7295 (defun anything-comp-read-get-candidates (collection &optional test sort-fn)
7296 "Convert COLLECTION to list removing elements that don't match TEST.
7297 SORT-FN is a predicate to sort COLLECTION.
7298 If collection is an `obarray', a TEST is needed. See `obarray'."
7299 (let ((cands
7300 (cond ((and (listp collection) test)
7301 (loop for i in collection when (funcall test i) collect i))
7302 ((and (eq collection obarray) test)
7303 (loop for s being the symbols of collection
7304 when (funcall test s) collect s))
7305 ((and (vectorp collection) test)
7306 (loop for i across collection when (funcall test i) collect i))
7307 ((vectorp collection)
7308 (loop for i across collection collect i))
7309 ((and (hash-table-p collection) test)
7310 (anything-comp-hash-get-items collection :test test))
7311 ((hash-table-p collection)
7312 (anything-comp-hash-get-items collection))
7313 (t collection))))
7314 (if sort-fn (sort cands sort-fn) cands)))
7316 (defun anything-cr-default-transformer (candidates source)
7317 "Default filter candidate function for `anything-comp-read'.
7318 Do nothing, just return candidate list unmodified."
7319 candidates)
7321 (defun* anything-comp-read (prompt collection
7322 &key
7323 test
7324 initial-input
7325 (buffer "*Anything Completions*")
7326 must-match
7327 (requires-pattern 0)
7328 (history nil)
7329 (persistent-action nil)
7330 (persistent-help "DoNothing")
7331 (name "Anything Completions")
7332 sort
7333 (fc-transformer 'anything-cr-default-transformer)
7334 (marked-candidates nil))
7335 "Anything `completing-read' emulation.
7336 PROMPT is the prompt name to use.
7337 COLLECTION can be a list, vector, obarray or hash-table.
7338 Keys:
7340 TEST: A predicate called with one arg i.e candidate.
7341 INITIAL-INPUT: Same as initial-input arg in `anything'.
7342 BUFFER: Name of anything-buffer.
7343 MUST-MATCH: Candidate selected must be one of COLLECTION.
7344 REQUIRES-PATTERN: Same as anything attribute, default is 0.
7345 HISTORY: A list containing specific history, default is nil.
7346 When it is non--nil, all elements of HISTORY are displayed in
7347 anything-buffer before COLLECTION.
7348 PERSISTENT-ACTION: A function called with one arg i.e candidate.
7349 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
7350 NAME: The name related to this local source.
7351 SORT: A predicate to give to `sort' e.g `string-lessp'.
7352 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
7353 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
7355 Any prefix args passed during `anything-comp-read' invocation will be recorded
7356 in `anything-current-prefix-arg', otherwise if prefix args where given before
7357 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
7358 That's mean you can pass prefix arg before or after calling
7359 a command that use `anything-comp-read'."
7360 (when (get-buffer anything-action-buffer)
7361 (kill-buffer anything-action-buffer))
7362 (flet ((action-fn (candidate)
7363 (if marked-candidates
7364 (anything-marked-candidates)
7365 (identity candidate))))
7366 (or (anything
7367 :sources
7368 `(((name . ,(format "%s History" name))
7369 (candidates . (lambda ()
7370 (anything-comp-read-get-candidates history)))
7371 (volatile)
7372 (persistent-action . ,persistent-action)
7373 (persistent-help . ,persistent-help)
7374 (action . ,'action-fn))
7375 ((name . ,name)
7376 (candidates
7377 . (lambda ()
7378 (let ((cands (anything-comp-read-get-candidates
7379 collection test sort)))
7380 (if (or must-match (string= anything-pattern ""))
7381 cands (append (list anything-pattern) cands)))))
7382 (filtered-candidate-transformer ,fc-transformer)
7383 (requires-pattern . ,requires-pattern)
7384 (persistent-action . ,persistent-action)
7385 (persistent-help . ,persistent-help)
7386 (volatile)
7387 (action . ,'action-fn)))
7388 :input initial-input
7389 :prompt prompt
7390 :resume 'noresume
7391 :buffer buffer)
7392 (keyboard-quit))))
7394 (defun anything-c-get-pid-from-process-name (process-name)
7395 "Get pid from running process PROCESS-NAME."
7396 (loop with process-list = (list-system-processes)
7397 for pid in process-list
7398 for process = (assoc-default 'comm (process-attributes pid))
7399 when (and process (string-match process-name process))
7400 return pid))
7403 (defun anything-run-or-raise (exe &optional file)
7404 "Generic command that run asynchronously EXE.
7405 If EXE is already running just jump to his window if `anything-raise-command'
7406 is non--nil.
7407 When FILE argument is provided run EXE with FILE.
7408 In this case EXE must be provided as \"EXE %s\"."
7409 (lexical-let* ((real-com (car (split-string (replace-regexp-in-string "'%s'" "" exe))))
7410 (proc (if file (concat real-com " " file) real-com)))
7411 (if (get-process proc)
7412 (if anything-raise-command
7413 (shell-command (format anything-raise-command real-com))
7414 (error "Error: %s is already running" real-com))
7415 (when (member real-com anything-c-external-commands-list)
7416 (message "Starting %s..." real-com)
7417 (if file
7418 (start-process-shell-command proc nil (format exe file))
7419 (start-process-shell-command proc nil real-com))
7420 (set-process-sentinel
7421 (get-process proc)
7422 #'(lambda (process event)
7423 (when (and (string= event "finished\n")
7424 anything-raise-command
7425 (not (anything-c-get-pid-from-process-name real-com)))
7426 (shell-command (format anything-raise-command "emacs")))
7427 (message "%s process...Finished." process))))
7428 (setq anything-c-external-commands-list
7429 (cons real-com (delete real-com anything-c-external-commands-list))))))
7432 (defvar anything-external-command-history nil)
7433 ;;;###autoload
7434 (defun anything-c-run-external-command (program)
7435 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
7436 If program is already running exit with error.
7437 You can set your own list of commands with
7438 `anything-c-external-commands-list'."
7439 (interactive (list
7440 (anything-comp-read
7441 "RunProgram: "
7442 (anything-c-external-commands-list-1 'sort)
7443 :must-match t
7444 :name "External Commands"
7445 :history anything-external-command-history)))
7446 (anything-run-or-raise program)
7447 (setq anything-external-command-history
7448 (cons program (delete program
7449 (loop for i in anything-external-command-history
7450 when (executable-find i) collect i)))))
7452 (defsubst* anything-c-position (item seq &key (test 'eq))
7453 "A simple and faster replacement of CL `position'."
7454 (loop for i in seq for index from 0
7455 when (funcall test i item) return index))
7457 (defvar anything-c-source-ratpoison-commands
7458 '((name . "Ratpoison Commands")
7459 (init . anything-c-ratpoison-commands-init)
7460 (candidates-in-buffer)
7461 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
7462 (display-to-real . anything-c-ratpoison-commands-display-to-real)
7463 (candidate-number-limit)))
7464 ;; (anything 'anything-c-source-ratpoison-commands)
7466 (defun anything-c-ratpoison-commands-init ()
7467 (unless (anything-candidate-buffer)
7468 (with-current-buffer (anything-candidate-buffer 'global)
7469 ;; with ratpoison prefix key
7470 (save-excursion
7471 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
7472 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
7473 (replace-match "<ratpoison> \\1: \\2"))
7474 (goto-char (point-max))
7475 ;; direct binding
7476 (save-excursion
7477 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
7478 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
7479 (replace-match "\\1: \\2")))))
7481 (defun anything-c-ratpoison-commands-display-to-real (display)
7482 (and (string-match ": " display)
7483 (substring display (match-end 0))))
7485 (defun anything-c-ratpoison-commands-execute (candidate)
7486 (call-process "ratpoison" nil nil nil "-ic" candidate))
7488 ;;;###autoload
7489 (defun anything-ratpoison-commands ()
7490 "Preconfigured `anything' to execute ratpoison commands."
7491 (interactive)
7492 (anything-other-buffer 'anything-c-source-ratpoison-commands
7493 "*anything ratpoison commands*"))
7495 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7496 ;;; Files
7497 (defvar anything-c-external-commands-list nil
7498 "A list of all external commands the user can execute. If this
7499 variable is not set by the user, it will be calculated
7500 automatically.")
7502 (defun anything-c-external-commands-list-1 (&optional sort)
7503 "Returns a list of all external commands the user can execute.
7504 If `anything-c-external-commands-list' is non-nil it will
7505 return its contents. Else it calculates all external commands
7506 and sets `anything-c-external-commands-list'."
7507 (if anything-c-external-commands-list
7508 anything-c-external-commands-list
7509 (setq anything-c-external-commands-list
7510 (loop
7511 with paths = (split-string (getenv "PATH") path-separator)
7512 with completions = ()
7513 for dir in paths
7514 when (and (file-exists-p dir) (file-accessible-directory-p dir))
7515 for lsdir = (loop for i in (directory-files dir t)
7516 for bn = (file-name-nondirectory i)
7517 when (and (not (member bn completions))
7518 (not (file-directory-p i))
7519 (file-executable-p i))
7520 collect bn)
7521 append lsdir into completions
7522 finally return (if sort (sort completions 'string-lessp) completions)))))
7525 (defun anything-c-file-buffers (filename)
7526 "Returns a list of buffer names corresponding to FILENAME."
7527 (let ((name (expand-file-name filename))
7528 (buf-list ()))
7529 (dolist (buf (buffer-list) buf-list)
7530 (let ((bfn (buffer-file-name buf)))
7531 (when (and bfn (string= name bfn))
7532 (push (buffer-name buf) buf-list))))))
7535 (defun anything-c-delete-file (file)
7536 "Delete the given file after querying the user.
7537 Ask to kill buffers associated with that file, too."
7538 (let ((buffers (anything-c-file-buffers file)))
7539 (if (< emacs-major-version 24)
7540 ;; `dired-delete-file' in Emacs versions < 24
7541 ;; doesn't support delete-by-moving-to-trash
7542 ;; so use `delete-directory' and `delete-file'
7543 ;; that handle it.
7544 (cond ((and (not (file-symlink-p file))
7545 (file-directory-p file)
7546 (directory-files file t dired-re-no-dot))
7547 (when (y-or-n-p (format "Recursive delete of `%s'? " file))
7548 (delete-directory file 'recursive)))
7549 ((and (not (file-symlink-p file))
7550 (file-directory-p file))
7551 (delete-directory file))
7552 (t (delete-file file)))
7553 (dired-delete-file
7554 file 'dired-recursive-deletes delete-by-moving-to-trash))
7555 (when buffers
7556 (dolist (buf buffers)
7557 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
7558 (kill-buffer buf))))))
7560 (defun anything-get-mailcap-for-file (filename)
7561 "Get the command to use for FILENAME from mailcap files.
7562 The command is like <command %s> and is meant to use with `format'."
7563 (mailcap-parse-mailcaps)
7564 (let* ((ext (file-name-extension filename))
7565 (mime (when ext (mailcap-extension-to-mime ext))))
7566 (when mime (mailcap-mime-info mime))))
7568 (defun anything-get-default-program-for-file (filename)
7569 "Try to find a default program to open FILENAME.
7570 Try first in `anything-c-external-programs-associations' and then in mailcap file
7571 if nothing found return nil."
7572 (let* ((ext (file-name-extension filename))
7573 (def-prog (assoc-default ext anything-c-external-programs-associations)))
7574 (if (and def-prog (not (string= def-prog "")))
7575 (concat def-prog " %s")
7576 (anything-get-mailcap-for-file filename))))
7578 (defun anything-c-open-file-externally (file)
7579 "Open FILE with an external program.
7580 Try to guess which program to use with `anything-get-default-program-for-file'.
7581 If not found or a prefix arg is given query the user which tool to use."
7582 (let* ((fname (expand-file-name file))
7583 (collection (anything-c-external-commands-list-1 'sort))
7584 (def-prog (anything-get-default-program-for-file fname))
7585 (real-prog-name (if (or anything-current-prefix-arg (not def-prog))
7586 ;; Prefix arg or no default program.
7587 (prog1
7588 (anything-comp-read
7589 "Program: " collection
7590 :must-match t
7591 :name "Open file Externally"
7592 :history anything-external-command-history)
7593 ;; Always prompt to set this program as default.
7594 (setq def-prog nil))
7595 ;; No prefix arg or default program exists.
7596 (replace-regexp-in-string " %s\\| '%s'" "" def-prog)))
7597 (program (concat real-prog-name " '%s'")))
7598 (unless (or def-prog ; Association exists, no need to record it.
7599 ;; Don't try to record non--filenames associations (e.g urls).
7600 (not (file-exists-p fname)))
7601 (when
7602 (y-or-n-p
7603 (format
7604 "Do you want to make `%s' the default program for this kind of files? "
7605 real-prog-name))
7606 (anything-aif (assoc (file-name-extension fname)
7607 anything-c-external-programs-associations)
7608 (setq anything-c-external-programs-associations
7609 (delete it anything-c-external-programs-associations)))
7610 (push (cons (file-name-extension fname)
7611 (read-string
7612 "Program (Add args maybe and confirm): " real-prog-name))
7613 anything-c-external-programs-associations)
7614 (customize-save-variable 'anything-c-external-programs-associations
7615 anything-c-external-programs-associations)))
7616 (anything-run-or-raise program file)
7617 (setq anything-external-command-history
7618 (cons real-prog-name
7619 (delete real-prog-name
7620 (loop for i in anything-external-command-history
7621 when (executable-find i) collect i))))))
7624 ;;;###autoload
7625 (defun w32-shell-execute-open-file (file)
7626 (interactive "fOpen file:")
7627 (with-no-warnings
7628 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
7629 "/" "\\"
7630 (replace-regexp-in-string ; strip cygdrive paths
7631 "/cygdrive/\\(.\\)" "\\1:"
7632 file nil nil) nil t))))
7634 (defun anything-c-open-file-with-default-tool (file)
7635 "Open FILE with the default tool on this platform."
7636 (if (eq system-type 'windows-nt)
7637 (w32-shell-execute-open-file file)
7638 (start-process "anything-c-open-file-with-default-tool"
7640 (cond ((eq system-type 'gnu/linux)
7641 "xdg-open")
7642 ((or (eq system-type 'darwin) ;; Mac OS X
7643 (eq system-type 'macos)) ;; Mac OS 9
7644 "open"))
7645 file)))
7647 (defun anything-c-open-dired (file)
7648 "Opens a dired buffer in FILE's directory. If FILE is a
7649 directory, open this directory."
7650 (if (file-directory-p file)
7651 (dired file)
7652 (dired (file-name-directory file))
7653 (dired-goto-file file)))
7655 (defun anything-c-display-to-real-line (candidate)
7656 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
7657 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
7658 (error "Line number not found")))
7660 (defun anything-c-action-line-goto (lineno-and-content)
7661 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
7662 (append lineno-and-content
7663 (list (if (and (anything-attr-defined 'target-file)
7664 (not anything-in-persistent-action))
7665 'find-file-other-window
7666 'find-file)))))
7668 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
7669 (apply #'anything-goto-file-line
7670 (if (stringp file-line-content)
7671 ;; Case: filtered-candidate-transformer is skipped
7672 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
7673 file-line-content)))
7675 (require 'compile)
7676 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
7677 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
7679 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
7680 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
7681 (let ((filename (match-string 1 candidate))
7682 (lineno (match-string 2 candidate))
7683 (content (match-string 3 candidate)))
7684 (cons (format "%s:%s\n %s"
7685 (propertize filename 'face compilation-info-face)
7686 (propertize lineno 'face compilation-line-face)
7687 content)
7688 (list (expand-file-name
7689 filename
7690 (or (anything-interpret-value (anything-attr 'default-directory))
7691 (and (anything-candidate-buffer)
7692 (buffer-local-value
7693 'default-directory (anything-candidate-buffer)))))
7694 (string-to-number lineno) content)))))
7696 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
7697 (anything-aif (anything-attr 'before-jump-hook)
7698 (funcall it))
7699 (when file (funcall find-file-function file))
7700 (if (anything-attr-defined 'adjust)
7701 (anything-c-goto-line-with-adjustment lineno content)
7702 (anything-goto-line lineno))
7703 (unless (anything-attr-defined 'recenter)
7704 (set-window-start (get-buffer-window anything-current-buffer) (point)))
7705 (anything-aif (anything-attr 'after-jump-hook)
7706 (funcall it))
7707 (when anything-in-persistent-action
7708 (anything-match-line-color-current-line)))
7710 (defun anything-find-file-as-root (candidate)
7711 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
7713 (defun anything-find-many-files (ignore)
7714 (mapc 'find-file (anything-marked-candidates)))
7716 ;; borrowed from etags.el
7717 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
7718 (defun anything-c-goto-line-with-adjustment (line line-content)
7719 (let ((startpos)
7720 offset found pat)
7721 ;; This constant is 1/2 the initial search window.
7722 ;; There is no sense in making it too small,
7723 ;; since just going around the loop once probably
7724 ;; costs about as much as searching 2000 chars.
7725 (setq offset 1000
7726 found nil
7727 pat (concat (if (eq selective-display t)
7728 "\\(^\\|\^m\\) *" "^ *") ;allow indent
7729 (regexp-quote line-content)))
7730 ;; If no char pos was given, try the given line number.
7731 (setq startpos (progn (anything-goto-line line) (point)))
7732 (or startpos (setq startpos (point-min)))
7733 ;; First see if the tag is right at the specified location.
7734 (goto-char startpos)
7735 (setq found (looking-at pat))
7736 (while (and (not found)
7737 (progn
7738 (goto-char (- startpos offset))
7739 (not (bobp))))
7740 (setq found
7741 (re-search-forward pat (+ startpos offset) t)
7742 offset (* 3 offset))) ; expand search window
7743 (or found
7744 (re-search-forward pat nil t)
7745 (error "not found")))
7746 ;; Position point at the right place
7747 ;; if the search string matched an extra Ctrl-m at the beginning.
7748 (and (eq selective-display t)
7749 (looking-at "\^m")
7750 (forward-char 1))
7751 (beginning-of-line))
7753 (anything-document-attribute 'default-directory "type . file-line"
7754 "`default-directory' to interpret file.")
7755 (anything-document-attribute 'before-jump-hook "type . file-line / line"
7756 "Function to call before jumping to the target location.")
7757 (anything-document-attribute 'after-jump-hook "type . file-line / line"
7758 "Function to call after jumping to the target location.")
7759 (anything-document-attribute 'adjust "type . file-line"
7760 "Search around line matching line contents.")
7761 (anything-document-attribute 'recenter "type . file-line / line"
7762 "`recenter' after jumping.")
7763 (anything-document-attribute 'target-file "type . line"
7764 "Goto line of target-file.")
7766 ;;;###autoload
7767 (defun anything-c-call-interactively (cmd-or-name)
7768 "Execute CMD-OR-NAME as Emacs command.
7769 It is added to `extended-command-history'.
7770 `anything-current-prefix-arg' is used as the command's prefix argument."
7771 (setq extended-command-history
7772 (cons (anything-c-stringify cmd-or-name)
7773 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
7774 (let ((current-prefix-arg anything-current-prefix-arg)
7775 (cmd (anything-c-symbolify cmd-or-name)))
7776 (if (stringp (symbol-function cmd))
7777 (execute-kbd-macro (symbol-function cmd))
7778 (setq this-command cmd)
7779 (call-interactively cmd))))
7781 ;;;###autoload
7782 (defun anything-c-set-variable (var)
7783 "Set value to VAR interactively."
7784 (interactive)
7785 (let ((sym (anything-c-symbolify var)))
7786 (set sym (eval-minibuffer (format "Set %s: " var)
7787 (prin1-to-string (symbol-value sym))))))
7788 ;; (setq hh 12)
7789 ;; (anything-c-set-variable 'hh)
7791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7792 (defvar anything-match-line-overlay-face nil)
7793 (defvar anything-match-line-overlay nil)
7795 (defun anything-match-line-color-current-line (&optional start end buf face rec)
7796 "Highlight and underline current position"
7797 (let ((args (list (or start (line-beginning-position))
7798 (or end (1+ (line-end-position)))
7799 buf)))
7800 (if (not anything-match-line-overlay)
7801 (setq anything-match-line-overlay (apply 'make-overlay args))
7802 (apply 'move-overlay anything-match-line-overlay args)))
7803 (overlay-put anything-match-line-overlay
7804 'face (or face anything-match-line-overlay-face))
7805 (when rec
7806 (goto-char start)
7807 (recenter)))
7809 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
7811 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
7812 "Face for source header in the anything buffer." :group 'anything)
7814 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
7816 (defun anything-match-line-cleanup ()
7817 (when anything-match-line-overlay
7818 (delete-overlay anything-match-line-overlay)
7819 (setq anything-match-line-overlay nil)))
7821 (defun anything-match-line-update ()
7822 (when anything-match-line-overlay
7823 (delete-overlay anything-match-line-overlay)
7824 (anything-match-line-color-current-line)))
7826 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
7827 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
7829 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7830 ;;; Files
7831 (defun anything-c-transform-file-load-el (actions candidate)
7832 "Add action to load the file CANDIDATE if it is an emacs lisp
7833 file. Else return ACTIONS unmodified."
7834 (if (member (file-name-extension candidate) '("el" "elc"))
7835 (append actions '(("Load Emacs Lisp File" . load-file)))
7836 actions))
7838 (defun anything-c-transform-file-browse-url (actions candidate)
7839 "Add an action to browse the file CANDIDATE if it in a html
7840 file or URL. Else return ACTIONS unmodified."
7841 (let ((browse-action '("Browse with Browser" . browse-url)))
7842 (cond ((string-match "^http\\|^ftp" candidate)
7843 (cons browse-action actions))
7844 ((string-match "\\.html?$" candidate)
7845 (append actions (list browse-action)))
7846 (t actions))))
7848 ;;;; Function
7849 (defun anything-c-transform-function-call-interactively (actions candidate)
7850 "Add an action to call the function CANDIDATE interactively if
7851 it is a command. Else return ACTIONS unmodified."
7852 (if (commandp (intern-soft candidate))
7853 (append actions '(("Call Interactively"
7855 anything-c-call-interactively)))
7856 actions))
7858 ;;;; S-Expressions
7859 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
7860 "If CANDIDATE's `car' is a command, then add an action to
7861 evaluate it and put it onto the `command-history'."
7862 (if (commandp (car (read candidate)))
7863 ;; Make it first entry
7864 (cons '("Eval and put onto command-history" .
7865 (lambda (sexp)
7866 (let ((sym (read sexp)))
7867 (eval sym)
7868 (setq command-history
7869 (cons sym command-history)))))
7870 actions)
7871 actions))
7873 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7874 ;;; Buffers
7875 (defun anything-c-skip-boring-buffers (buffers)
7876 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
7878 (defun anything-c-skip-current-buffer (buffers)
7879 (if anything-allow-skipping-current-buffer
7880 (remove (buffer-name anything-current-buffer) buffers)
7881 buffers))
7883 (defun anything-c-shadow-boring-buffers (buffers)
7884 "Buffers matching `anything-c-boring-buffer-regexp' will be
7885 displayed with the `file-name-shadow' face if available."
7886 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
7888 ;;; Files
7889 (defun anything-c-shadow-boring-files (files)
7890 "Files matching `anything-c-boring-file-regexp' will be
7891 displayed with the `file-name-shadow' face if available."
7892 (anything-c-shadow-entries files anything-c-boring-file-regexp))
7894 (defun anything-c-skip-boring-files (files)
7895 "Files matching `anything-c-boring-file-regexp' will be skipped."
7896 (anything-c-skip-entries files anything-c-boring-file-regexp))
7897 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
7899 (defun anything-c-skip-current-file (files)
7900 "Current file will be skipped."
7901 (remove (buffer-file-name anything-current-buffer) files))
7903 (defun anything-c-w32-pathname-transformer (args)
7904 "Change undesirable features of windows pathnames to ones more acceptable to
7905 other candidate transformers."
7906 (if (eq system-type 'windows-nt)
7907 (mapcar (lambda (x)
7908 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
7909 (mapcar (lambda (y)
7910 (replace-regexp-in-string "\\\\" "/" y)) args))
7911 args))
7913 (defun anything-c-shorten-home-path (files)
7914 "Replaces /home/user with ~."
7915 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
7916 (getenv "HOME"))))
7917 (mapcar (lambda (file)
7918 (if (and (stringp file) (string-match home file))
7919 (cons (replace-match "~" nil nil file) file)
7920 file))
7921 files)))
7923 ;;; Functions
7924 (defun anything-c-mark-interactive-functions (functions)
7925 "Mark interactive functions (commands) with (i) after the function name."
7926 (let (list)
7927 (loop for function in functions
7928 do (push (cons (concat function
7929 (when (commandp (intern-soft function)) " (i)"))
7930 function)
7931 list)
7932 finally (return (nreverse list)))))
7934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7935 (defvar anything-c-adaptive-done nil
7936 "nil if history information is not yet stored for the current
7937 selection.")
7939 (defvar anything-c-adaptive-history nil
7940 "Contains the stored history information.
7941 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
7943 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
7944 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
7945 when anything is started."
7946 (setq anything-c-adaptive-done nil))
7948 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
7949 "Advise `anything-exit-minibuffer' to store history information
7950 when a candidate is selected with RET."
7951 (anything-c-adaptive-store-selection))
7953 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
7954 "Advise `anything-select-action' to store history information
7955 when the user goes to the action list with TAB."
7956 (anything-c-adaptive-store-selection))
7958 (defun anything-c-source-use-adaptative-p (&optional source-name)
7959 "Return current source only if it use adaptative history, nil otherwise."
7960 (let* ((source (or source-name (anything-get-current-source)))
7961 (adapt-source (or (assoc-default 'filtered-candidate-transformer
7962 (assoc (assoc-default 'type source)
7963 anything-type-attributes))
7964 (assoc-default 'candidate-transformer
7965 (assoc (assoc-default 'type source)
7966 anything-type-attributes))
7967 (assoc-default 'filtered-candidate-transformer source)
7968 (assoc-default 'candidate-transformer source))))
7969 (if (listp adapt-source)
7970 (when (member 'anything-c-adaptive-sort adapt-source) source)
7971 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
7973 (defun anything-c-adaptive-store-selection ()
7974 "Store history information for the selected candidate."
7975 (unless anything-c-adaptive-done
7976 (setq anything-c-adaptive-done t)
7977 (let ((source (anything-c-source-use-adaptative-p)))
7978 (when source
7979 (let* ((source-name (or (assoc-default 'type source)
7980 (assoc-default 'name source)))
7981 (source-info (or (assoc source-name anything-c-adaptive-history)
7982 (progn
7983 (push (list source-name) anything-c-adaptive-history)
7984 (car anything-c-adaptive-history))))
7985 (selection (anything-get-selection))
7986 (selection-info (progn
7987 (setcdr source-info
7988 (cons
7989 (let ((found (assoc selection (cdr source-info))))
7990 (if (not found)
7991 ;; new entry
7992 (list selection)
7994 ;; move entry to the beginning of the
7995 ;; list, so that it doesn't get
7996 ;; trimmed when the history is
7997 ;; truncated
7998 (setcdr source-info
7999 (delete found (cdr source-info)))
8000 found))
8001 (cdr source-info)))
8002 (cadr source-info)))
8003 (pattern-info (progn
8004 (setcdr selection-info
8005 (cons
8006 (let ((found (assoc anything-pattern (cdr selection-info))))
8007 (if (not found)
8008 ;; new entry
8009 (cons anything-pattern 0)
8011 ;; move entry to the beginning of the
8012 ;; list, so if two patterns used the
8013 ;; same number of times then the one
8014 ;; used last appears first in the list
8015 (setcdr selection-info
8016 (delete found (cdr selection-info)))
8017 found))
8018 (cdr selection-info)))
8019 (cadr selection-info))))
8021 ;; increase usage count
8022 (setcdr pattern-info (1+ (cdr pattern-info)))
8024 ;; truncate history if needed
8025 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
8026 (setcdr selection-info
8027 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
8029 (if (file-readable-p anything-c-adaptive-history-file)
8030 (load-file anything-c-adaptive-history-file))
8031 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
8033 (defun anything-c-adaptive-save-history ()
8034 "Save history information to file given by `anything-c-adaptive-history-file'."
8035 (interactive)
8036 (with-temp-buffer
8037 (insert
8038 ";; -*- mode: emacs-lisp -*-\n"
8039 ";; History entries used for anything adaptive display.\n")
8040 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
8041 (current-buffer))
8042 (insert ?\n)
8043 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
8044 (unless (interactive-p) 'quiet))))
8046 (defun anything-c-adaptive-sort (candidates source)
8047 "Sort the CANDIDATES for SOURCE by usage frequency.
8048 This is a filtered candidate transformer you can use for the
8049 attribute `filtered-candidate-transformer' of a source in
8050 `anything-sources' or a type in `anything-type-attributes'."
8051 (let* ((source-name (or (assoc-default 'type source)
8052 (assoc-default 'name source)))
8053 (source-info (assoc source-name anything-c-adaptive-history)))
8054 (if (not source-info)
8055 ;; if there is no information stored for this source then do nothing
8056 candidates
8057 ;; else...
8058 (let ((usage
8059 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
8060 ;; pairs
8061 (mapcar (lambda (candidate-info)
8062 (let ((count 0))
8063 (dolist (pattern-info (cdr candidate-info))
8064 (if (not (equal (car pattern-info)
8065 anything-pattern))
8066 (incf count (cdr pattern-info))
8068 ;; if current pattern is equal to the previously
8069 ;; used one then this candidate has priority
8070 ;; (that's why its count is boosted by 10000) and
8071 ;; it only has to compete with other candidates
8072 ;; which were also selected with the same pattern
8073 (setq count (+ 10000 (cdr pattern-info)))
8074 (return)))
8075 (cons (car candidate-info) count)))
8076 (cdr source-info)))
8077 sorted)
8079 ;; sort the list in descending order, so candidates with highest
8080 ;; priorty come first
8081 (setq usage (sort usage (lambda (first second)
8082 (> (cdr first) (cdr second)))))
8084 ;; put those candidates first which have the highest usage count
8085 (dolist (info usage)
8086 (when (member* (car info) candidates
8087 :test 'anything-c-adaptive-compare)
8088 (push (car info) sorted)
8089 (setq candidates (remove* (car info) candidates
8090 :test 'anything-c-adaptive-compare))))
8092 ;; and append the rest
8093 (append (reverse sorted) candidates nil)))))
8095 (defun anything-c-adaptive-compare (x y)
8096 "Compare candidates X and Y taking into account that the
8097 candidate can be in (DISPLAY . REAL) format."
8098 (equal (if (listp x)
8099 (cdr x)
8101 (if (listp y)
8102 (cdr y)
8103 y)))
8105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8106 (defvar anything-outline-goto-near-line-flag t)
8107 (defvar anything-outline-using nil)
8108 (defun anything-after-update-hook--outline ()
8109 (if (and (eq anything-outline-using t)
8110 (eq anything-outline-goto-near-line-flag t))
8111 (anything-outline-goto-near-line)))
8112 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
8114 (defun anything-outline-goto-near-line ()
8115 (with-anything-window
8116 ;; TODO need consideration whether to update position by every input.
8117 (when t ; (equal anything-pattern "")
8118 (anything-goto-line 2)
8119 (let ((lineno (with-current-buffer anything-current-buffer
8120 (line-number-at-pos (car anything-current-position)))))
8121 (block exit
8122 (while (<= (progn (skip-chars-forward " ")
8123 (or (number-at-point) lineno))
8124 lineno)
8125 (forward-line 1)
8126 (when (eobp)
8127 (forward-line -1)
8128 (return-from exit))))
8129 (forward-line -1)
8130 (and (bobp) (forward-line 1))
8131 (and (anything-pos-header-line-p) (forward-line -2))
8132 (anything-mark-current-line)))))
8134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8135 ;; Plug-in: info-index
8136 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
8137 (let (result)
8138 (unless (anything-candidate-buffer)
8139 (save-window-excursion
8140 (info file)
8141 (let (Info-history
8142 (tobuf (anything-candidate-buffer 'global))
8143 (infobuf (current-buffer))
8144 s e)
8145 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
8146 (Info-goto-node node)
8147 (goto-char (point-min))
8148 (while (search-forward "\n* " nil t)
8149 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
8150 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
8151 (setq s (point-at-bol)
8152 e (point-at-eol))
8153 (with-current-buffer tobuf
8154 (insert-buffer-substring infobuf s e)
8155 (insert "\n"))))))))))
8157 (defun anything-c-info-goto (node-line)
8158 (Info-goto-node (car node-line))
8159 (anything-goto-line (cdr node-line)))
8161 (defun anything-c-info-display-to-real (line)
8162 (and (string-match
8163 ;; This regexp is stolen from Info-apropos-matches
8164 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
8165 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
8166 (string-to-number (or (match-string 3 line) "1")))))
8168 (defun anything-c-make-info-source (source file)
8169 `(,@source
8170 (name . ,(concat "Info Index: " file))
8171 (info-file . ,file)
8172 (init . anything-c-info-init)
8173 (display-to-real . anything-c-info-display-to-real)
8174 (get-line . buffer-substring)
8175 (candidates-in-buffer)
8176 (action ("Goto node" . anything-c-info-goto))))
8178 (defun anything-compile-source--info-index (source)
8179 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
8180 (anything-c-make-info-source source it)
8181 source))
8182 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
8184 (anything-document-attribute 'info-index "info-index plugin"
8185 "Create a source of info index very easily.
8187 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
8189 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
8190 "Index nodes of info file.
8192 If it is omitted, `Info-index-nodes' is used to collect index nodes.
8193 Some info files are missing index specification.
8195 ex. See `anything-c-source-info-screen'.")
8197 ;; Plug-in: candidates-file
8198 (defun anything-compile-source--candidates-file (source)
8199 (if (assoc-default 'candidates-file source)
8200 `((init anything-p-candidats-file-init
8201 ,@(let ((orig-init (assoc-default 'init source)))
8202 (cond ((null orig-init) nil)
8203 ((functionp orig-init) (list orig-init))
8204 (t orig-init))))
8205 (candidates-in-buffer)
8206 ,@source)
8207 source))
8208 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
8210 (defun anything-p-candidats-file-init ()
8211 (destructuring-bind (file &optional updating)
8212 (anything-mklist (anything-attr 'candidates-file))
8213 (setq file (anything-interpret-value file))
8214 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
8215 (when updating
8216 (buffer-disable-undo)
8217 (font-lock-mode -1)
8218 (auto-revert-mode 1)))))
8220 (anything-document-attribute 'candidates-file "candidates-file plugin"
8221 "Use a file as the candidates buffer.
8223 1st argument is a filename, string or function name or variable name.
8224 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
8226 ;; Plug-in: headline
8227 (defun anything-compile-source--anything-headline (source)
8228 (if (assoc-default 'headline source)
8229 (append '((init . anything-headline-init)
8230 (get-line . buffer-substring)
8231 (type . line))
8232 source
8233 '((candidates-in-buffer)
8234 (persistent-help . "Show this line")))
8235 source))
8236 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
8238 (defun anything-headline-init ()
8239 (when (and (anything-current-buffer-is-modified)
8240 (with-current-buffer anything-current-buffer
8241 (eval (or (anything-attr 'condition) t))))
8242 (anything-headline-make-candidate-buffer
8243 (anything-interpret-value (anything-attr 'headline))
8244 (anything-interpret-value (anything-attr 'subexp)))))
8246 (anything-document-attribute 'headline "Headline plug-in"
8247 "Regexp string for anything-headline to scan.")
8248 (anything-document-attribute 'condition "Headline plug-in"
8249 "A sexp representing the condition to use anything-headline.")
8250 (anything-document-attribute 'subexp "Headline plug-in"
8251 "Display (match-string-no-properties subexp).")
8254 (defun anything-headline-get-candidates (regexp subexp)
8255 (with-current-buffer anything-current-buffer
8256 (save-excursion
8257 (goto-char (point-min))
8258 (if (functionp regexp) (setq regexp (funcall regexp)))
8259 (let (hierarchy curhead)
8260 (flet ((matched ()
8261 (if (numberp subexp)
8262 (cons (match-string-no-properties subexp) (match-beginning subexp))
8263 (cons (buffer-substring (point-at-bol) (point-at-eol))
8264 (point-at-bol))))
8265 (hierarchies (headlines)
8266 (1+ (loop for (_ . hierarchy) in headlines
8267 maximize hierarchy)))
8268 (vector-0-n (v n)
8269 (loop for i from 0 to hierarchy
8270 collecting (aref curhead i)))
8271 (arrange (headlines)
8272 (unless (null headlines) ; FIX headlines empty bug!
8273 (loop with curhead = (make-vector (hierarchies headlines) "")
8274 for ((str . pt) . hierarchy) in headlines
8275 do (aset curhead hierarchy str)
8276 collecting
8277 (cons
8278 (format "H%d:%s" (1+ hierarchy)
8279 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
8280 pt)))))
8281 (if (listp regexp)
8282 (arrange
8283 (sort
8284 (loop for re in regexp
8285 for hierarchy from 0
8286 do (goto-char (point-min))
8287 appending
8288 (loop
8289 while (re-search-forward re nil t)
8290 collect (cons (matched) hierarchy)))
8291 (lambda (a b) (> (cdar b) (cdar a)))))
8292 (loop while (re-search-forward regexp nil t)
8293 collect (matched))))))))
8296 (defun anything-headline-make-candidate-buffer (regexp subexp)
8297 (with-current-buffer (anything-candidate-buffer 'local)
8298 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
8299 do (insert
8300 (format "%5d:%s\n"
8301 (with-current-buffer anything-current-buffer
8302 (line-number-at-pos pos))
8303 content)))))
8305 (defun anything-headline-goto-position (pos recenter)
8306 (goto-char pos)
8307 (unless recenter
8308 (set-window-start (get-buffer-window anything-current-buffer) (point))))
8310 (defun anything-revert-buffer (candidate)
8311 (with-current-buffer candidate
8312 (when (buffer-modified-p)
8313 (revert-buffer t t))))
8315 (defun anything-revert-marked-buffers (ignore)
8316 (mapc 'anything-revert-buffer (anything-marked-candidates)))
8318 (defun anything-kill-marked-buffers (ignore)
8319 (mapc 'kill-buffer (anything-marked-candidates)))
8321 ;; Plug-in: persistent-help
8322 (defun anything-compile-source--persistent-help (source)
8323 (append source '((header-line . anything-persistent-help-string))))
8324 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
8326 (defun anything-persistent-help-string ()
8327 (substitute-command-keys
8328 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
8329 (or (anything-interpret-value (anything-attr 'persistent-help))
8330 (anything-aif (or (assoc-default 'persistent-action
8331 (anything-get-current-source))
8332 (assoc-default 'action
8333 (anything-get-current-source)))
8334 (cond ((symbolp it) (symbol-name it))
8335 ((listp it) (or (ignore-errors (caar it)) ""))))
8337 " (keeping session)")))
8339 (anything-document-attribute 'persistent-help "persistent-help plug-in"
8340 "A string to explain persistent-action of this source.
8341 It also accepts a function or a variable name.")
8343 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
8345 ;; Plug-in: Type customize
8346 (defun anything-c-uniq-list (lst)
8347 "Like `remove-duplicates' in CL.
8348 But cut deeper duplicates and test by `equal'. "
8349 (reverse (remove-duplicates (reverse lst) :test 'equal)))
8350 (defvar anything-additional-type-attributes nil)
8351 (defun anything-c-arrange-type-attribute (type spec)
8352 "Override type attributes by `define-anything-type-attribute'.
8354 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
8356 Example: Set `play-sound-file' as default action
8357 (anything-c-arrange-type-attribute 'file
8358 '((action (\"Play sound\" . play-sound-file)
8359 REST ;; Rest of actions (find-file, find-file-other-window, ...)
8362 (add-to-list 'anything-additional-type-attributes
8363 (cons type
8364 (loop with typeattr = (assoc-default type anything-type-attributes)
8365 for (attr . value) in spec
8366 if (listp value)
8367 collect (cons attr
8368 (anything-c-uniq-list
8369 (loop for v in value
8370 if (eq v 'REST)
8371 append (assoc-default attr typeattr)
8372 else
8373 collect v)))
8374 else
8375 collect (cons attr value)))))
8376 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
8378 (defun anything-compile-source--type-customize (source)
8379 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
8380 (append it source)
8381 source))
8382 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
8384 ;; Plug-in: default-action
8385 (defun anything-compile-source--default-action (source)
8386 (anything-aif (assoc-default 'default-action source)
8387 (append `((action ,it ,@(remove it (assoc-default 'action source))))
8388 source)
8389 source))
8390 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
8391 (anything-document-attribute 'default-action "default-action plug-in"
8392 "Default action.")
8394 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8396 (defun anything-c-find-file-or-marked (candidate)
8397 "Open file CANDIDATE or open anything marked files in background."
8398 (let ((marked (anything-marked-candidates)))
8399 (if (> (length marked) 1)
8400 ;; Open all marked files in background.
8401 (mapc 'find-file-noselect marked)
8402 (if (and (not (file-exists-p candidate))
8403 (and ffap-url-regexp
8404 (not (string-match ffap-url-regexp candidate)))
8405 (string-match "/$" candidate))
8406 ;; A a non--existing filename ending with /
8407 ;; Create a directory and jump to it.
8408 (when (y-or-n-p (format "Create directory `%s'? " candidate))
8409 (make-directory candidate 'parent)
8410 (anything-find-files1 candidate))
8411 ;; A non--existing filename NOT ending with / or
8412 ;; an existing filename, create or jump to it.
8413 (find-file-at-point (car marked))))))
8415 (defun anything-delete-marked-files (ignore)
8416 (let* ((files (anything-marked-candidates))
8417 (len (length files)))
8418 (if (not (y-or-n-p
8419 (format "Delete *%s File(s):\n%s"
8421 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
8422 (message "(No deletions performed)")
8423 (dolist (i files)
8424 (set-text-properties 0 (length i) nil i)
8425 (anything-c-delete-file i))
8426 (message "%s File(s) deleted" len))))
8428 (defun anything-ediff-marked-buffers (candidate &optional merge)
8429 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
8430 With optional arg `merge' call `ediff-merge-buffers'."
8431 (let ((lg-lst (length (anything-marked-candidates)))
8432 buf1 buf2)
8433 (case lg-lst
8435 (error "Error:You have to mark at least 1 buffer"))
8437 (setq buf1 anything-current-buffer
8438 buf2 (first (anything-marked-candidates))))
8440 (setq buf1 (first (anything-marked-candidates))
8441 buf2 (second (anything-marked-candidates))))
8443 (error "Error:To much buffers marked!")))
8444 (if merge
8445 (ediff-merge-buffers buf1 buf2)
8446 (ediff-buffers buf1 buf2))))
8448 (defun anything-bookmark-get-bookmark-from-name (bmk)
8449 "Return bookmark name even if it is a bookmark with annotation.
8450 e.g prepended with *.
8451 Return nil if bmk is not a valid bookmark."
8452 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
8453 (if (assoc bookmark bookmark-alist)
8454 bookmark
8455 (when (assoc bmk bookmark-alist)
8456 bmk))))
8458 (defun anything-delete-marked-bookmarks (ignore)
8459 "Delete this bookmark or all marked bookmarks."
8460 (dolist (i (anything-marked-candidates))
8461 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
8462 'batch)))
8464 (defun anything-require-or-error (feature function)
8465 (or (require feature nil t)
8466 (error "Need %s to use `%s'." feature function)))
8468 (defun anything-find-buffer-on-elscreen (candidate)
8469 "Open buffer in new screen, if marked buffers open all in elscreens."
8470 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
8471 (anything-aif (anything-marked-candidates)
8472 (dolist (i it)
8473 (let ((target-screen (elscreen-find-screen-by-buffer
8474 (get-buffer i) 'create)))
8475 (elscreen-goto target-screen)))
8476 (let ((target-screen (elscreen-find-screen-by-buffer
8477 (get-buffer candidate) 'create)))
8478 (elscreen-goto target-screen))))
8480 (defun anything-elscreen-find-file (file)
8481 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
8482 (elscreen-find-file file))
8484 ;; Toggle anything-match-plugin
8485 (defvar anything-mp-initial-highlight-delay nil)
8486 (defun anything-c-toggle-match-plugin ()
8487 "Toggle anything-match-plugin."
8488 (interactive)
8489 (let ((anything-match-plugin-enabled
8490 (member 'anything-compile-source--match-plugin
8491 anything-compile-source-functions)))
8492 (flet ((disable-match-plugin ()
8493 (setq anything-compile-source-functions
8494 (delq 'anything-compile-source--match-plugin
8495 anything-compile-source-functions))
8496 (setq anything-mp-initial-highlight-delay
8497 anything-mp-highlight-delay)
8498 (setq anything-mp-highlight-delay nil))
8499 (enable-match-plugin ()
8500 (require 'anything-match-plugin)
8501 (unless anything-mp-initial-highlight-delay
8502 (setq anything-mp-initial-highlight-delay
8503 anything-mp-highlight-delay))
8504 (setq anything-compile-source-functions
8505 (cons 'anything-compile-source--match-plugin
8506 anything-compile-source-functions))
8507 (unless anything-mp-highlight-delay
8508 (setq anything-mp-highlight-delay
8509 anything-mp-initial-highlight-delay))))
8510 (if anything-match-plugin-enabled
8511 (when (y-or-n-p "Really disable match-plugin? ")
8512 (disable-match-plugin)
8513 (message "Anything-match-plugin disabled"))
8514 (when (y-or-n-p "Really enable match-plugin? ")
8515 (enable-match-plugin)
8516 (message "Anything-match-plugin enabled"))))))
8519 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8521 ;;;; Type Attributes
8522 (define-anything-type-attribute 'buffer
8523 `((action
8524 ,@(if pop-up-frames
8525 '(("Switch to buffer other window" . switch-to-buffer-other-window)
8526 ("Switch to buffer" . switch-to-buffer))
8527 '(("Switch to buffer" . switch-to-buffer)
8528 ("Switch to buffer other window" . switch-to-buffer-other-window)
8529 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
8530 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
8531 ("View buffer" . view-buffer)
8532 ("Display buffer" . display-buffer)
8533 ("Revert buffer" . anything-revert-buffer)
8534 ("Revert Marked buffers" . anything-revert-marked-buffers)
8535 ("Insert buffer" . insert-buffer)
8536 ("Kill buffer" . kill-buffer)
8537 ("Kill Marked buffers" . anything-kill-marked-buffers)
8538 ("Diff with file" . diff-buffer-with-file)
8539 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
8540 ("Ediff Merge marked buffers" . (lambda (candidate)
8541 (anything-ediff-marked-buffers candidate t))))
8542 (persistent-help . "Show this buffer")
8543 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
8544 "Buffer or buffer name.")
8546 (define-anything-type-attribute 'file
8547 `((action
8548 ,@(if pop-up-frames
8549 '(("Find file other window" . find-file-other-window)
8550 ("Find file(s)" . anything-find-many-files)
8551 ("Find file as root" . anything-find-file-as-root))
8552 '(("Find file" . anything-find-many-files)
8553 ("Find file as root" . anything-find-file-as-root)
8554 ("Find file other window" . find-file-other-window)
8555 ("Find file other frame" . find-file-other-frame)))
8556 ("Open dired in file's directory" . anything-c-open-dired)
8557 ("Grep File(s) `C-u recurse'"
8558 . (lambda (candidate)
8559 (if anything-current-prefix-arg
8560 (anything-do-grep1 (anything-marked-candidates) 'recurse)
8561 (anything-do-grep1 (anything-marked-candidates)))))
8562 ("View file" . view-file)
8563 ("Insert file" . insert-file)
8564 ("Delete file(s)" . anything-delete-marked-files)
8565 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
8566 ("Open file with default tool" . anything-c-open-file-with-default-tool)
8567 ("Find file in hex dump" . hexl-find-file))
8568 (persistent-help . "Show this file")
8569 (action-transformer anything-c-transform-file-load-el
8570 anything-c-transform-file-browse-url)
8571 (candidate-transformer anything-c-w32-pathname-transformer
8572 anything-c-skip-current-file
8573 anything-c-skip-boring-files
8574 anything-c-shorten-home-path))
8575 "File name.")
8577 (let ((actions '(("Describe command" . describe-function)
8578 ("Add command to kill ring" . anything-c-kill-new)
8579 ("Go to command's definition" . find-function)
8580 ("Debug on entry" . debug-on-entry)
8581 ("Cancel debug on entry" . cancel-debug-on-entry)
8582 ("Trace function" . trace-function)
8583 ("Trace function (background)" . trace-function-background)
8584 ("Untrace function" . untrace-function))))
8585 (define-anything-type-attribute 'command
8586 `((action ("Call interactively" . anything-c-call-interactively)
8587 ,@actions)
8588 ;; Sort commands according to their usage count.
8589 ;(filtered-candidate-transformer . anything-c-adaptive-sort)
8590 (coerce . anything-c-symbolify)
8591 (persistent-action . describe-function))
8592 "Command. (string or symbol)")
8594 (define-anything-type-attribute 'function
8595 `((action . ,actions)
8596 (action-transformer anything-c-transform-function-call-interactively)
8597 (candidate-transformer anything-c-mark-interactive-functions)
8598 (coerce . anything-c-symbolify))
8599 "Function. (string or symbol)"))
8601 (define-anything-type-attribute 'variable
8602 '((action ("Describe variable" . describe-variable)
8603 ("Add variable to kill ring" . anything-c-kill-new)
8604 ("Go to variable's definition" . find-variable)
8605 ("Set variable" . anything-c-set-variable))
8606 (coerce . anything-c-symbolify))
8607 "Variable.")
8609 (define-anything-type-attribute 'sexp
8610 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
8611 ("Add s-expression to kill ring" . kill-new))
8612 (action-transformer anything-c-transform-sexp-eval-command-sexp))
8613 "String representing S-Expressions.")
8615 (define-anything-type-attribute 'bookmark
8616 `((coerce . anything-bookmark-get-bookmark-from-name)
8617 (action
8618 ("Jump to bookmark" . (lambda (bookmark)
8619 (let ((current-prefix-arg anything-current-prefix-arg))
8620 (bookmark-jump bookmark))
8621 (anything-update)))
8622 ("Jump to BM other window" . (lambda (bookmark)
8623 (bookmark-jump-other-window bookmark)
8624 (anything-update)))
8625 ("Bookmark edit annotation" . bookmark-edit-annotation)
8626 ("Bookmark show annotation" . bookmark-show-annotation)
8627 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
8628 ,@(when (fboundp 'bmkext-edit-bookmark)
8629 '(("Edit Bookmark" . bmkext-edit-bookmark)))
8630 ("Rename bookmark" . bookmark-rename)
8631 ("Relocate bookmark" . bookmark-relocate)))
8632 "Bookmark name.")
8634 (define-anything-type-attribute 'line
8635 '((display-to-real . anything-c-display-to-real-line)
8636 (action ("Go to Line" . anything-c-action-line-goto)))
8637 "LINENO:CONTENT string, eg. \" 16:foo\".
8639 Optional `target-file' attribute is a name of target file.
8641 Optional `before-jump-hook' attribute is a function with no
8642 arguments which is called before jumping to position.
8644 Optional `after-jump-hook' attribute is a function with no
8645 arguments which is called after jumping to position.
8647 If `adjust' attribute is specified, searches the line whose
8648 content is CONTENT near the LINENO.
8650 If `recenter' attribute is specified, the line is displayed at
8651 the center of window, otherwise at the top of window.
8654 (define-anything-type-attribute 'file-line
8655 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
8656 (multiline)
8657 (action ("Go to" . anything-c-action-file-line-goto)))
8658 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
8660 Optional `default-directory' attribute is a default-directory
8661 FILENAME is interpreted.
8663 Optional `before-jump-hook' attribute is a function with no
8664 arguments which is called before jumping to position.
8666 Optional `after-jump-hook' attribute is a function with no
8667 arguments which is called after jumping to position.
8669 If `adjust' attribute is specified, searches the line whose
8670 content is CONTENT near the LINENO.
8672 If `recenter' attribute is specified, the line is displayed at
8673 the center of window, otherwise at the top of window.
8676 (define-anything-type-attribute 'timer
8677 '((real-to-display . anything-c-timer-real-to-display)
8678 (action ("Cancel Timer" . cancel-timer)
8679 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
8680 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
8681 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
8682 (persistent-help . "Describe Function"))
8683 "Timer.")
8685 ;;;; Default `anything-sources'
8686 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
8687 ;; tend to invoke M-x anything directly. So I offer default setting.
8688 (setq anything-sources
8689 '(anything-c-source-buffers+
8690 anything-c-source-recentf
8691 anything-c-source-files-in-current-dir+))
8693 ;;;; unit test
8694 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
8695 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
8696 (dont-compile
8697 (when (fboundp 'expectations)
8698 (expectations
8699 (desc "candidates-file plug-in")
8700 (expect '(anything-p-candidats-file-init)
8701 (assoc-default 'init
8702 (car (anything-compile-sources
8703 '(((name . "test")
8704 (candidates-file . "test.txt")))
8705 '(anything-compile-source--candidates-file)))))
8706 (expect '(anything-p-candidats-file-init
8707 (lambda () 1))
8708 (assoc-default 'init
8709 (car (anything-compile-sources
8710 '(((name . "test")
8711 (candidates-file . "test.txt")
8712 (init . (lambda () 1))))
8713 '(anything-compile-source--candidates-file)))))
8714 (expect '(anything-p-candidats-file-init
8715 (lambda () 1))
8716 (assoc-default 'init
8717 (car (anything-compile-sources
8718 '(((name . "test")
8719 (candidates-file . "test.txt")
8720 (init (lambda () 1))))
8721 '(anything-compile-source--candidates-file)))))
8722 ;; FIXME error
8723 ;; (desc "anything-c-source-buffers")
8724 ;; (expect '(("Buffers" ("foo" "curbuf")))
8725 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
8726 ;; (let ((anything-c-boring-buffer-regexp
8727 ;; (rx (or
8728 ;; (group bos " ")
8729 ;; "*anything"
8730 ;; ;; echo area
8731 ;; " *Echo Area" " *Minibuf"))))
8732 ;; (flet ((buffer-name (&optional x) x))
8733 ;; (anything-test-candidates 'anything-c-source-buffers))))
8734 (desc "anything-c-stringify")
8735 (expect "str1"
8736 (anything-c-stringify "str1"))
8737 (expect "str2"
8738 (anything-c-stringify 'str2))
8739 (desc "anything-c-symbolify")
8740 (expect 'sym1
8741 (anything-c-symbolify "sym1"))
8742 (expect 'sym2
8743 (anything-c-symbolify 'sym2))
8744 (desc "plug-in:default-action")
8745 (expect '(((action ("default" . default) ("original" . original))
8746 (default-action . ("default" . default))
8747 (action ("original" . original))))
8748 (anything-compile-sources
8749 '(((default-action . ("default" . default))
8750 (action ("original" . original))))
8751 '(anything-compile-source--default-action)))
8752 (expect '(((action ("a1" . a1) ("a2" . a2))
8753 (default-action . ("a1" . a1))
8754 (action ("a1" . a1) ("a2" . a2))))
8755 (anything-compile-sources
8756 '(((default-action . ("a1" . a1))
8757 (action ("a1" . a1) ("a2" . a2))))
8758 '(anything-compile-source--default-action)))
8759 (expect '(((action ("a2" . a2) ("a1" . a1))
8760 (default-action . ("a2" . a2))
8761 (action ("a1" . a1) ("a2" . a2))))
8762 (anything-compile-sources
8763 '(((default-action . ("a2" . a2))
8764 (action ("a1" . a1) ("a2" . a2))))
8765 '(anything-compile-source--default-action))))))
8767 (provide 'anything-config)
8769 ;;; Local Variables:
8770 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
8771 ;;; End:
8773 ;; How to save (DO NOT REMOVE!!)
8774 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
8775 ;;; anything-config.el ends here
8777 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
8778 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
8779 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
8780 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
8781 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
8782 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
8783 ;;; LocalWords: dotimes Thierry online vname
8784 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
8785 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
8786 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
8787 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
8788 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
8789 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
8790 ;;; LocalWords: startpos noselect dont desc