Update auto document
[anything-config.git] / anything-config.el
blob9dae5251ff5c59b825c6f36089cdcbb673f14230
1 ;;; anything-config.el --- Predefined configurations for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Predefined configurations for `anything.el'
6 ;; Time-stamp: <2009-03-11 00:14:57 (JST) rubikitch>
7 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
8 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
9 ;; Andy Stewart <lazycat.manatee@gmail.com>
10 ;; rubikitch <rubikitch@ruby-lang.org>
11 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
12 ;; Copyright (C) 2007 ~ 2009, Tassilo Horn, all rights reserved.
13 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
14 ;; Copyright (C) 2009, rubikitch, all rights reserved.
15 ;; Copyright (C) 2009, Thierry Volpiatto, all rights reserved.
16 ;; Created: 2009-02-16 21:38:23
17 ;; Version: 0.4.0
18 ;; URL: http://www.emacswiki.org/emacs/download/anything-config.el
19 ;; Keywords: anything, anything-config
20 ;; Compatibility: GNU Emacs 22 ~ 23
22 ;; Features that might be required by this library:
24 ;; `anything'
27 ;;; This file is NOT part of GNU Emacs
29 ;;; License
31 ;; This program is free software; you can redistribute it and/or modify
32 ;; it under the terms of the GNU General Public License as published by
33 ;; the Free Software Foundation; either version 3, or (at your option)
34 ;; any later version.
36 ;; This program is distributed in the hope that it will be useful,
37 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
38 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 ;; GNU General Public License for more details.
41 ;; You should have received a copy of the GNU General Public License
42 ;; along with this program; see the file COPYING. If not, write to
43 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
44 ;; Floor, Boston, MA 02110-1301, USA.
46 ;;; !NOTICE!
48 ;; If this file does not work, upgrade anything.el!
49 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
51 ;;; Commentary:
53 ;; Predefined configurations for `anything.el'
55 ;; For quick start, try `anything-for-files' to open files.
56 ;;
57 ;; To configure anything you should setup `anything-sources'
58 ;; with specify source, like below:
60 ;; (setq anything-sources
61 ;; '(anything-c-source-buffers
62 ;; anything-c-source-buffer-not-found
63 ;; anything-c-source-file-name-history
64 ;; anything-c-source-info-pages
65 ;; anything-c-source-info-elisp
66 ;; anything-c-source-man-pages
67 ;; anything-c-source-locate
68 ;; anything-c-source-emacs-commands
69 ;; ))
71 ;; Below are complete source list you can setup in `anything-sources':
73 ;; Buffer:
74 ;; `anything-c-source-buffers' (Buffers)
75 ;; `anything-c-source-buffer-not-found' (Create buffer)
76 ;; `anything-c-source-buffers+' (Buffers)
77 ;; File:
78 ;; `anything-c-source-file-name-history' (File Name History)
79 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
80 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
81 ;; `anything-c-source-file-cache' (File Cache)
82 ;; `anything-c-source-locate' (Locate)
83 ;; `anything-c-source-recentf' (Recentf)
84 ;; `anything-c-source-ffap-guesser' (File at point)
85 ;; Help:
86 ;; `anything-c-source-man-pages' (Manual Pages)
87 ;; `anything-c-source-info-pages' (Info Pages)
88 ;; `anything-c-source-info-elisp' (Info Elisp)
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 ;; Bookmark:
98 ;; `anything-c-source-bookmarks' (Bookmarks)
99 ;; `anything-c-source-bookmark-set' (Set Bookmark)
100 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
101 ;; `anything-c-source-bookmarks-su' (Bookmarks-su)
102 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
103 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
104 ;; Library:
105 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
106 ;; Programming:
107 ;; `anything-c-source-imenu' (Imenu)
108 ;; `anything-c-source-ctags' (Exuberant ctags)
109 ;; `anything-c-source-semantic' (Semantic Tags)
110 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
111 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
112 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
113 ;; Color and Face:
114 ;; `anything-c-source-customize-face' (Customize Face)
115 ;; `anything-c-source-colors' (Colors)
116 ;; Search Engine:
117 ;; `anything-c-source-tracker-search' (Tracker Search)
118 ;; `anything-c-source-mac-spotlight' (mdfind)
119 ;; Kill ring:
120 ;; `anything-c-source-kill-ring' (Kill Ring)
121 ;; Register:
122 ;; `anything-c-source-register' (Registers)
123 ;; Headline Extraction:
124 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
125 ;; `anything-c-source-rd-headline' (RD HeadLine)
126 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
127 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
128 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
129 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
130 ;; `anything-c-source-org-headline' (Org HeadLine)
131 ;; Misc:
132 ;; `anything-c-source-picklist' (Picklist)
133 ;; `anything-c-source-bbdb' (BBDB)
134 ;; `anything-c-source-evaluation-result' (Evaluation Result)
135 ;; `anything-c-source-calculation-result' (Calculation Result)
136 ;; `anything-c-source-google-suggest' (Google Suggest)
137 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
138 ;; `anything-c-source-call-source' (Call anything source)
139 ;; `anything-c-source-occur' (Occur)
140 ;; `anything-c-source-create' (Create)
141 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
142 ;; System:
143 ;; `anything-c-source-gentoo' (Portage sources)
144 ;; `anything-c-source-use-flags' (Use Flags)
146 ;;; Commands:
148 ;; Below are complete command list:
150 ;; `anything-for-files'
151 ;; Preconfigured `anything' for opening files.
152 ;; `anything-info-at-point'
153 ;; Preconfigured `anything' for searching info at point.
154 ;; `anything-show-kill-ring'
155 ;; Show `kill-ring'. It is drop-in replacement of `yank-pop'.
156 ;; `anything-minibuffer-history'
157 ;; Show `minibuffer-history'.
158 ;; `anything-insert-buffer-name'
159 ;; Insert buffer name.
160 ;; `anything-insert-symbol'
161 ;; Insert current symbol.
162 ;; `anything-insert-selection'
163 ;; Insert current selection.
164 ;; `anything-show-buffer-only'
165 ;; Only show sources about buffer.
166 ;; `anything-show-bbdb-only'
167 ;; Only show sources about BBDB.
168 ;; `anything-show-locate-only'
169 ;; Only show sources about Locate.
170 ;; `anything-show-info-only'
171 ;; Only show sources about Info.
172 ;; `anything-show-imenu-only'
173 ;; Only show sources about Imenu.
174 ;; `anything-show-files-only'
175 ;; Only show sources about File.
176 ;; `anything-show-w3m-bookmarks-only'
177 ;; Only show source about w3m bookmark.
178 ;; `anything-show-colors-only'
179 ;; Only show source about color.
180 ;; `anything-show-kill-ring-only'
181 ;; Only show source about kill ring.
182 ;; `anything-show-this-source-only'
183 ;; Only show this source.
184 ;; `anything-test-sources'
185 ;; List all anything sources for test.
186 ;; `anything-select-source'
187 ;; Select source.
188 ;; `anything-call-source'
189 ;; Call anything source.
190 ;; `anything-call-source-from-anything'
191 ;; Call anything source within `anything' session.
192 ;; `anything-create-from-anything'
193 ;; Run `anything-create' from `anything' as a fallback.
194 ;; `anything-create'
195 ;; Do many create actions from STRING.
196 ;; `anything-gentoo'
197 ;; Start anything with only gentoo sources.
198 ;; `anything-c-adaptive-save-history'
199 ;; Save history information to file given by `anything-c-adaptive-history-file'.
201 ;;; Customizable Options:
203 ;; Below are customizable option list:
205 ;; `anything-c-use-standard-keys'
206 ;; Whether use standard keybindings. (no effect)
207 ;; default = nil
208 ;; `anything-c-adaptive-history-file'
209 ;; Path of file where history information is stored.
210 ;; default = "~/.emacs.d/anything-c-adaptive-history"
211 ;; `anything-c-adaptive-history-length'
212 ;; Maximum number of candidates stored for a source.
213 ;; default = 50
214 ;; `anything-c-google-suggest-url'
215 ;; URL used for looking up suggestions.
216 ;; default = "http://www.google.com/complete/search?hl=en&js=true&qu="
217 ;; `anything-c-google-suggest-search-url'
218 ;; URL used for searching.
219 ;; default = "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
220 ;; `anything-c-boring-buffer-regexp'
221 ;; The regexp that match boring buffers.
222 ;; default = (rx (or (group bos " ") "*anything" " *Echo Area" " *Minibuf"))
223 ;; `anything-c-boring-file-regexp'
224 ;; The regexp that match boring files.
225 ;; default = (rx (or (and "/" ... ...) (and line-start ".#") (and ... eol)))
226 ;; `anything-kill-ring-threshold'
227 ;; *Minimum length to be listed by `anything-c-source-kill-ring'.
228 ;; default = 10
229 ;; `anything-create--actions-private'
230 ;; User defined actions for `anything-create' / `anything-c-source-create'.
231 ;; default = nil
233 ;;; Change log:
235 ;; Change log of this file is found at
236 ;; http://repo.or.cz/w/anything-config.git?a=shortlog;h=b30091a6bb64828eb3d70007db5b68d51b868bcc
238 ;;; Contributors:
240 ;; Tamas Patrovics
241 ;; Tassilo Horn <tassilo@member.fsf.org>
242 ;; Vagn Johansen <gonz808@hotmail.com>
243 ;; Mathias Dahl <mathias.dahl@gmail.com>
244 ;; Bill Clementson <billclem@gmail.com>
245 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
246 ;; Drew Adams <drew.adams@oracle.com>
247 ;; Jason McBrayer <jmcbray@carcosa.net>
248 ;; Andy Stewart <lazycat.manatee@gmail.com>
249 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
250 ;; rubikitch <rubikitch@ruby-lang.org>
251 ;; Scott Vokes <vokes.s@gmail.com>
254 ;;; For Maintainers:
256 ;; Evaluate (anything-c-insert-summary) before commit. This function
257 ;; generates anything-c-source-* list.
259 ;; Install also http://www.emacswiki.org/emacs/auto-document.el
260 ;; And eval it or run interactively.
262 ;; [EVAL IT] (anything-c-insert-summary)
263 ;; [EVAL IT] (auto-document)
265 ;; Please write details documentation about function, then others will
266 ;; read code more easier. -- Andy Stewart
270 ;;; TODO
272 ;; - anything-c-adaptive stores infos for sources/types that don't have
273 ;; set it as `filtered-candidate-transformer'.
275 ;; - Fix documentation, now many functions haven't documentations.
278 ;;; Require
279 (require 'anything)
280 (require 'thingatpt)
282 ;;; Code:
284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
285 (defgroup anything-config nil
286 "Predefined configurations for `anything.el'."
287 :group 'anything)
289 (defcustom anything-c-use-standard-keys nil
290 "Whether use standard keybindings. (no effect)
292 Key definitions in anything-config.el are removed because
293 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
294 minibuffer history, C-s for isearch, etc.
296 If you use `iswitchb' with `anything',
297 evaluate (anything-iswitchb-setup) . Then some bindings that
298 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
299 history, are removed from `anything-map'. "
300 :type 'boolean
301 :group 'anything-config)
303 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
304 "Path of file where history information is stored."
305 :type 'string
306 :group 'anything-config)
308 (defcustom anything-c-adaptive-history-length 50
309 "Maximum number of candidates stored for a source."
310 :type 'number
311 :group 'anything-config)
313 (defcustom anything-c-google-suggest-url
314 "http://www.google.com/complete/search?hl=en&js=true&qu="
315 "URL used for looking up suggestions."
316 :type 'string
317 :group 'anything-config)
319 (defcustom anything-c-google-suggest-search-url
320 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
321 "URL used for searching."
322 :type 'string
323 :group 'anything-config)
325 (defcustom anything-c-boring-buffer-regexp
326 (rx (or
327 (group bos " ")
328 ;; anything-buffer
329 "*anything"
330 ;; echo area
331 " *Echo Area" " *Minibuf"))
332 "The regexp that match boring buffers.
333 Buffer candidates matching this regular expression will be
334 filtered from the list of candidates if the
335 `anything-c-skip-boring-buffers' candidate transformer is used, or
336 they will be displayed with face `file-name-shadow' if
337 `anything-c-shadow-boring-buffers' is used."
338 :type 'string
339 :group 'anything-config)
340 ;; (string-match anything-c-boring-buffer-regexp "buf")
341 ;; (string-match anything-c-boring-buffer-regexp " hidden")
342 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
344 (defcustom anything-c-boring-file-regexp
345 (rx (or
346 ;; Boring directories
347 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
348 ;; Boring files
349 (and line-start ".#")
350 (and (or ".class" ".la" ".o" "~") eol)))
351 "The regexp that match boring files.
352 File candidates matching this regular expression will be
353 filtered from the list of candidates if the
354 `anything-c-skip-boring-files' candidate transformer is used, or
355 they will be displayed with face `file-name-shadow' if
356 `anything-c-shadow-boring-files' is used."
357 :type 'string
358 :group 'anything-config)
360 (defcustom anything-kill-ring-threshold 10
361 "*Minimum length to be listed by `anything-c-source-kill-ring'."
362 :type 'integer
363 :group 'anything-config)
366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
367 (defun anything-for-files ()
368 "Preconfigured `anything' for opening files.
369 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
370 (interactive)
371 (anything '(anything-c-source-ffap-guesser
372 anything-c-source-recentf
373 anything-c-source-buffers+
374 anything-c-source-bookmarks
375 anything-c-source-file-cache
376 anything-c-source-files-in-current-dir+
377 anything-c-source-locate)))
379 (defun anything-info-at-point ()
380 "Preconfigured `anything' for searching info at point."
381 (interactive)
382 (let ((pattern (thing-at-point 'sexp)))
383 (anything '(anything-c-source-info-elisp
384 anything-c-source-info-cl
385 anything-c-source-info-pages)
386 pattern)))
388 (defun anything-show-kill-ring ()
389 "Show `kill-ring'. It is drop-in replacement of `yank-pop'.
390 You may bind this command to M-y."
391 (interactive)
392 (anything 'anything-c-source-kill-ring nil nil nil nil "*anything kill-ring*"))
394 (defun anything-minibuffer-history ()
395 "Show `minibuffer-history'.
396 You may bind this command to C-r in minibuffer-local-map / minibuffer-local-completion-map."
397 (interactive)
398 (anything 'anything-c-source-minibuffer-history nil nil nil nil
399 "*anything minibuffer-history*"))
400 ;; (define-key minibuffer-local-map "\C-r" 'anything-minibuffer-history)
401 ;; (define-key minibuffer-local-completion-map "\C-r" 'anything-minibuffer-history)
403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
405 (defun anything-insert-buffer-name ()
406 "Insert buffer name."
407 (interactive)
408 (anything-insert-string
409 (with-current-buffer anything-current-buffer
410 (if buffer-file-name (file-name-nondirectory buffer-file-name)
411 (buffer-name)))))
413 (defun anything-insert-symbol ()
414 "Insert current symbol."
415 (interactive)
416 (anything-insert-string
417 (with-current-buffer anything-current-buffer
418 (save-excursion
419 (buffer-substring (beginning-of-thing 'symbol)
420 (end-of-thing 'symbol))))))
422 (defun anything-insert-selection ()
423 "Insert current selection."
424 (interactive)
425 (anything-insert-string
426 (with-current-buffer anything-current-buffer
427 (anything-get-selection))))
429 (defun anything-show-buffer-only ()
430 "Only show sources about buffer."
431 (interactive)
432 (anything-set-source-filter '("Buffers")))
434 (defun anything-show-bbdb-only ()
435 "Only show sources about BBDB."
436 (interactive)
437 (anything-set-source-filter '("BBDB")))
439 (defun anything-show-locate-only ()
440 "Only show sources about Locate."
441 (interactive)
442 (anything-set-source-filter '("Locate")))
444 (defun anything-show-info-only ()
445 "Only show sources about Info."
446 (interactive)
447 (anything-set-source-filter '("Info Pages"
448 "Info Elisp"
449 "Info Common-Lisp")))
451 (defun anything-show-imenu-only ()
452 "Only show sources about Imenu."
453 (interactive)
454 (anything-set-source-filter '("Imenu")))
456 (defun anything-show-files-only ()
457 "Only show sources about File."
458 (interactive)
459 (anything-set-source-filter '("File Name History"
460 "Files from Current Directory"
461 "Recentf")))
463 (defun anything-show-w3m-bookmarks-only ()
464 "Only show source about w3m bookmark."
465 (interactive)
466 (anything-set-source-filter '("W3m Bookmarks")))
468 (defun anything-show-colors-only ()
469 "Only show source about color."
470 (interactive)
471 (anything-set-source-filter '("Colors"
472 "Customize Faces")))
474 (defun anything-show-kill-ring-only ()
475 "Only show source about kill ring."
476 (interactive)
477 (anything-set-source-filter '("Kill Ring")))
479 (defun anything-show-this-source-only ()
480 "Only show this source."
481 (interactive)
482 (setq anything-candidate-number-limit 9999)
483 (anything-set-source-filter
484 (list (assoc-default 'name (anything-get-current-source)))))
486 (defun anything-test-sources ()
487 "List all anything sources for test.
488 The output is sexps which are evaluated by \\[eval-last-sexp]."
489 (interactive)
490 (with-output-to-temp-buffer "*Anything Test Sources*"
491 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
492 (apropos-internal "^anything-c-source" #'boundp))
493 (pop-to-buffer standard-output)))
495 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
496 (defun anything-nest (&rest same-as-anything)
497 "Nested `anything'. If you use `anything' within `anything', use it."
498 (with-selected-window (anything-window)
499 (let (anything-current-position
500 anything-current-buffer
501 (orig-anything-buffer anything-buffer)
502 anything-pattern
503 anything-buffer
504 anything-sources
505 anything-compiled-sources
506 anything-buffer-chars-modified-tick
507 (anything-samewindow t)
508 (enable-recursive-minibuffers t))
509 (unwind-protect
510 (apply #'anything same-as-anything)
511 (anything-initialize-overlays orig-anything-buffer)
512 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
514 (defun anything-displaying-source-names ()
515 "Display sources name."
516 (with-current-buffer anything-buffer
517 (goto-char (point-min))
518 (loop with pos
519 while (setq pos (next-single-property-change (point) 'anything-header))
520 do (goto-char pos)
521 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
522 do (forward-line 1))))
524 (defun anything-select-source ()
525 "Select source."
526 (interactive)
527 (let ((default (assoc-default 'name (anything-get-current-source)))
528 (source-names (anything-displaying-source-names))
529 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
530 (anything-get-sources))))
531 (setq anything-candidate-number-limit 9999)
532 (anything-aif
533 (let (anything-source-filter)
534 (anything-nest '(((name . "Anything Source")
535 (candidates . source-names)
536 (action . identity))
537 ((name . "Anything Source (ALL)")
538 (candidates . all-source-names)
539 (action . identity)))
540 nil "Source: " nil
541 default "*anything select source*"))
542 (anything-set-source-filter (list it))
543 (anything-set-source-filter nil))))
545 (defun anything-insert-string (str)
546 "Insert STR."
547 (delete-minibuffer-contents)
548 (insert str))
550 (defun anything-c-match-on-file-name (candidate)
551 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
552 (string-match anything-pattern (file-name-nondirectory candidate)))
554 (defun anything-c-match-on-directory-name (candidate)
555 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
556 (let ((dir (file-name-directory candidate)))
557 (when dir
558 (string-match anything-pattern dir))))
560 (defun anything-c-string-match (candidate)
561 "Return non-nil if `anything-pattern' match CANDIDATE.
562 The match is done with `string-match'."
563 (string-match anything-pattern candidate))
565 (defun anything-c-compose (arg-lst func-lst)
566 "Call each function in FUNC-LST with the arguments specified in ARG-LST.
567 The result of each function will be the new `car' of ARG-LST.
569 This function allows easy sequencing of transformer functions."
570 (dolist (func func-lst)
571 (setcar arg-lst (apply func arg-lst)))
572 (car arg-lst))
574 (defun anything-c-skip-entries (list regexp)
575 "Remove entries which matches REGEXP from LIST."
576 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
577 list))
579 (defun anything-c-shadow-entries (list regexp)
580 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
581 (mapcar (lambda (file)
582 ;; Add shadow face property to boring files.
583 (let ((face (if (facep 'file-name-shadow)
584 'file-name-shadow
585 ;; fall back to default on XEmacs
586 'default)))
587 (if (string-match regexp file)
588 (setq file (propertize file 'face face))))
589 file)
590 list))
592 (defsubst anything-c-stringify (str-or-sym)
593 "Get string of STR-OR-SYM."
594 (if (stringp str-or-sym)
595 str-or-sym
596 (symbol-name str-or-sym)))
598 (defsubst anything-c-symbolify (str-or-sym)
599 "Get symbol of STR-OR-SYM."
600 (if (symbolp str-or-sym)
601 str-or-sym
602 (intern str-or-sym)))
604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
605 ;; TODO
606 (defvar anything-current-prefix-arg nil
607 "`current-prefix-arg' when selecting action.
608 It is cleared after executing action.")
610 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
611 (unless anything-current-prefix-arg
612 (setq anything-current-prefix-arg current-prefix-arg)))
614 (add-hook 'anything-after-action-hook
615 (lambda () (setq anything-current-prefix-arg nil)))
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
619 (defun anything-c-create-summary ()
620 "Create `anything' summary."
621 (save-excursion
622 (goto-char (point-min))
623 (loop while (re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$" nil t)
624 collect (if (match-beginning 1)
625 (cons 'section (match-string-no-properties 1))
626 (cons 'source
627 (cons (match-string-no-properties 2)
628 (assoc-default 'name (symbol-value (intern (match-string-no-properties 2))))))))))
629 ;; (find-epp (anything-c-create-summary))
631 (defun anything-c-insert-summary ()
632 "Insert `anything' summary."
633 (save-excursion
634 (goto-char (point-min))
635 (search-forward ";; Below are complete source list you can setup in")
636 (forward-line 1)
637 (delete-region (point)
638 (progn (search-forward ";;; Change log:" nil t)
639 (forward-line -1) (point)))
640 (insert ";;\n")
641 (loop with beg
642 for (kind . value) in (anything-c-create-summary)
643 for i from 0
644 do (cond ((eq kind 'section)
645 (unless (zerop i)
646 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
647 (insert ";; " value ":\n")
648 (setq beg (point)))
650 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
651 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
652 ;; (anything-c-insert-summary)
654 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
655 ;;;; <Buffer>
656 (defun anything-c-buffer-list ()
657 "Return the list of names of buffers with boring buffers filtered out.
658 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
659 The first buffer in the list will be the last recently used
660 buffer that is not the current buffer."
661 (let ((buffers (mapcar 'buffer-name (buffer-list))))
662 (append (cdr buffers) (list (car buffers)))))
664 (defvar anything-c-source-buffers
665 '((name . "Buffers")
666 (candidates . anything-c-buffer-list)
667 (volatile)
668 (type . buffer)))
669 ;; (anything 'anything-c-source-buffers)
671 (defvar anything-c-source-buffer-not-found
672 '((name . "Create buffer")
673 (dummy)
674 (type . buffer)))
675 ;; (anything 'anything-c-source-buffer-not-found)
677 ;;; Buffers+
678 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
679 "*Face used for directory headings in dired buffers."
680 :group 'anything)
682 (defface anything-file-name
683 '((t (:foreground "Blue")))
684 "*Face used for file names (without suffixes) in dired buffers."
685 :group 'anything)
687 (defface anything-dir-priv
688 '((t (:foreground "DarkRed" :background "LightGray")))
689 "*Face used for directory privilege indicator (d) in dired buffers."
690 :group 'anything)
692 (defvar anything-c-buffers-face1 'anything-dir-priv)
693 (defvar anything-c-buffers-face2 'font-lock-type-face)
694 (defvar anything-c-buffers-face3 'italic)
695 (defun anything-c-highlight-buffers (buffers)
696 (let ((cand-mod (loop for i in buffers
697 if (rassoc (get-buffer i) dired-buffers)
698 collect (propertize i
699 'face anything-c-buffers-face1
700 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
701 if (buffer-file-name (get-buffer i))
702 collect (propertize i
703 'face anything-c-buffers-face2
704 'help-echo (buffer-file-name (get-buffer i)))
705 if (and (not (rassoc (get-buffer i) dired-buffers))
706 (not (buffer-file-name (get-buffer i))))
707 collect (propertize i
708 'face anything-c-buffers-face3))))
709 cand-mod))
711 (defvar anything-c-source-buffers+
712 '((name . "Buffers")
713 (candidates . anything-c-buffer-list)
714 (volatile)
715 (type . buffer)
716 (candidate-transformer . (lambda (candidates)
717 (anything-c-compose
718 (list candidates)
719 '(anything-c-highlight-buffers
720 anything-c-skip-boring-buffers))))
721 (persistent-action . (lambda (name)
722 (flet ((kill (item)
723 (with-current-buffer item
724 (if (and (buffer-modified-p)
725 (buffer-file-name (current-buffer)))
726 (progn
727 (save-buffer)
728 (kill-buffer item))
729 (kill-buffer item))))
730 (goto (item)
731 (switch-to-buffer item)))
732 (if current-prefix-arg
733 (progn
734 (kill name)
735 (anything-delete-current-selection))
736 (goto name)))))))
738 ;; (anything 'anything-c-source-buffers+)
741 ;;;; <File>
742 ;;; File name history
743 (defvar anything-c-source-file-name-history
744 '((name . "File Name History")
745 (candidates . file-name-history)
746 (match . (anything-c-match-on-file-name
747 anything-c-match-on-directory-name))
748 (type . file)))
749 ;; (anything 'anything-c-source-file-name-history)
751 ;;; Files in current dir
752 (defvar anything-c-source-files-in-current-dir
753 '((name . "Files from Current Directory")
754 (init . (lambda ()
755 (setq anything-c-default-directory
756 default-directory)))
757 (candidates . (lambda ()
758 (directory-files
759 anything-c-default-directory)))
760 (volatile)
761 (type . file)))
762 ;; (anything 'anything-c-source-files-in-current-dir)
764 (defvar anything-c-files-face1 'anything-dir-priv)
765 (defvar anything-c-files-face2 'anything-file-name)
766 (defun anything-c-highlight-files (files)
767 (let ((cand-mod (loop for i in files
768 if (file-directory-p i)
769 collect (propertize (file-name-nondirectory i)
770 'face anything-c-files-face1
771 'help-echo (expand-file-name i))
772 else
773 collect (propertize (file-name-nondirectory i)
774 'face anything-c-files-face2
775 'help-echo (expand-file-name i)))))
776 cand-mod))
779 (defvar anything-c-source-files-in-current-dir+
780 '((name . "Files from Current Directory")
781 (init . (lambda ()
782 (setq anything-c-default-directory
783 (expand-file-name default-directory))))
784 (candidates . (lambda ()
785 (directory-files
786 anything-c-default-directory t)))
787 (candidate-transformer . (lambda (candidates)
788 (anything-c-compose
789 (list candidates)
790 '(anything-c-highlight-files))))
791 (volatile)
792 (type . file)))
794 ;; (anything 'anything-c-source-files-in-current-dir+)
796 ;;; File Cache
797 (defvar anything-c-source-file-cache-initialized nil)
799 (defvar anything-c-file-cache-files nil)
801 (defvar anything-c-source-file-cache
802 '((name . "File Cache")
803 (init . (lambda ()
804 (require 'filecache nil t)
805 (unless anything-c-source-file-cache-initialized
806 (setq anything-c-file-cache-files
807 (loop for item in file-cache-alist append
808 (destructuring-bind (base &rest dirs) item
809 (loop for dir in dirs collect
810 (concat dir base)))))
811 (defadvice file-cache-add-file (after file-cache-list activate)
812 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
813 (setq anything-c-source-file-cache-initialized t))))
814 (candidates . anything-c-file-cache-files)
815 (match . (anything-c-match-on-file-name
816 anything-c-match-on-directory-name))
817 (type . file)))
818 ;; (anything 'anything-c-source-file-cache)
820 ;;; Locate
821 (defvar anything-c-locate-options
822 (cond
823 ((eq system-type 'darwin) '("locate"))
824 ((eq system-type 'berkeley-unix) '("locate" "-i"))
825 (t '("locate" "-i" "-r")))
826 "A list where the `car' is the name of the locat program followed by options.
827 The search pattern will be appended, so the
828 \"-r\" option should be the last option.")
830 (defvar anything-c-source-locate
831 '((name . "Locate")
832 (candidates . (lambda ()
833 (apply 'start-process "locate-process" nil
834 (append anything-c-locate-options
835 (list anything-pattern)))))
836 (type . file)
837 (requires-pattern . 3)
838 (delayed))
839 "Source for retrieving files matching the current input pattern with locate.")
840 ;; (anything 'anything-c-source-locate)
842 ;;; Recentf files
843 (defvar anything-c-source-recentf
844 '((name . "Recentf")
845 (init . (lambda ()
846 (require 'recentf)
847 (or recentf-mode (recentf-mode 1))
848 ;; Big value empowers anything/recentf
849 (when (and (numberp recentf-max-saved-items)
850 (<= recentf-max-saved-items 20))
851 (setq recentf-max-saved-items 500))))
852 (candidates . recentf-list)
853 (match . (anything-c-match-on-file-name
854 anything-c-match-on-directory-name))
855 (type . file))
856 "See (info \"(emacs)File Conveniences\").
857 if `recentf-max-saved-items' is too small, set it to 500.")
858 ;; (anything 'anything-c-source-recentf)
860 ;;; ffap
861 (defvar anything-c-source-ffap-guesser
862 '((name . "File at point")
863 (init . (lambda () (require 'ffap)))
864 (candidates . (lambda ()
865 (let ((guess (with-current-buffer anything-current-buffer
866 (ffap-guesser))))
867 (if guess (list guess)))))
868 (type . file)))
869 ;; (anything 'anything-c-source-ffap-guesser)
871 ;;;; <Help>
872 ;;; Man Pages
873 (defvar anything-c-man-pages nil
874 "All man pages on system.
875 Will be calculated the first time you invoke anything with this
876 source.")
878 (defvar anything-c-source-man-pages
879 `((name . "Manual Pages")
880 (candidates . (lambda ()
881 (if anything-c-man-pages
882 anything-c-man-pages
883 ;; XEmacs doesn't have a woman :)
884 (setq anything-c-man-pages
885 (condition-case nil
886 (progn
887 (require 'woman)
888 (woman-file-name "")
889 (sort (mapcar 'car
890 woman-topic-all-completions)
891 'string-lessp))
892 (error nil))))))
893 (action . (("Show with Woman" . woman)))
894 (requires-pattern . 2)))
895 ;; (anything 'anything-c-source-man-pages)
897 ;;; Info pages
898 (defvar anything-c-info-pages nil
899 "All info pages on system.
900 Will be calculated the first time you invoke anything with this
901 source.")
903 (defvar anything-c-source-info-pages
904 `((name . "Info Pages")
905 (candidates . (lambda ()
906 (if anything-c-info-pages
907 anything-c-info-pages
908 (setq anything-c-info-pages
909 (save-window-excursion
910 (save-excursion
911 (require 'info)
912 (Info-find-node "dir" "top")
913 (goto-char (point-min))
914 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
915 topics)
916 (while (re-search-forward info-topic-regexp nil t)
917 (add-to-list 'topics (match-string-no-properties 1)))
918 (goto-char (point-min))
919 (Info-exit)
920 topics)))))))
921 (action . (("Show with Info" .(lambda (node-str)
922 (info (replace-regexp-in-string "^[^:]+: "
924 node-str))))))
925 (requires-pattern . 2)))
926 ;; (anything 'anything-c-source-info-pages)
928 ;; Info Elisp
929 (defvar anything-c-info-elisp nil)
930 (defvar anything-c-source-info-elisp
931 `((name . "Info Elisp")
932 (init . (lambda ()
933 (save-window-excursion
934 (unless anything-c-info-elisp
935 (with-temp-buffer
936 (Info-find-node "elisp" "Index")
937 (setq anything-c-info-elisp (split-string (buffer-string) "\n"))
938 (Info-exit))))))
939 (candidates . (lambda ()
940 (loop for i in anything-c-info-elisp
941 if (string-match "^* [^ \n]+[^: ]" i)
942 collect (match-string 0 i))))
943 (action . (lambda (candidate)
944 (Info-find-node "elisp" "Index")
945 (Info-index (replace-regexp-in-string "* " "" candidate))))
946 (volatile)
947 (requires-pattern . 2)))
948 ;; (anything 'anything-c-source-info-elisp)
950 ;; Info-Common-Lisp
951 (defvar anything-c-info-cl-fn nil)
952 (defvar anything-c-source-info-cl
953 `((name . "Info Common-Lisp")
954 (init . (lambda ()
955 (save-window-excursion
956 (unless anything-c-info-cl-fn
957 (with-temp-buffer
958 (Info-find-node "cl" "Function Index")
959 (setq anything-c-info-cl-fn (split-string (buffer-string) "\n"))
960 (Info-exit))))))
961 (candidates . (lambda ()
962 (loop for i in anything-c-info-cl-fn
963 if (string-match "^* [^ \n]+[^: ]" i)
964 collect (match-string 0 i))))
965 (action . (("Goto Info Node" . (lambda (candidate)
966 (Info-find-node "cl" "Function Index")
967 (Info-index (replace-regexp-in-string "* " "" candidate))))
968 ("Find Example" . (lambda (candidate)
969 (and (fboundp 'traverse-deep-rfind)
970 (traverse-deep-rfind traverse-example-directory
971 (replace-regexp-in-string "* " "" candidate)
972 ".el"))))))
973 (volatile)
974 (requires-pattern . 2)))
976 ;;;; <Command>
977 ;;; Complex command history
978 (defvar anything-c-source-complex-command-history
979 '((name . "Complex Command History")
980 (candidates . (lambda ()
981 (mapcar 'prin1-to-string
982 command-history)))
983 (volatile)
984 (type . sexp)))
985 ;; (anything 'anything-c-source-complex-command-history)
987 ;;; M-x history
988 (defvar anything-c-source-extended-command-history
989 '((name . "Emacs Commands History")
990 (candidates . extended-command-history)
991 (type . command)))
992 ;; (anything 'anything-c-source-extended-command-history)
994 ;;; Emacs commands
995 (defvar anything-c-source-emacs-commands
996 '((name . "Emacs Commands")
997 (candidates . (lambda ()
998 (let (commands)
999 (mapatoms (lambda (a)
1000 (if (commandp a)
1001 (push (symbol-name a)
1002 commands))))
1003 (sort commands 'string-lessp))))
1004 (volatile)
1005 (type . command)
1006 (requires-pattern . 2))
1007 "Source for completing and invoking Emacs commands.
1008 A command is a function with interactive spec that can
1009 be invoked with `M-x'.
1011 To get non-interactive functions listed, use
1012 `anything-c-source-emacs-functions'.")
1013 ;; (anything 'anything-c-source-emacs-commands)
1015 ;;; LaCarte
1016 (defvar anything-c-source-lacarte
1017 '((name . "Lacarte")
1018 (init . (lambda ()
1019 (require 'lacarte )))
1020 (candidates . (lambda ()
1021 (delete '(nil) (lacarte-get-overall-menu-item-alist))))
1022 (candidate-number-limit . 9999)
1023 (action . anything-c-call-interactively))
1024 "Needs lacarte.el.
1026 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
1027 ;; (anything 'anything-c-source-lacarte)
1029 ;;;; <Function>
1030 ;;; Emacs functions
1031 (defvar anything-c-source-emacs-functions
1032 '((name . "Emacs Functions")
1033 (candidates . (lambda ()
1034 (let (commands)
1035 (mapatoms (lambda (a)
1036 (if (functionp a)
1037 (push (symbol-name a)
1038 commands))))
1039 (sort commands 'string-lessp))))
1040 (volatile)
1041 (type . function)
1042 (requires-pattern . 2))
1043 "Source for completing Emacs functions.")
1044 ;; (anything 'anything-c-source-emacs-functions)
1046 ;;; With abbrev expansion
1047 ;;; Similar to my exec-abbrev-cmd.el
1048 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
1049 (defvar anything-c-function-abbrev-regexp nil
1050 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
1051 Regexp built from the current `anything-pattern' interpreting it
1052 as abbreviation.
1053 Only for internal use.")
1055 (defun anything-c-match-function-by-abbrev (candidate)
1056 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
1058 Abbreviations are made by taking the first character from each
1059 word in the function's name, e.g. \"bb\" is an abbrev for
1060 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
1061 (string-match anything-c-function-abbrev-regexp candidate))
1063 (defvar anything-c-source-emacs-functions-with-abbrevs
1064 (append anything-c-source-emacs-functions
1065 '((match . (anything-c-match-function-by-abbrev
1066 anything-c-string-match)))
1067 '((init . (lambda ()
1068 (defadvice anything-update
1069 (before anything-c-update-function-abbrev-regexp activate)
1070 (let ((char-list (append anything-pattern nil))
1071 (str "^"))
1072 (dolist (c char-list)
1073 (setq str (concat str (list c) "[^-]*-")))
1074 (setq str (concat (substring str 0 (1- (length str))) "$"))
1075 (setq anything-c-function-abbrev-regexp str))))))))
1076 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
1078 ;;;; <Bookmark>
1079 ;;; Bookmarks
1080 (defvar anything-c-source-bookmarks
1081 '((name . "Bookmarks")
1082 (init . (lambda ()
1083 (require 'bookmark)))
1084 (candidates . bookmark-all-names)
1085 (type . bookmark))
1086 "See (info \"(emacs)Bookmarks\").")
1087 ;; (anything 'anything-c-source-bookmarks)
1089 ;;; bookmark-set
1090 (defvar anything-c-source-bookmark-set
1091 '((name . "Set Bookmark")
1092 (dummy)
1093 (action . bookmark-set))
1094 "See (info \"(emacs)Bookmarks\").")
1095 ;; (anything 'anything-c-source-bookmark-set)
1097 ;;; Visible Bookmarks
1098 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
1101 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
1102 ;; modified by me
1103 (defvar anything-c-source-bm
1104 '((name . "Visible Bookmarks")
1105 (init . anything-c-source-bm-init)
1106 (candidates-in-buffer)
1107 (type . line))
1108 "Needs bm.el.
1110 http://www.nongnu.org/bm/")
1112 (defun anything-c-source-bm-init ()
1113 "Init function for `anything-c-source-bm'."
1114 (when (require 'bm nil t)
1115 (with-no-warnings
1116 (let ((bookmarks (bm-lists))
1117 (buf (anything-candidate-buffer 'global)))
1118 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
1119 '< :key 'overlay-start))
1120 (let ((start (overlay-start bm))
1121 (end (overlay-end bm))
1122 (annotation (or (overlay-get bm 'annotation) "")))
1123 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
1124 (let ((str (format "%7d: [%s]: %s\n"
1125 (line-number-at-pos start)
1126 annotation
1127 (buffer-substring start (1- end)))))
1128 (with-current-buffer buf (insert str))))))))))
1130 ;;; Special bookmarks
1131 (defvar anything-c-source-bookmarks-ssh
1132 '((name . "Bookmarks-ssh")
1133 (init . (lambda ()
1134 (require 'bookmark)))
1135 (candidates . (lambda ()
1136 (let (lis-all
1137 lis-ssh)
1138 (setq lis-all (bookmark-all-names))
1139 (setq lis-ssh (loop for i in lis-all
1140 if (string-match "^(ssh)" i)
1141 collect i))
1142 (sort lis-ssh 'string-lessp))))
1143 (type . bookmark))
1144 "See (info \"(emacs)Bookmarks\").")
1145 ;; (anything 'anything-c-source-bookmarks-ssh)
1147 (defvar anything-c-source-bookmarks-su
1148 '((name . "Bookmarks-su")
1149 (init . (lambda ()
1150 (require 'bookmark)))
1151 (candidates . (lambda ()
1152 (let (lis-all
1153 lis-su)
1154 (setq lis-all (bookmark-all-names))
1155 (setq lis-su (loop for i in lis-all
1156 if (string-match "^(su)" i)
1157 collect i))
1158 (sort lis-su 'string-lessp))))
1159 (candidate-transformer . (lambda (candidates)
1160 (anything-c-compose
1161 (list candidates)
1162 '(anything-c-highlight-bookmark-su))))
1164 (type . bookmark))
1165 "See (info \"(emacs)Bookmarks\").")
1166 ;; (anything 'anything-c-source-bookmarks-su)
1168 (defface anything-bookmarks-su-face '((t (:foreground "red")))
1169 "TRAVERSEDIR face."
1170 :group 'traverse-faces)
1172 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
1173 (defvar anything-c-bookmarks-face2 'anything-file-name)
1174 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
1176 (defun tv-root-logged-p ()
1177 (catch 'break
1178 (dolist (i (mapcar #'buffer-name
1179 (buffer-list)))
1180 (when (string-match "*tramp/su ." i)
1181 (throw 'break t)))))
1184 (defun anything-c-highlight-bookmark-su (files)
1185 (if (tv-root-logged-p)
1186 (anything-c-highlight-bookmark files)
1187 (anything-c-highlight-not-logged files)))
1189 (defun anything-c-highlight-not-logged (files)
1190 (let ((cand-mod (loop for i in files
1191 collect (propertize i
1192 'face anything-c-bookmarks-face3))))
1193 cand-mod))
1195 (defun anything-c-highlight-bookmark (files)
1196 (let ((cand-mod (loop for i in files
1197 if (file-directory-p (bookmark-get-filename i))
1198 collect (propertize i
1199 'face anything-c-bookmarks-face1)
1200 else
1201 collect (propertize i
1202 'face anything-c-bookmarks-face2))))
1203 cand-mod))
1205 (defvar anything-c-source-bookmarks-local
1206 '((name . "Bookmarks-Local")
1207 (init . (lambda ()
1208 (require 'bookmark)))
1209 (candidates . (lambda ()
1210 (let (lis-all
1211 lis-loc)
1212 (setq lis-all (bookmark-all-names))
1213 (setq lis-loc (loop for i in lis-all
1214 if (and (not (string-match "^(ssh)" i))
1215 (not (string-match "^(su)" i)))
1216 collect i))
1217 (sort lis-loc 'string-lessp))))
1218 (candidate-transformer . (lambda (candidates)
1219 (anything-c-compose
1220 (list candidates)
1221 '(anything-c-highlight-bookmark))))
1222 (type . bookmark))
1223 "See (info \"(emacs)Bookmarks\").")
1224 ;; (anything 'anything-c-source-bookmarks-local)
1227 ;; W3m bookmark
1228 (unless (and (require 'w3m nil t)
1229 (require 'w3m-bookmark nil t))
1230 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
1231 ;; (defvar anything-w3m-bookmarks-regexp ">[^><]+[^</a>]+[a-z)0-9]+")
1233 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
1234 "Face for w3m bookmarks" :group 'anything)
1236 (defvar anything-w3m-bookmarks-regexp ">[^><]+.[^</a>]")
1237 (defun anything-w3m-bookmarks-to-alist ()
1238 (let ((bookmarks-alist)
1239 (url)
1240 (title))
1241 (with-temp-buffer
1242 (insert-file-contents w3m-bookmark-file) ;; or w3m-bookmark-file
1243 (goto-char (point-min))
1244 (while (not (eobp))
1245 (forward-line)
1246 (when (re-search-forward "href=" nil t)
1247 (beginning-of-line)
1248 (when (re-search-forward "http://[^>]*" nil t)
1249 (setq url (concat "\"" (match-string 0))))
1250 (beginning-of-line)
1251 (when (re-search-forward anything-w3m-bookmarks-regexp nil t)
1252 (setq title (match-string 0)))
1253 (push (cons title url) bookmarks-alist))))
1254 (setq bookmarks-alist (reverse bookmarks-alist))))
1256 (defvar anything-c-w3m-bookmarks-alist nil)
1257 (defvar anything-c-source-w3m-bookmarks
1258 '((name . "W3m Bookmarks")
1259 (init . (lambda ()
1260 (setq anything-c-w3m-bookmarks-alist
1261 (anything-w3m-bookmarks-to-alist))))
1262 (candidates . (lambda ()
1263 (mapcar #'car
1264 anything-c-w3m-bookmarks-alist)))
1265 (filtered-candidate-transformer . (lambda (candidates source)
1266 (anything-c-compose
1267 (list candidates)
1268 '(anything-c-highlight-w3m-bookmarks))))
1269 (action . (("Browse Url" . (lambda (candidate)
1270 (anything-c-w3m-browse-bookmark candidate)))
1271 ("Copy Url" . (lambda (elm)
1272 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
1273 ("Browse Url Firefox" . (lambda (candidate)
1274 (anything-c-w3m-browse-bookmark candidate t)))
1275 ("Delete Bookmark" . (lambda (candidate)
1276 (anything-c-w3m-delete-bookmark candidate)))
1277 ("Rename Bookmark" . (lambda (candidate)
1278 (anything-c-w3m-rename-bookmark candidate)))))
1279 (persistent-action . (lambda (candidate)
1280 (if current-prefix-arg
1281 (anything-c-w3m-browse-bookmark candidate t)
1282 (anything-c-w3m-browse-bookmark candidate nil t))))
1283 (delayed)
1284 (volatile)))
1285 ;; (anything 'anything-c-source-w3m-bookmarks)
1287 (defun anything-c-w3m-bookmarks-get-value (elm)
1288 (let ((value
1289 (replace-regexp-in-string "\"" ""
1290 (cdr (assoc elm
1291 anything-c-w3m-bookmarks-alist)))))
1292 value))
1294 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
1295 (let* ((fn (if use-firefox
1296 'browse-url-firefox
1297 'w3m-browse-url))
1298 (arg (if (and (eq fn 'w3m-browse-url)
1299 new-tab)
1301 nil)))
1302 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
1305 (defun anything-c-highlight-w3m-bookmarks (books)
1306 (let ((cand-mod (loop for i in books
1307 collect (propertize i
1308 'face 'anything-w3m-bookmarks-face
1309 'help-echo (anything-c-w3m-bookmarks-get-value i)))))
1310 cand-mod))
1313 (defun anything-c-w3m-delete-bookmark (elm)
1314 (save-excursion
1315 (find-file-literally w3m-bookmark-file)
1316 (goto-char (point-min))
1317 (when (re-search-forward elm nil t)
1318 (beginning-of-line)
1319 (delete-region (point)
1320 (line-end-position))
1321 (delete-blank-lines))
1322 (save-buffer (current-buffer))
1323 (kill-buffer (current-buffer))))
1325 (defun anything-c-w3m-rename-bookmark (elm)
1326 (let* ((old-title (replace-regexp-in-string ">" "" elm))
1327 (new-title (read-string "NewTitle: " old-title)))
1328 (save-excursion
1329 (find-file-literally w3m-bookmark-file)
1330 (goto-char (point-min))
1331 (when (re-search-forward (concat elm "<") nil t)
1332 (goto-char (1- (point)))
1333 (delete-backward-char (length old-title))
1334 (insert new-title))
1335 (save-buffer (current-buffer))
1336 (kill-buffer (current-buffer)))))
1338 ;;;; <Library>
1339 ;;; Elisp library scan
1340 (defvar anything-c-source-elisp-library-scan
1341 '((name . "Elisp libraries (Scan)")
1342 (init . (anything-c-elisp-library-scan-init))
1343 (candidates-in-buffer)
1344 (action . (("Find library" . (lambda (candidate)
1345 (find-file (find-library-name candidate))))
1346 ("Find library other window" . (lambda (candidate)
1347 (find-file-other-window (find-library-name candidate))))
1348 ("Load library" . (lambda (candidate)
1349 (load-library candidate)))))))
1350 ;; (anything 'anything-c-source-elisp-library-scan)
1352 (defun anything-c-elisp-library-scan-init ()
1353 "Init anything buffer status."
1354 (let ((anything-buffer (anything-candidate-buffer 'global))
1355 (library-list (anything-c-elisp-library-scan-list)))
1356 (with-current-buffer anything-buffer
1357 (dolist (library library-list)
1358 (insert (format "%s\n" library))))))
1360 (defun anything-c-elisp-library-scan-list (&optional dirs string)
1361 "Do completion for file names passed to `locate-file'.
1362 DIRS is directory to search path.
1363 STRING is string to match."
1364 ;; Use `load-path' as path when ignore `dirs'.
1365 (or dirs (setq dirs load-path))
1366 ;; Init with blank when ignore `string'.
1367 (or string (setq string ""))
1368 ;; Get library list.
1369 (let ((string-dir (file-name-directory string))
1370 ;; File regexp that suffix match `load-file-rep-suffixes'.
1371 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
1372 name
1373 names)
1374 (dolist (dir dirs)
1375 (unless dir
1376 (setq dir default-directory))
1377 (if string-dir
1378 (setq dir (expand-file-name string-dir dir)))
1379 (when (file-directory-p dir)
1380 (dolist (file (file-name-all-completions
1381 (file-name-nondirectory string) dir))
1382 ;; Suffixes match `load-file-rep-suffixes'.
1383 (setq name (if string-dir (concat string-dir file) file))
1384 (if (string-match match-regexp name)
1385 (add-to-list 'names name)))))
1386 names))
1388 ;;;; <Programming>
1389 ;;; Imenu
1390 (defvar anything-c-imenu-delimiter " / ")
1392 (defvar anything-c-imenu-index-filter nil)
1393 (make-variable-buffer-local 'anything-c-imenu-index-filter)
1395 (defvar anything-c-cached-imenu-alist nil)
1396 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
1398 (defvar anything-c-cached-imenu-candidates nil)
1399 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
1401 (defvar anything-c-cached-imenu-tick nil)
1402 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
1404 (setq imenu-auto-rescan t)
1406 (defun anything-imenu-create-candidates (entry)
1407 "Create candidates with ENTRY."
1408 (if (listp (cdr entry))
1409 (mapcan (lambda (sub)
1410 (if (consp (cdr sub))
1411 (mapcar
1412 (lambda (subentry)
1413 (concat (car entry) anything-c-imenu-delimiter subentry))
1414 (anything-imenu-create-candidates sub))
1415 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
1416 (cdr entry))
1417 (list entry)))
1419 (defvar anything-c-source-imenu
1420 '((name . "Imenu")
1421 (init . (lambda ()
1422 (setq anything-c-imenu-current-buffer
1423 (current-buffer))))
1424 (candidates . (lambda ()
1425 (with-current-buffer anything-c-imenu-current-buffer
1426 (let ((tick (buffer-modified-tick)))
1427 (if (eq anything-c-cached-imenu-tick tick)
1428 anything-c-cached-imenu-candidates
1429 (setq imenu--index-alist nil)
1430 (setq anything-c-cached-imenu-tick tick
1431 anything-c-cached-imenu-candidates
1432 (condition-case nil
1433 (mapcan
1434 'anything-imenu-create-candidates
1435 (setq anything-c-cached-imenu-alist
1436 (let ((index (imenu--make-index-alist)))
1437 (if anything-c-imenu-index-filter
1438 (funcall anything-c-imenu-index-filter index)
1439 index))))
1440 (error nil)))
1441 (setq anything-c-cached-imenu-candidates
1442 (mapcar #'(lambda (x)
1443 (if (stringp x)
1445 (car x)))
1446 anything-c-cached-imenu-candidates)))))))
1447 (volatile)
1448 (persistent-action . (lambda (elm)
1449 (anything-c-imenu-default-action elm)
1450 (unless (fboundp 'semantic-imenu-tag-overlay)
1451 (anything-match-line-color-current-line))))
1452 (action . (lambda (elm)
1453 (anything-c-imenu-default-action elm))))
1454 "See (info \"(emacs)Imenu\")")
1456 ;; (anything 'anything-c-source-imenu)
1458 (setq imenu-default-goto-function 'imenu-default-goto-function)
1459 (defun anything-c-imenu-default-action (elm)
1460 "The default action for `anything-c-source-imenu'."
1461 (let ((path (split-string elm anything-c-imenu-delimiter))
1462 (alist anything-c-cached-imenu-alist))
1463 (if (> (length path) 1)
1464 (progn
1465 (setq alist (assoc (car path) alist))
1466 (setq elm (cadr path))
1467 (imenu (assoc elm alist)))
1468 (imenu (assoc elm alist)))))
1470 ;;; Ctags
1471 (defvar anything-c-ctags-modes
1472 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
1473 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
1474 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
1476 (defun anything-c-source-ctags-init ()
1477 (when (and buffer-file-name
1478 (memq major-mode anything-c-ctags-modes)
1479 (anything-current-buffer-is-modified))
1480 (with-current-buffer (anything-candidate-buffer 'local)
1481 (call-process-shell-command
1482 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
1483 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
1484 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
1485 nil (current-buffer))
1486 (goto-char (point-min))
1487 (forward-line 2)
1488 (delete-region (point-min) (point))
1489 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
1490 for lineno-start = (point)
1491 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
1493 (beginning-of-line)
1494 (insert (format "%5s:" lineno))
1495 (search-forward "\177" (point-at-eol) t)
1496 (delete-region (1- (point)) (point-at-eol))
1497 (forward-line 1)))))
1499 (defvar anything-c-source-ctags
1500 '((name . "Exuberant ctags")
1501 (init
1502 . anything-c-source-ctags-init)
1503 (candidates-in-buffer)
1504 (adjust)
1505 (type . line))
1506 "Needs Exuberant Ctags.
1508 http://ctags.sourceforge.net/")
1509 ;; (anything 'anything-c-source-ctags)
1511 ;; Semantic
1512 (defun anything-semantic-construct-candidates (tags depth)
1513 (when (require 'semantic nil t)
1514 (apply 'append (mapcar (lambda (tag)
1515 (if (listp tag)
1516 (let ((type (semantic-tag-type tag))
1517 (class (semantic-tag-class tag)))
1518 (if (or (and (stringp type)
1519 (string= type "class"))
1520 (eq class 'function)
1521 (eq class 'variable))
1522 (cons (cons (concat (make-string (* depth 2) ?\s)
1523 (semantic-format-tag-summarize tag nil t)) tag)
1524 (anything-semantic-construct-candidates (semantic-tag-components tag)
1525 (1+ depth)))))))
1526 tags))))
1528 (defun anything-semantic-default-action (candidate)
1529 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
1530 (semantic-go-to-tag tag)))
1532 (defvar anything-c-source-semantic
1533 '((name . "Semantic Tags")
1534 (init . (lambda ()
1535 (setq anything-semantic-candidates
1536 (condition-case nil
1537 (anything-semantic-construct-candidates (semantic-fetch-tags) 0)
1538 (error nil)))))
1539 (candidates . (lambda ()
1540 (if anything-semantic-candidates
1541 (mapcar 'car anything-semantic-candidates))))
1542 (persistent-action . (lambda (elm)
1543 (anything-semantic-default-action elm)
1544 (anything-match-line-color-current-line)))
1545 (action . (("Goto tag" . (lambda (candidate)
1546 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
1547 (semantic-go-to-tag tag)))))))
1548 "Needs semantic in CEDET.
1550 http://cedet.sourceforge.net/semantic.shtml
1551 http://cedet.sourceforge.net/")
1553 ;; (anything 'anything-c-source-semantic)
1555 ;;; Function is called by
1556 (defvar anything-c-source-simple-call-tree-functions-callers
1557 '((name . "Function is called by")
1558 (init . (lambda ()
1559 (require 'simple-call-tree)
1560 (when (anything-current-buffer-is-modified)
1561 (simple-call-tree-analyze)
1562 (let ((list (simple-call-tree-invert simple-call-tree-alist)))
1563 (with-current-buffer (anything-candidate-buffer 'local)
1564 (dolist (entry list)
1565 (let ((callers (mapconcat #'identity (cdr entry) ", ")))
1566 (insert (car entry) " is called by "
1567 (if (string= callers "")
1568 "no functions."
1569 callers)
1570 ".\n"))))))))
1571 (delayed)
1572 (candidates-in-buffer))
1573 "Needs simple-call-tree.el.
1574 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
1575 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
1577 ;;; Function calls
1578 (defvar anything-c-source-simple-call-tree-callers-functions
1579 '((name . "Function calls")
1580 (init . (lambda ()
1581 (require 'simple-call-tree)
1582 (when (anything-current-buffer-is-modified)
1583 (simple-call-tree-analyze)
1584 (let ((list simple-call-tree-alist))
1585 (with-current-buffer (anything-candidate-buffer 'local)
1586 (dolist (entry list)
1587 (let ((functions (mapconcat #'identity (cdr entry) ", ")))
1588 (insert (car entry) " calls "
1589 (if (string= functions "")
1590 "no functions"
1591 functions)
1592 ".\n"))))))))
1593 (delayed)
1594 (candidates-in-buffer))
1595 "Needs simple-call-tree.el.
1596 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
1597 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
1599 ;;; Commands/Options with doc
1600 (defvar anything-c-auto-document-data nil)
1601 (make-variable-buffer-local 'anything-c-auto-document-data)
1602 (defvar anything-c-source-commands-and-options-in-file
1603 '((name . "Commands/Options in file")
1604 (header-name
1605 . (lambda (x) (format "Commands/Options in %s"
1606 (buffer-local-value 'buffer-file-name anything-current-buffer))))
1607 (candidates . anything-command-and-options-candidates)
1608 (multiline)
1609 (action . imenu))
1610 "List Commands and Options with doc. It needs auto-document.el .
1612 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
1614 (defun anything-command-and-options-candidates ()
1615 (with-current-buffer anything-current-buffer
1616 (when (and (require 'auto-document nil t)
1617 (eq major-mode 'emacs-lisp-mode)
1618 (or (anything-current-buffer-is-modified)
1619 (not anything-c-auto-document-data)))
1620 (or imenu--index-alist (imenu--make-index-alist t))
1621 (setq anything-c-auto-document-data
1622 (destructuring-bind (commands options)
1623 (adoc-construct anything-current-buffer)
1624 (append
1625 (loop for (command . doc) in commands
1626 for cmdname = (symbol-name command)
1627 collect
1628 (cons (format "Command: %s\n %s"
1629 (propertize cmdname 'face font-lock-function-name-face)
1630 (adoc-first-line doc))
1631 (assoc cmdname imenu--index-alist)))
1632 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
1633 for (option doc default) in options
1634 for optname = (symbol-name option)
1635 collect
1636 (cons (format "Option: %s\n %s\n default = %s"
1637 (propertize optname 'face font-lock-variable-name-face)
1638 (adoc-first-line doc)
1639 (adoc-prin1-to-string default))
1640 (assoc optname
1641 var-alist)))))))
1642 anything-c-auto-document-data))
1644 ;; (anything 'anything-c-source-commands-and-options-in-file)
1646 ;;;; <Color and Face>
1647 ;;; Customize Face
1648 (defvar anything-c-source-customize-face
1649 '((name . "Customize Face")
1650 (init . (lambda ()
1651 (unless (anything-candidate-buffer)
1652 (save-window-excursion (list-faces-display))
1653 (anything-candidate-buffer (get-buffer "*Faces*")))))
1654 (candidates-in-buffer)
1655 (get-line . buffer-substring)
1656 (action . (lambda (line)
1657 (customize-face (intern (car (split-string line))))))
1658 (requires-pattern . 3))
1659 "See (info \"(emacs)Faces\")")
1660 ;; (anything 'anything-c-source-customize-face)
1662 ;; Color
1663 (defvar anything-c-source-colors
1664 '((name . "Colors")
1665 (init . (lambda () (unless (anything-candidate-buffer)
1666 (save-window-excursion (list-colors-display))
1667 (anything-candidate-buffer (get-buffer "*Colors*")))))
1668 (candidates-in-buffer)
1669 (get-line . buffer-substring)
1670 (action . (("Copy Name" . (lambda (candidate)
1671 (kill-new (anything-c-colors-get-name candidate))))
1672 ("Copy RGB" . (lambda (candidate)
1673 (kill-new (anything-c-colors-get-rgb candidate))))
1674 ("Insert Name" . (lambda (candidate)
1675 (with-current-buffer anything-current-buffer
1676 (insert (anything-c-colors-get-name candidate)))))
1677 ("Insert RGB" . (lambda (candidate)
1678 (with-current-buffer anything-current-buffer
1679 (insert (anything-c-colors-get-rgb candidate)))))))
1680 (requires-pattern . 3)))
1681 ;; (anything 'anything-c-source-colors)
1683 (defun anything-c-colors-get-name (candidate)
1684 "Get color name."
1685 (replace-regexp-in-string
1686 " " ""
1687 (with-temp-buffer
1688 (insert (capitalize candidate))
1689 (goto-char (point-min))
1690 (search-forward-regexp "\\s-\\{2,\\}")
1691 (kill-line)
1692 (buffer-string))))
1694 (defun anything-c-colors-get-rgb (candidate)
1695 "Get color RGB."
1696 (replace-regexp-in-string
1697 " " ""
1698 (with-temp-buffer
1699 (insert (capitalize candidate))
1700 (goto-char (point-max))
1701 (search-backward-regexp "\\s-\\{2,\\}")
1702 (kill-region (point) (point-min))
1703 (buffer-string))))
1705 ;;;; <Search Engine>
1706 ;;; Tracker desktop search
1707 (defvar anything-c-source-tracker-search
1708 '((name . "Tracker Search")
1709 (candidates . (lambda ()
1710 (start-process "tracker-search-process" nil
1711 "tracker-search"
1712 anything-pattern)))
1713 (type . file)
1714 (requires-pattern . 3)
1715 (delayed))
1716 "Source for retrieving files matching the current input pattern
1717 with the tracker desktop search.")
1718 ;; (anything 'anything-c-source-tracker-search)
1720 ;;; Spotlight (MacOS X desktop search)
1721 (defvar anything-c-source-mac-spotlight
1722 '((name . "mdfind")
1723 (candidates . (lambda ()
1724 (start-process "mdfind-process" nil
1725 "mdfind" anything-pattern)))
1726 (type . file)
1727 (requires-pattern . 3)
1728 (delayed))
1729 "Source for retrieving files via Spotlight's command line
1730 utility mdfind.")
1731 ;; (anything 'anything-c-source-mac-spotlight)
1733 ;;;; <Kill ring>
1734 ;;; Kill ring
1735 (defvar anything-c-source-kill-ring
1736 '((name . "Kill Ring")
1737 (init . (lambda () (anything-attrset 'last-command last-command)))
1738 (candidates . (lambda ()
1739 (loop for kill in kill-ring
1740 unless (or (< (length kill) anything-kill-ring-threshold)
1741 (string-match "^[\\s\\t]+$" kill))
1742 collect kill)))
1743 (action . anything-c-kill-ring-action)
1744 (last-command)
1745 (migemo)
1746 (multiline))
1747 "Source for browse and insert contents of kill-ring.")
1749 (defun anything-c-kill-ring-action (str)
1750 "Insert STR in `kill-ring' and set STR to the head.
1751 If this action is executed just after `yank', replace with STR as yanked string."
1752 (setq kill-ring (delete str kill-ring))
1753 (if (not (eq (anything-attr 'last-command) 'yank))
1754 (insert-for-yank str)
1755 ;; from `yank-pop'
1756 (let ((inhibit-read-only t)
1757 (before (< (point) (mark t))))
1758 (if before
1759 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
1760 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
1761 (setq yank-undo-function nil)
1762 (set-marker (mark-marker) (point) (current-buffer))
1763 (insert-for-yank str)
1764 ;; Set the window start back where it was in the yank command,
1765 ;; if possible.
1766 (set-window-start (selected-window) yank-window-start t)
1767 (if before
1768 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1769 ;; It is cleaner to avoid activation, even though the command
1770 ;; loop would deactivate the mark because we inserted text.
1771 (goto-char (prog1 (mark t)
1772 (set-marker (mark-marker) (point) (current-buffer)))))))
1773 (kill-new str))
1775 ;; (anything 'anything-c-source-kill-ring)
1777 ;;;; <Register>
1778 ;;; Insert from register
1779 (defvar anything-c-source-register
1780 '((name . "Registers")
1781 (candidates . anything-c-register-candidates)
1782 (action-transformer . anything-c-register-action-transformer)
1783 (multiline)
1784 (action))
1785 "See (info \"(emacs)Registers\")")
1787 (defun anything-c-register-candidates ()
1788 "Collecting register contents and appropriate commands."
1789 (loop for (char . val) in register-alist
1790 for key = (single-key-description char)
1791 for string-actions = (cond
1792 ((numberp val)
1793 (list (int-to-string val)
1794 'insert-register
1795 'increment-register))
1796 ((markerp val)
1797 (let ((buf (marker-buffer val)))
1798 (if (null buf)
1799 (list "a marker in no buffer")
1800 (list (concat
1801 "a buffer position:"
1802 (buffer-name buf)
1803 ", position "
1804 (int-to-string (marker-position val)))
1805 'jump-to-register
1806 'insert-register))))
1807 ((and (consp val) (window-configuration-p (car val)))
1808 (list "window configuration."
1809 'jump-to-register))
1810 ((and (consp val) (frame-configuration-p (car val)))
1811 (list "frame configuration."
1812 'jump-to-register))
1813 ((and (consp val) (eq (car val) 'file))
1814 (list (concat "file:"
1815 (prin1-to-string (cdr val))
1816 ".")
1817 'jump-to-register))
1818 ((and (consp val) (eq (car val) 'file-query))
1819 (list (concat "file:a file-query reference: file "
1820 (car (cdr val))
1821 ", position "
1822 (int-to-string (car (cdr (cdr val))))
1823 ".")
1824 'jump-to-register))
1825 ((consp val)
1826 (let ((lines (format "%4d" (length val))))
1827 (list (format "%s: %s\n" lines
1828 (truncate-string-to-width
1829 (mapconcat 'identity (list (car val))
1830 ;; (mapconcat (lambda (y) y) val
1831 "^J") (- (window-width) 15)))
1832 'insert-register)))
1833 ((stringp val)
1834 (list ;; without properties
1835 (substring-no-properties val)
1836 'insert-register
1837 'append-to-register
1838 'prepend-to-register))
1840 "GARBAGE!"))
1841 collect (cons (format "register %3s: %s" key (car string-actions))
1842 (cons char (cdr string-actions)))))
1844 (defun anything-c-register-action-transformer (actions register-and-functions)
1845 "Decide actions by the contents of register."
1846 (let ((descriptions
1847 '((insert-register
1848 "Insert Register" .
1849 (lambda (c) (insert-register (car c))))
1850 (jump-to-register
1851 "Jump to Register" .
1852 (lambda (c) (jump-to-register (car c))))
1853 (append-to-register
1854 "Append Region to Register" .
1855 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
1856 (prepend-to-register
1857 "Prepend Region to Register" .
1858 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
1859 (increment-register
1860 "Increment Prefix Arg to Register" .
1861 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))))
1862 (loop for func in (cdr register-and-functions)
1863 for cell = (assq func descriptions)
1864 when cell
1865 collect (cdr cell))))
1867 ;; (anything 'anything-c-source-register)
1869 ;;;; <Headline Extraction>
1870 (defvar anything-c-source-fixme
1871 '((name . "TODO/FIXME/DRY comments")
1872 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
1873 (adjust)
1874 (recenter))
1875 "Show TODO/FIXME/DRY comments in current file.")
1876 ;; (anything 'anything-c-source-fixme)
1878 (defvar anything-c-source-rd-headline
1879 '((name . "RD HeadLine")
1880 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
1881 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
1882 (migemo)
1883 (subexp . 1))
1884 "Show RD headlines.
1886 RD is Ruby's POD.
1887 http://en.wikipedia.org/wiki/Ruby_Document_format")
1888 ;; (anything 'anything-c-source-rd-headline)
1890 (defvar anything-c-source-oddmuse-headline
1891 '((name . "Oddmuse HeadLine")
1892 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
1893 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
1894 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
1895 (migemo)
1896 (subexp . 1))
1897 "Show Oddmuse headlines, such as EmacsWiki.")
1898 ;; (anything 'anything-c-source-oddmuse-headline)
1900 (defvar anything-c-source-emacs-source-defun
1901 '((name . "Emacs Source DEFUN")
1902 (headline . "DEFUN\\|DEFVAR")
1903 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
1904 "Show DEFUN/DEFVAR in Emacs C source file.")
1905 ;; (anything 'anything-c-source-emacs-source-defun)
1907 (defvar anything-c-source-emacs-lisp-expectations
1908 '((name . "Emacs Lisp Expectations")
1909 (headline . "(desc \\|(expectations")
1910 (condition . (eq major-mode 'emacs-lisp-mode)))
1911 "Show descriptions (desc) in Emacs Lisp Expectations.
1913 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
1914 ;; (anything 'anything-c-source-emacs-lisp-expectations)
1916 (defvar anything-c-source-emacs-lisp-toplevels
1917 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
1918 (headline . "^(\\|(@\\*\\|^;;;;")
1919 (get-line . buffer-substring)
1920 (condition . (eq major-mode 'emacs-lisp-mode))
1921 (adjust))
1922 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
1923 linkd.el is optional because linkd stars are extracted by regexp.
1924 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
1925 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
1927 (defvar anything-c-source-org-headline
1928 '((name . "Org HeadLine")
1929 (headline
1930 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
1931 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
1932 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
1933 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
1934 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
1935 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
1936 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
1937 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
1938 (condition . (eq major-mode 'org-mode))
1939 (migemo)
1940 (subexp . 1)
1941 (persistent-action . (lambda (elm)
1942 (anything-c-action-line-goto elm)
1943 (org-cycle)))
1944 (action-transformer
1945 . (lambda (actions candidate)
1946 '(("Go to Line" . anything-c-action-line-goto)
1947 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
1948 "Show Org headlines.
1949 org-mode is very very much extended text-mode/outline-mode.
1951 See (find-library \"org.el\")
1952 See http://orgmode.org for the latest version.")
1954 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
1955 (insert
1956 (save-excursion
1957 (goto-line (car lineno-and-content))
1958 (and (looking-at "^\\*+ \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
1959 (org-make-link-string (concat "*" (match-string 1)))))))
1961 ;; (anything 'anything-c-source-org-headline)
1963 ;;;; <Misc>
1964 ;;; Picklist
1965 (defvar anything-c-source-picklist
1966 '((name . "Picklist")
1967 (candidates . (lambda ()
1968 (mapcar 'car picklist-list)))
1969 (volatile)
1970 (type . file)))
1971 ;; (anything 'anything-c-source-picklist)
1973 ;;; BBDB
1974 (defun anything-c-bbdb-candidates ()
1975 "Return a list of all names in the bbdb database. The format
1976 is \"Firstname Lastname\"."
1977 (mapcar (lambda (bbdb-record)
1978 (replace-regexp-in-string
1979 "\\s-+$" ""
1980 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
1981 (bbdb-records)))
1983 (defun anything-c-bbdb-create-contact (actions candidate)
1984 "Action transformer that returns only an entry to add the
1985 current `anything-pattern' as new contact. All other actions are
1986 removed."
1987 (if (string= candidate "*Add to contacts*")
1988 '(("Add to contacts" . (lambda (actions)
1989 (bbdb-create-internal
1990 (read-from-minibuffer "Name: " anything-c-bbdb-name)
1991 (read-from-minibuffer "Company: ")
1992 (read-from-minibuffer "Email: ")
1995 (read-from-minibuffer "Note: ")))))
1996 actions))
1998 (defun anything-c-bbdb-get-record (candidate)
1999 "Return record that match CANDIDATE."
2000 (bbdb candidate nil)
2001 (set-buffer "*BBDB*")
2002 (bbdb-current-record))
2004 (defvar anything-c-bbdb-name nil
2005 "Only for internal use.")
2007 (defvar anything-c-source-bbdb
2008 '((name . "BBDB")
2009 (candidates . anything-c-bbdb-candidates)
2010 (volatile)
2011 (action ("Send a mail" . (lambda (candidate)
2012 (bbdb-send-mail (anything-c-bbdb-get-record candidate))))
2013 ("View person's data" . (lambda (candidate)
2014 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate)))))
2015 (filtered-candidate-transformer . (lambda (candidates source)
2016 (setq anything-c-bbdb-name anything-pattern)
2017 (if (not candidates)
2018 (list "*Add to contacts*")
2019 candidates)))
2020 (action-transformer . (lambda (actions candidate)
2021 (anything-c-bbdb-create-contact actions candidate)))))
2022 ;; (anything 'anything-c-source-bbdb)
2024 ;;; Evaluation Result
2025 (defvar anything-c-source-evaluation-result
2026 '((name . "Evaluation Result")
2027 (requires-pattern)
2028 (match (lambda (candidate) t))
2029 (candidates "dummy")
2030 (filtered-candidate-transformer . (lambda (candidates source)
2031 (list
2032 (condition-case nil
2033 (prin1-to-string
2034 (eval (read anything-pattern)))
2035 (error "Error")))))
2036 (volatile)
2037 (action ("Do Nothing" . ignore))))
2038 ;; (anything 'anything-c-source-evaluation-result)
2040 ;;; Calculation Result
2041 (defvar anything-c-source-calculation-result
2042 '((name . "Calculation Result")
2043 (requires-pattern)
2044 (match (lambda (candidate) t))
2045 (candidates "dummy")
2046 (filtered-candidate-transformer . (lambda (candidates source)
2047 (list
2048 (condition-case nil
2049 (calc-eval anything-pattern)
2050 (error "error")))))
2051 (volatile)
2052 (action ("Copy result to kill-ring" . (lambda (elm)
2053 (kill-new elm))))))
2054 ;; (anything 'anything-c-source-calculation-result)
2056 ;;; Google Suggestions
2057 (defvar anything-c-source-google-suggest
2058 '((name . "Google Suggest")
2059 (candidates . (lambda ()
2060 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
2061 (if (some (lambda (suggestion)
2062 (equal (cdr suggestion) anything-input))
2063 suggestions)
2064 suggestions
2065 ;; if there is no suggestion exactly matching the input then
2066 ;; prepend a Search on Google item to the list
2067 (append (list (cons (concat "Search for "
2068 "'" anything-input "'"
2069 " on Google")
2070 anything-input))
2071 suggestions)))))
2072 (action . (("Google Search" .
2073 (lambda (candidate)
2074 (browse-url (concat anything-c-google-suggest-search-url
2075 (url-hexify-string candidate)))))))
2076 (volatile)
2077 (requires-pattern . 3)
2078 (delayed)))
2079 ;; (anything 'anything-c-source-google-suggest)
2081 (defun anything-c-google-suggest-fetch (input)
2082 "Fetch suggestions for INPUT."
2083 (let* ((result (with-current-buffer
2084 (url-retrieve-synchronously
2085 (concat anything-c-google-suggest-url
2086 (url-hexify-string input)))
2087 (buffer-substring (point-min) (point-max))))
2088 (split (split-string result "new Array("))
2089 (suggestions (anything-c-google-suggest-get-items (second split)))
2090 (numbers (anything-c-google-suggest-get-items (third split)))
2091 (longest (+ (apply 'max 0 (let (lengths)
2092 (dotimes (i (length suggestions))
2093 (push (+ (length (nth i suggestions))
2094 (length (nth i numbers)))
2095 lengths))
2096 lengths))
2097 10))
2098 items)
2099 (dotimes (i (length suggestions))
2100 (let ((suggestion (nth i suggestions))
2101 (number (nth i numbers)))
2102 (push (cons (concat suggestion
2103 (make-string (- longest
2104 (length suggestion)
2105 (length number))
2107 number)
2108 suggestion)
2109 items)))
2110 items))
2112 (defun anything-c-google-suggest-get-items (str)
2113 "Extract items from STR returned by Google Suggest."
2114 (let ((start nil)
2115 items)
2116 (while (string-match "\"\\([^\"]+?\\)\"" str start)
2117 (push (match-string 1 str) items)
2118 (setq start (1+ (match-end 1))))
2119 items))
2121 ;;; Jabber Contacts (jabber.el)
2122 (defun anything-c-jabber-online-contacts ()
2123 "List online Jabber contacts."
2124 (with-no-warnings
2125 (let (jids)
2126 (dolist (item (jabber-concat-rosters) jids)
2127 (when (get item 'connected)
2128 (push (if (get item 'name)
2129 (cons (get item 'name) item)
2130 (cons (symbol-name item) item)) jids))))))
2132 (defvar anything-c-source-jabber-contacts
2133 '((name . "Jabber Contacts")
2134 (init . (lambda () (require 'jabber)))
2135 (candidates . (lambda ()
2136 (mapcar
2137 'car
2138 (anything-c-jabber-online-contacts))))
2139 (action . (lambda (x)
2140 (jabber-chat-with
2141 (jabber-read-account)
2142 (symbol-name
2143 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
2144 ;; (anything 'anything-c-source-jabber-contacts)
2147 ;;; Call source.
2148 (defvar anything-source-select-buffer "*anything source select*")
2149 (defvar anything-c-source-call-source
2150 `((name . "Call anything source")
2151 (candidate-number-limit . 9999)
2152 (candidates . (lambda ()
2153 (loop for vname in (all-completions "anything-c-source-" obarray)
2154 for var = (intern vname)
2155 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
2156 if name collect (cons (format "%s (%s)" name vname) var))))
2157 (action . (("Invoke anything with selected source" .
2158 (lambda (candidate)
2159 (setq anything-candidate-number-limit 9999)
2160 (anything candidate nil nil nil nil
2161 anything-source-select-buffer)))
2162 ("Describe variable" . describe-variable)))
2163 (persistent-action . describe-variable)))
2164 ;; (anything 'anything-c-source-call-source)
2166 (defun anything-call-source ()
2167 "Call anything source."
2168 (interactive)
2169 (anything 'anything-c-source-call-source nil nil nil nil
2170 anything-source-select-buffer))
2172 (defun anything-call-source-from-anything ()
2173 "Call anything source within `anything' session."
2174 (interactive)
2175 (setq anything-input-idle-delay 0)
2176 (anything-set-sources '(anything-c-source-call-source)))
2178 ;; Occur
2179 (defvar anything-c-source-occur
2180 '((name . "Occur")
2181 (init . (lambda ()
2182 (setq anything-c-source-occur-current-buffer
2183 (current-buffer))))
2184 (candidates . (lambda ()
2185 (setq anything-occur-buf (get-buffer-create "*Anything Occur*"))
2186 (with-current-buffer anything-occur-buf
2187 (erase-buffer)
2188 (let ((count (occur-engine anything-pattern
2189 (list anything-c-source-occur-current-buffer) anything-occur-buf
2190 list-matching-lines-default-context-lines nil
2191 list-matching-lines-buffer-name-face
2192 nil list-matching-lines-face
2193 (not (eq occur-excluded-properties t)))))
2194 (when (> count 0)
2195 (let ((lines (split-string (buffer-string) "\n" t)))
2196 (cdr lines)))))))
2197 (action . (("Goto line" . (lambda (candidate)
2198 (goto-line (string-to-number candidate) anything-c-source-occur-current-buffer)))))
2199 (requires-pattern . 1)
2200 (volatile)))
2201 ;; (anything 'anything-c-source-occur)
2203 ;; Create many actions for input
2204 (defvar anything-c-source-create
2205 '((name . "Create")
2206 (dummy)
2207 (action)
2208 (candidate-number-limit . 9999)
2209 (action-transformer . anything-create--actions))
2210 "Do many create actions from `anything-pattern'.
2211 See also `anything-create--actions'.")
2212 ;; (anything 'anything-c-source-create)
2213 (defcustom anything-create--actions-private nil
2214 "User defined actions for `anything-create' / `anything-c-source-create'.
2215 It is a list of (DISPLAY . FUNCTION) pairs like `action'
2216 attribute of `anything-sources'.
2218 It is prepended to predefined pairs."
2219 :type 'list
2220 :group 'anything-config)
2222 (defun anything-create-from-anything ()
2223 "Run `anything-create' from `anything' as a fallback."
2224 (interactive)
2225 (anything-run-after-quit 'anything-create nil anything-pattern))
2227 (defun anything-create (&optional string initial-input)
2228 "Do many create actions from STRING.
2229 See also `anything-create--actions'."
2230 (interactive)
2231 (setq string (or string (read-string "Create Anything: " initial-input)))
2232 (anything '(((name . "Anything Create")
2233 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
2234 (candidates . anything-create--actions)
2235 (candidate-number-limit . 9999)
2236 (action . (lambda (func) (funcall func string)))))))
2238 (defun anything-create--actions (&rest ignored)
2239 "Default actions for `anything-create' / `anything-c-source-create'."
2240 (remove-if-not
2241 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
2242 (append anything-create--actions-private
2243 '(("find-file" . find-file)
2244 ("find-file other window" . find-file-other-window)
2245 ("New buffer" . switch-to-buffer)
2246 ("New buffer other window" . switch-to-buffer-other-window)
2247 ("Bookmark Set" . bookmark-set)
2248 ("Set Register" .
2249 (lambda (x) (set-register (read-char "Register: ") x)))
2250 ("Insert Linkd star" . linkd-insert-star)
2251 ("Insert Linkd Tag" . linkd-insert-tag)
2252 ("Insert Linkd Link" . linkd-insert-link)
2253 ("Insert Linkd Lisp" . linkd-insert-lisp)
2254 ("Insert Linkd Wiki" . linkd-insert-wiki)
2255 ("Google Search" . google)))))
2257 ;; Minibuffer History
2258 (defvar anything-c-source-minibuffer-history
2259 '((name . "Minibuffer History")
2260 (candidates . minibuffer-history)
2261 (migemo)
2262 (action . insert)))
2264 ;; (anything 'anything-c-source-minibuffer-history)
2265 ;;;; <System>
2267 ;; Sources for gentoo users
2269 (defvar anything-c-gentoo-world-file "/var/lib/portage/world")
2270 (defvar anything-c-gentoo-use-flags nil)
2271 (defvar anything-c-gentoo-buffer "*anything-gentoo*")
2272 (defvar anything-c-cache-gentoo nil)
2273 (defvar anything-c-cache-world nil)
2274 (defvar anything-c-source-gentoo
2275 '((name . "Portage sources")
2276 (init . (lambda ()
2277 (get-buffer-create anything-c-gentoo-buffer)
2278 (unless anything-c-cache-world
2279 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
2280 (unless anything-c-cache-gentoo
2281 (setq anything-c-cache-gentoo (anything-c-gentoo-init-list)))))
2282 (candidates . anything-c-cache-gentoo)
2283 (filtered-candidate-transformer . (lambda (candidates source)
2284 (anything-c-compose
2285 (list candidates)
2286 '(anything-c-highlight-world))))
2287 (action . (("Show package" . (lambda (elm)
2288 (when (get-buffer "*EShell Command Output*")
2289 (kill-buffer "*EShell Command Output*"))
2290 (eshell-command (format "eix %s" elm))))
2291 ("Show history" . (lambda (elm)
2292 (when (get-buffer "*EShell Command Output*")
2293 (kill-buffer "*EShell Command Output*"))
2294 (eshell-command (format "genlop -qe %s" elm))))
2295 ("Browse HomePage" . (lambda (elm)
2296 (browse-url (car (anything-c-gentoo-get-url elm)))))
2297 ("Show extra infos" . (lambda (elm)
2298 (when (get-buffer "*EShell Command Output*")
2299 (kill-buffer "*EShell Command Output*"))
2300 (eshell-command (format "genlop -qi %s" elm))))
2301 ("Show use flags" . (lambda (elm)
2302 (switch-to-buffer anything-c-gentoo-buffer)
2303 (erase-buffer)
2304 (apply #'call-process "equery" nil t nil
2305 `("-C"
2306 "-q"
2308 ,elm))
2309 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
2310 (font-lock-mode 1)))
2311 ("Run emerge pretend" . (lambda (elm)
2312 (when (get-buffer "*EShell Command Output*")
2313 (kill-buffer "*EShell Command Output*"))
2314 (eshell-command (format "emerge -p %s" elm))))
2315 ("Show dependencies" . (lambda (elm)
2316 (switch-to-buffer anything-c-gentoo-buffer)
2317 (erase-buffer)
2318 (apply #'call-process "equery" nil t nil
2319 `("-C"
2320 "-q"
2322 ,elm))))
2323 ("Update" . (lambda (elm)
2324 (setq anything-c-cache-gentoo (anything-c-gentoo-init-list))
2325 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
2327 ;; (anything 'anything-c-source-gentoo)
2329 (defvar anything-c-source-use-flags
2330 '((name . "Use Flags")
2331 (init . (lambda ()
2332 (unless anything-c-gentoo-use-flags
2333 (setq anything-c-gentoo-use-flags (anything-c-gentoo-get-use)))))
2334 (candidates . anything-c-gentoo-use-flags)
2335 (filtered-candidate-transformer . (lambda (candidates source)
2336 (anything-c-compose
2337 (list candidates)
2338 '(anything-c-highlight-local-use))))
2339 (action . (("Show which dep use this flag"
2340 . (lambda (elm)
2341 (switch-to-buffer anything-c-gentoo-buffer)
2342 (erase-buffer)
2343 (apply #'call-process "equery" nil t nil
2344 `("-C"
2345 "-q"
2347 ,elm))))
2348 ("Description"
2349 . (lambda (elm)
2350 (switch-to-buffer anything-c-gentoo-buffer)
2351 (erase-buffer)
2352 (apply #'call-process "euse" nil t nil
2353 `("-i"
2354 ,elm))
2355 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
2356 (font-lock-mode 1)))))))
2359 ;; (anything 'anything-c-source-use-flags)
2361 (defun anything-c-gentoo-init-list ()
2362 "Return a list of all packages in Portage."
2363 (let ((eix-list
2364 (split-string (with-temp-buffer
2365 (call-process "eix" nil t nil
2366 "--only-names")
2367 (buffer-string)))))
2368 eix-list))
2370 (defun anything-c-gentoo-get-use ()
2371 "Return a list of all use flags."
2372 (let ((eix-list
2373 (split-string (with-temp-buffer
2374 (call-process "eix" nil t nil
2375 "--print-all-useflags")
2376 (buffer-string)))))
2377 eix-list))
2379 (defun anything-c-gentoo-get-url (elm)
2380 "Return a list of urls from eix output."
2381 (split-string (eshell-command-result
2382 (format "eix %s | grep Homepage | awk '{print $2}'" elm))))
2384 (defun anything-c-gentoo-get-world ()
2385 "Return list of all installed package on your system."
2386 (let ((q-list
2387 (split-string (with-temp-buffer
2388 (call-process "qlist" nil t nil
2389 "-I")
2390 (buffer-string)))))
2391 q-list))
2393 (defun anything-c-gentoo-get-local-use ()
2394 (let ((use-list
2395 (split-string (with-temp-buffer
2396 (call-process "portageq" nil t nil
2397 "envvar"
2398 "USE")
2399 (buffer-string)))))
2400 use-list))
2402 (defface anything-gentoo-match-face '((t (:foreground "red")))
2403 "Face for anything-gentoo installed packages."
2404 :group 'traverse-faces)
2406 (defun anything-c-highlight-world (eix)
2407 "Highlight all installed package."
2408 (let ((cand-world (loop for i in eix
2409 if (member i anything-c-cache-world)
2410 collect (propertize i 'face 'anything-gentoo-match-face)
2411 else
2412 collect i)))
2413 cand-world))
2415 (defun anything-c-highlight-local-use (use-flags)
2416 (let* ((local-uses (anything-c-gentoo-get-local-use))
2417 (cand-use (loop for i in use-flags
2418 if (member i local-uses)
2419 collect (propertize i 'face 'anything-gentoo-match-face)
2420 else
2421 collect i)))
2422 cand-use))
2424 (defun anything-gentoo ()
2425 "Start anything with only gentoo sources."
2426 (interactive)
2427 (anything '(anything-c-source-gentoo
2428 anything-c-source-use-flags)))
2430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2431 ;;; Files
2432 (defvar anything-c-external-commands-list nil
2433 "A list of all external commands the user can execute. If this
2434 variable is not set by the user, it will be calculated
2435 automatically.")
2437 (defun anything-c-external-commands-list-1 ()
2438 "Returns a list of all external commands the user can execute.
2440 If `anything-c-external-commands-list' is non-nil it will
2441 return its contents. Else it calculates all external commands
2442 and sets `anything-c-external-commands-list'.
2444 The code is ripped out of `eshell-complete-commands-list'."
2445 (if anything-c-external-commands-list
2446 anything-c-external-commands-list
2447 (setq anything-c-external-commands-list
2448 (let* ((paths (split-string (getenv "PATH") path-separator))
2449 (cwd (file-name-as-directory
2450 (expand-file-name default-directory)))
2451 (path "") (comps-in-path ())
2452 (file "") (filepath "") (completions ()))
2453 ;; Go thru each path in the search path, finding completions.
2454 (while paths
2455 (setq path (file-name-as-directory
2456 (expand-file-name (or (car paths) ".")))
2457 comps-in-path
2458 (and (file-accessible-directory-p path)
2459 (file-name-all-completions "" path)))
2460 ;; Go thru each completion found, to see whether it should be
2461 ;; used, e.g. see if it's executable.
2462 (while comps-in-path
2463 (setq file (car comps-in-path)
2464 filepath (concat path file))
2465 (if (and (not (member file completions))
2466 (or (string-equal path cwd)
2467 (not (file-directory-p filepath)))
2468 (file-executable-p filepath))
2469 (setq completions (cons file completions)))
2470 (setq comps-in-path (cdr comps-in-path)))
2471 (setq paths (cdr paths)))
2472 completions))))
2474 (defun anything-c-file-buffers (filename)
2475 "Returns a list of those buffer names which correspond to the
2476 file given by FILENAME."
2477 (let (name ret)
2478 (dolist (buf (buffer-list) ret)
2479 (let ((bfn (buffer-file-name buf)))
2480 (when (and bfn
2481 (string= filename bfn))
2482 (push (buffer-name buf) ret)))
2483 ret)))
2485 (defun anything-c-delete-file (file)
2486 "Delete the given file after querying the user. Ask to kill
2487 buffers associated with that file, too."
2488 (if (y-or-n-p (format "Really delete file %s? " file))
2489 (progn
2490 (let ((buffers (anything-c-file-buffers file)))
2491 (delete-file file)
2492 (dolist (buf buffers)
2493 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
2494 (kill-buffer buf)))))
2495 (message "Nothing deleted.")))
2497 (defun anything-c-open-file-externally (file)
2498 "Open FILE with an external tool. Query the user which tool to
2499 use."
2500 (start-process "anything-c-open-file-externally"
2502 (completing-read "Program: "
2503 (anything-c-external-commands-list-1))
2504 file))
2506 (defun w32-shell-execute-open-file (file)
2507 (interactive "fOpen file:")
2508 (with-no-warnings
2509 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
2510 "/" "\\"
2511 (replace-regexp-in-string ; strip cygdrive paths
2512 "/cygdrive/\\(.\\)" "\\1:" file nil nil) nil t))))
2513 (defun anything-c-open-file-with-default-tool (file)
2514 "Open FILE with the default tool on this platform."
2515 (if (eq system-type 'windows-nt)
2516 (w32-shell-execute-open-file file)
2517 (start-process "anything-c-open-file-with-default-tool"
2519 (cond ((eq system-type 'gnu/linux)
2520 "xdg-open")
2521 ((or (eq system-type 'darwin) ;; Mac OS X
2522 (eq system-type 'macos)) ;; Mac OS 9
2523 "open"))
2524 file)))
2526 (defun anything-c-open-dired (file)
2527 "Opens a dired buffer in FILE's directory. If FILE is a
2528 directory, open this directory."
2529 (if (file-directory-p file)
2530 (dired file)
2531 (dired (file-name-directory file))
2532 (dired-goto-file file)))
2534 (defun anything-c-display-to-real-line (candidate)
2535 (if (string-match "^ *\\([0-9]+\\):\\(.+\\)$" candidate)
2536 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
2537 (error "Line number not found")))
2539 (defun anything-c-action-line-goto (lineno-and-content)
2540 (apply #'anything-goto-file-line (anything-attr 'target-file)
2541 (append lineno-and-content
2542 (list (if (and (anything-attr-defined 'target-file)
2543 (not anything-in-persistent-action))
2544 'find-file-other-window
2545 'find-file)))))
2547 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
2548 (apply #'anything-goto-file-line file-line-content))
2550 (require 'compile)
2551 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
2552 (mapcar
2553 (lambda (candidate)
2554 (if (not (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.+\\)$" candidate))
2555 (error "Filename and line number not found")
2556 (let ((filename (match-string 1 candidate))
2557 (lineno (match-string 2 candidate))
2558 (content (match-string 3 candidate)))
2559 (cons (format "%s:%s\n %s"
2560 (propertize filename 'face compilation-info-face)
2561 (propertize lineno 'face compilation-line-face)
2562 content)
2563 (list (expand-file-name
2564 filename
2565 (anything-aif (anything-attr 'default-directory)
2566 (if (functionp it) (funcall it) it)
2567 (and (anything-candidate-buffer)
2568 (buffer-local-value
2569 'default-directory
2570 (anything-candidate-buffer)))))
2571 (string-to-number lineno) content)))))
2572 candidates))
2574 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
2575 (anything-aif (anything-attr 'before-jump-hook)
2576 (funcall it))
2577 (when file (funcall find-file-function file))
2578 (if (anything-attr-defined 'adjust)
2579 (anything-c-goto-line-with-adjustment lineno content)
2580 (goto-line lineno))
2581 (unless (anything-attr-defined 'recenter)
2582 (set-window-start (get-buffer-window anything-current-buffer) (point)))
2583 (anything-aif (anything-attr 'after-jump-hook)
2584 (funcall it))
2585 (when anything-in-persistent-action
2586 (anything-persistent-highlight-point (point-at-bol) (point-at-eol))))
2588 ;; borrowed from etags.el
2589 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
2590 (defun anything-c-goto-line-with-adjustment (line line-content)
2591 (let ((startpos)
2592 offset found pat)
2593 ;; This constant is 1/2 the initial search window.
2594 ;; There is no sense in making it too small,
2595 ;; since just going around the loop once probably
2596 ;; costs about as much as searching 2000 chars.
2597 (setq offset 1000
2598 found nil
2599 pat (concat (if (eq selective-display t)
2600 "\\(^\\|\^m\\) *" "^ *") ;allow indent
2601 (regexp-quote line-content)))
2602 ;; If no char pos was given, try the given line number.
2603 (setq startpos (progn (goto-line line) (point)))
2604 (or startpos (setq startpos (point-min)))
2605 ;; First see if the tag is right at the specified location.
2606 (goto-char startpos)
2607 (setq found (looking-at pat))
2608 (while (and (not found)
2609 (progn
2610 (goto-char (- startpos offset))
2611 (not (bobp))))
2612 (setq found
2613 (re-search-forward pat (+ startpos offset) t)
2614 offset (* 3 offset))) ; expand search window
2615 (or found
2616 (re-search-forward pat nil t)
2617 (error "not found")))
2618 ;; Position point at the right place
2619 ;; if the search string matched an extra Ctrl-m at the beginning.
2620 (and (eq selective-display t)
2621 (looking-at "\^m")
2622 (forward-char 1))
2623 (beginning-of-line))
2625 (anything-document-attribute 'default-directory "type . file-line"
2626 "`default-directory' to interpret file.")
2627 (anything-document-attribute 'before-jump-hook "type . file-line / line"
2628 "Function to call before jumping to the target location.")
2629 (anything-document-attribute 'after-jump-hook "type . file-line / line"
2630 "Function to call after jumping to the target location.")
2631 (anything-document-attribute 'adjust "type . file-line"
2632 "Search around line matching line contents.")
2633 (anything-document-attribute 'recenter "type . file-line / line"
2634 "`recenter' after jumping.")
2635 (anything-document-attribute 'target-file "type . line"
2636 "Goto line of target-file.")
2638 (defun anything-c-call-interactively (cmd-or-name)
2639 "Execute CMD-OR-NAME as Emacs command.
2640 It is added to `extended-command-history'.
2641 `anything-current-prefix-arg' is used as the command's prefix argument."
2642 (setq extended-command-history
2643 (cons (anything-c-stringify cmd-or-name)
2644 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
2645 (let ((current-prefix-arg anything-current-prefix-arg))
2646 (call-interactively (anything-c-symbolify cmd-or-name))))
2648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2649 (defvar anything-c-persistent-highlight-overlay
2650 (make-overlay (point) (point)))
2652 (defun anything-persistent-highlight-point (start &optional end buf face rec)
2653 (goto-char start)
2654 (when (overlayp anything-c-persistent-highlight-overlay)
2655 (move-overlay anything-c-persistent-highlight-overlay
2656 start
2657 (or end (line-end-position))
2658 buf))
2659 (overlay-put anything-c-persistent-highlight-overlay 'face (or face 'highlight))
2660 (when rec
2661 (recenter)))
2663 (add-hook 'anything-cleanup-hook
2664 (lambda ()
2665 (when (overlayp anything-c-persistent-highlight-overlay)
2666 (delete-overlay anything-c-persistent-highlight-overlay))))
2668 (defvar anything-match-line-overlay-face nil)
2669 (defvar anything-match-line-overlay nil)
2670 (defun anything-match-line-color-current-line ()
2671 "Highlight and underline current position"
2672 (if (not anything-match-line-overlay)
2673 (setq anything-match-line-overlay
2674 (make-overlay
2675 (line-beginning-position) (1+ (line-end-position))))
2676 (move-overlay anything-match-line-overlay
2677 (line-beginning-position) (1+ (line-end-position))))
2678 (overlay-put anything-match-line-overlay
2679 'face anything-match-line-overlay-face))
2681 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
2682 "Face for source header in the anything buffer." :group 'anything)
2684 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
2686 (add-hook 'anything-cleanup-hook #'(lambda ()
2687 (when anything-match-line-overlay
2688 (delete-overlay anything-match-line-overlay)
2689 (setq anything-match-line-overlay nil))))
2691 (add-hook 'anything-after-persistent-action-hook #'(lambda ()
2692 (when anything-match-line-overlay
2693 (delete-overlay anything-match-line-overlay)
2694 (anything-match-line-color-current-line))))
2696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2697 ;;; Files
2698 (defun anything-c-transform-file-load-el (actions candidate)
2699 "Add action to load the file CANDIDATE if it is an emacs lisp
2700 file. Else return ACTIONS unmodified."
2701 (if (or (string= (file-name-extension candidate) "el")
2702 (string= (file-name-extension candidate) "elc"))
2703 (append actions '(("Load Emacs Lisp File" . load-file)))
2704 actions))
2706 (defun anything-c-transform-file-browse-url (actions candidate)
2707 "Add an action to browse the file CANDIDATE if it in a html
2708 file. Else return ACTIONS unmodified."
2709 (if (or (string= (file-name-extension candidate) "htm")
2710 (string= (file-name-extension candidate) "html"))
2711 (append actions '(("Browse with Browser" . browse-url)))
2712 actions))
2714 ;;;; Function
2715 (defun anything-c-transform-function-call-interactively (actions candidate)
2716 "Add an action to call the function CANDIDATE interactively if
2717 it is a command. Else return ACTIONS unmodified."
2718 (if (commandp (intern candidate))
2719 (append actions '(("Call Interactively"
2721 anything-c-call-interactively)))
2722 actions))
2724 ;;;; S-Expressions
2725 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
2726 "If CANDIDATE's `car' is a command, then add an action to
2727 evaluate it and put it onto the `command-history'."
2728 (if (commandp (car (read candidate)))
2729 ;; Make it first entry
2730 (cons '("Eval and put onto command-history" .
2731 (lambda (sexp)
2732 (let ((sym (read sexp)))
2733 (eval sym)
2734 (setq command-history
2735 (cons sym command-history)))))
2736 actions)
2737 actions))
2739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2740 ;;; Buffers
2741 (defun anything-c-skip-boring-buffers (buffers)
2742 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
2744 (defun anything-c-skip-current-buffer (buffers)
2745 (remove (buffer-name anything-current-buffer) buffers))
2747 (defun anything-c-shadow-boring-buffers (buffers)
2748 "Buffers matching `anything-c-boring-buffer-regexp' will be
2749 displayed with the `file-name-shadow' face if available."
2750 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
2752 ;;; Files
2753 (defun anything-c-shadow-boring-files (files)
2754 "Files matching `anything-c-boring-file-regexp' will be
2755 displayed with the `file-name-shadow' face if available."
2756 (anything-c-shadow-entries files anything-c-boring-file-regexp))
2758 (defun anything-c-skip-boring-files (files)
2759 "Files matching `anything-c-boring-file-regexp' will be skipped."
2760 (anything-c-skip-entries files anything-c-boring-file-regexp))
2761 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
2763 (defun anything-c-skip-current-file (files)
2764 "Current file will be skipped."
2765 (remove (buffer-file-name anything-current-buffer) files))
2767 (defun anything-c-w32-pathname-transformer (args)
2768 "Change undesirable features of windows pathnames to ones more acceptable to
2769 other candidate transformers."
2770 (if (eq system-type 'windows-nt)
2771 (mapcar (lambda (x)
2772 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
2773 (mapcar (lambda (y)
2774 (replace-regexp-in-string "\\\\" "/" y)) args))
2775 args))
2777 (defun anything-c-shorten-home-path (files)
2778 "Replaces /home/user with ~."
2779 (mapcar (lambda (file)
2780 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
2781 (getenv "HOME"))))
2782 (if (and (stringp file) (string-match home file))
2783 (cons (replace-match "~" nil nil file) file)
2784 file)))
2785 files))
2787 ;;; Functions
2788 (defun anything-c-mark-interactive-functions (functions)
2789 "Mark interactive functions (commands) with (i) after the function name."
2790 (let (list)
2791 (loop for function in functions
2792 do (push (cons (concat function
2793 (when (commandp (intern function)) " (i)"))
2794 function)
2795 list)
2796 finally (return (nreverse list)))))
2798 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2799 (defvar anything-c-adaptive-done nil
2800 "nil if history information is not yet stored for the current
2801 selection.")
2803 (defvar anything-c-adaptive-history nil
2804 "Contains the stored history information.
2805 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
2807 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
2808 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
2809 when anything is started."
2810 (setq anything-c-adaptive-done nil))
2812 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
2813 "Advise `anything-exit-minibuffer' to store history information
2814 when a candidate is selected with RET."
2815 (anything-c-adaptive-store-selection))
2817 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
2818 "Advise `anything-select-action' to store history information
2819 when the user goes to the action list with TAB."
2820 (anything-c-adaptive-store-selection))
2822 (defun anything-c-adaptive-store-selection ()
2823 "Store history information for the selected candidate."
2824 (unless anything-c-adaptive-done
2825 (setq anything-c-adaptive-done t)
2826 (let* ((source (anything-get-current-source))
2827 (source-name (or (assoc-default 'type source)
2828 (assoc-default 'name source)))
2829 (source-info (or (assoc source-name anything-c-adaptive-history)
2830 (progn
2831 (push (list source-name) anything-c-adaptive-history)
2832 (car anything-c-adaptive-history))))
2833 (selection (anything-get-selection))
2834 (selection-info (progn
2835 (setcdr source-info
2836 (cons
2837 (let ((found (assoc selection (cdr source-info))))
2838 (if (not found)
2839 ;; new entry
2840 (list selection)
2842 ;; move entry to the beginning of the
2843 ;; list, so that it doesn't get
2844 ;; trimmed when the history is
2845 ;; truncated
2846 (setcdr source-info
2847 (delete found (cdr source-info)))
2848 found))
2849 (cdr source-info)))
2850 (cadr source-info)))
2851 (pattern-info (progn
2852 (setcdr selection-info
2853 (cons
2854 (let ((found (assoc anything-pattern (cdr selection-info))))
2855 (if (not found)
2856 ;; new entry
2857 (cons anything-pattern 0)
2859 ;; move entry to the beginning of the
2860 ;; list, so if two patterns used the
2861 ;; same number of times then the one
2862 ;; used last appears first in the list
2863 (setcdr selection-info
2864 (delete found (cdr selection-info)))
2865 found))
2866 (cdr selection-info)))
2867 (cadr selection-info))))
2869 ;; increase usage count
2870 (setcdr pattern-info (1+ (cdr pattern-info)))
2872 ;; truncate history if needed
2873 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
2874 (setcdr selection-info
2875 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))
2877 (if (file-readable-p anything-c-adaptive-history-file)
2878 (load-file anything-c-adaptive-history-file))
2879 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
2881 (defun anything-c-adaptive-save-history ()
2882 "Save history information to file given by `anything-c-adaptive-history-file'."
2883 (interactive)
2884 (with-temp-buffer
2885 (insert
2886 ";; -*- mode: emacs-lisp -*-\n"
2887 ";; History entries used for anything adaptive display.\n")
2888 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
2889 (current-buffer))
2890 (insert ?\n)
2891 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
2892 (unless (interactive-p) 'quiet))))
2894 (defun anything-c-adaptive-sort (candidates source)
2895 "Sort the CANDIDATES for SOURCE by usage frequency.
2896 This is a filtered candidate transformer you can use for the
2897 attribute `filtered-candidate-transformer' of a source in
2898 `anything-sources' or a type in `anything-type-attributes'."
2899 (let* ((source-name (or (assoc-default 'type source)
2900 (assoc-default 'name source)))
2901 (source-info (assoc source-name anything-c-adaptive-history)))
2902 (if (not source-info)
2903 ;; if there is no information stored for this source then do nothing
2904 candidates
2905 ;; else...
2906 (let ((usage
2907 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
2908 ;; pairs
2909 (mapcar (lambda (candidate-info)
2910 (let ((count 0))
2911 (dolist (pattern-info (cdr candidate-info))
2912 (if (not (equal (car pattern-info)
2913 anything-pattern))
2914 (incf count (cdr pattern-info))
2916 ;; if current pattern is equal to the previously
2917 ;; used one then this candidate has priority
2918 ;; (that's why its count is boosted by 10000) and
2919 ;; it only has to compete with other candidates
2920 ;; which were also selected with the same pattern
2921 (setq count (+ 10000 (cdr pattern-info)))
2922 (return)))
2923 (cons (car candidate-info) count)))
2924 (cdr source-info)))
2925 sorted)
2927 ;; sort the list in descending order, so candidates with highest
2928 ;; priorty come first
2929 (setq usage (sort usage (lambda (first second)
2930 (> (cdr first) (cdr second)))))
2932 ;; put those candidates first which have the highest usage count
2933 (dolist (info usage)
2934 (when (member* (car info) candidates
2935 :test 'anything-c-adaptive-compare)
2936 (push (car info) sorted)
2937 (setq candidates (remove* (car info) candidates
2938 :test 'anything-c-adaptive-compare))))
2940 ;; and append the rest
2941 (append (reverse sorted) candidates nil)))))
2943 (defun anything-c-adaptive-compare (x y)
2944 "Compare candidates X and Y taking into account that the
2945 candidate can be in (DISPLAY . REAL) format."
2946 (equal (if (listp x)
2947 (cdr x)
2949 (if (listp y)
2950 (cdr y)
2951 y)))
2953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2954 ;; Plug-in: candidates-file
2955 (defun anything-compile-source--candidates-file (source)
2956 (if (assoc-default 'candidates-file source)
2957 `((init anything-p-candidats-file-init
2958 ,@(let ((orig-init (assoc-default 'init source)))
2959 (cond ((null orig-init) nil)
2960 ((functionp orig-init) (list orig-init))
2961 (t orig-init))))
2962 (candidates-in-buffer)
2963 ,@source)
2964 source))
2965 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
2967 (defun anything-p-candidats-file-init ()
2968 (destructuring-bind (file &optional updating)
2969 (anything-mklist (anything-attr 'candidates-file))
2970 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
2971 (when updating
2972 (buffer-disable-undo)
2973 (font-lock-mode -1)
2974 (auto-revert-mode 1)))))
2976 (anything-document-attribute 'candidates-file "candidates-file plugin"
2977 "Use a file as the candidates buffer.
2979 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
2981 ;; Plug-in: headline
2982 (defun anything-compile-source--anything-headline (source)
2983 (if (assoc-default 'headline source)
2984 (append '((init . anything-headline-init)
2985 (get-line-fn . buffer-substring)
2986 (type . line))
2987 source
2988 '((candidates-in-buffer)))
2989 source))
2990 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
2992 (defun anything-headline-init ()
2993 (when (and (anything-current-buffer-is-modified)
2994 (with-current-buffer anything-current-buffer
2995 (eval (or (anything-attr 'condition) t))))
2996 (anything-headline-make-candidate-buffer
2997 (anything-attr 'headline)
2998 (anything-attr 'subexp))))
3000 (anything-document-attribute 'headline "Headline plug-in"
3001 "Regexp string for anything-headline to scan.")
3002 (anything-document-attribute 'condition "Headline plug-in"
3003 "A sexp representing the condition to use anything-headline.")
3004 (anything-document-attribute 'subexp "Headline plug-in"
3005 "Display (match-string-no-properties subexp).")
3007 (defun anything-headline-get-candidates (regexp subexp)
3008 (save-excursion
3009 (set-buffer anything-current-buffer)
3010 (save-excursion
3011 (goto-char (point-min))
3012 (if (functionp regexp) (setq regexp (funcall regexp)))
3013 (let (hierarchy curhead)
3014 (flet ((matched ()
3015 (if (numberp subexp)
3016 (cons (match-string-no-properties subexp) (match-beginning subexp))
3017 (cons (buffer-substring (point-at-bol) (point-at-eol))
3018 (point-at-bol))))
3019 (hierarchies (headlines)
3020 (1+ (loop for (_ . hierarchy) in headlines
3021 maximize hierarchy)))
3022 (vector-0-n (v n)
3023 (loop for i from 0 to hierarchy
3024 collecting (aref curhead i)))
3025 (arrange (headlines)
3026 (loop with curhead = (make-vector (hierarchies headlines) "")
3027 for ((str . pt) . hierarchy) in headlines
3028 do (aset curhead hierarchy str)
3029 collecting
3030 (cons
3031 (mapconcat 'identity (vector-0-n curhead hierarchy) " / ")
3032 pt))))
3033 (if (listp regexp)
3034 (arrange
3035 (sort
3036 (loop for re in regexp
3037 for hierarchy from 0
3038 do (goto-char (point-min))
3039 appending
3040 (loop
3041 while (re-search-forward re nil t)
3042 collect (cons (matched) hierarchy)))
3043 (lambda (a b) (> (cdar b) (cdar a)))))
3044 (loop while (re-search-forward regexp nil t)
3045 collect (matched))))))))
3047 (defun anything-headline-make-candidate-buffer (regexp subexp)
3048 (with-current-buffer (anything-candidate-buffer 'local)
3049 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
3050 do (insert
3051 (format "%5d:%s\n"
3052 (with-current-buffer anything-current-buffer
3053 (line-number-at-pos pos))
3054 content)))))
3056 (defun anything-headline-goto-position (pos recenter)
3057 (goto-char pos)
3058 (unless recenter
3059 (set-window-start (get-buffer-window anything-current-buffer) (point))))
3062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3064 ;;; Type Attributes
3065 (setq anything-type-attributes
3066 `((buffer
3067 (action
3068 ,@(if pop-up-frames
3069 '(("Switch to buffer other window" . switch-to-buffer-other-window)
3070 ("Switch to buffer" . switch-to-buffer))
3071 '(("Switch to buffer" . switch-to-buffer)
3072 ("Switch to buffer other window" . switch-to-buffer-other-window)
3073 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
3074 ("Display buffer" . display-buffer)
3075 ("Revert buffer" . (lambda (elm)
3076 (with-current-buffer elm
3077 (when (buffer-modified-p)
3078 (revert-buffer t t)))))
3079 ("Kill buffer" . kill-buffer))
3080 (candidate-transformer . anything-c-skip-boring-buffers))
3081 (file
3082 (action
3083 ,@(if pop-up-frames
3084 '(("Find file other window" . find-file-other-window)
3085 ("Find file" . find-file))
3086 '(("Find file" . find-file)
3087 ("Find file other window" . find-file-other-window)
3088 ("Find file other frame" . find-file-other-frame)))
3089 ("Open dired in file's directory" . anything-c-open-dired)
3090 ("Delete file" . anything-c-delete-file)
3091 ("Open file externally" . anything-c-open-file-externally)
3092 ("Open file with default tool" . anything-c-open-file-with-default-tool))
3093 (action-transformer . (lambda (actions candidate)
3094 (anything-c-compose
3095 (list actions candidate)
3096 '(anything-c-transform-file-load-el
3097 anything-c-transform-file-browse-url))))
3098 (candidate-transformer . (lambda (candidates)
3099 (anything-c-compose
3100 (list candidates)
3101 '(anything-c-w32-pathname-transformer
3102 anything-c-skip-current-file
3103 anything-c-skip-boring-files
3104 anything-c-shorten-home-path)))))
3105 (command (action ("Call interactively" . anything-c-call-interactively)
3106 ("Describe command" . (lambda (command-name)
3107 (describe-function (intern command-name))))
3108 ("Add command to kill ring" . kill-new)
3109 ("Go to command's definition" . (lambda (command-name)
3110 (find-function
3111 (intern command-name)))))
3112 ;; Sort commands according to their usage count.
3113 (filtered-candidate-transformer . anything-c-adaptive-sort))
3114 (function (action ("Describe function" . (lambda (function-name)
3115 (describe-function (intern function-name))))
3116 ("Add function to kill ring" . kill-new)
3117 ("Go to function's definition" . (lambda (function-name)
3118 (find-function
3119 (intern function-name)))))
3120 (action-transformer . (lambda (actions candidate)
3121 (anything-c-compose
3122 (list actions candidate)
3123 '(anything-c-transform-function-call-interactively))))
3124 (candidate-transformer . (lambda (candidates)
3125 (anything-c-compose
3126 (list candidates)
3127 '(anything-c-mark-interactive-functions)))))
3128 (sexp (action ("Eval s-expression" . (lambda (c)
3129 (eval (read c))))
3130 ("Add s-expression to kill ring" . kill-new))
3131 (action-transformer . (lambda (actions candidate)
3132 (anything-c-compose
3133 (list actions candidate)
3134 '(anything-c-transform-sexp-eval-command-sexp)))))
3135 ;; (bookmark (action ("Jump to bookmark" . bookmark-jump)
3136 ;; ("Delete bookmark" . bookmark-delete)))
3137 (bookmark (action ("Jump to bookmark" . (lambda (candidate)
3138 (bookmark-jump candidate)
3139 (anything-update)))
3140 ("Delete bookmark" . bookmark-delete)
3141 ("Rename bookmark" . bookmark-rename)
3142 ("Relocate bookmark" . bookmark-relocate)))
3143 (line (display-to-real . anything-c-display-to-real-line)
3144 (action ("Go to Line" . anything-c-action-line-goto)))))
3146 ;;;; unit test
3147 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
3148 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
3149 (dont-compile
3150 (when (fboundp 'expectations)
3151 (expectations
3152 (desc "candidates-file plug-in")
3153 (expect '(anything-p-candidats-file-init)
3154 (assoc-default 'init
3155 (car (anything-compile-sources
3156 '(((name . "test")
3157 (candidates-file . "test.txt")))
3158 '(anything-compile-source--candidates-file)))))
3159 (expect '(anything-p-candidats-file-init
3160 (lambda () 1))
3161 (assoc-default 'init
3162 (car (anything-compile-sources
3163 '(((name . "test")
3164 (candidates-file . "test.txt")
3165 (init . (lambda () 1))))
3166 '(anything-compile-source--candidates-file)))))
3167 (expect '(anything-p-candidats-file-init
3168 (lambda () 1))
3169 (assoc-default 'init
3170 (car (anything-compile-sources
3171 '(((name . "test")
3172 (candidates-file . "test.txt")
3173 (init (lambda () 1))))
3174 '(anything-compile-source--candidates-file)))))
3175 (desc "anything-c-source-buffers")
3176 (expect '(("Buffers" ("foo" "curbuf")))
3177 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
3178 (let ((anything-c-boring-buffer-regexp
3179 (rx (or
3180 (group bos " ")
3181 "*anything"
3182 ;; echo area
3183 " *Echo Area" " *Minibuf"))))
3184 (flet ((buffer-name (x) x))
3185 (anything-test-candidates 'anything-c-source-buffers))))
3186 (desc "anything-c-stringify")
3187 (expect "str1"
3188 (anything-c-stringify "str1"))
3189 (expect "str2"
3190 (anything-c-stringify 'str2))
3191 (desc "anything-c-symbolify")
3192 (expect 'sym1
3193 (anything-c-symbolify "sym1"))
3194 (expect 'sym2
3195 (anything-c-symbolify 'sym2)))))
3198 (provide 'anything-config)
3200 ;;; Local Variables:
3201 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
3202 ;;; End:
3204 ;; How to save (DO NOT REMOVE!!)
3205 ;; (emacswiki-post "anything-config.el")
3206 ;;; anything-config.el ends here
3208 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
3209 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
3210 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
3211 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
3212 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
3213 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
3214 ;;; LocalWords: dotimes Thierry online vname
3215 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
3216 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
3217 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
3218 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
3219 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
3220 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
3221 ;;; LocalWords: startpos noselect dont desc