New variable: `anything-debug-variables'
[anything-config.git] / anything.el
blob929644eb664433befc7565d1a0b911d24f6eda7f
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 ;;; Commands:
56 ;; Below are complete command list:
58 ;; `anything'
59 ;; Select anything. In Lisp program, some optional arguments can be used.
60 ;; `anything-resume'
61 ;; Resurrect previously invoked `anything'.
62 ;; `anything-at-point'
63 ;; Same as `anything' except when C-u is pressed, the initial input is the symbol at point.
64 ;; `anything-force-update'
65 ;; Recalculate and update candidates.
66 ;; `anything-select-action'
67 ;; Select an action for the currently selected candidate.
68 ;; `anything-previous-line'
69 ;; Move selection to the previous line.
70 ;; `anything-next-line'
71 ;; Move selection to the next line.
72 ;; `anything-previous-page'
73 ;; Move selection back with a pageful.
74 ;; `anything-next-page'
75 ;; Move selection forward with a pageful.
76 ;; `anything-beginning-of-buffer'
77 ;; Move selection at the top.
78 ;; `anything-end-of-buffer'
79 ;; Move selection at the bottom.
80 ;; `anything-previous-source'
81 ;; Move selection to the previous source.
82 ;; `anything-next-source'
83 ;; Move selection to the next source.
84 ;; `anything-exit-minibuffer'
85 ;; Select the current candidate by exiting the minibuffer.
86 ;; `anything-help'
87 ;; Help of `anything'.
88 ;; `anything-debug-output'
89 ;; Show all anything-related variables at this time.
90 ;; `anything-delete-current-selection'
91 ;; Delete the currently selected item.
92 ;; `anything-delete-minibuffer-content'
93 ;; Same as `delete-minibuffer-contents' but this is a command.
94 ;; `anything-toggle-resplit-window'
95 ;; Toggle resplit anything window, vertically or horizontally.
96 ;; `anything-select-2nd-action'
97 ;; Select the 2nd action for the currently selected candidate.
98 ;; `anything-select-3rd-action'
99 ;; Select the 3rd action for the currently selected candidate.
100 ;; `anything-select-4th-action'
101 ;; Select the 4th action for the currently selected candidate.
102 ;; `anything-select-2nd-action-or-end-of-line'
103 ;; Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
104 ;; `anything-execute-persistent-action'
105 ;; If a candidate is selected then perform the associated action without quitting anything.
106 ;; `anything-scroll-other-window'
107 ;; Scroll other window (not *Anything* window) upward.
108 ;; `anything-scroll-other-window-down'
109 ;; Scroll other window (not *Anything* window) downward.
110 ;; `anything-quit-and-find-file'
111 ;; Drop into `find-file' from `anything' like `iswitchb-find-file'.
112 ;; `anything-yank-selection'
113 ;; Set minibuffer contents to current selection.
114 ;; `anything-kill-selection-and-quit'
115 ;; Store current selection to kill ring.
116 ;; `anything-follow-mode'
117 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
118 ;; `anything-isearch'
119 ;; Start incremental search within results. (UNMAINTAINED)
120 ;; `anything-isearch-printing-char'
121 ;; Add printing char to the pattern.
122 ;; `anything-isearch-again'
123 ;; Search again for the current pattern
124 ;; `anything-isearch-delete'
125 ;; Undo last event.
126 ;; `anything-isearch-default-action'
127 ;; Execute the default action for the selected candidate.
128 ;; `anything-isearch-select-action'
129 ;; Choose an action for the selected candidate.
130 ;; `anything-isearch-cancel'
131 ;; Cancel Anything isearch.
132 ;; `anything-iswitchb-setup'
133 ;; Integrate anything completion into iswitchb (UNMAINTAINED).
134 ;; `anything-iswitchb-cancel-anything'
135 ;; Cancel anything completion and return to standard iswitchb.
136 ;; `anything-describe-anything-attribute'
137 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
139 ;;; Customizable Options:
141 ;; Below are customizable option list:
144 ;; You can extend `anything' by writing plug-ins. As soon as
145 ;; `anything' is invoked, `anything-sources' is compiled into basic
146 ;; attributes, then compiled one is used during invocation.
148 ;; The oldest built-in plug-in is `type' attribute: appends
149 ;; appropriate element of `anything-type-attributes'. Second built-in
150 ;; plug-in is `candidates-in-buffer': selecting a line from candidates
151 ;; buffer.
153 ;; To write a plug-in:
154 ;; 1. Define a compiler: anything-compile-source--*
155 ;; 2. Add compier function to `anything-compile-source-functions'.
156 ;; 3. (optional) Write helper functions.
158 ;; Anything plug-ins are found in the EmacsWiki.
160 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
162 ;; Tested on Emacs 22/23.
165 ;; Thanks to Vagn Johansen for ideas.
166 ;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
167 ;; Thanks to Tassilo Horn for fixes.
168 ;; Thanks to Drew Adams for various fixes (frame, isearch, customization, etc.)
169 ;; Thanks to IMAKADO for candidates-in-buffer idea.
170 ;; Thanks to Tomohiro MATSUYAMA for multiline patch.
173 ;;; (@* "Index")
175 ;; If you have library `linkd.el', load
176 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
177 ;; navigate around the sections Linkd mode will
178 ;; highlight this Index. You can get `linkd.el' here:
179 ;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
183 ;;; (@* "INCOMPATIBLE CHANGES")
185 ;; v1.277
187 ;; Default setting of `anything-save-configuration-functions' is changed.
188 ;; Anything saves/restores window configuration instead of frame configuration now.
189 ;; The default is changed because flickering is occurred in some environment.
191 ;; If you want to save and restore frame configuration, set this variable to
192 ;; '(set-frame-configuration . current-frame-configuration)
194 ;; v1.276
196 ;; Fitting frame is disabled by default, because some flickering occurred
197 ;; in some environment. To enable fitting, set both
198 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
199 ;; nil.
201 ;; v1.114
203 ;; `anything-attr' returns nil when the source attribute is defined
204 ;; but the value of attribute is nil, eg. (volatile) cell. Use
205 ;; `anything-attr-defined' when testing whether the attribute is
206 ;; defined.
208 ;;; (@* "Tips")
211 ;; If you want to create anything sources, yasnippet would help you.
212 ;; http://yasnippet.googlecode.com/
214 ;; Then get the snippet from
215 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
217 ;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
221 ;; `anything-interpret-value' is useful function to interpret value
222 ;; like `candidates' attribute.
224 ;; (anything-interpret-value "literal") ; => "literal"
225 ;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
226 ;; (let ((source '((name . "lambda with source name"))))
227 ;; (anything-interpret-value
228 ;; (lambda () anything-source-name)
229 ;; source)) ; => "lambda with source name"
230 ;; (flet ((f () "function symbol"))
231 ;; (anything-interpret-value 'f)) ; => "function symbol"
232 ;; (let ((v "variable symbol"))
233 ;; (anything-interpret-value 'v)) ; => "variable symbol"
234 ;; (anything-interpret-value 'unbounded-1) ; error
237 ;; Now symbols are acceptable as candidates. So you do not have to use
238 ;; `symbol-name' function. The source is much simpler. For example,
239 ;; `apropos-internal' returns a list of symbols.
241 ;; (anything
242 ;; '(((name . "Commands")
243 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
244 ;; (volatile)
245 ;; (action . describe-function))))
248 ;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
249 ;; marked candidate, press M-[ or M-].
252 ;; `anything-map' is now Emacs-standard key bindings by default. If
253 ;; you are using `iswitchb', execute `anything-iswitchb-setup'. Then
254 ;; some key bindings are adjusted to `iswitchb'. Note that
255 ;; anything-iswitchb is not maintained.
258 ;; There are many `anything' applications, using `anything' for
259 ;; selecting candidate. In this case, if there is one candidate or no
260 ;; candidate, popping up *anything* buffer is irritating. If one
261 ;; candidate, you want to select it at once. If no candidate, you want
262 ;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
263 ;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
264 ;; that setting these variables GLOBALLY is bad idea because of
265 ;; delayed sources. These are meant to be let-binded.
266 ;; See anything-etags.el for example.
268 ;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
270 ;; ex.
271 ;; (let ((anything-execute-action-at-once-if-one t)
272 ;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
273 ;; (anything temporary-sources input))
276 ;; `set-frame-configuration' arises flickering. If you hate
277 ;; flickering, eval:
278 ;; (setq anything-save-configuration-functions
279 ;; '(set-window-configuration . current-window-configuration))
280 ;; at the cost of restoring frame configuration (only window configuration).
283 ;; `anything-delete-current-selection' deletes the current line.
284 ;; It is useful when deleting a candidate in persistent action.
285 ;; eg. `kill-buffer'.
287 ;; [EVAL IT] (describe-function 'anything-delete-current-selection)
290 ;; `anything-attr' gets the attribute. `anything-attrset' sets the
291 ;; attribute. `anything-attr-defined' tests whether the attribute is
292 ;; defined. They handles source-local variables.
294 ;; [EVAL IT] (describe-function 'anything-attr)
295 ;; [EVAL IT] (describe-function 'anything-attrset)
296 ;; [EVAL IT] (describe-function 'anything-attr-defined)
299 ;; `anything-sources' accepts many attributes to make your life easier.
300 ;; Now `anything-sources' accepts a list of symbols.
302 ;; [EVAL IT] (describe-variable 'anything-sources)
305 ;; `anything' has optional arguments. Now you do not have to let-bind
306 ;; `anything-sources'.
308 ;; [EVAL IT] (describe-function 'anything)
311 ;; `anything-resume' resumes last `anything' session. Now you do not
312 ;; have to retype pattern.
314 ;; [EVAL IT] (describe-function 'anything-resume)
317 ;; `anything-execute-persistent-action' executes action without
318 ;; quitting `anything'. When popping up a buffer in other window by
319 ;; persistent action, you can scroll with `anything-scroll-other-window' and
320 ;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
322 ;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
323 ;; [EVAL IT] (describe-variable 'anything-sources)
326 ;; `anything-select-2nd-action', `anything-select-3rd-action' and
327 ;; `anything-select-4th-action' select other than default action
328 ;; without pressing Tab.
331 ;; Using `anything-candidate-buffer' and the candidates-in-buffer
332 ;; attribute is much faster than traditional "candidates and match"
333 ;; way. And `anything-current-buffer-is-modified' avoids to
334 ;; recalculate candidates for unmodified buffer. See docstring of
335 ;; them.
337 ;; [EVAL IT] (describe-function 'anything-candidate-buffer)
338 ;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
339 ;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
342 ;; `anything-current-buffer' and `anything-buffer-file-name' stores
343 ;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
344 ;; is invoked. Use them freely.
346 ;; [EVAL IT] (describe-variable 'anything-current-buffer)
347 ;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
350 ;; `anything-completing-read' and `anything-read-file-name' are
351 ;; experimental implementation. If you are curious, type M-x
352 ;; anything-read-string-mode. It is a minor mode and toggles on/off.
355 ;; Use `anything-test-candidates' to test your handmade anything
356 ;; sources. It simulates contents of *anything* buffer with pseudo
357 ;; `anything-sources' and `anything-pattern', without side-effect. So
358 ;; you can unit-test your anything sources! Let's TDD!
360 ;; [EVAL IT] (describe-function 'anything-test-candidates)
362 ;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
363 ;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
365 ;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
366 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
367 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
370 ;; (@* "TODO")
372 ;; - process status indication
374 ;; - async sources doesn't honor digit-shortcut-count
376 ;; - anything-candidate-number-limit can't be nil everywhere
378 ;; (@* "HISTORY")
379 ;; $Log: anything.el,v $
380 ;; Revision 1.280 2010-04-01 02:22:22 rubikitch
381 ;; `anything': new argument ANY-KEYMAP
383 ;; Revision 1.279 2010/03/31 09:22:58 rubikitch
384 ;; Add tips of yasnippet for source creators (no code change)
386 ;; Revision 1.278 2010/03/31 09:01:08 rubikitch
387 ;; Added info to INCOMPATIBLE CHANGES
389 ;; Revision 1.277 2010/03/31 08:56:53 rubikitch
390 ;; Anything saves/restores window configuration instead of frame configuration now.
391 ;; The default is changed because flickering is occurred in some environment.
393 ;; If you want to save and restore frame configuration, set this variable to
394 ;; '(set-frame-configuration . current-frame-configuration)
396 ;; Revision 1.276 2010/03/31 08:52:50 rubikitch
397 ;; Fitting frame is disabled by default, because some flickering occurred
398 ;; in some environment. To enable fitting, set both
399 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
400 ;; nil.
402 ;; Revision 1.275 2010/03/31 02:46:09 rubikitch
403 ;; (defvaralias 'anything-attributes 'anything-additional-attributes)
405 ;; Revision 1.274 2010/03/31 02:43:35 rubikitch
406 ;; New command: `anything-describe-anything-attribute'
408 ;; Revision 1.273 2010/03/31 02:37:18 rubikitch
409 ;; Document all attributes by `anything-document-attribute' instead of `anything-sources' docstring
411 ;; Revision 1.272 2010/03/29 21:05:47 rubikitch
412 ;; `anything-mode-line-string': use `make-local-variable' instead
414 ;; Revision 1.271 2010/03/29 09:59:17 rubikitch
415 ;; stupid bug
417 ;; Revision 1.270 2010/03/29 09:56:12 rubikitch
418 ;; Call `filtered-candidate-transformer' functions even if process sources
420 ;; Revision 1.269 2010/03/29 08:42:23 rubikitch
421 ;; * New attribute `resume'
422 ;; * Fix a bug of `disable-shortcuts' plug-in
424 ;; Revision 1.268 2010/03/28 21:42:01 rubikitch
425 ;; Add some keys in `anything-help'
427 ;; Revision 1.267 2010/03/28 20:11:30 rubikitch
428 ;; Modify `anything-mode-line-string'
430 ;; Revision 1.266 2010/03/28 06:12:43 rubikitch
431 ;; process source and multiline: in the making (not usable)
433 ;; Revision 1.265 2010/03/28 05:07:00 rubikitch
434 ;; Change default `anything-sources'. It is only a sample, no problem.
436 ;; Revision 1.264 2010/03/27 19:02:52 rubikitch
437 ;; New attributes: `mode-line' and `header-line'
439 ;; Revision 1.263 2010/03/27 02:34:40 rubikitch
440 ;; doc
442 ;; Revision 1.262 2010/03/27 02:31:55 rubikitch
443 ;; New command: `anything-force-update' C-c C-u
445 ;; Revision 1.261 2010/03/27 02:29:39 rubikitch
446 ;; New function `anything-goto-source'
448 ;; Revision 1.260 2010/03/27 02:01:28 rubikitch
449 ;; reimplement move selection commands
451 ;; Revision 1.259 2010/03/26 22:52:15 rubikitch
452 ;; `anything-quit-and-find-file':
453 ;; If current selection is a buffer or a file, `find-file' from its directory.
454 ;; Idea from http://i-yt.info/?date=20090826#p01 with some modification. Thanks.
456 ;; Revision 1.258 2010/03/26 12:10:55 rubikitch
457 ;; * modify `anything-mode-line-string'
458 ;; * New command `anything-help'
460 ;; Revision 1.257 2010/03/24 11:08:19 rubikitch
461 ;; revert to 1.255
463 ;; Revision 1.256 2010/03/24 08:29:43 rubikitch
464 ;; `anything-check-minibuffer-input' set repeat timer.
466 ;; Revision 1.255 2010/03/24 02:35:47 rubikitch
467 ;; `anything-candidate-number-limit':
468 ;; When (candidate-number-limit) is specified in SOURCE,
469 ;; cancel the effect of `anything-candidate-number-limit'.
471 ;; Revision 1.254 2010/03/23 00:33:18 rubikitch
472 ;; New API: `anything-interpret-value'
474 ;; Revision 1.253 2010/03/22 07:04:03 rubikitch
475 ;; `anything-get-current-source': return nil when no candidates rather than error
477 ;; Revision 1.252 2010/03/21 06:08:44 rubikitch
478 ;; Mark bug fix. thx hchbaw!
479 ;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
481 ;; Revision 1.251 2010/03/21 02:39:34 rubikitch
482 ;; Fix a wrong usage of `delq'. thx hchbaw.
483 ;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
485 ;; Revision 1.250 2010/03/21 02:32:29 rubikitch
486 ;; Fix `select deleted buffer' error message when calling `anything-resume'.
488 ;; It was occurred when killing `anything-current-buffer' and calling `anything-resume'.
490 ;; Revision 1.249 2010/02/23 20:43:35 rubikitch
491 ;; `anything-update': Ensure to call `anything-next-line'
493 ;; Revision 1.248 2010/02/20 12:34:38 rubikitch
494 ;; Mode-line help!! `anything-mode-line-string' is help string.
496 ;; Revision 1.247 2010/02/20 10:41:39 rubikitch
497 ;; Automatically update `anything-version' when upgrading
499 ;; Revision 1.246 2010/02/20 10:38:58 rubikitch
500 ;; update copyright
502 ;; Revision 1.245 2010/02/20 10:36:01 rubikitch
503 ;; New API: `anything-require-at-least-version'
505 ;; Revision 1.244 2010/02/20 10:06:54 rubikitch
506 ;; * New plug-in: `disable-shortcuts'
507 ;; * `dummy' plug-in implies `disable-shortcuts' because it enables us to input capital letters.
509 ;; Revision 1.243 2010/02/20 09:54:16 rubikitch
510 ;; `anything-compile-source--dummy': swap arguments of `append'
512 ;; Revision 1.242 2010/02/19 17:37:12 rubikitch
513 ;; error check in `anything-set-source-filter'
515 ;; Revision 1.241 2010/01/29 18:53:17 rubikitch
516 ;; Fix a bug of `candidate-number-limit' in process sources.
518 ;; Revision 1.240 2010/01/23 04:21:31 rubikitch
519 ;; * `anything': Use `anything-display-buffer' as fallback
520 ;; * `anything-select-with-digit-shortcut': `self-insert-command' if disabled
522 ;; Revision 1.239 2009/12/28 07:33:28 rubikitch
523 ;; New command: `anything-toggle-resplit-window' (C-t)
525 ;; Revision 1.238 2009/12/28 07:19:37 rubikitch
526 ;; bugfix
528 ;; Revision 1.237 2009/12/28 07:15:30 rubikitch
529 ;; `anything-window-configuration' stores window configuration only.
531 ;; Revision 1.236 2009/12/28 07:07:09 rubikitch
532 ;; `anything-resume' resumes window configuration now.
534 ;; Revision 1.235 2009/12/28 04:12:33 rubikitch
535 ;; Fix tiny bug
537 ;; Revision 1.234 2009/12/28 03:57:33 rubikitch
538 ;; `anything-resume': New optional argument
540 ;; Revision 1.233 2009/12/28 03:43:12 rubikitch
541 ;; remove warnings
543 ;; Revision 1.232 2009/12/28 03:37:25 rubikitch
544 ;; refactoring
546 ;; Revision 1.231 2009/12/28 02:33:41 rubikitch
547 ;; refactoring
549 ;; Revision 1.230 2009/12/27 09:28:06 rubikitch
550 ;; `anything-window-configuration' save/restore anything window configuration (NOT YET)
552 ;; Revision 1.229 2009/12/26 21:41:33 rubikitch
553 ;; revive `anything-input' when resuming
555 ;; Revision 1.228 2009/12/25 01:34:35 rubikitch
556 ;; * `anything-resume' use anything interface to select anything buffers.
557 ;; * Its candidates are sorted by most recently used order.
558 ;; * 4th arg of `anything' accepts 'noresume not to resume this session.
560 ;; Revision 1.227 2009/12/19 20:30:12 rubikitch
561 ;; add `pattern-transformer' doc
563 ;; Revision 1.226 2009/12/19 20:15:47 rubikitch
564 ;; pattern-transformer can have multiple functions now
566 ;; Revision 1.225 2009/12/19 20:11:16 rubikitch
567 ;; add `delayed-init' doc
569 ;; Revision 1.224 2009/12/19 12:26:00 rubikitch
570 ;; New attribute `pattern-transformer'
572 ;; Revision 1.223 2009/12/19 11:57:41 rubikitch
573 ;; New attribute `delayed-init'
575 ;; Revision 1.222 2009/12/14 20:55:23 rubikitch
576 ;; Fix display bug: `anything-enable-digit-shortcuts' / multiline
578 ;; Revision 1.221 2009/12/14 20:29:49 rubikitch
579 ;; fix an error when executing `anything-prev-visible-mark' with no visible marks.
581 ;; Revision 1.220 2009/12/14 20:19:05 rubikitch
582 ;; Bugfix about anything-execute-action-at-once-if-one and multiline
584 ;; Revision 1.219 2009/12/14 03:21:11 rubikitch
585 ;; Extend alphabet shortcuts to A-Z
587 ;; Revision 1.218 2009/12/13 01:03:34 rubikitch
588 ;; Changed data structure of `anything-shortcut-keys-alist'
590 ;; Revision 1.217 2009/12/03 23:16:17 rubikitch
591 ;; silence warning
593 ;; Revision 1.216 2009/12/03 20:43:51 rubikitch
594 ;; Add keybindings for alphabet shortcuts
596 ;; Revision 1.215 2009/12/03 20:37:13 rubikitch
597 ;; `anything-enable-shortcuts' is an alias of `anything-enable-digit-shortcuts'.
598 ;; Alphabet shortcuts can be used now.
600 ;; Revision 1.214 2009/12/03 20:23:40 rubikitch
601 ;; `anything-enable-digit-shortcuts' also accepts 'alphabet.
603 ;; Now alphabet shortcuts are usable.
605 ;; Revision 1.213 2009/12/03 09:59:58 rubikitch
606 ;; refactoring
608 ;; Revision 1.212 2009/11/15 09:42:15 rubikitch
609 ;; refactoring
611 ;; Revision 1.211 2009/11/06 21:42:58 rubikitch
612 ;; New command: `anything-beginning-of-buffer', `anything-end-of-buffer'
614 ;; Revision 1.210 2009/10/22 13:30:06 rubikitch
615 ;; `real-to-display' function is evaluated just after `candidate-transformer' function now.
616 ;; This enables us to narrow candidates by display string by `real-to-display'.
618 ;; Revision 1.209 2009/10/21 20:25:10 rubikitch
619 ;; Add a document. (no code change)
621 ;; Revision 1.208 2009/10/21 11:31:15 rubikitch
622 ;; `anything': accept one source alist
624 ;; Revision 1.207 2009/10/16 19:47:39 rubikitch
625 ;; Link to Japanese translation of `anything-sources' attributes. (No code change)
627 ;; Revision 1.206 2009/10/10 09:28:54 rubikitch
628 ;; Remove an unnecessary test
630 ;; Revision 1.205 2009/10/10 06:21:28 rubikitch
631 ;; obsolete: `anything-c-marked-candidate-list'
632 ;; New function: `anything-marked-candidates'
634 ;; Revision 1.204 2009/10/06 21:01:12 rubikitch
635 ;; Call `anything-process-delayed-sources' only if delayed-sources is available.
637 ;; Revision 1.203 2009/10/02 10:04:07 rubikitch
638 ;; Tested on Emacs23 too. (no code change)
640 ;; Revision 1.202 2009/10/02 10:03:34 rubikitch
641 ;; * Display "no candidates" rather than assertion
642 ;; * Ensure to call `remove-hook' in `anything-current-buffer'
644 ;; Revision 1.201 2009/08/08 13:25:30 rubikitch
645 ;; `anything-toggle-visible-mark': move next line after unmarking
647 ;; Revision 1.200 2009/08/08 13:23:46 rubikitch
648 ;; `anything-toggle-visible-mark': Applied ThierryVolpiatto's patch. thx.
650 ;; Revision 1.199 2009/07/19 13:22:29 rubikitch
651 ;; `anything-follow-execute-persistent-action-maybe': execute persistent action after `anything-input-idle-delay'
653 ;; Revision 1.198 2009/07/06 15:22:48 rubikitch
654 ;; header modified (no code change)
656 ;; Revision 1.197 2009/06/29 15:10:13 rubikitch
657 ;; OOPS! remove debug code
659 ;; Revision 1.196 2009/06/29 13:29:25 rubikitch
660 ;; anything-follow-mode: automatical execution of persistent-action (C-c C-f)
662 ;; Revision 1.195 2009/06/19 14:42:57 rubikitch
663 ;; silence byte compiler
665 ;; Revision 1.194 2009/06/14 15:12:34 rubikitch
666 ;; typo
668 ;; Revision 1.193 2009/06/08 19:37:12 rubikitch
669 ;; typo!
671 ;; Revision 1.192 2009/06/08 19:36:39 rubikitch
672 ;; New keybind: C-e, C-j, C-k
674 ;; Revision 1.191 2009/06/08 19:30:27 rubikitch
675 ;; New command: `anything-select-2nd-action-or-end-of-line'
677 ;; Revision 1.190 2009/06/07 17:09:50 rubikitch
678 ;; add M-<next>, C-M-S-v, M-<prior> to `anything-map'.
680 ;; Revision 1.189 2009/06/01 21:36:31 rubikitch
681 ;; New function: `anything-other-buffer'
683 ;; Revision 1.188 2009/05/29 18:33:07 rubikitch
684 ;; avoid error when executing (anything-mark-current-line) in async process.
686 ;; Revision 1.187 2009/05/29 06:49:05 rubikitch
687 ;; small refactoring
689 ;; Revision 1.186 2009/05/29 06:46:34 rubikitch
690 ;; Prevent `anything-isearch-map' from overwriting `global-map'. With
691 ;; `copy-keymap', the prefix command "M-s" in `global-map' ends up
692 ;; getting clobbered by `anything-isearch-again', preventing `occur'
693 ;; (among other things) from running. This change replaces overwriting a
694 ;; copied map with writing to a sparse map whose parent is `global-map'.
696 ;; patched by DanielHackney. thanks!
698 ;; Revision 1.185 2009/05/25 19:07:42 rubikitch
699 ;; `anything': set `case-fold-search' to t
700 ;; Because users can assign commands to capital letter keys.
702 ;; Revision 1.184 2009/05/25 19:05:04 rubikitch
703 ;; Added auto-document
705 ;; Revision 1.183 2009/05/15 01:50:46 rubikitch
706 ;; typo
708 ;; Revision 1.182 2009/05/08 18:28:18 rubikitch
709 ;; Bug fix: `anything-attr' is usable in `header-name' function.
711 ;; Revision 1.181 2009/05/04 19:05:03 rubikitch
712 ;; * `anything-yank-selection' and `anything-kill-selection-and-quit' handles display string now.
713 ;; * `anything-get-selection': Added optional arguments.
715 ;; Revision 1.180 2009/05/03 19:03:34 rubikitch
716 ;; Add `anything-input' to `minibuffer-history' even if `anything' is quit.
718 ;; Revision 1.179 2009/04/20 16:35:44 rubikitch
719 ;; New keybindings in anything-map:
720 ;; C-c C-d: `anything-delete-current-selection'
721 ;; C-c C-y: `anything-yank-selection'
722 ;; C-c C-k: `anything-kill-selection-and-quit'
724 ;; Revision 1.178 2009/04/20 16:18:58 rubikitch
725 ;; New variable: `anything-display-function'
727 ;; Revision 1.177 2009/04/20 02:17:16 rubikitch
728 ;; New commands: `anything-yank-selection', `anything-kill-selection-and-quit'
730 ;; Revision 1.176 2009/04/08 14:48:15 rubikitch
731 ;; bug fix in `anything-candidate-buffer'
733 ;; Revision 1.175 2009/03/22 19:10:37 rubikitch
734 ;; New Variable: `anything-scroll-amount' (thx. ThierryVolpiatto)
736 ;; Revision 1.174 2009/03/12 19:12:24 rubikitch
737 ;; New API: `define-anything-type-attribute'
739 ;; Revision 1.173 2009/03/11 08:10:32 rubikitch
740 ;; Update doc
742 ;; Revision 1.172 2009/03/10 17:11:58 rubikitch
743 ;; `candidate-transformer', `filtered-candidate-transformer',
744 ;; `action-transformer' attributes: accept a list of functions
746 ;; Revision 1.171 2009/03/09 18:49:44 rubikitch
747 ;; New command: `anything-quit-and-find-file'
749 ;; Revision 1.170 2009/03/09 18:46:11 rubikitch
750 ;; New API: `anything-run-after-quit'
752 ;; Revision 1.169 2009/03/09 10:02:49 rubikitch
753 ;; Set candidate-number-limit attribute for actions.
755 ;; Revision 1.168 2009/03/07 21:01:10 rubikitch
756 ;; Bug workaround
758 ;; Revision 1.167 2009/03/06 04:13:42 rubikitch
759 ;; Fix doc
761 ;; Revision 1.166 2009/03/03 10:35:57 rubikitch
762 ;; Set default `anything-input-idle-delay' to 0.1
764 ;; Revision 1.165 2009/03/03 07:14:42 rubikitch
765 ;; Make sure to run `anything-update-hook' after processing delayed sources.
767 ;; Revision 1.164 2009/03/02 01:51:40 rubikitch
768 ;; better error handling.
770 ;; Revision 1.163 2009/03/01 05:15:00 rubikitch
771 ;; anything-iswitchb and anything-isearch are marked as unmaintained.
772 ;; (document change only)
774 ;; Revision 1.162 2009/02/28 01:24:13 rubikitch
775 ;; Symbols are now acceptable as candidate.
777 ;; Revision 1.161 2009/02/27 07:18:46 rubikitch
778 ;; Fix bug of `anything-scroll-other-window' and `anything-scroll-other-window-down'.
780 ;; Revision 1.160 2009/02/27 01:05:06 rubikitch
781 ;; * Make sure to restore point after running `anything-update-hook'.
782 ;; * Make `anything-compute-matches' easy to find error.
784 ;; Revision 1.159 2009/02/26 23:45:48 rubikitch
785 ;; * Check whether candidate is a string, otherwise ignore.
787 ;; Revision 1.158 2009/02/24 06:39:20 rubikitch
788 ;; suppress compile warnings.
790 ;; Revision 1.157 2009/02/23 22:51:43 rubikitch
791 ;; New function: `anything-document-attribute'
793 ;; Revision 1.156 2009/02/23 21:36:09 rubikitch
794 ;; New Variable: `anything-display-source-at-screen-top'
796 ;; Revision 1.155 2009/02/23 21:30:52 rubikitch
797 ;; New command: `anything-at-point'
799 ;; Revision 1.154 2009/02/23 08:57:54 rubikitch
800 ;; Visible Mark
802 ;; Revision 1.153 2009/02/23 08:38:57 rubikitch
803 ;; update doc
805 ;; Revision 1.152 2009/02/23 08:32:17 rubikitch
806 ;; More key bindings.
808 ;; Revision 1.151 2009/02/23 08:21:24 rubikitch
809 ;; `anything-map' is now Emacs-standard key bindings by default.
810 ;; After evaluating `anything-iswitchb-setup'. some key bindings are adjusted to iswitchb.
812 ;; Revision 1.150 2009/02/20 22:58:18 rubikitch
813 ;; Cancel timer in `anything-cleanup'.
815 ;; Revision 1.149 2009/02/20 12:23:44 rubikitch
816 ;; `anything-header' face now inherits header-line (not a copy).
818 ;; Revision 1.148 2009/02/16 23:40:22 rubikitch
819 ;; `real-to-display' attribute bug fix.
821 ;; Revision 1.147 2009/02/02 20:51:41 rubikitch
822 ;; New `anything-sources' attribute: real-to-display
824 ;; Revision 1.146 2009/02/01 20:01:00 rubikitch
825 ;; Update Tips
827 ;; Revision 1.145 2009/02/01 19:45:53 rubikitch
828 ;; New variable: `anything-quit-if-no-candidate'
830 ;; Revision 1.144 2009/02/01 19:31:47 rubikitch
831 ;; fixed a typo
833 ;; Revision 1.143 2009/02/01 19:23:32 rubikitch
834 ;; New variable: `anything-execute-action-at-once-if-one'
836 ;; Revision 1.142 2009/02/01 19:12:34 rubikitch
837 ;; `anything-persistent-action-display-buffer': bug fix
839 ;; Revision 1.141 2009/02/01 18:25:25 rubikitch
840 ;; * fix docstring
841 ;; * New variable: `anything-selection-face'
843 ;; Revision 1.140 2009/01/16 16:36:25 rubikitch
844 ;; New variable: `anything-persistent-action-use-special-display'.
846 ;; Revision 1.139 2009/01/05 20:15:53 rubikitch
847 ;; Fixed a bug of anything action buffer.
848 ;; The action source should not be cached.
850 ;; Revision 1.138 2008/12/21 16:56:05 rubikitch
851 ;; Fixed an error when action attribute is a function symbol and press TAB,
853 ;; Revision 1.137 2008/12/20 19:38:47 rubikitch
854 ;; `anything-check-minibuffer-input-1': proper quit handling
855 ;; `anything-process-delayed-sources': ditto
857 ;; Revision 1.136 2008/10/27 17:41:27 rubikitch
858 ;; `anything-process-delayed-sources', `anything-check-minibuffer-input-1': quittable
860 ;; Revision 1.135 2008/10/27 17:04:25 rubikitch
861 ;; arranged source, added more linkd tags (no code change)
863 ;; Revision 1.134 2008/10/27 15:02:25 rubikitch
864 ;; New variable: `anything-save-configuration-functions'
865 ;; Delete variable: `anything-save-configuration-type'
867 ;; Revision 1.133 2008/10/27 11:16:13 rubikitch
868 ;; New variable: `anything-save-configuration-type'
870 ;; Revision 1.132 2008/10/26 22:34:59 rubikitch
871 ;; `anything-delete-current-selection' with multiline
873 ;; Revision 1.131 2008/10/26 21:44:43 rubikitch
874 ;; New command: `anything-delete-current-selection'
876 ;; Revision 1.130 2008/10/22 10:41:09 rubikitch
877 ;; `anything-insert-match': do not override 'anything-realvalue property
879 ;; Revision 1.129 2008/10/21 17:01:37 rubikitch
880 ;; `anything-resume' per buffer.
881 ;; `anything-last-sources': obsolete
883 ;; Revision 1.128 2008/10/20 06:27:54 rubikitch
884 ;; `anything-quick-update': new user option
886 ;; Revision 1.127 2008/10/20 05:47:49 rubikitch
887 ;; refactoring
889 ;; Revision 1.126 2008/10/20 03:47:58 rubikitch
890 ;; `anything-update': reversed order of delayed sources
892 ;; Revision 1.125 2008/10/19 00:29:54 rubikitch
893 ;; kill buffer-local candidate buffers when creating global candidate buffers.
895 ;; Revision 1.124 2008/10/18 13:04:20 rubikitch
896 ;; Remove tick entry from `anything-tick-hash' when killing a buffer.
898 ;; Revision 1.123 2008/10/18 10:23:36 rubikitch
899 ;; multiline patch by Tomohiro MATSUYAMA.
901 ;; Revision 1.122 2008/10/13 03:10:07 rubikitch
902 ;; `anything': do `anything-mark-current-line' when resuming
904 ;; Revision 1.121 2008/10/13 03:08:08 rubikitch
905 ;; always set `anything-current-position'
907 ;; Revision 1.120 2008/10/07 14:12:02 rubikitch
908 ;; `anything-execute-persistent-action': optional arg
910 ;; Revision 1.119 2008/10/06 06:43:29 rubikitch
911 ;; `anything-candidate-buffer': return nil when the buffer is dead
913 ;; Revision 1.118 2008/09/30 22:21:28 rubikitch
914 ;; New `anything-sources' attribute: accept-empty
915 ;; dummy: include accept-empty
917 ;; Revision 1.117 2008/09/30 21:59:10 rubikitch
918 ;; New function: `anything-buffer-is-modified'
920 ;; Revision 1.116 2008/09/22 11:27:29 rubikitch
921 ;; *** empty log message ***
923 ;; Revision 1.115 2008/09/20 20:21:11 rubikitch
924 ;; added linkd index. (no code change)
926 ;; Revision 1.114 2008/09/20 20:09:57 rubikitch
927 ;; INCOMPATIBLE CHANGES: `anything-attr'
928 ;; New functions: `anything-attrset', `anything-attr-defined'
930 ;; Revision 1.113 2008/09/14 15:15:32 rubikitch
931 ;; bugfix: volatile and match attribute / process and match attribute
933 ;; Revision 1.112 2008/09/12 01:57:17 rubikitch
934 ;; When resuming anything, reinitialize overlays.
936 ;; Revision 1.111 2008/09/10 22:53:11 rubikitch
937 ;; anything: bug fix of `anything-buffer'
938 ;; New macro: `anything-test-update'
940 ;; Revision 1.110 2008/09/10 22:17:11 rubikitch
941 ;; New `anything-sources' attribute: header-name
943 ;; Revision 1.109 2008/09/10 21:12:26 rubikitch
944 ;; New hook: `anything-after-action-hook'
946 ;; Revision 1.108 2008/09/06 06:07:56 rubikitch
947 ;; Extended `anything-set-sources' optional arguments.
949 ;; Revision 1.107 2008/09/05 03:14:35 rubikitch
950 ;; reimplement `anything-current-buffer-is-modified' in the right way
952 ;; Revision 1.106 2008/09/05 00:11:05 rubikitch
953 ;; Moved `anything-read-string-mode' and read functions to anything-complete.el.
955 ;; Revision 1.105 2008/09/04 12:45:06 rubikitch
956 ;; New hook: `anything-after-persistent-action-hook'
958 ;; Revision 1.104 2008/09/04 12:27:05 rubikitch
959 ;; `anything': prefixed optional arguments
961 ;; Revision 1.103 2008/09/04 09:16:28 rubikitch
962 ;; fixed a bug of `anything-read-file-name'.
964 ;; Revision 1.102 2008/09/03 11:25:19 rubikitch
965 ;; Extended `anything' optional arguments: buffer
967 ;; Revision 1.101 2008/09/03 11:15:13 rubikitch
968 ;; `anything': return nil when keybord-quitted
970 ;; Revision 1.100 2008/09/01 23:11:02 rubikitch
971 ;; bug fix of search-from-end
973 ;; Revision 1.99 2008/09/01 13:45:55 rubikitch
974 ;; bug fix of search-from-end
976 ;; Revision 1.98 2008/09/01 11:23:38 rubikitch
977 ;; New `anything-sources' attribute: search-from-end
979 ;; Revision 1.97 2008/09/01 00:44:34 rubikitch
980 ;; Make sure to display the other window when persistent action.
982 ;; Revision 1.96 2008/08/31 20:55:20 rubikitch
983 ;; define `buffer-modified-tick' for older emacs.
985 ;; Revision 1.95 2008/08/30 04:55:51 rubikitch
986 ;; fixed a bug of `anything-completing-read'
988 ;; Revision 1.94 2008/08/28 20:18:03 rubikitch
989 ;; added some tests
991 ;; Revision 1.93 2008/08/25 20:18:46 rubikitch
992 ;; `anything': set `anything-input' and `anything-pattern' before `anything-update'
994 ;; Revision 1.92 2008/08/24 22:38:46 rubikitch
995 ;; *** empty log message ***
997 ;; Revision 1.91 2008/08/24 21:34:35 rubikitch
998 ;; rewrite `with-anything-restore-variables'
1000 ;; Revision 1.90 2008/08/24 20:33:02 rubikitch
1001 ;; prevent the unit test from byte-compiled.
1002 ;; macro bug fix.
1004 ;; Revision 1.89 2008/08/24 08:35:27 rubikitch
1005 ;; *** empty log message ***
1007 ;; Revision 1.88 2008/08/24 08:22:19 rubikitch
1008 ;; Rename `anything-candidates-buffer' -> `anything-candidate-buffer'
1010 ;; Revision 1.87 2008/08/23 22:27:04 rubikitch
1011 ;; New hook: `anything-cleanup-hook'
1013 ;; Revision 1.86 2008/08/23 22:05:42 rubikitch
1014 ;; `anything-original-source-filter' is removed.
1015 ;; Now use `anything-restored-variables' and `with-anything-restore-variables'.
1017 ;; Revision 1.85 2008/08/23 21:23:21 rubikitch
1018 ;; inhibit-read-only = t in anything-buffer
1020 ;; Revision 1.84 2008/08/23 21:18:33 rubikitch
1021 ;; *** empty log message ***
1023 ;; Revision 1.83 2008/08/23 20:44:20 rubikitch
1024 ;; `anything-execute-persistent-action': display-to-real bug fix
1026 ;; Revision 1.82 2008/08/23 20:19:12 rubikitch
1027 ;; New `anything-sources' attribute: get-line
1029 ;; Revision 1.81 2008/08/23 19:32:14 rubikitch
1030 ;; `anything-attr': Return t in (attribute-name) case.
1032 ;; Revision 1.80 2008/08/22 21:25:05 rubikitch
1033 ;; anything-candidates-in-buffer-1:
1034 ;; Open a line at the BOB to make use of `search-forward' for faster exact/prefix match.
1035 ;; Of course, restore the buffer contents after search.
1037 ;; Revision 1.79 2008/08/22 17:11:00 rubikitch
1038 ;; New hook: `anything-before-initialize-hook', `anything-after-initialize-hook'
1040 ;; Revision 1.78 2008/08/21 18:37:03 rubikitch
1041 ;; Implemented dummy sources as plug-in.
1043 ;; Revision 1.77 2008/08/21 17:40:40 rubikitch
1044 ;; New function: `anything-set-sources'
1046 ;; Revision 1.76 2008/08/21 12:25:02 rubikitch
1047 ;; New variable: `anything-version'
1049 ;; Revision 1.75 2008/08/21 12:13:46 rubikitch
1050 ;; New variable: `anything-in-persistent-action'
1052 ;; Revision 1.74 2008/08/21 10:34:22 rubikitch
1053 ;; New function `anything-mklist'
1055 ;; Revision 1.73 2008/08/21 09:41:38 rubikitch
1056 ;; accept multiple init/cleanup functions so that plug-ins can add new function.
1058 ;; Revision 1.72 2008/08/20 22:51:53 rubikitch
1059 ;; New `anything-sources' attribute: candidate-number-limit
1061 ;; Revision 1.71 2008/08/20 21:45:42 rubikitch
1062 ;; added many tests.
1064 ;; Revision 1.70 2008/08/20 18:51:45 rubikitch
1065 ;; `anything-preselect' bug fix.
1066 ;; refactoring.
1068 ;; Revision 1.69 2008/08/20 17:57:51 rubikitch
1069 ;; Extended `anything' optional arguments: preselect
1071 ;; Revision 1.68 2008/08/20 16:39:07 rubikitch
1072 ;; Nested `anything' invocation support, ie. `anything' can be invoked by anything action.
1074 ;; (anything '(((name . "nested anything invocation test")
1075 ;; (candidates "anything-c-source-buffers" "anything-c-source-man-pages")
1076 ;; (display-to-real . intern)
1077 ;; (action . anything))))
1079 ;; Revision 1.67 2008/08/20 00:08:28 rubikitch
1080 ;; `anything-candidates-in-buffer-1': add code when pattern == ""
1082 ;; Revision 1.66 2008/08/19 23:31:52 rubikitch
1083 ;; Removed `anything-show-exact-match-first' because it should be provided as a plug-in.
1085 ;; Revision 1.65 2008/08/19 23:18:47 rubikitch
1086 ;; *** empty log message ***
1088 ;; Revision 1.64 2008/08/19 23:15:43 rubikitch
1089 ;; `anything-compute-matches': short-cut when match == '(identity)
1091 ;; Revision 1.63 2008/08/19 23:06:42 rubikitch
1092 ;; Use hash table to speed uniquify candidates.
1094 ;; Revision 1.62 2008/08/19 22:40:57 rubikitch
1095 ;; `anything-test-candidates': additional optonal argument
1097 ;; Revision 1.61 2008/08/19 18:13:39 rubikitch
1098 ;; search attribute: multiple search functions
1100 ;; Revision 1.60 2008/08/19 15:07:39 rubikitch
1101 ;; New function: `anything-attr'
1103 ;; Revision 1.59 2008/08/19 15:01:59 rubikitch
1104 ;; arranged code
1105 ;; added unit tests
1106 ;; update doc
1108 ;; Revision 1.58 2008/08/19 13:40:52 rubikitch
1109 ;; `anything-get-current-source': This function can be used in
1110 ;; init/candidates/action/candidate-transformer/filtered-candidate-transformer
1111 ;; display-to-real/cleanup function.
1113 ;; Revision 1.57 2008/08/19 03:43:57 rubikitch
1114 ;; `anything-process-delayed-sources': delay = anything-idle-delay - anything-input-idle-delay
1116 ;; Revision 1.56 2008/08/18 06:37:51 rubikitch
1117 ;; Make `anything-input-idle-delay' ineffective when the action list is shown.
1119 ;; Revision 1.55 2008/08/18 06:35:00 rubikitch
1120 ;; New variable: `anything-show-exact-match-first'
1122 ;; Revision 1.54 2008/08/17 23:22:24 rubikitch
1123 ;; *** empty log message ***
1125 ;; Revision 1.53 2008/08/17 23:15:38 rubikitch
1126 ;; bind `anything-source-name' when executing action to enable to use `anything-candidate-buffer' in action.
1128 ;; Revision 1.52 2008/08/17 15:21:27 rubikitch
1129 ;; `anything-test-candidates': accept a symbol for source
1130 ;; New variable: `anything-input-idle-delay'
1132 ;; Revision 1.51 2008/08/17 12:45:30 rubikitch
1133 ;; (buffer-disable-undo) in anything-buffer
1135 ;; Revision 1.50 2008/08/16 22:21:37 rubikitch
1136 ;; `anything-saved-sources': removed
1137 ;; `anything-action-buffer': action selection buffer
1138 ;; `anything-select-action': toggle actions <=> candidates
1140 ;; Revision 1.49 2008/08/16 19:46:11 rubikitch
1141 ;; New function: `anything-action-list-is-shown'
1143 ;; Revision 1.48 2008/08/16 17:03:02 rubikitch
1144 ;; bugfix: cleanup
1146 ;; Revision 1.47 2008/08/16 16:35:24 rubikitch
1147 ;; silence byte compiler
1149 ;; Revision 1.46 2008/08/16 14:51:27 rubikitch
1150 ;; *** empty log message ***
1152 ;; Revision 1.45 2008/08/16 11:27:59 rubikitch
1153 ;; refactoring
1154 ;; `anything-aif': Anaphoric if.
1155 ;; `anything-compile-source-functions': make `anything-get-sources' customizable.
1157 ;; Revision 1.44 2008/08/16 09:38:15 rubikitch
1158 ;; *** empty log message ***
1160 ;; Revision 1.43 2008/08/15 11:44:28 rubikitch
1161 ;; `anything-read-string-mode': minor mode for `anything' version of read functions. (experimental)
1163 ;; Revision 1.42 2008/08/15 11:03:20 rubikitch
1164 ;; update docs
1166 ;; Revision 1.41 2008/08/14 20:51:28 rubikitch
1167 ;; New `anything-sources' attribute: cleanup
1169 ;; Revision 1.40 2008/08/14 10:34:04 rubikitch
1170 ;; `anything': SOURCES: accept symbols
1172 ;; Revision 1.39 2008/08/10 22:46:01 rubikitch
1173 ;; `anything-move-selection': avoid infinite loop
1175 ;; Revision 1.38 2008/08/09 21:38:25 rubikitch
1176 ;; `anything-read-file-name': experimental implementation.
1178 ;; Revision 1.37 2008/08/09 17:54:25 rubikitch
1179 ;; action test
1181 ;; Revision 1.36 2008/08/09 17:13:00 rubikitch
1182 ;; fixed test
1184 ;; Revision 1.35 2008/08/09 10:43:08 rubikitch
1185 ;; New `anything-sources' attribute: display-to-real
1187 ;; Revision 1.34 2008/08/07 13:15:44 rubikitch
1188 ;; New `anything-sources' attribute: search
1190 ;; Revision 1.33 2008/08/05 23:14:20 rubikitch
1191 ;; `anything-candidate-buffer': bugfix
1193 ;; Revision 1.32 2008/08/05 21:42:15 rubikitch
1194 ;; *** empty log message ***
1196 ;; Revision 1.31 2008/08/05 21:06:23 rubikitch
1197 ;; `anything-candidate-buffer': candidates buffer registration
1199 ;; Revision 1.30 2008/08/05 19:46:36 rubikitch
1200 ;; New `anything-sources' attribute: candidates-in-buffer
1202 ;; Revision 1.29 2008/08/05 17:58:31 rubikitch
1203 ;; *** empty log message ***
1205 ;; Revision 1.28 2008/08/05 17:46:04 rubikitch
1206 ;; memoized `anything-get-sources'
1208 ;; Revision 1.27 2008/08/05 17:29:40 rubikitch
1209 ;; update doc
1211 ;; Revision 1.26 2008/08/05 08:35:45 rubikitch
1212 ;; `anything-completing-read': accept obarray
1214 ;; Revision 1.25 2008/08/05 07:26:17 rubikitch
1215 ;; `anything-completing-read': guard from non-string return value
1217 ;; Revision 1.24 2008/08/04 12:05:41 rubikitch
1218 ;; Wrote Tips and some docstrings.
1219 ;; `anything-candidate-buffer': buffer-local by default
1221 ;; Revision 1.23 2008/08/04 05:29:46 rubikitch
1222 ;; `anything-buffer-file-name': `buffer-file-name' when `anything' is invoked.
1224 ;; Revision 1.22 2008/08/04 00:10:13 rubikitch
1225 ;; `anything-candidate-buffer': new API
1227 ;; Revision 1.21 2008/08/03 22:05:08 rubikitch
1228 ;; `anything-candidate-buffer': Return a buffer containing candidates of current source.
1230 ;; Revision 1.20 2008/08/03 20:47:56 rubikitch
1231 ;; `anything-current-buffer-is-modified': modify checker
1233 ;; Revision 1.19 2008/08/03 19:06:18 rubikitch
1234 ;; `anything-candidates-in-buffer': use `with-current-buffer' instead.
1236 ;; Revision 1.18 2008/08/03 05:55:01 rubikitch
1237 ;; `anything-candidates-in-buffer': extract candidates in a buffer for speed.
1239 ;; Revision 1.17 2008/08/02 21:31:29 rubikitch
1240 ;; Extended `anything' optional arguments.
1241 ;; `anything-completing-read': experimental implementation.
1243 ;; Revision 1.16 2008/08/02 20:32:54 rubikitch
1244 ;; Extended `anything' optional arguments.
1246 ;; Revision 1.15 2008/08/02 16:53:40 rubikitch
1247 ;; Fixed a small bug of `anything-test-candidates'.
1249 ;; Revision 1.14 2008/08/02 16:48:29 rubikitch
1250 ;; Refactored to testable code.
1251 ;; Added many candidate tests with `anything-test-candidates'.
1253 ;; Revision 1.13 2008/08/02 15:08:14 rubikitch
1254 ;; *** empty log message ***
1256 ;; Revision 1.12 2008/08/02 14:29:31 rubikitch
1257 ;; `anything-sources' accepts symbols. (patched by Sugawara)
1259 ;; Revision 1.11 2008/08/02 10:20:36 rubikitch
1260 ;; `anything-resume' is usable with other (let-binded) `anything-sources'.
1262 ;; Revision 1.10 2008/08/01 19:44:01 rubikitch
1263 ;; `anything-resume': resurrect previously invoked `anything'.
1265 ;; Revision 1.9 2008/07/30 15:44:49 rubikitch
1266 ;; *** empty log message ***
1268 ;; Revision 1.8 2008/07/30 15:38:51 rubikitch
1269 ;; *** empty log message ***
1271 ;; Revision 1.7 2008/07/30 15:21:48 rubikitch
1272 ;; `anything-scroll-other-window', `anything-scroll-other-window-down':
1273 ;; Scroll other window (for persistent action).
1275 ;; Revision 1.6 2008/07/30 15:12:36 rubikitch
1276 ;; *** empty log message ***
1278 ;; Revision 1.5 2008/07/30 15:06:32 rubikitch
1279 ;; `anything-select-2nd-action', `anything-select-3rd-action', `anything-select-4th-action':
1280 ;; Select other than default action without pressing Tab.
1282 ;; Revision 1.4 2008/07/30 14:58:27 rubikitch
1283 ;; `anything-current-buffer': Store current buffer when `anything' is invoked.
1284 ;; `anything-current-position': Restore position when keyboard-quitted.
1286 ;; Revision 1.3 2008/07/30 14:38:04 rubikitch
1287 ;; Implemented persistent action.
1289 ;; Revision 1.2 2008/07/30 13:37:16 rubikitch
1290 ;; Update doc.
1292 ;; Revision 1.1 2008/07/30 13:22:06 rubikitch
1293 ;; New maintainer.
1296 ;; ugly hack to auto-update version
1297 (defvar anything-version nil)
1298 (setq anything-version "$Id: anything.el,v 1.280 2010-04-01 02:22:22 rubikitch Exp $")
1299 (require 'cl)
1301 ;; (@* "User Configuration")
1303 ;; This is only an example. Customize it to your own taste!
1304 (defvar anything-sources `(((name . "Buffers")
1305 (candidates
1306 . (lambda ()
1307 (remove-if (lambda (name)
1308 (or (equal name anything-buffer)
1309 (eq ?\ (aref name 0))))
1310 (mapcar 'buffer-name (buffer-list)))))
1311 (type . buffer))
1313 ((name . "File Name History")
1314 (candidates . file-name-history)
1315 (match (lambda (candidate)
1316 ;; list basename matches first
1317 (string-match
1318 anything-pattern
1319 (file-name-nondirectory candidate)))
1321 (lambda (candidate)
1322 ;; and then directory part matches
1323 (let ((dir (file-name-directory candidate)))
1324 (if dir
1325 (string-match anything-pattern dir)))))
1326 (type . file))
1328 ((name . "Files from Current Directory")
1329 (init . (lambda ()
1330 (setq anything-default-directory
1331 default-directory)))
1332 (candidates . (lambda ()
1333 (directory-files
1334 anything-default-directory)))
1335 (type . file))
1337 ((name . "Complex Command History")
1338 (candidates . (lambda ()
1339 (mapcar 'prin1-to-string
1340 command-history)))
1341 (action . (("Repeat Complex Command" .
1342 (lambda (c)
1343 (eval (read c))))))
1344 (delayed)))
1345 "The source of candidates for anything.
1346 It accepts symbols:
1347 (setq anything-sources (list anything-c-foo anything-c-bar))
1348 can be written as
1349 (setq anything-sources '(anything-c-foo anything-c-bar))
1350 The latter is recommended because if you change anything-c-* variable,
1351 you do not have to update `anything-sources'.
1353 You are STRONGLY recommended to define a command which calls
1354 `anything' or `anything-other-buffer' with argument rather than
1355 to set `anything-sources' externally.
1357 If you want to change `anything-sources' during `anything' invocation,
1358 use `anything-set-sources', never use `setq'.
1360 Attributes:
1365 ;; This value is only provided as an example. Customize it to your own
1366 ;; taste!
1367 (defvar anything-type-attributes
1368 '((file (action . (("Find File" . find-file)
1369 ("Delete File" . (lambda (file)
1370 (if (y-or-n-p (format "Really delete file %s? "
1371 file))
1372 (delete-file file)))))))
1373 (buffer (action . (("Switch to Buffer" . switch-to-buffer)
1374 ("Pop to Buffer" . pop-to-buffer)
1375 ("Display Buffer" . display-buffer)
1376 ("Kill Buffer" . kill-buffer)))))
1377 "It's a list of (TYPE ATTRIBUTES ...). ATTRIBUTES are the same
1378 as attributes for `anything-sources'. TYPE connects the value
1379 to the appropriate sources in `anything-sources'.
1381 This allows specifying common attributes for several
1382 sources. For example, sources which provide files can specify
1383 common attributes with a `file' type.")
1386 (defvar anything-enable-shortcuts nil
1387 "*Whether to use digit/alphabet shortcut to select the first nine matches.
1388 If t then they can be selected using Ctrl+<number>.
1389 If 'alphabet then they can be selected using Shift+<alphabet>.
1391 Keys (digit/alphabet) are listed in `anything-digit-shortcut-index-alist'.")
1393 (defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
1394 "Alphabet shortcuts are usable now. Then `anything-enable-digit-shortcuts' should be renamed.
1395 `anything-enable-digit-shortcuts' is retained for compatibility.")
1397 (defvar anything-shortcut-keys-alist
1398 '((alphabet . "asdfghjklzxcvbnmqwertyuiop")
1399 (t . "123456789")))
1401 (defvar anything-display-source-at-screen-top t
1402 "*If t, `anything-next-source' and `anything-previous-source'
1403 display candidates at the top of screen.")
1405 (defvar anything-candidate-number-limit 50
1406 "*Do not show more candidates than this limit from individual
1407 sources. It is usually pointless to show hundreds of matches
1408 when the pattern is empty, because it is much simpler to type a
1409 few characters to narrow down the list of potential candidates.
1411 Set it to nil if you don't want this limit.")
1414 (defvar anything-idle-delay 0.5
1415 "*The user has to be idle for this many seconds, before
1416 candidates from delayed sources are collected. This is useful
1417 for sources involving heavy operations (like launching external
1418 programs), so that candidates from the source are not retrieved
1419 unnecessarily if the user keeps typing.
1421 It also can be used to declutter the results anything displays,
1422 so that results from certain sources are not shown with every
1423 character typed, only if the user hesitates a bit.")
1426 (defvar anything-input-idle-delay 0.1
1427 "The user has to be idle for this many seconds, before ALL candidates are collected.
1428 Unlink `anything-input-idle', it is also effective for non-delayed sources.
1429 If nil, candidates are collected immediately. ")
1432 (defvar anything-samewindow nil
1433 "If t then Anything doesn't pop up a new window, it uses the
1434 current window to show the candidates.")
1437 (defvar anything-source-filter nil
1438 "A list of source names to be displayed. Other sources won't
1439 appear in the search results. If nil then there is no filtering.
1440 See also `anything-set-source-filter'.")
1443 (defvar anything-map
1444 (let ((map (copy-keymap minibuffer-local-map)))
1445 (define-key map (kbd "<down>") 'anything-next-line)
1446 (define-key map (kbd "<up>") 'anything-previous-line)
1447 (define-key map (kbd "C-n") 'anything-next-line)
1448 (define-key map (kbd "C-p") 'anything-previous-line)
1449 (define-key map (kbd "<prior>") 'anything-previous-page)
1450 (define-key map (kbd "<next>") 'anything-next-page)
1451 (define-key map (kbd "M-v") 'anything-previous-page)
1452 (define-key map (kbd "C-v") 'anything-next-page)
1453 (define-key map (kbd "M-<") 'anything-beginning-of-buffer)
1454 (define-key map (kbd "M->") 'anything-end-of-buffer)
1455 (define-key map (kbd "<right>") 'anything-next-source)
1456 (define-key map (kbd "<left>") 'anything-previous-source)
1457 (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
1458 (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
1459 (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
1460 (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
1461 (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
1462 (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
1463 (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
1464 (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
1465 (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
1466 (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
1467 (loop for c from ?A to ?Z do
1468 (define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
1469 (define-key map (kbd "C-i") 'anything-select-action)
1470 (define-key map (kbd "C-z") 'anything-execute-persistent-action)
1471 (define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
1472 (define-key map (kbd "C-j") 'anything-select-3rd-action)
1473 (define-key map (kbd "C-o") 'anything-next-source)
1474 (define-key map (kbd "C-M-v") 'anything-scroll-other-window)
1475 (define-key map (kbd "M-<next>") 'anything-scroll-other-window)
1476 (define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
1477 (define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
1478 (define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
1479 (define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
1480 (define-key map (kbd "M-[") 'anything-prev-visible-mark)
1481 (define-key map (kbd "M-]") 'anything-next-visible-mark)
1482 (define-key map (kbd "C-k") 'anything-delete-minibuffer-content)
1484 (define-key map (kbd "C-s") 'anything-isearch)
1485 (define-key map (kbd "C-r") 'undefined)
1486 (define-key map (kbd "C-t") 'anything-toggle-resplit-window)
1487 (define-key map (kbd "C-x C-f") 'anything-quit-and-find-file)
1489 (define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
1490 (define-key map (kbd "C-c C-y") 'anything-yank-selection)
1491 (define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
1492 (define-key map (kbd "C-c C-f") 'anything-follow-mode)
1493 (define-key map (kbd "C-c C-u") 'anything-force-update)
1495 ;; Debugging command
1496 (define-key map "\C-c\C-x\C-d" 'anything-debug-output)
1497 ;; Use `describe-mode' key in `global-map'
1498 (dolist (k (where-is-internal 'describe-mode global-map))
1499 (define-key map k 'anything-help))
1500 ;; the defalias is needed because commands are bound by name when
1501 ;; using iswitchb, so only commands having the prefix anything-
1502 ;; get rebound
1503 (defalias 'anything-previous-history-element 'previous-history-element)
1504 (defalias 'anything-next-history-element 'next-history-element)
1505 (define-key map (kbd "M-p") 'anything-previous-history-element)
1506 (define-key map (kbd "M-n") 'anything-next-history-element)
1507 map)
1508 "Keymap for anything.
1510 If you execute `anything-iswitchb-setup', some keys are modified.
1511 See `anything-iswitchb-setup-keys'.")
1513 (defvar anything-isearch-map
1514 (let ((map (make-sparse-keymap)))
1515 (set-keymap-parent map (current-global-map))
1516 (define-key map (kbd "<return>") 'anything-isearch-default-action)
1517 (define-key map (kbd "<RET>") 'anything-isearch-default-action)
1518 (define-key map (kbd "C-i") 'anything-isearch-select-action)
1519 (define-key map (kbd "C-g") 'anything-isearch-cancel)
1520 (define-key map (kbd "M-s") 'anything-isearch-again)
1521 (define-key map (kbd "<backspace>") 'anything-isearch-delete)
1522 ;; add printing chars
1523 (loop for i from 32 below 256 do
1524 (define-key map (vector i) 'anything-isearch-printing-char))
1525 map)
1526 "Keymap for anything incremental search.")
1529 (defgroup anything nil
1530 "Open anything." :prefix "anything-" :group 'convenience)
1532 (defface anything-header
1533 '((t (:inherit header-line)))
1534 "Face for header lines in the anything buffer." :group 'anything)
1536 (defvar anything-header-face 'anything-header
1537 "Face for header lines in the anything buffer.")
1539 (defface anything-isearch-match '((t (:background "Yellow")))
1540 "Face for isearch in the anything buffer." :group 'anything)
1542 (defvar anything-isearch-match-face 'anything-isearch-match
1543 "Face for matches during incremental search.")
1545 (defvar anything-selection-face 'highlight
1546 "Face for currently selected item.")
1548 (defvar anything-iswitchb-idle-delay 1
1549 "Show anything completions if the user is idle that many
1550 seconds after typing.")
1552 (defvar anything-iswitchb-dont-touch-iswithcb-keys nil
1553 "If t then those commands are not bound from `anything-map'
1554 under iswitchb which would override standard iswithcb keys.
1556 This allows an even more seamless integration with iswitchb for
1557 those who prefer using iswitchb bindings even if the anything
1558 completions buffer is popped up.
1560 Note that you can bind alternative keys for the same command in
1561 `anything-map', so that you can use different keys for anything
1562 under iswitchb. For example, I bind the character \ to
1563 `anything-exit-minibuffer' which key is just above Enter on my
1564 keyboard. This way I can switch buffers with Enter and choose
1565 anything completions with \.")
1567 ;;----------------------------------------------------------------------
1569 (defvar anything-buffer "*anything*"
1570 "Buffer showing completions.")
1572 (defvar anything-action-buffer "*anything action*"
1573 "Buffer showing actions.")
1575 (defvar anything-selection-overlay nil
1576 "Overlay used to highlight the currently selected item.")
1578 (defvar anything-isearch-overlay nil
1579 "Overlay used to highlight the current match during isearch.")
1581 (defvar anything-digit-overlays nil
1582 "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
1584 (defvar anything-candidate-cache nil
1585 "Holds the available candidate withing a single anything invocation.")
1587 (defvar anything-pattern
1588 "The input pattern used to update the anything buffer.")
1590 (defvar anything-input
1591 "The input typed in the candidates panel.")
1593 (defvar anything-async-processes nil
1594 "List of information about asynchronous processes managed by anything.")
1596 (defvar anything-digit-shortcut-count 0
1597 "Number of digit shortcuts shown in the anything buffer.")
1599 (defvar anything-before-initialize-hook nil
1600 "Run before anything initialization.
1601 This hook is run before init functions in `anything-sources'.")
1603 (defvar anything-after-initialize-hook nil
1604 "Run after anything initialization.
1605 Global variables are initialized and the anything buffer is created.
1606 But the anything buffer has no contents. ")
1608 (defvar anything-update-hook nil
1609 "Run after the anything buffer was updated according the new
1610 input pattern.")
1612 (defvar anything-cleanup-hook nil
1613 "Run after anything minibuffer is closed, IOW this hook is executed BEFORE performing action. ")
1615 (defvar anything-after-action-hook nil
1616 "Run after executing action.")
1618 (defvar anything-after-persistent-action-hook nil
1619 "Run after executing persistent action.")
1621 (defvar anything-restored-variables
1622 '( anything-candidate-number-limit
1623 anything-source-filter
1624 anything-source-in-each-line-flag
1625 anything-sources)
1626 "Variables which are restored after `anything' invocation.")
1627 ;; `anything-saved-sources' is removed
1629 (defvar anything-saved-selection nil
1630 "Saved value of the currently selected object when the action
1631 list is shown.")
1633 ;; `anything-original-source-filter' is removed
1635 (defvar anything-candidate-separator
1636 "--------------------"
1637 "Candidates separator of `multiline' source.")
1639 (defvar anything-current-buffer nil
1640 "Current buffer when `anything' is invoked.")
1642 (defvar anything-buffer-file-name nil
1643 "`buffer-file-name' when `anything' is invoked.")
1645 (defvar anything-current-position nil
1646 "Cons of (point) and (window-start) when `anything' is invoked.
1647 It is needed because restoring position when `anything' is keyboard-quitted.")
1649 (defvar anything-saved-action nil
1650 "Saved value of the currently selected action by key.")
1652 (defvar anything-last-sources nil
1653 "OBSOLETE!! Sources of previously invoked `anything'.")
1655 (defvar anything-saved-current-source nil
1656 "Saved value of the original (anything-get-current-source) when the action
1657 list is shown.")
1659 (defvar anything-compiled-sources nil
1660 "Compiled version of `anything-sources'. ")
1662 (defvar anything-in-persistent-action nil
1663 "Flag whether in persistent-action or not.")
1665 (defvar anything-quick-update nil
1666 "If non-nil, suppress displaying sources which are out of screen at first.
1667 They are treated as delayed sources at this input.
1668 This flag makes `anything' a bit faster with many sources.")
1670 (defvar anything-last-sources-local nil
1671 "Buffer local value of `anything-sources'.")
1672 (defvar anything-last-buffer nil
1673 "`anything-buffer' of previously `anything' session.")
1675 (defvar anything-save-configuration-functions
1676 '(set-window-configuration . current-window-configuration)
1677 "If you want to save and restore frame configuration, set this variable to
1678 '(set-frame-configuration . current-frame-configuration)
1680 Older version saves/restores frame configuration, but the default is changed now,
1681 because flickering is occurred in some environment.
1684 (defvar anything-persistent-action-use-special-display nil
1685 "If non-nil, use `special-display-function' in persistent action.")
1687 (defvar anything-execute-action-at-once-if-one nil
1688 "If non-nil and there is one candidate, execute the first action without selection.
1689 It is useful for `anything' applications.")
1691 (defvar anything-quit-if-no-candidate nil
1692 "if non-nil and there is no candidate, do not display *anything* buffer and quit.
1693 This variable accepts a function, which is executed if no candidate.
1695 It is useful for `anything' applications.")
1697 (defvar anything-scroll-amount nil
1698 "Scroll amount used by `anything-scroll-other-window' and `anything-scroll-other-window-down'.
1699 If you prefer scrolling line by line, set this value to 1.")
1701 (defvar anything-display-function 'anything-default-display-buffer
1702 "Function to display *anything* buffer.
1703 It is `anything-default-display-buffer' by default, which affects `anything-samewindow'.")
1705 (defvar anything-delayed-init-executed nil)
1707 (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"
1708 "Help string displayed in mode-line in `anything'.
1709 If nil, use default `mode-line-format'.")
1711 (defvar anything-help-message
1712 "\\<anything-map>The keys that are defined for `anything' are:
1713 \\{anything-map}"
1714 "Detailed help message string for `anything'.
1715 It also accepts function or variable symbol.")
1717 (put 'anything 'timid-completion 'disabled)
1719 (defvar anything-inhibit-fit-frame-flag t
1720 "If non-nil, inhibit fitting anything frame to its buffer.
1721 It is nil by default because some flickering occurred in some environment.
1723 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
1724 `fit-frame-inhibit-fitting' to nil.")
1726 (defvar anything-source-in-each-line-flag nil
1727 "If non-nil, add anything-source text-property in each candidate.
1728 experimental feature.")
1730 (defvar anything-debug-variables nil
1731 "Variables to show in `anything-debug-output'.
1732 Otherwise all variables started with `anything-' are shown.
1733 It is useful for debug.")
1735 ;; (@* "Internal Variables")
1736 (defvar anything-test-candidate-list nil)
1737 (defvar anything-test-mode nil)
1738 (defvar anything-source-name nil)
1739 (defvar anything-candidate-buffer-alist nil)
1740 (defvar anything-check-minibuffer-input-timer nil)
1741 (defvar anything-match-hash (make-hash-table :test 'equal))
1742 (defvar anything-cib-hash (make-hash-table :test 'equal))
1743 (defvar anything-tick-hash (make-hash-table :test 'equal))
1744 (defvar anything-issued-errors nil)
1745 (defvar anything-shortcut-keys nil)
1746 (defvar anything-once-called-functions nil)
1747 (defvar anything-follow-mode nil)
1749 ;; (@* "Programming Tools")
1750 (defmacro anything-aif (test-form then-form &rest else-forms)
1751 "Anaphoric if. Temporary variable `it' is the result of test-form."
1752 `(let ((it ,test-form))
1753 (if it ,then-form ,@else-forms)))
1754 (put 'anything-aif 'lisp-indent-function 2)
1756 (defun anything-mklist (obj)
1757 "If OBJ is a list (but not lambda), return itself, otherwise make a list with one element."
1758 (if (and (listp obj) (not (functionp obj)))
1760 (list obj)))
1762 ;; (@* "Anything API")
1763 (defun anything-buffer-get ()
1764 "If *anything action* buffer is shown, return `anything-action-buffer', otherwise `anything-buffer'."
1765 (if (anything-action-window)
1766 anything-action-buffer
1767 anything-buffer))
1769 (defun anything-window ()
1770 "Window of `anything-buffer'."
1771 (get-buffer-window (anything-buffer-get) 'visible))
1773 (defun anything-action-window ()
1774 "Window of `anything-action-buffer'."
1775 (get-buffer-window anything-action-buffer 'visible))
1777 (defmacro with-anything-window (&rest body)
1778 `(let ((--tmpfunc-- (lambda () ,@body)))
1779 (if anything-test-mode
1780 (with-current-buffer (anything-buffer-get)
1781 (funcall --tmpfunc--))
1782 (with-selected-window (anything-window)
1783 (funcall --tmpfunc--)))))
1784 (put 'with-anything-window 'lisp-indent-function 0)
1786 (defmacro with-anything-restore-variables(&rest body)
1787 "Restore variables specified by `anything-restored-variables' after executing BODY ."
1788 `(let ((--orig-vars (mapcar (lambda (v) (cons v (symbol-value v))) anything-restored-variables)))
1789 (unwind-protect (progn ,@body)
1790 (loop for (var . value) in --orig-vars
1791 do (set var value)))))
1792 (put 'with-anything-restore-variables 'lisp-indent-function 0)
1794 (defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
1795 "Get the value of ATTRIBUTE-NAME of SRC (source).
1796 if SRC is omitted, use current source.
1797 It is useful to write your sources."
1798 (anything-aif (assq attribute-name src)
1799 (cdr it)))
1801 (defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
1802 "Return non-nil if ATTRIBUTE-NAME of SRC (source) is defined.
1803 if SRC is omitted, use current source.
1804 It is useful to write your sources."
1805 (and (assq attribute-name src) t))
1807 (defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
1808 "Set the value of ATTRIBUTE-NAME of SRC (source) to VALUE.
1809 if SRC is omitted, use current source.
1810 It is useful to write your sources."
1811 (anything-aif (assq attribute-name src)
1812 (setcdr it value)
1813 (setcdr src (cons (cons attribute-name value) (cdr src))))
1814 value)
1816 ;; anything-set-source-filter
1818 ;; This function sets a filter for anything sources and it may be
1819 ;; called while anything is running. It can be used to toggle
1820 ;; displaying of sources dinamically. For example, additional keys
1821 ;; can be bound into `anything-map' to display only the file-related
1822 ;; results if there are too many matches from other sources and
1823 ;; you're after files only:
1825 ;; Shift+F shows only file results from some sources:
1827 ;; (define-key anything-map "F" 'anything-my-show-files-only)
1829 ;; (defun anything-my-show-files-only ()
1830 ;; (interactive)
1831 ;; (anything-set-source-filter '("File Name History"
1832 ;; "Files from Current Directory")))
1834 ;; Shift+A shows all results:
1836 ;; (define-key anything-map "A" 'anything-my-show-all)
1838 ;; (defun anything-my-show-all ()
1839 ;; (interactive)
1840 ;; (anything-set-source-filter nil))
1843 ;; Note that you have to prefix the functions with anything- prefix,
1844 ;; otherwise they won't be bound when Anything is used under
1845 ;; Iswitchb. The -my- part is added to avoid collisions with
1846 ;; existing Anything function names.
1848 (defun anything-set-source-filter (sources)
1849 "Sets the value of `anything-source-filter' and updates the list of results."
1850 (unless (and (listp sources)
1851 (loop for name in sources always (stringp name)))
1852 (error "invalid data in `anything-set-source-filter': %S" sources))
1853 (setq anything-source-filter sources)
1854 (anything-update))
1856 (defun anything-set-sources (sources &optional no-init no-update)
1857 "Set `anything-sources' during `anything' invocation.
1858 If NO-INIT is non-nil, skip executing init functions of SOURCES.
1859 If NO-UPDATE is non-nil, skip executing `anything-update'."
1860 (setq anything-compiled-sources nil
1861 anything-sources sources)
1862 (unless no-init (anything-funcall-foreach 'init))
1863 (unless no-update (anything-update)))
1865 (defvar anything-compile-source-functions
1866 '(anything-compile-source--type
1867 anything-compile-source--dummy
1868 anything-compile-source--disable-shortcuts
1869 anything-compile-source--candidates-in-buffer)
1870 "Functions to compile elements of `anything-sources' (plug-in).")
1872 (defun anything-get-sources ()
1873 "Return compiled `anything-sources', which is memoized.
1875 Attributes:
1877 - type
1878 `anything-type-attributes' are merged in.
1879 - candidates-buffer
1880 candidates, volatile and match attrubute are created.
1882 (cond
1883 ;; action
1884 ((anything-action-window)
1885 anything-sources)
1886 ;; memoized
1887 (anything-compiled-sources)
1888 ;; first time
1890 (setq anything-compiled-sources
1891 (anything-compile-sources anything-sources anything-compile-source-functions)))))
1893 (defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
1894 "Return the currently selected item or nil.
1895 if BUFFER is nil or unspecified, use anything-buffer as default value.
1896 If FORCE-DISPLAY-PART is non-nil, return the display string."
1897 (setq buffer (if (and buffer buffer-s) buffer anything-buffer))
1898 (unless (zerop (buffer-size (get-buffer buffer)))
1899 (with-current-buffer buffer
1900 (let ((selection
1901 (or (and (not force-display-part)
1902 (get-text-property (overlay-start
1903 anything-selection-overlay)
1904 'anything-realvalue))
1905 (buffer-substring-no-properties
1906 (overlay-start anything-selection-overlay)
1907 (1- (overlay-end anything-selection-overlay))))))
1908 (unless (equal selection "")
1909 selection)))))
1911 (defun anything-get-action ()
1912 "Return the associated action for the selected candidate."
1913 (unless (zerop (buffer-size (get-buffer (anything-buffer-get))))
1914 (let* ((source (anything-get-current-source))
1915 (actions (assoc-default 'action source)))
1917 (anything-aif (assoc-default 'action-transformer source)
1918 ;; (funcall it actions (anything-get-selection))
1919 (anything-composed-funcall-with-source source it actions (anything-get-selection))
1920 actions))))
1922 (defun anything-get-current-source ()
1923 "Return the source for the current selection / in init/candidates/action/candidate-transformer/filtered-candidate-transformer function."
1924 (declare (special source))
1925 ;; The name `anything-get-current-source' should be used in init function etc.
1926 (if (and (boundp 'anything-source-name) (stringp anything-source-name))
1927 source
1928 (or
1929 (with-current-buffer (anything-buffer-get)
1930 (get-text-property (point) 'anything-source))
1931 (block exit
1932 (with-current-buffer (anything-buffer-get)
1933 ;; This goto-char shouldn't be necessary, but point is moved to
1934 ;; point-min somewhere else which shouldn't happen.
1935 (goto-char (overlay-start anything-selection-overlay))
1936 (let* ((header-pos (anything-get-previous-header-pos))
1937 (source-name
1938 (save-excursion
1939 (unless header-pos
1940 (message "No candidates")
1941 (return-from exit nil))
1942 (goto-char header-pos)
1943 (buffer-substring-no-properties
1944 (line-beginning-position) (line-end-position)))))
1945 (some (lambda (source)
1946 (if (equal (assoc-default 'name source)
1947 source-name)
1948 source))
1949 (anything-get-sources))))))))
1951 (defun anything-buffer-is-modified (buffer)
1952 "Return non-nil when BUFFER is modified since `anything' was invoked."
1953 (let* ((b (get-buffer buffer))
1954 (key (concat (buffer-name b)
1956 (anything-attr 'name)))
1957 (source-tick (or (gethash key anything-tick-hash) 0))
1958 (buffer-tick (buffer-chars-modified-tick b)))
1959 (prog1 (/= source-tick buffer-tick)
1960 (puthash key buffer-tick anything-tick-hash))))
1961 (defun anything-current-buffer-is-modified ()
1962 "Return non-nil when `anything-current-buffer' is modified since `anything' was invoked."
1963 (anything-buffer-is-modified anything-current-buffer))
1965 (defvar anything-quit nil)
1966 (defun anything-run-after-quit (function &rest args)
1967 "Perform an action after quitting `anything'.
1968 The action is to call FUNCTION with arguments ARGS."
1969 (setq anything-quit t)
1970 (apply 'run-with-idle-timer 0 nil function args)
1971 (anything-exit-minibuffer))
1973 (defun define-anything-type-attribute (type definition &optional doc)
1974 "Register type attribute of TYPE as DEFINITION with DOC.
1975 DOC is displayed in `anything-type-attributes' docstring.
1977 Use this function is better than setting `anything-type-attributes' directly."
1978 (anything-add-type-attribute type definition)
1979 (and doc (anything-document-type-attribute type doc))
1980 nil)
1982 (defvar anything-additional-attributes nil
1983 "List of all `anything' attributes.")
1984 (defvaralias 'anything-attributes 'anything-additional-attributes)
1985 (defun anything-document-attribute (attribute short-doc &optional long-doc)
1986 "Register ATTRIBUTE documentation introduced by plug-in.
1987 SHORT-DOC is displayed beside attribute name.
1988 LONG-DOC is displayed below attribute name and short documentation."
1989 (if long-doc
1990 (setq short-doc (concat "(" short-doc ")"))
1991 (setq long-doc short-doc
1992 short-doc ""))
1993 (add-to-list 'anything-additional-attributes attribute t)
1994 (put attribute 'anything-attrdoc
1995 (concat "- " (symbol-name attribute) " " short-doc "\n\n" long-doc "\n")))
1996 (put 'anything-document-attribute 'lisp-indent-function 2)
1998 (defun anything-require-at-least-version (version)
1999 "Output error message unless anything.el is older than VERSION.
2000 This is suitable for anything applications."
2001 (when (and (string= "1." (substring version 0 2))
2002 (string-match "1\.\\([0-9]+\\)" anything-version)
2003 (< (string-to-number (match-string 1 anything-version))
2004 (string-to-number (substring version 2))))
2005 (error "Please update anything.el!!
2007 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
2009 or M-x install-elisp-from-emacswiki anything.el")))
2011 (defun anything-interpret-value (value &optional source)
2012 "interpret VALUE as variable, function or literal.
2013 If VALUE is a function, call it with no arguments and return the value.
2014 If SOURCE is `anything' source, `anything-source-name' is source name.
2016 If VALUE is a variable, return the value.
2018 If VALUE is a symbol, but it is not a function or a variable, cause an error.
2020 Otherwise, return VALUE itself."
2021 (cond ((and source (functionp value))
2022 (anything-funcall-with-source source value))
2023 ((functionp value)
2024 (funcall value))
2025 ((and (symbolp value) (boundp value))
2026 (symbol-value value))
2027 ((symbolp value)
2028 (error "anything-interpret-value: Symbol must be a function or a variable"))
2030 value)))
2032 (defun anything-once (function &rest args)
2033 "Ensure FUNCTION with ARGS to be called once in `anything' session."
2034 (let ((spec (cons function args)))
2035 (unless (member spec anything-once-called-functions)
2036 (apply function args)
2037 (push spec anything-once-called-functions))))
2039 ;; (@* "Core: tools")
2040 (defun anything-current-frame/window-configuration ()
2041 (funcall (cdr anything-save-configuration-functions)))
2043 (defun anything-set-frame/window-configuration (conf)
2044 (funcall (car anything-save-configuration-functions) conf))
2046 (defun anything-funcall-with-source (source func &rest args)
2047 (let ((anything-source-name (assoc-default 'name source)))
2048 (apply func args)))
2050 (defun anything-funcall-foreach (sym)
2051 "Call the sym function(s) for each source if any."
2052 (dolist (source (anything-get-sources))
2053 (when (symbolp source)
2054 (setq source (symbol-value source)))
2055 (anything-aif (assoc-default sym source)
2056 (dolist (func (if (functionp it) (list it) it))
2057 (anything-funcall-with-source source func)))))
2059 (defun anything-normalize-sources (sources)
2060 "If SOURCES is only one source, make a list."
2061 (cond ((or (and sources ; avoid nil
2062 (symbolp sources))
2063 (and (listp sources) (assq 'name sources)))
2064 (list sources))
2065 (sources)
2066 (t anything-sources)))
2068 (defun anything-approximate-candidate-number ()
2069 "Approximate Number of candidates.
2070 It is used to check if candidate number is 0, 1, or 2+."
2071 (with-current-buffer anything-buffer
2072 (let ((lines (1- (line-number-at-pos (1- (point-max))))))
2073 (if (zerop lines)
2075 (save-excursion
2076 (goto-char (point-min))
2077 (forward-line 1)
2078 (if (anything-pos-multiline-p)
2079 (if (search-forward anything-candidate-separator nil t) 2 1)
2080 lines))))))
2082 (defmacro with-anything-quittable (&rest body)
2083 `(let (inhibit-quit)
2084 (condition-case v
2085 (progn ,@body)
2086 (quit (setq anything-quit t)
2087 (exit-minibuffer)
2088 (keyboard-quit)))))
2089 (put 'with-anything-quittable 'lisp-indent-function 0)
2091 (defun anything-compose (arg-lst func-lst)
2092 "Call each function in FUNC-LST with the arguments specified in ARG-LST.
2093 The result of each function will be the new `car' of ARG-LST.
2095 This function allows easy sequencing of transformer functions."
2096 (dolist (func func-lst)
2097 (setcar arg-lst (apply func arg-lst)))
2098 (car arg-lst))
2100 (defun anything-composed-funcall-with-source (source funcs &rest args)
2101 (if (functionp funcs)
2102 (apply 'anything-funcall-with-source source funcs args)
2103 (apply 'anything-funcall-with-source
2104 source (lambda (&rest args) (anything-compose args funcs)) args)))
2106 ;; (@* "Core: entry point")
2107 (defvar anything-buffers nil
2108 "All of `anything-buffer' in most recently used order.")
2110 ;;;###autoload
2111 (defun anything (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap)
2112 "Select anything. In Lisp program, some optional arguments can be used.
2114 Note that all the optional arguments are prefixed because of
2115 dynamic scope problem, IOW argument variables may eat
2116 already-bound variables. Yuck!
2118 - ANY-SOURCES
2120 Temporary value of `anything-sources'. It also accepts a
2121 symbol, interpreted as a variable of an anything source. It
2122 also accepts an alist representing an anything source, which is
2123 detected by (assq 'name ANY-SOURCES)
2126 - ANY-INPUT
2128 Temporary value of `anything-pattern', ie. initial input of minibuffer.
2130 - ANY-PROMPT
2132 Prompt other than \"pattern: \".
2134 - ANY-RESUME
2136 If t, Resurrect previously instance of `anything'. Skip the initialization.
2137 If 'noresume, this instance of `anything' cannot be resumed.
2139 - ANY-PRESELECT
2141 Initially selected candidate. Specified by exact candidate or a regexp.
2142 Note that it is not working with delayed sources.
2144 - ANY-BUFFER
2146 `anything-buffer' instead of *anything*.
2148 - ANY-KEYMAP
2150 `anything-map' for current `anything' session.
2152 ;; TODO more document
2153 (interactive)
2154 (condition-case v
2155 (with-anything-restore-variables
2156 (let ((frameconfig (anything-current-frame/window-configuration))
2157 ;; It is needed because `anything-source-name' is non-nil
2158 ;; when `anything' is invoked by action. Awful global scope.
2159 anything-source-name anything-in-persistent-action
2160 anything-quit
2161 (case-fold-search t)
2162 (anything-buffer (or any-buffer anything-buffer))
2163 (anything-map (or any-keymap anything-map)))
2164 (setq anything-sources (anything-normalize-sources any-sources))
2165 (anything-initialize-1 any-resume any-input)
2166 (anything-hooks 'setup)
2167 (if (eq any-resume t)
2168 (condition-case x
2169 (anything-window-configuration 'set)
2170 (error (anything-display-buffer anything-buffer)))
2171 (anything-display-buffer anything-buffer))
2172 (unwind-protect
2173 (anything-read-pattern-maybe any-prompt any-input any-preselect any-resume)
2174 (anything-cleanup)
2175 (anything-hooks 'cleanup)
2176 (anything-set-frame/window-configuration frameconfig))
2177 (unless anything-quit
2178 (anything-execute-selection-action-1))))
2179 (quit
2180 (anything-on-quit)
2181 nil)))
2183 (defun anything-initialize-1 (any-resume any-input)
2184 (setq anything-current-position (cons (point) (window-start)))
2185 (if (eq any-resume t)
2186 (anything-initialize-overlays (anything-buffer-get))
2187 (anything-initialize))
2188 (unless (eq any-resume 'noresume)
2189 (anything-recent-push anything-buffer 'anything-buffers)
2190 (setq anything-last-buffer anything-buffer))
2191 (when any-input (setq anything-input any-input anything-pattern any-input))
2192 (and (eq any-resume t) (anything-funcall-foreach 'resume)))
2194 (defun anything-execute-selection-action-1 ()
2195 (unwind-protect
2196 (anything-execute-selection-action)
2197 (anything-aif (get-buffer anything-action-buffer)
2198 (kill-buffer it))
2199 (run-hooks 'anything-after-action-hook)))
2201 (defun anything-on-quit ()
2202 (setq minibuffer-history (cons anything-input minibuffer-history))
2203 (goto-char (car anything-current-position))
2204 (set-window-start (selected-window) (cdr anything-current-position)))
2206 (defun anything-resume-select-buffer (input)
2207 (anything '(((name . "Resume anything buffer")
2208 (candidates . anything-buffers)
2209 (action . identity)))
2210 input nil 'noresume nil "*anything resume*"))
2212 (defun* anything-resume (&optional (any-buffer anything-last-buffer) buffer-pattern)
2213 "Resurrect previously invoked `anything'."
2214 (interactive)
2215 (when (or current-prefix-arg buffer-pattern)
2216 (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
2217 (setq anything-compiled-sources nil)
2218 (anything
2219 (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
2220 anything-last-sources anything-sources)
2221 (buffer-local-value 'anything-input-local (get-buffer any-buffer)) nil t nil any-buffer))
2223 (defvar anything-window-configuration nil)
2224 ;;; (set-window-configuration (buffer-local-value 'anything-window-configuration (get-buffer "*anything buffers*")))
2225 (defun anything-window-configuration (store-or-set)
2226 (case store-or-set
2227 ('store
2228 (with-current-buffer anything-buffer
2229 (set (make-local-variable 'anything-window-configuration)
2230 (current-window-configuration))))
2231 ('set
2232 (with-current-buffer anything-buffer
2233 (set-window-configuration anything-window-configuration))
2234 (select-window (anything-window)))))
2236 (defun anything-recent-push (elt list-var)
2237 "Add ELT to the value of LIST-VAR as most recently used value."
2238 (let ((m (member elt (symbol-value list-var))))
2239 (and m (set list-var (delq (car m) (symbol-value list-var))))
2240 (push elt (symbol-value list-var))))
2242 ;;;###autoload
2243 (defun anything-at-point (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
2244 "Same as `anything' except when C-u is pressed, the initial input is the symbol at point."
2245 (interactive)
2246 (anything any-sources
2247 (if current-prefix-arg
2248 (concat "\\b" (thing-at-point 'symbol) "\\b"
2249 (if (featurep 'anything-match-plugin) " " ""))
2250 any-input)
2251 any-prompt any-resume any-preselect any-buffer))
2253 (defun anything-other-buffer (any-sources any-buffer)
2254 "Simplified interface of `anything' with other `anything-buffer'"
2255 (anything any-sources nil nil nil nil any-buffer))
2257 ;; (@* "Core: Display *anything* buffer")
2258 (defun anything-display-buffer (buf)
2259 "Display *anything* buffer."
2260 (funcall anything-display-function buf))
2262 (defun anything-default-display-buffer (buf)
2263 (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
2265 ;; (@* "Core: initialize")
2266 (defun anything-initialize ()
2267 "Initialize anything settings and set up the anything buffer."
2268 (run-hooks 'anything-before-initialize-hook)
2269 (setq anything-once-called-functions nil)
2270 (setq anything-delayed-init-executed nil)
2271 (setq anything-current-buffer (current-buffer))
2272 (setq anything-buffer-file-name buffer-file-name)
2273 (setq anything-issued-errors nil)
2274 (setq anything-compiled-sources nil)
2275 (setq anything-saved-current-source nil)
2276 ;; Call the init function for sources where appropriate
2277 (anything-funcall-foreach 'init)
2279 (setq anything-pattern "")
2280 (setq anything-input "")
2281 (setq anything-candidate-cache nil)
2282 (setq anything-last-sources anything-sources)
2284 (anything-create-anything-buffer)
2285 (run-hooks 'anything-after-initialize-hook))
2287 (defun anything-read-pattern-maybe (any-prompt any-input any-preselect any-resume)
2288 (if (eq any-resume t) (anything-mark-current-line) (anything-update))
2289 (select-frame-set-input-focus (window-frame (minibuffer-window)))
2290 (anything-preselect any-preselect)
2291 (let ((ncandidate (anything-approximate-candidate-number))
2292 (minibuffer-local-map anything-map))
2293 (cond ((and anything-execute-action-at-once-if-one
2294 (= ncandidate 1))
2295 (ignore))
2296 ((and anything-quit-if-no-candidate (= ncandidate 0))
2297 (setq anything-quit t)
2298 (and (functionp anything-quit-if-no-candidate)
2299 (funcall anything-quit-if-no-candidate)))
2301 (read-string (or any-prompt "pattern: ") any-input)))))
2303 (defun anything-create-anything-buffer (&optional test-mode)
2304 "Create newly created `anything-buffer'.
2305 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
2306 (when test-mode
2307 (setq anything-candidate-cache nil))
2308 (with-current-buffer (get-buffer-create anything-buffer)
2309 (buffer-disable-undo)
2310 (erase-buffer)
2311 (set (make-local-variable 'inhibit-read-only) t)
2312 (set (make-local-variable 'anything-last-sources-local) anything-sources)
2313 (set (make-local-variable 'anything-follow-mode) nil)
2315 (setq cursor-type nil)
2316 (setq mode-name "Anything"))
2317 (anything-initialize-overlays anything-buffer)
2318 (get-buffer anything-buffer))
2320 (defun anything-initialize-overlays (buffer)
2321 (if anything-selection-overlay
2322 ;; make sure the overlay belongs to the anything buffer if
2323 ;; it's newly created
2324 (move-overlay anything-selection-overlay (point-min) (point-min)
2325 (get-buffer buffer))
2327 (setq anything-selection-overlay
2328 (make-overlay (point-min) (point-min) (get-buffer buffer)))
2329 (overlay-put anything-selection-overlay 'face anything-selection-face))
2331 (when anything-enable-shortcuts
2332 (setq anything-shortcut-keys (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist)))
2334 (if anything-enable-shortcuts
2335 (unless anything-digit-overlays
2336 (setq anything-digit-overlays
2337 (loop for key across anything-shortcut-keys
2338 for overlay = (make-overlay (point-min) (point-min) (get-buffer buffer))
2339 do (overlay-put overlay 'before-string
2340 (format "%s - " (upcase (make-string 1 key))))
2341 collect overlay)))
2343 (when anything-digit-overlays
2344 (dolist (overlay anything-digit-overlays)
2345 (delete-overlay overlay))
2346 (setq anything-digit-overlays nil))))
2348 (defun anything-hooks (setup-or-cleanup)
2349 (let ((hooks '((post-command-hook anything-check-minibuffer-input)
2350 (minibuffer-setup-hook anything-print-error-messages)
2351 (minibuffer-exit-hook (lambda () (anything-window-configuration 'store))))))
2352 (if (eq setup-or-cleanup 'setup)
2353 (dolist (args hooks) (apply 'add-hook args))
2354 (dolist (args (reverse hooks)) (apply 'remove-hook args)))))
2356 ;; (@* "Core: clean up")
2357 (defun anything-cleanup ()
2358 "Clean up the mess."
2359 (with-current-buffer anything-buffer
2360 (setq cursor-type t))
2361 (bury-buffer anything-buffer)
2362 (anything-funcall-foreach 'cleanup)
2363 (if anything-check-minibuffer-input-timer
2364 (cancel-timer anything-check-minibuffer-input-timer))
2365 (anything-kill-async-processes)
2366 (run-hooks 'anything-cleanup-hook))
2368 ;; (@* "Core: input handling")
2369 (defun anything-check-minibuffer-input ()
2370 "Extract input string from the minibuffer and check if it needs
2371 to be handled."
2372 (if (or (not anything-input-idle-delay) (anything-action-window))
2373 (anything-check-minibuffer-input-1)
2374 (if anything-check-minibuffer-input-timer
2375 (cancel-timer anything-check-minibuffer-input-timer))
2376 (setq anything-check-minibuffer-input-timer
2377 (run-with-idle-timer anything-input-idle-delay nil
2378 'anything-check-minibuffer-input-1))))
2380 (defun anything-check-minibuffer-input-1 ()
2381 (with-anything-quittable
2382 (with-selected-window (minibuffer-window)
2383 (anything-check-new-input (minibuffer-contents)))))
2385 (defun anything-check-new-input (input)
2386 "Check input string and update the anything buffer if
2387 necessary."
2388 (unless (equal input anything-pattern)
2389 (setq anything-pattern input)
2390 (unless (anything-action-window)
2391 (setq anything-input anything-pattern))
2392 (anything-update)))
2394 ;; (@* "Core: source compiler")
2395 (defvar anything-compile-source-functions-default anything-compile-source-functions
2396 "Plug-ins this file provides.")
2397 (defun anything-compile-sources (sources funcs)
2398 "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
2399 Anything plug-ins are realized by this function."
2400 (mapcar
2401 (lambda (source)
2402 (loop with source = (if (listp source) source (symbol-value source))
2403 for f in funcs
2404 do (setq source (funcall f source))
2405 finally (return source)))
2406 sources))
2408 ;; (@* "Core: plug-in attribute documentation hack")
2410 ;; `anything-document-attribute' is public API.
2411 (defadvice documentation-property (after anything-document-attribute activate)
2412 "Hack to display plug-in attributes' documentation as `anything-sources' docstring."
2413 (when (eq symbol 'anything-sources)
2414 (setq ad-return-value
2415 (concat ad-return-value "\n"
2416 (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
2417 anything-additional-attributes
2418 "\n")))))
2419 ;; (describe-variable 'anything-sources)
2420 ;; (documentation-property 'anything-sources 'variable-documentation)
2421 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
2423 ;; (@* "Core: all candidates")
2424 (defun anything-get-candidates (source)
2425 "Retrieve and return the list of candidates from
2426 SOURCE."
2427 (let ((name (assoc-default 'name source)))
2428 (unless (member name anything-delayed-init-executed)
2429 (anything-aif (assoc-default 'delayed-init source)
2430 (when (functionp it)
2431 (funcall it)
2432 (add-to-list 'anything-delayed-init-executed name)))))
2433 (let* ((candidate-source (assoc-default 'candidates source))
2434 (candidates (anything-interpret-value candidate-source source)))
2435 (cond ((processp candidates) candidates)
2436 ((listp candidates) (anything-transform-candidates candidates source))
2437 (t (error (concat "Candidates must either be a function, "
2438 " a variable or a list: %s")
2439 candidate-source)))))
2442 (defun anything-transform-candidates (candidates source &optional process-p)
2443 "Transform CANDIDATES according to candidate transformers."
2444 (anything-aif (assoc-default 'candidate-transformer source)
2445 (setq candidates (anything-composed-funcall-with-source source it candidates)))
2446 (anything-aif (and process-p (assoc-default 'filtered-candidate-transformer source))
2447 (setq candidates (anything-composed-funcall-with-source source it candidates source)))
2448 (anything-aif (assoc-default 'real-to-display source)
2449 (setq candidates (anything-funcall-with-source
2450 source 'mapcar
2451 (lambda (cand_)
2452 (if (consp cand_)
2453 ;; override DISPLAY from candidate-transformer
2454 (cons (funcall it (cdr cand_)) (cdr cand_))
2455 (cons (funcall it cand_) cand_)))
2456 candidates)))
2457 candidates)
2460 (defun anything-get-cached-candidates (source)
2461 "Return the cached value of candidates for SOURCE.
2462 Cache the candidates if there is not yet a cached value."
2463 (let* ((name (assoc-default 'name source))
2464 (candidate-cache (assoc name anything-candidate-cache))
2465 candidates)
2466 (if candidate-cache
2467 (setq candidates (cdr candidate-cache))
2469 (setq candidates (anything-get-candidates source))
2471 (if (processp candidates)
2472 (progn
2473 (push (cons candidates
2474 (append source
2475 (list (cons 'item-count 0)
2476 (cons 'incomplete-line ""))))
2477 anything-async-processes)
2478 (set-process-filter candidates 'anything-output-filter)
2479 (setq candidates nil))
2481 (unless (assoc 'volatile source)
2482 (setq candidate-cache (cons name candidates))
2483 (push candidate-cache anything-candidate-cache))))
2485 candidates))
2487 ;; (@* "Core: narrowing candidates")
2488 (defun anything-candidate-number-limit (source)
2489 "`anything-candidate-number-limit' variable may be overridden by SOURCE.
2490 If (candidate-number-limit) is in SOURCE, show all candidates in SOURCE,
2491 ie. cancel the effect of `anything-candidate-number-limit'."
2492 (anything-aif (assq 'candidate-number-limit source)
2493 (or (cdr it) 99999999)
2494 (or anything-candidate-number-limit 99999999)))
2496 (defun anything-compute-matches (source)
2497 "Compute matches from SOURCE according to its settings."
2498 (let ((doit (lambda ()
2499 (let ((functions (assoc-default 'match source))
2500 (anything-source-name (assoc-default 'name source))
2501 (limit (anything-candidate-number-limit source))
2502 (anything-pattern
2503 (anything-aif (assoc-default 'pattern-transformer source)
2504 (anything-composed-funcall-with-source source it anything-pattern)
2505 anything-pattern))
2506 matches)
2507 (cond ((or (equal anything-pattern "") (equal functions '(identity)))
2508 (setq matches (anything-get-cached-candidates source))
2509 (if (> (length matches) limit)
2510 (setq matches
2511 (subseq matches 0 limit))))
2513 (condition-case nil
2514 (let ((item-count 0)
2515 (cands (anything-get-cached-candidates source))
2516 exit)
2518 (unless functions
2519 (setq functions
2520 (list (lambda (candidate)
2521 (string-match anything-pattern candidate)))))
2523 (clrhash anything-match-hash)
2524 (dolist (function functions)
2525 (let (newmatches c cc)
2526 (dolist (candidate cands)
2527 (when (and (not (gethash candidate anything-match-hash))
2528 (setq c (if (listp candidate)
2529 (car candidate)
2530 candidate))
2531 (setq cc (cond ((stringp c) c)
2532 ((symbolp c) (symbol-name c))))
2533 (funcall function cc))
2534 (puthash candidate t anything-match-hash)
2535 (push candidate newmatches)
2537 (when limit
2538 (incf item-count)
2539 (when (= item-count limit)
2540 (setq exit t)
2541 (return)))))
2543 (setq matches (append matches (reverse newmatches)))
2545 (if exit
2546 (return)))))
2548 (invalid-regexp (setq matches nil)))))
2550 (anything-aif (assoc-default 'filtered-candidate-transformer source)
2551 (setq matches
2552 (anything-composed-funcall-with-source source it matches source)))
2553 matches))))
2554 (if debug-on-error
2555 (funcall doit)
2556 (condition-case v
2557 (funcall doit)
2558 (error (anything-log-error
2559 "anything-compute-matches: error when processing source: %s"
2560 (assoc-default 'name source))
2561 nil)))))
2563 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2565 (defun anything-process-source (source)
2566 "Display matches from SOURCE according to its settings."
2567 (let ((matches (anything-compute-matches source)))
2568 (when matches
2569 (when anything-test-mode
2570 (setq anything-test-candidate-list
2571 `(,@anything-test-candidate-list
2572 (,(assoc-default 'name source)
2573 ,matches))))
2574 (let ((multiline (assq 'multiline source))
2575 (start (point))
2576 separate)
2577 (anything-insert-header-from-source source)
2578 (dolist (match matches)
2579 (if (and multiline separate)
2580 (anything-insert-candidate-separator)
2581 (setq separate t))
2583 (when (and anything-enable-shortcuts
2584 (not (eq anything-digit-shortcut-count
2585 (length anything-digit-overlays))))
2586 (move-overlay (nth anything-digit-shortcut-count
2587 anything-digit-overlays)
2588 (line-beginning-position)
2589 (line-beginning-position))
2590 (incf anything-digit-shortcut-count))
2591 (anything-insert-match match 'insert source))
2593 (if multiline
2594 (put-text-property start (point) 'anything-multiline t))))))
2596 (defun anything-process-delayed-sources (delayed-sources)
2597 "Process delayed sources if the user is idle for
2598 `anything-idle-delay' seconds."
2599 (with-anything-quittable
2600 (if (sit-for (if anything-input-idle-delay
2601 (max 0 (- anything-idle-delay anything-input-idle-delay))
2602 anything-idle-delay))
2603 (with-current-buffer anything-buffer
2604 (save-excursion
2605 (goto-char (point-max))
2606 (dolist (source delayed-sources)
2607 (anything-process-source source))
2609 (when (and (not (equal (buffer-size) 0))
2610 ;; no selection yet
2611 (= (overlay-start anything-selection-overlay)
2612 (overlay-end anything-selection-overlay)))
2613 (goto-char (point-min))
2614 (anything-next-line)))
2615 (save-excursion
2616 (goto-char (point-min))
2617 (run-hooks 'anything-update-hook))
2618 (anything-maybe-fit-frame)))))
2620 ;; (@* "Core: *anything* buffer contents")
2621 (defvar anything-input-local nil)
2622 (defun anything-update ()
2623 "Update the list of matches in the anything buffer according to
2624 the current pattern."
2625 (setq anything-digit-shortcut-count 0)
2626 (anything-kill-async-processes)
2627 (with-current-buffer (anything-buffer-get)
2628 (set (make-local-variable 'anything-input-local) anything-pattern)
2629 (erase-buffer)
2631 (if anything-enable-shortcuts
2632 (dolist (overlay anything-digit-overlays)
2633 (delete-overlay overlay)))
2635 (let (delayed-sources)
2636 (unwind-protect
2637 (dolist (source (anything-get-sources))
2638 (when (and (or (not anything-source-filter)
2639 (member (assoc-default 'name source) anything-source-filter))
2640 (>= (length anything-pattern)
2641 (anything-aif (assoc 'requires-pattern source)
2642 (or (cdr it) 1)
2643 0)))
2644 (if (or (assoc 'delayed source)
2645 (and anything-quick-update
2646 (< (window-height (get-buffer-window (current-buffer)))
2647 (line-number-at-pos (point-max)))))
2648 (push source delayed-sources)
2649 (anything-process-source source))))
2651 (goto-char (point-min))
2652 (save-excursion (run-hooks 'anything-update-hook))
2653 (anything-next-line)
2654 (setq delayed-sources (nreverse delayed-sources))
2655 (if anything-test-mode
2656 (dolist (source delayed-sources)
2657 (anything-process-source source))
2658 (anything-maybe-fit-frame)
2659 (when delayed-sources
2660 (run-with-idle-timer (if (featurep 'xemacs)
2664 'anything-process-delayed-sources
2665 delayed-sources)))))))
2667 (defun anything-force-update ()
2668 "Recalculate and update candidates.
2669 If current source has `update' attribute, a function without argument, call it before update."
2670 (interactive)
2671 (anything-aif (anything-attr 'update)
2672 (anything-funcall-with-source (anything-get-current-source) it))
2673 ;; Remove from candidate cache to recalculate candidates
2674 (setq anything-candidate-cache
2675 (delete (assoc (assoc-default 'name (anything-get-current-source)) anything-candidate-cache)
2676 anything-candidate-cache))
2677 ;; Go to original selection after update
2678 (let ((selection (anything-get-selection))
2679 (source (anything-get-current-source)))
2680 (anything-update)
2681 (with-anything-window
2682 (anything-goto-source source)
2683 (forward-char -1) ;back to \n
2684 (if (search-forward (concat "\n" selection "\n") nil t)
2685 (forward-line -1)
2686 (goto-char (point-min))
2687 (forward-line 1))
2688 (anything-mark-current-line))))
2690 (defun anything-insert-match (match insert-function source)
2691 "Insert MATCH into the anything buffer. If MATCH is a list then
2692 insert the string inteneded to appear on the display and store
2693 the real value in a text property."
2694 (let ((start (line-beginning-position (point)))
2695 (string (if (listp match) (car match) match))
2696 (realvalue (if (listp match) (cdr match) match)))
2697 (when (symbolp string) (setq string (symbol-name string)))
2698 (when (stringp string)
2699 (funcall insert-function string)
2700 ;; Some sources with candidates-in-buffer have already added
2701 ;; 'anything-realvalue property when creating candidate buffer.
2702 (unless (get-text-property start 'anything-realvalue)
2703 (put-text-property start (line-end-position)
2704 'anything-realvalue realvalue))
2705 (when anything-source-in-each-line-flag
2706 (put-text-property start (line-end-position)
2707 'anything-source source))
2708 (funcall insert-function "\n"))))
2710 (defun anything-insert-header-from-source (source)
2711 (let ((name (assoc-default 'name source)))
2712 (anything-insert-header name
2713 (anything-aif (assoc-default 'header-name source)
2714 (anything-funcall-with-source source it name)))))
2716 (defun anything-insert-header (name &optional display-string)
2717 "Insert header of source NAME into the anything buffer."
2718 (unless (bobp)
2719 (let ((start (point)))
2720 (insert "\n")
2721 (put-text-property start (point) 'anything-header-separator t)))
2723 (let ((start (point)))
2724 (insert name)
2725 (put-text-property (line-beginning-position)
2726 (line-end-position) 'anything-header t)
2727 (when display-string
2728 (overlay-put (make-overlay (line-beginning-position) (line-end-position))
2729 'display display-string))
2730 (insert "\n")
2731 (put-text-property start (point) 'face anything-header-face)))
2734 (defun anything-insert-candidate-separator ()
2735 "Insert separator of candidates into the anything buffer."
2736 (insert anything-candidate-separator)
2737 (put-text-property (line-beginning-position)
2738 (line-end-position) 'anything-candidate-separator t)
2739 (insert "\n"))
2744 ;; (@* "Core: async process")
2745 (defun anything-output-filter (process string)
2746 "Process output from PROCESS."
2747 (let* ((process-assoc (assoc process anything-async-processes))
2748 (process-info (cdr process-assoc))
2749 (insertion-marker (assoc-default 'insertion-marker process-info))
2750 (incomplete-line-info (assoc 'incomplete-line process-info))
2751 (item-count-info (assoc 'item-count process-info))
2752 (limit (anything-candidate-number-limit process-info)))
2754 (with-current-buffer anything-buffer
2755 (save-excursion
2756 (if insertion-marker
2757 (goto-char insertion-marker)
2759 (goto-char (point-max))
2760 (anything-insert-header-from-source process-info)
2761 (setcdr process-assoc
2762 (append process-info `((insertion-marker . ,(point-marker))))))
2764 (let ((lines (split-string string "\n"))
2765 (multiline (assq 'multiline process-info))
2766 (start (point))
2767 candidates separate)
2768 (while lines
2769 (if (not (cdr lines))
2770 ;; store last incomplete line until new output arrives
2771 (setcdr incomplete-line-info (car lines))
2773 (if (cdr incomplete-line-info)
2774 (progn
2775 (push (concat (cdr incomplete-line-info) (car lines))
2776 candidates)
2777 (setcdr incomplete-line-info nil))
2779 (push (car lines) candidates)))
2781 (pop lines))
2783 (setq candidates (reverse candidates))
2784 (dolist (candidate (anything-transform-candidates candidates process-info t))
2785 ;; FIXME
2786 ;; (if (and multiline separate)
2787 ;; (anything-insert-candidate-separator)
2788 ;; (setq separate t))
2789 (anything-insert-match candidate 'insert-before-markers process-info)
2790 (incf (cdr item-count-info))
2791 ;; FIXME
2792 ;; (if multiline
2793 ;; (put-text-property start (point) 'anything-multiline t))
2794 (when (>= (cdr item-count-info) limit)
2795 (anything-kill-async-process process)
2796 (return)))))
2798 (anything-maybe-fit-frame)
2800 (run-hooks 'anything-update-hook)
2802 (if (bobp)
2803 (anything-next-line)
2805 (save-selected-window
2806 (select-window (get-buffer-window anything-buffer 'visible))
2807 (anything-mark-current-line))))))
2810 (defun anything-kill-async-processes ()
2811 "Kill all known asynchronous processes according to
2812 `anything-async-processes'."
2813 "Kill locate process."
2814 (dolist (process-info anything-async-processes)
2815 (anything-kill-async-process (car process-info)))
2816 (setq anything-async-processes nil))
2819 (defun anything-kill-async-process (process)
2820 "Kill PROCESS and detach the associated functions."
2821 (set-process-filter process nil)
2822 (delete-process process))
2825 ;; (@* "Core: action")
2826 (defun anything-execute-selection-action (&optional selection action clear-saved-action display-to-real)
2827 "If a candidate was selected then perform the associated
2828 action."
2829 (setq selection (or selection (anything-get-selection)))
2830 (setq action (or action
2831 anything-saved-action
2832 (if (get-buffer anything-action-buffer)
2833 (anything-get-selection anything-action-buffer)
2834 (anything-get-action))))
2835 (let ((source (or anything-saved-current-source (anything-get-current-source))))
2836 (if (and (not selection) (assoc 'accept-empty source))
2837 (setq selection ""))
2838 (setq display-to-real
2839 (or display-to-real (assoc-default 'display-to-real source)
2840 #'identity))
2841 (if (and (listp action)
2842 (not (functionp action))) ; lambda
2843 ;;select the default action
2844 (setq action (cdar action)))
2845 (unless clear-saved-action (setq anything-saved-action nil))
2846 (if (and selection action)
2847 (anything-funcall-with-source
2848 source action
2849 (anything-funcall-with-source source display-to-real selection)))))
2851 (defun anything-select-action ()
2852 "Select an action for the currently selected candidate.
2853 If action buffer is selected, back to the anything buffer."
2854 (interactive)
2855 (cond ((get-buffer-window anything-action-buffer 'visible)
2856 (set-window-buffer (get-buffer-window anything-action-buffer) anything-buffer)
2857 (kill-buffer anything-action-buffer))
2859 (setq anything-saved-selection (anything-get-selection))
2860 (unless anything-saved-selection
2861 (error "Nothing is selected."))
2862 (setq anything-saved-current-source (anything-get-current-source))
2863 (let ((actions (anything-get-action)))
2864 (if (functionp actions)
2865 (message "Sole action: %s" actions)
2866 (with-current-buffer (get-buffer-create anything-action-buffer)
2867 (erase-buffer)
2868 (buffer-disable-undo)
2869 (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
2870 (set (make-local-variable 'anything-sources)
2871 `(((name . "Actions")
2872 (volatile)
2873 (candidates . ,actions)
2874 ;; Override `anything-candidate-number-limit'
2875 (candidate-number-limit . 9999))))
2876 (set (make-local-variable 'anything-source-filter) nil)
2877 (set (make-local-variable 'anything-selection-overlay) nil)
2878 (set (make-local-variable 'anything-digit-overlays) nil)
2879 (anything-initialize-overlays anything-action-buffer))
2880 (with-selected-window (minibuffer-window)
2881 (delete-minibuffer-contents))
2882 (setq anything-pattern 'dummy) ; so that it differs from the
2883 ; previous one
2885 (anything-check-minibuffer-input))))))
2887 ;; (@* "Core: selection")
2888 (defun anything-move-selection-common (move-func unit direction)
2889 "Move the selection marker to a new position determined by
2890 UNIT and DIRECTION."
2891 (unless (or (zerop (buffer-size (get-buffer (anything-buffer-get))))
2892 (not (anything-window)))
2893 (with-anything-window
2894 (funcall move-func)
2895 (while (and (not (bobp))
2896 (or (anything-pos-header-line-p)
2897 (anything-pos-candidate-separator-p)))
2898 (forward-line (if (and (eq direction 'previous)
2899 (not (eq (line-beginning-position) (point-min))))
2901 1)))
2902 (and (bobp) (forward-line 1)) ;skip first header
2903 (and (eobp) (forward-line -1)) ;avoid last empty line
2904 (when (and anything-display-source-at-screen-top (eq unit 'source))
2905 (set-window-start (selected-window)
2906 (save-excursion (forward-line -1) (point))))
2907 (when (anything-get-previous-header-pos)
2908 (anything-mark-current-line))
2909 (anything-display-mode-line (anything-get-current-source)))))
2911 (defvar anything-mode-line-string-real nil)
2912 (defun anything-display-mode-line (source)
2913 (set (make-local-variable 'anything-mode-line-string)
2914 (anything-interpret-value (or (assoc-default 'mode-line source)
2915 (default-value 'anything-mode-line-string))
2916 source))
2917 (if anything-mode-line-string
2918 (setq mode-line-format
2919 '(" " mode-line-buffer-identification " "
2920 (line-number-mode "%l") " " (anything-follow-mode "(F)")
2921 " " anything-mode-line-string-real "-%-")
2922 anything-mode-line-string-real
2923 (substitute-command-keys anything-mode-line-string))
2924 (setq mode-line-format
2925 (default-value 'mode-line-format)))
2926 (setq header-line-format
2927 (anything-interpret-value (assoc-default 'header-line source) source)))
2929 (defun anything-previous-line ()
2930 "Move selection to the previous line."
2931 (interactive)
2932 (anything-move-selection-common
2933 (lambda ()
2934 (forward-line -1)
2935 (when (anything-pos-multiline-p)
2936 (if (or (anything-pos-header-line-p)
2937 (anything-pos-candidate-separator-p))
2938 (forward-line -1)
2939 (forward-line 1))
2940 (let ((header-pos (anything-get-previous-header-pos))
2941 (candidate-pos (anything-get-previous-candidate-separator-pos)))
2942 (when header-pos
2943 (if (or (null candidate-pos) (< candidate-pos header-pos))
2944 (goto-char header-pos)
2945 (goto-char candidate-pos))
2946 (forward-line 1)))))
2947 'line 'previous))
2949 (defun anything-next-line ()
2950 "Move selection to the next line."
2951 (interactive)
2952 (anything-move-selection-common
2953 (lambda ()
2954 (if (not (anything-pos-multiline-p))
2955 (forward-line 1)
2956 (let ((header-pos (anything-get-next-header-pos))
2957 (candidate-pos (anything-get-next-candidate-separator-pos)))
2958 (if (and candidate-pos
2959 (or (null header-pos)
2960 (< candidate-pos header-pos)))
2961 (goto-char candidate-pos)
2962 (if header-pos
2963 (goto-char header-pos)))
2964 (if candidate-pos
2965 (forward-line 1)))))
2966 'line 'next))
2968 (defun anything-previous-page ()
2969 "Move selection back with a pageful."
2970 (interactive)
2971 (anything-move-selection-common
2972 (lambda ()
2973 (condition-case nil
2974 (scroll-down)
2975 (beginning-of-buffer (goto-char (point-min)))))
2976 'page 'previous))
2978 (defun anything-next-page ()
2979 "Move selection forward with a pageful."
2980 (interactive)
2981 (anything-move-selection-common
2982 (lambda ()
2983 (condition-case nil
2984 (scroll-up)
2985 (end-of-buffer (goto-char (point-max)))))
2986 'page 'next))
2988 (defun anything-beginning-of-buffer ()
2989 "Move selection at the top."
2990 (interactive)
2991 (anything-move-selection-common (lambda () (goto-char (point-min)))
2992 'edge 'previous))
2994 (defun anything-end-of-buffer ()
2995 "Move selection at the bottom."
2996 (interactive)
2997 (anything-move-selection-common (lambda () (goto-char (point-max)))
2998 'edge 'next))
3000 (defun anything-previous-source ()
3001 "Move selection to the previous source."
3002 (interactive)
3003 (anything-move-selection-common
3004 (lambda ()
3005 (forward-line -1)
3006 (if (bobp)
3007 (goto-char (point-max))
3008 (if (anything-pos-header-line-p)
3009 (forward-line -1)
3010 (forward-line 1)))
3011 (goto-char (anything-get-previous-header-pos))
3012 (forward-line 1))
3013 'source 'previous))
3015 (defun anything-next-source ()
3016 "Move selection to the next source."
3017 (interactive)
3018 (anything-move-selection-common
3019 (lambda () (goto-char (or (anything-get-next-header-pos) (point-min))))
3020 'source 'next))
3022 (defun anything-goto-source (source-or-name)
3023 "Move the selection to the source (SOURCE-OR-NAME)."
3024 (anything-move-selection-common
3025 (lambda ()
3026 (goto-char (point-min))
3027 (let ((name (if (stringp source-or-name) source-or-name
3028 (assoc-default 'name source-or-name))))
3029 (while (not (string= name (buffer-substring (point-at-bol) (point-at-eol))))
3030 (goto-char (anything-get-next-header-pos)))))
3031 'source 'next))
3033 (defun anything-mark-current-line ()
3034 "Move selection overlay to current line."
3035 (move-overlay anything-selection-overlay
3036 (line-beginning-position)
3037 (if (anything-pos-multiline-p)
3038 (let ((header-pos (anything-get-next-header-pos))
3039 (candidate-pos (anything-get-next-candidate-separator-pos)))
3040 (or (and (null header-pos) candidate-pos candidate-pos)
3041 (and header-pos candidate-pos (< candidate-pos header-pos) candidate-pos)
3042 header-pos
3043 (point-max)))
3044 (1+ (line-end-position))))
3045 (anything-follow-execute-persistent-action-maybe))
3047 (defun anything-this-command-key ()
3048 (event-basic-type (elt (this-command-keys-vector) 0)))
3049 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
3051 (defun anything-select-with-digit-shortcut ()
3052 (interactive)
3053 (if anything-enable-shortcuts
3054 (save-selected-window
3055 (select-window (anything-window))
3056 (let* ((index (position (anything-this-command-key) anything-shortcut-keys))
3057 (overlay (nth index anything-digit-overlays)))
3058 (when (overlay-buffer overlay)
3059 (goto-char (overlay-start overlay))
3060 (anything-mark-current-line)
3061 (anything-exit-minibuffer))))
3062 (self-insert-command 1)))
3064 (defun anything-exit-minibuffer ()
3065 "Select the current candidate by exiting the minibuffer."
3066 (interactive)
3067 (declare (special anything-iswitchb-candidate-selected))
3068 (setq anything-iswitchb-candidate-selected (anything-get-selection))
3069 (exit-minibuffer))
3072 (defun anything-get-next-header-pos ()
3073 "Return the position of the next header from point."
3074 (next-single-property-change (point) 'anything-header))
3077 (defun anything-get-previous-header-pos ()
3078 "Return the position of the previous header from point"
3079 (previous-single-property-change (point) 'anything-header))
3082 (defun anything-pos-multiline-p ()
3083 "Return non-nil if the current position is in the multiline source region."
3084 (get-text-property (point) 'anything-multiline))
3087 (defun anything-get-next-candidate-separator-pos ()
3088 "Return the position of the next candidate separator from point."
3089 (next-single-property-change (point) 'anything-candidate-separator))
3092 (defun anything-get-previous-candidate-separator-pos ()
3093 "Return the position of the previous candidate separator from point."
3094 (previous-single-property-change (point) 'anything-candidate-separator))
3097 (defun anything-pos-header-line-p ()
3098 "Return t if the current line is a header line."
3099 (or (get-text-property (line-beginning-position) 'anything-header)
3100 (get-text-property (line-beginning-position) 'anything-header-separator)))
3102 (defun anything-pos-candidate-separator-p ()
3103 "Return t if the current line is a candidate separator."
3104 (get-text-property (line-beginning-position) 'anything-candidate-separator))
3106 ;; (@* "Core: error handling")
3107 (defun anything-log-error (&rest args)
3108 "Accumulate error messages into `anything-issued-errors'."
3109 (let ((msg (apply 'format args)))
3110 (unless (member msg anything-issued-errors)
3111 (add-to-list 'anything-issued-errors msg))))
3113 (defun anything-print-error-messages ()
3114 "Print error messages in `anything-issued-errors'."
3115 (message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))
3118 ;; (@* "Core: help")
3119 (defun anything-help-internal (bufname insert-content-fn)
3120 "Show long message during `anything' session."
3121 (save-window-excursion
3122 (select-window (anything-window))
3123 (delete-other-windows)
3124 (switch-to-buffer (get-buffer-create bufname))
3125 (setq mode-line-format "%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
3126 (setq cursor-type nil)
3127 (erase-buffer)
3128 (funcall insert-content-fn)
3129 (goto-char 1)
3130 (ignore-errors
3131 (loop for event = (read-event) do
3132 (case event
3133 ((?\C-v ? ) (scroll-up))
3134 ((?\M-v ?b) (scroll-down))
3135 (t (return)))))))
3137 (defun anything-help ()
3138 "Help of `anything'."
3139 (interactive)
3140 (anything-help-internal
3141 " *Anything Help*"
3142 (lambda ()
3143 (insert (substitute-command-keys
3144 (anything-interpret-value anything-help-message)))
3145 (org-mode))))
3147 (defun anything-debug-output ()
3148 "Show all anything-related variables at this time."
3149 (interactive)
3150 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function))
3152 (defun anything-debug-output-function (&optional vars)
3153 (dolist (v (or vars
3154 anything-debug-variables
3155 (apropos-internal "^anything-" 'boundp)))
3156 (insert "** "
3157 (symbol-name v) "\n"
3158 (pp-to-string (symbol-value v)) "\n")))
3160 ;; (@* "Core: misc")
3161 (defun anything-kill-buffer-hook ()
3162 "Remove tick entry from `anything-tick-hash' when killing a buffer."
3163 (loop for key being the hash-keys in anything-tick-hash
3164 if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
3165 do (remhash key anything-tick-hash)))
3166 (add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
3168 (defun anything-maybe-fit-frame ()
3169 "Fit anything frame to its buffer, and put it at top right of display.
3171 It is disabled by default because some flickering occurred in some environment.
3172 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
3173 `fit-frame-inhibit-fitting' to nil.
3174 You can set user options `fit-frame-max-width-percent' and
3175 `fit-frame-max-height-percent' to control max frame size."
3176 (declare (warn (unresolved 0)))
3177 (when (and (require 'fit-frame nil t)
3178 (boundp 'fit-frame-inhibit-fitting-flag)
3179 (not anything-inhibit-fit-frame-flag)
3180 (not fit-frame-inhibit-fitting-flag)
3181 (anything-window))
3182 (ignore-errors
3183 (with-anything-window
3184 (fit-frame nil nil nil t)
3185 (modify-frame-parameters
3186 (selected-frame)
3187 `((left . ,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
3188 (top . 0))))))) ; The (top . 0) shouldn't be necessary (Emacs bug).
3190 (defun anything-preselect (candidate-or-regexp)
3191 (when candidate-or-regexp
3192 (with-anything-window
3193 (goto-char (point-min))
3194 ;; go to first candidate of first source
3195 (forward-line 1)
3196 (let ((start (point)))
3197 (unless (or (re-search-forward (concat "^" (regexp-quote candidate-or-regexp) "$") nil t)
3198 (progn (goto-char start)
3199 (re-search-forward candidate-or-regexp nil t)))
3200 (goto-char start))
3201 (anything-mark-current-line)))))
3203 (defun anything-delete-current-selection ()
3204 "Delete the currently selected item."
3205 (interactive)
3206 (with-anything-window
3207 (cond ((anything-pos-multiline-p)
3208 (anything-aif (anything-get-next-candidate-separator-pos)
3209 (delete-region (point-at-bol)
3210 (1+ (progn (goto-char it) (point-at-eol))))
3211 ;; last candidate
3212 (goto-char (anything-get-previous-candidate-separator-pos))
3213 (delete-region (point-at-bol) (point-max)))
3214 (when (eobp)
3215 (goto-char (or (anything-get-previous-candidate-separator-pos)
3216 (point-min)))
3217 (forward-line 1)))
3219 (delete-region (point-at-bol) (1+ (point-at-eol)))
3220 (when (eobp) (forward-line -1))))
3221 (anything-mark-current-line)))
3223 (defun anything-delete-minibuffer-content ()
3224 "Same as `delete-minibuffer-contents' but this is a command."
3225 (interactive)
3226 (delete-minibuffer-contents))
3228 ;; (@* "Built-in plug-in: type")
3229 (defun anything-compile-source--type (source)
3230 (anything-aif (assoc-default 'type source)
3231 (append source (assoc-default it anything-type-attributes) nil)
3232 source))
3234 ;; `define-anything-type-attribute' is public API.
3236 (defun anything-add-type-attribute (type definition)
3237 (anything-aif (assq type anything-type-attributes)
3238 (setq anything-type-attributes (delete it anything-type-attributes)))
3239 (push (cons type definition) anything-type-attributes))
3241 (defvar anything-types nil)
3242 (defun anything-document-type-attribute (type doc)
3243 (add-to-list 'anything-types type t)
3244 (put type 'anything-typeattrdoc
3245 (concat "- " (symbol-name type) "\n\n" doc "\n")))
3247 (defadvice documentation-property (after anything-document-type-attribute activate)
3248 "Hack to display type attributes' documentation as `anything-type-attributes' docstring."
3249 (when (eq symbol 'anything-type-attributes)
3250 (setq ad-return-value
3251 (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
3252 (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
3253 anything-types "\n")))))
3255 ;; (@* "Built-in plug-in: dummy")
3256 (defun anything-dummy-candidate (candidate source)
3257 ;; `source' is defined in filtered-candidate-transformer
3258 (list anything-pattern))
3260 (defun anything-compile-source--dummy (source)
3261 (if (assoc 'dummy source)
3262 (append source
3263 '((candidates "dummy")
3264 (accept-empty)
3265 (match identity)
3266 (filtered-candidate-transformer . anything-dummy-candidate)
3267 (disable-shortcuts)
3268 (volatile)))
3269 source))
3271 ;; (@* "Built-in plug-in: disable-shortcuts")
3272 (defvar anything-orig-enable-shortcuts nil)
3273 (defun anything-save-enable-shortcuts ()
3274 (anything-once
3275 (lambda () (setq anything-orig-enable-shortcuts anything-enable-shortcuts
3276 anything-enable-shortcuts nil))))
3277 (defun anything-compile-source--disable-shortcuts (source)
3278 (if (assoc 'disable-shortcuts source)
3279 (append `((init ,@(anything-mklist (assoc-default 'init source))
3280 anything-save-enable-shortcuts)
3281 (resume ,@(anything-mklist (assoc-default 'resume source))
3282 anything-save-enable-shortcuts)
3283 (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
3284 (lambda () (setq anything-enable-shortcuts anything-orig-enable-shortcuts))))
3285 source)
3286 source))
3288 ;; (@* "Built-in plug-in: candidates-in-buffer")
3289 (defun anything-candidates-in-buffer ()
3290 "Get candidates from the candidates buffer according to `anything-pattern'.
3292 BUFFER is `anything-candidate-buffer' by default. Each
3293 candidate must be placed in one line. This function is meant to
3294 be used in candidates-in-buffer or candidates attribute of an
3295 anything source. Especially fast for many (1000+) candidates.
3298 '((name . \"many files\")
3299 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
3300 (insert-many-filenames))))
3301 (search re-search-forward) ; optional
3302 (candidates-in-buffer)
3303 (type . file))
3305 +===============================================================+
3306 | The new way of making and narrowing candidates: Using buffers |
3307 +===============================================================+
3309 By default, `anything' makes candidates by evaluating the
3310 candidates function, then narrows them by `string-match' for each
3311 candidate.
3313 But this way is very slow for many candidates. The new way is
3314 storing all candidates in a buffer and narrowing them by
3315 `re-search-forward'. Search function is customizable by search
3316 attribute. The important point is that buffer processing is MUCH
3317 FASTER than string list processing and is the Emacs way.
3319 The init function writes all candidates to a newly-created
3320 candidate buffer. The candidates buffer is created or specified
3321 by `anything-candidate-buffer'. Candidates are stored in a line.
3323 The candidates function narrows all candidates, IOW creates a
3324 subset of candidates dynamically. It is the task of
3325 `anything-candidates-in-buffer'. As long as
3326 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
3327 sufficient in most cases.
3329 Note that `(candidates-in-buffer)' is shortcut of three attributes:
3330 (candidates . anything-candidates-in-buffer)
3331 (volatile)
3332 (match identity)
3333 And `(candidates-in-buffer . func)' is shortcut of three attributes:
3334 (candidates . func)
3335 (volatile)
3336 (match identity)
3337 The expansion is performed in `anything-get-sources'.
3339 The candidates-in-buffer attribute implies the volatile attribute.
3340 The volatile attribute is needed because `anything-candidates-in-buffer'
3341 creates candidates dynamically and need to be called everytime
3342 `anything-pattern' changes.
3344 Because `anything-candidates-in-buffer' plays the role of `match' attribute
3345 function, specifying `(match identity)' makes the source slightly faster.
3347 To customize `anything-candidates-in-buffer' behavior, use search,
3348 get-line and search-from-end attributes. See also `anything-sources' docstring.
3350 (declare (special source))
3351 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
3352 anything-pattern
3353 (or (assoc-default 'get-line source)
3354 #'buffer-substring-no-properties)
3355 ;; use external variable `source'.
3356 (or (assoc-default 'search source)
3357 (if (assoc 'search-from-end source)
3358 '(re-search-backward)
3359 '(re-search-forward)))
3360 (anything-candidate-number-limit source)
3361 (assoc 'search-from-end source)))
3363 (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)
3364 ;; buffer == nil when candidates buffer does not exist.
3365 (when buffer
3366 (with-current-buffer buffer
3367 (let ((start-point (if search-from-end (point-max) (point-min)))
3368 (next-line-fn (if search-from-end
3369 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
3370 #'forward-line))
3371 (endp (if search-from-end #'bobp #'eobp)))
3372 (goto-char (1- start-point))
3373 (if (string= pattern "")
3374 (delq nil (loop until (funcall endp)
3375 for i from 1 to limit
3376 collecting (funcall get-line-fn (point-at-bol) (point-at-eol))
3377 do (funcall next-line-fn 1)))
3379 (let ((i 1)
3380 (next-line-fn (if search-from-end
3381 (lambda (x) (goto-char (max (point-at-bol) 1)))
3382 #'forward-line))
3383 buffer-read-only
3384 matches exit newmatches)
3385 (progn
3386 (goto-char (point-min))
3387 (insert "\n")
3388 (goto-char (point-max))
3389 (insert "\n")
3390 (setq start-point (if search-from-end (point-max) (point-min)))
3391 (clrhash anything-cib-hash)
3392 (unwind-protect
3393 (dolist (searcher search-fns)
3394 (goto-char start-point)
3395 (setq newmatches nil)
3396 (loop while (funcall searcher pattern nil t)
3397 if (or (funcall endp) (< limit i))
3398 do (setq exit t) (return)
3399 else do
3400 (let ((cand (funcall get-line-fn (point-at-bol) (point-at-eol))))
3401 (unless (gethash cand anything-cib-hash)
3402 (puthash cand t anything-cib-hash)
3403 (incf i)
3404 (push cand newmatches)))
3405 (funcall next-line-fn 1))
3406 (setq matches (append matches (nreverse newmatches)))
3407 (if exit (return)))
3408 (goto-char (point-min))
3409 (delete-char 1)
3410 (goto-char (1- (point-max)))
3411 (delete-char 1)
3413 (set-buffer-modified-p nil)))
3414 (delq nil matches)))))))
3417 (defun anything-candidate-buffer (&optional create-or-buffer)
3418 "Register and return a buffer containing candidates of current source.
3419 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3420 then global candidates buffer.
3422 Acceptable values of CREATE-OR-BUFFER:
3424 - nil (omit)
3425 Only return the candidates buffer.
3426 - a buffer
3427 Register a buffer as a candidates buffer.
3428 - 'global
3429 Create a new global candidates buffer,
3430 named \" *anything candidates:SOURCE*\".
3431 - other non-nil value
3432 Create a new global candidates buffer,
3433 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
3435 (let* ((gbufname (format " *anything candidates:%s*" anything-source-name))
3436 (lbufname (concat gbufname (buffer-name anything-current-buffer)))
3437 buf)
3438 (when create-or-buffer
3439 (if (bufferp create-or-buffer)
3440 (setq anything-candidate-buffer-alist
3441 (cons (cons anything-source-name create-or-buffer)
3442 (delete (assoc anything-source-name anything-candidate-buffer-alist)
3443 anything-candidate-buffer-alist)))
3444 (add-to-list 'anything-candidate-buffer-alist
3445 (cons anything-source-name create-or-buffer))
3446 (when (eq create-or-buffer 'global)
3447 (loop for b in (buffer-list)
3448 if (string-match (format "^%s" (regexp-quote gbufname)) (buffer-name b))
3449 do (kill-buffer b)))
3450 (with-current-buffer
3451 (get-buffer-create (if (eq create-or-buffer 'global) gbufname lbufname))
3452 (buffer-disable-undo)
3453 (erase-buffer)
3454 (font-lock-mode -1))))
3455 (or (get-buffer lbufname)
3456 (get-buffer gbufname)
3457 (anything-aif (assoc-default anything-source-name anything-candidate-buffer-alist)
3458 (and (buffer-live-p it) it)))))
3460 (defun anything-compile-source--candidates-in-buffer (source)
3461 (anything-aif (assoc 'candidates-in-buffer source)
3462 (append source `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
3463 (volatile) (match identity)))
3464 source))
3466 ;; (@* "Utility: resplit anything window")
3467 (defun anything-toggle-resplit-window ()
3468 "Toggle resplit anything window, vertically or horizontally."
3469 (interactive)
3470 (with-anything-window
3471 (let ((before-height (window-height)))
3472 (delete-window)
3473 (set-window-buffer
3474 (select-window (if (= (window-height) before-height)
3475 (split-window-vertically)
3476 (split-window-horizontally)))
3477 anything-buffer))))
3479 ;; (@* "Utility: select another action by key")
3480 (defun anything-select-nth-action (n)
3481 "Select the nth action for the currently selected candidate."
3482 (setq anything-saved-selection (anything-get-selection))
3483 (unless anything-saved-selection
3484 (error "Nothing is selected."))
3485 (setq anything-saved-action (cdr (elt (anything-get-action) n)))
3486 (anything-exit-minibuffer))
3488 (defun anything-select-2nd-action ()
3489 "Select the 2nd action for the currently selected candidate."
3490 (interactive)
3491 (anything-select-nth-action 1))
3493 (defun anything-select-3rd-action ()
3494 "Select the 3rd action for the currently selected candidate."
3495 (interactive)
3496 (anything-select-nth-action 2))
3498 (defun anything-select-4th-action ()
3499 "Select the 4th action for the currently selected candidate."
3500 (interactive)
3501 (anything-select-nth-action 3))
3503 (defun anything-select-2nd-action-or-end-of-line ()
3504 "Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
3505 Otherwise goto the end of minibuffer."
3506 (interactive)
3507 (if (eolp)
3508 (anything-select-nth-action 1)
3509 (end-of-line)))
3511 ;; (@* "Utility: Persistent Action")
3512 (defmacro with-anything-display-same-window (&rest body)
3513 "Make `pop-to-buffer' and `display-buffer' display in the same window."
3514 `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
3515 ,@body))
3516 (put 'with-anything-display-same-window 'lisp-indent-function 0)
3518 (defun* anything-execute-persistent-action (&optional (attr 'persistent-action))
3519 "If a candidate is selected then perform the associated action without quitting anything."
3520 (interactive)
3521 (save-selected-window
3522 (select-window (get-buffer-window (anything-buffer-get)))
3523 (select-window (setq minibuffer-scroll-window
3524 (if (one-window-p t) (split-window)
3525 (next-window (selected-window) 1))))
3526 (let ((anything-in-persistent-action t))
3527 (with-anything-display-same-window
3528 (anything-execute-selection-action
3530 (or (assoc-default attr (anything-get-current-source))
3531 (anything-get-action))
3533 (run-hooks 'anything-after-persistent-action-hook)))))
3535 (defun anything-persistent-action-display-buffer (buf &optional not-this-window)
3536 "Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
3537 If `anything-persistent-action-use-special-display' is non-nil and
3538 BUF is to be displayed by `special-display-function', use it.
3539 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
3540 (let* ((name (buffer-name buf))
3541 display-buffer-function pop-up-windows
3542 (same-window-regexps
3543 (unless (and anything-persistent-action-use-special-display
3544 (or (member name
3545 (mapcar (lambda (x) (or (car-safe x) x)) special-display-buffer-names))
3546 (remove-if-not
3547 (lambda (x) (string-match (or (car-safe x) x) name))
3548 special-display-regexps)))
3549 '("."))))
3550 (display-buffer buf not-this-window)))
3552 ;; scroll-other-window(-down)? for persistent-action
3553 (defun anything-scroll-other-window-base (command)
3554 (save-selected-window
3555 (select-window
3556 (some-window
3557 (lambda (w) (not (string= anything-buffer (buffer-name (window-buffer w)))))
3558 'no-minibuffer 'current-frame))
3559 (call-interactively command)))
3561 (defun anything-scroll-other-window ()
3562 "Scroll other window (not *Anything* window) upward."
3563 (interactive)
3564 (anything-scroll-other-window-base (lambda ()
3565 (interactive)
3566 (scroll-up anything-scroll-amount))))
3567 (defun anything-scroll-other-window-down ()
3568 "Scroll other window (not *Anything* window) downward."
3569 (interactive)
3570 (anything-scroll-other-window-base (lambda ()
3571 (interactive)
3572 (scroll-down anything-scroll-amount))))
3574 ;; (@* "Utility: Visible Mark")
3575 (defface anything-visible-mark
3576 '((((min-colors 88) (background dark))
3577 (:background "green1" :foreground "black"))
3578 (((background dark)) (:background "green" :foreground "black"))
3579 (((min-colors 88)) (:background "green1"))
3580 (t (:background "green")))
3581 "Face for visible mark."
3582 :group 'anything)
3583 (defvar anything-visible-mark-face 'anything-visible-mark)
3584 (defvar anything-visible-mark-overlays nil)
3586 (defun anything-clear-visible-mark ()
3587 (mapc 'delete-overlay anything-visible-mark-overlays)
3588 (setq anything-visible-mark-overlays nil))
3589 (add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
3591 ;; (defun anything-toggle-visible-mark ()
3592 ;; (interactive)
3593 ;; (with-anything-window
3594 ;; (anything-aif (loop for o in anything-visible-mark-overlays
3595 ;; when (equal (line-beginning-position) (overlay-start o))
3596 ;; do (return o))
3597 ;; ;; delete
3598 ;; (progn (delete-overlay it)
3599 ;; (delq it anything-visible-mark-overlays))
3600 ;; (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
3601 ;; (overlay-put o 'face anything-visible-mark-face)
3602 ;; (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3603 ;; (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3604 ;; (add-to-list 'anything-visible-mark-overlays o)))))
3606 (defvar anything-c-marked-candidate-list nil
3607 "[OBSOLETE] DO NOT USE!!")
3608 (defvar anything-marked-candidates nil
3609 "Marked candadates. List of (source . real) pair.")
3610 (defun anything-toggle-visible-mark ()
3611 (interactive)
3612 (with-anything-window
3613 (let ((display (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
3614 (source (anything-get-current-source))
3615 (selection (anything-get-selection)))
3616 (anything-aif (loop for o in anything-visible-mark-overlays
3617 when (equal (line-beginning-position) (overlay-start o))
3618 do (return o))
3619 ;; delete
3620 (progn
3621 (setq anything-c-marked-candidate-list
3622 (remove
3623 display anything-c-marked-candidate-list))
3624 (setq anything-marked-candidates
3625 (remove
3626 (cons source selection)
3627 anything-marked-candidates))
3628 (delete-overlay it)
3629 (setq anything-visible-mark-overlays (delq it anything-visible-mark-overlays)))
3630 (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
3631 (overlay-put o 'face anything-visible-mark-face)
3632 (overlay-put o 'source (assoc-default 'name source))
3633 (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3634 (add-to-list 'anything-visible-mark-overlays o)
3635 (push display anything-c-marked-candidate-list)
3636 (push (cons source selection) anything-marked-candidates)))
3637 (anything-next-line))))
3639 (defun anything-marked-candidates ()
3640 "Marked candidates (real value) of current source if any,
3641 otherwise 1-element list of current selection.
3643 It is analogous to `dired-get-marked-files'."
3644 (if anything-marked-candidates
3645 (loop with current-src = (anything-get-current-source)
3646 for (source . real) in (reverse anything-marked-candidates)
3647 when (eq current-src source)
3648 collect real)
3649 (list (anything-get-selection))))
3651 (defun anything-reset-marked-candidates ()
3652 (setq anything-c-marked-candidate-list nil)
3653 (setq anything-marked-candidates nil))
3655 (add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
3656 (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3658 (defun anything-revive-visible-mark ()
3659 (interactive)
3660 (with-current-buffer anything-buffer
3661 (loop for o in anything-visible-mark-overlays do
3662 (goto-char (point-min))
3663 (let (moved)
3664 (while (and (not moved)
3665 (search-forward (overlay-get o 'string) nil t))
3666 (forward-line -1)
3667 (when (and (save-excursion
3668 (goto-char (anything-get-previous-header-pos))
3669 (equal (overlay-get o 'source)
3670 (buffer-substring (line-beginning-position) (line-end-position))))
3671 (not (find-if (lambda (x)
3672 (memq x anything-visible-mark-overlays))
3673 (overlays-at (point)))))
3674 (move-overlay o (line-beginning-position) (1+ (line-end-position)))
3675 (setq moved t))
3676 (forward-line 1))))))
3677 (add-hook 'anything-update-hook 'anything-revive-visible-mark)
3679 (defun anything-next-visible-mark (&optional prev)
3680 (interactive)
3681 (with-anything-window
3682 (block 'exit
3683 (setq anything-visible-mark-overlays
3684 (sort* anything-visible-mark-overlays
3685 '< :key 'overlay-start))
3686 (let ((i (position-if (lambda (o) (< (point) (overlay-start o)))
3687 anything-visible-mark-overlays)))
3688 (when prev
3689 (unless anything-visible-mark-overlays (return-from 'exit nil))
3690 (if (not i) (setq i (length anything-visible-mark-overlays)))
3691 (if (equal (point) (overlay-start (nth (1- i) anything-visible-mark-overlays)))
3692 (setq i (1- i))))
3693 (when i
3694 (goto-char (overlay-start (nth (if prev (1- i) i) anything-visible-mark-overlays)))
3695 (anything-mark-current-line))))))
3697 (defun anything-prev-visible-mark ()
3698 (interactive)
3699 (anything-next-visible-mark t))
3701 ;; (@* "Utility: `find-file' integration")
3702 (defun anything-quit-and-find-file ()
3703 "Drop into `find-file' from `anything' like `iswitchb-find-file'.
3704 If current selection is a buffer or a file, `find-file' from its directory."
3705 (interactive)
3706 (anything-run-after-quit
3707 (lambda (f)
3708 (if (file-exists-p f)
3709 (let ((default-directory (file-name-directory f)))
3710 (call-interactively 'find-file))
3711 (call-interactively 'find-file)))
3712 (anything-aif (get-buffer (anything-get-selection))
3713 (buffer-file-name it)
3714 (expand-file-name (anything-get-selection)))))
3716 ;; (@* "Utility: Selection Paste")
3717 (defun anything-yank-selection ()
3718 "Set minibuffer contents to current selection."
3719 (interactive)
3720 (delete-minibuffer-contents)
3721 (insert (anything-get-selection nil t)))
3723 (defun anything-kill-selection-and-quit ()
3724 "Store current selection to kill ring.
3725 You can paste it by typing C-y."
3726 (interactive)
3727 (anything-run-after-quit
3728 (lambda (sel)
3729 (kill-new sel)
3730 (message "Killed: %s" sel))
3731 (anything-get-selection nil t)))
3734 ;; (@* "Utility: Automatical execution of persistent-action")
3735 (add-to-list 'minor-mode-alist '(anything-follow-mode " AFollow"))
3736 (defun anything-follow-mode ()
3737 "If this mode is on, persistent action is executed everytime the cursor is moved."
3738 (interactive)
3739 (with-current-buffer anything-buffer
3740 (setq anything-follow-mode (not anything-follow-mode))
3741 (message "anything-follow-mode is %s"
3742 (if anything-follow-mode "enabled" "disabled"))))
3744 (defun anything-follow-execute-persistent-action-maybe ()
3745 "Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
3746 (and (buffer-local-value 'anything-follow-mode
3747 (get-buffer-create anything-buffer))
3748 (sit-for anything-input-idle-delay)
3749 (anything-window)
3750 (anything-get-selection)
3751 (save-excursion
3752 (anything-execute-persistent-action))))
3754 ;; (@* "Utility: Incremental search within results (unmaintained)")
3756 (defvar anything-isearch-original-global-map nil
3757 "Original global map before Anything isearch is started.")
3759 (defvar anything-isearch-original-message-timeout nil
3760 "Original message timeout before Anything isearch is started.")
3762 (defvar anything-isearch-pattern nil
3763 "The current isearch pattern.")
3765 (defvar anything-isearch-message-suffix ""
3766 "Message suffix indicating the current state of the search.")
3768 (defvar anything-isearch-original-point nil
3769 "Original position of point before isearch is started.")
3771 (defvar anything-isearch-original-window nil
3772 "Original selected window before isearch is started.")
3774 (defvar anything-isearch-original-cursor-in-non-selected-windows nil
3775 "Original value of cursor-in-non-selected-windows before isearch is started.")
3777 (defvar anything-isearch-original-post-command-hook nil
3778 "Original value of post-command-hook before isearch is started.")
3780 (defvar anything-isearch-match-positions nil
3781 "Stack of positions of matches or non-matches.
3783 It's a list of plists with two properties: `event', the last user
3784 event, `start', the start position of the current match, and
3785 `pos', the position of point after that event.
3787 The value of `event' can be the following symbols: `char' if a
3788 character was typed, `error' if a non-matching character was
3789 typed, `search' if a forward search had to be done after a
3790 character, and `search-again' if a search was done for the next
3791 occurrence of the current pattern.")
3793 (defvar anything-isearch-match-start nil
3794 "Start position of the current match.")
3797 (defun anything-isearch ()
3798 "Start incremental search within results. (UNMAINTAINED)"
3799 (interactive)
3800 (if (zerop (buffer-size (get-buffer (anything-buffer-get))))
3801 (message "There are no results.")
3803 (setq anything-isearch-original-message-timeout minibuffer-message-timeout)
3804 (setq minibuffer-message-timeout nil)
3806 (setq anything-isearch-original-global-map global-map)
3808 (condition-case nil
3809 (progn
3810 (setq anything-isearch-original-window (selected-window))
3811 (select-window (anything-window))
3812 (setq cursor-type t)
3814 (setq anything-isearch-original-post-command-hook
3815 (default-value 'post-command-hook))
3816 (setq-default post-command-hook nil)
3817 (add-hook 'post-command-hook 'anything-isearch-post-command)
3819 (use-global-map anything-isearch-map)
3820 (setq overriding-terminal-local-map anything-isearch-map)
3822 (setq anything-isearch-pattern "")
3824 (setq anything-isearch-original-cursor-in-non-selected-windows
3825 cursor-in-non-selected-windows)
3826 (setq cursor-in-non-selected-windows nil)
3828 (setq anything-isearch-original-point (point-marker))
3829 (goto-char (point-min))
3830 (forward-line)
3831 (anything-mark-current-line)
3833 (setq anything-isearch-match-positions nil)
3834 (setq anything-isearch-match-start (point-marker))
3836 (if anything-isearch-overlay
3837 ;; make sure the overlay belongs to the anything buffer
3838 (move-overlay anything-isearch-overlay (point-min) (point-min)
3839 (get-buffer (anything-buffer-get)))
3841 (setq anything-isearch-overlay (make-overlay (point-min) (point-min)))
3842 (overlay-put anything-isearch-overlay 'face anything-isearch-match-face))
3844 (setq anything-isearch-message-suffix
3845 (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))
3847 (error (anything-isearch-cleanup)))))
3850 (defun anything-isearch-post-command ()
3851 "Print the current pattern after every command."
3852 (anything-isearch-message)
3853 (when (anything-window)
3854 (with-anything-window
3855 (move-overlay anything-isearch-overlay anything-isearch-match-start (point)
3856 (get-buffer (anything-buffer-get))))))
3859 (defun anything-isearch-printing-char ()
3860 "Add printing char to the pattern."
3861 (interactive)
3862 (let ((char (char-to-string last-command-event)))
3863 (setq anything-isearch-pattern (concat anything-isearch-pattern char))
3865 (with-anything-window
3866 (if (looking-at char)
3867 (progn
3868 (push (list 'event 'char
3869 'start anything-isearch-match-start
3870 'pos (point-marker))
3871 anything-isearch-match-positions)
3872 (forward-char))
3874 (let ((start (point)))
3875 (while (and (re-search-forward anything-isearch-pattern nil t)
3876 (anything-pos-header-line-p)))
3877 (if (or (anything-pos-header-line-p)
3878 (eq start (point)))
3879 (progn
3880 (goto-char start)
3881 (push (list 'event 'error
3882 'start anything-isearch-match-start
3883 'pos (point-marker))
3884 anything-isearch-match-positions))
3886 (push (list 'event 'search
3887 'start anything-isearch-match-start
3888 'pos (copy-marker start))
3889 anything-isearch-match-positions)
3890 (setq anything-isearch-match-start (copy-marker (match-beginning 0))))))
3892 (anything-mark-current-line))))
3895 (defun anything-isearch-again ()
3896 "Search again for the current pattern"
3897 (interactive)
3898 (if (equal anything-isearch-pattern "")
3899 (setq anything-isearch-message-suffix "no pattern yet")
3901 (with-anything-window
3902 (let ((start (point)))
3903 (while (and (re-search-forward anything-isearch-pattern nil t)
3904 (anything-pos-header-line-p)))
3905 (if (or (anything-pos-header-line-p)
3906 (eq start (point)))
3907 (progn
3908 (goto-char start)
3909 (unless (eq 'error (plist-get (car anything-isearch-match-positions)
3910 'event))
3911 (setq anything-isearch-message-suffix "no more matches")))
3913 (push (list 'event 'search-again
3914 'start anything-isearch-match-start
3915 'pos (copy-marker start))
3916 anything-isearch-match-positions)
3917 (setq anything-isearch-match-start (copy-marker (match-beginning 0)))
3919 (anything-mark-current-line))))))
3922 (defun anything-isearch-delete ()
3923 "Undo last event."
3924 (interactive)
3925 (unless (equal anything-isearch-pattern "")
3926 (let ((last (pop anything-isearch-match-positions)))
3927 (unless (eq 'search-again (plist-get last 'event))
3928 (setq anything-isearch-pattern
3929 (substring anything-isearch-pattern 0 -1)))
3931 (with-anything-window
3932 (goto-char (plist-get last 'pos))
3933 (setq anything-isearch-match-start (plist-get last 'start))
3934 (anything-mark-current-line)))))
3937 (defun anything-isearch-default-action ()
3938 "Execute the default action for the selected candidate."
3939 (interactive)
3940 (anything-isearch-cleanup)
3941 (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))
3944 (defun anything-isearch-select-action ()
3945 "Choose an action for the selected candidate."
3946 (interactive)
3947 (anything-isearch-cleanup)
3948 (with-anything-window
3949 (anything-select-action)))
3952 (defun anything-isearch-cancel ()
3953 "Cancel Anything isearch."
3954 (interactive)
3955 (anything-isearch-cleanup)
3956 (when (anything-window)
3957 (with-anything-window
3958 (goto-char anything-isearch-original-point)
3959 (anything-mark-current-line))))
3962 (defun anything-isearch-cleanup ()
3963 "Clean up the mess."
3964 (setq minibuffer-message-timeout anything-isearch-original-message-timeout)
3965 (with-current-buffer (anything-buffer-get)
3966 (setq overriding-terminal-local-map nil)
3967 (setq cursor-type nil)
3968 (setq cursor-in-non-selected-windows
3969 anything-isearch-original-cursor-in-non-selected-windows))
3970 (when anything-isearch-original-window
3971 (select-window anything-isearch-original-window))
3973 (use-global-map anything-isearch-original-global-map)
3974 (setq-default post-command-hook anything-isearch-original-post-command-hook)
3975 (when (overlayp anything-isearch-overlay)
3976 (delete-overlay anything-isearch-overlay)))
3979 (defun anything-isearch-message ()
3980 "Print prompt."
3981 (if (and (equal anything-isearch-message-suffix "")
3982 (eq (plist-get (car anything-isearch-match-positions) 'event)
3983 'error))
3984 (setq anything-isearch-message-suffix "failing"))
3986 (unless (equal anything-isearch-message-suffix "")
3987 (setq anything-isearch-message-suffix
3988 (concat " [" anything-isearch-message-suffix "]")))
3990 (message (concat "Search within results: "
3991 anything-isearch-pattern
3992 anything-isearch-message-suffix))
3994 (setq anything-isearch-message-suffix ""))
3997 ;; (@* "Utility: Iswitchb integration (unmaintained)")
3999 (defvar anything-iswitchb-candidate-selected nil
4000 "Indicates whether an anything candidate is selected from iswitchb.")
4002 (defvar anything-iswitchb-frame-configuration nil
4003 "Saved frame configuration, before anything buffer was displayed.")
4005 (defvar anything-iswitchb-saved-keys nil
4006 "The original in iswitchb before binding anything keys.")
4009 (defun anything-iswitchb-setup ()
4010 "Integrate anything completion into iswitchb (UNMAINTAINED).
4012 If the user is idle for `anything-iswitchb-idle-delay' seconds
4013 after typing something into iswitchb then anything candidates are
4014 shown for the current iswitchb input.
4016 ESC cancels anything completion and returns to normal iswitchb.
4018 Some key bindings in `anything-map' are modified.
4019 See also `anything-iswitchb-setup-keys'."
4020 (interactive)
4022 (require 'iswitchb)
4024 ;; disable timid completion during iswitchb
4025 (put 'iswitchb-buffer 'timid-completion 'disabled)
4026 (add-hook 'minibuffer-setup-hook 'anything-iswitchb-minibuffer-setup)
4028 (defadvice iswitchb-visit-buffer
4029 (around anything-iswitchb-visit-buffer activate)
4030 (if anything-iswitchb-candidate-selected
4031 (anything-execute-selection-action)
4032 ad-do-it))
4034 (defadvice iswitchb-possible-new-buffer
4035 (around anything-iswitchb-possible-new-buffer activate)
4036 (if anything-iswitchb-candidate-selected
4037 (anything-execute-selection-action)
4038 ad-do-it))
4039 (anything-iswitchb-setup-keys)
4040 (message "Iswitchb integration is activated."))
4042 (defun anything-iswitchb-setup-keys ()
4043 "Modify `anything-map' for anything-iswitchb users.
4045 C-p is used instead of M-p, because anything uses ESC
4046 (currently hardcoded) for `anything-iswitchb-cancel-anything' and
4047 Emacs handles ESC and Meta as synonyms, so ESC overrides
4048 other commands with Meta prefix.
4050 Note that iswitchb uses M-p and M-n by default for history
4051 navigation, so you should bind C-p and C-n in
4052 `iswitchb-mode-map' if you use the history keys and don't want
4053 to use different keys for iswitchb while anything is not yet
4054 kicked in. These keys are not bound automatically by anything
4055 in `iswitchb-mode-map' because they (C-n at least) already have
4056 a standard iswitchb binding which you might be accustomed to.
4058 Binding M-s is used instead of C-s, because C-s has a binding in
4059 iswitchb. You can rebind it AFTER `anything-iswitchb-setup'.
4061 Unbind C-r to prevent problems during anything-isearch."
4062 (define-key anything-map (kbd "C-s") nil)
4063 (define-key anything-map (kbd "M-p") nil)
4064 (define-key anything-map (kbd "M-n") nil)
4065 (define-key anything-map (kbd "M-v") nil)
4066 (define-key anything-map (kbd "C-v") nil)
4067 (define-key anything-map (kbd "C-p") 'anything-previous-history-element)
4068 (define-key anything-map (kbd "C-n") 'anything-next-history-element)
4069 (define-key anything-map (kbd "M-s") nil)
4070 (define-key anything-map (kbd "M-s") 'anything-isearch)
4071 (define-key anything-map (kbd "C-r") nil))
4073 (defun anything-iswitchb-minibuffer-setup ()
4074 (when (eq this-command 'iswitchb-buffer)
4075 (add-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
4077 (setq anything-iswitchb-frame-configuration nil)
4078 (setq anything-iswitchb-candidate-selected nil)
4079 (add-hook 'anything-update-hook 'anything-iswitchb-handle-update)
4081 (anything-initialize)
4083 (add-hook 'post-command-hook 'anything-iswitchb-check-input)))
4086 (defun anything-iswitchb-minibuffer-exit ()
4087 (remove-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
4088 (remove-hook 'post-command-hook 'anything-iswitchb-check-input)
4089 (remove-hook 'anything-update-hook 'anything-iswitchb-handle-update)
4091 (anything-cleanup)
4093 (when anything-iswitchb-frame-configuration
4094 (anything-set-frame/window-configuration anything-iswitchb-frame-configuration)
4095 (setq anything-iswitchb-frame-configuration nil)))
4098 (defun anything-iswitchb-check-input ()
4099 "Extract iswitchb input and check if it needs to be handled."
4100 (declare (special iswitchb-text))
4101 (if (or anything-iswitchb-frame-configuration
4102 (sit-for anything-iswitchb-idle-delay))
4103 (anything-check-new-input iswitchb-text)))
4106 (defun anything-iswitchb-handle-update ()
4107 "Pop up the anything buffer if it's not empty and it's not
4108 shown yet and bind anything commands in iswitchb."
4109 (unless (or (equal (buffer-size (get-buffer anything-buffer)) 0)
4110 anything-iswitchb-frame-configuration)
4111 (setq anything-iswitchb-frame-configuration (anything-current-frame/window-configuration))
4113 (save-selected-window
4114 (if (not anything-samewindow)
4115 (pop-to-buffer anything-buffer)
4117 (select-window (get-lru-window))
4118 (switch-to-buffer anything-buffer)))
4120 (with-current-buffer (window-buffer (active-minibuffer-window))
4121 (let* ((anything-prefix "anything-")
4122 (prefix-length (length anything-prefix))
4123 (commands
4124 (delete-dups
4125 (remove-if 'null
4126 (mapcar
4127 (lambda (binding)
4128 (let ((command (cdr binding)))
4129 (when (and (symbolp command)
4130 (eq (compare-strings
4131 anything-prefix
4132 0 prefix-length
4133 (symbol-name command)
4134 0 prefix-length)
4136 command)))
4137 (cdr anything-map)))))
4138 (bindings (mapcar (lambda (command)
4139 (cons command
4140 (where-is-internal command anything-map)))
4141 commands)))
4143 (push (list 'anything-iswitchb-cancel-anything (kbd "<ESC>"))
4144 bindings)
4146 (setq anything-iswitchb-saved-keys nil)
4148 (let* ((iswitchb-prefix "iswitchb-")
4149 (prefix-length (length iswitchb-prefix)))
4150 (dolist (binding bindings)
4151 (dolist (key (cdr binding))
4152 (let ((old-command (lookup-key (current-local-map) key)))
4153 (unless (and anything-iswitchb-dont-touch-iswithcb-keys
4154 (symbolp old-command)
4155 (eq (compare-strings iswitchb-prefix
4156 0 prefix-length
4157 (symbol-name old-command)
4158 0 prefix-length)
4160 (push (cons key old-command)
4161 anything-iswitchb-saved-keys)
4162 (define-key (current-local-map) key (car binding)))))))))))
4165 (defun anything-iswitchb-cancel-anything ()
4166 "Cancel anything completion and return to standard iswitchb."
4167 (interactive)
4168 (save-excursion
4169 (dolist (binding anything-iswitchb-saved-keys)
4170 (define-key (current-local-map) (car binding) (cdr binding)))
4171 (anything-iswitchb-minibuffer-exit)))
4173 ;; (@* "Compatibility")
4175 ;; Copied assoc-default from XEmacs version 21.5.12
4176 (unless (fboundp 'assoc-default)
4177 (defun assoc-default (key alist &optional test default)
4178 "Find object KEY in a pseudo-alist ALIST.
4179 ALIST is a list of conses or objects. Each element (or the element's car,
4180 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
4181 If that is non-nil, the element matches;
4182 then `assoc-default' returns the element's cdr, if it is a cons,
4183 or DEFAULT if the element is not a cons.
4185 If no element matches, the value is nil.
4186 If TEST is omitted or nil, `equal' is used."
4187 (let (found (tail alist) value)
4188 (while (and tail (not found))
4189 (let ((elt (car tail)))
4190 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
4191 (setq found t value (if (consp elt) (cdr elt) default))))
4192 (setq tail (cdr tail)))
4193 value)))
4195 ;; Function not available in XEmacs,
4196 (unless (fboundp 'minibuffer-contents)
4197 (defun minibuffer-contents ()
4198 "Return the user input in a minbuffer as a string.
4199 The current buffer must be a minibuffer."
4200 (field-string (point-max)))
4202 (defun delete-minibuffer-contents ()
4203 "Delete all user input in a minibuffer.
4204 The current buffer must be a minibuffer."
4205 (delete-field (point-max))))
4207 ;; Function not available in older Emacs (<= 22.1).
4208 (unless (fboundp 'buffer-chars-modified-tick)
4209 (defun buffer-chars-modified-tick (&optional buffer)
4210 "Return BUFFER's character-change tick counter.
4211 Each buffer has a character-change tick counter, which is set to the
4212 value of the buffer's tick counter (see `buffer-modified-tick'), each
4213 time text in that buffer is inserted or deleted. By comparing the
4214 values returned by two individual calls of `buffer-chars-modified-tick',
4215 you can tell whether a character change occurred in that buffer in
4216 between these calls. No argument or nil as argument means use current
4217 buffer as BUFFER."
4218 (with-current-buffer (or buffer (current-buffer))
4219 (if (listp buffer-undo-list)
4220 (length buffer-undo-list)
4221 (buffer-modified-tick)))))
4223 ;;(@* "Attribute Documentation")
4224 (defun anything-describe-anything-attribute (anything-attribute)
4225 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol)."
4226 (interactive (list (intern
4227 (completing-read
4228 "Describe anything attribute: "
4229 (mapcar 'symbol-name anything-additional-attributes)))))
4230 (with-output-to-temp-buffer "*Help*"
4231 (princ (get anything-attribute 'anything-attrdoc))))
4233 (anything-document-attribute 'name "mandatory"
4234 " The name of the source. It is also the heading which appears
4235 above the list of matches from the source. Must be unique. ")
4236 (anything-document-attribute 'header-name "optional"
4237 " A function returning the display string of the header. Its
4238 argument is the name of the source. This attribute is useful to
4239 add an additional information with the source name. ")
4240 (anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
4241 " Specifies how to retrieve candidates from the source. It can
4242 either be a variable name, a function called with no parameters
4243 or the actual list of candidates.
4245 The list must be a list whose members are strings, symbols
4246 or (DISPLAY . REAL) pairs.
4248 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
4249 in the Anything buffer, but the REAL one is used as action
4250 argument when the candidate is selected. This allows a more
4251 readable presentation for candidates which would otherwise be,
4252 for example, too long or have a common part shared with other
4253 candidates which can be safely replaced with an abbreviated
4254 string for display purposes.
4256 Note that if the (DISPLAY . REAL) form is used then pattern
4257 matching is done on the displayed string, not on the real
4258 value.
4260 If the candidates have to be retrieved asynchronously (for
4261 example, by an external command which takes a while to run)
4262 then the function should start the external command
4263 asynchronously and return the associated process object.
4264 Anything will take care of managing the process (receiving the
4265 output from it, killing it if necessary, etc.). The process
4266 should return candidates matching the current pattern (see
4267 variable `anything-pattern'.)
4269 Note that currently results from asynchronous sources appear
4270 last in the anything buffer regardless of their position in
4271 `anything-sources'. ")
4272 (anything-document-attribute 'action "mandatory if type attribute is not provided"
4273 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
4274 FUNCTION is called with one parameter: the selected candidate.
4276 An action other than the default can be chosen from this list
4277 of actions for the currently selected candidate (by default
4278 with TAB). The DISPLAY string is shown in the completions
4279 buffer and the FUNCTION is invoked when an action is
4280 selected. The first action of the list is the default. ")
4281 (anything-document-attribute 'type "optional if action attribute is provided"
4282 " Indicates the type of the items the source returns.
4284 Merge attributes not specified in the source itself from
4285 `anything-type-attributes'.
4287 This attribute is implemented by plug-in. ")
4288 (anything-document-attribute 'init "optional"
4289 " Function called with no parameters when anything is started. It
4290 is useful for collecting current state information which can be
4291 used to create the list of candidates later.
4293 For example, if a source needs to work with the current
4294 directory then it can store its value here, because later
4295 anything does its job in the minibuffer and in the
4296 `anything-buffer' and the current directory can be different
4297 there. ")
4298 (anything-document-attribute 'delayed-init "optional"
4299 " Function called with no parameters before candidate function is
4300 called. It is similar with `init' attribute, but its
4301 evaluation is deferred. It is useful to combine with ")
4302 (anything-document-attribute 'match "optional"
4303 " List of functions called with one parameter: a candidate. The
4304 function should return non-nil if the candidate matches the
4305 current pattern (see variable `anything-pattern').
4307 This attribute allows the source to override the default
4308 pattern matching based on `string-match'. It can be used, for
4309 example, to implement a source for file names and do the
4310 pattern matching on the basename of files, since it's more
4311 likely one is typing part of the basename when searching for a
4312 file, instead of some string anywhere else in its path.
4314 If the list contains more than one function then the list of
4315 matching candidates from the source is constructed by appending
4316 the results after invoking the first function on all the
4317 potential candidates, then the next function, and so on. The
4318 matching candidates supplied by the first function appear first
4319 in the list of results and then results from the other
4320 functions, respectively.
4322 This attribute has no effect for asynchronous sources (see
4323 attribute `candidates'), since they perform pattern matching
4324 themselves. ")
4325 (anything-document-attribute 'candidate-transformer "optional"
4326 " It's a function or a list of functions called with one argument
4327 when the completion list from the source is built. The argument
4328 is the list of candidates retrieved from the source. The
4329 function should return a transformed list of candidates which
4330 will be used for the actual completion. If it is a list of
4331 functions, it calls each function sequentially.
4333 This can be used to transform or remove items from the list of
4334 candidates.
4336 Note that `candidates' is run already, so the given transformer
4337 function should also be able to handle candidates with (DISPLAY
4338 . REAL) format. ")
4339 (anything-document-attribute 'filtered-candidate-transformer "optional"
4340 " It has the same format as `candidate-transformer', except the
4341 function is called with two parameters: the candidate list and
4342 the source.
4344 This transformer is run on the candidate list which is already
4345 filtered by the current pattern. While `candidate-transformer'
4346 is run only once, it is run every time the input pattern is
4347 changed.
4349 It can be used to transform the candidate list dynamically, for
4350 example, based on the current pattern.
4352 In some cases it may also be more efficent to perform candidate
4353 transformation here, instead of with `candidate-transformer'
4354 even if this transformation is done every time the pattern is
4355 changed. For example, if a candidate set is very large then
4356 `candidate-transformer' transforms every candidate while only
4357 some of them will actually be dislpayed due to the limit
4358 imposed by `anything-candidate-number-limit'.
4360 Note that `candidates' and `candidate-transformer' is run
4361 already, so the given transformer function should also be able
4362 to handle candidates with (DISPLAY . REAL) format.
4364 This option has no effect for asynchronous sources. (Not yet,
4365 at least. ")
4366 (anything-document-attribute 'action-transformer "optional"
4367 " It's a function or a list of functions called with two
4368 arguments when the action list from the source is
4369 assembled. The first argument is the list of actions, the
4370 second is the current selection. If it is a list of functions,
4371 it calls each function sequentially.
4373 The function should return a transformed action list.
4375 This can be used to customize the list of actions based on the
4376 currently selected candidate. ")
4377 (anything-document-attribute 'pattern-transformer "optional"
4378 " It's a function or a list of functions called with one argument
4379 before computing matches. Its argument is `anything-pattern'.
4380 Functions should return transformed `anything-pattern'.
4382 It is useful to change interpretation of `anything-pattern'. ")
4383 (anything-document-attribute 'delayed "optional"
4384 " Candidates from the source are shown only if the user stops
4385 typing and is idle for `anything-idle-delay' seconds. ")
4386 (anything-document-attribute 'volatile "optional"
4387 " Indicates the source assembles the candidate list dynamically,
4388 so it shouldn't be cached within a single Anything
4389 invocation. It is only applicable to synchronous sources,
4390 because asynchronous sources are not cached. ")
4391 (anything-document-attribute 'requires-pattern "optional"
4392 " If present matches from the source are shown only if the
4393 pattern is not empty. Optionally, it can have an integer
4394 parameter specifying the required length of input which is
4395 useful in case of sources with lots of candidates. ")
4396 (anything-document-attribute 'persistent-action "optional"
4397 " Function called with one parameter; the selected candidate.
4399 An action performed by `anything-execute-persistent-action'.
4400 If none, use the default action. ")
4401 (anything-document-attribute 'candidates-in-buffer "optional"
4402 " Shortcut attribute for making and narrowing candidates using
4403 buffers. This newly-introduced attribute prevents us from
4404 forgetting to add volatile and match attributes.
4406 See docstring of `anything-candidates-in-buffer'.
4408 (candidates-in-buffer) is equivalent of three attributes:
4409 (candidates . anything-candidates-in-buffer)
4410 (volatile)
4411 (match identity)
4413 (candidates-in-buffer . candidates-function) is equivalent of:
4414 (candidates . candidates-function)
4415 (volatile)
4416 (match identity)
4418 This attribute is implemented by plug-in. ")
4419 (anything-document-attribute 'search "optional"
4420 " List of functions like `re-search-forward' or `search-forward'.
4421 Buffer search function used by `anything-candidates-in-buffer'.
4422 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4423 This attribute is meant to be used with
4424 (candidates . anything-candidates-in-buffer) or
4425 (candidates-in-buffer) in short. ")
4426 (anything-document-attribute 'search-from-end "optional"
4427 " Make `anything-candidates-in-buffer' search from the end of buffer.
4428 If this attribute is specified, `anything-candidates-in-buffer' uses
4429 `re-search-backward' instead. ")
4430 (anything-document-attribute 'get-line "optional"
4431 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4432 This function converts point of line-beginning and point of line-end,
4433 which represents a candidate computed by `anything-candidates-in-buffer'.
4434 By default, `anything-candidates-in-buffer' uses
4435 `buffer-substring-no-properties'. ")
4436 (anything-document-attribute 'display-to-real "optional"
4437 " Function called with one parameter; the selected candidate.
4439 The function transforms the selected candidate, and the result
4440 is passed to the action function. The display-to-real
4441 attribute provides another way to pass other string than one
4442 shown in Anything buffer.
4444 Traditionally, it is possible to make candidates,
4445 candidate-transformer or filtered-candidate-transformer
4446 function return a list with (DISPLAY . REAL) pairs. But if REAL
4447 can be generated from DISPLAY, display-to-real is more
4448 convenient and faster. ")
4449 (anything-document-attribute 'real-to-display "optional"
4450 " Function called with one parameter; the selected candidate.
4452 The inverse of display-to-real attribute.
4454 The function transforms the selected candidate, which is passed
4455 to the action function, for display. The real-to-display
4456 attribute provides the other way to pass other string than one
4457 shown in Anything buffer.
4459 Traditionally, it is possible to make candidates,
4460 candidate-transformer or filtered-candidate-transformer
4461 function return a list with (DISPLAY . REAL) pairs. But if
4462 DISPLAY can be generated from REAL, real-to-display is more
4463 convenient.
4465 Note that DISPLAY parts returned from candidates /
4466 candidate-transformer are IGNORED as the name `display-to-real'
4467 says. ")
4468 (anything-document-attribute 'cleanup "optional"
4469 " Function called with no parameters when *anything* buffer is closed. It
4470 is useful for killing unneeded candidates buffer.
4472 Note that the function is executed BEFORE performing action. ")
4473 (anything-document-attribute 'candidate-number-limit "optional"
4474 " Override `anything-candidate-number-limit' only for this source. ")
4475 (anything-document-attribute 'accept-empty "optional"
4476 " Pass empty string \"\" to action function. ")
4477 (anything-document-attribute 'disable-shortcuts "optional"
4478 " Disable `anything-enable-shortcuts' in current `anything' session.
4480 This attribute is implemented by plug-in. ")
4481 (anything-document-attribute 'dummy "optional"
4482 " Set `anything-pattern' to candidate. If this attribute is
4483 specified, The candidates attribute is ignored.
4485 This attribute is implemented by plug-in.
4486 This plug-in implies disable-shortcuts plug-in. ")
4487 (anything-document-attribute 'multiline "optional"
4488 " Enable to selection multiline candidates. ")
4489 (anything-document-attribute 'update "optional"
4490 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4491 (anything-document-attribute 'mode-line "optional"
4492 " source local `anything-mode-line-string'. (included in `mode-line-format')
4493 It accepts also variable/function name. ")
4494 (anything-document-attribute 'header-line "optional"
4495 " source local `header-line-format'.
4496 It accepts also variable/function name. ")
4497 (anything-document-attribute 'resume "optional" " Function called with no parameters when `anything-resume' is started.")
4499 ;; (@* "Unit Tests")
4501 (defun* anything-test-candidates (sources &optional (input "") (compile-source-functions anything-compile-source-functions-default))
4502 "Test helper function for anything.
4503 Given pseudo `anything-sources' and `anything-pattern', returns list like
4504 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4505 (\"source name2\" (\"candidate3\" \"candidate4\")))
4507 (let ((anything-test-mode t)
4508 anything-enable-shortcuts
4509 anything-candidate-cache
4510 (anything-sources (anything-normalize-sources sources))
4511 (anything-compile-source-functions compile-source-functions)
4512 anything-before-initialize-hook
4513 anything-after-initialize-hook
4514 anything-update-hook
4515 anything-test-candidate-list)
4516 (get-buffer-create anything-buffer)
4518 (anything-initialize)
4519 (setq anything-input input anything-pattern input)
4520 (anything-update)
4521 ;; test-mode spec: select 1st candidate!
4522 (with-current-buffer anything-buffer
4523 (forward-line 1)
4524 (anything-mark-current-line))
4525 (prog1
4526 anything-test-candidate-list
4527 (anything-cleanup))))
4529 (defmacro anything-test-update (sources pattern)
4530 "Test helper macro for anything. It is meant for testing *anything* buffer contents."
4531 `(progn (stub anything-get-sources => ,sources)
4532 (stub run-hooks => nil)
4533 (stub anything-maybe-fit-frame => nil)
4534 (stub run-with-idle-timer => nil)
4535 (let (anything-test-mode (anything-pattern ,pattern))
4536 (anything-update))))
4538 ;;;; unit test
4539 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4540 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
4541 (dont-compile
4542 (when (fboundp 'expectations)
4543 (expectations
4544 (desc "anything-current-buffer")
4545 (expect "__a_buffer"
4546 (with-current-buffer (get-buffer-create "__a_buffer")
4547 (anything-test-candidates '(((name . "FOO"))) "")
4548 (prog1
4549 (buffer-name anything-current-buffer)
4550 (kill-buffer "__a_buffer")
4552 (desc "anything-buffer-file-name")
4553 (expect (regexp "/__a_file__")
4554 (with-current-buffer (get-buffer-create "__a_file__")
4555 (setq buffer-file-name "/__a_file__")
4556 (anything-test-candidates '(((name . "FOO"))) "")
4557 (prog1
4558 anything-buffer-file-name
4559 ;;(kill-buffer "__a_file__")
4561 (desc "anything-interpret-value")
4562 (expect "literal"
4563 (anything-interpret-value "literal"))
4564 (expect "lambda"
4565 (anything-interpret-value (lambda () "lambda")))
4566 (expect "lambda with source name"
4567 (let ((source '((name . "lambda with source name"))))
4568 (anything-interpret-value (lambda () anything-source-name) source)))
4569 (expect "function symbol"
4570 (flet ((f () "function symbol"))
4571 (anything-interpret-value 'f)))
4572 (expect "variable symbol"
4573 (let ((v "variable symbol"))
4574 (anything-interpret-value 'v)))
4575 (expect (error error *)
4576 (anything-interpret-value 'unbounded-1))
4577 (desc "anything-compile-sources")
4578 (expect '(((name . "foo")))
4579 (anything-compile-sources '(((name . "foo"))) nil)
4581 (expect '(((name . "foo") (type . test) (action . identity)))
4582 (let ((anything-type-attributes '((test (action . identity)))))
4583 (anything-compile-sources '(((name . "foo") (type . test)))
4584 '(anything-compile-source--type))))
4585 (desc "anything-sources accepts symbols")
4586 (expect '(((name . "foo")))
4587 (let* ((foo '((name . "foo"))))
4588 (anything-compile-sources '(foo) nil)))
4589 (desc "anything-get-sources action")
4590 (expect '(((name . "Actions") (candidates . actions)))
4591 (stub anything-action-window => t)
4592 (let (anything-compiled-sources
4593 (anything-sources '(((name . "Actions") (candidates . actions)))))
4594 (anything-get-sources)))
4595 (desc "get-buffer-create candidates-buffer")
4596 (expect '(((name . "many") (init . many-init)
4597 (candidates-in-buffer . anything-candidates-in-buffer)
4598 (candidates . anything-candidates-in-buffer)
4599 (volatile) (match identity)))
4600 (anything-compile-sources
4601 '(((name . "many") (init . many-init)
4602 (candidates-in-buffer . anything-candidates-in-buffer)))
4603 '(anything-compile-source--candidates-in-buffer)))
4604 (expect '(((name . "many") (init . many-init)
4605 (candidates-in-buffer)
4606 (candidates . anything-candidates-in-buffer)
4607 (volatile) (match identity)))
4608 (anything-compile-sources
4609 '(((name . "many") (init . many-init)
4610 (candidates-in-buffer)))
4611 '(anything-compile-source--candidates-in-buffer)))
4612 (expect '(((name . "many") (init . many-init)
4613 (candidates-in-buffer)
4614 (type . test)
4615 (action . identity)
4616 (candidates . anything-candidates-in-buffer)
4617 (volatile) (match identity)))
4618 (let ((anything-type-attributes '((test (action . identity)))))
4619 (anything-compile-sources
4620 '(((name . "many") (init . many-init)
4621 (candidates-in-buffer)
4622 (type . test)))
4623 '(anything-compile-source--type
4624 anything-compile-source--candidates-in-buffer))))
4626 (desc "anything-get-candidates")
4627 (expect '("foo" "bar")
4628 (anything-get-candidates '((name . "foo") (candidates "foo" "bar"))))
4629 (expect '("FOO" "BAR")
4630 (anything-get-candidates '((name . "foo") (candidates "foo" "bar")
4631 (candidate-transformer
4632 . (lambda (cands) (mapcar 'upcase cands))))))
4633 (expect '("foo" "bar")
4634 (anything-get-candidates '((name . "foo")
4635 (candidates . (lambda () '("foo" "bar"))))))
4636 (expect '("foo" "bar")
4637 (let ((var '("foo" "bar")))
4638 (anything-get-candidates '((name . "foo")
4639 (candidates . var)))))
4640 (expect (error error *)
4641 (anything-get-candidates '((name . "foo")
4642 (candidates . "err"))))
4643 (expect (error error *)
4644 (let ((var "err"))
4645 (anything-get-candidates '((name . "foo")
4646 (candidates . var)))))
4647 (desc "anything-compute-matches")
4648 (expect '("foo" "bar")
4649 (let ((anything-pattern ""))
4650 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4651 (expect '("foo")
4652 (let ((anything-pattern "oo"))
4653 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4654 (expect '("bar")
4655 (let ((anything-pattern "^b"))
4656 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4657 (expect '("a" "b")
4658 (let ((anything-pattern "")
4659 (anything-candidate-number-limit 2))
4660 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4661 (expect '("a" "b")
4662 (let ((anything-pattern ".")
4663 (anything-candidate-number-limit 2))
4664 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4665 (expect '("a" "b" "c")
4666 (let ((anything-pattern "")
4667 anything-candidate-number-limit)
4668 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4669 (expect '("a" "b" "c")
4670 (let ((anything-pattern "[abc]")
4671 anything-candidate-number-limit)
4672 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4673 ;; using anything-test-candidate-list
4674 (desc "anything-test-candidates")
4675 (expect '(("FOO" ("foo" "bar")))
4676 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")))))
4677 (expect '(("FOO" ("bar")))
4678 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar"))) "ar"))
4679 (expect '(("T1" ("hoge" "aiue"))
4680 ("T2" ("test" "boke")))
4681 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4682 ((name . "T2") (candidates "test" "boke")))))
4683 (expect '(("T1" ("hoge"))
4684 ("T2" ("boke")))
4685 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4686 ((name . "T2") (candidates "test" "boke"))) "o"))
4687 (desc "requires-pattern attribute")
4688 (expect nil
4689 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4690 (requires-pattern . 1)))))
4691 (expect '(("FOO" ("bar")))
4692 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4693 (requires-pattern . 1))) "b"))
4694 (desc "delayed attribute(for test)")
4695 (expect '(("T2" ("boke"))
4696 ("T1" ("hoge")))
4697 (anything-test-candidates
4698 '(((name . "T1") (candidates "hoge" "aiue") (delayed))
4699 ((name . "T2") (candidates "test" "boke")))
4700 "o"))
4701 (desc "match attribute(prefix search)")
4702 (expect '(("FOO" ("bar")))
4703 (anything-test-candidates
4704 '(((name . "FOO") (candidates "foo" "bar")
4705 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4706 "ba"))
4707 (expect nil
4708 (anything-test-candidates
4709 '(((name . "FOO") (candidates "foo" "bar")
4710 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4711 "ar"))
4712 (expect "TestSource"
4713 (let (x)
4714 (anything-test-candidates
4715 '(((name . "TestSource") (candidates "a")
4716 (match (lambda (c) (setq x anything-source-name)))))
4717 "a")
4719 (desc "init attribute")
4720 (expect '(("FOO" ("bar")))
4721 (let (v)
4722 (anything-test-candidates
4723 '(((name . "FOO") (init . (lambda () (setq v '("foo" "bar"))))
4724 (candidates . v)))
4725 "ar")))
4726 (desc "candidate-transformer attribute")
4727 (expect '(("FOO" ("BAR")))
4728 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4729 (candidate-transformer
4730 . (lambda (cands) (mapcar 'upcase cands)))))
4731 "ar"))
4732 (desc "filtered-candidate-transformer attribute")
4733 ;; needs more tests
4734 (expect '(("FOO" ("BAR")))
4735 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4736 (filtered-candidate-transformer
4737 . (lambda (cands src) (mapcar 'upcase cands)))))
4738 "ar"))
4739 (desc "anything-candidates-in-buffer-1")
4740 (expect nil
4741 (anything-candidates-in-buffer-1 nil))
4742 (expect '("foo+" "bar+" "baz+")
4743 (with-temp-buffer
4744 (insert "foo+\nbar+\nbaz+\n")
4745 (let ((anything-candidate-number-limit 5))
4746 (anything-candidates-in-buffer-1 (current-buffer) ""))))
4747 (expect '("foo+" "bar+")
4748 (with-temp-buffer
4749 (insert "foo+\nbar+\nbaz+\n")
4750 (let ((anything-candidate-number-limit 2))
4751 (anything-candidates-in-buffer-1 (current-buffer) ""))))
4752 (expect '("foo+")
4753 (with-temp-buffer
4754 (insert "foo+\nbar+\nbaz+\n")
4755 (anything-candidates-in-buffer-1 (current-buffer) "oo\\+")))
4756 (expect '("foo+")
4757 (with-temp-buffer
4758 (insert "foo+\nbar+\nbaz+\n")
4759 (anything-candidates-in-buffer-1
4760 (current-buffer) "oo+"
4761 #'buffer-substring-no-properties '(search-forward))))
4762 (expect '(("foo+" "FOO+"))
4763 (with-temp-buffer
4764 (insert "foo+\nbar+\nbaz+\n")
4765 (anything-candidates-in-buffer-1
4766 (current-buffer) "oo\\+"
4767 (lambda (s e)
4768 (let ((l (buffer-substring-no-properties s e)))
4769 (list l (upcase l)))))))
4770 (desc "anything-candidates-in-buffer")
4771 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4772 (anything-test-candidates
4773 '(((name . "TEST")
4774 (init
4775 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4776 (insert "foo+\nbar+\nbaz+\n"))))
4777 (candidates . anything-candidates-in-buffer)
4778 (match identity)
4779 (volatile)))))
4780 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4781 (let (anything-candidate-number-limit)
4782 (anything-test-candidates
4783 '(((name . "TEST")
4784 (init
4785 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4786 (insert "foo+\nbar+\nbaz+\n"))))
4787 (candidates . anything-candidates-in-buffer)
4788 (match identity)
4789 (volatile))))))
4790 (expect '(("TEST" ("foo+")))
4791 (anything-test-candidates
4792 '(((name . "TEST")
4793 (init
4794 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4795 (insert "foo+\nbar+\nbaz+\n"))))
4796 (candidates . anything-candidates-in-buffer)
4797 (match identity)
4798 (volatile)))
4799 "oo\\+"))
4800 (desc "search attribute")
4801 (expect '(("TEST" ("foo+")))
4802 (anything-test-candidates
4803 '(((name . "TEST")
4804 (init
4805 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4806 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4807 (search search-forward)
4808 (candidates . anything-candidates-in-buffer)
4809 (match identity)
4810 (volatile)))
4811 "oo+"))
4812 (expect '(("TEST" ("foo+" "ooo")))
4813 (anything-test-candidates
4814 '(((name . "TEST")
4815 (init
4816 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4817 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4818 (search search-forward re-search-forward)
4819 (candidates . anything-candidates-in-buffer)
4820 (match identity)
4821 (volatile)))
4822 "oo+"))
4823 (expect '(("TEST" ("foo+" "ooo")))
4824 (anything-test-candidates
4825 '(((name . "TEST")
4826 (init
4827 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4828 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4829 (search re-search-forward search-forward)
4830 (candidates . anything-candidates-in-buffer)
4831 (match identity)
4832 (volatile)))
4833 "oo+"))
4834 (expect '(("TEST" ("ooo" "foo+")))
4835 (anything-test-candidates
4836 '(((name . "TEST")
4837 (init
4838 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4839 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4840 (search re-search-forward search-forward)
4841 (candidates . anything-candidates-in-buffer)
4842 (match identity)
4843 (volatile)))
4844 "oo+"))
4845 ;; faster exact match
4846 (expect '(("TEST" ("bar+")))
4847 (anything-test-candidates
4848 '(((name . "TEST")
4849 (init
4850 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4851 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4852 (search (lambda (pattern &rest _)
4853 (and (search-forward (concat "\n" pattern "\n") nil t)
4854 (forward-line -1))))
4855 (candidates . anything-candidates-in-buffer)
4856 (match identity)
4857 (volatile)))
4858 "bar+"))
4859 ;; faster prefix match
4860 (expect '(("TEST" ("bar+")))
4861 (anything-test-candidates
4862 '(((name . "TEST")
4863 (init
4864 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4865 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4866 (search (lambda (pattern &rest _)
4867 (search-forward (concat "\n" pattern) nil t)))
4868 (candidates . anything-candidates-in-buffer)
4869 (match identity)
4870 (volatile)))
4871 "ba"))
4872 (desc "anything-current-buffer-is-modified")
4873 (expect '(("FOO" ("modified")))
4874 (let ((sources '(((name . "FOO")
4875 (candidates
4876 . (lambda ()
4877 (if (anything-current-buffer-is-modified)
4878 '("modified")
4879 '("unmodified"))))))))
4880 (with-temp-buffer
4881 (clrhash anything-tick-hash)
4882 (insert "1")
4883 (anything-test-candidates sources))))
4884 (expect '(("FOO" ("unmodified")))
4885 (let ((sources '(((name . "FOO")
4886 (candidates
4887 . (lambda ()
4888 (if (anything-current-buffer-is-modified)
4889 '("modified")
4890 '("unmodified"))))))))
4891 (with-temp-buffer
4892 (clrhash anything-tick-hash)
4893 (insert "1")
4894 (anything-test-candidates sources)
4895 (anything-test-candidates sources))))
4896 (expect '(("FOO" ("modified")))
4897 (let ((sources '(((name . "FOO")
4898 (candidates
4899 . (lambda ()
4900 (if (anything-current-buffer-is-modified)
4901 '("modified")
4902 '("unmodified"))))))))
4903 (with-temp-buffer
4904 (clrhash anything-tick-hash)
4905 (insert "1")
4906 (anything-test-candidates sources)
4907 (insert "2")
4908 (anything-test-candidates sources))))
4909 (expect '(("BAR" ("modified")))
4910 (let ((sources1 '(((name . "FOO")
4911 (candidates
4912 . (lambda ()
4913 (if (anything-current-buffer-is-modified)
4914 '("modified")
4915 '("unmodified")))))))
4916 (sources2 '(((name . "BAR")
4917 (candidates
4918 . (lambda ()
4919 (if (anything-current-buffer-is-modified)
4920 '("modified")
4921 '("unmodified"))))))))
4922 (with-temp-buffer
4923 (clrhash anything-tick-hash)
4924 (insert "1")
4925 (anything-test-candidates sources1)
4926 (anything-test-candidates sources2))))
4927 (expect '(("FOO" ("unmodified")))
4928 (let ((sources1 '(((name . "FOO")
4929 (candidates
4930 . (lambda ()
4931 (if (anything-current-buffer-is-modified)
4932 '("modified")
4933 '("unmodified")))))))
4934 (sources2 '(((name . "BAR")
4935 (candidates
4936 . (lambda ()
4937 (if (anything-current-buffer-is-modified)
4938 '("modified")
4939 '("unmodified"))))))))
4940 (with-temp-buffer
4941 (clrhash anything-tick-hash)
4942 (insert "1")
4943 (anything-test-candidates sources1)
4944 (anything-test-candidates sources2)
4945 (anything-test-candidates sources1))))
4946 (expect '(("BAR" ("unmodified")))
4947 (let ((sources1 '(((name . "FOO")
4948 (candidates
4949 . (lambda ()
4950 (if (anything-current-buffer-is-modified)
4951 '("modified")
4952 '("unmodified")))))))
4953 (sources2 '(((name . "BAR")
4954 (candidates
4955 . (lambda ()
4956 (if (anything-current-buffer-is-modified)
4957 '("modified")
4958 '("unmodified"))))))))
4959 (with-temp-buffer
4960 (clrhash anything-tick-hash)
4961 (insert "1")
4962 (anything-test-candidates sources1)
4963 (anything-test-candidates sources2)
4964 (anything-test-candidates sources2))))
4965 (expect '(("BAR" ("modified")))
4966 (let ((sources1 '(((name . "FOO")
4967 (candidates
4968 . (lambda ()
4969 (if (anything-current-buffer-is-modified)
4970 '("modified")
4971 '("unmodified")))))))
4972 (sources2 '(((name . "BAR")
4973 (candidates
4974 . (lambda ()
4975 (if (anything-current-buffer-is-modified)
4976 '("modified")
4977 '("unmodified"))))))))
4978 (with-temp-buffer
4979 (clrhash anything-tick-hash)
4980 (insert "1")
4981 (anything-test-candidates sources1)
4982 (anything-test-candidates sources2)
4983 (with-temp-buffer
4984 (anything-test-candidates sources2)))))
4985 (desc "anything-source-name")
4986 (expect "FOO"
4987 (let (v)
4988 (anything-test-candidates '(((name . "FOO")
4989 (init
4990 . (lambda () (setq v anything-source-name)))
4991 (candidates "ok"))))
4993 (expect "FOO"
4994 (let (v)
4995 (anything-test-candidates '(((name . "FOO")
4996 (candidates
4997 . (lambda ()
4998 (setq v anything-source-name)
4999 '("ok"))))))
5001 (expect "FOO"
5002 (let (v)
5003 (anything-test-candidates '(((name . "FOO")
5004 (candidates "ok")
5005 (candidate-transformer
5006 . (lambda (c)
5007 (setq v anything-source-name)
5008 c)))))
5010 (expect "FOO"
5011 (let (v)
5012 (anything-test-candidates '(((name . "FOO")
5013 (candidates "ok")
5014 (filtered-candidate-transformer
5015 . (lambda (c s)
5016 (setq v anything-source-name)
5017 c)))))
5019 (expect "FOO"
5020 (let (v)
5021 (anything-test-candidates '(((name . "FOO")
5022 (candidates "ok")
5023 (display-to-real
5024 . (lambda (c)
5025 (setq v anything-source-name)
5027 (action . identity))))
5028 (anything-execute-selection-action)
5030 (desc "anything-candidate-buffer create")
5031 (expect " *anything candidates:FOO*"
5032 (let* (anything-candidate-buffer-alist
5033 (anything-source-name "FOO")
5034 (buf (anything-candidate-buffer 'global)))
5035 (prog1 (buffer-name buf)
5036 (kill-buffer buf))))
5037 (expect " *anything candidates:FOO*aTestBuffer"
5038 (let* (anything-candidate-buffer-alist
5039 (anything-source-name "FOO")
5040 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5041 (buf (anything-candidate-buffer 'local)))
5042 (prog1 (buffer-name buf)
5043 (kill-buffer anything-current-buffer)
5044 (kill-buffer buf))))
5045 (expect 0
5046 (let (anything-candidate-buffer-alist
5047 (anything-source-name "FOO") buf)
5048 (with-current-buffer (anything-candidate-buffer 'global)
5049 (insert "1"))
5050 (setq buf (anything-candidate-buffer 'global))
5051 (prog1 (buffer-size buf)
5052 (kill-buffer buf))))
5053 (desc "anything-candidate-buffer get-buffer")
5054 (expect " *anything candidates:FOO*"
5055 (let* (anything-candidate-buffer-alist
5056 (anything-source-name "FOO")
5057 (buf (anything-candidate-buffer 'global)))
5058 (prog1 (buffer-name (anything-candidate-buffer))
5059 (kill-buffer buf))))
5060 (expect " *anything candidates:FOO*aTestBuffer"
5061 (let* (anything-candidate-buffer-alist
5062 (anything-source-name "FOO")
5063 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5064 (buf (anything-candidate-buffer 'local)))
5065 (prog1 (buffer-name (anything-candidate-buffer))
5066 (kill-buffer anything-current-buffer)
5067 (kill-buffer buf))))
5068 (expect " *anything candidates:FOO*"
5069 (let* (anything-candidate-buffer-alist
5070 (anything-source-name "FOO")
5071 (buf-local (anything-candidate-buffer 'local))
5072 (buf-global (anything-candidate-buffer 'global)))
5073 (prog1 (buffer-name (anything-candidate-buffer))
5074 (kill-buffer buf-local)
5075 (kill-buffer buf-global))))
5076 (expect " *anything candidates:FOO*aTestBuffer"
5077 (let* (anything-candidate-buffer-alist
5078 (anything-source-name "FOO")
5079 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5080 (buf-global (anything-candidate-buffer 'global))
5081 (buf-local (anything-candidate-buffer 'local)))
5082 (prog1 (buffer-name (anything-candidate-buffer))
5083 (kill-buffer buf-local)
5084 (kill-buffer buf-global))))
5085 (expect nil
5086 (let* (anything-candidate-buffer-alist
5087 (anything-source-name "NOP__"))
5088 (anything-candidate-buffer)))
5089 (desc "anything-candidate-buffer register-buffer")
5090 (expect " *anything test candidates*"
5091 (let (anything-candidate-buffer-alist
5092 (buf (get-buffer-create " *anything test candidates*")))
5093 (with-current-buffer buf
5094 (insert "1\n2\n")
5095 (prog1 (buffer-name (anything-candidate-buffer buf))
5096 (kill-buffer (current-buffer))))))
5097 (expect " *anything test candidates*"
5098 (let (anything-candidate-buffer-alist
5099 (buf (get-buffer-create " *anything test candidates*")))
5100 (with-current-buffer buf
5101 (insert "1\n2\n")
5102 (anything-candidate-buffer buf)
5103 (prog1 (buffer-name (anything-candidate-buffer))
5104 (kill-buffer (current-buffer))))))
5105 (expect "1\n2\n"
5106 (let (anything-candidate-buffer-alist
5107 (buf (get-buffer-create " *anything test candidates*")))
5108 (with-current-buffer buf
5109 (insert "1\n2\n")
5110 (anything-candidate-buffer buf)
5111 (prog1 (buffer-string)
5112 (kill-buffer (current-buffer))))))
5113 (expect "buf1"
5114 (let (anything-candidate-buffer-alist
5115 (anything-source-name "foo")
5116 (buf1 (get-buffer-create "buf1"))
5117 (buf2 (get-buffer-create "buf2")))
5118 (anything-candidate-buffer buf1)
5119 (anything-candidate-buffer buf2)
5120 (prog1 (buffer-name (anything-candidate-buffer buf1))
5121 (kill-buffer buf1)
5122 (kill-buffer buf2))))
5123 (desc "action attribute")
5124 (expect "foo"
5125 (anything-test-candidates
5126 '(((name . "TEST")
5127 (candidates "foo")
5128 (action ("identity" . identity)))))
5129 (anything-execute-selection-action))
5130 (expect "foo"
5131 (anything-test-candidates
5132 '(((name . "TEST")
5133 (candidates "foo")
5134 (action ("identity" . (lambda (c) (identity c)))))))
5135 (anything-execute-selection-action))
5136 (desc "anything-execute-selection-action")
5137 (expect "FOO"
5138 (anything-execute-selection-action
5139 "foo" '(("upcase" . upcase)) nil #'identity))
5140 (expect "FOO"
5141 (anything-execute-selection-action
5142 "foo" '(("upcase" . (lambda (c) (upcase c)))) nil #'identity))
5143 (desc "display-to-real attribute")
5144 (expect "FOO"
5145 (anything-execute-selection-action
5146 "foo"
5147 '(("identity" . identity))
5149 #'upcase
5151 (expect "FOO"
5152 (anything-test-candidates
5153 '(((name . "TEST")
5154 (candidates "foo")
5155 (display-to-real . upcase)
5156 (action ("identity" . identity)))))
5157 (anything-execute-selection-action))
5158 (desc "cleanup test")
5159 (expect 'cleaned
5160 (let (v)
5161 (anything-test-candidates
5162 '(((name . "TEST")
5163 (cleanup . (lambda () (setq v 'cleaned))))))
5165 (desc "anything-get-current-source")
5166 ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
5167 ;; display-to-real/cleanup function
5168 (expect "FOO"
5169 (assoc-default
5170 'name
5171 (anything-funcall-with-source '((name . "FOO")) 'anything-get-current-source)))
5172 ;; init
5173 (expect "FOO"
5174 (let (v)
5175 (anything-test-candidates
5176 '(((name . "FOO")
5177 (init . (lambda () (setq v (anything-get-current-source)))))))
5178 (assoc-default 'name v)))
5179 ;; candidates
5180 (expect "FOO"
5181 (let (v)
5182 (anything-test-candidates
5183 '(((name . "FOO")
5184 (candidates . (lambda () (setq v (anything-get-current-source)) '("a"))))))
5185 (assoc-default 'name v)))
5186 ;; action
5187 (expect "FOO"
5188 (let (v)
5189 (anything-test-candidates
5190 '(((name . "FOO")
5191 (candidates "a")
5192 (action
5193 . (lambda (c) (setq v (anything-get-current-source)) c)))))
5194 (anything-execute-selection-action)
5195 (assoc-default 'name v)))
5196 ;; candidate-transformer
5197 (expect "FOO"
5198 (let (v)
5199 (anything-test-candidates
5200 '(((name . "FOO")
5201 (candidates "a")
5202 (candidate-transformer
5203 . (lambda (c) (setq v (anything-get-current-source)) c)))))
5204 (assoc-default 'name v)))
5205 ;; filtered-candidate-transformer
5206 (expect "FOO"
5207 (let (v)
5208 (anything-test-candidates
5209 '(((name . "FOO")
5210 (candidates "a")
5211 (filtered-candidate-transformer
5212 . (lambda (c s) (setq v (anything-get-current-source)) c)))))
5213 (assoc-default 'name v)))
5214 ;; action-transformer
5215 (expect "FOO"
5216 (let (v)
5217 (anything-test-candidates
5218 '(((name . "FOO")
5219 (candidates "a")
5220 (action-transformer
5221 . (lambda (a c) (setq v (anything-get-current-source)) a))
5222 (action . identity))))
5223 (anything-execute-selection-action)
5224 (assoc-default 'name v)))
5225 ;; display-to-real
5226 (expect "FOO"
5227 (let (v)
5228 (anything-test-candidates
5229 '(((name . "FOO")
5230 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5231 (insert "a\n"))))
5232 (candidates-in-buffer)
5233 (display-to-real
5234 . (lambda (c) (setq v (anything-get-current-source)) c))
5235 (action . identity))))
5236 (anything-execute-selection-action)
5237 (assoc-default 'name v)))
5238 ;; cleanup
5239 (expect "FOO"
5240 (let (v)
5241 (anything-test-candidates
5242 '(((name . "FOO")
5243 (candidates "a")
5244 (cleanup
5245 . (lambda () (setq v (anything-get-current-source)))))))
5246 (assoc-default 'name v)))
5247 ;; candidates are displayed
5248 (expect "TEST"
5249 (anything-test-candidates
5250 '(((name . "TEST")
5251 (candidates "foo")
5252 (action ("identity" . identity)))))
5253 (assoc-default 'name (anything-get-current-source)))
5254 (desc "anything-attr")
5255 (expect "FOO"
5256 (anything-funcall-with-source
5257 '((name . "FOO"))
5258 (lambda ()
5259 (anything-attr 'name))))
5260 (expect 'fuga
5261 (let (v)
5262 (anything-test-candidates
5263 '(((name . "FOO")
5264 (hoge . fuga)
5265 (init . (lambda () (setq v (anything-attr 'hoge))))
5266 (candidates "a"))))
5268 (expect nil
5269 (let (v)
5270 (anything-test-candidates
5271 '(((name . "FOO")
5272 (init . (lambda () (setq v (anything-attr 'hoge))))
5273 (candidates "a"))))
5275 (expect nil
5276 (let (v)
5277 (anything-test-candidates
5278 '(((name . "FOO")
5279 (hoge) ;INCOMPATIBLE!
5280 (init . (lambda () (setq v (anything-attr 'hoge))))
5281 (candidates "a"))))
5283 (desc "anything-attr-defined")
5284 (expect (non-nil)
5285 (let (v)
5286 (anything-test-candidates
5287 '(((name . "FOO")
5288 (hoge)
5289 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5290 (candidates "a"))))
5291 v))
5292 (expect nil
5293 (let (v)
5294 (anything-test-candidates
5295 '(((name . "FOO")
5296 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5297 (candidates "a"))))
5298 v))
5299 (desc "anything-attrset")
5300 (expect '((name . "FOO") (hoge . 77))
5301 (let ((src '((name . "FOO") (hoge))))
5302 (anything-attrset 'hoge 77 src)
5303 src))
5304 (expect 77
5305 (anything-attrset 'hoge 77 '((name . "FOO") (hoge))))
5307 (expect '((name . "FOO") (hoge . 77))
5308 (let ((src '((name . "FOO") (hoge . 1))))
5309 (anything-attrset 'hoge 77 src)
5310 src))
5312 (expect '((name . "FOO") (hoge . 77) (x))
5313 (let ((src '((name . "FOO") (x))))
5314 (anything-attrset 'hoge 77 src)
5315 src))
5316 (expect 77
5317 (anything-attrset 'hoge 77 '((name . "FOO"))))
5318 (desc "anything-preselect")
5319 ;; entire candidate
5320 (expect "foo"
5321 (with-current-buffer (anything-create-anything-buffer t)
5322 (let ((anything-pattern "")
5323 (anything-test-mode t))
5324 (anything-process-source '((name . "test")
5325 (candidates "hoge" "foo" "bar")))
5326 (anything-preselect "foo")
5327 (anything-get-selection))))
5328 ;; regexp
5329 (expect "foo"
5330 (with-current-buffer (anything-create-anything-buffer t)
5331 (let ((anything-pattern "")
5332 (anything-test-mode t))
5333 (anything-process-source '((name . "test")
5334 (candidates "hoge" "foo" "bar")))
5335 (anything-preselect "fo+")
5336 (anything-get-selection))))
5337 ;; no match -> first entry
5338 (expect "hoge"
5339 (with-current-buffer (anything-create-anything-buffer t)
5340 (let ((anything-pattern "")
5341 (anything-test-mode t))
5342 (anything-process-source '((name . "test")
5343 (candidates "hoge" "foo" "bar")))
5344 (anything-preselect "not found")
5345 (anything-get-selection))))
5346 (desc "anything-check-new-input")
5347 (expect "newpattern"
5348 (stub anything-update)
5349 (stub anything-action-window)
5350 (let ((anything-pattern "pattern"))
5351 (anything-check-new-input "newpattern")
5352 anything-pattern))
5353 ;; anything-input == nil when action window is available
5354 (expect nil
5355 (stub anything-update)
5356 (stub anything-action-window => t)
5357 (let ((anything-pattern "pattern")
5358 anything-input)
5359 (anything-check-new-input "newpattern")
5360 anything-input))
5361 ;; anything-input == anything-pattern unless action window is available
5362 (expect "newpattern"
5363 (stub anything-update)
5364 (stub anything-action-window => nil)
5365 (let ((anything-pattern "pattern")
5366 anything-input)
5367 (anything-check-new-input "newpattern")
5368 anything-input))
5369 (expect (mock (anything-update))
5370 (stub anything-action-window)
5371 (let (anything-pattern)
5372 (anything-check-new-input "foo")))
5373 (desc "anything-update")
5374 (expect (mock (anything-process-source '((name . "1"))))
5375 (anything-test-update '(((name . "1"))) ""))
5376 ;; (find-function 'anything-update)
5377 ;; TODO el-mock.el should express 2nd call of function.
5378 ;; (expect (mock (anything-process-source '((name . "2"))))
5379 ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
5380 ;; (stub run-hooks)
5381 ;; (stub anything-maybe-fit-frame)
5382 ;; (stub run-with-idle-timer)
5383 ;; (anything-update))
5384 (expect (mock (run-with-idle-timer * nil 'anything-process-delayed-sources
5385 '(((name . "2") (delayed)))))
5386 (stub anything-get-sources => '(((name . "1"))
5387 ((name . "2") (delayed))))
5388 (stub run-hooks)
5389 (stub anything-maybe-fit-frame)
5390 (let ((anything-pattern "") anything-test-mode)
5391 (anything-update)))
5393 (desc "requires-pattern attribute")
5394 (expect (not-called anything-process-source)
5395 (anything-test-update '(((name . "1") (requires-pattern))) ""))
5396 (expect (not-called anything-process-source)
5397 (anything-test-update '(((name . "1") (requires-pattern . 3))) "xx"))
5399 (desc "delay")
5400 (expect (mock (sit-for 0.25))
5401 (stub with-current-buffer)
5402 (let ((anything-idle-delay 1.0)
5403 (anything-input-idle-delay 0.75))
5404 (anything-process-delayed-sources t)))
5405 (expect (mock (sit-for 0.0))
5406 (stub with-current-buffer)
5407 (let ((anything-idle-delay 0.2)
5408 (anything-input-idle-delay 0.5))
5409 (anything-process-delayed-sources t)))
5410 (expect (mock (sit-for 0.5))
5411 (stub with-current-buffer)
5412 (let ((anything-idle-delay 0.5)
5413 (anything-input-idle-delay nil))
5414 (anything-process-delayed-sources t)))
5415 (desc "anything-normalize-sources")
5416 (expect '(anything-c-source-test)
5417 (anything-normalize-sources 'anything-c-source-test))
5418 (expect '(anything-c-source-test)
5419 (anything-normalize-sources '(anything-c-source-test)))
5420 (expect '(anything-c-source-test)
5421 (let ((anything-sources '(anything-c-source-test)))
5422 (anything-normalize-sources nil)))
5423 (expect '(((name . "test")))
5424 (anything-normalize-sources '((name . "test"))))
5425 (expect '(((name . "test")))
5426 (anything-normalize-sources '(((name . "test")))))
5427 (desc "anything-get-action")
5428 (expect '(("identity" . identity))
5429 (stub buffer-size => 1)
5430 (stub anything-get-current-source => '((name . "test")
5431 (action ("identity" . identity))))
5432 (anything-get-action))
5433 (expect '((("identity" . identity)) "action-transformer is called")
5434 (stub buffer-size => 1)
5435 (stub anything-get-current-source
5436 => '((name . "test")
5437 (action ("identity" . identity))
5438 (action-transformer
5439 . (lambda (actions selection)
5440 (list actions selection)))))
5441 (stub anything-get-selection => "action-transformer is called")
5442 (anything-get-action))
5443 (desc "anything-select-nth-action")
5444 (expect "selection"
5445 (stub anything-get-selection => "selection")
5446 (stub anything-exit-minibuffer)
5447 (let (anything-saved-selection)
5448 (anything-select-nth-action 1)
5449 anything-saved-selection))
5450 (expect 'cadr
5451 (stub anything-get-action => '(("0" . car) ("1" . cdr) ("2" . cadr)))
5452 (stub anything-exit-minibuffer)
5453 (stub anything-get-selection => "selection")
5454 (let (anything-saved-action)
5455 (anything-select-nth-action 2)
5456 anything-saved-action))
5457 (desc "anything-funcall-foreach")
5458 (expect (mock (upcase "foo"))
5459 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5460 (anything-funcall-foreach 'init))
5461 (expect (mock (downcase "bar"))
5462 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))
5463 ((init . (lambda () (downcase "bar"))))))
5464 (anything-funcall-foreach 'init))
5465 (expect (not-called anything-funcall-with-source)
5466 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5467 (anything-funcall-foreach 'not-found))
5468 ;; TODO anything-select-with-digit-shortcut test
5469 (desc "anything-get-cached-candidates")
5470 (expect '("cached" "version")
5471 (let ((anything-candidate-cache '(("test" "cached" "version"))))
5472 (anything-get-cached-candidates '((name . "test")
5473 (candidates "new")))))
5474 (expect '("new")
5475 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5476 (anything-get-cached-candidates '((name . "test")
5477 (candidates "new")))))
5478 (expect '(("test" "new")
5479 ("other" "cached" "version"))
5480 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5481 (anything-get-cached-candidates '((name . "test")
5482 (candidates "new")))
5483 anything-candidate-cache))
5484 (expect '(("other" "cached" "version"))
5485 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5486 (anything-get-cached-candidates '((name . "test")
5487 (candidates "new")
5488 (volatile)))
5489 anything-candidate-cache))
5490 ;; TODO when candidates == process
5491 ;; TODO anything-output-filter
5492 (desc "candidate-number-limit attribute")
5493 (expect '("a" "b")
5494 (let ((anything-pattern "")
5495 (anything-candidate-number-limit 20))
5496 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5497 (candidate-number-limit . 2) (volatile)))))
5498 (expect '("a" "b")
5499 (let ((anything-pattern "[abc]")
5500 (anything-candidate-number-limit 20))
5501 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5502 (candidate-number-limit . 2) (volatile)))))
5503 (expect '("a" "b" "c" "d")
5504 (let ((anything-pattern "[abcd]")
5505 (anything-candidate-number-limit 2))
5506 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c" "d")
5507 (candidate-number-limit) (volatile)))))
5508 (expect '(("TEST" ("a" "b" "c")))
5509 (let ((anything-candidate-number-limit 2))
5510 (anything-test-candidates
5511 '(((name . "TEST")
5512 (init
5513 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5514 (insert "a\nb\nc\nd\n"))))
5515 (candidates . anything-candidates-in-buffer)
5516 (match identity)
5517 (candidate-number-limit . 3)
5518 (volatile))))))
5519 (expect '(("TEST" ("a" "b" "c")))
5520 (let ((anything-candidate-number-limit 2))
5521 (anything-test-candidates
5522 '(((name . "TEST")
5523 (init
5524 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5525 (insert "a\nb\nc\nd\n"))))
5526 (candidates . anything-candidates-in-buffer)
5527 (match identity)
5528 (candidate-number-limit . 3)
5529 (volatile)))
5530 ".")))
5531 (desc "multiple init")
5532 (expect '(1 . 2)
5533 (let (a b)
5534 (anything-test-candidates
5535 '(((name . "test")
5536 (init (lambda () (setq a 1))
5537 (lambda () (setq b 2))))))
5538 (cons a b)))
5539 (expect 1
5540 (let (a)
5541 (anything-test-candidates
5542 '(((name . "test")
5543 (init (lambda () (setq a 1))))))
5545 (desc "multiple cleanup")
5546 (expect '(1 . 2)
5547 (let (a b)
5548 (anything-test-candidates
5549 '(((name . "test")
5550 (cleanup (lambda () (setq a 1))
5551 (lambda () (setq b 2))))))
5552 (cons a b)))
5553 (desc "anything-mklist")
5554 (expect '(1)
5555 (anything-mklist 1))
5556 (expect '(2)
5557 (anything-mklist '(2)))
5558 (expect '((lambda ()))
5559 (anything-mklist (lambda ())))
5560 (desc "anything-before-initialize-hook")
5561 (expect 'called
5562 (let ((anything-before-initialize-hook '((lambda () (setq v 'called))))
5564 (anything-initialize)
5566 (desc "anything-after-initialize-hook")
5567 (expect '(b a)
5568 (let ((anything-before-initialize-hook
5569 '((lambda () (setq v '(a)))))
5570 (anything-after-initialize-hook
5571 '((lambda () (setq v (cons 'b v)))))
5573 (anything-initialize)
5575 (expect 0
5576 (let ((anything-after-initialize-hook
5577 '((lambda () (setq v (buffer-size (get-buffer anything-buffer))))))
5579 (anything-initialize)
5581 (desc "get-line attribute")
5582 (expect '(("TEST" ("FOO+")))
5583 (anything-test-candidates
5584 '(((name . "TEST")
5585 (init
5586 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5587 (insert "foo+\nbar+\nbaz+\n"))))
5588 (candidates-in-buffer)
5589 (get-line . (lambda (s e) (upcase (buffer-substring-no-properties s e))))))
5590 "oo\\+"))
5591 (desc "with-anything-restore-variables")
5592 (expect '(7 8)
5593 (let ((a 7) (b 8)
5594 (anything-restored-variables '(a b)))
5595 (with-anything-restore-variables
5596 (setq a 0 b 0))
5597 (list a b)))
5598 (desc "anything-cleanup-hook")
5599 (expect 'called
5600 (let ((anything-cleanup-hook
5601 '((lambda () (setq v 'called))))
5603 (anything-cleanup)
5605 (desc "with-anything-display-same-window")
5606 (expect (non-nil)
5607 (save-window-excursion
5608 (delete-other-windows)
5609 (split-window)
5611 (let ((buf (get-buffer-create " tmp"))
5612 (win (selected-window)))
5613 (with-anything-display-same-window
5614 (display-buffer buf)
5615 (eq win (get-buffer-window buf))))))
5616 (expect (non-nil)
5617 (save-window-excursion
5618 (delete-other-windows)
5619 (split-window)
5621 (let ((buf (get-buffer-create " tmp"))
5622 (win (selected-window)))
5623 (with-anything-display-same-window
5624 (pop-to-buffer buf)
5625 (eq win (get-buffer-window buf))))))
5626 (expect (non-nil)
5627 (save-window-excursion
5628 (delete-other-windows)
5629 (split-window)
5631 (let ((buf (get-buffer-create " tmp"))
5632 (win (selected-window)))
5633 (with-anything-display-same-window
5634 (switch-to-buffer buf)
5635 (eq win (get-buffer-window buf))))))
5636 (expect (non-nil)
5637 (save-window-excursion
5638 (delete-other-windows)
5639 (let ((buf (get-buffer-create " tmp"))
5640 (win (selected-window)))
5641 (with-anything-display-same-window
5642 (display-buffer buf)
5643 (eq win (get-buffer-window buf))))))
5644 (expect (non-nil)
5645 (save-window-excursion
5646 (delete-other-windows)
5647 (let ((buf (get-buffer-create " tmp"))
5648 (win (selected-window)))
5649 (with-anything-display-same-window
5650 (pop-to-buffer buf)
5651 (eq win (get-buffer-window buf))))))
5652 (desc "search-from-end attribute")
5653 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5654 (anything-test-candidates
5655 '(((name . "TEST")
5656 (init
5657 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5658 (insert "foo+\nbar+\nbaz+\n"))))
5659 (candidates-in-buffer)
5660 (search-from-end)))))
5661 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5662 (anything-test-candidates
5663 '(((name . "TEST")
5664 (init
5665 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5666 (insert "foo+\nbar+\nbaz+\n"))))
5667 (candidates-in-buffer)
5668 (search-from-end)))
5669 "\\+"))
5670 (expect '(("TEST" ("baz+" "bar+")))
5671 (anything-test-candidates
5672 '(((name . "TEST")
5673 (init
5674 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5675 (insert "foo+\nbar+\nbaz+\n"))))
5676 (candidates-in-buffer)
5677 (search-from-end)
5678 (candidate-number-limit . 2)))))
5679 (expect '(("TEST" ("baz+" "bar+")))
5680 (anything-test-candidates
5681 '(((name . "TEST")
5682 (init
5683 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5684 (insert "foo+\nbar+\nbaz+\n"))))
5685 (candidates-in-buffer)
5686 (search-from-end)
5687 (candidate-number-limit . 2)))
5688 "\\+"))
5690 (desc "header-name attribute")
5691 (expect "original is transformed"
5692 (anything-test-update '(((name . "original")
5693 (candidates "1")
5694 (header-name
5695 . (lambda (name)
5696 (format "%s is transformed" name)))))
5698 (with-current-buffer (anything-buffer-get)
5699 (buffer-string)
5700 (overlay-get (car (overlays-at (1+(point-min)))) 'display)))
5701 (desc "volatile and match attribute")
5702 ;; candidates function is called once per `anything-process-delayed-sources'
5703 (expect 1
5704 (let ((v 0))
5705 (anything-test-candidates '(((name . "test")
5706 (candidates . (lambda () (incf v) '("ok")))
5707 (volatile)
5708 (match identity identity identity)))
5709 "o")
5711 (desc "accept-empty attribute")
5712 (expect nil
5713 (anything-test-candidates
5714 '(((name . "test") (candidates "") (action . identity))))
5715 (anything-execute-selection-action))
5716 (expect ""
5717 (anything-test-candidates
5718 '(((name . "test") (candidates "") (action . identity) (accept-empty))))
5719 (anything-execute-selection-action))
5720 (desc "anything-tick-hash")
5721 (expect nil
5722 (with-current-buffer (get-buffer-create " *00create+*")
5723 (puthash " *00create+*/xxx" 1 anything-tick-hash)
5724 (kill-buffer (current-buffer)))
5725 (gethash " *00create+*/xxx" anything-tick-hash))
5726 (desc "anything-execute-action-at-once-if-once")
5727 (expect "HOGE"
5728 (let ((anything-execute-action-at-once-if-one t))
5729 (anything '(((name . "one test1")
5730 (candidates "hoge")
5731 (action . upcase))))))
5732 (expect "ANY"
5733 (let ((anything-execute-action-at-once-if-one t))
5734 (anything '(((name . "one test2")
5735 (candidates "hoge" "any")
5736 (action . upcase)))
5737 "an")))
5738 ;; candidates > 1
5739 (expect (mock (read-string "word: " nil))
5740 (let ((anything-execute-action-at-once-if-one t))
5741 (anything '(((name . "one test3")
5742 (candidates "hoge" "foo" "bar")
5743 (action . identity)))
5744 nil "word: ")))
5745 (desc "anything-quit-if-no-candidate")
5746 (expect nil
5747 (let ((anything-quit-if-no-candidate t))
5748 (anything '(((name . "zero test1") (candidates) (action . upcase))))))
5749 (expect 'called
5750 (let (v (anything-quit-if-no-candidate (lambda () (setq v 'called))))
5751 (anything '(((name . "zero test2") (candidates) (action . upcase))))
5753 (desc "real-to-display attribute")
5754 (expect '(("test" (("DDD" . "ddd"))))
5755 (anything-test-candidates '(((name . "test")
5756 (candidates "ddd")
5757 (real-to-display . upcase)
5758 (action . identity)))))
5759 (expect '(("test" (("DDD" . "ddd"))))
5760 (anything-test-candidates '(((name . "test")
5761 (candidates ("ignored" . "ddd"))
5762 (real-to-display . upcase)
5763 (action . identity)))))
5764 (expect '(("Commands" (("xxxhoge" . "hoge") ("xxxboke" . "boke"))))
5765 (anything-test-candidates '(((name . "Commands")
5766 (candidates
5767 "hoge" "boke")
5768 (real-to-display . (lambda (x) (concat "xxx" x)))
5769 (action . identity)))
5770 "xxx"))
5771 (expect "test\nDDD\n"
5772 (anything-test-update '(((name . "test")
5773 (candidates "ddd")
5774 (real-to-display . upcase)
5775 (action . identity)))
5777 (with-current-buffer (anything-buffer-get) (buffer-string)))
5778 (desc "real-to-display and candidate-transformer attribute")
5779 (expect '(("test" (("DDD" . "ddd"))))
5780 (anything-test-candidates
5781 '(((name . "test")
5782 (candidates "ddd")
5783 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
5784 (real-to-display . upcase)
5785 (action . identity)))))
5786 (expect "test\nDDD\n"
5787 (anything-test-update
5788 '(((name . "test")
5789 (candidates "ddd")
5790 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
5791 (real-to-display . upcase)
5792 (action . identity)))
5794 (with-current-buffer (anything-buffer-get) (buffer-string)))
5795 (desc "real-to-display and candidates-in-buffer")
5796 (expect '(("test" (("A" . "a") ("B" . "b"))))
5797 (anything-test-candidates
5798 '(((name . "test")
5799 (init
5800 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5801 (erase-buffer)
5802 (insert "a\nb\n"))))
5803 (candidates-in-buffer)
5804 (real-to-display . upcase)
5805 (action . identity)))))
5806 (expect "test\nA\nB\n"
5807 (stub read-string)
5808 (anything
5809 '(((name . "test")
5810 (init
5811 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5812 (erase-buffer)
5813 (insert "a\nb\n"))))
5814 (candidates-in-buffer)
5815 (real-to-display . upcase)
5816 (action . identity))))
5817 (with-current-buffer (anything-buffer-get) (buffer-string)))
5818 (desc "Symbols are acceptable as candidate.")
5819 (expect '(("test" (sym "str")))
5820 (anything-test-candidates
5821 '(((name . "test")
5822 (candidates sym "str")))))
5823 (expect '(("test" ((sym . realsym) ("str" . "realstr"))))
5824 (anything-test-candidates
5825 '(((name . "test")
5826 (candidates (sym . realsym) ("str" . "realstr"))))))
5827 (expect '(("test" (sym)))
5828 (anything-test-candidates
5829 '(((name . "test")
5830 (candidates sym "str")))
5831 "sym"))
5832 (expect '(("test" ("str")))
5833 (anything-test-candidates
5834 '(((name . "test")
5835 (candidates sym "str")))
5836 "str"))
5837 (expect '(("test" ((sym . realsym))))
5838 (anything-test-candidates
5839 '(((name . "test")
5840 (candidates (sym . realsym) ("str" . "realstr"))))
5841 "sym"))
5842 (expect '(("test" (("str" . "realstr"))))
5843 (anything-test-candidates
5844 '(((name . "test")
5845 (candidates (sym . realsym) ("str" . "realstr"))))
5846 "str"))
5847 (desc "multiple transformers")
5848 (expect '(("test" ("<FOO>")))
5849 (anything-test-candidates
5850 '(((name . "test")
5851 (candidates "foo")
5852 (candidate-transformer
5853 . (lambda (cands)
5854 (anything-compose (list cands)
5855 (list (lambda (c) (mapcar 'upcase c))
5856 (lambda (c) (list (concat "<" (car c) ">")))))))))))
5857 (expect '("<FOO>")
5858 (anything-composed-funcall-with-source
5859 '((name . "test"))
5860 (list (lambda (c) (mapcar 'upcase c))
5861 (lambda (c) (list (concat "<" (car c) ">"))))
5862 '("foo"))
5864 (expect '(("test" ("<FOO>")))
5865 (anything-test-candidates
5866 '(((name . "test")
5867 (candidates "foo")
5868 (candidate-transformer
5869 (lambda (c) (mapcar 'upcase c))
5870 (lambda (c) (list (concat "<" (car c) ">"))))))))
5871 (expect '(("test" ("<BAR>")))
5872 (anything-test-candidates
5873 '(((name . "test")
5874 (candidates "bar")
5875 (filtered-candidate-transformer
5876 (lambda (c s) (mapcar 'upcase c))
5877 (lambda (c s) (list (concat "<" (car c) ">"))))))))
5878 (expect '(("find-file" . find-file)
5879 ("view-file" . view-file))
5880 (stub zerop => nil)
5881 (stub anything-get-current-source
5882 => '((name . "test")
5883 (action)
5884 (action-transformer
5885 . (lambda (a s)
5886 (anything-compose
5887 (list a s)
5888 (list (lambda (a s) (push '("view-file" . view-file) a))
5889 (lambda (a s) (push '("find-file" . find-file) a))))))))
5890 (anything-get-action))
5891 (expect '(("find-file" . find-file)
5892 ("view-file" . view-file))
5893 (stub zerop => nil)
5894 (stub anything-get-current-source
5895 => '((name . "test")
5896 (action)
5897 (action-transformer
5898 (lambda (a s) (push '("view-file" . view-file) a))
5899 (lambda (a s) (push '("find-file" . find-file) a)))))
5900 (anything-get-action))
5901 (desc "define-anything-type-attribute")
5902 (expect '((file (action . find-file)))
5903 (let (anything-type-attributes)
5904 (define-anything-type-attribute 'file '((action . find-file)))
5905 anything-type-attributes))
5906 (expect '((file (action . find-file)))
5907 (let ((anything-type-attributes '((file (action . view-file)))))
5908 (define-anything-type-attribute 'file '((action . find-file)))
5909 anything-type-attributes))
5910 (expect '((file (action . find-file))
5911 (buffer (action . switch-to-buffer)))
5912 (let (anything-type-attributes)
5913 (define-anything-type-attribute 'buffer '((action . switch-to-buffer)))
5914 (define-anything-type-attribute 'file '((action . find-file)))
5915 anything-type-attributes))
5916 (desc "anything-approximate-candidate-number")
5917 (expect 0
5918 (with-temp-buffer
5919 (let ((anything-buffer (current-buffer)))
5920 (anything-approximate-candidate-number))))
5921 (expect 1
5922 (with-temp-buffer
5923 (let ((anything-buffer (current-buffer)))
5924 (insert "Title\n"
5925 "candiate1\n")
5926 (anything-approximate-candidate-number))))
5927 (expect t
5928 (with-temp-buffer
5929 (let ((anything-buffer (current-buffer)))
5930 (insert "Title\n"
5931 "candiate1\n"
5932 "candiate2\n")
5933 (<= 2 (anything-approximate-candidate-number)))))
5934 (expect 1
5935 (with-temp-buffer
5936 (let ((anything-buffer (current-buffer)))
5937 (insert "Title\n"
5938 (propertize "multi\nline\n" 'anything-multiline t))
5939 (anything-approximate-candidate-number))))
5940 (expect t
5941 (with-temp-buffer
5942 (let ((anything-buffer (current-buffer))
5943 (anything-candidate-separator "-----"))
5944 (insert "Title\n"
5945 (propertize "multi\nline1\n" 'anything-multiline t)
5946 "-----\n"
5947 (propertize "multi\nline2\n" 'anything-multiline t))
5948 (<= 2 (anything-approximate-candidate-number)))))
5949 (desc "delayed-init attribute")
5950 (expect 0
5951 (let ((value 0))
5952 (anything-test-candidates '(((name . "test")
5953 (delayed-init . (lambda () (incf value)))
5954 (candiates "abc")
5955 (requires-pattern . 2)))
5957 value))
5958 (expect 1
5959 (let ((value 0))
5960 (anything-test-candidates '(((name . "test")
5961 (delayed-init . (lambda () (incf value)))
5962 (candiates "abc")
5963 (requires-pattern . 2)))
5964 "abc")
5965 value))
5966 (desc "pattern-transformer attribute")
5967 (expect '(("test2" ("foo")) ("test3" ("bar")))
5968 (anything-test-candidates '(((name . "test1")
5969 (candidates "foo" "bar"))
5970 ((name . "test2")
5971 (pattern-transformer . (lambda (pat) (substring pat 1)))
5972 (candidates "foo" "bar"))
5973 ((name . "test3")
5974 (pattern-transformer . (lambda (pat) "bar"))
5975 (candidates "foo" "bar")))
5976 "xfoo"))
5977 (expect '(("test2" ("foo")) ("test3" ("bar")))
5978 (anything-test-candidates '(((name . "test1")
5979 (candidates "foo" "bar"))
5980 ((name . "test2")
5981 (pattern-transformer (lambda (pat) (substring pat 1)))
5982 (candidates "foo" "bar"))
5983 ((name . "test3")
5984 (pattern-transformer (lambda (pat) "bar"))
5985 (candidates "foo" "bar")))
5986 "xfoo"))
5987 (expect '(("test2" ("foo")) ("test3" ("bar")))
5988 (anything-test-candidates '(((name . "test1")
5989 (init
5990 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5991 (insert "foo\nbar\n"))))
5992 (candidates-in-buffer))
5993 ((name . "test2")
5994 (pattern-transformer . (lambda (pat) (substring pat 1)))
5995 (init
5996 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5997 (insert "foo\nbar\n"))))
5998 (candidates-in-buffer))
5999 ((name . "test3")
6000 (pattern-transformer . (lambda (pat) "bar"))
6001 (init
6002 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
6003 (insert "foo\nbar\n"))))
6004 (candidates-in-buffer)))
6005 "xfoo"))
6006 (desc "anything-recent-push")
6007 (expect '("foo" "bar" "baz")
6008 (let ((lst '("bar" "baz")))
6009 (anything-recent-push "foo" 'lst)))
6010 (expect '("foo" "bar" "baz")
6011 (let ((lst '("foo" "bar" "baz")))
6012 (anything-recent-push "foo" 'lst)))
6013 (expect '("foo" "bar" "baz")
6014 (let ((lst '("bar" "foo" "baz")))
6015 (anything-recent-push "foo" 'lst)))
6016 (desc "anything-require-at-least-version")
6017 (expect nil
6018 (anything-require-at-least-version "1.1"))
6019 (expect nil
6020 (anything-require-at-least-version "1.200"))
6021 (expect nil
6022 (anything-require-at-least-version
6023 (and (string-match "1\.\\([0-9]+\\)" anything-version)
6024 (match-string 0 anything-version))))
6025 (expect (error)
6026 (anything-require-at-least-version "1.999"))
6027 (expect (error)
6028 (anything-require-at-least-version "1.2000"))
6029 (desc "anything-once")
6030 (expect 2
6031 (let ((i 0))
6032 (anything-test-candidates
6033 '(((name . "1")
6034 (init . (lambda () (incf i))))
6035 ((name . "2")
6036 (init . (lambda () (incf i))))))
6038 (expect 1
6039 (let ((i 0))
6040 (anything-test-candidates
6041 '(((name . "1")
6042 (init . (lambda () (anything-once (lambda () (incf i))))))
6043 ((name . "2")
6044 (init . (lambda () (anything-once (lambda () (incf i))))))))
6046 (expect 1
6047 (let ((i 0))
6048 (flet ((init1 () (anything-once (lambda () (incf i)))))
6049 (anything-test-candidates
6050 '(((name . "1")
6051 (init . init1))
6052 ((name . "2")
6053 (init . init1)))))
6055 (desc "anything-marked-candidates")
6056 (expect '("mark3" "mark1")
6057 (let* ((source '((name . "mark test")))
6058 (anything-marked-candidates
6059 `((,source . "mark1")
6060 (((name . "other")) . "mark2")
6061 (,source . "mark3"))))
6062 (stub anything-get-current-source => source)
6063 (anything-marked-candidates)))
6064 (expect '("current")
6065 (let* ((source '((name . "mark test")))
6066 (anything-marked-candidates nil))
6067 (stub anything-get-current-source => source)
6068 (stub anything-get-selection => "current")
6069 (anything-marked-candidates)))
6073 (provide 'anything)
6074 ;; How to save (DO NOT REMOVE!!)
6075 ;; (progn (magit-push) (emacswiki-post "anything.el"))
6076 ;;; anything.el ends here