anything-menu.el (anything-menu): write current selection to am/tmp-file after action
[anything-config.git] / anything-config.el
blob81181179f318edd9594c8b3fa065b751c1a3c82c
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.
54 ;;
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-c-describe-anything-bindings'
83 ;; [OBSOLETE] Describe `anything' bindings.
84 ;; `anything-mini'
85 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
86 ;; `anything-for-files'
87 ;; Preconfigured `anything' for opening files.
88 ;; `anything-recentf'
89 ;; Preconfigured `anything' for `recentf'.
90 ;; `anything-info-at-point'
91 ;; Preconfigured `anything' for searching info at point.
92 ;; `anything-show-kill-ring'
93 ;; Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
94 ;; `anything-minibuffer-history'
95 ;; Preconfigured `anything' for `minibuffer-history'.
96 ;; `anything-gentoo'
97 ;; Preconfigured `anything' for gentoo linux.
98 ;; `anything-surfraw-only'
99 ;; Preconfigured `anything' for surfraw.
100 ;; `anything-imenu'
101 ;; Preconfigured `anything' for `imenu'.
102 ;; `anything-google-suggest'
103 ;; Preconfigured `anything' for google search with google suggest.
104 ;; `anything-yahoo-suggest'
105 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
106 ;; `anything-for-buffers'
107 ;; Preconfigured `anything' for buffer.
108 ;; `anything-bbdb'
109 ;; Preconfigured `anything' for BBDB.
110 ;; `anything-locate'
111 ;; Preconfigured `anything' for Locate.
112 ;; `anything-w3m-bookmarks'
113 ;; Preconfigured `anything' for w3m bookmark.
114 ;; `anything-colors'
115 ;; Preconfigured `anything' for color.
116 ;; `anything-bm-list'
117 ;; Preconfigured `anything' for visible bookmarks.
118 ;; `anything-timers'
119 ;; Preconfigured `anything' for timers.
120 ;; `anything-kill-buffers'
121 ;; Preconfigured `anything' to kill buffer you selected.
122 ;; `anything-query-replace-regexp'
123 ;; Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually.
124 ;; `anything-regexp'
125 ;; Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement.
126 ;; `anything-insert-buffer-name'
127 ;; Insert buffer name.
128 ;; `anything-insert-symbol'
129 ;; Insert current symbol.
130 ;; `anything-insert-selection'
131 ;; Insert current selection.
132 ;; `anything-show-buffer-only'
133 ;; [OBSOLETE] Only show sources about buffer.
134 ;; `anything-show-bbdb-only'
135 ;; [OBSOLETE] Only show sources about BBDB.
136 ;; `anything-show-locate-only'
137 ;; [OBSOLETE] Only show sources about Locate.
138 ;; `anything-show-info-only'
139 ;; [OBSOLETE] Only show sources about Info.
140 ;; `anything-show-imenu-only'
141 ;; [OBSOLETE] Only show sources about Imenu.
142 ;; `anything-show-files-only'
143 ;; [OBSOLETE] Only show sources about File.
144 ;; `anything-show-w3m-bookmarks-only'
145 ;; [OBSOLETE] Only show source about w3m bookmark.
146 ;; `anything-show-colors-only'
147 ;; [OBSOLETE] Only show source about color.
148 ;; `anything-show-kill-ring-only'
149 ;; [OBSOLETE] Only show source about kill ring.
150 ;; `anything-show-this-source-only'
151 ;; Only show this source.
152 ;; `anything-test-sources'
153 ;; List all anything sources for test.
154 ;; `anything-select-source'
155 ;; Select source.
156 ;; `anything-find-files-down-one-level'
157 ;; Go down one level like unix command `cd ..'.
158 ;; `anything-find-files'
159 ;; Preconfigured `anything' for anything implementation of `find-file'.
160 ;; `anything-write-file'
161 ;; Preconfigured `anything' providing completion for `write-file'.
162 ;; `anything-insert-file'
163 ;; Preconfigured `anything' providing completion for `insert-file'.
164 ;; `anything-dired-rename-file'
165 ;; Preconfigured `anything' to rename files from dired.
166 ;; `anything-dired-copy-file'
167 ;; Preconfigured `anything' to copy files from dired.
168 ;; `anything-dired-symlink-file'
169 ;; Preconfigured `anything' to symlink files from dired.
170 ;; `anything-dired-hardlink-file'
171 ;; Preconfigured `anything' to hardlink files from dired.
172 ;; `anything-dired-bindings'
173 ;; Replace usual dired commands `C' and `R' by anything ones.
174 ;; `anything-manage-advice'
175 ;; Preconfigured `anything' to disable/enable function advices.
176 ;; `anything-bookmark-ext'
177 ;; Preconfigured `anything' for bookmark-extensions sources.
178 ;; `anything-simple-call-tree'
179 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
180 ;; `anything-mark-ring'
181 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
182 ;; `anything-global-mark-ring'
183 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
184 ;; `anything-yaoddmuse-cache-pages'
185 ;; Fetch the list of files on emacswiki and create cache file.
186 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
187 ;; Preconfigured `anything' to edit or view EmacsWiki page.
188 ;; `anything-yaoddmuse-emacswiki-post-library'
189 ;; Preconfigured `anything' to post library to EmacsWiki.
190 ;; `anything-emms-stream-edit-bookmark'
191 ;; Change the information of current emms-stream bookmark from anything.
192 ;; `anything-emms-stream-delete-bookmark'
193 ;; Delete an emms-stream bookmark from anything.
194 ;; `anything-call-source'
195 ;; Preconfigured `anything' to call anything source.
196 ;; `anything-call-source-from-anything'
197 ;; Call anything source within `anything' session.
198 ;; `anything-execute-anything-command'
199 ;; Preconfigured `anything' to execute preconfigured `anything'.
200 ;; `anything-occur'
201 ;; Preconfigured Anything for Occur source.
202 ;; `anything-create-from-anything'
203 ;; Run `anything-create' from `anything' as a fallback.
204 ;; `anything-create'
205 ;; Preconfigured `anything' to do many create actions from STRING.
206 ;; `anything-top'
207 ;; Preconfigured `anything' for top command.
208 ;; `anything-select-xfont'
209 ;; Preconfigured `anything' to select Xfont.
210 ;; `anything-apt'
211 ;; Preconfigured `anything' : frontend of APT package manager.
212 ;; `anything-c-shell-command-if-needed'
213 ;; Not documented.
214 ;; `anything-c-run-external-command'
215 ;; Run External PROGRAM asyncronously from Emacs.
216 ;; `anything-ratpoison-commands'
217 ;; Preconfigured `anything' to execute ratpoison commands.
218 ;; `anything-c-set-variable'
219 ;; Set value to VAR interactively.
220 ;; `anything-c-adaptive-save-history'
221 ;; Save history information to file given by `anything-c-adaptive-history-file'.
223 ;; * User variables defined here:
224 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
225 ;; `anything-c-use-standard-keys'
226 ;; Default Value: nil
227 ;; `anything-c-adaptive-history-file'
228 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
229 ;; `anything-c-adaptive-history-length'
230 ;; Default Value: 50
231 ;; `anything-c-google-suggest-url'
232 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
233 ;; `anything-c-google-suggest-search-url'
234 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
235 ;; `anything-google-suggest-use-curl-p'
236 ;; Default Value: nil
237 ;; `anything-c-yahoo-suggest-url'
238 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
239 ;; `anything-c-yahoo-suggest-search-url'
240 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
241 ;; `anything-c-boring-buffer-regexp'
242 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
243 ;; `anything-c-boring-file-regexp'
244 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
245 ;; `anything-kill-ring-threshold'
246 ;; Default Value: 10
247 ;; `anything-su-or-sudo'
248 ;; Default Value: "su"
249 ;; `anything-for-files-prefered-list'
250 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
251 ;; `anything-create--actions-private'
252 ;; Default Value: nil
253 ;; `anything-allow-skipping-current-buffer'
254 ;; Default Value: t
255 ;; `anything-c-enable-eval-defun-hack'
256 ;; Default Value: t
257 ;; `anything-tramp-verbose'
258 ;; Default Value: 0
259 ;; `anything-back-to-emacs-shell-command'
260 ;; Default Value: nil
262 ;; * Anything sources defined here:
263 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
264 ;; `anything-c-source-buffers' (Buffers)
265 ;; `anything-c-source-buffer-not-found' (Create buffer)
266 ;; `anything-c-source-buffers+' (Buffers)
267 ;; `anything-c-source-file-name-history' (File Name History)
268 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
269 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
270 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
271 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
272 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
273 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
274 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
275 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
276 ;; `anything-c-source-file-cache-initialized' ()
277 ;; `anything-c-source-file-cache' (File Cache)
278 ;; `anything-c-source-locate' (Locate)
279 ;; `anything-c-source-recentf' (Recentf)
280 ;; `anything-c-source-ffap-guesser' (File at point)
281 ;; `anything-c-source-ffap-line' (File/Lineno at point)
282 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
283 ;; `anything-c-source-info-pages' (Info Pages)
284 ;; `anything-c-source-info-elisp' (Info index: elisp)
285 ;; `anything-c-source-info-cl' (Info index: cl)
286 ;; `anything-c-source-info-org' (Info index: org)
287 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
288 ;; `anything-c-source-info-zsh' (Info index: zsh)
289 ;; `anything-c-source-info-bash' (Info index: bash)
290 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
291 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
292 ;; `anything-c-source-info-find' (Info index: find)
293 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
294 ;; `anything-c-source-info-textutils' (Info index: textutils)
295 ;; `anything-c-source-info-libc' (Info index: libc)
296 ;; `anything-c-source-info-make' (Info index: make)
297 ;; `anything-c-source-info-automake' (Info index: automake)
298 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
299 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
300 ;; `anything-c-source-info-emacs' (Info index: emacs)
301 ;; `anything-c-source-info-elib' (Info index: elib)
302 ;; `anything-c-source-info-eieio' (Info index: eieio)
303 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
304 ;; `anything-c-source-info-guile' (Info index: guile)
305 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
306 ;; `anything-c-source-info-goops' (Info index: goops)
307 ;; `anything-c-source-info-screen' (Info index: screen)
308 ;; `anything-c-source-info-latex' (Info index: latex)
309 ;; `anything-c-source-info-gawk' (Info index: gawk)
310 ;; `anything-c-source-info-sed' (Info index: sed)
311 ;; `anything-c-source-info-m4' (Info index: m4)
312 ;; `anything-c-source-info-wget' (Info index: wget)
313 ;; `anything-c-source-info-binutils' (Info index: binutils)
314 ;; `anything-c-source-info-as' (Info index: as)
315 ;; `anything-c-source-info-bfd' (Info index: bfd)
316 ;; `anything-c-source-info-gprof' (Info index: gprof)
317 ;; `anything-c-source-info-ld' (Info index: ld)
318 ;; `anything-c-source-info-diff' (Info index: diff)
319 ;; `anything-c-source-info-flex' (Info index: flex)
320 ;; `anything-c-source-info-grep' (Info index: grep)
321 ;; `anything-c-source-info-gzip' (Info index: gzip)
322 ;; `anything-c-source-info-libtool' (Info index: libtool)
323 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
324 ;; `anything-c-source-info-info' (Info index: info)
325 ;; `anything-c-source-info-gdb' (Info index: gdb)
326 ;; `anything-c-source-info-stabs' (Info index: stabs)
327 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
328 ;; `anything-c-source-info-cvs' (Info index: cvs)
329 ;; `anything-c-source-info-bison' (Info index: bison)
330 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
331 ;; `anything-c-source-info-global' (Info index: global)
332 ;; `anything-c-source-man-pages' (Manual Pages)
333 ;; `anything-c-source-complex-command-history' (Complex Command History)
334 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
335 ;; `anything-c-source-emacs-commands' (Emacs Commands)
336 ;; `anything-c-source-lacarte' (Lacarte)
337 ;; `anything-c-source-emacs-functions' (Emacs Functions)
338 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
339 ;; `anything-c-source-advice' (Function Advice)
340 ;; `anything-c-source-emacs-variables' (Emacs Variables)
341 ;; `anything-c-source-bookmarks' (Bookmarks)
342 ;; `anything-c-source-bookmark-set' (Set Bookmark)
343 ;; `anything-c-source-bm' (Visible Bookmarks)
344 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
345 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
346 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
347 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
348 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
349 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
350 ;; `anything-c-source-bookmark-info' (Bookmark Info)
351 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
352 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
353 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
354 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
355 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
356 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
357 ;; `anything-c-source-imenu' (Imenu)
358 ;; `anything-c-source-ctags' (Exuberant ctags)
359 ;; `anything-c-source-semantic' (Semantic Tags)
360 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
361 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
362 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
363 ;; `anything-c-source-customize-face' (Customize Face)
364 ;; `anything-c-source-colors' (Colors)
365 ;; `anything-c-source-tracker-search' (Tracker Search)
366 ;; `anything-c-source-mac-spotlight' (mdfind)
367 ;; `anything-c-source-kill-ring' (Kill Ring)
368 ;; `anything-c-source-mark-ring' (mark-ring)
369 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
370 ;; `anything-c-source-register' (Registers)
371 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
372 ;; `anything-c-source-rd-headline' (RD HeadLine)
373 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
374 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
375 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
376 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
377 ;; `anything-c-source-org-headline' (Org HeadLine)
378 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
379 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
380 ;; `anything-c-source-eev-anchor' (Anchors)
381 ;; `anything-c-source-org-keywords' (Org Keywords)
382 ;; `anything-c-source-picklist' (Picklist)
383 ;; `anything-c-source-bbdb' (BBDB)
384 ;; `anything-c-source-evaluation-result' (Evaluation Result)
385 ;; `anything-c-source-calculation-result' (Calculation Result)
386 ;; `anything-c-source-google-suggest' (Google Suggest)
387 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
388 ;; `anything-c-source-surfraw' (Surfraw)
389 ;; `anything-c-source-emms-streams' (Emms Streams)
390 ;; `anything-c-source-emms-dired' (Music Directory)
391 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
392 ;; `anything-c-source-call-source' (Call anything source)
393 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
394 ;; `anything-c-source-occur' (Occur)
395 ;; `anything-c-source-create' (Create)
396 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
397 ;; `anything-c-source-elscreen' (Elscreen)
398 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
399 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
400 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
401 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
402 ;; `anything-c-source-xfonts' (X Fonts)
403 ;; `anything-c-source-apt' (APT)
404 ;; `anything-c-source-gentoo' (Portage sources)
405 ;; `anything-c-source-use-flags' (Use Flags)
406 ;; `anything-c-source-emacs-process' (Emacs Process)
407 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
409 ;; *** END auto-documentation
412 ;;; Change log:
414 ;; Change log of this file is found at
415 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
417 ;;; Contributors:
419 ;; Tamas Patrovics
420 ;; Tassilo Horn <tassilo@member.fsf.org>
421 ;; Vagn Johansen <gonz808@hotmail.com>
422 ;; Mathias Dahl <mathias.dahl@gmail.com>
423 ;; Bill Clementson <billclem@gmail.com>
424 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
425 ;; Drew Adams <drew.adams@oracle.com>
426 ;; Jason McBrayer <jmcbray@carcosa.net>
427 ;; Andy Stewart <lazycat.manatee@gmail.com>
428 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
429 ;; rubikitch <rubikitch@ruby-lang.org>
430 ;; Scott Vokes <vokes.s@gmail.com>
433 ;;; For Maintainers:
435 ;; Evaluate (autodoc-update-all) before commit. This function
436 ;; generates anything-c-source-* / functions / options list.
438 ;; Install also developer-tools/autodoc.el
439 ;; And eval it or run interactively.
441 ;; [EVAL IT] (autodoc-update-all)
443 ;; Please write details documentation about function, then others will
444 ;; read code more easier. -- Andy Stewart
448 ;;; TODO
450 ;; - Fix documentation, now many functions haven't documentations.
453 ;;; Require
454 (require 'anything)
455 (require 'thingatpt)
456 (require 'ffap)
457 (require 'cl)
459 ;;; Code:
461 ;; version check
462 (let ((version "1.263"))
463 (when (and (string= "1." (substring version 0 2))
464 (string-match "1\.\\([0-9]+\\)" anything-version)
465 (< (string-to-number (match-string 1 anything-version))
466 (string-to-number (substring version 2))))
467 (error "Please update anything.el!!
469 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
471 or M-x install-elisp-from-emacswiki anything.el")))
473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
474 (defgroup anything-config nil
475 "Predefined configurations for `anything.el'."
476 :group 'anything)
478 (defcustom anything-c-use-standard-keys nil
479 "Whether use standard keybindings. (no effect)
481 Key definitions in anything-config.el are removed because
482 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
483 minibuffer history, C-s for isearch, etc.
485 If you use `iswitchb' with `anything',
486 evaluate (anything-iswitchb-setup) . Then some bindings that
487 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
488 history, are removed from `anything-map'. "
489 :type 'boolean
490 :group 'anything-config)
492 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
493 "Path of file where history information is stored."
494 :type 'string
495 :group 'anything-config)
497 (defcustom anything-c-adaptive-history-length 50
498 "Maximum number of candidates stored for a source."
499 :type 'number
500 :group 'anything-config)
502 (defcustom anything-c-google-suggest-url
503 "http://google.com/complete/search?output=toolbar&q="
504 "URL used for looking up Google suggestions."
505 :type 'string
506 :group 'anything-config)
508 (defcustom anything-c-google-suggest-search-url
509 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
510 "URL used for Google searching."
511 :type 'string
512 :group 'anything-config)
514 (defcustom anything-google-suggest-use-curl-p nil
515 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
516 Otherwise `url-retrieve-synchronously' is used."
517 :type 'boolean
518 :group 'anything-config)
520 (defcustom anything-c-yahoo-suggest-url
521 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
522 "Url used for looking up Yahoo suggestions."
523 :type 'string
524 :group 'anything-config)
526 (defcustom anything-c-yahoo-suggest-search-url
527 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
528 "Url used for Yahoo searching."
529 :type 'string
530 :group 'anything-config)
532 (defcustom anything-c-boring-buffer-regexp
533 (rx (or
534 (group bos " ")
535 ;; anything-buffer
536 "*anything"
537 ;; echo area
538 " *Echo Area" " *Minibuf"))
539 "The regexp that match boring buffers.
540 Buffer candidates matching this regular expression will be
541 filtered from the list of candidates if the
542 `anything-c-skip-boring-buffers' candidate transformer is used, or
543 they will be displayed with face `file-name-shadow' if
544 `anything-c-shadow-boring-buffers' is used."
545 :type 'string
546 :group 'anything-config)
547 ;; (string-match anything-c-boring-buffer-regexp "buf")
548 ;; (string-match anything-c-boring-buffer-regexp " hidden")
549 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
551 (defcustom anything-c-boring-file-regexp
552 (rx (or
553 ;; Boring directories
554 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
555 ;; Boring files
556 (and line-start ".#")
557 (and (or ".class" ".la" ".o" "~") eol)))
558 "The regexp that match boring files.
559 File candidates matching this regular expression will be
560 filtered from the list of candidates if the
561 `anything-c-skip-boring-files' candidate transformer is used, or
562 they will be displayed with face `file-name-shadow' if
563 `anything-c-shadow-boring-files' is used."
564 :type 'string
565 :group 'anything-config)
567 (defcustom anything-kill-ring-threshold 10
568 "*Minimum length to be listed by `anything-c-source-kill-ring'."
569 :type 'integer
570 :group 'anything-config)
572 (defcustom anything-su-or-sudo "su"
573 "What command to use for root access."
574 :type 'string
575 :group 'anything-config)
577 (defcustom anything-for-files-prefered-list '(anything-c-source-ffap-line
578 anything-c-source-ffap-guesser
579 anything-c-source-buffers+
580 anything-c-source-recentf
581 anything-c-source-bookmarks
582 anything-c-source-file-cache
583 anything-c-source-files-in-current-dir+
584 anything-c-source-locate)
585 "Your prefered sources to find files."
586 :type 'list
587 :group 'anything-config)
589 (defcustom anything-create--actions-private nil
590 "User defined actions for `anything-create' / `anything-c-source-create'.
591 It is a list of (DISPLAY . FUNCTION) pairs like `action'
592 attribute of `anything-sources'.
594 It is prepended to predefined pairs."
595 :type 'list
596 :group 'anything-config)
598 (defcustom anything-allow-skipping-current-buffer t
599 "Show current buffer or not in anything buffer"
600 :type 'boolean
601 :group 'anything-config)
603 (defcustom anything-c-enable-eval-defun-hack t
604 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
605 This hack is invoked when pressing C-M-x in the form \
606 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
607 :type 'boolean
608 :group 'anything-config)
610 (defcustom anything-tramp-verbose 0
611 "*Just like `tramp-verbose' but specific to anything.
612 When set to 0 don't show tramp messages in anything.
613 If you want to have the default tramp messages set it to 3."
614 :type 'integer
615 :group 'anything-config)
617 (defcustom anything-back-to-emacs-shell-command nil
618 "*A shell command to come back to Emacs after running externals programs.
619 Stumpwm users could use:
620 \"stumpish eval \"\(stumpwm::emacs\)\"\".
621 With others windows manager you could use:
622 \"wmctrl -xa emacs\"."
623 :type 'string
624 :group 'anything-config)
626 ;;; Documentation
627 ;; It is replaced by `anything-help'
628 (defun anything-c-describe-anything-bindings ()
629 "[OBSOLETE] Describe `anything' bindings."
630 (interactive)
631 (anything-run-after-quit
632 #'(lambda ()
633 (with-current-buffer (get-buffer-create "*Anything Help*")
634 (erase-buffer)
635 (insert
636 (substitute-command-keys
637 "The keys that are defined for `anything' are:
638 \\{anything-map}")))
639 (pop-to-buffer "*Anything Help*")
640 (goto-char (point-min)))))
642 ;; Use `describe-mode' key in `global-map'
643 ;; (dolist (k (where-is-internal 'describe-mode global-map))
644 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
646 ;;; Help message
647 (defun anything-c-list-preconfigured-anything ()
648 (loop with doc
649 with sym
650 for entry in (cdr (assoc
651 (file-truename (locate-library "anything-config"))
652 load-history))
653 if (and (consp entry)
654 (eq (car entry) 'defun)
655 (string-match "^Preconfigured.+$"
656 (setq doc (or (documentation (setq sym (cdr entry)))
657 ""))))
658 collect (cons sym (match-string 0 doc))))
660 (defun anything-c-format-preconfigured-anything ()
661 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
662 (anything-c-list-preconfigured-anything)))
664 (setq anything-help-message
665 (lambda ()
666 (concat
667 "\\<anything-map>"
668 "`anything' is QuickSilver-like candidate-selection framework.
670 Narrow the list by typing some pattern,
671 Multiple patterns are allowed by splitting by space.
672 Select with natural Emacs operations, choose with RET.
674 If you have any problems, press C-c C-x C-b!!
675 Feel free to send bug reports. I'll fix them.
676 The steps are described in the beginning of anything.el file.
678 == Basic Operations ==
679 C-p, Up: Previous Line
680 C-n, Down : Next Line
681 M-v, PageUp : Previous Page
682 C-v, PageDown : Next Page
683 Enter : Execute first (default) action / Select
684 M-< : First Line
685 M-> : Last Line
686 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
687 M-PageDown, C-M-v : Next Page (other-window)
689 Tab, C-i : Show action list
690 Left : Previous Source
691 Right, C-o : Next Source
692 C-k : Delete pattern
693 C-z : Persistent Action (Execute action with anything session kept)
694 C-c C-x C-b: Send a bug report
696 == Shortcuts For 2nd/3rd Action ==
697 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
698 \\[anything-select-3rd-action] : Execute 3rd Action
700 == Visible Marks ==
701 Visible marks store candidate. Some actions uses marked candidates.
703 \\[anything-toggle-visible-mark] : Toggle Visible Mark
704 \\[anything-prev-visible-mark] : Previous Mark
705 \\[anything-next-visible-mark] : Next Mark
707 == Miscellaneous Commands ==
708 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
709 \\[anything-quit-and-find-file] : Drop into `find-file'
710 \\[anything-delete-current-selection] : Delete Selected Item (visually)
711 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
712 \\[anything-yank-selection] : Yank Selected Item Into Pattern
713 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
714 \\[anything-force-update] : Recalculate And Redisplay Candidates
716 == Global Commands ==
717 \\<global-map>\\[anything-resume] revives last `anything' session.
718 It is very useful, so you should bind any key.
720 Single source is executed by \\[anything-call-source].
722 == Preconfigured `anything' ==
723 Preconfigured `anything' is commands that uses `anything' interface.
724 You can use them without configuration.
727 (apply 'concat (anything-c-format-preconfigured-anything))
729 Enjoy!")))
731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
732 ;;;###autoload
733 (defun anything-mini ()
734 "Preconfigured `anything' lightweight version (buffer -> recentf)."
735 (interactive)
736 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf)
737 "*anything mini*"))
738 ;;;###autoload
739 (defun anything-for-files ()
740 "Preconfigured `anything' for opening files.
741 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
742 (interactive)
743 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
745 ;;;###autoload
746 (defun anything-recentf ()
747 "Preconfigured `anything' for `recentf'."
748 (interactive)
749 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
750 ;;;###autoload
751 (defun anything-info-at-point ()
752 "Preconfigured `anything' for searching info at point."
753 (interactive)
754 (anything '(anything-c-source-info-elisp
755 anything-c-source-info-cl
756 anything-c-source-info-pages)
757 (thing-at-point 'symbol) nil nil nil "*anything info*"))
759 ;;;###autoload
760 (defun anything-show-kill-ring ()
761 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
762 You may bind this command to M-y."
763 (interactive)
764 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
766 ;;;###autoload
767 (defun anything-minibuffer-history ()
768 "Preconfigured `anything' for `minibuffer-history'."
769 (interactive)
770 (let ((enable-recursive-minibuffers t))
771 (anything-other-buffer 'anything-c-source-minibuffer-history
772 "*anything minibuffer-history*")))
774 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
775 ;; minibuffer-local-filename-must-match-map.
776 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
777 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
778 (dolist (map (list minibuffer-local-filename-completion-map
779 minibuffer-local-completion-map
780 minibuffer-local-must-match-filename-map
781 minibuffer-local-filename-must-match-map
782 minibuffer-local-map
783 minibuffer-local-isearch-map
784 minibuffer-local-must-match-map
785 minibuffer-local-ns-map))
786 (define-key map "\C-r" 'anything-minibuffer-history))
788 ;;;###autoload
789 (defun anything-gentoo ()
790 "Preconfigured `anything' for gentoo linux."
791 (interactive)
792 (anything-other-buffer '(anything-c-source-gentoo
793 anything-c-source-use-flags)
794 "*anything gentoo*"))
796 ;;;###autoload
797 (defun anything-surfraw-only ()
798 "Preconfigured `anything' for surfraw.
799 If region is marked set anything-pattern to region.
800 With one prefix arg search symbol at point.
801 With two prefix args allow choosing in which symbol to search."
802 (interactive)
803 (let (search pattern)
804 (cond ((region-active-p)
805 (setq pattern (buffer-substring (region-beginning) (region-end))))
806 ((equal current-prefix-arg '(4))
807 (setq pattern (thing-at-point 'symbol)))
808 ((equal current-prefix-arg '(16))
809 (setq search
810 (intern
811 (completing-read "Search in: "
812 (list "symbol" "sentence" "sexp" "line" "word"))))
813 (setq pattern (thing-at-point search))))
814 (anything 'anything-c-source-surfraw
815 (and pattern (replace-regexp-in-string "\n" "" pattern))
816 nil nil nil "*anything surfraw*")))
818 ;;;###autoload
819 (defun anything-imenu ()
820 "Preconfigured `anything' for `imenu'."
821 (interactive)
822 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
824 ;;;###autoload
825 (defun anything-google-suggest ()
826 "Preconfigured `anything' for google search with google suggest."
827 (interactive)
828 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
830 ;;;###autoload
831 (defun anything-yahoo-suggest ()
832 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
833 (interactive)
834 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
836 ;;; Converted from anything-show-*-only
837 ;;;###autoload
838 (defun anything-for-buffers ()
839 "Preconfigured `anything' for buffer."
840 (interactive)
841 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
843 ;;;###autoload
844 (defun anything-bbdb ()
845 "Preconfigured `anything' for BBDB."
846 (interactive)
847 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
849 ;;;###autoload
850 (defun anything-locate ()
851 "Preconfigured `anything' for Locate.
852 Note you can add locate command after entering pattern.
853 See man locate for more infos."
854 (interactive)
855 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
857 ;;;###autoload
858 (defun anything-w3m-bookmarks ()
859 "Preconfigured `anything' for w3m bookmark."
860 (interactive)
861 (anything-other-buffer 'anything-c-source-w3m-bookmarks "*anything w3m bookmarks*"))
863 ;;;###autoload
864 (defun anything-colors ()
865 "Preconfigured `anything' for color."
866 (interactive)
867 (anything-other-buffer '(anything-c-source-colors anything-c-source-customize-face)
868 "*anything colors*"))
870 ;;;###autoload
871 (defun anything-bm-list ()
872 "Preconfigured `anything' for visible bookmarks."
873 (interactive)
874 (let ((anything-outline-using t))
875 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
877 ;;;###autoload
878 (defun anything-timers ()
879 "Preconfigured `anything' for timers."
880 (interactive)
881 (anything-other-buffer '(anything-c-source-absolute-time-timers
882 anything-c-source-idle-time-timers)
883 "*anything timers*"))
885 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
886 ;;; kill buffers
887 ;;;###autoload
888 (defun anything-kill-buffers ()
889 "Preconfigured `anything' to kill buffer you selected."
890 (interactive)
891 (anything
892 '(((name . "Kill Buffers")
893 (candidates . anything-c-buffer-list)
894 (action
895 ("Kill Buffer" . (lambda (candidate)
896 (kill-buffer candidate)
897 (anything-kill-buffers)
898 )))))
899 nil nil))
901 ;;; Regexp
902 ;;;###autoload
903 (defun anything-query-replace-regexp (&rest args)
904 "Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually."
905 (interactive
906 (let ((common
907 (anything-c-regexp-base "Query Replace Regexp: "
908 '((name . "Lines matching Regexp")
909 (mode-line . "Set replace start line and type RET.")
910 (action . anything-c-query-replace-args)))))
911 (if (not common)
912 (keyboard-quit))
913 (list (car common) (cadr common) (caddr common)
914 ;; These are done separately here
915 ;; so that command-history will record these expressions
916 ;; rather than the values they had this time.
918 ;; This idea is borrowed from original `query-replace-regexp'.
919 (if (and transient-mark-mode mark-active)
920 (region-beginning))
921 (if (and transient-mark-mode mark-active)
922 (region-end)))))
923 (apply 'query-replace-regexp args))
925 ;;;###autoload
926 (defun anything-regexp ()
927 "Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement."
928 (interactive)
929 (anything-c-regexp-base
930 "Regexp: "
931 '((name . "Regexp Builder")
932 (mode-line . "Press TAB to select action.")
933 (action
934 ("Kill Regexp as sexp" .
935 (lambda (x) (anything-c-regexp-kill-new (prin1-to-string (funcall (anything-attr 'regexp))))))
936 ("Query Replace Regexp" .
937 (lambda (x) (apply 'query-replace-regexp (anything-c-query-replace-args (point)))))
938 ("Kill Regexp" .
939 (lambda (x) (anything-c-regexp-kill-new (funcall (anything-attr 'regexp)))))))))
941 (defun anything-c-query-replace-args (start-point)
942 ;; create arguments of `query-replace-regexp'.
943 (let ((region-only (and transient-mark-mode mark-active))
944 (regexp (funcall (anything-attr 'regexp))))
945 (list
946 regexp
947 (query-replace-read-to regexp
948 (format "Query replace regexp %s%s%s with: "
949 (if region-only "in region " "")
950 regexp
951 (if current-prefix-arg "(word) " ""))
953 current-prefix-arg)))
955 (defun anything-c-regexp-get-line (s e)
956 (propertize
957 (apply 'concat
958 ;; Line contents
959 (format "%5d: %s" (line-number-at-pos s) (buffer-substring s e))
960 ;; subexps
961 (loop for i from 0 to (1- (/ (length (match-data)) 2))
962 unless (zerop i)
963 collect (format "\n $%d = %s"
964 i (match-string i))))
965 ;; match beginning
966 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
967 ;; It is implementation problem of candidates-in-buffer.
968 'anything-realvalue
969 (1- s)))
971 ;; Shut up byte compiler
972 (defun anything-goto-line (numline)
973 "Replacement of `goto-line'."
974 (goto-char (point-min))
975 (forward-line (1- numline)))
977 (defun anything-c-regexp-persistent-action (pt)
978 (goto-char pt)
979 (anything-persistent-highlight-point))
981 (defun anything-c-regexp-base (prompt attributes)
982 (save-restriction
983 (let ((anything-compile-source-functions
984 ;; rule out anything-match-plugin because the input is one regexp.
985 (delq 'anything-compile-source--match-plugin
986 (copy-sequence anything-compile-source-functions)))
987 (base-attributes
988 '((init . (lambda () (anything-candidate-buffer anything-current-buffer)))
989 (candidates-in-buffer)
990 (get-line . anything-c-regexp-get-line)
991 (persistent-action . anything-c-regexp-persistent-action)
992 (persistent-help . "Show this line")
993 (multiline)
994 (delayed))))
995 (if (and transient-mark-mode mark-active)
996 (narrow-to-region (region-beginning) (region-end)))
997 (anything
998 (list
999 (append
1000 attributes
1001 '((regexp . (lambda () anything-pattern)))
1002 base-attributes)
1003 ;; sexp form regexp
1004 (append
1005 `((name . ,(concat (assoc-default 'name attributes) " (sexp)")))
1006 attributes
1007 '((candidates-in-buffer
1008 . (lambda () (let ((anything-pattern (eval (read anything-pattern))))
1009 (anything-candidates-in-buffer))))
1010 (regexp . (lambda () (eval (read anything-pattern)))))
1011 base-attributes))
1012 nil prompt nil nil "*anything regexp*"))))
1014 ;; (anything-c-regexp-base "Regexp: " '((name . "test")))
1015 ;; (anything-c-regexp-base "Regexp: " '((name . "test") (candidates-in-buffer . (lambda () (let ((anything-pattern (eval (read anything-pattern)))) (anything-candidates-in-buffer))))))
1017 (defun anything-c-regexp-kill-new (input)
1018 (kill-new input)
1019 (message "Killed: %s" input))
1021 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1023 (defun anything-insert-buffer-name ()
1024 "Insert buffer name."
1025 (interactive)
1026 (anything-insert-string
1027 (with-current-buffer anything-current-buffer
1028 (if buffer-file-name (file-name-nondirectory buffer-file-name)
1029 (buffer-name)))))
1031 (defun anything-insert-symbol ()
1032 "Insert current symbol."
1033 (interactive)
1034 (anything-insert-string
1035 (with-current-buffer anything-current-buffer
1036 (save-excursion
1037 (buffer-substring (beginning-of-thing 'symbol)
1038 (end-of-thing 'symbol))))))
1040 (defun anything-insert-selection ()
1041 "Insert current selection."
1042 (interactive)
1043 (anything-insert-string
1044 (with-current-buffer anything-current-buffer
1045 (anything-get-selection))))
1047 (defun anything-show-buffer-only ()
1048 "[OBSOLETE] Only show sources about buffer.
1049 Use `anything-for-buffers' instead."
1050 (interactive)
1051 (anything-set-source-filter '("Buffers")))
1053 (defun anything-show-bbdb-only ()
1054 "[OBSOLETE] Only show sources about BBDB.
1055 Use `anything-bbdb' instead."
1056 (interactive)
1057 (anything-set-source-filter '("BBDB")))
1059 (defun anything-show-locate-only ()
1060 "[OBSOLETE] Only show sources about Locate.
1061 Use `anything-locate' instead."
1062 (interactive)
1063 (anything-set-source-filter '("Locate")))
1065 (defun anything-show-info-only ()
1066 "[OBSOLETE] Only show sources about Info.
1067 Use `anything-info-at-point' instead."
1068 (interactive)
1069 (anything-set-source-filter '("Info Pages"
1070 "Info Elisp"
1071 "Info Common-Lisp")))
1073 (defun anything-show-imenu-only ()
1074 "[OBSOLETE] Only show sources about Imenu.
1075 Use `anything-imenu' instead."
1076 (interactive)
1077 (anything-set-source-filter '("Imenu")))
1079 (defun anything-show-files-only ()
1080 "[OBSOLETE] Only show sources about File.
1081 Use `anything-for-files' instead."
1082 (interactive)
1083 (anything-set-source-filter '("File Name History"
1084 "Files from Current Directory"
1085 "Recentf")))
1087 (defun anything-show-w3m-bookmarks-only ()
1088 "[OBSOLETE] Only show source about w3m bookmark.
1089 Use `anything-w3m-bookmarks' instead."
1090 (interactive)
1091 (anything-set-source-filter '("W3m Bookmarks")))
1093 (defun anything-show-colors-only ()
1094 "[OBSOLETE] Only show source about color.
1095 Use `anything-colors' instead."
1096 (interactive)
1097 (anything-set-source-filter '("Colors"
1098 "Customize Faces")))
1100 (defun anything-show-kill-ring-only ()
1101 "[OBSOLETE] Only show source about kill ring.
1102 Use `anything-show-kill-ring' instead."
1103 (interactive)
1104 (anything-set-source-filter '("Kill Ring")))
1106 (defun anything-show-this-source-only ()
1107 "Only show this source."
1108 (interactive)
1109 (setq anything-candidate-number-limit 9999)
1110 (anything-set-source-filter
1111 (list (assoc-default 'name (anything-get-current-source)))))
1113 (defun anything-test-sources ()
1114 "List all anything sources for test.
1115 The output is sexps which are evaluated by \\[eval-last-sexp]."
1116 (interactive)
1117 (with-output-to-temp-buffer "*Anything Test Sources*"
1118 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
1119 (apropos-internal "^anything-c-source" #'boundp))
1120 (pop-to-buffer standard-output)))
1122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1123 ;;; For compatibility
1124 (unless (fboundp 'region-active-p)
1125 (defun region-active-p ()
1126 "Return t if Transient Mark mode is enabled and the mark is active.
1128 Most commands that act on the region if it is active and
1129 Transient Mark mode is enabled, and on the text near point
1130 otherwise, should use `use-region-p' instead. That function
1131 checks the value of `use-empty-active-region' as well."
1132 (and transient-mark-mode mark-active)))
1134 (defun anything-nest (&rest same-as-anything)
1135 "Nested `anything'. If you use `anything' within `anything', use it."
1136 (with-selected-window (anything-window)
1137 (let (anything-current-position
1138 anything-current-buffer
1139 (orig-anything-buffer anything-buffer)
1140 anything-pattern
1141 anything-buffer
1142 anything-sources
1143 anything-compiled-sources
1144 anything-buffer-chars-modified-tick
1145 (anything-samewindow t)
1146 (enable-recursive-minibuffers t))
1147 (unwind-protect
1148 (apply #'anything same-as-anything)
1149 (anything-initialize-overlays orig-anything-buffer)
1150 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
1152 (defun anything-displaying-source-names ()
1153 "Display sources name."
1154 (with-current-buffer anything-buffer
1155 (goto-char (point-min))
1156 (loop with pos
1157 while (setq pos (next-single-property-change (point) 'anything-header))
1158 do (goto-char pos)
1159 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1160 do (forward-line 1))))
1162 (defun anything-select-source ()
1163 "Select source."
1164 (interactive)
1165 (let ((default (assoc-default 'name (anything-get-current-source)))
1166 (source-names (anything-displaying-source-names))
1167 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
1168 (anything-get-sources))))
1169 (setq anything-candidate-number-limit 9999)
1170 (anything-aif
1171 (let (anything-source-filter)
1172 (anything-nest '(((name . "Anything Source")
1173 (candidates . source-names)
1174 (action . identity))
1175 ((name . "Anything Source (ALL)")
1176 (candidates . all-source-names)
1177 (action . identity)))
1178 nil "Source: " nil
1179 default "*anything select source*"))
1180 (anything-set-source-filter (list it))
1181 (anything-set-source-filter nil))))
1183 (defun anything-insert-string (str)
1184 "Insert STR."
1185 (delete-minibuffer-contents)
1186 (insert str))
1188 (defun anything-c-match-on-file-name (candidate)
1189 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1190 (string-match anything-pattern (file-name-nondirectory candidate)))
1192 (defun anything-c-match-on-directory-name (candidate)
1193 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1194 (anything-aif (file-name-directory candidate)
1195 (string-match anything-pattern it)))
1197 (defun anything-c-string-match (candidate)
1198 "Return non-nil if `anything-pattern' match CANDIDATE.
1199 The match is done with `string-match'."
1200 (string-match anything-pattern candidate))
1202 ;; `anything-c-compose' is no more needed, it is for compatibility.
1203 (defalias 'anything-c-compose 'anything-compose)
1205 (defun anything-c-skip-entries (list regexp)
1206 "Remove entries which matches REGEXP from LIST."
1207 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
1208 list))
1210 (defun anything-c-shadow-entries (list regexp)
1211 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1212 (mapcar (lambda (file)
1213 ;; Add shadow face property to boring files.
1214 (let ((face (if (facep 'file-name-shadow)
1215 'file-name-shadow
1216 ;; fall back to default on XEmacs
1217 'default)))
1218 (if (string-match regexp file)
1219 (setq file (propertize file 'face face))))
1220 file)
1221 list))
1223 (defsubst anything-c-stringify (str-or-sym)
1224 "Get string of STR-OR-SYM."
1225 (if (stringp str-or-sym)
1226 str-or-sym
1227 (symbol-name str-or-sym)))
1229 (defsubst anything-c-symbolify (str-or-sym)
1230 "Get symbol of STR-OR-SYM."
1231 (if (symbolp str-or-sym)
1232 str-or-sym
1233 (intern str-or-sym)))
1235 (defun anything-c-describe-function (func)
1236 "FUNC is symbol or string."
1237 (describe-function (anything-c-symbolify func)))
1239 (defun anything-c-describe-variable (var)
1240 "VAR is symbol or string."
1241 (describe-variable (anything-c-symbolify var)))
1243 (defun anything-c-find-function (func)
1244 "FUNC is symbol or string."
1245 (find-function (anything-c-symbolify func)))
1247 (defun anything-c-find-variable (var)
1248 "VAR is symbol or string."
1249 (find-variable (anything-c-symbolify var)))
1251 (defun anything-c-kill-new (string &optional replace yank-handler)
1252 "STRING is symbol or string."
1253 (kill-new (anything-c-stringify string) replace yank-handler))
1255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1256 ;; TODO
1257 (defvar anything-current-prefix-arg nil
1258 "`current-prefix-arg' when selecting action.
1259 It is cleared after executing action.")
1261 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
1262 (unless anything-current-prefix-arg
1263 (setq anything-current-prefix-arg current-prefix-arg)))
1265 (add-hook 'anything-after-action-hook
1266 (lambda () (setq anything-current-prefix-arg nil)))
1269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1270 (defadvice eval-defun (after anything-source-hack activate)
1271 "See `anything-c-enable-eval-defun-hack'."
1272 (when anything-c-enable-eval-defun-hack
1273 (let ((varsym (save-excursion
1274 (beginning-of-defun)
1275 (forward-char 1)
1276 (when (memq (read (current-buffer)) '(defvar setq))
1277 (read (current-buffer))))))
1278 (when (string-match "^anything-c-source-" (symbol-name varsym))
1279 (anything varsym)))))
1280 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1283 (defun anything-c-create-summary ()
1284 "Create `anything' summary."
1285 (save-excursion
1286 (goto-char (point-min))
1287 (loop while (re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$" nil t)
1288 collect (cond ((match-beginning 1)
1289 (cons 'section (match-string-no-properties 1)))
1290 ((match-beginning 2)
1291 (cons 'source
1292 (cons (match-string-no-properties 2)
1293 (assoc-default 'name (symbol-value (intern (match-string-no-properties 2)))))))
1294 ((match-beginning 3)
1295 (cons 'source
1296 (cons (match-string-no-properties 3)
1297 (assoc-default 'name (symbol-value (intern (match-string-no-properties 3)))))))))))
1299 ;; (find-epp (anything-c-create-summary))
1301 (defun anything-c-insert-summary ()
1302 "Insert `anything' summary."
1303 (save-excursion
1304 (goto-char (point-min))
1305 (search-forward ";; Below are complete source list you can setup in")
1306 (forward-line 1)
1307 (delete-region (point)
1308 (progn (search-forward ";;; Change log:" nil t)
1309 (forward-line -1) (point)))
1310 (insert ";;\n")
1311 (loop with beg
1312 for (kind . value) in (anything-c-create-summary)
1313 for i from 0
1314 do (cond ((eq kind 'section)
1315 (unless (zerop i)
1316 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1317 (insert ";; " value ":\n")
1318 (setq beg (point)))
1320 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
1321 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
1322 ;; (anything-c-insert-summary)
1324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1325 ;;;; <Buffer>
1326 (defun anything-c-buffer-list ()
1327 "Return the list of names of buffers with boring buffers filtered out.
1328 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1329 The first buffer in the list will be the last recently used
1330 buffer that is not the current buffer."
1331 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1332 (append (cdr buffers) (list (car buffers)))))
1334 (defvar anything-c-source-buffers
1335 '((name . "Buffers")
1336 (candidates . anything-c-buffer-list)
1337 (type . buffer)))
1338 ;; (anything 'anything-c-source-buffers)
1340 (defvar anything-c-source-buffer-not-found
1341 '((name . "Create buffer")
1342 (dummy)
1343 (type . buffer)))
1344 ;; (anything 'anything-c-source-buffer-not-found)
1346 ;;; Buffers+
1347 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1348 "*Face used for directory headings in dired buffers."
1349 :group 'anything)
1351 (defface anything-file-name
1352 '((t (:foreground "Blue")))
1353 "*Face used for file names (without suffixes) in dired buffers."
1354 :group 'anything)
1356 (defface anything-dir-priv
1357 '((t (:foreground "DarkRed" :background "LightGray")))
1358 "*Face used for directory privilege indicator (d) in dired buffers."
1359 :group 'anything)
1361 (defvar anything-c-buffers-face1 'anything-dir-priv)
1362 (defvar anything-c-buffers-face2 'font-lock-type-face)
1363 (defvar anything-c-buffers-face3 'italic)
1364 (eval-when-compile (require 'dired))
1365 (defun anything-c-highlight-buffers (buffers)
1366 (require 'dired)
1367 (loop for i in buffers
1368 if (rassoc (get-buffer i) dired-buffers)
1369 collect (propertize i
1370 'face anything-c-buffers-face1
1371 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1372 if (buffer-file-name (get-buffer i))
1373 collect (propertize i
1374 'face anything-c-buffers-face2
1375 'help-echo (buffer-file-name (get-buffer i)))
1376 if (and (not (rassoc (get-buffer i) dired-buffers))
1377 (not (buffer-file-name (get-buffer i))))
1378 collect (propertize i
1379 'face anything-c-buffers-face3)))
1381 (defvar anything-c-source-buffers+
1382 '((name . "Buffers")
1383 (candidates . anything-c-buffer-list)
1384 (type . buffer)
1385 (candidate-transformer anything-c-skip-current-buffer
1386 anything-c-highlight-buffers
1387 anything-c-skip-boring-buffers)
1388 (persistent-action . anything-c-buffers+-persistent-action)
1389 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1391 (defun anything-c-buffers+-persistent-action (name)
1392 (flet ((kill (item)
1393 (with-current-buffer item
1394 (if (and (buffer-modified-p)
1395 (buffer-file-name (current-buffer)))
1396 (progn
1397 (save-buffer)
1398 (kill-buffer item))
1399 (kill-buffer item))))
1400 (goto (item)
1401 (switch-to-buffer item)))
1402 (if current-prefix-arg
1403 (progn
1404 (kill name)
1405 (anything-delete-current-selection))
1406 (goto name))))
1408 ;; (anything 'anything-c-source-buffers+)
1411 ;;;; <File>
1412 ;;; File name history
1413 (defvar anything-c-source-file-name-history
1414 '((name . "File Name History")
1415 (candidates . file-name-history)
1416 (match anything-c-match-on-file-name
1417 anything-c-match-on-directory-name)
1418 (type . file)))
1419 ;; (anything 'anything-c-source-file-name-history)
1421 ;;; Files in current dir
1422 (defvar anything-c-source-files-in-current-dir
1423 '((name . "Files from Current Directory")
1424 (candidates . (lambda ()
1425 (with-current-buffer anything-current-buffer
1426 (directory-files default-directory))))
1427 ;; volatile is not needed, I think.
1428 (type . file)))
1429 ;; (anything 'anything-c-source-files-in-current-dir)
1431 (defvar anything-c-files-face1 'anything-dir-priv)
1432 (defvar anything-c-files-face2 'anything-file-name)
1433 (defun anything-c-highlight-files (files)
1434 (loop for i in files
1435 if (file-directory-p i)
1436 collect (propertize (file-name-nondirectory i)
1437 'face anything-c-files-face1
1438 'help-echo (expand-file-name i))
1439 else
1440 collect (propertize (file-name-nondirectory i)
1441 'face anything-c-files-face2
1442 'help-echo (expand-file-name i))))
1445 (defvar anything-c-source-files-in-current-dir+
1446 '((name . "Files from Current Directory")
1447 (candidates . (lambda ()
1448 (with-current-buffer anything-current-buffer
1449 (directory-files default-directory t))))
1450 (candidate-transformer anything-c-highlight-files)
1451 ;; volatile is not needed, I think.
1452 (type . file)))
1454 ;; (anything 'anything-c-source-files-in-current-dir+)
1456 ;;; Anything replacement of file name completion for `find-file' and friends.
1458 (defvar anything-c-find-files-doc-header (format " (`%s':Go to precedent level)"
1459 (if window-system "C-." "C-l"))
1460 "*The doc that is inserted in the Name header of a find-files or dired source.")
1462 (defvar anything-c-source-find-files
1463 `((name . ,(concat "Find Files" anything-c-find-files-doc-header))
1464 ;; It is needed for filenames with capital letters
1465 (disable-shortcuts)
1466 (init . (lambda ()
1467 (setq ffap-newfile-prompt t)))
1468 (candidates . anything-find-files-get-candidates)
1469 (candidate-transformer anything-c-highlight-ffiles)
1470 (persistent-action . anything-find-files-persistent-action)
1471 (persistent-help . "Expand Candidate")
1472 (volatile)
1473 (action
1474 . ,(delq
1476 `(("Find File" . find-file-at-point)
1477 ("Find file in Dired" . anything-c-point-file-in-dired)
1478 ,(and (locate-library "elscreen")
1479 '("Find file in Elscreen" . anything-elscreen-find-file))
1480 ("Complete at point"
1481 . anything-c-insert-file-name-completion-at-point)
1482 ("Delete File(s)" . anything-delete-marked-files)
1483 ("Find file as root" . anything-find-file-as-root)
1484 ("Open file externally (C-u to choose)"
1485 . anything-c-open-file-externally)
1486 ("Find file other window" . find-file-other-window)
1487 ("Find file other frame" . find-file-other-frame))))))
1489 ;; (anything 'anything-c-source-find-files)
1491 (defun* anything-reduce-file-name (fname level &key unix-close expand)
1492 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1493 If LEVEL is positive reduce from end else from beginning.
1494 If UNIX-CLOSE is non--nil close filename with /.
1495 If EXPAND is non--nil expand-file-name."
1496 (let* ((exp-fname (expand-file-name fname))
1497 (fname-list (split-string (if (or (string= fname "~/") expand)
1498 exp-fname fname) "/" t))
1499 (len (length fname-list))
1500 (pop-list (if (< level 0)
1501 (subseq fname-list (* level -1))
1502 (subseq fname-list 0 (- len level))))
1503 (result (mapconcat 'identity pop-list "/"))
1504 (empty (string= result "")))
1505 (when unix-close (setq result (concat result "/")))
1506 (if (string-match "^~" result)
1507 (if (string= result "~/") "~/" result)
1508 (if (< level 0)
1509 (if empty "../" (concat "../" result))
1510 (cond ((and (eq system-type 'windows-nt) empty)
1511 "c:/")
1512 ((and (not empty) (eq system-type 'windows-nt))
1513 result)
1514 (empty "/")
1516 (concat "/" result)))))))
1518 (defun anything-file-completion-source-p ()
1519 "Test if current source is a dired or find-files source."
1520 (let ((ff-sources '("Find Files" "Copy Files"
1521 "Rename Files" "Symlink Files"
1522 "Hardlink Files" "Write File"
1523 "Insert File" "Read file name"))
1524 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
1525 (catch 'break
1526 (dolist (i ff-sources)
1527 (when (equal cur-source (concat i anything-c-find-files-doc-header))
1528 (throw 'break t))))))
1530 (defun anything-find-files-down-one-level (arg)
1531 "Go down one level like unix command `cd ..'.
1532 If prefix numeric arg is given go ARG level down."
1533 (interactive "p")
1534 (when (anything-file-completion-source-p)
1535 (let ((new-pattern (anything-reduce-file-name anything-pattern arg :unix-close t :expand t)))
1536 (with-selected-window (minibuffer-window)
1537 (delete-minibuffer-contents)
1538 (insert new-pattern)))))
1540 ;; `C-.' doesn't work in terms use `C-l' instead.
1541 (if window-system
1542 (define-key anything-map (kbd "C-.") 'anything-find-files-down-one-level)
1543 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))
1545 (defun anything-c-point-file-in-dired (file)
1546 "Put point on filename FILE in dired buffer."
1547 (dired (file-name-directory file))
1548 (dired-goto-file file))
1550 (defun anything-create-tramp-name (fname)
1551 "Build filename for `anything-pattern' like /su:: or /sudo::."
1552 (apply #'tramp-make-tramp-file-name
1553 (loop
1554 with v = (tramp-dissect-file-name fname)
1555 for i across v collect i)))
1557 (defun anything-find-files-get-candidates ()
1558 "Create candidate list for `anything-c-source-find-files'."
1559 (let* ( ; Don't try to tramp connect before entering the second ":".
1560 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1561 (path (cond ((string-match "^~" anything-pattern)
1562 (replace-match (getenv "HOME") nil t anything-pattern))
1563 ((string-match tramp-file-name-regexp anything-pattern)
1564 (let ((tramp-name (anything-create-tramp-name
1565 (match-string 0 anything-pattern))))
1566 (replace-match tramp-name nil t anything-pattern)))
1567 (t anything-pattern)))
1568 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
1569 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1570 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1571 ;; and sorting.
1572 (flet ((tramp-handle-directory-files
1573 (directory &optional full match nosort files-only)
1574 "Like `directory-files' for Tramp files."
1575 ;; FILES-ONLY is valid for XEmacs only.
1576 (when (file-directory-p directory)
1577 (setq directory (file-name-as-directory (expand-file-name directory)))
1578 (let ((temp (nreverse (file-name-all-completions "" directory)))
1579 result item)
1581 (while temp
1582 (setq item (directory-file-name (pop temp)))
1583 (when (and (or (null match) (string-match match item))
1584 (or (null files-only)
1585 ;; Files only.
1586 (and (equal files-only t) (file-regular-p item))
1587 ;; Directories only.
1588 (file-directory-p item)))
1589 (push (if full (concat directory item) item)
1590 result)))
1591 (if nosort result (sort result 'string<))))))
1593 (set-text-properties 0 (length path) nil path)
1594 (setq anything-pattern path)
1595 (cond ((or (file-regular-p path)
1596 (and ffap-url-regexp (string-match ffap-url-regexp path)))
1597 (list path))
1598 ((string= anything-pattern "") (directory-files "/" t))
1599 ((file-directory-p path) (directory-files path t))
1601 (append
1602 (list path)
1603 (directory-files (file-name-directory path) t)))))))
1605 (defface anything-dired-symlink-face
1606 '((t (:foreground "DarkOrange")))
1607 "*Face used for symlinks in `anything-find-files'."
1608 :group 'anything)
1610 (defun anything-c-highlight-ffiles (files)
1611 "Candidate transformer for `anything-c-source-find-files'."
1612 (loop for i in files
1613 if (file-symlink-p i)
1614 collect (propertize i 'face 'anything-dired-symlink-face
1615 'help-echo (file-truename i)) into a
1616 if (file-directory-p i)
1617 collect (propertize i 'face anything-c-files-face1) into a
1618 else
1619 collect (propertize i 'face anything-c-files-face2) into a
1620 finally return a))
1623 (defun anything-find-files-persistent-action (candidate)
1624 "Open subtree CANDIDATE without quitting anything.
1625 If CANDIDATE is not a directory expand CANDIDATE filename.
1626 If CANDIDATE is alone, open file CANDIDATE filename."
1627 (flet ((insert-in-minibuffer (elm)
1628 (with-selected-window (minibuffer-window)
1629 (delete-minibuffer-contents)
1630 (set-text-properties 0 (length elm) nil elm)
1631 (insert elm))))
1632 (cond ((and (file-directory-p candidate) (file-symlink-p candidate))
1633 (insert-in-minibuffer (file-name-as-directory
1634 (file-truename
1635 (expand-file-name candidate)))))
1636 ((file-directory-p candidate)
1637 (insert-in-minibuffer (file-name-as-directory
1638 (expand-file-name candidate))))
1639 ((file-symlink-p candidate)
1640 (insert-in-minibuffer (file-truename candidate)))
1641 (t ; First hit on C-z expand CANDIDATE second hit open file.
1642 (let ((new-pattern (anything-get-selection anything-last-buffer))
1643 (num-lines-buf (with-current-buffer anything-last-buffer
1644 (count-lines (point-min) (point-max)))))
1645 (if (> num-lines-buf 3)
1646 (insert-in-minibuffer new-pattern) (find-file candidate)))))))
1648 (defun anything-c-insert-file-name-completion-at-point (candidate)
1649 "Insert file name completion at point."
1650 (let* ((end (point))
1651 (guess (thing-at-point 'filename))
1652 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess)
1653 (string-match "^[^\~]" guess))))
1654 (set-text-properties 0 (length candidate) nil candidate)
1655 (when (and guess (not (string= guess "")))
1656 (search-backward guess (- (point) (length guess)))
1657 (delete-region (point) end)
1658 (if full-path-p
1659 (insert (expand-file-name candidate))
1660 (insert (abbreviate-file-name candidate))))))
1662 ;;;###autoload
1663 (defun anything-find-files ()
1664 "Preconfigured `anything' for anything implementation of `find-file'."
1665 (interactive)
1666 (anything 'anything-c-source-find-files
1667 (anything-find-files-input (ffap-guesser)
1668 (thing-at-point 'filename))
1669 "Find Files or Url: " nil nil "*Anything Find Files*"))
1671 (defun anything-find-files-input (fap tap)
1672 "Default input of `anything-find-files'."
1673 (let* ((def-dir (if (eq major-mode 'dired-mode)
1674 (dired-current-directory)
1675 default-directory))
1676 (file-p (and fap (file-exists-p fap)
1677 (file-exists-p
1678 (file-name-directory (expand-file-name tap def-dir)))))
1679 (input (if file-p (expand-file-name tap def-dir) fap)))
1680 (or input (expand-file-name def-dir))))
1682 ;;; Anything completion for `write-file'.==> C-x C-w
1683 (defvar anything-c-source-write-file
1684 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
1685 ;; It is needed for filenames with capital letters
1686 (disable-shortcuts)
1687 (candidates . anything-find-files-get-candidates)
1688 (candidate-transformer anything-c-highlight-ffiles)
1689 (persistent-action . anything-find-files-persistent-action)
1690 (persistent-help . "Expand Candidate")
1691 (volatile)
1692 (action .
1693 (("Write File" . (lambda (candidate)
1694 (write-file candidate 'confirm)))))))
1696 ;;;###autoload
1697 (defun anything-write-file ()
1698 "Preconfigured `anything' providing completion for `write-file'."
1699 (interactive)
1700 (anything 'anything-c-source-write-file
1701 (expand-file-name default-directory)
1702 "Write buffer to file: " nil nil "*Anything write file*"))
1704 ;;; Anything completion for `insert-file'.==> C-x i
1705 (defvar anything-c-source-insert-file
1706 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
1707 ;; It is needed for filenames with capital letters
1708 (disable-shortcuts)
1709 (candidates . anything-find-files-get-candidates)
1710 (candidate-transformer anything-c-highlight-ffiles)
1711 (persistent-action . anything-find-files-persistent-action)
1712 (persistent-help . "Expand Candidate")
1713 (volatile)
1714 (action .
1715 (("Insert File" . (lambda (candidate)
1716 (when (y-or-n-p (format "Really insert %s in %s "
1717 candidate anything-current-buffer))
1718 (insert-file-contents candidate))))))))
1720 ;;;###autoload
1721 (defun anything-insert-file ()
1722 "Preconfigured `anything' providing completion for `insert-file'."
1723 (interactive)
1724 (anything 'anything-c-source-insert-file
1725 (expand-file-name default-directory)
1726 "Insert file: " nil nil "*Anything insert file*"))
1728 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
1729 (defvar anything-c-source-copy-files
1730 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
1731 ;; It is needed for filenames with capital letters
1732 (disable-shortcuts)
1733 (candidates . anything-find-files-get-candidates)
1734 (candidate-transformer anything-c-highlight-ffiles)
1735 (persistent-action . anything-find-files-persistent-action)
1736 (persistent-help . "Expand Candidate")
1737 (volatile)
1738 (action .
1739 (("Copy File"
1740 . (lambda (candidate)
1741 (anything-dired-action candidate :action 'copy)))
1742 ("Copy and Follow"
1743 . (lambda (candidate)
1744 (anything-dired-action candidate :action 'copy :follow t)))))))
1747 (defvar anything-c-source-rename-files
1748 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
1749 ;; It is needed for filenames with capital letters
1750 (disable-shortcuts)
1751 (candidates . anything-find-files-get-candidates)
1752 (candidate-transformer anything-c-highlight-ffiles)
1753 (persistent-action . anything-find-files-persistent-action)
1754 (persistent-help . "Expand Candidate")
1755 (volatile)
1756 (action .
1757 (("Rename File"
1758 . (lambda (candidate)
1759 (anything-dired-action candidate :action 'rename)))
1760 ("Rename and Follow"
1761 . (lambda (candidate)
1762 (anything-dired-action candidate :action 'rename :follow t)))))))
1764 (defvar anything-c-source-symlink-files
1765 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
1766 ;; It is needed for filenames with capital letters
1767 (disable-shortcuts)
1768 (candidates . anything-find-files-get-candidates)
1769 (candidate-transformer anything-c-highlight-ffiles)
1770 (persistent-action . anything-find-files-persistent-action)
1771 (persistent-help . "Expand Candidate")
1772 (volatile)
1773 (action .
1774 (("Symlink File" . (lambda (candidate)
1775 (anything-dired-action candidate :action 'symlink)))
1776 ("RelSymlink File" . (lambda (candidate)
1777 (anything-dired-action candidate :action 'relsymlink)))))))
1780 (defvar anything-c-source-hardlink-files
1781 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
1782 ;; It is needed for filenames with capital letters
1783 (disable-shortcuts)
1784 (candidates . anything-find-files-get-candidates)
1785 (candidate-transformer anything-c-highlight-ffiles)
1786 (persistent-action . anything-find-files-persistent-action)
1787 (persistent-help . "Expand Candidate")
1788 (volatile)
1789 (action .
1790 (("Hardlink File" . (lambda (candidate)
1791 (anything-dired-action candidate :action 'hardlink)))))))
1793 (defun* anything-dired-action (candidate &key action follow)
1794 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
1795 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
1796 (let ((files (dired-get-marked-files))
1797 (fn (case action
1798 ('copy 'dired-copy-file)
1799 ('rename 'dired-rename-file)
1800 ('symlink 'make-symbolic-link)
1801 ('relsymlink 'dired-make-relative-symlink)
1802 ('hardlink 'dired-hardlink)))
1803 (marker (case action
1804 ((copy rename) dired-keep-marker-copy)
1805 ('symlink dired-keep-marker-symlink)
1806 ('relsymlink dired-keep-marker-relsymlink)
1807 ('hardlink dired-keep-marker-hardlink))))
1808 (dired-create-files
1809 fn (symbol-name action) files
1810 (if (file-directory-p candidate)
1811 ;; When CANDIDATE is a directory, build file-name in this directory.
1812 ;; Else we use CANDIDATE.
1813 #'(lambda (from)
1814 (expand-file-name (file-name-nondirectory from) candidate))
1815 #'(lambda (from) candidate))
1816 marker)
1817 (when follow
1818 (let* ((src (car files))
1819 (dest (expand-file-name candidate))
1820 (basename-src (if (file-directory-p src)
1821 (file-relative-name
1822 (directory-file-name src)
1823 (file-name-directory src))
1824 (file-name-nondirectory src)))
1825 (fname (if (file-directory-p dest)
1826 (concat (file-name-as-directory dest)
1827 basename-src)
1828 dest)))
1829 (anything-c-point-file-in-dired fname)))))
1832 (defun* anything-dired-do-action-on-file (&key action)
1833 (let* ((files (dired-get-marked-files))
1834 (len (length files))
1835 (fname (if (> len 1)
1836 (format "* %d Files" len)
1837 (car files)))
1838 (source (case action
1839 ('copy 'anything-c-source-copy-files)
1840 ('rename 'anything-c-source-rename-files)
1841 ('symlink 'anything-c-source-symlink-files)
1842 ('hardlink 'anything-c-source-hardlink-files)))
1843 (prompt-fm (case action
1844 ('copy "Copy %s to: ")
1845 ('rename "Rename %s to: ")
1846 ('symlink "Symlink %s to: ")
1847 ('hardlink "Hardlink %s to: ")))
1848 (buffer (case action
1849 ('copy "*Anything Copy Files*")
1850 ('rename "*Anything Rename Files*")
1851 ('symlink "*Anything Symlink Files*")
1852 ('hardlink "*Anything Hardlink Files*"))))
1853 (anything source
1854 (or (dired-dwim-target-directory)
1855 (expand-file-name default-directory))
1856 (format prompt-fm fname) nil nil buffer)))
1859 ;;;###autoload
1860 (defun anything-dired-rename-file ()
1861 "Preconfigured `anything' to rename files from dired."
1862 (interactive)
1863 (anything-dired-do-action-on-file :action 'rename))
1865 ;;;###autoload
1866 (defun anything-dired-copy-file ()
1867 "Preconfigured `anything' to copy files from dired."
1868 (interactive)
1869 (anything-dired-do-action-on-file :action 'copy))
1871 ;;;###autoload
1872 (defun anything-dired-symlink-file ()
1873 "Preconfigured `anything' to symlink files from dired."
1874 (interactive)
1875 (anything-dired-do-action-on-file :action 'symlink))
1877 ;;;###autoload
1878 (defun anything-dired-hardlink-file ()
1879 "Preconfigured `anything' to hardlink files from dired."
1880 (interactive)
1881 (anything-dired-do-action-on-file :action 'hardlink))
1883 (defvar anything-dired-bindings nil)
1884 ;;;###autoload
1885 (defun anything-dired-bindings (&optional arg)
1886 "Replace usual dired commands `C' and `R' by anything ones.
1887 When call interactively toggle dired bindings and anything bindings.
1888 When call non--interactively with arg > 0, enable anything bindings.
1889 You can put (anything-dired-binding 1) in init file to enable anything bindings."
1890 (interactive)
1891 (if (or (when arg (> arg 0)) (not anything-dired-bindings))
1892 (progn
1893 (define-key dired-mode-map (kbd "C") 'anything-dired-copy-file)
1894 (define-key dired-mode-map (kbd "R") 'anything-dired-rename-file)
1895 (define-key dired-mode-map (kbd "S") 'anything-dired-symlink-file)
1896 (define-key dired-mode-map (kbd "H") 'anything-dired-hardlink-file)
1897 (setq anything-dired-bindings t))
1898 (define-key dired-mode-map (kbd "C") 'dired-do-copy)
1899 (define-key dired-mode-map (kbd "R") 'dired-do-rename)
1900 (define-key dired-mode-map (kbd "S") 'dired-do-symlink)
1901 (define-key dired-mode-map (kbd "H") 'dired-do-hardlink)
1902 (setq anything-dired-bindings nil)))
1904 (defun* anything-c-read-file-name (prompt &key
1905 (initial-input (expand-file-name default-directory))
1906 (buffer "*Anything Completions*")
1907 test)
1908 "Anything `read-file-name' emulation.
1909 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
1910 (when (get-buffer anything-action-buffer)
1911 (kill-buffer anything-action-buffer))
1912 (or (anything
1913 `((name . ,(concat "Read file name" anything-c-find-files-doc-header))
1914 ;; It is needed for filenames with capital letters
1915 (disable-shortcuts)
1916 (candidates . (lambda ()
1917 (if test
1918 (loop with seq = (anything-find-files-get-candidates)
1919 for fname in seq when (funcall test fname)
1920 collect fname)
1921 (anything-find-files-get-candidates))))
1922 (candidate-transformer anything-c-highlight-ffiles)
1923 (persistent-action . anything-find-files-persistent-action)
1924 (persistent-help . "Expand Candidate")
1925 (volatile)
1926 (action . (("candidate" . ,'identity))))
1927 initial-input prompt 'noresume nil buffer)
1928 (keyboard-quit)))
1930 ;;; File Cache
1931 (defvar anything-c-source-file-cache-initialized nil)
1933 (defvar anything-c-file-cache-files nil)
1935 (defvar anything-c-source-file-cache
1936 '((name . "File Cache")
1937 (init . (lambda ()
1938 (require 'filecache nil t)
1939 (unless anything-c-source-file-cache-initialized
1940 (setq anything-c-file-cache-files
1941 (loop for item in file-cache-alist append
1942 (destructuring-bind (base &rest dirs) item
1943 (loop for dir in dirs collect
1944 (concat dir base)))))
1945 (defadvice file-cache-add-file (after file-cache-list activate)
1946 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
1947 (setq anything-c-source-file-cache-initialized t))))
1948 (candidates . anything-c-file-cache-files)
1949 (match anything-c-match-on-file-name
1950 anything-c-match-on-directory-name)
1951 (type . file)))
1952 ;; (anything 'anything-c-source-file-cache)
1954 ;;; Locate
1955 ;; NOTE for WINDOZE users:
1956 ;; You have to install Everything with his command line interface here:
1957 ;; http://www.voidtools.com/download.php
1959 (defvar anything-c-locate-command
1960 (case system-type
1961 ('gnu/linux "locate -i -r %s")
1962 ('berkeley-unix "locate -i %s")
1963 ('windows-nt "es -i -r %s")
1964 (t "locate %s"))
1965 "A list of arguments for locate program.
1966 The \"-r\" option must be the last option.")
1968 (defun anything-c-locate-init ()
1969 "Initialize async locate process for `anything-c-source-locate'."
1970 (start-process-shell-command "locate-process" nil
1971 (format anything-c-locate-command
1972 anything-pattern)))
1974 (defvar anything-c-source-locate
1975 '((name . "Locate")
1976 (candidates . anything-c-locate-init)
1977 (type . file)
1978 (requires-pattern . 3)
1979 (delayed))
1980 "Find files matching the current input pattern with locate.")
1982 ;; (anything 'anything-c-source-locate)
1984 ;;; Recentf files
1985 (defvar anything-c-source-recentf
1986 '((name . "Recentf")
1987 (init . (lambda ()
1988 (require 'recentf)
1989 (or recentf-mode (recentf-mode 1))
1990 ;; Big value empowers anything/recentf
1991 (when (and (numberp recentf-max-saved-items)
1992 (<= recentf-max-saved-items 20))
1993 (setq recentf-max-saved-items 500))))
1994 (candidates . recentf-list)
1995 (match anything-c-match-on-file-name
1996 anything-c-match-on-directory-name)
1997 (type . file))
1998 "See (info \"(emacs)File Conveniences\").
1999 if `recentf-max-saved-items' is too small, set it to 500.")
2000 ;; (anything 'anything-c-source-recentf)
2002 ;;; ffap
2003 (eval-when-compile (require 'ffap))
2004 (defvar anything-c-source-ffap-guesser
2005 '((name . "File at point")
2006 (init . (lambda () (require 'ffap)))
2007 (candidates . (lambda ()
2008 (anything-aif
2009 (with-current-buffer anything-current-buffer
2010 (ffap-guesser))
2011 (list it))))
2012 (type . file)))
2013 ;; (anything 'anything-c-source-ffap-guesser)
2015 ;;; ffap with line number
2016 (defun anything-c-ffap-file-line-at-point ()
2017 "Get (FILENAME . LINENO) at point."
2018 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2019 (save-excursion
2020 (beginning-of-line)
2021 (when (and (search-forward it nil t)
2022 (looking-at ":\\([0-9]+\\)"))
2023 (cons it (string-to-number (match-string 1)))))))
2025 (defvar anything-c-ffap-line-location nil
2026 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2027 It is cleared after jumping line.")
2029 (defun anything-c-ffap-line-candidates ()
2030 (with-current-buffer anything-current-buffer
2031 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
2032 (when anything-c-ffap-line-location
2033 (destructuring-bind (file . line) anything-c-ffap-line-location
2034 (list (cons (format "%s (line %d)" file line) file)))))
2036 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2037 (defun anything-c-ffap-line-goto-line ()
2038 (when (car anything-c-ffap-line-location)
2039 (unwind-protect
2040 (ignore-errors
2041 (with-selected-window (get-buffer-window
2042 (get-file-buffer (car anything-c-ffap-line-location)))
2043 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
2044 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
2045 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
2047 (defvar anything-c-source-ffap-line
2048 '((name . "File/Lineno at point")
2049 (init . (lambda () (require 'ffap)))
2050 (candidates . anything-c-ffap-line-candidates)
2051 (type . file)))
2052 ;; (anything 'anything-c-source-ffap-line)
2054 ;;; list of files gleaned from every dired buffer
2055 (defun anything-c-files-in-all-dired-candidates ()
2056 (save-excursion
2057 (mapcan
2058 (lambda (dir)
2059 (cond ((listp dir) ;filelist
2060 dir)
2061 ((equal "" (file-name-nondirectory dir)) ;dir
2062 (directory-files dir t))
2063 (t ;wildcard
2064 (file-expand-wildcards dir t))))
2065 (delq nil
2066 (mapcar (lambda (buf)
2067 (set-buffer buf)
2068 (when (eq major-mode 'dired-mode)
2069 (if (consp dired-directory)
2070 (cdr dired-directory) ;filelist
2071 dired-directory))) ;dir or wildcard
2072 (buffer-list))))))
2073 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2075 (defvar anything-c-source-files-in-all-dired
2076 '((name . "Files in all dired buffer.")
2077 (candidates . anything-c-files-in-all-dired-candidates)
2078 (type . file)))
2079 ;; (anything 'anything-c-source-files-in-all-dired)
2081 ;;;; <info>
2082 ;;; Info pages
2083 (defvar anything-c-info-pages nil
2084 "All info pages on system.
2085 Will be calculated the first time you invoke anything with this
2086 source.")
2088 (defvar anything-c-source-info-pages
2089 `((name . "Info Pages")
2090 (candidates . (lambda ()
2091 (if anything-c-info-pages
2092 anything-c-info-pages
2093 (setq anything-c-info-pages
2094 (save-window-excursion
2095 (save-excursion
2096 (require 'info)
2097 (Info-find-node "dir" "top")
2098 (goto-char (point-min))
2099 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2100 topics)
2101 (while (re-search-forward info-topic-regexp nil t)
2102 (add-to-list 'topics (match-string-no-properties 1)))
2103 (goto-char (point-min))
2104 (Info-exit)
2105 topics)))))))
2106 (action . (("Show with Info" .(lambda (node-str)
2107 (info (replace-regexp-in-string "^[^:]+: "
2109 node-str))))))
2110 (requires-pattern . 2)))
2111 ;; (anything 'anything-c-source-info-pages)
2114 ;;; Use info-index plug-in. Note that `name' attribute is
2115 ;;; not needed but `anything-c-insert-summary' uses it.
2116 ;; Info Elisp
2117 (defvar anything-c-source-info-elisp
2118 '((name . "Info index: elisp")
2119 (info-index . "elisp")))
2120 ;; (anything 'anything-c-source-info-elisp)
2122 ;; Info-Common-Lisp
2123 (defvar anything-c-source-info-cl
2124 '((name . "Info index: cl")
2125 (info-index . "cl")))
2126 ;; (anything 'anything-c-source-info-cl)
2128 ;; Info Index org
2129 (defvar anything-c-source-info-org
2130 '((name . "Info index: org")
2131 (info-index . "org")))
2132 ;; (anything 'anything-c-source-info-org)
2134 ;; Info Index ratpoison
2135 (defvar anything-c-source-info-ratpoison
2136 '((name . "Info index: ratpoison")
2137 (info-index . "ratpoison")))
2138 ;; (anything 'anything-c-source-info-ratpoison)
2140 ;; Info Index zsh
2141 (defvar anything-c-source-info-zsh
2142 '((name . "Info index: zsh")
2143 (info-index . "zsh")))
2144 ;; (anything 'anything-c-source-info-zsh)
2146 ;; Info Index bash
2147 (defvar anything-c-source-info-bash
2148 '((name . "Info index: bash")
2149 (info-index . "bash")))
2150 ;; (anything 'anything-c-source-info-bash)
2152 ;; Info Index coreutils
2153 (defvar anything-c-source-info-coreutils
2154 '((name . "Info index: coreutils")
2155 (info-index . "coreutils")))
2156 ;; (anything 'anything-c-source-info-coreutils)
2158 ;; Info Index fileutils
2159 (defvar anything-c-source-info-fileutils
2160 '((name . "Info index: fileutils")
2161 (info-index . "fileutils")))
2162 ;; (anything 'anything-c-source-info-fileutils)
2164 ;; Info Index find
2165 (defvar anything-c-source-info-find
2166 '((name . "Info index: find")
2167 (info-index . "find")))
2168 ;; (anything 'anything-c-source-info-find)
2170 ;; Info Index sh-utils
2171 (defvar anything-c-source-info-sh-utils
2172 '((name . "Info index: sh-utils")
2173 (info-index . "sh-utils")))
2174 ;; (anything 'anything-c-source-info-sh-utils)
2176 ;; Info Index textutils
2177 (defvar anything-c-source-info-textutils
2178 '((name . "Info index: textutils")
2179 (info-index . "textutils")))
2180 ;; (anything 'anything-c-source-info-textutils)
2182 ;; Info Index libc
2183 (defvar anything-c-source-info-libc
2184 '((name . "Info index: libc")
2185 (info-index . "libc")))
2186 ;; (anything 'anything-c-source-info-libc)
2188 ;; Info Index make
2189 (defvar anything-c-source-info-make
2190 '((name . "Info index: make")
2191 (info-index . "make")))
2192 ;; (anything 'anything-c-source-info-make)
2194 ;; Info Index automake
2195 (defvar anything-c-source-info-automake
2196 '((name . "Info index: automake")
2197 (info-index . "automake")))
2198 ;; (anything 'anything-c-source-info-automake)
2200 ;; Info Index autoconf
2201 (defvar anything-c-source-info-autoconf
2202 '((name . "Info index: autoconf")
2203 (info-index . "autoconf")))
2204 ;; (anything 'anything-c-source-info-autoconf)
2206 ;; Info Index emacs-lisp-intro
2207 (defvar anything-c-source-info-emacs-lisp-intro
2208 '((name . "Info index: emacs-lisp-intro")
2209 (info-index . "emacs-lisp-intro")))
2210 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2212 ;; Info Index emacs
2213 (defvar anything-c-source-info-emacs
2214 '((name . "Info index: emacs")
2215 (info-index . "emacs")))
2216 ;; (anything 'anything-c-source-info-emacs)
2218 ;; Info Index elib
2219 (defvar anything-c-source-info-elib
2220 '((name . "Info index: elib")
2221 (info-index . "elib")))
2222 ;; (anything 'anything-c-source-info-elib)
2224 ;; Info Index eieio
2225 (defvar anything-c-source-info-eieio
2226 '((name . "Info index: eieio")
2227 (info-index . "eieio")))
2228 ;; (anything 'anything-c-source-info-eieio)
2230 ;; Info Index gauche-refe
2231 (defvar anything-c-source-info-gauche-refe
2232 '((name . "Info index: gauche")
2233 (info-index . "gauche-refe")))
2234 ;; (anything 'anything-c-source-info-gauche-refe)
2236 ;; Info Index guile
2237 (defvar anything-c-source-info-guile
2238 '((name . "Info index: guile")
2239 (info-index . "guile")))
2240 ;; (anything 'anything-c-source-info-guile)
2242 ;; Info Index guile-tut
2243 (defvar anything-c-source-info-guile-tut
2244 '((name . "Info index: guile-tut")
2245 (info-index . "guile-tut")))
2246 ;; (anything 'anything-c-source-info-guile-tut)
2248 ;; Info Index goops
2249 (defvar anything-c-source-info-goops
2250 '((name . "Info index: goops")
2251 (info-index . "goops")))
2252 ;; (anything 'anything-c-source-info-goops)
2254 ;; Info Index screen
2255 (defvar anything-c-source-info-screen
2256 '((name . "Info index: screen")
2257 (info-index . "screen")
2258 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2259 ;; (anything 'anything-c-source-info-screen)
2261 ;; Info Index latex
2262 (defvar anything-c-source-info-latex
2263 '((name . "Info index: latex")
2264 (info-index . "latex")))
2265 ;; (anything 'anything-c-source-info-latex)
2267 ;; Info Index gawk
2268 (defvar anything-c-source-info-gawk
2269 '((name . "Info index: gawk")
2270 (info-index . "gawk")))
2271 ;; (anything 'anything-c-source-info-gawk)
2273 ;; Info Index sed
2274 (defvar anything-c-source-info-sed
2275 '((name . "Info index: sed")
2276 (info-index . "sed")))
2277 ;; (anything 'anything-c-source-info-sed)
2279 ;; Info Index m4
2280 (defvar anything-c-source-info-m4
2281 '((name . "Info index: m4")
2282 (info-index . "m4")))
2283 ;; (anything 'anything-c-source-info-m4)
2285 ;; Info Index wget
2286 (defvar anything-c-source-info-wget
2287 '((name . "Info index: wget")
2288 (info-index . "wget")))
2289 ;; (anything 'anything-c-source-info-wget)
2291 ;; Info Index binutils
2292 (defvar anything-c-source-info-binutils
2293 '((name . "Info index: binutils")
2294 (info-index . "binutils")))
2295 ;; (anything 'anything-c-source-info-binutils)
2297 ;; Info Index as
2298 (defvar anything-c-source-info-as
2299 '((name . "Info index: as")
2300 (info-index . "as")))
2301 ;; (anything 'anything-c-source-info-as)
2303 ;; Info Index bfd
2304 (defvar anything-c-source-info-bfd
2305 '((name . "Info index: bfd")
2306 (info-index . "bfd")))
2307 ;; (anything 'anything-c-source-info-bfd)
2309 ;; Info Index gprof
2310 (defvar anything-c-source-info-gprof
2311 '((name . "Info index: gprof")
2312 (info-index . "gprof")))
2313 ;; (anything 'anything-c-source-info-gprof)
2315 ;; Info Index ld
2316 (defvar anything-c-source-info-ld
2317 '((name . "Info index: ld")
2318 (info-index . "ld")))
2319 ;; (anything 'anything-c-source-info-ld)
2321 ;; Info Index diff
2322 (defvar anything-c-source-info-diff
2323 '((name . "Info index: diff")
2324 (info-index . "diff")))
2325 ;; (anything 'anything-c-source-info-diff)
2327 ;; Info Index flex
2328 (defvar anything-c-source-info-flex
2329 '((name . "Info index: flex")
2330 (info-index . "flex")))
2331 ;; (anything 'anything-c-source-info-flex)
2333 ;; Info Index grep
2334 (defvar anything-c-source-info-grep
2335 '((name . "Info index: grep")
2336 (info-index . "grep")))
2337 ;; (anything 'anything-c-source-info-grep)
2339 ;; Info Index gzip
2340 (defvar anything-c-source-info-gzip
2341 '((name . "Info index: gzip")
2342 (info-index . "gzip")))
2343 ;; (anything 'anything-c-source-info-gzip)
2345 ;; Info Index libtool
2346 (defvar anything-c-source-info-libtool
2347 '((name . "Info index: libtool")
2348 (info-index . "libtool")))
2349 ;; (anything 'anything-c-source-info-libtool)
2351 ;; Info Index texinfo
2352 (defvar anything-c-source-info-texinfo
2353 '((name . "Info index: texinfo")
2354 (info-index . "texinfo")))
2355 ;; (anything 'anything-c-source-info-texinfo)
2357 ;; Info Index info
2358 (defvar anything-c-source-info-info
2359 '((name . "Info index: info")
2360 (info-index . "info")))
2361 ;; (anything 'anything-c-source-info-info)
2363 ;; Info Index gdb
2364 (defvar anything-c-source-info-gdb
2365 '((name . "Info index: gdb")
2366 (info-index . "gdb")))
2367 ;; (anything 'anything-c-source-info-gdb)
2369 ;; Info Index stabs
2370 (defvar anything-c-source-info-stabs
2371 '((name . "Info index: stabs")
2372 (info-index . "stabs")))
2373 ;; (anything 'anything-c-source-info-stabs)
2375 ;; Info Index cvsbook
2376 (defvar anything-c-source-info-cvsbook
2377 '((name . "Info index: cvsbook")
2378 (info-index . "cvsbook")))
2379 ;; (anything 'anything-c-source-info-cvsbook)
2381 ;; Info Index cvs
2382 (defvar anything-c-source-info-cvs
2383 '((name . "Info index: cvs")
2384 (info-index . "cvs")))
2385 ;; (anything 'anything-c-source-info-cvs)
2387 ;; Info Index bison
2388 (defvar anything-c-source-info-bison
2389 '((name . "Info index: bison")
2390 (info-index . "bison")))
2391 ;; (anything 'anything-c-source-info-bison)
2393 ;; Info Index id-utils
2394 (defvar anything-c-source-info-id-utils
2395 '((name . "Info index: id-utils")
2396 (info-index . "id-utils")))
2397 ;; (anything 'anything-c-source-info-id-utils)
2399 ;; Info Index global
2400 (defvar anything-c-source-info-global
2401 '((name . "Info index: global")
2402 (info-index . "global")))
2403 ;; (anything 'anything-c-source-info-global)
2405 ;;;; <Help>
2406 ;;; Man Pages
2407 (defvar anything-c-man-pages nil
2408 "All man pages on system.
2409 Will be calculated the first time you invoke anything with this
2410 source.")
2412 (defvar anything-c-source-man-pages
2413 `((name . "Manual Pages")
2414 (candidates . (lambda ()
2415 (if anything-c-man-pages
2416 anything-c-man-pages
2417 ;; XEmacs doesn't have a woman :)
2418 (setq anything-c-man-pages
2419 (ignore-errors
2420 (require 'woman)
2421 (woman-file-name "")
2422 (sort (mapcar 'car woman-topic-all-completions)
2423 'string-lessp))))))
2424 (action ("Show with Woman" . woman))
2425 ;; Woman does not work OS X
2426 ;; http://xahlee.org/emacs/modernization_man_page.html
2427 (action-transformer . (lambda (actions candidate)
2428 (if (eq system-type 'darwin)
2429 '(("Show with Man" . man))
2430 actions)))
2431 (requires-pattern . 2)))
2432 ;; (anything 'anything-c-source-man-pages)
2434 ;;;; <Command>
2435 ;;; Complex command history
2436 (defvar anything-c-source-complex-command-history
2437 '((name . "Complex Command History")
2438 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
2439 (type . sexp)))
2440 ;; (anything 'anything-c-source-complex-command-history)
2442 ;;; M-x history
2443 (defvar anything-c-source-extended-command-history
2444 '((name . "Emacs Commands History")
2445 (candidates . extended-command-history)
2446 (type . command)))
2447 ;; (anything 'anything-c-source-extended-command-history)
2449 ;;; Emacs commands
2450 (defvar anything-c-source-emacs-commands
2451 '((name . "Emacs Commands")
2452 (candidates . (lambda ()
2453 (let (commands)
2454 (mapatoms (lambda (a)
2455 (if (commandp a)
2456 (push (symbol-name a)
2457 commands))))
2458 (sort commands 'string-lessp))))
2459 (type . command)
2460 (requires-pattern . 2))
2461 "Source for completing and invoking Emacs commands.
2462 A command is a function with interactive spec that can
2463 be invoked with `M-x'.
2465 To get non-interactive functions listed, use
2466 `anything-c-source-emacs-functions'.")
2467 ;; (anything 'anything-c-source-emacs-commands)
2469 ;;; LaCarte
2470 (defvar anything-c-source-lacarte
2471 '((name . "Lacarte")
2472 (init . (lambda () (require 'lacarte )))
2473 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2474 (candidate-number-limit . 9999)
2475 (action . anything-c-call-interactively))
2476 "Needs lacarte.el.
2478 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2479 ;; (anything 'anything-c-source-lacarte)
2481 ;;;; <Function>
2482 ;;; Emacs functions
2483 (defvar anything-c-source-emacs-functions
2484 '((name . "Emacs Functions")
2485 (candidates . (lambda ()
2486 (let (commands)
2487 (mapatoms (lambda (a) (if (functionp a)
2488 (push (symbol-name a) commands))))
2489 (sort commands 'string-lessp))))
2490 (type . function)
2491 (requires-pattern . 2))
2492 "Source for completing Emacs functions.")
2493 ;; (anything 'anything-c-source-emacs-functions)
2495 ;;; With abbrev expansion
2496 ;;; Similar to my exec-abbrev-cmd.el
2497 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2498 (defvar anything-c-function-abbrev-regexp nil
2499 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2500 Regexp built from the current `anything-pattern' interpreting it
2501 as abbreviation.
2502 Only for internal use.")
2504 (defun anything-c-match-function-by-abbrev (candidate)
2505 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2507 Abbreviations are made by taking the first character from each
2508 word in the function's name, e.g. \"bb\" is an abbrev for
2509 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2510 (string-match anything-c-function-abbrev-regexp candidate))
2512 (defvar anything-c-source-emacs-functions-with-abbrevs
2513 (append anything-c-source-emacs-functions
2514 '((match anything-c-match-function-by-abbrev
2515 anything-c-string-match))
2516 '((init . (lambda ()
2517 (defadvice anything-update
2518 (before anything-c-update-function-abbrev-regexp activate)
2519 (let ((char-list (append anything-pattern nil))
2520 (str "^"))
2521 (dolist (c char-list)
2522 (setq str (concat str (list c) "[^-]*-")))
2523 (setq str (concat (substring str 0 (1- (length str))) "$"))
2524 (setq anything-c-function-abbrev-regexp str))))))))
2525 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2527 (defvar anything-c-source-advice
2528 '((name . "Function Advice")
2529 (candidates . anything-c-advice-candidates)
2530 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
2531 ;; (real-to-display . anything-c-advice-real-to-display)
2534 (persistent-action . anything-c-advice-persistent-action)
2535 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
2536 ;; (anything 'anything-c-source-advice)
2537 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
2538 ;; (testadvice)
2540 (defun anything-c-advice-candidates ()
2541 (require 'advice)
2542 (loop for (fname) in ad-advised-functions
2543 for function = (intern fname)
2544 append
2545 (loop for class in ad-advice-classes append
2546 (loop for advice in (ad-get-advice-info-field function class)
2547 for enabled = (ad-advice-enabled advice)
2548 collect
2549 (cons (format "%s %s %s"
2550 (if enabled "Enabled " "Disabled")
2551 (propertize fname 'face 'font-lock-function-name-face)
2552 (ad-make-single-advice-docstring advice class nil))
2553 (list function class advice))))))
2555 (defun anything-c-advice-persistent-action (func-class-advice)
2556 (if current-prefix-arg
2557 (anything-c-advice-toggle func-class-advice)
2558 (describe-function (car func-class-advice))))
2560 (defun anything-c-advice-toggle (func-class-advice)
2561 (destructuring-bind (function class advice) func-class-advice
2562 (cond ((ad-advice-enabled advice)
2563 (ad-advice-set-enabled advice nil)
2564 (message "Disabled"))
2565 (t ;disabled
2566 (ad-advice-set-enabled advice t)
2567 (message "Enabled")))
2568 (ad-activate function)
2569 (and anything-in-persistent-action
2570 (anything-c-advice-update-current-display-string))))
2572 (defun anything-c-advice-update-current-display-string ()
2573 (anything-edit-current-selection
2574 (let ((newword (cond ((looking-at "Disabled") "Enabled")
2575 ((looking-at "Enabled") "Disabled")))
2576 realvalue)
2577 (when newword
2578 (delete-region (point) (progn (forward-word 1) (point)))
2579 (insert newword)))))
2581 ;;;###autoload
2582 (defun anything-manage-advice ()
2583 "Preconfigured `anything' to disable/enable function advices."
2584 (interactive)
2585 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
2587 ;;;; <Variable>
2588 ;;; Emacs variables
2589 (defvar anything-c-source-emacs-variables
2590 '((name . "Emacs Variables")
2591 (candidates . (lambda ()
2592 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
2593 (type . variable)
2594 (requires-pattern . 2))
2595 "Source for completing Emacs variables.")
2596 ;; (anything 'anything-c-source-emacs-variables)
2598 ;;;; <Bookmark>
2599 ;;; Bookmarks
2600 (eval-when-compile (require 'bookmark))
2601 (defvar anything-c-source-bookmarks
2602 '((name . "Bookmarks")
2603 (init . (lambda ()
2604 (require 'bookmark)))
2605 (candidates . bookmark-all-names)
2606 (type . bookmark))
2607 "See (info \"(emacs)Bookmarks\").")
2608 ;; (anything 'anything-c-source-bookmarks)
2610 ;;; bookmark-set
2611 (defvar anything-c-source-bookmark-set
2612 '((name . "Set Bookmark")
2613 (dummy)
2614 (action . bookmark-set))
2615 "See (info \"(emacs)Bookmarks\").")
2616 ;; (anything 'anything-c-source-bookmark-set)
2618 ;;; Visible Bookmarks
2619 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2622 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2623 (defvar anything-c-source-bm
2624 '((name . "Visible Bookmarks")
2625 (init . anything-c-bm-init)
2626 (candidates-in-buffer)
2627 (type . line))
2628 "Needs bm.el.
2630 http://www.nongnu.org/bm/")
2632 (defun anything-c-bm-init ()
2633 "Init function for `anything-c-source-bm'."
2634 (when (require 'bm nil t)
2635 (with-no-warnings
2636 (let ((bookmarks (bm-lists))
2637 (buf (anything-candidate-buffer 'global)))
2638 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
2639 '< :key 'overlay-start))
2640 (let ((start (overlay-start bm))
2641 (end (overlay-end bm))
2642 (annotation (or (overlay-get bm 'annotation) "")))
2643 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
2644 (let ((str (format "%5d: [%s]: %s\n"
2645 (line-number-at-pos start)
2646 annotation
2647 (buffer-substring start (1- end)))))
2648 (with-current-buffer buf (insert str))))))))))
2650 ;;; Special bookmarks
2651 (defvar anything-c-source-bookmarks-ssh
2652 '((name . "Bookmarks-ssh")
2653 (init . (lambda ()
2654 (require 'bookmark)))
2655 ;; DRY
2656 (candidates . (lambda ()
2657 (let (lis-all lis-ssh)
2658 (setq lis-all (bookmark-all-names))
2659 (setq lis-ssh (loop for i in lis-all
2660 if (string-match "^(ssh)" i)
2661 collect i))
2662 (sort lis-ssh 'string-lessp))))
2663 (type . bookmark))
2664 "See (info \"(emacs)Bookmarks\").")
2665 ;; (anything 'anything-c-source-bookmarks-ssh)
2667 (defvar anything-c-source-bookmarks-su
2668 '((name . "Bookmarks-root")
2669 (init . (lambda ()
2670 (require 'bookmark)))
2671 ;; DRY
2672 (candidates . (lambda ()
2673 (let (lis-all lis-su)
2674 (setq lis-all (bookmark-all-names))
2675 (setq lis-su (loop for i in lis-all
2676 if (string-match (format "^(%s)" anything-su-or-sudo) i)
2677 collect i))
2678 (sort lis-su 'string-lessp))))
2679 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
2681 (type . bookmark))
2682 "See (info \"(emacs)Bookmarks\").")
2683 ;; (anything 'anything-c-source-bookmarks-su)
2686 (defun tv-root-logged-p ()
2687 (catch 'break
2688 (dolist (i (mapcar #'buffer-name (buffer-list)))
2689 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
2690 (throw 'break t)))))
2693 (defun anything-c-highlight-bookmark-su (files source)
2694 (if (tv-root-logged-p)
2695 (anything-c-highlight-bookmark files source)
2696 (anything-c-highlight-not-logged files source)))
2698 (defun anything-c-highlight-not-logged (files source)
2699 (loop for i in files
2700 collect (propertize i 'face anything-c-bookmarks-face3)))
2702 (defun anything-c-highlight-bookmark (bookmarks source)
2703 "Used as `candidate-transformer' to colorize bookmarks.
2704 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2705 (loop for i in bookmarks
2706 for pred = (bookmark-get-filename i)
2707 for bufp = (and (fboundp 'bmkext-get-buffer-name)
2708 (bmkext-get-buffer-name i))
2709 for handlerp = (and (fboundp 'bookmark-get-handler)
2710 (bookmark-get-handler i))
2711 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
2712 (bmkext-w3m-bookmark-p i))
2713 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
2714 (bmkext-gnus-bookmark-p i))
2715 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
2716 (bmkext-man-bookmark-p i))
2717 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
2718 (bmkext-woman-bookmark-p i))
2719 for handlerp = (bookmark-get-handler i)
2720 for isannotation = (bookmark-get-annotation i)
2721 ;; Add a * if bookmark have annotation
2722 if (and isannotation (not (string-equal isannotation "")))
2723 do (setq i (concat "*" i))
2724 ;; info buffers
2725 if (eq handlerp 'Info-bookmark-jump)
2726 collect (propertize i 'face 'anything-bmkext-info 'help-echo pred)
2727 ;; w3m buffers
2728 if isw3m
2729 collect (propertize i 'face 'anything-bmkext-w3m 'help-echo pred)
2730 ;; gnus buffers
2731 if isgnus
2732 collect (propertize i 'face 'anything-bmkext-gnus 'help-echo pred)
2733 ;; Man Woman
2734 if (or iswoman isman)
2735 collect (propertize i 'face 'anything-bmkext-man 'help-echo pred)
2736 ;; directories
2737 if (and pred (file-directory-p pred))
2738 collect (propertize i 'face anything-c-bookmarks-face1 'help-echo pred)
2739 ;; regular files
2740 if (and pred (not (file-directory-p pred)) (file-exists-p pred)
2741 (not (or iswoman isman)))
2742 collect (propertize i 'face 'anything-bmkext-file 'help-echo pred)))
2744 ;;; Faces for bookmarks
2745 (defface anything-bmkext-info
2746 '((t (:foreground "green")))
2747 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2748 :group 'anything)
2750 (defface anything-bmkext-w3m
2751 '((t (:foreground "yellow")))
2752 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2753 :group 'anything)
2755 (defface anything-bmkext-gnus
2756 '((t (:foreground "magenta")))
2757 "*Face used for Gnus bookmarks."
2758 :group 'anything)
2760 (defface anything-bmkext-man
2761 '((t (:foreground "Orange4")))
2762 "*Face used for Woman/man bookmarks."
2763 :group 'anything)
2765 (defface anything-bmkext-no--file
2766 '((t (:foreground "grey")))
2767 "*Face used for non--file bookmarks."
2768 :group 'anything)
2770 (defface anything-bmkext-file
2771 '((t (:foreground "Deepskyblue2")))
2772 "*Face used for non--file bookmarks."
2773 :group 'anything)
2775 (defface anything-bookmarks-su-face '((t (:foreground "red")))
2776 "Face for su/sudo bookmarks."
2777 :group 'anything)
2779 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
2780 (defvar anything-c-bookmarks-face2 'anything-file-name)
2781 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
2783 (defvar anything-c-source-bookmarks-local
2784 '((name . "Bookmarks-Local")
2785 (init . (lambda ()
2786 (require 'bookmark)))
2787 ;; DRY
2788 (candidates . (lambda ()
2789 (let (lis-all lis-loc)
2790 (setq lis-all (bookmark-all-names))
2791 (setq lis-loc (loop for i in lis-all
2792 if (and (not (string-match "^(ssh)" i))
2793 (not (string-match "^(su)" i)))
2794 collect i))
2795 (sort lis-loc 'string-lessp))))
2796 (candidate-transformer anything-c-highlight-bookmark)
2797 (type . bookmark))
2798 "See (info \"(emacs)Bookmarks\").")
2799 ;; (anything 'anything-c-source-bookmarks-local)
2801 ;;; Sources to filter bookmark-extensions bookmarks.
2802 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
2805 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
2806 "Return a filtered `bookmark-alist' sorted alphabetically."
2807 (loop
2808 with alist = (if args
2809 (apply #'(lambda (x) (funcall fn x)) args)
2810 (funcall fn))
2811 for i in alist
2812 for b = (car i)
2813 collect b into sa
2814 finally return (sort sa 'string-lessp)))
2816 ;; W3m
2817 (defvar anything-c-source-bookmark-w3m
2818 '((name . "Bookmark W3m")
2819 (init . (lambda ()
2820 (require 'bookmark-extensions)
2821 (bookmark-maybe-load-default-file)))
2822 (candidates . anything-c-bookmark-w3m-setup-alist)
2823 (filtered-candidate-transformer
2824 anything-c-adaptive-sort
2825 anything-c-highlight-bookmark)
2826 (type . bookmark)))
2827 ;; (anything 'anything-c-source-bookmark-w3m)
2829 (defun anything-c-bookmark-w3m-setup-alist ()
2830 "Specialized filter function for bookmarks w3m."
2831 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
2833 ;; Woman Man
2834 (defvar anything-c-source-bookmark-man
2835 '((name . "Bookmark Woman&Man")
2836 (init . (lambda ()
2837 (require 'bookmark-extensions)
2838 (bookmark-maybe-load-default-file)))
2839 (candidates . anything-c-bookmark-man-setup-alist)
2840 (filtered-candidate-transformer
2841 anything-c-adaptive-sort
2842 anything-c-highlight-bookmark)
2843 (type . bookmark)))
2844 ;; (anything 'anything-c-source-bookmark-man)
2846 (defun anything-c-bookmark-man-setup-alist ()
2847 "Specialized filter function for bookmarks w3m."
2848 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
2849 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
2851 ;; Gnus
2852 (defvar anything-c-source-bookmark-gnus
2853 '((name . "Bookmark Gnus")
2854 (init . (lambda ()
2855 (require 'bookmark-extensions)
2856 (bookmark-maybe-load-default-file)))
2857 (candidates . anything-c-bookmark-gnus-setup-alist)
2858 (filtered-candidate-transformer
2859 anything-c-adaptive-sort
2860 anything-c-highlight-bookmark)
2861 (type . bookmark)))
2862 ;; (anything 'anything-c-source-bookmark-gnus)
2864 (defun anything-c-bookmark-gnus-setup-alist ()
2865 "Specialized filter function for bookmarks gnus."
2866 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
2868 ;; Info
2869 (defvar anything-c-source-bookmark-info
2870 '((name . "Bookmark Info")
2871 (init . (lambda ()
2872 (require 'bookmark-extensions)
2873 (bookmark-maybe-load-default-file)))
2874 (candidates . anything-c-bookmark-info-setup-alist)
2875 (filtered-candidate-transformer
2876 anything-c-adaptive-sort
2877 anything-c-highlight-bookmark)
2878 (type . bookmark)))
2879 ;; (anything 'anything-c-source-bookmark-info)
2881 (defun anything-c-bookmark-info-setup-alist ()
2882 "Specialized filter function for bookmarks info."
2883 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
2885 ;; Local Files&directories
2886 (defvar anything-c-source-bookmark-files&dirs
2887 '((name . "Bookmark Files&Directories")
2888 (init . (lambda ()
2889 (require 'bookmark-extensions)
2890 (bookmark-maybe-load-default-file)))
2891 (candidates . anything-c-bookmark-local-files-setup-alist)
2892 (filtered-candidate-transformer
2893 anything-c-adaptive-sort
2894 anything-c-highlight-bookmark)
2895 (type . bookmark)))
2896 ;; (anything 'anything-c-source-bookmark-files&dirs)
2898 (defun anything-c-bookmark-local-files-setup-alist ()
2899 "Specialized filter function for bookmarks locals files."
2900 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
2902 ;; Su Files&directories
2903 (defvar anything-c-source-bookmark-su-files&dirs
2904 '((name . "Bookmark Root-Files&Directories")
2905 (init . (lambda ()
2906 (require 'bookmark-extensions)
2907 (bookmark-maybe-load-default-file)))
2908 (candidates . anything-c-bookmark-su-files-setup-alist)
2909 (filtered-candidate-transformer
2910 anything-c-adaptive-sort
2911 anything-c-highlight-bookmark-su)
2912 (type . bookmark)))
2913 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
2915 (defun anything-c-bookmark-su-files-setup-alist ()
2916 "Specialized filter function for bookmarks su/sudo files."
2917 (loop
2918 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
2919 for i in l
2920 for isfile = (bookmark-get-filename i)
2921 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
2922 (save-match-data
2923 (string-match tramp-file-name-regexp isfile)))
2924 for issu = (and istramp
2925 (string-match bmkext-su-or-sudo-regexp isfile))
2926 if issu
2927 collect i))
2929 ;; Ssh Files&directories
2930 (defvar anything-c-source-bookmark-ssh-files&dirs
2931 '((name . "Bookmark Ssh-Files&Directories")
2932 (init . (lambda ()
2933 (require 'bookmark-extensions)
2934 (bookmark-maybe-load-default-file)))
2935 (candidates . anything-c-bookmark-ssh-files-setup-alist)
2936 (filtered-candidate-transformer . anything-c-adaptive-sort)
2937 (type . bookmark)))
2938 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
2940 (defun anything-c-bookmark-ssh-files-setup-alist ()
2941 "Specialized filter function for bookmarks ssh files."
2942 (loop
2943 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
2944 for i in l
2945 for isfile = (bookmark-get-filename i)
2946 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
2947 (save-match-data
2948 (string-match tramp-file-name-regexp isfile)))
2949 for isssh = (and istramp
2950 (string-match "/ssh:" isfile))
2951 if isssh
2952 collect i))
2955 ;; All bookmark-extensions sources.
2956 ;;;###autoload
2957 (defun anything-bookmark-ext ()
2958 "Preconfigured `anything' for bookmark-extensions sources.
2959 See: <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>."
2960 (interactive)
2961 (anything '(anything-c-source-bookmark-files&dirs
2962 anything-c-source-bookmark-w3m
2963 anything-c-source-bookmark-gnus
2964 anything-c-source-bookmark-info
2965 anything-c-source-bookmark-man
2966 anything-c-source-bookmark-su-files&dirs
2967 anything-c-source-bookmark-ssh-files&dirs)))
2970 ;; Firefox bookmarks
2971 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
2972 ;; (only for firefox versions >=3)
2973 ;; To achieve that, open about:config in firefox and double click on this line to enable value
2974 ;; to true:
2975 ;; user_pref("browser.bookmarks.autoExportHTML", false);
2976 ;; You should have now:
2977 ;; user_pref("browser.bookmarks.autoExportHTML", true);
2979 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
2980 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
2982 (defun anything-get-firefox-user-init-dir ()
2983 "Guess the default Firefox user directory name."
2984 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
2985 (moz-user-dir (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
2986 (goto-char (point-min))
2987 (when (search-forward "Path=" nil t)
2988 (buffer-substring-no-properties (point) (point-at-eol))))))
2989 (file-name-as-directory (concat moz-dir moz-user-dir))))
2991 (defun anything-guess-firefox-bookmark-file ()
2992 "Return the path of the Firefox bookmarks file."
2993 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
2995 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
2996 "Parse html bookmark FILE and return an alist with (title . url) as elements."
2997 (let (bookmarks-alist url title)
2998 (with-temp-buffer
2999 (insert-file-contents file)
3000 (goto-char (point-min))
3001 (while (not (eobp))
3002 (forward-line)
3003 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
3004 (beginning-of-line)
3005 (when (re-search-forward url-regexp nil t)
3006 (setq url (concat "\"" (match-string 0))))
3007 (beginning-of-line)
3008 (when (re-search-forward bmk-regexp nil t)
3009 (setq title (match-string 1)))
3010 (push (cons title url) bookmarks-alist))))
3011 (nreverse bookmarks-alist)))
3014 (defvar anything-c-firefox-bookmarks-alist nil)
3015 (defvar anything-c-source-firefox-bookmarks
3016 '((name . "Firefox Bookmarks")
3017 (init . (lambda ()
3018 (setq anything-c-firefox-bookmarks-alist
3019 (anything-html-bookmarks-to-alist
3020 (anything-guess-firefox-bookmark-file)
3021 anything-firefox-bookmark-url-regexp
3022 anything-firefox-bookmarks-regexp))))
3023 (candidates . (lambda ()
3024 (mapcar #'car
3025 anything-c-firefox-bookmarks-alist)))
3026 (candidate-transformer anything-c-highlight-firefox-bookmarks)
3027 (filtered-candidate-transformer . anything-c-adaptive-sort)
3028 (action . (("Browse Url" . (lambda (candidate)
3029 (w3m-browse-url
3030 (anything-c-firefox-bookmarks-get-value candidate))))
3031 ("Browse Url Firefox" . (lambda (candidate)
3032 (browse-url-firefox
3033 (anything-c-firefox-bookmarks-get-value candidate))))
3034 ("Copy Url" . (lambda (elm)
3035 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
3037 ;; (anything 'anything-c-source-firefox-bookmarks)
3039 (defun anything-c-firefox-bookmarks-get-value (elm)
3040 (replace-regexp-in-string "\"" ""
3041 (cdr (assoc elm
3042 anything-c-firefox-bookmarks-alist))))
3045 (defun anything-c-highlight-firefox-bookmarks (books)
3046 (loop for i in books
3047 collect (propertize i
3048 'face '((:foreground "YellowGreen"))
3049 'help-echo (anything-c-firefox-bookmarks-get-value i))))
3051 ;; W3m bookmark
3052 (eval-when-compile (require 'w3m-bookmark nil t))
3053 (unless (and (require 'w3m nil t)
3054 (require 'w3m-bookmark nil t))
3055 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
3058 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
3059 "Face for w3m bookmarks" :group 'anything)
3061 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3062 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
3063 (defvar anything-c-w3m-bookmarks-alist nil)
3064 (defvar anything-c-source-w3m-bookmarks
3065 '((name . "W3m Bookmarks")
3066 (init . (lambda ()
3067 (setq anything-c-w3m-bookmarks-alist
3068 (anything-html-bookmarks-to-alist
3069 w3m-bookmark-file
3070 anything-w3m-bookmark-url-regexp
3071 anything-w3m-bookmarks-regexp))))
3072 (candidates . (lambda ()
3073 (mapcar #'car anything-c-w3m-bookmarks-alist)))
3074 (candidate-transformer anything-c-highlight-w3m-bookmarks)
3075 (filtered-candidate-transformer . anything-c-adaptive-sort)
3076 (action . (("Browse Url" . (lambda (candidate)
3077 (anything-c-w3m-browse-bookmark candidate)))
3078 ("Copy Url" . (lambda (elm)
3079 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
3080 ("Browse Url Firefox" . (lambda (candidate)
3081 (anything-c-w3m-browse-bookmark candidate t)))
3082 ("Delete Bookmark" . (lambda (candidate)
3083 (anything-c-w3m-delete-bookmark candidate)))
3084 ("Rename Bookmark" . (lambda (candidate)
3085 (anything-c-w3m-rename-bookmark candidate)))))
3086 (persistent-action . (lambda (candidate)
3087 (if current-prefix-arg
3088 (anything-c-w3m-browse-bookmark candidate t)
3089 (anything-c-w3m-browse-bookmark candidate nil t))))
3090 (persistent-help . "Open URL with emacs-w3m in new tab / \
3091 C-u \\[anything-execute-persistent-action]: Open URL with Firefox")))
3093 ;; (anything 'anything-c-source-w3m-bookmarks)
3095 (defun anything-c-w3m-bookmarks-get-value (elm)
3096 (replace-regexp-in-string
3097 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
3099 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
3100 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
3101 (arg (and (eq fn 'w3m-browse-url) new-tab)))
3102 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
3104 (defun anything-c-highlight-w3m-bookmarks (books)
3105 (loop for i in books
3106 collect (propertize
3107 i 'face 'anything-w3m-bookmarks-face
3108 'help-echo (anything-c-w3m-bookmarks-get-value i))))
3111 (defun anything-c-w3m-delete-bookmark (elm)
3112 (save-excursion
3113 (find-file-literally w3m-bookmark-file)
3114 (goto-char (point-min))
3115 (when (re-search-forward elm nil t)
3116 (beginning-of-line)
3117 (delete-region (point)
3118 (line-end-position))
3119 (delete-blank-lines))
3120 (save-buffer (current-buffer))
3121 (kill-buffer (current-buffer))))
3123 (defun anything-c-w3m-rename-bookmark (elm)
3124 (let* ((old-title (replace-regexp-in-string ">" "" elm))
3125 (new-title (read-string "NewTitle: " old-title)))
3126 (save-excursion
3127 (find-file-literally w3m-bookmark-file)
3128 (goto-char (point-min))
3129 (when (re-search-forward (concat elm "<") nil t)
3130 (goto-char (1- (point)))
3131 (delete-char (- (length old-title)))
3132 (insert new-title))
3133 (save-buffer (current-buffer))
3134 (kill-buffer (current-buffer)))))
3136 ;;;; <Library>
3137 ;;; Elisp library scan
3138 (defvar anything-c-source-elisp-library-scan
3139 '((name . "Elisp libraries (Scan)")
3140 (init . (anything-c-elisp-library-scan-init))
3141 (candidates-in-buffer)
3142 (action ("Find library" . (lambda (candidate)
3143 (find-file (find-library-name candidate))))
3144 ("Find library other window" . (lambda (candidate)
3145 (find-file-other-window (find-library-name candidate))))
3146 ("Load library" . (lambda (candidate)
3147 (load-library candidate))))))
3148 ;; (anything 'anything-c-source-elisp-library-scan)
3150 (defun anything-c-elisp-library-scan-init ()
3151 "Init anything buffer status."
3152 (let ((anything-buffer (anything-candidate-buffer 'global))
3153 (library-list (anything-c-elisp-library-scan-list)))
3154 (with-current-buffer anything-buffer
3155 (dolist (library library-list)
3156 (insert (format "%s\n" library))))))
3158 (defun anything-c-elisp-library-scan-list (&optional dirs string)
3159 "Do completion for file names passed to `locate-file'.
3160 DIRS is directory to search path.
3161 STRING is string to match."
3162 ;; Use `load-path' as path when ignore `dirs'.
3163 (or dirs (setq dirs load-path))
3164 ;; Init with blank when ignore `string'.
3165 (or string (setq string ""))
3166 ;; Get library list.
3167 (let ((string-dir (file-name-directory string))
3168 ;; File regexp that suffix match `load-file-rep-suffixes'.
3169 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
3170 name
3171 names)
3172 (dolist (dir dirs)
3173 (unless dir
3174 (setq dir default-directory))
3175 (if string-dir
3176 (setq dir (expand-file-name string-dir dir)))
3177 (when (file-directory-p dir)
3178 (dolist (file (file-name-all-completions
3179 (file-name-nondirectory string) dir))
3180 ;; Suffixes match `load-file-rep-suffixes'.
3181 (setq name (if string-dir (concat string-dir file) file))
3182 (if (string-match match-regexp name)
3183 (add-to-list 'names name)))))
3184 names))
3186 ;;;; <Programming>
3187 ;;; Imenu
3188 (defvar anything-c-imenu-delimiter " / ")
3190 (defvar anything-c-imenu-index-filter nil)
3191 (make-variable-buffer-local 'anything-c-imenu-index-filter)
3193 (defvar anything-c-cached-imenu-alist nil)
3194 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
3196 (defvar anything-c-cached-imenu-candidates nil)
3197 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
3199 (defvar anything-c-cached-imenu-tick nil)
3200 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
3202 (eval-when-compile (require 'imenu))
3203 (setq imenu-auto-rescan t)
3205 (defun anything-imenu-create-candidates (entry)
3206 "Create candidates with ENTRY."
3207 (if (listp (cdr entry))
3208 (mapcan (lambda (sub)
3209 (if (consp (cdr sub))
3210 (mapcar
3211 (lambda (subentry)
3212 (concat (car entry) anything-c-imenu-delimiter subentry))
3213 (anything-imenu-create-candidates sub))
3214 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
3215 (cdr entry))
3216 (list entry)))
3218 (defvar anything-c-source-imenu
3219 '((name . "Imenu")
3220 (candidates . anything-c-imenu-candidates)
3221 (persistent-action . (lambda (elm)
3222 (anything-c-imenu-default-action elm)
3223 (unless (fboundp 'semantic-imenu-tag-overlay)
3224 (anything-match-line-color-current-line))))
3225 (persistent-help . "Show this entry")
3226 (action . anything-c-imenu-default-action))
3227 "See (info \"(emacs)Imenu\")")
3229 ;; (anything 'anything-c-source-imenu)
3231 (defun anything-c-imenu-candidates ()
3232 (with-current-buffer anything-current-buffer
3233 (let ((tick (buffer-modified-tick)))
3234 (if (eq anything-c-cached-imenu-tick tick)
3235 anything-c-cached-imenu-candidates
3236 (setq imenu--index-alist nil)
3237 (setq anything-c-cached-imenu-tick tick
3238 anything-c-cached-imenu-candidates
3239 (condition-case nil
3240 (mapcan
3241 'anything-imenu-create-candidates
3242 (setq anything-c-cached-imenu-alist
3243 (let ((index (imenu--make-index-alist)))
3244 (if anything-c-imenu-index-filter
3245 (funcall anything-c-imenu-index-filter index)
3246 index))))
3247 (error nil)))
3248 (setq anything-c-cached-imenu-candidates
3249 (mapcar #'(lambda (x)
3250 (if (stringp x)
3252 (car x)))
3253 anything-c-cached-imenu-candidates))))))
3255 (setq imenu-default-goto-function 'imenu-default-goto-function)
3256 (defun anything-c-imenu-default-action (elm)
3257 "The default action for `anything-c-source-imenu'."
3258 (let ((path (split-string elm anything-c-imenu-delimiter))
3259 (alist anything-c-cached-imenu-alist))
3260 (if (> (length path) 1)
3261 (progn
3262 (setq alist (assoc (car path) alist))
3263 (setq elm (cadr path))
3264 (imenu (assoc elm alist)))
3265 (imenu (assoc elm alist)))))
3267 ;;; Ctags
3268 (defvar anything-c-ctags-modes
3269 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3270 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3271 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
3273 (defun anything-c-source-ctags-init ()
3274 (when (and buffer-file-name
3275 (memq major-mode anything-c-ctags-modes)
3276 (anything-current-buffer-is-modified))
3277 (with-current-buffer (anything-candidate-buffer 'local)
3278 (call-process-shell-command
3279 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
3280 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
3281 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
3282 nil (current-buffer))
3283 (goto-char (point-min))
3284 (forward-line 2)
3285 (delete-region (point-min) (point))
3286 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
3287 for lineno-start = (point)
3288 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
3290 (beginning-of-line)
3291 (insert (format "%5s:" lineno))
3292 (search-forward "\177" (point-at-eol) t)
3293 (delete-region (1- (point)) (point-at-eol))
3294 (forward-line 1)))))
3296 (defvar anything-c-source-ctags
3297 '((name . "Exuberant ctags")
3298 (init . anything-c-source-ctags-init)
3299 (candidates-in-buffer)
3300 (adjust)
3301 (type . line))
3302 "Needs Exuberant Ctags.
3304 http://ctags.sourceforge.net/")
3305 ;; (anything 'anything-c-source-ctags)
3307 ;; Semantic
3308 (defvar anything-semantic-candidates nil)
3309 (eval-when-compile (require 'semantic nil t))
3310 (defun anything-semantic-construct-candidates (tags depth)
3311 (when (require 'semantic nil t)
3312 (apply 'append
3313 (mapcar (lambda (tag)
3314 (if (listp tag)
3315 (let ((type (semantic-tag-type tag))
3316 (class (semantic-tag-class tag)))
3317 (if (or (and (stringp type)
3318 (or (string= type "class")
3319 (string= type "namespace")))
3320 (eq class 'function)
3321 (eq class 'variable))
3322 (cons (cons (concat (make-string (* depth 2) ?\s)
3323 (semantic-format-tag-summarize tag nil t)) tag)
3324 (anything-semantic-construct-candidates (semantic-tag-components tag)
3325 (1+ depth)))))))
3326 tags))))
3328 (defun anything-semantic-default-action (candidate)
3329 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
3330 (semantic-go-to-tag tag)))
3332 (defvar anything-c-source-semantic
3333 '((name . "Semantic Tags")
3334 (init . (lambda ()
3335 (setq anything-semantic-candidates
3336 (condition-case nil
3337 (anything-semantic-construct-candidates (semantic-fetch-tags) 0)
3338 (error nil)))))
3339 (candidates . (lambda ()
3340 (if anything-semantic-candidates
3341 (mapcar 'car anything-semantic-candidates))))
3342 (persistent-action . (lambda (elm)
3343 (anything-semantic-default-action elm)
3344 (anything-match-line-color-current-line)))
3345 (persistent-help . "Show this entry")
3346 (action . anything-semantic-default-action)
3347 "Needs semantic in CEDET.
3349 http://cedet.sourceforge.net/semantic.shtml
3350 http://cedet.sourceforge.net/"))
3352 ;; (anything 'anything-c-source-semantic)
3354 ;;; Function is called by
3355 ;;;###autoload
3356 (defun anything-simple-call-tree ()
3357 "Preconfigured `anything' for simple-call-tree. List function relationships."
3358 (interactive)
3359 (anything-other-buffer
3360 '(anything-c-source-simple-call-tree-functions-callers
3361 anything-c-source-simple-call-tree-callers-functions)
3362 "*anything simple-call-tree*"))
3364 (defvar anything-c-source-simple-call-tree-functions-callers
3365 '((name . "Function is called by")
3366 (init . anything-c-simple-call-tree-functions-callers-init)
3367 (multiline)
3368 (candidates . anything-c-simple-call-tree-candidates)
3369 (persistent-action . anything-c-simple-call-tree-persistent-action)
3370 (persistent-help . "Show function definitions by rotation")
3371 (action ("Find definition selected by persistent-action" .
3372 anything-c-simple-call-tree-find-definition)))
3373 "Needs simple-call-tree.el.
3374 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3376 (defvar anything-c-simple-call-tree-tick nil)
3377 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
3378 (defun anything-c-simple-call-tree-analyze-maybe ()
3379 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
3380 (simple-call-tree-analyze)
3381 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
3383 (defun anything-c-simple-call-tree-init-base (function message)
3384 (require 'simple-call-tree)
3385 (with-no-warnings
3386 (when (anything-current-buffer-is-modified)
3387 (anything-c-simple-call-tree-analyze-maybe)
3388 (let ((list (funcall function simple-call-tree-alist)))
3389 (with-current-buffer (anything-candidate-buffer 'local)
3390 (dolist (entry list)
3391 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
3392 (insert (car entry) message
3393 (if (string= funcs " ")
3394 " no functions."
3395 funcs)
3396 "\n\n"))))))))
3398 (defun anything-c-simple-call-tree-functions-callers-init ()
3399 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert " is called by\n"))
3401 (defun anything-c-simple-call-tree-candidates ()
3402 (with-current-buffer (anything-candidate-buffer)
3403 (split-string (buffer-string) "\n\n")))
3405 (defvar anything-c-simple-call-tree-related-functions nil)
3406 (defvar anything-c-simple-call-tree-function-index 0)
3407 (defun anything-c-simple-call-tree-persistent-action (candidate)
3408 (unless (eq last-command 'anything-execute-persistent-action)
3409 (setq anything-c-simple-call-tree-related-functions
3410 (delete "no functions."
3411 (split-string
3412 (replace-regexp-in-string " \\| is called by\\| calls " "" candidate)
3413 "\n")))
3414 (setq anything-c-simple-call-tree-function-index -1))
3415 (incf anything-c-simple-call-tree-function-index)
3416 (anything-c-simple-call-tree-find-definition candidate))
3418 (defun anything-c-simple-call-tree-find-definition (candidate)
3419 (find-function (intern
3420 (nth (mod anything-c-simple-call-tree-function-index
3421 (length anything-c-simple-call-tree-related-functions))
3422 anything-c-simple-call-tree-related-functions))))
3424 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3426 ;;; Function calls
3427 (defvar anything-c-source-simple-call-tree-callers-functions
3428 '((name . "Function calls")
3429 (init . anything-c-simple-call-tree-callers-functions-init)
3430 (multiline)
3431 (candidates . anything-c-simple-call-tree-candidates)
3432 (persistent-action . anything-c-simple-call-tree-persistent-action)
3433 (persistent-help . "Show function definitions by rotation")
3434 (action ("Find definition selected by persistent-action" .
3435 anything-c-simple-call-tree-find-definition)))
3436 "Needs simple-call-tree.el.
3437 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3439 (defun anything-c-simple-call-tree-callers-functions-init ()
3440 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
3442 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3444 ;;; Commands/Options with doc
3445 (defvar anything-c-auto-document-data nil)
3446 (make-variable-buffer-local 'anything-c-auto-document-data)
3447 (defvar anything-c-source-commands-and-options-in-file
3448 '((name . "Commands/Options in file")
3449 (header-name
3450 . (lambda (x) (format "Commands/Options in %s"
3451 (buffer-local-value 'buffer-file-name anything-current-buffer))))
3452 (candidates . anything-command-and-options-candidates)
3453 (multiline)
3454 (action . imenu))
3455 "List Commands and Options with doc. It needs auto-document.el .
3457 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3459 (eval-when-compile (require 'auto-document nil t))
3460 (defun anything-command-and-options-candidates ()
3461 (with-current-buffer anything-current-buffer
3462 (when (and (require 'auto-document nil t)
3463 (eq major-mode 'emacs-lisp-mode)
3464 (or (anything-current-buffer-is-modified)
3465 (not anything-c-auto-document-data)))
3466 (or imenu--index-alist (imenu--make-index-alist t))
3467 (setq anything-c-auto-document-data
3468 (destructuring-bind (commands options)
3469 (adoc-construct anything-current-buffer)
3470 (append
3471 (loop for (command . doc) in commands
3472 for cmdname = (symbol-name command)
3473 collect
3474 (cons (format "Command: %s\n %s"
3475 (propertize cmdname 'face font-lock-function-name-face)
3476 (adoc-first-line doc))
3477 (assoc cmdname imenu--index-alist)))
3478 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
3479 for (option doc default) in options
3480 for optname = (symbol-name option)
3481 collect
3482 (cons (format "Option: %s\n %s\n default = %s"
3483 (propertize optname 'face font-lock-variable-name-face)
3484 (adoc-first-line doc)
3485 (adoc-prin1-to-string default))
3486 (assoc optname
3487 var-alist)))))))
3488 anything-c-auto-document-data))
3490 ;; (anything 'anything-c-source-commands-and-options-in-file)
3492 ;;;; <Color and Face>
3493 ;;; Customize Face
3494 (defvar anything-c-source-customize-face
3495 '((name . "Customize Face")
3496 (init . (lambda ()
3497 (unless (anything-candidate-buffer)
3498 (save-window-excursion (list-faces-display))
3499 (anything-candidate-buffer (get-buffer "*Faces*")))))
3500 (candidates-in-buffer)
3501 (get-line . buffer-substring)
3502 (action . (lambda (line)
3503 (customize-face (intern (car (split-string line))))))
3504 (requires-pattern . 3))
3505 "See (info \"(emacs)Faces\")")
3506 ;; (anything 'anything-c-source-customize-face)
3508 ;; Color
3509 (defvar anything-c-source-colors
3510 '((name . "Colors")
3511 (init . (lambda () (unless (anything-candidate-buffer)
3512 (save-window-excursion (list-colors-display))
3513 (anything-candidate-buffer (get-buffer "*Colors*")))))
3514 (candidates-in-buffer)
3515 (get-line . buffer-substring)
3516 (action ("Copy Name" . (lambda (candidate)
3517 (kill-new (anything-c-colors-get-name candidate))))
3518 ("Copy RGB" . (lambda (candidate)
3519 (kill-new (anything-c-colors-get-rgb candidate))))
3520 ("Insert Name" . (lambda (candidate)
3521 (with-current-buffer anything-current-buffer
3522 (insert (anything-c-colors-get-name candidate)))))
3523 ("Insert RGB" . (lambda (candidate)
3524 (with-current-buffer anything-current-buffer
3525 (insert (anything-c-colors-get-rgb candidate))))))))
3526 ;; (anything 'anything-c-source-colors)
3528 (defun anything-c-colors-get-name (candidate)
3529 "Get color name."
3530 (replace-regexp-in-string
3531 " " ""
3532 (with-temp-buffer
3533 (insert (capitalize candidate))
3534 (goto-char (point-min))
3535 (search-forward-regexp "\\s-\\{2,\\}")
3536 (kill-line)
3537 (buffer-string))))
3539 (defun anything-c-colors-get-rgb (candidate)
3540 "Get color RGB."
3541 (replace-regexp-in-string
3542 " " ""
3543 (with-temp-buffer
3544 (insert (capitalize candidate))
3545 (goto-char (point-max))
3546 (search-backward-regexp "\\s-\\{2,\\}")
3547 (kill-region (point) (point-min))
3548 (buffer-string))))
3550 ;;;; <Search Engine>
3551 ;;; Tracker desktop search
3552 (defvar anything-c-source-tracker-search
3553 '((name . "Tracker Search")
3554 (candidates . (lambda ()
3555 (start-process "tracker-search-process" nil
3556 "tracker-search"
3557 anything-pattern)))
3558 (type . file)
3559 (requires-pattern . 3)
3560 (delayed))
3561 "Source for retrieving files matching the current input pattern
3562 with the tracker desktop search.")
3563 ;; (anything 'anything-c-source-tracker-search)
3565 ;;; Spotlight (MacOS X desktop search)
3566 (defvar anything-c-source-mac-spotlight
3567 '((name . "mdfind")
3568 (candidates . (lambda ()
3569 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
3570 (type . file)
3571 (requires-pattern . 3)
3572 (delayed))
3573 "Source for retrieving files via Spotlight's command line
3574 utility mdfind.")
3575 ;; (anything 'anything-c-source-mac-spotlight)
3578 ;;;; <Kill ring>
3579 ;;; Kill ring
3580 (defvar anything-c-source-kill-ring
3581 '((name . "Kill Ring")
3582 (init . (lambda () (anything-attrset 'last-command last-command)))
3583 (candidates . (lambda ()
3584 (loop for kill in kill-ring
3585 unless (or (< (length kill) anything-kill-ring-threshold)
3586 (string-match "^[\\s\\t]+$" kill))
3587 collect kill)))
3588 (action . anything-c-kill-ring-action)
3589 (last-command)
3590 (migemo)
3591 (multiline))
3592 "Source for browse and insert contents of kill-ring.")
3594 (defun anything-c-kill-ring-action (str)
3595 "Insert STR in `kill-ring' and set STR to the head.
3596 If this action is executed just after `yank', replace with STR as yanked string."
3597 (setq kill-ring (delete str kill-ring))
3598 (if (not (eq (anything-attr 'last-command) 'yank))
3599 (insert-for-yank str)
3600 ;; from `yank-pop'
3601 (let ((inhibit-read-only t)
3602 (before (< (point) (mark t))))
3603 (if before
3604 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
3605 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
3606 (setq yank-undo-function nil)
3607 (set-marker (mark-marker) (point) (current-buffer))
3608 (insert-for-yank str)
3609 ;; Set the window start back where it was in the yank command,
3610 ;; if possible.
3611 (set-window-start (selected-window) yank-window-start t)
3612 (if before
3613 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3614 ;; It is cleaner to avoid activation, even though the command
3615 ;; loop would deactivate the mark because we inserted text.
3616 (goto-char (prog1 (mark t)
3617 (set-marker (mark-marker) (point) (current-buffer)))))))
3618 (kill-new str))
3620 ;; (anything 'anything-c-source-kill-ring)
3622 ;;;; <Mark ring>
3623 ;; DO NOT include these sources in `anything-sources' use
3624 ;; the commands `anything-mark-ring' and `anything-global-mark-ring' instead.
3626 (defun anything-c-source-mark-ring-candidates ()
3627 (flet ((get-marks (pos)
3628 (save-excursion
3629 (goto-char pos)
3630 (beginning-of-line)
3631 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3632 (when (string= "" line)
3633 (setq line "<EMPTY LINE>"))
3634 (format "%7d: %s" (line-number-at-pos) line)))))
3635 (with-current-buffer anything-current-buffer
3636 (loop
3637 with marks = (cons (mark-marker) mark-ring)
3638 with recip = nil
3639 for i in marks
3640 for f = (get-marks i)
3641 if (not (member f recip))
3643 (push f recip)
3644 finally (return (reverse recip))))))
3646 (defvar anything-mark-ring-cache nil)
3647 (defvar anything-c-source-mark-ring
3648 '((name . "mark-ring")
3649 (init . (lambda ()
3650 (setq anything-mark-ring-cache
3651 (anything-c-source-mark-ring-candidates))))
3652 (candidates . (lambda ()
3653 (anything-aif anything-mark-ring-cache
3654 it)))
3655 (action . (("Goto line" . (lambda (candidate)
3656 (anything-goto-line (string-to-number candidate))))))
3657 (persistent-action . (lambda (candidate)
3658 (anything-goto-line (string-to-number candidate))
3659 (anything-match-line-color-current-line)))
3660 (persistent-help . "Show this line")))
3662 ;; (anything 'anything-c-source-mark-ring)
3664 ;;;###autoload
3665 (defun anything-mark-ring ()
3666 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3667 (interactive)
3668 (anything 'anything-c-source-mark-ring))
3670 ;;; Global-mark-ring
3671 (defvar anything-c-source-global-mark-ring
3672 '((name . "global-mark-ring")
3673 (candidates . anything-c-source-global-mark-ring-candidates)
3674 (action . (("Goto line" . (lambda (candidate)
3675 (let ((items (split-string candidate ":")))
3676 (switch-to-buffer (second items))
3677 (anything-goto-line (string-to-number (car items))))))))
3678 (persistent-action . (lambda (candidate)
3679 (let ((items (split-string candidate ":")))
3680 (switch-to-buffer (second items))
3681 (anything-goto-line (string-to-number (car items)))
3682 (anything-match-line-color-current-line))))
3683 (persistent-help . "Show this line")))
3685 (defun anything-c-source-global-mark-ring-candidates ()
3686 (flet ((buf-fn (m)
3687 (with-current-buffer (marker-buffer m)
3688 (goto-char m)
3689 (beginning-of-line)
3690 (let (line)
3691 (if (string= "" line)
3692 (setq line "<EMPTY LINE>")
3693 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3694 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
3695 (loop
3696 with marks = global-mark-ring
3697 with recip = nil
3698 for i in marks
3699 if (not (or (string-match "^ " (format "%s" (marker-buffer i)))
3700 (null (marker-buffer i))))
3701 for a = (buf-fn i)
3702 if (and a (not (member a recip)))
3704 (push a recip)
3705 finally (return (reverse recip)))))
3707 ;; (anything 'anything-c-source-global-mark-ring)
3709 ;;;###autoload
3710 (defun anything-global-mark-ring ()
3711 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
3712 (interactive)
3713 (anything 'anything-c-source-global-mark-ring))
3715 ;;;; <Register>
3716 ;;; Insert from register
3717 (defvar anything-c-source-register
3718 '((name . "Registers")
3719 (candidates . anything-c-register-candidates)
3720 (action-transformer . anything-c-register-action-transformer)
3721 (multiline)
3722 (action))
3723 "See (info \"(emacs)Registers\")")
3725 (defun anything-c-register-candidates ()
3726 "Collecting register contents and appropriate commands."
3727 (loop for (char . val) in register-alist
3728 for key = (single-key-description char)
3729 for string-actions = (cond
3730 ((numberp val)
3731 (list (int-to-string val)
3732 'insert-register
3733 'increment-register))
3734 ((markerp val)
3735 (let ((buf (marker-buffer val)))
3736 (if (null buf)
3737 (list "a marker in no buffer")
3738 (list (concat
3739 "a buffer position:"
3740 (buffer-name buf)
3741 ", position "
3742 (int-to-string (marker-position val)))
3743 'jump-to-register
3744 'insert-register))))
3745 ((and (consp val) (window-configuration-p (car val)))
3746 (list "window configuration."
3747 'jump-to-register))
3748 ((and (consp val) (frame-configuration-p (car val)))
3749 (list "frame configuration."
3750 'jump-to-register))
3751 ((and (consp val) (eq (car val) 'file))
3752 (list (concat "file:"
3753 (prin1-to-string (cdr val))
3754 ".")
3755 'jump-to-register))
3756 ((and (consp val) (eq (car val) 'file-query))
3757 (list (concat "file:a file-query reference: file "
3758 (car (cdr val))
3759 ", position "
3760 (int-to-string (car (cdr (cdr val))))
3761 ".")
3762 'jump-to-register))
3763 ((consp val)
3764 (let ((lines (format "%4d" (length val))))
3765 (list (format "%s: %s\n" lines
3766 (truncate-string-to-width
3767 (mapconcat 'identity (list (car val))
3768 ;; (mapconcat (lambda (y) y) val
3769 "^J") (- (window-width) 15)))
3770 'insert-register)))
3771 ((stringp val)
3772 (list ;; without properties
3773 (substring-no-properties val)
3774 'insert-register
3775 'append-to-register
3776 'prepend-to-register))
3778 "GARBAGE!"))
3779 collect (cons (format "register %3s: %s" key (car string-actions))
3780 (cons char (cdr string-actions)))))
3782 (defun anything-c-register-action-transformer (actions register-and-functions)
3783 "Decide actions by the contents of register."
3784 (loop with func-actions =
3785 '((insert-register
3786 "Insert Register" .
3787 (lambda (c) (insert-register (car c))))
3788 (jump-to-register
3789 "Jump to Register" .
3790 (lambda (c) (jump-to-register (car c))))
3791 (append-to-register
3792 "Append Region to Register" .
3793 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
3794 (prepend-to-register
3795 "Prepend Region to Register" .
3796 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
3797 (increment-register
3798 "Increment Prefix Arg to Register" .
3799 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
3800 for func in (cdr register-and-functions)
3801 for cell = (assq func func-actions)
3802 when cell
3803 collect (cdr cell)))
3805 ;; (anything 'anything-c-source-register)
3807 ;;;; <Headline Extraction>
3808 (defvar anything-c-source-fixme
3809 '((name . "TODO/FIXME/DRY comments")
3810 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
3811 (adjust)
3812 (recenter))
3813 "Show TODO/FIXME/DRY comments in current file.")
3814 ;; (anything 'anything-c-source-fixme)
3816 (defvar anything-c-source-rd-headline
3817 '((name . "RD HeadLine")
3818 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
3819 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
3820 (migemo)
3821 (subexp . 1))
3822 "Show RD headlines.
3824 RD is Ruby's POD.
3825 http://en.wikipedia.org/wiki/Ruby_Document_format")
3826 ;; (anything 'anything-c-source-rd-headline)
3828 (defvar anything-c-source-oddmuse-headline
3829 '((name . "Oddmuse HeadLine")
3830 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
3831 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
3832 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
3833 (migemo)
3834 (subexp . 1))
3835 "Show Oddmuse headlines, such as EmacsWiki.")
3836 ;; (anything 'anything-c-source-oddmuse-headline)
3838 (defvar anything-c-source-emacs-source-defun
3839 '((name . "Emacs Source DEFUN")
3840 (headline . "DEFUN\\|DEFVAR")
3841 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
3842 "Show DEFUN/DEFVAR in Emacs C source file.")
3843 ;; (anything 'anything-c-source-emacs-source-defun)
3845 (defvar anything-c-source-emacs-lisp-expectations
3846 '((name . "Emacs Lisp Expectations")
3847 (headline . "(desc[ ]\\|(expectations")
3848 (condition . (eq major-mode 'emacs-lisp-mode)))
3849 "Show descriptions (desc) in Emacs Lisp Expectations.
3851 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
3852 ;; (anything 'anything-c-source-emacs-lisp-expectations)
3854 (defvar anything-c-source-emacs-lisp-toplevels
3855 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
3856 (headline . "^(\\|(@\\*\\|^;;;;")
3857 (get-line . buffer-substring)
3858 (condition . (eq major-mode 'emacs-lisp-mode))
3859 (adjust))
3860 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
3861 linkd.el is optional because linkd stars are extracted by regexp.
3862 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
3863 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
3865 (defvar anything-c-source-org-headline
3866 '((name . "Org HeadLine")
3867 (headline
3868 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3869 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3870 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3871 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3872 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3873 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3874 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3875 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3876 (condition . (eq major-mode 'org-mode))
3877 (migemo)
3878 (subexp . 1)
3879 (persistent-action . (lambda (elm)
3880 (anything-c-action-line-goto elm)
3881 (org-cycle)))
3882 (action-transformer
3883 . (lambda (actions candidate)
3884 '(("Go to Line" . anything-c-action-line-goto)
3885 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
3886 "Show Org headlines.
3887 org-mode is very very much extended text-mode/outline-mode.
3889 See (find-library \"org.el\")
3890 See http://orgmode.org for the latest version.")
3892 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
3893 (insert
3894 (save-excursion
3895 (anything-goto-line (car lineno-and-content))
3896 (and (looking-at org-complex-heading-regexp)
3897 (org-make-link-string (concat "*" (match-string 4)))))))
3899 ;; (anything 'anything-c-source-org-headline)
3901 ;;; Anything yaoddmuse
3902 ;; Be sure to have yaoddmuse.el installed
3903 ;; install-elisp may be required if you want to install elisp file from here.
3904 (defvar anything-yaoddmuse-use-cache-file nil)
3905 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
3906 (defvar anything-c-yaoddmuse-ew-cache nil)
3907 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
3908 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
3909 (candidates . (lambda ()
3910 (if anything-yaoddmuse-use-cache-file
3911 (condition-case nil
3912 (progn
3913 (unless anything-c-yaoddmuse-ew-cache
3914 (load anything-c-yaoddmuse-cache-file)
3915 (setq anything-c-yaoddmuse-ew-cache
3916 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
3917 anything-c-yaoddmuse-ew-cache)
3918 (error nil))
3919 (yaoddmuse-update-pagename t)
3920 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
3921 (action . (("Edit page" . (lambda (candidate)
3922 (yaoddmuse-edit "EmacsWiki" candidate)))
3923 ("Browse page" . (lambda (candidate)
3924 (yaoddmuse-browse-page "EmacsWiki" candidate)))
3925 ("Browse page other window" . (lambda (candidate)
3926 (if (one-window-p)
3927 (split-window-vertically))
3928 (yaoddmuse-browse-page "EmacsWiki" candidate)))
3929 ("Browse diff" . (lambda (candidate)
3930 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
3931 ("Copy URL" . (lambda (candidate)
3932 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
3933 (message "Have copy page %s's URL to yank." candidate)))
3934 ("Create page" . (lambda (candidate)
3935 (yaoddmuse-edit "EmacsWiki" anything-input)))
3936 ("Update cache" . (lambda (candidate)
3937 (if anything-yaoddmuse-use-cache-file
3938 (progn
3939 (anything-yaoddmuse-cache-pages t)
3940 (setq anything-c-yaoddmuse-ew-cache
3941 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
3942 (yaoddmuse-update-pagename))))))
3943 (action-transformer anything-c-yaoddmuse-action-transformer)))
3945 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
3947 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
3948 '((name . "Yaoddmuse Post library (EmacsWiki)")
3949 (init . (anything-yaoddmuse-init))
3950 (candidates-in-buffer)
3951 (action . (("Post library and Browse" . (lambda (candidate)
3952 (yaoddmuse-post-file (find-library-name candidate)
3953 "EmacsWiki"
3954 (file-name-nondirectory (find-library-name candidate))
3955 nil t)))
3956 ("Post library" . (lambda (candidate)
3957 (yaoddmuse-post-file (find-library-name candidate)
3958 "EmacsWiki"
3959 (file-name-nondirectory (find-library-name candidate)))))))))
3961 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
3963 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
3964 "Allow the use of `install-elisp' only on elisp files."
3965 (if (string-match "\.el$" candidate)
3966 (append actions '(("Install Elisp" . (lambda (elm)
3967 (install-elisp-from-emacswiki elm)))))
3968 actions))
3970 ;;;###autoload
3971 (defun anything-yaoddmuse-cache-pages (&optional load)
3972 "Fetch the list of files on emacswiki and create cache file.
3973 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
3974 (interactive)
3975 (yaoddmuse-update-pagename)
3976 (save-excursion
3977 (find-file anything-c-yaoddmuse-cache-file)
3978 (erase-buffer)
3979 (insert "(puthash \"EmacsWiki\" '(")
3980 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
3982 (insert (concat "(\"" (car i) "\") ")))
3983 (insert ") yaoddmuse-pages-hash)\n")
3984 (save-buffer)
3985 (kill-buffer (current-buffer))
3986 (when (or current-prefix-arg
3987 load)
3988 (load anything-c-yaoddmuse-cache-file))))
3990 ;;;###autoload
3991 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
3992 "Preconfigured `anything' to edit or view EmacsWiki page."
3993 (interactive)
3994 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
3996 ;;;###autoload
3997 (defun anything-yaoddmuse-emacswiki-post-library ()
3998 "Preconfigured `anything' to post library to EmacsWiki."
3999 (interactive)
4000 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
4002 (defun anything-yaoddmuse-init ()
4003 "Init anything buffer status."
4004 (let ((anything-buffer (anything-candidate-buffer 'global))
4005 (library-list (yaoddmuse-get-library-list)))
4006 (with-current-buffer anything-buffer
4007 ;; Insert library name.
4008 (dolist (library library-list)
4009 (insert (format "%s\n" library)))
4010 ;; Sort lines.
4011 (sort-lines nil (point-min) (point-max)))))
4013 ;;; Eev anchors
4014 (defvar anything-c-source-eev-anchor
4015 '((name . "Anchors")
4016 (candidates
4017 . (lambda ()
4018 (ignore-errors
4019 (with-current-buffer anything-current-buffer
4020 (loop initially (goto-char (point-min))
4021 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
4022 for anchor = (match-string-no-properties 1)
4023 collect (cons (format "%5d:%s"
4024 (line-number-at-pos (match-beginning 0))
4025 (format ee-anchor-format anchor)) anchor))))))
4026 (persistent-action . (lambda (item)
4027 (ee-to item)
4028 (anything-match-line-color-current-line)))
4029 (persistent-help . "Show this entry")
4030 (action . (("Goto link" . ee-to)))))
4031 ;; (anything 'anything-c-source-eev-anchor)
4033 ;;;; <Misc>
4034 ;;; Org keywords
4035 (defvar anything-c-source-org-keywords
4036 '((name . "Org Keywords")
4037 (init . anything-c-org-keywords-init)
4038 (candidates . anything-c-org-keywords-candidates)
4039 (action . anything-c-org-keywords-insert)
4040 (persistent-action . anything-c-org-keywords-show-help)
4041 (persistent-help . "Show an example and info page to describe this keyword.")
4042 (keywords-examples)
4043 (keywords)))
4044 ;; (anything 'anything-c-source-org-keywords)
4045 (defvar anything-c-org-keywords-info-location
4046 '(("#+TITLE:" . "(org)Export options")
4047 ("#+AUTHOR:" . "(org)Export options")
4048 ("#+DATE:" . "(org)Export options")
4049 ("#+EMAIL:" . "(org)Export options")
4050 ("#+DESCRIPTION:" . "(org)Export options")
4051 ("#+KEYWORDS:" . "(org)Export options")
4052 ("#+LANGUAGE:" . "(org)Export options")
4053 ("#+TEXT:" . "(org)Export options")
4054 ("#+TEXT:" . "(org)Export options")
4055 ("#+OPTIONS:" . "(org)Export options")
4056 ("#+BIND:" . "(org)Export options")
4057 ("#+LINK_UP:" . "(org)Export options")
4058 ("#+LINK_HOME:" . "(org)Export options")
4059 ("#+LATEX_HEADER:" . "(org)Export options")
4060 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
4061 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
4062 ("#+INFOJS_OPT" . "(org)Javascript support")
4063 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
4064 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
4065 ("#+ORGTBL" . "(org)Radio tables")
4066 ("#+HTML:" . "(org)Quoting HTML tags")
4067 ("#+LaTeX:" . "(org)Quoting LaTeX code")
4068 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
4069 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
4070 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
4071 ("#+BEGIN_VERSE" . "(org)Paragraphs")
4072 ("#+BEGIN_SRC" . "(org)Literal examples")
4073 ("#+CAPTION" . "(org)Tables in HTML export")
4074 ("#+LABEL" . "(org)Tables in LaTeX export")
4075 ("#+ATTR_HTML" . "(org)Links")
4076 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
4078 (defun anything-c-org-keywords-init ()
4079 (unless (anything-attr 'keywords-examples)
4080 (require 'org)
4081 (anything-attrset 'keywords-examples
4082 (append
4083 (mapcar
4084 (lambda (x)
4085 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
4086 (cons (match-string 2 x) (match-string 1 x)))
4087 (org-split-string (org-get-current-options) "\n"))
4088 (mapcar 'list org-additional-option-like-keywords)))
4089 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
4091 (defun anything-c-org-keywords-candidates ()
4092 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
4093 (anything-attr 'keywords)))
4095 (defun anything-c-org-keywords-insert (keyword)
4096 (cond ((string-match "BEGIN" keyword)
4097 (insert "#+" keyword " ")
4098 (save-excursion
4099 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
4101 (insert "#+" keyword " "))))
4103 (defun anything-c-org-keywords-show-help (keyword)
4104 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
4105 "(org)In-buffer settings"))
4106 (search-forward (concat "#+" keyword) nil t)
4107 (anything-persistent-highlight-point)
4108 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
4111 ;;; Picklist
4112 (defvar anything-c-source-picklist
4113 '((name . "Picklist")
4114 (candidates . (lambda () (mapcar 'car picklist-list)))
4115 (type . file)))
4116 ;; (anything 'anything-c-source-picklist)
4118 ;;; BBDB
4119 (defun anything-c-bbdb-candidates ()
4120 "Return a list of all names in the bbdb database. The format
4121 is \"Firstname Lastname\"."
4122 (mapcar (lambda (bbdb-record)
4123 (replace-regexp-in-string
4124 "\\s-+$" ""
4125 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
4126 (bbdb-records)))
4128 (defun anything-c-bbdb-create-contact (actions candidate)
4129 "Action transformer that returns only an entry to add the
4130 current `anything-pattern' as new contact. All other actions are
4131 removed."
4132 (if (string= candidate "*Add to contacts*")
4133 '(("Add to contacts" . (lambda (actions)
4134 (bbdb-create-internal
4135 (read-from-minibuffer "Name: " anything-c-bbdb-name)
4136 (read-from-minibuffer "Company: ")
4137 (read-from-minibuffer "Email: ")
4140 (read-from-minibuffer "Note: ")))))
4141 actions))
4143 (defun anything-c-bbdb-get-record (candidate)
4144 "Return record that match CANDIDATE."
4145 (bbdb candidate nil)
4146 (set-buffer "*BBDB*")
4147 (bbdb-current-record))
4149 (defvar anything-c-bbdb-name nil
4150 "Only for internal use.")
4152 (defvar anything-c-source-bbdb
4153 '((name . "BBDB")
4154 (candidates . anything-c-bbdb-candidates)
4155 (action ("Send a mail" . anything-c-bbdb-compose-mail)
4156 ("View person's data" . anything-c-bbdb-view-person-action))
4157 (filtered-candidate-transformer . (lambda (candidates source)
4158 (setq anything-c-bbdb-name anything-pattern)
4159 (if (not candidates)
4160 (list "*Add to contacts*")
4161 candidates)))
4162 (action-transformer . (lambda (actions candidate)
4163 (anything-c-bbdb-create-contact actions candidate)))))
4164 ;; (anything 'anything-c-source-bbdb)
4166 (defun anything-c-bbdb-view-person-action (candidate)
4167 "View BBDB data of single CANDIDATE or marked candidates."
4168 (anything-aif (anything-marked-candidates)
4169 (let ((bbdb-append-records (length it)))
4170 (dolist (i it)
4171 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
4172 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
4174 (defun anything-c-bbdb-collect-mail-addresses ()
4175 "Return a list of all mail addresses of records in bbdb buffer."
4176 (with-current-buffer bbdb-buffer-name
4177 (loop for i in bbdb-records
4178 if (bbdb-record-net (car i))
4179 collect (bbdb-dwim-net-address (car i)))))
4181 (defun anything-c-bbdb-compose-mail (candidate)
4182 "Compose a mail with all records of bbdb buffer."
4183 (anything-c-bbdb-view-person-action candidate)
4184 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4185 (address-str (mapconcat 'identity address-list ",\n ")))
4186 (compose-mail address-str)))
4188 ;;; Evaluation Result
4189 (defvar anything-c-source-evaluation-result
4190 '((name . "Evaluation Result")
4191 (dummy)
4192 (filtered-candidate-transformer . (lambda (candidates source)
4193 (list
4194 (condition-case nil
4195 (pp-to-string
4196 (eval (read anything-pattern)))
4197 (error "Error")))))
4198 (action ("Do Nothing" . ignore))))
4199 ;; (anything 'anything-c-source-evaluation-result)
4201 ;;; Calculation Result
4202 (defvar anything-c-source-calculation-result
4203 '((name . "Calculation Result")
4204 (dummy)
4205 (filtered-candidate-transformer . (lambda (candidates source)
4206 (list
4207 (condition-case nil
4208 (calc-eval anything-pattern)
4209 (error "error")))))
4210 (action ("Copy result to kill-ring" . kill-new))))
4211 ;; (anything 'anything-c-source-calculation-result)
4213 ;;; Google Suggestions
4214 (defvar anything-gg-sug-lgh-flag 0)
4215 (defun anything-c-google-suggest-fetch (input)
4216 "Fetch suggestions for INPUT from XML buffer.
4217 Return an alist with elements like (data . number_results)."
4218 (let ((request (concat anything-c-google-suggest-url
4219 (url-hexify-string input))))
4220 (flet ((fetch ()
4221 (loop
4222 with result-alist = (xml-get-children
4223 (car (xml-parse-region (point-min) (point-max)))
4224 'CompleteSuggestion)
4225 for i in result-alist
4226 for data = (cdr (caadr (assoc 'suggestion i)))
4227 for nqueries = (cdr (caadr (assoc 'num_queries i)))
4228 for ldata = (length data)
4230 (when (> ldata anything-gg-sug-lgh-flag)
4231 (setq anything-gg-sug-lgh-flag ldata))
4232 collect (cons data nqueries) into cont
4233 finally return cont)))
4234 (if anything-google-suggest-use-curl-p
4235 (with-temp-buffer
4236 (call-process "curl" nil t nil request)
4237 (fetch))
4238 (with-current-buffer
4239 (url-retrieve-synchronously request)
4240 (fetch))))))
4243 (defun anything-c-google-suggest-set-candidates ()
4244 "Set candidates with result and number of google results found."
4245 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
4246 (setq suggestions (loop for i in suggestions
4247 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
4248 for elm = (concat (car i)
4249 (make-string (+ 2 interval) ? )
4250 "(" (cdr i) " results)")
4251 collect (cons elm (car i))))
4252 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
4253 suggestions
4254 ;; if there is no suggestion exactly matching the input then
4255 ;; prepend a Search on Google item to the list
4256 (append
4257 suggestions
4258 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
4259 anything-input))))))
4262 (defun anything-c-google-suggest-action (candidate)
4263 "Default action to jump to a google suggested candidate."
4264 (browse-url (concat anything-c-google-suggest-search-url
4265 (url-hexify-string candidate))))
4268 (defvar anything-c-source-google-suggest
4269 '((name . "Google Suggest")
4270 (candidates . anything-c-google-suggest-set-candidates)
4271 (action . (("Google Search" . anything-c-google-suggest-action)))
4272 (volatile)
4273 (requires-pattern . 3)
4274 (delayed)))
4276 ;; (anything 'anything-c-source-google-suggest)
4278 ;;; Yahoo suggestions
4280 (defun anything-c-yahoo-suggest-fetch (input)
4281 "Fetch Yahoo suggestions for INPUT from XML buffer.
4282 Return an alist with elements like (data . number_results)."
4283 (let ((request (concat anything-c-yahoo-suggest-url
4284 (url-hexify-string input))))
4285 (flet ((fetch ()
4286 (loop
4287 with result-alist = (xml-get-children
4288 (car (xml-parse-region (point-min) (point-max)))
4289 'Result)
4290 for i in result-alist
4291 collect (caddr i))))
4292 (with-current-buffer
4293 (url-retrieve-synchronously request)
4294 (fetch)))))
4296 (defun anything-c-yahoo-suggest-set-candidates ()
4297 "Set candidates with Yahoo results found."
4298 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
4299 (or suggestions
4300 (append
4301 suggestions
4302 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
4303 anything-input))))))
4305 (defun anything-c-yahoo-suggest-action (candidate)
4306 "Default action to jump to a Yahoo suggested candidate."
4307 (browse-url (concat anything-c-yahoo-suggest-search-url
4308 (url-hexify-string candidate))))
4310 (defvar anything-c-source-yahoo-suggest
4311 '((name . "Yahoo Suggest")
4312 (candidates . anything-c-yahoo-suggest-set-candidates)
4313 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
4314 (volatile)
4315 (requires-pattern . 3)
4316 (delayed)))
4318 ;; (anything 'anything-c-source-yahoo-suggest)
4320 ;;; Surfraw
4321 ;;; Need external program surfraw.
4322 ;;; http://surfraw.alioth.debian.org/
4323 ;; user variables
4324 (defvar anything-c-surfraw-favorites '("google" "wikipedia"
4325 "yahoo" "translate"
4326 "codesearch" "genpkg"
4327 "genportage" "fast"
4328 "currency")
4329 "All elements of this list will appear first in results.")
4330 (defvar anything-c-surfraw-use-only-favorites nil
4331 "If non-nil use only `anything-c-surfraw-favorites'.")
4334 (defun anything-c-build-elvi-alist ()
4335 "Build elvi alist.
4336 A list of search engines."
4337 (let* ((elvi-list
4338 (with-temp-buffer
4339 (call-process "surfraw" nil t nil
4340 "-elvi")
4341 (split-string (buffer-string) "\n")))
4342 (elvi-alist
4343 (let (line)
4344 (loop for i in elvi-list
4346 (setq line (split-string i))
4347 collect (cons (first line) (mapconcat #'(lambda (x) x) (cdr line) " "))))))
4348 elvi-alist))
4350 (defun anything-c-surfraw-sort-elvi (&optional only-fav)
4351 "Sort elvi alist according to `anything-c-surfraw-favorites'."
4352 (let* ((elvi-alist (anything-c-build-elvi-alist))
4353 (fav-alist (loop for j in anything-c-surfraw-favorites
4354 collect (assoc j elvi-alist)))
4355 (rest-elvi (loop for i in elvi-alist
4356 if (not (member i fav-alist))
4357 collect i)))
4358 (if only-fav
4359 fav-alist
4360 (append fav-alist rest-elvi))))
4362 (defun anything-c-surfraw-get-url (engine pattern)
4363 "Get search url from `engine' for `anything-pattern'."
4364 (with-temp-buffer
4365 (apply #'call-process "surfraw" nil t nil
4366 `(,engine
4367 "-p"
4368 ,anything-pattern))
4369 (buffer-string)))
4372 (defvar anything-c-surfraw-elvi nil)
4373 (defvar anything-c-surfraw-cache nil)
4374 (defvar anything-c-source-surfraw
4375 '((name . "Surfraw")
4376 (init . (lambda ()
4377 (unless anything-c-surfraw-cache
4378 (setq anything-c-surfraw-elvi (anything-c-surfraw-sort-elvi
4379 anything-c-surfraw-use-only-favorites))
4380 (setq anything-c-surfraw-cache
4381 (loop for i in anything-c-surfraw-elvi
4382 if (car i)
4383 collect (car i))))))
4384 (candidates . (lambda ()
4385 (loop for i in anything-c-surfraw-cache
4386 for s = (anything-c-surfraw-get-url i anything-pattern)
4387 collect (concat (propertize i
4388 'face '((:foreground "green"))
4389 'help-echo (cdr (assoc i anything-c-surfraw-elvi)))
4390 ">>>" (replace-regexp-in-string "\n" "" s)))))
4391 (action . (("Browse" . (lambda (candidate)
4392 (let ((url (second (split-string candidate ">>>"))))
4393 (browse-url url))))
4394 ("Browse firefox" . (lambda (candidate)
4395 (let ((url (second (split-string candidate ">>>"))))
4396 (browse-url-firefox url t))))))
4397 (volatile)
4398 (requires-pattern . 3)
4399 (multiline)
4400 (delayed)))
4402 ;; (anything 'anything-c-source-surfraw)
4404 ;;; Emms
4406 ;;;###autoload
4407 (defun anything-emms-stream-edit-bookmark (elm)
4408 "Change the information of current emms-stream bookmark from anything."
4409 (interactive)
4410 (let* ((cur-buf anything-current-buffer)
4411 (bookmark (assoc elm emms-stream-list))
4412 (name (read-from-minibuffer "Description: "
4413 (nth 0 bookmark)))
4414 (url (read-from-minibuffer "URL: "
4415 (nth 1 bookmark)))
4416 (fd (read-from-minibuffer "Feed Descriptor: "
4417 (int-to-string (nth 2 bookmark))))
4418 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4419 (format "%s" (car (last bookmark))))))
4420 (save-excursion
4421 (emms-streams)
4422 (when (re-search-forward (concat "^" name) nil t)
4423 (beginning-of-line)
4424 (emms-stream-delete-bookmark)
4425 (emms-stream-add-bookmark name url (string-to-number fd) type)
4426 (emms-stream-save-bookmarks-file)
4427 (emms-stream-quit)
4428 (switch-to-buffer cur-buf)))))
4430 (defun anything-emms-stream-delete-bookmark (elm)
4431 "Delete an emms-stream bookmark from anything."
4432 (interactive)
4433 (let* ((cur-buf anything-current-buffer)
4434 (bookmark (assoc elm emms-stream-list))
4435 (name (nth 0 bookmark)))
4436 (save-excursion
4437 (emms-streams)
4438 (when (re-search-forward (concat "^" name) nil t)
4439 (beginning-of-line)
4440 (emms-stream-delete-bookmark)
4441 (emms-stream-save-bookmarks-file)
4442 (emms-stream-quit)
4443 (switch-to-buffer cur-buf)))))
4445 (defvar anything-c-source-emms-streams
4446 '((name . "Emms Streams")
4447 (init . (lambda ()
4448 (emms-stream-init)))
4449 (candidates . (lambda ()
4450 (mapcar 'car emms-stream-list)))
4451 (action . (("Play" . (lambda (elm)
4452 (let* ((stream (assoc elm emms-stream-list))
4453 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
4454 (url (second stream)))
4455 (funcall fn url))))
4456 ("Delete" . anything-emms-stream-delete-bookmark)
4457 ("Edit" . anything-emms-stream-edit-bookmark)))
4458 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4459 ;; (anything 'anything-c-source-emms-streams)
4461 ;; Don't forget to set `emms-source-file-default-directory'
4462 (defvar anything-c-source-emms-dired
4463 '((name . "Music Directory")
4464 (candidates . (lambda ()
4465 (cddr (directory-files emms-source-file-default-directory))))
4466 (action .
4467 (("Play Directory" . (lambda (item)
4468 (emms-play-directory
4469 (expand-file-name
4470 item
4471 emms-source-file-default-directory))))
4472 ("Open dired in file's directory" . (lambda (item)
4473 (anything-c-open-dired
4474 (expand-file-name
4475 item
4476 emms-source-file-default-directory))))))
4477 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4478 ;; (anything 'anything-c-source-emms-dired)
4480 ;;; Jabber Contacts (jabber.el)
4481 (defun anything-c-jabber-online-contacts ()
4482 "List online Jabber contacts."
4483 (with-no-warnings
4484 (let (jids)
4485 (dolist (item (jabber-concat-rosters) jids)
4486 (when (get item 'connected)
4487 (push (if (get item 'name)
4488 (cons (get item 'name) item)
4489 (cons (symbol-name item) item)) jids))))))
4491 (defvar anything-c-source-jabber-contacts
4492 '((name . "Jabber Contacts")
4493 (init . (lambda () (require 'jabber)))
4494 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
4495 (action . (lambda (x)
4496 (jabber-chat-with
4497 (jabber-read-account)
4498 (symbol-name
4499 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
4500 ;; (anything 'anything-c-source-jabber-contacts)
4503 ;;; Call source.
4504 (defvar anything-source-select-buffer "*anything source select*")
4505 (defvar anything-c-source-call-source
4506 `((name . "Call anything source")
4507 (candidate-number-limit)
4508 (candidates . (lambda ()
4509 (loop for vname in (all-completions "anything-c-source-" obarray)
4510 for var = (intern vname)
4511 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
4512 if name collect (cons (format "%s `%s'"
4513 name (propertize vname 'face 'font-lock-variable-name-face))
4514 var))))
4515 (action . (("Invoke anything with selected source" .
4516 (lambda (candidate)
4517 (setq anything-candidate-number-limit 9999)
4518 (anything candidate nil nil nil nil
4519 anything-source-select-buffer)))
4520 ("Describe variable" . describe-variable)
4521 ("Find variable" . find-variable)))
4522 (persistent-action . describe-variable)
4523 (persistent-help . "Show description of this source")))
4524 ;; (anything 'anything-c-source-call-source)
4526 ;;;###autoload
4527 (defun anything-call-source ()
4528 "Preconfigured `anything' to call anything source."
4529 (interactive)
4530 (anything 'anything-c-source-call-source nil nil nil nil
4531 anything-source-select-buffer))
4533 (defun anything-call-source-from-anything ()
4534 "Call anything source within `anything' session."
4535 (interactive)
4536 (setq anything-input-idle-delay 0)
4537 (anything-set-sources '(anything-c-source-call-source)))
4539 ;;; Execute Preconfigured anything.
4540 (defvar anything-c-source-anything-commands
4541 '((name . "Preconfigured Anything")
4542 (candidates . anything-c-anything-commands-candidates)
4543 (type . command)
4544 (candidate-number-limit)))
4545 ;; (anything 'anything-c-source-anything-commands)
4547 (defun anything-c-anything-commands-candidates ()
4548 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
4549 collect (cons (substitute-command-keys (format "\\[%s] : %s" cmd desc))
4550 cmd)))
4552 ;;;###autoload
4553 (defun anything-execute-anything-command ()
4554 "Preconfigured `anything' to execute preconfigured `anything'."
4555 (interactive)
4556 (anything-other-buffer 'anything-c-source-anything-commands
4557 "*anything commands*"))
4559 ;; Occur
4561 (defun anything-c-occur-goto-line (candidate)
4562 "Goto line action for anything-c-source-occur."
4563 (anything-goto-line (string-to-number candidate)))
4565 (defun anything-c-occur-persistent-action (candidate)
4566 "Persistent action for anything occur source."
4567 (anything-c-occur-goto-line candidate)
4568 (anything-match-line-color-current-line))
4570 (defun anything-c-get-occur-candidates ()
4571 "Get `anything-c-source-occur' candidates."
4572 (with-temp-buffer
4573 (let ((count (occur-engine
4574 anything-pattern
4575 (list anything-current-buffer) (current-buffer)
4576 list-matching-lines-default-context-lines nil
4577 list-matching-lines-buffer-name-face
4578 nil list-matching-lines-face
4579 (not (eq occur-excluded-properties t)))))
4580 (when (> count 0)
4581 (cdr (split-string (buffer-string) "\n" t))))))
4583 (defvar anything-c-source-occur
4584 '((name . "Occur")
4585 (candidates . anything-c-get-occur-candidates)
4586 (persistent-action . anything-c-occur-persistent-action)
4587 (persistent-help . "Goto Line")
4588 (action . anything-c-occur-goto-line)
4589 (requires-pattern . 1)
4590 (delayed)
4591 (volatile)))
4592 ;; (anything 'anything-c-source-occur)
4594 ;;;###autoload
4595 (defun anything-occur ()
4596 "Preconfigured Anything for Occur source."
4597 (interactive)
4598 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*"))
4600 ;; Do many actions for input
4601 (defvar anything-c-source-create
4602 '((name . "Create")
4603 (dummy)
4604 (action)
4605 (candidate-number-limit . 9999)
4606 (action-transformer . anything-create--actions))
4607 "Do many create actions from `anything-pattern'.
4608 See also `anything-create--actions'.")
4609 ;; (anything 'anything-c-source-create)
4611 (defun anything-create-from-anything ()
4612 "Run `anything-create' from `anything' as a fallback."
4613 (interactive)
4614 (anything-run-after-quit 'anything-create nil anything-pattern))
4616 ;;;###autoload
4617 (defun anything-create (&optional string initial-input)
4618 "Preconfigured `anything' to do many create actions from STRING.
4619 See also `anything-create--actions'."
4620 (interactive)
4621 (setq string (or string (read-string "Create Anything: " initial-input)))
4622 (anything '(((name . "Anything Create")
4623 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
4624 (candidates . anything-create--actions)
4625 (candidate-number-limit . 9999)
4626 (action . (lambda (func) (funcall func string)))))))
4628 (defun anything-create--actions (&rest ignored)
4629 "Default actions for `anything-create' / `anything-c-source-create'."
4630 (remove-if-not
4631 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
4632 (append anything-create--actions-private
4633 '(("find-file" . find-file)
4634 ("find-file other window" . find-file-other-window)
4635 ("New buffer" . switch-to-buffer)
4636 ("New buffer other window" . switch-to-buffer-other-window)
4637 ("Bookmark Set" . bookmark-set)
4638 ("Set Register" .
4639 (lambda (x) (set-register (read-char "Register: ") x)))
4640 ("Insert Linkd star" . linkd-insert-star)
4641 ("Insert Linkd Tag" . linkd-insert-tag)
4642 ("Insert Linkd Link" . linkd-insert-link)
4643 ("Insert Linkd Lisp" . linkd-insert-lisp)
4644 ("Insert Linkd Wiki" . linkd-insert-wiki)
4645 ("Google Search" . google)))))
4647 ;; Minibuffer History
4648 (defvar anything-c-source-minibuffer-history
4649 '((name . "Minibuffer History")
4650 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
4651 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
4652 (if (consp (car history))
4653 (mapcar 'prin1-to-string history)
4654 history))))
4655 (migemo)
4656 (action . insert)))
4657 ;; (anything 'anything-c-source-minibuffer-history)
4659 ;; elscreen
4660 (defvar anything-c-source-elscreen
4661 '((name . "Elscreen")
4662 (candidates . (lambda ()
4663 (if (cdr (elscreen-get-screen-to-name-alist))
4664 (sort
4665 (loop for sname in (elscreen-get-screen-to-name-alist)
4666 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
4667 finally (return lst))
4668 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
4669 (action . (("Change Screen".
4670 (lambda (candidate)
4671 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
4672 ("Kill Screen(s)".
4673 (lambda (candidate)
4674 (dolist (i (anything-marked-candidates))
4675 (elscreen-goto (- (aref i 1) (aref "0" 0)))
4676 (elscreen-kill))))
4677 ("Only Screen".
4678 (lambda (candidate)
4679 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
4680 (elscreen-kill-others)))))))
4681 ;; (anything 'anything-c-source-elscreen)
4683 ;;;; <System>
4685 ;;; Top (process)
4686 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
4687 "Top command (batch mode). %s is replaced with `frame-width'.")
4688 (defvar anything-c-source-top
4689 '((name . "Top (Press C-c C-u to refresh)")
4690 (init . anything-c-top-init)
4691 (candidates-in-buffer)
4692 (display-to-real . anything-c-top-display-to-real)
4693 (update . anything-c-top-update)
4694 (action
4695 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
4696 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
4697 ("Copy PID" . (lambda (pid) (kill-new pid))))))
4698 ;; (anything 'anything-c-source-top)
4700 (defun anything-c-top-sh (cmd)
4701 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
4703 (defun anything-c-top-init ()
4704 (with-current-buffer (anything-candidate-buffer 'global)
4705 (call-process-shell-command
4706 (format anything-c-top-command
4707 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
4708 nil (current-buffer))))
4710 (defun anything-c-top-display-to-real (line)
4711 (car (split-string line)))
4713 (defun anything-c-top-update ()
4714 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
4715 (anything-c-top-init)))
4717 ;;;###autoload
4718 (defun anything-top ()
4719 "Preconfigured `anything' for top command."
4720 (interactive)
4721 (let ((anything-samewindow t)
4722 (anything-enable-shortcuts)
4723 (anything-display-function 'anything-default-display-buffer)
4724 (anything-candidate-number-limit 9999))
4725 (save-window-excursion
4726 (delete-other-windows)
4727 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
4729 ;;; Timers
4730 (defvar anything-c-source-absolute-time-timers
4731 '((name . "Absolute Time Timers")
4732 (candidates . timer-list)
4733 (type . timer)))
4734 ;; (anything 'anything-c-source-absolute-time-timers)
4736 (defvar anything-c-source-idle-time-timers
4737 '((name . "Idle Time Timers")
4738 (candidates . timer-idle-list)
4739 (type . timer)))
4740 ;; (anything 'anything-c-source-idle-time-timers)
4742 (defun anything-c-timer-real-to-display (timer)
4743 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
4744 (append timer nil) ;use `append' to convert vector->list
4745 (format "%s repeat=%5S %s(%s)"
4746 (let ((time (list t1 t2 t3)))
4747 (if idle-delay
4748 (format-time-string "idle-for=%5s" time)
4749 (format-time-string "%m/%d %T" time)))
4750 repeat-delay
4751 func
4752 (mapconcat 'prin1-to-string args " "))))
4754 ;;; X RandR resolution change
4755 ;;; FIXME I do not care multi-display.
4756 (defvar anything-c-xrandr-output "VGA")
4757 (defvar anything-c-xrandr-screen "0")
4758 (defvar anything-c-source-xrandr-change-resolution
4759 '((name . "Change Resolution")
4760 (candidates
4761 . (lambda ()
4762 (with-temp-buffer
4763 (call-process "xrandr" nil (current-buffer) nil
4764 "--screen" anything-c-xrandr-screen "-q")
4765 (goto-char 1)
4766 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
4767 collect (match-string 1)))))
4768 (action
4769 ("Change Resolution" . (lambda (mode)
4770 (call-process "xrandr" nil nil nil
4771 "--screen" anything-c-xrandr-screen
4772 "--output" anything-c-xrandr-output
4773 "--mode" mode))))))
4774 ;; (anything 'anything-c-source-xrandr-change-resolution)
4776 ;;; Xfont selection
4777 (defun anything-c-persistent-xfont-action (elm)
4778 "Show current font temporarily"
4779 (let ((current-font (cdr (assoc 'font (frame-parameters))))
4780 (default-font elm))
4781 (unwind-protect
4782 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
4783 (set-frame-font current-font))))
4785 (defvar anything-c-xfonts-cache nil)
4786 (defvar anything-c-source-xfonts
4787 '((name . "X Fonts")
4788 (init . (lambda ()
4789 (unless anything-c-xfonts-cache
4790 (setq anything-c-xfonts-cache
4791 (x-list-fonts "*")))))
4792 (candidates . anything-c-xfonts-cache)
4793 (action . (("Copy to kill ring" . (lambda (elm)
4794 (kill-new elm)))
4795 ("Set Font" . (lambda (elm)
4796 (kill-new elm)
4797 (set-frame-font elm 'keep-size)
4798 (message "New font have been copied to kill ring")))))
4799 (persistent-action . anything-c-persistent-xfont-action)
4800 (persistent-help . "Switch to this font temporarily")))
4802 ;;;###autoload
4803 (defun anything-select-xfont ()
4804 "Preconfigured `anything' to select Xfont."
4805 (interactive)
4806 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
4808 ;; (anything 'anything-c-source-xfonts)
4810 ;;; Source for Debian/Ubuntu users
4811 (defvar anything-c-source-apt
4812 '((name . "APT")
4813 (init . anything-c-apt-init)
4814 (candidates-in-buffer)
4815 (candidate-transformer anything-c-apt-candidate-transformer)
4816 (display-to-real . anything-c-apt-display-to-real)
4817 (candidate-number-limit . 9999)
4818 (action
4819 ("Show package description" . anything-c-apt-cache-show)
4820 ("Install package" . anything-c-apt-install)
4821 ("Remove package" . anything-c-apt-uninstall)
4822 ("Purge package" . anything-c-apt-purge))
4823 (persistent-action . anything-c-apt-persistent-action)
4824 (persistent-help . "Show - C-u Refresh")))
4825 ;; (anything 'anything-c-source-apt)
4827 (defvar anything-c-apt-query "emacs")
4828 (defvar anything-c-apt-search-command "apt-cache search '%s'")
4829 (defvar anything-c-apt-show-command "apt-cache show '%s'")
4830 (defvar anything-c-apt-installed-packages nil)
4832 (defface anything-apt-installed
4833 '((t (:foreground "green")))
4834 "*Face used for apt installed candidates."
4835 :group 'anything)
4837 (defun anything-c-apt-refresh ()
4838 "Refresh installed candidates list."
4839 (setq anything-c-apt-installed-packages nil)
4840 (anything-force-update))
4842 (defun anything-c-apt-persistent-action (candidate)
4843 "Persistent action for APT source."
4844 (if current-prefix-arg
4845 (anything-c-apt-refresh)
4846 (anything-c-apt-cache-show candidate)))
4848 ;;;###autoload
4849 (defun anything-apt (query)
4850 "Preconfigured `anything' : frontend of APT package manager."
4851 (interactive "sAPT search: ")
4852 (let ((anything-c-apt-query query))
4853 (anything 'anything-c-source-apt)))
4855 (defun anything-c-apt-candidate-transformer (candidates)
4856 "Show installed candidates in a different color."
4857 (loop
4858 with all
4859 for cand in candidates
4860 for name = (anything-c-apt-display-to-real cand)
4861 if (member name anything-c-apt-installed-packages)
4862 collect (propertize cand 'face 'anything-apt-installed) into all
4863 else collect cand into all finally return all))
4865 (defun anything-c-apt-init ()
4866 "Initialize list of debian packages."
4867 (unless anything-c-apt-installed-packages
4868 (message "Updating installed candidate list...")
4869 (setq anything-c-apt-installed-packages
4870 (with-temp-buffer
4871 (call-process-shell-command "dpkg --get-selections"
4872 nil (current-buffer))
4873 (loop for i in (split-string (buffer-string) "\n" t)
4874 collect (car (split-string i))))))
4875 (with-current-buffer
4876 (anything-candidate-buffer
4877 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
4878 (erase-buffer)
4879 (call-process-shell-command
4880 (format anything-c-apt-search-command anything-c-apt-query)
4881 nil (current-buffer)))
4882 (message "Updating installed candidate list...done"))
4884 (defun anything-c-apt-display-to-real (line)
4885 "Return only name of a debian package.
4886 LINE is displayed like:
4887 package name - description."
4888 (car (split-string line " - ")))
4890 ;;;###autoload
4891 (defun anything-c-shell-command-if-needed (command)
4892 (interactive "sShell command: ")
4893 (if (get-buffer command) ; if the buffer already exists
4894 (switch-to-buffer command) ; then just switch to it
4895 (switch-to-buffer command) ; otherwise create it
4896 (insert (shell-command-to-string command))))
4898 (defun anything-c-apt-cache-show (package)
4899 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
4901 (defun anything-c-apt-install (package)
4902 (anything-c-apt-install1 package :action 'install))
4904 (defun anything-c-apt-uninstall (package)
4905 (anything-c-apt-install1 package :action 'uninstall))
4907 (defun anything-c-apt-purge (package)
4908 (anything-c-apt-install1 package :action 'purge))
4910 (defun* anything-c-apt-install1 (candidate &key action)
4911 (ansi-term (getenv "SHELL") "anything apt")
4912 (term-line-mode)
4913 (let ((command (case action
4914 ('install "sudo apt-get install '%s'")
4915 ('uninstall "sudo apt-get remove '%s'")
4916 ('purge "sudo apt-get purge '%s'")
4917 (t (error "Unknow action"))))
4918 (beg (point)) end)
4919 (goto-char (point-max))
4920 (insert (format command candidate))
4921 (setq end (point))
4922 (if (y-or-n-p (format "%s package" (symbol-name action)))
4923 (progn
4924 (setq anything-c-external-commands-list nil)
4925 (setq anything-c-apt-installed-packages nil)
4926 (term-char-mode) (term-send-input))
4927 (delete-region beg end) (term-send-eof) (kill-buffer))))
4929 ;; (anything-c-apt-install "jed")
4931 ;;; Sources for gentoo users
4932 (defvar anything-c-gentoo-use-flags nil)
4933 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
4934 (defvar anything-c-cache-gentoo nil)
4935 (defvar anything-c-cache-world nil)
4936 (defvar anything-c-source-gentoo
4937 '((name . "Portage sources")
4938 (init . (lambda ()
4939 (get-buffer-create anything-c-gentoo-buffer)
4940 (unless anything-c-cache-gentoo
4941 (anything-c-gentoo-setup-cache))
4942 (unless anything-c-cache-world
4943 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
4944 (anything-c-gentoo-init-list)))
4945 (candidates-in-buffer)
4946 (match . identity)
4947 (candidate-transformer anything-c-highlight-world)
4948 (action . (("Show package" . (lambda (elm)
4949 (anything-c-gentoo-eshell-action elm "eix")))
4950 ("Show history" . (lambda (elm)
4951 (if (member elm anything-c-cache-world)
4952 (anything-c-gentoo-eshell-action elm "genlop -qe")
4953 (message "No infos on packages not yet installed"))))
4954 ("Copy in kill-ring" . kill-new)
4955 ("insert at point" . insert)
4956 ("Browse HomePage" . (lambda (elm)
4957 (let ((urls (anything-c-gentoo-get-url elm)))
4958 (browse-url (anything-comp-read "Url: " urls)))))
4959 ("Show extra infos" . (lambda (elm)
4960 (if (member elm anything-c-cache-world)
4961 (anything-c-gentoo-eshell-action elm "genlop -qi")
4962 (message "No infos on packages not yet installed"))))
4963 ("Show use flags" . (lambda (elm)
4964 (anything-c-gentoo-default-action elm "equery" "-C" "u")
4965 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
4966 (font-lock-mode 1)))
4967 ("Run emerge pretend" . (lambda (elm)
4968 (anything-c-gentoo-eshell-action elm "emerge -p")))
4969 ("Emerge" . (lambda (elm)
4970 (anything-gentoo-install elm :action 'install)))
4971 ("Unmerge" . (lambda (elm)
4972 (anything-gentoo-install elm :action 'uninstall)))
4973 ("Show dependencies" . (lambda (elm)
4974 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
4975 ("Show related files" . (lambda (elm)
4976 (anything-c-gentoo-default-action elm "equery" "files")))
4977 ("Refresh" . (lambda (elm)
4978 (anything-c-gentoo-setup-cache)
4979 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
4981 ;; (anything 'anything-c-source-gentoo)
4983 (defun* anything-gentoo-install (candidate &key action)
4984 (setq anything-c-external-commands-list nil)
4985 (ansi-term (getenv "SHELL") "anything gentoo")
4986 (term-line-mode)
4987 (let ((command (case action
4988 ('install "sudo emerge -av ")
4989 ('uninstall "sudo emerge -avC ")
4990 (t (error "Unknow action"))))
4991 (elms (mapconcat 'identity (anything-marked-candidates) " "))
4992 (beg (point)) end)
4993 (goto-char (point-max))
4994 (insert (concat command elms))
4995 (setq end (point))
4996 (term-char-mode) (term-send-input)))
4998 (defun anything-c-gentoo-default-action (elm command &rest args)
4999 "Gentoo default action that use `anything-c-gentoo-buffer'."
5000 (if (member elm anything-c-cache-world)
5001 (progn
5002 (switch-to-buffer anything-c-gentoo-buffer)
5003 (erase-buffer)
5004 (let ((com-list (append args (list elm))))
5005 (apply #'call-process command nil t nil
5006 com-list)))
5007 (message "No infos on packages not yet installed")))
5009 (defvar anything-c-source-use-flags
5010 '((name . "Use Flags")
5011 (init . (lambda ()
5012 (unless anything-c-gentoo-use-flags
5013 (anything-c-gentoo-setup-use-flags-cache))
5014 (anything-c-gentoo-get-use)))
5015 (candidates-in-buffer)
5016 (match . identity)
5017 (candidate-transformer anything-c-highlight-local-use)
5018 (action . (("Description"
5019 . (lambda (elm)
5020 (switch-to-buffer anything-c-gentoo-buffer)
5021 (erase-buffer)
5022 (apply #'call-process "euse" nil t nil
5023 `("-i"
5024 ,elm))
5025 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
5026 (font-lock-mode 1)))
5027 ("Enable"
5028 . (lambda (elm)
5029 (anything-c-gentoo-eshell-action elm "*sudo euse -E")))
5030 ("Disable"
5031 . (lambda (elm)
5032 (anything-c-gentoo-eshell-action elm "*sudo euse -D")))
5033 ("Remove"
5034 . (lambda (elm)
5035 (anything-c-gentoo-eshell-action elm "*sudo euse -P")))
5036 ("Show which dep use this flag"
5037 . (lambda (elm)
5038 (switch-to-buffer anything-c-gentoo-buffer)
5039 (erase-buffer)
5040 (apply #'call-process "equery" nil t nil
5041 `("-C"
5043 ,elm))))))))
5046 ;; (anything 'anything-c-source-use-flags)
5048 (defun anything-c-gentoo-init-list ()
5049 "Initialize buffer with all packages in Portage."
5050 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
5051 (buf (anything-candidate-buffer 'portage-buf)))
5052 (with-current-buffer buf
5053 (dolist (i anything-c-cache-gentoo)
5054 (insert (concat i "\n"))))))
5056 (defun anything-c-gentoo-setup-cache ()
5057 "Set up `anything-c-cache-gentoo'"
5058 (setq anything-c-cache-gentoo
5059 (split-string (with-temp-buffer
5060 (call-process "eix" nil t nil
5061 "--only-names")
5062 (buffer-string)))))
5064 (defun anything-c-gentoo-eshell-action (elm command)
5065 (when (get-buffer "*EShell Command Output*")
5066 (kill-buffer "*EShell Command Output*"))
5067 (message "Wait searching...")
5068 (let ((buf-fname (buffer-file-name anything-current-buffer)))
5069 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
5070 (progn
5071 (save-window-excursion
5072 (pop-to-buffer "*scratch*")
5073 (eshell-command (format "%s %s" command elm)))
5074 (pop-to-buffer "*EShell Command Output*"))
5075 (eshell-command (format "%s %s" command elm)))))
5077 (defun anything-c-gentoo-get-use ()
5078 "Initialize buffer with all use flags."
5079 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
5080 (buf (anything-candidate-buffer 'use-buf)))
5081 (with-current-buffer buf
5082 (dolist (i anything-c-gentoo-use-flags)
5083 (insert (concat i "\n"))))))
5086 (defun anything-c-gentoo-setup-use-flags-cache ()
5087 "Setup `anything-c-gentoo-use-flags'"
5088 (setq anything-c-gentoo-use-flags
5089 (split-string (with-temp-buffer
5090 (call-process "eix" nil t nil
5091 "--print-all-useflags")
5092 (buffer-string)))))
5094 (defun anything-c-gentoo-get-url (elm)
5095 "Return a list of urls from eix output."
5096 (loop
5097 with url-list = (split-string
5098 (with-temp-buffer
5099 (call-process "eix" nil t nil
5100 elm "--format" "<homepage>\n")
5101 (buffer-string)))
5102 with all
5103 for i in url-list
5104 when (and (string-match "^http://.*" i)
5105 (not (member i all)))
5106 collect i into all
5107 finally return all))
5109 (defun anything-c-gentoo-get-world ()
5110 "Return list of all installed package on your system."
5111 (split-string (with-temp-buffer
5112 (call-process "qlist" nil t nil
5113 "-I")
5114 (buffer-string))))
5116 (defun anything-c-gentoo-get-local-use ()
5117 (split-string (with-temp-buffer
5118 (call-process "portageq" nil t nil
5119 "envvar"
5120 "USE")
5121 (buffer-string))))
5123 (defface anything-gentoo-match-face '((t (:foreground "red")))
5124 "Face for anything-gentoo installed packages."
5125 :group 'traverse-faces)
5127 (defun anything-c-highlight-world (eix)
5128 "Highlight all installed package."
5129 (loop for i in eix
5130 if (member i anything-c-cache-world)
5131 collect (propertize i 'face 'anything-gentoo-match-face)
5132 else
5133 collect i))
5135 (defun anything-c-highlight-local-use (use-flags)
5136 (let ((local-uses (anything-c-gentoo-get-local-use)))
5137 (loop for i in use-flags
5138 if (member i local-uses)
5139 collect (propertize i 'face 'anything-gentoo-match-face)
5140 else
5141 collect i)))
5143 (defvar anything-c-source-emacs-process
5144 '((name . "Emacs Process")
5145 (candidates . (lambda () (mapcar #'process-name (process-list))))
5146 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
5148 ;; (anything 'anything-c-source-emacs-process)
5150 ;; Run Externals commands within Emacs
5151 (defmacro* anything-comp-hash-get-items (hash-table &key test)
5152 "Get the list of all keys/values of hash-table."
5153 `(let ((li-items ()))
5154 (maphash #'(lambda (x y)
5155 (if ,test
5156 (when (funcall ,test y)
5157 (push (list x y) li-items))
5158 (push (list x y) li-items)))
5159 ,hash-table)
5160 li-items))
5162 (defun anything-comp-read-get-candidates (collection &optional test)
5163 "Convert collection to list.
5164 If collection is an `obarray', a test is maybe needed, otherwise
5165 the list would be incomplete.
5166 See `obarray'."
5167 (cond ((and (listp collection) test)
5168 (loop for i in collection
5169 when (funcall test i) collect i))
5170 ((and (vectorp collection) test)
5171 (let (ob)
5172 (mapatoms
5173 #'(lambda (s)
5174 (when (funcall test s) (push s ob))))
5175 ob))
5176 ((and (hash-table-p collection) test)
5177 (anything-comp-hash-get-items collection :test test))
5178 ((vectorp collection)
5179 (loop for i across collection collect i))
5180 ((hash-table-p collection)
5181 (anything-comp-hash-get-items collection))
5182 (t collection)))
5184 (defun* anything-comp-read (prompt collection &key test initial-input
5185 (buffer "*Anything Completions*") must-match)
5186 "Anything `completing-read' emulation.
5187 Collection can be a list, vector, obarray or hash-table."
5188 (when (get-buffer anything-action-buffer)
5189 (kill-buffer anything-action-buffer))
5190 (or (anything
5191 `((name . "Completions")
5192 (candidates
5193 . (lambda ()
5194 (let ((cands (anything-comp-read-get-candidates collection test)))
5195 (if (or must-match (string= anything-pattern ""))
5196 cands (append (list anything-pattern) cands)))))
5197 (volatile)
5198 (action . (("candidate" . ,'identity))))
5199 initial-input prompt 'noresume nil buffer)
5200 (keyboard-quit)))
5202 (defun anything-c-get-pid-from-process-name (process-name)
5203 "Get pid from running process PROCESS-NAME."
5204 (let ((process-list (list-system-processes)))
5205 (catch 'break
5206 (dolist (i process-list)
5207 (let ((process-attr (process-attributes i)))
5208 (when process-attr
5209 (when (string-match process-name
5210 (cdr (assq 'comm
5211 process-attr)))
5212 (throw 'break
5213 i))))))))
5216 ;;;###autoload
5217 (defun anything-c-run-external-command (program)
5218 "Run External PROGRAM asyncronously from Emacs.
5219 If program is already running exit with error.
5220 You can set your own list of commands with
5221 `anything-c-external-commands-list'."
5222 (interactive (list
5223 (anything-comp-read
5224 "RunProgram: "
5225 (anything-c-external-commands-list-1 'sort)
5226 :must-match t)))
5227 (if (or (get-process program)
5228 (anything-c-get-pid-from-process-name program))
5229 (error "Error: %s is already running" program)
5230 (message "Starting %s..." program)
5231 (start-process-shell-command program nil program)
5232 (set-process-sentinel
5233 (get-process program)
5234 #'(lambda (process event)
5235 (when (string= event "finished\n")
5236 (message "%s process...Finished." process)
5237 (when anything-back-to-emacs-shell-command
5238 (shell-command anything-back-to-emacs-shell-command)))))
5239 (setq anything-c-external-commands-list
5240 (push (pop (nthcdr (anything-c-position
5241 program anything-c-external-commands-list
5242 :test 'equal)
5243 anything-c-external-commands-list))
5244 anything-c-external-commands-list))))
5246 (defsubst* anything-c-position (item seq &key (test 'eq))
5247 "A simple and faster replacement of CL `position'."
5248 (loop for i in seq for index from 0
5249 when (funcall test i item) return index))
5251 (defvar anything-c-source-ratpoison-commands
5252 '((name . "Ratpoison Commands")
5253 (init . anything-c-ratpoison-commands-init)
5254 (candidates-in-buffer)
5255 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
5256 (display-to-real . anything-c-ratpoison-commands-display-to-real)
5257 (candidate-number-limit)))
5258 ;; (anything 'anything-c-source-ratpoison-commands)
5260 (defun anything-c-ratpoison-commands-init ()
5261 (unless (anything-candidate-buffer)
5262 (with-current-buffer (anything-candidate-buffer 'global)
5263 ;; with ratpoison prefix key
5264 (save-excursion
5265 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
5266 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5267 (replace-match "<ratpoison> \\1: \\2"))
5268 (goto-char (point-max))
5269 ;; direct binding
5270 (save-excursion
5271 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
5272 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5273 (replace-match "\\1: \\2")))))
5275 (defun anything-c-ratpoison-commands-display-to-real (display)
5276 (and (string-match ": " display)
5277 (substring display (match-end 0))))
5279 (defun anything-c-ratpoison-commands-execute (candidate)
5280 (call-process "ratpoison" nil nil nil "-ic" candidate))
5282 ;;;###autoload
5283 (defun anything-ratpoison-commands ()
5284 "Preconfigured `anything' to execute ratpoison commands."
5285 (interactive)
5286 (anything-other-buffer 'anything-c-source-ratpoison-commands
5287 "*anything ratpoison commands*"))
5289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5290 ;;; Files
5291 (defvar anything-c-external-commands-list nil
5292 "A list of all external commands the user can execute. If this
5293 variable is not set by the user, it will be calculated
5294 automatically.")
5296 (defun anything-c-external-commands-list-1 (&optional sort)
5297 "Returns a list of all external commands the user can execute.
5299 If `anything-c-external-commands-list' is non-nil it will
5300 return its contents. Else it calculates all external commands
5301 and sets `anything-c-external-commands-list'.
5303 The code is ripped out of `eshell-complete-commands-list'."
5304 (if anything-c-external-commands-list
5305 anything-c-external-commands-list
5306 (setq anything-c-external-commands-list
5307 (let* ((paths (split-string (getenv "PATH") path-separator))
5308 (cwd (file-name-as-directory
5309 (expand-file-name default-directory)))
5310 (path "") (comps-in-path ())
5311 (file "") (filepath "") (completions ()))
5312 ;; Go thru each path in the search path, finding completions.
5313 (while paths
5314 (setq path (file-name-as-directory
5315 (expand-file-name (or (car paths) ".")))
5316 comps-in-path
5317 (and (file-accessible-directory-p path)
5318 (file-name-all-completions "" path)))
5319 ;; Go thru each completion found, to see whether it should be
5320 ;; used, e.g. see if it's executable.
5321 (while comps-in-path
5322 (setq file (car comps-in-path)
5323 filepath (concat path file))
5324 (if (and (not (member file completions))
5325 (or (string-equal path cwd)
5326 (not (file-directory-p filepath)))
5327 (file-executable-p filepath))
5328 (setq completions (cons file completions)))
5329 (setq comps-in-path (cdr comps-in-path)))
5330 (setq paths (cdr paths)))
5331 (if sort
5332 (sort completions #'(lambda (x y) (string< x y)))
5333 completions)))))
5335 (defun anything-c-file-buffers (filename)
5336 "Returns a list of buffer names corresponding to FILENAME."
5337 (let ((name (expand-file-name filename))
5338 (buf-list ()))
5339 (dolist (buf (buffer-list) buf-list)
5340 (let ((bfn (buffer-file-name buf)))
5341 (when (and bfn (string= name bfn))
5342 (push (buffer-name buf) buf-list))))))
5344 (defun anything-c-delete-file (file)
5345 "Delete the given file after querying the user.
5346 Ask to kill buffers associated with that file, too."
5347 (let ((buffers (anything-c-file-buffers file)))
5348 (dired-delete-file file 'dired-recursive-deletes)
5349 (when buffers
5350 (dolist (buf buffers)
5351 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
5352 (kill-buffer buf))))))
5354 (defun anything-get-mailcap-for-file (filename)
5355 "Get the command to use for FILENAME from mailcap file.
5356 The command is like <command %s> and is meant to use with `format'."
5357 (let* ((ext (file-name-extension filename))
5358 (mime (when ext (mailcap-extension-to-mime ext))))
5359 (when mime (mailcap-mime-info mime))))
5361 (defun anything-c-open-file-externally (file)
5362 "Open FILE with an external tool found in .mailcap file.
5363 If not found or a prefix arg is given query the user which tool to use."
5364 (let* ((fname (expand-file-name file))
5365 (collection (anything-c-external-commands-list-1 'sort))
5366 (def-prog (anything-get-mailcap-for-file fname))
5367 (program (or (unless (or anything-current-prefix-arg
5368 (not def-prog))
5369 def-prog)
5370 (concat
5371 (anything-comp-read
5372 "Program: "
5373 collection :must-match t)
5374 " %s")))
5375 (progname (replace-regexp-in-string " %s" "" program))
5376 (process (format "%s-%s" progname fname)))
5377 (start-process-shell-command process
5378 nil (format program fname))
5379 (when (member progname anything-c-external-commands-list)
5380 (setq anything-c-external-commands-list
5381 (push (pop (nthcdr (anything-c-position
5382 progname anything-c-external-commands-list
5383 :test 'equal)
5384 anything-c-external-commands-list))
5385 anything-c-external-commands-list)))))
5387 ;;;###autoload
5388 (defun w32-shell-execute-open-file (file)
5389 (interactive "fOpen file:")
5390 (with-no-warnings
5391 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
5392 "/" "\\"
5393 (replace-regexp-in-string ; strip cygdrive paths
5394 "/cygdrive/\\(.\\)" "\\1:"
5395 file nil nil) nil t))))
5397 (defun anything-c-open-file-with-default-tool (file)
5398 "Open FILE with the default tool on this platform."
5399 (if (eq system-type 'windows-nt)
5400 (w32-shell-execute-open-file file)
5401 (start-process "anything-c-open-file-with-default-tool"
5403 (cond ((eq system-type 'gnu/linux)
5404 "xdg-open")
5405 ((or (eq system-type 'darwin) ;; Mac OS X
5406 (eq system-type 'macos)) ;; Mac OS 9
5407 "open"))
5408 file)))
5410 (defun anything-c-open-dired (file)
5411 "Opens a dired buffer in FILE's directory. If FILE is a
5412 directory, open this directory."
5413 (if (file-directory-p file)
5414 (dired file)
5415 (dired (file-name-directory file))
5416 (dired-goto-file file)))
5418 (defun anything-c-display-to-real-line (candidate)
5419 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
5420 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
5421 (error "Line number not found")))
5423 (defun anything-c-action-line-goto (lineno-and-content)
5424 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
5425 (append lineno-and-content
5426 (list (if (and (anything-attr-defined 'target-file)
5427 (not anything-in-persistent-action))
5428 'find-file-other-window
5429 'find-file)))))
5431 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
5432 (apply #'anything-goto-file-line file-line-content))
5434 (require 'compile)
5435 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
5436 (mapcar
5437 (lambda (candidate)
5438 (if (not (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate))
5439 (error "Filename and line number not found")
5440 (let ((filename (match-string 1 candidate))
5441 (lineno (match-string 2 candidate))
5442 (content (match-string 3 candidate)))
5443 (cons (format "%s:%s\n %s"
5444 (propertize filename 'face compilation-info-face)
5445 (propertize lineno 'face compilation-line-face)
5446 content)
5447 (list (expand-file-name
5448 filename
5449 (or (anything-interpret-value (anything-attr 'default-directory))
5450 (and (anything-candidate-buffer)
5451 (buffer-local-value
5452 'default-directory (anything-candidate-buffer)))))
5453 (string-to-number lineno) content)))))
5454 candidates))
5456 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
5457 (anything-aif (anything-attr 'before-jump-hook)
5458 (funcall it))
5459 (when file (funcall find-file-function file))
5460 (if (anything-attr-defined 'adjust)
5461 (anything-c-goto-line-with-adjustment lineno content)
5462 (anything-goto-line lineno))
5463 (unless (anything-attr-defined 'recenter)
5464 (set-window-start (get-buffer-window anything-current-buffer) (point)))
5465 (anything-aif (anything-attr 'after-jump-hook)
5466 (funcall it))
5467 (when anything-in-persistent-action
5468 (anything-match-line-color-current-line)))
5470 (defun anything-find-file-as-root (candidate)
5471 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
5473 (defun anything-find-many-files (ignore)
5474 (mapc 'find-file (anything-marked-candidates)))
5476 ;; borrowed from etags.el
5477 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
5478 (defun anything-c-goto-line-with-adjustment (line line-content)
5479 (let ((startpos)
5480 offset found pat)
5481 ;; This constant is 1/2 the initial search window.
5482 ;; There is no sense in making it too small,
5483 ;; since just going around the loop once probably
5484 ;; costs about as much as searching 2000 chars.
5485 (setq offset 1000
5486 found nil
5487 pat (concat (if (eq selective-display t)
5488 "\\(^\\|\^m\\) *" "^ *") ;allow indent
5489 (regexp-quote line-content)))
5490 ;; If no char pos was given, try the given line number.
5491 (setq startpos (progn (anything-goto-line line) (point)))
5492 (or startpos (setq startpos (point-min)))
5493 ;; First see if the tag is right at the specified location.
5494 (goto-char startpos)
5495 (setq found (looking-at pat))
5496 (while (and (not found)
5497 (progn
5498 (goto-char (- startpos offset))
5499 (not (bobp))))
5500 (setq found
5501 (re-search-forward pat (+ startpos offset) t)
5502 offset (* 3 offset))) ; expand search window
5503 (or found
5504 (re-search-forward pat nil t)
5505 (error "not found")))
5506 ;; Position point at the right place
5507 ;; if the search string matched an extra Ctrl-m at the beginning.
5508 (and (eq selective-display t)
5509 (looking-at "\^m")
5510 (forward-char 1))
5511 (beginning-of-line))
5513 (anything-document-attribute 'default-directory "type . file-line"
5514 "`default-directory' to interpret file.")
5515 (anything-document-attribute 'before-jump-hook "type . file-line / line"
5516 "Function to call before jumping to the target location.")
5517 (anything-document-attribute 'after-jump-hook "type . file-line / line"
5518 "Function to call after jumping to the target location.")
5519 (anything-document-attribute 'adjust "type . file-line"
5520 "Search around line matching line contents.")
5521 (anything-document-attribute 'recenter "type . file-line / line"
5522 "`recenter' after jumping.")
5523 (anything-document-attribute 'target-file "type . line"
5524 "Goto line of target-file.")
5526 ;;;###autoload
5527 (defun anything-c-call-interactively (cmd-or-name)
5528 "Execute CMD-OR-NAME as Emacs command.
5529 It is added to `extended-command-history'.
5530 `anything-current-prefix-arg' is used as the command's prefix argument."
5531 (setq extended-command-history
5532 (cons (anything-c-stringify cmd-or-name)
5533 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
5534 (let ((current-prefix-arg anything-current-prefix-arg)
5535 (cmd (anything-c-symbolify cmd-or-name)))
5536 (if (stringp (symbol-function cmd))
5537 (execute-kbd-macro (symbol-function cmd))
5538 (setq this-command cmd)
5539 (call-interactively cmd))))
5541 ;;;###autoload
5542 (defun anything-c-set-variable (var)
5543 "Set value to VAR interactively."
5544 (interactive)
5545 (let ((sym (anything-c-symbolify var)))
5546 (set sym (eval-minibuffer (format "Set %s: " var)
5547 (prin1-to-string (symbol-value sym))))))
5548 ;; (setq hh 12)
5549 ;; (anything-c-set-variable 'hh)
5551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5552 (defvar anything-match-line-overlay-face nil)
5553 (defvar anything-match-line-overlay nil)
5555 (defun anything-match-line-color-current-line (&optional start end buf face rec)
5556 "Highlight and underline current position"
5557 (let ((args (list (or start (line-beginning-position))
5558 (or end (1+ (line-end-position)))
5559 buf)))
5560 (if (not anything-match-line-overlay)
5561 (setq anything-match-line-overlay (apply 'make-overlay args))
5562 (apply 'move-overlay anything-match-line-overlay args)))
5563 (overlay-put anything-match-line-overlay
5564 'face (or face anything-match-line-overlay-face))
5565 (when rec
5566 (goto-char start)
5567 (recenter)))
5569 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
5571 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
5572 "Face for source header in the anything buffer." :group 'anything)
5574 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
5576 (defun anything-match-line-cleanup ()
5577 (when anything-match-line-overlay
5578 (delete-overlay anything-match-line-overlay)
5579 (setq anything-match-line-overlay nil)))
5581 (defun anything-match-line-update ()
5582 (when anything-match-line-overlay
5583 (delete-overlay anything-match-line-overlay)
5584 (anything-match-line-color-current-line)))
5586 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
5587 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
5589 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5590 ;;; Files
5591 (defun anything-c-transform-file-load-el (actions candidate)
5592 "Add action to load the file CANDIDATE if it is an emacs lisp
5593 file. Else return ACTIONS unmodified."
5594 (if (member (file-name-extension candidate) '("el" "elc"))
5595 (append actions '(("Load Emacs Lisp File" . load-file)))
5596 actions))
5598 (defun anything-c-transform-file-browse-url (actions candidate)
5599 "Add an action to browse the file CANDIDATE if it in a html
5600 file or URL. Else return ACTIONS unmodified."
5601 (let ((browse-action '("Browse with Browser" . browse-url)))
5602 (cond ((string-match "^http\\|^ftp" candidate)
5603 (cons browse-action actions))
5604 ((string-match "\\.html?$" candidate)
5605 (append actions (list browse-action)))
5606 (t actions))))
5608 ;;;; Function
5609 (defun anything-c-transform-function-call-interactively (actions candidate)
5610 "Add an action to call the function CANDIDATE interactively if
5611 it is a command. Else return ACTIONS unmodified."
5612 (if (commandp (intern-soft candidate))
5613 (append actions '(("Call Interactively"
5615 anything-c-call-interactively)))
5616 actions))
5618 ;;;; S-Expressions
5619 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
5620 "If CANDIDATE's `car' is a command, then add an action to
5621 evaluate it and put it onto the `command-history'."
5622 (if (commandp (car (read candidate)))
5623 ;; Make it first entry
5624 (cons '("Eval and put onto command-history" .
5625 (lambda (sexp)
5626 (let ((sym (read sexp)))
5627 (eval sym)
5628 (setq command-history
5629 (cons sym command-history)))))
5630 actions)
5631 actions))
5633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5634 ;;; Buffers
5635 (defun anything-c-skip-boring-buffers (buffers)
5636 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
5638 (defun anything-c-skip-current-buffer (buffers)
5639 (if anything-allow-skipping-current-buffer
5640 (remove (buffer-name anything-current-buffer) buffers)
5641 buffers))
5643 (defun anything-c-shadow-boring-buffers (buffers)
5644 "Buffers matching `anything-c-boring-buffer-regexp' will be
5645 displayed with the `file-name-shadow' face if available."
5646 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
5648 ;;; Files
5649 (defun anything-c-shadow-boring-files (files)
5650 "Files matching `anything-c-boring-file-regexp' will be
5651 displayed with the `file-name-shadow' face if available."
5652 (anything-c-shadow-entries files anything-c-boring-file-regexp))
5654 (defun anything-c-skip-boring-files (files)
5655 "Files matching `anything-c-boring-file-regexp' will be skipped."
5656 (anything-c-skip-entries files anything-c-boring-file-regexp))
5657 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
5659 (defun anything-c-skip-current-file (files)
5660 "Current file will be skipped."
5661 (remove (buffer-file-name anything-current-buffer) files))
5663 (defun anything-c-w32-pathname-transformer (args)
5664 "Change undesirable features of windows pathnames to ones more acceptable to
5665 other candidate transformers."
5666 (if (eq system-type 'windows-nt)
5667 (mapcar (lambda (x)
5668 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
5669 (mapcar (lambda (y)
5670 (replace-regexp-in-string "\\\\" "/" y)) args))
5671 args))
5673 (defun anything-c-shorten-home-path (files)
5674 "Replaces /home/user with ~."
5675 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
5676 (getenv "HOME"))))
5677 (mapcar (lambda (file)
5678 (if (and (stringp file) (string-match home file))
5679 (cons (replace-match "~" nil nil file) file)
5680 file))
5681 files)))
5683 ;;; Functions
5684 (defun anything-c-mark-interactive-functions (functions)
5685 "Mark interactive functions (commands) with (i) after the function name."
5686 (let (list)
5687 (loop for function in functions
5688 do (push (cons (concat function
5689 (when (commandp (intern-soft function)) " (i)"))
5690 function)
5691 list)
5692 finally (return (nreverse list)))))
5694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5695 (defvar anything-c-adaptive-done nil
5696 "nil if history information is not yet stored for the current
5697 selection.")
5699 (defvar anything-c-adaptive-history nil
5700 "Contains the stored history information.
5701 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
5703 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
5704 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
5705 when anything is started."
5706 (setq anything-c-adaptive-done nil))
5708 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
5709 "Advise `anything-exit-minibuffer' to store history information
5710 when a candidate is selected with RET."
5711 (anything-c-adaptive-store-selection))
5713 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
5714 "Advise `anything-select-action' to store history information
5715 when the user goes to the action list with TAB."
5716 (anything-c-adaptive-store-selection))
5718 (defun anything-c-source-use-adaptative-p (&optional source-name)
5719 "Return current source only if it use adaptative history, nil otherwise."
5720 (let* ((source (or source-name (anything-get-current-source)))
5721 (adapt-source (or (assoc-default 'filtered-candidate-transformer
5722 (assoc (assoc-default 'type source)
5723 anything-type-attributes))
5724 (assoc-default 'candidate-transformer
5725 (assoc (assoc-default 'type source)
5726 anything-type-attributes))
5727 (assoc-default 'filtered-candidate-transformer source)
5728 (assoc-default 'candidate-transformer source))))
5729 (if (listp adapt-source)
5730 (when (member 'anything-c-adaptive-sort adapt-source) source)
5731 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
5733 (defun anything-c-adaptive-store-selection ()
5734 "Store history information for the selected candidate."
5735 (unless anything-c-adaptive-done
5736 (setq anything-c-adaptive-done t)
5737 (let ((source (anything-c-source-use-adaptative-p)))
5738 (when source
5739 (let* ((source-name (or (assoc-default 'type source)
5740 (assoc-default 'name source)))
5741 (source-info (or (assoc source-name anything-c-adaptive-history)
5742 (progn
5743 (push (list source-name) anything-c-adaptive-history)
5744 (car anything-c-adaptive-history))))
5745 (selection (anything-get-selection))
5746 (selection-info (progn
5747 (setcdr source-info
5748 (cons
5749 (let ((found (assoc selection (cdr source-info))))
5750 (if (not found)
5751 ;; new entry
5752 (list selection)
5754 ;; move entry to the beginning of the
5755 ;; list, so that it doesn't get
5756 ;; trimmed when the history is
5757 ;; truncated
5758 (setcdr source-info
5759 (delete found (cdr source-info)))
5760 found))
5761 (cdr source-info)))
5762 (cadr source-info)))
5763 (pattern-info (progn
5764 (setcdr selection-info
5765 (cons
5766 (let ((found (assoc anything-pattern (cdr selection-info))))
5767 (if (not found)
5768 ;; new entry
5769 (cons anything-pattern 0)
5771 ;; move entry to the beginning of the
5772 ;; list, so if two patterns used the
5773 ;; same number of times then the one
5774 ;; used last appears first in the list
5775 (setcdr selection-info
5776 (delete found (cdr selection-info)))
5777 found))
5778 (cdr selection-info)))
5779 (cadr selection-info))))
5781 ;; increase usage count
5782 (setcdr pattern-info (1+ (cdr pattern-info)))
5784 ;; truncate history if needed
5785 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
5786 (setcdr selection-info
5787 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
5789 (if (file-readable-p anything-c-adaptive-history-file)
5790 (load-file anything-c-adaptive-history-file))
5791 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
5793 (defun anything-c-adaptive-save-history ()
5794 "Save history information to file given by `anything-c-adaptive-history-file'."
5795 (interactive)
5796 (with-temp-buffer
5797 (insert
5798 ";; -*- mode: emacs-lisp -*-\n"
5799 ";; History entries used for anything adaptive display.\n")
5800 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
5801 (current-buffer))
5802 (insert ?\n)
5803 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
5804 (unless (interactive-p) 'quiet))))
5806 (defun anything-c-adaptive-sort (candidates source)
5807 "Sort the CANDIDATES for SOURCE by usage frequency.
5808 This is a filtered candidate transformer you can use for the
5809 attribute `filtered-candidate-transformer' of a source in
5810 `anything-sources' or a type in `anything-type-attributes'."
5811 (let* ((source-name (or (assoc-default 'type source)
5812 (assoc-default 'name source)))
5813 (source-info (assoc source-name anything-c-adaptive-history)))
5814 (if (not source-info)
5815 ;; if there is no information stored for this source then do nothing
5816 candidates
5817 ;; else...
5818 (let ((usage
5819 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
5820 ;; pairs
5821 (mapcar (lambda (candidate-info)
5822 (let ((count 0))
5823 (dolist (pattern-info (cdr candidate-info))
5824 (if (not (equal (car pattern-info)
5825 anything-pattern))
5826 (incf count (cdr pattern-info))
5828 ;; if current pattern is equal to the previously
5829 ;; used one then this candidate has priority
5830 ;; (that's why its count is boosted by 10000) and
5831 ;; it only has to compete with other candidates
5832 ;; which were also selected with the same pattern
5833 (setq count (+ 10000 (cdr pattern-info)))
5834 (return)))
5835 (cons (car candidate-info) count)))
5836 (cdr source-info)))
5837 sorted)
5839 ;; sort the list in descending order, so candidates with highest
5840 ;; priorty come first
5841 (setq usage (sort usage (lambda (first second)
5842 (> (cdr first) (cdr second)))))
5844 ;; put those candidates first which have the highest usage count
5845 (dolist (info usage)
5846 (when (member* (car info) candidates
5847 :test 'anything-c-adaptive-compare)
5848 (push (car info) sorted)
5849 (setq candidates (remove* (car info) candidates
5850 :test 'anything-c-adaptive-compare))))
5852 ;; and append the rest
5853 (append (reverse sorted) candidates nil)))))
5855 (defun anything-c-adaptive-compare (x y)
5856 "Compare candidates X and Y taking into account that the
5857 candidate can be in (DISPLAY . REAL) format."
5858 (equal (if (listp x)
5859 (cdr x)
5861 (if (listp y)
5862 (cdr y)
5863 y)))
5865 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5866 (defvar anything-outline-goto-near-line-flag t)
5867 (defvar anything-outline-using nil)
5868 (defun anything-after-update-hook--outline ()
5869 (if (and (eq anything-outline-using t)
5870 (eq anything-outline-goto-near-line-flag t))
5871 (anything-outline-goto-near-line)))
5872 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
5874 (defun anything-outline-goto-near-line ()
5875 (with-anything-window
5876 ;; TODO need consideration whether to update position by every input.
5877 (when t ; (equal anything-pattern "")
5878 (anything-goto-line 2)
5879 (let ((lineno (with-current-buffer anything-current-buffer
5880 (line-number-at-pos (car anything-current-position)))))
5881 (block exit
5882 (while (<= (progn (skip-chars-forward " ")
5883 (or (number-at-point) lineno))
5884 lineno)
5885 (forward-line 1)
5886 (when (eobp)
5887 (forward-line -1)
5888 (return-from exit))))
5889 (forward-line -1)
5890 (and (bobp) (forward-line 1))
5891 (and (anything-pos-header-line-p) (forward-line -2))
5892 (anything-mark-current-line)))))
5894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5895 ;; Plug-in: info-index
5896 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
5897 (let (result)
5898 (unless (anything-candidate-buffer)
5899 (save-window-excursion
5900 (info file)
5901 (let (Info-history
5902 (tobuf (anything-candidate-buffer 'global))
5903 (infobuf (current-buffer))
5904 s e)
5905 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
5906 (Info-goto-node node)
5907 (goto-char (point-min))
5908 (while (search-forward "\n* " nil t)
5909 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
5910 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
5911 (setq s (point-at-bol)
5912 e (point-at-eol))
5913 (with-current-buffer tobuf
5914 (insert-buffer-substring infobuf s e)
5915 (insert "\n"))))))))))
5917 (defun anything-c-info-goto (node-line)
5918 (Info-goto-node (car node-line))
5919 (anything-goto-line (cdr node-line)))
5921 (defun anything-c-info-display-to-real (line)
5922 (and (string-match
5923 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
5924 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
5925 (string-to-number (or (match-string 3 line) "1")))))
5927 (defun anything-c-make-info-source (file)
5928 `((name . ,(concat "Info Index: " file))
5929 (info-file . ,file)
5930 (init . anything-c-info-init)
5931 (display-to-real . anything-c-info-display-to-real)
5932 (get-line . buffer-substring)
5933 (candidates-in-buffer)
5934 (action ("Goto node" . anything-c-info-goto))))
5936 (defun anything-compile-source--info-index (source)
5937 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
5938 (anything-c-make-info-source it)
5939 source))
5940 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
5942 (anything-document-attribute 'info-index "info-index plugin"
5943 "Create a source of info index very easily.
5945 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
5947 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
5948 "Index nodes of info file.
5950 If it is omitted, `Info-index-nodes' is used to collect index nodes.
5951 Some info files are missing index specification.
5953 ex. See `anything-c-source-info-screen'.")
5955 ;; Plug-in: candidates-file
5956 (defun anything-compile-source--candidates-file (source)
5957 (if (assoc-default 'candidates-file source)
5958 `((init anything-p-candidats-file-init
5959 ,@(let ((orig-init (assoc-default 'init source)))
5960 (cond ((null orig-init) nil)
5961 ((functionp orig-init) (list orig-init))
5962 (t orig-init))))
5963 (candidates-in-buffer)
5964 ,@source)
5965 source))
5966 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
5968 (defun anything-p-candidats-file-init ()
5969 (destructuring-bind (file &optional updating)
5970 (anything-mklist (anything-attr 'candidates-file))
5971 (setq file (anything-interpret-value file))
5972 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
5973 (when updating
5974 (buffer-disable-undo)
5975 (font-lock-mode -1)
5976 (auto-revert-mode 1)))))
5978 (anything-document-attribute 'candidates-file "candidates-file plugin"
5979 "Use a file as the candidates buffer.
5981 1st argument is a filename, string or function name or variable name.
5982 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
5984 ;; Plug-in: headline
5985 (defun anything-compile-source--anything-headline (source)
5986 (if (assoc-default 'headline source)
5987 (append '((init . anything-headline-init)
5988 (get-line . buffer-substring)
5989 (type . line))
5990 source
5991 '((candidates-in-buffer)
5992 (persistent-help . "Show this line")))
5993 source))
5994 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
5996 (defun anything-headline-init ()
5997 (when (and (anything-current-buffer-is-modified)
5998 (with-current-buffer anything-current-buffer
5999 (eval (or (anything-attr 'condition) t))))
6000 (anything-headline-make-candidate-buffer
6001 (anything-interpret-value (anything-attr 'headline))
6002 (anything-interpret-value (anything-attr 'subexp)))))
6004 (anything-document-attribute 'headline "Headline plug-in"
6005 "Regexp string for anything-headline to scan.")
6006 (anything-document-attribute 'condition "Headline plug-in"
6007 "A sexp representing the condition to use anything-headline.")
6008 (anything-document-attribute 'subexp "Headline plug-in"
6009 "Display (match-string-no-properties subexp).")
6012 (defun anything-headline-get-candidates (regexp subexp)
6013 (with-current-buffer anything-current-buffer
6014 (save-excursion
6015 (goto-char (point-min))
6016 (if (functionp regexp) (setq regexp (funcall regexp)))
6017 (let (hierarchy curhead)
6018 (flet ((matched ()
6019 (if (numberp subexp)
6020 (cons (match-string-no-properties subexp) (match-beginning subexp))
6021 (cons (buffer-substring (point-at-bol) (point-at-eol))
6022 (point-at-bol))))
6023 (hierarchies (headlines)
6024 (1+ (loop for (_ . hierarchy) in headlines
6025 maximize hierarchy)))
6026 (vector-0-n (v n)
6027 (loop for i from 0 to hierarchy
6028 collecting (aref curhead i)))
6029 (arrange (headlines)
6030 (unless (null headlines) ; FIX headlines empty bug!
6031 (loop with curhead = (make-vector (hierarchies headlines) "")
6032 for ((str . pt) . hierarchy) in headlines
6033 do (aset curhead hierarchy str)
6034 collecting
6035 (cons
6036 (format "H%d:%s" (1+ hierarchy)
6037 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
6038 pt)))))
6039 (if (listp regexp)
6040 (arrange
6041 (sort
6042 (loop for re in regexp
6043 for hierarchy from 0
6044 do (goto-char (point-min))
6045 appending
6046 (loop
6047 while (re-search-forward re nil t)
6048 collect (cons (matched) hierarchy)))
6049 (lambda (a b) (> (cdar b) (cdar a)))))
6050 (loop while (re-search-forward regexp nil t)
6051 collect (matched))))))))
6054 (defun anything-headline-make-candidate-buffer (regexp subexp)
6055 (with-current-buffer (anything-candidate-buffer 'local)
6056 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
6057 do (insert
6058 (format "%5d:%s\n"
6059 (with-current-buffer anything-current-buffer
6060 (line-number-at-pos pos))
6061 content)))))
6063 (defun anything-headline-goto-position (pos recenter)
6064 (goto-char pos)
6065 (unless recenter
6066 (set-window-start (get-buffer-window anything-current-buffer) (point))))
6068 (defun anything-revert-buffer (candidate)
6069 (with-current-buffer candidate
6070 (when (buffer-modified-p)
6071 (revert-buffer t t))))
6073 (defun anything-revert-marked-buffers (candidate)
6074 (dolist (i (anything-marked-candidates))
6075 (anything-revert-buffer i)))
6077 (defun anything-kill-marked-buffers (candidate)
6078 (dolist (i (anything-marked-candidates))
6079 (kill-buffer i)))
6081 ;; Plug-in: persistent-help
6082 (defun anything-compile-source--persistent-help (source)
6083 (append source '((header-line . anything-persistent-help-string))))
6084 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
6086 (defun anything-persistent-help-string ()
6087 (substitute-command-keys
6088 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
6089 (or (anything-interpret-value (anything-attr 'persistent-help))
6090 (anything-aif (or (assoc-default 'persistent-action (anything-get-current-source))
6091 (assoc-default 'action (anything-get-current-source))
6093 (cond ((symbolp it) (symbol-name it))
6094 ((listp it) (or (ignore-errors (caar it)) ""))))
6096 " (keeping session)")))
6098 (anything-document-attribute 'persistent-help "persistent-help plug-in"
6099 "A string to explain persistent-action of this source.
6100 It also accepts a function or a variable name.")
6102 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
6104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6106 (defun anything-delete-marked-files (ignore)
6107 (let* ((files (anything-marked-candidates))
6108 (len (length files)))
6109 (if (not (y-or-n-p
6110 (format "Delete *%s File(s):\n%s"
6112 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
6113 (message "(No deletions performed)")
6114 (dolist (i files)
6115 (set-text-properties 0 (length i) nil i)
6116 (anything-c-delete-file i))
6117 (message "%s File(s) deleted" len))))
6119 (defun anything-ediff-marked-buffers (candidate &optional merge)
6120 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
6121 With optional arg `merge' call `ediff-merge-buffers'."
6122 (let ((lg-lst (length (anything-marked-candidates)))
6123 buf1 buf2)
6124 (case lg-lst
6126 (error "Error:You have to mark at least 1 buffer"))
6128 (setq buf1 anything-current-buffer
6129 buf2 (first (anything-marked-candidates))))
6131 (setq buf1 (first (anything-marked-candidates))
6132 buf2 (second (anything-marked-candidates))))
6134 (error "Error:To much buffers marked!")))
6135 (if merge
6136 (ediff-merge-buffers buf1 buf2)
6137 (ediff-buffers buf1 buf2))))
6139 (defun anything-bookmark-get-bookmark-from-name (bmk)
6140 "Return bookmark name even if it is a bookmark with annotation.
6141 e.g prepended with *.
6142 Return nil if bmk is not a valid bookmark."
6143 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
6144 (if (assoc bookmark bookmark-alist)
6145 bookmark
6146 (when (assoc bmk bookmark-alist)
6147 bmk))))
6149 (defun anything-delete-marked-bookmarks (elm)
6150 "Delete this bookmark or all marked bookmarks."
6151 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
6152 (anything-aif (anything-marked-candidates)
6153 (dolist (i it)
6154 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
6155 (bookmark-delete bmk 'batch)))
6156 (bookmark-delete bookmark 'batch))))
6158 (defun anything-require-or-error (feature function)
6159 (or (require feature nil t)
6160 (error "Need %s to use `%s'." feature function)))
6162 (defun anything-find-buffer-on-elscreen (candidate)
6163 "Open buffer in new screen, if marked buffers open all in elscreens."
6164 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
6165 (anything-aif (anything-marked-candidates)
6166 (dolist (i it)
6167 (let ((target-screen (elscreen-find-screen-by-buffer
6168 (get-buffer i) 'create)))
6169 (elscreen-goto target-screen)))
6170 (let ((target-screen (elscreen-find-screen-by-buffer
6171 (get-buffer candidate) 'create)))
6172 (elscreen-goto target-screen))))
6174 (defun anything-elscreen-find-file (file)
6175 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
6176 (elscreen-find-file file))
6178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6180 ;;;; Type Attributes
6181 (define-anything-type-attribute 'buffer
6182 `((action
6183 ,@(if pop-up-frames
6184 '(("Switch to buffer other window" . switch-to-buffer-other-window)
6185 ("Switch to buffer" . switch-to-buffer))
6186 '(("Switch to buffer" . switch-to-buffer)
6187 ("Switch to buffer other window" . switch-to-buffer-other-window)
6188 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
6189 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
6190 ("Display buffer" . display-buffer)
6191 ("Revert buffer" . anything-revert-buffer)
6192 ("Revert Marked buffers" . anything-revert-marked-buffers)
6193 ("Kill buffer" . kill-buffer)
6194 ("Kill Marked buffers" . anything-kill-marked-buffers)
6195 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
6196 ("Ediff Merge marked buffers" . (lambda (candidate)
6197 (anything-ediff-marked-buffers candidate t))))
6198 (persistent-help . "Show this buffer")
6199 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
6200 "Buffer or buffer name.")
6202 (define-anything-type-attribute 'file
6203 `((action
6204 ,@(if pop-up-frames
6205 '(("Find file other window" . find-file-other-window)
6206 ("Find file(s)" . anything-find-many-files)
6207 ("Find file as root" . anything-find-file-as-root))
6208 '(("Find file" . anything-find-many-files)
6209 ("Find file as root" . anything-find-file-as-root)
6210 ("Find file other window" . find-file-other-window)
6211 ("Find file other frame" . find-file-other-frame)))
6212 ("Open dired in file's directory" . anything-c-open-dired)
6213 ("Delete file(s)" . anything-delete-marked-files)
6214 ("Open file externally" . anything-c-open-file-externally)
6215 ("Open file with default tool" . anything-c-open-file-with-default-tool))
6216 (persistent-help . "Show this file")
6217 (action-transformer anything-c-transform-file-load-el
6218 anything-c-transform-file-browse-url)
6219 (candidate-transformer anything-c-w32-pathname-transformer
6220 anything-c-skip-current-file
6221 anything-c-skip-boring-files
6222 anything-c-shorten-home-path))
6223 "File name.")
6225 (define-anything-type-attribute 'command
6226 `((action ("Call interactively" . anything-c-call-interactively)
6227 ("Describe command" . anything-c-describe-function)
6228 ("Add command to kill ring" . anything-c-kill-new)
6229 ("Go to command's definition" . anything-c-find-function))
6230 ;; Sort commands according to their usage count.
6231 (filtered-candidate-transformer . anything-c-adaptive-sort)
6232 (persistent-action . anything-c-describe-function))
6233 "Command. (string or symbol)")
6235 (define-anything-type-attribute 'function
6236 '((action ("Describe function" . anything-c-describe-function)
6237 ("Add function to kill ring" . anything-c-kill-new)
6238 ("Go to function's definition" . anything-c-find-function))
6239 (action-transformer anything-c-transform-function-call-interactively)
6240 (candidate-transformer anything-c-mark-interactive-functions))
6241 "Function. (string or symbol)")
6243 (define-anything-type-attribute 'variable
6244 '((action ("Describe variable" . anything-c-describe-variable)
6245 ("Add variable to kill ring" . anything-c-kill-new)
6246 ("Go to variable's definition" . anything-c-find-variable)
6247 ("Set variable" . anything-c-set-variable)))
6248 "Variable.")
6250 (define-anything-type-attribute 'sexp
6251 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
6252 ("Add s-expression to kill ring" . kill-new))
6253 (action-transformer anything-c-transform-sexp-eval-command-sexp))
6254 "String representing S-Expressions.")
6256 (define-anything-type-attribute 'bookmark
6257 `((action
6258 ("Jump to bookmark" . (lambda (candidate)
6259 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate))
6260 (current-prefix-arg anything-current-prefix-arg))
6261 (bookmark-jump bookmark))
6262 (anything-update)))
6263 ("Jump to BM other window" . (lambda (candidate)
6264 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6265 (bookmark-jump-other-window bookmark))
6266 (anything-update)))
6267 ("Bookmark edit annotation" . (lambda (candidate)
6268 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6269 (bookmark-edit-annotation bookmark))))
6270 ("Bookmark show annotation" . (lambda (candidate)
6271 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6272 (bookmark-show-annotation bookmark))))
6273 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
6274 ,@(when (fboundp 'bmkext-edit-bookmark)
6275 '(("Edit Bookmark" . (lambda (candidate)
6276 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6277 (bmkext-edit-bookmark bookmark))))))
6278 ("Rename bookmark" . (lambda (candidate)
6279 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6280 (bookmark-rename bookmark))))
6281 ("Relocate bookmark" . (lambda (candidate)
6282 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6283 (bookmark-relocate bookmark))))))
6284 "Bookmark name.")
6286 (define-anything-type-attribute 'line
6287 '((display-to-real . anything-c-display-to-real-line)
6288 (action ("Go to Line" . anything-c-action-line-goto)))
6289 "LINENO:CONTENT string, eg. \" 16:foo\".
6291 Optional `target-file' attribute is a name of target file.
6293 Optional `before-jump-hook' attribute is a function with no
6294 arguments which is called before jumping to position.
6296 Optional `after-jump-hook' attribute is a function with no
6297 arguments which is called after jumping to position.
6299 If `adjust' attribute is specified, searches the line whose
6300 content is CONTENT near the LINENO.
6302 If `recenter' attribute is specified, the line is displayed at
6303 the center of window, otherwise at the top of window.
6306 (define-anything-type-attribute 'file-line
6307 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
6308 (multiline)
6309 (action ("Go to" . anything-c-action-file-line-goto)))
6310 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
6312 Optional `default-directory' attribute is a default-directory
6313 FILENAME is interpreted.
6315 Optional `before-jump-hook' attribute is a function with no
6316 arguments which is called before jumping to position.
6318 Optional `after-jump-hook' attribute is a function with no
6319 arguments which is called after jumping to position.
6321 If `adjust' attribute is specified, searches the line whose
6322 content is CONTENT near the LINENO.
6324 If `recenter' attribute is specified, the line is displayed at
6325 the center of window, otherwise at the top of window.
6328 (define-anything-type-attribute 'timer
6329 '((real-to-display . anything-c-timer-real-to-display)
6330 (action ("Cancel Timer" . cancel-timer)
6331 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
6332 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
6333 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
6334 (persistent-help . "Describe Function"))
6335 "Timer.")
6337 ;;;; Default `anything-sources'
6338 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
6339 ;; tend to invoke M-x anything directly. So I offer default setting.
6340 (setq anything-sources
6341 '(anything-c-source-buffers+
6342 anything-c-source-recentf
6343 anything-c-source-files-in-current-dir+))
6345 ;;;; unit test
6346 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
6347 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6348 (dont-compile
6349 (when (fboundp 'expectations)
6350 (expectations
6351 (desc "candidates-file plug-in")
6352 (expect '(anything-p-candidats-file-init)
6353 (assoc-default 'init
6354 (car (anything-compile-sources
6355 '(((name . "test")
6356 (candidates-file . "test.txt")))
6357 '(anything-compile-source--candidates-file)))))
6358 (expect '(anything-p-candidats-file-init
6359 (lambda () 1))
6360 (assoc-default 'init
6361 (car (anything-compile-sources
6362 '(((name . "test")
6363 (candidates-file . "test.txt")
6364 (init . (lambda () 1))))
6365 '(anything-compile-source--candidates-file)))))
6366 (expect '(anything-p-candidats-file-init
6367 (lambda () 1))
6368 (assoc-default 'init
6369 (car (anything-compile-sources
6370 '(((name . "test")
6371 (candidates-file . "test.txt")
6372 (init (lambda () 1))))
6373 '(anything-compile-source--candidates-file)))))
6374 (desc "anything-c-source-buffers")
6375 (expect '(("Buffers" ("foo" "curbuf")))
6376 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
6377 (let ((anything-c-boring-buffer-regexp
6378 (rx (or
6379 (group bos " ")
6380 "*anything"
6381 ;; echo area
6382 " *Echo Area" " *Minibuf"))))
6383 (flet ((buffer-name (x) x))
6384 (anything-test-candidates 'anything-c-source-buffers))))
6385 (desc "anything-c-stringify")
6386 (expect "str1"
6387 (anything-c-stringify "str1"))
6388 (expect "str2"
6389 (anything-c-stringify 'str2))
6390 (desc "anything-c-symbolify")
6391 (expect 'sym1
6392 (anything-c-symbolify "sym1"))
6393 (expect 'sym2
6394 (anything-c-symbolify 'sym2)))))
6396 (provide 'anything-config)
6398 ;;; Local Variables:
6399 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
6400 ;;; End:
6402 ;; How to save (DO NOT REMOVE!!)
6403 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
6404 ;;; anything-config.el ends here
6406 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
6407 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
6408 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
6409 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
6410 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
6411 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
6412 ;;; LocalWords: dotimes Thierry online vname
6413 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
6414 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
6415 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
6416 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
6417 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
6418 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
6419 ;;; LocalWords: startpos noselect dont desc