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