anything-config.el (anything-get-firefox-user-init-dir): reformat
[anything-config.git] / anything-config.el
blob75778a6ae17b034c715d583e78e84ee1819c71f8
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
605 '(anything-c-source-ffap-line
606 anything-c-source-ffap-guesser
607 anything-c-source-buffers+
608 anything-c-source-recentf
609 anything-c-source-bookmarks
610 anything-c-source-file-cache
611 anything-c-source-files-in-current-dir+
612 anything-c-source-locate)
613 "Your prefered sources to find files."
614 :type 'list
615 :group 'anything-config)
617 (defcustom anything-create--actions-private nil
618 "User defined actions for `anything-create' / `anything-c-source-create'.
619 It is a list of (DISPLAY . FUNCTION) pairs like `action'
620 attribute of `anything-sources'.
622 It is prepended to predefined pairs."
623 :type 'list
624 :group 'anything-config)
626 (defcustom anything-allow-skipping-current-buffer t
627 "Show current buffer or not in anything buffer"
628 :type 'boolean
629 :group 'anything-config)
631 (defcustom anything-c-enable-eval-defun-hack t
632 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
633 This hack is invoked when pressing C-M-x in the form \
634 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
635 :type 'boolean
636 :group 'anything-config)
638 (defcustom anything-tramp-verbose 0
639 "*Just like `tramp-verbose' but specific to anything.
640 When set to 0 don't show tramp messages in anything.
641 If you want to have the default tramp messages set it to 3."
642 :type 'integer
643 :group 'anything-config)
645 (defcustom anything-raise-command nil
646 "*A shell command to jump to a window running specific program.
647 Stumpwm users could use:
648 \"stumpish eval \"\(stumpwm::%s\)\"\".
649 With others windows manager you could use:
650 \"wmctrl -xa %s\".
651 Though wmctrl work also with stumpwm."
652 :type 'string
653 :group 'anything-config)
655 (defun anything-set-anything-command-map-prefix-key (var key)
656 (when (boundp 'anything-command-map-prefix-key)
657 (global-unset-key (read-kbd-macro anything-command-map-prefix-key)))
658 (setq anything-command-map-prefix-key key)
659 (global-set-key (read-kbd-macro anything-command-map-prefix-key)
660 'anything-command-map))
662 (defcustom anything-command-map-prefix-key "<f5> a"
663 "*The prefix key for all `anything-command-map' commands.
665 !!WARNING!!
666 This default value is very likely to be changed,
667 because it is under discussion."
668 :type 'string
669 :set 'anything-set-anything-command-map-prefix-key
670 :group 'anything-config)
672 ;;;###autoload
673 (defun anything-configuration ()
674 "Customize `anything'."
675 (interactive)
676 (customize-group "anything-config"))
678 ;;; Anything-command-map
679 ;;;###autoload
680 (defvar anything-command-map)
681 (define-prefix-command 'anything-command-map)
683 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
684 (define-key anything-command-map (kbd "<SPC>") 'anything-execute-anything-command)
685 (define-key anything-command-map (kbd "e") 'anything-etags-maybe-at-point)
686 (define-key anything-command-map (kbd "l") 'anything-locate)
687 (define-key anything-command-map (kbd "s") 'anything-surfraw)
688 (define-key anything-command-map (kbd "r") 'anything-regexp)
689 (define-key anything-command-map (kbd "w") 'anything-w3m-bookmarks)
690 (define-key anything-command-map (kbd "x") 'anything-firefox-bookmarks)
691 (define-key anything-command-map (kbd "#") 'anything-emms)
692 (define-key anything-command-map (kbd "m") 'anything-man-woman)
693 (define-key anything-command-map (kbd "t") 'anything-top)
694 (define-key anything-command-map (kbd "i") 'anything-imenu)
695 (define-key anything-command-map (kbd "C-x r b") 'anything-c-pp-bookmarks)
696 (define-key anything-command-map (kbd "M-y") 'anything-show-kill-ring)
697 (define-key anything-command-map (kbd "C-c <SPC>") 'anything-all-mark-rings)
698 (define-key anything-command-map (kbd "C-x C-f") 'anything-find-files)
699 (define-key anything-command-map (kbd "f") 'anything-for-files)
700 (define-key anything-command-map (kbd "C-:") 'anything-eval-expression-with-eldoc)
701 (define-key anything-command-map (kbd "C-,") 'anything-calcul-expression)
702 (define-key anything-command-map (kbd "M-x") 'anything-M-x)
703 (define-key anything-command-map (kbd "C-x C-w") 'anything-write-file)
704 (define-key anything-command-map (kbd "C-x i") 'anything-insert-file)
705 (define-key anything-command-map (kbd "M-s o") 'anything-occur)
706 (define-key anything-command-map (kbd "c") 'anything-colors)
707 (define-key anything-command-map (kbd "F") 'anything-select-xfont)
708 (define-key anything-command-map (kbd "C-c f") 'anything-recentf)
709 (define-key anything-command-map (kbd "C-c g") 'anything-google-suggest)
710 (define-key anything-command-map (kbd "h i") 'anything-info-at-point)
711 (define-key anything-command-map (kbd "C-x C-b") 'anything-buffers+)
712 (define-key anything-command-map (kbd "C-x r i") 'anything-register)
713 (define-key anything-command-map (kbd "C-c C-x") 'anything-c-run-external-command)
715 ;;; Menu
716 (easy-menu-define nil global-map
717 "`anything' menu"
718 '("Anything"
719 ["All anything commands" anything-execute-anything-command t]
720 ["Find any Files/Buffers" anything-for-files t]
721 "----"
722 ("Files:"
723 ["Find files" anything-find-files t]
724 ["Recent Files" anything-recentf t]
725 ["Locate" anything-locate t]
726 ["Bookmarks" anything-c-pp-bookmarks t])
727 ("Buffers:"
728 ["Find buffers" anything-buffers+ t])
729 ("Commands:"
730 ["Emacs Commands" anything-M-x t]
731 ["Externals Commands" anything-c-run-external-command t])
732 ("Info:"
733 ["Info at point" anything-info-at-point t])
734 ("Tools:"
735 ["Occur" anything-occur t]
736 ["Browse Kill ring" anything-show-kill-ring t]
737 ["Browse register" anything-register t]
738 ["Mark Ring" anything-all-mark-rings t]
739 ["Colors & Faces" anything-colors t]
740 ["Show xfonts" anything-select-xfont t]
741 ["Imenu" anything-imenu t]
742 ["Google Suggest" anything-google-suggest t]
743 ["Eval expression" anything-eval-expression-with-eldoc t]
744 ["Calcul expression" anything-calcul-expression t]
745 ["Man pages" anything-man-woman t]
746 ["Top externals process" anything-top t])
747 "----"
748 ["Prefered Options" anything-configuration t]))
750 ;;; Documentation
751 ;; It is replaced by `anything-help'
752 (defun anything-c-describe-anything-bindings ()
753 "[OBSOLETE] Describe `anything' bindings."
754 (interactive)
755 (anything-run-after-quit
756 #'(lambda ()
757 (with-current-buffer (get-buffer-create "*Anything Help*")
758 (erase-buffer)
759 (insert
760 (substitute-command-keys
761 "The keys that are defined for `anything' are:
762 \\{anything-map}")))
763 (pop-to-buffer "*Anything Help*")
764 (goto-char (point-min)))))
766 ;; Use `describe-mode' key in `global-map'
767 ;; (dolist (k (where-is-internal 'describe-mode global-map))
768 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
770 ;;; Help message
771 (defun anything-c-list-preconfigured-anything ()
772 (loop with doc
773 with sym
774 for entry in (cdr (assoc
775 (file-truename (locate-library "anything-config"))
776 load-history))
777 if (and (consp entry)
778 (eq (car entry) 'defun)
779 (string-match "^Preconfigured.+$"
780 (setq doc (or (documentation (setq sym (cdr entry)))
781 ""))))
782 collect (cons sym (match-string 0 doc))))
784 (defun anything-c-format-preconfigured-anything ()
785 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x) (cdr x)))
786 (anything-c-list-preconfigured-anything)))
788 (setq anything-help-message
789 (lambda ()
790 (concat
791 "\\<anything-map>"
792 "`anything' is QuickSilver-like candidate-selection framework.
794 Narrow the list by typing some pattern,
795 Multiple patterns are allowed by splitting by space.
796 Select with natural Emacs operations, choose with RET.
798 If you have any problems, press C-c C-x C-b!!
799 Feel free to send bug reports. I'll fix them.
800 The steps are described in the beginning of anything.el file.
802 == Basic Operations ==
803 C-p, Up: Previous Line
804 C-n, Down : Next Line
805 M-v, PageUp : Previous Page
806 C-v, PageDown : Next Page
807 Enter : Execute first (default) action / Select
808 M-< : First Line
809 M-> : Last Line
810 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
811 M-PageDown, C-M-v : Next Page (other-window)
813 Tab, C-i : Show action list
814 Left : Previous Source
815 Right, C-o : Next Source
816 C-k : Delete pattern
817 C-z : Persistent Action (Execute action with anything session kept)
818 C-c C-x C-b: Send a bug report
820 == Shortcuts For 2nd/3rd Action ==
821 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
822 \\[anything-select-3rd-action] : Execute 3rd Action
824 == Visible Marks ==
825 Visible marks store candidate. Some actions uses marked candidates.
827 \\[anything-toggle-visible-mark] : Toggle Visible Mark
828 \\[anything-prev-visible-mark] : Previous Mark
829 \\[anything-next-visible-mark] : Next Mark
831 == Miscellaneous Commands ==
832 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
833 \\[anything-quit-and-find-file] : Drop into `find-file'
834 \\[anything-delete-current-selection] : Delete Selected Item (visually)
835 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
836 \\[anything-yank-selection] : Yank Selected Item Into Pattern
837 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
838 \\[anything-force-update] : Recalculate And Redisplay Candidates
840 == Global Commands ==
841 \\<global-map>\\[anything-resume] revives last `anything' session.
842 It is very useful, so you should bind any key.
844 Single source is executed by \\[anything-call-source].
846 == Preconfigured `anything' ==
847 Preconfigured `anything' is commands that uses `anything' interface.
848 You can use them without configuration.
851 (apply 'concat (anything-c-format-preconfigured-anything))
853 Enjoy!")))
855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
856 ;;;###autoload
857 (defun anything-mini ()
858 "Preconfigured `anything' lightweight version (buffer -> recentf)."
859 (interactive)
860 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf)
861 "*anything mini*"))
862 ;;;###autoload
863 (defun anything-for-files ()
864 "Preconfigured `anything' for opening files.
865 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
866 (interactive)
867 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
869 ;;;###autoload
870 (defun anything-recentf ()
871 "Preconfigured `anything' for `recentf'."
872 (interactive)
873 (anything-other-buffer 'anything-c-source-recentf "*anything recentf*"))
874 ;;;###autoload
875 (defun anything-info-at-point ()
876 "Preconfigured `anything' for searching info at point."
877 (interactive)
878 (anything '(anything-c-source-info-elisp
879 anything-c-source-info-cl
880 anything-c-source-info-pages)
881 (thing-at-point 'symbol) nil nil nil "*anything info*"))
883 ;;;###autoload
884 (defun anything-show-kill-ring ()
885 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
886 You may bind this command to M-y."
887 (interactive)
888 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
890 ;;;###autoload
891 (defun anything-minibuffer-history ()
892 "Preconfigured `anything' for `minibuffer-history'."
893 (interactive)
894 (let ((enable-recursive-minibuffers t))
895 (anything-other-buffer 'anything-c-source-minibuffer-history
896 "*anything minibuffer-history*")))
898 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
899 ;; minibuffer-local-filename-must-match-map.
900 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
901 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
902 (dolist (map (list minibuffer-local-filename-completion-map
903 minibuffer-local-completion-map
904 minibuffer-local-must-match-filename-map
905 minibuffer-local-filename-must-match-map
906 minibuffer-local-map
907 minibuffer-local-isearch-map
908 minibuffer-local-must-match-map
909 minibuffer-local-ns-map))
910 (define-key map "\C-r" 'anything-minibuffer-history))
912 ;;;###autoload
913 (defun anything-gentoo ()
914 "Preconfigured `anything' for gentoo linux."
915 (interactive)
916 (anything-other-buffer '(anything-c-source-gentoo
917 anything-c-source-use-flags)
918 "*anything gentoo*"))
920 ;;;###autoload
921 (defun anything-imenu ()
922 "Preconfigured `anything' for `imenu'."
923 (interactive)
924 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
926 ;;;###autoload
927 (defun anything-google-suggest ()
928 "Preconfigured `anything' for google search with google suggest."
929 (interactive)
930 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
932 ;;;###autoload
933 (defun anything-yahoo-suggest ()
934 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
935 (interactive)
936 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
938 ;;; Converted from anything-show-*-only
939 ;;;###autoload
940 (defun anything-for-buffers ()
941 "Preconfigured `anything' for buffer."
942 (interactive)
943 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
945 ;;;###autoload
946 (defun anything-buffers+ ()
947 "Enhanced preconfigured `anything' for buffer."
948 (interactive)
949 (anything-other-buffer 'anything-c-source-buffers+ "*anything buffers*"))
951 ;;;###autoload
952 (defun anything-bbdb ()
953 "Preconfigured `anything' for BBDB.
955 Needs BBDB.
957 http://bbdb.sourceforge.net/"
958 (interactive)
959 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
961 ;;;###autoload
962 (defun anything-locate ()
963 "Preconfigured `anything' for Locate.
964 Note you can add locate command after entering pattern.
965 See man locate for more infos."
966 (interactive)
967 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
969 ;;;###autoload
970 (defun anything-w3m-bookmarks ()
971 "Preconfigured `anything' for w3m bookmark.
973 Needs w3m and emacs-w3m.
975 http://w3m.sourceforge.net/
976 http://emacs-w3m.namazu.org/"
977 (interactive)
978 (anything-other-buffer 'anything-c-source-w3m-bookmarks
979 "*anything w3m bookmarks*"))
981 ;;;###autoload
982 (defun anything-firefox-bookmarks ()
983 "Preconfigured `anything' for firefox bookmark.
984 You will have to enable html bookmarks in firefox:
985 open about:config in firefox and double click on this line to enable value \
986 to true:
988 user_pref(\"browser.bookmarks.autoExportHTML\", false);
990 You should have now:
992 user_pref(\"browser.bookmarks.autoExportHTML\", true);
994 After closing firefox, you will be able to browse you bookmarks.
996 (interactive)
997 (anything-other-buffer 'anything-c-source-firefox-bookmarks
998 "*Anything Firefox*"))
1000 ;;;###autoload
1001 (defun anything-colors ()
1002 "Preconfigured `anything' for color."
1003 (interactive)
1004 (anything-other-buffer
1005 '(anything-c-source-colors anything-c-source-customize-face)
1006 "*anything colors*"))
1008 ;;;###autoload
1009 (defun anything-bookmarks ()
1010 "Preconfigured `anything' for bookmarks."
1011 (interactive)
1012 (anything-other-buffer 'anything-c-source-bookmarks "*anything bookmarks*"))
1014 ;;;###autoload
1015 (defun anything-c-pp-bookmarks ()
1016 "Preconfigured `anything' for bookmarks (pretty-printed)."
1017 (interactive)
1018 (anything-other-buffer '(anything-c-source-bookmarks-local
1019 anything-c-source-bookmarks-su
1020 anything-c-source-bookmarks-ssh)
1021 "*anything pp bookmarks*"))
1023 ;;;###autoload
1024 (defun anything-register ()
1025 "Preconfigured `anything' for Emacs registers."
1026 (interactive)
1027 (anything-other-buffer 'anything-c-source-register "*anything register*"))
1029 ;;;###autoload
1030 (defun anything-bm-list ()
1031 "Preconfigured `anything' for visible bookmarks.
1033 Needs bm.el
1035 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1036 (interactive)
1037 (let ((anything-outline-using t))
1038 (anything-other-buffer 'anything-c-source-bm "*anything bm list*")))
1040 ;;;###autoload
1041 (defun anything-timers ()
1042 "Preconfigured `anything' for timers."
1043 (interactive)
1044 (anything-other-buffer '(anything-c-source-absolute-time-timers
1045 anything-c-source-idle-time-timers)
1046 "*anything timers*"))
1048 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1049 ;;; kill buffers
1050 ;;;###autoload
1051 (defun anything-kill-buffers ()
1052 "Preconfigured `anything' to kill buffer you selected."
1053 (interactive)
1054 (anything
1055 '(((name . "Kill Buffers")
1056 (candidates . anything-c-buffer-list)
1057 (action
1058 ("Kill Buffer" . (lambda (candidate)
1059 (kill-buffer candidate)
1060 (anything-kill-buffers)
1061 )))))
1062 nil nil))
1064 ;;; Regexp
1065 ;;;###autoload
1066 (defun anything-query-replace-regexp (&rest args)
1067 "Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually."
1068 (interactive
1069 (let ((common
1070 (anything-c-regexp-base
1071 "Query Replace Regexp: "
1072 '((name . "Lines matching Regexp")
1073 (mode-line . "Set replace start line and type RET.")
1074 (action . anything-c-query-replace-args)))))
1075 (if (not common)
1076 (keyboard-quit))
1077 (list (car common) (cadr common) (caddr common)
1078 ;; These are done separately here
1079 ;; so that command-history will record these expressions
1080 ;; rather than the values they had this time.
1082 ;; This idea is borrowed from original `query-replace-regexp'.
1083 (if (and transient-mark-mode mark-active)
1084 (region-beginning))
1085 (if (and transient-mark-mode mark-active)
1086 (region-end)))))
1087 (apply 'query-replace-regexp args))
1089 ;;;###autoload
1090 (defun anything-regexp ()
1091 "Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement."
1092 (interactive)
1093 (anything-c-regexp-base
1094 "Regexp: "
1095 '((name . "Regexp Builder")
1096 (mode-line . "Press TAB to select action.")
1097 (action
1098 ("Kill Regexp as sexp" .
1099 (lambda (x) (anything-c-regexp-kill-new
1100 (prin1-to-string (funcall (anything-attr 'regexp))))))
1101 ("Query Replace Regexp" .
1102 (lambda (x) (apply 'query-replace-regexp
1103 (anything-c-query-replace-args (point)))))
1104 ("Kill Regexp" .
1105 (lambda (x) (anything-c-regexp-kill-new
1106 (funcall (anything-attr 'regexp)))))))))
1108 (defun anything-c-query-replace-args (start-point)
1109 ;; create arguments of `query-replace-regexp'.
1110 (let ((region-only (and transient-mark-mode mark-active))
1111 (regexp (funcall (anything-attr 'regexp))))
1112 (list
1113 regexp
1114 (query-replace-read-to regexp
1115 (format "Query replace regexp %s%s%s with: "
1116 (if region-only "in region " "")
1117 regexp
1118 (if current-prefix-arg "(word) " ""))
1120 current-prefix-arg)))
1122 (defun anything-c-regexp-get-line (s e)
1123 (propertize
1124 (apply 'concat
1125 ;; Line contents
1126 (format "%5d: %s" (line-number-at-pos s) (buffer-substring s e))
1127 ;; subexps
1128 (loop for i from 0 to (1- (/ (length (match-data)) 2))
1129 collect (format "\n \\%s = %s"
1130 (if (zerop i) "&" i)
1131 (match-string i))))
1132 ;; match beginning
1133 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1134 ;; It is implementation problem of candidates-in-buffer.
1135 'anything-realvalue
1136 (1- s)))
1138 ;; Shut up byte compiler
1139 (defun anything-goto-line (numline)
1140 "Replacement of `goto-line'."
1141 (goto-char (point-min))
1142 (forward-line (1- numline)))
1144 (defun anything-c-regexp-persistent-action (pt)
1145 (goto-char pt)
1146 (anything-persistent-highlight-point))
1148 (defun anything-c-regexp-base (prompt attributes)
1149 (save-restriction
1150 (let ((anything-compile-source-functions
1151 ;; rule out anything-match-plugin because the input is one regexp.
1152 (delq 'anything-compile-source--match-plugin
1153 (copy-sequence anything-compile-source-functions)))
1154 (base-attributes
1155 '((init . (lambda () (anything-candidate-buffer anything-current-buffer)))
1156 (candidates-in-buffer)
1157 (get-line . anything-c-regexp-get-line)
1158 (persistent-action . anything-c-regexp-persistent-action)
1159 (persistent-help . "Show this line")
1160 (multiline)
1161 (delayed))))
1162 (if (and transient-mark-mode mark-active)
1163 (narrow-to-region (region-beginning) (region-end)))
1164 (anything
1165 (list
1166 (append
1167 attributes
1168 '((regexp . (lambda () anything-pattern)))
1169 base-attributes)
1170 ;; sexp form regexp
1171 (append
1172 `((name . ,(concat (assoc-default 'name attributes) " (sexp)")))
1173 attributes
1174 '((candidates-in-buffer
1175 . (lambda () (let ((anything-pattern (eval (read anything-pattern))))
1176 (anything-candidates-in-buffer))))
1177 (regexp . (lambda () (eval (read anything-pattern)))))
1178 base-attributes))
1179 nil prompt nil nil "*anything regexp*"))))
1181 ;; (anything-c-regexp-base "Regexp: " '((name . "test")))
1182 ;; (anything-c-regexp-base "Regexp: " '((name . "test") (candidates-in-buffer . (lambda () (let ((anything-pattern (eval (read anything-pattern)))) (anything-candidates-in-buffer))))))
1184 (defun anything-c-regexp-kill-new (input)
1185 (kill-new input)
1186 (message "Killed: %s" input))
1188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1190 (defun anything-insert-buffer-name ()
1191 "Insert buffer name."
1192 (interactive)
1193 (anything-insert-string
1194 (with-current-buffer anything-current-buffer
1195 (if buffer-file-name (file-name-nondirectory buffer-file-name)
1196 (buffer-name)))))
1198 (defun anything-insert-symbol ()
1199 "Insert current symbol."
1200 (interactive)
1201 (anything-insert-string
1202 (with-current-buffer anything-current-buffer
1203 (save-excursion
1204 (buffer-substring (beginning-of-thing 'symbol)
1205 (end-of-thing 'symbol))))))
1207 (defun anything-insert-selection ()
1208 "Insert current selection."
1209 (interactive)
1210 (anything-insert-string
1211 (with-current-buffer anything-current-buffer
1212 (anything-get-selection))))
1214 (defun anything-show-buffer-only ()
1215 "[OBSOLETE] Only show sources about buffer.
1216 Use `anything-for-buffers' instead."
1217 (interactive)
1218 (anything-set-source-filter '("Buffers")))
1220 (defun anything-show-bbdb-only ()
1221 "[OBSOLETE] Only show sources about BBDB.
1222 Use `anything-bbdb' instead."
1223 (interactive)
1224 (anything-set-source-filter '("BBDB")))
1226 (defun anything-show-locate-only ()
1227 "[OBSOLETE] Only show sources about Locate.
1228 Use `anything-locate' instead."
1229 (interactive)
1230 (anything-set-source-filter '("Locate")))
1232 (defun anything-show-info-only ()
1233 "[OBSOLETE] Only show sources about Info.
1234 Use `anything-info-at-point' instead."
1235 (interactive)
1236 (anything-set-source-filter '("Info Pages"
1237 "Info Elisp"
1238 "Info Common-Lisp")))
1240 (defun anything-show-imenu-only ()
1241 "[OBSOLETE] Only show sources about Imenu.
1242 Use `anything-imenu' instead."
1243 (interactive)
1244 (anything-set-source-filter '("Imenu")))
1246 (defun anything-show-files-only ()
1247 "[OBSOLETE] Only show sources about File.
1248 Use `anything-for-files' instead."
1249 (interactive)
1250 (anything-set-source-filter '("File Name History"
1251 "Files from Current Directory"
1252 "Recentf")))
1254 (defun anything-show-w3m-bookmarks-only ()
1255 "[OBSOLETE] Only show source about w3m bookmark.
1256 Use `anything-w3m-bookmarks' instead."
1257 (interactive)
1258 (anything-set-source-filter '("W3m Bookmarks")))
1260 (defun anything-show-colors-only ()
1261 "[OBSOLETE] Only show source about color.
1262 Use `anything-colors' instead."
1263 (interactive)
1264 (anything-set-source-filter '("Colors"
1265 "Customize Faces")))
1267 (defun anything-show-kill-ring-only ()
1268 "[OBSOLETE] Only show source about kill ring.
1269 Use `anything-show-kill-ring' instead."
1270 (interactive)
1271 (anything-set-source-filter '("Kill Ring")))
1273 (defun anything-show-this-source-only ()
1274 "Only show this source."
1275 (interactive)
1276 (setq anything-candidate-number-limit 9999)
1277 (anything-set-source-filter
1278 (list (assoc-default 'name (anything-get-current-source)))))
1280 (defun anything-test-sources ()
1281 "List all anything sources for test.
1282 The output is sexps which are evaluated by \\[eval-last-sexp]."
1283 (interactive)
1284 (with-output-to-temp-buffer "*Anything Test Sources*"
1285 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
1286 (apropos-internal "^anything-c-source" #'boundp))
1287 (pop-to-buffer standard-output)))
1289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1290 ;;; For compatibility
1291 (unless (fboundp 'region-active-p)
1292 (defun region-active-p ()
1293 "Return t if Transient Mark mode is enabled and the mark is active.
1295 Most commands that act on the region if it is active and
1296 Transient Mark mode is enabled, and on the text near point
1297 otherwise, should use `use-region-p' instead. That function
1298 checks the value of `use-empty-active-region' as well."
1299 (and transient-mark-mode mark-active)))
1301 (defun anything-nest (&rest same-as-anything)
1302 "Nested `anything'. If you use `anything' within `anything', use it."
1303 (with-selected-window (anything-window)
1304 (let (anything-current-position
1305 anything-current-buffer
1306 (orig-anything-buffer anything-buffer)
1307 anything-pattern
1308 anything-buffer
1309 anything-sources
1310 anything-compiled-sources
1311 anything-buffer-chars-modified-tick
1312 (anything-samewindow t)
1313 (enable-recursive-minibuffers t))
1314 (unwind-protect
1315 (apply #'anything same-as-anything)
1316 (anything-initialize-overlays orig-anything-buffer)
1317 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
1319 (defun anything-displaying-source-names ()
1320 "Display sources name."
1321 (with-current-buffer anything-buffer
1322 (goto-char (point-min))
1323 (loop with pos
1324 while (setq pos (next-single-property-change (point) 'anything-header))
1325 do (goto-char pos)
1326 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1327 do (forward-line 1))))
1329 (defun anything-select-source ()
1330 "Select source."
1331 (interactive)
1332 (let ((default (assoc-default 'name (anything-get-current-source)))
1333 (source-names (anything-displaying-source-names))
1334 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
1335 (anything-get-sources))))
1336 (setq anything-candidate-number-limit 9999)
1337 (anything-aif
1338 (let (anything-source-filter)
1339 (anything-nest '(((name . "Anything Source")
1340 (candidates . source-names)
1341 (action . identity))
1342 ((name . "Anything Source (ALL)")
1343 (candidates . all-source-names)
1344 (action . identity)))
1345 nil "Source: " nil
1346 default "*anything select source*"))
1347 (anything-set-source-filter (list it))
1348 (anything-set-source-filter nil))))
1350 (defun anything-insert-string (str)
1351 "Insert STR."
1352 (delete-minibuffer-contents)
1353 (insert str))
1355 (defun anything-c-match-on-file-name (candidate)
1356 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1357 (string-match anything-pattern (file-name-nondirectory candidate)))
1359 (defun anything-c-match-on-directory-name (candidate)
1360 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1361 (anything-aif (file-name-directory candidate)
1362 (string-match anything-pattern it)))
1364 (defun anything-c-string-match (candidate)
1365 "Return non-nil if `anything-pattern' match CANDIDATE.
1366 The match is done with `string-match'."
1367 (string-match anything-pattern candidate))
1369 ;; `anything-c-compose' is no more needed, it is for compatibility.
1370 (defalias 'anything-c-compose 'anything-compose)
1372 (defun anything-c-skip-entries (list regexp)
1373 "Remove entries which matches REGEXP from LIST."
1374 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
1375 list))
1377 (defun anything-c-shadow-entries (list regexp)
1378 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1379 (mapcar (lambda (file)
1380 ;; Add shadow face property to boring files.
1381 (let ((face (if (facep 'file-name-shadow)
1382 'file-name-shadow
1383 ;; fall back to default on XEmacs
1384 'default)))
1385 (if (string-match regexp file)
1386 (setq file (propertize file 'face face))))
1387 file)
1388 list))
1390 (defsubst anything-c-stringify (str-or-sym)
1391 "Get string of STR-OR-SYM."
1392 (if (stringp str-or-sym)
1393 str-or-sym
1394 (symbol-name str-or-sym)))
1396 (defsubst anything-c-symbolify (str-or-sym)
1397 "Get symbol of STR-OR-SYM."
1398 (if (symbolp str-or-sym)
1399 str-or-sym
1400 (intern str-or-sym)))
1402 (defun anything-c-describe-function (func)
1403 "FUNC is symbol or string."
1404 (describe-function (anything-c-symbolify func)))
1406 (defun anything-c-describe-variable (var)
1407 "VAR is symbol or string."
1408 (describe-variable (anything-c-symbolify var)))
1410 (defun anything-c-find-function (func)
1411 "FUNC is symbol or string."
1412 (find-function (anything-c-symbolify func)))
1414 (defun anything-c-find-variable (var)
1415 "VAR is symbol or string."
1416 (find-variable (anything-c-symbolify var)))
1418 (defun anything-c-kill-new (string &optional replace yank-handler)
1419 "STRING is symbol or string."
1420 (kill-new (anything-c-stringify string) replace yank-handler))
1422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1423 ;; TODO
1424 (defvar anything-current-prefix-arg nil
1425 "`current-prefix-arg' when selecting action.
1426 It is cleared after executing action.")
1428 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
1429 (unless anything-current-prefix-arg
1430 (setq anything-current-prefix-arg current-prefix-arg)))
1432 (add-hook 'anything-after-action-hook
1433 (lambda () (setq anything-current-prefix-arg nil)))
1436 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1437 (defadvice eval-defun (after anything-source-hack activate)
1438 "See `anything-c-enable-eval-defun-hack'."
1439 (when anything-c-enable-eval-defun-hack
1440 (let ((varsym (save-excursion
1441 (beginning-of-defun)
1442 (forward-char 1)
1443 (when (memq (read (current-buffer)) '(defvar setq))
1444 (read (current-buffer))))))
1445 (when (string-match "^anything-c-source-" (symbol-name varsym))
1446 (anything varsym)))))
1447 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1450 (defun anything-c-create-summary ()
1451 "Create `anything' summary."
1452 (save-excursion
1453 (goto-char (point-min))
1454 (loop while (re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$" nil t)
1455 collect (cond ((match-beginning 1)
1456 (cons 'section (match-string-no-properties 1)))
1457 ((match-beginning 2)
1458 (cons 'source
1459 (cons (match-string-no-properties 2)
1460 (assoc-default 'name (symbol-value (intern (match-string-no-properties 2)))))))
1461 ((match-beginning 3)
1462 (cons 'source
1463 (cons (match-string-no-properties 3)
1464 (assoc-default 'name (symbol-value (intern (match-string-no-properties 3)))))))))))
1466 ;; (find-epp (anything-c-create-summary))
1468 (defun anything-c-insert-summary ()
1469 "Insert `anything' summary."
1470 (save-excursion
1471 (goto-char (point-min))
1472 (search-forward ";; Below are complete source list you can setup in")
1473 (forward-line 1)
1474 (delete-region (point)
1475 (progn (search-forward ";;; Change log:" nil t)
1476 (forward-line -1) (point)))
1477 (insert ";;\n")
1478 (loop with beg
1479 for (kind . value) in (anything-c-create-summary)
1480 for i from 0
1481 do (cond ((eq kind 'section)
1482 (unless (zerop i)
1483 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1484 (insert ";; " value ":\n")
1485 (setq beg (point)))
1487 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
1488 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
1489 ;; (anything-c-insert-summary)
1491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1492 ;;;; <Buffer>
1493 (defun anything-c-buffer-list ()
1494 "Return the list of names of buffers with boring buffers filtered out.
1495 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1496 The first buffer in the list will be the last recently used
1497 buffer that is not the current buffer."
1498 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1499 (append (cdr buffers) (list (car buffers)))))
1501 (defvar anything-c-source-buffers
1502 '((name . "Buffers")
1503 (candidates . anything-c-buffer-list)
1504 (type . buffer)))
1505 ;; (anything 'anything-c-source-buffers)
1507 (defvar anything-c-source-buffer-not-found
1508 '((name . "Create buffer")
1509 (dummy)
1510 (type . buffer)))
1511 ;; (anything 'anything-c-source-buffer-not-found)
1513 ;;; Buffers+
1514 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1515 "*Face used for directory headings in dired buffers."
1516 :group 'anything)
1518 (defface anything-file-name
1519 '((t (:foreground "Blue")))
1520 "*Face used for file names (without suffixes) in dired buffers."
1521 :group 'anything)
1523 (defface anything-dir-priv
1524 '((t (:foreground "DarkRed" :background "LightGray")))
1525 "*Face used for directory privilege indicator (d) in dired buffers."
1526 :group 'anything)
1528 (defvar anything-c-buffers-face1 'anything-dir-priv)
1529 (defvar anything-c-buffers-face2 'font-lock-type-face)
1530 (defvar anything-c-buffers-face3 'italic)
1531 (eval-when-compile (require 'dired))
1532 (defun anything-c-highlight-buffers (buffers)
1533 (require 'dired)
1534 (loop for i in buffers
1535 if (rassoc (get-buffer i) dired-buffers)
1536 collect (propertize i
1537 'face anything-c-buffers-face1
1538 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1539 if (buffer-file-name (get-buffer i))
1540 collect (propertize i
1541 'face anything-c-buffers-face2
1542 'help-echo (buffer-file-name (get-buffer i)))
1543 if (and (not (rassoc (get-buffer i) dired-buffers))
1544 (not (buffer-file-name (get-buffer i))))
1545 collect (propertize i
1546 'face anything-c-buffers-face3)))
1548 (defvar anything-c-source-buffers+
1549 '((name . "Buffers")
1550 (candidates . anything-c-buffer-list)
1551 (type . buffer)
1552 (candidate-transformer anything-c-skip-current-buffer
1553 anything-c-highlight-buffers
1554 anything-c-skip-boring-buffers)
1555 (persistent-action . anything-c-buffers+-persistent-action)
1556 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1558 (defun anything-c-buffers+-persistent-action (name)
1559 (flet ((kill (item)
1560 (with-current-buffer item
1561 (if (and (buffer-modified-p)
1562 (buffer-file-name (current-buffer)))
1563 (progn
1564 (save-buffer)
1565 (kill-buffer item))
1566 (kill-buffer item))))
1567 (goto (item)
1568 (switch-to-buffer item)))
1569 (if current-prefix-arg
1570 (progn
1571 (kill name)
1572 (anything-delete-current-selection))
1573 (goto name))))
1575 ;; (anything 'anything-c-source-buffers+)
1578 ;;;; <File>
1579 ;;; File name history
1580 (defvar anything-c-source-file-name-history
1581 '((name . "File Name History")
1582 (candidates . file-name-history)
1583 (match anything-c-match-on-file-name
1584 anything-c-match-on-directory-name)
1585 (type . file)))
1586 ;; (anything 'anything-c-source-file-name-history)
1588 ;;; Files in current dir
1589 (defvar anything-c-source-files-in-current-dir
1590 '((name . "Files from Current Directory")
1591 (candidates . (lambda ()
1592 (with-current-buffer anything-current-buffer
1593 (directory-files (anything-c-current-directory)))))
1594 ;; volatile is not needed, I think.
1595 (type . file)))
1596 ;; (anything 'anything-c-source-files-in-current-dir)
1598 (defvar anything-c-files-face1 'anything-dir-priv)
1599 (defvar anything-c-files-face2 'anything-file-name)
1600 (defun anything-c-highlight-files (files)
1601 (loop for i in files
1602 if (file-directory-p i)
1603 collect (propertize (file-name-nondirectory i)
1604 'face anything-c-files-face1
1605 'help-echo (expand-file-name i))
1606 else
1607 collect (propertize (file-name-nondirectory i)
1608 'face anything-c-files-face2
1609 'help-echo (expand-file-name i))))
1612 (defvar anything-c-source-files-in-current-dir+
1613 '((name . "Files from Current Directory")
1614 (candidates . (lambda ()
1615 (with-current-buffer anything-current-buffer
1616 (directory-files (anything-c-current-directory) t))))
1617 (candidate-transformer anything-c-highlight-files)
1618 ;; volatile is not needed, I think.
1619 (type . file)))
1621 ;; (anything 'anything-c-source-files-in-current-dir+)
1623 ;;; Anything replacement of file name completion for `find-file' and friends.
1625 (defvar anything-c-find-files-doc-header (format " (`%s':Go to precedent level)"
1626 (if window-system "C-." "C-l"))
1627 "*The doc that is inserted in the Name header of a find-files or dired source.")
1629 (defvar anything-c-source-find-files
1630 `((name . ,(concat "Find Files" anything-c-find-files-doc-header))
1631 ;; It is needed for filenames with capital letters
1632 (disable-shortcuts)
1633 (init . (lambda ()
1634 (setq ffap-newfile-prompt t)))
1635 (candidates . anything-find-files-get-candidates)
1636 (candidate-transformer anything-c-highlight-ffiles)
1637 (persistent-action . anything-find-files-persistent-action)
1638 (persistent-help . "Expand Candidate")
1639 (volatile)
1640 (action
1641 . ,(delq
1643 `(("Find File" . anything-c-find-file-or-marked)
1644 ("Find file in Dired" . anything-c-point-file-in-dired)
1645 ,(and (locate-library "elscreen")
1646 '("Find file in Elscreen" . anything-elscreen-find-file))
1647 ("Complete at point"
1648 . anything-c-insert-file-name-completion-at-point)
1649 ("Delete File(s)" . anything-delete-marked-files)
1650 ("Find file as root" . anything-find-file-as-root)
1651 ("Open file externally (C-u to choose)"
1652 . anything-c-open-file-externally)
1653 ;; ("Create dired buffer on marked"
1654 ;; . anything-c-create-dired-on-marked)
1655 ("Find file other window" . find-file-other-window)
1656 ("Find file other frame" . find-file-other-frame))))))
1658 ;; (anything 'anything-c-source-find-files)
1660 (defun* anything-reduce-file-name (fname level &key unix-close expand)
1661 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1662 If LEVEL is positive reduce from end else from beginning.
1663 If UNIX-CLOSE is non--nil close filename with /.
1664 If EXPAND is non--nil expand-file-name."
1665 (let* ((exp-fname (expand-file-name fname))
1666 (fname-list (split-string (if (or (string= fname "~/") expand)
1667 exp-fname fname) "/" t))
1668 (len (length fname-list))
1669 (pop-list (if (< level 0)
1670 (subseq fname-list (* level -1))
1671 (subseq fname-list 0 (- len level))))
1672 (result (mapconcat 'identity pop-list "/"))
1673 (empty (string= result "")))
1674 (when unix-close (setq result (concat result "/")))
1675 (if (string-match "^~" result)
1676 (if (string= result "~/") "~/" result)
1677 (if (< level 0)
1678 (if empty "../" (concat "../" result))
1679 (cond ((eq system-type 'windows-nt)
1680 (if empty "c:/" result))
1681 (empty "/")
1683 (concat "/" result)))))))
1685 (defun anything-file-completion-source-p ()
1686 "Test if current source is a dired or find-files source."
1687 (let ((ff-sources '("Find Files" "Copy Files"
1688 "Rename Files" "Symlink Files"
1689 "Hardlink Files" "Write File"
1690 "Insert File" "Read file name"))
1691 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
1692 (catch 'break
1693 (dolist (i ff-sources)
1694 (when (equal cur-source (concat i anything-c-find-files-doc-header))
1695 (throw 'break t))))))
1697 (defun anything-find-files-down-one-level (arg)
1698 "Go down one level like unix command `cd ..'.
1699 If prefix numeric arg is given go ARG level down."
1700 (interactive "p")
1701 (when (anything-file-completion-source-p)
1702 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
1703 :unix-close t :expand t)))
1704 (with-selected-window (minibuffer-window)
1705 (delete-minibuffer-contents)
1706 (insert new-pattern)))))
1708 ;; `C-.' doesn't work in terms use `C-l' instead.
1709 (if window-system
1710 (define-key anything-map (kbd "C-.") 'anything-find-files-down-one-level)
1711 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))
1713 (defun anything-c-point-file-in-dired (file)
1714 "Put point on filename FILE in dired buffer."
1715 (dired (file-name-directory file))
1716 (dired-goto-file file))
1718 (defun anything-create-tramp-name (fname)
1719 "Build filename for `anything-pattern' like /su:: or /sudo::."
1720 (apply #'tramp-make-tramp-file-name
1721 (loop
1722 with v = (tramp-dissect-file-name fname)
1723 for i across v collect i)))
1725 (defun anything-find-files-get-candidates ()
1726 "Create candidate list for `anything-c-source-find-files'."
1727 (let* ( ; Don't try to tramp connect before entering the second ":".
1728 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1729 (path (cond ((string-match "^~" anything-pattern)
1730 (replace-match (getenv "HOME") nil t anything-pattern))
1731 ((string-match tramp-file-name-regexp anything-pattern)
1732 (let ((tramp-name (anything-create-tramp-name
1733 (match-string 0 anything-pattern))))
1734 (replace-match tramp-name nil t anything-pattern)))
1735 (t anything-pattern)))
1736 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
1737 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1738 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1739 ;; and sorting.
1740 (flet ((tramp-handle-directory-files
1741 (directory &optional full match nosort files-only)
1742 "Like `directory-files' for Tramp files."
1743 ;; FILES-ONLY is valid for XEmacs only.
1744 (when (file-directory-p directory)
1745 (setq directory (file-name-as-directory (expand-file-name directory)))
1746 (let ((temp (nreverse (file-name-all-completions "" directory)))
1747 result item)
1749 (while temp
1750 (setq item (directory-file-name (pop temp)))
1751 (when (and (or (null match) (string-match match item))
1752 (or (null files-only)
1753 ;; Files only.
1754 (and (equal files-only t) (file-regular-p item))
1755 ;; Directories only.
1756 (file-directory-p item)))
1757 (push (if full (concat directory item) item)
1758 result)))
1759 (if nosort result (sort result 'string<))))))
1761 (set-text-properties 0 (length path) nil path)
1762 (setq anything-pattern path)
1763 (cond ((or (file-regular-p path)
1764 (and ffap-url-regexp (string-match ffap-url-regexp path)))
1765 (list path))
1766 ((string= anything-pattern "") (directory-files "/" t))
1767 ((file-directory-p path) (directory-files path t))
1769 (append
1770 (list path)
1771 (directory-files (file-name-directory path) t)))))))
1773 (defface anything-dired-symlink-face
1774 '((t (:foreground "DarkOrange")))
1775 "*Face used for symlinks in `anything-find-files'."
1776 :group 'anything)
1778 (defun anything-c-highlight-ffiles (files)
1779 "Candidate transformer for `anything-c-source-find-files'."
1780 (loop for i in files
1781 if (file-symlink-p i)
1782 collect (propertize i 'face 'anything-dired-symlink-face
1783 'help-echo (file-truename i)) into a
1784 if (file-directory-p i)
1785 collect (propertize i 'face anything-c-files-face1) into a
1786 else
1787 collect (propertize i 'face anything-c-files-face2) into a
1788 finally return a))
1791 (defun anything-find-files-persistent-action (candidate)
1792 "Open subtree CANDIDATE without quitting anything.
1793 If CANDIDATE is not a directory expand CANDIDATE filename.
1794 If CANDIDATE is alone, open file CANDIDATE filename."
1795 (flet ((insert-in-minibuffer (elm)
1796 (with-selected-window (minibuffer-window)
1797 (delete-minibuffer-contents)
1798 (set-text-properties 0 (length elm) nil elm)
1799 (insert elm))))
1800 (cond ((and (file-directory-p candidate) (file-symlink-p candidate))
1801 (insert-in-minibuffer (file-name-as-directory
1802 (file-truename
1803 (expand-file-name candidate)))))
1804 ((file-directory-p candidate)
1805 (insert-in-minibuffer (file-name-as-directory
1806 (expand-file-name candidate))))
1807 ((file-symlink-p candidate)
1808 (insert-in-minibuffer (file-truename candidate)))
1809 (t ; First hit on C-z expand CANDIDATE second hit open file.
1810 (let ((new-pattern (anything-get-selection anything-last-buffer))
1811 (num-lines-buf (with-current-buffer anything-last-buffer
1812 (count-lines (point-min) (point-max)))))
1813 (if (> num-lines-buf 3)
1814 (insert-in-minibuffer new-pattern) (find-file candidate)))))))
1816 (defun anything-c-insert-file-name-completion-at-point (candidate)
1817 "Insert file name completion at point."
1818 (if buffer-read-only
1819 (error "Error: Buffer `%s' is read-only" (buffer-name))
1820 (let* ((end (point))
1821 (guess (thing-at-point 'filename))
1822 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess)
1823 (string-match "^[^\~]" guess))))
1824 (set-text-properties 0 (length candidate) nil candidate)
1825 (if (and guess (not (string= guess "")) (string-match "^~\\|/.*" guess))
1826 (progn
1827 (search-backward guess (- (point) (length guess)))
1828 (delete-region (point) end)
1829 (if full-path-p
1830 (insert (expand-file-name candidate))
1831 (insert (abbreviate-file-name candidate))))
1832 (error "Aborting completion: No valid file name at point")))))
1834 ;;;###autoload
1835 (defun anything-find-files ()
1836 "Preconfigured `anything' for anything implementation of `find-file'."
1837 (interactive)
1838 (anything 'anything-c-source-find-files
1839 (anything-find-files-input (ffap-guesser)
1840 (thing-at-point 'filename))
1841 "Find Files or Url: " nil nil "*Anything Find Files*"))
1843 (defun anything-c-current-directory ()
1844 "Return current-directory name at point.
1845 Useful in dired buffers when there is inserted subdirs."
1846 (if (eq major-mode 'dired-mode)
1847 (dired-current-directory)
1848 default-directory))
1850 (defun anything-find-files-input (fap tap)
1851 "Default input of `anything-find-files'."
1852 (let* ((def-dir (anything-c-current-directory))
1853 (file-p (and fap (file-exists-p fap)
1854 (file-exists-p
1855 (file-name-directory (expand-file-name tap def-dir)))))
1856 (input (if file-p (expand-file-name tap def-dir) fap)))
1857 (or input (expand-file-name def-dir))))
1859 ;;; Anything completion for `write-file'.==> C-x C-w
1860 (defvar anything-c-source-write-file
1861 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
1862 ;; It is needed for filenames with capital letters
1863 (disable-shortcuts)
1864 (candidates . anything-find-files-get-candidates)
1865 (candidate-transformer anything-c-highlight-ffiles)
1866 (persistent-action . anything-find-files-persistent-action)
1867 (persistent-help . "Expand Candidate")
1868 (volatile)
1869 (action .
1870 (("Write File" . (lambda (candidate)
1871 (write-file candidate 'confirm)))))))
1873 ;;;###autoload
1874 (defun anything-write-file ()
1875 "Preconfigured `anything' providing completion for `write-file'."
1876 (interactive)
1877 (anything 'anything-c-source-write-file
1878 (expand-file-name default-directory)
1879 "Write buffer to file: " nil nil "*Anything write file*"))
1881 ;;; Anything completion for `insert-file'.==> C-x i
1882 (defvar anything-c-source-insert-file
1883 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
1884 ;; It is needed for filenames with capital letters
1885 (disable-shortcuts)
1886 (candidates . anything-find-files-get-candidates)
1887 (candidate-transformer anything-c-highlight-ffiles)
1888 (persistent-action . anything-find-files-persistent-action)
1889 (persistent-help . "Expand Candidate")
1890 (volatile)
1891 (action .
1892 (("Insert File" . (lambda (candidate)
1893 (when (y-or-n-p (format "Really insert %s in %s "
1894 candidate anything-current-buffer))
1895 (insert-file-contents candidate))))))))
1897 ;;;###autoload
1898 (defun anything-insert-file ()
1899 "Preconfigured `anything' providing completion for `insert-file'."
1900 (interactive)
1901 (anything 'anything-c-source-insert-file
1902 (expand-file-name default-directory)
1903 "Insert file: " nil nil "*Anything insert file*"))
1905 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
1906 (defvar anything-c-source-copy-files
1907 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
1908 ;; It is needed for filenames with capital letters
1909 (disable-shortcuts)
1910 (candidates . anything-find-files-get-candidates)
1911 (candidate-transformer anything-c-highlight-ffiles)
1912 (persistent-action . anything-find-files-persistent-action)
1913 (persistent-help . "Expand Candidate")
1914 (volatile)
1915 (action .
1916 (("Copy File"
1917 . (lambda (candidate)
1918 (anything-dired-action candidate :action 'copy)))
1919 ("Copy and Follow"
1920 . (lambda (candidate)
1921 (anything-dired-action candidate :action 'copy :follow t)))))))
1924 (defvar anything-c-source-rename-files
1925 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
1926 ;; It is needed for filenames with capital letters
1927 (disable-shortcuts)
1928 (candidates . anything-find-files-get-candidates)
1929 (candidate-transformer anything-c-highlight-ffiles)
1930 (persistent-action . anything-find-files-persistent-action)
1931 (persistent-help . "Expand Candidate")
1932 (volatile)
1933 (action .
1934 (("Rename File"
1935 . (lambda (candidate)
1936 (anything-dired-action candidate :action 'rename)))
1937 ("Rename and Follow"
1938 . (lambda (candidate)
1939 (anything-dired-action candidate :action 'rename :follow t)))))))
1941 (defvar anything-c-source-symlink-files
1942 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
1943 ;; It is needed for filenames with capital letters
1944 (disable-shortcuts)
1945 (candidates . anything-find-files-get-candidates)
1946 (candidate-transformer anything-c-highlight-ffiles)
1947 (persistent-action . anything-find-files-persistent-action)
1948 (persistent-help . "Expand Candidate")
1949 (volatile)
1950 (action
1951 . (("Symlink File"
1952 . (lambda (candidate)
1953 (anything-dired-action candidate :action 'symlink)))
1954 ("RelSymlink File"
1955 . (lambda (candidate)
1956 (anything-dired-action candidate :action 'relsymlink)))))))
1959 (defvar anything-c-source-hardlink-files
1960 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
1961 ;; It is needed for filenames with capital letters
1962 (disable-shortcuts)
1963 (candidates . anything-find-files-get-candidates)
1964 (candidate-transformer anything-c-highlight-ffiles)
1965 (persistent-action . anything-find-files-persistent-action)
1966 (persistent-help . "Expand Candidate")
1967 (volatile)
1968 (action
1969 . (("Hardlink File"
1970 . (lambda (candidate)
1971 (anything-dired-action candidate :action 'hardlink)))))))
1973 (defun* anything-dired-action (candidate &key action follow)
1974 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
1975 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
1976 (let ((files (dired-get-marked-files))
1977 (fn (case action
1978 ('copy 'dired-copy-file)
1979 ('rename 'dired-rename-file)
1980 ('symlink 'make-symbolic-link)
1981 ('relsymlink 'dired-make-relative-symlink)
1982 ('hardlink 'dired-hardlink)))
1983 (marker (case action
1984 ((copy rename) dired-keep-marker-copy)
1985 ('symlink dired-keep-marker-symlink)
1986 ('relsymlink dired-keep-marker-relsymlink)
1987 ('hardlink dired-keep-marker-hardlink))))
1988 (dired-create-files
1989 fn (symbol-name action) files
1990 (if (file-directory-p candidate)
1991 ;; When CANDIDATE is a directory, build file-name in this directory.
1992 ;; Else we use CANDIDATE.
1993 #'(lambda (from)
1994 (expand-file-name (file-name-nondirectory from) candidate))
1995 #'(lambda (from) candidate))
1996 marker)
1997 (when follow
1998 (let* ((src (car files))
1999 (dest (expand-file-name candidate))
2000 (basename-src (if (file-directory-p src)
2001 (file-relative-name
2002 (directory-file-name src)
2003 (file-name-directory src))
2004 (file-name-nondirectory src)))
2005 (fname (if (file-directory-p dest)
2006 (concat (file-name-as-directory dest)
2007 basename-src)
2008 dest)))
2009 (anything-c-point-file-in-dired fname)))))
2012 (defun* anything-dired-do-action-on-file (&key action)
2013 (let* ((files (dired-get-marked-files))
2014 (len (length files))
2015 (fname (if (> len 1)
2016 (format "* %d Files" len)
2017 (car files)))
2018 (source (case action
2019 ('copy 'anything-c-source-copy-files)
2020 ('rename 'anything-c-source-rename-files)
2021 ('symlink 'anything-c-source-symlink-files)
2022 ('hardlink 'anything-c-source-hardlink-files)))
2023 (prompt-fm (case action
2024 ('copy "Copy %s to: ")
2025 ('rename "Rename %s to: ")
2026 ('symlink "Symlink %s to: ")
2027 ('hardlink "Hardlink %s to: ")))
2028 (buffer (case action
2029 ('copy "*Anything Copy Files*")
2030 ('rename "*Anything Rename Files*")
2031 ('symlink "*Anything Symlink Files*")
2032 ('hardlink "*Anything Hardlink Files*"))))
2033 (anything source
2034 (or (dired-dwim-target-directory)
2035 (expand-file-name (anything-c-current-directory)))
2036 (format prompt-fm fname) nil nil buffer)))
2039 ;;;###autoload
2040 (defun anything-dired-rename-file ()
2041 "Preconfigured `anything' to rename files from dired."
2042 (interactive)
2043 (anything-dired-do-action-on-file :action 'rename))
2045 ;;;###autoload
2046 (defun anything-dired-copy-file ()
2047 "Preconfigured `anything' to copy files from dired."
2048 (interactive)
2049 (anything-dired-do-action-on-file :action 'copy))
2051 ;;;###autoload
2052 (defun anything-dired-symlink-file ()
2053 "Preconfigured `anything' to symlink files from dired."
2054 (interactive)
2055 (anything-dired-do-action-on-file :action 'symlink))
2057 ;;;###autoload
2058 (defun anything-dired-hardlink-file ()
2059 "Preconfigured `anything' to hardlink files from dired."
2060 (interactive)
2061 (anything-dired-do-action-on-file :action 'hardlink))
2063 (defvar anything-dired-bindings nil)
2064 ;;;###autoload
2065 (defun anything-dired-bindings (&optional arg)
2066 "Replace usual dired commands `C' and `R' by anything ones.
2067 When call interactively toggle dired bindings and anything bindings.
2068 When call non--interactively with arg > 0, enable anything bindings.
2069 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2070 (interactive)
2071 (if (or (when arg (> arg 0)) (not anything-dired-bindings))
2072 (progn
2073 (define-key dired-mode-map (kbd "C") 'anything-dired-copy-file)
2074 (define-key dired-mode-map (kbd "R") 'anything-dired-rename-file)
2075 (define-key dired-mode-map (kbd "S") 'anything-dired-symlink-file)
2076 (define-key dired-mode-map (kbd "H") 'anything-dired-hardlink-file)
2077 (setq anything-dired-bindings t))
2078 (define-key dired-mode-map (kbd "C") 'dired-do-copy)
2079 (define-key dired-mode-map (kbd "R") 'dired-do-rename)
2080 (define-key dired-mode-map (kbd "S") 'dired-do-symlink)
2081 (define-key dired-mode-map (kbd "H") 'dired-do-hardlink)
2082 (setq anything-dired-bindings nil)))
2084 (defun* anything-c-read-file-name (prompt &key
2085 (initial-input (expand-file-name default-directory))
2086 (buffer "*Anything Completions*")
2087 test)
2088 "Anything `read-file-name' emulation.
2089 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2090 (when (get-buffer anything-action-buffer)
2091 (kill-buffer anything-action-buffer))
2092 (or (anything
2093 `((name . ,(concat "Read file name" anything-c-find-files-doc-header))
2094 ;; It is needed for filenames with capital letters
2095 (disable-shortcuts)
2096 (candidates . (lambda ()
2097 (if test
2098 (loop with seq = (anything-find-files-get-candidates)
2099 for fname in seq when (funcall test fname)
2100 collect fname)
2101 (anything-find-files-get-candidates))))
2102 (candidate-transformer anything-c-highlight-ffiles)
2103 (persistent-action . anything-find-files-persistent-action)
2104 (persistent-help . "Expand Candidate")
2105 (volatile)
2106 (action . (("candidate" . ,'identity))))
2107 initial-input prompt 'noresume nil buffer)
2108 (keyboard-quit)))
2110 ;;; File Cache
2111 (defvar anything-c-source-file-cache-initialized nil)
2113 (defvar anything-c-file-cache-files nil)
2115 (defvar anything-c-source-file-cache
2116 '((name . "File Cache")
2117 (init
2118 . (lambda ()
2119 (require 'filecache nil t)
2120 (unless anything-c-source-file-cache-initialized
2121 (setq anything-c-file-cache-files
2122 (loop for item in file-cache-alist append
2123 (destructuring-bind (base &rest dirs) item
2124 (loop for dir in dirs collect
2125 (concat dir base)))))
2126 (defadvice file-cache-add-file (after file-cache-list activate)
2127 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
2128 (setq anything-c-source-file-cache-initialized t))))
2129 (candidates . anything-c-file-cache-files)
2130 (match anything-c-match-on-file-name
2131 anything-c-match-on-directory-name)
2132 (type . file)))
2133 ;; (anything 'anything-c-source-file-cache)
2135 ;;; Locate
2136 ;; NOTE for WINDOZE users:
2137 ;; You have to install Everything with his command line interface here:
2138 ;; http://www.voidtools.com/download.php
2140 (defvar anything-c-locate-command
2141 (case system-type
2142 ('gnu/linux "locate -i -r %s")
2143 ('berkeley-unix "locate -i %s")
2144 ('windows-nt "es -i -r %s")
2145 (t "locate %s"))
2146 "A list of arguments for locate program.
2147 The \"-r\" option must be the last option.")
2149 (defun anything-c-locate-init ()
2150 "Initialize async locate process for `anything-c-source-locate'."
2151 (start-process-shell-command "locate-process" nil
2152 (format anything-c-locate-command
2153 anything-pattern)))
2155 (defvar anything-c-source-locate
2156 '((name . "Locate")
2157 (candidates . anything-c-locate-init)
2158 (type . file)
2159 (requires-pattern . 3)
2160 (delayed))
2161 "Find files matching the current input pattern with locate.")
2163 ;; (anything 'anything-c-source-locate)
2165 ;;; Recentf files
2166 (defvar anything-c-source-recentf
2167 '((name . "Recentf")
2168 (init . (lambda ()
2169 (require 'recentf)
2170 (or recentf-mode (recentf-mode 1))
2171 ;; Big value empowers anything/recentf
2172 (when (and (numberp recentf-max-saved-items)
2173 (<= recentf-max-saved-items 20))
2174 (setq recentf-max-saved-items 500))))
2175 (candidates . recentf-list)
2176 (match anything-c-match-on-file-name
2177 anything-c-match-on-directory-name)
2178 (type . file))
2179 "See (info \"(emacs)File Conveniences\").
2180 if `recentf-max-saved-items' is too small, set it to 500.")
2181 ;; (anything 'anything-c-source-recentf)
2183 ;;; ffap
2184 (eval-when-compile (require 'ffap))
2185 (defvar anything-c-source-ffap-guesser
2186 '((name . "File at point")
2187 (init . (lambda () (require 'ffap)))
2188 (candidates . (lambda ()
2189 (anything-aif
2190 (with-current-buffer anything-current-buffer
2191 (ffap-guesser))
2192 (list it))))
2193 (type . file)))
2194 ;; (anything 'anything-c-source-ffap-guesser)
2196 ;;; ffap with line number
2197 (defun anything-c-ffap-file-line-at-point ()
2198 "Get (FILENAME . LINENO) at point."
2199 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2200 (save-excursion
2201 (beginning-of-line)
2202 (when (and (search-forward it nil t)
2203 (looking-at ":\\([0-9]+\\)"))
2204 (cons it (string-to-number (match-string 1)))))))
2206 (defvar anything-c-ffap-line-location nil
2207 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2208 It is cleared after jumping line.")
2210 (defun anything-c-ffap-line-candidates ()
2211 (with-current-buffer anything-current-buffer
2212 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
2213 (when anything-c-ffap-line-location
2214 (destructuring-bind (file . line) anything-c-ffap-line-location
2215 (list (cons (format "%s (line %d)" file line) file)))))
2217 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2218 (defun anything-c-ffap-line-goto-line ()
2219 (when (car anything-c-ffap-line-location)
2220 (unwind-protect
2221 (ignore-errors
2222 (with-selected-window
2223 (get-buffer-window
2224 (get-file-buffer (car anything-c-ffap-line-location)))
2225 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
2226 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
2227 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
2229 (defvar anything-c-source-ffap-line
2230 '((name . "File/Lineno at point")
2231 (init . (lambda () (require 'ffap)))
2232 (candidates . anything-c-ffap-line-candidates)
2233 (type . file)))
2234 ;; (anything 'anything-c-source-ffap-line)
2236 ;;; list of files gleaned from every dired buffer
2237 (defun anything-c-files-in-all-dired-candidates ()
2238 (save-excursion
2239 (mapcan
2240 (lambda (dir)
2241 (cond ((listp dir) ;filelist
2242 dir)
2243 ((equal "" (file-name-nondirectory dir)) ;dir
2244 (directory-files dir t))
2245 (t ;wildcard
2246 (file-expand-wildcards dir t))))
2247 (delq nil
2248 (mapcar (lambda (buf)
2249 (set-buffer buf)
2250 (when (eq major-mode 'dired-mode)
2251 (if (consp dired-directory)
2252 (cdr dired-directory) ;filelist
2253 dired-directory))) ;dir or wildcard
2254 (buffer-list))))))
2255 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2257 (defvar anything-c-source-files-in-all-dired
2258 '((name . "Files in all dired buffer.")
2259 (candidates . anything-c-files-in-all-dired-candidates)
2260 (type . file)))
2261 ;; (anything 'anything-c-source-files-in-all-dired)
2263 ;;;; <info>
2264 ;;; Info pages
2265 (defvar anything-c-info-pages nil
2266 "All info pages on system.
2267 Will be calculated the first time you invoke anything with this
2268 source.")
2270 (defvar anything-c-source-info-pages
2271 `((name . "Info Pages")
2272 (candidates
2273 . (lambda ()
2274 (if anything-c-info-pages
2275 anything-c-info-pages
2276 (setq anything-c-info-pages
2277 (save-window-excursion
2278 (save-excursion
2279 (require 'info)
2280 (Info-find-node "dir" "top")
2281 (goto-char (point-min))
2282 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2283 topics)
2284 (while (re-search-forward info-topic-regexp nil t)
2285 (add-to-list 'topics (match-string-no-properties 1)))
2286 (goto-char (point-min))
2287 (Info-exit)
2288 topics)))))))
2289 (action . (("Show with Info" .(lambda (node-str)
2290 (info (replace-regexp-in-string
2291 "^[^:]+: " "" node-str))))))
2292 (requires-pattern . 2)))
2293 ;; (anything 'anything-c-source-info-pages)
2296 ;;; Use info-index plug-in. Note that `name' attribute is
2297 ;;; not needed but `anything-c-insert-summary' uses it.
2298 ;; Info Elisp
2299 (defvar anything-c-source-info-elisp
2300 '((name . "Info index: elisp")
2301 (info-index . "elisp")))
2302 ;; (anything 'anything-c-source-info-elisp)
2304 ;; Info-Common-Lisp
2305 (defvar anything-c-source-info-cl
2306 '((name . "Info index: cl")
2307 (info-index . "cl")))
2308 ;; (anything 'anything-c-source-info-cl)
2310 ;; Info Index org
2311 (defvar anything-c-source-info-org
2312 '((name . "Info index: org")
2313 (info-index . "org")))
2314 ;; (anything 'anything-c-source-info-org)
2316 ;; Info Index ratpoison
2317 (defvar anything-c-source-info-ratpoison
2318 '((name . "Info index: ratpoison")
2319 (info-index . "ratpoison")))
2320 ;; (anything 'anything-c-source-info-ratpoison)
2322 ;; Info Index zsh
2323 (defvar anything-c-source-info-zsh
2324 '((name . "Info index: zsh")
2325 (info-index . "zsh")))
2326 ;; (anything 'anything-c-source-info-zsh)
2328 ;; Info Index bash
2329 (defvar anything-c-source-info-bash
2330 '((name . "Info index: bash")
2331 (info-index . "bash")))
2332 ;; (anything 'anything-c-source-info-bash)
2334 ;; Info Index coreutils
2335 (defvar anything-c-source-info-coreutils
2336 '((name . "Info index: coreutils")
2337 (info-index . "coreutils")))
2338 ;; (anything 'anything-c-source-info-coreutils)
2340 ;; Info Index fileutils
2341 (defvar anything-c-source-info-fileutils
2342 '((name . "Info index: fileutils")
2343 (info-index . "fileutils")))
2344 ;; (anything 'anything-c-source-info-fileutils)
2346 ;; Info Index find
2347 (defvar anything-c-source-info-find
2348 '((name . "Info index: find")
2349 (info-index . "find")))
2350 ;; (anything 'anything-c-source-info-find)
2352 ;; Info Index sh-utils
2353 (defvar anything-c-source-info-sh-utils
2354 '((name . "Info index: sh-utils")
2355 (info-index . "sh-utils")))
2356 ;; (anything 'anything-c-source-info-sh-utils)
2358 ;; Info Index textutils
2359 (defvar anything-c-source-info-textutils
2360 '((name . "Info index: textutils")
2361 (info-index . "textutils")))
2362 ;; (anything 'anything-c-source-info-textutils)
2364 ;; Info Index libc
2365 (defvar anything-c-source-info-libc
2366 '((name . "Info index: libc")
2367 (info-index . "libc")))
2368 ;; (anything 'anything-c-source-info-libc)
2370 ;; Info Index make
2371 (defvar anything-c-source-info-make
2372 '((name . "Info index: make")
2373 (info-index . "make")))
2374 ;; (anything 'anything-c-source-info-make)
2376 ;; Info Index automake
2377 (defvar anything-c-source-info-automake
2378 '((name . "Info index: automake")
2379 (info-index . "automake")))
2380 ;; (anything 'anything-c-source-info-automake)
2382 ;; Info Index autoconf
2383 (defvar anything-c-source-info-autoconf
2384 '((name . "Info index: autoconf")
2385 (info-index . "autoconf")))
2386 ;; (anything 'anything-c-source-info-autoconf)
2388 ;; Info Index emacs-lisp-intro
2389 (defvar anything-c-source-info-emacs-lisp-intro
2390 '((name . "Info index: emacs-lisp-intro")
2391 (info-index . "emacs-lisp-intro")))
2392 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2394 ;; Info Index emacs
2395 (defvar anything-c-source-info-emacs
2396 '((name . "Info index: emacs")
2397 (info-index . "emacs")))
2398 ;; (anything 'anything-c-source-info-emacs)
2400 ;; Info Index elib
2401 (defvar anything-c-source-info-elib
2402 '((name . "Info index: elib")
2403 (info-index . "elib")))
2404 ;; (anything 'anything-c-source-info-elib)
2406 ;; Info Index eieio
2407 (defvar anything-c-source-info-eieio
2408 '((name . "Info index: eieio")
2409 (info-index . "eieio")))
2410 ;; (anything 'anything-c-source-info-eieio)
2412 ;; Info Index gauche-refe
2413 (defvar anything-c-source-info-gauche-refe
2414 '((name . "Info index: gauche")
2415 (info-index . "gauche-refe")))
2416 ;; (anything 'anything-c-source-info-gauche-refe)
2418 ;; Info Index guile
2419 (defvar anything-c-source-info-guile
2420 '((name . "Info index: guile")
2421 (info-index . "guile")))
2422 ;; (anything 'anything-c-source-info-guile)
2424 ;; Info Index guile-tut
2425 (defvar anything-c-source-info-guile-tut
2426 '((name . "Info index: guile-tut")
2427 (info-index . "guile-tut")))
2428 ;; (anything 'anything-c-source-info-guile-tut)
2430 ;; Info Index goops
2431 (defvar anything-c-source-info-goops
2432 '((name . "Info index: goops")
2433 (info-index . "goops")))
2434 ;; (anything 'anything-c-source-info-goops)
2436 ;; Info Index screen
2437 (defvar anything-c-source-info-screen
2438 '((name . "Info index: screen")
2439 (info-index . "screen")
2440 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2441 ;; (anything 'anything-c-source-info-screen)
2443 ;; Info Index latex
2444 (defvar anything-c-source-info-latex
2445 '((name . "Info index: latex")
2446 (info-index . "latex")))
2447 ;; (anything 'anything-c-source-info-latex)
2449 ;; Info Index gawk
2450 (defvar anything-c-source-info-gawk
2451 '((name . "Info index: gawk")
2452 (info-index . "gawk")))
2453 ;; (anything 'anything-c-source-info-gawk)
2455 ;; Info Index sed
2456 (defvar anything-c-source-info-sed
2457 '((name . "Info index: sed")
2458 (info-index . "sed")))
2459 ;; (anything 'anything-c-source-info-sed)
2461 ;; Info Index m4
2462 (defvar anything-c-source-info-m4
2463 '((name . "Info index: m4")
2464 (info-index . "m4")))
2465 ;; (anything 'anything-c-source-info-m4)
2467 ;; Info Index wget
2468 (defvar anything-c-source-info-wget
2469 '((name . "Info index: wget")
2470 (info-index . "wget")))
2471 ;; (anything 'anything-c-source-info-wget)
2473 ;; Info Index binutils
2474 (defvar anything-c-source-info-binutils
2475 '((name . "Info index: binutils")
2476 (info-index . "binutils")))
2477 ;; (anything 'anything-c-source-info-binutils)
2479 ;; Info Index as
2480 (defvar anything-c-source-info-as
2481 '((name . "Info index: as")
2482 (info-index . "as")))
2483 ;; (anything 'anything-c-source-info-as)
2485 ;; Info Index bfd
2486 (defvar anything-c-source-info-bfd
2487 '((name . "Info index: bfd")
2488 (info-index . "bfd")))
2489 ;; (anything 'anything-c-source-info-bfd)
2491 ;; Info Index gprof
2492 (defvar anything-c-source-info-gprof
2493 '((name . "Info index: gprof")
2494 (info-index . "gprof")))
2495 ;; (anything 'anything-c-source-info-gprof)
2497 ;; Info Index ld
2498 (defvar anything-c-source-info-ld
2499 '((name . "Info index: ld")
2500 (info-index . "ld")))
2501 ;; (anything 'anything-c-source-info-ld)
2503 ;; Info Index diff
2504 (defvar anything-c-source-info-diff
2505 '((name . "Info index: diff")
2506 (info-index . "diff")))
2507 ;; (anything 'anything-c-source-info-diff)
2509 ;; Info Index flex
2510 (defvar anything-c-source-info-flex
2511 '((name . "Info index: flex")
2512 (info-index . "flex")))
2513 ;; (anything 'anything-c-source-info-flex)
2515 ;; Info Index grep
2516 (defvar anything-c-source-info-grep
2517 '((name . "Info index: grep")
2518 (info-index . "grep")))
2519 ;; (anything 'anything-c-source-info-grep)
2521 ;; Info Index gzip
2522 (defvar anything-c-source-info-gzip
2523 '((name . "Info index: gzip")
2524 (info-index . "gzip")))
2525 ;; (anything 'anything-c-source-info-gzip)
2527 ;; Info Index libtool
2528 (defvar anything-c-source-info-libtool
2529 '((name . "Info index: libtool")
2530 (info-index . "libtool")))
2531 ;; (anything 'anything-c-source-info-libtool)
2533 ;; Info Index texinfo
2534 (defvar anything-c-source-info-texinfo
2535 '((name . "Info index: texinfo")
2536 (info-index . "texinfo")))
2537 ;; (anything 'anything-c-source-info-texinfo)
2539 ;; Info Index info
2540 (defvar anything-c-source-info-info
2541 '((name . "Info index: info")
2542 (info-index . "info")))
2543 ;; (anything 'anything-c-source-info-info)
2545 ;; Info Index gdb
2546 (defvar anything-c-source-info-gdb
2547 '((name . "Info index: gdb")
2548 (info-index . "gdb")))
2549 ;; (anything 'anything-c-source-info-gdb)
2551 ;; Info Index stabs
2552 (defvar anything-c-source-info-stabs
2553 '((name . "Info index: stabs")
2554 (info-index . "stabs")))
2555 ;; (anything 'anything-c-source-info-stabs)
2557 ;; Info Index cvsbook
2558 (defvar anything-c-source-info-cvsbook
2559 '((name . "Info index: cvsbook")
2560 (info-index . "cvsbook")))
2561 ;; (anything 'anything-c-source-info-cvsbook)
2563 ;; Info Index cvs
2564 (defvar anything-c-source-info-cvs
2565 '((name . "Info index: cvs")
2566 (info-index . "cvs")))
2567 ;; (anything 'anything-c-source-info-cvs)
2569 ;; Info Index bison
2570 (defvar anything-c-source-info-bison
2571 '((name . "Info index: bison")
2572 (info-index . "bison")))
2573 ;; (anything 'anything-c-source-info-bison)
2575 ;; Info Index id-utils
2576 (defvar anything-c-source-info-id-utils
2577 '((name . "Info index: id-utils")
2578 (info-index . "id-utils")))
2579 ;; (anything 'anything-c-source-info-id-utils)
2581 ;; Info Index global
2582 (defvar anything-c-source-info-global
2583 '((name . "Info index: global")
2584 (info-index . "global")))
2585 ;; (anything 'anything-c-source-info-global)
2587 ;;;; <Help>
2588 ;;; Man Pages
2589 (defvar anything-c-man-pages nil
2590 "All man pages on system.
2591 Will be calculated the first time you invoke anything with this
2592 source.")
2594 (defvar anything-c-source-man-pages
2595 `((name . "Manual Pages")
2596 (candidates . (lambda ()
2597 (if anything-c-man-pages
2598 anything-c-man-pages
2599 ;; XEmacs doesn't have a woman :)
2600 (setq anything-c-man-pages
2601 (ignore-errors
2602 (require 'woman)
2603 (woman-file-name "")
2604 (sort (mapcar 'car woman-topic-all-completions)
2605 'string-lessp))))))
2606 (action ("Show with Woman"
2607 . (lambda (candidate)
2608 (let ((wfiles (woman-file-name-all-completions candidate)))
2609 (if (> (length wfiles) 1)
2610 (woman-find-file (anything-comp-read "ManFile: " wfiles
2611 :must-match t))
2612 (woman candidate))))))
2613 ;; Woman does not work OS X
2614 ;; http://xahlee.org/emacs/modernization_man_page.html
2615 (action-transformer . (lambda (actions candidate)
2616 (if (eq system-type 'darwin)
2617 '(("Show with Man" . man))
2618 actions)))
2619 (requires-pattern . 2)))
2620 ;; (anything 'anything-c-source-man-pages)
2622 ;;;; <Command>
2623 ;;; Complex command history
2624 (defvar anything-c-source-complex-command-history
2625 '((name . "Complex Command History")
2626 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
2627 (type . sexp)))
2628 ;; (anything 'anything-c-source-complex-command-history)
2630 ;;; M-x history
2631 (defvar anything-c-source-extended-command-history
2632 '((name . "Emacs Commands History")
2633 (candidates . extended-command-history)
2634 (type . command)))
2635 ;; (anything 'anything-c-source-extended-command-history)
2637 ;;; Emacs commands
2638 (defvar anything-c-source-emacs-commands
2639 '((name . "Emacs Commands")
2640 (candidates . (lambda ()
2641 (let (commands)
2642 (mapatoms (lambda (a)
2643 (if (commandp a)
2644 (push (symbol-name a)
2645 commands))))
2646 (sort commands 'string-lessp))))
2647 (type . command)
2648 (requires-pattern . 2))
2649 "Source for completing and invoking Emacs commands.
2650 A command is a function with interactive spec that can
2651 be invoked with `M-x'.
2653 To get non-interactive functions listed, use
2654 `anything-c-source-emacs-functions'.")
2655 ;; (anything 'anything-c-source-emacs-commands)
2657 ;; Another replacement of `M-x' that act exactly like the
2658 ;; vanilla Emacs one, no problem of windows configuration, prefix args
2659 ;; are passed before calling `M-x' (e.g C-u M-x..).
2660 ;;;###autoload
2661 (defun anything-M-x ()
2662 "Preconfigured `anything' for Emacs commands.
2663 It is `anything' replacement of regular `M-x' `execute-extended-command'."
2664 (interactive)
2665 (let ((command (anything-comp-read "M-x " obarray
2666 :test 'commandp
2667 :must-match t
2668 :requires-pattern 2)))
2669 (call-interactively (intern command))))
2671 ;;; LaCarte
2672 (defvar anything-c-source-lacarte
2673 '((name . "Lacarte")
2674 (init . (lambda () (require 'lacarte )))
2675 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2676 (candidate-number-limit . 9999)
2677 (action . anything-c-call-interactively))
2678 "Needs lacarte.el.
2680 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2681 ;; (anything 'anything-c-source-lacarte)
2683 ;;;; <Function>
2684 ;;; Emacs functions
2685 (defvar anything-c-source-emacs-functions
2686 '((name . "Emacs Functions")
2687 (candidates . (lambda ()
2688 (let (commands)
2689 (mapatoms (lambda (a)
2690 (if (functionp a)
2691 (push (symbol-name a) commands))))
2692 (sort commands 'string-lessp))))
2693 (type . function)
2694 (requires-pattern . 2))
2695 "Source for completing Emacs functions.")
2696 ;; (anything 'anything-c-source-emacs-functions)
2698 ;;; With abbrev expansion
2699 ;;; Similar to my exec-abbrev-cmd.el
2700 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2701 (defvar anything-c-function-abbrev-regexp nil
2702 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2703 Regexp built from the current `anything-pattern' interpreting it
2704 as abbreviation.
2705 Only for internal use.")
2707 (defun anything-c-match-function-by-abbrev (candidate)
2708 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2710 Abbreviations are made by taking the first character from each
2711 word in the function's name, e.g. \"bb\" is an abbrev for
2712 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2713 (string-match anything-c-function-abbrev-regexp candidate))
2715 (defvar anything-c-source-emacs-functions-with-abbrevs
2716 (append anything-c-source-emacs-functions
2717 '((match anything-c-match-function-by-abbrev
2718 anything-c-string-match))
2719 '((init
2720 . (lambda ()
2721 (defadvice anything-update
2722 (before anything-c-update-function-abbrev-regexp activate)
2723 (let ((char-list (append anything-pattern nil))
2724 (str "^"))
2725 (dolist (c char-list)
2726 (setq str (concat str (list c) "[^-]*-")))
2727 (setq str (concat (substring str 0 (1- (length str))) "$"))
2728 (setq anything-c-function-abbrev-regexp str))))))))
2729 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2731 (defvar anything-c-source-advice
2732 '((name . "Function Advice")
2733 (candidates . anything-c-advice-candidates)
2734 (action ("Toggle Enable/Disable" . anything-c-advice-toggle))
2735 ;; (real-to-display . anything-c-advice-real-to-display)
2738 (persistent-action . anything-c-advice-persistent-action)
2739 (persistent-help . "Describe function / C-u C-z: Toggle advice")))
2740 ;; (anything 'anything-c-source-advice)
2741 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
2742 ;; (testadvice)
2744 (defun anything-c-advice-candidates ()
2745 (require 'advice)
2746 (loop for (fname) in ad-advised-functions
2747 for function = (intern fname)
2748 append
2749 (loop for class in ad-advice-classes append
2750 (loop for advice in (ad-get-advice-info-field function class)
2751 for enabled = (ad-advice-enabled advice)
2752 collect
2753 (cons (format
2754 "%s %s %s"
2755 (if enabled "Enabled " "Disabled")
2756 (propertize fname 'face 'font-lock-function-name-face)
2757 (ad-make-single-advice-docstring advice class nil))
2758 (list function class advice))))))
2760 (defun anything-c-advice-persistent-action (func-class-advice)
2761 (if current-prefix-arg
2762 (anything-c-advice-toggle func-class-advice)
2763 (describe-function (car func-class-advice))))
2765 (defun anything-c-advice-toggle (func-class-advice)
2766 (destructuring-bind (function class advice) func-class-advice
2767 (cond ((ad-advice-enabled advice)
2768 (ad-advice-set-enabled advice nil)
2769 (message "Disabled"))
2770 (t ;disabled
2771 (ad-advice-set-enabled advice t)
2772 (message "Enabled")))
2773 (ad-activate function)
2774 (and anything-in-persistent-action
2775 (anything-c-advice-update-current-display-string))))
2777 (defun anything-c-advice-update-current-display-string ()
2778 (anything-edit-current-selection
2779 (let ((newword (cond ((looking-at "Disabled") "Enabled")
2780 ((looking-at "Enabled") "Disabled")))
2781 realvalue)
2782 (when newword
2783 (delete-region (point) (progn (forward-word 1) (point)))
2784 (insert newword)))))
2786 ;;;###autoload
2787 (defun anything-manage-advice ()
2788 "Preconfigured `anything' to disable/enable function advices."
2789 (interactive)
2790 (anything-other-buffer 'anything-c-source-advice "*anything advice*"))
2792 ;;;; <Variable>
2793 ;;; Emacs variables
2794 (defvar anything-c-source-emacs-variables
2795 '((name . "Emacs Variables")
2796 (candidates . (lambda ()
2797 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
2798 (type . variable)
2799 (requires-pattern . 2))
2800 "Source for completing Emacs variables.")
2801 ;; (anything 'anything-c-source-emacs-variables)
2803 ;;;; <Bookmark>
2804 ;;; Bookmarks
2805 (eval-when-compile (require 'bookmark))
2806 (defvar anything-c-source-bookmarks
2807 '((name . "Bookmarks")
2808 (init . (lambda ()
2809 (require 'bookmark)))
2810 (candidates . bookmark-all-names)
2811 (type . bookmark))
2812 "See (info \"(emacs)Bookmarks\").")
2813 ;; (anything 'anything-c-source-bookmarks)
2815 ;;; bookmark-set
2816 (defvar anything-c-source-bookmark-set
2817 '((name . "Set Bookmark")
2818 (dummy)
2819 (action . bookmark-set))
2820 "See (info \"(emacs)Bookmarks\").")
2821 ;; (anything 'anything-c-source-bookmark-set)
2823 ;;; Visible Bookmarks
2824 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2827 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2828 (defvar anything-c-source-bm
2829 '((name . "Visible Bookmarks")
2830 (init . anything-c-bm-init)
2831 (candidates-in-buffer)
2832 (type . line))
2833 "Needs bm.el.
2835 http://www.nongnu.org/bm/")
2837 (defun anything-c-bm-init ()
2838 "Init function for `anything-c-source-bm'."
2839 (when (require 'bm nil t)
2840 (with-no-warnings
2841 (let ((bookmarks (bm-lists))
2842 (buf (anything-candidate-buffer 'global)))
2843 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
2844 '< :key 'overlay-start))
2845 (let ((start (overlay-start bm))
2846 (end (overlay-end bm))
2847 (annotation (or (overlay-get bm 'annotation) "")))
2848 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
2849 (let ((str (format "%5d: [%s]: %s\n"
2850 (line-number-at-pos start)
2851 annotation
2852 (buffer-substring start (1- end)))))
2853 (with-current-buffer buf (insert str))))))))))
2855 ;;; Special bookmarks
2856 (defvar anything-c-source-bookmarks-ssh
2857 '((name . "Bookmarks-ssh")
2858 (init . (lambda ()
2859 (require 'bookmark)))
2860 (candidates . (lambda () (anything-c-collect-bookmarks :ssh t)))
2861 (type . bookmark))
2862 "See (info \"(emacs)Bookmarks\").")
2863 ;; (anything 'anything-c-source-bookmarks-ssh)
2865 (defvar anything-c-source-bookmarks-su
2866 '((name . "Bookmarks-root")
2867 (init . (lambda ()
2868 (require 'bookmark)))
2869 (candidates . (lambda () (anything-c-collect-bookmarks :su t)))
2870 (filtered-candidate-transformer anything-c-highlight-bookmark-su)
2872 (type . bookmark))
2873 "See (info \"(emacs)Bookmarks\").")
2874 ;; (anything 'anything-c-source-bookmarks-su)
2876 (defvar anything-c-source-bookmarks-local
2877 '((name . "Bookmarks-Local")
2878 (init . (lambda ()
2879 (require 'bookmark)))
2880 (candidates . (lambda () (anything-c-collect-bookmarks :local t)))
2881 (filtered-candidate-transformer
2882 anything-c-adaptive-sort
2883 anything-c-highlight-bookmark)
2884 (type . bookmark))
2885 "See (info \"(emacs)Bookmarks\").")
2886 ;; (anything 'anything-c-source-bookmarks-local)
2888 (defun* anything-c-collect-bookmarks (&key local su sudo ssh)
2889 (let* ((lis-all (bookmark-all-names))
2890 (lis-loc (cond (local (loop for i in lis-all
2891 unless (string-match "^(ssh)\\|^(su)" i)
2892 collect i))
2893 (su (loop for i in lis-all
2894 when (string-match "^(su)" i)
2895 collect i))
2896 (sudo (loop for i in lis-all
2897 when (string-match "^(sudo)" i)
2898 collect i))
2899 (ssh (loop for i in lis-all
2900 when (string-match "^(ssh)" i)
2901 collect i)))))
2902 (sort lis-loc 'string-lessp)))
2904 (defun anything-c-bookmark-root-logged-p ()
2905 (catch 'break
2906 (dolist (i (mapcar #'buffer-name (buffer-list)))
2907 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
2908 (throw 'break t)))))
2910 (defun anything-c-highlight-bookmark-su (files source)
2911 (if (anything-c-bookmark-root-logged-p)
2912 (anything-c-highlight-bookmark files source)
2913 (anything-c-highlight-not-logged files source)))
2915 (defun anything-c-highlight-not-logged (files source)
2916 (loop for i in files
2917 collect (propertize i 'face anything-c-bookmarks-face3)))
2919 (defun anything-c-highlight-bookmark (bookmarks source)
2920 "Used as `candidate-transformer' to colorize bookmarks.
2921 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2922 (loop for i in bookmarks
2923 for pred = (bookmark-get-filename i)
2924 for bufp = (and (fboundp 'bmkext-get-buffer-name)
2925 (bmkext-get-buffer-name i))
2926 for handlerp = (and (fboundp 'bookmark-get-handler)
2927 (bookmark-get-handler i))
2928 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
2929 (bmkext-w3m-bookmark-p i))
2930 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
2931 (bmkext-gnus-bookmark-p i))
2932 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
2933 (bmkext-man-bookmark-p i))
2934 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
2935 (bmkext-woman-bookmark-p i))
2936 for handlerp = (bookmark-get-handler i)
2937 for isannotation = (bookmark-get-annotation i)
2938 for isabook = (string= (bookmark-prop-get i 'type) "addressbook")
2939 ;; Add a * if bookmark have annotation
2940 if (and isannotation (not (string-equal isannotation "")))
2941 do (setq i (concat "*" i))
2942 ;; info buffers
2943 if (eq handlerp 'Info-bookmark-jump)
2944 collect (propertize i 'face 'anything-bmkext-info 'help-echo pred)
2945 ;; w3m buffers
2946 if isw3m
2947 collect (propertize i 'face 'anything-bmkext-w3m 'help-echo pred)
2948 ;; gnus buffers
2949 if isgnus
2950 collect (propertize i 'face 'anything-bmkext-gnus 'help-echo pred)
2951 ;; Man Woman
2952 if (or iswoman isman)
2953 collect (propertize i 'face 'anything-bmkext-man 'help-echo pred)
2954 ;; Addressbook
2955 if (and (not pred) isabook)
2956 collect (propertize i 'face '((:foreground "Tomato")))
2957 ;; directories
2958 if (and pred (file-directory-p pred))
2959 collect (propertize i 'face anything-c-bookmarks-face1 'help-echo pred)
2960 ;; regular files
2961 if (and pred (not (file-directory-p pred)) (file-exists-p pred)
2962 (not (or iswoman isman)))
2963 collect (propertize i 'face 'anything-bmkext-file 'help-echo pred)))
2966 ;;; Faces for bookmarks
2967 (defface anything-bmkext-info
2968 '((t (:foreground "green")))
2969 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2970 :group 'anything)
2972 (defface anything-bmkext-w3m
2973 '((t (:foreground "yellow")))
2974 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2975 :group 'anything)
2977 (defface anything-bmkext-gnus
2978 '((t (:foreground "magenta")))
2979 "*Face used for Gnus bookmarks."
2980 :group 'anything)
2982 (defface anything-bmkext-man
2983 '((t (:foreground "Orange4")))
2984 "*Face used for Woman/man bookmarks."
2985 :group 'anything)
2987 (defface anything-bmkext-no--file
2988 '((t (:foreground "grey")))
2989 "*Face used for non--file bookmarks."
2990 :group 'anything)
2992 (defface anything-bmkext-file
2993 '((t (:foreground "Deepskyblue2")))
2994 "*Face used for non--file bookmarks."
2995 :group 'anything)
2997 (defface anything-bookmarks-su-face '((t (:foreground "red")))
2998 "Face for su/sudo bookmarks."
2999 :group 'anything)
3001 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
3002 (defvar anything-c-bookmarks-face2 'anything-file-name)
3003 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
3006 ;;; Sources to filter bookmark-extensions bookmarks.
3007 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3008 ;; If you want to enable google-maps in addressbook you will need
3009 ;; Julien Danjou google-maps-el package available here:
3010 ;; http://julien.danjou.info/google-maps-el.html
3012 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
3013 "Return a filtered `bookmark-alist' sorted alphabetically."
3014 (loop
3015 with alist = (if args
3016 (apply #'(lambda (x) (funcall fn x)) args)
3017 (funcall fn))
3018 for i in alist
3019 for b = (car i)
3020 collect b into sa
3021 finally return (sort sa 'string-lessp)))
3023 ;; Addressbook
3024 (defvar anything-c-source-bmkext-addressbook
3025 '((name . "Bookmark Addressbook")
3026 (init . (lambda ()
3027 (require 'bookmark-extensions)
3028 (bookmark-maybe-load-default-file)))
3029 (candidates . anything-c-bmkext-addressbook-setup-alist)
3030 (persistent-action
3031 . (lambda (candidate)
3032 (let ((bmk (anything-bookmark-get-bookmark-from-name
3033 candidate)))
3034 (bookmark--jump-via bmk 'pop-to-buffer))))
3035 (persistent-help . "Show contact - Prefix with C-u to append")
3036 (filtered-candidate-transformer
3037 anything-c-adaptive-sort
3038 anything-c-highlight-bookmark)
3039 (action . (("Show person's data"
3040 . (lambda (candidate)
3041 (let ((bmk (anything-bookmark-get-bookmark-from-name
3042 candidate))
3043 (current-prefix-arg anything-current-prefix-arg))
3044 (bookmark-jump bmk))))
3045 ("Send Mail"
3046 . (lambda (candidate)
3047 (let ((bmk (anything-bookmark-get-bookmark-from-name
3048 candidate)))
3049 (if anything-current-prefix-arg
3050 (addressbook-set-mail-buffer1 bmk 'append)
3051 (addressbook-set-mail-buffer1 bmk)))))
3052 ("Edit Bookmark"
3053 . (lambda (candidate)
3054 (let ((bmk (anything-bookmark-get-bookmark-from-name
3055 candidate)))
3056 (addressbook-bookmark-edit
3057 (assoc bmk bookmark-alist)))))
3058 ("Insert Email at point"
3059 . (lambda (candidate)
3060 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3061 candidate))
3062 (mlist (split-string
3063 (assoc-default
3064 'email (assoc bmk bookmark-alist))
3065 ", ")))
3066 (insert
3067 (if (> (length mlist) 1)
3068 (anything-comp-read
3069 "Insert Mail Address: " mlist :must-match t)
3070 (car mlist))))))
3071 ("Show annotation"
3072 . (lambda (candidate)
3073 (let ((bmk (anything-bookmark-get-bookmark-from-name
3074 candidate)))
3075 (bookmark-show-annotation bmk))))
3076 ("Edit annotation"
3077 . (lambda (candidate)
3078 (let ((bmk (anything-bookmark-get-bookmark-from-name
3079 candidate)))
3080 (bookmark-edit-annotation bmk))))
3081 ("Show Google map"
3082 . (lambda (candidate)
3083 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3084 candidate))
3085 (full-bmk (assoc bmk bookmark-alist)))
3086 (addressbook-google-map full-bmk))))))))
3089 (defun anything-c-bmkext-addressbook-setup-alist ()
3090 "Specialized filter function for bookmarks w3m."
3091 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only))
3093 ;; W3m
3094 (defvar anything-c-source-bookmark-w3m
3095 '((name . "Bookmark W3m")
3096 (init . (lambda ()
3097 (require 'bookmark-extensions)
3098 (bookmark-maybe-load-default-file)))
3099 (candidates . anything-c-bookmark-w3m-setup-alist)
3100 (filtered-candidate-transformer
3101 anything-c-adaptive-sort
3102 anything-c-highlight-bookmark)
3103 (type . bookmark)))
3104 ;; (anything 'anything-c-source-bookmark-w3m)
3106 (defun anything-c-bookmark-w3m-setup-alist ()
3107 "Specialized filter function for bookmarks w3m."
3108 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
3110 ;; Images
3111 (defvar anything-c-source-bookmark-images
3112 '((name . "Bookmark Images")
3113 (init . (lambda ()
3114 (require 'bookmark-extensions)
3115 (bookmark-maybe-load-default-file)))
3116 (candidates . anything-c-bookmark-images-setup-alist)
3117 (filtered-candidate-transformer
3118 anything-c-adaptive-sort
3119 anything-c-highlight-bookmark)
3120 (type . bookmark)))
3121 ;; (anything 'anything-c-source-bookmark-images)
3123 (defun anything-c-bookmark-images-setup-alist ()
3124 "Specialized filter function for images bookmarks."
3125 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only))
3127 ;; Woman Man
3128 (defvar anything-c-source-bookmark-man
3129 '((name . "Bookmark Woman&Man")
3130 (init . (lambda ()
3131 (require 'bookmark-extensions)
3132 (bookmark-maybe-load-default-file)))
3133 (candidates . anything-c-bookmark-man-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-man)
3140 (defun anything-c-bookmark-man-setup-alist ()
3141 "Specialized filter function for bookmarks w3m."
3142 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
3143 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
3145 ;; Gnus
3146 (defvar anything-c-source-bookmark-gnus
3147 '((name . "Bookmark Gnus")
3148 (init . (lambda ()
3149 (require 'bookmark-extensions)
3150 (bookmark-maybe-load-default-file)))
3151 (candidates . anything-c-bookmark-gnus-setup-alist)
3152 (filtered-candidate-transformer
3153 anything-c-adaptive-sort
3154 anything-c-highlight-bookmark)
3155 (type . bookmark)))
3156 ;; (anything 'anything-c-source-bookmark-gnus)
3158 (defun anything-c-bookmark-gnus-setup-alist ()
3159 "Specialized filter function for bookmarks gnus."
3160 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
3162 ;; Info
3163 (defvar anything-c-source-bookmark-info
3164 '((name . "Bookmark Info")
3165 (init . (lambda ()
3166 (require 'bookmark-extensions)
3167 (bookmark-maybe-load-default-file)))
3168 (candidates . anything-c-bookmark-info-setup-alist)
3169 (filtered-candidate-transformer
3170 anything-c-adaptive-sort
3171 anything-c-highlight-bookmark)
3172 (type . bookmark)))
3173 ;; (anything 'anything-c-source-bookmark-info)
3175 (defun anything-c-bookmark-info-setup-alist ()
3176 "Specialized filter function for bookmarks info."
3177 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
3179 ;; Local Files&directories
3180 (defvar anything-c-source-bookmark-files&dirs
3181 '((name . "Bookmark Files&Directories")
3182 (init . (lambda ()
3183 (require 'bookmark-extensions)
3184 (bookmark-maybe-load-default-file)))
3185 (candidates . anything-c-bookmark-local-files-setup-alist)
3186 (filtered-candidate-transformer
3187 anything-c-adaptive-sort
3188 anything-c-highlight-bookmark)
3189 (type . bookmark)))
3190 ;; (anything 'anything-c-source-bookmark-files&dirs)
3192 (defun anything-c-bookmark-local-files-setup-alist ()
3193 "Specialized filter function for bookmarks locals files."
3194 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
3196 ;; Su Files&directories
3197 (defvar anything-c-source-bookmark-su-files&dirs
3198 '((name . "Bookmark Root-Files&Directories")
3199 (init . (lambda ()
3200 (require 'bookmark-extensions)
3201 (bookmark-maybe-load-default-file)))
3202 (candidates . anything-c-bookmark-su-files-setup-alist)
3203 (filtered-candidate-transformer
3204 anything-c-adaptive-sort
3205 anything-c-highlight-bookmark-su)
3206 (type . bookmark)))
3207 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3209 (defun anything-c-bookmark-su-files-setup-alist ()
3210 "Specialized filter function for bookmarks su/sudo files."
3211 (loop
3212 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3213 for i in l
3214 for isfile = (bookmark-get-filename i)
3215 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3216 (save-match-data
3217 (string-match tramp-file-name-regexp isfile)))
3218 for issu = (and istramp
3219 (string-match bmkext-su-or-sudo-regexp isfile))
3220 if issu
3221 collect i))
3223 ;; Ssh Files&directories
3224 (defvar anything-c-source-bookmark-ssh-files&dirs
3225 '((name . "Bookmark Ssh-Files&Directories")
3226 (init . (lambda ()
3227 (require 'bookmark-extensions)
3228 (bookmark-maybe-load-default-file)))
3229 (candidates . anything-c-bookmark-ssh-files-setup-alist)
3230 (filtered-candidate-transformer . anything-c-adaptive-sort)
3231 (type . bookmark)))
3232 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3234 (defun anything-c-bookmark-ssh-files-setup-alist ()
3235 "Specialized filter function for bookmarks ssh files."
3236 (loop
3237 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
3238 for i in l
3239 for isfile = (bookmark-get-filename i)
3240 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
3241 (save-match-data
3242 (string-match tramp-file-name-regexp isfile)))
3243 for isssh = (and istramp
3244 (string-match "/ssh:" isfile))
3245 if isssh
3246 collect i))
3249 ;; All bookmark-extensions sources.
3250 ;;;###autoload
3251 (defun anything-bookmark-ext ()
3252 "Preconfigured `anything' for bookmark-extensions sources.
3253 Needs bookmark-ext.el
3255 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3256 (interactive)
3257 (anything '(anything-c-source-bookmark-files&dirs
3258 anything-c-source-bookmark-w3m
3259 anything-c-source-bmkext-addressbook
3260 anything-c-source-bookmark-gnus
3261 anything-c-source-bookmark-info
3262 anything-c-source-bookmark-man
3263 anything-c-source-bookmark-images
3264 anything-c-source-bookmark-su-files&dirs
3265 anything-c-source-bookmark-ssh-files&dirs)
3266 nil "SearchBookmark: " nil nil "*anything bmkext*"))
3269 ;; Firefox bookmarks
3270 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
3271 ;; (only for firefox versions >=3)
3272 ;; To achieve that, open about:config in firefox and double click on this line to enable value
3273 ;; to true:
3274 ;; user_pref("browser.bookmarks.autoExportHTML", false);
3275 ;; You should have now:
3276 ;; user_pref("browser.bookmarks.autoExportHTML", true);
3278 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
3279 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3281 (defun anything-get-firefox-user-init-dir ()
3282 "Guess the default Firefox user directory name."
3283 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
3284 (moz-user-dir
3285 (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
3286 (goto-char (point-min))
3287 (when (search-forward "Path=" nil t)
3288 (buffer-substring-no-properties (point) (point-at-eol))))))
3289 (file-name-as-directory (concat moz-dir moz-user-dir))))
3291 (defun anything-guess-firefox-bookmark-file ()
3292 "Return the path of the Firefox bookmarks file."
3293 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
3295 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
3296 "Parse html bookmark FILE and return an alist with (title . url) as elements."
3297 (let (bookmarks-alist url title)
3298 (with-temp-buffer
3299 (insert-file-contents file)
3300 (goto-char (point-min))
3301 (while (not (eobp))
3302 (forward-line)
3303 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
3304 (beginning-of-line)
3305 (when (re-search-forward url-regexp nil t)
3306 (setq url (concat "\"" (match-string 0))))
3307 (beginning-of-line)
3308 (when (re-search-forward bmk-regexp nil t)
3309 (setq title (match-string 1)))
3310 (push (cons title url) bookmarks-alist))))
3311 (nreverse bookmarks-alist)))
3314 (defvar anything-c-firefox-bookmarks-alist nil)
3315 (defvar anything-c-source-firefox-bookmarks
3316 '((name . "Firefox Bookmarks")
3317 (init . (lambda ()
3318 (setq anything-c-firefox-bookmarks-alist
3319 (anything-html-bookmarks-to-alist
3320 (anything-guess-firefox-bookmark-file)
3321 anything-firefox-bookmark-url-regexp
3322 anything-firefox-bookmarks-regexp))))
3323 (candidates . (lambda ()
3324 (mapcar #'car
3325 anything-c-firefox-bookmarks-alist)))
3326 (filtered-candidate-transformer
3327 anything-c-adaptive-sort
3328 anything-c-highlight-firefox-bookmarks)
3329 (action . (("Browse Url Firefox" . (lambda (candidate)
3330 (browse-url-firefox
3331 (anything-c-firefox-bookmarks-get-value candidate))))
3332 ("Browse Url w3m" . (lambda (candidate)
3333 (w3m-browse-url
3334 (anything-c-firefox-bookmarks-get-value candidate))))
3335 ("Copy Url" . (lambda (elm)
3336 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
3338 ;; (anything 'anything-c-source-firefox-bookmarks)
3340 (defun anything-c-firefox-bookmarks-get-value (elm)
3341 (replace-regexp-in-string "\"" ""
3342 (cdr (assoc elm
3343 anything-c-firefox-bookmarks-alist))))
3346 (defun anything-c-highlight-firefox-bookmarks (bookmarks source)
3347 (loop for i in bookmarks
3348 collect (propertize i
3349 'face '((:foreground "YellowGreen"))
3350 'help-echo (anything-c-firefox-bookmarks-get-value i))))
3352 ;; W3m bookmark
3353 (eval-when-compile (require 'w3m-bookmark nil t))
3354 (unless (and (require 'w3m nil t)
3355 (require 'w3m-bookmark nil t))
3356 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
3359 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
3360 "Face for w3m bookmarks" :group 'anything)
3362 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
3363 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
3364 (defvar anything-c-w3m-bookmarks-alist nil)
3365 (defvar anything-c-source-w3m-bookmarks
3366 '((name . "W3m Bookmarks")
3367 (init . (lambda ()
3368 (setq anything-c-w3m-bookmarks-alist
3369 (anything-html-bookmarks-to-alist
3370 w3m-bookmark-file
3371 anything-w3m-bookmark-url-regexp
3372 anything-w3m-bookmarks-regexp))))
3373 (candidates . (lambda ()
3374 (mapcar #'car anything-c-w3m-bookmarks-alist)))
3375 (filtered-candidate-transformer
3376 anything-c-adaptive-sort
3377 anything-c-highlight-w3m-bookmarks)
3378 (action . (("Browse Url" . (lambda (candidate)
3379 (anything-c-w3m-browse-bookmark candidate)))
3380 ("Copy Url" . (lambda (elm)
3381 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
3382 ("Browse Url Firefox" . (lambda (candidate)
3383 (anything-c-w3m-browse-bookmark candidate t)))
3384 ("Delete Bookmark" . (lambda (candidate)
3385 (anything-c-w3m-delete-bookmark candidate)))
3386 ("Rename Bookmark" . (lambda (candidate)
3387 (anything-c-w3m-rename-bookmark candidate)))))
3388 (persistent-action . (lambda (candidate)
3389 (if current-prefix-arg
3390 (anything-c-w3m-browse-bookmark candidate t)
3391 (anything-c-w3m-browse-bookmark candidate nil t))))
3392 (persistent-help . "Open URL with emacs-w3m in new tab / \
3393 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
3394 "Needs w3m and emacs-w3m.
3396 http://w3m.sourceforge.net/
3397 http://emacs-w3m.namazu.org/")
3399 ;; (anything 'anything-c-source-w3m-bookmarks)
3401 (defun anything-c-w3m-bookmarks-get-value (elm)
3402 (replace-regexp-in-string
3403 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
3405 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
3406 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
3407 (arg (and (eq fn 'w3m-browse-url) new-tab)))
3408 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
3410 (defun anything-c-highlight-w3m-bookmarks (bookmarks source)
3411 (loop for i in bookmarks
3412 collect (propertize
3413 i 'face 'anything-w3m-bookmarks-face
3414 'help-echo (anything-c-w3m-bookmarks-get-value i))))
3417 (defun anything-c-w3m-delete-bookmark (elm)
3418 (save-excursion
3419 (find-file-literally w3m-bookmark-file)
3420 (goto-char (point-min))
3421 (when (re-search-forward elm nil t)
3422 (beginning-of-line)
3423 (delete-region (point)
3424 (line-end-position))
3425 (delete-blank-lines))
3426 (save-buffer (current-buffer))
3427 (kill-buffer (current-buffer))))
3429 (defun anything-c-w3m-rename-bookmark (elm)
3430 (let* ((old-title (replace-regexp-in-string ">" "" elm))
3431 (new-title (read-string "NewTitle: " old-title)))
3432 (save-excursion
3433 (find-file-literally w3m-bookmark-file)
3434 (goto-char (point-min))
3435 (when (re-search-forward (concat elm "<") nil t)
3436 (goto-char (1- (point)))
3437 (delete-char (- (length old-title)))
3438 (insert new-title))
3439 (save-buffer (current-buffer))
3440 (kill-buffer (current-buffer)))))
3442 ;;;; <Library>
3443 ;;; Elisp library scan
3444 (defvar anything-c-source-elisp-library-scan
3445 '((name . "Elisp libraries (Scan)")
3446 (init . (anything-c-elisp-library-scan-init))
3447 (candidates-in-buffer)
3448 (action ("Find library" . (lambda (candidate)
3449 (find-file (find-library-name candidate))))
3450 ("Find library other window" . (lambda (candidate)
3451 (find-file-other-window (find-library-name candidate))))
3452 ("Load library" . (lambda (candidate)
3453 (load-library candidate))))))
3454 ;; (anything 'anything-c-source-elisp-library-scan)
3456 (defun anything-c-elisp-library-scan-init ()
3457 "Init anything buffer status."
3458 (let ((anything-buffer (anything-candidate-buffer 'global))
3459 (library-list (anything-c-elisp-library-scan-list)))
3460 (with-current-buffer anything-buffer
3461 (dolist (library library-list)
3462 (insert (format "%s\n" library))))))
3464 (defun anything-c-elisp-library-scan-list (&optional dirs string)
3465 "Do completion for file names passed to `locate-file'.
3466 DIRS is directory to search path.
3467 STRING is string to match."
3468 ;; Use `load-path' as path when ignore `dirs'.
3469 (or dirs (setq dirs load-path))
3470 ;; Init with blank when ignore `string'.
3471 (or string (setq string ""))
3472 ;; Get library list.
3473 (let ((string-dir (file-name-directory string))
3474 ;; File regexp that suffix match `load-file-rep-suffixes'.
3475 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
3476 name
3477 names)
3478 (dolist (dir dirs)
3479 (unless dir
3480 (setq dir default-directory))
3481 (if string-dir
3482 (setq dir (expand-file-name string-dir dir)))
3483 (when (file-directory-p dir)
3484 (dolist (file (file-name-all-completions
3485 (file-name-nondirectory string) dir))
3486 ;; Suffixes match `load-file-rep-suffixes'.
3487 (setq name (if string-dir (concat string-dir file) file))
3488 (if (string-match match-regexp name)
3489 (add-to-list 'names name)))))
3490 names))
3492 ;;;; <Programming>
3493 ;;; Imenu
3494 (defvar anything-c-imenu-delimiter " / ")
3496 (defvar anything-c-imenu-index-filter nil)
3497 (make-variable-buffer-local 'anything-c-imenu-index-filter)
3499 (defvar anything-c-cached-imenu-alist nil)
3500 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
3502 (defvar anything-c-cached-imenu-candidates nil)
3503 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
3505 (defvar anything-c-cached-imenu-tick nil)
3506 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
3508 (eval-when-compile (require 'imenu))
3509 (setq imenu-auto-rescan t)
3511 (defun anything-imenu-create-candidates (entry)
3512 "Create candidates with ENTRY."
3513 (if (listp (cdr entry))
3514 (mapcan (lambda (sub)
3515 (if (consp (cdr sub))
3516 (mapcar
3517 (lambda (subentry)
3518 (concat (car entry) anything-c-imenu-delimiter subentry))
3519 (anything-imenu-create-candidates sub))
3520 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
3521 (cdr entry))
3522 (list entry)))
3524 (defvar anything-c-source-imenu
3525 '((name . "Imenu")
3526 (init . (lambda () (require 'imenu)))
3527 (candidates . anything-c-imenu-candidates)
3528 (persistent-action . (lambda (elm)
3529 (anything-c-imenu-default-action elm)
3530 (unless (fboundp 'semantic-imenu-tag-overlay)
3531 (anything-match-line-color-current-line))))
3532 (persistent-help . "Show this entry")
3533 (action . anything-c-imenu-default-action))
3534 "See (info \"(emacs)Imenu\")")
3536 ;; (anything 'anything-c-source-imenu)
3538 (defun anything-c-imenu-candidates ()
3539 (with-current-buffer anything-current-buffer
3540 (let ((tick (buffer-modified-tick)))
3541 (if (eq anything-c-cached-imenu-tick tick)
3542 anything-c-cached-imenu-candidates
3543 (setq imenu--index-alist nil)
3544 (setq anything-c-cached-imenu-tick tick
3545 anything-c-cached-imenu-candidates
3546 (ignore-errors
3547 (mapcan
3548 'anything-imenu-create-candidates
3549 (setq anything-c-cached-imenu-alist
3550 (let ((index (imenu--make-index-alist)))
3551 (if anything-c-imenu-index-filter
3552 (funcall anything-c-imenu-index-filter index)
3553 index))))))
3554 (setq anything-c-cached-imenu-candidates
3555 (mapcar #'(lambda (x)
3556 (if (stringp x)
3558 (car x)))
3559 anything-c-cached-imenu-candidates))))))
3561 (setq imenu-default-goto-function 'imenu-default-goto-function)
3562 (defun anything-c-imenu-default-action (elm)
3563 "The default action for `anything-c-source-imenu'."
3564 (let ((path (split-string elm anything-c-imenu-delimiter))
3565 (alist anything-c-cached-imenu-alist))
3566 (if (> (length path) 1)
3567 (progn
3568 (setq alist (assoc (car path) alist))
3569 (setq elm (cadr path))
3570 (imenu (assoc elm alist)))
3571 (imenu (assoc elm alist)))))
3573 ;;; Ctags
3574 (defvar anything-c-ctags-modes
3575 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3576 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3577 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
3579 (defun anything-c-source-ctags-init ()
3580 (when (and buffer-file-name
3581 (memq major-mode anything-c-ctags-modes)
3582 (anything-current-buffer-is-modified))
3583 (with-current-buffer (anything-candidate-buffer 'local)
3584 (call-process-shell-command
3585 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
3586 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
3587 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
3588 nil (current-buffer))
3589 (goto-char (point-min))
3590 (forward-line 2)
3591 (delete-region (point-min) (point))
3592 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
3593 for lineno-start = (point)
3594 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
3596 (beginning-of-line)
3597 (insert (format "%5s:" lineno))
3598 (search-forward "\177" (point-at-eol) t)
3599 (delete-region (1- (point)) (point-at-eol))
3600 (forward-line 1)))))
3602 (defvar anything-c-source-ctags
3603 '((name . "Exuberant ctags")
3604 (init . anything-c-source-ctags-init)
3605 (candidates-in-buffer)
3606 (adjust)
3607 (type . line))
3608 "Needs Exuberant Ctags.
3610 http://ctags.sourceforge.net/")
3611 ;; (anything 'anything-c-source-ctags)
3613 ;; Semantic
3614 (eval-when-compile (require 'semantic nil t))
3615 (declare-function semantic-format-tag-summarize "ext:format.el" (tag &optional parent color) t)
3616 (declare-function semantic-tag-components "ext:tag.el" (tag) t)
3617 (declare-function semantic-go-to-tag "ext:tag-file.el" (tag) t)
3618 (defvar anything-semantic-candidates nil)
3620 (defun anything-semantic-construct-candidates (tags depth)
3621 (when (require 'semantic nil t)
3622 (apply 'append
3623 (mapcar (lambda (tag)
3624 (if (listp tag)
3625 (let ((type (semantic-tag-type tag))
3626 (class (semantic-tag-class tag)))
3627 (if (or (and (stringp type)
3628 (or (string= type "class")
3629 (string= type "namespace")))
3630 (eq class 'function)
3631 (eq class 'variable))
3632 (cons (cons (concat (make-string (* depth 2) ?\s)
3633 (semantic-format-tag-summarize tag nil t)) tag)
3634 (anything-semantic-construct-candidates (semantic-tag-components tag)
3635 (1+ depth)))))))
3636 tags))))
3638 (defun anything-semantic-default-action (candidate)
3639 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
3640 (semantic-go-to-tag tag)))
3642 (defvar anything-c-source-semantic
3643 '((name . "Semantic Tags")
3644 (init . (lambda ()
3645 (setq anything-semantic-candidates
3646 (ignore-errors (anything-semantic-construct-candidates (semantic-fetch-tags) 0)))))
3647 (candidates . (lambda ()
3648 (if anything-semantic-candidates
3649 (mapcar 'car anything-semantic-candidates))))
3650 (persistent-action . (lambda (elm)
3651 (anything-semantic-default-action elm)
3652 (anything-match-line-color-current-line)))
3653 (persistent-help . "Show this entry")
3654 (action . anything-semantic-default-action)
3655 "Needs semantic in CEDET.
3657 http://cedet.sourceforge.net/semantic.shtml
3658 http://cedet.sourceforge.net/"))
3660 ;; (anything 'anything-c-source-semantic)
3662 ;;; Function is called by
3663 ;;;###autoload
3664 (defun anything-simple-call-tree ()
3665 "Preconfigured `anything' for simple-call-tree. List function relationships.
3667 Needs simple-call-tree.el.
3668 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
3669 (interactive)
3670 (anything-other-buffer
3671 '(anything-c-source-simple-call-tree-functions-callers
3672 anything-c-source-simple-call-tree-callers-functions)
3673 "*anything simple-call-tree*"))
3675 (defvar anything-c-source-simple-call-tree-functions-callers
3676 '((name . "Function is called by")
3677 (init . anything-c-simple-call-tree-functions-callers-init)
3678 (multiline)
3679 (candidates . anything-c-simple-call-tree-candidates)
3680 (persistent-action . anything-c-simple-call-tree-persistent-action)
3681 (persistent-help . "Show function definitions by rotation")
3682 (action ("Find definition selected by persistent-action" .
3683 anything-c-simple-call-tree-find-definition)))
3684 "Needs simple-call-tree.el.
3685 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3687 (defvar anything-c-simple-call-tree-tick nil)
3688 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
3689 (defun anything-c-simple-call-tree-analyze-maybe ()
3690 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
3691 (simple-call-tree-analyze)
3692 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
3694 (defun anything-c-simple-call-tree-init-base (function message)
3695 (require 'simple-call-tree)
3696 (with-no-warnings
3697 (when (anything-current-buffer-is-modified)
3698 (anything-c-simple-call-tree-analyze-maybe)
3699 (let ((list (funcall function simple-call-tree-alist)))
3700 (with-current-buffer (anything-candidate-buffer 'local)
3701 (dolist (entry list)
3702 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
3703 (insert (car entry) message
3704 (if (string= funcs " ")
3705 " no functions."
3706 funcs)
3707 "\n\n"))))))))
3709 (defun anything-c-simple-call-tree-functions-callers-init ()
3710 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert " is called by\n"))
3712 (defun anything-c-simple-call-tree-candidates ()
3713 (with-current-buffer (anything-candidate-buffer)
3714 (split-string (buffer-string) "\n\n")))
3716 (defvar anything-c-simple-call-tree-related-functions nil)
3717 (defvar anything-c-simple-call-tree-function-index 0)
3718 (defun anything-c-simple-call-tree-persistent-action (candidate)
3719 (unless (eq last-command 'anything-execute-persistent-action)
3720 (setq anything-c-simple-call-tree-related-functions
3721 (delete "no functions."
3722 (split-string
3723 (replace-regexp-in-string " \\| is called by\\| calls " "" candidate)
3724 "\n")))
3725 (setq anything-c-simple-call-tree-function-index -1))
3726 (incf anything-c-simple-call-tree-function-index)
3727 (anything-c-simple-call-tree-find-definition candidate))
3729 (defun anything-c-simple-call-tree-find-definition (candidate)
3730 (find-function (intern
3731 (nth (mod anything-c-simple-call-tree-function-index
3732 (length anything-c-simple-call-tree-related-functions))
3733 anything-c-simple-call-tree-related-functions))))
3735 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3737 ;;; Function calls
3738 (defvar anything-c-source-simple-call-tree-callers-functions
3739 '((name . "Function calls")
3740 (init . anything-c-simple-call-tree-callers-functions-init)
3741 (multiline)
3742 (candidates . anything-c-simple-call-tree-candidates)
3743 (persistent-action . anything-c-simple-call-tree-persistent-action)
3744 (persistent-help . "Show function definitions by rotation")
3745 (action ("Find definition selected by persistent-action" .
3746 anything-c-simple-call-tree-find-definition)))
3747 "Needs simple-call-tree.el.
3748 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3750 (defun anything-c-simple-call-tree-callers-functions-init ()
3751 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
3753 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3755 ;;; Commands/Options with doc
3756 (defvar anything-c-auto-document-data nil)
3757 (make-variable-buffer-local 'anything-c-auto-document-data)
3758 (defvar anything-c-source-commands-and-options-in-file
3759 '((name . "Commands/Options in file")
3760 (header-name
3761 . (lambda (x) (format "Commands/Options in %s"
3762 (buffer-local-value 'buffer-file-name anything-current-buffer))))
3763 (candidates . anything-command-and-options-candidates)
3764 (multiline)
3765 (action . imenu))
3766 "List Commands and Options with doc. It needs auto-document.el .
3768 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3770 (eval-when-compile (require 'auto-document nil t))
3771 (defun anything-command-and-options-candidates ()
3772 (with-current-buffer anything-current-buffer
3773 (when (and (require 'auto-document nil t)
3774 (eq major-mode 'emacs-lisp-mode)
3775 (or (anything-current-buffer-is-modified)
3776 (not anything-c-auto-document-data)))
3777 (or imenu--index-alist (imenu--make-index-alist t))
3778 (setq anything-c-auto-document-data
3779 (destructuring-bind (commands options)
3780 (adoc-construct anything-current-buffer)
3781 (append
3782 (loop for (command . doc) in commands
3783 for cmdname = (symbol-name command)
3784 collect
3785 (cons (format "Command: %s\n %s"
3786 (propertize cmdname 'face font-lock-function-name-face)
3787 (adoc-first-line doc))
3788 (assoc cmdname imenu--index-alist)))
3789 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
3790 for (option doc default) in options
3791 for optname = (symbol-name option)
3792 collect
3793 (cons (format "Option: %s\n %s\n default = %s"
3794 (propertize optname 'face font-lock-variable-name-face)
3795 (adoc-first-line doc)
3796 (adoc-prin1-to-string default))
3797 (assoc optname
3798 var-alist)))))))
3799 anything-c-auto-document-data))
3801 ;; (anything 'anything-c-source-commands-and-options-in-file)
3803 ;;;; <Color and Face>
3804 ;;; Customize Face
3805 (defvar anything-c-source-customize-face
3806 '((name . "Customize Face")
3807 (init . (lambda ()
3808 (unless (anything-candidate-buffer)
3809 (save-window-excursion (list-faces-display))
3810 (anything-candidate-buffer (get-buffer "*Faces*")))))
3811 (candidates-in-buffer)
3812 (get-line . buffer-substring)
3813 (action . (lambda (line)
3814 (customize-face (intern (car (split-string line))))))
3815 (requires-pattern . 3))
3816 "See (info \"(emacs)Faces\")")
3817 ;; (anything 'anything-c-source-customize-face)
3819 ;; Color
3820 (defvar anything-c-source-colors
3821 '((name . "Colors")
3822 (init . (lambda () (unless (anything-candidate-buffer)
3823 (save-window-excursion (list-colors-display))
3824 (anything-candidate-buffer (get-buffer "*Colors*")))))
3825 (candidates-in-buffer)
3826 (get-line . buffer-substring)
3827 (action ("Copy Name" . (lambda (candidate)
3828 (kill-new (anything-c-colors-get-name candidate))))
3829 ("Copy RGB" . (lambda (candidate)
3830 (kill-new (anything-c-colors-get-rgb candidate))))
3831 ("Insert Name" . (lambda (candidate)
3832 (with-current-buffer anything-current-buffer
3833 (insert (anything-c-colors-get-name candidate)))))
3834 ("Insert RGB" . (lambda (candidate)
3835 (with-current-buffer anything-current-buffer
3836 (insert (anything-c-colors-get-rgb candidate))))))))
3837 ;; (anything 'anything-c-source-colors)
3839 (defun anything-c-colors-get-name (candidate)
3840 "Get color name."
3841 (replace-regexp-in-string
3842 " " ""
3843 (with-temp-buffer
3844 (insert (capitalize candidate))
3845 (goto-char (point-min))
3846 (search-forward-regexp "\\s-\\{2,\\}")
3847 (delete-region (point) (point-max))
3848 (buffer-string))))
3850 (defun anything-c-colors-get-rgb (candidate)
3851 "Get color RGB."
3852 (replace-regexp-in-string
3853 " " ""
3854 (with-temp-buffer
3855 (insert (capitalize candidate))
3856 (goto-char (point-max))
3857 (search-backward-regexp "\\s-\\{2,\\}")
3858 (delete-region (point) (point-min))
3859 (buffer-string))))
3861 ;;;; <Search Engine>
3862 ;;; Tracker desktop search
3863 (defvar anything-c-source-tracker-search
3864 '((name . "Tracker Search")
3865 (candidates . (lambda ()
3866 (start-process "tracker-search-process" nil
3867 "tracker-search"
3868 anything-pattern)))
3869 (type . file)
3870 (requires-pattern . 3)
3871 (delayed))
3872 "Source for retrieving files matching the current input pattern
3873 with the tracker desktop search.")
3874 ;; (anything 'anything-c-source-tracker-search)
3876 ;;; Spotlight (MacOS X desktop search)
3877 (defvar anything-c-source-mac-spotlight
3878 '((name . "mdfind")
3879 (candidates . (lambda ()
3880 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
3881 (type . file)
3882 (requires-pattern . 3)
3883 (delayed))
3884 "Source for retrieving files via Spotlight's command line
3885 utility mdfind.")
3886 ;; (anything 'anything-c-source-mac-spotlight)
3889 ;;;; <Kill ring>
3890 ;;; Kill ring
3891 (defvar anything-c-source-kill-ring
3892 '((name . "Kill Ring")
3893 (init . (lambda () (anything-attrset 'last-command last-command)))
3894 (candidates . anything-c-kill-ring-candidates)
3895 (action . anything-c-kill-ring-action)
3896 (last-command)
3897 (migemo)
3898 (multiline))
3899 "Source for browse and insert contents of kill-ring.")
3901 (defun anything-c-kill-ring-candidates ()
3902 (loop for kill in kill-ring
3903 unless (or (< (length kill) anything-kill-ring-threshold)
3904 (string-match "^[\\s\\t]+$" kill))
3905 collect kill))
3907 (defun anything-c-kill-ring-action (str)
3908 "Insert STR in `kill-ring' and set STR to the head.
3909 If this action is executed just after `yank', replace with STR as yanked string."
3910 (setq kill-ring (delete str kill-ring))
3911 (if (not (eq (anything-attr 'last-command) 'yank))
3912 (insert-for-yank str)
3913 ;; from `yank-pop'
3914 (let ((inhibit-read-only t)
3915 (before (< (point) (mark t))))
3916 (if before
3917 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
3918 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
3919 (setq yank-undo-function nil)
3920 (set-marker (mark-marker) (point) (current-buffer))
3921 (insert-for-yank str)
3922 ;; Set the window start back where it was in the yank command,
3923 ;; if possible.
3924 (set-window-start (selected-window) yank-window-start t)
3925 (if before
3926 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3927 ;; It is cleaner to avoid activation, even though the command
3928 ;; loop would deactivate the mark because we inserted text.
3929 (goto-char (prog1 (mark t)
3930 (set-marker (mark-marker) (point) (current-buffer)))))))
3931 (kill-new str))
3933 ;; (anything 'anything-c-source-kill-ring)
3935 ;;;; <Mark ring>
3936 ;; DO NOT include these sources in `anything-sources' use
3937 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
3938 ;; `anything-all-mark-rings' instead.
3940 (defun anything-c-source-mark-ring-candidates ()
3941 (flet ((get-marks (pos)
3942 (save-excursion
3943 (goto-char pos)
3944 (beginning-of-line)
3945 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3946 (when (string= "" line)
3947 (setq line "<EMPTY LINE>"))
3948 (format "%7d: %s" (line-number-at-pos) line)))))
3949 (with-current-buffer anything-current-buffer
3950 (loop
3951 with marks = (cons (mark-marker) mark-ring)
3952 with recip = nil
3953 for i in marks
3954 for m = (get-marks i)
3955 unless (member m recip)
3956 collect m into recip
3957 finally return recip))))
3959 (defvar anything-mark-ring-cache nil)
3960 (defvar anything-c-source-mark-ring
3961 '((name . "mark-ring")
3962 (init . (lambda ()
3963 (setq anything-mark-ring-cache
3964 (ignore-errors (anything-c-source-mark-ring-candidates)))))
3965 (candidates . (lambda ()
3966 (anything-aif anything-mark-ring-cache
3967 it)))
3968 (action . (("Goto line" . (lambda (candidate)
3969 (anything-goto-line (string-to-number candidate))))))
3970 (persistent-action . (lambda (candidate)
3971 (anything-goto-line (string-to-number candidate))
3972 (anything-match-line-color-current-line)))
3973 (persistent-help . "Show this line")))
3975 ;; (anything 'anything-c-source-mark-ring)
3977 ;;;###autoload
3978 (defun anything-mark-ring ()
3979 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3980 (interactive)
3981 (anything 'anything-c-source-mark-ring))
3983 ;;; Global-mark-ring
3984 (defvar anything-c-source-global-mark-ring
3985 '((name . "global-mark-ring")
3986 (candidates . anything-c-source-global-mark-ring-candidates)
3987 (action . (("Goto line" . (lambda (candidate)
3988 (let ((items (split-string candidate ":")))
3989 (switch-to-buffer (second items))
3990 (anything-goto-line (string-to-number (car items))))))))
3991 (persistent-action . (lambda (candidate)
3992 (let ((items (split-string candidate ":")))
3993 (switch-to-buffer (second items))
3994 (anything-goto-line (string-to-number (car items)))
3995 (anything-match-line-color-current-line))))
3996 (persistent-help . "Show this line")))
3998 (defun anything-c-source-global-mark-ring-candidates ()
3999 (flet ((buf-fn (m)
4000 (with-current-buffer (marker-buffer m)
4001 (goto-char m)
4002 (beginning-of-line)
4003 (let (line)
4004 (if (string= "" line)
4005 (setq line "<EMPTY LINE>")
4006 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
4007 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
4008 (loop
4009 with marks = global-mark-ring
4010 with recip = nil
4011 for i in marks
4012 for gm = (unless (or (string-match
4013 "^ " (format "%s" (marker-buffer i)))
4014 (null (marker-buffer i)))
4015 (buf-fn i))
4016 when (and gm (not (member gm recip)))
4017 collect gm into recip
4018 finally return recip)))
4020 ;; (anything 'anything-c-source-global-mark-ring)
4022 ;;;###autoload
4023 (defun anything-global-mark-ring ()
4024 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4025 (interactive)
4026 (anything 'anything-c-source-global-mark-ring))
4028 ;;;###autoload
4029 (defun anything-all-mark-rings ()
4030 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4031 `anything-c-source-mark-ring'."
4032 (interactive)
4033 (anything '(anything-c-source-global-mark-ring
4034 anything-c-source-mark-ring)))
4036 ;;;; <Register>
4037 ;;; Insert from register
4038 (defvar anything-c-source-register
4039 '((name . "Registers")
4040 (candidates . anything-c-register-candidates)
4041 (action-transformer . anything-c-register-action-transformer)
4042 (multiline)
4043 (action))
4044 "See (info \"(emacs)Registers\")")
4046 (defun anything-c-register-candidates ()
4047 "Collecting register contents and appropriate commands."
4048 (loop for (char . val) in register-alist
4049 for key = (single-key-description char)
4050 for string-actions = (cond
4051 ((numberp val)
4052 (list (int-to-string val)
4053 'insert-register
4054 'increment-register))
4055 ((markerp val)
4056 (let ((buf (marker-buffer val)))
4057 (if (null buf)
4058 (list "a marker in no buffer")
4059 (list (concat
4060 "a buffer position:"
4061 (buffer-name buf)
4062 ", position "
4063 (int-to-string (marker-position val)))
4064 'jump-to-register
4065 'insert-register))))
4066 ((and (consp val) (window-configuration-p (car val)))
4067 (list "window configuration."
4068 'jump-to-register))
4069 ((and (consp val) (frame-configuration-p (car val)))
4070 (list "frame configuration."
4071 'jump-to-register))
4072 ((and (consp val) (eq (car val) 'file))
4073 (list (concat "file:"
4074 (prin1-to-string (cdr val))
4075 ".")
4076 'jump-to-register))
4077 ((and (consp val) (eq (car val) 'file-query))
4078 (list (concat "file:a file-query reference: file "
4079 (car (cdr val))
4080 ", position "
4081 (int-to-string (car (cdr (cdr val))))
4082 ".")
4083 'jump-to-register))
4084 ((consp val)
4085 (let ((lines (format "%4d" (length val))))
4086 (list (format "%s: %s\n" lines
4087 (truncate-string-to-width
4088 (mapconcat 'identity (list (car val))
4089 ;; (mapconcat (lambda (y) y) val
4090 "^J") (- (window-width) 15)))
4091 'insert-register)))
4092 ((stringp val)
4093 (list ;; without properties
4094 (substring-no-properties val)
4095 'insert-register
4096 'append-to-register
4097 'prepend-to-register))
4099 "GARBAGE!"))
4100 collect (cons (format "register %3s: %s" key (car string-actions))
4101 (cons char (cdr string-actions)))))
4103 (defun anything-c-register-action-transformer (actions register-and-functions)
4104 "Decide actions by the contents of register."
4105 (loop with func-actions =
4106 '((insert-register
4107 "Insert Register" .
4108 (lambda (c) (insert-register (car c))))
4109 (jump-to-register
4110 "Jump to Register" .
4111 (lambda (c) (jump-to-register (car c))))
4112 (append-to-register
4113 "Append Region to Register" .
4114 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
4115 (prepend-to-register
4116 "Prepend Region to Register" .
4117 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
4118 (increment-register
4119 "Increment Prefix Arg to Register" .
4120 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
4121 for func in (cdr register-and-functions)
4122 for cell = (assq func func-actions)
4123 when cell
4124 collect (cdr cell)))
4126 ;; (anything 'anything-c-source-register)
4128 ;;;; <Headline Extraction>
4129 (defvar anything-c-source-fixme
4130 '((name . "TODO/FIXME/DRY comments")
4131 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4132 (adjust)
4133 (recenter))
4134 "Show TODO/FIXME/DRY comments in current file.")
4135 ;; (anything 'anything-c-source-fixme)
4137 (defvar anything-c-source-rd-headline
4138 '((name . "RD HeadLine")
4139 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4140 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
4141 (migemo)
4142 (subexp . 1))
4143 "Show RD headlines.
4145 RD is Ruby's POD.
4146 http://en.wikipedia.org/wiki/Ruby_Document_format")
4147 ;; (anything 'anything-c-source-rd-headline)
4149 (defvar anything-c-source-oddmuse-headline
4150 '((name . "Oddmuse HeadLine")
4151 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4152 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4153 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
4154 (migemo)
4155 (subexp . 1))
4156 "Show Oddmuse headlines, such as EmacsWiki.")
4157 ;; (anything 'anything-c-source-oddmuse-headline)
4159 (defvar anything-c-source-emacs-source-defun
4160 '((name . "Emacs Source DEFUN")
4161 (headline . "DEFUN\\|DEFVAR")
4162 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
4163 "Show DEFUN/DEFVAR in Emacs C source file.")
4164 ;; (anything 'anything-c-source-emacs-source-defun)
4166 (defvar anything-c-source-emacs-lisp-expectations
4167 '((name . "Emacs Lisp Expectations")
4168 (headline . "(desc[ ]\\|(expectations")
4169 (condition . (eq major-mode 'emacs-lisp-mode)))
4170 "Show descriptions (desc) in Emacs Lisp Expectations.
4172 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4173 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4175 (defvar anything-c-source-emacs-lisp-toplevels
4176 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4177 (headline . "^(\\|(@\\*\\|^;;;;")
4178 (get-line . buffer-substring)
4179 (condition . (eq major-mode 'emacs-lisp-mode))
4180 (adjust))
4181 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4182 linkd.el is optional because linkd stars are extracted by regexp.
4183 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4184 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4186 (defvar anything-c-source-org-headline
4187 '((name . "Org HeadLine")
4188 (headline
4189 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4190 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4191 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4192 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4193 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4194 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4195 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4196 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4197 (condition . (eq major-mode 'org-mode))
4198 (migemo)
4199 (subexp . 1)
4200 (persistent-action . (lambda (elm)
4201 (anything-c-action-line-goto elm)
4202 (org-cycle)))
4203 (action-transformer
4204 . (lambda (actions candidate)
4205 '(("Go to Line" . anything-c-action-line-goto)
4206 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
4207 "Show Org headlines.
4208 org-mode is very very much extended text-mode/outline-mode.
4210 See (find-library \"org.el\")
4211 See http://orgmode.org for the latest version.")
4213 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4214 (insert
4215 (save-excursion
4216 (anything-goto-line (car lineno-and-content))
4217 (and (looking-at org-complex-heading-regexp)
4218 (org-make-link-string (concat "*" (match-string 4)))))))
4220 ;; (anything 'anything-c-source-org-headline)
4222 ;;; Anything yaoddmuse
4223 ;; Be sure to have yaoddmuse.el installed
4224 ;; install-elisp may be required if you want to install elisp file from here.
4225 (defvar anything-yaoddmuse-use-cache-file nil)
4226 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
4227 (defvar anything-c-yaoddmuse-ew-cache nil)
4228 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4229 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
4230 (candidates . (lambda ()
4231 (if anything-yaoddmuse-use-cache-file
4232 (ignore-errors
4233 (unless anything-c-yaoddmuse-ew-cache
4234 (load anything-c-yaoddmuse-cache-file)
4235 (setq anything-c-yaoddmuse-ew-cache
4236 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4237 anything-c-yaoddmuse-ew-cache)
4238 (yaoddmuse-update-pagename t)
4239 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
4240 (action . (("Edit page" . (lambda (candidate)
4241 (yaoddmuse-edit "EmacsWiki" candidate)))
4242 ("Browse page" . (lambda (candidate)
4243 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4244 ("Browse page other window" . (lambda (candidate)
4245 (if (one-window-p)
4246 (split-window-vertically))
4247 (yaoddmuse-browse-page "EmacsWiki" candidate)))
4248 ("Browse diff" . (lambda (candidate)
4249 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
4250 ("Copy URL" . (lambda (candidate)
4251 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
4252 (message "Have copy page %s's URL to yank." candidate)))
4253 ("Create page" . (lambda (candidate)
4254 (yaoddmuse-edit "EmacsWiki" anything-input)))
4255 ("Update cache" . (lambda (candidate)
4256 (if anything-yaoddmuse-use-cache-file
4257 (progn
4258 (anything-yaoddmuse-cache-pages t)
4259 (setq anything-c-yaoddmuse-ew-cache
4260 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
4261 (yaoddmuse-update-pagename))))))
4262 (action-transformer anything-c-yaoddmuse-action-transformer))
4263 "Needs yaoddmuse.el.
4265 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4267 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
4269 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
4270 '((name . "Yaoddmuse Post library (EmacsWiki)")
4271 (init . (anything-yaoddmuse-init))
4272 (candidates-in-buffer)
4273 (action . (("Post library and Browse" . (lambda (candidate)
4274 (yaoddmuse-post-file (find-library-name candidate)
4275 "EmacsWiki"
4276 (file-name-nondirectory (find-library-name candidate))
4277 nil t)))
4278 ("Post library" . (lambda (candidate)
4279 (yaoddmuse-post-file (find-library-name candidate)
4280 "EmacsWiki"
4281 (file-name-nondirectory (find-library-name candidate))))))))
4282 "Needs yaoddmuse.el.
4284 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4286 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
4288 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
4289 "Allow the use of `install-elisp' only on elisp files."
4290 (if (string-match "\.el$" candidate)
4291 (append actions '(("Install Elisp" . (lambda (elm)
4292 (install-elisp-from-emacswiki elm)))))
4293 actions))
4295 ;;;###autoload
4296 (defun anything-yaoddmuse-cache-pages (&optional load)
4297 "Fetch the list of files on emacswiki and create cache file.
4298 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
4299 (interactive)
4300 (yaoddmuse-update-pagename)
4301 (save-excursion
4302 (find-file anything-c-yaoddmuse-cache-file)
4303 (erase-buffer)
4304 (insert "(puthash \"EmacsWiki\" '(")
4305 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
4307 (insert (concat "(\"" (car i) "\") ")))
4308 (insert ") yaoddmuse-pages-hash)\n")
4309 (save-buffer)
4310 (kill-buffer (current-buffer))
4311 (when (or current-prefix-arg
4312 load)
4313 (load anything-c-yaoddmuse-cache-file))))
4315 ;;;###autoload
4316 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
4317 "Preconfigured `anything' to edit or view EmacsWiki page.
4319 Needs yaoddmuse.el.
4321 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4322 (interactive)
4323 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
4325 ;;;###autoload
4326 (defun anything-yaoddmuse-emacswiki-post-library ()
4327 "Preconfigured `anything' to post library to EmacsWiki.
4329 Needs yaoddmuse.el.
4331 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4332 (interactive)
4333 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
4335 (defun anything-yaoddmuse-init ()
4336 "Init anything buffer status."
4337 (let ((anything-buffer (anything-candidate-buffer 'global))
4338 (library-list (yaoddmuse-get-library-list)))
4339 (with-current-buffer anything-buffer
4340 ;; Insert library name.
4341 (dolist (library library-list)
4342 (insert (format "%s\n" library)))
4343 ;; Sort lines.
4344 (sort-lines nil (point-min) (point-max)))))
4346 ;;; Eev anchors
4347 (defvar anything-c-source-eev-anchor
4348 '((name . "Anchors")
4349 (candidates
4350 . (lambda ()
4351 (ignore-errors
4352 (with-current-buffer anything-current-buffer
4353 (loop initially (goto-char (point-min))
4354 while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
4355 for anchor = (match-string-no-properties 1)
4356 collect (cons (format "%5d:%s"
4357 (line-number-at-pos (match-beginning 0))
4358 (format ee-anchor-format anchor)) anchor))))))
4359 (persistent-action . (lambda (item)
4360 (ee-to item)
4361 (anything-match-line-color-current-line)))
4362 (persistent-help . "Show this entry")
4363 (action . (("Goto link" . ee-to)))))
4364 ;; (anything 'anything-c-source-eev-anchor)
4366 ;;;; <Misc>
4367 ;;; Org keywords
4368 (defvar anything-c-source-org-keywords
4369 '((name . "Org Keywords")
4370 (init . anything-c-org-keywords-init)
4371 (candidates . anything-c-org-keywords-candidates)
4372 (action . anything-c-org-keywords-insert)
4373 (persistent-action . anything-c-org-keywords-show-help)
4374 (persistent-help . "Show an example and info page to describe this keyword.")
4375 (keywords-examples)
4376 (keywords)))
4377 ;; (anything 'anything-c-source-org-keywords)
4378 (defvar anything-c-org-keywords-info-location
4379 '(("#+TITLE:" . "(org)Export options")
4380 ("#+AUTHOR:" . "(org)Export options")
4381 ("#+DATE:" . "(org)Export options")
4382 ("#+EMAIL:" . "(org)Export options")
4383 ("#+DESCRIPTION:" . "(org)Export options")
4384 ("#+KEYWORDS:" . "(org)Export options")
4385 ("#+LANGUAGE:" . "(org)Export options")
4386 ("#+TEXT:" . "(org)Export options")
4387 ("#+TEXT:" . "(org)Export options")
4388 ("#+OPTIONS:" . "(org)Export options")
4389 ("#+BIND:" . "(org)Export options")
4390 ("#+LINK_UP:" . "(org)Export options")
4391 ("#+LINK_HOME:" . "(org)Export options")
4392 ("#+LATEX_HEADER:" . "(org)Export options")
4393 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
4394 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
4395 ("#+INFOJS_OPT" . "(org)Javascript support")
4396 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
4397 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
4398 ("#+ORGTBL" . "(org)Radio tables")
4399 ("#+HTML:" . "(org)Quoting HTML tags")
4400 ("#+LaTeX:" . "(org)Quoting LaTeX code")
4401 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
4402 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
4403 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
4404 ("#+BEGIN_VERSE" . "(org)Paragraphs")
4405 ("#+BEGIN_SRC" . "(org)Literal examples")
4406 ("#+CAPTION" . "(org)Tables in HTML export")
4407 ("#+LABEL" . "(org)Tables in LaTeX export")
4408 ("#+ATTR_HTML" . "(org)Links")
4409 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
4411 (defun anything-c-org-keywords-init ()
4412 (unless (anything-attr 'keywords-examples)
4413 (require 'org)
4414 (anything-attrset 'keywords-examples
4415 (append
4416 (mapcar
4417 (lambda (x)
4418 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
4419 (cons (match-string 2 x) (match-string 1 x)))
4420 (org-split-string (org-get-current-options) "\n"))
4421 (mapcar 'list org-additional-option-like-keywords)))
4422 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
4424 (defun anything-c-org-keywords-candidates ()
4425 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
4426 (anything-attr 'keywords)))
4428 (defun anything-c-org-keywords-insert (keyword)
4429 (cond ((string-match "BEGIN" keyword)
4430 (insert "#+" keyword " ")
4431 (save-excursion
4432 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
4434 (insert "#+" keyword " "))))
4436 (defun anything-c-org-keywords-show-help (keyword)
4437 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
4438 "(org)In-buffer settings"))
4439 (search-forward (concat "#+" keyword) nil t)
4440 (anything-persistent-highlight-point)
4441 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
4444 ;;; Picklist
4445 (defvar anything-c-source-picklist
4446 '((name . "Picklist")
4447 (candidates . (lambda () (mapcar 'car picklist-list)))
4448 (type . file)))
4449 ;; (anything 'anything-c-source-picklist)
4451 ;;; BBDB
4452 (defvar bbdb-records)
4453 (defvar bbdb-buffer-name)
4454 (declare-function bbdb "ext:bbdb-com")
4455 (declare-function bbdb-current-record "ext:bbdb-com")
4456 (declare-function bbdb-redisplay-one-record "ext:bbdb-com")
4457 (declare-function bbdb-record-net "ext:bbdb-com" (string) t)
4458 (declare-function bbdb-current-record "ext:bbdb-com")
4459 (declare-function bbdb-dwim-net-address "ext:bbdb-com")
4460 (declare-function bbdb-records "ext:bbdb-com"
4461 (&optional dont-check-disk already-in-db-buffer))
4463 (defun anything-c-bbdb-candidates ()
4464 "Return a list of all names in the bbdb database. The format
4465 is \"Firstname Lastname\"."
4466 (mapcar (lambda (bbdb-record)
4467 (replace-regexp-in-string
4468 "\\s-+$" ""
4469 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
4470 (bbdb-records)))
4472 (defun anything-c-bbdb-create-contact (actions candidate)
4473 "Action transformer that returns only an entry to add the
4474 current `anything-pattern' as new contact. All other actions are
4475 removed."
4476 (if (string= candidate "*Add to contacts*")
4477 '(("Add to contacts" . (lambda (actions)
4478 (bbdb-create-internal
4479 (read-from-minibuffer "Name: " anything-c-bbdb-name)
4480 (read-from-minibuffer "Company: ")
4481 (read-from-minibuffer "Email: ")
4484 (read-from-minibuffer "Note: ")))))
4485 actions))
4487 (defun anything-c-bbdb-get-record (candidate)
4488 "Return record that match CANDIDATE."
4489 (bbdb candidate nil)
4490 (set-buffer "*BBDB*")
4491 (bbdb-current-record))
4493 (defvar anything-c-bbdb-name nil
4494 "Only for internal use.")
4496 (defvar anything-c-source-bbdb
4497 '((name . "BBDB")
4498 (candidates . anything-c-bbdb-candidates)
4499 (action ("Send a mail" . anything-c-bbdb-compose-mail)
4500 ("View person's data" . anything-c-bbdb-view-person-action))
4501 (filtered-candidate-transformer . (lambda (candidates source)
4502 (setq anything-c-bbdb-name anything-pattern)
4503 (if (not candidates)
4504 (list "*Add to contacts*")
4505 candidates)))
4506 (action-transformer . (lambda (actions candidate)
4507 (anything-c-bbdb-create-contact actions candidate))))
4508 "Needs BBDB.
4510 http://bbdb.sourceforge.net/")
4511 ;; (anything 'anything-c-source-bbdb)
4513 (defun anything-c-bbdb-view-person-action (candidate)
4514 "View BBDB data of single CANDIDATE or marked candidates."
4515 (anything-aif (anything-marked-candidates)
4516 (let ((bbdb-append-records (length it)))
4517 (dolist (i it)
4518 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
4519 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
4521 (defun anything-c-bbdb-collect-mail-addresses ()
4522 "Return a list of all mail addresses of records in bbdb buffer."
4523 (with-current-buffer bbdb-buffer-name
4524 (loop for i in bbdb-records
4525 if (bbdb-record-net (car i))
4526 collect (bbdb-dwim-net-address (car i)))))
4528 (defun anything-c-bbdb-compose-mail (candidate)
4529 "Compose a mail with all records of bbdb buffer."
4530 (anything-c-bbdb-view-person-action candidate)
4531 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4532 (address-str (mapconcat 'identity address-list ",\n ")))
4533 (compose-mail address-str)))
4535 ;;; Evaluation Result
4536 (defvar anything-c-source-evaluation-result
4537 '((name . "Evaluation Result")
4538 (disable-shortcuts)
4539 (dummy)
4540 (filtered-candidate-transformer . (lambda (candidates source)
4541 (list
4542 (condition-case nil
4543 (with-current-buffer anything-current-buffer
4544 (pp-to-string
4545 (eval (read anything-pattern))))
4546 (error "Error")))))
4547 (action ("Copy result to kill-ring" . (lambda (candidate)
4548 (with-current-buffer anything-buffer
4549 (let ((end (save-excursion
4550 (goto-char (point-max))
4551 (search-backward "\n")
4552 (point))))
4553 (kill-region (point) end))))))))
4554 ;; (anything 'anything-c-source-evaluation-result)
4556 ;;;###autoload
4557 (defun anything-eval-expression (arg)
4558 "Preconfigured anything for `anything-c-source-evaluation-result'."
4559 (interactive "P")
4560 (anything 'anything-c-source-evaluation-result (when arg (thing-at-point 'sexp))
4561 nil nil nil "*anything eval*"))
4563 ;;;###autoload
4564 (defun anything-eval-expression-with-eldoc ()
4565 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
4566 (interactive)
4567 (if (window-system)
4568 (let ((timer (run-with-idle-timer eldoc-idle-delay
4569 'repeat 'anything-eldoc-show-in-eval)))
4570 (unwind-protect
4571 (call-interactively 'anything-eval-expression)
4572 (cancel-timer timer)))
4573 (call-interactively 'anything-eval-expression)))
4575 (defun anything-eldoc-show-in-eval ()
4576 "Return eldoc in a tooltip for current minibuffer input."
4577 (let* ((str-all (minibuffer-completion-contents))
4578 (sym (when str-all
4579 (with-temp-buffer
4580 (insert str-all)
4581 (goto-char (point-max))
4582 (unless (looking-back ")\\|\"") (forward-char -1))
4583 (eldoc-current-symbol))))
4584 (doc (or (eldoc-get-var-docstring sym)
4585 (eldoc-get-fnsym-args-string
4586 (car (eldoc-fnsym-in-current-sexp))))))
4587 (when doc (tooltip-show doc))))
4589 ;;; Calculation Result
4590 (defvar anything-c-source-calculation-result
4591 '((name . "Calculation Result")
4592 (dummy)
4593 (filtered-candidate-transformer . (lambda (candidates source)
4594 (list
4595 (condition-case nil
4596 (calc-eval anything-pattern)
4597 (error "error")))))
4598 (action ("Copy result to kill-ring" . kill-new))))
4599 ;; (anything 'anything-c-source-calculation-result)
4601 ;;; Google Suggestions
4602 (defvar anything-gg-sug-lgh-flag 0)
4603 (defun anything-c-google-suggest-fetch (input)
4604 "Fetch suggestions for INPUT from XML buffer.
4605 Return an alist with elements like (data . number_results)."
4606 (let ((request (concat anything-c-google-suggest-url
4607 (url-hexify-string input))))
4608 (flet ((fetch ()
4609 (loop
4610 with result-alist = (xml-get-children
4611 (car (xml-parse-region (point-min) (point-max)))
4612 'CompleteSuggestion)
4613 for i in result-alist
4614 for data = (cdr (caadr (assoc 'suggestion i)))
4615 for nqueries = (cdr (caadr (assoc 'num_queries i)))
4616 for ldata = (length data)
4618 (when (> ldata anything-gg-sug-lgh-flag)
4619 (setq anything-gg-sug-lgh-flag ldata))
4620 collect (cons data nqueries) into cont
4621 finally return cont)))
4622 (if anything-google-suggest-use-curl-p
4623 (with-temp-buffer
4624 (call-process "curl" nil t nil request)
4625 (fetch))
4626 (with-current-buffer
4627 (url-retrieve-synchronously request)
4628 (fetch))))))
4631 (defun anything-c-google-suggest-set-candidates ()
4632 "Set candidates with result and number of google results found."
4633 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
4634 (setq suggestions (loop for i in suggestions
4635 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
4636 for elm = (concat (car i)
4637 (make-string (+ 2 interval) ? )
4638 "(" (cdr i) " results)")
4639 collect (cons elm (car i))))
4640 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
4641 suggestions
4642 ;; if there is no suggestion exactly matching the input then
4643 ;; prepend a Search on Google item to the list
4644 (append
4645 suggestions
4646 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
4647 anything-input))))))
4650 (defun anything-c-google-suggest-action (candidate)
4651 "Default action to jump to a google suggested candidate."
4652 (anything-c-browse-url (concat anything-c-google-suggest-search-url
4653 (url-hexify-string candidate))))
4656 (defvar anything-c-source-google-suggest
4657 '((name . "Google Suggest")
4658 (candidates . anything-c-google-suggest-set-candidates)
4659 (action . (("Google Search" . anything-c-google-suggest-action)))
4660 (volatile)
4661 (requires-pattern . 3)
4662 (delayed)))
4664 ;; (anything 'anything-c-source-google-suggest)
4666 ;;; Yahoo suggestions
4668 (defun anything-c-yahoo-suggest-fetch (input)
4669 "Fetch Yahoo suggestions for INPUT from XML buffer.
4670 Return an alist with elements like (data . number_results)."
4671 (let ((request (concat anything-c-yahoo-suggest-url
4672 (url-hexify-string input))))
4673 (flet ((fetch ()
4674 (loop
4675 with result-alist = (xml-get-children
4676 (car (xml-parse-region (point-min) (point-max)))
4677 'Result)
4678 for i in result-alist
4679 collect (caddr i))))
4680 (with-current-buffer
4681 (url-retrieve-synchronously request)
4682 (fetch)))))
4684 (defun anything-c-yahoo-suggest-set-candidates ()
4685 "Set candidates with Yahoo results found."
4686 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
4687 (or suggestions
4688 (append
4689 suggestions
4690 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
4691 anything-input))))))
4693 (defun anything-c-yahoo-suggest-action (candidate)
4694 "Default action to jump to a Yahoo suggested candidate."
4695 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
4696 (url-hexify-string candidate))))
4698 (defvar anything-c-source-yahoo-suggest
4699 '((name . "Yahoo Suggest")
4700 (candidates . anything-c-yahoo-suggest-set-candidates)
4701 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
4702 (volatile)
4703 (requires-pattern . 3)
4704 (delayed)))
4706 ;; (anything 'anything-c-source-yahoo-suggest)
4708 ;;; Surfraw
4709 ;;; Need external program surfraw.
4710 ;;; http://surfraw.alioth.debian.org/
4711 ;; user variables
4712 (require 'browse-url)
4713 (defvar w3m-command nil)
4714 (defvar anything-c-home-url "http://www.google.fr"
4715 "*Default url to use as home url.")
4717 (defvar anything-browse-url-default-browser-alist
4718 `((,w3m-command . w3m-browse-url)
4719 (,browse-url-firefox-program . browse-url-firefox)
4720 (,browse-url-kde-program . browse-url-kde)
4721 (,browse-url-gnome-moz-program . browse-url-gnome-moz)
4722 (,browse-url-mozilla-program . browse-url-mozilla)
4723 (,browse-url-galeon-program . browse-url-galeon)
4724 (,browse-url-netscape-program . browse-url-netscape)
4725 (,browse-url-mosaic-program . browse-url-mosaic)
4726 (,browse-url-xterm-program . browse-url-text-xterm))
4727 "*Alist of (executable . function) to try to find a suitable url browser.")
4729 (defun anything-browse-url-default-browser (url &rest args)
4730 "Find a suitable browser and ask it to load URL."
4731 (let ((default-browser (loop
4732 for i in anything-browse-url-default-browser-alist
4733 when (and (car i) (executable-find (car i))) return (cdr i))))
4734 (if default-browser
4735 (apply default-browser url args)
4736 (error "No usable browser found"))))
4738 (defun* anything-c-browse-url (&optional (url anything-c-home-url))
4739 "Default command to browse URL."
4740 (if browse-url-browser-function
4741 (browse-url url)
4742 (anything-browse-url-default-browser url)))
4744 (defun anything-c-build-elvi-list ()
4745 "Return list of all engines and descriptions handled by surfraw."
4746 (cdr
4747 (with-temp-buffer
4748 (call-process "surfraw" nil t nil
4749 "-elvi")
4750 (split-string (buffer-string) "\n"))))
4752 ;;;###autoload
4753 (defun anything-surfraw (pattern engine)
4754 "Preconfigured `anything' to search PATTERN with search ENGINE."
4755 (interactive (list (read-string "SearchFor: ")
4756 (anything-comp-read
4757 "Engine: "
4758 (anything-c-build-elvi-list)
4759 :must-match t)))
4760 (let* ((engine-nodesc (car (split-string engine)))
4761 (url (with-temp-buffer
4762 (apply 'call-process "surfraw" nil t nil
4763 (list engine-nodesc "-p" pattern))
4764 (replace-regexp-in-string
4765 "\n" "" (buffer-string)))))
4766 (if (string= engine-nodesc "W")
4767 (anything-c-browse-url)
4768 (anything-c-browse-url url))))
4770 ;;; Emms
4772 ;;;###autoload
4773 (defun anything-emms-stream-edit-bookmark (elm)
4774 "Change the information of current emms-stream bookmark from anything."
4775 (interactive)
4776 (let* ((cur-buf anything-current-buffer)
4777 (bookmark (assoc elm emms-stream-list))
4778 (name (read-from-minibuffer "Description: "
4779 (nth 0 bookmark)))
4780 (url (read-from-minibuffer "URL: "
4781 (nth 1 bookmark)))
4782 (fd (read-from-minibuffer "Feed Descriptor: "
4783 (int-to-string (nth 2 bookmark))))
4784 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4785 (format "%s" (car (last bookmark))))))
4786 (save-excursion
4787 (emms-streams)
4788 (when (re-search-forward (concat "^" name) nil t)
4789 (beginning-of-line)
4790 (emms-stream-delete-bookmark)
4791 (emms-stream-add-bookmark name url (string-to-number fd) type)
4792 (emms-stream-save-bookmarks-file)
4793 (emms-stream-quit)
4794 (switch-to-buffer cur-buf)))))
4796 (defun anything-emms-stream-delete-bookmark (elm)
4797 "Delete an emms-stream bookmark from anything."
4798 (interactive)
4799 (let* ((cur-buf anything-current-buffer)
4800 (bookmark (assoc elm emms-stream-list))
4801 (name (nth 0 bookmark)))
4802 (save-excursion
4803 (emms-streams)
4804 (when (re-search-forward (concat "^" name) nil t)
4805 (beginning-of-line)
4806 (emms-stream-delete-bookmark)
4807 (emms-stream-save-bookmarks-file)
4808 (emms-stream-quit)
4809 (switch-to-buffer cur-buf)))))
4811 (defvar anything-c-source-emms-streams
4812 '((name . "Emms Streams")
4813 (init . (lambda ()
4814 (emms-stream-init)))
4815 (candidates . (lambda ()
4816 (mapcar 'car emms-stream-list)))
4817 (action . (("Play" . (lambda (elm)
4818 (let* ((stream (assoc elm emms-stream-list))
4819 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
4820 (url (second stream)))
4821 (funcall fn url))))
4822 ("Delete" . anything-emms-stream-delete-bookmark)
4823 ("Edit" . anything-emms-stream-edit-bookmark)))
4824 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4825 ;; (anything 'anything-c-source-emms-streams)
4827 ;; Don't forget to set `emms-source-file-default-directory'
4828 (defvar anything-c-source-emms-dired
4829 '((name . "Music Directory")
4830 (candidates . (lambda ()
4831 (cddr (directory-files emms-source-file-default-directory))))
4832 (action .
4833 (("Play Directory" . (lambda (item)
4834 (emms-play-directory
4835 (expand-file-name
4836 item
4837 emms-source-file-default-directory))))
4838 ("Open dired in file's directory" . (lambda (item)
4839 (anything-c-open-dired
4840 (expand-file-name
4841 item
4842 emms-source-file-default-directory))))))
4843 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4844 ;; (anything 'anything-c-source-emms-dired)
4846 (defface anything-emms-playlist
4847 '((t (:foreground "Springgreen4" :underline t)))
4848 "*Face used for tracks in current emms playlist."
4849 :group 'anything)
4851 (defun anything-c-emms-files-modifier (candidates)
4852 (let ((current-playlist (with-current-emms-playlist
4853 (loop
4854 with cur-list = (emms-playlist-tracks-in-region
4855 (point-min) (point-max))
4856 for i in cur-list
4857 collect (assoc-default 'info-file i)))))
4858 (loop for i in candidates
4859 if (member i current-playlist)
4860 collect (propertize i 'face 'anything-emms-playlist) into lis
4861 else collect i into lis finally return lis)))
4863 (defun anything-c-emms-play-current-playlist ()
4864 "Play current playlist."
4865 (with-current-emms-playlist
4866 (emms-playlist-first)
4867 (emms-playlist-mode-play-smart)))
4869 (defvar anything-c-source-emms-files
4870 '((name . "Emms files")
4871 (candidates . (lambda ()
4872 (loop for v being the hash-values in emms-cache-db
4873 for name = (assoc-default 'name v)
4874 unless (string-match "^http:" name) collect name)))
4875 (candidate-transformer . anything-c-emms-files-modifier)
4876 (action . (("Play file" . emms-play-file)
4877 ("Add to Playlist and play"
4878 . (lambda (candidate)
4879 (emms-playlist-new)
4880 (dolist (i (anything-marked-candidates))
4881 (emms-add-playlist-file i))
4882 (unless emms-player-playing-p
4883 (anything-c-emms-play-current-playlist))))))))
4885 ;; (anything 'anything-c-source-emms-files)
4887 ;;; Jabber Contacts (jabber.el)
4888 (defun anything-c-jabber-online-contacts ()
4889 "List online Jabber contacts."
4890 (with-no-warnings
4891 (let (jids)
4892 (dolist (item (jabber-concat-rosters) jids)
4893 (when (get item 'connected)
4894 (push (if (get item 'name)
4895 (cons (get item 'name) item)
4896 (cons (symbol-name item) item)) jids))))))
4898 (defvar anything-c-source-jabber-contacts
4899 '((name . "Jabber Contacts")
4900 (init . (lambda () (require 'jabber)))
4901 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
4902 (action . (lambda (x)
4903 (jabber-chat-with
4904 (jabber-read-account)
4905 (symbol-name
4906 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
4907 ;; (anything 'anything-c-source-jabber-contacts)
4910 ;;; Call source.
4911 (defvar anything-source-select-buffer "*anything source select*")
4912 (defvar anything-c-source-call-source
4913 `((name . "Call anything source")
4914 (candidate-number-limit)
4915 (candidates . (lambda ()
4916 (loop for vname in (all-completions "anything-c-source-" obarray)
4917 for var = (intern vname)
4918 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
4919 if name collect (cons (format "%s `%s'"
4920 name (propertize vname 'face 'font-lock-variable-name-face))
4921 var))))
4922 (action . (("Invoke anything with selected source" .
4923 (lambda (candidate)
4924 (setq anything-candidate-number-limit 9999)
4925 (anything candidate nil nil nil nil
4926 anything-source-select-buffer)))
4927 ("Describe variable" . describe-variable)
4928 ("Find variable" . find-variable)))
4929 (persistent-action . describe-variable)
4930 (persistent-help . "Show description of this source")))
4931 ;; (anything 'anything-c-source-call-source)
4933 ;;;###autoload
4934 (defun anything-call-source ()
4935 "Preconfigured `anything' to call anything source."
4936 (interactive)
4937 (anything 'anything-c-source-call-source nil nil nil nil
4938 anything-source-select-buffer))
4940 (defun anything-call-source-from-anything ()
4941 "Call anything source within `anything' session."
4942 (interactive)
4943 (setq anything-input-idle-delay 0)
4944 (anything-set-sources '(anything-c-source-call-source)))
4946 ;;; Execute Preconfigured anything.
4947 (defvar anything-c-source-anything-commands
4948 '((name . "Preconfigured Anything")
4949 (candidates . anything-c-anything-commands-candidates)
4950 (type . command)
4951 (candidate-number-limit)))
4952 ;; (anything 'anything-c-source-anything-commands)
4954 (defun anything-c-anything-commands-candidates ()
4955 (loop for (cmd . desc) in (anything-c-list-preconfigured-anything)
4956 collect (cons (if (where-is-internal cmd nil t)
4957 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc))
4958 (substitute-command-keys (format "\\[%s] : %s" cmd desc)))
4959 cmd)))
4961 ;;;###autoload
4962 (defun anything-execute-anything-command ()
4963 "Preconfigured `anything' to execute preconfigured `anything'."
4964 (interactive)
4965 (anything-other-buffer 'anything-c-source-anything-commands
4966 "*anything commands*"))
4968 ;; Occur
4970 (defun anything-c-occur-goto-line (candidate)
4971 "Goto line action for anything-c-source-occur."
4972 (anything-goto-line (string-to-number candidate)))
4974 (defun anything-c-occur-persistent-action (candidate)
4975 "Persistent action for anything occur source."
4976 (anything-c-occur-goto-line candidate)
4977 (anything-match-line-color-current-line))
4979 (defun anything-c-get-occur-candidates ()
4980 "Get `anything-c-source-occur' candidates."
4981 (with-temp-buffer
4982 (let ((count (occur-engine
4983 anything-pattern
4984 (list anything-current-buffer) (current-buffer)
4985 list-matching-lines-default-context-lines nil
4986 list-matching-lines-buffer-name-face
4987 nil list-matching-lines-face
4988 (not (eq occur-excluded-properties t)))))
4989 (when (> count 0)
4990 (cdr (split-string (buffer-string) "\n" t))))))
4992 (defvar anything-c-source-occur
4993 '((name . "Occur")
4994 (candidates . anything-c-get-occur-candidates)
4995 (persistent-action . anything-c-occur-persistent-action)
4996 (persistent-help . "Goto Line")
4997 (action . anything-c-occur-goto-line)
4998 (requires-pattern . 1)
4999 (delayed)
5000 (volatile)))
5001 ;; (anything 'anything-c-source-occur)
5003 ;;;###autoload
5004 (defun anything-occur ()
5005 "Preconfigured Anything for Occur source."
5006 (interactive)
5007 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*"))
5009 ;; Do many actions for input
5010 (defvar anything-c-source-create
5011 '((name . "Create")
5012 (dummy)
5013 (action)
5014 (action-transformer . anything-create--actions))
5015 "Do many create actions from `anything-pattern'.
5016 See also `anything-create--actions'.")
5017 ;; (anything 'anything-c-source-create)
5019 (defun anything-create-from-anything ()
5020 "Run `anything-create' from `anything' as a fallback."
5021 (interactive)
5022 (anything-run-after-quit 'anything-create nil anything-pattern))
5024 ;;;###autoload
5025 (defun anything-create (&optional string initial-input)
5026 "Preconfigured `anything' to do many create actions from STRING.
5027 See also `anything-create--actions'."
5028 (interactive)
5029 (setq string (or string (read-string "Create Anything: " initial-input)))
5030 (anything '(((name . "Anything Create")
5031 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
5032 (candidates . anything-create--actions)
5033 (candidate-number-limit)
5034 (action . (lambda (func) (funcall func string)))))))
5036 (defun anything-create--actions (&rest ignored)
5037 "Default actions for `anything-create' / `anything-c-source-create'."
5038 (remove-if-not
5039 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
5040 (append anything-create--actions-private
5041 '(("find-file" . find-file)
5042 ("find-file other window" . find-file-other-window)
5043 ("New buffer" . switch-to-buffer)
5044 ("New buffer other window" . switch-to-buffer-other-window)
5045 ("Bookmark Set" . bookmark-set)
5046 ("Set Register" .
5047 (lambda (x) (set-register (read-char "Register: ") x)))
5048 ("Insert Linkd star" . linkd-insert-star)
5049 ("Insert Linkd Tag" . linkd-insert-tag)
5050 ("Insert Linkd Link" . linkd-insert-link)
5051 ("Insert Linkd Lisp" . linkd-insert-lisp)
5052 ("Insert Linkd Wiki" . linkd-insert-wiki)
5053 ("Google Search" . google)))))
5055 ;; Minibuffer History
5056 (defvar anything-c-source-minibuffer-history
5057 '((name . "Minibuffer History")
5058 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
5059 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
5060 (if (consp (car history))
5061 (mapcar 'prin1-to-string history)
5062 history))))
5063 (migemo)
5064 (action . insert)))
5065 ;; (anything 'anything-c-source-minibuffer-history)
5067 ;; elscreen
5068 (defvar anything-c-source-elscreen
5069 '((name . "Elscreen")
5070 (candidates . (lambda ()
5071 (if (cdr (elscreen-get-screen-to-name-alist))
5072 (sort
5073 (loop for sname in (elscreen-get-screen-to-name-alist)
5074 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
5075 finally (return lst))
5076 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
5077 (action . (("Change Screen".
5078 (lambda (candidate)
5079 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
5080 ("Kill Screen(s)".
5081 (lambda (candidate)
5082 (dolist (i (anything-marked-candidates))
5083 (elscreen-goto (- (aref i 1) (aref "0" 0)))
5084 (elscreen-kill))))
5085 ("Only Screen".
5086 (lambda (candidate)
5087 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
5088 (elscreen-kill-others)))))))
5089 ;; (anything 'anything-c-source-elscreen)
5091 ;;;; <System>
5093 ;;; Top (process)
5094 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
5095 "Top command (batch mode). %s is replaced with `frame-width'.")
5096 (defvar anything-c-source-top
5097 '((name . "Top (Press C-c C-u to refresh)")
5098 (init . anything-c-top-init)
5099 (candidates-in-buffer)
5100 (display-to-real . anything-c-top-display-to-real)
5101 (update . anything-c-top-update)
5102 (action
5103 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
5104 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
5105 ("Copy PID" . (lambda (pid) (kill-new pid))))))
5106 ;; (anything 'anything-c-source-top)
5108 (defun anything-c-top-sh (cmd)
5109 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
5111 (defun anything-c-top-init ()
5112 (with-current-buffer (anything-candidate-buffer 'global)
5113 (call-process-shell-command
5114 (format anything-c-top-command
5115 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
5116 nil (current-buffer))))
5118 (defun anything-c-top-display-to-real (line)
5119 (car (split-string line)))
5121 (defun anything-c-top-update ()
5122 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
5123 (anything-c-top-init)))
5125 ;;;###autoload
5126 (defun anything-top ()
5127 "Preconfigured `anything' for top command."
5128 (interactive)
5129 (let ((anything-samewindow t)
5130 (anything-enable-shortcuts)
5131 (anything-display-function 'anything-default-display-buffer)
5132 (anything-candidate-number-limit 9999))
5133 (save-window-excursion
5134 (delete-other-windows)
5135 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
5137 ;;; Timers
5138 (defvar anything-c-source-absolute-time-timers
5139 '((name . "Absolute Time Timers")
5140 (candidates . timer-list)
5141 (type . timer)))
5142 ;; (anything 'anything-c-source-absolute-time-timers)
5144 (defvar anything-c-source-idle-time-timers
5145 '((name . "Idle Time Timers")
5146 (candidates . timer-idle-list)
5147 (type . timer)))
5148 ;; (anything 'anything-c-source-idle-time-timers)
5150 (defun anything-c-timer-real-to-display (timer)
5151 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay)
5152 (append timer nil) ;use `append' to convert vector->list
5153 (format "%s repeat=%5S %s(%s)"
5154 (let ((time (list t1 t2 t3)))
5155 (if idle-delay
5156 (format-time-string "idle-for=%5s" time)
5157 (format-time-string "%m/%d %T" time)))
5158 repeat-delay
5159 func
5160 (mapconcat 'prin1-to-string args " "))))
5162 ;;; X RandR resolution change
5163 ;;; FIXME I do not care multi-display.
5164 (defvar anything-c-xrandr-output "VGA")
5165 (defvar anything-c-xrandr-screen "0")
5166 (defvar anything-c-source-xrandr-change-resolution
5167 '((name . "Change Resolution")
5168 (candidates
5169 . (lambda ()
5170 (with-temp-buffer
5171 (call-process "xrandr" nil (current-buffer) nil
5172 "--screen" anything-c-xrandr-screen "-q")
5173 (goto-char 1)
5174 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
5175 collect (match-string 1)))))
5176 (action
5177 ("Change Resolution" . (lambda (mode)
5178 (call-process "xrandr" nil nil nil
5179 "--screen" anything-c-xrandr-screen
5180 "--output" anything-c-xrandr-output
5181 "--mode" mode))))))
5182 ;; (anything 'anything-c-source-xrandr-change-resolution)
5184 ;;; Xfont selection
5185 (defun anything-c-persistent-xfont-action (elm)
5186 "Show current font temporarily"
5187 (let ((current-font (cdr (assoc 'font (frame-parameters))))
5188 (default-font elm))
5189 (unwind-protect
5190 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
5191 (set-frame-font current-font))))
5193 (defvar anything-c-xfonts-cache nil)
5194 (defvar anything-c-source-xfonts
5195 '((name . "X Fonts")
5196 (init . (lambda ()
5197 (unless anything-c-xfonts-cache
5198 (setq anything-c-xfonts-cache
5199 (x-list-fonts "*")))))
5200 (candidates . anything-c-xfonts-cache)
5201 (action . (("Copy to kill ring" . (lambda (elm)
5202 (kill-new elm)))
5203 ("Set Font" . (lambda (elm)
5204 (kill-new elm)
5205 (set-frame-font elm 'keep-size)
5206 (message "New font have been copied to kill ring")))))
5207 (persistent-action . anything-c-persistent-xfont-action)
5208 (persistent-help . "Switch to this font temporarily")))
5210 ;;;###autoload
5211 (defun anything-select-xfont ()
5212 "Preconfigured `anything' to select Xfont."
5213 (interactive)
5214 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
5216 ;; (anything 'anything-c-source-xfonts)
5218 ;;; Source for Debian/Ubuntu users
5219 (defvar anything-c-source-apt
5220 '((name . "APT")
5221 (init . anything-c-apt-init)
5222 (candidates-in-buffer)
5223 (candidate-transformer anything-c-apt-candidate-transformer)
5224 (display-to-real . anything-c-apt-display-to-real)
5225 (candidate-number-limit . 9999)
5226 (action
5227 ("Show package description" . anything-c-apt-cache-show)
5228 ("Install package" . anything-c-apt-install)
5229 ("Remove package" . anything-c-apt-uninstall)
5230 ("Purge package" . anything-c-apt-purge))
5231 (persistent-action . anything-c-apt-persistent-action)
5232 (persistent-help . "Show - C-u Refresh")))
5233 ;; (anything 'anything-c-source-apt)
5235 (defvar anything-c-apt-query "emacs")
5236 (defvar anything-c-apt-search-command "apt-cache search '%s'")
5237 (defvar anything-c-apt-show-command "apt-cache show '%s'")
5238 (defvar anything-c-apt-installed-packages nil)
5240 (defface anything-apt-installed
5241 '((t (:foreground "green")))
5242 "*Face used for apt installed candidates."
5243 :group 'anything)
5245 (defun anything-c-apt-refresh ()
5246 "Refresh installed candidates list."
5247 (setq anything-c-apt-installed-packages nil)
5248 (anything-force-update))
5250 (defun anything-c-apt-persistent-action (candidate)
5251 "Persistent action for APT source."
5252 (if current-prefix-arg
5253 (anything-c-apt-refresh)
5254 (anything-c-apt-cache-show candidate)))
5256 ;;;###autoload
5257 (defun anything-apt (query)
5258 "Preconfigured `anything' : frontend of APT package manager."
5259 (interactive "sAPT search: ")
5260 (let ((anything-c-apt-query query))
5261 (anything 'anything-c-source-apt)))
5263 (defun anything-c-apt-candidate-transformer (candidates)
5264 "Show installed candidates in a different color."
5265 (loop
5266 with all
5267 for cand in candidates
5268 for name = (anything-c-apt-display-to-real cand)
5269 if (member name anything-c-apt-installed-packages)
5270 collect (propertize cand 'face 'anything-apt-installed) into all
5271 else collect cand into all finally return all))
5273 (defun anything-c-apt-init ()
5274 "Initialize list of debian packages."
5275 (unless anything-c-apt-installed-packages
5276 (message "Updating installed candidate list...")
5277 (setq anything-c-apt-installed-packages
5278 (with-temp-buffer
5279 (call-process-shell-command "dpkg --get-selections"
5280 nil (current-buffer))
5281 (loop for i in (split-string (buffer-string) "\n" t)
5282 collect (car (split-string i))))))
5283 (with-current-buffer
5284 (anything-candidate-buffer
5285 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
5286 (erase-buffer)
5287 (call-process-shell-command
5288 (format anything-c-apt-search-command anything-c-apt-query)
5289 nil (current-buffer)))
5290 (message "Updating installed candidate list...done"))
5292 (defun anything-c-apt-display-to-real (line)
5293 "Return only name of a debian package.
5294 LINE is displayed like:
5295 package name - description."
5296 (car (split-string line " - ")))
5298 ;;;###autoload
5299 (defun anything-c-shell-command-if-needed (command)
5300 (interactive "sShell command: ")
5301 (if (get-buffer command) ; if the buffer already exists
5302 (switch-to-buffer command) ; then just switch to it
5303 (switch-to-buffer command) ; otherwise create it
5304 (insert (shell-command-to-string command))))
5306 (defun anything-c-apt-cache-show (package)
5307 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
5309 (defun anything-c-apt-install (package)
5310 (anything-c-apt-install1 package :action 'install))
5312 (defun anything-c-apt-uninstall (package)
5313 (anything-c-apt-install1 package :action 'uninstall))
5315 (defun anything-c-apt-purge (package)
5316 (anything-c-apt-install1 package :action 'purge))
5318 (defun* anything-c-apt-install1 (candidate &key action)
5319 (ansi-term (getenv "SHELL") "anything apt")
5320 (term-line-mode)
5321 (let ((command (case action
5322 ('install "sudo apt-get install '%s'")
5323 ('uninstall "sudo apt-get remove '%s'")
5324 ('purge "sudo apt-get purge '%s'")
5325 (t (error "Unknow action"))))
5326 (beg (point)) end)
5327 (goto-char (point-max))
5328 (insert (format command candidate))
5329 (setq end (point))
5330 (if (y-or-n-p (format "%s package" (symbol-name action)))
5331 (progn
5332 (setq anything-c-external-commands-list nil)
5333 (setq anything-c-apt-installed-packages nil)
5334 (term-char-mode) (term-send-input))
5335 (delete-region beg end) (term-send-eof) (kill-buffer))))
5337 ;; (anything-c-apt-install "jed")
5339 ;;; Sources for gentoo users
5340 (defvar anything-c-gentoo-use-flags nil)
5341 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
5342 (defvar anything-c-cache-gentoo nil)
5343 (defvar anything-c-cache-world nil)
5344 (defvar anything-c-source-gentoo
5345 '((name . "Portage sources")
5346 (init . (lambda ()
5347 (get-buffer-create anything-c-gentoo-buffer)
5348 (unless anything-c-cache-gentoo
5349 (anything-c-gentoo-setup-cache))
5350 (unless anything-c-cache-world
5351 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
5352 (anything-c-gentoo-init-list)))
5353 (candidates-in-buffer)
5354 (match . identity)
5355 (candidate-transformer anything-c-highlight-world)
5356 (action . (("Show package" . (lambda (elm)
5357 (anything-c-gentoo-eshell-action elm "eix")))
5358 ("Show history" . (lambda (elm)
5359 (if (member elm anything-c-cache-world)
5360 (anything-c-gentoo-eshell-action elm "genlop -qe")
5361 (message "No infos on packages not yet installed"))))
5362 ("Copy in kill-ring" . kill-new)
5363 ("insert at point" . insert)
5364 ("Browse HomePage" . (lambda (elm)
5365 (let ((urls (anything-c-gentoo-get-url elm)))
5366 (browse-url (anything-comp-read "Url: " urls :must-match t)))))
5367 ("Show extra infos" . (lambda (elm)
5368 (if (member elm anything-c-cache-world)
5369 (anything-c-gentoo-eshell-action elm "genlop -qi")
5370 (message "No infos on packages not yet installed"))))
5371 ("Show use flags" . (lambda (elm)
5372 (anything-c-gentoo-default-action elm "equery" "-C" "u")
5373 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
5374 (font-lock-mode 1)))
5375 ("Run emerge pretend" . (lambda (elm)
5376 (anything-c-gentoo-eshell-action elm "emerge -p")))
5377 ("Emerge" . (lambda (elm)
5378 (anything-gentoo-install elm :action 'install)))
5379 ("Unmerge" . (lambda (elm)
5380 (anything-gentoo-install elm :action 'uninstall)))
5381 ("Show dependencies" . (lambda (elm)
5382 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
5383 ("Show related files" . (lambda (elm)
5384 (anything-c-gentoo-default-action elm "equery" "files")))
5385 ("Refresh" . (lambda (elm)
5386 (anything-c-gentoo-setup-cache)
5387 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
5389 ;; (anything 'anything-c-source-gentoo)
5391 (defun* anything-gentoo-install (candidate &key action)
5392 (setq anything-c-external-commands-list nil)
5393 (ansi-term (getenv "SHELL") "anything gentoo")
5394 (term-line-mode)
5395 (let ((command (case action
5396 ('install "sudo emerge -av ")
5397 ('uninstall "sudo emerge -avC ")
5398 (t (error "Unknow action"))))
5399 (elms (mapconcat 'identity (anything-marked-candidates) " "))
5400 (beg (point)) end)
5401 (goto-char (point-max))
5402 (insert (concat command elms))
5403 (setq end (point))
5404 (term-char-mode) (term-send-input)))
5406 (defun anything-c-gentoo-default-action (elm command &rest args)
5407 "Gentoo default action that use `anything-c-gentoo-buffer'."
5408 (if (member elm anything-c-cache-world)
5409 (progn
5410 (switch-to-buffer anything-c-gentoo-buffer)
5411 (erase-buffer)
5412 (let ((com-list (append args (list elm))))
5413 (apply #'call-process command nil t nil
5414 com-list)))
5415 (message "No infos on packages not yet installed")))
5417 (defvar anything-c-source-use-flags
5418 '((name . "Use Flags")
5419 (init . (lambda ()
5420 (unless anything-c-gentoo-use-flags
5421 (anything-c-gentoo-setup-use-flags-cache))
5422 (anything-c-gentoo-get-use)))
5423 (candidates-in-buffer)
5424 (match . identity)
5425 (candidate-transformer anything-c-highlight-local-use)
5426 (action . (("Description"
5427 . (lambda (elm)
5428 (switch-to-buffer anything-c-gentoo-buffer)
5429 (erase-buffer)
5430 (apply #'call-process "euse" nil t nil
5431 `("-i"
5432 ,elm))
5433 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
5434 (font-lock-mode 1)))
5435 ("Enable"
5436 . (lambda (elm)
5437 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
5438 ("Disable"
5439 . (lambda (elm)
5440 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
5441 ("Remove"
5442 . (lambda (elm)
5443 (anything-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
5444 ("Show which dep use this flag"
5445 . (lambda (elm)
5446 (switch-to-buffer anything-c-gentoo-buffer)
5447 (erase-buffer)
5448 (apply #'call-process "equery" nil t nil
5449 `("-C"
5451 ,elm))))))))
5454 ;; (anything 'anything-c-source-use-flags)
5456 (defun anything-c-gentoo-init-list ()
5457 "Initialize buffer with all packages in Portage."
5458 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
5459 (buf (anything-candidate-buffer 'portage-buf)))
5460 (with-current-buffer buf
5461 (dolist (i anything-c-cache-gentoo)
5462 (insert (concat i "\n"))))))
5464 (defun anything-c-gentoo-setup-cache ()
5465 "Set up `anything-c-cache-gentoo'"
5466 (setq anything-c-cache-gentoo
5467 (split-string (with-temp-buffer
5468 (call-process "eix" nil t nil
5469 "--only-names")
5470 (buffer-string)))))
5472 (defun anything-c-gentoo-eshell-action (elm command)
5473 (when (get-buffer "*EShell Command Output*")
5474 (kill-buffer "*EShell Command Output*"))
5475 (message "Wait searching...")
5476 (let ((buf-fname (buffer-file-name anything-current-buffer)))
5477 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
5478 (progn
5479 (save-window-excursion
5480 (pop-to-buffer "*scratch*")
5481 (eshell-command (format "%s %s" command elm)))
5482 (pop-to-buffer "*EShell Command Output*"))
5483 (eshell-command (format "%s %s" command elm)))))
5485 (defun anything-c-gentoo-get-use ()
5486 "Initialize buffer with all use flags."
5487 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
5488 (buf (anything-candidate-buffer 'use-buf)))
5489 (with-current-buffer buf
5490 (dolist (i anything-c-gentoo-use-flags)
5491 (insert (concat i "\n"))))))
5494 (defun anything-c-gentoo-setup-use-flags-cache ()
5495 "Setup `anything-c-gentoo-use-flags'"
5496 (setq anything-c-gentoo-use-flags
5497 (split-string (with-temp-buffer
5498 (call-process "eix" nil t nil
5499 "--print-all-useflags")
5500 (buffer-string)))))
5502 (defun anything-c-gentoo-get-url (elm)
5503 "Return a list of urls from eix output."
5504 (loop
5505 with url-list = (split-string
5506 (with-temp-buffer
5507 (call-process "eix" nil t nil
5508 elm "--format" "<homepage>\n")
5509 (buffer-string)))
5510 with all
5511 for i in url-list
5512 when (and (string-match "^http://.*" i)
5513 (not (member i all)))
5514 collect i into all
5515 finally return all))
5517 (defun anything-c-gentoo-get-world ()
5518 "Return list of all installed package on your system."
5519 (split-string (with-temp-buffer
5520 (call-process "qlist" nil t nil
5521 "-I")
5522 (buffer-string))))
5524 (defun anything-c-gentoo-get-local-use ()
5525 (split-string (with-temp-buffer
5526 (call-process "portageq" nil t nil
5527 "envvar"
5528 "USE")
5529 (buffer-string))))
5531 (defface anything-gentoo-match-face '((t (:foreground "red")))
5532 "Face for anything-gentoo installed packages."
5533 :group 'traverse-faces)
5535 (defun anything-c-highlight-world (eix)
5536 "Highlight all installed package."
5537 (loop for i in eix
5538 if (member i anything-c-cache-world)
5539 collect (propertize i 'face 'anything-gentoo-match-face)
5540 else
5541 collect i))
5543 (defun anything-c-highlight-local-use (use-flags)
5544 (let ((local-uses (anything-c-gentoo-get-local-use)))
5545 (loop for i in use-flags
5546 if (member i local-uses)
5547 collect (propertize i 'face 'anything-gentoo-match-face)
5548 else
5549 collect i)))
5551 (defvar anything-c-source-emacs-process
5552 '((name . "Emacs Process")
5553 (candidates . (lambda () (mapcar #'process-name (process-list))))
5554 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
5556 ;; (anything 'anything-c-source-emacs-process)
5558 ;; Run Externals commands within Emacs
5559 (defmacro* anything-comp-hash-get-items (hash-table &key test)
5560 "Get the list of all keys/values of hash-table."
5561 `(let ((li-items ()))
5562 (maphash #'(lambda (x y)
5563 (if ,test
5564 (when (funcall ,test y)
5565 (push (list x y) li-items))
5566 (push (list x y) li-items)))
5567 ,hash-table)
5568 li-items))
5570 (defun anything-comp-read-get-candidates (collection &optional test)
5571 "Convert collection to list.
5572 If collection is an `obarray', a test is maybe needed, otherwise
5573 the list would be incomplete.
5574 See `obarray'."
5575 (cond ((and (listp collection) test)
5576 (loop for i in collection when (funcall test i) collect i))
5577 ((and (eq collection obarray) test)
5578 (loop for s being the symbols of collection
5579 when (funcall test s) collect s))
5580 ((and (vectorp collection) test)
5581 (loop for i across collection when (funcall test i) collect i))
5582 ((vectorp collection)
5583 (loop for i across collection collect i))
5584 ((and (hash-table-p collection) test)
5585 (anything-comp-hash-get-items collection :test test))
5586 ((hash-table-p collection)
5587 (anything-comp-hash-get-items collection))
5588 (t collection)))
5590 (defun* anything-comp-read (prompt collection &key test initial-input
5591 (buffer "*Anything Completions*") must-match
5592 (requires-pattern 0))
5593 "Anything `completing-read' emulation.
5594 Collection can be a list, vector, obarray or hash-table."
5595 (when (get-buffer anything-action-buffer)
5596 (kill-buffer anything-action-buffer))
5597 (or (anything
5598 `((name . "Completions")
5599 (candidates
5600 . (lambda ()
5601 (let ((cands (anything-comp-read-get-candidates collection test)))
5602 (if (or must-match (string= anything-pattern ""))
5603 cands (append (list anything-pattern) cands)))))
5604 (requires-pattern . ,requires-pattern)
5605 (volatile)
5606 (action . (("candidate" . ,'identity))))
5607 initial-input prompt 'noresume nil buffer)
5608 (keyboard-quit)))
5610 (defun anything-c-get-pid-from-process-name (process-name)
5611 "Get pid from running process PROCESS-NAME."
5612 (loop with process-list = (list-system-processes)
5613 for pid in process-list
5614 for process = (assoc-default 'comm (process-attributes pid))
5615 when (and process (string-match process-name process))
5616 return pid))
5619 (defun anything-run-or-raise (exe &optional file)
5620 "Generic command that run asynchronously EXE.
5621 If EXE is already running just jump to his window if `anything-raise-command'
5622 is non--nil.
5623 When FILE argument is provided run EXE with FILE.
5624 In this case EXE must be provided as \"EXE %s\"."
5625 (let ((real-com (car (split-string (replace-regexp-in-string " %s" "" exe)))))
5626 (if (or (get-process real-com)
5627 (anything-c-get-pid-from-process-name real-com))
5628 (if anything-raise-command
5629 (shell-command (format anything-raise-command real-com))
5630 (error "Error: %s is already running" real-com))
5631 (when (member real-com anything-c-external-commands-list)
5632 (message "Starting %s..." real-com)
5633 (if file
5634 (start-process-shell-command real-com nil (format exe file))
5635 (start-process-shell-command real-com nil real-com))
5636 (set-process-sentinel
5637 (get-process real-com)
5638 #'(lambda (process event)
5639 (when (string= event "finished\n")
5640 (when anything-raise-command
5641 (shell-command (format anything-raise-command "emacs")))
5642 (message "%s process...Finished." process))))
5643 (setq anything-c-external-commands-list
5644 (push (pop (nthcdr (anything-c-position
5645 real-com anything-c-external-commands-list
5646 :test 'equal)
5647 anything-c-external-commands-list))
5648 anything-c-external-commands-list))))))
5650 ;;;###autoload
5651 (defun anything-c-run-external-command (program)
5652 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
5653 If program is already running exit with error.
5654 You can set your own list of commands with
5655 `anything-c-external-commands-list'."
5656 (interactive (list
5657 (anything-comp-read
5658 "RunProgram: "
5659 (anything-c-external-commands-list-1 'sort)
5660 :must-match t)))
5661 (anything-run-or-raise program))
5663 (defsubst* anything-c-position (item seq &key (test 'eq))
5664 "A simple and faster replacement of CL `position'."
5665 (loop for i in seq for index from 0
5666 when (funcall test i item) return index))
5668 (defvar anything-c-source-ratpoison-commands
5669 '((name . "Ratpoison Commands")
5670 (init . anything-c-ratpoison-commands-init)
5671 (candidates-in-buffer)
5672 (action ("Execute the command" . anything-c-ratpoison-commands-execute))
5673 (display-to-real . anything-c-ratpoison-commands-display-to-real)
5674 (candidate-number-limit)))
5675 ;; (anything 'anything-c-source-ratpoison-commands)
5677 (defun anything-c-ratpoison-commands-init ()
5678 (unless (anything-candidate-buffer)
5679 (with-current-buffer (anything-candidate-buffer 'global)
5680 ;; with ratpoison prefix key
5681 (save-excursion
5682 (call-process "ratpoison" nil (current-buffer) nil "-c" "help"))
5683 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5684 (replace-match "<ratpoison> \\1: \\2"))
5685 (goto-char (point-max))
5686 ;; direct binding
5687 (save-excursion
5688 (call-process "ratpoison" nil (current-buffer) nil "-c" "help top"))
5689 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t)
5690 (replace-match "\\1: \\2")))))
5692 (defun anything-c-ratpoison-commands-display-to-real (display)
5693 (and (string-match ": " display)
5694 (substring display (match-end 0))))
5696 (defun anything-c-ratpoison-commands-execute (candidate)
5697 (call-process "ratpoison" nil nil nil "-ic" candidate))
5699 ;;;###autoload
5700 (defun anything-ratpoison-commands ()
5701 "Preconfigured `anything' to execute ratpoison commands."
5702 (interactive)
5703 (anything-other-buffer 'anything-c-source-ratpoison-commands
5704 "*anything ratpoison commands*"))
5706 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5707 ;;; Files
5708 (defvar anything-c-external-commands-list nil
5709 "A list of all external commands the user can execute. If this
5710 variable is not set by the user, it will be calculated
5711 automatically.")
5713 (defun anything-c-external-commands-list-1 (&optional sort)
5714 "Returns a list of all external commands the user can execute.
5716 If `anything-c-external-commands-list' is non-nil it will
5717 return its contents. Else it calculates all external commands
5718 and sets `anything-c-external-commands-list'.
5720 The code is ripped out of `eshell-complete-commands-list'."
5721 (if anything-c-external-commands-list
5722 anything-c-external-commands-list
5723 (setq anything-c-external-commands-list
5724 (let* ((paths (split-string (getenv "PATH") path-separator))
5725 (cwd (file-name-as-directory
5726 (expand-file-name default-directory)))
5727 (path "") (comps-in-path ())
5728 (file "") (filepath "") (completions ()))
5729 ;; Go thru each path in the search path, finding completions.
5730 (while paths
5731 (setq path (file-name-as-directory
5732 (expand-file-name (or (car paths) ".")))
5733 comps-in-path
5734 (and (file-accessible-directory-p path)
5735 (file-name-all-completions "" path)))
5736 ;; Go thru each completion found, to see whether it should be
5737 ;; used, e.g. see if it's executable.
5738 (while comps-in-path
5739 (setq file (car comps-in-path)
5740 filepath (concat path file))
5741 (if (and (not (member file completions))
5742 (or (string-equal path cwd)
5743 (not (file-directory-p filepath)))
5744 (file-executable-p filepath))
5745 (setq completions (cons file completions)))
5746 (setq comps-in-path (cdr comps-in-path)))
5747 (setq paths (cdr paths)))
5748 (if sort
5749 (sort completions #'(lambda (x y) (string< x y)))
5750 completions)))))
5752 (defun anything-c-file-buffers (filename)
5753 "Returns a list of buffer names corresponding to FILENAME."
5754 (let ((name (expand-file-name filename))
5755 (buf-list ()))
5756 (dolist (buf (buffer-list) buf-list)
5757 (let ((bfn (buffer-file-name buf)))
5758 (when (and bfn (string= name bfn))
5759 (push (buffer-name buf) buf-list))))))
5761 (defun anything-c-delete-file (file)
5762 "Delete the given file after querying the user.
5763 Ask to kill buffers associated with that file, too."
5764 (let ((buffers (anything-c-file-buffers file)))
5765 (dired-delete-file file 'dired-recursive-deletes)
5766 (when buffers
5767 (dolist (buf buffers)
5768 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
5769 (kill-buffer buf))))))
5771 (defun anything-get-mailcap-for-file (filename)
5772 "Get the command to use for FILENAME from mailcap files.
5773 The command is like <command %s> and is meant to use with `format'."
5774 (mailcap-parse-mailcaps)
5775 (let* ((ext (file-name-extension filename))
5776 (mime (when ext (mailcap-extension-to-mime ext))))
5777 (when mime (mailcap-mime-info mime))))
5779 (defun anything-c-open-file-externally (file)
5780 "Open FILE with an external tool found in .mailcap file.
5781 If not found or a prefix arg is given query the user which tool to use."
5782 (let* ((fname (expand-file-name file))
5783 (collection (anything-c-external-commands-list-1 'sort))
5784 (def-prog (anything-get-mailcap-for-file fname))
5785 (program (or (unless (or anything-current-prefix-arg
5786 (not def-prog))
5787 def-prog)
5788 (concat
5789 (anything-comp-read
5790 "Program: "
5791 collection :must-match t)
5792 " %s"))))
5793 (anything-run-or-raise program file)))
5795 ;;;###autoload
5796 (defun w32-shell-execute-open-file (file)
5797 (interactive "fOpen file:")
5798 (with-no-warnings
5799 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
5800 "/" "\\"
5801 (replace-regexp-in-string ; strip cygdrive paths
5802 "/cygdrive/\\(.\\)" "\\1:"
5803 file nil nil) nil t))))
5805 (defun anything-c-open-file-with-default-tool (file)
5806 "Open FILE with the default tool on this platform."
5807 (if (eq system-type 'windows-nt)
5808 (w32-shell-execute-open-file file)
5809 (start-process "anything-c-open-file-with-default-tool"
5811 (cond ((eq system-type 'gnu/linux)
5812 "xdg-open")
5813 ((or (eq system-type 'darwin) ;; Mac OS X
5814 (eq system-type 'macos)) ;; Mac OS 9
5815 "open"))
5816 file)))
5818 (defun anything-c-open-dired (file)
5819 "Opens a dired buffer in FILE's directory. If FILE is a
5820 directory, open this directory."
5821 (if (file-directory-p file)
5822 (dired file)
5823 (dired (file-name-directory file))
5824 (dired-goto-file file)))
5826 (defun anything-c-display-to-real-line (candidate)
5827 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
5828 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
5829 (error "Line number not found")))
5831 (defun anything-c-action-line-goto (lineno-and-content)
5832 (apply #'anything-goto-file-line (anything-interpret-value (anything-attr 'target-file))
5833 (append lineno-and-content
5834 (list (if (and (anything-attr-defined 'target-file)
5835 (not anything-in-persistent-action))
5836 'find-file-other-window
5837 'find-file)))))
5839 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
5840 (apply #'anything-goto-file-line
5841 (if (stringp file-line-content)
5842 ;; Case: filtered-candidate-transformer is skipped
5843 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content))
5844 file-line-content)))
5846 (require 'compile)
5847 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
5848 (delq nil (mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates)))
5850 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
5851 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate)
5852 (let ((filename (match-string 1 candidate))
5853 (lineno (match-string 2 candidate))
5854 (content (match-string 3 candidate)))
5855 (cons (format "%s:%s\n %s"
5856 (propertize filename 'face compilation-info-face)
5857 (propertize lineno 'face compilation-line-face)
5858 content)
5859 (list (expand-file-name
5860 filename
5861 (or (anything-interpret-value (anything-attr 'default-directory))
5862 (and (anything-candidate-buffer)
5863 (buffer-local-value
5864 'default-directory (anything-candidate-buffer)))))
5865 (string-to-number lineno) content)))))
5867 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
5868 (anything-aif (anything-attr 'before-jump-hook)
5869 (funcall it))
5870 (when file (funcall find-file-function file))
5871 (if (anything-attr-defined 'adjust)
5872 (anything-c-goto-line-with-adjustment lineno content)
5873 (anything-goto-line lineno))
5874 (unless (anything-attr-defined 'recenter)
5875 (set-window-start (get-buffer-window anything-current-buffer) (point)))
5876 (anything-aif (anything-attr 'after-jump-hook)
5877 (funcall it))
5878 (when anything-in-persistent-action
5879 (anything-match-line-color-current-line)))
5881 (defun anything-find-file-as-root (candidate)
5882 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
5884 (defun anything-find-many-files (ignore)
5885 (mapc 'find-file (anything-marked-candidates)))
5887 ;; borrowed from etags.el
5888 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
5889 (defun anything-c-goto-line-with-adjustment (line line-content)
5890 (let ((startpos)
5891 offset found pat)
5892 ;; This constant is 1/2 the initial search window.
5893 ;; There is no sense in making it too small,
5894 ;; since just going around the loop once probably
5895 ;; costs about as much as searching 2000 chars.
5896 (setq offset 1000
5897 found nil
5898 pat (concat (if (eq selective-display t)
5899 "\\(^\\|\^m\\) *" "^ *") ;allow indent
5900 (regexp-quote line-content)))
5901 ;; If no char pos was given, try the given line number.
5902 (setq startpos (progn (anything-goto-line line) (point)))
5903 (or startpos (setq startpos (point-min)))
5904 ;; First see if the tag is right at the specified location.
5905 (goto-char startpos)
5906 (setq found (looking-at pat))
5907 (while (and (not found)
5908 (progn
5909 (goto-char (- startpos offset))
5910 (not (bobp))))
5911 (setq found
5912 (re-search-forward pat (+ startpos offset) t)
5913 offset (* 3 offset))) ; expand search window
5914 (or found
5915 (re-search-forward pat nil t)
5916 (error "not found")))
5917 ;; Position point at the right place
5918 ;; if the search string matched an extra Ctrl-m at the beginning.
5919 (and (eq selective-display t)
5920 (looking-at "\^m")
5921 (forward-char 1))
5922 (beginning-of-line))
5924 (anything-document-attribute 'default-directory "type . file-line"
5925 "`default-directory' to interpret file.")
5926 (anything-document-attribute 'before-jump-hook "type . file-line / line"
5927 "Function to call before jumping to the target location.")
5928 (anything-document-attribute 'after-jump-hook "type . file-line / line"
5929 "Function to call after jumping to the target location.")
5930 (anything-document-attribute 'adjust "type . file-line"
5931 "Search around line matching line contents.")
5932 (anything-document-attribute 'recenter "type . file-line / line"
5933 "`recenter' after jumping.")
5934 (anything-document-attribute 'target-file "type . line"
5935 "Goto line of target-file.")
5937 ;;;###autoload
5938 (defun anything-c-call-interactively (cmd-or-name)
5939 "Execute CMD-OR-NAME as Emacs command.
5940 It is added to `extended-command-history'.
5941 `anything-current-prefix-arg' is used as the command's prefix argument."
5942 (setq extended-command-history
5943 (cons (anything-c-stringify cmd-or-name)
5944 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
5945 (let ((current-prefix-arg anything-current-prefix-arg)
5946 (cmd (anything-c-symbolify cmd-or-name)))
5947 (if (stringp (symbol-function cmd))
5948 (execute-kbd-macro (symbol-function cmd))
5949 (setq this-command cmd)
5950 (call-interactively cmd))))
5952 ;;;###autoload
5953 (defun anything-c-set-variable (var)
5954 "Set value to VAR interactively."
5955 (interactive)
5956 (let ((sym (anything-c-symbolify var)))
5957 (set sym (eval-minibuffer (format "Set %s: " var)
5958 (prin1-to-string (symbol-value sym))))))
5959 ;; (setq hh 12)
5960 ;; (anything-c-set-variable 'hh)
5962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5963 (defvar anything-match-line-overlay-face nil)
5964 (defvar anything-match-line-overlay nil)
5966 (defun anything-match-line-color-current-line (&optional start end buf face rec)
5967 "Highlight and underline current position"
5968 (let ((args (list (or start (line-beginning-position))
5969 (or end (1+ (line-end-position)))
5970 buf)))
5971 (if (not anything-match-line-overlay)
5972 (setq anything-match-line-overlay (apply 'make-overlay args))
5973 (apply 'move-overlay anything-match-line-overlay args)))
5974 (overlay-put anything-match-line-overlay
5975 'face (or face anything-match-line-overlay-face))
5976 (when rec
5977 (goto-char start)
5978 (recenter)))
5980 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
5982 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
5983 "Face for source header in the anything buffer." :group 'anything)
5985 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
5987 (defun anything-match-line-cleanup ()
5988 (when anything-match-line-overlay
5989 (delete-overlay anything-match-line-overlay)
5990 (setq anything-match-line-overlay nil)))
5992 (defun anything-match-line-update ()
5993 (when anything-match-line-overlay
5994 (delete-overlay anything-match-line-overlay)
5995 (anything-match-line-color-current-line)))
5997 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
5998 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
6000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6001 ;;; Files
6002 (defun anything-c-transform-file-load-el (actions candidate)
6003 "Add action to load the file CANDIDATE if it is an emacs lisp
6004 file. Else return ACTIONS unmodified."
6005 (if (member (file-name-extension candidate) '("el" "elc"))
6006 (append actions '(("Load Emacs Lisp File" . load-file)))
6007 actions))
6009 (defun anything-c-transform-file-browse-url (actions candidate)
6010 "Add an action to browse the file CANDIDATE if it in a html
6011 file or URL. Else return ACTIONS unmodified."
6012 (let ((browse-action '("Browse with Browser" . browse-url)))
6013 (cond ((string-match "^http\\|^ftp" candidate)
6014 (cons browse-action actions))
6015 ((string-match "\\.html?$" candidate)
6016 (append actions (list browse-action)))
6017 (t actions))))
6019 ;;;; Function
6020 (defun anything-c-transform-function-call-interactively (actions candidate)
6021 "Add an action to call the function CANDIDATE interactively if
6022 it is a command. Else return ACTIONS unmodified."
6023 (if (commandp (intern-soft candidate))
6024 (append actions '(("Call Interactively"
6026 anything-c-call-interactively)))
6027 actions))
6029 ;;;; S-Expressions
6030 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
6031 "If CANDIDATE's `car' is a command, then add an action to
6032 evaluate it and put it onto the `command-history'."
6033 (if (commandp (car (read candidate)))
6034 ;; Make it first entry
6035 (cons '("Eval and put onto command-history" .
6036 (lambda (sexp)
6037 (let ((sym (read sexp)))
6038 (eval sym)
6039 (setq command-history
6040 (cons sym command-history)))))
6041 actions)
6042 actions))
6044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6045 ;;; Buffers
6046 (defun anything-c-skip-boring-buffers (buffers)
6047 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
6049 (defun anything-c-skip-current-buffer (buffers)
6050 (if anything-allow-skipping-current-buffer
6051 (remove (buffer-name anything-current-buffer) buffers)
6052 buffers))
6054 (defun anything-c-shadow-boring-buffers (buffers)
6055 "Buffers matching `anything-c-boring-buffer-regexp' will be
6056 displayed with the `file-name-shadow' face if available."
6057 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
6059 ;;; Files
6060 (defun anything-c-shadow-boring-files (files)
6061 "Files matching `anything-c-boring-file-regexp' will be
6062 displayed with the `file-name-shadow' face if available."
6063 (anything-c-shadow-entries files anything-c-boring-file-regexp))
6065 (defun anything-c-skip-boring-files (files)
6066 "Files matching `anything-c-boring-file-regexp' will be skipped."
6067 (anything-c-skip-entries files anything-c-boring-file-regexp))
6068 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6070 (defun anything-c-skip-current-file (files)
6071 "Current file will be skipped."
6072 (remove (buffer-file-name anything-current-buffer) files))
6074 (defun anything-c-w32-pathname-transformer (args)
6075 "Change undesirable features of windows pathnames to ones more acceptable to
6076 other candidate transformers."
6077 (if (eq system-type 'windows-nt)
6078 (mapcar (lambda (x)
6079 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
6080 (mapcar (lambda (y)
6081 (replace-regexp-in-string "\\\\" "/" y)) args))
6082 args))
6084 (defun anything-c-shorten-home-path (files)
6085 "Replaces /home/user with ~."
6086 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6087 (getenv "HOME"))))
6088 (mapcar (lambda (file)
6089 (if (and (stringp file) (string-match home file))
6090 (cons (replace-match "~" nil nil file) file)
6091 file))
6092 files)))
6094 ;;; Functions
6095 (defun anything-c-mark-interactive-functions (functions)
6096 "Mark interactive functions (commands) with (i) after the function name."
6097 (let (list)
6098 (loop for function in functions
6099 do (push (cons (concat function
6100 (when (commandp (intern-soft function)) " (i)"))
6101 function)
6102 list)
6103 finally (return (nreverse list)))))
6105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6106 (defvar anything-c-adaptive-done nil
6107 "nil if history information is not yet stored for the current
6108 selection.")
6110 (defvar anything-c-adaptive-history nil
6111 "Contains the stored history information.
6112 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6114 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
6115 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6116 when anything is started."
6117 (setq anything-c-adaptive-done nil))
6119 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
6120 "Advise `anything-exit-minibuffer' to store history information
6121 when a candidate is selected with RET."
6122 (anything-c-adaptive-store-selection))
6124 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
6125 "Advise `anything-select-action' to store history information
6126 when the user goes to the action list with TAB."
6127 (anything-c-adaptive-store-selection))
6129 (defun anything-c-source-use-adaptative-p (&optional source-name)
6130 "Return current source only if it use adaptative history, nil otherwise."
6131 (let* ((source (or source-name (anything-get-current-source)))
6132 (adapt-source (or (assoc-default 'filtered-candidate-transformer
6133 (assoc (assoc-default 'type source)
6134 anything-type-attributes))
6135 (assoc-default 'candidate-transformer
6136 (assoc (assoc-default 'type source)
6137 anything-type-attributes))
6138 (assoc-default 'filtered-candidate-transformer source)
6139 (assoc-default 'candidate-transformer source))))
6140 (if (listp adapt-source)
6141 (when (member 'anything-c-adaptive-sort adapt-source) source)
6142 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
6144 (defun anything-c-adaptive-store-selection ()
6145 "Store history information for the selected candidate."
6146 (unless anything-c-adaptive-done
6147 (setq anything-c-adaptive-done t)
6148 (let ((source (anything-c-source-use-adaptative-p)))
6149 (when source
6150 (let* ((source-name (or (assoc-default 'type source)
6151 (assoc-default 'name source)))
6152 (source-info (or (assoc source-name anything-c-adaptive-history)
6153 (progn
6154 (push (list source-name) anything-c-adaptive-history)
6155 (car anything-c-adaptive-history))))
6156 (selection (anything-get-selection))
6157 (selection-info (progn
6158 (setcdr source-info
6159 (cons
6160 (let ((found (assoc selection (cdr source-info))))
6161 (if (not found)
6162 ;; new entry
6163 (list selection)
6165 ;; move entry to the beginning of the
6166 ;; list, so that it doesn't get
6167 ;; trimmed when the history is
6168 ;; truncated
6169 (setcdr source-info
6170 (delete found (cdr source-info)))
6171 found))
6172 (cdr source-info)))
6173 (cadr source-info)))
6174 (pattern-info (progn
6175 (setcdr selection-info
6176 (cons
6177 (let ((found (assoc anything-pattern (cdr selection-info))))
6178 (if (not found)
6179 ;; new entry
6180 (cons anything-pattern 0)
6182 ;; move entry to the beginning of the
6183 ;; list, so if two patterns used the
6184 ;; same number of times then the one
6185 ;; used last appears first in the list
6186 (setcdr selection-info
6187 (delete found (cdr selection-info)))
6188 found))
6189 (cdr selection-info)))
6190 (cadr selection-info))))
6192 ;; increase usage count
6193 (setcdr pattern-info (1+ (cdr pattern-info)))
6195 ;; truncate history if needed
6196 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
6197 (setcdr selection-info
6198 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
6200 (if (file-readable-p anything-c-adaptive-history-file)
6201 (load-file anything-c-adaptive-history-file))
6202 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
6204 (defun anything-c-adaptive-save-history ()
6205 "Save history information to file given by `anything-c-adaptive-history-file'."
6206 (interactive)
6207 (with-temp-buffer
6208 (insert
6209 ";; -*- mode: emacs-lisp -*-\n"
6210 ";; History entries used for anything adaptive display.\n")
6211 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
6212 (current-buffer))
6213 (insert ?\n)
6214 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
6215 (unless (interactive-p) 'quiet))))
6217 (defun anything-c-adaptive-sort (candidates source)
6218 "Sort the CANDIDATES for SOURCE by usage frequency.
6219 This is a filtered candidate transformer you can use for the
6220 attribute `filtered-candidate-transformer' of a source in
6221 `anything-sources' or a type in `anything-type-attributes'."
6222 (let* ((source-name (or (assoc-default 'type source)
6223 (assoc-default 'name source)))
6224 (source-info (assoc source-name anything-c-adaptive-history)))
6225 (if (not source-info)
6226 ;; if there is no information stored for this source then do nothing
6227 candidates
6228 ;; else...
6229 (let ((usage
6230 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
6231 ;; pairs
6232 (mapcar (lambda (candidate-info)
6233 (let ((count 0))
6234 (dolist (pattern-info (cdr candidate-info))
6235 (if (not (equal (car pattern-info)
6236 anything-pattern))
6237 (incf count (cdr pattern-info))
6239 ;; if current pattern is equal to the previously
6240 ;; used one then this candidate has priority
6241 ;; (that's why its count is boosted by 10000) and
6242 ;; it only has to compete with other candidates
6243 ;; which were also selected with the same pattern
6244 (setq count (+ 10000 (cdr pattern-info)))
6245 (return)))
6246 (cons (car candidate-info) count)))
6247 (cdr source-info)))
6248 sorted)
6250 ;; sort the list in descending order, so candidates with highest
6251 ;; priorty come first
6252 (setq usage (sort usage (lambda (first second)
6253 (> (cdr first) (cdr second)))))
6255 ;; put those candidates first which have the highest usage count
6256 (dolist (info usage)
6257 (when (member* (car info) candidates
6258 :test 'anything-c-adaptive-compare)
6259 (push (car info) sorted)
6260 (setq candidates (remove* (car info) candidates
6261 :test 'anything-c-adaptive-compare))))
6263 ;; and append the rest
6264 (append (reverse sorted) candidates nil)))))
6266 (defun anything-c-adaptive-compare (x y)
6267 "Compare candidates X and Y taking into account that the
6268 candidate can be in (DISPLAY . REAL) format."
6269 (equal (if (listp x)
6270 (cdr x)
6272 (if (listp y)
6273 (cdr y)
6274 y)))
6276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6277 (defvar anything-outline-goto-near-line-flag t)
6278 (defvar anything-outline-using nil)
6279 (defun anything-after-update-hook--outline ()
6280 (if (and (eq anything-outline-using t)
6281 (eq anything-outline-goto-near-line-flag t))
6282 (anything-outline-goto-near-line)))
6283 (add-hook 'anything-after-update-hook 'anything-after-update-hook--outline)
6285 (defun anything-outline-goto-near-line ()
6286 (with-anything-window
6287 ;; TODO need consideration whether to update position by every input.
6288 (when t ; (equal anything-pattern "")
6289 (anything-goto-line 2)
6290 (let ((lineno (with-current-buffer anything-current-buffer
6291 (line-number-at-pos (car anything-current-position)))))
6292 (block exit
6293 (while (<= (progn (skip-chars-forward " ")
6294 (or (number-at-point) lineno))
6295 lineno)
6296 (forward-line 1)
6297 (when (eobp)
6298 (forward-line -1)
6299 (return-from exit))))
6300 (forward-line -1)
6301 (and (bobp) (forward-line 1))
6302 (and (anything-pos-header-line-p) (forward-line -2))
6303 (anything-mark-current-line)))))
6305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6306 ;; Plug-in: info-index
6307 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
6308 (let (result)
6309 (unless (anything-candidate-buffer)
6310 (save-window-excursion
6311 (info file)
6312 (let (Info-history
6313 (tobuf (anything-candidate-buffer 'global))
6314 (infobuf (current-buffer))
6315 s e)
6316 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
6317 (Info-goto-node node)
6318 (goto-char (point-min))
6319 (while (search-forward "\n* " nil t)
6320 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
6321 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
6322 (setq s (point-at-bol)
6323 e (point-at-eol))
6324 (with-current-buffer tobuf
6325 (insert-buffer-substring infobuf s e)
6326 (insert "\n"))))))))))
6328 (defun anything-c-info-goto (node-line)
6329 (Info-goto-node (car node-line))
6330 (anything-goto-line (cdr node-line)))
6332 (defun anything-c-info-display-to-real (line)
6333 (and (string-match
6334 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
6335 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
6336 (string-to-number (or (match-string 3 line) "1")))))
6338 (defun anything-c-make-info-source (file)
6339 `((name . ,(concat "Info Index: " file))
6340 (info-file . ,file)
6341 (init . anything-c-info-init)
6342 (display-to-real . anything-c-info-display-to-real)
6343 (get-line . buffer-substring)
6344 (candidates-in-buffer)
6345 (action ("Goto node" . anything-c-info-goto))))
6347 (defun anything-compile-source--info-index (source)
6348 (anything-aif (anything-interpret-value (assoc-default 'info-index source))
6349 (anything-c-make-info-source it)
6350 source))
6351 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
6353 (anything-document-attribute 'info-index "info-index plugin"
6354 "Create a source of info index very easily.
6356 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
6358 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
6359 "Index nodes of info file.
6361 If it is omitted, `Info-index-nodes' is used to collect index nodes.
6362 Some info files are missing index specification.
6364 ex. See `anything-c-source-info-screen'.")
6366 ;; Plug-in: candidates-file
6367 (defun anything-compile-source--candidates-file (source)
6368 (if (assoc-default 'candidates-file source)
6369 `((init anything-p-candidats-file-init
6370 ,@(let ((orig-init (assoc-default 'init source)))
6371 (cond ((null orig-init) nil)
6372 ((functionp orig-init) (list orig-init))
6373 (t orig-init))))
6374 (candidates-in-buffer)
6375 ,@source)
6376 source))
6377 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
6379 (defun anything-p-candidats-file-init ()
6380 (destructuring-bind (file &optional updating)
6381 (anything-mklist (anything-attr 'candidates-file))
6382 (setq file (anything-interpret-value file))
6383 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
6384 (when updating
6385 (buffer-disable-undo)
6386 (font-lock-mode -1)
6387 (auto-revert-mode 1)))))
6389 (anything-document-attribute 'candidates-file "candidates-file plugin"
6390 "Use a file as the candidates buffer.
6392 1st argument is a filename, string or function name or variable name.
6393 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
6395 ;; Plug-in: headline
6396 (defun anything-compile-source--anything-headline (source)
6397 (if (assoc-default 'headline source)
6398 (append '((init . anything-headline-init)
6399 (get-line . buffer-substring)
6400 (type . line))
6401 source
6402 '((candidates-in-buffer)
6403 (persistent-help . "Show this line")))
6404 source))
6405 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
6407 (defun anything-headline-init ()
6408 (when (and (anything-current-buffer-is-modified)
6409 (with-current-buffer anything-current-buffer
6410 (eval (or (anything-attr 'condition) t))))
6411 (anything-headline-make-candidate-buffer
6412 (anything-interpret-value (anything-attr 'headline))
6413 (anything-interpret-value (anything-attr 'subexp)))))
6415 (anything-document-attribute 'headline "Headline plug-in"
6416 "Regexp string for anything-headline to scan.")
6417 (anything-document-attribute 'condition "Headline plug-in"
6418 "A sexp representing the condition to use anything-headline.")
6419 (anything-document-attribute 'subexp "Headline plug-in"
6420 "Display (match-string-no-properties subexp).")
6423 (defun anything-headline-get-candidates (regexp subexp)
6424 (with-current-buffer anything-current-buffer
6425 (save-excursion
6426 (goto-char (point-min))
6427 (if (functionp regexp) (setq regexp (funcall regexp)))
6428 (let (hierarchy curhead)
6429 (flet ((matched ()
6430 (if (numberp subexp)
6431 (cons (match-string-no-properties subexp) (match-beginning subexp))
6432 (cons (buffer-substring (point-at-bol) (point-at-eol))
6433 (point-at-bol))))
6434 (hierarchies (headlines)
6435 (1+ (loop for (_ . hierarchy) in headlines
6436 maximize hierarchy)))
6437 (vector-0-n (v n)
6438 (loop for i from 0 to hierarchy
6439 collecting (aref curhead i)))
6440 (arrange (headlines)
6441 (unless (null headlines) ; FIX headlines empty bug!
6442 (loop with curhead = (make-vector (hierarchies headlines) "")
6443 for ((str . pt) . hierarchy) in headlines
6444 do (aset curhead hierarchy str)
6445 collecting
6446 (cons
6447 (format "H%d:%s" (1+ hierarchy)
6448 (mapconcat 'identity (vector-0-n curhead hierarchy) " / "))
6449 pt)))))
6450 (if (listp regexp)
6451 (arrange
6452 (sort
6453 (loop for re in regexp
6454 for hierarchy from 0
6455 do (goto-char (point-min))
6456 appending
6457 (loop
6458 while (re-search-forward re nil t)
6459 collect (cons (matched) hierarchy)))
6460 (lambda (a b) (> (cdar b) (cdar a)))))
6461 (loop while (re-search-forward regexp nil t)
6462 collect (matched))))))))
6465 (defun anything-headline-make-candidate-buffer (regexp subexp)
6466 (with-current-buffer (anything-candidate-buffer 'local)
6467 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
6468 do (insert
6469 (format "%5d:%s\n"
6470 (with-current-buffer anything-current-buffer
6471 (line-number-at-pos pos))
6472 content)))))
6474 (defun anything-headline-goto-position (pos recenter)
6475 (goto-char pos)
6476 (unless recenter
6477 (set-window-start (get-buffer-window anything-current-buffer) (point))))
6479 (defun anything-revert-buffer (candidate)
6480 (with-current-buffer candidate
6481 (when (buffer-modified-p)
6482 (revert-buffer t t))))
6484 (defun anything-revert-marked-buffers (candidate)
6485 (dolist (i (anything-marked-candidates))
6486 (anything-revert-buffer i)))
6488 (defun anything-kill-marked-buffers (candidate)
6489 (dolist (i (anything-marked-candidates))
6490 (kill-buffer i)))
6492 ;; Plug-in: persistent-help
6493 (defun anything-compile-source--persistent-help (source)
6494 (append source '((header-line . anything-persistent-help-string))))
6495 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
6497 (defun anything-persistent-help-string ()
6498 (substitute-command-keys
6499 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
6500 (or (anything-interpret-value (anything-attr 'persistent-help))
6501 (anything-aif (or (assoc-default 'persistent-action
6502 (anything-get-current-source))
6503 (assoc-default 'action
6504 (anything-get-current-source)))
6505 (cond ((symbolp it) (symbol-name it))
6506 ((listp it) (or (ignore-errors (caar it)) ""))))
6508 " (keeping session)")))
6510 (anything-document-attribute 'persistent-help "persistent-help plug-in"
6511 "A string to explain persistent-action of this source.
6512 It also accepts a function or a variable name.")
6514 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
6516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6518 (defun anything-c-find-file-or-marked (candidate)
6519 "Open file CANDIDATE or open anything marked files in background."
6520 (let ((marked (anything-marked-candidates)))
6521 (if (> (length marked) 1)
6522 (dolist (i marked) (find-file-noselect i))
6523 (find-file-at-point candidate))))
6525 ;; FIXME there is a bug in dired that confuse all dired commands
6526 ;; when using this feature, so i suspend it until bug is fixed in emacs.
6528 ;; (defun anything-c-create-dired-on-marked (candidate)
6529 ;; "Create a new dired buffer with only marked candidates."
6530 ;; (let ((marked (anything-marked-candidates))
6531 ;; (buffer-name (read-string "New Dired Buffer: ")))
6532 ;; (dired (cons buffer-name marked))))
6534 (defun anything-delete-marked-files (ignore)
6535 (let* ((files (anything-marked-candidates))
6536 (len (length files)))
6537 (if (not (y-or-n-p
6538 (format "Delete *%s File(s):\n%s"
6540 (mapconcat (lambda (f) (format "- %s\n" f)) files ""))))
6541 (message "(No deletions performed)")
6542 (dolist (i files)
6543 (set-text-properties 0 (length i) nil i)
6544 (anything-c-delete-file i))
6545 (message "%s File(s) deleted" len))))
6547 (defun anything-ediff-marked-buffers (candidate &optional merge)
6548 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
6549 With optional arg `merge' call `ediff-merge-buffers'."
6550 (let ((lg-lst (length (anything-marked-candidates)))
6551 buf1 buf2)
6552 (case lg-lst
6554 (error "Error:You have to mark at least 1 buffer"))
6556 (setq buf1 anything-current-buffer
6557 buf2 (first (anything-marked-candidates))))
6559 (setq buf1 (first (anything-marked-candidates))
6560 buf2 (second (anything-marked-candidates))))
6562 (error "Error:To much buffers marked!")))
6563 (if merge
6564 (ediff-merge-buffers buf1 buf2)
6565 (ediff-buffers buf1 buf2))))
6567 (defun anything-bookmark-get-bookmark-from-name (bmk)
6568 "Return bookmark name even if it is a bookmark with annotation.
6569 e.g prepended with *.
6570 Return nil if bmk is not a valid bookmark."
6571 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
6572 (if (assoc bookmark bookmark-alist)
6573 bookmark
6574 (when (assoc bmk bookmark-alist)
6575 bmk))))
6577 (defun anything-delete-marked-bookmarks (elm)
6578 "Delete this bookmark or all marked bookmarks."
6579 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
6580 (anything-aif (anything-marked-candidates)
6581 (dolist (i it)
6582 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
6583 (bookmark-delete bmk 'batch)))
6584 (bookmark-delete bookmark 'batch))))
6586 (defun anything-require-or-error (feature function)
6587 (or (require feature nil t)
6588 (error "Need %s to use `%s'." feature function)))
6590 (defun anything-find-buffer-on-elscreen (candidate)
6591 "Open buffer in new screen, if marked buffers open all in elscreens."
6592 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
6593 (anything-aif (anything-marked-candidates)
6594 (dolist (i it)
6595 (let ((target-screen (elscreen-find-screen-by-buffer
6596 (get-buffer i) 'create)))
6597 (elscreen-goto target-screen)))
6598 (let ((target-screen (elscreen-find-screen-by-buffer
6599 (get-buffer candidate) 'create)))
6600 (elscreen-goto target-screen))))
6602 (defun anything-elscreen-find-file (file)
6603 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
6604 (elscreen-find-file file))
6606 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6608 ;;;; Type Attributes
6609 (define-anything-type-attribute 'buffer
6610 `((action
6611 ,@(if pop-up-frames
6612 '(("Switch to buffer other window" . switch-to-buffer-other-window)
6613 ("Switch to buffer" . switch-to-buffer))
6614 '(("Switch to buffer" . switch-to-buffer)
6615 ("Switch to buffer other window" . switch-to-buffer-other-window)
6616 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
6617 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
6618 ("Display buffer" . display-buffer)
6619 ("Revert buffer" . anything-revert-buffer)
6620 ("Revert Marked buffers" . anything-revert-marked-buffers)
6621 ("Kill buffer" . kill-buffer)
6622 ("Kill Marked buffers" . anything-kill-marked-buffers)
6623 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
6624 ("Ediff Merge marked buffers" . (lambda (candidate)
6625 (anything-ediff-marked-buffers candidate t))))
6626 (persistent-help . "Show this buffer")
6627 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
6628 "Buffer or buffer name.")
6630 (define-anything-type-attribute 'file
6631 `((action
6632 ,@(if pop-up-frames
6633 '(("Find file other window" . find-file-other-window)
6634 ("Find file(s)" . anything-find-many-files)
6635 ("Find file as root" . anything-find-file-as-root))
6636 '(("Find file" . anything-find-many-files)
6637 ("Find file as root" . anything-find-file-as-root)
6638 ("Find file other window" . find-file-other-window)
6639 ("Find file other frame" . find-file-other-frame)))
6640 ("Open dired in file's directory" . anything-c-open-dired)
6641 ("Delete file(s)" . anything-delete-marked-files)
6642 ("Open file externally" . anything-c-open-file-externally)
6643 ("Open file with default tool" . anything-c-open-file-with-default-tool))
6644 (persistent-help . "Show this file")
6645 (action-transformer anything-c-transform-file-load-el
6646 anything-c-transform-file-browse-url)
6647 (candidate-transformer anything-c-w32-pathname-transformer
6648 anything-c-skip-current-file
6649 anything-c-skip-boring-files
6650 anything-c-shorten-home-path))
6651 "File name.")
6653 (define-anything-type-attribute 'command
6654 `((action ("Call interactively" . anything-c-call-interactively)
6655 ("Describe command" . anything-c-describe-function)
6656 ("Add command to kill ring" . anything-c-kill-new)
6657 ("Go to command's definition" . anything-c-find-function))
6658 ;; Sort commands according to their usage count.
6659 (filtered-candidate-transformer . anything-c-adaptive-sort)
6660 (persistent-action . anything-c-describe-function))
6661 "Command. (string or symbol)")
6663 (define-anything-type-attribute 'function
6664 '((action ("Describe function" . anything-c-describe-function)
6665 ("Add function to kill ring" . anything-c-kill-new)
6666 ("Go to function's definition" . anything-c-find-function))
6667 (action-transformer anything-c-transform-function-call-interactively)
6668 (candidate-transformer anything-c-mark-interactive-functions))
6669 "Function. (string or symbol)")
6671 (define-anything-type-attribute 'variable
6672 '((action ("Describe variable" . anything-c-describe-variable)
6673 ("Add variable to kill ring" . anything-c-kill-new)
6674 ("Go to variable's definition" . anything-c-find-variable)
6675 ("Set variable" . anything-c-set-variable)))
6676 "Variable.")
6678 (define-anything-type-attribute 'sexp
6679 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
6680 ("Add s-expression to kill ring" . kill-new))
6681 (action-transformer anything-c-transform-sexp-eval-command-sexp))
6682 "String representing S-Expressions.")
6684 (define-anything-type-attribute 'bookmark
6685 `((action
6686 ("Jump to bookmark" . (lambda (candidate)
6687 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate))
6688 (current-prefix-arg anything-current-prefix-arg))
6689 (bookmark-jump bookmark))
6690 (anything-update)))
6691 ("Jump to BM other window" . (lambda (candidate)
6692 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6693 (bookmark-jump-other-window bookmark))
6694 (anything-update)))
6695 ("Bookmark edit annotation" . (lambda (candidate)
6696 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6697 (bookmark-edit-annotation bookmark))))
6698 ("Bookmark show annotation" . (lambda (candidate)
6699 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6700 (bookmark-show-annotation bookmark))))
6701 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
6702 ,@(when (fboundp 'bmkext-edit-bookmark)
6703 '(("Edit Bookmark" . (lambda (candidate)
6704 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6705 (bmkext-edit-bookmark bookmark))))))
6706 ("Rename bookmark" . (lambda (candidate)
6707 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6708 (bookmark-rename bookmark))))
6709 ("Relocate bookmark" . (lambda (candidate)
6710 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
6711 (bookmark-relocate bookmark))))))
6712 "Bookmark name.")
6714 (define-anything-type-attribute 'line
6715 '((display-to-real . anything-c-display-to-real-line)
6716 (action ("Go to Line" . anything-c-action-line-goto)))
6717 "LINENO:CONTENT string, eg. \" 16:foo\".
6719 Optional `target-file' attribute is a name of target file.
6721 Optional `before-jump-hook' attribute is a function with no
6722 arguments which is called before jumping to position.
6724 Optional `after-jump-hook' attribute is a function with no
6725 arguments which is called after jumping to position.
6727 If `adjust' attribute is specified, searches the line whose
6728 content is CONTENT near the LINENO.
6730 If `recenter' attribute is specified, the line is displayed at
6731 the center of window, otherwise at the top of window.
6734 (define-anything-type-attribute 'file-line
6735 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
6736 (multiline)
6737 (action ("Go to" . anything-c-action-file-line-goto)))
6738 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
6740 Optional `default-directory' attribute is a default-directory
6741 FILENAME is interpreted.
6743 Optional `before-jump-hook' attribute is a function with no
6744 arguments which is called before jumping to position.
6746 Optional `after-jump-hook' attribute is a function with no
6747 arguments which is called after jumping to position.
6749 If `adjust' attribute is specified, searches the line whose
6750 content is CONTENT near the LINENO.
6752 If `recenter' attribute is specified, the line is displayed at
6753 the center of window, otherwise at the top of window.
6756 (define-anything-type-attribute 'timer
6757 '((real-to-display . anything-c-timer-real-to-display)
6758 (action ("Cancel Timer" . cancel-timer)
6759 ("Describe Function" . (lambda (tm) (describe-function (timer--function tm))))
6760 ("Find Function" . (lambda (tm) (find-function (timer--function tm)))))
6761 (persistent-action . (lambda (tm) (describe-function (timer--function tm))))
6762 (persistent-help . "Describe Function"))
6763 "Timer.")
6765 ;;;; Default `anything-sources'
6766 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
6767 ;; tend to invoke M-x anything directly. So I offer default setting.
6768 (setq anything-sources
6769 '(anything-c-source-buffers+
6770 anything-c-source-recentf
6771 anything-c-source-files-in-current-dir+))
6773 ;;;; unit test
6774 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
6775 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6776 (dont-compile
6777 (when (fboundp 'expectations)
6778 (expectations
6779 (desc "candidates-file plug-in")
6780 (expect '(anything-p-candidats-file-init)
6781 (assoc-default 'init
6782 (car (anything-compile-sources
6783 '(((name . "test")
6784 (candidates-file . "test.txt")))
6785 '(anything-compile-source--candidates-file)))))
6786 (expect '(anything-p-candidats-file-init
6787 (lambda () 1))
6788 (assoc-default 'init
6789 (car (anything-compile-sources
6790 '(((name . "test")
6791 (candidates-file . "test.txt")
6792 (init . (lambda () 1))))
6793 '(anything-compile-source--candidates-file)))))
6794 (expect '(anything-p-candidats-file-init
6795 (lambda () 1))
6796 (assoc-default 'init
6797 (car (anything-compile-sources
6798 '(((name . "test")
6799 (candidates-file . "test.txt")
6800 (init (lambda () 1))))
6801 '(anything-compile-source--candidates-file)))))
6802 (desc "anything-c-source-buffers")
6803 (expect '(("Buffers" ("foo" "curbuf")))
6804 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
6805 (let ((anything-c-boring-buffer-regexp
6806 (rx (or
6807 (group bos " ")
6808 "*anything"
6809 ;; echo area
6810 " *Echo Area" " *Minibuf"))))
6811 (flet ((buffer-name (x) x))
6812 (anything-test-candidates 'anything-c-source-buffers))))
6813 (desc "anything-c-stringify")
6814 (expect "str1"
6815 (anything-c-stringify "str1"))
6816 (expect "str2"
6817 (anything-c-stringify 'str2))
6818 (desc "anything-c-symbolify")
6819 (expect 'sym1
6820 (anything-c-symbolify "sym1"))
6821 (expect 'sym2
6822 (anything-c-symbolify 'sym2)))))
6824 (provide 'anything-config)
6826 ;;; Local Variables:
6827 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
6828 ;;; End:
6830 ;; How to save (DO NOT REMOVE!!)
6831 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
6832 ;;; anything-config.el ends here
6834 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
6835 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
6836 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
6837 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
6838 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
6839 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
6840 ;;; LocalWords: dotimes Thierry online vname
6841 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
6842 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
6843 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
6844 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
6845 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
6846 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
6847 ;;; LocalWords: startpos noselect dont desc