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