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