anything-config.el (anything-c-source-symlink-files): reformat
[anything-config.git] / anything-config.el
blobcc9c869cac9baf424ac348d161b784f04f6c3ec9
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" . (lambda (candidate)
1970 (anything-dired-action candidate :action 'hardlink)))))))
1972 (defun* anything-dired-action (candidate &key action follow)
1973 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
1974 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
1975 (let ((files (dired-get-marked-files))
1976 (fn (case action
1977 ('copy 'dired-copy-file)
1978 ('rename 'dired-rename-file)
1979 ('symlink 'make-symbolic-link)
1980 ('relsymlink 'dired-make-relative-symlink)
1981 ('hardlink 'dired-hardlink)))
1982 (marker (case action
1983 ((copy rename) dired-keep-marker-copy)
1984 ('symlink dired-keep-marker-symlink)
1985 ('relsymlink dired-keep-marker-relsymlink)
1986 ('hardlink dired-keep-marker-hardlink))))
1987 (dired-create-files
1988 fn (symbol-name action) files
1989 (if (file-directory-p candidate)
1990 ;; When CANDIDATE is a directory, build file-name in this directory.
1991 ;; Else we use CANDIDATE.
1992 #'(lambda (from)
1993 (expand-file-name (file-name-nondirectory from) candidate))
1994 #'(lambda (from) candidate))
1995 marker)
1996 (when follow
1997 (let* ((src (car files))
1998 (dest (expand-file-name candidate))
1999 (basename-src (if (file-directory-p src)
2000 (file-relative-name
2001 (directory-file-name src)
2002 (file-name-directory src))
2003 (file-name-nondirectory src)))
2004 (fname (if (file-directory-p dest)
2005 (concat (file-name-as-directory dest)
2006 basename-src)
2007 dest)))
2008 (anything-c-point-file-in-dired fname)))))
2011 (defun* anything-dired-do-action-on-file (&key action)
2012 (let* ((files (dired-get-marked-files))
2013 (len (length files))
2014 (fname (if (> len 1)
2015 (format "* %d Files" len)
2016 (car files)))
2017 (source (case action
2018 ('copy 'anything-c-source-copy-files)
2019 ('rename 'anything-c-source-rename-files)
2020 ('symlink 'anything-c-source-symlink-files)
2021 ('hardlink 'anything-c-source-hardlink-files)))
2022 (prompt-fm (case action
2023 ('copy "Copy %s to: ")
2024 ('rename "Rename %s to: ")
2025 ('symlink "Symlink %s to: ")
2026 ('hardlink "Hardlink %s to: ")))
2027 (buffer (case action
2028 ('copy "*Anything Copy Files*")
2029 ('rename "*Anything Rename Files*")
2030 ('symlink "*Anything Symlink Files*")
2031 ('hardlink "*Anything Hardlink Files*"))))
2032 (anything source
2033 (or (dired-dwim-target-directory)
2034 (expand-file-name (anything-c-current-directory)))
2035 (format prompt-fm fname) nil nil buffer)))
2038 ;;;###autoload
2039 (defun anything-dired-rename-file ()
2040 "Preconfigured `anything' to rename files from dired."
2041 (interactive)
2042 (anything-dired-do-action-on-file :action 'rename))
2044 ;;;###autoload
2045 (defun anything-dired-copy-file ()
2046 "Preconfigured `anything' to copy files from dired."
2047 (interactive)
2048 (anything-dired-do-action-on-file :action 'copy))
2050 ;;;###autoload
2051 (defun anything-dired-symlink-file ()
2052 "Preconfigured `anything' to symlink files from dired."
2053 (interactive)
2054 (anything-dired-do-action-on-file :action 'symlink))
2056 ;;;###autoload
2057 (defun anything-dired-hardlink-file ()
2058 "Preconfigured `anything' to hardlink files from dired."
2059 (interactive)
2060 (anything-dired-do-action-on-file :action 'hardlink))
2062 (defvar anything-dired-bindings nil)
2063 ;;;###autoload
2064 (defun anything-dired-bindings (&optional arg)
2065 "Replace usual dired commands `C' and `R' by anything ones.
2066 When call interactively toggle dired bindings and anything bindings.
2067 When call non--interactively with arg > 0, enable anything bindings.
2068 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2069 (interactive)
2070 (if (or (when arg (> arg 0)) (not anything-dired-bindings))
2071 (progn
2072 (define-key dired-mode-map (kbd "C") 'anything-dired-copy-file)
2073 (define-key dired-mode-map (kbd "R") 'anything-dired-rename-file)
2074 (define-key dired-mode-map (kbd "S") 'anything-dired-symlink-file)
2075 (define-key dired-mode-map (kbd "H") 'anything-dired-hardlink-file)
2076 (setq anything-dired-bindings t))
2077 (define-key dired-mode-map (kbd "C") 'dired-do-copy)
2078 (define-key dired-mode-map (kbd "R") 'dired-do-rename)
2079 (define-key dired-mode-map (kbd "S") 'dired-do-symlink)
2080 (define-key dired-mode-map (kbd "H") 'dired-do-hardlink)
2081 (setq anything-dired-bindings nil)))
2083 (defun* anything-c-read-file-name (prompt &key
2084 (initial-input (expand-file-name default-directory))
2085 (buffer "*Anything Completions*")
2086 test)
2087 "Anything `read-file-name' emulation.
2088 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2089 (when (get-buffer anything-action-buffer)
2090 (kill-buffer anything-action-buffer))
2091 (or (anything
2092 `((name . ,(concat "Read file name" anything-c-find-files-doc-header))
2093 ;; It is needed for filenames with capital letters
2094 (disable-shortcuts)
2095 (candidates . (lambda ()
2096 (if test
2097 (loop with seq = (anything-find-files-get-candidates)
2098 for fname in seq when (funcall test fname)
2099 collect fname)
2100 (anything-find-files-get-candidates))))
2101 (candidate-transformer anything-c-highlight-ffiles)
2102 (persistent-action . anything-find-files-persistent-action)
2103 (persistent-help . "Expand Candidate")
2104 (volatile)
2105 (action . (("candidate" . ,'identity))))
2106 initial-input prompt 'noresume nil buffer)
2107 (keyboard-quit)))
2109 ;;; File Cache
2110 (defvar anything-c-source-file-cache-initialized nil)
2112 (defvar anything-c-file-cache-files nil)
2114 (defvar anything-c-source-file-cache
2115 '((name . "File Cache")
2116 (init . (lambda ()
2117 (require 'filecache nil t)
2118 (unless anything-c-source-file-cache-initialized
2119 (setq anything-c-file-cache-files
2120 (loop for item in file-cache-alist append
2121 (destructuring-bind (base &rest dirs) item
2122 (loop for dir in dirs collect
2123 (concat dir base)))))
2124 (defadvice file-cache-add-file (after file-cache-list activate)
2125 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
2126 (setq anything-c-source-file-cache-initialized t))))
2127 (candidates . anything-c-file-cache-files)
2128 (match anything-c-match-on-file-name
2129 anything-c-match-on-directory-name)
2130 (type . file)))
2131 ;; (anything 'anything-c-source-file-cache)
2133 ;;; Locate
2134 ;; NOTE for WINDOZE users:
2135 ;; You have to install Everything with his command line interface here:
2136 ;; http://www.voidtools.com/download.php
2138 (defvar anything-c-locate-command
2139 (case system-type
2140 ('gnu/linux "locate -i -r %s")
2141 ('berkeley-unix "locate -i %s")
2142 ('windows-nt "es -i -r %s")
2143 (t "locate %s"))
2144 "A list of arguments for locate program.
2145 The \"-r\" option must be the last option.")
2147 (defun anything-c-locate-init ()
2148 "Initialize async locate process for `anything-c-source-locate'."
2149 (start-process-shell-command "locate-process" nil
2150 (format anything-c-locate-command
2151 anything-pattern)))
2153 (defvar anything-c-source-locate
2154 '((name . "Locate")
2155 (candidates . anything-c-locate-init)
2156 (type . file)
2157 (requires-pattern . 3)
2158 (delayed))
2159 "Find files matching the current input pattern with locate.")
2161 ;; (anything 'anything-c-source-locate)
2163 ;;; Recentf files
2164 (defvar anything-c-source-recentf
2165 '((name . "Recentf")
2166 (init . (lambda ()
2167 (require 'recentf)
2168 (or recentf-mode (recentf-mode 1))
2169 ;; Big value empowers anything/recentf
2170 (when (and (numberp recentf-max-saved-items)
2171 (<= recentf-max-saved-items 20))
2172 (setq recentf-max-saved-items 500))))
2173 (candidates . recentf-list)
2174 (match anything-c-match-on-file-name
2175 anything-c-match-on-directory-name)
2176 (type . file))
2177 "See (info \"(emacs)File Conveniences\").
2178 if `recentf-max-saved-items' is too small, set it to 500.")
2179 ;; (anything 'anything-c-source-recentf)
2181 ;;; ffap
2182 (eval-when-compile (require 'ffap))
2183 (defvar anything-c-source-ffap-guesser
2184 '((name . "File at point")
2185 (init . (lambda () (require 'ffap)))
2186 (candidates . (lambda ()
2187 (anything-aif
2188 (with-current-buffer anything-current-buffer
2189 (ffap-guesser))
2190 (list it))))
2191 (type . file)))
2192 ;; (anything 'anything-c-source-ffap-guesser)
2194 ;;; ffap with line number
2195 (defun anything-c-ffap-file-line-at-point ()
2196 "Get (FILENAME . LINENO) at point."
2197 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2198 (save-excursion
2199 (beginning-of-line)
2200 (when (and (search-forward it nil t)
2201 (looking-at ":\\([0-9]+\\)"))
2202 (cons it (string-to-number (match-string 1)))))))
2204 (defvar anything-c-ffap-line-location nil
2205 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2206 It is cleared after jumping line.")
2208 (defun anything-c-ffap-line-candidates ()
2209 (with-current-buffer anything-current-buffer
2210 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
2211 (when anything-c-ffap-line-location
2212 (destructuring-bind (file . line) anything-c-ffap-line-location
2213 (list (cons (format "%s (line %d)" file line) file)))))
2215 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2216 (defun anything-c-ffap-line-goto-line ()
2217 (when (car anything-c-ffap-line-location)
2218 (unwind-protect
2219 (ignore-errors
2220 (with-selected-window (get-buffer-window
2221 (get-file-buffer (car anything-c-ffap-line-location)))
2222 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
2223 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
2224 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
2226 (defvar anything-c-source-ffap-line
2227 '((name . "File/Lineno at point")
2228 (init . (lambda () (require 'ffap)))
2229 (candidates . anything-c-ffap-line-candidates)
2230 (type . file)))
2231 ;; (anything 'anything-c-source-ffap-line)
2233 ;;; list of files gleaned from every dired buffer
2234 (defun anything-c-files-in-all-dired-candidates ()
2235 (save-excursion
2236 (mapcan
2237 (lambda (dir)
2238 (cond ((listp dir) ;filelist
2239 dir)
2240 ((equal "" (file-name-nondirectory dir)) ;dir
2241 (directory-files dir t))
2242 (t ;wildcard
2243 (file-expand-wildcards dir t))))
2244 (delq nil
2245 (mapcar (lambda (buf)
2246 (set-buffer buf)
2247 (when (eq major-mode 'dired-mode)
2248 (if (consp dired-directory)
2249 (cdr dired-directory) ;filelist
2250 dired-directory))) ;dir or wildcard
2251 (buffer-list))))))
2252 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2254 (defvar anything-c-source-files-in-all-dired
2255 '((name . "Files in all dired buffer.")
2256 (candidates . anything-c-files-in-all-dired-candidates)
2257 (type . file)))
2258 ;; (anything 'anything-c-source-files-in-all-dired)
2260 ;;;; <info>
2261 ;;; Info pages
2262 (defvar anything-c-info-pages nil
2263 "All info pages on system.
2264 Will be calculated the first time you invoke anything with this
2265 source.")
2267 (defvar anything-c-source-info-pages
2268 `((name . "Info Pages")
2269 (candidates . (lambda ()
2270 (if anything-c-info-pages
2271 anything-c-info-pages
2272 (setq anything-c-info-pages
2273 (save-window-excursion
2274 (save-excursion
2275 (require 'info)
2276 (Info-find-node "dir" "top")
2277 (goto-char (point-min))
2278 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2279 topics)
2280 (while (re-search-forward info-topic-regexp nil t)
2281 (add-to-list 'topics (match-string-no-properties 1)))
2282 (goto-char (point-min))
2283 (Info-exit)
2284 topics)))))))
2285 (action . (("Show with Info" .(lambda (node-str)
2286 (info (replace-regexp-in-string "^[^:]+: "
2288 node-str))))))
2289 (requires-pattern . 2)))
2290 ;; (anything 'anything-c-source-info-pages)
2293 ;;; Use info-index plug-in. Note that `name' attribute is
2294 ;;; not needed but `anything-c-insert-summary' uses it.
2295 ;; Info Elisp
2296 (defvar anything-c-source-info-elisp
2297 '((name . "Info index: elisp")
2298 (info-index . "elisp")))
2299 ;; (anything 'anything-c-source-info-elisp)
2301 ;; Info-Common-Lisp
2302 (defvar anything-c-source-info-cl
2303 '((name . "Info index: cl")
2304 (info-index . "cl")))
2305 ;; (anything 'anything-c-source-info-cl)
2307 ;; Info Index org
2308 (defvar anything-c-source-info-org
2309 '((name . "Info index: org")
2310 (info-index . "org")))
2311 ;; (anything 'anything-c-source-info-org)
2313 ;; Info Index ratpoison
2314 (defvar anything-c-source-info-ratpoison
2315 '((name . "Info index: ratpoison")
2316 (info-index . "ratpoison")))
2317 ;; (anything 'anything-c-source-info-ratpoison)
2319 ;; Info Index zsh
2320 (defvar anything-c-source-info-zsh
2321 '((name . "Info index: zsh")
2322 (info-index . "zsh")))
2323 ;; (anything 'anything-c-source-info-zsh)
2325 ;; Info Index bash
2326 (defvar anything-c-source-info-bash
2327 '((name . "Info index: bash")
2328 (info-index . "bash")))
2329 ;; (anything 'anything-c-source-info-bash)
2331 ;; Info Index coreutils
2332 (defvar anything-c-source-info-coreutils
2333 '((name . "Info index: coreutils")
2334 (info-index . "coreutils")))
2335 ;; (anything 'anything-c-source-info-coreutils)
2337 ;; Info Index fileutils
2338 (defvar anything-c-source-info-fileutils
2339 '((name . "Info index: fileutils")
2340 (info-index . "fileutils")))
2341 ;; (anything 'anything-c-source-info-fileutils)
2343 ;; Info Index find
2344 (defvar anything-c-source-info-find
2345 '((name . "Info index: find")
2346 (info-index . "find")))
2347 ;; (anything 'anything-c-source-info-find)
2349 ;; Info Index sh-utils
2350 (defvar anything-c-source-info-sh-utils
2351 '((name . "Info index: sh-utils")
2352 (info-index . "sh-utils")))
2353 ;; (anything 'anything-c-source-info-sh-utils)
2355 ;; Info Index textutils
2356 (defvar anything-c-source-info-textutils
2357 '((name . "Info index: textutils")
2358 (info-index . "textutils")))
2359 ;; (anything 'anything-c-source-info-textutils)
2361 ;; Info Index libc
2362 (defvar anything-c-source-info-libc
2363 '((name . "Info index: libc")
2364 (info-index . "libc")))
2365 ;; (anything 'anything-c-source-info-libc)
2367 ;; Info Index make
2368 (defvar anything-c-source-info-make
2369 '((name . "Info index: make")
2370 (info-index . "make")))
2371 ;; (anything 'anything-c-source-info-make)
2373 ;; Info Index automake
2374 (defvar anything-c-source-info-automake
2375 '((name . "Info index: automake")
2376 (info-index . "automake")))
2377 ;; (anything 'anything-c-source-info-automake)
2379 ;; Info Index autoconf
2380 (defvar anything-c-source-info-autoconf
2381 '((name . "Info index: autoconf")
2382 (info-index . "autoconf")))
2383 ;; (anything 'anything-c-source-info-autoconf)
2385 ;; Info Index emacs-lisp-intro
2386 (defvar anything-c-source-info-emacs-lisp-intro
2387 '((name . "Info index: emacs-lisp-intro")
2388 (info-index . "emacs-lisp-intro")))
2389 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2391 ;; Info Index emacs
2392 (defvar anything-c-source-info-emacs
2393 '((name . "Info index: emacs")
2394 (info-index . "emacs")))
2395 ;; (anything 'anything-c-source-info-emacs)
2397 ;; Info Index elib
2398 (defvar anything-c-source-info-elib
2399 '((name . "Info index: elib")
2400 (info-index . "elib")))
2401 ;; (anything 'anything-c-source-info-elib)
2403 ;; Info Index eieio
2404 (defvar anything-c-source-info-eieio
2405 '((name . "Info index: eieio")
2406 (info-index . "eieio")))
2407 ;; (anything 'anything-c-source-info-eieio)
2409 ;; Info Index gauche-refe
2410 (defvar anything-c-source-info-gauche-refe
2411 '((name . "Info index: gauche")
2412 (info-index . "gauche-refe")))
2413 ;; (anything 'anything-c-source-info-gauche-refe)
2415 ;; Info Index guile
2416 (defvar anything-c-source-info-guile
2417 '((name . "Info index: guile")
2418 (info-index . "guile")))
2419 ;; (anything 'anything-c-source-info-guile)
2421 ;; Info Index guile-tut
2422 (defvar anything-c-source-info-guile-tut
2423 '((name . "Info index: guile-tut")
2424 (info-index . "guile-tut")))
2425 ;; (anything 'anything-c-source-info-guile-tut)
2427 ;; Info Index goops
2428 (defvar anything-c-source-info-goops
2429 '((name . "Info index: goops")
2430 (info-index . "goops")))
2431 ;; (anything 'anything-c-source-info-goops)
2433 ;; Info Index screen
2434 (defvar anything-c-source-info-screen
2435 '((name . "Info index: screen")
2436 (info-index . "screen")
2437 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2438 ;; (anything 'anything-c-source-info-screen)
2440 ;; Info Index latex
2441 (defvar anything-c-source-info-latex
2442 '((name . "Info index: latex")
2443 (info-index . "latex")))
2444 ;; (anything 'anything-c-source-info-latex)
2446 ;; Info Index gawk
2447 (defvar anything-c-source-info-gawk
2448 '((name . "Info index: gawk")
2449 (info-index . "gawk")))
2450 ;; (anything 'anything-c-source-info-gawk)
2452 ;; Info Index sed
2453 (defvar anything-c-source-info-sed
2454 '((name . "Info index: sed")
2455 (info-index . "sed")))
2456 ;; (anything 'anything-c-source-info-sed)
2458 ;; Info Index m4
2459 (defvar anything-c-source-info-m4
2460 '((name . "Info index: m4")
2461 (info-index . "m4")))
2462 ;; (anything 'anything-c-source-info-m4)
2464 ;; Info Index wget
2465 (defvar anything-c-source-info-wget
2466 '((name . "Info index: wget")
2467 (info-index . "wget")))
2468 ;; (anything 'anything-c-source-info-wget)
2470 ;; Info Index binutils
2471 (defvar anything-c-source-info-binutils
2472 '((name . "Info index: binutils")
2473 (info-index . "binutils")))
2474 ;; (anything 'anything-c-source-info-binutils)
2476 ;; Info Index as
2477 (defvar anything-c-source-info-as
2478 '((name . "Info index: as")
2479 (info-index . "as")))
2480 ;; (anything 'anything-c-source-info-as)
2482 ;; Info Index bfd
2483 (defvar anything-c-source-info-bfd
2484 '((name . "Info index: bfd")
2485 (info-index . "bfd")))
2486 ;; (anything 'anything-c-source-info-bfd)
2488 ;; Info Index gprof
2489 (defvar anything-c-source-info-gprof
2490 '((name . "Info index: gprof")
2491 (info-index . "gprof")))
2492 ;; (anything 'anything-c-source-info-gprof)
2494 ;; Info Index ld
2495 (defvar anything-c-source-info-ld
2496 '((name . "Info index: ld")
2497 (info-index . "ld")))
2498 ;; (anything 'anything-c-source-info-ld)
2500 ;; Info Index diff
2501 (defvar anything-c-source-info-diff
2502 '((name . "Info index: diff")
2503 (info-index . "diff")))
2504 ;; (anything 'anything-c-source-info-diff)
2506 ;; Info Index flex
2507 (defvar anything-c-source-info-flex
2508 '((name . "Info index: flex")
2509 (info-index . "flex")))
2510 ;; (anything 'anything-c-source-info-flex)
2512 ;; Info Index grep
2513 (defvar anything-c-source-info-grep
2514 '((name . "Info index: grep")
2515 (info-index . "grep")))
2516 ;; (anything 'anything-c-source-info-grep)
2518 ;; Info Index gzip
2519 (defvar anything-c-source-info-gzip
2520 '((name . "Info index: gzip")
2521 (info-index . "gzip")))
2522 ;; (anything 'anything-c-source-info-gzip)
2524 ;; Info Index libtool
2525 (defvar anything-c-source-info-libtool
2526 '((name . "Info index: libtool")
2527 (info-index . "libtool")))
2528 ;; (anything 'anything-c-source-info-libtool)
2530 ;; Info Index texinfo
2531 (defvar anything-c-source-info-texinfo
2532 '((name . "Info index: texinfo")
2533 (info-index . "texinfo")))
2534 ;; (anything 'anything-c-source-info-texinfo)
2536 ;; Info Index info
2537 (defvar anything-c-source-info-info
2538 '((name . "Info index: info")
2539 (info-index . "info")))
2540 ;; (anything 'anything-c-source-info-info)
2542 ;; Info Index gdb
2543 (defvar anything-c-source-info-gdb
2544 '((name . "Info index: gdb")
2545 (info-index . "gdb")))
2546 ;; (anything 'anything-c-source-info-gdb)
2548 ;; Info Index stabs
2549 (defvar anything-c-source-info-stabs
2550 '((name . "Info index: stabs")
2551 (info-index . "stabs")))
2552 ;; (anything 'anything-c-source-info-stabs)
2554 ;; Info Index cvsbook
2555 (defvar anything-c-source-info-cvsbook
2556 '((name . "Info index: cvsbook")
2557 (info-index . "cvsbook")))
2558 ;; (anything 'anything-c-source-info-cvsbook)
2560 ;; Info Index cvs
2561 (defvar anything-c-source-info-cvs
2562 '((name . "Info index: cvs")
2563 (info-index . "cvs")))
2564 ;; (anything 'anything-c-source-info-cvs)
2566 ;; Info Index bison
2567 (defvar anything-c-source-info-bison
2568 '((name . "Info index: bison")
2569 (info-index . "bison")))
2570 ;; (anything 'anything-c-source-info-bison)
2572 ;; Info Index id-utils
2573 (defvar anything-c-source-info-id-utils
2574 '((name . "Info index: id-utils")
2575 (info-index . "id-utils")))
2576 ;; (anything 'anything-c-source-info-id-utils)
2578 ;; Info Index global
2579 (defvar anything-c-source-info-global
2580 '((name . "Info index: global")
2581 (info-index . "global")))
2582 ;; (anything 'anything-c-source-info-global)
2584 ;;;; <Help>
2585 ;;; Man Pages
2586 (defvar anything-c-man-pages nil
2587 "All man pages on system.
2588 Will be calculated the first time you invoke anything with this
2589 source.")
2591 (defvar anything-c-source-man-pages
2592 `((name . "Manual Pages")
2593 (candidates . (lambda ()
2594 (if anything-c-man-pages
2595 anything-c-man-pages
2596 ;; XEmacs doesn't have a woman :)
2597 (setq anything-c-man-pages
2598 (ignore-errors
2599 (require 'woman)
2600 (woman-file-name "")
2601 (sort (mapcar 'car woman-topic-all-completions)
2602 'string-lessp))))))
2603 (action ("Show with Woman" . (lambda (candidate)
2604 (let ((wfiles (woman-file-name-all-completions candidate)))
2605 (if (> (length wfiles) 1)
2606 (woman-find-file (anything-comp-read "ManFile: " wfiles
2607 :must-match t))
2608 (woman candidate))))))
2609 ;; Woman does not work OS X
2610 ;; http://xahlee.org/emacs/modernization_man_page.html
2611 (action-transformer . (lambda (actions candidate)
2612 (if (eq system-type 'darwin)
2613 '(("Show with Man" . man))
2614 actions)))
2615 (requires-pattern . 2)))
2616 ;; (anything 'anything-c-source-man-pages)
2618 ;;;; <Command>
2619 ;;; Complex command history
2620 (defvar anything-c-source-complex-command-history
2621 '((name . "Complex Command History")
2622 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
2623 (type . sexp)))
2624 ;; (anything 'anything-c-source-complex-command-history)
2626 ;;; M-x history
2627 (defvar anything-c-source-extended-command-history
2628 '((name . "Emacs Commands History")
2629 (candidates . extended-command-history)
2630 (type . command)))
2631 ;; (anything 'anything-c-source-extended-command-history)
2633 ;;; Emacs commands
2634 (defvar anything-c-source-emacs-commands
2635 '((name . "Emacs Commands")
2636 (candidates . (lambda ()
2637 (let (commands)
2638 (mapatoms (lambda (a)
2639 (if (commandp a)
2640 (push (symbol-name a)
2641 commands))))
2642 (sort commands 'string-lessp))))
2643 (type . command)
2644 (requires-pattern . 2))
2645 "Source for completing and invoking Emacs commands.
2646 A command is a function with interactive spec that can
2647 be invoked with `M-x'.
2649 To get non-interactive functions listed, use
2650 `anything-c-source-emacs-functions'.")
2651 ;; (anything 'anything-c-source-emacs-commands)
2653 ;; Another replacement of `M-x' that act exactly like the
2654 ;; vanilla Emacs one, no problem of windows configuration, prefix args
2655 ;; are passed before calling `M-x' (e.g C-u M-x..).
2656 ;;;###autoload
2657 (defun anything-M-x ()
2658 "Preconfigured `anything' for Emacs commands.
2659 It is `anything' replacement of regular `M-x' `execute-extended-command'."
2660 (interactive)
2661 (let ((command (anything-comp-read "M-x " obarray
2662 :test 'commandp
2663 :must-match t
2664 :requires-pattern 2)))
2665 (call-interactively (intern command))))
2667 ;;; LaCarte
2668 (defvar anything-c-source-lacarte
2669 '((name . "Lacarte")
2670 (init . (lambda () (require 'lacarte )))
2671 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2672 (candidate-number-limit . 9999)
2673 (action . anything-c-call-interactively))
2674 "Needs lacarte.el.
2676 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2677 ;; (anything 'anything-c-source-lacarte)
2679 ;;;; <Function>
2680 ;;; Emacs functions
2681 (defvar anything-c-source-emacs-functions
2682 '((name . "Emacs Functions")
2683 (candidates . (lambda ()
2684 (let (commands)
2685 (mapatoms (lambda (a) (if (functionp a)
2686 (push (symbol-name a) commands))))
2687 (sort commands 'string-lessp))))
2688 (type . function)
2689 (requires-pattern . 2))
2690 "Source for completing Emacs functions.")
2691 ;; (anything 'anything-c-source-emacs-functions)
2693 ;;; With abbrev expansion
2694 ;;; Similar to my exec-abbrev-cmd.el
2695 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2696 (defvar anything-c-function-abbrev-regexp nil
2697 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2698 Regexp built from the current `anything-pattern' interpreting it
2699 as abbreviation.
2700 Only for internal use.")
2702 (defun anything-c-match-function-by-abbrev (candidate)
2703 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2705 Abbreviations are made by taking the first character from each
2706 word in the function's name, e.g. \"bb\" is an abbrev for
2707 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2708 (string-match anything-c-function-abbrev-regexp candidate))
2710 (defvar anything-c-source-emacs-functions-with-abbrevs
2711 (append anything-c-source-emacs-functions
2712 '((match anything-c-match-function-by-abbrev
2713 anything-c-string-match))
2714 '((init . (lambda ()
2715 (defadvice anything-update
2716 (before anything-c-update-function-abbrev-regexp activate)
2717 (let ((char-list (append anything-pattern nil))
2718 (str "^"))
2719 (dolist (c char-list)
2720 (setq str (concat str (list c) "[^-]*-")))
2721 (setq str (concat (substring str 0 (1- (length str))) "$"))
2722 (setq anything-c-function-abbrev-regexp str))))))))
2723 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2725 (defvar anything-c-source-advice
2726 '((name . "Function Advice")
2727 (candidates . anything-c-advice-candidates)
2728 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
2729 ;; (real-to-display . anything-c-advice-real-to-display)
2732 (persistent-action . anything-c-advice-persistent-action)
2733 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
2734 ;; (anything 'anything-c-source-advice)
2735 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
2736 ;; (testadvice)
2738 (defun anything-c-advice-candidates ()
2739 (require 'advice)
2740 (loop for (fname) in ad-advised-functions
2741 for function = (intern fname)
2742 append
2743 (loop for class in ad-advice-classes append
2744 (loop for advice in (ad-get-advice-info-field function class)
2745 for enabled = (ad-advice-enabled advice)
2746 collect
2747 (cons (format "%s %s %s"
2748 (if enabled "Enabled " "Disabled")
2749 (propertize fname 'face 'font-lock-function-name-face)
2750 (ad-make-single-advice-docstring advice class nil))
2751 (list function class advice))))))
2753 (defun anything-c-advice-persistent-action (func-class-advice)
2754 (if current-prefix-arg
2755 (anything-c-advice-toggle func-class-advice)
2756 (describe-function (car func-class-advice))))
2758 (defun anything-c-advice-toggle (func-class-advice)
2759 (destructuring-bind (function class advice) func-class-advice
2760 (cond ((ad-advice-enabled advice)
2761 (ad-advice-set-enabled advice nil)
2762 (message "Disabled"))
2763 (t ;disabled
2764 (ad-advice-set-enabled advice t)
2765 (message "Enabled")))
2766 (ad-activate function)
2767 (and anything-in-persistent-action
2768 (anything-c-advice-update-current-display-string))))
2770 (defun anything-c-advice-update-current-display-string ()
2771 (anything-edit-current-selection
2772 (let ((newword (cond ((looking-at "Disabled") "Enabled")
2773 ((looking-at "Enabled") "Disabled")))
2774 realvalue)
2775 (when newword
2776 (delete-region (point) (progn (forward-word 1) (point)))
2777 (insert newword)))))
2779 ;;;###autoload
2780 (defun anything-manage-advice ()
2781 "Preconfigured `anything' to disable/enable function advices."
2782 (interactive)
2783 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
2785 ;;;; <Variable>
2786 ;;; Emacs variables
2787 (defvar anything-c-source-emacs-variables
2788 '((name . "Emacs Variables")
2789 (candidates . (lambda ()
2790 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
2791 (type . variable)
2792 (requires-pattern . 2))
2793 "Source for completing Emacs variables.")
2794 ;; (anything 'anything-c-source-emacs-variables)
2796 ;;;; <Bookmark>
2797 ;;; Bookmarks
2798 (eval-when-compile (require 'bookmark))
2799 (defvar anything-c-source-bookmarks
2800 '((name . "Bookmarks")
2801 (init . (lambda ()
2802 (require 'bookmark)))
2803 (candidates . bookmark-all-names)
2804 (type . bookmark))
2805 "See (info \"(emacs)Bookmarks\").")
2806 ;; (anything 'anything-c-source-bookmarks)
2808 ;;; bookmark-set
2809 (defvar anything-c-source-bookmark-set
2810 '((name . "Set Bookmark")
2811 (dummy)
2812 (action . bookmark-set))
2813 "See (info \"(emacs)Bookmarks\").")
2814 ;; (anything 'anything-c-source-bookmark-set)
2816 ;;; Visible Bookmarks
2817 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2820 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2821 (defvar anything-c-source-bm
2822 '((name . "Visible Bookmarks")
2823 (init . anything-c-bm-init)
2824 (candidates-in-buffer)
2825 (type . line))
2826 "Needs bm.el.
2828 http://www.nongnu.org/bm/")
2830 (defun anything-c-bm-init ()
2831 "Init function for `anything-c-source-bm'."
2832 (when (require 'bm nil t)
2833 (with-no-warnings
2834 (let ((bookmarks (bm-lists))
2835 (buf (anything-candidate-buffer 'global)))
2836 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
2837 '< :key 'overlay-start))
2838 (let ((start (overlay-start bm))
2839 (end (overlay-end bm))
2840 (annotation (or (overlay-get bm 'annotation) "")))
2841 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
2842 (let ((str (format "%5d: [%s]: %s\n"
2843 (line-number-at-pos start)
2844 annotation
2845 (buffer-substring start (1- end)))))
2846 (with-current-buffer buf (insert str))))))))))
2848 ;;; Special bookmarks
2849 (defvar anything-c-source-bookmarks-ssh
2850 '((name . "Bookmarks-ssh")
2851 (init . (lambda ()
2852 (require 'bookmark)))
2853 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
2854 (type . bookmark))
2855 "See (info \"(emacs)Bookmarks\").")
2856 ;; (anything 'anything-c-source-bookmarks-ssh)
2858 (defvar anything-c-source-bookmarks-su
2859 '((name . "Bookmarks-root")
2860 (init . (lambda ()
2861 (require 'bookmark)))
2862 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
2863 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
2865 (type . bookmark))
2866 "See (info \"(emacs)Bookmarks\").")
2867 ;; (anything 'anything-c-source-bookmarks-su)
2869 (defvar anything-c-source-bookmarks-local
2870 '((name . "Bookmarks-Local")
2871 (init . (lambda ()
2872 (require 'bookmark)))
2873 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
2874 (filtered-candidate-transformer
2875 anything-c-adaptive-sort
2876 anything-c-highlight-bookmark)
2877 (type . bookmark))
2878 "See (info \"(emacs)Bookmarks\").")
2879 ;; (anything 'anything-c-source-bookmarks-local)
2881 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
2882 (let* ((lis-all (bookmark-all-names))
2883 (lis-loc (cond (local (loop for i in lis-all
2884 unless (string-match "^(ssh)\\|^(su)" i)
2885 collect i))
2886 (su (loop for i in lis-all
2887 when (string-match "^(su)" i)
2888 collect i))
2889 (sudo (loop for i in lis-all
2890 when (string-match "^(sudo)" i)
2891 collect i))
2892 (ssh (loop for i in lis-all
2893 when (string-match "^(ssh)" i)
2894 collect i)))))
2895 (sort lis-loc 'string-lessp)))
2897 (defun anything-c-bookmark-root-logged-p ()
2898 (catch 'break
2899 (dolist (i (mapcar #'buffer-name (buffer-list)))
2900 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
2901 (throw 'break t)))))
2903 (defun anything-c-highlight-bookmark-su (files source)
2904 (if (anything-c-bookmark-root-logged-p)
2905 (anything-c-highlight-bookmark files source)
2906 (anything-c-highlight-not-logged files source)))
2908 (defun anything-c-highlight-not-logged (files source)
2909 (loop for i in files
2910 collect (propertize i 'face anything-c-bookmarks-face3)))
2912 (defun anything-c-highlight-bookmark (bookmarks source)
2913 "Used as `candidate-transformer' to colorize bookmarks.
2914 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2915 (loop for i in bookmarks
2916 for pred = (bookmark-get-filename i)
2917 for bufp = (and (fboundp 'bmkext-get-buffer-name)
2918 (bmkext-get-buffer-name i))
2919 for handlerp = (and (fboundp 'bookmark-get-handler)
2920 (bookmark-get-handler i))
2921 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
2922 (bmkext-w3m-bookmark-p i))
2923 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
2924 (bmkext-gnus-bookmark-p i))
2925 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
2926 (bmkext-man-bookmark-p i))
2927 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
2928 (bmkext-woman-bookmark-p i))
2929 for handlerp = (bookmark-get-handler i)
2930 for isannotation = (bookmark-get-annotation i)
2931 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
2932 ;; Add a * if bookmark have annotation
2933 if (and isannotation (not (string-equal isannotation "")))
2934 do (setq i (concat "*" i))
2935 ;; info buffers
2936 if (eq handlerp 'Info-bookmark-jump)
2937 collect (propertize i 'face 'anything-bmkext-info 'help-echo pred)
2938 ;; w3m buffers
2939 if isw3m
2940 collect (propertize i 'face 'anything-bmkext-w3m 'help-echo pred)
2941 ;; gnus buffers
2942 if isgnus
2943 collect (propertize i 'face 'anything-bmkext-gnus 'help-echo pred)
2944 ;; Man Woman
2945 if (or iswoman isman)
2946 collect (propertize i 'face 'anything-bmkext-man 'help-echo pred)
2947 ;; Addressbook
2948 if (and (not pred) isabook)
2949 collect (propertize i 'face '((:foreground "Tomato")))
2950 ;; directories
2951 if (and pred (file-directory-p pred))
2952 collect (propertize i 'face anything-c-bookmarks-face1 'help-echo pred)
2953 ;; regular files
2954 if (and pred (not (file-directory-p pred)) (file-exists-p pred)
2955 (not (or iswoman isman)))
2956 collect (propertize i 'face 'anything-bmkext-file 'help-echo pred)))
2959 ;;; Faces for bookmarks
2960 (defface anything-bmkext-info
2961 '((t (:foreground "green")))
2962 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2963 :group 'anything)
2965 (defface anything-bmkext-w3m
2966 '((t (:foreground "yellow")))
2967 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2968 :group 'anything)
2970 (defface anything-bmkext-gnus
2971 '((t (:foreground "magenta")))
2972 "*Face used for Gnus bookmarks."
2973 :group 'anything)
2975 (defface anything-bmkext-man
2976 '((t (:foreground "Orange4")))
2977 "*Face used for Woman/man bookmarks."
2978 :group 'anything)
2980 (defface anything-bmkext-no--file
2981 '((t (:foreground "grey")))
2982 "*Face used for non--file bookmarks."
2983 :group 'anything)
2985 (defface anything-bmkext-file
2986 '((t (:foreground "Deepskyblue2")))
2987 "*Face used for non--file bookmarks."
2988 :group 'anything)
2990 (defface anything-bookmarks-su-face '((t (:foreground "red")))
2991 "Face for su/sudo bookmarks."
2992 :group 'anything)
2994 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
2995 (defvar anything-c-bookmarks-face2 'anything-file-name)
2996 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
2999 ;;; Sources to filter bookmark-extensions bookmarks.
3000 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3001 ;; If you want to enable google-maps in addressbook you will need
3002 ;; Julien Danjou google-maps-el package available here:
3003 ;; http://julien.danjou.info/google-maps-el.html
3005 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
3006 "Return a filtered `bookmark-alist' sorted alphabetically."
3007 (loop
3008 with alist = (if args
3009 (apply #'(lambda (x) (funcall fn x)) args)
3010 (funcall fn))
3011 for i in alist
3012 for b = (car i)
3013 collect b into sa
3014 finally return (sort sa 'string-lessp)))
3016 ;; Addressbook
3017 (defvar anything-c-source-bmkext-addressbook
3018 '((name . "Bookmark Addressbook")
3019 (init . (lambda ()
3020 (require 'bookmark-extensions)
3021 (bookmark-maybe-load-default-file)))
3022 (candidates . anything-c-bmkext-addressbook-setup-alist)
3023 (persistent-action
3024 . (lambda (candidate)
3025 (let ((bmk (anything-bookmark-get-bookmark-from-name
3026 candidate)))
3027 (bookmark--jump-via bmk 'pop-to-buffer))))
3028 (persistent-help . "Show contact - Prefix with C-u to append")
3029 (filtered-candidate-transformer
3030 anything-c-adaptive-sort
3031 anything-c-highlight-bookmark)
3032 (action . (("Show person's data"
3033 . (lambda (candidate)
3034 (let ((bmk (anything-bookmark-get-bookmark-from-name
3035 candidate))
3036 (current-prefix-arg anything-current-prefix-arg))
3037 (bookmark-jump bmk))))
3038 ("Send Mail"
3039 . (lambda (candidate)
3040 (let ((bmk (anything-bookmark-get-bookmark-from-name
3041 candidate)))
3042 (if anything-current-prefix-arg
3043 (addressbook-set-mail-buffer1 bmk 'append)
3044 (addressbook-set-mail-buffer1 bmk)))))
3045 ("Edit Bookmark"
3046 . (lambda (candidate)
3047 (let ((bmk (anything-bookmark-get-bookmark-from-name
3048 candidate)))
3049 (addressbook-bookmark-edit
3050 (assoc bmk bookmark-alist)))))
3051 ("Insert Email at point"
3052 . (lambda (candidate)
3053 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3054 candidate))
3055 (mlist (split-string
3056 (assoc-default
3057 'email (assoc bmk bookmark-alist))
3058 ", ")))
3059 (insert
3060 (if (> (length mlist) 1)
3061 (anything-comp-read
3062 "Insert Mail Address: " mlist :must-match t)
3063 (car mlist))))))
3064 ("Show annotation"
3065 . (lambda (candidate)
3066 (let ((bmk (anything-bookmark-get-bookmark-from-name
3067 candidate)))
3068 (bookmark-show-annotation bmk))))
3069 ("Edit annotation"
3070 . (lambda (candidate)
3071 (let ((bmk (anything-bookmark-get-bookmark-from-name
3072 candidate)))
3073 (bookmark-edit-annotation bmk))))
3074 ("Show Google map" . (lambda (candidate)
3075 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3076 candidate))
3077 (full-bmk (assoc bmk bookmark-alist)))
3078 (addressbook-google-map full-bmk))))))))
3081 (defun anything-c-bmkext-addressbook-setup-alist ()
3082 "Specialized filter function for bookmarks w3m."
3083 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
3085 ;; W3m
3086 (defvar anything-c-source-bookmark-w3m
3087 '((name . "Bookmark W3m")
3088 (init . (lambda ()
3089 (require 'bookmark-extensions)
3090 (bookmark-maybe-load-default-file)))
3091 (candidates . anything-c-bookmark-w3m-setup-alist)
3092 (filtered-candidate-transformer
3093 anything-c-adaptive-sort
3094 anything-c-highlight-bookmark)
3095 (type . bookmark)))
3096 ;; (anything 'anything-c-source-bookmark-w3m)
3098 (defun anything-c-bookmark-w3m-setup-alist ()
3099 "Specialized filter function for bookmarks w3m."
3100 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
3102 ;; Images
3103 (defvar anything-c-source-bookmark-images
3104 '((name . "Bookmark Images")
3105 (init . (lambda ()
3106 (require 'bookmark-extensions)
3107 (bookmark-maybe-load-default-file)))
3108 (candidates . anything-c-bookmark-images-setup-alist)
3109 (filtered-candidate-transformer
3110 anything-c-adaptive-sort
3111 anything-c-highlight-bookmark)
3112 (type . bookmark)))
3113 ;; (anything 'anything-c-source-bookmark-images)
3115 (defun anything-c-bookmark-images-setup-alist ()
3116 "Specialized filter function for images bookmarks."
3117 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
3119 ;; Woman Man
3120 (defvar anything-c-source-bookmark-man
3121 '((name . "Bookmark Woman&Man")
3122 (init . (lambda ()
3123 (require 'bookmark-extensions)
3124 (bookmark-maybe-load-default-file)))
3125 (candidates . anything-c-bookmark-man-setup-alist)
3126 (filtered-candidate-transformer
3127 anything-c-adaptive-sort
3128 anything-c-highlight-bookmark)
3129 (type . bookmark)))
3130 ;; (anything 'anything-c-source-bookmark-man)
3132 (defun anything-c-bookmark-man-setup-alist ()
3133 "Specialized filter function for bookmarks w3m."
3134 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
3135 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
3137 ;; Gnus
3138 (defvar anything-c-source-bookmark-gnus
3139 '((name . "Bookmark Gnus")
3140 (init . (lambda ()
3141 (require 'bookmark-extensions)
3142 (bookmark-maybe-load-default-file)))
3143 (candidates . anything-c-bookmark-gnus-setup-alist)
3144 (filtered-candidate-transformer
3145 anything-c-adaptive-sort
3146 anything-c-highlight-bookmark)
3147 (type . bookmark)))
3148 ;; (anything 'anything-c-source-bookmark-gnus)
3150 (defun anything-c-bookmark-gnus-setup-alist ()
3151 "Specialized filter function for bookmarks gnus."
3152 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
3154 ;; Info
3155 (defvar anything-c-source-bookmark-info
3156 '((name . "Bookmark Info")
3157 (init . (lambda ()
3158 (require 'bookmark-extensions)
3159 (bookmark-maybe-load-default-file)))
3160 (candidates . anything-c-bookmark-info-setup-alist)
3161 (filtered-candidate-transformer
3162 anything-c-adaptive-sort
3163 anything-c-highlight-bookmark)
3164 (type . bookmark)))
3165 ;; (anything 'anything-c-source-bookmark-info)
3167 (defun anything-c-bookmark-info-setup-alist ()
3168 "Specialized filter function for bookmarks info."
3169 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
3171 ;; Local Files&directories
3172 (defvar anything-c-source-bookmark-files&dirs
3173 '((name . "Bookmark Files&Directories")
3174 (init . (lambda ()
3175 (require 'bookmark-extensions)
3176 (bookmark-maybe-load-default-file)))
3177 (candidates . anything-c-bookmark-local-files-setup-alist)
3178 (filtered-candidate-transformer
3179 anything-c-adaptive-sort
3180 anything-c-highlight-bookmark)
3181 (type . bookmark)))
3182 ;; (anything 'anything-c-source-bookmark-files&dirs)
3184 (defun anything-c-bookmark-local-files-setup-alist ()
3185 "Specialized filter function for bookmarks locals files."
3186 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
3188 ;; Su Files&directories
3189 (defvar anything-c-source-bookmark-su-files&dirs
3190 '((name . "Bookmark Root-Files&Directories")
3191 (init . (lambda ()
3192 (require 'bookmark-extensions)
3193 (bookmark-maybe-load-default-file)))
3194 (candidates . anything-c-bookmark-su-files-setup-alist)
3195 (filtered-candidate-transformer
3196 anything-c-adaptive-sort
3197 anything-c-highlight-bookmark-su)
3198 (type . bookmark)))
3199 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3201 (defun anything-c-bookmark-su-files-setup-alist ()
3202 "Specialized filter function for bookmarks su/sudo files."
3203 (loop
3204 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3205 for i in l
3206 for isfile = (bookmark-get-filename i)
3207 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3208 (save-match-data
3209 (string-match tramp-file-name-regexp isfile)))
3210 for issu = (and istramp
3211 (string-match bmkext-su-or-sudo-regexp isfile))
3212 if issu
3213 collect i))
3215 ;; Ssh Files&directories
3216 (defvar anything-c-source-bookmark-ssh-files&dirs
3217 '((name . "Bookmark Ssh-Files&Directories")
3218 (init . (lambda ()
3219 (require 'bookmark-extensions)
3220 (bookmark-maybe-load-default-file)))
3221 (candidates . anything-c-bookmark-ssh-files-setup-alist)
3222 (filtered-candidate-transformer . anything-c-adaptive-sort)
3223 (type . bookmark)))
3224 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3226 (defun anything-c-bookmark-ssh-files-setup-alist ()
3227 "Specialized filter function for bookmarks ssh files."
3228 (loop
3229 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3230 for i in l
3231 for isfile = (bookmark-get-filename i)
3232 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3233 (save-match-data
3234 (string-match tramp-file-name-regexp isfile)))
3235 for isssh = (and istramp
3236 (string-match "/ssh:" isfile))
3237 if isssh
3238 collect i))
3241 ;; All bookmark-extensions sources.
3242 ;;;###autoload
3243 (defun anything-bookmark-ext ()
3244 "Preconfigured `anything' for bookmark-extensions sources.
3245 Needs bookmark-ext.el
3247 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3248 (interactive)
3249 (anything '(anything-c-source-bookmark-files&dirs
3250 anything-c-source-bookmark-w3m
3251 anything-c-source-bmkext-addressbook
3252 anything-c-source-bookmark-gnus
3253 anything-c-source-bookmark-info
3254 anything-c-source-bookmark-man
3255 anything-c-source-bookmark-images
3256 anything-c-source-bookmark-su-files&dirs
3257 anything-c-source-bookmark-ssh-files&dirs)
3258 nil "SearchBookmark: " nil nil "*anything bmkext*"))
3261 ;; Firefox bookmarks
3262 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
3263 ;; (only for firefox versions >=3)
3264 ;; To achieve that, open about:config in firefox and double click on this line to enable value
3265 ;; to true:
3266 ;; user_pref("browser.bookmarks.autoExportHTML", false);
3267 ;; You should have now:
3268 ;; user_pref("browser.bookmarks.autoExportHTML", true);
3270 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
3271 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3273 (defun anything-get-firefox-user-init-dir ()
3274 "Guess the default Firefox user directory name."
3275 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
3276 (moz-user-dir (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
3277 (goto-char (point-min))
3278 (when (search-forward "Path=" nil t)
3279 (buffer-substring-no-properties (point) (point-at-eol))))))
3280 (file-name-as-directory (concat moz-dir moz-user-dir))))
3282 (defun anything-guess-firefox-bookmark-file ()
3283 "Return the path of the Firefox bookmarks file."
3284 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
3286 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
3287 "Parse html bookmark FILE and return an alist with (title . url) as elements."
3288 (let (bookmarks-alist url title)
3289 (with-temp-buffer
3290 (insert-file-contents file)
3291 (goto-char (point-min))
3292 (while (not (eobp))
3293 (forward-line)
3294 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
3295 (beginning-of-line)
3296 (when (re-search-forward url-regexp nil t)
3297 (setq url (concat "\"" (match-string 0))))
3298 (beginning-of-line)
3299 (when (re-search-forward bmk-regexp nil t)
3300 (setq title (match-string 1)))
3301 (push (cons title url) bookmarks-alist))))
3302 (nreverse bookmarks-alist)))
3305 (defvar anything-c-firefox-bookmarks-alist nil)
3306 (defvar anything-c-source-firefox-bookmarks
3307 '((name . "Firefox Bookmarks")
3308 (init . (lambda ()
3309 (setq anything-c-firefox-bookmarks-alist
3310 (anything-html-bookmarks-to-alist
3311 (anything-guess-firefox-bookmark-file)
3312 anything-firefox-bookmark-url-regexp
3313 anything-firefox-bookmarks-regexp))))
3314 (candidates . (lambda ()
3315 (mapcar #'car
3316 anything-c-firefox-bookmarks-alist)))
3317 (filtered-candidate-transformer
3318 anything-c-adaptive-sort
3319 anything-c-highlight-firefox-bookmarks)
3320 (action . (("Browse Url Firefox" . (lambda (candidate)
3321 (browse-url-firefox
3322 (anything-c-firefox-bookmarks-get-value candidate))))
3323 ("Browse Url w3m" . (lambda (candidate)
3324 (w3m-browse-url
3325 (anything-c-firefox-bookmarks-get-value candidate))))
3326 ("Copy Url" . (lambda (elm)
3327 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
3329 ;; (anything 'anything-c-source-firefox-bookmarks)
3331 (defun anything-c-firefox-bookmarks-get-value (elm)
3332 (replace-regexp-in-string "\"" ""
3333 (cdr (assoc elm
3334 anything-c-firefox-bookmarks-alist))))
3337 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
3338 (loop for i in bookmarks
3339 collect (propertize i
3340 'face '((:foreground "YellowGreen"))
3341 'help-echo (anything-c-firefox-bookmarks-get-value i))))
3343 ;; W3m bookmark
3344 (eval-when-compile (require 'w3m-bookmark nil t))
3345 (unless (and (require 'w3m nil t)
3346 (require 'w3m-bookmark nil t))
3347 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
3350 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
3351 "Face for w3m bookmarks" :group 'anything)
3353 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3354 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
3355 (defvar anything-c-w3m-bookmarks-alist nil)
3356 (defvar anything-c-source-w3m-bookmarks
3357 '((name . "W3m Bookmarks")
3358 (init . (lambda ()
3359 (setq anything-c-w3m-bookmarks-alist
3360 (anything-html-bookmarks-to-alist
3361 w3m-bookmark-file
3362 anything-w3m-bookmark-url-regexp
3363 anything-w3m-bookmarks-regexp))))
3364 (candidates . (lambda ()
3365 (mapcar #'car anything-c-w3m-bookmarks-alist)))
3366 (filtered-candidate-transformer
3367 anything-c-adaptive-sort
3368 anything-c-highlight-w3m-bookmarks)
3369 (action . (("Browse Url" . (lambda (candidate)
3370 (anything-c-w3m-browse-bookmark candidate)))
3371 ("Copy Url" . (lambda (elm)
3372 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
3373 ("Browse Url Firefox" . (lambda (candidate)
3374 (anything-c-w3m-browse-bookmark candidate t)))
3375 ("Delete Bookmark" . (lambda (candidate)
3376 (anything-c-w3m-delete-bookmark candidate)))
3377 ("Rename Bookmark" . (lambda (candidate)
3378 (anything-c-w3m-rename-bookmark candidate)))))
3379 (persistent-action . (lambda (candidate)
3380 (if current-prefix-arg
3381 (anything-c-w3m-browse-bookmark candidate t)
3382 (anything-c-w3m-browse-bookmark candidate nil t))))
3383 (persistent-help . "Open URL with emacs-w3m in new tab / \
3384 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
3385 "Needs w3m and emacs-w3m.
3387 http://w3m.sourceforge.net/
3388 http://emacs-w3m.namazu.org/")
3390 ;; (anything 'anything-c-source-w3m-bookmarks)
3392 (defun anything-c-w3m-bookmarks-get-value (elm)
3393 (replace-regexp-in-string
3394 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
3396 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
3397 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
3398 (arg (and (eq fn 'w3m-browse-url) new-tab)))
3399 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
3401 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
3402 (loop for i in bookmarks
3403 collect (propertize
3404 i 'face 'anything-w3m-bookmarks-face
3405 'help-echo (anything-c-w3m-bookmarks-get-value i))))
3408 (defun anything-c-w3m-delete-bookmark (elm)
3409 (save-excursion
3410 (find-file-literally w3m-bookmark-file)
3411 (goto-char (point-min))
3412 (when (re-search-forward elm nil t)
3413 (beginning-of-line)
3414 (delete-region (point)
3415 (line-end-position))
3416 (delete-blank-lines))
3417 (save-buffer (current-buffer))
3418 (kill-buffer (current-buffer))))
3420 (defun anything-c-w3m-rename-bookmark (elm)
3421 (let* ((old-title (replace-regexp-in-string ">" "" elm))
3422 (new-title (read-string "NewTitle: " old-title)))
3423 (save-excursion
3424 (find-file-literally w3m-bookmark-file)
3425 (goto-char (point-min))
3426 (when (re-search-forward (concat elm "<") nil t)
3427 (goto-char (1- (point)))
3428 (delete-char (- (length old-title)))
3429 (insert new-title))
3430 (save-buffer (current-buffer))
3431 (kill-buffer (current-buffer)))))
3433 ;;;; <Library>
3434 ;;; Elisp library scan
3435 (defvar anything-c-source-elisp-library-scan
3436 '((name . "Elisp libraries (Scan)")
3437 (init . (anything-c-elisp-library-scan-init))
3438 (candidates-in-buffer)
3439 (action ("Find library" . (lambda (candidate)
3440 (find-file (find-library-name candidate))))
3441 ("Find library other window" . (lambda (candidate)
3442 (find-file-other-window (find-library-name candidate))))
3443 ("Load library" . (lambda (candidate)
3444 (load-library candidate))))))
3445 ;; (anything 'anything-c-source-elisp-library-scan)
3447 (defun anything-c-elisp-library-scan-init ()
3448 "Init anything buffer status."
3449 (let ((anything-buffer (anything-candidate-buffer 'global))
3450 (library-list (anything-c-elisp-library-scan-list)))
3451 (with-current-buffer anything-buffer
3452 (dolist (library library-list)
3453 (insert (format "%s\n" library))))))
3455 (defun anything-c-elisp-library-scan-list (&optional dirs string)
3456 "Do completion for file names passed to `locate-file'.
3457 DIRS is directory to search path.
3458 STRING is string to match."
3459 ;; Use `load-path' as path when ignore `dirs'.
3460 (or dirs (setq dirs load-path))
3461 ;; Init with blank when ignore `string'.
3462 (or string (setq string ""))
3463 ;; Get library list.
3464 (let ((string-dir (file-name-directory string))
3465 ;; File regexp that suffix match `load-file-rep-suffixes'.
3466 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
3467 name
3468 names)
3469 (dolist (dir dirs)
3470 (unless dir
3471 (setq dir default-directory))
3472 (if string-dir
3473 (setq dir (expand-file-name string-dir dir)))
3474 (when (file-directory-p dir)
3475 (dolist (file (file-name-all-completions
3476 (file-name-nondirectory string) dir))
3477 ;; Suffixes match `load-file-rep-suffixes'.
3478 (setq name (if string-dir (concat string-dir file) file))
3479 (if (string-match match-regexp name)
3480 (add-to-list 'names name)))))
3481 names))
3483 ;;;; <Programming>
3484 ;;; Imenu
3485 (defvar anything-c-imenu-delimiter " / ")
3487 (defvar anything-c-imenu-index-filter nil)
3488 (make-variable-buffer-local 'anything-c-imenu-index-filter)
3490 (defvar anything-c-cached-imenu-alist nil)
3491 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
3493 (defvar anything-c-cached-imenu-candidates nil)
3494 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
3496 (defvar anything-c-cached-imenu-tick nil)
3497 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
3499 (eval-when-compile (require 'imenu))
3500 (setq imenu-auto-rescan t)
3502 (defun anything-imenu-create-candidates (entry)
3503 "Create candidates with ENTRY."
3504 (if (listp (cdr entry))
3505 (mapcan (lambda (sub)
3506 (if (consp (cdr sub))
3507 (mapcar
3508 (lambda (subentry)
3509 (concat (car entry) anything-c-imenu-delimiter subentry))
3510 (anything-imenu-create-candidates sub))
3511 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
3512 (cdr entry))
3513 (list entry)))
3515 (defvar anything-c-source-imenu
3516 '((name . "Imenu")
3517 (init . (lambda () (require 'imenu)))
3518 (candidates . anything-c-imenu-candidates)
3519 (persistent-action . (lambda (elm)
3520 (anything-c-imenu-default-action elm)
3521 (unless (fboundp 'semantic-imenu-tag-overlay)
3522 (anything-match-line-color-current-line))))
3523 (persistent-help . "Show this entry")
3524 (action . anything-c-imenu-default-action))
3525 "See (info \"(emacs)Imenu\")")
3527 ;; (anything 'anything-c-source-imenu)
3529 (defun anything-c-imenu-candidates ()
3530 (with-current-buffer anything-current-buffer
3531 (let ((tick (buffer-modified-tick)))
3532 (if (eq anything-c-cached-imenu-tick tick)
3533 anything-c-cached-imenu-candidates
3534 (setq imenu--index-alist nil)
3535 (setq anything-c-cached-imenu-tick tick
3536 anything-c-cached-imenu-candidates
3537 (ignore-errors
3538 (mapcan
3539 'anything-imenu-create-candidates
3540 (setq anything-c-cached-imenu-alist
3541 (let ((index (imenu--make-index-alist)))
3542 (if anything-c-imenu-index-filter
3543 (funcall anything-c-imenu-index-filter index)
3544 index))))))
3545 (setq anything-c-cached-imenu-candidates
3546 (mapcar #'(lambda (x)
3547 (if (stringp x)
3549 (car x)))
3550 anything-c-cached-imenu-candidates))))))
3552 (setq imenu-default-goto-function 'imenu-default-goto-function)
3553 (defun anything-c-imenu-default-action (elm)
3554 "The default action for `anything-c-source-imenu'."
3555 (let ((path (split-string elm anything-c-imenu-delimiter))
3556 (alist anything-c-cached-imenu-alist))
3557 (if (> (length path) 1)
3558 (progn
3559 (setq alist (assoc (car path) alist))
3560 (setq elm (cadr path))
3561 (imenu (assoc elm alist)))
3562 (imenu (assoc elm alist)))))
3564 ;;; Ctags
3565 (defvar anything-c-ctags-modes
3566 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3567 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3568 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
3570 (defun anything-c-source-ctags-init ()
3571 (when (and buffer-file-name
3572 (memq major-mode anything-c-ctags-modes)
3573 (anything-current-buffer-is-modified))
3574 (with-current-buffer (anything-candidate-buffer 'local)
3575 (call-process-shell-command
3576 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
3577 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
3578 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
3579 nil (current-buffer))
3580 (goto-char (point-min))
3581 (forward-line 2)
3582 (delete-region (point-min) (point))
3583 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
3584 for lineno-start = (point)
3585 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
3587 (beginning-of-line)
3588 (insert (format "%5s:" lineno))
3589 (search-forward "\177" (point-at-eol) t)
3590 (delete-region (1- (point)) (point-at-eol))
3591 (forward-line 1)))))
3593 (defvar anything-c-source-ctags
3594 '((name . "Exuberant ctags")
3595 (init . anything-c-source-ctags-init)
3596 (candidates-in-buffer)
3597 (adjust)
3598 (type . line))
3599 "Needs Exuberant Ctags.
3601 http://ctags.sourceforge.net/")
3602 ;; (anything 'anything-c-source-ctags)
3604 ;; Semantic
3605 (eval-when-compile (require 'semantic nil t))
3606 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
3607 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
3608 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
3609 (defvar anything-semantic-candidates nil)
3611 (defun anything-semantic-construct-candidates (tags depth)
3612 (when (require 'semantic nil t)
3613 (apply 'append
3614 (mapcar (lambda (tag)
3615 (if (listp tag)
3616 (let ((type (semantic-tag-type tag))
3617 (class (semantic-tag-class tag)))
3618 (if (or (and (stringp type)
3619 (or (string= type "class")
3620 (string= type "namespace")))
3621 (eq class 'function)
3622 (eq class 'variable))
3623 (cons (cons (concat (make-string (* depth 2) ?\s)
3624 (semantic-format-tag-summarize tag nil t)) tag)
3625 (anything-semantic-construct-candidates (semantic-tag-components tag)
3626 (1+ depth)))))))
3627 tags))))
3629 (defun anything-semantic-default-action (candidate)
3630 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
3631 (semantic-go-to-tag tag)))
3633 (defvar anything-c-source-semantic
3634 '((name . "Semantic Tags")
3635 (init . (lambda ()
3636 (setq anything-semantic-candidates
3637 (ignore-errors (anything-semantic-construct-candidates (semantic-fetch-tags) 0)))))
3638 (candidates . (lambda ()
3639 (if anything-semantic-candidates
3640 (mapcar 'car anything-semantic-candidates))))
3641 (persistent-action . (lambda (elm)
3642 (anything-semantic-default-action elm)
3643 (anything-match-line-color-current-line)))
3644 (persistent-help . "Show this entry")
3645 (action . anything-semantic-default-action)
3646 "Needs semantic in CEDET.
3648 http://cedet.sourceforge.net/semantic.shtml
3649 http://cedet.sourceforge.net/"))
3651 ;; (anything 'anything-c-source-semantic)
3653 ;;; Function is called by
3654 ;;;###autoload
3655 (defun anything-simple-call-tree ()
3656 "Preconfigured `anything' for simple-call-tree. List function relationships.
3658 Needs simple-call-tree.el.
3659 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
3660 (interactive)
3661 (anything-other-buffer
3662 '(anything-c-source-simple-call-tree-functions-callers
3663 anything-c-source-simple-call-tree-callers-functions)
3664 "*anything simple-call-tree*"))
3666 (defvar anything-c-source-simple-call-tree-functions-callers
3667 '((name . "Function is called by")
3668 (init . anything-c-simple-call-tree-functions-callers-init)
3669 (multiline)
3670 (candidates . anything-c-simple-call-tree-candidates)
3671 (persistent-action . anything-c-simple-call-tree-persistent-action)
3672 (persistent-help . "Show function definitions by rotation")
3673 (action ("Find definition selected by persistent-action" .
3674 anything-c-simple-call-tree-find-definition)))
3675 "Needs simple-call-tree.el.
3676 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3678 (defvar anything-c-simple-call-tree-tick nil)
3679 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
3680 (defun anything-c-simple-call-tree-analyze-maybe ()
3681 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
3682 (simple-call-tree-analyze)
3683 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
3685 (defun anything-c-simple-call-tree-init-base (function message)
3686 (require 'simple-call-tree)
3687 (with-no-warnings
3688 (when (anything-current-buffer-is-modified)
3689 (anything-c-simple-call-tree-analyze-maybe)
3690 (let ((list (funcall function simple-call-tree-alist)))
3691 (with-current-buffer (anything-candidate-buffer 'local)
3692 (dolist (entry list)
3693 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
3694 (insert (car entry) message
3695 (if (string= funcs " ")
3696 " no functions."
3697 funcs)
3698 "\n\n"))))))))
3700 (defun anything-c-simple-call-tree-functions-callers-init ()
3701 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert " is called by\n"))
3703 (defun anything-c-simple-call-tree-candidates ()
3704 (with-current-buffer (anything-candidate-buffer)
3705 (split-string (buffer-string) "\n\n")))
3707 (defvar anything-c-simple-call-tree-related-functions nil)
3708 (defvar anything-c-simple-call-tree-function-index 0)
3709 (defun anything-c-simple-call-tree-persistent-action (candidate)
3710 (unless (eq last-command 'anything-execute-persistent-action)
3711 (setq anything-c-simple-call-tree-related-functions
3712 (delete "no functions."
3713 (split-string
3714 (replace-regexp-in-string " \\| is called by\\| calls " "" candidate)
3715 "\n")))
3716 (setq anything-c-simple-call-tree-function-index -1))
3717 (incf anything-c-simple-call-tree-function-index)
3718 (anything-c-simple-call-tree-find-definition candidate))
3720 (defun anything-c-simple-call-tree-find-definition (candidate)
3721 (find-function (intern
3722 (nth (mod anything-c-simple-call-tree-function-index
3723 (length anything-c-simple-call-tree-related-functions))
3724 anything-c-simple-call-tree-related-functions))))
3726 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3728 ;;; Function calls
3729 (defvar anything-c-source-simple-call-tree-callers-functions
3730 '((name . "Function calls")
3731 (init . anything-c-simple-call-tree-callers-functions-init)
3732 (multiline)
3733 (candidates . anything-c-simple-call-tree-candidates)
3734 (persistent-action . anything-c-simple-call-tree-persistent-action)
3735 (persistent-help . "Show function definitions by rotation")
3736 (action ("Find definition selected by persistent-action" .
3737 anything-c-simple-call-tree-find-definition)))
3738 "Needs simple-call-tree.el.
3739 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3741 (defun anything-c-simple-call-tree-callers-functions-init ()
3742 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
3744 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3746 ;;; Commands/Options with doc
3747 (defvar anything-c-auto-document-data nil)
3748 (make-variable-buffer-local 'anything-c-auto-document-data)
3749 (defvar anything-c-source-commands-and-options-in-file
3750 '((name . "Commands/Options in file")
3751 (header-name
3752 . (lambda (x) (format "Commands/Options in %s"
3753 (buffer-local-value 'buffer-file-name anything-current-buffer))))
3754 (candidates . anything-command-and-options-candidates)
3755 (multiline)
3756 (action . imenu))
3757 "List Commands and Options with doc. It needs auto-document.el .
3759 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3761 (eval-when-compile (require 'auto-document nil t))
3762 (defun anything-command-and-options-candidates ()
3763 (with-current-buffer anything-current-buffer
3764 (when (and (require 'auto-document nil t)
3765 (eq major-mode 'emacs-lisp-mode)
3766 (or (anything-current-buffer-is-modified)
3767 (not anything-c-auto-document-data)))
3768 (or imenu--index-alist (imenu--make-index-alist t))
3769 (setq anything-c-auto-document-data
3770 (destructuring-bind (commands options)
3771 (adoc-construct anything-current-buffer)
3772 (append
3773 (loop for (command . doc) in commands
3774 for cmdname = (symbol-name command)
3775 collect
3776 (cons (format "Command: %s\n %s"
3777 (propertize cmdname 'face font-lock-function-name-face)
3778 (adoc-first-line doc))
3779 (assoc cmdname imenu--index-alist)))
3780 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
3781 for (option doc default) in options
3782 for optname = (symbol-name option)
3783 collect
3784 (cons (format "Option: %s\n %s\n default = %s"
3785 (propertize optname 'face font-lock-variable-name-face)
3786 (adoc-first-line doc)
3787 (adoc-prin1-to-string default))
3788 (assoc optname
3789 var-alist)))))))
3790 anything-c-auto-document-data))
3792 ;; (anything 'anything-c-source-commands-and-options-in-file)
3794 ;;;; <Color and Face>
3795 ;;; Customize Face
3796 (defvar anything-c-source-customize-face
3797 '((name . "Customize Face")
3798 (init . (lambda ()
3799 (unless (anything-candidate-buffer)
3800 (save-window-excursion (list-faces-display))
3801 (anything-candidate-buffer (get-buffer "*Faces*")))))
3802 (candidates-in-buffer)
3803 (get-line . buffer-substring)
3804 (action . (lambda (line)
3805 (customize-face (intern (car (split-string line))))))
3806 (requires-pattern . 3))
3807 "See (info \"(emacs)Faces\")")
3808 ;; (anything 'anything-c-source-customize-face)
3810 ;; Color
3811 (defvar anything-c-source-colors
3812 '((name . "Colors")
3813 (init . (lambda () (unless (anything-candidate-buffer)
3814 (save-window-excursion (list-colors-display))
3815 (anything-candidate-buffer (get-buffer "*Colors*")))))
3816 (candidates-in-buffer)
3817 (get-line . buffer-substring)
3818 (action ("Copy Name" . (lambda (candidate)
3819 (kill-new (anything-c-colors-get-name candidate))))
3820 ("Copy RGB" . (lambda (candidate)
3821 (kill-new (anything-c-colors-get-rgb candidate))))
3822 ("Insert Name" . (lambda (candidate)
3823 (with-current-buffer anything-current-buffer
3824 (insert (anything-c-colors-get-name candidate)))))
3825 ("Insert RGB" . (lambda (candidate)
3826 (with-current-buffer anything-current-buffer
3827 (insert (anything-c-colors-get-rgb candidate))))))))
3828 ;; (anything 'anything-c-source-colors)
3830 (defun anything-c-colors-get-name (candidate)
3831 "Get color name."
3832 (replace-regexp-in-string
3833 " " ""
3834 (with-temp-buffer
3835 (insert (capitalize candidate))
3836 (goto-char (point-min))
3837 (search-forward-regexp "\\s-\\{2,\\}")
3838 (delete-region (point) (point-max))
3839 (buffer-string))))
3841 (defun anything-c-colors-get-rgb (candidate)
3842 "Get color RGB."
3843 (replace-regexp-in-string
3844 " " ""
3845 (with-temp-buffer
3846 (insert (capitalize candidate))
3847 (goto-char (point-max))
3848 (search-backward-regexp "\\s-\\{2,\\}")
3849 (delete-region (point) (point-min))
3850 (buffer-string))))
3852 ;;;; <Search Engine>
3853 ;;; Tracker desktop search
3854 (defvar anything-c-source-tracker-search
3855 '((name . "Tracker Search")
3856 (candidates . (lambda ()
3857 (start-process "tracker-search-process" nil
3858 "tracker-search"
3859 anything-pattern)))
3860 (type . file)
3861 (requires-pattern . 3)
3862 (delayed))
3863 "Source for retrieving files matching the current input pattern
3864 with the tracker desktop search.")
3865 ;; (anything 'anything-c-source-tracker-search)
3867 ;;; Spotlight (MacOS X desktop search)
3868 (defvar anything-c-source-mac-spotlight
3869 '((name . "mdfind")
3870 (candidates . (lambda ()
3871 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
3872 (type . file)
3873 (requires-pattern . 3)
3874 (delayed))
3875 "Source for retrieving files via Spotlight's command line
3876 utility mdfind.")
3877 ;; (anything 'anything-c-source-mac-spotlight)
3880 ;;;; <Kill ring>
3881 ;;; Kill ring
3882 (defvar anything-c-source-kill-ring
3883 '((name . "Kill Ring")
3884 (init . (lambda () (anything-attrset 'last-command last-command)))
3885 (candidates . anything-c-kill-ring-candidates)
3886 (action . anything-c-kill-ring-action)
3887 (last-command)
3888 (migemo)
3889 (multiline))
3890 "Source for browse and insert contents of kill-ring.")
3892 (defun anything-c-kill-ring-candidates ()
3893 (loop for kill in kill-ring
3894 unless (or (< (length kill) anything-kill-ring-threshold)
3895 (string-match "^[\\s\\t]+$" kill))
3896 collect kill))
3898 (defun anything-c-kill-ring-action (str)
3899 "Insert STR in `kill-ring' and set STR to the head.
3900 If this action is executed just after `yank', replace with STR as yanked string."
3901 (setq kill-ring (delete str kill-ring))
3902 (if (not (eq (anything-attr 'last-command) 'yank))
3903 (insert-for-yank str)
3904 ;; from `yank-pop'
3905 (let ((inhibit-read-only t)
3906 (before (< (point) (mark t))))
3907 (if before
3908 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
3909 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
3910 (setq yank-undo-function nil)
3911 (set-marker (mark-marker) (point) (current-buffer))
3912 (insert-for-yank str)
3913 ;; Set the window start back where it was in the yank command,
3914 ;; if possible.
3915 (set-window-start (selected-window) yank-window-start t)
3916 (if before
3917 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3918 ;; It is cleaner to avoid activation, even though the command
3919 ;; loop would deactivate the mark because we inserted text.
3920 (goto-char (prog1 (mark t)
3921 (set-marker (mark-marker) (point) (current-buffer)))))))
3922 (kill-new str))
3924 ;; (anything 'anything-c-source-kill-ring)
3926 ;;;; <Mark ring>
3927 ;; DO NOT include these sources in `anything-sources' use
3928 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
3929 ;; `anything-all-mark-rings' instead.
3931 (defun anything-c-source-mark-ring-candidates ()
3932 (flet ((get-marks (pos)
3933 (save-excursion
3934 (goto-char pos)
3935 (beginning-of-line)
3936 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3937 (when (string= "" line)
3938 (setq line "<EMPTY LINE>"))
3939 (format "%7d: %s" (line-number-at-pos) line)))))
3940 (with-current-buffer anything-current-buffer
3941 (loop
3942 with marks = (cons (mark-marker) mark-ring)
3943 with recip = nil
3944 for i in marks
3945 for m = (get-marks i)
3946 unless (member m recip)
3947 collect m into recip
3948 finally return recip))))
3950 (defvar anything-mark-ring-cache nil)
3951 (defvar anything-c-source-mark-ring
3952 '((name . "mark-ring")
3953 (init . (lambda ()
3954 (setq anything-mark-ring-cache
3955 (ignore-errors (anything-c-source-mark-ring-candidates)))))
3956 (candidates . (lambda ()
3957 (anything-aif anything-mark-ring-cache
3958 it)))
3959 (action . (("Goto line" . (lambda (candidate)
3960 (anything-goto-line (string-to-number candidate))))))
3961 (persistent-action . (lambda (candidate)
3962 (anything-goto-line (string-to-number candidate))
3963 (anything-match-line-color-current-line)))
3964 (persistent-help . "Show this line")))
3966 ;; (anything 'anything-c-source-mark-ring)
3968 ;;;###autoload
3969 (defun anything-mark-ring ()
3970 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3971 (interactive)
3972 (anything 'anything-c-source-mark-ring))
3974 ;;; Global-mark-ring
3975 (defvar anything-c-source-global-mark-ring
3976 '((name . "global-mark-ring")
3977 (candidates . anything-c-source-global-mark-ring-candidates)
3978 (action . (("Goto line" . (lambda (candidate)
3979 (let ((items (split-string candidate ":")))
3980 (switch-to-buffer (second items))
3981 (anything-goto-line (string-to-number (car items))))))))
3982 (persistent-action . (lambda (candidate)
3983 (let ((items (split-string candidate ":")))
3984 (switch-to-buffer (second items))
3985 (anything-goto-line (string-to-number (car items)))
3986 (anything-match-line-color-current-line))))
3987 (persistent-help . "Show this line")))
3989 (defun anything-c-source-global-mark-ring-candidates ()
3990 (flet ((buf-fn (m)
3991 (with-current-buffer (marker-buffer m)
3992 (goto-char m)
3993 (beginning-of-line)
3994 (let (line)
3995 (if (string= "" line)
3996 (setq line "<EMPTY LINE>")
3997 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3998 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
3999 (loop
4000 with marks = global-mark-ring
4001 with recip = nil
4002 for i in marks
4003 for gm = (unless (or (string-match
4004 "^ " (format "%s" (marker-buffer i)))
4005 (null (marker-buffer i)))
4006 (buf-fn i))
4007 when (and gm (not (member gm recip)))
4008 collect gm into recip
4009 finally return recip)))
4011 ;; (anything 'anything-c-source-global-mark-ring)
4013 ;;;###autoload
4014 (defun anything-global-mark-ring ()
4015 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4016 (interactive)
4017 (anything 'anything-c-source-global-mark-ring))
4019 ;;;###autoload
4020 (defun anything-all-mark-rings ()
4021 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4022 `anything-c-source-mark-ring'."
4023 (interactive)
4024 (anything '(anything-c-source-global-mark-ring
4025 anything-c-source-mark-ring)))
4027 ;;;; <Register>
4028 ;;; Insert from register
4029 (defvar anything-c-source-register
4030 '((name . "Registers")
4031 (candidates . anything-c-register-candidates)
4032 (action-transformer . anything-c-register-action-transformer)
4033 (multiline)
4034 (action))
4035 "See (info \"(emacs)Registers\")")
4037 (defun anything-c-register-candidates ()
4038 "Collecting register contents and appropriate commands."
4039 (loop for (char . val) in register-alist
4040 for key = (single-key-description char)
4041 for string-actions = (cond
4042 ((numberp val)
4043 (list (int-to-string val)
4044 'insert-register
4045 'increment-register))
4046 ((markerp val)
4047 (let ((buf (marker-buffer val)))
4048 (if (null buf)
4049 (list "a marker in no buffer")
4050 (list (concat
4051 "a buffer position:"
4052 (buffer-name buf)
4053 ", position "
4054 (int-to-string (marker-position val)))
4055 'jump-to-register
4056 'insert-register))))
4057 ((and (consp val) (window-configuration-p (car val)))
4058 (list "window configuration."
4059 'jump-to-register))
4060 ((and (consp val) (frame-configuration-p (car val)))
4061 (list "frame configuration."
4062 'jump-to-register))
4063 ((and (consp val) (eq (car val) 'file))
4064 (list (concat "file:"
4065 (prin1-to-string (cdr val))
4066 ".")
4067 'jump-to-register))
4068 ((and (consp val) (eq (car val) 'file-query))
4069 (list (concat "file:a file-query reference: file "
4070 (car (cdr val))
4071 ", position "
4072 (int-to-string (car (cdr (cdr val))))
4073 ".")
4074 'jump-to-register))
4075 ((consp val)
4076 (let ((lines (format "%4d" (length val))))
4077 (list (format "%s: %s\n" lines
4078 (truncate-string-to-width
4079 (mapconcat 'identity (list (car val))
4080 ;; (mapconcat (lambda (y) y) val
4081 "^J") (- (window-width) 15)))
4082 'insert-register)))
4083 ((stringp val)
4084 (list ;; without properties
4085 (substring-no-properties val)
4086 'insert-register
4087 'append-to-register
4088 'prepend-to-register))
4090 "GARBAGE!"))
4091 collect (cons (format "register %3s: %s" key (car string-actions))
4092 (cons char (cdr string-actions)))))
4094 (defun anything-c-register-action-transformer (actions register-and-functions)
4095 "Decide actions by the contents of register."
4096 (loop with func-actions =
4097 '((insert-register
4098 "Insert Register" .
4099 (lambda (c) (insert-register (car c))))
4100 (jump-to-register
4101 "Jump to Register" .
4102 (lambda (c) (jump-to-register (car c))))
4103 (append-to-register
4104 "Append Region to Register" .
4105 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
4106 (prepend-to-register
4107 "Prepend Region to Register" .
4108 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
4109 (increment-register
4110 "Increment Prefix Arg to Register" .
4111 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
4112 for func in (cdr register-and-functions)
4113 for cell = (assq func func-actions)
4114 when cell
4115 collect (cdr cell)))
4117 ;; (anything 'anything-c-source-register)
4119 ;;;; <Headline Extraction>
4120 (defvar anything-c-source-fixme
4121 '((name . "TODO/FIXME/DRY comments")
4122 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4123 (adjust)
4124 (recenter))
4125 "Show TODO/FIXME/DRY comments in current file.")
4126 ;; (anything 'anything-c-source-fixme)
4128 (defvar anything-c-source-rd-headline
4129 '((name . "RD HeadLine")
4130 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4131 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
4132 (migemo)
4133 (subexp . 1))
4134 "Show RD headlines.
4136 RD is Ruby's POD.
4137 http://en.wikipedia.org/wiki/Ruby_Document_format")
4138 ;; (anything 'anything-c-source-rd-headline)
4140 (defvar anything-c-source-oddmuse-headline
4141 '((name . "Oddmuse HeadLine")
4142 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4143 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4144 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
4145 (migemo)
4146 (subexp . 1))
4147 "Show Oddmuse headlines, such as EmacsWiki.")
4148 ;; (anything 'anything-c-source-oddmuse-headline)
4150 (defvar anything-c-source-emacs-source-defun
4151 '((name . "Emacs Source DEFUN")
4152 (headline . "DEFUN\\|DEFVAR")
4153 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
4154 "Show DEFUN/DEFVAR in Emacs C source file.")
4155 ;; (anything 'anything-c-source-emacs-source-defun)
4157 (defvar anything-c-source-emacs-lisp-expectations
4158 '((name . "Emacs Lisp Expectations")
4159 (headline . "(desc[ ]\\|(expectations")
4160 (condition . (eq major-mode 'emacs-lisp-mode)))
4161 "Show descriptions (desc) in Emacs Lisp Expectations.
4163 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4164 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4166 (defvar anything-c-source-emacs-lisp-toplevels
4167 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4168 (headline . "^(\\|(@\\*\\|^;;;;")
4169 (get-line . buffer-substring)
4170 (condition . (eq major-mode 'emacs-lisp-mode))
4171 (adjust))
4172 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4173 linkd.el is optional because linkd stars are extracted by regexp.
4174 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4175 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4177 (defvar anything-c-source-org-headline
4178 '((name . "Org HeadLine")
4179 (headline
4180 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4181 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4182 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4183 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4184 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4185 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4186 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4187 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4188 (condition . (eq major-mode 'org-mode))
4189 (migemo)
4190 (subexp . 1)
4191 (persistent-action . (lambda (elm)
4192 (anything-c-action-line-goto elm)
4193 (org-cycle)))
4194 (action-transformer
4195 . (lambda (actions candidate)
4196 '(("Go to Line" . anything-c-action-line-goto)
4197 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
4198 "Show Org headlines.
4199 org-mode is very very much extended text-mode/outline-mode.
4201 See (find-library \"org.el\")
4202 See http://orgmode.org for the latest version.")
4204 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4205 (insert
4206 (save-excursion
4207 (anything-goto-line (car lineno-and-content))
4208 (and (looking-at org-complex-heading-regexp)
4209 (org-make-link-string (concat "*" (match-string 4)))))))
4211 ;; (anything 'anything-c-source-org-headline)
4213 ;;; Anything yaoddmuse
4214 ;; Be sure to have yaoddmuse.el installed
4215 ;; install-elisp may be required if you want to install elisp file from here.
4216 (defvar anything-yaoddmuse-use-cache-file nil)
4217 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
4218 (defvar anything-c-yaoddmuse-ew-cache nil)
4219 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4220 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
4221 (candidates . (lambda ()
4222 (if anything-yaoddmuse-use-cache-file
4223 (ignore-errors
4224 (unless anything-c-yaoddmuse-ew-cache
4225 (load anything-c-yaoddmuse-cache-file)
4226 (setq anything-c-yaoddmuse-ew-cache
4227 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4228 anything-c-yaoddmuse-ew-cache)
4229 (yaoddmuse-update-pagename t)
4230 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
4231 (action . (("Edit page" . (lambda (candidate)
4232 (yaoddmuse-edit "EmacsWiki" candidate)))
4233 ("Browse page" . (lambda (candidate)
4234 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4235 ("Browse page other window" . (lambda (candidate)
4236 (if (one-window-p)
4237 (split-window-vertically))
4238 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4239 ("Browse diff" . (lambda (candidate)
4240 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
4241 ("Copy URL" . (lambda (candidate)
4242 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
4243 (message "Have copy page %s's URL to yank." candidate)))
4244 ("Create page" . (lambda (candidate)
4245 (yaoddmuse-edit "EmacsWiki" anything-input)))
4246 ("Update cache" . (lambda (candidate)
4247 (if anything-yaoddmuse-use-cache-file
4248 (progn
4249 (anything-yaoddmuse-cache-pages t)
4250 (setq anything-c-yaoddmuse-ew-cache
4251 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4252 (yaoddmuse-update-pagename))))))
4253 (action-transformer anything-c-yaoddmuse-action-transformer))
4254 "Needs yaoddmuse.el.
4256 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4258 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
4260 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
4261 '((name . "Yaoddmuse Post library (EmacsWiki)")
4262 (init . (anything-yaoddmuse-init))
4263 (candidates-in-buffer)
4264 (action . (("Post library and Browse" . (lambda (candidate)
4265 (yaoddmuse-post-file (find-library-name candidate)
4266 "EmacsWiki"
4267 (file-name-nondirectory (find-library-name candidate))
4268 nil t)))
4269 ("Post library" . (lambda (candidate)
4270 (yaoddmuse-post-file (find-library-name candidate)
4271 "EmacsWiki"
4272 (file-name-nondirectory (find-library-name candidate))))))))
4273 "Needs yaoddmuse.el.
4275 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4277 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
4279 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
4280 "Allow the use of `install-elisp' only on elisp files."
4281 (if (string-match "\.el$" candidate)
4282 (append actions '(("Install Elisp" . (lambda (elm)
4283 (install-elisp-from-emacswiki elm)))))
4284 actions))
4286 ;;;###autoload
4287 (defun anything-yaoddmuse-cache-pages (&optional load)
4288 "Fetch the list of files on emacswiki and create cache file.
4289 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
4290 (interactive)
4291 (yaoddmuse-update-pagename)
4292 (save-excursion
4293 (find-file anything-c-yaoddmuse-cache-file)
4294 (erase-buffer)
4295 (insert "(puthash \"EmacsWiki\" '(")
4296 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
4298 (insert (concat "(\"" (car i) "\") ")))
4299 (insert ") yaoddmuse-pages-hash)\n")
4300 (save-buffer)
4301 (kill-buffer (current-buffer))
4302 (when (or current-prefix-arg
4303 load)
4304 (load anything-c-yaoddmuse-cache-file))))
4306 ;;;###autoload
4307 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
4308 "Preconfigured `anything' to edit or view EmacsWiki page.
4310 Needs yaoddmuse.el.
4312 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4313 (interactive)
4314 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
4316 ;;;###autoload
4317 (defun anything-yaoddmuse-emacswiki-post-library ()
4318 "Preconfigured `anything' to post library to EmacsWiki.
4320 Needs yaoddmuse.el.
4322 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4323 (interactive)
4324 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
4326 (defun anything-yaoddmuse-init ()
4327 "Init anything buffer status."
4328 (let ((anything-buffer (anything-candidate-buffer 'global))
4329 (library-list (yaoddmuse-get-library-list)))
4330 (with-current-buffer anything-buffer
4331 ;; Insert library name.
4332 (dolist (library library-list)
4333 (insert (format "%s\n" library)))
4334 ;; Sort lines.
4335 (sort-lines nil (point-min) (point-max)))))
4337 ;;; Eev anchors
4338 (defvar anything-c-source-eev-anchor
4339 '((name . "Anchors")
4340 (candidates
4341 . (lambda ()
4342 (ignore-errors
4343 (with-current-buffer anything-current-buffer
4344 (loop initially (goto-char (point-min))
4345 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
4346 for anchor = (match-string-no-properties 1)
4347 collect (cons (format "%5d:%s"
4348 (line-number-at-pos (match-beginning 0))
4349 (format ee-anchor-format anchor)) anchor))))))
4350 (persistent-action . (lambda (item)
4351 (ee-to item)
4352 (anything-match-line-color-current-line)))
4353 (persistent-help . "Show this entry")
4354 (action . (("Goto link" . ee-to)))))
4355 ;; (anything 'anything-c-source-eev-anchor)
4357 ;;;; <Misc>
4358 ;;; Org keywords
4359 (defvar anything-c-source-org-keywords
4360 '((name . "Org Keywords")
4361 (init . anything-c-org-keywords-init)
4362 (candidates . anything-c-org-keywords-candidates)
4363 (action . anything-c-org-keywords-insert)
4364 (persistent-action . anything-c-org-keywords-show-help)
4365 (persistent-help . "Show an example and info page to describe this keyword.")
4366 (keywords-examples)
4367 (keywords)))
4368 ;; (anything 'anything-c-source-org-keywords)
4369 (defvar anything-c-org-keywords-info-location
4370 '(("#+TITLE:" . "(org)Export options")
4371 ("#+AUTHOR:" . "(org)Export options")
4372 ("#+DATE:" . "(org)Export options")
4373 ("#+EMAIL:" . "(org)Export options")
4374 ("#+DESCRIPTION:" . "(org)Export options")
4375 ("#+KEYWORDS:" . "(org)Export options")
4376 ("#+LANGUAGE:" . "(org)Export options")
4377 ("#+TEXT:" . "(org)Export options")
4378 ("#+TEXT:" . "(org)Export options")
4379 ("#+OPTIONS:" . "(org)Export options")
4380 ("#+BIND:" . "(org)Export options")
4381 ("#+LINK_UP:" . "(org)Export options")
4382 ("#+LINK_HOME:" . "(org)Export options")
4383 ("#+LATEX_HEADER:" . "(org)Export options")
4384 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
4385 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
4386 ("#+INFOJS_OPT" . "(org)Javascript support")
4387 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
4388 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
4389 ("#+ORGTBL" . "(org)Radio tables")
4390 ("#+HTML:" . "(org)Quoting HTML tags")
4391 ("#+LaTeX:" . "(org)Quoting LaTeX code")
4392 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
4393 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
4394 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
4395 ("#+BEGIN_VERSE" . "(org)Paragraphs")
4396 ("#+BEGIN_SRC" . "(org)Literal examples")
4397 ("#+CAPTION" . "(org)Tables in HTML export")
4398 ("#+LABEL" . "(org)Tables in LaTeX export")
4399 ("#+ATTR_HTML" . "(org)Links")
4400 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
4402 (defun anything-c-org-keywords-init ()
4403 (unless (anything-attr 'keywords-examples)
4404 (require 'org)
4405 (anything-attrset 'keywords-examples
4406 (append
4407 (mapcar
4408 (lambda (x)
4409 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
4410 (cons (match-string 2 x) (match-string 1 x)))
4411 (org-split-string (org-get-current-options) "\n"))
4412 (mapcar 'list org-additional-option-like-keywords)))
4413 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
4415 (defun anything-c-org-keywords-candidates ()
4416 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
4417 (anything-attr 'keywords)))
4419 (defun anything-c-org-keywords-insert (keyword)
4420 (cond ((string-match "BEGIN" keyword)
4421 (insert "#+" keyword " ")
4422 (save-excursion
4423 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
4425 (insert "#+" keyword " "))))
4427 (defun anything-c-org-keywords-show-help (keyword)
4428 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
4429 "(org)In-buffer settings"))
4430 (search-forward (concat "#+" keyword) nil t)
4431 (anything-persistent-highlight-point)
4432 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
4435 ;;; Picklist
4436 (defvar anything-c-source-picklist
4437 '((name . "Picklist")
4438 (candidates . (lambda () (mapcar 'car picklist-list)))
4439 (type . file)))
4440 ;; (anything 'anything-c-source-picklist)
4442 ;;; BBDB
4443 (defvar bbdb-records)
4444 (defvar bbdb-buffer-name)
4445 (declare-function bbdb "ext:bbdb-com")
4446 (declare-function bbdb-current-record "ext:bbdb-com")
4447 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
4448 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
4449 (declare-function bbdb-current-record "ext:bbdb-com")
4450 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
4451 (declare-function bbdb-records "ext:bbdb-com"
4452 (&optional dont-check-disk already-in-db-buffer))
4454 (defun anything-c-bbdb-candidates ()
4455 "Return a list of all names in the bbdb database. The format
4456 is \"Firstname Lastname\"."
4457 (mapcar (lambda (bbdb-record)
4458 (replace-regexp-in-string
4459 "\\s-+$" ""
4460 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
4461 (bbdb-records)))
4463 (defun anything-c-bbdb-create-contact (actions candidate)
4464 "Action transformer that returns only an entry to add the
4465 current `anything-pattern' as new contact. All other actions are
4466 removed."
4467 (if (string= candidate "*Add to contacts*")
4468 '(("Add to contacts" . (lambda (actions)
4469 (bbdb-create-internal
4470 (read-from-minibuffer "Name: " anything-c-bbdb-name)
4471 (read-from-minibuffer "Company: ")
4472 (read-from-minibuffer "Email: ")
4475 (read-from-minibuffer "Note: ")))))
4476 actions))
4478 (defun anything-c-bbdb-get-record (candidate)
4479 "Return record that match CANDIDATE."
4480 (bbdb candidate nil)
4481 (set-buffer "*BBDB*")
4482 (bbdb-current-record))
4484 (defvar anything-c-bbdb-name nil
4485 "Only for internal use.")
4487 (defvar anything-c-source-bbdb
4488 '((name . "BBDB")
4489 (candidates . anything-c-bbdb-candidates)
4490 (action ("Send a mail" . anything-c-bbdb-compose-mail)
4491 ("View person's data" . anything-c-bbdb-view-person-action))
4492 (filtered-candidate-transformer . (lambda (candidates source)
4493 (setq anything-c-bbdb-name anything-pattern)
4494 (if (not candidates)
4495 (list "*Add to contacts*")
4496 candidates)))
4497 (action-transformer . (lambda (actions candidate)
4498 (anything-c-bbdb-create-contact actions candidate))))
4499 "Needs BBDB.
4501 http://bbdb.sourceforge.net/")
4502 ;; (anything 'anything-c-source-bbdb)
4504 (defun anything-c-bbdb-view-person-action (candidate)
4505 "View BBDB data of single CANDIDATE or marked candidates."
4506 (anything-aif (anything-marked-candidates)
4507 (let ((bbdb-append-records (length it)))
4508 (dolist (i it)
4509 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
4510 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
4512 (defun anything-c-bbdb-collect-mail-addresses ()
4513 "Return a list of all mail addresses of records in bbdb buffer."
4514 (with-current-buffer bbdb-buffer-name
4515 (loop for i in bbdb-records
4516 if (bbdb-record-net (car i))
4517 collect (bbdb-dwim-net-address (car i)))))
4519 (defun anything-c-bbdb-compose-mail (candidate)
4520 "Compose a mail with all records of bbdb buffer."
4521 (anything-c-bbdb-view-person-action candidate)
4522 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4523 (address-str (mapconcat 'identity address-list ",\n ")))
4524 (compose-mail address-str)))
4526 ;;; Evaluation Result
4527 (defvar anything-c-source-evaluation-result
4528 '((name . "Evaluation Result")
4529 (disable-shortcuts)
4530 (dummy)
4531 (filtered-candidate-transformer . (lambda (candidates source)
4532 (list
4533 (condition-case nil
4534 (with-current-buffer anything-current-buffer
4535 (pp-to-string
4536 (eval (read anything-pattern))))
4537 (error "Error")))))
4538 (action ("Copy result to kill-ring" . (lambda (candidate)
4539 (with-current-buffer anything-buffer
4540 (let ((end (save-excursion
4541 (goto-char (point-max))
4542 (search-backward "\n")
4543 (point))))
4544 (kill-region (point) end))))))))
4545 ;; (anything 'anything-c-source-evaluation-result)
4547 ;;;###autoload
4548 (defun anything-eval-expression (arg)
4549 "Preconfigured anything for `anything-c-source-evaluation-result'."
4550 (interactive "P")
4551 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
4552 nil nil nil "*anything eval*"))
4554 ;;;###autoload
4555 (defun anything-eval-expression-with-eldoc ()
4556 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
4557 (interactive)
4558 (if (window-system)
4559 (let ((timer (run-with-idle-timer eldoc-idle-delay
4560 'repeat 'anything-eldoc-show-in-eval)))
4561 (unwind-protect
4562 (call-interactively 'anything-eval-expression)
4563 (cancel-timer timer)))
4564 (call-interactively 'anything-eval-expression)))
4566 (defun anything-eldoc-show-in-eval ()
4567 "Return eldoc in a tooltip for current minibuffer input."
4568 (let* ((str-all (minibuffer-completion-contents))
4569 (sym (when str-all
4570 (with-temp-buffer
4571 (insert str-all)
4572 (goto-char (point-max))
4573 (unless (looking-back ")\\|\"") (forward-char -1))
4574 (eldoc-current-symbol))))
4575 (doc (or (eldoc-get-var-docstring sym)
4576 (eldoc-get-fnsym-args-string
4577 (car (eldoc-fnsym-in-current-sexp))))))
4578 (when doc (tooltip-show doc))))
4580 ;;; Calculation Result
4581 (defvar anything-c-source-calculation-result
4582 '((name . "Calculation Result")
4583 (dummy)
4584 (filtered-candidate-transformer . (lambda (candidates source)
4585 (list
4586 (condition-case nil
4587 (calc-eval anything-pattern)
4588 (error "error")))))
4589 (action ("Copy result to kill-ring" . kill-new))))
4590 ;; (anything 'anything-c-source-calculation-result)
4592 ;;; Google Suggestions
4593 (defvar anything-gg-sug-lgh-flag 0)
4594 (defun anything-c-google-suggest-fetch (input)
4595 "Fetch suggestions for INPUT from XML buffer.
4596 Return an alist with elements like (data . number_results)."
4597 (let ((request (concat anything-c-google-suggest-url
4598 (url-hexify-string input))))
4599 (flet ((fetch ()
4600 (loop
4601 with result-alist = (xml-get-children
4602 (car (xml-parse-region (point-min) (point-max)))
4603 'CompleteSuggestion)
4604 for i in result-alist
4605 for data = (cdr (caadr (assoc 'suggestion i)))
4606 for nqueries = (cdr (caadr (assoc 'num_queries i)))
4607 for ldata = (length data)
4609 (when (> ldata anything-gg-sug-lgh-flag)
4610 (setq anything-gg-sug-lgh-flag ldata))
4611 collect (cons data nqueries) into cont
4612 finally return cont)))
4613 (if anything-google-suggest-use-curl-p
4614 (with-temp-buffer
4615 (call-process "curl" nil t nil request)
4616 (fetch))
4617 (with-current-buffer
4618 (url-retrieve-synchronously request)
4619 (fetch))))))
4622 (defun anything-c-google-suggest-set-candidates ()
4623 "Set candidates with result and number of google results found."
4624 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
4625 (setq suggestions (loop for i in suggestions
4626 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
4627 for elm = (concat (car i)
4628 (make-string (+ 2 interval) ? )
4629 "(" (cdr i) " results)")
4630 collect (cons elm (car i))))
4631 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
4632 suggestions
4633 ;; if there is no suggestion exactly matching the input then
4634 ;; prepend a Search on Google item to the list
4635 (append
4636 suggestions
4637 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
4638 anything-input))))))
4641 (defun anything-c-google-suggest-action (candidate)
4642 "Default action to jump to a google suggested candidate."
4643 (anything-c-browse-url (concat anything-c-google-suggest-search-url
4644 (url-hexify-string candidate))))
4647 (defvar anything-c-source-google-suggest
4648 '((name . "Google Suggest")
4649 (candidates . anything-c-google-suggest-set-candidates)
4650 (action . (("Google Search" . anything-c-google-suggest-action)))
4651 (volatile)
4652 (requires-pattern . 3)
4653 (delayed)))
4655 ;; (anything 'anything-c-source-google-suggest)
4657 ;;; Yahoo suggestions
4659 (defun anything-c-yahoo-suggest-fetch (input)
4660 "Fetch Yahoo suggestions for INPUT from XML buffer.
4661 Return an alist with elements like (data . number_results)."
4662 (let ((request (concat anything-c-yahoo-suggest-url
4663 (url-hexify-string input))))
4664 (flet ((fetch ()
4665 (loop
4666 with result-alist = (xml-get-children
4667 (car (xml-parse-region (point-min) (point-max)))
4668 'Result)
4669 for i in result-alist
4670 collect (caddr i))))
4671 (with-current-buffer
4672 (url-retrieve-synchronously request)
4673 (fetch)))))
4675 (defun anything-c-yahoo-suggest-set-candidates ()
4676 "Set candidates with Yahoo results found."
4677 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
4678 (or suggestions
4679 (append
4680 suggestions
4681 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
4682 anything-input))))))
4684 (defun anything-c-yahoo-suggest-action (candidate)
4685 "Default action to jump to a Yahoo suggested candidate."
4686 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
4687 (url-hexify-string candidate))))
4689 (defvar anything-c-source-yahoo-suggest
4690 '((name . "Yahoo Suggest")
4691 (candidates . anything-c-yahoo-suggest-set-candidates)
4692 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
4693 (volatile)
4694 (requires-pattern . 3)
4695 (delayed)))
4697 ;; (anything 'anything-c-source-yahoo-suggest)
4699 ;;; Surfraw
4700 ;;; Need external program surfraw.
4701 ;;; http://surfraw.alioth.debian.org/
4702 ;; user variables
4703 (require 'browse-url)
4704 (defvar w3m-command nil)
4705 (defvar anything-c-home-url "http://www.google.fr"
4706 "*Default url to use as home url.")
4708 (defvar anything-browse-url-default-browser-alist
4709 `((,w3m-command . w3m-browse-url)
4710 (,browse-url-firefox-program . browse-url-firefox)
4711 (,browse-url-kde-program . browse-url-kde)
4712 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
4713 (,browse-url-mozilla-program . browse-url-mozilla)
4714 (,browse-url-galeon-program . browse-url-galeon)
4715 (,browse-url-netscape-program . browse-url-netscape)
4716 (,browse-url-mosaic-program . browse-url-mosaic)
4717 (,browse-url-xterm-program . browse-url-text-xterm))
4718 "*Alist of (executable . function) to try to find a suitable url browser.")
4720 (defun anything-browse-url-default-browser (url &rest args)
4721 "Find a suitable browser and ask it to load URL."
4722 (let ((default-browser (loop
4723 for i in anything-browse-url-default-browser-alist
4724 when (and (car i) (executable-find (car i))) return (cdr i))))
4725 (if default-browser
4726 (apply default-browser url args)
4727 (error "No usable browser found"))))
4729 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
4730 "Default command to browse URL."
4731 (if browse-url-browser-function
4732 (browse-url url)
4733 (anything-browse-url-default-browser url)))
4735 (defun anything-c-build-elvi-list ()
4736 "Return list of all engines and descriptions handled by surfraw."
4737 (cdr
4738 (with-temp-buffer
4739 (call-process "surfraw" nil t nil
4740 "-elvi")
4741 (split-string (buffer-string) "\n"))))
4743 ;;;###autoload
4744 (defun anything-surfraw (pattern engine)
4745 "Preconfigured `anything' to search PATTERN with search ENGINE."
4746 (interactive (list (read-string "SearchFor: ")
4747 (anything-comp-read
4748 "Engine: "
4749 (anything-c-build-elvi-list)
4750 :must-match t)))
4751 (let* ((engine-nodesc (car (split-string engine)))
4752 (url (with-temp-buffer
4753 (apply 'call-process "surfraw" nil t nil
4754 (list engine-nodesc "-p" pattern))
4755 (replace-regexp-in-string
4756 "\n" "" (buffer-string)))))
4757 (if (string= engine-nodesc "W")
4758 (anything-c-browse-url)
4759 (anything-c-browse-url url))))
4761 ;;; Emms
4763 ;;;###autoload
4764 (defun anything-emms-stream-edit-bookmark (elm)
4765 "Change the information of current emms-stream bookmark from anything."
4766 (interactive)
4767 (let* ((cur-buf anything-current-buffer)
4768 (bookmark (assoc elm emms-stream-list))
4769 (name (read-from-minibuffer "Description: "
4770 (nth 0 bookmark)))
4771 (url (read-from-minibuffer "URL: "
4772 (nth 1 bookmark)))
4773 (fd (read-from-minibuffer "Feed Descriptor: "
4774 (int-to-string (nth 2 bookmark))))
4775 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4776 (format "%s" (car (last bookmark))))))
4777 (save-excursion
4778 (emms-streams)
4779 (when (re-search-forward (concat "^" name) nil t)
4780 (beginning-of-line)
4781 (emms-stream-delete-bookmark)
4782 (emms-stream-add-bookmark name url (string-to-number fd) type)
4783 (emms-stream-save-bookmarks-file)
4784 (emms-stream-quit)
4785 (switch-to-buffer cur-buf)))))
4787 (defun anything-emms-stream-delete-bookmark (elm)
4788 "Delete an emms-stream bookmark from anything."
4789 (interactive)
4790 (let* ((cur-buf anything-current-buffer)
4791 (bookmark (assoc elm emms-stream-list))
4792 (name (nth 0 bookmark)))
4793 (save-excursion
4794 (emms-streams)
4795 (when (re-search-forward (concat "^" name) nil t)
4796 (beginning-of-line)
4797 (emms-stream-delete-bookmark)
4798 (emms-stream-save-bookmarks-file)
4799 (emms-stream-quit)
4800 (switch-to-buffer cur-buf)))))
4802 (defvar anything-c-source-emms-streams
4803 '((name . "Emms Streams")
4804 (init . (lambda ()
4805 (emms-stream-init)))
4806 (candidates . (lambda ()
4807 (mapcar 'car emms-stream-list)))
4808 (action . (("Play" . (lambda (elm)
4809 (let* ((stream (assoc elm emms-stream-list))
4810 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
4811 (url (second stream)))
4812 (funcall fn url))))
4813 ("Delete" . anything-emms-stream-delete-bookmark)
4814 ("Edit" . anything-emms-stream-edit-bookmark)))
4815 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4816 ;; (anything 'anything-c-source-emms-streams)
4818 ;; Don't forget to set `emms-source-file-default-directory'
4819 (defvar anything-c-source-emms-dired
4820 '((name . "Music Directory")
4821 (candidates . (lambda ()
4822 (cddr (directory-files emms-source-file-default-directory))))
4823 (action .
4824 (("Play Directory" . (lambda (item)
4825 (emms-play-directory
4826 (expand-file-name
4827 item
4828 emms-source-file-default-directory))))
4829 ("Open dired in file's directory" . (lambda (item)
4830 (anything-c-open-dired
4831 (expand-file-name
4832 item
4833 emms-source-file-default-directory))))))
4834 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4835 ;; (anything 'anything-c-source-emms-dired)
4837 (defface anything-emms-playlist
4838 '((t (:foreground "Springgreen4" :underline t)))
4839 "*Face used for tracks in current emms playlist."
4840 :group 'anything)
4842 (defun anything-c-emms-files-modifier (candidates)
4843 (let ((current-playlist (with-current-emms-playlist
4844 (loop
4845 with cur-list = (emms-playlist-tracks-in-region
4846 (point-min) (point-max))
4847 for i in cur-list
4848 collect (assoc-default 'info-file i)))))
4849 (loop for i in candidates
4850 if (member i current-playlist)
4851 collect (propertize i 'face 'anything-emms-playlist) into lis
4852 else collect i into lis finally return lis)))
4854 (defun anything-c-emms-play-current-playlist ()
4855 "Play current playlist."
4856 (with-current-emms-playlist
4857 (emms-playlist-first)
4858 (emms-playlist-mode-play-smart)))
4860 (defvar anything-c-source-emms-files
4861 '((name . "Emms files")
4862 (candidates . (lambda ()
4863 (loop for v being the hash-values in emms-cache-db
4864 for name = (assoc-default 'name v)
4865 unless (string-match "^http:" name) collect name)))
4866 (candidate-transformer . anything-c-emms-files-modifier)
4867 (action . (("Play file" . emms-play-file)
4868 ("Add to Playlist and play"
4869 . (lambda (candidate)
4870 (emms-playlist-new)
4871 (dolist (i (anything-marked-candidates))
4872 (emms-add-playlist-file i))
4873 (unless emms-player-playing-p
4874 (anything-c-emms-play-current-playlist))))))))
4876 ;; (anything 'anything-c-source-emms-files)
4878 ;;; Jabber Contacts (jabber.el)
4879 (defun anything-c-jabber-online-contacts ()
4880 "List online Jabber contacts."
4881 (with-no-warnings
4882 (let (jids)
4883 (dolist (item (jabber-concat-rosters) jids)
4884 (when (get item 'connected)
4885 (push (if (get item 'name)
4886 (cons (get item 'name) item)
4887 (cons (symbol-name item) item)) jids))))))
4889 (defvar anything-c-source-jabber-contacts
4890 '((name . "Jabber Contacts")
4891 (init . (lambda () (require 'jabber)))
4892 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
4893 (action . (lambda (x)
4894 (jabber-chat-with
4895 (jabber-read-account)
4896 (symbol-name
4897 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
4898 ;; (anything 'anything-c-source-jabber-contacts)
4901 ;;; Call source.
4902 (defvar anything-source-select-buffer "*anything source select*")
4903 (defvar anything-c-source-call-source
4904 `((name . "Call anything source")
4905 (candidate-number-limit)
4906 (candidates . (lambda ()
4907 (loop for vname in (all-completions "anything-c-source-" obarray)
4908 for var = (intern vname)
4909 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
4910 if name collect (cons (format "%s `%s'"
4911 name (propertize vname 'face 'font-lock-variable-name-face))
4912 var))))
4913 (action . (("Invoke anything with selected source" .
4914 (lambda (candidate)
4915 (setq anything-candidate-number-limit 9999)
4916 (anything candidate nil nil nil nil
4917 anything-source-select-buffer)))
4918 ("Describe variable" . describe-variable)
4919 ("Find variable" . find-variable)))
4920 (persistent-action . describe-variable)
4921 (persistent-help . "Show description of this source")))
4922 ;; (anything 'anything-c-source-call-source)
4924 ;;;###autoload
4925 (defun anything-call-source ()
4926 "Preconfigured `anything' to call anything source."
4927 (interactive)
4928 (anything 'anything-c-source-call-source nil nil nil nil
4929 anything-source-select-buffer))
4931 (defun anything-call-source-from-anything ()
4932 "Call anything source within `anything' session."
4933 (interactive)
4934 (setq anything-input-idle-delay 0)
4935 (anything-set-sources '(anything-c-source-call-source)))
4937 ;;; Execute Preconfigured anything.
4938 (defvar anything-c-source-anything-commands
4939 '((name . "Preconfigured Anything")
4940 (candidates . anything-c-anything-commands-candidates)
4941 (type . command)
4942 (candidate-number-limit)))
4943 ;; (anything 'anything-c-source-anything-commands)
4945 (defun anything-c-anything-commands-candidates ()
4946 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
4947 collect (cons (if (where-is-internal cmd nil t)
4948 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
4949 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
4950 cmd)))
4952 ;;;###autoload
4953 (defun anything-execute-anything-command ()
4954 "Preconfigured `anything' to execute preconfigured `anything'."
4955 (interactive)
4956 (anything-other-buffer 'anything-c-source-anything-commands
4957 "*anything commands*"))
4959 ;; Occur
4961 (defun anything-c-occur-goto-line (candidate)
4962 "Goto line action for anything-c-source-occur."
4963 (anything-goto-line (string-to-number candidate)))
4965 (defun anything-c-occur-persistent-action (candidate)
4966 "Persistent action for anything occur source."
4967 (anything-c-occur-goto-line candidate)
4968 (anything-match-line-color-current-line))
4970 (defun anything-c-get-occur-candidates ()
4971 "Get `anything-c-source-occur' candidates."
4972 (with-temp-buffer
4973 (let ((count (occur-engine
4974 anything-pattern
4975 (list anything-current-buffer) (current-buffer)
4976 list-matching-lines-default-context-lines nil
4977 list-matching-lines-buffer-name-face
4978 nil list-matching-lines-face
4979 (not (eq occur-excluded-properties t)))))
4980 (when (> count 0)
4981 (cdr (split-string (buffer-string) "\n" t))))))
4983 (defvar anything-c-source-occur
4984 '((name . "Occur")
4985 (candidates . anything-c-get-occur-candidates)
4986 (persistent-action . anything-c-occur-persistent-action)
4987 (persistent-help . "Goto Line")
4988 (action . anything-c-occur-goto-line)
4989 (requires-pattern . 1)
4990 (delayed)
4991 (volatile)))
4992 ;; (anything 'anything-c-source-occur)
4994 ;;;###autoload
4995 (defun anything-occur ()
4996 "Preconfigured Anything for Occur source."
4997 (interactive)
4998 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*"))
5000 ;; Do many actions for input
5001 (defvar anything-c-source-create
5002 '((name . "Create")
5003 (dummy)
5004 (action)
5005 (action-transformer . anything-create--actions))
5006 "Do many create actions from `anything-pattern'.
5007 See also `anything-create--actions'.")
5008 ;; (anything 'anything-c-source-create)
5010 (defun anything-create-from-anything ()
5011 "Run `anything-create' from `anything' as a fallback."
5012 (interactive)
5013 (anything-run-after-quit 'anything-create nil anything-pattern))
5015 ;;;###autoload
5016 (defun anything-create (&optional string initial-input)
5017 "Preconfigured `anything' to do many create actions from STRING.
5018 See also `anything-create--actions'."
5019 (interactive)
5020 (setq string (or string (read-string "Create Anything: " initial-input)))
5021 (anything '(((name . "Anything Create")
5022 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
5023 (candidates . anything-create--actions)
5024 (candidate-number-limit)
5025 (action . (lambda (func) (funcall func string)))))))
5027 (defun anything-create--actions (&rest ignored)
5028 "Default actions for `anything-create' / `anything-c-source-create'."
5029 (remove-if-not
5030 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
5031 (append anything-create--actions-private
5032 '(("find-file" . find-file)
5033 ("find-file other window" . find-file-other-window)
5034 ("New buffer" . switch-to-buffer)
5035 ("New buffer other window" . switch-to-buffer-other-window)
5036 ("Bookmark Set" . bookmark-set)
5037 ("Set Register" .
5038 (lambda (x) (set-register (read-char "Register: ") x)))
5039 ("Insert Linkd star" . linkd-insert-star)
5040 ("Insert Linkd Tag" . linkd-insert-tag)
5041 ("Insert Linkd Link" . linkd-insert-link)
5042 ("Insert Linkd Lisp" . linkd-insert-lisp)
5043 ("Insert Linkd Wiki" . linkd-insert-wiki)
5044 ("Google Search" . google)))))
5046 ;; Minibuffer History
5047 (defvar anything-c-source-minibuffer-history
5048 '((name . "Minibuffer History")
5049 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
5050 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
5051 (if (consp (car history))
5052 (mapcar 'prin1-to-string history)
5053 history))))
5054 (migemo)
5055 (action . insert)))
5056 ;; (anything 'anything-c-source-minibuffer-history)
5058 ;; elscreen
5059 (defvar anything-c-source-elscreen
5060 '((name . "Elscreen")
5061 (candidates . (lambda ()
5062 (if (cdr (elscreen-get-screen-to-name-alist))
5063 (sort
5064 (loop for sname in (elscreen-get-screen-to-name-alist)
5065 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
5066 finally (return lst))
5067 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
5068 (action . (("Change Screen".
5069 (lambda (candidate)
5070 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
5071 ("Kill Screen(s)".
5072 (lambda (candidate)
5073 (dolist (i (anything-marked-candidates))
5074 (elscreen-goto (- (aref i 1) (aref "0" 0)))
5075 (elscreen-kill))))
5076 ("Only Screen".
5077 (lambda (candidate)
5078 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
5079 (elscreen-kill-others)))))))
5080 ;; (anything 'anything-c-source-elscreen)
5082 ;;;; <System>
5084 ;;; Top (process)
5085 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
5086 "Top command (batch mode). %s is replaced with `frame-width'.")
5087 (defvar anything-c-source-top
5088 '((name . "Top (Press C-c C-u to refresh)")
5089 (init . anything-c-top-init)
5090 (candidates-in-buffer)
5091 (display-to-real . anything-c-top-display-to-real)
5092 (update . anything-c-top-update)
5093 (action
5094 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
5095 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
5096 ("Copy PID" . (lambda (pid) (kill-new pid))))))
5097 ;; (anything 'anything-c-source-top)
5099 (defun anything-c-top-sh (cmd)
5100 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
5102 (defun anything-c-top-init ()
5103 (with-current-buffer (anything-candidate-buffer 'global)
5104 (call-process-shell-command
5105 (format anything-c-top-command
5106 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
5107 nil (current-buffer))))
5109 (defun anything-c-top-display-to-real (line)
5110 (car (split-string line)))
5112 (defun anything-c-top-update ()
5113 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
5114 (anything-c-top-init)))
5116 ;;;###autoload
5117 (defun anything-top ()
5118 "Preconfigured `anything' for top command."
5119 (interactive)
5120 (let ((anything-samewindow t)
5121 (anything-enable-shortcuts)
5122 (anything-display-function 'anything-default-display-buffer)
5123 (anything-candidate-number-limit 9999))
5124 (save-window-excursion
5125 (delete-other-windows)
5126 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
5128 ;;; Timers
5129 (defvar anything-c-source-absolute-time-timers
5130 '((name . "Absolute Time Timers")
5131 (candidates . timer-list)
5132 (type . timer)))
5133 ;; (anything 'anything-c-source-absolute-time-timers)
5135 (defvar anything-c-source-idle-time-timers
5136 '((name . "Idle Time Timers")
5137 (candidates . timer-idle-list)
5138 (type . timer)))
5139 ;; (anything 'anything-c-source-idle-time-timers)
5141 (defun anything-c-timer-real-to-display (timer)
5142 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
5143 (append timer nil) ;use `append' to convert vector->list
5144 (format "%s repeat=%5S %s(%s)"
5145 (let ((time (list t1 t2 t3)))
5146 (if idle-delay
5147 (format-time-string "idle-for=%5s" time)
5148 (format-time-string "%m/%d %T" time)))
5149 repeat-delay
5150 func
5151 (mapconcat 'prin1-to-string args " "))))
5153 ;;; X RandR resolution change
5154 ;;; FIXME I do not care multi-display.
5155 (defvar anything-c-xrandr-output "VGA")
5156 (defvar anything-c-xrandr-screen "0")
5157 (defvar anything-c-source-xrandr-change-resolution
5158 '((name . "Change Resolution")
5159 (candidates
5160 . (lambda ()
5161 (with-temp-buffer
5162 (call-process "xrandr" nil (current-buffer) nil
5163 "--screen" anything-c-xrandr-screen "-q")
5164 (goto-char 1)
5165 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
5166 collect (match-string 1)))))
5167 (action
5168 ("Change Resolution" . (lambda (mode)
5169 (call-process "xrandr" nil nil nil
5170 "--screen" anything-c-xrandr-screen
5171 "--output" anything-c-xrandr-output
5172 "--mode" mode))))))
5173 ;; (anything 'anything-c-source-xrandr-change-resolution)
5175 ;;; Xfont selection
5176 (defun anything-c-persistent-xfont-action (elm)
5177 "Show current font temporarily"
5178 (let ((current-font (cdr (assoc 'font (frame-parameters))))
5179 (default-font elm))
5180 (unwind-protect
5181 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
5182 (set-frame-font current-font))))
5184 (defvar anything-c-xfonts-cache nil)
5185 (defvar anything-c-source-xfonts
5186 '((name . "X Fonts")
5187 (init . (lambda ()
5188 (unless anything-c-xfonts-cache
5189 (setq anything-c-xfonts-cache
5190 (x-list-fonts "*")))))
5191 (candidates . anything-c-xfonts-cache)
5192 (action . (("Copy to kill ring" . (lambda (elm)
5193 (kill-new elm)))
5194 ("Set Font" . (lambda (elm)
5195 (kill-new elm)
5196 (set-frame-font elm 'keep-size)
5197 (message "New font have been copied to kill ring")))))
5198 (persistent-action . anything-c-persistent-xfont-action)
5199 (persistent-help . "Switch to this font temporarily")))
5201 ;;;###autoload
5202 (defun anything-select-xfont ()
5203 "Preconfigured `anything' to select Xfont."
5204 (interactive)
5205 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
5207 ;; (anything 'anything-c-source-xfonts)
5209 ;;; Source for Debian/Ubuntu users
5210 (defvar anything-c-source-apt
5211 '((name . "APT")
5212 (init . anything-c-apt-init)
5213 (candidates-in-buffer)
5214 (candidate-transformer anything-c-apt-candidate-transformer)
5215 (display-to-real . anything-c-apt-display-to-real)
5216 (candidate-number-limit . 9999)
5217 (action
5218 ("Show package description" . anything-c-apt-cache-show)
5219 ("Install package" . anything-c-apt-install)
5220 ("Remove package" . anything-c-apt-uninstall)
5221 ("Purge package" . anything-c-apt-purge))
5222 (persistent-action . anything-c-apt-persistent-action)
5223 (persistent-help . "Show - C-u Refresh")))
5224 ;; (anything 'anything-c-source-apt)
5226 (defvar anything-c-apt-query "emacs")
5227 (defvar anything-c-apt-search-command "apt-cache search '%s'")
5228 (defvar anything-c-apt-show-command "apt-cache show '%s'")
5229 (defvar anything-c-apt-installed-packages nil)
5231 (defface anything-apt-installed
5232 '((t (:foreground "green")))
5233 "*Face used for apt installed candidates."
5234 :group 'anything)
5236 (defun anything-c-apt-refresh ()
5237 "Refresh installed candidates list."
5238 (setq anything-c-apt-installed-packages nil)
5239 (anything-force-update))
5241 (defun anything-c-apt-persistent-action (candidate)
5242 "Persistent action for APT source."
5243 (if current-prefix-arg
5244 (anything-c-apt-refresh)
5245 (anything-c-apt-cache-show candidate)))
5247 ;;;###autoload
5248 (defun anything-apt (query)
5249 "Preconfigured `anything' : frontend of APT package manager."
5250 (interactive "sAPT search: ")
5251 (let ((anything-c-apt-query query))
5252 (anything 'anything-c-source-apt)))
5254 (defun anything-c-apt-candidate-transformer (candidates)
5255 "Show installed candidates in a different color."
5256 (loop
5257 with all
5258 for cand in candidates
5259 for name = (anything-c-apt-display-to-real cand)
5260 if (member name anything-c-apt-installed-packages)
5261 collect (propertize cand 'face 'anything-apt-installed) into all
5262 else collect cand into all finally return all))
5264 (defun anything-c-apt-init ()
5265 "Initialize list of debian packages."
5266 (unless anything-c-apt-installed-packages
5267 (message "Updating installed candidate list...")
5268 (setq anything-c-apt-installed-packages
5269 (with-temp-buffer
5270 (call-process-shell-command "dpkg --get-selections"
5271 nil (current-buffer))
5272 (loop for i in (split-string (buffer-string) "\n" t)
5273 collect (car (split-string i))))))
5274 (with-current-buffer
5275 (anything-candidate-buffer
5276 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
5277 (erase-buffer)
5278 (call-process-shell-command
5279 (format anything-c-apt-search-command anything-c-apt-query)
5280 nil (current-buffer)))
5281 (message "Updating installed candidate list...done"))
5283 (defun anything-c-apt-display-to-real (line)
5284 "Return only name of a debian package.
5285 LINE is displayed like:
5286 package name - description."
5287 (car (split-string line " - ")))
5289 ;;;###autoload
5290 (defun anything-c-shell-command-if-needed (command)
5291 (interactive "sShell command: ")
5292 (if (get-buffer command) ; if the buffer already exists
5293 (switch-to-buffer command) ; then just switch to it
5294 (switch-to-buffer command) ; otherwise create it
5295 (insert (shell-command-to-string command))))
5297 (defun anything-c-apt-cache-show (package)
5298 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
5300 (defun anything-c-apt-install (package)
5301 (anything-c-apt-install1 package :action 'install))
5303 (defun anything-c-apt-uninstall (package)
5304 (anything-c-apt-install1 package :action 'uninstall))
5306 (defun anything-c-apt-purge (package)
5307 (anything-c-apt-install1 package :action 'purge))
5309 (defun* anything-c-apt-install1 (candidate &key action)
5310 (ansi-term (getenv "SHELL") "anything apt")
5311 (term-line-mode)
5312 (let ((command (case action
5313 ('install "sudo apt-get install '%s'")
5314 ('uninstall "sudo apt-get remove '%s'")
5315 ('purge "sudo apt-get purge '%s'")
5316 (t (error "Unknow action"))))
5317 (beg (point)) end)
5318 (goto-char (point-max))
5319 (insert (format command candidate))
5320 (setq end (point))
5321 (if (y-or-n-p (format "%s package" (symbol-name action)))
5322 (progn
5323 (setq anything-c-external-commands-list nil)
5324 (setq anything-c-apt-installed-packages nil)
5325 (term-char-mode) (term-send-input))
5326 (delete-region beg end) (term-send-eof) (kill-buffer))))
5328 ;; (anything-c-apt-install "jed")
5330 ;;; Sources for gentoo users
5331 (defvar anything-c-gentoo-use-flags nil)
5332 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
5333 (defvar anything-c-cache-gentoo nil)
5334 (defvar anything-c-cache-world nil)
5335 (defvar anything-c-source-gentoo
5336 '((name . "Portage sources")
5337 (init . (lambda ()
5338 (get-buffer-create anything-c-gentoo-buffer)
5339 (unless anything-c-cache-gentoo
5340 (anything-c-gentoo-setup-cache))
5341 (unless anything-c-cache-world
5342 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
5343 (anything-c-gentoo-init-list)))
5344 (candidates-in-buffer)
5345 (match . identity)
5346 (candidate-transformer anything-c-highlight-world)
5347 (action . (("Show package" . (lambda (elm)
5348 (anything-c-gentoo-eshell-action elm "eix")))
5349 ("Show history" . (lambda (elm)
5350 (if (member elm anything-c-cache-world)
5351 (anything-c-gentoo-eshell-action elm "genlop -qe")
5352 (message "No infos on packages not yet installed"))))
5353 ("Copy in kill-ring" . kill-new)
5354 ("insert at point" . insert)
5355 ("Browse HomePage" . (lambda (elm)
5356 (let ((urls (anything-c-gentoo-get-url elm)))
5357 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
5358 ("Show extra infos" . (lambda (elm)
5359 (if (member elm anything-c-cache-world)
5360 (anything-c-gentoo-eshell-action elm "genlop -qi")
5361 (message "No infos on packages not yet installed"))))
5362 ("Show use flags" . (lambda (elm)
5363 (anything-c-gentoo-default-action elm "equery" "-C" "u")
5364 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
5365 (font-lock-mode 1)))
5366 ("Run emerge pretend" . (lambda (elm)
5367 (anything-c-gentoo-eshell-action elm "emerge -p")))
5368 ("Emerge" . (lambda (elm)
5369 (anything-gentoo-install elm :action 'install)))
5370 ("Unmerge" . (lambda (elm)
5371 (anything-gentoo-install elm :action 'uninstall)))
5372 ("Show dependencies" . (lambda (elm)
5373 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
5374 ("Show related files" . (lambda (elm)
5375 (anything-c-gentoo-default-action elm "equery" "files")))
5376 ("Refresh" . (lambda (elm)
5377 (anything-c-gentoo-setup-cache)
5378 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
5380 ;; (anything 'anything-c-source-gentoo)
5382 (defun* anything-gentoo-install (candidate &key action)
5383 (setq anything-c-external-commands-list nil)
5384 (ansi-term (getenv "SHELL") "anything gentoo")
5385 (term-line-mode)
5386 (let ((command (case action
5387 ('install "sudo emerge -av ")
5388 ('uninstall "sudo emerge -avC ")
5389 (t (error "Unknow action"))))
5390 (elms (mapconcat 'identity (anything-marked-candidates) " "))
5391 (beg (point)) end)
5392 (goto-char (point-max))
5393 (insert (concat command elms))
5394 (setq end (point))
5395 (term-char-mode) (term-send-input)))
5397 (defun anything-c-gentoo-default-action (elm command &rest args)
5398 "Gentoo default action that use `anything-c-gentoo-buffer'."
5399 (if (member elm anything-c-cache-world)
5400 (progn
5401 (switch-to-buffer anything-c-gentoo-buffer)
5402 (erase-buffer)
5403 (let ((com-list (append args (list elm))))
5404 (apply #'call-process command nil t nil
5405 com-list)))
5406 (message "No infos on packages not yet installed")))
5408 (defvar anything-c-source-use-flags
5409 '((name . "Use Flags")
5410 (init . (lambda ()
5411 (unless anything-c-gentoo-use-flags
5412 (anything-c-gentoo-setup-use-flags-cache))
5413 (anything-c-gentoo-get-use)))
5414 (candidates-in-buffer)
5415 (match . identity)
5416 (candidate-transformer anything-c-highlight-local-use)
5417 (action . (("Description"
5418 . (lambda (elm)
5419 (switch-to-buffer anything-c-gentoo-buffer)
5420 (erase-buffer)
5421 (apply #'call-process "euse" nil t nil
5422 `("-i"
5423 ,elm))
5424 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
5425 (font-lock-mode 1)))
5426 ("Enable"
5427 . (lambda (elm)
5428 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
5429 ("Disable"
5430 . (lambda (elm)
5431 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
5432 ("Remove"
5433 . (lambda (elm)
5434 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
5435 ("Show which dep use this flag"
5436 . (lambda (elm)
5437 (switch-to-buffer anything-c-gentoo-buffer)
5438 (erase-buffer)
5439 (apply #'call-process "equery" nil t nil
5440 `("-C"
5442 ,elm))))))))
5445 ;; (anything 'anything-c-source-use-flags)
5447 (defun anything-c-gentoo-init-list ()
5448 "Initialize buffer with all packages in Portage."
5449 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
5450 (buf (anything-candidate-buffer 'portage-buf)))
5451 (with-current-buffer buf
5452 (dolist (i anything-c-cache-gentoo)
5453 (insert (concat i "\n"))))))
5455 (defun anything-c-gentoo-setup-cache ()
5456 "Set up `anything-c-cache-gentoo'"
5457 (setq anything-c-cache-gentoo
5458 (split-string (with-temp-buffer
5459 (call-process "eix" nil t nil
5460 "--only-names")
5461 (buffer-string)))))
5463 (defun anything-c-gentoo-eshell-action (elm command)
5464 (when (get-buffer "*EShell Command Output*")
5465 (kill-buffer "*EShell Command Output*"))
5466 (message "Wait searching...")
5467 (let ((buf-fname (buffer-file-name anything-current-buffer)))
5468 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
5469 (progn
5470 (save-window-excursion
5471 (pop-to-buffer "*scratch*")
5472 (eshell-command (format "%s %s" command elm)))
5473 (pop-to-buffer "*EShell Command Output*"))
5474 (eshell-command (format "%s %s" command elm)))))
5476 (defun anything-c-gentoo-get-use ()
5477 "Initialize buffer with all use flags."
5478 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
5479 (buf (anything-candidate-buffer 'use-buf)))
5480 (with-current-buffer buf
5481 (dolist (i anything-c-gentoo-use-flags)
5482 (insert (concat i "\n"))))))
5485 (defun anything-c-gentoo-setup-use-flags-cache ()
5486 "Setup `anything-c-gentoo-use-flags'"
5487 (setq anything-c-gentoo-use-flags
5488 (split-string (with-temp-buffer
5489 (call-process "eix" nil t nil
5490 "--print-all-useflags")
5491 (buffer-string)))))
5493 (defun anything-c-gentoo-get-url (elm)
5494 "Return a list of urls from eix output."
5495 (loop
5496 with url-list = (split-string
5497 (with-temp-buffer
5498 (call-process "eix" nil t nil
5499 elm "--format" "<homepage>\n")
5500 (buffer-string)))
5501 with all
5502 for i in url-list
5503 when (and (string-match "^http://.*" i)
5504 (not (member i all)))
5505 collect i into all
5506 finally return all))
5508 (defun anything-c-gentoo-get-world ()
5509 "Return list of all installed package on your system."
5510 (split-string (with-temp-buffer
5511 (call-process "qlist" nil t nil
5512 "-I")
5513 (buffer-string))))
5515 (defun anything-c-gentoo-get-local-use ()
5516 (split-string (with-temp-buffer
5517 (call-process "portageq" nil t nil
5518 "envvar"
5519 "USE")
5520 (buffer-string))))
5522 (defface anything-gentoo-match-face '((t (:foreground "red")))
5523 "Face for anything-gentoo installed packages."
5524 :group 'traverse-faces)
5526 (defun anything-c-highlight-world (eix)
5527 "Highlight all installed package."
5528 (loop for i in eix
5529 if (member i anything-c-cache-world)
5530 collect (propertize i 'face 'anything-gentoo-match-face)
5531 else
5532 collect i))
5534 (defun anything-c-highlight-local-use (use-flags)
5535 (let ((local-uses (anything-c-gentoo-get-local-use)))
5536 (loop for i in use-flags
5537 if (member i local-uses)
5538 collect (propertize i 'face 'anything-gentoo-match-face)
5539 else
5540 collect i)))
5542 (defvar anything-c-source-emacs-process
5543 '((name . "Emacs Process")
5544 (candidates . (lambda () (mapcar #'process-name (process-list))))
5545 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
5547 ;; (anything 'anything-c-source-emacs-process)
5549 ;; Run Externals commands within Emacs
5550 (defmacro* anything-comp-hash-get-items (hash-table &key test)
5551 "Get the list of all keys/values of hash-table."
5552 `(let ((li-items ()))
5553 (maphash #'(lambda (x y)
5554 (if ,test
5555 (when (funcall ,test y)
5556 (push (list x y) li-items))
5557 (push (list x y) li-items)))
5558 ,hash-table)
5559 li-items))
5561 (defun anything-comp-read-get-candidates (collection &optional test)
5562 "Convert collection to list.
5563 If collection is an `obarray', a test is maybe needed, otherwise
5564 the list would be incomplete.
5565 See `obarray'."
5566 (cond ((and (listp collection) test)
5567 (loop for i in collection when (funcall test i) collect i))
5568 ((and (eq collection obarray) test)
5569 (loop for s being the symbols of collection
5570 when (funcall test s) collect s))
5571 ((and (vectorp collection) test)
5572 (loop for i across collection when (funcall test i) collect i))
5573 ((vectorp collection)
5574 (loop for i across collection collect i))
5575 ((and (hash-table-p collection) test)
5576 (anything-comp-hash-get-items collection :test test))
5577 ((hash-table-p collection)
5578 (anything-comp-hash-get-items collection))
5579 (t collection)))
5581 (defun* anything-comp-read (prompt collection &key test initial-input
5582 (buffer "*Anything Completions*") must-match
5583 (requires-pattern 0))
5584 "Anything `completing-read' emulation.
5585 Collection can be a list, vector, obarray or hash-table."
5586 (when (get-buffer anything-action-buffer)
5587 (kill-buffer anything-action-buffer))
5588 (or (anything
5589 `((name . "Completions")
5590 (candidates
5591 . (lambda ()
5592 (let ((cands (anything-comp-read-get-candidates collection test)))
5593 (if (or must-match (string= anything-pattern ""))
5594 cands (append (list anything-pattern) cands)))))
5595 (requires-pattern . ,requires-pattern)
5596 (volatile)
5597 (action . (("candidate" . ,'identity))))
5598 initial-input prompt 'noresume nil buffer)
5599 (keyboard-quit)))
5601 (defun anything-c-get-pid-from-process-name (process-name)
5602 "Get pid from running process PROCESS-NAME."
5603 (loop with process-list = (list-system-processes)
5604 for pid in process-list
5605 for process = (assoc-default 'comm (process-attributes pid))
5606 when (and process (string-match process-name process))
5607 return pid))
5610 (defun anything-run-or-raise (exe &optional file)
5611 "Generic command that run asynchronously EXE.
5612 If EXE is already running just jump to his window if `anything-raise-command'
5613 is non--nil.
5614 When FILE argument is provided run EXE with FILE.
5615 In this case EXE must be provided as \"EXE %s\"."
5616 (let ((real-com (car (split-string (replace-regexp-in-string " %s" "" exe)))))
5617 (if (or (get-process real-com)
5618 (anything-c-get-pid-from-process-name real-com))
5619 (if anything-raise-command
5620 (shell-command (format anything-raise-command real-com))
5621 (error "Error: %s is already running" real-com))
5622 (when (member real-com anything-c-external-commands-list)
5623 (message "Starting %s..." real-com)
5624 (if file
5625 (start-process-shell-command real-com nil (format exe file))
5626 (start-process-shell-command real-com nil real-com))
5627 (set-process-sentinel
5628 (get-process real-com)
5629 #'(lambda (process event)
5630 (when (string= event "finished\n")
5631 (when anything-raise-command
5632 (shell-command (format anything-raise-command "emacs")))
5633 (message "%s process...Finished." process))))
5634 (setq anything-c-external-commands-list
5635 (push (pop (nthcdr (anything-c-position
5636 real-com anything-c-external-commands-list
5637 :test 'equal)
5638 anything-c-external-commands-list))
5639 anything-c-external-commands-list))))))
5641 ;;;###autoload
5642 (defun anything-c-run-external-command (program)
5643 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
5644 If program is already running exit with error.
5645 You can set your own list of commands with
5646 `anything-c-external-commands-list'."
5647 (interactive (list
5648 (anything-comp-read
5649 "RunProgram: "
5650 (anything-c-external-commands-list-1 'sort)
5651 :must-match t)))
5652 (anything-run-or-raise program))
5654 (defsubst* anything-c-position (item seq &key (test 'eq))
5655 "A simple and faster replacement of CL `position'."
5656 (loop for i in seq for index from 0
5657 when (funcall test i item) return index))
5659 (defvar anything-c-source-ratpoison-commands
5660 '((name . "Ratpoison Commands")
5661 (init . anything-c-ratpoison-commands-init)
5662 (candidates-in-buffer)
5663 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
5664 (display-to-real . anything-c-ratpoison-commands-display-to-real)
5665 (candidate-number-limit)))
5666 ;; (anything 'anything-c-source-ratpoison-commands)
5668 (defun anything-c-ratpoison-commands-init ()
5669 (unless (anything-candidate-buffer)
5670 (with-current-buffer (anything-candidate-buffer 'global)
5671 ;; with ratpoison prefix key
5672 (save-excursion
5673 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
5674 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5675 (replace-match "<ratpoison> \\1: \\2"))
5676 (goto-char (point-max))
5677 ;; direct binding
5678 (save-excursion
5679 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
5680 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5681 (replace-match "\\1: \\2")))))
5683 (defun anything-c-ratpoison-commands-display-to-real (display)
5684 (and (string-match ": " display)
5685 (substring display (match-end 0))))
5687 (defun anything-c-ratpoison-commands-execute (candidate)
5688 (call-process "ratpoison" nil nil nil "-ic" candidate))
5690 ;;;###autoload
5691 (defun anything-ratpoison-commands ()
5692 "Preconfigured `anything' to execute ratpoison commands."
5693 (interactive)
5694 (anything-other-buffer 'anything-c-source-ratpoison-commands
5695 "*anything ratpoison commands*"))
5697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5698 ;;; Files
5699 (defvar anything-c-external-commands-list nil
5700 "A list of all external commands the user can execute. If this
5701 variable is not set by the user, it will be calculated
5702 automatically.")
5704 (defun anything-c-external-commands-list-1 (&optional sort)
5705 "Returns a list of all external commands the user can execute.
5707 If `anything-c-external-commands-list' is non-nil it will
5708 return its contents. Else it calculates all external commands
5709 and sets `anything-c-external-commands-list'.
5711 The code is ripped out of `eshell-complete-commands-list'."
5712 (if anything-c-external-commands-list
5713 anything-c-external-commands-list
5714 (setq anything-c-external-commands-list
5715 (let* ((paths (split-string (getenv "PATH") path-separator))
5716 (cwd (file-name-as-directory
5717 (expand-file-name default-directory)))
5718 (path "") (comps-in-path ())
5719 (file "") (filepath "") (completions ()))
5720 ;; Go thru each path in the search path, finding completions.
5721 (while paths
5722 (setq path (file-name-as-directory
5723 (expand-file-name (or (car paths) ".")))
5724 comps-in-path
5725 (and (file-accessible-directory-p path)
5726 (file-name-all-completions "" path)))
5727 ;; Go thru each completion found, to see whether it should be
5728 ;; used, e.g. see if it's executable.
5729 (while comps-in-path
5730 (setq file (car comps-in-path)
5731 filepath (concat path file))
5732 (if (and (not (member file completions))
5733 (or (string-equal path cwd)
5734 (not (file-directory-p filepath)))
5735 (file-executable-p filepath))
5736 (setq completions (cons file completions)))
5737 (setq comps-in-path (cdr comps-in-path)))
5738 (setq paths (cdr paths)))
5739 (if sort
5740 (sort completions #'(lambda (x y) (string< x y)))
5741 completions)))))
5743 (defun anything-c-file-buffers (filename)
5744 "Returns a list of buffer names corresponding to FILENAME."
5745 (let ((name (expand-file-name filename))
5746 (buf-list ()))
5747 (dolist (buf (buffer-list) buf-list)
5748 (let ((bfn (buffer-file-name buf)))
5749 (when (and bfn (string= name bfn))
5750 (push (buffer-name buf) buf-list))))))
5752 (defun anything-c-delete-file (file)
5753 "Delete the given file after querying the user.
5754 Ask to kill buffers associated with that file, too."
5755 (let ((buffers (anything-c-file-buffers file)))
5756 (dired-delete-file file 'dired-recursive-deletes)
5757 (when buffers
5758 (dolist (buf buffers)
5759 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
5760 (kill-buffer buf))))))
5762 (defun anything-get-mailcap-for-file (filename)
5763 "Get the command to use for FILENAME from mailcap files.
5764 The command is like <command %s> and is meant to use with `format'."
5765 (mailcap-parse-mailcaps)
5766 (let* ((ext (file-name-extension filename))
5767 (mime (when ext (mailcap-extension-to-mime ext))))
5768 (when mime (mailcap-mime-info mime))))
5770 (defun anything-c-open-file-externally (file)
5771 "Open FILE with an external tool found in .mailcap file.
5772 If not found or a prefix arg is given query the user which tool to use."
5773 (let* ((fname (expand-file-name file))
5774 (collection (anything-c-external-commands-list-1 'sort))
5775 (def-prog (anything-get-mailcap-for-file fname))
5776 (program (or (unless (or anything-current-prefix-arg
5777 (not def-prog))
5778 def-prog)
5779 (concat
5780 (anything-comp-read
5781 "Program: "
5782 collection :must-match t)
5783 " %s"))))
5784 (anything-run-or-raise program file)))
5786 ;;;###autoload
5787 (defun w32-shell-execute-open-file (file)
5788 (interactive "fOpen file:")
5789 (with-no-warnings
5790 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
5791 "/" "\\"
5792 (replace-regexp-in-string ; strip cygdrive paths
5793 "/cygdrive/\\(.\\)" "\\1:"
5794 file nil nil) nil t))))
5796 (defun anything-c-open-file-with-default-tool (file)
5797 "Open FILE with the default tool on this platform."
5798 (if (eq system-type 'windows-nt)
5799 (w32-shell-execute-open-file file)
5800 (start-process "anything-c-open-file-with-default-tool"
5802 (cond ((eq system-type 'gnu/linux)
5803 "xdg-open")
5804 ((or (eq system-type 'darwin) ;; Mac OS X
5805 (eq system-type 'macos)) ;; Mac OS 9
5806 "open"))
5807 file)))
5809 (defun anything-c-open-dired (file)
5810 "Opens a dired buffer in FILE's directory. If FILE is a
5811 directory, open this directory."
5812 (if (file-directory-p file)
5813 (dired file)
5814 (dired (file-name-directory file))
5815 (dired-goto-file file)))
5817 (defun anything-c-display-to-real-line (candidate)
5818 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
5819 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
5820 (error "Line number not found")))
5822 (defun anything-c-action-line-goto (lineno-and-content)
5823 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
5824 (append lineno-and-content
5825 (list (if (and (anything-attr-defined 'target-file)
5826 (not anything-in-persistent-action))
5827 'find-file-other-window
5828 'find-file)))))
5830 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
5831 (apply #'anything-goto-file-line
5832 (if (stringp file-line-content)
5833 ;; Case: filtered-candidate-transformer is skipped
5834 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
5835 file-line-content)))
5837 (require 'compile)
5838 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
5839 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
5841 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
5842 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
5843 (let ((filename (match-string 1 candidate))
5844 (lineno (match-string 2 candidate))
5845 (content (match-string 3 candidate)))
5846 (cons (format "%s:%s\n %s"
5847 (propertize filename 'face compilation-info-face)
5848 (propertize lineno 'face compilation-line-face)
5849 content)
5850 (list (expand-file-name
5851 filename
5852 (or (anything-interpret-value (anything-attr 'default-directory))
5853 (and (anything-candidate-buffer)
5854 (buffer-local-value
5855 'default-directory (anything-candidate-buffer)))))
5856 (string-to-number lineno) content)))))
5858 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
5859 (anything-aif (anything-attr 'before-jump-hook)
5860 (funcall it))
5861 (when file (funcall find-file-function file))
5862 (if (anything-attr-defined 'adjust)
5863 (anything-c-goto-line-with-adjustment lineno content)
5864 (anything-goto-line lineno))
5865 (unless (anything-attr-defined 'recenter)
5866 (set-window-start (get-buffer-window anything-current-buffer) (point)))
5867 (anything-aif (anything-attr 'after-jump-hook)
5868 (funcall it))
5869 (when anything-in-persistent-action
5870 (anything-match-line-color-current-line)))
5872 (defun anything-find-file-as-root (candidate)
5873 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
5875 (defun anything-find-many-files (ignore)
5876 (mapc 'find-file (anything-marked-candidates)))
5878 ;; borrowed from etags.el
5879 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
5880 (defun anything-c-goto-line-with-adjustment (line line-content)
5881 (let ((startpos)
5882 offset found pat)
5883 ;; This constant is 1/2 the initial search window.
5884 ;; There is no sense in making it too small,
5885 ;; since just going around the loop once probably
5886 ;; costs about as much as searching 2000 chars.
5887 (setq offset 1000
5888 found nil
5889 pat (concat (if (eq selective-display t)
5890 "\\(^\\|\^m\\) *" "^ *") ;allow indent
5891 (regexp-quote line-content)))
5892 ;; If no char pos was given, try the given line number.
5893 (setq startpos (progn (anything-goto-line line) (point)))
5894 (or startpos (setq startpos (point-min)))
5895 ;; First see if the tag is right at the specified location.
5896 (goto-char startpos)
5897 (setq found (looking-at pat))
5898 (while (and (not found)
5899 (progn
5900 (goto-char (- startpos offset))
5901 (not (bobp))))
5902 (setq found
5903 (re-search-forward pat (+ startpos offset) t)
5904 offset (* 3 offset))) ; expand search window
5905 (or found
5906 (re-search-forward pat nil t)
5907 (error "not found")))
5908 ;; Position point at the right place
5909 ;; if the search string matched an extra Ctrl-m at the beginning.
5910 (and (eq selective-display t)
5911 (looking-at "\^m")
5912 (forward-char 1))
5913 (beginning-of-line))
5915 (anything-document-attribute 'default-directory "type . file-line"
5916 "`default-directory' to interpret file.")
5917 (anything-document-attribute 'before-jump-hook "type . file-line / line"
5918 "Function to call before jumping to the target location.")
5919 (anything-document-attribute 'after-jump-hook "type . file-line / line"
5920 "Function to call after jumping to the target location.")
5921 (anything-document-attribute 'adjust "type . file-line"
5922 "Search around line matching line contents.")
5923 (anything-document-attribute 'recenter "type . file-line / line"
5924 "`recenter' after jumping.")
5925 (anything-document-attribute 'target-file "type . line"
5926 "Goto line of target-file.")
5928 ;;;###autoload
5929 (defun anything-c-call-interactively (cmd-or-name)
5930 "Execute CMD-OR-NAME as Emacs command.
5931 It is added to `extended-command-history'.
5932 `anything-current-prefix-arg' is used as the command's prefix argument."
5933 (setq extended-command-history
5934 (cons (anything-c-stringify cmd-or-name)
5935 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
5936 (let ((current-prefix-arg anything-current-prefix-arg)
5937 (cmd (anything-c-symbolify cmd-or-name)))
5938 (if (stringp (symbol-function cmd))
5939 (execute-kbd-macro (symbol-function cmd))
5940 (setq this-command cmd)
5941 (call-interactively cmd))))
5943 ;;;###autoload
5944 (defun anything-c-set-variable (var)
5945 "Set value to VAR interactively."
5946 (interactive)
5947 (let ((sym (anything-c-symbolify var)))
5948 (set sym (eval-minibuffer (format "Set %s: " var)
5949 (prin1-to-string (symbol-value sym))))))
5950 ;; (setq hh 12)
5951 ;; (anything-c-set-variable 'hh)
5953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5954 (defvar anything-match-line-overlay-face nil)
5955 (defvar anything-match-line-overlay nil)
5957 (defun anything-match-line-color-current-line (&optional start end buf face rec)
5958 "Highlight and underline current position"
5959 (let ((args (list (or start (line-beginning-position))
5960 (or end (1+ (line-end-position)))
5961 buf)))
5962 (if (not anything-match-line-overlay)
5963 (setq anything-match-line-overlay (apply 'make-overlay args))
5964 (apply 'move-overlay anything-match-line-overlay args)))
5965 (overlay-put anything-match-line-overlay
5966 'face (or face anything-match-line-overlay-face))
5967 (when rec
5968 (goto-char start)
5969 (recenter)))
5971 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
5973 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
5974 "Face for source header in the anything buffer." :group 'anything)
5976 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
5978 (defun anything-match-line-cleanup ()
5979 (when anything-match-line-overlay
5980 (delete-overlay anything-match-line-overlay)
5981 (setq anything-match-line-overlay nil)))
5983 (defun anything-match-line-update ()
5984 (when anything-match-line-overlay
5985 (delete-overlay anything-match-line-overlay)
5986 (anything-match-line-color-current-line)))
5988 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
5989 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
5991 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5992 ;;; Files
5993 (defun anything-c-transform-file-load-el (actions candidate)
5994 "Add action to load the file CANDIDATE if it is an emacs lisp
5995 file. Else return ACTIONS unmodified."
5996 (if (member (file-name-extension candidate) '("el" "elc"))
5997 (append actions '(("Load Emacs Lisp File" . load-file)))
5998 actions))
6000 (defun anything-c-transform-file-browse-url (actions candidate)
6001 "Add an action to browse the file CANDIDATE if it in a html
6002 file or URL. Else return ACTIONS unmodified."
6003 (let ((browse-action '("Browse with Browser" . browse-url)))
6004 (cond ((string-match "^http\\|^ftp" candidate)
6005 (cons browse-action actions))
6006 ((string-match "\\.html?$" candidate)
6007 (append actions (list browse-action)))
6008 (t actions))))
6010 ;;;; Function
6011 (defun anything-c-transform-function-call-interactively (actions candidate)
6012 "Add an action to call the function CANDIDATE interactively if
6013 it is a command. Else return ACTIONS unmodified."
6014 (if (commandp (intern-soft candidate))
6015 (append actions '(("Call Interactively"
6017 anything-c-call-interactively)))
6018 actions))
6020 ;;;; S-Expressions
6021 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
6022 "If CANDIDATE's `car' is a command, then add an action to
6023 evaluate it and put it onto the `command-history'."
6024 (if (commandp (car (read candidate)))
6025 ;; Make it first entry
6026 (cons '("Eval and put onto command-history" .
6027 (lambda (sexp)
6028 (let ((sym (read sexp)))
6029 (eval sym)
6030 (setq command-history
6031 (cons sym command-history)))))
6032 actions)
6033 actions))
6035 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6036 ;;; Buffers
6037 (defun anything-c-skip-boring-buffers (buffers)
6038 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
6040 (defun anything-c-skip-current-buffer (buffers)
6041 (if anything-allow-skipping-current-buffer
6042 (remove (buffer-name anything-current-buffer) buffers)
6043 buffers))
6045 (defun anything-c-shadow-boring-buffers (buffers)
6046 "Buffers matching `anything-c-boring-buffer-regexp' will be
6047 displayed with the `file-name-shadow' face if available."
6048 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
6050 ;;; Files
6051 (defun anything-c-shadow-boring-files (files)
6052 "Files matching `anything-c-boring-file-regexp' will be
6053 displayed with the `file-name-shadow' face if available."
6054 (anything-c-shadow-entries files anything-c-boring-file-regexp))
6056 (defun anything-c-skip-boring-files (files)
6057 "Files matching `anything-c-boring-file-regexp' will be skipped."
6058 (anything-c-skip-entries files anything-c-boring-file-regexp))
6059 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6061 (defun anything-c-skip-current-file (files)
6062 "Current file will be skipped."
6063 (remove (buffer-file-name anything-current-buffer) files))
6065 (defun anything-c-w32-pathname-transformer (args)
6066 "Change undesirable features of windows pathnames to ones more acceptable to
6067 other candidate transformers."
6068 (if (eq system-type 'windows-nt)
6069 (mapcar (lambda (x)
6070 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
6071 (mapcar (lambda (y)
6072 (replace-regexp-in-string "\\\\" "/" y)) args))
6073 args))
6075 (defun anything-c-shorten-home-path (files)
6076 "Replaces /home/user with ~."
6077 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6078 (getenv "HOME"))))
6079 (mapcar (lambda (file)
6080 (if (and (stringp file) (string-match home file))
6081 (cons (replace-match "~" nil nil file) file)
6082 file))
6083 files)))
6085 ;;; Functions
6086 (defun anything-c-mark-interactive-functions (functions)
6087 "Mark interactive functions (commands) with (i) after the function name."
6088 (let (list)
6089 (loop for function in functions
6090 do (push (cons (concat function
6091 (when (commandp (intern-soft function)) " (i)"))
6092 function)
6093 list)
6094 finally (return (nreverse list)))))
6096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6097 (defvar anything-c-adaptive-done nil
6098 "nil if history information is not yet stored for the current
6099 selection.")
6101 (defvar anything-c-adaptive-history nil
6102 "Contains the stored history information.
6103 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6105 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
6106 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6107 when anything is started."
6108 (setq anything-c-adaptive-done nil))
6110 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
6111 "Advise `anything-exit-minibuffer' to store history information
6112 when a candidate is selected with RET."
6113 (anything-c-adaptive-store-selection))
6115 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
6116 "Advise `anything-select-action' to store history information
6117 when the user goes to the action list with TAB."
6118 (anything-c-adaptive-store-selection))
6120 (defun anything-c-source-use-adaptative-p (&optional source-name)
6121 "Return current source only if it use adaptative history, nil otherwise."
6122 (let* ((source (or source-name (anything-get-current-source)))
6123 (adapt-source (or (assoc-default 'filtered-candidate-transformer
6124 (assoc (assoc-default 'type source)
6125 anything-type-attributes))
6126 (assoc-default 'candidate-transformer
6127 (assoc (assoc-default 'type source)
6128 anything-type-attributes))
6129 (assoc-default 'filtered-candidate-transformer source)
6130 (assoc-default 'candidate-transformer source))))
6131 (if (listp adapt-source)
6132 (when (member 'anything-c-adaptive-sort adapt-source) source)
6133 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
6135 (defun anything-c-adaptive-store-selection ()
6136 "Store history information for the selected candidate."
6137 (unless anything-c-adaptive-done
6138 (setq anything-c-adaptive-done t)
6139 (let ((source (anything-c-source-use-adaptative-p)))
6140 (when source
6141 (let* ((source-name (or (assoc-default 'type source)
6142 (assoc-default 'name source)))
6143 (source-info (or (assoc source-name anything-c-adaptive-history)
6144 (progn
6145 (push (list source-name) anything-c-adaptive-history)
6146 (car anything-c-adaptive-history))))
6147 (selection (anything-get-selection))
6148 (selection-info (progn
6149 (setcdr source-info
6150 (cons
6151 (let ((found (assoc selection (cdr source-info))))
6152 (if (not found)
6153 ;; new entry
6154 (list selection)
6156 ;; move entry to the beginning of the
6157 ;; list, so that it doesn't get
6158 ;; trimmed when the history is
6159 ;; truncated
6160 (setcdr source-info
6161 (delete found (cdr source-info)))
6162 found))
6163 (cdr source-info)))
6164 (cadr source-info)))
6165 (pattern-info (progn
6166 (setcdr selection-info
6167 (cons
6168 (let ((found (assoc anything-pattern (cdr selection-info))))
6169 (if (not found)
6170 ;; new entry
6171 (cons anything-pattern 0)
6173 ;; move entry to the beginning of the
6174 ;; list, so if two patterns used the
6175 ;; same number of times then the one
6176 ;; used last appears first in the list
6177 (setcdr selection-info
6178 (delete found (cdr selection-info)))
6179 found))
6180 (cdr selection-info)))
6181 (cadr selection-info))))
6183 ;; increase usage count
6184 (setcdr pattern-info (1+ (cdr pattern-info)))
6186 ;; truncate history if needed
6187 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
6188 (setcdr selection-info
6189 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
6191 (if (file-readable-p anything-c-adaptive-history-file)
6192 (load-file anything-c-adaptive-history-file))
6193 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
6195 (defun anything-c-adaptive-save-history ()
6196 "Save history information to file given by `anything-c-adaptive-history-file'."
6197 (interactive)
6198 (with-temp-buffer
6199 (insert
6200 ";; -*- mode: emacs-lisp -*-\n"
6201 ";; History entries used for anything adaptive display.\n")
6202 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
6203 (current-buffer))
6204 (insert ?\n)
6205 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
6206 (unless (interactive-p) 'quiet))))
6208 (defun anything-c-adaptive-sort (candidates source)
6209 "Sort the CANDIDATES for SOURCE by usage frequency.
6210 This is a filtered candidate transformer you can use for the
6211 attribute `filtered-candidate-transformer' of a source in
6212 `anything-sources' or a type in `anything-type-attributes'."
6213 (let* ((source-name (or (assoc-default 'type source)
6214 (assoc-default 'name source)))
6215 (source-info (assoc source-name anything-c-adaptive-history)))
6216 (if (not source-info)
6217 ;; if there is no information stored for this source then do nothing
6218 candidates
6219 ;; else...
6220 (let ((usage
6221 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
6222 ;; pairs
6223 (mapcar (lambda (candidate-info)
6224 (let ((count 0))
6225 (dolist (pattern-info (cdr candidate-info))
6226 (if (not (equal (car pattern-info)
6227 anything-pattern))
6228 (incf count (cdr pattern-info))
6230 ;; if current pattern is equal to the previously
6231 ;; used one then this candidate has priority
6232 ;; (that's why its count is boosted by 10000) and
6233 ;; it only has to compete with other candidates
6234 ;; which were also selected with the same pattern
6235 (setq count (+ 10000 (cdr pattern-info)))
6236 (return)))
6237 (cons (car candidate-info) count)))
6238 (cdr source-info)))
6239 sorted)
6241 ;; sort the list in descending order, so candidates with highest
6242 ;; priorty come first
6243 (setq usage (sort usage (lambda (first second)
6244 (> (cdr first) (cdr second)))))
6246 ;; put those candidates first which have the highest usage count
6247 (dolist (info usage)
6248 (when (member* (car info) candidates
6249 :test 'anything-c-adaptive-compare)
6250 (push (car info) sorted)
6251 (setq candidates (remove* (car info) candidates
6252 :test 'anything-c-adaptive-compare))))
6254 ;; and append the rest
6255 (append (reverse sorted) candidates nil)))))
6257 (defun anything-c-adaptive-compare (x y)
6258 "Compare candidates X and Y taking into account that the
6259 candidate can be in (DISPLAY . REAL) format."
6260 (equal (if (listp x)
6261 (cdr x)
6263 (if (listp y)
6264 (cdr y)
6265 y)))
6267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6268 (defvar anything-outline-goto-near-line-flag t)
6269 (defvar anything-outline-using nil)
6270 (defun anything-after-update-hook--outline ()
6271 (if (and (eq anything-outline-using t)
6272 (eq anything-outline-goto-near-line-flag t))
6273 (anything-outline-goto-near-line)))
6274 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
6276 (defun anything-outline-goto-near-line ()
6277 (with-anything-window
6278 ;; TODO need consideration whether to update position by every input.
6279 (when t ; (equal anything-pattern "")
6280 (anything-goto-line 2)
6281 (let ((lineno (with-current-buffer anything-current-buffer
6282 (line-number-at-pos (car anything-current-position)))))
6283 (block exit
6284 (while (<= (progn (skip-chars-forward " ")
6285 (or (number-at-point) lineno))
6286 lineno)
6287 (forward-line 1)
6288 (when (eobp)
6289 (forward-line -1)
6290 (return-from exit))))
6291 (forward-line -1)
6292 (and (bobp) (forward-line 1))
6293 (and (anything-pos-header-line-p) (forward-line -2))
6294 (anything-mark-current-line)))))
6296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6297 ;; Plug-in: info-index
6298 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
6299 (let (result)
6300 (unless (anything-candidate-buffer)
6301 (save-window-excursion
6302 (info file)
6303 (let (Info-history
6304 (tobuf (anything-candidate-buffer 'global))
6305 (infobuf (current-buffer))
6306 s e)
6307 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
6308 (Info-goto-node node)
6309 (goto-char (point-min))
6310 (while (search-forward "\n* " nil t)
6311 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
6312 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
6313 (setq s (point-at-bol)
6314 e (point-at-eol))
6315 (with-current-buffer tobuf
6316 (insert-buffer-substring infobuf s e)
6317 (insert "\n"))))))))))
6319 (defun anything-c-info-goto (node-line)
6320 (Info-goto-node (car node-line))
6321 (anything-goto-line (cdr node-line)))
6323 (defun anything-c-info-display-to-real (line)
6324 (and (string-match
6325 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
6326 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
6327 (string-to-number (or (match-string 3 line) "1")))))
6329 (defun anything-c-make-info-source (file)
6330 `((name . ,(concat "Info Index: " file))
6331 (info-file . ,file)
6332 (init . anything-c-info-init)
6333 (display-to-real . anything-c-info-display-to-real)
6334 (get-line . buffer-substring)
6335 (candidates-in-buffer)
6336 (action ("Goto node" . anything-c-info-goto))))
6338 (defun anything-compile-source--info-index (source)
6339 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
6340 (anything-c-make-info-source it)
6341 source))
6342 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
6344 (anything-document-attribute 'info-index "info-index plugin"
6345 "Create a source of info index very easily.
6347 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
6349 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
6350 "Index nodes of info file.
6352 If it is omitted, `Info-index-nodes' is used to collect index nodes.
6353 Some info files are missing index specification.
6355 ex. See `anything-c-source-info-screen'.")
6357 ;; Plug-in: candidates-file
6358 (defun anything-compile-source--candidates-file (source)
6359 (if (assoc-default 'candidates-file source)
6360 `((init anything-p-candidats-file-init
6361 ,@(let ((orig-init (assoc-default 'init source)))
6362 (cond ((null orig-init) nil)
6363 ((functionp orig-init) (list orig-init))
6364 (t orig-init))))
6365 (candidates-in-buffer)
6366 ,@source)
6367 source))
6368 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
6370 (defun anything-p-candidats-file-init ()
6371 (destructuring-bind (file &optional updating)
6372 (anything-mklist (anything-attr 'candidates-file))
6373 (setq file (anything-interpret-value file))
6374 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
6375 (when updating
6376 (buffer-disable-undo)
6377 (font-lock-mode -1)
6378 (auto-revert-mode 1)))))
6380 (anything-document-attribute 'candidates-file "candidates-file plugin"
6381 "Use a file as the candidates buffer.
6383 1st argument is a filename, string or function name or variable name.
6384 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
6386 ;; Plug-in: headline
6387 (defun anything-compile-source--anything-headline (source)
6388 (if (assoc-default 'headline source)
6389 (append '((init . anything-headline-init)
6390 (get-line . buffer-substring)
6391 (type . line))
6392 source
6393 '((candidates-in-buffer)
6394 (persistent-help . "Show this line")))
6395 source))
6396 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
6398 (defun anything-headline-init ()
6399 (when (and (anything-current-buffer-is-modified)
6400 (with-current-buffer anything-current-buffer
6401 (eval (or (anything-attr 'condition) t))))
6402 (anything-headline-make-candidate-buffer
6403 (anything-interpret-value (anything-attr 'headline))
6404 (anything-interpret-value (anything-attr 'subexp)))))
6406 (anything-document-attribute 'headline "Headline plug-in"
6407 "Regexp string for anything-headline to scan.")
6408 (anything-document-attribute 'condition "Headline plug-in"
6409 "A sexp representing the condition to use anything-headline.")
6410 (anything-document-attribute 'subexp "Headline plug-in"
6411 "Display (match-string-no-properties subexp).")
6414 (defun anything-headline-get-candidates (regexp subexp)
6415 (with-current-buffer anything-current-buffer
6416 (save-excursion
6417 (goto-char (point-min))
6418 (if (functionp regexp) (setq regexp (funcall regexp)))
6419 (let (hierarchy curhead)
6420 (flet ((matched ()
6421 (if (numberp subexp)
6422 (cons (match-string-no-properties subexp) (match-beginning subexp))
6423 (cons (buffer-substring (point-at-bol) (point-at-eol))
6424 (point-at-bol))))
6425 (hierarchies (headlines)
6426 (1+ (loop for (_ . hierarchy) in headlines
6427 maximize hierarchy)))
6428 (vector-0-n (v n)
6429 (loop for i from 0 to hierarchy
6430 collecting (aref curhead i)))
6431 (arrange (headlines)
6432 (unless (null headlines) ; FIX headlines empty bug!
6433 (loop with curhead = (make-vector (hierarchies headlines) "")
6434 for ((str . pt) . hierarchy) in headlines
6435 do (aset curhead hierarchy str)
6436 collecting
6437 (cons
6438 (format "H%d:%s" (1+ hierarchy)
6439 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
6440 pt)))))
6441 (if (listp regexp)
6442 (arrange
6443 (sort
6444 (loop for re in regexp
6445 for hierarchy from 0
6446 do (goto-char (point-min))
6447 appending
6448 (loop
6449 while (re-search-forward re nil t)
6450 collect (cons (matched) hierarchy)))
6451 (lambda (a b) (> (cdar b) (cdar a)))))
6452 (loop while (re-search-forward regexp nil t)
6453 collect (matched))))))))
6456 (defun anything-headline-make-candidate-buffer (regexp subexp)
6457 (with-current-buffer (anything-candidate-buffer 'local)
6458 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
6459 do (insert
6460 (format "%5d:%s\n"
6461 (with-current-buffer anything-current-buffer
6462 (line-number-at-pos pos))
6463 content)))))
6465 (defun anything-headline-goto-position (pos recenter)
6466 (goto-char pos)
6467 (unless recenter
6468 (set-window-start (get-buffer-window anything-current-buffer) (point))))
6470 (defun anything-revert-buffer (candidate)
6471 (with-current-buffer candidate
6472 (when (buffer-modified-p)
6473 (revert-buffer t t))))
6475 (defun anything-revert-marked-buffers (candidate)
6476 (dolist (i (anything-marked-candidates))
6477 (anything-revert-buffer i)))
6479 (defun anything-kill-marked-buffers (candidate)
6480 (dolist (i (anything-marked-candidates))
6481 (kill-buffer i)))
6483 ;; Plug-in: persistent-help
6484 (defun anything-compile-source--persistent-help (source)
6485 (append source '((header-line . anything-persistent-help-string))))
6486 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
6488 (defun anything-persistent-help-string ()
6489 (substitute-command-keys
6490 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
6491 (or (anything-interpret-value (anything-attr 'persistent-help))
6492 (anything-aif (or (assoc-default 'persistent-action
6493 (anything-get-current-source))
6494 (assoc-default 'action
6495 (anything-get-current-source)))
6496 (cond ((symbolp it) (symbol-name it))
6497 ((listp it) (or (ignore-errors (caar it)) ""))))
6499 " (keeping session)")))
6501 (anything-document-attribute 'persistent-help "persistent-help plug-in"
6502 "A string to explain persistent-action of this source.
6503 It also accepts a function or a variable name.")
6505 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
6507 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6509 (defun anything-c-find-file-or-marked (candidate)
6510 "Open file CANDIDATE or open anything marked files in background."
6511 (let ((marked (anything-marked-candidates)))
6512 (if (> (length marked) 1)
6513 (dolist (i marked) (find-file-noselect i))
6514 (find-file-at-point candidate))))
6516 ;; FIXME there is a bug in dired that confuse all dired commands
6517 ;; when using this feature, so i suspend it until bug is fixed in emacs.
6519 ;; (defun anything-c-create-dired-on-marked (candidate)
6520 ;; "Create a new dired buffer with only marked candidates."
6521 ;; (let ((marked (anything-marked-candidates))
6522 ;; (buffer-name (read-string "New Dired Buffer: ")))
6523 ;; (dired (cons buffer-name marked))))
6525 (defun anything-delete-marked-files (ignore)
6526 (let* ((files (anything-marked-candidates))
6527 (len (length files)))
6528 (if (not (y-or-n-p
6529 (format "Delete *%s File(s):\n%s"
6531 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
6532 (message "(No deletions performed)")
6533 (dolist (i files)
6534 (set-text-properties 0 (length i) nil i)
6535 (anything-c-delete-file i))
6536 (message "%s File(s) deleted" len))))
6538 (defun anything-ediff-marked-buffers (candidate &optional merge)
6539 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
6540 With optional arg `merge' call `ediff-merge-buffers'."
6541 (let ((lg-lst (length (anything-marked-candidates)))
6542 buf1 buf2)
6543 (case lg-lst
6545 (error "Error:You have to mark at least 1 buffer"))
6547 (setq buf1 anything-current-buffer
6548 buf2 (first (anything-marked-candidates))))
6550 (setq buf1 (first (anything-marked-candidates))
6551 buf2 (second (anything-marked-candidates))))
6553 (error "Error:To much buffers marked!")))
6554 (if merge
6555 (ediff-merge-buffers buf1 buf2)
6556 (ediff-buffers buf1 buf2))))
6558 (defun anything-bookmark-get-bookmark-from-name (bmk)
6559 "Return bookmark name even if it is a bookmark with annotation.
6560 e.g prepended with *.
6561 Return nil if bmk is not a valid bookmark."
6562 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
6563 (if (assoc bookmark bookmark-alist)
6564 bookmark
6565 (when (assoc bmk bookmark-alist)
6566 bmk))))
6568 (defun anything-delete-marked-bookmarks (elm)
6569 "Delete this bookmark or all marked bookmarks."
6570 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
6571 (anything-aif (anything-marked-candidates)
6572 (dolist (i it)
6573 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
6574 (bookmark-delete bmk 'batch)))
6575 (bookmark-delete bookmark 'batch))))
6577 (defun anything-require-or-error (feature function)
6578 (or (require feature nil t)
6579 (error "Need %s to use `%s'." feature function)))
6581 (defun anything-find-buffer-on-elscreen (candidate)
6582 "Open buffer in new screen, if marked buffers open all in elscreens."
6583 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
6584 (anything-aif (anything-marked-candidates)
6585 (dolist (i it)
6586 (let ((target-screen (elscreen-find-screen-by-buffer
6587 (get-buffer i) 'create)))
6588 (elscreen-goto target-screen)))
6589 (let ((target-screen (elscreen-find-screen-by-buffer
6590 (get-buffer candidate) 'create)))
6591 (elscreen-goto target-screen))))
6593 (defun anything-elscreen-find-file (file)
6594 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
6595 (elscreen-find-file file))
6597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6599 ;;;; Type Attributes
6600 (define-anything-type-attribute 'buffer
6601 `((action
6602 ,@(if pop-up-frames
6603 '(("Switch to buffer other window" . switch-to-buffer-other-window)
6604 ("Switch to buffer" . switch-to-buffer))
6605 '(("Switch to buffer" . switch-to-buffer)
6606 ("Switch to buffer other window" . switch-to-buffer-other-window)
6607 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
6608 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
6609 ("Display buffer" . display-buffer)
6610 ("Revert buffer" . anything-revert-buffer)
6611 ("Revert Marked buffers" . anything-revert-marked-buffers)
6612 ("Kill buffer" . kill-buffer)
6613 ("Kill Marked buffers" . anything-kill-marked-buffers)
6614 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
6615 ("Ediff Merge marked buffers" . (lambda (candidate)
6616 (anything-ediff-marked-buffers candidate t))))
6617 (persistent-help . "Show this buffer")
6618 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
6619 "Buffer or buffer name.")
6621 (define-anything-type-attribute 'file
6622 `((action
6623 ,@(if pop-up-frames
6624 '(("Find file other window" . find-file-other-window)
6625 ("Find file(s)" . anything-find-many-files)
6626 ("Find file as root" . anything-find-file-as-root))
6627 '(("Find file" . anything-find-many-files)
6628 ("Find file as root" . anything-find-file-as-root)
6629 ("Find file other window" . find-file-other-window)
6630 ("Find file other frame" . find-file-other-frame)))
6631 ("Open dired in file's directory" . anything-c-open-dired)
6632 ("Delete file(s)" . anything-delete-marked-files)
6633 ("Open file externally" . anything-c-open-file-externally)
6634 ("Open file with default tool" . anything-c-open-file-with-default-tool))
6635 (persistent-help . "Show this file")
6636 (action-transformer anything-c-transform-file-load-el
6637 anything-c-transform-file-browse-url)
6638 (candidate-transformer anything-c-w32-pathname-transformer
6639 anything-c-skip-current-file
6640 anything-c-skip-boring-files
6641 anything-c-shorten-home-path))
6642 "File name.")
6644 (define-anything-type-attribute 'command
6645 `((action ("Call interactively" . anything-c-call-interactively)
6646 ("Describe command" . anything-c-describe-function)
6647 ("Add command to kill ring" . anything-c-kill-new)
6648 ("Go to command's definition" . anything-c-find-function))
6649 ;; Sort commands according to their usage count.
6650 (filtered-candidate-transformer . anything-c-adaptive-sort)
6651 (persistent-action . anything-c-describe-function))
6652 "Command. (string or symbol)")
6654 (define-anything-type-attribute 'function
6655 '((action ("Describe function" . anything-c-describe-function)
6656 ("Add function to kill ring" . anything-c-kill-new)
6657 ("Go to function's definition" . anything-c-find-function))
6658 (action-transformer anything-c-transform-function-call-interactively)
6659 (candidate-transformer anything-c-mark-interactive-functions))
6660 "Function. (string or symbol)")
6662 (define-anything-type-attribute 'variable
6663 '((action ("Describe variable" . anything-c-describe-variable)
6664 ("Add variable to kill ring" . anything-c-kill-new)
6665 ("Go to variable's definition" . anything-c-find-variable)
6666 ("Set variable" . anything-c-set-variable)))
6667 "Variable.")
6669 (define-anything-type-attribute 'sexp
6670 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
6671 ("Add s-expression to kill ring" . kill-new))
6672 (action-transformer anything-c-transform-sexp-eval-command-sexp))
6673 "String representing S-Expressions.")
6675 (define-anything-type-attribute 'bookmark
6676 `((action
6677 ("Jump to bookmark" . (lambda (candidate)
6678 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate))
6679 (current-prefix-arg anything-current-prefix-arg))
6680 (bookmark-jump bookmark))
6681 (anything-update)))
6682 ("Jump to BM other window" . (lambda (candidate)
6683 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6684 (bookmark-jump-other-window bookmark))
6685 (anything-update)))
6686 ("Bookmark edit annotation" . (lambda (candidate)
6687 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6688 (bookmark-edit-annotation bookmark))))
6689 ("Bookmark show annotation" . (lambda (candidate)
6690 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6691 (bookmark-show-annotation bookmark))))
6692 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
6693 ,@(when (fboundp 'bmkext-edit-bookmark)
6694 '(("Edit Bookmark" . (lambda (candidate)
6695 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6696 (bmkext-edit-bookmark bookmark))))))
6697 ("Rename bookmark" . (lambda (candidate)
6698 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6699 (bookmark-rename bookmark))))
6700 ("Relocate bookmark" . (lambda (candidate)
6701 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6702 (bookmark-relocate bookmark))))))
6703 "Bookmark name.")
6705 (define-anything-type-attribute 'line
6706 '((display-to-real . anything-c-display-to-real-line)
6707 (action ("Go to Line" . anything-c-action-line-goto)))
6708 "LINENO:CONTENT string, eg. \" 16:foo\".
6710 Optional `target-file' attribute is a name of target file.
6712 Optional `before-jump-hook' attribute is a function with no
6713 arguments which is called before jumping to position.
6715 Optional `after-jump-hook' attribute is a function with no
6716 arguments which is called after jumping to position.
6718 If `adjust' attribute is specified, searches the line whose
6719 content is CONTENT near the LINENO.
6721 If `recenter' attribute is specified, the line is displayed at
6722 the center of window, otherwise at the top of window.
6725 (define-anything-type-attribute 'file-line
6726 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
6727 (multiline)
6728 (action ("Go to" . anything-c-action-file-line-goto)))
6729 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
6731 Optional `default-directory' attribute is a default-directory
6732 FILENAME is interpreted.
6734 Optional `before-jump-hook' attribute is a function with no
6735 arguments which is called before jumping to position.
6737 Optional `after-jump-hook' attribute is a function with no
6738 arguments which is called after jumping to position.
6740 If `adjust' attribute is specified, searches the line whose
6741 content is CONTENT near the LINENO.
6743 If `recenter' attribute is specified, the line is displayed at
6744 the center of window, otherwise at the top of window.
6747 (define-anything-type-attribute 'timer
6748 '((real-to-display . anything-c-timer-real-to-display)
6749 (action ("Cancel Timer" . cancel-timer)
6750 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
6751 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
6752 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
6753 (persistent-help . "Describe Function"))
6754 "Timer.")
6756 ;;;; Default `anything-sources'
6757 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
6758 ;; tend to invoke M-x anything directly. So I offer default setting.
6759 (setq anything-sources
6760 '(anything-c-source-buffers+
6761 anything-c-source-recentf
6762 anything-c-source-files-in-current-dir+))
6764 ;;;; unit test
6765 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
6766 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6767 (dont-compile
6768 (when (fboundp 'expectations)
6769 (expectations
6770 (desc "candidates-file plug-in")
6771 (expect '(anything-p-candidats-file-init)
6772 (assoc-default 'init
6773 (car (anything-compile-sources
6774 '(((name . "test")
6775 (candidates-file . "test.txt")))
6776 '(anything-compile-source--candidates-file)))))
6777 (expect '(anything-p-candidats-file-init
6778 (lambda () 1))
6779 (assoc-default 'init
6780 (car (anything-compile-sources
6781 '(((name . "test")
6782 (candidates-file . "test.txt")
6783 (init . (lambda () 1))))
6784 '(anything-compile-source--candidates-file)))))
6785 (expect '(anything-p-candidats-file-init
6786 (lambda () 1))
6787 (assoc-default 'init
6788 (car (anything-compile-sources
6789 '(((name . "test")
6790 (candidates-file . "test.txt")
6791 (init (lambda () 1))))
6792 '(anything-compile-source--candidates-file)))))
6793 (desc "anything-c-source-buffers")
6794 (expect '(("Buffers" ("foo" "curbuf")))
6795 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
6796 (let ((anything-c-boring-buffer-regexp
6797 (rx (or
6798 (group bos " ")
6799 "*anything"
6800 ;; echo area
6801 " *Echo Area" " *Minibuf"))))
6802 (flet ((buffer-name (x) x))
6803 (anything-test-candidates 'anything-c-source-buffers))))
6804 (desc "anything-c-stringify")
6805 (expect "str1"
6806 (anything-c-stringify "str1"))
6807 (expect "str2"
6808 (anything-c-stringify 'str2))
6809 (desc "anything-c-symbolify")
6810 (expect 'sym1
6811 (anything-c-symbolify "sym1"))
6812 (expect 'sym2
6813 (anything-c-symbolify 'sym2)))))
6815 (provide 'anything-config)
6817 ;;; Local Variables:
6818 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
6819 ;;; End:
6821 ;; How to save (DO NOT REMOVE!!)
6822 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
6823 ;;; anything-config.el ends here
6825 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
6826 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
6827 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
6828 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
6829 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
6830 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
6831 ;;; LocalWords: dotimes Thierry online vname
6832 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
6833 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
6834 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
6835 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
6836 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
6837 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
6838 ;;; LocalWords: startpos noselect dont desc