anything.el (anything-check-minibuffer-input):
[anything-config.git] / anything-config.el
blobbeaf04db2df92f44023b3814b79c2b7b54565555
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"
3060 . (lambda (candidate)
3061 (let ((bmk (anything-bookmark-get-bookmark-from-name
3062 candidate)))
3063 (bookmark-edit-annotation bmk))))
3064 ("Show Google map" . (lambda (candidate)
3065 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3066 candidate))
3067 (full-bmk (assoc bmk bookmark-alist)))
3068 (addressbook-google-map full-bmk))))))))
3071 (defun anything-c-bmkext-addressbook-setup-alist ()
3072 "Specialized filter function for bookmarks w3m."
3073 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
3075 ;; W3m
3076 (defvar anything-c-source-bookmark-w3m
3077 '((name . "Bookmark W3m")
3078 (init . (lambda ()
3079 (require 'bookmark-extensions)
3080 (bookmark-maybe-load-default-file)))
3081 (candidates . anything-c-bookmark-w3m-setup-alist)
3082 (filtered-candidate-transformer
3083 anything-c-adaptive-sort
3084 anything-c-highlight-bookmark)
3085 (type . bookmark)))
3086 ;; (anything 'anything-c-source-bookmark-w3m)
3088 (defun anything-c-bookmark-w3m-setup-alist ()
3089 "Specialized filter function for bookmarks w3m."
3090 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
3092 ;; Images
3093 (defvar anything-c-source-bookmark-images
3094 '((name . "Bookmark Images")
3095 (init . (lambda ()
3096 (require 'bookmark-extensions)
3097 (bookmark-maybe-load-default-file)))
3098 (candidates . anything-c-bookmark-images-setup-alist)
3099 (filtered-candidate-transformer
3100 anything-c-adaptive-sort
3101 anything-c-highlight-bookmark)
3102 (type . bookmark)))
3103 ;; (anything 'anything-c-source-bookmark-images)
3105 (defun anything-c-bookmark-images-setup-alist ()
3106 "Specialized filter function for images bookmarks."
3107 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
3109 ;; Woman Man
3110 (defvar anything-c-source-bookmark-man
3111 '((name . "Bookmark Woman&Man")
3112 (init . (lambda ()
3113 (require 'bookmark-extensions)
3114 (bookmark-maybe-load-default-file)))
3115 (candidates . anything-c-bookmark-man-setup-alist)
3116 (filtered-candidate-transformer
3117 anything-c-adaptive-sort
3118 anything-c-highlight-bookmark)
3119 (type . bookmark)))
3120 ;; (anything 'anything-c-source-bookmark-man)
3122 (defun anything-c-bookmark-man-setup-alist ()
3123 "Specialized filter function for bookmarks w3m."
3124 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
3125 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
3127 ;; Gnus
3128 (defvar anything-c-source-bookmark-gnus
3129 '((name . "Bookmark Gnus")
3130 (init . (lambda ()
3131 (require 'bookmark-extensions)
3132 (bookmark-maybe-load-default-file)))
3133 (candidates . anything-c-bookmark-gnus-setup-alist)
3134 (filtered-candidate-transformer
3135 anything-c-adaptive-sort
3136 anything-c-highlight-bookmark)
3137 (type . bookmark)))
3138 ;; (anything 'anything-c-source-bookmark-gnus)
3140 (defun anything-c-bookmark-gnus-setup-alist ()
3141 "Specialized filter function for bookmarks gnus."
3142 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
3144 ;; Info
3145 (defvar anything-c-source-bookmark-info
3146 '((name . "Bookmark Info")
3147 (init . (lambda ()
3148 (require 'bookmark-extensions)
3149 (bookmark-maybe-load-default-file)))
3150 (candidates . anything-c-bookmark-info-setup-alist)
3151 (filtered-candidate-transformer
3152 anything-c-adaptive-sort
3153 anything-c-highlight-bookmark)
3154 (type . bookmark)))
3155 ;; (anything 'anything-c-source-bookmark-info)
3157 (defun anything-c-bookmark-info-setup-alist ()
3158 "Specialized filter function for bookmarks info."
3159 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
3161 ;; Local Files&directories
3162 (defvar anything-c-source-bookmark-files&dirs
3163 '((name . "Bookmark Files&Directories")
3164 (init . (lambda ()
3165 (require 'bookmark-extensions)
3166 (bookmark-maybe-load-default-file)))
3167 (candidates . anything-c-bookmark-local-files-setup-alist)
3168 (filtered-candidate-transformer
3169 anything-c-adaptive-sort
3170 anything-c-highlight-bookmark)
3171 (type . bookmark)))
3172 ;; (anything 'anything-c-source-bookmark-files&dirs)
3174 (defun anything-c-bookmark-local-files-setup-alist ()
3175 "Specialized filter function for bookmarks locals files."
3176 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
3178 ;; Su Files&directories
3179 (defvar anything-c-source-bookmark-su-files&dirs
3180 '((name . "Bookmark Root-Files&Directories")
3181 (init . (lambda ()
3182 (require 'bookmark-extensions)
3183 (bookmark-maybe-load-default-file)))
3184 (candidates . anything-c-bookmark-su-files-setup-alist)
3185 (filtered-candidate-transformer
3186 anything-c-adaptive-sort
3187 anything-c-highlight-bookmark-su)
3188 (type . bookmark)))
3189 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3191 (defun anything-c-bookmark-su-files-setup-alist ()
3192 "Specialized filter function for bookmarks su/sudo files."
3193 (loop
3194 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3195 for i in l
3196 for isfile = (bookmark-get-filename i)
3197 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3198 (save-match-data
3199 (string-match tramp-file-name-regexp isfile)))
3200 for issu = (and istramp
3201 (string-match bmkext-su-or-sudo-regexp isfile))
3202 if issu
3203 collect i))
3205 ;; Ssh Files&directories
3206 (defvar anything-c-source-bookmark-ssh-files&dirs
3207 '((name . "Bookmark Ssh-Files&Directories")
3208 (init . (lambda ()
3209 (require 'bookmark-extensions)
3210 (bookmark-maybe-load-default-file)))
3211 (candidates . anything-c-bookmark-ssh-files-setup-alist)
3212 (filtered-candidate-transformer . anything-c-adaptive-sort)
3213 (type . bookmark)))
3214 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3216 (defun anything-c-bookmark-ssh-files-setup-alist ()
3217 "Specialized filter function for bookmarks ssh files."
3218 (loop
3219 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3220 for i in l
3221 for isfile = (bookmark-get-filename i)
3222 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3223 (save-match-data
3224 (string-match tramp-file-name-regexp isfile)))
3225 for isssh = (and istramp
3226 (string-match "/ssh:" isfile))
3227 if isssh
3228 collect i))
3231 ;; All bookmark-extensions sources.
3232 ;;;###autoload
3233 (defun anything-bookmark-ext ()
3234 "Preconfigured `anything' for bookmark-extensions sources.
3235 Needs bookmark-ext.el
3237 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3238 (interactive)
3239 (anything '(anything-c-source-bookmark-files&dirs
3240 anything-c-source-bookmark-w3m
3241 anything-c-source-bmkext-addressbook
3242 anything-c-source-bookmark-gnus
3243 anything-c-source-bookmark-info
3244 anything-c-source-bookmark-man
3245 anything-c-source-bookmark-images
3246 anything-c-source-bookmark-su-files&dirs
3247 anything-c-source-bookmark-ssh-files&dirs)
3248 nil "SearchBookmark: " nil nil "*anything bmkext*"))
3251 ;; Firefox bookmarks
3252 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
3253 ;; (only for firefox versions >=3)
3254 ;; To achieve that, open about:config in firefox and double click on this line to enable value
3255 ;; to true:
3256 ;; user_pref("browser.bookmarks.autoExportHTML", false);
3257 ;; You should have now:
3258 ;; user_pref("browser.bookmarks.autoExportHTML", true);
3260 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
3261 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3263 (defun anything-get-firefox-user-init-dir ()
3264 "Guess the default Firefox user directory name."
3265 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
3266 (moz-user-dir (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
3267 (goto-char (point-min))
3268 (when (search-forward "Path=" nil t)
3269 (buffer-substring-no-properties (point) (point-at-eol))))))
3270 (file-name-as-directory (concat moz-dir moz-user-dir))))
3272 (defun anything-guess-firefox-bookmark-file ()
3273 "Return the path of the Firefox bookmarks file."
3274 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
3276 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
3277 "Parse html bookmark FILE and return an alist with (title . url) as elements."
3278 (let (bookmarks-alist url title)
3279 (with-temp-buffer
3280 (insert-file-contents file)
3281 (goto-char (point-min))
3282 (while (not (eobp))
3283 (forward-line)
3284 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
3285 (beginning-of-line)
3286 (when (re-search-forward url-regexp nil t)
3287 (setq url (concat "\"" (match-string 0))))
3288 (beginning-of-line)
3289 (when (re-search-forward bmk-regexp nil t)
3290 (setq title (match-string 1)))
3291 (push (cons title url) bookmarks-alist))))
3292 (nreverse bookmarks-alist)))
3295 (defvar anything-c-firefox-bookmarks-alist nil)
3296 (defvar anything-c-source-firefox-bookmarks
3297 '((name . "Firefox Bookmarks")
3298 (init . (lambda ()
3299 (setq anything-c-firefox-bookmarks-alist
3300 (anything-html-bookmarks-to-alist
3301 (anything-guess-firefox-bookmark-file)
3302 anything-firefox-bookmark-url-regexp
3303 anything-firefox-bookmarks-regexp))))
3304 (candidates . (lambda ()
3305 (mapcar #'car
3306 anything-c-firefox-bookmarks-alist)))
3307 (filtered-candidate-transformer
3308 anything-c-adaptive-sort
3309 anything-c-highlight-firefox-bookmarks)
3310 (action . (("Browse Url Firefox" . (lambda (candidate)
3311 (browse-url-firefox
3312 (anything-c-firefox-bookmarks-get-value candidate))))
3313 ("Browse Url w3m" . (lambda (candidate)
3314 (w3m-browse-url
3315 (anything-c-firefox-bookmarks-get-value candidate))))
3316 ("Copy Url" . (lambda (elm)
3317 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
3319 ;; (anything 'anything-c-source-firefox-bookmarks)
3321 (defun anything-c-firefox-bookmarks-get-value (elm)
3322 (replace-regexp-in-string "\"" ""
3323 (cdr (assoc elm
3324 anything-c-firefox-bookmarks-alist))))
3327 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
3328 (loop for i in bookmarks
3329 collect (propertize i
3330 'face '((:foreground "YellowGreen"))
3331 'help-echo (anything-c-firefox-bookmarks-get-value i))))
3333 ;; W3m bookmark
3334 (eval-when-compile (require 'w3m-bookmark nil t))
3335 (unless (and (require 'w3m nil t)
3336 (require 'w3m-bookmark nil t))
3337 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
3340 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
3341 "Face for w3m bookmarks" :group 'anything)
3343 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3344 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
3345 (defvar anything-c-w3m-bookmarks-alist nil)
3346 (defvar anything-c-source-w3m-bookmarks
3347 '((name . "W3m Bookmarks")
3348 (init . (lambda ()
3349 (setq anything-c-w3m-bookmarks-alist
3350 (anything-html-bookmarks-to-alist
3351 w3m-bookmark-file
3352 anything-w3m-bookmark-url-regexp
3353 anything-w3m-bookmarks-regexp))))
3354 (candidates . (lambda ()
3355 (mapcar #'car anything-c-w3m-bookmarks-alist)))
3356 (filtered-candidate-transformer
3357 anything-c-adaptive-sort
3358 anything-c-highlight-w3m-bookmarks)
3359 (action . (("Browse Url" . (lambda (candidate)
3360 (anything-c-w3m-browse-bookmark candidate)))
3361 ("Copy Url" . (lambda (elm)
3362 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
3363 ("Browse Url Firefox" . (lambda (candidate)
3364 (anything-c-w3m-browse-bookmark candidate t)))
3365 ("Delete Bookmark" . (lambda (candidate)
3366 (anything-c-w3m-delete-bookmark candidate)))
3367 ("Rename Bookmark" . (lambda (candidate)
3368 (anything-c-w3m-rename-bookmark candidate)))))
3369 (persistent-action . (lambda (candidate)
3370 (if current-prefix-arg
3371 (anything-c-w3m-browse-bookmark candidate t)
3372 (anything-c-w3m-browse-bookmark candidate nil t))))
3373 (persistent-help . "Open URL with emacs-w3m in new tab / \
3374 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
3375 "Needs w3m and emacs-w3m.
3377 http://w3m.sourceforge.net/
3378 http://emacs-w3m.namazu.org/")
3380 ;; (anything 'anything-c-source-w3m-bookmarks)
3382 (defun anything-c-w3m-bookmarks-get-value (elm)
3383 (replace-regexp-in-string
3384 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
3386 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
3387 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
3388 (arg (and (eq fn 'w3m-browse-url) new-tab)))
3389 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
3391 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
3392 (loop for i in bookmarks
3393 collect (propertize
3394 i 'face 'anything-w3m-bookmarks-face
3395 'help-echo (anything-c-w3m-bookmarks-get-value i))))
3398 (defun anything-c-w3m-delete-bookmark (elm)
3399 (save-excursion
3400 (find-file-literally w3m-bookmark-file)
3401 (goto-char (point-min))
3402 (when (re-search-forward elm nil t)
3403 (beginning-of-line)
3404 (delete-region (point)
3405 (line-end-position))
3406 (delete-blank-lines))
3407 (save-buffer (current-buffer))
3408 (kill-buffer (current-buffer))))
3410 (defun anything-c-w3m-rename-bookmark (elm)
3411 (let* ((old-title (replace-regexp-in-string ">" "" elm))
3412 (new-title (read-string "NewTitle: " old-title)))
3413 (save-excursion
3414 (find-file-literally w3m-bookmark-file)
3415 (goto-char (point-min))
3416 (when (re-search-forward (concat elm "<") nil t)
3417 (goto-char (1- (point)))
3418 (delete-char (- (length old-title)))
3419 (insert new-title))
3420 (save-buffer (current-buffer))
3421 (kill-buffer (current-buffer)))))
3423 ;;;; <Library>
3424 ;;; Elisp library scan
3425 (defvar anything-c-source-elisp-library-scan
3426 '((name . "Elisp libraries (Scan)")
3427 (init . (anything-c-elisp-library-scan-init))
3428 (candidates-in-buffer)
3429 (action ("Find library" . (lambda (candidate)
3430 (find-file (find-library-name candidate))))
3431 ("Find library other window" . (lambda (candidate)
3432 (find-file-other-window (find-library-name candidate))))
3433 ("Load library" . (lambda (candidate)
3434 (load-library candidate))))))
3435 ;; (anything 'anything-c-source-elisp-library-scan)
3437 (defun anything-c-elisp-library-scan-init ()
3438 "Init anything buffer status."
3439 (let ((anything-buffer (anything-candidate-buffer 'global))
3440 (library-list (anything-c-elisp-library-scan-list)))
3441 (with-current-buffer anything-buffer
3442 (dolist (library library-list)
3443 (insert (format "%s\n" library))))))
3445 (defun anything-c-elisp-library-scan-list (&optional dirs string)
3446 "Do completion for file names passed to `locate-file'.
3447 DIRS is directory to search path.
3448 STRING is string to match."
3449 ;; Use `load-path' as path when ignore `dirs'.
3450 (or dirs (setq dirs load-path))
3451 ;; Init with blank when ignore `string'.
3452 (or string (setq string ""))
3453 ;; Get library list.
3454 (let ((string-dir (file-name-directory string))
3455 ;; File regexp that suffix match `load-file-rep-suffixes'.
3456 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
3457 name
3458 names)
3459 (dolist (dir dirs)
3460 (unless dir
3461 (setq dir default-directory))
3462 (if string-dir
3463 (setq dir (expand-file-name string-dir dir)))
3464 (when (file-directory-p dir)
3465 (dolist (file (file-name-all-completions
3466 (file-name-nondirectory string) dir))
3467 ;; Suffixes match `load-file-rep-suffixes'.
3468 (setq name (if string-dir (concat string-dir file) file))
3469 (if (string-match match-regexp name)
3470 (add-to-list 'names name)))))
3471 names))
3473 ;;;; <Programming>
3474 ;;; Imenu
3475 (defvar anything-c-imenu-delimiter " / ")
3477 (defvar anything-c-imenu-index-filter nil)
3478 (make-variable-buffer-local 'anything-c-imenu-index-filter)
3480 (defvar anything-c-cached-imenu-alist nil)
3481 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
3483 (defvar anything-c-cached-imenu-candidates nil)
3484 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
3486 (defvar anything-c-cached-imenu-tick nil)
3487 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
3489 (eval-when-compile (require 'imenu))
3490 (setq imenu-auto-rescan t)
3492 (defun anything-imenu-create-candidates (entry)
3493 "Create candidates with ENTRY."
3494 (if (listp (cdr entry))
3495 (mapcan (lambda (sub)
3496 (if (consp (cdr sub))
3497 (mapcar
3498 (lambda (subentry)
3499 (concat (car entry) anything-c-imenu-delimiter subentry))
3500 (anything-imenu-create-candidates sub))
3501 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
3502 (cdr entry))
3503 (list entry)))
3505 (defvar anything-c-source-imenu
3506 '((name . "Imenu")
3507 (init . (lambda () (require 'imenu)))
3508 (candidates . anything-c-imenu-candidates)
3509 (persistent-action . (lambda (elm)
3510 (anything-c-imenu-default-action elm)
3511 (unless (fboundp 'semantic-imenu-tag-overlay)
3512 (anything-match-line-color-current-line))))
3513 (persistent-help . "Show this entry")
3514 (action . anything-c-imenu-default-action))
3515 "See (info \"(emacs)Imenu\")")
3517 ;; (anything 'anything-c-source-imenu)
3519 (defun anything-c-imenu-candidates ()
3520 (with-current-buffer anything-current-buffer
3521 (let ((tick (buffer-modified-tick)))
3522 (if (eq anything-c-cached-imenu-tick tick)
3523 anything-c-cached-imenu-candidates
3524 (setq imenu--index-alist nil)
3525 (setq anything-c-cached-imenu-tick tick
3526 anything-c-cached-imenu-candidates
3527 (ignore-errors
3528 (mapcan
3529 'anything-imenu-create-candidates
3530 (setq anything-c-cached-imenu-alist
3531 (let ((index (imenu--make-index-alist)))
3532 (if anything-c-imenu-index-filter
3533 (funcall anything-c-imenu-index-filter index)
3534 index))))))
3535 (setq anything-c-cached-imenu-candidates
3536 (mapcar #'(lambda (x)
3537 (if (stringp x)
3539 (car x)))
3540 anything-c-cached-imenu-candidates))))))
3542 (setq imenu-default-goto-function 'imenu-default-goto-function)
3543 (defun anything-c-imenu-default-action (elm)
3544 "The default action for `anything-c-source-imenu'."
3545 (let ((path (split-string elm anything-c-imenu-delimiter))
3546 (alist anything-c-cached-imenu-alist))
3547 (if (> (length path) 1)
3548 (progn
3549 (setq alist (assoc (car path) alist))
3550 (setq elm (cadr path))
3551 (imenu (assoc elm alist)))
3552 (imenu (assoc elm alist)))))
3554 ;;; Ctags
3555 (defvar anything-c-ctags-modes
3556 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3557 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3558 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
3560 (defun anything-c-source-ctags-init ()
3561 (when (and buffer-file-name
3562 (memq major-mode anything-c-ctags-modes)
3563 (anything-current-buffer-is-modified))
3564 (with-current-buffer (anything-candidate-buffer 'local)
3565 (call-process-shell-command
3566 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
3567 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
3568 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
3569 nil (current-buffer))
3570 (goto-char (point-min))
3571 (forward-line 2)
3572 (delete-region (point-min) (point))
3573 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
3574 for lineno-start = (point)
3575 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
3577 (beginning-of-line)
3578 (insert (format "%5s:" lineno))
3579 (search-forward "\177" (point-at-eol) t)
3580 (delete-region (1- (point)) (point-at-eol))
3581 (forward-line 1)))))
3583 (defvar anything-c-source-ctags
3584 '((name . "Exuberant ctags")
3585 (init . anything-c-source-ctags-init)
3586 (candidates-in-buffer)
3587 (adjust)
3588 (type . line))
3589 "Needs Exuberant Ctags.
3591 http://ctags.sourceforge.net/")
3592 ;; (anything 'anything-c-source-ctags)
3594 ;; Semantic
3595 (eval-when-compile (require 'semantic nil t))
3596 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
3597 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
3598 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
3599 (defvar anything-semantic-candidates nil)
3601 (defun anything-semantic-construct-candidates (tags depth)
3602 (when (require 'semantic nil t)
3603 (apply 'append
3604 (mapcar (lambda (tag)
3605 (if (listp tag)
3606 (let ((type (semantic-tag-type tag))
3607 (class (semantic-tag-class tag)))
3608 (if (or (and (stringp type)
3609 (or (string= type "class")
3610 (string= type "namespace")))
3611 (eq class 'function)
3612 (eq class 'variable))
3613 (cons (cons (concat (make-string (* depth 2) ?\s)
3614 (semantic-format-tag-summarize tag nil t)) tag)
3615 (anything-semantic-construct-candidates (semantic-tag-components tag)
3616 (1+ depth)))))))
3617 tags))))
3619 (defun anything-semantic-default-action (candidate)
3620 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
3621 (semantic-go-to-tag tag)))
3623 (defvar anything-c-source-semantic
3624 '((name . "Semantic Tags")
3625 (init . (lambda ()
3626 (setq anything-semantic-candidates
3627 (ignore-errors (anything-semantic-construct-candidates (semantic-fetch-tags) 0)))))
3628 (candidates . (lambda ()
3629 (if anything-semantic-candidates
3630 (mapcar 'car anything-semantic-candidates))))
3631 (persistent-action . (lambda (elm)
3632 (anything-semantic-default-action elm)
3633 (anything-match-line-color-current-line)))
3634 (persistent-help . "Show this entry")
3635 (action . anything-semantic-default-action)
3636 "Needs semantic in CEDET.
3638 http://cedet.sourceforge.net/semantic.shtml
3639 http://cedet.sourceforge.net/"))
3641 ;; (anything 'anything-c-source-semantic)
3643 ;;; Function is called by
3644 ;;;###autoload
3645 (defun anything-simple-call-tree ()
3646 "Preconfigured `anything' for simple-call-tree. List function relationships.
3648 Needs simple-call-tree.el.
3649 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
3650 (interactive)
3651 (anything-other-buffer
3652 '(anything-c-source-simple-call-tree-functions-callers
3653 anything-c-source-simple-call-tree-callers-functions)
3654 "*anything simple-call-tree*"))
3656 (defvar anything-c-source-simple-call-tree-functions-callers
3657 '((name . "Function is called by")
3658 (init . anything-c-simple-call-tree-functions-callers-init)
3659 (multiline)
3660 (candidates . anything-c-simple-call-tree-candidates)
3661 (persistent-action . anything-c-simple-call-tree-persistent-action)
3662 (persistent-help . "Show function definitions by rotation")
3663 (action ("Find definition selected by persistent-action" .
3664 anything-c-simple-call-tree-find-definition)))
3665 "Needs simple-call-tree.el.
3666 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3668 (defvar anything-c-simple-call-tree-tick nil)
3669 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
3670 (defun anything-c-simple-call-tree-analyze-maybe ()
3671 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
3672 (simple-call-tree-analyze)
3673 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
3675 (defun anything-c-simple-call-tree-init-base (function message)
3676 (require 'simple-call-tree)
3677 (with-no-warnings
3678 (when (anything-current-buffer-is-modified)
3679 (anything-c-simple-call-tree-analyze-maybe)
3680 (let ((list (funcall function simple-call-tree-alist)))
3681 (with-current-buffer (anything-candidate-buffer 'local)
3682 (dolist (entry list)
3683 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
3684 (insert (car entry) message
3685 (if (string= funcs " ")
3686 " no functions."
3687 funcs)
3688 "\n\n"))))))))
3690 (defun anything-c-simple-call-tree-functions-callers-init ()
3691 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert " is called by\n"))
3693 (defun anything-c-simple-call-tree-candidates ()
3694 (with-current-buffer (anything-candidate-buffer)
3695 (split-string (buffer-string) "\n\n")))
3697 (defvar anything-c-simple-call-tree-related-functions nil)
3698 (defvar anything-c-simple-call-tree-function-index 0)
3699 (defun anything-c-simple-call-tree-persistent-action (candidate)
3700 (unless (eq last-command 'anything-execute-persistent-action)
3701 (setq anything-c-simple-call-tree-related-functions
3702 (delete "no functions."
3703 (split-string
3704 (replace-regexp-in-string " \\| is called by\\| calls " "" candidate)
3705 "\n")))
3706 (setq anything-c-simple-call-tree-function-index -1))
3707 (incf anything-c-simple-call-tree-function-index)
3708 (anything-c-simple-call-tree-find-definition candidate))
3710 (defun anything-c-simple-call-tree-find-definition (candidate)
3711 (find-function (intern
3712 (nth (mod anything-c-simple-call-tree-function-index
3713 (length anything-c-simple-call-tree-related-functions))
3714 anything-c-simple-call-tree-related-functions))))
3716 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3718 ;;; Function calls
3719 (defvar anything-c-source-simple-call-tree-callers-functions
3720 '((name . "Function calls")
3721 (init . anything-c-simple-call-tree-callers-functions-init)
3722 (multiline)
3723 (candidates . anything-c-simple-call-tree-candidates)
3724 (persistent-action . anything-c-simple-call-tree-persistent-action)
3725 (persistent-help . "Show function definitions by rotation")
3726 (action ("Find definition selected by persistent-action" .
3727 anything-c-simple-call-tree-find-definition)))
3728 "Needs simple-call-tree.el.
3729 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3731 (defun anything-c-simple-call-tree-callers-functions-init ()
3732 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
3734 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3736 ;;; Commands/Options with doc
3737 (defvar anything-c-auto-document-data nil)
3738 (make-variable-buffer-local 'anything-c-auto-document-data)
3739 (defvar anything-c-source-commands-and-options-in-file
3740 '((name . "Commands/Options in file")
3741 (header-name
3742 . (lambda (x) (format "Commands/Options in %s"
3743 (buffer-local-value 'buffer-file-name anything-current-buffer))))
3744 (candidates . anything-command-and-options-candidates)
3745 (multiline)
3746 (action . imenu))
3747 "List Commands and Options with doc. It needs auto-document.el .
3749 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3751 (eval-when-compile (require 'auto-document nil t))
3752 (defun anything-command-and-options-candidates ()
3753 (with-current-buffer anything-current-buffer
3754 (when (and (require 'auto-document nil t)
3755 (eq major-mode 'emacs-lisp-mode)
3756 (or (anything-current-buffer-is-modified)
3757 (not anything-c-auto-document-data)))
3758 (or imenu--index-alist (imenu--make-index-alist t))
3759 (setq anything-c-auto-document-data
3760 (destructuring-bind (commands options)
3761 (adoc-construct anything-current-buffer)
3762 (append
3763 (loop for (command . doc) in commands
3764 for cmdname = (symbol-name command)
3765 collect
3766 (cons (format "Command: %s\n %s"
3767 (propertize cmdname 'face font-lock-function-name-face)
3768 (adoc-first-line doc))
3769 (assoc cmdname imenu--index-alist)))
3770 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
3771 for (option doc default) in options
3772 for optname = (symbol-name option)
3773 collect
3774 (cons (format "Option: %s\n %s\n default = %s"
3775 (propertize optname 'face font-lock-variable-name-face)
3776 (adoc-first-line doc)
3777 (adoc-prin1-to-string default))
3778 (assoc optname
3779 var-alist)))))))
3780 anything-c-auto-document-data))
3782 ;; (anything 'anything-c-source-commands-and-options-in-file)
3784 ;;;; <Color and Face>
3785 ;;; Customize Face
3786 (defvar anything-c-source-customize-face
3787 '((name . "Customize Face")
3788 (init . (lambda ()
3789 (unless (anything-candidate-buffer)
3790 (save-window-excursion (list-faces-display))
3791 (anything-candidate-buffer (get-buffer "*Faces*")))))
3792 (candidates-in-buffer)
3793 (get-line . buffer-substring)
3794 (action . (lambda (line)
3795 (customize-face (intern (car (split-string line))))))
3796 (requires-pattern . 3))
3797 "See (info \"(emacs)Faces\")")
3798 ;; (anything 'anything-c-source-customize-face)
3800 ;; Color
3801 (defvar anything-c-source-colors
3802 '((name . "Colors")
3803 (init . (lambda () (unless (anything-candidate-buffer)
3804 (save-window-excursion (list-colors-display))
3805 (anything-candidate-buffer (get-buffer "*Colors*")))))
3806 (candidates-in-buffer)
3807 (get-line . buffer-substring)
3808 (action ("Copy Name" . (lambda (candidate)
3809 (kill-new (anything-c-colors-get-name candidate))))
3810 ("Copy RGB" . (lambda (candidate)
3811 (kill-new (anything-c-colors-get-rgb candidate))))
3812 ("Insert Name" . (lambda (candidate)
3813 (with-current-buffer anything-current-buffer
3814 (insert (anything-c-colors-get-name candidate)))))
3815 ("Insert RGB" . (lambda (candidate)
3816 (with-current-buffer anything-current-buffer
3817 (insert (anything-c-colors-get-rgb candidate))))))))
3818 ;; (anything 'anything-c-source-colors)
3820 (defun anything-c-colors-get-name (candidate)
3821 "Get color name."
3822 (replace-regexp-in-string
3823 " " ""
3824 (with-temp-buffer
3825 (insert (capitalize candidate))
3826 (goto-char (point-min))
3827 (search-forward-regexp "\\s-\\{2,\\}")
3828 (delete-region (point) (point-max))
3829 (buffer-string))))
3831 (defun anything-c-colors-get-rgb (candidate)
3832 "Get color RGB."
3833 (replace-regexp-in-string
3834 " " ""
3835 (with-temp-buffer
3836 (insert (capitalize candidate))
3837 (goto-char (point-max))
3838 (search-backward-regexp "\\s-\\{2,\\}")
3839 (delete-region (point) (point-min))
3840 (buffer-string))))
3842 ;;;; <Search Engine>
3843 ;;; Tracker desktop search
3844 (defvar anything-c-source-tracker-search
3845 '((name . "Tracker Search")
3846 (candidates . (lambda ()
3847 (start-process "tracker-search-process" nil
3848 "tracker-search"
3849 anything-pattern)))
3850 (type . file)
3851 (requires-pattern . 3)
3852 (delayed))
3853 "Source for retrieving files matching the current input pattern
3854 with the tracker desktop search.")
3855 ;; (anything 'anything-c-source-tracker-search)
3857 ;;; Spotlight (MacOS X desktop search)
3858 (defvar anything-c-source-mac-spotlight
3859 '((name . "mdfind")
3860 (candidates . (lambda ()
3861 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
3862 (type . file)
3863 (requires-pattern . 3)
3864 (delayed))
3865 "Source for retrieving files via Spotlight's command line
3866 utility mdfind.")
3867 ;; (anything 'anything-c-source-mac-spotlight)
3870 ;;;; <Kill ring>
3871 ;;; Kill ring
3872 (defvar anything-c-source-kill-ring
3873 '((name . "Kill Ring")
3874 (init . (lambda () (anything-attrset 'last-command last-command)))
3875 (candidates . anything-c-kill-ring-candidates)
3876 (action . anything-c-kill-ring-action)
3877 (last-command)
3878 (migemo)
3879 (multiline))
3880 "Source for browse and insert contents of kill-ring.")
3882 (defun anything-c-kill-ring-candidates ()
3883 (loop for kill in kill-ring
3884 unless (or (< (length kill) anything-kill-ring-threshold)
3885 (string-match "^[\\s\\t]+$" kill))
3886 collect kill))
3888 (defun anything-c-kill-ring-action (str)
3889 "Insert STR in `kill-ring' and set STR to the head.
3890 If this action is executed just after `yank', replace with STR as yanked string."
3891 (setq kill-ring (delete str kill-ring))
3892 (if (not (eq (anything-attr 'last-command) 'yank))
3893 (insert-for-yank str)
3894 ;; from `yank-pop'
3895 (let ((inhibit-read-only t)
3896 (before (< (point) (mark t))))
3897 (if before
3898 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
3899 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
3900 (setq yank-undo-function nil)
3901 (set-marker (mark-marker) (point) (current-buffer))
3902 (insert-for-yank str)
3903 ;; Set the window start back where it was in the yank command,
3904 ;; if possible.
3905 (set-window-start (selected-window) yank-window-start t)
3906 (if before
3907 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3908 ;; It is cleaner to avoid activation, even though the command
3909 ;; loop would deactivate the mark because we inserted text.
3910 (goto-char (prog1 (mark t)
3911 (set-marker (mark-marker) (point) (current-buffer)))))))
3912 (kill-new str))
3914 ;; (anything 'anything-c-source-kill-ring)
3916 ;;;; <Mark ring>
3917 ;; DO NOT include these sources in `anything-sources' use
3918 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
3919 ;; `anything-all-mark-rings' instead.
3921 (defun anything-c-source-mark-ring-candidates ()
3922 (flet ((get-marks (pos)
3923 (save-excursion
3924 (goto-char pos)
3925 (beginning-of-line)
3926 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3927 (when (string= "" line)
3928 (setq line "<EMPTY LINE>"))
3929 (format "%7d: %s" (line-number-at-pos) line)))))
3930 (with-current-buffer anything-current-buffer
3931 (loop
3932 with marks = (cons (mark-marker) mark-ring)
3933 with recip = nil
3934 for i in marks
3935 for m = (get-marks i)
3936 unless (member m recip)
3937 collect m into recip
3938 finally return recip))))
3940 (defvar anything-mark-ring-cache nil)
3941 (defvar anything-c-source-mark-ring
3942 '((name . "mark-ring")
3943 (init . (lambda ()
3944 (setq anything-mark-ring-cache
3945 (ignore-errors (anything-c-source-mark-ring-candidates)))))
3946 (candidates . (lambda ()
3947 (anything-aif anything-mark-ring-cache
3948 it)))
3949 (action . (("Goto line" . (lambda (candidate)
3950 (anything-goto-line (string-to-number candidate))))))
3951 (persistent-action . (lambda (candidate)
3952 (anything-goto-line (string-to-number candidate))
3953 (anything-match-line-color-current-line)))
3954 (persistent-help . "Show this line")))
3956 ;; (anything 'anything-c-source-mark-ring)
3958 ;;;###autoload
3959 (defun anything-mark-ring ()
3960 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3961 (interactive)
3962 (anything 'anything-c-source-mark-ring))
3964 ;;; Global-mark-ring
3965 (defvar anything-c-source-global-mark-ring
3966 '((name . "global-mark-ring")
3967 (candidates . anything-c-source-global-mark-ring-candidates)
3968 (action . (("Goto line" . (lambda (candidate)
3969 (let ((items (split-string candidate ":")))
3970 (switch-to-buffer (second items))
3971 (anything-goto-line (string-to-number (car items))))))))
3972 (persistent-action . (lambda (candidate)
3973 (let ((items (split-string candidate ":")))
3974 (switch-to-buffer (second items))
3975 (anything-goto-line (string-to-number (car items)))
3976 (anything-match-line-color-current-line))))
3977 (persistent-help . "Show this line")))
3979 (defun anything-c-source-global-mark-ring-candidates ()
3980 (flet ((buf-fn (m)
3981 (with-current-buffer (marker-buffer m)
3982 (goto-char m)
3983 (beginning-of-line)
3984 (let (line)
3985 (if (string= "" line)
3986 (setq line "<EMPTY LINE>")
3987 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3988 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
3989 (loop
3990 with marks = global-mark-ring
3991 with recip = nil
3992 for i in marks
3993 for gm = (unless (or (string-match
3994 "^ " (format "%s" (marker-buffer i)))
3995 (null (marker-buffer i)))
3996 (buf-fn i))
3997 when (and gm (not (member gm recip)))
3998 collect gm into recip
3999 finally return recip)))
4001 ;; (anything 'anything-c-source-global-mark-ring)
4003 ;;;###autoload
4004 (defun anything-global-mark-ring ()
4005 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4006 (interactive)
4007 (anything 'anything-c-source-global-mark-ring))
4009 ;;;###autoload
4010 (defun anything-all-mark-rings ()
4011 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4012 `anything-c-source-mark-ring'."
4013 (interactive)
4014 (anything '(anything-c-source-global-mark-ring
4015 anything-c-source-mark-ring)))
4017 ;;;; <Register>
4018 ;;; Insert from register
4019 (defvar anything-c-source-register
4020 '((name . "Registers")
4021 (candidates . anything-c-register-candidates)
4022 (action-transformer . anything-c-register-action-transformer)
4023 (multiline)
4024 (action))
4025 "See (info \"(emacs)Registers\")")
4027 (defun anything-c-register-candidates ()
4028 "Collecting register contents and appropriate commands."
4029 (loop for (char . val) in register-alist
4030 for key = (single-key-description char)
4031 for string-actions = (cond
4032 ((numberp val)
4033 (list (int-to-string val)
4034 'insert-register
4035 'increment-register))
4036 ((markerp val)
4037 (let ((buf (marker-buffer val)))
4038 (if (null buf)
4039 (list "a marker in no buffer")
4040 (list (concat
4041 "a buffer position:"
4042 (buffer-name buf)
4043 ", position "
4044 (int-to-string (marker-position val)))
4045 'jump-to-register
4046 'insert-register))))
4047 ((and (consp val) (window-configuration-p (car val)))
4048 (list "window configuration."
4049 'jump-to-register))
4050 ((and (consp val) (frame-configuration-p (car val)))
4051 (list "frame configuration."
4052 'jump-to-register))
4053 ((and (consp val) (eq (car val) 'file))
4054 (list (concat "file:"
4055 (prin1-to-string (cdr val))
4056 ".")
4057 'jump-to-register))
4058 ((and (consp val) (eq (car val) 'file-query))
4059 (list (concat "file:a file-query reference: file "
4060 (car (cdr val))
4061 ", position "
4062 (int-to-string (car (cdr (cdr val))))
4063 ".")
4064 'jump-to-register))
4065 ((consp val)
4066 (let ((lines (format "%4d" (length val))))
4067 (list (format "%s: %s\n" lines
4068 (truncate-string-to-width
4069 (mapconcat 'identity (list (car val))
4070 ;; (mapconcat (lambda (y) y) val
4071 "^J") (- (window-width) 15)))
4072 'insert-register)))
4073 ((stringp val)
4074 (list ;; without properties
4075 (substring-no-properties val)
4076 'insert-register
4077 'append-to-register
4078 'prepend-to-register))
4080 "GARBAGE!"))
4081 collect (cons (format "register %3s: %s" key (car string-actions))
4082 (cons char (cdr string-actions)))))
4084 (defun anything-c-register-action-transformer (actions register-and-functions)
4085 "Decide actions by the contents of register."
4086 (loop with func-actions =
4087 '((insert-register
4088 "Insert Register" .
4089 (lambda (c) (insert-register (car c))))
4090 (jump-to-register
4091 "Jump to Register" .
4092 (lambda (c) (jump-to-register (car c))))
4093 (append-to-register
4094 "Append Region to Register" .
4095 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
4096 (prepend-to-register
4097 "Prepend Region to Register" .
4098 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
4099 (increment-register
4100 "Increment Prefix Arg to Register" .
4101 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
4102 for func in (cdr register-and-functions)
4103 for cell = (assq func func-actions)
4104 when cell
4105 collect (cdr cell)))
4107 ;; (anything 'anything-c-source-register)
4109 ;;;; <Headline Extraction>
4110 (defvar anything-c-source-fixme
4111 '((name . "TODO/FIXME/DRY comments")
4112 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4113 (adjust)
4114 (recenter))
4115 "Show TODO/FIXME/DRY comments in current file.")
4116 ;; (anything 'anything-c-source-fixme)
4118 (defvar anything-c-source-rd-headline
4119 '((name . "RD HeadLine")
4120 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4121 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
4122 (migemo)
4123 (subexp . 1))
4124 "Show RD headlines.
4126 RD is Ruby's POD.
4127 http://en.wikipedia.org/wiki/Ruby_Document_format")
4128 ;; (anything 'anything-c-source-rd-headline)
4130 (defvar anything-c-source-oddmuse-headline
4131 '((name . "Oddmuse HeadLine")
4132 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4133 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4134 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
4135 (migemo)
4136 (subexp . 1))
4137 "Show Oddmuse headlines, such as EmacsWiki.")
4138 ;; (anything 'anything-c-source-oddmuse-headline)
4140 (defvar anything-c-source-emacs-source-defun
4141 '((name . "Emacs Source DEFUN")
4142 (headline . "DEFUN\\|DEFVAR")
4143 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
4144 "Show DEFUN/DEFVAR in Emacs C source file.")
4145 ;; (anything 'anything-c-source-emacs-source-defun)
4147 (defvar anything-c-source-emacs-lisp-expectations
4148 '((name . "Emacs Lisp Expectations")
4149 (headline . "(desc[ ]\\|(expectations")
4150 (condition . (eq major-mode 'emacs-lisp-mode)))
4151 "Show descriptions (desc) in Emacs Lisp Expectations.
4153 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4154 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4156 (defvar anything-c-source-emacs-lisp-toplevels
4157 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4158 (headline . "^(\\|(@\\*\\|^;;;;")
4159 (get-line . buffer-substring)
4160 (condition . (eq major-mode 'emacs-lisp-mode))
4161 (adjust))
4162 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4163 linkd.el is optional because linkd stars are extracted by regexp.
4164 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4165 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4167 (defvar anything-c-source-org-headline
4168 '((name . "Org HeadLine")
4169 (headline
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 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4175 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4176 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4177 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4178 (condition . (eq major-mode 'org-mode))
4179 (migemo)
4180 (subexp . 1)
4181 (persistent-action . (lambda (elm)
4182 (anything-c-action-line-goto elm)
4183 (org-cycle)))
4184 (action-transformer
4185 . (lambda (actions candidate)
4186 '(("Go to Line" . anything-c-action-line-goto)
4187 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
4188 "Show Org headlines.
4189 org-mode is very very much extended text-mode/outline-mode.
4191 See (find-library \"org.el\")
4192 See http://orgmode.org for the latest version.")
4194 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4195 (insert
4196 (save-excursion
4197 (anything-goto-line (car lineno-and-content))
4198 (and (looking-at org-complex-heading-regexp)
4199 (org-make-link-string (concat "*" (match-string 4)))))))
4201 ;; (anything 'anything-c-source-org-headline)
4203 ;;; Anything yaoddmuse
4204 ;; Be sure to have yaoddmuse.el installed
4205 ;; install-elisp may be required if you want to install elisp file from here.
4206 (defvar anything-yaoddmuse-use-cache-file nil)
4207 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
4208 (defvar anything-c-yaoddmuse-ew-cache nil)
4209 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4210 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
4211 (candidates . (lambda ()
4212 (if anything-yaoddmuse-use-cache-file
4213 (ignore-errors
4214 (unless anything-c-yaoddmuse-ew-cache
4215 (load anything-c-yaoddmuse-cache-file)
4216 (setq anything-c-yaoddmuse-ew-cache
4217 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4218 anything-c-yaoddmuse-ew-cache)
4219 (yaoddmuse-update-pagename t)
4220 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
4221 (action . (("Edit page" . (lambda (candidate)
4222 (yaoddmuse-edit "EmacsWiki" candidate)))
4223 ("Browse page" . (lambda (candidate)
4224 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4225 ("Browse page other window" . (lambda (candidate)
4226 (if (one-window-p)
4227 (split-window-vertically))
4228 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4229 ("Browse diff" . (lambda (candidate)
4230 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
4231 ("Copy URL" . (lambda (candidate)
4232 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
4233 (message "Have copy page %s's URL to yank." candidate)))
4234 ("Create page" . (lambda (candidate)
4235 (yaoddmuse-edit "EmacsWiki" anything-input)))
4236 ("Update cache" . (lambda (candidate)
4237 (if anything-yaoddmuse-use-cache-file
4238 (progn
4239 (anything-yaoddmuse-cache-pages t)
4240 (setq anything-c-yaoddmuse-ew-cache
4241 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4242 (yaoddmuse-update-pagename))))))
4243 (action-transformer anything-c-yaoddmuse-action-transformer))
4244 "Needs yaoddmuse.el.
4246 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4248 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
4250 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
4251 '((name . "Yaoddmuse Post library (EmacsWiki)")
4252 (init . (anything-yaoddmuse-init))
4253 (candidates-in-buffer)
4254 (action . (("Post library and Browse" . (lambda (candidate)
4255 (yaoddmuse-post-file (find-library-name candidate)
4256 "EmacsWiki"
4257 (file-name-nondirectory (find-library-name candidate))
4258 nil t)))
4259 ("Post library" . (lambda (candidate)
4260 (yaoddmuse-post-file (find-library-name candidate)
4261 "EmacsWiki"
4262 (file-name-nondirectory (find-library-name candidate))))))))
4263 "Needs yaoddmuse.el.
4265 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4267 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
4269 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
4270 "Allow the use of `install-elisp' only on elisp files."
4271 (if (string-match "\.el$" candidate)
4272 (append actions '(("Install Elisp" . (lambda (elm)
4273 (install-elisp-from-emacswiki elm)))))
4274 actions))
4276 ;;;###autoload
4277 (defun anything-yaoddmuse-cache-pages (&optional load)
4278 "Fetch the list of files on emacswiki and create cache file.
4279 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
4280 (interactive)
4281 (yaoddmuse-update-pagename)
4282 (save-excursion
4283 (find-file anything-c-yaoddmuse-cache-file)
4284 (erase-buffer)
4285 (insert "(puthash \"EmacsWiki\" '(")
4286 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
4288 (insert (concat "(\"" (car i) "\") ")))
4289 (insert ") yaoddmuse-pages-hash)\n")
4290 (save-buffer)
4291 (kill-buffer (current-buffer))
4292 (when (or current-prefix-arg
4293 load)
4294 (load anything-c-yaoddmuse-cache-file))))
4296 ;;;###autoload
4297 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
4298 "Preconfigured `anything' to edit or view EmacsWiki page.
4300 Needs yaoddmuse.el.
4302 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4303 (interactive)
4304 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
4306 ;;;###autoload
4307 (defun anything-yaoddmuse-emacswiki-post-library ()
4308 "Preconfigured `anything' to post library to EmacsWiki.
4310 Needs yaoddmuse.el.
4312 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4313 (interactive)
4314 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
4316 (defun anything-yaoddmuse-init ()
4317 "Init anything buffer status."
4318 (let ((anything-buffer (anything-candidate-buffer 'global))
4319 (library-list (yaoddmuse-get-library-list)))
4320 (with-current-buffer anything-buffer
4321 ;; Insert library name.
4322 (dolist (library library-list)
4323 (insert (format "%s\n" library)))
4324 ;; Sort lines.
4325 (sort-lines nil (point-min) (point-max)))))
4327 ;;; Eev anchors
4328 (defvar anything-c-source-eev-anchor
4329 '((name . "Anchors")
4330 (candidates
4331 . (lambda ()
4332 (ignore-errors
4333 (with-current-buffer anything-current-buffer
4334 (loop initially (goto-char (point-min))
4335 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
4336 for anchor = (match-string-no-properties 1)
4337 collect (cons (format "%5d:%s"
4338 (line-number-at-pos (match-beginning 0))
4339 (format ee-anchor-format anchor)) anchor))))))
4340 (persistent-action . (lambda (item)
4341 (ee-to item)
4342 (anything-match-line-color-current-line)))
4343 (persistent-help . "Show this entry")
4344 (action . (("Goto link" . ee-to)))))
4345 ;; (anything 'anything-c-source-eev-anchor)
4347 ;;;; <Misc>
4348 ;;; Org keywords
4349 (defvar anything-c-source-org-keywords
4350 '((name . "Org Keywords")
4351 (init . anything-c-org-keywords-init)
4352 (candidates . anything-c-org-keywords-candidates)
4353 (action . anything-c-org-keywords-insert)
4354 (persistent-action . anything-c-org-keywords-show-help)
4355 (persistent-help . "Show an example and info page to describe this keyword.")
4356 (keywords-examples)
4357 (keywords)))
4358 ;; (anything 'anything-c-source-org-keywords)
4359 (defvar anything-c-org-keywords-info-location
4360 '(("#+TITLE:" . "(org)Export options")
4361 ("#+AUTHOR:" . "(org)Export options")
4362 ("#+DATE:" . "(org)Export options")
4363 ("#+EMAIL:" . "(org)Export options")
4364 ("#+DESCRIPTION:" . "(org)Export options")
4365 ("#+KEYWORDS:" . "(org)Export options")
4366 ("#+LANGUAGE:" . "(org)Export options")
4367 ("#+TEXT:" . "(org)Export options")
4368 ("#+TEXT:" . "(org)Export options")
4369 ("#+OPTIONS:" . "(org)Export options")
4370 ("#+BIND:" . "(org)Export options")
4371 ("#+LINK_UP:" . "(org)Export options")
4372 ("#+LINK_HOME:" . "(org)Export options")
4373 ("#+LATEX_HEADER:" . "(org)Export options")
4374 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
4375 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
4376 ("#+INFOJS_OPT" . "(org)Javascript support")
4377 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
4378 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
4379 ("#+ORGTBL" . "(org)Radio tables")
4380 ("#+HTML:" . "(org)Quoting HTML tags")
4381 ("#+LaTeX:" . "(org)Quoting LaTeX code")
4382 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
4383 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
4384 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
4385 ("#+BEGIN_VERSE" . "(org)Paragraphs")
4386 ("#+BEGIN_SRC" . "(org)Literal examples")
4387 ("#+CAPTION" . "(org)Tables in HTML export")
4388 ("#+LABEL" . "(org)Tables in LaTeX export")
4389 ("#+ATTR_HTML" . "(org)Links")
4390 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
4392 (defun anything-c-org-keywords-init ()
4393 (unless (anything-attr 'keywords-examples)
4394 (require 'org)
4395 (anything-attrset 'keywords-examples
4396 (append
4397 (mapcar
4398 (lambda (x)
4399 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
4400 (cons (match-string 2 x) (match-string 1 x)))
4401 (org-split-string (org-get-current-options) "\n"))
4402 (mapcar 'list org-additional-option-like-keywords)))
4403 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
4405 (defun anything-c-org-keywords-candidates ()
4406 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
4407 (anything-attr 'keywords)))
4409 (defun anything-c-org-keywords-insert (keyword)
4410 (cond ((string-match "BEGIN" keyword)
4411 (insert "#+" keyword " ")
4412 (save-excursion
4413 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
4415 (insert "#+" keyword " "))))
4417 (defun anything-c-org-keywords-show-help (keyword)
4418 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
4419 "(org)In-buffer settings"))
4420 (search-forward (concat "#+" keyword) nil t)
4421 (anything-persistent-highlight-point)
4422 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
4425 ;;; Picklist
4426 (defvar anything-c-source-picklist
4427 '((name . "Picklist")
4428 (candidates . (lambda () (mapcar 'car picklist-list)))
4429 (type . file)))
4430 ;; (anything 'anything-c-source-picklist)
4432 ;;; BBDB
4433 (defvar bbdb-records)
4434 (defvar bbdb-buffer-name)
4435 (declare-function bbdb "ext:bbdb-com")
4436 (declare-function bbdb-current-record "ext:bbdb-com")
4437 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
4438 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
4439 (declare-function bbdb-current-record "ext:bbdb-com")
4440 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
4441 (declare-function bbdb-records "ext:bbdb-com"
4442 (&optional dont-check-disk already-in-db-buffer))
4444 (defun anything-c-bbdb-candidates ()
4445 "Return a list of all names in the bbdb database. The format
4446 is \"Firstname Lastname\"."
4447 (mapcar (lambda (bbdb-record)
4448 (replace-regexp-in-string
4449 "\\s-+$" ""
4450 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
4451 (bbdb-records)))
4453 (defun anything-c-bbdb-create-contact (actions candidate)
4454 "Action transformer that returns only an entry to add the
4455 current `anything-pattern' as new contact. All other actions are
4456 removed."
4457 (if (string= candidate "*Add to contacts*")
4458 '(("Add to contacts" . (lambda (actions)
4459 (bbdb-create-internal
4460 (read-from-minibuffer "Name: " anything-c-bbdb-name)
4461 (read-from-minibuffer "Company: ")
4462 (read-from-minibuffer "Email: ")
4465 (read-from-minibuffer "Note: ")))))
4466 actions))
4468 (defun anything-c-bbdb-get-record (candidate)
4469 "Return record that match CANDIDATE."
4470 (bbdb candidate nil)
4471 (set-buffer "*BBDB*")
4472 (bbdb-current-record))
4474 (defvar anything-c-bbdb-name nil
4475 "Only for internal use.")
4477 (defvar anything-c-source-bbdb
4478 '((name . "BBDB")
4479 (candidates . anything-c-bbdb-candidates)
4480 (action ("Send a mail" . anything-c-bbdb-compose-mail)
4481 ("View person's data" . anything-c-bbdb-view-person-action))
4482 (filtered-candidate-transformer . (lambda (candidates source)
4483 (setq anything-c-bbdb-name anything-pattern)
4484 (if (not candidates)
4485 (list "*Add to contacts*")
4486 candidates)))
4487 (action-transformer . (lambda (actions candidate)
4488 (anything-c-bbdb-create-contact actions candidate))))
4489 "Needs BBDB.
4491 http://bbdb.sourceforge.net/")
4492 ;; (anything 'anything-c-source-bbdb)
4494 (defun anything-c-bbdb-view-person-action (candidate)
4495 "View BBDB data of single CANDIDATE or marked candidates."
4496 (anything-aif (anything-marked-candidates)
4497 (let ((bbdb-append-records (length it)))
4498 (dolist (i it)
4499 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
4500 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
4502 (defun anything-c-bbdb-collect-mail-addresses ()
4503 "Return a list of all mail addresses of records in bbdb buffer."
4504 (with-current-buffer bbdb-buffer-name
4505 (loop for i in bbdb-records
4506 if (bbdb-record-net (car i))
4507 collect (bbdb-dwim-net-address (car i)))))
4509 (defun anything-c-bbdb-compose-mail (candidate)
4510 "Compose a mail with all records of bbdb buffer."
4511 (anything-c-bbdb-view-person-action candidate)
4512 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4513 (address-str (mapconcat 'identity address-list ",\n ")))
4514 (compose-mail address-str)))
4516 ;;; Evaluation Result
4517 (defvar anything-c-source-evaluation-result
4518 '((name . "Evaluation Result")
4519 (disable-shortcuts)
4520 (dummy)
4521 (filtered-candidate-transformer . (lambda (candidates source)
4522 (list
4523 (condition-case nil
4524 (with-current-buffer anything-current-buffer
4525 (pp-to-string
4526 (eval (read anything-pattern))))
4527 (error "Error")))))
4528 (action ("Copy result to kill-ring" . (lambda (candidate)
4529 (with-current-buffer anything-buffer
4530 (let ((end (save-excursion
4531 (goto-char (point-max))
4532 (search-backward "\n")
4533 (point))))
4534 (kill-region (point) end))))))))
4535 ;; (anything 'anything-c-source-evaluation-result)
4537 ;;;###autoload
4538 (defun anything-eval-expression (arg)
4539 "Preconfigured anything for `anything-c-source-evaluation-result'."
4540 (interactive "P")
4541 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
4542 nil nil nil "*anything eval*"))
4544 ;;;###autoload
4545 (defun anything-eval-expression-with-eldoc ()
4546 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
4547 (interactive)
4548 (if (window-system)
4549 (let ((timer (run-with-idle-timer eldoc-idle-delay
4550 'repeat 'anything-eldoc-show-in-eval)))
4551 (unwind-protect
4552 (call-interactively 'anything-eval-expression)
4553 (cancel-timer timer)))
4554 (call-interactively 'anything-eval-expression)))
4556 (defun anything-eldoc-show-in-eval ()
4557 "Return eldoc in a tooltip for current minibuffer input."
4558 (let* ((str-all (minibuffer-completion-contents))
4559 (sym (when str-all
4560 (with-temp-buffer
4561 (insert str-all)
4562 (goto-char (point-max))
4563 (unless (looking-back ")\\|\"") (forward-char -1))
4564 (eldoc-current-symbol))))
4565 (doc (or (eldoc-get-var-docstring sym)
4566 (eldoc-get-fnsym-args-string
4567 (car (eldoc-fnsym-in-current-sexp))))))
4568 (when doc (tooltip-show doc))))
4570 ;;; Calculation Result
4571 (defvar anything-c-source-calculation-result
4572 '((name . "Calculation Result")
4573 (dummy)
4574 (filtered-candidate-transformer . (lambda (candidates source)
4575 (list
4576 (condition-case nil
4577 (calc-eval anything-pattern)
4578 (error "error")))))
4579 (action ("Copy result to kill-ring" . kill-new))))
4580 ;; (anything 'anything-c-source-calculation-result)
4582 ;;; Google Suggestions
4583 (defvar anything-gg-sug-lgh-flag 0)
4584 (defun anything-c-google-suggest-fetch (input)
4585 "Fetch suggestions for INPUT from XML buffer.
4586 Return an alist with elements like (data . number_results)."
4587 (let ((request (concat anything-c-google-suggest-url
4588 (url-hexify-string input))))
4589 (flet ((fetch ()
4590 (loop
4591 with result-alist = (xml-get-children
4592 (car (xml-parse-region (point-min) (point-max)))
4593 'CompleteSuggestion)
4594 for i in result-alist
4595 for data = (cdr (caadr (assoc 'suggestion i)))
4596 for nqueries = (cdr (caadr (assoc 'num_queries i)))
4597 for ldata = (length data)
4599 (when (> ldata anything-gg-sug-lgh-flag)
4600 (setq anything-gg-sug-lgh-flag ldata))
4601 collect (cons data nqueries) into cont
4602 finally return cont)))
4603 (if anything-google-suggest-use-curl-p
4604 (with-temp-buffer
4605 (call-process "curl" nil t nil request)
4606 (fetch))
4607 (with-current-buffer
4608 (url-retrieve-synchronously request)
4609 (fetch))))))
4612 (defun anything-c-google-suggest-set-candidates ()
4613 "Set candidates with result and number of google results found."
4614 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
4615 (setq suggestions (loop for i in suggestions
4616 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
4617 for elm = (concat (car i)
4618 (make-string (+ 2 interval) ? )
4619 "(" (cdr i) " results)")
4620 collect (cons elm (car i))))
4621 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
4622 suggestions
4623 ;; if there is no suggestion exactly matching the input then
4624 ;; prepend a Search on Google item to the list
4625 (append
4626 suggestions
4627 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
4628 anything-input))))))
4631 (defun anything-c-google-suggest-action (candidate)
4632 "Default action to jump to a google suggested candidate."
4633 (anything-c-browse-url (concat anything-c-google-suggest-search-url
4634 (url-hexify-string candidate))))
4637 (defvar anything-c-source-google-suggest
4638 '((name . "Google Suggest")
4639 (candidates . anything-c-google-suggest-set-candidates)
4640 (action . (("Google Search" . anything-c-google-suggest-action)))
4641 (volatile)
4642 (requires-pattern . 3)
4643 (delayed)))
4645 ;; (anything 'anything-c-source-google-suggest)
4647 ;;; Yahoo suggestions
4649 (defun anything-c-yahoo-suggest-fetch (input)
4650 "Fetch Yahoo suggestions for INPUT from XML buffer.
4651 Return an alist with elements like (data . number_results)."
4652 (let ((request (concat anything-c-yahoo-suggest-url
4653 (url-hexify-string input))))
4654 (flet ((fetch ()
4655 (loop
4656 with result-alist = (xml-get-children
4657 (car (xml-parse-region (point-min) (point-max)))
4658 'Result)
4659 for i in result-alist
4660 collect (caddr i))))
4661 (with-current-buffer
4662 (url-retrieve-synchronously request)
4663 (fetch)))))
4665 (defun anything-c-yahoo-suggest-set-candidates ()
4666 "Set candidates with Yahoo results found."
4667 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
4668 (or suggestions
4669 (append
4670 suggestions
4671 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
4672 anything-input))))))
4674 (defun anything-c-yahoo-suggest-action (candidate)
4675 "Default action to jump to a Yahoo suggested candidate."
4676 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
4677 (url-hexify-string candidate))))
4679 (defvar anything-c-source-yahoo-suggest
4680 '((name . "Yahoo Suggest")
4681 (candidates . anything-c-yahoo-suggest-set-candidates)
4682 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
4683 (volatile)
4684 (requires-pattern . 3)
4685 (delayed)))
4687 ;; (anything 'anything-c-source-yahoo-suggest)
4689 ;;; Surfraw
4690 ;;; Need external program surfraw.
4691 ;;; http://surfraw.alioth.debian.org/
4692 ;; user variables
4693 (require 'browse-url)
4694 (defvar w3m-command nil)
4695 (defvar anything-c-home-url "http://www.google.fr"
4696 "*Default url to use as home url.")
4698 (defvar anything-browse-url-default-browser-alist
4699 `((,w3m-command . w3m-browse-url)
4700 (,browse-url-firefox-program . browse-url-firefox)
4701 (,browse-url-kde-program . browse-url-kde)
4702 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
4703 (,browse-url-mozilla-program . browse-url-mozilla)
4704 (,browse-url-galeon-program . browse-url-galeon)
4705 (,browse-url-netscape-program . browse-url-netscape)
4706 (,browse-url-mosaic-program . browse-url-mosaic)
4707 (,browse-url-xterm-program . browse-url-text-xterm))
4708 "*Alist of (executable . function) to try to find a suitable url browser.")
4710 (defun anything-browse-url-default-browser (url &rest args)
4711 "Find a suitable browser and ask it to load URL."
4712 (let ((default-browser (loop
4713 for i in anything-browse-url-default-browser-alist
4714 when (and (car i) (executable-find (car i))) return (cdr i))))
4715 (if default-browser
4716 (apply default-browser url args)
4717 (error "No usable browser found"))))
4719 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
4720 "Default command to browse URL."
4721 (if browse-url-browser-function
4722 (browse-url url)
4723 (anything-browse-url-default-browser url)))
4725 (defun anything-c-build-elvi-list ()
4726 "Return list of all engines and descriptions handled by surfraw."
4727 (cdr
4728 (with-temp-buffer
4729 (call-process "surfraw" nil t nil
4730 "-elvi")
4731 (split-string (buffer-string) "\n"))))
4733 ;;;###autoload
4734 (defun anything-surfraw (pattern engine)
4735 "Preconfigured `anything' to search PATTERN with search ENGINE."
4736 (interactive (list (read-string "SearchFor: ")
4737 (anything-comp-read
4738 "Engine: "
4739 (anything-c-build-elvi-list)
4740 :must-match t)))
4741 (let* ((engine-nodesc (car (split-string engine)))
4742 (url (with-temp-buffer
4743 (apply 'call-process "surfraw" nil t nil
4744 (list engine-nodesc "-p" pattern))
4745 (replace-regexp-in-string
4746 "\n" "" (buffer-string)))))
4747 (if (string= engine-nodesc "W")
4748 (anything-c-browse-url)
4749 (anything-c-browse-url url))))
4751 ;;; Emms
4753 ;;;###autoload
4754 (defun anything-emms-stream-edit-bookmark (elm)
4755 "Change the information of current emms-stream bookmark from anything."
4756 (interactive)
4757 (let* ((cur-buf anything-current-buffer)
4758 (bookmark (assoc elm emms-stream-list))
4759 (name (read-from-minibuffer "Description: "
4760 (nth 0 bookmark)))
4761 (url (read-from-minibuffer "URL: "
4762 (nth 1 bookmark)))
4763 (fd (read-from-minibuffer "Feed Descriptor: "
4764 (int-to-string (nth 2 bookmark))))
4765 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4766 (format "%s" (car (last bookmark))))))
4767 (save-excursion
4768 (emms-streams)
4769 (when (re-search-forward (concat "^" name) nil t)
4770 (beginning-of-line)
4771 (emms-stream-delete-bookmark)
4772 (emms-stream-add-bookmark name url (string-to-number fd) type)
4773 (emms-stream-save-bookmarks-file)
4774 (emms-stream-quit)
4775 (switch-to-buffer cur-buf)))))
4777 (defun anything-emms-stream-delete-bookmark (elm)
4778 "Delete an emms-stream bookmark from anything."
4779 (interactive)
4780 (let* ((cur-buf anything-current-buffer)
4781 (bookmark (assoc elm emms-stream-list))
4782 (name (nth 0 bookmark)))
4783 (save-excursion
4784 (emms-streams)
4785 (when (re-search-forward (concat "^" name) nil t)
4786 (beginning-of-line)
4787 (emms-stream-delete-bookmark)
4788 (emms-stream-save-bookmarks-file)
4789 (emms-stream-quit)
4790 (switch-to-buffer cur-buf)))))
4792 (defvar anything-c-source-emms-streams
4793 '((name . "Emms Streams")
4794 (init . (lambda ()
4795 (emms-stream-init)))
4796 (candidates . (lambda ()
4797 (mapcar 'car emms-stream-list)))
4798 (action . (("Play" . (lambda (elm)
4799 (let* ((stream (assoc elm emms-stream-list))
4800 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
4801 (url (second stream)))
4802 (funcall fn url))))
4803 ("Delete" . anything-emms-stream-delete-bookmark)
4804 ("Edit" . anything-emms-stream-edit-bookmark)))
4805 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4806 ;; (anything 'anything-c-source-emms-streams)
4808 ;; Don't forget to set `emms-source-file-default-directory'
4809 (defvar anything-c-source-emms-dired
4810 '((name . "Music Directory")
4811 (candidates . (lambda ()
4812 (cddr (directory-files emms-source-file-default-directory))))
4813 (action .
4814 (("Play Directory" . (lambda (item)
4815 (emms-play-directory
4816 (expand-file-name
4817 item
4818 emms-source-file-default-directory))))
4819 ("Open dired in file's directory" . (lambda (item)
4820 (anything-c-open-dired
4821 (expand-file-name
4822 item
4823 emms-source-file-default-directory))))))
4824 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4825 ;; (anything 'anything-c-source-emms-dired)
4827 (defface anything-emms-playlist
4828 '((t (:foreground "Springgreen4" :underline t)))
4829 "*Face used for tracks in current emms playlist."
4830 :group 'anything)
4832 (defun anything-c-emms-files-modifier (candidates)
4833 (let ((current-playlist (with-current-emms-playlist
4834 (loop
4835 with cur-list = (emms-playlist-tracks-in-region
4836 (point-min) (point-max))
4837 for i in cur-list
4838 collect (assoc-default 'info-file i)))))
4839 (loop for i in candidates
4840 if (member i current-playlist)
4841 collect (propertize i 'face 'anything-emms-playlist) into lis
4842 else collect i into lis finally return lis)))
4844 (defun anything-c-emms-play-current-playlist ()
4845 "Play current playlist."
4846 (with-current-emms-playlist
4847 (emms-playlist-first)
4848 (emms-playlist-mode-play-smart)))
4850 (defvar anything-c-source-emms-files
4851 '((name . "Emms files")
4852 (candidates . (lambda ()
4853 (loop for v being the hash-values in emms-cache-db
4854 for name = (assoc-default 'name v)
4855 unless (string-match "^http:" name) collect name)))
4856 (candidate-transformer . anything-c-emms-files-modifier)
4857 (action . (("Play file" . emms-play-file)
4858 ("Add to Playlist and play"
4859 . (lambda (candidate)
4860 (emms-playlist-new)
4861 (dolist (i (anything-marked-candidates))
4862 (emms-add-playlist-file i))
4863 (unless emms-player-playing-p
4864 (anything-c-emms-play-current-playlist))))))))
4866 ;; (anything 'anything-c-source-emms-files)
4868 ;;; Jabber Contacts (jabber.el)
4869 (defun anything-c-jabber-online-contacts ()
4870 "List online Jabber contacts."
4871 (with-no-warnings
4872 (let (jids)
4873 (dolist (item (jabber-concat-rosters) jids)
4874 (when (get item 'connected)
4875 (push (if (get item 'name)
4876 (cons (get item 'name) item)
4877 (cons (symbol-name item) item)) jids))))))
4879 (defvar anything-c-source-jabber-contacts
4880 '((name . "Jabber Contacts")
4881 (init . (lambda () (require 'jabber)))
4882 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
4883 (action . (lambda (x)
4884 (jabber-chat-with
4885 (jabber-read-account)
4886 (symbol-name
4887 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
4888 ;; (anything 'anything-c-source-jabber-contacts)
4891 ;;; Call source.
4892 (defvar anything-source-select-buffer "*anything source select*")
4893 (defvar anything-c-source-call-source
4894 `((name . "Call anything source")
4895 (candidate-number-limit)
4896 (candidates . (lambda ()
4897 (loop for vname in (all-completions "anything-c-source-" obarray)
4898 for var = (intern vname)
4899 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
4900 if name collect (cons (format "%s `%s'"
4901 name (propertize vname 'face 'font-lock-variable-name-face))
4902 var))))
4903 (action . (("Invoke anything with selected source" .
4904 (lambda (candidate)
4905 (setq anything-candidate-number-limit 9999)
4906 (anything candidate nil nil nil nil
4907 anything-source-select-buffer)))
4908 ("Describe variable" . describe-variable)
4909 ("Find variable" . find-variable)))
4910 (persistent-action . describe-variable)
4911 (persistent-help . "Show description of this source")))
4912 ;; (anything 'anything-c-source-call-source)
4914 ;;;###autoload
4915 (defun anything-call-source ()
4916 "Preconfigured `anything' to call anything source."
4917 (interactive)
4918 (anything 'anything-c-source-call-source nil nil nil nil
4919 anything-source-select-buffer))
4921 (defun anything-call-source-from-anything ()
4922 "Call anything source within `anything' session."
4923 (interactive)
4924 (setq anything-input-idle-delay 0)
4925 (anything-set-sources '(anything-c-source-call-source)))
4927 ;;; Execute Preconfigured anything.
4928 (defvar anything-c-source-anything-commands
4929 '((name . "Preconfigured Anything")
4930 (candidates . anything-c-anything-commands-candidates)
4931 (type . command)
4932 (candidate-number-limit)))
4933 ;; (anything 'anything-c-source-anything-commands)
4935 (defun anything-c-anything-commands-candidates ()
4936 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
4937 collect (cons (if (where-is-internal cmd nil t)
4938 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
4939 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
4940 cmd)))
4942 ;;;###autoload
4943 (defun anything-execute-anything-command ()
4944 "Preconfigured `anything' to execute preconfigured `anything'."
4945 (interactive)
4946 (anything-other-buffer 'anything-c-source-anything-commands
4947 "*anything commands*"))
4949 ;; Occur
4951 (defun anything-c-occur-goto-line (candidate)
4952 "Goto line action for anything-c-source-occur."
4953 (anything-goto-line (string-to-number candidate)))
4955 (defun anything-c-occur-persistent-action (candidate)
4956 "Persistent action for anything occur source."
4957 (anything-c-occur-goto-line candidate)
4958 (anything-match-line-color-current-line))
4960 (defun anything-c-get-occur-candidates ()
4961 "Get `anything-c-source-occur' candidates."
4962 (with-temp-buffer
4963 (let ((count (occur-engine
4964 anything-pattern
4965 (list anything-current-buffer) (current-buffer)
4966 list-matching-lines-default-context-lines nil
4967 list-matching-lines-buffer-name-face
4968 nil list-matching-lines-face
4969 (not (eq occur-excluded-properties t)))))
4970 (when (> count 0)
4971 (cdr (split-string (buffer-string) "\n" t))))))
4973 (defvar anything-c-source-occur
4974 '((name . "Occur")
4975 (candidates . anything-c-get-occur-candidates)
4976 (persistent-action . anything-c-occur-persistent-action)
4977 (persistent-help . "Goto Line")
4978 (action . anything-c-occur-goto-line)
4979 (requires-pattern . 1)
4980 (delayed)
4981 (volatile)))
4982 ;; (anything 'anything-c-source-occur)
4984 ;;;###autoload
4985 (defun anything-occur ()
4986 "Preconfigured Anything for Occur source."
4987 (interactive)
4988 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*"))
4990 ;; Do many actions for input
4991 (defvar anything-c-source-create
4992 '((name . "Create")
4993 (dummy)
4994 (action)
4995 (action-transformer . anything-create--actions))
4996 "Do many create actions from `anything-pattern'.
4997 See also `anything-create--actions'.")
4998 ;; (anything 'anything-c-source-create)
5000 (defun anything-create-from-anything ()
5001 "Run `anything-create' from `anything' as a fallback."
5002 (interactive)
5003 (anything-run-after-quit 'anything-create nil anything-pattern))
5005 ;;;###autoload
5006 (defun anything-create (&optional string initial-input)
5007 "Preconfigured `anything' to do many create actions from STRING.
5008 See also `anything-create--actions'."
5009 (interactive)
5010 (setq string (or string (read-string "Create Anything: " initial-input)))
5011 (anything '(((name . "Anything Create")
5012 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
5013 (candidates . anything-create--actions)
5014 (candidate-number-limit)
5015 (action . (lambda (func) (funcall func string)))))))
5017 (defun anything-create--actions (&rest ignored)
5018 "Default actions for `anything-create' / `anything-c-source-create'."
5019 (remove-if-not
5020 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
5021 (append anything-create--actions-private
5022 '(("find-file" . find-file)
5023 ("find-file other window" . find-file-other-window)
5024 ("New buffer" . switch-to-buffer)
5025 ("New buffer other window" . switch-to-buffer-other-window)
5026 ("Bookmark Set" . bookmark-set)
5027 ("Set Register" .
5028 (lambda (x) (set-register (read-char "Register: ") x)))
5029 ("Insert Linkd star" . linkd-insert-star)
5030 ("Insert Linkd Tag" . linkd-insert-tag)
5031 ("Insert Linkd Link" . linkd-insert-link)
5032 ("Insert Linkd Lisp" . linkd-insert-lisp)
5033 ("Insert Linkd Wiki" . linkd-insert-wiki)
5034 ("Google Search" . google)))))
5036 ;; Minibuffer History
5037 (defvar anything-c-source-minibuffer-history
5038 '((name . "Minibuffer History")
5039 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
5040 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
5041 (if (consp (car history))
5042 (mapcar 'prin1-to-string history)
5043 history))))
5044 (migemo)
5045 (action . insert)))
5046 ;; (anything 'anything-c-source-minibuffer-history)
5048 ;; elscreen
5049 (defvar anything-c-source-elscreen
5050 '((name . "Elscreen")
5051 (candidates . (lambda ()
5052 (if (cdr (elscreen-get-screen-to-name-alist))
5053 (sort
5054 (loop for sname in (elscreen-get-screen-to-name-alist)
5055 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
5056 finally (return lst))
5057 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
5058 (action . (("Change Screen".
5059 (lambda (candidate)
5060 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
5061 ("Kill Screen(s)".
5062 (lambda (candidate)
5063 (dolist (i (anything-marked-candidates))
5064 (elscreen-goto (- (aref i 1) (aref "0" 0)))
5065 (elscreen-kill))))
5066 ("Only Screen".
5067 (lambda (candidate)
5068 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
5069 (elscreen-kill-others)))))))
5070 ;; (anything 'anything-c-source-elscreen)
5072 ;;;; <System>
5074 ;;; Top (process)
5075 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
5076 "Top command (batch mode). %s is replaced with `frame-width'.")
5077 (defvar anything-c-source-top
5078 '((name . "Top (Press C-c C-u to refresh)")
5079 (init . anything-c-top-init)
5080 (candidates-in-buffer)
5081 (display-to-real . anything-c-top-display-to-real)
5082 (update . anything-c-top-update)
5083 (action
5084 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
5085 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
5086 ("Copy PID" . (lambda (pid) (kill-new pid))))))
5087 ;; (anything 'anything-c-source-top)
5089 (defun anything-c-top-sh (cmd)
5090 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
5092 (defun anything-c-top-init ()
5093 (with-current-buffer (anything-candidate-buffer 'global)
5094 (call-process-shell-command
5095 (format anything-c-top-command
5096 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
5097 nil (current-buffer))))
5099 (defun anything-c-top-display-to-real (line)
5100 (car (split-string line)))
5102 (defun anything-c-top-update ()
5103 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
5104 (anything-c-top-init)))
5106 ;;;###autoload
5107 (defun anything-top ()
5108 "Preconfigured `anything' for top command."
5109 (interactive)
5110 (let ((anything-samewindow t)
5111 (anything-enable-shortcuts)
5112 (anything-display-function 'anything-default-display-buffer)
5113 (anything-candidate-number-limit 9999))
5114 (save-window-excursion
5115 (delete-other-windows)
5116 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
5118 ;;; Timers
5119 (defvar anything-c-source-absolute-time-timers
5120 '((name . "Absolute Time Timers")
5121 (candidates . timer-list)
5122 (type . timer)))
5123 ;; (anything 'anything-c-source-absolute-time-timers)
5125 (defvar anything-c-source-idle-time-timers
5126 '((name . "Idle Time Timers")
5127 (candidates . timer-idle-list)
5128 (type . timer)))
5129 ;; (anything 'anything-c-source-idle-time-timers)
5131 (defun anything-c-timer-real-to-display (timer)
5132 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
5133 (append timer nil) ;use `append' to convert vector->list
5134 (format "%s repeat=%5S %s(%s)"
5135 (let ((time (list t1 t2 t3)))
5136 (if idle-delay
5137 (format-time-string "idle-for=%5s" time)
5138 (format-time-string "%m/%d %T" time)))
5139 repeat-delay
5140 func
5141 (mapconcat 'prin1-to-string args " "))))
5143 ;;; X RandR resolution change
5144 ;;; FIXME I do not care multi-display.
5145 (defvar anything-c-xrandr-output "VGA")
5146 (defvar anything-c-xrandr-screen "0")
5147 (defvar anything-c-source-xrandr-change-resolution
5148 '((name . "Change Resolution")
5149 (candidates
5150 . (lambda ()
5151 (with-temp-buffer
5152 (call-process "xrandr" nil (current-buffer) nil
5153 "--screen" anything-c-xrandr-screen "-q")
5154 (goto-char 1)
5155 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
5156 collect (match-string 1)))))
5157 (action
5158 ("Change Resolution" . (lambda (mode)
5159 (call-process "xrandr" nil nil nil
5160 "--screen" anything-c-xrandr-screen
5161 "--output" anything-c-xrandr-output
5162 "--mode" mode))))))
5163 ;; (anything 'anything-c-source-xrandr-change-resolution)
5165 ;;; Xfont selection
5166 (defun anything-c-persistent-xfont-action (elm)
5167 "Show current font temporarily"
5168 (let ((current-font (cdr (assoc 'font (frame-parameters))))
5169 (default-font elm))
5170 (unwind-protect
5171 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
5172 (set-frame-font current-font))))
5174 (defvar anything-c-xfonts-cache nil)
5175 (defvar anything-c-source-xfonts
5176 '((name . "X Fonts")
5177 (init . (lambda ()
5178 (unless anything-c-xfonts-cache
5179 (setq anything-c-xfonts-cache
5180 (x-list-fonts "*")))))
5181 (candidates . anything-c-xfonts-cache)
5182 (action . (("Copy to kill ring" . (lambda (elm)
5183 (kill-new elm)))
5184 ("Set Font" . (lambda (elm)
5185 (kill-new elm)
5186 (set-frame-font elm 'keep-size)
5187 (message "New font have been copied to kill ring")))))
5188 (persistent-action . anything-c-persistent-xfont-action)
5189 (persistent-help . "Switch to this font temporarily")))
5191 ;;;###autoload
5192 (defun anything-select-xfont ()
5193 "Preconfigured `anything' to select Xfont."
5194 (interactive)
5195 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
5197 ;; (anything 'anything-c-source-xfonts)
5199 ;;; Source for Debian/Ubuntu users
5200 (defvar anything-c-source-apt
5201 '((name . "APT")
5202 (init . anything-c-apt-init)
5203 (candidates-in-buffer)
5204 (candidate-transformer anything-c-apt-candidate-transformer)
5205 (display-to-real . anything-c-apt-display-to-real)
5206 (candidate-number-limit . 9999)
5207 (action
5208 ("Show package description" . anything-c-apt-cache-show)
5209 ("Install package" . anything-c-apt-install)
5210 ("Remove package" . anything-c-apt-uninstall)
5211 ("Purge package" . anything-c-apt-purge))
5212 (persistent-action . anything-c-apt-persistent-action)
5213 (persistent-help . "Show - C-u Refresh")))
5214 ;; (anything 'anything-c-source-apt)
5216 (defvar anything-c-apt-query "emacs")
5217 (defvar anything-c-apt-search-command "apt-cache search '%s'")
5218 (defvar anything-c-apt-show-command "apt-cache show '%s'")
5219 (defvar anything-c-apt-installed-packages nil)
5221 (defface anything-apt-installed
5222 '((t (:foreground "green")))
5223 "*Face used for apt installed candidates."
5224 :group 'anything)
5226 (defun anything-c-apt-refresh ()
5227 "Refresh installed candidates list."
5228 (setq anything-c-apt-installed-packages nil)
5229 (anything-force-update))
5231 (defun anything-c-apt-persistent-action (candidate)
5232 "Persistent action for APT source."
5233 (if current-prefix-arg
5234 (anything-c-apt-refresh)
5235 (anything-c-apt-cache-show candidate)))
5237 ;;;###autoload
5238 (defun anything-apt (query)
5239 "Preconfigured `anything' : frontend of APT package manager."
5240 (interactive "sAPT search: ")
5241 (let ((anything-c-apt-query query))
5242 (anything 'anything-c-source-apt)))
5244 (defun anything-c-apt-candidate-transformer (candidates)
5245 "Show installed candidates in a different color."
5246 (loop
5247 with all
5248 for cand in candidates
5249 for name = (anything-c-apt-display-to-real cand)
5250 if (member name anything-c-apt-installed-packages)
5251 collect (propertize cand 'face 'anything-apt-installed) into all
5252 else collect cand into all finally return all))
5254 (defun anything-c-apt-init ()
5255 "Initialize list of debian packages."
5256 (unless anything-c-apt-installed-packages
5257 (message "Updating installed candidate list...")
5258 (setq anything-c-apt-installed-packages
5259 (with-temp-buffer
5260 (call-process-shell-command "dpkg --get-selections"
5261 nil (current-buffer))
5262 (loop for i in (split-string (buffer-string) "\n" t)
5263 collect (car (split-string i))))))
5264 (with-current-buffer
5265 (anything-candidate-buffer
5266 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
5267 (erase-buffer)
5268 (call-process-shell-command
5269 (format anything-c-apt-search-command anything-c-apt-query)
5270 nil (current-buffer)))
5271 (message "Updating installed candidate list...done"))
5273 (defun anything-c-apt-display-to-real (line)
5274 "Return only name of a debian package.
5275 LINE is displayed like:
5276 package name - description."
5277 (car (split-string line " - ")))
5279 ;;;###autoload
5280 (defun anything-c-shell-command-if-needed (command)
5281 (interactive "sShell command: ")
5282 (if (get-buffer command) ; if the buffer already exists
5283 (switch-to-buffer command) ; then just switch to it
5284 (switch-to-buffer command) ; otherwise create it
5285 (insert (shell-command-to-string command))))
5287 (defun anything-c-apt-cache-show (package)
5288 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
5290 (defun anything-c-apt-install (package)
5291 (anything-c-apt-install1 package :action 'install))
5293 (defun anything-c-apt-uninstall (package)
5294 (anything-c-apt-install1 package :action 'uninstall))
5296 (defun anything-c-apt-purge (package)
5297 (anything-c-apt-install1 package :action 'purge))
5299 (defun* anything-c-apt-install1 (candidate &key action)
5300 (ansi-term (getenv "SHELL") "anything apt")
5301 (term-line-mode)
5302 (let ((command (case action
5303 ('install "sudo apt-get install '%s'")
5304 ('uninstall "sudo apt-get remove '%s'")
5305 ('purge "sudo apt-get purge '%s'")
5306 (t (error "Unknow action"))))
5307 (beg (point)) end)
5308 (goto-char (point-max))
5309 (insert (format command candidate))
5310 (setq end (point))
5311 (if (y-or-n-p (format "%s package" (symbol-name action)))
5312 (progn
5313 (setq anything-c-external-commands-list nil)
5314 (setq anything-c-apt-installed-packages nil)
5315 (term-char-mode) (term-send-input))
5316 (delete-region beg end) (term-send-eof) (kill-buffer))))
5318 ;; (anything-c-apt-install "jed")
5320 ;;; Sources for gentoo users
5321 (defvar anything-c-gentoo-use-flags nil)
5322 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
5323 (defvar anything-c-cache-gentoo nil)
5324 (defvar anything-c-cache-world nil)
5325 (defvar anything-c-source-gentoo
5326 '((name . "Portage sources")
5327 (init . (lambda ()
5328 (get-buffer-create anything-c-gentoo-buffer)
5329 (unless anything-c-cache-gentoo
5330 (anything-c-gentoo-setup-cache))
5331 (unless anything-c-cache-world
5332 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
5333 (anything-c-gentoo-init-list)))
5334 (candidates-in-buffer)
5335 (match . identity)
5336 (candidate-transformer anything-c-highlight-world)
5337 (action . (("Show package" . (lambda (elm)
5338 (anything-c-gentoo-eshell-action elm "eix")))
5339 ("Show history" . (lambda (elm)
5340 (if (member elm anything-c-cache-world)
5341 (anything-c-gentoo-eshell-action elm "genlop -qe")
5342 (message "No infos on packages not yet installed"))))
5343 ("Copy in kill-ring" . kill-new)
5344 ("insert at point" . insert)
5345 ("Browse HomePage" . (lambda (elm)
5346 (let ((urls (anything-c-gentoo-get-url elm)))
5347 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
5348 ("Show extra infos" . (lambda (elm)
5349 (if (member elm anything-c-cache-world)
5350 (anything-c-gentoo-eshell-action elm "genlop -qi")
5351 (message "No infos on packages not yet installed"))))
5352 ("Show use flags" . (lambda (elm)
5353 (anything-c-gentoo-default-action elm "equery" "-C" "u")
5354 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
5355 (font-lock-mode 1)))
5356 ("Run emerge pretend" . (lambda (elm)
5357 (anything-c-gentoo-eshell-action elm "emerge -p")))
5358 ("Emerge" . (lambda (elm)
5359 (anything-gentoo-install elm :action 'install)))
5360 ("Unmerge" . (lambda (elm)
5361 (anything-gentoo-install elm :action 'uninstall)))
5362 ("Show dependencies" . (lambda (elm)
5363 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
5364 ("Show related files" . (lambda (elm)
5365 (anything-c-gentoo-default-action elm "equery" "files")))
5366 ("Refresh" . (lambda (elm)
5367 (anything-c-gentoo-setup-cache)
5368 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
5370 ;; (anything 'anything-c-source-gentoo)
5372 (defun* anything-gentoo-install (candidate &key action)
5373 (setq anything-c-external-commands-list nil)
5374 (ansi-term (getenv "SHELL") "anything gentoo")
5375 (term-line-mode)
5376 (let ((command (case action
5377 ('install "sudo emerge -av ")
5378 ('uninstall "sudo emerge -avC ")
5379 (t (error "Unknow action"))))
5380 (elms (mapconcat 'identity (anything-marked-candidates) " "))
5381 (beg (point)) end)
5382 (goto-char (point-max))
5383 (insert (concat command elms))
5384 (setq end (point))
5385 (term-char-mode) (term-send-input)))
5387 (defun anything-c-gentoo-default-action (elm command &rest args)
5388 "Gentoo default action that use `anything-c-gentoo-buffer'."
5389 (if (member elm anything-c-cache-world)
5390 (progn
5391 (switch-to-buffer anything-c-gentoo-buffer)
5392 (erase-buffer)
5393 (let ((com-list (append args (list elm))))
5394 (apply #'call-process command nil t nil
5395 com-list)))
5396 (message "No infos on packages not yet installed")))
5398 (defvar anything-c-source-use-flags
5399 '((name . "Use Flags")
5400 (init . (lambda ()
5401 (unless anything-c-gentoo-use-flags
5402 (anything-c-gentoo-setup-use-flags-cache))
5403 (anything-c-gentoo-get-use)))
5404 (candidates-in-buffer)
5405 (match . identity)
5406 (candidate-transformer anything-c-highlight-local-use)
5407 (action . (("Description"
5408 . (lambda (elm)
5409 (switch-to-buffer anything-c-gentoo-buffer)
5410 (erase-buffer)
5411 (apply #'call-process "euse" nil t nil
5412 `("-i"
5413 ,elm))
5414 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
5415 (font-lock-mode 1)))
5416 ("Enable"
5417 . (lambda (elm)
5418 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
5419 ("Disable"
5420 . (lambda (elm)
5421 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
5422 ("Remove"
5423 . (lambda (elm)
5424 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
5425 ("Show which dep use this flag"
5426 . (lambda (elm)
5427 (switch-to-buffer anything-c-gentoo-buffer)
5428 (erase-buffer)
5429 (apply #'call-process "equery" nil t nil
5430 `("-C"
5432 ,elm))))))))
5435 ;; (anything 'anything-c-source-use-flags)
5437 (defun anything-c-gentoo-init-list ()
5438 "Initialize buffer with all packages in Portage."
5439 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
5440 (buf (anything-candidate-buffer 'portage-buf)))
5441 (with-current-buffer buf
5442 (dolist (i anything-c-cache-gentoo)
5443 (insert (concat i "\n"))))))
5445 (defun anything-c-gentoo-setup-cache ()
5446 "Set up `anything-c-cache-gentoo'"
5447 (setq anything-c-cache-gentoo
5448 (split-string (with-temp-buffer
5449 (call-process "eix" nil t nil
5450 "--only-names")
5451 (buffer-string)))))
5453 (defun anything-c-gentoo-eshell-action (elm command)
5454 (when (get-buffer "*EShell Command Output*")
5455 (kill-buffer "*EShell Command Output*"))
5456 (message "Wait searching...")
5457 (let ((buf-fname (buffer-file-name anything-current-buffer)))
5458 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
5459 (progn
5460 (save-window-excursion
5461 (pop-to-buffer "*scratch*")
5462 (eshell-command (format "%s %s" command elm)))
5463 (pop-to-buffer "*EShell Command Output*"))
5464 (eshell-command (format "%s %s" command elm)))))
5466 (defun anything-c-gentoo-get-use ()
5467 "Initialize buffer with all use flags."
5468 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
5469 (buf (anything-candidate-buffer 'use-buf)))
5470 (with-current-buffer buf
5471 (dolist (i anything-c-gentoo-use-flags)
5472 (insert (concat i "\n"))))))
5475 (defun anything-c-gentoo-setup-use-flags-cache ()
5476 "Setup `anything-c-gentoo-use-flags'"
5477 (setq anything-c-gentoo-use-flags
5478 (split-string (with-temp-buffer
5479 (call-process "eix" nil t nil
5480 "--print-all-useflags")
5481 (buffer-string)))))
5483 (defun anything-c-gentoo-get-url (elm)
5484 "Return a list of urls from eix output."
5485 (loop
5486 with url-list = (split-string
5487 (with-temp-buffer
5488 (call-process "eix" nil t nil
5489 elm "--format" "<homepage>\n")
5490 (buffer-string)))
5491 with all
5492 for i in url-list
5493 when (and (string-match "^http://.*" i)
5494 (not (member i all)))
5495 collect i into all
5496 finally return all))
5498 (defun anything-c-gentoo-get-world ()
5499 "Return list of all installed package on your system."
5500 (split-string (with-temp-buffer
5501 (call-process "qlist" nil t nil
5502 "-I")
5503 (buffer-string))))
5505 (defun anything-c-gentoo-get-local-use ()
5506 (split-string (with-temp-buffer
5507 (call-process "portageq" nil t nil
5508 "envvar"
5509 "USE")
5510 (buffer-string))))
5512 (defface anything-gentoo-match-face '((t (:foreground "red")))
5513 "Face for anything-gentoo installed packages."
5514 :group 'traverse-faces)
5516 (defun anything-c-highlight-world (eix)
5517 "Highlight all installed package."
5518 (loop for i in eix
5519 if (member i anything-c-cache-world)
5520 collect (propertize i 'face 'anything-gentoo-match-face)
5521 else
5522 collect i))
5524 (defun anything-c-highlight-local-use (use-flags)
5525 (let ((local-uses (anything-c-gentoo-get-local-use)))
5526 (loop for i in use-flags
5527 if (member i local-uses)
5528 collect (propertize i 'face 'anything-gentoo-match-face)
5529 else
5530 collect i)))
5532 (defvar anything-c-source-emacs-process
5533 '((name . "Emacs Process")
5534 (candidates . (lambda () (mapcar #'process-name (process-list))))
5535 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
5537 ;; (anything 'anything-c-source-emacs-process)
5539 ;; Run Externals commands within Emacs
5540 (defmacro* anything-comp-hash-get-items (hash-table &key test)
5541 "Get the list of all keys/values of hash-table."
5542 `(let ((li-items ()))
5543 (maphash #'(lambda (x y)
5544 (if ,test
5545 (when (funcall ,test y)
5546 (push (list x y) li-items))
5547 (push (list x y) li-items)))
5548 ,hash-table)
5549 li-items))
5551 (defun anything-comp-read-get-candidates (collection &optional test)
5552 "Convert collection to list.
5553 If collection is an `obarray', a test is maybe needed, otherwise
5554 the list would be incomplete.
5555 See `obarray'."
5556 (cond ((and (listp collection) test)
5557 (loop for i in collection when (funcall test i) collect i))
5558 ((and (eq collection obarray) test)
5559 (loop for s being the symbols of collection
5560 when (funcall test s) collect s))
5561 ((and (vectorp collection) test)
5562 (loop for i across collection when (funcall test i) collect i))
5563 ((vectorp collection)
5564 (loop for i across collection collect i))
5565 ((and (hash-table-p collection) test)
5566 (anything-comp-hash-get-items collection :test test))
5567 ((hash-table-p collection)
5568 (anything-comp-hash-get-items collection))
5569 (t collection)))
5571 (defun* anything-comp-read (prompt collection &key test initial-input
5572 (buffer "*Anything Completions*") must-match
5573 (requires-pattern 0))
5574 "Anything `completing-read' emulation.
5575 Collection can be a list, vector, obarray or hash-table."
5576 (when (get-buffer anything-action-buffer)
5577 (kill-buffer anything-action-buffer))
5578 (or (anything
5579 `((name . "Completions")
5580 (candidates
5581 . (lambda ()
5582 (let ((cands (anything-comp-read-get-candidates collection test)))
5583 (if (or must-match (string= anything-pattern ""))
5584 cands (append (list anything-pattern) cands)))))
5585 (requires-pattern . ,requires-pattern)
5586 (volatile)
5587 (action . (("candidate" . ,'identity))))
5588 initial-input prompt 'noresume nil buffer)
5589 (keyboard-quit)))
5591 (defun anything-c-get-pid-from-process-name (process-name)
5592 "Get pid from running process PROCESS-NAME."
5593 (loop with process-list = (list-system-processes)
5594 for pid in process-list
5595 for process = (assoc-default 'comm (process-attributes pid))
5596 when (and process (string-match process-name process))
5597 return pid))
5600 (defun anything-run-or-raise (exe &optional file)
5601 "Generic command that run asynchronously EXE.
5602 If EXE is already running just jump to his window if `anything-raise-command'
5603 is non--nil.
5604 When FILE argument is provided run EXE with FILE.
5605 In this case EXE must be provided as \"EXE %s\"."
5606 (let ((real-com (car (split-string (replace-regexp-in-string " %s" "" exe)))))
5607 (if (or (get-process real-com)
5608 (anything-c-get-pid-from-process-name real-com))
5609 (if anything-raise-command
5610 (shell-command (format anything-raise-command real-com))
5611 (error "Error: %s is already running" real-com))
5612 (when (member real-com anything-c-external-commands-list)
5613 (message "Starting %s..." real-com)
5614 (if file
5615 (start-process-shell-command real-com nil (format exe file))
5616 (start-process-shell-command real-com nil real-com))
5617 (set-process-sentinel
5618 (get-process real-com)
5619 #'(lambda (process event)
5620 (when (string= event "finished\n")
5621 (when anything-raise-command
5622 (shell-command (format anything-raise-command "emacs")))
5623 (message "%s process...Finished." process))))
5624 (setq anything-c-external-commands-list
5625 (push (pop (nthcdr (anything-c-position
5626 real-com anything-c-external-commands-list
5627 :test 'equal)
5628 anything-c-external-commands-list))
5629 anything-c-external-commands-list))))))
5631 ;;;###autoload
5632 (defun anything-c-run-external-command (program)
5633 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
5634 If program is already running exit with error.
5635 You can set your own list of commands with
5636 `anything-c-external-commands-list'."
5637 (interactive (list
5638 (anything-comp-read
5639 "RunProgram: "
5640 (anything-c-external-commands-list-1 'sort)
5641 :must-match t)))
5642 (anything-run-or-raise program))
5644 (defsubst* anything-c-position (item seq &key (test 'eq))
5645 "A simple and faster replacement of CL `position'."
5646 (loop for i in seq for index from 0
5647 when (funcall test i item) return index))
5649 (defvar anything-c-source-ratpoison-commands
5650 '((name . "Ratpoison Commands")
5651 (init . anything-c-ratpoison-commands-init)
5652 (candidates-in-buffer)
5653 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
5654 (display-to-real . anything-c-ratpoison-commands-display-to-real)
5655 (candidate-number-limit)))
5656 ;; (anything 'anything-c-source-ratpoison-commands)
5658 (defun anything-c-ratpoison-commands-init ()
5659 (unless (anything-candidate-buffer)
5660 (with-current-buffer (anything-candidate-buffer 'global)
5661 ;; with ratpoison prefix key
5662 (save-excursion
5663 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
5664 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5665 (replace-match "<ratpoison> \\1: \\2"))
5666 (goto-char (point-max))
5667 ;; direct binding
5668 (save-excursion
5669 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
5670 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5671 (replace-match "\\1: \\2")))))
5673 (defun anything-c-ratpoison-commands-display-to-real (display)
5674 (and (string-match ": " display)
5675 (substring display (match-end 0))))
5677 (defun anything-c-ratpoison-commands-execute (candidate)
5678 (call-process "ratpoison" nil nil nil "-ic" candidate))
5680 ;;;###autoload
5681 (defun anything-ratpoison-commands ()
5682 "Preconfigured `anything' to execute ratpoison commands."
5683 (interactive)
5684 (anything-other-buffer 'anything-c-source-ratpoison-commands
5685 "*anything ratpoison commands*"))
5687 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5688 ;;; Files
5689 (defvar anything-c-external-commands-list nil
5690 "A list of all external commands the user can execute. If this
5691 variable is not set by the user, it will be calculated
5692 automatically.")
5694 (defun anything-c-external-commands-list-1 (&optional sort)
5695 "Returns a list of all external commands the user can execute.
5697 If `anything-c-external-commands-list' is non-nil it will
5698 return its contents. Else it calculates all external commands
5699 and sets `anything-c-external-commands-list'.
5701 The code is ripped out of `eshell-complete-commands-list'."
5702 (if anything-c-external-commands-list
5703 anything-c-external-commands-list
5704 (setq anything-c-external-commands-list
5705 (let* ((paths (split-string (getenv "PATH") path-separator))
5706 (cwd (file-name-as-directory
5707 (expand-file-name default-directory)))
5708 (path "") (comps-in-path ())
5709 (file "") (filepath "") (completions ()))
5710 ;; Go thru each path in the search path, finding completions.
5711 (while paths
5712 (setq path (file-name-as-directory
5713 (expand-file-name (or (car paths) ".")))
5714 comps-in-path
5715 (and (file-accessible-directory-p path)
5716 (file-name-all-completions "" path)))
5717 ;; Go thru each completion found, to see whether it should be
5718 ;; used, e.g. see if it's executable.
5719 (while comps-in-path
5720 (setq file (car comps-in-path)
5721 filepath (concat path file))
5722 (if (and (not (member file completions))
5723 (or (string-equal path cwd)
5724 (not (file-directory-p filepath)))
5725 (file-executable-p filepath))
5726 (setq completions (cons file completions)))
5727 (setq comps-in-path (cdr comps-in-path)))
5728 (setq paths (cdr paths)))
5729 (if sort
5730 (sort completions #'(lambda (x y) (string< x y)))
5731 completions)))))
5733 (defun anything-c-file-buffers (filename)
5734 "Returns a list of buffer names corresponding to FILENAME."
5735 (let ((name (expand-file-name filename))
5736 (buf-list ()))
5737 (dolist (buf (buffer-list) buf-list)
5738 (let ((bfn (buffer-file-name buf)))
5739 (when (and bfn (string= name bfn))
5740 (push (buffer-name buf) buf-list))))))
5742 (defun anything-c-delete-file (file)
5743 "Delete the given file after querying the user.
5744 Ask to kill buffers associated with that file, too."
5745 (let ((buffers (anything-c-file-buffers file)))
5746 (dired-delete-file file 'dired-recursive-deletes)
5747 (when buffers
5748 (dolist (buf buffers)
5749 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
5750 (kill-buffer buf))))))
5752 (defun anything-get-mailcap-for-file (filename)
5753 "Get the command to use for FILENAME from mailcap files.
5754 The command is like <command %s> and is meant to use with `format'."
5755 (mailcap-parse-mailcaps)
5756 (let* ((ext (file-name-extension filename))
5757 (mime (when ext (mailcap-extension-to-mime ext))))
5758 (when mime (mailcap-mime-info mime))))
5760 (defun anything-c-open-file-externally (file)
5761 "Open FILE with an external tool found in .mailcap file.
5762 If not found or a prefix arg is given query the user which tool to use."
5763 (let* ((fname (expand-file-name file))
5764 (collection (anything-c-external-commands-list-1 'sort))
5765 (def-prog (anything-get-mailcap-for-file fname))
5766 (program (or (unless (or anything-current-prefix-arg
5767 (not def-prog))
5768 def-prog)
5769 (concat
5770 (anything-comp-read
5771 "Program: "
5772 collection :must-match t)
5773 " %s"))))
5774 (anything-run-or-raise program file)))
5776 ;;;###autoload
5777 (defun w32-shell-execute-open-file (file)
5778 (interactive "fOpen file:")
5779 (with-no-warnings
5780 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
5781 "/" "\\"
5782 (replace-regexp-in-string ; strip cygdrive paths
5783 "/cygdrive/\\(.\\)" "\\1:"
5784 file nil nil) nil t))))
5786 (defun anything-c-open-file-with-default-tool (file)
5787 "Open FILE with the default tool on this platform."
5788 (if (eq system-type 'windows-nt)
5789 (w32-shell-execute-open-file file)
5790 (start-process "anything-c-open-file-with-default-tool"
5792 (cond ((eq system-type 'gnu/linux)
5793 "xdg-open")
5794 ((or (eq system-type 'darwin) ;; Mac OS X
5795 (eq system-type 'macos)) ;; Mac OS 9
5796 "open"))
5797 file)))
5799 (defun anything-c-open-dired (file)
5800 "Opens a dired buffer in FILE's directory. If FILE is a
5801 directory, open this directory."
5802 (if (file-directory-p file)
5803 (dired file)
5804 (dired (file-name-directory file))
5805 (dired-goto-file file)))
5807 (defun anything-c-display-to-real-line (candidate)
5808 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
5809 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
5810 (error "Line number not found")))
5812 (defun anything-c-action-line-goto (lineno-and-content)
5813 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
5814 (append lineno-and-content
5815 (list (if (and (anything-attr-defined 'target-file)
5816 (not anything-in-persistent-action))
5817 'find-file-other-window
5818 'find-file)))))
5820 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
5821 (apply #'anything-goto-file-line
5822 (if (stringp file-line-content)
5823 ;; Case: filtered-candidate-transformer is skipped
5824 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
5825 file-line-content)))
5827 (require 'compile)
5828 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
5829 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
5831 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
5832 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
5833 (let ((filename (match-string 1 candidate))
5834 (lineno (match-string 2 candidate))
5835 (content (match-string 3 candidate)))
5836 (cons (format "%s:%s\n %s"
5837 (propertize filename 'face compilation-info-face)
5838 (propertize lineno 'face compilation-line-face)
5839 content)
5840 (list (expand-file-name
5841 filename
5842 (or (anything-interpret-value (anything-attr 'default-directory))
5843 (and (anything-candidate-buffer)
5844 (buffer-local-value
5845 'default-directory (anything-candidate-buffer)))))
5846 (string-to-number lineno) content)))))
5848 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
5849 (anything-aif (anything-attr 'before-jump-hook)
5850 (funcall it))
5851 (when file (funcall find-file-function file))
5852 (if (anything-attr-defined 'adjust)
5853 (anything-c-goto-line-with-adjustment lineno content)
5854 (anything-goto-line lineno))
5855 (unless (anything-attr-defined 'recenter)
5856 (set-window-start (get-buffer-window anything-current-buffer) (point)))
5857 (anything-aif (anything-attr 'after-jump-hook)
5858 (funcall it))
5859 (when anything-in-persistent-action
5860 (anything-match-line-color-current-line)))
5862 (defun anything-find-file-as-root (candidate)
5863 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
5865 (defun anything-find-many-files (ignore)
5866 (mapc 'find-file (anything-marked-candidates)))
5868 ;; borrowed from etags.el
5869 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
5870 (defun anything-c-goto-line-with-adjustment (line line-content)
5871 (let ((startpos)
5872 offset found pat)
5873 ;; This constant is 1/2 the initial search window.
5874 ;; There is no sense in making it too small,
5875 ;; since just going around the loop once probably
5876 ;; costs about as much as searching 2000 chars.
5877 (setq offset 1000
5878 found nil
5879 pat (concat (if (eq selective-display t)
5880 "\\(^\\|\^m\\) *" "^ *") ;allow indent
5881 (regexp-quote line-content)))
5882 ;; If no char pos was given, try the given line number.
5883 (setq startpos (progn (anything-goto-line line) (point)))
5884 (or startpos (setq startpos (point-min)))
5885 ;; First see if the tag is right at the specified location.
5886 (goto-char startpos)
5887 (setq found (looking-at pat))
5888 (while (and (not found)
5889 (progn
5890 (goto-char (- startpos offset))
5891 (not (bobp))))
5892 (setq found
5893 (re-search-forward pat (+ startpos offset) t)
5894 offset (* 3 offset))) ; expand search window
5895 (or found
5896 (re-search-forward pat nil t)
5897 (error "not found")))
5898 ;; Position point at the right place
5899 ;; if the search string matched an extra Ctrl-m at the beginning.
5900 (and (eq selective-display t)
5901 (looking-at "\^m")
5902 (forward-char 1))
5903 (beginning-of-line))
5905 (anything-document-attribute 'default-directory "type . file-line"
5906 "`default-directory' to interpret file.")
5907 (anything-document-attribute 'before-jump-hook "type . file-line / line"
5908 "Function to call before jumping to the target location.")
5909 (anything-document-attribute 'after-jump-hook "type . file-line / line"
5910 "Function to call after jumping to the target location.")
5911 (anything-document-attribute 'adjust "type . file-line"
5912 "Search around line matching line contents.")
5913 (anything-document-attribute 'recenter "type . file-line / line"
5914 "`recenter' after jumping.")
5915 (anything-document-attribute 'target-file "type . line"
5916 "Goto line of target-file.")
5918 ;;;###autoload
5919 (defun anything-c-call-interactively (cmd-or-name)
5920 "Execute CMD-OR-NAME as Emacs command.
5921 It is added to `extended-command-history'.
5922 `anything-current-prefix-arg' is used as the command's prefix argument."
5923 (setq extended-command-history
5924 (cons (anything-c-stringify cmd-or-name)
5925 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
5926 (let ((current-prefix-arg anything-current-prefix-arg)
5927 (cmd (anything-c-symbolify cmd-or-name)))
5928 (if (stringp (symbol-function cmd))
5929 (execute-kbd-macro (symbol-function cmd))
5930 (setq this-command cmd)
5931 (call-interactively cmd))))
5933 ;;;###autoload
5934 (defun anything-c-set-variable (var)
5935 "Set value to VAR interactively."
5936 (interactive)
5937 (let ((sym (anything-c-symbolify var)))
5938 (set sym (eval-minibuffer (format "Set %s: " var)
5939 (prin1-to-string (symbol-value sym))))))
5940 ;; (setq hh 12)
5941 ;; (anything-c-set-variable 'hh)
5943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5944 (defvar anything-match-line-overlay-face nil)
5945 (defvar anything-match-line-overlay nil)
5947 (defun anything-match-line-color-current-line (&optional start end buf face rec)
5948 "Highlight and underline current position"
5949 (let ((args (list (or start (line-beginning-position))
5950 (or end (1+ (line-end-position)))
5951 buf)))
5952 (if (not anything-match-line-overlay)
5953 (setq anything-match-line-overlay (apply 'make-overlay args))
5954 (apply 'move-overlay anything-match-line-overlay args)))
5955 (overlay-put anything-match-line-overlay
5956 'face (or face anything-match-line-overlay-face))
5957 (when rec
5958 (goto-char start)
5959 (recenter)))
5961 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
5963 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
5964 "Face for source header in the anything buffer." :group 'anything)
5966 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
5968 (defun anything-match-line-cleanup ()
5969 (when anything-match-line-overlay
5970 (delete-overlay anything-match-line-overlay)
5971 (setq anything-match-line-overlay nil)))
5973 (defun anything-match-line-update ()
5974 (when anything-match-line-overlay
5975 (delete-overlay anything-match-line-overlay)
5976 (anything-match-line-color-current-line)))
5978 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
5979 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
5981 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5982 ;;; Files
5983 (defun anything-c-transform-file-load-el (actions candidate)
5984 "Add action to load the file CANDIDATE if it is an emacs lisp
5985 file. Else return ACTIONS unmodified."
5986 (if (member (file-name-extension candidate) '("el" "elc"))
5987 (append actions '(("Load Emacs Lisp File" . load-file)))
5988 actions))
5990 (defun anything-c-transform-file-browse-url (actions candidate)
5991 "Add an action to browse the file CANDIDATE if it in a html
5992 file or URL. Else return ACTIONS unmodified."
5993 (let ((browse-action '("Browse with Browser" . browse-url)))
5994 (cond ((string-match "^http\\|^ftp" candidate)
5995 (cons browse-action actions))
5996 ((string-match "\\.html?$" candidate)
5997 (append actions (list browse-action)))
5998 (t actions))))
6000 ;;;; Function
6001 (defun anything-c-transform-function-call-interactively (actions candidate)
6002 "Add an action to call the function CANDIDATE interactively if
6003 it is a command. Else return ACTIONS unmodified."
6004 (if (commandp (intern-soft candidate))
6005 (append actions '(("Call Interactively"
6007 anything-c-call-interactively)))
6008 actions))
6010 ;;;; S-Expressions
6011 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
6012 "If CANDIDATE's `car' is a command, then add an action to
6013 evaluate it and put it onto the `command-history'."
6014 (if (commandp (car (read candidate)))
6015 ;; Make it first entry
6016 (cons '("Eval and put onto command-history" .
6017 (lambda (sexp)
6018 (let ((sym (read sexp)))
6019 (eval sym)
6020 (setq command-history
6021 (cons sym command-history)))))
6022 actions)
6023 actions))
6025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6026 ;;; Buffers
6027 (defun anything-c-skip-boring-buffers (buffers)
6028 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
6030 (defun anything-c-skip-current-buffer (buffers)
6031 (if anything-allow-skipping-current-buffer
6032 (remove (buffer-name anything-current-buffer) buffers)
6033 buffers))
6035 (defun anything-c-shadow-boring-buffers (buffers)
6036 "Buffers matching `anything-c-boring-buffer-regexp' will be
6037 displayed with the `file-name-shadow' face if available."
6038 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
6040 ;;; Files
6041 (defun anything-c-shadow-boring-files (files)
6042 "Files matching `anything-c-boring-file-regexp' will be
6043 displayed with the `file-name-shadow' face if available."
6044 (anything-c-shadow-entries files anything-c-boring-file-regexp))
6046 (defun anything-c-skip-boring-files (files)
6047 "Files matching `anything-c-boring-file-regexp' will be skipped."
6048 (anything-c-skip-entries files anything-c-boring-file-regexp))
6049 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6051 (defun anything-c-skip-current-file (files)
6052 "Current file will be skipped."
6053 (remove (buffer-file-name anything-current-buffer) files))
6055 (defun anything-c-w32-pathname-transformer (args)
6056 "Change undesirable features of windows pathnames to ones more acceptable to
6057 other candidate transformers."
6058 (if (eq system-type 'windows-nt)
6059 (mapcar (lambda (x)
6060 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
6061 (mapcar (lambda (y)
6062 (replace-regexp-in-string "\\\\" "/" y)) args))
6063 args))
6065 (defun anything-c-shorten-home-path (files)
6066 "Replaces /home/user with ~."
6067 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6068 (getenv "HOME"))))
6069 (mapcar (lambda (file)
6070 (if (and (stringp file) (string-match home file))
6071 (cons (replace-match "~" nil nil file) file)
6072 file))
6073 files)))
6075 ;;; Functions
6076 (defun anything-c-mark-interactive-functions (functions)
6077 "Mark interactive functions (commands) with (i) after the function name."
6078 (let (list)
6079 (loop for function in functions
6080 do (push (cons (concat function
6081 (when (commandp (intern-soft function)) " (i)"))
6082 function)
6083 list)
6084 finally (return (nreverse list)))))
6086 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6087 (defvar anything-c-adaptive-done nil
6088 "nil if history information is not yet stored for the current
6089 selection.")
6091 (defvar anything-c-adaptive-history nil
6092 "Contains the stored history information.
6093 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6095 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
6096 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6097 when anything is started."
6098 (setq anything-c-adaptive-done nil))
6100 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
6101 "Advise `anything-exit-minibuffer' to store history information
6102 when a candidate is selected with RET."
6103 (anything-c-adaptive-store-selection))
6105 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
6106 "Advise `anything-select-action' to store history information
6107 when the user goes to the action list with TAB."
6108 (anything-c-adaptive-store-selection))
6110 (defun anything-c-source-use-adaptative-p (&optional source-name)
6111 "Return current source only if it use adaptative history, nil otherwise."
6112 (let* ((source (or source-name (anything-get-current-source)))
6113 (adapt-source (or (assoc-default 'filtered-candidate-transformer
6114 (assoc (assoc-default 'type source)
6115 anything-type-attributes))
6116 (assoc-default 'candidate-transformer
6117 (assoc (assoc-default 'type source)
6118 anything-type-attributes))
6119 (assoc-default 'filtered-candidate-transformer source)
6120 (assoc-default 'candidate-transformer source))))
6121 (if (listp adapt-source)
6122 (when (member 'anything-c-adaptive-sort adapt-source) source)
6123 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
6125 (defun anything-c-adaptive-store-selection ()
6126 "Store history information for the selected candidate."
6127 (unless anything-c-adaptive-done
6128 (setq anything-c-adaptive-done t)
6129 (let ((source (anything-c-source-use-adaptative-p)))
6130 (when source
6131 (let* ((source-name (or (assoc-default 'type source)
6132 (assoc-default 'name source)))
6133 (source-info (or (assoc source-name anything-c-adaptive-history)
6134 (progn
6135 (push (list source-name) anything-c-adaptive-history)
6136 (car anything-c-adaptive-history))))
6137 (selection (anything-get-selection))
6138 (selection-info (progn
6139 (setcdr source-info
6140 (cons
6141 (let ((found (assoc selection (cdr source-info))))
6142 (if (not found)
6143 ;; new entry
6144 (list selection)
6146 ;; move entry to the beginning of the
6147 ;; list, so that it doesn't get
6148 ;; trimmed when the history is
6149 ;; truncated
6150 (setcdr source-info
6151 (delete found (cdr source-info)))
6152 found))
6153 (cdr source-info)))
6154 (cadr source-info)))
6155 (pattern-info (progn
6156 (setcdr selection-info
6157 (cons
6158 (let ((found (assoc anything-pattern (cdr selection-info))))
6159 (if (not found)
6160 ;; new entry
6161 (cons anything-pattern 0)
6163 ;; move entry to the beginning of the
6164 ;; list, so if two patterns used the
6165 ;; same number of times then the one
6166 ;; used last appears first in the list
6167 (setcdr selection-info
6168 (delete found (cdr selection-info)))
6169 found))
6170 (cdr selection-info)))
6171 (cadr selection-info))))
6173 ;; increase usage count
6174 (setcdr pattern-info (1+ (cdr pattern-info)))
6176 ;; truncate history if needed
6177 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
6178 (setcdr selection-info
6179 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
6181 (if (file-readable-p anything-c-adaptive-history-file)
6182 (load-file anything-c-adaptive-history-file))
6183 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
6185 (defun anything-c-adaptive-save-history ()
6186 "Save history information to file given by `anything-c-adaptive-history-file'."
6187 (interactive)
6188 (with-temp-buffer
6189 (insert
6190 ";; -*- mode: emacs-lisp -*-\n"
6191 ";; History entries used for anything adaptive display.\n")
6192 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
6193 (current-buffer))
6194 (insert ?\n)
6195 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
6196 (unless (interactive-p) 'quiet))))
6198 (defun anything-c-adaptive-sort (candidates source)
6199 "Sort the CANDIDATES for SOURCE by usage frequency.
6200 This is a filtered candidate transformer you can use for the
6201 attribute `filtered-candidate-transformer' of a source in
6202 `anything-sources' or a type in `anything-type-attributes'."
6203 (let* ((source-name (or (assoc-default 'type source)
6204 (assoc-default 'name source)))
6205 (source-info (assoc source-name anything-c-adaptive-history)))
6206 (if (not source-info)
6207 ;; if there is no information stored for this source then do nothing
6208 candidates
6209 ;; else...
6210 (let ((usage
6211 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
6212 ;; pairs
6213 (mapcar (lambda (candidate-info)
6214 (let ((count 0))
6215 (dolist (pattern-info (cdr candidate-info))
6216 (if (not (equal (car pattern-info)
6217 anything-pattern))
6218 (incf count (cdr pattern-info))
6220 ;; if current pattern is equal to the previously
6221 ;; used one then this candidate has priority
6222 ;; (that's why its count is boosted by 10000) and
6223 ;; it only has to compete with other candidates
6224 ;; which were also selected with the same pattern
6225 (setq count (+ 10000 (cdr pattern-info)))
6226 (return)))
6227 (cons (car candidate-info) count)))
6228 (cdr source-info)))
6229 sorted)
6231 ;; sort the list in descending order, so candidates with highest
6232 ;; priorty come first
6233 (setq usage (sort usage (lambda (first second)
6234 (> (cdr first) (cdr second)))))
6236 ;; put those candidates first which have the highest usage count
6237 (dolist (info usage)
6238 (when (member* (car info) candidates
6239 :test 'anything-c-adaptive-compare)
6240 (push (car info) sorted)
6241 (setq candidates (remove* (car info) candidates
6242 :test 'anything-c-adaptive-compare))))
6244 ;; and append the rest
6245 (append (reverse sorted) candidates nil)))))
6247 (defun anything-c-adaptive-compare (x y)
6248 "Compare candidates X and Y taking into account that the
6249 candidate can be in (DISPLAY . REAL) format."
6250 (equal (if (listp x)
6251 (cdr x)
6253 (if (listp y)
6254 (cdr y)
6255 y)))
6257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6258 (defvar anything-outline-goto-near-line-flag t)
6259 (defvar anything-outline-using nil)
6260 (defun anything-after-update-hook--outline ()
6261 (if (and (eq anything-outline-using t)
6262 (eq anything-outline-goto-near-line-flag t))
6263 (anything-outline-goto-near-line)))
6264 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
6266 (defun anything-outline-goto-near-line ()
6267 (with-anything-window
6268 ;; TODO need consideration whether to update position by every input.
6269 (when t ; (equal anything-pattern "")
6270 (anything-goto-line 2)
6271 (let ((lineno (with-current-buffer anything-current-buffer
6272 (line-number-at-pos (car anything-current-position)))))
6273 (block exit
6274 (while (<= (progn (skip-chars-forward " ")
6275 (or (number-at-point) lineno))
6276 lineno)
6277 (forward-line 1)
6278 (when (eobp)
6279 (forward-line -1)
6280 (return-from exit))))
6281 (forward-line -1)
6282 (and (bobp) (forward-line 1))
6283 (and (anything-pos-header-line-p) (forward-line -2))
6284 (anything-mark-current-line)))))
6286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6287 ;; Plug-in: info-index
6288 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
6289 (let (result)
6290 (unless (anything-candidate-buffer)
6291 (save-window-excursion
6292 (info file)
6293 (let (Info-history
6294 (tobuf (anything-candidate-buffer 'global))
6295 (infobuf (current-buffer))
6296 s e)
6297 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
6298 (Info-goto-node node)
6299 (goto-char (point-min))
6300 (while (search-forward "\n* " nil t)
6301 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
6302 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
6303 (setq s (point-at-bol)
6304 e (point-at-eol))
6305 (with-current-buffer tobuf
6306 (insert-buffer-substring infobuf s e)
6307 (insert "\n"))))))))))
6309 (defun anything-c-info-goto (node-line)
6310 (Info-goto-node (car node-line))
6311 (anything-goto-line (cdr node-line)))
6313 (defun anything-c-info-display-to-real (line)
6314 (and (string-match
6315 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
6316 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
6317 (string-to-number (or (match-string 3 line) "1")))))
6319 (defun anything-c-make-info-source (file)
6320 `((name . ,(concat "Info Index: " file))
6321 (info-file . ,file)
6322 (init . anything-c-info-init)
6323 (display-to-real . anything-c-info-display-to-real)
6324 (get-line . buffer-substring)
6325 (candidates-in-buffer)
6326 (action ("Goto node" . anything-c-info-goto))))
6328 (defun anything-compile-source--info-index (source)
6329 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
6330 (anything-c-make-info-source it)
6331 source))
6332 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
6334 (anything-document-attribute 'info-index "info-index plugin"
6335 "Create a source of info index very easily.
6337 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
6339 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
6340 "Index nodes of info file.
6342 If it is omitted, `Info-index-nodes' is used to collect index nodes.
6343 Some info files are missing index specification.
6345 ex. See `anything-c-source-info-screen'.")
6347 ;; Plug-in: candidates-file
6348 (defun anything-compile-source--candidates-file (source)
6349 (if (assoc-default 'candidates-file source)
6350 `((init anything-p-candidats-file-init
6351 ,@(let ((orig-init (assoc-default 'init source)))
6352 (cond ((null orig-init) nil)
6353 ((functionp orig-init) (list orig-init))
6354 (t orig-init))))
6355 (candidates-in-buffer)
6356 ,@source)
6357 source))
6358 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
6360 (defun anything-p-candidats-file-init ()
6361 (destructuring-bind (file &optional updating)
6362 (anything-mklist (anything-attr 'candidates-file))
6363 (setq file (anything-interpret-value file))
6364 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
6365 (when updating
6366 (buffer-disable-undo)
6367 (font-lock-mode -1)
6368 (auto-revert-mode 1)))))
6370 (anything-document-attribute 'candidates-file "candidates-file plugin"
6371 "Use a file as the candidates buffer.
6373 1st argument is a filename, string or function name or variable name.
6374 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
6376 ;; Plug-in: headline
6377 (defun anything-compile-source--anything-headline (source)
6378 (if (assoc-default 'headline source)
6379 (append '((init . anything-headline-init)
6380 (get-line . buffer-substring)
6381 (type . line))
6382 source
6383 '((candidates-in-buffer)
6384 (persistent-help . "Show this line")))
6385 source))
6386 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
6388 (defun anything-headline-init ()
6389 (when (and (anything-current-buffer-is-modified)
6390 (with-current-buffer anything-current-buffer
6391 (eval (or (anything-attr 'condition) t))))
6392 (anything-headline-make-candidate-buffer
6393 (anything-interpret-value (anything-attr 'headline))
6394 (anything-interpret-value (anything-attr 'subexp)))))
6396 (anything-document-attribute 'headline "Headline plug-in"
6397 "Regexp string for anything-headline to scan.")
6398 (anything-document-attribute 'condition "Headline plug-in"
6399 "A sexp representing the condition to use anything-headline.")
6400 (anything-document-attribute 'subexp "Headline plug-in"
6401 "Display (match-string-no-properties subexp).")
6404 (defun anything-headline-get-candidates (regexp subexp)
6405 (with-current-buffer anything-current-buffer
6406 (save-excursion
6407 (goto-char (point-min))
6408 (if (functionp regexp) (setq regexp (funcall regexp)))
6409 (let (hierarchy curhead)
6410 (flet ((matched ()
6411 (if (numberp subexp)
6412 (cons (match-string-no-properties subexp) (match-beginning subexp))
6413 (cons (buffer-substring (point-at-bol) (point-at-eol))
6414 (point-at-bol))))
6415 (hierarchies (headlines)
6416 (1+ (loop for (_ . hierarchy) in headlines
6417 maximize hierarchy)))
6418 (vector-0-n (v n)
6419 (loop for i from 0 to hierarchy
6420 collecting (aref curhead i)))
6421 (arrange (headlines)
6422 (unless (null headlines) ; FIX headlines empty bug!
6423 (loop with curhead = (make-vector (hierarchies headlines) "")
6424 for ((str . pt) . hierarchy) in headlines
6425 do (aset curhead hierarchy str)
6426 collecting
6427 (cons
6428 (format "H%d:%s" (1+ hierarchy)
6429 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
6430 pt)))))
6431 (if (listp regexp)
6432 (arrange
6433 (sort
6434 (loop for re in regexp
6435 for hierarchy from 0
6436 do (goto-char (point-min))
6437 appending
6438 (loop
6439 while (re-search-forward re nil t)
6440 collect (cons (matched) hierarchy)))
6441 (lambda (a b) (> (cdar b) (cdar a)))))
6442 (loop while (re-search-forward regexp nil t)
6443 collect (matched))))))))
6446 (defun anything-headline-make-candidate-buffer (regexp subexp)
6447 (with-current-buffer (anything-candidate-buffer 'local)
6448 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
6449 do (insert
6450 (format "%5d:%s\n"
6451 (with-current-buffer anything-current-buffer
6452 (line-number-at-pos pos))
6453 content)))))
6455 (defun anything-headline-goto-position (pos recenter)
6456 (goto-char pos)
6457 (unless recenter
6458 (set-window-start (get-buffer-window anything-current-buffer) (point))))
6460 (defun anything-revert-buffer (candidate)
6461 (with-current-buffer candidate
6462 (when (buffer-modified-p)
6463 (revert-buffer t t))))
6465 (defun anything-revert-marked-buffers (candidate)
6466 (dolist (i (anything-marked-candidates))
6467 (anything-revert-buffer i)))
6469 (defun anything-kill-marked-buffers (candidate)
6470 (dolist (i (anything-marked-candidates))
6471 (kill-buffer i)))
6473 ;; Plug-in: persistent-help
6474 (defun anything-compile-source--persistent-help (source)
6475 (append source '((header-line . anything-persistent-help-string))))
6476 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
6478 (defun anything-persistent-help-string ()
6479 (substitute-command-keys
6480 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
6481 (or (anything-interpret-value (anything-attr 'persistent-help))
6482 (anything-aif (or (assoc-default 'persistent-action
6483 (anything-get-current-source))
6484 (assoc-default 'action
6485 (anything-get-current-source)))
6486 (cond ((symbolp it) (symbol-name it))
6487 ((listp it) (or (ignore-errors (caar it)) ""))))
6489 " (keeping session)")))
6491 (anything-document-attribute 'persistent-help "persistent-help plug-in"
6492 "A string to explain persistent-action of this source.
6493 It also accepts a function or a variable name.")
6495 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
6497 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6499 (defun anything-c-find-file-or-marked (candidate)
6500 "Open file CANDIDATE or open anything marked files in background."
6501 (let ((marked (anything-marked-candidates)))
6502 (if (> (length marked) 1)
6503 (dolist (i marked) (find-file-noselect i))
6504 (find-file-at-point candidate))))
6506 ;; FIXME there is a bug in dired that confuse all dired commands
6507 ;; when using this feature, so i suspend it until bug is fixed in emacs.
6509 ;; (defun anything-c-create-dired-on-marked (candidate)
6510 ;; "Create a new dired buffer with only marked candidates."
6511 ;; (let ((marked (anything-marked-candidates))
6512 ;; (buffer-name (read-string "New Dired Buffer: ")))
6513 ;; (dired (cons buffer-name marked))))
6515 (defun anything-delete-marked-files (ignore)
6516 (let* ((files (anything-marked-candidates))
6517 (len (length files)))
6518 (if (not (y-or-n-p
6519 (format "Delete *%s File(s):\n%s"
6521 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
6522 (message "(No deletions performed)")
6523 (dolist (i files)
6524 (set-text-properties 0 (length i) nil i)
6525 (anything-c-delete-file i))
6526 (message "%s File(s) deleted" len))))
6528 (defun anything-ediff-marked-buffers (candidate &optional merge)
6529 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
6530 With optional arg `merge' call `ediff-merge-buffers'."
6531 (let ((lg-lst (length (anything-marked-candidates)))
6532 buf1 buf2)
6533 (case lg-lst
6535 (error "Error:You have to mark at least 1 buffer"))
6537 (setq buf1 anything-current-buffer
6538 buf2 (first (anything-marked-candidates))))
6540 (setq buf1 (first (anything-marked-candidates))
6541 buf2 (second (anything-marked-candidates))))
6543 (error "Error:To much buffers marked!")))
6544 (if merge
6545 (ediff-merge-buffers buf1 buf2)
6546 (ediff-buffers buf1 buf2))))
6548 (defun anything-bookmark-get-bookmark-from-name (bmk)
6549 "Return bookmark name even if it is a bookmark with annotation.
6550 e.g prepended with *.
6551 Return nil if bmk is not a valid bookmark."
6552 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
6553 (if (assoc bookmark bookmark-alist)
6554 bookmark
6555 (when (assoc bmk bookmark-alist)
6556 bmk))))
6558 (defun anything-delete-marked-bookmarks (elm)
6559 "Delete this bookmark or all marked bookmarks."
6560 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
6561 (anything-aif (anything-marked-candidates)
6562 (dolist (i it)
6563 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
6564 (bookmark-delete bmk 'batch)))
6565 (bookmark-delete bookmark 'batch))))
6567 (defun anything-require-or-error (feature function)
6568 (or (require feature nil t)
6569 (error "Need %s to use `%s'." feature function)))
6571 (defun anything-find-buffer-on-elscreen (candidate)
6572 "Open buffer in new screen, if marked buffers open all in elscreens."
6573 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
6574 (anything-aif (anything-marked-candidates)
6575 (dolist (i it)
6576 (let ((target-screen (elscreen-find-screen-by-buffer
6577 (get-buffer i) 'create)))
6578 (elscreen-goto target-screen)))
6579 (let ((target-screen (elscreen-find-screen-by-buffer
6580 (get-buffer candidate) 'create)))
6581 (elscreen-goto target-screen))))
6583 (defun anything-elscreen-find-file (file)
6584 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
6585 (elscreen-find-file file))
6587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6589 ;;;; Type Attributes
6590 (define-anything-type-attribute 'buffer
6591 `((action
6592 ,@(if pop-up-frames
6593 '(("Switch to buffer other window" . switch-to-buffer-other-window)
6594 ("Switch to buffer" . switch-to-buffer))
6595 '(("Switch to buffer" . switch-to-buffer)
6596 ("Switch to buffer other window" . switch-to-buffer-other-window)
6597 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
6598 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
6599 ("Display buffer" . display-buffer)
6600 ("Revert buffer" . anything-revert-buffer)
6601 ("Revert Marked buffers" . anything-revert-marked-buffers)
6602 ("Kill buffer" . kill-buffer)
6603 ("Kill Marked buffers" . anything-kill-marked-buffers)
6604 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
6605 ("Ediff Merge marked buffers" . (lambda (candidate)
6606 (anything-ediff-marked-buffers candidate t))))
6607 (persistent-help . "Show this buffer")
6608 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
6609 "Buffer or buffer name.")
6611 (define-anything-type-attribute 'file
6612 `((action
6613 ,@(if pop-up-frames
6614 '(("Find file other window" . find-file-other-window)
6615 ("Find file(s)" . anything-find-many-files)
6616 ("Find file as root" . anything-find-file-as-root))
6617 '(("Find file" . anything-find-many-files)
6618 ("Find file as root" . anything-find-file-as-root)
6619 ("Find file other window" . find-file-other-window)
6620 ("Find file other frame" . find-file-other-frame)))
6621 ("Open dired in file's directory" . anything-c-open-dired)
6622 ("Delete file(s)" . anything-delete-marked-files)
6623 ("Open file externally" . anything-c-open-file-externally)
6624 ("Open file with default tool" . anything-c-open-file-with-default-tool))
6625 (persistent-help . "Show this file")
6626 (action-transformer anything-c-transform-file-load-el
6627 anything-c-transform-file-browse-url)
6628 (candidate-transformer anything-c-w32-pathname-transformer
6629 anything-c-skip-current-file
6630 anything-c-skip-boring-files
6631 anything-c-shorten-home-path))
6632 "File name.")
6634 (define-anything-type-attribute 'command
6635 `((action ("Call interactively" . anything-c-call-interactively)
6636 ("Describe command" . anything-c-describe-function)
6637 ("Add command to kill ring" . anything-c-kill-new)
6638 ("Go to command's definition" . anything-c-find-function))
6639 ;; Sort commands according to their usage count.
6640 (filtered-candidate-transformer . anything-c-adaptive-sort)
6641 (persistent-action . anything-c-describe-function))
6642 "Command. (string or symbol)")
6644 (define-anything-type-attribute 'function
6645 '((action ("Describe function" . anything-c-describe-function)
6646 ("Add function to kill ring" . anything-c-kill-new)
6647 ("Go to function's definition" . anything-c-find-function))
6648 (action-transformer anything-c-transform-function-call-interactively)
6649 (candidate-transformer anything-c-mark-interactive-functions))
6650 "Function. (string or symbol)")
6652 (define-anything-type-attribute 'variable
6653 '((action ("Describe variable" . anything-c-describe-variable)
6654 ("Add variable to kill ring" . anything-c-kill-new)
6655 ("Go to variable's definition" . anything-c-find-variable)
6656 ("Set variable" . anything-c-set-variable)))
6657 "Variable.")
6659 (define-anything-type-attribute 'sexp
6660 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
6661 ("Add s-expression to kill ring" . kill-new))
6662 (action-transformer anything-c-transform-sexp-eval-command-sexp))
6663 "String representing S-Expressions.")
6665 (define-anything-type-attribute 'bookmark
6666 `((action
6667 ("Jump to bookmark" . (lambda (candidate)
6668 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate))
6669 (current-prefix-arg anything-current-prefix-arg))
6670 (bookmark-jump bookmark))
6671 (anything-update)))
6672 ("Jump to BM other window" . (lambda (candidate)
6673 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6674 (bookmark-jump-other-window bookmark))
6675 (anything-update)))
6676 ("Bookmark edit annotation" . (lambda (candidate)
6677 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6678 (bookmark-edit-annotation bookmark))))
6679 ("Bookmark show annotation" . (lambda (candidate)
6680 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6681 (bookmark-show-annotation bookmark))))
6682 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
6683 ,@(when (fboundp 'bmkext-edit-bookmark)
6684 '(("Edit Bookmark" . (lambda (candidate)
6685 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6686 (bmkext-edit-bookmark bookmark))))))
6687 ("Rename bookmark" . (lambda (candidate)
6688 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6689 (bookmark-rename bookmark))))
6690 ("Relocate bookmark" . (lambda (candidate)
6691 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6692 (bookmark-relocate bookmark))))))
6693 "Bookmark name.")
6695 (define-anything-type-attribute 'line
6696 '((display-to-real . anything-c-display-to-real-line)
6697 (action ("Go to Line" . anything-c-action-line-goto)))
6698 "LINENO:CONTENT string, eg. \" 16:foo\".
6700 Optional `target-file' attribute is a name of target file.
6702 Optional `before-jump-hook' attribute is a function with no
6703 arguments which is called before jumping to position.
6705 Optional `after-jump-hook' attribute is a function with no
6706 arguments which is called after jumping to position.
6708 If `adjust' attribute is specified, searches the line whose
6709 content is CONTENT near the LINENO.
6711 If `recenter' attribute is specified, the line is displayed at
6712 the center of window, otherwise at the top of window.
6715 (define-anything-type-attribute 'file-line
6716 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
6717 (multiline)
6718 (action ("Go to" . anything-c-action-file-line-goto)))
6719 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
6721 Optional `default-directory' attribute is a default-directory
6722 FILENAME is interpreted.
6724 Optional `before-jump-hook' attribute is a function with no
6725 arguments which is called before jumping to position.
6727 Optional `after-jump-hook' attribute is a function with no
6728 arguments which is called after jumping to position.
6730 If `adjust' attribute is specified, searches the line whose
6731 content is CONTENT near the LINENO.
6733 If `recenter' attribute is specified, the line is displayed at
6734 the center of window, otherwise at the top of window.
6737 (define-anything-type-attribute 'timer
6738 '((real-to-display . anything-c-timer-real-to-display)
6739 (action ("Cancel Timer" . cancel-timer)
6740 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
6741 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
6742 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
6743 (persistent-help . "Describe Function"))
6744 "Timer.")
6746 ;;;; Default `anything-sources'
6747 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
6748 ;; tend to invoke M-x anything directly. So I offer default setting.
6749 (setq anything-sources
6750 '(anything-c-source-buffers+
6751 anything-c-source-recentf
6752 anything-c-source-files-in-current-dir+))
6754 ;;;; unit test
6755 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
6756 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6757 (dont-compile
6758 (when (fboundp 'expectations)
6759 (expectations
6760 (desc "candidates-file plug-in")
6761 (expect '(anything-p-candidats-file-init)
6762 (assoc-default 'init
6763 (car (anything-compile-sources
6764 '(((name . "test")
6765 (candidates-file . "test.txt")))
6766 '(anything-compile-source--candidates-file)))))
6767 (expect '(anything-p-candidats-file-init
6768 (lambda () 1))
6769 (assoc-default 'init
6770 (car (anything-compile-sources
6771 '(((name . "test")
6772 (candidates-file . "test.txt")
6773 (init . (lambda () 1))))
6774 '(anything-compile-source--candidates-file)))))
6775 (expect '(anything-p-candidats-file-init
6776 (lambda () 1))
6777 (assoc-default 'init
6778 (car (anything-compile-sources
6779 '(((name . "test")
6780 (candidates-file . "test.txt")
6781 (init (lambda () 1))))
6782 '(anything-compile-source--candidates-file)))))
6783 (desc "anything-c-source-buffers")
6784 (expect '(("Buffers" ("foo" "curbuf")))
6785 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
6786 (let ((anything-c-boring-buffer-regexp
6787 (rx (or
6788 (group bos " ")
6789 "*anything"
6790 ;; echo area
6791 " *Echo Area" " *Minibuf"))))
6792 (flet ((buffer-name (x) x))
6793 (anything-test-candidates 'anything-c-source-buffers))))
6794 (desc "anything-c-stringify")
6795 (expect "str1"
6796 (anything-c-stringify "str1"))
6797 (expect "str2"
6798 (anything-c-stringify 'str2))
6799 (desc "anything-c-symbolify")
6800 (expect 'sym1
6801 (anything-c-symbolify "sym1"))
6802 (expect 'sym2
6803 (anything-c-symbolify 'sym2)))))
6805 (provide 'anything-config)
6807 ;;; Local Variables:
6808 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
6809 ;;; End:
6811 ;; How to save (DO NOT REMOVE!!)
6812 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
6813 ;;; anything-config.el ends here
6815 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
6816 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
6817 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
6818 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
6819 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
6820 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
6821 ;;; LocalWords: dotimes Thierry online vname
6822 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
6823 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
6824 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
6825 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
6826 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
6827 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
6828 ;;; LocalWords: startpos noselect dont desc