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
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:
27 ;;; This file is NOT part of GNU Emacs
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)
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.
48 ;; If this file does not work, upgrade anything.el!
49 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
53 ;; Predefined configurations for `anything.el'
55 ;; For quick start, try `anything-for-files' to open files.
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
71 ;; Below are complete source list you can setup in `anything-sources':
74 ;; `anything-c-source-buffers' (Buffers)
75 ;; `anything-c-source-buffer-not-found' (Create buffer)
76 ;; `anything-c-source-buffers+' (Buffers)
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)
86 ;; `anything-c-source-man-pages' (Manual Pages)
87 ;; `anything-c-source-info-pages' (Info Pages)
88 ;; `anything-c-source-info-elisp' (Info Elisp)
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)
95 ;; `anything-c-source-emacs-functions' (Emacs Functions)
96 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
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)
105 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
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)
114 ;; `anything-c-source-customize-face' (Customize Face)
115 ;; `anything-c-source-colors' (Colors)
117 ;; `anything-c-source-tracker-search' (Tracker Search)
118 ;; `anything-c-source-mac-spotlight' (mdfind)
120 ;; `anything-c-source-kill-ring' (Kill Ring)
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)
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)
143 ;; `anything-c-source-gentoo' (Portage sources)
144 ;; `anything-c-source-use-flags' (Use Flags)
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'
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.
195 ;; Do many create actions from STRING.
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)
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.
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'.
229 ;; `anything-create--actions-private'
230 ;; User defined actions for `anything-create' / `anything-c-source-create'.
235 ;; Change log of this file is found at
236 ;; http://repo.or.cz/w/anything-config.git?a=shortlog;h=b30091a6bb64828eb3d70007db5b68d51b868bcc
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>
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
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.
284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
285 (defgroup anything-config nil
286 "Predefined configurations for `anything.el'."
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'. "
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."
306 :group
'anything-config
)
308 (defcustom anything-c-adaptive-history-length
50
309 "Maximum number of candidates stored for a source."
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."
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."
323 :group
'anything-config
)
325 (defcustom anything-c-boring-buffer-regexp
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."
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
346 ;; Boring directories
347 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
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."
358 :group
'anything-config
)
360 (defcustom anything-kill-ring-threshold
10
361 "*Minimum length to be listed by `anything-c-source-kill-ring'."
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"
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."
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
)
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."
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."
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."
408 (anything-insert-string
409 (with-current-buffer anything-current-buffer
410 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
413 (defun anything-insert-symbol ()
414 "Insert current symbol."
416 (anything-insert-string
417 (with-current-buffer anything-current-buffer
419 (buffer-substring (beginning-of-thing 'symbol
)
420 (end-of-thing 'symbol
))))))
422 (defun anything-insert-selection ()
423 "Insert current selection."
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."
432 (anything-set-source-filter '("Buffers")))
434 (defun anything-show-bbdb-only ()
435 "Only show sources about BBDB."
437 (anything-set-source-filter '("BBDB")))
439 (defun anything-show-locate-only ()
440 "Only show sources about Locate."
442 (anything-set-source-filter '("Locate")))
444 (defun anything-show-info-only ()
445 "Only show sources about Info."
447 (anything-set-source-filter '("Info Pages"
449 "Info Common-Lisp")))
451 (defun anything-show-imenu-only ()
452 "Only show sources about Imenu."
454 (anything-set-source-filter '("Imenu")))
456 (defun anything-show-files-only ()
457 "Only show sources about File."
459 (anything-set-source-filter '("File Name History"
460 "Files from Current Directory"
463 (defun anything-show-w3m-bookmarks-only ()
464 "Only show source about w3m bookmark."
466 (anything-set-source-filter '("W3m Bookmarks")))
468 (defun anything-show-colors-only ()
469 "Only show source about color."
471 (anything-set-source-filter '("Colors"
474 (defun anything-show-kill-ring-only ()
475 "Only show source about kill ring."
477 (anything-set-source-filter '("Kill Ring")))
479 (defun anything-show-this-source-only ()
480 "Only show this source."
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]."
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
)
505 anything-compiled-sources
506 anything-buffer-chars-modified-tick
507 (anything-samewindow t
)
508 (enable-recursive-minibuffers t
))
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))
519 while
(setq pos
(next-single-property-change (point) 'anything-header
))
521 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
522 do
(forward-line 1))))
524 (defun anything-select-source ()
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)
533 (let (anything-source-filter)
534 (anything-nest '(((name .
"Anything Source")
535 (candidates . source-names
)
537 ((name .
"Anything Source (ALL)")
538 (candidates . all-source-names
)
539 (action . identity
)))
541 default
"*anything select source*"))
542 (anything-set-source-filter (list it
))
543 (anything-set-source-filter nil
))))
545 (defun anything-insert-string (str)
547 (delete-minibuffer-contents)
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
)))
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
)))
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
)))
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
)
585 ;; fall back to default on XEmacs
587 (if (string-match regexp file
)
588 (setq file
(propertize file
'face face
))))
592 (defsubst anything-c-stringify
(str-or-sym)
593 "Get string of STR-OR-SYM."
594 (if (stringp 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
)
602 (intern str-or-sym
)))
604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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."
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))
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."
634 (goto-char (point-min))
635 (search-forward ";; Below are complete source list you can setup in")
637 (delete-region (point)
638 (progn (search-forward ";;; Change log:" nil t
)
639 (forward-line -
1) (point)))
642 for
(kind . value
) in
(anything-c-create-summary)
644 do
(cond ((eq kind
'section
)
646 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
647 (insert ";; " value
":\n")
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
666 (candidates . anything-c-buffer-list
)
669 ;; (anything 'anything-c-source-buffers)
671 (defvar anything-c-source-buffer-not-found
672 '((name .
"Create buffer")
675 ;; (anything 'anything-c-source-buffer-not-found)
678 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
679 "*Face used for directory headings in dired buffers."
682 (defface anything-file-name
683 '((t (:foreground
"Blue")))
684 "*Face used for file names (without suffixes) in dired buffers."
687 (defface anything-dir-priv
688 '((t (:foreground
"DarkRed" :background
"LightGray")))
689 "*Face used for directory privilege indicator (d) in dired buffers."
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
))))
711 (defvar anything-c-source-buffers
+
713 (candidates . anything-c-buffer-list
)
716 (candidate-transformer .
(lambda (candidates)
719 '(anything-c-highlight-buffers
720 anything-c-skip-boring-buffers
))))
721 (persistent-action .
(lambda (name)
723 (with-current-buffer item
724 (if (and (buffer-modified-p)
725 (buffer-file-name (current-buffer)))
729 (kill-buffer item
))))
731 (switch-to-buffer item
)))
732 (if current-prefix-arg
735 (anything-delete-current-selection))
738 ;; (anything 'anything-c-source-buffers+)
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
))
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")
755 (setq anything-c-default-directory
757 (candidates .
(lambda ()
759 anything-c-default-directory
)))
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
))
773 collect
(propertize (file-name-nondirectory i
)
774 'face anything-c-files-face2
775 'help-echo
(expand-file-name i
)))))
779 (defvar anything-c-source-files-in-current-dir
+
780 '((name .
"Files from Current Directory")
782 (setq anything-c-default-directory
783 (expand-file-name default-directory
))))
784 (candidates .
(lambda ()
786 anything-c-default-directory t
)))
787 (candidate-transformer .
(lambda (candidates)
790 '(anything-c-highlight-files))))
794 ;; (anything 'anything-c-source-files-in-current-dir+)
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")
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
))
818 ;; (anything 'anything-c-source-file-cache)
821 (defvar anything-c-locate-options
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
832 (candidates .
(lambda ()
833 (apply 'start-process
"locate-process" nil
834 (append anything-c-locate-options
835 (list anything-pattern
)))))
837 (requires-pattern .
3)
839 "Source for retrieving files matching the current input pattern with locate.")
840 ;; (anything 'anything-c-source-locate)
843 (defvar anything-c-source-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
))
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)
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
867 (if guess
(list guess
)))))
869 ;; (anything 'anything-c-source-ffap-guesser)
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
878 (defvar anything-c-source-man-pages
879 `((name .
"Manual Pages")
880 (candidates .
(lambda ()
881 (if anything-c-man-pages
883 ;; XEmacs doesn't have a woman :)
884 (setq anything-c-man-pages
890 woman-topic-all-completions
)
893 (action .
(("Show with Woman" . woman
)))
894 (requires-pattern .
2)))
895 ;; (anything 'anything-c-source-man-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
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
912 (Info-find-node "dir" "top")
913 (goto-char (point-min))
914 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
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))
921 (action .
(("Show with Info" .
(lambda (node-str)
922 (info (replace-regexp-in-string "^[^:]+: "
925 (requires-pattern .
2)))
926 ;; (anything 'anything-c-source-info-pages)
929 (defvar anything-c-info-elisp nil
)
930 (defvar anything-c-source-info-elisp
931 `((name .
"Info Elisp")
933 (save-window-excursion
934 (unless anything-c-info-elisp
936 (Info-find-node "elisp" "Index")
937 (setq anything-c-info-elisp
(split-string (buffer-string) "\n"))
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
))))
947 (requires-pattern .
2)))
948 ;; (anything 'anything-c-source-info-elisp)
951 (defvar anything-c-info-cl-fn nil
)
952 (defvar anything-c-source-info-cl
953 `((name .
"Info Common-Lisp")
955 (save-window-excursion
956 (unless anything-c-info-cl-fn
958 (Info-find-node "cl" "Function Index")
959 (setq anything-c-info-cl-fn
(split-string (buffer-string) "\n"))
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
)
974 (requires-pattern .
2)))
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
985 ;; (anything 'anything-c-source-complex-command-history)
988 (defvar anything-c-source-extended-command-history
989 '((name .
"Emacs Commands History")
990 (candidates . extended-command-history
)
992 ;; (anything 'anything-c-source-extended-command-history)
995 (defvar anything-c-source-emacs-commands
996 '((name .
"Emacs Commands")
997 (candidates .
(lambda ()
999 (mapatoms (lambda (a)
1001 (push (symbol-name a
)
1003 (sort commands
'string-lessp
))))
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)
1016 (defvar anything-c-source-lacarte
1017 '((name .
"Lacarte")
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
))
1026 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
1027 ;; (anything 'anything-c-source-lacarte)
1031 (defvar anything-c-source-emacs-functions
1032 '((name .
"Emacs Functions")
1033 (candidates .
(lambda ()
1035 (mapatoms (lambda (a)
1037 (push (symbol-name a
)
1039 (sort commands
'string-lessp
))))
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
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
))
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)
1080 (defvar anything-c-source-bookmarks
1081 '((name .
"Bookmarks")
1083 (require 'bookmark
)))
1084 (candidates . bookmark-all-names
)
1086 "See (info \"(emacs)Bookmarks\").")
1087 ;; (anything 'anything-c-source-bookmarks)
1090 (defvar anything-c-source-bookmark-set
1091 '((name .
"Set Bookmark")
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
1103 (defvar anything-c-source-bm
1104 '((name .
"Visible Bookmarks")
1105 (init . anything-c-source-bm-init
)
1106 (candidates-in-buffer)
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
)
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
)
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")
1134 (require 'bookmark
)))
1135 (candidates .
(lambda ()
1138 (setq lis-all
(bookmark-all-names))
1139 (setq lis-ssh
(loop for i in lis-all
1140 if
(string-match "^(ssh)" i
)
1142 (sort lis-ssh
'string-lessp
))))
1144 "See (info \"(emacs)Bookmarks\").")
1145 ;; (anything 'anything-c-source-bookmarks-ssh)
1147 (defvar anything-c-source-bookmarks-su
1148 '((name .
"Bookmarks-su")
1150 (require 'bookmark
)))
1151 (candidates .
(lambda ()
1154 (setq lis-all
(bookmark-all-names))
1155 (setq lis-su
(loop for i in lis-all
1156 if
(string-match "^(su)" i
)
1158 (sort lis-su
'string-lessp
))))
1159 (candidate-transformer .
(lambda (candidates)
1162 '(anything-c-highlight-bookmark-su))))
1165 "See (info \"(emacs)Bookmarks\").")
1166 ;; (anything 'anything-c-source-bookmarks-su)
1168 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
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 ()
1178 (dolist (i (mapcar #'buffer-name
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
))))
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
)
1201 collect
(propertize i
1202 'face anything-c-bookmarks-face2
))))
1205 (defvar anything-c-source-bookmarks-local
1206 '((name .
"Bookmarks-Local")
1208 (require 'bookmark
)))
1209 (candidates .
(lambda ()
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
)))
1217 (sort lis-loc
'string-lessp
))))
1218 (candidate-transformer .
(lambda (candidates)
1221 '(anything-c-highlight-bookmark))))
1223 "See (info \"(emacs)Bookmarks\").")
1224 ;; (anything 'anything-c-source-bookmarks-local)
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)
1242 (insert-file-contents w3m-bookmark-file
) ;; or w3m-bookmark-file
1243 (goto-char (point-min))
1246 (when (re-search-forward "href=" nil t
)
1248 (when (re-search-forward "http://[^>]*" nil t
)
1249 (setq url
(concat "\"" (match-string 0))))
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")
1260 (setq anything-c-w3m-bookmarks-alist
1261 (anything-w3m-bookmarks-to-alist))))
1262 (candidates .
(lambda ()
1264 anything-c-w3m-bookmarks-alist
)))
1265 (filtered-candidate-transformer .
(lambda (candidates source
)
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
))))
1285 ;; (anything 'anything-c-source-w3m-bookmarks)
1287 (defun anything-c-w3m-bookmarks-get-value (elm)
1289 (replace-regexp-in-string "\"" ""
1291 anything-c-w3m-bookmarks-alist
)))))
1294 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
1295 (let* ((fn (if use-firefox
1298 (arg (if (and (eq fn
'w3m-browse-url
)
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
)))))
1313 (defun anything-c-w3m-delete-bookmark (elm)
1315 (find-file-literally w3m-bookmark-file
)
1316 (goto-char (point-min))
1317 (when (re-search-forward elm nil t
)
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
)))
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
))
1335 (save-buffer (current-buffer))
1336 (kill-buffer (current-buffer)))))
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
)))
1376 (setq dir default-directory
))
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
)))))
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
))
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
)))))
1419 (defvar anything-c-source-imenu
1422 (setq anything-c-imenu-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
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
)
1441 (setq anything-c-cached-imenu-candidates
1442 (mapcar #'(lambda (x)
1446 anything-c-cached-imenu-candidates
)))))))
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)
1465 (setq alist
(assoc (car path
) alist
))
1466 (setq elm
(cadr path
))
1467 (imenu (assoc elm alist
)))
1468 (imenu (assoc elm alist
)))))
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))
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
)))
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")
1502 . anything-c-source-ctags-init
)
1503 (candidates-in-buffer)
1506 "Needs Exuberant Ctags.
1508 http://ctags.sourceforge.net/")
1509 ;; (anything 'anything-c-source-ctags)
1512 (defun anything-semantic-construct-candidates (tags depth
)
1513 (when (require 'semantic nil t
)
1514 (apply 'append
(mapcar (lambda (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
)
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")
1535 (setq anything-semantic-candidates
1537 (anything-semantic-construct-candidates (semantic-fetch-tags) 0)
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")
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
"")
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)
1578 (defvar anything-c-source-simple-call-tree-callers-functions
1579 '((name .
"Function calls")
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
"")
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")
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
)
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
)
1625 (loop for
(command . doc
) in commands
1626 for cmdname
= (symbol-name command
)
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
)
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
))
1642 anything-c-auto-document-data
))
1644 ;; (anything 'anything-c-source-commands-and-options-in-file)
1646 ;;;; <Color and Face>
1648 (defvar anything-c-source-customize-face
1649 '((name .
"Customize Face")
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)
1663 (defvar anything-c-source-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)
1685 (replace-regexp-in-string
1688 (insert (capitalize candidate
))
1689 (goto-char (point-min))
1690 (search-forward-regexp "\\s-\\{2,\\}")
1694 (defun anything-c-colors-get-rgb (candidate)
1696 (replace-regexp-in-string
1699 (insert (capitalize candidate
))
1700 (goto-char (point-max))
1701 (search-backward-regexp "\\s-\\{2,\\}")
1702 (kill-region (point) (point-min))
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
1714 (requires-pattern .
3)
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
1723 (candidates .
(lambda ()
1724 (start-process "mdfind-process" nil
1725 "mdfind" anything-pattern
)))
1727 (requires-pattern .
3)
1729 "Source for retrieving files via Spotlight's command line
1731 ;; (anything 'anything-c-source-mac-spotlight)
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
))
1743 (action . anything-c-kill-ring-action
)
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
)
1756 (let ((inhibit-read-only t
)
1757 (before (< (point) (mark t
))))
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,
1766 (set-window-start (selected-window) yank-window-start t
)
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)))))))
1775 ;; (anything 'anything-c-source-kill-ring)
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
)
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
1793 (list (int-to-string val
)
1795 'increment-register
))
1797 (let ((buf (marker-buffer val
)))
1799 (list "a marker in no buffer")
1801 "a buffer position:"
1804 (int-to-string (marker-position val
)))
1806 'insert-register
))))
1807 ((and (consp val
) (window-configuration-p (car val
)))
1808 (list "window configuration."
1810 ((and (consp val
) (frame-configuration-p (car val
)))
1811 (list "frame configuration."
1813 ((and (consp val
) (eq (car val
) 'file
))
1814 (list (concat "file:"
1815 (prin1-to-string (cdr val
))
1818 ((and (consp val
) (eq (car val
) 'file-query
))
1819 (list (concat "file:a file-query reference: file "
1822 (int-to-string (car (cdr (cdr 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)))
1834 (list ;; without properties
1835 (substring-no-properties val
)
1838 'prepend-to-register
))
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."
1849 (lambda (c) (insert-register (car c
))))
1851 "Jump to Register" .
1852 (lambda (c) (jump-to-register (car c
))))
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))))
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
)
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\\)\\>.*$")
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
)))
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
)))
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
))
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")
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
))
1941 (persistent-action .
(lambda (elm)
1942 (anything-c-action-line-goto elm
)
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)
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)
1965 (defvar anything-c-source-picklist
1966 '((name .
"Picklist")
1967 (candidates .
(lambda ()
1968 (mapcar 'car picklist-list
)))
1971 ;; (anything 'anything-c-source-picklist)
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
1980 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
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
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: ")))))
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
2009 (candidates . anything-c-bbdb-candidates
)
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*")
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")
2028 (match (lambda (candidate) t
))
2029 (candidates "dummy")
2030 (filtered-candidate-transformer .
(lambda (candidates source
)
2034 (eval (read anything-pattern
)))
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")
2044 (match (lambda (candidate) t
))
2045 (candidates "dummy")
2046 (filtered-candidate-transformer .
(lambda (candidates source
)
2049 (calc-eval anything-pattern
)
2052 (action ("Copy result to kill-ring" .
(lambda (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
))
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
"'"
2072 (action .
(("Google Search" .
2074 (browse-url (concat anything-c-google-suggest-search-url
2075 (url-hexify-string candidate
)))))))
2077 (requires-pattern .
3)
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
)))
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
2112 (defun anything-c-google-suggest-get-items (str)
2113 "Extract items from STR returned by Google Suggest."
2116 (while (string-match "\"\\([^\"]+?\\)\"" str start
)
2117 (push (match-string 1 str
) items
)
2118 (setq start
(1+ (match-end 1))))
2121 ;;; Jabber Contacts (jabber.el)
2122 (defun anything-c-jabber-online-contacts ()
2123 "List online Jabber contacts."
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 ()
2138 (anything-c-jabber-online-contacts))))
2139 (action .
(lambda (x)
2141 (jabber-read-account)
2143 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
2144 ;; (anything 'anything-c-source-jabber-contacts)
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" .
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."
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."
2175 (setq anything-input-idle-delay
0)
2176 (anything-set-sources '(anything-c-source-call-source)))
2179 (defvar anything-c-source-occur
2182 (setq anything-c-source-occur-current-buffer
2184 (candidates .
(lambda ()
2185 (setq anything-occur-buf
(get-buffer-create "*Anything Occur*"))
2186 (with-current-buffer anything-occur-buf
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
)))))
2195 (let ((lines (split-string (buffer-string) "\n" t
)))
2197 (action .
(("Goto line" .
(lambda (candidate)
2198 (goto-line (string-to-number candidate
) anything-c-source-occur-current-buffer
)))))
2199 (requires-pattern .
1)
2201 ;; (anything 'anything-c-source-occur)
2203 ;; Create many actions for input
2204 (defvar anything-c-source-create
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."
2220 :group
'anything-config
)
2222 (defun anything-create-from-anything ()
2223 "Run `anything-create' from `anything' as a fallback."
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'."
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'."
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
)
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
)
2264 ;; (anything 'anything-c-source-minibuffer-history)
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")
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
)
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
)
2304 (apply #'call-process
"equery" nil t nil
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
)
2318 (apply #'call-process
"equery" nil t nil
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")
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
)
2338 '(anything-c-highlight-local-use))))
2339 (action .
(("Show which dep use this flag"
2341 (switch-to-buffer anything-c-gentoo-buffer
)
2343 (apply #'call-process
"equery" nil t nil
2350 (switch-to-buffer anything-c-gentoo-buffer
)
2352 (apply #'call-process
"euse" nil t nil
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."
2364 (split-string (with-temp-buffer
2365 (call-process "eix" nil t nil
2370 (defun anything-c-gentoo-get-use ()
2371 "Return a list of all use flags."
2373 (split-string (with-temp-buffer
2374 (call-process "eix" nil t nil
2375 "--print-all-useflags")
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."
2387 (split-string (with-temp-buffer
2388 (call-process "qlist" nil t nil
2393 (defun anything-c-gentoo-get-local-use ()
2395 (split-string (with-temp-buffer
2396 (call-process "portageq" nil t nil
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
)
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
)
2424 (defun anything-gentoo ()
2425 "Start anything with only gentoo sources."
2427 (anything '(anything-c-source-gentoo
2428 anything-c-source-use-flags
)))
2430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
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.
2455 (setq path
(file-name-as-directory
2456 (expand-file-name (or (car paths
) ".")))
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
)))
2474 (defun anything-c-file-buffers (filename)
2475 "Returns a list of those buffer names which correspond to the
2476 file given by FILENAME."
2478 (dolist (buf (buffer-list) ret
)
2479 (let ((bfn (buffer-file-name buf
)))
2481 (string= filename bfn
))
2482 (push (buffer-name buf
) 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
))
2490 (let ((buffers (anything-c-file-buffers 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
2500 (start-process "anything-c-open-file-externally"
2502 (completing-read "Program: "
2503 (anything-c-external-commands-list-1))
2506 (defun w32-shell-execute-open-file (file)
2507 (interactive "fOpen file:")
2509 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
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
)
2521 ((or (eq system-type
'darwin
) ;; Mac OS X
2522 (eq system-type
'macos
)) ;; Mac OS 9
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
)
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
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
))
2551 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
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
)
2563 (list (expand-file-name
2565 (anything-aif (anything-attr 'default-directory
)
2566 (if (functionp it
) (funcall it
) it
)
2567 (and (anything-candidate-buffer)
2570 (anything-candidate-buffer)))))
2571 (string-to-number lineno
) content
)))))
2574 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
2575 (anything-aif (anything-attr 'before-jump-hook
)
2577 (when file
(funcall find-file-function file
))
2578 (if (anything-attr-defined 'adjust
)
2579 (anything-c-goto-line-with-adjustment lineno content
)
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
)
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
)
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.
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
)
2610 (goto-char (- startpos offset
))
2613 (re-search-forward pat
(+ startpos offset
) t
)
2614 offset
(* 3 offset
))) ; expand search window
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
)
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
)
2654 (when (overlayp anything-c-persistent-highlight-overlay
)
2655 (move-overlay anything-c-persistent-highlight-overlay
2657 (or end
(line-end-position))
2659 (overlay-put anything-c-persistent-highlight-overlay
'face
(or face
'highlight
))
2663 (add-hook 'anything-cleanup-hook
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
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
)))
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
)))
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
)))
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" .
2732 (let ((sym (read sexp
)))
2734 (setq command-history
2735 (cons sym command-history
)))))
2739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
))
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
)
2772 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
2774 (replace-regexp-in-string "\\\\" "/" y
)) 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...
2782 (if (and (stringp file
) (string-match home file
))
2783 (cons (replace-match "~" nil nil file
) file
)
2788 (defun anything-c-mark-interactive-functions (functions)
2789 "Mark interactive functions (commands) with (i) after the function name."
2791 (loop for function in functions
2792 do
(push (cons (concat function
2793 (when (commandp (intern function
)) " (i)"))
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
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
)
2831 (push (list source-name
) anything-c-adaptive-history
)
2832 (car anything-c-adaptive-history
))))
2833 (selection (anything-get-selection))
2834 (selection-info (progn
2837 (let ((found (assoc selection
(cdr source-info
))))
2842 ;; move entry to the beginning of the
2843 ;; list, so that it doesn't get
2844 ;; trimmed when the history is
2847 (delete found
(cdr source-info
)))
2850 (cadr source-info
)))
2851 (pattern-info (progn
2852 (setcdr selection-info
2854 (let ((found (assoc anything-pattern
(cdr selection-info
))))
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
)))
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'."
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
)
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
2907 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
2909 (mapcar (lambda (candidate-info)
2911 (dolist (pattern-info (cdr candidate-info
))
2912 (if (not (equal (car pattern-info
)
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
)))
2923 (cons (car candidate-info
) count
)))
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
)
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
))
2962 (candidates-in-buffer)
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
))
2972 (buffer-disable-undo)
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
)
2988 '((candidates-in-buffer)))
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
)
3009 (set-buffer anything-current-buffer
)
3011 (goto-char (point-min))
3012 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
3013 (let (hierarchy curhead
)
3015 (if (numberp subexp
)
3016 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
3017 (cons (buffer-substring (point-at-bol) (point-at-eol))
3019 (hierarchies (headlines)
3020 (1+ (loop for
(_ . hierarchy
) in headlines
3021 maximize hierarchy
)))
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
)
3031 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / ")
3036 (loop for re in regexp
3037 for hierarchy from
0
3038 do
(goto-char (point-min))
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
)
3052 (with-current-buffer anything-current-buffer
3053 (line-number-at-pos pos
))
3056 (defun anything-headline-goto-position (pos recenter
)
3059 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
3062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3065 (setq anything-type-attributes
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
))
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
)
3095 (list actions candidate
)
3096 '(anything-c-transform-file-load-el
3097 anything-c-transform-file-browse-url
))))
3098 (candidate-transformer .
(lambda (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)
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)
3119 (intern function-name
)))))
3120 (action-transformer .
(lambda (actions candidate
)
3122 (list actions candidate
)
3123 '(anything-c-transform-function-call-interactively))))
3124 (candidate-transformer .
(lambda (candidates)
3127 '(anything-c-mark-interactive-functions)))))
3128 (sexp (action ("Eval s-expression" .
(lambda (c)
3130 ("Add s-expression to kill ring" . kill-new
))
3131 (action-transformer .
(lambda (actions candidate
)
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
)
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
)))))
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")
3150 (when (fboundp 'expectations
)
3152 (desc "candidates-file plug-in")
3153 (expect '(anything-p-candidats-file-init)
3154 (assoc-default 'init
3155 (car (anything-compile-sources
3157 (candidates-file .
"test.txt")))
3158 '(anything-compile-source--candidates-file)))))
3159 (expect '(anything-p-candidats-file-init
3161 (assoc-default 'init
3162 (car (anything-compile-sources
3164 (candidates-file .
"test.txt")
3165 (init .
(lambda () 1))))
3166 '(anything-compile-source--candidates-file)))))
3167 (expect '(anything-p-candidats-file-init
3169 (assoc-default 'init
3170 (car (anything-compile-sources
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
3183 " *Echo Area" " *Minibuf"))))
3184 (flet ((buffer-name (x) x
))
3185 (anything-test-candidates 'anything-c-source-buffers
))))
3186 (desc "anything-c-stringify")
3188 (anything-c-stringify "str1"))
3190 (anything-c-stringify 'str2
))
3191 (desc "anything-c-symbolify")
3193 (anything-c-symbolify "sym1"))
3195 (anything-c-symbolify 'sym2
)))))
3198 (provide 'anything-config
)
3200 ;;; Local Variables:
3201 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
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