1 ;;;; anything.el --- open anything / QuickSilver-like candidate-selection framework
3 ;; Copyright (C) 2007 Tamas Patrovics
4 ;; 2008 ~ 2011 rubikitch <rubikitch@ruby-lang.org>
5 ;; 2011 Thierry Volpiatto <thierry.volpiatto@gmail.com>
7 ;; Author: Tamas Patrovics
9 ;; Maintainers: rubikitch <rubikitch@ruby-lang.org>
10 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
12 ;; Keywords: files, frames, help, matching, outlines, processes, tools, convenience, anything
13 ;; X-URL: http://repo.or.cz/w/anything-config.git
14 ;; Site: http://www.emacswiki.org/cgi-bin/emacs/Anything
16 ;;; This file is NOT part of GNU Emacs
20 ;; This file is free software; you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation; either version 2, or (at your option)
25 ;; This file is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 ;; GNU General Public License for more details.
31 ;; You should have received a copy of the GNU General Public License
32 ;; along with GNU Emacs; see the file COPYING. If not, write to the
33 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
34 ;; Boston, MA 02110-1301, USA.
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;; Autodoc documentation:
40 ;; ---------------------
42 ;; * Commands defined here are:
43 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
44 ;; `anything-open-last-log'
45 ;; Open anything log file of last anything session.
47 ;; Resurrect previously invoked `anything'.
48 ;; `anything-resume-window-only'
50 ;; `anything-at-point'
51 ;; Call anything with symbol at point as initial input.
52 ;; `anything-force-update'
53 ;; Force recalculation and update of candidates.
54 ;; `anything-select-action'
55 ;; Select an action for the currently selected candidate.
56 ;; `anything-previous-line'
57 ;; Move selection to the previous line.
58 ;; `anything-next-line'
59 ;; Move selection to the next line.
60 ;; `anything-previous-page'
61 ;; Move selection back with a pageful.
62 ;; `anything-next-page'
63 ;; Move selection forward with a pageful.
64 ;; `anything-beginning-of-buffer'
65 ;; Move selection at the top.
66 ;; `anything-end-of-buffer'
67 ;; Move selection at the bottom.
68 ;; `anything-previous-source'
69 ;; Move selection to the previous source.
70 ;; `anything-next-source'
71 ;; Move selection to the next source.
72 ;; `anything-select-with-prefix-shortcut'
73 ;; Invoke default action with prefix shortcut.
74 ;; `anything-select-with-digit-shortcut'
75 ;; Invoke default action with digit/alphabet shortcut.
76 ;; `anything-exit-minibuffer'
77 ;; Select the current candidate by exiting the minibuffer.
78 ;; `anything-keyboard-quit'
79 ;; Quit minibuffer in anything.
81 ;; Help of `anything'.
82 ;; `anything-debug-output'
83 ;; Show all anything-related variables at this time.
84 ;; `anything-delete-current-selection'
85 ;; Delete the currently selected item.
86 ;; `anything-delete-minibuffer-contents'
87 ;; Same as `delete-minibuffer-contents' but this is a command.
88 ;; `anything-toggle-resplit-window'
89 ;; Toggle resplit anything window, vertically or horizontally.
90 ;; `anything-narrow-window'
91 ;; Narrow anything window.
92 ;; `anything-enlarge-window'
93 ;; Enlarge anything window.
94 ;; `anything-select-2nd-action'
95 ;; Select the 2nd action for the currently selected candidate.
96 ;; `anything-select-3rd-action'
97 ;; Select the 3rd action for the currently selected candidate.
98 ;; `anything-select-4th-action'
99 ;; Select the 4th action for the currently selected candidate.
100 ;; `anything-select-2nd-action-or-end-of-line'
101 ;; Select the 2nd action for the currently selected candidate.
102 ;; `anything-execute-persistent-action'
103 ;; Perform the associated action ATTR without quitting anything.
104 ;; `anything-scroll-other-window'
105 ;; Scroll other window (not *Anything* window) upward.
106 ;; `anything-scroll-other-window-down'
107 ;; Scroll other window (not *Anything* window) downward.
108 ;; `anything-toggle-visible-mark'
109 ;; Toggle anything visible mark at point.
110 ;; `anything-display-all-visible-marks'
111 ;; Show all `anything' visible marks strings.
112 ;; `anything-next-visible-mark'
113 ;; Move next anything visible mark.
114 ;; `anything-prev-visible-mark'
115 ;; Move previous anything visible mark.
116 ;; `anything-yank-selection'
117 ;; Set minibuffer contents to current selection.
118 ;; `anything-kill-selection-and-quit'
119 ;; Store current selection to kill ring.
120 ;; `anything-follow-mode'
121 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
122 ;; `anything-migrate-sources'
123 ;; Help to migrate to new `anything' way.
124 ;; `anything-describe-anything-attribute'
125 ;; Display the full documentation of ANYTHING-ATTRIBUTE.
126 ;; `anything-send-bug-report'
127 ;; Send a bug report of anything.el.
128 ;; `anything-send-bug-report-from-anything'
129 ;; Send a bug report of anything.el in anything session.
131 ;; * Variables defined here are:
132 ;; [EVAL] (autodoc-document-lisp-buffer :type 'internal-variable :prefix "anything-" :docstring t)
133 ;; `anything-version'
135 ;; `anything-sources'
136 ;; A list of sources to use with `anything'.
137 ;; `anything-type-attributes'
138 ;; It's a list of (TYPE ATTRIBUTES ...).
139 ;; `anything-enable-shortcuts'
140 ;; *Whether to use digit/alphabet shortcut to select the first nine matches.
141 ;; `anything-shortcut-keys-alist'
143 ;; `anything-display-source-at-screen-top'
144 ;; *Display candidates at the top of screen.
145 ;; `anything-candidate-number-limit'
146 ;; Apply candidate-number-limit attribute value.
147 ;; `anything-idle-delay'
148 ;; *Be idle for this many seconds, before updating in delayed sources.
149 ;; `anything-input-idle-delay'
150 ;; Be idle for this many seconds, before updating.
151 ;; `anything-samewindow'
152 ;; Use current window to show the candidates.
153 ;; `anything-source-filter'
154 ;; A list of source names to be displayed.
156 ;; Keymap for anything.
157 ;; `anything-header-face'
158 ;; *Face for header lines in the anything buffer.
159 ;; `anything-selection-face'
160 ;; *Face for currently selected item.
162 ;; Buffer showing completions.
163 ;; `anything-action-buffer'
164 ;; Buffer showing actions.
165 ;; `anything-selection-overlay'
166 ;; Overlay used to highlight the currently selected item.
167 ;; `anything-digit-overlays'
168 ;; Overlays for digit shortcuts. See `anything-enable-shortcuts'.
169 ;; `anything-candidate-cache'
170 ;; Holds the available candidate withing a single anything invocation.
171 ;; `anything-pattern'
175 ;; `anything-async-processes'
176 ;; List of information about asynchronous processes managed by anything.
177 ;; `anything-digit-shortcut-count'
178 ;; Number of digit shortcuts shown in the anything buffer.
179 ;; `anything-before-initialize-hook'
180 ;; Run before anything initialization.
181 ;; `anything-after-initialize-hook'
182 ;; Run after anything initialization.
183 ;; `anything-update-hook'
184 ;; Run after the anything buffer was updated according the new input pattern.
185 ;; `anything-after-update-hook'
186 ;; Run after the anything buffer was updated according the new input pattern.
187 ;; `anything-cleanup-hook'
188 ;; Run after anything minibuffer is closed.
189 ;; `anything-after-action-hook'
190 ;; Run after executing action.
191 ;; `anything-after-persistent-action-hook'
192 ;; Run after executing persistent action.
193 ;; `anything-move-selection-before-hook'
194 ;; Run before moving selection in `anything-buffer'.
195 ;; `anything-move-selection-after-hook'
196 ;; Run after moving selection in `anything-buffer'.
197 ;; `anything-restored-variables'
198 ;; Variables which are restored after `anything' invocation.
199 ;; `anything-saved-selection'
200 ;; Value of the currently selected object when the action list is shown.
201 ;; `anything-current-prefix-arg'
202 ;; Record `current-prefix-arg' when exiting minibuffer.
203 ;; `anything-candidate-separator'
204 ;; Candidates separator of `multiline' source.
205 ;; `anything-current-buffer'
206 ;; Current buffer when `anything' is invoked.
207 ;; `anything-buffer-file-name'
208 ;; Variable `buffer-file-name' when `anything' is invoked.
209 ;; `anything-saved-action'
210 ;; Saved value of the currently selected action by key.
211 ;; `anything-last-sources'
212 ;; OBSOLETE!! Sources of previously invoked `anything'.
213 ;; `anything-saved-current-source'
214 ;; Value of the current source when the action list is shown.
215 ;; `anything-compiled-sources'
216 ;; Compiled version of `anything-sources'.
217 ;; `anything-in-persistent-action'
218 ;; Flag whether in persistent-action or not.
219 ;; `anything-quick-update'
220 ;; If non-nil, suppress displaying sources which are out of screen at first.
221 ;; `anything-last-sources-local'
222 ;; Buffer local value of `anything-sources'.
223 ;; `anything-last-buffer'
224 ;; `anything-buffer' of previously `anything' session.
225 ;; `anything-persistent-action-use-special-display'
226 ;; If non-nil, use `special-display-function' in persistent action.
227 ;; `anything-execute-action-at-once-if-one'
228 ;; Execute default action and exit when only one candidate is remaining.
229 ;; `anything-quit-if-no-candidate'
230 ;; Quit when there is no candidates when non--nil.
231 ;; `anything-scroll-amount'
232 ;; Scroll amount when scrolling other window in an anything session.
233 ;; `anything-display-function'
234 ;; Function to display *anything* buffer.
235 ;; `anything-delayed-init-executed'
237 ;; `anything-mode-line-string'
238 ;; Help string displayed in mode-line in `anything'.
239 ;; `anything-help-message'
240 ;; Detailed help message string for `anything'.
241 ;; `anything-source-in-each-line-flag'
242 ;; Non-nil means add anything-source text-property in each candidate.
243 ;; `anything-debug-forms'
244 ;; Forms to show in `anything-debug-output'.
246 ;; If non-nil, write log message into *Anything Log* buffer.
247 ;; `anything-test-candidate-list'
249 ;; `anything-test-mode'
251 ;; `anything-source-name'
253 ;; `anything-candidate-buffer-alist'
255 ;; `anything-check-minibuffer-input-timer'
257 ;; `anything-match-hash'
259 ;; `anything-cib-hash'
261 ;; `anything-tick-hash'
263 ;; `anything-issued-errors'
265 ;; `anything-shortcut-keys'
267 ;; `anything-once-called-functions'
269 ;; `anything-follow-mode'
270 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
271 ;; `anything-let-variables'
273 ;; `anything-split-window-state'
275 ;; `anything-last-log-file'
277 ;; `anything-compile-source-functions'
278 ;; Functions to compile elements of `anything-sources' (plug-in).
281 ;; `anything-additional-attributes'
282 ;; List of all `anything' attributes.
283 ;; `anything-buffers'
284 ;; All of `anything-buffer' in most recently used order.
285 ;; `anything-current-position'
286 ;; Restore or save current position in `anything-current-buffer'.
287 ;; `anything-last-frame-or-window-configuration'
288 ;; Used to store window or frame configuration when anything start.
289 ;; `anything-reading-pattern'
290 ;; Whether in `read-string' in anything or not.
291 ;; `anything-compile-source-functions-default'
292 ;; Plug-ins this file provides.
293 ;; `anything-input-local'
295 ;; `anything-process-delayed-sources-timer'
297 ;; `anything-mode-line-string-real'
299 ;; `anything-exit-status'
300 ;; Flag to inform whether anything have aborted or quitted.
303 ;; `anything-orig-enable-shortcuts'
305 ;; `anything-persistent-action-display-window'
306 ;; Return the window that will be used for presistent action.
307 ;; `anything-visible-mark-face'
309 ;; `anything-visible-mark-overlays'
311 ;; `anything-marked-candidates'
312 ;; Return marked candidates of current source if any.
313 ;; `anything-maintainer-mail-address'
315 ;; `anything-bug-report-salutation'
317 ;; `anything-no-dump-variables'
318 ;; Variables not to dump in bug report.
320 ;; *** END auto-documentation
322 ;; [EVAL] (autodoc-update-all)
328 ;; Start with M-x anything, narrow the list by typing some pattern,
329 ;; select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter,
330 ;; left/right moves between sources. With TAB actions can be selected
331 ;; if the selected candidate has more than one possible action.
333 ;; Note that anything.el provides only the framework and some example
334 ;; configurations for demonstration purposes. See anything-config.el
335 ;; for practical, polished, easy to use configurations which can be
336 ;; used to assemble a custom personalized configuration. And many
337 ;; other configurations are in the EmacsWiki.
339 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-config.el
340 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingSources
342 ;; Maintainer's configuration is in the EmacsWiki. It would tell you
343 ;; many tips to write smart sources!
345 ;; http://www.emacswiki.org/cgi-bin/emacs/RubikitchAnythingConfiguration
347 ;; Here is Japanese translation of `anything-sources' attributes. Thanks.
348 ;; http://d.hatena.ne.jp/sirocco634/20091012/1255336649
353 ;; If you have problems, send a bug report via C-c C-x C-b in anything session (best)
354 ;; or M-x anything-send-bug-report outside anything session.
355 ;; I implemented bug report feature because I want to know your current state.
356 ;; It helps me to solve problems easily.
358 ;; 0) Setup mail in Emacs, the easiest way is:
359 ;; (setq user-mail-address "your@mail.address")
360 ;; (setq user-full-name "Your Full Name")
361 ;; (setq smtpmail-smtp-server "your.smtp.server.jp")
362 ;; (setq mail-user-agent 'message-user-agent)
363 ;; (setq message-send-mail-function 'message-smtpmail-send-it)
364 ;; 1) Be sure to use the LATEST version of anything.el.
365 ;; 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
366 ;; 3) Use Lisp version instead of compiled one: (load "anything.el")
368 ;; 5) If you got an error, please do not close *Backtrace* buffer.
369 ;; 6) Type C-c C-x C-b (anything session, best!)
370 ;; or M-x anything-send-bug-report (outside)
371 ;; then M-x insert-buffer *Backtrace* (if you got error)
372 ;; 7) Describe the bug using a precise recipe.
373 ;; 8) Type C-c C-c to send.
374 ;; # If you are a Japanese, please write in Japanese:-)
377 ;; You can extend `anything' by writing plug-ins. As soon as
378 ;; `anything' is invoked, `anything-sources' is compiled into basic
379 ;; attributes, then compiled one is used during invocation.
381 ;; The oldest built-in plug-in is `type' attribute: appends
382 ;; appropriate element of `anything-type-attributes'. Second built-in
383 ;; plug-in is `candidates-in-buffer': selecting a line from candidates
386 ;; To write a plug-in:
387 ;; 1. Define a compiler: anything-compile-source--*
388 ;; 2. Add compier function to `anything-compile-source-functions'.
389 ;; 3. (optional) Write helper functions.
391 ;; Anything plug-ins are found in the EmacsWiki.
393 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
395 ;; Tested on Emacs 22/23/24.
398 ;; Thanks to Vagn Johansen for ideas.
399 ;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
400 ;; Thanks to Tassilo Horn for fixes.
401 ;; Thanks to Drew Adams for various fixes
402 ;; Thanks to IMAKADO for candidates-in-buffer idea.
403 ;; Thanks to Tomohiro MATSUYAMA for multiline patch.
408 ;; If you have library `linkd.el', load
409 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
410 ;; navigate around the sections Linkd mode will
411 ;; highlight this Index. You can get `linkd.el' here:
412 ;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
419 ;; `anything' accepts keyword arguments. See docstring.
420 ;; [EVAL IT] (describe-function 'anything)
423 ;; `anything-enable-shortcuts' enables us to select candidate easily.
424 ;; If 'prefix then they can be selected using <prefix-key> <alnum>.
425 ;; The prefix key is `anything-select-with-prefix-shortcut'.
426 ;; If the <prefix-key> is a letter, pressing twice inputs the letter itself.
428 ;; (setq anything-enable-shortcuts 'prefix)
429 ;; (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
432 ;; You can edit current selection using `anything-edit-current-selection'.
433 ;; It is useful after persistent-action.
436 ;; For `anything' users, setting `anything-sources' directly and
437 ;; invoke M-x anything is obsolete way for now. Try M-x
438 ;; `anything-migrate-sources'!
441 ;; If you want to create anything sources, yasnippet would help you.
442 ;; http://yasnippet.googlecode.com/
444 ;; Then get the snippet from
445 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
447 ;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
451 ;; `anything-interpret-value' is useful function to interpret value
452 ;; like `candidates' attribute.
454 ;; (anything-interpret-value "literal") ; => "literal"
455 ;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
456 ;; (let ((source '((name . "lambda with source name"))))
457 ;; (anything-interpret-value
458 ;; (lambda () anything-source-name)
459 ;; source)) ; => "lambda with source name"
460 ;; (flet ((f () "function symbol"))
461 ;; (anything-interpret-value 'f)) ; => "function symbol"
462 ;; (let ((v "variable symbol"))
463 ;; (anything-interpret-value 'v)) ; => "variable symbol"
464 ;; (anything-interpret-value 'unbounded-1) ; error
467 ;; Now symbols are acceptable as candidates. So you do not have to use
468 ;; `symbol-name' function. The source is much simpler. For example,
469 ;; `apropos-internal' returns a list of symbols.
472 ;; '(((name . "Commands")
473 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
475 ;; (action . describe-function))))
478 ;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
479 ;; marked candidate, press M-[ or M-].
482 ;; `anything-map' is now Emacs-standard key bindings by default.
484 ;; There are many `anything' applications, using `anything' for
485 ;; selecting candidate. In this case, if there is one candidate or no
486 ;; candidate, popping up *anything* buffer is irritating. If one
487 ;; candidate, you want to select it at once. If no candidate, you want
488 ;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
489 ;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
490 ;; that setting these variables GLOBALLY is bad idea because of
491 ;; delayed sources. These are meant to be let-binded.
492 ;; See anything-etags.el for example.
494 ;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
497 ;; (let ((anything-execute-action-at-once-if-one t)
498 ;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
499 ;; (anything temporary-sources input))
502 ;; `set-frame-configuration' arises flickering. If you hate
504 ;; (setq anything-save-configuration-functions
505 ;; '(set-window-configuration . current-window-configuration))
506 ;; at the cost of restoring frame configuration (only window configuration).
509 ;; `anything-delete-current-selection' deletes the current line.
510 ;; It is useful when deleting a candidate in persistent action.
511 ;; eg. `kill-buffer'.
513 ;; [EVAL IT] (describe-function 'anything-delete-current-selection)
516 ;; `anything-attr' gets the attribute. `anything-attrset' sets the
517 ;; attribute. `anything-attr-defined' tests whether the attribute is
518 ;; defined. They handles source-local variables.
520 ;; [EVAL IT] (describe-function 'anything-attr)
521 ;; [EVAL IT] (describe-function 'anything-attrset)
522 ;; [EVAL IT] (describe-function 'anything-attr-defined)
525 ;; `anything-sources' accepts many attributes to make your life easier.
526 ;; Now `anything-sources' accepts a list of symbols.
528 ;; [EVAL IT] (describe-variable 'anything-sources)
531 ;; `anything' has optional arguments. Now you do not have to let-bind
532 ;; `anything-sources'.
534 ;; [EVAL IT] (describe-function 'anything)
537 ;; `anything-resume' resumes last `anything' session. Now you do not
538 ;; have to retype pattern.
540 ;; [EVAL IT] (describe-function 'anything-resume)
543 ;; `anything-execute-persistent-action' executes action without
544 ;; quitting `anything'. When popping up a buffer in other window by
545 ;; persistent action, you can scroll with `anything-scroll-other-window' and
546 ;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
548 ;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
549 ;; [EVAL IT] (describe-variable 'anything-sources)
552 ;; `anything-select-2nd-action', `anything-select-3rd-action' and
553 ;; `anything-select-4th-action' select other than default action
554 ;; without pressing Tab.
557 ;; Using `anything-candidate-buffer' and the candidates-in-buffer
558 ;; attribute is much faster than traditional "candidates and match"
559 ;; way. And `anything-current-buffer-is-modified' avoids to
560 ;; recalculate candidates for unmodified buffer. See docstring of
563 ;; [EVAL IT] (describe-function 'anything-candidate-buffer)
564 ;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
565 ;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
568 ;; `anything-current-buffer' and `anything-buffer-file-name' stores
569 ;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
570 ;; is invoked. Use them freely.
572 ;; [EVAL IT] (describe-variable 'anything-current-buffer)
573 ;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
576 ;; `anything-completing-read' and `anything-read-file-name' are
577 ;; experimental implementation. If you are curious, type M-x
578 ;; anything-read-string-mode. It is a minor mode and toggles on/off.
581 ;; Use `anything-test-candidates' to test your handmade anything
582 ;; sources. It simulates contents of *anything* buffer with pseudo
583 ;; `anything-sources' and `anything-pattern', without side-effect. So
584 ;; you can unit-test your anything sources! Let's TDD!
586 ;; [EVAL IT] (describe-function 'anything-test-candidates)
588 ;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
589 ;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
591 ;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
592 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
593 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
596 ;; If you want to create anything sources, see anything-config.el.
597 ;; It is huge collection of sources. You can learn from examples.
602 ;; - process status indication
604 ;; - async sources doesn't honor digit-shortcut-count
606 ;; - anything-candidate-number-limit can't be nil everywhere
610 ;; Change log of this file is found at
611 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything.el
613 ;; Change log of this project is found at
614 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
621 (defvar anything-version nil
)
622 (setq anything-version
"1.3")
626 ;; (@* "User Configuration")
629 ;; A default value is provided in anything-config.el
630 (defvar anything-sources nil
631 "A list of sources to use with `anything'.
632 It is deprecated, you should not use this.
633 Use instead individual sources or list of sources of your choice.")
635 ;; Default values are provided in anything-config.el.
636 (defvar anything-type-attributes nil
637 "It's a list of \(TYPE ATTRIBUTES ...\).
638 ATTRIBUTES are the same as attributes for `anything-sources'.
639 TYPE connects the value to the appropriate sources.
640 Don't set this directly, use instead `define-anything-type-attribute'.
642 This allows specifying common attributes for several sources.
643 For example, sources which provide files can specify
644 common attributes with a `file' type.")
646 (defvaralias 'anything-enable-digit-shortcuts
'anything-enable-shortcuts
647 "Same as `anything-enable-shortcuts'.
648 Alphabet shortcuts are available now in `anything-enable-shortcuts'.
649 `anything-enable-digit-shortcuts' is retained for compatibility.")
651 (defvar anything-enable-shortcuts nil
652 "*Whether to use digit/alphabet shortcut to select the first nine matches.
653 If t then they can be selected using Ctrl+<number>.
655 If 'prefix then they can be selected using <prefix-key> <alnum>.
656 The prefix key is `anything-select-with-prefix-shortcut'.
657 If the <prefix-key> is a letter, pressing twice inputs the letter itself.
659 (setq anything-enable-shortcuts 'prefix)
660 (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
662 If 'alphabet then they can be selected using Shift+<alphabet> (deprecated).
663 It is not recommended because you cannot input capital letters in pattern.
665 Keys (digit/alphabet) are listed in `anything-shortcut-keys-alist'.")
667 (defvar anything-shortcut-keys-alist
668 '((alphabet .
"asdfghjklzxcvbnmqwertyuiop")
669 (prefix .
"asdfghjklzxcvbnmqwertyuiop1234567890")
672 (defvar anything-display-source-at-screen-top t
673 "*Display candidates at the top of screen.
674 This happen when using `anything-next-source' and `anything-previous-source'.")
676 (defvar anything-candidate-number-limit
50
677 "*Limit candidate number globally.
678 Do not show more candidates than this limit from individual sources.
679 It is usually pointless to show hundreds of matches
680 when the pattern is empty, because it is much simpler to type a
681 few characters to narrow down the list of potential candidates.
683 Set it to nil if you don't want this limit.")
685 (defvar anything-idle-delay
0.3
686 "*Be idle for this many seconds, before updating in delayed sources.
687 This is useful for sources involving heavy operations
688 \(like launching external programs\), so that candidates
689 from the source are not retrieved unnecessarily if the user keeps typing.
691 It also can be used to declutter the results anything displays,
692 so that results from certain sources are not shown with every
693 character typed, only if the user hesitates a bit.")
695 (defvar anything-input-idle-delay
0.3
696 "Be idle for this many seconds, before updating.
698 Unlike `anything-idle-delay', it is also effective for non-delayed sources.
699 If nil, candidates are collected immediately.
701 Note: If this value is too low compared to `anything-idle-delay',
702 you may have duplicated sources when using multiples sources.
703 Safe value is always >= `anything-idle-delay'.
704 Default settings are equal value for both.")
706 (defvar anything-samewindow nil
707 "Use current window to show the candidates.
708 If t then Anything doesn't pop up a new window.")
710 (defvar anything-source-filter nil
711 "A list of source names to be displayed.
712 Other sources won't appear in the search results.
713 If nil then there is no filtering.
714 See also `anything-set-source-filter'.")
717 (let ((map (copy-keymap minibuffer-local-map
)))
718 (define-key map
(kbd "<down>") 'anything-next-line
)
719 (define-key map
(kbd "<up>") 'anything-previous-line
)
720 (define-key map
(kbd "C-n") 'anything-next-line
)
721 (define-key map
(kbd "C-p") 'anything-previous-line
)
722 (define-key map
(kbd "<prior>") 'anything-previous-page
)
723 (define-key map
(kbd "<next>") 'anything-next-page
)
724 (define-key map
(kbd "M-v") 'anything-previous-page
)
725 (define-key map
(kbd "C-v") 'anything-next-page
)
726 (define-key map
(kbd "M-<") 'anything-beginning-of-buffer
)
727 (define-key map
(kbd "M->") 'anything-end-of-buffer
)
728 (define-key map
(kbd "C-g") 'anything-keyboard-quit
)
729 (define-key map
(kbd "<right>") 'anything-next-source
)
730 (define-key map
(kbd "<left>") 'anything-previous-source
)
731 (define-key map
(kbd "<RET>") 'anything-exit-minibuffer
)
732 (define-key map
(kbd "C-1") 'anything-select-with-digit-shortcut
)
733 (define-key map
(kbd "C-2") 'anything-select-with-digit-shortcut
)
734 (define-key map
(kbd "C-3") 'anything-select-with-digit-shortcut
)
735 (define-key map
(kbd "C-4") 'anything-select-with-digit-shortcut
)
736 (define-key map
(kbd "C-5") 'anything-select-with-digit-shortcut
)
737 (define-key map
(kbd "C-6") 'anything-select-with-digit-shortcut
)
738 (define-key map
(kbd "C-7") 'anything-select-with-digit-shortcut
)
739 (define-key map
(kbd "C-8") 'anything-select-with-digit-shortcut
)
740 (define-key map
(kbd "C-9") 'anything-select-with-digit-shortcut
)
741 (loop for c from ?A to ?Z do
742 (define-key map
(make-string 1 c
) 'anything-select-with-digit-shortcut
))
743 (define-key map
(kbd "C-i") 'anything-select-action
)
744 (define-key map
(kbd "C-z") 'anything-execute-persistent-action
)
745 (define-key map
(kbd "C-e") 'anything-select-2nd-action-or-end-of-line
)
746 (define-key map
(kbd "C-j") 'anything-select-3rd-action
)
747 (define-key map
(kbd "C-o") 'anything-next-source
)
748 (define-key map
(kbd "C-M-v") 'anything-scroll-other-window
)
749 (define-key map
(kbd "M-<next>") 'anything-scroll-other-window
)
750 (define-key map
(kbd "C-M-y") 'anything-scroll-other-window-down
)
751 (define-key map
(kbd "C-M-S-v") 'anything-scroll-other-window-down
)
752 (define-key map
(kbd "M-<prior>") 'anything-scroll-other-window-down
)
753 (define-key map
(kbd "<C-M-down>") 'anything-scroll-other-window
)
754 (define-key map
(kbd "<C-M-up>") 'anything-scroll-other-window-down
)
755 (define-key map
(kbd "C-SPC") 'anything-toggle-visible-mark
)
756 (define-key map
(kbd "M-[") 'anything-prev-visible-mark
)
757 (define-key map
(kbd "M-]") 'anything-next-visible-mark
)
758 (define-key map
(kbd "C-k") 'anything-delete-minibuffer-contents
)
760 (define-key map
(kbd "C-r") 'undefined
)
761 (define-key map
(kbd "C-t") 'anything-toggle-resplit-window
)
762 (define-key map
(kbd "C-}") 'anything-narrow-window
)
763 (define-key map
(kbd "C-{") 'anything-enlarge-window
)
765 (define-key map
(kbd "C-c C-d") 'anything-delete-current-selection
)
766 (define-key map
(kbd "C-c C-y") 'anything-yank-selection
)
767 (define-key map
(kbd "C-c C-k") 'anything-kill-selection-and-quit
)
768 (define-key map
(kbd "C-c C-f") 'anything-follow-mode
)
769 (define-key map
(kbd "C-c C-u") 'anything-force-update
)
770 (define-key map
(kbd "M-p") 'previous-history-element
)
771 (define-key map
(kbd "M-n") 'next-history-element
)
773 (define-key map
"\C-c\C-x\C-d" 'anything-debug-output
)
774 (define-key map
"\C-c\C-x\C-m" 'anything-display-all-visible-marks
)
775 (define-key map
"\C-c\C-x\C-b" 'anything-send-bug-report-from-anything
)
776 ;; Use `describe-mode' key in `global-map'.
777 (define-key map
[f1] nil) ; Allow to eval keymap whithout errors.
778 (dolist (k (where-is-internal 'describe-mode global-map))
779 (define-key map k 'anything-help))
781 "Keymap for anything.")
783 (defgroup anything nil
785 :prefix "anything-" :group 'convenience)
787 (defface anything-header
788 '((t (:inherit header-line)))
789 "Face for header lines in the anything buffer."
792 (defvar anything-header-face 'anything-header
793 "*Face for header lines in the anything buffer.")
795 (defface anything-candidate-number
796 '((t (:background "Yellow" :foreground "black")))
797 "Face for candidate number in mode-line." :group 'anything)
799 (defvar anything-selection-face 'highlight
800 "*Face for currently selected item.")
802 (defvar anything-buffer "*anything*"
803 "Buffer showing completions.")
805 (defvar anything-action-buffer "*anything action*"
806 "Buffer showing actions.")
808 (defvar anything-selection-overlay nil
809 "Overlay used to highlight the currently selected item.")
811 (defvar anything-digit-overlays nil
812 "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
814 (defvar anything-candidate-cache nil
815 "Holds the available candidate withing a single anything invocation.")
817 (defvar anything-pattern
818 "The input pattern used to update the anything buffer.")
820 (defvar anything-input
821 "The input typed in the candidates panel.")
823 (defvar anything-async-processes nil
824 "List of information about asynchronous processes managed by anything.")
826 (defvar anything-digit-shortcut-count 0
827 "Number of digit shortcuts shown in the anything buffer.")
829 (defvar anything-before-initialize-hook nil
830 "Run before anything initialization.
831 This hook is run before init functions in `anything-sources'.")
833 (defvar anything-after-initialize-hook nil
834 "Run after anything initialization.
835 Global variables are initialized and the anything buffer is created.
836 But the anything buffer has no contents.")
838 (defvar anything-update-hook nil
839 "Run after the anything buffer was updated according the new input pattern.
840 This hook is run at the beginning of buffer.
841 The first candidate is selected after running this hook.
842 See also `anything-after-update-hook'.")
844 (defvar anything-after-update-hook nil
845 "Run after the anything buffer was updated according the new input pattern.
846 This is very similar to `anything-update-hook' but selection is not moved.
847 It is useful to select a particular object instead of the first one.")
849 (defvar anything-cleanup-hook nil
850 "Run after anything minibuffer is closed.
851 IOW this hook is executed BEFORE performing action.")
853 (defvar anything-before-action-hook nil
854 "Run before executing action.
855 Contrarily to `anything-cleanup-hook',
856 this hook run before anything minibuffer is closed
857 and before performing action.")
859 (defvar anything-after-action-hook nil
860 "Run after executing action.")
862 (defvar anything-after-persistent-action-hook nil
863 "Run after executing persistent action.")
865 (defvar anything-move-selection-before-hook nil
866 "Run before moving selection in `anything-buffer'.")
868 (defvar anything-move-selection-after-hook nil
869 "Run after moving selection in `anything-buffer'.")
871 (defvar anything-restored-variables
872 '( anything-candidate-number-limit
873 anything-source-filter
874 anything-source-in-each-line-flag
877 "Variables which are restored after `anything' invocation.")
879 (defvar anything-saved-selection nil
880 "Value of the currently selected object when the action list is shown.")
882 (defvar anything-current-prefix-arg nil
883 "Record `current-prefix-arg' when exiting minibuffer.")
885 (defvar anything-candidate-separator
886 "--------------------"
887 "Candidates separator of `multiline' source.")
889 (defvar anything-current-buffer nil
890 "Current buffer when `anything' is invoked.")
892 (defvar anything-buffer-file-name nil
893 "Variable `buffer-file-name' when `anything' is invoked.")
895 (defvar anything-saved-action nil
896 "Saved value of the currently selected action by key.")
898 (defvar anything-last-sources nil
899 "OBSOLETE!! Sources of previously invoked `anything'.")
901 (defvar anything-saved-current-source nil
902 "Value of the current source when the action list is shown.")
904 (defvar anything-compiled-sources nil
905 "Compiled version of `anything-sources'.")
907 (defvar anything-in-persistent-action nil
908 "Flag whether in persistent-action or not.")
910 (defvar anything-quick-update nil
911 "If non-nil, suppress displaying sources which are out of screen at first.
912 They are treated as delayed sources at this input.
913 This flag makes `anything' a bit faster with many sources.")
915 (defvar anything-last-sources-local nil
916 "Buffer local value of `anything-sources'.")
918 (defvar anything-last-buffer nil
919 "`anything-buffer' of previously `anything' session.")
921 (defvar anything-save-configuration-functions
922 '(set-window-configuration . current-window-configuration)
923 "The functions used to restore/save window or frame configurations.
924 It is a pair where the car is the function to restore window or frame config,
925 and the cdr is the function to save the window or frame config.
927 If you want to save and restore frame configuration, set this variable to
928 '\(set-frame-configuration . current-frame-configuration\)
930 Older version saves/restores frame configuration, but the default is changed now
931 because flickering can occur in some environment. ")
933 (defvar anything-persistent-action-use-special-display nil
934 "If non-nil, use `special-display-function' in persistent action.")
936 (defvar anything-execute-action-at-once-if-one nil
937 "Execute default action and exit when only one candidate is remaining.
938 It is useful for `anything' applications.")
940 (defvar anything-quit-if-no-candidate nil
941 "Quit when there is no candidates when non--nil.
942 This variable accepts a function, which is executed if no candidate.
944 It is useful for `anything' applications.")
946 (defvar anything-scroll-amount nil
947 "Scroll amount when scrolling other window in an anything session.
948 It is used by `anything-scroll-other-window'
949 and `anything-scroll-other-window-down'.
951 If you prefer scrolling line by line, set this value to 1.")
953 (defvar anything-display-function 'anything-default-display-buffer
954 "Function to display *anything* buffer.
955 It is `anything-default-display-buffer' by default,
956 which affects `anything-samewindow'.")
958 (defvar anything-delayed-init-executed nil)
960 (defvar anything-mode-line-string "\\<anything-map>\\[anything-help]:help \
961 \\[anything-select-action]:Acts \
962 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
963 \\[anything-select-3rd-action]:NthAct \
964 \\[anything-send-bug-report-from-anything]:BugReport"
965 "Help string displayed in mode-line in `anything'.
966 It can be a string or a list of two args, in this case,
967 first arg is a string that will be used as name for candidates number,
968 second arg any string to display in mode line.
969 If nil, use default `mode-line-format'.")
971 (defvar anything-help-message
972 "\\<anything-map>The keys that are defined for `anything' are:
974 "Detailed help message string for `anything'.
975 It also accepts function or variable symbol.")
977 ;; FIXME: What is this
978 ;(put 'anything 'timid-completion 'disabled)
980 (defvar anything-source-in-each-line-flag nil
981 "Non-nil means add anything-source text-property in each candidate.
982 experimental feature.")
984 (defvaralias 'anything-debug-variables 'anything-debug-forms)
986 (defvar anything-debug-forms nil
987 "Forms to show in `anything-debug-output'.
988 Otherwise all variables started with `anything-' are shown.
989 It is useful for debug.")
991 (defvar anything-debug nil
992 "If non-nil, write log message into *Anything Log* buffer.
993 If `debug-on-error' is non-nil, write log message regardless of this variable.
994 It is disabled by default because *Anything Log* grows quickly.")
996 ;; (@* "Internal Variables")
997 (defvar anything-test-candidate-list nil)
998 (defvar anything-test-mode nil)
999 (defvar anything-source-name nil)
1000 (defvar anything-candidate-buffer-alist nil)
1001 (defvar anything-check-minibuffer-input-timer nil)
1002 (defvar anything-match-hash (make-hash-table :test 'equal))
1003 (defvar anything-cib-hash (make-hash-table :test 'equal))
1004 (defvar anything-tick-hash (make-hash-table :test 'equal))
1005 (defvar anything-issued-errors nil)
1006 (defvar anything-shortcut-keys nil)
1007 (defvar anything-once-called-functions nil)
1008 (defvar anything-follow-mode nil)
1009 (defvar anything-let-variables nil)
1010 (defvar anything-split-window-state nil)
1012 ;; (@* "Utility: logging")
1013 (defun anything-log (format-string &rest args)
1014 "Log message if `debug-on-error' or `anything-debug' is non-nil.
1015 Messages are written to the *Anything Log* buffer.
1017 Argument FORMAT-STRING is a string to use with `format'.
1018 Use optional arguments ARGS like in `format'."
1019 (when (or debug-on-error anything-debug)
1020 (with-current-buffer (get-buffer-create "*Anything Log*")
1021 (buffer-disable-undo)
1022 (set (make-local-variable 'inhibit-read-only) t)
1023 (goto-char (point-max))
1024 (insert (let ((tm (current-time)))
1025 (format "%s.%06d (%s) %s\n"
1026 (format-time-string "%H:%M:%S" tm)
1028 (anything-log-get-current-function)
1029 (apply #'format (cons format-string args))))))))
1031 (defmacro anything-log-eval (&rest exprs)
1032 "Write each EXPRS evaluation result to the *Anything Log* buffer."
1033 `(anything-log-eval-internal ',exprs))
1035 (defun anything-log-run-hook (hook)
1036 "Run HOOK like `run-hooks' but write these actions to anything log buffer."
1037 (anything-log "executing %s" hook)
1039 (anything-log-eval (symbol-value hook))
1040 (anything-log-eval (default-value hook)))
1042 (anything-log "executed %s" hook))
1044 (defun anything-log-eval-internal (exprs)
1045 "Eval EXPRS and write results to anything log buffer."
1046 (dolist (expr exprs)
1048 (anything-log "%S = %S" expr (eval expr))
1049 (error (anything-log "%S = ERROR!" expr)))))
1051 (defun anything-log-get-current-function ()
1052 "Get function name calling `anything-log'.
1053 The original idea is from `tramp-debug-message'."
1054 (loop with exclude-func-re = "^anything-\\(?:interpret\\|log\\|.*funcall\\)"
1055 for btn from 1 to 40 ;avoid inf-loop
1056 for btf = (second (backtrace-frame btn))
1057 for fn = (if (symbolp btf) (symbol-name btf) "")
1058 if (and (string-match "^anything" fn)
1059 (not (string-match exclude-func-re fn)))
1062 (defun anything-log-error (&rest args)
1063 "Accumulate error messages into `anything-issued-errors'.
1064 ARGS are args given to `format'."
1065 (apply 'anything-log (concat "ERROR: " (car args)) (cdr args))
1066 (let ((msg (apply 'format args)))
1067 (unless (member msg anything-issued-errors)
1068 (add-to-list 'anything-issued-errors msg))))
1070 (defvar anything-last-log-file nil)
1071 (defun anything-log-save-maybe ()
1072 "May be save log buffer to `anything-last-log-file'."
1073 (when (stringp anything-debug)
1074 (let ((logdir (expand-file-name (format-time-string "%Y%m%d")
1076 (make-directory logdir t)
1077 (with-current-buffer (get-buffer-create "*Anything Log*")
1078 (write-region (point-min) (point-max)
1079 (setq anything-last-log-file
1080 (expand-file-name (format-time-string "%Y%m%d-%H%M%S")
1085 (defun anything-open-last-log ()
1086 "Open anything log file of last anything session."
1088 (if anything-last-log-file
1089 (view-file anything-last-log-file)
1090 (switch-to-buffer "*Anything Log*")))
1092 (defun anything-print-error-messages ()
1093 "Print error messages in `anything-issued-errors'."
1094 (message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))
1096 ;; (anything-log "test")
1097 ;; (switch-to-buffer-other-window "*Anything Log*")
1099 ;; (@* "Programming Tools")
1100 (defmacro anything-aif (test-form then-form &rest else-forms)
1101 "Like `if' but set the result of TEST-FORM in a temprary variable called `it'.
1102 THEN-FORM and ELSE-FORMS are then excuted just like in `if'."
1103 (declare (indent 2) (debug t))
1104 `(let ((it ,test-form))
1105 (if it ,then-form ,@else-forms)))
1107 (defun anything-mklist (obj)
1108 "If OBJ is a list \(but not lambda\), return itself.
1109 Otherwise make a list with one element."
1110 (if (and (listp obj) (not (functionp obj)))
1114 ;; (@* "Anything API")
1116 (defun anything-buffer-get ()
1117 "Return `anything-action-buffer' if shown otherwise `anything-buffer'."
1118 (if (anything-action-window)
1119 anything-action-buffer
1122 (defun anything-window ()
1123 "Window of `anything-buffer'."
1124 (get-buffer-window (anything-buffer-get) 'visible))
1126 (defun anything-action-window ()
1127 "Window of `anything-action-buffer'."
1128 (get-buffer-window anything-action-buffer 'visible))
1130 (defmacro with-anything-window (&rest body)
1131 "Be sure BODY is excuted in the anything window."
1132 (declare (indent 0) (debug t))
1133 `(if anything-test-mode
1134 (with-current-buffer (anything-buffer-get)
1136 (with-selected-window (anything-window)
1139 (defmacro with-anything-current-buffer (&rest body)
1140 "Eval BODY inside `anything-current-buffer'."
1141 (declare (indent 0) (debug t))
1142 `(with-current-buffer anything-current-buffer
1145 (defmacro with-anything-restore-variables(&rest body)
1146 "Restore `anything-restored-variables' after executing BODY.
1147 `post-command-hook' is handled specially."
1148 (declare (indent 0) (debug t))
1149 `(let ((--orig-vars (mapcar (lambda (v)
1150 (cons v (symbol-value v)))
1151 anything-restored-variables))
1152 (--post-command-hook-pair (cons post-command-hook
1153 (default-value 'post-command-hook))))
1154 (setq post-command-hook '(t))
1155 (setq-default post-command-hook nil)
1156 (unwind-protect (progn ,@body)
1157 (loop for (var . value) in --orig-vars
1159 (setq post-command-hook (car --post-command-hook-pair))
1160 (setq-default post-command-hook (cdr --post-command-hook-pair))
1161 (anything-log "restore variables"))))
1163 (defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
1164 "Get the value of ATTRIBUTE-NAME of SRC.
1165 if SRC is omitted, use current source.
1166 It is useful to write your sources."
1167 (anything-aif (assq attribute-name src)
1170 (defun* anything-attr* (attribute-name &optional (src (anything-get-current-source)))
1171 "Pass the value of ATTRIBUTE-NAME of SRC to `anything-interpret-value'.
1172 if SRC is omitted, use current source.
1173 It is useful to write your sources."
1174 (anything-interpret-value (anything-attr attribute-name src)))
1176 (defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
1177 "Return non-nil if ATTRIBUTE-NAME of SRC is defined.
1178 if SRC is omitted, use current source.
1179 It is useful to write your sources."
1180 (and (assq attribute-name src) t))
1182 (defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
1183 "Set the value of ATTRIBUTE-NAME of SRC to VALUE.
1184 if SRC is omitted, use current source.
1185 It is useful to write your sources."
1186 (anything-aif (assq attribute-name src)
1188 (setcdr src (cons (cons attribute-name value) (cdr src))))
1191 ;; anything-set-source-filter
1193 ;; This function sets a filter for anything sources and it may be
1194 ;; called while anything is running. It can be used to toggle
1195 ;; displaying of sources dinamically. For example, additional keys
1196 ;; can be bound into `anything-map' to display only the file-related
1197 ;; results if there are too many matches from other sources and
1198 ;; you're after files only:
1200 ;; Shift+F shows only file results from some sources:
1202 ;; (define-key anything-map "F" 'anything-my-show-files-only)
1204 ;; (defun anything-my-show-files-only ()
1206 ;; (anything-set-source-filter '("File Name History"
1207 ;; "Files from Current Directory")))
1209 ;; Shift+A shows all results:
1211 ;; (define-key anything-map "A" 'anything-my-show-all)
1213 ;; (defun anything-my-show-all ()
1215 ;; (anything-set-source-filter nil))
1218 ;; Note that you have to prefix the functions with anything- prefix,
1219 ;; otherwise they won't be bound when Anything is used under
1220 ;; Iswitchb. The -my- part is added to avoid collisions with
1221 ;; existing Anything function names.
1223 (defun anything-set-source-filter (sources)
1224 "Set the value of `anything-source-filter' and update the list of results.
1225 This apply only on SOURCES."
1226 (unless (and (listp sources)
1227 (loop for name in sources always (stringp name)))
1228 (error "Invalid data in `anything-set-source-filter': %S" sources))
1229 (setq anything-source-filter sources)
1230 (anything-log-eval anything-source-filter)
1233 (defun anything-set-sources (sources &optional no-init no-update)
1234 "Set SOURCES during `anything' invocation.
1235 If NO-INIT is non-nil, skip executing init functions of SOURCES.
1236 If NO-UPDATE is non-nil, skip executing `anything-update'."
1237 (with-current-buffer anything-buffer
1238 (setq anything-compiled-sources nil
1239 anything-sources sources
1240 anything-last-sources-local sources)
1241 (anything-log-eval anything-compiled-sources anything-sources))
1242 (unless no-init (anything-funcall-foreach 'init))
1243 (unless no-update (anything-update)))
1245 (defvar anything-compile-source-functions
1246 '(anything-compile-source--type
1247 anything-compile-source--dummy
1248 anything-compile-source--disable-shortcuts
1249 anything-compile-source--candidates-in-buffer)
1250 "Functions to compile elements of `anything-sources' (plug-in).")
1252 (defun anything-get-sources ()
1253 "Return compiled `anything-sources', which is memoized.
1258 `anything-type-attributes' are merged in.
1260 candidates, volatile and match attrubute are created."
1263 ((anything-action-window)
1266 (anything-compiled-sources)
1270 (setq anything-compiled-sources
1271 (anything-compile-sources
1272 anything-sources anything-compile-source-functions))
1273 (anything-log-eval anything-compiled-sources)))))
1275 (defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
1276 "Return the currently selected item or nil.
1277 if BUFFER is nil or unspecified, use anything-buffer as default value.
1278 If FORCE-DISPLAY-PART is non-nil, return the display string."
1279 (setq buffer (if (and buffer buffer-s) buffer anything-buffer))
1280 (unless (anything-empty-buffer-p buffer)
1281 (with-current-buffer buffer
1283 (or (and (not force-display-part)
1284 (get-text-property (overlay-start
1285 anything-selection-overlay)
1286 'anything-realvalue))
1287 (let ((disp (buffer-substring-no-properties
1288 (overlay-start anything-selection-overlay)
1289 (1- (overlay-end anything-selection-overlay))))
1290 (source (anything-get-current-source)))
1291 (anything-aif (and (not force-display-part)
1292 (assoc-default 'display-to-real source))
1293 (anything-funcall-with-source source it disp)
1295 (unless (equal selection "")
1296 (anything-log-eval selection)
1299 (defun anything-get-action ()
1300 "Return the associated action for the selected candidate.
1301 It is a function symbol \(sole action\) or list
1302 of \(action-display . function\)."
1303 (unless (anything-empty-buffer-p (anything-buffer-get))
1304 (anything-aif (anything-attr 'action-transformer)
1305 (anything-composed-funcall-with-source
1306 (anything-get-current-source) it
1307 (anything-attr 'action) (anything-get-selection))
1308 (anything-attr 'action))))
1310 (defun anything-get-current-source ()
1311 "Return the source for the current selection.
1312 Use it in init, candidates, action, candidate-transformer,
1313 filtered-candidate-transformer functions."
1314 (declare (special source))
1315 ;; The name `anything-get-current-source' should be used in init function etc.
1316 (if (and (boundp 'anything-source-name) (stringp anything-source-name))
1318 (with-current-buffer (anything-buffer-get)
1319 (or (get-text-property (point) 'anything-source)
1321 ;; This goto-char shouldn't be necessary, but point is moved to
1322 ;; point-min somewhere else which shouldn't happen.
1323 (goto-char (overlay-start anything-selection-overlay))
1324 (let* ((header-pos (or (anything-get-previous-header-pos)
1325 (anything-get-next-header-pos)))
1329 ;(message "No candidates")
1330 (return-from exit nil))
1331 (goto-char header-pos)
1332 (anything-current-line-contents))))
1333 (some (lambda (source)
1334 (if (equal (assoc-default 'name source) source-name)
1336 (anything-get-sources))))))))
1338 (defun anything-buffer-is-modified (buffer)
1339 "Return non-nil when BUFFER is modified since `anything' was invoked."
1340 (let* ((b (get-buffer buffer))
1341 (key (concat (buffer-name b) "/" (anything-attr 'name)))
1342 (source-tick (or (gethash key anything-tick-hash) 0))
1343 (buffer-tick (buffer-chars-modified-tick b))
1344 (modifiedp (/= source-tick buffer-tick)))
1345 (puthash key buffer-tick anything-tick-hash)
1346 (anything-log-eval buffer modifiedp)
1349 (defun anything-current-buffer-is-modified ()
1350 "Check if `anything-current-buffer' is modified since `anything' was invoked."
1351 (anything-buffer-is-modified anything-current-buffer))
1353 (defvar anything-quit nil)
1354 (defun anything-run-after-quit (function &rest args)
1355 "Perform an action after quitting `anything'.
1356 The action is to call FUNCTION with arguments ARGS."
1357 (setq anything-quit t)
1358 (anything-log-eval function args)
1359 (apply 'run-with-idle-timer 0 nil function args)
1360 (anything-exit-minibuffer))
1363 (defun define-anything-type-attribute (type definition &optional doc)
1364 "Register type attribute of TYPE as DEFINITION with DOC.
1365 DOC is displayed in `anything-type-attributes' docstring.
1367 Use this function is better than setting `anything-type-attributes' directly."
1368 (loop for i in definition do
1369 ;; without `ignore-errors', error at emacs22
1370 (ignore-errors (setf i (delete nil i))))
1371 (anything-add-type-attribute type definition)
1372 (and doc (anything-document-type-attribute type doc))
1375 (defvaralias 'anything-attributes 'anything-additional-attributes)
1376 (defvar anything-additional-attributes nil
1377 "List of all `anything' attributes.")
1378 (defun anything-document-attribute (attribute short-doc &optional long-doc)
1379 "Register ATTRIBUTE documentation introduced by plug-in.
1380 SHORT-DOC is displayed beside attribute name.
1381 LONG-DOC is displayed below attribute name and short documentation."
1382 (declare (indent 2) (debug t))
1384 (setq short-doc (concat "(" short-doc ")"))
1385 (setq long-doc short-doc
1387 (add-to-list 'anything-additional-attributes attribute t)
1388 (put attribute 'anything-attrdoc
1389 (concat "- " (symbol-name attribute)
1390 " " short-doc "\n\n" long-doc "\n")))
1393 (defun anything-interpret-value (value &optional source)
1394 "Interpret VALUE as variable, function or literal.
1395 If VALUE is a function, call it with no arguments and return the value.
1396 If SOURCE is `anything' source, `anything-source-name' is source name.
1398 If VALUE is a variable, return the value.
1400 If VALUE is a symbol, but it is not a function or a variable, cause an error.
1402 Otherwise, return VALUE itself."
1403 (cond ((and source (functionp value))
1404 (anything-funcall-with-source source value))
1407 ((and (symbolp value) (boundp value))
1408 (symbol-value value))
1410 (error "anything-interpret-value: Symbol must be a function or a variable"))
1414 (defun anything-once (function &rest args)
1415 "Ensure FUNCTION with ARGS to be called once in `anything' session."
1416 (let ((spec (cons function args)))
1417 (unless (member spec anything-once-called-functions)
1418 (apply function args)
1419 (push spec anything-once-called-functions))))
1421 ;; (@* "Core: API helper")
1422 (defun* anything-empty-buffer-p (&optional (buffer anything-buffer))
1423 "Check if BUFFER have candidates.
1424 Default value for BUFFER is `anything-buffer'."
1425 (zerop (buffer-size (and buffer (get-buffer buffer)))))
1427 (defun anything-let-eval-varlist (varlist)
1428 "Return the list of pairs VARLIST with each cdr of pair evaluated.
1429 If VARLIST contain single elements, those are returned
1430 as a list of one element."
1431 (mapcar (lambda (pair)
1433 (cons (car pair) (eval (cadr pair)))
1438 ;; (defun anything-let*-eval-varlist (varlist)
1439 ;; (let ((vars (mapcar (lambda (pair)
1440 ;; (or (car-safe pair) pair))
1442 ;; (eval `(let ,vars
1443 ;; ,@(mapcar (lambda (pair)
1445 ;; `(setq ,(car pair) ,(cadr pair))
1446 ;; `(setq ,pair nil)))
1448 ;; (mapcar (lambda (v)
1449 ;; (cons v (symbol-value v)))
1452 (defun anything-let-internal (binding bodyfunc)
1453 "Set BINDING to anything buffer-local variables and Evaluate BODYFUNC.
1454 BINDING is a list of \(VARNAME . VALUE\) pair."
1455 (setq anything-let-variables binding)
1458 (setq anything-let-variables nil)))
1461 ;; (@* "Core: tools")
1462 (defun anything-current-line-contents ()
1463 "Current line string without properties."
1464 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1466 (defun anything-funcall-with-source (source func &rest args)
1467 "Call from SOURCE FUNC with ARGS.
1468 FUNC can be a function list.
1469 Return the result of last function call."
1470 (let ((anything-source-name (assoc-default 'name source))
1472 (anything-log-eval anything-source-name func args)
1473 (dolist (func (if (functionp func) (list func) func) result)
1474 (setq result (apply func args)))))
1476 (defun anything-funcall-foreach (sym)
1477 "Call the SYM function\(s\) for each source if any."
1478 (dolist (source (anything-get-sources))
1479 (anything-aif (assoc-default sym source)
1480 (anything-funcall-with-source source it))))
1482 (defun anything-normalize-sources (sources)
1483 "If SOURCES is only one source, make a list."
1484 (cond ((or (and sources ; avoid nil
1486 (and (listp sources) (assq 'name sources)))
1489 (t anything-sources)))
1491 (defun anything-approximate-candidate-number (&optional in-current-source)
1492 "Return approximate number of candidates in `anything-buffer'.
1493 If IN-CURRENT-SOURCE is provided return number of candidates
1494 in the source where point is.
1495 It is used to check if candidate number is 0, 1, or 2+."
1496 (with-current-buffer anything-buffer
1498 (if in-current-source
1499 (goto-char (anything-get-previous-header-pos))
1500 (goto-char (point-min)))
1502 (let ((count-multi 1))
1503 (if (anything-pos-multiline-p)
1505 (loop while (and (not (if in-current-source
1508 (or (anything-pos-header-line-p) (eobp)))
1510 (search-forward anything-candidate-separator nil t))
1511 do (incf count-multi)
1512 finally return count-multi))
1515 while (not (if in-current-source
1516 (or (anything-pos-header-line-p) (eobp))
1518 unless (anything-pos-header-line-p)
1520 do (forward-line 1) finally return ln)))))))
1522 (defmacro with-anything-quittable (&rest body)
1523 "If an error occur in execution of BODY, quit anything safely."
1524 (declare (indent 0) (debug t))
1525 `(let (inhibit-quit)
1528 (quit (setq anything-quit t)
1532 (defun anything-compose (arg-lst func-lst)
1533 "Apply arguments specified in ARG-LST with each function of FUNC-LST.
1534 The result of each function will be the new `car' of ARG-LST.
1536 This function allows easy sequencing of transformer functions."
1537 (dolist (func func-lst)
1538 (setcar arg-lst (apply func arg-lst)))
1541 (defun anything-composed-funcall-with-source (source funcs &rest args)
1542 "With SOURCE apply `anything-funcall-with-source' with each FUNCS and ARGS.
1543 This is used in transformers to modify candidates list."
1544 (if (functionp funcs)
1545 (apply 'anything-funcall-with-source source funcs args)
1546 (apply 'anything-funcall-with-source source
1547 (lambda (&rest args)
1548 (anything-compose args funcs))
1551 (defun anything-new-timer (variable timer)
1552 "Give VARIABLE value to TIMER and cancel old timer."
1553 (anything-aif (symbol-value variable)
1555 (set variable timer))
1557 ;; (@* "Core: entry point")
1558 (defconst anything-argument-keys
1559 '(:sources :input :prompt :resume :preselect :buffer :keymap :default))
1562 (defun anything (&rest plist)
1563 "Main function to execute anything sources.
1564 When call interactively with no arguments deprecated `anything-sources'
1565 will be used if non--nil.
1567 PLIST is a list like \(:key1 val1 :key2 val2 ...\) or
1568 \(&optional sources input prompt resume preselect buffer keymap\).
1570 Basic keywords are the following:
1574 Temporary value of `anything-sources'. It also accepts a
1575 symbol, interpreted as a variable of an anything source. It
1576 also accepts an alist representing an anything source, which is
1577 detected by \(assq 'name ANY-SOURCES\)
1581 Temporary value of `anything-pattern', ie. initial input of minibuffer.
1585 Prompt other than \"pattern: \".
1589 If t, Resurrect previously instance of `anything'. Skip the initialization.
1590 If 'noresume, this instance of `anything' cannot be resumed.
1594 Initially selected candidate. Specified by exact candidate or a regexp.
1595 Note that it is not working with delayed sources.
1599 `anything-buffer' instead of *anything*.
1603 `anything-map' for current `anything' session.
1607 A default argument that will be inserted in minibuffer with \
1608 \\<minibuffer-local-map>\\[next-history-element].
1609 When nil of not present `thing-at-point' will be used instead.
1611 Of course, conventional arguments are supported, the two are same.
1613 \(anything :sources sources :input input :prompt prompt :resume resume
1614 :preselect preselect :buffer buffer :keymap keymap\)
1615 \(anything sources input prompt resume preselect buffer keymap\)
1618 Other keywords are interpreted as local variables of this anything session.
1619 The `anything-' prefix can be omitted. For example,
1621 \(anything :sources 'anything-c-source-buffers
1622 :buffer \"*buffers*\" :candidate-number-limit 10\)
1624 means starting anything session with `anything-c-source-buffers'
1625 source in *buffers* buffer and set variable `anything-candidate-number-limit'
1626 to 10 as session local variable."
1628 (if (keywordp (car plist))
1629 (anything-let-internal
1630 (anything-parse-keys plist)
1633 (mapcar (lambda (key) (plist-get plist key))
1634 anything-argument-keys))))
1635 (apply 'anything-internal plist)))
1637 (defun* anything-resume (&optional
1638 (any-buffer anything-last-buffer)
1639 buffer-pattern (any-resume t))
1640 "Resurrect previously invoked `anything'.
1641 Called with a prefix arg, allow choosing among all existing
1642 anything buffers. i.e choose among various anything sessions."
1644 (when (or current-prefix-arg buffer-pattern)
1645 (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
1646 (setq anything-compiled-sources nil)
1648 (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
1649 anything-last-sources anything-sources)
1650 (buffer-local-value 'anything-input-local (get-buffer any-buffer))
1651 nil any-resume nil any-buffer))
1653 ;;; rubikitch: experimental
1654 ;;; I use this and check it whether I am convenient.
1655 ;;; I may introduce an option to control the behavior.
1656 (defun* anything-resume-window-only (&optional
1657 (any-buffer anything-last-buffer)
1660 (anything-resume any-buffer buffer-pattern 'window-only))
1663 (defun anything-at-point (&optional
1664 any-sources any-input
1665 any-prompt any-resume
1666 any-preselect any-buffer)
1667 "Call anything with symbol at point as initial input.
1668 ANY-SOURCES ANY-INPUT ANY-PROMPT ANY-RESUME ANY-PRESELECT and ANY-BUFFER
1669 are same args as in `anything'."
1671 (anything any-sources
1672 (if current-prefix-arg
1673 (concat "\\b" (thing-at-point 'symbol) "\\b"
1674 (if (featurep 'anything-match-plugin) " " ""))
1676 any-prompt any-resume any-preselect any-buffer))
1679 (defun anything-other-buffer (any-sources any-buffer)
1680 "Simplified interface of `anything' with other `anything-buffer'.
1681 Call `anything' with only ANY-SOURCES and ANY-BUFFER as args."
1682 (anything any-sources nil nil nil nil any-buffer))
1684 ;;; (@* "Core: entry point helper")
1685 (defun anything-internal (&optional
1686 any-sources any-input
1687 any-prompt any-resume
1688 any-preselect any-buffer
1689 any-keymap any-default)
1690 "The internal anything function called by `anything'.
1691 For ANY-SOURCES ANY-INPUT ANY-PROMPT ANY-RESUME ANY-PRESELECT ANY-BUFFER and
1692 ANY-KEYMAP See `anything'."
1693 (anything-log "++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
1694 (anything-log-eval any-prompt any-preselect any-buffer any-keymap any-default)
1697 (let ( ;; It is needed because `anything-source-name' is non-nil
1698 ;; when `anything' is invoked by action. Awful global scope.
1699 anything-source-name
1700 anything-in-persistent-action
1702 (case-fold-search t)
1703 (anything-buffer (or any-buffer anything-buffer))
1704 ;; cua-mode ; avoid error when region is selected
1706 (with-anything-restore-variables
1707 (anything-initialize any-resume any-input any-sources)
1708 (anything-display-buffer anything-buffer)
1709 (anything-log "show prompt")
1711 (anything-read-pattern-maybe
1712 any-prompt any-input any-preselect any-resume any-keymap any-default)
1713 (anything-cleanup)))
1714 (prog1 (unless anything-quit (anything-execute-selection-action-1))
1715 (anything-log "end session --------------------------------------------")))
1718 (anything-log "end session (quit) -------------------------------------")
1720 (anything-log-save-maybe)))
1722 (defun anything-parse-keys (keys)
1723 "Parse the KEYS arguments of `anything'."
1724 (loop for (key value &rest _) on keys by #'cddr
1725 for symname = (substring (symbol-name key) 1)
1726 for sym = (intern (if (string-match "^anything-" symname)
1728 (concat "anything-" symname)))
1729 unless (memq key anything-argument-keys)
1730 collect (cons sym value)))
1732 (defun anything-resume-p (any-resume)
1733 "Whether current anything session is resumed or not.
1734 Just check if ANY-RESUME value is t or window-only."
1735 (memq any-resume '(t window-only)))
1737 (defvar anything-buffers nil
1738 "All of `anything-buffer' in most recently used order.")
1739 (defun anything-initialize (any-resume any-input any-sources)
1740 "Start initialization of `anything' session.
1741 For ANY-RESUME ANY-INPUT and ANY-SOURCES See `anything'."
1742 (anything-log "start initialization: any-resume=%S any-input=%S" any-resume any-input)
1743 (anything-frame-or-window-configuration 'save)
1744 (setq anything-sources (anything-normalize-sources any-sources))
1745 (anything-log "sources = %S" anything-sources)
1746 (anything-hooks 'setup)
1747 (anything-current-position 'save)
1748 (if (anything-resume-p any-resume)
1749 (anything-initialize-overlays (anything-buffer-get))
1750 (anything-initial-setup))
1751 (unless (eq any-resume 'noresume)
1752 (anything-recent-push anything-buffer 'anything-buffers)
1753 (setq anything-last-buffer anything-buffer))
1754 (when any-input (setq anything-input any-input anything-pattern any-input))
1755 (and (anything-resume-p any-resume) (anything-funcall-foreach 'resume))
1756 (anything-log "end initialization"))
1758 ;; Here defun* allow using implicit block `anything-execute-selection-action-1'.
1759 (defun* anything-execute-selection-action-1 ()
1760 "Execute current action."
1761 (anything-log-run-hook 'anything-before-action-hook)
1763 (anything-execute-selection-action)
1764 (anything-aif (get-buffer anything-action-buffer)
1766 (anything-log-run-hook 'anything-after-action-hook)))
1768 (defun anything-on-quit ()
1769 "Save `minibuffer-history' and current position."
1770 (setq minibuffer-history (cons anything-input minibuffer-history))
1771 (anything-current-position 'restore))
1773 (defun anything-resume-select-buffer (input)
1774 "Resume precedent anything session with initial input INPUT."
1775 (anything '(((name . "Resume anything buffer")
1776 (candidates . anything-buffers)
1777 (action . identity)))
1778 input nil 'noresume nil "*anything resume*"))
1780 (defun anything-recent-push (elt list-var)
1781 "Add ELT to the value of LIST-VAR as most recently used value."
1782 (let ((m (member elt (symbol-value list-var))))
1783 (and m (set list-var (delq (car m) (symbol-value list-var))))
1784 (push elt (symbol-value list-var))))
1786 ;;; (@* "Core: Accessors")
1787 ;;; rubikitch: I love to create functions to control variables.
1788 (defvar anything-current-position nil
1789 "Cons of \(point . window-start\) when `anything' is invoked.
1790 It is needed to restore position in `anything-current-buffer'
1791 when `anything' is keyboard-quitted.")
1792 (defun anything-current-position (save-or-restore)
1793 "Restore or save current position in `anything-current-buffer'.
1794 Argument SAVE-OR-RESTORE is one of save or restore."
1795 (case save-or-restore
1797 (anything-log "Save position at %S" (cons (point) (window-start)))
1798 (setq anything-current-position (cons (point) (window-start))))
1800 (anything-log "Restore position at %S in buffer %s"
1801 anything-current-position
1802 (buffer-name (current-buffer)))
1803 (goto-char (car anything-current-position))
1804 ;; Fix this position with the NOFORCE arg of `set-window-start'
1805 ;; otherwise, if there is some other buffer than `anything-current-buffer'
1806 ;; one, position will be lost.
1807 (set-window-start (selected-window) (cdr anything-current-position) t))))
1811 (defvar anything-last-frame-or-window-configuration nil
1812 "Used to store window or frame configuration when anything start.")
1813 (defun anything-frame-or-window-configuration (save-or-restore)
1814 "Save or restore last frame or window configuration.
1815 Possible value of SAVE-OR-RESTORE are 'save and 'restore.
1816 window or frame configuration is saved/restored according to values of
1817 `anything-save-configuration-functions'."
1818 (anything-log-eval anything-save-configuration-functions)
1819 (case save-or-restore
1820 (save (setq anything-last-frame-or-window-configuration
1821 (funcall (cdr anything-save-configuration-functions))))
1822 (restore (funcall (car anything-save-configuration-functions)
1823 anything-last-frame-or-window-configuration)
1824 ;; Restore frame focus.
1825 (let ((frame (and (listp anything-last-frame-or-window-configuration)
1826 (caadr anything-last-frame-or-window-configuration))))
1827 ;; If `anything-save-configuration-functions' are window functions
1828 ;; frame should be nil, use current frame.
1829 (unless (framep frame)
1830 (setq frame (selected-frame)))
1831 (select-frame-set-input-focus frame)))))
1834 ;; (@* "Core: Display *anything* buffer")
1835 (defun anything-display-buffer (buf)
1836 "Display *anything* buffer BUF."
1837 (let (pop-up-frames)
1838 (funcall (with-current-buffer buf anything-display-function) buf)))
1840 (defun anything-default-display-buffer (buf)
1841 "Default function to display BUF.
1842 Where BUF is generally `anything-buffer'.
1843 It use `switch-to-buffer' or `pop-to-buffer' depending of value of
1844 `anything-samewindow'."
1845 (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
1847 ;; (@* "Core: initialize")
1848 (defun anything-initial-setup ()
1849 "Initialize anything settings and set up the anything buffer."
1850 (anything-log-run-hook 'anything-before-initialize-hook)
1851 (setq anything-current-prefix-arg nil)
1852 (setq anything-once-called-functions nil)
1853 (setq anything-delayed-init-executed nil)
1854 (setq anything-current-buffer
1855 (if (minibuffer-window-active-p (minibuffer-window))
1856 ;; If minibuffer is active be sure to use it's buffer
1857 ;; as `anything-current-buffer'.
1858 (window-buffer (active-minibuffer-window))
1860 (setq anything-buffer-file-name buffer-file-name)
1861 (setq anything-issued-errors nil)
1862 (setq anything-compiled-sources nil)
1863 (setq anything-saved-current-source nil)
1864 (if (or (not split-width-threshold)
1865 (and (integerp split-width-threshold)
1866 (>= split-width-threshold (+ (frame-width) 4))))
1867 (setq anything-split-window-state 'vertical)
1868 (setq anything-split-window-state 'horizontal))
1869 ;; Call the init function for sources where appropriate
1870 (anything-funcall-foreach 'init)
1871 (setq anything-pattern "")
1872 (setq anything-input "")
1873 (setq anything-candidate-cache nil)
1874 (setq anything-last-sources anything-sources)
1875 (anything-create-anything-buffer)
1876 (anything-log-run-hook 'anything-after-initialize-hook))
1878 (defvar anything-reading-pattern nil
1879 "Whether in `read-string' in anything or not.")
1880 (defun anything-read-pattern-maybe (any-prompt any-input
1881 any-preselect any-resume any-keymap any-default)
1882 "Read pattern with prompt ANY-PROMPT and initial input ANY-INPUT.
1883 For ANY-PRESELECT ANY-RESUME ANY-KEYMAP, See `anything'."
1884 (if (anything-resume-p any-resume)
1885 (anything-mark-current-line)
1886 (anything-update any-preselect))
1887 (with-current-buffer (anything-buffer-get)
1888 (and any-keymap (set (make-local-variable 'anything-map) any-keymap))
1889 (let ((minibuffer-local-map
1891 (anything-log-eval (anything-approximate-candidate-number)
1892 anything-execute-action-at-once-if-one
1893 anything-quit-if-no-candidate)
1894 (cond ((and anything-execute-action-at-once-if-one
1895 (= (anything-approximate-candidate-number) 1))
1897 ((and anything-quit-if-no-candidate
1898 (= (anything-approximate-candidate-number) 0))
1899 (setq anything-quit t)
1900 (and (functionp anything-quit-if-no-candidate)
1901 (funcall anything-quit-if-no-candidate)))
1903 (let ((anything-reading-pattern t)
1904 (tap (or any-default
1905 (with-anything-current-buffer
1906 (thing-at-point 'symbol)))))
1907 (read-string (or any-prompt "pattern: ") any-input nil tap)))))))
1909 (defun anything-create-anything-buffer (&optional test-mode)
1910 "Create newly created `anything-buffer'.
1911 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
1913 (setq anything-candidate-cache nil))
1914 (with-current-buffer (get-buffer-create anything-buffer)
1915 (anything-log "kill local variables: %S" (buffer-local-variables))
1916 (kill-all-local-variables)
1917 (set (make-local-variable 'inhibit-read-only) t)
1918 (buffer-disable-undo)
1920 (set (make-local-variable 'inhibit-read-only) t)
1921 (set (make-local-variable 'anything-last-sources-local) anything-sources)
1922 (set (make-local-variable 'anything-follow-mode) nil)
1923 (set (make-local-variable 'anything-display-function) anything-display-function)
1924 (anything-initialize-persistent-action)
1925 (anything-log-eval anything-display-function anything-let-variables)
1926 (loop for (var . val) in anything-let-variables
1927 do (set (make-local-variable var) val))
1928 (setq cursor-type nil)
1929 (setq mode-name "Anything"))
1930 (anything-initialize-overlays anything-buffer)
1931 (get-buffer anything-buffer))
1933 (defun anything-initialize-overlays (buffer)
1934 "Initialize anything overlays in BUFFER."
1935 (anything-log "overlay setup")
1936 (if anything-selection-overlay
1937 ;; make sure the overlay belongs to the anything buffer if
1938 ;; it's newly created
1939 (move-overlay anything-selection-overlay (point-min) (point-min)
1940 (get-buffer buffer))
1942 (setq anything-selection-overlay
1943 (make-overlay (point-min) (point-min) (get-buffer buffer)))
1944 (overlay-put anything-selection-overlay 'face anything-selection-face))
1946 (cond (anything-enable-shortcuts
1947 (setq anything-shortcut-keys
1948 (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist))
1949 (unless anything-digit-overlays
1950 (setq anything-digit-overlays
1951 (loop for key across anything-shortcut-keys
1952 for overlay = (make-overlay (point-min) (point-min)
1953 (get-buffer buffer))
1954 do (overlay-put overlay 'before-string
1955 (format "%s - " (upcase (make-string 1 key))))
1957 (anything-digit-overlays
1958 (mapc 'delete-overlay anything-digit-overlays)
1959 (setq anything-digit-overlays nil))))
1961 (defun anything-hooks (setup-or-cleanup)
1962 "Add or remove hooks according to SETUP-OR-CLEANUP value.
1963 if SETUP-OR-CLEANUP value is setup add hooks, any other value
1965 hooks concerned are `post-command-hook' and `minibuffer-setup-hook'."
1966 (let ((hooks '((post-command-hook anything-check-minibuffer-input)
1967 (minibuffer-setup-hook anything-print-error-messages))))
1968 (if (eq setup-or-cleanup 'setup)
1969 (dolist (args hooks) (apply #'(lambda (h f) (add-hook h f t)) args))
1970 (dolist (args (reverse hooks)) (apply 'remove-hook args)))))
1972 ;; (@* "Core: clean up")
1974 (defun anything-cleanup ()
1975 "Clean up the mess when anything exit or quit."
1976 (anything-log "start cleanup")
1977 (with-current-buffer anything-buffer
1978 (setq cursor-type t)
1979 ;; Call burry-buffer whithout arg
1980 ;; to remove anything-buffer from window.
1982 ;; Be sure we call this from anything-buffer.
1983 (anything-funcall-foreach 'cleanup))
1984 (anything-new-timer 'anything-check-minibuffer-input-timer nil)
1985 (anything-kill-async-processes)
1986 (anything-log-run-hook 'anything-cleanup-hook)
1987 (anything-hooks 'cleanup)
1988 (anything-frame-or-window-configuration 'restore)
1989 ;; This is needed in some cases where last input
1990 ;; is yielded infinitely in minibuffer after anything session.
1991 (anything-clean-up-minibuffer))
1993 (defun anything-clean-up-minibuffer ()
1994 "Remove contents of minibuffer."
1995 (let ((miniwin (minibuffer-window)))
1996 ;; Clean only current minibuffer used by anything.
1997 ;; i.e The precedent one is active.
1998 (unless (minibuffer-window-active-p miniwin)
1999 (with-current-buffer (window-buffer miniwin)
2000 (delete-minibuffer-contents)))))
2002 ;; (@* "Core: input handling")
2003 (defun anything-check-minibuffer-input ()
2004 "Extract input string from the minibuffer and check if it needs to be handled."
2005 (let ((delay (with-current-buffer anything-buffer anything-input-idle-delay)))
2006 (if (or (not delay) (anything-action-window))
2007 (anything-check-minibuffer-input-1)
2009 'anything-check-minibuffer-input-timer
2010 (run-with-idle-timer delay nil 'anything-check-minibuffer-input-1)))))
2012 (defun anything-check-minibuffer-input-1 ()
2013 "Check minibuffer content."
2014 (with-anything-quittable
2015 (with-selected-window (or (active-minibuffer-window) (minibuffer-window))
2016 (anything-check-new-input (minibuffer-contents)))))
2018 (defun anything-check-new-input (input)
2019 "Check INPUT string and update the anything buffer if necessary."
2020 (unless (equal input anything-pattern)
2021 (setq anything-pattern input)
2022 (unless (anything-action-window)
2023 (setq anything-input anything-pattern))
2024 (anything-log-eval anything-pattern anything-input)
2027 ;; (@* "Core: source compiler")
2028 (defvar anything-compile-source-functions-default anything-compile-source-functions
2029 "Plug-ins this file provides.")
2030 (defun anything-compile-sources (sources funcs)
2031 "Compile SOURCES with FUNCS.
2032 See `anything-compile-source-functions'.
2033 Anything plug-ins are realized by this function."
2036 (loop with source = (if (listp source) source (symbol-value source))
2038 do (setq source (funcall f source))
2039 finally (return source)))
2042 ;; (@* "Core: plug-in attribute documentation hack")
2044 ;; `anything-document-attribute' is public API.
2045 (defadvice documentation-property (after anything-document-attribute activate)
2046 "Display plug-in attributes' documentation as `anything-sources' docstring."
2047 (when (eq (ad-get-arg 0) 'anything-sources)
2048 (setq ad-return-value
2049 (concat ad-return-value "\n"
2050 (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
2051 anything-additional-attributes
2053 ;; (describe-variable 'anything-sources)
2054 ;; (documentation-property 'anything-sources 'variable-documentation)
2055 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
2057 ;; (@* "Core: all candidates")
2058 (defun anything-process-delayed-init (source)
2059 "Initialize delayed SOURCE."
2060 (let ((name (assoc-default 'name source)))
2061 (unless (member name anything-delayed-init-executed)
2062 (anything-aif (assoc-default 'delayed-init source)
2063 (with-current-buffer anything-current-buffer
2064 (anything-funcall-with-source source it)
2065 (dolist (f (if (functionp it) (list it) it))
2066 (add-to-list 'anything-delayed-init-executed name)))))))
2068 (defun anything-get-candidates (source)
2069 "Retrieve and return the list of candidates from SOURCE."
2070 (anything-process-delayed-init source)
2071 (let* ((candidate-source (assoc-default 'candidates source))
2072 (type-error (lambda ()
2073 (error (concat "Candidates must either be a function, "
2074 " a variable or a list: %s")
2076 (candidates (condition-case err
2077 (anything-interpret-value candidate-source source)
2078 (error (funcall type-error)))))
2079 (cond ((processp candidates) candidates)
2080 ((listp candidates) (anything-transform-candidates candidates source))
2081 (t (funcall type-error)))))
2084 (defun anything-get-cached-candidates (source)
2085 "Return the cached value of candidates for SOURCE.
2086 Cache the candidates if there is not yet a cached value."
2087 (let* ((name (assoc-default 'name source))
2088 (candidate-cache (assoc name anything-candidate-cache)))
2089 (cond (candidate-cache
2090 (anything-log "use cached candidates")
2091 (cdr candidate-cache))
2093 (anything-log "calculate candidates")
2094 (let ((candidates (anything-get-candidates source)))
2095 (cond ((processp candidates)
2096 (push (cons candidates
2098 (list (cons 'item-count 0)
2099 (cons 'incomplete-line ""))))
2100 anything-async-processes)
2101 (set-process-filter candidates 'anything-output-filter)
2102 (setq candidates nil))
2103 ((not (assoc 'volatile source))
2104 (setq candidate-cache (cons name candidates))
2105 (push candidate-cache anything-candidate-cache)))
2108 ;;; (@* "Core: candidate transformers")
2109 (defun anything-process-candidate-transformer (candidates source)
2110 "Execute candidate-transformer function on all CANDIDATES of SOURCE."
2111 (anything-aif (assoc-default 'candidate-transformer source)
2112 (anything-composed-funcall-with-source source it candidates)
2115 (defun anything-process-filtered-candidate-transformer (candidates source)
2116 "Execute filtered-candidate-transformer function on all CANDIDATES of SOURCE."
2117 (anything-aif (assoc-default 'filtered-candidate-transformer source)
2118 (anything-composed-funcall-with-source source it candidates source)
2121 (defun anything-process-filtered-candidate-transformer-maybe (candidates source process-p)
2122 "Execute filtered-candidate-transformer function on all CANDIDATES of SOURCE.
2123 This happen if PROCESS-P is non-nil."
2125 (anything-process-filtered-candidate-transformer candidates source)
2128 (defun anything-process-real-to-display (candidates source)
2129 "Execute real-to-display function on all CANDIDATES of SOURCE."
2130 (anything-aif (assoc-default 'real-to-display source)
2131 (setq candidates (anything-funcall-with-source
2135 ;; override DISPLAY from candidate-transformer
2136 (cons (funcall it (cdr cand_)) (cdr cand_))
2137 (cons (funcall it cand_) cand_)))
2141 (defun anything-transform-candidates (candidates source &optional process-p)
2142 "Transform CANDIDATES of SOURCE according to candidate transformers.
2143 This happen if PROCESS-P is non-nil."
2144 (anything-process-real-to-display
2145 (anything-process-filtered-candidate-transformer-maybe
2146 (anything-process-candidate-transformer candidates source) source process-p)
2149 ;; (@* "Core: narrowing candidates")
2150 (defun anything-candidate-number-limit (source)
2151 "Apply candidate-number-limit attribute value.
2152 This overhide variable `anything-candidate-number-limit'.
2155 If \(candidate-number-limit\) is in SOURCE, show all candidates in SOURCE.
2156 If \(candidate-number-limit . 123\) is in SOURCE limit candidate to 123."
2157 (anything-aif (assq 'candidate-number-limit source)
2158 (or (cdr it) 99999999)
2159 (or anything-candidate-number-limit 99999999)))
2161 ;; FIXME: Why a defconst here
2162 (defconst anything-default-match-functions
2163 (list (lambda (candidate)
2164 (string-match anything-pattern candidate)))
2165 "Default functions to match candidates according to `anything-pattern'.")
2167 (defun anything-compute-matches (source)
2168 "Compute matched results from SOURCE according to its settings."
2170 (anything-compute-matches-internal source)
2172 (anything-compute-matches-internal source)
2173 (error (anything-log-error
2174 "anything-compute-matches: error when processing source: %s"
2175 (assoc-default 'name source))
2178 (defun anything-candidate-get-display (candidate)
2179 "Get searched display part from CANDIDATE.
2180 CANDIDATE is a string, a symbol, or \(DISPLAY . REAL\) cons cell."
2181 (format "%s" (or (car-safe candidate) candidate)))
2183 (defun anything-process-pattern-transformer (pattern source)
2184 "Execute pattern-transformer attribute PATTERN function in SOURCE."
2185 (anything-aif (assoc-default 'pattern-transformer source)
2186 (anything-composed-funcall-with-source source it pattern)
2189 (defun anything-match-functions (source)
2190 (or (assoc-default 'match source)
2191 anything-default-match-functions))
2193 (defmacro anything-accumulate-candidates-internal (cand newmatches
2194 hash item-count limit)
2195 "Internal, add CAND into NEWMATCHES.
2196 Use HASH to uniq NEWMATCHES.
2197 Argument ITEM-COUNT count the matches.
2198 if ITEM-COUNT reaches LIMIT, exit from inner loop."
2199 `(unless (gethash ,cand ,hash)
2200 (puthash ,cand t ,hash)
2201 (push ,cand ,newmatches)
2203 (when (= ,item-count ,limit)
2207 (defun anything-take-first-elements (seq n)
2208 (if (> (length seq) n)
2209 (setq seq (subseq seq 0 n))
2212 (defun anything-match-from-candidates (cands matchfns limit)
2215 (let ((item-count 0) exit)
2216 (clrhash anything-match-hash)
2217 (dolist (match matchfns)
2219 (dolist (candidate cands)
2220 (when (funcall match (anything-candidate-get-display candidate))
2221 (anything-accumulate-candidates-internal
2222 candidate newmatches anything-match-hash item-count limit)))
2223 (setq matches (append matches (reverse newmatches)))
2224 (if exit (return)))))
2225 (invalid-regexp (setq matches nil)))
2228 (defun anything-compute-matches-internal (source)
2229 (save-current-buffer
2230 (let ((matchfns (anything-match-functions source))
2231 (anything-source-name (assoc-default 'name source))
2232 (limit (anything-candidate-number-limit source))
2233 (anything-pattern (anything-process-pattern-transformer
2234 anything-pattern source)))
2235 (anything-process-filtered-candidate-transformer
2236 (if (or (equal anything-pattern "") (equal matchfns '(identity)))
2237 (anything-take-first-elements
2238 (anything-get-cached-candidates source) limit)
2239 (anything-match-from-candidates
2240 (anything-get-cached-candidates source) matchfns limit))
2243 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2245 (defun anything-process-source (source)
2246 "Display matched results from SOURCE according to its settings."
2247 (anything-log-eval (assoc-default 'name source))
2248 (if (assq 'direct-insert-match source) ;experimental
2249 (anything-process-source--direct-insert-match source)
2250 (let ((matches (anything-compute-matches source)))
2252 (when anything-test-mode
2253 (setq anything-test-candidate-list
2254 `(,@anything-test-candidate-list
2255 (,(assoc-default 'name source)
2257 (anything-insert-header-from-source source)
2258 (if (not (assq 'multiline source))
2259 (mapc 'anything-insert-match-with-digit-overlay matches)
2260 (let ((start (point)) separate)
2261 (dolist (match matches)
2263 (anything-insert-candidate-separator)
2265 (anything-insert-match-with-digit-overlay match))
2266 (put-text-property start (point) 'anything-multiline t)))))))
2268 (defun anything-insert-match-with-digit-overlay (match)
2269 (declare (special source))
2270 (anything-put-digit-overlay-maybe)
2271 (anything-insert-match match 'insert source))
2273 (defun anything-put-digit-overlay-maybe ()
2274 (when (and anything-enable-shortcuts
2275 (not (eq anything-digit-shortcut-count
2276 (length anything-digit-overlays))))
2277 (move-overlay (nth anything-digit-shortcut-count
2278 anything-digit-overlays)
2281 (incf anything-digit-shortcut-count)))
2283 (defun anything-process-source--direct-insert-match (source)
2284 "[EXPERIMENTAL] Insert candidates from `anything-candidate-buffer' in SOURCE."
2285 (anything-log-eval (assoc-default 'name source))
2286 (let ((anything-source-name (assoc-default 'name source))
2288 (funcall (assoc-default 'candidates source))
2289 (setq content-buf (anything-candidate-buffer))
2290 (unless (anything-empty-buffer-p content-buf)
2291 (anything-insert-header-from-source source)
2292 (insert-buffer-substring content-buf)
2293 ;; TODO call anything-put-digit-overlay-maybe with loop
2296 (defun anything-process-delayed-sources (delayed-sources)
2297 "Process DELAYED-SOURCES when idle for `anything-idle-delay' seconds."
2298 (with-anything-quittable
2299 (anything-log-eval (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2300 (with-current-buffer anything-buffer
2302 (goto-char (point-max))
2303 (mapc 'anything-process-source delayed-sources)
2304 (when (and (not (anything-empty-buffer-p))
2306 (= (overlay-start anything-selection-overlay)
2307 (overlay-end anything-selection-overlay)))
2308 (goto-char (point-min))
2309 (anything-next-line)))
2311 (goto-char (point-min))
2312 (anything-log-run-hook 'anything-update-hook)))))
2314 ;; (@* "Core: *anything* buffer contents")
2315 (defvar anything-input-local nil)
2316 (defvar anything-process-delayed-sources-timer nil)
2317 (defun anything-update (&optional preselect)
2318 "Update candidates list in `anything-buffer' according to `anything-pattern'."
2319 (anything-log "start update")
2320 (setq anything-digit-shortcut-count 0)
2321 (anything-kill-async-processes)
2322 (with-current-buffer (anything-buffer-get)
2323 (set (make-local-variable 'anything-input-local) anything-pattern)
2325 (when anything-enable-shortcuts
2326 (mapc 'delete-overlay anything-digit-overlays))
2327 (let (delayed-sources)
2329 (setq delayed-sources
2330 (loop for source in (remove-if-not 'anything-update-source-p
2331 (anything-get-sources))
2332 if (anything-delayed-source-p source)
2334 else do (anything-process-source source)))
2336 (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2337 (anything-update-move-first-line)
2338 (if anything-test-mode
2339 (mapc 'anything-process-source delayed-sources)
2340 (when delayed-sources
2342 'anything-process-delayed-sources-timer
2343 (run-with-idle-timer
2344 anything-idle-delay nil
2345 'anything-process-delayed-sources delayed-sources)))
2346 ;; FIXME I want to execute anything-after-update-hook
2347 ;; AFTER processing delayed sources
2348 (anything-log-run-hook 'anything-after-update-hook))
2349 (and preselect (anything-preselect preselect))
2350 (anything-log "end update")))))
2352 (defun anything-update-source-p (source)
2353 (and (or (not anything-source-filter)
2354 (member (assoc-default 'name source) anything-source-filter))
2355 (>= (length anything-pattern)
2356 (anything-aif (assoc 'requires-pattern source)
2360 (defun anything-delayed-source-p (source)
2361 (or (assoc 'delayed source)
2362 (and anything-quick-update
2363 (< (window-height (get-buffer-window (current-buffer)))
2364 (line-number-at-pos (point-max))))))
2366 (defun anything-update-move-first-line ()
2367 (goto-char (point-min))
2368 (save-excursion (anything-log-run-hook 'anything-update-hook))
2369 (anything-next-line))
2371 (defun anything-force-update ()
2372 "Force recalculation and update of candidates.
2373 If current source has `update' attribute, a function without argument,
2374 call it before update."
2376 (let ((source (anything-get-current-source)))
2378 (anything-force-update--reinit source)
2379 (anything-erase-message)
2380 (mapc 'anything-force-update--reinit (anything-get-sources)))
2381 (let ((selection (anything-get-selection nil t)))
2383 (anything-keep-selection source selection))))
2385 (defun anything-force-update--reinit (source)
2386 (anything-aif (anything-funcall-with-source source 'anything-candidate-buffer)
2388 (dolist (attr '(update init))
2389 (anything-aif (assoc-default attr source)
2390 (anything-funcall-with-source source it)))
2391 (anything-remove-candidate-cache source))
2393 (defun anything-erase-message ()
2396 (defun anything-keep-selection (source selection)
2397 (when (and source selection)
2398 (with-anything-window
2399 (anything-goto-source source)
2400 (forward-char -1) ;back to \n
2401 (if (search-forward (concat "\n" selection "\n") nil t)
2403 (goto-char (point-min))
2405 (anything-mark-current-line))))
2407 (defun anything-remove-candidate-cache (source)
2408 (setq anything-candidate-cache
2409 (delete (assoc (assoc-default 'name source) anything-candidate-cache)
2410 anything-candidate-cache)))
2412 (defun anything-insert-match (match insert-function source)
2413 "Insert MATCH into `anything-buffer' with INSERT-FUNCTION for SOURCE.
2414 If MATCH is a list then insert the string intended to appear on the display
2415 and store the real value in a text property."
2416 (let ((start (point-at-bol (point)))
2417 (string (or (car-safe match) match))
2418 (realvalue (cdr-safe match)))
2419 (when (symbolp string) (setq string (symbol-name string)))
2420 (when (stringp string)
2421 (funcall insert-function string)
2422 ;; Some sources with candidates-in-buffer have already added
2423 ;; 'anything-realvalue property when creating candidate buffer.
2424 (unless (get-text-property start 'anything-realvalue)
2426 (put-text-property start (point-at-eol)
2427 'anything-realvalue realvalue)))
2428 (when anything-source-in-each-line-flag
2429 (put-text-property start (point-at-eol) 'anything-source source))
2430 (funcall insert-function "\n"))))
2432 (defun anything-insert-header-from-source (source)
2433 "Insert SOURCE name in `anything-buffer' header.
2434 Maybe insert by overlay additional info after source name if SOURCE have
2435 header-name attribute."
2436 (let ((name (assoc-default 'name source)))
2437 (anything-insert-header
2439 (anything-aif (assoc-default 'header-name source)
2440 (anything-funcall-with-source source it name)))))
2442 (defun anything-insert-header (name &optional display-string)
2443 "Insert header of source NAME into the anything buffer.
2444 If DISPLAY-STRING is non--nil and a string, display this additional info
2445 after the source name by overlay."
2447 (let ((start (point)))
2449 (put-text-property start (point) 'anything-header-separator t)))
2450 (let ((start (point)))
2452 (put-text-property (point-at-bol)
2453 (point-at-eol) 'anything-header t)
2454 (when display-string
2455 (overlay-put (make-overlay (point-at-bol) (point-at-eol))
2456 'display display-string))
2458 (put-text-property start (point) 'face anything-header-face)))
2460 (defun anything-insert-candidate-separator ()
2461 "Insert separator of candidates into the anything buffer."
2462 (insert anything-candidate-separator)
2463 (put-text-property (point-at-bol)
2464 (point-at-eol) 'anything-candidate-separator t)
2467 ;; (@* "Core: async process")
2468 (defun anything-output-filter (process string)
2469 "From PROCESS process output STRING."
2470 (anything-output-filter-1 (assoc process anything-async-processes) string))
2472 (defun anything-output-filter-1 (process-assoc string)
2473 (anything-log-eval string)
2474 (with-current-buffer anything-buffer
2475 (let ((source (cdr process-assoc)))
2477 (anything-aif (assoc-default 'insertion-marker source)
2479 (goto-char (point-max))
2480 (anything-insert-header-from-source source)
2481 (setcdr process-assoc
2482 (append source `((insertion-marker . ,(point-marker))))))
2483 (anything-output-filter--process-source
2484 (car process-assoc) string source
2485 (anything-candidate-number-limit source))))
2486 (anything-output-filter--post-process)))
2488 (defun anything-output-filter--process-source (process string source limit)
2489 (dolist (candidate (anything-transform-candidates
2490 (anything-output-filter--collect-candidates
2491 (split-string string "\n")
2492 (assoc 'incomplete-line source))
2494 (if (not (assq 'multiline source))
2495 (anything-insert-match candidate 'insert-before-markers source)
2496 (let ((start (point)))
2497 (anything-insert-candidate-separator)
2498 (anything-insert-match candidate 'insert-before-markers source)
2499 (put-text-property start (point) 'anything-multiline t)))
2500 (incf (cdr (assoc 'item-count source)))
2501 (when (>= (assoc-default 'item-count source) limit)
2502 (anything-kill-async-process process)
2505 (defun anything-output-filter--collect-candidates (lines incomplete-line-info)
2506 (anything-log-eval (cdr incomplete-line-info))
2508 (loop for line in lines collect
2509 (if (cdr incomplete-line-info)
2511 (concat (cdr incomplete-line-info) line)
2512 (setcdr incomplete-line-info nil))
2514 finally (setcdr incomplete-line-info line))))
2516 (defun anything-output-filter--post-process ()
2517 (anything-log-run-hook 'anything-update-hook)
2518 (anything-aif (get-buffer-window anything-buffer 'visible)
2519 (save-selected-window
2521 (anything-skip-noncandidate-line 'next)
2522 (anything-mark-current-line))))
2524 (defun anything-kill-async-processes ()
2525 "Kill all known asynchronous processes of `anything-async-processes'."
2526 "Kill locate process."
2527 (mapc 'anything-kill-async-process (mapcar 'car anything-async-processes))
2528 (setq anything-async-processes nil))
2530 (defun anything-kill-async-process (process)
2531 "Kill PROCESS and detach the associated functions."
2532 (set-process-filter process nil)
2533 (delete-process process))
2535 ;; (@* "Core: action")
2536 (defun anything-execute-selection-action (&optional
2538 preserve-saved-action)
2539 "If a candidate SELECTION is present then perform the associated ACTION on it.
2540 If PRESERVE-SAVED-ACTION is non-nil don't save action."
2541 (anything-log "executing action")
2542 (setq action (anything-get-default-action
2544 anything-saved-action
2545 (if (get-buffer anything-action-buffer)
2546 (anything-get-selection anything-action-buffer)
2547 (anything-get-action)))))
2548 (let ((source (or anything-saved-current-source
2549 (anything-get-current-source))))
2550 (setq selection (or selection
2551 (anything-get-selection)
2552 (and (assoc 'accept-empty source) "")))
2553 (unless preserve-saved-action (setq anything-saved-action nil))
2554 (if (and selection action)
2555 (anything-funcall-with-source
2557 (anything-coerce-selection selection source)))))
2559 (defun anything-coerce-selection (selection source)
2560 "Apply coerce attribute function to SELECTION in SOURCE.
2561 Coerce source with coerce function."
2562 (anything-aif (assoc-default 'coerce source)
2563 (anything-funcall-with-source source it selection)
2566 (defun anything-get-default-action (action)
2567 (if (and (listp action) (not (functionp action)))
2571 (defun anything-select-action ()
2572 "Select an action for the currently selected candidate.
2573 If action buffer is selected, back to the anything buffer."
2575 (cond ((get-buffer-window anything-action-buffer 'visible)
2576 (set-window-buffer (get-buffer-window anything-action-buffer)
2578 (kill-buffer anything-action-buffer)
2579 (anything-set-pattern anything-input 'noupdate))
2581 (setq anything-saved-selection (anything-get-selection))
2582 (unless anything-saved-selection
2583 (error "Nothing is selected"))
2584 (setq anything-saved-current-source (anything-get-current-source))
2585 (let ((actions (anything-get-action)))
2586 (if (functionp actions)
2587 (message "Sole action: %s" actions)
2588 (anything-show-action-buffer actions)
2589 (anything-delete-minibuffer-contents)
2590 (setq anything-pattern 'dummy) ; so that it differs from the previous one
2591 (anything-check-minibuffer-input))))))
2593 (defun anything-show-action-buffer (actions)
2594 (with-current-buffer (get-buffer-create anything-action-buffer)
2596 (buffer-disable-undo)
2597 (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
2598 (set (make-local-variable 'anything-sources)
2599 `(((name . "Actions")
2601 (candidates . ,actions)
2602 (candidate-number-limit))))
2603 (set (make-local-variable 'anything-source-filter) nil)
2604 (set (make-local-variable 'anything-selection-overlay) nil)
2605 (set (make-local-variable 'anything-digit-overlays) nil)
2606 (anything-initialize-overlays anything-action-buffer)))
2608 ;; (@* "Core: selection")
2609 (defun anything-move-selection-common (move-func unit direction)
2610 "Move the selection marker to a new position wit function MOVE-FUNC.
2611 It is determined by UNIT and DIRECTION."
2612 (unless (or (anything-empty-buffer-p (anything-buffer-get))
2613 (not (anything-window)))
2614 (with-anything-window
2615 (anything-log-run-hook 'anything-move-selection-before-hook)
2617 (anything-skip-noncandidate-line direction)
2618 (anything-display-source-at-screen-top-maybe unit)
2619 (when (anything-get-previous-header-pos)
2620 (anything-mark-current-line))
2621 (anything-display-mode-line (anything-get-current-source))
2622 (anything-log-run-hook 'anything-move-selection-after-hook))))
2624 (defun anything-display-source-at-screen-top-maybe (unit)
2625 (when (and anything-display-source-at-screen-top (eq unit 'source))
2626 (set-window-start (selected-window)
2627 (save-excursion (forward-line -1) (point)))))
2629 (defun anything-skip-noncandidate-line (direction)
2630 (anything-skip-header-and-separator-line direction)
2631 (and (bobp) (forward-line 1)) ;skip first header
2632 (and (eobp) (forward-line -1))) ;avoid last empty line
2635 (defun anything-skip-header-and-separator-line (direction)
2636 (while (and (not (bobp))
2637 (or (anything-pos-header-line-p)
2638 (anything-pos-candidate-separator-p)))
2639 (forward-line (if (and (eq direction 'previous)
2640 (not (eq (point-at-bol) (point-min))))
2643 (defvar anything-mode-line-string-real nil)
2644 (defun anything-display-mode-line (source)
2645 (set (make-local-variable 'anything-mode-line-string)
2646 (anything-interpret-value (or (assoc-default 'mode-line source)
2647 (default-value 'anything-mode-line-string))
2649 (if anything-mode-line-string
2650 (setq mode-line-format
2651 '(" " mode-line-buffer-identification " "
2652 (line-number-mode "L%l") " " (anything-follow-mode "(F) ")
2653 (:eval (anything-show-candidate-number
2654 (when (listp anything-mode-line-string)
2655 (car anything-mode-line-string))))
2656 " " anything-mode-line-string-real "-%-")
2657 anything-mode-line-string-real
2658 (substitute-command-keys (if (listp anything-mode-line-string)
2659 (cadr anything-mode-line-string)
2660 anything-mode-line-string)))
2661 (setq mode-line-format
2662 (default-value 'mode-line-format)))
2663 (setq header-line-format
2664 (anything-interpret-value (assoc-default 'header-line source) source)))
2666 (defun anything-show-candidate-number (&optional name)
2667 "Used to display candidate number in mode-line.
2668 You can specify NAME of candidates e.g \"Buffers\" otherwise
2669 it is \"Candidate\(s\)\" by default."
2672 (anything-approximate-candidate-number 'in-current-source)
2673 (or name "Candidate(s)"))
2674 'face 'anything-candidate-number))
2676 (defun anything-previous-line ()
2677 "Move selection to the previous line."
2679 (anything-move-selection-common
2681 (if (not (anything-pos-multiline-p))
2682 (forward-line -1) ;double forward-line is meaningful
2683 (forward-line -1) ;because evaluation order is important
2684 (anything-skip-header-and-separator-line 'previous)
2685 (let ((header-pos (anything-get-previous-header-pos))
2686 (separator-pos (anything-get-previous-candidate-separator-pos)))
2688 (goto-char (if (or (null separator-pos) (< separator-pos header-pos))
2689 header-pos ; first candidate
2691 (forward-line 1)))))
2694 (defun anything-next-line ()
2695 "Move selection to the next line."
2697 (anything-move-selection-common
2699 (if (not (anything-pos-multiline-p))
2701 (let ((header-pos (anything-get-next-header-pos))
2702 (separator-pos (anything-get-next-candidate-separator-pos)))
2703 (cond ((and separator-pos
2704 (or (null header-pos) (< separator-pos header-pos)))
2705 (goto-char separator-pos))
2707 (goto-char header-pos))))))
2710 (defun anything-previous-page ()
2711 "Move selection back with a pageful."
2713 (anything-move-selection-common
2717 (beginning-of-buffer (goto-char (point-min)))))
2720 (defun anything-next-page ()
2721 "Move selection forward with a pageful."
2723 (anything-move-selection-common
2727 (end-of-buffer (goto-char (point-max)))))
2730 (defun anything-beginning-of-buffer ()
2731 "Move selection at the top."
2733 (anything-move-selection-common
2734 (lambda () (goto-char (point-min)))
2737 (defun anything-end-of-buffer ()
2738 "Move selection at the bottom."
2740 (anything-move-selection-common
2741 (lambda () (goto-char (point-max)))
2744 (defun anything-previous-source ()
2745 "Move selection to the previous source."
2747 (anything-move-selection-common
2751 (goto-char (point-max))
2752 (anything-skip-header-and-separator-line 'previous))
2753 (goto-char (anything-get-previous-header-pos))
2757 (defun anything-next-source ()
2758 "Move selection to the next source."
2760 (anything-move-selection-common
2762 (goto-char (or (anything-get-next-header-pos) (point-min))))
2765 (defun anything-goto-source (source-or-name)
2766 "Move the selection to the source SOURCE-OR-NAME."
2767 (anything-move-selection-common
2769 (goto-char (point-min))
2770 (let ((name (if (stringp source-or-name) source-or-name
2771 (assoc-default 'name source-or-name))))
2773 (while (not (string= name (anything-current-line-contents)))
2774 (goto-char (anything-get-next-header-pos)))
2775 (error (message "")))))
2778 (defun anything-mark-current-line ()
2779 "Move `anything-selection-overlay' to current line.
2780 Note that this is not related with visibles marks, which are used
2781 to mark candidates."
2783 anything-selection-overlay (point-at-bol)
2784 (if (anything-pos-multiline-p)
2785 (let ((header-pos (anything-get-next-header-pos))
2786 (separator-pos (anything-get-next-candidate-separator-pos)))
2787 (or (and (null header-pos) separator-pos)
2788 (and header-pos separator-pos (< separator-pos header-pos)
2792 (1+ (point-at-eol))))
2793 (anything-follow-execute-persistent-action-maybe))
2795 (defun anything-this-command-key ()
2796 (event-basic-type (elt (this-command-keys-vector) 0)))
2797 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
2799 (defun anything-select-with-shortcut-internal (types get-key-func)
2800 (if (memq anything-enable-shortcuts types)
2801 (save-selected-window
2802 (select-window (anything-window))
2803 (let* ((key (funcall get-key-func))
2804 (overlay (ignore-errors (nth (position key anything-shortcut-keys)
2805 anything-digit-overlays))))
2806 (if (not (and overlay (overlay-buffer overlay)))
2808 (select-window (minibuffer-window))
2809 (self-insert-command 1))
2810 (goto-char (overlay-start overlay))
2811 (anything-mark-current-line)
2812 (anything-exit-minibuffer))))
2813 (self-insert-command 1)))
2815 (defun anything-select-with-prefix-shortcut ()
2816 "Invoke default action with prefix shortcut."
2818 (anything-select-with-shortcut-internal
2820 (lambda () (read-event "Select shortcut key: "))))
2822 (defun anything-select-with-digit-shortcut ()
2823 "Invoke default action with digit/alphabet shortcut."
2825 (anything-select-with-shortcut-internal
2826 '(alphabet t) 'anything-this-command-key))
2828 ;; (setq anything-enable-shortcuts 'prefix)
2829 ;; (define-key anything-map "@" 'anything-select-with-prefix-shortcut)
2830 ;; (define-key anything-map (kbd "<f18>") 'anything-select-with-prefix-shortcut)
2832 (defvar anything-exit-status 0
2833 "Flag to inform whether anything have aborted or quitted.
2834 Exit with 0 mean anything exit executing an action.
2835 Exit with 1 mean anything abort with \\[keyboard-quit]
2836 It is useful for example to restore a window config if anything abort
2838 See `anything-exit-minibuffer' and `anything-keyboard-quit'.")
2840 (defun anything-exit-minibuffer ()
2841 "Select the current candidate by exiting the minibuffer."
2843 (unless anything-current-prefix-arg
2844 (setq anything-current-prefix-arg current-prefix-arg))
2845 (setq anything-exit-status 0)
2848 (defun anything-keyboard-quit ()
2849 "Quit minibuffer in anything.
2851 If action buffer is displayed, kill it."
2853 (when (get-buffer-window anything-action-buffer 'visible)
2854 (kill-buffer anything-action-buffer))
2855 (setq anything-exit-status 1)
2856 (abort-recursive-edit))
2858 (defun anything-get-next-header-pos ()
2859 "Return the position of the next header from point."
2860 (next-single-property-change (point) 'anything-header))
2862 (defun anything-get-previous-header-pos ()
2863 "Return the position of the previous header from point."
2864 (previous-single-property-change (point) 'anything-header))
2866 (defun anything-pos-multiline-p ()
2867 "Return non-nil if the current position is in the multiline source region."
2868 (get-text-property (point) 'anything-multiline))
2870 (defun anything-get-next-candidate-separator-pos ()
2871 "Return the position of the next candidate separator from point."
2872 (next-single-property-change (point) 'anything-candidate-separator))
2874 (defun anything-get-previous-candidate-separator-pos ()
2875 "Return the position of the previous candidate separator from point."
2876 (previous-single-property-change (point) 'anything-candidate-separator))
2878 (defun anything-pos-header-line-p ()
2879 "Return t if the current line is a header line."
2880 (or (get-text-property (point-at-bol) 'anything-header)
2881 (get-text-property (point-at-bol) 'anything-header-separator)))
2883 (defun anything-pos-candidate-separator-p ()
2884 "Return t if the current line is a candidate separator."
2885 (get-text-property (point-at-bol) 'anything-candidate-separator))
2887 ;; (@* "Core: help")
2888 (defun anything-help-internal (bufname insert-content-fn)
2889 "Show long message during `anything' session in BUFNAME.
2890 INSERT-CONTENT-FN is the text to be displayed in BUFNAME."
2891 (save-window-excursion
2892 (select-window (anything-window))
2893 (delete-other-windows)
2894 (switch-to-buffer (get-buffer-create bufname))
2896 (funcall insert-content-fn)
2897 (setq mode-line-format "%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
2898 (setq cursor-type nil)
2900 (anything-help-event-loop)))
2902 (defun anything-help-event-loop ()
2904 (loop for event = (read-event) do
2906 ((?\C-v ? ) (scroll-up))
2907 ((?\M-v ?b) (scroll-down))
2910 (defun anything-help ()
2911 "Help of `anything'."
2913 (anything-help-internal
2916 (insert (substitute-command-keys
2917 (anything-interpret-value anything-help-message)))
2920 (defun anything-debug-output ()
2921 "Show all anything-related variables at this time."
2923 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function))
2925 (defun anything-debug-output-function (&optional vars)
2926 (message "Calculating all anything-related values...")
2927 (insert "If you debug some variables or forms, set `anything-debug-forms'
2928 to a list of forms.\n\n")
2930 anything-debug-forms
2931 (apropos-internal "^anything-" 'boundp)))
2933 (pp-to-string v) "\n"
2934 (pp-to-string (eval v)) "\n"))
2935 (message "Calculating all anything-related values...Done"))
2937 ;; (@* "Core: misc")
2938 (defun anything-kill-buffer-hook ()
2939 "Remove tick entry from `anything-tick-hash' when killing a buffer."
2940 (loop for key being the hash-keys in anything-tick-hash
2941 if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
2942 do (remhash key anything-tick-hash)))
2943 (add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
2945 (defun anything-preselect (candidate-or-regexp)
2946 "Move `anything-selection-overlay' to CANDIDATE-OR-REGEXP on startup."
2947 (with-anything-window
2948 (when candidate-or-regexp
2949 (goto-char (point-min))
2950 ;; go to first candidate of first source
2952 (let ((start (point)))
2953 (unless (or (re-search-forward
2954 (concat "^" (regexp-quote candidate-or-regexp) "$")
2956 (progn (goto-char start)
2957 (re-search-forward candidate-or-regexp nil t)))
2958 (goto-char start))))
2959 (anything-mark-current-line)))
2961 (defun anything-delete-current-selection ()
2962 "Delete the currently selected item."
2964 (with-anything-window
2965 (cond ((anything-pos-multiline-p)
2966 (anything-aif (anything-get-next-candidate-separator-pos)
2967 (delete-region (point-at-bol)
2968 (1+ (progn (goto-char it) (point-at-eol))))
2970 (goto-char (anything-get-previous-candidate-separator-pos))
2971 (delete-region (point-at-bol) (point-max)))
2972 (when (anything-end-of-source-p)
2973 (goto-char (or (anything-get-previous-candidate-separator-pos)
2977 (delete-region (point-at-bol) (1+ (point-at-eol)))
2978 (when (anything-end-of-source-p) (forward-line -1))))
2979 (anything-mark-current-line)))
2981 (defun anything-end-of-source-p ()
2982 "Return t if we are at eob or end of source."
2985 (or (eq (point-at-bol) (point-at-eol))
2986 (anything-pos-header-line-p)
2989 (defun anything-edit-current-selection-internal (func)
2990 (with-anything-window
2992 (let ((realvalue (get-text-property (point) 'anything-realvalue)))
2996 (put-text-property (point) (point-at-eol)
2997 'anything-realvalue realvalue))
2998 (anything-mark-current-line))))
3000 (defmacro anything-edit-current-selection (&rest forms)
3001 "Evaluate FORMS at current selection in the anything buffer.
3002 You can edit the line."
3003 (declare (indent 0) (debug t))
3004 `(anything-edit-current-selection-internal
3005 (lambda () ,@forms)))
3007 (defun anything-set-pattern (pattern &optional noupdate)
3008 "Set minibuffer contents to PATTERN.
3009 if optional NOUPDATE is non-nil, anything buffer is not changed."
3010 (with-selected-window (or (active-minibuffer-window) (minibuffer-window))
3011 (delete-minibuffer-contents)
3014 (setq anything-pattern pattern)
3015 (anything-hooks 'cleanup)
3016 (run-with-idle-timer 0 nil 'anything-hooks 'setup)))
3018 (defun anything-delete-minibuffer-contents ()
3019 "Same as `delete-minibuffer-contents' but this is a command."
3021 (anything-set-pattern ""))
3022 (defalias 'anything-delete-minibuffer-content 'anything-delete-minibuffer-contents)
3024 ;; (@* "Built-in plug-in: type")
3025 (defun anything-compile-source--type (source)
3026 (anything-aif (assoc-default 'type source)
3027 (append source (assoc-default it anything-type-attributes) nil)
3030 ;; `define-anything-type-attribute' is public API.
3032 (defun anything-add-type-attribute (type definition)
3033 (anything-aif (assq type anything-type-attributes)
3034 (setq anything-type-attributes (delete it anything-type-attributes)))
3035 (push (cons type definition) anything-type-attributes))
3037 (defvar anything-types nil)
3038 (defun anything-document-type-attribute (type doc)
3039 (add-to-list 'anything-types type t)
3040 (put type 'anything-typeattrdoc
3041 (concat "- " (symbol-name type) "\n\n" doc "\n")))
3043 (defadvice documentation-property (after anything-document-type-attribute activate)
3044 "Display type attributes' documentation as `anything-type-attributes' docstring."
3045 (when (eq (ad-get-arg 0) 'anything-type-attributes)
3046 (setq ad-return-value
3047 (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
3048 (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
3049 anything-types "\n")))))
3051 ;; (@* "Built-in plug-in: dummy")
3052 (defun anything-dummy-candidate (candidate source)
3053 "Use `anything-pattern' as CANDIDATE in SOURCE."
3054 ;; `source' is defined in filtered-candidate-transformer
3055 (list anything-pattern))
3057 (defun anything-compile-source--dummy (source)
3058 (if (assoc 'dummy source)
3060 '((candidates "dummy")
3063 (filtered-candidate-transformer . anything-dummy-candidate)
3068 ;; (@* "Built-in plug-in: disable-shortcuts")
3069 (defvar anything-orig-enable-shortcuts nil)
3070 (defun anything-save-enable-shortcuts ()
3073 (setq anything-orig-enable-shortcuts anything-enable-shortcuts
3074 anything-enable-shortcuts nil))))
3076 (defun anything-compile-source--disable-shortcuts (source)
3077 (if (assoc 'disable-shortcuts source)
3078 (append `((init ,@(anything-mklist (assoc-default 'init source))
3079 anything-save-enable-shortcuts)
3080 (resume ,@(anything-mklist (assoc-default 'resume source))
3081 anything-save-enable-shortcuts)
3082 (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
3083 (lambda () (setq anything-enable-shortcuts
3084 anything-orig-enable-shortcuts))))
3088 ;; (@* "Built-in plug-in: candidates-in-buffer")
3089 (defun anything-candidates-in-buffer ()
3090 "Get candidates from the candidates buffer according to `anything-pattern'.
3092 BUFFER is `anything-candidate-buffer' by default. Each
3093 candidate must be placed in one line. This function is meant to
3094 be used in candidates-in-buffer or candidates attribute of an
3095 anything source. Especially fast for many (1000+) candidates.
3098 '((name . \"many files\")
3099 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
3100 (insert-many-filenames))))
3101 (search re-search-forward) ; optional
3102 (candidates-in-buffer)
3105 +===============================================================+
3106 | The new way of making and narrowing candidates: Using buffers |
3107 +===============================================================+
3109 By default, `anything' makes candidates by evaluating the
3110 candidates function, then narrows them by `string-match' for each
3113 But this way is very slow for many candidates. The new way is
3114 storing all candidates in a buffer and narrowing them by
3115 `re-search-forward'. Search function is customizable by search
3116 attribute. The important point is that buffer processing is MUCH
3117 FASTER than string list processing and is the Emacs way.
3119 The init function writes all candidates to a newly-created
3120 candidate buffer. The candidates buffer is created or specified
3121 by `anything-candidate-buffer'. Candidates are stored in a line.
3123 The candidates function narrows all candidates, IOW creates a
3124 subset of candidates dynamically. It is the task of
3125 `anything-candidates-in-buffer'. As long as
3126 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
3127 sufficient in most cases.
3129 Note that `(candidates-in-buffer)' is shortcut of three attributes:
3130 (candidates . anything-candidates-in-buffer)
3133 And `(candidates-in-buffer . func)' is shortcut of three attributes:
3137 The expansion is performed in `anything-get-sources'.
3139 The candidates-in-buffer attribute implies the volatile attribute.
3140 The volatile attribute is needed because `anything-candidates-in-buffer'
3141 creates candidates dynamically and need to be called everytime
3142 `anything-pattern' changes.
3144 Because `anything-candidates-in-buffer' plays the role of `match' attribute
3145 function, specifying `(match identity)' makes the source slightly faster.
3147 To customize `anything-candidates-in-buffer' behavior, use search,
3148 get-line and search-from-end attributes. See also `anything-sources' docstring."
3149 (declare (special source))
3150 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
3152 (or (assoc-default 'get-line source)
3153 #'buffer-substring-no-properties)
3154 ;; use external variable `source'.
3155 (or (assoc-default 'search source)
3156 (if (assoc 'search-from-end source)
3157 '(re-search-backward)
3158 '(re-search-forward)))
3159 (anything-candidate-number-limit source)
3160 (assoc 'search-from-end source)))
3162 (defun anything-candidates-in-buffer-1 (buffer pattern get-line-fn search-fns limit search-from-end)
3163 ;; buffer == nil when candidates buffer does not exist.
3165 (with-current-buffer buffer
3166 (let ((start-point (if search-from-end (point-max) (point-min)))
3167 (endp (if search-from-end #'bobp #'eobp)))
3168 (goto-char (1- start-point))
3169 (if (string= pattern "")
3170 (anything-initial-candidates-from-candidate-buffer
3171 endp get-line-fn limit search-from-end)
3172 (anything-search-from-candidate-buffer
3173 pattern get-line-fn search-fns limit search-from-end
3174 start-point endp))))))
3176 (defun anything-point-is-moved (proc)
3177 "If point is moved after executing PROC, return t, otherwise nil."
3178 (/= (point) (progn (funcall proc) (point))))
3180 (defun anything-search-from-candidate-buffer (pattern get-line-fn search-fns
3181 limit search-from-end
3183 (let (buffer-read-only
3184 matches exit newmatches)
3185 (anything-search-from-candidate-buffer-internal
3187 (clrhash anything-cib-hash)
3188 (dolist (searcher search-fns)
3189 (goto-char start-point)
3190 (setq newmatches nil)
3191 (loop with item-count = 0
3192 while (funcall searcher pattern nil t)
3193 for cand = (funcall get-line-fn (point-at-bol) (point-at-eol))
3194 do (anything-accumulate-candidates-internal
3195 cand newmatches anything-cib-hash item-count limit)
3196 unless (anything-point-is-moved
3199 (goto-char (1- (point-at-bol)))
3202 (setq matches (append matches (nreverse newmatches)))
3204 (delq nil matches)))))
3206 (defun anything-initial-candidates-from-candidate-buffer (endp get-line-fn limit search-from-end)
3207 (delq nil (loop with next-line-fn =
3209 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
3211 until (funcall endp)
3212 for i from 1 to limit
3213 collect (funcall get-line-fn (point-at-bol) (point-at-eol))
3214 do (funcall next-line-fn 1))))
3216 (defun anything-search-from-candidate-buffer-internal (search-fn)
3217 (goto-char (point-min))
3219 (goto-char (point-max))
3223 (goto-char (point-min))
3225 (goto-char (1- (point-max)))
3228 (set-buffer-modified-p nil)))
3230 (defun anything-candidate-buffer (&optional create-or-buffer)
3231 "Register and return a buffer containing candidates of current source.
3232 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3233 then global candidates buffer.
3235 Acceptable values of CREATE-OR-BUFFER:
3238 Only return the candidates buffer.
3240 Register a buffer as a candidates buffer.
3242 Create a new global candidates buffer,
3243 named \" *anything candidates:SOURCE*\".
3244 - other non-nil value
3245 Create a new local candidates buffer,
3246 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\"."
3247 (let* ((global-bname (format " *anything candidates:%s*" anything-source-name))
3248 (local-bname (format " *anything candidates:%s*%s"
3249 anything-source-name
3250 (buffer-name anything-current-buffer)))
3253 (setq anything-candidate-buffer-alist
3254 (cons (cons anything-source-name create-or-buffer)
3255 (delete (assoc anything-source-name
3256 anything-candidate-buffer-alist)
3257 anything-candidate-buffer-alist)))))
3260 (loop for b in (buffer-list)
3261 if (string-match (format "^%s" (regexp-quote global-bname))
3263 do (kill-buffer b))))
3266 (with-current-buffer
3267 (get-buffer-create (if (eq create-or-buffer 'global)
3270 (buffer-disable-undo)
3272 (font-lock-mode -1))))
3275 (or (get-buffer local-bname)
3276 (get-buffer global-bname)
3277 (anything-aif (assoc-default anything-source-name
3278 anything-candidate-buffer-alist)
3279 (and (buffer-live-p it) it))))))
3280 (when create-or-buffer
3281 (funcall register-func)
3282 (unless (bufferp create-or-buffer)
3283 (and (eq create-or-buffer 'global) (funcall kill-buffers-func))
3284 (funcall create-func)))
3285 (funcall return-func)))
3287 (defun anything-compile-source--candidates-in-buffer (source)
3288 (anything-aif (assoc 'candidates-in-buffer source)
3290 `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
3291 (volatile) (match identity)))
3294 ;; (@* "Utility: resplit anything window")
3295 (defun anything-toggle-resplit-window ()
3296 "Toggle resplit anything window, vertically or horizontally."
3298 (with-anything-window
3299 (let ((before-height (window-height)))
3302 (select-window (if (= (window-height) before-height)
3304 (split-window-vertically)
3305 (setq anything-split-window-state 'vertical))
3306 (setq anything-split-window-state 'horizontal)
3307 (split-window-horizontally)))
3310 ;; (@* "Utility: Resize anything window.")
3311 (defun anything-enlarge-window-1 (n)
3312 "Enlarge or narrow anything window.
3313 If N is positive enlarge, if negative narrow."
3314 (unless anything-samewindow
3315 (let ((horizontal-p (eq anything-split-window-state 'horizontal)))
3316 (with-anything-window
3317 (enlarge-window n horizontal-p)))))
3319 (defun anything-narrow-window ()
3320 "Narrow anything window."
3322 (anything-enlarge-window-1 -1))
3324 (defun anything-enlarge-window ()
3325 "Enlarge anything window."
3327 (anything-enlarge-window-1 1))
3329 ;; (@* "Utility: select another action by key")
3330 (defun anything-select-nth-action (n)
3331 "Select the N nth action for the currently selected candidate."
3332 (setq anything-saved-selection (anything-get-selection))
3333 (unless anything-saved-selection
3334 (error "Nothing is selected"))
3335 (setq anything-saved-action (anything-get-nth-action n (anything-get-action)))
3336 (anything-exit-minibuffer))
3338 (defun anything-get-nth-action (n action)
3339 (cond ((and (zerop n) (functionp action))
3342 (or (cdr (elt action n))
3343 (error "No such action")))
3344 ((and (functionp action) (< 0 n))
3345 (error "Sole action"))
3347 (error "Error in `anything-select-nth-action'"))))
3349 (defun anything-select-2nd-action ()
3350 "Select the 2nd action for the currently selected candidate."
3352 (anything-select-nth-action 1))
3354 (defun anything-select-3rd-action ()
3355 "Select the 3rd action for the currently selected candidate."
3357 (anything-select-nth-action 2))
3359 (defun anything-select-4th-action ()
3360 "Select the 4th action for the currently selected candidate."
3362 (anything-select-nth-action 3))
3364 (defun anything-select-2nd-action-or-end-of-line ()
3365 "Select the 2nd action for the currently selected candidate.
3366 This happen when point is at the end of minibuffer.
3367 Otherwise goto the end of minibuffer."
3370 (anything-select-nth-action 1)
3373 ;; (@* "Utility: Persistent Action")
3374 (defmacro with-anything-display-same-window (&rest body)
3375 "Execute BODY in the window used for persistent action.
3376 Make `pop-to-buffer' and `display-buffer' display in the same window."
3377 (declare (indent 0) (debug t))
3378 `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
3381 (defvar anything-persistent-action-display-window nil)
3382 (defun anything-initialize-persistent-action ()
3383 (set (make-local-variable 'anything-persistent-action-display-window) nil))
3385 (defun* anything-execute-persistent-action (&optional (attr 'persistent-action) onewindow)
3386 "Perform the associated action ATTR without quitting anything.
3387 ATTR default is 'persistent-action', but it can be anything else.
3388 In this case you have to add this new attribute to your source.
3389 When `anything-samewindow' and ONEWINDOW are non--nil,
3390 the anything window is never split in persistent action."
3392 (anything-log "executing persistent-action")
3393 (with-anything-window
3394 (save-selected-window
3395 (anything-select-persistent-action-window onewindow)
3396 (anything-log-eval (current-buffer))
3397 (let ((anything-in-persistent-action t))
3398 (with-anything-display-same-window
3399 (anything-execute-selection-action
3401 (or (assoc-default attr (anything-get-current-source))
3402 (anything-get-action))
3404 (anything-log-run-hook 'anything-after-persistent-action-hook))))))
3407 (defun anything-persistent-action-display-window (&optional onewindow)
3408 "Return the window that will be used for presistent action.
3409 If ONEWINDOW is non--nil window will not be splitted in persistent action
3410 if `anything-samewindow' is non--nil also."
3411 (with-anything-window
3412 (setq anything-persistent-action-display-window
3413 (cond ((window-live-p anything-persistent-action-display-window)
3414 anything-persistent-action-display-window)
3415 ((and anything-samewindow (one-window-p t) (not onewindow))
3417 ((get-buffer-window anything-current-buffer))
3419 (next-window (selected-window) 1))))))
3421 (defun anything-select-persistent-action-window (&optional onewindow)
3422 "Select the window that will be used for persistent action.
3423 See `anything-persistent-action-display-window' for how to use ONEWINDOW."
3424 (select-window (get-buffer-window (anything-buffer-get)))
3426 (setq minibuffer-scroll-window
3427 (anything-persistent-action-display-window onewindow))))
3429 (defun anything-persistent-action-display-buffer (buf &optional not-this-window)
3430 "Make `pop-to-buffer' and `display-buffer' display in the same window.
3431 If `anything-persistent-action-use-special-display' is non-nil and
3432 BUF is to be displayed by `special-display-function', use it.
3433 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'.
3434 Argument NOT-THIS-WINDOW if present will be used as
3435 second argument of `display-buffer'."
3436 (let* ((name (buffer-name buf))
3437 display-buffer-function pop-up-windows pop-up-frames
3438 (same-window-regexps
3439 (unless (and anything-persistent-action-use-special-display
3441 (mapcar (lambda (x) (or (car-safe x) x))
3442 special-display-buffer-names))
3444 (lambda (x) (string-match (or (car-safe x) x) name))
3445 special-display-regexps)))
3447 (display-buffer buf not-this-window)))
3449 ;; scroll-other-window(-down)? for persistent-action
3450 (defun anything-scroll-other-window-base (command)
3451 (with-selected-window (anything-persistent-action-display-window)
3452 (funcall command anything-scroll-amount)))
3454 (defun anything-scroll-other-window ()
3455 "Scroll other window (not *Anything* window) upward."
3457 (anything-scroll-other-window-base 'scroll-up))
3459 (defun anything-scroll-other-window-down ()
3460 "Scroll other window (not *Anything* window) downward."
3462 (anything-scroll-other-window-base 'scroll-down))
3464 ;; (@* "Utility: Visible Mark")
3465 (defface anything-visible-mark
3466 '((((min-colors 88) (background dark))
3467 (:background "green1" :foreground "black"))
3468 (((background dark)) (:background "green" :foreground "black"))
3469 (((min-colors 88)) (:background "green1"))
3470 (t (:background "green")))
3471 "Face for visible mark."
3474 (defvar anything-visible-mark-face 'anything-visible-mark)
3475 (defvar anything-visible-mark-overlays nil)
3477 (defun anything-clear-visible-mark ()
3478 (with-current-buffer (anything-buffer-get)
3479 (mapc 'delete-overlay anything-visible-mark-overlays)
3480 (set (make-local-variable 'anything-visible-mark-overlays) nil)))
3481 (add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
3483 (defvar anything-marked-candidates nil
3484 "Marked candadates. List of \(source . real\) pair.")
3486 (defun anything-this-visible-mark ()
3487 (loop for o in anything-visible-mark-overlays
3488 when (equal (point-at-bol) (overlay-start o))
3491 (defun anything-delete-visible-mark (overlay)
3492 (setq anything-marked-candidates
3494 (cons (anything-get-current-source) (anything-get-selection))
3495 anything-marked-candidates))
3496 (delete-overlay overlay)
3497 (setq anything-visible-mark-overlays
3498 (delq overlay anything-visible-mark-overlays)))
3500 (defun anything-make-visible-mark ()
3501 (let ((o (make-overlay (point-at-bol) (1+ (point-at-eol)))))
3502 (overlay-put o 'face anything-visible-mark-face)
3503 (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3504 (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3505 (overlay-put o 'real (anything-get-selection))
3506 (add-to-list 'anything-visible-mark-overlays o))
3507 (push (cons (anything-get-current-source) (anything-get-selection))
3508 anything-marked-candidates))
3510 (defun anything-toggle-visible-mark ()
3511 "Toggle anything visible mark at point."
3513 (with-anything-window
3514 (anything-aif (anything-this-visible-mark)
3515 (anything-delete-visible-mark it)
3516 (anything-make-visible-mark))
3517 (anything-next-line)))
3519 (defun anything-display-all-visible-marks ()
3520 "Show all `anything' visible marks strings."
3522 (with-anything-window
3523 (lexical-let ((overlays (reverse anything-visible-mark-overlays)))
3524 (anything-run-after-quit
3526 (with-output-to-temp-buffer "*anything visible marks*"
3527 (dolist (o overlays) (princ (overlay-get o 'string)))))))))
3529 (defun anything-marked-candidates ()
3530 "Return marked candidates of current source if any.
3531 Otherwise one element list of current selection.
3533 It is analogous to `dired-get-marked-files'."
3534 (with-current-buffer (anything-buffer-get)
3536 (if anything-marked-candidates
3537 (loop with current-src = (anything-get-current-source)
3538 for (source . real) in (reverse anything-marked-candidates)
3539 when (equal current-src source)
3540 collect (anything-coerce-selection real source))
3541 (list (anything-get-selection)))))
3542 (anything-log-eval cands)
3545 (defun anything-reset-marked-candidates ()
3546 (with-current-buffer (anything-buffer-get)
3547 (set (make-local-variable 'anything-marked-candidates) nil)))
3549 (add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
3550 ;; (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3552 (defun anything-current-source-name= (name)
3554 (goto-char (anything-get-previous-header-pos))
3555 (equal name (anything-current-line-contents))))
3557 (defun anything-revive-visible-mark ()
3558 "Restore marked candidates when anything update display."
3559 (with-current-buffer anything-buffer
3560 (dolist (o anything-visible-mark-overlays)
3561 (goto-char (point-min))
3562 (while (and (search-forward (overlay-get o 'string) nil t)
3563 (anything-current-source-name= (overlay-get o 'source)))
3564 ;; Calculate real value of candidate.
3565 ;; It can be nil if candidate have only a display value.
3566 (let ((real (get-text-property (point-at-bol 0) 'anything-realvalue)))
3568 ;; Check if real value of current candidate is the same
3569 ;; that the one stored in overlay.
3570 (and (string= (overlay-get o 'real) real)
3571 (move-overlay o (point-at-bol 0) (1+ (point-at-eol 0))))
3572 (move-overlay o (point-at-bol 0) (1+ (point-at-eol 0)))))))))
3573 (add-hook 'anything-update-hook 'anything-revive-visible-mark)
3575 (defun anything-next-point-in-list (curpos points &optional prev)
3577 ;; rule out special cases
3578 ((null points) curpos)
3579 ((and prev (< curpos (car points))) curpos)
3580 ((< (car (last points)) curpos)
3581 (if prev (car (last points)) curpos))
3584 (loop for pt in points
3588 (loop for pt in points
3594 (defun anything-next-visible-mark (&optional prev)
3595 "Move next anything visible mark.
3596 If PREV is non-nil move to precedent."
3598 (with-anything-window
3599 (goto-char (anything-next-point-in-list
3601 (sort (mapcar 'overlay-start anything-visible-mark-overlays) '<)
3603 (anything-mark-current-line)))
3605 (defun anything-prev-visible-mark ()
3606 "Move previous anything visible mark."
3608 (anything-next-visible-mark t))
3610 ;; (@* "Utility: Selection Paste")
3611 (defun anything-yank-selection ()
3612 "Set minibuffer contents to current selection."
3614 (anything-set-pattern (anything-get-selection nil t)))
3616 (defun anything-kill-selection-and-quit ()
3617 "Store current selection to kill ring.
3618 You can paste it by typing \\[yank]."
3620 (anything-run-after-quit
3623 (message "Killed: %s" sel))
3624 (anything-get-selection nil t)))
3627 ;; (@* "Utility: Automatical execution of persistent-action")
3628 (add-to-list 'minor-mode-alist '(anything-follow-mode " AFollow"))
3629 (defun anything-follow-mode ()
3630 "If this mode is on, persistent action is executed everytime the cursor is moved."
3632 (with-current-buffer anything-buffer
3633 (setq anything-follow-mode (not anything-follow-mode))
3634 (message "anything-follow-mode is %s"
3635 (if anything-follow-mode "enabled" "disabled"))))
3637 (defun anything-follow-execute-persistent-action-maybe ()
3638 "Execute persistent action in mode `anything-follow-mode'.
3639 This happen after `anything-input-idle-delay' secs."
3640 (and (not (get-buffer-window anything-action-buffer 'visible))
3641 (buffer-local-value 'anything-follow-mode
3642 (get-buffer-create anything-buffer))
3643 (sit-for anything-input-idle-delay)
3645 (anything-get-selection)
3647 (anything-execute-persistent-action))))
3649 ;; (@* "Utility: Migrate `anything-sources' to my-anything command")
3650 (defun anything-migrate-sources ()
3651 "Help to migrate to new `anything' way."
3653 (with-current-buffer (get-buffer-create "*anything migrate*")
3656 Setting `anything-sources' directly is not good because
3657 `anything' is not for one command. For now, interactive use of
3658 `anything' (M-x anything) is only for demonstration purpose.
3659 So you should define commands calling `anything'.
3660 I help you to migrate to the new way.
3662 The code below is automatically generated from current
3663 `anything-sources' value. You can use the `my-anything' command
3666 Copy and paste it to your .emacs. Then substitute `my-anything'
3667 for `anything' bindings in all `define-key', `local-set-key' and
3668 `global-set-key' calls.
3670 \(defun my-anything ()
3671 \"Anything command for you.
3673 It is automatically generated by `anything-migrate-sources'.\"
3675 (anything-other-buffer
3678 " anything-sources))
3679 (eval-last-sexp nil)
3680 (substitute-key-definition 'anything 'my-anything global-map)
3681 (pop-to-buffer (current-buffer))))
3683 ;; (@* "Compatibility")
3685 ;; Copied assoc-default from XEmacs version 21.5.12
3686 (unless (fboundp 'assoc-default)
3687 (defun assoc-default (key alist &optional test default)
3688 "Find object KEY in a pseudo-alist ALIST.
3689 ALIST is a list of conses or objects. Each element (or the element's car,
3690 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
3691 If that is non-nil, the element matches;
3692 then `assoc-default' returns the element's cdr, if it is a cons,
3693 or DEFAULT if the element is not a cons.
3695 If no element matches, the value is nil.
3696 If TEST is omitted or nil, `equal' is used."
3697 (let (found (tail alist) value)
3698 (while (and tail (not found))
3699 (let ((elt (car tail)))
3700 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
3701 (setq found t value (if (consp elt) (cdr elt) default))))
3702 (setq tail (cdr tail)))
3705 ;; Function not available in XEmacs,
3706 (unless (fboundp 'minibuffer-contents)
3707 (defun minibuffer-contents ()
3708 "Return the user input in a minbuffer as a string.
3709 The current buffer must be a minibuffer."
3710 (field-string (point-max)))
3712 (defun delete-minibuffer-contents ()
3713 "Delete all user input in a minibuffer.
3714 The current buffer must be a minibuffer."
3715 (delete-field (point-max))))
3717 ;; Function not available in older Emacs (<= 22.1).
3718 (unless (fboundp 'buffer-chars-modified-tick)
3719 (defun buffer-chars-modified-tick (&optional buffer)
3720 "Return BUFFER's character-change tick counter.
3721 Each buffer has a character-change tick counter, which is set to the
3722 value of the buffer's tick counter (see `buffer-modified-tick'), each
3723 time text in that buffer is inserted or deleted. By comparing the
3724 values returned by two individual calls of `buffer-chars-modified-tick',
3725 you can tell whether a character change occurred in that buffer in
3726 between these calls. No argument or nil as argument means use current
3728 (with-current-buffer (or buffer (current-buffer))
3729 (if (listp buffer-undo-list)
3730 (length buffer-undo-list)
3731 (buffer-modified-tick)))))
3733 ;; (@* "CUA workaround")
3734 (defadvice cua-delete-region (around anything-avoid-cua activate)
3735 (ignore-errors ad-do-it))
3737 (defadvice copy-region-as-kill (around anything-avoid-cua activate)
3739 (ignore-errors ad-do-it)
3742 ;;(@* "Attribute Documentation")
3743 (defun anything-describe-anything-attribute (anything-attribute)
3744 "Display the full documentation of ANYTHING-ATTRIBUTE.
3745 ANYTHING-ATTRIBUTE should be a symbol."
3746 (interactive (list (intern
3748 "Describe anything attribute: "
3749 (mapcar 'symbol-name anything-additional-attributes)))))
3750 (with-output-to-temp-buffer "*Help*"
3751 (princ (get anything-attribute 'anything-attrdoc))))
3753 (anything-document-attribute 'name "mandatory"
3754 " The name of the source. It is also the heading which appears
3755 above the list of matches from the source. Must be unique. ")
3756 (anything-document-attribute 'header-name "optional"
3757 " A function returning the display string of the header. Its
3758 argument is the name of the source. This attribute is useful to
3759 add an additional information with the source name. ")
3760 (anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
3761 " Specifies how to retrieve candidates from the source. It can
3762 either be a variable name, a function called with no parameters
3763 or the actual list of candidates.
3765 The list must be a list whose members are strings, symbols
3766 or (DISPLAY . REAL) pairs.
3768 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
3769 in the Anything buffer, but the REAL one is used as action
3770 argument when the candidate is selected. This allows a more
3771 readable presentation for candidates which would otherwise be,
3772 for example, too long or have a common part shared with other
3773 candidates which can be safely replaced with an abbreviated
3774 string for display purposes.
3776 Note that if the (DISPLAY . REAL) form is used then pattern
3777 matching is done on the displayed string, not on the real
3780 If the candidates have to be retrieved asynchronously (for
3781 example, by an external command which takes a while to run)
3782 then the function should start the external command
3783 asynchronously and return the associated process object.
3784 Anything will take care of managing the process (receiving the
3785 output from it, killing it if necessary, etc.). The process
3786 should return candidates matching the current pattern (see
3787 variable `anything-pattern'.)
3789 Note that currently results from asynchronous sources appear
3790 last in the anything buffer regardless of their position in
3791 `anything-sources'. ")
3792 (anything-document-attribute 'action "mandatory if type attribute is not provided"
3793 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
3794 FUNCTION is called with one parameter: the selected candidate.
3796 An action other than the default can be chosen from this list
3797 of actions for the currently selected candidate (by default
3798 with TAB). The DISPLAY string is shown in the completions
3799 buffer and the FUNCTION is invoked when an action is
3800 selected. The first action of the list is the default. ")
3801 (anything-document-attribute 'coerce "optional"
3802 " It's a function called with one argument: the selected candidate.
3804 This function is intended for type convertion.
3805 In normal case, the selected candidate (string) is passed to action function.
3806 If coerce function is specified, it is called just before action function.
3808 Example: converting string to symbol
3809 (coerce . intern) ")
3810 (anything-document-attribute 'type "optional if action attribute is provided"
3811 " Indicates the type of the items the source returns.
3813 Merge attributes not specified in the source itself from
3814 `anything-type-attributes'.
3816 This attribute is implemented by plug-in. ")
3817 (anything-document-attribute 'init "optional"
3818 " Function called with no parameters when anything is started. It
3819 is useful for collecting current state information which can be
3820 used to create the list of candidates later.
3822 For example, if a source needs to work with the current
3823 directory then it can store its value here, because later
3824 anything does its job in the minibuffer and in the
3825 `anything-buffer' and the current directory can be different
3827 (anything-document-attribute 'delayed-init "optional"
3828 " Function called with no parameters before candidate function is
3829 called. It is similar with `init' attribute, but its
3830 evaluation is deferred. It is useful to combine with ")
3831 (anything-document-attribute 'match "optional"
3832 " List of functions called with one parameter: a candidate. The
3833 function should return non-nil if the candidate matches the
3834 current pattern (see variable `anything-pattern').
3836 This attribute allows the source to override the default
3837 pattern matching based on `string-match'. It can be used, for
3838 example, to implement a source for file names and do the
3839 pattern matching on the basename of files, since it's more
3840 likely one is typing part of the basename when searching for a
3841 file, instead of some string anywhere else in its path.
3843 If the list contains more than one function then the list of
3844 matching candidates from the source is constructed by appending
3845 the results after invoking the first function on all the
3846 potential candidates, then the next function, and so on. The
3847 matching candidates supplied by the first function appear first
3848 in the list of results and then results from the other
3849 functions, respectively.
3851 This attribute has no effect for asynchronous sources (see
3852 attribute `candidates'), since they perform pattern matching
3854 (anything-document-attribute 'candidate-transformer "optional"
3855 " It's a function or a list of functions called with one argument
3856 when the completion list from the source is built. The argument
3857 is the list of candidates retrieved from the source. The
3858 function should return a transformed list of candidates which
3859 will be used for the actual completion. If it is a list of
3860 functions, it calls each function sequentially.
3862 This can be used to transform or remove items from the list of
3865 Note that `candidates' is run already, so the given transformer
3866 function should also be able to handle candidates with (DISPLAY
3868 (anything-document-attribute 'filtered-candidate-transformer "optional"
3869 " It has the same format as `candidate-transformer', except the
3870 function is called with two parameters: the candidate list and
3873 This transformer is run on the candidate list which is already
3874 filtered by the current pattern. While `candidate-transformer'
3875 is run only once, it is run every time the input pattern is
3878 It can be used to transform the candidate list dynamically, for
3879 example, based on the current pattern.
3881 In some cases it may also be more efficent to perform candidate
3882 transformation here, instead of with `candidate-transformer'
3883 even if this transformation is done every time the pattern is
3884 changed. For example, if a candidate set is very large then
3885 `candidate-transformer' transforms every candidate while only
3886 some of them will actually be dislpayed due to the limit
3887 imposed by `anything-candidate-number-limit'.
3889 Note that `candidates' and `candidate-transformer' is run
3890 already, so the given transformer function should also be able
3891 to handle candidates with (DISPLAY . REAL) format.
3893 This option has no effect for asynchronous sources. (Not yet,
3895 (anything-document-attribute 'action-transformer "optional"
3896 " It's a function or a list of functions called with two
3897 arguments when the action list from the source is
3898 assembled. The first argument is the list of actions, the
3899 second is the current selection. If it is a list of functions,
3900 it calls each function sequentially.
3902 The function should return a transformed action list.
3904 This can be used to customize the list of actions based on the
3905 currently selected candidate. ")
3906 (anything-document-attribute 'pattern-transformer "optional"
3907 " It's a function or a list of functions called with one argument
3908 before computing matches. Its argument is `anything-pattern'.
3909 Functions should return transformed `anything-pattern'.
3911 It is useful to change interpretation of `anything-pattern'. ")
3912 (anything-document-attribute 'delayed "optional"
3913 " Candidates from the source are shown only if the user stops
3914 typing and is idle for `anything-idle-delay' seconds. ")
3915 (anything-document-attribute 'volatile "optional"
3916 " Indicates the source assembles the candidate list dynamically,
3917 so it shouldn't be cached within a single Anything
3918 invocation. It is only applicable to synchronous sources,
3919 because asynchronous sources are not cached. ")
3920 (anything-document-attribute 'requires-pattern "optional"
3921 " If present matches from the source are shown only if the
3922 pattern is not empty. Optionally, it can have an integer
3923 parameter specifying the required length of input which is
3924 useful in case of sources with lots of candidates. ")
3925 (anything-document-attribute 'persistent-action "optional"
3926 " Function called with one parameter; the selected candidate.
3928 An action performed by `anything-execute-persistent-action'.
3929 If none, use the default action. ")
3930 (anything-document-attribute 'candidates-in-buffer "optional"
3931 " Shortcut attribute for making and narrowing candidates using
3932 buffers. This newly-introduced attribute prevents us from
3933 forgetting to add volatile and match attributes.
3935 See docstring of `anything-candidates-in-buffer'.
3937 (candidates-in-buffer) is equivalent of three attributes:
3938 (candidates . anything-candidates-in-buffer)
3942 (candidates-in-buffer . candidates-function) is equivalent of:
3943 (candidates . candidates-function)
3947 This attribute is implemented by plug-in. ")
3948 (anything-document-attribute 'search "optional"
3949 " List of functions like `re-search-forward' or `search-forward'.
3950 Buffer search function used by `anything-candidates-in-buffer'.
3951 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
3952 This attribute is meant to be used with
3953 (candidates . anything-candidates-in-buffer) or
3954 (candidates-in-buffer) in short. ")
3955 (anything-document-attribute 'search-from-end "optional"
3956 " Make `anything-candidates-in-buffer' search from the end of buffer.
3957 If this attribute is specified, `anything-candidates-in-buffer' uses
3958 `re-search-backward' instead. ")
3959 (anything-document-attribute 'get-line "optional"
3960 " A function like `buffer-substring-no-properties' or `buffer-substring'.
3961 This function converts point of line-beginning and point of line-end,
3962 which represents a candidate computed by `anything-candidates-in-buffer'.
3963 By default, `anything-candidates-in-buffer' uses
3964 `buffer-substring-no-properties'. ")
3965 (anything-document-attribute 'display-to-real "optional"
3966 " Function called with one parameter; the selected candidate.
3968 The function transforms the selected candidate, and the result
3969 is passed to the action function. The display-to-real
3970 attribute provides another way to pass other string than one
3971 shown in Anything buffer.
3973 Traditionally, it is possible to make candidates,
3974 candidate-transformer or filtered-candidate-transformer
3975 function return a list with (DISPLAY . REAL) pairs. But if REAL
3976 can be generated from DISPLAY, display-to-real is more
3977 convenient and faster. ")
3978 (anything-document-attribute 'real-to-display "optional"
3979 " Function called with one parameter; the selected candidate.
3981 The inverse of display-to-real attribute.
3983 The function transforms the selected candidate, which is passed
3984 to the action function, for display. The real-to-display
3985 attribute provides the other way to pass other string than one
3986 shown in Anything buffer.
3988 Traditionally, it is possible to make candidates,
3989 candidate-transformer or filtered-candidate-transformer
3990 function return a list with (DISPLAY . REAL) pairs. But if
3991 DISPLAY can be generated from REAL, real-to-display is more
3994 Note that DISPLAY parts returned from candidates /
3995 candidate-transformer are IGNORED as the name `display-to-real'
3997 (anything-document-attribute 'cleanup "optional"
3998 " Function called with no parameters when *anything* buffer is closed. It
3999 is useful for killing unneeded candidates buffer.
4001 Note that the function is executed BEFORE performing action. ")
4002 (anything-document-attribute 'candidate-number-limit "optional"
4003 " Override `anything-candidate-number-limit' only for this source. ")
4004 (anything-document-attribute 'accept-empty "optional"
4005 " Pass empty string \"\" to action function. ")
4006 (anything-document-attribute 'disable-shortcuts "optional"
4007 " Disable `anything-enable-shortcuts' in current `anything' session.
4009 This attribute is implemented by plug-in. ")
4010 (anything-document-attribute 'dummy "optional"
4011 " Set `anything-pattern' to candidate. If this attribute is
4012 specified, The candidates attribute is ignored.
4014 This attribute is implemented by plug-in.
4015 This plug-in implies disable-shortcuts plug-in. ")
4016 (anything-document-attribute 'multiline "optional"
4017 " Enable to selection multiline candidates. ")
4018 (anything-document-attribute 'update "optional"
4019 ;; FIXME: this is not displayed correctly in help buffer.
4020 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4021 (anything-document-attribute 'mode-line "optional"
4022 " source local `anything-mode-line-string'. (included in `mode-line-format')
4023 It accepts also variable/function name. ")
4024 (anything-document-attribute 'header-line "optional"
4025 " source local `header-line-format'.
4026 It accepts also variable/function name. ")
4027 (anything-document-attribute
4029 " Function called with no parameters when `anything-resume' is started.")
4031 ;; (@* "Bug Report")
4032 (defvar anything-maintainer-mail-address
4033 (concat "rubiki" "tch@ru" "by-lang.org"))
4034 (defvar anything-bug-report-salutation
4035 "Describe bug below, using a precise recipe.
4037 When I executed M-x ...
4039 How to send a bug report:
4040 1) Be sure to use the LATEST version of anything.el.
4041 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
4042 3) Use Lisp version instead of compiled one: (load \"anything.el\")
4043 4) If you got an error, please paste *Backtrace* buffer.
4044 5) Type C-c C-c to send.
4045 # If you are a Japanese, please write in Japanese:-)")
4046 (defvar anything-no-dump-variables
4047 '(anything-candidate-buffer-alist
4048 anything-digit-overlays
4049 anything-help-message
4050 anything-candidate-cache
4052 "Variables not to dump in bug report.")
4054 (defun anything-dumped-variables-in-bug-report ()
4055 (let ((hash (make-hash-table)))
4056 (loop for var in (apropos-internal "anything-" 'boundp)
4057 for vname = (symbol-name var)
4058 unless (or (string-match "-map$" vname)
4059 (string-match "^anything-c-source-" vname)
4060 (string-match "-hash$" vname)
4061 (string-match "-face$" vname)
4062 (memq var anything-no-dump-variables))
4065 (defun anything-send-bug-report ()
4066 "Send a bug report of anything.el."
4068 (with-current-buffer (or anything-last-buffer
4070 (reporter-submit-bug-report
4071 anything-maintainer-mail-address
4073 (anything-dumped-variables-in-bug-report)
4075 anything-bug-report-salutation)))
4077 (defun anything-send-bug-report-from-anything ()
4078 "Send a bug report of anything.el in anything session."
4080 (anything-run-after-quit 'anything-send-bug-report))
4082 ;; Debugging function.
4083 (defun* anything-test-candidates
4084 (sources &optional (input "")
4085 (compile-source-functions
4086 anything-compile-source-functions-default))
4087 "Test helper function for anything.
4088 Given pseudo `anything-sources' and `anything-pattern', returns list like
4089 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4090 (\"source name2\" (\"candidate3\" \"candidate4\")))"
4091 (let ((anything-test-mode t)
4092 anything-enable-shortcuts
4093 anything-candidate-cache
4094 (anything-compile-source-functions compile-source-functions)
4095 anything-before-initialize-hook
4096 anything-after-initialize-hook
4097 anything-update-hook
4098 anything-test-candidate-list)
4099 (get-buffer-create anything-buffer)
4100 (anything-initialize nil input sources)
4102 ;; test-mode spec: select 1st candidate!
4103 (with-current-buffer anything-buffer
4105 (anything-mark-current-line))
4107 anything-test-candidate-list
4108 (anything-cleanup))))
4110 ;; (@* "Unit Tests")
4111 ;; See developer-tools/unit-test-anything.el
4115 ;; How to save (DO NOT REMOVE!!)
4116 ;; (progn (magit-push) (emacswiki-post "anything.el"))
4122 ;;; anything.el ends here