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