anything.el: Rename function `anything-dump-variables-in-bug-report' -> `anything...
[anything-config.git] / anything.el
blob7cb248beb67083657215e1b96f2b54c25d90c570
1 ;;;; anything.el --- open anything / QuickSilver-like candidate-selection framework
2 ;; $Id: anything.el,v 1.282 2010-04-01 02:22:22 rubikitch Exp $
4 ;; Copyright (C) 2007 Tamas Patrovics
5 ;; 2008, 2009, 2010 rubikitch <rubikitch@ruby-lang.org>
7 ;; Author: Tamas Patrovics
8 ;; Maintainer: rubikitch <rubikitch@ruby-lang.org>
9 ;; Keywords: files, frames, help, matching, outlines, processes, tools, convenience, anything
10 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
11 ;; Site: http://www.emacswiki.org/cgi-bin/emacs/Anything
13 ;; This file is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; This file is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
29 ;;; Commentary:
32 ;; Start with M-x anything, narrow the list by typing some pattern,
33 ;; select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter,
34 ;; left/right moves between sources. With TAB actions can be selected
35 ;; if the selected candidate has more than one possible action.
37 ;; Note that anything.el provides only the framework and some example
38 ;; configurations for demonstration purposes. See anything-config.el
39 ;; for practical, polished, easy to use configurations which can be
40 ;; used to assemble a custom personalized configuration. And many
41 ;; other configurations are in the EmacsWiki.
42 ;;
43 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-config.el
44 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingSources
46 ;; Maintainer's configuration is in the EmacsWiki. It would tell you
47 ;; many tips to write smart sources!
49 ;; http://www.emacswiki.org/cgi-bin/emacs/RubikitchAnythingConfiguration
51 ;; Here is Japanese translation of `anything-sources' attributes. Thanks.
52 ;; http://d.hatena.ne.jp/sirocco634/20091012/1255336649
54 ;;; Bug Report:
56 ;; If you have problem, send a bug report via M-x anything-send-bug-report.
57 ;; The step is:
58 ;; 0) Setup mail in Emacs, the easiest way is:
59 ;; (setq user-mail-address "your@mail.address")
60 ;; (setq user-full-name "Your Full Name")
61 ;; (setq smtpmail-smtp-server "your.smtp.server.jp")
62 ;; (setq mail-user-agent 'message-user-agent)
63 ;; (setq message-send-mail-function 'message-smtpmail-send-it)
64 ;; 1) Be sure to use the LATEST version of anything.el.
65 ;; 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
66 ;; 3) Use Lisp version instead of compiled one: (load "anything.el")
67 ;; 4) Do it!
68 ;; 5) If you got an error, please do not close *Backtrace* buffer.
69 ;; 6) M-x anything-send-bug-report and M-x insert-buffer *Backtrace*
70 ;; 7) Describe the bug using a precise recipe.
71 ;; 8) Type C-c C-c to send.
72 ;; # If you are a Japanese, please write in Japanese:-)
75 ;;; Commands:
77 ;; Below are complete command list:
79 ;; `anything'
80 ;; Select anything. In Lisp program, some optional arguments can be used.
81 ;; `anything-resume'
82 ;; Resurrect previously invoked `anything'.
83 ;; `anything-at-point'
84 ;; Same as `anything' except when C-u is pressed, the initial input is the symbol at point.
85 ;; `anything-force-update'
86 ;; Recalculate and update candidates.
87 ;; `anything-select-action'
88 ;; Select an action for the currently selected candidate.
89 ;; `anything-previous-line'
90 ;; Move selection to the previous line.
91 ;; `anything-next-line'
92 ;; Move selection to the next line.
93 ;; `anything-previous-page'
94 ;; Move selection back with a pageful.
95 ;; `anything-next-page'
96 ;; Move selection forward with a pageful.
97 ;; `anything-beginning-of-buffer'
98 ;; Move selection at the top.
99 ;; `anything-end-of-buffer'
100 ;; Move selection at the bottom.
101 ;; `anything-previous-source'
102 ;; Move selection to the previous source.
103 ;; `anything-next-source'
104 ;; Move selection to the next source.
105 ;; `anything-exit-minibuffer'
106 ;; Select the current candidate by exiting the minibuffer.
107 ;; `anything-help'
108 ;; Help of `anything'.
109 ;; `anything-debug-output'
110 ;; Show all anything-related variables at this time.
111 ;; `anything-delete-current-selection'
112 ;; Delete the currently selected item.
113 ;; `anything-delete-minibuffer-content'
114 ;; Same as `delete-minibuffer-contents' but this is a command.
115 ;; `anything-toggle-resplit-window'
116 ;; Toggle resplit anything window, vertically or horizontally.
117 ;; `anything-select-2nd-action'
118 ;; Select the 2nd action for the currently selected candidate.
119 ;; `anything-select-3rd-action'
120 ;; Select the 3rd action for the currently selected candidate.
121 ;; `anything-select-4th-action'
122 ;; Select the 4th action for the currently selected candidate.
123 ;; `anything-select-2nd-action-or-end-of-line'
124 ;; Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
125 ;; `anything-execute-persistent-action'
126 ;; If a candidate is selected then perform the associated action without quitting anything.
127 ;; `anything-scroll-other-window'
128 ;; Scroll other window (not *Anything* window) upward.
129 ;; `anything-scroll-other-window-down'
130 ;; Scroll other window (not *Anything* window) downward.
131 ;; `anything-display-all-visible-marks'
132 ;; Show all `anything' visible marks strings.
133 ;; `anything-quit-and-find-file'
134 ;; Drop into `find-file' from `anything' like `iswitchb-find-file'.
135 ;; `anything-yank-selection'
136 ;; Set minibuffer contents to current selection.
137 ;; `anything-kill-selection-and-quit'
138 ;; Store current selection to kill ring.
139 ;; `anything-follow-mode'
140 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
141 ;; `anything-migrate-sources'
142 ;; Help to migrate to new `anything' way.
143 ;; `anything-isearch'
144 ;; Start incremental search within results. (UNMAINTAINED)
145 ;; `anything-isearch-printing-char'
146 ;; Add printing char to the pattern.
147 ;; `anything-isearch-again'
148 ;; Search again for the current pattern
149 ;; `anything-isearch-delete'
150 ;; Undo last event.
151 ;; `anything-isearch-default-action'
152 ;; Execute the default action for the selected candidate.
153 ;; `anything-isearch-select-action'
154 ;; Choose an action for the selected candidate.
155 ;; `anything-isearch-cancel'
156 ;; Cancel Anything isearch.
157 ;; `anything-iswitchb-setup'
158 ;; Integrate anything completion into iswitchb (UNMAINTAINED).
159 ;; `anything-iswitchb-cancel-anything'
160 ;; Cancel anything completion and return to standard iswitchb.
161 ;; `anything-describe-anything-attribute'
162 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
164 ;;; Customizable Options:
166 ;; Below are customizable option list:
169 ;; You can extend `anything' by writing plug-ins. As soon as
170 ;; `anything' is invoked, `anything-sources' is compiled into basic
171 ;; attributes, then compiled one is used during invocation.
173 ;; The oldest built-in plug-in is `type' attribute: appends
174 ;; appropriate element of `anything-type-attributes'. Second built-in
175 ;; plug-in is `candidates-in-buffer': selecting a line from candidates
176 ;; buffer.
178 ;; To write a plug-in:
179 ;; 1. Define a compiler: anything-compile-source--*
180 ;; 2. Add compier function to `anything-compile-source-functions'.
181 ;; 3. (optional) Write helper functions.
183 ;; Anything plug-ins are found in the EmacsWiki.
185 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
187 ;; Tested on Emacs 22/23.
190 ;; Thanks to Vagn Johansen for ideas.
191 ;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
192 ;; Thanks to Tassilo Horn for fixes.
193 ;; Thanks to Drew Adams for various fixes (frame, isearch, customization, etc.)
194 ;; Thanks to IMAKADO for candidates-in-buffer idea.
195 ;; Thanks to Tomohiro MATSUYAMA for multiline patch.
198 ;;; (@* "Index")
200 ;; If you have library `linkd.el', load
201 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
202 ;; navigate around the sections Linkd mode will
203 ;; highlight this Index. You can get `linkd.el' here:
204 ;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
208 ;;; (@* "INCOMPATIBLE CHANGES")
210 ;; v1.277
212 ;; Default setting of `anything-save-configuration-functions' is changed.
213 ;; Anything saves/restores window configuration instead of frame configuration now.
214 ;; The default is changed because flickering is occurred in some environment.
216 ;; If you want to save and restore frame configuration, set this variable to
217 ;; '(set-frame-configuration . current-frame-configuration)
219 ;; v1.276
221 ;; Fitting frame is disabled by default, because some flickering occurred
222 ;; in some environment. To enable fitting, set both
223 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
224 ;; nil.
226 ;; v1.114
228 ;; `anything-attr' returns nil when the source attribute is defined
229 ;; but the value of attribute is nil, eg. (volatile) cell. Use
230 ;; `anything-attr-defined' when testing whether the attribute is
231 ;; defined.
233 ;;; (@* "Tips")
236 ;; `anything-enable-shortcuts' enables us to select candidate easily.
237 ;; If 'prefix then they can be selected using <prefix-key> <alnum>.
238 ;; The prefix key is `anything-select-with-prefix-shortcut'.
239 ;; If the <prefix-key> is a letter, pressing twice inputs the letter itself.
240 ;; e.g.
241 ;; (setq anything-enable-shortcuts 'prefix)
242 ;; (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
245 ;; You can edit current selection using `anything-edit-current-selection'.
246 ;; It is useful after persistent-action.
249 ;; For `anything' users, setting `anything-sources' directly and
250 ;; invoke M-x anything is obsolete way for now. Try M-x
251 ;; `anything-migrate-sources'!
254 ;; If you want to create anything sources, yasnippet would help you.
255 ;; http://yasnippet.googlecode.com/
257 ;; Then get the snippet from
258 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
260 ;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
264 ;; `anything-interpret-value' is useful function to interpret value
265 ;; like `candidates' attribute.
267 ;; (anything-interpret-value "literal") ; => "literal"
268 ;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
269 ;; (let ((source '((name . "lambda with source name"))))
270 ;; (anything-interpret-value
271 ;; (lambda () anything-source-name)
272 ;; source)) ; => "lambda with source name"
273 ;; (flet ((f () "function symbol"))
274 ;; (anything-interpret-value 'f)) ; => "function symbol"
275 ;; (let ((v "variable symbol"))
276 ;; (anything-interpret-value 'v)) ; => "variable symbol"
277 ;; (anything-interpret-value 'unbounded-1) ; error
280 ;; Now symbols are acceptable as candidates. So you do not have to use
281 ;; `symbol-name' function. The source is much simpler. For example,
282 ;; `apropos-internal' returns a list of symbols.
284 ;; (anything
285 ;; '(((name . "Commands")
286 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
287 ;; (volatile)
288 ;; (action . describe-function))))
291 ;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
292 ;; marked candidate, press M-[ or M-].
295 ;; `anything-map' is now Emacs-standard key bindings by default. If
296 ;; you are using `iswitchb', execute `anything-iswitchb-setup'. Then
297 ;; some key bindings are adjusted to `iswitchb'. Note that
298 ;; anything-iswitchb is not maintained.
301 ;; There are many `anything' applications, using `anything' for
302 ;; selecting candidate. In this case, if there is one candidate or no
303 ;; candidate, popping up *anything* buffer is irritating. If one
304 ;; candidate, you want to select it at once. If no candidate, you want
305 ;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
306 ;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
307 ;; that setting these variables GLOBALLY is bad idea because of
308 ;; delayed sources. These are meant to be let-binded.
309 ;; See anything-etags.el for example.
311 ;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
313 ;; ex.
314 ;; (let ((anything-execute-action-at-once-if-one t)
315 ;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
316 ;; (anything temporary-sources input))
319 ;; `set-frame-configuration' arises flickering. If you hate
320 ;; flickering, eval:
321 ;; (setq anything-save-configuration-functions
322 ;; '(set-window-configuration . current-window-configuration))
323 ;; at the cost of restoring frame configuration (only window configuration).
326 ;; `anything-delete-current-selection' deletes the current line.
327 ;; It is useful when deleting a candidate in persistent action.
328 ;; eg. `kill-buffer'.
330 ;; [EVAL IT] (describe-function 'anything-delete-current-selection)
333 ;; `anything-attr' gets the attribute. `anything-attrset' sets the
334 ;; attribute. `anything-attr-defined' tests whether the attribute is
335 ;; defined. They handles source-local variables.
337 ;; [EVAL IT] (describe-function 'anything-attr)
338 ;; [EVAL IT] (describe-function 'anything-attrset)
339 ;; [EVAL IT] (describe-function 'anything-attr-defined)
342 ;; `anything-sources' accepts many attributes to make your life easier.
343 ;; Now `anything-sources' accepts a list of symbols.
345 ;; [EVAL IT] (describe-variable 'anything-sources)
348 ;; `anything' has optional arguments. Now you do not have to let-bind
349 ;; `anything-sources'.
351 ;; [EVAL IT] (describe-function 'anything)
354 ;; `anything-resume' resumes last `anything' session. Now you do not
355 ;; have to retype pattern.
357 ;; [EVAL IT] (describe-function 'anything-resume)
360 ;; `anything-execute-persistent-action' executes action without
361 ;; quitting `anything'. When popping up a buffer in other window by
362 ;; persistent action, you can scroll with `anything-scroll-other-window' and
363 ;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
365 ;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
366 ;; [EVAL IT] (describe-variable 'anything-sources)
369 ;; `anything-select-2nd-action', `anything-select-3rd-action' and
370 ;; `anything-select-4th-action' select other than default action
371 ;; without pressing Tab.
374 ;; Using `anything-candidate-buffer' and the candidates-in-buffer
375 ;; attribute is much faster than traditional "candidates and match"
376 ;; way. And `anything-current-buffer-is-modified' avoids to
377 ;; recalculate candidates for unmodified buffer. See docstring of
378 ;; them.
380 ;; [EVAL IT] (describe-function 'anything-candidate-buffer)
381 ;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
382 ;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
385 ;; `anything-current-buffer' and `anything-buffer-file-name' stores
386 ;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
387 ;; is invoked. Use them freely.
389 ;; [EVAL IT] (describe-variable 'anything-current-buffer)
390 ;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
393 ;; `anything-completing-read' and `anything-read-file-name' are
394 ;; experimental implementation. If you are curious, type M-x
395 ;; anything-read-string-mode. It is a minor mode and toggles on/off.
398 ;; Use `anything-test-candidates' to test your handmade anything
399 ;; sources. It simulates contents of *anything* buffer with pseudo
400 ;; `anything-sources' and `anything-pattern', without side-effect. So
401 ;; you can unit-test your anything sources! Let's TDD!
403 ;; [EVAL IT] (describe-function 'anything-test-candidates)
405 ;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
406 ;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
408 ;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
409 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
410 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
413 ;; If you want to create anything sources, see anything-config.el.
414 ;; It is huge collection of sources. You can learn from examples.
417 ;; (@* "TODO")
419 ;; - process status indication
421 ;; - async sources doesn't honor digit-shortcut-count
423 ;; - anything-candidate-number-limit can't be nil everywhere
425 ;; (@* "HISTORY")
426 ;; $Log: anything.el,v $
427 ;; Revision 1.280 2010-04-01 02:22:22 rubikitch
428 ;; `anything': new argument ANY-KEYMAP
430 ;; Revision 1.279 2010/03/31 09:22:58 rubikitch
431 ;; Add tips of yasnippet for source creators (no code change)
433 ;; Revision 1.278 2010/03/31 09:01:08 rubikitch
434 ;; Added info to INCOMPATIBLE CHANGES
436 ;; Revision 1.277 2010/03/31 08:56:53 rubikitch
437 ;; Anything saves/restores window configuration instead of frame configuration now.
438 ;; The default is changed because flickering is occurred in some environment.
440 ;; If you want to save and restore frame configuration, set this variable to
441 ;; '(set-frame-configuration . current-frame-configuration)
443 ;; Revision 1.276 2010/03/31 08:52:50 rubikitch
444 ;; Fitting frame is disabled by default, because some flickering occurred
445 ;; in some environment. To enable fitting, set both
446 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
447 ;; nil.
449 ;; Revision 1.275 2010/03/31 02:46:09 rubikitch
450 ;; (defvaralias 'anything-attributes 'anything-additional-attributes)
452 ;; Revision 1.274 2010/03/31 02:43:35 rubikitch
453 ;; New command: `anything-describe-anything-attribute'
455 ;; Revision 1.273 2010/03/31 02:37:18 rubikitch
456 ;; Document all attributes by `anything-document-attribute' instead of `anything-sources' docstring
458 ;; Revision 1.272 2010/03/29 21:05:47 rubikitch
459 ;; `anything-mode-line-string': use `make-local-variable' instead
461 ;; Revision 1.271 2010/03/29 09:59:17 rubikitch
462 ;; stupid bug
464 ;; Revision 1.270 2010/03/29 09:56:12 rubikitch
465 ;; Call `filtered-candidate-transformer' functions even if process sources
467 ;; Revision 1.269 2010/03/29 08:42:23 rubikitch
468 ;; * New attribute `resume'
469 ;; * Fix a bug of `disable-shortcuts' plug-in
471 ;; Revision 1.268 2010/03/28 21:42:01 rubikitch
472 ;; Add some keys in `anything-help'
474 ;; Revision 1.267 2010/03/28 20:11:30 rubikitch
475 ;; Modify `anything-mode-line-string'
477 ;; Revision 1.266 2010/03/28 06:12:43 rubikitch
478 ;; process source and multiline: in the making (not usable)
480 ;; Revision 1.265 2010/03/28 05:07:00 rubikitch
481 ;; Change default `anything-sources'. It is only a sample, no problem.
483 ;; Revision 1.264 2010/03/27 19:02:52 rubikitch
484 ;; New attributes: `mode-line' and `header-line'
486 ;; Revision 1.263 2010/03/27 02:34:40 rubikitch
487 ;; doc
489 ;; Revision 1.262 2010/03/27 02:31:55 rubikitch
490 ;; New command: `anything-force-update' C-c C-u
492 ;; Revision 1.261 2010/03/27 02:29:39 rubikitch
493 ;; New function `anything-goto-source'
495 ;; Revision 1.260 2010/03/27 02:01:28 rubikitch
496 ;; reimplement move selection commands
498 ;; Revision 1.259 2010/03/26 22:52:15 rubikitch
499 ;; `anything-quit-and-find-file':
500 ;; If current selection is a buffer or a file, `find-file' from its directory.
501 ;; Idea from http://i-yt.info/?date=20090826#p01 with some modification. Thanks.
503 ;; Revision 1.258 2010/03/26 12:10:55 rubikitch
504 ;; * modify `anything-mode-line-string'
505 ;; * New command `anything-help'
507 ;; Revision 1.257 2010/03/24 11:08:19 rubikitch
508 ;; revert to 1.255
510 ;; Revision 1.256 2010/03/24 08:29:43 rubikitch
511 ;; `anything-check-minibuffer-input' set repeat timer.
513 ;; Revision 1.255 2010/03/24 02:35:47 rubikitch
514 ;; `anything-candidate-number-limit':
515 ;; When (candidate-number-limit) is specified in SOURCE,
516 ;; cancel the effect of `anything-candidate-number-limit'.
518 ;; Revision 1.254 2010/03/23 00:33:18 rubikitch
519 ;; New API: `anything-interpret-value'
521 ;; Revision 1.253 2010/03/22 07:04:03 rubikitch
522 ;; `anything-get-current-source': return nil when no candidates rather than error
524 ;; Revision 1.252 2010/03/21 06:08:44 rubikitch
525 ;; Mark bug fix. thx hchbaw!
526 ;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
528 ;; Revision 1.251 2010/03/21 02:39:34 rubikitch
529 ;; Fix a wrong usage of `delq'. thx hchbaw.
530 ;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
532 ;; Revision 1.250 2010/03/21 02:32:29 rubikitch
533 ;; Fix `select deleted buffer' error message when calling `anything-resume'.
535 ;; It was occurred when killing `anything-current-buffer' and calling `anything-resume'.
537 ;; Revision 1.249 2010/02/23 20:43:35 rubikitch
538 ;; `anything-update': Ensure to call `anything-next-line'
540 ;; Revision 1.248 2010/02/20 12:34:38 rubikitch
541 ;; Mode-line help!! `anything-mode-line-string' is help string.
543 ;; Revision 1.247 2010/02/20 10:41:39 rubikitch
544 ;; Automatically update `anything-version' when upgrading
546 ;; Revision 1.246 2010/02/20 10:38:58 rubikitch
547 ;; update copyright
549 ;; Revision 1.245 2010/02/20 10:36:01 rubikitch
550 ;; New API: `anything-require-at-least-version'
552 ;; Revision 1.244 2010/02/20 10:06:54 rubikitch
553 ;; * New plug-in: `disable-shortcuts'
554 ;; * `dummy' plug-in implies `disable-shortcuts' because it enables us to input capital letters.
556 ;; Revision 1.243 2010/02/20 09:54:16 rubikitch
557 ;; `anything-compile-source--dummy': swap arguments of `append'
559 ;; Revision 1.242 2010/02/19 17:37:12 rubikitch
560 ;; error check in `anything-set-source-filter'
562 ;; Revision 1.241 2010/01/29 18:53:17 rubikitch
563 ;; Fix a bug of `candidate-number-limit' in process sources.
565 ;; Revision 1.240 2010/01/23 04:21:31 rubikitch
566 ;; * `anything': Use `anything-display-buffer' as fallback
567 ;; * `anything-select-with-digit-shortcut': `self-insert-command' if disabled
569 ;; Revision 1.239 2009/12/28 07:33:28 rubikitch
570 ;; New command: `anything-toggle-resplit-window' (C-t)
572 ;; Revision 1.238 2009/12/28 07:19:37 rubikitch
573 ;; bugfix
575 ;; Revision 1.237 2009/12/28 07:15:30 rubikitch
576 ;; `anything-window-configuration' stores window configuration only.
578 ;; Revision 1.236 2009/12/28 07:07:09 rubikitch
579 ;; `anything-resume' resumes window configuration now.
581 ;; Revision 1.235 2009/12/28 04:12:33 rubikitch
582 ;; Fix tiny bug
584 ;; Revision 1.234 2009/12/28 03:57:33 rubikitch
585 ;; `anything-resume': New optional argument
587 ;; Revision 1.233 2009/12/28 03:43:12 rubikitch
588 ;; remove warnings
590 ;; Revision 1.232 2009/12/28 03:37:25 rubikitch
591 ;; refactoring
593 ;; Revision 1.231 2009/12/28 02:33:41 rubikitch
594 ;; refactoring
596 ;; Revision 1.230 2009/12/27 09:28:06 rubikitch
597 ;; `anything-window-configuration' save/restore anything window configuration (NOT YET)
599 ;; Revision 1.229 2009/12/26 21:41:33 rubikitch
600 ;; revive `anything-input' when resuming
602 ;; Revision 1.228 2009/12/25 01:34:35 rubikitch
603 ;; * `anything-resume' use anything interface to select anything buffers.
604 ;; * Its candidates are sorted by most recently used order.
605 ;; * 4th arg of `anything' accepts 'noresume not to resume this session.
607 ;; Revision 1.227 2009/12/19 20:30:12 rubikitch
608 ;; add `pattern-transformer' doc
610 ;; Revision 1.226 2009/12/19 20:15:47 rubikitch
611 ;; pattern-transformer can have multiple functions now
613 ;; Revision 1.225 2009/12/19 20:11:16 rubikitch
614 ;; add `delayed-init' doc
616 ;; Revision 1.224 2009/12/19 12:26:00 rubikitch
617 ;; New attribute `pattern-transformer'
619 ;; Revision 1.223 2009/12/19 11:57:41 rubikitch
620 ;; New attribute `delayed-init'
622 ;; Revision 1.222 2009/12/14 20:55:23 rubikitch
623 ;; Fix display bug: `anything-enable-digit-shortcuts' / multiline
625 ;; Revision 1.221 2009/12/14 20:29:49 rubikitch
626 ;; fix an error when executing `anything-prev-visible-mark' with no visible marks.
628 ;; Revision 1.220 2009/12/14 20:19:05 rubikitch
629 ;; Bugfix about anything-execute-action-at-once-if-one and multiline
631 ;; Revision 1.219 2009/12/14 03:21:11 rubikitch
632 ;; Extend alphabet shortcuts to A-Z
634 ;; Revision 1.218 2009/12/13 01:03:34 rubikitch
635 ;; Changed data structure of `anything-shortcut-keys-alist'
637 ;; Revision 1.217 2009/12/03 23:16:17 rubikitch
638 ;; silence warning
640 ;; Revision 1.216 2009/12/03 20:43:51 rubikitch
641 ;; Add keybindings for alphabet shortcuts
643 ;; Revision 1.215 2009/12/03 20:37:13 rubikitch
644 ;; `anything-enable-shortcuts' is an alias of `anything-enable-digit-shortcuts'.
645 ;; Alphabet shortcuts can be used now.
647 ;; Revision 1.214 2009/12/03 20:23:40 rubikitch
648 ;; `anything-enable-digit-shortcuts' also accepts 'alphabet.
650 ;; Now alphabet shortcuts are usable.
652 ;; Revision 1.213 2009/12/03 09:59:58 rubikitch
653 ;; refactoring
655 ;; Revision 1.212 2009/11/15 09:42:15 rubikitch
656 ;; refactoring
658 ;; Revision 1.211 2009/11/06 21:42:58 rubikitch
659 ;; New command: `anything-beginning-of-buffer', `anything-end-of-buffer'
661 ;; Revision 1.210 2009/10/22 13:30:06 rubikitch
662 ;; `real-to-display' function is evaluated just after `candidate-transformer' function now.
663 ;; This enables us to narrow candidates by display string by `real-to-display'.
665 ;; Revision 1.209 2009/10/21 20:25:10 rubikitch
666 ;; Add a document. (no code change)
668 ;; Revision 1.208 2009/10/21 11:31:15 rubikitch
669 ;; `anything': accept one source alist
671 ;; Revision 1.207 2009/10/16 19:47:39 rubikitch
672 ;; Link to Japanese translation of `anything-sources' attributes. (No code change)
674 ;; Revision 1.206 2009/10/10 09:28:54 rubikitch
675 ;; Remove an unnecessary test
677 ;; Revision 1.205 2009/10/10 06:21:28 rubikitch
678 ;; obsolete: `anything-c-marked-candidate-list'
679 ;; New function: `anything-marked-candidates'
681 ;; Revision 1.204 2009/10/06 21:01:12 rubikitch
682 ;; Call `anything-process-delayed-sources' only if delayed-sources is available.
684 ;; Revision 1.203 2009/10/02 10:04:07 rubikitch
685 ;; Tested on Emacs23 too. (no code change)
687 ;; Revision 1.202 2009/10/02 10:03:34 rubikitch
688 ;; * Display "no candidates" rather than assertion
689 ;; * Ensure to call `remove-hook' in `anything-current-buffer'
691 ;; Revision 1.201 2009/08/08 13:25:30 rubikitch
692 ;; `anything-toggle-visible-mark': move next line after unmarking
694 ;; Revision 1.200 2009/08/08 13:23:46 rubikitch
695 ;; `anything-toggle-visible-mark': Applied ThierryVolpiatto's patch. thx.
697 ;; Revision 1.199 2009/07/19 13:22:29 rubikitch
698 ;; `anything-follow-execute-persistent-action-maybe': execute persistent action after `anything-input-idle-delay'
700 ;; Revision 1.198 2009/07/06 15:22:48 rubikitch
701 ;; header modified (no code change)
703 ;; Revision 1.197 2009/06/29 15:10:13 rubikitch
704 ;; OOPS! remove debug code
706 ;; Revision 1.196 2009/06/29 13:29:25 rubikitch
707 ;; anything-follow-mode: automatical execution of persistent-action (C-c C-f)
709 ;; Revision 1.195 2009/06/19 14:42:57 rubikitch
710 ;; silence byte compiler
712 ;; Revision 1.194 2009/06/14 15:12:34 rubikitch
713 ;; typo
715 ;; Revision 1.193 2009/06/08 19:37:12 rubikitch
716 ;; typo!
718 ;; Revision 1.192 2009/06/08 19:36:39 rubikitch
719 ;; New keybind: C-e, C-j, C-k
721 ;; Revision 1.191 2009/06/08 19:30:27 rubikitch
722 ;; New command: `anything-select-2nd-action-or-end-of-line'
724 ;; Revision 1.190 2009/06/07 17:09:50 rubikitch
725 ;; add M-<next>, C-M-S-v, M-<prior> to `anything-map'.
727 ;; Revision 1.189 2009/06/01 21:36:31 rubikitch
728 ;; New function: `anything-other-buffer'
730 ;; Revision 1.188 2009/05/29 18:33:07 rubikitch
731 ;; avoid error when executing (anything-mark-current-line) in async process.
733 ;; Revision 1.187 2009/05/29 06:49:05 rubikitch
734 ;; small refactoring
736 ;; Revision 1.186 2009/05/29 06:46:34 rubikitch
737 ;; Prevent `anything-isearch-map' from overwriting `global-map'. With
738 ;; `copy-keymap', the prefix command "M-s" in `global-map' ends up
739 ;; getting clobbered by `anything-isearch-again', preventing `occur'
740 ;; (among other things) from running. This change replaces overwriting a
741 ;; copied map with writing to a sparse map whose parent is `global-map'.
743 ;; patched by DanielHackney. thanks!
745 ;; Revision 1.185 2009/05/25 19:07:42 rubikitch
746 ;; `anything': set `case-fold-search' to t
747 ;; Because users can assign commands to capital letter keys.
749 ;; Revision 1.184 2009/05/25 19:05:04 rubikitch
750 ;; Added auto-document
752 ;; Revision 1.183 2009/05/15 01:50:46 rubikitch
753 ;; typo
755 ;; Revision 1.182 2009/05/08 18:28:18 rubikitch
756 ;; Bug fix: `anything-attr' is usable in `header-name' function.
758 ;; Revision 1.181 2009/05/04 19:05:03 rubikitch
759 ;; * `anything-yank-selection' and `anything-kill-selection-and-quit' handles display string now.
760 ;; * `anything-get-selection': Added optional arguments.
762 ;; Revision 1.180 2009/05/03 19:03:34 rubikitch
763 ;; Add `anything-input' to `minibuffer-history' even if `anything' is quit.
765 ;; Revision 1.179 2009/04/20 16:35:44 rubikitch
766 ;; New keybindings in anything-map:
767 ;; C-c C-d: `anything-delete-current-selection'
768 ;; C-c C-y: `anything-yank-selection'
769 ;; C-c C-k: `anything-kill-selection-and-quit'
771 ;; Revision 1.178 2009/04/20 16:18:58 rubikitch
772 ;; New variable: `anything-display-function'
774 ;; Revision 1.177 2009/04/20 02:17:16 rubikitch
775 ;; New commands: `anything-yank-selection', `anything-kill-selection-and-quit'
777 ;; Revision 1.176 2009/04/08 14:48:15 rubikitch
778 ;; bug fix in `anything-candidate-buffer'
780 ;; Revision 1.175 2009/03/22 19:10:37 rubikitch
781 ;; New Variable: `anything-scroll-amount' (thx. ThierryVolpiatto)
783 ;; Revision 1.174 2009/03/12 19:12:24 rubikitch
784 ;; New API: `define-anything-type-attribute'
786 ;; Revision 1.173 2009/03/11 08:10:32 rubikitch
787 ;; Update doc
789 ;; Revision 1.172 2009/03/10 17:11:58 rubikitch
790 ;; `candidate-transformer', `filtered-candidate-transformer',
791 ;; `action-transformer' attributes: accept a list of functions
793 ;; Revision 1.171 2009/03/09 18:49:44 rubikitch
794 ;; New command: `anything-quit-and-find-file'
796 ;; Revision 1.170 2009/03/09 18:46:11 rubikitch
797 ;; New API: `anything-run-after-quit'
799 ;; Revision 1.169 2009/03/09 10:02:49 rubikitch
800 ;; Set candidate-number-limit attribute for actions.
802 ;; Revision 1.168 2009/03/07 21:01:10 rubikitch
803 ;; Bug workaround
805 ;; Revision 1.167 2009/03/06 04:13:42 rubikitch
806 ;; Fix doc
808 ;; Revision 1.166 2009/03/03 10:35:57 rubikitch
809 ;; Set default `anything-input-idle-delay' to 0.1
811 ;; Revision 1.165 2009/03/03 07:14:42 rubikitch
812 ;; Make sure to run `anything-update-hook' after processing delayed sources.
814 ;; Revision 1.164 2009/03/02 01:51:40 rubikitch
815 ;; better error handling.
817 ;; Revision 1.163 2009/03/01 05:15:00 rubikitch
818 ;; anything-iswitchb and anything-isearch are marked as unmaintained.
819 ;; (document change only)
821 ;; Revision 1.162 2009/02/28 01:24:13 rubikitch
822 ;; Symbols are now acceptable as candidate.
824 ;; Revision 1.161 2009/02/27 07:18:46 rubikitch
825 ;; Fix bug of `anything-scroll-other-window' and `anything-scroll-other-window-down'.
827 ;; Revision 1.160 2009/02/27 01:05:06 rubikitch
828 ;; * Make sure to restore point after running `anything-update-hook'.
829 ;; * Make `anything-compute-matches' easy to find error.
831 ;; Revision 1.159 2009/02/26 23:45:48 rubikitch
832 ;; * Check whether candidate is a string, otherwise ignore.
834 ;; Revision 1.158 2009/02/24 06:39:20 rubikitch
835 ;; suppress compile warnings.
837 ;; Revision 1.157 2009/02/23 22:51:43 rubikitch
838 ;; New function: `anything-document-attribute'
840 ;; Revision 1.156 2009/02/23 21:36:09 rubikitch
841 ;; New Variable: `anything-display-source-at-screen-top'
843 ;; Revision 1.155 2009/02/23 21:30:52 rubikitch
844 ;; New command: `anything-at-point'
846 ;; Revision 1.154 2009/02/23 08:57:54 rubikitch
847 ;; Visible Mark
849 ;; Revision 1.153 2009/02/23 08:38:57 rubikitch
850 ;; update doc
852 ;; Revision 1.152 2009/02/23 08:32:17 rubikitch
853 ;; More key bindings.
855 ;; Revision 1.151 2009/02/23 08:21:24 rubikitch
856 ;; `anything-map' is now Emacs-standard key bindings by default.
857 ;; After evaluating `anything-iswitchb-setup'. some key bindings are adjusted to iswitchb.
859 ;; Revision 1.150 2009/02/20 22:58:18 rubikitch
860 ;; Cancel timer in `anything-cleanup'.
862 ;; Revision 1.149 2009/02/20 12:23:44 rubikitch
863 ;; `anything-header' face now inherits header-line (not a copy).
865 ;; Revision 1.148 2009/02/16 23:40:22 rubikitch
866 ;; `real-to-display' attribute bug fix.
868 ;; Revision 1.147 2009/02/02 20:51:41 rubikitch
869 ;; New `anything-sources' attribute: real-to-display
871 ;; Revision 1.146 2009/02/01 20:01:00 rubikitch
872 ;; Update Tips
874 ;; Revision 1.145 2009/02/01 19:45:53 rubikitch
875 ;; New variable: `anything-quit-if-no-candidate'
877 ;; Revision 1.144 2009/02/01 19:31:47 rubikitch
878 ;; fixed a typo
880 ;; Revision 1.143 2009/02/01 19:23:32 rubikitch
881 ;; New variable: `anything-execute-action-at-once-if-one'
883 ;; Revision 1.142 2009/02/01 19:12:34 rubikitch
884 ;; `anything-persistent-action-display-buffer': bug fix
886 ;; Revision 1.141 2009/02/01 18:25:25 rubikitch
887 ;; * fix docstring
888 ;; * New variable: `anything-selection-face'
890 ;; Revision 1.140 2009/01/16 16:36:25 rubikitch
891 ;; New variable: `anything-persistent-action-use-special-display'.
893 ;; Revision 1.139 2009/01/05 20:15:53 rubikitch
894 ;; Fixed a bug of anything action buffer.
895 ;; The action source should not be cached.
897 ;; Revision 1.138 2008/12/21 16:56:05 rubikitch
898 ;; Fixed an error when action attribute is a function symbol and press TAB,
900 ;; Revision 1.137 2008/12/20 19:38:47 rubikitch
901 ;; `anything-check-minibuffer-input-1': proper quit handling
902 ;; `anything-process-delayed-sources': ditto
904 ;; Revision 1.136 2008/10/27 17:41:27 rubikitch
905 ;; `anything-process-delayed-sources', `anything-check-minibuffer-input-1': quittable
907 ;; Revision 1.135 2008/10/27 17:04:25 rubikitch
908 ;; arranged source, added more linkd tags (no code change)
910 ;; Revision 1.134 2008/10/27 15:02:25 rubikitch
911 ;; New variable: `anything-save-configuration-functions'
912 ;; Delete variable: `anything-save-configuration-type'
914 ;; Revision 1.133 2008/10/27 11:16:13 rubikitch
915 ;; New variable: `anything-save-configuration-type'
917 ;; Revision 1.132 2008/10/26 22:34:59 rubikitch
918 ;; `anything-delete-current-selection' with multiline
920 ;; Revision 1.131 2008/10/26 21:44:43 rubikitch
921 ;; New command: `anything-delete-current-selection'
923 ;; Revision 1.130 2008/10/22 10:41:09 rubikitch
924 ;; `anything-insert-match': do not override 'anything-realvalue property
926 ;; Revision 1.129 2008/10/21 17:01:37 rubikitch
927 ;; `anything-resume' per buffer.
928 ;; `anything-last-sources': obsolete
930 ;; Revision 1.128 2008/10/20 06:27:54 rubikitch
931 ;; `anything-quick-update': new user option
933 ;; Revision 1.127 2008/10/20 05:47:49 rubikitch
934 ;; refactoring
936 ;; Revision 1.126 2008/10/20 03:47:58 rubikitch
937 ;; `anything-update': reversed order of delayed sources
939 ;; Revision 1.125 2008/10/19 00:29:54 rubikitch
940 ;; kill buffer-local candidate buffers when creating global candidate buffers.
942 ;; Revision 1.124 2008/10/18 13:04:20 rubikitch
943 ;; Remove tick entry from `anything-tick-hash' when killing a buffer.
945 ;; Revision 1.123 2008/10/18 10:23:36 rubikitch
946 ;; multiline patch by Tomohiro MATSUYAMA.
948 ;; Revision 1.122 2008/10/13 03:10:07 rubikitch
949 ;; `anything': do `anything-mark-current-line' when resuming
951 ;; Revision 1.121 2008/10/13 03:08:08 rubikitch
952 ;; always set `anything-current-position'
954 ;; Revision 1.120 2008/10/07 14:12:02 rubikitch
955 ;; `anything-execute-persistent-action': optional arg
957 ;; Revision 1.119 2008/10/06 06:43:29 rubikitch
958 ;; `anything-candidate-buffer': return nil when the buffer is dead
960 ;; Revision 1.118 2008/09/30 22:21:28 rubikitch
961 ;; New `anything-sources' attribute: accept-empty
962 ;; dummy: include accept-empty
964 ;; Revision 1.117 2008/09/30 21:59:10 rubikitch
965 ;; New function: `anything-buffer-is-modified'
967 ;; Revision 1.116 2008/09/22 11:27:29 rubikitch
968 ;; *** empty log message ***
970 ;; Revision 1.115 2008/09/20 20:21:11 rubikitch
971 ;; added linkd index. (no code change)
973 ;; Revision 1.114 2008/09/20 20:09:57 rubikitch
974 ;; INCOMPATIBLE CHANGES: `anything-attr'
975 ;; New functions: `anything-attrset', `anything-attr-defined'
977 ;; Revision 1.113 2008/09/14 15:15:32 rubikitch
978 ;; bugfix: volatile and match attribute / process and match attribute
980 ;; Revision 1.112 2008/09/12 01:57:17 rubikitch
981 ;; When resuming anything, reinitialize overlays.
983 ;; Revision 1.111 2008/09/10 22:53:11 rubikitch
984 ;; anything: bug fix of `anything-buffer'
985 ;; New macro: `anything-test-update'
987 ;; Revision 1.110 2008/09/10 22:17:11 rubikitch
988 ;; New `anything-sources' attribute: header-name
990 ;; Revision 1.109 2008/09/10 21:12:26 rubikitch
991 ;; New hook: `anything-after-action-hook'
993 ;; Revision 1.108 2008/09/06 06:07:56 rubikitch
994 ;; Extended `anything-set-sources' optional arguments.
996 ;; Revision 1.107 2008/09/05 03:14:35 rubikitch
997 ;; reimplement `anything-current-buffer-is-modified' in the right way
999 ;; Revision 1.106 2008/09/05 00:11:05 rubikitch
1000 ;; Moved `anything-read-string-mode' and read functions to anything-complete.el.
1002 ;; Revision 1.105 2008/09/04 12:45:06 rubikitch
1003 ;; New hook: `anything-after-persistent-action-hook'
1005 ;; Revision 1.104 2008/09/04 12:27:05 rubikitch
1006 ;; `anything': prefixed optional arguments
1008 ;; Revision 1.103 2008/09/04 09:16:28 rubikitch
1009 ;; fixed a bug of `anything-read-file-name'.
1011 ;; Revision 1.102 2008/09/03 11:25:19 rubikitch
1012 ;; Extended `anything' optional arguments: buffer
1014 ;; Revision 1.101 2008/09/03 11:15:13 rubikitch
1015 ;; `anything': return nil when keybord-quitted
1017 ;; Revision 1.100 2008/09/01 23:11:02 rubikitch
1018 ;; bug fix of search-from-end
1020 ;; Revision 1.99 2008/09/01 13:45:55 rubikitch
1021 ;; bug fix of search-from-end
1023 ;; Revision 1.98 2008/09/01 11:23:38 rubikitch
1024 ;; New `anything-sources' attribute: search-from-end
1026 ;; Revision 1.97 2008/09/01 00:44:34 rubikitch
1027 ;; Make sure to display the other window when persistent action.
1029 ;; Revision 1.96 2008/08/31 20:55:20 rubikitch
1030 ;; define `buffer-modified-tick' for older emacs.
1032 ;; Revision 1.95 2008/08/30 04:55:51 rubikitch
1033 ;; fixed a bug of `anything-completing-read'
1035 ;; Revision 1.94 2008/08/28 20:18:03 rubikitch
1036 ;; added some tests
1038 ;; Revision 1.93 2008/08/25 20:18:46 rubikitch
1039 ;; `anything': set `anything-input' and `anything-pattern' before `anything-update'
1041 ;; Revision 1.92 2008/08/24 22:38:46 rubikitch
1042 ;; *** empty log message ***
1044 ;; Revision 1.91 2008/08/24 21:34:35 rubikitch
1045 ;; rewrite `with-anything-restore-variables'
1047 ;; Revision 1.90 2008/08/24 20:33:02 rubikitch
1048 ;; prevent the unit test from byte-compiled.
1049 ;; macro bug fix.
1051 ;; Revision 1.89 2008/08/24 08:35:27 rubikitch
1052 ;; *** empty log message ***
1054 ;; Revision 1.88 2008/08/24 08:22:19 rubikitch
1055 ;; Rename `anything-candidates-buffer' -> `anything-candidate-buffer'
1057 ;; Revision 1.87 2008/08/23 22:27:04 rubikitch
1058 ;; New hook: `anything-cleanup-hook'
1060 ;; Revision 1.86 2008/08/23 22:05:42 rubikitch
1061 ;; `anything-original-source-filter' is removed.
1062 ;; Now use `anything-restored-variables' and `with-anything-restore-variables'.
1064 ;; Revision 1.85 2008/08/23 21:23:21 rubikitch
1065 ;; inhibit-read-only = t in anything-buffer
1067 ;; Revision 1.84 2008/08/23 21:18:33 rubikitch
1068 ;; *** empty log message ***
1070 ;; Revision 1.83 2008/08/23 20:44:20 rubikitch
1071 ;; `anything-execute-persistent-action': display-to-real bug fix
1073 ;; Revision 1.82 2008/08/23 20:19:12 rubikitch
1074 ;; New `anything-sources' attribute: get-line
1076 ;; Revision 1.81 2008/08/23 19:32:14 rubikitch
1077 ;; `anything-attr': Return t in (attribute-name) case.
1079 ;; Revision 1.80 2008/08/22 21:25:05 rubikitch
1080 ;; anything-candidates-in-buffer-1:
1081 ;; Open a line at the BOB to make use of `search-forward' for faster exact/prefix match.
1082 ;; Of course, restore the buffer contents after search.
1084 ;; Revision 1.79 2008/08/22 17:11:00 rubikitch
1085 ;; New hook: `anything-before-initialize-hook', `anything-after-initialize-hook'
1087 ;; Revision 1.78 2008/08/21 18:37:03 rubikitch
1088 ;; Implemented dummy sources as plug-in.
1090 ;; Revision 1.77 2008/08/21 17:40:40 rubikitch
1091 ;; New function: `anything-set-sources'
1093 ;; Revision 1.76 2008/08/21 12:25:02 rubikitch
1094 ;; New variable: `anything-version'
1096 ;; Revision 1.75 2008/08/21 12:13:46 rubikitch
1097 ;; New variable: `anything-in-persistent-action'
1099 ;; Revision 1.74 2008/08/21 10:34:22 rubikitch
1100 ;; New function `anything-mklist'
1102 ;; Revision 1.73 2008/08/21 09:41:38 rubikitch
1103 ;; accept multiple init/cleanup functions so that plug-ins can add new function.
1105 ;; Revision 1.72 2008/08/20 22:51:53 rubikitch
1106 ;; New `anything-sources' attribute: candidate-number-limit
1108 ;; Revision 1.71 2008/08/20 21:45:42 rubikitch
1109 ;; added many tests.
1111 ;; Revision 1.70 2008/08/20 18:51:45 rubikitch
1112 ;; `anything-preselect' bug fix.
1113 ;; refactoring.
1115 ;; Revision 1.69 2008/08/20 17:57:51 rubikitch
1116 ;; Extended `anything' optional arguments: preselect
1118 ;; Revision 1.68 2008/08/20 16:39:07 rubikitch
1119 ;; Nested `anything' invocation support, ie. `anything' can be invoked by anything action.
1121 ;; (anything '(((name . "nested anything invocation test")
1122 ;; (candidates "anything-c-source-buffers" "anything-c-source-man-pages")
1123 ;; (display-to-real . intern)
1124 ;; (action . anything))))
1126 ;; Revision 1.67 2008/08/20 00:08:28 rubikitch
1127 ;; `anything-candidates-in-buffer-1': add code when pattern == ""
1129 ;; Revision 1.66 2008/08/19 23:31:52 rubikitch
1130 ;; Removed `anything-show-exact-match-first' because it should be provided as a plug-in.
1132 ;; Revision 1.65 2008/08/19 23:18:47 rubikitch
1133 ;; *** empty log message ***
1135 ;; Revision 1.64 2008/08/19 23:15:43 rubikitch
1136 ;; `anything-compute-matches': short-cut when match == '(identity)
1138 ;; Revision 1.63 2008/08/19 23:06:42 rubikitch
1139 ;; Use hash table to speed uniquify candidates.
1141 ;; Revision 1.62 2008/08/19 22:40:57 rubikitch
1142 ;; `anything-test-candidates': additional optonal argument
1144 ;; Revision 1.61 2008/08/19 18:13:39 rubikitch
1145 ;; search attribute: multiple search functions
1147 ;; Revision 1.60 2008/08/19 15:07:39 rubikitch
1148 ;; New function: `anything-attr'
1150 ;; Revision 1.59 2008/08/19 15:01:59 rubikitch
1151 ;; arranged code
1152 ;; added unit tests
1153 ;; update doc
1155 ;; Revision 1.58 2008/08/19 13:40:52 rubikitch
1156 ;; `anything-get-current-source': This function can be used in
1157 ;; init/candidates/action/candidate-transformer/filtered-candidate-transformer
1158 ;; display-to-real/cleanup function.
1160 ;; Revision 1.57 2008/08/19 03:43:57 rubikitch
1161 ;; `anything-process-delayed-sources': delay = anything-idle-delay - anything-input-idle-delay
1163 ;; Revision 1.56 2008/08/18 06:37:51 rubikitch
1164 ;; Make `anything-input-idle-delay' ineffective when the action list is shown.
1166 ;; Revision 1.55 2008/08/18 06:35:00 rubikitch
1167 ;; New variable: `anything-show-exact-match-first'
1169 ;; Revision 1.54 2008/08/17 23:22:24 rubikitch
1170 ;; *** empty log message ***
1172 ;; Revision 1.53 2008/08/17 23:15:38 rubikitch
1173 ;; bind `anything-source-name' when executing action to enable to use `anything-candidate-buffer' in action.
1175 ;; Revision 1.52 2008/08/17 15:21:27 rubikitch
1176 ;; `anything-test-candidates': accept a symbol for source
1177 ;; New variable: `anything-input-idle-delay'
1179 ;; Revision 1.51 2008/08/17 12:45:30 rubikitch
1180 ;; (buffer-disable-undo) in anything-buffer
1182 ;; Revision 1.50 2008/08/16 22:21:37 rubikitch
1183 ;; `anything-saved-sources': removed
1184 ;; `anything-action-buffer': action selection buffer
1185 ;; `anything-select-action': toggle actions <=> candidates
1187 ;; Revision 1.49 2008/08/16 19:46:11 rubikitch
1188 ;; New function: `anything-action-list-is-shown'
1190 ;; Revision 1.48 2008/08/16 17:03:02 rubikitch
1191 ;; bugfix: cleanup
1193 ;; Revision 1.47 2008/08/16 16:35:24 rubikitch
1194 ;; silence byte compiler
1196 ;; Revision 1.46 2008/08/16 14:51:27 rubikitch
1197 ;; *** empty log message ***
1199 ;; Revision 1.45 2008/08/16 11:27:59 rubikitch
1200 ;; refactoring
1201 ;; `anything-aif': Anaphoric if.
1202 ;; `anything-compile-source-functions': make `anything-get-sources' customizable.
1204 ;; Revision 1.44 2008/08/16 09:38:15 rubikitch
1205 ;; *** empty log message ***
1207 ;; Revision 1.43 2008/08/15 11:44:28 rubikitch
1208 ;; `anything-read-string-mode': minor mode for `anything' version of read functions. (experimental)
1210 ;; Revision 1.42 2008/08/15 11:03:20 rubikitch
1211 ;; update docs
1213 ;; Revision 1.41 2008/08/14 20:51:28 rubikitch
1214 ;; New `anything-sources' attribute: cleanup
1216 ;; Revision 1.40 2008/08/14 10:34:04 rubikitch
1217 ;; `anything': SOURCES: accept symbols
1219 ;; Revision 1.39 2008/08/10 22:46:01 rubikitch
1220 ;; `anything-move-selection': avoid infinite loop
1222 ;; Revision 1.38 2008/08/09 21:38:25 rubikitch
1223 ;; `anything-read-file-name': experimental implementation.
1225 ;; Revision 1.37 2008/08/09 17:54:25 rubikitch
1226 ;; action test
1228 ;; Revision 1.36 2008/08/09 17:13:00 rubikitch
1229 ;; fixed test
1231 ;; Revision 1.35 2008/08/09 10:43:08 rubikitch
1232 ;; New `anything-sources' attribute: display-to-real
1234 ;; Revision 1.34 2008/08/07 13:15:44 rubikitch
1235 ;; New `anything-sources' attribute: search
1237 ;; Revision 1.33 2008/08/05 23:14:20 rubikitch
1238 ;; `anything-candidate-buffer': bugfix
1240 ;; Revision 1.32 2008/08/05 21:42:15 rubikitch
1241 ;; *** empty log message ***
1243 ;; Revision 1.31 2008/08/05 21:06:23 rubikitch
1244 ;; `anything-candidate-buffer': candidates buffer registration
1246 ;; Revision 1.30 2008/08/05 19:46:36 rubikitch
1247 ;; New `anything-sources' attribute: candidates-in-buffer
1249 ;; Revision 1.29 2008/08/05 17:58:31 rubikitch
1250 ;; *** empty log message ***
1252 ;; Revision 1.28 2008/08/05 17:46:04 rubikitch
1253 ;; memoized `anything-get-sources'
1255 ;; Revision 1.27 2008/08/05 17:29:40 rubikitch
1256 ;; update doc
1258 ;; Revision 1.26 2008/08/05 08:35:45 rubikitch
1259 ;; `anything-completing-read': accept obarray
1261 ;; Revision 1.25 2008/08/05 07:26:17 rubikitch
1262 ;; `anything-completing-read': guard from non-string return value
1264 ;; Revision 1.24 2008/08/04 12:05:41 rubikitch
1265 ;; Wrote Tips and some docstrings.
1266 ;; `anything-candidate-buffer': buffer-local by default
1268 ;; Revision 1.23 2008/08/04 05:29:46 rubikitch
1269 ;; `anything-buffer-file-name': `buffer-file-name' when `anything' is invoked.
1271 ;; Revision 1.22 2008/08/04 00:10:13 rubikitch
1272 ;; `anything-candidate-buffer': new API
1274 ;; Revision 1.21 2008/08/03 22:05:08 rubikitch
1275 ;; `anything-candidate-buffer': Return a buffer containing candidates of current source.
1277 ;; Revision 1.20 2008/08/03 20:47:56 rubikitch
1278 ;; `anything-current-buffer-is-modified': modify checker
1280 ;; Revision 1.19 2008/08/03 19:06:18 rubikitch
1281 ;; `anything-candidates-in-buffer': use `with-current-buffer' instead.
1283 ;; Revision 1.18 2008/08/03 05:55:01 rubikitch
1284 ;; `anything-candidates-in-buffer': extract candidates in a buffer for speed.
1286 ;; Revision 1.17 2008/08/02 21:31:29 rubikitch
1287 ;; Extended `anything' optional arguments.
1288 ;; `anything-completing-read': experimental implementation.
1290 ;; Revision 1.16 2008/08/02 20:32:54 rubikitch
1291 ;; Extended `anything' optional arguments.
1293 ;; Revision 1.15 2008/08/02 16:53:40 rubikitch
1294 ;; Fixed a small bug of `anything-test-candidates'.
1296 ;; Revision 1.14 2008/08/02 16:48:29 rubikitch
1297 ;; Refactored to testable code.
1298 ;; Added many candidate tests with `anything-test-candidates'.
1300 ;; Revision 1.13 2008/08/02 15:08:14 rubikitch
1301 ;; *** empty log message ***
1303 ;; Revision 1.12 2008/08/02 14:29:31 rubikitch
1304 ;; `anything-sources' accepts symbols. (patched by Sugawara)
1306 ;; Revision 1.11 2008/08/02 10:20:36 rubikitch
1307 ;; `anything-resume' is usable with other (let-binded) `anything-sources'.
1309 ;; Revision 1.10 2008/08/01 19:44:01 rubikitch
1310 ;; `anything-resume': resurrect previously invoked `anything'.
1312 ;; Revision 1.9 2008/07/30 15:44:49 rubikitch
1313 ;; *** empty log message ***
1315 ;; Revision 1.8 2008/07/30 15:38:51 rubikitch
1316 ;; *** empty log message ***
1318 ;; Revision 1.7 2008/07/30 15:21:48 rubikitch
1319 ;; `anything-scroll-other-window', `anything-scroll-other-window-down':
1320 ;; Scroll other window (for persistent action).
1322 ;; Revision 1.6 2008/07/30 15:12:36 rubikitch
1323 ;; *** empty log message ***
1325 ;; Revision 1.5 2008/07/30 15:06:32 rubikitch
1326 ;; `anything-select-2nd-action', `anything-select-3rd-action', `anything-select-4th-action':
1327 ;; Select other than default action without pressing Tab.
1329 ;; Revision 1.4 2008/07/30 14:58:27 rubikitch
1330 ;; `anything-current-buffer': Store current buffer when `anything' is invoked.
1331 ;; `anything-current-position': Restore position when keyboard-quitted.
1333 ;; Revision 1.3 2008/07/30 14:38:04 rubikitch
1334 ;; Implemented persistent action.
1336 ;; Revision 1.2 2008/07/30 13:37:16 rubikitch
1337 ;; Update doc.
1339 ;; Revision 1.1 2008/07/30 13:22:06 rubikitch
1340 ;; New maintainer.
1343 ;; ugly hack to auto-update version
1344 (defvar anything-version nil)
1345 (setq anything-version "$Id: anything.el,v 1.280 2010-04-01 02:22:22 rubikitch Exp $")
1346 (require 'cl)
1347 ;; (require 'anything-match-plugin nil t)
1349 ;; (@* "User Configuration")
1351 ;; This is only an example. Customize it to your own taste!
1352 (defvar anything-sources `(((name . "Buffers")
1353 (candidates
1354 . (lambda ()
1355 (remove-if (lambda (name)
1356 (or (equal name anything-buffer)
1357 (eq ?\ (aref name 0))))
1358 (mapcar 'buffer-name (buffer-list)))))
1359 (type . buffer))
1361 ((name . "File Name History")
1362 (candidates . file-name-history)
1363 (match (lambda (candidate)
1364 ;; list basename matches first
1365 (string-match
1366 anything-pattern
1367 (file-name-nondirectory candidate)))
1369 (lambda (candidate)
1370 ;; and then directory part matches
1371 (let ((dir (file-name-directory candidate)))
1372 (if dir
1373 (string-match anything-pattern dir)))))
1374 (type . file))
1376 ((name . "Files from Current Directory")
1377 (init . (lambda ()
1378 (setq anything-default-directory
1379 default-directory)))
1380 (candidates . (lambda ()
1381 (directory-files
1382 anything-default-directory)))
1383 (type . file))
1385 ((name . "Complex Command History")
1386 (candidates . (lambda ()
1387 (mapcar 'prin1-to-string
1388 command-history)))
1389 (action . (("Repeat Complex Command" .
1390 (lambda (c)
1391 (eval (read c))))))
1392 (delayed)))
1393 "The source of candidates for anything.
1394 It accepts symbols:
1395 (setq anything-sources (list anything-c-foo anything-c-bar))
1396 can be written as
1397 (setq anything-sources '(anything-c-foo anything-c-bar))
1398 The latter is recommended because if you change anything-c-* variable,
1399 you do not have to update `anything-sources'.
1401 You are STRONGLY recommended to define a command which calls
1402 `anything' or `anything-other-buffer' with argument rather than
1403 to set `anything-sources' externally.
1405 If you want to change `anything-sources' during `anything' invocation,
1406 use `anything-set-sources', never use `setq'.
1408 Attributes:
1413 ;; This value is only provided as an example. Customize it to your own
1414 ;; taste!
1415 (defvar anything-type-attributes
1416 '((file (action . (("Find File" . find-file)
1417 ("Delete File" . (lambda (file)
1418 (if (y-or-n-p (format "Really delete file %s? "
1419 file))
1420 (delete-file file)))))))
1421 (buffer (action . (("Switch to Buffer" . switch-to-buffer)
1422 ("Pop to Buffer" . pop-to-buffer)
1423 ("Display Buffer" . display-buffer)
1424 ("Kill Buffer" . kill-buffer)))))
1425 "It's a list of (TYPE ATTRIBUTES ...). ATTRIBUTES are the same
1426 as attributes for `anything-sources'. TYPE connects the value
1427 to the appropriate sources in `anything-sources'.
1429 This allows specifying common attributes for several
1430 sources. For example, sources which provide files can specify
1431 common attributes with a `file' type.")
1434 (defvar anything-enable-shortcuts nil
1435 "*Whether to use digit/alphabet shortcut to select the first nine matches.
1436 If t then they can be selected using Ctrl+<number>.
1438 If 'prefix then they can be selected using <prefix-key> <alnum>.
1439 The prefix key is `anything-select-with-prefix-shortcut'.
1440 If the <prefix-key> is a letter, pressing twice inputs the letter itself.
1441 e.g.
1442 (setq anything-enable-shortcuts 'prefix)
1443 (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
1445 If 'alphabet then they can be selected using Shift+<alphabet> (deprecated).
1446 It is not recommended because you cannot input capital letters in pattern.
1448 Keys (digit/alphabet) are listed in `anything-shortcut-keys-alist'.")
1450 (defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
1451 "Alphabet shortcuts are usable now. Then `anything-enable-digit-shortcuts' should be renamed.
1452 `anything-enable-digit-shortcuts' is retained for compatibility.")
1454 (defvar anything-shortcut-keys-alist
1455 '((alphabet . "asdfghjklzxcvbnmqwertyuiop")
1456 (prefix . "asdfghjklzxcvbnmqwertyuiop1234567890")
1457 (t . "123456789")))
1459 (defvar anything-display-source-at-screen-top t
1460 "*If t, `anything-next-source' and `anything-previous-source'
1461 display candidates at the top of screen.")
1463 (defvar anything-candidate-number-limit 50
1464 "*Do not show more candidates than this limit from individual
1465 sources. It is usually pointless to show hundreds of matches
1466 when the pattern is empty, because it is much simpler to type a
1467 few characters to narrow down the list of potential candidates.
1469 Set it to nil if you don't want this limit.")
1472 (defvar anything-idle-delay 0.5
1473 "*The user has to be idle for this many seconds, before
1474 candidates from delayed sources are collected. This is useful
1475 for sources involving heavy operations (like launching external
1476 programs), so that candidates from the source are not retrieved
1477 unnecessarily if the user keeps typing.
1479 It also can be used to declutter the results anything displays,
1480 so that results from certain sources are not shown with every
1481 character typed, only if the user hesitates a bit.")
1484 (defvar anything-input-idle-delay 0.1
1485 "The user has to be idle for this many seconds, before ALL candidates are collected.
1486 Unlink `anything-input-idle', it is also effective for non-delayed sources.
1487 If nil, candidates are collected immediately. ")
1490 (defvar anything-samewindow nil
1491 "If t then Anything doesn't pop up a new window, it uses the
1492 current window to show the candidates.")
1495 (defvar anything-source-filter nil
1496 "A list of source names to be displayed. Other sources won't
1497 appear in the search results. If nil then there is no filtering.
1498 See also `anything-set-source-filter'.")
1501 (defvar anything-map
1502 (let ((map (copy-keymap minibuffer-local-map)))
1503 (define-key map (kbd "<down>") 'anything-next-line)
1504 (define-key map (kbd "<up>") 'anything-previous-line)
1505 (define-key map (kbd "C-n") 'anything-next-line)
1506 (define-key map (kbd "C-p") 'anything-previous-line)
1507 (define-key map (kbd "<prior>") 'anything-previous-page)
1508 (define-key map (kbd "<next>") 'anything-next-page)
1509 (define-key map (kbd "M-v") 'anything-previous-page)
1510 (define-key map (kbd "C-v") 'anything-next-page)
1511 (define-key map (kbd "M-<") 'anything-beginning-of-buffer)
1512 (define-key map (kbd "M->") 'anything-end-of-buffer)
1513 (define-key map (kbd "<right>") 'anything-next-source)
1514 (define-key map (kbd "<left>") 'anything-previous-source)
1515 (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
1516 (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
1517 (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
1518 (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
1519 (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
1520 (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
1521 (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
1522 (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
1523 (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
1524 (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
1525 (loop for c from ?A to ?Z do
1526 (define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
1527 (define-key map (kbd "C-i") 'anything-select-action)
1528 (define-key map (kbd "C-z") 'anything-execute-persistent-action)
1529 (define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
1530 (define-key map (kbd "C-j") 'anything-select-3rd-action)
1531 (define-key map (kbd "C-o") 'anything-next-source)
1532 (define-key map (kbd "C-M-v") 'anything-scroll-other-window)
1533 (define-key map (kbd "M-<next>") 'anything-scroll-other-window)
1534 (define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
1535 (define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
1536 (define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
1537 (define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
1538 (define-key map (kbd "M-[") 'anything-prev-visible-mark)
1539 (define-key map (kbd "M-]") 'anything-next-visible-mark)
1540 (define-key map (kbd "C-k") 'anything-delete-minibuffer-content)
1542 (define-key map (kbd "C-s") 'anything-isearch)
1543 (define-key map (kbd "C-r") 'undefined)
1544 (define-key map (kbd "C-t") 'anything-toggle-resplit-window)
1545 (define-key map (kbd "C-x C-f") 'anything-quit-and-find-file)
1547 (define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
1548 (define-key map (kbd "C-c C-y") 'anything-yank-selection)
1549 (define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
1550 (define-key map (kbd "C-c C-f") 'anything-follow-mode)
1551 (define-key map (kbd "C-c C-u") 'anything-force-update)
1553 ;; Debugging command
1554 (define-key map "\C-c\C-x\C-d" 'anything-debug-output)
1555 (define-key map "\C-c\C-x\C-m" 'anything-display-all-visible-marks)
1556 (define-key map "\C-c\C-x\C-b" 'anything-send-bug-report-from-anything)
1557 ;; Use `describe-mode' key in `global-map'
1558 (dolist (k (where-is-internal 'describe-mode global-map))
1559 (define-key map k 'anything-help))
1560 ;; the defalias is needed because commands are bound by name when
1561 ;; using iswitchb, so only commands having the prefix anything-
1562 ;; get rebound
1563 (defalias 'anything-previous-history-element 'previous-history-element)
1564 (defalias 'anything-next-history-element 'next-history-element)
1565 (define-key map (kbd "M-p") 'anything-previous-history-element)
1566 (define-key map (kbd "M-n") 'anything-next-history-element)
1567 map)
1568 "Keymap for anything.
1570 If you execute `anything-iswitchb-setup', some keys are modified.
1571 See `anything-iswitchb-setup-keys'.")
1573 (defvar anything-isearch-map
1574 (let ((map (make-sparse-keymap)))
1575 (set-keymap-parent map (current-global-map))
1576 (define-key map (kbd "<return>") 'anything-isearch-default-action)
1577 (define-key map (kbd "<RET>") 'anything-isearch-default-action)
1578 (define-key map (kbd "C-i") 'anything-isearch-select-action)
1579 (define-key map (kbd "C-g") 'anything-isearch-cancel)
1580 (define-key map (kbd "M-s") 'anything-isearch-again)
1581 (define-key map (kbd "<backspace>") 'anything-isearch-delete)
1582 ;; add printing chars
1583 (loop for i from 32 below 256 do
1584 (define-key map (vector i) 'anything-isearch-printing-char))
1585 map)
1586 "Keymap for anything incremental search.")
1589 (defgroup anything nil
1590 "Open anything." :prefix "anything-" :group 'convenience)
1592 (defface anything-header
1593 '((t (:inherit header-line)))
1594 "Face for header lines in the anything buffer." :group 'anything)
1596 (defvar anything-header-face 'anything-header
1597 "Face for header lines in the anything buffer.")
1599 (defface anything-isearch-match '((t (:background "Yellow")))
1600 "Face for isearch in the anything buffer." :group 'anything)
1602 (defvar anything-isearch-match-face 'anything-isearch-match
1603 "Face for matches during incremental search.")
1605 (defvar anything-selection-face 'highlight
1606 "Face for currently selected item.")
1608 (defvar anything-iswitchb-idle-delay 1
1609 "Show anything completions if the user is idle that many
1610 seconds after typing.")
1612 (defvar anything-iswitchb-dont-touch-iswithcb-keys nil
1613 "If t then those commands are not bound from `anything-map'
1614 under iswitchb which would override standard iswithcb keys.
1616 This allows an even more seamless integration with iswitchb for
1617 those who prefer using iswitchb bindings even if the anything
1618 completions buffer is popped up.
1620 Note that you can bind alternative keys for the same command in
1621 `anything-map', so that you can use different keys for anything
1622 under iswitchb. For example, I bind the character \ to
1623 `anything-exit-minibuffer' which key is just above Enter on my
1624 keyboard. This way I can switch buffers with Enter and choose
1625 anything completions with \.")
1627 ;;----------------------------------------------------------------------
1629 (defvar anything-buffer "*anything*"
1630 "Buffer showing completions.")
1632 (defvar anything-action-buffer "*anything action*"
1633 "Buffer showing actions.")
1635 (defvar anything-selection-overlay nil
1636 "Overlay used to highlight the currently selected item.")
1638 (defvar anything-isearch-overlay nil
1639 "Overlay used to highlight the current match during isearch.")
1641 (defvar anything-digit-overlays nil
1642 "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
1644 (defvar anything-candidate-cache nil
1645 "Holds the available candidate withing a single anything invocation.")
1647 (defvar anything-pattern
1648 "The input pattern used to update the anything buffer.")
1650 (defvar anything-input
1651 "The input typed in the candidates panel.")
1653 (defvar anything-async-processes nil
1654 "List of information about asynchronous processes managed by anything.")
1656 (defvar anything-digit-shortcut-count 0
1657 "Number of digit shortcuts shown in the anything buffer.")
1659 (defvar anything-before-initialize-hook nil
1660 "Run before anything initialization.
1661 This hook is run before init functions in `anything-sources'.")
1663 (defvar anything-after-initialize-hook nil
1664 "Run after anything initialization.
1665 Global variables are initialized and the anything buffer is created.
1666 But the anything buffer has no contents. ")
1668 (defvar anything-update-hook nil
1669 "Run after the anything buffer was updated according the new input pattern.
1670 This hook is run at the beginning of buffer.
1671 The first candidate is selected after running this hook.
1672 See also `anything-after-update-hook'.")
1674 (defvar anything-after-update-hook nil
1675 "Run after the anything buffer was updated according the new input pattern.
1676 This is very similar to `anything-update-hook' but selection is not moved.
1677 It is useful to select a particular object instead of the first one. ")
1679 (defvar anything-cleanup-hook nil
1680 "Run after anything minibuffer is closed, IOW this hook is executed BEFORE performing action. ")
1682 (defvar anything-after-action-hook nil
1683 "Run after executing action.")
1685 (defvar anything-after-persistent-action-hook nil
1686 "Run after executing persistent action.")
1688 (defvar anything-restored-variables
1689 '( anything-candidate-number-limit
1690 anything-source-filter
1691 anything-source-in-each-line-flag
1692 anything-sources)
1693 "Variables which are restored after `anything' invocation.")
1694 ;; `anything-saved-sources' is removed
1696 (defvar anything-saved-selection nil
1697 "Saved value of the currently selected object when the action
1698 list is shown.")
1700 ;; `anything-original-source-filter' is removed
1702 (defvar anything-candidate-separator
1703 "--------------------"
1704 "Candidates separator of `multiline' source.")
1706 (defvar anything-current-buffer nil
1707 "Current buffer when `anything' is invoked.")
1709 (defvar anything-buffer-file-name nil
1710 "`buffer-file-name' when `anything' is invoked.")
1712 (defvar anything-saved-action nil
1713 "Saved value of the currently selected action by key.")
1715 (defvar anything-last-sources nil
1716 "OBSOLETE!! Sources of previously invoked `anything'.")
1718 (defvar anything-saved-current-source nil
1719 "Saved value of the original (anything-get-current-source) when the action
1720 list is shown.")
1722 (defvar anything-compiled-sources nil
1723 "Compiled version of `anything-sources'. ")
1725 (defvar anything-in-persistent-action nil
1726 "Flag whether in persistent-action or not.")
1728 (defvar anything-quick-update nil
1729 "If non-nil, suppress displaying sources which are out of screen at first.
1730 They are treated as delayed sources at this input.
1731 This flag makes `anything' a bit faster with many sources.")
1733 (defvar anything-last-sources-local nil
1734 "Buffer local value of `anything-sources'.")
1735 (defvar anything-last-buffer nil
1736 "`anything-buffer' of previously `anything' session.")
1738 (defvar anything-save-configuration-functions
1739 '(set-window-configuration . current-window-configuration)
1740 "If you want to save and restore frame configuration, set this variable to
1741 '(set-frame-configuration . current-frame-configuration)
1743 Older version saves/restores frame configuration, but the default is changed now,
1744 because flickering is occurred in some environment.
1747 (defvar anything-persistent-action-use-special-display nil
1748 "If non-nil, use `special-display-function' in persistent action.")
1750 (defvar anything-execute-action-at-once-if-one nil
1751 "If non-nil and there is one candidate, execute the first action without selection.
1752 It is useful for `anything' applications.")
1754 (defvar anything-quit-if-no-candidate nil
1755 "if non-nil and there is no candidate, do not display *anything* buffer and quit.
1756 This variable accepts a function, which is executed if no candidate.
1758 It is useful for `anything' applications.")
1760 (defvar anything-scroll-amount nil
1761 "Scroll amount used by `anything-scroll-other-window' and `anything-scroll-other-window-down'.
1762 If you prefer scrolling line by line, set this value to 1.")
1764 (defvar anything-display-function 'anything-default-display-buffer
1765 "Function to display *anything* buffer.
1766 It is `anything-default-display-buffer' by default, which affects `anything-samewindow'.")
1768 (defvar anything-delayed-init-executed nil)
1770 (defvar anything-mode-line-string "\\<anything-map>\\[anything-help]:help \\[anything-select-action]:ActionList \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\\[anything-select-3rd-action]:NthAction"
1771 "Help string displayed in mode-line in `anything'.
1772 If nil, use default `mode-line-format'.")
1774 (defvar anything-help-message
1775 "\\<anything-map>The keys that are defined for `anything' are:
1776 \\{anything-map}"
1777 "Detailed help message string for `anything'.
1778 It also accepts function or variable symbol.")
1780 (put 'anything 'timid-completion 'disabled)
1782 (defvar anything-inhibit-fit-frame-flag t
1783 "If non-nil, inhibit fitting anything frame to its buffer.
1784 It is nil by default because some flickering occurred in some environment.
1786 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
1787 `fit-frame-inhibit-fitting' to nil.")
1789 (defvar anything-source-in-each-line-flag nil
1790 "If non-nil, add anything-source text-property in each candidate.
1791 experimental feature.")
1793 (defvar anything-debug-forms nil
1794 "Forms to show in `anything-debug-output'.
1795 Otherwise all variables started with `anything-' are shown.
1796 It is useful for debug.")
1797 (defvaralias 'anything-debug-variables 'anything-debug-forms)
1799 ;; (@* "Internal Variables")
1800 (defvar anything-test-candidate-list nil)
1801 (defvar anything-test-mode nil)
1802 (defvar anything-source-name nil)
1803 (defvar anything-candidate-buffer-alist nil)
1804 (defvar anything-check-minibuffer-input-timer nil)
1805 (defvar anything-match-hash (make-hash-table :test 'equal))
1806 (defvar anything-cib-hash (make-hash-table :test 'equal))
1807 (defvar anything-tick-hash (make-hash-table :test 'equal))
1808 (defvar anything-issued-errors nil)
1809 (defvar anything-shortcut-keys nil)
1810 (defvar anything-once-called-functions nil)
1811 (defvar anything-follow-mode nil)
1813 ;; (@* "Programming Tools")
1814 (defmacro anything-aif (test-form then-form &rest else-forms)
1815 "Anaphoric if. Temporary variable `it' is the result of test-form."
1816 `(let ((it ,test-form))
1817 (if it ,then-form ,@else-forms)))
1818 (put 'anything-aif 'lisp-indent-function 2)
1820 (defun anything-mklist (obj)
1821 "If OBJ is a list (but not lambda), return itself, otherwise make a list with one element."
1822 (if (and (listp obj) (not (functionp obj)))
1824 (list obj)))
1826 ;; (@* "Anything API")
1827 (defun anything-buffer-get ()
1828 "If *anything action* buffer is shown, return `anything-action-buffer', otherwise `anything-buffer'."
1829 (if (anything-action-window)
1830 anything-action-buffer
1831 anything-buffer))
1833 (defun anything-window ()
1834 "Window of `anything-buffer'."
1835 (get-buffer-window (anything-buffer-get) 'visible))
1837 (defun anything-action-window ()
1838 "Window of `anything-action-buffer'."
1839 (get-buffer-window anything-action-buffer 'visible))
1841 (defmacro with-anything-window (&rest body)
1842 `(let ((--tmpfunc-- (lambda () ,@body)))
1843 (if anything-test-mode
1844 (with-current-buffer (anything-buffer-get)
1845 (funcall --tmpfunc--))
1846 (with-selected-window (anything-window)
1847 (funcall --tmpfunc--)))))
1848 (put 'with-anything-window 'lisp-indent-function 0)
1850 (defmacro with-anything-restore-variables(&rest body)
1851 "Restore variables specified by `anything-restored-variables' after executing BODY .
1852 `post-command-hook' is handled specially."
1853 `(let ((--orig-vars (mapcar (lambda (v) (cons v (symbol-value v))) anything-restored-variables))
1854 (--post-command-hook-pair (cons post-command-hook
1855 (default-value 'post-command-hook))))
1856 (setq post-command-hook '(t))
1857 (setq-default post-command-hook nil)
1858 (unwind-protect (progn ,@body)
1859 (loop for (var . value) in --orig-vars
1860 do (set var value))
1861 (setq post-command-hook (car --post-command-hook-pair))
1862 (setq-default post-command-hook (cdr --post-command-hook-pair)))))
1863 (put 'with-anything-restore-variables 'lisp-indent-function 0)
1865 (defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
1866 "Get the value of ATTRIBUTE-NAME of SRC (source).
1867 if SRC is omitted, use current source.
1868 It is useful to write your sources."
1869 (anything-aif (assq attribute-name src)
1870 (cdr it)))
1872 (defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
1873 "Return non-nil if ATTRIBUTE-NAME of SRC (source) is defined.
1874 if SRC is omitted, use current source.
1875 It is useful to write your sources."
1876 (and (assq attribute-name src) t))
1878 (defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
1879 "Set the value of ATTRIBUTE-NAME of SRC (source) to VALUE.
1880 if SRC is omitted, use current source.
1881 It is useful to write your sources."
1882 (anything-aif (assq attribute-name src)
1883 (setcdr it value)
1884 (setcdr src (cons (cons attribute-name value) (cdr src))))
1885 value)
1887 ;; anything-set-source-filter
1889 ;; This function sets a filter for anything sources and it may be
1890 ;; called while anything is running. It can be used to toggle
1891 ;; displaying of sources dinamically. For example, additional keys
1892 ;; can be bound into `anything-map' to display only the file-related
1893 ;; results if there are too many matches from other sources and
1894 ;; you're after files only:
1896 ;; Shift+F shows only file results from some sources:
1898 ;; (define-key anything-map "F" 'anything-my-show-files-only)
1900 ;; (defun anything-my-show-files-only ()
1901 ;; (interactive)
1902 ;; (anything-set-source-filter '("File Name History"
1903 ;; "Files from Current Directory")))
1905 ;; Shift+A shows all results:
1907 ;; (define-key anything-map "A" 'anything-my-show-all)
1909 ;; (defun anything-my-show-all ()
1910 ;; (interactive)
1911 ;; (anything-set-source-filter nil))
1914 ;; Note that you have to prefix the functions with anything- prefix,
1915 ;; otherwise they won't be bound when Anything is used under
1916 ;; Iswitchb. The -my- part is added to avoid collisions with
1917 ;; existing Anything function names.
1919 (defun anything-set-source-filter (sources)
1920 "Sets the value of `anything-source-filter' and updates the list of results."
1921 (unless (and (listp sources)
1922 (loop for name in sources always (stringp name)))
1923 (error "invalid data in `anything-set-source-filter': %S" sources))
1924 (setq anything-source-filter sources)
1925 (anything-update))
1927 (defun anything-set-sources (sources &optional no-init no-update)
1928 "Set `anything-sources' during `anything' invocation.
1929 If NO-INIT is non-nil, skip executing init functions of SOURCES.
1930 If NO-UPDATE is non-nil, skip executing `anything-update'."
1931 (setq anything-compiled-sources nil
1932 anything-sources sources)
1933 (unless no-init (anything-funcall-foreach 'init))
1934 (unless no-update (anything-update)))
1936 (defvar anything-compile-source-functions
1937 '(anything-compile-source--type
1938 anything-compile-source--dummy
1939 anything-compile-source--disable-shortcuts
1940 anything-compile-source--candidates-in-buffer)
1941 "Functions to compile elements of `anything-sources' (plug-in).")
1943 (defun anything-get-sources ()
1944 "Return compiled `anything-sources', which is memoized.
1946 Attributes:
1948 - type
1949 `anything-type-attributes' are merged in.
1950 - candidates-buffer
1951 candidates, volatile and match attrubute are created.
1953 (cond
1954 ;; action
1955 ((anything-action-window)
1956 anything-sources)
1957 ;; memoized
1958 (anything-compiled-sources)
1959 ;; first time
1961 (setq anything-compiled-sources
1962 (anything-compile-sources anything-sources anything-compile-source-functions)))))
1964 (defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
1965 "Return the currently selected item or nil.
1966 if BUFFER is nil or unspecified, use anything-buffer as default value.
1967 If FORCE-DISPLAY-PART is non-nil, return the display string."
1968 (setq buffer (if (and buffer buffer-s) buffer anything-buffer))
1969 (unless (zerop (buffer-size (get-buffer buffer)))
1970 (with-current-buffer buffer
1971 (let ((selection
1972 (or (and (not force-display-part)
1973 (get-text-property (overlay-start
1974 anything-selection-overlay)
1975 'anything-realvalue))
1976 (let ((disp (buffer-substring-no-properties
1977 (overlay-start anything-selection-overlay)
1978 (1- (overlay-end anything-selection-overlay))))
1979 (source (anything-get-current-source)))
1980 (anything-aif (and (not force-display-part)
1981 (assoc-default 'display-to-real source))
1982 (anything-funcall-with-source source it disp)
1983 disp)))))
1984 (unless (equal selection "")
1985 selection)))))
1987 (defun anything-get-action ()
1988 "Return the associated action for the selected candidate."
1989 (unless (zerop (buffer-size (get-buffer (anything-buffer-get))))
1990 (let* ((source (anything-get-current-source))
1991 (actions (assoc-default 'action source)))
1993 (anything-aif (assoc-default 'action-transformer source)
1994 ;; (funcall it actions (anything-get-selection))
1995 (anything-composed-funcall-with-source source it actions (anything-get-selection))
1996 actions))))
1998 (defun anything-get-current-source ()
1999 "Return the source for the current selection / in init/candidates/action/candidate-transformer/filtered-candidate-transformer function."
2000 (declare (special source))
2001 ;; The name `anything-get-current-source' should be used in init function etc.
2002 (if (and (boundp 'anything-source-name) (stringp anything-source-name))
2003 source
2004 (or
2005 (with-current-buffer (anything-buffer-get)
2006 (get-text-property (point) 'anything-source))
2007 (block exit
2008 (with-current-buffer (anything-buffer-get)
2009 ;; This goto-char shouldn't be necessary, but point is moved to
2010 ;; point-min somewhere else which shouldn't happen.
2011 (goto-char (overlay-start anything-selection-overlay))
2012 (let* ((header-pos (or (anything-get-previous-header-pos)
2013 (anything-get-next-header-pos)))
2014 (source-name
2015 (save-excursion
2016 (unless header-pos
2017 (message "No candidates")
2018 (return-from exit nil))
2019 (goto-char header-pos)
2020 (buffer-substring-no-properties
2021 (line-beginning-position) (line-end-position)))))
2022 (some (lambda (source)
2023 (if (equal (assoc-default 'name source)
2024 source-name)
2025 source))
2026 (anything-get-sources))))))))
2028 (defun anything-buffer-is-modified (buffer)
2029 "Return non-nil when BUFFER is modified since `anything' was invoked."
2030 (let* ((b (get-buffer buffer))
2031 (key (concat (buffer-name b)
2033 (anything-attr 'name)))
2034 (source-tick (or (gethash key anything-tick-hash) 0))
2035 (buffer-tick (buffer-chars-modified-tick b)))
2036 (prog1 (/= source-tick buffer-tick)
2037 (puthash key buffer-tick anything-tick-hash))))
2038 (defun anything-current-buffer-is-modified ()
2039 "Return non-nil when `anything-current-buffer' is modified since `anything' was invoked."
2040 (anything-buffer-is-modified anything-current-buffer))
2042 (defvar anything-quit nil)
2043 (defun anything-run-after-quit (function &rest args)
2044 "Perform an action after quitting `anything'.
2045 The action is to call FUNCTION with arguments ARGS."
2046 (setq anything-quit t)
2047 (apply 'run-with-idle-timer 0 nil function args)
2048 (anything-exit-minibuffer))
2050 (defun define-anything-type-attribute (type definition &optional doc)
2051 "Register type attribute of TYPE as DEFINITION with DOC.
2052 DOC is displayed in `anything-type-attributes' docstring.
2054 Use this function is better than setting `anything-type-attributes' directly."
2055 (anything-add-type-attribute type definition)
2056 (and doc (anything-document-type-attribute type doc))
2057 nil)
2059 (defvar anything-additional-attributes nil
2060 "List of all `anything' attributes.")
2061 (defvaralias 'anything-attributes 'anything-additional-attributes)
2062 (defun anything-document-attribute (attribute short-doc &optional long-doc)
2063 "Register ATTRIBUTE documentation introduced by plug-in.
2064 SHORT-DOC is displayed beside attribute name.
2065 LONG-DOC is displayed below attribute name and short documentation."
2066 (if long-doc
2067 (setq short-doc (concat "(" short-doc ")"))
2068 (setq long-doc short-doc
2069 short-doc ""))
2070 (add-to-list 'anything-additional-attributes attribute t)
2071 (put attribute 'anything-attrdoc
2072 (concat "- " (symbol-name attribute) " " short-doc "\n\n" long-doc "\n")))
2073 (put 'anything-document-attribute 'lisp-indent-function 2)
2075 (defun anything-require-at-least-version (version)
2076 "Output error message unless anything.el is older than VERSION.
2077 This is suitable for anything applications."
2078 (when (and (string= "1." (substring version 0 2))
2079 (string-match "1\.\\([0-9]+\\)" anything-version)
2080 (< (string-to-number (match-string 1 anything-version))
2081 (string-to-number (substring version 2))))
2082 (error "Please update anything.el!!
2084 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
2086 or M-x install-elisp-from-emacswiki anything.el")))
2088 (defun anything-interpret-value (value &optional source)
2089 "interpret VALUE as variable, function or literal.
2090 If VALUE is a function, call it with no arguments and return the value.
2091 If SOURCE is `anything' source, `anything-source-name' is source name.
2093 If VALUE is a variable, return the value.
2095 If VALUE is a symbol, but it is not a function or a variable, cause an error.
2097 Otherwise, return VALUE itself."
2098 (cond ((and source (functionp value))
2099 (anything-funcall-with-source source value))
2100 ((functionp value)
2101 (funcall value))
2102 ((and (symbolp value) (boundp value))
2103 (symbol-value value))
2104 ((symbolp value)
2105 (error "anything-interpret-value: Symbol must be a function or a variable"))
2107 value)))
2109 (defun anything-once (function &rest args)
2110 "Ensure FUNCTION with ARGS to be called once in `anything' session."
2111 (let ((spec (cons function args)))
2112 (unless (member spec anything-once-called-functions)
2113 (apply function args)
2114 (push spec anything-once-called-functions))))
2116 ;; (@* "Core: tools")
2117 (defun anything-funcall-with-source (source func &rest args)
2118 "Call FUNC with ARGS with variable `anything-source-name' and `source' is bound.
2119 FUNC can be function list. Return the result of last function call."
2120 (let ((anything-source-name (assoc-default 'name source))
2121 result)
2122 (dolist (func (if (functionp func) (list func) func) result)
2123 (setq result (apply func args)))))
2125 (defun anything-funcall-foreach (sym)
2126 "Call the sym function(s) for each source if any."
2127 (dolist (source (anything-get-sources))
2128 (when (symbolp source)
2129 (setq source (symbol-value source)))
2130 (anything-aif (assoc-default sym source)
2131 (anything-funcall-with-source source it))))
2133 (defun anything-normalize-sources (sources)
2134 "If SOURCES is only one source, make a list."
2135 (cond ((or (and sources ; avoid nil
2136 (symbolp sources))
2137 (and (listp sources) (assq 'name sources)))
2138 (list sources))
2139 (sources)
2140 (t anything-sources)))
2142 (defun anything-approximate-candidate-number ()
2143 "Approximate Number of candidates.
2144 It is used to check if candidate number is 0, 1, or 2+."
2145 (with-current-buffer anything-buffer
2146 (let ((lines (1- (line-number-at-pos (1- (point-max))))))
2147 (if (zerop lines)
2149 (save-excursion
2150 (goto-char (point-min))
2151 (forward-line 1)
2152 (if (anything-pos-multiline-p)
2153 (if (search-forward anything-candidate-separator nil t) 2 1)
2154 lines))))))
2156 (defmacro with-anything-quittable (&rest body)
2157 `(let (inhibit-quit)
2158 (condition-case v
2159 (progn ,@body)
2160 (quit (setq anything-quit t)
2161 (exit-minibuffer)
2162 (keyboard-quit)))))
2163 (put 'with-anything-quittable 'lisp-indent-function 0)
2165 (defun anything-compose (arg-lst func-lst)
2166 "Call each function in FUNC-LST with the arguments specified in ARG-LST.
2167 The result of each function will be the new `car' of ARG-LST.
2169 This function allows easy sequencing of transformer functions."
2170 (dolist (func func-lst)
2171 (setcar arg-lst (apply func arg-lst)))
2172 (car arg-lst))
2174 (defun anything-composed-funcall-with-source (source funcs &rest args)
2175 (if (functionp funcs)
2176 (apply 'anything-funcall-with-source source funcs args)
2177 (apply 'anything-funcall-with-source
2178 source (lambda (&rest args) (anything-compose args funcs)) args)))
2180 ;; (@* "Core: entry point")
2181 (defvar anything-buffers nil
2182 "All of `anything-buffer' in most recently used order.")
2184 ;;;###autoload
2185 (defun anything (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap)
2186 "Select anything. In Lisp program, some optional arguments can be used.
2188 Note that all the optional arguments are prefixed because of
2189 dynamic scope problem, IOW argument variables may eat
2190 already-bound variables. Yuck!
2192 - ANY-SOURCES
2194 Temporary value of `anything-sources'. It also accepts a
2195 symbol, interpreted as a variable of an anything source. It
2196 also accepts an alist representing an anything source, which is
2197 detected by (assq 'name ANY-SOURCES)
2200 - ANY-INPUT
2202 Temporary value of `anything-pattern', ie. initial input of minibuffer.
2204 - ANY-PROMPT
2206 Prompt other than \"pattern: \".
2208 - ANY-RESUME
2210 If t, Resurrect previously instance of `anything'. Skip the initialization.
2211 If 'noresume, this instance of `anything' cannot be resumed.
2213 - ANY-PRESELECT
2215 Initially selected candidate. Specified by exact candidate or a regexp.
2216 Note that it is not working with delayed sources.
2218 - ANY-BUFFER
2220 `anything-buffer' instead of *anything*.
2222 - ANY-KEYMAP
2224 `anything-map' for current `anything' session.
2226 ;; TODO more document
2227 (interactive)
2228 (condition-case v
2229 (with-anything-restore-variables
2230 (let (;; It is needed because `anything-source-name' is non-nil
2231 ;; when `anything' is invoked by action. Awful global scope.
2232 anything-source-name anything-in-persistent-action
2233 anything-quit
2234 (case-fold-search t)
2235 (anything-buffer (or any-buffer anything-buffer))
2236 (anything-map (or any-keymap anything-map)))
2237 (anything-frame/window-configuration 'save)
2238 (setq anything-sources (anything-normalize-sources any-sources))
2239 (anything-initialize-1 any-resume any-input)
2240 (anything-hooks 'setup)
2241 (if (eq any-resume t)
2242 (condition-case x
2243 (anything-window-configuration 'restore)
2244 (error (anything-display-buffer anything-buffer)))
2245 (anything-display-buffer anything-buffer))
2246 (unwind-protect
2247 (anything-read-pattern-maybe any-prompt any-input any-preselect any-resume)
2248 (anything-cleanup)
2249 (anything-hooks 'cleanup)
2250 (anything-frame/window-configuration 'restore))
2251 (unless anything-quit
2252 (anything-execute-selection-action-1))))
2253 (quit
2254 (anything-on-quit)
2255 nil)))
2257 (defun anything-resume-p (any-resume)
2258 "Whethre current anything session is resumed or not."
2259 (memq any-resume '(t window-only)))
2261 (defun anything-initialize-1 (any-resume any-input)
2262 (anything-current-position 'save)
2263 (if (anything-resume-p any-resume)
2264 (anything-initialize-overlays (anything-buffer-get))
2265 (anything-initialize))
2266 (unless (eq any-resume 'noresume)
2267 (anything-recent-push anything-buffer 'anything-buffers)
2268 (setq anything-last-buffer anything-buffer))
2269 (when any-input (setq anything-input any-input anything-pattern any-input))
2270 (and (anything-resume-p any-resume) (anything-funcall-foreach 'resume)))
2272 (defun anything-execute-selection-action-1 ()
2273 (unwind-protect
2274 (anything-execute-selection-action)
2275 (anything-aif (get-buffer anything-action-buffer)
2276 (kill-buffer it))
2277 (run-hooks 'anything-after-action-hook)))
2279 (defun anything-on-quit ()
2280 (setq minibuffer-history (cons anything-input minibuffer-history))
2281 (anything-current-position 'restore))
2283 (defun anything-resume-select-buffer (input)
2284 (anything '(((name . "Resume anything buffer")
2285 (candidates . anything-buffers)
2286 (action . identity)))
2287 input nil 'noresume nil "*anything resume*"))
2289 (defun* anything-resume (&optional (any-buffer anything-last-buffer) buffer-pattern (any-resume t))
2290 "Resurrect previously invoked `anything'."
2291 (interactive)
2292 (when (or current-prefix-arg buffer-pattern)
2293 (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
2294 (setq anything-compiled-sources nil)
2295 (anything
2296 (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
2297 anything-last-sources anything-sources)
2298 (buffer-local-value 'anything-input-local (get-buffer any-buffer)) nil any-resume nil any-buffer))
2300 ;;; rubikitch: experimental
2301 ;;; I use this and check it whether I am convenient.
2302 ;;; I may introduce an option to control the behavior.
2303 (defun* anything-resume-window-only (&optional (any-buffer anything-last-buffer) buffer-pattern)
2304 (interactive)
2305 (anything-resume any-buffer buffer-pattern 'window-only))
2307 (defun anything-recent-push (elt list-var)
2308 "Add ELT to the value of LIST-VAR as most recently used value."
2309 (let ((m (member elt (symbol-value list-var))))
2310 (and m (set list-var (delq (car m) (symbol-value list-var))))
2311 (push elt (symbol-value list-var))))
2313 ;;; (@* "Core: Accessors")
2314 (defvar anything-window-configuration nil)
2315 ;;; (set-window-configuration (buffer-local-value 'anything-window-configuration (get-buffer "*anything buffers*")))
2316 (defun anything-window-configuration (save-or-restore)
2317 (case save-or-restore
2318 ((save store)
2319 (with-current-buffer anything-buffer
2320 (set (make-local-variable 'anything-window-configuration)
2321 (current-window-configuration))))
2322 ((restore set)
2323 (with-current-buffer anything-buffer
2324 (set-window-configuration anything-window-configuration))
2325 (select-window (anything-window)))))
2327 (defvar anything-current-position nil
2328 "Cons of (point) and (window-start) when `anything' is invoked.
2329 It is needed because restoring position when `anything' is keyboard-quitted.")
2330 (defun anything-current-position (save-or-restore)
2331 (case save-or-restore
2332 (save
2333 (setq anything-current-position (cons (point) (window-start))))
2334 (restore
2335 (goto-char (car anything-current-position))
2336 (set-window-start (selected-window) (cdr anything-current-position)))))
2338 ;;; FIXME I want to remove them. But anything-iswitchb uses them.
2339 (defun anything-current-frame/window-configuration ()
2340 (funcall (cdr anything-save-configuration-functions)))
2341 (defun anything-set-frame/window-configuration (conf)
2342 (funcall (car anything-save-configuration-functions) conf))
2344 (declare-function 'anything-frame/window-configuration "anything")
2345 (lexical-let (conf)
2346 (defun anything-frame/window-configuration (save-or-restore)
2347 (case save-or-restore
2348 (save (setq conf (funcall (cdr anything-save-configuration-functions))))
2349 (restore (funcall (car anything-save-configuration-functions) conf)))))
2353 ;;;###autoload
2354 (defun anything-at-point (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
2355 "Same as `anything' except when C-u is pressed, the initial input is the symbol at point."
2356 (interactive)
2357 (anything any-sources
2358 (if current-prefix-arg
2359 (concat "\\b" (thing-at-point 'symbol) "\\b"
2360 (if (featurep 'anything-match-plugin) " " ""))
2361 any-input)
2362 any-prompt any-resume any-preselect any-buffer))
2364 (defun anything-other-buffer (any-sources any-buffer)
2365 "Simplified interface of `anything' with other `anything-buffer'"
2366 (anything any-sources nil nil nil nil any-buffer))
2368 ;; (@* "Core: Display *anything* buffer")
2369 (defun anything-display-buffer (buf)
2370 "Display *anything* buffer."
2371 (funcall anything-display-function buf))
2373 (defun anything-default-display-buffer (buf)
2374 (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
2376 ;; (@* "Core: initialize")
2377 (defun anything-initialize ()
2378 "Initialize anything settings and set up the anything buffer."
2379 (run-hooks 'anything-before-initialize-hook)
2380 (setq anything-once-called-functions nil)
2381 (setq anything-delayed-init-executed nil)
2382 (setq anything-current-buffer (current-buffer))
2383 (setq anything-buffer-file-name buffer-file-name)
2384 (setq anything-issued-errors nil)
2385 (setq anything-compiled-sources nil)
2386 (setq anything-saved-current-source nil)
2387 ;; Call the init function for sources where appropriate
2388 (anything-funcall-foreach 'init)
2390 (setq anything-pattern "")
2391 (setq anything-input "")
2392 (setq anything-candidate-cache nil)
2393 (setq anything-last-sources anything-sources)
2395 (anything-create-anything-buffer)
2396 (run-hooks 'anything-after-initialize-hook))
2398 (defun anything-read-pattern-maybe (any-prompt any-input any-preselect any-resume)
2399 (if (anything-resume-p any-resume) (anything-mark-current-line) (anything-update))
2400 (select-frame-set-input-focus (window-frame (minibuffer-window)))
2401 (anything-preselect any-preselect)
2402 (let ((ncandidate (anything-approximate-candidate-number))
2403 (minibuffer-local-map anything-map))
2404 (cond ((and anything-execute-action-at-once-if-one
2405 (= ncandidate 1))
2406 (ignore))
2407 ((and anything-quit-if-no-candidate (= ncandidate 0))
2408 (setq anything-quit t)
2409 (and (functionp anything-quit-if-no-candidate)
2410 (funcall anything-quit-if-no-candidate)))
2412 (read-string (or any-prompt "pattern: ") any-input)))))
2414 (defun anything-create-anything-buffer (&optional test-mode)
2415 "Create newly created `anything-buffer'.
2416 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
2417 (when test-mode
2418 (setq anything-candidate-cache nil))
2419 (with-current-buffer (get-buffer-create anything-buffer)
2420 (buffer-disable-undo)
2421 (erase-buffer)
2422 (set (make-local-variable 'inhibit-read-only) t)
2423 (set (make-local-variable 'anything-last-sources-local) anything-sources)
2424 (set (make-local-variable 'anything-follow-mode) nil)
2426 (setq cursor-type nil)
2427 (setq mode-name "Anything"))
2428 (anything-initialize-overlays anything-buffer)
2429 (get-buffer anything-buffer))
2431 (defun anything-initialize-overlays (buffer)
2432 (if anything-selection-overlay
2433 ;; make sure the overlay belongs to the anything buffer if
2434 ;; it's newly created
2435 (move-overlay anything-selection-overlay (point-min) (point-min)
2436 (get-buffer buffer))
2438 (setq anything-selection-overlay
2439 (make-overlay (point-min) (point-min) (get-buffer buffer)))
2440 (overlay-put anything-selection-overlay 'face anything-selection-face))
2442 (when anything-enable-shortcuts
2443 (setq anything-shortcut-keys (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist)))
2445 (if anything-enable-shortcuts
2446 (unless anything-digit-overlays
2447 (setq anything-digit-overlays
2448 (loop for key across anything-shortcut-keys
2449 for overlay = (make-overlay (point-min) (point-min) (get-buffer buffer))
2450 do (overlay-put overlay 'before-string
2451 (format "%s - " (upcase (make-string 1 key))))
2452 collect overlay)))
2454 (when anything-digit-overlays
2455 (dolist (overlay anything-digit-overlays)
2456 (delete-overlay overlay))
2457 (setq anything-digit-overlays nil))))
2459 (defun anything-hooks (setup-or-cleanup)
2460 (let ((hooks '((post-command-hook anything-check-minibuffer-input)
2461 (minibuffer-setup-hook anything-print-error-messages)
2462 (minibuffer-exit-hook (lambda () (anything-window-configuration 'save))))))
2463 (if (eq setup-or-cleanup 'setup)
2464 (dolist (args hooks) (apply 'add-hook args))
2465 (dolist (args (reverse hooks)) (apply 'remove-hook args)))))
2467 ;; (@* "Core: clean up")
2468 (defun anything-cleanup ()
2469 "Clean up the mess."
2470 (with-current-buffer anything-buffer
2471 (setq cursor-type t))
2472 (bury-buffer anything-buffer)
2473 (anything-funcall-foreach 'cleanup)
2474 (if anything-check-minibuffer-input-timer
2475 (cancel-timer anything-check-minibuffer-input-timer))
2476 (anything-kill-async-processes)
2477 (run-hooks 'anything-cleanup-hook))
2479 ;; (@* "Core: input handling")
2480 (defun anything-check-minibuffer-input ()
2481 "Extract input string from the minibuffer and check if it needs
2482 to be handled."
2483 (if (or (not anything-input-idle-delay) (anything-action-window))
2484 (anything-check-minibuffer-input-1)
2485 (if anything-check-minibuffer-input-timer
2486 (cancel-timer anything-check-minibuffer-input-timer))
2487 (setq anything-check-minibuffer-input-timer
2488 (run-with-idle-timer anything-input-idle-delay nil
2489 'anything-check-minibuffer-input-1))))
2491 (defun anything-check-minibuffer-input-1 ()
2492 (with-anything-quittable
2493 (with-selected-window (minibuffer-window)
2494 (anything-check-new-input (minibuffer-contents)))))
2496 (defun anything-check-new-input (input)
2497 "Check input string and update the anything buffer if
2498 necessary."
2499 (unless (equal input anything-pattern)
2500 (setq anything-pattern input)
2501 (unless (anything-action-window)
2502 (setq anything-input anything-pattern))
2503 (anything-update)))
2505 ;; (@* "Core: source compiler")
2506 (defvar anything-compile-source-functions-default anything-compile-source-functions
2507 "Plug-ins this file provides.")
2508 (defun anything-compile-sources (sources funcs)
2509 "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
2510 Anything plug-ins are realized by this function."
2511 (mapcar
2512 (lambda (source)
2513 (loop with source = (if (listp source) source (symbol-value source))
2514 for f in funcs
2515 do (setq source (funcall f source))
2516 finally (return source)))
2517 sources))
2519 ;; (@* "Core: plug-in attribute documentation hack")
2521 ;; `anything-document-attribute' is public API.
2522 (defadvice documentation-property (after anything-document-attribute activate)
2523 "Hack to display plug-in attributes' documentation as `anything-sources' docstring."
2524 (when (eq symbol 'anything-sources)
2525 (setq ad-return-value
2526 (concat ad-return-value "\n"
2527 (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
2528 anything-additional-attributes
2529 "\n")))))
2530 ;; (describe-variable 'anything-sources)
2531 ;; (documentation-property 'anything-sources 'variable-documentation)
2532 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
2534 ;; (@* "Core: all candidates")
2535 (defun anything-get-candidates (source)
2536 "Retrieve and return the list of candidates from
2537 SOURCE."
2538 (let ((name (assoc-default 'name source)))
2539 (unless (member name anything-delayed-init-executed)
2540 (anything-aif (assoc-default 'delayed-init source)
2541 (with-current-buffer anything-current-buffer
2542 (anything-funcall-with-source source it)
2543 (dolist (f (if (functionp it) (list it) it))
2544 (add-to-list 'anything-delayed-init-executed name))))))
2545 (let* ((candidate-source (assoc-default 'candidates source))
2546 (candidates (anything-interpret-value candidate-source source)))
2547 (cond ((processp candidates) candidates)
2548 ((listp candidates) (anything-transform-candidates candidates source))
2549 (t (error (concat "Candidates must either be a function, "
2550 " a variable or a list: %s")
2551 candidate-source)))))
2554 (defun anything-transform-candidates (candidates source &optional process-p)
2555 "Transform CANDIDATES according to candidate transformers."
2556 (anything-aif (assoc-default 'candidate-transformer source)
2557 (setq candidates (anything-composed-funcall-with-source source it candidates)))
2558 (anything-aif (and process-p (assoc-default 'filtered-candidate-transformer source))
2559 (setq candidates (anything-composed-funcall-with-source source it candidates source)))
2560 (anything-aif (assoc-default 'real-to-display source)
2561 (setq candidates (anything-funcall-with-source
2562 source 'mapcar
2563 (lambda (cand_)
2564 (if (consp cand_)
2565 ;; override DISPLAY from candidate-transformer
2566 (cons (funcall it (cdr cand_)) (cdr cand_))
2567 (cons (funcall it cand_) cand_)))
2568 candidates)))
2569 candidates)
2572 (defun anything-get-cached-candidates (source)
2573 "Return the cached value of candidates for SOURCE.
2574 Cache the candidates if there is not yet a cached value."
2575 (let* ((name (assoc-default 'name source))
2576 (candidate-cache (assoc name anything-candidate-cache))
2577 candidates)
2578 (if candidate-cache
2579 (setq candidates (cdr candidate-cache))
2581 (setq candidates (anything-get-candidates source))
2583 (if (processp candidates)
2584 (progn
2585 (push (cons candidates
2586 (append source
2587 (list (cons 'item-count 0)
2588 (cons 'incomplete-line ""))))
2589 anything-async-processes)
2590 (set-process-filter candidates 'anything-output-filter)
2591 (setq candidates nil))
2593 (unless (assoc 'volatile source)
2594 (setq candidate-cache (cons name candidates))
2595 (push candidate-cache anything-candidate-cache))))
2597 candidates))
2599 ;; (@* "Core: narrowing candidates")
2600 (defun anything-candidate-number-limit (source)
2601 "`anything-candidate-number-limit' variable may be overridden by SOURCE.
2602 If (candidate-number-limit) is in SOURCE, show all candidates in SOURCE,
2603 ie. cancel the effect of `anything-candidate-number-limit'."
2604 (anything-aif (assq 'candidate-number-limit source)
2605 (or (cdr it) 99999999)
2606 (or anything-candidate-number-limit 99999999)))
2608 (defun anything-compute-matches (source)
2609 "Compute matches from SOURCE according to its settings."
2610 (let ((doit (lambda ()
2611 (let ((functions (assoc-default 'match source))
2612 (anything-source-name (assoc-default 'name source))
2613 (limit (anything-candidate-number-limit source))
2614 (anything-pattern
2615 (anything-aif (assoc-default 'pattern-transformer source)
2616 (anything-composed-funcall-with-source source it anything-pattern)
2617 anything-pattern))
2618 matches)
2619 (cond ((or (equal anything-pattern "") (equal functions '(identity)))
2620 (setq matches (anything-get-cached-candidates source))
2621 (if (> (length matches) limit)
2622 (setq matches
2623 (subseq matches 0 limit))))
2625 (condition-case nil
2626 (let ((item-count 0)
2627 (cands (anything-get-cached-candidates source))
2628 exit)
2630 (unless functions
2631 (setq functions
2632 (list (lambda (candidate)
2633 (string-match anything-pattern candidate)))))
2635 (clrhash anything-match-hash)
2636 (dolist (function functions)
2637 (let (newmatches c cc)
2638 (dolist (candidate cands)
2639 (when (and (not (gethash candidate anything-match-hash))
2640 (setq c (if (listp candidate)
2641 (car candidate)
2642 candidate))
2643 (setq cc (cond ((stringp c) c)
2644 ((symbolp c) (symbol-name c))))
2645 (funcall function cc))
2646 (puthash candidate t anything-match-hash)
2647 (push candidate newmatches)
2649 (when limit
2650 (incf item-count)
2651 (when (= item-count limit)
2652 (setq exit t)
2653 (return)))))
2655 (setq matches (append matches (reverse newmatches)))
2657 (if exit
2658 (return)))))
2660 (invalid-regexp (setq matches nil)))))
2662 (anything-aif (assoc-default 'filtered-candidate-transformer source)
2663 (setq matches
2664 (anything-composed-funcall-with-source source it matches source)))
2665 matches))))
2666 (if debug-on-error
2667 (funcall doit)
2668 (condition-case v
2669 (funcall doit)
2670 (error (anything-log-error
2671 "anything-compute-matches: error when processing source: %s"
2672 (assoc-default 'name source))
2673 nil)))))
2675 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2677 (defun anything-process-source (source)
2678 "Display matches from SOURCE according to its settings."
2679 (let ((matches (anything-compute-matches source)))
2680 (when matches
2681 (when anything-test-mode
2682 (setq anything-test-candidate-list
2683 `(,@anything-test-candidate-list
2684 (,(assoc-default 'name source)
2685 ,matches))))
2686 (let ((multiline (assq 'multiline source))
2687 (start (point))
2688 separate)
2689 (anything-insert-header-from-source source)
2690 (dolist (match matches)
2691 (if (and multiline separate)
2692 (anything-insert-candidate-separator)
2693 (setq separate t))
2695 (when (and anything-enable-shortcuts
2696 (not (eq anything-digit-shortcut-count
2697 (length anything-digit-overlays))))
2698 (move-overlay (nth anything-digit-shortcut-count
2699 anything-digit-overlays)
2700 (line-beginning-position)
2701 (line-beginning-position))
2702 (incf anything-digit-shortcut-count))
2703 (anything-insert-match match 'insert source))
2705 (if multiline
2706 (put-text-property start (point) 'anything-multiline t))))))
2708 (defun anything-process-delayed-sources (delayed-sources)
2709 "Process delayed sources if the user is idle for
2710 `anything-idle-delay' seconds."
2711 (with-anything-quittable
2712 (if (sit-for (if anything-input-idle-delay
2713 (max 0 (- anything-idle-delay anything-input-idle-delay))
2714 anything-idle-delay))
2715 (with-current-buffer anything-buffer
2716 (save-excursion
2717 (goto-char (point-max))
2718 (dolist (source delayed-sources)
2719 (anything-process-source source))
2721 (when (and (not (equal (buffer-size) 0))
2722 ;; no selection yet
2723 (= (overlay-start anything-selection-overlay)
2724 (overlay-end anything-selection-overlay)))
2725 (goto-char (point-min))
2726 (anything-next-line)))
2727 (save-excursion
2728 (goto-char (point-min))
2729 (run-hooks 'anything-update-hook))
2730 (anything-maybe-fit-frame)))))
2732 ;; (@* "Core: *anything* buffer contents")
2733 (defvar anything-input-local nil)
2734 (defun anything-update ()
2735 "Update the list of matches in the anything buffer according to
2736 the current pattern."
2737 (setq anything-digit-shortcut-count 0)
2738 (anything-kill-async-processes)
2739 (with-current-buffer (anything-buffer-get)
2740 (set (make-local-variable 'anything-input-local) anything-pattern)
2741 (erase-buffer)
2743 (if anything-enable-shortcuts
2744 (dolist (overlay anything-digit-overlays)
2745 (delete-overlay overlay)))
2747 (let (delayed-sources)
2748 (unwind-protect
2749 (dolist (source (anything-get-sources))
2750 (when (and (or (not anything-source-filter)
2751 (member (assoc-default 'name source) anything-source-filter))
2752 (>= (length anything-pattern)
2753 (anything-aif (assoc 'requires-pattern source)
2754 (or (cdr it) 1)
2755 0)))
2756 (if (or (assoc 'delayed source)
2757 (and anything-quick-update
2758 (< (window-height (get-buffer-window (current-buffer)))
2759 (line-number-at-pos (point-max)))))
2760 (push source delayed-sources)
2761 (anything-process-source source))))
2763 (goto-char (point-min))
2764 (save-excursion (run-hooks 'anything-update-hook))
2765 (anything-next-line)
2766 (setq delayed-sources (nreverse delayed-sources))
2767 (if anything-test-mode
2768 (dolist (source delayed-sources)
2769 (anything-process-source source))
2770 (anything-maybe-fit-frame)
2771 (when delayed-sources
2772 (run-with-idle-timer (if (featurep 'xemacs)
2776 'anything-process-delayed-sources
2777 delayed-sources))
2778 ;; FIXME I want to execute anything-after-update-hook
2779 ;; AFTER processing delayed sources
2780 (run-hooks 'anything-after-update-hook))))))
2782 (defun anything-force-update ()
2783 "Recalculate and update candidates.
2784 If current source has `update' attribute, a function without argument, call it before update."
2785 (interactive)
2786 (let ((source (anything-get-current-source)))
2787 (anything-aif (anything-funcall-with-source source 'anything-candidate-buffer)
2788 (kill-buffer it))
2789 (anything-aif (assoc-default 'init source)
2790 (anything-funcall-with-source source it))
2791 (anything-aif (assoc-default 'update source)
2792 (anything-funcall-with-source source it))
2793 ;; Remove from candidate cache to recalculate candidates
2794 (setq anything-candidate-cache
2795 (delete (assoc (assoc-default 'name source) anything-candidate-cache)
2796 anything-candidate-cache))
2797 ;; Go to original selection after update
2798 (let ((selection (anything-get-selection nil t)))
2799 (anything-update)
2800 (with-anything-window
2801 (anything-goto-source source)
2802 (forward-char -1) ;back to \n
2803 (if (search-forward (concat "\n" selection "\n") nil t)
2804 (forward-line -1)
2805 (goto-char (point-min))
2806 (forward-line 1))
2807 (anything-mark-current-line)))))
2809 (defun anything-insert-match (match insert-function source)
2810 "Insert MATCH into the anything buffer. If MATCH is a list then
2811 insert the string inteneded to appear on the display and store
2812 the real value in a text property."
2813 (let ((start (line-beginning-position (point)))
2814 (string (if (listp match) (car match) match))
2815 (realvalue (if (listp match) (cdr match))))
2816 (when (symbolp string) (setq string (symbol-name string)))
2817 (when (stringp string)
2818 (funcall insert-function string)
2819 ;; Some sources with candidates-in-buffer have already added
2820 ;; 'anything-realvalue property when creating candidate buffer.
2821 (unless (get-text-property start 'anything-realvalue)
2822 (and realvalue
2823 (put-text-property start (line-end-position)
2824 'anything-realvalue realvalue)))
2825 (when anything-source-in-each-line-flag
2826 (put-text-property start (line-end-position)
2827 'anything-source source))
2828 (funcall insert-function "\n"))))
2830 (defun anything-insert-header-from-source (source)
2831 (let ((name (assoc-default 'name source)))
2832 (anything-insert-header name
2833 (anything-aif (assoc-default 'header-name source)
2834 (anything-funcall-with-source source it name)))))
2836 (defun anything-insert-header (name &optional display-string)
2837 "Insert header of source NAME into the anything buffer."
2838 (unless (bobp)
2839 (let ((start (point)))
2840 (insert "\n")
2841 (put-text-property start (point) 'anything-header-separator t)))
2843 (let ((start (point)))
2844 (insert name)
2845 (put-text-property (line-beginning-position)
2846 (line-end-position) 'anything-header t)
2847 (when display-string
2848 (overlay-put (make-overlay (line-beginning-position) (line-end-position))
2849 'display display-string))
2850 (insert "\n")
2851 (put-text-property start (point) 'face anything-header-face)))
2854 (defun anything-insert-candidate-separator ()
2855 "Insert separator of candidates into the anything buffer."
2856 (insert anything-candidate-separator)
2857 (put-text-property (line-beginning-position)
2858 (line-end-position) 'anything-candidate-separator t)
2859 (insert "\n"))
2864 ;; (@* "Core: async process")
2865 (defun anything-output-filter (process string)
2866 "Process output from PROCESS."
2867 (let* ((process-assoc (assoc process anything-async-processes))
2868 (process-info (cdr process-assoc))
2869 (insertion-marker (assoc-default 'insertion-marker process-info))
2870 (incomplete-line-info (assoc 'incomplete-line process-info))
2871 (item-count-info (assoc 'item-count process-info))
2872 (limit (anything-candidate-number-limit process-info)))
2874 (with-current-buffer anything-buffer
2875 (save-excursion
2876 (if insertion-marker
2877 (goto-char insertion-marker)
2879 (goto-char (point-max))
2880 (anything-insert-header-from-source process-info)
2881 (setcdr process-assoc
2882 (append process-info `((insertion-marker . ,(point-marker))))))
2884 (let ((lines (split-string string "\n"))
2885 (multiline (assq 'multiline process-info))
2886 (start (point))
2887 candidates separate)
2888 (while lines
2889 (if (not (cdr lines))
2890 ;; store last incomplete line until new output arrives
2891 (setcdr incomplete-line-info (car lines))
2893 (if (cdr incomplete-line-info)
2894 (progn
2895 (push (concat (cdr incomplete-line-info) (car lines))
2896 candidates)
2897 (setcdr incomplete-line-info nil))
2899 (push (car lines) candidates)))
2901 (pop lines))
2903 (setq candidates (reverse candidates))
2904 (dolist (candidate (anything-transform-candidates candidates process-info t))
2905 ;; FIXME
2906 ;; (if (and multiline separate)
2907 ;; (anything-insert-candidate-separator)
2908 ;; (setq separate t))
2909 (anything-insert-match candidate 'insert-before-markers process-info)
2910 (incf (cdr item-count-info))
2911 ;; FIXME
2912 ;; (if multiline
2913 ;; (put-text-property start (point) 'anything-multiline t))
2914 (when (>= (cdr item-count-info) limit)
2915 (anything-kill-async-process process)
2916 (return)))))
2918 (anything-maybe-fit-frame)
2920 (run-hooks 'anything-update-hook)
2922 (if (bobp)
2923 (anything-next-line)
2925 (save-selected-window
2926 (select-window (get-buffer-window anything-buffer 'visible))
2927 (anything-mark-current-line))))))
2930 (defun anything-kill-async-processes ()
2931 "Kill all known asynchronous processes according to
2932 `anything-async-processes'."
2933 "Kill locate process."
2934 (dolist (process-info anything-async-processes)
2935 (anything-kill-async-process (car process-info)))
2936 (setq anything-async-processes nil))
2939 (defun anything-kill-async-process (process)
2940 "Kill PROCESS and detach the associated functions."
2941 (set-process-filter process nil)
2942 (delete-process process))
2945 ;; (@* "Core: action")
2946 (defun anything-execute-selection-action (&optional selection action clear-saved-action)
2947 "If a candidate was selected then perform the associated
2948 action."
2949 (setq selection (or selection (anything-get-selection)))
2950 (setq action (or action
2951 anything-saved-action
2952 (if (get-buffer anything-action-buffer)
2953 (anything-get-selection anything-action-buffer)
2954 (anything-get-action))))
2955 (let ((source (or anything-saved-current-source (anything-get-current-source))))
2956 (if (and (not selection) (assoc 'accept-empty source))
2957 (setq selection ""))
2958 (if (and (listp action)
2959 (not (functionp action))) ; lambda
2960 ;;select the default action
2961 (setq action (cdar action)))
2962 (unless clear-saved-action (setq anything-saved-action nil))
2963 (if (and selection action)
2964 (anything-funcall-with-source source action selection))))
2966 (defun anything-select-action ()
2967 "Select an action for the currently selected candidate.
2968 If action buffer is selected, back to the anything buffer."
2969 (interactive)
2970 (cond ((get-buffer-window anything-action-buffer 'visible)
2971 (set-window-buffer (get-buffer-window anything-action-buffer) anything-buffer)
2972 (kill-buffer anything-action-buffer)
2973 (insert anything-input))
2975 (setq anything-saved-selection (anything-get-selection))
2976 (unless anything-saved-selection
2977 (error "Nothing is selected."))
2978 (setq anything-saved-current-source (anything-get-current-source))
2979 (let ((actions (anything-get-action)))
2980 (if (functionp actions)
2981 (message "Sole action: %s" actions)
2982 (with-current-buffer (get-buffer-create anything-action-buffer)
2983 (erase-buffer)
2984 (buffer-disable-undo)
2985 (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
2986 (set (make-local-variable 'anything-sources)
2987 `(((name . "Actions")
2988 (volatile)
2989 (candidates . ,actions)
2990 ;; Override `anything-candidate-number-limit'
2991 (candidate-number-limit . 9999))))
2992 (set (make-local-variable 'anything-source-filter) nil)
2993 (set (make-local-variable 'anything-selection-overlay) nil)
2994 (set (make-local-variable 'anything-digit-overlays) nil)
2995 (anything-initialize-overlays anything-action-buffer))
2996 (with-selected-window (minibuffer-window)
2997 (delete-minibuffer-contents))
2998 (setq anything-pattern 'dummy) ; so that it differs from the
2999 ; previous one
3001 (anything-check-minibuffer-input))))))
3003 ;; (@* "Core: selection")
3004 (defun anything-move-selection-common (move-func unit direction)
3005 "Move the selection marker to a new position determined by
3006 UNIT and DIRECTION."
3007 (unless (or (zerop (buffer-size (get-buffer (anything-buffer-get))))
3008 (not (anything-window)))
3009 (with-anything-window
3010 (funcall move-func)
3011 (while (and (not (bobp))
3012 (or (anything-pos-header-line-p)
3013 (anything-pos-candidate-separator-p)))
3014 (forward-line (if (and (eq direction 'previous)
3015 (not (eq (line-beginning-position) (point-min))))
3017 1)))
3018 (and (bobp) (forward-line 1)) ;skip first header
3019 (and (eobp) (forward-line -1)) ;avoid last empty line
3020 (when (and anything-display-source-at-screen-top (eq unit 'source))
3021 (set-window-start (selected-window)
3022 (save-excursion (forward-line -1) (point))))
3023 (when (anything-get-previous-header-pos)
3024 (anything-mark-current-line))
3025 (anything-display-mode-line (anything-get-current-source)))))
3027 (defvar anything-mode-line-string-real nil)
3028 (defun anything-display-mode-line (source)
3029 (set (make-local-variable 'anything-mode-line-string)
3030 (anything-interpret-value (or (assoc-default 'mode-line source)
3031 (default-value 'anything-mode-line-string))
3032 source))
3033 (if anything-mode-line-string
3034 (setq mode-line-format
3035 '(" " mode-line-buffer-identification " "
3036 (line-number-mode "%l") " " (anything-follow-mode "(F)")
3037 " " anything-mode-line-string-real "-%-")
3038 anything-mode-line-string-real
3039 (substitute-command-keys anything-mode-line-string))
3040 (setq mode-line-format
3041 (default-value 'mode-line-format)))
3042 (setq header-line-format
3043 (anything-interpret-value (assoc-default 'header-line source) source)))
3045 (defun anything-previous-line ()
3046 "Move selection to the previous line."
3047 (interactive)
3048 (anything-move-selection-common
3049 (lambda ()
3050 (forward-line -1)
3051 (when (anything-pos-multiline-p)
3052 (if (or (anything-pos-header-line-p)
3053 (anything-pos-candidate-separator-p))
3054 (forward-line -1)
3055 (forward-line 1))
3056 (let ((header-pos (anything-get-previous-header-pos))
3057 (candidate-pos (anything-get-previous-candidate-separator-pos)))
3058 (when header-pos
3059 (if (or (null candidate-pos) (< candidate-pos header-pos))
3060 (goto-char header-pos)
3061 (goto-char candidate-pos))
3062 (forward-line 1)))))
3063 'line 'previous))
3065 (defun anything-next-line ()
3066 "Move selection to the next line."
3067 (interactive)
3068 (anything-move-selection-common
3069 (lambda ()
3070 (if (not (anything-pos-multiline-p))
3071 (forward-line 1)
3072 (let ((header-pos (anything-get-next-header-pos))
3073 (candidate-pos (anything-get-next-candidate-separator-pos)))
3074 (if (and candidate-pos
3075 (or (null header-pos)
3076 (< candidate-pos header-pos)))
3077 (goto-char candidate-pos)
3078 (if header-pos
3079 (goto-char header-pos)))
3080 (if candidate-pos
3081 (forward-line 1)))))
3082 'line 'next))
3084 (defun anything-previous-page ()
3085 "Move selection back with a pageful."
3086 (interactive)
3087 (anything-move-selection-common
3088 (lambda ()
3089 (condition-case nil
3090 (scroll-down)
3091 (beginning-of-buffer (goto-char (point-min)))))
3092 'page 'previous))
3094 (defun anything-next-page ()
3095 "Move selection forward with a pageful."
3096 (interactive)
3097 (anything-move-selection-common
3098 (lambda ()
3099 (condition-case nil
3100 (scroll-up)
3101 (end-of-buffer (goto-char (point-max)))))
3102 'page 'next))
3104 (defun anything-beginning-of-buffer ()
3105 "Move selection at the top."
3106 (interactive)
3107 (anything-move-selection-common (lambda () (goto-char (point-min)))
3108 'edge 'previous))
3110 (defun anything-end-of-buffer ()
3111 "Move selection at the bottom."
3112 (interactive)
3113 (anything-move-selection-common (lambda () (goto-char (point-max)))
3114 'edge 'next))
3116 (defun anything-previous-source ()
3117 "Move selection to the previous source."
3118 (interactive)
3119 (anything-move-selection-common
3120 (lambda ()
3121 (forward-line -1)
3122 (if (bobp)
3123 (goto-char (point-max))
3124 (if (anything-pos-header-line-p)
3125 (forward-line -1)
3126 (forward-line 1)))
3127 (goto-char (anything-get-previous-header-pos))
3128 (forward-line 1))
3129 'source 'previous))
3131 (defun anything-next-source ()
3132 "Move selection to the next source."
3133 (interactive)
3134 (anything-move-selection-common
3135 (lambda () (goto-char (or (anything-get-next-header-pos) (point-min))))
3136 'source 'next))
3138 (defun anything-goto-source (source-or-name)
3139 "Move the selection to the source (SOURCE-OR-NAME)."
3140 (anything-move-selection-common
3141 (lambda ()
3142 (goto-char (point-min))
3143 (let ((name (if (stringp source-or-name) source-or-name
3144 (assoc-default 'name source-or-name))))
3145 (while (not (string= name (buffer-substring (point-at-bol) (point-at-eol))))
3146 (goto-char (anything-get-next-header-pos)))))
3147 'source 'next))
3149 (defun anything-mark-current-line ()
3150 "Move selection overlay to current line."
3151 (move-overlay anything-selection-overlay
3152 (line-beginning-position)
3153 (if (anything-pos-multiline-p)
3154 (let ((header-pos (anything-get-next-header-pos))
3155 (candidate-pos (anything-get-next-candidate-separator-pos)))
3156 (or (and (null header-pos) candidate-pos candidate-pos)
3157 (and header-pos candidate-pos (< candidate-pos header-pos) candidate-pos)
3158 header-pos
3159 (point-max)))
3160 (1+ (line-end-position))))
3161 (anything-follow-execute-persistent-action-maybe))
3163 (defun anything-this-command-key ()
3164 (event-basic-type (elt (this-command-keys-vector) 0)))
3165 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
3167 (defun anything-select-with-digit-shortcut ()
3168 (interactive)
3169 (if (eq anything-enable-shortcuts 'alphabet)
3170 (save-selected-window
3171 (select-window (anything-window))
3172 (let* ((index (position (anything-this-command-key) anything-shortcut-keys))
3173 (overlay (nth index anything-digit-overlays)))
3174 (when (overlay-buffer overlay)
3175 (goto-char (overlay-start overlay))
3176 (anything-mark-current-line)
3177 (anything-exit-minibuffer))))
3178 (self-insert-command 1)))
3180 ;;; EXPERIMENTAL TODO documentation
3181 (defun anything-select-with-prefix-shortcut ()
3182 (interactive)
3183 (if (eq anything-enable-shortcuts 'prefix)
3184 (save-selected-window
3185 (select-window (anything-window))
3186 (let* ((key (read-event "Select shortcut key: "))
3187 (index (position key anything-shortcut-keys))
3188 (overlay (ignore-errors (nth index anything-digit-overlays))))
3189 (if (not (and overlay (overlay-buffer overlay)))
3190 (when (numberp key)
3191 (select-window (minibuffer-window))
3192 (self-insert-command 1))
3193 (goto-char (overlay-start overlay))
3194 (anything-mark-current-line)
3195 (anything-exit-minibuffer))))
3196 (self-insert-command 1)))
3197 ;; (setq anything-enable-shortcuts 'prefix)
3198 ;; (define-key anything-map "@" 'anything-select-with-prefix-shortcut)
3199 ;; (define-key anything-map (kbd "<f18>") 'anything-select-with-prefix-shortcut)
3201 (defun anything-exit-minibuffer ()
3202 "Select the current candidate by exiting the minibuffer."
3203 (interactive)
3204 (declare (special anything-iswitchb-candidate-selected))
3205 (setq anything-iswitchb-candidate-selected (anything-get-selection))
3206 (exit-minibuffer))
3209 (defun anything-get-next-header-pos ()
3210 "Return the position of the next header from point."
3211 (next-single-property-change (point) 'anything-header))
3214 (defun anything-get-previous-header-pos ()
3215 "Return the position of the previous header from point"
3216 (previous-single-property-change (point) 'anything-header))
3219 (defun anything-pos-multiline-p ()
3220 "Return non-nil if the current position is in the multiline source region."
3221 (get-text-property (point) 'anything-multiline))
3224 (defun anything-get-next-candidate-separator-pos ()
3225 "Return the position of the next candidate separator from point."
3226 (next-single-property-change (point) 'anything-candidate-separator))
3229 (defun anything-get-previous-candidate-separator-pos ()
3230 "Return the position of the previous candidate separator from point."
3231 (previous-single-property-change (point) 'anything-candidate-separator))
3234 (defun anything-pos-header-line-p ()
3235 "Return t if the current line is a header line."
3236 (or (get-text-property (line-beginning-position) 'anything-header)
3237 (get-text-property (line-beginning-position) 'anything-header-separator)))
3239 (defun anything-pos-candidate-separator-p ()
3240 "Return t if the current line is a candidate separator."
3241 (get-text-property (line-beginning-position) 'anything-candidate-separator))
3243 ;; (@* "Core: error handling")
3244 (defun anything-log-error (&rest args)
3245 "Accumulate error messages into `anything-issued-errors'."
3246 (let ((msg (apply 'format args)))
3247 (unless (member msg anything-issued-errors)
3248 (add-to-list 'anything-issued-errors msg))))
3250 (defun anything-print-error-messages ()
3251 "Print error messages in `anything-issued-errors'."
3252 (message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))
3255 ;; (@* "Core: help")
3256 (defun anything-help-internal (bufname insert-content-fn)
3257 "Show long message during `anything' session."
3258 (save-window-excursion
3259 (select-window (anything-window))
3260 (delete-other-windows)
3261 (switch-to-buffer (get-buffer-create bufname))
3262 (setq mode-line-format "%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
3263 (setq cursor-type nil)
3264 (erase-buffer)
3265 (funcall insert-content-fn)
3266 (goto-char 1)
3267 (ignore-errors
3268 (loop for event = (read-event) do
3269 (case event
3270 ((?\C-v ? ) (scroll-up))
3271 ((?\M-v ?b) (scroll-down))
3272 (t (return)))))))
3274 (defun anything-help ()
3275 "Help of `anything'."
3276 (interactive)
3277 (anything-help-internal
3278 " *Anything Help*"
3279 (lambda ()
3280 (insert (substitute-command-keys
3281 (anything-interpret-value anything-help-message)))
3282 (org-mode))))
3284 (defun anything-debug-output ()
3285 "Show all anything-related variables at this time."
3286 (interactive)
3287 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function))
3289 (defun anything-debug-output-function (&optional vars)
3290 (message "Calculating all anything-related values...")
3291 (insert "If you debug some variables or forms, set `anything-debug-forms'
3292 to a list of forms.\n\n")
3293 (dolist (v (or vars
3294 anything-debug-forms
3295 (apropos-internal "^anything-" 'boundp)))
3296 (insert "** "
3297 (pp-to-string v) "\n"
3298 (pp-to-string (eval v)) "\n"))
3299 (message "Calculating all anything-related values...Done")
3302 ;; (@* "Core: misc")
3303 (defun anything-kill-buffer-hook ()
3304 "Remove tick entry from `anything-tick-hash' when killing a buffer."
3305 (loop for key being the hash-keys in anything-tick-hash
3306 if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
3307 do (remhash key anything-tick-hash)))
3308 (add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
3310 (defun anything-maybe-fit-frame ()
3311 "Fit anything frame to its buffer, and put it at top right of display.
3313 It is disabled by default because some flickering occurred in some environment.
3314 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
3315 `fit-frame-inhibit-fitting' to nil.
3316 You can set user options `fit-frame-max-width-percent' and
3317 `fit-frame-max-height-percent' to control max frame size."
3318 (declare (warn (unresolved 0)))
3319 (when (and (require 'fit-frame nil t)
3320 (boundp 'fit-frame-inhibit-fitting-flag)
3321 (not anything-inhibit-fit-frame-flag)
3322 (not fit-frame-inhibit-fitting-flag)
3323 (anything-window))
3324 (ignore-errors
3325 (with-anything-window
3326 (fit-frame nil nil nil t)
3327 (modify-frame-parameters
3328 (selected-frame)
3329 `((left . ,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
3330 (top . 0))))))) ; The (top . 0) shouldn't be necessary (Emacs bug).
3332 (defun anything-preselect (candidate-or-regexp)
3333 (when candidate-or-regexp
3334 (with-anything-window
3335 (goto-char (point-min))
3336 ;; go to first candidate of first source
3337 (forward-line 1)
3338 (let ((start (point)))
3339 (unless (or (re-search-forward (concat "^" (regexp-quote candidate-or-regexp) "$") nil t)
3340 (progn (goto-char start)
3341 (re-search-forward candidate-or-regexp nil t)))
3342 (goto-char start))
3343 (anything-mark-current-line)))))
3345 (defun anything-delete-current-selection ()
3346 "Delete the currently selected item."
3347 (interactive)
3348 (with-anything-window
3349 (cond ((anything-pos-multiline-p)
3350 (anything-aif (anything-get-next-candidate-separator-pos)
3351 (delete-region (point-at-bol)
3352 (1+ (progn (goto-char it) (point-at-eol))))
3353 ;; last candidate
3354 (goto-char (anything-get-previous-candidate-separator-pos))
3355 (delete-region (point-at-bol) (point-max)))
3356 (when (eobp)
3357 (goto-char (or (anything-get-previous-candidate-separator-pos)
3358 (point-min)))
3359 (forward-line 1)))
3361 (delete-region (point-at-bol) (1+ (point-at-eol)))
3362 (when (eobp) (forward-line -1))))
3363 (anything-mark-current-line)))
3365 (defun anything-edit-current-selection-1 (func)
3366 (with-anything-window
3367 (beginning-of-line)
3368 (let ((realvalue (get-text-property (point) 'anything-realvalue)))
3369 (funcall func)
3370 (beginning-of-line)
3371 (and realvalue
3372 (put-text-property (point) (point-at-eol) 'anything-realvalue realvalue))
3373 (anything-mark-current-line))))
3375 (defmacro anything-edit-current-selection (&rest forms)
3376 "Evaluate FORMS at current selection in the anything buffer.
3377 You can edit the line."
3378 `(anything-edit-current-selection-1
3379 (lambda () ,@forms)))
3380 (put 'anything-edit-current-selection 'lisp-indent-function 0)
3382 (defun anything-delete-minibuffer-content ()
3383 "Same as `delete-minibuffer-contents' but this is a command."
3384 (interactive)
3385 (delete-minibuffer-contents))
3387 ;; (@* "Built-in plug-in: type")
3388 (defun anything-compile-source--type (source)
3389 (anything-aif (assoc-default 'type source)
3390 (append source (assoc-default it anything-type-attributes) nil)
3391 source))
3393 ;; `define-anything-type-attribute' is public API.
3395 (defun anything-add-type-attribute (type definition)
3396 (anything-aif (assq type anything-type-attributes)
3397 (setq anything-type-attributes (delete it anything-type-attributes)))
3398 (push (cons type definition) anything-type-attributes))
3400 (defvar anything-types nil)
3401 (defun anything-document-type-attribute (type doc)
3402 (add-to-list 'anything-types type t)
3403 (put type 'anything-typeattrdoc
3404 (concat "- " (symbol-name type) "\n\n" doc "\n")))
3406 (defadvice documentation-property (after anything-document-type-attribute activate)
3407 "Hack to display type attributes' documentation as `anything-type-attributes' docstring."
3408 (when (eq symbol 'anything-type-attributes)
3409 (setq ad-return-value
3410 (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
3411 (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
3412 anything-types "\n")))))
3414 ;; (@* "Built-in plug-in: dummy")
3415 (defun anything-dummy-candidate (candidate source)
3416 ;; `source' is defined in filtered-candidate-transformer
3417 (list anything-pattern))
3419 (defun anything-compile-source--dummy (source)
3420 (if (assoc 'dummy source)
3421 (append source
3422 '((candidates "dummy")
3423 (accept-empty)
3424 (match identity)
3425 (filtered-candidate-transformer . anything-dummy-candidate)
3426 (disable-shortcuts)
3427 (volatile)))
3428 source))
3430 ;; (@* "Built-in plug-in: disable-shortcuts")
3431 (defvar anything-orig-enable-shortcuts nil)
3432 (defun anything-save-enable-shortcuts ()
3433 (anything-once
3434 (lambda () (setq anything-orig-enable-shortcuts anything-enable-shortcuts
3435 anything-enable-shortcuts nil))))
3436 (defun anything-compile-source--disable-shortcuts (source)
3437 (if (assoc 'disable-shortcuts source)
3438 (append `((init ,@(anything-mklist (assoc-default 'init source))
3439 anything-save-enable-shortcuts)
3440 (resume ,@(anything-mklist (assoc-default 'resume source))
3441 anything-save-enable-shortcuts)
3442 (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
3443 (lambda () (setq anything-enable-shortcuts anything-orig-enable-shortcuts))))
3444 source)
3445 source))
3447 ;; (@* "Built-in plug-in: candidates-in-buffer")
3448 (defun anything-candidates-in-buffer ()
3449 "Get candidates from the candidates buffer according to `anything-pattern'.
3451 BUFFER is `anything-candidate-buffer' by default. Each
3452 candidate must be placed in one line. This function is meant to
3453 be used in candidates-in-buffer or candidates attribute of an
3454 anything source. Especially fast for many (1000+) candidates.
3457 '((name . \"many files\")
3458 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
3459 (insert-many-filenames))))
3460 (search re-search-forward) ; optional
3461 (candidates-in-buffer)
3462 (type . file))
3464 +===============================================================+
3465 | The new way of making and narrowing candidates: Using buffers |
3466 +===============================================================+
3468 By default, `anything' makes candidates by evaluating the
3469 candidates function, then narrows them by `string-match' for each
3470 candidate.
3472 But this way is very slow for many candidates. The new way is
3473 storing all candidates in a buffer and narrowing them by
3474 `re-search-forward'. Search function is customizable by search
3475 attribute. The important point is that buffer processing is MUCH
3476 FASTER than string list processing and is the Emacs way.
3478 The init function writes all candidates to a newly-created
3479 candidate buffer. The candidates buffer is created or specified
3480 by `anything-candidate-buffer'. Candidates are stored in a line.
3482 The candidates function narrows all candidates, IOW creates a
3483 subset of candidates dynamically. It is the task of
3484 `anything-candidates-in-buffer'. As long as
3485 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
3486 sufficient in most cases.
3488 Note that `(candidates-in-buffer)' is shortcut of three attributes:
3489 (candidates . anything-candidates-in-buffer)
3490 (volatile)
3491 (match identity)
3492 And `(candidates-in-buffer . func)' is shortcut of three attributes:
3493 (candidates . func)
3494 (volatile)
3495 (match identity)
3496 The expansion is performed in `anything-get-sources'.
3498 The candidates-in-buffer attribute implies the volatile attribute.
3499 The volatile attribute is needed because `anything-candidates-in-buffer'
3500 creates candidates dynamically and need to be called everytime
3501 `anything-pattern' changes.
3503 Because `anything-candidates-in-buffer' plays the role of `match' attribute
3504 function, specifying `(match identity)' makes the source slightly faster.
3506 To customize `anything-candidates-in-buffer' behavior, use search,
3507 get-line and search-from-end attributes. See also `anything-sources' docstring.
3509 (declare (special source))
3510 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
3511 anything-pattern
3512 (or (assoc-default 'get-line source)
3513 #'buffer-substring-no-properties)
3514 ;; use external variable `source'.
3515 (or (assoc-default 'search source)
3516 (if (assoc 'search-from-end source)
3517 '(re-search-backward)
3518 '(re-search-forward)))
3519 (anything-candidate-number-limit source)
3520 (assoc 'search-from-end source)))
3522 (defun* anything-candidates-in-buffer-1 (buffer &optional (pattern anything-pattern) (get-line-fn 'buffer-substring-no-properties) (search-fns '(re-search-forward)) (limit anything-candidate-number-limit) search-from-end)
3523 ;; buffer == nil when candidates buffer does not exist.
3524 (when buffer
3525 (with-current-buffer buffer
3526 (let ((start-point (if search-from-end (point-max) (point-min)))
3527 (next-line-fn (if search-from-end
3528 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
3529 #'forward-line))
3530 (endp (if search-from-end #'bobp #'eobp)))
3531 (goto-char (1- start-point))
3532 (if (string= pattern "")
3533 (delq nil (loop until (funcall endp)
3534 for i from 1 to limit
3535 collecting (funcall get-line-fn (point-at-bol) (point-at-eol))
3536 do (funcall next-line-fn 1)))
3538 (let ((i 1)
3539 (next-line-fn (if search-from-end
3540 (lambda (x) (goto-char (max (point-at-bol) 1)))
3541 #'forward-line))
3542 buffer-read-only
3543 matches exit newmatches)
3544 (progn
3545 (goto-char (point-min))
3546 (insert "\n")
3547 (goto-char (point-max))
3548 (insert "\n")
3549 (setq start-point (if search-from-end (point-max) (point-min)))
3550 (clrhash anything-cib-hash)
3551 (unwind-protect
3552 (dolist (searcher search-fns)
3553 (goto-char start-point)
3554 (setq newmatches nil)
3555 (loop while (funcall searcher pattern nil t)
3556 if (or (funcall endp) (< limit i))
3557 do (setq exit t) (return)
3558 else do
3559 (let ((cand (funcall get-line-fn (point-at-bol) (point-at-eol))))
3560 (unless (gethash cand anything-cib-hash)
3561 (puthash cand t anything-cib-hash)
3562 (incf i)
3563 (push cand newmatches)))
3564 (funcall next-line-fn 1))
3565 (setq matches (append matches (nreverse newmatches)))
3566 (if exit (return)))
3567 (goto-char (point-min))
3568 (delete-char 1)
3569 (goto-char (1- (point-max)))
3570 (delete-char 1)
3572 (set-buffer-modified-p nil)))
3573 (delq nil matches)))))))
3576 (defun anything-candidate-buffer (&optional create-or-buffer)
3577 "Register and return a buffer containing candidates of current source.
3578 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3579 then global candidates buffer.
3581 Acceptable values of CREATE-OR-BUFFER:
3583 - nil (omit)
3584 Only return the candidates buffer.
3585 - a buffer
3586 Register a buffer as a candidates buffer.
3587 - 'global
3588 Create a new global candidates buffer,
3589 named \" *anything candidates:SOURCE*\".
3590 - other non-nil value
3591 Create a new global candidates buffer,
3592 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
3594 (let* ((gbufname (format " *anything candidates:%s*" anything-source-name))
3595 (lbufname (concat gbufname (buffer-name anything-current-buffer)))
3596 buf)
3597 (when create-or-buffer
3598 (if (bufferp create-or-buffer)
3599 (setq anything-candidate-buffer-alist
3600 (cons (cons anything-source-name create-or-buffer)
3601 (delete (assoc anything-source-name anything-candidate-buffer-alist)
3602 anything-candidate-buffer-alist)))
3603 (add-to-list 'anything-candidate-buffer-alist
3604 (cons anything-source-name create-or-buffer))
3605 (when (eq create-or-buffer 'global)
3606 (loop for b in (buffer-list)
3607 if (string-match (format "^%s" (regexp-quote gbufname)) (buffer-name b))
3608 do (kill-buffer b)))
3609 (with-current-buffer
3610 (get-buffer-create (if (eq create-or-buffer 'global) gbufname lbufname))
3611 (buffer-disable-undo)
3612 (erase-buffer)
3613 (font-lock-mode -1))))
3614 (or (get-buffer lbufname)
3615 (get-buffer gbufname)
3616 (anything-aif (assoc-default anything-source-name anything-candidate-buffer-alist)
3617 (and (buffer-live-p it) it)))))
3619 (defun anything-compile-source--candidates-in-buffer (source)
3620 (anything-aif (assoc 'candidates-in-buffer source)
3621 (append source `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
3622 (volatile) (match identity)))
3623 source))
3625 ;; (@* "Utility: resplit anything window")
3626 (defun anything-toggle-resplit-window ()
3627 "Toggle resplit anything window, vertically or horizontally."
3628 (interactive)
3629 (with-anything-window
3630 (let ((before-height (window-height)))
3631 (delete-window)
3632 (set-window-buffer
3633 (select-window (if (= (window-height) before-height)
3634 (split-window-vertically)
3635 (split-window-horizontally)))
3636 anything-buffer))))
3638 ;; (@* "Utility: select another action by key")
3639 (defun anything-select-nth-action (n)
3640 "Select the nth action for the currently selected candidate."
3641 (setq anything-saved-selection (anything-get-selection))
3642 (unless anything-saved-selection
3643 (error "Nothing is selected."))
3644 (setq anything-saved-action (cdr (elt (anything-get-action) n)))
3645 (anything-exit-minibuffer))
3647 (defun anything-select-2nd-action ()
3648 "Select the 2nd action for the currently selected candidate."
3649 (interactive)
3650 (anything-select-nth-action 1))
3652 (defun anything-select-3rd-action ()
3653 "Select the 3rd action for the currently selected candidate."
3654 (interactive)
3655 (anything-select-nth-action 2))
3657 (defun anything-select-4th-action ()
3658 "Select the 4th action for the currently selected candidate."
3659 (interactive)
3660 (anything-select-nth-action 3))
3662 (defun anything-select-2nd-action-or-end-of-line ()
3663 "Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
3664 Otherwise goto the end of minibuffer."
3665 (interactive)
3666 (if (eolp)
3667 (anything-select-nth-action 1)
3668 (end-of-line)))
3670 ;; (@* "Utility: Persistent Action")
3671 (defmacro with-anything-display-same-window (&rest body)
3672 "Make `pop-to-buffer' and `display-buffer' display in the same window."
3673 `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
3674 ,@body))
3675 (put 'with-anything-display-same-window 'lisp-indent-function 0)
3677 (defun* anything-execute-persistent-action (&optional (attr 'persistent-action))
3678 "If a candidate is selected then perform the associated action without quitting anything."
3679 (interactive)
3680 (save-selected-window
3681 (select-window (get-buffer-window (anything-buffer-get)))
3682 (select-window (setq minibuffer-scroll-window
3683 (if (one-window-p t) (split-window)
3684 (next-window (selected-window) 1))))
3685 (let ((anything-in-persistent-action t))
3686 (with-anything-display-same-window
3687 (anything-execute-selection-action
3689 (or (assoc-default attr (anything-get-current-source))
3690 (anything-get-action))
3692 (run-hooks 'anything-after-persistent-action-hook)))))
3694 (defun anything-persistent-action-display-buffer (buf &optional not-this-window)
3695 "Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
3696 If `anything-persistent-action-use-special-display' is non-nil and
3697 BUF is to be displayed by `special-display-function', use it.
3698 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
3699 (let* ((name (buffer-name buf))
3700 display-buffer-function pop-up-windows
3701 (same-window-regexps
3702 (unless (and anything-persistent-action-use-special-display
3703 (or (member name
3704 (mapcar (lambda (x) (or (car-safe x) x)) special-display-buffer-names))
3705 (remove-if-not
3706 (lambda (x) (string-match (or (car-safe x) x) name))
3707 special-display-regexps)))
3708 '("."))))
3709 (display-buffer buf not-this-window)))
3711 ;; scroll-other-window(-down)? for persistent-action
3712 (defun anything-scroll-other-window-base (command)
3713 (save-selected-window
3714 (select-window
3715 (some-window
3716 (lambda (w) (not (string= anything-buffer (buffer-name (window-buffer w)))))
3717 'no-minibuffer 'current-frame))
3718 (call-interactively command)))
3720 (defun anything-scroll-other-window ()
3721 "Scroll other window (not *Anything* window) upward."
3722 (interactive)
3723 (anything-scroll-other-window-base (lambda ()
3724 (interactive)
3725 (scroll-up anything-scroll-amount))))
3726 (defun anything-scroll-other-window-down ()
3727 "Scroll other window (not *Anything* window) downward."
3728 (interactive)
3729 (anything-scroll-other-window-base (lambda ()
3730 (interactive)
3731 (scroll-down anything-scroll-amount))))
3733 ;; (@* "Utility: Visible Mark")
3734 (defface anything-visible-mark
3735 '((((min-colors 88) (background dark))
3736 (:background "green1" :foreground "black"))
3737 (((background dark)) (:background "green" :foreground "black"))
3738 (((min-colors 88)) (:background "green1"))
3739 (t (:background "green")))
3740 "Face for visible mark."
3741 :group 'anything)
3742 (defvar anything-visible-mark-face 'anything-visible-mark)
3743 (defvar anything-visible-mark-overlays nil)
3745 (defun anything-clear-visible-mark ()
3746 (mapc 'delete-overlay anything-visible-mark-overlays)
3747 (setq anything-visible-mark-overlays nil))
3748 (add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
3750 ;; (defun anything-toggle-visible-mark ()
3751 ;; (interactive)
3752 ;; (with-anything-window
3753 ;; (anything-aif (loop for o in anything-visible-mark-overlays
3754 ;; when (equal (line-beginning-position) (overlay-start o))
3755 ;; do (return o))
3756 ;; ;; delete
3757 ;; (progn (delete-overlay it)
3758 ;; (delq it anything-visible-mark-overlays))
3759 ;; (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
3760 ;; (overlay-put o 'face anything-visible-mark-face)
3761 ;; (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3762 ;; (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3763 ;; (add-to-list 'anything-visible-mark-overlays o)))))
3765 (defvar anything-c-marked-candidate-list nil
3766 "[OBSOLETE] DO NOT USE!!")
3767 (defvar anything-marked-candidates nil
3768 "Marked candadates. List of (source . real) pair.")
3769 (defun anything-toggle-visible-mark ()
3770 (interactive)
3771 (with-anything-window
3772 (let ((display (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
3773 (source (anything-get-current-source))
3774 (selection (anything-get-selection)))
3775 (anything-aif (loop for o in anything-visible-mark-overlays
3776 when (equal (line-beginning-position) (overlay-start o))
3777 do (return o))
3778 ;; delete
3779 (progn
3780 (setq anything-c-marked-candidate-list
3781 (remove
3782 display anything-c-marked-candidate-list))
3783 (setq anything-marked-candidates
3784 (remove
3785 (cons source selection)
3786 anything-marked-candidates))
3787 (delete-overlay it)
3788 (setq anything-visible-mark-overlays (delq it anything-visible-mark-overlays)))
3789 (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
3790 (overlay-put o 'face anything-visible-mark-face)
3791 (overlay-put o 'source (assoc-default 'name source))
3792 (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3793 (add-to-list 'anything-visible-mark-overlays o)
3794 (push display anything-c-marked-candidate-list)
3795 (push (cons source selection) anything-marked-candidates)))
3796 (anything-next-line))))
3798 (defun anything-display-all-visible-marks ()
3799 "Show all `anything' visible marks strings."
3800 (interactive)
3801 (lexical-let ((overlays (reverse anything-visible-mark-overlays)))
3802 (anything-run-after-quit
3803 (lambda ()
3804 (with-output-to-temp-buffer "*anything visible marks*"
3805 (dolist (o overlays) (princ (overlay-get o 'string))))))))
3807 (defun anything-marked-candidates ()
3808 "Marked candidates (real value) of current source if any,
3809 otherwise 1-element list of current selection.
3811 It is analogous to `dired-get-marked-files'."
3812 (if anything-marked-candidates
3813 (loop with current-src = (anything-get-current-source)
3814 for (source . real) in (reverse anything-marked-candidates)
3815 when (eq current-src source)
3816 collect real)
3817 (list (anything-get-selection))))
3819 (defun anything-reset-marked-candidates ()
3820 (setq anything-c-marked-candidate-list nil)
3821 (setq anything-marked-candidates nil))
3823 (add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
3824 (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3826 (defun anything-revive-visible-mark ()
3827 (interactive)
3828 (with-current-buffer anything-buffer
3829 (loop for o in anything-visible-mark-overlays do
3830 (goto-char (point-min))
3831 (let (moved)
3832 (while (and (not moved)
3833 (search-forward (overlay-get o 'string) nil t))
3834 (forward-line -1)
3835 (when (and (save-excursion
3836 (goto-char (anything-get-previous-header-pos))
3837 (equal (overlay-get o 'source)
3838 (buffer-substring (line-beginning-position) (line-end-position))))
3839 (not (find-if (lambda (x)
3840 (memq x anything-visible-mark-overlays))
3841 (overlays-at (point)))))
3842 (move-overlay o (line-beginning-position) (1+ (line-end-position)))
3843 (setq moved t))
3844 (forward-line 1))))))
3845 (add-hook 'anything-update-hook 'anything-revive-visible-mark)
3847 (defun anything-next-visible-mark (&optional prev)
3848 (interactive)
3849 (with-anything-window
3850 (block 'exit
3851 (setq anything-visible-mark-overlays
3852 (sort* anything-visible-mark-overlays
3853 '< :key 'overlay-start))
3854 (let ((i (position-if (lambda (o) (< (point) (overlay-start o)))
3855 anything-visible-mark-overlays)))
3856 (when prev
3857 (unless anything-visible-mark-overlays (return-from 'exit nil))
3858 (if (not i) (setq i (length anything-visible-mark-overlays)))
3859 (if (equal (point) (overlay-start (nth (1- i) anything-visible-mark-overlays)))
3860 (setq i (1- i))))
3861 (when i
3862 (goto-char (overlay-start (nth (if prev (1- i) i) anything-visible-mark-overlays)))
3863 (anything-mark-current-line))))))
3865 (defun anything-prev-visible-mark ()
3866 (interactive)
3867 (anything-next-visible-mark t))
3869 ;; (@* "Utility: `find-file' integration")
3870 (defun anything-quit-and-find-file ()
3871 "Drop into `find-file' from `anything' like `iswitchb-find-file'.
3872 If current selection is a buffer or a file, `find-file' from its directory."
3873 (interactive)
3874 (anything-run-after-quit
3875 (lambda (f)
3876 (if (file-exists-p f)
3877 (let ((default-directory (file-name-directory f)))
3878 (call-interactively 'find-file))
3879 (call-interactively 'find-file)))
3880 (anything-aif (get-buffer (anything-get-selection))
3881 (buffer-file-name it)
3882 (expand-file-name (anything-get-selection)))))
3884 ;; (@* "Utility: Selection Paste")
3885 (defun anything-yank-selection ()
3886 "Set minibuffer contents to current selection."
3887 (interactive)
3888 (delete-minibuffer-contents)
3889 (insert (anything-get-selection nil t)))
3891 (defun anything-kill-selection-and-quit ()
3892 "Store current selection to kill ring.
3893 You can paste it by typing C-y."
3894 (interactive)
3895 (anything-run-after-quit
3896 (lambda (sel)
3897 (kill-new sel)
3898 (message "Killed: %s" sel))
3899 (anything-get-selection nil t)))
3902 ;; (@* "Utility: Automatical execution of persistent-action")
3903 (add-to-list 'minor-mode-alist '(anything-follow-mode " AFollow"))
3904 (defun anything-follow-mode ()
3905 "If this mode is on, persistent action is executed everytime the cursor is moved."
3906 (interactive)
3907 (with-current-buffer anything-buffer
3908 (setq anything-follow-mode (not anything-follow-mode))
3909 (message "anything-follow-mode is %s"
3910 (if anything-follow-mode "enabled" "disabled"))))
3912 (defun anything-follow-execute-persistent-action-maybe ()
3913 "Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
3914 (and (buffer-local-value 'anything-follow-mode
3915 (get-buffer-create anything-buffer))
3916 (sit-for anything-input-idle-delay)
3917 (anything-window)
3918 (anything-get-selection)
3919 (save-excursion
3920 (anything-execute-persistent-action))))
3922 ;; (@* "Utility: Migrate `anything-sources' to my-anything command")
3923 (defun anything-migrate-sources ()
3924 "Help to migrate to new `anything' way."
3925 (interactive)
3926 (with-current-buffer (get-buffer-create "*anything migrate*")
3927 (erase-buffer)
3928 (insert (format "\
3929 Setting `anything-sources' directly is not good because
3930 `anything' is not for one command. For now, interactive use of
3931 `anything' (M-x anything) is only for demonstration purpose.
3932 So you should define commands calling `anything'.
3933 I help you to migrate to the new way.
3935 The code below is automatically generated from current
3936 `anything-sources' value. You can use the `my-anything' command
3937 now!
3939 Copy and paste it to your .emacs. Then substitute `my-anything'
3940 for `anything' bindings in all `define-key', `local-set-key' and
3941 `global-set-key' calls.
3943 \(defun my-anything ()
3944 \"Anything command for you.
3946 It is automatically generated by `anything-migrate-sources'.\"
3947 (interactive)
3948 (anything-other-buffer
3950 \"*my-anything*\"))
3951 " anything-sources))
3952 (eval-last-sexp nil)
3953 (substitute-key-definition 'anything 'my-anything global-map)
3954 (pop-to-buffer (current-buffer))))
3956 ;; (@* "Utility: Incremental search within results (unmaintained)")
3958 (defvar anything-isearch-original-global-map nil
3959 "Original global map before Anything isearch is started.")
3961 (defvar anything-isearch-original-message-timeout nil
3962 "Original message timeout before Anything isearch is started.")
3964 (defvar anything-isearch-pattern nil
3965 "The current isearch pattern.")
3967 (defvar anything-isearch-message-suffix ""
3968 "Message suffix indicating the current state of the search.")
3970 (defvar anything-isearch-original-point nil
3971 "Original position of point before isearch is started.")
3973 (defvar anything-isearch-original-window nil
3974 "Original selected window before isearch is started.")
3976 (defvar anything-isearch-original-cursor-in-non-selected-windows nil
3977 "Original value of cursor-in-non-selected-windows before isearch is started.")
3979 (defvar anything-isearch-original-post-command-hook nil
3980 "Original value of post-command-hook before isearch is started.")
3982 (defvar anything-isearch-match-positions nil
3983 "Stack of positions of matches or non-matches.
3985 It's a list of plists with two properties: `event', the last user
3986 event, `start', the start position of the current match, and
3987 `pos', the position of point after that event.
3989 The value of `event' can be the following symbols: `char' if a
3990 character was typed, `error' if a non-matching character was
3991 typed, `search' if a forward search had to be done after a
3992 character, and `search-again' if a search was done for the next
3993 occurrence of the current pattern.")
3995 (defvar anything-isearch-match-start nil
3996 "Start position of the current match.")
3999 (defun anything-isearch ()
4000 "Start incremental search within results. (UNMAINTAINED)"
4001 (interactive)
4002 (if (zerop (buffer-size (get-buffer (anything-buffer-get))))
4003 (message "There are no results.")
4005 (setq anything-isearch-original-message-timeout minibuffer-message-timeout)
4006 (setq minibuffer-message-timeout nil)
4008 (setq anything-isearch-original-global-map global-map)
4010 (condition-case nil
4011 (progn
4012 (setq anything-isearch-original-window (selected-window))
4013 (select-window (anything-window))
4014 (setq cursor-type t)
4016 (setq anything-isearch-original-post-command-hook
4017 (default-value 'post-command-hook))
4018 (setq-default post-command-hook nil)
4019 (add-hook 'post-command-hook 'anything-isearch-post-command)
4021 (use-global-map anything-isearch-map)
4022 (setq overriding-terminal-local-map anything-isearch-map)
4024 (setq anything-isearch-pattern "")
4026 (setq anything-isearch-original-cursor-in-non-selected-windows
4027 cursor-in-non-selected-windows)
4028 (setq cursor-in-non-selected-windows nil)
4030 (setq anything-isearch-original-point (point-marker))
4031 (goto-char (point-min))
4032 (forward-line)
4033 (anything-mark-current-line)
4035 (setq anything-isearch-match-positions nil)
4036 (setq anything-isearch-match-start (point-marker))
4038 (if anything-isearch-overlay
4039 ;; make sure the overlay belongs to the anything buffer
4040 (move-overlay anything-isearch-overlay (point-min) (point-min)
4041 (get-buffer (anything-buffer-get)))
4043 (setq anything-isearch-overlay (make-overlay (point-min) (point-min)))
4044 (overlay-put anything-isearch-overlay 'face anything-isearch-match-face))
4046 (setq anything-isearch-message-suffix
4047 (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))
4049 (error (anything-isearch-cleanup)))))
4052 (defun anything-isearch-post-command ()
4053 "Print the current pattern after every command."
4054 (anything-isearch-message)
4055 (when (anything-window)
4056 (with-anything-window
4057 (move-overlay anything-isearch-overlay anything-isearch-match-start (point)
4058 (get-buffer (anything-buffer-get))))))
4061 (defun anything-isearch-printing-char ()
4062 "Add printing char to the pattern."
4063 (interactive)
4064 (let ((char (char-to-string last-command-event)))
4065 (setq anything-isearch-pattern (concat anything-isearch-pattern char))
4067 (with-anything-window
4068 (if (looking-at char)
4069 (progn
4070 (push (list 'event 'char
4071 'start anything-isearch-match-start
4072 'pos (point-marker))
4073 anything-isearch-match-positions)
4074 (forward-char))
4076 (let ((start (point)))
4077 (while (and (re-search-forward anything-isearch-pattern nil t)
4078 (anything-pos-header-line-p)))
4079 (if (or (anything-pos-header-line-p)
4080 (eq start (point)))
4081 (progn
4082 (goto-char start)
4083 (push (list 'event 'error
4084 'start anything-isearch-match-start
4085 'pos (point-marker))
4086 anything-isearch-match-positions))
4088 (push (list 'event 'search
4089 'start anything-isearch-match-start
4090 'pos (copy-marker start))
4091 anything-isearch-match-positions)
4092 (setq anything-isearch-match-start (copy-marker (match-beginning 0))))))
4094 (anything-mark-current-line))))
4097 (defun anything-isearch-again ()
4098 "Search again for the current pattern"
4099 (interactive)
4100 (if (equal anything-isearch-pattern "")
4101 (setq anything-isearch-message-suffix "no pattern yet")
4103 (with-anything-window
4104 (let ((start (point)))
4105 (while (and (re-search-forward anything-isearch-pattern nil t)
4106 (anything-pos-header-line-p)))
4107 (if (or (anything-pos-header-line-p)
4108 (eq start (point)))
4109 (progn
4110 (goto-char start)
4111 (unless (eq 'error (plist-get (car anything-isearch-match-positions)
4112 'event))
4113 (setq anything-isearch-message-suffix "no more matches")))
4115 (push (list 'event 'search-again
4116 'start anything-isearch-match-start
4117 'pos (copy-marker start))
4118 anything-isearch-match-positions)
4119 (setq anything-isearch-match-start (copy-marker (match-beginning 0)))
4121 (anything-mark-current-line))))))
4124 (defun anything-isearch-delete ()
4125 "Undo last event."
4126 (interactive)
4127 (unless (equal anything-isearch-pattern "")
4128 (let ((last (pop anything-isearch-match-positions)))
4129 (unless (eq 'search-again (plist-get last 'event))
4130 (setq anything-isearch-pattern
4131 (substring anything-isearch-pattern 0 -1)))
4133 (with-anything-window
4134 (goto-char (plist-get last 'pos))
4135 (setq anything-isearch-match-start (plist-get last 'start))
4136 (anything-mark-current-line)))))
4139 (defun anything-isearch-default-action ()
4140 "Execute the default action for the selected candidate."
4141 (interactive)
4142 (anything-isearch-cleanup)
4143 (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))
4146 (defun anything-isearch-select-action ()
4147 "Choose an action for the selected candidate."
4148 (interactive)
4149 (anything-isearch-cleanup)
4150 (with-anything-window
4151 (anything-select-action)))
4154 (defun anything-isearch-cancel ()
4155 "Cancel Anything isearch."
4156 (interactive)
4157 (anything-isearch-cleanup)
4158 (when (anything-window)
4159 (with-anything-window
4160 (goto-char anything-isearch-original-point)
4161 (anything-mark-current-line))))
4164 (defun anything-isearch-cleanup ()
4165 "Clean up the mess."
4166 (setq minibuffer-message-timeout anything-isearch-original-message-timeout)
4167 (with-current-buffer (anything-buffer-get)
4168 (setq overriding-terminal-local-map nil)
4169 (setq cursor-type nil)
4170 (setq cursor-in-non-selected-windows
4171 anything-isearch-original-cursor-in-non-selected-windows))
4172 (when anything-isearch-original-window
4173 (select-window anything-isearch-original-window))
4175 (use-global-map anything-isearch-original-global-map)
4176 (setq-default post-command-hook anything-isearch-original-post-command-hook)
4177 (when (overlayp anything-isearch-overlay)
4178 (delete-overlay anything-isearch-overlay)))
4181 (defun anything-isearch-message ()
4182 "Print prompt."
4183 (if (and (equal anything-isearch-message-suffix "")
4184 (eq (plist-get (car anything-isearch-match-positions) 'event)
4185 'error))
4186 (setq anything-isearch-message-suffix "failing"))
4188 (unless (equal anything-isearch-message-suffix "")
4189 (setq anything-isearch-message-suffix
4190 (concat " [" anything-isearch-message-suffix "]")))
4192 (message (concat "Search within results: "
4193 anything-isearch-pattern
4194 anything-isearch-message-suffix))
4196 (setq anything-isearch-message-suffix ""))
4199 ;; (@* "Utility: Iswitchb integration (unmaintained)")
4201 (defvar anything-iswitchb-candidate-selected nil
4202 "Indicates whether an anything candidate is selected from iswitchb.")
4204 (defvar anything-iswitchb-frame-configuration nil
4205 "Saved frame configuration, before anything buffer was displayed.")
4207 (defvar anything-iswitchb-saved-keys nil
4208 "The original in iswitchb before binding anything keys.")
4211 (defun anything-iswitchb-setup ()
4212 "Integrate anything completion into iswitchb (UNMAINTAINED).
4214 If the user is idle for `anything-iswitchb-idle-delay' seconds
4215 after typing something into iswitchb then anything candidates are
4216 shown for the current iswitchb input.
4218 ESC cancels anything completion and returns to normal iswitchb.
4220 Some key bindings in `anything-map' are modified.
4221 See also `anything-iswitchb-setup-keys'."
4222 (interactive)
4224 (require 'iswitchb)
4226 ;; disable timid completion during iswitchb
4227 (put 'iswitchb-buffer 'timid-completion 'disabled)
4228 (add-hook 'minibuffer-setup-hook 'anything-iswitchb-minibuffer-setup)
4230 (defadvice iswitchb-visit-buffer
4231 (around anything-iswitchb-visit-buffer activate)
4232 (if anything-iswitchb-candidate-selected
4233 (anything-execute-selection-action)
4234 ad-do-it))
4236 (defadvice iswitchb-possible-new-buffer
4237 (around anything-iswitchb-possible-new-buffer activate)
4238 (if anything-iswitchb-candidate-selected
4239 (anything-execute-selection-action)
4240 ad-do-it))
4241 (anything-iswitchb-setup-keys)
4242 (message "Iswitchb integration is activated."))
4244 (defun anything-iswitchb-setup-keys ()
4245 "Modify `anything-map' for anything-iswitchb users.
4247 C-p is used instead of M-p, because anything uses ESC
4248 (currently hardcoded) for `anything-iswitchb-cancel-anything' and
4249 Emacs handles ESC and Meta as synonyms, so ESC overrides
4250 other commands with Meta prefix.
4252 Note that iswitchb uses M-p and M-n by default for history
4253 navigation, so you should bind C-p and C-n in
4254 `iswitchb-mode-map' if you use the history keys and don't want
4255 to use different keys for iswitchb while anything is not yet
4256 kicked in. These keys are not bound automatically by anything
4257 in `iswitchb-mode-map' because they (C-n at least) already have
4258 a standard iswitchb binding which you might be accustomed to.
4260 Binding M-s is used instead of C-s, because C-s has a binding in
4261 iswitchb. You can rebind it AFTER `anything-iswitchb-setup'.
4263 Unbind C-r to prevent problems during anything-isearch."
4264 (define-key anything-map (kbd "C-s") nil)
4265 (define-key anything-map (kbd "M-p") nil)
4266 (define-key anything-map (kbd "M-n") nil)
4267 (define-key anything-map (kbd "M-v") nil)
4268 (define-key anything-map (kbd "C-v") nil)
4269 (define-key anything-map (kbd "C-p") 'anything-previous-history-element)
4270 (define-key anything-map (kbd "C-n") 'anything-next-history-element)
4271 (define-key anything-map (kbd "M-s") nil)
4272 (define-key anything-map (kbd "M-s") 'anything-isearch)
4273 (define-key anything-map (kbd "C-r") nil))
4275 (defun anything-iswitchb-minibuffer-setup ()
4276 (when (eq this-command 'iswitchb-buffer)
4277 (add-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
4279 (setq anything-iswitchb-frame-configuration nil)
4280 (setq anything-iswitchb-candidate-selected nil)
4281 (add-hook 'anything-update-hook 'anything-iswitchb-handle-update)
4283 (anything-initialize)
4285 (add-hook 'post-command-hook 'anything-iswitchb-check-input)))
4288 (defun anything-iswitchb-minibuffer-exit ()
4289 (remove-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
4290 (remove-hook 'post-command-hook 'anything-iswitchb-check-input)
4291 (remove-hook 'anything-update-hook 'anything-iswitchb-handle-update)
4293 (anything-cleanup)
4295 (when anything-iswitchb-frame-configuration
4296 (anything-set-frame/window-configuration anything-iswitchb-frame-configuration)
4297 (setq anything-iswitchb-frame-configuration nil)))
4300 (defun anything-iswitchb-check-input ()
4301 "Extract iswitchb input and check if it needs to be handled."
4302 (declare (special iswitchb-text))
4303 (if (or anything-iswitchb-frame-configuration
4304 (sit-for anything-iswitchb-idle-delay))
4305 (anything-check-new-input iswitchb-text)))
4308 (defun anything-iswitchb-handle-update ()
4309 "Pop up the anything buffer if it's not empty and it's not
4310 shown yet and bind anything commands in iswitchb."
4311 (unless (or (equal (buffer-size (get-buffer anything-buffer)) 0)
4312 anything-iswitchb-frame-configuration)
4313 (setq anything-iswitchb-frame-configuration (anything-current-frame/window-configuration))
4315 (save-selected-window
4316 (if (not anything-samewindow)
4317 (pop-to-buffer anything-buffer)
4319 (select-window (get-lru-window))
4320 (switch-to-buffer anything-buffer)))
4322 (with-current-buffer (window-buffer (active-minibuffer-window))
4323 (let* ((anything-prefix "anything-")
4324 (prefix-length (length anything-prefix))
4325 (commands
4326 (delete-dups
4327 (remove-if 'null
4328 (mapcar
4329 (lambda (binding)
4330 (let ((command (cdr binding)))
4331 (when (and (symbolp command)
4332 (eq (compare-strings
4333 anything-prefix
4334 0 prefix-length
4335 (symbol-name command)
4336 0 prefix-length)
4338 command)))
4339 (cdr anything-map)))))
4340 (bindings (mapcar (lambda (command)
4341 (cons command
4342 (where-is-internal command anything-map)))
4343 commands)))
4345 (push (list 'anything-iswitchb-cancel-anything (kbd "<ESC>"))
4346 bindings)
4348 (setq anything-iswitchb-saved-keys nil)
4350 (let* ((iswitchb-prefix "iswitchb-")
4351 (prefix-length (length iswitchb-prefix)))
4352 (dolist (binding bindings)
4353 (dolist (key (cdr binding))
4354 (let ((old-command (lookup-key (current-local-map) key)))
4355 (unless (and anything-iswitchb-dont-touch-iswithcb-keys
4356 (symbolp old-command)
4357 (eq (compare-strings iswitchb-prefix
4358 0 prefix-length
4359 (symbol-name old-command)
4360 0 prefix-length)
4362 (push (cons key old-command)
4363 anything-iswitchb-saved-keys)
4364 (define-key (current-local-map) key (car binding)))))))))))
4367 (defun anything-iswitchb-cancel-anything ()
4368 "Cancel anything completion and return to standard iswitchb."
4369 (interactive)
4370 (save-excursion
4371 (dolist (binding anything-iswitchb-saved-keys)
4372 (define-key (current-local-map) (car binding) (cdr binding)))
4373 (anything-iswitchb-minibuffer-exit)))
4375 ;; (@* "Compatibility")
4377 ;; Copied assoc-default from XEmacs version 21.5.12
4378 (unless (fboundp 'assoc-default)
4379 (defun assoc-default (key alist &optional test default)
4380 "Find object KEY in a pseudo-alist ALIST.
4381 ALIST is a list of conses or objects. Each element (or the element's car,
4382 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
4383 If that is non-nil, the element matches;
4384 then `assoc-default' returns the element's cdr, if it is a cons,
4385 or DEFAULT if the element is not a cons.
4387 If no element matches, the value is nil.
4388 If TEST is omitted or nil, `equal' is used."
4389 (let (found (tail alist) value)
4390 (while (and tail (not found))
4391 (let ((elt (car tail)))
4392 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
4393 (setq found t value (if (consp elt) (cdr elt) default))))
4394 (setq tail (cdr tail)))
4395 value)))
4397 ;; Function not available in XEmacs,
4398 (unless (fboundp 'minibuffer-contents)
4399 (defun minibuffer-contents ()
4400 "Return the user input in a minbuffer as a string.
4401 The current buffer must be a minibuffer."
4402 (field-string (point-max)))
4404 (defun delete-minibuffer-contents ()
4405 "Delete all user input in a minibuffer.
4406 The current buffer must be a minibuffer."
4407 (delete-field (point-max))))
4409 ;; Function not available in older Emacs (<= 22.1).
4410 (unless (fboundp 'buffer-chars-modified-tick)
4411 (defun buffer-chars-modified-tick (&optional buffer)
4412 "Return BUFFER's character-change tick counter.
4413 Each buffer has a character-change tick counter, which is set to the
4414 value of the buffer's tick counter (see `buffer-modified-tick'), each
4415 time text in that buffer is inserted or deleted. By comparing the
4416 values returned by two individual calls of `buffer-chars-modified-tick',
4417 you can tell whether a character change occurred in that buffer in
4418 between these calls. No argument or nil as argument means use current
4419 buffer as BUFFER."
4420 (with-current-buffer (or buffer (current-buffer))
4421 (if (listp buffer-undo-list)
4422 (length buffer-undo-list)
4423 (buffer-modified-tick)))))
4425 ;;(@* "Attribute Documentation")
4426 (defun anything-describe-anything-attribute (anything-attribute)
4427 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol)."
4428 (interactive (list (intern
4429 (completing-read
4430 "Describe anything attribute: "
4431 (mapcar 'symbol-name anything-additional-attributes)))))
4432 (with-output-to-temp-buffer "*Help*"
4433 (princ (get anything-attribute 'anything-attrdoc))))
4435 (anything-document-attribute 'name "mandatory"
4436 " The name of the source. It is also the heading which appears
4437 above the list of matches from the source. Must be unique. ")
4438 (anything-document-attribute 'header-name "optional"
4439 " A function returning the display string of the header. Its
4440 argument is the name of the source. This attribute is useful to
4441 add an additional information with the source name. ")
4442 (anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
4443 " Specifies how to retrieve candidates from the source. It can
4444 either be a variable name, a function called with no parameters
4445 or the actual list of candidates.
4447 The list must be a list whose members are strings, symbols
4448 or (DISPLAY . REAL) pairs.
4450 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
4451 in the Anything buffer, but the REAL one is used as action
4452 argument when the candidate is selected. This allows a more
4453 readable presentation for candidates which would otherwise be,
4454 for example, too long or have a common part shared with other
4455 candidates which can be safely replaced with an abbreviated
4456 string for display purposes.
4458 Note that if the (DISPLAY . REAL) form is used then pattern
4459 matching is done on the displayed string, not on the real
4460 value.
4462 If the candidates have to be retrieved asynchronously (for
4463 example, by an external command which takes a while to run)
4464 then the function should start the external command
4465 asynchronously and return the associated process object.
4466 Anything will take care of managing the process (receiving the
4467 output from it, killing it if necessary, etc.). The process
4468 should return candidates matching the current pattern (see
4469 variable `anything-pattern'.)
4471 Note that currently results from asynchronous sources appear
4472 last in the anything buffer regardless of their position in
4473 `anything-sources'. ")
4474 (anything-document-attribute 'action "mandatory if type attribute is not provided"
4475 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
4476 FUNCTION is called with one parameter: the selected candidate.
4478 An action other than the default can be chosen from this list
4479 of actions for the currently selected candidate (by default
4480 with TAB). The DISPLAY string is shown in the completions
4481 buffer and the FUNCTION is invoked when an action is
4482 selected. The first action of the list is the default. ")
4483 (anything-document-attribute 'type "optional if action attribute is provided"
4484 " Indicates the type of the items the source returns.
4486 Merge attributes not specified in the source itself from
4487 `anything-type-attributes'.
4489 This attribute is implemented by plug-in. ")
4490 (anything-document-attribute 'init "optional"
4491 " Function called with no parameters when anything is started. It
4492 is useful for collecting current state information which can be
4493 used to create the list of candidates later.
4495 For example, if a source needs to work with the current
4496 directory then it can store its value here, because later
4497 anything does its job in the minibuffer and in the
4498 `anything-buffer' and the current directory can be different
4499 there. ")
4500 (anything-document-attribute 'delayed-init "optional"
4501 " Function called with no parameters before candidate function is
4502 called. It is similar with `init' attribute, but its
4503 evaluation is deferred. It is useful to combine with ")
4504 (anything-document-attribute 'match "optional"
4505 " List of functions called with one parameter: a candidate. The
4506 function should return non-nil if the candidate matches the
4507 current pattern (see variable `anything-pattern').
4509 This attribute allows the source to override the default
4510 pattern matching based on `string-match'. It can be used, for
4511 example, to implement a source for file names and do the
4512 pattern matching on the basename of files, since it's more
4513 likely one is typing part of the basename when searching for a
4514 file, instead of some string anywhere else in its path.
4516 If the list contains more than one function then the list of
4517 matching candidates from the source is constructed by appending
4518 the results after invoking the first function on all the
4519 potential candidates, then the next function, and so on. The
4520 matching candidates supplied by the first function appear first
4521 in the list of results and then results from the other
4522 functions, respectively.
4524 This attribute has no effect for asynchronous sources (see
4525 attribute `candidates'), since they perform pattern matching
4526 themselves. ")
4527 (anything-document-attribute 'candidate-transformer "optional"
4528 " It's a function or a list of functions called with one argument
4529 when the completion list from the source is built. The argument
4530 is the list of candidates retrieved from the source. The
4531 function should return a transformed list of candidates which
4532 will be used for the actual completion. If it is a list of
4533 functions, it calls each function sequentially.
4535 This can be used to transform or remove items from the list of
4536 candidates.
4538 Note that `candidates' is run already, so the given transformer
4539 function should also be able to handle candidates with (DISPLAY
4540 . REAL) format. ")
4541 (anything-document-attribute 'filtered-candidate-transformer "optional"
4542 " It has the same format as `candidate-transformer', except the
4543 function is called with two parameters: the candidate list and
4544 the source.
4546 This transformer is run on the candidate list which is already
4547 filtered by the current pattern. While `candidate-transformer'
4548 is run only once, it is run every time the input pattern is
4549 changed.
4551 It can be used to transform the candidate list dynamically, for
4552 example, based on the current pattern.
4554 In some cases it may also be more efficent to perform candidate
4555 transformation here, instead of with `candidate-transformer'
4556 even if this transformation is done every time the pattern is
4557 changed. For example, if a candidate set is very large then
4558 `candidate-transformer' transforms every candidate while only
4559 some of them will actually be dislpayed due to the limit
4560 imposed by `anything-candidate-number-limit'.
4562 Note that `candidates' and `candidate-transformer' is run
4563 already, so the given transformer function should also be able
4564 to handle candidates with (DISPLAY . REAL) format.
4566 This option has no effect for asynchronous sources. (Not yet,
4567 at least. ")
4568 (anything-document-attribute 'action-transformer "optional"
4569 " It's a function or a list of functions called with two
4570 arguments when the action list from the source is
4571 assembled. The first argument is the list of actions, the
4572 second is the current selection. If it is a list of functions,
4573 it calls each function sequentially.
4575 The function should return a transformed action list.
4577 This can be used to customize the list of actions based on the
4578 currently selected candidate. ")
4579 (anything-document-attribute 'pattern-transformer "optional"
4580 " It's a function or a list of functions called with one argument
4581 before computing matches. Its argument is `anything-pattern'.
4582 Functions should return transformed `anything-pattern'.
4584 It is useful to change interpretation of `anything-pattern'. ")
4585 (anything-document-attribute 'delayed "optional"
4586 " Candidates from the source are shown only if the user stops
4587 typing and is idle for `anything-idle-delay' seconds. ")
4588 (anything-document-attribute 'volatile "optional"
4589 " Indicates the source assembles the candidate list dynamically,
4590 so it shouldn't be cached within a single Anything
4591 invocation. It is only applicable to synchronous sources,
4592 because asynchronous sources are not cached. ")
4593 (anything-document-attribute 'requires-pattern "optional"
4594 " If present matches from the source are shown only if the
4595 pattern is not empty. Optionally, it can have an integer
4596 parameter specifying the required length of input which is
4597 useful in case of sources with lots of candidates. ")
4598 (anything-document-attribute 'persistent-action "optional"
4599 " Function called with one parameter; the selected candidate.
4601 An action performed by `anything-execute-persistent-action'.
4602 If none, use the default action. ")
4603 (anything-document-attribute 'candidates-in-buffer "optional"
4604 " Shortcut attribute for making and narrowing candidates using
4605 buffers. This newly-introduced attribute prevents us from
4606 forgetting to add volatile and match attributes.
4608 See docstring of `anything-candidates-in-buffer'.
4610 (candidates-in-buffer) is equivalent of three attributes:
4611 (candidates . anything-candidates-in-buffer)
4612 (volatile)
4613 (match identity)
4615 (candidates-in-buffer . candidates-function) is equivalent of:
4616 (candidates . candidates-function)
4617 (volatile)
4618 (match identity)
4620 This attribute is implemented by plug-in. ")
4621 (anything-document-attribute 'search "optional"
4622 " List of functions like `re-search-forward' or `search-forward'.
4623 Buffer search function used by `anything-candidates-in-buffer'.
4624 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4625 This attribute is meant to be used with
4626 (candidates . anything-candidates-in-buffer) or
4627 (candidates-in-buffer) in short. ")
4628 (anything-document-attribute 'search-from-end "optional"
4629 " Make `anything-candidates-in-buffer' search from the end of buffer.
4630 If this attribute is specified, `anything-candidates-in-buffer' uses
4631 `re-search-backward' instead. ")
4632 (anything-document-attribute 'get-line "optional"
4633 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4634 This function converts point of line-beginning and point of line-end,
4635 which represents a candidate computed by `anything-candidates-in-buffer'.
4636 By default, `anything-candidates-in-buffer' uses
4637 `buffer-substring-no-properties'. ")
4638 (anything-document-attribute 'display-to-real "optional"
4639 " Function called with one parameter; the selected candidate.
4641 The function transforms the selected candidate, and the result
4642 is passed to the action function. The display-to-real
4643 attribute provides another way to pass other string than one
4644 shown in Anything buffer.
4646 Traditionally, it is possible to make candidates,
4647 candidate-transformer or filtered-candidate-transformer
4648 function return a list with (DISPLAY . REAL) pairs. But if REAL
4649 can be generated from DISPLAY, display-to-real is more
4650 convenient and faster. ")
4651 (anything-document-attribute 'real-to-display "optional"
4652 " Function called with one parameter; the selected candidate.
4654 The inverse of display-to-real attribute.
4656 The function transforms the selected candidate, which is passed
4657 to the action function, for display. The real-to-display
4658 attribute provides the other way to pass other string than one
4659 shown in Anything buffer.
4661 Traditionally, it is possible to make candidates,
4662 candidate-transformer or filtered-candidate-transformer
4663 function return a list with (DISPLAY . REAL) pairs. But if
4664 DISPLAY can be generated from REAL, real-to-display is more
4665 convenient.
4667 Note that DISPLAY parts returned from candidates /
4668 candidate-transformer are IGNORED as the name `display-to-real'
4669 says. ")
4670 (anything-document-attribute 'cleanup "optional"
4671 " Function called with no parameters when *anything* buffer is closed. It
4672 is useful for killing unneeded candidates buffer.
4674 Note that the function is executed BEFORE performing action. ")
4675 (anything-document-attribute 'candidate-number-limit "optional"
4676 " Override `anything-candidate-number-limit' only for this source. ")
4677 (anything-document-attribute 'accept-empty "optional"
4678 " Pass empty string \"\" to action function. ")
4679 (anything-document-attribute 'disable-shortcuts "optional"
4680 " Disable `anything-enable-shortcuts' in current `anything' session.
4682 This attribute is implemented by plug-in. ")
4683 (anything-document-attribute 'dummy "optional"
4684 " Set `anything-pattern' to candidate. If this attribute is
4685 specified, The candidates attribute is ignored.
4687 This attribute is implemented by plug-in.
4688 This plug-in implies disable-shortcuts plug-in. ")
4689 (anything-document-attribute 'multiline "optional"
4690 " Enable to selection multiline candidates. ")
4691 (anything-document-attribute 'update "optional"
4692 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4693 (anything-document-attribute 'mode-line "optional"
4694 " source local `anything-mode-line-string'. (included in `mode-line-format')
4695 It accepts also variable/function name. ")
4696 (anything-document-attribute 'header-line "optional"
4697 " source local `header-line-format'.
4698 It accepts also variable/function name. ")
4699 (anything-document-attribute 'resume "optional" " Function called with no parameters when `anything-resume' is started.")
4701 ;; (@* "Bug Report")
4702 (defvar anything-maintainer-mail-address
4703 (concat "rubiki" "tch@ru" "by-lang.org"))
4704 (defvar anything-bug-report-salutation
4705 "Describe bug below, using a precise recipe.
4707 When I executed M-x ...
4709 How to send a bug report:
4710 1) Be sure to use the LATEST version of anything.el.
4711 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
4712 3) Use Lisp version instead of compiled one: (load \"anything.el\")
4713 4) If you got an error, please paste *Backtrace* buffer.
4714 5) Type C-c C-c to send.
4715 # If you are a Japanese, please write in Japanese:-)")
4716 (defvar anything-no-dump-variables
4717 '(anything-candidate-buffer-alist
4718 anything-digit-overlays
4719 anything-help-message
4722 (defun anything-dumped-variables-in-bug-report ()
4723 (let ((hash (make-hash-table)))
4724 (loop for var in (apropos-internal "anything-" 'boundp)
4725 for vname = (symbol-name var)
4726 unless (or (string-match "-map$" vname)
4727 (string-match "^anything-c-source-" vname)
4728 (string-match "-hash$" vname)
4729 (string-match "-face$" vname)
4730 (memq var anything-no-dump-variables))
4731 collect var)))
4733 (defun anything-send-bug-report ()
4734 (interactive)
4735 (reporter-submit-bug-report
4736 anything-maintainer-mail-address
4737 "anything.el"
4738 (anything-dumped-variables-in-bug-report)
4739 nil nil
4740 anything-bug-report-salutation))
4742 (defun anything-send-bug-report-from-anything ()
4743 (interactive))
4745 ;; (@* "Unit Tests")
4747 (defun* anything-test-candidates (sources &optional (input "") (compile-source-functions anything-compile-source-functions-default))
4748 "Test helper function for anything.
4749 Given pseudo `anything-sources' and `anything-pattern', returns list like
4750 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4751 (\"source name2\" (\"candidate3\" \"candidate4\")))
4753 (let ((anything-test-mode t)
4754 anything-enable-shortcuts
4755 anything-candidate-cache
4756 (anything-sources (anything-normalize-sources sources))
4757 (anything-compile-source-functions compile-source-functions)
4758 anything-before-initialize-hook
4759 anything-after-initialize-hook
4760 anything-update-hook
4761 anything-test-candidate-list)
4762 (get-buffer-create anything-buffer)
4764 (anything-initialize)
4765 (setq anything-input input anything-pattern input)
4766 (anything-update)
4767 ;; test-mode spec: select 1st candidate!
4768 (with-current-buffer anything-buffer
4769 (forward-line 1)
4770 (anything-mark-current-line))
4771 (prog1
4772 anything-test-candidate-list
4773 (anything-cleanup))))
4775 (defmacro anything-test-update (sources pattern)
4776 "Test helper macro for anything. It is meant for testing *anything* buffer contents."
4777 `(progn (stub anything-get-sources => ,sources)
4778 (stub run-hooks => nil)
4779 (stub anything-maybe-fit-frame => nil)
4780 (stub run-with-idle-timer => nil)
4781 (let (anything-test-mode (anything-pattern ,pattern))
4782 (anything-update))))
4784 ;;;; unit test
4785 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4786 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
4787 (dont-compile
4788 (when (fboundp 'expectations)
4789 (expectations
4790 (desc "anything-current-buffer")
4791 (expect "__a_buffer"
4792 (with-current-buffer (get-buffer-create "__a_buffer")
4793 (anything-test-candidates '(((name . "FOO"))) "")
4794 (prog1
4795 (buffer-name anything-current-buffer)
4796 (kill-buffer "__a_buffer")
4798 (desc "anything-buffer-file-name")
4799 (expect (regexp "/__a_file__")
4800 (with-current-buffer (get-buffer-create "__a_file__")
4801 (setq buffer-file-name "/__a_file__")
4802 (anything-test-candidates '(((name . "FOO"))) "")
4803 (prog1
4804 anything-buffer-file-name
4805 ;;(kill-buffer "__a_file__")
4807 (desc "anything-interpret-value")
4808 (expect "literal"
4809 (anything-interpret-value "literal"))
4810 (expect "lambda"
4811 (anything-interpret-value (lambda () "lambda")))
4812 (expect "lambda with source name"
4813 (let ((source '((name . "lambda with source name"))))
4814 (anything-interpret-value (lambda () anything-source-name) source)))
4815 (expect "function symbol"
4816 (flet ((f () "function symbol"))
4817 (anything-interpret-value 'f)))
4818 (expect "variable symbol"
4819 (let ((v "variable symbol"))
4820 (anything-interpret-value 'v)))
4821 (expect (error error *)
4822 (anything-interpret-value 'unbounded-1))
4823 (desc "anything-compile-sources")
4824 (expect '(((name . "foo")))
4825 (anything-compile-sources '(((name . "foo"))) nil)
4827 (expect '(((name . "foo") (type . test) (action . identity)))
4828 (let ((anything-type-attributes '((test (action . identity)))))
4829 (anything-compile-sources '(((name . "foo") (type . test)))
4830 '(anything-compile-source--type))))
4831 (desc "anything-sources accepts symbols")
4832 (expect '(((name . "foo")))
4833 (let* ((foo '((name . "foo"))))
4834 (anything-compile-sources '(foo) nil)))
4835 (desc "anything-get-sources action")
4836 (expect '(((name . "Actions") (candidates . actions)))
4837 (stub anything-action-window => t)
4838 (let (anything-compiled-sources
4839 (anything-sources '(((name . "Actions") (candidates . actions)))))
4840 (anything-get-sources)))
4841 (desc "get-buffer-create candidates-buffer")
4842 (expect '(((name . "many") (init . many-init)
4843 (candidates-in-buffer . anything-candidates-in-buffer)
4844 (candidates . anything-candidates-in-buffer)
4845 (volatile) (match identity)))
4846 (anything-compile-sources
4847 '(((name . "many") (init . many-init)
4848 (candidates-in-buffer . anything-candidates-in-buffer)))
4849 '(anything-compile-source--candidates-in-buffer)))
4850 (expect '(((name . "many") (init . many-init)
4851 (candidates-in-buffer)
4852 (candidates . anything-candidates-in-buffer)
4853 (volatile) (match identity)))
4854 (anything-compile-sources
4855 '(((name . "many") (init . many-init)
4856 (candidates-in-buffer)))
4857 '(anything-compile-source--candidates-in-buffer)))
4858 (expect '(((name . "many") (init . many-init)
4859 (candidates-in-buffer)
4860 (type . test)
4861 (action . identity)
4862 (candidates . anything-candidates-in-buffer)
4863 (volatile) (match identity)))
4864 (let ((anything-type-attributes '((test (action . identity)))))
4865 (anything-compile-sources
4866 '(((name . "many") (init . many-init)
4867 (candidates-in-buffer)
4868 (type . test)))
4869 '(anything-compile-source--type
4870 anything-compile-source--candidates-in-buffer))))
4872 (desc "anything-get-candidates")
4873 (expect '("foo" "bar")
4874 (anything-get-candidates '((name . "foo") (candidates "foo" "bar"))))
4875 (expect '("FOO" "BAR")
4876 (anything-get-candidates '((name . "foo") (candidates "foo" "bar")
4877 (candidate-transformer
4878 . (lambda (cands) (mapcar 'upcase cands))))))
4879 (expect '("foo" "bar")
4880 (anything-get-candidates '((name . "foo")
4881 (candidates . (lambda () '("foo" "bar"))))))
4882 (expect '("foo" "bar")
4883 (let ((var '("foo" "bar")))
4884 (anything-get-candidates '((name . "foo")
4885 (candidates . var)))))
4886 (expect (error error *)
4887 (anything-get-candidates '((name . "foo")
4888 (candidates . "err"))))
4889 (expect (error error *)
4890 (let ((var "err"))
4891 (anything-get-candidates '((name . "foo")
4892 (candidates . var)))))
4893 (desc "anything-compute-matches")
4894 (expect '("foo" "bar")
4895 (let ((anything-pattern ""))
4896 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4897 (expect '("foo")
4898 (let ((anything-pattern "oo"))
4899 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4900 (expect '("bar")
4901 (let ((anything-pattern "^b"))
4902 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4903 (expect '("a" "b")
4904 (let ((anything-pattern "")
4905 (anything-candidate-number-limit 2))
4906 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4907 (expect '("a" "b")
4908 (let ((anything-pattern ".")
4909 (anything-candidate-number-limit 2))
4910 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4911 (expect '("a" "b" "c")
4912 (let ((anything-pattern "")
4913 anything-candidate-number-limit)
4914 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4915 (expect '("a" "b" "c")
4916 (let ((anything-pattern "[abc]")
4917 anything-candidate-number-limit)
4918 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4919 ;; using anything-test-candidate-list
4920 (desc "anything-test-candidates")
4921 (expect '(("FOO" ("foo" "bar")))
4922 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")))))
4923 (expect '(("FOO" ("bar")))
4924 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar"))) "ar"))
4925 (expect '(("T1" ("hoge" "aiue"))
4926 ("T2" ("test" "boke")))
4927 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4928 ((name . "T2") (candidates "test" "boke")))))
4929 (expect '(("T1" ("hoge"))
4930 ("T2" ("boke")))
4931 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4932 ((name . "T2") (candidates "test" "boke"))) "o"))
4933 (desc "requires-pattern attribute")
4934 (expect nil
4935 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4936 (requires-pattern . 1)))))
4937 (expect '(("FOO" ("bar")))
4938 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4939 (requires-pattern . 1))) "b"))
4940 (desc "delayed attribute(for test)")
4941 (expect '(("T2" ("boke"))
4942 ("T1" ("hoge")))
4943 (anything-test-candidates
4944 '(((name . "T1") (candidates "hoge" "aiue") (delayed))
4945 ((name . "T2") (candidates "test" "boke")))
4946 "o"))
4947 (desc "match attribute(prefix search)")
4948 (expect '(("FOO" ("bar")))
4949 (anything-test-candidates
4950 '(((name . "FOO") (candidates "foo" "bar")
4951 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4952 "ba"))
4953 (expect nil
4954 (anything-test-candidates
4955 '(((name . "FOO") (candidates "foo" "bar")
4956 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4957 "ar"))
4958 (expect "TestSource"
4959 (let (x)
4960 (anything-test-candidates
4961 '(((name . "TestSource") (candidates "a")
4962 (match (lambda (c) (setq x anything-source-name)))))
4963 "a")
4965 (desc "init attribute")
4966 (expect '(("FOO" ("bar")))
4967 (let (v)
4968 (anything-test-candidates
4969 '(((name . "FOO") (init . (lambda () (setq v '("foo" "bar"))))
4970 (candidates . v)))
4971 "ar")))
4972 (desc "candidate-transformer attribute")
4973 (expect '(("FOO" ("BAR")))
4974 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4975 (candidate-transformer
4976 . (lambda (cands) (mapcar 'upcase cands)))))
4977 "ar"))
4978 (desc "filtered-candidate-transformer attribute")
4979 ;; needs more tests
4980 (expect '(("FOO" ("BAR")))
4981 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4982 (filtered-candidate-transformer
4983 . (lambda (cands src) (mapcar 'upcase cands)))))
4984 "ar"))
4985 (desc "anything-candidates-in-buffer-1")
4986 (expect nil
4987 (anything-candidates-in-buffer-1 nil))
4988 (expect '("foo+" "bar+" "baz+")
4989 (with-temp-buffer
4990 (insert "foo+\nbar+\nbaz+\n")
4991 (let ((anything-candidate-number-limit 5))
4992 (anything-candidates-in-buffer-1 (current-buffer) ""))))
4993 (expect '("foo+" "bar+")
4994 (with-temp-buffer
4995 (insert "foo+\nbar+\nbaz+\n")
4996 (let ((anything-candidate-number-limit 2))
4997 (anything-candidates-in-buffer-1 (current-buffer) ""))))
4998 (expect '("foo+")
4999 (with-temp-buffer
5000 (insert "foo+\nbar+\nbaz+\n")
5001 (anything-candidates-in-buffer-1 (current-buffer) "oo\\+")))
5002 (expect '("foo+")
5003 (with-temp-buffer
5004 (insert "foo+\nbar+\nbaz+\n")
5005 (anything-candidates-in-buffer-1
5006 (current-buffer) "oo+"
5007 #'buffer-substring-no-properties '(search-forward))))
5008 (expect '(("foo+" "FOO+"))
5009 (with-temp-buffer
5010 (insert "foo+\nbar+\nbaz+\n")
5011 (anything-candidates-in-buffer-1
5012 (current-buffer) "oo\\+"
5013 (lambda (s e)
5014 (let ((l (buffer-substring-no-properties s e)))
5015 (list l (upcase l)))))))
5016 (desc "anything-candidates-in-buffer")
5017 (expect '(("TEST" ("foo+" "bar+" "baz+")))
5018 (anything-test-candidates
5019 '(((name . "TEST")
5020 (init
5021 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5022 (insert "foo+\nbar+\nbaz+\n"))))
5023 (candidates . anything-candidates-in-buffer)
5024 (match identity)
5025 (volatile)))))
5026 (expect '(("TEST" ("foo+" "bar+" "baz+")))
5027 (let (anything-candidate-number-limit)
5028 (anything-test-candidates
5029 '(((name . "TEST")
5030 (init
5031 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5032 (insert "foo+\nbar+\nbaz+\n"))))
5033 (candidates . anything-candidates-in-buffer)
5034 (match identity)
5035 (volatile))))))
5036 (expect '(("TEST" ("foo+")))
5037 (anything-test-candidates
5038 '(((name . "TEST")
5039 (init
5040 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5041 (insert "foo+\nbar+\nbaz+\n"))))
5042 (candidates . anything-candidates-in-buffer)
5043 (match identity)
5044 (volatile)))
5045 "oo\\+"))
5046 (desc "search attribute")
5047 (expect '(("TEST" ("foo+")))
5048 (anything-test-candidates
5049 '(((name . "TEST")
5050 (init
5051 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5052 (insert "foo+\nbar+\nbaz+\nooo\n"))))
5053 (search search-forward)
5054 (candidates . anything-candidates-in-buffer)
5055 (match identity)
5056 (volatile)))
5057 "oo+"))
5058 (expect '(("TEST" ("foo+" "ooo")))
5059 (anything-test-candidates
5060 '(((name . "TEST")
5061 (init
5062 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5063 (insert "foo+\nbar+\nbaz+\nooo\n"))))
5064 (search search-forward re-search-forward)
5065 (candidates . anything-candidates-in-buffer)
5066 (match identity)
5067 (volatile)))
5068 "oo+"))
5069 (expect '(("TEST" ("foo+" "ooo")))
5070 (anything-test-candidates
5071 '(((name . "TEST")
5072 (init
5073 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5074 (insert "foo+\nbar+\nbaz+\nooo\n"))))
5075 (search re-search-forward search-forward)
5076 (candidates . anything-candidates-in-buffer)
5077 (match identity)
5078 (volatile)))
5079 "oo+"))
5080 (expect '(("TEST" ("ooo" "foo+")))
5081 (anything-test-candidates
5082 '(((name . "TEST")
5083 (init
5084 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5085 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
5086 (search re-search-forward search-forward)
5087 (candidates . anything-candidates-in-buffer)
5088 (match identity)
5089 (volatile)))
5090 "oo+"))
5091 ;; faster exact match
5092 (expect '(("TEST" ("bar+")))
5093 (anything-test-candidates
5094 '(((name . "TEST")
5095 (init
5096 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5097 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
5098 (search (lambda (pattern &rest _)
5099 (and (search-forward (concat "\n" pattern "\n") nil t)
5100 (forward-line -1))))
5101 (candidates . anything-candidates-in-buffer)
5102 (match identity)
5103 (volatile)))
5104 "bar+"))
5105 ;; faster prefix match
5106 (expect '(("TEST" ("bar+")))
5107 (anything-test-candidates
5108 '(((name . "TEST")
5109 (init
5110 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5111 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
5112 (search (lambda (pattern &rest _)
5113 (search-forward (concat "\n" pattern) nil t)))
5114 (candidates . anything-candidates-in-buffer)
5115 (match identity)
5116 (volatile)))
5117 "ba"))
5118 (desc "anything-current-buffer-is-modified")
5119 (expect '(("FOO" ("modified")))
5120 (let ((sources '(((name . "FOO")
5121 (candidates
5122 . (lambda ()
5123 (if (anything-current-buffer-is-modified)
5124 '("modified")
5125 '("unmodified"))))))))
5126 (with-temp-buffer
5127 (clrhash anything-tick-hash)
5128 (insert "1")
5129 (anything-test-candidates sources))))
5130 (expect '(("FOO" ("unmodified")))
5131 (let ((sources '(((name . "FOO")
5132 (candidates
5133 . (lambda ()
5134 (if (anything-current-buffer-is-modified)
5135 '("modified")
5136 '("unmodified"))))))))
5137 (with-temp-buffer
5138 (clrhash anything-tick-hash)
5139 (insert "1")
5140 (anything-test-candidates sources)
5141 (anything-test-candidates sources))))
5142 (expect '(("FOO" ("modified")))
5143 (let ((sources '(((name . "FOO")
5144 (candidates
5145 . (lambda ()
5146 (if (anything-current-buffer-is-modified)
5147 '("modified")
5148 '("unmodified"))))))))
5149 (with-temp-buffer
5150 (clrhash anything-tick-hash)
5151 (insert "1")
5152 (anything-test-candidates sources)
5153 (insert "2")
5154 (anything-test-candidates sources))))
5155 (expect '(("BAR" ("modified")))
5156 (let ((sources1 '(((name . "FOO")
5157 (candidates
5158 . (lambda ()
5159 (if (anything-current-buffer-is-modified)
5160 '("modified")
5161 '("unmodified")))))))
5162 (sources2 '(((name . "BAR")
5163 (candidates
5164 . (lambda ()
5165 (if (anything-current-buffer-is-modified)
5166 '("modified")
5167 '("unmodified"))))))))
5168 (with-temp-buffer
5169 (clrhash anything-tick-hash)
5170 (insert "1")
5171 (anything-test-candidates sources1)
5172 (anything-test-candidates sources2))))
5173 (expect '(("FOO" ("unmodified")))
5174 (let ((sources1 '(((name . "FOO")
5175 (candidates
5176 . (lambda ()
5177 (if (anything-current-buffer-is-modified)
5178 '("modified")
5179 '("unmodified")))))))
5180 (sources2 '(((name . "BAR")
5181 (candidates
5182 . (lambda ()
5183 (if (anything-current-buffer-is-modified)
5184 '("modified")
5185 '("unmodified"))))))))
5186 (with-temp-buffer
5187 (clrhash anything-tick-hash)
5188 (insert "1")
5189 (anything-test-candidates sources1)
5190 (anything-test-candidates sources2)
5191 (anything-test-candidates sources1))))
5192 (expect '(("BAR" ("unmodified")))
5193 (let ((sources1 '(((name . "FOO")
5194 (candidates
5195 . (lambda ()
5196 (if (anything-current-buffer-is-modified)
5197 '("modified")
5198 '("unmodified")))))))
5199 (sources2 '(((name . "BAR")
5200 (candidates
5201 . (lambda ()
5202 (if (anything-current-buffer-is-modified)
5203 '("modified")
5204 '("unmodified"))))))))
5205 (with-temp-buffer
5206 (clrhash anything-tick-hash)
5207 (insert "1")
5208 (anything-test-candidates sources1)
5209 (anything-test-candidates sources2)
5210 (anything-test-candidates sources2))))
5211 (expect '(("BAR" ("modified")))
5212 (let ((sources1 '(((name . "FOO")
5213 (candidates
5214 . (lambda ()
5215 (if (anything-current-buffer-is-modified)
5216 '("modified")
5217 '("unmodified")))))))
5218 (sources2 '(((name . "BAR")
5219 (candidates
5220 . (lambda ()
5221 (if (anything-current-buffer-is-modified)
5222 '("modified")
5223 '("unmodified"))))))))
5224 (with-temp-buffer
5225 (clrhash anything-tick-hash)
5226 (insert "1")
5227 (anything-test-candidates sources1)
5228 (anything-test-candidates sources2)
5229 (with-temp-buffer
5230 (anything-test-candidates sources2)))))
5231 (desc "anything-source-name")
5232 (expect "FOO"
5233 (let (v)
5234 (anything-test-candidates '(((name . "FOO")
5235 (init
5236 . (lambda () (setq v anything-source-name)))
5237 (candidates "ok"))))
5239 (expect "FOO"
5240 (let (v)
5241 (anything-test-candidates '(((name . "FOO")
5242 (candidates
5243 . (lambda ()
5244 (setq v anything-source-name)
5245 '("ok"))))))
5247 (expect "FOO"
5248 (let (v)
5249 (anything-test-candidates '(((name . "FOO")
5250 (candidates "ok")
5251 (candidate-transformer
5252 . (lambda (c)
5253 (setq v anything-source-name)
5254 c)))))
5256 (expect "FOO"
5257 (let (v)
5258 (anything-test-candidates '(((name . "FOO")
5259 (candidates "ok")
5260 (filtered-candidate-transformer
5261 . (lambda (c s)
5262 (setq v anything-source-name)
5263 c)))))
5265 (expect "FOO"
5266 (let (v)
5267 (anything-test-candidates '(((name . "FOO")
5268 (candidates "ok")
5269 (display-to-real
5270 . (lambda (c)
5271 (setq v anything-source-name)
5273 (action . identity))))
5274 (anything-execute-selection-action)
5276 (desc "anything-candidate-buffer create")
5277 (expect " *anything candidates:FOO*"
5278 (let* (anything-candidate-buffer-alist
5279 (anything-source-name "FOO")
5280 (buf (anything-candidate-buffer 'global)))
5281 (prog1 (buffer-name buf)
5282 (kill-buffer buf))))
5283 (expect " *anything candidates:FOO*aTestBuffer"
5284 (let* (anything-candidate-buffer-alist
5285 (anything-source-name "FOO")
5286 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5287 (buf (anything-candidate-buffer 'local)))
5288 (prog1 (buffer-name buf)
5289 (kill-buffer anything-current-buffer)
5290 (kill-buffer buf))))
5291 (expect 0
5292 (let (anything-candidate-buffer-alist
5293 (anything-source-name "FOO") buf)
5294 (with-current-buffer (anything-candidate-buffer 'global)
5295 (insert "1"))
5296 (setq buf (anything-candidate-buffer 'global))
5297 (prog1 (buffer-size buf)
5298 (kill-buffer buf))))
5299 (desc "anything-candidate-buffer get-buffer")
5300 (expect " *anything candidates:FOO*"
5301 (let* (anything-candidate-buffer-alist
5302 (anything-source-name "FOO")
5303 (buf (anything-candidate-buffer 'global)))
5304 (prog1 (buffer-name (anything-candidate-buffer))
5305 (kill-buffer buf))))
5306 (expect " *anything candidates:FOO*aTestBuffer"
5307 (let* (anything-candidate-buffer-alist
5308 (anything-source-name "FOO")
5309 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5310 (buf (anything-candidate-buffer 'local)))
5311 (prog1 (buffer-name (anything-candidate-buffer))
5312 (kill-buffer anything-current-buffer)
5313 (kill-buffer buf))))
5314 (expect " *anything candidates:FOO*"
5315 (let* (anything-candidate-buffer-alist
5316 (anything-source-name "FOO")
5317 (buf-local (anything-candidate-buffer 'local))
5318 (buf-global (anything-candidate-buffer 'global)))
5319 (prog1 (buffer-name (anything-candidate-buffer))
5320 (kill-buffer buf-local)
5321 (kill-buffer buf-global))))
5322 (expect " *anything candidates:FOO*aTestBuffer"
5323 (let* (anything-candidate-buffer-alist
5324 (anything-source-name "FOO")
5325 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5326 (buf-global (anything-candidate-buffer 'global))
5327 (buf-local (anything-candidate-buffer 'local)))
5328 (prog1 (buffer-name (anything-candidate-buffer))
5329 (kill-buffer buf-local)
5330 (kill-buffer buf-global))))
5331 (expect nil
5332 (let* (anything-candidate-buffer-alist
5333 (anything-source-name "NOP__"))
5334 (anything-candidate-buffer)))
5335 (desc "anything-candidate-buffer register-buffer")
5336 (expect " *anything test candidates*"
5337 (let (anything-candidate-buffer-alist
5338 (buf (get-buffer-create " *anything test candidates*")))
5339 (with-current-buffer buf
5340 (insert "1\n2\n")
5341 (prog1 (buffer-name (anything-candidate-buffer buf))
5342 (kill-buffer (current-buffer))))))
5343 (expect " *anything test candidates*"
5344 (let (anything-candidate-buffer-alist
5345 (buf (get-buffer-create " *anything test candidates*")))
5346 (with-current-buffer buf
5347 (insert "1\n2\n")
5348 (anything-candidate-buffer buf)
5349 (prog1 (buffer-name (anything-candidate-buffer))
5350 (kill-buffer (current-buffer))))))
5351 (expect "1\n2\n"
5352 (let (anything-candidate-buffer-alist
5353 (buf (get-buffer-create " *anything test candidates*")))
5354 (with-current-buffer buf
5355 (insert "1\n2\n")
5356 (anything-candidate-buffer buf)
5357 (prog1 (buffer-string)
5358 (kill-buffer (current-buffer))))))
5359 (expect "buf1"
5360 (let (anything-candidate-buffer-alist
5361 (anything-source-name "foo")
5362 (buf1 (get-buffer-create "buf1"))
5363 (buf2 (get-buffer-create "buf2")))
5364 (anything-candidate-buffer buf1)
5365 (anything-candidate-buffer buf2)
5366 (prog1 (buffer-name (anything-candidate-buffer buf1))
5367 (kill-buffer buf1)
5368 (kill-buffer buf2))))
5369 (desc "action attribute")
5370 (expect "foo"
5371 (anything-test-candidates
5372 '(((name . "TEST")
5373 (candidates "foo")
5374 (action ("identity" . identity)))))
5375 (anything-execute-selection-action))
5376 (expect "foo"
5377 (anything-test-candidates
5378 '(((name . "TEST")
5379 (candidates "foo")
5380 (action ("identity" . (lambda (c) (identity c)))))))
5381 (anything-execute-selection-action))
5382 (desc "anything-execute-selection-action")
5383 (expect "FOO"
5384 (anything-execute-selection-action
5385 "foo" '(("upcase" . upcase)) nil))
5386 (expect "FOO"
5387 (anything-execute-selection-action
5388 "foo" '(("upcase" . (lambda (c) (upcase c)))) nil))
5389 (desc "display-to-real attribute")
5390 (expect "FOO"
5391 (anything-test-candidates
5392 '(((name . "TEST")
5393 (candidates "foo")
5394 (display-to-real . upcase)
5395 (action ("identity" . identity)))))
5396 (anything-execute-selection-action))
5397 (desc "cleanup test")
5398 (expect 'cleaned
5399 (let (v)
5400 (anything-test-candidates
5401 '(((name . "TEST")
5402 (cleanup . (lambda () (setq v 'cleaned))))))
5404 (desc "anything-get-current-source")
5405 ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
5406 ;; display-to-real/cleanup function
5407 (expect "FOO"
5408 (assoc-default
5409 'name
5410 (anything-funcall-with-source '((name . "FOO")) 'anything-get-current-source)))
5411 ;; init
5412 (expect "FOO"
5413 (let (v)
5414 (anything-test-candidates
5415 '(((name . "FOO")
5416 (init . (lambda () (setq v (anything-get-current-source)))))))
5417 (assoc-default 'name v)))
5418 ;; candidates
5419 (expect "FOO"
5420 (let (v)
5421 (anything-test-candidates
5422 '(((name . "FOO")
5423 (candidates . (lambda () (setq v (anything-get-current-source)) '("a"))))))
5424 (assoc-default 'name v)))
5425 ;; action
5426 (expect "FOO"
5427 (let (v)
5428 (anything-test-candidates
5429 '(((name . "FOO")
5430 (candidates "a")
5431 (action
5432 . (lambda (c) (setq v (anything-get-current-source)) c)))))
5433 (anything-execute-selection-action)
5434 (assoc-default 'name v)))
5435 ;; candidate-transformer
5436 (expect "FOO"
5437 (let (v)
5438 (anything-test-candidates
5439 '(((name . "FOO")
5440 (candidates "a")
5441 (candidate-transformer
5442 . (lambda (c) (setq v (anything-get-current-source)) c)))))
5443 (assoc-default 'name v)))
5444 ;; filtered-candidate-transformer
5445 (expect "FOO"
5446 (let (v)
5447 (anything-test-candidates
5448 '(((name . "FOO")
5449 (candidates "a")
5450 (filtered-candidate-transformer
5451 . (lambda (c s) (setq v (anything-get-current-source)) c)))))
5452 (assoc-default 'name v)))
5453 ;; action-transformer
5454 (expect "FOO"
5455 (let (v)
5456 (anything-test-candidates
5457 '(((name . "FOO")
5458 (candidates "a")
5459 (action-transformer
5460 . (lambda (a c) (setq v (anything-get-current-source)) a))
5461 (action . identity))))
5462 (anything-execute-selection-action)
5463 (assoc-default 'name v)))
5464 ;; display-to-real
5465 (expect "FOO"
5466 (let (v)
5467 (anything-test-candidates
5468 '(((name . "FOO")
5469 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5470 (insert "a\n"))))
5471 (candidates-in-buffer)
5472 (display-to-real
5473 . (lambda (c) (setq v (anything-get-current-source)) c))
5474 (action . identity))))
5475 (anything-execute-selection-action)
5476 (assoc-default 'name v)))
5477 ;; cleanup
5478 (expect "FOO"
5479 (let (v)
5480 (anything-test-candidates
5481 '(((name . "FOO")
5482 (candidates "a")
5483 (cleanup
5484 . (lambda () (setq v (anything-get-current-source)))))))
5485 (assoc-default 'name v)))
5486 ;; candidates are displayed
5487 (expect "TEST"
5488 (anything-test-candidates
5489 '(((name . "TEST")
5490 (candidates "foo")
5491 (action ("identity" . identity)))))
5492 (assoc-default 'name (anything-get-current-source)))
5493 (desc "anything-attr")
5494 (expect "FOO"
5495 (anything-funcall-with-source
5496 '((name . "FOO"))
5497 (lambda ()
5498 (anything-attr 'name))))
5499 (expect 'fuga
5500 (let (v)
5501 (anything-test-candidates
5502 '(((name . "FOO")
5503 (hoge . fuga)
5504 (init . (lambda () (setq v (anything-attr 'hoge))))
5505 (candidates "a"))))
5507 (expect nil
5508 (let (v)
5509 (anything-test-candidates
5510 '(((name . "FOO")
5511 (init . (lambda () (setq v (anything-attr 'hoge))))
5512 (candidates "a"))))
5514 (expect nil
5515 (let (v)
5516 (anything-test-candidates
5517 '(((name . "FOO")
5518 (hoge) ;INCOMPATIBLE!
5519 (init . (lambda () (setq v (anything-attr 'hoge))))
5520 (candidates "a"))))
5522 (desc "anything-attr-defined")
5523 (expect (non-nil)
5524 (let (v)
5525 (anything-test-candidates
5526 '(((name . "FOO")
5527 (hoge)
5528 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5529 (candidates "a"))))
5530 v))
5531 (expect nil
5532 (let (v)
5533 (anything-test-candidates
5534 '(((name . "FOO")
5535 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5536 (candidates "a"))))
5537 v))
5538 (desc "anything-attrset")
5539 (expect '((name . "FOO") (hoge . 77))
5540 (let ((src '((name . "FOO") (hoge))))
5541 (anything-attrset 'hoge 77 src)
5542 src))
5543 (expect 77
5544 (anything-attrset 'hoge 77 '((name . "FOO") (hoge))))
5546 (expect '((name . "FOO") (hoge . 77))
5547 (let ((src '((name . "FOO") (hoge . 1))))
5548 (anything-attrset 'hoge 77 src)
5549 src))
5551 (expect '((name . "FOO") (hoge . 77) (x))
5552 (let ((src '((name . "FOO") (x))))
5553 (anything-attrset 'hoge 77 src)
5554 src))
5555 (expect 77
5556 (anything-attrset 'hoge 77 '((name . "FOO"))))
5557 (desc "anything-preselect")
5558 ;; entire candidate
5559 (expect "foo"
5560 (with-current-buffer (anything-create-anything-buffer t)
5561 (let ((anything-pattern "")
5562 (anything-test-mode t))
5563 (anything-process-source '((name . "test")
5564 (candidates "hoge" "foo" "bar")))
5565 (anything-preselect "foo")
5566 (anything-get-selection))))
5567 ;; regexp
5568 (expect "foo"
5569 (with-current-buffer (anything-create-anything-buffer t)
5570 (let ((anything-pattern "")
5571 (anything-test-mode t))
5572 (anything-process-source '((name . "test")
5573 (candidates "hoge" "foo" "bar")))
5574 (anything-preselect "fo+")
5575 (anything-get-selection))))
5576 ;; no match -> first entry
5577 (expect "hoge"
5578 (with-current-buffer (anything-create-anything-buffer t)
5579 (let ((anything-pattern "")
5580 (anything-test-mode t))
5581 (anything-process-source '((name . "test")
5582 (candidates "hoge" "foo" "bar")))
5583 (anything-preselect "not found")
5584 (anything-get-selection))))
5585 (desc "anything-check-new-input")
5586 (expect "newpattern"
5587 (stub anything-update)
5588 (stub anything-action-window)
5589 (let ((anything-pattern "pattern"))
5590 (anything-check-new-input "newpattern")
5591 anything-pattern))
5592 ;; anything-input == nil when action window is available
5593 (expect nil
5594 (stub anything-update)
5595 (stub anything-action-window => t)
5596 (let ((anything-pattern "pattern")
5597 anything-input)
5598 (anything-check-new-input "newpattern")
5599 anything-input))
5600 ;; anything-input == anything-pattern unless action window is available
5601 (expect "newpattern"
5602 (stub anything-update)
5603 (stub anything-action-window => nil)
5604 (let ((anything-pattern "pattern")
5605 anything-input)
5606 (anything-check-new-input "newpattern")
5607 anything-input))
5608 (expect (mock (anything-update))
5609 (stub anything-action-window)
5610 (let (anything-pattern)
5611 (anything-check-new-input "foo")))
5612 (desc "anything-update")
5613 (expect (mock (anything-process-source '((name . "1"))))
5614 (anything-test-update '(((name . "1"))) ""))
5615 ;; (find-function 'anything-update)
5616 ;; TODO el-mock.el should express 2nd call of function.
5617 ;; (expect (mock (anything-process-source '((name . "2"))))
5618 ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
5619 ;; (stub run-hooks)
5620 ;; (stub anything-maybe-fit-frame)
5621 ;; (stub run-with-idle-timer)
5622 ;; (anything-update))
5623 (expect (mock (run-with-idle-timer * nil 'anything-process-delayed-sources
5624 '(((name . "2") (delayed)))))
5625 (stub anything-get-sources => '(((name . "1"))
5626 ((name . "2") (delayed))))
5627 (stub run-hooks)
5628 (stub anything-maybe-fit-frame)
5629 (let ((anything-pattern "") anything-test-mode)
5630 (anything-update)))
5632 (desc "requires-pattern attribute")
5633 (expect (not-called anything-process-source)
5634 (anything-test-update '(((name . "1") (requires-pattern))) ""))
5635 (expect (not-called anything-process-source)
5636 (anything-test-update '(((name . "1") (requires-pattern . 3))) "xx"))
5638 (desc "delay")
5639 (expect (mock (sit-for 0.25))
5640 (stub with-current-buffer)
5641 (let ((anything-idle-delay 1.0)
5642 (anything-input-idle-delay 0.75))
5643 (anything-process-delayed-sources t)))
5644 (expect (mock (sit-for 0.0))
5645 (stub with-current-buffer)
5646 (let ((anything-idle-delay 0.2)
5647 (anything-input-idle-delay 0.5))
5648 (anything-process-delayed-sources t)))
5649 (expect (mock (sit-for 0.5))
5650 (stub with-current-buffer)
5651 (let ((anything-idle-delay 0.5)
5652 (anything-input-idle-delay nil))
5653 (anything-process-delayed-sources t)))
5654 (desc "anything-normalize-sources")
5655 (expect '(anything-c-source-test)
5656 (anything-normalize-sources 'anything-c-source-test))
5657 (expect '(anything-c-source-test)
5658 (anything-normalize-sources '(anything-c-source-test)))
5659 (expect '(anything-c-source-test)
5660 (let ((anything-sources '(anything-c-source-test)))
5661 (anything-normalize-sources nil)))
5662 (expect '(((name . "test")))
5663 (anything-normalize-sources '((name . "test"))))
5664 (expect '(((name . "test")))
5665 (anything-normalize-sources '(((name . "test")))))
5666 (desc "anything-get-action")
5667 (expect '(("identity" . identity))
5668 (stub buffer-size => 1)
5669 (stub anything-get-current-source => '((name . "test")
5670 (action ("identity" . identity))))
5671 (anything-get-action))
5672 (expect '((("identity" . identity)) "action-transformer is called")
5673 (stub buffer-size => 1)
5674 (stub anything-get-current-source
5675 => '((name . "test")
5676 (action ("identity" . identity))
5677 (action-transformer
5678 . (lambda (actions selection)
5679 (list actions selection)))))
5680 (stub anything-get-selection => "action-transformer is called")
5681 (anything-get-action))
5682 (desc "anything-select-nth-action")
5683 (expect "selection"
5684 (stub anything-get-selection => "selection")
5685 (stub anything-exit-minibuffer)
5686 (let (anything-saved-selection)
5687 (anything-select-nth-action 1)
5688 anything-saved-selection))
5689 (expect 'cadr
5690 (stub anything-get-action => '(("0" . car) ("1" . cdr) ("2" . cadr)))
5691 (stub anything-exit-minibuffer)
5692 (stub anything-get-selection => "selection")
5693 (let (anything-saved-action)
5694 (anything-select-nth-action 2)
5695 anything-saved-action))
5696 (desc "anything-funcall-foreach")
5697 (expect (mock (upcase "foo"))
5698 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5699 (anything-funcall-foreach 'init))
5700 (expect (mock (downcase "bar"))
5701 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))
5702 ((init . (lambda () (downcase "bar"))))))
5703 (anything-funcall-foreach 'init))
5704 (expect (not-called anything-funcall-with-source)
5705 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5706 (anything-funcall-foreach 'not-found))
5707 ;; TODO anything-select-with-digit-shortcut test
5708 (desc "anything-get-cached-candidates")
5709 (expect '("cached" "version")
5710 (let ((anything-candidate-cache '(("test" "cached" "version"))))
5711 (anything-get-cached-candidates '((name . "test")
5712 (candidates "new")))))
5713 (expect '("new")
5714 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5715 (anything-get-cached-candidates '((name . "test")
5716 (candidates "new")))))
5717 (expect '(("test" "new")
5718 ("other" "cached" "version"))
5719 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5720 (anything-get-cached-candidates '((name . "test")
5721 (candidates "new")))
5722 anything-candidate-cache))
5723 (expect '(("other" "cached" "version"))
5724 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5725 (anything-get-cached-candidates '((name . "test")
5726 (candidates "new")
5727 (volatile)))
5728 anything-candidate-cache))
5729 ;; TODO when candidates == process
5730 ;; TODO anything-output-filter
5731 (desc "candidate-number-limit attribute")
5732 (expect '("a" "b")
5733 (let ((anything-pattern "")
5734 (anything-candidate-number-limit 20))
5735 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5736 (candidate-number-limit . 2) (volatile)))))
5737 (expect '("a" "b")
5738 (let ((anything-pattern "[abc]")
5739 (anything-candidate-number-limit 20))
5740 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5741 (candidate-number-limit . 2) (volatile)))))
5742 (expect '("a" "b" "c" "d")
5743 (let ((anything-pattern "[abcd]")
5744 (anything-candidate-number-limit 2))
5745 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c" "d")
5746 (candidate-number-limit) (volatile)))))
5747 (expect '(("TEST" ("a" "b" "c")))
5748 (let ((anything-candidate-number-limit 2))
5749 (anything-test-candidates
5750 '(((name . "TEST")
5751 (init
5752 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5753 (insert "a\nb\nc\nd\n"))))
5754 (candidates . anything-candidates-in-buffer)
5755 (match identity)
5756 (candidate-number-limit . 3)
5757 (volatile))))))
5758 (expect '(("TEST" ("a" "b" "c")))
5759 (let ((anything-candidate-number-limit 2))
5760 (anything-test-candidates
5761 '(((name . "TEST")
5762 (init
5763 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5764 (insert "a\nb\nc\nd\n"))))
5765 (candidates . anything-candidates-in-buffer)
5766 (match identity)
5767 (candidate-number-limit . 3)
5768 (volatile)))
5769 ".")))
5770 (desc "multiple init")
5771 (expect '(1 . 2)
5772 (let (a b)
5773 (anything-test-candidates
5774 '(((name . "test")
5775 (init (lambda () (setq a 1))
5776 (lambda () (setq b 2))))))
5777 (cons a b)))
5778 (expect 1
5779 (let (a)
5780 (anything-test-candidates
5781 '(((name . "test")
5782 (init (lambda () (setq a 1))))))
5784 (desc "multiple cleanup")
5785 (expect '(1 . 2)
5786 (let (a b)
5787 (anything-test-candidates
5788 '(((name . "test")
5789 (cleanup (lambda () (setq a 1))
5790 (lambda () (setq b 2))))))
5791 (cons a b)))
5792 (desc "anything-mklist")
5793 (expect '(1)
5794 (anything-mklist 1))
5795 (expect '(2)
5796 (anything-mklist '(2)))
5797 (expect '((lambda ()))
5798 (anything-mklist (lambda ())))
5799 (desc "anything-before-initialize-hook")
5800 (expect 'called
5801 (let ((anything-before-initialize-hook '((lambda () (setq v 'called))))
5803 (anything-initialize)
5805 (desc "anything-after-initialize-hook")
5806 (expect '(b a)
5807 (let ((anything-before-initialize-hook
5808 '((lambda () (setq v '(a)))))
5809 (anything-after-initialize-hook
5810 '((lambda () (setq v (cons 'b v)))))
5812 (anything-initialize)
5814 (expect 0
5815 (let ((anything-after-initialize-hook
5816 '((lambda () (setq v (buffer-size (get-buffer anything-buffer))))))
5818 (anything-initialize)
5820 (desc "get-line attribute")
5821 (expect '(("TEST" ("FOO+")))
5822 (anything-test-candidates
5823 '(((name . "TEST")
5824 (init
5825 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5826 (insert "foo+\nbar+\nbaz+\n"))))
5827 (candidates-in-buffer)
5828 (get-line . (lambda (s e) (upcase (buffer-substring-no-properties s e))))))
5829 "oo\\+"))
5830 (desc "with-anything-restore-variables")
5831 (expect '(7 8)
5832 (let ((a 7) (b 8)
5833 (anything-restored-variables '(a b)))
5834 (with-anything-restore-variables
5835 (setq a 0 b 0))
5836 (list a b)))
5837 (desc "anything-cleanup-hook")
5838 (expect 'called
5839 (let ((anything-cleanup-hook
5840 '((lambda () (setq v 'called))))
5842 (anything-cleanup)
5844 (desc "with-anything-display-same-window")
5845 (expect (non-nil)
5846 (save-window-excursion
5847 (delete-other-windows)
5848 (split-window)
5850 (let ((buf (get-buffer-create " tmp"))
5851 (win (selected-window)))
5852 (with-anything-display-same-window
5853 (display-buffer buf)
5854 (eq win (get-buffer-window buf))))))
5855 (expect (non-nil)
5856 (save-window-excursion
5857 (delete-other-windows)
5858 (split-window)
5860 (let ((buf (get-buffer-create " tmp"))
5861 (win (selected-window)))
5862 (with-anything-display-same-window
5863 (pop-to-buffer buf)
5864 (eq win (get-buffer-window buf))))))
5865 (expect (non-nil)
5866 (save-window-excursion
5867 (delete-other-windows)
5868 (split-window)
5870 (let ((buf (get-buffer-create " tmp"))
5871 (win (selected-window)))
5872 (with-anything-display-same-window
5873 (switch-to-buffer buf)
5874 (eq win (get-buffer-window buf))))))
5875 (expect (non-nil)
5876 (save-window-excursion
5877 (delete-other-windows)
5878 (let ((buf (get-buffer-create " tmp"))
5879 (win (selected-window)))
5880 (with-anything-display-same-window
5881 (display-buffer buf)
5882 (eq win (get-buffer-window buf))))))
5883 (expect (non-nil)
5884 (save-window-excursion
5885 (delete-other-windows)
5886 (let ((buf (get-buffer-create " tmp"))
5887 (win (selected-window)))
5888 (with-anything-display-same-window
5889 (pop-to-buffer buf)
5890 (eq win (get-buffer-window buf))))))
5891 (desc "search-from-end attribute")
5892 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5893 (anything-test-candidates
5894 '(((name . "TEST")
5895 (init
5896 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5897 (insert "foo+\nbar+\nbaz+\n"))))
5898 (candidates-in-buffer)
5899 (search-from-end)))))
5900 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5901 (anything-test-candidates
5902 '(((name . "TEST")
5903 (init
5904 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5905 (insert "foo+\nbar+\nbaz+\n"))))
5906 (candidates-in-buffer)
5907 (search-from-end)))
5908 "\\+"))
5909 (expect '(("TEST" ("baz+" "bar+")))
5910 (anything-test-candidates
5911 '(((name . "TEST")
5912 (init
5913 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5914 (insert "foo+\nbar+\nbaz+\n"))))
5915 (candidates-in-buffer)
5916 (search-from-end)
5917 (candidate-number-limit . 2)))))
5918 (expect '(("TEST" ("baz+" "bar+")))
5919 (anything-test-candidates
5920 '(((name . "TEST")
5921 (init
5922 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5923 (insert "foo+\nbar+\nbaz+\n"))))
5924 (candidates-in-buffer)
5925 (search-from-end)
5926 (candidate-number-limit . 2)))
5927 "\\+"))
5929 (desc "header-name attribute")
5930 (expect "original is transformed"
5931 (anything-test-update '(((name . "original")
5932 (candidates "1")
5933 (header-name
5934 . (lambda (name)
5935 (format "%s is transformed" name)))))
5937 (with-current-buffer (anything-buffer-get)
5938 (buffer-string)
5939 (overlay-get (car (overlays-at (1+(point-min)))) 'display)))
5940 (desc "volatile and match attribute")
5941 ;; candidates function is called once per `anything-process-delayed-sources'
5942 (expect 1
5943 (let ((v 0))
5944 (anything-test-candidates '(((name . "test")
5945 (candidates . (lambda () (incf v) '("ok")))
5946 (volatile)
5947 (match identity identity identity)))
5948 "o")
5950 (desc "accept-empty attribute")
5951 (expect nil
5952 (anything-test-candidates
5953 '(((name . "test") (candidates "") (action . identity))))
5954 (anything-execute-selection-action))
5955 (expect ""
5956 (anything-test-candidates
5957 '(((name . "test") (candidates "") (action . identity) (accept-empty))))
5958 (anything-execute-selection-action))
5959 (desc "anything-tick-hash")
5960 (expect nil
5961 (with-current-buffer (get-buffer-create " *00create+*")
5962 (puthash " *00create+*/xxx" 1 anything-tick-hash)
5963 (kill-buffer (current-buffer)))
5964 (gethash " *00create+*/xxx" anything-tick-hash))
5965 (desc "anything-execute-action-at-once-if-once")
5966 (expect "HOGE"
5967 (let ((anything-execute-action-at-once-if-one t))
5968 (anything '(((name . "one test1")
5969 (candidates "hoge")
5970 (action . upcase))))))
5971 (expect "ANY"
5972 (let ((anything-execute-action-at-once-if-one t))
5973 (anything '(((name . "one test2")
5974 (candidates "hoge" "any")
5975 (action . upcase)))
5976 "an")))
5977 ;; candidates > 1
5978 (expect (mock (read-string "word: " nil))
5979 (let ((anything-execute-action-at-once-if-one t))
5980 (anything '(((name . "one test3")
5981 (candidates "hoge" "foo" "bar")
5982 (action . identity)))
5983 nil "word: ")))
5984 (desc "anything-quit-if-no-candidate")
5985 (expect nil
5986 (let ((anything-quit-if-no-candidate t))
5987 (anything '(((name . "zero test1") (candidates) (action . upcase))))))
5988 (expect 'called
5989 (let (v (anything-quit-if-no-candidate (lambda () (setq v 'called))))
5990 (anything '(((name . "zero test2") (candidates) (action . upcase))))
5992 (desc "real-to-display attribute")
5993 (expect '(("test" (("DDD" . "ddd"))))
5994 (anything-test-candidates '(((name . "test")
5995 (candidates "ddd")
5996 (real-to-display . upcase)
5997 (action . identity)))))
5998 (expect '(("test" (("DDD" . "ddd"))))
5999 (anything-test-candidates '(((name . "test")
6000 (candidates ("ignored" . "ddd"))
6001 (real-to-display . upcase)
6002 (action . identity)))))
6003 (expect '(("Commands" (("xxxhoge" . "hoge") ("xxxboke" . "boke"))))
6004 (anything-test-candidates '(((name . "Commands")
6005 (candidates
6006 "hoge" "boke")
6007 (real-to-display . (lambda (x) (concat "xxx" x)))
6008 (action . identity)))
6009 "xxx"))
6010 (expect "test\nDDD\n"
6011 (anything-test-update '(((name . "test")
6012 (candidates "ddd")
6013 (real-to-display . upcase)
6014 (action . identity)))
6016 (with-current-buffer (anything-buffer-get) (buffer-string)))
6017 (desc "real-to-display and candidate-transformer attribute")
6018 (expect '(("test" (("DDD" . "ddd"))))
6019 (anything-test-candidates
6020 '(((name . "test")
6021 (candidates "ddd")
6022 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
6023 (real-to-display . upcase)
6024 (action . identity)))))
6025 (expect "test\nDDD\n"
6026 (anything-test-update
6027 '(((name . "test")
6028 (candidates "ddd")
6029 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
6030 (real-to-display . upcase)
6031 (action . identity)))
6033 (with-current-buffer (anything-buffer-get) (buffer-string)))
6034 (desc "real-to-display and candidates-in-buffer")
6035 (expect '(("test" (("A" . "a") ("B" . "b"))))
6036 (anything-test-candidates
6037 '(((name . "test")
6038 (init
6039 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
6040 (erase-buffer)
6041 (insert "a\nb\n"))))
6042 (candidates-in-buffer)
6043 (real-to-display . upcase)
6044 (action . identity)))))
6045 (expect "test\nA\nB\n"
6046 (stub read-string)
6047 (anything
6048 '(((name . "test")
6049 (init
6050 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
6051 (erase-buffer)
6052 (insert "a\nb\n"))))
6053 (candidates-in-buffer)
6054 (real-to-display . upcase)
6055 (action . identity))))
6056 (with-current-buffer (anything-buffer-get) (buffer-string)))
6057 (desc "Symbols are acceptable as candidate.")
6058 (expect '(("test" (sym "str")))
6059 (anything-test-candidates
6060 '(((name . "test")
6061 (candidates sym "str")))))
6062 (expect '(("test" ((sym . realsym) ("str" . "realstr"))))
6063 (anything-test-candidates
6064 '(((name . "test")
6065 (candidates (sym . realsym) ("str" . "realstr"))))))
6066 (expect '(("test" (sym)))
6067 (anything-test-candidates
6068 '(((name . "test")
6069 (candidates sym "str")))
6070 "sym"))
6071 (expect '(("test" ("str")))
6072 (anything-test-candidates
6073 '(((name . "test")
6074 (candidates sym "str")))
6075 "str"))
6076 (expect '(("test" ((sym . realsym))))
6077 (anything-test-candidates
6078 '(((name . "test")
6079 (candidates (sym . realsym) ("str" . "realstr"))))
6080 "sym"))
6081 (expect '(("test" (("str" . "realstr"))))
6082 (anything-test-candidates
6083 '(((name . "test")
6084 (candidates (sym . realsym) ("str" . "realstr"))))
6085 "str"))
6086 (desc "multiple transformers")
6087 (expect '(("test" ("<FOO>")))
6088 (anything-test-candidates
6089 '(((name . "test")
6090 (candidates "foo")
6091 (candidate-transformer
6092 . (lambda (cands)
6093 (anything-compose (list cands)
6094 (list (lambda (c) (mapcar 'upcase c))
6095 (lambda (c) (list (concat "<" (car c) ">")))))))))))
6096 (expect '("<FOO>")
6097 (anything-composed-funcall-with-source
6098 '((name . "test"))
6099 (list (lambda (c) (mapcar 'upcase c))
6100 (lambda (c) (list (concat "<" (car c) ">"))))
6101 '("foo"))
6103 (expect '(("test" ("<FOO>")))
6104 (anything-test-candidates
6105 '(((name . "test")
6106 (candidates "foo")
6107 (candidate-transformer
6108 (lambda (c) (mapcar 'upcase c))
6109 (lambda (c) (list (concat "<" (car c) ">"))))))))
6110 (expect '(("test" ("<BAR>")))
6111 (anything-test-candidates
6112 '(((name . "test")
6113 (candidates "bar")
6114 (filtered-candidate-transformer
6115 (lambda (c s) (mapcar 'upcase c))
6116 (lambda (c s) (list (concat "<" (car c) ">"))))))))
6117 (expect '(("find-file" . find-file)
6118 ("view-file" . view-file))
6119 (stub zerop => nil)
6120 (stub anything-get-current-source
6121 => '((name . "test")
6122 (action)
6123 (action-transformer
6124 . (lambda (a s)
6125 (anything-compose
6126 (list a s)
6127 (list (lambda (a s) (push '("view-file" . view-file) a))
6128 (lambda (a s) (push '("find-file" . find-file) a))))))))
6129 (anything-get-action))
6130 (expect '(("find-file" . find-file)
6131 ("view-file" . view-file))
6132 (stub zerop => nil)
6133 (stub anything-get-current-source
6134 => '((name . "test")
6135 (action)
6136 (action-transformer
6137 (lambda (a s) (push '("view-file" . view-file) a))
6138 (lambda (a s) (push '("find-file" . find-file) a)))))
6139 (anything-get-action))
6140 (desc "define-anything-type-attribute")
6141 (expect '((file (action . find-file)))
6142 (let (anything-type-attributes)
6143 (define-anything-type-attribute 'file '((action . find-file)))
6144 anything-type-attributes))
6145 (expect '((file (action . find-file)))
6146 (let ((anything-type-attributes '((file (action . view-file)))))
6147 (define-anything-type-attribute 'file '((action . find-file)))
6148 anything-type-attributes))
6149 (expect '((file (action . find-file))
6150 (buffer (action . switch-to-buffer)))
6151 (let (anything-type-attributes)
6152 (define-anything-type-attribute 'buffer '((action . switch-to-buffer)))
6153 (define-anything-type-attribute 'file '((action . find-file)))
6154 anything-type-attributes))
6155 (desc "anything-approximate-candidate-number")
6156 (expect 0
6157 (with-temp-buffer
6158 (let ((anything-buffer (current-buffer)))
6159 (anything-approximate-candidate-number))))
6160 (expect 1
6161 (with-temp-buffer
6162 (let ((anything-buffer (current-buffer)))
6163 (insert "Title\n"
6164 "candiate1\n")
6165 (anything-approximate-candidate-number))))
6166 (expect t
6167 (with-temp-buffer
6168 (let ((anything-buffer (current-buffer)))
6169 (insert "Title\n"
6170 "candiate1\n"
6171 "candiate2\n")
6172 (<= 2 (anything-approximate-candidate-number)))))
6173 (expect 1
6174 (with-temp-buffer
6175 (let ((anything-buffer (current-buffer)))
6176 (insert "Title\n"
6177 (propertize "multi\nline\n" 'anything-multiline t))
6178 (anything-approximate-candidate-number))))
6179 (expect t
6180 (with-temp-buffer
6181 (let ((anything-buffer (current-buffer))
6182 (anything-candidate-separator "-----"))
6183 (insert "Title\n"
6184 (propertize "multi\nline1\n" 'anything-multiline t)
6185 "-----\n"
6186 (propertize "multi\nline2\n" 'anything-multiline t))
6187 (<= 2 (anything-approximate-candidate-number)))))
6188 (desc "delayed-init attribute")
6189 (expect 0
6190 (let ((value 0))
6191 (anything-test-candidates '(((name . "test")
6192 (delayed-init . (lambda () (incf value)))
6193 (candiates "abc")
6194 (requires-pattern . 2)))
6196 value))
6197 (expect 1
6198 (let ((value 0))
6199 (anything-test-candidates '(((name . "test")
6200 (delayed-init . (lambda () (incf value)))
6201 (candiates "abc")
6202 (requires-pattern . 2)))
6203 "abc")
6204 value))
6205 (expect 2
6206 (let ((value 0))
6207 (anything-test-candidates '(((name . "test")
6208 (delayed-init (lambda () (incf value))
6209 (lambda () (incf value)))
6210 (candiates "abc")
6211 (requires-pattern . 2)))
6212 "abc")
6213 value))
6214 (expect t
6215 (let (value)
6216 (with-temp-buffer
6217 (anything-test-candidates '(((name . "test")
6218 (delayed-init
6219 . (lambda () (setq value
6220 (eq anything-current-buffer (current-buffer)))))
6221 (candiates "abc")
6222 (requires-pattern . 2)))
6223 "abc")
6224 value)))
6225 (desc "pattern-transformer attribute")
6226 (expect '(("test2" ("foo")) ("test3" ("bar")))
6227 (anything-test-candidates '(((name . "test1")
6228 (candidates "foo" "bar"))
6229 ((name . "test2")
6230 (pattern-transformer . (lambda (pat) (substring pat 1)))
6231 (candidates "foo" "bar"))
6232 ((name . "test3")
6233 (pattern-transformer . (lambda (pat) "bar"))
6234 (candidates "foo" "bar")))
6235 "xfoo"))
6236 (expect '(("test2" ("foo")) ("test3" ("bar")))
6237 (anything-test-candidates '(((name . "test1")
6238 (candidates "foo" "bar"))
6239 ((name . "test2")
6240 (pattern-transformer (lambda (pat) (substring pat 1)))
6241 (candidates "foo" "bar"))
6242 ((name . "test3")
6243 (pattern-transformer (lambda (pat) "bar"))
6244 (candidates "foo" "bar")))
6245 "xfoo"))
6246 (expect '(("test2" ("foo")) ("test3" ("bar")))
6247 (anything-test-candidates '(((name . "test1")
6248 (init
6249 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
6250 (insert "foo\nbar\n"))))
6251 (candidates-in-buffer))
6252 ((name . "test2")
6253 (pattern-transformer . (lambda (pat) (substring pat 1)))
6254 (init
6255 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
6256 (insert "foo\nbar\n"))))
6257 (candidates-in-buffer))
6258 ((name . "test3")
6259 (pattern-transformer . (lambda (pat) "bar"))
6260 (init
6261 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
6262 (insert "foo\nbar\n"))))
6263 (candidates-in-buffer)))
6264 "xfoo"))
6265 (desc "anything-recent-push")
6266 (expect '("foo" "bar" "baz")
6267 (let ((lst '("bar" "baz")))
6268 (anything-recent-push "foo" 'lst)))
6269 (expect '("foo" "bar" "baz")
6270 (let ((lst '("foo" "bar" "baz")))
6271 (anything-recent-push "foo" 'lst)))
6272 (expect '("foo" "bar" "baz")
6273 (let ((lst '("bar" "foo" "baz")))
6274 (anything-recent-push "foo" 'lst)))
6275 (desc "anything-require-at-least-version")
6276 (expect nil
6277 (anything-require-at-least-version "1.1"))
6278 (expect nil
6279 (anything-require-at-least-version "1.200"))
6280 (expect nil
6281 (anything-require-at-least-version
6282 (and (string-match "1\.\\([0-9]+\\)" anything-version)
6283 (match-string 0 anything-version))))
6284 (expect (error)
6285 (anything-require-at-least-version "1.999"))
6286 (expect (error)
6287 (anything-require-at-least-version "1.2000"))
6288 (desc "anything-once")
6289 (expect 2
6290 (let ((i 0))
6291 (anything-test-candidates
6292 '(((name . "1")
6293 (init . (lambda () (incf i))))
6294 ((name . "2")
6295 (init . (lambda () (incf i))))))
6297 (expect 1
6298 (let ((i 0))
6299 (anything-test-candidates
6300 '(((name . "1")
6301 (init . (lambda () (anything-once (lambda () (incf i))))))
6302 ((name . "2")
6303 (init . (lambda () (anything-once (lambda () (incf i))))))))
6305 (expect 1
6306 (let ((i 0))
6307 (flet ((init1 () (anything-once (lambda () (incf i)))))
6308 (anything-test-candidates
6309 '(((name . "1")
6310 (init . init1))
6311 ((name . "2")
6312 (init . init1)))))
6314 (desc "anything-marked-candidates")
6315 (expect '("mark3" "mark1")
6316 (let* ((source '((name . "mark test")))
6317 (anything-marked-candidates
6318 `((,source . "mark1")
6319 (((name . "other")) . "mark2")
6320 (,source . "mark3"))))
6321 (stub anything-get-current-source => source)
6322 (anything-marked-candidates)))
6323 (expect '("current")
6324 (let* ((source '((name . "mark test")))
6325 (anything-marked-candidates nil))
6326 (stub anything-get-current-source => source)
6327 (stub anything-get-selection => "current")
6328 (anything-marked-candidates)))
6332 (provide 'anything)
6333 ;; How to save (DO NOT REMOVE!!)
6334 ;; (progn (magit-push) (emacswiki-post "anything.el"))
6335 ;;; anything.el ends here