Merge branch 'master' of ssh://repo.or.cz/srv/git/anything-config
[anything-config.git] / anything-config.el
blob6c3a74e1f99f32c361de5b4a59799ce6e44326fc
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 ~ 2010, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009 ~ 2010, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009 ~ 2010, 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-register'
127 ;; Preconfigured `anything' for Emacs registers.
128 ;; `anything-man-woman'
129 ;; Preconfigured `anything' for Man and Woman pages.
130 ;; `anything-org-keywords'
131 ;; Preconfigured `anything' for org keywords.
132 ;; `anything-emms'
133 ;; Preconfigured `anything' for emms sources.
134 ;; `anything-eev-anchors'
135 ;; Preconfigured `anything' for eev anchors.
136 ;; `anything-bm-list'
137 ;; Preconfigured `anything' for visible bookmarks.
138 ;; `anything-timers'
139 ;; Preconfigured `anything' for timers.
140 ;; `anything-list-emacs-process'
141 ;; Preconfigured `anything' for emacs process.
142 ;; `anything-occur'
143 ;; Preconfigured Anything for Occur source.
144 ;; `anything-browse-code'
145 ;; Preconfigured anything to browse code.
146 ;; `anything-org-headlines'
147 ;; Preconfigured anything to show org headlines.
148 ;; `anything-kill-buffers'
149 ;; Preconfigured `anything' to kill buffer you selected.
150 ;; `anything-regexp'
151 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
152 ;; `anything-insert-buffer-name'
153 ;; Insert buffer name.
154 ;; `anything-insert-symbol'
155 ;; Insert current symbol.
156 ;; `anything-insert-selection'
157 ;; Insert current selection.
158 ;; `anything-show-buffer-only'
159 ;; [OBSOLETE] Only show sources about buffer.
160 ;; `anything-show-bbdb-only'
161 ;; [OBSOLETE] Only show sources about BBDB.
162 ;; `anything-show-locate-only'
163 ;; [OBSOLETE] Only show sources about Locate.
164 ;; `anything-show-info-only'
165 ;; [OBSOLETE] Only show sources about Info.
166 ;; `anything-show-imenu-only'
167 ;; [OBSOLETE] Only show sources about Imenu.
168 ;; `anything-show-files-only'
169 ;; [OBSOLETE] Only show sources about File.
170 ;; `anything-show-w3m-bookmarks-only'
171 ;; [OBSOLETE] Only show source about w3m bookmark.
172 ;; `anything-show-colors-only'
173 ;; [OBSOLETE] Only show source about color.
174 ;; `anything-show-kill-ring-only'
175 ;; [OBSOLETE] Only show source about kill ring.
176 ;; `anything-show-this-source-only'
177 ;; Only show this source.
178 ;; `anything-test-sources'
179 ;; List all anything sources for test.
180 ;; `anything-select-source'
181 ;; Select source.
182 ;; `anything-find-files-down-one-level'
183 ;; Go down one level like unix command `cd ..'.
184 ;; `anything-find-files'
185 ;; Preconfigured `anything' for anything implementation of `find-file'.
186 ;; `anything-write-file'
187 ;; Preconfigured `anything' providing completion for `write-file'.
188 ;; `anything-insert-file'
189 ;; Preconfigured `anything' providing completion for `insert-file'.
190 ;; `anything-dired-rename-file'
191 ;; Preconfigured `anything' to rename files from dired.
192 ;; `anything-dired-copy-file'
193 ;; Preconfigured `anything' to copy files from dired.
194 ;; `anything-dired-symlink-file'
195 ;; Preconfigured `anything' to symlink files from dired.
196 ;; `anything-dired-hardlink-file'
197 ;; Preconfigured `anything' to hardlink files from dired.
198 ;; `anything-dired-bindings'
199 ;; Replace usual dired commands `C' and `R' by anything ones.
200 ;; `anything-do-grep'
201 ;; Preconfigured anything for grep.
202 ;; `anything-c-grep-precedent-file'
203 ;; Go to precedent file in `anything-do-grep'.
204 ;; `anything-c-grep-next-or-prec-file'
205 ;; Go to next or precedent candidate file in anything grep buffer.
206 ;; `anything-filelist'
207 ;; Preconfigured `anything' to open files instantly.
208 ;; `anything-filelist+'
209 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
210 ;; `anything-M-x'
211 ;; Preconfigured `anything' for Emacs commands.
212 ;; `anything-manage-advice'
213 ;; Preconfigured `anything' to disable/enable function advices.
214 ;; `anything-bookmark-ext'
215 ;; Preconfigured `anything' for bookmark-extensions sources.
216 ;; `anything-simple-call-tree'
217 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
218 ;; `anything-mark-ring'
219 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
220 ;; `anything-global-mark-ring'
221 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
222 ;; `anything-all-mark-rings'
223 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
224 ;; `anything-yaoddmuse-cache-pages'
225 ;; Fetch the list of files on emacswiki and create cache file.
226 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
227 ;; Preconfigured `anything' to edit or view EmacsWiki page.
228 ;; `anything-yaoddmuse-emacswiki-post-library'
229 ;; Preconfigured `anything' to post library to EmacsWiki.
230 ;; `anything-eval-expression'
231 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
232 ;; `anything-eval-expression-with-eldoc'
233 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
234 ;; `anything-surfraw'
235 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
236 ;; `anything-call-source'
237 ;; Preconfigured `anything' to call anything source.
238 ;; `anything-call-source-from-anything'
239 ;; Call anything source within `anything' session.
240 ;; `anything-execute-anything-command'
241 ;; Preconfigured `anything' to execute preconfigured `anything'.
242 ;; `anything-create-from-anything'
243 ;; Run `anything-create' from `anything' as a fallback.
244 ;; `anything-create'
245 ;; Preconfigured `anything' to do many create actions from STRING.
246 ;; `anything-top'
247 ;; Preconfigured `anything' for top command.
248 ;; `anything-select-xfont'
249 ;; Preconfigured `anything' to select Xfont.
250 ;; `anything-world-time'
251 ;; Preconfigured `anything' to show world time.
252 ;; `anything-apt'
253 ;; Preconfigured `anything' : frontend of APT package manager.
254 ;; `anything-c-shell-command-if-needed'
255 ;; Not documented.
256 ;; `anything-c-run-external-command'
257 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
258 ;; `anything-ratpoison-commands'
259 ;; Preconfigured `anything' to execute ratpoison commands.
260 ;; `anything-c-set-variable'
261 ;; Set value to VAR interactively.
262 ;; `anything-c-adaptive-save-history'
263 ;; Save history information to file given by `anything-c-adaptive-history-file'.
265 ;; * User variables defined here:
266 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
267 ;; `anything-c-use-standard-keys'
268 ;; Default Value: nil
269 ;; `anything-c-adaptive-history-file'
270 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
271 ;; `anything-c-adaptive-history-length'
272 ;; Default Value: 50
273 ;; `anything-c-google-suggest-url'
274 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
275 ;; `anything-c-google-suggest-search-url'
276 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
277 ;; `anything-google-suggest-use-curl-p'
278 ;; Default Value: nil
279 ;; `anything-c-yahoo-suggest-url'
280 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
281 ;; `anything-c-yahoo-suggest-search-url'
282 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
283 ;; `anything-c-boring-buffer-regexp'
284 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
285 ;; `anything-c-boring-file-regexp'
286 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
287 ;; `anything-kill-ring-threshold'
288 ;; Default Value: 10
289 ;; `anything-su-or-sudo'
290 ;; Default Value: "su"
291 ;; `anything-for-files-prefered-list'
292 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
293 ;; `anything-create--actions-private'
294 ;; Default Value: nil
295 ;; `anything-allow-skipping-current-buffer'
296 ;; Default Value: t
297 ;; `anything-c-enable-eval-defun-hack'
298 ;; Default Value: t
299 ;; `anything-tramp-verbose'
300 ;; Default Value: 0
301 ;; `anything-raise-command'
302 ;; Default Value: nil
303 ;; `anything-command-map-prefix-key'
304 ;; Default Value: "<f5> a"
305 ;; `anything-c-find-files-show-icons'
306 ;; Default Value: t
307 ;; `anything-c-find-files-icons-directory'
308 ;; Default Value: "/usr/share/emacs/24.0.50/etc/images/tree-widget/default"
309 ;; `anything-c-browse-code-regexp-lisp'
310 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
311 ;; `anything-c-browse-code-regexp-python'
312 ;; Default Value: "\\<def\\>\\|\\<class\\>"
313 ;; `anything-c-browse-code-regexp-alist'
314 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
315 ;; `anything-c-external-programs-associations'
316 ;; Default Value: nil
317 ;; `anything-c-filelist-file-name'
318 ;; Default Value: nil
320 ;; * Anything sources defined here:
321 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
322 ;; `anything-c-source-regexp' (Regexp Builder)
323 ;; `anything-c-source-buffers' (Buffers)
324 ;; `anything-c-source-buffer-not-found' (Create buffer)
325 ;; `anything-c-source-buffers+' (Buffers)
326 ;; `anything-c-source-file-name-history' (File Name History)
327 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
328 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
329 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
330 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
331 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
332 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
333 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
334 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
335 ;; `anything-c-source-file-cache-initialized' ()
336 ;; `anything-c-source-file-cache' (File Cache)
337 ;; `anything-c-source-locate' (Locate)
338 ;; `anything-c-source-recentf' (Recentf)
339 ;; `anything-c-source-ffap-guesser' (File at point)
340 ;; `anything-c-source-ffap-line' (File/Lineno at point)
341 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
342 ;; `anything-c-source-filelist' (FileList)
343 ;; `anything-c-source-info-pages' (Info Pages)
344 ;; `anything-c-source-info-elisp' (Info index: elisp)
345 ;; `anything-c-source-info-cl' (Info index: cl)
346 ;; `anything-c-source-info-org' (Info index: org)
347 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
348 ;; `anything-c-source-info-zsh' (Info index: zsh)
349 ;; `anything-c-source-info-bash' (Info index: bash)
350 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
351 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
352 ;; `anything-c-source-info-find' (Info index: find)
353 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
354 ;; `anything-c-source-info-textutils' (Info index: textutils)
355 ;; `anything-c-source-info-libc' (Info index: libc)
356 ;; `anything-c-source-info-make' (Info index: make)
357 ;; `anything-c-source-info-automake' (Info index: automake)
358 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
359 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
360 ;; `anything-c-source-info-emacs' (Info index: emacs)
361 ;; `anything-c-source-info-elib' (Info index: elib)
362 ;; `anything-c-source-info-eieio' (Info index: eieio)
363 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
364 ;; `anything-c-source-info-guile' (Info index: guile)
365 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
366 ;; `anything-c-source-info-goops' (Info index: goops)
367 ;; `anything-c-source-info-screen' (Info index: screen)
368 ;; `anything-c-source-info-latex' (Info index: latex)
369 ;; `anything-c-source-info-gawk' (Info index: gawk)
370 ;; `anything-c-source-info-sed' (Info index: sed)
371 ;; `anything-c-source-info-m4' (Info index: m4)
372 ;; `anything-c-source-info-wget' (Info index: wget)
373 ;; `anything-c-source-info-binutils' (Info index: binutils)
374 ;; `anything-c-source-info-as' (Info index: as)
375 ;; `anything-c-source-info-bfd' (Info index: bfd)
376 ;; `anything-c-source-info-gprof' (Info index: gprof)
377 ;; `anything-c-source-info-ld' (Info index: ld)
378 ;; `anything-c-source-info-diff' (Info index: diff)
379 ;; `anything-c-source-info-flex' (Info index: flex)
380 ;; `anything-c-source-info-grep' (Info index: grep)
381 ;; `anything-c-source-info-gzip' (Info index: gzip)
382 ;; `anything-c-source-info-libtool' (Info index: libtool)
383 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
384 ;; `anything-c-source-info-info' (Info index: info)
385 ;; `anything-c-source-info-gdb' (Info index: gdb)
386 ;; `anything-c-source-info-stabs' (Info index: stabs)
387 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
388 ;; `anything-c-source-info-cvs' (Info index: cvs)
389 ;; `anything-c-source-info-bison' (Info index: bison)
390 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
391 ;; `anything-c-source-info-global' (Info index: global)
392 ;; `anything-c-source-man-pages' (Manual Pages)
393 ;; `anything-c-source-complex-command-history' (Complex Command History)
394 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
395 ;; `anything-c-source-emacs-commands' (Emacs Commands)
396 ;; `anything-c-source-lacarte' (Lacarte)
397 ;; `anything-c-source-emacs-functions' (Emacs Functions)
398 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
399 ;; `anything-c-source-advice' (Function Advice)
400 ;; `anything-c-source-emacs-variables' (Emacs Variables)
401 ;; `anything-c-source-bookmarks' (Bookmarks)
402 ;; `anything-c-source-bookmark-set' (Set Bookmark)
403 ;; `anything-c-source-bm' (Visible Bookmarks)
404 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
405 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
406 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
407 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
408 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
409 ;; `anything-c-source-bookmark-images' (Bookmark Images)
410 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
411 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
412 ;; `anything-c-source-bookmark-info' (Bookmark Info)
413 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
414 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
415 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
416 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
417 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
418 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
419 ;; `anything-c-source-imenu' (Imenu)
420 ;; `anything-c-source-ctags' (Exuberant ctags)
421 ;; `anything-c-source-semantic' (Semantic Tags)
422 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
423 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
424 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
425 ;; `anything-c-source-customize-face' (Customize Face)
426 ;; `anything-c-source-colors' (Colors)
427 ;; `anything-c-source-tracker-search' (Tracker Search)
428 ;; `anything-c-source-mac-spotlight' (mdfind)
429 ;; `anything-c-source-kill-ring' (Kill Ring)
430 ;; `anything-c-source-mark-ring' (mark-ring)
431 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
432 ;; `anything-c-source-register' (Registers)
433 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
434 ;; `anything-c-source-rd-headline' (RD HeadLine)
435 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
436 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
437 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
438 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
439 ;; `anything-c-source-org-headline' (Org HeadLine)
440 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
441 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
442 ;; `anything-c-source-eev-anchor' (Anchors)
443 ;; `anything-c-source-org-keywords' (Org Keywords)
444 ;; `anything-c-source-picklist' (Picklist)
445 ;; `anything-c-source-bbdb' (BBDB)
446 ;; `anything-c-source-evaluation-result' (Evaluation Result)
447 ;; `anything-c-source-calculation-result' (Calculation Result)
448 ;; `anything-c-source-google-suggest' (Google Suggest)
449 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
450 ;; `anything-c-source-emms-streams' (Emms Streams)
451 ;; `anything-c-source-emms-dired' (Music Directory)
452 ;; `anything-c-source-emms-files' (Emms files)
453 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
454 ;; `anything-c-source-call-source' (Call anything source)
455 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
456 ;; `anything-c-source-occur' (Occur)
457 ;; `anything-c-source-browse-code' (Browse code)
458 ;; `anything-c-source-create' (Create)
459 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
460 ;; `anything-c-source-elscreen' (Elscreen)
461 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
462 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
463 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
464 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
465 ;; `anything-c-source-xfonts' (X Fonts)
466 ;; `anything-c-source-time-world' (Time World List)
467 ;; `anything-c-source-apt' (APT)
468 ;; `anything-c-source-gentoo' (Portage sources)
469 ;; `anything-c-source-use-flags' (Use Flags)
470 ;; `anything-c-source-emacs-process' (Emacs Process)
471 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
473 ;; *** END auto-documentation
476 ;;; Change log:
478 ;; Change log of this file is found at
479 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
481 ;; Change log of this project is found at
482 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
484 ;;; Contributors:
486 ;; Tamas Patrovics
487 ;; Tassilo Horn <tassilo@member.fsf.org>
488 ;; Vagn Johansen <gonz808@hotmail.com>
489 ;; Mathias Dahl <mathias.dahl@gmail.com>
490 ;; Bill Clementson <billclem@gmail.com>
491 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
492 ;; Drew Adams <drew.adams@oracle.com>
493 ;; Jason McBrayer <jmcbray@carcosa.net>
494 ;; Andy Stewart <lazycat.manatee@gmail.com>
495 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
496 ;; rubikitch <rubikitch@ruby-lang.org>
497 ;; Scott Vokes <vokes.s@gmail.com>
500 ;;; For Maintainers:
502 ;; Evaluate (autodoc-update-all) before commit. This function
503 ;; generates anything-c-source-* / functions / options list.
505 ;; Install also developer-tools/autodoc.el
506 ;; And eval it or run interactively.
508 ;; [EVAL IT] (autodoc-update-all)
510 ;; Please write details documentation about function, then others will
511 ;; read code more easier. -- Andy Stewart
515 ;;; TODO
517 ;; - Fix documentation, now many functions haven't documentations.
520 ;;; Require
521 (require 'anything)
522 (require 'thingatpt)
523 (require 'ffap)
524 (require 'cl)
526 ;;; Code:
528 ;; version check
529 (let ((version "1.263"))
530 (when (and (string= "1." (substring version 0 2))
531 (string-match "1\.\\([0-9]+\\)" anything-version)
532 (< (string-to-number (match-string 1 anything-version))
533 (string-to-number (substring version 2))))
534 (error "Please update anything.el!!
536 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
538 or M-x install-elisp-from-emacswiki anything.el")))
540 ;; compatibility
541 (unless (fboundp 'window-system)
542 (defun window-system (&optional arg)
543 window-system))
545 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
546 (defgroup anything-config nil
547 "Predefined configurations for `anything.el'."
548 :group 'anything)
550 (defcustom anything-c-use-standard-keys nil
551 "Whether use standard keybindings. (no effect)
553 Key definitions in anything-config.el are removed because
554 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
555 minibuffer history, C-s for isearch, etc.
557 If you use `iswitchb' with `anything',
558 evaluate (anything-iswitchb-setup) . Then some bindings that
559 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
560 history, are removed from `anything-map'. "
561 :type 'boolean
562 :group 'anything-config)
564 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
565 "Path of file where history information is stored."
566 :type 'string
567 :group 'anything-config)
569 (defcustom anything-c-adaptive-history-length 50
570 "Maximum number of candidates stored for a source."
571 :type 'number
572 :group 'anything-config)
574 (defcustom anything-c-google-suggest-url
575 "http://google.com/complete/search?output=toolbar&q="
576 "URL used for looking up Google suggestions."
577 :type 'string
578 :group 'anything-config)
580 (defcustom anything-c-google-suggest-search-url
581 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
582 "URL used for Google searching."
583 :type 'string
584 :group 'anything-config)
586 (defcustom anything-google-suggest-use-curl-p nil
587 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
588 Otherwise `url-retrieve-synchronously' is used."
589 :type 'boolean
590 :group 'anything-config)
592 (defcustom anything-c-yahoo-suggest-url
593 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
594 "Url used for looking up Yahoo suggestions."
595 :type 'string
596 :group 'anything-config)
598 (defcustom anything-c-yahoo-suggest-search-url
599 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
600 "Url used for Yahoo searching."
601 :type 'string
602 :group 'anything-config)
604 (defcustom anything-c-boring-buffer-regexp
605 (rx (or
606 (group bos " ")
607 ;; anything-buffer
608 "*anything"
609 ;; echo area
610 " *Echo Area" " *Minibuf"))
611 "The regexp that match boring buffers.
612 Buffer candidates matching this regular expression will be
613 filtered from the list of candidates if the
614 `anything-c-skip-boring-buffers' candidate transformer is used, or
615 they will be displayed with face `file-name-shadow' if
616 `anything-c-shadow-boring-buffers' is used."
617 :type 'string
618 :group 'anything-config)
619 ;; (string-match anything-c-boring-buffer-regexp "buf")
620 ;; (string-match anything-c-boring-buffer-regexp " hidden")
621 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
623 (defcustom anything-c-boring-file-regexp
624 (rx (or
625 ;; Boring directories
626 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
627 ;; Boring files
628 (and line-start ".#")
629 (and (or ".class" ".la" ".o" "~") eol)))
630 "The regexp that match boring files.
631 File candidates matching this regular expression will be
632 filtered from the list of candidates if the
633 `anything-c-skip-boring-files' candidate transformer is used, or
634 they will be displayed with face `file-name-shadow' if
635 `anything-c-shadow-boring-files' is used."
636 :type 'string
637 :group 'anything-config)
639 (defcustom anything-kill-ring-threshold 10
640 "*Minimum length to be listed by `anything-c-source-kill-ring'."
641 :type 'integer
642 :group 'anything-config)
644 (defcustom anything-su-or-sudo "su"
645 "What command to use for root access."
646 :type 'string
647 :group 'anything-config)
649 (defcustom anything-for-files-prefered-list
650 '(anything-c-source-ffap-line
651 anything-c-source-ffap-guesser
652 anything-c-source-buffers+
653 anything-c-source-recentf
654 anything-c-source-bookmarks
655 anything-c-source-file-cache
656 anything-c-source-files-in-current-dir+
657 anything-c-source-locate)
658 "Your prefered sources to find files."
659 :type 'list
660 :group 'anything-config)
662 (defcustom anything-create--actions-private nil
663 "User defined actions for `anything-create' / `anything-c-source-create'.
664 It is a list of (DISPLAY . FUNCTION) pairs like `action'
665 attribute of `anything-sources'.
667 It is prepended to predefined pairs."
668 :type 'list
669 :group 'anything-config)
671 (defcustom anything-allow-skipping-current-buffer t
672 "Show current buffer or not in anything buffer"
673 :type 'boolean
674 :group 'anything-config)
676 (defcustom anything-c-enable-eval-defun-hack t
677 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
678 This hack is invoked when pressing C-M-x in the form \
679 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
680 :type 'boolean
681 :group 'anything-config)
683 (defcustom anything-tramp-verbose 0
684 "*Just like `tramp-verbose' but specific to anything.
685 When set to 0 don't show tramp messages in anything.
686 If you want to have the default tramp messages set it to 3."
687 :type 'integer
688 :group 'anything-config)
690 (defcustom anything-raise-command nil
691 "*A shell command to jump to a window running specific program.
692 Need external program wmctrl.
693 This will be use with `format', so use something like \"wmctrl -xa %s\"."
694 :type 'string
695 :group 'anything-config)
697 (defun anything-set-anything-command-map-prefix-key (var key)
698 (when (boundp 'anything-command-map-prefix-key)
699 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
700 (setq anything-command-map-prefix-key key)
701 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
702 'anything-command-map))
704 (defcustom anything-command-map-prefix-key "<f5> a"
705 "*The prefix key for all `anything-command-map' commands.
707 !!WARNING!!
708 This default value is very likely to be changed,
709 because it is under discussion."
710 :type 'string
711 :set 'anything-set-anything-command-map-prefix-key
712 :group 'anything-config)
714 (defcustom anything-c-find-files-show-icons nil
715 "*Whether show or hide icons in `anything-find-files'."
716 :type 'boolean
717 :group 'anything-config)
719 (defcustom anything-c-find-files-icons-directory
720 (and (window-system)
721 (concat (car image-load-path) "tree-widget/default"))
722 "*Default path where to find files and directory icons."
723 :type 'string
724 :group 'anything-config)
726 (defcustom anything-c-browse-code-regexp-lisp
727 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
728 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
729 "*Regexp used to parse lisp buffer when browsing code."
730 :type 'string
731 :group 'anything-config)
733 (defcustom anything-c-browse-code-regexp-python
734 "\\<def\\>\\|\\<class\\>"
735 "*Regexp used to parse python buffer when browsing code."
736 :type 'string
737 :group 'anything-config)
739 (defcustom anything-c-browse-code-regexp-alist
740 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
741 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
742 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
743 (python-mode . ,anything-c-browse-code-regexp-python))
744 "*Alist to store regexps for browsing code corresponding \
745 to a specific `major-mode'."
746 :type 'list
747 :group 'anything-config)
749 (defcustom anything-c-external-programs-associations nil
750 "*Alist to store externals programs associated with file extension.
751 This variable overhide setting in .mailcap file.
752 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
753 :type 'list
754 :group 'anything-config)
756 ;;;###autoload
757 (defun anything-configuration ()
758 "Customize `anything'."
759 (interactive)
760 (customize-group "anything-config"))
762 ;;; Anything-command-map
763 ;;;###autoload
764 (defvar anything-command-map)
765 (define-prefix-command 'anything-command-map)
767 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
768 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
769 (define-key anything-command-map (kbd "e") 'anything-etags-maybe-at-point)
770 (define-key anything-command-map (kbd "l") 'anything-locate)
771 (define-key anything-command-map (kbd "s") 'anything-surfraw)
772 (define-key anything-command-map (kbd "r") 'anything-regexp)
773 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
774 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
775 (define-key anything-command-map (kbd "#") 'anything-emms)
776 (define-key anything-command-map (kbd "m") 'anything-man-woman)
777 (define-key anything-command-map (kbd "t") 'anything-top)
778 (define-key anything-command-map (kbd "i") 'anything-imenu)
779 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
780 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
781 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
782 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
783 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
784 (define-key anything-command-map (kbd "f") 'anything-for-files)
785 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
786 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
787 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
788 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
789 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
790 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
791 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
792 (define-key anything-command-map (kbd "c") 'anything-colors)
793 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
794 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
795 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
796 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
797 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
798 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers+)
799 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
800 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
801 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
803 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
804 ;; minibuffer-local-filename-must-match-map.
805 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
806 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
807 (dolist (map (list minibuffer-local-filename-completion-map
808 minibuffer-local-completion-map
809 minibuffer-local-must-match-filename-map
810 minibuffer-local-filename-must-match-map
811 minibuffer-local-map
812 minibuffer-local-isearch-map
813 minibuffer-local-must-match-map
814 minibuffer-local-ns-map))
815 (define-key map "\C-r" 'anything-minibuffer-history))
817 ;;; Menu
818 (easy-menu-define nil global-map
819 "`anything' menu"
820 '("Anything"
821 ["All anything commands" anything-execute-anything-command t]
822 ["Find any Files/Buffers" anything-for-files t]
823 "----"
824 ("Files:"
825 ["Find files" anything-find-files t]
826 ["Recent Files" anything-recentf t]
827 ["Locate" anything-locate t]
828 ["Bookmarks" anything-c-pp-bookmarks t])
829 ("Buffers:"
830 ["Find buffers" anything-buffers+ t])
831 ("Commands:"
832 ["Emacs Commands" anything-M-x t]
833 ["Externals Commands" anything-c-run-external-command t])
834 ("Info:"
835 ["Info at point" anything-info-at-point t]
836 ["Emacs Manual index" anything-info-emacs t])
837 ("Org:"
838 ["Org keywords" anything-org-keywords t]
839 ["Org headlines" anything-org-headlines t])
840 ("Tools:"
841 ["Occur" anything-occur t]
842 ["Grep" anything-do-grep t]
843 ["Browse Kill ring" anything-show-kill-ring t]
844 ["Browse register" anything-register t]
845 ["Browse code" anything-browse-code t]
846 ["Mark Ring" anything-all-mark-rings t]
847 ["Regexp handler" anything-regexp t]
848 ["Colors & Faces" anything-colors t]
849 ["Show xfonts" anything-select-xfont t]
850 ["Imenu" anything-imenu t]
851 ["Google Suggest" anything-google-suggest t]
852 ["Eval expression" anything-eval-expression-with-eldoc t]
853 ["Calcul expression" anything-calcul-expression t]
854 ["Man pages" anything-man-woman t]
855 ["Top externals process" anything-top t]
856 ["Emacs internals process" anything-list-emacs-process t])
857 "----"
858 ["Prefered Options" anything-configuration t]))
861 ;;; Documentation
862 ;; It is replaced by `anything-help'
863 (defun anything-c-describe-anything-bindings ()
864 "[OBSOLETE] Describe `anything' bindings."
865 (interactive)
866 (anything-run-after-quit
867 #'(lambda ()
868 (with-current-buffer (get-buffer-create "*Anything Help*")
869 (erase-buffer)
870 (insert
871 (substitute-command-keys
872 "The keys that are defined for `anything' are:
873 \\{anything-map}")))
874 (pop-to-buffer "*Anything Help*")
875 (goto-char (point-min)))))
877 ;; Use `describe-mode' key in `global-map'
878 ;; (dolist (k (where-is-internal 'describe-mode global-map))
879 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
881 ;;; Help message
882 (defun anything-c-list-preconfigured-anything ()
883 (loop with doc
884 with sym
885 for entry in (cdr (assoc
886 (file-truename (locate-library "anything-config"))
887 load-history))
888 if (and (consp entry)
889 (eq (car entry) 'defun)
890 (string-match "^Preconfigured.+$"
891 (setq doc (or (documentation (setq sym (cdr entry)))
892 ""))))
893 collect (cons sym (match-string 0 doc))))
895 (defun anything-c-format-preconfigured-anything ()
896 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
897 (anything-c-list-preconfigured-anything)))
899 (setq anything-help-message
900 (lambda ()
901 (concat
902 "\\<anything-map>"
903 "`anything' is QuickSilver-like candidate-selection framework.
905 Narrow the list by typing some pattern,
906 Multiple patterns are allowed by splitting by space.
907 Select with natural Emacs operations, choose with RET.
909 If you have any problems, press C-c C-x C-b!!
910 Feel free to send bug reports. I'll fix them.
911 The steps are described in the beginning of anything.el file.
913 == Basic Operations ==
914 C-p, Up: Previous Line
915 C-n, Down : Next Line
916 M-v, PageUp : Previous Page
917 C-v, PageDown : Next Page
918 Enter : Execute first (default) action / Select
919 M-< : First Line
920 M-> : Last Line
921 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
922 M-PageDown, C-M-v : Next Page (other-window)
924 Tab, C-i : Show action list
925 Left : Previous Source
926 Right, C-o : Next Source
927 C-k : Delete pattern
928 C-z : Persistent Action (Execute action with anything session kept)
929 C-c C-x C-b: Send a bug report
931 == Shortcuts For 2nd/3rd Action ==
932 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
933 \\[anything-select-3rd-action] : Execute 3rd Action
935 == Visible Marks ==
936 Visible marks store candidate. Some actions uses marked candidates.
938 \\[anything-toggle-visible-mark] : Toggle Visible Mark
939 \\[anything-prev-visible-mark] : Previous Mark
940 \\[anything-next-visible-mark] : Next Mark
942 == Miscellaneous Commands ==
943 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
944 \\[anything-quit-and-find-file] : Drop into `find-file'
945 \\[anything-delete-current-selection] : Delete Selected Item (visually)
946 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
947 \\[anything-yank-selection] : Yank Selected Item Into Pattern
948 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
949 \\[anything-force-update] : Recalculate And Redisplay Candidates
951 == Global Commands ==
952 \\<global-map>\\[anything-resume] revives last `anything' session.
953 It is very useful, so you should bind any key.
955 Single source is executed by \\[anything-call-source].
957 == Preconfigured `anything' ==
958 Preconfigured `anything' is commands that uses `anything' interface.
959 You can use them without configuration.
962 (apply 'concat (anything-c-format-preconfigured-anything))
964 Enjoy!")))
966 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
967 ;;;###autoload
968 (defun anything-mini ()
969 "Preconfigured `anything' lightweight version (buffer -> recentf)."
970 (interactive)
971 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf)
972 "*anything mini*"))
973 ;;;###autoload
974 (defun anything-for-files ()
975 "Preconfigured `anything' for opening files.
976 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
977 (interactive)
978 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
980 ;;;###autoload
981 (defun anything-recentf ()
982 "Preconfigured `anything' for `recentf'."
983 (interactive)
984 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
986 ;;;###autoload
987 (defun anything-info-at-point ()
988 "Preconfigured `anything' for searching info at point."
989 (interactive)
990 (anything '(anything-c-source-info-elisp
991 anything-c-source-info-cl
992 anything-c-source-info-pages)
993 (thing-at-point 'symbol) nil nil nil "*anything info*"))
995 ;;;###autoload
996 (defun anything-info-emacs ()
997 "Preconfigured anything for Emacs manual index."
998 (interactive)
999 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
1001 ;;;###autoload
1002 (defun anything-show-kill-ring ()
1003 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
1004 You may bind this command to M-y."
1005 (interactive)
1006 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
1008 ;;;###autoload
1009 (defun anything-minibuffer-history ()
1010 "Preconfigured `anything' for `minibuffer-history'."
1011 (interactive)
1012 (let ((enable-recursive-minibuffers t))
1013 (anything-other-buffer 'anything-c-source-minibuffer-history
1014 "*anything minibuffer-history*")))
1016 ;;;###autoload
1017 (defun anything-gentoo ()
1018 "Preconfigured `anything' for gentoo linux."
1019 (interactive)
1020 (anything-other-buffer '(anything-c-source-gentoo
1021 anything-c-source-use-flags)
1022 "*anything gentoo*"))
1024 ;;;###autoload
1025 (defun anything-imenu ()
1026 "Preconfigured `anything' for `imenu'."
1027 (interactive)
1028 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
1030 ;;;###autoload
1031 (defun anything-google-suggest ()
1032 "Preconfigured `anything' for google search with google suggest."
1033 (interactive)
1034 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
1036 ;;;###autoload
1037 (defun anything-yahoo-suggest ()
1038 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1039 (interactive)
1040 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
1042 ;;; Converted from anything-show-*-only
1043 ;;;###autoload
1044 (defun anything-for-buffers ()
1045 "Preconfigured `anything' for buffer."
1046 (interactive)
1047 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
1049 ;;;###autoload
1050 (defun anything-buffers+ ()
1051 "Enhanced preconfigured `anything' for buffer."
1052 (interactive)
1053 (anything-other-buffer 'anything-c-source-buffers+ "*anything buffers*"))
1055 ;;;###autoload
1056 (defun anything-bbdb ()
1057 "Preconfigured `anything' for BBDB.
1059 Needs BBDB.
1061 http://bbdb.sourceforge.net/"
1062 (interactive)
1063 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
1065 ;;;###autoload
1066 (defun anything-locate ()
1067 "Preconfigured `anything' for Locate.
1068 Note you can add locate command after entering pattern.
1069 See man locate for more infos."
1070 (interactive)
1071 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
1073 ;;;###autoload
1074 (defun anything-w3m-bookmarks ()
1075 "Preconfigured `anything' for w3m bookmark.
1077 Needs w3m and emacs-w3m.
1079 http://w3m.sourceforge.net/
1080 http://emacs-w3m.namazu.org/"
1081 (interactive)
1082 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1083 "*anything w3m bookmarks*"))
1085 ;;;###autoload
1086 (defun anything-firefox-bookmarks ()
1087 "Preconfigured `anything' for firefox bookmark.
1088 You will have to enable html bookmarks in firefox:
1089 open about:config in firefox and double click on this line to enable value \
1090 to true:
1092 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1094 You should have now:
1096 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1098 After closing firefox, you will be able to browse you bookmarks.
1100 (interactive)
1101 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1102 "*Anything Firefox*"))
1104 ;;;###autoload
1105 (defun anything-colors ()
1106 "Preconfigured `anything' for color."
1107 (interactive)
1108 (anything-other-buffer
1109 '(anything-c-source-colors anything-c-source-customize-face)
1110 "*anything colors*"))
1112 ;;;###autoload
1113 (defun anything-bookmarks ()
1114 "Preconfigured `anything' for bookmarks."
1115 (interactive)
1116 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
1118 ;;;###autoload
1119 (defun anything-c-pp-bookmarks ()
1120 "Preconfigured `anything' for bookmarks (pretty-printed)."
1121 (interactive)
1122 (anything-other-buffer '(anything-c-source-bookmarks-local
1123 anything-c-source-bookmarks-su
1124 anything-c-source-bookmarks-ssh)
1125 "*anything pp bookmarks*"))
1127 ;;;###autoload
1128 (defun anything-register ()
1129 "Preconfigured `anything' for Emacs registers."
1130 (interactive)
1131 (anything-other-buffer 'anything-c-source-register "*anything register*"))
1133 ;;;###autoload
1134 (defun anything-man-woman ()
1135 "Preconfigured `anything' for Man and Woman pages."
1136 (interactive)
1137 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
1139 ;;;###autoload
1140 (defun anything-org-keywords ()
1141 "Preconfigured `anything' for org keywords."
1142 (interactive)
1143 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
1145 ;;;###autoload
1146 (defun anything-emms ()
1147 "Preconfigured `anything' for emms sources."
1148 (interactive)
1149 (anything '(anything-c-source-emms-streams
1150 anything-c-source-emms-files
1151 anything-c-source-emms-dired)
1152 nil nil nil nil
1153 "*Anything Emms*"))
1155 ;;;###autoload
1156 (defun anything-eev-anchors ()
1157 "Preconfigured `anything' for eev anchors."
1158 (interactive)
1159 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
1161 ;;;###autoload
1162 (defun anything-bm-list ()
1163 "Preconfigured `anything' for visible bookmarks.
1165 Needs bm.el
1167 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1168 (interactive)
1169 (let ((anything-outline-using t))
1170 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
1172 ;;;###autoload
1173 (defun anything-timers ()
1174 "Preconfigured `anything' for timers."
1175 (interactive)
1176 (anything-other-buffer '(anything-c-source-absolute-time-timers
1177 anything-c-source-idle-time-timers)
1178 "*anything timers*"))
1180 ;;;###autoload
1181 (defun anything-list-emacs-process ()
1182 "Preconfigured `anything' for emacs process."
1183 (interactive)
1184 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
1186 ;;;###autoload
1187 (defun anything-occur ()
1188 "Preconfigured Anything for Occur source."
1189 (interactive)
1190 (let ((anything-compile-source-functions
1191 ;; rule out anything-match-plugin because the input is one regexp.
1192 (delq 'anything-compile-source--match-plugin
1193 (copy-sequence anything-compile-source-functions))))
1194 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
1196 ;;;###autoload
1197 (defun anything-browse-code ()
1198 "Preconfigured anything to browse code."
1199 (interactive)
1200 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
1202 ;;;###autoload
1203 (defun anything-org-headlines ()
1204 "Preconfigured anything to show org headlines."
1205 (interactive)
1206 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
1208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1209 ;;; kill buffers
1210 ;;;###autoload
1211 (defun anything-kill-buffers ()
1212 "Preconfigured `anything' to kill buffer you selected."
1213 (interactive)
1214 (anything
1215 '(((name . "Kill Buffers")
1216 (candidates . anything-c-buffer-list)
1217 (action
1218 ("Kill Buffer" . (lambda (candidate)
1219 (kill-buffer candidate)
1220 (anything-kill-buffers)
1221 )))))
1222 nil nil))
1224 ;;; Regexp
1225 (defun anything-c-query-replace-regexp (candidate)
1226 (let ((regexp (funcall (anything-attr 'regexp))))
1227 (apply 'query-replace-regexp
1228 (anything-c-query-replace-args regexp))))
1230 (defun anything-c-kill-regexp-as-sexp (candidate)
1231 (anything-c-regexp-kill-new
1232 (prin1-to-string (funcall (anything-attr 'regexp)))))
1234 (defun anything-c-kill-regexp (candidate)
1235 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
1237 (defun anything-c-query-replace-args (regexp)
1238 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1239 (let ((region-only (anything-region-active-p)))
1240 (list
1241 regexp
1242 (query-replace-read-to regexp
1243 (format "Query replace %s regexp %s"
1244 (if anything-current-prefix-arg "word " "")
1245 (if region-only "in region " ""))
1247 anything-current-prefix-arg
1248 (when region-only (region-beginning))
1249 (when region-only (region-end)))))
1251 (defvar anything-c-source-regexp
1252 '((name . "Regexp Builder")
1253 (init . (lambda ()
1254 (anything-candidate-buffer anything-current-buffer)))
1255 (candidates-in-buffer)
1256 (get-line . anything-c-regexp-get-line)
1257 (persistent-action . anything-c-regexp-persistent-action)
1258 (persistent-help . "Show this line")
1259 (multiline)
1260 (delayed)
1261 (requires-pattern . 2)
1262 (mode-line . "Press TAB to select action.")
1263 ;; RUBIKITCH:
1264 ;; I use here `anything-input' because `anything-pattern' is lost when
1265 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1266 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1267 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1268 ;; Can you fix it?
1269 (regexp . (lambda () anything-input))
1270 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
1271 ("Query Replace Regexp" . anything-c-query-replace-regexp)
1272 ("Kill Regexp" . anything-c-kill-regexp)))))
1274 (defun anything-c-regexp-get-line (s e)
1275 (propertize
1276 (apply 'concat
1277 ;; Line contents
1278 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
1279 ;; subexps
1280 (loop for i from 0 to (1- (/ (length (match-data)) 2))
1281 collect (format "\n %s'%s'"
1282 (if (zerop i) "Group 0: " (format "Group %d: " i))
1283 (match-string i))))
1284 ;; match beginning
1285 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1286 ;; It is implementation problem of candidates-in-buffer.
1287 'anything-realvalue
1288 (1- s)))
1290 ;; Shut up byte compiler
1291 (defun anything-goto-line (numline)
1292 "Replacement of `goto-line'."
1293 (goto-char (point-min))
1294 (forward-line (1- numline)))
1296 (defun anything-c-regexp-persistent-action (pt)
1297 (goto-char pt)
1298 (anything-persistent-highlight-point))
1300 (defun anything-c-regexp-kill-new (input)
1301 (kill-new input)
1302 (message "Killed: %s" input))
1304 (defun anything-region-active-p ()
1305 (and transient-mark-mode mark-active (/= (mark) (point))))
1307 (defun* anything-current-buffer-narrowed-p (&optional
1308 (buffer anything-current-buffer))
1309 "Check if BUFFER is narrowed.
1310 Default is `anything-current-buffer'."
1311 (with-current-buffer buffer
1312 (let ((beg (point-min))
1313 (end (point-max))
1314 (total (buffer-size)))
1315 (or (/= beg 1) (/= end (1+ total))))))
1317 ;;;###autoload
1318 (defun anything-regexp ()
1319 "Preconfigured anything to build regexps and run query-replace-regexp \
1320 against."
1321 (interactive)
1322 (save-restriction
1323 (let ((anything-compile-source-functions
1324 ;; rule out anything-match-plugin because the input is one regexp.
1325 (delq 'anything-compile-source--match-plugin
1326 (copy-sequence anything-compile-source-functions))))
1327 (when (and (anything-region-active-p)
1328 ;; Don't narrow to region if buffer is already narrowed.
1329 (not (anything-current-buffer-narrowed-p)))
1330 (narrow-to-region (region-beginning) (region-end)))
1331 (anything :sources
1332 anything-c-source-regexp
1333 :buffer "*anything regexp*"
1334 :prompt "Regexp: "))))
1337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1339 (defun anything-insert-buffer-name ()
1340 "Insert buffer name."
1341 (interactive)
1342 (anything-insert-string
1343 (with-current-buffer anything-current-buffer
1344 (if buffer-file-name (file-name-nondirectory buffer-file-name)
1345 (buffer-name)))))
1347 (defun anything-insert-symbol ()
1348 "Insert current symbol."
1349 (interactive)
1350 (anything-insert-string
1351 (with-current-buffer anything-current-buffer
1352 (save-excursion
1353 (buffer-substring (beginning-of-thing 'symbol)
1354 (end-of-thing 'symbol))))))
1356 (defun anything-insert-selection ()
1357 "Insert current selection."
1358 (interactive)
1359 (anything-insert-string
1360 (with-current-buffer anything-current-buffer
1361 (anything-get-selection))))
1363 (defun anything-show-buffer-only ()
1364 "[OBSOLETE] Only show sources about buffer.
1365 Use `anything-for-buffers' instead."
1366 (interactive)
1367 (anything-set-source-filter '("Buffers")))
1369 (defun anything-show-bbdb-only ()
1370 "[OBSOLETE] Only show sources about BBDB.
1371 Use `anything-bbdb' instead."
1372 (interactive)
1373 (anything-set-source-filter '("BBDB")))
1375 (defun anything-show-locate-only ()
1376 "[OBSOLETE] Only show sources about Locate.
1377 Use `anything-locate' instead."
1378 (interactive)
1379 (anything-set-source-filter '("Locate")))
1381 (defun anything-show-info-only ()
1382 "[OBSOLETE] Only show sources about Info.
1383 Use `anything-info-at-point' instead."
1384 (interactive)
1385 (anything-set-source-filter '("Info Pages"
1386 "Info Elisp"
1387 "Info Common-Lisp")))
1389 (defun anything-show-imenu-only ()
1390 "[OBSOLETE] Only show sources about Imenu.
1391 Use `anything-imenu' instead."
1392 (interactive)
1393 (anything-set-source-filter '("Imenu")))
1395 (defun anything-show-files-only ()
1396 "[OBSOLETE] Only show sources about File.
1397 Use `anything-for-files' instead."
1398 (interactive)
1399 (anything-set-source-filter '("File Name History"
1400 "Files from Current Directory"
1401 "Recentf")))
1403 (defun anything-show-w3m-bookmarks-only ()
1404 "[OBSOLETE] Only show source about w3m bookmark.
1405 Use `anything-w3m-bookmarks' instead."
1406 (interactive)
1407 (anything-set-source-filter '("W3m Bookmarks")))
1409 (defun anything-show-colors-only ()
1410 "[OBSOLETE] Only show source about color.
1411 Use `anything-colors' instead."
1412 (interactive)
1413 (anything-set-source-filter '("Colors"
1414 "Customize Faces")))
1416 (defun anything-show-kill-ring-only ()
1417 "[OBSOLETE] Only show source about kill ring.
1418 Use `anything-show-kill-ring' instead."
1419 (interactive)
1420 (anything-set-source-filter '("Kill Ring")))
1422 (defun anything-show-this-source-only ()
1423 "Only show this source."
1424 (interactive)
1425 (setq anything-candidate-number-limit 9999)
1426 (anything-set-source-filter
1427 (list (assoc-default 'name (anything-get-current-source)))))
1429 (defun anything-test-sources ()
1430 "List all anything sources for test.
1431 The output is sexps which are evaluated by \\[eval-last-sexp]."
1432 (interactive)
1433 (with-output-to-temp-buffer "*Anything Test Sources*"
1434 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
1435 (apropos-internal "^anything-c-source" #'boundp))
1436 (pop-to-buffer standard-output)))
1438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1439 ;;; For compatibility
1440 (unless (fboundp 'region-active-p)
1441 (defun region-active-p ()
1442 "Return t if Transient Mark mode is enabled and the mark is active.
1444 Most commands that act on the region if it is active and
1445 Transient Mark mode is enabled, and on the text near point
1446 otherwise, should use `use-region-p' instead. That function
1447 checks the value of `use-empty-active-region' as well."
1448 (and transient-mark-mode mark-active)))
1450 (defun anything-nest (&rest same-as-anything)
1451 "Nested `anything'. If you use `anything' within `anything', use it."
1452 (with-selected-window (anything-window)
1453 (let (anything-current-position
1454 anything-current-buffer
1455 (orig-anything-buffer anything-buffer)
1456 anything-pattern
1457 anything-buffer
1458 anything-sources
1459 anything-compiled-sources
1460 anything-buffer-chars-modified-tick
1461 (anything-samewindow t)
1462 (enable-recursive-minibuffers t))
1463 (unwind-protect
1464 (apply #'anything same-as-anything)
1465 (anything-initialize-overlays orig-anything-buffer)
1466 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
1468 (defun anything-displaying-source-names ()
1469 "Display sources name."
1470 (with-current-buffer anything-buffer
1471 (goto-char (point-min))
1472 (loop with pos
1473 while (setq pos (next-single-property-change (point) 'anything-header))
1474 do (goto-char pos)
1475 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1476 do (forward-line 1))))
1478 (defun anything-select-source ()
1479 "Select source."
1480 (interactive)
1481 (let ((default (assoc-default 'name (anything-get-current-source)))
1482 (source-names (anything-displaying-source-names))
1483 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
1484 (anything-get-sources))))
1485 (setq anything-candidate-number-limit 9999)
1486 (anything-aif
1487 (let (anything-source-filter)
1488 (anything-nest '(((name . "Anything Source")
1489 (candidates . source-names)
1490 (action . identity))
1491 ((name . "Anything Source (ALL)")
1492 (candidates . all-source-names)
1493 (action . identity)))
1494 nil "Source: " nil
1495 default "*anything select source*"))
1496 (anything-set-source-filter (list it))
1497 (anything-set-source-filter nil))))
1499 (defun anything-insert-string (str)
1500 "Insert STR."
1501 (delete-minibuffer-contents)
1502 (insert str))
1504 (defun anything-c-match-on-file-name (candidate)
1505 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1506 (string-match anything-pattern (file-name-nondirectory candidate)))
1508 (defun anything-c-match-on-directory-name (candidate)
1509 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1510 (anything-aif (file-name-directory candidate)
1511 (string-match anything-pattern it)))
1513 (defun anything-c-string-match (candidate)
1514 "Return non-nil if `anything-pattern' match CANDIDATE.
1515 The match is done with `string-match'."
1516 (string-match anything-pattern candidate))
1518 ;; `anything-c-compose' is no more needed, it is for compatibility.
1519 (defalias 'anything-c-compose 'anything-compose)
1521 (defun anything-c-skip-entries (list regexp)
1522 "Remove entries which matches REGEXP from LIST."
1523 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
1524 list))
1526 (defun anything-c-shadow-entries (list regexp)
1527 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1528 (mapcar (lambda (file)
1529 ;; Add shadow face property to boring files.
1530 (let ((face (if (facep 'file-name-shadow)
1531 'file-name-shadow
1532 ;; fall back to default on XEmacs
1533 'default)))
1534 (if (string-match regexp file)
1535 (setq file (propertize file 'face face))))
1536 file)
1537 list))
1539 (defsubst anything-c-stringify (str-or-sym)
1540 "Get string of STR-OR-SYM."
1541 (if (stringp str-or-sym)
1542 str-or-sym
1543 (symbol-name str-or-sym)))
1545 (defsubst anything-c-symbolify (str-or-sym)
1546 "Get symbol of STR-OR-SYM."
1547 (if (symbolp str-or-sym)
1548 str-or-sym
1549 (intern str-or-sym)))
1551 (defun anything-c-describe-function (func)
1552 "FUNC is symbol or string."
1553 (describe-function (anything-c-symbolify func)))
1555 (defun anything-c-describe-variable (var)
1556 "VAR is symbol or string."
1557 (describe-variable (anything-c-symbolify var)))
1559 (defun anything-c-find-function (func)
1560 "FUNC is symbol or string."
1561 (find-function (anything-c-symbolify func)))
1563 (defun anything-c-find-variable (var)
1564 "VAR is symbol or string."
1565 (find-variable (anything-c-symbolify var)))
1567 (defun anything-c-kill-new (string &optional replace yank-handler)
1568 "STRING is symbol or string."
1569 (kill-new (anything-c-stringify string) replace yank-handler))
1571 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1572 ;; TODO: This should be integrated in anything.el instead of having
1573 ;; a defadvice here.
1575 (defvar anything-current-prefix-arg nil
1576 "Record `current-prefix-arg' when exiting minibuffer.
1577 It will be cleared at start of next `anything' call when \
1578 `anything-before-initialize-hook' is called.")
1580 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
1581 (unless anything-current-prefix-arg
1582 (setq anything-current-prefix-arg current-prefix-arg)))
1584 ;; using this hook instead of `anything-after-action-hook'
1585 ;; allow to record the prefix args and keep their values
1586 ;; when using `anything-comp-read'.
1587 (add-hook 'anything-before-initialize-hook
1588 (lambda () (setq anything-current-prefix-arg nil)))
1591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1592 (defadvice eval-defun (after anything-source-hack activate)
1593 "See `anything-c-enable-eval-defun-hack'."
1594 (when anything-c-enable-eval-defun-hack
1595 (let ((varsym (save-excursion
1596 (beginning-of-defun)
1597 (forward-char 1)
1598 (when (memq (read (current-buffer)) '(defvar setq))
1599 (read (current-buffer))))))
1600 (when (string-match "^anything-c-source-" (symbol-name varsym))
1601 (anything varsym)))))
1602 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1605 (defconst anything-c-create-summary-index-regexp
1606 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1607 (defun anything-c-create-summary ()
1608 "Create `anything' summary."
1609 (save-excursion
1610 (goto-char (point-min))
1611 (loop with it
1612 while (re-search-forward anything-c-create-summary-index-regexp nil t)
1613 collect
1614 (cond ((setq it (match-string-no-properties 1))
1615 (cons 'section it))
1616 ((setq it (match-string-no-properties 2))
1617 `(source ,it .
1618 ,(assoc-default 'name (symbol-value (intern it)))))
1619 ((setq it (match-string-no-properties 3))
1620 `(source ,it .
1621 ,(assoc-default 'name (symbol-value (intern it)))))))))
1623 ;; (find-epp (anything-c-create-summary))
1625 (defun anything-c-insert-summary ()
1626 "Insert `anything' summary."
1627 (save-excursion
1628 (goto-char (point-min))
1629 (search-forward ";; Below are complete source list you can setup in")
1630 (forward-line 1)
1631 (delete-region (point)
1632 (progn (search-forward ";;; Change log:" nil t)
1633 (forward-line -1) (point)))
1634 (insert ";;\n")
1635 (loop with beg
1636 for (kind . value) in (anything-c-create-summary)
1637 for i from 0
1638 do (cond ((eq kind 'section)
1639 (unless (zerop i)
1640 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1641 (insert ";; " value ":\n")
1642 (setq beg (point)))
1644 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
1645 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
1646 ;; (anything-c-insert-summary)
1648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1649 ;;;; <Buffer>
1650 (defun anything-c-buffer-list ()
1651 "Return the list of names of buffers with boring buffers filtered out.
1652 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1653 The first buffer in the list will be the last recently used
1654 buffer that is not the current buffer."
1655 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1656 (append (cdr buffers) (list (car buffers)))))
1658 (defvar anything-c-source-buffers
1659 '((name . "Buffers")
1660 (candidates . anything-c-buffer-list)
1661 (type . buffer)))
1662 ;; (anything 'anything-c-source-buffers)
1664 (defvar anything-c-source-buffer-not-found
1665 '((name . "Create buffer")
1666 (dummy)
1667 (type . buffer)))
1668 ;; (anything 'anything-c-source-buffer-not-found)
1670 ;;; Buffers+
1671 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1672 "*Face used for directory headings in dired buffers."
1673 :group 'anything)
1675 (defface anything-file-name
1676 '((t (:foreground "Blue")))
1677 "*Face used for file names (without suffixes) in dired buffers."
1678 :group 'anything)
1680 (defface anything-dir-priv
1681 '((t (:foreground "DarkRed" :background "LightGray")))
1682 "*Face used for directory privilege indicator (d) in dired buffers."
1683 :group 'anything)
1685 (defvar anything-c-buffers-face1 'anything-dir-priv)
1686 (defvar anything-c-buffers-face2 'font-lock-type-face)
1687 (defvar anything-c-buffers-face3 'italic)
1688 (eval-when-compile (require 'dired))
1689 (defun anything-c-highlight-buffers (buffers)
1690 (require 'dired)
1691 (loop for i in buffers
1692 if (rassoc (get-buffer i) dired-buffers)
1693 collect (propertize i
1694 'face anything-c-buffers-face1
1695 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1696 if (buffer-file-name (get-buffer i))
1697 collect (propertize i
1698 'face anything-c-buffers-face2
1699 'help-echo (buffer-file-name (get-buffer i)))
1700 if (and (not (rassoc (get-buffer i) dired-buffers))
1701 (not (buffer-file-name (get-buffer i))))
1702 collect (propertize i
1703 'face anything-c-buffers-face3)))
1705 (defvar anything-c-source-buffers+
1706 '((name . "Buffers")
1707 (candidates . anything-c-buffer-list)
1708 (type . buffer)
1709 (candidate-transformer anything-c-skip-current-buffer
1710 anything-c-highlight-buffers
1711 anything-c-skip-boring-buffers)
1712 (persistent-action . anything-c-buffers+-persistent-action)
1713 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1715 (defun anything-c-buffers+-persistent-action (name)
1716 (flet ((kill (item)
1717 (with-current-buffer item
1718 (if (and (buffer-modified-p)
1719 (buffer-file-name (current-buffer)))
1720 (progn
1721 (save-buffer)
1722 (kill-buffer item))
1723 (kill-buffer item))))
1724 (goto (item)
1725 (switch-to-buffer item)))
1726 (if current-prefix-arg
1727 (progn
1728 (kill name)
1729 (anything-delete-current-selection))
1730 (goto name))))
1732 ;; (anything 'anything-c-source-buffers+)
1735 ;;;; <File>
1736 ;;; File name history
1737 (defvar anything-c-source-file-name-history
1738 '((name . "File Name History")
1739 (candidates . file-name-history)
1740 (match anything-c-match-on-file-name
1741 anything-c-match-on-directory-name)
1742 (type . file)))
1743 ;; (anything 'anything-c-source-file-name-history)
1745 ;;; Files in current dir
1746 (defvar anything-c-source-files-in-current-dir
1747 '((name . "Files from Current Directory")
1748 (candidates . (lambda ()
1749 (with-current-buffer anything-current-buffer
1750 (directory-files (anything-c-current-directory)))))
1751 ;; volatile is not needed, I think.
1752 (type . file)))
1753 ;; (anything 'anything-c-source-files-in-current-dir)
1755 (defvar anything-c-files-face1 'anything-dir-priv)
1756 (defvar anything-c-files-face2 'anything-file-name)
1757 (defun anything-c-highlight-files (files)
1758 (loop for i in files
1759 if (file-directory-p i)
1760 collect (propertize (file-name-nondirectory i)
1761 'face anything-c-files-face1
1762 'help-echo (expand-file-name i))
1763 else
1764 collect (propertize (file-name-nondirectory i)
1765 'face anything-c-files-face2
1766 'help-echo (expand-file-name i))))
1769 (defvar anything-c-source-files-in-current-dir+
1770 '((name . "Files from Current Directory")
1771 (candidates . (lambda ()
1772 (with-current-buffer anything-current-buffer
1773 (directory-files (anything-c-current-directory) t))))
1774 (candidate-transformer anything-c-highlight-files)
1775 ;; volatile is not needed, I think.
1776 (type . file)))
1778 ;; (anything 'anything-c-source-files-in-current-dir+)
1780 ;;; Anything replacement of file name completion for `find-file' and friends.
1782 (defvar anything-c-find-files-doc-header (format " (`%s':Go to precedent level)"
1783 (if window-system "C-." "C-l"))
1784 "*The doc that is inserted in the Name header of a find-files or dired source.")
1786 (defvar anything-c-source-find-files
1787 `((name . ,(concat "Find Files" anything-c-find-files-doc-header))
1788 ;; It is needed for filenames with capital letters
1789 (disable-shortcuts)
1790 (init . (lambda ()
1791 (setq ffap-newfile-prompt t)
1792 ;; This is needed when connecting with emacsclient -t
1793 ;; on remote host that have an anything started on a window-system.
1794 ;; i.e when `C-.' is already loaded.
1795 (unless window-system
1796 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))))
1797 (candidates . anything-find-files-get-candidates)
1798 (filtered-candidate-transformer anything-c-find-files-transformer)
1799 (persistent-action . anything-find-files-persistent-action)
1800 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
1801 (volatile)
1802 (action-transformer . anything-find-files-action-transformer)
1803 (action
1804 . ,(delq
1806 `(("Find File" . anything-c-find-file-or-marked)
1807 ("Find file in Dired" . anything-c-point-file-in-dired)
1808 ,(and (locate-library "elscreen")
1809 '("Find file in Elscreen" . anything-elscreen-find-file))
1810 ("Complete at point"
1811 . anything-c-insert-file-name-completion-at-point)
1812 ("Open file externally `C-u to choose'"
1813 . anything-c-open-file-externally)
1814 ("Grep File(s) `C-u Recurse'"
1815 . (lambda (candidate)
1816 (if anything-current-prefix-arg
1817 (anything-do-grep (anything-marked-candidates) 'recurse)
1818 (anything-do-grep (anything-marked-candidates)))))
1819 ("Eshell command on file(s)" . anything-find-files-eshell-command-on-file)
1820 ("Ediff File" . anything-find-files-ediff-files)
1821 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
1822 ("Delete File(s)" . anything-delete-marked-files)
1823 ("Copy file(s) `C-u to follow'" . anything-find-files-copy)
1824 ("Rename file(s) `C-u to follow'" . anything-find-files-rename)
1825 ("Symlink files(s) `C-u to follow'" . anything-find-files-symlink)
1826 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
1827 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
1828 ("Find file other window" . find-file-other-window)
1829 ("Find file other frame" . find-file-other-frame)
1830 ("Find file as root" . anything-find-file-as-root))))))
1831 ;; (anything 'anything-c-source-find-files)
1833 (defun anything-find-files-set-prompt-for-action (prompt files)
1834 "Set prompt for action in `anything-find-files'."
1835 (let ((len (length files)))
1836 (if (> len 1)
1837 (format "%s * %d Files to: " prompt len)
1838 (format "%s %s to: " prompt (car files)))))
1840 (defun anything-find-files-do-action (action)
1841 "Generic function for creating action from `anything-c-source-find-files'.
1842 ACTION must be an action supported by `anything-dired-action'."
1843 (let* ((ifiles (anything-marked-candidates))
1844 (buf anything-current-buffer)
1845 (prompt (anything-find-files-set-prompt-for-action
1846 (capitalize (symbol-name action)) ifiles))
1847 (parg anything-current-prefix-arg)
1848 (dest (anything-c-read-file-name
1849 prompt :initial-input anything-ff-default-directory))
1850 (win-conf (current-window-configuration)))
1851 (unwind-protect
1852 ;; Create temporarily a dired buffer to call dired functions.
1853 (with-current-buffer (dired anything-ff-default-directory)
1854 (let ((dir-buf (current-buffer)))
1855 (anything-dired-action
1856 dest :files ifiles :action action :follow parg)
1857 ;; If we have started in a dired buffer, don't kill it.
1858 (unless (eq dir-buf (get-buffer buf))
1859 (kill-buffer dir-buf))))
1860 (unless parg (set-window-configuration win-conf)))))
1862 (defun anything-find-files-copy (candidate)
1863 "Copy files from `anything-find-files'."
1864 (anything-find-files-do-action 'copy))
1866 (defun anything-find-files-rename (candidate)
1867 "Rename files from `anything-find-files'."
1868 (anything-find-files-do-action 'rename))
1870 (defun anything-find-files-symlink (candidate)
1871 "Symlink files from `anything-find-files'."
1872 (anything-find-files-do-action 'symlink))
1874 (defun anything-find-files-relsymlink (candidate)
1875 "Relsymlink files from `anything-find-files'."
1876 (anything-find-files-do-action 'relsymlink))
1878 (defun anything-find-files-hardlink (candidate)
1879 "Hardlink files from `anything-find-files'."
1880 (anything-find-files-do-action 'hardlink))
1882 (defun anything-find-files-byte-compile (candidate)
1883 "Byte compile elisp files from `anything-find-files'."
1884 (let ((files (anything-marked-candidates))
1885 (parg anything-current-prefix-arg))
1886 (loop for fname in files
1887 do (byte-compile-file fname parg))))
1889 (defun anything-find-files-load-files (candidate)
1890 "Load elisp files from `anything-find-files'."
1891 (let ((files (anything-marked-candidates)))
1892 (loop for fname in files
1893 do (load fname))))
1895 (defun anything-find-files-ediff-files (candidate)
1896 "Default action to ediff files in `anything-find-files'."
1897 (ediff-files
1898 candidate
1899 (anything-c-read-file-name
1900 (format "Ediff `%s' With File: " (file-name-nondirectory candidate)))))
1902 (defun anything-find-files-ediff-merge-files (candidate)
1903 "Default action to ediff merge files in `anything-find-files'."
1904 (ediff-merge-files
1905 candidate
1906 (anything-c-read-file-name
1907 (format "Ediff Merge `%s' With File: "
1908 (file-name-nondirectory candidate)))))
1910 (defvar eshell-command-aliases-list nil)
1911 (declare-function eshell-read-aliases-list "em-alias")
1912 (defun anything-find-files-eshell-command-on-file (candidate)
1913 "Run `eshell-command' on file CANDIDATE possibly with an eshell alias.
1914 NOTE:
1915 If `eshell' or `eshell-command' have not been run once, `eshell-command-aliases-list'
1916 will not be loaded first time you use this."
1917 (when (or eshell-command-aliases-list
1918 (y-or-n-p "Eshell is not loaded, run eshell-command without alias anyway? "))
1919 (and eshell-command-aliases-list (eshell-read-aliases-list))
1920 (let ((cand-list (anything-marked-candidates))
1921 (default-directory anything-ff-default-directory)
1922 (command (anything-comp-read
1923 "Command: "
1924 (loop for (a . c) in eshell-command-aliases-list
1925 when (string-match "\\$1$" (car c))
1926 collect a))))
1927 (loop
1928 for i in cand-list
1929 for com = (concat command " " (shell-quote-argument i))
1930 do (eshell-command com)))))
1932 (defun* anything-reduce-file-name (fname level &key unix-close expand)
1933 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1934 If LEVEL is positive reduce from end else from beginning.
1935 If UNIX-CLOSE is non--nil close filename with /.
1936 If EXPAND is non--nil expand-file-name."
1937 (let* ((exp-fname (expand-file-name fname))
1938 (fname-list (split-string (if (or (string= fname "~/") expand)
1939 exp-fname fname) "/" t))
1940 (len (length fname-list))
1941 (pop-list (if (< level 0)
1942 (subseq fname-list (* level -1))
1943 (subseq fname-list 0 (- len level))))
1944 (result (mapconcat 'identity pop-list "/"))
1945 (empty (string= result "")))
1946 (when unix-close (setq result (concat result "/")))
1947 (if (string-match "^~" result)
1948 (if (string= result "~/") "~/" result)
1949 (if (< level 0)
1950 (if empty "../" (concat "../" result))
1951 (cond ((eq system-type 'windows-nt)
1952 (if empty "c:/" result))
1953 (empty "/")
1955 (concat "/" result)))))))
1957 (defun anything-file-completion-source-p ()
1958 "Test if current source is a dired or find-files source."
1959 (let ((ff-sources '("Find Files" "Copy Files"
1960 "Rename Files" "Symlink Files"
1961 "Hardlink Files" "Write File"
1962 "Insert File" "Read file name"))
1963 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
1964 (catch 'break
1965 (dolist (i ff-sources)
1966 (when (equal cur-source (concat i anything-c-find-files-doc-header))
1967 (throw 'break t))))))
1969 (defun anything-find-files-down-one-level (arg)
1970 "Go down one level like unix command `cd ..'.
1971 If prefix numeric arg is given go ARG level down."
1972 (interactive "p")
1973 (when (anything-file-completion-source-p)
1974 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
1975 :unix-close t :expand t)))
1976 (with-selected-window (minibuffer-window)
1977 (delete-minibuffer-contents)
1978 (insert new-pattern)))))
1980 ;; `C-.' doesn't work in terms use `C-l' instead.
1981 (if window-system
1982 (define-key anything-map (kbd "C-.") 'anything-find-files-down-one-level)
1983 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))
1985 (defun anything-c-point-file-in-dired (file)
1986 "Put point on filename FILE in dired buffer."
1987 (dired (file-name-directory file))
1988 (dired-goto-file file))
1990 (defun anything-create-tramp-name (fname)
1991 "Build filename for `anything-pattern' like /su:: or /sudo::."
1992 (apply #'tramp-make-tramp-file-name
1993 (loop
1994 with v = (tramp-dissect-file-name fname)
1995 for i across v collect i)))
1997 (defvar anything-ff-default-directory nil)
1998 (defun anything-find-files-get-candidates ()
1999 "Create candidate list for `anything-c-source-find-files'."
2000 (let* ( ; Don't try to tramp connect before entering the second ":".
2001 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
2002 (path (cond ((string-match "^~" anything-pattern)
2003 (replace-match (getenv "HOME") nil t anything-pattern))
2004 ((string-match tramp-file-name-regexp anything-pattern)
2005 (let ((tramp-name (anything-create-tramp-name
2006 (match-string 0 anything-pattern))))
2007 (replace-match tramp-name nil t anything-pattern)))
2008 (t anything-pattern)))
2009 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
2010 (set-text-properties 0 (length path) nil path)
2011 (if (member 'anything-compile-source--match-plugin
2012 anything-compile-source-functions)
2013 (setq anything-pattern path)
2014 (setq anything-pattern (replace-regexp-in-string " " ".*" path)))
2015 (setq anything-ff-default-directory (if (string= anything-pattern "")
2016 (if (eq system-type 'windows-nt) "c:/" "/")
2017 (file-name-directory path)))
2018 (cond ((or (file-regular-p path)
2019 (and (not (file-exists-p path)) (string-match "/$" path))
2020 (and ffap-url-regexp (string-match ffap-url-regexp path)))
2021 (list path))
2022 ((string= anything-pattern "") (directory-files "/" t))
2023 ((file-directory-p path) (directory-files path t))
2025 (append
2026 (list path)
2027 (directory-files (file-name-directory path) t))))))
2029 (defface anything-dired-symlink-face
2030 '((t (:foreground "DarkOrange")))
2031 "*Face used for symlinks in `anything-find-files'."
2032 :group 'anything)
2034 (defface anything-ffiles-prefix-face
2035 '((t (:background "yellow" :foreground "black")))
2036 "*Face used to prefix new file or url paths in `anything-find-files'."
2037 :group 'anything)
2039 (defun anything-c-prefix-filename (fname &optional image)
2040 "Return fname FNAME prefixed with icon IMAGE."
2041 (let* ((img-name (and image (expand-file-name
2042 image anything-c-find-files-icons-directory)))
2043 (img (and image (create-image img-name)))
2044 (prefix-img (and image (propertize " " 'display img)))
2045 (prefix-new (propertize
2046 " " 'display
2047 (propertize "[?]" 'face 'anything-ffiles-prefix-face)))
2048 (prefix-url (propertize
2049 " " 'display
2050 (propertize "[@]" 'face 'anything-ffiles-prefix-face))))
2051 (cond ((or (file-exists-p fname)
2052 (file-symlink-p fname))
2053 (if image (concat prefix-img fname) fname))
2054 ((string-match ffap-url-regexp fname) (concat prefix-url " " fname))
2055 (t (concat prefix-new " " fname)))))
2057 (defun anything-c-find-files-transformer (files sources)
2058 "Selector of transformer to use for `anything-c-source-find-files'."
2059 (if (and (window-system) anything-c-find-files-show-icons)
2060 (anything-c-highlight-ffiles1 files sources)
2061 (anything-c-highlight-ffiles files sources)))
2063 (defun anything-c-highlight-ffiles (files sources)
2064 "Candidate transformer for `anything-c-source-find-files' without icons."
2065 (loop for i in files
2066 collect (cond ((file-symlink-p i)
2067 (cons
2068 (anything-c-prefix-filename
2069 (propertize i 'face 'anything-dired-symlink-face
2070 'help-echo (file-truename i)))
2072 ((file-directory-p i)
2073 (cons
2074 (anything-c-prefix-filename
2075 (propertize i 'face anything-c-files-face1))
2078 (cons
2079 (anything-c-prefix-filename
2080 (propertize i 'face anything-c-files-face2))
2081 i)))))
2083 (defsubst anything-c-highlight-ffiles1 (files sources)
2084 "Candidate transformer for `anything-c-source-find-files' that show icons."
2085 (loop for i in files
2086 for af = (file-name-nondirectory i)
2087 collect (cond ( ;; Files.
2088 (eq nil (car (file-attributes i)))
2089 (cons (anything-c-prefix-filename
2090 (propertize i 'face anything-c-files-face2)
2091 "leaf.xpm")
2093 ( ;; Empty directories.
2094 (and (eq t (car (file-attributes i)))
2095 ;; Be sure to have permission to list content.
2096 (file-readable-p i)
2097 (eq 0 (length
2098 (directory-files
2099 i nil directory-files-no-dot-files-regexp t))))
2100 (cons (anything-c-prefix-filename
2101 (propertize i 'face anything-c-files-face1)
2102 "empty.xpm")
2104 ( ;; Open directories.
2105 (and (eq t (car (file-attributes i))) (get-buffer af))
2106 (cons (anything-c-prefix-filename
2107 (propertize i 'face anything-c-files-face1)
2108 "open.xpm")
2110 (;; Closed directories.
2111 (eq t (car (file-attributes i)))
2112 (cons (anything-c-prefix-filename
2113 (propertize i 'face anything-c-files-face1)
2114 "close.xpm")
2116 ( ;; Open Symlinks directories.
2117 (and (stringp (car (file-attributes i)))
2118 (file-directory-p i) (get-buffer af))
2119 (cons (anything-c-prefix-filename
2120 (propertize i 'face 'anything-dired-symlink-face
2121 'help-echo (file-truename i)) "open.xpm")
2123 ( ;; Closed Symlinks directories.
2124 (and (stringp (car (file-attributes i))) (file-directory-p i))
2125 (cons (anything-c-prefix-filename
2126 (propertize i 'face 'anything-dired-symlink-face
2127 'help-echo (file-truename i)) "close.xpm")
2129 ( ;; Files symlinks.
2130 (stringp (car (file-attributes i)))
2131 (cons (anything-c-prefix-filename
2132 (propertize i 'face 'anything-dired-symlink-face
2133 'help-echo (file-truename i))
2134 "leaf.xpm")
2135 i)))))
2137 (defun anything-find-files-action-transformer (actions candidate)
2138 "Action transformer for `anything-c-source-find-files'."
2139 (cond ((with-current-buffer anything-current-buffer (eq major-mode 'message-mode))
2140 (append actions '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))))
2141 ((string-match (image-file-name-regexp) candidate)
2142 (append actions
2143 '(("Rotate image right" . anything-ff-rotate-image-right)
2144 ("Rotate image left" . anything-ff-rotate-image-left))))
2145 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
2146 (car it) candidate))
2147 (append actions '(("Byte compile lisp file(s) `C-u to load'"
2148 . anything-find-files-byte-compile)
2149 ("Load File(s)" . anything-find-files-load-files))))
2150 ((and (string-match "\.html$" candidate)
2151 (file-exists-p candidate))
2152 (append actions '(("Browse url file" . browse-url-of-file))))
2153 (t actions)))
2155 (defun anything-ff-gnus-attach-files (candidate)
2156 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
2157 (let ((flist (anything-marked-candidates)))
2158 (gnus-dired-attach flist)))
2160 (defun anything-ff-rotate-current-image1 (file &optional num-arg)
2161 "Rotate current image at NUM-ARG degrees."
2162 (if (executable-find "mogrify")
2163 (progn
2164 (shell-command (format "mogrify -rotate %s %s" (or num-arg 90) file))
2165 (when (buffer-live-p image-dired-display-image-buffer)
2166 (kill-buffer image-dired-display-image-buffer))
2167 (image-dired-display-image file)
2168 (message nil)
2169 (display-buffer (get-buffer image-dired-display-image-buffer)))
2170 (error "mogrify not found")))
2172 (defun anything-ff-rotate-image-left (candidate)
2173 "Rotate image file CANDIDATE left.
2174 This affect directly file CANDIDATE."
2175 (anything-ff-rotate-current-image1 candidate -90))
2177 (defun anything-ff-rotate-image-right (candidate)
2178 "Rotate image file CANDIDATE right.
2179 This affect directly file CANDIDATE."
2180 (anything-ff-rotate-current-image1 candidate))
2182 (defun anything-find-files-persistent-action (candidate)
2183 "Open subtree CANDIDATE without quitting anything.
2184 If CANDIDATE is not a directory expand CANDIDATE filename.
2185 If CANDIDATE is alone, open file CANDIDATE filename.
2186 That's mean:
2187 First hit on C-z expand CANDIDATE second hit open file.
2188 If a prefix arg is given or `anything-follow-mode' is on open file."
2189 (let ((follow (buffer-local-value
2190 'anything-follow-mode
2191 (get-buffer-create anything-buffer))))
2192 (flet ((insert-in-minibuffer (fname)
2193 (with-selected-window (minibuffer-window)
2194 (unless follow
2195 (delete-minibuffer-contents)
2196 (set-text-properties 0 (length fname) nil fname)
2197 (insert fname)))))
2198 (cond ((and (file-directory-p candidate) (file-symlink-p candidate))
2199 (insert-in-minibuffer (file-name-as-directory
2200 (file-truename
2201 (expand-file-name candidate)))))
2202 ((file-directory-p candidate)
2203 (insert-in-minibuffer (file-name-as-directory
2204 (expand-file-name candidate))))
2205 ((file-symlink-p candidate)
2206 (insert-in-minibuffer (file-truename candidate)))
2208 ;; First hit on C-z expand CANDIDATE second hit open file.
2209 ;; If a prefix arg is given or `anything-follow-mode' is on, open file.
2210 (let ((new-pattern (anything-get-selection))
2211 (num-lines-buf (with-current-buffer anything-buffer
2212 (count-lines (point-min) (point-max)))))
2213 (if (and (> num-lines-buf 3) (not current-prefix-arg) (not follow))
2214 (insert-in-minibuffer new-pattern)
2215 (cond ((string-match (image-file-name-regexp) candidate)
2216 (when (buffer-live-p image-dired-display-image-buffer)
2217 (kill-buffer image-dired-display-image-buffer))
2218 (image-dired-display-image candidate)
2219 (message nil)
2220 (display-buffer image-dired-display-image-buffer))
2221 ;; Allow browsing archive on avfs fs.
2222 ;; Assume volume is already mounted with mountavfs.
2223 ((and anything-ff-avfs-directory
2224 (string-match anything-ff-avfs-directory
2225 (file-name-directory candidate))
2226 (anything-ff-file-compressed-p candidate))
2227 (insert-in-minibuffer (concat candidate "#")))
2228 (t (find-file candidate))))))))))
2230 (defvar anything-ff-avfs-directory nil
2231 "*The default avfs directory, usually '.avfs'.
2232 When this is set you will be able to expand archive filenames with `C-z'.
2233 See <http://sourceforge.net/projects/avf/>.")
2234 (defvar anything-ff-file-compressed-list '("gz" "bz2" "zip" "7z")
2235 "*Minimal list of compressed files extension.")
2236 (defun anything-ff-file-compressed-p (candidate)
2237 "Whether CANDIDATE is a compressed file or not."
2238 (member (file-name-extension candidate)
2239 anything-ff-file-compressed-list))
2241 (defun anything-c-insert-file-name-completion-at-point (candidate)
2242 "Insert file name completion at point."
2243 (if buffer-read-only
2244 (error "Error: Buffer `%s' is read-only" (buffer-name))
2245 (let* ((end (point))
2246 (guess (thing-at-point 'filename))
2247 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess)
2248 (string-match "^[^\~]" guess))))
2249 (set-text-properties 0 (length candidate) nil candidate)
2250 (if (and guess (not (string= guess "")) (string-match "^~\\|/.*" guess))
2251 (progn
2252 (search-backward guess (- (point) (length guess)))
2253 (delete-region (point) end)
2254 (if full-path-p
2255 (insert (expand-file-name candidate))
2256 (insert (abbreviate-file-name candidate))))
2257 (error "Aborting completion: No valid file name at point")))))
2259 ;;;###autoload
2260 (defun anything-find-files (&optional fname)
2261 "Preconfigured `anything' for anything implementation of `find-file'.
2262 In non--interactive use an argument FNAME can be used.
2263 This is the starting point for nearly all actions you can do on files."
2264 (interactive "i")
2265 (let ((anything-mp-highlight-delay nil))
2266 (anything :sources 'anything-c-source-find-files
2267 :input (or (and fname (expand-file-name fname))
2268 (anything-find-files-input
2269 (ffap-guesser)
2270 (thing-at-point 'filename)))
2271 :prompt "Find Files or Url: "
2272 :buffer "*Anything Find Files*")))
2274 (defun anything-c-current-directory ()
2275 "Return current-directory name at point.
2276 Useful in dired buffers when there is inserted subdirs."
2277 (if (eq major-mode 'dired-mode)
2278 (dired-current-directory)
2279 default-directory))
2281 (defun anything-find-files-input (fap tap)
2282 "Default input of `anything-find-files'."
2283 (let* ((def-dir (anything-c-current-directory))
2284 (lib (anything-find-library-at-point))
2285 (file-p (and fap (file-exists-p fap)
2286 (file-exists-p
2287 (file-name-directory (expand-file-name tap def-dir)))))
2288 (input (cond (lib)
2289 (file-p (expand-file-name tap def-dir))
2290 (t fap))))
2291 (or input (expand-file-name def-dir))))
2293 (defun anything-find-library-at-point ()
2294 "Try to find library path at point.
2295 Find inside `require' and `declare-function' sexp."
2296 (require 'find-func)
2297 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
2298 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
2299 (sexp (and beg-sexp end-sexp
2300 (buffer-substring-no-properties
2301 (1+ beg-sexp) (1- end-sexp)))))
2302 (ignore-errors
2303 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
2304 (find-library-name
2305 (replace-regexp-in-string
2306 "'\\|\)\\|\(" ""
2307 ;; If require use third arg, ignore it,
2308 ;; always use library path found in `load-path'.
2309 (second (split-string (match-string 0 sexp))))))
2310 ((and sexp (string-match-p "^declare-function" sexp))
2311 (find-library-name
2312 (replace-regexp-in-string
2313 "\"\\|ext:" ""
2314 (third (split-string sexp)))))
2315 (t nil)))))
2317 ;;; Anything completion for `write-file'.==> C-x C-w
2318 (defvar anything-c-source-write-file
2319 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
2320 ;; It is needed for filenames with capital letters
2321 (disable-shortcuts)
2322 (candidates . anything-find-files-get-candidates)
2323 (filtered-candidate-transformer anything-c-find-files-transformer)
2324 (persistent-action . anything-find-files-persistent-action)
2325 (persistent-help . "Expand Candidate")
2326 (volatile)
2327 (action .
2328 (("Write File" . (lambda (candidate)
2329 (write-file candidate 'confirm)))))))
2331 ;;;###autoload
2332 (defun anything-write-file ()
2333 "Preconfigured `anything' providing completion for `write-file'."
2334 (interactive)
2335 (anything 'anything-c-source-write-file
2336 (expand-file-name default-directory)
2337 "Write buffer to file: " nil nil "*Anything write file*"))
2339 ;;; Anything completion for `insert-file'.==> C-x i
2340 (defvar anything-c-source-insert-file
2341 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
2342 ;; It is needed for filenames with capital letters
2343 (disable-shortcuts)
2344 (candidates . anything-find-files-get-candidates)
2345 (filtered-candidate-transformer anything-c-find-files-transformer)
2346 (persistent-action . anything-find-files-persistent-action)
2347 (persistent-help . "Expand Candidate")
2348 (volatile)
2349 (action .
2350 (("Insert File" . (lambda (candidate)
2351 (when (y-or-n-p (format "Really insert %s in %s "
2352 candidate anything-current-buffer))
2353 (insert-file-contents candidate))))))))
2355 ;;;###autoload
2356 (defun anything-insert-file ()
2357 "Preconfigured `anything' providing completion for `insert-file'."
2358 (interactive)
2359 (anything 'anything-c-source-insert-file
2360 (expand-file-name default-directory)
2361 "Insert file: " nil nil "*Anything insert file*"))
2363 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2364 (defvar anything-c-source-copy-files
2365 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
2366 ;; It is needed for filenames with capital letters
2367 (disable-shortcuts)
2368 (candidates . anything-find-files-get-candidates)
2369 (filtered-candidate-transformer anything-c-find-files-transformer)
2370 (persistent-action . anything-find-files-persistent-action)
2371 (persistent-help . "Expand Candidate")
2372 (volatile)
2373 (action .
2374 (("Copy File"
2375 . (lambda (candidate)
2376 (anything-dired-action candidate :action 'copy)))
2377 ("Copy and Follow"
2378 . (lambda (candidate)
2379 (anything-dired-action candidate :action 'copy :follow t)))))))
2382 (defvar anything-c-source-rename-files
2383 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
2384 ;; It is needed for filenames with capital letters
2385 (disable-shortcuts)
2386 (candidates . anything-find-files-get-candidates)
2387 (filtered-candidate-transformer anything-c-find-files-transformer)
2388 (persistent-action . anything-find-files-persistent-action)
2389 (persistent-help . "Expand Candidate")
2390 (volatile)
2391 (action .
2392 (("Rename File"
2393 . (lambda (candidate)
2394 (anything-dired-action candidate :action 'rename)))
2395 ("Rename and Follow"
2396 . (lambda (candidate)
2397 (anything-dired-action candidate :action 'rename :follow t)))))))
2399 (defvar anything-c-source-symlink-files
2400 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
2401 ;; It is needed for filenames with capital letters
2402 (disable-shortcuts)
2403 (candidates . anything-find-files-get-candidates)
2404 (filtered-candidate-transformer anything-c-find-files-transformer)
2405 (persistent-action . anything-find-files-persistent-action)
2406 (persistent-help . "Expand Candidate")
2407 (volatile)
2408 (action
2409 . (("Symlink File"
2410 . (lambda (candidate)
2411 (anything-dired-action candidate :action 'symlink)))
2412 ("RelSymlink File"
2413 . (lambda (candidate)
2414 (anything-dired-action candidate :action 'relsymlink)))))))
2417 (defvar anything-c-source-hardlink-files
2418 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
2419 ;; It is needed for filenames with capital letters
2420 (disable-shortcuts)
2421 (candidates . anything-find-files-get-candidates)
2422 (filtered-candidate-transformer anything-c-find-files-transformer)
2423 (persistent-action . anything-find-files-persistent-action)
2424 (persistent-help . "Expand Candidate")
2425 (volatile)
2426 (action
2427 . (("Hardlink File"
2428 . (lambda (candidate)
2429 (anything-dired-action candidate :action 'hardlink)))))))
2432 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
2433 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2434 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2435 (let ((fn (case action
2436 ('copy 'dired-copy-file)
2437 ('rename 'dired-rename-file)
2438 ('symlink 'make-symbolic-link)
2439 ('relsymlink 'dired-make-relative-symlink)
2440 ('hardlink 'dired-hardlink)))
2441 (marker (case action
2442 ((copy rename) dired-keep-marker-copy)
2443 ('symlink dired-keep-marker-symlink)
2444 ('relsymlink dired-keep-marker-relsymlink)
2445 ('hardlink dired-keep-marker-hardlink))))
2446 (dired-create-files
2447 fn (symbol-name action) files
2448 (if (file-directory-p candidate)
2449 ;; When CANDIDATE is a directory, build file-name in this directory.
2450 ;; Else we use CANDIDATE.
2451 #'(lambda (from)
2452 (expand-file-name (file-name-nondirectory from) candidate))
2453 #'(lambda (from) candidate))
2454 marker)
2455 (when follow
2456 (let* ((moved-flist (anything-get-dest-fnames-from-list files candidate))
2457 (fname (car moved-flist)))
2458 (unwind-protect
2459 (progn
2460 (setq anything-ff-cand-to-mark moved-flist)
2461 (anything-find-files candidate))
2462 (setq anything-ff-cand-to-mark nil))))))
2464 ;; Internal
2465 (defvar anything-ff-cand-to-mark nil)
2467 (defun anything-get-dest-fnames-from-list (flist dest-cand)
2468 "Transform filenames of FLIST to abs of DEST-CAND."
2469 (loop
2470 with dest = (expand-file-name dest-cand)
2471 for src in flist
2472 for basename-src = (if (file-directory-p src)
2473 (file-relative-name
2474 (directory-file-name src)
2475 (file-name-directory src))
2476 (file-name-nondirectory src))
2477 for fname = (if (file-directory-p dest)
2478 (concat (file-name-as-directory dest)
2479 basename-src)
2480 dest)
2481 collect fname into tmp-list
2482 finally return (sort tmp-list 'string<)))
2484 (defun anything-c-maybe-mark-candidates ()
2485 "Mark all candidates of list `anything-ff-cand-to-mark'."
2486 (when (and (string= (assoc-default 'name (anything-get-current-source))
2487 (assoc-default 'name anything-c-source-find-files))
2488 anything-ff-cand-to-mark)
2489 (with-anything-window
2490 (while anything-ff-cand-to-mark
2491 (if (search-forward (car anything-ff-cand-to-mark) (point-at-eol) t)
2492 (progn
2493 (call-interactively 'anything-toggle-visible-mark)
2494 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
2495 (call-interactively 'anything-next-line)))
2496 (unless (anything-this-visible-mark)
2497 (call-interactively 'anything-prev-visible-mark)))))
2499 (add-hook 'anything-after-update-hook #'anything-c-maybe-mark-candidates)
2502 (defun* anything-dired-do-action-on-file (&key action)
2503 (let* ((files (dired-get-marked-files))
2504 (len (length files))
2505 (fname (if (> len 1)
2506 (format "* %d Files" len)
2507 (car files)))
2508 (source (case action
2509 ('copy 'anything-c-source-copy-files)
2510 ('rename 'anything-c-source-rename-files)
2511 ('symlink 'anything-c-source-symlink-files)
2512 ('hardlink 'anything-c-source-hardlink-files)))
2513 (prompt-fm (case action
2514 ('copy "Copy %s to: ")
2515 ('rename "Rename %s to: ")
2516 ('symlink "Symlink %s to: ")
2517 ('hardlink "Hardlink %s to: ")))
2518 (buffer (case action
2519 ('copy "*Anything Copy Files*")
2520 ('rename "*Anything Rename Files*")
2521 ('symlink "*Anything Symlink Files*")
2522 ('hardlink "*Anything Hardlink Files*"))))
2523 (anything source
2524 (or (dired-dwim-target-directory)
2525 (expand-file-name (anything-c-current-directory)))
2526 (format prompt-fm fname) nil nil buffer)))
2529 ;;;###autoload
2530 (defun anything-dired-rename-file ()
2531 "Preconfigured `anything' to rename files from dired."
2532 (interactive)
2533 (anything-dired-do-action-on-file :action 'rename))
2535 ;;;###autoload
2536 (defun anything-dired-copy-file ()
2537 "Preconfigured `anything' to copy files from dired."
2538 (interactive)
2539 (anything-dired-do-action-on-file :action 'copy))
2541 ;;;###autoload
2542 (defun anything-dired-symlink-file ()
2543 "Preconfigured `anything' to symlink files from dired."
2544 (interactive)
2545 (anything-dired-do-action-on-file :action 'symlink))
2547 ;;;###autoload
2548 (defun anything-dired-hardlink-file ()
2549 "Preconfigured `anything' to hardlink files from dired."
2550 (interactive)
2551 (anything-dired-do-action-on-file :action 'hardlink))
2553 (defvar anything-dired-bindings nil)
2554 ;;;###autoload
2555 (defun anything-dired-bindings (&optional arg)
2556 "Replace usual dired commands `C' and `R' by anything ones.
2557 When call interactively toggle dired bindings and anything bindings.
2558 When call non--interactively with arg > 0, enable anything bindings.
2559 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2560 (interactive)
2561 (if (or (and arg (> arg 0)) (not anything-dired-bindings))
2562 ;; Replace dired bindings.
2563 (progn
2564 (substitute-key-definition
2565 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
2566 (substitute-key-definition
2567 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
2568 (substitute-key-definition
2569 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
2570 (substitute-key-definition
2571 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map)
2572 (setq anything-dired-bindings t))
2573 ;; Replace anything bindings.
2574 (substitute-key-definition
2575 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
2576 (substitute-key-definition
2577 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
2578 (substitute-key-definition
2579 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
2580 (substitute-key-definition
2581 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)
2582 (setq anything-dired-bindings nil)))
2584 (defun* anything-c-read-file-name (prompt
2585 &key
2586 (initial-input (expand-file-name default-directory))
2587 (buffer "*Anything Completions*")
2588 test
2589 (marked-candidates nil)
2590 (persistent-action 'anything-find-files-persistent-action)
2591 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
2592 "Anything `read-file-name' emulation.
2593 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2594 (when (get-buffer anything-action-buffer)
2595 (kill-buffer anything-action-buffer))
2596 (let ((anything-mp-highlight-delay nil))
2597 (flet ((action-fn (candidate)
2598 (if marked-candidates
2599 (anything-marked-candidates)
2600 (identity candidate))))
2601 (or (anything
2602 :sources
2603 `((name . ,(concat "Read file name" anything-c-find-files-doc-header))
2604 ;; It is needed for filenames with capital letters
2605 (disable-shortcuts)
2606 (candidates . (lambda ()
2607 (if test
2608 (loop with seq = (anything-find-files-get-candidates)
2609 for fname in seq when (funcall test fname)
2610 collect fname)
2611 (anything-find-files-get-candidates))))
2612 (filtered-candidate-transformer anything-c-find-files-transformer)
2613 (persistent-action . ,persistent-action)
2614 (persistent-help . ,persistent-help)
2615 (volatile)
2616 (action . ,'action-fn))
2617 :input initial-input
2618 :prompt prompt
2619 :resume 'noresume
2620 :buffer buffer)
2621 (keyboard-quit)))))
2623 ;;; File Cache
2624 (defvar anything-c-source-file-cache-initialized nil)
2626 (defvar anything-c-file-cache-files nil)
2628 (defvar anything-c-source-file-cache
2629 '((name . "File Cache")
2630 (init
2631 . (lambda ()
2632 (require 'filecache nil t)
2633 (unless anything-c-source-file-cache-initialized
2634 (setq anything-c-file-cache-files
2635 (loop for item in file-cache-alist append
2636 (destructuring-bind (base &rest dirs) item
2637 (loop for dir in dirs collect
2638 (concat dir base)))))
2639 (defadvice file-cache-add-file (after file-cache-list activate)
2640 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
2641 (setq anything-c-source-file-cache-initialized t))))
2642 (candidates . anything-c-file-cache-files)
2643 (match anything-c-match-on-file-name
2644 anything-c-match-on-directory-name)
2645 (type . file)))
2646 ;; (anything 'anything-c-source-file-cache)
2648 ;;; Locate
2649 ;; NOTE for WINDOZE users:
2650 ;; You have to install Everything with his command line interface here:
2651 ;; http://www.voidtools.com/download.php
2653 (defvar anything-c-locate-command
2654 (case system-type
2655 ('gnu/linux "locate -i -r %s")
2656 ('berkeley-unix "locate -i %s")
2657 ('windows-nt "es -i -r %s")
2658 (t "locate %s"))
2659 "A list of arguments for locate program.
2660 The \"-r\" option must be the last option.")
2662 (defun anything-c-locate-init ()
2663 "Initialize async locate process for `anything-c-source-locate'."
2664 (setq mode-line-format
2665 '(" " mode-line-buffer-identification " "
2666 (line-number-mode "%l") " "
2667 (:eval (propertize "(Locate Process Running) "
2668 'face '((:foreground "red"))))))
2669 (prog1
2670 (start-process-shell-command "locate-process" nil
2671 (format anything-c-locate-command
2672 anything-pattern))
2673 (set-process-sentinel (get-process "locate-process")
2674 #'(lambda (process event)
2675 (when (string= event "finished\n")
2676 (kill-local-variable 'mode-line-format)
2677 (with-anything-window
2678 (anything-update-move-first-line)))))))
2680 (defvar anything-c-source-locate
2681 '((name . "Locate")
2682 (candidates . anything-c-locate-init)
2683 (type . file)
2684 (requires-pattern . 3)
2685 (delayed))
2686 "Find files matching the current input pattern with locate.")
2688 ;; (anything 'anything-c-source-locate)
2690 ;;; Grep
2691 ;; NOTE: the -d option with skip avoid error on windows.
2692 ;; It have no effect on GNU/Linux.
2693 (defvar anything-c-grep-default-command "grep -d skip -niH -e %s %s %s"
2694 "Default format command for `anything-do-grep'.
2695 If you want to enable recursion just add the -r option like this:
2696 \"grep -nirH -e %s %s %s\".
2697 NOTE: This option is accessible with a prefix arg
2698 from all anything grep commands without setting it here.")
2700 (defvar anything-c-grep-default-function 'anything-c-grep-init)
2702 (defface anything-grep-match
2703 '((t (:inherit match)))
2704 "Face used to highlight grep matches."
2705 :group 'anything)
2707 (defface anything-grep-file
2708 '((t (:foreground "BlueViolet" :underline t)))
2709 "Face used to highlight grep results filenames."
2710 :group 'anything)
2712 (defface anything-grep-lineno
2713 '((t (:foreground "Darkorange1")))
2714 "Face used to highlight grep number lines."
2715 :group 'anything)
2717 (defun anything-c-grep-prepare-candidates (candidates)
2718 "Prepare filenames and directories candidates for grep command line."
2719 ;; If one or more candidate is a directory, search in all files
2720 ;; of this candidate (e.g /home/user/directory/*).
2721 ;; If r option is enabled search also in subdidrectories.
2722 ;; We need here to expand wildcards to support crap windows filenames
2723 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
2724 (loop for i in candidates append
2725 (cond ((and (file-directory-p i)
2726 (anything-c-grep-recurse-p))
2727 (list (expand-file-name i)))
2728 ((file-directory-p i)
2729 (file-expand-wildcards (concat (file-name-as-directory
2730 (expand-file-name i))
2731 "*") t))
2732 ((string-match "\*" i) (file-expand-wildcards i t))
2733 (t (list i))) into of
2734 finally return
2735 (mapconcat #'(lambda (x) (shell-quote-argument x)) of " ")))
2737 (defun anything-c-grep-recurse-p ()
2738 "Check if `anything-do-grep1' have switched to recursive."
2739 (let ((args (replace-regexp-in-string
2740 "grep" "" anything-c-grep-default-command)))
2741 (string-match-p "r\\|recurse" args)))
2743 (defun anything-c-grep-init (only-files &optional include)
2744 "Start an asynchronous grep process in ONLY-FILES list."
2745 (let* ((fnargs (anything-c-grep-prepare-candidates
2746 (if (file-remote-p anything-ff-default-directory)
2747 (mapcar #'(lambda (x) (file-remote-p x 'localname)) only-files)
2748 only-files)))
2749 (ignored-files (mapconcat
2750 #'(lambda (x)
2751 (concat "--exclude=" (shell-quote-argument x)))
2752 grep-find-ignored-files " "))
2753 (ignored-dirs (mapconcat ; Need grep version 2.5.4 of Gnuwin32 on windoze.
2754 #'(lambda (x)
2755 (concat "--exclude-dir=" (shell-quote-argument x)))
2756 grep-find-ignored-directories " "))
2757 (exclude (if (anything-c-grep-recurse-p)
2758 (concat (or include ignored-files) " " ignored-dirs)
2759 ignored-files)))
2760 (setq mode-line-format
2761 '(" " mode-line-buffer-identification " "
2762 (line-number-mode "%l") " "
2763 (:eval (propertize "(Grep Process Running) "
2764 'face '((:foreground "red"))))))
2765 (prog1
2766 (let ((default-directory anything-ff-default-directory))
2767 (start-file-process-shell-command
2768 "grep-process" nil
2769 (format anything-c-grep-default-command
2770 (shell-quote-argument anything-pattern)
2771 fnargs
2772 exclude)))
2773 (message nil)
2774 (set-process-sentinel
2775 (get-process "grep-process")
2776 #'(lambda (process event)
2777 (when (string= event "finished\n")
2778 (kill-local-variable 'mode-line-format)
2779 (with-anything-window
2780 (anything-update-move-first-line))))))))
2782 (defun anything-c-grep-action (candidate &optional where)
2783 "Define a default action for `anything-do-grep' on CANDIDATE.
2784 WHERE can be one of other-window, elscreen, other-frame."
2785 (let* ((split (anything-c-grep-split-line candidate))
2786 (lineno (string-to-number (nth 1 split)))
2787 (loc-fname (car split))
2788 (tramp-method (file-remote-p anything-ff-default-directory 'method))
2789 (tramp-host (file-remote-p anything-ff-default-directory 'host))
2790 (tramp-prefix (concat "/" tramp-method ":" tramp-host ":"))
2791 (fname (if tramp-host (concat tramp-prefix loc-fname) loc-fname)))
2792 (case where
2793 (other-window (find-file-other-window fname))
2794 (elscreen (anything-elscreen-find-file fname))
2795 (other-frame (find-file-other-frame fname))
2796 (t (find-file fname)))
2797 (show-all)
2798 (anything-goto-line lineno)))
2800 (defun anything-c-grep-persistent-action (candidate)
2801 (anything-c-grep-action candidate)
2802 (anything-match-line-color-current-line))
2804 (defun anything-do-grep1 (only &optional recurse)
2805 "Launch grep with a list of ONLY files.
2806 When RECURSE is given use -r option of grep and prompt user
2807 to set the --include arg of grep.
2808 If it's not empty use it instead of `grep-find-ignored-files'."
2809 (let* ((anything-compile-source-functions
2810 ;; rule out anything-match-plugin because the input is one regexp.
2811 (delq 'anything-compile-source--match-plugin
2812 (copy-sequence anything-compile-source-functions)))
2813 (include-files (and recurse (read-string "OnlyExt: ")))
2814 (anything-c-grep-default-command (if recurse "grep -nirH -e %s %s %s"
2815 anything-c-grep-default-command))
2816 ;; Disable match-plugin and use here own highlighting.
2817 (anything-mp-highlight-delay nil))
2818 (when include-files
2819 (setq include-files
2820 (and (not (string= include-files ""))
2821 (format "--include=%s" (shell-quote-argument include-files)))))
2822 ;; When called as action from an other source e.g *-find-files
2823 ;; we have to kill action buffer.
2824 (when (get-buffer anything-action-buffer)
2825 (kill-buffer anything-action-buffer))
2826 (define-key anything-map (kbd "M-<down>") #'anything-c-grep-next-or-prec-file)
2827 (define-key anything-map (kbd "M-<up>") #'anything-c-grep-precedent-file)
2828 (anything
2829 :sources
2830 `(((name . "Grep (M-up/down - next/prec file)")
2831 (init . (lambda ()
2832 ;; Load `grep-find-ignored-files'.
2833 (require 'grep)))
2834 (candidates
2835 . (lambda () (if include-files
2836 (funcall anything-c-grep-default-function only include-files)
2837 (funcall anything-c-grep-default-function only))))
2838 (filtered-candidate-transformer anything-c-grep-cand-transformer)
2839 (candidate-number-limit . 9999)
2840 (action . ,(delq
2842 `(("Find File" . anything-c-grep-action)
2843 ("Find file other window"
2844 . (lambda (candidate)
2845 (anything-c-grep-action candidate 'other-window)))
2846 ,(and (locate-library "elscreen")
2847 '("Find file in Elscreen"
2848 . (lambda (candidate)
2849 (anything-c-grep-action candidate 'elscreen))))
2850 ("Find file other frame"
2851 . (lambda (candidate)
2852 (anything-c-grep-action candidate 'other-frame))))))
2853 (persistent-action . (lambda (candidate)
2854 (anything-c-grep-persistent-action candidate)))
2855 (requires-pattern . 3)
2856 (delayed)))
2857 :buffer "*anything grep*")))
2859 ;;;###autoload
2860 (defun anything-do-grep (only &optional arg)
2861 "Preconfigured anything for grep.
2862 Contrarily to Emacs `grep' no default directory is given, but
2863 the full path of candidates in ONLY.
2864 That allow to grep different files not only in `default-directory' but anywhere
2865 by marking them (C-<SPACE>). If one or more directory is selected
2866 grep will search in all files of these directories.
2867 You can use also wildcard in the base name of candidate.
2868 If a prefix arg is given use the -r option of grep."
2869 (interactive (list
2870 (anything-c-read-file-name
2871 "Search in file(s): " :marked-candidates t)
2872 "\nP"))
2873 (anything-do-grep1 only arg))
2876 (defun anything-c-grep-split-line (line)
2877 "Split a grep output line."
2878 (let (beg fname lineno str)
2879 ;; Don't print until grep line is valid.
2880 (when (string-match "\\(.*\\)\\(:[0-9]+:\\)\\(.*\\)" line)
2881 (with-temp-buffer
2882 (insert line)
2883 (goto-char (point-min))
2884 (setq beg (point))
2885 (forward-char 2)
2886 (re-search-forward ":" nil t)
2887 (setq fname (buffer-substring-no-properties beg (1- (point))))
2888 (setq beg (point))
2889 (re-search-forward ":" nil t)
2890 (setq lineno (buffer-substring-no-properties beg (1- (point))))
2891 (setq str (buffer-substring-no-properties (point) (point-at-eol))))
2892 (list fname lineno str))))
2894 (defun anything-c-grep-cand-transformer (candidates sources)
2895 "Filtered candidate transformer function for `anything-do-grep'."
2896 (loop for i in candidates
2897 for split = (and i (anything-c-grep-split-line i))
2898 for fname = (car split)
2899 for lineno = (nth 1 split)
2900 for str = (nth 2 split)
2901 when (and fname lineno str)
2902 collect
2903 (cons (concat (propertize (file-name-nondirectory fname)
2904 'face 'anything-grep-file
2905 'help-echo fname) ":"
2906 (propertize lineno 'face 'anything-grep-lineno) ":"
2907 (anything-c-grep-highlight-match str))
2908 i)))
2910 (defun anything-c-grep-highlight-match (str)
2911 "Highlight in STR all occurences matching `anything-pattern'."
2912 (condition-case nil
2913 (with-temp-buffer
2914 (insert str)
2915 (goto-char (point-min))
2916 (while (and (re-search-forward anything-pattern nil t)
2917 (> (- (match-end 0) (match-beginning 0)) 0))
2918 (add-text-properties
2919 (match-beginning 0) (match-end 0)
2920 '(face anything-grep-match)))
2921 (buffer-string))
2922 (error nil)))
2924 ;;;###autoload
2925 (defun anything-c-grep-precedent-file ()
2926 "Go to precedent file in `anything-do-grep'."
2927 (interactive)
2928 (anything-c-grep-next-or-prec-file -1))
2930 ;;;###autoload
2931 (defun* anything-c-grep-next-or-prec-file (&optional (n 1))
2932 "Go to next or precedent candidate file in anything grep buffer."
2933 (interactive)
2934 (let ((cur-source (assoc-default 'name (anything-get-current-source))))
2935 (with-anything-window
2936 (if (equal cur-source "Grep (M-up/down - next/prec file)")
2937 (let* ((current-line-list (split-string
2938 (buffer-substring
2939 (point-at-bol)
2940 (point-at-eol)) ":"))
2941 (current-fname (nth 0 current-line-list))
2942 (fn-b-o-f (if (eq n 1) 'eobp 'bobp))) ; func back or forward
2943 (catch 'break
2944 (while (not (funcall fn-b-o-f))
2945 (forward-line n)
2946 (beginning-of-line)
2947 (when (not (search-forward current-fname (point-at-eol) t))
2948 (anything-mark-current-line)
2949 (throw 'break nil))))
2950 (if (eq n 1)
2951 (when (eobp)
2952 (re-search-backward ".")
2953 (beginning-of-line)
2954 (anything-mark-current-line))
2955 (when (bobp)
2956 (forward-line)
2957 (beginning-of-line)
2958 (anything-mark-current-line))))
2959 (if (eq n 1)
2960 (anything-next-line)
2961 (anything-previous-line))))))
2963 ;;; Recentf files
2964 (defvar anything-c-source-recentf
2965 '((name . "Recentf")
2966 (init . (lambda ()
2967 (require 'recentf)
2968 (or recentf-mode (recentf-mode 1))
2969 ;; Big value empowers anything/recentf
2970 (when (and (numberp recentf-max-saved-items)
2971 (<= recentf-max-saved-items 20))
2972 (setq recentf-max-saved-items 500))))
2973 (candidates . recentf-list)
2974 (match anything-c-match-on-file-name
2975 anything-c-match-on-directory-name)
2976 (type . file))
2977 "See (info \"(emacs)File Conveniences\").
2978 if `recentf-max-saved-items' is too small, set it to 500.")
2979 ;; (anything 'anything-c-source-recentf)
2981 ;;; ffap
2982 (eval-when-compile (require 'ffap))
2983 (defvar anything-c-source-ffap-guesser
2984 '((name . "File at point")
2985 (init . (lambda () (require 'ffap)))
2986 (candidates . (lambda ()
2987 (anything-aif
2988 (with-current-buffer anything-current-buffer
2989 (ffap-guesser))
2990 (list it))))
2991 (type . file)))
2992 ;; (anything 'anything-c-source-ffap-guesser)
2994 ;;; ffap with line number
2995 (defun anything-c-ffap-file-line-at-point ()
2996 "Get (FILENAME . LINENO) at point."
2997 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2998 (save-excursion
2999 (beginning-of-line)
3000 (when (and (search-forward it nil t)
3001 (looking-at ":\\([0-9]+\\)"))
3002 (cons it (string-to-number (match-string 1)))))))
3004 (defvar anything-c-ffap-line-location nil
3005 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
3006 It is cleared after jumping line.")
3008 (defun anything-c-ffap-line-candidates ()
3009 (with-current-buffer anything-current-buffer
3010 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
3011 (when anything-c-ffap-line-location
3012 (destructuring-bind (file . line) anything-c-ffap-line-location
3013 (list (cons (format "%s (line %d)" file line) file)))))
3015 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
3016 (defun anything-c-ffap-line-goto-line ()
3017 (when (car anything-c-ffap-line-location)
3018 (unwind-protect
3019 (ignore-errors
3020 (with-selected-window
3021 (get-buffer-window
3022 (get-file-buffer (car anything-c-ffap-line-location)))
3023 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
3024 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
3025 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
3027 (defvar anything-c-source-ffap-line
3028 '((name . "File/Lineno at point")
3029 (init . (lambda () (require 'ffap)))
3030 (candidates . anything-c-ffap-line-candidates)
3031 (type . file)))
3032 ;; (anything 'anything-c-source-ffap-line)
3034 ;;; list of files gleaned from every dired buffer
3035 (defun anything-c-files-in-all-dired-candidates ()
3036 (save-excursion
3037 (mapcan
3038 (lambda (dir)
3039 (cond ((listp dir) ;filelist
3040 dir)
3041 ((equal "" (file-name-nondirectory dir)) ;dir
3042 (directory-files dir t))
3043 (t ;wildcard
3044 (file-expand-wildcards dir t))))
3045 (delq nil
3046 (mapcar (lambda (buf)
3047 (set-buffer buf)
3048 (when (eq major-mode 'dired-mode)
3049 (if (consp dired-directory)
3050 (cdr dired-directory) ;filelist
3051 dired-directory))) ;dir or wildcard
3052 (buffer-list))))))
3053 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
3055 (defvar anything-c-source-files-in-all-dired
3056 '((name . "Files in all dired buffer.")
3057 (candidates . anything-c-files-in-all-dired-candidates)
3058 (type . file)))
3059 ;; (anything 'anything-c-source-files-in-all-dired)
3061 (defcustom anything-c-filelist-file-name nil
3062 "*Filename of file list.
3063 Accept a list of string for multiple files.
3065 This file tend to be very large (> 100MB) and recommend to be in ramdisk for speed.
3066 File list is created by make-filelist.rb script.
3068 Usage:
3069 ruby make-filelist.rb > /tmp/all.filelist
3071 Then
3072 ;; Assume that /tmp is ramdisk or tmpfs
3073 (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")
3074 (setq anything-c-filelist-file-name \"/tmp/all.filelist\")
3076 :type 'string
3077 :group 'anything-config)
3078 (defvar anything-c-source-filelist
3079 '((name . "FileList")
3080 (grep-candidates . anything-c-filelist-file-name)
3081 (candidate-number-limit . 200)
3082 (requires-pattern . 4)
3083 (type . file)))
3085 ;;;###autoload
3086 (defun anything-filelist ()
3087 "Preconfigured `anything' to open files instantly."
3088 (interactive)
3089 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
3091 ;;;###autoload
3092 (defun anything-filelist+ ()
3093 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
3095 This is a replacement for `anything-for-files'."
3096 (interactive)
3097 (anything-other-buffer
3098 '(anything-c-source-ffap-line
3099 anything-c-source-ffap-guesser
3100 anything-c-source-buffers+
3101 anything-c-source-recentf
3102 anything-c-source-bookmarks
3103 anything-c-source-file-cache
3104 anything-c-source-filelist)
3105 "*anything file list*"))
3108 ;;;; <info>
3109 ;;; Info pages
3110 (defvar anything-c-info-pages nil
3111 "All info pages on system.
3112 Will be calculated the first time you invoke anything with this
3113 source.")
3115 (defvar anything-c-source-info-pages
3116 `((name . "Info Pages")
3117 (candidates
3118 . (lambda ()
3119 (if anything-c-info-pages
3120 anything-c-info-pages
3121 (setq anything-c-info-pages
3122 (save-window-excursion
3123 (save-excursion
3124 (require 'info)
3125 (Info-find-node "dir" "top")
3126 (goto-char (point-min))
3127 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
3128 topics)
3129 (while (re-search-forward info-topic-regexp nil t)
3130 (add-to-list 'topics (match-string-no-properties 1)))
3131 (goto-char (point-min))
3132 (Info-exit)
3133 topics)))))))
3134 (action . (("Show with Info" .(lambda (node-str)
3135 (info (replace-regexp-in-string
3136 "^[^:]+: " "" node-str))))))
3137 (requires-pattern . 2)))
3138 ;; (anything 'anything-c-source-info-pages)
3141 ;;; Use info-index plug-in. Note that `name' attribute is
3142 ;;; not needed but `anything-c-insert-summary' uses it.
3143 ;; Info Elisp
3144 (defvar anything-c-source-info-elisp
3145 '((name . "Info index: elisp")
3146 (info-index . "elisp")))
3147 ;; (anything 'anything-c-source-info-elisp)
3149 ;; Info-Common-Lisp
3150 (defvar anything-c-source-info-cl
3151 '((name . "Info index: cl")
3152 (info-index . "cl")))
3153 ;; (anything 'anything-c-source-info-cl)
3155 ;; Info Index org
3156 (defvar anything-c-source-info-org
3157 '((name . "Info index: org")
3158 (info-index . "org")))
3159 ;; (anything 'anything-c-source-info-org)
3161 ;; Info Index ratpoison
3162 (defvar anything-c-source-info-ratpoison
3163 '((name . "Info index: ratpoison")
3164 (info-index . "ratpoison")))
3165 ;; (anything 'anything-c-source-info-ratpoison)
3167 ;; Info Index zsh
3168 (defvar anything-c-source-info-zsh
3169 '((name . "Info index: zsh")
3170 (info-index . "zsh")))
3171 ;; (anything 'anything-c-source-info-zsh)
3173 ;; Info Index bash
3174 (defvar anything-c-source-info-bash
3175 '((name . "Info index: bash")
3176 (info-index . "bash")))
3177 ;; (anything 'anything-c-source-info-bash)
3179 ;; Info Index coreutils
3180 (defvar anything-c-source-info-coreutils
3181 '((name . "Info index: coreutils")
3182 (info-index . "coreutils")))
3183 ;; (anything 'anything-c-source-info-coreutils)
3185 ;; Info Index fileutils
3186 (defvar anything-c-source-info-fileutils
3187 '((name . "Info index: fileutils")
3188 (info-index . "fileutils")))
3189 ;; (anything 'anything-c-source-info-fileutils)
3191 ;; Info Index find
3192 (defvar anything-c-source-info-find
3193 '((name . "Info index: find")
3194 (info-index . "find")))
3195 ;; (anything 'anything-c-source-info-find)
3197 ;; Info Index sh-utils
3198 (defvar anything-c-source-info-sh-utils
3199 '((name . "Info index: sh-utils")
3200 (info-index . "sh-utils")))
3201 ;; (anything 'anything-c-source-info-sh-utils)
3203 ;; Info Index textutils
3204 (defvar anything-c-source-info-textutils
3205 '((name . "Info index: textutils")
3206 (info-index . "textutils")))
3207 ;; (anything 'anything-c-source-info-textutils)
3209 ;; Info Index libc
3210 (defvar anything-c-source-info-libc
3211 '((name . "Info index: libc")
3212 (info-index . "libc")))
3213 ;; (anything 'anything-c-source-info-libc)
3215 ;; Info Index make
3216 (defvar anything-c-source-info-make
3217 '((name . "Info index: make")
3218 (info-index . "make")))
3219 ;; (anything 'anything-c-source-info-make)
3221 ;; Info Index automake
3222 (defvar anything-c-source-info-automake
3223 '((name . "Info index: automake")
3224 (info-index . "automake")))
3225 ;; (anything 'anything-c-source-info-automake)
3227 ;; Info Index autoconf
3228 (defvar anything-c-source-info-autoconf
3229 '((name . "Info index: autoconf")
3230 (info-index . "autoconf")))
3231 ;; (anything 'anything-c-source-info-autoconf)
3233 ;; Info Index emacs-lisp-intro
3234 (defvar anything-c-source-info-emacs-lisp-intro
3235 '((name . "Info index: emacs-lisp-intro")
3236 (info-index . "emacs-lisp-intro")))
3237 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
3239 ;; Info Index emacs
3240 (defvar anything-c-source-info-emacs
3241 '((name . "Info index: emacs")
3242 (info-index . "emacs")))
3243 ;; (anything 'anything-c-source-info-emacs)
3245 ;; Info Index elib
3246 (defvar anything-c-source-info-elib
3247 '((name . "Info index: elib")
3248 (info-index . "elib")))
3249 ;; (anything 'anything-c-source-info-elib)
3251 ;; Info Index eieio
3252 (defvar anything-c-source-info-eieio
3253 '((name . "Info index: eieio")
3254 (info-index . "eieio")))
3255 ;; (anything 'anything-c-source-info-eieio)
3257 ;; Info Index gauche-refe
3258 (defvar anything-c-source-info-gauche-refe
3259 '((name . "Info index: gauche")
3260 (info-index . "gauche-refe")))
3261 ;; (anything 'anything-c-source-info-gauche-refe)
3263 ;; Info Index guile
3264 (defvar anything-c-source-info-guile
3265 '((name . "Info index: guile")
3266 (info-index . "guile")))
3267 ;; (anything 'anything-c-source-info-guile)
3269 ;; Info Index guile-tut
3270 (defvar anything-c-source-info-guile-tut
3271 '((name . "Info index: guile-tut")
3272 (info-index . "guile-tut")))
3273 ;; (anything 'anything-c-source-info-guile-tut)
3275 ;; Info Index goops
3276 (defvar anything-c-source-info-goops
3277 '((name . "Info index: goops")
3278 (info-index . "goops")))
3279 ;; (anything 'anything-c-source-info-goops)
3281 ;; Info Index screen
3282 (defvar anything-c-source-info-screen
3283 '((name . "Info index: screen")
3284 (info-index . "screen")
3285 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
3286 ;; (anything 'anything-c-source-info-screen)
3288 ;; Info Index latex
3289 (defvar anything-c-source-info-latex
3290 '((name . "Info index: latex")
3291 (info-index . "latex")))
3292 ;; (anything 'anything-c-source-info-latex)
3294 ;; Info Index gawk
3295 (defvar anything-c-source-info-gawk
3296 '((name . "Info index: gawk")
3297 (info-index . "gawk")))
3298 ;; (anything 'anything-c-source-info-gawk)
3300 ;; Info Index sed
3301 (defvar anything-c-source-info-sed
3302 '((name . "Info index: sed")
3303 (info-index . "sed")))
3304 ;; (anything 'anything-c-source-info-sed)
3306 ;; Info Index m4
3307 (defvar anything-c-source-info-m4
3308 '((name . "Info index: m4")
3309 (info-index . "m4")))
3310 ;; (anything 'anything-c-source-info-m4)
3312 ;; Info Index wget
3313 (defvar anything-c-source-info-wget
3314 '((name . "Info index: wget")
3315 (info-index . "wget")))
3316 ;; (anything 'anything-c-source-info-wget)
3318 ;; Info Index binutils
3319 (defvar anything-c-source-info-binutils
3320 '((name . "Info index: binutils")
3321 (info-index . "binutils")))
3322 ;; (anything 'anything-c-source-info-binutils)
3324 ;; Info Index as
3325 (defvar anything-c-source-info-as
3326 '((name . "Info index: as")
3327 (info-index . "as")))
3328 ;; (anything 'anything-c-source-info-as)
3330 ;; Info Index bfd
3331 (defvar anything-c-source-info-bfd
3332 '((name . "Info index: bfd")
3333 (info-index . "bfd")))
3334 ;; (anything 'anything-c-source-info-bfd)
3336 ;; Info Index gprof
3337 (defvar anything-c-source-info-gprof
3338 '((name . "Info index: gprof")
3339 (info-index . "gprof")))
3340 ;; (anything 'anything-c-source-info-gprof)
3342 ;; Info Index ld
3343 (defvar anything-c-source-info-ld
3344 '((name . "Info index: ld")
3345 (info-index . "ld")))
3346 ;; (anything 'anything-c-source-info-ld)
3348 ;; Info Index diff
3349 (defvar anything-c-source-info-diff
3350 '((name . "Info index: diff")
3351 (info-index . "diff")))
3352 ;; (anything 'anything-c-source-info-diff)
3354 ;; Info Index flex
3355 (defvar anything-c-source-info-flex
3356 '((name . "Info index: flex")
3357 (info-index . "flex")))
3358 ;; (anything 'anything-c-source-info-flex)
3360 ;; Info Index grep
3361 (defvar anything-c-source-info-grep
3362 '((name . "Info index: grep")
3363 (info-index . "grep")))
3364 ;; (anything 'anything-c-source-info-grep)
3366 ;; Info Index gzip
3367 (defvar anything-c-source-info-gzip
3368 '((name . "Info index: gzip")
3369 (info-index . "gzip")))
3370 ;; (anything 'anything-c-source-info-gzip)
3372 ;; Info Index libtool
3373 (defvar anything-c-source-info-libtool
3374 '((name . "Info index: libtool")
3375 (info-index . "libtool")))
3376 ;; (anything 'anything-c-source-info-libtool)
3378 ;; Info Index texinfo
3379 (defvar anything-c-source-info-texinfo
3380 '((name . "Info index: texinfo")
3381 (info-index . "texinfo")))
3382 ;; (anything 'anything-c-source-info-texinfo)
3384 ;; Info Index info
3385 (defvar anything-c-source-info-info
3386 '((name . "Info index: info")
3387 (info-index . "info")))
3388 ;; (anything 'anything-c-source-info-info)
3390 ;; Info Index gdb
3391 (defvar anything-c-source-info-gdb
3392 '((name . "Info index: gdb")
3393 (info-index . "gdb")))
3394 ;; (anything 'anything-c-source-info-gdb)
3396 ;; Info Index stabs
3397 (defvar anything-c-source-info-stabs
3398 '((name . "Info index: stabs")
3399 (info-index . "stabs")))
3400 ;; (anything 'anything-c-source-info-stabs)
3402 ;; Info Index cvsbook
3403 (defvar anything-c-source-info-cvsbook
3404 '((name . "Info index: cvsbook")
3405 (info-index . "cvsbook")))
3406 ;; (anything 'anything-c-source-info-cvsbook)
3408 ;; Info Index cvs
3409 (defvar anything-c-source-info-cvs
3410 '((name . "Info index: cvs")
3411 (info-index . "cvs")))
3412 ;; (anything 'anything-c-source-info-cvs)
3414 ;; Info Index bison
3415 (defvar anything-c-source-info-bison
3416 '((name . "Info index: bison")
3417 (info-index . "bison")))
3418 ;; (anything 'anything-c-source-info-bison)
3420 ;; Info Index id-utils
3421 (defvar anything-c-source-info-id-utils
3422 '((name . "Info index: id-utils")
3423 (info-index . "id-utils")))
3424 ;; (anything 'anything-c-source-info-id-utils)
3426 ;; Info Index global
3427 (defvar anything-c-source-info-global
3428 '((name . "Info index: global")
3429 (info-index . "global")))
3430 ;; (anything 'anything-c-source-info-global)
3432 ;;;; <Help>
3433 ;;; Man Pages
3434 (defvar anything-c-man-pages nil
3435 "All man pages on system.
3436 Will be calculated the first time you invoke anything with this
3437 source.")
3439 (defvar anything-c-source-man-pages
3440 `((name . "Manual Pages")
3441 (candidates . (lambda ()
3442 (if anything-c-man-pages
3443 anything-c-man-pages
3444 ;; XEmacs doesn't have a woman :)
3445 (setq anything-c-man-pages
3446 (ignore-errors
3447 (require 'woman)
3448 (woman-file-name "")
3449 (sort (mapcar 'car woman-topic-all-completions)
3450 'string-lessp))))))
3451 (action ("Show with Woman"
3452 . (lambda (candidate)
3453 (let ((wfiles (woman-file-name-all-completions candidate)))
3454 (if (> (length wfiles) 1)
3455 (woman-find-file (anything-comp-read "ManFile: " wfiles
3456 :must-match t))
3457 (woman candidate))))))
3458 ;; Woman does not work OS X
3459 ;; http://xahlee.org/emacs/modernization_man_page.html
3460 (action-transformer . (lambda (actions candidate)
3461 (if (eq system-type 'darwin)
3462 '(("Show with Man" . man))
3463 actions)))
3464 (requires-pattern . 2)))
3465 ;; (anything 'anything-c-source-man-pages)
3467 ;;;; <Command>
3468 ;;; Complex command history
3469 (defvar anything-c-source-complex-command-history
3470 '((name . "Complex Command History")
3471 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
3472 (type . sexp)))
3473 ;; (anything 'anything-c-source-complex-command-history)
3475 ;;; M-x history
3476 (defvar anything-c-source-extended-command-history
3477 '((name . "Emacs Commands History")
3478 (candidates . extended-command-history)
3479 (type . command)))
3480 ;; (anything 'anything-c-source-extended-command-history)
3482 ;;; Emacs commands
3483 (defvar anything-c-source-emacs-commands
3484 '((name . "Emacs Commands")
3485 (candidates . (lambda ()
3486 (let (commands)
3487 (mapatoms (lambda (a)
3488 (if (commandp a)
3489 (push (symbol-name a)
3490 commands))))
3491 (sort commands 'string-lessp))))
3492 (type . command)
3493 (requires-pattern . 2))
3494 "Source for completing and invoking Emacs commands.
3495 A command is a function with interactive spec that can
3496 be invoked with `M-x'.
3498 To get non-interactive functions listed, use
3499 `anything-c-source-emacs-functions'.")
3500 ;; (anything 'anything-c-source-emacs-commands)
3502 ;;; Anything M-x
3504 ;; Another replacement of `M-x' that act exactly like the
3505 ;; vanilla Emacs one, no problem of windows configuration, prefix args
3506 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
3507 ;; anything invocation.
3508 ;;;###autoload
3509 (defun anything-M-x ()
3510 "Preconfigured `anything' for Emacs commands.
3511 It is `anything' replacement of regular `M-x' `execute-extended-command'."
3512 (interactive)
3513 (let* (in-help help-cand
3514 (command (anything-comp-read
3515 "M-x " obarray
3516 :test 'commandp
3517 :must-match t
3518 :requires-pattern 2
3519 :name "Emacs Commands"
3520 :persistent-action
3521 #'(lambda (candidate)
3522 (if (and in-help (string= candidate help-cand))
3523 (progn (kill-buffer "*Help*") (setq in-help nil))
3524 (describe-function (intern candidate))
3525 (setq in-help t))
3526 (setq help-cand candidate))
3527 :persistent-help "Describe this command"
3528 :history extended-command-history
3529 :sort 'string-lessp
3530 :fc-transformer 'anything-M-x-transformer))
3531 (history (loop with hist
3532 for i in extended-command-history
3533 for com = (intern i)
3534 when (and (fboundp com) (not (member i hist)))
3535 collect i into hist finally return hist)))
3536 (unless current-prefix-arg (setq current-prefix-arg anything-current-prefix-arg))
3537 (call-interactively (intern command))
3538 (setq extended-command-history (cons command (delete command history)))))
3540 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
3541 "Return alist of MODE-MAP."
3542 (loop for key being the key-seqs of mode-map using (key-bindings com)
3543 for str-key = (key-description key)
3544 for ismenu = (string-match "<menu-bar>" str-key)
3545 unless ismenu collect (cons str-key com)))
3547 (defun anything-get-mode-map-from-mode (mode)
3548 "Guess the mode-map name according to MODE.
3549 Some modes don't use conventional mode-map name
3550 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
3551 Return nil if no mode-map found."
3552 (loop
3553 ;; Start with a conventional mode-map name.
3554 with mode-map = (intern-soft (format "%s-map" mode))
3555 with mode-string = (symbol-name mode)
3556 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
3557 while (not mode-map)
3558 for count downfrom (length mode-name)
3559 ;; Return when no result after parsing entire string.
3560 when (eq count 0) return nil
3561 for sub-name = (substring mode-name 0 count)
3562 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
3563 finally return mode-map))
3565 (defun anything-M-x-current-mode-map-alist ()
3566 "Return mode-map alist of current `major-mode'."
3567 (let ((map (anything-get-mode-map-from-mode major-mode)))
3568 (when (and map (boundp map))
3569 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
3571 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
3572 "*Face used in anything-M-x to show keybinding."
3573 :group 'anything)
3575 (defun anything-M-x-transformer (candidates sources)
3576 "filtered-candidate-transformer to show bindings in emacs commands.
3577 Show global bindings and local bindings according to current `major-mode'."
3578 (loop
3579 with local-map = (with-current-buffer anything-current-buffer
3580 (anything-M-x-current-mode-map-alist))
3581 for i in candidates
3582 for cand = (symbol-name i)
3583 for local-key = (car (rassq i local-map))
3584 for key = (substitute-command-keys (format "\\[%s]" cand))
3585 collect
3586 (cons (if (string-match "^M-x" key)
3587 (if local-key
3588 (concat
3589 cand " (" (propertize local-key 'face 'anything-M-x-key-face)
3590 ")")
3591 cand)
3592 (concat
3593 cand " (" (propertize key 'face 'anything-M-x-key-face) ")"))
3594 cand)))
3596 ;;; LaCarte
3597 (defvar anything-c-source-lacarte
3598 '((name . "Lacarte")
3599 (init . (lambda () (require 'lacarte )))
3600 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
3601 (candidate-number-limit . 9999)
3602 (action . anything-c-call-interactively))
3603 "Needs lacarte.el.
3605 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
3606 ;; (anything 'anything-c-source-lacarte)
3608 ;;;; <Function>
3609 ;;; Emacs functions
3610 (defvar anything-c-source-emacs-functions
3611 '((name . "Emacs Functions")
3612 (candidates . (lambda ()
3613 (let (commands)
3614 (mapatoms (lambda (a)
3615 (if (functionp a)
3616 (push (symbol-name a) commands))))
3617 (sort commands 'string-lessp))))
3618 (type . function)
3619 (requires-pattern . 2))
3620 "Source for completing Emacs functions.")
3621 ;; (anything 'anything-c-source-emacs-functions)
3623 ;;; With abbrev expansion
3624 ;;; Similar to my exec-abbrev-cmd.el
3625 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
3626 (defvar anything-c-function-abbrev-regexp nil
3627 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
3628 Regexp built from the current `anything-pattern' interpreting it
3629 as abbreviation.
3630 Only for internal use.")
3632 (defun anything-c-match-function-by-abbrev (candidate)
3633 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
3635 Abbreviations are made by taking the first character from each
3636 word in the function's name, e.g. \"bb\" is an abbrev for
3637 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
3638 (string-match anything-c-function-abbrev-regexp candidate))
3640 (defvar anything-c-source-emacs-functions-with-abbrevs
3641 (append anything-c-source-emacs-functions
3642 '((match anything-c-match-function-by-abbrev
3643 anything-c-string-match))
3644 '((init
3645 . (lambda ()
3646 (defadvice anything-update
3647 (before anything-c-update-function-abbrev-regexp activate)
3648 (let ((char-list (append anything-pattern nil))
3649 (str "^"))
3650 (dolist (c char-list)
3651 (setq str (concat str (list c) "[^-]*-")))
3652 (setq str (concat (substring str 0 (1- (length str))) "$"))
3653 (setq anything-c-function-abbrev-regexp str))))))))
3654 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
3656 (defvar anything-c-source-advice
3657 '((name . "Function Advice")
3658 (candidates . anything-c-advice-candidates)
3659 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
3660 ;; (real-to-display . anything-c-advice-real-to-display)
3663 (persistent-action . anything-c-advice-persistent-action)
3664 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
3665 ;; (anything 'anything-c-source-advice)
3666 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
3667 ;; (testadvice)
3669 (defun anything-c-advice-candidates ()
3670 (require 'advice)
3671 (loop for (fname) in ad-advised-functions
3672 for function = (intern fname)
3673 append
3674 (loop for class in ad-advice-classes append
3675 (loop for advice in (ad-get-advice-info-field function class)
3676 for enabled = (ad-advice-enabled advice)
3677 collect
3678 (cons (format
3679 "%s %s %s"
3680 (if enabled "Enabled " "Disabled")
3681 (propertize fname 'face 'font-lock-function-name-face)
3682 (ad-make-single-advice-docstring advice class nil))
3683 (list function class advice))))))
3685 (defun anything-c-advice-persistent-action (func-class-advice)
3686 (if current-prefix-arg
3687 (anything-c-advice-toggle func-class-advice)
3688 (describe-function (car func-class-advice))))
3690 (defun anything-c-advice-toggle (func-class-advice)
3691 (destructuring-bind (function class advice) func-class-advice
3692 (cond ((ad-advice-enabled advice)
3693 (ad-advice-set-enabled advice nil)
3694 (message "Disabled"))
3695 (t ;disabled
3696 (ad-advice-set-enabled advice t)
3697 (message "Enabled")))
3698 (ad-activate function)
3699 (and anything-in-persistent-action
3700 (anything-c-advice-update-current-display-string))))
3702 (defun anything-c-advice-update-current-display-string ()
3703 (anything-edit-current-selection
3704 (let ((newword (cond ((looking-at "Disabled") "Enabled")
3705 ((looking-at "Enabled") "Disabled")))
3706 realvalue)
3707 (when newword
3708 (delete-region (point) (progn (forward-word 1) (point)))
3709 (insert newword)))))
3711 ;;;###autoload
3712 (defun anything-manage-advice ()
3713 "Preconfigured `anything' to disable/enable function advices."
3714 (interactive)
3715 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
3717 ;;;; <Variable>
3718 ;;; Emacs variables
3719 (defvar anything-c-source-emacs-variables
3720 '((name . "Emacs Variables")
3721 (candidates . (lambda ()
3722 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
3723 (type . variable)
3724 (requires-pattern . 2))
3725 "Source for completing Emacs variables.")
3726 ;; (anything 'anything-c-source-emacs-variables)
3728 ;;;; <Bookmark>
3729 ;;; Bookmarks
3730 (eval-when-compile (require 'bookmark))
3731 (defvar anything-c-source-bookmarks
3732 '((name . "Bookmarks")
3733 (init . (lambda ()
3734 (require 'bookmark)))
3735 (candidates . bookmark-all-names)
3736 (type . bookmark))
3737 "See (info \"(emacs)Bookmarks\").")
3738 ;; (anything 'anything-c-source-bookmarks)
3740 ;;; bookmark-set
3741 (defvar anything-c-source-bookmark-set
3742 '((name . "Set Bookmark")
3743 (dummy)
3744 (action . bookmark-set))
3745 "See (info \"(emacs)Bookmarks\").")
3746 ;; (anything 'anything-c-source-bookmark-set)
3748 ;;; Visible Bookmarks
3749 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
3752 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
3753 (defvar anything-c-source-bm
3754 '((name . "Visible Bookmarks")
3755 (init . anything-c-bm-init)
3756 (candidates-in-buffer)
3757 (type . line))
3758 "Needs bm.el.
3760 http://www.nongnu.org/bm/")
3762 (defun anything-c-bm-init ()
3763 "Init function for `anything-c-source-bm'."
3764 (when (require 'bm nil t)
3765 (with-no-warnings
3766 (let ((bookmarks (bm-lists))
3767 (buf (anything-candidate-buffer 'global)))
3768 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
3769 '< :key 'overlay-start))
3770 (let ((start (overlay-start bm))
3771 (end (overlay-end bm))
3772 (annotation (or (overlay-get bm 'annotation) "")))
3773 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
3774 (let ((str (format "%5d: [%s]: %s\n"
3775 (line-number-at-pos start)
3776 annotation
3777 (buffer-substring start (1- end)))))
3778 (with-current-buffer buf (insert str))))))))))
3780 ;;; Special bookmarks
3781 (defvar anything-c-source-bookmarks-ssh
3782 '((name . "Bookmarks-ssh")
3783 (init . (lambda ()
3784 (require 'bookmark)))
3785 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
3786 (type . bookmark))
3787 "See (info \"(emacs)Bookmarks\").")
3788 ;; (anything 'anything-c-source-bookmarks-ssh)
3790 (defvar anything-c-source-bookmarks-su
3791 '((name . "Bookmarks-root")
3792 (init . (lambda ()
3793 (require 'bookmark)))
3794 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
3795 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
3797 (type . bookmark))
3798 "See (info \"(emacs)Bookmarks\").")
3799 ;; (anything 'anything-c-source-bookmarks-su)
3801 (defvar anything-c-source-bookmarks-local
3802 '((name . "Bookmarks-Local")
3803 (init . (lambda ()
3804 (require 'bookmark)))
3805 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
3806 (filtered-candidate-transformer
3807 anything-c-adaptive-sort
3808 anything-c-highlight-bookmark)
3809 (type . bookmark))
3810 "See (info \"(emacs)Bookmarks\").")
3811 ;; (anything 'anything-c-source-bookmarks-local)
3813 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
3814 (let* ((lis-all (bookmark-all-names))
3815 (lis-loc (cond (local (loop for i in lis-all
3816 unless (string-match "^(ssh)\\|^(su)" i)
3817 collect i))
3818 (su (loop for i in lis-all
3819 when (string-match "^(su)" i)
3820 collect i))
3821 (sudo (loop for i in lis-all
3822 when (string-match "^(sudo)" i)
3823 collect i))
3824 (ssh (loop for i in lis-all
3825 when (string-match "^(ssh)" i)
3826 collect i)))))
3827 (sort lis-loc 'string-lessp)))
3829 (defun anything-c-bookmark-root-logged-p ()
3830 (catch 'break
3831 (dolist (i (mapcar #'buffer-name (buffer-list)))
3832 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
3833 (throw 'break t)))))
3835 (defun anything-c-highlight-bookmark-su (files source)
3836 (if (anything-c-bookmark-root-logged-p)
3837 (anything-c-highlight-bookmark files source)
3838 (anything-c-highlight-not-logged files source)))
3840 (defun anything-c-highlight-not-logged (files source)
3841 (loop for i in files
3842 collect (propertize i 'face anything-c-bookmarks-face3)))
3844 (defun anything-c-highlight-bookmark (bookmarks source)
3845 "Used as `candidate-transformer' to colorize bookmarks.
3846 Work both with standard Emacs bookmarks and bookmark-extensions.el."
3847 (loop for i in bookmarks
3848 for isfile = (bookmark-get-filename i)
3849 for bufp = (and (fboundp 'bmkext-get-buffer-name)
3850 (bmkext-get-buffer-name i))
3851 for handlerp = (and (fboundp 'bookmark-get-handler)
3852 (bookmark-get-handler i))
3853 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
3854 (bmkext-w3m-bookmark-p i))
3855 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
3856 (bmkext-gnus-bookmark-p i))
3857 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
3858 (bmkext-man-bookmark-p i))
3859 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
3860 (bmkext-woman-bookmark-p i))
3861 for handlerp = (bookmark-get-handler i)
3862 for isannotation = (bookmark-get-annotation i)
3863 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
3864 for isinfo = (eq handlerp 'Info-bookmark-jump)
3865 ;; Add a * if bookmark have annotation
3866 if (and isannotation (not (string-equal isannotation "")))
3867 do (setq i (concat "*" i))
3868 collect (cond (;; info buffers
3869 isinfo
3870 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
3871 (;; w3m buffers
3872 isw3m
3873 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
3874 (;; gnus buffers
3875 isgnus
3876 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
3877 (;; Man Woman
3878 (or iswoman isman)
3879 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
3880 (;; Addressbook
3881 isabook
3882 (propertize i 'face '((:foreground "Tomato"))))
3883 (;; directories
3884 (and isfile (file-directory-p isfile))
3885 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
3886 (;; regular files
3888 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
3891 ;;; Faces for bookmarks
3892 (defface anything-bmkext-info
3893 '((t (:foreground "green")))
3894 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3895 :group 'anything)
3897 (defface anything-bmkext-w3m
3898 '((t (:foreground "yellow")))
3899 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3900 :group 'anything)
3902 (defface anything-bmkext-gnus
3903 '((t (:foreground "magenta")))
3904 "*Face used for Gnus bookmarks."
3905 :group 'anything)
3907 (defface anything-bmkext-man
3908 '((t (:foreground "Orange4")))
3909 "*Face used for Woman/man bookmarks."
3910 :group 'anything)
3912 (defface anything-bmkext-no--file
3913 '((t (:foreground "grey")))
3914 "*Face used for non--file bookmarks."
3915 :group 'anything)
3917 (defface anything-bmkext-file
3918 '((t (:foreground "Deepskyblue2")))
3919 "*Face used for non--file bookmarks."
3920 :group 'anything)
3922 (defface anything-bookmarks-su-face '((t (:foreground "red")))
3923 "Face for su/sudo bookmarks."
3924 :group 'anything)
3926 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
3927 (defvar anything-c-bookmarks-face2 'anything-file-name)
3928 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
3931 ;;; Sources to filter bookmark-extensions bookmarks.
3932 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3933 ;; If you want to enable google-maps in addressbook you will need
3934 ;; Julien Danjou google-maps-el package available here:
3935 ;; http://julien.danjou.info/google-maps-el.html
3937 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
3938 "Return a filtered `bookmark-alist' sorted alphabetically."
3939 (loop
3940 with alist = (if args
3941 (apply #'(lambda (x) (funcall fn x)) args)
3942 (funcall fn))
3943 for i in alist
3944 for b = (car i)
3945 collect b into sa
3946 finally return (sort sa 'string-lessp)))
3948 ;; Addressbook
3949 (defvar anything-c-source-bmkext-addressbook
3950 '((name . "Bookmark Addressbook")
3951 (init . (lambda ()
3952 (require 'bookmark-extensions)
3953 (bookmark-maybe-load-default-file)))
3954 (candidates . anything-c-bmkext-addressbook-setup-alist)
3955 (persistent-action
3956 . (lambda (candidate)
3957 (let ((bmk (anything-bookmark-get-bookmark-from-name
3958 candidate)))
3959 (bookmark--jump-via bmk 'pop-to-buffer))))
3960 (persistent-help . "Show contact - Prefix with C-u to append")
3961 (filtered-candidate-transformer
3962 anything-c-adaptive-sort
3963 anything-c-highlight-bookmark)
3964 (action . (("Show person's data"
3965 . (lambda (candidate)
3966 (let ((bmk (anything-bookmark-get-bookmark-from-name
3967 candidate))
3968 (current-prefix-arg anything-current-prefix-arg))
3969 (bookmark-jump bmk))))
3970 ("Send Mail"
3971 . (lambda (candidate)
3972 (let ((bmk (anything-bookmark-get-bookmark-from-name
3973 candidate)))
3974 (if anything-current-prefix-arg
3975 (addressbook-set-mail-buffer1 bmk 'append)
3976 (addressbook-set-mail-buffer1 bmk)))))
3977 ("Edit Bookmark"
3978 . (lambda (candidate)
3979 (let ((bmk (anything-bookmark-get-bookmark-from-name
3980 candidate)))
3981 (addressbook-bookmark-edit
3982 (assoc bmk bookmark-alist)))))
3983 ("Insert Email at point"
3984 . (lambda (candidate)
3985 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3986 candidate))
3987 (mlist (split-string
3988 (assoc-default
3989 'email (assoc bmk bookmark-alist))
3990 ", ")))
3991 (insert
3992 (if (> (length mlist) 1)
3993 (anything-comp-read
3994 "Insert Mail Address: " mlist :must-match t)
3995 (car mlist))))))
3996 ("Show annotation"
3997 . (lambda (candidate)
3998 (let ((bmk (anything-bookmark-get-bookmark-from-name
3999 candidate)))
4000 (bookmark-show-annotation bmk))))
4001 ("Edit annotation"
4002 . (lambda (candidate)
4003 (let ((bmk (anything-bookmark-get-bookmark-from-name
4004 candidate)))
4005 (bookmark-edit-annotation bmk))))
4006 ("Show Google map"
4007 . (lambda (candidate)
4008 (let* ((bmk (anything-bookmark-get-bookmark-from-name
4009 candidate))
4010 (full-bmk (assoc bmk bookmark-alist)))
4011 (addressbook-google-map full-bmk))))))))
4014 (defun anything-c-bmkext-addressbook-setup-alist ()
4015 "Specialized filter function for bookmarks w3m."
4016 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
4018 ;; W3m
4019 (defvar anything-c-source-bookmark-w3m
4020 '((name . "Bookmark W3m")
4021 (init . (lambda ()
4022 (require 'bookmark-extensions)
4023 (bookmark-maybe-load-default-file)))
4024 (candidates . anything-c-bookmark-w3m-setup-alist)
4025 (filtered-candidate-transformer
4026 anything-c-adaptive-sort
4027 anything-c-highlight-bookmark)
4028 (type . bookmark)))
4029 ;; (anything 'anything-c-source-bookmark-w3m)
4031 (defun anything-c-bookmark-w3m-setup-alist ()
4032 "Specialized filter function for bookmarks w3m."
4033 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
4035 ;; Images
4036 (defvar anything-c-source-bookmark-images
4037 '((name . "Bookmark Images")
4038 (init . (lambda ()
4039 (require 'bookmark-extensions)
4040 (bookmark-maybe-load-default-file)))
4041 (candidates . anything-c-bookmark-images-setup-alist)
4042 (filtered-candidate-transformer
4043 anything-c-adaptive-sort
4044 anything-c-highlight-bookmark)
4045 (type . bookmark)))
4046 ;; (anything 'anything-c-source-bookmark-images)
4048 (defun anything-c-bookmark-images-setup-alist ()
4049 "Specialized filter function for images bookmarks."
4050 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
4052 ;; Woman Man
4053 (defvar anything-c-source-bookmark-man
4054 '((name . "Bookmark Woman&Man")
4055 (init . (lambda ()
4056 (require 'bookmark-extensions)
4057 (bookmark-maybe-load-default-file)))
4058 (candidates . anything-c-bookmark-man-setup-alist)
4059 (filtered-candidate-transformer
4060 anything-c-adaptive-sort
4061 anything-c-highlight-bookmark)
4062 (type . bookmark)))
4063 ;; (anything 'anything-c-source-bookmark-man)
4065 (defun anything-c-bookmark-man-setup-alist ()
4066 "Specialized filter function for bookmarks w3m."
4067 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
4068 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
4070 ;; Gnus
4071 (defvar anything-c-source-bookmark-gnus
4072 '((name . "Bookmark Gnus")
4073 (init . (lambda ()
4074 (require 'bookmark-extensions)
4075 (bookmark-maybe-load-default-file)))
4076 (candidates . anything-c-bookmark-gnus-setup-alist)
4077 (filtered-candidate-transformer
4078 anything-c-adaptive-sort
4079 anything-c-highlight-bookmark)
4080 (type . bookmark)))
4081 ;; (anything 'anything-c-source-bookmark-gnus)
4083 (defun anything-c-bookmark-gnus-setup-alist ()
4084 "Specialized filter function for bookmarks gnus."
4085 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
4087 ;; Info
4088 (defvar anything-c-source-bookmark-info
4089 '((name . "Bookmark Info")
4090 (init . (lambda ()
4091 (require 'bookmark-extensions)
4092 (bookmark-maybe-load-default-file)))
4093 (candidates . anything-c-bookmark-info-setup-alist)
4094 (filtered-candidate-transformer
4095 anything-c-adaptive-sort
4096 anything-c-highlight-bookmark)
4097 (type . bookmark)))
4098 ;; (anything 'anything-c-source-bookmark-info)
4100 (defun anything-c-bookmark-info-setup-alist ()
4101 "Specialized filter function for bookmarks info."
4102 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
4104 ;; Local Files&directories
4105 (defvar anything-c-source-bookmark-files&dirs
4106 '((name . "Bookmark Files&Directories")
4107 (init . (lambda ()
4108 (require 'bookmark-extensions)
4109 (bookmark-maybe-load-default-file)))
4110 (candidates . anything-c-bookmark-local-files-setup-alist)
4111 (filtered-candidate-transformer
4112 anything-c-adaptive-sort
4113 anything-c-highlight-bookmark)
4114 (type . bookmark)))
4115 ;; (anything 'anything-c-source-bookmark-files&dirs)
4117 (defun anything-c-bookmark-local-files-setup-alist ()
4118 "Specialized filter function for bookmarks locals files."
4119 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
4121 ;; Su Files&directories
4122 (defvar anything-c-source-bookmark-su-files&dirs
4123 '((name . "Bookmark Root-Files&Directories")
4124 (init . (lambda ()
4125 (require 'bookmark-extensions)
4126 (bookmark-maybe-load-default-file)))
4127 (candidates . anything-c-bookmark-su-files-setup-alist)
4128 (filtered-candidate-transformer
4129 anything-c-adaptive-sort
4130 anything-c-highlight-bookmark-su)
4131 (type . bookmark)))
4132 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
4134 (defun anything-c-bookmark-su-files-setup-alist ()
4135 "Specialized filter function for bookmarks su/sudo files."
4136 (loop
4137 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
4138 for i in l
4139 for isfile = (bookmark-get-filename i)
4140 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
4141 (save-match-data
4142 (string-match tramp-file-name-regexp isfile)))
4143 for issu = (and istramp
4144 (string-match bmkext-su-or-sudo-regexp isfile))
4145 if issu
4146 collect i))
4148 ;; Ssh Files&directories
4149 (defvar anything-c-source-bookmark-ssh-files&dirs
4150 '((name . "Bookmark Ssh-Files&Directories")
4151 (init . (lambda ()
4152 (require 'bookmark-extensions)
4153 (bookmark-maybe-load-default-file)))
4154 (candidates . anything-c-bookmark-ssh-files-setup-alist)
4155 (filtered-candidate-transformer . anything-c-adaptive-sort)
4156 (type . bookmark)))
4157 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
4159 (defun anything-c-bookmark-ssh-files-setup-alist ()
4160 "Specialized filter function for bookmarks ssh files."
4161 (loop
4162 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
4163 for i in l
4164 for isfile = (bookmark-get-filename i)
4165 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
4166 (save-match-data
4167 (string-match tramp-file-name-regexp isfile)))
4168 for isssh = (and istramp
4169 (string-match "/ssh:" isfile))
4170 if isssh
4171 collect i))
4174 ;; All bookmark-extensions sources.
4175 ;;;###autoload
4176 (defun anything-bookmark-ext ()
4177 "Preconfigured `anything' for bookmark-extensions sources.
4178 Needs bookmark-ext.el
4180 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
4181 (interactive)
4182 (anything
4183 :sources
4184 '(anything-c-source-bookmark-files&dirs
4185 anything-c-source-bookmark-w3m
4186 anything-c-source-bmkext-addressbook
4187 anything-c-source-bookmark-gnus
4188 anything-c-source-bookmark-info
4189 anything-c-source-bookmark-man
4190 anything-c-source-bookmark-images
4191 anything-c-source-bookmark-su-files&dirs
4192 anything-c-source-bookmark-ssh-files&dirs)
4193 :prompt "SearchBookmark: "
4194 :buffer "*anything bmkext*"))
4197 ;; Firefox bookmarks
4198 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
4199 ;; (only for firefox versions >=3)
4200 ;; To achieve that, open about:config in firefox and double click on this line to enable value
4201 ;; to true:
4202 ;; user_pref("browser.bookmarks.autoExportHTML", false);
4203 ;; You should have now:
4204 ;; user_pref("browser.bookmarks.autoExportHTML", true);
4206 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
4207 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
4209 (defun anything-get-firefox-user-init-dir ()
4210 "Guess the default Firefox user directory name."
4211 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
4212 (moz-user-dir
4213 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
4214 (goto-char (point-min))
4215 (prog1
4216 (when (search-forward "Path=" nil t)
4217 (buffer-substring-no-properties (point) (point-at-eol)))
4218 (kill-buffer)))))
4219 (file-name-as-directory (concat moz-dir moz-user-dir))))
4221 (defun anything-guess-firefox-bookmark-file ()
4222 "Return the path of the Firefox bookmarks file."
4223 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
4225 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
4226 "Parse html bookmark FILE and return an alist with (title . url) as elements."
4227 (let (bookmarks-alist url title)
4228 (with-temp-buffer
4229 (insert-file-contents file)
4230 (goto-char (point-min))
4231 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
4232 (forward-line 0)
4233 (when (re-search-forward url-regexp nil t)
4234 (setq url (match-string 0)))
4235 (when (re-search-forward bmk-regexp nil t)
4236 (setq title (match-string 1)))
4237 (push (cons title url) bookmarks-alist)
4238 (forward-line)))
4239 (nreverse bookmarks-alist)))
4241 (defvar anything-c-firefox-bookmarks-alist nil)
4242 (defvar anything-c-source-firefox-bookmarks
4243 '((name . "Firefox Bookmarks")
4244 (init . (lambda ()
4245 (setq anything-c-firefox-bookmarks-alist
4246 (anything-html-bookmarks-to-alist
4247 (anything-guess-firefox-bookmark-file)
4248 anything-firefox-bookmark-url-regexp
4249 anything-firefox-bookmarks-regexp))))
4250 (candidates . (lambda ()
4251 (mapcar #'car anything-c-firefox-bookmarks-alist)))
4252 (filtered-candidate-transformer
4253 anything-c-adaptive-sort
4254 anything-c-highlight-firefox-bookmarks)
4255 (action . (("Browse Url Firefox"
4256 . (lambda (candidate)
4257 (browse-url-firefox
4258 (anything-c-firefox-bookmarks-get-value candidate))))
4259 ("Browse Url w3m"
4260 . (lambda (candidate)
4261 (w3m-browse-url
4262 (anything-c-firefox-bookmarks-get-value candidate))))
4263 ("Copy Url"
4264 . (lambda (elm)
4265 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
4267 ;; (anything 'anything-c-source-firefox-bookmarks)
4269 (defun anything-c-firefox-bookmarks-get-value (elm)
4270 (assoc-default elm anything-c-firefox-bookmarks-alist))
4272 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
4273 (loop for i in bookmarks
4274 collect (propertize
4275 i 'face '((:foreground "YellowGreen"))
4276 'help-echo (anything-c-firefox-bookmarks-get-value i))))
4278 ;; W3m bookmark
4279 (eval-when-compile (require 'w3m-bookmark nil t))
4280 (unless (and (require 'w3m nil t)
4281 (require 'w3m-bookmark nil t))
4282 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
4285 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
4286 "Face for w3m bookmarks" :group 'anything)
4288 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
4289 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
4290 (defvar anything-c-w3m-bookmarks-alist nil)
4291 (defvar anything-c-source-w3m-bookmarks
4292 '((name . "W3m Bookmarks")
4293 (init . (lambda ()
4294 (setq anything-c-w3m-bookmarks-alist
4295 (anything-html-bookmarks-to-alist
4296 w3m-bookmark-file
4297 anything-w3m-bookmark-url-regexp
4298 anything-w3m-bookmarks-regexp))))
4299 (candidates . (lambda ()
4300 (mapcar #'car anything-c-w3m-bookmarks-alist)))
4301 (filtered-candidate-transformer
4302 anything-c-adaptive-sort
4303 anything-c-highlight-w3m-bookmarks)
4304 (action . (("Browse Url"
4305 . (lambda (candidate)
4306 (anything-c-w3m-browse-bookmark candidate)))
4307 ("Copy Url"
4308 . (lambda (elm)
4309 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
4310 ("Browse Url Firefox"
4311 . (lambda (candidate)
4312 (anything-c-w3m-browse-bookmark candidate t)))
4313 ("Delete Bookmark"
4314 . (lambda (candidate)
4315 (anything-c-w3m-delete-bookmark candidate)))
4316 ("Rename Bookmark"
4317 . (lambda (candidate)
4318 (anything-c-w3m-rename-bookmark candidate)))))
4319 (persistent-action . (lambda (candidate)
4320 (if current-prefix-arg
4321 (anything-c-w3m-browse-bookmark candidate t)
4322 (anything-c-w3m-browse-bookmark candidate nil t))))
4323 (persistent-help . "Open URL with emacs-w3m in new tab / \
4324 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
4325 "Needs w3m and emacs-w3m.
4327 http://w3m.sourceforge.net/
4328 http://emacs-w3m.namazu.org/")
4330 ;; (anything 'anything-c-source-w3m-bookmarks)
4332 (defun anything-c-w3m-bookmarks-get-value (elm)
4333 (replace-regexp-in-string
4334 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
4336 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
4337 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
4338 (arg (and (eq fn 'w3m-browse-url) new-tab)))
4339 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
4341 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
4342 (loop for i in bookmarks
4343 collect (propertize
4344 i 'face 'anything-w3m-bookmarks-face
4345 'help-echo (anything-c-w3m-bookmarks-get-value i))))
4348 (defun anything-c-w3m-delete-bookmark (elm)
4349 (save-excursion
4350 (find-file-literally w3m-bookmark-file)
4351 (goto-char (point-min))
4352 (when (re-search-forward elm nil t)
4353 (beginning-of-line)
4354 (delete-region (point)
4355 (line-end-position))
4356 (delete-blank-lines))
4357 (save-buffer (current-buffer))
4358 (kill-buffer (current-buffer))))
4360 (defun anything-c-w3m-rename-bookmark (elm)
4361 (let* ((old-title (replace-regexp-in-string ">" "" elm))
4362 (new-title (read-string "NewTitle: " old-title)))
4363 (save-excursion
4364 (find-file-literally w3m-bookmark-file)
4365 (goto-char (point-min))
4366 (when (re-search-forward (concat elm "<") nil t)
4367 (goto-char (1- (point)))
4368 (delete-char (- (length old-title)))
4369 (insert new-title))
4370 (save-buffer (current-buffer))
4371 (kill-buffer (current-buffer)))))
4373 ;;;; <Library>
4374 ;;; Elisp library scan
4375 (defvar anything-c-source-elisp-library-scan
4376 '((name . "Elisp libraries (Scan)")
4377 (init . (anything-c-elisp-library-scan-init))
4378 (candidates-in-buffer)
4379 (action ("Find library"
4380 . (lambda (candidate) (find-file (find-library-name candidate))))
4381 ("Find library other window"
4382 . (lambda (candidate)
4383 (find-file-other-window (find-library-name candidate))))
4384 ("Load library"
4385 . (lambda (candidate) (load-library candidate))))))
4386 ;; (anything 'anything-c-source-elisp-library-scan)
4388 (defun anything-c-elisp-library-scan-init ()
4389 "Init anything buffer status."
4390 (let ((anything-buffer (anything-candidate-buffer 'global))
4391 (library-list (anything-c-elisp-library-scan-list)))
4392 (with-current-buffer anything-buffer
4393 (dolist (library library-list)
4394 (insert (format "%s\n" library))))))
4396 (defun anything-c-elisp-library-scan-list (&optional dirs string)
4397 "Do completion for file names passed to `locate-file'.
4398 DIRS is directory to search path.
4399 STRING is string to match."
4400 ;; Use `load-path' as path when ignore `dirs'.
4401 (or dirs (setq dirs load-path))
4402 ;; Init with blank when ignore `string'.
4403 (or string (setq string ""))
4404 ;; Get library list.
4405 (let ((string-dir (file-name-directory string))
4406 ;; File regexp that suffix match `load-file-rep-suffixes'.
4407 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
4408 name
4409 names)
4410 (dolist (dir dirs)
4411 (unless dir
4412 (setq dir default-directory))
4413 (if string-dir
4414 (setq dir (expand-file-name string-dir dir)))
4415 (when (file-directory-p dir)
4416 (dolist (file (file-name-all-completions
4417 (file-name-nondirectory string) dir))
4418 ;; Suffixes match `load-file-rep-suffixes'.
4419 (setq name (if string-dir (concat string-dir file) file))
4420 (if (string-match match-regexp name)
4421 (add-to-list 'names name)))))
4422 names))
4424 ;;;; <Programming>
4425 ;;; Imenu
4426 (defvar anything-c-imenu-delimiter " / ")
4428 (defvar anything-c-imenu-index-filter nil)
4429 (make-variable-buffer-local 'anything-c-imenu-index-filter)
4431 (defvar anything-c-cached-imenu-alist nil)
4432 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
4434 (defvar anything-c-cached-imenu-candidates nil)
4435 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
4437 (defvar anything-c-cached-imenu-tick nil)
4438 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
4440 (eval-when-compile (require 'imenu))
4441 (setq imenu-auto-rescan t)
4443 (defun anything-imenu-create-candidates (entry)
4444 "Create candidates with ENTRY."
4445 (if (listp (cdr entry))
4446 (mapcan
4447 (lambda (sub)
4448 (if (consp (cdr sub))
4449 (mapcar
4450 (lambda (subentry)
4451 (concat (car entry) anything-c-imenu-delimiter subentry))
4452 (anything-imenu-create-candidates sub))
4453 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
4454 (cdr entry))
4455 (list entry)))
4457 (defvar anything-c-source-imenu
4458 '((name . "Imenu")
4459 (init . (lambda () (require 'imenu)))
4460 (candidates . anything-c-imenu-candidates)
4461 (persistent-action . (lambda (elm)
4462 (anything-c-imenu-default-action elm)
4463 (unless (fboundp 'semantic-imenu-tag-overlay)
4464 (anything-match-line-color-current-line))))
4465 (persistent-help . "Show this entry")
4466 (action . anything-c-imenu-default-action))
4467 "See (info \"(emacs)Imenu\")")
4469 ;; (anything 'anything-c-source-imenu)
4471 (defun anything-c-imenu-candidates ()
4472 (with-current-buffer anything-current-buffer
4473 (let ((tick (buffer-modified-tick)))
4474 (if (eq anything-c-cached-imenu-tick tick)
4475 anything-c-cached-imenu-candidates
4476 (setq imenu--index-alist nil)
4477 (setq anything-c-cached-imenu-tick tick
4478 anything-c-cached-imenu-candidates
4479 (ignore-errors
4480 (mapcan
4481 'anything-imenu-create-candidates
4482 (setq anything-c-cached-imenu-alist
4483 (let ((index (imenu--make-index-alist)))
4484 (if anything-c-imenu-index-filter
4485 (funcall anything-c-imenu-index-filter index)
4486 index))))))
4487 (setq anything-c-cached-imenu-candidates
4488 (mapcar #'(lambda (x)
4489 (if (stringp x)
4491 (car x)))
4492 anything-c-cached-imenu-candidates))))))
4494 (setq imenu-default-goto-function 'imenu-default-goto-function)
4495 (defun anything-c-imenu-default-action (elm)
4496 "The default action for `anything-c-source-imenu'."
4497 (let ((path (split-string elm anything-c-imenu-delimiter))
4498 (alist anything-c-cached-imenu-alist))
4499 (if (> (length path) 1)
4500 (progn
4501 (setq alist (assoc (car path) alist))
4502 (setq elm (cadr path))
4503 (imenu (assoc elm alist)))
4504 (imenu (assoc elm alist)))))
4506 ;;; Ctags
4507 (defvar anything-c-ctags-modes
4508 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
4509 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
4510 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
4512 (defun anything-c-source-ctags-init ()
4513 (when (and buffer-file-name
4514 (memq major-mode anything-c-ctags-modes)
4515 (anything-current-buffer-is-modified))
4516 (with-current-buffer (anything-candidate-buffer 'local)
4517 (call-process-shell-command
4518 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
4519 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
4520 anything-buffer-file-name)
4521 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
4522 nil (current-buffer))
4523 (goto-char (point-min))
4524 (forward-line 2)
4525 (delete-region (point-min) (point))
4526 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
4527 for lineno-start = (point)
4528 for lineno = (buffer-substring
4529 lineno-start
4530 (1- (search-forward "," (point-at-eol) t)))
4532 (beginning-of-line)
4533 (insert (format "%5s:" lineno))
4534 (search-forward "\177" (point-at-eol) t)
4535 (delete-region (1- (point)) (point-at-eol))
4536 (forward-line 1)))))
4538 (defvar anything-c-source-ctags
4539 '((name . "Exuberant ctags")
4540 (init . anything-c-source-ctags-init)
4541 (candidates-in-buffer)
4542 (adjust)
4543 (type . line))
4544 "Needs Exuberant Ctags.
4546 http://ctags.sourceforge.net/")
4547 ;; (anything 'anything-c-source-ctags)
4549 ;; Semantic
4550 (eval-when-compile (require 'semantic nil t))
4551 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
4552 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
4553 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
4554 (defvar anything-semantic-candidates nil)
4556 (defun anything-semantic-construct-candidates (tags depth)
4557 (when (require 'semantic nil t)
4558 (apply
4559 'append
4560 (mapcar
4561 (lambda (tag)
4562 (if (listp tag)
4563 (let ((type (semantic-tag-type tag))
4564 (class (semantic-tag-class tag)))
4565 (if (or (and (stringp type)
4566 (or (string= type "class")
4567 (string= type "namespace")))
4568 (eq class 'function)
4569 (eq class 'variable))
4570 (cons (cons (concat (make-string (* depth 2) ?\s)
4571 (semantic-format-tag-summarize tag nil t))
4572 tag)
4573 (anything-semantic-construct-candidates
4574 (semantic-tag-components tag) (1+ depth)))))))
4575 tags))))
4577 (defun anything-semantic-default-action (candidate)
4578 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
4579 (semantic-go-to-tag tag)))
4581 (defvar anything-c-source-semantic
4582 '((name . "Semantic Tags")
4583 (init . (lambda ()
4584 (setq anything-semantic-candidates
4585 (ignore-errors (anything-semantic-construct-candidates
4586 (semantic-fetch-tags) 0)))))
4587 (candidates . (lambda ()
4588 (if anything-semantic-candidates
4589 (mapcar 'car anything-semantic-candidates))))
4590 (persistent-action . (lambda (elm)
4591 (anything-semantic-default-action elm)
4592 (anything-match-line-color-current-line)))
4593 (persistent-help . "Show this entry")
4594 (action . anything-semantic-default-action)
4595 "Needs semantic in CEDET.
4597 http://cedet.sourceforge.net/semantic.shtml
4598 http://cedet.sourceforge.net/"))
4600 ;; (anything 'anything-c-source-semantic)
4602 ;;; Function is called by
4603 ;;;###autoload
4604 (defun anything-simple-call-tree ()
4605 "Preconfigured `anything' for simple-call-tree. List function relationships.
4607 Needs simple-call-tree.el.
4608 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
4609 (interactive)
4610 (anything-other-buffer
4611 '(anything-c-source-simple-call-tree-functions-callers
4612 anything-c-source-simple-call-tree-callers-functions)
4613 "*anything simple-call-tree*"))
4615 (defvar anything-c-source-simple-call-tree-functions-callers
4616 '((name . "Function is called by")
4617 (init . anything-c-simple-call-tree-functions-callers-init)
4618 (multiline)
4619 (candidates . anything-c-simple-call-tree-candidates)
4620 (persistent-action . anything-c-simple-call-tree-persistent-action)
4621 (persistent-help . "Show function definitions by rotation")
4622 (action ("Find definition selected by persistent-action" .
4623 anything-c-simple-call-tree-find-definition)))
4624 "Needs simple-call-tree.el.
4625 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4627 (defvar anything-c-simple-call-tree-tick nil)
4628 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
4629 (defun anything-c-simple-call-tree-analyze-maybe ()
4630 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
4631 (simple-call-tree-analyze)
4632 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
4634 (defun anything-c-simple-call-tree-init-base (function message)
4635 (require 'simple-call-tree)
4636 (with-no-warnings
4637 (when (anything-current-buffer-is-modified)
4638 (anything-c-simple-call-tree-analyze-maybe)
4639 (let ((list (funcall function simple-call-tree-alist)))
4640 (with-current-buffer (anything-candidate-buffer 'local)
4641 (dolist (entry list)
4642 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
4643 (insert (car entry) message
4644 (if (string= funcs " ")
4645 " no functions."
4646 funcs)
4647 "\n\n"))))))))
4649 (defun anything-c-simple-call-tree-functions-callers-init ()
4650 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
4651 " is called by\n"))
4653 (defun anything-c-simple-call-tree-candidates ()
4654 (with-current-buffer (anything-candidate-buffer)
4655 (split-string (buffer-string) "\n\n")))
4657 (defvar anything-c-simple-call-tree-related-functions nil)
4658 (defvar anything-c-simple-call-tree-function-index 0)
4659 (defun anything-c-simple-call-tree-persistent-action (candidate)
4660 (unless (eq last-command 'anything-execute-persistent-action)
4661 (setq anything-c-simple-call-tree-related-functions
4662 (delete "no functions."
4663 (split-string
4664 (replace-regexp-in-string " \\| is called by\\| calls "
4665 "" candidate)
4666 "\n")))
4667 (setq anything-c-simple-call-tree-function-index -1))
4668 (incf anything-c-simple-call-tree-function-index)
4669 (anything-c-simple-call-tree-find-definition candidate))
4671 (defun anything-c-simple-call-tree-find-definition (candidate)
4672 (find-function
4673 (intern
4674 (nth (mod anything-c-simple-call-tree-function-index
4675 (length anything-c-simple-call-tree-related-functions))
4676 anything-c-simple-call-tree-related-functions))))
4678 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
4680 ;;; Function calls
4681 (defvar anything-c-source-simple-call-tree-callers-functions
4682 '((name . "Function calls")
4683 (init . anything-c-simple-call-tree-callers-functions-init)
4684 (multiline)
4685 (candidates . anything-c-simple-call-tree-candidates)
4686 (persistent-action . anything-c-simple-call-tree-persistent-action)
4687 (persistent-help . "Show function definitions by rotation")
4688 (action ("Find definition selected by persistent-action" .
4689 anything-c-simple-call-tree-find-definition)))
4690 "Needs simple-call-tree.el.
4691 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4693 (defun anything-c-simple-call-tree-callers-functions-init ()
4694 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
4696 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
4698 ;;; Commands/Options with doc
4699 (defvar anything-c-auto-document-data nil)
4700 (make-variable-buffer-local 'anything-c-auto-document-data)
4701 (defvar anything-c-source-commands-and-options-in-file
4702 '((name . "Commands/Options in file")
4703 (header-name
4704 . (lambda (x) (format "Commands/Options in %s"
4705 (buffer-local-value 'buffer-file-name
4706 anything-current-buffer))))
4707 (candidates . anything-command-and-options-candidates)
4708 (multiline)
4709 (action . imenu))
4710 "List Commands and Options with doc. It needs auto-document.el .
4712 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
4714 (eval-when-compile (require 'auto-document nil t))
4715 (defun anything-command-and-options-candidates ()
4716 (with-current-buffer anything-current-buffer
4717 (when (and (require 'auto-document nil t)
4718 (eq major-mode 'emacs-lisp-mode)
4719 (or (anything-current-buffer-is-modified)
4720 (not anything-c-auto-document-data)))
4721 (or imenu--index-alist (imenu--make-index-alist t))
4722 (setq anything-c-auto-document-data
4723 (destructuring-bind (commands options)
4724 (adoc-construct anything-current-buffer)
4725 (append
4726 (loop for (command . doc) in commands
4727 for cmdname = (symbol-name command)
4728 collect
4729 (cons
4730 (format "Command: %s\n %s"
4731 (propertize cmdname 'face font-lock-function-name-face)
4732 (adoc-first-line doc))
4733 (assoc cmdname imenu--index-alist)))
4734 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
4735 for (option doc default) in options
4736 for optname = (symbol-name option)
4737 collect
4738 (cons
4739 (format "Option: %s\n %s\n default = %s"
4740 (propertize optname 'face font-lock-variable-name-face)
4741 (adoc-first-line doc)
4742 (adoc-prin1-to-string default))
4743 (assoc optname
4744 var-alist)))))))
4745 anything-c-auto-document-data))
4747 ;; (anything 'anything-c-source-commands-and-options-in-file)
4749 ;;;; <Color and Face>
4750 ;;; Customize Face
4751 (defvar anything-c-source-customize-face
4752 '((name . "Customize Face")
4753 (init . (lambda ()
4754 (unless (anything-candidate-buffer)
4755 (save-window-excursion (list-faces-display))
4756 (anything-candidate-buffer (get-buffer "*Faces*")))))
4757 (candidates-in-buffer)
4758 (get-line . buffer-substring)
4759 (action . (lambda (line)
4760 (customize-face (intern (car (split-string line))))))
4761 (requires-pattern . 3))
4762 "See (info \"(emacs)Faces\")")
4763 ;; (anything 'anything-c-source-customize-face)
4765 ;; Color
4766 (defvar anything-c-source-colors
4767 '((name . "Colors")
4768 (init . (lambda () (unless (anything-candidate-buffer)
4769 (save-window-excursion (list-colors-display))
4770 (anything-candidate-buffer (get-buffer "*Colors*")))))
4771 (candidates-in-buffer)
4772 (get-line . buffer-substring)
4773 (action
4774 ("Copy Name" . (lambda (candidate)
4775 (kill-new (anything-c-colors-get-name candidate))))
4776 ("Copy RGB" . (lambda (candidate)
4777 (kill-new (anything-c-colors-get-rgb candidate))))
4778 ("Insert Name" . (lambda (candidate)
4779 (with-current-buffer anything-current-buffer
4780 (insert (anything-c-colors-get-name candidate)))))
4781 ("Insert RGB" . (lambda (candidate)
4782 (with-current-buffer anything-current-buffer
4783 (insert (anything-c-colors-get-rgb candidate))))))))
4784 ;; (anything 'anything-c-source-colors)
4786 (defun anything-c-colors-get-name (candidate)
4787 "Get color name."
4788 (replace-regexp-in-string
4789 " " ""
4790 (with-temp-buffer
4791 (insert (capitalize candidate))
4792 (goto-char (point-min))
4793 (search-forward-regexp "\\s-\\{2,\\}")
4794 (delete-region (point) (point-max))
4795 (buffer-string))))
4797 (defun anything-c-colors-get-rgb (candidate)
4798 "Get color RGB."
4799 (replace-regexp-in-string
4800 " " ""
4801 (with-temp-buffer
4802 (insert (capitalize candidate))
4803 (goto-char (point-max))
4804 (search-backward-regexp "\\s-\\{2,\\}")
4805 (delete-region (point) (point-min))
4806 (buffer-string))))
4808 ;;;; <Search Engine>
4809 ;;; Tracker desktop search
4810 (defvar anything-c-source-tracker-search
4811 '((name . "Tracker Search")
4812 (candidates . (lambda ()
4813 (start-process "tracker-search-process" nil
4814 "tracker-search"
4815 anything-pattern)))
4816 (type . file)
4817 (requires-pattern . 3)
4818 (delayed))
4819 "Source for retrieving files matching the current input pattern
4820 with the tracker desktop search.")
4821 ;; (anything 'anything-c-source-tracker-search)
4823 ;;; Spotlight (MacOS X desktop search)
4824 (defvar anything-c-source-mac-spotlight
4825 '((name . "mdfind")
4826 (candidates
4827 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
4828 (type . file)
4829 (requires-pattern . 3)
4830 (delayed))
4831 "Source for retrieving files via Spotlight's command line
4832 utility mdfind.")
4833 ;; (anything 'anything-c-source-mac-spotlight)
4836 ;;;; <Kill ring>
4837 ;;; Kill ring
4838 (defvar anything-c-source-kill-ring
4839 '((name . "Kill Ring")
4840 (init . (lambda () (anything-attrset 'last-command last-command)))
4841 (candidates . anything-c-kill-ring-candidates)
4842 (action . anything-c-kill-ring-action)
4843 (last-command)
4844 (migemo)
4845 (multiline))
4846 "Source for browse and insert contents of kill-ring.")
4848 (defun anything-c-kill-ring-candidates ()
4849 (loop for kill in kill-ring
4850 unless (or (< (length kill) anything-kill-ring-threshold)
4851 (string-match "^[\\s\\t]+$" kill))
4852 collect kill))
4854 (defun anything-c-kill-ring-action (str)
4855 "Insert STR in `kill-ring' and set STR to the head.
4856 If this action is executed just after `yank',
4857 replace with STR as yanked string."
4858 (setq kill-ring (delete str kill-ring))
4859 (if (not (eq (anything-attr 'last-command) 'yank))
4860 (insert-for-yank str)
4861 ;; from `yank-pop'
4862 (let ((inhibit-read-only t)
4863 (before (< (point) (mark t))))
4864 (if before
4865 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
4866 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
4867 (setq yank-undo-function nil)
4868 (set-marker (mark-marker) (point) (current-buffer))
4869 (insert-for-yank str)
4870 ;; Set the window start back where it was in the yank command,
4871 ;; if possible.
4872 (set-window-start (selected-window) yank-window-start t)
4873 (if before
4874 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
4875 ;; It is cleaner to avoid activation, even though the command
4876 ;; loop would deactivate the mark because we inserted text.
4877 (goto-char (prog1 (mark t)
4878 (set-marker (mark-marker) (point) (current-buffer)))))))
4879 (kill-new str))
4881 ;; (anything 'anything-c-source-kill-ring)
4883 ;;;; <Mark ring>
4884 ;; DO NOT include these sources in `anything-sources' use
4885 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
4886 ;; `anything-all-mark-rings' instead.
4888 (defun anything-c-source-mark-ring-candidates ()
4889 (flet ((get-marks (pos)
4890 (save-excursion
4891 (goto-char pos)
4892 (beginning-of-line)
4893 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
4894 (when (string= "" line)
4895 (setq line "<EMPTY LINE>"))
4896 (format "%7d: %s" (line-number-at-pos) line)))))
4897 (with-current-buffer anything-current-buffer
4898 (loop
4899 with marks = (cons (mark-marker) mark-ring)
4900 with recip = nil
4901 for i in marks
4902 for m = (get-marks i)
4903 unless (member m recip)
4904 collect m into recip
4905 finally return recip))))
4907 (defvar anything-mark-ring-cache nil)
4908 (defvar anything-c-source-mark-ring
4909 '((name . "mark-ring")
4910 (init . (lambda ()
4911 (setq anything-mark-ring-cache
4912 (ignore-errors (anything-c-source-mark-ring-candidates)))))
4913 (candidates . (lambda ()
4914 (anything-aif anything-mark-ring-cache
4915 it)))
4916 (action . (("Goto line"
4917 . (lambda (candidate)
4918 (anything-goto-line (string-to-number candidate))))))
4919 (persistent-action . (lambda (candidate)
4920 (anything-goto-line (string-to-number candidate))
4921 (anything-match-line-color-current-line)))
4922 (persistent-help . "Show this line")))
4924 ;; (anything 'anything-c-source-mark-ring)
4926 ;;;###autoload
4927 (defun anything-mark-ring ()
4928 "Preconfigured `anything' for `anything-c-source-mark-ring'."
4929 (interactive)
4930 (anything 'anything-c-source-mark-ring))
4932 ;;; Global-mark-ring
4933 (defvar anything-c-source-global-mark-ring
4934 '((name . "global-mark-ring")
4935 (candidates . anything-c-source-global-mark-ring-candidates)
4936 (action . (("Goto line"
4937 . (lambda (candidate)
4938 (let ((items (split-string candidate ":")))
4939 (switch-to-buffer (second items))
4940 (anything-goto-line (string-to-number (car items))))))))
4941 (persistent-action . (lambda (candidate)
4942 (let ((items (split-string candidate ":")))
4943 (switch-to-buffer (second items))
4944 (anything-goto-line (string-to-number (car items)))
4945 (anything-match-line-color-current-line))))
4946 (persistent-help . "Show this line")))
4948 (defun anything-c-source-global-mark-ring-candidates ()
4949 (flet ((buf-fn (m)
4950 (with-current-buffer (marker-buffer m)
4951 (goto-char m)
4952 (beginning-of-line)
4953 (let (line)
4954 (if (string= "" line)
4955 (setq line "<EMPTY LINE>")
4956 (setq line (car (split-string (thing-at-point 'line)
4957 "[\n\r]"))))
4958 (format "%7d:%s: %s"
4959 (line-number-at-pos) (marker-buffer m) line)))))
4960 (loop
4961 with marks = global-mark-ring
4962 with recip = nil
4963 for i in marks
4964 for gm = (unless (or (string-match
4965 "^ " (format "%s" (marker-buffer i)))
4966 (null (marker-buffer i)))
4967 (buf-fn i))
4968 when (and gm (not (member gm recip)))
4969 collect gm into recip
4970 finally return recip)))
4972 ;; (anything 'anything-c-source-global-mark-ring)
4974 ;;;###autoload
4975 (defun anything-global-mark-ring ()
4976 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4977 (interactive)
4978 (anything 'anything-c-source-global-mark-ring))
4980 ;;;###autoload
4981 (defun anything-all-mark-rings ()
4982 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4983 `anything-c-source-mark-ring'."
4984 (interactive)
4985 (anything '(anything-c-source-mark-ring
4986 anything-c-source-global-mark-ring)))
4988 ;;;; <Register>
4989 ;;; Insert from register
4990 (defvar anything-c-source-register
4991 '((name . "Registers")
4992 (candidates . anything-c-register-candidates)
4993 (action-transformer . anything-c-register-action-transformer)
4994 (multiline)
4995 (action))
4996 "See (info \"(emacs)Registers\")")
4998 (defun anything-c-register-candidates ()
4999 "Collecting register contents and appropriate commands."
5000 (loop for (char . val) in register-alist
5001 for key = (single-key-description char)
5002 for string-actions =
5003 (cond
5004 ((numberp val)
5005 (list (int-to-string val)
5006 'insert-register
5007 'increment-register))
5008 ((markerp val)
5009 (let ((buf (marker-buffer val)))
5010 (if (null buf)
5011 (list "a marker in no buffer")
5012 (list (concat
5013 "a buffer position:"
5014 (buffer-name buf)
5015 ", position "
5016 (int-to-string (marker-position val)))
5017 'jump-to-register
5018 'insert-register))))
5019 ((and (consp val) (window-configuration-p (car val)))
5020 (list "window configuration."
5021 'jump-to-register))
5022 ((and (consp val) (frame-configuration-p (car val)))
5023 (list "frame configuration."
5024 'jump-to-register))
5025 ((and (consp val) (eq (car val) 'file))
5026 (list (concat "file:"
5027 (prin1-to-string (cdr val))
5028 ".")
5029 'jump-to-register))
5030 ((and (consp val) (eq (car val) 'file-query))
5031 (list (concat "file:a file-query reference: file "
5032 (car (cdr val))
5033 ", position "
5034 (int-to-string (car (cdr (cdr val))))
5035 ".")
5036 'jump-to-register))
5037 ((consp val)
5038 (let ((lines (format "%4d" (length val))))
5039 (list (format "%s: %s\n" lines
5040 (truncate-string-to-width
5041 (mapconcat 'identity (list (car val))
5042 ;; (mapconcat (lambda (y) y) val
5043 "^J") (- (window-width) 15)))
5044 'insert-register)))
5045 ((stringp val)
5046 (list ;; without properties
5047 (substring-no-properties val)
5048 'insert-register
5049 'append-to-register
5050 'prepend-to-register))
5052 "GARBAGE!"))
5053 collect (cons (format "register %3s: %s" key (car string-actions))
5054 (cons char (cdr string-actions)))))
5056 (defun anything-c-register-action-transformer (actions register-and-functions)
5057 "Decide actions by the contents of register."
5058 (loop with func-actions =
5059 '((insert-register
5060 "Insert Register" .
5061 (lambda (c) (insert-register (car c))))
5062 (jump-to-register
5063 "Jump to Register" .
5064 (lambda (c) (jump-to-register (car c))))
5065 (append-to-register
5066 "Append Region to Register" .
5067 (lambda (c) (append-to-register
5068 (car c) (region-beginning) (region-end))))
5069 (prepend-to-register
5070 "Prepend Region to Register" .
5071 (lambda (c) (prepend-to-register
5072 (car c) (region-beginning) (region-end))))
5073 (increment-register
5074 "Increment Prefix Arg to Register" .
5075 (lambda (c) (increment-register
5076 anything-current-prefix-arg (car c)))))
5077 for func in (cdr register-and-functions)
5078 for cell = (assq func func-actions)
5079 when cell
5080 collect (cdr cell)))
5082 ;; (anything 'anything-c-source-register)
5084 ;;;; <Headline Extraction>
5085 (defvar anything-c-source-fixme
5086 '((name . "TODO/FIXME/DRY comments")
5087 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
5088 (adjust)
5089 (recenter))
5090 "Show TODO/FIXME/DRY comments in current file.")
5091 ;; (anything 'anything-c-source-fixme)
5093 (defvar anything-c-source-rd-headline
5094 '((name . "RD HeadLine")
5095 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
5096 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
5097 (migemo)
5098 (subexp . 1))
5099 "Show RD headlines.
5101 RD is Ruby's POD.
5102 http://en.wikipedia.org/wiki/Ruby_Document_format")
5103 ;; (anything 'anything-c-source-rd-headline)
5105 (defvar anything-c-source-oddmuse-headline
5106 '((name . "Oddmuse HeadLine")
5107 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
5108 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
5109 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
5110 (migemo)
5111 (subexp . 1))
5112 "Show Oddmuse headlines, such as EmacsWiki.")
5113 ;; (anything 'anything-c-source-oddmuse-headline)
5115 (defvar anything-c-source-emacs-source-defun
5116 '((name . "Emacs Source DEFUN")
5117 (headline . "DEFUN\\|DEFVAR")
5118 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
5119 (or buffer-file-name ""))))
5120 "Show DEFUN/DEFVAR in Emacs C source file.")
5121 ;; (anything 'anything-c-source-emacs-source-defun)
5123 (defvar anything-c-source-emacs-lisp-expectations
5124 '((name . "Emacs Lisp Expectations")
5125 (headline . "(desc[ ]\\|(expectations")
5126 (condition . (eq major-mode 'emacs-lisp-mode)))
5127 "Show descriptions (desc) in Emacs Lisp Expectations.
5129 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
5130 ;; (anything 'anything-c-source-emacs-lisp-expectations)
5132 (defvar anything-c-source-emacs-lisp-toplevels
5133 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
5134 (headline . "^(\\|(@\\*\\|^;;;;")
5135 (get-line . buffer-substring)
5136 (condition . (eq major-mode 'emacs-lisp-mode))
5137 (adjust))
5138 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
5139 linkd.el is optional because linkd stars are extracted by regexp.
5140 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
5141 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
5143 (defvar anything-c-source-org-headline
5144 '((name . "Org HeadLine")
5145 (headline
5146 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5147 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5148 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5149 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5150 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5151 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5152 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
5153 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
5154 (condition . (eq major-mode 'org-mode))
5155 (migemo)
5156 (subexp . 1)
5157 (persistent-action . (lambda (elm)
5158 (anything-c-action-line-goto elm)
5159 (org-cycle)))
5160 (action-transformer
5161 . (lambda (actions candidate)
5162 '(("Go to Line" . anything-c-action-line-goto)
5163 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
5164 "Show Org headlines.
5165 org-mode is very very much extended text-mode/outline-mode.
5167 See (find-library \"org.el\")
5168 See http://orgmode.org for the latest version.")
5170 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
5171 (insert
5172 (save-excursion
5173 (anything-goto-line (car lineno-and-content))
5174 (and (looking-at org-complex-heading-regexp)
5175 (org-make-link-string (concat "*" (match-string 4)))))))
5177 ;; (anything 'anything-c-source-org-headline)
5179 ;;; Anything yaoddmuse
5180 ;; Be sure to have yaoddmuse.el installed
5181 ;; install-elisp may be required if you want to install elisp file from here.
5182 (defvar anything-yaoddmuse-use-cache-file nil)
5183 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
5184 (defvar anything-c-yaoddmuse-ew-cache nil)
5185 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
5186 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
5187 (candidates . (lambda ()
5188 (if anything-yaoddmuse-use-cache-file
5189 (ignore-errors
5190 (unless anything-c-yaoddmuse-ew-cache
5191 (load anything-c-yaoddmuse-cache-file)
5192 (setq anything-c-yaoddmuse-ew-cache
5193 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
5194 anything-c-yaoddmuse-ew-cache)
5195 (yaoddmuse-update-pagename t)
5196 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
5197 (action . (("Edit page" . (lambda (candidate)
5198 (yaoddmuse-edit "EmacsWiki" candidate)))
5199 ("Browse page" . (lambda (candidate)
5200 (yaoddmuse-browse-page "EmacsWiki" candidate)))
5201 ("Browse page other window" . (lambda (candidate)
5202 (if (one-window-p)
5203 (split-window-vertically))
5204 (yaoddmuse-browse-page "EmacsWiki" candidate)))
5205 ("Browse diff" . (lambda (candidate)
5206 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
5207 ("Copy URL" . (lambda (candidate)
5208 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
5209 (message "Have copy page %s's URL to yank." candidate)))
5210 ("Create page" . (lambda (candidate)
5211 (yaoddmuse-edit "EmacsWiki" anything-input)))
5212 ("Update cache" . (lambda (candidate)
5213 (if anything-yaoddmuse-use-cache-file
5214 (progn
5215 (anything-yaoddmuse-cache-pages t)
5216 (setq anything-c-yaoddmuse-ew-cache
5217 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
5218 (yaoddmuse-update-pagename))))))
5219 (action-transformer anything-c-yaoddmuse-action-transformer))
5220 "Needs yaoddmuse.el.
5222 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5224 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
5226 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
5227 '((name . "Yaoddmuse Post library (EmacsWiki)")
5228 (init . (anything-yaoddmuse-init))
5229 (candidates-in-buffer)
5230 (action . (("Post library and Browse" . (lambda (candidate)
5231 (yaoddmuse-post-file (find-library-name candidate)
5232 "EmacsWiki"
5233 (file-name-nondirectory (find-library-name candidate))
5234 nil t)))
5235 ("Post library" . (lambda (candidate)
5236 (yaoddmuse-post-file (find-library-name candidate)
5237 "EmacsWiki"
5238 (file-name-nondirectory (find-library-name candidate))))))))
5239 "Needs yaoddmuse.el.
5241 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5243 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
5245 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
5246 "Allow the use of `install-elisp' only on elisp files."
5247 (if (string-match "\.el$" candidate)
5248 (append actions '(("Install Elisp" . (lambda (elm)
5249 (install-elisp-from-emacswiki elm)))))
5250 actions))
5252 ;;;###autoload
5253 (defun anything-yaoddmuse-cache-pages (&optional load)
5254 "Fetch the list of files on emacswiki and create cache file.
5255 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
5256 (interactive)
5257 (yaoddmuse-update-pagename)
5258 (save-excursion
5259 (find-file anything-c-yaoddmuse-cache-file)
5260 (erase-buffer)
5261 (insert "(puthash \"EmacsWiki\" '(")
5262 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
5264 (insert (concat "(\"" (car i) "\") ")))
5265 (insert ") yaoddmuse-pages-hash)\n")
5266 (save-buffer)
5267 (kill-buffer (current-buffer))
5268 (when (or current-prefix-arg
5269 load)
5270 (load anything-c-yaoddmuse-cache-file))))
5272 ;;;###autoload
5273 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
5274 "Preconfigured `anything' to edit or view EmacsWiki page.
5276 Needs yaoddmuse.el.
5278 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5279 (interactive)
5280 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
5282 ;;;###autoload
5283 (defun anything-yaoddmuse-emacswiki-post-library ()
5284 "Preconfigured `anything' to post library to EmacsWiki.
5286 Needs yaoddmuse.el.
5288 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5289 (interactive)
5290 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
5292 (defun anything-yaoddmuse-init ()
5293 "Init anything buffer status."
5294 (let ((anything-buffer (anything-candidate-buffer 'global))
5295 (library-list (yaoddmuse-get-library-list)))
5296 (with-current-buffer anything-buffer
5297 ;; Insert library name.
5298 (dolist (library library-list)
5299 (insert (format "%s\n" library)))
5300 ;; Sort lines.
5301 (sort-lines nil (point-min) (point-max)))))
5303 ;;; Eev anchors
5304 (defvar anything-c-source-eev-anchor
5305 '((name . "Anchors")
5306 (candidates
5307 . (lambda ()
5308 (ignore-errors
5309 (with-current-buffer anything-current-buffer
5310 (loop initially (goto-char (point-min))
5311 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
5312 for anchor = (match-string-no-properties 1)
5313 collect (cons (format "%5d:%s"
5314 (line-number-at-pos (match-beginning 0))
5315 (format ee-anchor-format anchor)) anchor))))))
5316 (persistent-action . (lambda (item)
5317 (ee-to item)
5318 (anything-match-line-color-current-line)))
5319 (persistent-help . "Show this entry")
5320 (action . (("Goto link" . ee-to)))))
5321 ;; (anything 'anything-c-source-eev-anchor)
5323 ;;;; <Misc>
5324 ;;; Org keywords
5325 (defvar anything-c-source-org-keywords
5326 '((name . "Org Keywords")
5327 (init . anything-c-org-keywords-init)
5328 (candidates . anything-c-org-keywords-candidates)
5329 (action . anything-c-org-keywords-insert)
5330 (persistent-action . anything-c-org-keywords-show-help)
5331 (persistent-help . "Show an example and info page to describe this keyword.")
5332 (keywords-examples)
5333 (keywords)))
5334 ;; (anything 'anything-c-source-org-keywords)
5335 (defvar anything-c-org-keywords-info-location
5336 '(("#+TITLE:" . "(org)Export options")
5337 ("#+AUTHOR:" . "(org)Export options")
5338 ("#+DATE:" . "(org)Export options")
5339 ("#+EMAIL:" . "(org)Export options")
5340 ("#+DESCRIPTION:" . "(org)Export options")
5341 ("#+KEYWORDS:" . "(org)Export options")
5342 ("#+LANGUAGE:" . "(org)Export options")
5343 ("#+TEXT:" . "(org)Export options")
5344 ("#+TEXT:" . "(org)Export options")
5345 ("#+OPTIONS:" . "(org)Export options")
5346 ("#+BIND:" . "(org)Export options")
5347 ("#+LINK_UP:" . "(org)Export options")
5348 ("#+LINK_HOME:" . "(org)Export options")
5349 ("#+LATEX_HEADER:" . "(org)Export options")
5350 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
5351 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
5352 ("#+INFOJS_OPT" . "(org)Javascript support")
5353 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
5354 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
5355 ("#+ORGTBL" . "(org)Radio tables")
5356 ("#+HTML:" . "(org)Quoting HTML tags")
5357 ("#+LaTeX:" . "(org)Quoting LaTeX code")
5358 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
5359 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
5360 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
5361 ("#+BEGIN_VERSE" . "(org)Paragraphs")
5362 ("#+BEGIN_SRC" . "(org)Literal examples")
5363 ("#+CAPTION" . "(org)Tables in HTML export")
5364 ("#+LABEL" . "(org)Tables in LaTeX export")
5365 ("#+ATTR_HTML" . "(org)Links")
5366 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
5368 (defun anything-c-org-keywords-init ()
5369 (unless (anything-attr 'keywords-examples)
5370 (require 'org)
5371 (anything-attrset 'keywords-examples
5372 (append
5373 (mapcar
5374 (lambda (x)
5375 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
5376 (cons (match-string 2 x) (match-string 1 x)))
5377 (org-split-string (org-get-current-options) "\n"))
5378 (mapcar 'list org-additional-option-like-keywords)))
5379 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
5381 (defun anything-c-org-keywords-candidates ()
5382 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
5383 (anything-attr 'keywords)))
5385 (defun anything-c-org-keywords-insert (keyword)
5386 (cond ((string-match "BEGIN" keyword)
5387 (insert "#+" keyword " ")
5388 (save-excursion
5389 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
5391 (insert "#+" keyword " "))))
5393 (defun anything-c-org-keywords-show-help (keyword)
5394 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
5395 "(org)In-buffer settings"))
5396 (search-forward (concat "#+" keyword) nil t)
5397 (anything-persistent-highlight-point)
5398 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
5401 ;;; Picklist
5402 (defvar anything-c-source-picklist
5403 '((name . "Picklist")
5404 (candidates . (lambda () (mapcar 'car picklist-list)))
5405 (type . file)))
5406 ;; (anything 'anything-c-source-picklist)
5408 ;;; BBDB
5409 (defvar bbdb-records)
5410 (defvar bbdb-buffer-name)
5411 (declare-function bbdb "ext:bbdb-com")
5412 (declare-function bbdb-current-record "ext:bbdb-com")
5413 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
5414 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
5415 (declare-function bbdb-current-record "ext:bbdb-com")
5416 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
5417 (declare-function bbdb-records "ext:bbdb-com"
5418 (&optional dont-check-disk already-in-db-buffer))
5420 (defun anything-c-bbdb-candidates ()
5421 "Return a list of all names in the bbdb database. The format
5422 is \"Firstname Lastname\"."
5423 (mapcar (lambda (bbdb-record)
5424 (replace-regexp-in-string
5425 "\\s-+$" ""
5426 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
5427 (bbdb-records)))
5429 (defun anything-c-bbdb-create-contact (actions candidate)
5430 "Action transformer that returns only an entry to add the
5431 current `anything-pattern' as new contact. All other actions are
5432 removed."
5433 (if (string= candidate "*Add to contacts*")
5434 '(("Add to contacts" . (lambda (actions)
5435 (bbdb-create-internal
5436 (read-from-minibuffer "Name: " anything-c-bbdb-name)
5437 (read-from-minibuffer "Company: ")
5438 (read-from-minibuffer "Email: ")
5441 (read-from-minibuffer "Note: ")))))
5442 actions))
5444 (defun anything-c-bbdb-get-record (candidate)
5445 "Return record that match CANDIDATE."
5446 (bbdb candidate nil)
5447 (set-buffer "*BBDB*")
5448 (bbdb-current-record))
5450 (defvar anything-c-bbdb-name nil
5451 "Only for internal use.")
5453 (defvar anything-c-source-bbdb
5454 '((name . "BBDB")
5455 (candidates . anything-c-bbdb-candidates)
5456 (action ("Send a mail" . anything-c-bbdb-compose-mail)
5457 ("View person's data" . anything-c-bbdb-view-person-action))
5458 (filtered-candidate-transformer . (lambda (candidates source)
5459 (setq anything-c-bbdb-name anything-pattern)
5460 (if (not candidates)
5461 (list "*Add to contacts*")
5462 candidates)))
5463 (action-transformer . (lambda (actions candidate)
5464 (anything-c-bbdb-create-contact actions candidate))))
5465 "Needs BBDB.
5467 http://bbdb.sourceforge.net/")
5468 ;; (anything 'anything-c-source-bbdb)
5470 (defun anything-c-bbdb-view-person-action (candidate)
5471 "View BBDB data of single CANDIDATE or marked candidates."
5472 (anything-aif (anything-marked-candidates)
5473 (let ((bbdb-append-records (length it)))
5474 (dolist (i it)
5475 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
5476 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
5478 (defun anything-c-bbdb-collect-mail-addresses ()
5479 "Return a list of all mail addresses of records in bbdb buffer."
5480 (with-current-buffer bbdb-buffer-name
5481 (loop for i in bbdb-records
5482 if (bbdb-record-net (car i))
5483 collect (bbdb-dwim-net-address (car i)))))
5485 (defun anything-c-bbdb-compose-mail (candidate)
5486 "Compose a mail with all records of bbdb buffer."
5487 (anything-c-bbdb-view-person-action candidate)
5488 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
5489 (address-str (mapconcat 'identity address-list ",\n ")))
5490 (compose-mail address-str)))
5492 ;;; Evaluation Result
5493 (defvar anything-c-source-evaluation-result
5494 '((name . "Evaluation Result")
5495 (disable-shortcuts)
5496 (dummy)
5497 (filtered-candidate-transformer . (lambda (candidates source)
5498 (list
5499 (condition-case nil
5500 (with-current-buffer anything-current-buffer
5501 (pp-to-string
5502 (eval (read anything-pattern))))
5503 (error "Error")))))
5504 (action ("Copy result to kill-ring" . (lambda (candidate)
5505 (with-current-buffer anything-buffer
5506 (let ((end (save-excursion
5507 (goto-char (point-max))
5508 (search-backward "\n")
5509 (point))))
5510 (kill-region (point) end))))))))
5511 ;; (anything 'anything-c-source-evaluation-result)
5513 ;;;###autoload
5514 (defun anything-eval-expression (arg)
5515 "Preconfigured anything for `anything-c-source-evaluation-result'."
5516 (interactive "P")
5517 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
5518 nil nil nil "*anything eval*"))
5520 ;;;###autoload
5521 (defun anything-eval-expression-with-eldoc ()
5522 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
5523 (interactive)
5524 (if (window-system)
5525 (let ((timer (run-with-idle-timer eldoc-idle-delay
5526 'repeat 'anything-eldoc-show-in-eval)))
5527 (unwind-protect
5528 (call-interactively 'anything-eval-expression)
5529 (cancel-timer timer)))
5530 (call-interactively 'anything-eval-expression)))
5532 (defun anything-eldoc-show-in-eval ()
5533 "Return eldoc in a tooltip for current minibuffer input."
5534 (let* ((str-all (minibuffer-completion-contents))
5535 (sym (when str-all
5536 (with-temp-buffer
5537 (insert str-all)
5538 (goto-char (point-max))
5539 (unless (looking-back ")\\|\"") (forward-char -1))
5540 (eldoc-current-symbol))))
5541 (doc (or (eldoc-get-var-docstring sym)
5542 (eldoc-get-fnsym-args-string
5543 (car (eldoc-fnsym-in-current-sexp))))))
5544 (when doc (tooltip-show doc))))
5546 ;;; Calculation Result
5547 (defvar anything-c-source-calculation-result
5548 '((name . "Calculation Result")
5549 (dummy)
5550 (filtered-candidate-transformer . (lambda (candidates source)
5551 (list
5552 (condition-case nil
5553 (calc-eval anything-pattern)
5554 (error "error")))))
5555 (action ("Copy result to kill-ring" . kill-new))))
5556 ;; (anything 'anything-c-source-calculation-result)
5558 ;;; Google Suggestions
5559 (defvar anything-gg-sug-lgh-flag 0)
5560 (defun anything-c-google-suggest-fetch (input)
5561 "Fetch suggestions for INPUT from XML buffer.
5562 Return an alist with elements like (data . number_results)."
5563 (let ((request (concat anything-c-google-suggest-url
5564 (url-hexify-string input))))
5565 (flet ((fetch ()
5566 (loop
5567 with result-alist = (xml-get-children
5568 (car (xml-parse-region (point-min) (point-max)))
5569 'CompleteSuggestion)
5570 for i in result-alist
5571 for data = (cdr (caadr (assoc 'suggestion i)))
5572 for nqueries = (cdr (caadr (assoc 'num_queries i)))
5573 for ldata = (length data)
5575 (when (> ldata anything-gg-sug-lgh-flag)
5576 (setq anything-gg-sug-lgh-flag ldata))
5577 collect (cons data nqueries) into cont
5578 finally return cont)))
5579 (if anything-google-suggest-use-curl-p
5580 (with-temp-buffer
5581 (call-process "curl" nil t nil request)
5582 (fetch))
5583 (with-current-buffer
5584 (url-retrieve-synchronously request)
5585 (fetch))))))
5588 (defun anything-c-google-suggest-set-candidates ()
5589 "Set candidates with result and number of google results found."
5590 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
5591 (setq suggestions (loop for i in suggestions
5592 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
5593 for elm = (concat (car i)
5594 (make-string (+ 2 interval) ? )
5595 "(" (cdr i) " results)")
5596 collect (cons elm (car i))))
5597 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
5598 suggestions
5599 ;; if there is no suggestion exactly matching the input then
5600 ;; prepend a Search on Google item to the list
5601 (append
5602 suggestions
5603 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
5604 anything-input))))))
5607 (defun anything-c-google-suggest-action (candidate)
5608 "Default action to jump to a google suggested candidate."
5609 (anything-c-browse-url (concat anything-c-google-suggest-search-url
5610 (url-hexify-string candidate))))
5613 (defvar anything-c-source-google-suggest
5614 '((name . "Google Suggest")
5615 (candidates . anything-c-google-suggest-set-candidates)
5616 (action . (("Google Search" . anything-c-google-suggest-action)))
5617 (volatile)
5618 (requires-pattern . 3)
5619 (delayed)))
5621 ;; (anything 'anything-c-source-google-suggest)
5623 ;;; Yahoo suggestions
5625 (defun anything-c-yahoo-suggest-fetch (input)
5626 "Fetch Yahoo suggestions for INPUT from XML buffer.
5627 Return an alist with elements like (data . number_results)."
5628 (let ((request (concat anything-c-yahoo-suggest-url
5629 (url-hexify-string input))))
5630 (flet ((fetch ()
5631 (loop
5632 with result-alist = (xml-get-children
5633 (car (xml-parse-region (point-min) (point-max)))
5634 'Result)
5635 for i in result-alist
5636 collect (caddr i))))
5637 (with-current-buffer
5638 (url-retrieve-synchronously request)
5639 (fetch)))))
5641 (defun anything-c-yahoo-suggest-set-candidates ()
5642 "Set candidates with Yahoo results found."
5643 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
5644 (or suggestions
5645 (append
5646 suggestions
5647 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
5648 anything-input))))))
5650 (defun anything-c-yahoo-suggest-action (candidate)
5651 "Default action to jump to a Yahoo suggested candidate."
5652 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
5653 (url-hexify-string candidate))))
5655 (defvar anything-c-source-yahoo-suggest
5656 '((name . "Yahoo Suggest")
5657 (candidates . anything-c-yahoo-suggest-set-candidates)
5658 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
5659 (volatile)
5660 (requires-pattern . 3)
5661 (delayed)))
5663 ;; (anything 'anything-c-source-yahoo-suggest)
5665 ;;; Surfraw
5666 ;;; Need external program surfraw.
5667 ;;; http://surfraw.alioth.debian.org/
5668 ;; user variables
5669 (require 'browse-url)
5670 (defvar w3m-command nil)
5671 (defvar anything-c-home-url "http://www.google.fr"
5672 "*Default url to use as home url.")
5674 (defvar anything-browse-url-default-browser-alist
5675 `((,w3m-command . w3m-browse-url)
5676 (,browse-url-firefox-program . browse-url-firefox)
5677 (,browse-url-kde-program . browse-url-kde)
5678 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
5679 (,browse-url-mozilla-program . browse-url-mozilla)
5680 (,browse-url-galeon-program . browse-url-galeon)
5681 (,browse-url-netscape-program . browse-url-netscape)
5682 (,browse-url-mosaic-program . browse-url-mosaic)
5683 (,browse-url-xterm-program . browse-url-text-xterm))
5684 "*Alist of (executable . function) to try to find a suitable url browser.")
5686 (defun anything-browse-url-default-browser (url &rest args)
5687 "Find a suitable browser and ask it to load URL."
5688 (let ((default-browser (loop
5689 for i in anything-browse-url-default-browser-alist
5690 when (and (car i) (executable-find (car i))) return (cdr i))))
5691 (if default-browser
5692 (apply default-browser url args)
5693 (error "No usable browser found"))))
5695 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
5696 "Default command to browse URL."
5697 (if browse-url-browser-function
5698 (browse-url url)
5699 (anything-browse-url-default-browser url)))
5701 (defun anything-c-build-elvi-list ()
5702 "Return list of all engines and descriptions handled by surfraw."
5703 (cdr
5704 (with-temp-buffer
5705 (call-process "surfraw" nil t nil
5706 "-elvi")
5707 (split-string (buffer-string) "\n"))))
5709 (defvar anything-surfraw-engines-history nil)
5710 ;;;###autoload
5711 (defun anything-surfraw (pattern engine)
5712 "Preconfigured `anything' to search PATTERN with search ENGINE."
5713 (interactive (list (read-string "SearchFor: ")
5714 (anything-comp-read
5715 "Engine: "
5716 (anything-c-build-elvi-list)
5717 :must-match t
5718 :name "Surfraw Search Engines"
5719 :history anything-surfraw-engines-history)))
5720 (let* ((engine-nodesc (car (split-string engine)))
5721 (url (with-temp-buffer
5722 (apply 'call-process "surfraw" nil t nil
5723 (list engine-nodesc "-p" pattern))
5724 (replace-regexp-in-string
5725 "\n" "" (buffer-string)))))
5726 (if (string= engine-nodesc "W")
5727 (anything-c-browse-url)
5728 (anything-c-browse-url url)
5729 (setq anything-surfraw-engines-history
5730 (cons engine (delete engine anything-surfraw-engines-history))))))
5732 ;;; Emms
5734 (defun anything-emms-stream-edit-bookmark (elm)
5735 "Change the information of current emms-stream bookmark from anything."
5736 (let* ((cur-buf anything-current-buffer)
5737 (bookmark (assoc elm emms-stream-list))
5738 (name (read-from-minibuffer "Description: "
5739 (nth 0 bookmark)))
5740 (url (read-from-minibuffer "URL: "
5741 (nth 1 bookmark)))
5742 (fd (read-from-minibuffer "Feed Descriptor: "
5743 (int-to-string (nth 2 bookmark))))
5744 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
5745 (format "%s" (car (last bookmark))))))
5746 (save-excursion
5747 (emms-streams)
5748 (when (re-search-forward (concat "^" name) nil t)
5749 (beginning-of-line)
5750 (emms-stream-delete-bookmark)
5751 (emms-stream-add-bookmark name url (string-to-number fd) type)
5752 (emms-stream-save-bookmarks-file)
5753 (emms-stream-quit)
5754 (switch-to-buffer cur-buf)))))
5756 (defun anything-emms-stream-delete-bookmark (elm)
5757 "Delete an emms-stream bookmark from anything."
5758 (let* ((cur-buf anything-current-buffer)
5759 (bookmark (assoc elm emms-stream-list))
5760 (name (nth 0 bookmark)))
5761 (save-excursion
5762 (emms-streams)
5763 (when (re-search-forward (concat "^" name) nil t)
5764 (beginning-of-line)
5765 (emms-stream-delete-bookmark)
5766 (emms-stream-save-bookmarks-file)
5767 (emms-stream-quit)
5768 (switch-to-buffer cur-buf)))))
5770 (defvar anything-c-source-emms-streams
5771 '((name . "Emms Streams")
5772 (init . (lambda ()
5773 (emms-stream-init)))
5774 (candidates . (lambda ()
5775 (mapcar 'car emms-stream-list)))
5776 (action . (("Play" . (lambda (elm)
5777 (let* ((stream (assoc elm emms-stream-list))
5778 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
5779 (url (second stream)))
5780 (funcall fn url))))
5781 ("Delete" . anything-emms-stream-delete-bookmark)
5782 ("Edit" . anything-emms-stream-edit-bookmark)))
5783 (filtered-candidate-transformer . anything-c-adaptive-sort)))
5784 ;; (anything 'anything-c-source-emms-streams)
5786 ;; Don't forget to set `emms-source-file-default-directory'
5787 (defvar anything-c-source-emms-dired
5788 '((name . "Music Directory")
5789 (candidates . (lambda ()
5790 (cddr (directory-files emms-source-file-default-directory))))
5791 (action .
5792 (("Play Directory" . (lambda (item)
5793 (emms-play-directory
5794 (expand-file-name
5795 item
5796 emms-source-file-default-directory))))
5797 ("Open dired in file's directory" . (lambda (item)
5798 (anything-c-open-dired
5799 (expand-file-name
5800 item
5801 emms-source-file-default-directory))))))
5802 (filtered-candidate-transformer . anything-c-adaptive-sort)))
5803 ;; (anything 'anything-c-source-emms-dired)
5805 (defface anything-emms-playlist
5806 '((t (:foreground "Springgreen4" :underline t)))
5807 "*Face used for tracks in current emms playlist."
5808 :group 'anything)
5810 (defun anything-c-emms-files-modifier (candidates source)
5811 (let ((current-playlist (with-current-emms-playlist
5812 (loop
5813 with cur-list = (emms-playlist-tracks-in-region
5814 (point-min) (point-max))
5815 for i in cur-list
5816 collect (assoc-default 'name i)))))
5817 (loop for i in candidates
5818 if (member (cdr i) current-playlist)
5819 collect (cons (propertize (car i)
5820 'face 'anything-emms-playlist)
5821 (cdr i)) into lis
5822 else collect i into lis
5823 finally return lis)))
5825 (defun anything-c-emms-play-current-playlist ()
5826 "Play current playlist."
5827 (with-current-emms-playlist
5828 (emms-playlist-first)
5829 (emms-playlist-mode-play-smart)))
5831 (defvar anything-c-source-emms-files
5832 '((name . "Emms files")
5833 (candidates . (lambda ()
5834 (loop for v being the hash-values in emms-cache-db
5835 for name = (assoc-default 'name v)
5836 for artist = (or (assoc-default 'info-artist v) "unknown")
5837 for genre = (or (assoc-default 'info-genre v) "unknown")
5838 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
5839 for song = (or (assoc-default 'info-title v) "unknown")
5840 for info = (concat artist " - " genre " - " tracknum ": " song)
5841 unless (string-match "^http:" name) collect (cons info name))))
5842 (filtered-candidate-transformer . anything-c-emms-files-modifier)
5843 (action . (("Play file" . emms-play-file)
5844 ("Add to Playlist and play (C-u clear current)"
5845 . (lambda (candidate)
5846 (when anything-current-prefix-arg
5847 (emms-playlist-current-clear))
5848 (emms-playlist-new)
5849 (mapc 'emms-add-playlist-file (anything-marked-candidates))
5850 (unless emms-player-playing-p
5851 (anything-c-emms-play-current-playlist))))))))
5853 ;; (anything 'anything-c-source-emms-files)
5855 ;;; Jabber Contacts (jabber.el)
5856 (defun anything-c-jabber-online-contacts ()
5857 "List online Jabber contacts."
5858 (with-no-warnings
5859 (let (jids)
5860 (dolist (item (jabber-concat-rosters) jids)
5861 (when (get item 'connected)
5862 (push (if (get item 'name)
5863 (cons (get item 'name) item)
5864 (cons (symbol-name item) item)) jids))))))
5866 (defvar anything-c-source-jabber-contacts
5867 '((name . "Jabber Contacts")
5868 (init . (lambda () (require 'jabber)))
5869 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
5870 (action . (lambda (x)
5871 (jabber-chat-with
5872 (jabber-read-account)
5873 (symbol-name
5874 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
5875 ;; (anything 'anything-c-source-jabber-contacts)
5878 ;;; Call source.
5879 (defvar anything-source-select-buffer "*anything source select*")
5880 (defvar anything-c-source-call-source
5881 `((name . "Call anything source")
5882 (candidate-number-limit)
5883 (candidates . (lambda ()
5884 (loop for vname in (all-completions "anything-c-source-" obarray)
5885 for var = (intern vname)
5886 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
5887 if name collect (cons (format "%s `%s'"
5888 name (propertize vname 'face 'font-lock-variable-name-face))
5889 var))))
5890 (action . (("Invoke anything with selected source" .
5891 (lambda (candidate)
5892 (setq anything-candidate-number-limit 9999)
5893 (anything candidate nil nil nil nil
5894 anything-source-select-buffer)))
5895 ("Describe variable" . describe-variable)
5896 ("Find variable" . find-variable)))
5897 (persistent-action . describe-variable)
5898 (persistent-help . "Show description of this source")))
5899 ;; (anything 'anything-c-source-call-source)
5901 ;;;###autoload
5902 (defun anything-call-source ()
5903 "Preconfigured `anything' to call anything source."
5904 (interactive)
5905 (anything 'anything-c-source-call-source nil nil nil nil
5906 anything-source-select-buffer))
5908 (defun anything-call-source-from-anything ()
5909 "Call anything source within `anything' session."
5910 (interactive)
5911 (setq anything-input-idle-delay 0)
5912 (anything-set-sources '(anything-c-source-call-source)))
5914 ;;; Execute Preconfigured anything.
5915 (defvar anything-c-source-anything-commands
5916 '((name . "Preconfigured Anything")
5917 (candidates . anything-c-anything-commands-candidates)
5918 (type . command)
5919 (candidate-number-limit)))
5920 ;; (anything 'anything-c-source-anything-commands)
5922 (defun anything-c-anything-commands-candidates ()
5923 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
5924 collect (cons (if (where-is-internal cmd nil t)
5925 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
5926 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
5927 cmd)))
5929 ;;;###autoload
5930 (defun anything-execute-anything-command ()
5931 "Preconfigured `anything' to execute preconfigured `anything'."
5932 (interactive)
5933 (anything-other-buffer 'anything-c-source-anything-commands
5934 "*anything commands*"))
5936 ;; Occur
5937 (defun anything-c-occur-init ()
5938 (anything-candidate-buffer anything-current-buffer))
5940 (defun anything-c-occur-get-line (s e)
5941 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
5943 (defvar anything-c-source-occur
5944 '((name . "Occur")
5945 (init . anything-c-occur-init)
5946 (candidates-in-buffer)
5947 (migemo)
5948 (get-line . anything-c-occur-get-line)
5949 (type . line)
5950 (recenter)
5951 (requires-pattern . 1)
5952 (delayed)
5953 (volatile)))
5954 ;; (anything 'anything-c-source-occur)
5956 ;;; Anything browse code.
5957 (defun anything-c-browse-code-get-line (beg end)
5958 "Select line if it match the regexp corresponding to current `major-mode'.
5959 Line is parsed for BEG position to END position."
5960 (let ((str-line (buffer-substring beg end))
5961 (regexp (assoc-default major-mode
5962 anything-c-browse-code-regexp-alist))
5963 (num-line (if (string= anything-pattern "") beg (1- beg))))
5964 (when (and regexp (string-match regexp str-line))
5965 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
5968 (defvar anything-c-source-browse-code
5969 '((name . "Browse code")
5970 (init . (lambda ()
5971 (anything-candidate-buffer anything-current-buffer)
5972 (with-current-buffer anything-current-buffer
5973 (jit-lock-fontify-now))))
5974 (candidates-in-buffer)
5975 (get-line . anything-c-browse-code-get-line)
5976 (type . line)
5977 (recenter)))
5979 ;; Do many actions for input
5980 (defvar anything-c-source-create
5981 '((name . "Create")
5982 (dummy)
5983 (action)
5984 (action-transformer . anything-create--actions))
5985 "Do many create actions from `anything-pattern'.
5986 See also `anything-create--actions'.")
5987 ;; (anything 'anything-c-source-create)
5989 (defun anything-create-from-anything ()
5990 "Run `anything-create' from `anything' as a fallback."
5991 (interactive)
5992 (anything-run-after-quit 'anything-create nil anything-pattern))
5994 ;;;###autoload
5995 (defun anything-create (&optional string initial-input)
5996 "Preconfigured `anything' to do many create actions from STRING.
5997 See also `anything-create--actions'."
5998 (interactive)
5999 (setq string (or string (read-string "Create Anything: " initial-input)))
6000 (anything '(((name . "Anything Create")
6001 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
6002 (candidates . anything-create--actions)
6003 (candidate-number-limit)
6004 (action . (lambda (func) (funcall func string)))))))
6006 (defun anything-create--actions (&rest ignored)
6007 "Default actions for `anything-create' / `anything-c-source-create'."
6008 (remove-if-not
6009 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
6010 (append anything-create--actions-private
6011 '(("find-file" . find-file)
6012 ("find-file other window" . find-file-other-window)
6013 ("New buffer" . switch-to-buffer)
6014 ("New buffer other window" . switch-to-buffer-other-window)
6015 ("Bookmark Set" . bookmark-set)
6016 ("Set Register" .
6017 (lambda (x) (set-register (read-char "Register: ") x)))
6018 ("Insert Linkd star" . linkd-insert-star)
6019 ("Insert Linkd Tag" . linkd-insert-tag)
6020 ("Insert Linkd Link" . linkd-insert-link)
6021 ("Insert Linkd Lisp" . linkd-insert-lisp)
6022 ("Insert Linkd Wiki" . linkd-insert-wiki)
6023 ("Google Search" . google)))))
6025 ;; Minibuffer History
6026 (defvar anything-c-source-minibuffer-history
6027 '((name . "Minibuffer History")
6028 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
6029 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
6030 (if (consp (car history))
6031 (mapcar 'prin1-to-string history)
6032 history))))
6033 (migemo)
6034 (action . insert)))
6035 ;; (anything 'anything-c-source-minibuffer-history)
6037 ;; elscreen
6038 (defvar anything-c-source-elscreen
6039 '((name . "Elscreen")
6040 (candidates . (lambda ()
6041 (if (cdr (elscreen-get-screen-to-name-alist))
6042 (sort
6043 (loop for sname in (elscreen-get-screen-to-name-alist)
6044 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
6045 finally (return lst))
6046 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
6047 (action . (("Change Screen".
6048 (lambda (candidate)
6049 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
6050 ("Kill Screen(s)".
6051 (lambda (candidate)
6052 (dolist (i (anything-marked-candidates))
6053 (elscreen-goto (- (aref i 1) (aref "0" 0)))
6054 (elscreen-kill))))
6055 ("Only Screen".
6056 (lambda (candidate)
6057 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
6058 (elscreen-kill-others)))))))
6059 ;; (anything 'anything-c-source-elscreen)
6061 ;;;; <System>
6063 ;;; Top (process)
6064 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
6065 "Top command (batch mode). %s is replaced with `frame-width'.")
6066 (defvar anything-c-source-top
6067 '((name . "Top (Press C-c C-u to refresh)")
6068 (init . anything-c-top-init)
6069 (candidates-in-buffer)
6070 (display-to-real . anything-c-top-display-to-real)
6071 (update . anything-c-top-update)
6072 (persistent-action . anything-c-top-sh-persistent-action)
6073 (persistent-help . "SIGTERM")
6074 (action
6075 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
6076 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
6077 ("Copy PID" . (lambda (pid) (kill-new pid))))))
6078 ;; (anything 'anything-c-source-top)
6080 (defun anything-c-top-sh (cmd)
6081 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
6083 (defun anything-c-top-sh-persistent-action (pid)
6084 (delete-other-windows)
6085 (anything-c-top-sh (format "kill -TERM %s" pid))
6086 (anything-force-update))
6088 (defun anything-c-top-init ()
6089 (with-current-buffer (anything-candidate-buffer 'global)
6090 (call-process-shell-command
6091 (format anything-c-top-command
6092 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
6093 nil (current-buffer))))
6095 (defun anything-c-top-display-to-real (line)
6096 (car (split-string line)))
6098 (defun anything-c-top-update ()
6099 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
6100 (anything-c-top-init)))
6102 ;;;###autoload
6103 (defun anything-top ()
6104 "Preconfigured `anything' for top command."
6105 (interactive)
6106 (let ((anything-samewindow t)
6107 (anything-enable-shortcuts)
6108 (anything-display-function 'anything-default-display-buffer)
6109 (anything-candidate-number-limit 9999))
6110 (save-window-excursion
6111 (delete-other-windows)
6112 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
6114 ;;; Timers
6115 (defvar anything-c-source-absolute-time-timers
6116 '((name . "Absolute Time Timers")
6117 (candidates . timer-list)
6118 (type . timer)))
6119 ;; (anything 'anything-c-source-absolute-time-timers)
6121 (defvar anything-c-source-idle-time-timers
6122 '((name . "Idle Time Timers")
6123 (candidates . timer-idle-list)
6124 (type . timer)))
6125 ;; (anything 'anything-c-source-idle-time-timers)
6127 (defun anything-c-timer-real-to-display (timer)
6128 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
6129 (append timer nil) ;use `append' to convert vector->list
6130 (format "%s repeat=%5S %s(%s)"
6131 (let ((time (list t1 t2 t3)))
6132 (if idle-delay
6133 (format-time-string "idle-for=%5s" time)
6134 (format-time-string "%m/%d %T" time)))
6135 repeat-delay
6136 func
6137 (mapconcat 'prin1-to-string args " "))))
6139 ;;; X RandR resolution change
6140 ;;; FIXME I do not care multi-display.
6141 (defvar anything-c-xrandr-output "VGA")
6142 (defvar anything-c-xrandr-screen "0")
6143 (defvar anything-c-source-xrandr-change-resolution
6144 '((name . "Change Resolution")
6145 (candidates
6146 . (lambda ()
6147 (with-temp-buffer
6148 (call-process "xrandr" nil (current-buffer) nil
6149 "--screen" anything-c-xrandr-screen "-q")
6150 (goto-char 1)
6151 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
6152 collect (match-string 1)))))
6153 (action
6154 ("Change Resolution" . (lambda (mode)
6155 (call-process "xrandr" nil nil nil
6156 "--screen" anything-c-xrandr-screen
6157 "--output" anything-c-xrandr-output
6158 "--mode" mode))))))
6159 ;; (anything 'anything-c-source-xrandr-change-resolution)
6161 ;;; Xfont selection
6162 (defun anything-c-persistent-xfont-action (elm)
6163 "Show current font temporarily"
6164 (let ((current-font (cdr (assoc 'font (frame-parameters))))
6165 (default-font elm))
6166 (unwind-protect
6167 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
6168 (set-frame-font current-font))))
6170 (defvar anything-c-xfonts-cache nil)
6171 (defvar anything-c-source-xfonts
6172 '((name . "X Fonts")
6173 (init . (lambda ()
6174 (unless anything-c-xfonts-cache
6175 (setq anything-c-xfonts-cache
6176 (x-list-fonts "*")))))
6177 (candidates . anything-c-xfonts-cache)
6178 (action . (("Copy to kill ring" . (lambda (elm)
6179 (kill-new elm)))
6180 ("Set Font" . (lambda (elm)
6181 (kill-new elm)
6182 (set-frame-font elm 'keep-size)
6183 (message "New font have been copied to kill ring")))))
6184 (persistent-action . anything-c-persistent-xfont-action)
6185 (persistent-help . "Switch to this font temporarily")))
6187 ;;;###autoload
6188 (defun anything-select-xfont ()
6189 "Preconfigured `anything' to select Xfont."
6190 (interactive)
6191 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
6193 ;; (anything 'anything-c-source-xfonts)
6195 ;;; World time
6197 (defvar anything-c-source-time-world
6198 '((name . "Time World List")
6199 (init . (lambda ()
6200 (let ((anything-buffer (anything-candidate-buffer 'global)))
6201 (with-current-buffer anything-buffer
6202 (display-time-world-display display-time-world-list)))))
6203 (candidates-in-buffer)))
6205 ;;;###autoload
6206 (defun anything-world-time ()
6207 "Preconfigured `anything' to show world time."
6208 (interactive)
6209 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
6211 ;;; Source for Debian/Ubuntu users
6212 (defvar anything-c-source-apt
6213 '((name . "APT")
6214 (init . anything-c-apt-init)
6215 (candidates-in-buffer)
6216 (candidate-transformer anything-c-apt-candidate-transformer)
6217 (display-to-real . anything-c-apt-display-to-real)
6218 (candidate-number-limit . 9999)
6219 (action
6220 ("Show package description" . anything-c-apt-cache-show)
6221 ("Install package" . anything-c-apt-install)
6222 ("Remove package" . anything-c-apt-uninstall)
6223 ("Purge package" . anything-c-apt-purge))
6224 (persistent-action . anything-c-apt-persistent-action)
6225 (persistent-help . "Show - C-u Refresh")))
6226 ;; (anything 'anything-c-source-apt)
6228 (defvar anything-c-apt-query "emacs")
6229 (defvar anything-c-apt-search-command "apt-cache search '%s'")
6230 (defvar anything-c-apt-show-command "apt-cache show '%s'")
6231 (defvar anything-c-apt-installed-packages nil)
6233 (defface anything-apt-installed
6234 '((t (:foreground "green")))
6235 "*Face used for apt installed candidates."
6236 :group 'anything)
6238 (defun anything-c-apt-refresh ()
6239 "Refresh installed candidates list."
6240 (setq anything-c-apt-installed-packages nil)
6241 (anything-force-update))
6243 (defun anything-c-apt-persistent-action (candidate)
6244 "Persistent action for APT source."
6245 (if current-prefix-arg
6246 (anything-c-apt-refresh)
6247 (anything-c-apt-cache-show candidate)))
6249 ;;;###autoload
6250 (defun anything-apt (query)
6251 "Preconfigured `anything' : frontend of APT package manager."
6252 (interactive "sAPT search: ")
6253 (let ((anything-c-apt-query query))
6254 (anything 'anything-c-source-apt)))
6256 (defun anything-c-apt-candidate-transformer (candidates)
6257 "Show installed candidates in a different color."
6258 (loop
6259 with all
6260 for cand in candidates
6261 for name = (anything-c-apt-display-to-real cand)
6262 if (member name anything-c-apt-installed-packages)
6263 collect (propertize cand 'face 'anything-apt-installed) into all
6264 else collect cand into all finally return all))
6266 (defun anything-c-apt-init ()
6267 "Initialize list of debian packages."
6268 (unless anything-c-apt-installed-packages
6269 (message "Updating installed candidate list...")
6270 (setq anything-c-apt-installed-packages
6271 (with-temp-buffer
6272 (call-process-shell-command "dpkg --get-selections"
6273 nil (current-buffer))
6274 (loop for i in (split-string (buffer-string) "\n" t)
6275 collect (car (split-string i))))))
6276 (with-current-buffer
6277 (anything-candidate-buffer
6278 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
6279 (erase-buffer)
6280 (call-process-shell-command
6281 (format anything-c-apt-search-command anything-c-apt-query)
6282 nil (current-buffer)))
6283 (message "Updating installed candidate list...done"))
6285 (defun anything-c-apt-display-to-real (line)
6286 "Return only name of a debian package.
6287 LINE is displayed like:
6288 package name - description."
6289 (car (split-string line " - ")))
6291 ;;;###autoload
6292 (defun anything-c-shell-command-if-needed (command)
6293 (interactive "sShell command: ")
6294 (if (get-buffer command) ; if the buffer already exists
6295 (switch-to-buffer command) ; then just switch to it
6296 (switch-to-buffer command) ; otherwise create it
6297 (insert (shell-command-to-string command))))
6299 (defun anything-c-apt-cache-show (package)
6300 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
6302 (defun anything-c-apt-install (package)
6303 (anything-c-apt-install1 package :action 'install))
6305 (defun anything-c-apt-uninstall (package)
6306 (anything-c-apt-install1 package :action 'uninstall))
6308 (defun anything-c-apt-purge (package)
6309 (anything-c-apt-install1 package :action 'purge))
6311 (defun* anything-c-apt-install1 (candidate &key action)
6312 (ansi-term (getenv "SHELL") "anything apt")
6313 (term-line-mode)
6314 (let ((command (case action
6315 ('install "sudo apt-get install '%s'")
6316 ('uninstall "sudo apt-get remove '%s'")
6317 ('purge "sudo apt-get purge '%s'")
6318 (t (error "Unknow action"))))
6319 (beg (point)) end)
6320 (goto-char (point-max))
6321 (insert (format command candidate))
6322 (setq end (point))
6323 (if (y-or-n-p (format "%s package" (symbol-name action)))
6324 (progn
6325 (setq anything-c-external-commands-list nil)
6326 (setq anything-c-apt-installed-packages nil)
6327 (term-char-mode) (term-send-input))
6328 (delete-region beg end) (term-send-eof) (kill-buffer))))
6330 ;; (anything-c-apt-install "jed")
6332 ;;; Sources for gentoo users
6333 (defvar anything-c-gentoo-use-flags nil)
6334 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
6335 (defvar anything-c-cache-gentoo nil)
6336 (defvar anything-c-cache-world nil)
6337 (defvar anything-c-source-gentoo
6338 '((name . "Portage sources")
6339 (init . (lambda ()
6340 (get-buffer-create anything-c-gentoo-buffer)
6341 (unless anything-c-cache-gentoo
6342 (anything-c-gentoo-setup-cache))
6343 (unless anything-c-cache-world
6344 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
6345 (anything-c-gentoo-init-list)))
6346 (candidates-in-buffer)
6347 (match . identity)
6348 (candidate-transformer anything-c-highlight-world)
6349 (action . (("Show package" . (lambda (elm)
6350 (anything-c-gentoo-eshell-action elm "eix")))
6351 ("Show history" . (lambda (elm)
6352 (if (member elm anything-c-cache-world)
6353 (anything-c-gentoo-eshell-action elm "genlop -qe")
6354 (message "No infos on packages not yet installed"))))
6355 ("Copy in kill-ring" . kill-new)
6356 ("insert at point" . insert)
6357 ("Browse HomePage" . (lambda (elm)
6358 (let ((urls (anything-c-gentoo-get-url elm)))
6359 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
6360 ("Show extra infos" . (lambda (elm)
6361 (if (member elm anything-c-cache-world)
6362 (anything-c-gentoo-eshell-action elm "genlop -qi")
6363 (message "No infos on packages not yet installed"))))
6364 ("Show use flags" . (lambda (elm)
6365 (anything-c-gentoo-default-action elm "equery" "-C" "u")
6366 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
6367 (font-lock-mode 1)))
6368 ("Run emerge pretend" . (lambda (elm)
6369 (anything-c-gentoo-eshell-action elm "emerge -p")))
6370 ("Emerge" . (lambda (elm)
6371 (anything-gentoo-install elm :action 'install)))
6372 ("Unmerge" . (lambda (elm)
6373 (anything-gentoo-install elm :action 'uninstall)))
6374 ("Show dependencies" . (lambda (elm)
6375 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
6376 ("Show related files" . (lambda (elm)
6377 (anything-c-gentoo-default-action elm "equery" "files")))
6378 ("Refresh" . (lambda (elm)
6379 (anything-c-gentoo-setup-cache)
6380 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
6382 ;; (anything 'anything-c-source-gentoo)
6384 (defun* anything-gentoo-install (candidate &key action)
6385 (setq anything-c-external-commands-list nil)
6386 (ansi-term (getenv "SHELL") "Gentoo emerge")
6387 (term-line-mode)
6388 (let ((command (case action
6389 ('install "sudo emerge -av ")
6390 ('uninstall "sudo emerge -avC ")
6391 (t (error "Unknow action"))))
6392 (elms (mapconcat 'identity (anything-marked-candidates) " "))
6393 (beg (point)) end)
6394 (goto-char (point-max))
6395 (insert (concat command elms))
6396 (setq end (point))
6397 (term-char-mode) (term-send-input)))
6399 (defun anything-c-gentoo-default-action (elm command &rest args)
6400 "Gentoo default action that use `anything-c-gentoo-buffer'."
6401 (if (member elm anything-c-cache-world)
6402 (progn
6403 (switch-to-buffer anything-c-gentoo-buffer)
6404 (erase-buffer)
6405 (let ((com-list (append args (list elm))))
6406 (apply #'call-process command nil t nil
6407 com-list)))
6408 (message "No infos on packages not yet installed")))
6410 (defvar anything-c-source-use-flags
6411 '((name . "Use Flags")
6412 (init . (lambda ()
6413 (unless anything-c-gentoo-use-flags
6414 (anything-c-gentoo-setup-use-flags-cache))
6415 (anything-c-gentoo-get-use)))
6416 (candidates-in-buffer)
6417 (match . identity)
6418 (candidate-transformer anything-c-highlight-local-use)
6419 (action . (("Description"
6420 . (lambda (elm)
6421 (switch-to-buffer anything-c-gentoo-buffer)
6422 (erase-buffer)
6423 (apply #'call-process "euse" nil t nil
6424 `("-i"
6425 ,elm))
6426 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
6427 (font-lock-mode 1)))
6428 ("Enable"
6429 . (lambda (elm)
6430 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
6431 ("Disable"
6432 . (lambda (elm)
6433 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
6434 ("Remove"
6435 . (lambda (elm)
6436 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
6437 ("Show which dep use this flag"
6438 . (lambda (elm)
6439 (switch-to-buffer anything-c-gentoo-buffer)
6440 (erase-buffer)
6441 (apply #'call-process "equery" nil t nil
6442 `("-C"
6444 ,elm))))))))
6447 ;; (anything 'anything-c-source-use-flags)
6449 (defun anything-c-gentoo-init-list ()
6450 "Initialize buffer with all packages in Portage."
6451 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
6452 (buf (anything-candidate-buffer 'portage-buf)))
6453 (with-current-buffer buf
6454 (dolist (i anything-c-cache-gentoo)
6455 (insert (concat i "\n"))))))
6457 (defun anything-c-gentoo-setup-cache ()
6458 "Set up `anything-c-cache-gentoo'"
6459 (setq anything-c-cache-gentoo
6460 (split-string (with-temp-buffer
6461 (call-process "eix" nil t nil
6462 "--only-names")
6463 (buffer-string)))))
6465 (defun anything-c-gentoo-eshell-action (elm command)
6466 (when (get-buffer "*EShell Command Output*")
6467 (kill-buffer "*EShell Command Output*"))
6468 (message "Wait searching...")
6469 (let ((buf-fname (buffer-file-name anything-current-buffer)))
6470 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
6471 (progn
6472 (save-window-excursion
6473 (pop-to-buffer "*scratch*")
6474 (eshell-command (format "%s %s" command elm)))
6475 (pop-to-buffer "*EShell Command Output*"))
6476 (eshell-command (format "%s %s" command elm)))))
6478 (defun anything-c-gentoo-get-use ()
6479 "Initialize buffer with all use flags."
6480 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
6481 (buf (anything-candidate-buffer 'use-buf)))
6482 (with-current-buffer buf
6483 (dolist (i anything-c-gentoo-use-flags)
6484 (insert (concat i "\n"))))))
6487 (defun anything-c-gentoo-setup-use-flags-cache ()
6488 "Setup `anything-c-gentoo-use-flags'"
6489 (setq anything-c-gentoo-use-flags
6490 (split-string (with-temp-buffer
6491 (call-process "eix" nil t nil
6492 "--print-all-useflags")
6493 (buffer-string)))))
6495 (defun anything-c-gentoo-get-url (elm)
6496 "Return a list of urls from eix output."
6497 (loop
6498 with url-list = (split-string
6499 (with-temp-buffer
6500 (call-process "eix" nil t nil
6501 elm "--format" "<homepage>\n")
6502 (buffer-string)))
6503 with all
6504 for i in url-list
6505 when (and (string-match "^http://.*" i)
6506 (not (member i all)))
6507 collect i into all
6508 finally return all))
6510 (defun anything-c-gentoo-get-world ()
6511 "Return list of all installed package on your system."
6512 (split-string (with-temp-buffer
6513 (call-process "qlist" nil t nil
6514 "-I")
6515 (buffer-string))))
6517 (defun anything-c-gentoo-get-local-use ()
6518 (split-string (with-temp-buffer
6519 (call-process "portageq" nil t nil
6520 "envvar"
6521 "USE")
6522 (buffer-string))))
6524 (defface anything-gentoo-match-face '((t (:foreground "red")))
6525 "Face for anything-gentoo installed packages."
6526 :group 'traverse-faces)
6528 (defun anything-c-highlight-world (eix)
6529 "Highlight all installed package."
6530 (loop for i in eix
6531 if (member i anything-c-cache-world)
6532 collect (propertize i 'face 'anything-gentoo-match-face)
6533 else
6534 collect i))
6536 (defun anything-c-highlight-local-use (use-flags)
6537 (let ((local-uses (anything-c-gentoo-get-local-use)))
6538 (loop for i in use-flags
6539 if (member i local-uses)
6540 collect (propertize i 'face 'anything-gentoo-match-face)
6541 else
6542 collect i)))
6544 (defvar anything-c-source-emacs-process
6545 '((name . "Emacs Process")
6546 (candidates . (lambda () (mapcar #'process-name (process-list))))
6547 (persistent-action . (lambda (elm)
6548 (delete-process (get-process elm))
6549 (anything-delete-current-selection)))
6550 (persistent-help . "Kill Process")
6551 (action ("Kill Process" . (lambda (elm)
6552 (delete-process (get-process elm)))))))
6554 ;; (anything 'anything-c-source-emacs-process)
6556 ;; Run Externals commands within Emacs
6557 (defmacro* anything-comp-hash-get-items (hash-table &key test)
6558 "Get the list of all keys/values of hash-table."
6559 `(let ((li-items ()))
6560 (maphash #'(lambda (x y)
6561 (if ,test
6562 (when (funcall ,test y)
6563 (push (list x y) li-items))
6564 (push (list x y) li-items)))
6565 ,hash-table)
6566 li-items))
6568 (defun anything-comp-read-get-candidates (collection &optional test sort-fn)
6569 "Convert COLLECTION to list removing elements that don't match TEST.
6570 SORT-FN is a predicate to sort COLLECTION.
6571 If collection is an `obarray', a TEST is needed. See `obarray'."
6572 (let ((cands
6573 (cond ((and (listp collection) test)
6574 (loop for i in collection when (funcall test i) collect i))
6575 ((and (eq collection obarray) test)
6576 (loop for s being the symbols of collection
6577 when (funcall test s) collect s))
6578 ((and (vectorp collection) test)
6579 (loop for i across collection when (funcall test i) collect i))
6580 ((vectorp collection)
6581 (loop for i across collection collect i))
6582 ((and (hash-table-p collection) test)
6583 (anything-comp-hash-get-items collection :test test))
6584 ((hash-table-p collection)
6585 (anything-comp-hash-get-items collection))
6586 (t collection))))
6587 (if sort-fn (sort cands sort-fn) cands)))
6589 (defun anything-cr-default-transformer (candidates source)
6590 "Default filter candidate function for `anything-comp-read'.
6591 Do nothing, just return candidate list unmodified."
6592 candidates)
6594 (defun* anything-comp-read (prompt collection
6595 &key
6596 test
6597 initial-input
6598 (buffer "*Anything Completions*")
6599 must-match
6600 (requires-pattern 0)
6601 (history nil)
6602 (persistent-action nil)
6603 (persistent-help "DoNothing")
6604 (name "Anything Completions")
6605 sort
6606 (fc-transformer 'anything-cr-default-transformer)
6607 (marked-candidates nil))
6608 "Anything `completing-read' emulation.
6609 PROMPT is the prompt name to use.
6610 COLLECTION can be a list, vector, obarray or hash-table.
6611 Keys:
6613 TEST: A predicate called with one arg i.e candidate.
6614 INITIAL-INPUT: Same as initial-input arg in `anything'.
6615 BUFFER: Name of anything-buffer.
6616 MUST-MATCH: Candidate selected must be one of COLLECTION.
6617 REQUIRES-PATTERN: Same as anything attribute, default is 0.
6618 HISTORY: A list containing specific history, default is nil.
6619 When it is non--nil, all elements of HISTORY are displayed in
6620 anything-buffer before COLLECTION.
6621 PERSISTENT-ACTION: A function called with one arg i.e candidate.
6622 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
6623 NAME: The name related to this local source.
6624 SORT: A predicate to give to `sort' e.g `string-lessp'.
6625 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
6626 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
6628 Any prefix args passed during `anything-comp-read' invocation will be recorded
6629 in `anything-current-prefix-arg', otherwise if prefix args where given before
6630 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
6631 That's mean you can pass prefix arg before or after calling
6632 a command that use `anything-comp-read'."
6633 (when (get-buffer anything-action-buffer)
6634 (kill-buffer anything-action-buffer))
6635 (flet ((action-fn (candidate)
6636 (if marked-candidates
6637 (anything-marked-candidates)
6638 (identity candidate))))
6639 (or (anything
6640 :sources
6641 `(((name . ,(format "%s History" name))
6642 (candidates . (lambda ()
6643 (anything-comp-read-get-candidates history)))
6644 (volatile)
6645 (persistent-action . ,persistent-action)
6646 (persistent-help . ,persistent-help)
6647 (action . ,'action-fn))
6648 ((name . ,name)
6649 (candidates
6650 . (lambda ()
6651 (let ((cands (anything-comp-read-get-candidates
6652 collection test sort)))
6653 (if (or must-match (string= anything-pattern ""))
6654 cands (append (list anything-pattern) cands)))))
6655 (filtered-candidate-transformer ,fc-transformer)
6656 (requires-pattern . ,requires-pattern)
6657 (persistent-action . ,persistent-action)
6658 (persistent-help . ,persistent-help)
6659 (volatile)
6660 (action . ,'action-fn)))
6661 :input initial-input
6662 :prompt prompt
6663 :resume 'noresume
6664 :buffer buffer)
6665 (keyboard-quit))))
6667 (defun anything-c-get-pid-from-process-name (process-name)
6668 "Get pid from running process PROCESS-NAME."
6669 (loop with process-list = (list-system-processes)
6670 for pid in process-list
6671 for process = (assoc-default 'comm (process-attributes pid))
6672 when (and process (string-match process-name process))
6673 return pid))
6676 (defun anything-run-or-raise (exe &optional file)
6677 "Generic command that run asynchronously EXE.
6678 If EXE is already running just jump to his window if `anything-raise-command'
6679 is non--nil.
6680 When FILE argument is provided run EXE with FILE.
6681 In this case EXE must be provided as \"EXE %s\"."
6682 (let ((real-com (car (split-string (replace-regexp-in-string "'%s'" "" exe)))))
6683 (if (or (get-process real-com)
6684 (anything-c-get-pid-from-process-name real-com))
6685 (if anything-raise-command
6686 (shell-command (format anything-raise-command real-com))
6687 (error "Error: %s is already running" real-com))
6688 (when (member real-com anything-c-external-commands-list)
6689 (message "Starting %s..." real-com)
6690 (if file
6691 (start-process-shell-command real-com nil (format exe file))
6692 (start-process-shell-command real-com nil real-com))
6693 (set-process-sentinel
6694 (get-process real-com)
6695 #'(lambda (process event)
6696 (when (and (string= event "finished\n")
6697 anything-raise-command)
6698 (shell-command (format anything-raise-command "emacs")))
6699 (message "%s process...Finished." process))))
6700 (setq anything-c-external-commands-list
6701 (cons real-com (delete real-com anything-c-external-commands-list))))))
6704 (defvar anything-external-command-history nil)
6705 ;;;###autoload
6706 (defun anything-c-run-external-command (program)
6707 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
6708 If program is already running exit with error.
6709 You can set your own list of commands with
6710 `anything-c-external-commands-list'."
6711 (interactive (list
6712 (anything-comp-read
6713 "RunProgram: "
6714 (anything-c-external-commands-list-1 'sort)
6715 :must-match t
6716 :name "External Commands"
6717 :history anything-external-command-history)))
6718 (anything-run-or-raise program)
6719 (setq anything-external-command-history
6720 (cons program (delete program
6721 (loop for i in anything-external-command-history
6722 when (executable-find i) collect i)))))
6724 (defsubst* anything-c-position (item seq &key (test 'eq))
6725 "A simple and faster replacement of CL `position'."
6726 (loop for i in seq for index from 0
6727 when (funcall test i item) return index))
6729 (defvar anything-c-source-ratpoison-commands
6730 '((name . "Ratpoison Commands")
6731 (init . anything-c-ratpoison-commands-init)
6732 (candidates-in-buffer)
6733 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
6734 (display-to-real . anything-c-ratpoison-commands-display-to-real)
6735 (candidate-number-limit)))
6736 ;; (anything 'anything-c-source-ratpoison-commands)
6738 (defun anything-c-ratpoison-commands-init ()
6739 (unless (anything-candidate-buffer)
6740 (with-current-buffer (anything-candidate-buffer 'global)
6741 ;; with ratpoison prefix key
6742 (save-excursion
6743 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
6744 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
6745 (replace-match "<ratpoison> \\1: \\2"))
6746 (goto-char (point-max))
6747 ;; direct binding
6748 (save-excursion
6749 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
6750 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
6751 (replace-match "\\1: \\2")))))
6753 (defun anything-c-ratpoison-commands-display-to-real (display)
6754 (and (string-match ": " display)
6755 (substring display (match-end 0))))
6757 (defun anything-c-ratpoison-commands-execute (candidate)
6758 (call-process "ratpoison" nil nil nil "-ic" candidate))
6760 ;;;###autoload
6761 (defun anything-ratpoison-commands ()
6762 "Preconfigured `anything' to execute ratpoison commands."
6763 (interactive)
6764 (anything-other-buffer 'anything-c-source-ratpoison-commands
6765 "*anything ratpoison commands*"))
6767 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6768 ;;; Files
6769 (defvar anything-c-external-commands-list nil
6770 "A list of all external commands the user can execute. If this
6771 variable is not set by the user, it will be calculated
6772 automatically.")
6774 (defun anything-c-external-commands-list-1 (&optional sort)
6775 "Returns a list of all external commands the user can execute.
6776 If `anything-c-external-commands-list' is non-nil it will
6777 return its contents. Else it calculates all external commands
6778 and sets `anything-c-external-commands-list'."
6779 (if anything-c-external-commands-list
6780 anything-c-external-commands-list
6781 (setq anything-c-external-commands-list
6782 (loop
6783 with paths = (split-string (getenv "PATH") path-separator)
6784 with completions = ()
6785 for dir in paths
6786 when (and (file-exists-p dir) (file-accessible-directory-p dir))
6787 for lsdir = (loop for i in (directory-files dir t)
6788 for bn = (file-name-nondirectory i)
6789 when (and (not (member bn completions))
6790 (not (file-directory-p i))
6791 (file-executable-p i))
6792 collect bn)
6793 append lsdir into completions
6794 finally return (if sort (sort completions 'string-lessp) completions)))))
6797 (defun anything-c-file-buffers (filename)
6798 "Returns a list of buffer names corresponding to FILENAME."
6799 (let ((name (expand-file-name filename))
6800 (buf-list ()))
6801 (dolist (buf (buffer-list) buf-list)
6802 (let ((bfn (buffer-file-name buf)))
6803 (when (and bfn (string= name bfn))
6804 (push (buffer-name buf) buf-list))))))
6806 (defun anything-c-delete-file (file)
6807 "Delete the given file after querying the user.
6808 Ask to kill buffers associated with that file, too."
6809 (let ((buffers (anything-c-file-buffers file)))
6810 (dired-delete-file file 'dired-recursive-deletes)
6811 (when buffers
6812 (dolist (buf buffers)
6813 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
6814 (kill-buffer buf))))))
6816 (defun anything-get-mailcap-for-file (filename)
6817 "Get the command to use for FILENAME from mailcap files.
6818 The command is like <command %s> and is meant to use with `format'."
6819 (mailcap-parse-mailcaps)
6820 (let* ((ext (file-name-extension filename))
6821 (mime (when ext (mailcap-extension-to-mime ext))))
6822 (when mime (mailcap-mime-info mime))))
6824 (defun anything-get-default-program-for-file (filename)
6825 "Try to find a default program to open FILENAME.
6826 Try first in `anything-c-external-programs-associations' and then in mailcap file
6827 if nothing found return nil."
6828 (let* ((ext (file-name-extension filename))
6829 (def-prog (assoc-default ext anything-c-external-programs-associations)))
6830 (if (and def-prog (not (string= def-prog "")))
6831 (concat def-prog " %s")
6832 (anything-get-mailcap-for-file filename))))
6834 (defun anything-c-open-file-externally (file)
6835 "Open FILE with an external program.
6836 Try to guess which program to use with `anything-get-default-program-for-file'.
6837 If not found or a prefix arg is given query the user which tool to use."
6838 (let* ((fname (expand-file-name file))
6839 (collection (anything-c-external-commands-list-1 'sort))
6840 (def-prog (anything-get-default-program-for-file fname))
6841 (real-prog-name (or
6842 ;; No prefix arg, default program exists.
6843 (unless (or anything-current-prefix-arg (not def-prog))
6844 (replace-regexp-in-string " %s\\| '%s'" "" def-prog))
6845 ;; Prefix arg or no default program.
6846 (anything-comp-read
6847 "Program: " collection
6848 :must-match t
6849 :name "Open file Externally"
6850 :history anything-external-command-history)))
6851 (program (concat real-prog-name " '%s'")))
6852 (unless (or def-prog ; Association exists, no need to record it.
6853 (not (file-exists-p fname))) ; Don't record non--filenames.
6854 (when
6855 (y-or-n-p
6856 (format
6857 "Do you want to make %s the default program for this kind of files? "
6858 real-prog-name))
6859 (push (cons (file-name-extension fname)
6860 (read-string
6861 "Program(Add args maybe and confirm): " real-prog-name))
6862 anything-c-external-programs-associations)
6863 (customize-save-variable 'anything-c-external-programs-associations
6864 anything-c-external-programs-associations)))
6865 (anything-run-or-raise program file)
6866 (setq anything-external-command-history
6867 (cons real-prog-name
6868 (delete real-prog-name
6869 (loop for i in anything-external-command-history
6870 when (executable-find i) collect i))))))
6873 ;;;###autoload
6874 (defun w32-shell-execute-open-file (file)
6875 (interactive "fOpen file:")
6876 (with-no-warnings
6877 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
6878 "/" "\\"
6879 (replace-regexp-in-string ; strip cygdrive paths
6880 "/cygdrive/\\(.\\)" "\\1:"
6881 file nil nil) nil t))))
6883 (defun anything-c-open-file-with-default-tool (file)
6884 "Open FILE with the default tool on this platform."
6885 (if (eq system-type 'windows-nt)
6886 (w32-shell-execute-open-file file)
6887 (start-process "anything-c-open-file-with-default-tool"
6889 (cond ((eq system-type 'gnu/linux)
6890 "xdg-open")
6891 ((or (eq system-type 'darwin) ;; Mac OS X
6892 (eq system-type 'macos)) ;; Mac OS 9
6893 "open"))
6894 file)))
6896 (defun anything-c-open-dired (file)
6897 "Opens a dired buffer in FILE's directory. If FILE is a
6898 directory, open this directory."
6899 (if (file-directory-p file)
6900 (dired file)
6901 (dired (file-name-directory file))
6902 (dired-goto-file file)))
6904 (defun anything-c-display-to-real-line (candidate)
6905 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
6906 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
6907 (error "Line number not found")))
6909 (defun anything-c-action-line-goto (lineno-and-content)
6910 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
6911 (append lineno-and-content
6912 (list (if (and (anything-attr-defined 'target-file)
6913 (not anything-in-persistent-action))
6914 'find-file-other-window
6915 'find-file)))))
6917 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
6918 (apply #'anything-goto-file-line
6919 (if (stringp file-line-content)
6920 ;; Case: filtered-candidate-transformer is skipped
6921 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
6922 file-line-content)))
6924 (require 'compile)
6925 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
6926 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
6928 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
6929 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
6930 (let ((filename (match-string 1 candidate))
6931 (lineno (match-string 2 candidate))
6932 (content (match-string 3 candidate)))
6933 (cons (format "%s:%s\n %s"
6934 (propertize filename 'face compilation-info-face)
6935 (propertize lineno 'face compilation-line-face)
6936 content)
6937 (list (expand-file-name
6938 filename
6939 (or (anything-interpret-value (anything-attr 'default-directory))
6940 (and (anything-candidate-buffer)
6941 (buffer-local-value
6942 'default-directory (anything-candidate-buffer)))))
6943 (string-to-number lineno) content)))))
6945 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
6946 (anything-aif (anything-attr 'before-jump-hook)
6947 (funcall it))
6948 (when file (funcall find-file-function file))
6949 (if (anything-attr-defined 'adjust)
6950 (anything-c-goto-line-with-adjustment lineno content)
6951 (anything-goto-line lineno))
6952 (unless (anything-attr-defined 'recenter)
6953 (set-window-start (get-buffer-window anything-current-buffer) (point)))
6954 (anything-aif (anything-attr 'after-jump-hook)
6955 (funcall it))
6956 (when anything-in-persistent-action
6957 (anything-match-line-color-current-line)))
6959 (defun anything-find-file-as-root (candidate)
6960 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
6962 (defun anything-find-many-files (ignore)
6963 (mapc 'find-file (anything-marked-candidates)))
6965 ;; borrowed from etags.el
6966 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
6967 (defun anything-c-goto-line-with-adjustment (line line-content)
6968 (let ((startpos)
6969 offset found pat)
6970 ;; This constant is 1/2 the initial search window.
6971 ;; There is no sense in making it too small,
6972 ;; since just going around the loop once probably
6973 ;; costs about as much as searching 2000 chars.
6974 (setq offset 1000
6975 found nil
6976 pat (concat (if (eq selective-display t)
6977 "\\(^\\|\^m\\) *" "^ *") ;allow indent
6978 (regexp-quote line-content)))
6979 ;; If no char pos was given, try the given line number.
6980 (setq startpos (progn (anything-goto-line line) (point)))
6981 (or startpos (setq startpos (point-min)))
6982 ;; First see if the tag is right at the specified location.
6983 (goto-char startpos)
6984 (setq found (looking-at pat))
6985 (while (and (not found)
6986 (progn
6987 (goto-char (- startpos offset))
6988 (not (bobp))))
6989 (setq found
6990 (re-search-forward pat (+ startpos offset) t)
6991 offset (* 3 offset))) ; expand search window
6992 (or found
6993 (re-search-forward pat nil t)
6994 (error "not found")))
6995 ;; Position point at the right place
6996 ;; if the search string matched an extra Ctrl-m at the beginning.
6997 (and (eq selective-display t)
6998 (looking-at "\^m")
6999 (forward-char 1))
7000 (beginning-of-line))
7002 (anything-document-attribute 'default-directory "type . file-line"
7003 "`default-directory' to interpret file.")
7004 (anything-document-attribute 'before-jump-hook "type . file-line / line"
7005 "Function to call before jumping to the target location.")
7006 (anything-document-attribute 'after-jump-hook "type . file-line / line"
7007 "Function to call after jumping to the target location.")
7008 (anything-document-attribute 'adjust "type . file-line"
7009 "Search around line matching line contents.")
7010 (anything-document-attribute 'recenter "type . file-line / line"
7011 "`recenter' after jumping.")
7012 (anything-document-attribute 'target-file "type . line"
7013 "Goto line of target-file.")
7015 ;;;###autoload
7016 (defun anything-c-call-interactively (cmd-or-name)
7017 "Execute CMD-OR-NAME as Emacs command.
7018 It is added to `extended-command-history'.
7019 `anything-current-prefix-arg' is used as the command's prefix argument."
7020 (setq extended-command-history
7021 (cons (anything-c-stringify cmd-or-name)
7022 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
7023 (let ((current-prefix-arg anything-current-prefix-arg)
7024 (cmd (anything-c-symbolify cmd-or-name)))
7025 (if (stringp (symbol-function cmd))
7026 (execute-kbd-macro (symbol-function cmd))
7027 (setq this-command cmd)
7028 (call-interactively cmd))))
7030 ;;;###autoload
7031 (defun anything-c-set-variable (var)
7032 "Set value to VAR interactively."
7033 (interactive)
7034 (let ((sym (anything-c-symbolify var)))
7035 (set sym (eval-minibuffer (format "Set %s: " var)
7036 (prin1-to-string (symbol-value sym))))))
7037 ;; (setq hh 12)
7038 ;; (anything-c-set-variable 'hh)
7040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7041 (defvar anything-match-line-overlay-face nil)
7042 (defvar anything-match-line-overlay nil)
7044 (defun anything-match-line-color-current-line (&optional start end buf face rec)
7045 "Highlight and underline current position"
7046 (let ((args (list (or start (line-beginning-position))
7047 (or end (1+ (line-end-position)))
7048 buf)))
7049 (if (not anything-match-line-overlay)
7050 (setq anything-match-line-overlay (apply 'make-overlay args))
7051 (apply 'move-overlay anything-match-line-overlay args)))
7052 (overlay-put anything-match-line-overlay
7053 'face (or face anything-match-line-overlay-face))
7054 (when rec
7055 (goto-char start)
7056 (recenter)))
7058 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
7060 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
7061 "Face for source header in the anything buffer." :group 'anything)
7063 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
7065 (defun anything-match-line-cleanup ()
7066 (when anything-match-line-overlay
7067 (delete-overlay anything-match-line-overlay)
7068 (setq anything-match-line-overlay nil)))
7070 (defun anything-match-line-update ()
7071 (when anything-match-line-overlay
7072 (delete-overlay anything-match-line-overlay)
7073 (anything-match-line-color-current-line)))
7075 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
7076 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
7078 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7079 ;;; Files
7080 (defun anything-c-transform-file-load-el (actions candidate)
7081 "Add action to load the file CANDIDATE if it is an emacs lisp
7082 file. Else return ACTIONS unmodified."
7083 (if (member (file-name-extension candidate) '("el" "elc"))
7084 (append actions '(("Load Emacs Lisp File" . load-file)))
7085 actions))
7087 (defun anything-c-transform-file-browse-url (actions candidate)
7088 "Add an action to browse the file CANDIDATE if it in a html
7089 file or URL. Else return ACTIONS unmodified."
7090 (let ((browse-action '("Browse with Browser" . browse-url)))
7091 (cond ((string-match "^http\\|^ftp" candidate)
7092 (cons browse-action actions))
7093 ((string-match "\\.html?$" candidate)
7094 (append actions (list browse-action)))
7095 (t actions))))
7097 ;;;; Function
7098 (defun anything-c-transform-function-call-interactively (actions candidate)
7099 "Add an action to call the function CANDIDATE interactively if
7100 it is a command. Else return ACTIONS unmodified."
7101 (if (commandp (intern-soft candidate))
7102 (append actions '(("Call Interactively"
7104 anything-c-call-interactively)))
7105 actions))
7107 ;;;; S-Expressions
7108 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
7109 "If CANDIDATE's `car' is a command, then add an action to
7110 evaluate it and put it onto the `command-history'."
7111 (if (commandp (car (read candidate)))
7112 ;; Make it first entry
7113 (cons '("Eval and put onto command-history" .
7114 (lambda (sexp)
7115 (let ((sym (read sexp)))
7116 (eval sym)
7117 (setq command-history
7118 (cons sym command-history)))))
7119 actions)
7120 actions))
7122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7123 ;;; Buffers
7124 (defun anything-c-skip-boring-buffers (buffers)
7125 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
7127 (defun anything-c-skip-current-buffer (buffers)
7128 (if anything-allow-skipping-current-buffer
7129 (remove (buffer-name anything-current-buffer) buffers)
7130 buffers))
7132 (defun anything-c-shadow-boring-buffers (buffers)
7133 "Buffers matching `anything-c-boring-buffer-regexp' will be
7134 displayed with the `file-name-shadow' face if available."
7135 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
7137 ;;; Files
7138 (defun anything-c-shadow-boring-files (files)
7139 "Files matching `anything-c-boring-file-regexp' will be
7140 displayed with the `file-name-shadow' face if available."
7141 (anything-c-shadow-entries files anything-c-boring-file-regexp))
7143 (defun anything-c-skip-boring-files (files)
7144 "Files matching `anything-c-boring-file-regexp' will be skipped."
7145 (anything-c-skip-entries files anything-c-boring-file-regexp))
7146 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
7148 (defun anything-c-skip-current-file (files)
7149 "Current file will be skipped."
7150 (remove (buffer-file-name anything-current-buffer) files))
7152 (defun anything-c-w32-pathname-transformer (args)
7153 "Change undesirable features of windows pathnames to ones more acceptable to
7154 other candidate transformers."
7155 (if (eq system-type 'windows-nt)
7156 (mapcar (lambda (x)
7157 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
7158 (mapcar (lambda (y)
7159 (replace-regexp-in-string "\\\\" "/" y)) args))
7160 args))
7162 (defun anything-c-shorten-home-path (files)
7163 "Replaces /home/user with ~."
7164 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
7165 (getenv "HOME"))))
7166 (mapcar (lambda (file)
7167 (if (and (stringp file) (string-match home file))
7168 (cons (replace-match "~" nil nil file) file)
7169 file))
7170 files)))
7172 ;;; Functions
7173 (defun anything-c-mark-interactive-functions (functions)
7174 "Mark interactive functions (commands) with (i) after the function name."
7175 (let (list)
7176 (loop for function in functions
7177 do (push (cons (concat function
7178 (when (commandp (intern-soft function)) " (i)"))
7179 function)
7180 list)
7181 finally (return (nreverse list)))))
7183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7184 (defvar anything-c-adaptive-done nil
7185 "nil if history information is not yet stored for the current
7186 selection.")
7188 (defvar anything-c-adaptive-history nil
7189 "Contains the stored history information.
7190 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
7192 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
7193 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
7194 when anything is started."
7195 (setq anything-c-adaptive-done nil))
7197 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
7198 "Advise `anything-exit-minibuffer' to store history information
7199 when a candidate is selected with RET."
7200 (anything-c-adaptive-store-selection))
7202 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
7203 "Advise `anything-select-action' to store history information
7204 when the user goes to the action list with TAB."
7205 (anything-c-adaptive-store-selection))
7207 (defun anything-c-source-use-adaptative-p (&optional source-name)
7208 "Return current source only if it use adaptative history, nil otherwise."
7209 (let* ((source (or source-name (anything-get-current-source)))
7210 (adapt-source (or (assoc-default 'filtered-candidate-transformer
7211 (assoc (assoc-default 'type source)
7212 anything-type-attributes))
7213 (assoc-default 'candidate-transformer
7214 (assoc (assoc-default 'type source)
7215 anything-type-attributes))
7216 (assoc-default 'filtered-candidate-transformer source)
7217 (assoc-default 'candidate-transformer source))))
7218 (if (listp adapt-source)
7219 (when (member 'anything-c-adaptive-sort adapt-source) source)
7220 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
7222 (defun anything-c-adaptive-store-selection ()
7223 "Store history information for the selected candidate."
7224 (unless anything-c-adaptive-done
7225 (setq anything-c-adaptive-done t)
7226 (let ((source (anything-c-source-use-adaptative-p)))
7227 (when source
7228 (let* ((source-name (or (assoc-default 'type source)
7229 (assoc-default 'name source)))
7230 (source-info (or (assoc source-name anything-c-adaptive-history)
7231 (progn
7232 (push (list source-name) anything-c-adaptive-history)
7233 (car anything-c-adaptive-history))))
7234 (selection (anything-get-selection))
7235 (selection-info (progn
7236 (setcdr source-info
7237 (cons
7238 (let ((found (assoc selection (cdr source-info))))
7239 (if (not found)
7240 ;; new entry
7241 (list selection)
7243 ;; move entry to the beginning of the
7244 ;; list, so that it doesn't get
7245 ;; trimmed when the history is
7246 ;; truncated
7247 (setcdr source-info
7248 (delete found (cdr source-info)))
7249 found))
7250 (cdr source-info)))
7251 (cadr source-info)))
7252 (pattern-info (progn
7253 (setcdr selection-info
7254 (cons
7255 (let ((found (assoc anything-pattern (cdr selection-info))))
7256 (if (not found)
7257 ;; new entry
7258 (cons anything-pattern 0)
7260 ;; move entry to the beginning of the
7261 ;; list, so if two patterns used the
7262 ;; same number of times then the one
7263 ;; used last appears first in the list
7264 (setcdr selection-info
7265 (delete found (cdr selection-info)))
7266 found))
7267 (cdr selection-info)))
7268 (cadr selection-info))))
7270 ;; increase usage count
7271 (setcdr pattern-info (1+ (cdr pattern-info)))
7273 ;; truncate history if needed
7274 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
7275 (setcdr selection-info
7276 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
7278 (if (file-readable-p anything-c-adaptive-history-file)
7279 (load-file anything-c-adaptive-history-file))
7280 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
7282 (defun anything-c-adaptive-save-history ()
7283 "Save history information to file given by `anything-c-adaptive-history-file'."
7284 (interactive)
7285 (with-temp-buffer
7286 (insert
7287 ";; -*- mode: emacs-lisp -*-\n"
7288 ";; History entries used for anything adaptive display.\n")
7289 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
7290 (current-buffer))
7291 (insert ?\n)
7292 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
7293 (unless (interactive-p) 'quiet))))
7295 (defun anything-c-adaptive-sort (candidates source)
7296 "Sort the CANDIDATES for SOURCE by usage frequency.
7297 This is a filtered candidate transformer you can use for the
7298 attribute `filtered-candidate-transformer' of a source in
7299 `anything-sources' or a type in `anything-type-attributes'."
7300 (let* ((source-name (or (assoc-default 'type source)
7301 (assoc-default 'name source)))
7302 (source-info (assoc source-name anything-c-adaptive-history)))
7303 (if (not source-info)
7304 ;; if there is no information stored for this source then do nothing
7305 candidates
7306 ;; else...
7307 (let ((usage
7308 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
7309 ;; pairs
7310 (mapcar (lambda (candidate-info)
7311 (let ((count 0))
7312 (dolist (pattern-info (cdr candidate-info))
7313 (if (not (equal (car pattern-info)
7314 anything-pattern))
7315 (incf count (cdr pattern-info))
7317 ;; if current pattern is equal to the previously
7318 ;; used one then this candidate has priority
7319 ;; (that's why its count is boosted by 10000) and
7320 ;; it only has to compete with other candidates
7321 ;; which were also selected with the same pattern
7322 (setq count (+ 10000 (cdr pattern-info)))
7323 (return)))
7324 (cons (car candidate-info) count)))
7325 (cdr source-info)))
7326 sorted)
7328 ;; sort the list in descending order, so candidates with highest
7329 ;; priorty come first
7330 (setq usage (sort usage (lambda (first second)
7331 (> (cdr first) (cdr second)))))
7333 ;; put those candidates first which have the highest usage count
7334 (dolist (info usage)
7335 (when (member* (car info) candidates
7336 :test 'anything-c-adaptive-compare)
7337 (push (car info) sorted)
7338 (setq candidates (remove* (car info) candidates
7339 :test 'anything-c-adaptive-compare))))
7341 ;; and append the rest
7342 (append (reverse sorted) candidates nil)))))
7344 (defun anything-c-adaptive-compare (x y)
7345 "Compare candidates X and Y taking into account that the
7346 candidate can be in (DISPLAY . REAL) format."
7347 (equal (if (listp x)
7348 (cdr x)
7350 (if (listp y)
7351 (cdr y)
7352 y)))
7354 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7355 (defvar anything-outline-goto-near-line-flag t)
7356 (defvar anything-outline-using nil)
7357 (defun anything-after-update-hook--outline ()
7358 (if (and (eq anything-outline-using t)
7359 (eq anything-outline-goto-near-line-flag t))
7360 (anything-outline-goto-near-line)))
7361 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
7363 (defun anything-outline-goto-near-line ()
7364 (with-anything-window
7365 ;; TODO need consideration whether to update position by every input.
7366 (when t ; (equal anything-pattern "")
7367 (anything-goto-line 2)
7368 (let ((lineno (with-current-buffer anything-current-buffer
7369 (line-number-at-pos (car anything-current-position)))))
7370 (block exit
7371 (while (<= (progn (skip-chars-forward " ")
7372 (or (number-at-point) lineno))
7373 lineno)
7374 (forward-line 1)
7375 (when (eobp)
7376 (forward-line -1)
7377 (return-from exit))))
7378 (forward-line -1)
7379 (and (bobp) (forward-line 1))
7380 (and (anything-pos-header-line-p) (forward-line -2))
7381 (anything-mark-current-line)))))
7383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7384 ;; Plug-in: info-index
7385 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
7386 (let (result)
7387 (unless (anything-candidate-buffer)
7388 (save-window-excursion
7389 (info file)
7390 (let (Info-history
7391 (tobuf (anything-candidate-buffer 'global))
7392 (infobuf (current-buffer))
7393 s e)
7394 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
7395 (Info-goto-node node)
7396 (goto-char (point-min))
7397 (while (search-forward "\n* " nil t)
7398 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
7399 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
7400 (setq s (point-at-bol)
7401 e (point-at-eol))
7402 (with-current-buffer tobuf
7403 (insert-buffer-substring infobuf s e)
7404 (insert "\n"))))))))))
7406 (defun anything-c-info-goto (node-line)
7407 (Info-goto-node (car node-line))
7408 (anything-goto-line (cdr node-line)))
7410 (defun anything-c-info-display-to-real (line)
7411 (and (string-match
7412 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
7413 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
7414 (string-to-number (or (match-string 3 line) "1")))))
7416 (defun anything-c-make-info-source (file)
7417 `((name . ,(concat "Info Index: " file))
7418 (info-file . ,file)
7419 (init . anything-c-info-init)
7420 (display-to-real . anything-c-info-display-to-real)
7421 (get-line . buffer-substring)
7422 (candidates-in-buffer)
7423 (action ("Goto node" . anything-c-info-goto))))
7425 (defun anything-compile-source--info-index (source)
7426 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
7427 (anything-c-make-info-source it)
7428 source))
7429 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
7431 (anything-document-attribute 'info-index "info-index plugin"
7432 "Create a source of info index very easily.
7434 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
7436 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
7437 "Index nodes of info file.
7439 If it is omitted, `Info-index-nodes' is used to collect index nodes.
7440 Some info files are missing index specification.
7442 ex. See `anything-c-source-info-screen'.")
7444 ;; Plug-in: candidates-file
7445 (defun anything-compile-source--candidates-file (source)
7446 (if (assoc-default 'candidates-file source)
7447 `((init anything-p-candidats-file-init
7448 ,@(let ((orig-init (assoc-default 'init source)))
7449 (cond ((null orig-init) nil)
7450 ((functionp orig-init) (list orig-init))
7451 (t orig-init))))
7452 (candidates-in-buffer)
7453 ,@source)
7454 source))
7455 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
7457 (defun anything-p-candidats-file-init ()
7458 (destructuring-bind (file &optional updating)
7459 (anything-mklist (anything-attr 'candidates-file))
7460 (setq file (anything-interpret-value file))
7461 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
7462 (when updating
7463 (buffer-disable-undo)
7464 (font-lock-mode -1)
7465 (auto-revert-mode 1)))))
7467 (anything-document-attribute 'candidates-file "candidates-file plugin"
7468 "Use a file as the candidates buffer.
7470 1st argument is a filename, string or function name or variable name.
7471 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
7473 ;; Plug-in: headline
7474 (defun anything-compile-source--anything-headline (source)
7475 (if (assoc-default 'headline source)
7476 (append '((init . anything-headline-init)
7477 (get-line . buffer-substring)
7478 (type . line))
7479 source
7480 '((candidates-in-buffer)
7481 (persistent-help . "Show this line")))
7482 source))
7483 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
7485 (defun anything-headline-init ()
7486 (when (and (anything-current-buffer-is-modified)
7487 (with-current-buffer anything-current-buffer
7488 (eval (or (anything-attr 'condition) t))))
7489 (anything-headline-make-candidate-buffer
7490 (anything-interpret-value (anything-attr 'headline))
7491 (anything-interpret-value (anything-attr 'subexp)))))
7493 (anything-document-attribute 'headline "Headline plug-in"
7494 "Regexp string for anything-headline to scan.")
7495 (anything-document-attribute 'condition "Headline plug-in"
7496 "A sexp representing the condition to use anything-headline.")
7497 (anything-document-attribute 'subexp "Headline plug-in"
7498 "Display (match-string-no-properties subexp).")
7501 (defun anything-headline-get-candidates (regexp subexp)
7502 (with-current-buffer anything-current-buffer
7503 (save-excursion
7504 (goto-char (point-min))
7505 (if (functionp regexp) (setq regexp (funcall regexp)))
7506 (let (hierarchy curhead)
7507 (flet ((matched ()
7508 (if (numberp subexp)
7509 (cons (match-string-no-properties subexp) (match-beginning subexp))
7510 (cons (buffer-substring (point-at-bol) (point-at-eol))
7511 (point-at-bol))))
7512 (hierarchies (headlines)
7513 (1+ (loop for (_ . hierarchy) in headlines
7514 maximize hierarchy)))
7515 (vector-0-n (v n)
7516 (loop for i from 0 to hierarchy
7517 collecting (aref curhead i)))
7518 (arrange (headlines)
7519 (unless (null headlines) ; FIX headlines empty bug!
7520 (loop with curhead = (make-vector (hierarchies headlines) "")
7521 for ((str . pt) . hierarchy) in headlines
7522 do (aset curhead hierarchy str)
7523 collecting
7524 (cons
7525 (format "H%d:%s" (1+ hierarchy)
7526 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
7527 pt)))))
7528 (if (listp regexp)
7529 (arrange
7530 (sort
7531 (loop for re in regexp
7532 for hierarchy from 0
7533 do (goto-char (point-min))
7534 appending
7535 (loop
7536 while (re-search-forward re nil t)
7537 collect (cons (matched) hierarchy)))
7538 (lambda (a b) (> (cdar b) (cdar a)))))
7539 (loop while (re-search-forward regexp nil t)
7540 collect (matched))))))))
7543 (defun anything-headline-make-candidate-buffer (regexp subexp)
7544 (with-current-buffer (anything-candidate-buffer 'local)
7545 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
7546 do (insert
7547 (format "%5d:%s\n"
7548 (with-current-buffer anything-current-buffer
7549 (line-number-at-pos pos))
7550 content)))))
7552 (defun anything-headline-goto-position (pos recenter)
7553 (goto-char pos)
7554 (unless recenter
7555 (set-window-start (get-buffer-window anything-current-buffer) (point))))
7557 (defun anything-revert-buffer (candidate)
7558 (with-current-buffer candidate
7559 (when (buffer-modified-p)
7560 (revert-buffer t t))))
7562 (defun anything-revert-marked-buffers (ignore)
7563 (mapc 'anything-revert-buffer (anything-marked-candidates)))
7565 (defun anything-kill-marked-buffers (ignore)
7566 (mapc 'kill-buffer (anything-marked-candidates)))
7568 ;; Plug-in: persistent-help
7569 (defun anything-compile-source--persistent-help (source)
7570 (append source '((header-line . anything-persistent-help-string))))
7571 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
7573 (defun anything-persistent-help-string ()
7574 (substitute-command-keys
7575 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
7576 (or (anything-interpret-value (anything-attr 'persistent-help))
7577 (anything-aif (or (assoc-default 'persistent-action
7578 (anything-get-current-source))
7579 (assoc-default 'action
7580 (anything-get-current-source)))
7581 (cond ((symbolp it) (symbol-name it))
7582 ((listp it) (or (ignore-errors (caar it)) ""))))
7584 " (keeping session)")))
7586 (anything-document-attribute 'persistent-help "persistent-help plug-in"
7587 "A string to explain persistent-action of this source.
7588 It also accepts a function or a variable name.")
7590 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
7592 ;; Plug-in: Type customize
7593 (defun anything-c-uniq-list (lst)
7594 "Like `remove-duplicates' in CL.
7595 But cut deeper duplicates and test by `equal'. "
7596 (reverse (remove-duplicates (reverse lst) :test 'equal)))
7597 (defvar anything-additional-type-attributes nil)
7598 (defun anything-c-arrange-type-attribute (type spec)
7599 "Override type attributes by `define-anything-type-attribute'.
7601 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
7603 Example: Set `play-sound-file' as default action
7604 (anything-c-arrange-type-attribute 'file
7605 '((action (\"Play sound\" . play-sound-file)
7606 REST ;; Rest of actions (find-file, find-file-other-window, ...)
7609 (add-to-list 'anything-additional-type-attributes
7610 (cons type
7611 (loop with typeattr = (assoc-default type anything-type-attributes)
7612 for (attr . value) in spec
7613 if (listp value)
7614 collect (cons attr
7615 (anything-c-uniq-list
7616 (loop for v in value
7617 if (eq v 'REST)
7618 append (assoc-default attr typeattr)
7619 else
7620 collect v)))
7621 else
7622 collect (cons attr value)))))
7623 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
7625 (defun anything-compile-source--type-customize (source)
7626 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
7627 (append it source)
7628 source))
7629 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
7631 ;; Plug-in: default-action
7632 (defun anything-compile-source--default-action (source)
7633 (anything-aif (assoc-default 'default-action source)
7634 (append `((action ,it ,@(remove it (assoc-default 'action source))))
7635 source)
7636 source))
7637 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
7638 (anything-document-attribute 'default-action "default-action plug-in"
7639 "Default action.")
7641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7643 (defun anything-c-find-file-or-marked (candidate)
7644 "Open file CANDIDATE or open anything marked files in background."
7645 (let ((marked (anything-marked-candidates)))
7646 (if (> (length marked) 1)
7647 ;; Open all marked files in background.
7648 (mapc 'find-file-noselect marked)
7649 (if (and (not (file-exists-p candidate))
7650 (and ffap-url-regexp
7651 (not (string-match ffap-url-regexp candidate)))
7652 (string-match "/$" candidate))
7653 ;; A a non--existing filename ending with /
7654 ;; Create a directory and jump to it.
7655 (when (y-or-n-p (format "Create directory `%s'? " candidate))
7656 (let ((cur-dir default-directory))
7657 (unwind-protect
7658 (progn
7659 (make-directory candidate 'parent)
7660 (when (file-exists-p candidate)
7661 (cd candidate)
7662 (anything-find-files candidate)))
7663 (setq default-directory cur-dir))))
7664 ;; A non--existing filename NOT ending with / or
7665 ;; an existing filename, create or jump to it.
7666 (find-file-at-point (car marked))))))
7668 (defun anything-delete-marked-files (ignore)
7669 (let* ((files (anything-marked-candidates))
7670 (len (length files)))
7671 (if (not (y-or-n-p
7672 (format "Delete *%s File(s):\n%s"
7674 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
7675 (message "(No deletions performed)")
7676 (dolist (i files)
7677 (set-text-properties 0 (length i) nil i)
7678 (anything-c-delete-file i))
7679 (message "%s File(s) deleted" len))))
7681 (defun anything-ediff-marked-buffers (candidate &optional merge)
7682 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
7683 With optional arg `merge' call `ediff-merge-buffers'."
7684 (let ((lg-lst (length (anything-marked-candidates)))
7685 buf1 buf2)
7686 (case lg-lst
7688 (error "Error:You have to mark at least 1 buffer"))
7690 (setq buf1 anything-current-buffer
7691 buf2 (first (anything-marked-candidates))))
7693 (setq buf1 (first (anything-marked-candidates))
7694 buf2 (second (anything-marked-candidates))))
7696 (error "Error:To much buffers marked!")))
7697 (if merge
7698 (ediff-merge-buffers buf1 buf2)
7699 (ediff-buffers buf1 buf2))))
7701 (defun anything-bookmark-get-bookmark-from-name (bmk)
7702 "Return bookmark name even if it is a bookmark with annotation.
7703 e.g prepended with *.
7704 Return nil if bmk is not a valid bookmark."
7705 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
7706 (if (assoc bookmark bookmark-alist)
7707 bookmark
7708 (when (assoc bmk bookmark-alist)
7709 bmk))))
7711 (defun anything-delete-marked-bookmarks (ignore)
7712 "Delete this bookmark or all marked bookmarks."
7713 (dolist (i (anything-marked-candidates))
7714 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
7715 'batch)))
7717 (defun anything-require-or-error (feature function)
7718 (or (require feature nil t)
7719 (error "Need %s to use `%s'." feature function)))
7721 (defun anything-find-buffer-on-elscreen (candidate)
7722 "Open buffer in new screen, if marked buffers open all in elscreens."
7723 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
7724 (anything-aif (anything-marked-candidates)
7725 (dolist (i it)
7726 (let ((target-screen (elscreen-find-screen-by-buffer
7727 (get-buffer i) 'create)))
7728 (elscreen-goto target-screen)))
7729 (let ((target-screen (elscreen-find-screen-by-buffer
7730 (get-buffer candidate) 'create)))
7731 (elscreen-goto target-screen))))
7733 (defun anything-elscreen-find-file (file)
7734 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
7735 (elscreen-find-file file))
7737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7739 ;;;; Type Attributes
7740 (define-anything-type-attribute 'buffer
7741 `((action
7742 ,@(if pop-up-frames
7743 '(("Switch to buffer other window" . switch-to-buffer-other-window)
7744 ("Switch to buffer" . switch-to-buffer))
7745 '(("Switch to buffer" . switch-to-buffer)
7746 ("Switch to buffer other window" . switch-to-buffer-other-window)
7747 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
7748 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
7749 ("View buffer" . view-buffer)
7750 ("Display buffer" . display-buffer)
7751 ("Revert buffer" . anything-revert-buffer)
7752 ("Revert Marked buffers" . anything-revert-marked-buffers)
7753 ("Insert buffer" . insert-buffer)
7754 ("Kill buffer" . kill-buffer)
7755 ("Kill Marked buffers" . anything-kill-marked-buffers)
7756 ("Diff with file" . diff-buffer-with-file)
7757 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
7758 ("Ediff Merge marked buffers" . (lambda (candidate)
7759 (anything-ediff-marked-buffers candidate t))))
7760 (persistent-help . "Show this buffer")
7761 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
7762 "Buffer or buffer name.")
7764 (define-anything-type-attribute 'file
7765 `((action
7766 ,@(if pop-up-frames
7767 '(("Find file other window" . find-file-other-window)
7768 ("Find file(s)" . anything-find-many-files)
7769 ("Find file as root" . anything-find-file-as-root))
7770 '(("Find file" . anything-find-many-files)
7771 ("Find file as root" . anything-find-file-as-root)
7772 ("Find file other window" . find-file-other-window)
7773 ("Find file other frame" . find-file-other-frame)))
7774 ("Open dired in file's directory" . anything-c-open-dired)
7775 ("Grep File(s) `C-u recurse'"
7776 . (lambda (candidate)
7777 (if anything-current-prefix-arg
7778 (anything-do-grep (anything-marked-candidates) 'recurse)
7779 (anything-do-grep (anything-marked-candidates)))))
7780 ("View file" . view-file)
7781 ("Insert file" . insert-file)
7782 ("Delete file(s)" . anything-delete-marked-files)
7783 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
7784 ("Open file with default tool" . anything-c-open-file-with-default-tool)
7785 ("Find file in hex dump" . hexl-find-file))
7786 (persistent-help . "Show this file")
7787 (action-transformer anything-c-transform-file-load-el
7788 anything-c-transform-file-browse-url)
7789 (candidate-transformer anything-c-w32-pathname-transformer
7790 anything-c-skip-current-file
7791 anything-c-skip-boring-files
7792 anything-c-shorten-home-path))
7793 "File name.")
7795 (let ((actions '(("Describe command" . describe-function)
7796 ("Add command to kill ring" . anything-c-kill-new)
7797 ("Go to command's definition" . find-function)
7798 ("Debug on entry" . debug-on-entry)
7799 ("Cancel debug on entry" . cancel-debug-on-entry)
7800 ("Trace function" . trace-function)
7801 ("Trace function (background)" . trace-function-background)
7802 ("Untrace function" . untrace-function))))
7803 (define-anything-type-attribute 'command
7804 `((action ("Call interactively" . anything-c-call-interactively)
7805 ,@actions)
7806 ;; Sort commands according to their usage count.
7807 (filtered-candidate-transformer . anything-c-adaptive-sort)
7808 (coerce . anything-c-symbolify)
7809 (persistent-action . describe-function))
7810 "Command. (string or symbol)")
7812 (define-anything-type-attribute 'function
7813 `((action . ,actions)
7814 (action-transformer anything-c-transform-function-call-interactively)
7815 (candidate-transformer anything-c-mark-interactive-functions)
7816 (coerce . anything-c-symbolify))
7817 "Function. (string or symbol)"))
7819 (define-anything-type-attribute 'variable
7820 '((action ("Describe variable" . describe-variable)
7821 ("Add variable to kill ring" . anything-c-kill-new)
7822 ("Go to variable's definition" . find-variable)
7823 ("Set variable" . anything-c-set-variable))
7824 (coerce . anything-c-symbolify))
7825 "Variable.")
7827 (define-anything-type-attribute 'sexp
7828 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
7829 ("Add s-expression to kill ring" . kill-new))
7830 (action-transformer anything-c-transform-sexp-eval-command-sexp))
7831 "String representing S-Expressions.")
7833 (define-anything-type-attribute 'bookmark
7834 `((coerce . anything-bookmark-get-bookmark-from-name)
7835 (action
7836 ("Jump to bookmark" . (lambda (bookmark)
7837 (let ((current-prefix-arg anything-current-prefix-arg))
7838 (bookmark-jump bookmark))
7839 (anything-update)))
7840 ("Jump to BM other window" . (lambda (bookmark)
7841 (bookmark-jump-other-window bookmark)
7842 (anything-update)))
7843 ("Bookmark edit annotation" . bookmark-edit-annotation)
7844 ("Bookmark show annotation" . bookmark-show-annotation)
7845 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
7846 ,@(when (fboundp 'bmkext-edit-bookmark)
7847 '(("Edit Bookmark" . bmkext-edit-bookmark)))
7848 ("Rename bookmark" . bookmark-rename)
7849 ("Relocate bookmark" . bookmark-relocate)))
7850 "Bookmark name.")
7852 (define-anything-type-attribute 'line
7853 '((display-to-real . anything-c-display-to-real-line)
7854 (action ("Go to Line" . anything-c-action-line-goto)))
7855 "LINENO:CONTENT string, eg. \" 16:foo\".
7857 Optional `target-file' attribute is a name of target file.
7859 Optional `before-jump-hook' attribute is a function with no
7860 arguments which is called before jumping to position.
7862 Optional `after-jump-hook' attribute is a function with no
7863 arguments which is called after jumping to position.
7865 If `adjust' attribute is specified, searches the line whose
7866 content is CONTENT near the LINENO.
7868 If `recenter' attribute is specified, the line is displayed at
7869 the center of window, otherwise at the top of window.
7872 (define-anything-type-attribute 'file-line
7873 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
7874 (multiline)
7875 (action ("Go to" . anything-c-action-file-line-goto)))
7876 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
7878 Optional `default-directory' attribute is a default-directory
7879 FILENAME is interpreted.
7881 Optional `before-jump-hook' attribute is a function with no
7882 arguments which is called before jumping to position.
7884 Optional `after-jump-hook' attribute is a function with no
7885 arguments which is called after jumping to position.
7887 If `adjust' attribute is specified, searches the line whose
7888 content is CONTENT near the LINENO.
7890 If `recenter' attribute is specified, the line is displayed at
7891 the center of window, otherwise at the top of window.
7894 (define-anything-type-attribute 'timer
7895 '((real-to-display . anything-c-timer-real-to-display)
7896 (action ("Cancel Timer" . cancel-timer)
7897 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
7898 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
7899 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
7900 (persistent-help . "Describe Function"))
7901 "Timer.")
7903 ;;;; Default `anything-sources'
7904 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
7905 ;; tend to invoke M-x anything directly. So I offer default setting.
7906 (setq anything-sources
7907 '(anything-c-source-buffers+
7908 anything-c-source-recentf
7909 anything-c-source-files-in-current-dir+))
7911 ;;;; unit test
7912 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7913 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
7914 (dont-compile
7915 (when (fboundp 'expectations)
7916 (expectations
7917 (desc "candidates-file plug-in")
7918 (expect '(anything-p-candidats-file-init)
7919 (assoc-default 'init
7920 (car (anything-compile-sources
7921 '(((name . "test")
7922 (candidates-file . "test.txt")))
7923 '(anything-compile-source--candidates-file)))))
7924 (expect '(anything-p-candidats-file-init
7925 (lambda () 1))
7926 (assoc-default 'init
7927 (car (anything-compile-sources
7928 '(((name . "test")
7929 (candidates-file . "test.txt")
7930 (init . (lambda () 1))))
7931 '(anything-compile-source--candidates-file)))))
7932 (expect '(anything-p-candidats-file-init
7933 (lambda () 1))
7934 (assoc-default 'init
7935 (car (anything-compile-sources
7936 '(((name . "test")
7937 (candidates-file . "test.txt")
7938 (init (lambda () 1))))
7939 '(anything-compile-source--candidates-file)))))
7940 ;; FIXME error
7941 ;; (desc "anything-c-source-buffers")
7942 ;; (expect '(("Buffers" ("foo" "curbuf")))
7943 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
7944 ;; (let ((anything-c-boring-buffer-regexp
7945 ;; (rx (or
7946 ;; (group bos " ")
7947 ;; "*anything"
7948 ;; ;; echo area
7949 ;; " *Echo Area" " *Minibuf"))))
7950 ;; (flet ((buffer-name (&optional x) x))
7951 ;; (anything-test-candidates 'anything-c-source-buffers))))
7952 (desc "anything-c-stringify")
7953 (expect "str1"
7954 (anything-c-stringify "str1"))
7955 (expect "str2"
7956 (anything-c-stringify 'str2))
7957 (desc "anything-c-symbolify")
7958 (expect 'sym1
7959 (anything-c-symbolify "sym1"))
7960 (expect 'sym2
7961 (anything-c-symbolify 'sym2))
7962 (desc "plug-in:default-action")
7963 (expect '(((action ("default" . default) ("original" . original))
7964 (default-action . ("default" . default))
7965 (action ("original" . original))))
7966 (anything-compile-sources
7967 '(((default-action . ("default" . default))
7968 (action ("original" . original))))
7969 '(anything-compile-source--default-action)))
7970 (expect '(((action ("a1" . a1) ("a2" . a2))
7971 (default-action . ("a1" . a1))
7972 (action ("a1" . a1) ("a2" . a2))))
7973 (anything-compile-sources
7974 '(((default-action . ("a1" . a1))
7975 (action ("a1" . a1) ("a2" . a2))))
7976 '(anything-compile-source--default-action)))
7977 (expect '(((action ("a2" . a2) ("a1" . a1))
7978 (default-action . ("a2" . a2))
7979 (action ("a1" . a1) ("a2" . a2))))
7980 (anything-compile-sources
7981 '(((default-action . ("a2" . a2))
7982 (action ("a1" . a1) ("a2" . a2))))
7983 '(anything-compile-source--default-action))))))
7985 (provide 'anything-config)
7987 ;;; Local Variables:
7988 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
7989 ;;; End:
7991 ;; How to save (DO NOT REMOVE!!)
7992 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
7993 ;;; anything-config.el ends here
7995 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
7996 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
7997 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
7998 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
7999 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
8000 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
8001 ;;; LocalWords: dotimes Thierry online vname
8002 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
8003 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
8004 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
8005 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
8006 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
8007 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
8008 ;;; LocalWords: startpos noselect dont desc