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