anything-config.el (anything-command-and-options-candidates): reformat
[anything-config.git] / anything-config.el
blob710cd294ce798f18c99e806dc71946fec1c17a04
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
2291 "^[^:]+: " "" node-str))))))
2292 (requires-pattern . 2)))
2293 ;; (anything 'anything-c-source-info-pages)
2296 ;;; Use info-index plug-in. Note that `name' attribute is
2297 ;;; not needed but `anything-c-insert-summary' uses it.
2298 ;; Info Elisp
2299 (defvar anything-c-source-info-elisp
2300 '((name . "Info index: elisp")
2301 (info-index . "elisp")))
2302 ;; (anything 'anything-c-source-info-elisp)
2304 ;; Info-Common-Lisp
2305 (defvar anything-c-source-info-cl
2306 '((name . "Info index: cl")
2307 (info-index . "cl")))
2308 ;; (anything 'anything-c-source-info-cl)
2310 ;; Info Index org
2311 (defvar anything-c-source-info-org
2312 '((name . "Info index: org")
2313 (info-index . "org")))
2314 ;; (anything 'anything-c-source-info-org)
2316 ;; Info Index ratpoison
2317 (defvar anything-c-source-info-ratpoison
2318 '((name . "Info index: ratpoison")
2319 (info-index . "ratpoison")))
2320 ;; (anything 'anything-c-source-info-ratpoison)
2322 ;; Info Index zsh
2323 (defvar anything-c-source-info-zsh
2324 '((name . "Info index: zsh")
2325 (info-index . "zsh")))
2326 ;; (anything 'anything-c-source-info-zsh)
2328 ;; Info Index bash
2329 (defvar anything-c-source-info-bash
2330 '((name . "Info index: bash")
2331 (info-index . "bash")))
2332 ;; (anything 'anything-c-source-info-bash)
2334 ;; Info Index coreutils
2335 (defvar anything-c-source-info-coreutils
2336 '((name . "Info index: coreutils")
2337 (info-index . "coreutils")))
2338 ;; (anything 'anything-c-source-info-coreutils)
2340 ;; Info Index fileutils
2341 (defvar anything-c-source-info-fileutils
2342 '((name . "Info index: fileutils")
2343 (info-index . "fileutils")))
2344 ;; (anything 'anything-c-source-info-fileutils)
2346 ;; Info Index find
2347 (defvar anything-c-source-info-find
2348 '((name . "Info index: find")
2349 (info-index . "find")))
2350 ;; (anything 'anything-c-source-info-find)
2352 ;; Info Index sh-utils
2353 (defvar anything-c-source-info-sh-utils
2354 '((name . "Info index: sh-utils")
2355 (info-index . "sh-utils")))
2356 ;; (anything 'anything-c-source-info-sh-utils)
2358 ;; Info Index textutils
2359 (defvar anything-c-source-info-textutils
2360 '((name . "Info index: textutils")
2361 (info-index . "textutils")))
2362 ;; (anything 'anything-c-source-info-textutils)
2364 ;; Info Index libc
2365 (defvar anything-c-source-info-libc
2366 '((name . "Info index: libc")
2367 (info-index . "libc")))
2368 ;; (anything 'anything-c-source-info-libc)
2370 ;; Info Index make
2371 (defvar anything-c-source-info-make
2372 '((name . "Info index: make")
2373 (info-index . "make")))
2374 ;; (anything 'anything-c-source-info-make)
2376 ;; Info Index automake
2377 (defvar anything-c-source-info-automake
2378 '((name . "Info index: automake")
2379 (info-index . "automake")))
2380 ;; (anything 'anything-c-source-info-automake)
2382 ;; Info Index autoconf
2383 (defvar anything-c-source-info-autoconf
2384 '((name . "Info index: autoconf")
2385 (info-index . "autoconf")))
2386 ;; (anything 'anything-c-source-info-autoconf)
2388 ;; Info Index emacs-lisp-intro
2389 (defvar anything-c-source-info-emacs-lisp-intro
2390 '((name . "Info index: emacs-lisp-intro")
2391 (info-index . "emacs-lisp-intro")))
2392 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2394 ;; Info Index emacs
2395 (defvar anything-c-source-info-emacs
2396 '((name . "Info index: emacs")
2397 (info-index . "emacs")))
2398 ;; (anything 'anything-c-source-info-emacs)
2400 ;; Info Index elib
2401 (defvar anything-c-source-info-elib
2402 '((name . "Info index: elib")
2403 (info-index . "elib")))
2404 ;; (anything 'anything-c-source-info-elib)
2406 ;; Info Index eieio
2407 (defvar anything-c-source-info-eieio
2408 '((name . "Info index: eieio")
2409 (info-index . "eieio")))
2410 ;; (anything 'anything-c-source-info-eieio)
2412 ;; Info Index gauche-refe
2413 (defvar anything-c-source-info-gauche-refe
2414 '((name . "Info index: gauche")
2415 (info-index . "gauche-refe")))
2416 ;; (anything 'anything-c-source-info-gauche-refe)
2418 ;; Info Index guile
2419 (defvar anything-c-source-info-guile
2420 '((name . "Info index: guile")
2421 (info-index . "guile")))
2422 ;; (anything 'anything-c-source-info-guile)
2424 ;; Info Index guile-tut
2425 (defvar anything-c-source-info-guile-tut
2426 '((name . "Info index: guile-tut")
2427 (info-index . "guile-tut")))
2428 ;; (anything 'anything-c-source-info-guile-tut)
2430 ;; Info Index goops
2431 (defvar anything-c-source-info-goops
2432 '((name . "Info index: goops")
2433 (info-index . "goops")))
2434 ;; (anything 'anything-c-source-info-goops)
2436 ;; Info Index screen
2437 (defvar anything-c-source-info-screen
2438 '((name . "Info index: screen")
2439 (info-index . "screen")
2440 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2441 ;; (anything 'anything-c-source-info-screen)
2443 ;; Info Index latex
2444 (defvar anything-c-source-info-latex
2445 '((name . "Info index: latex")
2446 (info-index . "latex")))
2447 ;; (anything 'anything-c-source-info-latex)
2449 ;; Info Index gawk
2450 (defvar anything-c-source-info-gawk
2451 '((name . "Info index: gawk")
2452 (info-index . "gawk")))
2453 ;; (anything 'anything-c-source-info-gawk)
2455 ;; Info Index sed
2456 (defvar anything-c-source-info-sed
2457 '((name . "Info index: sed")
2458 (info-index . "sed")))
2459 ;; (anything 'anything-c-source-info-sed)
2461 ;; Info Index m4
2462 (defvar anything-c-source-info-m4
2463 '((name . "Info index: m4")
2464 (info-index . "m4")))
2465 ;; (anything 'anything-c-source-info-m4)
2467 ;; Info Index wget
2468 (defvar anything-c-source-info-wget
2469 '((name . "Info index: wget")
2470 (info-index . "wget")))
2471 ;; (anything 'anything-c-source-info-wget)
2473 ;; Info Index binutils
2474 (defvar anything-c-source-info-binutils
2475 '((name . "Info index: binutils")
2476 (info-index . "binutils")))
2477 ;; (anything 'anything-c-source-info-binutils)
2479 ;; Info Index as
2480 (defvar anything-c-source-info-as
2481 '((name . "Info index: as")
2482 (info-index . "as")))
2483 ;; (anything 'anything-c-source-info-as)
2485 ;; Info Index bfd
2486 (defvar anything-c-source-info-bfd
2487 '((name . "Info index: bfd")
2488 (info-index . "bfd")))
2489 ;; (anything 'anything-c-source-info-bfd)
2491 ;; Info Index gprof
2492 (defvar anything-c-source-info-gprof
2493 '((name . "Info index: gprof")
2494 (info-index . "gprof")))
2495 ;; (anything 'anything-c-source-info-gprof)
2497 ;; Info Index ld
2498 (defvar anything-c-source-info-ld
2499 '((name . "Info index: ld")
2500 (info-index . "ld")))
2501 ;; (anything 'anything-c-source-info-ld)
2503 ;; Info Index diff
2504 (defvar anything-c-source-info-diff
2505 '((name . "Info index: diff")
2506 (info-index . "diff")))
2507 ;; (anything 'anything-c-source-info-diff)
2509 ;; Info Index flex
2510 (defvar anything-c-source-info-flex
2511 '((name . "Info index: flex")
2512 (info-index . "flex")))
2513 ;; (anything 'anything-c-source-info-flex)
2515 ;; Info Index grep
2516 (defvar anything-c-source-info-grep
2517 '((name . "Info index: grep")
2518 (info-index . "grep")))
2519 ;; (anything 'anything-c-source-info-grep)
2521 ;; Info Index gzip
2522 (defvar anything-c-source-info-gzip
2523 '((name . "Info index: gzip")
2524 (info-index . "gzip")))
2525 ;; (anything 'anything-c-source-info-gzip)
2527 ;; Info Index libtool
2528 (defvar anything-c-source-info-libtool
2529 '((name . "Info index: libtool")
2530 (info-index . "libtool")))
2531 ;; (anything 'anything-c-source-info-libtool)
2533 ;; Info Index texinfo
2534 (defvar anything-c-source-info-texinfo
2535 '((name . "Info index: texinfo")
2536 (info-index . "texinfo")))
2537 ;; (anything 'anything-c-source-info-texinfo)
2539 ;; Info Index info
2540 (defvar anything-c-source-info-info
2541 '((name . "Info index: info")
2542 (info-index . "info")))
2543 ;; (anything 'anything-c-source-info-info)
2545 ;; Info Index gdb
2546 (defvar anything-c-source-info-gdb
2547 '((name . "Info index: gdb")
2548 (info-index . "gdb")))
2549 ;; (anything 'anything-c-source-info-gdb)
2551 ;; Info Index stabs
2552 (defvar anything-c-source-info-stabs
2553 '((name . "Info index: stabs")
2554 (info-index . "stabs")))
2555 ;; (anything 'anything-c-source-info-stabs)
2557 ;; Info Index cvsbook
2558 (defvar anything-c-source-info-cvsbook
2559 '((name . "Info index: cvsbook")
2560 (info-index . "cvsbook")))
2561 ;; (anything 'anything-c-source-info-cvsbook)
2563 ;; Info Index cvs
2564 (defvar anything-c-source-info-cvs
2565 '((name . "Info index: cvs")
2566 (info-index . "cvs")))
2567 ;; (anything 'anything-c-source-info-cvs)
2569 ;; Info Index bison
2570 (defvar anything-c-source-info-bison
2571 '((name . "Info index: bison")
2572 (info-index . "bison")))
2573 ;; (anything 'anything-c-source-info-bison)
2575 ;; Info Index id-utils
2576 (defvar anything-c-source-info-id-utils
2577 '((name . "Info index: id-utils")
2578 (info-index . "id-utils")))
2579 ;; (anything 'anything-c-source-info-id-utils)
2581 ;; Info Index global
2582 (defvar anything-c-source-info-global
2583 '((name . "Info index: global")
2584 (info-index . "global")))
2585 ;; (anything 'anything-c-source-info-global)
2587 ;;;; <Help>
2588 ;;; Man Pages
2589 (defvar anything-c-man-pages nil
2590 "All man pages on system.
2591 Will be calculated the first time you invoke anything with this
2592 source.")
2594 (defvar anything-c-source-man-pages
2595 `((name . "Manual Pages")
2596 (candidates . (lambda ()
2597 (if anything-c-man-pages
2598 anything-c-man-pages
2599 ;; XEmacs doesn't have a woman :)
2600 (setq anything-c-man-pages
2601 (ignore-errors
2602 (require 'woman)
2603 (woman-file-name "")
2604 (sort (mapcar 'car woman-topic-all-completions)
2605 'string-lessp))))))
2606 (action ("Show with Woman"
2607 . (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)
2690 (if (functionp a)
2691 (push (symbol-name a) commands))))
2692 (sort commands 'string-lessp))))
2693 (type . function)
2694 (requires-pattern . 2))
2695 "Source for completing Emacs functions.")
2696 ;; (anything 'anything-c-source-emacs-functions)
2698 ;;; With abbrev expansion
2699 ;;; Similar to my exec-abbrev-cmd.el
2700 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2701 (defvar anything-c-function-abbrev-regexp nil
2702 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2703 Regexp built from the current `anything-pattern' interpreting it
2704 as abbreviation.
2705 Only for internal use.")
2707 (defun anything-c-match-function-by-abbrev (candidate)
2708 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2710 Abbreviations are made by taking the first character from each
2711 word in the function's name, e.g. \"bb\" is an abbrev for
2712 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2713 (string-match anything-c-function-abbrev-regexp candidate))
2715 (defvar anything-c-source-emacs-functions-with-abbrevs
2716 (append anything-c-source-emacs-functions
2717 '((match anything-c-match-function-by-abbrev
2718 anything-c-string-match))
2719 '((init
2720 . (lambda ()
2721 (defadvice anything-update
2722 (before anything-c-update-function-abbrev-regexp activate)
2723 (let ((char-list (append anything-pattern nil))
2724 (str "^"))
2725 (dolist (c char-list)
2726 (setq str (concat str (list c) "[^-]*-")))
2727 (setq str (concat (substring str 0 (1- (length str))) "$"))
2728 (setq anything-c-function-abbrev-regexp str))))))))
2729 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2731 (defvar anything-c-source-advice
2732 '((name . "Function Advice")
2733 (candidates . anything-c-advice-candidates)
2734 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
2735 ;; (real-to-display . anything-c-advice-real-to-display)
2738 (persistent-action . anything-c-advice-persistent-action)
2739 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
2740 ;; (anything 'anything-c-source-advice)
2741 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
2742 ;; (testadvice)
2744 (defun anything-c-advice-candidates ()
2745 (require 'advice)
2746 (loop for (fname) in ad-advised-functions
2747 for function = (intern fname)
2748 append
2749 (loop for class in ad-advice-classes append
2750 (loop for advice in (ad-get-advice-info-field function class)
2751 for enabled = (ad-advice-enabled advice)
2752 collect
2753 (cons (format
2754 "%s %s %s"
2755 (if enabled "Enabled " "Disabled")
2756 (propertize fname 'face 'font-lock-function-name-face)
2757 (ad-make-single-advice-docstring advice class nil))
2758 (list function class advice))))))
2760 (defun anything-c-advice-persistent-action (func-class-advice)
2761 (if current-prefix-arg
2762 (anything-c-advice-toggle func-class-advice)
2763 (describe-function (car func-class-advice))))
2765 (defun anything-c-advice-toggle (func-class-advice)
2766 (destructuring-bind (function class advice) func-class-advice
2767 (cond ((ad-advice-enabled advice)
2768 (ad-advice-set-enabled advice nil)
2769 (message "Disabled"))
2770 (t ;disabled
2771 (ad-advice-set-enabled advice t)
2772 (message "Enabled")))
2773 (ad-activate function)
2774 (and anything-in-persistent-action
2775 (anything-c-advice-update-current-display-string))))
2777 (defun anything-c-advice-update-current-display-string ()
2778 (anything-edit-current-selection
2779 (let ((newword (cond ((looking-at "Disabled") "Enabled")
2780 ((looking-at "Enabled") "Disabled")))
2781 realvalue)
2782 (when newword
2783 (delete-region (point) (progn (forward-word 1) (point)))
2784 (insert newword)))))
2786 ;;;###autoload
2787 (defun anything-manage-advice ()
2788 "Preconfigured `anything' to disable/enable function advices."
2789 (interactive)
2790 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
2792 ;;;; <Variable>
2793 ;;; Emacs variables
2794 (defvar anything-c-source-emacs-variables
2795 '((name . "Emacs Variables")
2796 (candidates . (lambda ()
2797 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
2798 (type . variable)
2799 (requires-pattern . 2))
2800 "Source for completing Emacs variables.")
2801 ;; (anything 'anything-c-source-emacs-variables)
2803 ;;;; <Bookmark>
2804 ;;; Bookmarks
2805 (eval-when-compile (require 'bookmark))
2806 (defvar anything-c-source-bookmarks
2807 '((name . "Bookmarks")
2808 (init . (lambda ()
2809 (require 'bookmark)))
2810 (candidates . bookmark-all-names)
2811 (type . bookmark))
2812 "See (info \"(emacs)Bookmarks\").")
2813 ;; (anything 'anything-c-source-bookmarks)
2815 ;;; bookmark-set
2816 (defvar anything-c-source-bookmark-set
2817 '((name . "Set Bookmark")
2818 (dummy)
2819 (action . bookmark-set))
2820 "See (info \"(emacs)Bookmarks\").")
2821 ;; (anything 'anything-c-source-bookmark-set)
2823 ;;; Visible Bookmarks
2824 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2827 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2828 (defvar anything-c-source-bm
2829 '((name . "Visible Bookmarks")
2830 (init . anything-c-bm-init)
2831 (candidates-in-buffer)
2832 (type . line))
2833 "Needs bm.el.
2835 http://www.nongnu.org/bm/")
2837 (defun anything-c-bm-init ()
2838 "Init function for `anything-c-source-bm'."
2839 (when (require 'bm nil t)
2840 (with-no-warnings
2841 (let ((bookmarks (bm-lists))
2842 (buf (anything-candidate-buffer 'global)))
2843 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
2844 '< :key 'overlay-start))
2845 (let ((start (overlay-start bm))
2846 (end (overlay-end bm))
2847 (annotation (or (overlay-get bm 'annotation) "")))
2848 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
2849 (let ((str (format "%5d: [%s]: %s\n"
2850 (line-number-at-pos start)
2851 annotation
2852 (buffer-substring start (1- end)))))
2853 (with-current-buffer buf (insert str))))))))))
2855 ;;; Special bookmarks
2856 (defvar anything-c-source-bookmarks-ssh
2857 '((name . "Bookmarks-ssh")
2858 (init . (lambda ()
2859 (require 'bookmark)))
2860 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
2861 (type . bookmark))
2862 "See (info \"(emacs)Bookmarks\").")
2863 ;; (anything 'anything-c-source-bookmarks-ssh)
2865 (defvar anything-c-source-bookmarks-su
2866 '((name . "Bookmarks-root")
2867 (init . (lambda ()
2868 (require 'bookmark)))
2869 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
2870 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
2872 (type . bookmark))
2873 "See (info \"(emacs)Bookmarks\").")
2874 ;; (anything 'anything-c-source-bookmarks-su)
2876 (defvar anything-c-source-bookmarks-local
2877 '((name . "Bookmarks-Local")
2878 (init . (lambda ()
2879 (require 'bookmark)))
2880 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
2881 (filtered-candidate-transformer
2882 anything-c-adaptive-sort
2883 anything-c-highlight-bookmark)
2884 (type . bookmark))
2885 "See (info \"(emacs)Bookmarks\").")
2886 ;; (anything 'anything-c-source-bookmarks-local)
2888 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
2889 (let* ((lis-all (bookmark-all-names))
2890 (lis-loc (cond (local (loop for i in lis-all
2891 unless (string-match "^(ssh)\\|^(su)" i)
2892 collect i))
2893 (su (loop for i in lis-all
2894 when (string-match "^(su)" i)
2895 collect i))
2896 (sudo (loop for i in lis-all
2897 when (string-match "^(sudo)" i)
2898 collect i))
2899 (ssh (loop for i in lis-all
2900 when (string-match "^(ssh)" i)
2901 collect i)))))
2902 (sort lis-loc 'string-lessp)))
2904 (defun anything-c-bookmark-root-logged-p ()
2905 (catch 'break
2906 (dolist (i (mapcar #'buffer-name (buffer-list)))
2907 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
2908 (throw 'break t)))))
2910 (defun anything-c-highlight-bookmark-su (files source)
2911 (if (anything-c-bookmark-root-logged-p)
2912 (anything-c-highlight-bookmark files source)
2913 (anything-c-highlight-not-logged files source)))
2915 (defun anything-c-highlight-not-logged (files source)
2916 (loop for i in files
2917 collect (propertize i 'face anything-c-bookmarks-face3)))
2919 (defun anything-c-highlight-bookmark (bookmarks source)
2920 "Used as `candidate-transformer' to colorize bookmarks.
2921 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2922 (loop for i in bookmarks
2923 for pred = (bookmark-get-filename i)
2924 for bufp = (and (fboundp 'bmkext-get-buffer-name)
2925 (bmkext-get-buffer-name i))
2926 for handlerp = (and (fboundp 'bookmark-get-handler)
2927 (bookmark-get-handler i))
2928 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
2929 (bmkext-w3m-bookmark-p i))
2930 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
2931 (bmkext-gnus-bookmark-p i))
2932 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
2933 (bmkext-man-bookmark-p i))
2934 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
2935 (bmkext-woman-bookmark-p i))
2936 for handlerp = (bookmark-get-handler i)
2937 for isannotation = (bookmark-get-annotation i)
2938 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
2939 ;; Add a * if bookmark have annotation
2940 if (and isannotation (not (string-equal isannotation "")))
2941 do (setq i (concat "*" i))
2942 ;; info buffers
2943 if (eq handlerp 'Info-bookmark-jump)
2944 collect (propertize i 'face 'anything-bmkext-info 'help-echo pred)
2945 ;; w3m buffers
2946 if isw3m
2947 collect (propertize i 'face 'anything-bmkext-w3m 'help-echo pred)
2948 ;; gnus buffers
2949 if isgnus
2950 collect (propertize i 'face 'anything-bmkext-gnus 'help-echo pred)
2951 ;; Man Woman
2952 if (or iswoman isman)
2953 collect (propertize i 'face 'anything-bmkext-man 'help-echo pred)
2954 ;; Addressbook
2955 if (and (not pred) isabook)
2956 collect (propertize i 'face '((:foreground "Tomato")))
2957 ;; directories
2958 if (and pred (file-directory-p pred))
2959 collect (propertize i 'face anything-c-bookmarks-face1 'help-echo pred)
2960 ;; regular files
2961 if (and pred (not (file-directory-p pred)) (file-exists-p pred)
2962 (not (or iswoman isman)))
2963 collect (propertize i 'face 'anything-bmkext-file 'help-echo pred)))
2966 ;;; Faces for bookmarks
2967 (defface anything-bmkext-info
2968 '((t (:foreground "green")))
2969 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2970 :group 'anything)
2972 (defface anything-bmkext-w3m
2973 '((t (:foreground "yellow")))
2974 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2975 :group 'anything)
2977 (defface anything-bmkext-gnus
2978 '((t (:foreground "magenta")))
2979 "*Face used for Gnus bookmarks."
2980 :group 'anything)
2982 (defface anything-bmkext-man
2983 '((t (:foreground "Orange4")))
2984 "*Face used for Woman/man bookmarks."
2985 :group 'anything)
2987 (defface anything-bmkext-no--file
2988 '((t (:foreground "grey")))
2989 "*Face used for non--file bookmarks."
2990 :group 'anything)
2992 (defface anything-bmkext-file
2993 '((t (:foreground "Deepskyblue2")))
2994 "*Face used for non--file bookmarks."
2995 :group 'anything)
2997 (defface anything-bookmarks-su-face '((t (:foreground "red")))
2998 "Face for su/sudo bookmarks."
2999 :group 'anything)
3001 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
3002 (defvar anything-c-bookmarks-face2 'anything-file-name)
3003 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
3006 ;;; Sources to filter bookmark-extensions bookmarks.
3007 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3008 ;; If you want to enable google-maps in addressbook you will need
3009 ;; Julien Danjou google-maps-el package available here:
3010 ;; http://julien.danjou.info/google-maps-el.html
3012 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
3013 "Return a filtered `bookmark-alist' sorted alphabetically."
3014 (loop
3015 with alist = (if args
3016 (apply #'(lambda (x) (funcall fn x)) args)
3017 (funcall fn))
3018 for i in alist
3019 for b = (car i)
3020 collect b into sa
3021 finally return (sort sa 'string-lessp)))
3023 ;; Addressbook
3024 (defvar anything-c-source-bmkext-addressbook
3025 '((name . "Bookmark Addressbook")
3026 (init . (lambda ()
3027 (require 'bookmark-extensions)
3028 (bookmark-maybe-load-default-file)))
3029 (candidates . anything-c-bmkext-addressbook-setup-alist)
3030 (persistent-action
3031 . (lambda (candidate)
3032 (let ((bmk (anything-bookmark-get-bookmark-from-name
3033 candidate)))
3034 (bookmark--jump-via bmk 'pop-to-buffer))))
3035 (persistent-help . "Show contact - Prefix with C-u to append")
3036 (filtered-candidate-transformer
3037 anything-c-adaptive-sort
3038 anything-c-highlight-bookmark)
3039 (action . (("Show person's data"
3040 . (lambda (candidate)
3041 (let ((bmk (anything-bookmark-get-bookmark-from-name
3042 candidate))
3043 (current-prefix-arg anything-current-prefix-arg))
3044 (bookmark-jump bmk))))
3045 ("Send Mail"
3046 . (lambda (candidate)
3047 (let ((bmk (anything-bookmark-get-bookmark-from-name
3048 candidate)))
3049 (if anything-current-prefix-arg
3050 (addressbook-set-mail-buffer1 bmk 'append)
3051 (addressbook-set-mail-buffer1 bmk)))))
3052 ("Edit Bookmark"
3053 . (lambda (candidate)
3054 (let ((bmk (anything-bookmark-get-bookmark-from-name
3055 candidate)))
3056 (addressbook-bookmark-edit
3057 (assoc bmk bookmark-alist)))))
3058 ("Insert Email at point"
3059 . (lambda (candidate)
3060 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3061 candidate))
3062 (mlist (split-string
3063 (assoc-default
3064 'email (assoc bmk bookmark-alist))
3065 ", ")))
3066 (insert
3067 (if (> (length mlist) 1)
3068 (anything-comp-read
3069 "Insert Mail Address: " mlist :must-match t)
3070 (car mlist))))))
3071 ("Show annotation"
3072 . (lambda (candidate)
3073 (let ((bmk (anything-bookmark-get-bookmark-from-name
3074 candidate)))
3075 (bookmark-show-annotation bmk))))
3076 ("Edit annotation"
3077 . (lambda (candidate)
3078 (let ((bmk (anything-bookmark-get-bookmark-from-name
3079 candidate)))
3080 (bookmark-edit-annotation bmk))))
3081 ("Show Google map"
3082 . (lambda (candidate)
3083 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3084 candidate))
3085 (full-bmk (assoc bmk bookmark-alist)))
3086 (addressbook-google-map full-bmk))))))))
3089 (defun anything-c-bmkext-addressbook-setup-alist ()
3090 "Specialized filter function for bookmarks w3m."
3091 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
3093 ;; W3m
3094 (defvar anything-c-source-bookmark-w3m
3095 '((name . "Bookmark W3m")
3096 (init . (lambda ()
3097 (require 'bookmark-extensions)
3098 (bookmark-maybe-load-default-file)))
3099 (candidates . anything-c-bookmark-w3m-setup-alist)
3100 (filtered-candidate-transformer
3101 anything-c-adaptive-sort
3102 anything-c-highlight-bookmark)
3103 (type . bookmark)))
3104 ;; (anything 'anything-c-source-bookmark-w3m)
3106 (defun anything-c-bookmark-w3m-setup-alist ()
3107 "Specialized filter function for bookmarks w3m."
3108 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
3110 ;; Images
3111 (defvar anything-c-source-bookmark-images
3112 '((name . "Bookmark Images")
3113 (init . (lambda ()
3114 (require 'bookmark-extensions)
3115 (bookmark-maybe-load-default-file)))
3116 (candidates . anything-c-bookmark-images-setup-alist)
3117 (filtered-candidate-transformer
3118 anything-c-adaptive-sort
3119 anything-c-highlight-bookmark)
3120 (type . bookmark)))
3121 ;; (anything 'anything-c-source-bookmark-images)
3123 (defun anything-c-bookmark-images-setup-alist ()
3124 "Specialized filter function for images bookmarks."
3125 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
3127 ;; Woman Man
3128 (defvar anything-c-source-bookmark-man
3129 '((name . "Bookmark Woman&Man")
3130 (init . (lambda ()
3131 (require 'bookmark-extensions)
3132 (bookmark-maybe-load-default-file)))
3133 (candidates . anything-c-bookmark-man-setup-alist)
3134 (filtered-candidate-transformer
3135 anything-c-adaptive-sort
3136 anything-c-highlight-bookmark)
3137 (type . bookmark)))
3138 ;; (anything 'anything-c-source-bookmark-man)
3140 (defun anything-c-bookmark-man-setup-alist ()
3141 "Specialized filter function for bookmarks w3m."
3142 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
3143 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
3145 ;; Gnus
3146 (defvar anything-c-source-bookmark-gnus
3147 '((name . "Bookmark Gnus")
3148 (init . (lambda ()
3149 (require 'bookmark-extensions)
3150 (bookmark-maybe-load-default-file)))
3151 (candidates . anything-c-bookmark-gnus-setup-alist)
3152 (filtered-candidate-transformer
3153 anything-c-adaptive-sort
3154 anything-c-highlight-bookmark)
3155 (type . bookmark)))
3156 ;; (anything 'anything-c-source-bookmark-gnus)
3158 (defun anything-c-bookmark-gnus-setup-alist ()
3159 "Specialized filter function for bookmarks gnus."
3160 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
3162 ;; Info
3163 (defvar anything-c-source-bookmark-info
3164 '((name . "Bookmark Info")
3165 (init . (lambda ()
3166 (require 'bookmark-extensions)
3167 (bookmark-maybe-load-default-file)))
3168 (candidates . anything-c-bookmark-info-setup-alist)
3169 (filtered-candidate-transformer
3170 anything-c-adaptive-sort
3171 anything-c-highlight-bookmark)
3172 (type . bookmark)))
3173 ;; (anything 'anything-c-source-bookmark-info)
3175 (defun anything-c-bookmark-info-setup-alist ()
3176 "Specialized filter function for bookmarks info."
3177 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
3179 ;; Local Files&directories
3180 (defvar anything-c-source-bookmark-files&dirs
3181 '((name . "Bookmark Files&Directories")
3182 (init . (lambda ()
3183 (require 'bookmark-extensions)
3184 (bookmark-maybe-load-default-file)))
3185 (candidates . anything-c-bookmark-local-files-setup-alist)
3186 (filtered-candidate-transformer
3187 anything-c-adaptive-sort
3188 anything-c-highlight-bookmark)
3189 (type . bookmark)))
3190 ;; (anything 'anything-c-source-bookmark-files&dirs)
3192 (defun anything-c-bookmark-local-files-setup-alist ()
3193 "Specialized filter function for bookmarks locals files."
3194 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
3196 ;; Su Files&directories
3197 (defvar anything-c-source-bookmark-su-files&dirs
3198 '((name . "Bookmark Root-Files&Directories")
3199 (init . (lambda ()
3200 (require 'bookmark-extensions)
3201 (bookmark-maybe-load-default-file)))
3202 (candidates . anything-c-bookmark-su-files-setup-alist)
3203 (filtered-candidate-transformer
3204 anything-c-adaptive-sort
3205 anything-c-highlight-bookmark-su)
3206 (type . bookmark)))
3207 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3209 (defun anything-c-bookmark-su-files-setup-alist ()
3210 "Specialized filter function for bookmarks su/sudo files."
3211 (loop
3212 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3213 for i in l
3214 for isfile = (bookmark-get-filename i)
3215 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3216 (save-match-data
3217 (string-match tramp-file-name-regexp isfile)))
3218 for issu = (and istramp
3219 (string-match bmkext-su-or-sudo-regexp isfile))
3220 if issu
3221 collect i))
3223 ;; Ssh Files&directories
3224 (defvar anything-c-source-bookmark-ssh-files&dirs
3225 '((name . "Bookmark Ssh-Files&Directories")
3226 (init . (lambda ()
3227 (require 'bookmark-extensions)
3228 (bookmark-maybe-load-default-file)))
3229 (candidates . anything-c-bookmark-ssh-files-setup-alist)
3230 (filtered-candidate-transformer . anything-c-adaptive-sort)
3231 (type . bookmark)))
3232 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3234 (defun anything-c-bookmark-ssh-files-setup-alist ()
3235 "Specialized filter function for bookmarks ssh files."
3236 (loop
3237 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3238 for i in l
3239 for isfile = (bookmark-get-filename i)
3240 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3241 (save-match-data
3242 (string-match tramp-file-name-regexp isfile)))
3243 for isssh = (and istramp
3244 (string-match "/ssh:" isfile))
3245 if isssh
3246 collect i))
3249 ;; All bookmark-extensions sources.
3250 ;;;###autoload
3251 (defun anything-bookmark-ext ()
3252 "Preconfigured `anything' for bookmark-extensions sources.
3253 Needs bookmark-ext.el
3255 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3256 (interactive)
3257 (anything '(anything-c-source-bookmark-files&dirs
3258 anything-c-source-bookmark-w3m
3259 anything-c-source-bmkext-addressbook
3260 anything-c-source-bookmark-gnus
3261 anything-c-source-bookmark-info
3262 anything-c-source-bookmark-man
3263 anything-c-source-bookmark-images
3264 anything-c-source-bookmark-su-files&dirs
3265 anything-c-source-bookmark-ssh-files&dirs)
3266 nil "SearchBookmark: " nil nil "*anything bmkext*"))
3269 ;; Firefox bookmarks
3270 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
3271 ;; (only for firefox versions >=3)
3272 ;; To achieve that, open about:config in firefox and double click on this line to enable value
3273 ;; to true:
3274 ;; user_pref("browser.bookmarks.autoExportHTML", false);
3275 ;; You should have now:
3276 ;; user_pref("browser.bookmarks.autoExportHTML", true);
3278 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
3279 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3281 (defun anything-get-firefox-user-init-dir ()
3282 "Guess the default Firefox user directory name."
3283 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
3284 (moz-user-dir
3285 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
3286 (goto-char (point-min))
3287 (when (search-forward "Path=" nil t)
3288 (buffer-substring-no-properties (point) (point-at-eol))))))
3289 (file-name-as-directory (concat moz-dir moz-user-dir))))
3291 (defun anything-guess-firefox-bookmark-file ()
3292 "Return the path of the Firefox bookmarks file."
3293 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
3295 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
3296 "Parse html bookmark FILE and return an alist with (title . url) as elements."
3297 (let (bookmarks-alist url title)
3298 (with-temp-buffer
3299 (insert-file-contents file)
3300 (goto-char (point-min))
3301 (while (not (eobp))
3302 (forward-line)
3303 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
3304 (beginning-of-line)
3305 (when (re-search-forward url-regexp nil t)
3306 (setq url (concat "\"" (match-string 0))))
3307 (beginning-of-line)
3308 (when (re-search-forward bmk-regexp nil t)
3309 (setq title (match-string 1)))
3310 (push (cons title url) bookmarks-alist))))
3311 (nreverse bookmarks-alist)))
3314 (defvar anything-c-firefox-bookmarks-alist nil)
3315 (defvar anything-c-source-firefox-bookmarks
3316 '((name . "Firefox Bookmarks")
3317 (init . (lambda ()
3318 (setq anything-c-firefox-bookmarks-alist
3319 (anything-html-bookmarks-to-alist
3320 (anything-guess-firefox-bookmark-file)
3321 anything-firefox-bookmark-url-regexp
3322 anything-firefox-bookmarks-regexp))))
3323 (candidates . (lambda ()
3324 (mapcar #'car
3325 anything-c-firefox-bookmarks-alist)))
3326 (filtered-candidate-transformer
3327 anything-c-adaptive-sort
3328 anything-c-highlight-firefox-bookmarks)
3329 (action . (("Browse Url Firefox"
3330 . (lambda (candidate)
3331 (browse-url-firefox
3332 (anything-c-firefox-bookmarks-get-value candidate))))
3333 ("Browse Url w3m"
3334 . (lambda (candidate)
3335 (w3m-browse-url
3336 (anything-c-firefox-bookmarks-get-value candidate))))
3337 ("Copy Url"
3338 . (lambda (elm)
3339 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
3341 ;; (anything 'anything-c-source-firefox-bookmarks)
3343 (defun anything-c-firefox-bookmarks-get-value (elm)
3344 (replace-regexp-in-string "\"" ""
3345 (cdr (assoc elm
3346 anything-c-firefox-bookmarks-alist))))
3349 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
3350 (loop for i in bookmarks
3351 collect (propertize
3353 'face '((:foreground "YellowGreen"))
3354 'help-echo (anything-c-firefox-bookmarks-get-value i))))
3356 ;; W3m bookmark
3357 (eval-when-compile (require 'w3m-bookmark nil t))
3358 (unless (and (require 'w3m nil t)
3359 (require 'w3m-bookmark nil t))
3360 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
3363 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
3364 "Face for w3m bookmarks" :group 'anything)
3366 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3367 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
3368 (defvar anything-c-w3m-bookmarks-alist nil)
3369 (defvar anything-c-source-w3m-bookmarks
3370 '((name . "W3m Bookmarks")
3371 (init . (lambda ()
3372 (setq anything-c-w3m-bookmarks-alist
3373 (anything-html-bookmarks-to-alist
3374 w3m-bookmark-file
3375 anything-w3m-bookmark-url-regexp
3376 anything-w3m-bookmarks-regexp))))
3377 (candidates . (lambda ()
3378 (mapcar #'car anything-c-w3m-bookmarks-alist)))
3379 (filtered-candidate-transformer
3380 anything-c-adaptive-sort
3381 anything-c-highlight-w3m-bookmarks)
3382 (action . (("Browse Url"
3383 . (lambda (candidate)
3384 (anything-c-w3m-browse-bookmark candidate)))
3385 ("Copy Url"
3386 . (lambda (elm)
3387 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
3388 ("Browse Url Firefox"
3389 . (lambda (candidate)
3390 (anything-c-w3m-browse-bookmark candidate t)))
3391 ("Delete Bookmark"
3392 . (lambda (candidate)
3393 (anything-c-w3m-delete-bookmark candidate)))
3394 ("Rename Bookmark"
3395 . (lambda (candidate)
3396 (anything-c-w3m-rename-bookmark candidate)))))
3397 (persistent-action . (lambda (candidate)
3398 (if current-prefix-arg
3399 (anything-c-w3m-browse-bookmark candidate t)
3400 (anything-c-w3m-browse-bookmark candidate nil t))))
3401 (persistent-help . "Open URL with emacs-w3m in new tab / \
3402 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
3403 "Needs w3m and emacs-w3m.
3405 http://w3m.sourceforge.net/
3406 http://emacs-w3m.namazu.org/")
3408 ;; (anything 'anything-c-source-w3m-bookmarks)
3410 (defun anything-c-w3m-bookmarks-get-value (elm)
3411 (replace-regexp-in-string
3412 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
3414 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
3415 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
3416 (arg (and (eq fn 'w3m-browse-url) new-tab)))
3417 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
3419 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
3420 (loop for i in bookmarks
3421 collect (propertize
3422 i 'face 'anything-w3m-bookmarks-face
3423 'help-echo (anything-c-w3m-bookmarks-get-value i))))
3426 (defun anything-c-w3m-delete-bookmark (elm)
3427 (save-excursion
3428 (find-file-literally w3m-bookmark-file)
3429 (goto-char (point-min))
3430 (when (re-search-forward elm nil t)
3431 (beginning-of-line)
3432 (delete-region (point)
3433 (line-end-position))
3434 (delete-blank-lines))
3435 (save-buffer (current-buffer))
3436 (kill-buffer (current-buffer))))
3438 (defun anything-c-w3m-rename-bookmark (elm)
3439 (let* ((old-title (replace-regexp-in-string ">" "" elm))
3440 (new-title (read-string "NewTitle: " old-title)))
3441 (save-excursion
3442 (find-file-literally w3m-bookmark-file)
3443 (goto-char (point-min))
3444 (when (re-search-forward (concat elm "<") nil t)
3445 (goto-char (1- (point)))
3446 (delete-char (- (length old-title)))
3447 (insert new-title))
3448 (save-buffer (current-buffer))
3449 (kill-buffer (current-buffer)))))
3451 ;;;; <Library>
3452 ;;; Elisp library scan
3453 (defvar anything-c-source-elisp-library-scan
3454 '((name . "Elisp libraries (Scan)")
3455 (init . (anything-c-elisp-library-scan-init))
3456 (candidates-in-buffer)
3457 (action ("Find library"
3458 . (lambda (candidate) (find-file (find-library-name candidate))))
3459 ("Find library other window"
3460 . (lambda (candidate)
3461 (find-file-other-window (find-library-name candidate))))
3462 ("Load library"
3463 . (lambda (candidate) (load-library candidate))))))
3464 ;; (anything 'anything-c-source-elisp-library-scan)
3466 (defun anything-c-elisp-library-scan-init ()
3467 "Init anything buffer status."
3468 (let ((anything-buffer (anything-candidate-buffer 'global))
3469 (library-list (anything-c-elisp-library-scan-list)))
3470 (with-current-buffer anything-buffer
3471 (dolist (library library-list)
3472 (insert (format "%s\n" library))))))
3474 (defun anything-c-elisp-library-scan-list (&optional dirs string)
3475 "Do completion for file names passed to `locate-file'.
3476 DIRS is directory to search path.
3477 STRING is string to match."
3478 ;; Use `load-path' as path when ignore `dirs'.
3479 (or dirs (setq dirs load-path))
3480 ;; Init with blank when ignore `string'.
3481 (or string (setq string ""))
3482 ;; Get library list.
3483 (let ((string-dir (file-name-directory string))
3484 ;; File regexp that suffix match `load-file-rep-suffixes'.
3485 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
3486 name
3487 names)
3488 (dolist (dir dirs)
3489 (unless dir
3490 (setq dir default-directory))
3491 (if string-dir
3492 (setq dir (expand-file-name string-dir dir)))
3493 (when (file-directory-p dir)
3494 (dolist (file (file-name-all-completions
3495 (file-name-nondirectory string) dir))
3496 ;; Suffixes match `load-file-rep-suffixes'.
3497 (setq name (if string-dir (concat string-dir file) file))
3498 (if (string-match match-regexp name)
3499 (add-to-list 'names name)))))
3500 names))
3502 ;;;; <Programming>
3503 ;;; Imenu
3504 (defvar anything-c-imenu-delimiter " / ")
3506 (defvar anything-c-imenu-index-filter nil)
3507 (make-variable-buffer-local 'anything-c-imenu-index-filter)
3509 (defvar anything-c-cached-imenu-alist nil)
3510 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
3512 (defvar anything-c-cached-imenu-candidates nil)
3513 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
3515 (defvar anything-c-cached-imenu-tick nil)
3516 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
3518 (eval-when-compile (require 'imenu))
3519 (setq imenu-auto-rescan t)
3521 (defun anything-imenu-create-candidates (entry)
3522 "Create candidates with ENTRY."
3523 (if (listp (cdr entry))
3524 (mapcan
3525 (lambda (sub)
3526 (if (consp (cdr sub))
3527 (mapcar
3528 (lambda (subentry)
3529 (concat (car entry) anything-c-imenu-delimiter subentry))
3530 (anything-imenu-create-candidates sub))
3531 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
3532 (cdr entry))
3533 (list entry)))
3535 (defvar anything-c-source-imenu
3536 '((name . "Imenu")
3537 (init . (lambda () (require 'imenu)))
3538 (candidates . anything-c-imenu-candidates)
3539 (persistent-action . (lambda (elm)
3540 (anything-c-imenu-default-action elm)
3541 (unless (fboundp 'semantic-imenu-tag-overlay)
3542 (anything-match-line-color-current-line))))
3543 (persistent-help . "Show this entry")
3544 (action . anything-c-imenu-default-action))
3545 "See (info \"(emacs)Imenu\")")
3547 ;; (anything 'anything-c-source-imenu)
3549 (defun anything-c-imenu-candidates ()
3550 (with-current-buffer anything-current-buffer
3551 (let ((tick (buffer-modified-tick)))
3552 (if (eq anything-c-cached-imenu-tick tick)
3553 anything-c-cached-imenu-candidates
3554 (setq imenu--index-alist nil)
3555 (setq anything-c-cached-imenu-tick tick
3556 anything-c-cached-imenu-candidates
3557 (ignore-errors
3558 (mapcan
3559 'anything-imenu-create-candidates
3560 (setq anything-c-cached-imenu-alist
3561 (let ((index (imenu--make-index-alist)))
3562 (if anything-c-imenu-index-filter
3563 (funcall anything-c-imenu-index-filter index)
3564 index))))))
3565 (setq anything-c-cached-imenu-candidates
3566 (mapcar #'(lambda (x)
3567 (if (stringp x)
3569 (car x)))
3570 anything-c-cached-imenu-candidates))))))
3572 (setq imenu-default-goto-function 'imenu-default-goto-function)
3573 (defun anything-c-imenu-default-action (elm)
3574 "The default action for `anything-c-source-imenu'."
3575 (let ((path (split-string elm anything-c-imenu-delimiter))
3576 (alist anything-c-cached-imenu-alist))
3577 (if (> (length path) 1)
3578 (progn
3579 (setq alist (assoc (car path) alist))
3580 (setq elm (cadr path))
3581 (imenu (assoc elm alist)))
3582 (imenu (assoc elm alist)))))
3584 ;;; Ctags
3585 (defvar anything-c-ctags-modes
3586 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3587 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3588 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
3590 (defun anything-c-source-ctags-init ()
3591 (when (and buffer-file-name
3592 (memq major-mode anything-c-ctags-modes)
3593 (anything-current-buffer-is-modified))
3594 (with-current-buffer (anything-candidate-buffer 'local)
3595 (call-process-shell-command
3596 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
3597 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
3598 anything-buffer-file-name)
3599 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
3600 nil (current-buffer))
3601 (goto-char (point-min))
3602 (forward-line 2)
3603 (delete-region (point-min) (point))
3604 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
3605 for lineno-start = (point)
3606 for lineno = (buffer-substring
3607 lineno-start
3608 (1- (search-forward "," (point-at-eol) t)))
3610 (beginning-of-line)
3611 (insert (format "%5s:" lineno))
3612 (search-forward "\177" (point-at-eol) t)
3613 (delete-region (1- (point)) (point-at-eol))
3614 (forward-line 1)))))
3616 (defvar anything-c-source-ctags
3617 '((name . "Exuberant ctags")
3618 (init . anything-c-source-ctags-init)
3619 (candidates-in-buffer)
3620 (adjust)
3621 (type . line))
3622 "Needs Exuberant Ctags.
3624 http://ctags.sourceforge.net/")
3625 ;; (anything 'anything-c-source-ctags)
3627 ;; Semantic
3628 (eval-when-compile (require 'semantic nil t))
3629 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
3630 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
3631 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
3632 (defvar anything-semantic-candidates nil)
3634 (defun anything-semantic-construct-candidates (tags depth)
3635 (when (require 'semantic nil t)
3636 (apply
3637 'append
3638 (mapcar
3639 (lambda (tag)
3640 (if (listp tag)
3641 (let ((type (semantic-tag-type tag))
3642 (class (semantic-tag-class tag)))
3643 (if (or (and (stringp type)
3644 (or (string= type "class")
3645 (string= type "namespace")))
3646 (eq class 'function)
3647 (eq class 'variable))
3648 (cons (cons (concat (make-string (* depth 2) ?\s)
3649 (semantic-format-tag-summarize tag nil t))
3650 tag)
3651 (anything-semantic-construct-candidates
3652 (semantic-tag-components tag) (1+ depth)))))))
3653 tags))))
3655 (defun anything-semantic-default-action (candidate)
3656 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
3657 (semantic-go-to-tag tag)))
3659 (defvar anything-c-source-semantic
3660 '((name . "Semantic Tags")
3661 (init . (lambda ()
3662 (setq anything-semantic-candidates
3663 (ignore-errors (anything-semantic-construct-candidates
3664 (semantic-fetch-tags) 0)))))
3665 (candidates . (lambda ()
3666 (if anything-semantic-candidates
3667 (mapcar 'car anything-semantic-candidates))))
3668 (persistent-action . (lambda (elm)
3669 (anything-semantic-default-action elm)
3670 (anything-match-line-color-current-line)))
3671 (persistent-help . "Show this entry")
3672 (action . anything-semantic-default-action)
3673 "Needs semantic in CEDET.
3675 http://cedet.sourceforge.net/semantic.shtml
3676 http://cedet.sourceforge.net/"))
3678 ;; (anything 'anything-c-source-semantic)
3680 ;;; Function is called by
3681 ;;;###autoload
3682 (defun anything-simple-call-tree ()
3683 "Preconfigured `anything' for simple-call-tree. List function relationships.
3685 Needs simple-call-tree.el.
3686 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
3687 (interactive)
3688 (anything-other-buffer
3689 '(anything-c-source-simple-call-tree-functions-callers
3690 anything-c-source-simple-call-tree-callers-functions)
3691 "*anything simple-call-tree*"))
3693 (defvar anything-c-source-simple-call-tree-functions-callers
3694 '((name . "Function is called by")
3695 (init . anything-c-simple-call-tree-functions-callers-init)
3696 (multiline)
3697 (candidates . anything-c-simple-call-tree-candidates)
3698 (persistent-action . anything-c-simple-call-tree-persistent-action)
3699 (persistent-help . "Show function definitions by rotation")
3700 (action ("Find definition selected by persistent-action" .
3701 anything-c-simple-call-tree-find-definition)))
3702 "Needs simple-call-tree.el.
3703 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3705 (defvar anything-c-simple-call-tree-tick nil)
3706 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
3707 (defun anything-c-simple-call-tree-analyze-maybe ()
3708 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
3709 (simple-call-tree-analyze)
3710 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
3712 (defun anything-c-simple-call-tree-init-base (function message)
3713 (require 'simple-call-tree)
3714 (with-no-warnings
3715 (when (anything-current-buffer-is-modified)
3716 (anything-c-simple-call-tree-analyze-maybe)
3717 (let ((list (funcall function simple-call-tree-alist)))
3718 (with-current-buffer (anything-candidate-buffer 'local)
3719 (dolist (entry list)
3720 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
3721 (insert (car entry) message
3722 (if (string= funcs " ")
3723 " no functions."
3724 funcs)
3725 "\n\n"))))))))
3727 (defun anything-c-simple-call-tree-functions-callers-init ()
3728 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
3729 " is called by\n"))
3731 (defun anything-c-simple-call-tree-candidates ()
3732 (with-current-buffer (anything-candidate-buffer)
3733 (split-string (buffer-string) "\n\n")))
3735 (defvar anything-c-simple-call-tree-related-functions nil)
3736 (defvar anything-c-simple-call-tree-function-index 0)
3737 (defun anything-c-simple-call-tree-persistent-action (candidate)
3738 (unless (eq last-command 'anything-execute-persistent-action)
3739 (setq anything-c-simple-call-tree-related-functions
3740 (delete "no functions."
3741 (split-string
3742 (replace-regexp-in-string " \\| is called by\\| calls "
3743 "" candidate)
3744 "\n")))
3745 (setq anything-c-simple-call-tree-function-index -1))
3746 (incf anything-c-simple-call-tree-function-index)
3747 (anything-c-simple-call-tree-find-definition candidate))
3749 (defun anything-c-simple-call-tree-find-definition (candidate)
3750 (find-function
3751 (intern
3752 (nth (mod anything-c-simple-call-tree-function-index
3753 (length anything-c-simple-call-tree-related-functions))
3754 anything-c-simple-call-tree-related-functions))))
3756 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3758 ;;; Function calls
3759 (defvar anything-c-source-simple-call-tree-callers-functions
3760 '((name . "Function calls")
3761 (init . anything-c-simple-call-tree-callers-functions-init)
3762 (multiline)
3763 (candidates . anything-c-simple-call-tree-candidates)
3764 (persistent-action . anything-c-simple-call-tree-persistent-action)
3765 (persistent-help . "Show function definitions by rotation")
3766 (action ("Find definition selected by persistent-action" .
3767 anything-c-simple-call-tree-find-definition)))
3768 "Needs simple-call-tree.el.
3769 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3771 (defun anything-c-simple-call-tree-callers-functions-init ()
3772 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
3774 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3776 ;;; Commands/Options with doc
3777 (defvar anything-c-auto-document-data nil)
3778 (make-variable-buffer-local 'anything-c-auto-document-data)
3779 (defvar anything-c-source-commands-and-options-in-file
3780 '((name . "Commands/Options in file")
3781 (header-name
3782 . (lambda (x) (format "Commands/Options in %s"
3783 (buffer-local-value 'buffer-file-name
3784 anything-current-buffer))))
3785 (candidates . anything-command-and-options-candidates)
3786 (multiline)
3787 (action . imenu))
3788 "List Commands and Options with doc. It needs auto-document.el .
3790 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3792 (eval-when-compile (require 'auto-document nil t))
3793 (defun anything-command-and-options-candidates ()
3794 (with-current-buffer anything-current-buffer
3795 (when (and (require 'auto-document nil t)
3796 (eq major-mode 'emacs-lisp-mode)
3797 (or (anything-current-buffer-is-modified)
3798 (not anything-c-auto-document-data)))
3799 (or imenu--index-alist (imenu--make-index-alist t))
3800 (setq anything-c-auto-document-data
3801 (destructuring-bind (commands options)
3802 (adoc-construct anything-current-buffer)
3803 (append
3804 (loop for (command . doc) in commands
3805 for cmdname = (symbol-name command)
3806 collect
3807 (cons
3808 (format "Command: %s\n %s"
3809 (propertize cmdname 'face font-lock-function-name-face)
3810 (adoc-first-line doc))
3811 (assoc cmdname imenu--index-alist)))
3812 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
3813 for (option doc default) in options
3814 for optname = (symbol-name option)
3815 collect
3816 (cons
3817 (format "Option: %s\n %s\n default = %s"
3818 (propertize optname 'face font-lock-variable-name-face)
3819 (adoc-first-line doc)
3820 (adoc-prin1-to-string default))
3821 (assoc optname
3822 var-alist)))))))
3823 anything-c-auto-document-data))
3825 ;; (anything 'anything-c-source-commands-and-options-in-file)
3827 ;;;; <Color and Face>
3828 ;;; Customize Face
3829 (defvar anything-c-source-customize-face
3830 '((name . "Customize Face")
3831 (init . (lambda ()
3832 (unless (anything-candidate-buffer)
3833 (save-window-excursion (list-faces-display))
3834 (anything-candidate-buffer (get-buffer "*Faces*")))))
3835 (candidates-in-buffer)
3836 (get-line . buffer-substring)
3837 (action . (lambda (line)
3838 (customize-face (intern (car (split-string line))))))
3839 (requires-pattern . 3))
3840 "See (info \"(emacs)Faces\")")
3841 ;; (anything 'anything-c-source-customize-face)
3843 ;; Color
3844 (defvar anything-c-source-colors
3845 '((name . "Colors")
3846 (init . (lambda () (unless (anything-candidate-buffer)
3847 (save-window-excursion (list-colors-display))
3848 (anything-candidate-buffer (get-buffer "*Colors*")))))
3849 (candidates-in-buffer)
3850 (get-line . buffer-substring)
3851 (action ("Copy Name" . (lambda (candidate)
3852 (kill-new (anything-c-colors-get-name candidate))))
3853 ("Copy RGB" . (lambda (candidate)
3854 (kill-new (anything-c-colors-get-rgb candidate))))
3855 ("Insert Name" . (lambda (candidate)
3856 (with-current-buffer anything-current-buffer
3857 (insert (anything-c-colors-get-name candidate)))))
3858 ("Insert RGB" . (lambda (candidate)
3859 (with-current-buffer anything-current-buffer
3860 (insert (anything-c-colors-get-rgb candidate))))))))
3861 ;; (anything 'anything-c-source-colors)
3863 (defun anything-c-colors-get-name (candidate)
3864 "Get color name."
3865 (replace-regexp-in-string
3866 " " ""
3867 (with-temp-buffer
3868 (insert (capitalize candidate))
3869 (goto-char (point-min))
3870 (search-forward-regexp "\\s-\\{2,\\}")
3871 (delete-region (point) (point-max))
3872 (buffer-string))))
3874 (defun anything-c-colors-get-rgb (candidate)
3875 "Get color RGB."
3876 (replace-regexp-in-string
3877 " " ""
3878 (with-temp-buffer
3879 (insert (capitalize candidate))
3880 (goto-char (point-max))
3881 (search-backward-regexp "\\s-\\{2,\\}")
3882 (delete-region (point) (point-min))
3883 (buffer-string))))
3885 ;;;; <Search Engine>
3886 ;;; Tracker desktop search
3887 (defvar anything-c-source-tracker-search
3888 '((name . "Tracker Search")
3889 (candidates . (lambda ()
3890 (start-process "tracker-search-process" nil
3891 "tracker-search"
3892 anything-pattern)))
3893 (type . file)
3894 (requires-pattern . 3)
3895 (delayed))
3896 "Source for retrieving files matching the current input pattern
3897 with the tracker desktop search.")
3898 ;; (anything 'anything-c-source-tracker-search)
3900 ;;; Spotlight (MacOS X desktop search)
3901 (defvar anything-c-source-mac-spotlight
3902 '((name . "mdfind")
3903 (candidates . (lambda ()
3904 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
3905 (type . file)
3906 (requires-pattern . 3)
3907 (delayed))
3908 "Source for retrieving files via Spotlight's command line
3909 utility mdfind.")
3910 ;; (anything 'anything-c-source-mac-spotlight)
3913 ;;;; <Kill ring>
3914 ;;; Kill ring
3915 (defvar anything-c-source-kill-ring
3916 '((name . "Kill Ring")
3917 (init . (lambda () (anything-attrset 'last-command last-command)))
3918 (candidates . anything-c-kill-ring-candidates)
3919 (action . anything-c-kill-ring-action)
3920 (last-command)
3921 (migemo)
3922 (multiline))
3923 "Source for browse and insert contents of kill-ring.")
3925 (defun anything-c-kill-ring-candidates ()
3926 (loop for kill in kill-ring
3927 unless (or (< (length kill) anything-kill-ring-threshold)
3928 (string-match "^[\\s\\t]+$" kill))
3929 collect kill))
3931 (defun anything-c-kill-ring-action (str)
3932 "Insert STR in `kill-ring' and set STR to the head.
3933 If this action is executed just after `yank', replace with STR as yanked string."
3934 (setq kill-ring (delete str kill-ring))
3935 (if (not (eq (anything-attr 'last-command) 'yank))
3936 (insert-for-yank str)
3937 ;; from `yank-pop'
3938 (let ((inhibit-read-only t)
3939 (before (< (point) (mark t))))
3940 (if before
3941 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
3942 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
3943 (setq yank-undo-function nil)
3944 (set-marker (mark-marker) (point) (current-buffer))
3945 (insert-for-yank str)
3946 ;; Set the window start back where it was in the yank command,
3947 ;; if possible.
3948 (set-window-start (selected-window) yank-window-start t)
3949 (if before
3950 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3951 ;; It is cleaner to avoid activation, even though the command
3952 ;; loop would deactivate the mark because we inserted text.
3953 (goto-char (prog1 (mark t)
3954 (set-marker (mark-marker) (point) (current-buffer)))))))
3955 (kill-new str))
3957 ;; (anything 'anything-c-source-kill-ring)
3959 ;;;; <Mark ring>
3960 ;; DO NOT include these sources in `anything-sources' use
3961 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
3962 ;; `anything-all-mark-rings' instead.
3964 (defun anything-c-source-mark-ring-candidates ()
3965 (flet ((get-marks (pos)
3966 (save-excursion
3967 (goto-char pos)
3968 (beginning-of-line)
3969 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3970 (when (string= "" line)
3971 (setq line "<EMPTY LINE>"))
3972 (format "%7d: %s" (line-number-at-pos) line)))))
3973 (with-current-buffer anything-current-buffer
3974 (loop
3975 with marks = (cons (mark-marker) mark-ring)
3976 with recip = nil
3977 for i in marks
3978 for m = (get-marks i)
3979 unless (member m recip)
3980 collect m into recip
3981 finally return recip))))
3983 (defvar anything-mark-ring-cache nil)
3984 (defvar anything-c-source-mark-ring
3985 '((name . "mark-ring")
3986 (init . (lambda ()
3987 (setq anything-mark-ring-cache
3988 (ignore-errors (anything-c-source-mark-ring-candidates)))))
3989 (candidates . (lambda ()
3990 (anything-aif anything-mark-ring-cache
3991 it)))
3992 (action . (("Goto line" . (lambda (candidate)
3993 (anything-goto-line (string-to-number candidate))))))
3994 (persistent-action . (lambda (candidate)
3995 (anything-goto-line (string-to-number candidate))
3996 (anything-match-line-color-current-line)))
3997 (persistent-help . "Show this line")))
3999 ;; (anything 'anything-c-source-mark-ring)
4001 ;;;###autoload
4002 (defun anything-mark-ring ()
4003 "Preconfigured `anything' for `anything-c-source-mark-ring'."
4004 (interactive)
4005 (anything 'anything-c-source-mark-ring))
4007 ;;; Global-mark-ring
4008 (defvar anything-c-source-global-mark-ring
4009 '((name . "global-mark-ring")
4010 (candidates . anything-c-source-global-mark-ring-candidates)
4011 (action . (("Goto line" . (lambda (candidate)
4012 (let ((items (split-string candidate ":")))
4013 (switch-to-buffer (second items))
4014 (anything-goto-line (string-to-number (car items))))))))
4015 (persistent-action . (lambda (candidate)
4016 (let ((items (split-string candidate ":")))
4017 (switch-to-buffer (second items))
4018 (anything-goto-line (string-to-number (car items)))
4019 (anything-match-line-color-current-line))))
4020 (persistent-help . "Show this line")))
4022 (defun anything-c-source-global-mark-ring-candidates ()
4023 (flet ((buf-fn (m)
4024 (with-current-buffer (marker-buffer m)
4025 (goto-char m)
4026 (beginning-of-line)
4027 (let (line)
4028 (if (string= "" line)
4029 (setq line "<EMPTY LINE>")
4030 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
4031 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
4032 (loop
4033 with marks = global-mark-ring
4034 with recip = nil
4035 for i in marks
4036 for gm = (unless (or (string-match
4037 "^ " (format "%s" (marker-buffer i)))
4038 (null (marker-buffer i)))
4039 (buf-fn i))
4040 when (and gm (not (member gm recip)))
4041 collect gm into recip
4042 finally return recip)))
4044 ;; (anything 'anything-c-source-global-mark-ring)
4046 ;;;###autoload
4047 (defun anything-global-mark-ring ()
4048 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4049 (interactive)
4050 (anything 'anything-c-source-global-mark-ring))
4052 ;;;###autoload
4053 (defun anything-all-mark-rings ()
4054 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4055 `anything-c-source-mark-ring'."
4056 (interactive)
4057 (anything '(anything-c-source-global-mark-ring
4058 anything-c-source-mark-ring)))
4060 ;;;; <Register>
4061 ;;; Insert from register
4062 (defvar anything-c-source-register
4063 '((name . "Registers")
4064 (candidates . anything-c-register-candidates)
4065 (action-transformer . anything-c-register-action-transformer)
4066 (multiline)
4067 (action))
4068 "See (info \"(emacs)Registers\")")
4070 (defun anything-c-register-candidates ()
4071 "Collecting register contents and appropriate commands."
4072 (loop for (char . val) in register-alist
4073 for key = (single-key-description char)
4074 for string-actions = (cond
4075 ((numberp val)
4076 (list (int-to-string val)
4077 'insert-register
4078 'increment-register))
4079 ((markerp val)
4080 (let ((buf (marker-buffer val)))
4081 (if (null buf)
4082 (list "a marker in no buffer")
4083 (list (concat
4084 "a buffer position:"
4085 (buffer-name buf)
4086 ", position "
4087 (int-to-string (marker-position val)))
4088 'jump-to-register
4089 'insert-register))))
4090 ((and (consp val) (window-configuration-p (car val)))
4091 (list "window configuration."
4092 'jump-to-register))
4093 ((and (consp val) (frame-configuration-p (car val)))
4094 (list "frame configuration."
4095 'jump-to-register))
4096 ((and (consp val) (eq (car val) 'file))
4097 (list (concat "file:"
4098 (prin1-to-string (cdr val))
4099 ".")
4100 'jump-to-register))
4101 ((and (consp val) (eq (car val) 'file-query))
4102 (list (concat "file:a file-query reference: file "
4103 (car (cdr val))
4104 ", position "
4105 (int-to-string (car (cdr (cdr val))))
4106 ".")
4107 'jump-to-register))
4108 ((consp val)
4109 (let ((lines (format "%4d" (length val))))
4110 (list (format "%s: %s\n" lines
4111 (truncate-string-to-width
4112 (mapconcat 'identity (list (car val))
4113 ;; (mapconcat (lambda (y) y) val
4114 "^J") (- (window-width) 15)))
4115 'insert-register)))
4116 ((stringp val)
4117 (list ;; without properties
4118 (substring-no-properties val)
4119 'insert-register
4120 'append-to-register
4121 'prepend-to-register))
4123 "GARBAGE!"))
4124 collect (cons (format "register %3s: %s" key (car string-actions))
4125 (cons char (cdr string-actions)))))
4127 (defun anything-c-register-action-transformer (actions register-and-functions)
4128 "Decide actions by the contents of register."
4129 (loop with func-actions =
4130 '((insert-register
4131 "Insert Register" .
4132 (lambda (c) (insert-register (car c))))
4133 (jump-to-register
4134 "Jump to Register" .
4135 (lambda (c) (jump-to-register (car c))))
4136 (append-to-register
4137 "Append Region to Register" .
4138 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
4139 (prepend-to-register
4140 "Prepend Region to Register" .
4141 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
4142 (increment-register
4143 "Increment Prefix Arg to Register" .
4144 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
4145 for func in (cdr register-and-functions)
4146 for cell = (assq func func-actions)
4147 when cell
4148 collect (cdr cell)))
4150 ;; (anything 'anything-c-source-register)
4152 ;;;; <Headline Extraction>
4153 (defvar anything-c-source-fixme
4154 '((name . "TODO/FIXME/DRY comments")
4155 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4156 (adjust)
4157 (recenter))
4158 "Show TODO/FIXME/DRY comments in current file.")
4159 ;; (anything 'anything-c-source-fixme)
4161 (defvar anything-c-source-rd-headline
4162 '((name . "RD HeadLine")
4163 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4164 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
4165 (migemo)
4166 (subexp . 1))
4167 "Show RD headlines.
4169 RD is Ruby's POD.
4170 http://en.wikipedia.org/wiki/Ruby_Document_format")
4171 ;; (anything 'anything-c-source-rd-headline)
4173 (defvar anything-c-source-oddmuse-headline
4174 '((name . "Oddmuse HeadLine")
4175 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4176 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4177 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
4178 (migemo)
4179 (subexp . 1))
4180 "Show Oddmuse headlines, such as EmacsWiki.")
4181 ;; (anything 'anything-c-source-oddmuse-headline)
4183 (defvar anything-c-source-emacs-source-defun
4184 '((name . "Emacs Source DEFUN")
4185 (headline . "DEFUN\\|DEFVAR")
4186 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
4187 "Show DEFUN/DEFVAR in Emacs C source file.")
4188 ;; (anything 'anything-c-source-emacs-source-defun)
4190 (defvar anything-c-source-emacs-lisp-expectations
4191 '((name . "Emacs Lisp Expectations")
4192 (headline . "(desc[ ]\\|(expectations")
4193 (condition . (eq major-mode 'emacs-lisp-mode)))
4194 "Show descriptions (desc) in Emacs Lisp Expectations.
4196 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4197 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4199 (defvar anything-c-source-emacs-lisp-toplevels
4200 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4201 (headline . "^(\\|(@\\*\\|^;;;;")
4202 (get-line . buffer-substring)
4203 (condition . (eq major-mode 'emacs-lisp-mode))
4204 (adjust))
4205 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4206 linkd.el is optional because linkd stars are extracted by regexp.
4207 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4208 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4210 (defvar anything-c-source-org-headline
4211 '((name . "Org HeadLine")
4212 (headline
4213 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4214 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4215 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4216 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4217 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4218 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4219 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4220 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4221 (condition . (eq major-mode 'org-mode))
4222 (migemo)
4223 (subexp . 1)
4224 (persistent-action . (lambda (elm)
4225 (anything-c-action-line-goto elm)
4226 (org-cycle)))
4227 (action-transformer
4228 . (lambda (actions candidate)
4229 '(("Go to Line" . anything-c-action-line-goto)
4230 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
4231 "Show Org headlines.
4232 org-mode is very very much extended text-mode/outline-mode.
4234 See (find-library \"org.el\")
4235 See http://orgmode.org for the latest version.")
4237 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4238 (insert
4239 (save-excursion
4240 (anything-goto-line (car lineno-and-content))
4241 (and (looking-at org-complex-heading-regexp)
4242 (org-make-link-string (concat "*" (match-string 4)))))))
4244 ;; (anything 'anything-c-source-org-headline)
4246 ;;; Anything yaoddmuse
4247 ;; Be sure to have yaoddmuse.el installed
4248 ;; install-elisp may be required if you want to install elisp file from here.
4249 (defvar anything-yaoddmuse-use-cache-file nil)
4250 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
4251 (defvar anything-c-yaoddmuse-ew-cache nil)
4252 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4253 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
4254 (candidates . (lambda ()
4255 (if anything-yaoddmuse-use-cache-file
4256 (ignore-errors
4257 (unless anything-c-yaoddmuse-ew-cache
4258 (load anything-c-yaoddmuse-cache-file)
4259 (setq anything-c-yaoddmuse-ew-cache
4260 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4261 anything-c-yaoddmuse-ew-cache)
4262 (yaoddmuse-update-pagename t)
4263 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
4264 (action . (("Edit page" . (lambda (candidate)
4265 (yaoddmuse-edit "EmacsWiki" candidate)))
4266 ("Browse page" . (lambda (candidate)
4267 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4268 ("Browse page other window" . (lambda (candidate)
4269 (if (one-window-p)
4270 (split-window-vertically))
4271 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4272 ("Browse diff" . (lambda (candidate)
4273 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
4274 ("Copy URL" . (lambda (candidate)
4275 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
4276 (message "Have copy page %s's URL to yank." candidate)))
4277 ("Create page" . (lambda (candidate)
4278 (yaoddmuse-edit "EmacsWiki" anything-input)))
4279 ("Update cache" . (lambda (candidate)
4280 (if anything-yaoddmuse-use-cache-file
4281 (progn
4282 (anything-yaoddmuse-cache-pages t)
4283 (setq anything-c-yaoddmuse-ew-cache
4284 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4285 (yaoddmuse-update-pagename))))))
4286 (action-transformer anything-c-yaoddmuse-action-transformer))
4287 "Needs yaoddmuse.el.
4289 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4291 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
4293 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
4294 '((name . "Yaoddmuse Post library (EmacsWiki)")
4295 (init . (anything-yaoddmuse-init))
4296 (candidates-in-buffer)
4297 (action . (("Post library and Browse" . (lambda (candidate)
4298 (yaoddmuse-post-file (find-library-name candidate)
4299 "EmacsWiki"
4300 (file-name-nondirectory (find-library-name candidate))
4301 nil t)))
4302 ("Post library" . (lambda (candidate)
4303 (yaoddmuse-post-file (find-library-name candidate)
4304 "EmacsWiki"
4305 (file-name-nondirectory (find-library-name candidate))))))))
4306 "Needs yaoddmuse.el.
4308 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4310 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
4312 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
4313 "Allow the use of `install-elisp' only on elisp files."
4314 (if (string-match "\.el$" candidate)
4315 (append actions '(("Install Elisp" . (lambda (elm)
4316 (install-elisp-from-emacswiki elm)))))
4317 actions))
4319 ;;;###autoload
4320 (defun anything-yaoddmuse-cache-pages (&optional load)
4321 "Fetch the list of files on emacswiki and create cache file.
4322 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
4323 (interactive)
4324 (yaoddmuse-update-pagename)
4325 (save-excursion
4326 (find-file anything-c-yaoddmuse-cache-file)
4327 (erase-buffer)
4328 (insert "(puthash \"EmacsWiki\" '(")
4329 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
4331 (insert (concat "(\"" (car i) "\") ")))
4332 (insert ") yaoddmuse-pages-hash)\n")
4333 (save-buffer)
4334 (kill-buffer (current-buffer))
4335 (when (or current-prefix-arg
4336 load)
4337 (load anything-c-yaoddmuse-cache-file))))
4339 ;;;###autoload
4340 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
4341 "Preconfigured `anything' to edit or view EmacsWiki page.
4343 Needs yaoddmuse.el.
4345 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4346 (interactive)
4347 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
4349 ;;;###autoload
4350 (defun anything-yaoddmuse-emacswiki-post-library ()
4351 "Preconfigured `anything' to post library to EmacsWiki.
4353 Needs yaoddmuse.el.
4355 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4356 (interactive)
4357 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
4359 (defun anything-yaoddmuse-init ()
4360 "Init anything buffer status."
4361 (let ((anything-buffer (anything-candidate-buffer 'global))
4362 (library-list (yaoddmuse-get-library-list)))
4363 (with-current-buffer anything-buffer
4364 ;; Insert library name.
4365 (dolist (library library-list)
4366 (insert (format "%s\n" library)))
4367 ;; Sort lines.
4368 (sort-lines nil (point-min) (point-max)))))
4370 ;;; Eev anchors
4371 (defvar anything-c-source-eev-anchor
4372 '((name . "Anchors")
4373 (candidates
4374 . (lambda ()
4375 (ignore-errors
4376 (with-current-buffer anything-current-buffer
4377 (loop initially (goto-char (point-min))
4378 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
4379 for anchor = (match-string-no-properties 1)
4380 collect (cons (format "%5d:%s"
4381 (line-number-at-pos (match-beginning 0))
4382 (format ee-anchor-format anchor)) anchor))))))
4383 (persistent-action . (lambda (item)
4384 (ee-to item)
4385 (anything-match-line-color-current-line)))
4386 (persistent-help . "Show this entry")
4387 (action . (("Goto link" . ee-to)))))
4388 ;; (anything 'anything-c-source-eev-anchor)
4390 ;;;; <Misc>
4391 ;;; Org keywords
4392 (defvar anything-c-source-org-keywords
4393 '((name . "Org Keywords")
4394 (init . anything-c-org-keywords-init)
4395 (candidates . anything-c-org-keywords-candidates)
4396 (action . anything-c-org-keywords-insert)
4397 (persistent-action . anything-c-org-keywords-show-help)
4398 (persistent-help . "Show an example and info page to describe this keyword.")
4399 (keywords-examples)
4400 (keywords)))
4401 ;; (anything 'anything-c-source-org-keywords)
4402 (defvar anything-c-org-keywords-info-location
4403 '(("#+TITLE:" . "(org)Export options")
4404 ("#+AUTHOR:" . "(org)Export options")
4405 ("#+DATE:" . "(org)Export options")
4406 ("#+EMAIL:" . "(org)Export options")
4407 ("#+DESCRIPTION:" . "(org)Export options")
4408 ("#+KEYWORDS:" . "(org)Export options")
4409 ("#+LANGUAGE:" . "(org)Export options")
4410 ("#+TEXT:" . "(org)Export options")
4411 ("#+TEXT:" . "(org)Export options")
4412 ("#+OPTIONS:" . "(org)Export options")
4413 ("#+BIND:" . "(org)Export options")
4414 ("#+LINK_UP:" . "(org)Export options")
4415 ("#+LINK_HOME:" . "(org)Export options")
4416 ("#+LATEX_HEADER:" . "(org)Export options")
4417 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
4418 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
4419 ("#+INFOJS_OPT" . "(org)Javascript support")
4420 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
4421 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
4422 ("#+ORGTBL" . "(org)Radio tables")
4423 ("#+HTML:" . "(org)Quoting HTML tags")
4424 ("#+LaTeX:" . "(org)Quoting LaTeX code")
4425 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
4426 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
4427 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
4428 ("#+BEGIN_VERSE" . "(org)Paragraphs")
4429 ("#+BEGIN_SRC" . "(org)Literal examples")
4430 ("#+CAPTION" . "(org)Tables in HTML export")
4431 ("#+LABEL" . "(org)Tables in LaTeX export")
4432 ("#+ATTR_HTML" . "(org)Links")
4433 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
4435 (defun anything-c-org-keywords-init ()
4436 (unless (anything-attr 'keywords-examples)
4437 (require 'org)
4438 (anything-attrset 'keywords-examples
4439 (append
4440 (mapcar
4441 (lambda (x)
4442 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
4443 (cons (match-string 2 x) (match-string 1 x)))
4444 (org-split-string (org-get-current-options) "\n"))
4445 (mapcar 'list org-additional-option-like-keywords)))
4446 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
4448 (defun anything-c-org-keywords-candidates ()
4449 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
4450 (anything-attr 'keywords)))
4452 (defun anything-c-org-keywords-insert (keyword)
4453 (cond ((string-match "BEGIN" keyword)
4454 (insert "#+" keyword " ")
4455 (save-excursion
4456 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
4458 (insert "#+" keyword " "))))
4460 (defun anything-c-org-keywords-show-help (keyword)
4461 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
4462 "(org)In-buffer settings"))
4463 (search-forward (concat "#+" keyword) nil t)
4464 (anything-persistent-highlight-point)
4465 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
4468 ;;; Picklist
4469 (defvar anything-c-source-picklist
4470 '((name . "Picklist")
4471 (candidates . (lambda () (mapcar 'car picklist-list)))
4472 (type . file)))
4473 ;; (anything 'anything-c-source-picklist)
4475 ;;; BBDB
4476 (defvar bbdb-records)
4477 (defvar bbdb-buffer-name)
4478 (declare-function bbdb "ext:bbdb-com")
4479 (declare-function bbdb-current-record "ext:bbdb-com")
4480 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
4481 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
4482 (declare-function bbdb-current-record "ext:bbdb-com")
4483 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
4484 (declare-function bbdb-records "ext:bbdb-com"
4485 (&optional dont-check-disk already-in-db-buffer))
4487 (defun anything-c-bbdb-candidates ()
4488 "Return a list of all names in the bbdb database. The format
4489 is \"Firstname Lastname\"."
4490 (mapcar (lambda (bbdb-record)
4491 (replace-regexp-in-string
4492 "\\s-+$" ""
4493 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
4494 (bbdb-records)))
4496 (defun anything-c-bbdb-create-contact (actions candidate)
4497 "Action transformer that returns only an entry to add the
4498 current `anything-pattern' as new contact. All other actions are
4499 removed."
4500 (if (string= candidate "*Add to contacts*")
4501 '(("Add to contacts" . (lambda (actions)
4502 (bbdb-create-internal
4503 (read-from-minibuffer "Name: " anything-c-bbdb-name)
4504 (read-from-minibuffer "Company: ")
4505 (read-from-minibuffer "Email: ")
4508 (read-from-minibuffer "Note: ")))))
4509 actions))
4511 (defun anything-c-bbdb-get-record (candidate)
4512 "Return record that match CANDIDATE."
4513 (bbdb candidate nil)
4514 (set-buffer "*BBDB*")
4515 (bbdb-current-record))
4517 (defvar anything-c-bbdb-name nil
4518 "Only for internal use.")
4520 (defvar anything-c-source-bbdb
4521 '((name . "BBDB")
4522 (candidates . anything-c-bbdb-candidates)
4523 (action ("Send a mail" . anything-c-bbdb-compose-mail)
4524 ("View person's data" . anything-c-bbdb-view-person-action))
4525 (filtered-candidate-transformer . (lambda (candidates source)
4526 (setq anything-c-bbdb-name anything-pattern)
4527 (if (not candidates)
4528 (list "*Add to contacts*")
4529 candidates)))
4530 (action-transformer . (lambda (actions candidate)
4531 (anything-c-bbdb-create-contact actions candidate))))
4532 "Needs BBDB.
4534 http://bbdb.sourceforge.net/")
4535 ;; (anything 'anything-c-source-bbdb)
4537 (defun anything-c-bbdb-view-person-action (candidate)
4538 "View BBDB data of single CANDIDATE or marked candidates."
4539 (anything-aif (anything-marked-candidates)
4540 (let ((bbdb-append-records (length it)))
4541 (dolist (i it)
4542 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
4543 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
4545 (defun anything-c-bbdb-collect-mail-addresses ()
4546 "Return a list of all mail addresses of records in bbdb buffer."
4547 (with-current-buffer bbdb-buffer-name
4548 (loop for i in bbdb-records
4549 if (bbdb-record-net (car i))
4550 collect (bbdb-dwim-net-address (car i)))))
4552 (defun anything-c-bbdb-compose-mail (candidate)
4553 "Compose a mail with all records of bbdb buffer."
4554 (anything-c-bbdb-view-person-action candidate)
4555 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4556 (address-str (mapconcat 'identity address-list ",\n ")))
4557 (compose-mail address-str)))
4559 ;;; Evaluation Result
4560 (defvar anything-c-source-evaluation-result
4561 '((name . "Evaluation Result")
4562 (disable-shortcuts)
4563 (dummy)
4564 (filtered-candidate-transformer . (lambda (candidates source)
4565 (list
4566 (condition-case nil
4567 (with-current-buffer anything-current-buffer
4568 (pp-to-string
4569 (eval (read anything-pattern))))
4570 (error "Error")))))
4571 (action ("Copy result to kill-ring" . (lambda (candidate)
4572 (with-current-buffer anything-buffer
4573 (let ((end (save-excursion
4574 (goto-char (point-max))
4575 (search-backward "\n")
4576 (point))))
4577 (kill-region (point) end))))))))
4578 ;; (anything 'anything-c-source-evaluation-result)
4580 ;;;###autoload
4581 (defun anything-eval-expression (arg)
4582 "Preconfigured anything for `anything-c-source-evaluation-result'."
4583 (interactive "P")
4584 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
4585 nil nil nil "*anything eval*"))
4587 ;;;###autoload
4588 (defun anything-eval-expression-with-eldoc ()
4589 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
4590 (interactive)
4591 (if (window-system)
4592 (let ((timer (run-with-idle-timer eldoc-idle-delay
4593 'repeat 'anything-eldoc-show-in-eval)))
4594 (unwind-protect
4595 (call-interactively 'anything-eval-expression)
4596 (cancel-timer timer)))
4597 (call-interactively 'anything-eval-expression)))
4599 (defun anything-eldoc-show-in-eval ()
4600 "Return eldoc in a tooltip for current minibuffer input."
4601 (let* ((str-all (minibuffer-completion-contents))
4602 (sym (when str-all
4603 (with-temp-buffer
4604 (insert str-all)
4605 (goto-char (point-max))
4606 (unless (looking-back ")\\|\"") (forward-char -1))
4607 (eldoc-current-symbol))))
4608 (doc (or (eldoc-get-var-docstring sym)
4609 (eldoc-get-fnsym-args-string
4610 (car (eldoc-fnsym-in-current-sexp))))))
4611 (when doc (tooltip-show doc))))
4613 ;;; Calculation Result
4614 (defvar anything-c-source-calculation-result
4615 '((name . "Calculation Result")
4616 (dummy)
4617 (filtered-candidate-transformer . (lambda (candidates source)
4618 (list
4619 (condition-case nil
4620 (calc-eval anything-pattern)
4621 (error "error")))))
4622 (action ("Copy result to kill-ring" . kill-new))))
4623 ;; (anything 'anything-c-source-calculation-result)
4625 ;;; Google Suggestions
4626 (defvar anything-gg-sug-lgh-flag 0)
4627 (defun anything-c-google-suggest-fetch (input)
4628 "Fetch suggestions for INPUT from XML buffer.
4629 Return an alist with elements like (data . number_results)."
4630 (let ((request (concat anything-c-google-suggest-url
4631 (url-hexify-string input))))
4632 (flet ((fetch ()
4633 (loop
4634 with result-alist = (xml-get-children
4635 (car (xml-parse-region (point-min) (point-max)))
4636 'CompleteSuggestion)
4637 for i in result-alist
4638 for data = (cdr (caadr (assoc 'suggestion i)))
4639 for nqueries = (cdr (caadr (assoc 'num_queries i)))
4640 for ldata = (length data)
4642 (when (> ldata anything-gg-sug-lgh-flag)
4643 (setq anything-gg-sug-lgh-flag ldata))
4644 collect (cons data nqueries) into cont
4645 finally return cont)))
4646 (if anything-google-suggest-use-curl-p
4647 (with-temp-buffer
4648 (call-process "curl" nil t nil request)
4649 (fetch))
4650 (with-current-buffer
4651 (url-retrieve-synchronously request)
4652 (fetch))))))
4655 (defun anything-c-google-suggest-set-candidates ()
4656 "Set candidates with result and number of google results found."
4657 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
4658 (setq suggestions (loop for i in suggestions
4659 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
4660 for elm = (concat (car i)
4661 (make-string (+ 2 interval) ? )
4662 "(" (cdr i) " results)")
4663 collect (cons elm (car i))))
4664 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
4665 suggestions
4666 ;; if there is no suggestion exactly matching the input then
4667 ;; prepend a Search on Google item to the list
4668 (append
4669 suggestions
4670 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
4671 anything-input))))))
4674 (defun anything-c-google-suggest-action (candidate)
4675 "Default action to jump to a google suggested candidate."
4676 (anything-c-browse-url (concat anything-c-google-suggest-search-url
4677 (url-hexify-string candidate))))
4680 (defvar anything-c-source-google-suggest
4681 '((name . "Google Suggest")
4682 (candidates . anything-c-google-suggest-set-candidates)
4683 (action . (("Google Search" . anything-c-google-suggest-action)))
4684 (volatile)
4685 (requires-pattern . 3)
4686 (delayed)))
4688 ;; (anything 'anything-c-source-google-suggest)
4690 ;;; Yahoo suggestions
4692 (defun anything-c-yahoo-suggest-fetch (input)
4693 "Fetch Yahoo suggestions for INPUT from XML buffer.
4694 Return an alist with elements like (data . number_results)."
4695 (let ((request (concat anything-c-yahoo-suggest-url
4696 (url-hexify-string input))))
4697 (flet ((fetch ()
4698 (loop
4699 with result-alist = (xml-get-children
4700 (car (xml-parse-region (point-min) (point-max)))
4701 'Result)
4702 for i in result-alist
4703 collect (caddr i))))
4704 (with-current-buffer
4705 (url-retrieve-synchronously request)
4706 (fetch)))))
4708 (defun anything-c-yahoo-suggest-set-candidates ()
4709 "Set candidates with Yahoo results found."
4710 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
4711 (or suggestions
4712 (append
4713 suggestions
4714 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
4715 anything-input))))))
4717 (defun anything-c-yahoo-suggest-action (candidate)
4718 "Default action to jump to a Yahoo suggested candidate."
4719 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
4720 (url-hexify-string candidate))))
4722 (defvar anything-c-source-yahoo-suggest
4723 '((name . "Yahoo Suggest")
4724 (candidates . anything-c-yahoo-suggest-set-candidates)
4725 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
4726 (volatile)
4727 (requires-pattern . 3)
4728 (delayed)))
4730 ;; (anything 'anything-c-source-yahoo-suggest)
4732 ;;; Surfraw
4733 ;;; Need external program surfraw.
4734 ;;; http://surfraw.alioth.debian.org/
4735 ;; user variables
4736 (require 'browse-url)
4737 (defvar w3m-command nil)
4738 (defvar anything-c-home-url "http://www.google.fr"
4739 "*Default url to use as home url.")
4741 (defvar anything-browse-url-default-browser-alist
4742 `((,w3m-command . w3m-browse-url)
4743 (,browse-url-firefox-program . browse-url-firefox)
4744 (,browse-url-kde-program . browse-url-kde)
4745 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
4746 (,browse-url-mozilla-program . browse-url-mozilla)
4747 (,browse-url-galeon-program . browse-url-galeon)
4748 (,browse-url-netscape-program . browse-url-netscape)
4749 (,browse-url-mosaic-program . browse-url-mosaic)
4750 (,browse-url-xterm-program . browse-url-text-xterm))
4751 "*Alist of (executable . function) to try to find a suitable url browser.")
4753 (defun anything-browse-url-default-browser (url &rest args)
4754 "Find a suitable browser and ask it to load URL."
4755 (let ((default-browser (loop
4756 for i in anything-browse-url-default-browser-alist
4757 when (and (car i) (executable-find (car i))) return (cdr i))))
4758 (if default-browser
4759 (apply default-browser url args)
4760 (error "No usable browser found"))))
4762 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
4763 "Default command to browse URL."
4764 (if browse-url-browser-function
4765 (browse-url url)
4766 (anything-browse-url-default-browser url)))
4768 (defun anything-c-build-elvi-list ()
4769 "Return list of all engines and descriptions handled by surfraw."
4770 (cdr
4771 (with-temp-buffer
4772 (call-process "surfraw" nil t nil
4773 "-elvi")
4774 (split-string (buffer-string) "\n"))))
4776 ;;;###autoload
4777 (defun anything-surfraw (pattern engine)
4778 "Preconfigured `anything' to search PATTERN with search ENGINE."
4779 (interactive (list (read-string "SearchFor: ")
4780 (anything-comp-read
4781 "Engine: "
4782 (anything-c-build-elvi-list)
4783 :must-match t)))
4784 (let* ((engine-nodesc (car (split-string engine)))
4785 (url (with-temp-buffer
4786 (apply 'call-process "surfraw" nil t nil
4787 (list engine-nodesc "-p" pattern))
4788 (replace-regexp-in-string
4789 "\n" "" (buffer-string)))))
4790 (if (string= engine-nodesc "W")
4791 (anything-c-browse-url)
4792 (anything-c-browse-url url))))
4794 ;;; Emms
4796 ;;;###autoload
4797 (defun anything-emms-stream-edit-bookmark (elm)
4798 "Change the information of current emms-stream bookmark from anything."
4799 (interactive)
4800 (let* ((cur-buf anything-current-buffer)
4801 (bookmark (assoc elm emms-stream-list))
4802 (name (read-from-minibuffer "Description: "
4803 (nth 0 bookmark)))
4804 (url (read-from-minibuffer "URL: "
4805 (nth 1 bookmark)))
4806 (fd (read-from-minibuffer "Feed Descriptor: "
4807 (int-to-string (nth 2 bookmark))))
4808 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4809 (format "%s" (car (last bookmark))))))
4810 (save-excursion
4811 (emms-streams)
4812 (when (re-search-forward (concat "^" name) nil t)
4813 (beginning-of-line)
4814 (emms-stream-delete-bookmark)
4815 (emms-stream-add-bookmark name url (string-to-number fd) type)
4816 (emms-stream-save-bookmarks-file)
4817 (emms-stream-quit)
4818 (switch-to-buffer cur-buf)))))
4820 (defun anything-emms-stream-delete-bookmark (elm)
4821 "Delete an emms-stream bookmark from anything."
4822 (interactive)
4823 (let* ((cur-buf anything-current-buffer)
4824 (bookmark (assoc elm emms-stream-list))
4825 (name (nth 0 bookmark)))
4826 (save-excursion
4827 (emms-streams)
4828 (when (re-search-forward (concat "^" name) nil t)
4829 (beginning-of-line)
4830 (emms-stream-delete-bookmark)
4831 (emms-stream-save-bookmarks-file)
4832 (emms-stream-quit)
4833 (switch-to-buffer cur-buf)))))
4835 (defvar anything-c-source-emms-streams
4836 '((name . "Emms Streams")
4837 (init . (lambda ()
4838 (emms-stream-init)))
4839 (candidates . (lambda ()
4840 (mapcar 'car emms-stream-list)))
4841 (action . (("Play" . (lambda (elm)
4842 (let* ((stream (assoc elm emms-stream-list))
4843 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
4844 (url (second stream)))
4845 (funcall fn url))))
4846 ("Delete" . anything-emms-stream-delete-bookmark)
4847 ("Edit" . anything-emms-stream-edit-bookmark)))
4848 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4849 ;; (anything 'anything-c-source-emms-streams)
4851 ;; Don't forget to set `emms-source-file-default-directory'
4852 (defvar anything-c-source-emms-dired
4853 '((name . "Music Directory")
4854 (candidates . (lambda ()
4855 (cddr (directory-files emms-source-file-default-directory))))
4856 (action .
4857 (("Play Directory" . (lambda (item)
4858 (emms-play-directory
4859 (expand-file-name
4860 item
4861 emms-source-file-default-directory))))
4862 ("Open dired in file's directory" . (lambda (item)
4863 (anything-c-open-dired
4864 (expand-file-name
4865 item
4866 emms-source-file-default-directory))))))
4867 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4868 ;; (anything 'anything-c-source-emms-dired)
4870 (defface anything-emms-playlist
4871 '((t (:foreground "Springgreen4" :underline t)))
4872 "*Face used for tracks in current emms playlist."
4873 :group 'anything)
4875 (defun anything-c-emms-files-modifier (candidates)
4876 (let ((current-playlist (with-current-emms-playlist
4877 (loop
4878 with cur-list = (emms-playlist-tracks-in-region
4879 (point-min) (point-max))
4880 for i in cur-list
4881 collect (assoc-default 'info-file i)))))
4882 (loop for i in candidates
4883 if (member i current-playlist)
4884 collect (propertize i 'face 'anything-emms-playlist) into lis
4885 else collect i into lis finally return lis)))
4887 (defun anything-c-emms-play-current-playlist ()
4888 "Play current playlist."
4889 (with-current-emms-playlist
4890 (emms-playlist-first)
4891 (emms-playlist-mode-play-smart)))
4893 (defvar anything-c-source-emms-files
4894 '((name . "Emms files")
4895 (candidates . (lambda ()
4896 (loop for v being the hash-values in emms-cache-db
4897 for name = (assoc-default 'name v)
4898 unless (string-match "^http:" name) collect name)))
4899 (candidate-transformer . anything-c-emms-files-modifier)
4900 (action . (("Play file" . emms-play-file)
4901 ("Add to Playlist and play"
4902 . (lambda (candidate)
4903 (emms-playlist-new)
4904 (dolist (i (anything-marked-candidates))
4905 (emms-add-playlist-file i))
4906 (unless emms-player-playing-p
4907 (anything-c-emms-play-current-playlist))))))))
4909 ;; (anything 'anything-c-source-emms-files)
4911 ;;; Jabber Contacts (jabber.el)
4912 (defun anything-c-jabber-online-contacts ()
4913 "List online Jabber contacts."
4914 (with-no-warnings
4915 (let (jids)
4916 (dolist (item (jabber-concat-rosters) jids)
4917 (when (get item 'connected)
4918 (push (if (get item 'name)
4919 (cons (get item 'name) item)
4920 (cons (symbol-name item) item)) jids))))))
4922 (defvar anything-c-source-jabber-contacts
4923 '((name . "Jabber Contacts")
4924 (init . (lambda () (require 'jabber)))
4925 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
4926 (action . (lambda (x)
4927 (jabber-chat-with
4928 (jabber-read-account)
4929 (symbol-name
4930 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
4931 ;; (anything 'anything-c-source-jabber-contacts)
4934 ;;; Call source.
4935 (defvar anything-source-select-buffer "*anything source select*")
4936 (defvar anything-c-source-call-source
4937 `((name . "Call anything source")
4938 (candidate-number-limit)
4939 (candidates . (lambda ()
4940 (loop for vname in (all-completions "anything-c-source-" obarray)
4941 for var = (intern vname)
4942 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
4943 if name collect (cons (format "%s `%s'"
4944 name (propertize vname 'face 'font-lock-variable-name-face))
4945 var))))
4946 (action . (("Invoke anything with selected source" .
4947 (lambda (candidate)
4948 (setq anything-candidate-number-limit 9999)
4949 (anything candidate nil nil nil nil
4950 anything-source-select-buffer)))
4951 ("Describe variable" . describe-variable)
4952 ("Find variable" . find-variable)))
4953 (persistent-action . describe-variable)
4954 (persistent-help . "Show description of this source")))
4955 ;; (anything 'anything-c-source-call-source)
4957 ;;;###autoload
4958 (defun anything-call-source ()
4959 "Preconfigured `anything' to call anything source."
4960 (interactive)
4961 (anything 'anything-c-source-call-source nil nil nil nil
4962 anything-source-select-buffer))
4964 (defun anything-call-source-from-anything ()
4965 "Call anything source within `anything' session."
4966 (interactive)
4967 (setq anything-input-idle-delay 0)
4968 (anything-set-sources '(anything-c-source-call-source)))
4970 ;;; Execute Preconfigured anything.
4971 (defvar anything-c-source-anything-commands
4972 '((name . "Preconfigured Anything")
4973 (candidates . anything-c-anything-commands-candidates)
4974 (type . command)
4975 (candidate-number-limit)))
4976 ;; (anything 'anything-c-source-anything-commands)
4978 (defun anything-c-anything-commands-candidates ()
4979 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
4980 collect (cons (if (where-is-internal cmd nil t)
4981 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
4982 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
4983 cmd)))
4985 ;;;###autoload
4986 (defun anything-execute-anything-command ()
4987 "Preconfigured `anything' to execute preconfigured `anything'."
4988 (interactive)
4989 (anything-other-buffer 'anything-c-source-anything-commands
4990 "*anything commands*"))
4992 ;; Occur
4994 (defun anything-c-occur-goto-line (candidate)
4995 "Goto line action for anything-c-source-occur."
4996 (anything-goto-line (string-to-number candidate)))
4998 (defun anything-c-occur-persistent-action (candidate)
4999 "Persistent action for anything occur source."
5000 (anything-c-occur-goto-line candidate)
5001 (anything-match-line-color-current-line))
5003 (defun anything-c-get-occur-candidates ()
5004 "Get `anything-c-source-occur' candidates."
5005 (with-temp-buffer
5006 (let ((count (occur-engine
5007 anything-pattern
5008 (list anything-current-buffer) (current-buffer)
5009 list-matching-lines-default-context-lines nil
5010 list-matching-lines-buffer-name-face
5011 nil list-matching-lines-face
5012 (not (eq occur-excluded-properties t)))))
5013 (when (> count 0)
5014 (cdr (split-string (buffer-string) "\n" t))))))
5016 (defvar anything-c-source-occur
5017 '((name . "Occur")
5018 (candidates . anything-c-get-occur-candidates)
5019 (persistent-action . anything-c-occur-persistent-action)
5020 (persistent-help . "Goto Line")
5021 (action . anything-c-occur-goto-line)
5022 (requires-pattern . 1)
5023 (delayed)
5024 (volatile)))
5025 ;; (anything 'anything-c-source-occur)
5027 ;;;###autoload
5028 (defun anything-occur ()
5029 "Preconfigured Anything for Occur source."
5030 (interactive)
5031 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*"))
5033 ;; Do many actions for input
5034 (defvar anything-c-source-create
5035 '((name . "Create")
5036 (dummy)
5037 (action)
5038 (action-transformer . anything-create--actions))
5039 "Do many create actions from `anything-pattern'.
5040 See also `anything-create--actions'.")
5041 ;; (anything 'anything-c-source-create)
5043 (defun anything-create-from-anything ()
5044 "Run `anything-create' from `anything' as a fallback."
5045 (interactive)
5046 (anything-run-after-quit 'anything-create nil anything-pattern))
5048 ;;;###autoload
5049 (defun anything-create (&optional string initial-input)
5050 "Preconfigured `anything' to do many create actions from STRING.
5051 See also `anything-create--actions'."
5052 (interactive)
5053 (setq string (or string (read-string "Create Anything: " initial-input)))
5054 (anything '(((name . "Anything Create")
5055 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
5056 (candidates . anything-create--actions)
5057 (candidate-number-limit)
5058 (action . (lambda (func) (funcall func string)))))))
5060 (defun anything-create--actions (&rest ignored)
5061 "Default actions for `anything-create' / `anything-c-source-create'."
5062 (remove-if-not
5063 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
5064 (append anything-create--actions-private
5065 '(("find-file" . find-file)
5066 ("find-file other window" . find-file-other-window)
5067 ("New buffer" . switch-to-buffer)
5068 ("New buffer other window" . switch-to-buffer-other-window)
5069 ("Bookmark Set" . bookmark-set)
5070 ("Set Register" .
5071 (lambda (x) (set-register (read-char "Register: ") x)))
5072 ("Insert Linkd star" . linkd-insert-star)
5073 ("Insert Linkd Tag" . linkd-insert-tag)
5074 ("Insert Linkd Link" . linkd-insert-link)
5075 ("Insert Linkd Lisp" . linkd-insert-lisp)
5076 ("Insert Linkd Wiki" . linkd-insert-wiki)
5077 ("Google Search" . google)))))
5079 ;; Minibuffer History
5080 (defvar anything-c-source-minibuffer-history
5081 '((name . "Minibuffer History")
5082 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
5083 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
5084 (if (consp (car history))
5085 (mapcar 'prin1-to-string history)
5086 history))))
5087 (migemo)
5088 (action . insert)))
5089 ;; (anything 'anything-c-source-minibuffer-history)
5091 ;; elscreen
5092 (defvar anything-c-source-elscreen
5093 '((name . "Elscreen")
5094 (candidates . (lambda ()
5095 (if (cdr (elscreen-get-screen-to-name-alist))
5096 (sort
5097 (loop for sname in (elscreen-get-screen-to-name-alist)
5098 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
5099 finally (return lst))
5100 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
5101 (action . (("Change Screen".
5102 (lambda (candidate)
5103 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
5104 ("Kill Screen(s)".
5105 (lambda (candidate)
5106 (dolist (i (anything-marked-candidates))
5107 (elscreen-goto (- (aref i 1) (aref "0" 0)))
5108 (elscreen-kill))))
5109 ("Only Screen".
5110 (lambda (candidate)
5111 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
5112 (elscreen-kill-others)))))))
5113 ;; (anything 'anything-c-source-elscreen)
5115 ;;;; <System>
5117 ;;; Top (process)
5118 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
5119 "Top command (batch mode). %s is replaced with `frame-width'.")
5120 (defvar anything-c-source-top
5121 '((name . "Top (Press C-c C-u to refresh)")
5122 (init . anything-c-top-init)
5123 (candidates-in-buffer)
5124 (display-to-real . anything-c-top-display-to-real)
5125 (update . anything-c-top-update)
5126 (action
5127 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
5128 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
5129 ("Copy PID" . (lambda (pid) (kill-new pid))))))
5130 ;; (anything 'anything-c-source-top)
5132 (defun anything-c-top-sh (cmd)
5133 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
5135 (defun anything-c-top-init ()
5136 (with-current-buffer (anything-candidate-buffer 'global)
5137 (call-process-shell-command
5138 (format anything-c-top-command
5139 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
5140 nil (current-buffer))))
5142 (defun anything-c-top-display-to-real (line)
5143 (car (split-string line)))
5145 (defun anything-c-top-update ()
5146 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
5147 (anything-c-top-init)))
5149 ;;;###autoload
5150 (defun anything-top ()
5151 "Preconfigured `anything' for top command."
5152 (interactive)
5153 (let ((anything-samewindow t)
5154 (anything-enable-shortcuts)
5155 (anything-display-function 'anything-default-display-buffer)
5156 (anything-candidate-number-limit 9999))
5157 (save-window-excursion
5158 (delete-other-windows)
5159 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
5161 ;;; Timers
5162 (defvar anything-c-source-absolute-time-timers
5163 '((name . "Absolute Time Timers")
5164 (candidates . timer-list)
5165 (type . timer)))
5166 ;; (anything 'anything-c-source-absolute-time-timers)
5168 (defvar anything-c-source-idle-time-timers
5169 '((name . "Idle Time Timers")
5170 (candidates . timer-idle-list)
5171 (type . timer)))
5172 ;; (anything 'anything-c-source-idle-time-timers)
5174 (defun anything-c-timer-real-to-display (timer)
5175 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
5176 (append timer nil) ;use `append' to convert vector->list
5177 (format "%s repeat=%5S %s(%s)"
5178 (let ((time (list t1 t2 t3)))
5179 (if idle-delay
5180 (format-time-string "idle-for=%5s" time)
5181 (format-time-string "%m/%d %T" time)))
5182 repeat-delay
5183 func
5184 (mapconcat 'prin1-to-string args " "))))
5186 ;;; X RandR resolution change
5187 ;;; FIXME I do not care multi-display.
5188 (defvar anything-c-xrandr-output "VGA")
5189 (defvar anything-c-xrandr-screen "0")
5190 (defvar anything-c-source-xrandr-change-resolution
5191 '((name . "Change Resolution")
5192 (candidates
5193 . (lambda ()
5194 (with-temp-buffer
5195 (call-process "xrandr" nil (current-buffer) nil
5196 "--screen" anything-c-xrandr-screen "-q")
5197 (goto-char 1)
5198 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
5199 collect (match-string 1)))))
5200 (action
5201 ("Change Resolution" . (lambda (mode)
5202 (call-process "xrandr" nil nil nil
5203 "--screen" anything-c-xrandr-screen
5204 "--output" anything-c-xrandr-output
5205 "--mode" mode))))))
5206 ;; (anything 'anything-c-source-xrandr-change-resolution)
5208 ;;; Xfont selection
5209 (defun anything-c-persistent-xfont-action (elm)
5210 "Show current font temporarily"
5211 (let ((current-font (cdr (assoc 'font (frame-parameters))))
5212 (default-font elm))
5213 (unwind-protect
5214 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
5215 (set-frame-font current-font))))
5217 (defvar anything-c-xfonts-cache nil)
5218 (defvar anything-c-source-xfonts
5219 '((name . "X Fonts")
5220 (init . (lambda ()
5221 (unless anything-c-xfonts-cache
5222 (setq anything-c-xfonts-cache
5223 (x-list-fonts "*")))))
5224 (candidates . anything-c-xfonts-cache)
5225 (action . (("Copy to kill ring" . (lambda (elm)
5226 (kill-new elm)))
5227 ("Set Font" . (lambda (elm)
5228 (kill-new elm)
5229 (set-frame-font elm 'keep-size)
5230 (message "New font have been copied to kill ring")))))
5231 (persistent-action . anything-c-persistent-xfont-action)
5232 (persistent-help . "Switch to this font temporarily")))
5234 ;;;###autoload
5235 (defun anything-select-xfont ()
5236 "Preconfigured `anything' to select Xfont."
5237 (interactive)
5238 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
5240 ;; (anything 'anything-c-source-xfonts)
5242 ;;; Source for Debian/Ubuntu users
5243 (defvar anything-c-source-apt
5244 '((name . "APT")
5245 (init . anything-c-apt-init)
5246 (candidates-in-buffer)
5247 (candidate-transformer anything-c-apt-candidate-transformer)
5248 (display-to-real . anything-c-apt-display-to-real)
5249 (candidate-number-limit . 9999)
5250 (action
5251 ("Show package description" . anything-c-apt-cache-show)
5252 ("Install package" . anything-c-apt-install)
5253 ("Remove package" . anything-c-apt-uninstall)
5254 ("Purge package" . anything-c-apt-purge))
5255 (persistent-action . anything-c-apt-persistent-action)
5256 (persistent-help . "Show - C-u Refresh")))
5257 ;; (anything 'anything-c-source-apt)
5259 (defvar anything-c-apt-query "emacs")
5260 (defvar anything-c-apt-search-command "apt-cache search '%s'")
5261 (defvar anything-c-apt-show-command "apt-cache show '%s'")
5262 (defvar anything-c-apt-installed-packages nil)
5264 (defface anything-apt-installed
5265 '((t (:foreground "green")))
5266 "*Face used for apt installed candidates."
5267 :group 'anything)
5269 (defun anything-c-apt-refresh ()
5270 "Refresh installed candidates list."
5271 (setq anything-c-apt-installed-packages nil)
5272 (anything-force-update))
5274 (defun anything-c-apt-persistent-action (candidate)
5275 "Persistent action for APT source."
5276 (if current-prefix-arg
5277 (anything-c-apt-refresh)
5278 (anything-c-apt-cache-show candidate)))
5280 ;;;###autoload
5281 (defun anything-apt (query)
5282 "Preconfigured `anything' : frontend of APT package manager."
5283 (interactive "sAPT search: ")
5284 (let ((anything-c-apt-query query))
5285 (anything 'anything-c-source-apt)))
5287 (defun anything-c-apt-candidate-transformer (candidates)
5288 "Show installed candidates in a different color."
5289 (loop
5290 with all
5291 for cand in candidates
5292 for name = (anything-c-apt-display-to-real cand)
5293 if (member name anything-c-apt-installed-packages)
5294 collect (propertize cand 'face 'anything-apt-installed) into all
5295 else collect cand into all finally return all))
5297 (defun anything-c-apt-init ()
5298 "Initialize list of debian packages."
5299 (unless anything-c-apt-installed-packages
5300 (message "Updating installed candidate list...")
5301 (setq anything-c-apt-installed-packages
5302 (with-temp-buffer
5303 (call-process-shell-command "dpkg --get-selections"
5304 nil (current-buffer))
5305 (loop for i in (split-string (buffer-string) "\n" t)
5306 collect (car (split-string i))))))
5307 (with-current-buffer
5308 (anything-candidate-buffer
5309 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
5310 (erase-buffer)
5311 (call-process-shell-command
5312 (format anything-c-apt-search-command anything-c-apt-query)
5313 nil (current-buffer)))
5314 (message "Updating installed candidate list...done"))
5316 (defun anything-c-apt-display-to-real (line)
5317 "Return only name of a debian package.
5318 LINE is displayed like:
5319 package name - description."
5320 (car (split-string line " - ")))
5322 ;;;###autoload
5323 (defun anything-c-shell-command-if-needed (command)
5324 (interactive "sShell command: ")
5325 (if (get-buffer command) ; if the buffer already exists
5326 (switch-to-buffer command) ; then just switch to it
5327 (switch-to-buffer command) ; otherwise create it
5328 (insert (shell-command-to-string command))))
5330 (defun anything-c-apt-cache-show (package)
5331 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
5333 (defun anything-c-apt-install (package)
5334 (anything-c-apt-install1 package :action 'install))
5336 (defun anything-c-apt-uninstall (package)
5337 (anything-c-apt-install1 package :action 'uninstall))
5339 (defun anything-c-apt-purge (package)
5340 (anything-c-apt-install1 package :action 'purge))
5342 (defun* anything-c-apt-install1 (candidate &key action)
5343 (ansi-term (getenv "SHELL") "anything apt")
5344 (term-line-mode)
5345 (let ((command (case action
5346 ('install "sudo apt-get install '%s'")
5347 ('uninstall "sudo apt-get remove '%s'")
5348 ('purge "sudo apt-get purge '%s'")
5349 (t (error "Unknow action"))))
5350 (beg (point)) end)
5351 (goto-char (point-max))
5352 (insert (format command candidate))
5353 (setq end (point))
5354 (if (y-or-n-p (format "%s package" (symbol-name action)))
5355 (progn
5356 (setq anything-c-external-commands-list nil)
5357 (setq anything-c-apt-installed-packages nil)
5358 (term-char-mode) (term-send-input))
5359 (delete-region beg end) (term-send-eof) (kill-buffer))))
5361 ;; (anything-c-apt-install "jed")
5363 ;;; Sources for gentoo users
5364 (defvar anything-c-gentoo-use-flags nil)
5365 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
5366 (defvar anything-c-cache-gentoo nil)
5367 (defvar anything-c-cache-world nil)
5368 (defvar anything-c-source-gentoo
5369 '((name . "Portage sources")
5370 (init . (lambda ()
5371 (get-buffer-create anything-c-gentoo-buffer)
5372 (unless anything-c-cache-gentoo
5373 (anything-c-gentoo-setup-cache))
5374 (unless anything-c-cache-world
5375 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
5376 (anything-c-gentoo-init-list)))
5377 (candidates-in-buffer)
5378 (match . identity)
5379 (candidate-transformer anything-c-highlight-world)
5380 (action . (("Show package" . (lambda (elm)
5381 (anything-c-gentoo-eshell-action elm "eix")))
5382 ("Show history" . (lambda (elm)
5383 (if (member elm anything-c-cache-world)
5384 (anything-c-gentoo-eshell-action elm "genlop -qe")
5385 (message "No infos on packages not yet installed"))))
5386 ("Copy in kill-ring" . kill-new)
5387 ("insert at point" . insert)
5388 ("Browse HomePage" . (lambda (elm)
5389 (let ((urls (anything-c-gentoo-get-url elm)))
5390 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
5391 ("Show extra infos" . (lambda (elm)
5392 (if (member elm anything-c-cache-world)
5393 (anything-c-gentoo-eshell-action elm "genlop -qi")
5394 (message "No infos on packages not yet installed"))))
5395 ("Show use flags" . (lambda (elm)
5396 (anything-c-gentoo-default-action elm "equery" "-C" "u")
5397 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
5398 (font-lock-mode 1)))
5399 ("Run emerge pretend" . (lambda (elm)
5400 (anything-c-gentoo-eshell-action elm "emerge -p")))
5401 ("Emerge" . (lambda (elm)
5402 (anything-gentoo-install elm :action 'install)))
5403 ("Unmerge" . (lambda (elm)
5404 (anything-gentoo-install elm :action 'uninstall)))
5405 ("Show dependencies" . (lambda (elm)
5406 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
5407 ("Show related files" . (lambda (elm)
5408 (anything-c-gentoo-default-action elm "equery" "files")))
5409 ("Refresh" . (lambda (elm)
5410 (anything-c-gentoo-setup-cache)
5411 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
5413 ;; (anything 'anything-c-source-gentoo)
5415 (defun* anything-gentoo-install (candidate &key action)
5416 (setq anything-c-external-commands-list nil)
5417 (ansi-term (getenv "SHELL") "anything gentoo")
5418 (term-line-mode)
5419 (let ((command (case action
5420 ('install "sudo emerge -av ")
5421 ('uninstall "sudo emerge -avC ")
5422 (t (error "Unknow action"))))
5423 (elms (mapconcat 'identity (anything-marked-candidates) " "))
5424 (beg (point)) end)
5425 (goto-char (point-max))
5426 (insert (concat command elms))
5427 (setq end (point))
5428 (term-char-mode) (term-send-input)))
5430 (defun anything-c-gentoo-default-action (elm command &rest args)
5431 "Gentoo default action that use `anything-c-gentoo-buffer'."
5432 (if (member elm anything-c-cache-world)
5433 (progn
5434 (switch-to-buffer anything-c-gentoo-buffer)
5435 (erase-buffer)
5436 (let ((com-list (append args (list elm))))
5437 (apply #'call-process command nil t nil
5438 com-list)))
5439 (message "No infos on packages not yet installed")))
5441 (defvar anything-c-source-use-flags
5442 '((name . "Use Flags")
5443 (init . (lambda ()
5444 (unless anything-c-gentoo-use-flags
5445 (anything-c-gentoo-setup-use-flags-cache))
5446 (anything-c-gentoo-get-use)))
5447 (candidates-in-buffer)
5448 (match . identity)
5449 (candidate-transformer anything-c-highlight-local-use)
5450 (action . (("Description"
5451 . (lambda (elm)
5452 (switch-to-buffer anything-c-gentoo-buffer)
5453 (erase-buffer)
5454 (apply #'call-process "euse" nil t nil
5455 `("-i"
5456 ,elm))
5457 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
5458 (font-lock-mode 1)))
5459 ("Enable"
5460 . (lambda (elm)
5461 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
5462 ("Disable"
5463 . (lambda (elm)
5464 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
5465 ("Remove"
5466 . (lambda (elm)
5467 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
5468 ("Show which dep use this flag"
5469 . (lambda (elm)
5470 (switch-to-buffer anything-c-gentoo-buffer)
5471 (erase-buffer)
5472 (apply #'call-process "equery" nil t nil
5473 `("-C"
5475 ,elm))))))))
5478 ;; (anything 'anything-c-source-use-flags)
5480 (defun anything-c-gentoo-init-list ()
5481 "Initialize buffer with all packages in Portage."
5482 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
5483 (buf (anything-candidate-buffer 'portage-buf)))
5484 (with-current-buffer buf
5485 (dolist (i anything-c-cache-gentoo)
5486 (insert (concat i "\n"))))))
5488 (defun anything-c-gentoo-setup-cache ()
5489 "Set up `anything-c-cache-gentoo'"
5490 (setq anything-c-cache-gentoo
5491 (split-string (with-temp-buffer
5492 (call-process "eix" nil t nil
5493 "--only-names")
5494 (buffer-string)))))
5496 (defun anything-c-gentoo-eshell-action (elm command)
5497 (when (get-buffer "*EShell Command Output*")
5498 (kill-buffer "*EShell Command Output*"))
5499 (message "Wait searching...")
5500 (let ((buf-fname (buffer-file-name anything-current-buffer)))
5501 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
5502 (progn
5503 (save-window-excursion
5504 (pop-to-buffer "*scratch*")
5505 (eshell-command (format "%s %s" command elm)))
5506 (pop-to-buffer "*EShell Command Output*"))
5507 (eshell-command (format "%s %s" command elm)))))
5509 (defun anything-c-gentoo-get-use ()
5510 "Initialize buffer with all use flags."
5511 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
5512 (buf (anything-candidate-buffer 'use-buf)))
5513 (with-current-buffer buf
5514 (dolist (i anything-c-gentoo-use-flags)
5515 (insert (concat i "\n"))))))
5518 (defun anything-c-gentoo-setup-use-flags-cache ()
5519 "Setup `anything-c-gentoo-use-flags'"
5520 (setq anything-c-gentoo-use-flags
5521 (split-string (with-temp-buffer
5522 (call-process "eix" nil t nil
5523 "--print-all-useflags")
5524 (buffer-string)))))
5526 (defun anything-c-gentoo-get-url (elm)
5527 "Return a list of urls from eix output."
5528 (loop
5529 with url-list = (split-string
5530 (with-temp-buffer
5531 (call-process "eix" nil t nil
5532 elm "--format" "<homepage>\n")
5533 (buffer-string)))
5534 with all
5535 for i in url-list
5536 when (and (string-match "^http://.*" i)
5537 (not (member i all)))
5538 collect i into all
5539 finally return all))
5541 (defun anything-c-gentoo-get-world ()
5542 "Return list of all installed package on your system."
5543 (split-string (with-temp-buffer
5544 (call-process "qlist" nil t nil
5545 "-I")
5546 (buffer-string))))
5548 (defun anything-c-gentoo-get-local-use ()
5549 (split-string (with-temp-buffer
5550 (call-process "portageq" nil t nil
5551 "envvar"
5552 "USE")
5553 (buffer-string))))
5555 (defface anything-gentoo-match-face '((t (:foreground "red")))
5556 "Face for anything-gentoo installed packages."
5557 :group 'traverse-faces)
5559 (defun anything-c-highlight-world (eix)
5560 "Highlight all installed package."
5561 (loop for i in eix
5562 if (member i anything-c-cache-world)
5563 collect (propertize i 'face 'anything-gentoo-match-face)
5564 else
5565 collect i))
5567 (defun anything-c-highlight-local-use (use-flags)
5568 (let ((local-uses (anything-c-gentoo-get-local-use)))
5569 (loop for i in use-flags
5570 if (member i local-uses)
5571 collect (propertize i 'face 'anything-gentoo-match-face)
5572 else
5573 collect i)))
5575 (defvar anything-c-source-emacs-process
5576 '((name . "Emacs Process")
5577 (candidates . (lambda () (mapcar #'process-name (process-list))))
5578 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
5580 ;; (anything 'anything-c-source-emacs-process)
5582 ;; Run Externals commands within Emacs
5583 (defmacro* anything-comp-hash-get-items (hash-table &key test)
5584 "Get the list of all keys/values of hash-table."
5585 `(let ((li-items ()))
5586 (maphash #'(lambda (x y)
5587 (if ,test
5588 (when (funcall ,test y)
5589 (push (list x y) li-items))
5590 (push (list x y) li-items)))
5591 ,hash-table)
5592 li-items))
5594 (defun anything-comp-read-get-candidates (collection &optional test)
5595 "Convert collection to list.
5596 If collection is an `obarray', a test is maybe needed, otherwise
5597 the list would be incomplete.
5598 See `obarray'."
5599 (cond ((and (listp collection) test)
5600 (loop for i in collection when (funcall test i) collect i))
5601 ((and (eq collection obarray) test)
5602 (loop for s being the symbols of collection
5603 when (funcall test s) collect s))
5604 ((and (vectorp collection) test)
5605 (loop for i across collection when (funcall test i) collect i))
5606 ((vectorp collection)
5607 (loop for i across collection collect i))
5608 ((and (hash-table-p collection) test)
5609 (anything-comp-hash-get-items collection :test test))
5610 ((hash-table-p collection)
5611 (anything-comp-hash-get-items collection))
5612 (t collection)))
5614 (defun* anything-comp-read (prompt collection &key test initial-input
5615 (buffer "*Anything Completions*") must-match
5616 (requires-pattern 0))
5617 "Anything `completing-read' emulation.
5618 Collection can be a list, vector, obarray or hash-table."
5619 (when (get-buffer anything-action-buffer)
5620 (kill-buffer anything-action-buffer))
5621 (or (anything
5622 `((name . "Completions")
5623 (candidates
5624 . (lambda ()
5625 (let ((cands (anything-comp-read-get-candidates collection test)))
5626 (if (or must-match (string= anything-pattern ""))
5627 cands (append (list anything-pattern) cands)))))
5628 (requires-pattern . ,requires-pattern)
5629 (volatile)
5630 (action . (("candidate" . ,'identity))))
5631 initial-input prompt 'noresume nil buffer)
5632 (keyboard-quit)))
5634 (defun anything-c-get-pid-from-process-name (process-name)
5635 "Get pid from running process PROCESS-NAME."
5636 (loop with process-list = (list-system-processes)
5637 for pid in process-list
5638 for process = (assoc-default 'comm (process-attributes pid))
5639 when (and process (string-match process-name process))
5640 return pid))
5643 (defun anything-run-or-raise (exe &optional file)
5644 "Generic command that run asynchronously EXE.
5645 If EXE is already running just jump to his window if `anything-raise-command'
5646 is non--nil.
5647 When FILE argument is provided run EXE with FILE.
5648 In this case EXE must be provided as \"EXE %s\"."
5649 (let ((real-com (car (split-string (replace-regexp-in-string " %s" "" exe)))))
5650 (if (or (get-process real-com)
5651 (anything-c-get-pid-from-process-name real-com))
5652 (if anything-raise-command
5653 (shell-command (format anything-raise-command real-com))
5654 (error "Error: %s is already running" real-com))
5655 (when (member real-com anything-c-external-commands-list)
5656 (message "Starting %s..." real-com)
5657 (if file
5658 (start-process-shell-command real-com nil (format exe file))
5659 (start-process-shell-command real-com nil real-com))
5660 (set-process-sentinel
5661 (get-process real-com)
5662 #'(lambda (process event)
5663 (when (string= event "finished\n")
5664 (when anything-raise-command
5665 (shell-command (format anything-raise-command "emacs")))
5666 (message "%s process...Finished." process))))
5667 (setq anything-c-external-commands-list
5668 (push (pop (nthcdr (anything-c-position
5669 real-com anything-c-external-commands-list
5670 :test 'equal)
5671 anything-c-external-commands-list))
5672 anything-c-external-commands-list))))))
5674 ;;;###autoload
5675 (defun anything-c-run-external-command (program)
5676 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
5677 If program is already running exit with error.
5678 You can set your own list of commands with
5679 `anything-c-external-commands-list'."
5680 (interactive (list
5681 (anything-comp-read
5682 "RunProgram: "
5683 (anything-c-external-commands-list-1 'sort)
5684 :must-match t)))
5685 (anything-run-or-raise program))
5687 (defsubst* anything-c-position (item seq &key (test 'eq))
5688 "A simple and faster replacement of CL `position'."
5689 (loop for i in seq for index from 0
5690 when (funcall test i item) return index))
5692 (defvar anything-c-source-ratpoison-commands
5693 '((name . "Ratpoison Commands")
5694 (init . anything-c-ratpoison-commands-init)
5695 (candidates-in-buffer)
5696 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
5697 (display-to-real . anything-c-ratpoison-commands-display-to-real)
5698 (candidate-number-limit)))
5699 ;; (anything 'anything-c-source-ratpoison-commands)
5701 (defun anything-c-ratpoison-commands-init ()
5702 (unless (anything-candidate-buffer)
5703 (with-current-buffer (anything-candidate-buffer 'global)
5704 ;; with ratpoison prefix key
5705 (save-excursion
5706 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
5707 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5708 (replace-match "<ratpoison> \\1: \\2"))
5709 (goto-char (point-max))
5710 ;; direct binding
5711 (save-excursion
5712 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
5713 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5714 (replace-match "\\1: \\2")))))
5716 (defun anything-c-ratpoison-commands-display-to-real (display)
5717 (and (string-match ": " display)
5718 (substring display (match-end 0))))
5720 (defun anything-c-ratpoison-commands-execute (candidate)
5721 (call-process "ratpoison" nil nil nil "-ic" candidate))
5723 ;;;###autoload
5724 (defun anything-ratpoison-commands ()
5725 "Preconfigured `anything' to execute ratpoison commands."
5726 (interactive)
5727 (anything-other-buffer 'anything-c-source-ratpoison-commands
5728 "*anything ratpoison commands*"))
5730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5731 ;;; Files
5732 (defvar anything-c-external-commands-list nil
5733 "A list of all external commands the user can execute. If this
5734 variable is not set by the user, it will be calculated
5735 automatically.")
5737 (defun anything-c-external-commands-list-1 (&optional sort)
5738 "Returns a list of all external commands the user can execute.
5740 If `anything-c-external-commands-list' is non-nil it will
5741 return its contents. Else it calculates all external commands
5742 and sets `anything-c-external-commands-list'.
5744 The code is ripped out of `eshell-complete-commands-list'."
5745 (if anything-c-external-commands-list
5746 anything-c-external-commands-list
5747 (setq anything-c-external-commands-list
5748 (let* ((paths (split-string (getenv "PATH") path-separator))
5749 (cwd (file-name-as-directory
5750 (expand-file-name default-directory)))
5751 (path "") (comps-in-path ())
5752 (file "") (filepath "") (completions ()))
5753 ;; Go thru each path in the search path, finding completions.
5754 (while paths
5755 (setq path (file-name-as-directory
5756 (expand-file-name (or (car paths) ".")))
5757 comps-in-path
5758 (and (file-accessible-directory-p path)
5759 (file-name-all-completions "" path)))
5760 ;; Go thru each completion found, to see whether it should be
5761 ;; used, e.g. see if it's executable.
5762 (while comps-in-path
5763 (setq file (car comps-in-path)
5764 filepath (concat path file))
5765 (if (and (not (member file completions))
5766 (or (string-equal path cwd)
5767 (not (file-directory-p filepath)))
5768 (file-executable-p filepath))
5769 (setq completions (cons file completions)))
5770 (setq comps-in-path (cdr comps-in-path)))
5771 (setq paths (cdr paths)))
5772 (if sort
5773 (sort completions #'(lambda (x y) (string< x y)))
5774 completions)))))
5776 (defun anything-c-file-buffers (filename)
5777 "Returns a list of buffer names corresponding to FILENAME."
5778 (let ((name (expand-file-name filename))
5779 (buf-list ()))
5780 (dolist (buf (buffer-list) buf-list)
5781 (let ((bfn (buffer-file-name buf)))
5782 (when (and bfn (string= name bfn))
5783 (push (buffer-name buf) buf-list))))))
5785 (defun anything-c-delete-file (file)
5786 "Delete the given file after querying the user.
5787 Ask to kill buffers associated with that file, too."
5788 (let ((buffers (anything-c-file-buffers file)))
5789 (dired-delete-file file 'dired-recursive-deletes)
5790 (when buffers
5791 (dolist (buf buffers)
5792 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
5793 (kill-buffer buf))))))
5795 (defun anything-get-mailcap-for-file (filename)
5796 "Get the command to use for FILENAME from mailcap files.
5797 The command is like <command %s> and is meant to use with `format'."
5798 (mailcap-parse-mailcaps)
5799 (let* ((ext (file-name-extension filename))
5800 (mime (when ext (mailcap-extension-to-mime ext))))
5801 (when mime (mailcap-mime-info mime))))
5803 (defun anything-c-open-file-externally (file)
5804 "Open FILE with an external tool found in .mailcap file.
5805 If not found or a prefix arg is given query the user which tool to use."
5806 (let* ((fname (expand-file-name file))
5807 (collection (anything-c-external-commands-list-1 'sort))
5808 (def-prog (anything-get-mailcap-for-file fname))
5809 (program (or (unless (or anything-current-prefix-arg
5810 (not def-prog))
5811 def-prog)
5812 (concat
5813 (anything-comp-read
5814 "Program: "
5815 collection :must-match t)
5816 " %s"))))
5817 (anything-run-or-raise program file)))
5819 ;;;###autoload
5820 (defun w32-shell-execute-open-file (file)
5821 (interactive "fOpen file:")
5822 (with-no-warnings
5823 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
5824 "/" "\\"
5825 (replace-regexp-in-string ; strip cygdrive paths
5826 "/cygdrive/\\(.\\)" "\\1:"
5827 file nil nil) nil t))))
5829 (defun anything-c-open-file-with-default-tool (file)
5830 "Open FILE with the default tool on this platform."
5831 (if (eq system-type 'windows-nt)
5832 (w32-shell-execute-open-file file)
5833 (start-process "anything-c-open-file-with-default-tool"
5835 (cond ((eq system-type 'gnu/linux)
5836 "xdg-open")
5837 ((or (eq system-type 'darwin) ;; Mac OS X
5838 (eq system-type 'macos)) ;; Mac OS 9
5839 "open"))
5840 file)))
5842 (defun anything-c-open-dired (file)
5843 "Opens a dired buffer in FILE's directory. If FILE is a
5844 directory, open this directory."
5845 (if (file-directory-p file)
5846 (dired file)
5847 (dired (file-name-directory file))
5848 (dired-goto-file file)))
5850 (defun anything-c-display-to-real-line (candidate)
5851 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
5852 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
5853 (error "Line number not found")))
5855 (defun anything-c-action-line-goto (lineno-and-content)
5856 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
5857 (append lineno-and-content
5858 (list (if (and (anything-attr-defined 'target-file)
5859 (not anything-in-persistent-action))
5860 'find-file-other-window
5861 'find-file)))))
5863 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
5864 (apply #'anything-goto-file-line
5865 (if (stringp file-line-content)
5866 ;; Case: filtered-candidate-transformer is skipped
5867 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
5868 file-line-content)))
5870 (require 'compile)
5871 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
5872 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
5874 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
5875 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
5876 (let ((filename (match-string 1 candidate))
5877 (lineno (match-string 2 candidate))
5878 (content (match-string 3 candidate)))
5879 (cons (format "%s:%s\n %s"
5880 (propertize filename 'face compilation-info-face)
5881 (propertize lineno 'face compilation-line-face)
5882 content)
5883 (list (expand-file-name
5884 filename
5885 (or (anything-interpret-value (anything-attr 'default-directory))
5886 (and (anything-candidate-buffer)
5887 (buffer-local-value
5888 'default-directory (anything-candidate-buffer)))))
5889 (string-to-number lineno) content)))))
5891 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
5892 (anything-aif (anything-attr 'before-jump-hook)
5893 (funcall it))
5894 (when file (funcall find-file-function file))
5895 (if (anything-attr-defined 'adjust)
5896 (anything-c-goto-line-with-adjustment lineno content)
5897 (anything-goto-line lineno))
5898 (unless (anything-attr-defined 'recenter)
5899 (set-window-start (get-buffer-window anything-current-buffer) (point)))
5900 (anything-aif (anything-attr 'after-jump-hook)
5901 (funcall it))
5902 (when anything-in-persistent-action
5903 (anything-match-line-color-current-line)))
5905 (defun anything-find-file-as-root (candidate)
5906 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
5908 (defun anything-find-many-files (ignore)
5909 (mapc 'find-file (anything-marked-candidates)))
5911 ;; borrowed from etags.el
5912 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
5913 (defun anything-c-goto-line-with-adjustment (line line-content)
5914 (let ((startpos)
5915 offset found pat)
5916 ;; This constant is 1/2 the initial search window.
5917 ;; There is no sense in making it too small,
5918 ;; since just going around the loop once probably
5919 ;; costs about as much as searching 2000 chars.
5920 (setq offset 1000
5921 found nil
5922 pat (concat (if (eq selective-display t)
5923 "\\(^\\|\^m\\) *" "^ *") ;allow indent
5924 (regexp-quote line-content)))
5925 ;; If no char pos was given, try the given line number.
5926 (setq startpos (progn (anything-goto-line line) (point)))
5927 (or startpos (setq startpos (point-min)))
5928 ;; First see if the tag is right at the specified location.
5929 (goto-char startpos)
5930 (setq found (looking-at pat))
5931 (while (and (not found)
5932 (progn
5933 (goto-char (- startpos offset))
5934 (not (bobp))))
5935 (setq found
5936 (re-search-forward pat (+ startpos offset) t)
5937 offset (* 3 offset))) ; expand search window
5938 (or found
5939 (re-search-forward pat nil t)
5940 (error "not found")))
5941 ;; Position point at the right place
5942 ;; if the search string matched an extra Ctrl-m at the beginning.
5943 (and (eq selective-display t)
5944 (looking-at "\^m")
5945 (forward-char 1))
5946 (beginning-of-line))
5948 (anything-document-attribute 'default-directory "type . file-line"
5949 "`default-directory' to interpret file.")
5950 (anything-document-attribute 'before-jump-hook "type . file-line / line"
5951 "Function to call before jumping to the target location.")
5952 (anything-document-attribute 'after-jump-hook "type . file-line / line"
5953 "Function to call after jumping to the target location.")
5954 (anything-document-attribute 'adjust "type . file-line"
5955 "Search around line matching line contents.")
5956 (anything-document-attribute 'recenter "type . file-line / line"
5957 "`recenter' after jumping.")
5958 (anything-document-attribute 'target-file "type . line"
5959 "Goto line of target-file.")
5961 ;;;###autoload
5962 (defun anything-c-call-interactively (cmd-or-name)
5963 "Execute CMD-OR-NAME as Emacs command.
5964 It is added to `extended-command-history'.
5965 `anything-current-prefix-arg' is used as the command's prefix argument."
5966 (setq extended-command-history
5967 (cons (anything-c-stringify cmd-or-name)
5968 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
5969 (let ((current-prefix-arg anything-current-prefix-arg)
5970 (cmd (anything-c-symbolify cmd-or-name)))
5971 (if (stringp (symbol-function cmd))
5972 (execute-kbd-macro (symbol-function cmd))
5973 (setq this-command cmd)
5974 (call-interactively cmd))))
5976 ;;;###autoload
5977 (defun anything-c-set-variable (var)
5978 "Set value to VAR interactively."
5979 (interactive)
5980 (let ((sym (anything-c-symbolify var)))
5981 (set sym (eval-minibuffer (format "Set %s: " var)
5982 (prin1-to-string (symbol-value sym))))))
5983 ;; (setq hh 12)
5984 ;; (anything-c-set-variable 'hh)
5986 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5987 (defvar anything-match-line-overlay-face nil)
5988 (defvar anything-match-line-overlay nil)
5990 (defun anything-match-line-color-current-line (&optional start end buf face rec)
5991 "Highlight and underline current position"
5992 (let ((args (list (or start (line-beginning-position))
5993 (or end (1+ (line-end-position)))
5994 buf)))
5995 (if (not anything-match-line-overlay)
5996 (setq anything-match-line-overlay (apply 'make-overlay args))
5997 (apply 'move-overlay anything-match-line-overlay args)))
5998 (overlay-put anything-match-line-overlay
5999 'face (or face anything-match-line-overlay-face))
6000 (when rec
6001 (goto-char start)
6002 (recenter)))
6004 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
6006 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
6007 "Face for source header in the anything buffer." :group 'anything)
6009 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
6011 (defun anything-match-line-cleanup ()
6012 (when anything-match-line-overlay
6013 (delete-overlay anything-match-line-overlay)
6014 (setq anything-match-line-overlay nil)))
6016 (defun anything-match-line-update ()
6017 (when anything-match-line-overlay
6018 (delete-overlay anything-match-line-overlay)
6019 (anything-match-line-color-current-line)))
6021 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
6022 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
6024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6025 ;;; Files
6026 (defun anything-c-transform-file-load-el (actions candidate)
6027 "Add action to load the file CANDIDATE if it is an emacs lisp
6028 file. Else return ACTIONS unmodified."
6029 (if (member (file-name-extension candidate) '("el" "elc"))
6030 (append actions '(("Load Emacs Lisp File" . load-file)))
6031 actions))
6033 (defun anything-c-transform-file-browse-url (actions candidate)
6034 "Add an action to browse the file CANDIDATE if it in a html
6035 file or URL. Else return ACTIONS unmodified."
6036 (let ((browse-action '("Browse with Browser" . browse-url)))
6037 (cond ((string-match "^http\\|^ftp" candidate)
6038 (cons browse-action actions))
6039 ((string-match "\\.html?$" candidate)
6040 (append actions (list browse-action)))
6041 (t actions))))
6043 ;;;; Function
6044 (defun anything-c-transform-function-call-interactively (actions candidate)
6045 "Add an action to call the function CANDIDATE interactively if
6046 it is a command. Else return ACTIONS unmodified."
6047 (if (commandp (intern-soft candidate))
6048 (append actions '(("Call Interactively"
6050 anything-c-call-interactively)))
6051 actions))
6053 ;;;; S-Expressions
6054 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
6055 "If CANDIDATE's `car' is a command, then add an action to
6056 evaluate it and put it onto the `command-history'."
6057 (if (commandp (car (read candidate)))
6058 ;; Make it first entry
6059 (cons '("Eval and put onto command-history" .
6060 (lambda (sexp)
6061 (let ((sym (read sexp)))
6062 (eval sym)
6063 (setq command-history
6064 (cons sym command-history)))))
6065 actions)
6066 actions))
6068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6069 ;;; Buffers
6070 (defun anything-c-skip-boring-buffers (buffers)
6071 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
6073 (defun anything-c-skip-current-buffer (buffers)
6074 (if anything-allow-skipping-current-buffer
6075 (remove (buffer-name anything-current-buffer) buffers)
6076 buffers))
6078 (defun anything-c-shadow-boring-buffers (buffers)
6079 "Buffers matching `anything-c-boring-buffer-regexp' will be
6080 displayed with the `file-name-shadow' face if available."
6081 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
6083 ;;; Files
6084 (defun anything-c-shadow-boring-files (files)
6085 "Files matching `anything-c-boring-file-regexp' will be
6086 displayed with the `file-name-shadow' face if available."
6087 (anything-c-shadow-entries files anything-c-boring-file-regexp))
6089 (defun anything-c-skip-boring-files (files)
6090 "Files matching `anything-c-boring-file-regexp' will be skipped."
6091 (anything-c-skip-entries files anything-c-boring-file-regexp))
6092 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6094 (defun anything-c-skip-current-file (files)
6095 "Current file will be skipped."
6096 (remove (buffer-file-name anything-current-buffer) files))
6098 (defun anything-c-w32-pathname-transformer (args)
6099 "Change undesirable features of windows pathnames to ones more acceptable to
6100 other candidate transformers."
6101 (if (eq system-type 'windows-nt)
6102 (mapcar (lambda (x)
6103 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
6104 (mapcar (lambda (y)
6105 (replace-regexp-in-string "\\\\" "/" y)) args))
6106 args))
6108 (defun anything-c-shorten-home-path (files)
6109 "Replaces /home/user with ~."
6110 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6111 (getenv "HOME"))))
6112 (mapcar (lambda (file)
6113 (if (and (stringp file) (string-match home file))
6114 (cons (replace-match "~" nil nil file) file)
6115 file))
6116 files)))
6118 ;;; Functions
6119 (defun anything-c-mark-interactive-functions (functions)
6120 "Mark interactive functions (commands) with (i) after the function name."
6121 (let (list)
6122 (loop for function in functions
6123 do (push (cons (concat function
6124 (when (commandp (intern-soft function)) " (i)"))
6125 function)
6126 list)
6127 finally (return (nreverse list)))))
6129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6130 (defvar anything-c-adaptive-done nil
6131 "nil if history information is not yet stored for the current
6132 selection.")
6134 (defvar anything-c-adaptive-history nil
6135 "Contains the stored history information.
6136 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6138 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
6139 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6140 when anything is started."
6141 (setq anything-c-adaptive-done nil))
6143 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
6144 "Advise `anything-exit-minibuffer' to store history information
6145 when a candidate is selected with RET."
6146 (anything-c-adaptive-store-selection))
6148 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
6149 "Advise `anything-select-action' to store history information
6150 when the user goes to the action list with TAB."
6151 (anything-c-adaptive-store-selection))
6153 (defun anything-c-source-use-adaptative-p (&optional source-name)
6154 "Return current source only if it use adaptative history, nil otherwise."
6155 (let* ((source (or source-name (anything-get-current-source)))
6156 (adapt-source (or (assoc-default 'filtered-candidate-transformer
6157 (assoc (assoc-default 'type source)
6158 anything-type-attributes))
6159 (assoc-default 'candidate-transformer
6160 (assoc (assoc-default 'type source)
6161 anything-type-attributes))
6162 (assoc-default 'filtered-candidate-transformer source)
6163 (assoc-default 'candidate-transformer source))))
6164 (if (listp adapt-source)
6165 (when (member 'anything-c-adaptive-sort adapt-source) source)
6166 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
6168 (defun anything-c-adaptive-store-selection ()
6169 "Store history information for the selected candidate."
6170 (unless anything-c-adaptive-done
6171 (setq anything-c-adaptive-done t)
6172 (let ((source (anything-c-source-use-adaptative-p)))
6173 (when source
6174 (let* ((source-name (or (assoc-default 'type source)
6175 (assoc-default 'name source)))
6176 (source-info (or (assoc source-name anything-c-adaptive-history)
6177 (progn
6178 (push (list source-name) anything-c-adaptive-history)
6179 (car anything-c-adaptive-history))))
6180 (selection (anything-get-selection))
6181 (selection-info (progn
6182 (setcdr source-info
6183 (cons
6184 (let ((found (assoc selection (cdr source-info))))
6185 (if (not found)
6186 ;; new entry
6187 (list selection)
6189 ;; move entry to the beginning of the
6190 ;; list, so that it doesn't get
6191 ;; trimmed when the history is
6192 ;; truncated
6193 (setcdr source-info
6194 (delete found (cdr source-info)))
6195 found))
6196 (cdr source-info)))
6197 (cadr source-info)))
6198 (pattern-info (progn
6199 (setcdr selection-info
6200 (cons
6201 (let ((found (assoc anything-pattern (cdr selection-info))))
6202 (if (not found)
6203 ;; new entry
6204 (cons anything-pattern 0)
6206 ;; move entry to the beginning of the
6207 ;; list, so if two patterns used the
6208 ;; same number of times then the one
6209 ;; used last appears first in the list
6210 (setcdr selection-info
6211 (delete found (cdr selection-info)))
6212 found))
6213 (cdr selection-info)))
6214 (cadr selection-info))))
6216 ;; increase usage count
6217 (setcdr pattern-info (1+ (cdr pattern-info)))
6219 ;; truncate history if needed
6220 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
6221 (setcdr selection-info
6222 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
6224 (if (file-readable-p anything-c-adaptive-history-file)
6225 (load-file anything-c-adaptive-history-file))
6226 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
6228 (defun anything-c-adaptive-save-history ()
6229 "Save history information to file given by `anything-c-adaptive-history-file'."
6230 (interactive)
6231 (with-temp-buffer
6232 (insert
6233 ";; -*- mode: emacs-lisp -*-\n"
6234 ";; History entries used for anything adaptive display.\n")
6235 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
6236 (current-buffer))
6237 (insert ?\n)
6238 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
6239 (unless (interactive-p) 'quiet))))
6241 (defun anything-c-adaptive-sort (candidates source)
6242 "Sort the CANDIDATES for SOURCE by usage frequency.
6243 This is a filtered candidate transformer you can use for the
6244 attribute `filtered-candidate-transformer' of a source in
6245 `anything-sources' or a type in `anything-type-attributes'."
6246 (let* ((source-name (or (assoc-default 'type source)
6247 (assoc-default 'name source)))
6248 (source-info (assoc source-name anything-c-adaptive-history)))
6249 (if (not source-info)
6250 ;; if there is no information stored for this source then do nothing
6251 candidates
6252 ;; else...
6253 (let ((usage
6254 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
6255 ;; pairs
6256 (mapcar (lambda (candidate-info)
6257 (let ((count 0))
6258 (dolist (pattern-info (cdr candidate-info))
6259 (if (not (equal (car pattern-info)
6260 anything-pattern))
6261 (incf count (cdr pattern-info))
6263 ;; if current pattern is equal to the previously
6264 ;; used one then this candidate has priority
6265 ;; (that's why its count is boosted by 10000) and
6266 ;; it only has to compete with other candidates
6267 ;; which were also selected with the same pattern
6268 (setq count (+ 10000 (cdr pattern-info)))
6269 (return)))
6270 (cons (car candidate-info) count)))
6271 (cdr source-info)))
6272 sorted)
6274 ;; sort the list in descending order, so candidates with highest
6275 ;; priorty come first
6276 (setq usage (sort usage (lambda (first second)
6277 (> (cdr first) (cdr second)))))
6279 ;; put those candidates first which have the highest usage count
6280 (dolist (info usage)
6281 (when (member* (car info) candidates
6282 :test 'anything-c-adaptive-compare)
6283 (push (car info) sorted)
6284 (setq candidates (remove* (car info) candidates
6285 :test 'anything-c-adaptive-compare))))
6287 ;; and append the rest
6288 (append (reverse sorted) candidates nil)))))
6290 (defun anything-c-adaptive-compare (x y)
6291 "Compare candidates X and Y taking into account that the
6292 candidate can be in (DISPLAY . REAL) format."
6293 (equal (if (listp x)
6294 (cdr x)
6296 (if (listp y)
6297 (cdr y)
6298 y)))
6300 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6301 (defvar anything-outline-goto-near-line-flag t)
6302 (defvar anything-outline-using nil)
6303 (defun anything-after-update-hook--outline ()
6304 (if (and (eq anything-outline-using t)
6305 (eq anything-outline-goto-near-line-flag t))
6306 (anything-outline-goto-near-line)))
6307 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
6309 (defun anything-outline-goto-near-line ()
6310 (with-anything-window
6311 ;; TODO need consideration whether to update position by every input.
6312 (when t ; (equal anything-pattern "")
6313 (anything-goto-line 2)
6314 (let ((lineno (with-current-buffer anything-current-buffer
6315 (line-number-at-pos (car anything-current-position)))))
6316 (block exit
6317 (while (<= (progn (skip-chars-forward " ")
6318 (or (number-at-point) lineno))
6319 lineno)
6320 (forward-line 1)
6321 (when (eobp)
6322 (forward-line -1)
6323 (return-from exit))))
6324 (forward-line -1)
6325 (and (bobp) (forward-line 1))
6326 (and (anything-pos-header-line-p) (forward-line -2))
6327 (anything-mark-current-line)))))
6329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6330 ;; Plug-in: info-index
6331 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
6332 (let (result)
6333 (unless (anything-candidate-buffer)
6334 (save-window-excursion
6335 (info file)
6336 (let (Info-history
6337 (tobuf (anything-candidate-buffer 'global))
6338 (infobuf (current-buffer))
6339 s e)
6340 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
6341 (Info-goto-node node)
6342 (goto-char (point-min))
6343 (while (search-forward "\n* " nil t)
6344 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
6345 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
6346 (setq s (point-at-bol)
6347 e (point-at-eol))
6348 (with-current-buffer tobuf
6349 (insert-buffer-substring infobuf s e)
6350 (insert "\n"))))))))))
6352 (defun anything-c-info-goto (node-line)
6353 (Info-goto-node (car node-line))
6354 (anything-goto-line (cdr node-line)))
6356 (defun anything-c-info-display-to-real (line)
6357 (and (string-match
6358 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
6359 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
6360 (string-to-number (or (match-string 3 line) "1")))))
6362 (defun anything-c-make-info-source (file)
6363 `((name . ,(concat "Info Index: " file))
6364 (info-file . ,file)
6365 (init . anything-c-info-init)
6366 (display-to-real . anything-c-info-display-to-real)
6367 (get-line . buffer-substring)
6368 (candidates-in-buffer)
6369 (action ("Goto node" . anything-c-info-goto))))
6371 (defun anything-compile-source--info-index (source)
6372 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
6373 (anything-c-make-info-source it)
6374 source))
6375 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
6377 (anything-document-attribute 'info-index "info-index plugin"
6378 "Create a source of info index very easily.
6380 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
6382 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
6383 "Index nodes of info file.
6385 If it is omitted, `Info-index-nodes' is used to collect index nodes.
6386 Some info files are missing index specification.
6388 ex. See `anything-c-source-info-screen'.")
6390 ;; Plug-in: candidates-file
6391 (defun anything-compile-source--candidates-file (source)
6392 (if (assoc-default 'candidates-file source)
6393 `((init anything-p-candidats-file-init
6394 ,@(let ((orig-init (assoc-default 'init source)))
6395 (cond ((null orig-init) nil)
6396 ((functionp orig-init) (list orig-init))
6397 (t orig-init))))
6398 (candidates-in-buffer)
6399 ,@source)
6400 source))
6401 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
6403 (defun anything-p-candidats-file-init ()
6404 (destructuring-bind (file &optional updating)
6405 (anything-mklist (anything-attr 'candidates-file))
6406 (setq file (anything-interpret-value file))
6407 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
6408 (when updating
6409 (buffer-disable-undo)
6410 (font-lock-mode -1)
6411 (auto-revert-mode 1)))))
6413 (anything-document-attribute 'candidates-file "candidates-file plugin"
6414 "Use a file as the candidates buffer.
6416 1st argument is a filename, string or function name or variable name.
6417 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
6419 ;; Plug-in: headline
6420 (defun anything-compile-source--anything-headline (source)
6421 (if (assoc-default 'headline source)
6422 (append '((init . anything-headline-init)
6423 (get-line . buffer-substring)
6424 (type . line))
6425 source
6426 '((candidates-in-buffer)
6427 (persistent-help . "Show this line")))
6428 source))
6429 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
6431 (defun anything-headline-init ()
6432 (when (and (anything-current-buffer-is-modified)
6433 (with-current-buffer anything-current-buffer
6434 (eval (or (anything-attr 'condition) t))))
6435 (anything-headline-make-candidate-buffer
6436 (anything-interpret-value (anything-attr 'headline))
6437 (anything-interpret-value (anything-attr 'subexp)))))
6439 (anything-document-attribute 'headline "Headline plug-in"
6440 "Regexp string for anything-headline to scan.")
6441 (anything-document-attribute 'condition "Headline plug-in"
6442 "A sexp representing the condition to use anything-headline.")
6443 (anything-document-attribute 'subexp "Headline plug-in"
6444 "Display (match-string-no-properties subexp).")
6447 (defun anything-headline-get-candidates (regexp subexp)
6448 (with-current-buffer anything-current-buffer
6449 (save-excursion
6450 (goto-char (point-min))
6451 (if (functionp regexp) (setq regexp (funcall regexp)))
6452 (let (hierarchy curhead)
6453 (flet ((matched ()
6454 (if (numberp subexp)
6455 (cons (match-string-no-properties subexp) (match-beginning subexp))
6456 (cons (buffer-substring (point-at-bol) (point-at-eol))
6457 (point-at-bol))))
6458 (hierarchies (headlines)
6459 (1+ (loop for (_ . hierarchy) in headlines
6460 maximize hierarchy)))
6461 (vector-0-n (v n)
6462 (loop for i from 0 to hierarchy
6463 collecting (aref curhead i)))
6464 (arrange (headlines)
6465 (unless (null headlines) ; FIX headlines empty bug!
6466 (loop with curhead = (make-vector (hierarchies headlines) "")
6467 for ((str . pt) . hierarchy) in headlines
6468 do (aset curhead hierarchy str)
6469 collecting
6470 (cons
6471 (format "H%d:%s" (1+ hierarchy)
6472 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
6473 pt)))))
6474 (if (listp regexp)
6475 (arrange
6476 (sort
6477 (loop for re in regexp
6478 for hierarchy from 0
6479 do (goto-char (point-min))
6480 appending
6481 (loop
6482 while (re-search-forward re nil t)
6483 collect (cons (matched) hierarchy)))
6484 (lambda (a b) (> (cdar b) (cdar a)))))
6485 (loop while (re-search-forward regexp nil t)
6486 collect (matched))))))))
6489 (defun anything-headline-make-candidate-buffer (regexp subexp)
6490 (with-current-buffer (anything-candidate-buffer 'local)
6491 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
6492 do (insert
6493 (format "%5d:%s\n"
6494 (with-current-buffer anything-current-buffer
6495 (line-number-at-pos pos))
6496 content)))))
6498 (defun anything-headline-goto-position (pos recenter)
6499 (goto-char pos)
6500 (unless recenter
6501 (set-window-start (get-buffer-window anything-current-buffer) (point))))
6503 (defun anything-revert-buffer (candidate)
6504 (with-current-buffer candidate
6505 (when (buffer-modified-p)
6506 (revert-buffer t t))))
6508 (defun anything-revert-marked-buffers (candidate)
6509 (dolist (i (anything-marked-candidates))
6510 (anything-revert-buffer i)))
6512 (defun anything-kill-marked-buffers (candidate)
6513 (dolist (i (anything-marked-candidates))
6514 (kill-buffer i)))
6516 ;; Plug-in: persistent-help
6517 (defun anything-compile-source--persistent-help (source)
6518 (append source '((header-line . anything-persistent-help-string))))
6519 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
6521 (defun anything-persistent-help-string ()
6522 (substitute-command-keys
6523 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
6524 (or (anything-interpret-value (anything-attr 'persistent-help))
6525 (anything-aif (or (assoc-default 'persistent-action
6526 (anything-get-current-source))
6527 (assoc-default 'action
6528 (anything-get-current-source)))
6529 (cond ((symbolp it) (symbol-name it))
6530 ((listp it) (or (ignore-errors (caar it)) ""))))
6532 " (keeping session)")))
6534 (anything-document-attribute 'persistent-help "persistent-help plug-in"
6535 "A string to explain persistent-action of this source.
6536 It also accepts a function or a variable name.")
6538 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
6540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6542 (defun anything-c-find-file-or-marked (candidate)
6543 "Open file CANDIDATE or open anything marked files in background."
6544 (let ((marked (anything-marked-candidates)))
6545 (if (> (length marked) 1)
6546 (dolist (i marked) (find-file-noselect i))
6547 (find-file-at-point candidate))))
6549 ;; FIXME there is a bug in dired that confuse all dired commands
6550 ;; when using this feature, so i suspend it until bug is fixed in emacs.
6552 ;; (defun anything-c-create-dired-on-marked (candidate)
6553 ;; "Create a new dired buffer with only marked candidates."
6554 ;; (let ((marked (anything-marked-candidates))
6555 ;; (buffer-name (read-string "New Dired Buffer: ")))
6556 ;; (dired (cons buffer-name marked))))
6558 (defun anything-delete-marked-files (ignore)
6559 (let* ((files (anything-marked-candidates))
6560 (len (length files)))
6561 (if (not (y-or-n-p
6562 (format "Delete *%s File(s):\n%s"
6564 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
6565 (message "(No deletions performed)")
6566 (dolist (i files)
6567 (set-text-properties 0 (length i) nil i)
6568 (anything-c-delete-file i))
6569 (message "%s File(s) deleted" len))))
6571 (defun anything-ediff-marked-buffers (candidate &optional merge)
6572 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
6573 With optional arg `merge' call `ediff-merge-buffers'."
6574 (let ((lg-lst (length (anything-marked-candidates)))
6575 buf1 buf2)
6576 (case lg-lst
6578 (error "Error:You have to mark at least 1 buffer"))
6580 (setq buf1 anything-current-buffer
6581 buf2 (first (anything-marked-candidates))))
6583 (setq buf1 (first (anything-marked-candidates))
6584 buf2 (second (anything-marked-candidates))))
6586 (error "Error:To much buffers marked!")))
6587 (if merge
6588 (ediff-merge-buffers buf1 buf2)
6589 (ediff-buffers buf1 buf2))))
6591 (defun anything-bookmark-get-bookmark-from-name (bmk)
6592 "Return bookmark name even if it is a bookmark with annotation.
6593 e.g prepended with *.
6594 Return nil if bmk is not a valid bookmark."
6595 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
6596 (if (assoc bookmark bookmark-alist)
6597 bookmark
6598 (when (assoc bmk bookmark-alist)
6599 bmk))))
6601 (defun anything-delete-marked-bookmarks (elm)
6602 "Delete this bookmark or all marked bookmarks."
6603 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
6604 (anything-aif (anything-marked-candidates)
6605 (dolist (i it)
6606 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
6607 (bookmark-delete bmk 'batch)))
6608 (bookmark-delete bookmark 'batch))))
6610 (defun anything-require-or-error (feature function)
6611 (or (require feature nil t)
6612 (error "Need %s to use `%s'." feature function)))
6614 (defun anything-find-buffer-on-elscreen (candidate)
6615 "Open buffer in new screen, if marked buffers open all in elscreens."
6616 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
6617 (anything-aif (anything-marked-candidates)
6618 (dolist (i it)
6619 (let ((target-screen (elscreen-find-screen-by-buffer
6620 (get-buffer i) 'create)))
6621 (elscreen-goto target-screen)))
6622 (let ((target-screen (elscreen-find-screen-by-buffer
6623 (get-buffer candidate) 'create)))
6624 (elscreen-goto target-screen))))
6626 (defun anything-elscreen-find-file (file)
6627 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
6628 (elscreen-find-file file))
6630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6632 ;;;; Type Attributes
6633 (define-anything-type-attribute 'buffer
6634 `((action
6635 ,@(if pop-up-frames
6636 '(("Switch to buffer other window" . switch-to-buffer-other-window)
6637 ("Switch to buffer" . switch-to-buffer))
6638 '(("Switch to buffer" . switch-to-buffer)
6639 ("Switch to buffer other window" . switch-to-buffer-other-window)
6640 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
6641 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
6642 ("Display buffer" . display-buffer)
6643 ("Revert buffer" . anything-revert-buffer)
6644 ("Revert Marked buffers" . anything-revert-marked-buffers)
6645 ("Kill buffer" . kill-buffer)
6646 ("Kill Marked buffers" . anything-kill-marked-buffers)
6647 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
6648 ("Ediff Merge marked buffers" . (lambda (candidate)
6649 (anything-ediff-marked-buffers candidate t))))
6650 (persistent-help . "Show this buffer")
6651 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
6652 "Buffer or buffer name.")
6654 (define-anything-type-attribute 'file
6655 `((action
6656 ,@(if pop-up-frames
6657 '(("Find file other window" . find-file-other-window)
6658 ("Find file(s)" . anything-find-many-files)
6659 ("Find file as root" . anything-find-file-as-root))
6660 '(("Find file" . anything-find-many-files)
6661 ("Find file as root" . anything-find-file-as-root)
6662 ("Find file other window" . find-file-other-window)
6663 ("Find file other frame" . find-file-other-frame)))
6664 ("Open dired in file's directory" . anything-c-open-dired)
6665 ("Delete file(s)" . anything-delete-marked-files)
6666 ("Open file externally" . anything-c-open-file-externally)
6667 ("Open file with default tool" . anything-c-open-file-with-default-tool))
6668 (persistent-help . "Show this file")
6669 (action-transformer anything-c-transform-file-load-el
6670 anything-c-transform-file-browse-url)
6671 (candidate-transformer anything-c-w32-pathname-transformer
6672 anything-c-skip-current-file
6673 anything-c-skip-boring-files
6674 anything-c-shorten-home-path))
6675 "File name.")
6677 (define-anything-type-attribute 'command
6678 `((action ("Call interactively" . anything-c-call-interactively)
6679 ("Describe command" . anything-c-describe-function)
6680 ("Add command to kill ring" . anything-c-kill-new)
6681 ("Go to command's definition" . anything-c-find-function))
6682 ;; Sort commands according to their usage count.
6683 (filtered-candidate-transformer . anything-c-adaptive-sort)
6684 (persistent-action . anything-c-describe-function))
6685 "Command. (string or symbol)")
6687 (define-anything-type-attribute 'function
6688 '((action ("Describe function" . anything-c-describe-function)
6689 ("Add function to kill ring" . anything-c-kill-new)
6690 ("Go to function's definition" . anything-c-find-function))
6691 (action-transformer anything-c-transform-function-call-interactively)
6692 (candidate-transformer anything-c-mark-interactive-functions))
6693 "Function. (string or symbol)")
6695 (define-anything-type-attribute 'variable
6696 '((action ("Describe variable" . anything-c-describe-variable)
6697 ("Add variable to kill ring" . anything-c-kill-new)
6698 ("Go to variable's definition" . anything-c-find-variable)
6699 ("Set variable" . anything-c-set-variable)))
6700 "Variable.")
6702 (define-anything-type-attribute 'sexp
6703 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
6704 ("Add s-expression to kill ring" . kill-new))
6705 (action-transformer anything-c-transform-sexp-eval-command-sexp))
6706 "String representing S-Expressions.")
6708 (define-anything-type-attribute 'bookmark
6709 `((action
6710 ("Jump to bookmark" . (lambda (candidate)
6711 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate))
6712 (current-prefix-arg anything-current-prefix-arg))
6713 (bookmark-jump bookmark))
6714 (anything-update)))
6715 ("Jump to BM other window" . (lambda (candidate)
6716 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6717 (bookmark-jump-other-window bookmark))
6718 (anything-update)))
6719 ("Bookmark edit annotation" . (lambda (candidate)
6720 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6721 (bookmark-edit-annotation bookmark))))
6722 ("Bookmark show annotation" . (lambda (candidate)
6723 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6724 (bookmark-show-annotation bookmark))))
6725 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
6726 ,@(when (fboundp 'bmkext-edit-bookmark)
6727 '(("Edit Bookmark" . (lambda (candidate)
6728 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6729 (bmkext-edit-bookmark bookmark))))))
6730 ("Rename bookmark" . (lambda (candidate)
6731 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6732 (bookmark-rename bookmark))))
6733 ("Relocate bookmark" . (lambda (candidate)
6734 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6735 (bookmark-relocate bookmark))))))
6736 "Bookmark name.")
6738 (define-anything-type-attribute 'line
6739 '((display-to-real . anything-c-display-to-real-line)
6740 (action ("Go to Line" . anything-c-action-line-goto)))
6741 "LINENO:CONTENT string, eg. \" 16:foo\".
6743 Optional `target-file' attribute is a name of target file.
6745 Optional `before-jump-hook' attribute is a function with no
6746 arguments which is called before jumping to position.
6748 Optional `after-jump-hook' attribute is a function with no
6749 arguments which is called after jumping to position.
6751 If `adjust' attribute is specified, searches the line whose
6752 content is CONTENT near the LINENO.
6754 If `recenter' attribute is specified, the line is displayed at
6755 the center of window, otherwise at the top of window.
6758 (define-anything-type-attribute 'file-line
6759 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
6760 (multiline)
6761 (action ("Go to" . anything-c-action-file-line-goto)))
6762 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
6764 Optional `default-directory' attribute is a default-directory
6765 FILENAME is interpreted.
6767 Optional `before-jump-hook' attribute is a function with no
6768 arguments which is called before jumping to position.
6770 Optional `after-jump-hook' attribute is a function with no
6771 arguments which is called after jumping to position.
6773 If `adjust' attribute is specified, searches the line whose
6774 content is CONTENT near the LINENO.
6776 If `recenter' attribute is specified, the line is displayed at
6777 the center of window, otherwise at the top of window.
6780 (define-anything-type-attribute 'timer
6781 '((real-to-display . anything-c-timer-real-to-display)
6782 (action ("Cancel Timer" . cancel-timer)
6783 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
6784 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
6785 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
6786 (persistent-help . "Describe Function"))
6787 "Timer.")
6789 ;;;; Default `anything-sources'
6790 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
6791 ;; tend to invoke M-x anything directly. So I offer default setting.
6792 (setq anything-sources
6793 '(anything-c-source-buffers+
6794 anything-c-source-recentf
6795 anything-c-source-files-in-current-dir+))
6797 ;;;; unit test
6798 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
6799 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6800 (dont-compile
6801 (when (fboundp 'expectations)
6802 (expectations
6803 (desc "candidates-file plug-in")
6804 (expect '(anything-p-candidats-file-init)
6805 (assoc-default 'init
6806 (car (anything-compile-sources
6807 '(((name . "test")
6808 (candidates-file . "test.txt")))
6809 '(anything-compile-source--candidates-file)))))
6810 (expect '(anything-p-candidats-file-init
6811 (lambda () 1))
6812 (assoc-default 'init
6813 (car (anything-compile-sources
6814 '(((name . "test")
6815 (candidates-file . "test.txt")
6816 (init . (lambda () 1))))
6817 '(anything-compile-source--candidates-file)))))
6818 (expect '(anything-p-candidats-file-init
6819 (lambda () 1))
6820 (assoc-default 'init
6821 (car (anything-compile-sources
6822 '(((name . "test")
6823 (candidates-file . "test.txt")
6824 (init (lambda () 1))))
6825 '(anything-compile-source--candidates-file)))))
6826 (desc "anything-c-source-buffers")
6827 (expect '(("Buffers" ("foo" "curbuf")))
6828 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
6829 (let ((anything-c-boring-buffer-regexp
6830 (rx (or
6831 (group bos " ")
6832 "*anything"
6833 ;; echo area
6834 " *Echo Area" " *Minibuf"))))
6835 (flet ((buffer-name (x) x))
6836 (anything-test-candidates 'anything-c-source-buffers))))
6837 (desc "anything-c-stringify")
6838 (expect "str1"
6839 (anything-c-stringify "str1"))
6840 (expect "str2"
6841 (anything-c-stringify 'str2))
6842 (desc "anything-c-symbolify")
6843 (expect 'sym1
6844 (anything-c-symbolify "sym1"))
6845 (expect 'sym2
6846 (anything-c-symbolify 'sym2)))))
6848 (provide 'anything-config)
6850 ;;; Local Variables:
6851 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
6852 ;;; End:
6854 ;; How to save (DO NOT REMOVE!!)
6855 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
6856 ;;; anything-config.el ends here
6858 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
6859 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
6860 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
6861 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
6862 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
6863 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
6864 ;;; LocalWords: dotimes Thierry online vname
6865 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
6866 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
6867 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
6868 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
6869 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
6870 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
6871 ;;; LocalWords: startpos noselect dont desc