Merge branch 'master' of ssh://repo.or.cz/srv/git/anything-config
[anything-config.git] / anything-config.el
blob8924ddfebcd167cdd3ee644df1710d8112468977
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 ~ 2009, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009, 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.
54 ;;
55 ;; To configure anything you should setup `anything-sources'
56 ;; with specify source, like below:
58 ;; (setq anything-sources
59 ;; '(anything-c-source-buffers
60 ;; anything-c-source-buffer-not-found
61 ;; anything-c-source-file-name-history
62 ;; anything-c-source-info-pages
63 ;; anything-c-source-info-elisp
64 ;; anything-c-source-man-pages
65 ;; anything-c-source-locate
66 ;; anything-c-source-emacs-commands
67 ;; ))
69 ;; Below are complete source list you can setup in `anything-sources':
71 ;; Buffer:
72 ;; `anything-c-source-buffers' (Buffers)
73 ;; `anything-c-source-buffer-not-found' (Create buffer)
74 ;; `anything-c-source-buffers+' (Buffers)
75 ;; File:
76 ;; `anything-c-source-file-name-history' (File Name History)
77 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
78 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
79 ;; `anything-c-source-file-cache' (File Cache)
80 ;; `anything-c-source-locate' (Locate)
81 ;; `anything-c-source-recentf' (Recentf)
82 ;; `anything-c-source-ffap-guesser' (File at point)
83 ;; `anything-c-source-ffap-line' (File/Lineno at point)
84 ;; Help:
85 ;; `anything-c-source-man-pages' (Manual Pages)
86 ;; `anything-c-source-info-pages' (Info Pages)
87 ;; `anything-c-source-info-elisp' (Info Elisp)
88 ;; `anything-c-source-info-cl' (Info Common-Lisp)
89 ;; Command:
90 ;; `anything-c-source-complex-command-history' (Complex Command History)
91 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
92 ;; `anything-c-source-emacs-commands' (Emacs Commands)
93 ;; `anything-c-source-lacarte' (Lacarte)
94 ;; Function:
95 ;; `anything-c-source-emacs-functions' (Emacs Functions)
96 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
97 ;; Variable:
98 ;; `anything-c-source-emacs-variables' (Emacs Variables)
99 ;; Bookmark:
100 ;; `anything-c-source-bookmarks' (Bookmarks)
101 ;; `anything-c-source-bookmark-set' (Set Bookmark)
102 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
103 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
104 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
105 ;; `anything-c-source-bookmark-regions' (Bookmark Regions)
106 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
107 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
108 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
109 ;; `anything-c-source-bookmark-info' (Bookmark Info)
110 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
111 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
112 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
113 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
114 ;; Library:
115 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
116 ;; Programming:
117 ;; `anything-c-source-imenu' (Imenu)
118 ;; `anything-c-source-ctags' (Exuberant ctags)
119 ;; `anything-c-source-semantic' (Semantic Tags)
120 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
121 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
122 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
123 ;; Color and Face:
124 ;; `anything-c-source-customize-face' (Customize Face)
125 ;; `anything-c-source-colors' (Colors)
126 ;; Search Engine:
127 ;; `anything-c-source-tracker-search' (Tracker Search)
128 ;; `anything-c-source-mac-spotlight' (mdfind)
129 ;; icicle:
130 ;; `anything-c-source-icicle-region' (Icicle Regions)
131 ;; Kill ring:
132 ;; `anything-c-source-kill-ring' (Kill Ring)
133 ;; Mark ring:
134 ;; `anything-c-source-mark-ring' (mark-ring)
135 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
136 ;; Register:
137 ;; `anything-c-source-register' (Registers)
138 ;; Headline Extraction:
139 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
140 ;; `anything-c-source-rd-headline' (RD HeadLine)
141 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
142 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
143 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
144 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
145 ;; `anything-c-source-org-headline' (Org HeadLine)
146 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
147 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
148 ;; `anything-c-source-eev-anchor' (Anchors)
149 ;; Misc:
150 ;; `anything-c-source-picklist' (Picklist)
151 ;; `anything-c-source-bbdb' (BBDB)
152 ;; `anything-c-source-evaluation-result' (Evaluation Result)
153 ;; `anything-c-source-calculation-result' (Calculation Result)
154 ;; `anything-c-source-google-suggest' (Google Suggest)
155 ;; `anything-c-source-surfraw' (Surfraw)
156 ;; `anything-c-source-emms-streams' (Emms Streams)
157 ;; `anything-c-source-emms-dired' (Music Directory)
158 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
159 ;; `anything-c-source-call-source' (Call anything source)
160 ;; `anything-c-source-occur' (Occur)
161 ;; `anything-c-source-create' (Create)
162 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
163 ;; `anything-c-source-elscreen' (Elscreen)
164 ;; System:
165 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
166 ;; `anything-c-source-xfonts' (X Fonts)
167 ;; `anything-c-source-gentoo' (Portage sources)
168 ;; `anything-c-source-use-flags' (Use Flags)
169 ;; `anything-c-source-emacs-process' (Emacs Process)
171 ;;; Commands:
173 ;; Below are complete command list:
175 ;; `anything-for-files'
176 ;; Preconfigured `anything' for opening files.
177 ;; `anything-info-at-point'
178 ;; Preconfigured `anything' for searching info at point.
179 ;; `anything-show-kill-ring'
180 ;; Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
181 ;; `anything-minibuffer-history'
182 ;; Preconfigured `anything' for `minibuffer-history'.
183 ;; `anything-gentoo'
184 ;; Preconfigured `anything' for gentoo linux.
185 ;; `anything-surfraw-only'
186 ;; Preconfigured `anything' for surfraw.
187 ;; `anything-imenu'
188 ;; Preconfigured `anything' for `imenu'.
189 ;; `anything-google-suggest'
190 ;; Preconfigured `anything' for google search with google suggest.
191 ;; `anything-for-buffers'
192 ;; Preconfigured `anything' for buffer.
193 ;; `anything-bbdb'
194 ;; Preconfigured `anything' for BBDB.
195 ;; `anything-locate'
196 ;; Preconfigured `anything' for Locate.
197 ;; `anything-w3m-bookmarks'
198 ;; Preconfigured `anything' for w3m bookmark.
199 ;; `anything-colors'
200 ;; Preconfigured `anything' for color.
201 ;; `anything-bm-list'
202 ;; Preconfigured `anything' for visible bookmarks.
203 ;; `anything-kill-buffers'
204 ;; You can continuously kill buffer you selected.
205 ;; `anything-query-replace-regexp'
206 ;; Drop-in replacement of `query-replace-regexp' with building regexp visually.
207 ;; `anything-regexp'
208 ;; It is like `re-builder'. It helps buliding regexp and replacement.
209 ;; `anything-insert-buffer-name'
210 ;; Insert buffer name.
211 ;; `anything-insert-symbol'
212 ;; Insert current symbol.
213 ;; `anything-insert-selection'
214 ;; Insert current selection.
215 ;; `anything-show-buffer-only'
216 ;; [OBSOLETE] Only show sources about buffer.
217 ;; `anything-show-bbdb-only'
218 ;; [OBSOLETE] Only show sources about BBDB.
219 ;; `anything-show-locate-only'
220 ;; [OBSOLETE] Only show sources about Locate.
221 ;; `anything-show-info-only'
222 ;; [OBSOLETE] Only show sources about Info.
223 ;; `anything-show-imenu-only'
224 ;; [OBSOLETE] Only show sources about Imenu.
225 ;; `anything-show-files-only'
226 ;; [OBSOLETE] Only show sources about File.
227 ;; `anything-show-w3m-bookmarks-only'
228 ;; [OBSOLETE] Only show source about w3m bookmark.
229 ;; `anything-show-colors-only'
230 ;; [OBSOLETE] Only show source about color.
231 ;; `anything-show-kill-ring-only'
232 ;; [OBSOLETE] Only show source about kill ring.
233 ;; `anything-show-this-source-only'
234 ;; Only show this source.
235 ;; `anything-test-sources'
236 ;; List all anything sources for test.
237 ;; `anything-select-source'
238 ;; Select source.
239 ;; `anything-bookmark-ext'
240 ;; Preconfigured anything for bookmark-extensions sources.
241 ;; `anything-mark-ring'
242 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
243 ;; `anything-global-mark-ring'
244 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
245 ;; `anything-yaoddmuse-cache-pages'
246 ;; Fetch the list of files on emacswiki and create cache file.
247 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
248 ;; Edit or View EmacsWiki page.
249 ;; `anything-yaoddmuse-emacswiki-post-library'
250 ;; Post library to EmacsWiki.
251 ;; `anything-emms-stream-edit-bookmark'
252 ;; Change the information of current emms-stream bookmark from anything.
253 ;; `anything-emms-stream-delete-bookmark'
254 ;; Delete an emms-stream bookmark from anything.
255 ;; `anything-call-source'
256 ;; Call anything source.
257 ;; `anything-call-source-from-anything'
258 ;; Call anything source within `anything' session.
259 ;; `anything-create-from-anything'
260 ;; Run `anything-create' from `anything' as a fallback.
261 ;; `anything-create'
262 ;; Do many create actions from STRING.
263 ;; `anything-c-set-variable'
264 ;; Set value to VAR interactively.
265 ;; `anything-c-adaptive-save-history'
266 ;; Save history information to file given by `anything-c-adaptive-history-file'.
268 ;;; Customizable Options:
270 ;; Below are customizable option list:
272 ;; `anything-c-use-standard-keys'
273 ;; Whether use standard keybindings. (no effect)
274 ;; default = nil
275 ;; `anything-c-adaptive-history-file'
276 ;; Path of file where history information is stored.
277 ;; default = "~/.emacs.d/anything-c-adaptive-history"
278 ;; `anything-c-adaptive-history-length'
279 ;; Maximum number of candidates stored for a source.
280 ;; default = 50
281 ;; `anything-c-google-suggest-url'
282 ;; URL used for looking up suggestions.
283 ;; default = "http://www.google.com/complete/search?hl=en&js=true&qu="
284 ;; `anything-c-google-suggest-search-url'
285 ;; URL used for searching.
286 ;; default = "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
287 ;; `anything-c-boring-buffer-regexp'
288 ;; The regexp that match boring buffers.
289 ;; default = (rx (or (group bos " ") "*anything" " *Echo Area" " *Minibuf"))
290 ;; `anything-c-boring-file-regexp'
291 ;; The regexp that match boring files.
292 ;; default = (rx (or (and "/" ... ...) (and line-start ".#") (and ... eol)))
293 ;; `anything-kill-ring-threshold'
294 ;; *Minimum length to be listed by `anything-c-source-kill-ring'.
295 ;; default = 10
296 ;; `anything-su-or-sudo'
297 ;; What command to use for root access.
298 ;; default = "su"
299 ;; `anything-for-files-prefered-list'
300 ;; Your prefered sources to find files.
301 ;; default = (quote (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-source-buffers+ anything-c-source-recentf anything-c-source-bookmarks ...))
302 ;; `anything-create--actions-private'
303 ;; User defined actions for `anything-create' / `anything-c-source-create'.
304 ;; default = nil
305 ;; `anything-allow-skipping-current-buffer'
306 ;; Show current buffer or not in anything buffer
307 ;; default = t
308 ;; `anything-c-enable-eval-defun-hack'
309 ;; *If non-nil, execute `anything' using the source at point when C-M-x is pressed.
310 ;; default = t
312 ;;; Change log:
314 ;; Change log of this file is found at
315 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
317 ;;; Contributors:
319 ;; Tamas Patrovics
320 ;; Tassilo Horn <tassilo@member.fsf.org>
321 ;; Vagn Johansen <gonz808@hotmail.com>
322 ;; Mathias Dahl <mathias.dahl@gmail.com>
323 ;; Bill Clementson <billclem@gmail.com>
324 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
325 ;; Drew Adams <drew.adams@oracle.com>
326 ;; Jason McBrayer <jmcbray@carcosa.net>
327 ;; Andy Stewart <lazycat.manatee@gmail.com>
328 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
329 ;; rubikitch <rubikitch@ruby-lang.org>
330 ;; Scott Vokes <vokes.s@gmail.com>
333 ;;; For Maintainers:
335 ;; Evaluate (anything-c-insert-summary) before commit. This function
336 ;; generates anything-c-source-* list.
338 ;; Install also http://www.emacswiki.org/emacs/auto-document.el
339 ;; And eval it or run interactively.
341 ;; [EVAL IT] (anything-c-insert-summary)
342 ;; [EVAL IT] (auto-document)
344 ;; Please write details documentation about function, then others will
345 ;; read code more easier. -- Andy Stewart
349 ;;; TODO
351 ;; - anything-c-adaptive stores infos for sources/types that don't have
352 ;; set it as `filtered-candidate-transformer'.
354 ;; - Fix documentation, now many functions haven't documentations.
357 ;;; Require
358 (require 'anything)
359 (require 'thingatpt)
361 ;;; Code:
363 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
364 (defgroup anything-config nil
365 "Predefined configurations for `anything.el'."
366 :group 'anything)
368 (defcustom anything-c-use-standard-keys nil
369 "Whether use standard keybindings. (no effect)
371 Key definitions in anything-config.el are removed because
372 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
373 minibuffer history, C-s for isearch, etc.
375 If you use `iswitchb' with `anything',
376 evaluate (anything-iswitchb-setup) . Then some bindings that
377 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
378 history, are removed from `anything-map'. "
379 :type 'boolean
380 :group 'anything-config)
382 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
383 "Path of file where history information is stored."
384 :type 'string
385 :group 'anything-config)
387 (defcustom anything-c-adaptive-history-length 50
388 "Maximum number of candidates stored for a source."
389 :type 'number
390 :group 'anything-config)
392 (defcustom anything-c-google-suggest-url
393 "http://www.google.com/complete/search?hl=en&js=true&qu="
394 "URL used for looking up suggestions."
395 :type 'string
396 :group 'anything-config)
398 (defcustom anything-c-google-suggest-search-url
399 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
400 "URL used for searching."
401 :type 'string
402 :group 'anything-config)
404 (defcustom anything-c-boring-buffer-regexp
405 (rx (or
406 (group bos " ")
407 ;; anything-buffer
408 "*anything"
409 ;; echo area
410 " *Echo Area" " *Minibuf"))
411 "The regexp that match boring buffers.
412 Buffer candidates matching this regular expression will be
413 filtered from the list of candidates if the
414 `anything-c-skip-boring-buffers' candidate transformer is used, or
415 they will be displayed with face `file-name-shadow' if
416 `anything-c-shadow-boring-buffers' is used."
417 :type 'string
418 :group 'anything-config)
419 ;; (string-match anything-c-boring-buffer-regexp "buf")
420 ;; (string-match anything-c-boring-buffer-regexp " hidden")
421 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
423 (defcustom anything-c-boring-file-regexp
424 (rx (or
425 ;; Boring directories
426 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
427 ;; Boring files
428 (and line-start ".#")
429 (and (or ".class" ".la" ".o" "~") eol)))
430 "The regexp that match boring files.
431 File candidates matching this regular expression will be
432 filtered from the list of candidates if the
433 `anything-c-skip-boring-files' candidate transformer is used, or
434 they will be displayed with face `file-name-shadow' if
435 `anything-c-shadow-boring-files' is used."
436 :type 'string
437 :group 'anything-config)
439 (defcustom anything-kill-ring-threshold 10
440 "*Minimum length to be listed by `anything-c-source-kill-ring'."
441 :type 'integer
442 :group 'anything-config)
444 (defcustom anything-su-or-sudo "su"
445 "What command to use for root access."
446 :type 'string
447 :group 'anything-config)
449 (defcustom anything-for-files-prefered-list '(anything-c-source-ffap-line
450 anything-c-source-ffap-guesser
451 anything-c-source-buffers+
452 anything-c-source-recentf
453 anything-c-source-bookmarks
454 anything-c-source-file-cache
455 anything-c-source-files-in-current-dir+
456 anything-c-source-locate)
457 "Your prefered sources to find files."
458 :type 'list
459 :group 'anything-config)
461 (defcustom anything-create--actions-private nil
462 "User defined actions for `anything-create' / `anything-c-source-create'.
463 It is a list of (DISPLAY . FUNCTION) pairs like `action'
464 attribute of `anything-sources'.
466 It is prepended to predefined pairs."
467 :type 'list
468 :group 'anything-config)
470 (defcustom anything-allow-skipping-current-buffer t
471 "Show current buffer or not in anything buffer"
472 :type 'boolean
473 :group 'anything-config)
475 (defcustom anything-c-enable-eval-defun-hack t
476 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
477 This hack is invoked when pressing C-M-x in the form (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
478 :type 'boolean
479 :group 'anything-config)
481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
482 (defun anything-for-files ()
483 "Preconfigured `anything' for opening files.
484 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
485 (interactive)
486 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
488 (defun anything-info-at-point ()
489 "Preconfigured `anything' for searching info at point."
490 (interactive)
491 (anything '(anything-c-source-info-elisp
492 anything-c-source-info-cl
493 anything-c-source-info-pages)
494 (thing-at-point 'symbol) nil nil nil "*anything info*"))
496 (defun anything-show-kill-ring ()
497 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
498 You may bind this command to M-y."
499 (interactive)
500 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
502 (defun anything-minibuffer-history ()
503 "Preconfigured `anything' for `minibuffer-history'."
504 (interactive)
505 (let ((enable-recursive-minibuffers t))
506 (anything-other-buffer 'anything-c-source-minibuffer-history
507 "*anything minibuffer-history*")))
509 (dolist (map (list minibuffer-local-filename-completion-map
510 minibuffer-local-completion-map
511 minibuffer-local-must-match-filename-map
512 minibuffer-local-map
513 minibuffer-local-isearch-map
514 minibuffer-local-must-match-map
515 minibuffer-local-ns-map))
516 (define-key map "\C-r" 'anything-minibuffer-history))
518 (defun anything-gentoo ()
519 "Preconfigured `anything' for gentoo linux."
520 (interactive)
521 (anything-other-buffer '(anything-c-source-gentoo
522 anything-c-source-use-flags)
523 "*anything gentoo*"))
525 (defun anything-surfraw-only ()
526 "Preconfigured `anything' for surfraw.
527 If region is marked set anything-pattern to region.
528 With one prefix arg search symbol at point.
529 With two prefix args allow choosing in which symbol to search."
530 (interactive)
531 (let (search pattern)
532 (cond ((region-active-p)
533 (setq pattern (buffer-substring (region-beginning) (region-end))))
534 ((equal current-prefix-arg '(4))
535 (setq pattern (thing-at-point 'symbol)))
536 ((equal current-prefix-arg '(16))
537 (setq search
538 (intern
539 (completing-read "Search in: "
540 (list "symbol" "sentence" "sexp" "line" "word"))))
541 (setq pattern (thing-at-point search))))
542 (anything 'anything-c-source-surfraw
543 (and pattern (replace-regexp-in-string "\n" "" pattern))
544 nil nil nil "*anything surfraw*")))
546 (defun anything-imenu ()
547 "Preconfigured `anything' for `imenu'."
548 (interactive)
549 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
551 (defun anything-google-suggest ()
552 "Preconfigured `anything' for google search with google suggest."
553 (interactive)
554 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
556 ;;; Converted from anything-show-*-only
557 (defun anything-for-buffers ()
558 "Preconfigured `anything' for buffer."
559 (interactive)
560 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
562 (defun anything-bbdb ()
563 "Preconfigured `anything' for BBDB."
564 (interactive)
565 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
567 (defun anything-locate ()
568 "Preconfigured `anything' for Locate."
569 (interactive)
570 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
572 (defun anything-w3m-bookmarks ()
573 "Preconfigured `anything' for w3m bookmark."
574 (interactive)
575 (anything-other-buffer 'anything-c-source-w3m-bookmarks "*anything w3m bookmarks*"))
577 (defun anything-colors ()
578 "Preconfigured `anything' for color."
579 (interactive)
580 (anything-other-buffer '(anything-c-source-colors anything-c-source-customize-face)
581 "*anything colors*"))
583 (defun anything-bm-list ()
584 "Preconfigured `anything' for visible bookmarks."
585 (interactive)
586 (anything-other-buffer 'anything-c-source-bm "*anything bm list*"))
588 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
589 ;;; kill buffers
590 (defun anything-kill-buffers ()
591 "You can continuously kill buffer you selected."
592 (interactive)
593 (anything
594 '(((name . "Kill Buffers")
595 (candidates . anything-c-buffer-list)
596 (action
597 ("Kill Buffer" . (lambda (candidate)
598 (kill-buffer candidate)
599 (anything-kill-buffers)
600 )))))
601 nil nil))
603 ;;; Regexp
604 (defun anything-query-replace-regexp (&rest args)
605 "Drop-in replacement of `query-replace-regexp' with building regexp visually."
606 (interactive
607 (let ((common
608 (anything-c-regexp-base "Query Replace Regexp: "
609 '((name . "Lines matching Regexp")
610 (action . anything-c-query-replace-args)))))
611 (if (not common)
612 (keyboard-quit))
613 (list (car common) (cadr common) (caddr common)
614 ;; These are done separately here
615 ;; so that command-history will record these expressions
616 ;; rather than the values they had this time.
618 ;; This idea is borrowed from original `query-replace-regexp'.
619 (if (and transient-mark-mode mark-active)
620 (region-beginning))
621 (if (and transient-mark-mode mark-active)
622 (region-end)))))
623 (apply 'query-replace-regexp args))
625 (defun anything-regexp ()
626 "It is like `re-builder'. It helps buliding regexp and replacement."
627 (interactive)
628 (anything-c-regexp-base
629 "Regexp: "
630 '((name . "Regexp Builder")
631 (action
632 ("Kill Regexp as sexp" .
633 (lambda (x) (anything-c-regexp-kill-new (prin1-to-string anything-input))))
634 ("Query Replace Regexp" .
635 (lambda (x) (apply 'query-replace-regexp (anything-c-query-replace-args (point)))))
636 ("Kill Regexp" .
637 (lambda (x) (anything-c-regexp-kill-new anything-input)))))))
639 (defun anything-c-query-replace-args (start-point)
640 ;; create arguments of `query-replace-regexp'.
641 (let ((region-only (and transient-mark-mode mark-active)))
642 (list
643 anything-input
644 (query-replace-read-to anything-input
645 (format "Query replace regexp %s%s%s with: "
646 (if region-only "in region " "")
647 anything-input
648 (if current-prefix-arg "(word) " ""))
650 current-prefix-arg)))
652 (defun anything-c-regexp-get-line (s e)
653 (propertize
654 (apply 'concat
655 ;; Line contents
656 (format "%5d: %s" (line-number-at-pos s) (buffer-substring s e))
657 ;; subexps
658 (loop for i from 0 to (1- (/ (length (match-data)) 2))
659 unless (zerop i)
660 collect (format "\n $%d = %s"
661 i (match-string i))))
662 ;; match beginning
663 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
664 ;; It is implementation problem of candidates-in-buffer.
665 'anything-realvalue
666 (1- s)))
668 (defun anything-c-regexp-persistent-action (txt)
669 (goto-line (anything-aif (string-match "^ *\\([0-9]+\\)" txt)
670 (string-to-number (match-string 1 txt)))))
672 (defun anything-c-regexp-base (prompt attributes)
673 (save-restriction
674 (let ((anything-compile-source-functions
675 ;; rule out anything-match-plugin because the input is one regexp.
676 (delq 'anything-compile-source--match-plugin
677 (copy-sequence anything-compile-source-functions))))
678 (if (and transient-mark-mode mark-active)
679 (narrow-to-region (region-beginning) (region-end)))
680 (anything
681 (list
682 (append
683 '((init . (lambda () (anything-candidate-buffer anything-current-buffer)))
684 (candidates-in-buffer)
685 (get-line . anything-c-regexp-get-line)
686 (persistent-action . anything-c-regexp-persistent-action)
687 (multiline)
688 (delayed))
689 attributes))
690 nil prompt nil nil "*anything regexp*"))))
692 (defun anything-c-regexp-kill-new (input)
693 (kill-new input)
694 (message "Killed: %s" input))
696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
698 (defun anything-insert-buffer-name ()
699 "Insert buffer name."
700 (interactive)
701 (anything-insert-string
702 (with-current-buffer anything-current-buffer
703 (if buffer-file-name (file-name-nondirectory buffer-file-name)
704 (buffer-name)))))
706 (defun anything-insert-symbol ()
707 "Insert current symbol."
708 (interactive)
709 (anything-insert-string
710 (with-current-buffer anything-current-buffer
711 (save-excursion
712 (buffer-substring (beginning-of-thing 'symbol)
713 (end-of-thing 'symbol))))))
715 (defun anything-insert-selection ()
716 "Insert current selection."
717 (interactive)
718 (anything-insert-string
719 (with-current-buffer anything-current-buffer
720 (anything-get-selection))))
722 (defun anything-show-buffer-only ()
723 "[OBSOLETE] Only show sources about buffer.
724 Use `anything-for-buffers' instead."
725 (interactive)
726 (anything-set-source-filter '("Buffers")))
728 (defun anything-show-bbdb-only ()
729 "[OBSOLETE] Only show sources about BBDB.
730 Use `anything-bbdb' instead."
731 (interactive)
732 (anything-set-source-filter '("BBDB")))
734 (defun anything-show-locate-only ()
735 "[OBSOLETE] Only show sources about Locate.
736 Use `anything-locate' instead."
737 (interactive)
738 (anything-set-source-filter '("Locate")))
740 (defun anything-show-info-only ()
741 "[OBSOLETE] Only show sources about Info.
742 Use `anything-info-at-point' instead."
743 (interactive)
744 (anything-set-source-filter '("Info Pages"
745 "Info Elisp"
746 "Info Common-Lisp")))
748 (defun anything-show-imenu-only ()
749 "[OBSOLETE] Only show sources about Imenu.
750 Use `anything-imenu' instead."
751 (interactive)
752 (anything-set-source-filter '("Imenu")))
754 (defun anything-show-files-only ()
755 "[OBSOLETE] Only show sources about File.
756 Use `anything-for-files' instead."
757 (interactive)
758 (anything-set-source-filter '("File Name History"
759 "Files from Current Directory"
760 "Recentf")))
762 (defun anything-show-w3m-bookmarks-only ()
763 "[OBSOLETE] Only show source about w3m bookmark.
764 Use `anything-w3m-bookmarks' instead."
765 (interactive)
766 (anything-set-source-filter '("W3m Bookmarks")))
768 (defun anything-show-colors-only ()
769 "[OBSOLETE] Only show source about color.
770 Use `anything-colors' instead."
771 (interactive)
772 (anything-set-source-filter '("Colors"
773 "Customize Faces")))
775 (defun anything-show-kill-ring-only ()
776 "[OBSOLETE] Only show source about kill ring.
777 Use `anything-show-kill-ring' instead."
778 (interactive)
779 (anything-set-source-filter '("Kill Ring")))
781 (defun anything-show-this-source-only ()
782 "Only show this source."
783 (interactive)
784 (setq anything-candidate-number-limit 9999)
785 (anything-set-source-filter
786 (list (assoc-default 'name (anything-get-current-source)))))
788 (defun anything-test-sources ()
789 "List all anything sources for test.
790 The output is sexps which are evaluated by \\[eval-last-sexp]."
791 (interactive)
792 (with-output-to-temp-buffer "*Anything Test Sources*"
793 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
794 (apropos-internal "^anything-c-source" #'boundp))
795 (pop-to-buffer standard-output)))
797 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
798 ;;; For compatibility
799 (unless (fboundp 'region-active-p)
800 (defun region-active-p ()
801 "Return t if Transient Mark mode is enabled and the mark is active.
803 Most commands that act on the region if it is active and
804 Transient Mark mode is enabled, and on the text near point
805 otherwise, should use `use-region-p' instead. That function
806 checks the value of `use-empty-active-region' as well."
807 (and transient-mark-mode mark-active)))
809 (defun anything-nest (&rest same-as-anything)
810 "Nested `anything'. If you use `anything' within `anything', use it."
811 (with-selected-window (anything-window)
812 (let (anything-current-position
813 anything-current-buffer
814 (orig-anything-buffer anything-buffer)
815 anything-pattern
816 anything-buffer
817 anything-sources
818 anything-compiled-sources
819 anything-buffer-chars-modified-tick
820 (anything-samewindow t)
821 (enable-recursive-minibuffers t))
822 (unwind-protect
823 (apply #'anything same-as-anything)
824 (anything-initialize-overlays orig-anything-buffer)
825 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
827 (defun anything-displaying-source-names ()
828 "Display sources name."
829 (with-current-buffer anything-buffer
830 (goto-char (point-min))
831 (loop with pos
832 while (setq pos (next-single-property-change (point) 'anything-header))
833 do (goto-char pos)
834 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
835 do (forward-line 1))))
837 (defun anything-select-source ()
838 "Select source."
839 (interactive)
840 (let ((default (assoc-default 'name (anything-get-current-source)))
841 (source-names (anything-displaying-source-names))
842 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
843 (anything-get-sources))))
844 (setq anything-candidate-number-limit 9999)
845 (anything-aif
846 (let (anything-source-filter)
847 (anything-nest '(((name . "Anything Source")
848 (candidates . source-names)
849 (action . identity))
850 ((name . "Anything Source (ALL)")
851 (candidates . all-source-names)
852 (action . identity)))
853 nil "Source: " nil
854 default "*anything select source*"))
855 (anything-set-source-filter (list it))
856 (anything-set-source-filter nil))))
858 (defun anything-insert-string (str)
859 "Insert STR."
860 (delete-minibuffer-contents)
861 (insert str))
863 (defun anything-c-match-on-file-name (candidate)
864 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
865 (string-match anything-pattern (file-name-nondirectory candidate)))
867 (defun anything-c-match-on-directory-name (candidate)
868 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
869 (anything-aif (file-name-directory candidate)
870 (string-match anything-pattern it)))
872 (defun anything-c-string-match (candidate)
873 "Return non-nil if `anything-pattern' match CANDIDATE.
874 The match is done with `string-match'."
875 (string-match anything-pattern candidate))
877 ;; `anything-c-compose' is no more needed, it is for compatibility.
878 (defalias 'anything-c-compose 'anything-compose)
880 (defun anything-c-skip-entries (list regexp)
881 "Remove entries which matches REGEXP from LIST."
882 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
883 list))
885 (defun anything-c-shadow-entries (list regexp)
886 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
887 (mapcar (lambda (file)
888 ;; Add shadow face property to boring files.
889 (let ((face (if (facep 'file-name-shadow)
890 'file-name-shadow
891 ;; fall back to default on XEmacs
892 'default)))
893 (if (string-match regexp file)
894 (setq file (propertize file 'face face))))
895 file)
896 list))
898 (defsubst anything-c-stringify (str-or-sym)
899 "Get string of STR-OR-SYM."
900 (if (stringp str-or-sym)
901 str-or-sym
902 (symbol-name str-or-sym)))
904 (defsubst anything-c-symbolify (str-or-sym)
905 "Get symbol of STR-OR-SYM."
906 (if (symbolp str-or-sym)
907 str-or-sym
908 (intern str-or-sym)))
910 (defun anything-c-describe-function (func)
911 "FUNC is symbol or string."
912 (describe-function (anything-c-symbolify func)))
914 (defun anything-c-describe-variable (var)
915 "VAR is symbol or string."
916 (describe-variable (anything-c-symbolify var)))
918 (defun anything-c-find-function (func)
919 "FUNC is symbol or string."
920 (find-function (anything-c-symbolify func)))
922 (defun anything-c-find-variable (var)
923 "VAR is symbol or string."
924 (find-variable (anything-c-symbolify var)))
926 (defun anything-c-kill-new (string &optional replace yank-handler)
927 "STRING is symbol or string."
928 (kill-new (anything-c-stringify string) replace yank-handler))
930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931 ;; TODO
932 (defvar anything-current-prefix-arg nil
933 "`current-prefix-arg' when selecting action.
934 It is cleared after executing action.")
936 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
937 (unless anything-current-prefix-arg
938 (setq anything-current-prefix-arg current-prefix-arg)))
940 (add-hook 'anything-after-action-hook
941 (lambda () (setq anything-current-prefix-arg nil)))
944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
945 (defadvice eval-defun (after anything-source-hack activate)
946 "See `anything-c-enable-eval-defun-hack'."
947 (when anything-c-enable-eval-defun-hack
948 (let ((varsym (save-excursion
949 (beginning-of-defun)
950 (forward-char 1)
951 (when (memq (read (current-buffer)) '(defvar setq))
952 (read (current-buffer))))))
953 (when (string-match "^anything-c-source-" (symbol-name varsym))
954 (anything varsym)))))
955 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
958 (defun anything-c-create-summary ()
959 "Create `anything' summary."
960 (save-excursion
961 (goto-char (point-min))
962 (loop while (re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$" nil t)
963 collect (cond ((match-beginning 1)
964 (cons 'section (match-string-no-properties 1)))
965 ((match-beginning 2)
966 (cons 'source
967 (cons (match-string-no-properties 2)
968 (assoc-default 'name (symbol-value (intern (match-string-no-properties 2)))))))
969 ((match-beginning 3)
970 (cons 'source
971 (cons (match-string-no-properties 3)
972 (assoc-default 'name (symbol-value (intern (match-string-no-properties 3)))))))))))
974 ;; (find-epp (anything-c-create-summary))
976 (defun anything-c-insert-summary ()
977 "Insert `anything' summary."
978 (save-excursion
979 (goto-char (point-min))
980 (search-forward ";; Below are complete source list you can setup in")
981 (forward-line 1)
982 (delete-region (point)
983 (progn (search-forward ";;; Change log:" nil t)
984 (forward-line -1) (point)))
985 (insert ";;\n")
986 (loop with beg
987 for (kind . value) in (anything-c-create-summary)
988 for i from 0
989 do (cond ((eq kind 'section)
990 (unless (zerop i)
991 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
992 (insert ";; " value ":\n")
993 (setq beg (point)))
995 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
996 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
997 ;; (anything-c-insert-summary)
999 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1000 ;;;; <Buffer>
1001 (defun anything-c-buffer-list ()
1002 "Return the list of names of buffers with boring buffers filtered out.
1003 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1004 The first buffer in the list will be the last recently used
1005 buffer that is not the current buffer."
1006 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1007 (append (cdr buffers) (list (car buffers)))))
1009 (defvar anything-c-source-buffers
1010 '((name . "Buffers")
1011 (candidates . anything-c-buffer-list)
1012 (volatile)
1013 (type . buffer)))
1014 ;; (anything 'anything-c-source-buffers)
1016 (defvar anything-c-source-buffer-not-found
1017 '((name . "Create buffer")
1018 (dummy)
1019 (type . buffer)))
1020 ;; (anything 'anything-c-source-buffer-not-found)
1022 ;;; Buffers+
1023 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1024 "*Face used for directory headings in dired buffers."
1025 :group 'anything)
1027 (defface anything-file-name
1028 '((t (:foreground "Blue")))
1029 "*Face used for file names (without suffixes) in dired buffers."
1030 :group 'anything)
1032 (defface anything-dir-priv
1033 '((t (:foreground "DarkRed" :background "LightGray")))
1034 "*Face used for directory privilege indicator (d) in dired buffers."
1035 :group 'anything)
1037 (defvar anything-c-buffers-face1 'anything-dir-priv)
1038 (defvar anything-c-buffers-face2 'font-lock-type-face)
1039 (defvar anything-c-buffers-face3 'italic)
1040 (eval-when-compile (require 'dired))
1041 (defun anything-c-highlight-buffers (buffers)
1042 (require 'dired)
1043 (loop for i in buffers
1044 if (rassoc (get-buffer i) dired-buffers)
1045 collect (propertize i
1046 'face anything-c-buffers-face1
1047 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1048 if (buffer-file-name (get-buffer i))
1049 collect (propertize i
1050 'face anything-c-buffers-face2
1051 'help-echo (buffer-file-name (get-buffer i)))
1052 if (and (not (rassoc (get-buffer i) dired-buffers))
1053 (not (buffer-file-name (get-buffer i))))
1054 collect (propertize i
1055 'face anything-c-buffers-face3)))
1057 (defvar anything-c-source-buffers+
1058 '((name . "Buffers")
1059 (candidates . anything-c-buffer-list)
1060 (volatile)
1061 (type . buffer)
1062 (candidate-transformer anything-c-skip-current-buffer
1063 anything-c-highlight-buffers
1064 anything-c-skip-boring-buffers)
1065 (persistent-action . anything-c-buffers+-persistent-action)))
1067 (defun anything-c-buffers+-persistent-action (name)
1068 (flet ((kill (item)
1069 (with-current-buffer item
1070 (if (and (buffer-modified-p)
1071 (buffer-file-name (current-buffer)))
1072 (progn
1073 (save-buffer)
1074 (kill-buffer item))
1075 (kill-buffer item))))
1076 (goto (item)
1077 (switch-to-buffer item)))
1078 (if current-prefix-arg
1079 (progn
1080 (kill name)
1081 (anything-delete-current-selection))
1082 (goto name))))
1084 ;; (anything 'anything-c-source-buffers+)
1087 ;;;; <File>
1088 ;;; File name history
1089 (defvar anything-c-source-file-name-history
1090 '((name . "File Name History")
1091 (candidates . file-name-history)
1092 (match anything-c-match-on-file-name
1093 anything-c-match-on-directory-name)
1094 (type . file)))
1095 ;; (anything 'anything-c-source-file-name-history)
1097 ;;; Files in current dir
1098 (defvar anything-c-source-files-in-current-dir
1099 '((name . "Files from Current Directory")
1100 (candidates . (lambda ()
1101 (with-current-buffer anything-current-buffer
1102 (directory-files default-directory))))
1103 ;; volatile is not needed, I think.
1104 (type . file)))
1105 ;; (anything 'anything-c-source-files-in-current-dir)
1107 (defvar anything-c-files-face1 'anything-dir-priv)
1108 (defvar anything-c-files-face2 'anything-file-name)
1109 (defun anything-c-highlight-files (files)
1110 (loop for i in files
1111 if (file-directory-p i)
1112 collect (propertize (file-name-nondirectory i)
1113 'face anything-c-files-face1
1114 'help-echo (expand-file-name i))
1115 else
1116 collect (propertize (file-name-nondirectory i)
1117 'face anything-c-files-face2
1118 'help-echo (expand-file-name i))))
1121 (defvar anything-c-source-files-in-current-dir+
1122 '((name . "Files from Current Directory")
1123 (candidates . (lambda ()
1124 (with-current-buffer anything-current-buffer
1125 (directory-files default-directory t))))
1126 (candidate-transformer anything-c-highlight-files)
1127 ;; volatile is not needed, I think.
1128 (type . file)))
1130 ;; (anything 'anything-c-source-files-in-current-dir+)
1132 ;;; File Cache
1133 (defvar anything-c-source-file-cache-initialized nil)
1135 (defvar anything-c-file-cache-files nil)
1137 (defvar anything-c-source-file-cache
1138 '((name . "File Cache")
1139 (init . (lambda ()
1140 (require 'filecache nil t)
1141 (unless anything-c-source-file-cache-initialized
1142 (setq anything-c-file-cache-files
1143 (loop for item in file-cache-alist append
1144 (destructuring-bind (base &rest dirs) item
1145 (loop for dir in dirs collect
1146 (concat dir base)))))
1147 (defadvice file-cache-add-file (after file-cache-list activate)
1148 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
1149 (setq anything-c-source-file-cache-initialized t))))
1150 (candidates . anything-c-file-cache-files)
1151 (match anything-c-match-on-file-name
1152 anything-c-match-on-directory-name)
1153 (type . file)))
1154 ;; (anything 'anything-c-source-file-cache)
1156 ;;; Locate
1157 (defvar anything-c-locate-options
1158 (cond
1159 ((eq system-type 'darwin) '("locate"))
1160 ((eq system-type 'berkeley-unix) '("locate" "-i"))
1161 (t '("locate" "-i" "-r")))
1162 "A list where the `car' is the name of the locat program followed by options.
1163 The search pattern will be appended, so the
1164 \"-r\" option should be the last option.")
1166 (defvar anything-c-source-locate
1167 '((name . "Locate")
1168 (candidates . (lambda ()
1169 (apply 'start-process "locate-process" nil
1170 (append anything-c-locate-options
1171 (list anything-pattern)))))
1172 (type . file)
1173 (requires-pattern . 3)
1174 (delayed))
1175 "Source for retrieving files matching the current input pattern with locate.")
1176 ;; (anything 'anything-c-source-locate)
1178 ;;; Recentf files
1179 (defvar anything-c-source-recentf
1180 '((name . "Recentf")
1181 (init . (lambda ()
1182 (require 'recentf)
1183 (or recentf-mode (recentf-mode 1))
1184 ;; Big value empowers anything/recentf
1185 (when (and (numberp recentf-max-saved-items)
1186 (<= recentf-max-saved-items 20))
1187 (setq recentf-max-saved-items 500))))
1188 (candidates . recentf-list)
1189 (match anything-c-match-on-file-name
1190 anything-c-match-on-directory-name)
1191 (type . file))
1192 "See (info \"(emacs)File Conveniences\").
1193 if `recentf-max-saved-items' is too small, set it to 500.")
1194 ;; (anything 'anything-c-source-recentf)
1196 ;;; ffap
1197 (eval-when-compile (require 'ffap))
1198 (defvar anything-c-source-ffap-guesser
1199 '((name . "File at point")
1200 (init . (lambda () (require 'ffap)))
1201 (candidates . (lambda ()
1202 (anything-aif
1203 (with-current-buffer anything-current-buffer
1204 (ffap-guesser))
1205 (list it))))
1206 (type . file)))
1207 ;; (anything 'anything-c-source-ffap-guesser)
1209 ;;; ffap with line number
1210 (defun anything-c-ffap-file-line-at-point ()
1211 "Get (FILENAME . LINENO) at point."
1212 (anything-aif (let (ffap-alist) (ffap-file-at-point))
1213 (save-excursion
1214 (beginning-of-line)
1215 (when (and (search-forward it nil t)
1216 (looking-at ":\\([0-9]+\\)"))
1217 (cons it (string-to-number (match-string 1)))))))
1219 (defvar anything-c-ffap-line-location nil
1220 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
1221 It is cleared after jumping line.")
1223 (defun anything-c-ffap-line-candidates ()
1224 (with-current-buffer anything-current-buffer
1225 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
1226 (when anything-c-ffap-line-location
1227 (destructuring-bind (file . line) anything-c-ffap-line-location
1228 (list (cons (format "%s (line %d)" file line) file)))))
1230 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
1231 (defun anything-c-ffap-line-goto-line ()
1232 (when (car anything-c-ffap-line-location)
1233 (unwind-protect
1234 (ignore-errors
1235 (with-selected-window (get-buffer-window
1236 (get-file-buffer (car anything-c-ffap-line-location)))
1237 (goto-line (cdr anything-c-ffap-line-location))))
1238 (setq anything-c-ffap-line-location nil))))
1239 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
1241 (defvar anything-c-source-ffap-line
1242 '((name . "File/Lineno at point")
1243 (init . (lambda () (require 'ffap)))
1244 (candidates . anything-c-ffap-line-candidates)
1245 (type . file)))
1246 ;; (anything 'anything-c-source-ffap-line)
1249 ;;;; <Help>
1250 ;;; Man Pages
1251 (defvar anything-c-man-pages nil
1252 "All man pages on system.
1253 Will be calculated the first time you invoke anything with this
1254 source.")
1256 (defvar anything-c-source-man-pages
1257 `((name . "Manual Pages")
1258 (candidates . (lambda ()
1259 (if anything-c-man-pages
1260 anything-c-man-pages
1261 ;; XEmacs doesn't have a woman :)
1262 (setq anything-c-man-pages
1263 (ignore-errors
1264 (require 'woman)
1265 (woman-file-name "")
1266 (sort (mapcar 'car woman-topic-all-completions)
1267 'string-lessp))))))
1268 (action ("Show with Woman" . woman))
1269 (requires-pattern . 2)))
1270 ;; (anything 'anything-c-source-man-pages)
1272 ;;; Info pages
1273 (defvar anything-c-info-pages nil
1274 "All info pages on system.
1275 Will be calculated the first time you invoke anything with this
1276 source.")
1278 (defvar anything-c-source-info-pages
1279 `((name . "Info Pages")
1280 (candidates . (lambda ()
1281 (if anything-c-info-pages
1282 anything-c-info-pages
1283 (setq anything-c-info-pages
1284 (save-window-excursion
1285 (save-excursion
1286 (require 'info)
1287 (Info-find-node "dir" "top")
1288 (goto-char (point-min))
1289 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
1290 topics)
1291 (while (re-search-forward info-topic-regexp nil t)
1292 (add-to-list 'topics (match-string-no-properties 1)))
1293 (goto-char (point-min))
1294 (Info-exit)
1295 topics)))))))
1296 (action . (("Show with Info" .(lambda (node-str)
1297 (info (replace-regexp-in-string "^[^:]+: "
1299 node-str))))))
1300 (requires-pattern . 2)))
1301 ;; (anything 'anything-c-source-info-pages)
1303 ;; Info Elisp
1304 (defvar anything-c-info-elisp nil)
1305 (defvar anything-c-source-info-elisp
1306 `((name . "Info Elisp")
1307 (init . (lambda ()
1308 (save-window-excursion
1309 (unless anything-c-info-elisp
1310 (with-temp-buffer
1311 (Info-find-node "elisp" "Index")
1312 (setq anything-c-info-elisp (split-string (buffer-string) "\n"))
1313 (Info-exit))))))
1314 (candidates . (lambda ()
1315 (loop for i in anything-c-info-elisp
1316 if (string-match "^* [^ \n]+[^: ]" i)
1317 collect (match-string 0 i))))
1318 (action . (lambda (candidate)
1319 (Info-find-node "elisp" "Index")
1320 (Info-index (replace-regexp-in-string "* " "" candidate))))
1321 (volatile)
1322 (requires-pattern . 2)))
1323 ;; (anything 'anything-c-source-info-elisp)
1325 ;; Info-Common-Lisp
1326 (defvar anything-c-info-cl-fn nil)
1327 (defvar anything-c-source-info-cl
1328 `((name . "Info Common-Lisp")
1329 (init . (lambda ()
1330 (save-window-excursion
1331 (unless anything-c-info-cl-fn
1332 (with-temp-buffer
1333 (Info-find-node "cl" "Function Index")
1334 (setq anything-c-info-cl-fn (split-string (buffer-string) "\n"))
1335 (Info-exit))))))
1336 (candidates . (lambda ()
1337 (loop for i in anything-c-info-cl-fn
1338 if (string-match "^* [^ \n]+[^: ]" i)
1339 collect (match-string 0 i))))
1340 (action . (lambda (candidate)
1341 (Info-find-node "cl" "Function Index")
1342 (Info-index (replace-regexp-in-string "* " "" candidate))))
1343 (volatile)
1344 (requires-pattern . 2)))
1345 ;; (anything 'anything-c-source-info-cl)
1347 ;;;; <Command>
1348 ;;; Complex command history
1349 (defvar anything-c-source-complex-command-history
1350 '((name . "Complex Command History")
1351 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
1352 (type . sexp)))
1353 ;; (anything 'anything-c-source-complex-command-history)
1355 ;;; M-x history
1356 (defvar anything-c-source-extended-command-history
1357 '((name . "Emacs Commands History")
1358 (candidates . extended-command-history)
1359 (type . command)))
1360 ;; (anything 'anything-c-source-extended-command-history)
1362 ;;; Emacs commands
1363 (defvar anything-c-source-emacs-commands
1364 '((name . "Emacs Commands")
1365 (candidates . (lambda ()
1366 (let (commands)
1367 (mapatoms (lambda (a)
1368 (if (commandp a)
1369 (push (symbol-name a)
1370 commands))))
1371 (sort commands 'string-lessp))))
1372 (volatile)
1373 (type . command)
1374 (requires-pattern . 2))
1375 "Source for completing and invoking Emacs commands.
1376 A command is a function with interactive spec that can
1377 be invoked with `M-x'.
1379 To get non-interactive functions listed, use
1380 `anything-c-source-emacs-functions'.")
1381 ;; (anything 'anything-c-source-emacs-commands)
1383 ;;; LaCarte
1384 (defvar anything-c-source-lacarte
1385 '((name . "Lacarte")
1386 (init . (lambda () (require 'lacarte )))
1387 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
1388 (candidate-number-limit . 9999)
1389 (action . anything-c-call-interactively))
1390 "Needs lacarte.el.
1392 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
1393 ;; (anything 'anything-c-source-lacarte)
1395 ;;;; <Function>
1396 ;;; Emacs functions
1397 (defvar anything-c-source-emacs-functions
1398 '((name . "Emacs Functions")
1399 (candidates . (lambda ()
1400 (let (commands)
1401 (mapatoms (lambda (a) (if (functionp a)
1402 (push (symbol-name a) commands))))
1403 (sort commands 'string-lessp))))
1404 (volatile)
1405 (type . function)
1406 (requires-pattern . 2))
1407 "Source for completing Emacs functions.")
1408 ;; (anything 'anything-c-source-emacs-functions)
1410 ;;; With abbrev expansion
1411 ;;; Similar to my exec-abbrev-cmd.el
1412 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
1413 (defvar anything-c-function-abbrev-regexp nil
1414 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
1415 Regexp built from the current `anything-pattern' interpreting it
1416 as abbreviation.
1417 Only for internal use.")
1419 (defun anything-c-match-function-by-abbrev (candidate)
1420 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
1422 Abbreviations are made by taking the first character from each
1423 word in the function's name, e.g. \"bb\" is an abbrev for
1424 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
1425 (string-match anything-c-function-abbrev-regexp candidate))
1427 (defvar anything-c-source-emacs-functions-with-abbrevs
1428 (append anything-c-source-emacs-functions
1429 '((match anything-c-match-function-by-abbrev
1430 anything-c-string-match))
1431 '((init . (lambda ()
1432 (defadvice anything-update
1433 (before anything-c-update-function-abbrev-regexp activate)
1434 (let ((char-list (append anything-pattern nil))
1435 (str "^"))
1436 (dolist (c char-list)
1437 (setq str (concat str (list c) "[^-]*-")))
1438 (setq str (concat (substring str 0 (1- (length str))) "$"))
1439 (setq anything-c-function-abbrev-regexp str))))))))
1440 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
1442 ;;;; <Variable>
1443 ;;; Emacs variables
1444 (defvar anything-c-source-emacs-variables
1445 '((name . "Emacs Variables")
1446 (candidates . (lambda ()
1447 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
1448 (type . variable)
1449 (requires-pattern . 2))
1450 "Source for completing Emacs variables.")
1451 ;; (anything 'anything-c-source-emacs-variables)
1453 ;;;; <Bookmark>
1454 ;;; Bookmarks
1455 (eval-when-compile (require 'bookmark))
1456 (defvar anything-c-source-bookmarks
1457 '((name . "Bookmarks")
1458 (init . (lambda ()
1459 (require 'bookmark)))
1460 (candidates . bookmark-all-names)
1461 (type . bookmark))
1462 "See (info \"(emacs)Bookmarks\").")
1463 ;; (anything 'anything-c-source-bookmarks)
1465 ;;; bookmark-set
1466 (defvar anything-c-source-bookmark-set
1467 '((name . "Set Bookmark")
1468 (dummy)
1469 (action . bookmark-set))
1470 "See (info \"(emacs)Bookmarks\").")
1471 ;; (anything 'anything-c-source-bookmark-set)
1473 ;;; Visible Bookmarks
1474 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
1477 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
1478 (defvar anything-c-source-bm
1479 '((name . "Visible Bookmarks")
1480 (init . anything-c-bm-init)
1481 (candidates-in-buffer)
1482 (type . line))
1483 "Needs bm.el.
1485 http://www.nongnu.org/bm/")
1487 (defun anything-c-bm-init ()
1488 "Init function for `anything-c-source-bm'."
1489 (when (require 'bm nil t)
1490 (with-no-warnings
1491 (let ((bookmarks (bm-lists))
1492 (buf (anything-candidate-buffer 'global)))
1493 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
1494 '< :key 'overlay-start))
1495 (let ((start (overlay-start bm))
1496 (end (overlay-end bm))
1497 (annotation (or (overlay-get bm 'annotation) "")))
1498 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
1499 (let ((str (format "%7d: [%s]: %s\n"
1500 (line-number-at-pos start)
1501 annotation
1502 (buffer-substring start (1- end)))))
1503 (with-current-buffer buf (insert str))))))))))
1505 ;;; Special bookmarks
1506 (defvar anything-c-source-bookmarks-ssh
1507 '((name . "Bookmarks-ssh")
1508 (init . (lambda ()
1509 (require 'bookmark)))
1510 ;; DRY
1511 (candidates . (lambda ()
1512 (let (lis-all lis-ssh)
1513 (setq lis-all (bookmark-all-names))
1514 (setq lis-ssh (loop for i in lis-all
1515 if (string-match "^(ssh)" i)
1516 collect i))
1517 (sort lis-ssh 'string-lessp))))
1518 (type . bookmark))
1519 "See (info \"(emacs)Bookmarks\").")
1520 ;; (anything 'anything-c-source-bookmarks-ssh)
1522 (defvar anything-c-source-bookmarks-su
1523 '((name . "Bookmarks-root")
1524 (init . (lambda ()
1525 (require 'bookmark)))
1526 ;; DRY
1527 (candidates . (lambda ()
1528 (let (lis-all lis-su)
1529 (setq lis-all (bookmark-all-names))
1530 (setq lis-su (loop for i in lis-all
1531 if (string-match (format "^(%s)" anything-su-or-sudo) i)
1532 collect i))
1533 (sort lis-su 'string-lessp))))
1534 (candidate-transformer anything-c-highlight-bookmark-su)
1536 (type . bookmark))
1537 "See (info \"(emacs)Bookmarks\").")
1538 ;; (anything 'anything-c-source-bookmarks-su)
1541 (defun tv-root-logged-p ()
1542 (catch 'break
1543 (dolist (i (mapcar #'buffer-name (buffer-list)))
1544 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
1545 (throw 'break t)))))
1548 (defun anything-c-highlight-bookmark-su (files)
1549 (if (tv-root-logged-p)
1550 (anything-c-highlight-bookmark files)
1551 (anything-c-highlight-not-logged files)))
1553 (defun anything-c-highlight-not-logged (files)
1554 (loop for i in files
1555 collect (propertize i 'face anything-c-bookmarks-face3)))
1557 (defun anything-c-highlight-bookmark (bookmarks)
1558 "Used as `candidate-transformer' to colorize bookmarks.
1559 Work both with standard Emacs bookmarks and bookmark-extensions.el."
1560 (loop for i in bookmarks
1561 for pred = (bookmark-get-filename i)
1562 for bufp = (and (fboundp 'bmkext-get-buffer-name)
1563 (bmkext-get-buffer-name i))
1564 for regp = (and (fboundp 'bmkext-get-end-position)
1565 (bmkext-get-end-position i)
1566 (/= (bookmark-get-position i)
1567 (bmkext-get-end-position i)))
1568 for handlerp = (and (fboundp 'bookmark-get-handler)
1569 (bookmark-get-handler i))
1570 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
1571 (bmkext-w3m-bookmark-p i))
1572 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
1573 (bmkext-gnus-bookmark-p i))
1574 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
1575 (bmkext-man-bookmark-p i))
1576 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
1577 (bmkext-woman-bookmark-p i))
1578 for isannotation = (bookmark-get-annotation i)
1579 ;; Add a * if bookmark have annotation
1580 if (and isannotation (not (string-equal isannotation "")))
1581 do (setq i (concat "*" i))
1582 ;; info buffers
1583 if (eq handlerp 'Info-bookmark-jump)
1584 collect (propertize i 'face 'anything-bmkext-info 'help-echo pred)
1585 ;; w3m buffers
1586 if isw3m
1587 collect (propertize i 'face 'anything-bmkext-w3m 'help-echo pred)
1588 ;; gnus buffers
1589 if isgnus
1590 collect (propertize i 'face 'anything-bmkext-gnus 'help-echo pred)
1591 ;; Man Woman
1592 if (or iswoman isman)
1593 collect (propertize i 'face 'anything-bmkext-man 'help-echo pred)
1594 ;; directories
1595 if (and pred (file-directory-p pred))
1596 collect (propertize i 'face anything-c-bookmarks-face1 'help-echo pred)
1597 ;; regular files with regions saved
1598 if (and pred (not (file-directory-p pred)) (file-exists-p pred) regp)
1599 collect (propertize i 'face 'anything-bmkext-region 'help-echo pred)
1600 ;; regular files
1601 if (and pred (not (file-directory-p pred)) (file-exists-p pred)
1602 (not regp) (not (or iswoman isman)))
1603 collect (propertize i 'face anything-c-bookmarks-face2 'help-echo pred)
1604 ;; buffer non--filename
1605 if (and (fboundp 'bmkext-get-buffer-name) bufp (not (bookmark-get-handler i))
1606 (if pred (not (file-exists-p pred)) (not pred)))
1607 collect (propertize i 'face 'anything-bmkext-no--file)))
1609 ;;; Faces for bookmarks
1610 (defface anything-bmkext-info
1611 '((t (:foreground "green")))
1612 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1613 :group 'anything)
1615 (defface anything-bmkext-w3m
1616 '((t (:foreground "yellow")))
1617 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
1618 :group 'anything)
1620 (defface anything-bmkext-gnus
1621 '((t (:foreground "magenta")))
1622 "*Face used for Gnus bookmarks."
1623 :group 'anything)
1625 (defface anything-bmkext-man
1626 '((t (:foreground "Orange4")))
1627 "*Face used for Woman/man bookmarks."
1628 :group 'anything)
1630 (defface anything-bmkext-region
1631 '((t (:foreground "Indianred2")))
1632 "*Face used for region bookmarks."
1633 :group 'anything)
1635 (defface anything-bmkext-no--file
1636 '((t (:foreground "grey")))
1637 "*Face used for non--file bookmarks."
1638 :group 'anything)
1640 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1641 "Face for su/sudo bookmarks."
1642 :group 'anything)
1644 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
1645 (defvar anything-c-bookmarks-face2 'anything-file-name)
1646 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
1648 (defvar anything-c-source-bookmarks-local
1649 '((name . "Bookmarks-Local")
1650 (init . (lambda ()
1651 (require 'bookmark)))
1652 ;; DRY
1653 (candidates . (lambda ()
1654 (let (lis-all lis-loc)
1655 (setq lis-all (bookmark-all-names))
1656 (setq lis-loc (loop for i in lis-all
1657 if (and (not (string-match "^(ssh)" i))
1658 (not (string-match "^(su)" i)))
1659 collect i))
1660 (sort lis-loc 'string-lessp))))
1661 (candidate-transformer anything-c-highlight-bookmark)
1662 (type . bookmark))
1663 "See (info \"(emacs)Bookmarks\").")
1664 ;; (anything 'anything-c-source-bookmarks-local)
1666 ;;; Sources to filter bookmark-extensions bookmarks.
1667 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
1670 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
1671 "Return a filtered `bookmark-alist' sorted alphabetically."
1672 (loop
1673 with alist = (if args
1674 (apply #'(lambda (x) (funcall fn x)) args)
1675 (funcall fn))
1676 for i in alist
1677 for b = (car i)
1678 collect b into sa
1679 finally return (sort sa 'string-lessp)))
1681 ;; Regions
1682 (defvar anything-c-source-bookmark-regions
1683 '((name . "Bookmark Regions")
1684 (init . (lambda () (require 'bookmark-extensions) (bookmark-maybe-load-default-file)))
1685 (candidates . anything-c-bookmark-region-setup-alist)
1686 (candidate-transformer anything-c-highlight-bookmark)
1687 (type . bookmark)))
1688 ;; (anything 'anything-c-source-bookmark-regions)
1690 (defun anything-c-bookmark-region-setup-alist ()
1691 "Specialized filter function for bookmark+ regions."
1692 (anything-c-bmkext-filter-setup-alist 'bmkext-region-alist-only))
1694 ;; W3m
1695 (defvar anything-c-source-bookmark-w3m
1696 '((name . "Bookmark W3m")
1697 (init . (lambda () (require 'bookmark-extensions) (bookmark-maybe-load-default-file)))
1698 (candidates . anything-c-bookmark-w3m-setup-alist)
1699 (candidate-transformer anything-c-highlight-bookmark)
1700 (type . bookmark)))
1701 ;; (anything 'anything-c-source-bookmark-w3m)
1703 (defun anything-c-bookmark-w3m-setup-alist ()
1704 "Specialized filter function for bookmark+ w3m."
1705 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
1707 ;; Woman Man
1708 (defvar anything-c-source-bookmark-man
1709 '((name . "Bookmark Woman&Man")
1710 (init . (lambda () (require 'bookmark-extensions) (bookmark-maybe-load-default-file)))
1711 (candidates . anything-c-bookmark-man-setup-alist)
1712 (candidate-transformer anything-c-highlight-bookmark)
1713 (type . bookmark)))
1714 ;; (anything 'anything-c-source-bookmark-man)
1716 (defun anything-c-bookmark-man-setup-alist ()
1717 "Specialized filter function for bookmark+ w3m."
1718 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
1719 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
1721 ;; Gnus
1722 (defvar anything-c-source-bookmark-gnus
1723 '((name . "Bookmark Gnus")
1724 (init . (lambda () (require 'bookmark-extensions) (bookmark-maybe-load-default-file)))
1725 (candidates . anything-c-bookmark-gnus-setup-alist)
1726 (candidate-transformer anything-c-highlight-bookmark)
1727 (type . bookmark)))
1728 ;; (anything 'anything-c-source-bookmark-gnus)
1730 (defun anything-c-bookmark-gnus-setup-alist ()
1731 "Specialized filter function for bookmark+ gnus."
1732 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
1734 ;; Info
1735 (defvar anything-c-source-bookmark-info
1736 '((name . "Bookmark Info")
1737 (init . (lambda () (require 'bookmark-extensions) (bookmark-maybe-load-default-file)))
1738 (candidates . anything-c-bookmark-info-setup-alist)
1739 (candidate-transformer anything-c-highlight-bookmark)
1740 (type . bookmark)))
1741 ;; (anything 'anything-c-source-bookmark-info)
1743 (defun anything-c-bookmark-info-setup-alist ()
1744 "Specialized filter function for bookmark+ info."
1745 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
1747 ;; Local Files&directories
1748 (defvar anything-c-source-bookmark-files&dirs
1749 '((name . "Bookmark Files&Directories")
1750 (init . (lambda () (require 'bookmark-extensions) (bookmark-maybe-load-default-file)))
1751 (candidates . anything-c-bookmark-local-files-setup-alist)
1752 (candidate-transformer anything-c-highlight-bookmark)
1753 (type . bookmark)))
1754 ;; (anything 'anything-c-source-bookmark-files&dirs)
1756 (defun anything-c-bookmark-local-files-setup-alist ()
1757 "Specialized filter function for bookmark+ locals files."
1758 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
1760 ;; Su Files&directories
1761 (defun anything-c-highlight-bookmark+-su (bmk)
1762 (if (bmkext-root-or-sudo-logged-p)
1763 (anything-c-highlight-bookmark bmk)
1764 (anything-c-highlight-not-logged bmk)))
1766 (defvar anything-c-source-bookmark-su-files&dirs
1767 '((name . "Bookmark Root-Files&Directories")
1768 (init . (lambda () (require 'bookmark-extensions) (bookmark-maybe-load-default-file)))
1769 (candidates . anything-c-bookmark-su-files-setup-alist)
1770 (candidate-transformer anything-c-highlight-bookmark+-su)
1771 (type . bookmark)))
1772 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
1774 (defun anything-c-bookmark-su-files-setup-alist ()
1775 "Specialized filter function for bookmark+ su/sudo files."
1776 (loop
1777 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
1778 for i in l
1779 for isfile = (bookmark-get-filename i)
1780 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
1781 (save-match-data
1782 (string-match tramp-file-name-regexp isfile)))
1783 for issu = (and istramp
1784 (string-match bmkext-su-or-sudo-regexp isfile))
1785 if issu
1786 collect i))
1788 ;; Ssh Files&directories
1789 (defvar anything-c-source-bookmark-ssh-files&dirs
1790 '((name . "Bookmark Ssh-Files&Directories")
1791 (init . (lambda () (require 'bookmark-extensions) (bookmark-maybe-load-default-file)))
1792 (candidates . anything-c-bookmark-ssh-files-setup-alist)
1793 (type . bookmark)))
1794 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
1796 (defun anything-c-bookmark-ssh-files-setup-alist ()
1797 "Specialized filter function for bookmark+ ssh files."
1798 (loop
1799 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
1800 for i in l
1801 for isfile = (bookmark-get-filename i)
1802 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
1803 (save-match-data
1804 (string-match tramp-file-name-regexp isfile)))
1805 for isssh = (and istramp
1806 (string-match "/ssh:" isfile))
1807 if isssh
1808 collect i))
1810 ;; All bookmark-extensions sources.
1811 (defun anything-bookmark-ext ()
1812 "Preconfigured anything for bookmark-extensions sources.
1813 See: <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>."
1814 (interactive)
1815 (anything '(anything-c-source-bookmark-files&dirs
1816 anything-c-source-bookmark-w3m
1817 anything-c-source-bookmark-gnus
1818 anything-c-source-bookmark-info
1819 anything-c-source-bookmark-man
1820 anything-c-source-bookmark-regions
1821 anything-c-source-bookmark-su-files&dirs
1822 anything-c-source-bookmark-ssh-files&dirs)))
1825 ;; W3m bookmark
1826 (eval-when-compile (require 'w3m-bookmark nil t))
1827 (unless (and (require 'w3m nil t)
1828 (require 'w3m-bookmark nil t))
1829 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
1830 ;; (defvar anything-w3m-bookmarks-regexp ">[^><]+[^</a>]+[a-z)0-9]+")
1832 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1833 "Face for w3m bookmarks" :group 'anything)
1835 (defvar anything-w3m-bookmarks-regexp ">[^><]+.[^</a>]")
1836 (defun anything-w3m-bookmarks-to-alist ()
1837 (let (bookmarks-alist url title)
1838 (with-temp-buffer
1839 (insert-file-contents w3m-bookmark-file) ;; or w3m-bookmark-file
1840 (goto-char (point-min))
1841 (while (not (eobp))
1842 (forward-line)
1843 (when (re-search-forward "href=" nil t)
1844 (beginning-of-line)
1845 (when (re-search-forward "\\(http\\|file\\)://[^>]*" nil t)
1846 (setq url (concat "\"" (match-string 0))))
1847 (beginning-of-line)
1848 (when (re-search-forward anything-w3m-bookmarks-regexp nil t)
1849 (setq title (match-string 0)))
1850 (push (cons title url) bookmarks-alist))))
1851 (reverse bookmarks-alist)))
1853 (defvar anything-c-w3m-bookmarks-alist nil)
1854 (defvar anything-c-source-w3m-bookmarks
1855 '((name . "W3m Bookmarks")
1856 (init . (lambda ()
1857 (setq anything-c-w3m-bookmarks-alist
1858 (anything-w3m-bookmarks-to-alist))))
1859 (candidates . (lambda ()
1860 (mapcar #'car
1861 anything-c-w3m-bookmarks-alist)))
1862 (candidate-transformer anything-c-highlight-w3m-bookmarks)
1863 (action . (("Browse Url" . (lambda (candidate)
1864 (anything-c-w3m-browse-bookmark candidate)))
1865 ("Copy Url" . (lambda (elm)
1866 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
1867 ("Browse Url Firefox" . (lambda (candidate)
1868 (anything-c-w3m-browse-bookmark candidate t)))
1869 ("Delete Bookmark" . (lambda (candidate)
1870 (anything-c-w3m-delete-bookmark candidate)))
1871 ("Rename Bookmark" . (lambda (candidate)
1872 (anything-c-w3m-rename-bookmark candidate)))))
1873 (persistent-action . (lambda (candidate)
1874 (if current-prefix-arg
1875 (anything-c-w3m-browse-bookmark candidate t)
1876 (anything-c-w3m-browse-bookmark candidate nil t))))
1877 (delayed)))
1879 ;; (anything 'anything-c-source-w3m-bookmarks)
1881 (defun anything-c-w3m-bookmarks-get-value (elm)
1882 (replace-regexp-in-string "\"" ""
1883 (cdr (assoc elm
1884 anything-c-w3m-bookmarks-alist))))
1887 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
1888 (let* ((fn (if use-firefox
1889 'browse-url-firefox
1890 'w3m-browse-url))
1891 (arg (and (eq fn 'w3m-browse-url)
1892 new-tab)))
1893 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
1896 (defun anything-c-highlight-w3m-bookmarks (books)
1897 (loop for i in books
1898 collect (propertize i
1899 'face 'anything-w3m-bookmarks-face
1900 'help-echo (anything-c-w3m-bookmarks-get-value i))))
1903 (defun anything-c-w3m-delete-bookmark (elm)
1904 (save-excursion
1905 (find-file-literally w3m-bookmark-file)
1906 (goto-char (point-min))
1907 (when (re-search-forward elm nil t)
1908 (beginning-of-line)
1909 (delete-region (point)
1910 (line-end-position))
1911 (delete-blank-lines))
1912 (save-buffer (current-buffer))
1913 (kill-buffer (current-buffer))))
1915 (defun anything-c-w3m-rename-bookmark (elm)
1916 (let* ((old-title (replace-regexp-in-string ">" "" elm))
1917 (new-title (read-string "NewTitle: " old-title)))
1918 (save-excursion
1919 (find-file-literally w3m-bookmark-file)
1920 (goto-char (point-min))
1921 (when (re-search-forward (concat elm "<") nil t)
1922 (goto-char (1- (point)))
1923 (delete-backward-char (length old-title))
1924 (insert new-title))
1925 (save-buffer (current-buffer))
1926 (kill-buffer (current-buffer)))))
1928 ;;;; <Library>
1929 ;;; Elisp library scan
1930 (defvar anything-c-source-elisp-library-scan
1931 '((name . "Elisp libraries (Scan)")
1932 (init . (anything-c-elisp-library-scan-init))
1933 (candidates-in-buffer)
1934 (action ("Find library" . (lambda (candidate)
1935 (find-file (find-library-name candidate))))
1936 ("Find library other window" . (lambda (candidate)
1937 (find-file-other-window (find-library-name candidate))))
1938 ("Load library" . (lambda (candidate)
1939 (load-library candidate))))))
1940 ;; (anything 'anything-c-source-elisp-library-scan)
1942 (defun anything-c-elisp-library-scan-init ()
1943 "Init anything buffer status."
1944 (let ((anything-buffer (anything-candidate-buffer 'global))
1945 (library-list (anything-c-elisp-library-scan-list)))
1946 (with-current-buffer anything-buffer
1947 (dolist (library library-list)
1948 (insert (format "%s\n" library))))))
1950 (defun anything-c-elisp-library-scan-list (&optional dirs string)
1951 "Do completion for file names passed to `locate-file'.
1952 DIRS is directory to search path.
1953 STRING is string to match."
1954 ;; Use `load-path' as path when ignore `dirs'.
1955 (or dirs (setq dirs load-path))
1956 ;; Init with blank when ignore `string'.
1957 (or string (setq string ""))
1958 ;; Get library list.
1959 (let ((string-dir (file-name-directory string))
1960 ;; File regexp that suffix match `load-file-rep-suffixes'.
1961 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
1962 name
1963 names)
1964 (dolist (dir dirs)
1965 (unless dir
1966 (setq dir default-directory))
1967 (if string-dir
1968 (setq dir (expand-file-name string-dir dir)))
1969 (when (file-directory-p dir)
1970 (dolist (file (file-name-all-completions
1971 (file-name-nondirectory string) dir))
1972 ;; Suffixes match `load-file-rep-suffixes'.
1973 (setq name (if string-dir (concat string-dir file) file))
1974 (if (string-match match-regexp name)
1975 (add-to-list 'names name)))))
1976 names))
1978 ;;;; <Programming>
1979 ;;; Imenu
1980 (defvar anything-c-imenu-delimiter " / ")
1982 (defvar anything-c-imenu-index-filter nil)
1983 (make-variable-buffer-local 'anything-c-imenu-index-filter)
1985 (defvar anything-c-cached-imenu-alist nil)
1986 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
1988 (defvar anything-c-cached-imenu-candidates nil)
1989 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
1991 (defvar anything-c-cached-imenu-tick nil)
1992 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
1994 (eval-when-compile (require 'imenu))
1995 (setq imenu-auto-rescan t)
1997 (defun anything-imenu-create-candidates (entry)
1998 "Create candidates with ENTRY."
1999 (if (listp (cdr entry))
2000 (mapcan (lambda (sub)
2001 (if (consp (cdr sub))
2002 (mapcar
2003 (lambda (subentry)
2004 (concat (car entry) anything-c-imenu-delimiter subentry))
2005 (anything-imenu-create-candidates sub))
2006 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
2007 (cdr entry))
2008 (list entry)))
2010 (defvar anything-c-source-imenu
2011 '((name . "Imenu")
2012 (candidates . anything-c-imenu-candidates)
2013 (volatile)
2014 (persistent-action . (lambda (elm)
2015 (anything-c-imenu-default-action elm)
2016 (unless (fboundp 'semantic-imenu-tag-overlay)
2017 (anything-match-line-color-current-line))))
2018 (action . anything-c-imenu-default-action))
2019 "See (info \"(emacs)Imenu\")")
2021 ;; (anything 'anything-c-source-imenu)
2023 (defun anything-c-imenu-candidates ()
2024 (with-current-buffer anything-current-buffer
2025 (let ((tick (buffer-modified-tick)))
2026 (if (eq anything-c-cached-imenu-tick tick)
2027 anything-c-cached-imenu-candidates
2028 (setq imenu--index-alist nil)
2029 (setq anything-c-cached-imenu-tick tick
2030 anything-c-cached-imenu-candidates
2031 (condition-case nil
2032 (mapcan
2033 'anything-imenu-create-candidates
2034 (setq anything-c-cached-imenu-alist
2035 (let ((index (imenu--make-index-alist)))
2036 (if anything-c-imenu-index-filter
2037 (funcall anything-c-imenu-index-filter index)
2038 index))))
2039 (error nil)))
2040 (setq anything-c-cached-imenu-candidates
2041 (mapcar #'(lambda (x)
2042 (if (stringp x)
2044 (car x)))
2045 anything-c-cached-imenu-candidates))))))
2047 (setq imenu-default-goto-function 'imenu-default-goto-function)
2048 (defun anything-c-imenu-default-action (elm)
2049 "The default action for `anything-c-source-imenu'."
2050 (let ((path (split-string elm anything-c-imenu-delimiter))
2051 (alist anything-c-cached-imenu-alist))
2052 (if (> (length path) 1)
2053 (progn
2054 (setq alist (assoc (car path) alist))
2055 (setq elm (cadr path))
2056 (imenu (assoc elm alist)))
2057 (imenu (assoc elm alist)))))
2059 ;;; Ctags
2060 (defvar anything-c-ctags-modes
2061 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
2062 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
2063 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
2065 (defun anything-c-source-ctags-init ()
2066 (when (and buffer-file-name
2067 (memq major-mode anything-c-ctags-modes)
2068 (anything-current-buffer-is-modified))
2069 (with-current-buffer (anything-candidate-buffer 'local)
2070 (call-process-shell-command
2071 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
2072 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
2073 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
2074 nil (current-buffer))
2075 (goto-char (point-min))
2076 (forward-line 2)
2077 (delete-region (point-min) (point))
2078 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
2079 for lineno-start = (point)
2080 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
2082 (beginning-of-line)
2083 (insert (format "%5s:" lineno))
2084 (search-forward "\177" (point-at-eol) t)
2085 (delete-region (1- (point)) (point-at-eol))
2086 (forward-line 1)))))
2088 (defvar anything-c-source-ctags
2089 '((name . "Exuberant ctags")
2090 (init . anything-c-source-ctags-init)
2091 (candidates-in-buffer)
2092 (adjust)
2093 (type . line))
2094 "Needs Exuberant Ctags.
2096 http://ctags.sourceforge.net/")
2097 ;; (anything 'anything-c-source-ctags)
2099 ;; Semantic
2100 (eval-when-compile (require 'semantic nil t))
2101 (defun anything-semantic-construct-candidates (tags depth)
2102 (when (require 'semantic nil t)
2103 (apply 'append
2104 (mapcar (lambda (tag)
2105 (if (listp tag)
2106 (let ((type (semantic-tag-type tag))
2107 (class (semantic-tag-class tag)))
2108 (if (or (and (stringp type)
2109 (string= type "class"))
2110 (eq class 'function)
2111 (eq class 'variable))
2112 (cons (cons (concat (make-string (* depth 2) ?\s)
2113 (semantic-format-tag-summarize tag nil t)) tag)
2114 (anything-semantic-construct-candidates (semantic-tag-components tag)
2115 (1+ depth)))))))
2116 tags))))
2118 (defun anything-semantic-default-action (candidate)
2119 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
2120 (semantic-go-to-tag tag)))
2122 (defvar anything-c-source-semantic
2123 '((name . "Semantic Tags")
2124 (init . (lambda ()
2125 (setq anything-semantic-candidates
2126 (condition-case nil
2127 (anything-semantic-construct-candidates (semantic-fetch-tags) 0)
2128 (error nil)))))
2129 (candidates . (lambda ()
2130 (if anything-semantic-candidates
2131 (mapcar 'car anything-semantic-candidates))))
2132 (persistent-action . (lambda (elm)
2133 (anything-semantic-default-action elm)
2134 (anything-match-line-color-current-line)))
2135 (action . anything-semantic-default-action)
2136 "Needs semantic in CEDET.
2138 http://cedet.sourceforge.net/semantic.shtml
2139 http://cedet.sourceforge.net/"))
2141 ;; (anything 'anything-c-source-semantic)
2143 ;;; Function is called by
2144 (defvar anything-c-source-simple-call-tree-functions-callers
2145 '((name . "Function is called by")
2146 (init . anything-c-simple-call-tree-functions-callers-init)
2147 (delayed)
2148 (candidates-in-buffer))
2149 "Needs simple-call-tree.el.
2150 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
2152 (defun anything-c-simple-call-tree-functions-callers-init ()
2153 (require 'simple-call-tree)
2154 (with-no-warnings
2155 (when (anything-current-buffer-is-modified)
2156 (simple-call-tree-analyze)
2157 (let ((list (simple-call-tree-invert simple-call-tree-alist)))
2158 (with-current-buffer (anything-candidate-buffer 'local)
2159 (dolist (entry list)
2160 (let ((callers (mapconcat #'identity (cdr entry) ", ")))
2161 (insert (car entry) " is called by "
2162 (if (string= callers "")
2163 "no functions."
2164 callers)
2165 ".\n"))))))))
2166 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
2168 ;;; Function calls
2169 (defvar anything-c-source-simple-call-tree-callers-functions
2170 '((name . "Function calls")
2171 (init . anything-c-simple-call-tree-callers-functions-init)
2172 (delayed)
2173 (candidates-in-buffer))
2174 "Needs simple-call-tree.el.
2175 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
2177 (defun anything-c-simple-call-tree-callers-functions-init ()
2178 (require 'simple-call-tree)
2179 (with-no-warnings
2180 (when (anything-current-buffer-is-modified)
2181 (simple-call-tree-analyze)
2182 (let ((list simple-call-tree-alist))
2183 (with-current-buffer (anything-candidate-buffer 'local)
2184 (dolist (entry list)
2185 (let ((functions (mapconcat #'identity (cdr entry) ", ")))
2186 (insert (car entry) " calls "
2187 (if (string= functions "")
2188 "no functions"
2189 functions)
2190 ".\n"))))))))
2192 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
2194 ;;; Commands/Options with doc
2195 (defvar anything-c-auto-document-data nil)
2196 (make-variable-buffer-local 'anything-c-auto-document-data)
2197 (defvar anything-c-source-commands-and-options-in-file
2198 '((name . "Commands/Options in file")
2199 (header-name
2200 . (lambda (x) (format "Commands/Options in %s"
2201 (buffer-local-value 'buffer-file-name anything-current-buffer))))
2202 (candidates . anything-command-and-options-candidates)
2203 (multiline)
2204 (action . imenu))
2205 "List Commands and Options with doc. It needs auto-document.el .
2207 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
2209 (eval-when-compile (require 'auto-document nil t))
2210 (defun anything-command-and-options-candidates ()
2211 (with-current-buffer anything-current-buffer
2212 (when (and (require 'auto-document nil t)
2213 (eq major-mode 'emacs-lisp-mode)
2214 (or (anything-current-buffer-is-modified)
2215 (not anything-c-auto-document-data)))
2216 (or imenu--index-alist (imenu--make-index-alist t))
2217 (setq anything-c-auto-document-data
2218 (destructuring-bind (commands options)
2219 (adoc-construct anything-current-buffer)
2220 (append
2221 (loop for (command . doc) in commands
2222 for cmdname = (symbol-name command)
2223 collect
2224 (cons (format "Command: %s\n %s"
2225 (propertize cmdname 'face font-lock-function-name-face)
2226 (adoc-first-line doc))
2227 (assoc cmdname imenu--index-alist)))
2228 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
2229 for (option doc default) in options
2230 for optname = (symbol-name option)
2231 collect
2232 (cons (format "Option: %s\n %s\n default = %s"
2233 (propertize optname 'face font-lock-variable-name-face)
2234 (adoc-first-line doc)
2235 (adoc-prin1-to-string default))
2236 (assoc optname
2237 var-alist)))))))
2238 anything-c-auto-document-data))
2240 ;; (anything 'anything-c-source-commands-and-options-in-file)
2242 ;;;; <Color and Face>
2243 ;;; Customize Face
2244 (defvar anything-c-source-customize-face
2245 '((name . "Customize Face")
2246 (init . (lambda ()
2247 (unless (anything-candidate-buffer)
2248 (save-window-excursion (list-faces-display))
2249 (anything-candidate-buffer (get-buffer "*Faces*")))))
2250 (candidates-in-buffer)
2251 (get-line . buffer-substring)
2252 (action . (lambda (line)
2253 (customize-face (intern (car (split-string line))))))
2254 (requires-pattern . 3))
2255 "See (info \"(emacs)Faces\")")
2256 ;; (anything 'anything-c-source-customize-face)
2258 ;; Color
2259 (defvar anything-c-source-colors
2260 '((name . "Colors")
2261 (init . (lambda () (unless (anything-candidate-buffer)
2262 (save-window-excursion (list-colors-display))
2263 (anything-candidate-buffer (get-buffer "*Colors*")))))
2264 (candidates-in-buffer)
2265 (get-line . buffer-substring)
2266 (action ("Copy Name" . (lambda (candidate)
2267 (kill-new (anything-c-colors-get-name candidate))))
2268 ("Copy RGB" . (lambda (candidate)
2269 (kill-new (anything-c-colors-get-rgb candidate))))
2270 ("Insert Name" . (lambda (candidate)
2271 (with-current-buffer anything-current-buffer
2272 (insert (anything-c-colors-get-name candidate)))))
2273 ("Insert RGB" . (lambda (candidate)
2274 (with-current-buffer anything-current-buffer
2275 (insert (anything-c-colors-get-rgb candidate))))))
2276 (requires-pattern . 3)))
2277 ;; (anything 'anything-c-source-colors)
2279 (defun anything-c-colors-get-name (candidate)
2280 "Get color name."
2281 (replace-regexp-in-string
2282 " " ""
2283 (with-temp-buffer
2284 (insert (capitalize candidate))
2285 (goto-char (point-min))
2286 (search-forward-regexp "\\s-\\{2,\\}")
2287 (kill-line)
2288 (buffer-string))))
2290 (defun anything-c-colors-get-rgb (candidate)
2291 "Get color RGB."
2292 (replace-regexp-in-string
2293 " " ""
2294 (with-temp-buffer
2295 (insert (capitalize candidate))
2296 (goto-char (point-max))
2297 (search-backward-regexp "\\s-\\{2,\\}")
2298 (kill-region (point) (point-min))
2299 (buffer-string))))
2301 ;;;; <Search Engine>
2302 ;;; Tracker desktop search
2303 (defvar anything-c-source-tracker-search
2304 '((name . "Tracker Search")
2305 (candidates . (lambda ()
2306 (start-process "tracker-search-process" nil
2307 "tracker-search"
2308 anything-pattern)))
2309 (type . file)
2310 (requires-pattern . 3)
2311 (delayed))
2312 "Source for retrieving files matching the current input pattern
2313 with the tracker desktop search.")
2314 ;; (anything 'anything-c-source-tracker-search)
2316 ;;; Spotlight (MacOS X desktop search)
2317 (defvar anything-c-source-mac-spotlight
2318 '((name . "mdfind")
2319 (candidates . (lambda ()
2320 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
2321 (type . file)
2322 (requires-pattern . 3)
2323 (delayed))
2324 "Source for retrieving files via Spotlight's command line
2325 utility mdfind.")
2326 ;; (anything 'anything-c-source-mac-spotlight)
2328 ;;;; <icicle>
2329 ;;; Icicle regions
2330 ;; See: http://www.emacswiki.org/emacs-en/Icicles_-_Multiple_Regions
2331 ;; That is the anything interface.
2333 (defvar anything-icicle-region-alist nil)
2334 (defvar anything-c-source-icicle-region
2335 '((name . "Icicle Regions")
2336 (init . (lambda ()
2337 (setq anything-icicle-region-alist
2338 (loop
2339 for i in icicle-region-alist
2340 collect (concat (car i) " => " (cadr i))))))
2341 (candidates . anything-icicle-region-alist)
2342 (action . (("Go to region" . anything-c-icicle-region-goto-region)
2343 ("Insert region at point" . (lambda (elm)
2344 (let (reg)
2345 (save-window-excursion
2346 (anything-c-icicle-region-goto-region elm)
2347 (setq reg (buffer-substring (mark) (point))))
2348 (insert reg))))
2349 ("Remove region" . anything-c-icicle-region-delete-region)
2350 ("Update" . (lambda (elm)
2351 (icicle-purge-bad-file-regions)))))))
2353 ;; (anything 'anything-c-source-icicle-region)
2355 (defun anything-icicle-select-region-action (pos)
2356 "Go to the region at nth `pos' in `icicle-region-alist'.
2357 See `icicle-select-region-action'."
2358 (let ((icicle-get-alist-candidate-function #'(lambda (pos)
2359 (nth pos icicle-region-alist))))
2360 (icicle-select-region-action pos)))
2362 (defun anything-icicle-delete-region-from-alist (pos)
2363 "Delete the region at nth `pos' from `icicle-region-alist'.
2364 See `icicle-delete-region-from-alist'."
2365 (let ((alist-cand (nth pos icicle-region-alist)))
2366 (setq icicle-region-alist
2367 (delete alist-cand icicle-region-alist)))
2368 (funcall icicle-customize-save-variable-function 'icicle-region-alist icicle-region-alist))
2370 (defun anything-c-icicle-region-goto-region (candidate)
2371 "Get the position of `candidate' and call `anything-icicle-select-region-action'."
2372 (let ((pos (position candidate anything-icicle-region-alist))
2373 (buf (second (split-string candidate " => "))))
2374 (if (equal buf "*info*")
2375 (info (caddr (nth pos icicle-region-alist))))
2376 (anything-icicle-select-region-action pos)))
2378 (defun anything-c-icicle-region-delete-region (candidate)
2379 "Get the position of `candidate' and call `anything-icicle-delete-region-from-alist'."
2380 (let ((pos (position candidate anything-icicle-region-alist)))
2381 (anything-icicle-delete-region-from-alist pos)))
2385 ;;;; <Kill ring>
2386 ;;; Kill ring
2387 (defvar anything-c-source-kill-ring
2388 '((name . "Kill Ring")
2389 (init . (lambda () (anything-attrset 'last-command last-command)))
2390 (candidates . (lambda ()
2391 (loop for kill in kill-ring
2392 unless (or (< (length kill) anything-kill-ring-threshold)
2393 (string-match "^[\\s\\t]+$" kill))
2394 collect kill)))
2395 (action . anything-c-kill-ring-action)
2396 (last-command)
2397 (migemo)
2398 (multiline))
2399 "Source for browse and insert contents of kill-ring.")
2401 (defun anything-c-kill-ring-action (str)
2402 "Insert STR in `kill-ring' and set STR to the head.
2403 If this action is executed just after `yank', replace with STR as yanked string."
2404 (setq kill-ring (delete str kill-ring))
2405 (if (not (eq (anything-attr 'last-command) 'yank))
2406 (insert-for-yank str)
2407 ;; from `yank-pop'
2408 (let ((inhibit-read-only t)
2409 (before (< (point) (mark t))))
2410 (if before
2411 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
2412 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
2413 (setq yank-undo-function nil)
2414 (set-marker (mark-marker) (point) (current-buffer))
2415 (insert-for-yank str)
2416 ;; Set the window start back where it was in the yank command,
2417 ;; if possible.
2418 (set-window-start (selected-window) yank-window-start t)
2419 (if before
2420 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
2421 ;; It is cleaner to avoid activation, even though the command
2422 ;; loop would deactivate the mark because we inserted text.
2423 (goto-char (prog1 (mark t)
2424 (set-marker (mark-marker) (point) (current-buffer)))))))
2425 (kill-new str))
2427 ;; (anything 'anything-c-source-kill-ring)
2429 ;;;; <Mark ring>
2430 ;; DO NOT include these sources in `anything-sources' use
2431 ;; the commands `anything-mark-ring' and `anything-global-mark-ring' instead.
2433 (defun anything-c-source-mark-ring-candidates ()
2434 (flet ((get-marks (pos)
2435 (save-excursion
2436 (goto-char pos)
2437 (beginning-of-line)
2438 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
2439 (when (string= "" line)
2440 (setq line "<EMPTY LINE>"))
2441 (format "%7d: %s" (line-number-at-pos) line)))))
2442 (with-current-buffer anything-current-buffer
2443 (loop
2444 with marks = (cons (mark-marker) mark-ring)
2445 with recip = nil
2446 for i in marks
2447 for f = (get-marks i)
2448 if (not (member f recip))
2450 (push f recip)
2451 finally (return (reverse recip))))))
2453 (defvar anything-mark-ring-cache nil)
2454 (defvar anything-c-source-mark-ring
2455 '((name . "mark-ring")
2456 (init . (lambda ()
2457 (setq anything-mark-ring-cache
2458 (anything-c-source-mark-ring-candidates))))
2459 (candidates . (lambda ()
2460 (anything-aif anything-mark-ring-cache
2461 it)))
2462 (action . (("Goto line" . (lambda (candidate)
2463 (goto-line (string-to-number candidate))))))
2464 (persistent-action . (lambda (candidate)
2465 (goto-line (string-to-number candidate))
2466 (anything-match-line-color-current-line)))))
2468 ;; (anything 'anything-c-source-mark-ring)
2470 (defun anything-mark-ring ()
2471 "Preconfigured `anything' for `anything-c-source-mark-ring'."
2472 (interactive)
2473 (anything 'anything-c-source-mark-ring))
2475 ;;; Global-mark-ring
2476 (defvar anything-c-source-global-mark-ring
2477 '((name . "global-mark-ring")
2478 (candidates . anything-c-source-global-mark-ring-candidates)
2479 (action . (("Goto line" . (lambda (candidate)
2480 (let ((items (split-string candidate ":")))
2481 (switch-to-buffer (second items))
2482 (goto-line (string-to-number (car items))))))))
2483 (persistent-action . (lambda (candidate)
2484 (let ((items (split-string candidate ":")))
2485 (switch-to-buffer (second items))
2486 (goto-line (string-to-number (car items)))
2487 (anything-match-line-color-current-line))))))
2489 (defun anything-c-source-global-mark-ring-candidates ()
2490 (flet ((buf-fn (m)
2491 (with-current-buffer (marker-buffer m)
2492 (goto-char m)
2493 (beginning-of-line)
2494 (let (line)
2495 (if (string= "" line)
2496 (setq line "<EMPTY LINE>")
2497 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
2498 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
2499 (loop
2500 with marks = global-mark-ring
2501 with recip = nil
2502 for i in marks
2503 if (not (or (string-match "^ " (format "%s" (marker-buffer i)))
2504 (null (marker-buffer i))))
2505 for a = (buf-fn i)
2506 if (and a (not (member a recip)))
2508 (push a recip)
2509 finally (return (reverse recip)))))
2511 ;; (anything 'anything-c-source-global-mark-ring)
2513 (defun anything-global-mark-ring ()
2514 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
2515 (interactive)
2516 (anything 'anything-c-source-global-mark-ring))
2518 ;;;; <Register>
2519 ;;; Insert from register
2520 (defvar anything-c-source-register
2521 '((name . "Registers")
2522 (candidates . anything-c-register-candidates)
2523 (action-transformer . anything-c-register-action-transformer)
2524 (multiline)
2525 (action))
2526 "See (info \"(emacs)Registers\")")
2528 (defun anything-c-register-candidates ()
2529 "Collecting register contents and appropriate commands."
2530 (loop for (char . val) in register-alist
2531 for key = (single-key-description char)
2532 for string-actions = (cond
2533 ((numberp val)
2534 (list (int-to-string val)
2535 'insert-register
2536 'increment-register))
2537 ((markerp val)
2538 (let ((buf (marker-buffer val)))
2539 (if (null buf)
2540 (list "a marker in no buffer")
2541 (list (concat
2542 "a buffer position:"
2543 (buffer-name buf)
2544 ", position "
2545 (int-to-string (marker-position val)))
2546 'jump-to-register
2547 'insert-register))))
2548 ((and (consp val) (window-configuration-p (car val)))
2549 (list "window configuration."
2550 'jump-to-register))
2551 ((and (consp val) (frame-configuration-p (car val)))
2552 (list "frame configuration."
2553 'jump-to-register))
2554 ((and (consp val) (eq (car val) 'file))
2555 (list (concat "file:"
2556 (prin1-to-string (cdr val))
2557 ".")
2558 'jump-to-register))
2559 ((and (consp val) (eq (car val) 'file-query))
2560 (list (concat "file:a file-query reference: file "
2561 (car (cdr val))
2562 ", position "
2563 (int-to-string (car (cdr (cdr val))))
2564 ".")
2565 'jump-to-register))
2566 ((consp val)
2567 (let ((lines (format "%4d" (length val))))
2568 (list (format "%s: %s\n" lines
2569 (truncate-string-to-width
2570 (mapconcat 'identity (list (car val))
2571 ;; (mapconcat (lambda (y) y) val
2572 "^J") (- (window-width) 15)))
2573 'insert-register)))
2574 ((stringp val)
2575 (list ;; without properties
2576 (substring-no-properties val)
2577 'insert-register
2578 'append-to-register
2579 'prepend-to-register))
2581 "GARBAGE!"))
2582 collect (cons (format "register %3s: %s" key (car string-actions))
2583 (cons char (cdr string-actions)))))
2585 (defun anything-c-register-action-transformer (actions register-and-functions)
2586 "Decide actions by the contents of register."
2587 (loop with func-actions =
2588 '((insert-register
2589 "Insert Register" .
2590 (lambda (c) (insert-register (car c))))
2591 (jump-to-register
2592 "Jump to Register" .
2593 (lambda (c) (jump-to-register (car c))))
2594 (append-to-register
2595 "Append Region to Register" .
2596 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
2597 (prepend-to-register
2598 "Prepend Region to Register" .
2599 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
2600 (increment-register
2601 "Increment Prefix Arg to Register" .
2602 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
2603 for func in (cdr register-and-functions)
2604 for cell = (assq func func-actions)
2605 when cell
2606 collect (cdr cell)))
2608 ;; (anything 'anything-c-source-register)
2610 ;;;; <Headline Extraction>
2611 (defvar anything-c-source-fixme
2612 '((name . "TODO/FIXME/DRY comments")
2613 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
2614 (adjust)
2615 (recenter))
2616 "Show TODO/FIXME/DRY comments in current file.")
2617 ;; (anything 'anything-c-source-fixme)
2619 (defvar anything-c-source-rd-headline
2620 '((name . "RD HeadLine")
2621 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
2622 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
2623 (migemo)
2624 (subexp . 1))
2625 "Show RD headlines.
2627 RD is Ruby's POD.
2628 http://en.wikipedia.org/wiki/Ruby_Document_format")
2629 ;; (anything 'anything-c-source-rd-headline)
2631 (defvar anything-c-source-oddmuse-headline
2632 '((name . "Oddmuse HeadLine")
2633 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
2634 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
2635 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
2636 (migemo)
2637 (subexp . 1))
2638 "Show Oddmuse headlines, such as EmacsWiki.")
2639 ;; (anything 'anything-c-source-oddmuse-headline)
2641 (defvar anything-c-source-emacs-source-defun
2642 '((name . "Emacs Source DEFUN")
2643 (headline . "DEFUN\\|DEFVAR")
2644 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
2645 "Show DEFUN/DEFVAR in Emacs C source file.")
2646 ;; (anything 'anything-c-source-emacs-source-defun)
2648 (defvar anything-c-source-emacs-lisp-expectations
2649 '((name . "Emacs Lisp Expectations")
2650 (headline . "(desc[ ]\\|(expectations")
2651 (condition . (eq major-mode 'emacs-lisp-mode)))
2652 "Show descriptions (desc) in Emacs Lisp Expectations.
2654 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
2655 ;; (anything 'anything-c-source-emacs-lisp-expectations)
2657 (defvar anything-c-source-emacs-lisp-toplevels
2658 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
2659 (headline . "^(\\|(@\\*\\|^;;;;")
2660 (get-line . buffer-substring)
2661 (condition . (eq major-mode 'emacs-lisp-mode))
2662 (adjust))
2663 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
2664 linkd.el is optional because linkd stars are extracted by regexp.
2665 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
2666 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
2668 (defvar anything-c-source-org-headline
2669 '((name . "Org HeadLine")
2670 (headline
2671 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
2672 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
2673 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
2674 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
2675 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
2676 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
2677 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
2678 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
2679 (condition . (eq major-mode 'org-mode))
2680 (migemo)
2681 (subexp . 1)
2682 (persistent-action . (lambda (elm)
2683 (anything-c-action-line-goto elm)
2684 (org-cycle)))
2685 (action-transformer
2686 . (lambda (actions candidate)
2687 '(("Go to Line" . anything-c-action-line-goto)
2688 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
2689 "Show Org headlines.
2690 org-mode is very very much extended text-mode/outline-mode.
2692 See (find-library \"org.el\")
2693 See http://orgmode.org for the latest version.")
2695 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
2696 (insert
2697 (save-excursion
2698 (goto-line (car lineno-and-content))
2699 (and (looking-at "^\\*+ \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
2700 (org-make-link-string (concat "*" (match-string 1)))))))
2702 ;; (anything 'anything-c-source-org-headline)
2704 ;;; Anything yaoddmuse
2705 ;; Be sure to have yaoddmuse.el installed
2706 ;; install-elisp may be required if you want to install elisp file from here.
2707 (defvar anything-yaoddmuse-use-cache-file nil)
2708 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
2709 (defvar anything-c-yaoddmuse-ew-cache nil)
2710 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
2711 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
2712 (candidates . (lambda ()
2713 (if anything-yaoddmuse-use-cache-file
2714 (condition-case nil
2715 (progn
2716 (unless anything-c-yaoddmuse-ew-cache
2717 (load anything-c-yaoddmuse-cache-file)
2718 (setq anything-c-yaoddmuse-ew-cache
2719 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
2720 anything-c-yaoddmuse-ew-cache)
2721 (error nil))
2722 (yaoddmuse-update-pagename t)
2723 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
2724 (action . (("Edit page" . (lambda (candidate)
2725 (yaoddmuse-edit "EmacsWiki" candidate)))
2726 ("Browse page" . (lambda (candidate)
2727 (yaoddmuse-browse-page "EmacsWiki" candidate)))
2728 ("Browse page other window" . (lambda (candidate)
2729 (if (one-window-p)
2730 (split-window-vertically))
2731 (yaoddmuse-browse-page "EmacsWiki" candidate)))
2732 ("Browse diff" . (lambda (candidate)
2733 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
2734 ("Copy URL" . (lambda (candidate)
2735 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
2736 (message "Have copy page %s's URL to yank." candidate)))
2737 ("Create page" . (lambda (candidate)
2738 (yaoddmuse-edit "EmacsWiki" anything-input)))
2739 ("Update cache" . (lambda (candidate)
2740 (if anything-yaoddmuse-use-cache-file
2741 (progn
2742 (anything-yaoddmuse-cache-pages t)
2743 (setq anything-c-yaoddmuse-ew-cache
2744 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
2745 (yaoddmuse-update-pagename))))))
2746 (action-transformer anything-c-yaoddmuse-action-transformer)))
2748 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
2750 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
2751 '((name . "Yaoddmuse Post library (EmacsWiki)")
2752 (init . (anything-yaoddmuse-init))
2753 (candidates-in-buffer)
2754 (action . (("Post library and Browse" . (lambda (candidate)
2755 (yaoddmuse-post-file (find-library-name candidate)
2756 "EmacsWiki"
2757 (file-name-nondirectory (find-library-name candidate))
2758 nil t)))
2759 ("Post library" . (lambda (candidate)
2760 (yaoddmuse-post-file (find-library-name candidate)
2761 "EmacsWiki"
2762 (file-name-nondirectory (find-library-name candidate)))))))))
2764 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
2766 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
2767 "Allow the use of `install-elisp' only on elisp files."
2768 (if (string-match "\.el$" candidate)
2769 (append actions '(("Install Elisp" . (lambda (elm)
2770 (install-elisp-from-emacswiki elm)))))
2771 actions))
2773 (defun anything-yaoddmuse-cache-pages (&optional load)
2774 "Fetch the list of files on emacswiki and create cache file.
2775 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
2776 (interactive)
2777 (yaoddmuse-update-pagename)
2778 (save-excursion
2779 (find-file anything-c-yaoddmuse-cache-file)
2780 (erase-buffer)
2781 (insert "(puthash \"EmacsWiki\" '(")
2782 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
2784 (insert (concat "(\"" (car i) "\") ")))
2785 (insert ") yaoddmuse-pages-hash)\n")
2786 (save-buffer)
2787 (kill-buffer (current-buffer))
2788 (when (or current-prefix-arg
2789 load)
2790 (load anything-c-yaoddmuse-cache-file))))
2792 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
2793 "Edit or View EmacsWiki page."
2794 (interactive)
2795 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
2797 (defun anything-yaoddmuse-emacswiki-post-library ()
2798 "Post library to EmacsWiki."
2799 (interactive)
2800 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
2802 (defun anything-yaoddmuse-init ()
2803 "Init anything buffer status."
2804 (let ((anything-buffer (anything-candidate-buffer 'global))
2805 (library-list (yaoddmuse-get-library-list)))
2806 (with-current-buffer anything-buffer
2807 ;; Insert library name.
2808 (dolist (library library-list)
2809 (insert (format "%s\n" library)))
2810 ;; Sort lines.
2811 (sort-lines nil (point-min) (point-max)))))
2813 ;;; Eev anchors
2814 (defvar anything-c-source-eev-anchor
2815 '((name . "Anchors")
2816 (init . (lambda ()
2817 (setq anything-c-eev-anchor-buffer
2818 (current-buffer))))
2819 (candidates . (lambda ()
2820 (condition-case nil
2821 (save-excursion
2822 (with-current-buffer anything-c-eev-anchor-buffer
2823 (goto-char (point-min))
2824 (let (anchors)
2825 (while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
2826 (push (match-string-no-properties 1) anchors))
2827 (setq anchors (reverse anchors)))))
2828 (error nil))))
2829 (persistent-action . (lambda (item)
2830 (ee-to item)
2831 (anything-match-line-color-current-line)))
2832 (action . (("Goto link" . (lambda (item)
2833 (ee-to item)))))))
2835 ;; (anything 'anything-c-source-eev-anchor)
2837 ;;;; <Misc>
2838 ;;; Picklist
2839 (defvar anything-c-source-picklist
2840 '((name . "Picklist")
2841 (candidates . (lambda () (mapcar 'car picklist-list)))
2842 (volatile)
2843 (type . file)))
2844 ;; (anything 'anything-c-source-picklist)
2846 ;;; BBDB
2847 (defun anything-c-bbdb-candidates ()
2848 "Return a list of all names in the bbdb database. The format
2849 is \"Firstname Lastname\"."
2850 (mapcar (lambda (bbdb-record)
2851 (replace-regexp-in-string
2852 "\\s-+$" ""
2853 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
2854 (bbdb-records)))
2856 (defun anything-c-bbdb-create-contact (actions candidate)
2857 "Action transformer that returns only an entry to add the
2858 current `anything-pattern' as new contact. All other actions are
2859 removed."
2860 (if (string= candidate "*Add to contacts*")
2861 '(("Add to contacts" . (lambda (actions)
2862 (bbdb-create-internal
2863 (read-from-minibuffer "Name: " anything-c-bbdb-name)
2864 (read-from-minibuffer "Company: ")
2865 (read-from-minibuffer "Email: ")
2868 (read-from-minibuffer "Note: ")))))
2869 actions))
2871 (defun anything-c-bbdb-get-record (candidate)
2872 "Return record that match CANDIDATE."
2873 (bbdb candidate nil)
2874 (set-buffer "*BBDB*")
2875 (bbdb-current-record))
2877 (defvar anything-c-bbdb-name nil
2878 "Only for internal use.")
2880 (defvar anything-c-source-bbdb
2881 '((name . "BBDB")
2882 (candidates . anything-c-bbdb-candidates)
2883 (volatile)
2884 (action ("Send a mail" . (lambda (candidate)
2885 (bbdb-send-mail (anything-c-bbdb-get-record candidate))))
2886 ("View person's data" . (lambda (candidate)
2887 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate)))))
2888 (filtered-candidate-transformer . (lambda (candidates source)
2889 (setq anything-c-bbdb-name anything-pattern)
2890 (if (not candidates)
2891 (list "*Add to contacts*")
2892 candidates)))
2893 (action-transformer . (lambda (actions candidate)
2894 (anything-c-bbdb-create-contact actions candidate)))))
2895 ;; (anything 'anything-c-source-bbdb)
2897 ;;; Evaluation Result
2898 (defvar anything-c-source-evaluation-result
2899 '((name . "Evaluation Result")
2900 (requires-pattern)
2901 (match (lambda (candidate) t))
2902 (candidates "dummy")
2903 (filtered-candidate-transformer . (lambda (candidates source)
2904 (list
2905 (condition-case nil
2906 (prin1-to-string
2907 (eval (read anything-pattern)))
2908 (error "Error")))))
2909 (volatile)
2910 (action ("Do Nothing" . ignore))))
2911 ;; (anything 'anything-c-source-evaluation-result)
2913 ;;; Calculation Result
2914 (defvar anything-c-source-calculation-result
2915 '((name . "Calculation Result")
2916 (requires-pattern)
2917 (match (lambda (candidate) t))
2918 (candidates "dummy")
2919 (filtered-candidate-transformer . (lambda (candidates source)
2920 (list
2921 (condition-case nil
2922 (calc-eval anything-pattern)
2923 (error "error")))))
2924 (volatile)
2925 (action ("Copy result to kill-ring" . kill-new))))
2926 ;; (anything 'anything-c-source-calculation-result)
2928 ;;; Google Suggestions
2929 (defvar anything-c-source-google-suggest
2930 '((name . "Google Suggest")
2931 (candidates . (lambda ()
2932 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
2933 (if (some (lambda (suggestion)
2934 (equal (cdr suggestion) anything-input))
2935 suggestions)
2936 suggestions
2937 ;; if there is no suggestion exactly matching the input then
2938 ;; prepend a Search on Google item to the list
2939 (append (list (cons (concat "Search for "
2940 "'" anything-input "'"
2941 " on Google")
2942 anything-input))
2943 suggestions)))))
2944 (action . (("Google Search" .
2945 (lambda (candidate)
2946 (browse-url (concat anything-c-google-suggest-search-url
2947 (url-hexify-string candidate)))))))
2948 (volatile)
2949 (requires-pattern . 3)
2950 (delayed)))
2951 ;; (anything 'anything-c-source-google-suggest)
2953 (defun anything-c-google-suggest-fetch (input)
2954 "Fetch suggestions for INPUT."
2955 (let* ((result (with-current-buffer
2956 (url-retrieve-synchronously
2957 (concat anything-c-google-suggest-url
2958 (url-hexify-string input)))
2959 (buffer-substring (point-min) (point-max))))
2960 (split (split-string result "new Array("))
2961 (suggestions (anything-c-google-suggest-get-items (second split)))
2962 (numbers (anything-c-google-suggest-get-items (third split)))
2963 (longest (+ (apply 'max 0 (let (lengths)
2964 (dotimes (i (length suggestions))
2965 (push (+ (length (nth i suggestions))
2966 (length (nth i numbers)))
2967 lengths))
2968 lengths))
2969 10))
2970 items)
2971 (dotimes (i (length suggestions))
2972 (let ((suggestion (nth i suggestions))
2973 (number (nth i numbers)))
2974 (push (cons (concat suggestion
2975 (make-string (- longest
2976 (length suggestion)
2977 (length number))
2979 number)
2980 suggestion)
2981 items)))
2982 items))
2984 (defun anything-c-google-suggest-get-items (str)
2985 "Extract items from STR returned by Google Suggest."
2986 (let ((start nil) items)
2987 (while (string-match "\"\\([^\"]+?\\)\"" str start)
2988 (push (match-string 1 str) items)
2989 (setq start (1+ (match-end 1))))
2990 items))
2992 ;;; Surfraw
2993 ;;; Need external program surfraw.
2994 ;;; http://surfraw.alioth.debian.org/
2995 ;; user variables
2996 (defvar anything-c-surfraw-favorites '("google" "wikipedia"
2997 "yahoo" "translate"
2998 "codesearch" "genpkg"
2999 "genportage" "fast"
3000 "currency")
3001 "All elements of this list will appear first in results.")
3002 (defvar anything-c-surfraw-use-only-favorites nil
3003 "If non-nil use only `anything-c-surfraw-favorites'.")
3006 (defun anything-c-build-elvi-alist ()
3007 "Build elvi alist.
3008 A list of search engines."
3009 (let* ((elvi-list
3010 (with-temp-buffer
3011 (call-process "surfraw" nil t nil
3012 "-elvi")
3013 (split-string (buffer-string) "\n")))
3014 (elvi-alist
3015 (let (line)
3016 (loop for i in elvi-list
3018 (setq line (split-string i))
3019 collect (cons (first line) (mapconcat #'(lambda (x) x) (cdr line) " "))))))
3020 elvi-alist))
3022 (defun anything-c-surfraw-sort-elvi (&optional only-fav)
3023 "Sort elvi alist according to `anything-c-surfraw-favorites'."
3024 (let* ((elvi-alist (anything-c-build-elvi-alist))
3025 (fav-alist (loop for j in anything-c-surfraw-favorites
3026 collect (assoc j elvi-alist)))
3027 (rest-elvi (loop for i in elvi-alist
3028 if (not (member i fav-alist))
3029 collect i)))
3030 (if only-fav
3031 fav-alist
3032 (append fav-alist rest-elvi))))
3034 (defun anything-c-surfraw-get-url (engine pattern)
3035 "Get search url from `engine' for `anything-pattern'."
3036 (with-temp-buffer
3037 (apply #'call-process "surfraw" nil t nil
3038 `(,engine
3039 "-p"
3040 ,anything-pattern))
3041 (buffer-string)))
3044 (defvar anything-c-surfraw-elvi nil)
3045 (defvar anything-c-surfraw-cache nil)
3046 (defvar anything-c-source-surfraw
3047 '((name . "Surfraw")
3048 (init . (lambda ()
3049 (unless anything-c-surfraw-cache
3050 (setq anything-c-surfraw-elvi (anything-c-surfraw-sort-elvi
3051 anything-c-surfraw-use-only-favorites))
3052 (setq anything-c-surfraw-cache
3053 (loop for i in anything-c-surfraw-elvi
3054 if (car i)
3055 collect (car i))))))
3056 (candidates . (lambda ()
3057 (loop for i in anything-c-surfraw-cache
3058 for s = (anything-c-surfraw-get-url i anything-pattern)
3059 collect (concat (propertize i
3060 'face '((:foreground "green"))
3061 'help-echo (cdr (assoc i anything-c-surfraw-elvi)))
3062 ">>>" (replace-regexp-in-string "\n" "" s)))))
3063 (action . (("Browse" . (lambda (candidate)
3064 (let ((url (second (split-string candidate ">>>"))))
3065 (browse-url url))))
3066 ("Browse firefox" . (lambda (candidate)
3067 (let ((url (second (split-string candidate ">>>"))))
3068 (browse-url-firefox url t))))))
3069 (volatile)
3070 (requires-pattern . 3)
3071 (multiline)
3072 (delayed)))
3074 ;; (anything 'anything-c-source-surfraw)
3076 ;;; Emms
3078 (defun anything-emms-stream-edit-bookmark (elm)
3079 "Change the information of current emms-stream bookmark from anything."
3080 (interactive)
3081 (let* ((cur-buf anything-current-buffer)
3082 (bookmark (assoc elm emms-stream-list))
3083 (name (read-from-minibuffer "Description: "
3084 (nth 0 bookmark)))
3085 (url (read-from-minibuffer "URL: "
3086 (nth 1 bookmark)))
3087 (fd (read-from-minibuffer "Feed Descriptor: "
3088 (int-to-string (nth 2 bookmark))))
3089 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
3090 (format "%s" (car (last bookmark))))))
3091 (save-excursion
3092 (emms-streams)
3093 (when (re-search-forward (concat "^" name) nil t)
3094 (beginning-of-line)
3095 (emms-stream-delete-bookmark)
3096 (emms-stream-add-bookmark name url (string-to-number fd) type)
3097 (emms-stream-save-bookmarks-file)
3098 (emms-stream-quit)
3099 (switch-to-buffer cur-buf)))))
3101 (defun anything-emms-stream-delete-bookmark (elm)
3102 "Delete an emms-stream bookmark from anything."
3103 (interactive)
3104 (let* ((cur-buf anything-current-buffer)
3105 (bookmark (assoc elm emms-stream-list))
3106 (name (nth 0 bookmark)))
3107 (save-excursion
3108 (emms-streams)
3109 (when (re-search-forward (concat "^" name) nil t)
3110 (beginning-of-line)
3111 (emms-stream-delete-bookmark)
3112 (emms-stream-save-bookmarks-file)
3113 (emms-stream-quit)
3114 (switch-to-buffer cur-buf)))))
3116 (defvar anything-c-source-emms-streams
3117 '((name . "Emms Streams")
3118 (init . (lambda ()
3119 (emms-stream-init)))
3120 (candidates . (lambda ()
3121 (mapcar 'car emms-stream-list)))
3122 (action . (("Play" . (lambda (elm)
3123 (let* ((stream (assoc elm emms-stream-list))
3124 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
3125 (url (second stream)))
3126 (funcall fn url))))
3127 ("Delete" . anything-emms-stream-delete-bookmark)
3128 ("Edit" . anything-emms-stream-edit-bookmark)))
3129 (volatile)))
3130 ;; (anything 'anything-c-source-emms-streams)
3132 ;; Don't forget to set `emms-source-file-default-directory'
3133 (defvar anything-c-source-emms-dired
3134 '((name . "Music Directory")
3135 (candidates . (lambda ()
3136 (cddr (directory-files emms-source-file-default-directory))))
3137 (action . (("Play Directory" . (lambda (item)
3138 (emms-play-directory
3139 (expand-file-name item
3140 emms-source-file-default-directory))))
3141 ("Open dired in file's directory" . (lambda (item)
3142 (anything-c-open-dired
3143 (expand-file-name item
3144 emms-source-file-default-directory))))))
3145 (volatile)))
3146 ;; (anything 'anything-c-source-emms-dired)
3148 ;;; Jabber Contacts (jabber.el)
3149 (defun anything-c-jabber-online-contacts ()
3150 "List online Jabber contacts."
3151 (with-no-warnings
3152 (let (jids)
3153 (dolist (item (jabber-concat-rosters) jids)
3154 (when (get item 'connected)
3155 (push (if (get item 'name)
3156 (cons (get item 'name) item)
3157 (cons (symbol-name item) item)) jids))))))
3159 (defvar anything-c-source-jabber-contacts
3160 '((name . "Jabber Contacts")
3161 (init . (lambda () (require 'jabber)))
3162 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
3163 (action . (lambda (x)
3164 (jabber-chat-with
3165 (jabber-read-account)
3166 (symbol-name
3167 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
3168 ;; (anything 'anything-c-source-jabber-contacts)
3171 ;;; Call source.
3172 (defvar anything-source-select-buffer "*anything source select*")
3173 (defvar anything-c-source-call-source
3174 `((name . "Call anything source")
3175 (candidate-number-limit . 9999)
3176 (candidates . (lambda ()
3177 (loop for vname in (all-completions "anything-c-source-" obarray)
3178 for var = (intern vname)
3179 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
3180 if name collect (cons (format "%s (%s)" name vname) var))))
3181 (action . (("Invoke anything with selected source" .
3182 (lambda (candidate)
3183 (setq anything-candidate-number-limit 9999)
3184 (anything candidate nil nil nil nil
3185 anything-source-select-buffer)))
3186 ("Describe variable" . describe-variable)))
3187 (persistent-action . describe-variable)))
3188 ;; (anything 'anything-c-source-call-source)
3190 (defun anything-call-source ()
3191 "Call anything source."
3192 (interactive)
3193 (anything 'anything-c-source-call-source nil nil nil nil
3194 anything-source-select-buffer))
3196 (defun anything-call-source-from-anything ()
3197 "Call anything source within `anything' session."
3198 (interactive)
3199 (setq anything-input-idle-delay 0)
3200 (anything-set-sources '(anything-c-source-call-source)))
3202 ;; Occur
3203 (defvar anything-c-source-occur
3204 '((name . "Occur")
3205 (init . (lambda ()
3206 (setq anything-c-source-occur-current-buffer
3207 (current-buffer))))
3208 (candidates . (lambda ()
3209 (setq anything-occur-buf (get-buffer-create "*Anything Occur*"))
3210 (with-current-buffer anything-occur-buf
3211 (erase-buffer)
3212 (let ((count (occur-engine anything-pattern
3213 (list anything-c-source-occur-current-buffer) anything-occur-buf
3214 list-matching-lines-default-context-lines nil
3215 list-matching-lines-buffer-name-face
3216 nil list-matching-lines-face
3217 (not (eq occur-excluded-properties t)))))
3218 (when (> count 0)
3219 (let ((lines (split-string (buffer-string) "\n" t)))
3220 (cdr lines)))))))
3221 (action . (("Goto line" . (lambda (candidate)
3222 (goto-line (string-to-number candidate) anything-c-source-occur-current-buffer)))))
3223 (requires-pattern . 1)
3224 (volatile)))
3225 ;; (anything 'anything-c-source-occur)
3227 ;; Do many actions for input
3228 (defvar anything-c-source-create
3229 '((name . "Create")
3230 (dummy)
3231 (action)
3232 (candidate-number-limit . 9999)
3233 (action-transformer . anything-create--actions))
3234 "Do many create actions from `anything-pattern'.
3235 See also `anything-create--actions'.")
3236 ;; (anything 'anything-c-source-create)
3238 (defun anything-create-from-anything ()
3239 "Run `anything-create' from `anything' as a fallback."
3240 (interactive)
3241 (anything-run-after-quit 'anything-create nil anything-pattern))
3243 (defun anything-create (&optional string initial-input)
3244 "Do many create actions from STRING.
3245 See also `anything-create--actions'."
3246 (interactive)
3247 (setq string (or string (read-string "Create Anything: " initial-input)))
3248 (anything '(((name . "Anything Create")
3249 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
3250 (candidates . anything-create--actions)
3251 (candidate-number-limit . 9999)
3252 (action . (lambda (func) (funcall func string)))))))
3254 (defun anything-create--actions (&rest ignored)
3255 "Default actions for `anything-create' / `anything-c-source-create'."
3256 (remove-if-not
3257 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
3258 (append anything-create--actions-private
3259 '(("find-file" . find-file)
3260 ("find-file other window" . find-file-other-window)
3261 ("New buffer" . switch-to-buffer)
3262 ("New buffer other window" . switch-to-buffer-other-window)
3263 ("Bookmark Set" . bookmark-set)
3264 ("Set Register" .
3265 (lambda (x) (set-register (read-char "Register: ") x)))
3266 ("Insert Linkd star" . linkd-insert-star)
3267 ("Insert Linkd Tag" . linkd-insert-tag)
3268 ("Insert Linkd Link" . linkd-insert-link)
3269 ("Insert Linkd Lisp" . linkd-insert-lisp)
3270 ("Insert Linkd Wiki" . linkd-insert-wiki)
3271 ("Google Search" . google)))))
3273 ;; Minibuffer History
3274 (defvar anything-c-source-minibuffer-history
3275 '((name . "Minibuffer History")
3276 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
3277 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
3278 (if (consp (car history))
3279 (mapcar 'prin1-to-string history)
3280 history))))
3281 (migemo)
3282 (action . insert)))
3283 ;; (anything 'anything-c-source-minibuffer-history)
3285 ;; elscreen
3286 (defvar anything-c-source-elscreen
3287 '((name . "Elscreen")
3288 (candidates . (lambda ()
3289 (if (cdr (elscreen-get-screen-to-name-alist))
3290 (sort
3291 (loop for sname in (elscreen-get-screen-to-name-alist)
3292 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
3293 finally (return lst))
3294 '(lambda (a b) (compare-strings a nil nil b nil nil))))))
3295 (action . (("Change Screen".
3296 (lambda (candidate)
3297 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
3298 ("Kill Screen".
3299 (lambda (candidate)
3300 (elscreen-kill (- (aref candidate 1) (aref "0" 0)))))
3301 ("Only Screen".
3302 (lambda (candidate)
3303 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
3304 (elscreen-kill-others)))))))
3305 ;; (anything 'anything-c-source-elscreen)
3307 ;;;; <System>
3309 ;;; X RandR resolution change
3310 ;;; FIXME I do not care multi-display.
3311 (defvar anything-c-xrandr-output "VGA")
3312 (defvar anything-c-xrandr-screen "0")
3313 (defvar anything-c-source-xrandr-change-resolution
3314 '((name . "Change Resolution")
3315 (candidates
3316 . (lambda ()
3317 (with-temp-buffer
3318 (call-process "xrandr" nil (current-buffer) nil
3319 "--screen" anything-c-xrandr-screen "-q")
3320 (goto-char 1)
3321 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
3322 collect (match-string 1)))))
3323 (action
3324 ("Change Resolution" . (lambda (mode)
3325 (call-process "xrandr" nil nil nil
3326 "--screen" anything-c-xrandr-screen
3327 "--output" anything-c-xrandr-output
3328 "--mode" mode))))))
3329 ;; (anything 'anything-c-source-xrandr-change-resolution)
3331 ;;; Xfont selection
3332 (defun anything-c-persistent-xfont-action (elm)
3333 "Show current font temporarily"
3334 (let ((default-font elm))
3335 (set-default-font default-font)))
3337 (defvar anything-c-xfonts-cache nil)
3338 (defvar anything-c-source-xfonts
3339 '((name . "X Fonts")
3340 (init . (lambda ()
3341 (unless anything-c-xfonts-cache
3342 (setq anything-c-xfonts-cache
3343 (x-list-fonts "*")))))
3344 (candidates . anything-c-xfonts-cache)
3345 (multiline)
3346 (volatile)
3347 (action . (("Copy to kill ring" . (lambda (elm)
3348 (kill-new elm)))
3349 ("Set Font" . (lambda (elm)
3350 (kill-new elm)
3351 (set-default-font elm 'keep-size)
3352 (message "New font have been copied to kill ring")))))
3353 (persistent-action . anything-c-persistent-xfont-action)))
3355 ;; (anything 'anything-c-source-xfonts)
3357 ;; Sources for gentoo users
3359 (defvar anything-gentoo-prefered-shell 'eshell
3360 "Your favorite shell to run emerge command.")
3362 (defvar anything-c-gentoo-use-flags nil)
3363 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
3364 (defvar anything-c-cache-gentoo nil)
3365 (defvar anything-c-cache-world nil)
3366 (defvar anything-c-source-gentoo
3367 '((name . "Portage sources")
3368 (init . (lambda ()
3369 (get-buffer-create anything-c-gentoo-buffer)
3370 (unless anything-c-cache-gentoo
3371 (anything-c-gentoo-setup-cache))
3372 (unless anything-c-cache-world
3373 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
3374 (anything-c-gentoo-init-list)))
3375 (candidates-in-buffer)
3376 (match . identity)
3377 (candidate-transformer anything-c-highlight-world)
3378 (action . (("Show package" . (lambda (elm)
3379 (anything-c-gentoo-eshell-action elm "eix")))
3380 ("Show history" . (lambda (elm)
3381 (if (member elm anything-c-cache-world)
3382 (anything-c-gentoo-eshell-action elm "genlop -qe")
3383 (message "No infos on packages not yet installed"))))
3384 ("Copy in kill-ring" . kill-new)
3385 ("insert at point" . insert)
3386 ("Browse HomePage" . (lambda (elm)
3387 (browse-url (car (anything-c-gentoo-get-url elm)))))
3388 ("Show extra infos" . (lambda (elm)
3389 (if (member elm anything-c-cache-world)
3390 (anything-c-gentoo-eshell-action elm "genlop -qi")
3391 (message "No infos on packages not yet installed"))))
3392 ("Show use flags" . (lambda (elm)
3393 (anything-c-gentoo-default-action elm "equery" "-C" "u")
3394 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
3395 (font-lock-mode 1)))
3396 ("Run emerge pretend" . (lambda (elm)
3397 (anything-c-gentoo-eshell-action elm "emerge -p")))
3398 ("Emerge" . (lambda (elm)
3399 (anything-gentoo-install elm :action 'install)))
3400 ("Unmerge" . (lambda (elm)
3401 (anything-gentoo-install elm :action 'uninstall)))
3402 ("Show dependencies" . (lambda (elm)
3403 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
3404 ("Show related files" . (lambda (elm)
3405 (anything-c-gentoo-default-action elm "equery" "files")))
3406 ("Update" . (lambda (elm)
3407 (anything-c-gentoo-setup-cache)
3408 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
3410 ;; (anything 'anything-c-source-gentoo)
3412 (defun* anything-gentoo-install (candidate &key action)
3413 (funcall anything-gentoo-prefered-shell)
3414 (let ((command (case action
3415 ('install "sudo emerge -av ")
3416 ('uninstall "sudo emerge -avC ")
3417 (t (error "Unknow action")))))
3418 (if (anything-marked-candidates)
3419 (let ((elms (mapconcat 'identity (anything-marked-candidates) " ")))
3420 (insert (concat command elms)))
3421 (insert (concat command candidate)))))
3424 (defun anything-c-gentoo-default-action (elm command &rest args)
3425 "Gentoo default action that use `anything-c-gentoo-buffer'."
3426 (if (member elm anything-c-cache-world)
3427 (progn
3428 (switch-to-buffer anything-c-gentoo-buffer)
3429 (erase-buffer)
3430 (let ((com-list (append args (list elm))))
3431 (apply #'call-process command nil t nil
3432 com-list)))
3433 (message "No infos on packages not yet installed")))
3435 (defvar anything-c-source-use-flags
3436 '((name . "Use Flags")
3437 (init . (lambda ()
3438 (unless anything-c-gentoo-use-flags
3439 (anything-c-gentoo-setup-use-flags-cache))
3440 (anything-c-gentoo-get-use)))
3441 (candidates-in-buffer)
3442 (match . identity)
3443 (candidate-transformer anything-c-highlight-local-use)
3444 (action . (("Show which dep use this flag"
3445 . (lambda (elm)
3446 (switch-to-buffer anything-c-gentoo-buffer)
3447 (erase-buffer)
3448 (apply #'call-process "equery" nil t nil
3449 `("-C"
3451 ,elm))))
3452 ("Description"
3453 . (lambda (elm)
3454 (switch-to-buffer anything-c-gentoo-buffer)
3455 (erase-buffer)
3456 (apply #'call-process "euse" nil t nil
3457 `("-i"
3458 ,elm))
3459 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
3460 (font-lock-mode 1)))))))
3463 ;; (anything 'anything-c-source-use-flags)
3465 (defun anything-c-gentoo-init-list ()
3466 "Initialize buffer with all packages in Portage."
3467 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
3468 (buf (anything-candidate-buffer 'portage-buf)))
3469 (with-current-buffer buf
3470 (dolist (i anything-c-cache-gentoo)
3471 (insert (concat i "\n"))))))
3473 (defun anything-c-gentoo-setup-cache ()
3474 "Set up `anything-c-cache-gentoo'"
3475 (setq anything-c-cache-gentoo
3476 (split-string (with-temp-buffer
3477 (call-process "eix" nil t nil
3478 "--only-names")
3479 (buffer-string)))))
3481 (defun anything-c-gentoo-eshell-action (elm command)
3482 (when (get-buffer "*EShell Command Output*")
3483 (kill-buffer "*EShell Command Output*"))
3484 (message "Wait searching...")
3485 (let ((buf-fname (buffer-file-name anything-current-buffer)))
3486 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
3487 (progn
3488 (save-window-excursion
3489 (pop-to-buffer "*scratch*")
3490 (eshell-command (format "%s %s" command elm)))
3491 (pop-to-buffer "*EShell Command Output*"))
3492 (eshell-command (format "%s %s" command elm)))))
3494 (defun anything-c-gentoo-get-use ()
3495 "Initialize buffer with all use flags."
3496 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
3497 (buf (anything-candidate-buffer 'use-buf)))
3498 (with-current-buffer buf
3499 (dolist (i anything-c-gentoo-use-flags)
3500 (insert (concat i "\n"))))))
3503 (defun anything-c-gentoo-setup-use-flags-cache ()
3504 "Setup `anything-c-gentoo-use-flags'"
3505 (setq anything-c-gentoo-use-flags
3506 (split-string (with-temp-buffer
3507 (call-process "eix" nil t nil
3508 "--print-all-useflags")
3509 (buffer-string)))))
3511 (defun anything-c-gentoo-get-url (elm)
3512 "Return a list of urls from eix output."
3513 (split-string (eshell-command-result
3514 (format "eix %s | grep Homepage | awk '{print $2}'" elm))))
3516 (defun anything-c-gentoo-get-world ()
3517 "Return list of all installed package on your system."
3518 (split-string (with-temp-buffer
3519 (call-process "qlist" nil t nil
3520 "-I")
3521 (buffer-string))))
3523 (defun anything-c-gentoo-get-local-use ()
3524 (split-string (with-temp-buffer
3525 (call-process "portageq" nil t nil
3526 "envvar"
3527 "USE")
3528 (buffer-string))))
3530 (defface anything-gentoo-match-face '((t (:foreground "red")))
3531 "Face for anything-gentoo installed packages."
3532 :group 'traverse-faces)
3534 (defun anything-c-highlight-world (eix)
3535 "Highlight all installed package."
3536 (loop for i in eix
3537 if (member i anything-c-cache-world)
3538 collect (propertize i 'face 'anything-gentoo-match-face)
3539 else
3540 collect i))
3542 (defun anything-c-highlight-local-use (use-flags)
3543 (let ((local-uses (anything-c-gentoo-get-local-use)))
3544 (loop for i in use-flags
3545 if (member i local-uses)
3546 collect (propertize i 'face 'anything-gentoo-match-face)
3547 else
3548 collect i)))
3550 (defvar anything-c-source-emacs-process
3551 '((name . "Emacs Process")
3552 (candidates . (lambda () (mapcar #'process-name (process-list))))
3553 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
3555 ;; (anything 'anything-c-source-emacs-process)
3558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3559 ;;; Files
3560 (defvar anything-c-external-commands-list nil
3561 "A list of all external commands the user can execute. If this
3562 variable is not set by the user, it will be calculated
3563 automatically.")
3565 (defun anything-c-external-commands-list-1 ()
3566 "Returns a list of all external commands the user can execute.
3568 If `anything-c-external-commands-list' is non-nil it will
3569 return its contents. Else it calculates all external commands
3570 and sets `anything-c-external-commands-list'.
3572 The code is ripped out of `eshell-complete-commands-list'."
3573 (if anything-c-external-commands-list
3574 anything-c-external-commands-list
3575 (setq anything-c-external-commands-list
3576 (let* ((paths (split-string (getenv "PATH") path-separator))
3577 (cwd (file-name-as-directory
3578 (expand-file-name default-directory)))
3579 (path "") (comps-in-path ())
3580 (file "") (filepath "") (completions ()))
3581 ;; Go thru each path in the search path, finding completions.
3582 (while paths
3583 (setq path (file-name-as-directory
3584 (expand-file-name (or (car paths) ".")))
3585 comps-in-path
3586 (and (file-accessible-directory-p path)
3587 (file-name-all-completions "" path)))
3588 ;; Go thru each completion found, to see whether it should be
3589 ;; used, e.g. see if it's executable.
3590 (while comps-in-path
3591 (setq file (car comps-in-path)
3592 filepath (concat path file))
3593 (if (and (not (member file completions))
3594 (or (string-equal path cwd)
3595 (not (file-directory-p filepath)))
3596 (file-executable-p filepath))
3597 (setq completions (cons file completions)))
3598 (setq comps-in-path (cdr comps-in-path)))
3599 (setq paths (cdr paths)))
3600 completions))))
3602 (defun anything-c-file-buffers (filename)
3603 "Returns a list of those buffer names which correspond to the
3604 file given by FILENAME."
3605 (let (name ret)
3606 (dolist (buf (buffer-list) ret)
3607 (let ((bfn (buffer-file-name buf)))
3608 (when (and bfn
3609 (string= filename bfn))
3610 (push (buffer-name buf) ret)))
3611 ret)))
3613 (defun anything-c-delete-file (file)
3614 "Delete the given file after querying the user. Ask to kill
3615 buffers associated with that file, too."
3616 (if (y-or-n-p (format "Really delete file %s? " file))
3617 (progn
3618 (let ((buffers (anything-c-file-buffers file)))
3619 (delete-file file)
3620 (dolist (buf buffers)
3621 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
3622 (kill-buffer buf)))))
3623 (message "Nothing deleted.")))
3625 (defun anything-c-open-file-externally (file)
3626 "Open FILE with an external tool. Query the user which tool to
3627 use."
3628 (start-process "anything-c-open-file-externally"
3630 (completing-read "Program: "
3631 (anything-c-external-commands-list-1))
3632 file))
3634 (defun w32-shell-execute-open-file (file)
3635 (interactive "fOpen file:")
3636 (with-no-warnings
3637 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
3638 "/" "\\"
3639 (replace-regexp-in-string ; strip cygdrive paths
3640 "/cygdrive/\\(.\\)" "\\1:" file nil nil) nil t))))
3641 (defun anything-c-open-file-with-default-tool (file)
3642 "Open FILE with the default tool on this platform."
3643 (if (eq system-type 'windows-nt)
3644 (w32-shell-execute-open-file file)
3645 (start-process "anything-c-open-file-with-default-tool"
3647 (cond ((eq system-type 'gnu/linux)
3648 "xdg-open")
3649 ((or (eq system-type 'darwin) ;; Mac OS X
3650 (eq system-type 'macos)) ;; Mac OS 9
3651 "open"))
3652 file)))
3654 (defun anything-c-open-dired (file)
3655 "Opens a dired buffer in FILE's directory. If FILE is a
3656 directory, open this directory."
3657 (if (file-directory-p file)
3658 (dired file)
3659 (dired (file-name-directory file))
3660 (dired-goto-file file)))
3662 (defun anything-c-display-to-real-line (candidate)
3663 (if (string-match "^ *\\([0-9]+\\):\\(.+\\)$" candidate)
3664 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
3665 (error "Line number not found")))
3667 (defun anything-c-action-line-goto (lineno-and-content)
3668 (apply #'anything-goto-file-line (anything-attr 'target-file)
3669 (append lineno-and-content
3670 (list (if (and (anything-attr-defined 'target-file)
3671 (not anything-in-persistent-action))
3672 'find-file-other-window
3673 'find-file)))))
3675 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
3676 (apply #'anything-goto-file-line file-line-content))
3678 (require 'compile)
3679 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
3680 (mapcar
3681 (lambda (candidate)
3682 (if (not (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.+\\)$" candidate))
3683 (error "Filename and line number not found")
3684 (let ((filename (match-string 1 candidate))
3685 (lineno (match-string 2 candidate))
3686 (content (match-string 3 candidate)))
3687 (cons (format "%s:%s\n %s"
3688 (propertize filename 'face compilation-info-face)
3689 (propertize lineno 'face compilation-line-face)
3690 content)
3691 (list (expand-file-name
3692 filename
3693 (anything-aif (anything-attr 'default-directory)
3694 (if (functionp it) (funcall it) it)
3695 (and (anything-candidate-buffer)
3696 (buffer-local-value
3697 'default-directory
3698 (anything-candidate-buffer)))))
3699 (string-to-number lineno) content)))))
3700 candidates))
3702 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
3703 (anything-aif (anything-attr 'before-jump-hook)
3704 (funcall it))
3705 (when file (funcall find-file-function file))
3706 (if (anything-attr-defined 'adjust)
3707 (anything-c-goto-line-with-adjustment lineno content)
3708 (goto-line lineno))
3709 (unless (anything-attr-defined 'recenter)
3710 (set-window-start (get-buffer-window anything-current-buffer) (point)))
3711 (anything-aif (anything-attr 'after-jump-hook)
3712 (funcall it))
3713 (when anything-in-persistent-action
3714 (anything-match-line-color-current-line)))
3716 (defun anything-find-file-as-root (candidate)
3717 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
3719 ;; borrowed from etags.el
3720 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
3721 (defun anything-c-goto-line-with-adjustment (line line-content)
3722 (let ((startpos)
3723 offset found pat)
3724 ;; This constant is 1/2 the initial search window.
3725 ;; There is no sense in making it too small,
3726 ;; since just going around the loop once probably
3727 ;; costs about as much as searching 2000 chars.
3728 (setq offset 1000
3729 found nil
3730 pat (concat (if (eq selective-display t)
3731 "\\(^\\|\^m\\) *" "^ *") ;allow indent
3732 (regexp-quote line-content)))
3733 ;; If no char pos was given, try the given line number.
3734 (setq startpos (progn (goto-line line) (point)))
3735 (or startpos (setq startpos (point-min)))
3736 ;; First see if the tag is right at the specified location.
3737 (goto-char startpos)
3738 (setq found (looking-at pat))
3739 (while (and (not found)
3740 (progn
3741 (goto-char (- startpos offset))
3742 (not (bobp))))
3743 (setq found
3744 (re-search-forward pat (+ startpos offset) t)
3745 offset (* 3 offset))) ; expand search window
3746 (or found
3747 (re-search-forward pat nil t)
3748 (error "not found")))
3749 ;; Position point at the right place
3750 ;; if the search string matched an extra Ctrl-m at the beginning.
3751 (and (eq selective-display t)
3752 (looking-at "\^m")
3753 (forward-char 1))
3754 (beginning-of-line))
3756 (anything-document-attribute 'default-directory "type . file-line"
3757 "`default-directory' to interpret file.")
3758 (anything-document-attribute 'before-jump-hook "type . file-line / line"
3759 "Function to call before jumping to the target location.")
3760 (anything-document-attribute 'after-jump-hook "type . file-line / line"
3761 "Function to call after jumping to the target location.")
3762 (anything-document-attribute 'adjust "type . file-line"
3763 "Search around line matching line contents.")
3764 (anything-document-attribute 'recenter "type . file-line / line"
3765 "`recenter' after jumping.")
3766 (anything-document-attribute 'target-file "type . line"
3767 "Goto line of target-file.")
3769 (defun anything-c-call-interactively (cmd-or-name)
3770 "Execute CMD-OR-NAME as Emacs command.
3771 It is added to `extended-command-history'.
3772 `anything-current-prefix-arg' is used as the command's prefix argument."
3773 (setq extended-command-history
3774 (cons (anything-c-stringify cmd-or-name)
3775 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
3776 (let ((current-prefix-arg anything-current-prefix-arg)
3777 (cmd (anything-c-symbolify cmd-or-name)))
3778 (if (stringp (symbol-function cmd))
3779 (execute-kbd-macro (symbol-function cmd))
3780 (call-interactively cmd))))
3782 (defun anything-c-set-variable (var)
3783 "Set value to VAR interactively."
3784 (interactive)
3785 (let ((sym (anything-c-symbolify var)))
3786 (set sym (eval-minibuffer (format "Set %s: " var)
3787 (prin1-to-string (symbol-value sym))))))
3788 ;; (setq hh 12)
3789 ;; (anything-c-set-variable 'hh)
3791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3792 (defvar anything-match-line-overlay-face nil)
3793 (defvar anything-match-line-overlay nil)
3795 (defun anything-match-line-color-current-line (&optional start end buf face rec)
3796 "Highlight and underline current position"
3797 (let ((args (list (or start (line-beginning-position))
3798 (or end (1+ (line-end-position)))
3799 buf)))
3800 (if (not anything-match-line-overlay)
3801 (setq anything-match-line-overlay (apply 'make-overlay args))
3802 (apply 'move-overlay anything-match-line-overlay args)))
3803 (overlay-put anything-match-line-overlay
3804 'face (or face anything-match-line-overlay-face))
3805 (when rec
3806 (goto-char start)
3807 (recenter)))
3809 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
3811 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
3812 "Face for source header in the anything buffer." :group 'anything)
3814 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
3816 (add-hook 'anything-cleanup-hook #'(lambda ()
3817 (when anything-match-line-overlay
3818 (delete-overlay anything-match-line-overlay)
3819 (setq anything-match-line-overlay nil))))
3821 (add-hook 'anything-after-persistent-action-hook #'(lambda ()
3822 (when anything-match-line-overlay
3823 (delete-overlay anything-match-line-overlay)
3824 (anything-match-line-color-current-line))))
3826 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3827 ;;; Files
3828 (defun anything-c-transform-file-load-el (actions candidate)
3829 "Add action to load the file CANDIDATE if it is an emacs lisp
3830 file. Else return ACTIONS unmodified."
3831 (if (or (string= (file-name-extension candidate) "el")
3832 (string= (file-name-extension candidate) "elc"))
3833 (append actions '(("Load Emacs Lisp File" . load-file)))
3834 actions))
3836 (defun anything-c-transform-file-browse-url (actions candidate)
3837 "Add an action to browse the file CANDIDATE if it in a html
3838 file or URL. Else return ACTIONS unmodified."
3839 (if (string-match "^http\\|^ftp\\|\\.html?$" candidate)
3840 (cons '("Browse with Browser" . browse-url) actions )
3841 actions))
3843 ;;;; Function
3844 (defun anything-c-transform-function-call-interactively (actions candidate)
3845 "Add an action to call the function CANDIDATE interactively if
3846 it is a command. Else return ACTIONS unmodified."
3847 (if (commandp (intern-soft candidate))
3848 (append actions '(("Call Interactively"
3850 anything-c-call-interactively)))
3851 actions))
3853 ;;;; S-Expressions
3854 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
3855 "If CANDIDATE's `car' is a command, then add an action to
3856 evaluate it and put it onto the `command-history'."
3857 (if (commandp (car (read candidate)))
3858 ;; Make it first entry
3859 (cons '("Eval and put onto command-history" .
3860 (lambda (sexp)
3861 (let ((sym (read sexp)))
3862 (eval sym)
3863 (setq command-history
3864 (cons sym command-history)))))
3865 actions)
3866 actions))
3868 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3869 ;;; Buffers
3870 (defun anything-c-skip-boring-buffers (buffers)
3871 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
3873 (defun anything-c-skip-current-buffer (buffers)
3874 (if anything-allow-skipping-current-buffer
3875 (remove (buffer-name anything-current-buffer) buffers)
3876 buffers))
3878 (defun anything-c-shadow-boring-buffers (buffers)
3879 "Buffers matching `anything-c-boring-buffer-regexp' will be
3880 displayed with the `file-name-shadow' face if available."
3881 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
3883 ;;; Files
3884 (defun anything-c-shadow-boring-files (files)
3885 "Files matching `anything-c-boring-file-regexp' will be
3886 displayed with the `file-name-shadow' face if available."
3887 (anything-c-shadow-entries files anything-c-boring-file-regexp))
3889 (defun anything-c-skip-boring-files (files)
3890 "Files matching `anything-c-boring-file-regexp' will be skipped."
3891 (anything-c-skip-entries files anything-c-boring-file-regexp))
3892 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
3894 (defun anything-c-skip-current-file (files)
3895 "Current file will be skipped."
3896 (remove (buffer-file-name anything-current-buffer) files))
3898 (defun anything-c-w32-pathname-transformer (args)
3899 "Change undesirable features of windows pathnames to ones more acceptable to
3900 other candidate transformers."
3901 (if (eq system-type 'windows-nt)
3902 (mapcar (lambda (x)
3903 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
3904 (mapcar (lambda (y)
3905 (replace-regexp-in-string "\\\\" "/" y)) args))
3906 args))
3908 (defun anything-c-shorten-home-path (files)
3909 "Replaces /home/user with ~."
3910 (mapcar (lambda (file)
3911 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
3912 (getenv "HOME"))))
3913 (if (and (stringp file) (string-match home file))
3914 (cons (replace-match "~" nil nil file) file)
3915 file)))
3916 files))
3918 ;;; Functions
3919 (defun anything-c-mark-interactive-functions (functions)
3920 "Mark interactive functions (commands) with (i) after the function name."
3921 (let (list)
3922 (loop for function in functions
3923 do (push (cons (concat function
3924 (when (commandp (intern-soft function)) " (i)"))
3925 function)
3926 list)
3927 finally (return (nreverse list)))))
3929 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3930 (defvar anything-c-adaptive-done nil
3931 "nil if history information is not yet stored for the current
3932 selection.")
3934 (defvar anything-c-adaptive-history nil
3935 "Contains the stored history information.
3936 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
3938 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
3939 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
3940 when anything is started."
3941 (setq anything-c-adaptive-done nil))
3943 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
3944 "Advise `anything-exit-minibuffer' to store history information
3945 when a candidate is selected with RET."
3946 (anything-c-adaptive-store-selection))
3948 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
3949 "Advise `anything-select-action' to store history information
3950 when the user goes to the action list with TAB."
3951 (anything-c-adaptive-store-selection))
3953 (defun anything-c-adaptive-store-selection ()
3954 "Store history information for the selected candidate."
3955 (unless anything-c-adaptive-done
3956 (setq anything-c-adaptive-done t)
3957 (let* ((source (anything-get-current-source))
3958 (source-name (or (assoc-default 'type source)
3959 (assoc-default 'name source)))
3960 (source-info (or (assoc source-name anything-c-adaptive-history)
3961 (progn
3962 (push (list source-name) anything-c-adaptive-history)
3963 (car anything-c-adaptive-history))))
3964 (selection (anything-get-selection))
3965 (selection-info (progn
3966 (setcdr source-info
3967 (cons
3968 (let ((found (assoc selection (cdr source-info))))
3969 (if (not found)
3970 ;; new entry
3971 (list selection)
3973 ;; move entry to the beginning of the
3974 ;; list, so that it doesn't get
3975 ;; trimmed when the history is
3976 ;; truncated
3977 (setcdr source-info
3978 (delete found (cdr source-info)))
3979 found))
3980 (cdr source-info)))
3981 (cadr source-info)))
3982 (pattern-info (progn
3983 (setcdr selection-info
3984 (cons
3985 (let ((found (assoc anything-pattern (cdr selection-info))))
3986 (if (not found)
3987 ;; new entry
3988 (cons anything-pattern 0)
3990 ;; move entry to the beginning of the
3991 ;; list, so if two patterns used the
3992 ;; same number of times then the one
3993 ;; used last appears first in the list
3994 (setcdr selection-info
3995 (delete found (cdr selection-info)))
3996 found))
3997 (cdr selection-info)))
3998 (cadr selection-info))))
4000 ;; increase usage count
4001 (setcdr pattern-info (1+ (cdr pattern-info)))
4003 ;; truncate history if needed
4004 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
4005 (setcdr selection-info
4006 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))
4008 (if (file-readable-p anything-c-adaptive-history-file)
4009 (load-file anything-c-adaptive-history-file))
4010 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
4012 (defun anything-c-adaptive-save-history ()
4013 "Save history information to file given by `anything-c-adaptive-history-file'."
4014 (interactive)
4015 (with-temp-buffer
4016 (insert
4017 ";; -*- mode: emacs-lisp -*-\n"
4018 ";; History entries used for anything adaptive display.\n")
4019 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
4020 (current-buffer))
4021 (insert ?\n)
4022 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
4023 (unless (interactive-p) 'quiet))))
4025 (defun anything-c-adaptive-sort (candidates source)
4026 "Sort the CANDIDATES for SOURCE by usage frequency.
4027 This is a filtered candidate transformer you can use for the
4028 attribute `filtered-candidate-transformer' of a source in
4029 `anything-sources' or a type in `anything-type-attributes'."
4030 (let* ((source-name (or (assoc-default 'type source)
4031 (assoc-default 'name source)))
4032 (source-info (assoc source-name anything-c-adaptive-history)))
4033 (if (not source-info)
4034 ;; if there is no information stored for this source then do nothing
4035 candidates
4036 ;; else...
4037 (let ((usage
4038 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
4039 ;; pairs
4040 (mapcar (lambda (candidate-info)
4041 (let ((count 0))
4042 (dolist (pattern-info (cdr candidate-info))
4043 (if (not (equal (car pattern-info)
4044 anything-pattern))
4045 (incf count (cdr pattern-info))
4047 ;; if current pattern is equal to the previously
4048 ;; used one then this candidate has priority
4049 ;; (that's why its count is boosted by 10000) and
4050 ;; it only has to compete with other candidates
4051 ;; which were also selected with the same pattern
4052 (setq count (+ 10000 (cdr pattern-info)))
4053 (return)))
4054 (cons (car candidate-info) count)))
4055 (cdr source-info)))
4056 sorted)
4058 ;; sort the list in descending order, so candidates with highest
4059 ;; priorty come first
4060 (setq usage (sort usage (lambda (first second)
4061 (> (cdr first) (cdr second)))))
4063 ;; put those candidates first which have the highest usage count
4064 (dolist (info usage)
4065 (when (member* (car info) candidates
4066 :test 'anything-c-adaptive-compare)
4067 (push (car info) sorted)
4068 (setq candidates (remove* (car info) candidates
4069 :test 'anything-c-adaptive-compare))))
4071 ;; and append the rest
4072 (append (reverse sorted) candidates nil)))))
4074 (defun anything-c-adaptive-compare (x y)
4075 "Compare candidates X and Y taking into account that the
4076 candidate can be in (DISPLAY . REAL) format."
4077 (equal (if (listp x)
4078 (cdr x)
4080 (if (listp y)
4081 (cdr y)
4082 y)))
4084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4085 ;; Plug-in: candidates-file
4086 (defun anything-compile-source--candidates-file (source)
4087 (if (assoc-default 'candidates-file source)
4088 `((init anything-p-candidats-file-init
4089 ,@(let ((orig-init (assoc-default 'init source)))
4090 (cond ((null orig-init) nil)
4091 ((functionp orig-init) (list orig-init))
4092 (t orig-init))))
4093 (candidates-in-buffer)
4094 ,@source)
4095 source))
4096 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
4098 (defun anything-p-candidats-file-init ()
4099 (destructuring-bind (file &optional updating)
4100 (anything-mklist (anything-attr 'candidates-file))
4101 (when (symbolp file)
4102 (setq file (symbol-value file)))
4103 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
4104 (when updating
4105 (buffer-disable-undo)
4106 (font-lock-mode -1)
4107 (auto-revert-mode 1)))))
4109 (anything-document-attribute 'candidates-file "candidates-file plugin"
4110 "Use a file as the candidates buffer.
4112 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
4114 ;; Plug-in: headline
4115 (defun anything-compile-source--anything-headline (source)
4116 (if (assoc-default 'headline source)
4117 (append '((init . anything-headline-init)
4118 (get-line-fn . buffer-substring)
4119 (type . line))
4120 source
4121 '((candidates-in-buffer)))
4122 source))
4123 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
4125 (defun anything-headline-init ()
4126 (when (and (anything-current-buffer-is-modified)
4127 (with-current-buffer anything-current-buffer
4128 (eval (or (anything-attr 'condition) t))))
4129 (anything-headline-make-candidate-buffer
4130 (anything-attr 'headline)
4131 (anything-attr 'subexp))))
4133 (anything-document-attribute 'headline "Headline plug-in"
4134 "Regexp string for anything-headline to scan.")
4135 (anything-document-attribute 'condition "Headline plug-in"
4136 "A sexp representing the condition to use anything-headline.")
4137 (anything-document-attribute 'subexp "Headline plug-in"
4138 "Display (match-string-no-properties subexp).")
4140 (defun anything-headline-get-candidates (regexp subexp)
4141 (save-excursion
4142 (set-buffer anything-current-buffer)
4143 (save-excursion
4144 (goto-char (point-min))
4145 (if (functionp regexp) (setq regexp (funcall regexp)))
4146 (let (hierarchy curhead)
4147 (flet ((matched ()
4148 (if (numberp subexp)
4149 (cons (match-string-no-properties subexp) (match-beginning subexp))
4150 (cons (buffer-substring (point-at-bol) (point-at-eol))
4151 (point-at-bol))))
4152 (hierarchies (headlines)
4153 (1+ (loop for (_ . hierarchy) in headlines
4154 maximize hierarchy)))
4155 (vector-0-n (v n)
4156 (loop for i from 0 to hierarchy
4157 collecting (aref curhead i)))
4158 (arrange (headlines)
4159 (loop with curhead = (make-vector (hierarchies headlines) "")
4160 for ((str . pt) . hierarchy) in headlines
4161 do (aset curhead hierarchy str)
4162 collecting
4163 (cons
4164 (mapconcat 'identity (vector-0-n curhead hierarchy) " / ")
4165 pt))))
4166 (if (listp regexp)
4167 (arrange
4168 (sort
4169 (loop for re in regexp
4170 for hierarchy from 0
4171 do (goto-char (point-min))
4172 appending
4173 (loop
4174 while (re-search-forward re nil t)
4175 collect (cons (matched) hierarchy)))
4176 (lambda (a b) (> (cdar b) (cdar a)))))
4177 (loop while (re-search-forward regexp nil t)
4178 collect (matched))))))))
4180 (defun anything-headline-make-candidate-buffer (regexp subexp)
4181 (with-current-buffer (anything-candidate-buffer 'local)
4182 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
4183 do (insert
4184 (format "%5d:%s\n"
4185 (with-current-buffer anything-current-buffer
4186 (line-number-at-pos pos))
4187 content)))))
4189 (defun anything-headline-goto-position (pos recenter)
4190 (goto-char pos)
4191 (unless recenter
4192 (set-window-start (get-buffer-window anything-current-buffer) (point))))
4194 (defun anything-revert-buffer (candidate)
4195 (with-current-buffer candidate
4196 (when (buffer-modified-p)
4197 (revert-buffer t t))))
4199 (defun anything-revert-marked-buffers (candidate)
4200 (dolist (i (anything-marked-candidates))
4201 (anything-revert-buffer i)))
4203 (defun anything-kill-marked-buffers (candidate)
4204 (dolist (i (anything-marked-candidates))
4205 (kill-buffer i)))
4207 (defun anything-delete-marked-files (candidate)
4208 (dolist (i (anything-marked-candidates))
4209 (anything-c-delete-file i)))
4211 (defun anything-ediff-marked-buffers (candidate &optional merge)
4212 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
4213 With optional arg `merge' call `ediff-merge-buffers'."
4214 (let ((lg-lst (length (anything-marked-candidates)))
4215 buf1 buf2)
4216 (case lg-lst
4218 (error "Error:You have to mark at least 1 buffer"))
4220 (setq buf1 anything-current-buffer
4221 buf2 (first (anything-marked-candidates))))
4223 (setq buf1 (first (anything-marked-candidates))
4224 buf2 (second (anything-marked-candidates))))
4226 (error "Error:To much buffers marked!")))
4227 (if merge
4228 (ediff-merge-buffers buf1 buf2)
4229 (ediff-buffers buf1 buf2))))
4231 (defun anything-bookmark-get-bookmark-from-name (bmk)
4232 "Return bookmark name even if it is a bookmark with annotation.
4233 e.g prepended with *.
4234 Return nil if bmk is not a valid bookmark."
4235 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
4236 (if (assoc bookmark bookmark-alist)
4237 bookmark
4238 (when (assoc bmk bookmark-alist)
4239 bmk))))
4241 (defun anything-delete-marked-bookmarks (elm)
4242 "Delete this bookmark or all marked bookmarks."
4243 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
4244 (anything-aif (anything-marked-candidates)
4245 (dolist (i it)
4246 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
4247 (bookmark-delete bmk 'batch)))
4248 (bookmark-delete bookmark 'batch))))
4250 (defun anything-bookmark-active-region-maybe (candidate)
4251 "Active saved region if this bookmark have one."
4252 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
4253 (condition-case nil
4254 (when (and (boundp bmkext-use-region-flag)
4255 bmkext-use-region-flag)
4256 (let ((bmk-name (or (bmkext-get-buffer-name bookmark)
4257 (file-name-nondirectory
4258 (bookmark-get-filename bookmark)))))
4259 (when bmk-name
4260 (with-current-buffer bmk-name
4261 (setq deactivate-mark nil)))))
4262 (error nil))))
4265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4267 ;;; Type Attributes
4268 (define-anything-type-attribute 'buffer
4269 `((action
4270 ,@(if pop-up-frames
4271 '(("Switch to buffer other window" . switch-to-buffer-other-window)
4272 ("Switch to buffer" . switch-to-buffer))
4273 '(("Switch to buffer" . switch-to-buffer)
4274 ("Switch to buffer other window" . switch-to-buffer-other-window)
4275 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
4276 ("Display buffer" . display-buffer)
4277 ("Revert buffer" . anything-revert-buffer)
4278 ("Revert Marked buffers" . anything-revert-marked-buffers)
4279 ("Kill buffer" . kill-buffer)
4280 ("Kill Marked buffers" . anything-kill-marked-buffers)
4281 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
4282 ("Ediff Merge marked buffers" . (lambda (candidate)
4283 (anything-ediff-marked-buffers candidate t))))
4284 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
4285 "Buffer or buffer name.")
4287 (define-anything-type-attribute 'file
4288 `((action
4289 ,@(if pop-up-frames
4290 '(("Find file other window" . find-file-other-window)
4291 ("Find file" . find-file)
4292 ("Find file as root" . anything-find-file-as-root))
4293 '(("Find file" . find-file)
4294 ("Find file as root" . anything-find-file-as-root)
4295 ("Find file other window" . find-file-other-window)
4296 ("Find file other frame" . find-file-other-frame)))
4297 ("Open dired in file's directory" . anything-c-open-dired)
4298 ("Delete file" . anything-c-delete-file)
4299 ("Delete Marked files" . anything-delete-marked-files)
4300 ("Open file externally" . anything-c-open-file-externally)
4301 ("Open file with default tool" . anything-c-open-file-with-default-tool))
4302 (action-transformer anything-c-transform-file-load-el
4303 anything-c-transform-file-browse-url)
4304 (candidate-transformer anything-c-w32-pathname-transformer
4305 anything-c-skip-current-file
4306 anything-c-skip-boring-files
4307 anything-c-shorten-home-path))
4308 "File name.")
4310 (define-anything-type-attribute 'command
4311 `((action ("Call interactively" . anything-c-call-interactively)
4312 ("Describe command" . anything-c-describe-function)
4313 ("Add command to kill ring" . anything-c-kill-new)
4314 ("Go to command's definition" . anything-c-find-function))
4315 ;; Sort commands according to their usage count.
4316 (filtered-candidate-transformer . anything-c-adaptive-sort))
4317 "Command. (string or symbol)")
4319 (define-anything-type-attribute 'function
4320 '((action ("Describe function" . anything-c-describe-function)
4321 ("Add function to kill ring" . anything-c-kill-new)
4322 ("Go to function's definition" . anything-c-find-function))
4323 (action-transformer anything-c-transform-function-call-interactively)
4324 (candidate-transformer anything-c-mark-interactive-functions))
4325 "Function. (string or symbol)")
4327 (define-anything-type-attribute 'variable
4328 '((action ("Describe variable" . anything-c-describe-variable)
4329 ("Add variable to kill ring" . anything-c-kill-new)
4330 ("Go to variable's definition" . anything-c-find-variable)
4331 ("Set variable" . anything-c-set-variable)))
4332 "Variable.")
4334 (define-anything-type-attribute 'sexp
4335 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
4336 ("Add s-expression to kill ring" . kill-new))
4337 (action-transformer anything-c-transform-sexp-eval-command-sexp))
4338 "String representing S-Expressions.")
4340 (define-anything-type-attribute 'bookmark
4341 `((action
4342 ("Jump to bookmark" . (lambda (candidate)
4343 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
4344 (bookmark-jump bookmark))
4345 (anything-update)
4346 (anything-bookmark-active-region-maybe candidate)))
4347 ("Jump to BM other window" . (lambda (candidate)
4348 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
4349 (bookmark-jump-other-window bookmark))
4350 (anything-update)
4351 (anything-bookmark-active-region-maybe candidate)))
4352 ("Bookmark edit annotation" . (lambda (candidate)
4353 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
4354 (bookmark-edit-annotation bookmark))))
4355 ("Bookmark show annotation" . (lambda (candidate)
4356 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
4357 (bookmark-show-annotation bookmark))))
4358 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
4359 ,@(when (fboundp 'bmkext-edit-bookmark)
4360 '(("Edit Bookmark" . (lambda (candidate)
4361 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
4362 (bmkext-edit-bookmark bookmark))))))
4363 ("Rename bookmark" . (lambda (candidate)
4364 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
4365 (bookmark-rename bookmark))))
4366 ("Relocate bookmark" . (lambda (candidate)
4367 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
4368 (bookmark-relocate bookmark))))))
4369 "Bookmark name.")
4371 (define-anything-type-attribute 'line
4372 '((display-to-real . anything-c-display-to-real-line)
4373 (action ("Go to Line" . anything-c-action-line-goto)))
4374 "LINENO:CONTENT string, eg. \" 16:foo\".")
4376 ;;;; unit test
4377 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4378 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
4379 (dont-compile
4380 (when (fboundp 'expectations)
4381 (expectations
4382 (desc "candidates-file plug-in")
4383 (expect '(anything-p-candidats-file-init)
4384 (assoc-default 'init
4385 (car (anything-compile-sources
4386 '(((name . "test")
4387 (candidates-file . "test.txt")))
4388 '(anything-compile-source--candidates-file)))))
4389 (expect '(anything-p-candidats-file-init
4390 (lambda () 1))
4391 (assoc-default 'init
4392 (car (anything-compile-sources
4393 '(((name . "test")
4394 (candidates-file . "test.txt")
4395 (init . (lambda () 1))))
4396 '(anything-compile-source--candidates-file)))))
4397 (expect '(anything-p-candidats-file-init
4398 (lambda () 1))
4399 (assoc-default 'init
4400 (car (anything-compile-sources
4401 '(((name . "test")
4402 (candidates-file . "test.txt")
4403 (init (lambda () 1))))
4404 '(anything-compile-source--candidates-file)))))
4405 (desc "anything-c-source-buffers")
4406 (expect '(("Buffers" ("foo" "curbuf")))
4407 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
4408 (let ((anything-c-boring-buffer-regexp
4409 (rx (or
4410 (group bos " ")
4411 "*anything"
4412 ;; echo area
4413 " *Echo Area" " *Minibuf"))))
4414 (flet ((buffer-name (x) x))
4415 (anything-test-candidates 'anything-c-source-buffers))))
4416 (desc "anything-c-stringify")
4417 (expect "str1"
4418 (anything-c-stringify "str1"))
4419 (expect "str2"
4420 (anything-c-stringify 'str2))
4421 (desc "anything-c-symbolify")
4422 (expect 'sym1
4423 (anything-c-symbolify "sym1"))
4424 (expect 'sym2
4425 (anything-c-symbolify 'sym2)))))
4428 (provide 'anything-config)
4430 ;;; Local Variables:
4431 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
4432 ;;; End:
4434 ;; How to save (DO NOT REMOVE!!)
4435 ;; (emacswiki-post "anything-config.el")
4436 ;;; anything-config.el ends here
4438 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
4439 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
4440 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
4441 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
4442 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
4443 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
4444 ;;; LocalWords: dotimes Thierry online vname
4445 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
4446 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
4447 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
4448 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
4449 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
4450 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
4451 ;;; LocalWords: startpos noselect dont desc