anything-config.el (anything-c-source-info-pages): reformat
[anything-config.git] / anything-config.el
blob369c9204a9229e6aa99aca2188d2887069d57ef9
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 ;; Not documented.
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-show-kill-ring'
95 ;; Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
96 ;; `anything-minibuffer-history'
97 ;; Preconfigured `anything' for `minibuffer-history'.
98 ;; `anything-gentoo'
99 ;; Preconfigured `anything' for gentoo linux.
100 ;; `anything-imenu'
101 ;; Preconfigured `anything' for `imenu'.
102 ;; `anything-google-suggest'
103 ;; Preconfigured `anything' for google search with google suggest.
104 ;; `anything-yahoo-suggest'
105 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
106 ;; `anything-for-buffers'
107 ;; Preconfigured `anything' for buffer.
108 ;; `anything-buffers+'
109 ;; Enhanced preconfigured `anything' for buffer.
110 ;; `anything-bbdb'
111 ;; Preconfigured `anything' for BBDB.
112 ;; `anything-locate'
113 ;; Preconfigured `anything' for Locate.
114 ;; `anything-w3m-bookmarks'
115 ;; Preconfigured `anything' for w3m bookmark.
116 ;; `anything-firefox-bookmarks'
117 ;; Preconfigured `anything' for firefox bookmark.
118 ;; `anything-colors'
119 ;; Preconfigured `anything' for color.
120 ;; `anything-bookmarks'
121 ;; Not documented.
122 ;; `anything-c-pp-bookmarks'
123 ;; Not documented.
124 ;; `anything-register'
125 ;; Not documented.
126 ;; `anything-bm-list'
127 ;; Preconfigured `anything' for visible bookmarks.
128 ;; `anything-timers'
129 ;; Preconfigured `anything' for timers.
130 ;; `anything-kill-buffers'
131 ;; Preconfigured `anything' to kill buffer you selected.
132 ;; `anything-query-replace-regexp'
133 ;; Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually.
134 ;; `anything-regexp'
135 ;; Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement.
136 ;; `anything-insert-buffer-name'
137 ;; Insert buffer name.
138 ;; `anything-insert-symbol'
139 ;; Insert current symbol.
140 ;; `anything-insert-selection'
141 ;; Insert current selection.
142 ;; `anything-show-buffer-only'
143 ;; [OBSOLETE] Only show sources about buffer.
144 ;; `anything-show-bbdb-only'
145 ;; [OBSOLETE] Only show sources about BBDB.
146 ;; `anything-show-locate-only'
147 ;; [OBSOLETE] Only show sources about Locate.
148 ;; `anything-show-info-only'
149 ;; [OBSOLETE] Only show sources about Info.
150 ;; `anything-show-imenu-only'
151 ;; [OBSOLETE] Only show sources about Imenu.
152 ;; `anything-show-files-only'
153 ;; [OBSOLETE] Only show sources about File.
154 ;; `anything-show-w3m-bookmarks-only'
155 ;; [OBSOLETE] Only show source about w3m bookmark.
156 ;; `anything-show-colors-only'
157 ;; [OBSOLETE] Only show source about color.
158 ;; `anything-show-kill-ring-only'
159 ;; [OBSOLETE] Only show source about kill ring.
160 ;; `anything-show-this-source-only'
161 ;; Only show this source.
162 ;; `anything-test-sources'
163 ;; List all anything sources for test.
164 ;; `anything-select-source'
165 ;; Select source.
166 ;; `anything-find-files-down-one-level'
167 ;; Go down one level like unix command `cd ..'.
168 ;; `anything-find-files'
169 ;; Preconfigured `anything' for anything implementation of `find-file'.
170 ;; `anything-write-file'
171 ;; Preconfigured `anything' providing completion for `write-file'.
172 ;; `anything-insert-file'
173 ;; Preconfigured `anything' providing completion for `insert-file'.
174 ;; `anything-dired-rename-file'
175 ;; Preconfigured `anything' to rename files from dired.
176 ;; `anything-dired-copy-file'
177 ;; Preconfigured `anything' to copy files from dired.
178 ;; `anything-dired-symlink-file'
179 ;; Preconfigured `anything' to symlink files from dired.
180 ;; `anything-dired-hardlink-file'
181 ;; Preconfigured `anything' to hardlink files from dired.
182 ;; `anything-dired-bindings'
183 ;; Replace usual dired commands `C' and `R' by anything ones.
184 ;; `anything-M-x'
185 ;; Anything replacement of regular `M-x' `execute-extended-command'.
186 ;; `anything-manage-advice'
187 ;; Preconfigured `anything' to disable/enable function advices.
188 ;; `anything-bookmark-ext'
189 ;; Preconfigured `anything' for bookmark-extensions sources.
190 ;; `anything-simple-call-tree'
191 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
192 ;; `anything-mark-ring'
193 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
194 ;; `anything-global-mark-ring'
195 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
196 ;; `anything-all-mark-rings'
197 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
198 ;; `anything-yaoddmuse-cache-pages'
199 ;; Fetch the list of files on emacswiki and create cache file.
200 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
201 ;; Preconfigured `anything' to edit or view EmacsWiki page.
202 ;; `anything-yaoddmuse-emacswiki-post-library'
203 ;; Preconfigured `anything' to post library to EmacsWiki.
204 ;; `anything-eval-expression'
205 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
206 ;; `anything-eval-expression-with-eldoc'
207 ;; Same as `anything-eval-expression' but with `eldoc' support.
208 ;; `anything-surfraw'
209 ;; Search PATTERN with search ENGINE.
210 ;; `anything-emms-stream-edit-bookmark'
211 ;; Change the information of current emms-stream bookmark from anything.
212 ;; `anything-emms-stream-delete-bookmark'
213 ;; Delete an emms-stream bookmark from anything.
214 ;; `anything-call-source'
215 ;; Preconfigured `anything' to call anything source.
216 ;; `anything-call-source-from-anything'
217 ;; Call anything source within `anything' session.
218 ;; `anything-execute-anything-command'
219 ;; Preconfigured `anything' to execute preconfigured `anything'.
220 ;; `anything-occur'
221 ;; Preconfigured Anything for Occur source.
222 ;; `anything-create-from-anything'
223 ;; Run `anything-create' from `anything' as a fallback.
224 ;; `anything-create'
225 ;; Preconfigured `anything' to do many create actions from STRING.
226 ;; `anything-top'
227 ;; Preconfigured `anything' for top command.
228 ;; `anything-select-xfont'
229 ;; Preconfigured `anything' to select Xfont.
230 ;; `anything-apt'
231 ;; Preconfigured `anything' : frontend of APT package manager.
232 ;; `anything-c-shell-command-if-needed'
233 ;; Not documented.
234 ;; `anything-c-run-external-command'
235 ;; Run External PROGRAM asyncronously from Emacs.
236 ;; `anything-ratpoison-commands'
237 ;; Preconfigured `anything' to execute ratpoison commands.
238 ;; `anything-c-set-variable'
239 ;; Set value to VAR interactively.
240 ;; `anything-c-adaptive-save-history'
241 ;; Save history information to file given by `anything-c-adaptive-history-file'.
243 ;; * User variables defined here:
244 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
245 ;; `anything-c-use-standard-keys'
246 ;; Default Value: nil
247 ;; `anything-c-adaptive-history-file'
248 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
249 ;; `anything-c-adaptive-history-length'
250 ;; Default Value: 50
251 ;; `anything-c-google-suggest-url'
252 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
253 ;; `anything-c-google-suggest-search-url'
254 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
255 ;; `anything-google-suggest-use-curl-p'
256 ;; Default Value: nil
257 ;; `anything-c-yahoo-suggest-url'
258 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
259 ;; `anything-c-yahoo-suggest-search-url'
260 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
261 ;; `anything-c-boring-buffer-regexp'
262 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
263 ;; `anything-c-boring-file-regexp'
264 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
265 ;; `anything-kill-ring-threshold'
266 ;; Default Value: 10
267 ;; `anything-su-or-sudo'
268 ;; Default Value: "su"
269 ;; `anything-for-files-prefered-list'
270 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
271 ;; `anything-create--actions-private'
272 ;; Default Value: nil
273 ;; `anything-allow-skipping-current-buffer'
274 ;; Default Value: t
275 ;; `anything-c-enable-eval-defun-hack'
276 ;; Default Value: t
277 ;; `anything-tramp-verbose'
278 ;; Default Value: 0
279 ;; `anything-raise-command'
280 ;; Default Value: nil
281 ;; `anything-command-map-prefix-key'
282 ;; Default Value: "<f5> a"
284 ;; * Anything sources defined here:
285 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
286 ;; `anything-c-source-buffers' (Buffers)
287 ;; `anything-c-source-buffer-not-found' (Create buffer)
288 ;; `anything-c-source-buffers+' (Buffers)
289 ;; `anything-c-source-file-name-history' (File Name History)
290 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
291 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
292 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
293 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
294 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
295 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
296 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
297 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
298 ;; `anything-c-source-file-cache-initialized' ()
299 ;; `anything-c-source-file-cache' (File Cache)
300 ;; `anything-c-source-locate' (Locate)
301 ;; `anything-c-source-recentf' (Recentf)
302 ;; `anything-c-source-ffap-guesser' (File at point)
303 ;; `anything-c-source-ffap-line' (File/Lineno at point)
304 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
305 ;; `anything-c-source-info-pages' (Info Pages)
306 ;; `anything-c-source-info-elisp' (Info index: elisp)
307 ;; `anything-c-source-info-cl' (Info index: cl)
308 ;; `anything-c-source-info-org' (Info index: org)
309 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
310 ;; `anything-c-source-info-zsh' (Info index: zsh)
311 ;; `anything-c-source-info-bash' (Info index: bash)
312 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
313 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
314 ;; `anything-c-source-info-find' (Info index: find)
315 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
316 ;; `anything-c-source-info-textutils' (Info index: textutils)
317 ;; `anything-c-source-info-libc' (Info index: libc)
318 ;; `anything-c-source-info-make' (Info index: make)
319 ;; `anything-c-source-info-automake' (Info index: automake)
320 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
321 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
322 ;; `anything-c-source-info-emacs' (Info index: emacs)
323 ;; `anything-c-source-info-elib' (Info index: elib)
324 ;; `anything-c-source-info-eieio' (Info index: eieio)
325 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
326 ;; `anything-c-source-info-guile' (Info index: guile)
327 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
328 ;; `anything-c-source-info-goops' (Info index: goops)
329 ;; `anything-c-source-info-screen' (Info index: screen)
330 ;; `anything-c-source-info-latex' (Info index: latex)
331 ;; `anything-c-source-info-gawk' (Info index: gawk)
332 ;; `anything-c-source-info-sed' (Info index: sed)
333 ;; `anything-c-source-info-m4' (Info index: m4)
334 ;; `anything-c-source-info-wget' (Info index: wget)
335 ;; `anything-c-source-info-binutils' (Info index: binutils)
336 ;; `anything-c-source-info-as' (Info index: as)
337 ;; `anything-c-source-info-bfd' (Info index: bfd)
338 ;; `anything-c-source-info-gprof' (Info index: gprof)
339 ;; `anything-c-source-info-ld' (Info index: ld)
340 ;; `anything-c-source-info-diff' (Info index: diff)
341 ;; `anything-c-source-info-flex' (Info index: flex)
342 ;; `anything-c-source-info-grep' (Info index: grep)
343 ;; `anything-c-source-info-gzip' (Info index: gzip)
344 ;; `anything-c-source-info-libtool' (Info index: libtool)
345 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
346 ;; `anything-c-source-info-info' (Info index: info)
347 ;; `anything-c-source-info-gdb' (Info index: gdb)
348 ;; `anything-c-source-info-stabs' (Info index: stabs)
349 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
350 ;; `anything-c-source-info-cvs' (Info index: cvs)
351 ;; `anything-c-source-info-bison' (Info index: bison)
352 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
353 ;; `anything-c-source-info-global' (Info index: global)
354 ;; `anything-c-source-man-pages' (Manual Pages)
355 ;; `anything-c-source-complex-command-history' (Complex Command History)
356 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
357 ;; `anything-c-source-emacs-commands' (Emacs Commands)
358 ;; `anything-c-source-lacarte' (Lacarte)
359 ;; `anything-c-source-emacs-functions' (Emacs Functions)
360 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
361 ;; `anything-c-source-advice' (Function Advice)
362 ;; `anything-c-source-emacs-variables' (Emacs Variables)
363 ;; `anything-c-source-bookmarks' (Bookmarks)
364 ;; `anything-c-source-bookmark-set' (Set Bookmark)
365 ;; `anything-c-source-bm' (Visible Bookmarks)
366 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
367 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
368 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
369 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
370 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
371 ;; `anything-c-source-bookmark-images' (Bookmark Images)
372 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
373 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
374 ;; `anything-c-source-bookmark-info' (Bookmark Info)
375 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
376 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
377 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
378 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
379 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
380 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
381 ;; `anything-c-source-imenu' (Imenu)
382 ;; `anything-c-source-ctags' (Exuberant ctags)
383 ;; `anything-c-source-semantic' (Semantic Tags)
384 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
385 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
386 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
387 ;; `anything-c-source-customize-face' (Customize Face)
388 ;; `anything-c-source-colors' (Colors)
389 ;; `anything-c-source-tracker-search' (Tracker Search)
390 ;; `anything-c-source-mac-spotlight' (mdfind)
391 ;; `anything-c-source-kill-ring' (Kill Ring)
392 ;; `anything-c-source-mark-ring' (mark-ring)
393 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
394 ;; `anything-c-source-register' (Registers)
395 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
396 ;; `anything-c-source-rd-headline' (RD HeadLine)
397 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
398 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
399 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
400 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
401 ;; `anything-c-source-org-headline' (Org HeadLine)
402 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
403 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
404 ;; `anything-c-source-eev-anchor' (Anchors)
405 ;; `anything-c-source-org-keywords' (Org Keywords)
406 ;; `anything-c-source-picklist' (Picklist)
407 ;; `anything-c-source-bbdb' (BBDB)
408 ;; `anything-c-source-evaluation-result' (Evaluation Result)
409 ;; `anything-c-source-calculation-result' (Calculation Result)
410 ;; `anything-c-source-google-suggest' (Google Suggest)
411 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
412 ;; `anything-c-source-emms-streams' (Emms Streams)
413 ;; `anything-c-source-emms-dired' (Music Directory)
414 ;; `anything-c-source-emms-files' (Emms files)
415 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
416 ;; `anything-c-source-call-source' (Call anything source)
417 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
418 ;; `anything-c-source-occur' (Occur)
419 ;; `anything-c-source-create' (Create)
420 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
421 ;; `anything-c-source-elscreen' (Elscreen)
422 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
423 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
424 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
425 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
426 ;; `anything-c-source-xfonts' (X Fonts)
427 ;; `anything-c-source-apt' (APT)
428 ;; `anything-c-source-gentoo' (Portage sources)
429 ;; `anything-c-source-use-flags' (Use Flags)
430 ;; `anything-c-source-emacs-process' (Emacs Process)
431 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
433 ;; *** END auto-documentation
436 ;;; Change log:
438 ;; Change log of this file is found at
439 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
441 ;; Change log of this project is found at
442 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
444 ;;; Contributors:
446 ;; Tamas Patrovics
447 ;; Tassilo Horn <tassilo@member.fsf.org>
448 ;; Vagn Johansen <gonz808@hotmail.com>
449 ;; Mathias Dahl <mathias.dahl@gmail.com>
450 ;; Bill Clementson <billclem@gmail.com>
451 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
452 ;; Drew Adams <drew.adams@oracle.com>
453 ;; Jason McBrayer <jmcbray@carcosa.net>
454 ;; Andy Stewart <lazycat.manatee@gmail.com>
455 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
456 ;; rubikitch <rubikitch@ruby-lang.org>
457 ;; Scott Vokes <vokes.s@gmail.com>
460 ;;; For Maintainers:
462 ;; Evaluate (autodoc-update-all) before commit. This function
463 ;; generates anything-c-source-* / functions / options list.
465 ;; Install also developer-tools/autodoc.el
466 ;; And eval it or run interactively.
468 ;; [EVAL IT] (autodoc-update-all)
470 ;; Please write details documentation about function, then others will
471 ;; read code more easier. -- Andy Stewart
475 ;;; TODO
477 ;; - Fix documentation, now many functions haven't documentations.
480 ;;; Require
481 (require 'anything)
482 (require 'thingatpt)
483 (require 'ffap)
484 (require 'cl)
486 ;;; Code:
488 ;; version check
489 (let ((version "1.263"))
490 (when (and (string= "1." (substring version 0 2))
491 (string-match "1\.\\([0-9]+\\)" anything-version)
492 (< (string-to-number (match-string 1 anything-version))
493 (string-to-number (substring version 2))))
494 (error "Please update anything.el!!
496 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
498 or M-x install-elisp-from-emacswiki anything.el")))
500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
501 (defgroup anything-config nil
502 "Predefined configurations for `anything.el'."
503 :group 'anything)
505 (defcustom anything-c-use-standard-keys nil
506 "Whether use standard keybindings. (no effect)
508 Key definitions in anything-config.el are removed because
509 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
510 minibuffer history, C-s for isearch, etc.
512 If you use `iswitchb' with `anything',
513 evaluate (anything-iswitchb-setup) . Then some bindings that
514 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
515 history, are removed from `anything-map'. "
516 :type 'boolean
517 :group 'anything-config)
519 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
520 "Path of file where history information is stored."
521 :type 'string
522 :group 'anything-config)
524 (defcustom anything-c-adaptive-history-length 50
525 "Maximum number of candidates stored for a source."
526 :type 'number
527 :group 'anything-config)
529 (defcustom anything-c-google-suggest-url
530 "http://google.com/complete/search?output=toolbar&q="
531 "URL used for looking up Google suggestions."
532 :type 'string
533 :group 'anything-config)
535 (defcustom anything-c-google-suggest-search-url
536 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
537 "URL used for Google searching."
538 :type 'string
539 :group 'anything-config)
541 (defcustom anything-google-suggest-use-curl-p nil
542 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
543 Otherwise `url-retrieve-synchronously' is used."
544 :type 'boolean
545 :group 'anything-config)
547 (defcustom anything-c-yahoo-suggest-url
548 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
549 "Url used for looking up Yahoo suggestions."
550 :type 'string
551 :group 'anything-config)
553 (defcustom anything-c-yahoo-suggest-search-url
554 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
555 "Url used for Yahoo searching."
556 :type 'string
557 :group 'anything-config)
559 (defcustom anything-c-boring-buffer-regexp
560 (rx (or
561 (group bos " ")
562 ;; anything-buffer
563 "*anything"
564 ;; echo area
565 " *Echo Area" " *Minibuf"))
566 "The regexp that match boring buffers.
567 Buffer candidates matching this regular expression will be
568 filtered from the list of candidates if the
569 `anything-c-skip-boring-buffers' candidate transformer is used, or
570 they will be displayed with face `file-name-shadow' if
571 `anything-c-shadow-boring-buffers' is used."
572 :type 'string
573 :group 'anything-config)
574 ;; (string-match anything-c-boring-buffer-regexp "buf")
575 ;; (string-match anything-c-boring-buffer-regexp " hidden")
576 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
578 (defcustom anything-c-boring-file-regexp
579 (rx (or
580 ;; Boring directories
581 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
582 ;; Boring files
583 (and line-start ".#")
584 (and (or ".class" ".la" ".o" "~") eol)))
585 "The regexp that match boring files.
586 File candidates matching this regular expression will be
587 filtered from the list of candidates if the
588 `anything-c-skip-boring-files' candidate transformer is used, or
589 they will be displayed with face `file-name-shadow' if
590 `anything-c-shadow-boring-files' is used."
591 :type 'string
592 :group 'anything-config)
594 (defcustom anything-kill-ring-threshold 10
595 "*Minimum length to be listed by `anything-c-source-kill-ring'."
596 :type 'integer
597 :group 'anything-config)
599 (defcustom anything-su-or-sudo "su"
600 "What command to use for root access."
601 :type 'string
602 :group 'anything-config)
604 (defcustom anything-for-files-prefered-list
605 '(anything-c-source-ffap-line
606 anything-c-source-ffap-guesser
607 anything-c-source-buffers+
608 anything-c-source-recentf
609 anything-c-source-bookmarks
610 anything-c-source-file-cache
611 anything-c-source-files-in-current-dir+
612 anything-c-source-locate)
613 "Your prefered sources to find files."
614 :type 'list
615 :group 'anything-config)
617 (defcustom anything-create--actions-private nil
618 "User defined actions for `anything-create' / `anything-c-source-create'.
619 It is a list of (DISPLAY . FUNCTION) pairs like `action'
620 attribute of `anything-sources'.
622 It is prepended to predefined pairs."
623 :type 'list
624 :group 'anything-config)
626 (defcustom anything-allow-skipping-current-buffer t
627 "Show current buffer or not in anything buffer"
628 :type 'boolean
629 :group 'anything-config)
631 (defcustom anything-c-enable-eval-defun-hack t
632 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
633 This hack is invoked when pressing C-M-x in the form \
634 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
635 :type 'boolean
636 :group 'anything-config)
638 (defcustom anything-tramp-verbose 0
639 "*Just like `tramp-verbose' but specific to anything.
640 When set to 0 don't show tramp messages in anything.
641 If you want to have the default tramp messages set it to 3."
642 :type 'integer
643 :group 'anything-config)
645 (defcustom anything-raise-command nil
646 "*A shell command to jump to a window running specific program.
647 Stumpwm users could use:
648 \"stumpish eval \"\(stumpwm::%s\)\"\".
649 With others windows manager you could use:
650 \"wmctrl -xa %s\".
651 Though wmctrl work also with stumpwm."
652 :type 'string
653 :group 'anything-config)
655 (defun anything-set-anything-command-map-prefix-key (var key)
656 (when (boundp 'anything-command-map-prefix-key)
657 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
658 (setq anything-command-map-prefix-key key)
659 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
660 'anything-command-map))
662 (defcustom anything-command-map-prefix-key "<f5> a"
663 "*The prefix key for all `anything-command-map' commands.
665 !!WARNING!!
666 This default value is very likely to be changed,
667 because it is under discussion."
668 :type 'string
669 :set 'anything-set-anything-command-map-prefix-key
670 :group 'anything-config)
672 ;;;###autoload
673 (defun anything-configuration ()
674 "Customize `anything'."
675 (interactive)
676 (customize-group "anything-config"))
678 ;;; Anything-command-map
679 ;;;###autoload
680 (defvar anything-command-map)
681 (define-prefix-command 'anything-command-map)
683 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
684 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
685 (define-key anything-command-map (kbd "e") 'anything-etags-maybe-at-point)
686 (define-key anything-command-map (kbd "l") 'anything-locate)
687 (define-key anything-command-map (kbd "s") 'anything-surfraw)
688 (define-key anything-command-map (kbd "r") 'anything-regexp)
689 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
690 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
691 (define-key anything-command-map (kbd "#") 'anything-emms)
692 (define-key anything-command-map (kbd "m") 'anything-man-woman)
693 (define-key anything-command-map (kbd "t") 'anything-top)
694 (define-key anything-command-map (kbd "i") 'anything-imenu)
695 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
696 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
697 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
698 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
699 (define-key anything-command-map (kbd "f") 'anything-for-files)
700 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
701 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
702 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
703 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
704 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
705 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
706 (define-key anything-command-map (kbd "c") 'anything-colors)
707 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
708 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
709 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
710 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
711 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers+)
712 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
713 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
715 ;;; Menu
716 (easy-menu-define nil global-map
717 "`anything' menu"
718 '("Anything"
719 ["All anything commands" anything-execute-anything-command t]
720 ["Find any Files/Buffers" anything-for-files t]
721 "----"
722 ("Files:"
723 ["Find files" anything-find-files t]
724 ["Recent Files" anything-recentf t]
725 ["Locate" anything-locate t]
726 ["Bookmarks" anything-c-pp-bookmarks t])
727 ("Buffers:"
728 ["Find buffers" anything-buffers+ t])
729 ("Commands:"
730 ["Emacs Commands" anything-M-x t]
731 ["Externals Commands" anything-c-run-external-command t])
732 ("Info:"
733 ["Info at point" anything-info-at-point t])
734 ("Tools:"
735 ["Occur" anything-occur t]
736 ["Browse Kill ring" anything-show-kill-ring t]
737 ["Browse register" anything-register t]
738 ["Mark Ring" anything-all-mark-rings t]
739 ["Colors & Faces" anything-colors t]
740 ["Show xfonts" anything-select-xfont t]
741 ["Imenu" anything-imenu t]
742 ["Google Suggest" anything-google-suggest t]
743 ["Eval expression" anything-eval-expression-with-eldoc t]
744 ["Calcul expression" anything-calcul-expression t]
745 ["Man pages" anything-man-woman t]
746 ["Top externals process" anything-top t])
747 "----"
748 ["Prefered Options" anything-configuration t]))
750 ;;; Documentation
751 ;; It is replaced by `anything-help'
752 (defun anything-c-describe-anything-bindings ()
753 "[OBSOLETE] Describe `anything' bindings."
754 (interactive)
755 (anything-run-after-quit
756 #'(lambda ()
757 (with-current-buffer (get-buffer-create "*Anything Help*")
758 (erase-buffer)
759 (insert
760 (substitute-command-keys
761 "The keys that are defined for `anything' are:
762 \\{anything-map}")))
763 (pop-to-buffer "*Anything Help*")
764 (goto-char (point-min)))))
766 ;; Use `describe-mode' key in `global-map'
767 ;; (dolist (k (where-is-internal 'describe-mode global-map))
768 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
770 ;;; Help message
771 (defun anything-c-list-preconfigured-anything ()
772 (loop with doc
773 with sym
774 for entry in (cdr (assoc
775 (file-truename (locate-library "anything-config"))
776 load-history))
777 if (and (consp entry)
778 (eq (car entry) 'defun)
779 (string-match "^Preconfigured.+$"
780 (setq doc (or (documentation (setq sym (cdr entry)))
781 ""))))
782 collect (cons sym (match-string 0 doc))))
784 (defun anything-c-format-preconfigured-anything ()
785 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
786 (anything-c-list-preconfigured-anything)))
788 (setq anything-help-message
789 (lambda ()
790 (concat
791 "\\<anything-map>"
792 "`anything' is QuickSilver-like candidate-selection framework.
794 Narrow the list by typing some pattern,
795 Multiple patterns are allowed by splitting by space.
796 Select with natural Emacs operations, choose with RET.
798 If you have any problems, press C-c C-x C-b!!
799 Feel free to send bug reports. I'll fix them.
800 The steps are described in the beginning of anything.el file.
802 == Basic Operations ==
803 C-p, Up: Previous Line
804 C-n, Down : Next Line
805 M-v, PageUp : Previous Page
806 C-v, PageDown : Next Page
807 Enter : Execute first (default) action / Select
808 M-< : First Line
809 M-> : Last Line
810 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
811 M-PageDown, C-M-v : Next Page (other-window)
813 Tab, C-i : Show action list
814 Left : Previous Source
815 Right, C-o : Next Source
816 C-k : Delete pattern
817 C-z : Persistent Action (Execute action with anything session kept)
818 C-c C-x C-b: Send a bug report
820 == Shortcuts For 2nd/3rd Action ==
821 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
822 \\[anything-select-3rd-action] : Execute 3rd Action
824 == Visible Marks ==
825 Visible marks store candidate. Some actions uses marked candidates.
827 \\[anything-toggle-visible-mark] : Toggle Visible Mark
828 \\[anything-prev-visible-mark] : Previous Mark
829 \\[anything-next-visible-mark] : Next Mark
831 == Miscellaneous Commands ==
832 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
833 \\[anything-quit-and-find-file] : Drop into `find-file'
834 \\[anything-delete-current-selection] : Delete Selected Item (visually)
835 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
836 \\[anything-yank-selection] : Yank Selected Item Into Pattern
837 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
838 \\[anything-force-update] : Recalculate And Redisplay Candidates
840 == Global Commands ==
841 \\<global-map>\\[anything-resume] revives last `anything' session.
842 It is very useful, so you should bind any key.
844 Single source is executed by \\[anything-call-source].
846 == Preconfigured `anything' ==
847 Preconfigured `anything' is commands that uses `anything' interface.
848 You can use them without configuration.
851 (apply 'concat (anything-c-format-preconfigured-anything))
853 Enjoy!")))
855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
856 ;;;###autoload
857 (defun anything-mini ()
858 "Preconfigured `anything' lightweight version (buffer -> recentf)."
859 (interactive)
860 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf)
861 "*anything mini*"))
862 ;;;###autoload
863 (defun anything-for-files ()
864 "Preconfigured `anything' for opening files.
865 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
866 (interactive)
867 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
869 ;;;###autoload
870 (defun anything-recentf ()
871 "Preconfigured `anything' for `recentf'."
872 (interactive)
873 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
874 ;;;###autoload
875 (defun anything-info-at-point ()
876 "Preconfigured `anything' for searching info at point."
877 (interactive)
878 (anything '(anything-c-source-info-elisp
879 anything-c-source-info-cl
880 anything-c-source-info-pages)
881 (thing-at-point 'symbol) nil nil nil "*anything info*"))
883 ;;;###autoload
884 (defun anything-show-kill-ring ()
885 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
886 You may bind this command to M-y."
887 (interactive)
888 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
890 ;;;###autoload
891 (defun anything-minibuffer-history ()
892 "Preconfigured `anything' for `minibuffer-history'."
893 (interactive)
894 (let ((enable-recursive-minibuffers t))
895 (anything-other-buffer 'anything-c-source-minibuffer-history
896 "*anything minibuffer-history*")))
898 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
899 ;; minibuffer-local-filename-must-match-map.
900 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
901 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
902 (dolist (map (list minibuffer-local-filename-completion-map
903 minibuffer-local-completion-map
904 minibuffer-local-must-match-filename-map
905 minibuffer-local-filename-must-match-map
906 minibuffer-local-map
907 minibuffer-local-isearch-map
908 minibuffer-local-must-match-map
909 minibuffer-local-ns-map))
910 (define-key map "\C-r" 'anything-minibuffer-history))
912 ;;;###autoload
913 (defun anything-gentoo ()
914 "Preconfigured `anything' for gentoo linux."
915 (interactive)
916 (anything-other-buffer '(anything-c-source-gentoo
917 anything-c-source-use-flags)
918 "*anything gentoo*"))
920 ;;;###autoload
921 (defun anything-imenu ()
922 "Preconfigured `anything' for `imenu'."
923 (interactive)
924 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
926 ;;;###autoload
927 (defun anything-google-suggest ()
928 "Preconfigured `anything' for google search with google suggest."
929 (interactive)
930 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
932 ;;;###autoload
933 (defun anything-yahoo-suggest ()
934 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
935 (interactive)
936 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
938 ;;; Converted from anything-show-*-only
939 ;;;###autoload
940 (defun anything-for-buffers ()
941 "Preconfigured `anything' for buffer."
942 (interactive)
943 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
945 ;;;###autoload
946 (defun anything-buffers+ ()
947 "Enhanced preconfigured `anything' for buffer."
948 (interactive)
949 (anything-other-buffer 'anything-c-source-buffers+ "*anything buffers*"))
951 ;;;###autoload
952 (defun anything-bbdb ()
953 "Preconfigured `anything' for BBDB.
955 Needs BBDB.
957 http://bbdb.sourceforge.net/"
958 (interactive)
959 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
961 ;;;###autoload
962 (defun anything-locate ()
963 "Preconfigured `anything' for Locate.
964 Note you can add locate command after entering pattern.
965 See man locate for more infos."
966 (interactive)
967 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
969 ;;;###autoload
970 (defun anything-w3m-bookmarks ()
971 "Preconfigured `anything' for w3m bookmark.
973 Needs w3m and emacs-w3m.
975 http://w3m.sourceforge.net/
976 http://emacs-w3m.namazu.org/"
977 (interactive)
978 (anything-other-buffer 'anything-c-source-w3m-bookmarks
979 "*anything w3m bookmarks*"))
981 ;;;###autoload
982 (defun anything-firefox-bookmarks ()
983 "Preconfigured `anything' for firefox bookmark.
984 You will have to enable html bookmarks in firefox:
985 open about:config in firefox and double click on this line to enable value \
986 to true:
988 user_pref(\"browser.bookmarks.autoExportHTML\", false);
990 You should have now:
992 user_pref(\"browser.bookmarks.autoExportHTML\", true);
994 After closing firefox, you will be able to browse you bookmarks.
996 (interactive)
997 (anything-other-buffer 'anything-c-source-firefox-bookmarks
998 "*Anything Firefox*"))
1000 ;;;###autoload
1001 (defun anything-colors ()
1002 "Preconfigured `anything' for color."
1003 (interactive)
1004 (anything-other-buffer
1005 '(anything-c-source-colors anything-c-source-customize-face)
1006 "*anything colors*"))
1008 ;;;###autoload
1009 (defun anything-bookmarks ()
1010 "Preconfigured `anything' for bookmarks."
1011 (interactive)
1012 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
1014 ;;;###autoload
1015 (defun anything-c-pp-bookmarks ()
1016 "Preconfigured `anything' for bookmarks (pretty-printed)."
1017 (interactive)
1018 (anything-other-buffer '(anything-c-source-bookmarks-local
1019 anything-c-source-bookmarks-su
1020 anything-c-source-bookmarks-ssh)
1021 "*anything pp bookmarks*"))
1023 ;;;###autoload
1024 (defun anything-register ()
1025 "Preconfigured `anything' for Emacs registers."
1026 (interactive)
1027 (anything-other-buffer 'anything-c-source-register "*anything register*"))
1029 ;;;###autoload
1030 (defun anything-bm-list ()
1031 "Preconfigured `anything' for visible bookmarks.
1033 Needs bm.el
1035 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1036 (interactive)
1037 (let ((anything-outline-using t))
1038 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
1040 ;;;###autoload
1041 (defun anything-timers ()
1042 "Preconfigured `anything' for timers."
1043 (interactive)
1044 (anything-other-buffer '(anything-c-source-absolute-time-timers
1045 anything-c-source-idle-time-timers)
1046 "*anything timers*"))
1048 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1049 ;;; kill buffers
1050 ;;;###autoload
1051 (defun anything-kill-buffers ()
1052 "Preconfigured `anything' to kill buffer you selected."
1053 (interactive)
1054 (anything
1055 '(((name . "Kill Buffers")
1056 (candidates . anything-c-buffer-list)
1057 (action
1058 ("Kill Buffer" . (lambda (candidate)
1059 (kill-buffer candidate)
1060 (anything-kill-buffers)
1061 )))))
1062 nil nil))
1064 ;;; Regexp
1065 ;;;###autoload
1066 (defun anything-query-replace-regexp (&rest args)
1067 "Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually."
1068 (interactive
1069 (let ((common
1070 (anything-c-regexp-base
1071 "Query Replace Regexp: "
1072 '((name . "Lines matching Regexp")
1073 (mode-line . "Set replace start line and type RET.")
1074 (action . anything-c-query-replace-args)))))
1075 (if (not common)
1076 (keyboard-quit))
1077 (list (car common) (cadr common) (caddr common)
1078 ;; These are done separately here
1079 ;; so that command-history will record these expressions
1080 ;; rather than the values they had this time.
1082 ;; This idea is borrowed from original `query-replace-regexp'.
1083 (if (and transient-mark-mode mark-active)
1084 (region-beginning))
1085 (if (and transient-mark-mode mark-active)
1086 (region-end)))))
1087 (apply 'query-replace-regexp args))
1089 ;;;###autoload
1090 (defun anything-regexp ()
1091 "Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement."
1092 (interactive)
1093 (anything-c-regexp-base
1094 "Regexp: "
1095 '((name . "Regexp Builder")
1096 (mode-line . "Press TAB to select action.")
1097 (action
1098 ("Kill Regexp as sexp" .
1099 (lambda (x) (anything-c-regexp-kill-new
1100 (prin1-to-string (funcall (anything-attr 'regexp))))))
1101 ("Query Replace Regexp" .
1102 (lambda (x) (apply 'query-replace-regexp
1103 (anything-c-query-replace-args (point)))))
1104 ("Kill Regexp" .
1105 (lambda (x) (anything-c-regexp-kill-new
1106 (funcall (anything-attr 'regexp)))))))))
1108 (defun anything-c-query-replace-args (start-point)
1109 ;; create arguments of `query-replace-regexp'.
1110 (let ((region-only (and transient-mark-mode mark-active))
1111 (regexp (funcall (anything-attr 'regexp))))
1112 (list
1113 regexp
1114 (query-replace-read-to regexp
1115 (format "Query replace regexp %s%s%s with: "
1116 (if region-only "in region " "")
1117 regexp
1118 (if current-prefix-arg "(word) " ""))
1120 current-prefix-arg)))
1122 (defun anything-c-regexp-get-line (s e)
1123 (propertize
1124 (apply 'concat
1125 ;; Line contents
1126 (format "%5d: %s" (line-number-at-pos s) (buffer-substring s e))
1127 ;; subexps
1128 (loop for i from 0 to (1- (/ (length (match-data)) 2))
1129 collect (format "\n \\%s = %s"
1130 (if (zerop i) "&" i)
1131 (match-string i))))
1132 ;; match beginning
1133 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1134 ;; It is implementation problem of candidates-in-buffer.
1135 'anything-realvalue
1136 (1- s)))
1138 ;; Shut up byte compiler
1139 (defun anything-goto-line (numline)
1140 "Replacement of `goto-line'."
1141 (goto-char (point-min))
1142 (forward-line (1- numline)))
1144 (defun anything-c-regexp-persistent-action (pt)
1145 (goto-char pt)
1146 (anything-persistent-highlight-point))
1148 (defun anything-c-regexp-base (prompt attributes)
1149 (save-restriction
1150 (let ((anything-compile-source-functions
1151 ;; rule out anything-match-plugin because the input is one regexp.
1152 (delq 'anything-compile-source--match-plugin
1153 (copy-sequence anything-compile-source-functions)))
1154 (base-attributes
1155 '((init . (lambda () (anything-candidate-buffer anything-current-buffer)))
1156 (candidates-in-buffer)
1157 (get-line . anything-c-regexp-get-line)
1158 (persistent-action . anything-c-regexp-persistent-action)
1159 (persistent-help . "Show this line")
1160 (multiline)
1161 (delayed))))
1162 (if (and transient-mark-mode mark-active)
1163 (narrow-to-region (region-beginning) (region-end)))
1164 (anything
1165 (list
1166 (append
1167 attributes
1168 '((regexp . (lambda () anything-pattern)))
1169 base-attributes)
1170 ;; sexp form regexp
1171 (append
1172 `((name . ,(concat (assoc-default 'name attributes) " (sexp)")))
1173 attributes
1174 '((candidates-in-buffer
1175 . (lambda () (let ((anything-pattern (eval (read anything-pattern))))
1176 (anything-candidates-in-buffer))))
1177 (regexp . (lambda () (eval (read anything-pattern)))))
1178 base-attributes))
1179 nil prompt nil nil "*anything regexp*"))))
1181 ;; (anything-c-regexp-base "Regexp: " '((name . "test")))
1182 ;; (anything-c-regexp-base "Regexp: " '((name . "test") (candidates-in-buffer . (lambda () (let ((anything-pattern (eval (read anything-pattern)))) (anything-candidates-in-buffer))))))
1184 (defun anything-c-regexp-kill-new (input)
1185 (kill-new input)
1186 (message "Killed: %s" input))
1188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1190 (defun anything-insert-buffer-name ()
1191 "Insert buffer name."
1192 (interactive)
1193 (anything-insert-string
1194 (with-current-buffer anything-current-buffer
1195 (if buffer-file-name (file-name-nondirectory buffer-file-name)
1196 (buffer-name)))))
1198 (defun anything-insert-symbol ()
1199 "Insert current symbol."
1200 (interactive)
1201 (anything-insert-string
1202 (with-current-buffer anything-current-buffer
1203 (save-excursion
1204 (buffer-substring (beginning-of-thing 'symbol)
1205 (end-of-thing 'symbol))))))
1207 (defun anything-insert-selection ()
1208 "Insert current selection."
1209 (interactive)
1210 (anything-insert-string
1211 (with-current-buffer anything-current-buffer
1212 (anything-get-selection))))
1214 (defun anything-show-buffer-only ()
1215 "[OBSOLETE] Only show sources about buffer.
1216 Use `anything-for-buffers' instead."
1217 (interactive)
1218 (anything-set-source-filter '("Buffers")))
1220 (defun anything-show-bbdb-only ()
1221 "[OBSOLETE] Only show sources about BBDB.
1222 Use `anything-bbdb' instead."
1223 (interactive)
1224 (anything-set-source-filter '("BBDB")))
1226 (defun anything-show-locate-only ()
1227 "[OBSOLETE] Only show sources about Locate.
1228 Use `anything-locate' instead."
1229 (interactive)
1230 (anything-set-source-filter '("Locate")))
1232 (defun anything-show-info-only ()
1233 "[OBSOLETE] Only show sources about Info.
1234 Use `anything-info-at-point' instead."
1235 (interactive)
1236 (anything-set-source-filter '("Info Pages"
1237 "Info Elisp"
1238 "Info Common-Lisp")))
1240 (defun anything-show-imenu-only ()
1241 "[OBSOLETE] Only show sources about Imenu.
1242 Use `anything-imenu' instead."
1243 (interactive)
1244 (anything-set-source-filter '("Imenu")))
1246 (defun anything-show-files-only ()
1247 "[OBSOLETE] Only show sources about File.
1248 Use `anything-for-files' instead."
1249 (interactive)
1250 (anything-set-source-filter '("File Name History"
1251 "Files from Current Directory"
1252 "Recentf")))
1254 (defun anything-show-w3m-bookmarks-only ()
1255 "[OBSOLETE] Only show source about w3m bookmark.
1256 Use `anything-w3m-bookmarks' instead."
1257 (interactive)
1258 (anything-set-source-filter '("W3m Bookmarks")))
1260 (defun anything-show-colors-only ()
1261 "[OBSOLETE] Only show source about color.
1262 Use `anything-colors' instead."
1263 (interactive)
1264 (anything-set-source-filter '("Colors"
1265 "Customize Faces")))
1267 (defun anything-show-kill-ring-only ()
1268 "[OBSOLETE] Only show source about kill ring.
1269 Use `anything-show-kill-ring' instead."
1270 (interactive)
1271 (anything-set-source-filter '("Kill Ring")))
1273 (defun anything-show-this-source-only ()
1274 "Only show this source."
1275 (interactive)
1276 (setq anything-candidate-number-limit 9999)
1277 (anything-set-source-filter
1278 (list (assoc-default 'name (anything-get-current-source)))))
1280 (defun anything-test-sources ()
1281 "List all anything sources for test.
1282 The output is sexps which are evaluated by \\[eval-last-sexp]."
1283 (interactive)
1284 (with-output-to-temp-buffer "*Anything Test Sources*"
1285 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
1286 (apropos-internal "^anything-c-source" #'boundp))
1287 (pop-to-buffer standard-output)))
1289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1290 ;;; For compatibility
1291 (unless (fboundp 'region-active-p)
1292 (defun region-active-p ()
1293 "Return t if Transient Mark mode is enabled and the mark is active.
1295 Most commands that act on the region if it is active and
1296 Transient Mark mode is enabled, and on the text near point
1297 otherwise, should use `use-region-p' instead. That function
1298 checks the value of `use-empty-active-region' as well."
1299 (and transient-mark-mode mark-active)))
1301 (defun anything-nest (&rest same-as-anything)
1302 "Nested `anything'. If you use `anything' within `anything', use it."
1303 (with-selected-window (anything-window)
1304 (let (anything-current-position
1305 anything-current-buffer
1306 (orig-anything-buffer anything-buffer)
1307 anything-pattern
1308 anything-buffer
1309 anything-sources
1310 anything-compiled-sources
1311 anything-buffer-chars-modified-tick
1312 (anything-samewindow t)
1313 (enable-recursive-minibuffers t))
1314 (unwind-protect
1315 (apply #'anything same-as-anything)
1316 (anything-initialize-overlays orig-anything-buffer)
1317 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
1319 (defun anything-displaying-source-names ()
1320 "Display sources name."
1321 (with-current-buffer anything-buffer
1322 (goto-char (point-min))
1323 (loop with pos
1324 while (setq pos (next-single-property-change (point) 'anything-header))
1325 do (goto-char pos)
1326 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1327 do (forward-line 1))))
1329 (defun anything-select-source ()
1330 "Select source."
1331 (interactive)
1332 (let ((default (assoc-default 'name (anything-get-current-source)))
1333 (source-names (anything-displaying-source-names))
1334 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
1335 (anything-get-sources))))
1336 (setq anything-candidate-number-limit 9999)
1337 (anything-aif
1338 (let (anything-source-filter)
1339 (anything-nest '(((name . "Anything Source")
1340 (candidates . source-names)
1341 (action . identity))
1342 ((name . "Anything Source (ALL)")
1343 (candidates . all-source-names)
1344 (action . identity)))
1345 nil "Source: " nil
1346 default "*anything select source*"))
1347 (anything-set-source-filter (list it))
1348 (anything-set-source-filter nil))))
1350 (defun anything-insert-string (str)
1351 "Insert STR."
1352 (delete-minibuffer-contents)
1353 (insert str))
1355 (defun anything-c-match-on-file-name (candidate)
1356 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1357 (string-match anything-pattern (file-name-nondirectory candidate)))
1359 (defun anything-c-match-on-directory-name (candidate)
1360 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1361 (anything-aif (file-name-directory candidate)
1362 (string-match anything-pattern it)))
1364 (defun anything-c-string-match (candidate)
1365 "Return non-nil if `anything-pattern' match CANDIDATE.
1366 The match is done with `string-match'."
1367 (string-match anything-pattern candidate))
1369 ;; `anything-c-compose' is no more needed, it is for compatibility.
1370 (defalias 'anything-c-compose 'anything-compose)
1372 (defun anything-c-skip-entries (list regexp)
1373 "Remove entries which matches REGEXP from LIST."
1374 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
1375 list))
1377 (defun anything-c-shadow-entries (list regexp)
1378 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1379 (mapcar (lambda (file)
1380 ;; Add shadow face property to boring files.
1381 (let ((face (if (facep 'file-name-shadow)
1382 'file-name-shadow
1383 ;; fall back to default on XEmacs
1384 'default)))
1385 (if (string-match regexp file)
1386 (setq file (propertize file 'face face))))
1387 file)
1388 list))
1390 (defsubst anything-c-stringify (str-or-sym)
1391 "Get string of STR-OR-SYM."
1392 (if (stringp str-or-sym)
1393 str-or-sym
1394 (symbol-name str-or-sym)))
1396 (defsubst anything-c-symbolify (str-or-sym)
1397 "Get symbol of STR-OR-SYM."
1398 (if (symbolp str-or-sym)
1399 str-or-sym
1400 (intern str-or-sym)))
1402 (defun anything-c-describe-function (func)
1403 "FUNC is symbol or string."
1404 (describe-function (anything-c-symbolify func)))
1406 (defun anything-c-describe-variable (var)
1407 "VAR is symbol or string."
1408 (describe-variable (anything-c-symbolify var)))
1410 (defun anything-c-find-function (func)
1411 "FUNC is symbol or string."
1412 (find-function (anything-c-symbolify func)))
1414 (defun anything-c-find-variable (var)
1415 "VAR is symbol or string."
1416 (find-variable (anything-c-symbolify var)))
1418 (defun anything-c-kill-new (string &optional replace yank-handler)
1419 "STRING is symbol or string."
1420 (kill-new (anything-c-stringify string) replace yank-handler))
1422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1423 ;; TODO
1424 (defvar anything-current-prefix-arg nil
1425 "`current-prefix-arg' when selecting action.
1426 It is cleared after executing action.")
1428 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
1429 (unless anything-current-prefix-arg
1430 (setq anything-current-prefix-arg current-prefix-arg)))
1432 (add-hook 'anything-after-action-hook
1433 (lambda () (setq anything-current-prefix-arg nil)))
1436 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1437 (defadvice eval-defun (after anything-source-hack activate)
1438 "See `anything-c-enable-eval-defun-hack'."
1439 (when anything-c-enable-eval-defun-hack
1440 (let ((varsym (save-excursion
1441 (beginning-of-defun)
1442 (forward-char 1)
1443 (when (memq (read (current-buffer)) '(defvar setq))
1444 (read (current-buffer))))))
1445 (when (string-match "^anything-c-source-" (symbol-name varsym))
1446 (anything varsym)))))
1447 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1450 (defun anything-c-create-summary ()
1451 "Create `anything' summary."
1452 (save-excursion
1453 (goto-char (point-min))
1454 (loop while (re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$" nil t)
1455 collect (cond ((match-beginning 1)
1456 (cons 'section (match-string-no-properties 1)))
1457 ((match-beginning 2)
1458 (cons 'source
1459 (cons (match-string-no-properties 2)
1460 (assoc-default 'name (symbol-value (intern (match-string-no-properties 2)))))))
1461 ((match-beginning 3)
1462 (cons 'source
1463 (cons (match-string-no-properties 3)
1464 (assoc-default 'name (symbol-value (intern (match-string-no-properties 3)))))))))))
1466 ;; (find-epp (anything-c-create-summary))
1468 (defun anything-c-insert-summary ()
1469 "Insert `anything' summary."
1470 (save-excursion
1471 (goto-char (point-min))
1472 (search-forward ";; Below are complete source list you can setup in")
1473 (forward-line 1)
1474 (delete-region (point)
1475 (progn (search-forward ";;; Change log:" nil t)
1476 (forward-line -1) (point)))
1477 (insert ";;\n")
1478 (loop with beg
1479 for (kind . value) in (anything-c-create-summary)
1480 for i from 0
1481 do (cond ((eq kind 'section)
1482 (unless (zerop i)
1483 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1484 (insert ";; " value ":\n")
1485 (setq beg (point)))
1487 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
1488 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
1489 ;; (anything-c-insert-summary)
1491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1492 ;;;; <Buffer>
1493 (defun anything-c-buffer-list ()
1494 "Return the list of names of buffers with boring buffers filtered out.
1495 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1496 The first buffer in the list will be the last recently used
1497 buffer that is not the current buffer."
1498 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1499 (append (cdr buffers) (list (car buffers)))))
1501 (defvar anything-c-source-buffers
1502 '((name . "Buffers")
1503 (candidates . anything-c-buffer-list)
1504 (type . buffer)))
1505 ;; (anything 'anything-c-source-buffers)
1507 (defvar anything-c-source-buffer-not-found
1508 '((name . "Create buffer")
1509 (dummy)
1510 (type . buffer)))
1511 ;; (anything 'anything-c-source-buffer-not-found)
1513 ;;; Buffers+
1514 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1515 "*Face used for directory headings in dired buffers."
1516 :group 'anything)
1518 (defface anything-file-name
1519 '((t (:foreground "Blue")))
1520 "*Face used for file names (without suffixes) in dired buffers."
1521 :group 'anything)
1523 (defface anything-dir-priv
1524 '((t (:foreground "DarkRed" :background "LightGray")))
1525 "*Face used for directory privilege indicator (d) in dired buffers."
1526 :group 'anything)
1528 (defvar anything-c-buffers-face1 'anything-dir-priv)
1529 (defvar anything-c-buffers-face2 'font-lock-type-face)
1530 (defvar anything-c-buffers-face3 'italic)
1531 (eval-when-compile (require 'dired))
1532 (defun anything-c-highlight-buffers (buffers)
1533 (require 'dired)
1534 (loop for i in buffers
1535 if (rassoc (get-buffer i) dired-buffers)
1536 collect (propertize i
1537 'face anything-c-buffers-face1
1538 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1539 if (buffer-file-name (get-buffer i))
1540 collect (propertize i
1541 'face anything-c-buffers-face2
1542 'help-echo (buffer-file-name (get-buffer i)))
1543 if (and (not (rassoc (get-buffer i) dired-buffers))
1544 (not (buffer-file-name (get-buffer i))))
1545 collect (propertize i
1546 'face anything-c-buffers-face3)))
1548 (defvar anything-c-source-buffers+
1549 '((name . "Buffers")
1550 (candidates . anything-c-buffer-list)
1551 (type . buffer)
1552 (candidate-transformer anything-c-skip-current-buffer
1553 anything-c-highlight-buffers
1554 anything-c-skip-boring-buffers)
1555 (persistent-action . anything-c-buffers+-persistent-action)
1556 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1558 (defun anything-c-buffers+-persistent-action (name)
1559 (flet ((kill (item)
1560 (with-current-buffer item
1561 (if (and (buffer-modified-p)
1562 (buffer-file-name (current-buffer)))
1563 (progn
1564 (save-buffer)
1565 (kill-buffer item))
1566 (kill-buffer item))))
1567 (goto (item)
1568 (switch-to-buffer item)))
1569 (if current-prefix-arg
1570 (progn
1571 (kill name)
1572 (anything-delete-current-selection))
1573 (goto name))))
1575 ;; (anything 'anything-c-source-buffers+)
1578 ;;;; <File>
1579 ;;; File name history
1580 (defvar anything-c-source-file-name-history
1581 '((name . "File Name History")
1582 (candidates . file-name-history)
1583 (match anything-c-match-on-file-name
1584 anything-c-match-on-directory-name)
1585 (type . file)))
1586 ;; (anything 'anything-c-source-file-name-history)
1588 ;;; Files in current dir
1589 (defvar anything-c-source-files-in-current-dir
1590 '((name . "Files from Current Directory")
1591 (candidates . (lambda ()
1592 (with-current-buffer anything-current-buffer
1593 (directory-files (anything-c-current-directory)))))
1594 ;; volatile is not needed, I think.
1595 (type . file)))
1596 ;; (anything 'anything-c-source-files-in-current-dir)
1598 (defvar anything-c-files-face1 'anything-dir-priv)
1599 (defvar anything-c-files-face2 'anything-file-name)
1600 (defun anything-c-highlight-files (files)
1601 (loop for i in files
1602 if (file-directory-p i)
1603 collect (propertize (file-name-nondirectory i)
1604 'face anything-c-files-face1
1605 'help-echo (expand-file-name i))
1606 else
1607 collect (propertize (file-name-nondirectory i)
1608 'face anything-c-files-face2
1609 'help-echo (expand-file-name i))))
1612 (defvar anything-c-source-files-in-current-dir+
1613 '((name . "Files from Current Directory")
1614 (candidates . (lambda ()
1615 (with-current-buffer anything-current-buffer
1616 (directory-files (anything-c-current-directory) t))))
1617 (candidate-transformer anything-c-highlight-files)
1618 ;; volatile is not needed, I think.
1619 (type . file)))
1621 ;; (anything 'anything-c-source-files-in-current-dir+)
1623 ;;; Anything replacement of file name completion for `find-file' and friends.
1625 (defvar anything-c-find-files-doc-header (format " (`%s':Go to precedent level)"
1626 (if window-system "C-." "C-l"))
1627 "*The doc that is inserted in the Name header of a find-files or dired source.")
1629 (defvar anything-c-source-find-files
1630 `((name . ,(concat "Find Files" anything-c-find-files-doc-header))
1631 ;; It is needed for filenames with capital letters
1632 (disable-shortcuts)
1633 (init . (lambda ()
1634 (setq ffap-newfile-prompt t)))
1635 (candidates . anything-find-files-get-candidates)
1636 (candidate-transformer anything-c-highlight-ffiles)
1637 (persistent-action . anything-find-files-persistent-action)
1638 (persistent-help . "Expand Candidate")
1639 (volatile)
1640 (action
1641 . ,(delq
1643 `(("Find File" . anything-c-find-file-or-marked)
1644 ("Find file in Dired" . anything-c-point-file-in-dired)
1645 ,(and (locate-library "elscreen")
1646 '("Find file in Elscreen" . anything-elscreen-find-file))
1647 ("Complete at point"
1648 . anything-c-insert-file-name-completion-at-point)
1649 ("Delete File(s)" . anything-delete-marked-files)
1650 ("Find file as root" . anything-find-file-as-root)
1651 ("Open file externally (C-u to choose)"
1652 . anything-c-open-file-externally)
1653 ;; ("Create dired buffer on marked"
1654 ;; . anything-c-create-dired-on-marked)
1655 ("Find file other window" . find-file-other-window)
1656 ("Find file other frame" . find-file-other-frame))))))
1658 ;; (anything 'anything-c-source-find-files)
1660 (defun* anything-reduce-file-name (fname level &key unix-close expand)
1661 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1662 If LEVEL is positive reduce from end else from beginning.
1663 If UNIX-CLOSE is non--nil close filename with /.
1664 If EXPAND is non--nil expand-file-name."
1665 (let* ((exp-fname (expand-file-name fname))
1666 (fname-list (split-string (if (or (string= fname "~/") expand)
1667 exp-fname fname) "/" t))
1668 (len (length fname-list))
1669 (pop-list (if (< level 0)
1670 (subseq fname-list (* level -1))
1671 (subseq fname-list 0 (- len level))))
1672 (result (mapconcat 'identity pop-list "/"))
1673 (empty (string= result "")))
1674 (when unix-close (setq result (concat result "/")))
1675 (if (string-match "^~" result)
1676 (if (string= result "~/") "~/" result)
1677 (if (< level 0)
1678 (if empty "../" (concat "../" result))
1679 (cond ((eq system-type 'windows-nt)
1680 (if empty "c:/" result))
1681 (empty "/")
1683 (concat "/" result)))))))
1685 (defun anything-file-completion-source-p ()
1686 "Test if current source is a dired or find-files source."
1687 (let ((ff-sources '("Find Files" "Copy Files"
1688 "Rename Files" "Symlink Files"
1689 "Hardlink Files" "Write File"
1690 "Insert File" "Read file name"))
1691 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
1692 (catch 'break
1693 (dolist (i ff-sources)
1694 (when (equal cur-source (concat i anything-c-find-files-doc-header))
1695 (throw 'break t))))))
1697 (defun anything-find-files-down-one-level (arg)
1698 "Go down one level like unix command `cd ..'.
1699 If prefix numeric arg is given go ARG level down."
1700 (interactive "p")
1701 (when (anything-file-completion-source-p)
1702 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
1703 :unix-close t :expand t)))
1704 (with-selected-window (minibuffer-window)
1705 (delete-minibuffer-contents)
1706 (insert new-pattern)))))
1708 ;; `C-.' doesn't work in terms use `C-l' instead.
1709 (if window-system
1710 (define-key anything-map (kbd "C-.") 'anything-find-files-down-one-level)
1711 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))
1713 (defun anything-c-point-file-in-dired (file)
1714 "Put point on filename FILE in dired buffer."
1715 (dired (file-name-directory file))
1716 (dired-goto-file file))
1718 (defun anything-create-tramp-name (fname)
1719 "Build filename for `anything-pattern' like /su:: or /sudo::."
1720 (apply #'tramp-make-tramp-file-name
1721 (loop
1722 with v = (tramp-dissect-file-name fname)
1723 for i across v collect i)))
1725 (defun anything-find-files-get-candidates ()
1726 "Create candidate list for `anything-c-source-find-files'."
1727 (let* ( ; Don't try to tramp connect before entering the second ":".
1728 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1729 (path (cond ((string-match "^~" anything-pattern)
1730 (replace-match (getenv "HOME") nil t anything-pattern))
1731 ((string-match tramp-file-name-regexp anything-pattern)
1732 (let ((tramp-name (anything-create-tramp-name
1733 (match-string 0 anything-pattern))))
1734 (replace-match tramp-name nil t anything-pattern)))
1735 (t anything-pattern)))
1736 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
1737 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1738 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1739 ;; and sorting.
1740 (flet ((tramp-handle-directory-files
1741 (directory &optional full match nosort files-only)
1742 "Like `directory-files' for Tramp files."
1743 ;; FILES-ONLY is valid for XEmacs only.
1744 (when (file-directory-p directory)
1745 (setq directory (file-name-as-directory (expand-file-name directory)))
1746 (let ((temp (nreverse (file-name-all-completions "" directory)))
1747 result item)
1749 (while temp
1750 (setq item (directory-file-name (pop temp)))
1751 (when (and (or (null match) (string-match match item))
1752 (or (null files-only)
1753 ;; Files only.
1754 (and (equal files-only t) (file-regular-p item))
1755 ;; Directories only.
1756 (file-directory-p item)))
1757 (push (if full (concat directory item) item)
1758 result)))
1759 (if nosort result (sort result 'string<))))))
1761 (set-text-properties 0 (length path) nil path)
1762 (setq anything-pattern path)
1763 (cond ((or (file-regular-p path)
1764 (and ffap-url-regexp (string-match ffap-url-regexp path)))
1765 (list path))
1766 ((string= anything-pattern "") (directory-files "/" t))
1767 ((file-directory-p path) (directory-files path t))
1769 (append
1770 (list path)
1771 (directory-files (file-name-directory path) t)))))))
1773 (defface anything-dired-symlink-face
1774 '((t (:foreground "DarkOrange")))
1775 "*Face used for symlinks in `anything-find-files'."
1776 :group 'anything)
1778 (defun anything-c-highlight-ffiles (files)
1779 "Candidate transformer for `anything-c-source-find-files'."
1780 (loop for i in files
1781 if (file-symlink-p i)
1782 collect (propertize i 'face 'anything-dired-symlink-face
1783 'help-echo (file-truename i)) into a
1784 if (file-directory-p i)
1785 collect (propertize i 'face anything-c-files-face1) into a
1786 else
1787 collect (propertize i 'face anything-c-files-face2) into a
1788 finally return a))
1791 (defun anything-find-files-persistent-action (candidate)
1792 "Open subtree CANDIDATE without quitting anything.
1793 If CANDIDATE is not a directory expand CANDIDATE filename.
1794 If CANDIDATE is alone, open file CANDIDATE filename."
1795 (flet ((insert-in-minibuffer (elm)
1796 (with-selected-window (minibuffer-window)
1797 (delete-minibuffer-contents)
1798 (set-text-properties 0 (length elm) nil elm)
1799 (insert elm))))
1800 (cond ((and (file-directory-p candidate) (file-symlink-p candidate))
1801 (insert-in-minibuffer (file-name-as-directory
1802 (file-truename
1803 (expand-file-name candidate)))))
1804 ((file-directory-p candidate)
1805 (insert-in-minibuffer (file-name-as-directory
1806 (expand-file-name candidate))))
1807 ((file-symlink-p candidate)
1808 (insert-in-minibuffer (file-truename candidate)))
1809 (t ; First hit on C-z expand CANDIDATE second hit open file.
1810 (let ((new-pattern (anything-get-selection anything-last-buffer))
1811 (num-lines-buf (with-current-buffer anything-last-buffer
1812 (count-lines (point-min) (point-max)))))
1813 (if (> num-lines-buf 3)
1814 (insert-in-minibuffer new-pattern) (find-file candidate)))))))
1816 (defun anything-c-insert-file-name-completion-at-point (candidate)
1817 "Insert file name completion at point."
1818 (if buffer-read-only
1819 (error "Error: Buffer `%s' is read-only" (buffer-name))
1820 (let* ((end (point))
1821 (guess (thing-at-point 'filename))
1822 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess)
1823 (string-match "^[^\~]" guess))))
1824 (set-text-properties 0 (length candidate) nil candidate)
1825 (if (and guess (not (string= guess "")) (string-match "^~\\|/.*" guess))
1826 (progn
1827 (search-backward guess (- (point) (length guess)))
1828 (delete-region (point) end)
1829 (if full-path-p
1830 (insert (expand-file-name candidate))
1831 (insert (abbreviate-file-name candidate))))
1832 (error "Aborting completion: No valid file name at point")))))
1834 ;;;###autoload
1835 (defun anything-find-files ()
1836 "Preconfigured `anything' for anything implementation of `find-file'."
1837 (interactive)
1838 (anything 'anything-c-source-find-files
1839 (anything-find-files-input (ffap-guesser)
1840 (thing-at-point 'filename))
1841 "Find Files or Url: " nil nil "*Anything Find Files*"))
1843 (defun anything-c-current-directory ()
1844 "Return current-directory name at point.
1845 Useful in dired buffers when there is inserted subdirs."
1846 (if (eq major-mode 'dired-mode)
1847 (dired-current-directory)
1848 default-directory))
1850 (defun anything-find-files-input (fap tap)
1851 "Default input of `anything-find-files'."
1852 (let* ((def-dir (anything-c-current-directory))
1853 (file-p (and fap (file-exists-p fap)
1854 (file-exists-p
1855 (file-name-directory (expand-file-name tap def-dir)))))
1856 (input (if file-p (expand-file-name tap def-dir) fap)))
1857 (or input (expand-file-name def-dir))))
1859 ;;; Anything completion for `write-file'.==> C-x C-w
1860 (defvar anything-c-source-write-file
1861 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
1862 ;; It is needed for filenames with capital letters
1863 (disable-shortcuts)
1864 (candidates . anything-find-files-get-candidates)
1865 (candidate-transformer anything-c-highlight-ffiles)
1866 (persistent-action . anything-find-files-persistent-action)
1867 (persistent-help . "Expand Candidate")
1868 (volatile)
1869 (action .
1870 (("Write File" . (lambda (candidate)
1871 (write-file candidate 'confirm)))))))
1873 ;;;###autoload
1874 (defun anything-write-file ()
1875 "Preconfigured `anything' providing completion for `write-file'."
1876 (interactive)
1877 (anything 'anything-c-source-write-file
1878 (expand-file-name default-directory)
1879 "Write buffer to file: " nil nil "*Anything write file*"))
1881 ;;; Anything completion for `insert-file'.==> C-x i
1882 (defvar anything-c-source-insert-file
1883 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
1884 ;; It is needed for filenames with capital letters
1885 (disable-shortcuts)
1886 (candidates . anything-find-files-get-candidates)
1887 (candidate-transformer anything-c-highlight-ffiles)
1888 (persistent-action . anything-find-files-persistent-action)
1889 (persistent-help . "Expand Candidate")
1890 (volatile)
1891 (action .
1892 (("Insert File" . (lambda (candidate)
1893 (when (y-or-n-p (format "Really insert %s in %s "
1894 candidate anything-current-buffer))
1895 (insert-file-contents candidate))))))))
1897 ;;;###autoload
1898 (defun anything-insert-file ()
1899 "Preconfigured `anything' providing completion for `insert-file'."
1900 (interactive)
1901 (anything 'anything-c-source-insert-file
1902 (expand-file-name default-directory)
1903 "Insert file: " nil nil "*Anything insert file*"))
1905 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
1906 (defvar anything-c-source-copy-files
1907 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
1908 ;; It is needed for filenames with capital letters
1909 (disable-shortcuts)
1910 (candidates . anything-find-files-get-candidates)
1911 (candidate-transformer anything-c-highlight-ffiles)
1912 (persistent-action . anything-find-files-persistent-action)
1913 (persistent-help . "Expand Candidate")
1914 (volatile)
1915 (action .
1916 (("Copy File"
1917 . (lambda (candidate)
1918 (anything-dired-action candidate :action 'copy)))
1919 ("Copy and Follow"
1920 . (lambda (candidate)
1921 (anything-dired-action candidate :action 'copy :follow t)))))))
1924 (defvar anything-c-source-rename-files
1925 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
1926 ;; It is needed for filenames with capital letters
1927 (disable-shortcuts)
1928 (candidates . anything-find-files-get-candidates)
1929 (candidate-transformer anything-c-highlight-ffiles)
1930 (persistent-action . anything-find-files-persistent-action)
1931 (persistent-help . "Expand Candidate")
1932 (volatile)
1933 (action .
1934 (("Rename File"
1935 . (lambda (candidate)
1936 (anything-dired-action candidate :action 'rename)))
1937 ("Rename and Follow"
1938 . (lambda (candidate)
1939 (anything-dired-action candidate :action 'rename :follow t)))))))
1941 (defvar anything-c-source-symlink-files
1942 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
1943 ;; It is needed for filenames with capital letters
1944 (disable-shortcuts)
1945 (candidates . anything-find-files-get-candidates)
1946 (candidate-transformer anything-c-highlight-ffiles)
1947 (persistent-action . anything-find-files-persistent-action)
1948 (persistent-help . "Expand Candidate")
1949 (volatile)
1950 (action
1951 . (("Symlink File"
1952 . (lambda (candidate)
1953 (anything-dired-action candidate :action 'symlink)))
1954 ("RelSymlink File"
1955 . (lambda (candidate)
1956 (anything-dired-action candidate :action 'relsymlink)))))))
1959 (defvar anything-c-source-hardlink-files
1960 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
1961 ;; It is needed for filenames with capital letters
1962 (disable-shortcuts)
1963 (candidates . anything-find-files-get-candidates)
1964 (candidate-transformer anything-c-highlight-ffiles)
1965 (persistent-action . anything-find-files-persistent-action)
1966 (persistent-help . "Expand Candidate")
1967 (volatile)
1968 (action
1969 . (("Hardlink File"
1970 . (lambda (candidate)
1971 (anything-dired-action candidate :action 'hardlink)))))))
1973 (defun* anything-dired-action (candidate &key action follow)
1974 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
1975 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
1976 (let ((files (dired-get-marked-files))
1977 (fn (case action
1978 ('copy 'dired-copy-file)
1979 ('rename 'dired-rename-file)
1980 ('symlink 'make-symbolic-link)
1981 ('relsymlink 'dired-make-relative-symlink)
1982 ('hardlink 'dired-hardlink)))
1983 (marker (case action
1984 ((copy rename) dired-keep-marker-copy)
1985 ('symlink dired-keep-marker-symlink)
1986 ('relsymlink dired-keep-marker-relsymlink)
1987 ('hardlink dired-keep-marker-hardlink))))
1988 (dired-create-files
1989 fn (symbol-name action) files
1990 (if (file-directory-p candidate)
1991 ;; When CANDIDATE is a directory, build file-name in this directory.
1992 ;; Else we use CANDIDATE.
1993 #'(lambda (from)
1994 (expand-file-name (file-name-nondirectory from) candidate))
1995 #'(lambda (from) candidate))
1996 marker)
1997 (when follow
1998 (let* ((src (car files))
1999 (dest (expand-file-name candidate))
2000 (basename-src (if (file-directory-p src)
2001 (file-relative-name
2002 (directory-file-name src)
2003 (file-name-directory src))
2004 (file-name-nondirectory src)))
2005 (fname (if (file-directory-p dest)
2006 (concat (file-name-as-directory dest)
2007 basename-src)
2008 dest)))
2009 (anything-c-point-file-in-dired fname)))))
2012 (defun* anything-dired-do-action-on-file (&key action)
2013 (let* ((files (dired-get-marked-files))
2014 (len (length files))
2015 (fname (if (> len 1)
2016 (format "* %d Files" len)
2017 (car files)))
2018 (source (case action
2019 ('copy 'anything-c-source-copy-files)
2020 ('rename 'anything-c-source-rename-files)
2021 ('symlink 'anything-c-source-symlink-files)
2022 ('hardlink 'anything-c-source-hardlink-files)))
2023 (prompt-fm (case action
2024 ('copy "Copy %s to: ")
2025 ('rename "Rename %s to: ")
2026 ('symlink "Symlink %s to: ")
2027 ('hardlink "Hardlink %s to: ")))
2028 (buffer (case action
2029 ('copy "*Anything Copy Files*")
2030 ('rename "*Anything Rename Files*")
2031 ('symlink "*Anything Symlink Files*")
2032 ('hardlink "*Anything Hardlink Files*"))))
2033 (anything source
2034 (or (dired-dwim-target-directory)
2035 (expand-file-name (anything-c-current-directory)))
2036 (format prompt-fm fname) nil nil buffer)))
2039 ;;;###autoload
2040 (defun anything-dired-rename-file ()
2041 "Preconfigured `anything' to rename files from dired."
2042 (interactive)
2043 (anything-dired-do-action-on-file :action 'rename))
2045 ;;;###autoload
2046 (defun anything-dired-copy-file ()
2047 "Preconfigured `anything' to copy files from dired."
2048 (interactive)
2049 (anything-dired-do-action-on-file :action 'copy))
2051 ;;;###autoload
2052 (defun anything-dired-symlink-file ()
2053 "Preconfigured `anything' to symlink files from dired."
2054 (interactive)
2055 (anything-dired-do-action-on-file :action 'symlink))
2057 ;;;###autoload
2058 (defun anything-dired-hardlink-file ()
2059 "Preconfigured `anything' to hardlink files from dired."
2060 (interactive)
2061 (anything-dired-do-action-on-file :action 'hardlink))
2063 (defvar anything-dired-bindings nil)
2064 ;;;###autoload
2065 (defun anything-dired-bindings (&optional arg)
2066 "Replace usual dired commands `C' and `R' by anything ones.
2067 When call interactively toggle dired bindings and anything bindings.
2068 When call non--interactively with arg > 0, enable anything bindings.
2069 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2070 (interactive)
2071 (if (or (when arg (> arg 0)) (not anything-dired-bindings))
2072 (progn
2073 (define-key dired-mode-map (kbd "C") 'anything-dired-copy-file)
2074 (define-key dired-mode-map (kbd "R") 'anything-dired-rename-file)
2075 (define-key dired-mode-map (kbd "S") 'anything-dired-symlink-file)
2076 (define-key dired-mode-map (kbd "H") 'anything-dired-hardlink-file)
2077 (setq anything-dired-bindings t))
2078 (define-key dired-mode-map (kbd "C") 'dired-do-copy)
2079 (define-key dired-mode-map (kbd "R") 'dired-do-rename)
2080 (define-key dired-mode-map (kbd "S") 'dired-do-symlink)
2081 (define-key dired-mode-map (kbd "H") 'dired-do-hardlink)
2082 (setq anything-dired-bindings nil)))
2084 (defun* anything-c-read-file-name (prompt &key
2085 (initial-input (expand-file-name default-directory))
2086 (buffer "*Anything Completions*")
2087 test)
2088 "Anything `read-file-name' emulation.
2089 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2090 (when (get-buffer anything-action-buffer)
2091 (kill-buffer anything-action-buffer))
2092 (or (anything
2093 `((name . ,(concat "Read file name" anything-c-find-files-doc-header))
2094 ;; It is needed for filenames with capital letters
2095 (disable-shortcuts)
2096 (candidates . (lambda ()
2097 (if test
2098 (loop with seq = (anything-find-files-get-candidates)
2099 for fname in seq when (funcall test fname)
2100 collect fname)
2101 (anything-find-files-get-candidates))))
2102 (candidate-transformer anything-c-highlight-ffiles)
2103 (persistent-action . anything-find-files-persistent-action)
2104 (persistent-help . "Expand Candidate")
2105 (volatile)
2106 (action . (("candidate" . ,'identity))))
2107 initial-input prompt 'noresume nil buffer)
2108 (keyboard-quit)))
2110 ;;; File Cache
2111 (defvar anything-c-source-file-cache-initialized nil)
2113 (defvar anything-c-file-cache-files nil)
2115 (defvar anything-c-source-file-cache
2116 '((name . "File Cache")
2117 (init
2118 . (lambda ()
2119 (require 'filecache nil t)
2120 (unless anything-c-source-file-cache-initialized
2121 (setq anything-c-file-cache-files
2122 (loop for item in file-cache-alist append
2123 (destructuring-bind (base &rest dirs) item
2124 (loop for dir in dirs collect
2125 (concat dir base)))))
2126 (defadvice file-cache-add-file (after file-cache-list activate)
2127 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
2128 (setq anything-c-source-file-cache-initialized t))))
2129 (candidates . anything-c-file-cache-files)
2130 (match anything-c-match-on-file-name
2131 anything-c-match-on-directory-name)
2132 (type . file)))
2133 ;; (anything 'anything-c-source-file-cache)
2135 ;;; Locate
2136 ;; NOTE for WINDOZE users:
2137 ;; You have to install Everything with his command line interface here:
2138 ;; http://www.voidtools.com/download.php
2140 (defvar anything-c-locate-command
2141 (case system-type
2142 ('gnu/linux "locate -i -r %s")
2143 ('berkeley-unix "locate -i %s")
2144 ('windows-nt "es -i -r %s")
2145 (t "locate %s"))
2146 "A list of arguments for locate program.
2147 The \"-r\" option must be the last option.")
2149 (defun anything-c-locate-init ()
2150 "Initialize async locate process for `anything-c-source-locate'."
2151 (start-process-shell-command "locate-process" nil
2152 (format anything-c-locate-command
2153 anything-pattern)))
2155 (defvar anything-c-source-locate
2156 '((name . "Locate")
2157 (candidates . anything-c-locate-init)
2158 (type . file)
2159 (requires-pattern . 3)
2160 (delayed))
2161 "Find files matching the current input pattern with locate.")
2163 ;; (anything 'anything-c-source-locate)
2165 ;;; Recentf files
2166 (defvar anything-c-source-recentf
2167 '((name . "Recentf")
2168 (init . (lambda ()
2169 (require 'recentf)
2170 (or recentf-mode (recentf-mode 1))
2171 ;; Big value empowers anything/recentf
2172 (when (and (numberp recentf-max-saved-items)
2173 (<= recentf-max-saved-items 20))
2174 (setq recentf-max-saved-items 500))))
2175 (candidates . recentf-list)
2176 (match anything-c-match-on-file-name
2177 anything-c-match-on-directory-name)
2178 (type . file))
2179 "See (info \"(emacs)File Conveniences\").
2180 if `recentf-max-saved-items' is too small, set it to 500.")
2181 ;; (anything 'anything-c-source-recentf)
2183 ;;; ffap
2184 (eval-when-compile (require 'ffap))
2185 (defvar anything-c-source-ffap-guesser
2186 '((name . "File at point")
2187 (init . (lambda () (require 'ffap)))
2188 (candidates . (lambda ()
2189 (anything-aif
2190 (with-current-buffer anything-current-buffer
2191 (ffap-guesser))
2192 (list it))))
2193 (type . file)))
2194 ;; (anything 'anything-c-source-ffap-guesser)
2196 ;;; ffap with line number
2197 (defun anything-c-ffap-file-line-at-point ()
2198 "Get (FILENAME . LINENO) at point."
2199 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2200 (save-excursion
2201 (beginning-of-line)
2202 (when (and (search-forward it nil t)
2203 (looking-at ":\\([0-9]+\\)"))
2204 (cons it (string-to-number (match-string 1)))))))
2206 (defvar anything-c-ffap-line-location nil
2207 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2208 It is cleared after jumping line.")
2210 (defun anything-c-ffap-line-candidates ()
2211 (with-current-buffer anything-current-buffer
2212 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
2213 (when anything-c-ffap-line-location
2214 (destructuring-bind (file . line) anything-c-ffap-line-location
2215 (list (cons (format "%s (line %d)" file line) file)))))
2217 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2218 (defun anything-c-ffap-line-goto-line ()
2219 (when (car anything-c-ffap-line-location)
2220 (unwind-protect
2221 (ignore-errors
2222 (with-selected-window
2223 (get-buffer-window
2224 (get-file-buffer (car anything-c-ffap-line-location)))
2225 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
2226 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
2227 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
2229 (defvar anything-c-source-ffap-line
2230 '((name . "File/Lineno at point")
2231 (init . (lambda () (require 'ffap)))
2232 (candidates . anything-c-ffap-line-candidates)
2233 (type . file)))
2234 ;; (anything 'anything-c-source-ffap-line)
2236 ;;; list of files gleaned from every dired buffer
2237 (defun anything-c-files-in-all-dired-candidates ()
2238 (save-excursion
2239 (mapcan
2240 (lambda (dir)
2241 (cond ((listp dir) ;filelist
2242 dir)
2243 ((equal "" (file-name-nondirectory dir)) ;dir
2244 (directory-files dir t))
2245 (t ;wildcard
2246 (file-expand-wildcards dir t))))
2247 (delq nil
2248 (mapcar (lambda (buf)
2249 (set-buffer buf)
2250 (when (eq major-mode 'dired-mode)
2251 (if (consp dired-directory)
2252 (cdr dired-directory) ;filelist
2253 dired-directory))) ;dir or wildcard
2254 (buffer-list))))))
2255 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2257 (defvar anything-c-source-files-in-all-dired
2258 '((name . "Files in all dired buffer.")
2259 (candidates . anything-c-files-in-all-dired-candidates)
2260 (type . file)))
2261 ;; (anything 'anything-c-source-files-in-all-dired)
2263 ;;;; <info>
2264 ;;; Info pages
2265 (defvar anything-c-info-pages nil
2266 "All info pages on system.
2267 Will be calculated the first time you invoke anything with this
2268 source.")
2270 (defvar anything-c-source-info-pages
2271 `((name . "Info Pages")
2272 (candidates
2273 . (lambda ()
2274 (if anything-c-info-pages
2275 anything-c-info-pages
2276 (setq anything-c-info-pages
2277 (save-window-excursion
2278 (save-excursion
2279 (require 'info)
2280 (Info-find-node "dir" "top")
2281 (goto-char (point-min))
2282 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2283 topics)
2284 (while (re-search-forward info-topic-regexp nil t)
2285 (add-to-list 'topics (match-string-no-properties 1)))
2286 (goto-char (point-min))
2287 (Info-exit)
2288 topics)))))))
2289 (action . (("Show with Info" .(lambda (node-str)
2290 (info (replace-regexp-in-string "^[^:]+: "
2292 node-str))))))
2293 (requires-pattern . 2)))
2294 ;; (anything 'anything-c-source-info-pages)
2297 ;;; Use info-index plug-in. Note that `name' attribute is
2298 ;;; not needed but `anything-c-insert-summary' uses it.
2299 ;; Info Elisp
2300 (defvar anything-c-source-info-elisp
2301 '((name . "Info index: elisp")
2302 (info-index . "elisp")))
2303 ;; (anything 'anything-c-source-info-elisp)
2305 ;; Info-Common-Lisp
2306 (defvar anything-c-source-info-cl
2307 '((name . "Info index: cl")
2308 (info-index . "cl")))
2309 ;; (anything 'anything-c-source-info-cl)
2311 ;; Info Index org
2312 (defvar anything-c-source-info-org
2313 '((name . "Info index: org")
2314 (info-index . "org")))
2315 ;; (anything 'anything-c-source-info-org)
2317 ;; Info Index ratpoison
2318 (defvar anything-c-source-info-ratpoison
2319 '((name . "Info index: ratpoison")
2320 (info-index . "ratpoison")))
2321 ;; (anything 'anything-c-source-info-ratpoison)
2323 ;; Info Index zsh
2324 (defvar anything-c-source-info-zsh
2325 '((name . "Info index: zsh")
2326 (info-index . "zsh")))
2327 ;; (anything 'anything-c-source-info-zsh)
2329 ;; Info Index bash
2330 (defvar anything-c-source-info-bash
2331 '((name . "Info index: bash")
2332 (info-index . "bash")))
2333 ;; (anything 'anything-c-source-info-bash)
2335 ;; Info Index coreutils
2336 (defvar anything-c-source-info-coreutils
2337 '((name . "Info index: coreutils")
2338 (info-index . "coreutils")))
2339 ;; (anything 'anything-c-source-info-coreutils)
2341 ;; Info Index fileutils
2342 (defvar anything-c-source-info-fileutils
2343 '((name . "Info index: fileutils")
2344 (info-index . "fileutils")))
2345 ;; (anything 'anything-c-source-info-fileutils)
2347 ;; Info Index find
2348 (defvar anything-c-source-info-find
2349 '((name . "Info index: find")
2350 (info-index . "find")))
2351 ;; (anything 'anything-c-source-info-find)
2353 ;; Info Index sh-utils
2354 (defvar anything-c-source-info-sh-utils
2355 '((name . "Info index: sh-utils")
2356 (info-index . "sh-utils")))
2357 ;; (anything 'anything-c-source-info-sh-utils)
2359 ;; Info Index textutils
2360 (defvar anything-c-source-info-textutils
2361 '((name . "Info index: textutils")
2362 (info-index . "textutils")))
2363 ;; (anything 'anything-c-source-info-textutils)
2365 ;; Info Index libc
2366 (defvar anything-c-source-info-libc
2367 '((name . "Info index: libc")
2368 (info-index . "libc")))
2369 ;; (anything 'anything-c-source-info-libc)
2371 ;; Info Index make
2372 (defvar anything-c-source-info-make
2373 '((name . "Info index: make")
2374 (info-index . "make")))
2375 ;; (anything 'anything-c-source-info-make)
2377 ;; Info Index automake
2378 (defvar anything-c-source-info-automake
2379 '((name . "Info index: automake")
2380 (info-index . "automake")))
2381 ;; (anything 'anything-c-source-info-automake)
2383 ;; Info Index autoconf
2384 (defvar anything-c-source-info-autoconf
2385 '((name . "Info index: autoconf")
2386 (info-index . "autoconf")))
2387 ;; (anything 'anything-c-source-info-autoconf)
2389 ;; Info Index emacs-lisp-intro
2390 (defvar anything-c-source-info-emacs-lisp-intro
2391 '((name . "Info index: emacs-lisp-intro")
2392 (info-index . "emacs-lisp-intro")))
2393 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2395 ;; Info Index emacs
2396 (defvar anything-c-source-info-emacs
2397 '((name . "Info index: emacs")
2398 (info-index . "emacs")))
2399 ;; (anything 'anything-c-source-info-emacs)
2401 ;; Info Index elib
2402 (defvar anything-c-source-info-elib
2403 '((name . "Info index: elib")
2404 (info-index . "elib")))
2405 ;; (anything 'anything-c-source-info-elib)
2407 ;; Info Index eieio
2408 (defvar anything-c-source-info-eieio
2409 '((name . "Info index: eieio")
2410 (info-index . "eieio")))
2411 ;; (anything 'anything-c-source-info-eieio)
2413 ;; Info Index gauche-refe
2414 (defvar anything-c-source-info-gauche-refe
2415 '((name . "Info index: gauche")
2416 (info-index . "gauche-refe")))
2417 ;; (anything 'anything-c-source-info-gauche-refe)
2419 ;; Info Index guile
2420 (defvar anything-c-source-info-guile
2421 '((name . "Info index: guile")
2422 (info-index . "guile")))
2423 ;; (anything 'anything-c-source-info-guile)
2425 ;; Info Index guile-tut
2426 (defvar anything-c-source-info-guile-tut
2427 '((name . "Info index: guile-tut")
2428 (info-index . "guile-tut")))
2429 ;; (anything 'anything-c-source-info-guile-tut)
2431 ;; Info Index goops
2432 (defvar anything-c-source-info-goops
2433 '((name . "Info index: goops")
2434 (info-index . "goops")))
2435 ;; (anything 'anything-c-source-info-goops)
2437 ;; Info Index screen
2438 (defvar anything-c-source-info-screen
2439 '((name . "Info index: screen")
2440 (info-index . "screen")
2441 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2442 ;; (anything 'anything-c-source-info-screen)
2444 ;; Info Index latex
2445 (defvar anything-c-source-info-latex
2446 '((name . "Info index: latex")
2447 (info-index . "latex")))
2448 ;; (anything 'anything-c-source-info-latex)
2450 ;; Info Index gawk
2451 (defvar anything-c-source-info-gawk
2452 '((name . "Info index: gawk")
2453 (info-index . "gawk")))
2454 ;; (anything 'anything-c-source-info-gawk)
2456 ;; Info Index sed
2457 (defvar anything-c-source-info-sed
2458 '((name . "Info index: sed")
2459 (info-index . "sed")))
2460 ;; (anything 'anything-c-source-info-sed)
2462 ;; Info Index m4
2463 (defvar anything-c-source-info-m4
2464 '((name . "Info index: m4")
2465 (info-index . "m4")))
2466 ;; (anything 'anything-c-source-info-m4)
2468 ;; Info Index wget
2469 (defvar anything-c-source-info-wget
2470 '((name . "Info index: wget")
2471 (info-index . "wget")))
2472 ;; (anything 'anything-c-source-info-wget)
2474 ;; Info Index binutils
2475 (defvar anything-c-source-info-binutils
2476 '((name . "Info index: binutils")
2477 (info-index . "binutils")))
2478 ;; (anything 'anything-c-source-info-binutils)
2480 ;; Info Index as
2481 (defvar anything-c-source-info-as
2482 '((name . "Info index: as")
2483 (info-index . "as")))
2484 ;; (anything 'anything-c-source-info-as)
2486 ;; Info Index bfd
2487 (defvar anything-c-source-info-bfd
2488 '((name . "Info index: bfd")
2489 (info-index . "bfd")))
2490 ;; (anything 'anything-c-source-info-bfd)
2492 ;; Info Index gprof
2493 (defvar anything-c-source-info-gprof
2494 '((name . "Info index: gprof")
2495 (info-index . "gprof")))
2496 ;; (anything 'anything-c-source-info-gprof)
2498 ;; Info Index ld
2499 (defvar anything-c-source-info-ld
2500 '((name . "Info index: ld")
2501 (info-index . "ld")))
2502 ;; (anything 'anything-c-source-info-ld)
2504 ;; Info Index diff
2505 (defvar anything-c-source-info-diff
2506 '((name . "Info index: diff")
2507 (info-index . "diff")))
2508 ;; (anything 'anything-c-source-info-diff)
2510 ;; Info Index flex
2511 (defvar anything-c-source-info-flex
2512 '((name . "Info index: flex")
2513 (info-index . "flex")))
2514 ;; (anything 'anything-c-source-info-flex)
2516 ;; Info Index grep
2517 (defvar anything-c-source-info-grep
2518 '((name . "Info index: grep")
2519 (info-index . "grep")))
2520 ;; (anything 'anything-c-source-info-grep)
2522 ;; Info Index gzip
2523 (defvar anything-c-source-info-gzip
2524 '((name . "Info index: gzip")
2525 (info-index . "gzip")))
2526 ;; (anything 'anything-c-source-info-gzip)
2528 ;; Info Index libtool
2529 (defvar anything-c-source-info-libtool
2530 '((name . "Info index: libtool")
2531 (info-index . "libtool")))
2532 ;; (anything 'anything-c-source-info-libtool)
2534 ;; Info Index texinfo
2535 (defvar anything-c-source-info-texinfo
2536 '((name . "Info index: texinfo")
2537 (info-index . "texinfo")))
2538 ;; (anything 'anything-c-source-info-texinfo)
2540 ;; Info Index info
2541 (defvar anything-c-source-info-info
2542 '((name . "Info index: info")
2543 (info-index . "info")))
2544 ;; (anything 'anything-c-source-info-info)
2546 ;; Info Index gdb
2547 (defvar anything-c-source-info-gdb
2548 '((name . "Info index: gdb")
2549 (info-index . "gdb")))
2550 ;; (anything 'anything-c-source-info-gdb)
2552 ;; Info Index stabs
2553 (defvar anything-c-source-info-stabs
2554 '((name . "Info index: stabs")
2555 (info-index . "stabs")))
2556 ;; (anything 'anything-c-source-info-stabs)
2558 ;; Info Index cvsbook
2559 (defvar anything-c-source-info-cvsbook
2560 '((name . "Info index: cvsbook")
2561 (info-index . "cvsbook")))
2562 ;; (anything 'anything-c-source-info-cvsbook)
2564 ;; Info Index cvs
2565 (defvar anything-c-source-info-cvs
2566 '((name . "Info index: cvs")
2567 (info-index . "cvs")))
2568 ;; (anything 'anything-c-source-info-cvs)
2570 ;; Info Index bison
2571 (defvar anything-c-source-info-bison
2572 '((name . "Info index: bison")
2573 (info-index . "bison")))
2574 ;; (anything 'anything-c-source-info-bison)
2576 ;; Info Index id-utils
2577 (defvar anything-c-source-info-id-utils
2578 '((name . "Info index: id-utils")
2579 (info-index . "id-utils")))
2580 ;; (anything 'anything-c-source-info-id-utils)
2582 ;; Info Index global
2583 (defvar anything-c-source-info-global
2584 '((name . "Info index: global")
2585 (info-index . "global")))
2586 ;; (anything 'anything-c-source-info-global)
2588 ;;;; <Help>
2589 ;;; Man Pages
2590 (defvar anything-c-man-pages nil
2591 "All man pages on system.
2592 Will be calculated the first time you invoke anything with this
2593 source.")
2595 (defvar anything-c-source-man-pages
2596 `((name . "Manual Pages")
2597 (candidates . (lambda ()
2598 (if anything-c-man-pages
2599 anything-c-man-pages
2600 ;; XEmacs doesn't have a woman :)
2601 (setq anything-c-man-pages
2602 (ignore-errors
2603 (require 'woman)
2604 (woman-file-name "")
2605 (sort (mapcar 'car woman-topic-all-completions)
2606 'string-lessp))))))
2607 (action ("Show with Woman" . (lambda (candidate)
2608 (let ((wfiles (woman-file-name-all-completions candidate)))
2609 (if (> (length wfiles) 1)
2610 (woman-find-file (anything-comp-read "ManFile: " wfiles
2611 :must-match t))
2612 (woman candidate))))))
2613 ;; Woman does not work OS X
2614 ;; http://xahlee.org/emacs/modernization_man_page.html
2615 (action-transformer . (lambda (actions candidate)
2616 (if (eq system-type 'darwin)
2617 '(("Show with Man" . man))
2618 actions)))
2619 (requires-pattern . 2)))
2620 ;; (anything 'anything-c-source-man-pages)
2622 ;;;; <Command>
2623 ;;; Complex command history
2624 (defvar anything-c-source-complex-command-history
2625 '((name . "Complex Command History")
2626 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
2627 (type . sexp)))
2628 ;; (anything 'anything-c-source-complex-command-history)
2630 ;;; M-x history
2631 (defvar anything-c-source-extended-command-history
2632 '((name . "Emacs Commands History")
2633 (candidates . extended-command-history)
2634 (type . command)))
2635 ;; (anything 'anything-c-source-extended-command-history)
2637 ;;; Emacs commands
2638 (defvar anything-c-source-emacs-commands
2639 '((name . "Emacs Commands")
2640 (candidates . (lambda ()
2641 (let (commands)
2642 (mapatoms (lambda (a)
2643 (if (commandp a)
2644 (push (symbol-name a)
2645 commands))))
2646 (sort commands 'string-lessp))))
2647 (type . command)
2648 (requires-pattern . 2))
2649 "Source for completing and invoking Emacs commands.
2650 A command is a function with interactive spec that can
2651 be invoked with `M-x'.
2653 To get non-interactive functions listed, use
2654 `anything-c-source-emacs-functions'.")
2655 ;; (anything 'anything-c-source-emacs-commands)
2657 ;; Another replacement of `M-x' that act exactly like the
2658 ;; vanilla Emacs one, no problem of windows configuration, prefix args
2659 ;; are passed before calling `M-x' (e.g C-u M-x..).
2660 ;;;###autoload
2661 (defun anything-M-x ()
2662 "Preconfigured `anything' for Emacs commands.
2663 It is `anything' replacement of regular `M-x' `execute-extended-command'."
2664 (interactive)
2665 (let ((command (anything-comp-read "M-x " obarray
2666 :test 'commandp
2667 :must-match t
2668 :requires-pattern 2)))
2669 (call-interactively (intern command))))
2671 ;;; LaCarte
2672 (defvar anything-c-source-lacarte
2673 '((name . "Lacarte")
2674 (init . (lambda () (require 'lacarte )))
2675 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2676 (candidate-number-limit . 9999)
2677 (action . anything-c-call-interactively))
2678 "Needs lacarte.el.
2680 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2681 ;; (anything 'anything-c-source-lacarte)
2683 ;;;; <Function>
2684 ;;; Emacs functions
2685 (defvar anything-c-source-emacs-functions
2686 '((name . "Emacs Functions")
2687 (candidates . (lambda ()
2688 (let (commands)
2689 (mapatoms (lambda (a) (if (functionp a)
2690 (push (symbol-name a) commands))))
2691 (sort commands 'string-lessp))))
2692 (type . function)
2693 (requires-pattern . 2))
2694 "Source for completing Emacs functions.")
2695 ;; (anything 'anything-c-source-emacs-functions)
2697 ;;; With abbrev expansion
2698 ;;; Similar to my exec-abbrev-cmd.el
2699 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2700 (defvar anything-c-function-abbrev-regexp nil
2701 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2702 Regexp built from the current `anything-pattern' interpreting it
2703 as abbreviation.
2704 Only for internal use.")
2706 (defun anything-c-match-function-by-abbrev (candidate)
2707 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2709 Abbreviations are made by taking the first character from each
2710 word in the function's name, e.g. \"bb\" is an abbrev for
2711 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2712 (string-match anything-c-function-abbrev-regexp candidate))
2714 (defvar anything-c-source-emacs-functions-with-abbrevs
2715 (append anything-c-source-emacs-functions
2716 '((match anything-c-match-function-by-abbrev
2717 anything-c-string-match))
2718 '((init . (lambda ()
2719 (defadvice anything-update
2720 (before anything-c-update-function-abbrev-regexp activate)
2721 (let ((char-list (append anything-pattern nil))
2722 (str "^"))
2723 (dolist (c char-list)
2724 (setq str (concat str (list c) "[^-]*-")))
2725 (setq str (concat (substring str 0 (1- (length str))) "$"))
2726 (setq anything-c-function-abbrev-regexp str))))))))
2727 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2729 (defvar anything-c-source-advice
2730 '((name . "Function Advice")
2731 (candidates . anything-c-advice-candidates)
2732 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
2733 ;; (real-to-display . anything-c-advice-real-to-display)
2736 (persistent-action . anything-c-advice-persistent-action)
2737 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
2738 ;; (anything 'anything-c-source-advice)
2739 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
2740 ;; (testadvice)
2742 (defun anything-c-advice-candidates ()
2743 (require 'advice)
2744 (loop for (fname) in ad-advised-functions
2745 for function = (intern fname)
2746 append
2747 (loop for class in ad-advice-classes append
2748 (loop for advice in (ad-get-advice-info-field function class)
2749 for enabled = (ad-advice-enabled advice)
2750 collect
2751 (cons (format "%s %s %s"
2752 (if enabled "Enabled " "Disabled")
2753 (propertize fname 'face 'font-lock-function-name-face)
2754 (ad-make-single-advice-docstring advice class nil))
2755 (list function class advice))))))
2757 (defun anything-c-advice-persistent-action (func-class-advice)
2758 (if current-prefix-arg
2759 (anything-c-advice-toggle func-class-advice)
2760 (describe-function (car func-class-advice))))
2762 (defun anything-c-advice-toggle (func-class-advice)
2763 (destructuring-bind (function class advice) func-class-advice
2764 (cond ((ad-advice-enabled advice)
2765 (ad-advice-set-enabled advice nil)
2766 (message "Disabled"))
2767 (t ;disabled
2768 (ad-advice-set-enabled advice t)
2769 (message "Enabled")))
2770 (ad-activate function)
2771 (and anything-in-persistent-action
2772 (anything-c-advice-update-current-display-string))))
2774 (defun anything-c-advice-update-current-display-string ()
2775 (anything-edit-current-selection
2776 (let ((newword (cond ((looking-at "Disabled") "Enabled")
2777 ((looking-at "Enabled") "Disabled")))
2778 realvalue)
2779 (when newword
2780 (delete-region (point) (progn (forward-word 1) (point)))
2781 (insert newword)))))
2783 ;;;###autoload
2784 (defun anything-manage-advice ()
2785 "Preconfigured `anything' to disable/enable function advices."
2786 (interactive)
2787 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
2789 ;;;; <Variable>
2790 ;;; Emacs variables
2791 (defvar anything-c-source-emacs-variables
2792 '((name . "Emacs Variables")
2793 (candidates . (lambda ()
2794 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
2795 (type . variable)
2796 (requires-pattern . 2))
2797 "Source for completing Emacs variables.")
2798 ;; (anything 'anything-c-source-emacs-variables)
2800 ;;;; <Bookmark>
2801 ;;; Bookmarks
2802 (eval-when-compile (require 'bookmark))
2803 (defvar anything-c-source-bookmarks
2804 '((name . "Bookmarks")
2805 (init . (lambda ()
2806 (require 'bookmark)))
2807 (candidates . bookmark-all-names)
2808 (type . bookmark))
2809 "See (info \"(emacs)Bookmarks\").")
2810 ;; (anything 'anything-c-source-bookmarks)
2812 ;;; bookmark-set
2813 (defvar anything-c-source-bookmark-set
2814 '((name . "Set Bookmark")
2815 (dummy)
2816 (action . bookmark-set))
2817 "See (info \"(emacs)Bookmarks\").")
2818 ;; (anything 'anything-c-source-bookmark-set)
2820 ;;; Visible Bookmarks
2821 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2824 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2825 (defvar anything-c-source-bm
2826 '((name . "Visible Bookmarks")
2827 (init . anything-c-bm-init)
2828 (candidates-in-buffer)
2829 (type . line))
2830 "Needs bm.el.
2832 http://www.nongnu.org/bm/")
2834 (defun anything-c-bm-init ()
2835 "Init function for `anything-c-source-bm'."
2836 (when (require 'bm nil t)
2837 (with-no-warnings
2838 (let ((bookmarks (bm-lists))
2839 (buf (anything-candidate-buffer 'global)))
2840 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
2841 '< :key 'overlay-start))
2842 (let ((start (overlay-start bm))
2843 (end (overlay-end bm))
2844 (annotation (or (overlay-get bm 'annotation) "")))
2845 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
2846 (let ((str (format "%5d: [%s]: %s\n"
2847 (line-number-at-pos start)
2848 annotation
2849 (buffer-substring start (1- end)))))
2850 (with-current-buffer buf (insert str))))))))))
2852 ;;; Special bookmarks
2853 (defvar anything-c-source-bookmarks-ssh
2854 '((name . "Bookmarks-ssh")
2855 (init . (lambda ()
2856 (require 'bookmark)))
2857 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
2858 (type . bookmark))
2859 "See (info \"(emacs)Bookmarks\").")
2860 ;; (anything 'anything-c-source-bookmarks-ssh)
2862 (defvar anything-c-source-bookmarks-su
2863 '((name . "Bookmarks-root")
2864 (init . (lambda ()
2865 (require 'bookmark)))
2866 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
2867 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
2869 (type . bookmark))
2870 "See (info \"(emacs)Bookmarks\").")
2871 ;; (anything 'anything-c-source-bookmarks-su)
2873 (defvar anything-c-source-bookmarks-local
2874 '((name . "Bookmarks-Local")
2875 (init . (lambda ()
2876 (require 'bookmark)))
2877 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
2878 (filtered-candidate-transformer
2879 anything-c-adaptive-sort
2880 anything-c-highlight-bookmark)
2881 (type . bookmark))
2882 "See (info \"(emacs)Bookmarks\").")
2883 ;; (anything 'anything-c-source-bookmarks-local)
2885 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
2886 (let* ((lis-all (bookmark-all-names))
2887 (lis-loc (cond (local (loop for i in lis-all
2888 unless (string-match "^(ssh)\\|^(su)" i)
2889 collect i))
2890 (su (loop for i in lis-all
2891 when (string-match "^(su)" i)
2892 collect i))
2893 (sudo (loop for i in lis-all
2894 when (string-match "^(sudo)" i)
2895 collect i))
2896 (ssh (loop for i in lis-all
2897 when (string-match "^(ssh)" i)
2898 collect i)))))
2899 (sort lis-loc 'string-lessp)))
2901 (defun anything-c-bookmark-root-logged-p ()
2902 (catch 'break
2903 (dolist (i (mapcar #'buffer-name (buffer-list)))
2904 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
2905 (throw 'break t)))))
2907 (defun anything-c-highlight-bookmark-su (files source)
2908 (if (anything-c-bookmark-root-logged-p)
2909 (anything-c-highlight-bookmark files source)
2910 (anything-c-highlight-not-logged files source)))
2912 (defun anything-c-highlight-not-logged (files source)
2913 (loop for i in files
2914 collect (propertize i 'face anything-c-bookmarks-face3)))
2916 (defun anything-c-highlight-bookmark (bookmarks source)
2917 "Used as `candidate-transformer' to colorize bookmarks.
2918 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2919 (loop for i in bookmarks
2920 for pred = (bookmark-get-filename i)
2921 for bufp = (and (fboundp 'bmkext-get-buffer-name)
2922 (bmkext-get-buffer-name i))
2923 for handlerp = (and (fboundp 'bookmark-get-handler)
2924 (bookmark-get-handler i))
2925 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
2926 (bmkext-w3m-bookmark-p i))
2927 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
2928 (bmkext-gnus-bookmark-p i))
2929 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
2930 (bmkext-man-bookmark-p i))
2931 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
2932 (bmkext-woman-bookmark-p i))
2933 for handlerp = (bookmark-get-handler i)
2934 for isannotation = (bookmark-get-annotation i)
2935 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
2936 ;; Add a * if bookmark have annotation
2937 if (and isannotation (not (string-equal isannotation "")))
2938 do (setq i (concat "*" i))
2939 ;; info buffers
2940 if (eq handlerp 'Info-bookmark-jump)
2941 collect (propertize i 'face 'anything-bmkext-info 'help-echo pred)
2942 ;; w3m buffers
2943 if isw3m
2944 collect (propertize i 'face 'anything-bmkext-w3m 'help-echo pred)
2945 ;; gnus buffers
2946 if isgnus
2947 collect (propertize i 'face 'anything-bmkext-gnus 'help-echo pred)
2948 ;; Man Woman
2949 if (or iswoman isman)
2950 collect (propertize i 'face 'anything-bmkext-man 'help-echo pred)
2951 ;; Addressbook
2952 if (and (not pred) isabook)
2953 collect (propertize i 'face '((:foreground "Tomato")))
2954 ;; directories
2955 if (and pred (file-directory-p pred))
2956 collect (propertize i 'face anything-c-bookmarks-face1 'help-echo pred)
2957 ;; regular files
2958 if (and pred (not (file-directory-p pred)) (file-exists-p pred)
2959 (not (or iswoman isman)))
2960 collect (propertize i 'face 'anything-bmkext-file 'help-echo pred)))
2963 ;;; Faces for bookmarks
2964 (defface anything-bmkext-info
2965 '((t (:foreground "green")))
2966 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2967 :group 'anything)
2969 (defface anything-bmkext-w3m
2970 '((t (:foreground "yellow")))
2971 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2972 :group 'anything)
2974 (defface anything-bmkext-gnus
2975 '((t (:foreground "magenta")))
2976 "*Face used for Gnus bookmarks."
2977 :group 'anything)
2979 (defface anything-bmkext-man
2980 '((t (:foreground "Orange4")))
2981 "*Face used for Woman/man bookmarks."
2982 :group 'anything)
2984 (defface anything-bmkext-no--file
2985 '((t (:foreground "grey")))
2986 "*Face used for non--file bookmarks."
2987 :group 'anything)
2989 (defface anything-bmkext-file
2990 '((t (:foreground "Deepskyblue2")))
2991 "*Face used for non--file bookmarks."
2992 :group 'anything)
2994 (defface anything-bookmarks-su-face '((t (:foreground "red")))
2995 "Face for su/sudo bookmarks."
2996 :group 'anything)
2998 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
2999 (defvar anything-c-bookmarks-face2 'anything-file-name)
3000 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
3003 ;;; Sources to filter bookmark-extensions bookmarks.
3004 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3005 ;; If you want to enable google-maps in addressbook you will need
3006 ;; Julien Danjou google-maps-el package available here:
3007 ;; http://julien.danjou.info/google-maps-el.html
3009 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
3010 "Return a filtered `bookmark-alist' sorted alphabetically."
3011 (loop
3012 with alist = (if args
3013 (apply #'(lambda (x) (funcall fn x)) args)
3014 (funcall fn))
3015 for i in alist
3016 for b = (car i)
3017 collect b into sa
3018 finally return (sort sa 'string-lessp)))
3020 ;; Addressbook
3021 (defvar anything-c-source-bmkext-addressbook
3022 '((name . "Bookmark Addressbook")
3023 (init . (lambda ()
3024 (require 'bookmark-extensions)
3025 (bookmark-maybe-load-default-file)))
3026 (candidates . anything-c-bmkext-addressbook-setup-alist)
3027 (persistent-action
3028 . (lambda (candidate)
3029 (let ((bmk (anything-bookmark-get-bookmark-from-name
3030 candidate)))
3031 (bookmark--jump-via bmk 'pop-to-buffer))))
3032 (persistent-help . "Show contact - Prefix with C-u to append")
3033 (filtered-candidate-transformer
3034 anything-c-adaptive-sort
3035 anything-c-highlight-bookmark)
3036 (action . (("Show person's data"
3037 . (lambda (candidate)
3038 (let ((bmk (anything-bookmark-get-bookmark-from-name
3039 candidate))
3040 (current-prefix-arg anything-current-prefix-arg))
3041 (bookmark-jump bmk))))
3042 ("Send Mail"
3043 . (lambda (candidate)
3044 (let ((bmk (anything-bookmark-get-bookmark-from-name
3045 candidate)))
3046 (if anything-current-prefix-arg
3047 (addressbook-set-mail-buffer1 bmk 'append)
3048 (addressbook-set-mail-buffer1 bmk)))))
3049 ("Edit Bookmark"
3050 . (lambda (candidate)
3051 (let ((bmk (anything-bookmark-get-bookmark-from-name
3052 candidate)))
3053 (addressbook-bookmark-edit
3054 (assoc bmk bookmark-alist)))))
3055 ("Insert Email at point"
3056 . (lambda (candidate)
3057 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3058 candidate))
3059 (mlist (split-string
3060 (assoc-default
3061 'email (assoc bmk bookmark-alist))
3062 ", ")))
3063 (insert
3064 (if (> (length mlist) 1)
3065 (anything-comp-read
3066 "Insert Mail Address: " mlist :must-match t)
3067 (car mlist))))))
3068 ("Show annotation"
3069 . (lambda (candidate)
3070 (let ((bmk (anything-bookmark-get-bookmark-from-name
3071 candidate)))
3072 (bookmark-show-annotation bmk))))
3073 ("Edit annotation"
3074 . (lambda (candidate)
3075 (let ((bmk (anything-bookmark-get-bookmark-from-name
3076 candidate)))
3077 (bookmark-edit-annotation bmk))))
3078 ("Show Google map" . (lambda (candidate)
3079 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3080 candidate))
3081 (full-bmk (assoc bmk bookmark-alist)))
3082 (addressbook-google-map full-bmk))))))))
3085 (defun anything-c-bmkext-addressbook-setup-alist ()
3086 "Specialized filter function for bookmarks w3m."
3087 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
3089 ;; W3m
3090 (defvar anything-c-source-bookmark-w3m
3091 '((name . "Bookmark W3m")
3092 (init . (lambda ()
3093 (require 'bookmark-extensions)
3094 (bookmark-maybe-load-default-file)))
3095 (candidates . anything-c-bookmark-w3m-setup-alist)
3096 (filtered-candidate-transformer
3097 anything-c-adaptive-sort
3098 anything-c-highlight-bookmark)
3099 (type . bookmark)))
3100 ;; (anything 'anything-c-source-bookmark-w3m)
3102 (defun anything-c-bookmark-w3m-setup-alist ()
3103 "Specialized filter function for bookmarks w3m."
3104 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
3106 ;; Images
3107 (defvar anything-c-source-bookmark-images
3108 '((name . "Bookmark Images")
3109 (init . (lambda ()
3110 (require 'bookmark-extensions)
3111 (bookmark-maybe-load-default-file)))
3112 (candidates . anything-c-bookmark-images-setup-alist)
3113 (filtered-candidate-transformer
3114 anything-c-adaptive-sort
3115 anything-c-highlight-bookmark)
3116 (type . bookmark)))
3117 ;; (anything 'anything-c-source-bookmark-images)
3119 (defun anything-c-bookmark-images-setup-alist ()
3120 "Specialized filter function for images bookmarks."
3121 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
3123 ;; Woman Man
3124 (defvar anything-c-source-bookmark-man
3125 '((name . "Bookmark Woman&Man")
3126 (init . (lambda ()
3127 (require 'bookmark-extensions)
3128 (bookmark-maybe-load-default-file)))
3129 (candidates . anything-c-bookmark-man-setup-alist)
3130 (filtered-candidate-transformer
3131 anything-c-adaptive-sort
3132 anything-c-highlight-bookmark)
3133 (type . bookmark)))
3134 ;; (anything 'anything-c-source-bookmark-man)
3136 (defun anything-c-bookmark-man-setup-alist ()
3137 "Specialized filter function for bookmarks w3m."
3138 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
3139 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
3141 ;; Gnus
3142 (defvar anything-c-source-bookmark-gnus
3143 '((name . "Bookmark Gnus")
3144 (init . (lambda ()
3145 (require 'bookmark-extensions)
3146 (bookmark-maybe-load-default-file)))
3147 (candidates . anything-c-bookmark-gnus-setup-alist)
3148 (filtered-candidate-transformer
3149 anything-c-adaptive-sort
3150 anything-c-highlight-bookmark)
3151 (type . bookmark)))
3152 ;; (anything 'anything-c-source-bookmark-gnus)
3154 (defun anything-c-bookmark-gnus-setup-alist ()
3155 "Specialized filter function for bookmarks gnus."
3156 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
3158 ;; Info
3159 (defvar anything-c-source-bookmark-info
3160 '((name . "Bookmark Info")
3161 (init . (lambda ()
3162 (require 'bookmark-extensions)
3163 (bookmark-maybe-load-default-file)))
3164 (candidates . anything-c-bookmark-info-setup-alist)
3165 (filtered-candidate-transformer
3166 anything-c-adaptive-sort
3167 anything-c-highlight-bookmark)
3168 (type . bookmark)))
3169 ;; (anything 'anything-c-source-bookmark-info)
3171 (defun anything-c-bookmark-info-setup-alist ()
3172 "Specialized filter function for bookmarks info."
3173 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
3175 ;; Local Files&directories
3176 (defvar anything-c-source-bookmark-files&dirs
3177 '((name . "Bookmark Files&Directories")
3178 (init . (lambda ()
3179 (require 'bookmark-extensions)
3180 (bookmark-maybe-load-default-file)))
3181 (candidates . anything-c-bookmark-local-files-setup-alist)
3182 (filtered-candidate-transformer
3183 anything-c-adaptive-sort
3184 anything-c-highlight-bookmark)
3185 (type . bookmark)))
3186 ;; (anything 'anything-c-source-bookmark-files&dirs)
3188 (defun anything-c-bookmark-local-files-setup-alist ()
3189 "Specialized filter function for bookmarks locals files."
3190 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
3192 ;; Su Files&directories
3193 (defvar anything-c-source-bookmark-su-files&dirs
3194 '((name . "Bookmark Root-Files&Directories")
3195 (init . (lambda ()
3196 (require 'bookmark-extensions)
3197 (bookmark-maybe-load-default-file)))
3198 (candidates . anything-c-bookmark-su-files-setup-alist)
3199 (filtered-candidate-transformer
3200 anything-c-adaptive-sort
3201 anything-c-highlight-bookmark-su)
3202 (type . bookmark)))
3203 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3205 (defun anything-c-bookmark-su-files-setup-alist ()
3206 "Specialized filter function for bookmarks su/sudo files."
3207 (loop
3208 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3209 for i in l
3210 for isfile = (bookmark-get-filename i)
3211 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3212 (save-match-data
3213 (string-match tramp-file-name-regexp isfile)))
3214 for issu = (and istramp
3215 (string-match bmkext-su-or-sudo-regexp isfile))
3216 if issu
3217 collect i))
3219 ;; Ssh Files&directories
3220 (defvar anything-c-source-bookmark-ssh-files&dirs
3221 '((name . "Bookmark Ssh-Files&Directories")
3222 (init . (lambda ()
3223 (require 'bookmark-extensions)
3224 (bookmark-maybe-load-default-file)))
3225 (candidates . anything-c-bookmark-ssh-files-setup-alist)
3226 (filtered-candidate-transformer . anything-c-adaptive-sort)
3227 (type . bookmark)))
3228 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3230 (defun anything-c-bookmark-ssh-files-setup-alist ()
3231 "Specialized filter function for bookmarks ssh files."
3232 (loop
3233 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3234 for i in l
3235 for isfile = (bookmark-get-filename i)
3236 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3237 (save-match-data
3238 (string-match tramp-file-name-regexp isfile)))
3239 for isssh = (and istramp
3240 (string-match "/ssh:" isfile))
3241 if isssh
3242 collect i))
3245 ;; All bookmark-extensions sources.
3246 ;;;###autoload
3247 (defun anything-bookmark-ext ()
3248 "Preconfigured `anything' for bookmark-extensions sources.
3249 Needs bookmark-ext.el
3251 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3252 (interactive)
3253 (anything '(anything-c-source-bookmark-files&dirs
3254 anything-c-source-bookmark-w3m
3255 anything-c-source-bmkext-addressbook
3256 anything-c-source-bookmark-gnus
3257 anything-c-source-bookmark-info
3258 anything-c-source-bookmark-man
3259 anything-c-source-bookmark-images
3260 anything-c-source-bookmark-su-files&dirs
3261 anything-c-source-bookmark-ssh-files&dirs)
3262 nil "SearchBookmark: " nil nil "*anything bmkext*"))
3265 ;; Firefox bookmarks
3266 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
3267 ;; (only for firefox versions >=3)
3268 ;; To achieve that, open about:config in firefox and double click on this line to enable value
3269 ;; to true:
3270 ;; user_pref("browser.bookmarks.autoExportHTML", false);
3271 ;; You should have now:
3272 ;; user_pref("browser.bookmarks.autoExportHTML", true);
3274 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
3275 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3277 (defun anything-get-firefox-user-init-dir ()
3278 "Guess the default Firefox user directory name."
3279 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
3280 (moz-user-dir (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
3281 (goto-char (point-min))
3282 (when (search-forward "Path=" nil t)
3283 (buffer-substring-no-properties (point) (point-at-eol))))))
3284 (file-name-as-directory (concat moz-dir moz-user-dir))))
3286 (defun anything-guess-firefox-bookmark-file ()
3287 "Return the path of the Firefox bookmarks file."
3288 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
3290 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
3291 "Parse html bookmark FILE and return an alist with (title . url) as elements."
3292 (let (bookmarks-alist url title)
3293 (with-temp-buffer
3294 (insert-file-contents file)
3295 (goto-char (point-min))
3296 (while (not (eobp))
3297 (forward-line)
3298 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
3299 (beginning-of-line)
3300 (when (re-search-forward url-regexp nil t)
3301 (setq url (concat "\"" (match-string 0))))
3302 (beginning-of-line)
3303 (when (re-search-forward bmk-regexp nil t)
3304 (setq title (match-string 1)))
3305 (push (cons title url) bookmarks-alist))))
3306 (nreverse bookmarks-alist)))
3309 (defvar anything-c-firefox-bookmarks-alist nil)
3310 (defvar anything-c-source-firefox-bookmarks
3311 '((name . "Firefox Bookmarks")
3312 (init . (lambda ()
3313 (setq anything-c-firefox-bookmarks-alist
3314 (anything-html-bookmarks-to-alist
3315 (anything-guess-firefox-bookmark-file)
3316 anything-firefox-bookmark-url-regexp
3317 anything-firefox-bookmarks-regexp))))
3318 (candidates . (lambda ()
3319 (mapcar #'car
3320 anything-c-firefox-bookmarks-alist)))
3321 (filtered-candidate-transformer
3322 anything-c-adaptive-sort
3323 anything-c-highlight-firefox-bookmarks)
3324 (action . (("Browse Url Firefox" . (lambda (candidate)
3325 (browse-url-firefox
3326 (anything-c-firefox-bookmarks-get-value candidate))))
3327 ("Browse Url w3m" . (lambda (candidate)
3328 (w3m-browse-url
3329 (anything-c-firefox-bookmarks-get-value candidate))))
3330 ("Copy Url" . (lambda (elm)
3331 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
3333 ;; (anything 'anything-c-source-firefox-bookmarks)
3335 (defun anything-c-firefox-bookmarks-get-value (elm)
3336 (replace-regexp-in-string "\"" ""
3337 (cdr (assoc elm
3338 anything-c-firefox-bookmarks-alist))))
3341 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
3342 (loop for i in bookmarks
3343 collect (propertize i
3344 'face '((:foreground "YellowGreen"))
3345 'help-echo (anything-c-firefox-bookmarks-get-value i))))
3347 ;; W3m bookmark
3348 (eval-when-compile (require 'w3m-bookmark nil t))
3349 (unless (and (require 'w3m nil t)
3350 (require 'w3m-bookmark nil t))
3351 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
3354 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
3355 "Face for w3m bookmarks" :group 'anything)
3357 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3358 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
3359 (defvar anything-c-w3m-bookmarks-alist nil)
3360 (defvar anything-c-source-w3m-bookmarks
3361 '((name . "W3m Bookmarks")
3362 (init . (lambda ()
3363 (setq anything-c-w3m-bookmarks-alist
3364 (anything-html-bookmarks-to-alist
3365 w3m-bookmark-file
3366 anything-w3m-bookmark-url-regexp
3367 anything-w3m-bookmarks-regexp))))
3368 (candidates . (lambda ()
3369 (mapcar #'car anything-c-w3m-bookmarks-alist)))
3370 (filtered-candidate-transformer
3371 anything-c-adaptive-sort
3372 anything-c-highlight-w3m-bookmarks)
3373 (action . (("Browse Url" . (lambda (candidate)
3374 (anything-c-w3m-browse-bookmark candidate)))
3375 ("Copy Url" . (lambda (elm)
3376 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
3377 ("Browse Url Firefox" . (lambda (candidate)
3378 (anything-c-w3m-browse-bookmark candidate t)))
3379 ("Delete Bookmark" . (lambda (candidate)
3380 (anything-c-w3m-delete-bookmark candidate)))
3381 ("Rename Bookmark" . (lambda (candidate)
3382 (anything-c-w3m-rename-bookmark candidate)))))
3383 (persistent-action . (lambda (candidate)
3384 (if current-prefix-arg
3385 (anything-c-w3m-browse-bookmark candidate t)
3386 (anything-c-w3m-browse-bookmark candidate nil t))))
3387 (persistent-help . "Open URL with emacs-w3m in new tab / \
3388 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
3389 "Needs w3m and emacs-w3m.
3391 http://w3m.sourceforge.net/
3392 http://emacs-w3m.namazu.org/")
3394 ;; (anything 'anything-c-source-w3m-bookmarks)
3396 (defun anything-c-w3m-bookmarks-get-value (elm)
3397 (replace-regexp-in-string
3398 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
3400 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
3401 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
3402 (arg (and (eq fn 'w3m-browse-url) new-tab)))
3403 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
3405 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
3406 (loop for i in bookmarks
3407 collect (propertize
3408 i 'face 'anything-w3m-bookmarks-face
3409 'help-echo (anything-c-w3m-bookmarks-get-value i))))
3412 (defun anything-c-w3m-delete-bookmark (elm)
3413 (save-excursion
3414 (find-file-literally w3m-bookmark-file)
3415 (goto-char (point-min))
3416 (when (re-search-forward elm nil t)
3417 (beginning-of-line)
3418 (delete-region (point)
3419 (line-end-position))
3420 (delete-blank-lines))
3421 (save-buffer (current-buffer))
3422 (kill-buffer (current-buffer))))
3424 (defun anything-c-w3m-rename-bookmark (elm)
3425 (let* ((old-title (replace-regexp-in-string ">" "" elm))
3426 (new-title (read-string "NewTitle: " old-title)))
3427 (save-excursion
3428 (find-file-literally w3m-bookmark-file)
3429 (goto-char (point-min))
3430 (when (re-search-forward (concat elm "<") nil t)
3431 (goto-char (1- (point)))
3432 (delete-char (- (length old-title)))
3433 (insert new-title))
3434 (save-buffer (current-buffer))
3435 (kill-buffer (current-buffer)))))
3437 ;;;; <Library>
3438 ;;; Elisp library scan
3439 (defvar anything-c-source-elisp-library-scan
3440 '((name . "Elisp libraries (Scan)")
3441 (init . (anything-c-elisp-library-scan-init))
3442 (candidates-in-buffer)
3443 (action ("Find library" . (lambda (candidate)
3444 (find-file (find-library-name candidate))))
3445 ("Find library other window" . (lambda (candidate)
3446 (find-file-other-window (find-library-name candidate))))
3447 ("Load library" . (lambda (candidate)
3448 (load-library candidate))))))
3449 ;; (anything 'anything-c-source-elisp-library-scan)
3451 (defun anything-c-elisp-library-scan-init ()
3452 "Init anything buffer status."
3453 (let ((anything-buffer (anything-candidate-buffer 'global))
3454 (library-list (anything-c-elisp-library-scan-list)))
3455 (with-current-buffer anything-buffer
3456 (dolist (library library-list)
3457 (insert (format "%s\n" library))))))
3459 (defun anything-c-elisp-library-scan-list (&optional dirs string)
3460 "Do completion for file names passed to `locate-file'.
3461 DIRS is directory to search path.
3462 STRING is string to match."
3463 ;; Use `load-path' as path when ignore `dirs'.
3464 (or dirs (setq dirs load-path))
3465 ;; Init with blank when ignore `string'.
3466 (or string (setq string ""))
3467 ;; Get library list.
3468 (let ((string-dir (file-name-directory string))
3469 ;; File regexp that suffix match `load-file-rep-suffixes'.
3470 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
3471 name
3472 names)
3473 (dolist (dir dirs)
3474 (unless dir
3475 (setq dir default-directory))
3476 (if string-dir
3477 (setq dir (expand-file-name string-dir dir)))
3478 (when (file-directory-p dir)
3479 (dolist (file (file-name-all-completions
3480 (file-name-nondirectory string) dir))
3481 ;; Suffixes match `load-file-rep-suffixes'.
3482 (setq name (if string-dir (concat string-dir file) file))
3483 (if (string-match match-regexp name)
3484 (add-to-list 'names name)))))
3485 names))
3487 ;;;; <Programming>
3488 ;;; Imenu
3489 (defvar anything-c-imenu-delimiter " / ")
3491 (defvar anything-c-imenu-index-filter nil)
3492 (make-variable-buffer-local 'anything-c-imenu-index-filter)
3494 (defvar anything-c-cached-imenu-alist nil)
3495 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
3497 (defvar anything-c-cached-imenu-candidates nil)
3498 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
3500 (defvar anything-c-cached-imenu-tick nil)
3501 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
3503 (eval-when-compile (require 'imenu))
3504 (setq imenu-auto-rescan t)
3506 (defun anything-imenu-create-candidates (entry)
3507 "Create candidates with ENTRY."
3508 (if (listp (cdr entry))
3509 (mapcan (lambda (sub)
3510 (if (consp (cdr sub))
3511 (mapcar
3512 (lambda (subentry)
3513 (concat (car entry) anything-c-imenu-delimiter subentry))
3514 (anything-imenu-create-candidates sub))
3515 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
3516 (cdr entry))
3517 (list entry)))
3519 (defvar anything-c-source-imenu
3520 '((name . "Imenu")
3521 (init . (lambda () (require 'imenu)))
3522 (candidates . anything-c-imenu-candidates)
3523 (persistent-action . (lambda (elm)
3524 (anything-c-imenu-default-action elm)
3525 (unless (fboundp 'semantic-imenu-tag-overlay)
3526 (anything-match-line-color-current-line))))
3527 (persistent-help . "Show this entry")
3528 (action . anything-c-imenu-default-action))
3529 "See (info \"(emacs)Imenu\")")
3531 ;; (anything 'anything-c-source-imenu)
3533 (defun anything-c-imenu-candidates ()
3534 (with-current-buffer anything-current-buffer
3535 (let ((tick (buffer-modified-tick)))
3536 (if (eq anything-c-cached-imenu-tick tick)
3537 anything-c-cached-imenu-candidates
3538 (setq imenu--index-alist nil)
3539 (setq anything-c-cached-imenu-tick tick
3540 anything-c-cached-imenu-candidates
3541 (ignore-errors
3542 (mapcan
3543 'anything-imenu-create-candidates
3544 (setq anything-c-cached-imenu-alist
3545 (let ((index (imenu--make-index-alist)))
3546 (if anything-c-imenu-index-filter
3547 (funcall anything-c-imenu-index-filter index)
3548 index))))))
3549 (setq anything-c-cached-imenu-candidates
3550 (mapcar #'(lambda (x)
3551 (if (stringp x)
3553 (car x)))
3554 anything-c-cached-imenu-candidates))))))
3556 (setq imenu-default-goto-function 'imenu-default-goto-function)
3557 (defun anything-c-imenu-default-action (elm)
3558 "The default action for `anything-c-source-imenu'."
3559 (let ((path (split-string elm anything-c-imenu-delimiter))
3560 (alist anything-c-cached-imenu-alist))
3561 (if (> (length path) 1)
3562 (progn
3563 (setq alist (assoc (car path) alist))
3564 (setq elm (cadr path))
3565 (imenu (assoc elm alist)))
3566 (imenu (assoc elm alist)))))
3568 ;;; Ctags
3569 (defvar anything-c-ctags-modes
3570 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3571 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3572 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
3574 (defun anything-c-source-ctags-init ()
3575 (when (and buffer-file-name
3576 (memq major-mode anything-c-ctags-modes)
3577 (anything-current-buffer-is-modified))
3578 (with-current-buffer (anything-candidate-buffer 'local)
3579 (call-process-shell-command
3580 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
3581 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
3582 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
3583 nil (current-buffer))
3584 (goto-char (point-min))
3585 (forward-line 2)
3586 (delete-region (point-min) (point))
3587 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
3588 for lineno-start = (point)
3589 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
3591 (beginning-of-line)
3592 (insert (format "%5s:" lineno))
3593 (search-forward "\177" (point-at-eol) t)
3594 (delete-region (1- (point)) (point-at-eol))
3595 (forward-line 1)))))
3597 (defvar anything-c-source-ctags
3598 '((name . "Exuberant ctags")
3599 (init . anything-c-source-ctags-init)
3600 (candidates-in-buffer)
3601 (adjust)
3602 (type . line))
3603 "Needs Exuberant Ctags.
3605 http://ctags.sourceforge.net/")
3606 ;; (anything 'anything-c-source-ctags)
3608 ;; Semantic
3609 (eval-when-compile (require 'semantic nil t))
3610 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
3611 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
3612 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
3613 (defvar anything-semantic-candidates nil)
3615 (defun anything-semantic-construct-candidates (tags depth)
3616 (when (require 'semantic nil t)
3617 (apply 'append
3618 (mapcar (lambda (tag)
3619 (if (listp tag)
3620 (let ((type (semantic-tag-type tag))
3621 (class (semantic-tag-class tag)))
3622 (if (or (and (stringp type)
3623 (or (string= type "class")
3624 (string= type "namespace")))
3625 (eq class 'function)
3626 (eq class 'variable))
3627 (cons (cons (concat (make-string (* depth 2) ?\s)
3628 (semantic-format-tag-summarize tag nil t)) tag)
3629 (anything-semantic-construct-candidates (semantic-tag-components tag)
3630 (1+ depth)))))))
3631 tags))))
3633 (defun anything-semantic-default-action (candidate)
3634 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
3635 (semantic-go-to-tag tag)))
3637 (defvar anything-c-source-semantic
3638 '((name . "Semantic Tags")
3639 (init . (lambda ()
3640 (setq anything-semantic-candidates
3641 (ignore-errors (anything-semantic-construct-candidates (semantic-fetch-tags) 0)))))
3642 (candidates . (lambda ()
3643 (if anything-semantic-candidates
3644 (mapcar 'car anything-semantic-candidates))))
3645 (persistent-action . (lambda (elm)
3646 (anything-semantic-default-action elm)
3647 (anything-match-line-color-current-line)))
3648 (persistent-help . "Show this entry")
3649 (action . anything-semantic-default-action)
3650 "Needs semantic in CEDET.
3652 http://cedet.sourceforge.net/semantic.shtml
3653 http://cedet.sourceforge.net/"))
3655 ;; (anything 'anything-c-source-semantic)
3657 ;;; Function is called by
3658 ;;;###autoload
3659 (defun anything-simple-call-tree ()
3660 "Preconfigured `anything' for simple-call-tree. List function relationships.
3662 Needs simple-call-tree.el.
3663 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
3664 (interactive)
3665 (anything-other-buffer
3666 '(anything-c-source-simple-call-tree-functions-callers
3667 anything-c-source-simple-call-tree-callers-functions)
3668 "*anything simple-call-tree*"))
3670 (defvar anything-c-source-simple-call-tree-functions-callers
3671 '((name . "Function is called by")
3672 (init . anything-c-simple-call-tree-functions-callers-init)
3673 (multiline)
3674 (candidates . anything-c-simple-call-tree-candidates)
3675 (persistent-action . anything-c-simple-call-tree-persistent-action)
3676 (persistent-help . "Show function definitions by rotation")
3677 (action ("Find definition selected by persistent-action" .
3678 anything-c-simple-call-tree-find-definition)))
3679 "Needs simple-call-tree.el.
3680 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3682 (defvar anything-c-simple-call-tree-tick nil)
3683 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
3684 (defun anything-c-simple-call-tree-analyze-maybe ()
3685 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
3686 (simple-call-tree-analyze)
3687 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
3689 (defun anything-c-simple-call-tree-init-base (function message)
3690 (require 'simple-call-tree)
3691 (with-no-warnings
3692 (when (anything-current-buffer-is-modified)
3693 (anything-c-simple-call-tree-analyze-maybe)
3694 (let ((list (funcall function simple-call-tree-alist)))
3695 (with-current-buffer (anything-candidate-buffer 'local)
3696 (dolist (entry list)
3697 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
3698 (insert (car entry) message
3699 (if (string= funcs " ")
3700 " no functions."
3701 funcs)
3702 "\n\n"))))))))
3704 (defun anything-c-simple-call-tree-functions-callers-init ()
3705 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert " is called by\n"))
3707 (defun anything-c-simple-call-tree-candidates ()
3708 (with-current-buffer (anything-candidate-buffer)
3709 (split-string (buffer-string) "\n\n")))
3711 (defvar anything-c-simple-call-tree-related-functions nil)
3712 (defvar anything-c-simple-call-tree-function-index 0)
3713 (defun anything-c-simple-call-tree-persistent-action (candidate)
3714 (unless (eq last-command 'anything-execute-persistent-action)
3715 (setq anything-c-simple-call-tree-related-functions
3716 (delete "no functions."
3717 (split-string
3718 (replace-regexp-in-string " \\| is called by\\| calls " "" candidate)
3719 "\n")))
3720 (setq anything-c-simple-call-tree-function-index -1))
3721 (incf anything-c-simple-call-tree-function-index)
3722 (anything-c-simple-call-tree-find-definition candidate))
3724 (defun anything-c-simple-call-tree-find-definition (candidate)
3725 (find-function (intern
3726 (nth (mod anything-c-simple-call-tree-function-index
3727 (length anything-c-simple-call-tree-related-functions))
3728 anything-c-simple-call-tree-related-functions))))
3730 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3732 ;;; Function calls
3733 (defvar anything-c-source-simple-call-tree-callers-functions
3734 '((name . "Function calls")
3735 (init . anything-c-simple-call-tree-callers-functions-init)
3736 (multiline)
3737 (candidates . anything-c-simple-call-tree-candidates)
3738 (persistent-action . anything-c-simple-call-tree-persistent-action)
3739 (persistent-help . "Show function definitions by rotation")
3740 (action ("Find definition selected by persistent-action" .
3741 anything-c-simple-call-tree-find-definition)))
3742 "Needs simple-call-tree.el.
3743 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3745 (defun anything-c-simple-call-tree-callers-functions-init ()
3746 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
3748 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3750 ;;; Commands/Options with doc
3751 (defvar anything-c-auto-document-data nil)
3752 (make-variable-buffer-local 'anything-c-auto-document-data)
3753 (defvar anything-c-source-commands-and-options-in-file
3754 '((name . "Commands/Options in file")
3755 (header-name
3756 . (lambda (x) (format "Commands/Options in %s"
3757 (buffer-local-value 'buffer-file-name anything-current-buffer))))
3758 (candidates . anything-command-and-options-candidates)
3759 (multiline)
3760 (action . imenu))
3761 "List Commands and Options with doc. It needs auto-document.el .
3763 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3765 (eval-when-compile (require 'auto-document nil t))
3766 (defun anything-command-and-options-candidates ()
3767 (with-current-buffer anything-current-buffer
3768 (when (and (require 'auto-document nil t)
3769 (eq major-mode 'emacs-lisp-mode)
3770 (or (anything-current-buffer-is-modified)
3771 (not anything-c-auto-document-data)))
3772 (or imenu--index-alist (imenu--make-index-alist t))
3773 (setq anything-c-auto-document-data
3774 (destructuring-bind (commands options)
3775 (adoc-construct anything-current-buffer)
3776 (append
3777 (loop for (command . doc) in commands
3778 for cmdname = (symbol-name command)
3779 collect
3780 (cons (format "Command: %s\n %s"
3781 (propertize cmdname 'face font-lock-function-name-face)
3782 (adoc-first-line doc))
3783 (assoc cmdname imenu--index-alist)))
3784 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
3785 for (option doc default) in options
3786 for optname = (symbol-name option)
3787 collect
3788 (cons (format "Option: %s\n %s\n default = %s"
3789 (propertize optname 'face font-lock-variable-name-face)
3790 (adoc-first-line doc)
3791 (adoc-prin1-to-string default))
3792 (assoc optname
3793 var-alist)))))))
3794 anything-c-auto-document-data))
3796 ;; (anything 'anything-c-source-commands-and-options-in-file)
3798 ;;;; <Color and Face>
3799 ;;; Customize Face
3800 (defvar anything-c-source-customize-face
3801 '((name . "Customize Face")
3802 (init . (lambda ()
3803 (unless (anything-candidate-buffer)
3804 (save-window-excursion (list-faces-display))
3805 (anything-candidate-buffer (get-buffer "*Faces*")))))
3806 (candidates-in-buffer)
3807 (get-line . buffer-substring)
3808 (action . (lambda (line)
3809 (customize-face (intern (car (split-string line))))))
3810 (requires-pattern . 3))
3811 "See (info \"(emacs)Faces\")")
3812 ;; (anything 'anything-c-source-customize-face)
3814 ;; Color
3815 (defvar anything-c-source-colors
3816 '((name . "Colors")
3817 (init . (lambda () (unless (anything-candidate-buffer)
3818 (save-window-excursion (list-colors-display))
3819 (anything-candidate-buffer (get-buffer "*Colors*")))))
3820 (candidates-in-buffer)
3821 (get-line . buffer-substring)
3822 (action ("Copy Name" . (lambda (candidate)
3823 (kill-new (anything-c-colors-get-name candidate))))
3824 ("Copy RGB" . (lambda (candidate)
3825 (kill-new (anything-c-colors-get-rgb candidate))))
3826 ("Insert Name" . (lambda (candidate)
3827 (with-current-buffer anything-current-buffer
3828 (insert (anything-c-colors-get-name candidate)))))
3829 ("Insert RGB" . (lambda (candidate)
3830 (with-current-buffer anything-current-buffer
3831 (insert (anything-c-colors-get-rgb candidate))))))))
3832 ;; (anything 'anything-c-source-colors)
3834 (defun anything-c-colors-get-name (candidate)
3835 "Get color name."
3836 (replace-regexp-in-string
3837 " " ""
3838 (with-temp-buffer
3839 (insert (capitalize candidate))
3840 (goto-char (point-min))
3841 (search-forward-regexp "\\s-\\{2,\\}")
3842 (delete-region (point) (point-max))
3843 (buffer-string))))
3845 (defun anything-c-colors-get-rgb (candidate)
3846 "Get color RGB."
3847 (replace-regexp-in-string
3848 " " ""
3849 (with-temp-buffer
3850 (insert (capitalize candidate))
3851 (goto-char (point-max))
3852 (search-backward-regexp "\\s-\\{2,\\}")
3853 (delete-region (point) (point-min))
3854 (buffer-string))))
3856 ;;;; <Search Engine>
3857 ;;; Tracker desktop search
3858 (defvar anything-c-source-tracker-search
3859 '((name . "Tracker Search")
3860 (candidates . (lambda ()
3861 (start-process "tracker-search-process" nil
3862 "tracker-search"
3863 anything-pattern)))
3864 (type . file)
3865 (requires-pattern . 3)
3866 (delayed))
3867 "Source for retrieving files matching the current input pattern
3868 with the tracker desktop search.")
3869 ;; (anything 'anything-c-source-tracker-search)
3871 ;;; Spotlight (MacOS X desktop search)
3872 (defvar anything-c-source-mac-spotlight
3873 '((name . "mdfind")
3874 (candidates . (lambda ()
3875 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
3876 (type . file)
3877 (requires-pattern . 3)
3878 (delayed))
3879 "Source for retrieving files via Spotlight's command line
3880 utility mdfind.")
3881 ;; (anything 'anything-c-source-mac-spotlight)
3884 ;;;; <Kill ring>
3885 ;;; Kill ring
3886 (defvar anything-c-source-kill-ring
3887 '((name . "Kill Ring")
3888 (init . (lambda () (anything-attrset 'last-command last-command)))
3889 (candidates . anything-c-kill-ring-candidates)
3890 (action . anything-c-kill-ring-action)
3891 (last-command)
3892 (migemo)
3893 (multiline))
3894 "Source for browse and insert contents of kill-ring.")
3896 (defun anything-c-kill-ring-candidates ()
3897 (loop for kill in kill-ring
3898 unless (or (< (length kill) anything-kill-ring-threshold)
3899 (string-match "^[\\s\\t]+$" kill))
3900 collect kill))
3902 (defun anything-c-kill-ring-action (str)
3903 "Insert STR in `kill-ring' and set STR to the head.
3904 If this action is executed just after `yank', replace with STR as yanked string."
3905 (setq kill-ring (delete str kill-ring))
3906 (if (not (eq (anything-attr 'last-command) 'yank))
3907 (insert-for-yank str)
3908 ;; from `yank-pop'
3909 (let ((inhibit-read-only t)
3910 (before (< (point) (mark t))))
3911 (if before
3912 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
3913 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
3914 (setq yank-undo-function nil)
3915 (set-marker (mark-marker) (point) (current-buffer))
3916 (insert-for-yank str)
3917 ;; Set the window start back where it was in the yank command,
3918 ;; if possible.
3919 (set-window-start (selected-window) yank-window-start t)
3920 (if before
3921 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3922 ;; It is cleaner to avoid activation, even though the command
3923 ;; loop would deactivate the mark because we inserted text.
3924 (goto-char (prog1 (mark t)
3925 (set-marker (mark-marker) (point) (current-buffer)))))))
3926 (kill-new str))
3928 ;; (anything 'anything-c-source-kill-ring)
3930 ;;;; <Mark ring>
3931 ;; DO NOT include these sources in `anything-sources' use
3932 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
3933 ;; `anything-all-mark-rings' instead.
3935 (defun anything-c-source-mark-ring-candidates ()
3936 (flet ((get-marks (pos)
3937 (save-excursion
3938 (goto-char pos)
3939 (beginning-of-line)
3940 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3941 (when (string= "" line)
3942 (setq line "<EMPTY LINE>"))
3943 (format "%7d: %s" (line-number-at-pos) line)))))
3944 (with-current-buffer anything-current-buffer
3945 (loop
3946 with marks = (cons (mark-marker) mark-ring)
3947 with recip = nil
3948 for i in marks
3949 for m = (get-marks i)
3950 unless (member m recip)
3951 collect m into recip
3952 finally return recip))))
3954 (defvar anything-mark-ring-cache nil)
3955 (defvar anything-c-source-mark-ring
3956 '((name . "mark-ring")
3957 (init . (lambda ()
3958 (setq anything-mark-ring-cache
3959 (ignore-errors (anything-c-source-mark-ring-candidates)))))
3960 (candidates . (lambda ()
3961 (anything-aif anything-mark-ring-cache
3962 it)))
3963 (action . (("Goto line" . (lambda (candidate)
3964 (anything-goto-line (string-to-number candidate))))))
3965 (persistent-action . (lambda (candidate)
3966 (anything-goto-line (string-to-number candidate))
3967 (anything-match-line-color-current-line)))
3968 (persistent-help . "Show this line")))
3970 ;; (anything 'anything-c-source-mark-ring)
3972 ;;;###autoload
3973 (defun anything-mark-ring ()
3974 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3975 (interactive)
3976 (anything 'anything-c-source-mark-ring))
3978 ;;; Global-mark-ring
3979 (defvar anything-c-source-global-mark-ring
3980 '((name . "global-mark-ring")
3981 (candidates . anything-c-source-global-mark-ring-candidates)
3982 (action . (("Goto line" . (lambda (candidate)
3983 (let ((items (split-string candidate ":")))
3984 (switch-to-buffer (second items))
3985 (anything-goto-line (string-to-number (car items))))))))
3986 (persistent-action . (lambda (candidate)
3987 (let ((items (split-string candidate ":")))
3988 (switch-to-buffer (second items))
3989 (anything-goto-line (string-to-number (car items)))
3990 (anything-match-line-color-current-line))))
3991 (persistent-help . "Show this line")))
3993 (defun anything-c-source-global-mark-ring-candidates ()
3994 (flet ((buf-fn (m)
3995 (with-current-buffer (marker-buffer m)
3996 (goto-char m)
3997 (beginning-of-line)
3998 (let (line)
3999 (if (string= "" line)
4000 (setq line "<EMPTY LINE>")
4001 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
4002 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
4003 (loop
4004 with marks = global-mark-ring
4005 with recip = nil
4006 for i in marks
4007 for gm = (unless (or (string-match
4008 "^ " (format "%s" (marker-buffer i)))
4009 (null (marker-buffer i)))
4010 (buf-fn i))
4011 when (and gm (not (member gm recip)))
4012 collect gm into recip
4013 finally return recip)))
4015 ;; (anything 'anything-c-source-global-mark-ring)
4017 ;;;###autoload
4018 (defun anything-global-mark-ring ()
4019 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4020 (interactive)
4021 (anything 'anything-c-source-global-mark-ring))
4023 ;;;###autoload
4024 (defun anything-all-mark-rings ()
4025 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4026 `anything-c-source-mark-ring'."
4027 (interactive)
4028 (anything '(anything-c-source-global-mark-ring
4029 anything-c-source-mark-ring)))
4031 ;;;; <Register>
4032 ;;; Insert from register
4033 (defvar anything-c-source-register
4034 '((name . "Registers")
4035 (candidates . anything-c-register-candidates)
4036 (action-transformer . anything-c-register-action-transformer)
4037 (multiline)
4038 (action))
4039 "See (info \"(emacs)Registers\")")
4041 (defun anything-c-register-candidates ()
4042 "Collecting register contents and appropriate commands."
4043 (loop for (char . val) in register-alist
4044 for key = (single-key-description char)
4045 for string-actions = (cond
4046 ((numberp val)
4047 (list (int-to-string val)
4048 'insert-register
4049 'increment-register))
4050 ((markerp val)
4051 (let ((buf (marker-buffer val)))
4052 (if (null buf)
4053 (list "a marker in no buffer")
4054 (list (concat
4055 "a buffer position:"
4056 (buffer-name buf)
4057 ", position "
4058 (int-to-string (marker-position val)))
4059 'jump-to-register
4060 'insert-register))))
4061 ((and (consp val) (window-configuration-p (car val)))
4062 (list "window configuration."
4063 'jump-to-register))
4064 ((and (consp val) (frame-configuration-p (car val)))
4065 (list "frame configuration."
4066 'jump-to-register))
4067 ((and (consp val) (eq (car val) 'file))
4068 (list (concat "file:"
4069 (prin1-to-string (cdr val))
4070 ".")
4071 'jump-to-register))
4072 ((and (consp val) (eq (car val) 'file-query))
4073 (list (concat "file:a file-query reference: file "
4074 (car (cdr val))
4075 ", position "
4076 (int-to-string (car (cdr (cdr val))))
4077 ".")
4078 'jump-to-register))
4079 ((consp val)
4080 (let ((lines (format "%4d" (length val))))
4081 (list (format "%s: %s\n" lines
4082 (truncate-string-to-width
4083 (mapconcat 'identity (list (car val))
4084 ;; (mapconcat (lambda (y) y) val
4085 "^J") (- (window-width) 15)))
4086 'insert-register)))
4087 ((stringp val)
4088 (list ;; without properties
4089 (substring-no-properties val)
4090 'insert-register
4091 'append-to-register
4092 'prepend-to-register))
4094 "GARBAGE!"))
4095 collect (cons (format "register %3s: %s" key (car string-actions))
4096 (cons char (cdr string-actions)))))
4098 (defun anything-c-register-action-transformer (actions register-and-functions)
4099 "Decide actions by the contents of register."
4100 (loop with func-actions =
4101 '((insert-register
4102 "Insert Register" .
4103 (lambda (c) (insert-register (car c))))
4104 (jump-to-register
4105 "Jump to Register" .
4106 (lambda (c) (jump-to-register (car c))))
4107 (append-to-register
4108 "Append Region to Register" .
4109 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
4110 (prepend-to-register
4111 "Prepend Region to Register" .
4112 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
4113 (increment-register
4114 "Increment Prefix Arg to Register" .
4115 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
4116 for func in (cdr register-and-functions)
4117 for cell = (assq func func-actions)
4118 when cell
4119 collect (cdr cell)))
4121 ;; (anything 'anything-c-source-register)
4123 ;;;; <Headline Extraction>
4124 (defvar anything-c-source-fixme
4125 '((name . "TODO/FIXME/DRY comments")
4126 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4127 (adjust)
4128 (recenter))
4129 "Show TODO/FIXME/DRY comments in current file.")
4130 ;; (anything 'anything-c-source-fixme)
4132 (defvar anything-c-source-rd-headline
4133 '((name . "RD HeadLine")
4134 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4135 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
4136 (migemo)
4137 (subexp . 1))
4138 "Show RD headlines.
4140 RD is Ruby's POD.
4141 http://en.wikipedia.org/wiki/Ruby_Document_format")
4142 ;; (anything 'anything-c-source-rd-headline)
4144 (defvar anything-c-source-oddmuse-headline
4145 '((name . "Oddmuse HeadLine")
4146 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4147 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4148 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
4149 (migemo)
4150 (subexp . 1))
4151 "Show Oddmuse headlines, such as EmacsWiki.")
4152 ;; (anything 'anything-c-source-oddmuse-headline)
4154 (defvar anything-c-source-emacs-source-defun
4155 '((name . "Emacs Source DEFUN")
4156 (headline . "DEFUN\\|DEFVAR")
4157 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
4158 "Show DEFUN/DEFVAR in Emacs C source file.")
4159 ;; (anything 'anything-c-source-emacs-source-defun)
4161 (defvar anything-c-source-emacs-lisp-expectations
4162 '((name . "Emacs Lisp Expectations")
4163 (headline . "(desc[ ]\\|(expectations")
4164 (condition . (eq major-mode 'emacs-lisp-mode)))
4165 "Show descriptions (desc) in Emacs Lisp Expectations.
4167 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4168 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4170 (defvar anything-c-source-emacs-lisp-toplevels
4171 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4172 (headline . "^(\\|(@\\*\\|^;;;;")
4173 (get-line . buffer-substring)
4174 (condition . (eq major-mode 'emacs-lisp-mode))
4175 (adjust))
4176 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4177 linkd.el is optional because linkd stars are extracted by regexp.
4178 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4179 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4181 (defvar anything-c-source-org-headline
4182 '((name . "Org HeadLine")
4183 (headline
4184 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4185 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4186 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4187 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4188 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4189 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4190 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4191 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4192 (condition . (eq major-mode 'org-mode))
4193 (migemo)
4194 (subexp . 1)
4195 (persistent-action . (lambda (elm)
4196 (anything-c-action-line-goto elm)
4197 (org-cycle)))
4198 (action-transformer
4199 . (lambda (actions candidate)
4200 '(("Go to Line" . anything-c-action-line-goto)
4201 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
4202 "Show Org headlines.
4203 org-mode is very very much extended text-mode/outline-mode.
4205 See (find-library \"org.el\")
4206 See http://orgmode.org for the latest version.")
4208 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4209 (insert
4210 (save-excursion
4211 (anything-goto-line (car lineno-and-content))
4212 (and (looking-at org-complex-heading-regexp)
4213 (org-make-link-string (concat "*" (match-string 4)))))))
4215 ;; (anything 'anything-c-source-org-headline)
4217 ;;; Anything yaoddmuse
4218 ;; Be sure to have yaoddmuse.el installed
4219 ;; install-elisp may be required if you want to install elisp file from here.
4220 (defvar anything-yaoddmuse-use-cache-file nil)
4221 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
4222 (defvar anything-c-yaoddmuse-ew-cache nil)
4223 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4224 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
4225 (candidates . (lambda ()
4226 (if anything-yaoddmuse-use-cache-file
4227 (ignore-errors
4228 (unless anything-c-yaoddmuse-ew-cache
4229 (load anything-c-yaoddmuse-cache-file)
4230 (setq anything-c-yaoddmuse-ew-cache
4231 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4232 anything-c-yaoddmuse-ew-cache)
4233 (yaoddmuse-update-pagename t)
4234 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
4235 (action . (("Edit page" . (lambda (candidate)
4236 (yaoddmuse-edit "EmacsWiki" candidate)))
4237 ("Browse page" . (lambda (candidate)
4238 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4239 ("Browse page other window" . (lambda (candidate)
4240 (if (one-window-p)
4241 (split-window-vertically))
4242 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4243 ("Browse diff" . (lambda (candidate)
4244 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
4245 ("Copy URL" . (lambda (candidate)
4246 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
4247 (message "Have copy page %s's URL to yank." candidate)))
4248 ("Create page" . (lambda (candidate)
4249 (yaoddmuse-edit "EmacsWiki" anything-input)))
4250 ("Update cache" . (lambda (candidate)
4251 (if anything-yaoddmuse-use-cache-file
4252 (progn
4253 (anything-yaoddmuse-cache-pages t)
4254 (setq anything-c-yaoddmuse-ew-cache
4255 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4256 (yaoddmuse-update-pagename))))))
4257 (action-transformer anything-c-yaoddmuse-action-transformer))
4258 "Needs yaoddmuse.el.
4260 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4262 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
4264 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
4265 '((name . "Yaoddmuse Post library (EmacsWiki)")
4266 (init . (anything-yaoddmuse-init))
4267 (candidates-in-buffer)
4268 (action . (("Post library and Browse" . (lambda (candidate)
4269 (yaoddmuse-post-file (find-library-name candidate)
4270 "EmacsWiki"
4271 (file-name-nondirectory (find-library-name candidate))
4272 nil t)))
4273 ("Post library" . (lambda (candidate)
4274 (yaoddmuse-post-file (find-library-name candidate)
4275 "EmacsWiki"
4276 (file-name-nondirectory (find-library-name candidate))))))))
4277 "Needs yaoddmuse.el.
4279 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4281 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
4283 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
4284 "Allow the use of `install-elisp' only on elisp files."
4285 (if (string-match "\.el$" candidate)
4286 (append actions '(("Install Elisp" . (lambda (elm)
4287 (install-elisp-from-emacswiki elm)))))
4288 actions))
4290 ;;;###autoload
4291 (defun anything-yaoddmuse-cache-pages (&optional load)
4292 "Fetch the list of files on emacswiki and create cache file.
4293 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
4294 (interactive)
4295 (yaoddmuse-update-pagename)
4296 (save-excursion
4297 (find-file anything-c-yaoddmuse-cache-file)
4298 (erase-buffer)
4299 (insert "(puthash \"EmacsWiki\" '(")
4300 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
4302 (insert (concat "(\"" (car i) "\") ")))
4303 (insert ") yaoddmuse-pages-hash)\n")
4304 (save-buffer)
4305 (kill-buffer (current-buffer))
4306 (when (or current-prefix-arg
4307 load)
4308 (load anything-c-yaoddmuse-cache-file))))
4310 ;;;###autoload
4311 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
4312 "Preconfigured `anything' to edit or view EmacsWiki page.
4314 Needs yaoddmuse.el.
4316 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4317 (interactive)
4318 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
4320 ;;;###autoload
4321 (defun anything-yaoddmuse-emacswiki-post-library ()
4322 "Preconfigured `anything' to post library to EmacsWiki.
4324 Needs yaoddmuse.el.
4326 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4327 (interactive)
4328 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
4330 (defun anything-yaoddmuse-init ()
4331 "Init anything buffer status."
4332 (let ((anything-buffer (anything-candidate-buffer 'global))
4333 (library-list (yaoddmuse-get-library-list)))
4334 (with-current-buffer anything-buffer
4335 ;; Insert library name.
4336 (dolist (library library-list)
4337 (insert (format "%s\n" library)))
4338 ;; Sort lines.
4339 (sort-lines nil (point-min) (point-max)))))
4341 ;;; Eev anchors
4342 (defvar anything-c-source-eev-anchor
4343 '((name . "Anchors")
4344 (candidates
4345 . (lambda ()
4346 (ignore-errors
4347 (with-current-buffer anything-current-buffer
4348 (loop initially (goto-char (point-min))
4349 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
4350 for anchor = (match-string-no-properties 1)
4351 collect (cons (format "%5d:%s"
4352 (line-number-at-pos (match-beginning 0))
4353 (format ee-anchor-format anchor)) anchor))))))
4354 (persistent-action . (lambda (item)
4355 (ee-to item)
4356 (anything-match-line-color-current-line)))
4357 (persistent-help . "Show this entry")
4358 (action . (("Goto link" . ee-to)))))
4359 ;; (anything 'anything-c-source-eev-anchor)
4361 ;;;; <Misc>
4362 ;;; Org keywords
4363 (defvar anything-c-source-org-keywords
4364 '((name . "Org Keywords")
4365 (init . anything-c-org-keywords-init)
4366 (candidates . anything-c-org-keywords-candidates)
4367 (action . anything-c-org-keywords-insert)
4368 (persistent-action . anything-c-org-keywords-show-help)
4369 (persistent-help . "Show an example and info page to describe this keyword.")
4370 (keywords-examples)
4371 (keywords)))
4372 ;; (anything 'anything-c-source-org-keywords)
4373 (defvar anything-c-org-keywords-info-location
4374 '(("#+TITLE:" . "(org)Export options")
4375 ("#+AUTHOR:" . "(org)Export options")
4376 ("#+DATE:" . "(org)Export options")
4377 ("#+EMAIL:" . "(org)Export options")
4378 ("#+DESCRIPTION:" . "(org)Export options")
4379 ("#+KEYWORDS:" . "(org)Export options")
4380 ("#+LANGUAGE:" . "(org)Export options")
4381 ("#+TEXT:" . "(org)Export options")
4382 ("#+TEXT:" . "(org)Export options")
4383 ("#+OPTIONS:" . "(org)Export options")
4384 ("#+BIND:" . "(org)Export options")
4385 ("#+LINK_UP:" . "(org)Export options")
4386 ("#+LINK_HOME:" . "(org)Export options")
4387 ("#+LATEX_HEADER:" . "(org)Export options")
4388 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
4389 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
4390 ("#+INFOJS_OPT" . "(org)Javascript support")
4391 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
4392 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
4393 ("#+ORGTBL" . "(org)Radio tables")
4394 ("#+HTML:" . "(org)Quoting HTML tags")
4395 ("#+LaTeX:" . "(org)Quoting LaTeX code")
4396 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
4397 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
4398 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
4399 ("#+BEGIN_VERSE" . "(org)Paragraphs")
4400 ("#+BEGIN_SRC" . "(org)Literal examples")
4401 ("#+CAPTION" . "(org)Tables in HTML export")
4402 ("#+LABEL" . "(org)Tables in LaTeX export")
4403 ("#+ATTR_HTML" . "(org)Links")
4404 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
4406 (defun anything-c-org-keywords-init ()
4407 (unless (anything-attr 'keywords-examples)
4408 (require 'org)
4409 (anything-attrset 'keywords-examples
4410 (append
4411 (mapcar
4412 (lambda (x)
4413 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
4414 (cons (match-string 2 x) (match-string 1 x)))
4415 (org-split-string (org-get-current-options) "\n"))
4416 (mapcar 'list org-additional-option-like-keywords)))
4417 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
4419 (defun anything-c-org-keywords-candidates ()
4420 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
4421 (anything-attr 'keywords)))
4423 (defun anything-c-org-keywords-insert (keyword)
4424 (cond ((string-match "BEGIN" keyword)
4425 (insert "#+" keyword " ")
4426 (save-excursion
4427 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
4429 (insert "#+" keyword " "))))
4431 (defun anything-c-org-keywords-show-help (keyword)
4432 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
4433 "(org)In-buffer settings"))
4434 (search-forward (concat "#+" keyword) nil t)
4435 (anything-persistent-highlight-point)
4436 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
4439 ;;; Picklist
4440 (defvar anything-c-source-picklist
4441 '((name . "Picklist")
4442 (candidates . (lambda () (mapcar 'car picklist-list)))
4443 (type . file)))
4444 ;; (anything 'anything-c-source-picklist)
4446 ;;; BBDB
4447 (defvar bbdb-records)
4448 (defvar bbdb-buffer-name)
4449 (declare-function bbdb "ext:bbdb-com")
4450 (declare-function bbdb-current-record "ext:bbdb-com")
4451 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
4452 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
4453 (declare-function bbdb-current-record "ext:bbdb-com")
4454 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
4455 (declare-function bbdb-records "ext:bbdb-com"
4456 (&optional dont-check-disk already-in-db-buffer))
4458 (defun anything-c-bbdb-candidates ()
4459 "Return a list of all names in the bbdb database. The format
4460 is \"Firstname Lastname\"."
4461 (mapcar (lambda (bbdb-record)
4462 (replace-regexp-in-string
4463 "\\s-+$" ""
4464 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
4465 (bbdb-records)))
4467 (defun anything-c-bbdb-create-contact (actions candidate)
4468 "Action transformer that returns only an entry to add the
4469 current `anything-pattern' as new contact. All other actions are
4470 removed."
4471 (if (string= candidate "*Add to contacts*")
4472 '(("Add to contacts" . (lambda (actions)
4473 (bbdb-create-internal
4474 (read-from-minibuffer "Name: " anything-c-bbdb-name)
4475 (read-from-minibuffer "Company: ")
4476 (read-from-minibuffer "Email: ")
4479 (read-from-minibuffer "Note: ")))))
4480 actions))
4482 (defun anything-c-bbdb-get-record (candidate)
4483 "Return record that match CANDIDATE."
4484 (bbdb candidate nil)
4485 (set-buffer "*BBDB*")
4486 (bbdb-current-record))
4488 (defvar anything-c-bbdb-name nil
4489 "Only for internal use.")
4491 (defvar anything-c-source-bbdb
4492 '((name . "BBDB")
4493 (candidates . anything-c-bbdb-candidates)
4494 (action ("Send a mail" . anything-c-bbdb-compose-mail)
4495 ("View person's data" . anything-c-bbdb-view-person-action))
4496 (filtered-candidate-transformer . (lambda (candidates source)
4497 (setq anything-c-bbdb-name anything-pattern)
4498 (if (not candidates)
4499 (list "*Add to contacts*")
4500 candidates)))
4501 (action-transformer . (lambda (actions candidate)
4502 (anything-c-bbdb-create-contact actions candidate))))
4503 "Needs BBDB.
4505 http://bbdb.sourceforge.net/")
4506 ;; (anything 'anything-c-source-bbdb)
4508 (defun anything-c-bbdb-view-person-action (candidate)
4509 "View BBDB data of single CANDIDATE or marked candidates."
4510 (anything-aif (anything-marked-candidates)
4511 (let ((bbdb-append-records (length it)))
4512 (dolist (i it)
4513 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
4514 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
4516 (defun anything-c-bbdb-collect-mail-addresses ()
4517 "Return a list of all mail addresses of records in bbdb buffer."
4518 (with-current-buffer bbdb-buffer-name
4519 (loop for i in bbdb-records
4520 if (bbdb-record-net (car i))
4521 collect (bbdb-dwim-net-address (car i)))))
4523 (defun anything-c-bbdb-compose-mail (candidate)
4524 "Compose a mail with all records of bbdb buffer."
4525 (anything-c-bbdb-view-person-action candidate)
4526 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4527 (address-str (mapconcat 'identity address-list ",\n ")))
4528 (compose-mail address-str)))
4530 ;;; Evaluation Result
4531 (defvar anything-c-source-evaluation-result
4532 '((name . "Evaluation Result")
4533 (disable-shortcuts)
4534 (dummy)
4535 (filtered-candidate-transformer . (lambda (candidates source)
4536 (list
4537 (condition-case nil
4538 (with-current-buffer anything-current-buffer
4539 (pp-to-string
4540 (eval (read anything-pattern))))
4541 (error "Error")))))
4542 (action ("Copy result to kill-ring" . (lambda (candidate)
4543 (with-current-buffer anything-buffer
4544 (let ((end (save-excursion
4545 (goto-char (point-max))
4546 (search-backward "\n")
4547 (point))))
4548 (kill-region (point) end))))))))
4549 ;; (anything 'anything-c-source-evaluation-result)
4551 ;;;###autoload
4552 (defun anything-eval-expression (arg)
4553 "Preconfigured anything for `anything-c-source-evaluation-result'."
4554 (interactive "P")
4555 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
4556 nil nil nil "*anything eval*"))
4558 ;;;###autoload
4559 (defun anything-eval-expression-with-eldoc ()
4560 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
4561 (interactive)
4562 (if (window-system)
4563 (let ((timer (run-with-idle-timer eldoc-idle-delay
4564 'repeat 'anything-eldoc-show-in-eval)))
4565 (unwind-protect
4566 (call-interactively 'anything-eval-expression)
4567 (cancel-timer timer)))
4568 (call-interactively 'anything-eval-expression)))
4570 (defun anything-eldoc-show-in-eval ()
4571 "Return eldoc in a tooltip for current minibuffer input."
4572 (let* ((str-all (minibuffer-completion-contents))
4573 (sym (when str-all
4574 (with-temp-buffer
4575 (insert str-all)
4576 (goto-char (point-max))
4577 (unless (looking-back ")\\|\"") (forward-char -1))
4578 (eldoc-current-symbol))))
4579 (doc (or (eldoc-get-var-docstring sym)
4580 (eldoc-get-fnsym-args-string
4581 (car (eldoc-fnsym-in-current-sexp))))))
4582 (when doc (tooltip-show doc))))
4584 ;;; Calculation Result
4585 (defvar anything-c-source-calculation-result
4586 '((name . "Calculation Result")
4587 (dummy)
4588 (filtered-candidate-transformer . (lambda (candidates source)
4589 (list
4590 (condition-case nil
4591 (calc-eval anything-pattern)
4592 (error "error")))))
4593 (action ("Copy result to kill-ring" . kill-new))))
4594 ;; (anything 'anything-c-source-calculation-result)
4596 ;;; Google Suggestions
4597 (defvar anything-gg-sug-lgh-flag 0)
4598 (defun anything-c-google-suggest-fetch (input)
4599 "Fetch suggestions for INPUT from XML buffer.
4600 Return an alist with elements like (data . number_results)."
4601 (let ((request (concat anything-c-google-suggest-url
4602 (url-hexify-string input))))
4603 (flet ((fetch ()
4604 (loop
4605 with result-alist = (xml-get-children
4606 (car (xml-parse-region (point-min) (point-max)))
4607 'CompleteSuggestion)
4608 for i in result-alist
4609 for data = (cdr (caadr (assoc 'suggestion i)))
4610 for nqueries = (cdr (caadr (assoc 'num_queries i)))
4611 for ldata = (length data)
4613 (when (> ldata anything-gg-sug-lgh-flag)
4614 (setq anything-gg-sug-lgh-flag ldata))
4615 collect (cons data nqueries) into cont
4616 finally return cont)))
4617 (if anything-google-suggest-use-curl-p
4618 (with-temp-buffer
4619 (call-process "curl" nil t nil request)
4620 (fetch))
4621 (with-current-buffer
4622 (url-retrieve-synchronously request)
4623 (fetch))))))
4626 (defun anything-c-google-suggest-set-candidates ()
4627 "Set candidates with result and number of google results found."
4628 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
4629 (setq suggestions (loop for i in suggestions
4630 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
4631 for elm = (concat (car i)
4632 (make-string (+ 2 interval) ? )
4633 "(" (cdr i) " results)")
4634 collect (cons elm (car i))))
4635 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
4636 suggestions
4637 ;; if there is no suggestion exactly matching the input then
4638 ;; prepend a Search on Google item to the list
4639 (append
4640 suggestions
4641 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
4642 anything-input))))))
4645 (defun anything-c-google-suggest-action (candidate)
4646 "Default action to jump to a google suggested candidate."
4647 (anything-c-browse-url (concat anything-c-google-suggest-search-url
4648 (url-hexify-string candidate))))
4651 (defvar anything-c-source-google-suggest
4652 '((name . "Google Suggest")
4653 (candidates . anything-c-google-suggest-set-candidates)
4654 (action . (("Google Search" . anything-c-google-suggest-action)))
4655 (volatile)
4656 (requires-pattern . 3)
4657 (delayed)))
4659 ;; (anything 'anything-c-source-google-suggest)
4661 ;;; Yahoo suggestions
4663 (defun anything-c-yahoo-suggest-fetch (input)
4664 "Fetch Yahoo suggestions for INPUT from XML buffer.
4665 Return an alist with elements like (data . number_results)."
4666 (let ((request (concat anything-c-yahoo-suggest-url
4667 (url-hexify-string input))))
4668 (flet ((fetch ()
4669 (loop
4670 with result-alist = (xml-get-children
4671 (car (xml-parse-region (point-min) (point-max)))
4672 'Result)
4673 for i in result-alist
4674 collect (caddr i))))
4675 (with-current-buffer
4676 (url-retrieve-synchronously request)
4677 (fetch)))))
4679 (defun anything-c-yahoo-suggest-set-candidates ()
4680 "Set candidates with Yahoo results found."
4681 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
4682 (or suggestions
4683 (append
4684 suggestions
4685 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
4686 anything-input))))))
4688 (defun anything-c-yahoo-suggest-action (candidate)
4689 "Default action to jump to a Yahoo suggested candidate."
4690 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
4691 (url-hexify-string candidate))))
4693 (defvar anything-c-source-yahoo-suggest
4694 '((name . "Yahoo Suggest")
4695 (candidates . anything-c-yahoo-suggest-set-candidates)
4696 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
4697 (volatile)
4698 (requires-pattern . 3)
4699 (delayed)))
4701 ;; (anything 'anything-c-source-yahoo-suggest)
4703 ;;; Surfraw
4704 ;;; Need external program surfraw.
4705 ;;; http://surfraw.alioth.debian.org/
4706 ;; user variables
4707 (require 'browse-url)
4708 (defvar w3m-command nil)
4709 (defvar anything-c-home-url "http://www.google.fr"
4710 "*Default url to use as home url.")
4712 (defvar anything-browse-url-default-browser-alist
4713 `((,w3m-command . w3m-browse-url)
4714 (,browse-url-firefox-program . browse-url-firefox)
4715 (,browse-url-kde-program . browse-url-kde)
4716 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
4717 (,browse-url-mozilla-program . browse-url-mozilla)
4718 (,browse-url-galeon-program . browse-url-galeon)
4719 (,browse-url-netscape-program . browse-url-netscape)
4720 (,browse-url-mosaic-program . browse-url-mosaic)
4721 (,browse-url-xterm-program . browse-url-text-xterm))
4722 "*Alist of (executable . function) to try to find a suitable url browser.")
4724 (defun anything-browse-url-default-browser (url &rest args)
4725 "Find a suitable browser and ask it to load URL."
4726 (let ((default-browser (loop
4727 for i in anything-browse-url-default-browser-alist
4728 when (and (car i) (executable-find (car i))) return (cdr i))))
4729 (if default-browser
4730 (apply default-browser url args)
4731 (error "No usable browser found"))))
4733 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
4734 "Default command to browse URL."
4735 (if browse-url-browser-function
4736 (browse-url url)
4737 (anything-browse-url-default-browser url)))
4739 (defun anything-c-build-elvi-list ()
4740 "Return list of all engines and descriptions handled by surfraw."
4741 (cdr
4742 (with-temp-buffer
4743 (call-process "surfraw" nil t nil
4744 "-elvi")
4745 (split-string (buffer-string) "\n"))))
4747 ;;;###autoload
4748 (defun anything-surfraw (pattern engine)
4749 "Preconfigured `anything' to search PATTERN with search ENGINE."
4750 (interactive (list (read-string "SearchFor: ")
4751 (anything-comp-read
4752 "Engine: "
4753 (anything-c-build-elvi-list)
4754 :must-match t)))
4755 (let* ((engine-nodesc (car (split-string engine)))
4756 (url (with-temp-buffer
4757 (apply 'call-process "surfraw" nil t nil
4758 (list engine-nodesc "-p" pattern))
4759 (replace-regexp-in-string
4760 "\n" "" (buffer-string)))))
4761 (if (string= engine-nodesc "W")
4762 (anything-c-browse-url)
4763 (anything-c-browse-url url))))
4765 ;;; Emms
4767 ;;;###autoload
4768 (defun anything-emms-stream-edit-bookmark (elm)
4769 "Change the information of current emms-stream bookmark from anything."
4770 (interactive)
4771 (let* ((cur-buf anything-current-buffer)
4772 (bookmark (assoc elm emms-stream-list))
4773 (name (read-from-minibuffer "Description: "
4774 (nth 0 bookmark)))
4775 (url (read-from-minibuffer "URL: "
4776 (nth 1 bookmark)))
4777 (fd (read-from-minibuffer "Feed Descriptor: "
4778 (int-to-string (nth 2 bookmark))))
4779 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4780 (format "%s" (car (last bookmark))))))
4781 (save-excursion
4782 (emms-streams)
4783 (when (re-search-forward (concat "^" name) nil t)
4784 (beginning-of-line)
4785 (emms-stream-delete-bookmark)
4786 (emms-stream-add-bookmark name url (string-to-number fd) type)
4787 (emms-stream-save-bookmarks-file)
4788 (emms-stream-quit)
4789 (switch-to-buffer cur-buf)))))
4791 (defun anything-emms-stream-delete-bookmark (elm)
4792 "Delete an emms-stream bookmark from anything."
4793 (interactive)
4794 (let* ((cur-buf anything-current-buffer)
4795 (bookmark (assoc elm emms-stream-list))
4796 (name (nth 0 bookmark)))
4797 (save-excursion
4798 (emms-streams)
4799 (when (re-search-forward (concat "^" name) nil t)
4800 (beginning-of-line)
4801 (emms-stream-delete-bookmark)
4802 (emms-stream-save-bookmarks-file)
4803 (emms-stream-quit)
4804 (switch-to-buffer cur-buf)))))
4806 (defvar anything-c-source-emms-streams
4807 '((name . "Emms Streams")
4808 (init . (lambda ()
4809 (emms-stream-init)))
4810 (candidates . (lambda ()
4811 (mapcar 'car emms-stream-list)))
4812 (action . (("Play" . (lambda (elm)
4813 (let* ((stream (assoc elm emms-stream-list))
4814 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
4815 (url (second stream)))
4816 (funcall fn url))))
4817 ("Delete" . anything-emms-stream-delete-bookmark)
4818 ("Edit" . anything-emms-stream-edit-bookmark)))
4819 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4820 ;; (anything 'anything-c-source-emms-streams)
4822 ;; Don't forget to set `emms-source-file-default-directory'
4823 (defvar anything-c-source-emms-dired
4824 '((name . "Music Directory")
4825 (candidates . (lambda ()
4826 (cddr (directory-files emms-source-file-default-directory))))
4827 (action .
4828 (("Play Directory" . (lambda (item)
4829 (emms-play-directory
4830 (expand-file-name
4831 item
4832 emms-source-file-default-directory))))
4833 ("Open dired in file's directory" . (lambda (item)
4834 (anything-c-open-dired
4835 (expand-file-name
4836 item
4837 emms-source-file-default-directory))))))
4838 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4839 ;; (anything 'anything-c-source-emms-dired)
4841 (defface anything-emms-playlist
4842 '((t (:foreground "Springgreen4" :underline t)))
4843 "*Face used for tracks in current emms playlist."
4844 :group 'anything)
4846 (defun anything-c-emms-files-modifier (candidates)
4847 (let ((current-playlist (with-current-emms-playlist
4848 (loop
4849 with cur-list = (emms-playlist-tracks-in-region
4850 (point-min) (point-max))
4851 for i in cur-list
4852 collect (assoc-default 'info-file i)))))
4853 (loop for i in candidates
4854 if (member i current-playlist)
4855 collect (propertize i 'face 'anything-emms-playlist) into lis
4856 else collect i into lis finally return lis)))
4858 (defun anything-c-emms-play-current-playlist ()
4859 "Play current playlist."
4860 (with-current-emms-playlist
4861 (emms-playlist-first)
4862 (emms-playlist-mode-play-smart)))
4864 (defvar anything-c-source-emms-files
4865 '((name . "Emms files")
4866 (candidates . (lambda ()
4867 (loop for v being the hash-values in emms-cache-db
4868 for name = (assoc-default 'name v)
4869 unless (string-match "^http:" name) collect name)))
4870 (candidate-transformer . anything-c-emms-files-modifier)
4871 (action . (("Play file" . emms-play-file)
4872 ("Add to Playlist and play"
4873 . (lambda (candidate)
4874 (emms-playlist-new)
4875 (dolist (i (anything-marked-candidates))
4876 (emms-add-playlist-file i))
4877 (unless emms-player-playing-p
4878 (anything-c-emms-play-current-playlist))))))))
4880 ;; (anything 'anything-c-source-emms-files)
4882 ;;; Jabber Contacts (jabber.el)
4883 (defun anything-c-jabber-online-contacts ()
4884 "List online Jabber contacts."
4885 (with-no-warnings
4886 (let (jids)
4887 (dolist (item (jabber-concat-rosters) jids)
4888 (when (get item 'connected)
4889 (push (if (get item 'name)
4890 (cons (get item 'name) item)
4891 (cons (symbol-name item) item)) jids))))))
4893 (defvar anything-c-source-jabber-contacts
4894 '((name . "Jabber Contacts")
4895 (init . (lambda () (require 'jabber)))
4896 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
4897 (action . (lambda (x)
4898 (jabber-chat-with
4899 (jabber-read-account)
4900 (symbol-name
4901 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
4902 ;; (anything 'anything-c-source-jabber-contacts)
4905 ;;; Call source.
4906 (defvar anything-source-select-buffer "*anything source select*")
4907 (defvar anything-c-source-call-source
4908 `((name . "Call anything source")
4909 (candidate-number-limit)
4910 (candidates . (lambda ()
4911 (loop for vname in (all-completions "anything-c-source-" obarray)
4912 for var = (intern vname)
4913 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
4914 if name collect (cons (format "%s `%s'"
4915 name (propertize vname 'face 'font-lock-variable-name-face))
4916 var))))
4917 (action . (("Invoke anything with selected source" .
4918 (lambda (candidate)
4919 (setq anything-candidate-number-limit 9999)
4920 (anything candidate nil nil nil nil
4921 anything-source-select-buffer)))
4922 ("Describe variable" . describe-variable)
4923 ("Find variable" . find-variable)))
4924 (persistent-action . describe-variable)
4925 (persistent-help . "Show description of this source")))
4926 ;; (anything 'anything-c-source-call-source)
4928 ;;;###autoload
4929 (defun anything-call-source ()
4930 "Preconfigured `anything' to call anything source."
4931 (interactive)
4932 (anything 'anything-c-source-call-source nil nil nil nil
4933 anything-source-select-buffer))
4935 (defun anything-call-source-from-anything ()
4936 "Call anything source within `anything' session."
4937 (interactive)
4938 (setq anything-input-idle-delay 0)
4939 (anything-set-sources '(anything-c-source-call-source)))
4941 ;;; Execute Preconfigured anything.
4942 (defvar anything-c-source-anything-commands
4943 '((name . "Preconfigured Anything")
4944 (candidates . anything-c-anything-commands-candidates)
4945 (type . command)
4946 (candidate-number-limit)))
4947 ;; (anything 'anything-c-source-anything-commands)
4949 (defun anything-c-anything-commands-candidates ()
4950 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
4951 collect (cons (if (where-is-internal cmd nil t)
4952 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
4953 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
4954 cmd)))
4956 ;;;###autoload
4957 (defun anything-execute-anything-command ()
4958 "Preconfigured `anything' to execute preconfigured `anything'."
4959 (interactive)
4960 (anything-other-buffer 'anything-c-source-anything-commands
4961 "*anything commands*"))
4963 ;; Occur
4965 (defun anything-c-occur-goto-line (candidate)
4966 "Goto line action for anything-c-source-occur."
4967 (anything-goto-line (string-to-number candidate)))
4969 (defun anything-c-occur-persistent-action (candidate)
4970 "Persistent action for anything occur source."
4971 (anything-c-occur-goto-line candidate)
4972 (anything-match-line-color-current-line))
4974 (defun anything-c-get-occur-candidates ()
4975 "Get `anything-c-source-occur' candidates."
4976 (with-temp-buffer
4977 (let ((count (occur-engine
4978 anything-pattern
4979 (list anything-current-buffer) (current-buffer)
4980 list-matching-lines-default-context-lines nil
4981 list-matching-lines-buffer-name-face
4982 nil list-matching-lines-face
4983 (not (eq occur-excluded-properties t)))))
4984 (when (> count 0)
4985 (cdr (split-string (buffer-string) "\n" t))))))
4987 (defvar anything-c-source-occur
4988 '((name . "Occur")
4989 (candidates . anything-c-get-occur-candidates)
4990 (persistent-action . anything-c-occur-persistent-action)
4991 (persistent-help . "Goto Line")
4992 (action . anything-c-occur-goto-line)
4993 (requires-pattern . 1)
4994 (delayed)
4995 (volatile)))
4996 ;; (anything 'anything-c-source-occur)
4998 ;;;###autoload
4999 (defun anything-occur ()
5000 "Preconfigured Anything for Occur source."
5001 (interactive)
5002 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*"))
5004 ;; Do many actions for input
5005 (defvar anything-c-source-create
5006 '((name . "Create")
5007 (dummy)
5008 (action)
5009 (action-transformer . anything-create--actions))
5010 "Do many create actions from `anything-pattern'.
5011 See also `anything-create--actions'.")
5012 ;; (anything 'anything-c-source-create)
5014 (defun anything-create-from-anything ()
5015 "Run `anything-create' from `anything' as a fallback."
5016 (interactive)
5017 (anything-run-after-quit 'anything-create nil anything-pattern))
5019 ;;;###autoload
5020 (defun anything-create (&optional string initial-input)
5021 "Preconfigured `anything' to do many create actions from STRING.
5022 See also `anything-create--actions'."
5023 (interactive)
5024 (setq string (or string (read-string "Create Anything: " initial-input)))
5025 (anything '(((name . "Anything Create")
5026 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
5027 (candidates . anything-create--actions)
5028 (candidate-number-limit)
5029 (action . (lambda (func) (funcall func string)))))))
5031 (defun anything-create--actions (&rest ignored)
5032 "Default actions for `anything-create' / `anything-c-source-create'."
5033 (remove-if-not
5034 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
5035 (append anything-create--actions-private
5036 '(("find-file" . find-file)
5037 ("find-file other window" . find-file-other-window)
5038 ("New buffer" . switch-to-buffer)
5039 ("New buffer other window" . switch-to-buffer-other-window)
5040 ("Bookmark Set" . bookmark-set)
5041 ("Set Register" .
5042 (lambda (x) (set-register (read-char "Register: ") x)))
5043 ("Insert Linkd star" . linkd-insert-star)
5044 ("Insert Linkd Tag" . linkd-insert-tag)
5045 ("Insert Linkd Link" . linkd-insert-link)
5046 ("Insert Linkd Lisp" . linkd-insert-lisp)
5047 ("Insert Linkd Wiki" . linkd-insert-wiki)
5048 ("Google Search" . google)))))
5050 ;; Minibuffer History
5051 (defvar anything-c-source-minibuffer-history
5052 '((name . "Minibuffer History")
5053 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
5054 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
5055 (if (consp (car history))
5056 (mapcar 'prin1-to-string history)
5057 history))))
5058 (migemo)
5059 (action . insert)))
5060 ;; (anything 'anything-c-source-minibuffer-history)
5062 ;; elscreen
5063 (defvar anything-c-source-elscreen
5064 '((name . "Elscreen")
5065 (candidates . (lambda ()
5066 (if (cdr (elscreen-get-screen-to-name-alist))
5067 (sort
5068 (loop for sname in (elscreen-get-screen-to-name-alist)
5069 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
5070 finally (return lst))
5071 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
5072 (action . (("Change Screen".
5073 (lambda (candidate)
5074 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
5075 ("Kill Screen(s)".
5076 (lambda (candidate)
5077 (dolist (i (anything-marked-candidates))
5078 (elscreen-goto (- (aref i 1) (aref "0" 0)))
5079 (elscreen-kill))))
5080 ("Only Screen".
5081 (lambda (candidate)
5082 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
5083 (elscreen-kill-others)))))))
5084 ;; (anything 'anything-c-source-elscreen)
5086 ;;;; <System>
5088 ;;; Top (process)
5089 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
5090 "Top command (batch mode). %s is replaced with `frame-width'.")
5091 (defvar anything-c-source-top
5092 '((name . "Top (Press C-c C-u to refresh)")
5093 (init . anything-c-top-init)
5094 (candidates-in-buffer)
5095 (display-to-real . anything-c-top-display-to-real)
5096 (update . anything-c-top-update)
5097 (action
5098 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
5099 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
5100 ("Copy PID" . (lambda (pid) (kill-new pid))))))
5101 ;; (anything 'anything-c-source-top)
5103 (defun anything-c-top-sh (cmd)
5104 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
5106 (defun anything-c-top-init ()
5107 (with-current-buffer (anything-candidate-buffer 'global)
5108 (call-process-shell-command
5109 (format anything-c-top-command
5110 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
5111 nil (current-buffer))))
5113 (defun anything-c-top-display-to-real (line)
5114 (car (split-string line)))
5116 (defun anything-c-top-update ()
5117 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
5118 (anything-c-top-init)))
5120 ;;;###autoload
5121 (defun anything-top ()
5122 "Preconfigured `anything' for top command."
5123 (interactive)
5124 (let ((anything-samewindow t)
5125 (anything-enable-shortcuts)
5126 (anything-display-function 'anything-default-display-buffer)
5127 (anything-candidate-number-limit 9999))
5128 (save-window-excursion
5129 (delete-other-windows)
5130 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
5132 ;;; Timers
5133 (defvar anything-c-source-absolute-time-timers
5134 '((name . "Absolute Time Timers")
5135 (candidates . timer-list)
5136 (type . timer)))
5137 ;; (anything 'anything-c-source-absolute-time-timers)
5139 (defvar anything-c-source-idle-time-timers
5140 '((name . "Idle Time Timers")
5141 (candidates . timer-idle-list)
5142 (type . timer)))
5143 ;; (anything 'anything-c-source-idle-time-timers)
5145 (defun anything-c-timer-real-to-display (timer)
5146 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
5147 (append timer nil) ;use `append' to convert vector->list
5148 (format "%s repeat=%5S %s(%s)"
5149 (let ((time (list t1 t2 t3)))
5150 (if idle-delay
5151 (format-time-string "idle-for=%5s" time)
5152 (format-time-string "%m/%d %T" time)))
5153 repeat-delay
5154 func
5155 (mapconcat 'prin1-to-string args " "))))
5157 ;;; X RandR resolution change
5158 ;;; FIXME I do not care multi-display.
5159 (defvar anything-c-xrandr-output "VGA")
5160 (defvar anything-c-xrandr-screen "0")
5161 (defvar anything-c-source-xrandr-change-resolution
5162 '((name . "Change Resolution")
5163 (candidates
5164 . (lambda ()
5165 (with-temp-buffer
5166 (call-process "xrandr" nil (current-buffer) nil
5167 "--screen" anything-c-xrandr-screen "-q")
5168 (goto-char 1)
5169 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
5170 collect (match-string 1)))))
5171 (action
5172 ("Change Resolution" . (lambda (mode)
5173 (call-process "xrandr" nil nil nil
5174 "--screen" anything-c-xrandr-screen
5175 "--output" anything-c-xrandr-output
5176 "--mode" mode))))))
5177 ;; (anything 'anything-c-source-xrandr-change-resolution)
5179 ;;; Xfont selection
5180 (defun anything-c-persistent-xfont-action (elm)
5181 "Show current font temporarily"
5182 (let ((current-font (cdr (assoc 'font (frame-parameters))))
5183 (default-font elm))
5184 (unwind-protect
5185 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
5186 (set-frame-font current-font))))
5188 (defvar anything-c-xfonts-cache nil)
5189 (defvar anything-c-source-xfonts
5190 '((name . "X Fonts")
5191 (init . (lambda ()
5192 (unless anything-c-xfonts-cache
5193 (setq anything-c-xfonts-cache
5194 (x-list-fonts "*")))))
5195 (candidates . anything-c-xfonts-cache)
5196 (action . (("Copy to kill ring" . (lambda (elm)
5197 (kill-new elm)))
5198 ("Set Font" . (lambda (elm)
5199 (kill-new elm)
5200 (set-frame-font elm 'keep-size)
5201 (message "New font have been copied to kill ring")))))
5202 (persistent-action . anything-c-persistent-xfont-action)
5203 (persistent-help . "Switch to this font temporarily")))
5205 ;;;###autoload
5206 (defun anything-select-xfont ()
5207 "Preconfigured `anything' to select Xfont."
5208 (interactive)
5209 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
5211 ;; (anything 'anything-c-source-xfonts)
5213 ;;; Source for Debian/Ubuntu users
5214 (defvar anything-c-source-apt
5215 '((name . "APT")
5216 (init . anything-c-apt-init)
5217 (candidates-in-buffer)
5218 (candidate-transformer anything-c-apt-candidate-transformer)
5219 (display-to-real . anything-c-apt-display-to-real)
5220 (candidate-number-limit . 9999)
5221 (action
5222 ("Show package description" . anything-c-apt-cache-show)
5223 ("Install package" . anything-c-apt-install)
5224 ("Remove package" . anything-c-apt-uninstall)
5225 ("Purge package" . anything-c-apt-purge))
5226 (persistent-action . anything-c-apt-persistent-action)
5227 (persistent-help . "Show - C-u Refresh")))
5228 ;; (anything 'anything-c-source-apt)
5230 (defvar anything-c-apt-query "emacs")
5231 (defvar anything-c-apt-search-command "apt-cache search '%s'")
5232 (defvar anything-c-apt-show-command "apt-cache show '%s'")
5233 (defvar anything-c-apt-installed-packages nil)
5235 (defface anything-apt-installed
5236 '((t (:foreground "green")))
5237 "*Face used for apt installed candidates."
5238 :group 'anything)
5240 (defun anything-c-apt-refresh ()
5241 "Refresh installed candidates list."
5242 (setq anything-c-apt-installed-packages nil)
5243 (anything-force-update))
5245 (defun anything-c-apt-persistent-action (candidate)
5246 "Persistent action for APT source."
5247 (if current-prefix-arg
5248 (anything-c-apt-refresh)
5249 (anything-c-apt-cache-show candidate)))
5251 ;;;###autoload
5252 (defun anything-apt (query)
5253 "Preconfigured `anything' : frontend of APT package manager."
5254 (interactive "sAPT search: ")
5255 (let ((anything-c-apt-query query))
5256 (anything 'anything-c-source-apt)))
5258 (defun anything-c-apt-candidate-transformer (candidates)
5259 "Show installed candidates in a different color."
5260 (loop
5261 with all
5262 for cand in candidates
5263 for name = (anything-c-apt-display-to-real cand)
5264 if (member name anything-c-apt-installed-packages)
5265 collect (propertize cand 'face 'anything-apt-installed) into all
5266 else collect cand into all finally return all))
5268 (defun anything-c-apt-init ()
5269 "Initialize list of debian packages."
5270 (unless anything-c-apt-installed-packages
5271 (message "Updating installed candidate list...")
5272 (setq anything-c-apt-installed-packages
5273 (with-temp-buffer
5274 (call-process-shell-command "dpkg --get-selections"
5275 nil (current-buffer))
5276 (loop for i in (split-string (buffer-string) "\n" t)
5277 collect (car (split-string i))))))
5278 (with-current-buffer
5279 (anything-candidate-buffer
5280 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
5281 (erase-buffer)
5282 (call-process-shell-command
5283 (format anything-c-apt-search-command anything-c-apt-query)
5284 nil (current-buffer)))
5285 (message "Updating installed candidate list...done"))
5287 (defun anything-c-apt-display-to-real (line)
5288 "Return only name of a debian package.
5289 LINE is displayed like:
5290 package name - description."
5291 (car (split-string line " - ")))
5293 ;;;###autoload
5294 (defun anything-c-shell-command-if-needed (command)
5295 (interactive "sShell command: ")
5296 (if (get-buffer command) ; if the buffer already exists
5297 (switch-to-buffer command) ; then just switch to it
5298 (switch-to-buffer command) ; otherwise create it
5299 (insert (shell-command-to-string command))))
5301 (defun anything-c-apt-cache-show (package)
5302 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
5304 (defun anything-c-apt-install (package)
5305 (anything-c-apt-install1 package :action 'install))
5307 (defun anything-c-apt-uninstall (package)
5308 (anything-c-apt-install1 package :action 'uninstall))
5310 (defun anything-c-apt-purge (package)
5311 (anything-c-apt-install1 package :action 'purge))
5313 (defun* anything-c-apt-install1 (candidate &key action)
5314 (ansi-term (getenv "SHELL") "anything apt")
5315 (term-line-mode)
5316 (let ((command (case action
5317 ('install "sudo apt-get install '%s'")
5318 ('uninstall "sudo apt-get remove '%s'")
5319 ('purge "sudo apt-get purge '%s'")
5320 (t (error "Unknow action"))))
5321 (beg (point)) end)
5322 (goto-char (point-max))
5323 (insert (format command candidate))
5324 (setq end (point))
5325 (if (y-or-n-p (format "%s package" (symbol-name action)))
5326 (progn
5327 (setq anything-c-external-commands-list nil)
5328 (setq anything-c-apt-installed-packages nil)
5329 (term-char-mode) (term-send-input))
5330 (delete-region beg end) (term-send-eof) (kill-buffer))))
5332 ;; (anything-c-apt-install "jed")
5334 ;;; Sources for gentoo users
5335 (defvar anything-c-gentoo-use-flags nil)
5336 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
5337 (defvar anything-c-cache-gentoo nil)
5338 (defvar anything-c-cache-world nil)
5339 (defvar anything-c-source-gentoo
5340 '((name . "Portage sources")
5341 (init . (lambda ()
5342 (get-buffer-create anything-c-gentoo-buffer)
5343 (unless anything-c-cache-gentoo
5344 (anything-c-gentoo-setup-cache))
5345 (unless anything-c-cache-world
5346 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
5347 (anything-c-gentoo-init-list)))
5348 (candidates-in-buffer)
5349 (match . identity)
5350 (candidate-transformer anything-c-highlight-world)
5351 (action . (("Show package" . (lambda (elm)
5352 (anything-c-gentoo-eshell-action elm "eix")))
5353 ("Show history" . (lambda (elm)
5354 (if (member elm anything-c-cache-world)
5355 (anything-c-gentoo-eshell-action elm "genlop -qe")
5356 (message "No infos on packages not yet installed"))))
5357 ("Copy in kill-ring" . kill-new)
5358 ("insert at point" . insert)
5359 ("Browse HomePage" . (lambda (elm)
5360 (let ((urls (anything-c-gentoo-get-url elm)))
5361 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
5362 ("Show extra infos" . (lambda (elm)
5363 (if (member elm anything-c-cache-world)
5364 (anything-c-gentoo-eshell-action elm "genlop -qi")
5365 (message "No infos on packages not yet installed"))))
5366 ("Show use flags" . (lambda (elm)
5367 (anything-c-gentoo-default-action elm "equery" "-C" "u")
5368 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
5369 (font-lock-mode 1)))
5370 ("Run emerge pretend" . (lambda (elm)
5371 (anything-c-gentoo-eshell-action elm "emerge -p")))
5372 ("Emerge" . (lambda (elm)
5373 (anything-gentoo-install elm :action 'install)))
5374 ("Unmerge" . (lambda (elm)
5375 (anything-gentoo-install elm :action 'uninstall)))
5376 ("Show dependencies" . (lambda (elm)
5377 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
5378 ("Show related files" . (lambda (elm)
5379 (anything-c-gentoo-default-action elm "equery" "files")))
5380 ("Refresh" . (lambda (elm)
5381 (anything-c-gentoo-setup-cache)
5382 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
5384 ;; (anything 'anything-c-source-gentoo)
5386 (defun* anything-gentoo-install (candidate &key action)
5387 (setq anything-c-external-commands-list nil)
5388 (ansi-term (getenv "SHELL") "anything gentoo")
5389 (term-line-mode)
5390 (let ((command (case action
5391 ('install "sudo emerge -av ")
5392 ('uninstall "sudo emerge -avC ")
5393 (t (error "Unknow action"))))
5394 (elms (mapconcat 'identity (anything-marked-candidates) " "))
5395 (beg (point)) end)
5396 (goto-char (point-max))
5397 (insert (concat command elms))
5398 (setq end (point))
5399 (term-char-mode) (term-send-input)))
5401 (defun anything-c-gentoo-default-action (elm command &rest args)
5402 "Gentoo default action that use `anything-c-gentoo-buffer'."
5403 (if (member elm anything-c-cache-world)
5404 (progn
5405 (switch-to-buffer anything-c-gentoo-buffer)
5406 (erase-buffer)
5407 (let ((com-list (append args (list elm))))
5408 (apply #'call-process command nil t nil
5409 com-list)))
5410 (message "No infos on packages not yet installed")))
5412 (defvar anything-c-source-use-flags
5413 '((name . "Use Flags")
5414 (init . (lambda ()
5415 (unless anything-c-gentoo-use-flags
5416 (anything-c-gentoo-setup-use-flags-cache))
5417 (anything-c-gentoo-get-use)))
5418 (candidates-in-buffer)
5419 (match . identity)
5420 (candidate-transformer anything-c-highlight-local-use)
5421 (action . (("Description"
5422 . (lambda (elm)
5423 (switch-to-buffer anything-c-gentoo-buffer)
5424 (erase-buffer)
5425 (apply #'call-process "euse" nil t nil
5426 `("-i"
5427 ,elm))
5428 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
5429 (font-lock-mode 1)))
5430 ("Enable"
5431 . (lambda (elm)
5432 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
5433 ("Disable"
5434 . (lambda (elm)
5435 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
5436 ("Remove"
5437 . (lambda (elm)
5438 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
5439 ("Show which dep use this flag"
5440 . (lambda (elm)
5441 (switch-to-buffer anything-c-gentoo-buffer)
5442 (erase-buffer)
5443 (apply #'call-process "equery" nil t nil
5444 `("-C"
5446 ,elm))))))))
5449 ;; (anything 'anything-c-source-use-flags)
5451 (defun anything-c-gentoo-init-list ()
5452 "Initialize buffer with all packages in Portage."
5453 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
5454 (buf (anything-candidate-buffer 'portage-buf)))
5455 (with-current-buffer buf
5456 (dolist (i anything-c-cache-gentoo)
5457 (insert (concat i "\n"))))))
5459 (defun anything-c-gentoo-setup-cache ()
5460 "Set up `anything-c-cache-gentoo'"
5461 (setq anything-c-cache-gentoo
5462 (split-string (with-temp-buffer
5463 (call-process "eix" nil t nil
5464 "--only-names")
5465 (buffer-string)))))
5467 (defun anything-c-gentoo-eshell-action (elm command)
5468 (when (get-buffer "*EShell Command Output*")
5469 (kill-buffer "*EShell Command Output*"))
5470 (message "Wait searching...")
5471 (let ((buf-fname (buffer-file-name anything-current-buffer)))
5472 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
5473 (progn
5474 (save-window-excursion
5475 (pop-to-buffer "*scratch*")
5476 (eshell-command (format "%s %s" command elm)))
5477 (pop-to-buffer "*EShell Command Output*"))
5478 (eshell-command (format "%s %s" command elm)))))
5480 (defun anything-c-gentoo-get-use ()
5481 "Initialize buffer with all use flags."
5482 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
5483 (buf (anything-candidate-buffer 'use-buf)))
5484 (with-current-buffer buf
5485 (dolist (i anything-c-gentoo-use-flags)
5486 (insert (concat i "\n"))))))
5489 (defun anything-c-gentoo-setup-use-flags-cache ()
5490 "Setup `anything-c-gentoo-use-flags'"
5491 (setq anything-c-gentoo-use-flags
5492 (split-string (with-temp-buffer
5493 (call-process "eix" nil t nil
5494 "--print-all-useflags")
5495 (buffer-string)))))
5497 (defun anything-c-gentoo-get-url (elm)
5498 "Return a list of urls from eix output."
5499 (loop
5500 with url-list = (split-string
5501 (with-temp-buffer
5502 (call-process "eix" nil t nil
5503 elm "--format" "<homepage>\n")
5504 (buffer-string)))
5505 with all
5506 for i in url-list
5507 when (and (string-match "^http://.*" i)
5508 (not (member i all)))
5509 collect i into all
5510 finally return all))
5512 (defun anything-c-gentoo-get-world ()
5513 "Return list of all installed package on your system."
5514 (split-string (with-temp-buffer
5515 (call-process "qlist" nil t nil
5516 "-I")
5517 (buffer-string))))
5519 (defun anything-c-gentoo-get-local-use ()
5520 (split-string (with-temp-buffer
5521 (call-process "portageq" nil t nil
5522 "envvar"
5523 "USE")
5524 (buffer-string))))
5526 (defface anything-gentoo-match-face '((t (:foreground "red")))
5527 "Face for anything-gentoo installed packages."
5528 :group 'traverse-faces)
5530 (defun anything-c-highlight-world (eix)
5531 "Highlight all installed package."
5532 (loop for i in eix
5533 if (member i anything-c-cache-world)
5534 collect (propertize i 'face 'anything-gentoo-match-face)
5535 else
5536 collect i))
5538 (defun anything-c-highlight-local-use (use-flags)
5539 (let ((local-uses (anything-c-gentoo-get-local-use)))
5540 (loop for i in use-flags
5541 if (member i local-uses)
5542 collect (propertize i 'face 'anything-gentoo-match-face)
5543 else
5544 collect i)))
5546 (defvar anything-c-source-emacs-process
5547 '((name . "Emacs Process")
5548 (candidates . (lambda () (mapcar #'process-name (process-list))))
5549 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
5551 ;; (anything 'anything-c-source-emacs-process)
5553 ;; Run Externals commands within Emacs
5554 (defmacro* anything-comp-hash-get-items (hash-table &key test)
5555 "Get the list of all keys/values of hash-table."
5556 `(let ((li-items ()))
5557 (maphash #'(lambda (x y)
5558 (if ,test
5559 (when (funcall ,test y)
5560 (push (list x y) li-items))
5561 (push (list x y) li-items)))
5562 ,hash-table)
5563 li-items))
5565 (defun anything-comp-read-get-candidates (collection &optional test)
5566 "Convert collection to list.
5567 If collection is an `obarray', a test is maybe needed, otherwise
5568 the list would be incomplete.
5569 See `obarray'."
5570 (cond ((and (listp collection) test)
5571 (loop for i in collection when (funcall test i) collect i))
5572 ((and (eq collection obarray) test)
5573 (loop for s being the symbols of collection
5574 when (funcall test s) collect s))
5575 ((and (vectorp collection) test)
5576 (loop for i across collection when (funcall test i) collect i))
5577 ((vectorp collection)
5578 (loop for i across collection collect i))
5579 ((and (hash-table-p collection) test)
5580 (anything-comp-hash-get-items collection :test test))
5581 ((hash-table-p collection)
5582 (anything-comp-hash-get-items collection))
5583 (t collection)))
5585 (defun* anything-comp-read (prompt collection &key test initial-input
5586 (buffer "*Anything Completions*") must-match
5587 (requires-pattern 0))
5588 "Anything `completing-read' emulation.
5589 Collection can be a list, vector, obarray or hash-table."
5590 (when (get-buffer anything-action-buffer)
5591 (kill-buffer anything-action-buffer))
5592 (or (anything
5593 `((name . "Completions")
5594 (candidates
5595 . (lambda ()
5596 (let ((cands (anything-comp-read-get-candidates collection test)))
5597 (if (or must-match (string= anything-pattern ""))
5598 cands (append (list anything-pattern) cands)))))
5599 (requires-pattern . ,requires-pattern)
5600 (volatile)
5601 (action . (("candidate" . ,'identity))))
5602 initial-input prompt 'noresume nil buffer)
5603 (keyboard-quit)))
5605 (defun anything-c-get-pid-from-process-name (process-name)
5606 "Get pid from running process PROCESS-NAME."
5607 (loop with process-list = (list-system-processes)
5608 for pid in process-list
5609 for process = (assoc-default 'comm (process-attributes pid))
5610 when (and process (string-match process-name process))
5611 return pid))
5614 (defun anything-run-or-raise (exe &optional file)
5615 "Generic command that run asynchronously EXE.
5616 If EXE is already running just jump to his window if `anything-raise-command'
5617 is non--nil.
5618 When FILE argument is provided run EXE with FILE.
5619 In this case EXE must be provided as \"EXE %s\"."
5620 (let ((real-com (car (split-string (replace-regexp-in-string " %s" "" exe)))))
5621 (if (or (get-process real-com)
5622 (anything-c-get-pid-from-process-name real-com))
5623 (if anything-raise-command
5624 (shell-command (format anything-raise-command real-com))
5625 (error "Error: %s is already running" real-com))
5626 (when (member real-com anything-c-external-commands-list)
5627 (message "Starting %s..." real-com)
5628 (if file
5629 (start-process-shell-command real-com nil (format exe file))
5630 (start-process-shell-command real-com nil real-com))
5631 (set-process-sentinel
5632 (get-process real-com)
5633 #'(lambda (process event)
5634 (when (string= event "finished\n")
5635 (when anything-raise-command
5636 (shell-command (format anything-raise-command "emacs")))
5637 (message "%s process...Finished." process))))
5638 (setq anything-c-external-commands-list
5639 (push (pop (nthcdr (anything-c-position
5640 real-com anything-c-external-commands-list
5641 :test 'equal)
5642 anything-c-external-commands-list))
5643 anything-c-external-commands-list))))))
5645 ;;;###autoload
5646 (defun anything-c-run-external-command (program)
5647 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
5648 If program is already running exit with error.
5649 You can set your own list of commands with
5650 `anything-c-external-commands-list'."
5651 (interactive (list
5652 (anything-comp-read
5653 "RunProgram: "
5654 (anything-c-external-commands-list-1 'sort)
5655 :must-match t)))
5656 (anything-run-or-raise program))
5658 (defsubst* anything-c-position (item seq &key (test 'eq))
5659 "A simple and faster replacement of CL `position'."
5660 (loop for i in seq for index from 0
5661 when (funcall test i item) return index))
5663 (defvar anything-c-source-ratpoison-commands
5664 '((name . "Ratpoison Commands")
5665 (init . anything-c-ratpoison-commands-init)
5666 (candidates-in-buffer)
5667 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
5668 (display-to-real . anything-c-ratpoison-commands-display-to-real)
5669 (candidate-number-limit)))
5670 ;; (anything 'anything-c-source-ratpoison-commands)
5672 (defun anything-c-ratpoison-commands-init ()
5673 (unless (anything-candidate-buffer)
5674 (with-current-buffer (anything-candidate-buffer 'global)
5675 ;; with ratpoison prefix key
5676 (save-excursion
5677 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
5678 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5679 (replace-match "<ratpoison> \\1: \\2"))
5680 (goto-char (point-max))
5681 ;; direct binding
5682 (save-excursion
5683 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
5684 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5685 (replace-match "\\1: \\2")))))
5687 (defun anything-c-ratpoison-commands-display-to-real (display)
5688 (and (string-match ": " display)
5689 (substring display (match-end 0))))
5691 (defun anything-c-ratpoison-commands-execute (candidate)
5692 (call-process "ratpoison" nil nil nil "-ic" candidate))
5694 ;;;###autoload
5695 (defun anything-ratpoison-commands ()
5696 "Preconfigured `anything' to execute ratpoison commands."
5697 (interactive)
5698 (anything-other-buffer 'anything-c-source-ratpoison-commands
5699 "*anything ratpoison commands*"))
5701 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5702 ;;; Files
5703 (defvar anything-c-external-commands-list nil
5704 "A list of all external commands the user can execute. If this
5705 variable is not set by the user, it will be calculated
5706 automatically.")
5708 (defun anything-c-external-commands-list-1 (&optional sort)
5709 "Returns a list of all external commands the user can execute.
5711 If `anything-c-external-commands-list' is non-nil it will
5712 return its contents. Else it calculates all external commands
5713 and sets `anything-c-external-commands-list'.
5715 The code is ripped out of `eshell-complete-commands-list'."
5716 (if anything-c-external-commands-list
5717 anything-c-external-commands-list
5718 (setq anything-c-external-commands-list
5719 (let* ((paths (split-string (getenv "PATH") path-separator))
5720 (cwd (file-name-as-directory
5721 (expand-file-name default-directory)))
5722 (path "") (comps-in-path ())
5723 (file "") (filepath "") (completions ()))
5724 ;; Go thru each path in the search path, finding completions.
5725 (while paths
5726 (setq path (file-name-as-directory
5727 (expand-file-name (or (car paths) ".")))
5728 comps-in-path
5729 (and (file-accessible-directory-p path)
5730 (file-name-all-completions "" path)))
5731 ;; Go thru each completion found, to see whether it should be
5732 ;; used, e.g. see if it's executable.
5733 (while comps-in-path
5734 (setq file (car comps-in-path)
5735 filepath (concat path file))
5736 (if (and (not (member file completions))
5737 (or (string-equal path cwd)
5738 (not (file-directory-p filepath)))
5739 (file-executable-p filepath))
5740 (setq completions (cons file completions)))
5741 (setq comps-in-path (cdr comps-in-path)))
5742 (setq paths (cdr paths)))
5743 (if sort
5744 (sort completions #'(lambda (x y) (string< x y)))
5745 completions)))))
5747 (defun anything-c-file-buffers (filename)
5748 "Returns a list of buffer names corresponding to FILENAME."
5749 (let ((name (expand-file-name filename))
5750 (buf-list ()))
5751 (dolist (buf (buffer-list) buf-list)
5752 (let ((bfn (buffer-file-name buf)))
5753 (when (and bfn (string= name bfn))
5754 (push (buffer-name buf) buf-list))))))
5756 (defun anything-c-delete-file (file)
5757 "Delete the given file after querying the user.
5758 Ask to kill buffers associated with that file, too."
5759 (let ((buffers (anything-c-file-buffers file)))
5760 (dired-delete-file file 'dired-recursive-deletes)
5761 (when buffers
5762 (dolist (buf buffers)
5763 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
5764 (kill-buffer buf))))))
5766 (defun anything-get-mailcap-for-file (filename)
5767 "Get the command to use for FILENAME from mailcap files.
5768 The command is like <command %s> and is meant to use with `format'."
5769 (mailcap-parse-mailcaps)
5770 (let* ((ext (file-name-extension filename))
5771 (mime (when ext (mailcap-extension-to-mime ext))))
5772 (when mime (mailcap-mime-info mime))))
5774 (defun anything-c-open-file-externally (file)
5775 "Open FILE with an external tool found in .mailcap file.
5776 If not found or a prefix arg is given query the user which tool to use."
5777 (let* ((fname (expand-file-name file))
5778 (collection (anything-c-external-commands-list-1 'sort))
5779 (def-prog (anything-get-mailcap-for-file fname))
5780 (program (or (unless (or anything-current-prefix-arg
5781 (not def-prog))
5782 def-prog)
5783 (concat
5784 (anything-comp-read
5785 "Program: "
5786 collection :must-match t)
5787 " %s"))))
5788 (anything-run-or-raise program file)))
5790 ;;;###autoload
5791 (defun w32-shell-execute-open-file (file)
5792 (interactive "fOpen file:")
5793 (with-no-warnings
5794 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
5795 "/" "\\"
5796 (replace-regexp-in-string ; strip cygdrive paths
5797 "/cygdrive/\\(.\\)" "\\1:"
5798 file nil nil) nil t))))
5800 (defun anything-c-open-file-with-default-tool (file)
5801 "Open FILE with the default tool on this platform."
5802 (if (eq system-type 'windows-nt)
5803 (w32-shell-execute-open-file file)
5804 (start-process "anything-c-open-file-with-default-tool"
5806 (cond ((eq system-type 'gnu/linux)
5807 "xdg-open")
5808 ((or (eq system-type 'darwin) ;; Mac OS X
5809 (eq system-type 'macos)) ;; Mac OS 9
5810 "open"))
5811 file)))
5813 (defun anything-c-open-dired (file)
5814 "Opens a dired buffer in FILE's directory. If FILE is a
5815 directory, open this directory."
5816 (if (file-directory-p file)
5817 (dired file)
5818 (dired (file-name-directory file))
5819 (dired-goto-file file)))
5821 (defun anything-c-display-to-real-line (candidate)
5822 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
5823 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
5824 (error "Line number not found")))
5826 (defun anything-c-action-line-goto (lineno-and-content)
5827 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
5828 (append lineno-and-content
5829 (list (if (and (anything-attr-defined 'target-file)
5830 (not anything-in-persistent-action))
5831 'find-file-other-window
5832 'find-file)))))
5834 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
5835 (apply #'anything-goto-file-line
5836 (if (stringp file-line-content)
5837 ;; Case: filtered-candidate-transformer is skipped
5838 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
5839 file-line-content)))
5841 (require 'compile)
5842 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
5843 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
5845 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
5846 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
5847 (let ((filename (match-string 1 candidate))
5848 (lineno (match-string 2 candidate))
5849 (content (match-string 3 candidate)))
5850 (cons (format "%s:%s\n %s"
5851 (propertize filename 'face compilation-info-face)
5852 (propertize lineno 'face compilation-line-face)
5853 content)
5854 (list (expand-file-name
5855 filename
5856 (or (anything-interpret-value (anything-attr 'default-directory))
5857 (and (anything-candidate-buffer)
5858 (buffer-local-value
5859 'default-directory (anything-candidate-buffer)))))
5860 (string-to-number lineno) content)))))
5862 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
5863 (anything-aif (anything-attr 'before-jump-hook)
5864 (funcall it))
5865 (when file (funcall find-file-function file))
5866 (if (anything-attr-defined 'adjust)
5867 (anything-c-goto-line-with-adjustment lineno content)
5868 (anything-goto-line lineno))
5869 (unless (anything-attr-defined 'recenter)
5870 (set-window-start (get-buffer-window anything-current-buffer) (point)))
5871 (anything-aif (anything-attr 'after-jump-hook)
5872 (funcall it))
5873 (when anything-in-persistent-action
5874 (anything-match-line-color-current-line)))
5876 (defun anything-find-file-as-root (candidate)
5877 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
5879 (defun anything-find-many-files (ignore)
5880 (mapc 'find-file (anything-marked-candidates)))
5882 ;; borrowed from etags.el
5883 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
5884 (defun anything-c-goto-line-with-adjustment (line line-content)
5885 (let ((startpos)
5886 offset found pat)
5887 ;; This constant is 1/2 the initial search window.
5888 ;; There is no sense in making it too small,
5889 ;; since just going around the loop once probably
5890 ;; costs about as much as searching 2000 chars.
5891 (setq offset 1000
5892 found nil
5893 pat (concat (if (eq selective-display t)
5894 "\\(^\\|\^m\\) *" "^ *") ;allow indent
5895 (regexp-quote line-content)))
5896 ;; If no char pos was given, try the given line number.
5897 (setq startpos (progn (anything-goto-line line) (point)))
5898 (or startpos (setq startpos (point-min)))
5899 ;; First see if the tag is right at the specified location.
5900 (goto-char startpos)
5901 (setq found (looking-at pat))
5902 (while (and (not found)
5903 (progn
5904 (goto-char (- startpos offset))
5905 (not (bobp))))
5906 (setq found
5907 (re-search-forward pat (+ startpos offset) t)
5908 offset (* 3 offset))) ; expand search window
5909 (or found
5910 (re-search-forward pat nil t)
5911 (error "not found")))
5912 ;; Position point at the right place
5913 ;; if the search string matched an extra Ctrl-m at the beginning.
5914 (and (eq selective-display t)
5915 (looking-at "\^m")
5916 (forward-char 1))
5917 (beginning-of-line))
5919 (anything-document-attribute 'default-directory "type . file-line"
5920 "`default-directory' to interpret file.")
5921 (anything-document-attribute 'before-jump-hook "type . file-line / line"
5922 "Function to call before jumping to the target location.")
5923 (anything-document-attribute 'after-jump-hook "type . file-line / line"
5924 "Function to call after jumping to the target location.")
5925 (anything-document-attribute 'adjust "type . file-line"
5926 "Search around line matching line contents.")
5927 (anything-document-attribute 'recenter "type . file-line / line"
5928 "`recenter' after jumping.")
5929 (anything-document-attribute 'target-file "type . line"
5930 "Goto line of target-file.")
5932 ;;;###autoload
5933 (defun anything-c-call-interactively (cmd-or-name)
5934 "Execute CMD-OR-NAME as Emacs command.
5935 It is added to `extended-command-history'.
5936 `anything-current-prefix-arg' is used as the command's prefix argument."
5937 (setq extended-command-history
5938 (cons (anything-c-stringify cmd-or-name)
5939 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
5940 (let ((current-prefix-arg anything-current-prefix-arg)
5941 (cmd (anything-c-symbolify cmd-or-name)))
5942 (if (stringp (symbol-function cmd))
5943 (execute-kbd-macro (symbol-function cmd))
5944 (setq this-command cmd)
5945 (call-interactively cmd))))
5947 ;;;###autoload
5948 (defun anything-c-set-variable (var)
5949 "Set value to VAR interactively."
5950 (interactive)
5951 (let ((sym (anything-c-symbolify var)))
5952 (set sym (eval-minibuffer (format "Set %s: " var)
5953 (prin1-to-string (symbol-value sym))))))
5954 ;; (setq hh 12)
5955 ;; (anything-c-set-variable 'hh)
5957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5958 (defvar anything-match-line-overlay-face nil)
5959 (defvar anything-match-line-overlay nil)
5961 (defun anything-match-line-color-current-line (&optional start end buf face rec)
5962 "Highlight and underline current position"
5963 (let ((args (list (or start (line-beginning-position))
5964 (or end (1+ (line-end-position)))
5965 buf)))
5966 (if (not anything-match-line-overlay)
5967 (setq anything-match-line-overlay (apply 'make-overlay args))
5968 (apply 'move-overlay anything-match-line-overlay args)))
5969 (overlay-put anything-match-line-overlay
5970 'face (or face anything-match-line-overlay-face))
5971 (when rec
5972 (goto-char start)
5973 (recenter)))
5975 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
5977 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
5978 "Face for source header in the anything buffer." :group 'anything)
5980 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
5982 (defun anything-match-line-cleanup ()
5983 (when anything-match-line-overlay
5984 (delete-overlay anything-match-line-overlay)
5985 (setq anything-match-line-overlay nil)))
5987 (defun anything-match-line-update ()
5988 (when anything-match-line-overlay
5989 (delete-overlay anything-match-line-overlay)
5990 (anything-match-line-color-current-line)))
5992 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
5993 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
5995 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5996 ;;; Files
5997 (defun anything-c-transform-file-load-el (actions candidate)
5998 "Add action to load the file CANDIDATE if it is an emacs lisp
5999 file. Else return ACTIONS unmodified."
6000 (if (member (file-name-extension candidate) '("el" "elc"))
6001 (append actions '(("Load Emacs Lisp File" . load-file)))
6002 actions))
6004 (defun anything-c-transform-file-browse-url (actions candidate)
6005 "Add an action to browse the file CANDIDATE if it in a html
6006 file or URL. Else return ACTIONS unmodified."
6007 (let ((browse-action '("Browse with Browser" . browse-url)))
6008 (cond ((string-match "^http\\|^ftp" candidate)
6009 (cons browse-action actions))
6010 ((string-match "\\.html?$" candidate)
6011 (append actions (list browse-action)))
6012 (t actions))))
6014 ;;;; Function
6015 (defun anything-c-transform-function-call-interactively (actions candidate)
6016 "Add an action to call the function CANDIDATE interactively if
6017 it is a command. Else return ACTIONS unmodified."
6018 (if (commandp (intern-soft candidate))
6019 (append actions '(("Call Interactively"
6021 anything-c-call-interactively)))
6022 actions))
6024 ;;;; S-Expressions
6025 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
6026 "If CANDIDATE's `car' is a command, then add an action to
6027 evaluate it and put it onto the `command-history'."
6028 (if (commandp (car (read candidate)))
6029 ;; Make it first entry
6030 (cons '("Eval and put onto command-history" .
6031 (lambda (sexp)
6032 (let ((sym (read sexp)))
6033 (eval sym)
6034 (setq command-history
6035 (cons sym command-history)))))
6036 actions)
6037 actions))
6039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6040 ;;; Buffers
6041 (defun anything-c-skip-boring-buffers (buffers)
6042 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
6044 (defun anything-c-skip-current-buffer (buffers)
6045 (if anything-allow-skipping-current-buffer
6046 (remove (buffer-name anything-current-buffer) buffers)
6047 buffers))
6049 (defun anything-c-shadow-boring-buffers (buffers)
6050 "Buffers matching `anything-c-boring-buffer-regexp' will be
6051 displayed with the `file-name-shadow' face if available."
6052 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
6054 ;;; Files
6055 (defun anything-c-shadow-boring-files (files)
6056 "Files matching `anything-c-boring-file-regexp' will be
6057 displayed with the `file-name-shadow' face if available."
6058 (anything-c-shadow-entries files anything-c-boring-file-regexp))
6060 (defun anything-c-skip-boring-files (files)
6061 "Files matching `anything-c-boring-file-regexp' will be skipped."
6062 (anything-c-skip-entries files anything-c-boring-file-regexp))
6063 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6065 (defun anything-c-skip-current-file (files)
6066 "Current file will be skipped."
6067 (remove (buffer-file-name anything-current-buffer) files))
6069 (defun anything-c-w32-pathname-transformer (args)
6070 "Change undesirable features of windows pathnames to ones more acceptable to
6071 other candidate transformers."
6072 (if (eq system-type 'windows-nt)
6073 (mapcar (lambda (x)
6074 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
6075 (mapcar (lambda (y)
6076 (replace-regexp-in-string "\\\\" "/" y)) args))
6077 args))
6079 (defun anything-c-shorten-home-path (files)
6080 "Replaces /home/user with ~."
6081 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6082 (getenv "HOME"))))
6083 (mapcar (lambda (file)
6084 (if (and (stringp file) (string-match home file))
6085 (cons (replace-match "~" nil nil file) file)
6086 file))
6087 files)))
6089 ;;; Functions
6090 (defun anything-c-mark-interactive-functions (functions)
6091 "Mark interactive functions (commands) with (i) after the function name."
6092 (let (list)
6093 (loop for function in functions
6094 do (push (cons (concat function
6095 (when (commandp (intern-soft function)) " (i)"))
6096 function)
6097 list)
6098 finally (return (nreverse list)))))
6100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6101 (defvar anything-c-adaptive-done nil
6102 "nil if history information is not yet stored for the current
6103 selection.")
6105 (defvar anything-c-adaptive-history nil
6106 "Contains the stored history information.
6107 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6109 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
6110 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6111 when anything is started."
6112 (setq anything-c-adaptive-done nil))
6114 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
6115 "Advise `anything-exit-minibuffer' to store history information
6116 when a candidate is selected with RET."
6117 (anything-c-adaptive-store-selection))
6119 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
6120 "Advise `anything-select-action' to store history information
6121 when the user goes to the action list with TAB."
6122 (anything-c-adaptive-store-selection))
6124 (defun anything-c-source-use-adaptative-p (&optional source-name)
6125 "Return current source only if it use adaptative history, nil otherwise."
6126 (let* ((source (or source-name (anything-get-current-source)))
6127 (adapt-source (or (assoc-default 'filtered-candidate-transformer
6128 (assoc (assoc-default 'type source)
6129 anything-type-attributes))
6130 (assoc-default 'candidate-transformer
6131 (assoc (assoc-default 'type source)
6132 anything-type-attributes))
6133 (assoc-default 'filtered-candidate-transformer source)
6134 (assoc-default 'candidate-transformer source))))
6135 (if (listp adapt-source)
6136 (when (member 'anything-c-adaptive-sort adapt-source) source)
6137 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
6139 (defun anything-c-adaptive-store-selection ()
6140 "Store history information for the selected candidate."
6141 (unless anything-c-adaptive-done
6142 (setq anything-c-adaptive-done t)
6143 (let ((source (anything-c-source-use-adaptative-p)))
6144 (when source
6145 (let* ((source-name (or (assoc-default 'type source)
6146 (assoc-default 'name source)))
6147 (source-info (or (assoc source-name anything-c-adaptive-history)
6148 (progn
6149 (push (list source-name) anything-c-adaptive-history)
6150 (car anything-c-adaptive-history))))
6151 (selection (anything-get-selection))
6152 (selection-info (progn
6153 (setcdr source-info
6154 (cons
6155 (let ((found (assoc selection (cdr source-info))))
6156 (if (not found)
6157 ;; new entry
6158 (list selection)
6160 ;; move entry to the beginning of the
6161 ;; list, so that it doesn't get
6162 ;; trimmed when the history is
6163 ;; truncated
6164 (setcdr source-info
6165 (delete found (cdr source-info)))
6166 found))
6167 (cdr source-info)))
6168 (cadr source-info)))
6169 (pattern-info (progn
6170 (setcdr selection-info
6171 (cons
6172 (let ((found (assoc anything-pattern (cdr selection-info))))
6173 (if (not found)
6174 ;; new entry
6175 (cons anything-pattern 0)
6177 ;; move entry to the beginning of the
6178 ;; list, so if two patterns used the
6179 ;; same number of times then the one
6180 ;; used last appears first in the list
6181 (setcdr selection-info
6182 (delete found (cdr selection-info)))
6183 found))
6184 (cdr selection-info)))
6185 (cadr selection-info))))
6187 ;; increase usage count
6188 (setcdr pattern-info (1+ (cdr pattern-info)))
6190 ;; truncate history if needed
6191 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
6192 (setcdr selection-info
6193 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
6195 (if (file-readable-p anything-c-adaptive-history-file)
6196 (load-file anything-c-adaptive-history-file))
6197 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
6199 (defun anything-c-adaptive-save-history ()
6200 "Save history information to file given by `anything-c-adaptive-history-file'."
6201 (interactive)
6202 (with-temp-buffer
6203 (insert
6204 ";; -*- mode: emacs-lisp -*-\n"
6205 ";; History entries used for anything adaptive display.\n")
6206 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
6207 (current-buffer))
6208 (insert ?\n)
6209 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
6210 (unless (interactive-p) 'quiet))))
6212 (defun anything-c-adaptive-sort (candidates source)
6213 "Sort the CANDIDATES for SOURCE by usage frequency.
6214 This is a filtered candidate transformer you can use for the
6215 attribute `filtered-candidate-transformer' of a source in
6216 `anything-sources' or a type in `anything-type-attributes'."
6217 (let* ((source-name (or (assoc-default 'type source)
6218 (assoc-default 'name source)))
6219 (source-info (assoc source-name anything-c-adaptive-history)))
6220 (if (not source-info)
6221 ;; if there is no information stored for this source then do nothing
6222 candidates
6223 ;; else...
6224 (let ((usage
6225 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
6226 ;; pairs
6227 (mapcar (lambda (candidate-info)
6228 (let ((count 0))
6229 (dolist (pattern-info (cdr candidate-info))
6230 (if (not (equal (car pattern-info)
6231 anything-pattern))
6232 (incf count (cdr pattern-info))
6234 ;; if current pattern is equal to the previously
6235 ;; used one then this candidate has priority
6236 ;; (that's why its count is boosted by 10000) and
6237 ;; it only has to compete with other candidates
6238 ;; which were also selected with the same pattern
6239 (setq count (+ 10000 (cdr pattern-info)))
6240 (return)))
6241 (cons (car candidate-info) count)))
6242 (cdr source-info)))
6243 sorted)
6245 ;; sort the list in descending order, so candidates with highest
6246 ;; priorty come first
6247 (setq usage (sort usage (lambda (first second)
6248 (> (cdr first) (cdr second)))))
6250 ;; put those candidates first which have the highest usage count
6251 (dolist (info usage)
6252 (when (member* (car info) candidates
6253 :test 'anything-c-adaptive-compare)
6254 (push (car info) sorted)
6255 (setq candidates (remove* (car info) candidates
6256 :test 'anything-c-adaptive-compare))))
6258 ;; and append the rest
6259 (append (reverse sorted) candidates nil)))))
6261 (defun anything-c-adaptive-compare (x y)
6262 "Compare candidates X and Y taking into account that the
6263 candidate can be in (DISPLAY . REAL) format."
6264 (equal (if (listp x)
6265 (cdr x)
6267 (if (listp y)
6268 (cdr y)
6269 y)))
6271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6272 (defvar anything-outline-goto-near-line-flag t)
6273 (defvar anything-outline-using nil)
6274 (defun anything-after-update-hook--outline ()
6275 (if (and (eq anything-outline-using t)
6276 (eq anything-outline-goto-near-line-flag t))
6277 (anything-outline-goto-near-line)))
6278 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
6280 (defun anything-outline-goto-near-line ()
6281 (with-anything-window
6282 ;; TODO need consideration whether to update position by every input.
6283 (when t ; (equal anything-pattern "")
6284 (anything-goto-line 2)
6285 (let ((lineno (with-current-buffer anything-current-buffer
6286 (line-number-at-pos (car anything-current-position)))))
6287 (block exit
6288 (while (<= (progn (skip-chars-forward " ")
6289 (or (number-at-point) lineno))
6290 lineno)
6291 (forward-line 1)
6292 (when (eobp)
6293 (forward-line -1)
6294 (return-from exit))))
6295 (forward-line -1)
6296 (and (bobp) (forward-line 1))
6297 (and (anything-pos-header-line-p) (forward-line -2))
6298 (anything-mark-current-line)))))
6300 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6301 ;; Plug-in: info-index
6302 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
6303 (let (result)
6304 (unless (anything-candidate-buffer)
6305 (save-window-excursion
6306 (info file)
6307 (let (Info-history
6308 (tobuf (anything-candidate-buffer 'global))
6309 (infobuf (current-buffer))
6310 s e)
6311 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
6312 (Info-goto-node node)
6313 (goto-char (point-min))
6314 (while (search-forward "\n* " nil t)
6315 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
6316 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
6317 (setq s (point-at-bol)
6318 e (point-at-eol))
6319 (with-current-buffer tobuf
6320 (insert-buffer-substring infobuf s e)
6321 (insert "\n"))))))))))
6323 (defun anything-c-info-goto (node-line)
6324 (Info-goto-node (car node-line))
6325 (anything-goto-line (cdr node-line)))
6327 (defun anything-c-info-display-to-real (line)
6328 (and (string-match
6329 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
6330 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
6331 (string-to-number (or (match-string 3 line) "1")))))
6333 (defun anything-c-make-info-source (file)
6334 `((name . ,(concat "Info Index: " file))
6335 (info-file . ,file)
6336 (init . anything-c-info-init)
6337 (display-to-real . anything-c-info-display-to-real)
6338 (get-line . buffer-substring)
6339 (candidates-in-buffer)
6340 (action ("Goto node" . anything-c-info-goto))))
6342 (defun anything-compile-source--info-index (source)
6343 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
6344 (anything-c-make-info-source it)
6345 source))
6346 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
6348 (anything-document-attribute 'info-index "info-index plugin"
6349 "Create a source of info index very easily.
6351 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
6353 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
6354 "Index nodes of info file.
6356 If it is omitted, `Info-index-nodes' is used to collect index nodes.
6357 Some info files are missing index specification.
6359 ex. See `anything-c-source-info-screen'.")
6361 ;; Plug-in: candidates-file
6362 (defun anything-compile-source--candidates-file (source)
6363 (if (assoc-default 'candidates-file source)
6364 `((init anything-p-candidats-file-init
6365 ,@(let ((orig-init (assoc-default 'init source)))
6366 (cond ((null orig-init) nil)
6367 ((functionp orig-init) (list orig-init))
6368 (t orig-init))))
6369 (candidates-in-buffer)
6370 ,@source)
6371 source))
6372 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
6374 (defun anything-p-candidats-file-init ()
6375 (destructuring-bind (file &optional updating)
6376 (anything-mklist (anything-attr 'candidates-file))
6377 (setq file (anything-interpret-value file))
6378 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
6379 (when updating
6380 (buffer-disable-undo)
6381 (font-lock-mode -1)
6382 (auto-revert-mode 1)))))
6384 (anything-document-attribute 'candidates-file "candidates-file plugin"
6385 "Use a file as the candidates buffer.
6387 1st argument is a filename, string or function name or variable name.
6388 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
6390 ;; Plug-in: headline
6391 (defun anything-compile-source--anything-headline (source)
6392 (if (assoc-default 'headline source)
6393 (append '((init . anything-headline-init)
6394 (get-line . buffer-substring)
6395 (type . line))
6396 source
6397 '((candidates-in-buffer)
6398 (persistent-help . "Show this line")))
6399 source))
6400 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
6402 (defun anything-headline-init ()
6403 (when (and (anything-current-buffer-is-modified)
6404 (with-current-buffer anything-current-buffer
6405 (eval (or (anything-attr 'condition) t))))
6406 (anything-headline-make-candidate-buffer
6407 (anything-interpret-value (anything-attr 'headline))
6408 (anything-interpret-value (anything-attr 'subexp)))))
6410 (anything-document-attribute 'headline "Headline plug-in"
6411 "Regexp string for anything-headline to scan.")
6412 (anything-document-attribute 'condition "Headline plug-in"
6413 "A sexp representing the condition to use anything-headline.")
6414 (anything-document-attribute 'subexp "Headline plug-in"
6415 "Display (match-string-no-properties subexp).")
6418 (defun anything-headline-get-candidates (regexp subexp)
6419 (with-current-buffer anything-current-buffer
6420 (save-excursion
6421 (goto-char (point-min))
6422 (if (functionp regexp) (setq regexp (funcall regexp)))
6423 (let (hierarchy curhead)
6424 (flet ((matched ()
6425 (if (numberp subexp)
6426 (cons (match-string-no-properties subexp) (match-beginning subexp))
6427 (cons (buffer-substring (point-at-bol) (point-at-eol))
6428 (point-at-bol))))
6429 (hierarchies (headlines)
6430 (1+ (loop for (_ . hierarchy) in headlines
6431 maximize hierarchy)))
6432 (vector-0-n (v n)
6433 (loop for i from 0 to hierarchy
6434 collecting (aref curhead i)))
6435 (arrange (headlines)
6436 (unless (null headlines) ; FIX headlines empty bug!
6437 (loop with curhead = (make-vector (hierarchies headlines) "")
6438 for ((str . pt) . hierarchy) in headlines
6439 do (aset curhead hierarchy str)
6440 collecting
6441 (cons
6442 (format "H%d:%s" (1+ hierarchy)
6443 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
6444 pt)))))
6445 (if (listp regexp)
6446 (arrange
6447 (sort
6448 (loop for re in regexp
6449 for hierarchy from 0
6450 do (goto-char (point-min))
6451 appending
6452 (loop
6453 while (re-search-forward re nil t)
6454 collect (cons (matched) hierarchy)))
6455 (lambda (a b) (> (cdar b) (cdar a)))))
6456 (loop while (re-search-forward regexp nil t)
6457 collect (matched))))))))
6460 (defun anything-headline-make-candidate-buffer (regexp subexp)
6461 (with-current-buffer (anything-candidate-buffer 'local)
6462 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
6463 do (insert
6464 (format "%5d:%s\n"
6465 (with-current-buffer anything-current-buffer
6466 (line-number-at-pos pos))
6467 content)))))
6469 (defun anything-headline-goto-position (pos recenter)
6470 (goto-char pos)
6471 (unless recenter
6472 (set-window-start (get-buffer-window anything-current-buffer) (point))))
6474 (defun anything-revert-buffer (candidate)
6475 (with-current-buffer candidate
6476 (when (buffer-modified-p)
6477 (revert-buffer t t))))
6479 (defun anything-revert-marked-buffers (candidate)
6480 (dolist (i (anything-marked-candidates))
6481 (anything-revert-buffer i)))
6483 (defun anything-kill-marked-buffers (candidate)
6484 (dolist (i (anything-marked-candidates))
6485 (kill-buffer i)))
6487 ;; Plug-in: persistent-help
6488 (defun anything-compile-source--persistent-help (source)
6489 (append source '((header-line . anything-persistent-help-string))))
6490 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
6492 (defun anything-persistent-help-string ()
6493 (substitute-command-keys
6494 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
6495 (or (anything-interpret-value (anything-attr 'persistent-help))
6496 (anything-aif (or (assoc-default 'persistent-action
6497 (anything-get-current-source))
6498 (assoc-default 'action
6499 (anything-get-current-source)))
6500 (cond ((symbolp it) (symbol-name it))
6501 ((listp it) (or (ignore-errors (caar it)) ""))))
6503 " (keeping session)")))
6505 (anything-document-attribute 'persistent-help "persistent-help plug-in"
6506 "A string to explain persistent-action of this source.
6507 It also accepts a function or a variable name.")
6509 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
6511 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6513 (defun anything-c-find-file-or-marked (candidate)
6514 "Open file CANDIDATE or open anything marked files in background."
6515 (let ((marked (anything-marked-candidates)))
6516 (if (> (length marked) 1)
6517 (dolist (i marked) (find-file-noselect i))
6518 (find-file-at-point candidate))))
6520 ;; FIXME there is a bug in dired that confuse all dired commands
6521 ;; when using this feature, so i suspend it until bug is fixed in emacs.
6523 ;; (defun anything-c-create-dired-on-marked (candidate)
6524 ;; "Create a new dired buffer with only marked candidates."
6525 ;; (let ((marked (anything-marked-candidates))
6526 ;; (buffer-name (read-string "New Dired Buffer: ")))
6527 ;; (dired (cons buffer-name marked))))
6529 (defun anything-delete-marked-files (ignore)
6530 (let* ((files (anything-marked-candidates))
6531 (len (length files)))
6532 (if (not (y-or-n-p
6533 (format "Delete *%s File(s):\n%s"
6535 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
6536 (message "(No deletions performed)")
6537 (dolist (i files)
6538 (set-text-properties 0 (length i) nil i)
6539 (anything-c-delete-file i))
6540 (message "%s File(s) deleted" len))))
6542 (defun anything-ediff-marked-buffers (candidate &optional merge)
6543 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
6544 With optional arg `merge' call `ediff-merge-buffers'."
6545 (let ((lg-lst (length (anything-marked-candidates)))
6546 buf1 buf2)
6547 (case lg-lst
6549 (error "Error:You have to mark at least 1 buffer"))
6551 (setq buf1 anything-current-buffer
6552 buf2 (first (anything-marked-candidates))))
6554 (setq buf1 (first (anything-marked-candidates))
6555 buf2 (second (anything-marked-candidates))))
6557 (error "Error:To much buffers marked!")))
6558 (if merge
6559 (ediff-merge-buffers buf1 buf2)
6560 (ediff-buffers buf1 buf2))))
6562 (defun anything-bookmark-get-bookmark-from-name (bmk)
6563 "Return bookmark name even if it is a bookmark with annotation.
6564 e.g prepended with *.
6565 Return nil if bmk is not a valid bookmark."
6566 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
6567 (if (assoc bookmark bookmark-alist)
6568 bookmark
6569 (when (assoc bmk bookmark-alist)
6570 bmk))))
6572 (defun anything-delete-marked-bookmarks (elm)
6573 "Delete this bookmark or all marked bookmarks."
6574 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
6575 (anything-aif (anything-marked-candidates)
6576 (dolist (i it)
6577 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
6578 (bookmark-delete bmk 'batch)))
6579 (bookmark-delete bookmark 'batch))))
6581 (defun anything-require-or-error (feature function)
6582 (or (require feature nil t)
6583 (error "Need %s to use `%s'." feature function)))
6585 (defun anything-find-buffer-on-elscreen (candidate)
6586 "Open buffer in new screen, if marked buffers open all in elscreens."
6587 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
6588 (anything-aif (anything-marked-candidates)
6589 (dolist (i it)
6590 (let ((target-screen (elscreen-find-screen-by-buffer
6591 (get-buffer i) 'create)))
6592 (elscreen-goto target-screen)))
6593 (let ((target-screen (elscreen-find-screen-by-buffer
6594 (get-buffer candidate) 'create)))
6595 (elscreen-goto target-screen))))
6597 (defun anything-elscreen-find-file (file)
6598 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
6599 (elscreen-find-file file))
6601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6603 ;;;; Type Attributes
6604 (define-anything-type-attribute 'buffer
6605 `((action
6606 ,@(if pop-up-frames
6607 '(("Switch to buffer other window" . switch-to-buffer-other-window)
6608 ("Switch to buffer" . switch-to-buffer))
6609 '(("Switch to buffer" . switch-to-buffer)
6610 ("Switch to buffer other window" . switch-to-buffer-other-window)
6611 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
6612 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
6613 ("Display buffer" . display-buffer)
6614 ("Revert buffer" . anything-revert-buffer)
6615 ("Revert Marked buffers" . anything-revert-marked-buffers)
6616 ("Kill buffer" . kill-buffer)
6617 ("Kill Marked buffers" . anything-kill-marked-buffers)
6618 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
6619 ("Ediff Merge marked buffers" . (lambda (candidate)
6620 (anything-ediff-marked-buffers candidate t))))
6621 (persistent-help . "Show this buffer")
6622 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
6623 "Buffer or buffer name.")
6625 (define-anything-type-attribute 'file
6626 `((action
6627 ,@(if pop-up-frames
6628 '(("Find file other window" . find-file-other-window)
6629 ("Find file(s)" . anything-find-many-files)
6630 ("Find file as root" . anything-find-file-as-root))
6631 '(("Find file" . anything-find-many-files)
6632 ("Find file as root" . anything-find-file-as-root)
6633 ("Find file other window" . find-file-other-window)
6634 ("Find file other frame" . find-file-other-frame)))
6635 ("Open dired in file's directory" . anything-c-open-dired)
6636 ("Delete file(s)" . anything-delete-marked-files)
6637 ("Open file externally" . anything-c-open-file-externally)
6638 ("Open file with default tool" . anything-c-open-file-with-default-tool))
6639 (persistent-help . "Show this file")
6640 (action-transformer anything-c-transform-file-load-el
6641 anything-c-transform-file-browse-url)
6642 (candidate-transformer anything-c-w32-pathname-transformer
6643 anything-c-skip-current-file
6644 anything-c-skip-boring-files
6645 anything-c-shorten-home-path))
6646 "File name.")
6648 (define-anything-type-attribute 'command
6649 `((action ("Call interactively" . anything-c-call-interactively)
6650 ("Describe command" . anything-c-describe-function)
6651 ("Add command to kill ring" . anything-c-kill-new)
6652 ("Go to command's definition" . anything-c-find-function))
6653 ;; Sort commands according to their usage count.
6654 (filtered-candidate-transformer . anything-c-adaptive-sort)
6655 (persistent-action . anything-c-describe-function))
6656 "Command. (string or symbol)")
6658 (define-anything-type-attribute 'function
6659 '((action ("Describe function" . anything-c-describe-function)
6660 ("Add function to kill ring" . anything-c-kill-new)
6661 ("Go to function's definition" . anything-c-find-function))
6662 (action-transformer anything-c-transform-function-call-interactively)
6663 (candidate-transformer anything-c-mark-interactive-functions))
6664 "Function. (string or symbol)")
6666 (define-anything-type-attribute 'variable
6667 '((action ("Describe variable" . anything-c-describe-variable)
6668 ("Add variable to kill ring" . anything-c-kill-new)
6669 ("Go to variable's definition" . anything-c-find-variable)
6670 ("Set variable" . anything-c-set-variable)))
6671 "Variable.")
6673 (define-anything-type-attribute 'sexp
6674 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
6675 ("Add s-expression to kill ring" . kill-new))
6676 (action-transformer anything-c-transform-sexp-eval-command-sexp))
6677 "String representing S-Expressions.")
6679 (define-anything-type-attribute 'bookmark
6680 `((action
6681 ("Jump to bookmark" . (lambda (candidate)
6682 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate))
6683 (current-prefix-arg anything-current-prefix-arg))
6684 (bookmark-jump bookmark))
6685 (anything-update)))
6686 ("Jump to BM other window" . (lambda (candidate)
6687 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6688 (bookmark-jump-other-window bookmark))
6689 (anything-update)))
6690 ("Bookmark edit annotation" . (lambda (candidate)
6691 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6692 (bookmark-edit-annotation bookmark))))
6693 ("Bookmark show annotation" . (lambda (candidate)
6694 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6695 (bookmark-show-annotation bookmark))))
6696 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
6697 ,@(when (fboundp 'bmkext-edit-bookmark)
6698 '(("Edit Bookmark" . (lambda (candidate)
6699 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6700 (bmkext-edit-bookmark bookmark))))))
6701 ("Rename bookmark" . (lambda (candidate)
6702 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6703 (bookmark-rename bookmark))))
6704 ("Relocate bookmark" . (lambda (candidate)
6705 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6706 (bookmark-relocate bookmark))))))
6707 "Bookmark name.")
6709 (define-anything-type-attribute 'line
6710 '((display-to-real . anything-c-display-to-real-line)
6711 (action ("Go to Line" . anything-c-action-line-goto)))
6712 "LINENO:CONTENT string, eg. \" 16:foo\".
6714 Optional `target-file' attribute is a name of target file.
6716 Optional `before-jump-hook' attribute is a function with no
6717 arguments which is called before jumping to position.
6719 Optional `after-jump-hook' attribute is a function with no
6720 arguments which is called after jumping to position.
6722 If `adjust' attribute is specified, searches the line whose
6723 content is CONTENT near the LINENO.
6725 If `recenter' attribute is specified, the line is displayed at
6726 the center of window, otherwise at the top of window.
6729 (define-anything-type-attribute 'file-line
6730 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
6731 (multiline)
6732 (action ("Go to" . anything-c-action-file-line-goto)))
6733 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
6735 Optional `default-directory' attribute is a default-directory
6736 FILENAME is interpreted.
6738 Optional `before-jump-hook' attribute is a function with no
6739 arguments which is called before jumping to position.
6741 Optional `after-jump-hook' attribute is a function with no
6742 arguments which is called after jumping to position.
6744 If `adjust' attribute is specified, searches the line whose
6745 content is CONTENT near the LINENO.
6747 If `recenter' attribute is specified, the line is displayed at
6748 the center of window, otherwise at the top of window.
6751 (define-anything-type-attribute 'timer
6752 '((real-to-display . anything-c-timer-real-to-display)
6753 (action ("Cancel Timer" . cancel-timer)
6754 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
6755 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
6756 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
6757 (persistent-help . "Describe Function"))
6758 "Timer.")
6760 ;;;; Default `anything-sources'
6761 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
6762 ;; tend to invoke M-x anything directly. So I offer default setting.
6763 (setq anything-sources
6764 '(anything-c-source-buffers+
6765 anything-c-source-recentf
6766 anything-c-source-files-in-current-dir+))
6768 ;;;; unit test
6769 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
6770 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6771 (dont-compile
6772 (when (fboundp 'expectations)
6773 (expectations
6774 (desc "candidates-file plug-in")
6775 (expect '(anything-p-candidats-file-init)
6776 (assoc-default 'init
6777 (car (anything-compile-sources
6778 '(((name . "test")
6779 (candidates-file . "test.txt")))
6780 '(anything-compile-source--candidates-file)))))
6781 (expect '(anything-p-candidats-file-init
6782 (lambda () 1))
6783 (assoc-default 'init
6784 (car (anything-compile-sources
6785 '(((name . "test")
6786 (candidates-file . "test.txt")
6787 (init . (lambda () 1))))
6788 '(anything-compile-source--candidates-file)))))
6789 (expect '(anything-p-candidats-file-init
6790 (lambda () 1))
6791 (assoc-default 'init
6792 (car (anything-compile-sources
6793 '(((name . "test")
6794 (candidates-file . "test.txt")
6795 (init (lambda () 1))))
6796 '(anything-compile-source--candidates-file)))))
6797 (desc "anything-c-source-buffers")
6798 (expect '(("Buffers" ("foo" "curbuf")))
6799 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
6800 (let ((anything-c-boring-buffer-regexp
6801 (rx (or
6802 (group bos " ")
6803 "*anything"
6804 ;; echo area
6805 " *Echo Area" " *Minibuf"))))
6806 (flet ((buffer-name (x) x))
6807 (anything-test-candidates 'anything-c-source-buffers))))
6808 (desc "anything-c-stringify")
6809 (expect "str1"
6810 (anything-c-stringify "str1"))
6811 (expect "str2"
6812 (anything-c-stringify 'str2))
6813 (desc "anything-c-symbolify")
6814 (expect 'sym1
6815 (anything-c-symbolify "sym1"))
6816 (expect 'sym2
6817 (anything-c-symbolify 'sym2)))))
6819 (provide 'anything-config)
6821 ;;; Local Variables:
6822 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
6823 ;;; End:
6825 ;; How to save (DO NOT REMOVE!!)
6826 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
6827 ;;; anything-config.el ends here
6829 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
6830 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
6831 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
6832 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
6833 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
6834 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
6835 ;;; LocalWords: dotimes Thierry online vname
6836 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
6837 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
6838 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
6839 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
6840 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
6841 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
6842 ;;; LocalWords: startpos noselect dont desc