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