* anything-config.el (anything-completing-read-default-1): new arg that allow using...
[anything-config.git] / anything.el
blob5ebfe23b89f4d6ad560eda33210215344f9674fb
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
14 ;; X-URL: http://repo.or.cz/w/anything-config.git
16 ;; Site: http://www.emacswiki.org/cgi-bin/emacs/Anything
18 ;; MailingList: https://groups.google.com/group/emacs-anything?hl=en
21 ;;; This file is NOT part of GNU Emacs
23 ;;; License
25 ;; This file is free software; you can redistribute it and/or modify
26 ;; it under the terms of the GNU General Public License as published by
27 ;; the Free Software Foundation; either version 2, or (at your option)
28 ;; any later version.
30 ;; This file is distributed in the hope that it will be useful,
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs; see the file COPYING. If not, write to the
38 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39 ;; Boston, MA 02110-1301, USA.
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 ;;; Autodoc documentation:
45 ;; ---------------------
47 ;; * Commands defined here are:
48 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
49 ;; `anything-open-last-log'
50 ;; Open anything log file of last anything session.
51 ;; `anything-resume'
52 ;; Resurrect previously invoked `anything'.
53 ;; `anything-resume-window-only'
54 ;;
55 ;; `anything-at-point'
56 ;; Call anything with symbol at point as initial input.
57 ;; `anything-force-update'
58 ;; Force recalculation and update of candidates.
59 ;; `anything-select-action'
60 ;; Select an action for the currently selected candidate.
61 ;; `anything-previous-line'
62 ;; Move selection to the previous line.
63 ;; `anything-next-line'
64 ;; Move selection to the next line.
65 ;; `anything-previous-page'
66 ;; Move selection back with a pageful.
67 ;; `anything-next-page'
68 ;; Move selection forward with a pageful.
69 ;; `anything-beginning-of-buffer'
70 ;; Move selection at the top.
71 ;; `anything-end-of-buffer'
72 ;; Move selection at the bottom.
73 ;; `anything-previous-source'
74 ;; Move selection to the previous source.
75 ;; `anything-next-source'
76 ;; Move selection to the next source.
77 ;; `anything-select-with-prefix-shortcut'
78 ;; Invoke default action with prefix shortcut.
79 ;; `anything-select-with-digit-shortcut'
80 ;; Invoke default action with digit/alphabet shortcut.
81 ;; `anything-exit-minibuffer'
82 ;; Select the current candidate by exiting the minibuffer.
83 ;; `anything-keyboard-quit'
84 ;; Quit minibuffer in anything.
85 ;; `anything-help'
86 ;; Help of `anything'.
87 ;; `anything-debug-output'
88 ;; Show all anything-related variables at this time.
89 ;; `anything-delete-current-selection'
90 ;; Delete the currently selected item.
91 ;; `anything-delete-minibuffer-contents'
92 ;; Same as `delete-minibuffer-contents' but this is a command.
93 ;; `anything-toggle-resplit-window'
94 ;; Toggle resplit anything window, vertically or horizontally.
95 ;; `anything-narrow-window'
96 ;; Narrow anything window.
97 ;; `anything-enlarge-window'
98 ;; Enlarge anything window.
99 ;; `anything-select-2nd-action'
100 ;; Select the 2nd action for the currently selected candidate.
101 ;; `anything-select-3rd-action'
102 ;; Select the 3rd action for the currently selected candidate.
103 ;; `anything-select-4th-action'
104 ;; Select the 4th action for the currently selected candidate.
105 ;; `anything-select-2nd-action-or-end-of-line'
106 ;; Select the 2nd action for the currently selected candidate.
107 ;; `anything-execute-persistent-action'
108 ;; Perform the associated action ATTR without quitting anything.
109 ;; `anything-scroll-other-window'
110 ;; Scroll other window (not *Anything* window) upward.
111 ;; `anything-scroll-other-window-down'
112 ;; Scroll other window (not *Anything* window) downward.
113 ;; `anything-toggle-visible-mark'
114 ;; Toggle anything visible mark at point.
115 ;; `anything-display-all-visible-marks'
116 ;; Show all `anything' visible marks strings.
117 ;; `anything-next-visible-mark'
118 ;; Move next anything visible mark.
119 ;; `anything-prev-visible-mark'
120 ;; Move previous anything visible mark.
121 ;; `anything-yank-selection'
122 ;; Set minibuffer contents to current selection.
123 ;; `anything-kill-selection-and-quit'
124 ;; Store current selection to kill ring.
125 ;; `anything-follow-mode'
126 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
127 ;; `anything-migrate-sources'
128 ;; Help to migrate to new `anything' way.
129 ;; `anything-describe-anything-attribute'
130 ;; Display the full documentation of ANYTHING-ATTRIBUTE.
131 ;; `anything-send-bug-report'
132 ;; Send a bug report of anything.el.
133 ;; `anything-send-bug-report-from-anything'
134 ;; Send a bug report of anything.el in anything session.
136 ;; * Variables defined here are:
137 ;; [EVAL] (autodoc-document-lisp-buffer :type 'internal-variable :prefix "anything-" :docstring t)
138 ;; `anything-version'
139 ;; Not documented.
140 ;; `anything-sources'
141 ;; A list of sources to use with `anything'.
142 ;; `anything-type-attributes'
143 ;; It's a list of (TYPE ATTRIBUTES ...).
144 ;; `anything-enable-shortcuts'
145 ;; *Whether to use digit/alphabet shortcut to select the first nine matches.
146 ;; `anything-shortcut-keys-alist'
147 ;; Not documented.
148 ;; `anything-display-source-at-screen-top'
149 ;; *Display candidates at the top of screen.
150 ;; `anything-candidate-number-limit'
151 ;; Apply candidate-number-limit attribute value.
152 ;; `anything-idle-delay'
153 ;; *Be idle for this many seconds, before updating in delayed sources.
154 ;; `anything-input-idle-delay'
155 ;; Be idle for this many seconds, before updating.
156 ;; `anything-samewindow'
157 ;; Use current window to show the candidates.
158 ;; `anything-source-filter'
159 ;; A list of source names to be displayed.
160 ;; `anything-map'
161 ;; Keymap for anything.
162 ;; `anything-header-face'
163 ;; *Face for header lines in the anything buffer.
164 ;; `anything-selection-face'
165 ;; *Face for currently selected item.
166 ;; `anything-buffer'
167 ;; Buffer showing completions.
168 ;; `anything-action-buffer'
169 ;; Buffer showing actions.
170 ;; `anything-selection-overlay'
171 ;; Overlay used to highlight the currently selected item.
172 ;; `anything-digit-overlays'
173 ;; Overlays for digit shortcuts. See `anything-enable-shortcuts'.
174 ;; `anything-candidate-cache'
175 ;; Holds the available candidate withing a single anything invocation.
176 ;; `anything-pattern'
177 ;; Not documented.
178 ;; `anything-input'
179 ;; Not documented.
180 ;; `anything-async-processes'
181 ;; List of information about asynchronous processes managed by anything.
182 ;; `anything-digit-shortcut-count'
183 ;; Number of digit shortcuts shown in the anything buffer.
184 ;; `anything-before-initialize-hook'
185 ;; Run before anything initialization.
186 ;; `anything-after-initialize-hook'
187 ;; Run after anything initialization.
188 ;; `anything-update-hook'
189 ;; Run after the anything buffer was updated according the new input pattern.
190 ;; `anything-after-update-hook'
191 ;; Run after the anything buffer was updated according the new input pattern.
192 ;; `anything-cleanup-hook'
193 ;; Run after anything minibuffer is closed.
194 ;; `anything-after-action-hook'
195 ;; Run after executing action.
196 ;; `anything-after-persistent-action-hook'
197 ;; Run after executing persistent action.
198 ;; `anything-move-selection-before-hook'
199 ;; Run before moving selection in `anything-buffer'.
200 ;; `anything-move-selection-after-hook'
201 ;; Run after moving selection in `anything-buffer'.
202 ;; `anything-restored-variables'
203 ;; Variables which are restored after `anything' invocation.
204 ;; `anything-saved-selection'
205 ;; Value of the currently selected object when the action list is shown.
206 ;; `anything-current-prefix-arg'
207 ;; Record `current-prefix-arg' when exiting minibuffer.
208 ;; `anything-candidate-separator'
209 ;; Candidates separator of `multiline' source.
210 ;; `anything-current-buffer'
211 ;; Current buffer when `anything' is invoked.
212 ;; `anything-buffer-file-name'
213 ;; Variable `buffer-file-name' when `anything' is invoked.
214 ;; `anything-saved-action'
215 ;; Saved value of the currently selected action by key.
216 ;; `anything-last-sources'
217 ;; OBSOLETE!! Sources of previously invoked `anything'.
218 ;; `anything-saved-current-source'
219 ;; Value of the current source when the action list is shown.
220 ;; `anything-compiled-sources'
221 ;; Compiled version of `anything-sources'.
222 ;; `anything-in-persistent-action'
223 ;; Flag whether in persistent-action or not.
224 ;; `anything-quick-update'
225 ;; If non-nil, suppress displaying sources which are out of screen at first.
226 ;; `anything-last-sources-local'
227 ;; Buffer local value of `anything-sources'.
228 ;; `anything-last-buffer'
229 ;; `anything-buffer' of previously `anything' session.
230 ;; `anything-persistent-action-use-special-display'
231 ;; If non-nil, use `special-display-function' in persistent action.
232 ;; `anything-execute-action-at-once-if-one'
233 ;; Execute default action and exit when only one candidate is remaining.
234 ;; `anything-quit-if-no-candidate'
235 ;; Quit when there is no candidates when non--nil.
236 ;; `anything-scroll-amount'
237 ;; Scroll amount when scrolling other window in an anything session.
238 ;; `anything-display-function'
239 ;; Function to display *anything* buffer.
240 ;; `anything-delayed-init-executed'
241 ;; Not documented.
242 ;; `anything-mode-line-string'
243 ;; Help string displayed in mode-line in `anything'.
244 ;; `anything-help-message'
245 ;; Detailed help message string for `anything'.
246 ;; `anything-source-in-each-line-flag'
247 ;; Non-nil means add anything-source text-property in each candidate.
248 ;; `anything-debug-forms'
249 ;; Forms to show in `anything-debug-output'.
250 ;; `anything-debug'
251 ;; If non-nil, write log message into *Anything Log* buffer.
252 ;; `anything-test-candidate-list'
253 ;; Not documented.
254 ;; `anything-test-mode'
255 ;; Not documented.
256 ;; `anything-source-name'
257 ;; Not documented.
258 ;; `anything-candidate-buffer-alist'
259 ;; Not documented.
260 ;; `anything-check-minibuffer-input-timer'
261 ;; Not documented.
262 ;; `anything-match-hash'
263 ;; Not documented.
264 ;; `anything-cib-hash'
265 ;; Not documented.
266 ;; `anything-tick-hash'
267 ;; Not documented.
268 ;; `anything-issued-errors'
269 ;; Not documented.
270 ;; `anything-shortcut-keys'
271 ;; Not documented.
272 ;; `anything-once-called-functions'
273 ;; Not documented.
274 ;; `anything-follow-mode'
275 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
276 ;; `anything-let-variables'
277 ;; Not documented.
278 ;; `anything-split-window-state'
279 ;; Not documented.
280 ;; `anything-last-log-file'
281 ;; Not documented.
282 ;; `anything-compile-source-functions'
283 ;; Functions to compile elements of `anything-sources' (plug-in).
284 ;; `anything-quit'
285 ;; Not documented.
286 ;; `anything-additional-attributes'
287 ;; List of all `anything' attributes.
288 ;; `anything-buffers'
289 ;; All of `anything-buffer' in most recently used order.
290 ;; `anything-current-position'
291 ;; Restore or save current position in `anything-current-buffer'.
292 ;; `anything-last-frame-or-window-configuration'
293 ;; Used to store window or frame configuration when anything start.
294 ;; `anything-reading-pattern'
295 ;; Whether in `read-string' in anything or not.
296 ;; `anything-compile-source-functions-default'
297 ;; Plug-ins this file provides.
298 ;; `anything-input-local'
299 ;; Not documented.
300 ;; `anything-process-delayed-sources-timer'
301 ;; Not documented.
302 ;; `anything-mode-line-string-real'
303 ;; Not documented.
304 ;; `anything-exit-status'
305 ;; Flag to inform whether anything have aborted or quitted.
306 ;; `anything-types'
307 ;; Not documented.
308 ;; `anything-orig-enable-shortcuts'
309 ;; Not documented.
310 ;; `anything-persistent-action-display-window'
311 ;; Return the window that will be used for presistent action.
312 ;; `anything-visible-mark-face'
313 ;; Not documented.
314 ;; `anything-visible-mark-overlays'
315 ;; Not documented.
316 ;; `anything-marked-candidates'
317 ;; Return marked candidates of current source if any.
318 ;; `anything-maintainer-mail-address'
319 ;; Not documented.
320 ;; `anything-bug-report-salutation'
321 ;; Not documented.
322 ;; `anything-no-dump-variables'
323 ;; Variables not to dump in bug report.
325 ;; *** END auto-documentation
327 ;; [EVAL] (autodoc-update-all)
330 ;;; Commentary:
333 ;; Start with M-x anything, narrow the list by typing some pattern,
334 ;; select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter,
335 ;; left/right moves between sources. With TAB actions can be selected
336 ;; if the selected candidate has more than one possible action.
338 ;; Note that anything.el provides only the framework and some example
339 ;; configurations for demonstration purposes. See anything-config.el
340 ;; for practical, polished, easy to use configurations which can be
341 ;; used to assemble a custom personalized configuration. And many
342 ;; other configurations are in the EmacsWiki.
344 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-config.el
345 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingSources
347 ;; Maintainer's configuration is in the EmacsWiki. It would tell you
348 ;; many tips to write smart sources!
350 ;; http://www.emacswiki.org/cgi-bin/emacs/RubikitchAnythingConfiguration
352 ;; Here is Japanese translation of `anything-sources' attributes. Thanks.
353 ;; http://d.hatena.ne.jp/sirocco634/20091012/1255336649
356 ;;; Bug Report:
358 ;; If you have problems, send a bug report via C-c C-x C-b in anything session (best)
359 ;; or M-x anything-send-bug-report outside anything session.
360 ;; I implemented bug report feature because I want to know your current state.
361 ;; It helps me to solve problems easily.
362 ;; The step is:
363 ;; 0) Setup mail in Emacs, the easiest way is:
364 ;; (setq user-mail-address "your@mail.address")
365 ;; (setq user-full-name "Your Full Name")
366 ;; (setq smtpmail-smtp-server "your.smtp.server.jp")
367 ;; (setq mail-user-agent 'message-user-agent)
368 ;; (setq message-send-mail-function 'message-smtpmail-send-it)
369 ;; 1) Be sure to use the LATEST version of anything.el.
370 ;; 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
371 ;; 3) Use Lisp version instead of compiled one: (load "anything.el")
372 ;; 4) Do it!
373 ;; 5) If you got an error, please do not close *Backtrace* buffer.
374 ;; 6) Type C-c C-x C-b (anything session, best!)
375 ;; or M-x anything-send-bug-report (outside)
376 ;; then M-x insert-buffer *Backtrace* (if you got error)
377 ;; 7) Describe the bug using a precise recipe.
378 ;; 8) Type C-c C-c to send.
379 ;; # If you are a Japanese, please write in Japanese:-)
382 ;; You can extend `anything' by writing plug-ins. As soon as
383 ;; `anything' is invoked, `anything-sources' is compiled into basic
384 ;; attributes, then compiled one is used during invocation.
386 ;; The oldest built-in plug-in is `type' attribute: appends
387 ;; appropriate element of `anything-type-attributes'. Second built-in
388 ;; plug-in is `candidates-in-buffer': selecting a line from candidates
389 ;; buffer.
391 ;; To write a plug-in:
392 ;; 1. Define a compiler: anything-compile-source--*
393 ;; 2. Add compier function to `anything-compile-source-functions'.
394 ;; 3. (optional) Write helper functions.
396 ;; Anything plug-ins are found in the EmacsWiki.
398 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
400 ;; Tested on Emacs 22/23/24.
403 ;; Thanks to Vagn Johansen for ideas.
404 ;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
405 ;; Thanks to Tassilo Horn for fixes.
406 ;; Thanks to Drew Adams for various fixes
407 ;; Thanks to IMAKADO for candidates-in-buffer idea.
408 ;; Thanks to Tomohiro MATSUYAMA for multiline patch.
411 ;;; (@* "Index")
413 ;; If you have library `linkd.el', load
414 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
415 ;; navigate around the sections Linkd mode will
416 ;; highlight this Index. You can get `linkd.el' here:
417 ;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
421 ;;; (@* "Tips")
424 ;; `anything' accepts keyword arguments. See docstring.
425 ;; [EVAL IT] (describe-function 'anything)
428 ;; `anything-enable-shortcuts' enables us to select candidate easily.
429 ;; If 'prefix then they can be selected using <prefix-key> <alnum>.
430 ;; The prefix key is `anything-select-with-prefix-shortcut'.
431 ;; If the <prefix-key> is a letter, pressing twice inputs the letter itself.
432 ;; e.g.
433 ;; (setq anything-enable-shortcuts 'prefix)
434 ;; (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
437 ;; You can edit current selection using `anything-edit-current-selection'.
438 ;; It is useful after persistent-action.
441 ;; For `anything' users, setting `anything-sources' directly and
442 ;; invoke M-x anything is obsolete way for now. Try M-x
443 ;; `anything-migrate-sources'!
446 ;; If you want to create anything sources, yasnippet would help you.
447 ;; http://yasnippet.googlecode.com/
449 ;; Then get the snippet from
450 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
452 ;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
456 ;; `anything-interpret-value' is useful function to interpret value
457 ;; like `candidates' attribute.
459 ;; (anything-interpret-value "literal") ; => "literal"
460 ;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
461 ;; (let ((source '((name . "lambda with source name"))))
462 ;; (anything-interpret-value
463 ;; (lambda () anything-source-name)
464 ;; source)) ; => "lambda with source name"
465 ;; (flet ((f () "function symbol"))
466 ;; (anything-interpret-value 'f)) ; => "function symbol"
467 ;; (let ((v "variable symbol"))
468 ;; (anything-interpret-value 'v)) ; => "variable symbol"
469 ;; (anything-interpret-value 'unbounded-1) ; error
472 ;; Now symbols are acceptable as candidates. So you do not have to use
473 ;; `symbol-name' function. The source is much simpler. For example,
474 ;; `apropos-internal' returns a list of symbols.
476 ;; (anything
477 ;; '(((name . "Commands")
478 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
479 ;; (volatile)
480 ;; (action . describe-function))))
483 ;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
484 ;; marked candidate, press M-[ or M-].
487 ;; `anything-map' is now Emacs-standard key bindings by default.
489 ;; There are many `anything' applications, using `anything' for
490 ;; selecting candidate. In this case, if there is one candidate or no
491 ;; candidate, popping up *anything* buffer is irritating. If one
492 ;; candidate, you want to select it at once. If no candidate, you want
493 ;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
494 ;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
495 ;; that setting these variables GLOBALLY is bad idea because of
496 ;; delayed sources. These are meant to be let-binded.
497 ;; See anything-etags.el for example.
499 ;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
501 ;; ex.
502 ;; (let ((anything-execute-action-at-once-if-one t)
503 ;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
504 ;; (anything temporary-sources input))
507 ;; `set-frame-configuration' arises flickering. If you hate
508 ;; flickering, eval:
509 ;; (setq anything-save-configuration-functions
510 ;; '(set-window-configuration . current-window-configuration))
511 ;; at the cost of restoring frame configuration (only window configuration).
514 ;; `anything-delete-current-selection' deletes the current line.
515 ;; It is useful when deleting a candidate in persistent action.
516 ;; eg. `kill-buffer'.
518 ;; [EVAL IT] (describe-function 'anything-delete-current-selection)
521 ;; `anything-attr' gets the attribute. `anything-attrset' sets the
522 ;; attribute. `anything-attr-defined' tests whether the attribute is
523 ;; defined. They handles source-local variables.
525 ;; [EVAL IT] (describe-function 'anything-attr)
526 ;; [EVAL IT] (describe-function 'anything-attrset)
527 ;; [EVAL IT] (describe-function 'anything-attr-defined)
530 ;; `anything-sources' accepts many attributes to make your life easier.
531 ;; Now `anything-sources' accepts a list of symbols.
533 ;; [EVAL IT] (describe-variable 'anything-sources)
536 ;; `anything' has optional arguments. Now you do not have to let-bind
537 ;; `anything-sources'.
539 ;; [EVAL IT] (describe-function 'anything)
542 ;; `anything-resume' resumes last `anything' session. Now you do not
543 ;; have to retype pattern.
545 ;; [EVAL IT] (describe-function 'anything-resume)
548 ;; `anything-execute-persistent-action' executes action without
549 ;; quitting `anything'. When popping up a buffer in other window by
550 ;; persistent action, you can scroll with `anything-scroll-other-window' and
551 ;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
553 ;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
554 ;; [EVAL IT] (describe-variable 'anything-sources)
557 ;; `anything-select-2nd-action', `anything-select-3rd-action' and
558 ;; `anything-select-4th-action' select other than default action
559 ;; without pressing Tab.
562 ;; Using `anything-candidate-buffer' and the candidates-in-buffer
563 ;; attribute is much faster than traditional "candidates and match"
564 ;; way. And `anything-current-buffer-is-modified' avoids to
565 ;; recalculate candidates for unmodified buffer. See docstring of
566 ;; them.
568 ;; [EVAL IT] (describe-function 'anything-candidate-buffer)
569 ;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
570 ;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
573 ;; `anything-current-buffer' and `anything-buffer-file-name' stores
574 ;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
575 ;; is invoked. Use them freely.
577 ;; [EVAL IT] (describe-variable 'anything-current-buffer)
578 ;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
581 ;; `anything-completing-read' and `anything-read-file-name' are
582 ;; experimental implementation. If you are curious, type M-x
583 ;; anything-read-string-mode. It is a minor mode and toggles on/off.
586 ;; Use `anything-test-candidates' to test your handmade anything
587 ;; sources. It simulates contents of *anything* buffer with pseudo
588 ;; `anything-sources' and `anything-pattern', without side-effect. So
589 ;; you can unit-test your anything sources! Let's TDD!
591 ;; [EVAL IT] (describe-function 'anything-test-candidates)
593 ;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
594 ;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
596 ;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
597 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
598 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
601 ;; If you want to create anything sources, see anything-config.el.
602 ;; It is huge collection of sources. You can learn from examples.
605 ;; (@* "TODO")
607 ;; - process status indication
609 ;; - async sources doesn't honor digit-shortcut-count
611 ;; - anything-candidate-number-limit can't be nil everywhere
613 ;; (@* "HISTORY")
615 ;; Change log of this file is found at
616 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything.el
618 ;; Change log of this project is found at
619 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
624 ;;; Code:
626 (require 'cl)
628 (defvar anything-version "1.3.4")
630 ;; (@* "User Configuration")
633 ;;; Variables
636 ;; [DEPRECATED]
637 ;; A default value is provided in anything-config.el
638 (defvar anything-sources nil
639 "A list of sources to use with `anything'.
640 It is deprecated, you should not use this.
641 Use instead individual sources or list of sources of your choice.")
643 ;; Default values are provided in anything-config.el.
644 (defvar anything-type-attributes nil
645 "It's a list of \(TYPE ATTRIBUTES ...\).
646 ATTRIBUTES are the same as attributes for `anything-sources'.
647 TYPE connects the value to the appropriate sources.
648 Don't set this directly, use instead `define-anything-type-attribute'.
650 This allows specifying common attributes for several sources.
651 For example, sources which provide files can specify
652 common attributes with a `file' type.")
654 (defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
655 "Same as `anything-enable-shortcuts'.
656 Alphabet shortcuts are available now in `anything-enable-shortcuts'.
657 `anything-enable-digit-shortcuts' is retained for compatibility.")
659 (defvar anything-enable-shortcuts nil
660 "*Whether to use digit/alphabet shortcut to select the first nine matches.
661 If t then they can be selected using Ctrl+<number>.
663 If 'prefix then they can be selected using <prefix-key> <alnum>.
664 The prefix key is `anything-select-with-prefix-shortcut'.
665 If the <prefix-key> is a letter, pressing twice inputs the letter itself.
666 e.g.
667 (setq anything-enable-shortcuts 'prefix)
668 (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
670 If 'alphabet then they can be selected using Shift+<alphabet> (deprecated).
671 It is not recommended because you cannot input capital letters in pattern.
673 Keys (digit/alphabet) are listed in `anything-shortcut-keys-alist'.")
675 (defvar anything-shortcut-keys-alist
676 '((alphabet . "asdfghjklzxcvbnmqwertyuiop")
677 (prefix . "asdfghjklzxcvbnmqwertyuiop1234567890")
678 (t . "123456789")))
680 (defvar anything-display-source-at-screen-top t
681 "*Display candidates at the top of screen.
682 This happen when using `anything-next-source' and `anything-previous-source'.")
684 (defvar anything-candidate-number-limit 50
685 "*Limit candidate number globally.
686 Do not show more candidates than this limit from individual sources.
687 It is usually pointless to show hundreds of matches
688 when the pattern is empty, because it is much simpler to type a
689 few characters to narrow down the list of potential candidates.
691 Set it to nil if you don't want this limit.")
693 (defvar anything-idle-delay 0.3
694 "*Be idle for this many seconds, before updating in delayed sources.
695 This is useful for sources involving heavy operations
696 \(like launching external programs\), so that candidates
697 from the source are not retrieved unnecessarily if the user keeps typing.
699 It also can be used to declutter the results anything displays,
700 so that results from certain sources are not shown with every
701 character typed, only if the user hesitates a bit.")
703 (defvar anything-input-idle-delay 0.3
704 "Be idle for this many seconds, before updating.
706 Unlike `anything-idle-delay', it is also effective for non-delayed sources.
707 If nil, candidates are collected immediately.
709 Note: If this value is too low compared to `anything-idle-delay',
710 you may have duplicated sources when using multiples sources.
711 Safe value is always >= `anything-idle-delay'.
712 Default settings are equal value for both.")
714 (defvar anything-samewindow nil
715 "Use current window to show the candidates.
716 If t then Anything doesn't pop up a new window.")
718 (defvar anything-source-filter nil
719 "A list of source names to be displayed.
720 Other sources won't appear in the search results.
721 If nil then there is no filtering.
722 See also `anything-set-source-filter'.")
725 (defvar anything-map
726 (let ((map (copy-keymap minibuffer-local-map)))
727 (define-key map (kbd "<down>") 'anything-next-line)
728 (define-key map (kbd "<up>") 'anything-previous-line)
729 (define-key map (kbd "C-n") 'anything-next-line)
730 (define-key map (kbd "C-p") 'anything-previous-line)
731 (define-key map (kbd "<prior>") 'anything-previous-page)
732 (define-key map (kbd "<next>") 'anything-next-page)
733 (define-key map (kbd "M-v") 'anything-previous-page)
734 (define-key map (kbd "C-v") 'anything-next-page)
735 (define-key map (kbd "M-<") 'anything-beginning-of-buffer)
736 (define-key map (kbd "M->") 'anything-end-of-buffer)
737 (define-key map (kbd "C-g") 'anything-keyboard-quit)
738 (define-key map (kbd "<right>") 'anything-next-source)
739 (define-key map (kbd "<left>") 'anything-previous-source)
740 (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
741 (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
742 (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
743 (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
744 (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
745 (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
746 (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
747 (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
748 (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
749 (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
750 (loop for c from ?A to ?Z do
751 (define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
752 (define-key map (kbd "C-i") 'anything-select-action)
753 (define-key map (kbd "C-z") 'anything-execute-persistent-action)
754 (define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
755 (define-key map (kbd "C-j") 'anything-select-3rd-action)
756 (define-key map (kbd "C-o") 'anything-next-source)
757 (define-key map (kbd "C-M-v") 'anything-scroll-other-window)
758 (define-key map (kbd "M-<next>") 'anything-scroll-other-window)
759 (define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
760 (define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
761 (define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
762 (define-key map (kbd "<C-M-down>") 'anything-scroll-other-window)
763 (define-key map (kbd "<C-M-up>") 'anything-scroll-other-window-down)
764 (define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
765 (define-key map (kbd "M-[") 'anything-prev-visible-mark)
766 (define-key map (kbd "M-]") 'anything-next-visible-mark)
767 (define-key map (kbd "C-k") 'anything-delete-minibuffer-contents)
769 (define-key map (kbd "C-r") 'undefined)
770 (define-key map (kbd "C-t") 'anything-toggle-resplit-window)
771 (define-key map (kbd "C-}") 'anything-narrow-window)
772 (define-key map (kbd "C-{") 'anything-enlarge-window)
774 (define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
775 (define-key map (kbd "C-c C-y") 'anything-yank-selection)
776 (define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
777 (define-key map (kbd "C-c C-f") 'anything-follow-mode)
778 (define-key map (kbd "C-c C-u") 'anything-force-update)
779 (define-key map (kbd "M-p") 'previous-history-element)
780 (define-key map (kbd "M-n") 'next-history-element)
781 ;; Debugging command
782 (define-key map "\C-c\C-x\C-d" 'anything-debug-output)
783 (define-key map "\C-c\C-x\C-m" 'anything-display-all-visible-marks)
784 (define-key map "\C-c\C-x\C-b" 'anything-send-bug-report-from-anything)
785 ;; Use `describe-mode' key in `global-map'.
786 (define-key map [f1] nil) ; Allow to eval keymap whithout errors.
787 (dolist (k (where-is-internal 'describe-mode global-map))
788 (define-key map k 'anything-help))
789 map)
790 "Keymap for anything.")
793 (defgroup anything nil
794 "Open anything."
795 :prefix "anything-" :group 'convenience)
797 (defface anything-header
798 '((t (:inherit header-line)))
799 "Face for header lines in the anything buffer."
800 :group 'anything)
802 (defvar anything-header-face 'anything-header
803 "*Face for header lines in the anything buffer.")
805 (defface anything-candidate-number
806 '((t (:background "Yellow" :foreground "black")))
807 "Face for candidate number in mode-line." :group 'anything)
809 (defvar anything-selection-face 'highlight
810 "*Face for currently selected item.")
812 (defvar anything-buffer "*anything*"
813 "Buffer showing completions.")
815 (defvar anything-action-buffer "*anything action*"
816 "Buffer showing actions.")
818 (defvar anything-selection-overlay nil
819 "Overlay used to highlight the currently selected item.")
821 (defvar anything-digit-overlays nil
822 "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
824 (defvar anything-candidate-cache nil
825 "Holds the available candidate withing a single anything invocation.")
827 (defvar anything-pattern
828 "The input pattern used to update the anything buffer.")
830 (defvar anything-input
831 "The input typed in the candidates panel.")
833 (defvar anything-async-processes nil
834 "List of information about asynchronous processes managed by anything.")
836 (defvar anything-digit-shortcut-count 0
837 "Number of digit shortcuts shown in the anything buffer.")
839 (defvar anything-before-initialize-hook nil
840 "Run before anything initialization.
841 This hook is run before init functions in `anything-sources'.")
843 (defvar anything-after-initialize-hook nil
844 "Run after anything initialization.
845 Global variables are initialized and the anything buffer is created.
846 But the anything buffer has no contents.")
848 (defvar anything-update-hook nil
849 "Run after the anything buffer was updated according the new input pattern.
850 This hook is run at the beginning of buffer.
851 The first candidate is selected after running this hook.
852 See also `anything-after-update-hook'.")
854 (defvar anything-after-update-hook nil
855 "Run after the anything buffer was updated according the new input pattern.
856 This is very similar to `anything-update-hook' but selection is not moved.
857 It is useful to select a particular object instead of the first one.")
859 (defvar anything-cleanup-hook nil
860 "Run after anything minibuffer is closed.
861 IOW this hook is executed BEFORE performing action.")
863 (defvar anything-before-action-hook nil
864 "Run before executing action.
865 Contrarily to `anything-cleanup-hook',
866 this hook run before anything minibuffer is closed
867 and before performing action.")
869 (defvar anything-after-action-hook nil
870 "Run after executing action.")
872 (defvar anything-after-persistent-action-hook nil
873 "Run after executing persistent action.")
875 (defvar anything-move-selection-before-hook nil
876 "Run before moving selection in `anything-buffer'.")
878 (defvar anything-move-selection-after-hook nil
879 "Run after moving selection in `anything-buffer'.")
881 (defvar anything-restored-variables
882 '( anything-candidate-number-limit
883 anything-source-filter
884 anything-source-in-each-line-flag
885 anything-map
886 anything-sources)
887 "Variables which are restored after `anything' invocation.")
889 (defvar anything-saved-selection nil
890 "Value of the currently selected object when the action list is shown.")
892 (defvar anything-current-prefix-arg nil
893 "Record `current-prefix-arg' when exiting minibuffer.")
895 (defvar anything-candidate-separator
896 "--------------------"
897 "Candidates separator of `multiline' source.")
899 (defvar anything-current-buffer nil
900 "Current buffer when `anything' is invoked.")
902 (defvar anything-buffer-file-name nil
903 "Variable `buffer-file-name' when `anything' is invoked.")
905 (defvar anything-saved-action nil
906 "Saved value of the currently selected action by key.")
908 (defvar anything-last-sources nil
909 "OBSOLETE!! Sources of previously invoked `anything'.")
911 (defvar anything-saved-current-source nil
912 "Value of the current source when the action list is shown.")
914 (defvar anything-compiled-sources nil
915 "Compiled version of `anything-sources'.")
917 (defvar anything-in-persistent-action nil
918 "Flag whether in persistent-action or not.")
920 (defvar anything-quick-update nil
921 "If non-nil, suppress displaying sources which are out of screen at first.
922 They are treated as delayed sources at this input.
923 This flag makes `anything' a bit faster with many sources.")
925 (defvar anything-last-sources-local nil
926 "Buffer local value of `anything-sources'.")
928 (defvar anything-last-buffer nil
929 "`anything-buffer' of previously `anything' session.")
931 (defvar anything-save-configuration-functions
932 '(set-window-configuration . current-window-configuration)
933 "The functions used to restore/save window or frame configurations.
934 It is a pair where the car is the function to restore window or frame config,
935 and the cdr is the function to save the window or frame config.
937 If you want to save and restore frame configuration, set this variable to
938 '\(set-frame-configuration . current-frame-configuration\)
940 Older version saves/restores frame configuration, but the default is changed now
941 because flickering can occur in some environment. ")
943 (defvar anything-persistent-action-use-special-display nil
944 "If non-nil, use `special-display-function' in persistent action.")
946 (defvar anything-execute-action-at-once-if-one nil
947 "Execute default action and exit when only one candidate is remaining.
948 It is useful for `anything' applications.")
950 (defvar anything-quit-if-no-candidate nil
951 "Quit when there is no candidates when non--nil.
952 This variable accepts a function, which is executed if no candidate.
954 It is useful for `anything' applications.")
956 (defvar anything-scroll-amount nil
957 "Scroll amount when scrolling other window in an anything session.
958 It is used by `anything-scroll-other-window'
959 and `anything-scroll-other-window-down'.
961 If you prefer scrolling line by line, set this value to 1.")
963 (defvar anything-display-function 'anything-default-display-buffer
964 "Function to display *anything* buffer.
965 It is `anything-default-display-buffer' by default,
966 which affects `anything-samewindow'.")
968 (defvar anything-delayed-init-executed nil)
970 (defvar anything-mode-line-string "\\<anything-map>\\[anything-help]:help \
971 \\[anything-select-action]:Acts \
972 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
973 \\[anything-select-3rd-action]:NthAct \
974 \\[anything-send-bug-report-from-anything]:BugReport"
975 "Help string displayed in mode-line in `anything'.
976 It can be a string or a list of two args, in this case,
977 first arg is a string that will be used as name for candidates number,
978 second arg any string to display in mode line.
979 If nil, use default `mode-line-format'.")
981 (defvar anything-help-message
982 "\\<anything-map>The keys that are defined for `anything' are:
983 \\{anything-map}"
984 "Detailed help message string for `anything'.
985 It also accepts function or variable symbol.")
987 ;; FIXME: What is this
988 ;(put 'anything 'timid-completion 'disabled)
990 (defvar anything-source-in-each-line-flag nil
991 "Non-nil means add anything-source text-property in each candidate.
992 experimental feature.")
994 (defvaralias 'anything-debug-variables 'anything-debug-forms)
996 (defvar anything-debug-forms nil
997 "Forms to show in `anything-debug-output'.
998 Otherwise all variables started with `anything-' are shown.
999 It is useful for debug.")
1001 (defvar anything-debug nil
1002 "If non-nil, write log message into *Anything Log* buffer.
1003 If `debug-on-error' is non-nil, write log message regardless of this variable.
1004 It is disabled by default because *Anything Log* grows quickly.")
1007 ;; (@* "Internal Variables")
1008 (defvar anything-test-candidate-list nil)
1009 (defvar anything-test-mode nil)
1010 (defvar anything-source-name nil)
1011 (defvar anything-candidate-buffer-alist nil)
1012 (defvar anything-check-minibuffer-input-timer nil)
1013 (defvar anything-match-hash (make-hash-table :test 'equal))
1014 (defvar anything-cib-hash (make-hash-table :test 'equal))
1015 (defvar anything-tick-hash (make-hash-table :test 'equal))
1016 (defvar anything-issued-errors nil)
1017 (defvar anything-shortcut-keys nil)
1018 (defvar anything-once-called-functions nil)
1019 (defvar anything-follow-mode nil)
1020 (defvar anything-let-variables nil)
1021 (defvar anything-split-window-state nil)
1024 ;; (@* "Utility: logging")
1025 (defun anything-log (format-string &rest args)
1026 "Log message if `debug-on-error' or `anything-debug' is non-nil.
1027 Messages are written to the *Anything Log* buffer.
1029 Argument FORMAT-STRING is a string to use with `format'.
1030 Use optional arguments ARGS like in `format'."
1031 (when (or debug-on-error anything-debug)
1032 (with-current-buffer (get-buffer-create "*Anything Log*")
1033 (buffer-disable-undo)
1034 (set (make-local-variable 'inhibit-read-only) t)
1035 (goto-char (point-max))
1036 (insert (let ((tm (current-time)))
1037 (format "%s.%06d (%s) %s\n"
1038 (format-time-string "%H:%M:%S" tm)
1039 (nth 2 tm)
1040 (anything-log-get-current-function)
1041 (apply #'format (cons format-string args))))))))
1043 (defmacro anything-log-eval (&rest exprs)
1044 "Write each EXPRS evaluation result to the *Anything Log* buffer."
1045 `(anything-log-eval-internal ',exprs))
1047 (defun anything-log-run-hook (hook)
1048 "Run HOOK like `run-hooks' but write these actions to anything log buffer."
1049 (anything-log "executing %s" hook)
1050 (when (boundp hook)
1051 (anything-log-eval (symbol-value hook))
1052 (anything-log-eval (default-value hook)))
1053 (run-hooks hook)
1054 (anything-log "executed %s" hook))
1056 (defun anything-log-eval-internal (exprs)
1057 "Eval EXPRS and write results to anything log buffer."
1058 (dolist (expr exprs)
1059 (condition-case err
1060 (anything-log "%S = %S" expr (eval expr))
1061 (error (anything-log "%S = ERROR!" expr)))))
1063 (defun anything-log-get-current-function ()
1064 "Get function name calling `anything-log'.
1065 The original idea is from `tramp-debug-message'."
1066 (loop with exclude-func-re = "^anything-\\(?:interpret\\|log\\|.*funcall\\)"
1067 for btn from 1 to 40 ;avoid inf-loop
1068 for btf = (second (backtrace-frame btn))
1069 for fn = (if (symbolp btf) (symbol-name btf) "")
1070 if (and (string-match "^anything" fn)
1071 (not (string-match exclude-func-re fn)))
1072 return fn))
1074 (defun anything-log-error (&rest args)
1075 "Accumulate error messages into `anything-issued-errors'.
1076 ARGS are args given to `format'."
1077 (apply 'anything-log (concat "ERROR: " (car args)) (cdr args))
1078 (let ((msg (apply 'format args)))
1079 (unless (member msg anything-issued-errors)
1080 (add-to-list 'anything-issued-errors msg))))
1082 (defvar anything-last-log-file nil)
1083 (defun anything-log-save-maybe ()
1084 "May be save log buffer to `anything-last-log-file'."
1085 (when (stringp anything-debug)
1086 (let ((logdir (expand-file-name (format-time-string "%Y%m%d")
1087 anything-debug)))
1088 (make-directory logdir t)
1089 (with-current-buffer (get-buffer-create "*Anything Log*")
1090 (write-region (point-min) (point-max)
1091 (setq anything-last-log-file
1092 (expand-file-name (format-time-string "%Y%m%d-%H%M%S")
1093 logdir))
1094 nil 'silent)
1095 (erase-buffer)))))
1097 (defun anything-open-last-log ()
1098 "Open anything log file of last anything session."
1099 (interactive)
1100 (if anything-last-log-file
1101 (view-file anything-last-log-file)
1102 (switch-to-buffer "*Anything Log*")))
1104 (defun anything-print-error-messages ()
1105 "Print error messages in `anything-issued-errors'."
1106 (message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))
1108 ;; (anything-log "test")
1109 ;; (switch-to-buffer-other-window "*Anything Log*")
1112 ;; (@* "Programming Tools")
1113 (defmacro anything-aif (test-form then-form &rest else-forms)
1114 "Like `if' but set the result of TEST-FORM in a temprary variable called `it'.
1115 THEN-FORM and ELSE-FORMS are then excuted just like in `if'."
1116 (declare (indent 2) (debug t))
1117 `(let ((it ,test-form))
1118 (if it ,then-form ,@else-forms)))
1120 (defun anything-mklist (obj)
1121 "If OBJ is a list \(but not lambda\), return itself.
1122 Otherwise make a list with one element."
1123 (if (and (listp obj) (not (functionp obj)))
1125 (list obj)))
1128 ;; (@* "Anything API")
1130 (defun anything-buffer-get ()
1131 "Return `anything-action-buffer' if shown otherwise `anything-buffer'."
1132 (if (anything-action-window)
1133 anything-action-buffer
1134 anything-buffer))
1136 (defun anything-window ()
1137 "Window of `anything-buffer'."
1138 (get-buffer-window (anything-buffer-get) 'visible))
1140 (defun anything-action-window ()
1141 "Window of `anything-action-buffer'."
1142 (get-buffer-window anything-action-buffer 'visible))
1144 (defmacro with-anything-window (&rest body)
1145 "Be sure BODY is excuted in the anything window."
1146 (declare (indent 0) (debug t))
1147 `(if anything-test-mode
1148 (with-current-buffer (anything-buffer-get)
1149 ,@body)
1150 (with-selected-window (anything-window)
1151 ,@body)))
1153 (defmacro with-anything-current-buffer (&rest body)
1154 "Eval BODY inside `anything-current-buffer'."
1155 (declare (indent 0) (debug t))
1156 `(with-current-buffer anything-current-buffer
1157 ,@body))
1159 (defmacro with-anything-restore-variables(&rest body)
1160 "Restore `anything-restored-variables' after executing BODY.
1161 `post-command-hook' is handled specially."
1162 (declare (indent 0) (debug t))
1163 `(let ((--orig-vars (mapcar (lambda (v)
1164 (cons v (symbol-value v)))
1165 anything-restored-variables))
1166 (--post-command-hook-pair (cons post-command-hook
1167 (default-value 'post-command-hook))))
1168 (setq post-command-hook '(t))
1169 (setq-default post-command-hook nil)
1170 (unwind-protect (progn ,@body)
1171 (loop for (var . value) in --orig-vars
1172 do (set var value))
1173 (setq post-command-hook (car --post-command-hook-pair))
1174 (setq-default post-command-hook (cdr --post-command-hook-pair))
1175 (anything-log "restore variables"))))
1177 (defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
1178 "Get the value of ATTRIBUTE-NAME of SRC.
1179 if SRC is omitted, use current source.
1180 It is useful to write your sources."
1181 (anything-aif (assq attribute-name src)
1182 (cdr it)))
1184 (defun* anything-attr* (attribute-name &optional (src (anything-get-current-source)))
1185 "Pass the value of ATTRIBUTE-NAME of SRC to `anything-interpret-value'.
1186 if SRC is omitted, use current source.
1187 It is useful to write your sources."
1188 (anything-interpret-value (anything-attr attribute-name src)))
1190 (defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
1191 "Return non-nil if ATTRIBUTE-NAME of SRC is defined.
1192 if SRC is omitted, use current source.
1193 It is useful to write your sources."
1194 (and (assq attribute-name src) t))
1196 (defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
1197 "Set the value of ATTRIBUTE-NAME of SRC to VALUE.
1198 if SRC is omitted, use current source.
1199 It is useful to write your sources."
1200 (anything-aif (assq attribute-name src)
1201 (setcdr it value)
1202 (setcdr src (cons (cons attribute-name value) (cdr src))))
1203 value)
1205 (defun anything-set-source-filter (sources)
1206 "Set the value of `anything-source-filter' to SOURCES and update.
1208 This function sets a filter for anything sources and it may be
1209 called while anything is running. It can be used to toggle
1210 displaying of sources dinamically. For example, additional keys
1211 can be bound into `anything-map' to display only the file-related
1212 results if there are too many matches from other sources and
1213 you're after files only:
1215 Shift+F shows only file results from some sources:
1217 \(define-key anything-map \"F\" 'anything-my-show-files-only)
1219 \(defun anything-my-show-files-only ()
1220 (interactive)
1221 (anything-set-source-filter '(\"File Name History\"
1222 \"Files from Current Directory\")))
1224 Shift+A shows all results:
1226 \(define-key anything-map \"A\" 'anything-my-show-all)
1228 \(defun anything-my-show-all ()
1229 (interactive)
1230 (anything-set-source-filter nil))
1232 Note that you have to prefix the functions with anything- prefix,
1233 otherwise they won't be bound when Anything is used under
1234 Iswitchb. The -my- part is added to avoid collisions with
1235 existing Anything function names."
1236 (unless (and (listp sources)
1237 (loop for name in sources always (stringp name)))
1238 (error "Invalid data in `anything-set-source-filter': %S" sources))
1239 (setq anything-source-filter sources)
1240 (anything-log-eval anything-source-filter)
1241 (anything-update))
1243 (defun anything-set-sources (sources &optional no-init no-update)
1244 "Set SOURCES during `anything' invocation.
1245 If NO-INIT is non-nil, skip executing init functions of SOURCES.
1246 If NO-UPDATE is non-nil, skip executing `anything-update'."
1247 (with-current-buffer anything-buffer
1248 (setq anything-compiled-sources nil
1249 anything-sources sources
1250 anything-last-sources-local sources)
1251 (anything-log-eval anything-compiled-sources anything-sources))
1252 (unless no-init (anything-funcall-foreach 'init))
1253 (unless no-update (anything-update)))
1255 (defvar anything-compile-source-functions
1256 '(anything-compile-source--type
1257 anything-compile-source--dummy
1258 anything-compile-source--disable-shortcuts
1259 anything-compile-source--candidates-in-buffer)
1260 "Functions to compile elements of `anything-sources' (plug-in).")
1262 (defun anything-get-sources ()
1263 "Return compiled `anything-sources', which is memoized.
1265 Attributes:
1267 - type
1268 `anything-type-attributes' are merged in.
1269 - candidates-buffer
1270 candidates, volatile and match attrubute are created."
1271 (cond
1272 ;; action
1273 ((anything-action-window)
1274 anything-sources)
1275 ;; memoized
1276 (anything-compiled-sources)
1277 ;; first time
1279 (prog1
1280 (setq anything-compiled-sources
1281 (anything-compile-sources
1282 anything-sources anything-compile-source-functions))
1283 (anything-log-eval anything-compiled-sources)))))
1285 (defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
1286 "Return the currently selected item or nil.
1287 if BUFFER is nil or unspecified, use anything-buffer as default value.
1288 If FORCE-DISPLAY-PART is non-nil, return the display string."
1289 (setq buffer (if (and buffer buffer-s) buffer anything-buffer))
1290 (unless (anything-empty-buffer-p buffer)
1291 (with-current-buffer buffer
1292 (let ((selection
1293 (or (and (not force-display-part)
1294 (get-text-property (overlay-start
1295 anything-selection-overlay)
1296 'anything-realvalue))
1297 (let ((disp (buffer-substring-no-properties
1298 (overlay-start anything-selection-overlay)
1299 (1- (overlay-end anything-selection-overlay))))
1300 (source (anything-get-current-source)))
1301 (anything-aif (and (not force-display-part)
1302 (assoc-default 'display-to-real source))
1303 (anything-funcall-with-source source it disp)
1304 disp)))))
1305 (unless (equal selection "")
1306 (anything-log-eval selection)
1307 selection)))))
1309 (defun anything-get-action ()
1310 "Return the associated action for the selected candidate.
1311 It is a function symbol \(sole action\) or list
1312 of \(action-display . function\)."
1313 (unless (anything-empty-buffer-p (anything-buffer-get))
1314 (anything-aif (anything-attr 'action-transformer)
1315 (anything-composed-funcall-with-source
1316 (anything-get-current-source) it
1317 (anything-attr 'action) (anything-get-selection))
1318 (anything-attr 'action))))
1320 (defun anything-get-current-source ()
1321 "Return the source for the current selection.
1322 Use it in init, candidates, action, candidate-transformer,
1323 filtered-candidate-transformer functions."
1324 (declare (special source))
1325 ;; The name `anything-get-current-source' should be used in init function etc.
1326 (if (and (boundp 'anything-source-name) (stringp anything-source-name))
1327 source
1328 (with-current-buffer (anything-buffer-get)
1329 (or (get-text-property (point) 'anything-source)
1330 (block exit
1331 ;; This goto-char shouldn't be necessary, but point is moved to
1332 ;; point-min somewhere else which shouldn't happen.
1333 (goto-char (overlay-start anything-selection-overlay))
1334 (let* ((header-pos (or (anything-get-previous-header-pos)
1335 (anything-get-next-header-pos)))
1336 (source-name
1337 (save-excursion
1338 (unless header-pos
1339 ;(message "No candidates")
1340 (return-from exit nil))
1341 (goto-char header-pos)
1342 (anything-current-line-contents))))
1343 (some (lambda (source)
1344 (if (equal (assoc-default 'name source) source-name)
1345 source))
1346 (anything-get-sources))))))))
1348 (defun anything-buffer-is-modified (buffer)
1349 "Return non-nil when BUFFER is modified since `anything' was invoked."
1350 (let* ((b (get-buffer buffer))
1351 (key (concat (buffer-name b) "/" (anything-attr 'name)))
1352 (source-tick (or (gethash key anything-tick-hash) 0))
1353 (buffer-tick (buffer-chars-modified-tick b))
1354 (modifiedp (/= source-tick buffer-tick)))
1355 (puthash key buffer-tick anything-tick-hash)
1356 (anything-log-eval buffer modifiedp)
1357 modifiedp))
1359 (defun anything-current-buffer-is-modified ()
1360 "Check if `anything-current-buffer' is modified since `anything' was invoked."
1361 (anything-buffer-is-modified anything-current-buffer))
1363 (defvar anything-quit nil)
1364 (defun anything-run-after-quit (function &rest args)
1365 "Perform an action after quitting `anything'.
1366 The action is to call FUNCTION with arguments ARGS."
1367 (setq anything-quit t)
1368 (anything-log-eval function args)
1369 (apply 'run-with-idle-timer 0 nil function args)
1370 (anything-exit-minibuffer))
1373 (defun define-anything-type-attribute (type definition &optional doc)
1374 "Register type attribute of TYPE as DEFINITION with DOC.
1375 DOC is displayed in `anything-type-attributes' docstring.
1377 Use this function is better than setting `anything-type-attributes' directly."
1378 (loop for i in definition do
1379 ;; without `ignore-errors', error at emacs22
1380 (ignore-errors (setf i (delete nil i))))
1381 (anything-add-type-attribute type definition)
1382 (and doc (anything-document-type-attribute type doc))
1383 nil)
1385 (defvaralias 'anything-attributes 'anything-additional-attributes)
1386 (defvar anything-additional-attributes nil
1387 "List of all `anything' attributes.")
1388 (defun anything-document-attribute (attribute short-doc &optional long-doc)
1389 "Register ATTRIBUTE documentation introduced by plug-in.
1390 SHORT-DOC is displayed beside attribute name.
1391 LONG-DOC is displayed below attribute name and short documentation."
1392 (declare (indent 2) (debug t))
1393 (if long-doc
1394 (setq short-doc (concat "(" short-doc ")"))
1395 (setq long-doc short-doc
1396 short-doc ""))
1397 (add-to-list 'anything-additional-attributes attribute t)
1398 (put attribute 'anything-attrdoc
1399 (concat "- " (symbol-name attribute)
1400 " " short-doc "\n\n" long-doc "\n")))
1403 (defun anything-interpret-value (value &optional source)
1404 "Interpret VALUE as variable, function or literal.
1405 If VALUE is a function, call it with no arguments and return the value.
1406 If SOURCE is `anything' source, `anything-source-name' is source name.
1408 If VALUE is a variable, return the value.
1410 If VALUE is a symbol, but it is not a function or a variable, cause an error.
1412 Otherwise, return VALUE itself."
1413 (cond ((and source (functionp value))
1414 (anything-funcall-with-source source value))
1415 ((functionp value)
1416 (funcall value))
1417 ((and (symbolp value) (boundp value))
1418 (symbol-value value))
1419 ((symbolp value)
1420 (error "anything-interpret-value: Symbol must be a function or a variable"))
1422 value)))
1424 (defun anything-once (function &rest args)
1425 "Ensure FUNCTION with ARGS to be called once in `anything' session."
1426 (let ((spec (cons function args)))
1427 (unless (member spec anything-once-called-functions)
1428 (apply function args)
1429 (push spec anything-once-called-functions))))
1432 ;; (@* "Core: API helper")
1433 (defun* anything-empty-buffer-p (&optional (buffer anything-buffer))
1434 "Check if BUFFER have candidates.
1435 Default value for BUFFER is `anything-buffer'."
1436 (zerop (buffer-size (and buffer (get-buffer buffer)))))
1438 (defun anything-let-eval-varlist (varlist)
1439 "Return the list of pairs VARLIST with each cdr of pair evaluated.
1440 If VARLIST contain single elements, those are returned
1441 as a list of one element."
1442 (mapcar (lambda (pair)
1443 (if (listp pair)
1444 (cons (car pair) (eval (cadr pair)))
1445 (cons pair nil)))
1446 varlist))
1448 ;; [NOT USED]
1449 ;; (defun anything-let*-eval-varlist (varlist)
1450 ;; (let ((vars (mapcar (lambda (pair)
1451 ;; (or (car-safe pair) pair))
1452 ;; varlist)))
1453 ;; (eval `(let ,vars
1454 ;; ,@(mapcar (lambda (pair)
1455 ;; (if (listp pair)
1456 ;; `(setq ,(car pair) ,(cadr pair))
1457 ;; `(setq ,pair nil)))
1458 ;; varlist)
1459 ;; (mapcar (lambda (v)
1460 ;; (cons v (symbol-value v)))
1461 ;; ',vars)))))
1463 (defun anything-let-internal (binding bodyfunc)
1464 "Set BINDING to anything buffer-local variables and Evaluate BODYFUNC.
1465 BINDING is a list of \(VARNAME . VALUE\) pair."
1466 (setq anything-let-variables binding)
1467 (unwind-protect
1468 (funcall bodyfunc)
1469 (setq anything-let-variables nil)))
1472 ;; (@* "Core: tools")
1473 (defun anything-current-line-contents ()
1474 "Current line string without properties."
1475 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1477 (defun anything-funcall-with-source (source func &rest args)
1478 "Call from SOURCE FUNC list or single function FUNC with ARGS.
1479 FUNC can be a symbol or a list of functions.
1480 Return the result of last function call."
1481 (let ((anything-source-name (assoc-default 'name source))
1482 result)
1483 (anything-log-eval anything-source-name func args)
1484 (dolist (func (if (functionp func) (list func) func) result)
1485 (setq result (apply func args)))))
1487 (defun anything-funcall-foreach (sym)
1488 "Call the function SYM for each source if any."
1489 (dolist (source (anything-get-sources))
1490 (anything-aif (assoc-default sym source)
1491 (anything-funcall-with-source source it))))
1493 (defun anything-normalize-sources (sources)
1494 "If SOURCES is only one source, make a list of one element."
1495 (cond ((or (and sources
1496 (symbolp sources))
1497 (and (listp sources) (assq 'name sources)))
1498 (list sources))
1499 (sources)
1500 (t anything-sources)))
1502 (defun anything-approximate-candidate-number (&optional in-current-source)
1503 "Return approximate number of candidates in `anything-buffer'.
1504 If IN-CURRENT-SOURCE is provided return number of candidates
1505 in the source where point is.
1506 It is used to check if candidate number is 0, 1, or 2+."
1507 (with-current-buffer anything-buffer
1508 (save-excursion
1509 (if in-current-source
1510 (goto-char (anything-get-previous-header-pos))
1511 (goto-char (point-min)))
1512 (forward-line 1)
1513 (let ((count-multi 1))
1514 (if (anything-pos-multiline-p)
1515 (save-excursion
1516 (loop while (and (not (if in-current-source
1517 (save-excursion
1518 (forward-line 2)
1519 (or (anything-pos-header-line-p) (eobp)))
1520 (eobp)))
1521 (search-forward anything-candidate-separator nil t))
1522 do (incf count-multi)
1523 finally return count-multi))
1524 (save-excursion
1525 (loop with ln = 0
1526 while (not (if in-current-source
1527 (or (anything-pos-header-line-p) (eobp))
1528 (eobp)))
1529 unless (anything-pos-header-line-p)
1530 do (incf ln)
1531 do (forward-line 1) finally return ln)))))))
1533 (defmacro with-anything-quittable (&rest body)
1534 "If an error occur in execution of BODY, quit anything safely."
1535 (declare (indent 0) (debug t))
1536 `(let (inhibit-quit)
1537 (condition-case v
1538 (progn ,@body)
1539 (quit (setq anything-quit t)
1540 (exit-minibuffer)
1541 (keyboard-quit)))))
1543 (defun anything-compose (arg-lst func-lst)
1544 "Apply arguments specified in ARG-LST with each function of FUNC-LST.
1545 The result of each function will be the new `car' of ARG-LST.
1547 This function allows easy sequencing of transformer functions."
1548 (dolist (func func-lst)
1549 (setcar arg-lst (apply func arg-lst)))
1550 (car arg-lst))
1552 (defun anything-composed-funcall-with-source (source funcs &rest args)
1553 "With SOURCE apply `anything-funcall-with-source' with each FUNCS and ARGS.
1554 This is used in transformers to modify candidates list."
1555 (if (functionp funcs)
1556 (apply 'anything-funcall-with-source source funcs args)
1557 (apply 'anything-funcall-with-source source
1558 (lambda (&rest args)
1559 (anything-compose args funcs))
1560 args)))
1562 (defun anything-new-timer (variable timer)
1563 "Give VARIABLE value to TIMER and cancel old timer."
1564 (anything-aif (symbol-value variable)
1565 (cancel-timer it))
1566 (set variable timer))
1569 ;; (@* "Core: entry point")
1570 (defconst anything-argument-keys
1571 '(:sources :input :prompt :resume :preselect :buffer :keymap :default :history))
1573 (make-obsolete 'anything 'anything-1 "anything 1.3.5")
1574 ;;;###autoload
1575 (defun anything (&rest plist)
1576 "Main function to execute anything sources.
1578 When call interactively with no arguments deprecated `anything-sources'
1579 will be used if non--nil.
1581 PLIST is a list like \(:key1 val1 :key2 val2 ...\) or
1582 \(&optional sources input prompt resume preselect buffer keymap\).
1584 Basic keywords are the following:
1586 \:sources
1588 Temporary value of `anything-sources'. It also accepts a
1589 symbol, interpreted as a variable of an anything source. It
1590 also accepts an alist representing an anything source, which is
1591 detected by \(assq 'name ANY-SOURCES\)
1593 \:input
1595 Temporary value of `anything-pattern', ie. initial input of minibuffer.
1597 \:prompt
1599 Prompt other than \"pattern: \".
1601 \:resume
1603 If t, Resurrect previously instance of `anything'. Skip the initialization.
1604 If 'noresume, this instance of `anything' cannot be resumed.
1606 \:preselect
1608 Initially selected candidate. Specified by exact candidate or a regexp.
1609 Note that it is not working with delayed sources.
1611 \:buffer
1613 `anything-buffer' instead of *anything*.
1615 \:keymap
1617 `anything-map' for current `anything' session.
1619 \:default
1621 A default argument that will be inserted in minibuffer \
1622 with \\<minibuffer-local-map>\\[next-history-element].
1623 When nil of not present `thing-at-point' will be used instead.
1625 \:history
1627 By default all minibuffer input is pushed to `minibuffer-history',
1628 if an argument HISTORY is provided, input will be pushed to HISTORY.
1629 History element should be a symbol.
1631 Of course, conventional arguments are supported, the two are same.
1633 \(anything :sources sources :input input :prompt prompt :resume resume
1634 :preselect preselect :buffer buffer :keymap keymap\)
1635 \(anything sources input prompt resume preselect buffer keymap\)
1637 Other keywords are interpreted as local variables of this anything session.
1638 The `anything-' prefix can be omitted. For example,
1640 \(anything :sources 'anything-c-source-buffers
1641 :buffer \"*buffers*\" :candidate-number-limit 10\)
1643 means starting anything session with `anything-c-source-buffers'
1644 source in *buffers* buffer and set variable `anything-candidate-number-limit'
1645 to 10 as session local variable."
1646 (interactive)
1647 (if (keywordp (car plist))
1648 (anything-let-internal
1649 (anything-parse-keys plist)
1650 (lambda ()
1651 (apply 'anything
1652 (mapcar (lambda (key) (plist-get plist key))
1653 anything-argument-keys))))
1654 (apply 'anything-internal plist)))
1656 (defun anything-parse-keys (keys)
1657 "Parse the KEYS arguments of `anything'."
1658 (loop for (key value &rest _) on keys by #'cddr
1659 for symname = (substring (symbol-name key) 1)
1660 for sym = (intern (if (string-match "^anything-" symname)
1661 symname
1662 (concat "anything-" symname)))
1663 unless (memq key anything-argument-keys)
1664 collect (cons sym value)))
1666 (defun* anything-1 (&key sources input prompt resume
1667 preselect buffer keymap default history)
1668 "A simplified version of `anything' non--interactive.
1669 See documentation of `anything' for more info."
1670 (anything-internal sources input prompt resume
1671 preselect buffer keymap default history))
1673 ;;; (@* "Core: entry point helper")
1674 (defun anything-internal (&optional
1675 any-sources any-input
1676 any-prompt any-resume
1677 any-preselect any-buffer
1678 any-keymap any-default any-history)
1679 "The internal anything function called by `anything'.
1680 For ANY-SOURCES ANY-INPUT ANY-PROMPT ANY-RESUME ANY-PRESELECT ANY-BUFFER and
1681 ANY-KEYMAP ANY-DEFAULT ANY-HISTORY See `anything'."
1682 (anything-log (concat "[Start session] " (make-string 41 ?+)))
1683 (anything-log-eval any-prompt any-preselect
1684 any-buffer any-keymap any-default)
1685 (unwind-protect
1686 (condition-case v
1687 (let (;; It is needed because `anything-source-name' is non-nil
1688 ;; when `anything' is invoked by action. Awful global scope.
1689 anything-source-name
1690 anything-in-persistent-action
1691 anything-quit
1692 (case-fold-search t)
1693 (anything-buffer (or any-buffer anything-buffer))
1694 ;; cua-mode ; avoid error when region is selected
1696 (with-anything-restore-variables
1697 (anything-initialize any-resume any-input any-sources)
1698 (anything-display-buffer anything-buffer)
1699 (anything-log "show prompt")
1700 (unwind-protect
1701 (anything-read-pattern-maybe
1702 any-prompt any-input any-preselect
1703 any-resume any-keymap any-default)
1704 (anything-cleanup)))
1705 (prog1 (unless anything-quit
1706 (anything-execute-selection-action-1 any-history))
1707 (anything-log (concat "[End session] " (make-string 41 ?-)))))
1708 (quit
1709 (anything-restore-position-on-quit)
1710 (anything-log (concat "[End session (quit)] " (make-string 34 ?-)))
1711 nil))
1712 (anything-log-save-maybe)))
1715 ;;; Anything resume
1718 (defun* anything-resume (&optional
1719 (any-buffer anything-last-buffer)
1720 buffer-pattern (any-resume t))
1721 "Resurrect previously invoked `anything'.
1722 Called with a prefix arg, allow choosing among all existing
1723 anything buffers. i.e choose among various anything sessions."
1724 (interactive)
1725 (when (or current-prefix-arg buffer-pattern)
1726 (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
1727 (setq anything-compiled-sources nil)
1728 (anything-1
1729 :sources (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
1730 anything-last-sources anything-sources)
1731 :input (buffer-local-value 'anything-input-local (get-buffer any-buffer))
1732 :resume any-resume
1733 :buffer any-buffer))
1735 ;;; rubikitch: experimental
1736 ;;; I use this and check it whether I am convenient.
1737 ;;; I may introduce an option to control the behavior.
1738 (defun* anything-resume-window-only (&optional
1739 (any-buffer anything-last-buffer)
1740 buffer-pattern)
1741 (interactive)
1742 (anything-resume any-buffer buffer-pattern 'window-only))
1744 (defun anything-resume-p (any-resume)
1745 "Whether current anything session is resumed or not.
1746 Just check if ANY-RESUME value is t or window-only."
1747 (memq any-resume '(t window-only)))
1749 (defun anything-resume-select-buffer (input)
1750 "Resume precedent anything session with initial input INPUT."
1751 (or (anything-1 :sources '(((name . "Resume anything buffer")
1752 (candidates . anything-buffers)
1753 (action . identity)))
1754 :input input
1755 :resume 'noresume
1756 :buffer "*anything resume*")
1757 (keyboard-quit)))
1760 ;;;###autoload
1761 (defun anything-at-point (&optional
1762 any-sources any-input
1763 any-prompt any-resume
1764 any-preselect any-buffer)
1765 "Call anything with symbol at point as initial input.
1766 ANY-SOURCES ANY-INPUT ANY-PROMPT ANY-RESUME ANY-PRESELECT and ANY-BUFFER
1767 are same args as in `anything'."
1768 (interactive)
1769 (anything-1 :sources any-sources
1770 :input (if current-prefix-arg
1771 (concat "\\b" (thing-at-point 'symbol) "\\b"
1772 (if (featurep 'anything-match-plugin) " " ""))
1773 any-input)
1774 :prompt any-prompt
1775 :resume any-resume
1776 :preselect any-preselect
1777 :buffer any-buffer))
1779 ;;;###autoload
1780 (defun anything-other-buffer (any-sources any-buffer)
1781 "Simplified interface of `anything' with other `anything-buffer'.
1782 Call `anything' with only ANY-SOURCES and ANY-BUFFER as args."
1783 (anything-1 :sources any-sources :buffer any-buffer))
1786 ;;; Initialize
1789 (defvar anything-buffers nil
1790 "All of `anything-buffer' in most recently used order.")
1791 (defun anything-initialize (any-resume any-input any-sources)
1792 "Start initialization of `anything' session.
1793 For ANY-RESUME ANY-INPUT and ANY-SOURCES See `anything'."
1794 (anything-log "start initialization: any-resume=%S any-input=%S" any-resume any-input)
1795 (anything-frame-or-window-configuration 'save)
1796 (setq anything-sources (anything-normalize-sources any-sources))
1797 (anything-log "sources = %S" anything-sources)
1798 (anything-hooks 'setup)
1799 (anything-current-position 'save)
1800 (if (anything-resume-p any-resume)
1801 (anything-initialize-overlays (anything-buffer-get))
1802 (anything-initial-setup))
1803 (unless (eq any-resume 'noresume)
1804 (anything-recent-push anything-buffer 'anything-buffers)
1805 (setq anything-last-buffer anything-buffer))
1806 (when any-input (setq anything-input any-input anything-pattern any-input))
1807 (and (anything-resume-p any-resume) (anything-funcall-foreach 'resume))
1808 (anything-log "end initialization"))
1810 ;; Here defun* allow using implicit block `anything-execute-selection-action-1'.
1811 (defun* anything-execute-selection-action-1 (&optional history)
1812 "Execute current action.
1813 Push current input to HISTORY if present, otherwise
1814 `minibuffer-history' will be used instead."
1815 (anything-log-run-hook 'anything-before-action-hook)
1816 (unwind-protect
1817 (anything-execute-selection-action)
1818 (anything-aif (get-buffer anything-action-buffer)
1819 (kill-buffer it))
1820 (when (and history (symbolp history) (not (string= anything-pattern "")))
1821 (set history (cons anything-pattern (symbol-value history))))
1822 (anything-log-run-hook 'anything-after-action-hook)))
1824 (defun anything-restore-position-on-quit ()
1825 "Restore position in `anything-current-buffer' when quitting."
1826 (anything-current-position 'restore))
1828 (defun anything-recent-push (elt list-var)
1829 "Add ELT to the value of LIST-VAR as most recently used value."
1830 (let ((m (member elt (symbol-value list-var))))
1831 (and m (set list-var (delq (car m) (symbol-value list-var))))
1832 (push elt (symbol-value list-var))))
1835 ;;; (@* "Core: Accessors")
1836 ;;; rubikitch: I love to create functions to control variables.
1837 (defvar anything-current-position nil
1838 "Cons of \(point . window-start\) when `anything' is invoked.
1839 It is needed to restore position in `anything-current-buffer'
1840 when `anything' is keyboard-quitted.")
1841 (defun anything-current-position (save-or-restore)
1842 "Restore or save current position in `anything-current-buffer'.
1843 Argument SAVE-OR-RESTORE is one of save or restore."
1844 (case save-or-restore
1845 (save
1846 (anything-log "Save position at %S" (cons (point) (window-start)))
1847 (setq anything-current-position (cons (point) (window-start))))
1848 (restore
1849 (anything-log "Restore position at %S in buffer %s"
1850 anything-current-position
1851 (buffer-name (current-buffer)))
1852 (goto-char (car anything-current-position))
1853 ;; Fix this position with the NOFORCE arg of `set-window-start'
1854 ;; otherwise, if there is some other buffer than `anything-current-buffer'
1855 ;; one, position will be lost.
1856 (set-window-start (selected-window) (cdr anything-current-position) t))))
1859 ;; Internal.
1860 (defvar anything-last-frame-or-window-configuration nil
1861 "Used to store window or frame configuration when anything start.")
1862 (defun anything-frame-or-window-configuration (save-or-restore)
1863 "Save or restore last frame or window configuration.
1864 Possible value of SAVE-OR-RESTORE are 'save and 'restore.
1865 window or frame configuration is saved/restored according to values of
1866 `anything-save-configuration-functions'."
1867 (anything-log-eval anything-save-configuration-functions)
1868 (case save-or-restore
1869 (save (setq anything-last-frame-or-window-configuration
1870 (funcall (cdr anything-save-configuration-functions))))
1871 (restore (funcall (car anything-save-configuration-functions)
1872 anything-last-frame-or-window-configuration)
1873 ;; Restore frame focus.
1874 (let ((frame (and (listp anything-last-frame-or-window-configuration)
1875 (caadr anything-last-frame-or-window-configuration))))
1876 ;; If `anything-save-configuration-functions' are window functions
1877 ;; frame should be nil, use current frame.
1878 (unless (framep frame)
1879 (setq frame (selected-frame)))
1880 (select-frame-set-input-focus frame)))))
1883 ;; (@* "Core: Display *anything* buffer")
1884 (defun anything-display-buffer (buf)
1885 "Display *anything* buffer BUF."
1886 (let (pop-up-frames)
1887 (funcall (with-current-buffer buf anything-display-function) buf)))
1889 (defun anything-default-display-buffer (buf)
1890 "Default function to display BUF.
1891 Where BUF is generally `anything-buffer'.
1892 It use `switch-to-buffer' or `pop-to-buffer' depending of value of
1893 `anything-samewindow'."
1894 (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
1897 ;; (@* "Core: initialize")
1898 (defun anything-initial-setup ()
1899 "Initialize anything settings and set up the anything buffer."
1900 (anything-log-run-hook 'anything-before-initialize-hook)
1901 (setq anything-current-prefix-arg nil)
1902 (setq anything-once-called-functions nil)
1903 (setq anything-delayed-init-executed nil)
1904 (setq anything-current-buffer
1905 (if (minibuffer-window-active-p (minibuffer-window))
1906 ;; If minibuffer is active be sure to use it's buffer
1907 ;; as `anything-current-buffer'.
1908 (window-buffer (active-minibuffer-window))
1909 (current-buffer)))
1910 (setq anything-buffer-file-name buffer-file-name)
1911 (setq anything-issued-errors nil)
1912 (setq anything-compiled-sources nil)
1913 (setq anything-saved-current-source nil)
1914 (if (or (not split-width-threshold)
1915 (and (integerp split-width-threshold)
1916 (>= split-width-threshold (+ (frame-width) 4))))
1917 (setq anything-split-window-state 'vertical)
1918 (setq anything-split-window-state 'horizontal))
1919 ;; Call the init function for sources where appropriate
1920 (anything-funcall-foreach 'init)
1921 (setq anything-pattern "")
1922 (setq anything-input "")
1923 (setq anything-candidate-cache nil)
1924 (setq anything-last-sources anything-sources)
1925 (anything-create-anything-buffer)
1926 (anything-log-run-hook 'anything-after-initialize-hook))
1928 (defvar anything-reading-pattern nil
1929 "Whether in `read-string' in anything or not.")
1930 (defun anything-read-pattern-maybe (any-prompt any-input
1931 any-preselect any-resume any-keymap any-default)
1932 "Read pattern with prompt ANY-PROMPT and initial input ANY-INPUT.
1933 For ANY-PRESELECT ANY-RESUME ANY-KEYMAP, See `anything'."
1934 (if (anything-resume-p any-resume)
1935 (anything-mark-current-line)
1936 (anything-update any-preselect))
1937 (with-current-buffer (anything-buffer-get)
1938 (and any-keymap (set (make-local-variable 'anything-map) any-keymap))
1939 (let ((minibuffer-local-map
1940 anything-map))
1941 (anything-log-eval (anything-approximate-candidate-number)
1942 anything-execute-action-at-once-if-one
1943 anything-quit-if-no-candidate)
1944 (cond ((and anything-execute-action-at-once-if-one
1945 (= (anything-approximate-candidate-number) 1))
1946 (ignore))
1947 ((and anything-quit-if-no-candidate
1948 (= (anything-approximate-candidate-number) 0))
1949 (setq anything-quit t)
1950 (and (functionp anything-quit-if-no-candidate)
1951 (funcall anything-quit-if-no-candidate)))
1953 (let ((anything-reading-pattern t)
1954 (tap (or any-default
1955 (with-anything-current-buffer
1956 (thing-at-point 'symbol)))))
1957 (read-string (or any-prompt "pattern: ") any-input nil tap)))))))
1959 (defun anything-create-anything-buffer (&optional test-mode)
1960 "Create newly created `anything-buffer'.
1961 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
1962 (when test-mode
1963 (setq anything-candidate-cache nil))
1964 (with-current-buffer (get-buffer-create anything-buffer)
1965 (anything-log "kill local variables: %S" (buffer-local-variables))
1966 (kill-all-local-variables)
1967 (set (make-local-variable 'inhibit-read-only) t)
1968 (buffer-disable-undo)
1969 (erase-buffer)
1970 (set (make-local-variable 'inhibit-read-only) t)
1971 (set (make-local-variable 'anything-last-sources-local) anything-sources)
1972 (set (make-local-variable 'anything-follow-mode) nil)
1973 (set (make-local-variable 'anything-display-function) anything-display-function)
1974 (anything-initialize-persistent-action)
1975 (anything-log-eval anything-display-function anything-let-variables)
1976 (loop for (var . val) in anything-let-variables
1977 do (set (make-local-variable var) val))
1978 (setq cursor-type nil)
1979 (setq mode-name "Anything"))
1980 (anything-initialize-overlays anything-buffer)
1981 (get-buffer anything-buffer))
1983 (defun anything-initialize-overlays (buffer)
1984 "Initialize anything overlays in BUFFER."
1985 (anything-log "overlay setup")
1986 (if anything-selection-overlay
1987 ;; make sure the overlay belongs to the anything buffer if
1988 ;; it's newly created
1989 (move-overlay anything-selection-overlay (point-min) (point-min)
1990 (get-buffer buffer))
1992 (setq anything-selection-overlay
1993 (make-overlay (point-min) (point-min) (get-buffer buffer)))
1994 (overlay-put anything-selection-overlay 'face anything-selection-face))
1996 (cond (anything-enable-shortcuts
1997 (setq anything-shortcut-keys
1998 (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist))
1999 (unless anything-digit-overlays
2000 (setq anything-digit-overlays
2001 (loop for key across anything-shortcut-keys
2002 for overlay = (make-overlay (point-min) (point-min)
2003 (get-buffer buffer))
2004 do (overlay-put overlay 'before-string
2005 (format "%s - " (upcase (make-string 1 key))))
2006 collect overlay))))
2007 (anything-digit-overlays
2008 (mapc 'delete-overlay anything-digit-overlays)
2009 (setq anything-digit-overlays nil))))
2011 (defun anything-hooks (setup-or-cleanup)
2012 "Add or remove hooks according to SETUP-OR-CLEANUP value.
2013 if SETUP-OR-CLEANUP value is setup add hooks, any other value
2014 will remove hooks.
2015 hooks concerned are `post-command-hook' and `minibuffer-setup-hook'."
2016 (let ((hooks '((post-command-hook anything-check-minibuffer-input)
2017 (minibuffer-setup-hook anything-print-error-messages))))
2018 (if (eq setup-or-cleanup 'setup)
2019 (dolist (args hooks) (apply 'add-hook args))
2020 (dolist (args (reverse hooks)) (apply 'remove-hook args)))))
2023 ;; (@* "Core: clean up")
2024 ;;; TODO move
2025 (defun anything-cleanup ()
2026 "Clean up the mess when anything exit or quit."
2027 (anything-log "start cleanup")
2028 (with-current-buffer anything-buffer
2029 (setq cursor-type t)
2030 ;; Call burry-buffer whithout arg
2031 ;; to remove anything-buffer from window.
2032 (bury-buffer)
2033 ;; Be sure we call this from anything-buffer.
2034 (anything-funcall-foreach 'cleanup))
2035 (anything-new-timer 'anything-check-minibuffer-input-timer nil)
2036 (anything-kill-async-processes)
2037 (anything-log-run-hook 'anything-cleanup-hook)
2038 (anything-hooks 'cleanup)
2039 (anything-frame-or-window-configuration 'restore)
2040 ;; This is needed in some cases where last input
2041 ;; is yielded infinitely in minibuffer after anything session.
2042 (anything-clean-up-minibuffer))
2044 (defun anything-clean-up-minibuffer ()
2045 "Remove contents of minibuffer."
2046 (let ((miniwin (minibuffer-window)))
2047 ;; Clean only current minibuffer used by anything.
2048 ;; i.e The precedent one is active.
2049 (unless (minibuffer-window-active-p miniwin)
2050 (with-current-buffer (window-buffer miniwin)
2051 (delete-minibuffer-contents)))))
2054 ;; (@* "Core: input handling")
2055 (defun anything-check-minibuffer-input ()
2056 "Extract input string from the minibuffer and check if it needs to be handled."
2057 (let ((delay (with-current-buffer anything-buffer anything-input-idle-delay)))
2058 (if (or (not delay) (anything-action-window))
2059 (anything-check-minibuffer-input-1)
2060 (anything-new-timer
2061 'anything-check-minibuffer-input-timer
2062 (run-with-idle-timer delay nil 'anything-check-minibuffer-input-1)))))
2064 (defun anything-check-minibuffer-input-1 ()
2065 "Check minibuffer content."
2066 (with-anything-quittable
2067 (with-selected-window (or (active-minibuffer-window) (minibuffer-window))
2068 (anything-check-new-input (minibuffer-contents)))))
2070 (defun anything-check-new-input (input)
2071 "Check INPUT string and update the anything buffer if necessary."
2072 (unless (equal input anything-pattern)
2073 (setq anything-pattern input)
2074 (unless (anything-action-window)
2075 (setq anything-input anything-pattern))
2076 (anything-log-eval anything-pattern anything-input)
2077 (anything-update)))
2080 ;; (@* "Core: source compiler")
2081 (defvar anything-compile-source-functions-default anything-compile-source-functions
2082 "Plug-ins this file provides.")
2083 (defun anything-compile-sources (sources funcs)
2084 "Compile SOURCES with FUNCS.
2085 See `anything-compile-source-functions'.
2086 Anything plug-ins are realized by this function."
2087 (mapcar
2088 (lambda (source)
2089 (loop with source = (if (listp source) source (symbol-value source))
2090 for f in funcs
2091 do (setq source (funcall f source))
2092 finally (return source)))
2093 sources))
2096 ;; (@* "Core: plug-in attribute documentation hack")
2098 ;; `anything-document-attribute' is public API.
2099 (defadvice documentation-property (after anything-document-attribute activate)
2100 "Display plug-in attributes' documentation as `anything-sources' docstring."
2101 (when (eq (ad-get-arg 0) 'anything-sources)
2102 (setq ad-return-value
2103 (concat ad-return-value "\n"
2104 (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
2105 anything-additional-attributes
2106 "\n")))))
2107 ;; (describe-variable 'anything-sources)
2108 ;; (documentation-property 'anything-sources 'variable-documentation)
2109 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
2112 ;; (@* "Core: all candidates")
2113 (defun anything-process-delayed-init (source)
2114 "Initialize delayed SOURCE."
2115 (let ((name (assoc-default 'name source)))
2116 (unless (member name anything-delayed-init-executed)
2117 (anything-aif (assoc-default 'delayed-init source)
2118 (with-current-buffer anything-current-buffer
2119 (anything-funcall-with-source source it)
2120 (dolist (f (if (functionp it) (list it) it))
2121 (add-to-list 'anything-delayed-init-executed name)))))))
2123 (defun anything-get-candidates (source)
2124 "Retrieve and return the list of candidates from SOURCE."
2125 (anything-process-delayed-init source)
2126 (let* ((candidate-source (assoc-default 'candidates source))
2127 (type-error (lambda ()
2128 (error (concat "Candidates must either be a function, "
2129 " a variable or a list: %s")
2130 candidate-source)))
2131 (candidates (condition-case err
2132 (anything-interpret-value candidate-source source)
2133 (error (funcall type-error)))))
2134 (cond ((processp candidates) candidates)
2135 ((listp candidates) (anything-transform-candidates candidates source))
2136 (t (funcall type-error)))))
2139 (defun anything-get-cached-candidates (source)
2140 "Return the cached value of candidates for SOURCE.
2141 Cache the candidates if there is not yet a cached value."
2142 (let* ((name (assoc-default 'name source))
2143 (candidate-cache (assoc name anything-candidate-cache)))
2144 (cond (candidate-cache
2145 (anything-log "use cached candidates")
2146 (cdr candidate-cache))
2148 (anything-log "calculate candidates")
2149 (let ((candidates (anything-get-candidates source)))
2150 (cond ((processp candidates)
2151 (push (cons candidates
2152 (append source
2153 (list (cons 'item-count 0)
2154 (cons 'incomplete-line ""))))
2155 anything-async-processes)
2156 (set-process-filter candidates 'anything-output-filter)
2157 (setq candidates nil))
2158 ((not (assoc 'volatile source))
2159 (setq candidate-cache (cons name candidates))
2160 (push candidate-cache anything-candidate-cache)))
2161 candidates)))))
2164 ;;; (@* "Core: candidate transformers")
2165 (defun anything-process-candidate-transformer (candidates source)
2166 "Execute candidate-transformer function on all CANDIDATES of SOURCE."
2167 (anything-aif (assoc-default 'candidate-transformer source)
2168 (anything-composed-funcall-with-source source it candidates)
2169 candidates))
2171 (defun anything-process-filtered-candidate-transformer (candidates source)
2172 "Execute filtered-candidate-transformer function on all CANDIDATES of SOURCE."
2173 (anything-aif (assoc-default 'filtered-candidate-transformer source)
2174 (anything-composed-funcall-with-source source it candidates source)
2175 candidates))
2177 (defun anything-process-filtered-candidate-transformer-maybe (candidates source process-p)
2178 "Execute filtered-candidate-transformer function on all CANDIDATES of SOURCE.
2179 This happen if PROCESS-P is non-nil."
2180 (if process-p
2181 (anything-process-filtered-candidate-transformer candidates source)
2182 candidates))
2184 (defun anything-process-real-to-display (candidates source)
2185 "Execute real-to-display function on all CANDIDATES of SOURCE."
2186 (anything-aif (assoc-default 'real-to-display source)
2187 (setq candidates (anything-funcall-with-source
2188 source 'mapcar
2189 (lambda (cand_)
2190 (if (consp cand_)
2191 ;; override DISPLAY from candidate-transformer
2192 (cons (funcall it (cdr cand_)) (cdr cand_))
2193 (cons (funcall it cand_) cand_)))
2194 candidates))
2195 candidates))
2197 (defun anything-transform-candidates (candidates source &optional process-p)
2198 "Transform CANDIDATES of SOURCE according to candidate transformers.
2199 This happen if PROCESS-P is non-nil."
2200 (anything-process-real-to-display
2201 (anything-process-filtered-candidate-transformer-maybe
2202 (anything-process-candidate-transformer candidates source) source process-p)
2203 source))
2206 ;; (@* "Core: narrowing candidates")
2207 (defun anything-candidate-number-limit (source)
2208 "Apply candidate-number-limit attribute value.
2209 This overhide variable `anything-candidate-number-limit'.
2211 e.g:
2212 If \(candidate-number-limit\) is in SOURCE, show all candidates in SOURCE.
2213 If \(candidate-number-limit . 123\) is in SOURCE limit candidate to 123."
2214 (anything-aif (assq 'candidate-number-limit source)
2215 (or (cdr it) 99999999)
2216 (or anything-candidate-number-limit 99999999)))
2218 ;; FIXME: Why a defconst here
2219 (defconst anything-default-match-functions
2220 (list (lambda (candidate)
2221 (string-match anything-pattern candidate)))
2222 "Default functions to match candidates according to `anything-pattern'.")
2224 (defun anything-compute-matches (source)
2225 "Compute matched results from SOURCE according to its settings."
2226 (if debug-on-error
2227 (anything-compute-matches-internal source)
2228 (condition-case v
2229 (anything-compute-matches-internal source)
2230 (error (anything-log-error
2231 "anything-compute-matches: error when processing source: %s"
2232 (assoc-default 'name source))
2233 nil))))
2235 (defun anything-candidate-get-display (candidate)
2236 "Get searched display part from CANDIDATE.
2237 CANDIDATE is a string, a symbol, or \(DISPLAY . REAL\) cons cell."
2238 (format "%s" (or (car-safe candidate) candidate)))
2240 (defun anything-process-pattern-transformer (pattern source)
2241 "Execute pattern-transformer attribute PATTERN function in SOURCE."
2242 (anything-aif (assoc-default 'pattern-transformer source)
2243 (anything-composed-funcall-with-source source it pattern)
2244 pattern))
2246 (defun anything-match-functions (source)
2247 (or (assoc-default 'match source)
2248 anything-default-match-functions))
2250 (defmacro anything-accumulate-candidates-internal (cand newmatches
2251 hash item-count limit)
2252 "Internal, add CAND into NEWMATCHES.
2253 Use HASH to uniq NEWMATCHES.
2254 Argument ITEM-COUNT count the matches.
2255 if ITEM-COUNT reaches LIMIT, exit from inner loop."
2256 `(unless (gethash ,cand ,hash)
2257 (puthash ,cand t ,hash)
2258 (push ,cand ,newmatches)
2259 (incf ,item-count)
2260 (when (= ,item-count ,limit)
2261 (setq exit t)
2262 (return))))
2264 (defun anything-take-first-elements (seq n)
2265 (if (> (length seq) n)
2266 (setq seq (subseq seq 0 n))
2267 seq))
2269 (defun anything-match-from-candidates (cands matchfns limit)
2270 (let (matches)
2271 (condition-case nil
2272 (let ((item-count 0) exit)
2273 (clrhash anything-match-hash)
2274 (dolist (match matchfns)
2275 (let (newmatches)
2276 (dolist (candidate cands)
2277 (when (funcall match (anything-candidate-get-display candidate))
2278 (anything-accumulate-candidates-internal
2279 candidate newmatches anything-match-hash item-count limit)))
2280 (setq matches (append matches (reverse newmatches)))
2281 (if exit (return)))))
2282 (invalid-regexp (setq matches nil)))
2283 matches))
2285 (defun anything-compute-matches-internal (source)
2286 (save-current-buffer
2287 (let ((matchfns (anything-match-functions source))
2288 (anything-source-name (assoc-default 'name source))
2289 (limit (anything-candidate-number-limit source))
2290 (anything-pattern (anything-process-pattern-transformer
2291 anything-pattern source)))
2292 (anything-process-filtered-candidate-transformer
2293 (if (or (equal anything-pattern "") (equal matchfns '(identity)))
2294 (anything-take-first-elements
2295 (anything-get-cached-candidates source) limit)
2296 (anything-match-from-candidates
2297 (anything-get-cached-candidates source) matchfns limit))
2298 source))))
2300 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2302 (defun anything-process-source (source)
2303 "Display matched results from SOURCE according to its settings."
2304 (anything-log-eval (assoc-default 'name source))
2305 (if (assq 'direct-insert-match source) ;experimental
2306 (anything-process-source--direct-insert-match source)
2307 (let ((matches (anything-compute-matches source)))
2308 (when matches
2309 (when anything-test-mode
2310 (setq anything-test-candidate-list
2311 `(,@anything-test-candidate-list
2312 (,(assoc-default 'name source)
2313 ,matches))))
2314 (anything-insert-header-from-source source)
2315 (if (not (assq 'multiline source))
2316 (mapc 'anything-insert-match-with-digit-overlay matches)
2317 (let ((start (point)) separate)
2318 (dolist (match matches)
2319 (if separate
2320 (anything-insert-candidate-separator)
2321 (setq separate t))
2322 (anything-insert-match-with-digit-overlay match))
2323 (put-text-property start (point) 'anything-multiline t)))))))
2325 (defun anything-insert-match-with-digit-overlay (match)
2326 (declare (special source))
2327 (anything-put-digit-overlay-maybe)
2328 (anything-insert-match match 'insert source))
2330 (defun anything-put-digit-overlay-maybe ()
2331 (when (and anything-enable-shortcuts
2332 (not (eq anything-digit-shortcut-count
2333 (length anything-digit-overlays))))
2334 (move-overlay (nth anything-digit-shortcut-count
2335 anything-digit-overlays)
2336 (point-at-bol)
2337 (point-at-bol))
2338 (incf anything-digit-shortcut-count)))
2340 (defun anything-process-source--direct-insert-match (source)
2341 "[EXPERIMENTAL] Insert candidates from `anything-candidate-buffer' in SOURCE."
2342 (anything-log-eval (assoc-default 'name source))
2343 (let ((anything-source-name (assoc-default 'name source))
2344 content-buf)
2345 (funcall (assoc-default 'candidates source))
2346 (setq content-buf (anything-candidate-buffer))
2347 (unless (anything-empty-buffer-p content-buf)
2348 (anything-insert-header-from-source source)
2349 (insert-buffer-substring content-buf)
2350 ;; TODO call anything-put-digit-overlay-maybe with loop
2353 (defun anything-process-delayed-sources (delayed-sources &optional preselect)
2354 "Process anything DELAYED-SOURCES.
2355 Move selection to string or regexp PRESELECT if non--nil.
2356 This function is called in `anything-process-delayed-sources-timer'
2357 when emacs is idle for `anything-idle-delay'."
2358 (with-anything-quittable
2359 (anything-log-eval (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2360 (with-current-buffer anything-buffer
2361 (save-excursion
2362 (goto-char (point-max))
2363 (mapc 'anything-process-source delayed-sources)
2364 (when (and (not (anything-empty-buffer-p))
2365 ;; No selection yet.
2366 (= (overlay-start anything-selection-overlay)
2367 (overlay-end anything-selection-overlay)))
2368 (anything-update-move-first-line 'without-hook)))
2369 (when preselect (anything-preselect preselect))
2370 (save-excursion
2371 (goto-char (point-min))
2372 (anything-log-run-hook 'anything-update-hook))
2373 (anything-log-run-hook 'anything-after-update-hook))))
2376 ;; (@* "Core: *anything* buffer contents")
2377 (defvar anything-input-local nil)
2378 (defvar anything-process-delayed-sources-timer nil)
2379 (defun anything-update (&optional preselect)
2380 "Update candidates list in `anything-buffer' according to `anything-pattern'.
2381 Argument PRESELECT is a string or regexp used to move selection to a particular
2382 place once updating is done. It should be used on single source because search
2383 is done on whole `anything-buffer' and not on current source."
2384 (anything-log "start update")
2385 (setq anything-digit-shortcut-count 0)
2386 (anything-kill-async-processes)
2387 (with-current-buffer (anything-buffer-get)
2388 (set (make-local-variable 'anything-input-local) anything-pattern)
2389 (erase-buffer)
2390 (when anything-enable-shortcuts
2391 (mapc 'delete-overlay anything-digit-overlays))
2392 (let (delayed-sources
2393 normal-sources)
2394 (unwind-protect ; Process normal sources and store delayed one's.
2395 (setq delayed-sources
2396 (loop for source in (remove-if-not 'anything-update-source-p
2397 (anything-get-sources))
2398 if (anything-delayed-source-p source)
2399 collect source
2400 else do (progn (push source normal-sources)
2401 (anything-process-source source))))
2402 (anything-log-eval
2403 (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2404 (if anything-test-mode ; Need only to process sources.
2405 (mapc 'anything-process-source delayed-sources)
2406 (cond ((and preselect delayed-sources normal-sources)
2407 ;; Preselection run here when there is
2408 ;; normal AND delayed sources.
2409 (anything-log "Update preselect candidate %s" preselect)
2410 (anything-preselect preselect))
2411 (delayed-sources ; Preselection and hooks will run later.
2412 (anything-update-move-first-line 'without-hook))
2413 (t ; No delayed sources, run the hooks now.
2414 (anything-update-move-first-line)
2415 (anything-log-run-hook 'anything-after-update-hook)
2416 (when preselect
2417 (anything-log "Update preselect candidate %s" preselect)
2418 (anything-preselect preselect))))
2419 (when delayed-sources
2420 (anything-new-timer
2421 'anything-process-delayed-sources-timer
2422 (run-with-idle-timer
2423 ;; Be sure anything-idle-delay is >
2424 ;; to anything-input-idle-delay
2425 ;; otherwise use value of anything-input-idle-delay.
2426 (max anything-idle-delay anything-input-idle-delay) nil
2427 'anything-process-delayed-sources delayed-sources preselect))))
2428 (anything-log "end update")))))
2430 (defun anything-update-source-p (source)
2431 "Wheter SOURCE need updating or not."
2432 (and (or (not anything-source-filter)
2433 (member (assoc-default 'name source) anything-source-filter))
2434 (>= (length anything-pattern)
2435 (anything-aif (assoc 'requires-pattern source)
2436 (or (cdr it) 1)
2437 0))))
2439 (defun anything-delayed-source-p (source)
2440 "Wheter SOURCE is a delayed source or not."
2441 (or (assoc 'delayed source)
2442 (and anything-quick-update
2443 (< (window-height (get-buffer-window (current-buffer)))
2444 (line-number-at-pos (point-max))))))
2446 (defun anything-update-move-first-line (&optional without-hook)
2447 "Goto first line of `anything-buffer'."
2448 (goto-char (point-min))
2449 (unless without-hook
2450 (save-excursion (anything-log-run-hook 'anything-update-hook)))
2451 (anything-next-line))
2453 (defun anything-force-update (&optional preselect)
2454 "Force recalculation and update of candidates.
2455 If current source has `update' attribute, a function without argument,
2456 call it before update."
2457 (interactive)
2458 (let ((source (anything-get-current-source))
2459 (selection (anything-get-selection nil t)))
2460 (when source
2461 (mapc 'anything-force-update--reinit
2462 (anything-get-sources)))
2463 (anything-update preselect)
2464 ;; If preselect arg exists, `anything-update' should
2465 ;; have moved to selection, otherwise do it now.
2466 (unless preselect
2467 (anything-keep-selection (assoc-default 'name source) selection))
2468 (with-anything-window (recenter))))
2470 (defun anything-force-update--reinit (source)
2471 "Reinit SOURCE by calling his update and/or init functions."
2472 (anything-aif (anything-funcall-with-source
2473 source 'anything-candidate-buffer)
2474 (kill-buffer it))
2475 (dolist (attr '(update init))
2476 (anything-aif (assoc-default attr source)
2477 (anything-funcall-with-source source it)))
2478 (anything-remove-candidate-cache source))
2480 (defun anything-keep-selection (source selection)
2481 "Switch to SOURCE and goto SELECTION."
2482 (when (and source selection)
2483 (with-anything-window
2484 (anything-goto-source source)
2485 (forward-char -1)
2486 (if (search-forward selection nil t)
2487 (forward-line 0)
2488 (goto-char (point-min))
2489 (forward-line 1))
2490 (anything-mark-current-line))))
2492 (defun anything-remove-candidate-cache (source)
2493 "Remove SOURCE from `anything-candidate-cache'."
2494 (setq anything-candidate-cache
2495 (delete (assoc (assoc-default 'name source)
2496 anything-candidate-cache)
2497 anything-candidate-cache)))
2499 (defun anything-insert-match (match insert-function source)
2500 "Insert MATCH into `anything-buffer' with INSERT-FUNCTION for SOURCE.
2501 If MATCH is a list then insert the string intended to appear on the display
2502 and store the real value in a text property."
2503 (let ((start (point-at-bol (point)))
2504 (string (or (car-safe match) match))
2505 (realvalue (cdr-safe match)))
2506 (when (symbolp string) (setq string (symbol-name string)))
2507 (when (stringp string)
2508 (funcall insert-function string)
2509 ;; Some sources with candidates-in-buffer have already added
2510 ;; 'anything-realvalue property when creating candidate buffer.
2511 (unless (get-text-property start 'anything-realvalue)
2512 (and realvalue
2513 (put-text-property start (point-at-eol)
2514 'anything-realvalue realvalue)))
2515 (when anything-source-in-each-line-flag
2516 (put-text-property start (point-at-eol) 'anything-source source))
2517 (funcall insert-function "\n"))))
2519 (defun anything-insert-header-from-source (source)
2520 "Insert SOURCE name in `anything-buffer' header.
2521 Maybe insert by overlay additional info after source name if SOURCE have
2522 header-name attribute."
2523 (let ((name (assoc-default 'name source)))
2524 (anything-insert-header
2525 name
2526 (anything-aif (assoc-default 'header-name source)
2527 (anything-funcall-with-source source it name)))))
2529 (defun anything-insert-header (name &optional display-string)
2530 "Insert header of source NAME into the anything buffer.
2531 If DISPLAY-STRING is non--nil and a string, display this additional info
2532 after the source name by overlay."
2533 (unless (bobp)
2534 (let ((start (point)))
2535 (insert "\n")
2536 (put-text-property start (point) 'anything-header-separator t)))
2537 (let ((start (point)))
2538 (insert name)
2539 (put-text-property (point-at-bol)
2540 (point-at-eol) 'anything-header t)
2541 (when display-string
2542 (overlay-put (make-overlay (point-at-bol) (point-at-eol))
2543 'display display-string))
2544 (insert "\n")
2545 (put-text-property start (point) 'face anything-header-face)))
2547 (defun anything-insert-candidate-separator ()
2548 "Insert separator of candidates into the anything buffer."
2549 (insert anything-candidate-separator)
2550 (put-text-property (point-at-bol)
2551 (point-at-eol) 'anything-candidate-separator t)
2552 (insert "\n"))
2555 ;; (@* "Core: async process")
2556 (defun anything-output-filter (process string)
2557 "From PROCESS process output STRING."
2558 (anything-output-filter-1 (assoc process anything-async-processes) string))
2560 (defun anything-output-filter-1 (process-assoc string)
2561 (anything-log-eval string)
2562 (with-current-buffer anything-buffer
2563 (let ((source (cdr process-assoc)))
2564 (save-excursion
2565 (anything-aif (assoc-default 'insertion-marker source)
2566 (goto-char it)
2567 (goto-char (point-max))
2568 (anything-insert-header-from-source source)
2569 (setcdr process-assoc
2570 (append source `((insertion-marker . ,(point-marker))))))
2571 (anything-output-filter--process-source
2572 (car process-assoc) string source
2573 (anything-candidate-number-limit source))))
2574 (anything-output-filter--post-process)))
2576 (defun anything-output-filter--process-source (process string source limit)
2577 (dolist (candidate (anything-transform-candidates
2578 (anything-output-filter--collect-candidates
2579 (split-string string "\n")
2580 (assoc 'incomplete-line source))
2581 source t))
2582 (if (not (assq 'multiline source))
2583 (anything-insert-match candidate 'insert-before-markers source)
2584 (let ((start (point)))
2585 (anything-insert-candidate-separator)
2586 (anything-insert-match candidate 'insert-before-markers source)
2587 (put-text-property start (point) 'anything-multiline t)))
2588 (incf (cdr (assoc 'item-count source)))
2589 (when (>= (assoc-default 'item-count source) limit)
2590 (anything-kill-async-process process)
2591 (return))))
2593 (defun anything-output-filter--collect-candidates (lines incomplete-line-info)
2594 (anything-log-eval (cdr incomplete-line-info))
2595 (butlast
2596 (loop for line in lines collect
2597 (if (cdr incomplete-line-info)
2598 (prog1
2599 (concat (cdr incomplete-line-info) line)
2600 (setcdr incomplete-line-info nil))
2601 line)
2602 finally (setcdr incomplete-line-info line))))
2604 (defun anything-output-filter--post-process ()
2605 (anything-log-run-hook 'anything-update-hook)
2606 (anything-aif (get-buffer-window anything-buffer 'visible)
2607 (save-selected-window
2608 (select-window it)
2609 (anything-skip-noncandidate-line 'next)
2610 (anything-mark-current-line))))
2612 (defun anything-kill-async-processes ()
2613 "Kill all known asynchronous processes of `anything-async-processes'."
2614 (mapc 'anything-kill-async-process (mapcar 'car anything-async-processes))
2615 (setq anything-async-processes nil))
2617 (defun anything-kill-async-process (process)
2618 "Kill PROCESS and detach the associated functions."
2619 (set-process-filter process nil)
2620 (delete-process process))
2623 ;; (@* "Core: action")
2624 (defun anything-execute-selection-action (&optional
2625 selection action
2626 preserve-saved-action)
2627 "If a candidate SELECTION is present then perform the associated ACTION on it.
2628 If PRESERVE-SAVED-ACTION is non-nil don't save action."
2629 (anything-log "executing action")
2630 (setq action (anything-get-default-action
2631 (or action
2632 anything-saved-action
2633 (if (get-buffer anything-action-buffer)
2634 (anything-get-selection anything-action-buffer)
2635 (anything-get-action)))))
2636 (let ((source (or anything-saved-current-source
2637 (anything-get-current-source))))
2638 (setq selection (or selection
2639 (anything-get-selection)
2640 (and (assoc 'accept-empty source) "")))
2641 (unless preserve-saved-action (setq anything-saved-action nil))
2642 (if (and selection action)
2643 (anything-funcall-with-source
2644 source action
2645 (anything-coerce-selection selection source)))))
2647 (defun anything-coerce-selection (selection source)
2648 "Apply coerce attribute function to SELECTION in SOURCE.
2649 Coerce source with coerce function."
2650 (anything-aif (assoc-default 'coerce source)
2651 (anything-funcall-with-source source it selection)
2652 selection))
2654 (defun anything-get-default-action (action)
2655 (if (and (listp action) (not (functionp action)))
2656 (cdar action)
2657 action))
2659 (defun anything-select-action ()
2660 "Select an action for the currently selected candidate.
2661 If action buffer is selected, back to the anything buffer."
2662 (interactive)
2663 (cond ((get-buffer-window anything-action-buffer 'visible)
2664 (set-window-buffer (get-buffer-window anything-action-buffer)
2665 anything-buffer)
2666 (kill-buffer anything-action-buffer)
2667 (anything-set-pattern anything-input 'noupdate))
2669 (setq anything-saved-selection (anything-get-selection))
2670 (unless anything-saved-selection
2671 (error "Nothing is selected"))
2672 (setq anything-saved-current-source (anything-get-current-source))
2673 (let ((actions (anything-get-action)))
2674 (if (functionp actions)
2675 (message "Sole action: %s" actions)
2676 (anything-show-action-buffer actions)
2677 (anything-delete-minibuffer-contents)
2678 (setq anything-pattern 'dummy) ; so that it differs from the previous one
2679 (anything-check-minibuffer-input))))))
2681 (defun anything-show-action-buffer (actions)
2682 (with-current-buffer (get-buffer-create anything-action-buffer)
2683 (erase-buffer)
2684 (buffer-disable-undo)
2685 (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
2686 (set (make-local-variable 'anything-sources)
2687 `(((name . "Actions")
2688 (volatile)
2689 (candidates . ,actions)
2690 (candidate-number-limit))))
2691 (set (make-local-variable 'anything-source-filter) nil)
2692 (set (make-local-variable 'anything-selection-overlay) nil)
2693 (set (make-local-variable 'anything-digit-overlays) nil)
2694 (anything-initialize-overlays anything-action-buffer)))
2697 ;; (@* "Core: selection")
2698 (defun anything-move-selection-common (move-func unit direction)
2699 "Move the selection marker to a new position wit function MOVE-FUNC.
2700 It is determined by UNIT and DIRECTION."
2701 (unless (or (anything-empty-buffer-p (anything-buffer-get))
2702 (not (anything-window)))
2703 (with-anything-window
2704 (anything-log-run-hook 'anything-move-selection-before-hook)
2705 (funcall move-func)
2706 (anything-skip-noncandidate-line direction)
2707 (anything-display-source-at-screen-top-maybe unit)
2708 (when (anything-get-previous-header-pos)
2709 (anything-mark-current-line))
2710 (anything-display-mode-line (anything-get-current-source))
2711 (anything-log-run-hook 'anything-move-selection-after-hook))))
2713 (defun anything-display-source-at-screen-top-maybe (unit)
2714 (when (and anything-display-source-at-screen-top (eq unit 'source))
2715 (set-window-start (selected-window)
2716 (save-excursion (forward-line -1) (point)))))
2718 (defun anything-skip-noncandidate-line (direction)
2719 (anything-skip-header-and-separator-line direction)
2720 (and (bobp) (forward-line 1)) ;skip first header
2721 (and (eobp) (forward-line -1))) ;avoid last empty line
2724 (defun anything-skip-header-and-separator-line (direction)
2725 (while (and (not (bobp))
2726 (or (anything-pos-header-line-p)
2727 (anything-pos-candidate-separator-p)))
2728 (forward-line (if (and (eq direction 'previous)
2729 (not (eq (point-at-bol) (point-min))))
2730 -1 1))))
2732 (defvar anything-mode-line-string-real nil)
2733 (defun anything-display-mode-line (source)
2734 (set (make-local-variable 'anything-mode-line-string)
2735 (anything-interpret-value (or (assoc-default 'mode-line source)
2736 (default-value 'anything-mode-line-string))
2737 source))
2738 (if anything-mode-line-string
2739 (setq mode-line-format
2740 '(" " mode-line-buffer-identification " "
2741 (line-number-mode "L%l") " " (anything-follow-mode "(F) ")
2742 (:eval (anything-show-candidate-number
2743 (when (listp anything-mode-line-string)
2744 (car anything-mode-line-string))))
2745 " " anything-mode-line-string-real "-%-")
2746 anything-mode-line-string-real
2747 (substitute-command-keys (if (listp anything-mode-line-string)
2748 (cadr anything-mode-line-string)
2749 anything-mode-line-string)))
2750 (setq mode-line-format
2751 (default-value 'mode-line-format)))
2752 (setq header-line-format
2753 (anything-interpret-value (assoc-default 'header-line source) source)))
2755 (defun anything-show-candidate-number (&optional name)
2756 "Used to display candidate number in mode-line.
2757 You can specify NAME of candidates e.g \"Buffers\" otherwise
2758 it is \"Candidate\(s\)\" by default."
2759 (propertize
2760 (format "[%s %s]"
2761 (anything-approximate-candidate-number 'in-current-source)
2762 (or name "Candidate(s)"))
2763 'face 'anything-candidate-number))
2765 (defun anything-previous-line ()
2766 "Move selection to the previous line."
2767 (interactive)
2768 (anything-move-selection-common
2769 (lambda ()
2770 (if (not (anything-pos-multiline-p))
2771 (forward-line -1) ;double forward-line is meaningful
2772 (forward-line -1) ;because evaluation order is important
2773 (anything-skip-header-and-separator-line 'previous)
2774 (let ((header-pos (anything-get-previous-header-pos))
2775 (separator-pos (anything-get-previous-candidate-separator-pos)))
2776 (when header-pos
2777 (goto-char (if (or (null separator-pos) (< separator-pos header-pos))
2778 header-pos ; first candidate
2779 separator-pos))
2780 (forward-line 1)))))
2781 'line 'previous))
2783 (defun anything-next-line ()
2784 "Move selection to the next line."
2785 (interactive)
2786 (anything-move-selection-common
2787 (lambda ()
2788 (if (not (anything-pos-multiline-p))
2789 (forward-line 1)
2790 (let ((header-pos (anything-get-next-header-pos))
2791 (separator-pos (anything-get-next-candidate-separator-pos)))
2792 (cond ((and separator-pos
2793 (or (null header-pos) (< separator-pos header-pos)))
2794 (goto-char separator-pos))
2795 (header-pos
2796 (goto-char header-pos))))))
2797 'line 'next))
2799 (defun anything-previous-page ()
2800 "Move selection back with a pageful."
2801 (interactive)
2802 (anything-move-selection-common
2803 (lambda ()
2804 (condition-case nil
2805 (scroll-down)
2806 (beginning-of-buffer (goto-char (point-min)))))
2807 'page 'previous))
2809 (defun anything-next-page ()
2810 "Move selection forward with a pageful."
2811 (interactive)
2812 (anything-move-selection-common
2813 (lambda ()
2814 (condition-case nil
2815 (scroll-up)
2816 (end-of-buffer (goto-char (point-max)))))
2817 'page 'next))
2819 (defun anything-beginning-of-buffer ()
2820 "Move selection at the top."
2821 (interactive)
2822 (anything-move-selection-common
2823 (lambda () (goto-char (point-min)))
2824 'edge 'previous))
2826 (defun anything-end-of-buffer ()
2827 "Move selection at the bottom."
2828 (interactive)
2829 (anything-move-selection-common
2830 (lambda () (goto-char (point-max)))
2831 'edge 'next))
2833 (defun anything-previous-source ()
2834 "Move selection to the previous source."
2835 (interactive)
2836 (anything-move-selection-common
2837 (lambda ()
2838 (forward-line -1)
2839 (if (bobp)
2840 (goto-char (point-max))
2841 (anything-skip-header-and-separator-line 'previous))
2842 (goto-char (anything-get-previous-header-pos))
2843 (forward-line 1))
2844 'source 'previous))
2846 (defun anything-next-source ()
2847 "Move selection to the next source."
2848 (interactive)
2849 (anything-move-selection-common
2850 (lambda ()
2851 (goto-char (or (anything-get-next-header-pos) (point-min))))
2852 'source 'next))
2854 (defun anything-goto-source (source-or-name)
2855 "Move the selection to the source SOURCE-OR-NAME."
2856 (anything-move-selection-common
2857 (lambda ()
2858 (goto-char (point-min))
2859 (let ((name (if (stringp source-or-name) source-or-name
2860 (assoc-default 'name source-or-name))))
2861 (condition-case err
2862 (while (not (string= name (anything-current-line-contents)))
2863 (goto-char (anything-get-next-header-pos)))
2864 (error (message "")))))
2865 'source 'next))
2867 (defun anything-mark-current-line ()
2868 "Move `anything-selection-overlay' to current line.
2869 Note that this is not related with visibles marks, which are used
2870 to mark candidates."
2871 (move-overlay
2872 anything-selection-overlay (point-at-bol)
2873 (if (anything-pos-multiline-p)
2874 (let ((header-pos (anything-get-next-header-pos))
2875 (separator-pos (anything-get-next-candidate-separator-pos)))
2876 (or (and (null header-pos) separator-pos)
2877 (and header-pos separator-pos (< separator-pos header-pos)
2878 separator-pos)
2879 header-pos
2880 (point-max)))
2881 (1+ (point-at-eol))))
2882 (anything-follow-execute-persistent-action-maybe))
2884 (defun anything-this-command-key ()
2885 (event-basic-type (elt (this-command-keys-vector) 0)))
2886 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
2888 (defun anything-select-with-shortcut-internal (types get-key-func)
2889 (if (memq anything-enable-shortcuts types)
2890 (save-selected-window
2891 (select-window (anything-window))
2892 (let* ((key (funcall get-key-func))
2893 (overlay (ignore-errors (nth (position key anything-shortcut-keys)
2894 anything-digit-overlays))))
2895 (if (not (and overlay (overlay-buffer overlay)))
2896 (when (numberp key)
2897 (select-window (minibuffer-window))
2898 (self-insert-command 1))
2899 (goto-char (overlay-start overlay))
2900 (anything-mark-current-line)
2901 (anything-exit-minibuffer))))
2902 (self-insert-command 1)))
2904 (defun anything-select-with-prefix-shortcut ()
2905 "Invoke default action with prefix shortcut."
2906 (interactive)
2907 (anything-select-with-shortcut-internal
2908 '(prefix)
2909 (lambda () (read-event "Select shortcut key: "))))
2911 (defun anything-select-with-digit-shortcut ()
2912 "Invoke default action with digit/alphabet shortcut."
2913 (interactive)
2914 (anything-select-with-shortcut-internal
2915 '(alphabet t) 'anything-this-command-key))
2917 ;; (setq anything-enable-shortcuts 'prefix)
2918 ;; (define-key anything-map "@" 'anything-select-with-prefix-shortcut)
2919 ;; (define-key anything-map (kbd "<f18>") 'anything-select-with-prefix-shortcut)
2921 (defvar anything-exit-status 0
2922 "Flag to inform whether anything have aborted or quitted.
2923 Exit with 0 mean anything exit executing an action.
2924 Exit with 1 mean anything abort with \\[keyboard-quit]
2925 It is useful for example to restore a window config if anything abort
2926 in special cases.
2927 See `anything-exit-minibuffer' and `anything-keyboard-quit'.")
2929 (defun anything-exit-minibuffer ()
2930 "Select the current candidate by exiting the minibuffer."
2931 (interactive)
2932 (unless anything-current-prefix-arg
2933 (setq anything-current-prefix-arg current-prefix-arg))
2934 (setq anything-exit-status 0)
2935 (exit-minibuffer))
2937 (defun anything-keyboard-quit ()
2938 "Quit minibuffer in anything.
2939 If action buffer is displayed, kill it."
2940 (interactive)
2941 (when (get-buffer-window anything-action-buffer 'visible)
2942 (kill-buffer anything-action-buffer))
2943 (setq anything-exit-status 1)
2944 (abort-recursive-edit))
2946 (defun anything-get-next-header-pos ()
2947 "Return the position of the next header from point."
2948 (next-single-property-change (point) 'anything-header))
2950 (defun anything-get-previous-header-pos ()
2951 "Return the position of the previous header from point."
2952 (previous-single-property-change (point) 'anything-header))
2954 (defun anything-pos-multiline-p ()
2955 "Return non-nil if the current position is in the multiline source region."
2956 (get-text-property (point) 'anything-multiline))
2958 (defun anything-get-next-candidate-separator-pos ()
2959 "Return the position of the next candidate separator from point."
2960 (next-single-property-change (point) 'anything-candidate-separator))
2962 (defun anything-get-previous-candidate-separator-pos ()
2963 "Return the position of the previous candidate separator from point."
2964 (previous-single-property-change (point) 'anything-candidate-separator))
2966 (defun anything-pos-header-line-p ()
2967 "Return t if the current line is a header line."
2968 (or (get-text-property (point-at-bol) 'anything-header)
2969 (get-text-property (point-at-bol) 'anything-header-separator)))
2971 (defun anything-pos-candidate-separator-p ()
2972 "Return t if the current line is a candidate separator."
2973 (get-text-property (point-at-bol) 'anything-candidate-separator))
2976 ;; (@* "Core: help")
2977 (defun anything-help-internal (bufname insert-content-fn)
2978 "Show long message during `anything' session in BUFNAME.
2979 INSERT-CONTENT-FN is the text to be displayed in BUFNAME."
2980 (save-window-excursion
2981 (select-window (anything-window))
2982 (delete-other-windows)
2983 (switch-to-buffer (get-buffer-create bufname))
2984 (erase-buffer)
2985 (funcall insert-content-fn)
2986 (setq mode-line-format "%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
2987 (setq cursor-type nil)
2988 (goto-char 1)
2989 (anything-help-event-loop)))
2991 (defun anything-help-event-loop ()
2992 (ignore-errors
2993 (loop for event = (read-event) do
2994 (case event
2995 ((?\C-v ? ) (scroll-up))
2996 ((?\M-v ?b) (scroll-down))
2997 (t (return))))))
2999 (defun anything-help ()
3000 "Help of `anything'."
3001 (interactive)
3002 (anything-help-internal
3003 " *Anything Help*"
3004 (lambda ()
3005 (insert (substitute-command-keys
3006 (anything-interpret-value anything-help-message)))
3007 (org-mode))))
3009 (defun anything-debug-output ()
3010 "Show all anything-related variables at this time."
3011 (interactive)
3012 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function))
3014 (defun anything-debug-output-function (&optional vars)
3015 (message "Calculating all anything-related values...")
3016 (insert "If you debug some variables or forms, set `anything-debug-forms'
3017 to a list of forms.\n\n")
3018 (dolist (v (or vars
3019 anything-debug-forms
3020 (apropos-internal "^anything-" 'boundp)))
3021 (insert "** "
3022 (pp-to-string v) "\n"
3023 (pp-to-string (eval v)) "\n"))
3024 (message "Calculating all anything-related values...Done"))
3027 ;; (@* "Core: misc")
3028 (defun anything-kill-buffer-hook ()
3029 "Remove tick entry from `anything-tick-hash' when killing a buffer."
3030 (loop for key being the hash-keys in anything-tick-hash
3031 if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
3032 do (remhash key anything-tick-hash)))
3033 (add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
3035 (defun anything-preselect (candidate-or-regexp)
3036 "Move `anything-selection-overlay' to CANDIDATE-OR-REGEXP on startup."
3037 (with-anything-window
3038 (when candidate-or-regexp
3039 (goto-char (point-min))
3040 ;; go to first candidate of first source
3041 (forward-line 1)
3042 (let ((start (point)))
3043 (or (re-search-forward
3044 (concat "^" (regexp-quote candidate-or-regexp) "$") nil t)
3045 (re-search-forward candidate-or-regexp nil t)
3046 (search-forward candidate-or-regexp nil t)
3047 (goto-char start))))
3048 (anything-mark-current-line)))
3050 (defun anything-delete-current-selection ()
3051 "Delete the currently selected item."
3052 (interactive)
3053 (with-anything-window
3054 (cond ((anything-pos-multiline-p)
3055 (anything-aif (anything-get-next-candidate-separator-pos)
3056 (delete-region (point-at-bol)
3057 (1+ (progn (goto-char it) (point-at-eol))))
3058 ;; last candidate
3059 (goto-char (anything-get-previous-candidate-separator-pos))
3060 (delete-region (point-at-bol) (point-max)))
3061 (when (anything-end-of-source-p)
3062 (goto-char (or (anything-get-previous-candidate-separator-pos)
3063 (point-min)))
3064 (forward-line 1)))
3066 (delete-region (point-at-bol) (1+ (point-at-eol)))
3067 (when (anything-end-of-source-p) (forward-line -1))))
3068 (anything-mark-current-line)))
3070 (defun anything-end-of-source-p ()
3071 "Return non--nil if we are at eob or end of source."
3072 (save-excursion
3073 (forward-line 1)
3074 (or (eq (point-at-bol) (point-at-eol))
3075 (anything-pos-header-line-p)
3076 (eobp))))
3078 (defun anything-edit-current-selection-internal (func)
3079 (with-anything-window
3080 (beginning-of-line)
3081 (let ((realvalue (get-text-property (point) 'anything-realvalue)))
3082 (funcall func)
3083 (beginning-of-line)
3084 (and realvalue
3085 (put-text-property (point) (point-at-eol)
3086 'anything-realvalue realvalue))
3087 (anything-mark-current-line))))
3089 (defmacro anything-edit-current-selection (&rest forms)
3090 "Evaluate FORMS at current selection in the anything buffer.
3091 You can edit the line."
3092 (declare (indent 0) (debug t))
3093 `(anything-edit-current-selection-internal
3094 (lambda () ,@forms)))
3096 (defun anything-set-pattern (pattern &optional noupdate)
3097 "Set minibuffer contents to PATTERN.
3098 if optional NOUPDATE is non-nil, anything buffer is not changed."
3099 (with-selected-window (or (active-minibuffer-window) (minibuffer-window))
3100 (delete-minibuffer-contents)
3101 (insert pattern))
3102 (when noupdate
3103 (setq anything-pattern pattern)
3104 (anything-hooks 'cleanup)
3105 (run-with-idle-timer 0 nil 'anything-hooks 'setup)))
3107 (defun anything-delete-minibuffer-contents ()
3108 "Same as `delete-minibuffer-contents' but this is a command."
3109 (interactive)
3110 (anything-set-pattern ""))
3111 (defalias 'anything-delete-minibuffer-content 'anything-delete-minibuffer-contents)
3114 ;;; Plugins
3116 ;; (@* "Built-in plug-in: type")
3117 (defun anything-compile-source--type (source)
3118 (anything-aif (assoc-default 'type source)
3119 (append source (assoc-default it anything-type-attributes) nil)
3120 source))
3122 ;; `define-anything-type-attribute' is public API.
3124 (defun anything-add-type-attribute (type definition)
3125 (anything-aif (assq type anything-type-attributes)
3126 (setq anything-type-attributes (delete it anything-type-attributes)))
3127 (push (cons type definition) anything-type-attributes))
3129 (defvar anything-types nil)
3130 (defun anything-document-type-attribute (type doc)
3131 (add-to-list 'anything-types type t)
3132 (put type 'anything-typeattrdoc
3133 (concat "- " (symbol-name type) "\n\n" doc "\n")))
3135 (defadvice documentation-property (after anything-document-type-attribute activate)
3136 "Display type attributes' documentation as `anything-type-attributes' docstring."
3137 (when (eq (ad-get-arg 0) 'anything-type-attributes)
3138 (setq ad-return-value
3139 (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
3140 (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
3141 anything-types "\n")))))
3143 ;; (@* "Built-in plug-in: dummy")
3144 (defun anything-dummy-candidate (candidate source)
3145 "Use `anything-pattern' as CANDIDATE in SOURCE."
3146 ;; `source' is defined in filtered-candidate-transformer
3147 (list anything-pattern))
3149 (defun anything-compile-source--dummy (source)
3150 (if (assoc 'dummy source)
3151 (append source
3152 '((candidates "dummy")
3153 (accept-empty)
3154 (match identity)
3155 (filtered-candidate-transformer . anything-dummy-candidate)
3156 (disable-shortcuts)
3157 (volatile)))
3158 source))
3160 ;; (@* "Built-in plug-in: disable-shortcuts")
3161 (defvar anything-orig-enable-shortcuts nil)
3162 (defun anything-save-enable-shortcuts ()
3163 (anything-once
3164 (lambda ()
3165 (setq anything-orig-enable-shortcuts anything-enable-shortcuts
3166 anything-enable-shortcuts nil))))
3168 (defun anything-compile-source--disable-shortcuts (source)
3169 (if (assoc 'disable-shortcuts source)
3170 (append `((init ,@(anything-mklist (assoc-default 'init source))
3171 anything-save-enable-shortcuts)
3172 (resume ,@(anything-mklist (assoc-default 'resume source))
3173 anything-save-enable-shortcuts)
3174 (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
3175 (lambda () (setq anything-enable-shortcuts
3176 anything-orig-enable-shortcuts))))
3177 source)
3178 source))
3180 ;; (@* "Built-in plug-in: candidates-in-buffer")
3181 (defun anything-candidates-in-buffer ()
3182 "Get candidates from the candidates buffer according to `anything-pattern'.
3184 BUFFER is `anything-candidate-buffer' by default. Each
3185 candidate must be placed in one line. This function is meant to
3186 be used in candidates-in-buffer or candidates attribute of an
3187 anything source. Especially fast for many (1000+) candidates.
3190 '((name . \"many files\")
3191 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
3192 (insert-many-filenames))))
3193 (search re-search-forward) ; optional
3194 (candidates-in-buffer)
3195 (type . file))
3197 +===============================================================+
3198 | The new way of making and narrowing candidates: Using buffers |
3199 +===============================================================+
3201 By default, `anything' makes candidates by evaluating the
3202 candidates function, then narrows them by `string-match' for each
3203 candidate.
3205 But this way is very slow for many candidates. The new way is
3206 storing all candidates in a buffer and narrowing them by
3207 `re-search-forward'. Search function is customizable by search
3208 attribute. The important point is that buffer processing is MUCH
3209 FASTER than string list processing and is the Emacs way.
3211 The init function writes all candidates to a newly-created
3212 candidate buffer. The candidates buffer is created or specified
3213 by `anything-candidate-buffer'. Candidates are stored in a line.
3215 The candidates function narrows all candidates, IOW creates a
3216 subset of candidates dynamically. It is the task of
3217 `anything-candidates-in-buffer'. As long as
3218 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
3219 sufficient in most cases.
3221 Note that `(candidates-in-buffer)' is shortcut of three attributes:
3222 (candidates . anything-candidates-in-buffer)
3223 (volatile)
3224 (match identity)
3225 And `(candidates-in-buffer . func)' is shortcut of three attributes:
3226 (candidates . func)
3227 (volatile)
3228 (match identity)
3229 The expansion is performed in `anything-get-sources'.
3231 The candidates-in-buffer attribute implies the volatile attribute.
3232 The volatile attribute is needed because `anything-candidates-in-buffer'
3233 creates candidates dynamically and need to be called everytime
3234 `anything-pattern' changes.
3236 Because `anything-candidates-in-buffer' plays the role of `match' attribute
3237 function, specifying `(match identity)' makes the source slightly faster.
3239 To customize `anything-candidates-in-buffer' behavior, use search,
3240 get-line and search-from-end attributes. See also `anything-sources' docstring."
3241 (declare (special source))
3242 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
3243 anything-pattern
3244 (or (assoc-default 'get-line source)
3245 #'buffer-substring-no-properties)
3246 ;; use external variable `source'.
3247 (or (assoc-default 'search source)
3248 (if (assoc 'search-from-end source)
3249 '(re-search-backward)
3250 '(re-search-forward)))
3251 (anything-candidate-number-limit source)
3252 (assoc 'search-from-end source)))
3254 (defun anything-candidates-in-buffer-1 (buffer pattern get-line-fn search-fns limit search-from-end)
3255 ;; buffer == nil when candidates buffer does not exist.
3256 (when buffer
3257 (with-current-buffer buffer
3258 (let ((start-point (if search-from-end (point-max) (point-min)))
3259 (endp (if search-from-end #'bobp #'eobp)))
3260 (goto-char (1- start-point))
3261 (if (string= pattern "")
3262 (anything-initial-candidates-from-candidate-buffer
3263 endp get-line-fn limit search-from-end)
3264 (anything-search-from-candidate-buffer
3265 pattern get-line-fn search-fns limit search-from-end
3266 start-point endp))))))
3268 (defun anything-point-is-moved (proc)
3269 "If point is moved after executing PROC, return t, otherwise nil."
3270 (/= (point) (progn (funcall proc) (point))))
3272 (defun anything-search-from-candidate-buffer (pattern get-line-fn search-fns
3273 limit search-from-end
3274 start-point endp)
3275 (let (buffer-read-only
3276 matches exit newmatches)
3277 (anything-search-from-candidate-buffer-internal
3278 (lambda ()
3279 (clrhash anything-cib-hash)
3280 (dolist (searcher search-fns)
3281 (goto-char start-point)
3282 (setq newmatches nil)
3283 (loop with item-count = 0
3284 while (funcall searcher pattern nil t)
3285 for cand = (funcall get-line-fn (point-at-bol) (point-at-eol))
3286 do (anything-accumulate-candidates-internal
3287 cand newmatches anything-cib-hash item-count limit)
3288 unless (anything-point-is-moved
3289 (lambda ()
3290 (if search-from-end
3291 (goto-char (1- (point-at-bol)))
3292 (forward-line 1))))
3293 return nil)
3294 (setq matches (append matches (nreverse newmatches)))
3295 (if exit (return)))
3296 (delq nil matches)))))
3298 (defun anything-initial-candidates-from-candidate-buffer (endp get-line-fn limit search-from-end)
3299 (delq nil (loop with next-line-fn =
3300 (if search-from-end
3301 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
3302 #'forward-line)
3303 until (funcall endp)
3304 for i from 1 to limit
3305 collect (funcall get-line-fn (point-at-bol) (point-at-eol))
3306 do (funcall next-line-fn 1))))
3308 (defun anything-search-from-candidate-buffer-internal (search-fn)
3309 (goto-char (point-min))
3310 (insert "\n")
3311 (goto-char (point-max))
3312 (insert "\n")
3313 (unwind-protect
3314 (funcall search-fn)
3315 (goto-char (point-min))
3316 (delete-char 1)
3317 (goto-char (1- (point-max)))
3318 (delete-char 1)
3320 (set-buffer-modified-p nil)))
3322 (defun anything-candidate-buffer (&optional create-or-buffer)
3323 "Register and return a buffer containing candidates of current source.
3324 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3325 then global candidates buffer.
3327 Acceptable values of CREATE-OR-BUFFER:
3329 - nil (omit)
3330 Only return the candidates buffer.
3331 - a buffer
3332 Register a buffer as a candidates buffer.
3333 - 'global
3334 Create a new global candidates buffer,
3335 named \" *anything candidates:SOURCE*\".
3336 - other non-nil value
3337 Create a new local candidates buffer,
3338 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\"."
3339 (let* ((global-bname (format " *anything candidates:%s*" anything-source-name))
3340 (local-bname (format " *anything candidates:%s*%s"
3341 anything-source-name
3342 (buffer-name anything-current-buffer)))
3343 (register-func
3344 (lambda ()
3345 (setq anything-candidate-buffer-alist
3346 (cons (cons anything-source-name create-or-buffer)
3347 (delete (assoc anything-source-name
3348 anything-candidate-buffer-alist)
3349 anything-candidate-buffer-alist)))))
3350 (kill-buffers-func
3351 (lambda ()
3352 (loop for b in (buffer-list)
3353 if (string-match (format "^%s" (regexp-quote global-bname))
3354 (buffer-name b))
3355 do (kill-buffer b))))
3356 (create-func
3357 (lambda ()
3358 (with-current-buffer
3359 (get-buffer-create (if (eq create-or-buffer 'global)
3360 global-bname
3361 local-bname))
3362 (buffer-disable-undo)
3363 (erase-buffer)
3364 (font-lock-mode -1))))
3365 (return-func
3366 (lambda ()
3367 (or (get-buffer local-bname)
3368 (get-buffer global-bname)
3369 (anything-aif (assoc-default anything-source-name
3370 anything-candidate-buffer-alist)
3371 (and (buffer-live-p it) it))))))
3372 (when create-or-buffer
3373 (funcall register-func)
3374 (unless (bufferp create-or-buffer)
3375 (and (eq create-or-buffer 'global) (funcall kill-buffers-func))
3376 (funcall create-func)))
3377 (funcall return-func)))
3379 (defun anything-compile-source--candidates-in-buffer (source)
3380 (anything-aif (assoc 'candidates-in-buffer source)
3381 (append source
3382 `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
3383 (volatile) (match identity)))
3384 source))
3387 ;; (@* "Utility: resplit anything window")
3388 (defun anything-toggle-resplit-window ()
3389 "Toggle resplit anything window, vertically or horizontally."
3390 (interactive)
3391 (with-anything-window
3392 (let ((before-height (window-height)))
3393 (delete-window)
3394 (set-window-buffer
3395 (select-window (if (= (window-height) before-height)
3396 (prog1
3397 (split-window-vertically)
3398 (setq anything-split-window-state 'vertical))
3399 (setq anything-split-window-state 'horizontal)
3400 (split-window-horizontally)))
3401 anything-buffer))))
3403 ;; (@* "Utility: Resize anything window.")
3404 (defun anything-enlarge-window-1 (n)
3405 "Enlarge or narrow anything window.
3406 If N is positive enlarge, if negative narrow."
3407 (unless anything-samewindow
3408 (let ((horizontal-p (eq anything-split-window-state 'horizontal)))
3409 (with-anything-window
3410 (enlarge-window n horizontal-p)))))
3412 (defun anything-narrow-window ()
3413 "Narrow anything window."
3414 (interactive)
3415 (anything-enlarge-window-1 -1))
3417 (defun anything-enlarge-window ()
3418 "Enlarge anything window."
3419 (interactive)
3420 (anything-enlarge-window-1 1))
3422 ;; (@* "Utility: select another action by key")
3423 (defun anything-select-nth-action (n)
3424 "Select the N nth action for the currently selected candidate."
3425 (setq anything-saved-selection (anything-get-selection))
3426 (unless anything-saved-selection
3427 (error "Nothing is selected"))
3428 (setq anything-saved-action (anything-get-nth-action n (anything-get-action)))
3429 (anything-exit-minibuffer))
3431 (defun anything-get-nth-action (n action)
3432 (cond ((and (zerop n) (functionp action))
3433 action)
3434 ((listp action)
3435 (or (cdr (elt action n))
3436 (error "No such action")))
3437 ((and (functionp action) (< 0 n))
3438 (error "Sole action"))
3440 (error "Error in `anything-select-nth-action'"))))
3442 (defun anything-select-2nd-action ()
3443 "Select the 2nd action for the currently selected candidate."
3444 (interactive)
3445 (anything-select-nth-action 1))
3447 (defun anything-select-3rd-action ()
3448 "Select the 3rd action for the currently selected candidate."
3449 (interactive)
3450 (anything-select-nth-action 2))
3452 (defun anything-select-4th-action ()
3453 "Select the 4th action for the currently selected candidate."
3454 (interactive)
3455 (anything-select-nth-action 3))
3457 (defun anything-select-2nd-action-or-end-of-line ()
3458 "Select the 2nd action for the currently selected candidate.
3459 This happen when point is at the end of minibuffer.
3460 Otherwise goto the end of minibuffer."
3461 (interactive)
3462 (if (eolp)
3463 (anything-select-nth-action 1)
3464 (end-of-line)))
3466 ;; (@* "Utility: Persistent Action")
3467 (defmacro with-anything-display-same-window (&rest body)
3468 "Execute BODY in the window used for persistent action.
3469 Make `pop-to-buffer' and `display-buffer' display in the same window."
3470 (declare (indent 0) (debug t))
3471 `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
3472 ,@body))
3474 (defvar anything-persistent-action-display-window nil)
3475 (defun anything-initialize-persistent-action ()
3476 (set (make-local-variable 'anything-persistent-action-display-window) nil))
3478 (defun* anything-execute-persistent-action (&optional (attr 'persistent-action) onewindow)
3479 "Perform the associated action ATTR without quitting anything.
3480 ATTR default is 'persistent-action', but it can be anything else.
3481 In this case you have to add this new attribute to your source.
3482 When `anything-samewindow' and ONEWINDOW are non--nil,
3483 the anything window is never split in persistent action."
3484 (interactive)
3485 (anything-log "executing persistent-action")
3486 (with-anything-window
3487 (save-selected-window
3488 (anything-select-persistent-action-window onewindow)
3489 (anything-log-eval (current-buffer))
3490 (let ((anything-in-persistent-action t))
3491 (with-anything-display-same-window
3492 (anything-execute-selection-action
3494 (or (assoc-default attr (anything-get-current-source))
3495 (anything-get-action))
3497 (anything-log-run-hook 'anything-after-persistent-action-hook))))))
3500 (defun anything-persistent-action-display-window (&optional onewindow)
3501 "Return the window that will be used for presistent action.
3502 If ONEWINDOW is non--nil window will not be splitted in persistent action
3503 if `anything-samewindow' is non--nil also."
3504 (with-anything-window
3505 (setq anything-persistent-action-display-window
3506 (cond ((window-live-p anything-persistent-action-display-window)
3507 anything-persistent-action-display-window)
3508 ((and anything-samewindow (one-window-p t) (not onewindow))
3509 (split-window))
3510 ((get-buffer-window anything-current-buffer))
3512 (next-window (selected-window) 1))))))
3514 (defun anything-select-persistent-action-window (&optional onewindow)
3515 "Select the window that will be used for persistent action.
3516 See `anything-persistent-action-display-window' for how to use ONEWINDOW."
3517 (select-window (get-buffer-window (anything-buffer-get)))
3518 (select-window
3519 (setq minibuffer-scroll-window
3520 (anything-persistent-action-display-window onewindow))))
3522 (defun anything-persistent-action-display-buffer (buf &optional not-this-window)
3523 "Make `pop-to-buffer' and `display-buffer' display in the same window.
3524 If `anything-persistent-action-use-special-display' is non-nil and
3525 BUF is to be displayed by `special-display-function', use it.
3526 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'.
3527 Argument NOT-THIS-WINDOW if present will be used as
3528 second argument of `display-buffer'."
3529 (let* ((name (buffer-name buf))
3530 display-buffer-function pop-up-windows pop-up-frames
3531 (same-window-regexps
3532 (unless (and anything-persistent-action-use-special-display
3533 (or (member name
3534 (mapcar (lambda (x) (or (car-safe x) x))
3535 special-display-buffer-names))
3536 (remove-if-not
3537 (lambda (x) (string-match (or (car-safe x) x) name))
3538 special-display-regexps)))
3539 '("."))))
3540 (display-buffer buf not-this-window)))
3542 ;; scroll-other-window(-down)? for persistent-action
3543 (defun anything-scroll-other-window-base (command)
3544 (with-selected-window (anything-persistent-action-display-window)
3545 (funcall command anything-scroll-amount)))
3547 (defun anything-scroll-other-window ()
3548 "Scroll other window (not *Anything* window) upward."
3549 (interactive)
3550 (anything-scroll-other-window-base 'scroll-up))
3552 (defun anything-scroll-other-window-down ()
3553 "Scroll other window (not *Anything* window) downward."
3554 (interactive)
3555 (anything-scroll-other-window-base 'scroll-down))
3558 ;; (@* "Utility: Visible Mark")
3559 (defface anything-visible-mark
3560 '((((min-colors 88) (background dark))
3561 (:background "green1" :foreground "black"))
3562 (((background dark)) (:background "green" :foreground "black"))
3563 (((min-colors 88)) (:background "green1"))
3564 (t (:background "green")))
3565 "Face for visible mark."
3566 :group 'anything)
3568 (defvar anything-visible-mark-face 'anything-visible-mark)
3569 (defvar anything-visible-mark-overlays nil)
3571 (defun anything-clear-visible-mark ()
3572 (with-current-buffer (anything-buffer-get)
3573 (mapc 'delete-overlay anything-visible-mark-overlays)
3574 (set (make-local-variable 'anything-visible-mark-overlays) nil)))
3575 (add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
3577 (defvar anything-marked-candidates nil
3578 "Marked candadates. List of \(source . real\) pair.")
3580 (defun anything-this-visible-mark ()
3581 (loop for o in anything-visible-mark-overlays
3582 when (equal (point-at-bol) (overlay-start o))
3583 do (return o)))
3585 (defun anything-delete-visible-mark (overlay)
3586 (setq anything-marked-candidates
3587 (remove
3588 (cons (anything-get-current-source) (anything-get-selection))
3589 anything-marked-candidates))
3590 (delete-overlay overlay)
3591 (setq anything-visible-mark-overlays
3592 (delq overlay anything-visible-mark-overlays)))
3594 (defun anything-make-visible-mark ()
3595 (let ((o (make-overlay (point-at-bol) (1+ (point-at-eol)))))
3596 (overlay-put o 'face anything-visible-mark-face)
3597 (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3598 (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3599 (overlay-put o 'real (anything-get-selection))
3600 (add-to-list 'anything-visible-mark-overlays o))
3601 (push (cons (anything-get-current-source) (anything-get-selection))
3602 anything-marked-candidates))
3604 (defun anything-toggle-visible-mark ()
3605 "Toggle anything visible mark at point."
3606 (interactive)
3607 (with-anything-window
3608 (anything-aif (anything-this-visible-mark)
3609 (anything-delete-visible-mark it)
3610 (anything-make-visible-mark))
3611 (anything-next-line)))
3613 (defun anything-display-all-visible-marks ()
3614 "Show all `anything' visible marks strings."
3615 (interactive)
3616 (with-anything-window
3617 (lexical-let ((overlays (reverse anything-visible-mark-overlays)))
3618 (anything-run-after-quit
3619 (lambda ()
3620 (with-output-to-temp-buffer "*anything visible marks*"
3621 (dolist (o overlays) (princ (overlay-get o 'string)))))))))
3623 (defun anything-marked-candidates ()
3624 "Return marked candidates of current source if any.
3625 Otherwise one element list of current selection.
3627 It is analogous to `dired-get-marked-files'."
3628 (with-current-buffer (anything-buffer-get)
3629 (let ((cands
3630 (if anything-marked-candidates
3631 (loop with current-src = (anything-get-current-source)
3632 for (source . real) in (reverse anything-marked-candidates)
3633 when (equal current-src source)
3634 collect (anything-coerce-selection real source))
3635 (list (anything-get-selection)))))
3636 (anything-log-eval cands)
3637 cands)))
3639 (defun anything-reset-marked-candidates ()
3640 (with-current-buffer (anything-buffer-get)
3641 (set (make-local-variable 'anything-marked-candidates) nil)))
3643 (add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
3644 ;; (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3646 (defun anything-current-source-name= (name)
3647 (save-excursion
3648 (goto-char (anything-get-previous-header-pos))
3649 (equal name (anything-current-line-contents))))
3651 (defun anything-revive-visible-mark ()
3652 "Restore marked candidates when anything update display."
3653 (with-current-buffer anything-buffer
3654 (dolist (o anything-visible-mark-overlays)
3655 (goto-char (point-min))
3656 (while (and (search-forward (overlay-get o 'string) nil t)
3657 (anything-current-source-name= (overlay-get o 'source)))
3658 ;; Calculate real value of candidate.
3659 ;; It can be nil if candidate have only a display value.
3660 (let ((real (get-text-property (point-at-bol 0) 'anything-realvalue)))
3661 (if real
3662 ;; Check if real value of current candidate is the same
3663 ;; that the one stored in overlay.
3664 (and (string= (overlay-get o 'real) real)
3665 (move-overlay o (point-at-bol 0) (1+ (point-at-eol 0))))
3666 (move-overlay o (point-at-bol 0) (1+ (point-at-eol 0)))))))))
3667 (add-hook 'anything-update-hook 'anything-revive-visible-mark)
3669 (defun anything-next-point-in-list (curpos points &optional prev)
3670 (cond
3671 ;; rule out special cases
3672 ((null points) curpos)
3673 ((and prev (< curpos (car points))) curpos)
3674 ((< (car (last points)) curpos)
3675 (if prev (car (last points)) curpos))
3677 (nth (if prev
3678 (loop for pt in points
3679 for i from 0
3680 if (<= curpos pt)
3681 do (return (1- i)))
3682 (loop for pt in points
3683 for i from 0
3684 if (< curpos pt)
3685 do (return i)))
3686 points))))
3688 (defun anything-next-visible-mark (&optional prev)
3689 "Move next anything visible mark.
3690 If PREV is non-nil move to precedent."
3691 (interactive)
3692 (with-anything-window
3693 (goto-char (anything-next-point-in-list
3694 (point)
3695 (sort (mapcar 'overlay-start anything-visible-mark-overlays) '<)
3696 prev))
3697 (anything-mark-current-line)))
3699 (defun anything-prev-visible-mark ()
3700 "Move previous anything visible mark."
3701 (interactive)
3702 (anything-next-visible-mark t))
3704 ;; (@* "Utility: Selection Paste")
3705 (defun anything-yank-selection ()
3706 "Set minibuffer contents to current selection."
3707 (interactive)
3708 (anything-set-pattern (anything-get-selection nil t)))
3710 (defun anything-kill-selection-and-quit ()
3711 "Store current selection to kill ring.
3712 You can paste it by typing \\[yank]."
3713 (interactive)
3714 (anything-run-after-quit
3715 (lambda (sel)
3716 (kill-new sel)
3717 (message "Killed: %s" sel))
3718 (anything-get-selection nil t)))
3721 ;; (@* "Utility: Automatical execution of persistent-action")
3722 (add-to-list 'minor-mode-alist '(anything-follow-mode " AFollow"))
3723 (defun anything-follow-mode ()
3724 "If this mode is on, persistent action is executed everytime the cursor is moved."
3725 (interactive)
3726 (with-current-buffer anything-buffer
3727 (setq anything-follow-mode (not anything-follow-mode))
3728 (message "anything-follow-mode is %s"
3729 (if anything-follow-mode "enabled" "disabled"))))
3731 (defun anything-follow-execute-persistent-action-maybe ()
3732 "Execute persistent action in mode `anything-follow-mode'.
3733 This happen after `anything-input-idle-delay' secs."
3734 (and (not (get-buffer-window anything-action-buffer 'visible))
3735 (buffer-local-value 'anything-follow-mode
3736 (get-buffer-create anything-buffer))
3737 (sit-for anything-input-idle-delay)
3738 (anything-window)
3739 (anything-get-selection)
3740 (save-excursion
3741 (anything-execute-persistent-action))))
3744 ;; (@* "Utility: Migrate `anything-sources' to my-anything command")
3745 (defun anything-migrate-sources ()
3746 "Help to migrate to new `anything' way."
3747 (interactive)
3748 (with-current-buffer (get-buffer-create "*anything migrate*")
3749 (erase-buffer)
3750 (insert (format "\
3751 Setting `anything-sources' directly is not good because
3752 `anything' is not for one command. For now, interactive use of
3753 `anything' (M-x anything) is only for demonstration purpose.
3754 So you should define commands calling `anything'.
3755 I help you to migrate to the new way.
3757 The code below is automatically generated from current
3758 `anything-sources' value. You can use the `my-anything' command
3759 now!
3761 Copy and paste it to your .emacs. Then substitute `my-anything'
3762 for `anything' bindings in all `define-key', `local-set-key' and
3763 `global-set-key' calls.
3765 \(defun my-anything ()
3766 \"Anything command for you.
3768 It is automatically generated by `anything-migrate-sources'.\"
3769 (interactive)
3770 (anything-other-buffer
3772 \"*my-anything*\"))
3773 " anything-sources))
3774 (eval-last-sexp nil)
3775 (substitute-key-definition 'anything 'my-anything global-map)
3776 (pop-to-buffer (current-buffer))))
3779 ;; (@* "Compatibility")
3781 ;; Copied assoc-default from XEmacs version 21.5.12
3782 (unless (fboundp 'assoc-default)
3783 (defun assoc-default (key alist &optional test default)
3784 "Find object KEY in a pseudo-alist ALIST.
3785 ALIST is a list of conses or objects. Each element (or the element's car,
3786 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
3787 If that is non-nil, the element matches;
3788 then `assoc-default' returns the element's cdr, if it is a cons,
3789 or DEFAULT if the element is not a cons.
3791 If no element matches, the value is nil.
3792 If TEST is omitted or nil, `equal' is used."
3793 (let (found (tail alist) value)
3794 (while (and tail (not found))
3795 (let ((elt (car tail)))
3796 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
3797 (setq found t value (if (consp elt) (cdr elt) default))))
3798 (setq tail (cdr tail)))
3799 value)))
3801 ;; Function not available in XEmacs,
3802 (unless (fboundp 'minibuffer-contents)
3803 (defun minibuffer-contents ()
3804 "Return the user input in a minbuffer as a string.
3805 The current buffer must be a minibuffer."
3806 (field-string (point-max)))
3808 (defun delete-minibuffer-contents ()
3809 "Delete all user input in a minibuffer.
3810 The current buffer must be a minibuffer."
3811 (delete-field (point-max))))
3813 ;; Function not available in older Emacs (<= 22.1).
3814 (unless (fboundp 'buffer-chars-modified-tick)
3815 (defun buffer-chars-modified-tick (&optional buffer)
3816 "Return BUFFER's character-change tick counter.
3817 Each buffer has a character-change tick counter, which is set to the
3818 value of the buffer's tick counter (see `buffer-modified-tick'), each
3819 time text in that buffer is inserted or deleted. By comparing the
3820 values returned by two individual calls of `buffer-chars-modified-tick',
3821 you can tell whether a character change occurred in that buffer in
3822 between these calls. No argument or nil as argument means use current
3823 buffer as BUFFER."
3824 (with-current-buffer (or buffer (current-buffer))
3825 (if (listp buffer-undo-list)
3826 (length buffer-undo-list)
3827 (buffer-modified-tick)))))
3830 ;; (@* "CUA workaround")
3831 (defadvice cua-delete-region (around anything-avoid-cua activate)
3832 (ignore-errors ad-do-it))
3834 (defadvice copy-region-as-kill (around anything-avoid-cua activate)
3835 (if cua-mode
3836 (ignore-errors ad-do-it)
3837 ad-do-it))
3839 ;;(@* "Attribute Documentation")
3840 (defun anything-describe-anything-attribute (anything-attribute)
3841 "Display the full documentation of ANYTHING-ATTRIBUTE.
3842 ANYTHING-ATTRIBUTE should be a symbol."
3843 (interactive (list (intern
3844 (completing-read
3845 "Describe anything attribute: "
3846 (mapcar 'symbol-name anything-additional-attributes)))))
3847 (with-output-to-temp-buffer "*Help*"
3848 (princ (get anything-attribute 'anything-attrdoc))))
3850 (anything-document-attribute 'name "mandatory"
3851 " The name of the source. It is also the heading which appears
3852 above the list of matches from the source. Must be unique. ")
3853 (anything-document-attribute 'header-name "optional"
3854 " A function returning the display string of the header. Its
3855 argument is the name of the source. This attribute is useful to
3856 add an additional information with the source name. ")
3857 (anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
3858 " Specifies how to retrieve candidates from the source. It can
3859 either be a variable name, a function called with no parameters
3860 or the actual list of candidates.
3862 The list must be a list whose members are strings, symbols
3863 or (DISPLAY . REAL) pairs.
3865 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
3866 in the Anything buffer, but the REAL one is used as action
3867 argument when the candidate is selected. This allows a more
3868 readable presentation for candidates which would otherwise be,
3869 for example, too long or have a common part shared with other
3870 candidates which can be safely replaced with an abbreviated
3871 string for display purposes.
3873 Note that if the (DISPLAY . REAL) form is used then pattern
3874 matching is done on the displayed string, not on the real
3875 value.
3877 If the candidates have to be retrieved asynchronously (for
3878 example, by an external command which takes a while to run)
3879 then the function should start the external command
3880 asynchronously and return the associated process object.
3881 Anything will take care of managing the process (receiving the
3882 output from it, killing it if necessary, etc.). The process
3883 should return candidates matching the current pattern (see
3884 variable `anything-pattern'.)
3886 Note that currently results from asynchronous sources appear
3887 last in the anything buffer regardless of their position in
3888 `anything-sources'. ")
3889 (anything-document-attribute 'action "mandatory if type attribute is not provided"
3890 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
3891 FUNCTION is called with one parameter: the selected candidate.
3893 An action other than the default can be chosen from this list
3894 of actions for the currently selected candidate (by default
3895 with TAB). The DISPLAY string is shown in the completions
3896 buffer and the FUNCTION is invoked when an action is
3897 selected. The first action of the list is the default. ")
3898 (anything-document-attribute 'coerce "optional"
3899 " It's a function called with one argument: the selected candidate.
3901 This function is intended for type convertion.
3902 In normal case, the selected candidate (string) is passed to action function.
3903 If coerce function is specified, it is called just before action function.
3905 Example: converting string to symbol
3906 (coerce . intern) ")
3907 (anything-document-attribute 'type "optional if action attribute is provided"
3908 " Indicates the type of the items the source returns.
3910 Merge attributes not specified in the source itself from
3911 `anything-type-attributes'.
3913 This attribute is implemented by plug-in. ")
3914 (anything-document-attribute 'init "optional"
3915 " Function called with no parameters when anything is started. It
3916 is useful for collecting current state information which can be
3917 used to create the list of candidates later.
3919 For example, if a source needs to work with the current
3920 directory then it can store its value here, because later
3921 anything does its job in the minibuffer and in the
3922 `anything-buffer' and the current directory can be different
3923 there. ")
3924 (anything-document-attribute 'delayed-init "optional"
3925 " Function called with no parameters before candidate function is
3926 called. It is similar with `init' attribute, but its
3927 evaluation is deferred. It is useful to combine with ")
3928 (anything-document-attribute 'match "optional"
3929 " List of functions called with one parameter: a candidate. The
3930 function should return non-nil if the candidate matches the
3931 current pattern (see variable `anything-pattern').
3933 This attribute allows the source to override the default
3934 pattern matching based on `string-match'. It can be used, for
3935 example, to implement a source for file names and do the
3936 pattern matching on the basename of files, since it's more
3937 likely one is typing part of the basename when searching for a
3938 file, instead of some string anywhere else in its path.
3940 If the list contains more than one function then the list of
3941 matching candidates from the source is constructed by appending
3942 the results after invoking the first function on all the
3943 potential candidates, then the next function, and so on. The
3944 matching candidates supplied by the first function appear first
3945 in the list of results and then results from the other
3946 functions, respectively.
3948 This attribute has no effect for asynchronous sources (see
3949 attribute `candidates'), since they perform pattern matching
3950 themselves. ")
3951 (anything-document-attribute 'candidate-transformer "optional"
3952 " It's a function or a list of functions called with one argument
3953 when the completion list from the source is built. The argument
3954 is the list of candidates retrieved from the source. The
3955 function should return a transformed list of candidates which
3956 will be used for the actual completion. If it is a list of
3957 functions, it calls each function sequentially.
3959 This can be used to transform or remove items from the list of
3960 candidates.
3962 Note that `candidates' is run already, so the given transformer
3963 function should also be able to handle candidates with (DISPLAY
3964 . REAL) format. ")
3965 (anything-document-attribute 'filtered-candidate-transformer "optional"
3966 " It has the same format as `candidate-transformer', except the
3967 function is called with two parameters: the candidate list and
3968 the source.
3970 This transformer is run on the candidate list which is already
3971 filtered by the current pattern. While `candidate-transformer'
3972 is run only once, it is run every time the input pattern is
3973 changed.
3975 It can be used to transform the candidate list dynamically, for
3976 example, based on the current pattern.
3978 In some cases it may also be more efficent to perform candidate
3979 transformation here, instead of with `candidate-transformer'
3980 even if this transformation is done every time the pattern is
3981 changed. For example, if a candidate set is very large then
3982 `candidate-transformer' transforms every candidate while only
3983 some of them will actually be dislpayed due to the limit
3984 imposed by `anything-candidate-number-limit'.
3986 Note that `candidates' and `candidate-transformer' is run
3987 already, so the given transformer function should also be able
3988 to handle candidates with (DISPLAY . REAL) format.
3990 This option has no effect for asynchronous sources. (Not yet,
3991 at least. ")
3992 (anything-document-attribute 'action-transformer "optional"
3993 " It's a function or a list of functions called with two
3994 arguments when the action list from the source is
3995 assembled. The first argument is the list of actions, the
3996 second is the current selection. If it is a list of functions,
3997 it calls each function sequentially.
3999 The function should return a transformed action list.
4001 This can be used to customize the list of actions based on the
4002 currently selected candidate. ")
4003 (anything-document-attribute 'pattern-transformer "optional"
4004 " It's a function or a list of functions called with one argument
4005 before computing matches. Its argument is `anything-pattern'.
4006 Functions should return transformed `anything-pattern'.
4008 It is useful to change interpretation of `anything-pattern'. ")
4009 (anything-document-attribute 'delayed "optional"
4010 " Candidates from the source are shown only if the user stops
4011 typing and is idle for `anything-idle-delay' seconds. ")
4012 (anything-document-attribute 'volatile "optional"
4013 " Indicates the source assembles the candidate list dynamically,
4014 so it shouldn't be cached within a single Anything
4015 invocation. It is only applicable to synchronous sources,
4016 because asynchronous sources are not cached. ")
4017 (anything-document-attribute 'requires-pattern "optional"
4018 " If present matches from the source are shown only if the
4019 pattern is not empty. Optionally, it can have an integer
4020 parameter specifying the required length of input which is
4021 useful in case of sources with lots of candidates. ")
4022 (anything-document-attribute 'persistent-action "optional"
4023 " Function called with one parameter; the selected candidate.
4025 An action performed by `anything-execute-persistent-action'.
4026 If none, use the default action. ")
4027 (anything-document-attribute 'candidates-in-buffer "optional"
4028 " Shortcut attribute for making and narrowing candidates using
4029 buffers. This newly-introduced attribute prevents us from
4030 forgetting to add volatile and match attributes.
4032 See docstring of `anything-candidates-in-buffer'.
4034 (candidates-in-buffer) is equivalent of three attributes:
4035 (candidates . anything-candidates-in-buffer)
4036 (volatile)
4037 (match identity)
4039 (candidates-in-buffer . candidates-function) is equivalent of:
4040 (candidates . candidates-function)
4041 (volatile)
4042 (match identity)
4044 This attribute is implemented by plug-in. ")
4045 (anything-document-attribute 'search "optional"
4046 " List of functions like `re-search-forward' or `search-forward'.
4047 Buffer search function used by `anything-candidates-in-buffer'.
4048 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4049 This attribute is meant to be used with
4050 (candidates . anything-candidates-in-buffer) or
4051 (candidates-in-buffer) in short. ")
4052 (anything-document-attribute 'search-from-end "optional"
4053 " Make `anything-candidates-in-buffer' search from the end of buffer.
4054 If this attribute is specified, `anything-candidates-in-buffer' uses
4055 `re-search-backward' instead. ")
4056 (anything-document-attribute 'get-line "optional"
4057 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4058 This function converts point of line-beginning and point of line-end,
4059 which represents a candidate computed by `anything-candidates-in-buffer'.
4060 By default, `anything-candidates-in-buffer' uses
4061 `buffer-substring-no-properties'. ")
4062 (anything-document-attribute 'display-to-real "optional"
4063 " Function called with one parameter; the selected candidate.
4065 The function transforms the selected candidate, and the result
4066 is passed to the action function. The display-to-real
4067 attribute provides another way to pass other string than one
4068 shown in Anything buffer.
4070 Traditionally, it is possible to make candidates,
4071 candidate-transformer or filtered-candidate-transformer
4072 function return a list with (DISPLAY . REAL) pairs. But if REAL
4073 can be generated from DISPLAY, display-to-real is more
4074 convenient and faster. ")
4075 (anything-document-attribute 'real-to-display "optional"
4076 " Function called with one parameter; the selected candidate.
4078 The inverse of display-to-real attribute.
4080 The function transforms the selected candidate, which is passed
4081 to the action function, for display. The real-to-display
4082 attribute provides the other way to pass other string than one
4083 shown in Anything buffer.
4085 Traditionally, it is possible to make candidates,
4086 candidate-transformer or filtered-candidate-transformer
4087 function return a list with (DISPLAY . REAL) pairs. But if
4088 DISPLAY can be generated from REAL, real-to-display is more
4089 convenient.
4091 Note that DISPLAY parts returned from candidates /
4092 candidate-transformer are IGNORED as the name `display-to-real'
4093 says. ")
4094 (anything-document-attribute 'cleanup "optional"
4095 " Function called with no parameters when *anything* buffer is closed. It
4096 is useful for killing unneeded candidates buffer.
4098 Note that the function is executed BEFORE performing action. ")
4099 (anything-document-attribute 'candidate-number-limit "optional"
4100 " Override `anything-candidate-number-limit' only for this source. ")
4101 (anything-document-attribute 'accept-empty "optional"
4102 " Pass empty string \"\" to action function. ")
4103 (anything-document-attribute 'disable-shortcuts "optional"
4104 " Disable `anything-enable-shortcuts' in current `anything' session.
4106 This attribute is implemented by plug-in. ")
4107 (anything-document-attribute 'dummy "optional"
4108 " Set `anything-pattern' to candidate. If this attribute is
4109 specified, The candidates attribute is ignored.
4111 This attribute is implemented by plug-in.
4112 This plug-in implies disable-shortcuts plug-in. ")
4113 (anything-document-attribute 'multiline "optional"
4114 " Enable to selection multiline candidates. ")
4115 (anything-document-attribute 'update "optional"
4116 ;; FIXME: this is not displayed correctly in help buffer.
4117 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4118 (anything-document-attribute 'mode-line "optional"
4119 " source local `anything-mode-line-string'. (included in `mode-line-format')
4120 It accepts also variable/function name. ")
4121 (anything-document-attribute 'header-line "optional"
4122 " source local `header-line-format'.
4123 It accepts also variable/function name. ")
4124 (anything-document-attribute
4125 'resume "optional"
4126 " Function called with no parameters when `anything-resume' is started.")
4129 ;; (@* "Bug Report")
4130 (defvar anything-maintainer-mail-address "emacs-anything@googlegroups.com")
4132 (defvar anything-bug-report-salutation
4133 "Describe bug below, using a precise recipe.
4135 When I executed M-x ...
4137 How to send a bug report:
4138 1) Be sure to use the LATEST version of anything.el.
4139 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
4140 3) Use Lisp version instead of compiled one: (load \"anything.el\")
4141 4) If you got an error, please paste *Backtrace* buffer.
4142 5) Type C-c C-c to send.")
4144 (defvar anything-no-dump-variables
4145 '(anything-candidate-buffer-alist
4146 anything-digit-overlays
4147 anything-help-message
4148 anything-candidate-cache
4150 "Variables not to dump in bug report.")
4152 (defun anything-dumped-variables-in-bug-report ()
4153 (let ((hash (make-hash-table)))
4154 (loop for var in (apropos-internal "anything-" 'boundp)
4155 for vname = (symbol-name var)
4156 unless (or (string-match "-map$" vname)
4157 (string-match "^anything-c-source-" vname)
4158 (string-match "-hash$" vname)
4159 (string-match "-face$" vname)
4160 (memq var anything-no-dump-variables))
4161 collect var)))
4163 (defun anything-send-bug-report ()
4164 "Send a bug report of anything.el."
4165 (interactive)
4166 (with-current-buffer (or anything-last-buffer
4167 (current-buffer))
4168 (reporter-submit-bug-report
4169 anything-maintainer-mail-address
4170 "anything.el"
4171 (anything-dumped-variables-in-bug-report)
4172 nil nil
4173 anything-bug-report-salutation)))
4175 (defun anything-send-bug-report-from-anything ()
4176 "Send a bug report of anything.el in anything session."
4177 (interactive)
4178 (anything-run-after-quit 'anything-send-bug-report))
4180 ;; Debugging function.
4181 (defun* anything-test-candidates
4182 (sources &optional (input "")
4183 (compile-source-functions
4184 anything-compile-source-functions-default))
4185 "Test helper function for anything.
4186 Given pseudo `anything-sources' and `anything-pattern', returns list like
4187 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4188 (\"source name2\" (\"candidate3\" \"candidate4\")))"
4189 (let ((anything-test-mode t)
4190 anything-enable-shortcuts
4191 anything-candidate-cache
4192 (anything-compile-source-functions compile-source-functions)
4193 anything-before-initialize-hook
4194 anything-after-initialize-hook
4195 anything-update-hook
4196 anything-test-candidate-list)
4197 (get-buffer-create anything-buffer)
4198 (anything-initialize nil input sources)
4199 (anything-update)
4200 ;; test-mode spec: select 1st candidate!
4201 (with-current-buffer anything-buffer
4202 (forward-line 1)
4203 (anything-mark-current-line))
4204 (prog1
4205 anything-test-candidate-list
4206 (anything-cleanup))))
4209 ;; (@* "Unit Tests")
4210 ;; See developer-tools/unit-test-anything.el
4212 (provide 'anything)
4214 ;; How to save (DO NOT REMOVE!!)
4215 ;; (progn (magit-push) (emacswiki-post "anything.el"))
4217 ;; Local Variables:
4218 ;; coding: utf-8
4219 ;; End:
4221 ;;; anything.el ends here