anything-config.el (anything-show-kill-ring): enable-recursive-minibuffers = t
[anything-config.git] / anything-config.el
blob856949681f72494e350741b42af82cd37ee175ff
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-list-emacs-process'
141 ;; Preconfigured `anything' for emacs process.
142 ;; `anything-occur'
143 ;; Preconfigured Anything for Occur source.
144 ;; `anything-browse-code'
145 ;; Preconfigured anything to browse code.
146 ;; `anything-org-headlines'
147 ;; Preconfigured anything to show org headlines.
148 ;; `anything-kill-buffers'
149 ;; Preconfigured `anything' to kill buffer you selected.
150 ;; `anything-regexp'
151 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
152 ;; `anything-insert-buffer-name'
153 ;; Insert buffer name.
154 ;; `anything-insert-symbol'
155 ;; Insert current symbol.
156 ;; `anything-insert-selection'
157 ;; Insert current selection.
158 ;; `anything-show-buffer-only'
159 ;; [OBSOLETE] Only show sources about buffer.
160 ;; `anything-show-bbdb-only'
161 ;; [OBSOLETE] Only show sources about BBDB.
162 ;; `anything-show-locate-only'
163 ;; [OBSOLETE] Only show sources about Locate.
164 ;; `anything-show-info-only'
165 ;; [OBSOLETE] Only show sources about Info.
166 ;; `anything-show-imenu-only'
167 ;; [OBSOLETE] Only show sources about Imenu.
168 ;; `anything-show-files-only'
169 ;; [OBSOLETE] Only show sources about File.
170 ;; `anything-show-w3m-bookmarks-only'
171 ;; [OBSOLETE] Only show source about w3m bookmark.
172 ;; `anything-show-colors-only'
173 ;; [OBSOLETE] Only show source about color.
174 ;; `anything-show-kill-ring-only'
175 ;; [OBSOLETE] Only show source about kill ring.
176 ;; `anything-show-this-source-only'
177 ;; Only show this source.
178 ;; `anything-test-sources'
179 ;; List all anything sources for test.
180 ;; `anything-select-source'
181 ;; Select source.
182 ;; `anything-find-files-down-one-level'
183 ;; Go down one level like unix command `cd ..'.
184 ;; `anything-find-files'
185 ;; Preconfigured `anything' for anything implementation of `find-file'.
186 ;; `anything-write-file'
187 ;; Preconfigured `anything' providing completion for `write-file'.
188 ;; `anything-insert-file'
189 ;; Preconfigured `anything' providing completion for `insert-file'.
190 ;; `anything-dired-rename-file'
191 ;; Preconfigured `anything' to rename files from dired.
192 ;; `anything-dired-copy-file'
193 ;; Preconfigured `anything' to copy files from dired.
194 ;; `anything-dired-symlink-file'
195 ;; Preconfigured `anything' to symlink files from dired.
196 ;; `anything-dired-hardlink-file'
197 ;; Preconfigured `anything' to hardlink files from dired.
198 ;; `anything-dired-bindings'
199 ;; Replace usual dired commands `C' and `R' by anything ones.
200 ;; `anything-do-grep'
201 ;; Preconfigured anything for grep.
202 ;; `anything-c-grep-precedent-file'
203 ;; Go to precedent file in `anything-do-grep'.
204 ;; `anything-c-grep-next-or-prec-file'
205 ;; Go to next or precedent candidate file in anything grep buffer.
206 ;; `anything-filelist'
207 ;; Preconfigured `anything' to open files instantly.
208 ;; `anything-filelist+'
209 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
210 ;; `anything-M-x'
211 ;; Preconfigured `anything' for Emacs commands.
212 ;; `anything-manage-advice'
213 ;; Preconfigured `anything' to disable/enable function advices.
214 ;; `anything-bookmark-ext'
215 ;; Preconfigured `anything' for bookmark-extensions sources.
216 ;; `anything-simple-call-tree'
217 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
218 ;; `anything-mark-ring'
219 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
220 ;; `anything-global-mark-ring'
221 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
222 ;; `anything-all-mark-rings'
223 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
224 ;; `anything-yaoddmuse-cache-pages'
225 ;; Fetch the list of files on emacswiki and create cache file.
226 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
227 ;; Preconfigured `anything' to edit or view EmacsWiki page.
228 ;; `anything-yaoddmuse-emacswiki-post-library'
229 ;; Preconfigured `anything' to post library to EmacsWiki.
230 ;; `anything-eval-expression'
231 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
232 ;; `anything-eval-expression-with-eldoc'
233 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
234 ;; `anything-surfraw'
235 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
236 ;; `anything-call-source'
237 ;; Preconfigured `anything' to call anything source.
238 ;; `anything-call-source-from-anything'
239 ;; Call anything source within `anything' session.
240 ;; `anything-execute-anything-command'
241 ;; Preconfigured `anything' to execute preconfigured `anything'.
242 ;; `anything-create-from-anything'
243 ;; Run `anything-create' from `anything' as a fallback.
244 ;; `anything-create'
245 ;; Preconfigured `anything' to do many create actions from STRING.
246 ;; `anything-top'
247 ;; Preconfigured `anything' for top command.
248 ;; `anything-select-xfont'
249 ;; Preconfigured `anything' to select Xfont.
250 ;; `anything-world-time'
251 ;; Preconfigured `anything' to show world time.
252 ;; `anything-apt'
253 ;; Preconfigured `anything' : frontend of APT package manager.
254 ;; `anything-c-shell-command-if-needed'
255 ;; Not documented.
256 ;; `anything-c-run-external-command'
257 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
258 ;; `anything-ratpoison-commands'
259 ;; Preconfigured `anything' to execute ratpoison commands.
260 ;; `anything-c-set-variable'
261 ;; Set value to VAR interactively.
262 ;; `anything-c-adaptive-save-history'
263 ;; Save history information to file given by `anything-c-adaptive-history-file'.
265 ;; * User variables defined here:
266 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
267 ;; `anything-c-use-standard-keys'
268 ;; Default Value: nil
269 ;; `anything-c-adaptive-history-file'
270 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
271 ;; `anything-c-adaptive-history-length'
272 ;; Default Value: 50
273 ;; `anything-c-google-suggest-url'
274 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
275 ;; `anything-c-google-suggest-search-url'
276 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
277 ;; `anything-google-suggest-use-curl-p'
278 ;; Default Value: nil
279 ;; `anything-c-yahoo-suggest-url'
280 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
281 ;; `anything-c-yahoo-suggest-search-url'
282 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
283 ;; `anything-c-boring-buffer-regexp'
284 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
285 ;; `anything-c-boring-file-regexp'
286 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
287 ;; `anything-kill-ring-threshold'
288 ;; Default Value: 10
289 ;; `anything-su-or-sudo'
290 ;; Default Value: "su"
291 ;; `anything-for-files-prefered-list'
292 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
293 ;; `anything-create--actions-private'
294 ;; Default Value: nil
295 ;; `anything-allow-skipping-current-buffer'
296 ;; Default Value: t
297 ;; `anything-c-enable-eval-defun-hack'
298 ;; Default Value: t
299 ;; `anything-tramp-verbose'
300 ;; Default Value: 0
301 ;; `anything-raise-command'
302 ;; Default Value: nil
303 ;; `anything-command-map-prefix-key'
304 ;; Default Value: "<f5> a"
305 ;; `anything-c-find-files-show-icons'
306 ;; Default Value: t
307 ;; `anything-c-find-files-icons-directory'
308 ;; Default Value: "/usr/share/emacs/23.2.50/etc/images/tree-widget/default"
309 ;; `anything-c-browse-code-regexp-lisp'
310 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
311 ;; `anything-c-browse-code-regexp-python'
312 ;; Default Value: "\\<def\\>\\|\\<class\\>"
313 ;; `anything-c-browse-code-regexp-alist'
314 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
315 ;; `anything-c-external-programs-associations'
316 ;; Default Value: nil
317 ;; `anything-c-filelist-file-name'
318 ;; Default Value: nil
320 ;; * Anything sources defined here:
321 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
322 ;; `anything-c-source-regexp' (Regexp Builder)
323 ;; `anything-c-source-buffers' (Buffers)
324 ;; `anything-c-source-buffer-not-found' (Create buffer)
325 ;; `anything-c-source-buffers+' (Buffers)
326 ;; `anything-c-source-file-name-history' (File Name History)
327 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
328 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
329 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
330 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
331 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
332 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
333 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
334 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
335 ;; `anything-c-source-file-cache-initialized' ()
336 ;; `anything-c-source-file-cache' (File Cache)
337 ;; `anything-c-source-locate' (Locate)
338 ;; `anything-c-source-recentf' (Recentf)
339 ;; `anything-c-source-ffap-guesser' (File at point)
340 ;; `anything-c-source-ffap-line' (File/Lineno at point)
341 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
342 ;; `anything-c-source-filelist' (FileList)
343 ;; `anything-c-source-info-pages' (Info Pages)
344 ;; `anything-c-source-info-elisp' (Info index: elisp)
345 ;; `anything-c-source-info-cl' (Info index: cl)
346 ;; `anything-c-source-info-org' (Info index: org)
347 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
348 ;; `anything-c-source-info-zsh' (Info index: zsh)
349 ;; `anything-c-source-info-bash' (Info index: bash)
350 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
351 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
352 ;; `anything-c-source-info-find' (Info index: find)
353 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
354 ;; `anything-c-source-info-textutils' (Info index: textutils)
355 ;; `anything-c-source-info-libc' (Info index: libc)
356 ;; `anything-c-source-info-make' (Info index: make)
357 ;; `anything-c-source-info-automake' (Info index: automake)
358 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
359 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
360 ;; `anything-c-source-info-emacs' (Info index: emacs)
361 ;; `anything-c-source-info-elib' (Info index: elib)
362 ;; `anything-c-source-info-eieio' (Info index: eieio)
363 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
364 ;; `anything-c-source-info-guile' (Info index: guile)
365 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
366 ;; `anything-c-source-info-goops' (Info index: goops)
367 ;; `anything-c-source-info-screen' (Info index: screen)
368 ;; `anything-c-source-info-latex' (Info index: latex)
369 ;; `anything-c-source-info-gawk' (Info index: gawk)
370 ;; `anything-c-source-info-sed' (Info index: sed)
371 ;; `anything-c-source-info-m4' (Info index: m4)
372 ;; `anything-c-source-info-wget' (Info index: wget)
373 ;; `anything-c-source-info-binutils' (Info index: binutils)
374 ;; `anything-c-source-info-as' (Info index: as)
375 ;; `anything-c-source-info-bfd' (Info index: bfd)
376 ;; `anything-c-source-info-gprof' (Info index: gprof)
377 ;; `anything-c-source-info-ld' (Info index: ld)
378 ;; `anything-c-source-info-diff' (Info index: diff)
379 ;; `anything-c-source-info-flex' (Info index: flex)
380 ;; `anything-c-source-info-grep' (Info index: grep)
381 ;; `anything-c-source-info-gzip' (Info index: gzip)
382 ;; `anything-c-source-info-libtool' (Info index: libtool)
383 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
384 ;; `anything-c-source-info-info' (Info index: info)
385 ;; `anything-c-source-info-gdb' (Info index: gdb)
386 ;; `anything-c-source-info-stabs' (Info index: stabs)
387 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
388 ;; `anything-c-source-info-cvs' (Info index: cvs)
389 ;; `anything-c-source-info-bison' (Info index: bison)
390 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
391 ;; `anything-c-source-info-global' (Info index: global)
392 ;; `anything-c-source-man-pages' (Manual Pages)
393 ;; `anything-c-source-complex-command-history' (Complex Command History)
394 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
395 ;; `anything-c-source-emacs-commands' (Emacs Commands)
396 ;; `anything-c-source-lacarte' (Lacarte)
397 ;; `anything-c-source-emacs-functions' (Emacs Functions)
398 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
399 ;; `anything-c-source-advice' (Function Advice)
400 ;; `anything-c-source-emacs-variables' (Emacs Variables)
401 ;; `anything-c-source-bookmarks' (Bookmarks)
402 ;; `anything-c-source-bookmark-set' (Set Bookmark)
403 ;; `anything-c-source-bm' (Visible Bookmarks)
404 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
405 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
406 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
407 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
408 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
409 ;; `anything-c-source-bookmark-images' (Bookmark Images)
410 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
411 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
412 ;; `anything-c-source-bookmark-info' (Bookmark Info)
413 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
414 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
415 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
416 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
417 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
418 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
419 ;; `anything-c-source-imenu' (Imenu)
420 ;; `anything-c-source-ctags' (Exuberant ctags)
421 ;; `anything-c-source-semantic' (Semantic Tags)
422 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
423 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
424 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
425 ;; `anything-c-source-customize-face' (Customize Face)
426 ;; `anything-c-source-colors' (Colors)
427 ;; `anything-c-source-tracker-search' (Tracker Search)
428 ;; `anything-c-source-mac-spotlight' (mdfind)
429 ;; `anything-c-source-kill-ring' (Kill Ring)
430 ;; `anything-c-source-mark-ring' (mark-ring)
431 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
432 ;; `anything-c-source-register' (Registers)
433 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
434 ;; `anything-c-source-rd-headline' (RD HeadLine)
435 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
436 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
437 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
438 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
439 ;; `anything-c-source-org-headline' (Org HeadLine)
440 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
441 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
442 ;; `anything-c-source-eev-anchor' (Anchors)
443 ;; `anything-c-source-org-keywords' (Org Keywords)
444 ;; `anything-c-source-picklist' (Picklist)
445 ;; `anything-c-source-bbdb' (BBDB)
446 ;; `anything-c-source-evaluation-result' (Evaluation Result)
447 ;; `anything-c-source-calculation-result' (Calculation Result)
448 ;; `anything-c-source-google-suggest' (Google Suggest)
449 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
450 ;; `anything-c-source-emms-streams' (Emms Streams)
451 ;; `anything-c-source-emms-dired' (Music Directory)
452 ;; `anything-c-source-emms-files' (Emms files)
453 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
454 ;; `anything-c-source-call-source' (Call anything source)
455 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
456 ;; `anything-c-source-occur' (Occur)
457 ;; `anything-c-source-browse-code' (Browse code)
458 ;; `anything-c-source-create' (Create)
459 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
460 ;; `anything-c-source-elscreen' (Elscreen)
461 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
462 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
463 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
464 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
465 ;; `anything-c-source-xfonts' (X Fonts)
466 ;; `anything-c-source-time-world' (Time World List)
467 ;; `anything-c-source-apt' (APT)
468 ;; `anything-c-source-gentoo' (Portage sources)
469 ;; `anything-c-source-use-flags' (Use Flags)
470 ;; `anything-c-source-emacs-process' (Emacs Process)
471 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
473 ;; *** END auto-documentation
476 ;;; Change log:
478 ;; Change log of this file is found at
479 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
481 ;; Change log of this project is found at
482 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
484 ;;; Contributors:
486 ;; Tamas Patrovics
487 ;; Tassilo Horn <tassilo@member.fsf.org>
488 ;; Vagn Johansen <gonz808@hotmail.com>
489 ;; Mathias Dahl <mathias.dahl@gmail.com>
490 ;; Bill Clementson <billclem@gmail.com>
491 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
492 ;; Drew Adams <drew.adams@oracle.com>
493 ;; Jason McBrayer <jmcbray@carcosa.net>
494 ;; Andy Stewart <lazycat.manatee@gmail.com>
495 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
496 ;; rubikitch <rubikitch@ruby-lang.org>
497 ;; Scott Vokes <vokes.s@gmail.com>
500 ;;; For Maintainers:
502 ;; Evaluate (autodoc-update-all) before commit. This function
503 ;; generates anything-c-source-* / functions / options list.
505 ;; Install also developer-tools/autodoc.el
506 ;; And eval it or run interactively.
508 ;; [EVAL IT] (autodoc-update-all)
510 ;; Please write details documentation about function, then others will
511 ;; read code more easier. -- Andy Stewart
515 ;;; TODO
517 ;; - Fix documentation, now many functions haven't documentations.
520 ;;; Require
521 (require 'anything)
522 (require 'thingatpt)
523 (require 'ffap)
524 (require 'cl)
526 ;;; Code:
528 ;; version check
529 (let ((version "1.263"))
530 (when (and (string= "1." (substring version 0 2))
531 (string-match "1\.\\([0-9]+\\)" anything-version)
532 (< (string-to-number (match-string 1 anything-version))
533 (string-to-number (substring version 2))))
534 (error "Please update anything.el!!
536 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
538 or M-x install-elisp-from-emacswiki anything.el")))
540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
541 (defgroup anything-config nil
542 "Predefined configurations for `anything.el'."
543 :group 'anything)
545 (defcustom anything-c-use-standard-keys nil
546 "Whether use standard keybindings. (no effect)
548 Key definitions in anything-config.el are removed because
549 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
550 minibuffer history, C-s for isearch, etc.
552 If you use `iswitchb' with `anything',
553 evaluate (anything-iswitchb-setup) . Then some bindings that
554 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
555 history, are removed from `anything-map'. "
556 :type 'boolean
557 :group 'anything-config)
559 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
560 "Path of file where history information is stored."
561 :type 'string
562 :group 'anything-config)
564 (defcustom anything-c-adaptive-history-length 50
565 "Maximum number of candidates stored for a source."
566 :type 'number
567 :group 'anything-config)
569 (defcustom anything-c-google-suggest-url
570 "http://google.com/complete/search?output=toolbar&q="
571 "URL used for looking up Google suggestions."
572 :type 'string
573 :group 'anything-config)
575 (defcustom anything-c-google-suggest-search-url
576 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
577 "URL used for Google searching."
578 :type 'string
579 :group 'anything-config)
581 (defcustom anything-google-suggest-use-curl-p nil
582 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
583 Otherwise `url-retrieve-synchronously' is used."
584 :type 'boolean
585 :group 'anything-config)
587 (defcustom anything-c-yahoo-suggest-url
588 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
589 "Url used for looking up Yahoo suggestions."
590 :type 'string
591 :group 'anything-config)
593 (defcustom anything-c-yahoo-suggest-search-url
594 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
595 "Url used for Yahoo searching."
596 :type 'string
597 :group 'anything-config)
599 (defcustom anything-c-boring-buffer-regexp
600 (rx (or
601 (group bos " ")
602 ;; anything-buffer
603 "*anything"
604 ;; echo area
605 " *Echo Area" " *Minibuf"))
606 "The regexp that match boring buffers.
607 Buffer candidates matching this regular expression will be
608 filtered from the list of candidates if the
609 `anything-c-skip-boring-buffers' candidate transformer is used, or
610 they will be displayed with face `file-name-shadow' if
611 `anything-c-shadow-boring-buffers' is used."
612 :type 'string
613 :group 'anything-config)
614 ;; (string-match anything-c-boring-buffer-regexp "buf")
615 ;; (string-match anything-c-boring-buffer-regexp " hidden")
616 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
618 (defcustom anything-c-boring-file-regexp
619 (rx (or
620 ;; Boring directories
621 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
622 ;; Boring files
623 (and line-start ".#")
624 (and (or ".class" ".la" ".o" "~") eol)))
625 "The regexp that match boring files.
626 File candidates matching this regular expression will be
627 filtered from the list of candidates if the
628 `anything-c-skip-boring-files' candidate transformer is used, or
629 they will be displayed with face `file-name-shadow' if
630 `anything-c-shadow-boring-files' is used."
631 :type 'string
632 :group 'anything-config)
634 (defcustom anything-kill-ring-threshold 10
635 "*Minimum length to be listed by `anything-c-source-kill-ring'."
636 :type 'integer
637 :group 'anything-config)
639 (defcustom anything-su-or-sudo "su"
640 "What command to use for root access."
641 :type 'string
642 :group 'anything-config)
644 (defcustom anything-for-files-prefered-list
645 '(anything-c-source-ffap-line
646 anything-c-source-ffap-guesser
647 anything-c-source-buffers+
648 anything-c-source-recentf
649 anything-c-source-bookmarks
650 anything-c-source-file-cache
651 anything-c-source-files-in-current-dir+
652 anything-c-source-locate)
653 "Your prefered sources to find files."
654 :type 'list
655 :group 'anything-config)
657 (defcustom anything-create--actions-private nil
658 "User defined actions for `anything-create' / `anything-c-source-create'.
659 It is a list of (DISPLAY . FUNCTION) pairs like `action'
660 attribute of `anything-sources'.
662 It is prepended to predefined pairs."
663 :type 'list
664 :group 'anything-config)
666 (defcustom anything-allow-skipping-current-buffer t
667 "Show current buffer or not in anything buffer"
668 :type 'boolean
669 :group 'anything-config)
671 (defcustom anything-c-enable-eval-defun-hack t
672 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
673 This hack is invoked when pressing C-M-x in the form \
674 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
675 :type 'boolean
676 :group 'anything-config)
678 (defcustom anything-tramp-verbose 0
679 "*Just like `tramp-verbose' but specific to anything.
680 When set to 0 don't show tramp messages in anything.
681 If you want to have the default tramp messages set it to 3."
682 :type 'integer
683 :group 'anything-config)
685 (defcustom anything-raise-command nil
686 "*A shell command to jump to a window running specific program.
687 Need external program wmctrl.
688 This will be use with `format', so use something like \"wmctrl -xa %s\"."
689 :type 'string
690 :group 'anything-config)
692 (defun anything-set-anything-command-map-prefix-key (var key)
693 (when (boundp 'anything-command-map-prefix-key)
694 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
695 (setq anything-command-map-prefix-key key)
696 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
697 'anything-command-map))
699 (defcustom anything-command-map-prefix-key "<f5> a"
700 "*The prefix key for all `anything-command-map' commands.
702 !!WARNING!!
703 This default value is very likely to be changed,
704 because it is under discussion."
705 :type 'string
706 :set 'anything-set-anything-command-map-prefix-key
707 :group 'anything-config)
709 (defcustom anything-c-find-files-show-icons nil
710 "*Whether show or hide icons in `anything-find-files'."
711 :type 'boolean
712 :group 'anything-config)
714 (defcustom anything-c-find-files-icons-directory
715 (concat (car image-load-path) "tree-widget/default")
716 "*Default path where to find files and directory icons."
717 :type 'string
718 :group 'anything-config)
720 (defcustom anything-c-browse-code-regexp-lisp
721 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
722 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
723 "*Regexp used to parse lisp buffer when browsing code."
724 :type 'string
725 :group 'anything-config)
727 (defcustom anything-c-browse-code-regexp-python
728 "\\<def\\>\\|\\<class\\>"
729 "*Regexp used to parse python buffer when browsing code."
730 :type 'string
731 :group 'anything-config)
733 (defcustom anything-c-browse-code-regexp-alist
734 `((lisp-interaction-mode . ,anything-c-browse-code-regexp-lisp)
735 (emacs-lisp-mode . ,anything-c-browse-code-regexp-lisp)
736 (lisp-mode . ,anything-c-browse-code-regexp-lisp)
737 (python-mode . ,anything-c-browse-code-regexp-python))
738 "*Alist to store regexps for browsing code corresponding \
739 to a specific `major-mode'."
740 :type 'list
741 :group 'anything-config)
743 (defcustom anything-c-external-programs-associations nil
744 "*Alist to store externals programs associated with file extension.
745 This variable overhide setting in .mailcap file.
746 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
747 :type 'list
748 :group 'anything-config)
750 ;;;###autoload
751 (defun anything-configuration ()
752 "Customize `anything'."
753 (interactive)
754 (customize-group "anything-config"))
756 ;;; Anything-command-map
757 ;;;###autoload
758 (defvar anything-command-map)
759 (define-prefix-command 'anything-command-map)
761 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
762 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
763 (define-key anything-command-map (kbd "e") 'anything-etags-maybe-at-point)
764 (define-key anything-command-map (kbd "l") 'anything-locate)
765 (define-key anything-command-map (kbd "s") 'anything-surfraw)
766 (define-key anything-command-map (kbd "r") 'anything-regexp)
767 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
768 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
769 (define-key anything-command-map (kbd "#") 'anything-emms)
770 (define-key anything-command-map (kbd "m") 'anything-man-woman)
771 (define-key anything-command-map (kbd "t") 'anything-top)
772 (define-key anything-command-map (kbd "i") 'anything-imenu)
773 (define-key anything-command-map (kbd "p") 'anything-list-emacs-process)
774 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
775 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
776 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
777 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
778 (define-key anything-command-map (kbd "f") 'anything-for-files)
779 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
780 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
781 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
782 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
783 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
784 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
785 (define-key anything-command-map (kbd "M-g s") 'anything-do-grep)
786 (define-key anything-command-map (kbd "c") 'anything-colors)
787 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
788 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
789 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
790 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
791 (define-key anything-command-map (kbd "h r") 'anything-info-emacs)
792 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers+)
793 (define-key anything-command-map (kbd "C-c C-b") 'anything-browse-code)
794 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
795 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
797 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
798 ;; minibuffer-local-filename-must-match-map.
799 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
800 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
801 (dolist (map (list minibuffer-local-filename-completion-map
802 minibuffer-local-completion-map
803 minibuffer-local-must-match-filename-map
804 minibuffer-local-filename-must-match-map
805 minibuffer-local-map
806 minibuffer-local-isearch-map
807 minibuffer-local-must-match-map
808 minibuffer-local-ns-map))
809 (define-key map "\C-r" 'anything-minibuffer-history))
811 ;;; Menu
812 (easy-menu-define nil global-map
813 "`anything' menu"
814 '("Anything"
815 ["All anything commands" anything-execute-anything-command t]
816 ["Find any Files/Buffers" anything-for-files t]
817 "----"
818 ("Files:"
819 ["Find files" anything-find-files t]
820 ["Recent Files" anything-recentf t]
821 ["Locate" anything-locate t]
822 ["Bookmarks" anything-c-pp-bookmarks t])
823 ("Buffers:"
824 ["Find buffers" anything-buffers+ t])
825 ("Commands:"
826 ["Emacs Commands" anything-M-x t]
827 ["Externals Commands" anything-c-run-external-command t])
828 ("Info:"
829 ["Info at point" anything-info-at-point t]
830 ["Emacs Manual index" anything-info-emacs t])
831 ("Org:"
832 ["Org keywords" anything-org-keywords t]
833 ["Org headlines" anything-org-headlines t])
834 ("Tools:"
835 ["Occur" anything-occur t]
836 ["Grep" anything-do-grep t]
837 ["Browse Kill ring" anything-show-kill-ring t]
838 ["Browse register" anything-register t]
839 ["Browse code" anything-browse-code t]
840 ["Mark Ring" anything-all-mark-rings t]
841 ["Regexp handler" anything-regexp t]
842 ["Colors & Faces" anything-colors t]
843 ["Show xfonts" anything-select-xfont t]
844 ["Imenu" anything-imenu t]
845 ["Google Suggest" anything-google-suggest t]
846 ["Eval expression" anything-eval-expression-with-eldoc t]
847 ["Calcul expression" anything-calcul-expression t]
848 ["Man pages" anything-man-woman t]
849 ["Top externals process" anything-top t]
850 ["Emacs internals process" anything-list-emacs-process t])
851 "----"
852 ["Prefered Options" anything-configuration t]))
855 ;;; Documentation
856 ;; It is replaced by `anything-help'
857 (defun anything-c-describe-anything-bindings ()
858 "[OBSOLETE] Describe `anything' bindings."
859 (interactive)
860 (anything-run-after-quit
861 #'(lambda ()
862 (with-current-buffer (get-buffer-create "*Anything Help*")
863 (erase-buffer)
864 (insert
865 (substitute-command-keys
866 "The keys that are defined for `anything' are:
867 \\{anything-map}")))
868 (pop-to-buffer "*Anything Help*")
869 (goto-char (point-min)))))
871 ;; Use `describe-mode' key in `global-map'
872 ;; (dolist (k (where-is-internal 'describe-mode global-map))
873 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
875 ;;; Help message
876 (defun anything-c-list-preconfigured-anything ()
877 (loop with doc
878 with sym
879 for entry in (cdr (assoc
880 (file-truename (locate-library "anything-config"))
881 load-history))
882 if (and (consp entry)
883 (eq (car entry) 'defun)
884 (string-match "^Preconfigured.+$"
885 (setq doc (or (documentation (setq sym (cdr entry)))
886 ""))))
887 collect (cons sym (match-string 0 doc))))
889 (defun anything-c-format-preconfigured-anything ()
890 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
891 (anything-c-list-preconfigured-anything)))
893 (setq anything-help-message
894 (lambda ()
895 (concat
896 "\\<anything-map>"
897 "`anything' is QuickSilver-like candidate-selection framework.
899 Narrow the list by typing some pattern,
900 Multiple patterns are allowed by splitting by space.
901 Select with natural Emacs operations, choose with RET.
903 If you have any problems, press C-c C-x C-b!!
904 Feel free to send bug reports. I'll fix them.
905 The steps are described in the beginning of anything.el file.
907 == Basic Operations ==
908 C-p, Up: Previous Line
909 C-n, Down : Next Line
910 M-v, PageUp : Previous Page
911 C-v, PageDown : Next Page
912 Enter : Execute first (default) action / Select
913 M-< : First Line
914 M-> : Last Line
915 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
916 M-PageDown, C-M-v : Next Page (other-window)
918 Tab, C-i : Show action list
919 Left : Previous Source
920 Right, C-o : Next Source
921 C-k : Delete pattern
922 C-z : Persistent Action (Execute action with anything session kept)
923 C-c C-x C-b: Send a bug report
925 == Shortcuts For 2nd/3rd Action ==
926 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
927 \\[anything-select-3rd-action] : Execute 3rd Action
929 == Visible Marks ==
930 Visible marks store candidate. Some actions uses marked candidates.
932 \\[anything-toggle-visible-mark] : Toggle Visible Mark
933 \\[anything-prev-visible-mark] : Previous Mark
934 \\[anything-next-visible-mark] : Next Mark
936 == Miscellaneous Commands ==
937 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
938 \\[anything-quit-and-find-file] : Drop into `find-file'
939 \\[anything-delete-current-selection] : Delete Selected Item (visually)
940 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
941 \\[anything-yank-selection] : Yank Selected Item Into Pattern
942 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
943 \\[anything-force-update] : Recalculate And Redisplay Candidates
945 == Global Commands ==
946 \\<global-map>\\[anything-resume] revives last `anything' session.
947 It is very useful, so you should bind any key.
949 Single source is executed by \\[anything-call-source].
951 == Preconfigured `anything' ==
952 Preconfigured `anything' is commands that uses `anything' interface.
953 You can use them without configuration.
956 (apply 'concat (anything-c-format-preconfigured-anything))
958 Enjoy!")))
960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
961 ;;;###autoload
962 (defun anything-mini ()
963 "Preconfigured `anything' lightweight version (buffer -> recentf)."
964 (interactive)
965 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf)
966 "*anything mini*"))
967 ;;;###autoload
968 (defun anything-for-files ()
969 "Preconfigured `anything' for opening files.
970 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
971 (interactive)
972 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
974 ;;;###autoload
975 (defun anything-recentf ()
976 "Preconfigured `anything' for `recentf'."
977 (interactive)
978 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
980 ;;;###autoload
981 (defun anything-info-at-point ()
982 "Preconfigured `anything' for searching info at point."
983 (interactive)
984 (anything '(anything-c-source-info-elisp
985 anything-c-source-info-cl
986 anything-c-source-info-pages)
987 (thing-at-point 'symbol) nil nil nil "*anything info*"))
989 ;;;###autoload
990 (defun anything-info-emacs ()
991 "Preconfigured anything for Emacs manual index."
992 (interactive)
993 (anything-other-buffer 'anything-c-source-info-emacs "*info emacs*"))
995 ;;;###autoload
996 (defun anything-show-kill-ring ()
997 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
998 You may bind this command to M-y."
999 (interactive)
1000 (let ((enable-recursive-minibuffers t))
1001 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*")))
1003 ;;;###autoload
1004 (defun anything-minibuffer-history ()
1005 "Preconfigured `anything' for `minibuffer-history'."
1006 (interactive)
1007 (let ((enable-recursive-minibuffers t))
1008 (anything-other-buffer 'anything-c-source-minibuffer-history
1009 "*anything minibuffer-history*")))
1011 ;;;###autoload
1012 (defun anything-gentoo ()
1013 "Preconfigured `anything' for gentoo linux."
1014 (interactive)
1015 (anything-other-buffer '(anything-c-source-gentoo
1016 anything-c-source-use-flags)
1017 "*anything gentoo*"))
1019 ;;;###autoload
1020 (defun anything-imenu ()
1021 "Preconfigured `anything' for `imenu'."
1022 (interactive)
1023 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
1025 ;;;###autoload
1026 (defun anything-google-suggest ()
1027 "Preconfigured `anything' for google search with google suggest."
1028 (interactive)
1029 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
1031 ;;;###autoload
1032 (defun anything-yahoo-suggest ()
1033 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1034 (interactive)
1035 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
1037 ;;; Converted from anything-show-*-only
1038 ;;;###autoload
1039 (defun anything-for-buffers ()
1040 "Preconfigured `anything' for buffer."
1041 (interactive)
1042 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
1044 ;;;###autoload
1045 (defun anything-buffers+ ()
1046 "Enhanced preconfigured `anything' for buffer."
1047 (interactive)
1048 (anything-other-buffer 'anything-c-source-buffers+ "*anything buffers*"))
1050 ;;;###autoload
1051 (defun anything-bbdb ()
1052 "Preconfigured `anything' for BBDB.
1054 Needs BBDB.
1056 http://bbdb.sourceforge.net/"
1057 (interactive)
1058 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
1060 ;;;###autoload
1061 (defun anything-locate ()
1062 "Preconfigured `anything' for Locate.
1063 Note you can add locate command after entering pattern.
1064 See man locate for more infos."
1065 (interactive)
1066 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
1068 ;;;###autoload
1069 (defun anything-w3m-bookmarks ()
1070 "Preconfigured `anything' for w3m bookmark.
1072 Needs w3m and emacs-w3m.
1074 http://w3m.sourceforge.net/
1075 http://emacs-w3m.namazu.org/"
1076 (interactive)
1077 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1078 "*anything w3m bookmarks*"))
1080 ;;;###autoload
1081 (defun anything-firefox-bookmarks ()
1082 "Preconfigured `anything' for firefox bookmark.
1083 You will have to enable html bookmarks in firefox:
1084 open about:config in firefox and double click on this line to enable value \
1085 to true:
1087 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1089 You should have now:
1091 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1093 After closing firefox, you will be able to browse you bookmarks.
1095 (interactive)
1096 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1097 "*Anything Firefox*"))
1099 ;;;###autoload
1100 (defun anything-colors ()
1101 "Preconfigured `anything' for color."
1102 (interactive)
1103 (anything-other-buffer
1104 '(anything-c-source-colors anything-c-source-customize-face)
1105 "*anything colors*"))
1107 ;;;###autoload
1108 (defun anything-bookmarks ()
1109 "Preconfigured `anything' for bookmarks."
1110 (interactive)
1111 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
1113 ;;;###autoload
1114 (defun anything-c-pp-bookmarks ()
1115 "Preconfigured `anything' for bookmarks (pretty-printed)."
1116 (interactive)
1117 (anything-other-buffer '(anything-c-source-bookmarks-local
1118 anything-c-source-bookmarks-su
1119 anything-c-source-bookmarks-ssh)
1120 "*anything pp bookmarks*"))
1122 ;;;###autoload
1123 (defun anything-register ()
1124 "Preconfigured `anything' for Emacs registers."
1125 (interactive)
1126 (anything-other-buffer 'anything-c-source-register "*anything register*"))
1128 ;;;###autoload
1129 (defun anything-man-woman ()
1130 "Preconfigured `anything' for Man and Woman pages."
1131 (interactive)
1132 (anything-other-buffer 'anything-c-source-man-pages "*Anything man woman*"))
1134 ;;;###autoload
1135 (defun anything-org-keywords ()
1136 "Preconfigured `anything' for org keywords."
1137 (interactive)
1138 (anything-other-buffer 'anything-c-source-org-keywords "*org keywords*"))
1140 ;;;###autoload
1141 (defun anything-emms ()
1142 "Preconfigured `anything' for emms sources."
1143 (interactive)
1144 (anything '(anything-c-source-emms-streams
1145 anything-c-source-emms-files
1146 anything-c-source-emms-dired)
1147 nil nil nil nil
1148 "*Anything Emms*"))
1150 ;;;###autoload
1151 (defun anything-eev-anchors ()
1152 "Preconfigured `anything' for eev anchors."
1153 (interactive)
1154 (anything-other-buffer 'anything-c-source-eev-anchor "*Anything eev anchors*"))
1156 ;;;###autoload
1157 (defun anything-bm-list ()
1158 "Preconfigured `anything' for visible bookmarks.
1160 Needs bm.el
1162 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1163 (interactive)
1164 (let ((anything-outline-using t))
1165 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
1167 ;;;###autoload
1168 (defun anything-timers ()
1169 "Preconfigured `anything' for timers."
1170 (interactive)
1171 (anything-other-buffer '(anything-c-source-absolute-time-timers
1172 anything-c-source-idle-time-timers)
1173 "*anything timers*"))
1175 ;;;###autoload
1176 (defun anything-list-emacs-process ()
1177 "Preconfigured `anything' for emacs process."
1178 (interactive)
1179 (anything-other-buffer 'anything-c-source-emacs-process "*anything process*"))
1181 ;;;###autoload
1182 (defun anything-occur ()
1183 "Preconfigured Anything for Occur source."
1184 (interactive)
1185 (let ((anything-compile-source-functions
1186 ;; rule out anything-match-plugin because the input is one regexp.
1187 (delq 'anything-compile-source--match-plugin
1188 (copy-sequence anything-compile-source-functions))))
1189 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*")))
1191 ;;;###autoload
1192 (defun anything-browse-code ()
1193 "Preconfigured anything to browse code."
1194 (interactive)
1195 (anything-other-buffer 'anything-c-source-browse-code "*Browse code*"))
1197 ;;;###autoload
1198 (defun anything-org-headlines ()
1199 "Preconfigured anything to show org headlines."
1200 (interactive)
1201 (anything-other-buffer 'anything-c-source-org-headline "*org headlines*"))
1203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1204 ;;; kill buffers
1205 ;;;###autoload
1206 (defun anything-kill-buffers ()
1207 "Preconfigured `anything' to kill buffer you selected."
1208 (interactive)
1209 (anything
1210 '(((name . "Kill Buffers")
1211 (candidates . anything-c-buffer-list)
1212 (action
1213 ("Kill Buffer" . (lambda (candidate)
1214 (kill-buffer candidate)
1215 (anything-kill-buffers)
1216 )))))
1217 nil nil))
1219 ;;; Regexp
1220 (defun anything-c-query-replace-regexp (candidate)
1221 (let ((regexp (funcall (anything-attr 'regexp))))
1222 (apply 'query-replace-regexp
1223 (anything-c-query-replace-args regexp))))
1225 (defun anything-c-kill-regexp-as-sexp (candidate)
1226 (anything-c-regexp-kill-new
1227 (prin1-to-string (funcall (anything-attr 'regexp)))))
1229 (defun anything-c-kill-regexp (candidate)
1230 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp))))
1232 (defun anything-c-query-replace-args (regexp)
1233 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1234 (let ((region-only (anything-region-active-p)))
1235 (list
1236 regexp
1237 (query-replace-read-to regexp
1238 (format "Query replace %s regexp %s"
1239 (if anything-current-prefix-arg "word " "")
1240 (if region-only "in region " ""))
1242 anything-current-prefix-arg
1243 (when region-only (region-beginning))
1244 (when region-only (region-end)))))
1246 (defvar anything-c-source-regexp
1247 '((name . "Regexp Builder")
1248 (init . (lambda ()
1249 (anything-candidate-buffer anything-current-buffer)))
1250 (candidates-in-buffer)
1251 (get-line . anything-c-regexp-get-line)
1252 (persistent-action . anything-c-regexp-persistent-action)
1253 (persistent-help . "Show this line")
1254 (multiline)
1255 (delayed)
1256 (requires-pattern . 2)
1257 (mode-line . "Press TAB to select action.")
1258 ;; RUBIKITCH:
1259 ;; I use here `anything-input' because `anything-pattern' is lost when
1260 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1261 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1262 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1263 ;; Can you fix it?
1264 (regexp . (lambda () anything-input))
1265 (action . (("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp)
1266 ("Query Replace Regexp" . anything-c-query-replace-regexp)
1267 ("Kill Regexp" . anything-c-kill-regexp)))))
1269 (defun anything-c-regexp-get-line (s e)
1270 (propertize
1271 (apply 'concat
1272 ;; Line contents
1273 (format "%5d: %s" (line-number-at-pos (1- s)) (buffer-substring s e))
1274 ;; subexps
1275 (loop for i from 0 to (1- (/ (length (match-data)) 2))
1276 collect (format "\n %s'%s'"
1277 (if (zerop i) "Group 0: " (format "Group %d: " i))
1278 (match-string i))))
1279 ;; match beginning
1280 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1281 ;; It is implementation problem of candidates-in-buffer.
1282 'anything-realvalue
1283 (1- s)))
1285 ;; Shut up byte compiler
1286 (defun anything-goto-line (numline)
1287 "Replacement of `goto-line'."
1288 (goto-char (point-min))
1289 (forward-line (1- numline)))
1291 (defun anything-c-regexp-persistent-action (pt)
1292 (goto-char pt)
1293 (anything-persistent-highlight-point))
1295 (defun anything-c-regexp-kill-new (input)
1296 (kill-new input)
1297 (message "Killed: %s" input))
1299 (defun anything-region-active-p ()
1300 (and transient-mark-mode mark-active (/= (mark) (point))))
1302 (defun* anything-current-buffer-narrowed-p (&optional
1303 (buffer anything-current-buffer))
1304 "Check if BUFFER is narrowed.
1305 Default is `anything-current-buffer'."
1306 (with-current-buffer buffer
1307 (let ((beg (point-min))
1308 (end (point-max))
1309 (total (buffer-size)))
1310 (or (/= beg 1) (/= end (1+ total))))))
1312 ;;;###autoload
1313 (defun anything-regexp ()
1314 "Preconfigured anything to build regexps and run query-replace-regexp \
1315 against."
1316 (interactive)
1317 (save-restriction
1318 (let ((anything-compile-source-functions
1319 ;; rule out anything-match-plugin because the input is one regexp.
1320 (delq 'anything-compile-source--match-plugin
1321 (copy-sequence anything-compile-source-functions))))
1322 (when (and (anything-region-active-p)
1323 ;; Don't narrow to region if buffer is already narrowed.
1324 (not (anything-current-buffer-narrowed-p)))
1325 (narrow-to-region (region-beginning) (region-end)))
1326 (anything :sources
1327 anything-c-source-regexp
1328 :buffer "*anything regexp*"
1329 :prompt "Regexp: "))))
1332 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1334 (defun anything-insert-buffer-name ()
1335 "Insert buffer name."
1336 (interactive)
1337 (anything-insert-string
1338 (with-current-buffer anything-current-buffer
1339 (if buffer-file-name (file-name-nondirectory buffer-file-name)
1340 (buffer-name)))))
1342 (defun anything-insert-symbol ()
1343 "Insert current symbol."
1344 (interactive)
1345 (anything-insert-string
1346 (with-current-buffer anything-current-buffer
1347 (save-excursion
1348 (buffer-substring (beginning-of-thing 'symbol)
1349 (end-of-thing 'symbol))))))
1351 (defun anything-insert-selection ()
1352 "Insert current selection."
1353 (interactive)
1354 (anything-insert-string
1355 (with-current-buffer anything-current-buffer
1356 (anything-get-selection))))
1358 (defun anything-show-buffer-only ()
1359 "[OBSOLETE] Only show sources about buffer.
1360 Use `anything-for-buffers' instead."
1361 (interactive)
1362 (anything-set-source-filter '("Buffers")))
1364 (defun anything-show-bbdb-only ()
1365 "[OBSOLETE] Only show sources about BBDB.
1366 Use `anything-bbdb' instead."
1367 (interactive)
1368 (anything-set-source-filter '("BBDB")))
1370 (defun anything-show-locate-only ()
1371 "[OBSOLETE] Only show sources about Locate.
1372 Use `anything-locate' instead."
1373 (interactive)
1374 (anything-set-source-filter '("Locate")))
1376 (defun anything-show-info-only ()
1377 "[OBSOLETE] Only show sources about Info.
1378 Use `anything-info-at-point' instead."
1379 (interactive)
1380 (anything-set-source-filter '("Info Pages"
1381 "Info Elisp"
1382 "Info Common-Lisp")))
1384 (defun anything-show-imenu-only ()
1385 "[OBSOLETE] Only show sources about Imenu.
1386 Use `anything-imenu' instead."
1387 (interactive)
1388 (anything-set-source-filter '("Imenu")))
1390 (defun anything-show-files-only ()
1391 "[OBSOLETE] Only show sources about File.
1392 Use `anything-for-files' instead."
1393 (interactive)
1394 (anything-set-source-filter '("File Name History"
1395 "Files from Current Directory"
1396 "Recentf")))
1398 (defun anything-show-w3m-bookmarks-only ()
1399 "[OBSOLETE] Only show source about w3m bookmark.
1400 Use `anything-w3m-bookmarks' instead."
1401 (interactive)
1402 (anything-set-source-filter '("W3m Bookmarks")))
1404 (defun anything-show-colors-only ()
1405 "[OBSOLETE] Only show source about color.
1406 Use `anything-colors' instead."
1407 (interactive)
1408 (anything-set-source-filter '("Colors"
1409 "Customize Faces")))
1411 (defun anything-show-kill-ring-only ()
1412 "[OBSOLETE] Only show source about kill ring.
1413 Use `anything-show-kill-ring' instead."
1414 (interactive)
1415 (anything-set-source-filter '("Kill Ring")))
1417 (defun anything-show-this-source-only ()
1418 "Only show this source."
1419 (interactive)
1420 (setq anything-candidate-number-limit 9999)
1421 (anything-set-source-filter
1422 (list (assoc-default 'name (anything-get-current-source)))))
1424 (defun anything-test-sources ()
1425 "List all anything sources for test.
1426 The output is sexps which are evaluated by \\[eval-last-sexp]."
1427 (interactive)
1428 (with-output-to-temp-buffer "*Anything Test Sources*"
1429 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
1430 (apropos-internal "^anything-c-source" #'boundp))
1431 (pop-to-buffer standard-output)))
1433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1434 ;;; For compatibility
1435 (unless (fboundp 'region-active-p)
1436 (defun region-active-p ()
1437 "Return t if Transient Mark mode is enabled and the mark is active.
1439 Most commands that act on the region if it is active and
1440 Transient Mark mode is enabled, and on the text near point
1441 otherwise, should use `use-region-p' instead. That function
1442 checks the value of `use-empty-active-region' as well."
1443 (and transient-mark-mode mark-active)))
1445 (defun anything-nest (&rest same-as-anything)
1446 "Nested `anything'. If you use `anything' within `anything', use it."
1447 (with-selected-window (anything-window)
1448 (let (anything-current-position
1449 anything-current-buffer
1450 (orig-anything-buffer anything-buffer)
1451 anything-pattern
1452 anything-buffer
1453 anything-sources
1454 anything-compiled-sources
1455 anything-buffer-chars-modified-tick
1456 (anything-samewindow t)
1457 (enable-recursive-minibuffers t))
1458 (unwind-protect
1459 (apply #'anything same-as-anything)
1460 (anything-initialize-overlays orig-anything-buffer)
1461 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
1463 (defun anything-displaying-source-names ()
1464 "Display sources name."
1465 (with-current-buffer anything-buffer
1466 (goto-char (point-min))
1467 (loop with pos
1468 while (setq pos (next-single-property-change (point) 'anything-header))
1469 do (goto-char pos)
1470 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1471 do (forward-line 1))))
1473 (defun anything-select-source ()
1474 "Select source."
1475 (interactive)
1476 (let ((default (assoc-default 'name (anything-get-current-source)))
1477 (source-names (anything-displaying-source-names))
1478 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
1479 (anything-get-sources))))
1480 (setq anything-candidate-number-limit 9999)
1481 (anything-aif
1482 (let (anything-source-filter)
1483 (anything-nest '(((name . "Anything Source")
1484 (candidates . source-names)
1485 (action . identity))
1486 ((name . "Anything Source (ALL)")
1487 (candidates . all-source-names)
1488 (action . identity)))
1489 nil "Source: " nil
1490 default "*anything select source*"))
1491 (anything-set-source-filter (list it))
1492 (anything-set-source-filter nil))))
1494 (defun anything-insert-string (str)
1495 "Insert STR."
1496 (delete-minibuffer-contents)
1497 (insert str))
1499 (defun anything-c-match-on-file-name (candidate)
1500 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1501 (string-match anything-pattern (file-name-nondirectory candidate)))
1503 (defun anything-c-match-on-directory-name (candidate)
1504 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1505 (anything-aif (file-name-directory candidate)
1506 (string-match anything-pattern it)))
1508 (defun anything-c-string-match (candidate)
1509 "Return non-nil if `anything-pattern' match CANDIDATE.
1510 The match is done with `string-match'."
1511 (string-match anything-pattern candidate))
1513 ;; `anything-c-compose' is no more needed, it is for compatibility.
1514 (defalias 'anything-c-compose 'anything-compose)
1516 (defun anything-c-skip-entries (list regexp)
1517 "Remove entries which matches REGEXP from LIST."
1518 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
1519 list))
1521 (defun anything-c-shadow-entries (list regexp)
1522 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1523 (mapcar (lambda (file)
1524 ;; Add shadow face property to boring files.
1525 (let ((face (if (facep 'file-name-shadow)
1526 'file-name-shadow
1527 ;; fall back to default on XEmacs
1528 'default)))
1529 (if (string-match regexp file)
1530 (setq file (propertize file 'face face))))
1531 file)
1532 list))
1534 (defsubst anything-c-stringify (str-or-sym)
1535 "Get string of STR-OR-SYM."
1536 (if (stringp str-or-sym)
1537 str-or-sym
1538 (symbol-name str-or-sym)))
1540 (defsubst anything-c-symbolify (str-or-sym)
1541 "Get symbol of STR-OR-SYM."
1542 (if (symbolp str-or-sym)
1543 str-or-sym
1544 (intern str-or-sym)))
1546 (defun anything-c-describe-function (func)
1547 "FUNC is symbol or string."
1548 (describe-function (anything-c-symbolify func)))
1550 (defun anything-c-describe-variable (var)
1551 "VAR is symbol or string."
1552 (describe-variable (anything-c-symbolify var)))
1554 (defun anything-c-find-function (func)
1555 "FUNC is symbol or string."
1556 (find-function (anything-c-symbolify func)))
1558 (defun anything-c-find-variable (var)
1559 "VAR is symbol or string."
1560 (find-variable (anything-c-symbolify var)))
1562 (defun anything-c-kill-new (string &optional replace yank-handler)
1563 "STRING is symbol or string."
1564 (kill-new (anything-c-stringify string) replace yank-handler))
1566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1567 ;; TODO: This should be integrated in anything.el instead of having
1568 ;; a defadvice here.
1570 (defvar anything-current-prefix-arg nil
1571 "Record `current-prefix-arg' when exiting minibuffer.
1572 It will be cleared at start of next `anything' call when \
1573 `anything-before-initialize-hook' is called.")
1575 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
1576 (unless anything-current-prefix-arg
1577 (setq anything-current-prefix-arg current-prefix-arg)))
1579 ;; using this hook instead of `anything-after-action-hook'
1580 ;; allow to record the prefix args and keep their values
1581 ;; when using `anything-comp-read'.
1582 (add-hook 'anything-before-initialize-hook
1583 (lambda () (setq anything-current-prefix-arg nil)))
1586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1587 (defadvice eval-defun (after anything-source-hack activate)
1588 "See `anything-c-enable-eval-defun-hack'."
1589 (when anything-c-enable-eval-defun-hack
1590 (let ((varsym (save-excursion
1591 (beginning-of-defun)
1592 (forward-char 1)
1593 (when (memq (read (current-buffer)) '(defvar setq))
1594 (read (current-buffer))))))
1595 (when (string-match "^anything-c-source-" (symbol-name varsym))
1596 (anything varsym)))))
1597 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1600 (defconst anything-c-create-summary-index-regexp
1601 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1602 (defun anything-c-create-summary ()
1603 "Create `anything' summary."
1604 (save-excursion
1605 (goto-char (point-min))
1606 (loop with it
1607 while (re-search-forward anything-c-create-summary-index-regexp nil t)
1608 collect
1609 (cond ((setq it (match-string-no-properties 1))
1610 (cons 'section it))
1611 ((setq it (match-string-no-properties 2))
1612 `(source ,it .
1613 ,(assoc-default 'name (symbol-value (intern it)))))
1614 ((setq it (match-string-no-properties 3))
1615 `(source ,it .
1616 ,(assoc-default 'name (symbol-value (intern it)))))))))
1618 ;; (find-epp (anything-c-create-summary))
1620 (defun anything-c-insert-summary ()
1621 "Insert `anything' summary."
1622 (save-excursion
1623 (goto-char (point-min))
1624 (search-forward ";; Below are complete source list you can setup in")
1625 (forward-line 1)
1626 (delete-region (point)
1627 (progn (search-forward ";;; Change log:" nil t)
1628 (forward-line -1) (point)))
1629 (insert ";;\n")
1630 (loop with beg
1631 for (kind . value) in (anything-c-create-summary)
1632 for i from 0
1633 do (cond ((eq kind 'section)
1634 (unless (zerop i)
1635 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1636 (insert ";; " value ":\n")
1637 (setq beg (point)))
1639 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
1640 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
1641 ;; (anything-c-insert-summary)
1643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1644 ;;;; <Buffer>
1645 (defun anything-c-buffer-list ()
1646 "Return the list of names of buffers with boring buffers filtered out.
1647 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1648 The first buffer in the list will be the last recently used
1649 buffer that is not the current buffer."
1650 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1651 (append (cdr buffers) (list (car buffers)))))
1653 (defvar anything-c-source-buffers
1654 '((name . "Buffers")
1655 (candidates . anything-c-buffer-list)
1656 (type . buffer)))
1657 ;; (anything 'anything-c-source-buffers)
1659 (defvar anything-c-source-buffer-not-found
1660 '((name . "Create buffer")
1661 (dummy)
1662 (type . buffer)))
1663 ;; (anything 'anything-c-source-buffer-not-found)
1665 ;;; Buffers+
1666 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1667 "*Face used for directory headings in dired buffers."
1668 :group 'anything)
1670 (defface anything-file-name
1671 '((t (:foreground "Blue")))
1672 "*Face used for file names (without suffixes) in dired buffers."
1673 :group 'anything)
1675 (defface anything-dir-priv
1676 '((t (:foreground "DarkRed" :background "LightGray")))
1677 "*Face used for directory privilege indicator (d) in dired buffers."
1678 :group 'anything)
1680 (defvar anything-c-buffers-face1 'anything-dir-priv)
1681 (defvar anything-c-buffers-face2 'font-lock-type-face)
1682 (defvar anything-c-buffers-face3 'italic)
1683 (eval-when-compile (require 'dired))
1684 (defun anything-c-highlight-buffers (buffers)
1685 (require 'dired)
1686 (loop for i in buffers
1687 if (rassoc (get-buffer i) dired-buffers)
1688 collect (propertize i
1689 'face anything-c-buffers-face1
1690 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1691 if (buffer-file-name (get-buffer i))
1692 collect (propertize i
1693 'face anything-c-buffers-face2
1694 'help-echo (buffer-file-name (get-buffer i)))
1695 if (and (not (rassoc (get-buffer i) dired-buffers))
1696 (not (buffer-file-name (get-buffer i))))
1697 collect (propertize i
1698 'face anything-c-buffers-face3)))
1700 (defvar anything-c-source-buffers+
1701 '((name . "Buffers")
1702 (candidates . anything-c-buffer-list)
1703 (type . buffer)
1704 (candidate-transformer anything-c-skip-current-buffer
1705 anything-c-highlight-buffers
1706 anything-c-skip-boring-buffers)
1707 (persistent-action . anything-c-buffers+-persistent-action)
1708 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1710 (defun anything-c-buffers+-persistent-action (name)
1711 (flet ((kill (item)
1712 (with-current-buffer item
1713 (if (and (buffer-modified-p)
1714 (buffer-file-name (current-buffer)))
1715 (progn
1716 (save-buffer)
1717 (kill-buffer item))
1718 (kill-buffer item))))
1719 (goto (item)
1720 (switch-to-buffer item)))
1721 (if current-prefix-arg
1722 (progn
1723 (kill name)
1724 (anything-delete-current-selection))
1725 (goto name))))
1727 ;; (anything 'anything-c-source-buffers+)
1730 ;;;; <File>
1731 ;;; File name history
1732 (defvar anything-c-source-file-name-history
1733 '((name . "File Name History")
1734 (candidates . file-name-history)
1735 (match anything-c-match-on-file-name
1736 anything-c-match-on-directory-name)
1737 (type . file)))
1738 ;; (anything 'anything-c-source-file-name-history)
1740 ;;; Files in current dir
1741 (defvar anything-c-source-files-in-current-dir
1742 '((name . "Files from Current Directory")
1743 (candidates . (lambda ()
1744 (with-current-buffer anything-current-buffer
1745 (directory-files (anything-c-current-directory)))))
1746 ;; volatile is not needed, I think.
1747 (type . file)))
1748 ;; (anything 'anything-c-source-files-in-current-dir)
1750 (defvar anything-c-files-face1 'anything-dir-priv)
1751 (defvar anything-c-files-face2 'anything-file-name)
1752 (defun anything-c-highlight-files (files)
1753 (loop for i in files
1754 if (file-directory-p i)
1755 collect (propertize (file-name-nondirectory i)
1756 'face anything-c-files-face1
1757 'help-echo (expand-file-name i))
1758 else
1759 collect (propertize (file-name-nondirectory i)
1760 'face anything-c-files-face2
1761 'help-echo (expand-file-name i))))
1764 (defvar anything-c-source-files-in-current-dir+
1765 '((name . "Files from Current Directory")
1766 (candidates . (lambda ()
1767 (with-current-buffer anything-current-buffer
1768 (directory-files (anything-c-current-directory) t))))
1769 (candidate-transformer anything-c-highlight-files)
1770 ;; volatile is not needed, I think.
1771 (type . file)))
1773 ;; (anything 'anything-c-source-files-in-current-dir+)
1775 ;;; Anything replacement of file name completion for `find-file' and friends.
1777 (defvar anything-c-find-files-doc-header (format " (`%s':Go to precedent level)"
1778 (if window-system "C-." "C-l"))
1779 "*The doc that is inserted in the Name header of a find-files or dired source.")
1781 (defvar anything-c-source-find-files
1782 `((name . ,(concat "Find Files" anything-c-find-files-doc-header))
1783 ;; It is needed for filenames with capital letters
1784 (disable-shortcuts)
1785 (init . (lambda ()
1786 (setq ffap-newfile-prompt t)))
1787 (candidates . anything-find-files-get-candidates)
1788 (filtered-candidate-transformer anything-c-find-files-transformer)
1789 (persistent-action . anything-find-files-persistent-action)
1790 (persistent-help . "Hit1 Expand Candidate, Hit2 or (C-u) Find file")
1791 (volatile)
1792 (action-transformer . anything-find-files-action-transformer)
1793 (action
1794 . ,(delq
1796 `(("Find File" . anything-c-find-file-or-marked)
1797 ("Find file in Dired" . anything-c-point-file-in-dired)
1798 ,(and (locate-library "elscreen")
1799 '("Find file in Elscreen" . anything-elscreen-find-file))
1800 ("Complete at point"
1801 . anything-c-insert-file-name-completion-at-point)
1802 ("Open file externally `C-u to choose'"
1803 . anything-c-open-file-externally)
1804 ("Grep File(s)" . (lambda (candidate)
1805 ;; Restore highlighting disabled in *-find-files.
1806 (let ((anything-mp-highlight-delay 0.7))
1807 (anything-do-grep (anything-marked-candidates)))))
1808 ("Ediff File" . anything-find-files-ediff-files)
1809 ("Ediff Merge File" . anything-find-files-ediff-merge-files)
1810 ("Delete File(s)" . anything-delete-marked-files)
1811 ("Copy file(s) `C-u to follow'" . anything-find-files-copy)
1812 ("Rename file(s) `C-u to follow'" . anything-find-files-rename)
1813 ("Symlink files(s) `C-u to follow'" . anything-find-files-symlink)
1814 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink)
1815 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink)
1816 ("Find file other window" . find-file-other-window)
1817 ("Find file other frame" . find-file-other-frame)
1818 ("Find file as root" . anything-find-file-as-root))))))
1819 ;; (anything 'anything-c-source-find-files)
1821 (defun anything-find-files-set-prompt-for-action (prompt files)
1822 "Set prompt for action in `anything-find-files'."
1823 (let ((len (length files)))
1824 (if (> len 1)
1825 (format "%s * %d Files to: " prompt len)
1826 (format "%s %s to: " prompt (car files)))))
1828 (defun anything-find-files-do-action (action)
1829 "Generic function for creating action from `anything-c-source-find-files'.
1830 ACTION must be an action supported by `anything-dired-action'."
1831 (let* ((ifiles (anything-marked-candidates))
1832 (prompt (anything-find-files-set-prompt-for-action
1833 (capitalize (symbol-name action)) ifiles))
1834 (parg anything-current-prefix-arg)
1835 (dest (anything-c-read-file-name
1836 prompt))
1837 (win-conf (current-window-configuration)))
1838 (unwind-protect
1839 ;; Create temporarily a dired buffer to call dired functions.
1840 (with-current-buffer (dired default-directory)
1841 (anything-dired-action
1842 dest :files ifiles :action action :follow parg)
1843 (kill-buffer))
1844 (unless parg (set-window-configuration win-conf)))))
1846 (defun anything-find-files-copy (candidate)
1847 "Copy files from `anything-find-files'."
1848 (anything-find-files-do-action 'copy))
1850 (defun anything-find-files-rename (candidate)
1851 "Rename files from `anything-find-files'."
1852 (anything-find-files-do-action 'rename))
1854 (defun anything-find-files-symlink (candidate)
1855 "Symlink files from `anything-find-files'."
1856 (anything-find-files-do-action 'symlink))
1858 (defun anything-find-files-relsymlink (candidate)
1859 "Relsymlink files from `anything-find-files'."
1860 (anything-find-files-do-action 'relsymlink))
1862 (defun anything-find-files-hardlink (candidate)
1863 "Hardlink files from `anything-find-files'."
1864 (anything-find-files-do-action 'hardlink))
1866 (defun anything-find-files-byte-compile (candidate)
1867 "Byte compile files from `anything-find-files'."
1868 (let ((files (anything-marked-candidates))
1869 (parg anything-current-prefix-arg))
1870 (loop for fname in files
1871 do (byte-compile-file fname parg))))
1873 (defun anything-find-files-ediff-files (candidate)
1874 "Default action to ediff files in `anything-find-files'."
1875 (ediff-files
1876 candidate
1877 (anything-c-read-file-name
1878 (format "Ediff `%s' With File: " (file-name-nondirectory candidate)))))
1880 (defun anything-find-files-ediff-merge-files (candidate)
1881 "Default action to ediff merge files in `anything-find-files'."
1882 (ediff-merge-files
1883 candidate
1884 (anything-c-read-file-name
1885 (format "Ediff Merge `%s' With File: " (file-name-nondirectory candidate)))))
1887 (defun* anything-reduce-file-name (fname level &key unix-close expand)
1888 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1889 If LEVEL is positive reduce from end else from beginning.
1890 If UNIX-CLOSE is non--nil close filename with /.
1891 If EXPAND is non--nil expand-file-name."
1892 (let* ((exp-fname (expand-file-name fname))
1893 (fname-list (split-string (if (or (string= fname "~/") expand)
1894 exp-fname fname) "/" t))
1895 (len (length fname-list))
1896 (pop-list (if (< level 0)
1897 (subseq fname-list (* level -1))
1898 (subseq fname-list 0 (- len level))))
1899 (result (mapconcat 'identity pop-list "/"))
1900 (empty (string= result "")))
1901 (when unix-close (setq result (concat result "/")))
1902 (if (string-match "^~" result)
1903 (if (string= result "~/") "~/" result)
1904 (if (< level 0)
1905 (if empty "../" (concat "../" result))
1906 (cond ((eq system-type 'windows-nt)
1907 (if empty "c:/" result))
1908 (empty "/")
1910 (concat "/" result)))))))
1912 (defun anything-file-completion-source-p ()
1913 "Test if current source is a dired or find-files source."
1914 (let ((ff-sources '("Find Files" "Copy Files"
1915 "Rename Files" "Symlink Files"
1916 "Hardlink Files" "Write File"
1917 "Insert File" "Read file name"))
1918 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
1919 (catch 'break
1920 (dolist (i ff-sources)
1921 (when (equal cur-source (concat i anything-c-find-files-doc-header))
1922 (throw 'break t))))))
1924 (defun anything-find-files-down-one-level (arg)
1925 "Go down one level like unix command `cd ..'.
1926 If prefix numeric arg is given go ARG level down."
1927 (interactive "p")
1928 (when (anything-file-completion-source-p)
1929 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
1930 :unix-close t :expand t)))
1931 (with-selected-window (minibuffer-window)
1932 (delete-minibuffer-contents)
1933 (insert new-pattern)))))
1935 ;; `C-.' doesn't work in terms use `C-l' instead.
1936 (if window-system
1937 (define-key anything-map (kbd "C-.") 'anything-find-files-down-one-level)
1938 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))
1940 (defun anything-c-point-file-in-dired (file)
1941 "Put point on filename FILE in dired buffer."
1942 (dired (file-name-directory file))
1943 (dired-goto-file file))
1945 (defun anything-create-tramp-name (fname)
1946 "Build filename for `anything-pattern' like /su:: or /sudo::."
1947 (apply #'tramp-make-tramp-file-name
1948 (loop
1949 with v = (tramp-dissect-file-name fname)
1950 for i across v collect i)))
1952 (defun anything-find-files-get-candidates ()
1953 "Create candidate list for `anything-c-source-find-files'."
1954 (let* ( ; Don't try to tramp connect before entering the second ":".
1955 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1956 (path (cond ((string-match "^~" anything-pattern)
1957 (replace-match (getenv "HOME") nil t anything-pattern))
1958 ((string-match tramp-file-name-regexp anything-pattern)
1959 (let ((tramp-name (anything-create-tramp-name
1960 (match-string 0 anything-pattern))))
1961 (replace-match tramp-name nil t anything-pattern)))
1962 (t anything-pattern)))
1963 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
1964 (set-text-properties 0 (length path) nil path)
1965 (if (member 'anything-compile-source--match-plugin
1966 anything-compile-source-functions)
1967 (setq anything-pattern path)
1968 (setq anything-pattern (replace-regexp-in-string " " ".*" path)))
1969 (cond ((or (file-regular-p path)
1970 (and (not (file-exists-p path)) (string-match "/$" path))
1971 (and ffap-url-regexp (string-match ffap-url-regexp path)))
1972 (list path))
1973 ((string= anything-pattern "") (directory-files "/" t))
1974 ((file-directory-p path) (directory-files path t))
1976 (append
1977 (list path)
1978 (directory-files (file-name-directory path) t))))))
1980 (defface anything-dired-symlink-face
1981 '((t (:foreground "DarkOrange")))
1982 "*Face used for symlinks in `anything-find-files'."
1983 :group 'anything)
1985 (defface anything-ffiles-prefix-face
1986 '((t (:background "yellow" :foreground "black")))
1987 "*Face used to prefix new file or url paths in `anything-find-files'."
1988 :group 'anything)
1990 (defun anything-c-prefix-filename (fname &optional image)
1991 "Return fname FNAME prefixed with icon IMAGE."
1992 (let* ((img-name (and image (expand-file-name
1993 image anything-c-find-files-icons-directory)))
1994 (img (and image (create-image img-name)))
1995 (prefix-img (and image (propertize " " 'display img)))
1996 (prefix-new (propertize
1997 " " 'display
1998 (propertize "[?]" 'face 'anything-ffiles-prefix-face)))
1999 (prefix-url (propertize
2000 " " 'display
2001 (propertize "[@]" 'face 'anything-ffiles-prefix-face))))
2002 (cond ((or (file-exists-p fname)
2003 (file-symlink-p fname))
2004 (if image (concat prefix-img fname) fname))
2005 ((string-match ffap-url-regexp fname) (concat prefix-url " " fname))
2006 (t (concat prefix-new " " fname)))))
2008 (defun anything-c-find-files-transformer (files sources)
2009 "Selector of transformer to use for `anything-c-source-find-files'."
2010 (if (and (window-system) anything-c-find-files-show-icons)
2011 (anything-c-highlight-ffiles1 files sources)
2012 (anything-c-highlight-ffiles files sources)))
2014 (defun anything-c-highlight-ffiles (files sources)
2015 "Candidate transformer for `anything-c-source-find-files' without icons."
2016 (loop for i in files
2017 collect (cond ((file-symlink-p i)
2018 (cons
2019 (anything-c-prefix-filename
2020 (propertize i 'face 'anything-dired-symlink-face
2021 'help-echo (file-truename i)))
2023 ((file-directory-p i)
2024 (cons
2025 (anything-c-prefix-filename
2026 (propertize i 'face anything-c-files-face1))
2029 (cons
2030 (anything-c-prefix-filename
2031 (propertize i 'face anything-c-files-face2))
2032 i)))))
2034 (defsubst anything-c-highlight-ffiles1 (files sources)
2035 "Candidate transformer for `anything-c-source-find-files' that show icons."
2036 (loop for i in files
2037 for af = (file-name-nondirectory i)
2038 collect (cond ( ;; Files.
2039 (eq nil (car (file-attributes i)))
2040 (cons (anything-c-prefix-filename
2041 (propertize i 'face anything-c-files-face2)
2042 "leaf.xpm")
2044 ( ;; Empty directories.
2045 (and (eq t (car (file-attributes i)))
2046 ;; Be sure to have permission to list content.
2047 (file-readable-p i)
2048 (eq 0 (length
2049 (directory-files
2050 i nil directory-files-no-dot-files-regexp t))))
2051 (cons (anything-c-prefix-filename
2052 (propertize i 'face anything-c-files-face1)
2053 "empty.xpm")
2055 ( ;; Open directories.
2056 (and (eq t (car (file-attributes i))) (get-buffer af))
2057 (cons (anything-c-prefix-filename
2058 (propertize i 'face anything-c-files-face1)
2059 "open.xpm")
2061 (;; Closed directories.
2062 (eq t (car (file-attributes i)))
2063 (cons (anything-c-prefix-filename
2064 (propertize i 'face anything-c-files-face1)
2065 "close.xpm")
2067 ( ;; Open Symlinks directories.
2068 (and (stringp (car (file-attributes i)))
2069 (file-directory-p i) (get-buffer af))
2070 (cons (anything-c-prefix-filename
2071 (propertize i 'face 'anything-dired-symlink-face
2072 'help-echo (file-truename i)) "open.xpm")
2074 ( ;; Closed Symlinks directories.
2075 (and (stringp (car (file-attributes i))) (file-directory-p i))
2076 (cons (anything-c-prefix-filename
2077 (propertize i 'face 'anything-dired-symlink-face
2078 'help-echo (file-truename i)) "close.xpm")
2080 ( ;; Files symlinks.
2081 (stringp (car (file-attributes i)))
2082 (cons (anything-c-prefix-filename
2083 (propertize i 'face 'anything-dired-symlink-face
2084 'help-echo (file-truename i))
2085 "leaf.xpm")
2086 i)))))
2088 (defun anything-find-files-action-transformer (actions candidate)
2089 "Action transformer for `anything-c-source-find-files'."
2090 (cond ((with-current-buffer anything-current-buffer (eq major-mode 'message-mode))
2091 (append actions '(("Gnus attach file(s)" . anything-ff-gnus-attach-files))))
2092 ((string-match (image-file-name-regexp) candidate)
2093 (append actions '(("Rotate image right" . anything-ff-rotate-image-right)
2094 ("Rotate image left" . anything-ff-rotate-image-left))))
2095 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
2096 (car it) candidate))
2097 (append actions '(("Byte compile lisp file(s) `C-u to load'"
2098 . anything-find-files-byte-compile)
2099 ("Load File(s)" . load-file))))
2100 (t actions)))
2102 (defun anything-ff-gnus-attach-files (candidate)
2103 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
2104 (let ((flist (anything-marked-candidates)))
2105 (gnus-dired-attach flist)))
2107 (defun anything-ff-rotate-current-image1 (file &optional num-arg)
2108 "Rotate current image at NUM-ARG degrees."
2109 (if (executable-find "mogrify")
2110 (progn
2111 (shell-command (format "mogrify -rotate %s %s" (or num-arg 90) file))
2112 (when (buffer-live-p image-dired-display-image-buffer)
2113 (kill-buffer image-dired-display-image-buffer))
2114 (image-dired-display-image file)
2115 (message nil)
2116 (display-buffer (get-buffer image-dired-display-image-buffer)))
2117 (error "mogrify not found")))
2119 (defun anything-ff-rotate-image-left (candidate)
2120 "Rotate image file CANDIDATE left.
2121 This affect directly file CANDIDATE."
2122 (anything-ff-rotate-current-image1 candidate -90))
2124 (defun anything-ff-rotate-image-right (candidate)
2125 "Rotate image file CANDIDATE right.
2126 This affect directly file CANDIDATE."
2127 (anything-ff-rotate-current-image1 candidate))
2129 (defun anything-find-files-persistent-action (candidate)
2130 "Open subtree CANDIDATE without quitting anything.
2131 If CANDIDATE is not a directory expand CANDIDATE filename.
2132 If CANDIDATE is alone, open file CANDIDATE filename.
2133 That's mean:
2134 First hit on C-z expand CANDIDATE second hit open file.
2135 If a prefix arg is given or `anything-follow-mode' is on open file."
2136 (let ((follow (buffer-local-value
2137 'anything-follow-mode
2138 (get-buffer-create anything-buffer))))
2139 (flet ((insert-in-minibuffer (fname)
2140 (with-selected-window (minibuffer-window)
2141 (unless follow
2142 (delete-minibuffer-contents)
2143 (set-text-properties 0 (length fname) nil fname)
2144 (insert fname)))))
2145 (cond ((and (file-directory-p candidate) (file-symlink-p candidate))
2146 (insert-in-minibuffer (file-name-as-directory
2147 (file-truename
2148 (expand-file-name candidate)))))
2149 ((file-directory-p candidate)
2150 (insert-in-minibuffer (file-name-as-directory
2151 (expand-file-name candidate))))
2152 ((file-symlink-p candidate)
2153 (insert-in-minibuffer (file-truename candidate)))
2155 ;; First hit on C-z expand CANDIDATE second hit open file.
2156 ;; If a prefix arg is given or `anything-follow-mode' is on open file.
2157 (let ((new-pattern (anything-get-selection))
2158 (num-lines-buf (with-current-buffer anything-buffer
2159 (count-lines (point-min) (point-max)))))
2160 (if (and (> num-lines-buf 3) (not current-prefix-arg) (not follow))
2161 (insert-in-minibuffer new-pattern)
2162 (if (string-match (image-file-name-regexp) candidate)
2163 (progn
2164 (when (buffer-live-p image-dired-display-image-buffer)
2165 (kill-buffer image-dired-display-image-buffer))
2166 (image-dired-display-image candidate)
2167 (message nil)
2168 (display-buffer image-dired-display-image-buffer))
2169 (find-file candidate)))))))))
2171 (defun anything-c-insert-file-name-completion-at-point (candidate)
2172 "Insert file name completion at point."
2173 (if buffer-read-only
2174 (error "Error: Buffer `%s' is read-only" (buffer-name))
2175 (let* ((end (point))
2176 (guess (thing-at-point 'filename))
2177 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess)
2178 (string-match "^[^\~]" guess))))
2179 (set-text-properties 0 (length candidate) nil candidate)
2180 (if (and guess (not (string= guess "")) (string-match "^~\\|/.*" guess))
2181 (progn
2182 (search-backward guess (- (point) (length guess)))
2183 (delete-region (point) end)
2184 (if full-path-p
2185 (insert (expand-file-name candidate))
2186 (insert (abbreviate-file-name candidate))))
2187 (error "Aborting completion: No valid file name at point")))))
2189 ;;;###autoload
2190 (defun anything-find-files (&optional fname)
2191 "Preconfigured `anything' for anything implementation of `find-file'.
2192 In non--interactive use an argument FNAME can be used.
2193 This is the starting point for nearly all actions you can do on files."
2194 (interactive "i")
2195 (let ((anything-mp-highlight-delay nil))
2196 (anything :sources 'anything-c-source-find-files
2197 :input (or (and fname (expand-file-name fname))
2198 (anything-find-files-input
2199 (ffap-guesser)
2200 (thing-at-point 'filename)))
2201 :prompt "Find Files or Url: "
2202 :buffer "*Anything Find Files*")))
2204 (defun anything-c-current-directory ()
2205 "Return current-directory name at point.
2206 Useful in dired buffers when there is inserted subdirs."
2207 (if (eq major-mode 'dired-mode)
2208 (dired-current-directory)
2209 default-directory))
2211 (defun anything-find-files-input (fap tap)
2212 "Default input of `anything-find-files'."
2213 (let* ((def-dir (anything-c-current-directory))
2214 (lib (anything-find-library-at-point))
2215 (file-p (and fap (file-exists-p fap)
2216 (file-exists-p
2217 (file-name-directory (expand-file-name tap def-dir)))))
2218 (input (cond (lib)
2219 (file-p (expand-file-name tap def-dir))
2220 (t fap))))
2221 (or input (expand-file-name def-dir))))
2223 (defun anything-find-library-at-point ()
2224 "Try to find library path at point.
2225 Find inside `require' and `declare-function' sexp."
2226 (require 'find-func)
2227 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t)))
2228 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t)))
2229 (sexp (and beg-sexp end-sexp
2230 (buffer-substring-no-properties
2231 (1+ beg-sexp) (1- end-sexp)))))
2232 (ignore-errors
2233 (cond ((and sexp (string-match "require \'.+[^)]" sexp))
2234 (find-library-name
2235 (replace-regexp-in-string
2236 "'\\|\)\\|\(" ""
2237 ;; If require use third arg, ignore it,
2238 ;; always use library path found in `load-path'.
2239 (second (split-string (match-string 0 sexp))))))
2240 ((and sexp (string-match-p "^declare-function" sexp))
2241 (find-library-name
2242 (replace-regexp-in-string
2243 "\"\\|ext:" ""
2244 (third (split-string sexp)))))
2245 (t nil)))))
2247 ;;; Anything completion for `write-file'.==> C-x C-w
2248 (defvar anything-c-source-write-file
2249 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
2250 ;; It is needed for filenames with capital letters
2251 (disable-shortcuts)
2252 (candidates . anything-find-files-get-candidates)
2253 (filtered-candidate-transformer anything-c-find-files-transformer)
2254 (persistent-action . anything-find-files-persistent-action)
2255 (persistent-help . "Expand Candidate")
2256 (volatile)
2257 (action .
2258 (("Write File" . (lambda (candidate)
2259 (write-file candidate 'confirm)))))))
2261 ;;;###autoload
2262 (defun anything-write-file ()
2263 "Preconfigured `anything' providing completion for `write-file'."
2264 (interactive)
2265 (anything 'anything-c-source-write-file
2266 (expand-file-name default-directory)
2267 "Write buffer to file: " nil nil "*Anything write file*"))
2269 ;;; Anything completion for `insert-file'.==> C-x i
2270 (defvar anything-c-source-insert-file
2271 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
2272 ;; It is needed for filenames with capital letters
2273 (disable-shortcuts)
2274 (candidates . anything-find-files-get-candidates)
2275 (filtered-candidate-transformer anything-c-find-files-transformer)
2276 (persistent-action . anything-find-files-persistent-action)
2277 (persistent-help . "Expand Candidate")
2278 (volatile)
2279 (action .
2280 (("Insert File" . (lambda (candidate)
2281 (when (y-or-n-p (format "Really insert %s in %s "
2282 candidate anything-current-buffer))
2283 (insert-file-contents candidate))))))))
2285 ;;;###autoload
2286 (defun anything-insert-file ()
2287 "Preconfigured `anything' providing completion for `insert-file'."
2288 (interactive)
2289 (anything 'anything-c-source-insert-file
2290 (expand-file-name default-directory)
2291 "Insert file: " nil nil "*Anything insert file*"))
2293 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2294 (defvar anything-c-source-copy-files
2295 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
2296 ;; It is needed for filenames with capital letters
2297 (disable-shortcuts)
2298 (candidates . anything-find-files-get-candidates)
2299 (filtered-candidate-transformer anything-c-find-files-transformer)
2300 (persistent-action . anything-find-files-persistent-action)
2301 (persistent-help . "Expand Candidate")
2302 (volatile)
2303 (action .
2304 (("Copy File"
2305 . (lambda (candidate)
2306 (anything-dired-action candidate :action 'copy)))
2307 ("Copy and Follow"
2308 . (lambda (candidate)
2309 (anything-dired-action candidate :action 'copy :follow t)))))))
2312 (defvar anything-c-source-rename-files
2313 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
2314 ;; It is needed for filenames with capital letters
2315 (disable-shortcuts)
2316 (candidates . anything-find-files-get-candidates)
2317 (filtered-candidate-transformer anything-c-find-files-transformer)
2318 (persistent-action . anything-find-files-persistent-action)
2319 (persistent-help . "Expand Candidate")
2320 (volatile)
2321 (action .
2322 (("Rename File"
2323 . (lambda (candidate)
2324 (anything-dired-action candidate :action 'rename)))
2325 ("Rename and Follow"
2326 . (lambda (candidate)
2327 (anything-dired-action candidate :action 'rename :follow t)))))))
2329 (defvar anything-c-source-symlink-files
2330 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
2331 ;; It is needed for filenames with capital letters
2332 (disable-shortcuts)
2333 (candidates . anything-find-files-get-candidates)
2334 (filtered-candidate-transformer anything-c-find-files-transformer)
2335 (persistent-action . anything-find-files-persistent-action)
2336 (persistent-help . "Expand Candidate")
2337 (volatile)
2338 (action
2339 . (("Symlink File"
2340 . (lambda (candidate)
2341 (anything-dired-action candidate :action 'symlink)))
2342 ("RelSymlink File"
2343 . (lambda (candidate)
2344 (anything-dired-action candidate :action 'relsymlink)))))))
2347 (defvar anything-c-source-hardlink-files
2348 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
2349 ;; It is needed for filenames with capital letters
2350 (disable-shortcuts)
2351 (candidates . anything-find-files-get-candidates)
2352 (filtered-candidate-transformer anything-c-find-files-transformer)
2353 (persistent-action . anything-find-files-persistent-action)
2354 (persistent-help . "Expand Candidate")
2355 (volatile)
2356 (action
2357 . (("Hardlink File"
2358 . (lambda (candidate)
2359 (anything-dired-action candidate :action 'hardlink)))))))
2362 (defun* anything-dired-action (candidate &key action follow (files (dired-get-marked-files)))
2363 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2364 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2365 (let ((fn (case action
2366 ('copy 'dired-copy-file)
2367 ('rename 'dired-rename-file)
2368 ('symlink 'make-symbolic-link)
2369 ('relsymlink 'dired-make-relative-symlink)
2370 ('hardlink 'dired-hardlink)))
2371 (marker (case action
2372 ((copy rename) dired-keep-marker-copy)
2373 ('symlink dired-keep-marker-symlink)
2374 ('relsymlink dired-keep-marker-relsymlink)
2375 ('hardlink dired-keep-marker-hardlink))))
2376 (dired-create-files
2377 fn (symbol-name action) files
2378 (if (file-directory-p candidate)
2379 ;; When CANDIDATE is a directory, build file-name in this directory.
2380 ;; Else we use CANDIDATE.
2381 #'(lambda (from)
2382 (expand-file-name (file-name-nondirectory from) candidate))
2383 #'(lambda (from) candidate))
2384 marker)
2385 (when follow
2386 (let* ((moved-flist (anything-get-dest-fnames-from-list files candidate))
2387 (fname (car moved-flist)))
2388 (unwind-protect
2389 (progn
2390 (setq anything-ff-cand-to-mark moved-flist)
2391 (anything-find-files candidate))
2392 (setq anything-ff-cand-to-mark nil))))))
2394 ;; Internal
2395 (defvar anything-ff-cand-to-mark nil)
2397 (defun anything-get-dest-fnames-from-list (flist dest-cand)
2398 "Transform filenames of FLIST to abs of DEST-CAND."
2399 (loop
2400 with dest = (expand-file-name dest-cand)
2401 for src in flist
2402 for basename-src = (if (file-directory-p src)
2403 (file-relative-name
2404 (directory-file-name src)
2405 (file-name-directory src))
2406 (file-name-nondirectory src))
2407 for fname = (if (file-directory-p dest)
2408 (concat (file-name-as-directory dest)
2409 basename-src)
2410 dest)
2411 collect fname))
2413 (defun anything-c-maybe-mark-candidates ()
2414 "Mark all candidates of list `anything-ff-cand-to-mark'."
2415 (when (and (string= (assoc-default 'name (anything-get-current-source))
2416 (assoc-default 'name anything-c-source-find-files))
2417 anything-ff-cand-to-mark)
2418 (with-anything-window
2419 (while anything-ff-cand-to-mark
2420 (if (search-forward (car anything-ff-cand-to-mark) (point-at-eol) t)
2421 (progn
2422 (call-interactively 'anything-toggle-visible-mark)
2423 (setq anything-ff-cand-to-mark (cdr anything-ff-cand-to-mark)))
2424 (call-interactively 'anything-next-line)))
2425 (unless (anything-this-visible-mark)
2426 (call-interactively 'anything-prev-visible-mark)))))
2428 (add-hook 'anything-after-update-hook #'anything-c-maybe-mark-candidates)
2431 (defun* anything-dired-do-action-on-file (&key action)
2432 (let* ((files (dired-get-marked-files))
2433 (len (length files))
2434 (fname (if (> len 1)
2435 (format "* %d Files" len)
2436 (car files)))
2437 (source (case action
2438 ('copy 'anything-c-source-copy-files)
2439 ('rename 'anything-c-source-rename-files)
2440 ('symlink 'anything-c-source-symlink-files)
2441 ('hardlink 'anything-c-source-hardlink-files)))
2442 (prompt-fm (case action
2443 ('copy "Copy %s to: ")
2444 ('rename "Rename %s to: ")
2445 ('symlink "Symlink %s to: ")
2446 ('hardlink "Hardlink %s to: ")))
2447 (buffer (case action
2448 ('copy "*Anything Copy Files*")
2449 ('rename "*Anything Rename Files*")
2450 ('symlink "*Anything Symlink Files*")
2451 ('hardlink "*Anything Hardlink Files*"))))
2452 (anything source
2453 (or (dired-dwim-target-directory)
2454 (expand-file-name (anything-c-current-directory)))
2455 (format prompt-fm fname) nil nil buffer)))
2458 ;;;###autoload
2459 (defun anything-dired-rename-file ()
2460 "Preconfigured `anything' to rename files from dired."
2461 (interactive)
2462 (anything-dired-do-action-on-file :action 'rename))
2464 ;;;###autoload
2465 (defun anything-dired-copy-file ()
2466 "Preconfigured `anything' to copy files from dired."
2467 (interactive)
2468 (anything-dired-do-action-on-file :action 'copy))
2470 ;;;###autoload
2471 (defun anything-dired-symlink-file ()
2472 "Preconfigured `anything' to symlink files from dired."
2473 (interactive)
2474 (anything-dired-do-action-on-file :action 'symlink))
2476 ;;;###autoload
2477 (defun anything-dired-hardlink-file ()
2478 "Preconfigured `anything' to hardlink files from dired."
2479 (interactive)
2480 (anything-dired-do-action-on-file :action 'hardlink))
2482 (defvar anything-dired-bindings nil)
2483 ;;;###autoload
2484 (defun anything-dired-bindings (&optional arg)
2485 "Replace usual dired commands `C' and `R' by anything ones.
2486 When call interactively toggle dired bindings and anything bindings.
2487 When call non--interactively with arg > 0, enable anything bindings.
2488 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2489 (interactive)
2490 (if (or (and arg (> arg 0)) (not anything-dired-bindings))
2491 ;; Replace dired bindings.
2492 (progn
2493 (substitute-key-definition
2494 'dired-do-copy 'anything-dired-copy-file dired-mode-map)
2495 (substitute-key-definition
2496 'dired-do-rename 'anything-dired-rename-file dired-mode-map)
2497 (substitute-key-definition
2498 'dired-do-symlink 'anything-dired-symlink-file dired-mode-map)
2499 (substitute-key-definition
2500 'dired-do-hardlink 'anything-dired-hardlink-file dired-mode-map)
2501 (setq anything-dired-bindings t))
2502 ;; Replace anything bindings.
2503 (substitute-key-definition
2504 'anything-dired-copy-file 'dired-do-copy dired-mode-map)
2505 (substitute-key-definition
2506 'anything-dired-rename-file 'dired-do-rename dired-mode-map)
2507 (substitute-key-definition
2508 'anything-dired-symlink-file 'dired-do-symlink dired-mode-map)
2509 (substitute-key-definition
2510 'anything-dired-hardlink-file 'dired-do-hardlink dired-mode-map)
2511 (setq anything-dired-bindings nil)))
2513 (defun* anything-c-read-file-name (prompt
2514 &key
2515 (initial-input (expand-file-name default-directory))
2516 (buffer "*Anything Completions*")
2517 test
2518 (marked-candidates nil)
2519 (persistent-action 'anything-find-files-persistent-action)
2520 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
2521 "Anything `read-file-name' emulation.
2522 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2523 (when (get-buffer anything-action-buffer)
2524 (kill-buffer anything-action-buffer))
2525 (let ((anything-mp-highlight-delay nil))
2526 (flet ((action-fn (candidate)
2527 (if marked-candidates
2528 (anything-marked-candidates)
2529 (identity candidate))))
2530 (or (anything
2531 :sources
2532 `((name . ,(concat "Read file name" anything-c-find-files-doc-header))
2533 ;; It is needed for filenames with capital letters
2534 (disable-shortcuts)
2535 (candidates . (lambda ()
2536 (if test
2537 (loop with seq = (anything-find-files-get-candidates)
2538 for fname in seq when (funcall test fname)
2539 collect fname)
2540 (anything-find-files-get-candidates))))
2541 (filtered-candidate-transformer anything-c-find-files-transformer)
2542 (persistent-action . ,persistent-action)
2543 (persistent-help . ,persistent-help)
2544 (volatile)
2545 (action . ,'action-fn))
2546 :input initial-input
2547 :prompt prompt
2548 :resume 'noresume
2549 :buffer buffer)
2550 (keyboard-quit)))))
2552 ;;; File Cache
2553 (defvar anything-c-source-file-cache-initialized nil)
2555 (defvar anything-c-file-cache-files nil)
2557 (defvar anything-c-source-file-cache
2558 '((name . "File Cache")
2559 (init
2560 . (lambda ()
2561 (require 'filecache nil t)
2562 (unless anything-c-source-file-cache-initialized
2563 (setq anything-c-file-cache-files
2564 (loop for item in file-cache-alist append
2565 (destructuring-bind (base &rest dirs) item
2566 (loop for dir in dirs collect
2567 (concat dir base)))))
2568 (defadvice file-cache-add-file (after file-cache-list activate)
2569 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
2570 (setq anything-c-source-file-cache-initialized t))))
2571 (candidates . anything-c-file-cache-files)
2572 (match anything-c-match-on-file-name
2573 anything-c-match-on-directory-name)
2574 (type . file)))
2575 ;; (anything 'anything-c-source-file-cache)
2577 ;;; Locate
2578 ;; NOTE for WINDOZE users:
2579 ;; You have to install Everything with his command line interface here:
2580 ;; http://www.voidtools.com/download.php
2582 (defvar anything-c-locate-command
2583 (case system-type
2584 ('gnu/linux "locate -i -r %s")
2585 ('berkeley-unix "locate -i %s")
2586 ('windows-nt "es -i -r %s")
2587 (t "locate %s"))
2588 "A list of arguments for locate program.
2589 The \"-r\" option must be the last option.")
2591 (defun anything-c-locate-init ()
2592 "Initialize async locate process for `anything-c-source-locate'."
2593 (prog1
2594 (start-process-shell-command "locate-process" nil
2595 (format anything-c-locate-command
2596 anything-pattern))
2597 (set-process-sentinel (get-process "locate-process")
2598 #'(lambda (process event)
2599 (when (string= event "finished\n")
2600 (with-anything-window
2601 (anything-update-move-first-line)))))))
2603 (defvar anything-c-source-locate
2604 '((name . "Locate")
2605 (candidates . anything-c-locate-init)
2606 (type . file)
2607 (requires-pattern . 3)
2608 (delayed))
2609 "Find files matching the current input pattern with locate.")
2611 ;; (anything 'anything-c-source-locate)
2613 ;;; Grep
2614 (defvar anything-c-grep-default-command "grep -nH -e '%s' %s %s")
2615 (defvar anything-c-grep-default-function 'anything-c-grep-init)
2617 (defun anything-c-grep-init (only-files)
2618 "Start an asynchronous grep process in ONLY-FILES list."
2619 (prog1
2620 (start-process-shell-command
2621 "grep-process" nil
2622 (format anything-c-grep-default-command
2623 anything-pattern
2624 only-files
2625 (mapconcat #'(lambda (x)
2626 (concat "--exclude=" x))
2627 grep-find-ignored-files " ")))
2628 (set-process-sentinel (get-process "grep-process")
2629 #'(lambda (process event)
2630 (when (string= event "finished\n")
2631 (with-anything-window
2632 (anything-update-move-first-line)))))))
2634 (defun anything-c-grep-action (candidate &optional where)
2635 "Define a default action for `anything-do-grep' on CANDIDATE.
2636 WHERE can be one of other-window, elscreen, other-frame."
2637 (let* ((split (split-string candidate ":"))
2638 (lineno (string-to-number (second split)))
2639 (fname (car split)))
2640 (case where
2641 (other-window (find-file-other-window fname))
2642 (elscreen (anything-elscreen-find-file fname))
2643 (other-frame (find-file-other-frame fname))
2644 (t (find-file fname)))
2645 (show-all)
2646 (anything-goto-line lineno)))
2648 (defun anything-c-grep-persistent-action (candidate)
2649 (anything-c-grep-action candidate)
2650 (anything-match-line-color-current-line))
2652 ;;;###autoload
2653 (defun anything-do-grep (only)
2654 "Preconfigured anything for grep.
2655 Contrarily to Emacs `grep' no default directory is given, but
2656 the full path of candidates in ONLY.
2657 That allow to grep different files not only in `default-directory' but anywhere
2658 by marking them (C-<SPACE>). If one or more directory is selected
2659 grep will search in all files of these directories
2660 like -d recursive, or -r would do.
2661 You can use also wildcard in the base name of candidate."
2662 (interactive (list
2663 (anything-c-read-file-name "Search in file(s): "
2664 :marked-candidates t)))
2665 (let ((anything-compile-source-functions
2666 ;; rule out anything-match-plugin because the input is one regexp.
2667 (delq 'anything-compile-source--match-plugin
2668 (copy-sequence anything-compile-source-functions))))
2669 ;; If one or more candidate is a directory, search in all files
2670 ;; of this candidate e.g /home/user/directory/*
2671 (setq only
2672 (loop for i in only
2673 if (file-directory-p i)
2674 collect (concat (file-name-as-directory i) "*") into of
2675 else collect i into of
2676 finally return (mapconcat 'identity of " ")))
2677 ;; When called as action from an other source e.g *-find-files
2678 ;; we have to kill action buffer.
2679 (when (get-buffer anything-action-buffer)
2680 (kill-buffer anything-action-buffer))
2681 (define-key anything-map (kbd "M-<down>") #'anything-c-grep-next-or-prec-file)
2682 (define-key anything-map (kbd "M-<up>") #'anything-c-grep-precedent-file)
2683 (anything
2684 :sources
2685 `(((name . "Grep (M-up/down - next/prec file)")
2686 (init . (lambda ()
2687 ;; Load `grep-find-ignored-files'.
2688 (require 'grep)))
2689 (candidates . (lambda ()
2690 (funcall anything-c-grep-default-function only)))
2691 (filtered-candidate-transformer anything-c-grep-cand-transformer)
2692 (action . ,(delq
2694 `(("Find File" . anything-c-grep-action)
2695 ("Find file other window"
2696 . (lambda (candidate)
2697 (anything-c-grep-action candidate 'other-window)))
2698 ,(and (locate-library "elscreen")
2699 '("Find file in Elscreen"
2700 . (lambda (candidate)
2701 (anything-c-grep-action candidate 'elscreen))))
2702 ("Find file other frame"
2703 . (lambda (candidate)
2704 (anything-c-grep-action candidate 'other-frame))))))
2705 (persistent-action . (lambda (candidate)
2706 (anything-c-grep-persistent-action
2707 candidate)))
2708 (requires-pattern . 3)
2709 (delayed)))
2710 :buffer "*anything grep*")))
2712 (defun anything-c-grep-cand-transformer (candidates sources)
2713 "Filtered candidate transformer function for `anything-do-grep'."
2714 (loop for i in candidates
2715 for split = (split-string i ":")
2716 collect (cons (concat (propertize (file-relative-name (nth 0 split))
2717 'face '((:foreground "BlueViolet")))
2719 (propertize (nth 1 split)
2720 'face '((:foreground "Darkorange1")))
2722 (nth 2 split))
2723 i)))
2725 ;;;###autoload
2726 (defun anything-c-grep-precedent-file ()
2727 "Go to precedent file in `anything-do-grep'."
2728 (interactive)
2729 (anything-c-grep-next-or-prec-file -1))
2731 ;;;###autoload
2732 (defun* anything-c-grep-next-or-prec-file (&optional (n 1))
2733 "Go to next or precedent candidate file in anything grep buffer."
2734 (interactive)
2735 (let ((cur-source (assoc-default 'name (anything-get-current-source))))
2736 (with-anything-window
2737 (if (equal cur-source "Grep (M-up/down - next/prec file)")
2738 (let* ((current-line-list (split-string
2739 (buffer-substring
2740 (point-at-bol)
2741 (point-at-eol)) ":"))
2742 (current-fname (nth 0 current-line-list))
2743 (fn-b-o-f (if (eq n 1) 'eobp 'bobp))) ; func back or forward
2744 (catch 'break
2745 (while (not (funcall fn-b-o-f))
2746 (forward-line n)
2747 (beginning-of-line)
2748 (when (not (search-forward current-fname (point-at-eol) t))
2749 (anything-mark-current-line)
2750 (throw 'break nil))))
2751 (if (eq n 1)
2752 (when (eobp)
2753 (re-search-backward ".")
2754 (beginning-of-line)
2755 (anything-mark-current-line))
2756 (when (bobp)
2757 (forward-line)
2758 (beginning-of-line)
2759 (anything-mark-current-line))))
2760 (if (eq n 1)
2761 (anything-next-line)
2762 (anything-previous-line))))))
2764 ;;; Recentf files
2765 (defvar anything-c-source-recentf
2766 '((name . "Recentf")
2767 (init . (lambda ()
2768 (require 'recentf)
2769 (or recentf-mode (recentf-mode 1))
2770 ;; Big value empowers anything/recentf
2771 (when (and (numberp recentf-max-saved-items)
2772 (<= recentf-max-saved-items 20))
2773 (setq recentf-max-saved-items 500))))
2774 (candidates . recentf-list)
2775 (match anything-c-match-on-file-name
2776 anything-c-match-on-directory-name)
2777 (type . file))
2778 "See (info \"(emacs)File Conveniences\").
2779 if `recentf-max-saved-items' is too small, set it to 500.")
2780 ;; (anything 'anything-c-source-recentf)
2782 ;;; ffap
2783 (eval-when-compile (require 'ffap))
2784 (defvar anything-c-source-ffap-guesser
2785 '((name . "File at point")
2786 (init . (lambda () (require 'ffap)))
2787 (candidates . (lambda ()
2788 (anything-aif
2789 (with-current-buffer anything-current-buffer
2790 (ffap-guesser))
2791 (list it))))
2792 (type . file)))
2793 ;; (anything 'anything-c-source-ffap-guesser)
2795 ;;; ffap with line number
2796 (defun anything-c-ffap-file-line-at-point ()
2797 "Get (FILENAME . LINENO) at point."
2798 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2799 (save-excursion
2800 (beginning-of-line)
2801 (when (and (search-forward it nil t)
2802 (looking-at ":\\([0-9]+\\)"))
2803 (cons it (string-to-number (match-string 1)))))))
2805 (defvar anything-c-ffap-line-location nil
2806 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2807 It is cleared after jumping line.")
2809 (defun anything-c-ffap-line-candidates ()
2810 (with-current-buffer anything-current-buffer
2811 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
2812 (when anything-c-ffap-line-location
2813 (destructuring-bind (file . line) anything-c-ffap-line-location
2814 (list (cons (format "%s (line %d)" file line) file)))))
2816 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2817 (defun anything-c-ffap-line-goto-line ()
2818 (when (car anything-c-ffap-line-location)
2819 (unwind-protect
2820 (ignore-errors
2821 (with-selected-window
2822 (get-buffer-window
2823 (get-file-buffer (car anything-c-ffap-line-location)))
2824 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
2825 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
2826 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
2828 (defvar anything-c-source-ffap-line
2829 '((name . "File/Lineno at point")
2830 (init . (lambda () (require 'ffap)))
2831 (candidates . anything-c-ffap-line-candidates)
2832 (type . file)))
2833 ;; (anything 'anything-c-source-ffap-line)
2835 ;;; list of files gleaned from every dired buffer
2836 (defun anything-c-files-in-all-dired-candidates ()
2837 (save-excursion
2838 (mapcan
2839 (lambda (dir)
2840 (cond ((listp dir) ;filelist
2841 dir)
2842 ((equal "" (file-name-nondirectory dir)) ;dir
2843 (directory-files dir t))
2844 (t ;wildcard
2845 (file-expand-wildcards dir t))))
2846 (delq nil
2847 (mapcar (lambda (buf)
2848 (set-buffer buf)
2849 (when (eq major-mode 'dired-mode)
2850 (if (consp dired-directory)
2851 (cdr dired-directory) ;filelist
2852 dired-directory))) ;dir or wildcard
2853 (buffer-list))))))
2854 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2856 (defvar anything-c-source-files-in-all-dired
2857 '((name . "Files in all dired buffer.")
2858 (candidates . anything-c-files-in-all-dired-candidates)
2859 (type . file)))
2860 ;; (anything 'anything-c-source-files-in-all-dired)
2862 (defcustom anything-c-filelist-file-name nil
2863 "*Filename of file list.
2864 Accept a list of string for multiple files.
2866 This file tend to be very large (> 100MB) and recommend to be in ramdisk for speed.
2867 File list is created by make-filelist.rb script.
2869 Usage:
2870 ruby make-filelist.rb > /tmp/all.filelist
2872 Then
2873 ;; Assume that /tmp is ramdisk or tmpfs
2874 (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")
2875 (setq anything-c-filelist-file-name \"/tmp/all.filelist\")
2877 :type 'string
2878 :group 'anything-config)
2879 (defvar anything-c-source-filelist
2880 '((name . "FileList")
2881 (grep-candidates . anything-c-filelist-file-name)
2882 (candidate-number-limit . 200)
2883 (requires-pattern . 4)
2884 (type . file)))
2886 ;;;###autoload
2887 (defun anything-filelist ()
2888 "Preconfigured `anything' to open files instantly."
2889 (interactive)
2890 (anything-other-buffer 'anything-c-source-filelist "*anything file list*"))
2892 ;;;###autoload
2893 (defun anything-filelist+ ()
2894 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
2896 This is a replacement for `anything-for-files'."
2897 (interactive)
2898 (anything-other-buffer
2899 '(anything-c-source-ffap-line
2900 anything-c-source-ffap-guesser
2901 anything-c-source-buffers+
2902 anything-c-source-recentf
2903 anything-c-source-bookmarks
2904 anything-c-source-file-cache
2905 anything-c-source-filelist)
2906 "*anything file list*"))
2909 ;;;; <info>
2910 ;;; Info pages
2911 (defvar anything-c-info-pages nil
2912 "All info pages on system.
2913 Will be calculated the first time you invoke anything with this
2914 source.")
2916 (defvar anything-c-source-info-pages
2917 `((name . "Info Pages")
2918 (candidates
2919 . (lambda ()
2920 (if anything-c-info-pages
2921 anything-c-info-pages
2922 (setq anything-c-info-pages
2923 (save-window-excursion
2924 (save-excursion
2925 (require 'info)
2926 (Info-find-node "dir" "top")
2927 (goto-char (point-min))
2928 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2929 topics)
2930 (while (re-search-forward info-topic-regexp nil t)
2931 (add-to-list 'topics (match-string-no-properties 1)))
2932 (goto-char (point-min))
2933 (Info-exit)
2934 topics)))))))
2935 (action . (("Show with Info" .(lambda (node-str)
2936 (info (replace-regexp-in-string
2937 "^[^:]+: " "" node-str))))))
2938 (requires-pattern . 2)))
2939 ;; (anything 'anything-c-source-info-pages)
2942 ;;; Use info-index plug-in. Note that `name' attribute is
2943 ;;; not needed but `anything-c-insert-summary' uses it.
2944 ;; Info Elisp
2945 (defvar anything-c-source-info-elisp
2946 '((name . "Info index: elisp")
2947 (info-index . "elisp")))
2948 ;; (anything 'anything-c-source-info-elisp)
2950 ;; Info-Common-Lisp
2951 (defvar anything-c-source-info-cl
2952 '((name . "Info index: cl")
2953 (info-index . "cl")))
2954 ;; (anything 'anything-c-source-info-cl)
2956 ;; Info Index org
2957 (defvar anything-c-source-info-org
2958 '((name . "Info index: org")
2959 (info-index . "org")))
2960 ;; (anything 'anything-c-source-info-org)
2962 ;; Info Index ratpoison
2963 (defvar anything-c-source-info-ratpoison
2964 '((name . "Info index: ratpoison")
2965 (info-index . "ratpoison")))
2966 ;; (anything 'anything-c-source-info-ratpoison)
2968 ;; Info Index zsh
2969 (defvar anything-c-source-info-zsh
2970 '((name . "Info index: zsh")
2971 (info-index . "zsh")))
2972 ;; (anything 'anything-c-source-info-zsh)
2974 ;; Info Index bash
2975 (defvar anything-c-source-info-bash
2976 '((name . "Info index: bash")
2977 (info-index . "bash")))
2978 ;; (anything 'anything-c-source-info-bash)
2980 ;; Info Index coreutils
2981 (defvar anything-c-source-info-coreutils
2982 '((name . "Info index: coreutils")
2983 (info-index . "coreutils")))
2984 ;; (anything 'anything-c-source-info-coreutils)
2986 ;; Info Index fileutils
2987 (defvar anything-c-source-info-fileutils
2988 '((name . "Info index: fileutils")
2989 (info-index . "fileutils")))
2990 ;; (anything 'anything-c-source-info-fileutils)
2992 ;; Info Index find
2993 (defvar anything-c-source-info-find
2994 '((name . "Info index: find")
2995 (info-index . "find")))
2996 ;; (anything 'anything-c-source-info-find)
2998 ;; Info Index sh-utils
2999 (defvar anything-c-source-info-sh-utils
3000 '((name . "Info index: sh-utils")
3001 (info-index . "sh-utils")))
3002 ;; (anything 'anything-c-source-info-sh-utils)
3004 ;; Info Index textutils
3005 (defvar anything-c-source-info-textutils
3006 '((name . "Info index: textutils")
3007 (info-index . "textutils")))
3008 ;; (anything 'anything-c-source-info-textutils)
3010 ;; Info Index libc
3011 (defvar anything-c-source-info-libc
3012 '((name . "Info index: libc")
3013 (info-index . "libc")))
3014 ;; (anything 'anything-c-source-info-libc)
3016 ;; Info Index make
3017 (defvar anything-c-source-info-make
3018 '((name . "Info index: make")
3019 (info-index . "make")))
3020 ;; (anything 'anything-c-source-info-make)
3022 ;; Info Index automake
3023 (defvar anything-c-source-info-automake
3024 '((name . "Info index: automake")
3025 (info-index . "automake")))
3026 ;; (anything 'anything-c-source-info-automake)
3028 ;; Info Index autoconf
3029 (defvar anything-c-source-info-autoconf
3030 '((name . "Info index: autoconf")
3031 (info-index . "autoconf")))
3032 ;; (anything 'anything-c-source-info-autoconf)
3034 ;; Info Index emacs-lisp-intro
3035 (defvar anything-c-source-info-emacs-lisp-intro
3036 '((name . "Info index: emacs-lisp-intro")
3037 (info-index . "emacs-lisp-intro")))
3038 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
3040 ;; Info Index emacs
3041 (defvar anything-c-source-info-emacs
3042 '((name . "Info index: emacs")
3043 (info-index . "emacs")))
3044 ;; (anything 'anything-c-source-info-emacs)
3046 ;; Info Index elib
3047 (defvar anything-c-source-info-elib
3048 '((name . "Info index: elib")
3049 (info-index . "elib")))
3050 ;; (anything 'anything-c-source-info-elib)
3052 ;; Info Index eieio
3053 (defvar anything-c-source-info-eieio
3054 '((name . "Info index: eieio")
3055 (info-index . "eieio")))
3056 ;; (anything 'anything-c-source-info-eieio)
3058 ;; Info Index gauche-refe
3059 (defvar anything-c-source-info-gauche-refe
3060 '((name . "Info index: gauche")
3061 (info-index . "gauche-refe")))
3062 ;; (anything 'anything-c-source-info-gauche-refe)
3064 ;; Info Index guile
3065 (defvar anything-c-source-info-guile
3066 '((name . "Info index: guile")
3067 (info-index . "guile")))
3068 ;; (anything 'anything-c-source-info-guile)
3070 ;; Info Index guile-tut
3071 (defvar anything-c-source-info-guile-tut
3072 '((name . "Info index: guile-tut")
3073 (info-index . "guile-tut")))
3074 ;; (anything 'anything-c-source-info-guile-tut)
3076 ;; Info Index goops
3077 (defvar anything-c-source-info-goops
3078 '((name . "Info index: goops")
3079 (info-index . "goops")))
3080 ;; (anything 'anything-c-source-info-goops)
3082 ;; Info Index screen
3083 (defvar anything-c-source-info-screen
3084 '((name . "Info index: screen")
3085 (info-index . "screen")
3086 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
3087 ;; (anything 'anything-c-source-info-screen)
3089 ;; Info Index latex
3090 (defvar anything-c-source-info-latex
3091 '((name . "Info index: latex")
3092 (info-index . "latex")))
3093 ;; (anything 'anything-c-source-info-latex)
3095 ;; Info Index gawk
3096 (defvar anything-c-source-info-gawk
3097 '((name . "Info index: gawk")
3098 (info-index . "gawk")))
3099 ;; (anything 'anything-c-source-info-gawk)
3101 ;; Info Index sed
3102 (defvar anything-c-source-info-sed
3103 '((name . "Info index: sed")
3104 (info-index . "sed")))
3105 ;; (anything 'anything-c-source-info-sed)
3107 ;; Info Index m4
3108 (defvar anything-c-source-info-m4
3109 '((name . "Info index: m4")
3110 (info-index . "m4")))
3111 ;; (anything 'anything-c-source-info-m4)
3113 ;; Info Index wget
3114 (defvar anything-c-source-info-wget
3115 '((name . "Info index: wget")
3116 (info-index . "wget")))
3117 ;; (anything 'anything-c-source-info-wget)
3119 ;; Info Index binutils
3120 (defvar anything-c-source-info-binutils
3121 '((name . "Info index: binutils")
3122 (info-index . "binutils")))
3123 ;; (anything 'anything-c-source-info-binutils)
3125 ;; Info Index as
3126 (defvar anything-c-source-info-as
3127 '((name . "Info index: as")
3128 (info-index . "as")))
3129 ;; (anything 'anything-c-source-info-as)
3131 ;; Info Index bfd
3132 (defvar anything-c-source-info-bfd
3133 '((name . "Info index: bfd")
3134 (info-index . "bfd")))
3135 ;; (anything 'anything-c-source-info-bfd)
3137 ;; Info Index gprof
3138 (defvar anything-c-source-info-gprof
3139 '((name . "Info index: gprof")
3140 (info-index . "gprof")))
3141 ;; (anything 'anything-c-source-info-gprof)
3143 ;; Info Index ld
3144 (defvar anything-c-source-info-ld
3145 '((name . "Info index: ld")
3146 (info-index . "ld")))
3147 ;; (anything 'anything-c-source-info-ld)
3149 ;; Info Index diff
3150 (defvar anything-c-source-info-diff
3151 '((name . "Info index: diff")
3152 (info-index . "diff")))
3153 ;; (anything 'anything-c-source-info-diff)
3155 ;; Info Index flex
3156 (defvar anything-c-source-info-flex
3157 '((name . "Info index: flex")
3158 (info-index . "flex")))
3159 ;; (anything 'anything-c-source-info-flex)
3161 ;; Info Index grep
3162 (defvar anything-c-source-info-grep
3163 '((name . "Info index: grep")
3164 (info-index . "grep")))
3165 ;; (anything 'anything-c-source-info-grep)
3167 ;; Info Index gzip
3168 (defvar anything-c-source-info-gzip
3169 '((name . "Info index: gzip")
3170 (info-index . "gzip")))
3171 ;; (anything 'anything-c-source-info-gzip)
3173 ;; Info Index libtool
3174 (defvar anything-c-source-info-libtool
3175 '((name . "Info index: libtool")
3176 (info-index . "libtool")))
3177 ;; (anything 'anything-c-source-info-libtool)
3179 ;; Info Index texinfo
3180 (defvar anything-c-source-info-texinfo
3181 '((name . "Info index: texinfo")
3182 (info-index . "texinfo")))
3183 ;; (anything 'anything-c-source-info-texinfo)
3185 ;; Info Index info
3186 (defvar anything-c-source-info-info
3187 '((name . "Info index: info")
3188 (info-index . "info")))
3189 ;; (anything 'anything-c-source-info-info)
3191 ;; Info Index gdb
3192 (defvar anything-c-source-info-gdb
3193 '((name . "Info index: gdb")
3194 (info-index . "gdb")))
3195 ;; (anything 'anything-c-source-info-gdb)
3197 ;; Info Index stabs
3198 (defvar anything-c-source-info-stabs
3199 '((name . "Info index: stabs")
3200 (info-index . "stabs")))
3201 ;; (anything 'anything-c-source-info-stabs)
3203 ;; Info Index cvsbook
3204 (defvar anything-c-source-info-cvsbook
3205 '((name . "Info index: cvsbook")
3206 (info-index . "cvsbook")))
3207 ;; (anything 'anything-c-source-info-cvsbook)
3209 ;; Info Index cvs
3210 (defvar anything-c-source-info-cvs
3211 '((name . "Info index: cvs")
3212 (info-index . "cvs")))
3213 ;; (anything 'anything-c-source-info-cvs)
3215 ;; Info Index bison
3216 (defvar anything-c-source-info-bison
3217 '((name . "Info index: bison")
3218 (info-index . "bison")))
3219 ;; (anything 'anything-c-source-info-bison)
3221 ;; Info Index id-utils
3222 (defvar anything-c-source-info-id-utils
3223 '((name . "Info index: id-utils")
3224 (info-index . "id-utils")))
3225 ;; (anything 'anything-c-source-info-id-utils)
3227 ;; Info Index global
3228 (defvar anything-c-source-info-global
3229 '((name . "Info index: global")
3230 (info-index . "global")))
3231 ;; (anything 'anything-c-source-info-global)
3233 ;;;; <Help>
3234 ;;; Man Pages
3235 (defvar anything-c-man-pages nil
3236 "All man pages on system.
3237 Will be calculated the first time you invoke anything with this
3238 source.")
3240 (defvar anything-c-source-man-pages
3241 `((name . "Manual Pages")
3242 (candidates . (lambda ()
3243 (if anything-c-man-pages
3244 anything-c-man-pages
3245 ;; XEmacs doesn't have a woman :)
3246 (setq anything-c-man-pages
3247 (ignore-errors
3248 (require 'woman)
3249 (woman-file-name "")
3250 (sort (mapcar 'car woman-topic-all-completions)
3251 'string-lessp))))))
3252 (action ("Show with Woman"
3253 . (lambda (candidate)
3254 (let ((wfiles (woman-file-name-all-completions candidate)))
3255 (if (> (length wfiles) 1)
3256 (woman-find-file (anything-comp-read "ManFile: " wfiles
3257 :must-match t))
3258 (woman candidate))))))
3259 ;; Woman does not work OS X
3260 ;; http://xahlee.org/emacs/modernization_man_page.html
3261 (action-transformer . (lambda (actions candidate)
3262 (if (eq system-type 'darwin)
3263 '(("Show with Man" . man))
3264 actions)))
3265 (requires-pattern . 2)))
3266 ;; (anything 'anything-c-source-man-pages)
3268 ;;;; <Command>
3269 ;;; Complex command history
3270 (defvar anything-c-source-complex-command-history
3271 '((name . "Complex Command History")
3272 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
3273 (type . sexp)))
3274 ;; (anything 'anything-c-source-complex-command-history)
3276 ;;; M-x history
3277 (defvar anything-c-source-extended-command-history
3278 '((name . "Emacs Commands History")
3279 (candidates . extended-command-history)
3280 (type . command)))
3281 ;; (anything 'anything-c-source-extended-command-history)
3283 ;;; Emacs commands
3284 (defvar anything-c-source-emacs-commands
3285 '((name . "Emacs Commands")
3286 (candidates . (lambda ()
3287 (let (commands)
3288 (mapatoms (lambda (a)
3289 (if (commandp a)
3290 (push (symbol-name a)
3291 commands))))
3292 (sort commands 'string-lessp))))
3293 (type . command)
3294 (requires-pattern . 2))
3295 "Source for completing and invoking Emacs commands.
3296 A command is a function with interactive spec that can
3297 be invoked with `M-x'.
3299 To get non-interactive functions listed, use
3300 `anything-c-source-emacs-functions'.")
3301 ;; (anything 'anything-c-source-emacs-commands)
3303 ;;; Anything M-x
3305 ;; Another replacement of `M-x' that act exactly like the
3306 ;; vanilla Emacs one, no problem of windows configuration, prefix args
3307 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
3308 ;; anything invocation.
3309 ;;;###autoload
3310 (defun anything-M-x ()
3311 "Preconfigured `anything' for Emacs commands.
3312 It is `anything' replacement of regular `M-x' `execute-extended-command'."
3313 (interactive)
3314 (let* (in-help help-cand
3315 (command (anything-comp-read
3316 "M-x " obarray
3317 :test 'commandp
3318 :must-match t
3319 :requires-pattern 2
3320 :name "Emacs Commands"
3321 :persistent-action
3322 #'(lambda (candidate)
3323 (if (and in-help (string= candidate help-cand))
3324 (progn (kill-buffer "*Help*") (setq in-help nil))
3325 (describe-function (intern candidate))
3326 (setq in-help t))
3327 (setq help-cand candidate))
3328 :persistent-help "Describe this command"
3329 :history extended-command-history
3330 :sort 'string-lessp
3331 :fc-transformer 'anything-M-x-transformer))
3332 (history (loop with hist
3333 for i in extended-command-history
3334 for com = (intern i)
3335 when (and (fboundp com) (not (member i hist)))
3336 collect i into hist finally return hist)))
3337 (unless current-prefix-arg (setq current-prefix-arg anything-current-prefix-arg))
3338 (call-interactively (intern command))
3339 (setq extended-command-history (cons command (delete command history)))))
3341 (defun* anything-M-x-get-major-mode-command-alist (mode-map)
3342 "Return alist of MODE-MAP."
3343 (loop for key being the key-seqs of mode-map using (key-bindings com)
3344 for str-key = (key-description key)
3345 for ismenu = (string-match "<menu-bar>" str-key)
3346 unless ismenu collect (cons str-key com)))
3348 (defun anything-get-mode-map-from-mode (mode)
3349 "Guess the mode-map name according to MODE.
3350 Some modes don't use conventional mode-map name
3351 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
3352 Return nil if no mode-map found."
3353 (loop
3354 ;; Start with a conventional mode-map name.
3355 with mode-map = (intern-soft (format "%s-map" mode))
3356 with mode-string = (symbol-name mode)
3357 with mode-name = (replace-regexp-in-string "-mode" "" mode-string)
3358 while (not mode-map)
3359 for count downfrom (length mode-name)
3360 ;; Return when no result after parsing entire string.
3361 when (eq count 0) return nil
3362 for sub-name = (substring mode-name 0 count)
3363 do (setq mode-map (intern-soft (format "%s-map" (concat sub-name "-mode"))))
3364 finally return mode-map))
3366 (defun anything-M-x-current-mode-map-alist ()
3367 "Return mode-map alist of current `major-mode'."
3368 (let ((map (anything-get-mode-map-from-mode major-mode)))
3369 (when (and map (boundp map))
3370 (anything-M-x-get-major-mode-command-alist (symbol-value map)))))
3372 (defface anything-M-x-key-face '((t (:foreground "orange" :underline t)))
3373 "*Face used in anything-M-x to show keybinding."
3374 :group 'anything)
3376 (defun anything-M-x-transformer (candidates sources)
3377 "filtered-candidate-transformer to show bindings in emacs commands.
3378 Show global bindings and local bindings according to current `major-mode'."
3379 (loop
3380 with local-map = (with-current-buffer anything-current-buffer
3381 (anything-M-x-current-mode-map-alist))
3382 for i in candidates
3383 for cand = (symbol-name i)
3384 for local-key = (car (rassq i local-map))
3385 for key = (substitute-command-keys (format "\\[%s]" cand))
3386 collect
3387 (cons (if (string-match "^M-x" key)
3388 (if local-key
3389 (concat
3390 cand " (" (propertize local-key 'face 'anything-M-x-key-face)
3391 ")")
3392 cand)
3393 (concat
3394 cand " (" (propertize key 'face 'anything-M-x-key-face) ")"))
3395 cand)))
3397 ;;; LaCarte
3398 (defvar anything-c-source-lacarte
3399 '((name . "Lacarte")
3400 (init . (lambda () (require 'lacarte )))
3401 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
3402 (candidate-number-limit . 9999)
3403 (action . anything-c-call-interactively))
3404 "Needs lacarte.el.
3406 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
3407 ;; (anything 'anything-c-source-lacarte)
3409 ;;;; <Function>
3410 ;;; Emacs functions
3411 (defvar anything-c-source-emacs-functions
3412 '((name . "Emacs Functions")
3413 (candidates . (lambda ()
3414 (let (commands)
3415 (mapatoms (lambda (a)
3416 (if (functionp a)
3417 (push (symbol-name a) commands))))
3418 (sort commands 'string-lessp))))
3419 (type . function)
3420 (requires-pattern . 2))
3421 "Source for completing Emacs functions.")
3422 ;; (anything 'anything-c-source-emacs-functions)
3424 ;;; With abbrev expansion
3425 ;;; Similar to my exec-abbrev-cmd.el
3426 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
3427 (defvar anything-c-function-abbrev-regexp nil
3428 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
3429 Regexp built from the current `anything-pattern' interpreting it
3430 as abbreviation.
3431 Only for internal use.")
3433 (defun anything-c-match-function-by-abbrev (candidate)
3434 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
3436 Abbreviations are made by taking the first character from each
3437 word in the function's name, e.g. \"bb\" is an abbrev for
3438 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
3439 (string-match anything-c-function-abbrev-regexp candidate))
3441 (defvar anything-c-source-emacs-functions-with-abbrevs
3442 (append anything-c-source-emacs-functions
3443 '((match anything-c-match-function-by-abbrev
3444 anything-c-string-match))
3445 '((init
3446 . (lambda ()
3447 (defadvice anything-update
3448 (before anything-c-update-function-abbrev-regexp activate)
3449 (let ((char-list (append anything-pattern nil))
3450 (str "^"))
3451 (dolist (c char-list)
3452 (setq str (concat str (list c) "[^-]*-")))
3453 (setq str (concat (substring str 0 (1- (length str))) "$"))
3454 (setq anything-c-function-abbrev-regexp str))))))))
3455 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
3457 (defvar anything-c-source-advice
3458 '((name . "Function Advice")
3459 (candidates . anything-c-advice-candidates)
3460 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
3461 ;; (real-to-display . anything-c-advice-real-to-display)
3464 (persistent-action . anything-c-advice-persistent-action)
3465 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
3466 ;; (anything 'anything-c-source-advice)
3467 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
3468 ;; (testadvice)
3470 (defun anything-c-advice-candidates ()
3471 (require 'advice)
3472 (loop for (fname) in ad-advised-functions
3473 for function = (intern fname)
3474 append
3475 (loop for class in ad-advice-classes append
3476 (loop for advice in (ad-get-advice-info-field function class)
3477 for enabled = (ad-advice-enabled advice)
3478 collect
3479 (cons (format
3480 "%s %s %s"
3481 (if enabled "Enabled " "Disabled")
3482 (propertize fname 'face 'font-lock-function-name-face)
3483 (ad-make-single-advice-docstring advice class nil))
3484 (list function class advice))))))
3486 (defun anything-c-advice-persistent-action (func-class-advice)
3487 (if current-prefix-arg
3488 (anything-c-advice-toggle func-class-advice)
3489 (describe-function (car func-class-advice))))
3491 (defun anything-c-advice-toggle (func-class-advice)
3492 (destructuring-bind (function class advice) func-class-advice
3493 (cond ((ad-advice-enabled advice)
3494 (ad-advice-set-enabled advice nil)
3495 (message "Disabled"))
3496 (t ;disabled
3497 (ad-advice-set-enabled advice t)
3498 (message "Enabled")))
3499 (ad-activate function)
3500 (and anything-in-persistent-action
3501 (anything-c-advice-update-current-display-string))))
3503 (defun anything-c-advice-update-current-display-string ()
3504 (anything-edit-current-selection
3505 (let ((newword (cond ((looking-at "Disabled") "Enabled")
3506 ((looking-at "Enabled") "Disabled")))
3507 realvalue)
3508 (when newword
3509 (delete-region (point) (progn (forward-word 1) (point)))
3510 (insert newword)))))
3512 ;;;###autoload
3513 (defun anything-manage-advice ()
3514 "Preconfigured `anything' to disable/enable function advices."
3515 (interactive)
3516 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
3518 ;;;; <Variable>
3519 ;;; Emacs variables
3520 (defvar anything-c-source-emacs-variables
3521 '((name . "Emacs Variables")
3522 (candidates . (lambda ()
3523 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
3524 (type . variable)
3525 (requires-pattern . 2))
3526 "Source for completing Emacs variables.")
3527 ;; (anything 'anything-c-source-emacs-variables)
3529 ;;;; <Bookmark>
3530 ;;; Bookmarks
3531 (eval-when-compile (require 'bookmark))
3532 (defvar anything-c-source-bookmarks
3533 '((name . "Bookmarks")
3534 (init . (lambda ()
3535 (require 'bookmark)))
3536 (candidates . bookmark-all-names)
3537 (type . bookmark))
3538 "See (info \"(emacs)Bookmarks\").")
3539 ;; (anything 'anything-c-source-bookmarks)
3541 ;;; bookmark-set
3542 (defvar anything-c-source-bookmark-set
3543 '((name . "Set Bookmark")
3544 (dummy)
3545 (action . bookmark-set))
3546 "See (info \"(emacs)Bookmarks\").")
3547 ;; (anything 'anything-c-source-bookmark-set)
3549 ;;; Visible Bookmarks
3550 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
3553 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
3554 (defvar anything-c-source-bm
3555 '((name . "Visible Bookmarks")
3556 (init . anything-c-bm-init)
3557 (candidates-in-buffer)
3558 (type . line))
3559 "Needs bm.el.
3561 http://www.nongnu.org/bm/")
3563 (defun anything-c-bm-init ()
3564 "Init function for `anything-c-source-bm'."
3565 (when (require 'bm nil t)
3566 (with-no-warnings
3567 (let ((bookmarks (bm-lists))
3568 (buf (anything-candidate-buffer 'global)))
3569 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
3570 '< :key 'overlay-start))
3571 (let ((start (overlay-start bm))
3572 (end (overlay-end bm))
3573 (annotation (or (overlay-get bm 'annotation) "")))
3574 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
3575 (let ((str (format "%5d: [%s]: %s\n"
3576 (line-number-at-pos start)
3577 annotation
3578 (buffer-substring start (1- end)))))
3579 (with-current-buffer buf (insert str))))))))))
3581 ;;; Special bookmarks
3582 (defvar anything-c-source-bookmarks-ssh
3583 '((name . "Bookmarks-ssh")
3584 (init . (lambda ()
3585 (require 'bookmark)))
3586 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
3587 (type . bookmark))
3588 "See (info \"(emacs)Bookmarks\").")
3589 ;; (anything 'anything-c-source-bookmarks-ssh)
3591 (defvar anything-c-source-bookmarks-su
3592 '((name . "Bookmarks-root")
3593 (init . (lambda ()
3594 (require 'bookmark)))
3595 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
3596 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
3598 (type . bookmark))
3599 "See (info \"(emacs)Bookmarks\").")
3600 ;; (anything 'anything-c-source-bookmarks-su)
3602 (defvar anything-c-source-bookmarks-local
3603 '((name . "Bookmarks-Local")
3604 (init . (lambda ()
3605 (require 'bookmark)))
3606 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
3607 (filtered-candidate-transformer
3608 anything-c-adaptive-sort
3609 anything-c-highlight-bookmark)
3610 (type . bookmark))
3611 "See (info \"(emacs)Bookmarks\").")
3612 ;; (anything 'anything-c-source-bookmarks-local)
3614 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
3615 (let* ((lis-all (bookmark-all-names))
3616 (lis-loc (cond (local (loop for i in lis-all
3617 unless (string-match "^(ssh)\\|^(su)" i)
3618 collect i))
3619 (su (loop for i in lis-all
3620 when (string-match "^(su)" i)
3621 collect i))
3622 (sudo (loop for i in lis-all
3623 when (string-match "^(sudo)" i)
3624 collect i))
3625 (ssh (loop for i in lis-all
3626 when (string-match "^(ssh)" i)
3627 collect i)))))
3628 (sort lis-loc 'string-lessp)))
3630 (defun anything-c-bookmark-root-logged-p ()
3631 (catch 'break
3632 (dolist (i (mapcar #'buffer-name (buffer-list)))
3633 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
3634 (throw 'break t)))))
3636 (defun anything-c-highlight-bookmark-su (files source)
3637 (if (anything-c-bookmark-root-logged-p)
3638 (anything-c-highlight-bookmark files source)
3639 (anything-c-highlight-not-logged files source)))
3641 (defun anything-c-highlight-not-logged (files source)
3642 (loop for i in files
3643 collect (propertize i 'face anything-c-bookmarks-face3)))
3645 (defun anything-c-highlight-bookmark (bookmarks source)
3646 "Used as `candidate-transformer' to colorize bookmarks.
3647 Work both with standard Emacs bookmarks and bookmark-extensions.el."
3648 (loop for i in bookmarks
3649 for isfile = (bookmark-get-filename i)
3650 for bufp = (and (fboundp 'bmkext-get-buffer-name)
3651 (bmkext-get-buffer-name i))
3652 for handlerp = (and (fboundp 'bookmark-get-handler)
3653 (bookmark-get-handler i))
3654 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
3655 (bmkext-w3m-bookmark-p i))
3656 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
3657 (bmkext-gnus-bookmark-p i))
3658 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
3659 (bmkext-man-bookmark-p i))
3660 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
3661 (bmkext-woman-bookmark-p i))
3662 for handlerp = (bookmark-get-handler i)
3663 for isannotation = (bookmark-get-annotation i)
3664 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
3665 for isinfo = (eq handlerp 'Info-bookmark-jump)
3666 ;; Add a * if bookmark have annotation
3667 if (and isannotation (not (string-equal isannotation "")))
3668 do (setq i (concat "*" i))
3669 collect (cond (;; info buffers
3670 isinfo
3671 (propertize i 'face 'anything-bmkext-info 'help-echo isfile))
3672 (;; w3m buffers
3673 isw3m
3674 (propertize i 'face 'anything-bmkext-w3m 'help-echo isfile))
3675 (;; gnus buffers
3676 isgnus
3677 (propertize i 'face 'anything-bmkext-gnus 'help-echo isfile))
3678 (;; Man Woman
3679 (or iswoman isman)
3680 (propertize i 'face 'anything-bmkext-man 'help-echo isfile))
3681 (;; Addressbook
3682 isabook
3683 (propertize i 'face '((:foreground "Tomato"))))
3684 (;; directories
3685 (and isfile (file-directory-p isfile))
3686 (propertize i 'face anything-c-bookmarks-face1 'help-echo isfile))
3687 (;; regular files
3689 (propertize i 'face 'anything-bmkext-file 'help-echo isfile)))))
3692 ;;; Faces for bookmarks
3693 (defface anything-bmkext-info
3694 '((t (:foreground "green")))
3695 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3696 :group 'anything)
3698 (defface anything-bmkext-w3m
3699 '((t (:foreground "yellow")))
3700 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3701 :group 'anything)
3703 (defface anything-bmkext-gnus
3704 '((t (:foreground "magenta")))
3705 "*Face used for Gnus bookmarks."
3706 :group 'anything)
3708 (defface anything-bmkext-man
3709 '((t (:foreground "Orange4")))
3710 "*Face used for Woman/man bookmarks."
3711 :group 'anything)
3713 (defface anything-bmkext-no--file
3714 '((t (:foreground "grey")))
3715 "*Face used for non--file bookmarks."
3716 :group 'anything)
3718 (defface anything-bmkext-file
3719 '((t (:foreground "Deepskyblue2")))
3720 "*Face used for non--file bookmarks."
3721 :group 'anything)
3723 (defface anything-bookmarks-su-face '((t (:foreground "red")))
3724 "Face for su/sudo bookmarks."
3725 :group 'anything)
3727 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
3728 (defvar anything-c-bookmarks-face2 'anything-file-name)
3729 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
3732 ;;; Sources to filter bookmark-extensions bookmarks.
3733 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3734 ;; If you want to enable google-maps in addressbook you will need
3735 ;; Julien Danjou google-maps-el package available here:
3736 ;; http://julien.danjou.info/google-maps-el.html
3738 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
3739 "Return a filtered `bookmark-alist' sorted alphabetically."
3740 (loop
3741 with alist = (if args
3742 (apply #'(lambda (x) (funcall fn x)) args)
3743 (funcall fn))
3744 for i in alist
3745 for b = (car i)
3746 collect b into sa
3747 finally return (sort sa 'string-lessp)))
3749 ;; Addressbook
3750 (defvar anything-c-source-bmkext-addressbook
3751 '((name . "Bookmark Addressbook")
3752 (init . (lambda ()
3753 (require 'bookmark-extensions)
3754 (bookmark-maybe-load-default-file)))
3755 (candidates . anything-c-bmkext-addressbook-setup-alist)
3756 (persistent-action
3757 . (lambda (candidate)
3758 (let ((bmk (anything-bookmark-get-bookmark-from-name
3759 candidate)))
3760 (bookmark--jump-via bmk 'pop-to-buffer))))
3761 (persistent-help . "Show contact - Prefix with C-u to append")
3762 (filtered-candidate-transformer
3763 anything-c-adaptive-sort
3764 anything-c-highlight-bookmark)
3765 (action . (("Show person's data"
3766 . (lambda (candidate)
3767 (let ((bmk (anything-bookmark-get-bookmark-from-name
3768 candidate))
3769 (current-prefix-arg anything-current-prefix-arg))
3770 (bookmark-jump bmk))))
3771 ("Send Mail"
3772 . (lambda (candidate)
3773 (let ((bmk (anything-bookmark-get-bookmark-from-name
3774 candidate)))
3775 (if anything-current-prefix-arg
3776 (addressbook-set-mail-buffer1 bmk 'append)
3777 (addressbook-set-mail-buffer1 bmk)))))
3778 ("Edit Bookmark"
3779 . (lambda (candidate)
3780 (let ((bmk (anything-bookmark-get-bookmark-from-name
3781 candidate)))
3782 (addressbook-bookmark-edit
3783 (assoc bmk bookmark-alist)))))
3784 ("Insert Email at point"
3785 . (lambda (candidate)
3786 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3787 candidate))
3788 (mlist (split-string
3789 (assoc-default
3790 'email (assoc bmk bookmark-alist))
3791 ", ")))
3792 (insert
3793 (if (> (length mlist) 1)
3794 (anything-comp-read
3795 "Insert Mail Address: " mlist :must-match t)
3796 (car mlist))))))
3797 ("Show annotation"
3798 . (lambda (candidate)
3799 (let ((bmk (anything-bookmark-get-bookmark-from-name
3800 candidate)))
3801 (bookmark-show-annotation bmk))))
3802 ("Edit annotation"
3803 . (lambda (candidate)
3804 (let ((bmk (anything-bookmark-get-bookmark-from-name
3805 candidate)))
3806 (bookmark-edit-annotation bmk))))
3807 ("Show Google map"
3808 . (lambda (candidate)
3809 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3810 candidate))
3811 (full-bmk (assoc bmk bookmark-alist)))
3812 (addressbook-google-map full-bmk))))))))
3815 (defun anything-c-bmkext-addressbook-setup-alist ()
3816 "Specialized filter function for bookmarks w3m."
3817 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
3819 ;; W3m
3820 (defvar anything-c-source-bookmark-w3m
3821 '((name . "Bookmark W3m")
3822 (init . (lambda ()
3823 (require 'bookmark-extensions)
3824 (bookmark-maybe-load-default-file)))
3825 (candidates . anything-c-bookmark-w3m-setup-alist)
3826 (filtered-candidate-transformer
3827 anything-c-adaptive-sort
3828 anything-c-highlight-bookmark)
3829 (type . bookmark)))
3830 ;; (anything 'anything-c-source-bookmark-w3m)
3832 (defun anything-c-bookmark-w3m-setup-alist ()
3833 "Specialized filter function for bookmarks w3m."
3834 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
3836 ;; Images
3837 (defvar anything-c-source-bookmark-images
3838 '((name . "Bookmark Images")
3839 (init . (lambda ()
3840 (require 'bookmark-extensions)
3841 (bookmark-maybe-load-default-file)))
3842 (candidates . anything-c-bookmark-images-setup-alist)
3843 (filtered-candidate-transformer
3844 anything-c-adaptive-sort
3845 anything-c-highlight-bookmark)
3846 (type . bookmark)))
3847 ;; (anything 'anything-c-source-bookmark-images)
3849 (defun anything-c-bookmark-images-setup-alist ()
3850 "Specialized filter function for images bookmarks."
3851 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
3853 ;; Woman Man
3854 (defvar anything-c-source-bookmark-man
3855 '((name . "Bookmark Woman&Man")
3856 (init . (lambda ()
3857 (require 'bookmark-extensions)
3858 (bookmark-maybe-load-default-file)))
3859 (candidates . anything-c-bookmark-man-setup-alist)
3860 (filtered-candidate-transformer
3861 anything-c-adaptive-sort
3862 anything-c-highlight-bookmark)
3863 (type . bookmark)))
3864 ;; (anything 'anything-c-source-bookmark-man)
3866 (defun anything-c-bookmark-man-setup-alist ()
3867 "Specialized filter function for bookmarks w3m."
3868 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
3869 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
3871 ;; Gnus
3872 (defvar anything-c-source-bookmark-gnus
3873 '((name . "Bookmark Gnus")
3874 (init . (lambda ()
3875 (require 'bookmark-extensions)
3876 (bookmark-maybe-load-default-file)))
3877 (candidates . anything-c-bookmark-gnus-setup-alist)
3878 (filtered-candidate-transformer
3879 anything-c-adaptive-sort
3880 anything-c-highlight-bookmark)
3881 (type . bookmark)))
3882 ;; (anything 'anything-c-source-bookmark-gnus)
3884 (defun anything-c-bookmark-gnus-setup-alist ()
3885 "Specialized filter function for bookmarks gnus."
3886 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
3888 ;; Info
3889 (defvar anything-c-source-bookmark-info
3890 '((name . "Bookmark Info")
3891 (init . (lambda ()
3892 (require 'bookmark-extensions)
3893 (bookmark-maybe-load-default-file)))
3894 (candidates . anything-c-bookmark-info-setup-alist)
3895 (filtered-candidate-transformer
3896 anything-c-adaptive-sort
3897 anything-c-highlight-bookmark)
3898 (type . bookmark)))
3899 ;; (anything 'anything-c-source-bookmark-info)
3901 (defun anything-c-bookmark-info-setup-alist ()
3902 "Specialized filter function for bookmarks info."
3903 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
3905 ;; Local Files&directories
3906 (defvar anything-c-source-bookmark-files&dirs
3907 '((name . "Bookmark Files&Directories")
3908 (init . (lambda ()
3909 (require 'bookmark-extensions)
3910 (bookmark-maybe-load-default-file)))
3911 (candidates . anything-c-bookmark-local-files-setup-alist)
3912 (filtered-candidate-transformer
3913 anything-c-adaptive-sort
3914 anything-c-highlight-bookmark)
3915 (type . bookmark)))
3916 ;; (anything 'anything-c-source-bookmark-files&dirs)
3918 (defun anything-c-bookmark-local-files-setup-alist ()
3919 "Specialized filter function for bookmarks locals files."
3920 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
3922 ;; Su Files&directories
3923 (defvar anything-c-source-bookmark-su-files&dirs
3924 '((name . "Bookmark Root-Files&Directories")
3925 (init . (lambda ()
3926 (require 'bookmark-extensions)
3927 (bookmark-maybe-load-default-file)))
3928 (candidates . anything-c-bookmark-su-files-setup-alist)
3929 (filtered-candidate-transformer
3930 anything-c-adaptive-sort
3931 anything-c-highlight-bookmark-su)
3932 (type . bookmark)))
3933 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3935 (defun anything-c-bookmark-su-files-setup-alist ()
3936 "Specialized filter function for bookmarks su/sudo files."
3937 (loop
3938 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3939 for i in l
3940 for isfile = (bookmark-get-filename i)
3941 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3942 (save-match-data
3943 (string-match tramp-file-name-regexp isfile)))
3944 for issu = (and istramp
3945 (string-match bmkext-su-or-sudo-regexp isfile))
3946 if issu
3947 collect i))
3949 ;; Ssh Files&directories
3950 (defvar anything-c-source-bookmark-ssh-files&dirs
3951 '((name . "Bookmark Ssh-Files&Directories")
3952 (init . (lambda ()
3953 (require 'bookmark-extensions)
3954 (bookmark-maybe-load-default-file)))
3955 (candidates . anything-c-bookmark-ssh-files-setup-alist)
3956 (filtered-candidate-transformer . anything-c-adaptive-sort)
3957 (type . bookmark)))
3958 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3960 (defun anything-c-bookmark-ssh-files-setup-alist ()
3961 "Specialized filter function for bookmarks ssh files."
3962 (loop
3963 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3964 for i in l
3965 for isfile = (bookmark-get-filename i)
3966 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3967 (save-match-data
3968 (string-match tramp-file-name-regexp isfile)))
3969 for isssh = (and istramp
3970 (string-match "/ssh:" isfile))
3971 if isssh
3972 collect i))
3975 ;; All bookmark-extensions sources.
3976 ;;;###autoload
3977 (defun anything-bookmark-ext ()
3978 "Preconfigured `anything' for bookmark-extensions sources.
3979 Needs bookmark-ext.el
3981 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3982 (interactive)
3983 (anything
3984 :sources
3985 '(anything-c-source-bookmark-files&dirs
3986 anything-c-source-bookmark-w3m
3987 anything-c-source-bmkext-addressbook
3988 anything-c-source-bookmark-gnus
3989 anything-c-source-bookmark-info
3990 anything-c-source-bookmark-man
3991 anything-c-source-bookmark-images
3992 anything-c-source-bookmark-su-files&dirs
3993 anything-c-source-bookmark-ssh-files&dirs)
3994 :prompt "SearchBookmark: "
3995 :buffer "*anything bmkext*"))
3998 ;; Firefox bookmarks
3999 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
4000 ;; (only for firefox versions >=3)
4001 ;; To achieve that, open about:config in firefox and double click on this line to enable value
4002 ;; to true:
4003 ;; user_pref("browser.bookmarks.autoExportHTML", false);
4004 ;; You should have now:
4005 ;; user_pref("browser.bookmarks.autoExportHTML", true);
4007 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
4008 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
4010 (defun anything-get-firefox-user-init-dir ()
4011 "Guess the default Firefox user directory name."
4012 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
4013 (moz-user-dir
4014 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
4015 (goto-char (point-min))
4016 (prog1
4017 (when (search-forward "Path=" nil t)
4018 (buffer-substring-no-properties (point) (point-at-eol)))
4019 (kill-buffer)))))
4020 (file-name-as-directory (concat moz-dir moz-user-dir))))
4022 (defun anything-guess-firefox-bookmark-file ()
4023 "Return the path of the Firefox bookmarks file."
4024 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
4026 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
4027 "Parse html bookmark FILE and return an alist with (title . url) as elements."
4028 (let (bookmarks-alist url title)
4029 (with-temp-buffer
4030 (insert-file-contents file)
4031 (goto-char (point-min))
4032 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
4033 (forward-line 0)
4034 (when (re-search-forward url-regexp nil t)
4035 (setq url (match-string 0)))
4036 (when (re-search-forward bmk-regexp nil t)
4037 (setq title (match-string 1)))
4038 (push (cons title url) bookmarks-alist)
4039 (forward-line)))
4040 (nreverse bookmarks-alist)))
4042 (defvar anything-c-firefox-bookmarks-alist nil)
4043 (defvar anything-c-source-firefox-bookmarks
4044 '((name . "Firefox Bookmarks")
4045 (init . (lambda ()
4046 (setq anything-c-firefox-bookmarks-alist
4047 (anything-html-bookmarks-to-alist
4048 (anything-guess-firefox-bookmark-file)
4049 anything-firefox-bookmark-url-regexp
4050 anything-firefox-bookmarks-regexp))))
4051 (candidates . (lambda ()
4052 (mapcar #'car anything-c-firefox-bookmarks-alist)))
4053 (filtered-candidate-transformer
4054 anything-c-adaptive-sort
4055 anything-c-highlight-firefox-bookmarks)
4056 (action . (("Browse Url Firefox"
4057 . (lambda (candidate)
4058 (browse-url-firefox
4059 (anything-c-firefox-bookmarks-get-value candidate))))
4060 ("Browse Url w3m"
4061 . (lambda (candidate)
4062 (w3m-browse-url
4063 (anything-c-firefox-bookmarks-get-value candidate))))
4064 ("Copy Url"
4065 . (lambda (elm)
4066 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
4068 ;; (anything 'anything-c-source-firefox-bookmarks)
4070 (defun anything-c-firefox-bookmarks-get-value (elm)
4071 (assoc-default elm anything-c-firefox-bookmarks-alist))
4073 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
4074 (loop for i in bookmarks
4075 collect (propertize
4076 i 'face '((:foreground "YellowGreen"))
4077 'help-echo (anything-c-firefox-bookmarks-get-value i))))
4079 ;; W3m bookmark
4080 (eval-when-compile (require 'w3m-bookmark nil t))
4081 (unless (and (require 'w3m nil t)
4082 (require 'w3m-bookmark nil t))
4083 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
4086 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
4087 "Face for w3m bookmarks" :group 'anything)
4089 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
4090 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
4091 (defvar anything-c-w3m-bookmarks-alist nil)
4092 (defvar anything-c-source-w3m-bookmarks
4093 '((name . "W3m Bookmarks")
4094 (init . (lambda ()
4095 (setq anything-c-w3m-bookmarks-alist
4096 (anything-html-bookmarks-to-alist
4097 w3m-bookmark-file
4098 anything-w3m-bookmark-url-regexp
4099 anything-w3m-bookmarks-regexp))))
4100 (candidates . (lambda ()
4101 (mapcar #'car anything-c-w3m-bookmarks-alist)))
4102 (filtered-candidate-transformer
4103 anything-c-adaptive-sort
4104 anything-c-highlight-w3m-bookmarks)
4105 (action . (("Browse Url"
4106 . (lambda (candidate)
4107 (anything-c-w3m-browse-bookmark candidate)))
4108 ("Copy Url"
4109 . (lambda (elm)
4110 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
4111 ("Browse Url Firefox"
4112 . (lambda (candidate)
4113 (anything-c-w3m-browse-bookmark candidate t)))
4114 ("Delete Bookmark"
4115 . (lambda (candidate)
4116 (anything-c-w3m-delete-bookmark candidate)))
4117 ("Rename Bookmark"
4118 . (lambda (candidate)
4119 (anything-c-w3m-rename-bookmark candidate)))))
4120 (persistent-action . (lambda (candidate)
4121 (if current-prefix-arg
4122 (anything-c-w3m-browse-bookmark candidate t)
4123 (anything-c-w3m-browse-bookmark candidate nil t))))
4124 (persistent-help . "Open URL with emacs-w3m in new tab / \
4125 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
4126 "Needs w3m and emacs-w3m.
4128 http://w3m.sourceforge.net/
4129 http://emacs-w3m.namazu.org/")
4131 ;; (anything 'anything-c-source-w3m-bookmarks)
4133 (defun anything-c-w3m-bookmarks-get-value (elm)
4134 (replace-regexp-in-string
4135 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
4137 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
4138 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
4139 (arg (and (eq fn 'w3m-browse-url) new-tab)))
4140 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
4142 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
4143 (loop for i in bookmarks
4144 collect (propertize
4145 i 'face 'anything-w3m-bookmarks-face
4146 'help-echo (anything-c-w3m-bookmarks-get-value i))))
4149 (defun anything-c-w3m-delete-bookmark (elm)
4150 (save-excursion
4151 (find-file-literally w3m-bookmark-file)
4152 (goto-char (point-min))
4153 (when (re-search-forward elm nil t)
4154 (beginning-of-line)
4155 (delete-region (point)
4156 (line-end-position))
4157 (delete-blank-lines))
4158 (save-buffer (current-buffer))
4159 (kill-buffer (current-buffer))))
4161 (defun anything-c-w3m-rename-bookmark (elm)
4162 (let* ((old-title (replace-regexp-in-string ">" "" elm))
4163 (new-title (read-string "NewTitle: " old-title)))
4164 (save-excursion
4165 (find-file-literally w3m-bookmark-file)
4166 (goto-char (point-min))
4167 (when (re-search-forward (concat elm "<") nil t)
4168 (goto-char (1- (point)))
4169 (delete-char (- (length old-title)))
4170 (insert new-title))
4171 (save-buffer (current-buffer))
4172 (kill-buffer (current-buffer)))))
4174 ;;;; <Library>
4175 ;;; Elisp library scan
4176 (defvar anything-c-source-elisp-library-scan
4177 '((name . "Elisp libraries (Scan)")
4178 (init . (anything-c-elisp-library-scan-init))
4179 (candidates-in-buffer)
4180 (action ("Find library"
4181 . (lambda (candidate) (find-file (find-library-name candidate))))
4182 ("Find library other window"
4183 . (lambda (candidate)
4184 (find-file-other-window (find-library-name candidate))))
4185 ("Load library"
4186 . (lambda (candidate) (load-library candidate))))))
4187 ;; (anything 'anything-c-source-elisp-library-scan)
4189 (defun anything-c-elisp-library-scan-init ()
4190 "Init anything buffer status."
4191 (let ((anything-buffer (anything-candidate-buffer 'global))
4192 (library-list (anything-c-elisp-library-scan-list)))
4193 (with-current-buffer anything-buffer
4194 (dolist (library library-list)
4195 (insert (format "%s\n" library))))))
4197 (defun anything-c-elisp-library-scan-list (&optional dirs string)
4198 "Do completion for file names passed to `locate-file'.
4199 DIRS is directory to search path.
4200 STRING is string to match."
4201 ;; Use `load-path' as path when ignore `dirs'.
4202 (or dirs (setq dirs load-path))
4203 ;; Init with blank when ignore `string'.
4204 (or string (setq string ""))
4205 ;; Get library list.
4206 (let ((string-dir (file-name-directory string))
4207 ;; File regexp that suffix match `load-file-rep-suffixes'.
4208 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
4209 name
4210 names)
4211 (dolist (dir dirs)
4212 (unless dir
4213 (setq dir default-directory))
4214 (if string-dir
4215 (setq dir (expand-file-name string-dir dir)))
4216 (when (file-directory-p dir)
4217 (dolist (file (file-name-all-completions
4218 (file-name-nondirectory string) dir))
4219 ;; Suffixes match `load-file-rep-suffixes'.
4220 (setq name (if string-dir (concat string-dir file) file))
4221 (if (string-match match-regexp name)
4222 (add-to-list 'names name)))))
4223 names))
4225 ;;;; <Programming>
4226 ;;; Imenu
4227 (defvar anything-c-imenu-delimiter " / ")
4229 (defvar anything-c-imenu-index-filter nil)
4230 (make-variable-buffer-local 'anything-c-imenu-index-filter)
4232 (defvar anything-c-cached-imenu-alist nil)
4233 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
4235 (defvar anything-c-cached-imenu-candidates nil)
4236 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
4238 (defvar anything-c-cached-imenu-tick nil)
4239 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
4241 (eval-when-compile (require 'imenu))
4242 (setq imenu-auto-rescan t)
4244 (defun anything-imenu-create-candidates (entry)
4245 "Create candidates with ENTRY."
4246 (if (listp (cdr entry))
4247 (mapcan
4248 (lambda (sub)
4249 (if (consp (cdr sub))
4250 (mapcar
4251 (lambda (subentry)
4252 (concat (car entry) anything-c-imenu-delimiter subentry))
4253 (anything-imenu-create-candidates sub))
4254 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
4255 (cdr entry))
4256 (list entry)))
4258 (defvar anything-c-source-imenu
4259 '((name . "Imenu")
4260 (init . (lambda () (require 'imenu)))
4261 (candidates . anything-c-imenu-candidates)
4262 (persistent-action . (lambda (elm)
4263 (anything-c-imenu-default-action elm)
4264 (unless (fboundp 'semantic-imenu-tag-overlay)
4265 (anything-match-line-color-current-line))))
4266 (persistent-help . "Show this entry")
4267 (action . anything-c-imenu-default-action))
4268 "See (info \"(emacs)Imenu\")")
4270 ;; (anything 'anything-c-source-imenu)
4272 (defun anything-c-imenu-candidates ()
4273 (with-current-buffer anything-current-buffer
4274 (let ((tick (buffer-modified-tick)))
4275 (if (eq anything-c-cached-imenu-tick tick)
4276 anything-c-cached-imenu-candidates
4277 (setq imenu--index-alist nil)
4278 (setq anything-c-cached-imenu-tick tick
4279 anything-c-cached-imenu-candidates
4280 (ignore-errors
4281 (mapcan
4282 'anything-imenu-create-candidates
4283 (setq anything-c-cached-imenu-alist
4284 (let ((index (imenu--make-index-alist)))
4285 (if anything-c-imenu-index-filter
4286 (funcall anything-c-imenu-index-filter index)
4287 index))))))
4288 (setq anything-c-cached-imenu-candidates
4289 (mapcar #'(lambda (x)
4290 (if (stringp x)
4292 (car x)))
4293 anything-c-cached-imenu-candidates))))))
4295 (setq imenu-default-goto-function 'imenu-default-goto-function)
4296 (defun anything-c-imenu-default-action (elm)
4297 "The default action for `anything-c-source-imenu'."
4298 (let ((path (split-string elm anything-c-imenu-delimiter))
4299 (alist anything-c-cached-imenu-alist))
4300 (if (> (length path) 1)
4301 (progn
4302 (setq alist (assoc (car path) alist))
4303 (setq elm (cadr path))
4304 (imenu (assoc elm alist)))
4305 (imenu (assoc elm alist)))))
4307 ;;; Ctags
4308 (defvar anything-c-ctags-modes
4309 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
4310 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
4311 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
4313 (defun anything-c-source-ctags-init ()
4314 (when (and buffer-file-name
4315 (memq major-mode anything-c-ctags-modes)
4316 (anything-current-buffer-is-modified))
4317 (with-current-buffer (anything-candidate-buffer 'local)
4318 (call-process-shell-command
4319 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
4320 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
4321 anything-buffer-file-name)
4322 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
4323 nil (current-buffer))
4324 (goto-char (point-min))
4325 (forward-line 2)
4326 (delete-region (point-min) (point))
4327 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
4328 for lineno-start = (point)
4329 for lineno = (buffer-substring
4330 lineno-start
4331 (1- (search-forward "," (point-at-eol) t)))
4333 (beginning-of-line)
4334 (insert (format "%5s:" lineno))
4335 (search-forward "\177" (point-at-eol) t)
4336 (delete-region (1- (point)) (point-at-eol))
4337 (forward-line 1)))))
4339 (defvar anything-c-source-ctags
4340 '((name . "Exuberant ctags")
4341 (init . anything-c-source-ctags-init)
4342 (candidates-in-buffer)
4343 (adjust)
4344 (type . line))
4345 "Needs Exuberant Ctags.
4347 http://ctags.sourceforge.net/")
4348 ;; (anything 'anything-c-source-ctags)
4350 ;; Semantic
4351 (eval-when-compile (require 'semantic nil t))
4352 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
4353 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
4354 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
4355 (defvar anything-semantic-candidates nil)
4357 (defun anything-semantic-construct-candidates (tags depth)
4358 (when (require 'semantic nil t)
4359 (apply
4360 'append
4361 (mapcar
4362 (lambda (tag)
4363 (if (listp tag)
4364 (let ((type (semantic-tag-type tag))
4365 (class (semantic-tag-class tag)))
4366 (if (or (and (stringp type)
4367 (or (string= type "class")
4368 (string= type "namespace")))
4369 (eq class 'function)
4370 (eq class 'variable))
4371 (cons (cons (concat (make-string (* depth 2) ?\s)
4372 (semantic-format-tag-summarize tag nil t))
4373 tag)
4374 (anything-semantic-construct-candidates
4375 (semantic-tag-components tag) (1+ depth)))))))
4376 tags))))
4378 (defun anything-semantic-default-action (candidate)
4379 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
4380 (semantic-go-to-tag tag)))
4382 (defvar anything-c-source-semantic
4383 '((name . "Semantic Tags")
4384 (init . (lambda ()
4385 (setq anything-semantic-candidates
4386 (ignore-errors (anything-semantic-construct-candidates
4387 (semantic-fetch-tags) 0)))))
4388 (candidates . (lambda ()
4389 (if anything-semantic-candidates
4390 (mapcar 'car anything-semantic-candidates))))
4391 (persistent-action . (lambda (elm)
4392 (anything-semantic-default-action elm)
4393 (anything-match-line-color-current-line)))
4394 (persistent-help . "Show this entry")
4395 (action . anything-semantic-default-action)
4396 "Needs semantic in CEDET.
4398 http://cedet.sourceforge.net/semantic.shtml
4399 http://cedet.sourceforge.net/"))
4401 ;; (anything 'anything-c-source-semantic)
4403 ;;; Function is called by
4404 ;;;###autoload
4405 (defun anything-simple-call-tree ()
4406 "Preconfigured `anything' for simple-call-tree. List function relationships.
4408 Needs simple-call-tree.el.
4409 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
4410 (interactive)
4411 (anything-other-buffer
4412 '(anything-c-source-simple-call-tree-functions-callers
4413 anything-c-source-simple-call-tree-callers-functions)
4414 "*anything simple-call-tree*"))
4416 (defvar anything-c-source-simple-call-tree-functions-callers
4417 '((name . "Function is called by")
4418 (init . anything-c-simple-call-tree-functions-callers-init)
4419 (multiline)
4420 (candidates . anything-c-simple-call-tree-candidates)
4421 (persistent-action . anything-c-simple-call-tree-persistent-action)
4422 (persistent-help . "Show function definitions by rotation")
4423 (action ("Find definition selected by persistent-action" .
4424 anything-c-simple-call-tree-find-definition)))
4425 "Needs simple-call-tree.el.
4426 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4428 (defvar anything-c-simple-call-tree-tick nil)
4429 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
4430 (defun anything-c-simple-call-tree-analyze-maybe ()
4431 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
4432 (simple-call-tree-analyze)
4433 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
4435 (defun anything-c-simple-call-tree-init-base (function message)
4436 (require 'simple-call-tree)
4437 (with-no-warnings
4438 (when (anything-current-buffer-is-modified)
4439 (anything-c-simple-call-tree-analyze-maybe)
4440 (let ((list (funcall function simple-call-tree-alist)))
4441 (with-current-buffer (anything-candidate-buffer 'local)
4442 (dolist (entry list)
4443 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
4444 (insert (car entry) message
4445 (if (string= funcs " ")
4446 " no functions."
4447 funcs)
4448 "\n\n"))))))))
4450 (defun anything-c-simple-call-tree-functions-callers-init ()
4451 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
4452 " is called by\n"))
4454 (defun anything-c-simple-call-tree-candidates ()
4455 (with-current-buffer (anything-candidate-buffer)
4456 (split-string (buffer-string) "\n\n")))
4458 (defvar anything-c-simple-call-tree-related-functions nil)
4459 (defvar anything-c-simple-call-tree-function-index 0)
4460 (defun anything-c-simple-call-tree-persistent-action (candidate)
4461 (unless (eq last-command 'anything-execute-persistent-action)
4462 (setq anything-c-simple-call-tree-related-functions
4463 (delete "no functions."
4464 (split-string
4465 (replace-regexp-in-string " \\| is called by\\| calls "
4466 "" candidate)
4467 "\n")))
4468 (setq anything-c-simple-call-tree-function-index -1))
4469 (incf anything-c-simple-call-tree-function-index)
4470 (anything-c-simple-call-tree-find-definition candidate))
4472 (defun anything-c-simple-call-tree-find-definition (candidate)
4473 (find-function
4474 (intern
4475 (nth (mod anything-c-simple-call-tree-function-index
4476 (length anything-c-simple-call-tree-related-functions))
4477 anything-c-simple-call-tree-related-functions))))
4479 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
4481 ;;; Function calls
4482 (defvar anything-c-source-simple-call-tree-callers-functions
4483 '((name . "Function calls")
4484 (init . anything-c-simple-call-tree-callers-functions-init)
4485 (multiline)
4486 (candidates . anything-c-simple-call-tree-candidates)
4487 (persistent-action . anything-c-simple-call-tree-persistent-action)
4488 (persistent-help . "Show function definitions by rotation")
4489 (action ("Find definition selected by persistent-action" .
4490 anything-c-simple-call-tree-find-definition)))
4491 "Needs simple-call-tree.el.
4492 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4494 (defun anything-c-simple-call-tree-callers-functions-init ()
4495 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
4497 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
4499 ;;; Commands/Options with doc
4500 (defvar anything-c-auto-document-data nil)
4501 (make-variable-buffer-local 'anything-c-auto-document-data)
4502 (defvar anything-c-source-commands-and-options-in-file
4503 '((name . "Commands/Options in file")
4504 (header-name
4505 . (lambda (x) (format "Commands/Options in %s"
4506 (buffer-local-value 'buffer-file-name
4507 anything-current-buffer))))
4508 (candidates . anything-command-and-options-candidates)
4509 (multiline)
4510 (action . imenu))
4511 "List Commands and Options with doc. It needs auto-document.el .
4513 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
4515 (eval-when-compile (require 'auto-document nil t))
4516 (defun anything-command-and-options-candidates ()
4517 (with-current-buffer anything-current-buffer
4518 (when (and (require 'auto-document nil t)
4519 (eq major-mode 'emacs-lisp-mode)
4520 (or (anything-current-buffer-is-modified)
4521 (not anything-c-auto-document-data)))
4522 (or imenu--index-alist (imenu--make-index-alist t))
4523 (setq anything-c-auto-document-data
4524 (destructuring-bind (commands options)
4525 (adoc-construct anything-current-buffer)
4526 (append
4527 (loop for (command . doc) in commands
4528 for cmdname = (symbol-name command)
4529 collect
4530 (cons
4531 (format "Command: %s\n %s"
4532 (propertize cmdname 'face font-lock-function-name-face)
4533 (adoc-first-line doc))
4534 (assoc cmdname imenu--index-alist)))
4535 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
4536 for (option doc default) in options
4537 for optname = (symbol-name option)
4538 collect
4539 (cons
4540 (format "Option: %s\n %s\n default = %s"
4541 (propertize optname 'face font-lock-variable-name-face)
4542 (adoc-first-line doc)
4543 (adoc-prin1-to-string default))
4544 (assoc optname
4545 var-alist)))))))
4546 anything-c-auto-document-data))
4548 ;; (anything 'anything-c-source-commands-and-options-in-file)
4550 ;;;; <Color and Face>
4551 ;;; Customize Face
4552 (defvar anything-c-source-customize-face
4553 '((name . "Customize Face")
4554 (init . (lambda ()
4555 (unless (anything-candidate-buffer)
4556 (save-window-excursion (list-faces-display))
4557 (anything-candidate-buffer (get-buffer "*Faces*")))))
4558 (candidates-in-buffer)
4559 (get-line . buffer-substring)
4560 (action . (lambda (line)
4561 (customize-face (intern (car (split-string line))))))
4562 (requires-pattern . 3))
4563 "See (info \"(emacs)Faces\")")
4564 ;; (anything 'anything-c-source-customize-face)
4566 ;; Color
4567 (defvar anything-c-source-colors
4568 '((name . "Colors")
4569 (init . (lambda () (unless (anything-candidate-buffer)
4570 (save-window-excursion (list-colors-display))
4571 (anything-candidate-buffer (get-buffer "*Colors*")))))
4572 (candidates-in-buffer)
4573 (get-line . buffer-substring)
4574 (action
4575 ("Copy Name" . (lambda (candidate)
4576 (kill-new (anything-c-colors-get-name candidate))))
4577 ("Copy RGB" . (lambda (candidate)
4578 (kill-new (anything-c-colors-get-rgb candidate))))
4579 ("Insert Name" . (lambda (candidate)
4580 (with-current-buffer anything-current-buffer
4581 (insert (anything-c-colors-get-name candidate)))))
4582 ("Insert RGB" . (lambda (candidate)
4583 (with-current-buffer anything-current-buffer
4584 (insert (anything-c-colors-get-rgb candidate))))))))
4585 ;; (anything 'anything-c-source-colors)
4587 (defun anything-c-colors-get-name (candidate)
4588 "Get color name."
4589 (replace-regexp-in-string
4590 " " ""
4591 (with-temp-buffer
4592 (insert (capitalize candidate))
4593 (goto-char (point-min))
4594 (search-forward-regexp "\\s-\\{2,\\}")
4595 (delete-region (point) (point-max))
4596 (buffer-string))))
4598 (defun anything-c-colors-get-rgb (candidate)
4599 "Get color RGB."
4600 (replace-regexp-in-string
4601 " " ""
4602 (with-temp-buffer
4603 (insert (capitalize candidate))
4604 (goto-char (point-max))
4605 (search-backward-regexp "\\s-\\{2,\\}")
4606 (delete-region (point) (point-min))
4607 (buffer-string))))
4609 ;;;; <Search Engine>
4610 ;;; Tracker desktop search
4611 (defvar anything-c-source-tracker-search
4612 '((name . "Tracker Search")
4613 (candidates . (lambda ()
4614 (start-process "tracker-search-process" nil
4615 "tracker-search"
4616 anything-pattern)))
4617 (type . file)
4618 (requires-pattern . 3)
4619 (delayed))
4620 "Source for retrieving files matching the current input pattern
4621 with the tracker desktop search.")
4622 ;; (anything 'anything-c-source-tracker-search)
4624 ;;; Spotlight (MacOS X desktop search)
4625 (defvar anything-c-source-mac-spotlight
4626 '((name . "mdfind")
4627 (candidates
4628 . (lambda () (start-process "mdfind-process" nil "mdfind" anything-pattern)))
4629 (type . file)
4630 (requires-pattern . 3)
4631 (delayed))
4632 "Source for retrieving files via Spotlight's command line
4633 utility mdfind.")
4634 ;; (anything 'anything-c-source-mac-spotlight)
4637 ;;;; <Kill ring>
4638 ;;; Kill ring
4639 (defvar anything-c-source-kill-ring
4640 '((name . "Kill Ring")
4641 (init . (lambda () (anything-attrset 'last-command last-command)))
4642 (candidates . anything-c-kill-ring-candidates)
4643 (action . anything-c-kill-ring-action)
4644 (last-command)
4645 (migemo)
4646 (multiline))
4647 "Source for browse and insert contents of kill-ring.")
4649 (defun anything-c-kill-ring-candidates ()
4650 (loop for kill in kill-ring
4651 unless (or (< (length kill) anything-kill-ring-threshold)
4652 (string-match "^[\\s\\t]+$" kill))
4653 collect kill))
4655 (defun anything-c-kill-ring-action (str)
4656 "Insert STR in `kill-ring' and set STR to the head.
4657 If this action is executed just after `yank',
4658 replace with STR as yanked string."
4659 (setq kill-ring (delete str kill-ring))
4660 (if (not (eq (anything-attr 'last-command) 'yank))
4661 (insert-for-yank str)
4662 ;; from `yank-pop'
4663 (let ((inhibit-read-only t)
4664 (before (< (point) (mark t))))
4665 (if before
4666 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
4667 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
4668 (setq yank-undo-function nil)
4669 (set-marker (mark-marker) (point) (current-buffer))
4670 (insert-for-yank str)
4671 ;; Set the window start back where it was in the yank command,
4672 ;; if possible.
4673 (set-window-start (selected-window) yank-window-start t)
4674 (if before
4675 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
4676 ;; It is cleaner to avoid activation, even though the command
4677 ;; loop would deactivate the mark because we inserted text.
4678 (goto-char (prog1 (mark t)
4679 (set-marker (mark-marker) (point) (current-buffer)))))))
4680 (kill-new str))
4682 ;; (anything 'anything-c-source-kill-ring)
4684 ;;;; <Mark ring>
4685 ;; DO NOT include these sources in `anything-sources' use
4686 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
4687 ;; `anything-all-mark-rings' instead.
4689 (defun anything-c-source-mark-ring-candidates ()
4690 (flet ((get-marks (pos)
4691 (save-excursion
4692 (goto-char pos)
4693 (beginning-of-line)
4694 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
4695 (when (string= "" line)
4696 (setq line "<EMPTY LINE>"))
4697 (format "%7d: %s" (line-number-at-pos) line)))))
4698 (with-current-buffer anything-current-buffer
4699 (loop
4700 with marks = (cons (mark-marker) mark-ring)
4701 with recip = nil
4702 for i in marks
4703 for m = (get-marks i)
4704 unless (member m recip)
4705 collect m into recip
4706 finally return recip))))
4708 (defvar anything-mark-ring-cache nil)
4709 (defvar anything-c-source-mark-ring
4710 '((name . "mark-ring")
4711 (init . (lambda ()
4712 (setq anything-mark-ring-cache
4713 (ignore-errors (anything-c-source-mark-ring-candidates)))))
4714 (candidates . (lambda ()
4715 (anything-aif anything-mark-ring-cache
4716 it)))
4717 (action . (("Goto line"
4718 . (lambda (candidate)
4719 (anything-goto-line (string-to-number candidate))))))
4720 (persistent-action . (lambda (candidate)
4721 (anything-goto-line (string-to-number candidate))
4722 (anything-match-line-color-current-line)))
4723 (persistent-help . "Show this line")))
4725 ;; (anything 'anything-c-source-mark-ring)
4727 ;;;###autoload
4728 (defun anything-mark-ring ()
4729 "Preconfigured `anything' for `anything-c-source-mark-ring'."
4730 (interactive)
4731 (anything 'anything-c-source-mark-ring))
4733 ;;; Global-mark-ring
4734 (defvar anything-c-source-global-mark-ring
4735 '((name . "global-mark-ring")
4736 (candidates . anything-c-source-global-mark-ring-candidates)
4737 (action . (("Goto line"
4738 . (lambda (candidate)
4739 (let ((items (split-string candidate ":")))
4740 (switch-to-buffer (second items))
4741 (anything-goto-line (string-to-number (car items))))))))
4742 (persistent-action . (lambda (candidate)
4743 (let ((items (split-string candidate ":")))
4744 (switch-to-buffer (second items))
4745 (anything-goto-line (string-to-number (car items)))
4746 (anything-match-line-color-current-line))))
4747 (persistent-help . "Show this line")))
4749 (defun anything-c-source-global-mark-ring-candidates ()
4750 (flet ((buf-fn (m)
4751 (with-current-buffer (marker-buffer m)
4752 (goto-char m)
4753 (beginning-of-line)
4754 (let (line)
4755 (if (string= "" line)
4756 (setq line "<EMPTY LINE>")
4757 (setq line (car (split-string (thing-at-point 'line)
4758 "[\n\r]"))))
4759 (format "%7d:%s: %s"
4760 (line-number-at-pos) (marker-buffer m) line)))))
4761 (loop
4762 with marks = global-mark-ring
4763 with recip = nil
4764 for i in marks
4765 for gm = (unless (or (string-match
4766 "^ " (format "%s" (marker-buffer i)))
4767 (null (marker-buffer i)))
4768 (buf-fn i))
4769 when (and gm (not (member gm recip)))
4770 collect gm into recip
4771 finally return recip)))
4773 ;; (anything 'anything-c-source-global-mark-ring)
4775 ;;;###autoload
4776 (defun anything-global-mark-ring ()
4777 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4778 (interactive)
4779 (anything 'anything-c-source-global-mark-ring))
4781 ;;;###autoload
4782 (defun anything-all-mark-rings ()
4783 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4784 `anything-c-source-mark-ring'."
4785 (interactive)
4786 (anything '(anything-c-source-global-mark-ring
4787 anything-c-source-mark-ring)))
4789 ;;;; <Register>
4790 ;;; Insert from register
4791 (defvar anything-c-source-register
4792 '((name . "Registers")
4793 (candidates . anything-c-register-candidates)
4794 (action-transformer . anything-c-register-action-transformer)
4795 (multiline)
4796 (action))
4797 "See (info \"(emacs)Registers\")")
4799 (defun anything-c-register-candidates ()
4800 "Collecting register contents and appropriate commands."
4801 (loop for (char . val) in register-alist
4802 for key = (single-key-description char)
4803 for string-actions =
4804 (cond
4805 ((numberp val)
4806 (list (int-to-string val)
4807 'insert-register
4808 'increment-register))
4809 ((markerp val)
4810 (let ((buf (marker-buffer val)))
4811 (if (null buf)
4812 (list "a marker in no buffer")
4813 (list (concat
4814 "a buffer position:"
4815 (buffer-name buf)
4816 ", position "
4817 (int-to-string (marker-position val)))
4818 'jump-to-register
4819 'insert-register))))
4820 ((and (consp val) (window-configuration-p (car val)))
4821 (list "window configuration."
4822 'jump-to-register))
4823 ((and (consp val) (frame-configuration-p (car val)))
4824 (list "frame configuration."
4825 'jump-to-register))
4826 ((and (consp val) (eq (car val) 'file))
4827 (list (concat "file:"
4828 (prin1-to-string (cdr val))
4829 ".")
4830 'jump-to-register))
4831 ((and (consp val) (eq (car val) 'file-query))
4832 (list (concat "file:a file-query reference: file "
4833 (car (cdr val))
4834 ", position "
4835 (int-to-string (car (cdr (cdr val))))
4836 ".")
4837 'jump-to-register))
4838 ((consp val)
4839 (let ((lines (format "%4d" (length val))))
4840 (list (format "%s: %s\n" lines
4841 (truncate-string-to-width
4842 (mapconcat 'identity (list (car val))
4843 ;; (mapconcat (lambda (y) y) val
4844 "^J") (- (window-width) 15)))
4845 'insert-register)))
4846 ((stringp val)
4847 (list ;; without properties
4848 (substring-no-properties val)
4849 'insert-register
4850 'append-to-register
4851 'prepend-to-register))
4853 "GARBAGE!"))
4854 collect (cons (format "register %3s: %s" key (car string-actions))
4855 (cons char (cdr string-actions)))))
4857 (defun anything-c-register-action-transformer (actions register-and-functions)
4858 "Decide actions by the contents of register."
4859 (loop with func-actions =
4860 '((insert-register
4861 "Insert Register" .
4862 (lambda (c) (insert-register (car c))))
4863 (jump-to-register
4864 "Jump to Register" .
4865 (lambda (c) (jump-to-register (car c))))
4866 (append-to-register
4867 "Append Region to Register" .
4868 (lambda (c) (append-to-register
4869 (car c) (region-beginning) (region-end))))
4870 (prepend-to-register
4871 "Prepend Region to Register" .
4872 (lambda (c) (prepend-to-register
4873 (car c) (region-beginning) (region-end))))
4874 (increment-register
4875 "Increment Prefix Arg to Register" .
4876 (lambda (c) (increment-register
4877 anything-current-prefix-arg (car c)))))
4878 for func in (cdr register-and-functions)
4879 for cell = (assq func func-actions)
4880 when cell
4881 collect (cdr cell)))
4883 ;; (anything 'anything-c-source-register)
4885 ;;;; <Headline Extraction>
4886 (defvar anything-c-source-fixme
4887 '((name . "TODO/FIXME/DRY comments")
4888 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4889 (adjust)
4890 (recenter))
4891 "Show TODO/FIXME/DRY comments in current file.")
4892 ;; (anything 'anything-c-source-fixme)
4894 (defvar anything-c-source-rd-headline
4895 '((name . "RD HeadLine")
4896 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4897 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
4898 (migemo)
4899 (subexp . 1))
4900 "Show RD headlines.
4902 RD is Ruby's POD.
4903 http://en.wikipedia.org/wiki/Ruby_Document_format")
4904 ;; (anything 'anything-c-source-rd-headline)
4906 (defvar anything-c-source-oddmuse-headline
4907 '((name . "Oddmuse HeadLine")
4908 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4909 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4910 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
4911 (migemo)
4912 (subexp . 1))
4913 "Show Oddmuse headlines, such as EmacsWiki.")
4914 ;; (anything 'anything-c-source-oddmuse-headline)
4916 (defvar anything-c-source-emacs-source-defun
4917 '((name . "Emacs Source DEFUN")
4918 (headline . "DEFUN\\|DEFVAR")
4919 (condition . (string-match "/emacs2[0-9].+/src/.+c$"
4920 (or buffer-file-name ""))))
4921 "Show DEFUN/DEFVAR in Emacs C source file.")
4922 ;; (anything 'anything-c-source-emacs-source-defun)
4924 (defvar anything-c-source-emacs-lisp-expectations
4925 '((name . "Emacs Lisp Expectations")
4926 (headline . "(desc[ ]\\|(expectations")
4927 (condition . (eq major-mode 'emacs-lisp-mode)))
4928 "Show descriptions (desc) in Emacs Lisp Expectations.
4930 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4931 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4933 (defvar anything-c-source-emacs-lisp-toplevels
4934 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4935 (headline . "^(\\|(@\\*\\|^;;;;")
4936 (get-line . buffer-substring)
4937 (condition . (eq major-mode 'emacs-lisp-mode))
4938 (adjust))
4939 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4940 linkd.el is optional because linkd stars are extracted by regexp.
4941 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4942 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4944 (defvar anything-c-source-org-headline
4945 '((name . "Org HeadLine")
4946 (headline
4947 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4948 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4949 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4950 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4951 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4952 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4953 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4954 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4955 (condition . (eq major-mode 'org-mode))
4956 (migemo)
4957 (subexp . 1)
4958 (persistent-action . (lambda (elm)
4959 (anything-c-action-line-goto elm)
4960 (org-cycle)))
4961 (action-transformer
4962 . (lambda (actions candidate)
4963 '(("Go to Line" . anything-c-action-line-goto)
4964 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
4965 "Show Org headlines.
4966 org-mode is very very much extended text-mode/outline-mode.
4968 See (find-library \"org.el\")
4969 See http://orgmode.org for the latest version.")
4971 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4972 (insert
4973 (save-excursion
4974 (anything-goto-line (car lineno-and-content))
4975 (and (looking-at org-complex-heading-regexp)
4976 (org-make-link-string (concat "*" (match-string 4)))))))
4978 ;; (anything 'anything-c-source-org-headline)
4980 ;;; Anything yaoddmuse
4981 ;; Be sure to have yaoddmuse.el installed
4982 ;; install-elisp may be required if you want to install elisp file from here.
4983 (defvar anything-yaoddmuse-use-cache-file nil)
4984 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
4985 (defvar anything-c-yaoddmuse-ew-cache nil)
4986 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4987 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
4988 (candidates . (lambda ()
4989 (if anything-yaoddmuse-use-cache-file
4990 (ignore-errors
4991 (unless anything-c-yaoddmuse-ew-cache
4992 (load anything-c-yaoddmuse-cache-file)
4993 (setq anything-c-yaoddmuse-ew-cache
4994 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4995 anything-c-yaoddmuse-ew-cache)
4996 (yaoddmuse-update-pagename t)
4997 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
4998 (action . (("Edit page" . (lambda (candidate)
4999 (yaoddmuse-edit "EmacsWiki" candidate)))
5000 ("Browse page" . (lambda (candidate)
5001 (yaoddmuse-browse-page "EmacsWiki" candidate)))
5002 ("Browse page other window" . (lambda (candidate)
5003 (if (one-window-p)
5004 (split-window-vertically))
5005 (yaoddmuse-browse-page "EmacsWiki" candidate)))
5006 ("Browse diff" . (lambda (candidate)
5007 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
5008 ("Copy URL" . (lambda (candidate)
5009 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
5010 (message "Have copy page %s's URL to yank." candidate)))
5011 ("Create page" . (lambda (candidate)
5012 (yaoddmuse-edit "EmacsWiki" anything-input)))
5013 ("Update cache" . (lambda (candidate)
5014 (if anything-yaoddmuse-use-cache-file
5015 (progn
5016 (anything-yaoddmuse-cache-pages t)
5017 (setq anything-c-yaoddmuse-ew-cache
5018 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
5019 (yaoddmuse-update-pagename))))))
5020 (action-transformer anything-c-yaoddmuse-action-transformer))
5021 "Needs yaoddmuse.el.
5023 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5025 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
5027 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
5028 '((name . "Yaoddmuse Post library (EmacsWiki)")
5029 (init . (anything-yaoddmuse-init))
5030 (candidates-in-buffer)
5031 (action . (("Post library and Browse" . (lambda (candidate)
5032 (yaoddmuse-post-file (find-library-name candidate)
5033 "EmacsWiki"
5034 (file-name-nondirectory (find-library-name candidate))
5035 nil t)))
5036 ("Post library" . (lambda (candidate)
5037 (yaoddmuse-post-file (find-library-name candidate)
5038 "EmacsWiki"
5039 (file-name-nondirectory (find-library-name candidate))))))))
5040 "Needs yaoddmuse.el.
5042 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5044 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
5046 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
5047 "Allow the use of `install-elisp' only on elisp files."
5048 (if (string-match "\.el$" candidate)
5049 (append actions '(("Install Elisp" . (lambda (elm)
5050 (install-elisp-from-emacswiki elm)))))
5051 actions))
5053 ;;;###autoload
5054 (defun anything-yaoddmuse-cache-pages (&optional load)
5055 "Fetch the list of files on emacswiki and create cache file.
5056 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
5057 (interactive)
5058 (yaoddmuse-update-pagename)
5059 (save-excursion
5060 (find-file anything-c-yaoddmuse-cache-file)
5061 (erase-buffer)
5062 (insert "(puthash \"EmacsWiki\" '(")
5063 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
5065 (insert (concat "(\"" (car i) "\") ")))
5066 (insert ") yaoddmuse-pages-hash)\n")
5067 (save-buffer)
5068 (kill-buffer (current-buffer))
5069 (when (or current-prefix-arg
5070 load)
5071 (load anything-c-yaoddmuse-cache-file))))
5073 ;;;###autoload
5074 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
5075 "Preconfigured `anything' to edit or view EmacsWiki page.
5077 Needs yaoddmuse.el.
5079 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5080 (interactive)
5081 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
5083 ;;;###autoload
5084 (defun anything-yaoddmuse-emacswiki-post-library ()
5085 "Preconfigured `anything' to post library to EmacsWiki.
5087 Needs yaoddmuse.el.
5089 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5090 (interactive)
5091 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
5093 (defun anything-yaoddmuse-init ()
5094 "Init anything buffer status."
5095 (let ((anything-buffer (anything-candidate-buffer 'global))
5096 (library-list (yaoddmuse-get-library-list)))
5097 (with-current-buffer anything-buffer
5098 ;; Insert library name.
5099 (dolist (library library-list)
5100 (insert (format "%s\n" library)))
5101 ;; Sort lines.
5102 (sort-lines nil (point-min) (point-max)))))
5104 ;;; Eev anchors
5105 (defvar anything-c-source-eev-anchor
5106 '((name . "Anchors")
5107 (candidates
5108 . (lambda ()
5109 (ignore-errors
5110 (with-current-buffer anything-current-buffer
5111 (loop initially (goto-char (point-min))
5112 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
5113 for anchor = (match-string-no-properties 1)
5114 collect (cons (format "%5d:%s"
5115 (line-number-at-pos (match-beginning 0))
5116 (format ee-anchor-format anchor)) anchor))))))
5117 (persistent-action . (lambda (item)
5118 (ee-to item)
5119 (anything-match-line-color-current-line)))
5120 (persistent-help . "Show this entry")
5121 (action . (("Goto link" . ee-to)))))
5122 ;; (anything 'anything-c-source-eev-anchor)
5124 ;;;; <Misc>
5125 ;;; Org keywords
5126 (defvar anything-c-source-org-keywords
5127 '((name . "Org Keywords")
5128 (init . anything-c-org-keywords-init)
5129 (candidates . anything-c-org-keywords-candidates)
5130 (action . anything-c-org-keywords-insert)
5131 (persistent-action . anything-c-org-keywords-show-help)
5132 (persistent-help . "Show an example and info page to describe this keyword.")
5133 (keywords-examples)
5134 (keywords)))
5135 ;; (anything 'anything-c-source-org-keywords)
5136 (defvar anything-c-org-keywords-info-location
5137 '(("#+TITLE:" . "(org)Export options")
5138 ("#+AUTHOR:" . "(org)Export options")
5139 ("#+DATE:" . "(org)Export options")
5140 ("#+EMAIL:" . "(org)Export options")
5141 ("#+DESCRIPTION:" . "(org)Export options")
5142 ("#+KEYWORDS:" . "(org)Export options")
5143 ("#+LANGUAGE:" . "(org)Export options")
5144 ("#+TEXT:" . "(org)Export options")
5145 ("#+TEXT:" . "(org)Export options")
5146 ("#+OPTIONS:" . "(org)Export options")
5147 ("#+BIND:" . "(org)Export options")
5148 ("#+LINK_UP:" . "(org)Export options")
5149 ("#+LINK_HOME:" . "(org)Export options")
5150 ("#+LATEX_HEADER:" . "(org)Export options")
5151 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
5152 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
5153 ("#+INFOJS_OPT" . "(org)Javascript support")
5154 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
5155 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
5156 ("#+ORGTBL" . "(org)Radio tables")
5157 ("#+HTML:" . "(org)Quoting HTML tags")
5158 ("#+LaTeX:" . "(org)Quoting LaTeX code")
5159 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
5160 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
5161 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
5162 ("#+BEGIN_VERSE" . "(org)Paragraphs")
5163 ("#+BEGIN_SRC" . "(org)Literal examples")
5164 ("#+CAPTION" . "(org)Tables in HTML export")
5165 ("#+LABEL" . "(org)Tables in LaTeX export")
5166 ("#+ATTR_HTML" . "(org)Links")
5167 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
5169 (defun anything-c-org-keywords-init ()
5170 (unless (anything-attr 'keywords-examples)
5171 (require 'org)
5172 (anything-attrset 'keywords-examples
5173 (append
5174 (mapcar
5175 (lambda (x)
5176 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
5177 (cons (match-string 2 x) (match-string 1 x)))
5178 (org-split-string (org-get-current-options) "\n"))
5179 (mapcar 'list org-additional-option-like-keywords)))
5180 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
5182 (defun anything-c-org-keywords-candidates ()
5183 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
5184 (anything-attr 'keywords)))
5186 (defun anything-c-org-keywords-insert (keyword)
5187 (cond ((string-match "BEGIN" keyword)
5188 (insert "#+" keyword " ")
5189 (save-excursion
5190 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
5192 (insert "#+" keyword " "))))
5194 (defun anything-c-org-keywords-show-help (keyword)
5195 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
5196 "(org)In-buffer settings"))
5197 (search-forward (concat "#+" keyword) nil t)
5198 (anything-persistent-highlight-point)
5199 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
5202 ;;; Picklist
5203 (defvar anything-c-source-picklist
5204 '((name . "Picklist")
5205 (candidates . (lambda () (mapcar 'car picklist-list)))
5206 (type . file)))
5207 ;; (anything 'anything-c-source-picklist)
5209 ;;; BBDB
5210 (defvar bbdb-records)
5211 (defvar bbdb-buffer-name)
5212 (declare-function bbdb "ext:bbdb-com")
5213 (declare-function bbdb-current-record "ext:bbdb-com")
5214 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
5215 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
5216 (declare-function bbdb-current-record "ext:bbdb-com")
5217 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
5218 (declare-function bbdb-records "ext:bbdb-com"
5219 (&optional dont-check-disk already-in-db-buffer))
5221 (defun anything-c-bbdb-candidates ()
5222 "Return a list of all names in the bbdb database. The format
5223 is \"Firstname Lastname\"."
5224 (mapcar (lambda (bbdb-record)
5225 (replace-regexp-in-string
5226 "\\s-+$" ""
5227 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
5228 (bbdb-records)))
5230 (defun anything-c-bbdb-create-contact (actions candidate)
5231 "Action transformer that returns only an entry to add the
5232 current `anything-pattern' as new contact. All other actions are
5233 removed."
5234 (if (string= candidate "*Add to contacts*")
5235 '(("Add to contacts" . (lambda (actions)
5236 (bbdb-create-internal
5237 (read-from-minibuffer "Name: " anything-c-bbdb-name)
5238 (read-from-minibuffer "Company: ")
5239 (read-from-minibuffer "Email: ")
5242 (read-from-minibuffer "Note: ")))))
5243 actions))
5245 (defun anything-c-bbdb-get-record (candidate)
5246 "Return record that match CANDIDATE."
5247 (bbdb candidate nil)
5248 (set-buffer "*BBDB*")
5249 (bbdb-current-record))
5251 (defvar anything-c-bbdb-name nil
5252 "Only for internal use.")
5254 (defvar anything-c-source-bbdb
5255 '((name . "BBDB")
5256 (candidates . anything-c-bbdb-candidates)
5257 (action ("Send a mail" . anything-c-bbdb-compose-mail)
5258 ("View person's data" . anything-c-bbdb-view-person-action))
5259 (filtered-candidate-transformer . (lambda (candidates source)
5260 (setq anything-c-bbdb-name anything-pattern)
5261 (if (not candidates)
5262 (list "*Add to contacts*")
5263 candidates)))
5264 (action-transformer . (lambda (actions candidate)
5265 (anything-c-bbdb-create-contact actions candidate))))
5266 "Needs BBDB.
5268 http://bbdb.sourceforge.net/")
5269 ;; (anything 'anything-c-source-bbdb)
5271 (defun anything-c-bbdb-view-person-action (candidate)
5272 "View BBDB data of single CANDIDATE or marked candidates."
5273 (anything-aif (anything-marked-candidates)
5274 (let ((bbdb-append-records (length it)))
5275 (dolist (i it)
5276 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
5277 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
5279 (defun anything-c-bbdb-collect-mail-addresses ()
5280 "Return a list of all mail addresses of records in bbdb buffer."
5281 (with-current-buffer bbdb-buffer-name
5282 (loop for i in bbdb-records
5283 if (bbdb-record-net (car i))
5284 collect (bbdb-dwim-net-address (car i)))))
5286 (defun anything-c-bbdb-compose-mail (candidate)
5287 "Compose a mail with all records of bbdb buffer."
5288 (anything-c-bbdb-view-person-action candidate)
5289 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
5290 (address-str (mapconcat 'identity address-list ",\n ")))
5291 (compose-mail address-str)))
5293 ;;; Evaluation Result
5294 (defvar anything-c-source-evaluation-result
5295 '((name . "Evaluation Result")
5296 (disable-shortcuts)
5297 (dummy)
5298 (filtered-candidate-transformer . (lambda (candidates source)
5299 (list
5300 (condition-case nil
5301 (with-current-buffer anything-current-buffer
5302 (pp-to-string
5303 (eval (read anything-pattern))))
5304 (error "Error")))))
5305 (action ("Copy result to kill-ring" . (lambda (candidate)
5306 (with-current-buffer anything-buffer
5307 (let ((end (save-excursion
5308 (goto-char (point-max))
5309 (search-backward "\n")
5310 (point))))
5311 (kill-region (point) end))))))))
5312 ;; (anything 'anything-c-source-evaluation-result)
5314 ;;;###autoload
5315 (defun anything-eval-expression (arg)
5316 "Preconfigured anything for `anything-c-source-evaluation-result'."
5317 (interactive "P")
5318 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
5319 nil nil nil "*anything eval*"))
5321 ;;;###autoload
5322 (defun anything-eval-expression-with-eldoc ()
5323 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
5324 (interactive)
5325 (if (window-system)
5326 (let ((timer (run-with-idle-timer eldoc-idle-delay
5327 'repeat 'anything-eldoc-show-in-eval)))
5328 (unwind-protect
5329 (call-interactively 'anything-eval-expression)
5330 (cancel-timer timer)))
5331 (call-interactively 'anything-eval-expression)))
5333 (defun anything-eldoc-show-in-eval ()
5334 "Return eldoc in a tooltip for current minibuffer input."
5335 (let* ((str-all (minibuffer-completion-contents))
5336 (sym (when str-all
5337 (with-temp-buffer
5338 (insert str-all)
5339 (goto-char (point-max))
5340 (unless (looking-back ")\\|\"") (forward-char -1))
5341 (eldoc-current-symbol))))
5342 (doc (or (eldoc-get-var-docstring sym)
5343 (eldoc-get-fnsym-args-string
5344 (car (eldoc-fnsym-in-current-sexp))))))
5345 (when doc (tooltip-show doc))))
5347 ;;; Calculation Result
5348 (defvar anything-c-source-calculation-result
5349 '((name . "Calculation Result")
5350 (dummy)
5351 (filtered-candidate-transformer . (lambda (candidates source)
5352 (list
5353 (condition-case nil
5354 (calc-eval anything-pattern)
5355 (error "error")))))
5356 (action ("Copy result to kill-ring" . kill-new))))
5357 ;; (anything 'anything-c-source-calculation-result)
5359 ;;; Google Suggestions
5360 (defvar anything-gg-sug-lgh-flag 0)
5361 (defun anything-c-google-suggest-fetch (input)
5362 "Fetch suggestions for INPUT from XML buffer.
5363 Return an alist with elements like (data . number_results)."
5364 (let ((request (concat anything-c-google-suggest-url
5365 (url-hexify-string input))))
5366 (flet ((fetch ()
5367 (loop
5368 with result-alist = (xml-get-children
5369 (car (xml-parse-region (point-min) (point-max)))
5370 'CompleteSuggestion)
5371 for i in result-alist
5372 for data = (cdr (caadr (assoc 'suggestion i)))
5373 for nqueries = (cdr (caadr (assoc 'num_queries i)))
5374 for ldata = (length data)
5376 (when (> ldata anything-gg-sug-lgh-flag)
5377 (setq anything-gg-sug-lgh-flag ldata))
5378 collect (cons data nqueries) into cont
5379 finally return cont)))
5380 (if anything-google-suggest-use-curl-p
5381 (with-temp-buffer
5382 (call-process "curl" nil t nil request)
5383 (fetch))
5384 (with-current-buffer
5385 (url-retrieve-synchronously request)
5386 (fetch))))))
5389 (defun anything-c-google-suggest-set-candidates ()
5390 "Set candidates with result and number of google results found."
5391 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
5392 (setq suggestions (loop for i in suggestions
5393 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
5394 for elm = (concat (car i)
5395 (make-string (+ 2 interval) ? )
5396 "(" (cdr i) " results)")
5397 collect (cons elm (car i))))
5398 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
5399 suggestions
5400 ;; if there is no suggestion exactly matching the input then
5401 ;; prepend a Search on Google item to the list
5402 (append
5403 suggestions
5404 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
5405 anything-input))))))
5408 (defun anything-c-google-suggest-action (candidate)
5409 "Default action to jump to a google suggested candidate."
5410 (anything-c-browse-url (concat anything-c-google-suggest-search-url
5411 (url-hexify-string candidate))))
5414 (defvar anything-c-source-google-suggest
5415 '((name . "Google Suggest")
5416 (candidates . anything-c-google-suggest-set-candidates)
5417 (action . (("Google Search" . anything-c-google-suggest-action)))
5418 (volatile)
5419 (requires-pattern . 3)
5420 (delayed)))
5422 ;; (anything 'anything-c-source-google-suggest)
5424 ;;; Yahoo suggestions
5426 (defun anything-c-yahoo-suggest-fetch (input)
5427 "Fetch Yahoo suggestions for INPUT from XML buffer.
5428 Return an alist with elements like (data . number_results)."
5429 (let ((request (concat anything-c-yahoo-suggest-url
5430 (url-hexify-string input))))
5431 (flet ((fetch ()
5432 (loop
5433 with result-alist = (xml-get-children
5434 (car (xml-parse-region (point-min) (point-max)))
5435 'Result)
5436 for i in result-alist
5437 collect (caddr i))))
5438 (with-current-buffer
5439 (url-retrieve-synchronously request)
5440 (fetch)))))
5442 (defun anything-c-yahoo-suggest-set-candidates ()
5443 "Set candidates with Yahoo results found."
5444 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
5445 (or suggestions
5446 (append
5447 suggestions
5448 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
5449 anything-input))))))
5451 (defun anything-c-yahoo-suggest-action (candidate)
5452 "Default action to jump to a Yahoo suggested candidate."
5453 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
5454 (url-hexify-string candidate))))
5456 (defvar anything-c-source-yahoo-suggest
5457 '((name . "Yahoo Suggest")
5458 (candidates . anything-c-yahoo-suggest-set-candidates)
5459 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
5460 (volatile)
5461 (requires-pattern . 3)
5462 (delayed)))
5464 ;; (anything 'anything-c-source-yahoo-suggest)
5466 ;;; Surfraw
5467 ;;; Need external program surfraw.
5468 ;;; http://surfraw.alioth.debian.org/
5469 ;; user variables
5470 (require 'browse-url)
5471 (defvar w3m-command nil)
5472 (defvar anything-c-home-url "http://www.google.fr"
5473 "*Default url to use as home url.")
5475 (defvar anything-browse-url-default-browser-alist
5476 `((,w3m-command . w3m-browse-url)
5477 (,browse-url-firefox-program . browse-url-firefox)
5478 (,browse-url-kde-program . browse-url-kde)
5479 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
5480 (,browse-url-mozilla-program . browse-url-mozilla)
5481 (,browse-url-galeon-program . browse-url-galeon)
5482 (,browse-url-netscape-program . browse-url-netscape)
5483 (,browse-url-mosaic-program . browse-url-mosaic)
5484 (,browse-url-xterm-program . browse-url-text-xterm))
5485 "*Alist of (executable . function) to try to find a suitable url browser.")
5487 (defun anything-browse-url-default-browser (url &rest args)
5488 "Find a suitable browser and ask it to load URL."
5489 (let ((default-browser (loop
5490 for i in anything-browse-url-default-browser-alist
5491 when (and (car i) (executable-find (car i))) return (cdr i))))
5492 (if default-browser
5493 (apply default-browser url args)
5494 (error "No usable browser found"))))
5496 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
5497 "Default command to browse URL."
5498 (if browse-url-browser-function
5499 (browse-url url)
5500 (anything-browse-url-default-browser url)))
5502 (defun anything-c-build-elvi-list ()
5503 "Return list of all engines and descriptions handled by surfraw."
5504 (cdr
5505 (with-temp-buffer
5506 (call-process "surfraw" nil t nil
5507 "-elvi")
5508 (split-string (buffer-string) "\n"))))
5510 (defvar anything-surfraw-engines-history nil)
5511 ;;;###autoload
5512 (defun anything-surfraw (pattern engine)
5513 "Preconfigured `anything' to search PATTERN with search ENGINE."
5514 (interactive (list (read-string "SearchFor: ")
5515 (anything-comp-read
5516 "Engine: "
5517 (anything-c-build-elvi-list)
5518 :must-match t
5519 :name "Surfraw Search Engines"
5520 :history anything-surfraw-engines-history)))
5521 (let* ((engine-nodesc (car (split-string engine)))
5522 (url (with-temp-buffer
5523 (apply 'call-process "surfraw" nil t nil
5524 (list engine-nodesc "-p" pattern))
5525 (replace-regexp-in-string
5526 "\n" "" (buffer-string)))))
5527 (if (string= engine-nodesc "W")
5528 (anything-c-browse-url)
5529 (anything-c-browse-url url)
5530 (setq anything-surfraw-engines-history
5531 (cons engine (delete engine anything-surfraw-engines-history))))))
5533 ;;; Emms
5535 (defun anything-emms-stream-edit-bookmark (elm)
5536 "Change the information of current emms-stream bookmark from anything."
5537 (let* ((cur-buf anything-current-buffer)
5538 (bookmark (assoc elm emms-stream-list))
5539 (name (read-from-minibuffer "Description: "
5540 (nth 0 bookmark)))
5541 (url (read-from-minibuffer "URL: "
5542 (nth 1 bookmark)))
5543 (fd (read-from-minibuffer "Feed Descriptor: "
5544 (int-to-string (nth 2 bookmark))))
5545 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
5546 (format "%s" (car (last bookmark))))))
5547 (save-excursion
5548 (emms-streams)
5549 (when (re-search-forward (concat "^" name) nil t)
5550 (beginning-of-line)
5551 (emms-stream-delete-bookmark)
5552 (emms-stream-add-bookmark name url (string-to-number fd) type)
5553 (emms-stream-save-bookmarks-file)
5554 (emms-stream-quit)
5555 (switch-to-buffer cur-buf)))))
5557 (defun anything-emms-stream-delete-bookmark (elm)
5558 "Delete an emms-stream bookmark from anything."
5559 (let* ((cur-buf anything-current-buffer)
5560 (bookmark (assoc elm emms-stream-list))
5561 (name (nth 0 bookmark)))
5562 (save-excursion
5563 (emms-streams)
5564 (when (re-search-forward (concat "^" name) nil t)
5565 (beginning-of-line)
5566 (emms-stream-delete-bookmark)
5567 (emms-stream-save-bookmarks-file)
5568 (emms-stream-quit)
5569 (switch-to-buffer cur-buf)))))
5571 (defvar anything-c-source-emms-streams
5572 '((name . "Emms Streams")
5573 (init . (lambda ()
5574 (emms-stream-init)))
5575 (candidates . (lambda ()
5576 (mapcar 'car emms-stream-list)))
5577 (action . (("Play" . (lambda (elm)
5578 (let* ((stream (assoc elm emms-stream-list))
5579 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
5580 (url (second stream)))
5581 (funcall fn url))))
5582 ("Delete" . anything-emms-stream-delete-bookmark)
5583 ("Edit" . anything-emms-stream-edit-bookmark)))
5584 (filtered-candidate-transformer . anything-c-adaptive-sort)))
5585 ;; (anything 'anything-c-source-emms-streams)
5587 ;; Don't forget to set `emms-source-file-default-directory'
5588 (defvar anything-c-source-emms-dired
5589 '((name . "Music Directory")
5590 (candidates . (lambda ()
5591 (cddr (directory-files emms-source-file-default-directory))))
5592 (action .
5593 (("Play Directory" . (lambda (item)
5594 (emms-play-directory
5595 (expand-file-name
5596 item
5597 emms-source-file-default-directory))))
5598 ("Open dired in file's directory" . (lambda (item)
5599 (anything-c-open-dired
5600 (expand-file-name
5601 item
5602 emms-source-file-default-directory))))))
5603 (filtered-candidate-transformer . anything-c-adaptive-sort)))
5604 ;; (anything 'anything-c-source-emms-dired)
5606 (defface anything-emms-playlist
5607 '((t (:foreground "Springgreen4" :underline t)))
5608 "*Face used for tracks in current emms playlist."
5609 :group 'anything)
5611 (defun anything-c-emms-files-modifier (candidates source)
5612 (let ((current-playlist (with-current-emms-playlist
5613 (loop
5614 with cur-list = (emms-playlist-tracks-in-region
5615 (point-min) (point-max))
5616 for i in cur-list
5617 collect (assoc-default 'name i)))))
5618 (loop for i in candidates
5619 if (member (cdr i) current-playlist)
5620 collect (cons (propertize (car i)
5621 'face 'anything-emms-playlist)
5622 (cdr i)) into lis
5623 else collect i into lis
5624 finally return lis)))
5626 (defun anything-c-emms-play-current-playlist ()
5627 "Play current playlist."
5628 (with-current-emms-playlist
5629 (emms-playlist-first)
5630 (emms-playlist-mode-play-smart)))
5632 (defvar anything-c-source-emms-files
5633 '((name . "Emms files")
5634 (candidates . (lambda ()
5635 (loop for v being the hash-values in emms-cache-db
5636 for name = (assoc-default 'name v)
5637 for artist = (or (assoc-default 'info-artist v) "unknown")
5638 for genre = (or (assoc-default 'info-genre v) "unknown")
5639 for tracknum = (or (assoc-default 'info-tracknumber v) "unknown")
5640 for song = (or (assoc-default 'info-title v) "unknown")
5641 for info = (concat artist " - " genre " - " tracknum ": " song)
5642 unless (string-match "^http:" name) collect (cons info name))))
5643 (filtered-candidate-transformer . anything-c-emms-files-modifier)
5644 (action . (("Play file" . emms-play-file)
5645 ("Add to Playlist and play (C-u clear current)"
5646 . (lambda (candidate)
5647 (when anything-current-prefix-arg
5648 (emms-playlist-current-clear))
5649 (emms-playlist-new)
5650 (mapc 'emms-add-playlist-file (anything-marked-candidates))
5651 (unless emms-player-playing-p
5652 (anything-c-emms-play-current-playlist))))))))
5654 ;; (anything 'anything-c-source-emms-files)
5656 ;;; Jabber Contacts (jabber.el)
5657 (defun anything-c-jabber-online-contacts ()
5658 "List online Jabber contacts."
5659 (with-no-warnings
5660 (let (jids)
5661 (dolist (item (jabber-concat-rosters) jids)
5662 (when (get item 'connected)
5663 (push (if (get item 'name)
5664 (cons (get item 'name) item)
5665 (cons (symbol-name item) item)) jids))))))
5667 (defvar anything-c-source-jabber-contacts
5668 '((name . "Jabber Contacts")
5669 (init . (lambda () (require 'jabber)))
5670 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
5671 (action . (lambda (x)
5672 (jabber-chat-with
5673 (jabber-read-account)
5674 (symbol-name
5675 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
5676 ;; (anything 'anything-c-source-jabber-contacts)
5679 ;;; Call source.
5680 (defvar anything-source-select-buffer "*anything source select*")
5681 (defvar anything-c-source-call-source
5682 `((name . "Call anything source")
5683 (candidate-number-limit)
5684 (candidates . (lambda ()
5685 (loop for vname in (all-completions "anything-c-source-" obarray)
5686 for var = (intern vname)
5687 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
5688 if name collect (cons (format "%s `%s'"
5689 name (propertize vname 'face 'font-lock-variable-name-face))
5690 var))))
5691 (action . (("Invoke anything with selected source" .
5692 (lambda (candidate)
5693 (setq anything-candidate-number-limit 9999)
5694 (anything candidate nil nil nil nil
5695 anything-source-select-buffer)))
5696 ("Describe variable" . describe-variable)
5697 ("Find variable" . find-variable)))
5698 (persistent-action . describe-variable)
5699 (persistent-help . "Show description of this source")))
5700 ;; (anything 'anything-c-source-call-source)
5702 ;;;###autoload
5703 (defun anything-call-source ()
5704 "Preconfigured `anything' to call anything source."
5705 (interactive)
5706 (anything 'anything-c-source-call-source nil nil nil nil
5707 anything-source-select-buffer))
5709 (defun anything-call-source-from-anything ()
5710 "Call anything source within `anything' session."
5711 (interactive)
5712 (setq anything-input-idle-delay 0)
5713 (anything-set-sources '(anything-c-source-call-source)))
5715 ;;; Execute Preconfigured anything.
5716 (defvar anything-c-source-anything-commands
5717 '((name . "Preconfigured Anything")
5718 (candidates . anything-c-anything-commands-candidates)
5719 (type . command)
5720 (candidate-number-limit)))
5721 ;; (anything 'anything-c-source-anything-commands)
5723 (defun anything-c-anything-commands-candidates ()
5724 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
5725 collect (cons (if (where-is-internal cmd nil t)
5726 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
5727 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
5728 cmd)))
5730 ;;;###autoload
5731 (defun anything-execute-anything-command ()
5732 "Preconfigured `anything' to execute preconfigured `anything'."
5733 (interactive)
5734 (anything-other-buffer 'anything-c-source-anything-commands
5735 "*anything commands*"))
5737 ;; Occur
5738 (defun anything-c-occur-init ()
5739 (anything-candidate-buffer anything-current-buffer))
5741 (defun anything-c-occur-get-line (s e)
5742 (format "%7d:%s" (line-number-at-pos (1- s)) (buffer-substring s e)))
5744 (defvar anything-c-source-occur
5745 '((name . "Occur")
5746 (init . anything-c-occur-init)
5747 (candidates-in-buffer)
5748 (migemo)
5749 (get-line . anything-c-occur-get-line)
5750 (type . line)
5751 (recenter)
5752 (requires-pattern . 1)
5753 (delayed)
5754 (volatile)))
5755 ;; (anything 'anything-c-source-occur)
5757 ;;; Anything browse code.
5758 (defun anything-c-browse-code-get-line (beg end)
5759 "Select line if it match the regexp corresponding to current `major-mode'.
5760 Line is parsed for BEG position to END position."
5761 (let ((str-line (buffer-substring beg end))
5762 (regexp (assoc-default major-mode
5763 anything-c-browse-code-regexp-alist))
5764 (num-line (if (string= anything-pattern "") beg (1- beg))))
5765 (when (and regexp (string-match regexp str-line))
5766 (format "%4d:%s" (line-number-at-pos num-line) str-line))))
5769 (defvar anything-c-source-browse-code
5770 '((name . "Browse code")
5771 (init . (lambda ()
5772 (anything-candidate-buffer anything-current-buffer)
5773 (with-current-buffer anything-current-buffer
5774 (jit-lock-fontify-now))))
5775 (candidates-in-buffer)
5776 (get-line . anything-c-browse-code-get-line)
5777 (type . line)
5778 (recenter)))
5780 ;; Do many actions for input
5781 (defvar anything-c-source-create
5782 '((name . "Create")
5783 (dummy)
5784 (action)
5785 (action-transformer . anything-create--actions))
5786 "Do many create actions from `anything-pattern'.
5787 See also `anything-create--actions'.")
5788 ;; (anything 'anything-c-source-create)
5790 (defun anything-create-from-anything ()
5791 "Run `anything-create' from `anything' as a fallback."
5792 (interactive)
5793 (anything-run-after-quit 'anything-create nil anything-pattern))
5795 ;;;###autoload
5796 (defun anything-create (&optional string initial-input)
5797 "Preconfigured `anything' to do many create actions from STRING.
5798 See also `anything-create--actions'."
5799 (interactive)
5800 (setq string (or string (read-string "Create Anything: " initial-input)))
5801 (anything '(((name . "Anything Create")
5802 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
5803 (candidates . anything-create--actions)
5804 (candidate-number-limit)
5805 (action . (lambda (func) (funcall func string)))))))
5807 (defun anything-create--actions (&rest ignored)
5808 "Default actions for `anything-create' / `anything-c-source-create'."
5809 (remove-if-not
5810 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
5811 (append anything-create--actions-private
5812 '(("find-file" . find-file)
5813 ("find-file other window" . find-file-other-window)
5814 ("New buffer" . switch-to-buffer)
5815 ("New buffer other window" . switch-to-buffer-other-window)
5816 ("Bookmark Set" . bookmark-set)
5817 ("Set Register" .
5818 (lambda (x) (set-register (read-char "Register: ") x)))
5819 ("Insert Linkd star" . linkd-insert-star)
5820 ("Insert Linkd Tag" . linkd-insert-tag)
5821 ("Insert Linkd Link" . linkd-insert-link)
5822 ("Insert Linkd Lisp" . linkd-insert-lisp)
5823 ("Insert Linkd Wiki" . linkd-insert-wiki)
5824 ("Google Search" . google)))))
5826 ;; Minibuffer History
5827 (defvar anything-c-source-minibuffer-history
5828 '((name . "Minibuffer History")
5829 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
5830 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
5831 (if (consp (car history))
5832 (mapcar 'prin1-to-string history)
5833 history))))
5834 (migemo)
5835 (action . insert)))
5836 ;; (anything 'anything-c-source-minibuffer-history)
5838 ;; elscreen
5839 (defvar anything-c-source-elscreen
5840 '((name . "Elscreen")
5841 (candidates . (lambda ()
5842 (if (cdr (elscreen-get-screen-to-name-alist))
5843 (sort
5844 (loop for sname in (elscreen-get-screen-to-name-alist)
5845 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
5846 finally (return lst))
5847 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
5848 (action . (("Change Screen".
5849 (lambda (candidate)
5850 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
5851 ("Kill Screen(s)".
5852 (lambda (candidate)
5853 (dolist (i (anything-marked-candidates))
5854 (elscreen-goto (- (aref i 1) (aref "0" 0)))
5855 (elscreen-kill))))
5856 ("Only Screen".
5857 (lambda (candidate)
5858 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
5859 (elscreen-kill-others)))))))
5860 ;; (anything 'anything-c-source-elscreen)
5862 ;;;; <System>
5864 ;;; Top (process)
5865 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
5866 "Top command (batch mode). %s is replaced with `frame-width'.")
5867 (defvar anything-c-source-top
5868 '((name . "Top (Press C-c C-u to refresh)")
5869 (init . anything-c-top-init)
5870 (candidates-in-buffer)
5871 (display-to-real . anything-c-top-display-to-real)
5872 (update . anything-c-top-update)
5873 (persistent-action . anything-c-top-sh-persistent-action)
5874 (persistent-help . "SIGTERM")
5875 (action
5876 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
5877 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
5878 ("Copy PID" . (lambda (pid) (kill-new pid))))))
5879 ;; (anything 'anything-c-source-top)
5881 (defun anything-c-top-sh (cmd)
5882 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
5884 (defun anything-c-top-sh-persistent-action (pid)
5885 (delete-other-windows)
5886 (anything-c-top-sh (format "kill -TERM %s" pid))
5887 (anything-force-update))
5889 (defun anything-c-top-init ()
5890 (with-current-buffer (anything-candidate-buffer 'global)
5891 (call-process-shell-command
5892 (format anything-c-top-command
5893 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
5894 nil (current-buffer))))
5896 (defun anything-c-top-display-to-real (line)
5897 (car (split-string line)))
5899 (defun anything-c-top-update ()
5900 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
5901 (anything-c-top-init)))
5903 ;;;###autoload
5904 (defun anything-top ()
5905 "Preconfigured `anything' for top command."
5906 (interactive)
5907 (let ((anything-samewindow t)
5908 (anything-enable-shortcuts)
5909 (anything-display-function 'anything-default-display-buffer)
5910 (anything-candidate-number-limit 9999))
5911 (save-window-excursion
5912 (delete-other-windows)
5913 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
5915 ;;; Timers
5916 (defvar anything-c-source-absolute-time-timers
5917 '((name . "Absolute Time Timers")
5918 (candidates . timer-list)
5919 (type . timer)))
5920 ;; (anything 'anything-c-source-absolute-time-timers)
5922 (defvar anything-c-source-idle-time-timers
5923 '((name . "Idle Time Timers")
5924 (candidates . timer-idle-list)
5925 (type . timer)))
5926 ;; (anything 'anything-c-source-idle-time-timers)
5928 (defun anything-c-timer-real-to-display (timer)
5929 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
5930 (append timer nil) ;use `append' to convert vector->list
5931 (format "%s repeat=%5S %s(%s)"
5932 (let ((time (list t1 t2 t3)))
5933 (if idle-delay
5934 (format-time-string "idle-for=%5s" time)
5935 (format-time-string "%m/%d %T" time)))
5936 repeat-delay
5937 func
5938 (mapconcat 'prin1-to-string args " "))))
5940 ;;; X RandR resolution change
5941 ;;; FIXME I do not care multi-display.
5942 (defvar anything-c-xrandr-output "VGA")
5943 (defvar anything-c-xrandr-screen "0")
5944 (defvar anything-c-source-xrandr-change-resolution
5945 '((name . "Change Resolution")
5946 (candidates
5947 . (lambda ()
5948 (with-temp-buffer
5949 (call-process "xrandr" nil (current-buffer) nil
5950 "--screen" anything-c-xrandr-screen "-q")
5951 (goto-char 1)
5952 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
5953 collect (match-string 1)))))
5954 (action
5955 ("Change Resolution" . (lambda (mode)
5956 (call-process "xrandr" nil nil nil
5957 "--screen" anything-c-xrandr-screen
5958 "--output" anything-c-xrandr-output
5959 "--mode" mode))))))
5960 ;; (anything 'anything-c-source-xrandr-change-resolution)
5962 ;;; Xfont selection
5963 (defun anything-c-persistent-xfont-action (elm)
5964 "Show current font temporarily"
5965 (let ((current-font (cdr (assoc 'font (frame-parameters))))
5966 (default-font elm))
5967 (unwind-protect
5968 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
5969 (set-frame-font current-font))))
5971 (defvar anything-c-xfonts-cache nil)
5972 (defvar anything-c-source-xfonts
5973 '((name . "X Fonts")
5974 (init . (lambda ()
5975 (unless anything-c-xfonts-cache
5976 (setq anything-c-xfonts-cache
5977 (x-list-fonts "*")))))
5978 (candidates . anything-c-xfonts-cache)
5979 (action . (("Copy to kill ring" . (lambda (elm)
5980 (kill-new elm)))
5981 ("Set Font" . (lambda (elm)
5982 (kill-new elm)
5983 (set-frame-font elm 'keep-size)
5984 (message "New font have been copied to kill ring")))))
5985 (persistent-action . anything-c-persistent-xfont-action)
5986 (persistent-help . "Switch to this font temporarily")))
5988 ;;;###autoload
5989 (defun anything-select-xfont ()
5990 "Preconfigured `anything' to select Xfont."
5991 (interactive)
5992 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
5994 ;; (anything 'anything-c-source-xfonts)
5996 ;;; World time
5998 (defvar anything-c-source-time-world
5999 '((name . "Time World List")
6000 (init . (lambda ()
6001 (let ((anything-buffer (anything-candidate-buffer 'global)))
6002 (with-current-buffer anything-buffer
6003 (display-time-world-display display-time-world-list)))))
6004 (candidates-in-buffer)))
6006 ;;;###autoload
6007 (defun anything-world-time ()
6008 "Preconfigured `anything' to show world time."
6009 (interactive)
6010 (anything-other-buffer 'anything-c-source-time-world "*anything world time*"))
6012 ;;; Source for Debian/Ubuntu users
6013 (defvar anything-c-source-apt
6014 '((name . "APT")
6015 (init . anything-c-apt-init)
6016 (candidates-in-buffer)
6017 (candidate-transformer anything-c-apt-candidate-transformer)
6018 (display-to-real . anything-c-apt-display-to-real)
6019 (candidate-number-limit . 9999)
6020 (action
6021 ("Show package description" . anything-c-apt-cache-show)
6022 ("Install package" . anything-c-apt-install)
6023 ("Remove package" . anything-c-apt-uninstall)
6024 ("Purge package" . anything-c-apt-purge))
6025 (persistent-action . anything-c-apt-persistent-action)
6026 (persistent-help . "Show - C-u Refresh")))
6027 ;; (anything 'anything-c-source-apt)
6029 (defvar anything-c-apt-query "emacs")
6030 (defvar anything-c-apt-search-command "apt-cache search '%s'")
6031 (defvar anything-c-apt-show-command "apt-cache show '%s'")
6032 (defvar anything-c-apt-installed-packages nil)
6034 (defface anything-apt-installed
6035 '((t (:foreground "green")))
6036 "*Face used for apt installed candidates."
6037 :group 'anything)
6039 (defun anything-c-apt-refresh ()
6040 "Refresh installed candidates list."
6041 (setq anything-c-apt-installed-packages nil)
6042 (anything-force-update))
6044 (defun anything-c-apt-persistent-action (candidate)
6045 "Persistent action for APT source."
6046 (if current-prefix-arg
6047 (anything-c-apt-refresh)
6048 (anything-c-apt-cache-show candidate)))
6050 ;;;###autoload
6051 (defun anything-apt (query)
6052 "Preconfigured `anything' : frontend of APT package manager."
6053 (interactive "sAPT search: ")
6054 (let ((anything-c-apt-query query))
6055 (anything 'anything-c-source-apt)))
6057 (defun anything-c-apt-candidate-transformer (candidates)
6058 "Show installed candidates in a different color."
6059 (loop
6060 with all
6061 for cand in candidates
6062 for name = (anything-c-apt-display-to-real cand)
6063 if (member name anything-c-apt-installed-packages)
6064 collect (propertize cand 'face 'anything-apt-installed) into all
6065 else collect cand into all finally return all))
6067 (defun anything-c-apt-init ()
6068 "Initialize list of debian packages."
6069 (unless anything-c-apt-installed-packages
6070 (message "Updating installed candidate list...")
6071 (setq anything-c-apt-installed-packages
6072 (with-temp-buffer
6073 (call-process-shell-command "dpkg --get-selections"
6074 nil (current-buffer))
6075 (loop for i in (split-string (buffer-string) "\n" t)
6076 collect (car (split-string i))))))
6077 (with-current-buffer
6078 (anything-candidate-buffer
6079 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
6080 (erase-buffer)
6081 (call-process-shell-command
6082 (format anything-c-apt-search-command anything-c-apt-query)
6083 nil (current-buffer)))
6084 (message "Updating installed candidate list...done"))
6086 (defun anything-c-apt-display-to-real (line)
6087 "Return only name of a debian package.
6088 LINE is displayed like:
6089 package name - description."
6090 (car (split-string line " - ")))
6092 ;;;###autoload
6093 (defun anything-c-shell-command-if-needed (command)
6094 (interactive "sShell command: ")
6095 (if (get-buffer command) ; if the buffer already exists
6096 (switch-to-buffer command) ; then just switch to it
6097 (switch-to-buffer command) ; otherwise create it
6098 (insert (shell-command-to-string command))))
6100 (defun anything-c-apt-cache-show (package)
6101 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
6103 (defun anything-c-apt-install (package)
6104 (anything-c-apt-install1 package :action 'install))
6106 (defun anything-c-apt-uninstall (package)
6107 (anything-c-apt-install1 package :action 'uninstall))
6109 (defun anything-c-apt-purge (package)
6110 (anything-c-apt-install1 package :action 'purge))
6112 (defun* anything-c-apt-install1 (candidate &key action)
6113 (ansi-term (getenv "SHELL") "anything apt")
6114 (term-line-mode)
6115 (let ((command (case action
6116 ('install "sudo apt-get install '%s'")
6117 ('uninstall "sudo apt-get remove '%s'")
6118 ('purge "sudo apt-get purge '%s'")
6119 (t (error "Unknow action"))))
6120 (beg (point)) end)
6121 (goto-char (point-max))
6122 (insert (format command candidate))
6123 (setq end (point))
6124 (if (y-or-n-p (format "%s package" (symbol-name action)))
6125 (progn
6126 (setq anything-c-external-commands-list nil)
6127 (setq anything-c-apt-installed-packages nil)
6128 (term-char-mode) (term-send-input))
6129 (delete-region beg end) (term-send-eof) (kill-buffer))))
6131 ;; (anything-c-apt-install "jed")
6133 ;;; Sources for gentoo users
6134 (defvar anything-c-gentoo-use-flags nil)
6135 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
6136 (defvar anything-c-cache-gentoo nil)
6137 (defvar anything-c-cache-world nil)
6138 (defvar anything-c-source-gentoo
6139 '((name . "Portage sources")
6140 (init . (lambda ()
6141 (get-buffer-create anything-c-gentoo-buffer)
6142 (unless anything-c-cache-gentoo
6143 (anything-c-gentoo-setup-cache))
6144 (unless anything-c-cache-world
6145 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
6146 (anything-c-gentoo-init-list)))
6147 (candidates-in-buffer)
6148 (match . identity)
6149 (candidate-transformer anything-c-highlight-world)
6150 (action . (("Show package" . (lambda (elm)
6151 (anything-c-gentoo-eshell-action elm "eix")))
6152 ("Show history" . (lambda (elm)
6153 (if (member elm anything-c-cache-world)
6154 (anything-c-gentoo-eshell-action elm "genlop -qe")
6155 (message "No infos on packages not yet installed"))))
6156 ("Copy in kill-ring" . kill-new)
6157 ("insert at point" . insert)
6158 ("Browse HomePage" . (lambda (elm)
6159 (let ((urls (anything-c-gentoo-get-url elm)))
6160 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
6161 ("Show extra infos" . (lambda (elm)
6162 (if (member elm anything-c-cache-world)
6163 (anything-c-gentoo-eshell-action elm "genlop -qi")
6164 (message "No infos on packages not yet installed"))))
6165 ("Show use flags" . (lambda (elm)
6166 (anything-c-gentoo-default-action elm "equery" "-C" "u")
6167 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
6168 (font-lock-mode 1)))
6169 ("Run emerge pretend" . (lambda (elm)
6170 (anything-c-gentoo-eshell-action elm "emerge -p")))
6171 ("Emerge" . (lambda (elm)
6172 (anything-gentoo-install elm :action 'install)))
6173 ("Unmerge" . (lambda (elm)
6174 (anything-gentoo-install elm :action 'uninstall)))
6175 ("Show dependencies" . (lambda (elm)
6176 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
6177 ("Show related files" . (lambda (elm)
6178 (anything-c-gentoo-default-action elm "equery" "files")))
6179 ("Refresh" . (lambda (elm)
6180 (anything-c-gentoo-setup-cache)
6181 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
6183 ;; (anything 'anything-c-source-gentoo)
6185 (defun* anything-gentoo-install (candidate &key action)
6186 (setq anything-c-external-commands-list nil)
6187 (ansi-term (getenv "SHELL") "Gentoo emerge")
6188 (term-line-mode)
6189 (let ((command (case action
6190 ('install "sudo emerge -av ")
6191 ('uninstall "sudo emerge -avC ")
6192 (t (error "Unknow action"))))
6193 (elms (mapconcat 'identity (anything-marked-candidates) " "))
6194 (beg (point)) end)
6195 (goto-char (point-max))
6196 (insert (concat command elms))
6197 (setq end (point))
6198 (term-char-mode) (term-send-input)))
6200 (defun anything-c-gentoo-default-action (elm command &rest args)
6201 "Gentoo default action that use `anything-c-gentoo-buffer'."
6202 (if (member elm anything-c-cache-world)
6203 (progn
6204 (switch-to-buffer anything-c-gentoo-buffer)
6205 (erase-buffer)
6206 (let ((com-list (append args (list elm))))
6207 (apply #'call-process command nil t nil
6208 com-list)))
6209 (message "No infos on packages not yet installed")))
6211 (defvar anything-c-source-use-flags
6212 '((name . "Use Flags")
6213 (init . (lambda ()
6214 (unless anything-c-gentoo-use-flags
6215 (anything-c-gentoo-setup-use-flags-cache))
6216 (anything-c-gentoo-get-use)))
6217 (candidates-in-buffer)
6218 (match . identity)
6219 (candidate-transformer anything-c-highlight-local-use)
6220 (action . (("Description"
6221 . (lambda (elm)
6222 (switch-to-buffer anything-c-gentoo-buffer)
6223 (erase-buffer)
6224 (apply #'call-process "euse" nil t nil
6225 `("-i"
6226 ,elm))
6227 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
6228 (font-lock-mode 1)))
6229 ("Enable"
6230 . (lambda (elm)
6231 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
6232 ("Disable"
6233 . (lambda (elm)
6234 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
6235 ("Remove"
6236 . (lambda (elm)
6237 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
6238 ("Show which dep use this flag"
6239 . (lambda (elm)
6240 (switch-to-buffer anything-c-gentoo-buffer)
6241 (erase-buffer)
6242 (apply #'call-process "equery" nil t nil
6243 `("-C"
6245 ,elm))))))))
6248 ;; (anything 'anything-c-source-use-flags)
6250 (defun anything-c-gentoo-init-list ()
6251 "Initialize buffer with all packages in Portage."
6252 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
6253 (buf (anything-candidate-buffer 'portage-buf)))
6254 (with-current-buffer buf
6255 (dolist (i anything-c-cache-gentoo)
6256 (insert (concat i "\n"))))))
6258 (defun anything-c-gentoo-setup-cache ()
6259 "Set up `anything-c-cache-gentoo'"
6260 (setq anything-c-cache-gentoo
6261 (split-string (with-temp-buffer
6262 (call-process "eix" nil t nil
6263 "--only-names")
6264 (buffer-string)))))
6266 (defun anything-c-gentoo-eshell-action (elm command)
6267 (when (get-buffer "*EShell Command Output*")
6268 (kill-buffer "*EShell Command Output*"))
6269 (message "Wait searching...")
6270 (let ((buf-fname (buffer-file-name anything-current-buffer)))
6271 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
6272 (progn
6273 (save-window-excursion
6274 (pop-to-buffer "*scratch*")
6275 (eshell-command (format "%s %s" command elm)))
6276 (pop-to-buffer "*EShell Command Output*"))
6277 (eshell-command (format "%s %s" command elm)))))
6279 (defun anything-c-gentoo-get-use ()
6280 "Initialize buffer with all use flags."
6281 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
6282 (buf (anything-candidate-buffer 'use-buf)))
6283 (with-current-buffer buf
6284 (dolist (i anything-c-gentoo-use-flags)
6285 (insert (concat i "\n"))))))
6288 (defun anything-c-gentoo-setup-use-flags-cache ()
6289 "Setup `anything-c-gentoo-use-flags'"
6290 (setq anything-c-gentoo-use-flags
6291 (split-string (with-temp-buffer
6292 (call-process "eix" nil t nil
6293 "--print-all-useflags")
6294 (buffer-string)))))
6296 (defun anything-c-gentoo-get-url (elm)
6297 "Return a list of urls from eix output."
6298 (loop
6299 with url-list = (split-string
6300 (with-temp-buffer
6301 (call-process "eix" nil t nil
6302 elm "--format" "<homepage>\n")
6303 (buffer-string)))
6304 with all
6305 for i in url-list
6306 when (and (string-match "^http://.*" i)
6307 (not (member i all)))
6308 collect i into all
6309 finally return all))
6311 (defun anything-c-gentoo-get-world ()
6312 "Return list of all installed package on your system."
6313 (split-string (with-temp-buffer
6314 (call-process "qlist" nil t nil
6315 "-I")
6316 (buffer-string))))
6318 (defun anything-c-gentoo-get-local-use ()
6319 (split-string (with-temp-buffer
6320 (call-process "portageq" nil t nil
6321 "envvar"
6322 "USE")
6323 (buffer-string))))
6325 (defface anything-gentoo-match-face '((t (:foreground "red")))
6326 "Face for anything-gentoo installed packages."
6327 :group 'traverse-faces)
6329 (defun anything-c-highlight-world (eix)
6330 "Highlight all installed package."
6331 (loop for i in eix
6332 if (member i anything-c-cache-world)
6333 collect (propertize i 'face 'anything-gentoo-match-face)
6334 else
6335 collect i))
6337 (defun anything-c-highlight-local-use (use-flags)
6338 (let ((local-uses (anything-c-gentoo-get-local-use)))
6339 (loop for i in use-flags
6340 if (member i local-uses)
6341 collect (propertize i 'face 'anything-gentoo-match-face)
6342 else
6343 collect i)))
6345 (defvar anything-c-source-emacs-process
6346 '((name . "Emacs Process")
6347 (candidates . (lambda () (mapcar #'process-name (process-list))))
6348 (persistent-action . (lambda (elm)
6349 (delete-process (get-process elm))
6350 (anything-delete-current-selection)))
6351 (persistent-help . "Kill Process")
6352 (action ("Kill Process" . (lambda (elm)
6353 (delete-process (get-process elm)))))))
6355 ;; (anything 'anything-c-source-emacs-process)
6357 ;; Run Externals commands within Emacs
6358 (defmacro* anything-comp-hash-get-items (hash-table &key test)
6359 "Get the list of all keys/values of hash-table."
6360 `(let ((li-items ()))
6361 (maphash #'(lambda (x y)
6362 (if ,test
6363 (when (funcall ,test y)
6364 (push (list x y) li-items))
6365 (push (list x y) li-items)))
6366 ,hash-table)
6367 li-items))
6369 (defun anything-comp-read-get-candidates (collection &optional test sort-fn)
6370 "Convert COLLECTION to list removing elements that don't match TEST.
6371 SORT-FN is a predicate to sort COLLECTION.
6372 If collection is an `obarray', a TEST is needed. See `obarray'."
6373 (let ((cands
6374 (cond ((and (listp collection) test)
6375 (loop for i in collection when (funcall test i) collect i))
6376 ((and (eq collection obarray) test)
6377 (loop for s being the symbols of collection
6378 when (funcall test s) collect s))
6379 ((and (vectorp collection) test)
6380 (loop for i across collection when (funcall test i) collect i))
6381 ((vectorp collection)
6382 (loop for i across collection collect i))
6383 ((and (hash-table-p collection) test)
6384 (anything-comp-hash-get-items collection :test test))
6385 ((hash-table-p collection)
6386 (anything-comp-hash-get-items collection))
6387 (t collection))))
6388 (if sort-fn (sort cands sort-fn) cands)))
6390 (defun anything-cr-default-transformer (candidates source)
6391 "Default filter candidate function for `anything-comp-read'.
6392 Do nothing, just return candidate list unmodified."
6393 candidates)
6395 (defun* anything-comp-read (prompt collection
6396 &key
6397 test
6398 initial-input
6399 (buffer "*Anything Completions*")
6400 must-match
6401 (requires-pattern 0)
6402 (history nil)
6403 (persistent-action nil)
6404 (persistent-help "DoNothing")
6405 (name "Anything Completions")
6406 sort
6407 (fc-transformer 'anything-cr-default-transformer)
6408 (marked-candidates nil))
6409 "Anything `completing-read' emulation.
6410 PROMPT is the prompt name to use.
6411 COLLECTION can be a list, vector, obarray or hash-table.
6412 Keys:
6414 TEST: A predicate called with one arg i.e candidate.
6415 INITIAL-INPUT: Same as initial-input arg in `anything'.
6416 BUFFER: Name of anything-buffer.
6417 MUST-MATCH: Candidate selected must be one of COLLECTION.
6418 REQUIRES-PATTERN: Same as anything attribute, default is 0.
6419 HISTORY: A list containing specific history, default is nil.
6420 When it is non--nil, all elements of HISTORY are displayed in
6421 anything-buffer before COLLECTION.
6422 PERSISTENT-ACTION: A function called with one arg i.e candidate.
6423 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
6424 NAME: The name related to this local source.
6425 SORT: A predicate to give to `sort' e.g `string-lessp'.
6426 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
6427 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
6429 Any prefix args passed during `anything-comp-read' invocation will be recorded
6430 in `anything-current-prefix-arg', otherwise if prefix args where given before
6431 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
6432 That's mean you can pass prefix arg before or after calling
6433 a command that use `anything-comp-read'."
6434 (when (get-buffer anything-action-buffer)
6435 (kill-buffer anything-action-buffer))
6436 (flet ((action-fn (candidate)
6437 (if marked-candidates
6438 (anything-marked-candidates)
6439 (identity candidate))))
6440 (or (anything
6441 :sources
6442 `(((name . ,(format "%s History" name))
6443 (candidates . (lambda ()
6444 (anything-comp-read-get-candidates history)))
6445 (volatile)
6446 (persistent-action . ,persistent-action)
6447 (persistent-help . ,persistent-help)
6448 (action . ,'action-fn))
6449 ((name . ,name)
6450 (candidates
6451 . (lambda ()
6452 (let ((cands (anything-comp-read-get-candidates
6453 collection test sort)))
6454 (if (or must-match (string= anything-pattern ""))
6455 cands (append (list anything-pattern) cands)))))
6456 (filtered-candidate-transformer ,fc-transformer)
6457 (requires-pattern . ,requires-pattern)
6458 (persistent-action . ,persistent-action)
6459 (persistent-help . ,persistent-help)
6460 (volatile)
6461 (action . ,'action-fn)))
6462 :input initial-input
6463 :prompt prompt
6464 :resume 'noresume
6465 :buffer buffer)
6466 (keyboard-quit))))
6468 (defun anything-c-get-pid-from-process-name (process-name)
6469 "Get pid from running process PROCESS-NAME."
6470 (loop with process-list = (list-system-processes)
6471 for pid in process-list
6472 for process = (assoc-default 'comm (process-attributes pid))
6473 when (and process (string-match process-name process))
6474 return pid))
6477 (defun anything-run-or-raise (exe &optional file)
6478 "Generic command that run asynchronously EXE.
6479 If EXE is already running just jump to his window if `anything-raise-command'
6480 is non--nil.
6481 When FILE argument is provided run EXE with FILE.
6482 In this case EXE must be provided as \"EXE %s\"."
6483 (let ((real-com (car (split-string (replace-regexp-in-string "'%s'" "" exe)))))
6484 (if (or (get-process real-com)
6485 (anything-c-get-pid-from-process-name real-com))
6486 (if anything-raise-command
6487 (shell-command (format anything-raise-command real-com))
6488 (error "Error: %s is already running" real-com))
6489 (when (member real-com anything-c-external-commands-list)
6490 (message "Starting %s..." real-com)
6491 (if file
6492 (start-process-shell-command real-com nil (format exe file))
6493 (start-process-shell-command real-com nil real-com))
6494 (set-process-sentinel
6495 (get-process real-com)
6496 #'(lambda (process event)
6497 (when (and (string= event "finished\n")
6498 anything-raise-command)
6499 (shell-command (format anything-raise-command "emacs")))
6500 (message "%s process...Finished." process))))
6501 (setq anything-c-external-commands-list
6502 (cons real-com (delete real-com anything-c-external-commands-list))))))
6505 (defvar anything-external-command-history nil)
6506 ;;;###autoload
6507 (defun anything-c-run-external-command (program)
6508 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
6509 If program is already running exit with error.
6510 You can set your own list of commands with
6511 `anything-c-external-commands-list'."
6512 (interactive (list
6513 (anything-comp-read
6514 "RunProgram: "
6515 (anything-c-external-commands-list-1 'sort)
6516 :must-match t
6517 :name "External Commands"
6518 :history anything-external-command-history)))
6519 (anything-run-or-raise program)
6520 (setq anything-external-command-history
6521 (cons program (delete program
6522 (loop for i in anything-external-command-history
6523 when (executable-find i) collect i)))))
6525 (defsubst* anything-c-position (item seq &key (test 'eq))
6526 "A simple and faster replacement of CL `position'."
6527 (loop for i in seq for index from 0
6528 when (funcall test i item) return index))
6530 (defvar anything-c-source-ratpoison-commands
6531 '((name . "Ratpoison Commands")
6532 (init . anything-c-ratpoison-commands-init)
6533 (candidates-in-buffer)
6534 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
6535 (display-to-real . anything-c-ratpoison-commands-display-to-real)
6536 (candidate-number-limit)))
6537 ;; (anything 'anything-c-source-ratpoison-commands)
6539 (defun anything-c-ratpoison-commands-init ()
6540 (unless (anything-candidate-buffer)
6541 (with-current-buffer (anything-candidate-buffer 'global)
6542 ;; with ratpoison prefix key
6543 (save-excursion
6544 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
6545 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
6546 (replace-match "<ratpoison> \\1: \\2"))
6547 (goto-char (point-max))
6548 ;; direct binding
6549 (save-excursion
6550 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
6551 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
6552 (replace-match "\\1: \\2")))))
6554 (defun anything-c-ratpoison-commands-display-to-real (display)
6555 (and (string-match ": " display)
6556 (substring display (match-end 0))))
6558 (defun anything-c-ratpoison-commands-execute (candidate)
6559 (call-process "ratpoison" nil nil nil "-ic" candidate))
6561 ;;;###autoload
6562 (defun anything-ratpoison-commands ()
6563 "Preconfigured `anything' to execute ratpoison commands."
6564 (interactive)
6565 (anything-other-buffer 'anything-c-source-ratpoison-commands
6566 "*anything ratpoison commands*"))
6568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6569 ;;; Files
6570 (defvar anything-c-external-commands-list nil
6571 "A list of all external commands the user can execute. If this
6572 variable is not set by the user, it will be calculated
6573 automatically.")
6575 (defun anything-c-external-commands-list-1 (&optional sort)
6576 "Returns a list of all external commands the user can execute.
6577 If `anything-c-external-commands-list' is non-nil it will
6578 return its contents. Else it calculates all external commands
6579 and sets `anything-c-external-commands-list'."
6580 (if anything-c-external-commands-list
6581 anything-c-external-commands-list
6582 (setq anything-c-external-commands-list
6583 (loop
6584 with paths = (split-string (getenv "PATH") path-separator)
6585 with completions = ()
6586 for dir in paths
6587 when (and (file-exists-p dir) (file-accessible-directory-p dir))
6588 for lsdir = (loop for i in (directory-files dir t)
6589 for bn = (file-name-nondirectory i)
6590 when (and (not (member bn completions))
6591 (not (file-directory-p i))
6592 (file-executable-p i))
6593 collect bn)
6594 append lsdir into completions
6595 finally return (if sort (sort completions 'string-lessp) completions)))))
6598 (defun anything-c-file-buffers (filename)
6599 "Returns a list of buffer names corresponding to FILENAME."
6600 (let ((name (expand-file-name filename))
6601 (buf-list ()))
6602 (dolist (buf (buffer-list) buf-list)
6603 (let ((bfn (buffer-file-name buf)))
6604 (when (and bfn (string= name bfn))
6605 (push (buffer-name buf) buf-list))))))
6607 (defun anything-c-delete-file (file)
6608 "Delete the given file after querying the user.
6609 Ask to kill buffers associated with that file, too."
6610 (let ((buffers (anything-c-file-buffers file)))
6611 (dired-delete-file file 'dired-recursive-deletes)
6612 (when buffers
6613 (dolist (buf buffers)
6614 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
6615 (kill-buffer buf))))))
6617 (defun anything-get-mailcap-for-file (filename)
6618 "Get the command to use for FILENAME from mailcap files.
6619 The command is like <command %s> and is meant to use with `format'."
6620 (mailcap-parse-mailcaps)
6621 (let* ((ext (file-name-extension filename))
6622 (mime (when ext (mailcap-extension-to-mime ext))))
6623 (when mime (mailcap-mime-info mime))))
6625 (defun anything-get-default-program-for-file (filename)
6626 "Try to find a default program to open FILENAME.
6627 Try first in `anything-c-external-programs-associations' and then in mailcap file
6628 if nothing found return nil."
6629 (let* ((ext (file-name-extension filename))
6630 (def-prog (assoc-default ext anything-c-external-programs-associations)))
6631 (if (and def-prog (not (string= def-prog "")))
6632 (concat def-prog " %s")
6633 (anything-get-mailcap-for-file filename))))
6635 (defun anything-c-open-file-externally (file)
6636 "Open FILE with an external program.
6637 Try to guess which program to use with `anything-get-default-program-for-file'.
6638 If not found or a prefix arg is given query the user which tool to use."
6639 (let* ((fname (expand-file-name file))
6640 (collection (anything-c-external-commands-list-1 'sort))
6641 (def-prog (anything-get-default-program-for-file fname))
6642 (real-prog-name (or
6643 ;; No prefix arg, default program exists.
6644 (unless (or anything-current-prefix-arg (not def-prog))
6645 (replace-regexp-in-string " %s" "" def-prog))
6646 ;; Prefix arg or no default program.
6647 (anything-comp-read
6648 "Program: " collection
6649 :must-match t
6650 :name "Open file Externally"
6651 :history anything-external-command-history)))
6652 (program (concat real-prog-name " '%s'")))
6653 (unless (or def-prog ; Association exists, no need to record it.
6654 (not (file-exists-p fname))) ; Don't record non--filenames.
6655 (when
6656 (y-or-n-p
6657 (format
6658 "Do you want to make %s the default program for this kind of files? "
6659 real-prog-name))
6660 (push (cons (file-name-extension fname)
6661 (read-string
6662 "Program(Add args maybe and confirm): " real-prog-name))
6663 anything-c-external-programs-associations)
6664 (customize-save-variable 'anything-c-external-programs-associations
6665 anything-c-external-programs-associations)))
6666 (anything-run-or-raise program file)
6667 (setq anything-external-command-history
6668 (cons real-prog-name
6669 (delete real-prog-name
6670 (loop for i in anything-external-command-history
6671 when (executable-find i) collect i))))))
6674 ;;;###autoload
6675 (defun w32-shell-execute-open-file (file)
6676 (interactive "fOpen file:")
6677 (with-no-warnings
6678 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
6679 "/" "\\"
6680 (replace-regexp-in-string ; strip cygdrive paths
6681 "/cygdrive/\\(.\\)" "\\1:"
6682 file nil nil) nil t))))
6684 (defun anything-c-open-file-with-default-tool (file)
6685 "Open FILE with the default tool on this platform."
6686 (if (eq system-type 'windows-nt)
6687 (w32-shell-execute-open-file file)
6688 (start-process "anything-c-open-file-with-default-tool"
6690 (cond ((eq system-type 'gnu/linux)
6691 "xdg-open")
6692 ((or (eq system-type 'darwin) ;; Mac OS X
6693 (eq system-type 'macos)) ;; Mac OS 9
6694 "open"))
6695 file)))
6697 (defun anything-c-open-dired (file)
6698 "Opens a dired buffer in FILE's directory. If FILE is a
6699 directory, open this directory."
6700 (if (file-directory-p file)
6701 (dired file)
6702 (dired (file-name-directory file))
6703 (dired-goto-file file)))
6705 (defun anything-c-display-to-real-line (candidate)
6706 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
6707 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
6708 (error "Line number not found")))
6710 (defun anything-c-action-line-goto (lineno-and-content)
6711 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
6712 (append lineno-and-content
6713 (list (if (and (anything-attr-defined 'target-file)
6714 (not anything-in-persistent-action))
6715 'find-file-other-window
6716 'find-file)))))
6718 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
6719 (apply #'anything-goto-file-line
6720 (if (stringp file-line-content)
6721 ;; Case: filtered-candidate-transformer is skipped
6722 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
6723 file-line-content)))
6725 (require 'compile)
6726 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
6727 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
6729 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
6730 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
6731 (let ((filename (match-string 1 candidate))
6732 (lineno (match-string 2 candidate))
6733 (content (match-string 3 candidate)))
6734 (cons (format "%s:%s\n %s"
6735 (propertize filename 'face compilation-info-face)
6736 (propertize lineno 'face compilation-line-face)
6737 content)
6738 (list (expand-file-name
6739 filename
6740 (or (anything-interpret-value (anything-attr 'default-directory))
6741 (and (anything-candidate-buffer)
6742 (buffer-local-value
6743 'default-directory (anything-candidate-buffer)))))
6744 (string-to-number lineno) content)))))
6746 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
6747 (anything-aif (anything-attr 'before-jump-hook)
6748 (funcall it))
6749 (when file (funcall find-file-function file))
6750 (if (anything-attr-defined 'adjust)
6751 (anything-c-goto-line-with-adjustment lineno content)
6752 (anything-goto-line lineno))
6753 (unless (anything-attr-defined 'recenter)
6754 (set-window-start (get-buffer-window anything-current-buffer) (point)))
6755 (anything-aif (anything-attr 'after-jump-hook)
6756 (funcall it))
6757 (when anything-in-persistent-action
6758 (anything-match-line-color-current-line)))
6760 (defun anything-find-file-as-root (candidate)
6761 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
6763 (defun anything-find-many-files (ignore)
6764 (mapc 'find-file (anything-marked-candidates)))
6766 ;; borrowed from etags.el
6767 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
6768 (defun anything-c-goto-line-with-adjustment (line line-content)
6769 (let ((startpos)
6770 offset found pat)
6771 ;; This constant is 1/2 the initial search window.
6772 ;; There is no sense in making it too small,
6773 ;; since just going around the loop once probably
6774 ;; costs about as much as searching 2000 chars.
6775 (setq offset 1000
6776 found nil
6777 pat (concat (if (eq selective-display t)
6778 "\\(^\\|\^m\\) *" "^ *") ;allow indent
6779 (regexp-quote line-content)))
6780 ;; If no char pos was given, try the given line number.
6781 (setq startpos (progn (anything-goto-line line) (point)))
6782 (or startpos (setq startpos (point-min)))
6783 ;; First see if the tag is right at the specified location.
6784 (goto-char startpos)
6785 (setq found (looking-at pat))
6786 (while (and (not found)
6787 (progn
6788 (goto-char (- startpos offset))
6789 (not (bobp))))
6790 (setq found
6791 (re-search-forward pat (+ startpos offset) t)
6792 offset (* 3 offset))) ; expand search window
6793 (or found
6794 (re-search-forward pat nil t)
6795 (error "not found")))
6796 ;; Position point at the right place
6797 ;; if the search string matched an extra Ctrl-m at the beginning.
6798 (and (eq selective-display t)
6799 (looking-at "\^m")
6800 (forward-char 1))
6801 (beginning-of-line))
6803 (anything-document-attribute 'default-directory "type . file-line"
6804 "`default-directory' to interpret file.")
6805 (anything-document-attribute 'before-jump-hook "type . file-line / line"
6806 "Function to call before jumping to the target location.")
6807 (anything-document-attribute 'after-jump-hook "type . file-line / line"
6808 "Function to call after jumping to the target location.")
6809 (anything-document-attribute 'adjust "type . file-line"
6810 "Search around line matching line contents.")
6811 (anything-document-attribute 'recenter "type . file-line / line"
6812 "`recenter' after jumping.")
6813 (anything-document-attribute 'target-file "type . line"
6814 "Goto line of target-file.")
6816 ;;;###autoload
6817 (defun anything-c-call-interactively (cmd-or-name)
6818 "Execute CMD-OR-NAME as Emacs command.
6819 It is added to `extended-command-history'.
6820 `anything-current-prefix-arg' is used as the command's prefix argument."
6821 (setq extended-command-history
6822 (cons (anything-c-stringify cmd-or-name)
6823 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
6824 (let ((current-prefix-arg anything-current-prefix-arg)
6825 (cmd (anything-c-symbolify cmd-or-name)))
6826 (if (stringp (symbol-function cmd))
6827 (execute-kbd-macro (symbol-function cmd))
6828 (setq this-command cmd)
6829 (call-interactively cmd))))
6831 ;;;###autoload
6832 (defun anything-c-set-variable (var)
6833 "Set value to VAR interactively."
6834 (interactive)
6835 (let ((sym (anything-c-symbolify var)))
6836 (set sym (eval-minibuffer (format "Set %s: " var)
6837 (prin1-to-string (symbol-value sym))))))
6838 ;; (setq hh 12)
6839 ;; (anything-c-set-variable 'hh)
6841 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6842 (defvar anything-match-line-overlay-face nil)
6843 (defvar anything-match-line-overlay nil)
6845 (defun anything-match-line-color-current-line (&optional start end buf face rec)
6846 "Highlight and underline current position"
6847 (let ((args (list (or start (line-beginning-position))
6848 (or end (1+ (line-end-position)))
6849 buf)))
6850 (if (not anything-match-line-overlay)
6851 (setq anything-match-line-overlay (apply 'make-overlay args))
6852 (apply 'move-overlay anything-match-line-overlay args)))
6853 (overlay-put anything-match-line-overlay
6854 'face (or face anything-match-line-overlay-face))
6855 (when rec
6856 (goto-char start)
6857 (recenter)))
6859 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
6861 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
6862 "Face for source header in the anything buffer." :group 'anything)
6864 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
6866 (defun anything-match-line-cleanup ()
6867 (when anything-match-line-overlay
6868 (delete-overlay anything-match-line-overlay)
6869 (setq anything-match-line-overlay nil)))
6871 (defun anything-match-line-update ()
6872 (when anything-match-line-overlay
6873 (delete-overlay anything-match-line-overlay)
6874 (anything-match-line-color-current-line)))
6876 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
6877 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
6879 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6880 ;;; Files
6881 (defun anything-c-transform-file-load-el (actions candidate)
6882 "Add action to load the file CANDIDATE if it is an emacs lisp
6883 file. Else return ACTIONS unmodified."
6884 (if (member (file-name-extension candidate) '("el" "elc"))
6885 (append actions '(("Load Emacs Lisp File" . load-file)))
6886 actions))
6888 (defun anything-c-transform-file-browse-url (actions candidate)
6889 "Add an action to browse the file CANDIDATE if it in a html
6890 file or URL. Else return ACTIONS unmodified."
6891 (let ((browse-action '("Browse with Browser" . browse-url)))
6892 (cond ((string-match "^http\\|^ftp" candidate)
6893 (cons browse-action actions))
6894 ((string-match "\\.html?$" candidate)
6895 (append actions (list browse-action)))
6896 (t actions))))
6898 ;;;; Function
6899 (defun anything-c-transform-function-call-interactively (actions candidate)
6900 "Add an action to call the function CANDIDATE interactively if
6901 it is a command. Else return ACTIONS unmodified."
6902 (if (commandp (intern-soft candidate))
6903 (append actions '(("Call Interactively"
6905 anything-c-call-interactively)))
6906 actions))
6908 ;;;; S-Expressions
6909 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
6910 "If CANDIDATE's `car' is a command, then add an action to
6911 evaluate it and put it onto the `command-history'."
6912 (if (commandp (car (read candidate)))
6913 ;; Make it first entry
6914 (cons '("Eval and put onto command-history" .
6915 (lambda (sexp)
6916 (let ((sym (read sexp)))
6917 (eval sym)
6918 (setq command-history
6919 (cons sym command-history)))))
6920 actions)
6921 actions))
6923 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6924 ;;; Buffers
6925 (defun anything-c-skip-boring-buffers (buffers)
6926 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
6928 (defun anything-c-skip-current-buffer (buffers)
6929 (if anything-allow-skipping-current-buffer
6930 (remove (buffer-name anything-current-buffer) buffers)
6931 buffers))
6933 (defun anything-c-shadow-boring-buffers (buffers)
6934 "Buffers matching `anything-c-boring-buffer-regexp' will be
6935 displayed with the `file-name-shadow' face if available."
6936 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
6938 ;;; Files
6939 (defun anything-c-shadow-boring-files (files)
6940 "Files matching `anything-c-boring-file-regexp' will be
6941 displayed with the `file-name-shadow' face if available."
6942 (anything-c-shadow-entries files anything-c-boring-file-regexp))
6944 (defun anything-c-skip-boring-files (files)
6945 "Files matching `anything-c-boring-file-regexp' will be skipped."
6946 (anything-c-skip-entries files anything-c-boring-file-regexp))
6947 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6949 (defun anything-c-skip-current-file (files)
6950 "Current file will be skipped."
6951 (remove (buffer-file-name anything-current-buffer) files))
6953 (defun anything-c-w32-pathname-transformer (args)
6954 "Change undesirable features of windows pathnames to ones more acceptable to
6955 other candidate transformers."
6956 (if (eq system-type 'windows-nt)
6957 (mapcar (lambda (x)
6958 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
6959 (mapcar (lambda (y)
6960 (replace-regexp-in-string "\\\\" "/" y)) args))
6961 args))
6963 (defun anything-c-shorten-home-path (files)
6964 "Replaces /home/user with ~."
6965 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6966 (getenv "HOME"))))
6967 (mapcar (lambda (file)
6968 (if (and (stringp file) (string-match home file))
6969 (cons (replace-match "~" nil nil file) file)
6970 file))
6971 files)))
6973 ;;; Functions
6974 (defun anything-c-mark-interactive-functions (functions)
6975 "Mark interactive functions (commands) with (i) after the function name."
6976 (let (list)
6977 (loop for function in functions
6978 do (push (cons (concat function
6979 (when (commandp (intern-soft function)) " (i)"))
6980 function)
6981 list)
6982 finally (return (nreverse list)))))
6984 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6985 (defvar anything-c-adaptive-done nil
6986 "nil if history information is not yet stored for the current
6987 selection.")
6989 (defvar anything-c-adaptive-history nil
6990 "Contains the stored history information.
6991 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6993 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
6994 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6995 when anything is started."
6996 (setq anything-c-adaptive-done nil))
6998 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
6999 "Advise `anything-exit-minibuffer' to store history information
7000 when a candidate is selected with RET."
7001 (anything-c-adaptive-store-selection))
7003 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
7004 "Advise `anything-select-action' to store history information
7005 when the user goes to the action list with TAB."
7006 (anything-c-adaptive-store-selection))
7008 (defun anything-c-source-use-adaptative-p (&optional source-name)
7009 "Return current source only if it use adaptative history, nil otherwise."
7010 (let* ((source (or source-name (anything-get-current-source)))
7011 (adapt-source (or (assoc-default 'filtered-candidate-transformer
7012 (assoc (assoc-default 'type source)
7013 anything-type-attributes))
7014 (assoc-default 'candidate-transformer
7015 (assoc (assoc-default 'type source)
7016 anything-type-attributes))
7017 (assoc-default 'filtered-candidate-transformer source)
7018 (assoc-default 'candidate-transformer source))))
7019 (if (listp adapt-source)
7020 (when (member 'anything-c-adaptive-sort adapt-source) source)
7021 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
7023 (defun anything-c-adaptive-store-selection ()
7024 "Store history information for the selected candidate."
7025 (unless anything-c-adaptive-done
7026 (setq anything-c-adaptive-done t)
7027 (let ((source (anything-c-source-use-adaptative-p)))
7028 (when source
7029 (let* ((source-name (or (assoc-default 'type source)
7030 (assoc-default 'name source)))
7031 (source-info (or (assoc source-name anything-c-adaptive-history)
7032 (progn
7033 (push (list source-name) anything-c-adaptive-history)
7034 (car anything-c-adaptive-history))))
7035 (selection (anything-get-selection))
7036 (selection-info (progn
7037 (setcdr source-info
7038 (cons
7039 (let ((found (assoc selection (cdr source-info))))
7040 (if (not found)
7041 ;; new entry
7042 (list selection)
7044 ;; move entry to the beginning of the
7045 ;; list, so that it doesn't get
7046 ;; trimmed when the history is
7047 ;; truncated
7048 (setcdr source-info
7049 (delete found (cdr source-info)))
7050 found))
7051 (cdr source-info)))
7052 (cadr source-info)))
7053 (pattern-info (progn
7054 (setcdr selection-info
7055 (cons
7056 (let ((found (assoc anything-pattern (cdr selection-info))))
7057 (if (not found)
7058 ;; new entry
7059 (cons anything-pattern 0)
7061 ;; move entry to the beginning of the
7062 ;; list, so if two patterns used the
7063 ;; same number of times then the one
7064 ;; used last appears first in the list
7065 (setcdr selection-info
7066 (delete found (cdr selection-info)))
7067 found))
7068 (cdr selection-info)))
7069 (cadr selection-info))))
7071 ;; increase usage count
7072 (setcdr pattern-info (1+ (cdr pattern-info)))
7074 ;; truncate history if needed
7075 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
7076 (setcdr selection-info
7077 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
7079 (if (file-readable-p anything-c-adaptive-history-file)
7080 (load-file anything-c-adaptive-history-file))
7081 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
7083 (defun anything-c-adaptive-save-history ()
7084 "Save history information to file given by `anything-c-adaptive-history-file'."
7085 (interactive)
7086 (with-temp-buffer
7087 (insert
7088 ";; -*- mode: emacs-lisp -*-\n"
7089 ";; History entries used for anything adaptive display.\n")
7090 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
7091 (current-buffer))
7092 (insert ?\n)
7093 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
7094 (unless (interactive-p) 'quiet))))
7096 (defun anything-c-adaptive-sort (candidates source)
7097 "Sort the CANDIDATES for SOURCE by usage frequency.
7098 This is a filtered candidate transformer you can use for the
7099 attribute `filtered-candidate-transformer' of a source in
7100 `anything-sources' or a type in `anything-type-attributes'."
7101 (let* ((source-name (or (assoc-default 'type source)
7102 (assoc-default 'name source)))
7103 (source-info (assoc source-name anything-c-adaptive-history)))
7104 (if (not source-info)
7105 ;; if there is no information stored for this source then do nothing
7106 candidates
7107 ;; else...
7108 (let ((usage
7109 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
7110 ;; pairs
7111 (mapcar (lambda (candidate-info)
7112 (let ((count 0))
7113 (dolist (pattern-info (cdr candidate-info))
7114 (if (not (equal (car pattern-info)
7115 anything-pattern))
7116 (incf count (cdr pattern-info))
7118 ;; if current pattern is equal to the previously
7119 ;; used one then this candidate has priority
7120 ;; (that's why its count is boosted by 10000) and
7121 ;; it only has to compete with other candidates
7122 ;; which were also selected with the same pattern
7123 (setq count (+ 10000 (cdr pattern-info)))
7124 (return)))
7125 (cons (car candidate-info) count)))
7126 (cdr source-info)))
7127 sorted)
7129 ;; sort the list in descending order, so candidates with highest
7130 ;; priorty come first
7131 (setq usage (sort usage (lambda (first second)
7132 (> (cdr first) (cdr second)))))
7134 ;; put those candidates first which have the highest usage count
7135 (dolist (info usage)
7136 (when (member* (car info) candidates
7137 :test 'anything-c-adaptive-compare)
7138 (push (car info) sorted)
7139 (setq candidates (remove* (car info) candidates
7140 :test 'anything-c-adaptive-compare))))
7142 ;; and append the rest
7143 (append (reverse sorted) candidates nil)))))
7145 (defun anything-c-adaptive-compare (x y)
7146 "Compare candidates X and Y taking into account that the
7147 candidate can be in (DISPLAY . REAL) format."
7148 (equal (if (listp x)
7149 (cdr x)
7151 (if (listp y)
7152 (cdr y)
7153 y)))
7155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7156 (defvar anything-outline-goto-near-line-flag t)
7157 (defvar anything-outline-using nil)
7158 (defun anything-after-update-hook--outline ()
7159 (if (and (eq anything-outline-using t)
7160 (eq anything-outline-goto-near-line-flag t))
7161 (anything-outline-goto-near-line)))
7162 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
7164 (defun anything-outline-goto-near-line ()
7165 (with-anything-window
7166 ;; TODO need consideration whether to update position by every input.
7167 (when t ; (equal anything-pattern "")
7168 (anything-goto-line 2)
7169 (let ((lineno (with-current-buffer anything-current-buffer
7170 (line-number-at-pos (car anything-current-position)))))
7171 (block exit
7172 (while (<= (progn (skip-chars-forward " ")
7173 (or (number-at-point) lineno))
7174 lineno)
7175 (forward-line 1)
7176 (when (eobp)
7177 (forward-line -1)
7178 (return-from exit))))
7179 (forward-line -1)
7180 (and (bobp) (forward-line 1))
7181 (and (anything-pos-header-line-p) (forward-line -2))
7182 (anything-mark-current-line)))))
7184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7185 ;; Plug-in: info-index
7186 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
7187 (let (result)
7188 (unless (anything-candidate-buffer)
7189 (save-window-excursion
7190 (info file)
7191 (let (Info-history
7192 (tobuf (anything-candidate-buffer 'global))
7193 (infobuf (current-buffer))
7194 s e)
7195 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
7196 (Info-goto-node node)
7197 (goto-char (point-min))
7198 (while (search-forward "\n* " nil t)
7199 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
7200 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
7201 (setq s (point-at-bol)
7202 e (point-at-eol))
7203 (with-current-buffer tobuf
7204 (insert-buffer-substring infobuf s e)
7205 (insert "\n"))))))))))
7207 (defun anything-c-info-goto (node-line)
7208 (Info-goto-node (car node-line))
7209 (anything-goto-line (cdr node-line)))
7211 (defun anything-c-info-display-to-real (line)
7212 (and (string-match
7213 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
7214 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
7215 (string-to-number (or (match-string 3 line) "1")))))
7217 (defun anything-c-make-info-source (file)
7218 `((name . ,(concat "Info Index: " file))
7219 (info-file . ,file)
7220 (init . anything-c-info-init)
7221 (display-to-real . anything-c-info-display-to-real)
7222 (get-line . buffer-substring)
7223 (candidates-in-buffer)
7224 (action ("Goto node" . anything-c-info-goto))))
7226 (defun anything-compile-source--info-index (source)
7227 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
7228 (anything-c-make-info-source it)
7229 source))
7230 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
7232 (anything-document-attribute 'info-index "info-index plugin"
7233 "Create a source of info index very easily.
7235 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
7237 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
7238 "Index nodes of info file.
7240 If it is omitted, `Info-index-nodes' is used to collect index nodes.
7241 Some info files are missing index specification.
7243 ex. See `anything-c-source-info-screen'.")
7245 ;; Plug-in: candidates-file
7246 (defun anything-compile-source--candidates-file (source)
7247 (if (assoc-default 'candidates-file source)
7248 `((init anything-p-candidats-file-init
7249 ,@(let ((orig-init (assoc-default 'init source)))
7250 (cond ((null orig-init) nil)
7251 ((functionp orig-init) (list orig-init))
7252 (t orig-init))))
7253 (candidates-in-buffer)
7254 ,@source)
7255 source))
7256 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
7258 (defun anything-p-candidats-file-init ()
7259 (destructuring-bind (file &optional updating)
7260 (anything-mklist (anything-attr 'candidates-file))
7261 (setq file (anything-interpret-value file))
7262 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
7263 (when updating
7264 (buffer-disable-undo)
7265 (font-lock-mode -1)
7266 (auto-revert-mode 1)))))
7268 (anything-document-attribute 'candidates-file "candidates-file plugin"
7269 "Use a file as the candidates buffer.
7271 1st argument is a filename, string or function name or variable name.
7272 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
7274 ;; Plug-in: headline
7275 (defun anything-compile-source--anything-headline (source)
7276 (if (assoc-default 'headline source)
7277 (append '((init . anything-headline-init)
7278 (get-line . buffer-substring)
7279 (type . line))
7280 source
7281 '((candidates-in-buffer)
7282 (persistent-help . "Show this line")))
7283 source))
7284 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
7286 (defun anything-headline-init ()
7287 (when (and (anything-current-buffer-is-modified)
7288 (with-current-buffer anything-current-buffer
7289 (eval (or (anything-attr 'condition) t))))
7290 (anything-headline-make-candidate-buffer
7291 (anything-interpret-value (anything-attr 'headline))
7292 (anything-interpret-value (anything-attr 'subexp)))))
7294 (anything-document-attribute 'headline "Headline plug-in"
7295 "Regexp string for anything-headline to scan.")
7296 (anything-document-attribute 'condition "Headline plug-in"
7297 "A sexp representing the condition to use anything-headline.")
7298 (anything-document-attribute 'subexp "Headline plug-in"
7299 "Display (match-string-no-properties subexp).")
7302 (defun anything-headline-get-candidates (regexp subexp)
7303 (with-current-buffer anything-current-buffer
7304 (save-excursion
7305 (goto-char (point-min))
7306 (if (functionp regexp) (setq regexp (funcall regexp)))
7307 (let (hierarchy curhead)
7308 (flet ((matched ()
7309 (if (numberp subexp)
7310 (cons (match-string-no-properties subexp) (match-beginning subexp))
7311 (cons (buffer-substring (point-at-bol) (point-at-eol))
7312 (point-at-bol))))
7313 (hierarchies (headlines)
7314 (1+ (loop for (_ . hierarchy) in headlines
7315 maximize hierarchy)))
7316 (vector-0-n (v n)
7317 (loop for i from 0 to hierarchy
7318 collecting (aref curhead i)))
7319 (arrange (headlines)
7320 (unless (null headlines) ; FIX headlines empty bug!
7321 (loop with curhead = (make-vector (hierarchies headlines) "")
7322 for ((str . pt) . hierarchy) in headlines
7323 do (aset curhead hierarchy str)
7324 collecting
7325 (cons
7326 (format "H%d:%s" (1+ hierarchy)
7327 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
7328 pt)))))
7329 (if (listp regexp)
7330 (arrange
7331 (sort
7332 (loop for re in regexp
7333 for hierarchy from 0
7334 do (goto-char (point-min))
7335 appending
7336 (loop
7337 while (re-search-forward re nil t)
7338 collect (cons (matched) hierarchy)))
7339 (lambda (a b) (> (cdar b) (cdar a)))))
7340 (loop while (re-search-forward regexp nil t)
7341 collect (matched))))))))
7344 (defun anything-headline-make-candidate-buffer (regexp subexp)
7345 (with-current-buffer (anything-candidate-buffer 'local)
7346 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
7347 do (insert
7348 (format "%5d:%s\n"
7349 (with-current-buffer anything-current-buffer
7350 (line-number-at-pos pos))
7351 content)))))
7353 (defun anything-headline-goto-position (pos recenter)
7354 (goto-char pos)
7355 (unless recenter
7356 (set-window-start (get-buffer-window anything-current-buffer) (point))))
7358 (defun anything-revert-buffer (candidate)
7359 (with-current-buffer candidate
7360 (when (buffer-modified-p)
7361 (revert-buffer t t))))
7363 (defun anything-revert-marked-buffers (ignore)
7364 (mapc 'anything-revert-buffer (anything-marked-candidates)))
7366 (defun anything-kill-marked-buffers (ignore)
7367 (mapc 'kill-buffer (anything-marked-candidates)))
7369 ;; Plug-in: persistent-help
7370 (defun anything-compile-source--persistent-help (source)
7371 (append source '((header-line . anything-persistent-help-string))))
7372 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
7374 (defun anything-persistent-help-string ()
7375 (substitute-command-keys
7376 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
7377 (or (anything-interpret-value (anything-attr 'persistent-help))
7378 (anything-aif (or (assoc-default 'persistent-action
7379 (anything-get-current-source))
7380 (assoc-default 'action
7381 (anything-get-current-source)))
7382 (cond ((symbolp it) (symbol-name it))
7383 ((listp it) (or (ignore-errors (caar it)) ""))))
7385 " (keeping session)")))
7387 (anything-document-attribute 'persistent-help "persistent-help plug-in"
7388 "A string to explain persistent-action of this source.
7389 It also accepts a function or a variable name.")
7391 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
7393 ;; Plug-in: Type customize
7394 (defun anything-c-uniq-list (lst)
7395 "Like `remove-duplicates' in CL.
7396 But cut deeper duplicates and test by `equal'. "
7397 (reverse (remove-duplicates (reverse lst) :test 'equal)))
7398 (defvar anything-additional-type-attributes nil)
7399 (defun anything-c-arrange-type-attribute (type spec)
7400 "Override type attributes by `define-anything-type-attribute'.
7402 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
7404 Example: Set `play-sound-file' as default action
7405 (anything-c-arrange-type-attribute 'file
7406 '((action (\"Play sound\" . play-sound-file)
7407 REST ;; Rest of actions (find-file, find-file-other-window, ...)
7410 (add-to-list 'anything-additional-type-attributes
7411 (cons type
7412 (loop with typeattr = (assoc-default type anything-type-attributes)
7413 for (attr . value) in spec
7414 if (listp value)
7415 collect (cons attr
7416 (anything-c-uniq-list
7417 (loop for v in value
7418 if (eq v 'REST)
7419 append (assoc-default attr typeattr)
7420 else
7421 collect v)))
7422 else
7423 collect (cons attr value)))))
7424 (put 'anything-c-arrange-type-attribute 'lisp-indent-function 1)
7426 (defun anything-compile-source--type-customize (source)
7427 (anything-aif (assoc-default (assoc-default 'type source) anything-additional-type-attributes)
7428 (append it source)
7429 source))
7430 (add-to-list 'anything-compile-source-functions 'anything-compile-source--type-customize t)
7432 ;; Plug-in: default-action
7433 (defun anything-compile-source--default-action (source)
7434 (anything-aif (assoc-default 'default-action source)
7435 (append `((action ,it ,@(remove it (assoc-default 'action source))))
7436 source)
7437 source))
7438 (add-to-list 'anything-compile-source-functions 'anything-compile-source--default-action t)
7439 (anything-document-attribute 'default-action "default-action plug-in"
7440 "Default action.")
7442 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7444 (defun anything-c-find-file-or-marked (candidate)
7445 "Open file CANDIDATE or open anything marked files in background."
7446 (let ((marked (anything-marked-candidates)))
7447 (if (> (length marked) 1)
7448 ;; Open all marked files in background.
7449 (mapc 'find-file-noselect marked)
7450 (if (and (not (file-exists-p candidate))
7451 (and ffap-url-regexp
7452 (not (string-match ffap-url-regexp candidate)))
7453 (string-match "/$" candidate))
7454 ;; A a non--existing filename ending with /
7455 ;; Create a directory and jump to it.
7456 (when (y-or-n-p (format "Create directory `%s'? " candidate))
7457 (let ((cur-dir default-directory))
7458 (unwind-protect
7459 (progn
7460 (make-directory candidate 'parent)
7461 (when (file-exists-p candidate)
7462 (cd candidate)
7463 (anything-find-files candidate)))
7464 (setq default-directory cur-dir))))
7465 ;; A non--existing filename NOT ending with / or
7466 ;; an existing filename, create or jump to it.
7467 (find-file-at-point candidate)))))
7469 (defun anything-delete-marked-files (ignore)
7470 (let* ((files (anything-marked-candidates))
7471 (len (length files)))
7472 (if (not (y-or-n-p
7473 (format "Delete *%s File(s):\n%s"
7475 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
7476 (message "(No deletions performed)")
7477 (dolist (i files)
7478 (set-text-properties 0 (length i) nil i)
7479 (anything-c-delete-file i))
7480 (message "%s File(s) deleted" len))))
7482 (defun anything-ediff-marked-buffers (candidate &optional merge)
7483 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
7484 With optional arg `merge' call `ediff-merge-buffers'."
7485 (let ((lg-lst (length (anything-marked-candidates)))
7486 buf1 buf2)
7487 (case lg-lst
7489 (error "Error:You have to mark at least 1 buffer"))
7491 (setq buf1 anything-current-buffer
7492 buf2 (first (anything-marked-candidates))))
7494 (setq buf1 (first (anything-marked-candidates))
7495 buf2 (second (anything-marked-candidates))))
7497 (error "Error:To much buffers marked!")))
7498 (if merge
7499 (ediff-merge-buffers buf1 buf2)
7500 (ediff-buffers buf1 buf2))))
7502 (defun anything-bookmark-get-bookmark-from-name (bmk)
7503 "Return bookmark name even if it is a bookmark with annotation.
7504 e.g prepended with *.
7505 Return nil if bmk is not a valid bookmark."
7506 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
7507 (if (assoc bookmark bookmark-alist)
7508 bookmark
7509 (when (assoc bmk bookmark-alist)
7510 bmk))))
7512 (defun anything-delete-marked-bookmarks (ignore)
7513 "Delete this bookmark or all marked bookmarks."
7514 (dolist (i (anything-marked-candidates))
7515 (bookmark-delete (anything-bookmark-get-bookmark-from-name i)
7516 'batch)))
7518 (defun anything-require-or-error (feature function)
7519 (or (require feature nil t)
7520 (error "Need %s to use `%s'." feature function)))
7522 (defun anything-find-buffer-on-elscreen (candidate)
7523 "Open buffer in new screen, if marked buffers open all in elscreens."
7524 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
7525 (anything-aif (anything-marked-candidates)
7526 (dolist (i it)
7527 (let ((target-screen (elscreen-find-screen-by-buffer
7528 (get-buffer i) 'create)))
7529 (elscreen-goto target-screen)))
7530 (let ((target-screen (elscreen-find-screen-by-buffer
7531 (get-buffer candidate) 'create)))
7532 (elscreen-goto target-screen))))
7534 (defun anything-elscreen-find-file (file)
7535 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
7536 (elscreen-find-file file))
7538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7540 ;;;; Type Attributes
7541 (define-anything-type-attribute 'buffer
7542 `((action
7543 ,@(if pop-up-frames
7544 '(("Switch to buffer other window" . switch-to-buffer-other-window)
7545 ("Switch to buffer" . switch-to-buffer))
7546 '(("Switch to buffer" . switch-to-buffer)
7547 ("Switch to buffer other window" . switch-to-buffer-other-window)
7548 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
7549 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
7550 ("View buffer" . view-buffer)
7551 ("Display buffer" . display-buffer)
7552 ("Revert buffer" . anything-revert-buffer)
7553 ("Revert Marked buffers" . anything-revert-marked-buffers)
7554 ("Insert buffer" . insert-buffer)
7555 ("Kill buffer" . kill-buffer)
7556 ("Kill Marked buffers" . anything-kill-marked-buffers)
7557 ("Diff with file" . diff-buffer-with-file)
7558 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
7559 ("Ediff Merge marked buffers" . (lambda (candidate)
7560 (anything-ediff-marked-buffers candidate t))))
7561 (persistent-help . "Show this buffer")
7562 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
7563 "Buffer or buffer name.")
7565 (define-anything-type-attribute 'file
7566 `((action
7567 ,@(if pop-up-frames
7568 '(("Find file other window" . find-file-other-window)
7569 ("Find file(s)" . anything-find-many-files)
7570 ("Find file as root" . anything-find-file-as-root))
7571 '(("Find file" . anything-find-many-files)
7572 ("Find file as root" . anything-find-file-as-root)
7573 ("Find file other window" . find-file-other-window)
7574 ("Find file other frame" . find-file-other-frame)))
7575 ("Open dired in file's directory" . anything-c-open-dired)
7576 ("Grep File(s)" . (lambda (candidate)
7577 ;; Restore highlighting disabled in *-find-files.
7578 (let ((anything-mp-highlight-delay 0.7))
7579 (anything-do-grep (anything-marked-candidates)))))
7580 ("View file" . view-file)
7581 ("Insert file" . insert-file)
7582 ("Delete file(s)" . anything-delete-marked-files)
7583 ("Open file externally (C-u to choose)" . anything-c-open-file-externally)
7584 ("Open file with default tool" . anything-c-open-file-with-default-tool)
7585 ("Find file in hex dump" . hexl-find-file))
7586 (persistent-help . "Show this file")
7587 (action-transformer anything-c-transform-file-load-el
7588 anything-c-transform-file-browse-url)
7589 (candidate-transformer anything-c-w32-pathname-transformer
7590 anything-c-skip-current-file
7591 anything-c-skip-boring-files
7592 anything-c-shorten-home-path))
7593 "File name.")
7595 (let ((actions '(("Describe command" . describe-function)
7596 ("Add command to kill ring" . anything-c-kill-new)
7597 ("Go to command's definition" . find-function)
7598 ("Debug on entry" . debug-on-entry)
7599 ("Cancel debug on entry" . cancel-debug-on-entry)
7600 ("Trace function" . trace-function)
7601 ("Trace function (background)" . trace-function-background)
7602 ("Untrace function" . untrace-function))))
7603 (define-anything-type-attribute 'command
7604 `((action ("Call interactively" . anything-c-call-interactively)
7605 ,@actions)
7606 ;; Sort commands according to their usage count.
7607 (filtered-candidate-transformer . anything-c-adaptive-sort)
7608 (coerce . anything-c-symbolify)
7609 (persistent-action . describe-function))
7610 "Command. (string or symbol)")
7612 (define-anything-type-attribute 'function
7613 `((action . ,actions)
7614 (action-transformer anything-c-transform-function-call-interactively)
7615 (candidate-transformer anything-c-mark-interactive-functions)
7616 (coerce . anything-c-symbolify))
7617 "Function. (string or symbol)"))
7619 (define-anything-type-attribute 'variable
7620 '((action ("Describe variable" . describe-variable)
7621 ("Add variable to kill ring" . anything-c-kill-new)
7622 ("Go to variable's definition" . find-variable)
7623 ("Set variable" . anything-c-set-variable))
7624 (coerce . anything-c-symbolify))
7625 "Variable.")
7627 (define-anything-type-attribute 'sexp
7628 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
7629 ("Add s-expression to kill ring" . kill-new))
7630 (action-transformer anything-c-transform-sexp-eval-command-sexp))
7631 "String representing S-Expressions.")
7633 (define-anything-type-attribute 'bookmark
7634 `((coerce . anything-bookmark-get-bookmark-from-name)
7635 (action
7636 ("Jump to bookmark" . (lambda (bookmark)
7637 (let ((current-prefix-arg anything-current-prefix-arg))
7638 (bookmark-jump bookmark))
7639 (anything-update)))
7640 ("Jump to BM other window" . (lambda (bookmark)
7641 (bookmark-jump-other-window bookmark)
7642 (anything-update)))
7643 ("Bookmark edit annotation" . bookmark-edit-annotation)
7644 ("Bookmark show annotation" . bookmark-show-annotation)
7645 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
7646 ,@(when (fboundp 'bmkext-edit-bookmark)
7647 '(("Edit Bookmark" . bmkext-edit-bookmark)))
7648 ("Rename bookmark" . bookmark-rename)
7649 ("Relocate bookmark" . bookmark-relocate)))
7650 "Bookmark name.")
7652 (define-anything-type-attribute 'line
7653 '((display-to-real . anything-c-display-to-real-line)
7654 (action ("Go to Line" . anything-c-action-line-goto)))
7655 "LINENO:CONTENT string, eg. \" 16:foo\".
7657 Optional `target-file' attribute is a name of target file.
7659 Optional `before-jump-hook' attribute is a function with no
7660 arguments which is called before jumping to position.
7662 Optional `after-jump-hook' attribute is a function with no
7663 arguments which is called after jumping to position.
7665 If `adjust' attribute is specified, searches the line whose
7666 content is CONTENT near the LINENO.
7668 If `recenter' attribute is specified, the line is displayed at
7669 the center of window, otherwise at the top of window.
7672 (define-anything-type-attribute 'file-line
7673 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
7674 (multiline)
7675 (action ("Go to" . anything-c-action-file-line-goto)))
7676 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
7678 Optional `default-directory' attribute is a default-directory
7679 FILENAME is interpreted.
7681 Optional `before-jump-hook' attribute is a function with no
7682 arguments which is called before jumping to position.
7684 Optional `after-jump-hook' attribute is a function with no
7685 arguments which is called after jumping to position.
7687 If `adjust' attribute is specified, searches the line whose
7688 content is CONTENT near the LINENO.
7690 If `recenter' attribute is specified, the line is displayed at
7691 the center of window, otherwise at the top of window.
7694 (define-anything-type-attribute 'timer
7695 '((real-to-display . anything-c-timer-real-to-display)
7696 (action ("Cancel Timer" . cancel-timer)
7697 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
7698 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
7699 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
7700 (persistent-help . "Describe Function"))
7701 "Timer.")
7703 ;;;; Default `anything-sources'
7704 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
7705 ;; tend to invoke M-x anything directly. So I offer default setting.
7706 (setq anything-sources
7707 '(anything-c-source-buffers+
7708 anything-c-source-recentf
7709 anything-c-source-files-in-current-dir+))
7711 ;;;; unit test
7712 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7713 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
7714 (dont-compile
7715 (when (fboundp 'expectations)
7716 (expectations
7717 (desc "candidates-file plug-in")
7718 (expect '(anything-p-candidats-file-init)
7719 (assoc-default 'init
7720 (car (anything-compile-sources
7721 '(((name . "test")
7722 (candidates-file . "test.txt")))
7723 '(anything-compile-source--candidates-file)))))
7724 (expect '(anything-p-candidats-file-init
7725 (lambda () 1))
7726 (assoc-default 'init
7727 (car (anything-compile-sources
7728 '(((name . "test")
7729 (candidates-file . "test.txt")
7730 (init . (lambda () 1))))
7731 '(anything-compile-source--candidates-file)))))
7732 (expect '(anything-p-candidats-file-init
7733 (lambda () 1))
7734 (assoc-default 'init
7735 (car (anything-compile-sources
7736 '(((name . "test")
7737 (candidates-file . "test.txt")
7738 (init (lambda () 1))))
7739 '(anything-compile-source--candidates-file)))))
7740 ;; FIXME error
7741 ;; (desc "anything-c-source-buffers")
7742 ;; (expect '(("Buffers" ("foo" "curbuf")))
7743 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
7744 ;; (let ((anything-c-boring-buffer-regexp
7745 ;; (rx (or
7746 ;; (group bos " ")
7747 ;; "*anything"
7748 ;; ;; echo area
7749 ;; " *Echo Area" " *Minibuf"))))
7750 ;; (flet ((buffer-name (&optional x) x))
7751 ;; (anything-test-candidates 'anything-c-source-buffers))))
7752 (desc "anything-c-stringify")
7753 (expect "str1"
7754 (anything-c-stringify "str1"))
7755 (expect "str2"
7756 (anything-c-stringify 'str2))
7757 (desc "anything-c-symbolify")
7758 (expect 'sym1
7759 (anything-c-symbolify "sym1"))
7760 (expect 'sym2
7761 (anything-c-symbolify 'sym2))
7762 (desc "plug-in:default-action")
7763 (expect '(((action ("default" . default) ("original" . original))
7764 (default-action . ("default" . default))
7765 (action ("original" . original))))
7766 (anything-compile-sources
7767 '(((default-action . ("default" . default))
7768 (action ("original" . original))))
7769 '(anything-compile-source--default-action)))
7770 (expect '(((action ("a1" . a1) ("a2" . a2))
7771 (default-action . ("a1" . a1))
7772 (action ("a1" . a1) ("a2" . a2))))
7773 (anything-compile-sources
7774 '(((default-action . ("a1" . a1))
7775 (action ("a1" . a1) ("a2" . a2))))
7776 '(anything-compile-source--default-action)))
7777 (expect '(((action ("a2" . a2) ("a1" . a1))
7778 (default-action . ("a2" . a2))
7779 (action ("a1" . a1) ("a2" . a2))))
7780 (anything-compile-sources
7781 '(((default-action . ("a2" . a2))
7782 (action ("a1" . a1) ("a2" . a2))))
7783 '(anything-compile-source--default-action))))))
7785 (provide 'anything-config)
7787 ;;; Local Variables:
7788 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
7789 ;;; End:
7791 ;; How to save (DO NOT REMOVE!!)
7792 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
7793 ;;; anything-config.el ends here
7795 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
7796 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
7797 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
7798 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
7799 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
7800 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
7801 ;;; LocalWords: dotimes Thierry online vname
7802 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
7803 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
7804 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
7805 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
7806 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
7807 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
7808 ;;; LocalWords: startpos noselect dont desc