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