Merge branch 'my-anything'
[anything-config.git] / anything.el
blob989a674a67f048f312c502eb625c8ce06df0e295
1 ;;;; anything.el --- open anything / QuickSilver-like candidate-selection framework
2 ;; $Id: anything.el,v 1.280 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-delete-current-selection'
89 ;; Delete the currently selected item.
90 ;; `anything-delete-minibuffer-content'
91 ;; Same as `delete-minibuffer-contents' but this is a command.
92 ;; `anything-toggle-resplit-window'
93 ;; Toggle resplit anything window, vertically or horizontally.
94 ;; `anything-select-2nd-action'
95 ;; Select the 2nd action for the currently selected candidate.
96 ;; `anything-select-3rd-action'
97 ;; Select the 3rd action for the currently selected candidate.
98 ;; `anything-select-4th-action'
99 ;; Select the 4th action for the currently selected candidate.
100 ;; `anything-select-2nd-action-or-end-of-line'
101 ;; Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
102 ;; `anything-execute-persistent-action'
103 ;; If a candidate is selected then perform the associated action without quitting anything.
104 ;; `anything-scroll-other-window'
105 ;; Scroll other window (not *Anything* window) upward.
106 ;; `anything-scroll-other-window-down'
107 ;; Scroll other window (not *Anything* window) downward.
108 ;; `anything-quit-and-find-file'
109 ;; Drop into `find-file' from `anything' like `iswitchb-find-file'.
110 ;; `anything-yank-selection'
111 ;; Set minibuffer contents to current selection.
112 ;; `anything-kill-selection-and-quit'
113 ;; Store current selection to kill ring.
114 ;; `anything-follow-mode'
115 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
116 ;; `anything-isearch'
117 ;; Start incremental search within results. (UNMAINTAINED)
118 ;; `anything-isearch-printing-char'
119 ;; Add printing char to the pattern.
120 ;; `anything-isearch-again'
121 ;; Search again for the current pattern
122 ;; `anything-isearch-delete'
123 ;; Undo last event.
124 ;; `anything-isearch-default-action'
125 ;; Execute the default action for the selected candidate.
126 ;; `anything-isearch-select-action'
127 ;; Choose an action for the selected candidate.
128 ;; `anything-isearch-cancel'
129 ;; Cancel Anything isearch.
130 ;; `anything-iswitchb-setup'
131 ;; Integrate anything completion into iswitchb (UNMAINTAINED).
132 ;; `anything-iswitchb-cancel-anything'
133 ;; Cancel anything completion and return to standard iswitchb.
134 ;; `anything-describe-anything-attribute'
135 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
137 ;;; Customizable Options:
139 ;; Below are customizable option list:
142 ;; You can extend `anything' by writing plug-ins. As soon as
143 ;; `anything' is invoked, `anything-sources' is compiled into basic
144 ;; attributes, then compiled one is used during invocation.
146 ;; The oldest built-in plug-in is `type' attribute: appends
147 ;; appropriate element of `anything-type-attributes'. Second built-in
148 ;; plug-in is `candidates-in-buffer': selecting a line from candidates
149 ;; buffer.
151 ;; To write a plug-in:
152 ;; 1. Define a compiler: anything-compile-source--*
153 ;; 2. Add compier function to `anything-compile-source-functions'.
154 ;; 3. (optional) Write helper functions.
156 ;; Anything plug-ins are found in the EmacsWiki.
158 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
160 ;; Tested on Emacs 22/23.
163 ;; Thanks to Vagn Johansen for ideas.
164 ;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
165 ;; Thanks to Tassilo Horn for fixes.
166 ;; Thanks to Drew Adams for various fixes (frame, isearch, customization, etc.)
167 ;; Thanks to IMAKADO for candidates-in-buffer idea.
168 ;; Thanks to Tomohiro MATSUYAMA for multiline patch.
171 ;;; (@* "Index")
173 ;; If you have library `linkd.el', load
174 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
175 ;; navigate around the sections Linkd mode will
176 ;; highlight this Index. You can get `linkd.el' here:
177 ;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
181 ;;; (@* "INCOMPATIBLE CHANGES")
183 ;; v1.277
185 ;; Default setting of `anything-save-configuration-functions' is changed.
186 ;; Anything saves/restores window configuration instead of frame configuration now.
187 ;; The default is changed because flickering is occurred in some environment.
189 ;; If you want to save and restore frame configuration, set this variable to
190 ;; '(set-frame-configuration . current-frame-configuration)
192 ;; v1.276
194 ;; Fitting frame is disabled by default, because some flickering occurred
195 ;; in some environment. To enable fitting, set both
196 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
197 ;; nil.
199 ;; v1.114
201 ;; `anything-attr' returns nil when the source attribute is defined
202 ;; but the value of attribute is nil, eg. (volatile) cell. Use
203 ;; `anything-attr-defined' when testing whether the attribute is
204 ;; defined.
206 ;;; (@* "Tips")
209 ;; If you want to create anything sources, yasnippet would help you.
210 ;; http://yasnippet.googlecode.com/
212 ;; Then get the snippet from
213 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
215 ;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
219 ;; `anything-interpret-value' is useful function to interpret value
220 ;; like `candidates' attribute.
222 ;; (anything-interpret-value "literal") ; => "literal"
223 ;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
224 ;; (let ((source '((name . "lambda with source name"))))
225 ;; (anything-interpret-value
226 ;; (lambda () anything-source-name)
227 ;; source)) ; => "lambda with source name"
228 ;; (flet ((f () "function symbol"))
229 ;; (anything-interpret-value 'f)) ; => "function symbol"
230 ;; (let ((v "variable symbol"))
231 ;; (anything-interpret-value 'v)) ; => "variable symbol"
232 ;; (anything-interpret-value 'unbounded-1) ; error
235 ;; Now symbols are acceptable as candidates. So you do not have to use
236 ;; `symbol-name' function. The source is much simpler. For example,
237 ;; `apropos-internal' returns a list of symbols.
239 ;; (anything
240 ;; '(((name . "Commands")
241 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
242 ;; (volatile)
243 ;; (action . describe-function))))
246 ;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
247 ;; marked candidate, press M-[ or M-].
250 ;; `anything-map' is now Emacs-standard key bindings by default. If
251 ;; you are using `iswitchb', execute `anything-iswitchb-setup'. Then
252 ;; some key bindings are adjusted to `iswitchb'. Note that
253 ;; anything-iswitchb is not maintained.
256 ;; There are many `anything' applications, using `anything' for
257 ;; selecting candidate. In this case, if there is one candidate or no
258 ;; candidate, popping up *anything* buffer is irritating. If one
259 ;; candidate, you want to select it at once. If no candidate, you want
260 ;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
261 ;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
262 ;; that setting these variables GLOBALLY is bad idea because of
263 ;; delayed sources. These are meant to be let-binded.
264 ;; See anything-etags.el for example.
266 ;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
268 ;; ex.
269 ;; (let ((anything-execute-action-at-once-if-one t)
270 ;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
271 ;; (anything temporary-sources input))
274 ;; `set-frame-configuration' arises flickering. If you hate
275 ;; flickering, eval:
276 ;; (setq anything-save-configuration-functions
277 ;; '(set-window-configuration . current-window-configuration))
278 ;; at the cost of restoring frame configuration (only window configuration).
281 ;; `anything-delete-current-selection' deletes the current line.
282 ;; It is useful when deleting a candidate in persistent action.
283 ;; eg. `kill-buffer'.
285 ;; [EVAL IT] (describe-function 'anything-delete-current-selection)
288 ;; `anything-attr' gets the attribute. `anything-attrset' sets the
289 ;; attribute. `anything-attr-defined' tests whether the attribute is
290 ;; defined. They handles source-local variables.
292 ;; [EVAL IT] (describe-function 'anything-attr)
293 ;; [EVAL IT] (describe-function 'anything-attrset)
294 ;; [EVAL IT] (describe-function 'anything-attr-defined)
297 ;; `anything-sources' accepts many attributes to make your life easier.
298 ;; Now `anything-sources' accepts a list of symbols.
300 ;; [EVAL IT] (describe-variable 'anything-sources)
303 ;; `anything' has optional arguments. Now you do not have to let-bind
304 ;; `anything-sources'.
306 ;; [EVAL IT] (describe-function 'anything)
309 ;; `anything-resume' resumes last `anything' session. Now you do not
310 ;; have to retype pattern.
312 ;; [EVAL IT] (describe-function 'anything-resume)
315 ;; `anything-execute-persistent-action' executes action without
316 ;; quitting `anything'. When popping up a buffer in other window by
317 ;; persistent action, you can scroll with `anything-scroll-other-window' and
318 ;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
320 ;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
321 ;; [EVAL IT] (describe-variable 'anything-sources)
324 ;; `anything-select-2nd-action', `anything-select-3rd-action' and
325 ;; `anything-select-4th-action' select other than default action
326 ;; without pressing Tab.
329 ;; Using `anything-candidate-buffer' and the candidates-in-buffer
330 ;; attribute is much faster than traditional "candidates and match"
331 ;; way. And `anything-current-buffer-is-modified' avoids to
332 ;; recalculate candidates for unmodified buffer. See docstring of
333 ;; them.
335 ;; [EVAL IT] (describe-function 'anything-candidate-buffer)
336 ;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
337 ;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
340 ;; `anything-current-buffer' and `anything-buffer-file-name' stores
341 ;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
342 ;; is invoked. Use them freely.
344 ;; [EVAL IT] (describe-variable 'anything-current-buffer)
345 ;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
348 ;; `anything-completing-read' and `anything-read-file-name' are
349 ;; experimental implementation. If you are curious, type M-x
350 ;; anything-read-string-mode. It is a minor mode and toggles on/off.
353 ;; Use `anything-test-candidates' to test your handmade anything
354 ;; sources. It simulates contents of *anything* buffer with pseudo
355 ;; `anything-sources' and `anything-pattern', without side-effect. So
356 ;; you can unit-test your anything sources! Let's TDD!
358 ;; [EVAL IT] (describe-function 'anything-test-candidates)
360 ;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
361 ;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
363 ;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
364 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
365 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
368 ;; (@* "TODO")
370 ;; - process status indication
372 ;; - async sources doesn't honor digit-shortcut-count
374 ;; - anything-candidate-number-limit can't be nil everywhere
376 ;; (@* "HISTORY")
377 ;; $Log: anything.el,v $
378 ;; Revision 1.280 2010-04-01 02:22:22 rubikitch
379 ;; `anything': new argument ANY-KEYMAP
381 ;; Revision 1.279 2010/03/31 09:22:58 rubikitch
382 ;; Add tips of yasnippet for source creators (no code change)
384 ;; Revision 1.278 2010/03/31 09:01:08 rubikitch
385 ;; Added info to INCOMPATIBLE CHANGES
387 ;; Revision 1.277 2010/03/31 08:56:53 rubikitch
388 ;; Anything saves/restores window configuration instead of frame configuration now.
389 ;; The default is changed because flickering is occurred in some environment.
391 ;; If you want to save and restore frame configuration, set this variable to
392 ;; '(set-frame-configuration . current-frame-configuration)
394 ;; Revision 1.276 2010/03/31 08:52:50 rubikitch
395 ;; Fitting frame is disabled by default, because some flickering occurred
396 ;; in some environment. To enable fitting, set both
397 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
398 ;; nil.
400 ;; Revision 1.275 2010/03/31 02:46:09 rubikitch
401 ;; (defvaralias 'anything-attributes 'anything-additional-attributes)
403 ;; Revision 1.274 2010/03/31 02:43:35 rubikitch
404 ;; New command: `anything-describe-anything-attribute'
406 ;; Revision 1.273 2010/03/31 02:37:18 rubikitch
407 ;; Document all attributes by `anything-document-attribute' instead of `anything-sources' docstring
409 ;; Revision 1.272 2010/03/29 21:05:47 rubikitch
410 ;; `anything-mode-line-string': use `make-local-variable' instead
412 ;; Revision 1.271 2010/03/29 09:59:17 rubikitch
413 ;; stupid bug
415 ;; Revision 1.270 2010/03/29 09:56:12 rubikitch
416 ;; Call `filtered-candidate-transformer' functions even if process sources
418 ;; Revision 1.269 2010/03/29 08:42:23 rubikitch
419 ;; * New attribute `resume'
420 ;; * Fix a bug of `disable-shortcuts' plug-in
422 ;; Revision 1.268 2010/03/28 21:42:01 rubikitch
423 ;; Add some keys in `anything-help'
425 ;; Revision 1.267 2010/03/28 20:11:30 rubikitch
426 ;; Modify `anything-mode-line-string'
428 ;; Revision 1.266 2010/03/28 06:12:43 rubikitch
429 ;; process source and multiline: in the making (not usable)
431 ;; Revision 1.265 2010/03/28 05:07:00 rubikitch
432 ;; Change default `anything-sources'. It is only a sample, no problem.
434 ;; Revision 1.264 2010/03/27 19:02:52 rubikitch
435 ;; New attributes: `mode-line' and `header-line'
437 ;; Revision 1.263 2010/03/27 02:34:40 rubikitch
438 ;; doc
440 ;; Revision 1.262 2010/03/27 02:31:55 rubikitch
441 ;; New command: `anything-force-update' C-c C-u
443 ;; Revision 1.261 2010/03/27 02:29:39 rubikitch
444 ;; New function `anything-goto-source'
446 ;; Revision 1.260 2010/03/27 02:01:28 rubikitch
447 ;; reimplement move selection commands
449 ;; Revision 1.259 2010/03/26 22:52:15 rubikitch
450 ;; `anything-quit-and-find-file':
451 ;; If current selection is a buffer or a file, `find-file' from its directory.
452 ;; Idea from http://i-yt.info/?date=20090826#p01 with some modification. Thanks.
454 ;; Revision 1.258 2010/03/26 12:10:55 rubikitch
455 ;; * modify `anything-mode-line-string'
456 ;; * New command `anything-help'
458 ;; Revision 1.257 2010/03/24 11:08:19 rubikitch
459 ;; revert to 1.255
461 ;; Revision 1.256 2010/03/24 08:29:43 rubikitch
462 ;; `anything-check-minibuffer-input' set repeat timer.
464 ;; Revision 1.255 2010/03/24 02:35:47 rubikitch
465 ;; `anything-candidate-number-limit':
466 ;; When (candidate-number-limit) is specified in SOURCE,
467 ;; cancel the effect of `anything-candidate-number-limit'.
469 ;; Revision 1.254 2010/03/23 00:33:18 rubikitch
470 ;; New API: `anything-interpret-value'
472 ;; Revision 1.253 2010/03/22 07:04:03 rubikitch
473 ;; `anything-get-current-source': return nil when no candidates rather than error
475 ;; Revision 1.252 2010/03/21 06:08:44 rubikitch
476 ;; Mark bug fix. thx hchbaw!
477 ;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
479 ;; Revision 1.251 2010/03/21 02:39:34 rubikitch
480 ;; Fix a wrong usage of `delq'. thx hchbaw.
481 ;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
483 ;; Revision 1.250 2010/03/21 02:32:29 rubikitch
484 ;; Fix `select deleted buffer' error message when calling `anything-resume'.
486 ;; It was occurred when killing `anything-current-buffer' and calling `anything-resume'.
488 ;; Revision 1.249 2010/02/23 20:43:35 rubikitch
489 ;; `anything-update': Ensure to call `anything-next-line'
491 ;; Revision 1.248 2010/02/20 12:34:38 rubikitch
492 ;; Mode-line help!! `anything-mode-line-string' is help string.
494 ;; Revision 1.247 2010/02/20 10:41:39 rubikitch
495 ;; Automatically update `anything-version' when upgrading
497 ;; Revision 1.246 2010/02/20 10:38:58 rubikitch
498 ;; update copyright
500 ;; Revision 1.245 2010/02/20 10:36:01 rubikitch
501 ;; New API: `anything-require-at-least-version'
503 ;; Revision 1.244 2010/02/20 10:06:54 rubikitch
504 ;; * New plug-in: `disable-shortcuts'
505 ;; * `dummy' plug-in implies `disable-shortcuts' because it enables us to input capital letters.
507 ;; Revision 1.243 2010/02/20 09:54:16 rubikitch
508 ;; `anything-compile-source--dummy': swap arguments of `append'
510 ;; Revision 1.242 2010/02/19 17:37:12 rubikitch
511 ;; error check in `anything-set-source-filter'
513 ;; Revision 1.241 2010/01/29 18:53:17 rubikitch
514 ;; Fix a bug of `candidate-number-limit' in process sources.
516 ;; Revision 1.240 2010/01/23 04:21:31 rubikitch
517 ;; * `anything': Use `anything-display-buffer' as fallback
518 ;; * `anything-select-with-digit-shortcut': `self-insert-command' if disabled
520 ;; Revision 1.239 2009/12/28 07:33:28 rubikitch
521 ;; New command: `anything-toggle-resplit-window' (C-t)
523 ;; Revision 1.238 2009/12/28 07:19:37 rubikitch
524 ;; bugfix
526 ;; Revision 1.237 2009/12/28 07:15:30 rubikitch
527 ;; `anything-window-configuration' stores window configuration only.
529 ;; Revision 1.236 2009/12/28 07:07:09 rubikitch
530 ;; `anything-resume' resumes window configuration now.
532 ;; Revision 1.235 2009/12/28 04:12:33 rubikitch
533 ;; Fix tiny bug
535 ;; Revision 1.234 2009/12/28 03:57:33 rubikitch
536 ;; `anything-resume': New optional argument
538 ;; Revision 1.233 2009/12/28 03:43:12 rubikitch
539 ;; remove warnings
541 ;; Revision 1.232 2009/12/28 03:37:25 rubikitch
542 ;; refactoring
544 ;; Revision 1.231 2009/12/28 02:33:41 rubikitch
545 ;; refactoring
547 ;; Revision 1.230 2009/12/27 09:28:06 rubikitch
548 ;; `anything-window-configuration' save/restore anything window configuration (NOT YET)
550 ;; Revision 1.229 2009/12/26 21:41:33 rubikitch
551 ;; revive `anything-input' when resuming
553 ;; Revision 1.228 2009/12/25 01:34:35 rubikitch
554 ;; * `anything-resume' use anything interface to select anything buffers.
555 ;; * Its candidates are sorted by most recently used order.
556 ;; * 4th arg of `anything' accepts 'noresume not to resume this session.
558 ;; Revision 1.227 2009/12/19 20:30:12 rubikitch
559 ;; add `pattern-transformer' doc
561 ;; Revision 1.226 2009/12/19 20:15:47 rubikitch
562 ;; pattern-transformer can have multiple functions now
564 ;; Revision 1.225 2009/12/19 20:11:16 rubikitch
565 ;; add `delayed-init' doc
567 ;; Revision 1.224 2009/12/19 12:26:00 rubikitch
568 ;; New attribute `pattern-transformer'
570 ;; Revision 1.223 2009/12/19 11:57:41 rubikitch
571 ;; New attribute `delayed-init'
573 ;; Revision 1.222 2009/12/14 20:55:23 rubikitch
574 ;; Fix display bug: `anything-enable-digit-shortcuts' / multiline
576 ;; Revision 1.221 2009/12/14 20:29:49 rubikitch
577 ;; fix an error when executing `anything-prev-visible-mark' with no visible marks.
579 ;; Revision 1.220 2009/12/14 20:19:05 rubikitch
580 ;; Bugfix about anything-execute-action-at-once-if-one and multiline
582 ;; Revision 1.219 2009/12/14 03:21:11 rubikitch
583 ;; Extend alphabet shortcuts to A-Z
585 ;; Revision 1.218 2009/12/13 01:03:34 rubikitch
586 ;; Changed data structure of `anything-shortcut-keys-alist'
588 ;; Revision 1.217 2009/12/03 23:16:17 rubikitch
589 ;; silence warning
591 ;; Revision 1.216 2009/12/03 20:43:51 rubikitch
592 ;; Add keybindings for alphabet shortcuts
594 ;; Revision 1.215 2009/12/03 20:37:13 rubikitch
595 ;; `anything-enable-shortcuts' is an alias of `anything-enable-digit-shortcuts'.
596 ;; Alphabet shortcuts can be used now.
598 ;; Revision 1.214 2009/12/03 20:23:40 rubikitch
599 ;; `anything-enable-digit-shortcuts' also accepts 'alphabet.
601 ;; Now alphabet shortcuts are usable.
603 ;; Revision 1.213 2009/12/03 09:59:58 rubikitch
604 ;; refactoring
606 ;; Revision 1.212 2009/11/15 09:42:15 rubikitch
607 ;; refactoring
609 ;; Revision 1.211 2009/11/06 21:42:58 rubikitch
610 ;; New command: `anything-beginning-of-buffer', `anything-end-of-buffer'
612 ;; Revision 1.210 2009/10/22 13:30:06 rubikitch
613 ;; `real-to-display' function is evaluated just after `candidate-transformer' function now.
614 ;; This enables us to narrow candidates by display string by `real-to-display'.
616 ;; Revision 1.209 2009/10/21 20:25:10 rubikitch
617 ;; Add a document. (no code change)
619 ;; Revision 1.208 2009/10/21 11:31:15 rubikitch
620 ;; `anything': accept one source alist
622 ;; Revision 1.207 2009/10/16 19:47:39 rubikitch
623 ;; Link to Japanese translation of `anything-sources' attributes. (No code change)
625 ;; Revision 1.206 2009/10/10 09:28:54 rubikitch
626 ;; Remove an unnecessary test
628 ;; Revision 1.205 2009/10/10 06:21:28 rubikitch
629 ;; obsolete: `anything-c-marked-candidate-list'
630 ;; New function: `anything-marked-candidates'
632 ;; Revision 1.204 2009/10/06 21:01:12 rubikitch
633 ;; Call `anything-process-delayed-sources' only if delayed-sources is available.
635 ;; Revision 1.203 2009/10/02 10:04:07 rubikitch
636 ;; Tested on Emacs23 too. (no code change)
638 ;; Revision 1.202 2009/10/02 10:03:34 rubikitch
639 ;; * Display "no candidates" rather than assertion
640 ;; * Ensure to call `remove-hook' in `anything-current-buffer'
642 ;; Revision 1.201 2009/08/08 13:25:30 rubikitch
643 ;; `anything-toggle-visible-mark': move next line after unmarking
645 ;; Revision 1.200 2009/08/08 13:23:46 rubikitch
646 ;; `anything-toggle-visible-mark': Applied ThierryVolpiatto's patch. thx.
648 ;; Revision 1.199 2009/07/19 13:22:29 rubikitch
649 ;; `anything-follow-execute-persistent-action-maybe': execute persistent action after `anything-input-idle-delay'
651 ;; Revision 1.198 2009/07/06 15:22:48 rubikitch
652 ;; header modified (no code change)
654 ;; Revision 1.197 2009/06/29 15:10:13 rubikitch
655 ;; OOPS! remove debug code
657 ;; Revision 1.196 2009/06/29 13:29:25 rubikitch
658 ;; anything-follow-mode: automatical execution of persistent-action (C-c C-f)
660 ;; Revision 1.195 2009/06/19 14:42:57 rubikitch
661 ;; silence byte compiler
663 ;; Revision 1.194 2009/06/14 15:12:34 rubikitch
664 ;; typo
666 ;; Revision 1.193 2009/06/08 19:37:12 rubikitch
667 ;; typo!
669 ;; Revision 1.192 2009/06/08 19:36:39 rubikitch
670 ;; New keybind: C-e, C-j, C-k
672 ;; Revision 1.191 2009/06/08 19:30:27 rubikitch
673 ;; New command: `anything-select-2nd-action-or-end-of-line'
675 ;; Revision 1.190 2009/06/07 17:09:50 rubikitch
676 ;; add M-<next>, C-M-S-v, M-<prior> to `anything-map'.
678 ;; Revision 1.189 2009/06/01 21:36:31 rubikitch
679 ;; New function: `anything-other-buffer'
681 ;; Revision 1.188 2009/05/29 18:33:07 rubikitch
682 ;; avoid error when executing (anything-mark-current-line) in async process.
684 ;; Revision 1.187 2009/05/29 06:49:05 rubikitch
685 ;; small refactoring
687 ;; Revision 1.186 2009/05/29 06:46:34 rubikitch
688 ;; Prevent `anything-isearch-map' from overwriting `global-map'. With
689 ;; `copy-keymap', the prefix command "M-s" in `global-map' ends up
690 ;; getting clobbered by `anything-isearch-again', preventing `occur'
691 ;; (among other things) from running. This change replaces overwriting a
692 ;; copied map with writing to a sparse map whose parent is `global-map'.
694 ;; patched by DanielHackney. thanks!
696 ;; Revision 1.185 2009/05/25 19:07:42 rubikitch
697 ;; `anything': set `case-fold-search' to t
698 ;; Because users can assign commands to capital letter keys.
700 ;; Revision 1.184 2009/05/25 19:05:04 rubikitch
701 ;; Added auto-document
703 ;; Revision 1.183 2009/05/15 01:50:46 rubikitch
704 ;; typo
706 ;; Revision 1.182 2009/05/08 18:28:18 rubikitch
707 ;; Bug fix: `anything-attr' is usable in `header-name' function.
709 ;; Revision 1.181 2009/05/04 19:05:03 rubikitch
710 ;; * `anything-yank-selection' and `anything-kill-selection-and-quit' handles display string now.
711 ;; * `anything-get-selection': Added optional arguments.
713 ;; Revision 1.180 2009/05/03 19:03:34 rubikitch
714 ;; Add `anything-input' to `minibuffer-history' even if `anything' is quit.
716 ;; Revision 1.179 2009/04/20 16:35:44 rubikitch
717 ;; New keybindings in anything-map:
718 ;; C-c C-d: `anything-delete-current-selection'
719 ;; C-c C-y: `anything-yank-selection'
720 ;; C-c C-k: `anything-kill-selection-and-quit'
722 ;; Revision 1.178 2009/04/20 16:18:58 rubikitch
723 ;; New variable: `anything-display-function'
725 ;; Revision 1.177 2009/04/20 02:17:16 rubikitch
726 ;; New commands: `anything-yank-selection', `anything-kill-selection-and-quit'
728 ;; Revision 1.176 2009/04/08 14:48:15 rubikitch
729 ;; bug fix in `anything-candidate-buffer'
731 ;; Revision 1.175 2009/03/22 19:10:37 rubikitch
732 ;; New Variable: `anything-scroll-amount' (thx. ThierryVolpiatto)
734 ;; Revision 1.174 2009/03/12 19:12:24 rubikitch
735 ;; New API: `define-anything-type-attribute'
737 ;; Revision 1.173 2009/03/11 08:10:32 rubikitch
738 ;; Update doc
740 ;; Revision 1.172 2009/03/10 17:11:58 rubikitch
741 ;; `candidate-transformer', `filtered-candidate-transformer',
742 ;; `action-transformer' attributes: accept a list of functions
744 ;; Revision 1.171 2009/03/09 18:49:44 rubikitch
745 ;; New command: `anything-quit-and-find-file'
747 ;; Revision 1.170 2009/03/09 18:46:11 rubikitch
748 ;; New API: `anything-run-after-quit'
750 ;; Revision 1.169 2009/03/09 10:02:49 rubikitch
751 ;; Set candidate-number-limit attribute for actions.
753 ;; Revision 1.168 2009/03/07 21:01:10 rubikitch
754 ;; Bug workaround
756 ;; Revision 1.167 2009/03/06 04:13:42 rubikitch
757 ;; Fix doc
759 ;; Revision 1.166 2009/03/03 10:35:57 rubikitch
760 ;; Set default `anything-input-idle-delay' to 0.1
762 ;; Revision 1.165 2009/03/03 07:14:42 rubikitch
763 ;; Make sure to run `anything-update-hook' after processing delayed sources.
765 ;; Revision 1.164 2009/03/02 01:51:40 rubikitch
766 ;; better error handling.
768 ;; Revision 1.163 2009/03/01 05:15:00 rubikitch
769 ;; anything-iswitchb and anything-isearch are marked as unmaintained.
770 ;; (document change only)
772 ;; Revision 1.162 2009/02/28 01:24:13 rubikitch
773 ;; Symbols are now acceptable as candidate.
775 ;; Revision 1.161 2009/02/27 07:18:46 rubikitch
776 ;; Fix bug of `anything-scroll-other-window' and `anything-scroll-other-window-down'.
778 ;; Revision 1.160 2009/02/27 01:05:06 rubikitch
779 ;; * Make sure to restore point after running `anything-update-hook'.
780 ;; * Make `anything-compute-matches' easy to find error.
782 ;; Revision 1.159 2009/02/26 23:45:48 rubikitch
783 ;; * Check whether candidate is a string, otherwise ignore.
785 ;; Revision 1.158 2009/02/24 06:39:20 rubikitch
786 ;; suppress compile warnings.
788 ;; Revision 1.157 2009/02/23 22:51:43 rubikitch
789 ;; New function: `anything-document-attribute'
791 ;; Revision 1.156 2009/02/23 21:36:09 rubikitch
792 ;; New Variable: `anything-display-source-at-screen-top'
794 ;; Revision 1.155 2009/02/23 21:30:52 rubikitch
795 ;; New command: `anything-at-point'
797 ;; Revision 1.154 2009/02/23 08:57:54 rubikitch
798 ;; Visible Mark
800 ;; Revision 1.153 2009/02/23 08:38:57 rubikitch
801 ;; update doc
803 ;; Revision 1.152 2009/02/23 08:32:17 rubikitch
804 ;; More key bindings.
806 ;; Revision 1.151 2009/02/23 08:21:24 rubikitch
807 ;; `anything-map' is now Emacs-standard key bindings by default.
808 ;; After evaluating `anything-iswitchb-setup'. some key bindings are adjusted to iswitchb.
810 ;; Revision 1.150 2009/02/20 22:58:18 rubikitch
811 ;; Cancel timer in `anything-cleanup'.
813 ;; Revision 1.149 2009/02/20 12:23:44 rubikitch
814 ;; `anything-header' face now inherits header-line (not a copy).
816 ;; Revision 1.148 2009/02/16 23:40:22 rubikitch
817 ;; `real-to-display' attribute bug fix.
819 ;; Revision 1.147 2009/02/02 20:51:41 rubikitch
820 ;; New `anything-sources' attribute: real-to-display
822 ;; Revision 1.146 2009/02/01 20:01:00 rubikitch
823 ;; Update Tips
825 ;; Revision 1.145 2009/02/01 19:45:53 rubikitch
826 ;; New variable: `anything-quit-if-no-candidate'
828 ;; Revision 1.144 2009/02/01 19:31:47 rubikitch
829 ;; fixed a typo
831 ;; Revision 1.143 2009/02/01 19:23:32 rubikitch
832 ;; New variable: `anything-execute-action-at-once-if-one'
834 ;; Revision 1.142 2009/02/01 19:12:34 rubikitch
835 ;; `anything-persistent-action-display-buffer': bug fix
837 ;; Revision 1.141 2009/02/01 18:25:25 rubikitch
838 ;; * fix docstring
839 ;; * New variable: `anything-selection-face'
841 ;; Revision 1.140 2009/01/16 16:36:25 rubikitch
842 ;; New variable: `anything-persistent-action-use-special-display'.
844 ;; Revision 1.139 2009/01/05 20:15:53 rubikitch
845 ;; Fixed a bug of anything action buffer.
846 ;; The action source should not be cached.
848 ;; Revision 1.138 2008/12/21 16:56:05 rubikitch
849 ;; Fixed an error when action attribute is a function symbol and press TAB,
851 ;; Revision 1.137 2008/12/20 19:38:47 rubikitch
852 ;; `anything-check-minibuffer-input-1': proper quit handling
853 ;; `anything-process-delayed-sources': ditto
855 ;; Revision 1.136 2008/10/27 17:41:27 rubikitch
856 ;; `anything-process-delayed-sources', `anything-check-minibuffer-input-1': quittable
858 ;; Revision 1.135 2008/10/27 17:04:25 rubikitch
859 ;; arranged source, added more linkd tags (no code change)
861 ;; Revision 1.134 2008/10/27 15:02:25 rubikitch
862 ;; New variable: `anything-save-configuration-functions'
863 ;; Delete variable: `anything-save-configuration-type'
865 ;; Revision 1.133 2008/10/27 11:16:13 rubikitch
866 ;; New variable: `anything-save-configuration-type'
868 ;; Revision 1.132 2008/10/26 22:34:59 rubikitch
869 ;; `anything-delete-current-selection' with multiline
871 ;; Revision 1.131 2008/10/26 21:44:43 rubikitch
872 ;; New command: `anything-delete-current-selection'
874 ;; Revision 1.130 2008/10/22 10:41:09 rubikitch
875 ;; `anything-insert-match': do not override 'anything-realvalue property
877 ;; Revision 1.129 2008/10/21 17:01:37 rubikitch
878 ;; `anything-resume' per buffer.
879 ;; `anything-last-sources': obsolete
881 ;; Revision 1.128 2008/10/20 06:27:54 rubikitch
882 ;; `anything-quick-update': new user option
884 ;; Revision 1.127 2008/10/20 05:47:49 rubikitch
885 ;; refactoring
887 ;; Revision 1.126 2008/10/20 03:47:58 rubikitch
888 ;; `anything-update': reversed order of delayed sources
890 ;; Revision 1.125 2008/10/19 00:29:54 rubikitch
891 ;; kill buffer-local candidate buffers when creating global candidate buffers.
893 ;; Revision 1.124 2008/10/18 13:04:20 rubikitch
894 ;; Remove tick entry from `anything-tick-hash' when killing a buffer.
896 ;; Revision 1.123 2008/10/18 10:23:36 rubikitch
897 ;; multiline patch by Tomohiro MATSUYAMA.
899 ;; Revision 1.122 2008/10/13 03:10:07 rubikitch
900 ;; `anything': do `anything-mark-current-line' when resuming
902 ;; Revision 1.121 2008/10/13 03:08:08 rubikitch
903 ;; always set `anything-current-position'
905 ;; Revision 1.120 2008/10/07 14:12:02 rubikitch
906 ;; `anything-execute-persistent-action': optional arg
908 ;; Revision 1.119 2008/10/06 06:43:29 rubikitch
909 ;; `anything-candidate-buffer': return nil when the buffer is dead
911 ;; Revision 1.118 2008/09/30 22:21:28 rubikitch
912 ;; New `anything-sources' attribute: accept-empty
913 ;; dummy: include accept-empty
915 ;; Revision 1.117 2008/09/30 21:59:10 rubikitch
916 ;; New function: `anything-buffer-is-modified'
918 ;; Revision 1.116 2008/09/22 11:27:29 rubikitch
919 ;; *** empty log message ***
921 ;; Revision 1.115 2008/09/20 20:21:11 rubikitch
922 ;; added linkd index. (no code change)
924 ;; Revision 1.114 2008/09/20 20:09:57 rubikitch
925 ;; INCOMPATIBLE CHANGES: `anything-attr'
926 ;; New functions: `anything-attrset', `anything-attr-defined'
928 ;; Revision 1.113 2008/09/14 15:15:32 rubikitch
929 ;; bugfix: volatile and match attribute / process and match attribute
931 ;; Revision 1.112 2008/09/12 01:57:17 rubikitch
932 ;; When resuming anything, reinitialize overlays.
934 ;; Revision 1.111 2008/09/10 22:53:11 rubikitch
935 ;; anything: bug fix of `anything-buffer'
936 ;; New macro: `anything-test-update'
938 ;; Revision 1.110 2008/09/10 22:17:11 rubikitch
939 ;; New `anything-sources' attribute: header-name
941 ;; Revision 1.109 2008/09/10 21:12:26 rubikitch
942 ;; New hook: `anything-after-action-hook'
944 ;; Revision 1.108 2008/09/06 06:07:56 rubikitch
945 ;; Extended `anything-set-sources' optional arguments.
947 ;; Revision 1.107 2008/09/05 03:14:35 rubikitch
948 ;; reimplement `anything-current-buffer-is-modified' in the right way
950 ;; Revision 1.106 2008/09/05 00:11:05 rubikitch
951 ;; Moved `anything-read-string-mode' and read functions to anything-complete.el.
953 ;; Revision 1.105 2008/09/04 12:45:06 rubikitch
954 ;; New hook: `anything-after-persistent-action-hook'
956 ;; Revision 1.104 2008/09/04 12:27:05 rubikitch
957 ;; `anything': prefixed optional arguments
959 ;; Revision 1.103 2008/09/04 09:16:28 rubikitch
960 ;; fixed a bug of `anything-read-file-name'.
962 ;; Revision 1.102 2008/09/03 11:25:19 rubikitch
963 ;; Extended `anything' optional arguments: buffer
965 ;; Revision 1.101 2008/09/03 11:15:13 rubikitch
966 ;; `anything': return nil when keybord-quitted
968 ;; Revision 1.100 2008/09/01 23:11:02 rubikitch
969 ;; bug fix of search-from-end
971 ;; Revision 1.99 2008/09/01 13:45:55 rubikitch
972 ;; bug fix of search-from-end
974 ;; Revision 1.98 2008/09/01 11:23:38 rubikitch
975 ;; New `anything-sources' attribute: search-from-end
977 ;; Revision 1.97 2008/09/01 00:44:34 rubikitch
978 ;; Make sure to display the other window when persistent action.
980 ;; Revision 1.96 2008/08/31 20:55:20 rubikitch
981 ;; define `buffer-modified-tick' for older emacs.
983 ;; Revision 1.95 2008/08/30 04:55:51 rubikitch
984 ;; fixed a bug of `anything-completing-read'
986 ;; Revision 1.94 2008/08/28 20:18:03 rubikitch
987 ;; added some tests
989 ;; Revision 1.93 2008/08/25 20:18:46 rubikitch
990 ;; `anything': set `anything-input' and `anything-pattern' before `anything-update'
992 ;; Revision 1.92 2008/08/24 22:38:46 rubikitch
993 ;; *** empty log message ***
995 ;; Revision 1.91 2008/08/24 21:34:35 rubikitch
996 ;; rewrite `with-anything-restore-variables'
998 ;; Revision 1.90 2008/08/24 20:33:02 rubikitch
999 ;; prevent the unit test from byte-compiled.
1000 ;; macro bug fix.
1002 ;; Revision 1.89 2008/08/24 08:35:27 rubikitch
1003 ;; *** empty log message ***
1005 ;; Revision 1.88 2008/08/24 08:22:19 rubikitch
1006 ;; Rename `anything-candidates-buffer' -> `anything-candidate-buffer'
1008 ;; Revision 1.87 2008/08/23 22:27:04 rubikitch
1009 ;; New hook: `anything-cleanup-hook'
1011 ;; Revision 1.86 2008/08/23 22:05:42 rubikitch
1012 ;; `anything-original-source-filter' is removed.
1013 ;; Now use `anything-restored-variables' and `with-anything-restore-variables'.
1015 ;; Revision 1.85 2008/08/23 21:23:21 rubikitch
1016 ;; inhibit-read-only = t in anything-buffer
1018 ;; Revision 1.84 2008/08/23 21:18:33 rubikitch
1019 ;; *** empty log message ***
1021 ;; Revision 1.83 2008/08/23 20:44:20 rubikitch
1022 ;; `anything-execute-persistent-action': display-to-real bug fix
1024 ;; Revision 1.82 2008/08/23 20:19:12 rubikitch
1025 ;; New `anything-sources' attribute: get-line
1027 ;; Revision 1.81 2008/08/23 19:32:14 rubikitch
1028 ;; `anything-attr': Return t in (attribute-name) case.
1030 ;; Revision 1.80 2008/08/22 21:25:05 rubikitch
1031 ;; anything-candidates-in-buffer-1:
1032 ;; Open a line at the BOB to make use of `search-forward' for faster exact/prefix match.
1033 ;; Of course, restore the buffer contents after search.
1035 ;; Revision 1.79 2008/08/22 17:11:00 rubikitch
1036 ;; New hook: `anything-before-initialize-hook', `anything-after-initialize-hook'
1038 ;; Revision 1.78 2008/08/21 18:37:03 rubikitch
1039 ;; Implemented dummy sources as plug-in.
1041 ;; Revision 1.77 2008/08/21 17:40:40 rubikitch
1042 ;; New function: `anything-set-sources'
1044 ;; Revision 1.76 2008/08/21 12:25:02 rubikitch
1045 ;; New variable: `anything-version'
1047 ;; Revision 1.75 2008/08/21 12:13:46 rubikitch
1048 ;; New variable: `anything-in-persistent-action'
1050 ;; Revision 1.74 2008/08/21 10:34:22 rubikitch
1051 ;; New function `anything-mklist'
1053 ;; Revision 1.73 2008/08/21 09:41:38 rubikitch
1054 ;; accept multiple init/cleanup functions so that plug-ins can add new function.
1056 ;; Revision 1.72 2008/08/20 22:51:53 rubikitch
1057 ;; New `anything-sources' attribute: candidate-number-limit
1059 ;; Revision 1.71 2008/08/20 21:45:42 rubikitch
1060 ;; added many tests.
1062 ;; Revision 1.70 2008/08/20 18:51:45 rubikitch
1063 ;; `anything-preselect' bug fix.
1064 ;; refactoring.
1066 ;; Revision 1.69 2008/08/20 17:57:51 rubikitch
1067 ;; Extended `anything' optional arguments: preselect
1069 ;; Revision 1.68 2008/08/20 16:39:07 rubikitch
1070 ;; Nested `anything' invocation support, ie. `anything' can be invoked by anything action.
1072 ;; (anything '(((name . "nested anything invocation test")
1073 ;; (candidates "anything-c-source-buffers" "anything-c-source-man-pages")
1074 ;; (display-to-real . intern)
1075 ;; (action . anything))))
1077 ;; Revision 1.67 2008/08/20 00:08:28 rubikitch
1078 ;; `anything-candidates-in-buffer-1': add code when pattern == ""
1080 ;; Revision 1.66 2008/08/19 23:31:52 rubikitch
1081 ;; Removed `anything-show-exact-match-first' because it should be provided as a plug-in.
1083 ;; Revision 1.65 2008/08/19 23:18:47 rubikitch
1084 ;; *** empty log message ***
1086 ;; Revision 1.64 2008/08/19 23:15:43 rubikitch
1087 ;; `anything-compute-matches': short-cut when match == '(identity)
1089 ;; Revision 1.63 2008/08/19 23:06:42 rubikitch
1090 ;; Use hash table to speed uniquify candidates.
1092 ;; Revision 1.62 2008/08/19 22:40:57 rubikitch
1093 ;; `anything-test-candidates': additional optonal argument
1095 ;; Revision 1.61 2008/08/19 18:13:39 rubikitch
1096 ;; search attribute: multiple search functions
1098 ;; Revision 1.60 2008/08/19 15:07:39 rubikitch
1099 ;; New function: `anything-attr'
1101 ;; Revision 1.59 2008/08/19 15:01:59 rubikitch
1102 ;; arranged code
1103 ;; added unit tests
1104 ;; update doc
1106 ;; Revision 1.58 2008/08/19 13:40:52 rubikitch
1107 ;; `anything-get-current-source': This function can be used in
1108 ;; init/candidates/action/candidate-transformer/filtered-candidate-transformer
1109 ;; display-to-real/cleanup function.
1111 ;; Revision 1.57 2008/08/19 03:43:57 rubikitch
1112 ;; `anything-process-delayed-sources': delay = anything-idle-delay - anything-input-idle-delay
1114 ;; Revision 1.56 2008/08/18 06:37:51 rubikitch
1115 ;; Make `anything-input-idle-delay' ineffective when the action list is shown.
1117 ;; Revision 1.55 2008/08/18 06:35:00 rubikitch
1118 ;; New variable: `anything-show-exact-match-first'
1120 ;; Revision 1.54 2008/08/17 23:22:24 rubikitch
1121 ;; *** empty log message ***
1123 ;; Revision 1.53 2008/08/17 23:15:38 rubikitch
1124 ;; bind `anything-source-name' when executing action to enable to use `anything-candidate-buffer' in action.
1126 ;; Revision 1.52 2008/08/17 15:21:27 rubikitch
1127 ;; `anything-test-candidates': accept a symbol for source
1128 ;; New variable: `anything-input-idle-delay'
1130 ;; Revision 1.51 2008/08/17 12:45:30 rubikitch
1131 ;; (buffer-disable-undo) in anything-buffer
1133 ;; Revision 1.50 2008/08/16 22:21:37 rubikitch
1134 ;; `anything-saved-sources': removed
1135 ;; `anything-action-buffer': action selection buffer
1136 ;; `anything-select-action': toggle actions <=> candidates
1138 ;; Revision 1.49 2008/08/16 19:46:11 rubikitch
1139 ;; New function: `anything-action-list-is-shown'
1141 ;; Revision 1.48 2008/08/16 17:03:02 rubikitch
1142 ;; bugfix: cleanup
1144 ;; Revision 1.47 2008/08/16 16:35:24 rubikitch
1145 ;; silence byte compiler
1147 ;; Revision 1.46 2008/08/16 14:51:27 rubikitch
1148 ;; *** empty log message ***
1150 ;; Revision 1.45 2008/08/16 11:27:59 rubikitch
1151 ;; refactoring
1152 ;; `anything-aif': Anaphoric if.
1153 ;; `anything-compile-source-functions': make `anything-get-sources' customizable.
1155 ;; Revision 1.44 2008/08/16 09:38:15 rubikitch
1156 ;; *** empty log message ***
1158 ;; Revision 1.43 2008/08/15 11:44:28 rubikitch
1159 ;; `anything-read-string-mode': minor mode for `anything' version of read functions. (experimental)
1161 ;; Revision 1.42 2008/08/15 11:03:20 rubikitch
1162 ;; update docs
1164 ;; Revision 1.41 2008/08/14 20:51:28 rubikitch
1165 ;; New `anything-sources' attribute: cleanup
1167 ;; Revision 1.40 2008/08/14 10:34:04 rubikitch
1168 ;; `anything': SOURCES: accept symbols
1170 ;; Revision 1.39 2008/08/10 22:46:01 rubikitch
1171 ;; `anything-move-selection': avoid infinite loop
1173 ;; Revision 1.38 2008/08/09 21:38:25 rubikitch
1174 ;; `anything-read-file-name': experimental implementation.
1176 ;; Revision 1.37 2008/08/09 17:54:25 rubikitch
1177 ;; action test
1179 ;; Revision 1.36 2008/08/09 17:13:00 rubikitch
1180 ;; fixed test
1182 ;; Revision 1.35 2008/08/09 10:43:08 rubikitch
1183 ;; New `anything-sources' attribute: display-to-real
1185 ;; Revision 1.34 2008/08/07 13:15:44 rubikitch
1186 ;; New `anything-sources' attribute: search
1188 ;; Revision 1.33 2008/08/05 23:14:20 rubikitch
1189 ;; `anything-candidate-buffer': bugfix
1191 ;; Revision 1.32 2008/08/05 21:42:15 rubikitch
1192 ;; *** empty log message ***
1194 ;; Revision 1.31 2008/08/05 21:06:23 rubikitch
1195 ;; `anything-candidate-buffer': candidates buffer registration
1197 ;; Revision 1.30 2008/08/05 19:46:36 rubikitch
1198 ;; New `anything-sources' attribute: candidates-in-buffer
1200 ;; Revision 1.29 2008/08/05 17:58:31 rubikitch
1201 ;; *** empty log message ***
1203 ;; Revision 1.28 2008/08/05 17:46:04 rubikitch
1204 ;; memoized `anything-get-sources'
1206 ;; Revision 1.27 2008/08/05 17:29:40 rubikitch
1207 ;; update doc
1209 ;; Revision 1.26 2008/08/05 08:35:45 rubikitch
1210 ;; `anything-completing-read': accept obarray
1212 ;; Revision 1.25 2008/08/05 07:26:17 rubikitch
1213 ;; `anything-completing-read': guard from non-string return value
1215 ;; Revision 1.24 2008/08/04 12:05:41 rubikitch
1216 ;; Wrote Tips and some docstrings.
1217 ;; `anything-candidate-buffer': buffer-local by default
1219 ;; Revision 1.23 2008/08/04 05:29:46 rubikitch
1220 ;; `anything-buffer-file-name': `buffer-file-name' when `anything' is invoked.
1222 ;; Revision 1.22 2008/08/04 00:10:13 rubikitch
1223 ;; `anything-candidate-buffer': new API
1225 ;; Revision 1.21 2008/08/03 22:05:08 rubikitch
1226 ;; `anything-candidate-buffer': Return a buffer containing candidates of current source.
1228 ;; Revision 1.20 2008/08/03 20:47:56 rubikitch
1229 ;; `anything-current-buffer-is-modified': modify checker
1231 ;; Revision 1.19 2008/08/03 19:06:18 rubikitch
1232 ;; `anything-candidates-in-buffer': use `with-current-buffer' instead.
1234 ;; Revision 1.18 2008/08/03 05:55:01 rubikitch
1235 ;; `anything-candidates-in-buffer': extract candidates in a buffer for speed.
1237 ;; Revision 1.17 2008/08/02 21:31:29 rubikitch
1238 ;; Extended `anything' optional arguments.
1239 ;; `anything-completing-read': experimental implementation.
1241 ;; Revision 1.16 2008/08/02 20:32:54 rubikitch
1242 ;; Extended `anything' optional arguments.
1244 ;; Revision 1.15 2008/08/02 16:53:40 rubikitch
1245 ;; Fixed a small bug of `anything-test-candidates'.
1247 ;; Revision 1.14 2008/08/02 16:48:29 rubikitch
1248 ;; Refactored to testable code.
1249 ;; Added many candidate tests with `anything-test-candidates'.
1251 ;; Revision 1.13 2008/08/02 15:08:14 rubikitch
1252 ;; *** empty log message ***
1254 ;; Revision 1.12 2008/08/02 14:29:31 rubikitch
1255 ;; `anything-sources' accepts symbols. (patched by Sugawara)
1257 ;; Revision 1.11 2008/08/02 10:20:36 rubikitch
1258 ;; `anything-resume' is usable with other (let-binded) `anything-sources'.
1260 ;; Revision 1.10 2008/08/01 19:44:01 rubikitch
1261 ;; `anything-resume': resurrect previously invoked `anything'.
1263 ;; Revision 1.9 2008/07/30 15:44:49 rubikitch
1264 ;; *** empty log message ***
1266 ;; Revision 1.8 2008/07/30 15:38:51 rubikitch
1267 ;; *** empty log message ***
1269 ;; Revision 1.7 2008/07/30 15:21:48 rubikitch
1270 ;; `anything-scroll-other-window', `anything-scroll-other-window-down':
1271 ;; Scroll other window (for persistent action).
1273 ;; Revision 1.6 2008/07/30 15:12:36 rubikitch
1274 ;; *** empty log message ***
1276 ;; Revision 1.5 2008/07/30 15:06:32 rubikitch
1277 ;; `anything-select-2nd-action', `anything-select-3rd-action', `anything-select-4th-action':
1278 ;; Select other than default action without pressing Tab.
1280 ;; Revision 1.4 2008/07/30 14:58:27 rubikitch
1281 ;; `anything-current-buffer': Store current buffer when `anything' is invoked.
1282 ;; `anything-current-position': Restore position when keyboard-quitted.
1284 ;; Revision 1.3 2008/07/30 14:38:04 rubikitch
1285 ;; Implemented persistent action.
1287 ;; Revision 1.2 2008/07/30 13:37:16 rubikitch
1288 ;; Update doc.
1290 ;; Revision 1.1 2008/07/30 13:22:06 rubikitch
1291 ;; New maintainer.
1294 ;; ugly hack to auto-update version
1295 (defvar anything-version nil)
1296 (setq anything-version "$Id: anything.el,v 1.280 2010-04-01 02:22:22 rubikitch Exp $")
1297 (require 'cl)
1299 ;; (@* "User Configuration")
1301 ;; This is only an example. Customize it to your own taste!
1302 (defvar anything-sources `(((name . "Buffers")
1303 (candidates
1304 . (lambda ()
1305 (remove-if (lambda (name)
1306 (or (equal name anything-buffer)
1307 (eq ?\ (aref name 0))))
1308 (mapcar 'buffer-name (buffer-list)))))
1309 (type . buffer))
1311 ((name . "File Name History")
1312 (candidates . file-name-history)
1313 (match (lambda (candidate)
1314 ;; list basename matches first
1315 (string-match
1316 anything-pattern
1317 (file-name-nondirectory candidate)))
1319 (lambda (candidate)
1320 ;; and then directory part matches
1321 (let ((dir (file-name-directory candidate)))
1322 (if dir
1323 (string-match anything-pattern dir)))))
1324 (type . file))
1326 ((name . "Files from Current Directory")
1327 (init . (lambda ()
1328 (setq anything-default-directory
1329 default-directory)))
1330 (candidates . (lambda ()
1331 (directory-files
1332 anything-default-directory)))
1333 (type . file))
1335 ((name . "Complex Command History")
1336 (candidates . (lambda ()
1337 (mapcar 'prin1-to-string
1338 command-history)))
1339 (action . (("Repeat Complex Command" .
1340 (lambda (c)
1341 (eval (read c))))))
1342 (delayed)))
1343 "The source of candidates for anything.
1344 It accepts symbols:
1345 (setq anything-sources (list anything-c-foo anything-c-bar))
1346 can be written as
1347 (setq anything-sources '(anything-c-foo anything-c-bar))
1348 The latter is recommended because if you change anything-c-* variable,
1349 you do not have to update `anything-sources'.
1351 You are STRONGLY recommended to define a command which calls
1352 `anything' or `anything-other-buffer' with argument rather than
1353 to set `anything-sources' externally.
1355 If you want to change `anything-sources' during `anything' invocation,
1356 use `anything-set-sources', never use `setq'.
1358 Attributes:
1363 ;; This value is only provided as an example. Customize it to your own
1364 ;; taste!
1365 (defvar anything-type-attributes
1366 '((file (action . (("Find File" . find-file)
1367 ("Delete File" . (lambda (file)
1368 (if (y-or-n-p (format "Really delete file %s? "
1369 file))
1370 (delete-file file)))))))
1371 (buffer (action . (("Switch to Buffer" . switch-to-buffer)
1372 ("Pop to Buffer" . pop-to-buffer)
1373 ("Display Buffer" . display-buffer)
1374 ("Kill Buffer" . kill-buffer)))))
1375 "It's a list of (TYPE ATTRIBUTES ...). ATTRIBUTES are the same
1376 as attributes for `anything-sources'. TYPE connects the value
1377 to the appropriate sources in `anything-sources'.
1379 This allows specifying common attributes for several
1380 sources. For example, sources which provide files can specify
1381 common attributes with a `file' type.")
1384 (defvar anything-enable-shortcuts nil
1385 "*Whether to use digit/alphabet shortcut to select the first nine matches.
1386 If t then they can be selected using Ctrl+<number>.
1387 If 'alphabet then they can be selected using Shift+<alphabet>.
1389 Keys (digit/alphabet) are listed in `anything-digit-shortcut-index-alist'.")
1391 (defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
1392 "Alphabet shortcuts are usable now. Then `anything-enable-digit-shortcuts' should be renamed.
1393 `anything-enable-digit-shortcuts' is retained for compatibility.")
1395 (defvar anything-shortcut-keys-alist
1396 '((alphabet . "asdfghjklzxcvbnmqwertyuiop")
1397 (t . "123456789")))
1399 (defvar anything-display-source-at-screen-top t
1400 "*If t, `anything-next-source' and `anything-previous-source'
1401 display candidates at the top of screen.")
1403 (defvar anything-candidate-number-limit 50
1404 "*Do not show more candidates than this limit from individual
1405 sources. It is usually pointless to show hundreds of matches
1406 when the pattern is empty, because it is much simpler to type a
1407 few characters to narrow down the list of potential candidates.
1409 Set it to nil if you don't want this limit.")
1412 (defvar anything-idle-delay 0.5
1413 "*The user has to be idle for this many seconds, before
1414 candidates from delayed sources are collected. This is useful
1415 for sources involving heavy operations (like launching external
1416 programs), so that candidates from the source are not retrieved
1417 unnecessarily if the user keeps typing.
1419 It also can be used to declutter the results anything displays,
1420 so that results from certain sources are not shown with every
1421 character typed, only if the user hesitates a bit.")
1424 (defvar anything-input-idle-delay 0.1
1425 "The user has to be idle for this many seconds, before ALL candidates are collected.
1426 Unlink `anything-input-idle', it is also effective for non-delayed sources.
1427 If nil, candidates are collected immediately. ")
1430 (defvar anything-samewindow nil
1431 "If t then Anything doesn't pop up a new window, it uses the
1432 current window to show the candidates.")
1435 (defvar anything-source-filter nil
1436 "A list of source names to be displayed. Other sources won't
1437 appear in the search results. If nil then there is no filtering.
1438 See also `anything-set-source-filter'.")
1441 (defvar anything-map
1442 (let ((map (copy-keymap minibuffer-local-map)))
1443 (define-key map (kbd "<down>") 'anything-next-line)
1444 (define-key map (kbd "<up>") 'anything-previous-line)
1445 (define-key map (kbd "C-n") 'anything-next-line)
1446 (define-key map (kbd "C-p") 'anything-previous-line)
1447 (define-key map (kbd "<prior>") 'anything-previous-page)
1448 (define-key map (kbd "<next>") 'anything-next-page)
1449 (define-key map (kbd "M-v") 'anything-previous-page)
1450 (define-key map (kbd "C-v") 'anything-next-page)
1451 (define-key map (kbd "M-<") 'anything-beginning-of-buffer)
1452 (define-key map (kbd "M->") 'anything-end-of-buffer)
1453 (define-key map (kbd "<right>") 'anything-next-source)
1454 (define-key map (kbd "<left>") 'anything-previous-source)
1455 (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
1456 (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
1457 (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
1458 (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
1459 (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
1460 (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
1461 (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
1462 (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
1463 (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
1464 (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
1465 (loop for c from ?A to ?Z do
1466 (define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
1467 (define-key map (kbd "C-i") 'anything-select-action)
1468 (define-key map (kbd "C-z") 'anything-execute-persistent-action)
1469 (define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
1470 (define-key map (kbd "C-j") 'anything-select-3rd-action)
1471 (define-key map (kbd "C-o") 'anything-next-source)
1472 (define-key map (kbd "C-M-v") 'anything-scroll-other-window)
1473 (define-key map (kbd "M-<next>") 'anything-scroll-other-window)
1474 (define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
1475 (define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
1476 (define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
1477 (define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
1478 (define-key map (kbd "M-[") 'anything-prev-visible-mark)
1479 (define-key map (kbd "M-]") 'anything-next-visible-mark)
1480 (define-key map (kbd "C-k") 'anything-delete-minibuffer-content)
1482 (define-key map (kbd "C-s") 'anything-isearch)
1483 (define-key map (kbd "C-r") 'undefined)
1484 (define-key map (kbd "C-t") 'anything-toggle-resplit-window)
1485 (define-key map (kbd "C-x C-f") 'anything-quit-and-find-file)
1487 (define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
1488 (define-key map (kbd "C-c C-y") 'anything-yank-selection)
1489 (define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
1490 (define-key map (kbd "C-c C-f") 'anything-follow-mode)
1491 (define-key map (kbd "C-c C-u") 'anything-force-update)
1493 ;; Use `describe-mode' key in `global-map'
1494 (dolist (k (where-is-internal 'describe-mode global-map))
1495 (define-key map k 'anything-help))
1496 ;; the defalias is needed because commands are bound by name when
1497 ;; using iswitchb, so only commands having the prefix anything-
1498 ;; get rebound
1499 (defalias 'anything-previous-history-element 'previous-history-element)
1500 (defalias 'anything-next-history-element 'next-history-element)
1501 (define-key map (kbd "M-p") 'anything-previous-history-element)
1502 (define-key map (kbd "M-n") 'anything-next-history-element)
1503 map)
1504 "Keymap for anything.
1506 If you execute `anything-iswitchb-setup', some keys are modified.
1507 See `anything-iswitchb-setup-keys'.")
1509 (defvar anything-isearch-map
1510 (let ((map (make-sparse-keymap)))
1511 (set-keymap-parent map (current-global-map))
1512 (define-key map (kbd "<return>") 'anything-isearch-default-action)
1513 (define-key map (kbd "<RET>") 'anything-isearch-default-action)
1514 (define-key map (kbd "C-i") 'anything-isearch-select-action)
1515 (define-key map (kbd "C-g") 'anything-isearch-cancel)
1516 (define-key map (kbd "M-s") 'anything-isearch-again)
1517 (define-key map (kbd "<backspace>") 'anything-isearch-delete)
1518 ;; add printing chars
1519 (loop for i from 32 below 256 do
1520 (define-key map (vector i) 'anything-isearch-printing-char))
1521 map)
1522 "Keymap for anything incremental search.")
1525 (defgroup anything nil
1526 "Open anything." :prefix "anything-" :group 'convenience)
1528 (defface anything-header
1529 '((t (:inherit header-line)))
1530 "Face for header lines in the anything buffer." :group 'anything)
1532 (defvar anything-header-face 'anything-header
1533 "Face for header lines in the anything buffer.")
1535 (defface anything-isearch-match '((t (:background "Yellow")))
1536 "Face for isearch in the anything buffer." :group 'anything)
1538 (defvar anything-isearch-match-face 'anything-isearch-match
1539 "Face for matches during incremental search.")
1541 (defvar anything-selection-face 'highlight
1542 "Face for currently selected item.")
1544 (defvar anything-iswitchb-idle-delay 1
1545 "Show anything completions if the user is idle that many
1546 seconds after typing.")
1548 (defvar anything-iswitchb-dont-touch-iswithcb-keys nil
1549 "If t then those commands are not bound from `anything-map'
1550 under iswitchb which would override standard iswithcb keys.
1552 This allows an even more seamless integration with iswitchb for
1553 those who prefer using iswitchb bindings even if the anything
1554 completions buffer is popped up.
1556 Note that you can bind alternative keys for the same command in
1557 `anything-map', so that you can use different keys for anything
1558 under iswitchb. For example, I bind the character \ to
1559 `anything-exit-minibuffer' which key is just above Enter on my
1560 keyboard. This way I can switch buffers with Enter and choose
1561 anything completions with \.")
1563 ;;----------------------------------------------------------------------
1565 (defvar anything-buffer "*anything*"
1566 "Buffer showing completions.")
1568 (defvar anything-action-buffer "*anything action*"
1569 "Buffer showing actions.")
1571 (defvar anything-selection-overlay nil
1572 "Overlay used to highlight the currently selected item.")
1574 (defvar anything-isearch-overlay nil
1575 "Overlay used to highlight the current match during isearch.")
1577 (defvar anything-digit-overlays nil
1578 "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
1580 (defvar anything-candidate-cache nil
1581 "Holds the available candidate withing a single anything invocation.")
1583 (defvar anything-pattern
1584 "The input pattern used to update the anything buffer.")
1586 (defvar anything-input
1587 "The input typed in the candidates panel.")
1589 (defvar anything-async-processes nil
1590 "List of information about asynchronous processes managed by anything.")
1592 (defvar anything-digit-shortcut-count 0
1593 "Number of digit shortcuts shown in the anything buffer.")
1595 (defvar anything-before-initialize-hook nil
1596 "Run before anything initialization.
1597 This hook is run before init functions in `anything-sources'.")
1599 (defvar anything-after-initialize-hook nil
1600 "Run after anything initialization.
1601 Global variables are initialized and the anything buffer is created.
1602 But the anything buffer has no contents. ")
1604 (defvar anything-update-hook nil
1605 "Run after the anything buffer was updated according the new
1606 input pattern.")
1608 (defvar anything-cleanup-hook nil
1609 "Run after anything minibuffer is closed, IOW this hook is executed BEFORE performing action. ")
1611 (defvar anything-after-action-hook nil
1612 "Run after executing action.")
1614 (defvar anything-after-persistent-action-hook nil
1615 "Run after executing persistent action.")
1617 (defvar anything-restored-variables
1618 '( anything-candidate-number-limit
1619 anything-source-filter)
1620 "Variables which are restored after `anything' invocation.")
1621 ;; `anything-saved-sources' is removed
1623 (defvar anything-saved-selection nil
1624 "Saved value of the currently selected object when the action
1625 list is shown.")
1627 ;; `anything-original-source-filter' is removed
1629 (defvar anything-candidate-separator
1630 "--------------------"
1631 "Candidates separator of `multiline' source.")
1633 (defvar anything-current-buffer nil
1634 "Current buffer when `anything' is invoked.")
1636 (defvar anything-buffer-file-name nil
1637 "`buffer-file-name' when `anything' is invoked.")
1639 (defvar anything-current-position nil
1640 "Cons of (point) and (window-start) when `anything' is invoked.
1641 It is needed because restoring position when `anything' is keyboard-quitted.")
1643 (defvar anything-saved-action nil
1644 "Saved value of the currently selected action by key.")
1646 (defvar anything-last-sources nil
1647 "OBSOLETE!! Sources of previously invoked `anything'.")
1649 (defvar anything-saved-current-source nil
1650 "Saved value of the original (anything-get-current-source) when the action
1651 list is shown.")
1653 (defvar anything-compiled-sources nil
1654 "Compiled version of `anything-sources'. ")
1656 (defvar anything-in-persistent-action nil
1657 "Flag whether in persistent-action or not.")
1659 (defvar anything-quick-update nil
1660 "If non-nil, suppress displaying sources which are out of screen at first.
1661 They are treated as delayed sources at this input.
1662 This flag makes `anything' a bit faster with many sources.")
1664 (defvar anything-last-sources-local nil
1665 "Buffer local value of `anything-sources'.")
1666 (defvar anything-last-buffer nil
1667 "`anything-buffer' of previously `anything' session.")
1669 (defvar anything-save-configuration-functions
1670 '(set-window-configuration . current-window-configuration)
1671 "If you want to save and restore frame configuration, set this variable to
1672 '(set-frame-configuration . current-frame-configuration)
1674 Older version saves/restores frame configuration, but the default is changed now,
1675 because flickering is occurred in some environment.
1678 (defvar anything-persistent-action-use-special-display nil
1679 "If non-nil, use `special-display-function' in persistent action.")
1681 (defvar anything-execute-action-at-once-if-one nil
1682 "If non-nil and there is one candidate, execute the first action without selection.
1683 It is useful for `anything' applications.")
1685 (defvar anything-quit-if-no-candidate nil
1686 "if non-nil and there is no candidate, do not display *anything* buffer and quit.
1687 This variable accepts a function, which is executed if no candidate.
1689 It is useful for `anything' applications.")
1691 (defvar anything-scroll-amount nil
1692 "Scroll amount used by `anything-scroll-other-window' and `anything-scroll-other-window-down'.
1693 If you prefer scrolling line by line, set this value to 1.")
1695 (defvar anything-display-function 'anything-default-display-buffer
1696 "Function to display *anything* buffer.
1697 It is `anything-default-display-buffer' by default, which affects `anything-samewindow'.")
1699 (defvar anything-delayed-init-executed nil)
1701 (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"
1702 "Help string displayed in mode-line in `anything'.
1703 If nil, use default `mode-line-format'.")
1705 (defvar anything-help-message
1706 "\\<anything-map>The keys that are defined for `anything' are:
1707 \\{anything-map}"
1708 "Detailed help message string for `anything'.")
1710 (put 'anything 'timid-completion 'disabled)
1712 (defvar anything-inhibit-fit-frame-flag t
1713 "If non-nil, inhibit fitting anything frame to its buffer.
1714 It is nil by default because some flickering occurred in some environment.
1716 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
1717 `fit-frame-inhibit-fitting' to nil.")
1719 ;; (@* "Internal Variables")
1720 (defvar anything-test-candidate-list nil)
1721 (defvar anything-test-mode nil)
1722 (defvar anything-source-name nil)
1723 (defvar anything-candidate-buffer-alist nil)
1724 (defvar anything-check-minibuffer-input-timer nil)
1725 (defvar anything-match-hash (make-hash-table :test 'equal))
1726 (defvar anything-cib-hash (make-hash-table :test 'equal))
1727 (defvar anything-tick-hash (make-hash-table :test 'equal))
1728 (defvar anything-issued-errors nil)
1729 (defvar anything-shortcut-keys nil)
1732 ;; (@* "Programming Tools")
1733 (defmacro anything-aif (test-form then-form &rest else-forms)
1734 "Anaphoric if. Temporary variable `it' is the result of test-form."
1735 `(let ((it ,test-form))
1736 (if it ,then-form ,@else-forms)))
1737 (put 'anything-aif 'lisp-indent-function 2)
1739 (defun anything-mklist (obj)
1740 "If OBJ is a list, return itself, otherwise make a list with one element."
1741 (if (listp obj) obj (list obj)))
1743 ;; (@* "Anything API")
1744 (defun anything-buffer-get ()
1745 "If *anything action* buffer is shown, return `anything-action-buffer', otherwise `anything-buffer'."
1746 (if (anything-action-window)
1747 anything-action-buffer
1748 anything-buffer))
1750 (defun anything-window ()
1751 "Window of `anything-buffer'."
1752 (get-buffer-window (anything-buffer-get) 'visible))
1754 (defun anything-action-window ()
1755 "Window of `anything-action-buffer'."
1756 (get-buffer-window anything-action-buffer 'visible))
1758 (defmacro with-anything-window (&rest body)
1759 `(let ((--tmpfunc-- (lambda () ,@body)))
1760 (if anything-test-mode
1761 (with-current-buffer (anything-buffer-get)
1762 (funcall --tmpfunc--))
1763 (with-selected-window (anything-window)
1764 (funcall --tmpfunc--)))))
1765 (put 'with-anything-window 'lisp-indent-function 0)
1767 (defmacro with-anything-restore-variables(&rest body)
1768 "Restore variables specified by `anything-restored-variables' after executing BODY ."
1769 `(let ((--orig-vars (mapcar (lambda (v) (cons v (symbol-value v))) anything-restored-variables)))
1770 (unwind-protect (progn ,@body)
1771 (loop for (var . value) in --orig-vars
1772 do (set var value)))))
1773 (put 'with-anything-restore-variables 'lisp-indent-function 0)
1775 (defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
1776 "Get the value of ATTRIBUTE-NAME of SRC (source).
1777 if SRC is omitted, use current source.
1778 It is useful to write your sources."
1779 (anything-aif (assq attribute-name src)
1780 (cdr it)))
1782 (defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
1783 "Return non-nil if ATTRIBUTE-NAME of SRC (source) is defined.
1784 if SRC is omitted, use current source.
1785 It is useful to write your sources."
1786 (and (assq attribute-name src) t))
1788 (defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
1789 "Set the value of ATTRIBUTE-NAME of SRC (source) to VALUE.
1790 if SRC is omitted, use current source.
1791 It is useful to write your sources."
1792 (anything-aif (assq attribute-name src)
1793 (setcdr it value)
1794 (setcdr src (cons (cons attribute-name value) (cdr src))))
1795 value)
1797 ;; anything-set-source-filter
1799 ;; This function sets a filter for anything sources and it may be
1800 ;; called while anything is running. It can be used to toggle
1801 ;; displaying of sources dinamically. For example, additional keys
1802 ;; can be bound into `anything-map' to display only the file-related
1803 ;; results if there are too many matches from other sources and
1804 ;; you're after files only:
1806 ;; Shift+F shows only file results from some sources:
1808 ;; (define-key anything-map "F" 'anything-my-show-files-only)
1810 ;; (defun anything-my-show-files-only ()
1811 ;; (interactive)
1812 ;; (anything-set-source-filter '("File Name History"
1813 ;; "Files from Current Directory")))
1815 ;; Shift+A shows all results:
1817 ;; (define-key anything-map "A" 'anything-my-show-all)
1819 ;; (defun anything-my-show-all ()
1820 ;; (interactive)
1821 ;; (anything-set-source-filter nil))
1824 ;; Note that you have to prefix the functions with anything- prefix,
1825 ;; otherwise they won't be bound when Anything is used under
1826 ;; Iswitchb. The -my- part is added to avoid collisions with
1827 ;; existing Anything function names.
1829 (defun anything-set-source-filter (sources)
1830 "Sets the value of `anything-source-filter' and updates the list of results."
1831 (unless (and (listp sources)
1832 (loop for name in sources always (stringp name)))
1833 (error "invalid data in `anything-set-source-filter': %S" sources))
1834 (setq anything-source-filter sources)
1835 (anything-update))
1837 (defun anything-set-sources (sources &optional no-init no-update)
1838 "Set `anything-sources' during `anything' invocation.
1839 If NO-INIT is non-nil, skip executing init functions of SOURCES.
1840 If NO-UPDATE is non-nil, skip executing `anything-update'."
1841 (setq anything-compiled-sources nil
1842 anything-sources sources)
1843 (unless no-init (anything-funcall-foreach 'init))
1844 (unless no-update (anything-update)))
1846 (defvar anything-compile-source-functions
1847 '(anything-compile-source--type
1848 anything-compile-source--dummy
1849 anything-compile-source--disable-shortcuts
1850 anything-compile-source--candidates-in-buffer)
1851 "Functions to compile elements of `anything-sources' (plug-in).")
1853 (defun anything-get-sources ()
1854 "Return compiled `anything-sources', which is memoized.
1856 Attributes:
1858 - type
1859 `anything-type-attributes' are merged in.
1860 - candidates-buffer
1861 candidates, volatile and match attrubute are created.
1863 (cond
1864 ;; action
1865 ((anything-action-window)
1866 anything-sources)
1867 ;; memoized
1868 (anything-compiled-sources)
1869 ;; first time
1871 (setq anything-compiled-sources
1872 (anything-compile-sources anything-sources anything-compile-source-functions)))))
1874 (defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
1875 "Return the currently selected item or nil.
1876 if BUFFER is nil or unspecified, use anything-buffer as default value.
1877 If FORCE-DISPLAY-PART is non-nil, return the display string."
1878 (setq buffer (if (and buffer buffer-s) buffer anything-buffer))
1879 (unless (zerop (buffer-size (get-buffer buffer)))
1880 (with-current-buffer buffer
1881 (let ((selection
1882 (or (and (not force-display-part)
1883 (get-text-property (overlay-start
1884 anything-selection-overlay)
1885 'anything-realvalue))
1886 (buffer-substring-no-properties
1887 (overlay-start anything-selection-overlay)
1888 (1- (overlay-end anything-selection-overlay))))))
1889 (unless (equal selection "")
1890 selection)))))
1892 (defun anything-get-action ()
1893 "Return the associated action for the selected candidate."
1894 (unless (zerop (buffer-size (get-buffer (anything-buffer-get))))
1895 (let* ((source (anything-get-current-source))
1896 (actions (assoc-default 'action source)))
1898 (anything-aif (assoc-default 'action-transformer source)
1899 ;; (funcall it actions (anything-get-selection))
1900 (anything-composed-funcall-with-source source it actions (anything-get-selection))
1901 actions))))
1903 (defun anything-get-current-source ()
1904 "Return the source for the current selection / in init/candidates/action/candidate-transformer/filtered-candidate-transformer function."
1905 (declare (special source))
1906 ;; The name `anything-get-current-source' should be used in init function etc.
1907 (if (and (boundp 'anything-source-name) (stringp anything-source-name))
1908 source
1909 (block exit
1910 (with-current-buffer (anything-buffer-get)
1911 ;; This goto-char shouldn't be necessary, but point is moved to
1912 ;; point-min somewhere else which shouldn't happen.
1913 (goto-char (overlay-start anything-selection-overlay))
1914 (let* ((header-pos (anything-get-previous-header-pos))
1915 (source-name
1916 (save-excursion
1917 (unless header-pos
1918 (message "No candidates")
1919 (return-from exit nil))
1920 (goto-char header-pos)
1921 (buffer-substring-no-properties
1922 (line-beginning-position) (line-end-position)))))
1923 (some (lambda (source)
1924 (if (equal (assoc-default 'name source)
1925 source-name)
1926 source))
1927 (anything-get-sources)))))))
1929 (defun anything-buffer-is-modified (buffer)
1930 "Return non-nil when BUFFER is modified since `anything' was invoked."
1931 (let* ((b (get-buffer buffer))
1932 (key (concat (buffer-name b)
1934 (anything-attr 'name)))
1935 (source-tick (or (gethash key anything-tick-hash) 0))
1936 (buffer-tick (buffer-chars-modified-tick b)))
1937 (prog1 (/= source-tick buffer-tick)
1938 (puthash key buffer-tick anything-tick-hash))))
1939 (defun anything-current-buffer-is-modified ()
1940 "Return non-nil when `anything-current-buffer' is modified since `anything' was invoked."
1941 (anything-buffer-is-modified anything-current-buffer))
1943 (defvar anything-quit nil)
1944 (defun anything-run-after-quit (function &rest args)
1945 "Perform an action after quitting `anything'.
1946 The action is to call FUNCTION with arguments ARGS."
1947 (setq anything-quit t)
1948 (apply 'run-with-idle-timer 0 nil function args)
1949 (anything-exit-minibuffer))
1951 (defun define-anything-type-attribute (type definition &optional doc)
1952 "Register type attribute of TYPE as DEFINITION with DOC.
1953 DOC is displayed in `anything-type-attributes' docstring.
1955 Use this function is better than setting `anything-type-attributes' directly."
1956 (anything-add-type-attribute type definition)
1957 (and doc (anything-document-type-attribute type doc))
1958 nil)
1960 (defvar anything-additional-attributes nil
1961 "List of all `anything' attributes.")
1962 (defvaralias 'anything-attributes 'anything-additional-attributes)
1963 (defun anything-document-attribute (attribute short-doc &optional long-doc)
1964 "Register ATTRIBUTE documentation introduced by plug-in.
1965 SHORT-DOC is displayed beside attribute name.
1966 LONG-DOC is displayed below attribute name and short documentation."
1967 (if long-doc
1968 (setq short-doc (concat "(" short-doc ")"))
1969 (setq long-doc short-doc
1970 short-doc ""))
1971 (add-to-list 'anything-additional-attributes attribute t)
1972 (put attribute 'anything-attrdoc
1973 (concat "- " (symbol-name attribute) " " short-doc "\n\n" long-doc "\n")))
1974 (put 'anything-document-attribute 'lisp-indent-function 2)
1976 (defun anything-require-at-least-version (version)
1977 "Output error message unless anything.el is older than VERSION.
1978 This is suitable for anything applications."
1979 (when (and (string= "1." (substring version 0 2))
1980 (string-match "1\.\\([0-9]+\\)" anything-version)
1981 (< (string-to-number (match-string 1 anything-version))
1982 (string-to-number (substring version 2))))
1983 (error "Please update anything.el!!
1985 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
1987 or M-x install-elisp-from-emacswiki anything.el")))
1989 (defun anything-interpret-value (value &optional source)
1990 "interpret VALUE as variable, function or literal.
1991 If VALUE is a function, call it with no arguments and return the value.
1992 If SOURCE is `anything' source, `anything-source-name' is source name.
1994 If VALUE is a variable, return the value.
1996 If VALUE is a symbol, but it is not a function or a variable, cause an error.
1998 Otherwise, return VALUE itself."
1999 (cond ((and source (functionp value))
2000 (anything-funcall-with-source source value))
2001 ((functionp value)
2002 (funcall value))
2003 ((and (symbolp value) (boundp value))
2004 (symbol-value value))
2005 ((symbolp value)
2006 (error "anything-interpret-value: Symbol must be a function or a variable"))
2008 value)))
2010 ;; (@* "Core: tools")
2011 (defun anything-current-frame/window-configuration ()
2012 (funcall (cdr anything-save-configuration-functions)))
2014 (defun anything-set-frame/window-configuration (conf)
2015 (funcall (car anything-save-configuration-functions) conf))
2017 (defun anything-funcall-with-source (source func &rest args)
2018 (let ((anything-source-name (assoc-default 'name source)))
2019 (apply func args)))
2021 (defun anything-funcall-foreach (sym)
2022 "Call the sym function(s) for each source if any."
2023 (dolist (source (anything-get-sources))
2024 (when (symbolp source)
2025 (setq source (symbol-value source)))
2026 (anything-aif (assoc-default sym source)
2027 (dolist (func (if (functionp it) (list it) it))
2028 (anything-funcall-with-source source func)))))
2030 (defun anything-normalize-sources (sources)
2031 "If SOURCES is only one source, make a list."
2032 (cond ((or (and sources ; avoid nil
2033 (symbolp sources))
2034 (and (listp sources) (assq 'name sources)))
2035 (list sources))
2036 (sources)
2037 (t anything-sources)))
2039 (defun anything-approximate-candidate-number ()
2040 "Approximate Number of candidates.
2041 It is used to check if candidate number is 0, 1, or 2+."
2042 (with-current-buffer anything-buffer
2043 (let ((lines (1- (line-number-at-pos (1- (point-max))))))
2044 (if (zerop lines)
2046 (save-excursion
2047 (goto-char (point-min))
2048 (forward-line 1)
2049 (if (anything-pos-multiline-p)
2050 (if (search-forward anything-candidate-separator nil t) 2 1)
2051 lines))))))
2053 (defmacro with-anything-quittable (&rest body)
2054 `(let (inhibit-quit)
2055 (condition-case v
2056 (progn ,@body)
2057 (quit (setq anything-quit t)
2058 (exit-minibuffer)
2059 (keyboard-quit)))))
2060 (put 'with-anything-quittable 'lisp-indent-function 0)
2062 (defun anything-compose (arg-lst func-lst)
2063 "Call each function in FUNC-LST with the arguments specified in ARG-LST.
2064 The result of each function will be the new `car' of ARG-LST.
2066 This function allows easy sequencing of transformer functions."
2067 (dolist (func func-lst)
2068 (setcar arg-lst (apply func arg-lst)))
2069 (car arg-lst))
2071 (defun anything-composed-funcall-with-source (source funcs &rest args)
2072 (if (functionp funcs)
2073 (apply 'anything-funcall-with-source source funcs args)
2074 (apply 'anything-funcall-with-source
2075 source (lambda (&rest args) (anything-compose args funcs)) args)))
2077 ;; (@* "Core: entry point")
2078 (defvar anything-buffers nil
2079 "All of `anything-buffer' in most recently used order.")
2081 (defun anything (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap)
2082 "Select anything. In Lisp program, some optional arguments can be used.
2084 Note that all the optional arguments are prefixed because of
2085 dynamic scope problem, IOW argument variables may eat
2086 already-bound variables. Yuck!
2088 - ANY-SOURCES
2090 Temporary value of `anything-sources'. It also accepts a
2091 symbol, interpreted as a variable of an anything source. It
2092 also accepts an alist representing an anything source, which is
2093 detected by (assq 'name ANY-SOURCES)
2096 - ANY-INPUT
2098 Temporary value of `anything-pattern', ie. initial input of minibuffer.
2100 - ANY-PROMPT
2102 Prompt other than \"pattern: \".
2104 - ANY-RESUME
2106 If t, Resurrect previously instance of `anything'. Skip the initialization.
2107 If 'noresume, this instance of `anything' cannot be resumed.
2109 - ANY-PRESELECT
2111 Initially selected candidate. Specified by exact candidate or a regexp.
2112 Note that it is not working with delayed sources.
2114 - ANY-BUFFER
2116 `anything-buffer' instead of *anything*.
2118 - ANY-KEYMAP
2120 `anything-map' for current `anything' session.
2122 ;; TODO more document
2123 (interactive)
2124 (condition-case v
2125 (with-anything-restore-variables
2126 (let ((frameconfig (anything-current-frame/window-configuration))
2127 ;; It is needed because `anything-source-name' is non-nil
2128 ;; when `anything' is invoked by action. Awful global scope.
2129 anything-source-name anything-in-persistent-action
2130 anything-quit anything-follow-mode
2131 (case-fold-search t)
2132 (anything-buffer (or any-buffer anything-buffer))
2133 (anything-sources (anything-normalize-sources any-sources))
2134 (anything-map (or any-keymap anything-map)))
2135 (anything-initialize-1 any-resume any-input)
2136 (anything-hooks 'setup)
2137 (if (eq any-resume t)
2138 (condition-case x
2139 (anything-window-configuration 'set)
2140 (error (anything-display-buffer anything-buffer)))
2141 (anything-display-buffer anything-buffer))
2142 (unwind-protect
2143 (anything-read-pattern-maybe any-prompt any-input any-preselect any-resume)
2144 (anything-cleanup)
2145 (anything-hooks 'cleanup)
2146 (anything-set-frame/window-configuration frameconfig))
2147 (unless anything-quit
2148 (anything-execute-selection-action-1))))
2149 (quit
2150 (anything-on-quit)
2151 nil)))
2153 (defun anything-initialize-1 (any-resume any-input)
2154 (setq anything-current-position (cons (point) (window-start)))
2155 (if (eq any-resume t)
2156 (anything-initialize-overlays (anything-buffer-get))
2157 (anything-initialize))
2158 (unless (eq any-resume 'noresume)
2159 (anything-recent-push anything-buffer 'anything-buffers)
2160 (setq anything-last-buffer anything-buffer))
2161 (when any-input (setq anything-input any-input anything-pattern any-input))
2162 (and (eq any-resume t) (anything-funcall-foreach 'resume)))
2164 (defun anything-execute-selection-action-1 ()
2165 (unwind-protect
2166 (anything-execute-selection-action)
2167 (anything-aif (get-buffer anything-action-buffer)
2168 (kill-buffer it))
2169 (run-hooks 'anything-after-action-hook)))
2171 (defun anything-on-quit ()
2172 (setq minibuffer-history (cons anything-input minibuffer-history))
2173 (goto-char (car anything-current-position))
2174 (set-window-start (selected-window) (cdr anything-current-position)))
2176 (defun anything-resume-select-buffer (input)
2177 (anything '(((name . "Resume anything buffer")
2178 (candidates . anything-buffers)
2179 (action . identity)))
2180 input nil 'noresume nil "*anything resume*"))
2182 (defun* anything-resume (&optional (any-buffer anything-last-buffer) buffer-pattern)
2183 "Resurrect previously invoked `anything'."
2184 (interactive)
2185 (when (or current-prefix-arg buffer-pattern)
2186 (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
2187 (setq anything-compiled-sources nil)
2188 (anything
2189 (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
2190 anything-last-sources anything-sources)
2191 (buffer-local-value 'anything-input-local (get-buffer any-buffer)) nil t nil any-buffer))
2193 (defvar anything-window-configuration nil)
2194 ;;; (set-window-configuration (buffer-local-value 'anything-window-configuration (get-buffer "*anything buffers*")))
2195 (defun anything-window-configuration (store-or-set)
2196 (case store-or-set
2197 ('store
2198 (with-current-buffer anything-buffer
2199 (set (make-local-variable 'anything-window-configuration)
2200 (current-window-configuration))))
2201 ('set
2202 (with-current-buffer anything-buffer
2203 (set-window-configuration anything-window-configuration))
2204 (select-window (anything-window)))))
2206 (defun anything-recent-push (elt list-var)
2207 "Add ELT to the value of LIST-VAR as most recently used value."
2208 (let ((m (member elt (symbol-value list-var))))
2209 (and m (set list-var (delq (car m) (symbol-value list-var))))
2210 (push elt (symbol-value list-var))))
2212 (defun anything-at-point (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
2213 "Same as `anything' except when C-u is pressed, the initial input is the symbol at point."
2214 (interactive)
2215 (anything any-sources
2216 (if current-prefix-arg
2217 (concat "\\b" (thing-at-point 'symbol) "\\b"
2218 (if (featurep 'anything-match-plugin) " " ""))
2219 any-input)
2220 any-prompt any-resume any-preselect any-buffer))
2222 (defun anything-other-buffer (any-sources any-buffer)
2223 "Simplified interface of `anything' with other `anything-buffer'"
2224 (anything any-sources nil nil nil nil any-buffer))
2226 ;; (@* "Core: Display *anything* buffer")
2227 (defun anything-display-buffer (buf)
2228 "Display *anything* buffer."
2229 (funcall anything-display-function buf))
2231 (defun anything-default-display-buffer (buf)
2232 (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
2234 ;; (@* "Core: initialize")
2235 (defun anything-initialize ()
2236 "Initialize anything settings and set up the anything buffer."
2237 (run-hooks 'anything-before-initialize-hook)
2238 (setq anything-delayed-init-executed nil)
2239 (setq anything-current-buffer (current-buffer))
2240 (setq anything-buffer-file-name buffer-file-name)
2241 (setq anything-issued-errors nil)
2242 (setq anything-compiled-sources nil)
2243 (setq anything-saved-current-source nil)
2244 ;; Call the init function for sources where appropriate
2245 (anything-funcall-foreach 'init)
2247 (setq anything-pattern "")
2248 (setq anything-input "")
2249 (setq anything-candidate-cache nil)
2250 (setq anything-last-sources anything-sources)
2252 (anything-create-anything-buffer)
2253 (run-hooks 'anything-after-initialize-hook))
2255 (defun anything-read-pattern-maybe (any-prompt any-input any-preselect any-resume)
2256 (if (eq any-resume t) (anything-mark-current-line) (anything-update))
2257 (select-frame-set-input-focus (window-frame (minibuffer-window)))
2258 (anything-preselect any-preselect)
2259 (let ((ncandidate (anything-approximate-candidate-number))
2260 (minibuffer-local-map anything-map))
2261 (cond ((and anything-execute-action-at-once-if-one
2262 (= ncandidate 1))
2263 (ignore))
2264 ((and anything-quit-if-no-candidate (= ncandidate 0))
2265 (setq anything-quit t)
2266 (and (functionp anything-quit-if-no-candidate)
2267 (funcall anything-quit-if-no-candidate)))
2269 (read-string (or any-prompt "pattern: ") any-input)))))
2271 (defun anything-create-anything-buffer (&optional test-mode)
2272 "Create newly created `anything-buffer'.
2273 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
2274 (when test-mode
2275 (setq anything-candidate-cache nil))
2276 (with-current-buffer (get-buffer-create anything-buffer)
2277 (buffer-disable-undo)
2278 (erase-buffer)
2279 (set (make-local-variable 'inhibit-read-only) t)
2280 (set (make-local-variable 'anything-last-sources-local) anything-sources)
2282 (setq cursor-type nil)
2283 (setq mode-name "Anything"))
2284 (anything-initialize-overlays anything-buffer)
2285 (get-buffer anything-buffer))
2287 (defun anything-initialize-overlays (buffer)
2288 (if anything-selection-overlay
2289 ;; make sure the overlay belongs to the anything buffer if
2290 ;; it's newly created
2291 (move-overlay anything-selection-overlay (point-min) (point-min)
2292 (get-buffer buffer))
2294 (setq anything-selection-overlay
2295 (make-overlay (point-min) (point-min) (get-buffer buffer)))
2296 (overlay-put anything-selection-overlay 'face anything-selection-face))
2298 (when anything-enable-shortcuts
2299 (setq anything-shortcut-keys (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist)))
2301 (if anything-enable-shortcuts
2302 (unless anything-digit-overlays
2303 (setq anything-digit-overlays
2304 (loop for key across anything-shortcut-keys
2305 for overlay = (make-overlay (point-min) (point-min) (get-buffer buffer))
2306 do (overlay-put overlay 'before-string
2307 (format "%s - " (upcase (make-string 1 key))))
2308 collect overlay)))
2310 (when anything-digit-overlays
2311 (dolist (overlay anything-digit-overlays)
2312 (delete-overlay overlay))
2313 (setq anything-digit-overlays nil))))
2315 (defun anything-hooks (setup-or-cleanup)
2316 (let ((hooks '((post-command-hook anything-check-minibuffer-input)
2317 (minibuffer-setup-hook anything-print-error-messages)
2318 (minibuffer-exit-hook (lambda () (anything-window-configuration 'store))))))
2319 (if (eq setup-or-cleanup 'setup)
2320 (dolist (args hooks) (apply 'add-hook args))
2321 (dolist (args (reverse hooks)) (apply 'remove-hook args)))))
2323 ;; (@* "Core: clean up")
2324 (defun anything-cleanup ()
2325 "Clean up the mess."
2326 (with-current-buffer anything-buffer
2327 (setq cursor-type t))
2328 (bury-buffer anything-buffer)
2329 (anything-funcall-foreach 'cleanup)
2330 (if anything-check-minibuffer-input-timer
2331 (cancel-timer anything-check-minibuffer-input-timer))
2332 (anything-kill-async-processes)
2333 (run-hooks 'anything-cleanup-hook))
2335 ;; (@* "Core: input handling")
2336 (defun anything-check-minibuffer-input ()
2337 "Extract input string from the minibuffer and check if it needs
2338 to be handled."
2339 (if (or (not anything-input-idle-delay) (anything-action-window))
2340 (anything-check-minibuffer-input-1)
2341 (if anything-check-minibuffer-input-timer
2342 (cancel-timer anything-check-minibuffer-input-timer))
2343 (setq anything-check-minibuffer-input-timer
2344 (run-with-idle-timer anything-input-idle-delay nil
2345 'anything-check-minibuffer-input-1))))
2347 (defun anything-check-minibuffer-input-1 ()
2348 (with-anything-quittable
2349 (with-selected-window (minibuffer-window)
2350 (anything-check-new-input (minibuffer-contents)))))
2352 (defun anything-check-new-input (input)
2353 "Check input string and update the anything buffer if
2354 necessary."
2355 (unless (equal input anything-pattern)
2356 (setq anything-pattern input)
2357 (unless (anything-action-window)
2358 (setq anything-input anything-pattern))
2359 (anything-update)))
2361 ;; (@* "Core: source compiler")
2362 (defvar anything-compile-source-functions-default anything-compile-source-functions
2363 "Plug-ins this file provides.")
2364 (defun anything-compile-sources (sources funcs)
2365 "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
2366 Anything plug-ins are realized by this function."
2367 (mapcar
2368 (lambda (source)
2369 (loop with source = (if (listp source) source (symbol-value source))
2370 for f in funcs
2371 do (setq source (funcall f source))
2372 finally (return source)))
2373 sources))
2375 ;; (@* "Core: plug-in attribute documentation hack")
2377 ;; `anything-document-attribute' is public API.
2378 (defadvice documentation-property (after anything-document-attribute activate)
2379 "Hack to display plug-in attributes' documentation as `anything-sources' docstring."
2380 (when (eq symbol 'anything-sources)
2381 (setq ad-return-value
2382 (concat ad-return-value "\n"
2383 (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
2384 anything-additional-attributes
2385 "\n")))))
2386 ;; (describe-variable 'anything-sources)
2387 ;; (documentation-property 'anything-sources 'variable-documentation)
2388 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
2390 ;; (@* "Core: all candidates")
2391 (defun anything-get-candidates (source)
2392 "Retrieve and return the list of candidates from
2393 SOURCE."
2394 (let ((name (assoc-default 'name source)))
2395 (unless (member name anything-delayed-init-executed)
2396 (anything-aif (assoc-default 'delayed-init source)
2397 (when (functionp it)
2398 (funcall it)
2399 (add-to-list 'anything-delayed-init-executed name)))))
2400 (let* ((candidate-source (assoc-default 'candidates source))
2401 (candidates (anything-interpret-value candidate-source source)))
2402 (cond ((processp candidates) candidates)
2403 ((listp candidates) (anything-transform-candidates candidates source))
2404 (t (error (concat "Candidates must either be a function, "
2405 " a variable or a list: %s")
2406 candidate-source)))))
2409 (defun anything-transform-candidates (candidates source &optional process-p)
2410 "Transform CANDIDATES according to candidate transformers."
2411 (anything-aif (assoc-default 'candidate-transformer source)
2412 (setq candidates (anything-composed-funcall-with-source source it candidates)))
2413 (anything-aif (and process-p (assoc-default 'filtered-candidate-transformer source))
2414 (setq candidates (anything-composed-funcall-with-source source it candidates source)))
2415 (anything-aif (assoc-default 'real-to-display source)
2416 (setq candidates (anything-funcall-with-source
2417 source 'mapcar
2418 (lambda (cand_)
2419 (if (consp cand_)
2420 ;; override DISPLAY from candidate-transformer
2421 (cons (funcall it (cdr cand_)) (cdr cand_))
2422 (cons (funcall it cand_) cand_)))
2423 candidates)))
2424 candidates)
2427 (defun anything-get-cached-candidates (source)
2428 "Return the cached value of candidates for SOURCE.
2429 Cache the candidates if there is not yet a cached value."
2430 (let* ((name (assoc-default 'name source))
2431 (candidate-cache (assoc name anything-candidate-cache))
2432 candidates)
2433 (if candidate-cache
2434 (setq candidates (cdr candidate-cache))
2436 (setq candidates (anything-get-candidates source))
2438 (if (processp candidates)
2439 (progn
2440 (push (cons candidates
2441 (append source
2442 (list (cons 'item-count 0)
2443 (cons 'incomplete-line ""))))
2444 anything-async-processes)
2445 (set-process-filter candidates 'anything-output-filter)
2446 (setq candidates nil))
2448 (unless (assoc 'volatile source)
2449 (setq candidate-cache (cons name candidates))
2450 (push candidate-cache anything-candidate-cache))))
2452 candidates))
2454 ;; (@* "Core: narrowing candidates")
2455 (defun anything-candidate-number-limit (source)
2456 "`anything-candidate-number-limit' variable may be overridden by SOURCE.
2457 If (candidate-number-limit) is in SOURCE, show all candidates in SOURCE,
2458 ie. cancel the effect of `anything-candidate-number-limit'."
2459 (anything-aif (assq 'candidate-number-limit source)
2460 (or (cdr it) 99999999)
2461 (or anything-candidate-number-limit 99999999)))
2463 (defun anything-compute-matches (source)
2464 "Compute matches from SOURCE according to its settings."
2465 (let ((doit (lambda ()
2466 (let ((functions (assoc-default 'match source))
2467 (limit (anything-candidate-number-limit source))
2468 (anything-pattern
2469 (anything-aif (assoc-default 'pattern-transformer source)
2470 (anything-composed-funcall-with-source source it anything-pattern)
2471 anything-pattern))
2472 matches)
2473 (cond ((or (equal anything-pattern "") (equal functions '(identity)))
2474 (setq matches (anything-get-cached-candidates source))
2475 (if (> (length matches) limit)
2476 (setq matches
2477 (subseq matches 0 limit))))
2479 (condition-case nil
2480 (let ((item-count 0)
2481 (cands (anything-get-cached-candidates source))
2482 exit)
2484 (unless functions
2485 (setq functions
2486 (list (lambda (candidate)
2487 (string-match anything-pattern candidate)))))
2489 (clrhash anything-match-hash)
2490 (dolist (function functions)
2491 (let (newmatches c cc)
2492 (dolist (candidate cands)
2493 (when (and (not (gethash candidate anything-match-hash))
2494 (setq c (if (listp candidate)
2495 (car candidate)
2496 candidate))
2497 (setq cc (cond ((stringp c) c)
2498 ((symbolp c) (symbol-name c))))
2499 (funcall function cc))
2500 (puthash candidate t anything-match-hash)
2501 (push candidate newmatches)
2503 (when limit
2504 (incf item-count)
2505 (when (= item-count limit)
2506 (setq exit t)
2507 (return)))))
2509 (setq matches (append matches (reverse newmatches)))
2511 (if exit
2512 (return)))))
2514 (invalid-regexp (setq matches nil)))))
2516 (anything-aif (assoc-default 'filtered-candidate-transformer source)
2517 (setq matches
2518 (anything-composed-funcall-with-source source it matches source)))
2519 matches))))
2520 (if debug-on-error
2521 (funcall doit)
2522 (condition-case v
2523 (funcall doit)
2524 (error (anything-log-error
2525 "anything-compute-matches: error when processing source: %s"
2526 (assoc-default 'name source))
2527 nil)))))
2529 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2531 (defun anything-process-source (source)
2532 "Display matches from SOURCE according to its settings."
2533 (let ((matches (anything-compute-matches source)))
2534 (when matches
2535 (when anything-test-mode
2536 (setq anything-test-candidate-list
2537 `(,@anything-test-candidate-list
2538 (,(assoc-default 'name source)
2539 ,matches))))
2540 (let ((multiline (assq 'multiline source))
2541 (start (point))
2542 separate)
2543 (anything-insert-header-from-source source)
2544 (dolist (match matches)
2545 (if (and multiline separate)
2546 (anything-insert-candidate-separator)
2547 (setq separate t))
2549 (when (and anything-enable-shortcuts
2550 (not (eq anything-digit-shortcut-count
2551 (length anything-digit-overlays))))
2552 (move-overlay (nth anything-digit-shortcut-count
2553 anything-digit-overlays)
2554 (line-beginning-position)
2555 (line-beginning-position))
2556 (incf anything-digit-shortcut-count))
2557 (anything-insert-match match 'insert))
2559 (if multiline
2560 (put-text-property start (point) 'anything-multiline t))))))
2562 (defun anything-process-delayed-sources (delayed-sources)
2563 "Process delayed sources if the user is idle for
2564 `anything-idle-delay' seconds."
2565 (with-anything-quittable
2566 (if (sit-for (if anything-input-idle-delay
2567 (max 0 (- anything-idle-delay anything-input-idle-delay))
2568 anything-idle-delay))
2569 (with-current-buffer anything-buffer
2570 (save-excursion
2571 (goto-char (point-max))
2572 (dolist (source delayed-sources)
2573 (anything-process-source source))
2575 (when (and (not (equal (buffer-size) 0))
2576 ;; no selection yet
2577 (= (overlay-start anything-selection-overlay)
2578 (overlay-end anything-selection-overlay)))
2579 (goto-char (point-min))
2580 (anything-next-line)))
2581 (save-excursion
2582 (goto-char (point-min))
2583 (run-hooks 'anything-update-hook))
2584 (anything-maybe-fit-frame)))))
2586 ;; (@* "Core: *anything* buffer contents")
2587 (defvar anything-input-local nil)
2588 (defun anything-update ()
2589 "Update the list of matches in the anything buffer according to
2590 the current pattern."
2591 (setq anything-digit-shortcut-count 0)
2592 (anything-kill-async-processes)
2593 (with-current-buffer (anything-buffer-get)
2594 (set (make-local-variable 'anything-input-local) anything-pattern)
2595 (erase-buffer)
2597 (if anything-enable-shortcuts
2598 (dolist (overlay anything-digit-overlays)
2599 (delete-overlay overlay)))
2601 (let (delayed-sources)
2602 (unwind-protect
2603 (dolist (source (anything-get-sources))
2604 (when (and (or (not anything-source-filter)
2605 (member (assoc-default 'name source) anything-source-filter))
2606 (>= (length anything-pattern)
2607 (anything-aif (assoc 'requires-pattern source)
2608 (or (cdr it) 1)
2609 0)))
2610 (if (or (assoc 'delayed source)
2611 (and anything-quick-update
2612 (< (window-height (get-buffer-window (current-buffer)))
2613 (line-number-at-pos (point-max)))))
2614 (push source delayed-sources)
2615 (anything-process-source source))))
2617 (goto-char (point-min))
2618 (save-excursion (run-hooks 'anything-update-hook))
2619 (anything-next-line)
2620 (setq delayed-sources (nreverse delayed-sources))
2621 (if anything-test-mode
2622 (dolist (source delayed-sources)
2623 (anything-process-source source))
2624 (anything-maybe-fit-frame)
2625 (when delayed-sources
2626 (run-with-idle-timer (if (featurep 'xemacs)
2630 'anything-process-delayed-sources
2631 delayed-sources)))))))
2633 (defun anything-force-update ()
2634 "Recalculate and update candidates.
2635 If current source has `update' attribute, a function without argument, call it before update."
2636 (interactive)
2637 (anything-aif (anything-attr 'update)
2638 (anything-funcall-with-source (anything-get-current-source) it))
2639 ;; Remove from candidate cache to recalculate candidates
2640 (setq anything-candidate-cache
2641 (delete (assoc (assoc-default 'name (anything-get-current-source)) anything-candidate-cache)
2642 anything-candidate-cache))
2643 ;; Go to original selection after update
2644 (let ((selection (anything-get-selection))
2645 (source (anything-get-current-source)))
2646 (anything-update)
2647 (with-anything-window
2648 (anything-goto-source source)
2649 (forward-char -1) ;back to \n
2650 (if (search-forward (concat "\n" selection "\n") nil t)
2651 (forward-line -1)
2652 (goto-char (point-min))
2653 (forward-line 1))
2654 (anything-mark-current-line))))
2656 (defun anything-insert-match (match insert-function &optional ignored)
2657 "Insert MATCH into the anything buffer. If MATCH is a list then
2658 insert the string inteneded to appear on the display and store
2659 the real value in a text property."
2660 (let ((start (line-beginning-position (point)))
2661 (string (if (listp match) (car match) match))
2662 (realvalue (if (listp match) (cdr match) match)))
2663 (when (symbolp string) (setq string (symbol-name string)))
2664 (when (stringp string)
2665 (funcall insert-function string)
2666 ;; Some sources with candidates-in-buffer have already added
2667 ;; 'anything-realvalue property when creating candidate buffer.
2668 (unless (get-text-property start 'anything-realvalue)
2669 (put-text-property start (line-end-position)
2670 'anything-realvalue realvalue))
2671 (funcall insert-function "\n"))))
2673 (defun anything-insert-header-from-source (source)
2674 (let ((name (assoc-default 'name source)))
2675 (anything-insert-header name
2676 (anything-aif (assoc-default 'header-name source)
2677 (anything-funcall-with-source source it name)))))
2679 (defun anything-insert-header (name &optional display-string)
2680 "Insert header of source NAME into the anything buffer."
2681 (unless (bobp)
2682 (let ((start (point)))
2683 (insert "\n")
2684 (put-text-property start (point) 'anything-header-separator t)))
2686 (let ((start (point)))
2687 (insert name)
2688 (put-text-property (line-beginning-position)
2689 (line-end-position) 'anything-header t)
2690 (when display-string
2691 (overlay-put (make-overlay (line-beginning-position) (line-end-position))
2692 'display display-string))
2693 (insert "\n")
2694 (put-text-property start (point) 'face anything-header-face)))
2697 (defun anything-insert-candidate-separator ()
2698 "Insert separator of candidates into the anything buffer."
2699 (insert anything-candidate-separator)
2700 (put-text-property (line-beginning-position)
2701 (line-end-position) 'anything-candidate-separator t)
2702 (insert "\n"))
2707 ;; (@* "Core: async process")
2708 (defun anything-output-filter (process string)
2709 "Process output from PROCESS."
2710 (let* ((process-assoc (assoc process anything-async-processes))
2711 (process-info (cdr process-assoc))
2712 (insertion-marker (assoc-default 'insertion-marker process-info))
2713 (incomplete-line-info (assoc 'incomplete-line process-info))
2714 (item-count-info (assoc 'item-count process-info))
2715 (limit (anything-candidate-number-limit process-info)))
2717 (with-current-buffer anything-buffer
2718 (save-excursion
2719 (if insertion-marker
2720 (goto-char insertion-marker)
2722 (goto-char (point-max))
2723 (anything-insert-header-from-source process-info)
2724 (setcdr process-assoc
2725 (append process-info `((insertion-marker . ,(point-marker))))))
2727 (let ((lines (split-string string "\n"))
2728 (multiline (assq 'multiline process-info))
2729 (start (point))
2730 candidates separate)
2731 (while lines
2732 (if (not (cdr lines))
2733 ;; store last incomplete line until new output arrives
2734 (setcdr incomplete-line-info (car lines))
2736 (if (cdr incomplete-line-info)
2737 (progn
2738 (push (concat (cdr incomplete-line-info) (car lines))
2739 candidates)
2740 (setcdr incomplete-line-info nil))
2742 (push (car lines) candidates)))
2744 (pop lines))
2746 (setq candidates (reverse candidates))
2747 (dolist (candidate (anything-transform-candidates candidates process-info t))
2748 ;; FIXME
2749 ;; (if (and multiline separate)
2750 ;; (anything-insert-candidate-separator)
2751 ;; (setq separate t))
2752 (anything-insert-match candidate 'insert-before-markers)
2753 (incf (cdr item-count-info))
2754 ;; FIXME
2755 ;; (if multiline
2756 ;; (put-text-property start (point) 'anything-multiline t))
2757 (when (>= (cdr item-count-info) limit)
2758 (anything-kill-async-process process)
2759 (return)))))
2761 (anything-maybe-fit-frame)
2763 (run-hooks 'anything-update-hook)
2765 (if (bobp)
2766 (anything-next-line)
2768 (save-selected-window
2769 (select-window (get-buffer-window anything-buffer 'visible))
2770 (anything-mark-current-line))))))
2773 (defun anything-kill-async-processes ()
2774 "Kill all known asynchronous processes according to
2775 `anything-async-processes'."
2776 "Kill locate process."
2777 (dolist (process-info anything-async-processes)
2778 (anything-kill-async-process (car process-info)))
2779 (setq anything-async-processes nil))
2782 (defun anything-kill-async-process (process)
2783 "Kill PROCESS and detach the associated functions."
2784 (set-process-filter process nil)
2785 (delete-process process))
2788 ;; (@* "Core: action")
2789 (defun anything-execute-selection-action (&optional selection action clear-saved-action display-to-real)
2790 "If a candidate was selected then perform the associated
2791 action."
2792 (setq selection (or selection (anything-get-selection)))
2793 (setq action (or action
2794 anything-saved-action
2795 (if (get-buffer anything-action-buffer)
2796 (anything-get-selection anything-action-buffer)
2797 (anything-get-action))))
2798 (let ((source (or anything-saved-current-source (anything-get-current-source))))
2799 (if (and (not selection) (assoc 'accept-empty source))
2800 (setq selection ""))
2801 (setq display-to-real
2802 (or display-to-real (assoc-default 'display-to-real source)
2803 #'identity))
2804 (if (and (listp action)
2805 (not (functionp action))) ; lambda
2806 ;;select the default action
2807 (setq action (cdar action)))
2808 (unless clear-saved-action (setq anything-saved-action nil))
2809 (if (and selection action)
2810 (anything-funcall-with-source
2811 source action
2812 (anything-funcall-with-source source display-to-real selection)))))
2814 (defun anything-select-action ()
2815 "Select an action for the currently selected candidate.
2816 If action buffer is selected, back to the anything buffer."
2817 (interactive)
2818 (cond ((get-buffer-window anything-action-buffer 'visible)
2819 (set-window-buffer (get-buffer-window anything-action-buffer) anything-buffer)
2820 (kill-buffer anything-action-buffer))
2822 (setq anything-saved-selection (anything-get-selection))
2823 (unless anything-saved-selection
2824 (error "Nothing is selected."))
2825 (setq anything-saved-current-source (anything-get-current-source))
2826 (let ((actions (anything-get-action)))
2827 (if (functionp actions)
2828 (message "Sole action: %s" actions)
2829 (with-current-buffer (get-buffer-create anything-action-buffer)
2830 (erase-buffer)
2831 (buffer-disable-undo)
2832 (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
2833 (set (make-local-variable 'anything-sources)
2834 `(((name . "Actions")
2835 (volatile)
2836 (candidates . ,actions)
2837 ;; Override `anything-candidate-number-limit'
2838 (candidate-number-limit . 9999))))
2839 (set (make-local-variable 'anything-source-filter) nil)
2840 (set (make-local-variable 'anything-selection-overlay) nil)
2841 (set (make-local-variable 'anything-digit-overlays) nil)
2842 (anything-initialize-overlays anything-action-buffer))
2843 (with-selected-window (minibuffer-window)
2844 (delete-minibuffer-contents))
2845 (setq anything-pattern 'dummy) ; so that it differs from the
2846 ; previous one
2848 (anything-check-minibuffer-input))))))
2850 ;; (@* "Core: selection")
2851 (defun anything-move-selection-common (move-func unit direction)
2852 "Move the selection marker to a new position determined by
2853 UNIT and DIRECTION."
2854 (unless (or (zerop (buffer-size (get-buffer (anything-buffer-get))))
2855 (not (anything-window)))
2856 (with-anything-window
2857 (funcall move-func)
2858 (while (and (not (bobp))
2859 (or (anything-pos-header-line-p)
2860 (anything-pos-candidate-separator-p)))
2861 (forward-line (if (and (eq direction 'previous)
2862 (not (eq (line-beginning-position) (point-min))))
2864 1)))
2865 (and (bobp) (forward-line 1)) ;skip first header
2866 (and (eobp) (forward-line -1)) ;avoid last empty line
2867 (when (and anything-display-source-at-screen-top (eq unit 'source))
2868 (set-window-start (selected-window)
2869 (save-excursion (forward-line -1) (point))))
2870 (when (anything-get-previous-header-pos)
2871 (anything-mark-current-line))
2872 (anything-display-mode-line (anything-get-current-source)))))
2874 (defvar anything-mode-line-string-real nil)
2875 (defun anything-display-mode-line (source)
2876 (set (make-local-variable 'anything-mode-line-string)
2877 (anything-interpret-value (or (assoc-default 'mode-line source)
2878 (default-value 'anything-mode-line-string))
2879 source))
2880 (if anything-mode-line-string
2881 (setq mode-line-format
2882 '(" " mode-line-buffer-identification " "
2883 (line-number-mode "%l") " " anything-mode-line-string-real "-%-")
2884 anything-mode-line-string-real
2885 (substitute-command-keys anything-mode-line-string))
2886 (setq mode-line-format
2887 (default-value 'mode-line-format)))
2888 (setq header-line-format
2889 (anything-interpret-value (assoc-default 'header-line source) source)))
2891 (defun anything-previous-line ()
2892 "Move selection to the previous line."
2893 (interactive)
2894 (anything-move-selection-common
2895 (lambda ()
2896 (forward-line -1)
2897 (when (anything-pos-multiline-p)
2898 (if (or (anything-pos-header-line-p)
2899 (anything-pos-candidate-separator-p))
2900 (forward-line -1)
2901 (forward-line 1))
2902 (let ((header-pos (anything-get-previous-header-pos))
2903 (candidate-pos (anything-get-previous-candidate-separator-pos)))
2904 (when header-pos
2905 (if (or (null candidate-pos) (< candidate-pos header-pos))
2906 (goto-char header-pos)
2907 (goto-char candidate-pos))
2908 (forward-line 1)))))
2909 'line 'previous))
2911 (defun anything-next-line ()
2912 "Move selection to the next line."
2913 (interactive)
2914 (anything-move-selection-common
2915 (lambda ()
2916 (if (not (anything-pos-multiline-p))
2917 (forward-line 1)
2918 (let ((header-pos (anything-get-next-header-pos))
2919 (candidate-pos (anything-get-next-candidate-separator-pos)))
2920 (if (and candidate-pos
2921 (or (null header-pos)
2922 (< candidate-pos header-pos)))
2923 (goto-char candidate-pos)
2924 (if header-pos
2925 (goto-char header-pos)))
2926 (if candidate-pos
2927 (forward-line 1)))))
2928 'line 'next))
2930 (defun anything-previous-page ()
2931 "Move selection back with a pageful."
2932 (interactive)
2933 (anything-move-selection-common
2934 (lambda ()
2935 (condition-case nil
2936 (scroll-down)
2937 (beginning-of-buffer (goto-char (point-min)))))
2938 'page 'previous))
2940 (defun anything-next-page ()
2941 "Move selection forward with a pageful."
2942 (interactive)
2943 (anything-move-selection-common
2944 (lambda ()
2945 (condition-case nil
2946 (scroll-up)
2947 (end-of-buffer (goto-char (point-max)))))
2948 'page 'next))
2950 (defun anything-beginning-of-buffer ()
2951 "Move selection at the top."
2952 (interactive)
2953 (anything-move-selection-common (lambda () (goto-char (point-min)))
2954 'edge 'previous))
2956 (defun anything-end-of-buffer ()
2957 "Move selection at the bottom."
2958 (interactive)
2959 (anything-move-selection-common (lambda () (goto-char (point-max)))
2960 'edge 'next))
2962 (defun anything-previous-source ()
2963 "Move selection to the previous source."
2964 (interactive)
2965 (anything-move-selection-common
2966 (lambda ()
2967 (forward-line -1)
2968 (if (bobp)
2969 (goto-char (point-max))
2970 (if (anything-pos-header-line-p)
2971 (forward-line -1)
2972 (forward-line 1)))
2973 (goto-char (anything-get-previous-header-pos))
2974 (forward-line 1))
2975 'source 'previous))
2977 (defun anything-next-source ()
2978 "Move selection to the next source."
2979 (interactive)
2980 (anything-move-selection-common
2981 (lambda () (goto-char (or (anything-get-next-header-pos) (point-min))))
2982 'source 'next))
2984 (defun anything-goto-source (source-or-name)
2985 "Move the selection to the source (SOURCE-OR-NAME)."
2986 (anything-move-selection-common
2987 (lambda ()
2988 (goto-char (point-min))
2989 (let ((name (if (stringp source-or-name) source-or-name
2990 (assoc-default 'name source-or-name))))
2991 (while (not (string= name (buffer-substring (point-at-bol) (point-at-eol))))
2992 (goto-char (anything-get-next-header-pos)))))
2993 'source 'next))
2995 (defun anything-mark-current-line ()
2996 "Move selection overlay to current line."
2997 (move-overlay anything-selection-overlay
2998 (line-beginning-position)
2999 (if (anything-pos-multiline-p)
3000 (let ((header-pos (anything-get-next-header-pos))
3001 (candidate-pos (anything-get-next-candidate-separator-pos)))
3002 (or (and (null header-pos) candidate-pos candidate-pos)
3003 (and header-pos candidate-pos (< candidate-pos header-pos) candidate-pos)
3004 header-pos
3005 (point-max)))
3006 (1+ (line-end-position))))
3007 (anything-follow-execute-persistent-action-maybe))
3009 (defun anything-this-command-key ()
3010 (event-basic-type (elt (this-command-keys-vector) 0)))
3011 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
3013 (defun anything-select-with-digit-shortcut ()
3014 (interactive)
3015 (if anything-enable-shortcuts
3016 (save-selected-window
3017 (select-window (anything-window))
3018 (let* ((index (position (anything-this-command-key) anything-shortcut-keys))
3019 (overlay (nth index anything-digit-overlays)))
3020 (when (overlay-buffer overlay)
3021 (goto-char (overlay-start overlay))
3022 (anything-mark-current-line)
3023 (anything-exit-minibuffer))))
3024 (self-insert-command 1)))
3026 (defun anything-exit-minibuffer ()
3027 "Select the current candidate by exiting the minibuffer."
3028 (interactive)
3029 (declare (special anything-iswitchb-candidate-selected))
3030 (setq anything-iswitchb-candidate-selected (anything-get-selection))
3031 (exit-minibuffer))
3034 (defun anything-get-next-header-pos ()
3035 "Return the position of the next header from point."
3036 (next-single-property-change (point) 'anything-header))
3039 (defun anything-get-previous-header-pos ()
3040 "Return the position of the previous header from point"
3041 (previous-single-property-change (point) 'anything-header))
3044 (defun anything-pos-multiline-p ()
3045 "Return non-nil if the current position is in the multiline source region."
3046 (get-text-property (point) 'anything-multiline))
3049 (defun anything-get-next-candidate-separator-pos ()
3050 "Return the position of the next candidate separator from point."
3051 (next-single-property-change (point) 'anything-candidate-separator))
3054 (defun anything-get-previous-candidate-separator-pos ()
3055 "Return the position of the previous candidate separator from point."
3056 (previous-single-property-change (point) 'anything-candidate-separator))
3059 (defun anything-pos-header-line-p ()
3060 "Return t if the current line is a header line."
3061 (or (get-text-property (line-beginning-position) 'anything-header)
3062 (get-text-property (line-beginning-position) 'anything-header-separator)))
3064 (defun anything-pos-candidate-separator-p ()
3065 "Return t if the current line is a candidate separator."
3066 (get-text-property (line-beginning-position) 'anything-candidate-separator))
3068 ;; (@* "Core: error handling")
3069 (defun anything-log-error (&rest args)
3070 "Accumulate error messages into `anything-issued-errors'."
3071 (let ((msg (apply 'format args)))
3072 (unless (member msg anything-issued-errors)
3073 (add-to-list 'anything-issued-errors msg))))
3075 (defun anything-print-error-messages ()
3076 "Print error messages in `anything-issued-errors'."
3077 (message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))
3080 ;; (@* "Core: help")
3081 (defun anything-help ()
3082 "Help of `anything'."
3083 (interactive)
3084 (save-window-excursion
3085 (select-window (anything-window))
3086 (delete-other-windows)
3087 (switch-to-buffer (get-buffer-create " *Anything Help*"))
3088 (setq mode-line-format "%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
3089 (setq cursor-type nil)
3090 (erase-buffer)
3091 (insert (substitute-command-keys anything-help-message))
3092 (goto-char 1)
3093 (ignore-errors
3094 (loop for event = (read-event) do
3095 (case event
3096 ((?\C-v ? ) (scroll-up))
3097 ((?\M-v ?b) (scroll-down))
3098 (t (return)))))))
3100 ;; (@* "Core: misc")
3101 (defun anything-kill-buffer-hook ()
3102 "Remove tick entry from `anything-tick-hash' when killing a buffer."
3103 (loop for key being the hash-keys in anything-tick-hash
3104 if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
3105 do (remhash key anything-tick-hash)))
3106 (add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
3108 (defun anything-maybe-fit-frame ()
3109 "Fit anything frame to its buffer, and put it at top right of display.
3111 It is disabled by default because some flickering occurred in some environment.
3112 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
3113 `fit-frame-inhibit-fitting' to nil.
3114 You can set user options `fit-frame-max-width-percent' and
3115 `fit-frame-max-height-percent' to control max frame size."
3116 (declare (warn (unresolved 0)))
3117 (when (and (require 'fit-frame nil t)
3118 (boundp 'fit-frame-inhibit-fitting-flag)
3119 (not fit-frame-inhibit-fitting-flag)
3120 (anything-window))
3121 (ignore-errors
3122 (with-anything-window
3123 (fit-frame nil nil nil t)
3124 (modify-frame-parameters
3125 (selected-frame)
3126 `((left . ,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
3127 (top . 0))))))) ; The (top . 0) shouldn't be necessary (Emacs bug).
3129 (defun anything-preselect (candidate-or-regexp)
3130 (when candidate-or-regexp
3131 (with-anything-window
3132 (goto-char (point-min))
3133 ;; go to first candidate of first source
3134 (forward-line 1)
3135 (let ((start (point)))
3136 (unless (or (re-search-forward (concat "^" (regexp-quote candidate-or-regexp) "$") nil t)
3137 (progn (goto-char start)
3138 (re-search-forward candidate-or-regexp nil t)))
3139 (goto-char start))
3140 (anything-mark-current-line)))))
3142 (defun anything-delete-current-selection ()
3143 "Delete the currently selected item."
3144 (interactive)
3145 (with-anything-window
3146 (cond ((anything-pos-multiline-p)
3147 (anything-aif (anything-get-next-candidate-separator-pos)
3148 (delete-region (point-at-bol)
3149 (1+ (progn (goto-char it) (point-at-eol))))
3150 ;; last candidate
3151 (goto-char (anything-get-previous-candidate-separator-pos))
3152 (delete-region (point-at-bol) (point-max)))
3153 (when (eobp)
3154 (goto-char (or (anything-get-previous-candidate-separator-pos)
3155 (point-min)))
3156 (forward-line 1)))
3158 (delete-region (point-at-bol) (1+ (point-at-eol)))
3159 (when (eobp) (forward-line -1))))
3160 (anything-mark-current-line)))
3162 (defun anything-delete-minibuffer-content ()
3163 "Same as `delete-minibuffer-contents' but this is a command."
3164 (interactive)
3165 (delete-minibuffer-contents))
3167 ;; (@* "Built-in plug-in: type")
3168 (defun anything-compile-source--type (source)
3169 (anything-aif (assoc-default 'type source)
3170 (append source (assoc-default it anything-type-attributes) nil)
3171 source))
3173 ;; `define-anything-type-attribute' is public API.
3175 (defun anything-add-type-attribute (type definition)
3176 (anything-aif (assq type anything-type-attributes)
3177 (setq anything-type-attributes (delete it anything-type-attributes)))
3178 (push (cons type definition) anything-type-attributes))
3180 (defvar anything-types nil)
3181 (defun anything-document-type-attribute (type doc)
3182 (add-to-list 'anything-types type t)
3183 (put type 'anything-typeattrdoc
3184 (concat "- " (symbol-name type) "\n\n" doc "\n")))
3186 (defadvice documentation-property (after anything-document-type-attribute activate)
3187 "Hack to display type attributes' documentation as `anything-type-attributes' docstring."
3188 (when (eq symbol 'anything-type-attributes)
3189 (setq ad-return-value
3190 (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
3191 (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
3192 anything-types "\n")))))
3194 ;; (@* "Built-in plug-in: dummy")
3195 (defun anything-dummy-candidate (candidate source)
3196 ;; `source' is defined in filtered-candidate-transformer
3197 (list anything-pattern))
3199 (defun anything-compile-source--dummy (source)
3200 (if (assoc 'dummy source)
3201 (append source
3202 '((candidates "dummy")
3203 (accept-empty)
3204 (match identity)
3205 (filtered-candidate-transformer . anything-dummy-candidate)
3206 (disable-shortcuts)
3207 (volatile)))
3208 source))
3210 ;; (@* "Built-in plug-in: disable-shortcuts")
3211 (defvar anything-orig-enable-shortcuts nil)
3212 (defun anything-save-enable-shortcuts ()
3213 (setq anything-orig-enable-shortcuts anything-enable-shortcuts
3214 anything-enable-shortcuts nil))
3215 (defun anything-compile-source--disable-shortcuts (source)
3216 (if (assoc 'disable-shortcuts source)
3217 (append `((init ,@(anything-mklist (assoc-default 'init source))
3218 anything-save-enable-shortcuts)
3219 (resume ,@(anything-mklist (assoc-default 'resume source))
3220 anything-save-enable-shortcuts)
3221 (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
3222 (lambda () (setq anything-enable-shortcuts anything-orig-enable-shortcuts))))
3223 source)
3224 source))
3226 ;; (@* "Built-in plug-in: candidates-in-buffer")
3227 (defun anything-candidates-in-buffer ()
3228 "Get candidates from the candidates buffer according to `anything-pattern'.
3230 BUFFER is `anything-candidate-buffer' by default. Each
3231 candidate must be placed in one line. This function is meant to
3232 be used in candidates-in-buffer or candidates attribute of an
3233 anything source. Especially fast for many (1000+) candidates.
3236 '((name . \"many files\")
3237 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
3238 (insert-many-filenames))))
3239 (search re-search-forward) ; optional
3240 (candidates-in-buffer)
3241 (type . file))
3243 +===============================================================+
3244 | The new way of making and narrowing candidates: Using buffers |
3245 +===============================================================+
3247 By default, `anything' makes candidates by evaluating the
3248 candidates function, then narrows them by `string-match' for each
3249 candidate.
3251 But this way is very slow for many candidates. The new way is
3252 storing all candidates in a buffer and narrowing them by
3253 `re-search-forward'. Search function is customizable by search
3254 attribute. The important point is that buffer processing is MUCH
3255 FASTER than string list processing and is the Emacs way.
3257 The init function writes all candidates to a newly-created
3258 candidate buffer. The candidates buffer is created or specified
3259 by `anything-candidate-buffer'. Candidates are stored in a line.
3261 The candidates function narrows all candidates, IOW creates a
3262 subset of candidates dynamically. It is the task of
3263 `anything-candidates-in-buffer'. As long as
3264 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
3265 sufficient in most cases.
3267 Note that `(candidates-in-buffer)' is shortcut of three attributes:
3268 (candidates . anything-candidates-in-buffer)
3269 (volatile)
3270 (match identity)
3271 And `(candidates-in-buffer . func)' is shortcut of three attributes:
3272 (candidates . func)
3273 (volatile)
3274 (match identity)
3275 The expansion is performed in `anything-get-sources'.
3277 The candidates-in-buffer attribute implies the volatile attribute.
3278 The volatile attribute is needed because `anything-candidates-in-buffer'
3279 creates candidates dynamically and need to be called everytime
3280 `anything-pattern' changes.
3282 Because `anything-candidates-in-buffer' plays the role of `match' attribute
3283 function, specifying `(match identity)' makes the source slightly faster.
3285 To customize `anything-candidates-in-buffer' behavior, use search,
3286 get-line and search-from-end attributes. See also `anything-sources' docstring.
3288 (declare (special source))
3289 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
3290 anything-pattern
3291 (or (assoc-default 'get-line source)
3292 #'buffer-substring-no-properties)
3293 ;; use external variable `source'.
3294 (or (assoc-default 'search source)
3295 (if (assoc 'search-from-end source)
3296 '(re-search-backward)
3297 '(re-search-forward)))
3298 (anything-candidate-number-limit source)
3299 (assoc 'search-from-end source)))
3301 (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)
3302 ;; buffer == nil when candidates buffer does not exist.
3303 (when buffer
3304 (with-current-buffer buffer
3305 (let ((start-point (if search-from-end (point-max) (point-min)))
3306 (next-line-fn (if search-from-end
3307 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
3308 #'forward-line))
3309 (endp (if search-from-end #'bobp #'eobp)))
3310 (goto-char (1- start-point))
3311 (if (string= pattern "")
3312 (delq nil (loop until (funcall endp)
3313 for i from 1 to limit
3314 collecting (funcall get-line-fn (point-at-bol) (point-at-eol))
3315 do (funcall next-line-fn 1)))
3317 (let ((i 1)
3318 (next-line-fn (if search-from-end
3319 (lambda (x) (goto-char (max (point-at-bol) 1)))
3320 #'forward-line))
3321 buffer-read-only
3322 matches exit newmatches)
3323 (progn
3324 (goto-char (point-min))
3325 (insert "\n")
3326 (goto-char (point-max))
3327 (insert "\n")
3328 (setq start-point (if search-from-end (point-max) (point-min)))
3329 (clrhash anything-cib-hash)
3330 (unwind-protect
3331 (dolist (searcher search-fns)
3332 (goto-char start-point)
3333 (setq newmatches nil)
3334 (loop while (funcall searcher pattern nil t)
3335 if (or (funcall endp) (< limit i))
3336 do (setq exit t) (return)
3337 else do
3338 (let ((cand (funcall get-line-fn (point-at-bol) (point-at-eol))))
3339 (unless (gethash cand anything-cib-hash)
3340 (puthash cand t anything-cib-hash)
3341 (incf i)
3342 (push cand newmatches)))
3343 (funcall next-line-fn 1))
3344 (setq matches (append matches (nreverse newmatches)))
3345 (if exit (return)))
3346 (goto-char (point-min))
3347 (delete-char 1)
3348 (goto-char (1- (point-max)))
3349 (delete-char 1)
3351 (set-buffer-modified-p nil)))
3352 (delq nil matches)))))))
3355 (defun anything-candidate-buffer (&optional create-or-buffer)
3356 "Register and return a buffer containing candidates of current source.
3357 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3358 then global candidates buffer.
3360 Acceptable values of CREATE-OR-BUFFER:
3362 - nil (omit)
3363 Only return the candidates buffer.
3364 - a buffer
3365 Register a buffer as a candidates buffer.
3366 - 'global
3367 Create a new global candidates buffer,
3368 named \" *anything candidates:SOURCE*\".
3369 - other non-nil value
3370 Create a new global candidates buffer,
3371 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
3373 (let* ((gbufname (format " *anything candidates:%s*" anything-source-name))
3374 (lbufname (concat gbufname (buffer-name anything-current-buffer)))
3375 buf)
3376 (when create-or-buffer
3377 (if (bufferp create-or-buffer)
3378 (setq anything-candidate-buffer-alist
3379 (cons (cons anything-source-name create-or-buffer)
3380 (delete (assoc anything-source-name anything-candidate-buffer-alist)
3381 anything-candidate-buffer-alist)))
3382 (add-to-list 'anything-candidate-buffer-alist
3383 (cons anything-source-name create-or-buffer))
3384 (when (eq create-or-buffer 'global)
3385 (loop for b in (buffer-list)
3386 if (string-match (format "^%s" (regexp-quote gbufname)) (buffer-name b))
3387 do (kill-buffer b)))
3388 (with-current-buffer
3389 (get-buffer-create (if (eq create-or-buffer 'global) gbufname lbufname))
3390 (buffer-disable-undo)
3391 (erase-buffer)
3392 (font-lock-mode -1))))
3393 (or (get-buffer lbufname)
3394 (get-buffer gbufname)
3395 (anything-aif (assoc-default anything-source-name anything-candidate-buffer-alist)
3396 (and (buffer-live-p it) it)))))
3398 (defun anything-compile-source--candidates-in-buffer (source)
3399 (anything-aif (assoc 'candidates-in-buffer source)
3400 (append source `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
3401 (volatile) (match identity)))
3402 source))
3404 ;; (@* "Utility: resplit anything window")
3405 (defun anything-toggle-resplit-window ()
3406 "Toggle resplit anything window, vertically or horizontally."
3407 (interactive)
3408 (with-anything-window
3409 (let ((before-height (window-height)))
3410 (delete-window)
3411 (set-window-buffer
3412 (select-window (if (= (window-height) before-height)
3413 (split-window-vertically)
3414 (split-window-horizontally)))
3415 anything-buffer))))
3417 ;; (@* "Utility: select another action by key")
3418 (defun anything-select-nth-action (n)
3419 "Select the nth action for the currently selected candidate."
3420 (setq anything-saved-selection (anything-get-selection))
3421 (unless anything-saved-selection
3422 (error "Nothing is selected."))
3423 (setq anything-saved-action (cdr (elt (anything-get-action) n)))
3424 (anything-exit-minibuffer))
3426 (defun anything-select-2nd-action ()
3427 "Select the 2nd action for the currently selected candidate."
3428 (interactive)
3429 (anything-select-nth-action 1))
3431 (defun anything-select-3rd-action ()
3432 "Select the 3rd action for the currently selected candidate."
3433 (interactive)
3434 (anything-select-nth-action 2))
3436 (defun anything-select-4th-action ()
3437 "Select the 4th action for the currently selected candidate."
3438 (interactive)
3439 (anything-select-nth-action 3))
3441 (defun anything-select-2nd-action-or-end-of-line ()
3442 "Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
3443 Otherwise goto the end of minibuffer."
3444 (interactive)
3445 (if (eolp)
3446 (anything-select-nth-action 1)
3447 (end-of-line)))
3449 ;; (@* "Utility: Persistent Action")
3450 (defmacro with-anything-display-same-window (&rest body)
3451 "Make `pop-to-buffer' and `display-buffer' display in the same window."
3452 `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
3453 ,@body))
3454 (put 'with-anything-display-same-window 'lisp-indent-function 0)
3456 (defun* anything-execute-persistent-action (&optional (attr 'persistent-action))
3457 "If a candidate is selected then perform the associated action without quitting anything."
3458 (interactive)
3459 (save-selected-window
3460 (select-window (get-buffer-window (anything-buffer-get)))
3461 (select-window (setq minibuffer-scroll-window
3462 (if (one-window-p t) (split-window)
3463 (next-window (selected-window) 1))))
3464 (let ((anything-in-persistent-action t))
3465 (with-anything-display-same-window
3466 (anything-execute-selection-action
3468 (or (assoc-default attr (anything-get-current-source))
3469 (anything-get-action))
3471 (run-hooks 'anything-after-persistent-action-hook)))))
3473 (defun anything-persistent-action-display-buffer (buf &optional not-this-window)
3474 "Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
3475 If `anything-persistent-action-use-special-display' is non-nil and
3476 BUF is to be displayed by `special-display-function', use it.
3477 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
3478 (let* ((name (buffer-name buf))
3479 display-buffer-function pop-up-windows
3480 (same-window-regexps
3481 (unless (and anything-persistent-action-use-special-display
3482 (or (member name
3483 (mapcar (lambda (x) (or (car-safe x) x)) special-display-buffer-names))
3484 (remove-if-not
3485 (lambda (x) (string-match (or (car-safe x) x) name))
3486 special-display-regexps)))
3487 '("."))))
3488 (display-buffer buf not-this-window)))
3490 ;; scroll-other-window(-down)? for persistent-action
3491 (defun anything-scroll-other-window-base (command)
3492 (save-selected-window
3493 (select-window
3494 (some-window
3495 (lambda (w) (not (string= anything-buffer (buffer-name (window-buffer w)))))
3496 'no-minibuffer 'current-frame))
3497 (call-interactively command)))
3499 (defun anything-scroll-other-window ()
3500 "Scroll other window (not *Anything* window) upward."
3501 (interactive)
3502 (anything-scroll-other-window-base (lambda ()
3503 (interactive)
3504 (scroll-up anything-scroll-amount))))
3505 (defun anything-scroll-other-window-down ()
3506 "Scroll other window (not *Anything* window) downward."
3507 (interactive)
3508 (anything-scroll-other-window-base (lambda ()
3509 (interactive)
3510 (scroll-down anything-scroll-amount))))
3512 ;; (@* "Utility: Visible Mark")
3513 (defface anything-visible-mark
3514 '((((min-colors 88) (background dark))
3515 (:background "green1" :foreground "black"))
3516 (((background dark)) (:background "green" :foreground "black"))
3517 (((min-colors 88)) (:background "green1"))
3518 (t (:background "green")))
3519 "Face for visible mark."
3520 :group 'anything)
3521 (defvar anything-visible-mark-face 'anything-visible-mark)
3522 (defvar anything-visible-mark-overlays nil)
3524 (defun anything-clear-visible-mark ()
3525 (mapc 'delete-overlay anything-visible-mark-overlays)
3526 (setq anything-visible-mark-overlays nil))
3527 (add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
3529 ;; (defun anything-toggle-visible-mark ()
3530 ;; (interactive)
3531 ;; (with-anything-window
3532 ;; (anything-aif (loop for o in anything-visible-mark-overlays
3533 ;; when (equal (line-beginning-position) (overlay-start o))
3534 ;; do (return o))
3535 ;; ;; delete
3536 ;; (progn (delete-overlay it)
3537 ;; (delq it anything-visible-mark-overlays))
3538 ;; (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
3539 ;; (overlay-put o 'face anything-visible-mark-face)
3540 ;; (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3541 ;; (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3542 ;; (add-to-list 'anything-visible-mark-overlays o)))))
3544 (defvar anything-c-marked-candidate-list nil
3545 "[OBSOLETE] DO NOT USE!!")
3546 (defvar anything-marked-candidates nil
3547 "Marked candadates. List of (source . real) pair.")
3548 (defun anything-toggle-visible-mark ()
3549 (interactive)
3550 (with-anything-window
3551 (let ((display (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
3552 (source (anything-get-current-source))
3553 (selection (anything-get-selection)))
3554 (anything-aif (loop for o in anything-visible-mark-overlays
3555 when (equal (line-beginning-position) (overlay-start o))
3556 do (return o))
3557 ;; delete
3558 (progn
3559 (setq anything-c-marked-candidate-list
3560 (remove
3561 display anything-c-marked-candidate-list))
3562 (setq anything-marked-candidates
3563 (remove
3564 (cons source selection)
3565 anything-marked-candidates))
3566 (delete-overlay it)
3567 (setq anything-visible-mark-overlays (delq it anything-visible-mark-overlays)))
3568 (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
3569 (overlay-put o 'face anything-visible-mark-face)
3570 (overlay-put o 'source (assoc-default 'name source))
3571 (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3572 (add-to-list 'anything-visible-mark-overlays o)
3573 (push display anything-c-marked-candidate-list)
3574 (push (cons source selection) anything-marked-candidates)))
3575 (anything-next-line))))
3577 (defun anything-marked-candidates ()
3578 "Marked candidates (real value) of current source."
3579 (loop with current-src = (anything-get-current-source)
3580 for (source . real) in anything-marked-candidates
3581 when (eq current-src source)
3582 collect real))
3584 (defun anything-reset-marked-candidates ()
3585 (setq anything-c-marked-candidate-list nil)
3586 (setq anything-marked-candidates nil))
3588 (add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
3589 (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3591 (defun anything-revive-visible-mark ()
3592 (interactive)
3593 (with-current-buffer anything-buffer
3594 (loop for o in anything-visible-mark-overlays do
3595 (goto-char (point-min))
3596 (let (moved)
3597 (while (and (not moved)
3598 (search-forward (overlay-get o 'string) nil t))
3599 (forward-line -1)
3600 (when (and (save-excursion
3601 (goto-char (anything-get-previous-header-pos))
3602 (equal (overlay-get o 'source)
3603 (buffer-substring (line-beginning-position) (line-end-position))))
3604 (not (find-if (lambda (x)
3605 (memq x anything-visible-mark-overlays))
3606 (overlays-at (point)))))
3607 (move-overlay o (line-beginning-position) (1+ (line-end-position)))
3608 (setq moved t))
3609 (forward-line 1))))))
3610 (add-hook 'anything-update-hook 'anything-revive-visible-mark)
3612 (defun anything-next-visible-mark (&optional prev)
3613 (interactive)
3614 (with-anything-window
3615 (block 'exit
3616 (setq anything-visible-mark-overlays
3617 (sort* anything-visible-mark-overlays
3618 '< :key 'overlay-start))
3619 (let ((i (position-if (lambda (o) (< (point) (overlay-start o)))
3620 anything-visible-mark-overlays)))
3621 (when prev
3622 (unless anything-visible-mark-overlays (return-from 'exit nil))
3623 (if (not i) (setq i (length anything-visible-mark-overlays)))
3624 (if (equal (point) (overlay-start (nth (1- i) anything-visible-mark-overlays)))
3625 (setq i (1- i))))
3626 (when i
3627 (goto-char (overlay-start (nth (if prev (1- i) i) anything-visible-mark-overlays)))
3628 (anything-mark-current-line))))))
3630 (defun anything-prev-visible-mark ()
3631 (interactive)
3632 (anything-next-visible-mark t))
3634 ;; (@* "Utility: `find-file' integration")
3635 (defun anything-quit-and-find-file ()
3636 "Drop into `find-file' from `anything' like `iswitchb-find-file'.
3637 If current selection is a buffer or a file, `find-file' from its directory."
3638 (interactive)
3639 (anything-run-after-quit
3640 (lambda (f)
3641 (if (file-exists-p f)
3642 (let ((default-directory (file-name-directory f)))
3643 (call-interactively 'find-file))
3644 (call-interactively 'find-file)))
3645 (anything-aif (get-buffer (anything-get-selection))
3646 (buffer-file-name it)
3647 (expand-file-name (anything-get-selection)))))
3649 ;; (@* "Utility: Selection Paste")
3650 (defun anything-yank-selection ()
3651 "Set minibuffer contents to current selection."
3652 (interactive)
3653 (delete-minibuffer-contents)
3654 (insert (anything-get-selection nil t)))
3656 (defun anything-kill-selection-and-quit ()
3657 "Store current selection to kill ring.
3658 You can paste it by typing C-y."
3659 (interactive)
3660 (anything-run-after-quit
3661 (lambda (sel)
3662 (kill-new sel)
3663 (message "Killed: %s" sel))
3664 (anything-get-selection nil t)))
3667 ;; (@* "Utility: Automatical execution of persistent-action")
3668 (define-minor-mode anything-follow-mode
3669 "If this mode is on, persistent action is executed everytime the cursor is moved."
3670 nil " AFollow" :global t)
3672 (defun anything-follow-execute-persistent-action-maybe ()
3673 "Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
3674 (and anything-follow-mode
3675 (sit-for anything-input-idle-delay)
3676 (anything-window)
3677 (anything-get-selection)
3678 (save-excursion
3679 (anything-execute-persistent-action))))
3681 ;; (@* "Utility: Incremental search within results (unmaintained)")
3683 (defvar anything-isearch-original-global-map nil
3684 "Original global map before Anything isearch is started.")
3686 (defvar anything-isearch-original-message-timeout nil
3687 "Original message timeout before Anything isearch is started.")
3689 (defvar anything-isearch-pattern nil
3690 "The current isearch pattern.")
3692 (defvar anything-isearch-message-suffix ""
3693 "Message suffix indicating the current state of the search.")
3695 (defvar anything-isearch-original-point nil
3696 "Original position of point before isearch is started.")
3698 (defvar anything-isearch-original-window nil
3699 "Original selected window before isearch is started.")
3701 (defvar anything-isearch-original-cursor-in-non-selected-windows nil
3702 "Original value of cursor-in-non-selected-windows before isearch is started.")
3704 (defvar anything-isearch-original-post-command-hook nil
3705 "Original value of post-command-hook before isearch is started.")
3707 (defvar anything-isearch-match-positions nil
3708 "Stack of positions of matches or non-matches.
3710 It's a list of plists with two properties: `event', the last user
3711 event, `start', the start position of the current match, and
3712 `pos', the position of point after that event.
3714 The value of `event' can be the following symbols: `char' if a
3715 character was typed, `error' if a non-matching character was
3716 typed, `search' if a forward search had to be done after a
3717 character, and `search-again' if a search was done for the next
3718 occurrence of the current pattern.")
3720 (defvar anything-isearch-match-start nil
3721 "Start position of the current match.")
3724 (defun anything-isearch ()
3725 "Start incremental search within results. (UNMAINTAINED)"
3726 (interactive)
3727 (if (zerop (buffer-size (get-buffer (anything-buffer-get))))
3728 (message "There are no results.")
3730 (setq anything-isearch-original-message-timeout minibuffer-message-timeout)
3731 (setq minibuffer-message-timeout nil)
3733 (setq anything-isearch-original-global-map global-map)
3735 (condition-case nil
3736 (progn
3737 (setq anything-isearch-original-window (selected-window))
3738 (select-window (anything-window))
3739 (setq cursor-type t)
3741 (setq anything-isearch-original-post-command-hook
3742 (default-value 'post-command-hook))
3743 (setq-default post-command-hook nil)
3744 (add-hook 'post-command-hook 'anything-isearch-post-command)
3746 (use-global-map anything-isearch-map)
3747 (setq overriding-terminal-local-map anything-isearch-map)
3749 (setq anything-isearch-pattern "")
3751 (setq anything-isearch-original-cursor-in-non-selected-windows
3752 cursor-in-non-selected-windows)
3753 (setq cursor-in-non-selected-windows nil)
3755 (setq anything-isearch-original-point (point-marker))
3756 (goto-char (point-min))
3757 (forward-line)
3758 (anything-mark-current-line)
3760 (setq anything-isearch-match-positions nil)
3761 (setq anything-isearch-match-start (point-marker))
3763 (if anything-isearch-overlay
3764 ;; make sure the overlay belongs to the anything buffer
3765 (move-overlay anything-isearch-overlay (point-min) (point-min)
3766 (get-buffer (anything-buffer-get)))
3768 (setq anything-isearch-overlay (make-overlay (point-min) (point-min)))
3769 (overlay-put anything-isearch-overlay 'face anything-isearch-match-face))
3771 (setq anything-isearch-message-suffix
3772 (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))
3774 (error (anything-isearch-cleanup)))))
3777 (defun anything-isearch-post-command ()
3778 "Print the current pattern after every command."
3779 (anything-isearch-message)
3780 (when (anything-window)
3781 (with-anything-window
3782 (move-overlay anything-isearch-overlay anything-isearch-match-start (point)
3783 (get-buffer (anything-buffer-get))))))
3786 (defun anything-isearch-printing-char ()
3787 "Add printing char to the pattern."
3788 (interactive)
3789 (let ((char (char-to-string last-command-event)))
3790 (setq anything-isearch-pattern (concat anything-isearch-pattern char))
3792 (with-anything-window
3793 (if (looking-at char)
3794 (progn
3795 (push (list 'event 'char
3796 'start anything-isearch-match-start
3797 'pos (point-marker))
3798 anything-isearch-match-positions)
3799 (forward-char))
3801 (let ((start (point)))
3802 (while (and (re-search-forward anything-isearch-pattern nil t)
3803 (anything-pos-header-line-p)))
3804 (if (or (anything-pos-header-line-p)
3805 (eq start (point)))
3806 (progn
3807 (goto-char start)
3808 (push (list 'event 'error
3809 'start anything-isearch-match-start
3810 'pos (point-marker))
3811 anything-isearch-match-positions))
3813 (push (list 'event 'search
3814 'start anything-isearch-match-start
3815 'pos (copy-marker start))
3816 anything-isearch-match-positions)
3817 (setq anything-isearch-match-start (copy-marker (match-beginning 0))))))
3819 (anything-mark-current-line))))
3822 (defun anything-isearch-again ()
3823 "Search again for the current pattern"
3824 (interactive)
3825 (if (equal anything-isearch-pattern "")
3826 (setq anything-isearch-message-suffix "no pattern yet")
3828 (with-anything-window
3829 (let ((start (point)))
3830 (while (and (re-search-forward anything-isearch-pattern nil t)
3831 (anything-pos-header-line-p)))
3832 (if (or (anything-pos-header-line-p)
3833 (eq start (point)))
3834 (progn
3835 (goto-char start)
3836 (unless (eq 'error (plist-get (car anything-isearch-match-positions)
3837 'event))
3838 (setq anything-isearch-message-suffix "no more matches")))
3840 (push (list 'event 'search-again
3841 'start anything-isearch-match-start
3842 'pos (copy-marker start))
3843 anything-isearch-match-positions)
3844 (setq anything-isearch-match-start (copy-marker (match-beginning 0)))
3846 (anything-mark-current-line))))))
3849 (defun anything-isearch-delete ()
3850 "Undo last event."
3851 (interactive)
3852 (unless (equal anything-isearch-pattern "")
3853 (let ((last (pop anything-isearch-match-positions)))
3854 (unless (eq 'search-again (plist-get last 'event))
3855 (setq anything-isearch-pattern
3856 (substring anything-isearch-pattern 0 -1)))
3858 (with-anything-window
3859 (goto-char (plist-get last 'pos))
3860 (setq anything-isearch-match-start (plist-get last 'start))
3861 (anything-mark-current-line)))))
3864 (defun anything-isearch-default-action ()
3865 "Execute the default action for the selected candidate."
3866 (interactive)
3867 (anything-isearch-cleanup)
3868 (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))
3871 (defun anything-isearch-select-action ()
3872 "Choose an action for the selected candidate."
3873 (interactive)
3874 (anything-isearch-cleanup)
3875 (with-anything-window
3876 (anything-select-action)))
3879 (defun anything-isearch-cancel ()
3880 "Cancel Anything isearch."
3881 (interactive)
3882 (anything-isearch-cleanup)
3883 (when (anything-window)
3884 (with-anything-window
3885 (goto-char anything-isearch-original-point)
3886 (anything-mark-current-line))))
3889 (defun anything-isearch-cleanup ()
3890 "Clean up the mess."
3891 (setq minibuffer-message-timeout anything-isearch-original-message-timeout)
3892 (with-current-buffer (anything-buffer-get)
3893 (setq overriding-terminal-local-map nil)
3894 (setq cursor-type nil)
3895 (setq cursor-in-non-selected-windows
3896 anything-isearch-original-cursor-in-non-selected-windows))
3897 (when anything-isearch-original-window
3898 (select-window anything-isearch-original-window))
3900 (use-global-map anything-isearch-original-global-map)
3901 (setq-default post-command-hook anything-isearch-original-post-command-hook)
3902 (when (overlayp anything-isearch-overlay)
3903 (delete-overlay anything-isearch-overlay)))
3906 (defun anything-isearch-message ()
3907 "Print prompt."
3908 (if (and (equal anything-isearch-message-suffix "")
3909 (eq (plist-get (car anything-isearch-match-positions) 'event)
3910 'error))
3911 (setq anything-isearch-message-suffix "failing"))
3913 (unless (equal anything-isearch-message-suffix "")
3914 (setq anything-isearch-message-suffix
3915 (concat " [" anything-isearch-message-suffix "]")))
3917 (message (concat "Search within results: "
3918 anything-isearch-pattern
3919 anything-isearch-message-suffix))
3921 (setq anything-isearch-message-suffix ""))
3924 ;; (@* "Utility: Iswitchb integration (unmaintained)")
3926 (defvar anything-iswitchb-candidate-selected nil
3927 "Indicates whether an anything candidate is selected from iswitchb.")
3929 (defvar anything-iswitchb-frame-configuration nil
3930 "Saved frame configuration, before anything buffer was displayed.")
3932 (defvar anything-iswitchb-saved-keys nil
3933 "The original in iswitchb before binding anything keys.")
3936 (defun anything-iswitchb-setup ()
3937 "Integrate anything completion into iswitchb (UNMAINTAINED).
3939 If the user is idle for `anything-iswitchb-idle-delay' seconds
3940 after typing something into iswitchb then anything candidates are
3941 shown for the current iswitchb input.
3943 ESC cancels anything completion and returns to normal iswitchb.
3945 Some key bindings in `anything-map' are modified.
3946 See also `anything-iswitchb-setup-keys'."
3947 (interactive)
3949 (require 'iswitchb)
3951 ;; disable timid completion during iswitchb
3952 (put 'iswitchb-buffer 'timid-completion 'disabled)
3953 (add-hook 'minibuffer-setup-hook 'anything-iswitchb-minibuffer-setup)
3955 (defadvice iswitchb-visit-buffer
3956 (around anything-iswitchb-visit-buffer activate)
3957 (if anything-iswitchb-candidate-selected
3958 (anything-execute-selection-action)
3959 ad-do-it))
3961 (defadvice iswitchb-possible-new-buffer
3962 (around anything-iswitchb-possible-new-buffer activate)
3963 (if anything-iswitchb-candidate-selected
3964 (anything-execute-selection-action)
3965 ad-do-it))
3966 (anything-iswitchb-setup-keys)
3967 (message "Iswitchb integration is activated."))
3969 (defun anything-iswitchb-setup-keys ()
3970 "Modify `anything-map' for anything-iswitchb users.
3972 C-p is used instead of M-p, because anything uses ESC
3973 (currently hardcoded) for `anything-iswitchb-cancel-anything' and
3974 Emacs handles ESC and Meta as synonyms, so ESC overrides
3975 other commands with Meta prefix.
3977 Note that iswitchb uses M-p and M-n by default for history
3978 navigation, so you should bind C-p and C-n in
3979 `iswitchb-mode-map' if you use the history keys and don't want
3980 to use different keys for iswitchb while anything is not yet
3981 kicked in. These keys are not bound automatically by anything
3982 in `iswitchb-mode-map' because they (C-n at least) already have
3983 a standard iswitchb binding which you might be accustomed to.
3985 Binding M-s is used instead of C-s, because C-s has a binding in
3986 iswitchb. You can rebind it AFTER `anything-iswitchb-setup'.
3988 Unbind C-r to prevent problems during anything-isearch."
3989 (define-key anything-map (kbd "C-s") nil)
3990 (define-key anything-map (kbd "M-p") nil)
3991 (define-key anything-map (kbd "M-n") nil)
3992 (define-key anything-map (kbd "M-v") nil)
3993 (define-key anything-map (kbd "C-v") nil)
3994 (define-key anything-map (kbd "C-p") 'anything-previous-history-element)
3995 (define-key anything-map (kbd "C-n") 'anything-next-history-element)
3996 (define-key anything-map (kbd "M-s") nil)
3997 (define-key anything-map (kbd "M-s") 'anything-isearch)
3998 (define-key anything-map (kbd "C-r") nil))
4000 (defun anything-iswitchb-minibuffer-setup ()
4001 (when (eq this-command 'iswitchb-buffer)
4002 (add-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
4004 (setq anything-iswitchb-frame-configuration nil)
4005 (setq anything-iswitchb-candidate-selected nil)
4006 (add-hook 'anything-update-hook 'anything-iswitchb-handle-update)
4008 (anything-initialize)
4010 (add-hook 'post-command-hook 'anything-iswitchb-check-input)))
4013 (defun anything-iswitchb-minibuffer-exit ()
4014 (remove-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
4015 (remove-hook 'post-command-hook 'anything-iswitchb-check-input)
4016 (remove-hook 'anything-update-hook 'anything-iswitchb-handle-update)
4018 (anything-cleanup)
4020 (when anything-iswitchb-frame-configuration
4021 (anything-set-frame/window-configuration anything-iswitchb-frame-configuration)
4022 (setq anything-iswitchb-frame-configuration nil)))
4025 (defun anything-iswitchb-check-input ()
4026 "Extract iswitchb input and check if it needs to be handled."
4027 (declare (special iswitchb-text))
4028 (if (or anything-iswitchb-frame-configuration
4029 (sit-for anything-iswitchb-idle-delay))
4030 (anything-check-new-input iswitchb-text)))
4033 (defun anything-iswitchb-handle-update ()
4034 "Pop up the anything buffer if it's not empty and it's not
4035 shown yet and bind anything commands in iswitchb."
4036 (unless (or (equal (buffer-size (get-buffer anything-buffer)) 0)
4037 anything-iswitchb-frame-configuration)
4038 (setq anything-iswitchb-frame-configuration (anything-current-frame/window-configuration))
4040 (save-selected-window
4041 (if (not anything-samewindow)
4042 (pop-to-buffer anything-buffer)
4044 (select-window (get-lru-window))
4045 (switch-to-buffer anything-buffer)))
4047 (with-current-buffer (window-buffer (active-minibuffer-window))
4048 (let* ((anything-prefix "anything-")
4049 (prefix-length (length anything-prefix))
4050 (commands
4051 (delete-dups
4052 (remove-if 'null
4053 (mapcar
4054 (lambda (binding)
4055 (let ((command (cdr binding)))
4056 (when (and (symbolp command)
4057 (eq (compare-strings
4058 anything-prefix
4059 0 prefix-length
4060 (symbol-name command)
4061 0 prefix-length)
4063 command)))
4064 (cdr anything-map)))))
4065 (bindings (mapcar (lambda (command)
4066 (cons command
4067 (where-is-internal command anything-map)))
4068 commands)))
4070 (push (list 'anything-iswitchb-cancel-anything (kbd "<ESC>"))
4071 bindings)
4073 (setq anything-iswitchb-saved-keys nil)
4075 (let* ((iswitchb-prefix "iswitchb-")
4076 (prefix-length (length iswitchb-prefix)))
4077 (dolist (binding bindings)
4078 (dolist (key (cdr binding))
4079 (let ((old-command (lookup-key (current-local-map) key)))
4080 (unless (and anything-iswitchb-dont-touch-iswithcb-keys
4081 (symbolp old-command)
4082 (eq (compare-strings iswitchb-prefix
4083 0 prefix-length
4084 (symbol-name old-command)
4085 0 prefix-length)
4087 (push (cons key old-command)
4088 anything-iswitchb-saved-keys)
4089 (define-key (current-local-map) key (car binding)))))))))))
4092 (defun anything-iswitchb-cancel-anything ()
4093 "Cancel anything completion and return to standard iswitchb."
4094 (interactive)
4095 (save-excursion
4096 (dolist (binding anything-iswitchb-saved-keys)
4097 (define-key (current-local-map) (car binding) (cdr binding)))
4098 (anything-iswitchb-minibuffer-exit)))
4100 ;; (@* "Compatibility")
4102 ;; Copied assoc-default from XEmacs version 21.5.12
4103 (unless (fboundp 'assoc-default)
4104 (defun assoc-default (key alist &optional test default)
4105 "Find object KEY in a pseudo-alist ALIST.
4106 ALIST is a list of conses or objects. Each element (or the element's car,
4107 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
4108 If that is non-nil, the element matches;
4109 then `assoc-default' returns the element's cdr, if it is a cons,
4110 or DEFAULT if the element is not a cons.
4112 If no element matches, the value is nil.
4113 If TEST is omitted or nil, `equal' is used."
4114 (let (found (tail alist) value)
4115 (while (and tail (not found))
4116 (let ((elt (car tail)))
4117 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
4118 (setq found t value (if (consp elt) (cdr elt) default))))
4119 (setq tail (cdr tail)))
4120 value)))
4122 ;; Function not available in XEmacs,
4123 (unless (fboundp 'minibuffer-contents)
4124 (defun minibuffer-contents ()
4125 "Return the user input in a minbuffer as a string.
4126 The current buffer must be a minibuffer."
4127 (field-string (point-max)))
4129 (defun delete-minibuffer-contents ()
4130 "Delete all user input in a minibuffer.
4131 The current buffer must be a minibuffer."
4132 (delete-field (point-max))))
4134 ;; Function not available in older Emacs (<= 22.1).
4135 (unless (fboundp 'buffer-chars-modified-tick)
4136 (defun buffer-chars-modified-tick (&optional buffer)
4137 "Return BUFFER's character-change tick counter.
4138 Each buffer has a character-change tick counter, which is set to the
4139 value of the buffer's tick counter (see `buffer-modified-tick'), each
4140 time text in that buffer is inserted or deleted. By comparing the
4141 values returned by two individual calls of `buffer-chars-modified-tick',
4142 you can tell whether a character change occurred in that buffer in
4143 between these calls. No argument or nil as argument means use current
4144 buffer as BUFFER."
4145 (with-current-buffer (or buffer (current-buffer))
4146 (if (listp buffer-undo-list)
4147 (length buffer-undo-list)
4148 (buffer-modified-tick)))))
4150 ;;(@* "Attribute Documentation")
4151 (defun anything-describe-anything-attribute (anything-attribute)
4152 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol)."
4153 (interactive (list (intern
4154 (completing-read
4155 "Describe anything attribute: "
4156 (mapcar 'symbol-name anything-additional-attributes)))))
4157 (with-output-to-temp-buffer "*Help*"
4158 (princ (get anything-attribute 'anything-attrdoc))))
4160 (anything-document-attribute 'name "mandatory"
4161 " The name of the source. It is also the heading which appears
4162 above the list of matches from the source. Must be unique. ")
4163 (anything-document-attribute 'header-name "optional"
4164 " A function returning the display string of the header. Its
4165 argument is the name of the source. This attribute is useful to
4166 add an additional information with the source name. ")
4167 (anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
4168 " Specifies how to retrieve candidates from the source. It can
4169 either be a variable name, a function called with no parameters
4170 or the actual list of candidates.
4172 The list must be a list whose members are strings, symbols
4173 or (DISPLAY . REAL) pairs.
4175 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
4176 in the Anything buffer, but the REAL one is used as action
4177 argument when the candidate is selected. This allows a more
4178 readable presentation for candidates which would otherwise be,
4179 for example, too long or have a common part shared with other
4180 candidates which can be safely replaced with an abbreviated
4181 string for display purposes.
4183 Note that if the (DISPLAY . REAL) form is used then pattern
4184 matching is done on the displayed string, not on the real
4185 value.
4187 If the candidates have to be retrieved asynchronously (for
4188 example, by an external command which takes a while to run)
4189 then the function should start the external command
4190 asynchronously and return the associated process object.
4191 Anything will take care of managing the process (receiving the
4192 output from it, killing it if necessary, etc.). The process
4193 should return candidates matching the current pattern (see
4194 variable `anything-pattern'.)
4196 Note that currently results from asynchronous sources appear
4197 last in the anything buffer regardless of their position in
4198 `anything-sources'. ")
4199 (anything-document-attribute 'action "mandatory if type attribute is not provided"
4200 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
4201 FUNCTION is called with one parameter: the selected candidate.
4203 An action other than the default can be chosen from this list
4204 of actions for the currently selected candidate (by default
4205 with TAB). The DISPLAY string is shown in the completions
4206 buffer and the FUNCTION is invoked when an action is
4207 selected. The first action of the list is the default. ")
4208 (anything-document-attribute 'type "optional if action attribute is provided"
4209 " Indicates the type of the items the source returns.
4211 Merge attributes not specified in the source itself from
4212 `anything-type-attributes'.
4214 This attribute is implemented by plug-in. ")
4215 (anything-document-attribute 'init "optional"
4216 " Function called with no parameters when anything is started. It
4217 is useful for collecting current state information which can be
4218 used to create the list of candidates later.
4220 For example, if a source needs to work with the current
4221 directory then it can store its value here, because later
4222 anything does its job in the minibuffer and in the
4223 `anything-buffer' and the current directory can be different
4224 there. ")
4225 (anything-document-attribute 'delayed-init "optional"
4226 " Function called with no parameters before candidate function is
4227 called. It is similar with `init' attribute, but its
4228 evaluation is deferred. It is useful to combine with ")
4229 (anything-document-attribute 'match "optional"
4230 " List of functions called with one parameter: a candidate. The
4231 function should return non-nil if the candidate matches the
4232 current pattern (see variable `anything-pattern').
4234 This attribute allows the source to override the default
4235 pattern matching based on `string-match'. It can be used, for
4236 example, to implement a source for file names and do the
4237 pattern matching on the basename of files, since it's more
4238 likely one is typing part of the basename when searching for a
4239 file, instead of some string anywhere else in its path.
4241 If the list contains more than one function then the list of
4242 matching candidates from the source is constructed by appending
4243 the results after invoking the first function on all the
4244 potential candidates, then the next function, and so on. The
4245 matching candidates supplied by the first function appear first
4246 in the list of results and then results from the other
4247 functions, respectively.
4249 This attribute has no effect for asynchronous sources (see
4250 attribute `candidates'), since they perform pattern matching
4251 themselves. ")
4252 (anything-document-attribute 'candidate-transformer "optional"
4253 " It's a function or a list of functions called with one argument
4254 when the completion list from the source is built. The argument
4255 is the list of candidates retrieved from the source. The
4256 function should return a transformed list of candidates which
4257 will be used for the actual completion. If it is a list of
4258 functions, it calls each function sequentially.
4260 This can be used to transform or remove items from the list of
4261 candidates.
4263 Note that `candidates' is run already, so the given transformer
4264 function should also be able to handle candidates with (DISPLAY
4265 . REAL) format. ")
4266 (anything-document-attribute 'filtered-candidate-transformer "optional"
4267 " It has the same format as `candidate-transformer', except the
4268 function is called with two parameters: the candidate list and
4269 the source.
4271 This transformer is run on the candidate list which is already
4272 filtered by the current pattern. While `candidate-transformer'
4273 is run only once, it is run every time the input pattern is
4274 changed.
4276 It can be used to transform the candidate list dynamically, for
4277 example, based on the current pattern.
4279 In some cases it may also be more efficent to perform candidate
4280 transformation here, instead of with `candidate-transformer'
4281 even if this transformation is done every time the pattern is
4282 changed. For example, if a candidate set is very large then
4283 `candidate-transformer' transforms every candidate while only
4284 some of them will actually be dislpayed due to the limit
4285 imposed by `anything-candidate-number-limit'.
4287 Note that `candidates' and `candidate-transformer' is run
4288 already, so the given transformer function should also be able
4289 to handle candidates with (DISPLAY . REAL) format.
4291 This option has no effect for asynchronous sources. (Not yet,
4292 at least. ")
4293 (anything-document-attribute 'action-transformer "optional"
4294 " It's a function or a list of functions called with two
4295 arguments when the action list from the source is
4296 assembled. The first argument is the list of actions, the
4297 second is the current selection. If it is a list of functions,
4298 it calls each function sequentially.
4300 The function should return a transformed action list.
4302 This can be used to customize the list of actions based on the
4303 currently selected candidate. ")
4304 (anything-document-attribute 'pattern-transformer "optional"
4305 " It's a function or a list of functions called with one argument
4306 before computing matches. Its argument is `anything-pattern'.
4307 Functions should return transformed `anything-pattern'.
4309 It is useful to change interpretation of `anything-pattern'. ")
4310 (anything-document-attribute 'delayed "optional"
4311 " Candidates from the source are shown only if the user stops
4312 typing and is idle for `anything-idle-delay' seconds. ")
4313 (anything-document-attribute 'volatile "optional"
4314 " Indicates the source assembles the candidate list dynamically,
4315 so it shouldn't be cached within a single Anything
4316 invocation. It is only applicable to synchronous sources,
4317 because asynchronous sources are not cached. ")
4318 (anything-document-attribute 'requires-pattern "optional"
4319 " If present matches from the source are shown only if the
4320 pattern is not empty. Optionally, it can have an integer
4321 parameter specifying the required length of input which is
4322 useful in case of sources with lots of candidates. ")
4323 (anything-document-attribute 'persistent-action "optional"
4324 " Function called with one parameter; the selected candidate.
4326 An action performed by `anything-execute-persistent-action'.
4327 If none, use the default action. ")
4328 (anything-document-attribute 'candidates-in-buffer "optional"
4329 " Shortcut attribute for making and narrowing candidates using
4330 buffers. This newly-introduced attribute prevents us from
4331 forgetting to add volatile and match attributes.
4333 See docstring of `anything-candidates-in-buffer'.
4335 (candidates-in-buffer) is equivalent of three attributes:
4336 (candidates . anything-candidates-in-buffer)
4337 (volatile)
4338 (match identity)
4340 (candidates-in-buffer . candidates-function) is equivalent of:
4341 (candidates . candidates-function)
4342 (volatile)
4343 (match identity)
4345 This attribute is implemented by plug-in. ")
4346 (anything-document-attribute 'search "optional"
4347 " List of functions like `re-search-forward' or `search-forward'.
4348 Buffer search function used by `anything-candidates-in-buffer'.
4349 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4350 This attribute is meant to be used with
4351 (candidates . anything-candidates-in-buffer) or
4352 (candidates-in-buffer) in short. ")
4353 (anything-document-attribute 'search-from-end "optional"
4354 " Make `anything-candidates-in-buffer' search from the end of buffer.
4355 If this attribute is specified, `anything-candidates-in-buffer' uses
4356 `re-search-backward' instead. ")
4357 (anything-document-attribute 'get-line "optional"
4358 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4359 This function converts point of line-beginning and point of line-end,
4360 which represents a candidate computed by `anything-candidates-in-buffer'.
4361 By default, `anything-candidates-in-buffer' uses
4362 `buffer-substring-no-properties'. ")
4363 (anything-document-attribute 'display-to-real "optional"
4364 " Function called with one parameter; the selected candidate.
4366 The function transforms the selected candidate, and the result
4367 is passed to the action function. The display-to-real
4368 attribute provides another way to pass other string than one
4369 shown in Anything buffer.
4371 Traditionally, it is possible to make candidates,
4372 candidate-transformer or filtered-candidate-transformer
4373 function return a list with (DISPLAY . REAL) pairs. But if REAL
4374 can be generated from DISPLAY, display-to-real is more
4375 convenient and faster. ")
4376 (anything-document-attribute 'real-to-display "optional"
4377 " Function called with one parameter; the selected candidate.
4379 The inverse of display-to-real attribute.
4381 The function transforms the selected candidate, which is passed
4382 to the action function, for display. The real-to-display
4383 attribute provides the other way to pass other string than one
4384 shown in Anything buffer.
4386 Traditionally, it is possible to make candidates,
4387 candidate-transformer or filtered-candidate-transformer
4388 function return a list with (DISPLAY . REAL) pairs. But if
4389 DISPLAY can be generated from REAL, real-to-display is more
4390 convenient.
4392 Note that DISPLAY parts returned from candidates /
4393 candidate-transformer are IGNORED as the name `display-to-real'
4394 says. ")
4395 (anything-document-attribute 'cleanup "optional"
4396 " Function called with no parameters when *anything* buffer is closed. It
4397 is useful for killing unneeded candidates buffer.
4399 Note that the function is executed BEFORE performing action. ")
4400 (anything-document-attribute 'candidate-number-limit "optional"
4401 " Override `anything-candidate-number-limit' only for this source. ")
4402 (anything-document-attribute 'accept-empty "optional"
4403 " Pass empty string \"\" to action function. ")
4404 (anything-document-attribute 'disable-shortcuts "optional"
4405 " Disable `anything-enable-shortcuts' in current `anything' session.
4407 This attribute is implemented by plug-in. ")
4408 (anything-document-attribute 'dummy "optional"
4409 " Set `anything-pattern' to candidate. If this attribute is
4410 specified, The candidates attribute is ignored.
4412 This attribute is implemented by plug-in.
4413 This plug-in implies disable-shortcuts plug-in. ")
4414 (anything-document-attribute 'multiline "optional"
4415 " Enable to selection multiline candidates. ")
4416 (anything-document-attribute 'update "optional"
4417 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4418 (anything-document-attribute 'mode-line "optional"
4419 " source local `anything-mode-line-string'. (included in `mode-line-format')
4420 It accepts also variable/function name. ")
4421 (anything-document-attribute 'header-line "optional"
4422 " source local `header-line-format'.
4423 It accepts also variable/function name. ")
4424 (anything-document-attribute 'resume "optional" " Function called with no parameters when `anything-resume' is started.")
4426 ;; (@* "Unit Tests")
4428 (defun* anything-test-candidates (sources &optional (input "") (compile-source-functions anything-compile-source-functions-default))
4429 "Test helper function for anything.
4430 Given pseudo `anything-sources' and `anything-pattern', returns list like
4431 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4432 (\"source name2\" (\"candidate3\" \"candidate4\")))
4434 (let ((anything-test-mode t)
4435 anything-enable-shortcuts
4436 anything-candidate-cache
4437 (anything-sources (anything-normalize-sources sources))
4438 (anything-compile-source-functions compile-source-functions)
4439 anything-before-initialize-hook
4440 anything-after-initialize-hook
4441 anything-update-hook
4442 anything-test-candidate-list)
4443 (get-buffer-create anything-buffer)
4445 (anything-initialize)
4446 (setq anything-input input anything-pattern input)
4447 (anything-update)
4448 ;; test-mode spec: select 1st candidate!
4449 (with-current-buffer anything-buffer
4450 (forward-line 1)
4451 (anything-mark-current-line))
4452 (prog1
4453 anything-test-candidate-list
4454 (anything-cleanup))))
4456 (defmacro anything-test-update (sources pattern)
4457 "Test helper macro for anything. It is meant for testing *anything* buffer contents."
4458 `(progn (stub anything-get-sources => ,sources)
4459 (stub run-hooks => nil)
4460 (stub anything-maybe-fit-frame => nil)
4461 (stub run-with-idle-timer => nil)
4462 (let (anything-test-mode (anything-pattern ,pattern))
4463 (anything-update))))
4465 ;;;; unit test
4466 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4467 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
4468 (dont-compile
4469 (when (fboundp 'expectations)
4470 (expectations
4471 (desc "anything-current-buffer")
4472 (expect "__a_buffer"
4473 (with-current-buffer (get-buffer-create "__a_buffer")
4474 (anything-test-candidates '(((name . "FOO"))) "")
4475 (prog1
4476 (buffer-name anything-current-buffer)
4477 (kill-buffer "__a_buffer")
4479 (desc "anything-buffer-file-name")
4480 (expect (regexp "/__a_file__")
4481 (with-current-buffer (get-buffer-create "__a_file__")
4482 (setq buffer-file-name "/__a_file__")
4483 (anything-test-candidates '(((name . "FOO"))) "")
4484 (prog1
4485 anything-buffer-file-name
4486 ;;(kill-buffer "__a_file__")
4488 (desc "anything-interpret-value")
4489 (expect "literal"
4490 (anything-interpret-value "literal"))
4491 (expect "lambda"
4492 (anything-interpret-value (lambda () "lambda")))
4493 (expect "lambda with source name"
4494 (let ((source '((name . "lambda with source name"))))
4495 (anything-interpret-value (lambda () anything-source-name) source)))
4496 (expect "function symbol"
4497 (flet ((f () "function symbol"))
4498 (anything-interpret-value 'f)))
4499 (expect "variable symbol"
4500 (let ((v "variable symbol"))
4501 (anything-interpret-value 'v)))
4502 (expect (error error *)
4503 (anything-interpret-value 'unbounded-1))
4504 (desc "anything-compile-sources")
4505 (expect '(((name . "foo")))
4506 (anything-compile-sources '(((name . "foo"))) nil)
4508 (expect '(((name . "foo") (type . test) (action . identity)))
4509 (let ((anything-type-attributes '((test (action . identity)))))
4510 (anything-compile-sources '(((name . "foo") (type . test)))
4511 '(anything-compile-source--type))))
4512 (desc "anything-sources accepts symbols")
4513 (expect '(((name . "foo")))
4514 (let* ((foo '((name . "foo"))))
4515 (anything-compile-sources '(foo) nil)))
4516 (desc "anything-get-sources action")
4517 (expect '(((name . "Actions") (candidates . actions)))
4518 (stub anything-action-window => t)
4519 (let (anything-compiled-sources
4520 (anything-sources '(((name . "Actions") (candidates . actions)))))
4521 (anything-get-sources)))
4522 (desc "get-buffer-create candidates-buffer")
4523 (expect '(((name . "many") (init . many-init)
4524 (candidates-in-buffer . anything-candidates-in-buffer)
4525 (candidates . anything-candidates-in-buffer)
4526 (volatile) (match identity)))
4527 (anything-compile-sources
4528 '(((name . "many") (init . many-init)
4529 (candidates-in-buffer . anything-candidates-in-buffer)))
4530 '(anything-compile-source--candidates-in-buffer)))
4531 (expect '(((name . "many") (init . many-init)
4532 (candidates-in-buffer)
4533 (candidates . anything-candidates-in-buffer)
4534 (volatile) (match identity)))
4535 (anything-compile-sources
4536 '(((name . "many") (init . many-init)
4537 (candidates-in-buffer)))
4538 '(anything-compile-source--candidates-in-buffer)))
4539 (expect '(((name . "many") (init . many-init)
4540 (candidates-in-buffer)
4541 (type . test)
4542 (action . identity)
4543 (candidates . anything-candidates-in-buffer)
4544 (volatile) (match identity)))
4545 (let ((anything-type-attributes '((test (action . identity)))))
4546 (anything-compile-sources
4547 '(((name . "many") (init . many-init)
4548 (candidates-in-buffer)
4549 (type . test)))
4550 '(anything-compile-source--type
4551 anything-compile-source--candidates-in-buffer))))
4553 (desc "anything-get-candidates")
4554 (expect '("foo" "bar")
4555 (anything-get-candidates '((name . "foo") (candidates "foo" "bar"))))
4556 (expect '("FOO" "BAR")
4557 (anything-get-candidates '((name . "foo") (candidates "foo" "bar")
4558 (candidate-transformer
4559 . (lambda (cands) (mapcar 'upcase cands))))))
4560 (expect '("foo" "bar")
4561 (anything-get-candidates '((name . "foo")
4562 (candidates . (lambda () '("foo" "bar"))))))
4563 (expect '("foo" "bar")
4564 (let ((var '("foo" "bar")))
4565 (anything-get-candidates '((name . "foo")
4566 (candidates . var)))))
4567 (expect (error error *)
4568 (anything-get-candidates '((name . "foo")
4569 (candidates . "err"))))
4570 (expect (error error *)
4571 (let ((var "err"))
4572 (anything-get-candidates '((name . "foo")
4573 (candidates . var)))))
4574 (desc "anything-compute-matches")
4575 (expect '("foo" "bar")
4576 (let ((anything-pattern ""))
4577 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4578 (expect '("foo")
4579 (let ((anything-pattern "oo"))
4580 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4581 (expect '("bar")
4582 (let ((anything-pattern "^b"))
4583 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4584 (expect '("a" "b")
4585 (let ((anything-pattern "")
4586 (anything-candidate-number-limit 2))
4587 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4588 (expect '("a" "b")
4589 (let ((anything-pattern ".")
4590 (anything-candidate-number-limit 2))
4591 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4592 (expect '("a" "b" "c")
4593 (let ((anything-pattern "")
4594 anything-candidate-number-limit)
4595 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4596 (expect '("a" "b" "c")
4597 (let ((anything-pattern "[abc]")
4598 anything-candidate-number-limit)
4599 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4600 ;; using anything-test-candidate-list
4601 (desc "anything-test-candidates")
4602 (expect '(("FOO" ("foo" "bar")))
4603 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")))))
4604 (expect '(("FOO" ("bar")))
4605 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar"))) "ar"))
4606 (expect '(("T1" ("hoge" "aiue"))
4607 ("T2" ("test" "boke")))
4608 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4609 ((name . "T2") (candidates "test" "boke")))))
4610 (expect '(("T1" ("hoge"))
4611 ("T2" ("boke")))
4612 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4613 ((name . "T2") (candidates "test" "boke"))) "o"))
4614 (desc "requires-pattern attribute")
4615 (expect nil
4616 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4617 (requires-pattern . 1)))))
4618 (expect '(("FOO" ("bar")))
4619 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4620 (requires-pattern . 1))) "b"))
4621 (desc "delayed attribute(for test)")
4622 (expect '(("T2" ("boke"))
4623 ("T1" ("hoge")))
4624 (anything-test-candidates
4625 '(((name . "T1") (candidates "hoge" "aiue") (delayed))
4626 ((name . "T2") (candidates "test" "boke")))
4627 "o"))
4628 (desc "match attribute(prefix search)")
4629 (expect '(("FOO" ("bar")))
4630 (anything-test-candidates
4631 '(((name . "FOO") (candidates "foo" "bar")
4632 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4633 "ba"))
4634 (expect nil
4635 (anything-test-candidates
4636 '(((name . "FOO") (candidates "foo" "bar")
4637 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4638 "ar"))
4639 (desc "init attribute")
4640 (expect '(("FOO" ("bar")))
4641 (let (v)
4642 (anything-test-candidates
4643 '(((name . "FOO") (init . (lambda () (setq v '("foo" "bar"))))
4644 (candidates . v)))
4645 "ar")))
4646 (desc "candidate-transformer attribute")
4647 (expect '(("FOO" ("BAR")))
4648 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4649 (candidate-transformer
4650 . (lambda (cands) (mapcar 'upcase cands)))))
4651 "ar"))
4652 (desc "filtered-candidate-transformer attribute")
4653 ;; needs more tests
4654 (expect '(("FOO" ("BAR")))
4655 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4656 (filtered-candidate-transformer
4657 . (lambda (cands src) (mapcar 'upcase cands)))))
4658 "ar"))
4659 (desc "anything-candidates-in-buffer-1")
4660 (expect nil
4661 (anything-candidates-in-buffer-1 nil))
4662 (expect '("foo+" "bar+" "baz+")
4663 (with-temp-buffer
4664 (insert "foo+\nbar+\nbaz+\n")
4665 (let ((anything-candidate-number-limit 5))
4666 (anything-candidates-in-buffer-1 (current-buffer) ""))))
4667 (expect '("foo+" "bar+")
4668 (with-temp-buffer
4669 (insert "foo+\nbar+\nbaz+\n")
4670 (let ((anything-candidate-number-limit 2))
4671 (anything-candidates-in-buffer-1 (current-buffer) ""))))
4672 (expect '("foo+")
4673 (with-temp-buffer
4674 (insert "foo+\nbar+\nbaz+\n")
4675 (anything-candidates-in-buffer-1 (current-buffer) "oo\\+")))
4676 (expect '("foo+")
4677 (with-temp-buffer
4678 (insert "foo+\nbar+\nbaz+\n")
4679 (anything-candidates-in-buffer-1
4680 (current-buffer) "oo+"
4681 #'buffer-substring-no-properties '(search-forward))))
4682 (expect '(("foo+" "FOO+"))
4683 (with-temp-buffer
4684 (insert "foo+\nbar+\nbaz+\n")
4685 (anything-candidates-in-buffer-1
4686 (current-buffer) "oo\\+"
4687 (lambda (s e)
4688 (let ((l (buffer-substring-no-properties s e)))
4689 (list l (upcase l)))))))
4690 (desc "anything-candidates-in-buffer")
4691 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4692 (anything-test-candidates
4693 '(((name . "TEST")
4694 (init
4695 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4696 (insert "foo+\nbar+\nbaz+\n"))))
4697 (candidates . anything-candidates-in-buffer)
4698 (match identity)
4699 (volatile)))))
4700 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4701 (let (anything-candidate-number-limit)
4702 (anything-test-candidates
4703 '(((name . "TEST")
4704 (init
4705 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4706 (insert "foo+\nbar+\nbaz+\n"))))
4707 (candidates . anything-candidates-in-buffer)
4708 (match identity)
4709 (volatile))))))
4710 (expect '(("TEST" ("foo+")))
4711 (anything-test-candidates
4712 '(((name . "TEST")
4713 (init
4714 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4715 (insert "foo+\nbar+\nbaz+\n"))))
4716 (candidates . anything-candidates-in-buffer)
4717 (match identity)
4718 (volatile)))
4719 "oo\\+"))
4720 (desc "search attribute")
4721 (expect '(("TEST" ("foo+")))
4722 (anything-test-candidates
4723 '(((name . "TEST")
4724 (init
4725 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4726 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4727 (search search-forward)
4728 (candidates . anything-candidates-in-buffer)
4729 (match identity)
4730 (volatile)))
4731 "oo+"))
4732 (expect '(("TEST" ("foo+" "ooo")))
4733 (anything-test-candidates
4734 '(((name . "TEST")
4735 (init
4736 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4737 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4738 (search search-forward re-search-forward)
4739 (candidates . anything-candidates-in-buffer)
4740 (match identity)
4741 (volatile)))
4742 "oo+"))
4743 (expect '(("TEST" ("foo+" "ooo")))
4744 (anything-test-candidates
4745 '(((name . "TEST")
4746 (init
4747 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4748 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4749 (search re-search-forward search-forward)
4750 (candidates . anything-candidates-in-buffer)
4751 (match identity)
4752 (volatile)))
4753 "oo+"))
4754 (expect '(("TEST" ("ooo" "foo+")))
4755 (anything-test-candidates
4756 '(((name . "TEST")
4757 (init
4758 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4759 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4760 (search re-search-forward search-forward)
4761 (candidates . anything-candidates-in-buffer)
4762 (match identity)
4763 (volatile)))
4764 "oo+"))
4765 ;; faster exact match
4766 (expect '(("TEST" ("bar+")))
4767 (anything-test-candidates
4768 '(((name . "TEST")
4769 (init
4770 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4771 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4772 (search (lambda (pattern &rest _)
4773 (and (search-forward (concat "\n" pattern "\n") nil t)
4774 (forward-line -1))))
4775 (candidates . anything-candidates-in-buffer)
4776 (match identity)
4777 (volatile)))
4778 "bar+"))
4779 ;; faster prefix match
4780 (expect '(("TEST" ("bar+")))
4781 (anything-test-candidates
4782 '(((name . "TEST")
4783 (init
4784 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4785 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4786 (search (lambda (pattern &rest _)
4787 (search-forward (concat "\n" pattern) nil t)))
4788 (candidates . anything-candidates-in-buffer)
4789 (match identity)
4790 (volatile)))
4791 "ba"))
4792 (desc "anything-current-buffer-is-modified")
4793 (expect '(("FOO" ("modified")))
4794 (let ((sources '(((name . "FOO")
4795 (candidates
4796 . (lambda ()
4797 (if (anything-current-buffer-is-modified)
4798 '("modified")
4799 '("unmodified"))))))))
4800 (with-temp-buffer
4801 (clrhash anything-tick-hash)
4802 (insert "1")
4803 (anything-test-candidates sources))))
4804 (expect '(("FOO" ("unmodified")))
4805 (let ((sources '(((name . "FOO")
4806 (candidates
4807 . (lambda ()
4808 (if (anything-current-buffer-is-modified)
4809 '("modified")
4810 '("unmodified"))))))))
4811 (with-temp-buffer
4812 (clrhash anything-tick-hash)
4813 (insert "1")
4814 (anything-test-candidates sources)
4815 (anything-test-candidates sources))))
4816 (expect '(("FOO" ("modified")))
4817 (let ((sources '(((name . "FOO")
4818 (candidates
4819 . (lambda ()
4820 (if (anything-current-buffer-is-modified)
4821 '("modified")
4822 '("unmodified"))))))))
4823 (with-temp-buffer
4824 (clrhash anything-tick-hash)
4825 (insert "1")
4826 (anything-test-candidates sources)
4827 (insert "2")
4828 (anything-test-candidates sources))))
4829 (expect '(("BAR" ("modified")))
4830 (let ((sources1 '(((name . "FOO")
4831 (candidates
4832 . (lambda ()
4833 (if (anything-current-buffer-is-modified)
4834 '("modified")
4835 '("unmodified")))))))
4836 (sources2 '(((name . "BAR")
4837 (candidates
4838 . (lambda ()
4839 (if (anything-current-buffer-is-modified)
4840 '("modified")
4841 '("unmodified"))))))))
4842 (with-temp-buffer
4843 (clrhash anything-tick-hash)
4844 (insert "1")
4845 (anything-test-candidates sources1)
4846 (anything-test-candidates sources2))))
4847 (expect '(("FOO" ("unmodified")))
4848 (let ((sources1 '(((name . "FOO")
4849 (candidates
4850 . (lambda ()
4851 (if (anything-current-buffer-is-modified)
4852 '("modified")
4853 '("unmodified")))))))
4854 (sources2 '(((name . "BAR")
4855 (candidates
4856 . (lambda ()
4857 (if (anything-current-buffer-is-modified)
4858 '("modified")
4859 '("unmodified"))))))))
4860 (with-temp-buffer
4861 (clrhash anything-tick-hash)
4862 (insert "1")
4863 (anything-test-candidates sources1)
4864 (anything-test-candidates sources2)
4865 (anything-test-candidates sources1))))
4866 (expect '(("BAR" ("unmodified")))
4867 (let ((sources1 '(((name . "FOO")
4868 (candidates
4869 . (lambda ()
4870 (if (anything-current-buffer-is-modified)
4871 '("modified")
4872 '("unmodified")))))))
4873 (sources2 '(((name . "BAR")
4874 (candidates
4875 . (lambda ()
4876 (if (anything-current-buffer-is-modified)
4877 '("modified")
4878 '("unmodified"))))))))
4879 (with-temp-buffer
4880 (clrhash anything-tick-hash)
4881 (insert "1")
4882 (anything-test-candidates sources1)
4883 (anything-test-candidates sources2)
4884 (anything-test-candidates sources2))))
4885 (expect '(("BAR" ("modified")))
4886 (let ((sources1 '(((name . "FOO")
4887 (candidates
4888 . (lambda ()
4889 (if (anything-current-buffer-is-modified)
4890 '("modified")
4891 '("unmodified")))))))
4892 (sources2 '(((name . "BAR")
4893 (candidates
4894 . (lambda ()
4895 (if (anything-current-buffer-is-modified)
4896 '("modified")
4897 '("unmodified"))))))))
4898 (with-temp-buffer
4899 (clrhash anything-tick-hash)
4900 (insert "1")
4901 (anything-test-candidates sources1)
4902 (anything-test-candidates sources2)
4903 (with-temp-buffer
4904 (anything-test-candidates sources2)))))
4905 (desc "anything-source-name")
4906 (expect "FOO"
4907 (let (v)
4908 (anything-test-candidates '(((name . "FOO")
4909 (init
4910 . (lambda () (setq v anything-source-name)))
4911 (candidates "ok"))))
4913 (expect "FOO"
4914 (let (v)
4915 (anything-test-candidates '(((name . "FOO")
4916 (candidates
4917 . (lambda ()
4918 (setq v anything-source-name)
4919 '("ok"))))))
4921 (expect "FOO"
4922 (let (v)
4923 (anything-test-candidates '(((name . "FOO")
4924 (candidates "ok")
4925 (candidate-transformer
4926 . (lambda (c)
4927 (setq v anything-source-name)
4928 c)))))
4930 (expect "FOO"
4931 (let (v)
4932 (anything-test-candidates '(((name . "FOO")
4933 (candidates "ok")
4934 (filtered-candidate-transformer
4935 . (lambda (c s)
4936 (setq v anything-source-name)
4937 c)))))
4939 (expect "FOO"
4940 (let (v)
4941 (anything-test-candidates '(((name . "FOO")
4942 (candidates "ok")
4943 (display-to-real
4944 . (lambda (c)
4945 (setq v anything-source-name)
4947 (action . identity))))
4948 (anything-execute-selection-action)
4950 (desc "anything-candidate-buffer create")
4951 (expect " *anything candidates:FOO*"
4952 (let* (anything-candidate-buffer-alist
4953 (anything-source-name "FOO")
4954 (buf (anything-candidate-buffer 'global)))
4955 (prog1 (buffer-name buf)
4956 (kill-buffer buf))))
4957 (expect " *anything candidates:FOO*aTestBuffer"
4958 (let* (anything-candidate-buffer-alist
4959 (anything-source-name "FOO")
4960 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4961 (buf (anything-candidate-buffer 'local)))
4962 (prog1 (buffer-name buf)
4963 (kill-buffer anything-current-buffer)
4964 (kill-buffer buf))))
4965 (expect 0
4966 (let (anything-candidate-buffer-alist
4967 (anything-source-name "FOO") buf)
4968 (with-current-buffer (anything-candidate-buffer 'global)
4969 (insert "1"))
4970 (setq buf (anything-candidate-buffer 'global))
4971 (prog1 (buffer-size buf)
4972 (kill-buffer buf))))
4973 (desc "anything-candidate-buffer get-buffer")
4974 (expect " *anything candidates:FOO*"
4975 (let* (anything-candidate-buffer-alist
4976 (anything-source-name "FOO")
4977 (buf (anything-candidate-buffer 'global)))
4978 (prog1 (buffer-name (anything-candidate-buffer))
4979 (kill-buffer buf))))
4980 (expect " *anything candidates:FOO*aTestBuffer"
4981 (let* (anything-candidate-buffer-alist
4982 (anything-source-name "FOO")
4983 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4984 (buf (anything-candidate-buffer 'local)))
4985 (prog1 (buffer-name (anything-candidate-buffer))
4986 (kill-buffer anything-current-buffer)
4987 (kill-buffer buf))))
4988 (expect " *anything candidates:FOO*"
4989 (let* (anything-candidate-buffer-alist
4990 (anything-source-name "FOO")
4991 (buf-local (anything-candidate-buffer 'local))
4992 (buf-global (anything-candidate-buffer 'global)))
4993 (prog1 (buffer-name (anything-candidate-buffer))
4994 (kill-buffer buf-local)
4995 (kill-buffer buf-global))))
4996 (expect " *anything candidates:FOO*aTestBuffer"
4997 (let* (anything-candidate-buffer-alist
4998 (anything-source-name "FOO")
4999 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5000 (buf-global (anything-candidate-buffer 'global))
5001 (buf-local (anything-candidate-buffer 'local)))
5002 (prog1 (buffer-name (anything-candidate-buffer))
5003 (kill-buffer buf-local)
5004 (kill-buffer buf-global))))
5005 (expect nil
5006 (let* (anything-candidate-buffer-alist
5007 (anything-source-name "NOP__"))
5008 (anything-candidate-buffer)))
5009 (desc "anything-candidate-buffer register-buffer")
5010 (expect " *anything test candidates*"
5011 (let (anything-candidate-buffer-alist
5012 (buf (get-buffer-create " *anything test candidates*")))
5013 (with-current-buffer buf
5014 (insert "1\n2\n")
5015 (prog1 (buffer-name (anything-candidate-buffer buf))
5016 (kill-buffer (current-buffer))))))
5017 (expect " *anything test candidates*"
5018 (let (anything-candidate-buffer-alist
5019 (buf (get-buffer-create " *anything test candidates*")))
5020 (with-current-buffer buf
5021 (insert "1\n2\n")
5022 (anything-candidate-buffer buf)
5023 (prog1 (buffer-name (anything-candidate-buffer))
5024 (kill-buffer (current-buffer))))))
5025 (expect "1\n2\n"
5026 (let (anything-candidate-buffer-alist
5027 (buf (get-buffer-create " *anything test candidates*")))
5028 (with-current-buffer buf
5029 (insert "1\n2\n")
5030 (anything-candidate-buffer buf)
5031 (prog1 (buffer-string)
5032 (kill-buffer (current-buffer))))))
5033 (expect "buf1"
5034 (let (anything-candidate-buffer-alist
5035 (anything-source-name "foo")
5036 (buf1 (get-buffer-create "buf1"))
5037 (buf2 (get-buffer-create "buf2")))
5038 (anything-candidate-buffer buf1)
5039 (anything-candidate-buffer buf2)
5040 (prog1 (buffer-name (anything-candidate-buffer buf1))
5041 (kill-buffer buf1)
5042 (kill-buffer buf2))))
5043 (desc "action attribute")
5044 (expect "foo"
5045 (anything-test-candidates
5046 '(((name . "TEST")
5047 (candidates "foo")
5048 (action ("identity" . identity)))))
5049 (anything-execute-selection-action))
5050 (expect "foo"
5051 (anything-test-candidates
5052 '(((name . "TEST")
5053 (candidates "foo")
5054 (action ("identity" . (lambda (c) (identity c)))))))
5055 (anything-execute-selection-action))
5056 (desc "anything-execute-selection-action")
5057 (expect "FOO"
5058 (anything-execute-selection-action
5059 "foo" '(("upcase" . upcase)) nil #'identity))
5060 (expect "FOO"
5061 (anything-execute-selection-action
5062 "foo" '(("upcase" . (lambda (c) (upcase c)))) nil #'identity))
5063 (desc "display-to-real attribute")
5064 (expect "FOO"
5065 (anything-execute-selection-action
5066 "foo"
5067 '(("identity" . identity))
5069 #'upcase
5071 (expect "FOO"
5072 (anything-test-candidates
5073 '(((name . "TEST")
5074 (candidates "foo")
5075 (display-to-real . upcase)
5076 (action ("identity" . identity)))))
5077 (anything-execute-selection-action))
5078 (desc "cleanup test")
5079 (expect 'cleaned
5080 (let (v)
5081 (anything-test-candidates
5082 '(((name . "TEST")
5083 (cleanup . (lambda () (setq v 'cleaned))))))
5085 (desc "anything-get-current-source")
5086 ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
5087 ;; display-to-real/cleanup function
5088 (expect "FOO"
5089 (assoc-default
5090 'name
5091 (anything-funcall-with-source '((name . "FOO")) 'anything-get-current-source)))
5092 ;; init
5093 (expect "FOO"
5094 (let (v)
5095 (anything-test-candidates
5096 '(((name . "FOO")
5097 (init . (lambda () (setq v (anything-get-current-source)))))))
5098 (assoc-default 'name v)))
5099 ;; candidates
5100 (expect "FOO"
5101 (let (v)
5102 (anything-test-candidates
5103 '(((name . "FOO")
5104 (candidates . (lambda () (setq v (anything-get-current-source)) '("a"))))))
5105 (assoc-default 'name v)))
5106 ;; action
5107 (expect "FOO"
5108 (let (v)
5109 (anything-test-candidates
5110 '(((name . "FOO")
5111 (candidates "a")
5112 (action
5113 . (lambda (c) (setq v (anything-get-current-source)) c)))))
5114 (anything-execute-selection-action)
5115 (assoc-default 'name v)))
5116 ;; candidate-transformer
5117 (expect "FOO"
5118 (let (v)
5119 (anything-test-candidates
5120 '(((name . "FOO")
5121 (candidates "a")
5122 (candidate-transformer
5123 . (lambda (c) (setq v (anything-get-current-source)) c)))))
5124 (assoc-default 'name v)))
5125 ;; filtered-candidate-transformer
5126 (expect "FOO"
5127 (let (v)
5128 (anything-test-candidates
5129 '(((name . "FOO")
5130 (candidates "a")
5131 (filtered-candidate-transformer
5132 . (lambda (c s) (setq v (anything-get-current-source)) c)))))
5133 (assoc-default 'name v)))
5134 ;; action-transformer
5135 (expect "FOO"
5136 (let (v)
5137 (anything-test-candidates
5138 '(((name . "FOO")
5139 (candidates "a")
5140 (action-transformer
5141 . (lambda (a c) (setq v (anything-get-current-source)) a))
5142 (action . identity))))
5143 (anything-execute-selection-action)
5144 (assoc-default 'name v)))
5145 ;; display-to-real
5146 (expect "FOO"
5147 (let (v)
5148 (anything-test-candidates
5149 '(((name . "FOO")
5150 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5151 (insert "a\n"))))
5152 (candidates-in-buffer)
5153 (display-to-real
5154 . (lambda (c) (setq v (anything-get-current-source)) c))
5155 (action . identity))))
5156 (anything-execute-selection-action)
5157 (assoc-default 'name v)))
5158 ;; cleanup
5159 (expect "FOO"
5160 (let (v)
5161 (anything-test-candidates
5162 '(((name . "FOO")
5163 (candidates "a")
5164 (cleanup
5165 . (lambda () (setq v (anything-get-current-source)))))))
5166 (assoc-default 'name v)))
5167 ;; candidates are displayed
5168 (expect "TEST"
5169 (anything-test-candidates
5170 '(((name . "TEST")
5171 (candidates "foo")
5172 (action ("identity" . identity)))))
5173 (assoc-default 'name (anything-get-current-source)))
5174 (desc "anything-attr")
5175 (expect "FOO"
5176 (anything-funcall-with-source
5177 '((name . "FOO"))
5178 (lambda ()
5179 (anything-attr 'name))))
5180 (expect 'fuga
5181 (let (v)
5182 (anything-test-candidates
5183 '(((name . "FOO")
5184 (hoge . fuga)
5185 (init . (lambda () (setq v (anything-attr 'hoge))))
5186 (candidates "a"))))
5188 (expect nil
5189 (let (v)
5190 (anything-test-candidates
5191 '(((name . "FOO")
5192 (init . (lambda () (setq v (anything-attr 'hoge))))
5193 (candidates "a"))))
5195 (expect nil
5196 (let (v)
5197 (anything-test-candidates
5198 '(((name . "FOO")
5199 (hoge) ;INCOMPATIBLE!
5200 (init . (lambda () (setq v (anything-attr 'hoge))))
5201 (candidates "a"))))
5203 (desc "anything-attr-defined")
5204 (expect (non-nil)
5205 (let (v)
5206 (anything-test-candidates
5207 '(((name . "FOO")
5208 (hoge)
5209 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5210 (candidates "a"))))
5211 v))
5212 (expect nil
5213 (let (v)
5214 (anything-test-candidates
5215 '(((name . "FOO")
5216 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5217 (candidates "a"))))
5218 v))
5219 (desc "anything-attrset")
5220 (expect '((name . "FOO") (hoge . 77))
5221 (let ((src '((name . "FOO") (hoge))))
5222 (anything-attrset 'hoge 77 src)
5223 src))
5224 (expect 77
5225 (anything-attrset 'hoge 77 '((name . "FOO") (hoge))))
5227 (expect '((name . "FOO") (hoge . 77))
5228 (let ((src '((name . "FOO") (hoge . 1))))
5229 (anything-attrset 'hoge 77 src)
5230 src))
5232 (expect '((name . "FOO") (hoge . 77) (x))
5233 (let ((src '((name . "FOO") (x))))
5234 (anything-attrset 'hoge 77 src)
5235 src))
5236 (expect 77
5237 (anything-attrset 'hoge 77 '((name . "FOO"))))
5238 (desc "anything-preselect")
5239 ;; entire candidate
5240 (expect "foo"
5241 (with-current-buffer (anything-create-anything-buffer t)
5242 (let ((anything-pattern "")
5243 (anything-test-mode t))
5244 (anything-process-source '((name . "test")
5245 (candidates "hoge" "foo" "bar")))
5246 (anything-preselect "foo")
5247 (anything-get-selection))))
5248 ;; regexp
5249 (expect "foo"
5250 (with-current-buffer (anything-create-anything-buffer t)
5251 (let ((anything-pattern "")
5252 (anything-test-mode t))
5253 (anything-process-source '((name . "test")
5254 (candidates "hoge" "foo" "bar")))
5255 (anything-preselect "fo+")
5256 (anything-get-selection))))
5257 ;; no match -> first entry
5258 (expect "hoge"
5259 (with-current-buffer (anything-create-anything-buffer t)
5260 (let ((anything-pattern "")
5261 (anything-test-mode t))
5262 (anything-process-source '((name . "test")
5263 (candidates "hoge" "foo" "bar")))
5264 (anything-preselect "not found")
5265 (anything-get-selection))))
5266 (desc "anything-check-new-input")
5267 (expect "newpattern"
5268 (stub anything-update)
5269 (stub anything-action-window)
5270 (let ((anything-pattern "pattern"))
5271 (anything-check-new-input "newpattern")
5272 anything-pattern))
5273 ;; anything-input == nil when action window is available
5274 (expect nil
5275 (stub anything-update)
5276 (stub anything-action-window => t)
5277 (let ((anything-pattern "pattern")
5278 anything-input)
5279 (anything-check-new-input "newpattern")
5280 anything-input))
5281 ;; anything-input == anything-pattern unless action window is available
5282 (expect "newpattern"
5283 (stub anything-update)
5284 (stub anything-action-window => nil)
5285 (let ((anything-pattern "pattern")
5286 anything-input)
5287 (anything-check-new-input "newpattern")
5288 anything-input))
5289 (expect (mock (anything-update))
5290 (stub anything-action-window)
5291 (let (anything-pattern)
5292 (anything-check-new-input "foo")))
5293 (desc "anything-update")
5294 (expect (mock (anything-process-source '((name . "1"))))
5295 (anything-test-update '(((name . "1"))) ""))
5296 ;; (find-function 'anything-update)
5297 ;; TODO el-mock.el should express 2nd call of function.
5298 ;; (expect (mock (anything-process-source '((name . "2"))))
5299 ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
5300 ;; (stub run-hooks)
5301 ;; (stub anything-maybe-fit-frame)
5302 ;; (stub run-with-idle-timer)
5303 ;; (anything-update))
5304 (expect (mock (run-with-idle-timer * nil 'anything-process-delayed-sources
5305 '(((name . "2") (delayed)))))
5306 (stub anything-get-sources => '(((name . "1"))
5307 ((name . "2") (delayed))))
5308 (stub run-hooks)
5309 (stub anything-maybe-fit-frame)
5310 (let ((anything-pattern "") anything-test-mode)
5311 (anything-update)))
5313 (desc "requires-pattern attribute")
5314 (expect (not-called anything-process-source)
5315 (anything-test-update '(((name . "1") (requires-pattern))) ""))
5316 (expect (not-called anything-process-source)
5317 (anything-test-update '(((name . "1") (requires-pattern . 3))) "xx"))
5319 (desc "delay")
5320 (expect (mock (sit-for 0.25))
5321 (stub with-current-buffer)
5322 (let ((anything-idle-delay 1.0)
5323 (anything-input-idle-delay 0.75))
5324 (anything-process-delayed-sources t)))
5325 (expect (mock (sit-for 0.0))
5326 (stub with-current-buffer)
5327 (let ((anything-idle-delay 0.2)
5328 (anything-input-idle-delay 0.5))
5329 (anything-process-delayed-sources t)))
5330 (expect (mock (sit-for 0.5))
5331 (stub with-current-buffer)
5332 (let ((anything-idle-delay 0.5)
5333 (anything-input-idle-delay nil))
5334 (anything-process-delayed-sources t)))
5335 (desc "anything-normalize-sources")
5336 (expect '(anything-c-source-test)
5337 (anything-normalize-sources 'anything-c-source-test))
5338 (expect '(anything-c-source-test)
5339 (anything-normalize-sources '(anything-c-source-test)))
5340 (expect '(anything-c-source-test)
5341 (let ((anything-sources '(anything-c-source-test)))
5342 (anything-normalize-sources nil)))
5343 (expect '(((name . "test")))
5344 (anything-normalize-sources '((name . "test"))))
5345 (expect '(((name . "test")))
5346 (anything-normalize-sources '(((name . "test")))))
5347 (desc "anything-get-action")
5348 (expect '(("identity" . identity))
5349 (stub buffer-size => 1)
5350 (stub anything-get-current-source => '((name . "test")
5351 (action ("identity" . identity))))
5352 (anything-get-action))
5353 (expect '((("identity" . identity)) "action-transformer is called")
5354 (stub buffer-size => 1)
5355 (stub anything-get-current-source
5356 => '((name . "test")
5357 (action ("identity" . identity))
5358 (action-transformer
5359 . (lambda (actions selection)
5360 (list actions selection)))))
5361 (stub anything-get-selection => "action-transformer is called")
5362 (anything-get-action))
5363 (desc "anything-select-nth-action")
5364 (expect "selection"
5365 (stub anything-get-selection => "selection")
5366 (stub anything-exit-minibuffer)
5367 (let (anything-saved-selection)
5368 (anything-select-nth-action 1)
5369 anything-saved-selection))
5370 (expect 'cadr
5371 (stub anything-get-action => '(("0" . car) ("1" . cdr) ("2" . cadr)))
5372 (stub anything-exit-minibuffer)
5373 (stub anything-get-selection => "selection")
5374 (let (anything-saved-action)
5375 (anything-select-nth-action 2)
5376 anything-saved-action))
5377 (desc "anything-funcall-foreach")
5378 (expect (mock (upcase "foo"))
5379 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5380 (anything-funcall-foreach 'init))
5381 (expect (mock (downcase "bar"))
5382 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))
5383 ((init . (lambda () (downcase "bar"))))))
5384 (anything-funcall-foreach 'init))
5385 (expect (not-called anything-funcall-with-source)
5386 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5387 (anything-funcall-foreach 'not-found))
5388 ;; TODO anything-select-with-digit-shortcut test
5389 (desc "anything-get-cached-candidates")
5390 (expect '("cached" "version")
5391 (let ((anything-candidate-cache '(("test" "cached" "version"))))
5392 (anything-get-cached-candidates '((name . "test")
5393 (candidates "new")))))
5394 (expect '("new")
5395 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5396 (anything-get-cached-candidates '((name . "test")
5397 (candidates "new")))))
5398 (expect '(("test" "new")
5399 ("other" "cached" "version"))
5400 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5401 (anything-get-cached-candidates '((name . "test")
5402 (candidates "new")))
5403 anything-candidate-cache))
5404 (expect '(("other" "cached" "version"))
5405 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5406 (anything-get-cached-candidates '((name . "test")
5407 (candidates "new")
5408 (volatile)))
5409 anything-candidate-cache))
5410 ;; TODO when candidates == process
5411 ;; TODO anything-output-filter
5412 (desc "candidate-number-limit attribute")
5413 (expect '("a" "b")
5414 (let ((anything-pattern "")
5415 (anything-candidate-number-limit 20))
5416 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5417 (candidate-number-limit . 2) (volatile)))))
5418 (expect '("a" "b")
5419 (let ((anything-pattern "[abc]")
5420 (anything-candidate-number-limit 20))
5421 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5422 (candidate-number-limit . 2) (volatile)))))
5423 (expect '("a" "b" "c" "d")
5424 (let ((anything-pattern "[abcd]")
5425 (anything-candidate-number-limit 2))
5426 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c" "d")
5427 (candidate-number-limit) (volatile)))))
5428 (expect '(("TEST" ("a" "b" "c")))
5429 (let ((anything-candidate-number-limit 2))
5430 (anything-test-candidates
5431 '(((name . "TEST")
5432 (init
5433 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5434 (insert "a\nb\nc\nd\n"))))
5435 (candidates . anything-candidates-in-buffer)
5436 (match identity)
5437 (candidate-number-limit . 3)
5438 (volatile))))))
5439 (expect '(("TEST" ("a" "b" "c")))
5440 (let ((anything-candidate-number-limit 2))
5441 (anything-test-candidates
5442 '(((name . "TEST")
5443 (init
5444 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5445 (insert "a\nb\nc\nd\n"))))
5446 (candidates . anything-candidates-in-buffer)
5447 (match identity)
5448 (candidate-number-limit . 3)
5449 (volatile)))
5450 ".")))
5451 (desc "multiple init")
5452 (expect '(1 . 2)
5453 (let (a b)
5454 (anything-test-candidates
5455 '(((name . "test")
5456 (init (lambda () (setq a 1))
5457 (lambda () (setq b 2))))))
5458 (cons a b)))
5459 (expect 1
5460 (let (a)
5461 (anything-test-candidates
5462 '(((name . "test")
5463 (init (lambda () (setq a 1))))))
5465 (desc "multiple cleanup")
5466 (expect '(1 . 2)
5467 (let (a b)
5468 (anything-test-candidates
5469 '(((name . "test")
5470 (cleanup (lambda () (setq a 1))
5471 (lambda () (setq b 2))))))
5472 (cons a b)))
5473 (desc "anything-mklist")
5474 (expect '(1)
5475 (anything-mklist 1))
5476 (expect '(2)
5477 (anything-mklist '(2)))
5478 (desc "anything-before-initialize-hook")
5479 (expect 'called
5480 (let ((anything-before-initialize-hook '((lambda () (setq v 'called))))
5482 (anything-initialize)
5484 (desc "anything-after-initialize-hook")
5485 (expect '(b a)
5486 (let ((anything-before-initialize-hook
5487 '((lambda () (setq v '(a)))))
5488 (anything-after-initialize-hook
5489 '((lambda () (setq v (cons 'b v)))))
5491 (anything-initialize)
5493 (expect 0
5494 (let ((anything-after-initialize-hook
5495 '((lambda () (setq v (buffer-size (get-buffer anything-buffer))))))
5497 (anything-initialize)
5499 (desc "get-line attribute")
5500 (expect '(("TEST" ("FOO+")))
5501 (anything-test-candidates
5502 '(((name . "TEST")
5503 (init
5504 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5505 (insert "foo+\nbar+\nbaz+\n"))))
5506 (candidates-in-buffer)
5507 (get-line . (lambda (s e) (upcase (buffer-substring-no-properties s e))))))
5508 "oo\\+"))
5509 (desc "with-anything-restore-variables")
5510 (expect '(7 8)
5511 (let ((a 7) (b 8)
5512 (anything-restored-variables '(a b)))
5513 (with-anything-restore-variables
5514 (setq a 0 b 0))
5515 (list a b)))
5516 (desc "anything-cleanup-hook")
5517 (expect 'called
5518 (let ((anything-cleanup-hook
5519 '((lambda () (setq v 'called))))
5521 (anything-cleanup)
5523 (desc "with-anything-display-same-window")
5524 (expect (non-nil)
5525 (save-window-excursion
5526 (delete-other-windows)
5527 (split-window)
5529 (let ((buf (get-buffer-create " tmp"))
5530 (win (selected-window)))
5531 (with-anything-display-same-window
5532 (display-buffer buf)
5533 (eq win (get-buffer-window buf))))))
5534 (expect (non-nil)
5535 (save-window-excursion
5536 (delete-other-windows)
5537 (split-window)
5539 (let ((buf (get-buffer-create " tmp"))
5540 (win (selected-window)))
5541 (with-anything-display-same-window
5542 (pop-to-buffer buf)
5543 (eq win (get-buffer-window buf))))))
5544 (expect (non-nil)
5545 (save-window-excursion
5546 (delete-other-windows)
5547 (split-window)
5549 (let ((buf (get-buffer-create " tmp"))
5550 (win (selected-window)))
5551 (with-anything-display-same-window
5552 (switch-to-buffer buf)
5553 (eq win (get-buffer-window buf))))))
5554 (expect (non-nil)
5555 (save-window-excursion
5556 (delete-other-windows)
5557 (let ((buf (get-buffer-create " tmp"))
5558 (win (selected-window)))
5559 (with-anything-display-same-window
5560 (display-buffer buf)
5561 (eq win (get-buffer-window buf))))))
5562 (expect (non-nil)
5563 (save-window-excursion
5564 (delete-other-windows)
5565 (let ((buf (get-buffer-create " tmp"))
5566 (win (selected-window)))
5567 (with-anything-display-same-window
5568 (pop-to-buffer buf)
5569 (eq win (get-buffer-window buf))))))
5570 (desc "search-from-end attribute")
5571 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5572 (anything-test-candidates
5573 '(((name . "TEST")
5574 (init
5575 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5576 (insert "foo+\nbar+\nbaz+\n"))))
5577 (candidates-in-buffer)
5578 (search-from-end)))))
5579 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5580 (anything-test-candidates
5581 '(((name . "TEST")
5582 (init
5583 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5584 (insert "foo+\nbar+\nbaz+\n"))))
5585 (candidates-in-buffer)
5586 (search-from-end)))
5587 "\\+"))
5588 (expect '(("TEST" ("baz+" "bar+")))
5589 (anything-test-candidates
5590 '(((name . "TEST")
5591 (init
5592 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5593 (insert "foo+\nbar+\nbaz+\n"))))
5594 (candidates-in-buffer)
5595 (search-from-end)
5596 (candidate-number-limit . 2)))))
5597 (expect '(("TEST" ("baz+" "bar+")))
5598 (anything-test-candidates
5599 '(((name . "TEST")
5600 (init
5601 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5602 (insert "foo+\nbar+\nbaz+\n"))))
5603 (candidates-in-buffer)
5604 (search-from-end)
5605 (candidate-number-limit . 2)))
5606 "\\+"))
5608 (desc "header-name attribute")
5609 (expect "original is transformed"
5610 (anything-test-update '(((name . "original")
5611 (candidates "1")
5612 (header-name
5613 . (lambda (name)
5614 (format "%s is transformed" name)))))
5616 (with-current-buffer (anything-buffer-get)
5617 (buffer-string)
5618 (overlay-get (car (overlays-at (1+(point-min)))) 'display)))
5619 (desc "volatile and match attribute")
5620 ;; candidates function is called once per `anything-process-delayed-sources'
5621 (expect 1
5622 (let ((v 0))
5623 (anything-test-candidates '(((name . "test")
5624 (candidates . (lambda () (incf v) '("ok")))
5625 (volatile)
5626 (match identity identity identity)))
5627 "o")
5629 (desc "accept-empty attribute")
5630 (expect nil
5631 (anything-test-candidates
5632 '(((name . "test") (candidates "") (action . identity))))
5633 (anything-execute-selection-action))
5634 (expect ""
5635 (anything-test-candidates
5636 '(((name . "test") (candidates "") (action . identity) (accept-empty))))
5637 (anything-execute-selection-action))
5638 (desc "anything-tick-hash")
5639 (expect nil
5640 (with-current-buffer (get-buffer-create " *00create+*")
5641 (puthash " *00create+*/xxx" 1 anything-tick-hash)
5642 (kill-buffer (current-buffer)))
5643 (gethash " *00create+*/xxx" anything-tick-hash))
5644 (desc "anything-execute-action-at-once-if-once")
5645 (expect "HOGE"
5646 (let ((anything-execute-action-at-once-if-one t))
5647 (anything '(((name . "one test1")
5648 (candidates "hoge")
5649 (action . upcase))))))
5650 (expect "ANY"
5651 (let ((anything-execute-action-at-once-if-one t))
5652 (anything '(((name . "one test2")
5653 (candidates "hoge" "any")
5654 (action . upcase)))
5655 "an")))
5656 ;; candidates > 1
5657 (expect (mock (read-string "word: " nil))
5658 (let ((anything-execute-action-at-once-if-one t))
5659 (anything '(((name . "one test3")
5660 (candidates "hoge" "foo" "bar")
5661 (action . identity)))
5662 nil "word: ")))
5663 (desc "anything-quit-if-no-candidate")
5664 (expect nil
5665 (let ((anything-quit-if-no-candidate t))
5666 (anything '(((name . "zero test1") (candidates) (action . upcase))))))
5667 (expect 'called
5668 (let (v (anything-quit-if-no-candidate (lambda () (setq v 'called))))
5669 (anything '(((name . "zero test2") (candidates) (action . upcase))))
5671 (desc "real-to-display attribute")
5672 (expect '(("test" (("DDD" . "ddd"))))
5673 (anything-test-candidates '(((name . "test")
5674 (candidates "ddd")
5675 (real-to-display . upcase)
5676 (action . identity)))))
5677 (expect '(("test" (("DDD" . "ddd"))))
5678 (anything-test-candidates '(((name . "test")
5679 (candidates ("ignored" . "ddd"))
5680 (real-to-display . upcase)
5681 (action . identity)))))
5682 (expect '(("Commands" (("xxxhoge" . "hoge") ("xxxboke" . "boke"))))
5683 (anything-test-candidates '(((name . "Commands")
5684 (candidates
5685 "hoge" "boke")
5686 (real-to-display . (lambda (x) (concat "xxx" x)))
5687 (action . identity)))
5688 "xxx"))
5689 (expect "test\nDDD\n"
5690 (anything-test-update '(((name . "test")
5691 (candidates "ddd")
5692 (real-to-display . upcase)
5693 (action . identity)))
5695 (with-current-buffer (anything-buffer-get) (buffer-string)))
5696 (desc "real-to-display and candidate-transformer attribute")
5697 (expect '(("test" (("DDD" . "ddd"))))
5698 (anything-test-candidates
5699 '(((name . "test")
5700 (candidates "ddd")
5701 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
5702 (real-to-display . upcase)
5703 (action . identity)))))
5704 (expect "test\nDDD\n"
5705 (anything-test-update
5706 '(((name . "test")
5707 (candidates "ddd")
5708 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
5709 (real-to-display . upcase)
5710 (action . identity)))
5712 (with-current-buffer (anything-buffer-get) (buffer-string)))
5713 (desc "real-to-display and candidates-in-buffer")
5714 (expect '(("test" (("A" . "a") ("B" . "b"))))
5715 (anything-test-candidates
5716 '(((name . "test")
5717 (init
5718 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5719 (erase-buffer)
5720 (insert "a\nb\n"))))
5721 (candidates-in-buffer)
5722 (real-to-display . upcase)
5723 (action . identity)))))
5724 (expect "test\nA\nB\n"
5725 (stub read-string)
5726 (anything
5727 '(((name . "test")
5728 (init
5729 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5730 (erase-buffer)
5731 (insert "a\nb\n"))))
5732 (candidates-in-buffer)
5733 (real-to-display . upcase)
5734 (action . identity))))
5735 (with-current-buffer (anything-buffer-get) (buffer-string)))
5736 (desc "Symbols are acceptable as candidate.")
5737 (expect '(("test" (sym "str")))
5738 (anything-test-candidates
5739 '(((name . "test")
5740 (candidates sym "str")))))
5741 (expect '(("test" ((sym . realsym) ("str" . "realstr"))))
5742 (anything-test-candidates
5743 '(((name . "test")
5744 (candidates (sym . realsym) ("str" . "realstr"))))))
5745 (expect '(("test" (sym)))
5746 (anything-test-candidates
5747 '(((name . "test")
5748 (candidates sym "str")))
5749 "sym"))
5750 (expect '(("test" ("str")))
5751 (anything-test-candidates
5752 '(((name . "test")
5753 (candidates sym "str")))
5754 "str"))
5755 (expect '(("test" ((sym . realsym))))
5756 (anything-test-candidates
5757 '(((name . "test")
5758 (candidates (sym . realsym) ("str" . "realstr"))))
5759 "sym"))
5760 (expect '(("test" (("str" . "realstr"))))
5761 (anything-test-candidates
5762 '(((name . "test")
5763 (candidates (sym . realsym) ("str" . "realstr"))))
5764 "str"))
5765 (desc "multiple transformers")
5766 (expect '(("test" ("<FOO>")))
5767 (anything-test-candidates
5768 '(((name . "test")
5769 (candidates "foo")
5770 (candidate-transformer
5771 . (lambda (cands)
5772 (anything-compose (list cands)
5773 (list (lambda (c) (mapcar 'upcase c))
5774 (lambda (c) (list (concat "<" (car c) ">")))))))))))
5775 (expect '("<FOO>")
5776 (anything-composed-funcall-with-source
5777 '((name . "test"))
5778 (list (lambda (c) (mapcar 'upcase c))
5779 (lambda (c) (list (concat "<" (car c) ">"))))
5780 '("foo"))
5782 (expect '(("test" ("<FOO>")))
5783 (anything-test-candidates
5784 '(((name . "test")
5785 (candidates "foo")
5786 (candidate-transformer
5787 (lambda (c) (mapcar 'upcase c))
5788 (lambda (c) (list (concat "<" (car c) ">"))))))))
5789 (expect '(("test" ("<BAR>")))
5790 (anything-test-candidates
5791 '(((name . "test")
5792 (candidates "bar")
5793 (filtered-candidate-transformer
5794 (lambda (c s) (mapcar 'upcase c))
5795 (lambda (c s) (list (concat "<" (car c) ">"))))))))
5796 (expect '(("find-file" . find-file)
5797 ("view-file" . view-file))
5798 (stub zerop => nil)
5799 (stub anything-get-current-source
5800 => '((name . "test")
5801 (action)
5802 (action-transformer
5803 . (lambda (a s)
5804 (anything-compose
5805 (list a s)
5806 (list (lambda (a s) (push '("view-file" . view-file) a))
5807 (lambda (a s) (push '("find-file" . find-file) a))))))))
5808 (anything-get-action))
5809 (expect '(("find-file" . find-file)
5810 ("view-file" . view-file))
5811 (stub zerop => nil)
5812 (stub anything-get-current-source
5813 => '((name . "test")
5814 (action)
5815 (action-transformer
5816 (lambda (a s) (push '("view-file" . view-file) a))
5817 (lambda (a s) (push '("find-file" . find-file) a)))))
5818 (anything-get-action))
5819 (desc "define-anything-type-attribute")
5820 (expect '((file (action . find-file)))
5821 (let (anything-type-attributes)
5822 (define-anything-type-attribute 'file '((action . find-file)))
5823 anything-type-attributes))
5824 (expect '((file (action . find-file)))
5825 (let ((anything-type-attributes '((file (action . view-file)))))
5826 (define-anything-type-attribute 'file '((action . find-file)))
5827 anything-type-attributes))
5828 (expect '((file (action . find-file))
5829 (buffer (action . switch-to-buffer)))
5830 (let (anything-type-attributes)
5831 (define-anything-type-attribute 'buffer '((action . switch-to-buffer)))
5832 (define-anything-type-attribute 'file '((action . find-file)))
5833 anything-type-attributes))
5834 (desc "anything-approximate-candidate-number")
5835 (expect 0
5836 (with-temp-buffer
5837 (let ((anything-buffer (current-buffer)))
5838 (anything-approximate-candidate-number))))
5839 (expect 1
5840 (with-temp-buffer
5841 (let ((anything-buffer (current-buffer)))
5842 (insert "Title\n"
5843 "candiate1\n")
5844 (anything-approximate-candidate-number))))
5845 (expect t
5846 (with-temp-buffer
5847 (let ((anything-buffer (current-buffer)))
5848 (insert "Title\n"
5849 "candiate1\n"
5850 "candiate2\n")
5851 (<= 2 (anything-approximate-candidate-number)))))
5852 (expect 1
5853 (with-temp-buffer
5854 (let ((anything-buffer (current-buffer)))
5855 (insert "Title\n"
5856 (propertize "multi\nline\n" 'anything-multiline t))
5857 (anything-approximate-candidate-number))))
5858 (expect t
5859 (with-temp-buffer
5860 (let ((anything-buffer (current-buffer))
5861 (anything-candidate-separator "-----"))
5862 (insert "Title\n"
5863 (propertize "multi\nline1\n" 'anything-multiline t)
5864 "-----\n"
5865 (propertize "multi\nline2\n" 'anything-multiline t))
5866 (<= 2 (anything-approximate-candidate-number)))))
5867 (desc "delayed-init attribute")
5868 (expect 0
5869 (let ((value 0))
5870 (anything-test-candidates '(((name . "test")
5871 (delayed-init . (lambda () (incf value)))
5872 (candiates "abc")
5873 (requires-pattern . 2)))
5875 value))
5876 (expect 1
5877 (let ((value 0))
5878 (anything-test-candidates '(((name . "test")
5879 (delayed-init . (lambda () (incf value)))
5880 (candiates "abc")
5881 (requires-pattern . 2)))
5882 "abc")
5883 value))
5884 (desc "pattern-transformer attribute")
5885 (expect '(("test2" ("foo")) ("test3" ("bar")))
5886 (anything-test-candidates '(((name . "test1")
5887 (candidates "foo" "bar"))
5888 ((name . "test2")
5889 (pattern-transformer . (lambda (pat) (substring pat 1)))
5890 (candidates "foo" "bar"))
5891 ((name . "test3")
5892 (pattern-transformer . (lambda (pat) "bar"))
5893 (candidates "foo" "bar")))
5894 "xfoo"))
5895 (expect '(("test2" ("foo")) ("test3" ("bar")))
5896 (anything-test-candidates '(((name . "test1")
5897 (candidates "foo" "bar"))
5898 ((name . "test2")
5899 (pattern-transformer (lambda (pat) (substring pat 1)))
5900 (candidates "foo" "bar"))
5901 ((name . "test3")
5902 (pattern-transformer (lambda (pat) "bar"))
5903 (candidates "foo" "bar")))
5904 "xfoo"))
5905 (expect '(("test2" ("foo")) ("test3" ("bar")))
5906 (anything-test-candidates '(((name . "test1")
5907 (init
5908 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5909 (insert "foo\nbar\n"))))
5910 (candidates-in-buffer))
5911 ((name . "test2")
5912 (pattern-transformer . (lambda (pat) (substring pat 1)))
5913 (init
5914 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5915 (insert "foo\nbar\n"))))
5916 (candidates-in-buffer))
5917 ((name . "test3")
5918 (pattern-transformer . (lambda (pat) "bar"))
5919 (init
5920 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5921 (insert "foo\nbar\n"))))
5922 (candidates-in-buffer)))
5923 "xfoo"))
5924 (desc "anything-recent-push")
5925 (expect '("foo" "bar" "baz")
5926 (let ((lst '("bar" "baz")))
5927 (anything-recent-push "foo" 'lst)))
5928 (expect '("foo" "bar" "baz")
5929 (let ((lst '("foo" "bar" "baz")))
5930 (anything-recent-push "foo" 'lst)))
5931 (expect '("foo" "bar" "baz")
5932 (let ((lst '("bar" "foo" "baz")))
5933 (anything-recent-push "foo" 'lst)))
5934 (desc "anything-require-at-least-version")
5935 (expect nil
5936 (anything-require-at-least-version "1.1"))
5937 (expect nil
5938 (anything-require-at-least-version "1.200"))
5939 (expect nil
5940 (anything-require-at-least-version
5941 (and (string-match "1\.\\([0-9]+\\)" anything-version)
5942 (match-string 0 anything-version))))
5943 (expect (error)
5944 (anything-require-at-least-version "1.999"))
5945 (expect (error)
5946 (anything-require-at-least-version "1.2000"))
5950 (provide 'anything)
5951 ;; How to save (DO NOT REMOVE!!)
5952 ;; (emacswiki-post "anything.el")
5953 ;;; anything.el ends here