1 ;;;; anything.el --- open anything / QuickSilver-like candidate-selection framework
2 ;; $Id: anything.el,v 1.282 2010-04-01 02:22:22 rubikitch Exp $
4 ;; Copyright (C) 2007 Tamas Patrovics
5 ;; 2008, 2009, 2010 rubikitch <rubikitch@ruby-lang.org>
7 ;; Author: Tamas Patrovics
8 ;; Maintainer: rubikitch <rubikitch@ruby-lang.org>
9 ;; Keywords: files, frames, help, matching, outlines, processes, tools, convenience, anything
10 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
11 ;; Site: http://www.emacswiki.org/cgi-bin/emacs/Anything
13 ;; This file is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
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.
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.
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
56 ;; Below are complete command list:
59 ;; Select anything. In Lisp program, some optional arguments can be used.
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.
87 ;; Help of `anything'.
88 ;; `anything-debug-output'
89 ;; Show all anything-related variables at this time.
90 ;; `anything-delete-current-selection'
91 ;; Delete the currently selected item.
92 ;; `anything-delete-minibuffer-content'
93 ;; Same as `delete-minibuffer-contents' but this is a command.
94 ;; `anything-toggle-resplit-window'
95 ;; Toggle resplit anything window, vertically or horizontally.
96 ;; `anything-select-2nd-action'
97 ;; Select the 2nd action for the currently selected candidate.
98 ;; `anything-select-3rd-action'
99 ;; Select the 3rd action for the currently selected candidate.
100 ;; `anything-select-4th-action'
101 ;; Select the 4th action for the currently selected candidate.
102 ;; `anything-select-2nd-action-or-end-of-line'
103 ;; Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
104 ;; `anything-execute-persistent-action'
105 ;; If a candidate is selected then perform the associated action without quitting anything.
106 ;; `anything-scroll-other-window'
107 ;; Scroll other window (not *Anything* window) upward.
108 ;; `anything-scroll-other-window-down'
109 ;; Scroll other window (not *Anything* window) downward.
110 ;; `anything-quit-and-find-file'
111 ;; Drop into `find-file' from `anything' like `iswitchb-find-file'.
112 ;; `anything-yank-selection'
113 ;; Set minibuffer contents to current selection.
114 ;; `anything-kill-selection-and-quit'
115 ;; Store current selection to kill ring.
116 ;; `anything-follow-mode'
117 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
118 ;; `anything-migrate-sources'
119 ;; Help to migrate to new `anything' way.
120 ;; `anything-isearch'
121 ;; Start incremental search within results. (UNMAINTAINED)
122 ;; `anything-isearch-printing-char'
123 ;; Add printing char to the pattern.
124 ;; `anything-isearch-again'
125 ;; Search again for the current pattern
126 ;; `anything-isearch-delete'
128 ;; `anything-isearch-default-action'
129 ;; Execute the default action for the selected candidate.
130 ;; `anything-isearch-select-action'
131 ;; Choose an action for the selected candidate.
132 ;; `anything-isearch-cancel'
133 ;; Cancel Anything isearch.
134 ;; `anything-iswitchb-setup'
135 ;; Integrate anything completion into iswitchb (UNMAINTAINED).
136 ;; `anything-iswitchb-cancel-anything'
137 ;; Cancel anything completion and return to standard iswitchb.
138 ;; `anything-describe-anything-attribute'
139 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
141 ;;; Customizable Options:
143 ;; Below are customizable option list:
146 ;; You can extend `anything' by writing plug-ins. As soon as
147 ;; `anything' is invoked, `anything-sources' is compiled into basic
148 ;; attributes, then compiled one is used during invocation.
150 ;; The oldest built-in plug-in is `type' attribute: appends
151 ;; appropriate element of `anything-type-attributes'. Second built-in
152 ;; plug-in is `candidates-in-buffer': selecting a line from candidates
155 ;; To write a plug-in:
156 ;; 1. Define a compiler: anything-compile-source--*
157 ;; 2. Add compier function to `anything-compile-source-functions'.
158 ;; 3. (optional) Write helper functions.
160 ;; Anything plug-ins are found in the EmacsWiki.
162 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
164 ;; Tested on Emacs 22/23.
167 ;; Thanks to Vagn Johansen for ideas.
168 ;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
169 ;; Thanks to Tassilo Horn for fixes.
170 ;; Thanks to Drew Adams for various fixes (frame, isearch, customization, etc.)
171 ;; Thanks to IMAKADO for candidates-in-buffer idea.
172 ;; Thanks to Tomohiro MATSUYAMA for multiline patch.
177 ;; If you have library `linkd.el', load
178 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
179 ;; navigate around the sections Linkd mode will
180 ;; highlight this Index. You can get `linkd.el' here:
181 ;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
185 ;;; (@* "INCOMPATIBLE CHANGES")
189 ;; Default setting of `anything-save-configuration-functions' is changed.
190 ;; Anything saves/restores window configuration instead of frame configuration now.
191 ;; The default is changed because flickering is occurred in some environment.
193 ;; If you want to save and restore frame configuration, set this variable to
194 ;; '(set-frame-configuration . current-frame-configuration)
198 ;; Fitting frame is disabled by default, because some flickering occurred
199 ;; in some environment. To enable fitting, set both
200 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
205 ;; `anything-attr' returns nil when the source attribute is defined
206 ;; but the value of attribute is nil, eg. (volatile) cell. Use
207 ;; `anything-attr-defined' when testing whether the attribute is
213 ;; For `anything' users, setting `anything-sources' directly and
214 ;; invoke M-x anything is obsolete way for now. Try M-x
215 ;; `anything-migrate-sources'!
218 ;; If you want to create anything sources, yasnippet would help you.
219 ;; http://yasnippet.googlecode.com/
221 ;; Then get the snippet from
222 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
224 ;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
228 ;; `anything-interpret-value' is useful function to interpret value
229 ;; like `candidates' attribute.
231 ;; (anything-interpret-value "literal") ; => "literal"
232 ;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
233 ;; (let ((source '((name . "lambda with source name"))))
234 ;; (anything-interpret-value
235 ;; (lambda () anything-source-name)
236 ;; source)) ; => "lambda with source name"
237 ;; (flet ((f () "function symbol"))
238 ;; (anything-interpret-value 'f)) ; => "function symbol"
239 ;; (let ((v "variable symbol"))
240 ;; (anything-interpret-value 'v)) ; => "variable symbol"
241 ;; (anything-interpret-value 'unbounded-1) ; error
244 ;; Now symbols are acceptable as candidates. So you do not have to use
245 ;; `symbol-name' function. The source is much simpler. For example,
246 ;; `apropos-internal' returns a list of symbols.
249 ;; '(((name . "Commands")
250 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
252 ;; (action . describe-function))))
255 ;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
256 ;; marked candidate, press M-[ or M-].
259 ;; `anything-map' is now Emacs-standard key bindings by default. If
260 ;; you are using `iswitchb', execute `anything-iswitchb-setup'. Then
261 ;; some key bindings are adjusted to `iswitchb'. Note that
262 ;; anything-iswitchb is not maintained.
265 ;; There are many `anything' applications, using `anything' for
266 ;; selecting candidate. In this case, if there is one candidate or no
267 ;; candidate, popping up *anything* buffer is irritating. If one
268 ;; candidate, you want to select it at once. If no candidate, you want
269 ;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
270 ;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
271 ;; that setting these variables GLOBALLY is bad idea because of
272 ;; delayed sources. These are meant to be let-binded.
273 ;; See anything-etags.el for example.
275 ;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
278 ;; (let ((anything-execute-action-at-once-if-one t)
279 ;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
280 ;; (anything temporary-sources input))
283 ;; `set-frame-configuration' arises flickering. If you hate
285 ;; (setq anything-save-configuration-functions
286 ;; '(set-window-configuration . current-window-configuration))
287 ;; at the cost of restoring frame configuration (only window configuration).
290 ;; `anything-delete-current-selection' deletes the current line.
291 ;; It is useful when deleting a candidate in persistent action.
292 ;; eg. `kill-buffer'.
294 ;; [EVAL IT] (describe-function 'anything-delete-current-selection)
297 ;; `anything-attr' gets the attribute. `anything-attrset' sets the
298 ;; attribute. `anything-attr-defined' tests whether the attribute is
299 ;; defined. They handles source-local variables.
301 ;; [EVAL IT] (describe-function 'anything-attr)
302 ;; [EVAL IT] (describe-function 'anything-attrset)
303 ;; [EVAL IT] (describe-function 'anything-attr-defined)
306 ;; `anything-sources' accepts many attributes to make your life easier.
307 ;; Now `anything-sources' accepts a list of symbols.
309 ;; [EVAL IT] (describe-variable 'anything-sources)
312 ;; `anything' has optional arguments. Now you do not have to let-bind
313 ;; `anything-sources'.
315 ;; [EVAL IT] (describe-function 'anything)
318 ;; `anything-resume' resumes last `anything' session. Now you do not
319 ;; have to retype pattern.
321 ;; [EVAL IT] (describe-function 'anything-resume)
324 ;; `anything-execute-persistent-action' executes action without
325 ;; quitting `anything'. When popping up a buffer in other window by
326 ;; persistent action, you can scroll with `anything-scroll-other-window' and
327 ;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
329 ;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
330 ;; [EVAL IT] (describe-variable 'anything-sources)
333 ;; `anything-select-2nd-action', `anything-select-3rd-action' and
334 ;; `anything-select-4th-action' select other than default action
335 ;; without pressing Tab.
338 ;; Using `anything-candidate-buffer' and the candidates-in-buffer
339 ;; attribute is much faster than traditional "candidates and match"
340 ;; way. And `anything-current-buffer-is-modified' avoids to
341 ;; recalculate candidates for unmodified buffer. See docstring of
344 ;; [EVAL IT] (describe-function 'anything-candidate-buffer)
345 ;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
346 ;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
349 ;; `anything-current-buffer' and `anything-buffer-file-name' stores
350 ;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
351 ;; is invoked. Use them freely.
353 ;; [EVAL IT] (describe-variable 'anything-current-buffer)
354 ;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
357 ;; `anything-completing-read' and `anything-read-file-name' are
358 ;; experimental implementation. If you are curious, type M-x
359 ;; anything-read-string-mode. It is a minor mode and toggles on/off.
362 ;; Use `anything-test-candidates' to test your handmade anything
363 ;; sources. It simulates contents of *anything* buffer with pseudo
364 ;; `anything-sources' and `anything-pattern', without side-effect. So
365 ;; you can unit-test your anything sources! Let's TDD!
367 ;; [EVAL IT] (describe-function 'anything-test-candidates)
369 ;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
370 ;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
372 ;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
373 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
374 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
379 ;; - process status indication
381 ;; - async sources doesn't honor digit-shortcut-count
383 ;; - anything-candidate-number-limit can't be nil everywhere
386 ;; $Log: anything.el,v $
387 ;; Revision 1.280 2010-04-01 02:22:22 rubikitch
388 ;; `anything': new argument ANY-KEYMAP
390 ;; Revision 1.279 2010/03/31 09:22:58 rubikitch
391 ;; Add tips of yasnippet for source creators (no code change)
393 ;; Revision 1.278 2010/03/31 09:01:08 rubikitch
394 ;; Added info to INCOMPATIBLE CHANGES
396 ;; Revision 1.277 2010/03/31 08:56:53 rubikitch
397 ;; Anything saves/restores window configuration instead of frame configuration now.
398 ;; The default is changed because flickering is occurred in some environment.
400 ;; If you want to save and restore frame configuration, set this variable to
401 ;; '(set-frame-configuration . current-frame-configuration)
403 ;; Revision 1.276 2010/03/31 08:52:50 rubikitch
404 ;; Fitting frame is disabled by default, because some flickering occurred
405 ;; in some environment. To enable fitting, set both
406 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
409 ;; Revision 1.275 2010/03/31 02:46:09 rubikitch
410 ;; (defvaralias 'anything-attributes 'anything-additional-attributes)
412 ;; Revision 1.274 2010/03/31 02:43:35 rubikitch
413 ;; New command: `anything-describe-anything-attribute'
415 ;; Revision 1.273 2010/03/31 02:37:18 rubikitch
416 ;; Document all attributes by `anything-document-attribute' instead of `anything-sources' docstring
418 ;; Revision 1.272 2010/03/29 21:05:47 rubikitch
419 ;; `anything-mode-line-string': use `make-local-variable' instead
421 ;; Revision 1.271 2010/03/29 09:59:17 rubikitch
424 ;; Revision 1.270 2010/03/29 09:56:12 rubikitch
425 ;; Call `filtered-candidate-transformer' functions even if process sources
427 ;; Revision 1.269 2010/03/29 08:42:23 rubikitch
428 ;; * New attribute `resume'
429 ;; * Fix a bug of `disable-shortcuts' plug-in
431 ;; Revision 1.268 2010/03/28 21:42:01 rubikitch
432 ;; Add some keys in `anything-help'
434 ;; Revision 1.267 2010/03/28 20:11:30 rubikitch
435 ;; Modify `anything-mode-line-string'
437 ;; Revision 1.266 2010/03/28 06:12:43 rubikitch
438 ;; process source and multiline: in the making (not usable)
440 ;; Revision 1.265 2010/03/28 05:07:00 rubikitch
441 ;; Change default `anything-sources'. It is only a sample, no problem.
443 ;; Revision 1.264 2010/03/27 19:02:52 rubikitch
444 ;; New attributes: `mode-line' and `header-line'
446 ;; Revision 1.263 2010/03/27 02:34:40 rubikitch
449 ;; Revision 1.262 2010/03/27 02:31:55 rubikitch
450 ;; New command: `anything-force-update' C-c C-u
452 ;; Revision 1.261 2010/03/27 02:29:39 rubikitch
453 ;; New function `anything-goto-source'
455 ;; Revision 1.260 2010/03/27 02:01:28 rubikitch
456 ;; reimplement move selection commands
458 ;; Revision 1.259 2010/03/26 22:52:15 rubikitch
459 ;; `anything-quit-and-find-file':
460 ;; If current selection is a buffer or a file, `find-file' from its directory.
461 ;; Idea from http://i-yt.info/?date=20090826#p01 with some modification. Thanks.
463 ;; Revision 1.258 2010/03/26 12:10:55 rubikitch
464 ;; * modify `anything-mode-line-string'
465 ;; * New command `anything-help'
467 ;; Revision 1.257 2010/03/24 11:08:19 rubikitch
470 ;; Revision 1.256 2010/03/24 08:29:43 rubikitch
471 ;; `anything-check-minibuffer-input' set repeat timer.
473 ;; Revision 1.255 2010/03/24 02:35:47 rubikitch
474 ;; `anything-candidate-number-limit':
475 ;; When (candidate-number-limit) is specified in SOURCE,
476 ;; cancel the effect of `anything-candidate-number-limit'.
478 ;; Revision 1.254 2010/03/23 00:33:18 rubikitch
479 ;; New API: `anything-interpret-value'
481 ;; Revision 1.253 2010/03/22 07:04:03 rubikitch
482 ;; `anything-get-current-source': return nil when no candidates rather than error
484 ;; Revision 1.252 2010/03/21 06:08:44 rubikitch
485 ;; Mark bug fix. thx hchbaw!
486 ;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
488 ;; Revision 1.251 2010/03/21 02:39:34 rubikitch
489 ;; Fix a wrong usage of `delq'. thx hchbaw.
490 ;; http://d.hatena.ne.jp/hchbaw/20100226/1267200447
492 ;; Revision 1.250 2010/03/21 02:32:29 rubikitch
493 ;; Fix `select deleted buffer' error message when calling `anything-resume'.
495 ;; It was occurred when killing `anything-current-buffer' and calling `anything-resume'.
497 ;; Revision 1.249 2010/02/23 20:43:35 rubikitch
498 ;; `anything-update': Ensure to call `anything-next-line'
500 ;; Revision 1.248 2010/02/20 12:34:38 rubikitch
501 ;; Mode-line help!! `anything-mode-line-string' is help string.
503 ;; Revision 1.247 2010/02/20 10:41:39 rubikitch
504 ;; Automatically update `anything-version' when upgrading
506 ;; Revision 1.246 2010/02/20 10:38:58 rubikitch
509 ;; Revision 1.245 2010/02/20 10:36:01 rubikitch
510 ;; New API: `anything-require-at-least-version'
512 ;; Revision 1.244 2010/02/20 10:06:54 rubikitch
513 ;; * New plug-in: `disable-shortcuts'
514 ;; * `dummy' plug-in implies `disable-shortcuts' because it enables us to input capital letters.
516 ;; Revision 1.243 2010/02/20 09:54:16 rubikitch
517 ;; `anything-compile-source--dummy': swap arguments of `append'
519 ;; Revision 1.242 2010/02/19 17:37:12 rubikitch
520 ;; error check in `anything-set-source-filter'
522 ;; Revision 1.241 2010/01/29 18:53:17 rubikitch
523 ;; Fix a bug of `candidate-number-limit' in process sources.
525 ;; Revision 1.240 2010/01/23 04:21:31 rubikitch
526 ;; * `anything': Use `anything-display-buffer' as fallback
527 ;; * `anything-select-with-digit-shortcut': `self-insert-command' if disabled
529 ;; Revision 1.239 2009/12/28 07:33:28 rubikitch
530 ;; New command: `anything-toggle-resplit-window' (C-t)
532 ;; Revision 1.238 2009/12/28 07:19:37 rubikitch
535 ;; Revision 1.237 2009/12/28 07:15:30 rubikitch
536 ;; `anything-window-configuration' stores window configuration only.
538 ;; Revision 1.236 2009/12/28 07:07:09 rubikitch
539 ;; `anything-resume' resumes window configuration now.
541 ;; Revision 1.235 2009/12/28 04:12:33 rubikitch
544 ;; Revision 1.234 2009/12/28 03:57:33 rubikitch
545 ;; `anything-resume': New optional argument
547 ;; Revision 1.233 2009/12/28 03:43:12 rubikitch
550 ;; Revision 1.232 2009/12/28 03:37:25 rubikitch
553 ;; Revision 1.231 2009/12/28 02:33:41 rubikitch
556 ;; Revision 1.230 2009/12/27 09:28:06 rubikitch
557 ;; `anything-window-configuration' save/restore anything window configuration (NOT YET)
559 ;; Revision 1.229 2009/12/26 21:41:33 rubikitch
560 ;; revive `anything-input' when resuming
562 ;; Revision 1.228 2009/12/25 01:34:35 rubikitch
563 ;; * `anything-resume' use anything interface to select anything buffers.
564 ;; * Its candidates are sorted by most recently used order.
565 ;; * 4th arg of `anything' accepts 'noresume not to resume this session.
567 ;; Revision 1.227 2009/12/19 20:30:12 rubikitch
568 ;; add `pattern-transformer' doc
570 ;; Revision 1.226 2009/12/19 20:15:47 rubikitch
571 ;; pattern-transformer can have multiple functions now
573 ;; Revision 1.225 2009/12/19 20:11:16 rubikitch
574 ;; add `delayed-init' doc
576 ;; Revision 1.224 2009/12/19 12:26:00 rubikitch
577 ;; New attribute `pattern-transformer'
579 ;; Revision 1.223 2009/12/19 11:57:41 rubikitch
580 ;; New attribute `delayed-init'
582 ;; Revision 1.222 2009/12/14 20:55:23 rubikitch
583 ;; Fix display bug: `anything-enable-digit-shortcuts' / multiline
585 ;; Revision 1.221 2009/12/14 20:29:49 rubikitch
586 ;; fix an error when executing `anything-prev-visible-mark' with no visible marks.
588 ;; Revision 1.220 2009/12/14 20:19:05 rubikitch
589 ;; Bugfix about anything-execute-action-at-once-if-one and multiline
591 ;; Revision 1.219 2009/12/14 03:21:11 rubikitch
592 ;; Extend alphabet shortcuts to A-Z
594 ;; Revision 1.218 2009/12/13 01:03:34 rubikitch
595 ;; Changed data structure of `anything-shortcut-keys-alist'
597 ;; Revision 1.217 2009/12/03 23:16:17 rubikitch
600 ;; Revision 1.216 2009/12/03 20:43:51 rubikitch
601 ;; Add keybindings for alphabet shortcuts
603 ;; Revision 1.215 2009/12/03 20:37:13 rubikitch
604 ;; `anything-enable-shortcuts' is an alias of `anything-enable-digit-shortcuts'.
605 ;; Alphabet shortcuts can be used now.
607 ;; Revision 1.214 2009/12/03 20:23:40 rubikitch
608 ;; `anything-enable-digit-shortcuts' also accepts 'alphabet.
610 ;; Now alphabet shortcuts are usable.
612 ;; Revision 1.213 2009/12/03 09:59:58 rubikitch
615 ;; Revision 1.212 2009/11/15 09:42:15 rubikitch
618 ;; Revision 1.211 2009/11/06 21:42:58 rubikitch
619 ;; New command: `anything-beginning-of-buffer', `anything-end-of-buffer'
621 ;; Revision 1.210 2009/10/22 13:30:06 rubikitch
622 ;; `real-to-display' function is evaluated just after `candidate-transformer' function now.
623 ;; This enables us to narrow candidates by display string by `real-to-display'.
625 ;; Revision 1.209 2009/10/21 20:25:10 rubikitch
626 ;; Add a document. (no code change)
628 ;; Revision 1.208 2009/10/21 11:31:15 rubikitch
629 ;; `anything': accept one source alist
631 ;; Revision 1.207 2009/10/16 19:47:39 rubikitch
632 ;; Link to Japanese translation of `anything-sources' attributes. (No code change)
634 ;; Revision 1.206 2009/10/10 09:28:54 rubikitch
635 ;; Remove an unnecessary test
637 ;; Revision 1.205 2009/10/10 06:21:28 rubikitch
638 ;; obsolete: `anything-c-marked-candidate-list'
639 ;; New function: `anything-marked-candidates'
641 ;; Revision 1.204 2009/10/06 21:01:12 rubikitch
642 ;; Call `anything-process-delayed-sources' only if delayed-sources is available.
644 ;; Revision 1.203 2009/10/02 10:04:07 rubikitch
645 ;; Tested on Emacs23 too. (no code change)
647 ;; Revision 1.202 2009/10/02 10:03:34 rubikitch
648 ;; * Display "no candidates" rather than assertion
649 ;; * Ensure to call `remove-hook' in `anything-current-buffer'
651 ;; Revision 1.201 2009/08/08 13:25:30 rubikitch
652 ;; `anything-toggle-visible-mark': move next line after unmarking
654 ;; Revision 1.200 2009/08/08 13:23:46 rubikitch
655 ;; `anything-toggle-visible-mark': Applied ThierryVolpiatto's patch. thx.
657 ;; Revision 1.199 2009/07/19 13:22:29 rubikitch
658 ;; `anything-follow-execute-persistent-action-maybe': execute persistent action after `anything-input-idle-delay'
660 ;; Revision 1.198 2009/07/06 15:22:48 rubikitch
661 ;; header modified (no code change)
663 ;; Revision 1.197 2009/06/29 15:10:13 rubikitch
664 ;; OOPS! remove debug code
666 ;; Revision 1.196 2009/06/29 13:29:25 rubikitch
667 ;; anything-follow-mode: automatical execution of persistent-action (C-c C-f)
669 ;; Revision 1.195 2009/06/19 14:42:57 rubikitch
670 ;; silence byte compiler
672 ;; Revision 1.194 2009/06/14 15:12:34 rubikitch
675 ;; Revision 1.193 2009/06/08 19:37:12 rubikitch
678 ;; Revision 1.192 2009/06/08 19:36:39 rubikitch
679 ;; New keybind: C-e, C-j, C-k
681 ;; Revision 1.191 2009/06/08 19:30:27 rubikitch
682 ;; New command: `anything-select-2nd-action-or-end-of-line'
684 ;; Revision 1.190 2009/06/07 17:09:50 rubikitch
685 ;; add M-<next>, C-M-S-v, M-<prior> to `anything-map'.
687 ;; Revision 1.189 2009/06/01 21:36:31 rubikitch
688 ;; New function: `anything-other-buffer'
690 ;; Revision 1.188 2009/05/29 18:33:07 rubikitch
691 ;; avoid error when executing (anything-mark-current-line) in async process.
693 ;; Revision 1.187 2009/05/29 06:49:05 rubikitch
696 ;; Revision 1.186 2009/05/29 06:46:34 rubikitch
697 ;; Prevent `anything-isearch-map' from overwriting `global-map'. With
698 ;; `copy-keymap', the prefix command "M-s" in `global-map' ends up
699 ;; getting clobbered by `anything-isearch-again', preventing `occur'
700 ;; (among other things) from running. This change replaces overwriting a
701 ;; copied map with writing to a sparse map whose parent is `global-map'.
703 ;; patched by DanielHackney. thanks!
705 ;; Revision 1.185 2009/05/25 19:07:42 rubikitch
706 ;; `anything': set `case-fold-search' to t
707 ;; Because users can assign commands to capital letter keys.
709 ;; Revision 1.184 2009/05/25 19:05:04 rubikitch
710 ;; Added auto-document
712 ;; Revision 1.183 2009/05/15 01:50:46 rubikitch
715 ;; Revision 1.182 2009/05/08 18:28:18 rubikitch
716 ;; Bug fix: `anything-attr' is usable in `header-name' function.
718 ;; Revision 1.181 2009/05/04 19:05:03 rubikitch
719 ;; * `anything-yank-selection' and `anything-kill-selection-and-quit' handles display string now.
720 ;; * `anything-get-selection': Added optional arguments.
722 ;; Revision 1.180 2009/05/03 19:03:34 rubikitch
723 ;; Add `anything-input' to `minibuffer-history' even if `anything' is quit.
725 ;; Revision 1.179 2009/04/20 16:35:44 rubikitch
726 ;; New keybindings in anything-map:
727 ;; C-c C-d: `anything-delete-current-selection'
728 ;; C-c C-y: `anything-yank-selection'
729 ;; C-c C-k: `anything-kill-selection-and-quit'
731 ;; Revision 1.178 2009/04/20 16:18:58 rubikitch
732 ;; New variable: `anything-display-function'
734 ;; Revision 1.177 2009/04/20 02:17:16 rubikitch
735 ;; New commands: `anything-yank-selection', `anything-kill-selection-and-quit'
737 ;; Revision 1.176 2009/04/08 14:48:15 rubikitch
738 ;; bug fix in `anything-candidate-buffer'
740 ;; Revision 1.175 2009/03/22 19:10:37 rubikitch
741 ;; New Variable: `anything-scroll-amount' (thx. ThierryVolpiatto)
743 ;; Revision 1.174 2009/03/12 19:12:24 rubikitch
744 ;; New API: `define-anything-type-attribute'
746 ;; Revision 1.173 2009/03/11 08:10:32 rubikitch
749 ;; Revision 1.172 2009/03/10 17:11:58 rubikitch
750 ;; `candidate-transformer', `filtered-candidate-transformer',
751 ;; `action-transformer' attributes: accept a list of functions
753 ;; Revision 1.171 2009/03/09 18:49:44 rubikitch
754 ;; New command: `anything-quit-and-find-file'
756 ;; Revision 1.170 2009/03/09 18:46:11 rubikitch
757 ;; New API: `anything-run-after-quit'
759 ;; Revision 1.169 2009/03/09 10:02:49 rubikitch
760 ;; Set candidate-number-limit attribute for actions.
762 ;; Revision 1.168 2009/03/07 21:01:10 rubikitch
765 ;; Revision 1.167 2009/03/06 04:13:42 rubikitch
768 ;; Revision 1.166 2009/03/03 10:35:57 rubikitch
769 ;; Set default `anything-input-idle-delay' to 0.1
771 ;; Revision 1.165 2009/03/03 07:14:42 rubikitch
772 ;; Make sure to run `anything-update-hook' after processing delayed sources.
774 ;; Revision 1.164 2009/03/02 01:51:40 rubikitch
775 ;; better error handling.
777 ;; Revision 1.163 2009/03/01 05:15:00 rubikitch
778 ;; anything-iswitchb and anything-isearch are marked as unmaintained.
779 ;; (document change only)
781 ;; Revision 1.162 2009/02/28 01:24:13 rubikitch
782 ;; Symbols are now acceptable as candidate.
784 ;; Revision 1.161 2009/02/27 07:18:46 rubikitch
785 ;; Fix bug of `anything-scroll-other-window' and `anything-scroll-other-window-down'.
787 ;; Revision 1.160 2009/02/27 01:05:06 rubikitch
788 ;; * Make sure to restore point after running `anything-update-hook'.
789 ;; * Make `anything-compute-matches' easy to find error.
791 ;; Revision 1.159 2009/02/26 23:45:48 rubikitch
792 ;; * Check whether candidate is a string, otherwise ignore.
794 ;; Revision 1.158 2009/02/24 06:39:20 rubikitch
795 ;; suppress compile warnings.
797 ;; Revision 1.157 2009/02/23 22:51:43 rubikitch
798 ;; New function: `anything-document-attribute'
800 ;; Revision 1.156 2009/02/23 21:36:09 rubikitch
801 ;; New Variable: `anything-display-source-at-screen-top'
803 ;; Revision 1.155 2009/02/23 21:30:52 rubikitch
804 ;; New command: `anything-at-point'
806 ;; Revision 1.154 2009/02/23 08:57:54 rubikitch
809 ;; Revision 1.153 2009/02/23 08:38:57 rubikitch
812 ;; Revision 1.152 2009/02/23 08:32:17 rubikitch
813 ;; More key bindings.
815 ;; Revision 1.151 2009/02/23 08:21:24 rubikitch
816 ;; `anything-map' is now Emacs-standard key bindings by default.
817 ;; After evaluating `anything-iswitchb-setup'. some key bindings are adjusted to iswitchb.
819 ;; Revision 1.150 2009/02/20 22:58:18 rubikitch
820 ;; Cancel timer in `anything-cleanup'.
822 ;; Revision 1.149 2009/02/20 12:23:44 rubikitch
823 ;; `anything-header' face now inherits header-line (not a copy).
825 ;; Revision 1.148 2009/02/16 23:40:22 rubikitch
826 ;; `real-to-display' attribute bug fix.
828 ;; Revision 1.147 2009/02/02 20:51:41 rubikitch
829 ;; New `anything-sources' attribute: real-to-display
831 ;; Revision 1.146 2009/02/01 20:01:00 rubikitch
834 ;; Revision 1.145 2009/02/01 19:45:53 rubikitch
835 ;; New variable: `anything-quit-if-no-candidate'
837 ;; Revision 1.144 2009/02/01 19:31:47 rubikitch
840 ;; Revision 1.143 2009/02/01 19:23:32 rubikitch
841 ;; New variable: `anything-execute-action-at-once-if-one'
843 ;; Revision 1.142 2009/02/01 19:12:34 rubikitch
844 ;; `anything-persistent-action-display-buffer': bug fix
846 ;; Revision 1.141 2009/02/01 18:25:25 rubikitch
848 ;; * New variable: `anything-selection-face'
850 ;; Revision 1.140 2009/01/16 16:36:25 rubikitch
851 ;; New variable: `anything-persistent-action-use-special-display'.
853 ;; Revision 1.139 2009/01/05 20:15:53 rubikitch
854 ;; Fixed a bug of anything action buffer.
855 ;; The action source should not be cached.
857 ;; Revision 1.138 2008/12/21 16:56:05 rubikitch
858 ;; Fixed an error when action attribute is a function symbol and press TAB,
860 ;; Revision 1.137 2008/12/20 19:38:47 rubikitch
861 ;; `anything-check-minibuffer-input-1': proper quit handling
862 ;; `anything-process-delayed-sources': ditto
864 ;; Revision 1.136 2008/10/27 17:41:27 rubikitch
865 ;; `anything-process-delayed-sources', `anything-check-minibuffer-input-1': quittable
867 ;; Revision 1.135 2008/10/27 17:04:25 rubikitch
868 ;; arranged source, added more linkd tags (no code change)
870 ;; Revision 1.134 2008/10/27 15:02:25 rubikitch
871 ;; New variable: `anything-save-configuration-functions'
872 ;; Delete variable: `anything-save-configuration-type'
874 ;; Revision 1.133 2008/10/27 11:16:13 rubikitch
875 ;; New variable: `anything-save-configuration-type'
877 ;; Revision 1.132 2008/10/26 22:34:59 rubikitch
878 ;; `anything-delete-current-selection' with multiline
880 ;; Revision 1.131 2008/10/26 21:44:43 rubikitch
881 ;; New command: `anything-delete-current-selection'
883 ;; Revision 1.130 2008/10/22 10:41:09 rubikitch
884 ;; `anything-insert-match': do not override 'anything-realvalue property
886 ;; Revision 1.129 2008/10/21 17:01:37 rubikitch
887 ;; `anything-resume' per buffer.
888 ;; `anything-last-sources': obsolete
890 ;; Revision 1.128 2008/10/20 06:27:54 rubikitch
891 ;; `anything-quick-update': new user option
893 ;; Revision 1.127 2008/10/20 05:47:49 rubikitch
896 ;; Revision 1.126 2008/10/20 03:47:58 rubikitch
897 ;; `anything-update': reversed order of delayed sources
899 ;; Revision 1.125 2008/10/19 00:29:54 rubikitch
900 ;; kill buffer-local candidate buffers when creating global candidate buffers.
902 ;; Revision 1.124 2008/10/18 13:04:20 rubikitch
903 ;; Remove tick entry from `anything-tick-hash' when killing a buffer.
905 ;; Revision 1.123 2008/10/18 10:23:36 rubikitch
906 ;; multiline patch by Tomohiro MATSUYAMA.
908 ;; Revision 1.122 2008/10/13 03:10:07 rubikitch
909 ;; `anything': do `anything-mark-current-line' when resuming
911 ;; Revision 1.121 2008/10/13 03:08:08 rubikitch
912 ;; always set `anything-current-position'
914 ;; Revision 1.120 2008/10/07 14:12:02 rubikitch
915 ;; `anything-execute-persistent-action': optional arg
917 ;; Revision 1.119 2008/10/06 06:43:29 rubikitch
918 ;; `anything-candidate-buffer': return nil when the buffer is dead
920 ;; Revision 1.118 2008/09/30 22:21:28 rubikitch
921 ;; New `anything-sources' attribute: accept-empty
922 ;; dummy: include accept-empty
924 ;; Revision 1.117 2008/09/30 21:59:10 rubikitch
925 ;; New function: `anything-buffer-is-modified'
927 ;; Revision 1.116 2008/09/22 11:27:29 rubikitch
928 ;; *** empty log message ***
930 ;; Revision 1.115 2008/09/20 20:21:11 rubikitch
931 ;; added linkd index. (no code change)
933 ;; Revision 1.114 2008/09/20 20:09:57 rubikitch
934 ;; INCOMPATIBLE CHANGES: `anything-attr'
935 ;; New functions: `anything-attrset', `anything-attr-defined'
937 ;; Revision 1.113 2008/09/14 15:15:32 rubikitch
938 ;; bugfix: volatile and match attribute / process and match attribute
940 ;; Revision 1.112 2008/09/12 01:57:17 rubikitch
941 ;; When resuming anything, reinitialize overlays.
943 ;; Revision 1.111 2008/09/10 22:53:11 rubikitch
944 ;; anything: bug fix of `anything-buffer'
945 ;; New macro: `anything-test-update'
947 ;; Revision 1.110 2008/09/10 22:17:11 rubikitch
948 ;; New `anything-sources' attribute: header-name
950 ;; Revision 1.109 2008/09/10 21:12:26 rubikitch
951 ;; New hook: `anything-after-action-hook'
953 ;; Revision 1.108 2008/09/06 06:07:56 rubikitch
954 ;; Extended `anything-set-sources' optional arguments.
956 ;; Revision 1.107 2008/09/05 03:14:35 rubikitch
957 ;; reimplement `anything-current-buffer-is-modified' in the right way
959 ;; Revision 1.106 2008/09/05 00:11:05 rubikitch
960 ;; Moved `anything-read-string-mode' and read functions to anything-complete.el.
962 ;; Revision 1.105 2008/09/04 12:45:06 rubikitch
963 ;; New hook: `anything-after-persistent-action-hook'
965 ;; Revision 1.104 2008/09/04 12:27:05 rubikitch
966 ;; `anything': prefixed optional arguments
968 ;; Revision 1.103 2008/09/04 09:16:28 rubikitch
969 ;; fixed a bug of `anything-read-file-name'.
971 ;; Revision 1.102 2008/09/03 11:25:19 rubikitch
972 ;; Extended `anything' optional arguments: buffer
974 ;; Revision 1.101 2008/09/03 11:15:13 rubikitch
975 ;; `anything': return nil when keybord-quitted
977 ;; Revision 1.100 2008/09/01 23:11:02 rubikitch
978 ;; bug fix of search-from-end
980 ;; Revision 1.99 2008/09/01 13:45:55 rubikitch
981 ;; bug fix of search-from-end
983 ;; Revision 1.98 2008/09/01 11:23:38 rubikitch
984 ;; New `anything-sources' attribute: search-from-end
986 ;; Revision 1.97 2008/09/01 00:44:34 rubikitch
987 ;; Make sure to display the other window when persistent action.
989 ;; Revision 1.96 2008/08/31 20:55:20 rubikitch
990 ;; define `buffer-modified-tick' for older emacs.
992 ;; Revision 1.95 2008/08/30 04:55:51 rubikitch
993 ;; fixed a bug of `anything-completing-read'
995 ;; Revision 1.94 2008/08/28 20:18:03 rubikitch
998 ;; Revision 1.93 2008/08/25 20:18:46 rubikitch
999 ;; `anything': set `anything-input' and `anything-pattern' before `anything-update'
1001 ;; Revision 1.92 2008/08/24 22:38:46 rubikitch
1002 ;; *** empty log message ***
1004 ;; Revision 1.91 2008/08/24 21:34:35 rubikitch
1005 ;; rewrite `with-anything-restore-variables'
1007 ;; Revision 1.90 2008/08/24 20:33:02 rubikitch
1008 ;; prevent the unit test from byte-compiled.
1011 ;; Revision 1.89 2008/08/24 08:35:27 rubikitch
1012 ;; *** empty log message ***
1014 ;; Revision 1.88 2008/08/24 08:22:19 rubikitch
1015 ;; Rename `anything-candidates-buffer' -> `anything-candidate-buffer'
1017 ;; Revision 1.87 2008/08/23 22:27:04 rubikitch
1018 ;; New hook: `anything-cleanup-hook'
1020 ;; Revision 1.86 2008/08/23 22:05:42 rubikitch
1021 ;; `anything-original-source-filter' is removed.
1022 ;; Now use `anything-restored-variables' and `with-anything-restore-variables'.
1024 ;; Revision 1.85 2008/08/23 21:23:21 rubikitch
1025 ;; inhibit-read-only = t in anything-buffer
1027 ;; Revision 1.84 2008/08/23 21:18:33 rubikitch
1028 ;; *** empty log message ***
1030 ;; Revision 1.83 2008/08/23 20:44:20 rubikitch
1031 ;; `anything-execute-persistent-action': display-to-real bug fix
1033 ;; Revision 1.82 2008/08/23 20:19:12 rubikitch
1034 ;; New `anything-sources' attribute: get-line
1036 ;; Revision 1.81 2008/08/23 19:32:14 rubikitch
1037 ;; `anything-attr': Return t in (attribute-name) case.
1039 ;; Revision 1.80 2008/08/22 21:25:05 rubikitch
1040 ;; anything-candidates-in-buffer-1:
1041 ;; Open a line at the BOB to make use of `search-forward' for faster exact/prefix match.
1042 ;; Of course, restore the buffer contents after search.
1044 ;; Revision 1.79 2008/08/22 17:11:00 rubikitch
1045 ;; New hook: `anything-before-initialize-hook', `anything-after-initialize-hook'
1047 ;; Revision 1.78 2008/08/21 18:37:03 rubikitch
1048 ;; Implemented dummy sources as plug-in.
1050 ;; Revision 1.77 2008/08/21 17:40:40 rubikitch
1051 ;; New function: `anything-set-sources'
1053 ;; Revision 1.76 2008/08/21 12:25:02 rubikitch
1054 ;; New variable: `anything-version'
1056 ;; Revision 1.75 2008/08/21 12:13:46 rubikitch
1057 ;; New variable: `anything-in-persistent-action'
1059 ;; Revision 1.74 2008/08/21 10:34:22 rubikitch
1060 ;; New function `anything-mklist'
1062 ;; Revision 1.73 2008/08/21 09:41:38 rubikitch
1063 ;; accept multiple init/cleanup functions so that plug-ins can add new function.
1065 ;; Revision 1.72 2008/08/20 22:51:53 rubikitch
1066 ;; New `anything-sources' attribute: candidate-number-limit
1068 ;; Revision 1.71 2008/08/20 21:45:42 rubikitch
1069 ;; added many tests.
1071 ;; Revision 1.70 2008/08/20 18:51:45 rubikitch
1072 ;; `anything-preselect' bug fix.
1075 ;; Revision 1.69 2008/08/20 17:57:51 rubikitch
1076 ;; Extended `anything' optional arguments: preselect
1078 ;; Revision 1.68 2008/08/20 16:39:07 rubikitch
1079 ;; Nested `anything' invocation support, ie. `anything' can be invoked by anything action.
1081 ;; (anything '(((name . "nested anything invocation test")
1082 ;; (candidates "anything-c-source-buffers" "anything-c-source-man-pages")
1083 ;; (display-to-real . intern)
1084 ;; (action . anything))))
1086 ;; Revision 1.67 2008/08/20 00:08:28 rubikitch
1087 ;; `anything-candidates-in-buffer-1': add code when pattern == ""
1089 ;; Revision 1.66 2008/08/19 23:31:52 rubikitch
1090 ;; Removed `anything-show-exact-match-first' because it should be provided as a plug-in.
1092 ;; Revision 1.65 2008/08/19 23:18:47 rubikitch
1093 ;; *** empty log message ***
1095 ;; Revision 1.64 2008/08/19 23:15:43 rubikitch
1096 ;; `anything-compute-matches': short-cut when match == '(identity)
1098 ;; Revision 1.63 2008/08/19 23:06:42 rubikitch
1099 ;; Use hash table to speed uniquify candidates.
1101 ;; Revision 1.62 2008/08/19 22:40:57 rubikitch
1102 ;; `anything-test-candidates': additional optonal argument
1104 ;; Revision 1.61 2008/08/19 18:13:39 rubikitch
1105 ;; search attribute: multiple search functions
1107 ;; Revision 1.60 2008/08/19 15:07:39 rubikitch
1108 ;; New function: `anything-attr'
1110 ;; Revision 1.59 2008/08/19 15:01:59 rubikitch
1115 ;; Revision 1.58 2008/08/19 13:40:52 rubikitch
1116 ;; `anything-get-current-source': This function can be used in
1117 ;; init/candidates/action/candidate-transformer/filtered-candidate-transformer
1118 ;; display-to-real/cleanup function.
1120 ;; Revision 1.57 2008/08/19 03:43:57 rubikitch
1121 ;; `anything-process-delayed-sources': delay = anything-idle-delay - anything-input-idle-delay
1123 ;; Revision 1.56 2008/08/18 06:37:51 rubikitch
1124 ;; Make `anything-input-idle-delay' ineffective when the action list is shown.
1126 ;; Revision 1.55 2008/08/18 06:35:00 rubikitch
1127 ;; New variable: `anything-show-exact-match-first'
1129 ;; Revision 1.54 2008/08/17 23:22:24 rubikitch
1130 ;; *** empty log message ***
1132 ;; Revision 1.53 2008/08/17 23:15:38 rubikitch
1133 ;; bind `anything-source-name' when executing action to enable to use `anything-candidate-buffer' in action.
1135 ;; Revision 1.52 2008/08/17 15:21:27 rubikitch
1136 ;; `anything-test-candidates': accept a symbol for source
1137 ;; New variable: `anything-input-idle-delay'
1139 ;; Revision 1.51 2008/08/17 12:45:30 rubikitch
1140 ;; (buffer-disable-undo) in anything-buffer
1142 ;; Revision 1.50 2008/08/16 22:21:37 rubikitch
1143 ;; `anything-saved-sources': removed
1144 ;; `anything-action-buffer': action selection buffer
1145 ;; `anything-select-action': toggle actions <=> candidates
1147 ;; Revision 1.49 2008/08/16 19:46:11 rubikitch
1148 ;; New function: `anything-action-list-is-shown'
1150 ;; Revision 1.48 2008/08/16 17:03:02 rubikitch
1153 ;; Revision 1.47 2008/08/16 16:35:24 rubikitch
1154 ;; silence byte compiler
1156 ;; Revision 1.46 2008/08/16 14:51:27 rubikitch
1157 ;; *** empty log message ***
1159 ;; Revision 1.45 2008/08/16 11:27:59 rubikitch
1161 ;; `anything-aif': Anaphoric if.
1162 ;; `anything-compile-source-functions': make `anything-get-sources' customizable.
1164 ;; Revision 1.44 2008/08/16 09:38:15 rubikitch
1165 ;; *** empty log message ***
1167 ;; Revision 1.43 2008/08/15 11:44:28 rubikitch
1168 ;; `anything-read-string-mode': minor mode for `anything' version of read functions. (experimental)
1170 ;; Revision 1.42 2008/08/15 11:03:20 rubikitch
1173 ;; Revision 1.41 2008/08/14 20:51:28 rubikitch
1174 ;; New `anything-sources' attribute: cleanup
1176 ;; Revision 1.40 2008/08/14 10:34:04 rubikitch
1177 ;; `anything': SOURCES: accept symbols
1179 ;; Revision 1.39 2008/08/10 22:46:01 rubikitch
1180 ;; `anything-move-selection': avoid infinite loop
1182 ;; Revision 1.38 2008/08/09 21:38:25 rubikitch
1183 ;; `anything-read-file-name': experimental implementation.
1185 ;; Revision 1.37 2008/08/09 17:54:25 rubikitch
1188 ;; Revision 1.36 2008/08/09 17:13:00 rubikitch
1191 ;; Revision 1.35 2008/08/09 10:43:08 rubikitch
1192 ;; New `anything-sources' attribute: display-to-real
1194 ;; Revision 1.34 2008/08/07 13:15:44 rubikitch
1195 ;; New `anything-sources' attribute: search
1197 ;; Revision 1.33 2008/08/05 23:14:20 rubikitch
1198 ;; `anything-candidate-buffer': bugfix
1200 ;; Revision 1.32 2008/08/05 21:42:15 rubikitch
1201 ;; *** empty log message ***
1203 ;; Revision 1.31 2008/08/05 21:06:23 rubikitch
1204 ;; `anything-candidate-buffer': candidates buffer registration
1206 ;; Revision 1.30 2008/08/05 19:46:36 rubikitch
1207 ;; New `anything-sources' attribute: candidates-in-buffer
1209 ;; Revision 1.29 2008/08/05 17:58:31 rubikitch
1210 ;; *** empty log message ***
1212 ;; Revision 1.28 2008/08/05 17:46:04 rubikitch
1213 ;; memoized `anything-get-sources'
1215 ;; Revision 1.27 2008/08/05 17:29:40 rubikitch
1218 ;; Revision 1.26 2008/08/05 08:35:45 rubikitch
1219 ;; `anything-completing-read': accept obarray
1221 ;; Revision 1.25 2008/08/05 07:26:17 rubikitch
1222 ;; `anything-completing-read': guard from non-string return value
1224 ;; Revision 1.24 2008/08/04 12:05:41 rubikitch
1225 ;; Wrote Tips and some docstrings.
1226 ;; `anything-candidate-buffer': buffer-local by default
1228 ;; Revision 1.23 2008/08/04 05:29:46 rubikitch
1229 ;; `anything-buffer-file-name': `buffer-file-name' when `anything' is invoked.
1231 ;; Revision 1.22 2008/08/04 00:10:13 rubikitch
1232 ;; `anything-candidate-buffer': new API
1234 ;; Revision 1.21 2008/08/03 22:05:08 rubikitch
1235 ;; `anything-candidate-buffer': Return a buffer containing candidates of current source.
1237 ;; Revision 1.20 2008/08/03 20:47:56 rubikitch
1238 ;; `anything-current-buffer-is-modified': modify checker
1240 ;; Revision 1.19 2008/08/03 19:06:18 rubikitch
1241 ;; `anything-candidates-in-buffer': use `with-current-buffer' instead.
1243 ;; Revision 1.18 2008/08/03 05:55:01 rubikitch
1244 ;; `anything-candidates-in-buffer': extract candidates in a buffer for speed.
1246 ;; Revision 1.17 2008/08/02 21:31:29 rubikitch
1247 ;; Extended `anything' optional arguments.
1248 ;; `anything-completing-read': experimental implementation.
1250 ;; Revision 1.16 2008/08/02 20:32:54 rubikitch
1251 ;; Extended `anything' optional arguments.
1253 ;; Revision 1.15 2008/08/02 16:53:40 rubikitch
1254 ;; Fixed a small bug of `anything-test-candidates'.
1256 ;; Revision 1.14 2008/08/02 16:48:29 rubikitch
1257 ;; Refactored to testable code.
1258 ;; Added many candidate tests with `anything-test-candidates'.
1260 ;; Revision 1.13 2008/08/02 15:08:14 rubikitch
1261 ;; *** empty log message ***
1263 ;; Revision 1.12 2008/08/02 14:29:31 rubikitch
1264 ;; `anything-sources' accepts symbols. (patched by Sugawara)
1266 ;; Revision 1.11 2008/08/02 10:20:36 rubikitch
1267 ;; `anything-resume' is usable with other (let-binded) `anything-sources'.
1269 ;; Revision 1.10 2008/08/01 19:44:01 rubikitch
1270 ;; `anything-resume': resurrect previously invoked `anything'.
1272 ;; Revision 1.9 2008/07/30 15:44:49 rubikitch
1273 ;; *** empty log message ***
1275 ;; Revision 1.8 2008/07/30 15:38:51 rubikitch
1276 ;; *** empty log message ***
1278 ;; Revision 1.7 2008/07/30 15:21:48 rubikitch
1279 ;; `anything-scroll-other-window', `anything-scroll-other-window-down':
1280 ;; Scroll other window (for persistent action).
1282 ;; Revision 1.6 2008/07/30 15:12:36 rubikitch
1283 ;; *** empty log message ***
1285 ;; Revision 1.5 2008/07/30 15:06:32 rubikitch
1286 ;; `anything-select-2nd-action', `anything-select-3rd-action', `anything-select-4th-action':
1287 ;; Select other than default action without pressing Tab.
1289 ;; Revision 1.4 2008/07/30 14:58:27 rubikitch
1290 ;; `anything-current-buffer': Store current buffer when `anything' is invoked.
1291 ;; `anything-current-position': Restore position when keyboard-quitted.
1293 ;; Revision 1.3 2008/07/30 14:38:04 rubikitch
1294 ;; Implemented persistent action.
1296 ;; Revision 1.2 2008/07/30 13:37:16 rubikitch
1299 ;; Revision 1.1 2008/07/30 13:22:06 rubikitch
1303 ;; ugly hack to auto-update version
1304 (defvar anything-version nil
)
1305 (setq anything-version
"$Id: anything.el,v 1.280 2010-04-01 02:22:22 rubikitch Exp $")
1307 ;; (require 'anything-match-plugin nil t)
1309 ;; (@* "User Configuration")
1311 ;; This is only an example. Customize it to your own taste!
1312 (defvar anything-sources
`(((name .
"Buffers")
1315 (remove-if (lambda (name)
1316 (or (equal name anything-buffer
)
1317 (eq ?\
(aref name
0))))
1318 (mapcar 'buffer-name
(buffer-list)))))
1321 ((name .
"File Name History")
1322 (candidates . file-name-history
)
1323 (match (lambda (candidate)
1324 ;; list basename matches first
1327 (file-name-nondirectory candidate
)))
1330 ;; and then directory part matches
1331 (let ((dir (file-name-directory candidate
)))
1333 (string-match anything-pattern dir
)))))
1336 ((name .
"Files from Current Directory")
1338 (setq anything-default-directory
1339 default-directory
)))
1340 (candidates .
(lambda ()
1342 anything-default-directory
)))
1345 ((name .
"Complex Command History")
1346 (candidates .
(lambda ()
1347 (mapcar 'prin1-to-string
1349 (action .
(("Repeat Complex Command" .
1353 "The source of candidates for anything.
1355 (setq anything-sources (list anything-c-foo anything-c-bar))
1357 (setq anything-sources '(anything-c-foo anything-c-bar))
1358 The latter is recommended because if you change anything-c-* variable,
1359 you do not have to update `anything-sources'.
1361 You are STRONGLY recommended to define a command which calls
1362 `anything' or `anything-other-buffer' with argument rather than
1363 to set `anything-sources' externally.
1365 If you want to change `anything-sources' during `anything' invocation,
1366 use `anything-set-sources', never use `setq'.
1373 ;; This value is only provided as an example. Customize it to your own
1375 (defvar anything-type-attributes
1376 '((file (action .
(("Find File" . find-file
)
1377 ("Delete File" .
(lambda (file)
1378 (if (y-or-n-p (format "Really delete file %s? "
1380 (delete-file file
)))))))
1381 (buffer (action .
(("Switch to Buffer" . switch-to-buffer
)
1382 ("Pop to Buffer" . pop-to-buffer
)
1383 ("Display Buffer" . display-buffer
)
1384 ("Kill Buffer" . kill-buffer
)))))
1385 "It's a list of (TYPE ATTRIBUTES ...). ATTRIBUTES are the same
1386 as attributes for `anything-sources'. TYPE connects the value
1387 to the appropriate sources in `anything-sources'.
1389 This allows specifying common attributes for several
1390 sources. For example, sources which provide files can specify
1391 common attributes with a `file' type.")
1394 (defvar anything-enable-shortcuts nil
1395 "*Whether to use digit/alphabet shortcut to select the first nine matches.
1396 If t then they can be selected using Ctrl+<number>.
1397 If 'alphabet then they can be selected using Shift+<alphabet>.
1399 Keys (digit/alphabet) are listed in `anything-digit-shortcut-index-alist'.")
1401 (defvaralias 'anything-enable-digit-shortcuts
'anything-enable-shortcuts
1402 "Alphabet shortcuts are usable now. Then `anything-enable-digit-shortcuts' should be renamed.
1403 `anything-enable-digit-shortcuts' is retained for compatibility.")
1405 (defvar anything-shortcut-keys-alist
1406 '((alphabet .
"asdfghjklzxcvbnmqwertyuiop")
1409 (defvar anything-display-source-at-screen-top t
1410 "*If t, `anything-next-source' and `anything-previous-source'
1411 display candidates at the top of screen.")
1413 (defvar anything-candidate-number-limit
50
1414 "*Do not show more candidates than this limit from individual
1415 sources. It is usually pointless to show hundreds of matches
1416 when the pattern is empty, because it is much simpler to type a
1417 few characters to narrow down the list of potential candidates.
1419 Set it to nil if you don't want this limit.")
1422 (defvar anything-idle-delay
0.5
1423 "*The user has to be idle for this many seconds, before
1424 candidates from delayed sources are collected. This is useful
1425 for sources involving heavy operations (like launching external
1426 programs), so that candidates from the source are not retrieved
1427 unnecessarily if the user keeps typing.
1429 It also can be used to declutter the results anything displays,
1430 so that results from certain sources are not shown with every
1431 character typed, only if the user hesitates a bit.")
1434 (defvar anything-input-idle-delay
0.1
1435 "The user has to be idle for this many seconds, before ALL candidates are collected.
1436 Unlink `anything-input-idle', it is also effective for non-delayed sources.
1437 If nil, candidates are collected immediately. ")
1440 (defvar anything-samewindow nil
1441 "If t then Anything doesn't pop up a new window, it uses the
1442 current window to show the candidates.")
1445 (defvar anything-source-filter nil
1446 "A list of source names to be displayed. Other sources won't
1447 appear in the search results. If nil then there is no filtering.
1448 See also `anything-set-source-filter'.")
1451 (defvar anything-map
1452 (let ((map (copy-keymap minibuffer-local-map
)))
1453 (define-key map
(kbd "<down>") 'anything-next-line
)
1454 (define-key map
(kbd "<up>") 'anything-previous-line
)
1455 (define-key map
(kbd "C-n") 'anything-next-line
)
1456 (define-key map
(kbd "C-p") 'anything-previous-line
)
1457 (define-key map
(kbd "<prior>") 'anything-previous-page
)
1458 (define-key map
(kbd "<next>") 'anything-next-page
)
1459 (define-key map
(kbd "M-v") 'anything-previous-page
)
1460 (define-key map
(kbd "C-v") 'anything-next-page
)
1461 (define-key map
(kbd "M-<") 'anything-beginning-of-buffer
)
1462 (define-key map
(kbd "M->") 'anything-end-of-buffer
)
1463 (define-key map
(kbd "<right>") 'anything-next-source
)
1464 (define-key map
(kbd "<left>") 'anything-previous-source
)
1465 (define-key map
(kbd "<RET>") 'anything-exit-minibuffer
)
1466 (define-key map
(kbd "C-1") 'anything-select-with-digit-shortcut
)
1467 (define-key map
(kbd "C-2") 'anything-select-with-digit-shortcut
)
1468 (define-key map
(kbd "C-3") 'anything-select-with-digit-shortcut
)
1469 (define-key map
(kbd "C-4") 'anything-select-with-digit-shortcut
)
1470 (define-key map
(kbd "C-5") 'anything-select-with-digit-shortcut
)
1471 (define-key map
(kbd "C-6") 'anything-select-with-digit-shortcut
)
1472 (define-key map
(kbd "C-7") 'anything-select-with-digit-shortcut
)
1473 (define-key map
(kbd "C-8") 'anything-select-with-digit-shortcut
)
1474 (define-key map
(kbd "C-9") 'anything-select-with-digit-shortcut
)
1475 (loop for c from ?A to ?Z do
1476 (define-key map
(make-string 1 c
) 'anything-select-with-digit-shortcut
))
1477 (define-key map
(kbd "C-i") 'anything-select-action
)
1478 (define-key map
(kbd "C-z") 'anything-execute-persistent-action
)
1479 (define-key map
(kbd "C-e") 'anything-select-2nd-action-or-end-of-line
)
1480 (define-key map
(kbd "C-j") 'anything-select-3rd-action
)
1481 (define-key map
(kbd "C-o") 'anything-next-source
)
1482 (define-key map
(kbd "C-M-v") 'anything-scroll-other-window
)
1483 (define-key map
(kbd "M-<next>") 'anything-scroll-other-window
)
1484 (define-key map
(kbd "C-M-y") 'anything-scroll-other-window-down
)
1485 (define-key map
(kbd "C-M-S-v") 'anything-scroll-other-window-down
)
1486 (define-key map
(kbd "M-<prior>") 'anything-scroll-other-window-down
)
1487 (define-key map
(kbd "C-SPC") 'anything-toggle-visible-mark
)
1488 (define-key map
(kbd "M-[") 'anything-prev-visible-mark
)
1489 (define-key map
(kbd "M-]") 'anything-next-visible-mark
)
1490 (define-key map
(kbd "C-k") 'anything-delete-minibuffer-content
)
1492 (define-key map
(kbd "C-s") 'anything-isearch
)
1493 (define-key map
(kbd "C-r") 'undefined
)
1494 (define-key map
(kbd "C-t") 'anything-toggle-resplit-window
)
1495 (define-key map
(kbd "C-x C-f") 'anything-quit-and-find-file
)
1497 (define-key map
(kbd "C-c C-d") 'anything-delete-current-selection
)
1498 (define-key map
(kbd "C-c C-y") 'anything-yank-selection
)
1499 (define-key map
(kbd "C-c C-k") 'anything-kill-selection-and-quit
)
1500 (define-key map
(kbd "C-c C-f") 'anything-follow-mode
)
1501 (define-key map
(kbd "C-c C-u") 'anything-force-update
)
1503 ;; Debugging command
1504 (define-key map
"\C-c\C-x\C-d" 'anything-debug-output
)
1505 ;; Use `describe-mode' key in `global-map'
1506 (dolist (k (where-is-internal 'describe-mode global-map
))
1507 (define-key map k
'anything-help
))
1508 ;; the defalias is needed because commands are bound by name when
1509 ;; using iswitchb, so only commands having the prefix anything-
1511 (defalias 'anything-previous-history-element
'previous-history-element
)
1512 (defalias 'anything-next-history-element
'next-history-element
)
1513 (define-key map
(kbd "M-p") 'anything-previous-history-element
)
1514 (define-key map
(kbd "M-n") 'anything-next-history-element
)
1516 "Keymap for anything.
1518 If you execute `anything-iswitchb-setup', some keys are modified.
1519 See `anything-iswitchb-setup-keys'.")
1521 (defvar anything-isearch-map
1522 (let ((map (make-sparse-keymap)))
1523 (set-keymap-parent map
(current-global-map))
1524 (define-key map
(kbd "<return>") 'anything-isearch-default-action
)
1525 (define-key map
(kbd "<RET>") 'anything-isearch-default-action
)
1526 (define-key map
(kbd "C-i") 'anything-isearch-select-action
)
1527 (define-key map
(kbd "C-g") 'anything-isearch-cancel
)
1528 (define-key map
(kbd "M-s") 'anything-isearch-again
)
1529 (define-key map
(kbd "<backspace>") 'anything-isearch-delete
)
1530 ;; add printing chars
1531 (loop for i from
32 below
256 do
1532 (define-key map
(vector i
) 'anything-isearch-printing-char
))
1534 "Keymap for anything incremental search.")
1537 (defgroup anything nil
1538 "Open anything." :prefix
"anything-" :group
'convenience
)
1540 (defface anything-header
1541 '((t (:inherit header-line
)))
1542 "Face for header lines in the anything buffer." :group
'anything
)
1544 (defvar anything-header-face
'anything-header
1545 "Face for header lines in the anything buffer.")
1547 (defface anything-isearch-match
'((t (:background
"Yellow")))
1548 "Face for isearch in the anything buffer." :group
'anything
)
1550 (defvar anything-isearch-match-face
'anything-isearch-match
1551 "Face for matches during incremental search.")
1553 (defvar anything-selection-face
'highlight
1554 "Face for currently selected item.")
1556 (defvar anything-iswitchb-idle-delay
1
1557 "Show anything completions if the user is idle that many
1558 seconds after typing.")
1560 (defvar anything-iswitchb-dont-touch-iswithcb-keys nil
1561 "If t then those commands are not bound from `anything-map'
1562 under iswitchb which would override standard iswithcb keys.
1564 This allows an even more seamless integration with iswitchb for
1565 those who prefer using iswitchb bindings even if the anything
1566 completions buffer is popped up.
1568 Note that you can bind alternative keys for the same command in
1569 `anything-map', so that you can use different keys for anything
1570 under iswitchb. For example, I bind the character \ to
1571 `anything-exit-minibuffer' which key is just above Enter on my
1572 keyboard. This way I can switch buffers with Enter and choose
1573 anything completions with \.")
1575 ;;----------------------------------------------------------------------
1577 (defvar anything-buffer
"*anything*"
1578 "Buffer showing completions.")
1580 (defvar anything-action-buffer
"*anything action*"
1581 "Buffer showing actions.")
1583 (defvar anything-selection-overlay nil
1584 "Overlay used to highlight the currently selected item.")
1586 (defvar anything-isearch-overlay nil
1587 "Overlay used to highlight the current match during isearch.")
1589 (defvar anything-digit-overlays nil
1590 "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
1592 (defvar anything-candidate-cache nil
1593 "Holds the available candidate withing a single anything invocation.")
1595 (defvar anything-pattern
1596 "The input pattern used to update the anything buffer.")
1598 (defvar anything-input
1599 "The input typed in the candidates panel.")
1601 (defvar anything-async-processes nil
1602 "List of information about asynchronous processes managed by anything.")
1604 (defvar anything-digit-shortcut-count
0
1605 "Number of digit shortcuts shown in the anything buffer.")
1607 (defvar anything-before-initialize-hook nil
1608 "Run before anything initialization.
1609 This hook is run before init functions in `anything-sources'.")
1611 (defvar anything-after-initialize-hook nil
1612 "Run after anything initialization.
1613 Global variables are initialized and the anything buffer is created.
1614 But the anything buffer has no contents. ")
1616 (defvar anything-update-hook nil
1617 "Run after the anything buffer was updated according the new input pattern.
1618 This hook is run at the beginning of buffer.
1619 The first candidate is selected after running this hook.
1620 See also `anything-after-update-hook'.")
1622 (defvar anything-after-update-hook nil
1623 "Run after the anything buffer was updated according the new input pattern.
1624 This is very similar to `anything-update-hook' but selection is not moved.
1625 It is useful to select a particular object instead of the first one. ")
1627 (defvar anything-cleanup-hook nil
1628 "Run after anything minibuffer is closed, IOW this hook is executed BEFORE performing action. ")
1630 (defvar anything-after-action-hook nil
1631 "Run after executing action.")
1633 (defvar anything-after-persistent-action-hook nil
1634 "Run after executing persistent action.")
1636 (defvar anything-restored-variables
1637 '( anything-candidate-number-limit
1638 anything-source-filter
1639 anything-source-in-each-line-flag
1641 "Variables which are restored after `anything' invocation.")
1642 ;; `anything-saved-sources' is removed
1644 (defvar anything-saved-selection nil
1645 "Saved value of the currently selected object when the action
1648 ;; `anything-original-source-filter' is removed
1650 (defvar anything-candidate-separator
1651 "--------------------"
1652 "Candidates separator of `multiline' source.")
1654 (defvar anything-current-buffer nil
1655 "Current buffer when `anything' is invoked.")
1657 (defvar anything-buffer-file-name nil
1658 "`buffer-file-name' when `anything' is invoked.")
1660 (defvar anything-saved-action nil
1661 "Saved value of the currently selected action by key.")
1663 (defvar anything-last-sources nil
1664 "OBSOLETE!! Sources of previously invoked `anything'.")
1666 (defvar anything-saved-current-source nil
1667 "Saved value of the original (anything-get-current-source) when the action
1670 (defvar anything-compiled-sources nil
1671 "Compiled version of `anything-sources'. ")
1673 (defvar anything-in-persistent-action nil
1674 "Flag whether in persistent-action or not.")
1676 (defvar anything-quick-update nil
1677 "If non-nil, suppress displaying sources which are out of screen at first.
1678 They are treated as delayed sources at this input.
1679 This flag makes `anything' a bit faster with many sources.")
1681 (defvar anything-last-sources-local nil
1682 "Buffer local value of `anything-sources'.")
1683 (defvar anything-last-buffer nil
1684 "`anything-buffer' of previously `anything' session.")
1686 (defvar anything-save-configuration-functions
1687 '(set-window-configuration . current-window-configuration
)
1688 "If you want to save and restore frame configuration, set this variable to
1689 '(set-frame-configuration . current-frame-configuration)
1691 Older version saves/restores frame configuration, but the default is changed now,
1692 because flickering is occurred in some environment.
1695 (defvar anything-persistent-action-use-special-display nil
1696 "If non-nil, use `special-display-function' in persistent action.")
1698 (defvar anything-execute-action-at-once-if-one nil
1699 "If non-nil and there is one candidate, execute the first action without selection.
1700 It is useful for `anything' applications.")
1702 (defvar anything-quit-if-no-candidate nil
1703 "if non-nil and there is no candidate, do not display *anything* buffer and quit.
1704 This variable accepts a function, which is executed if no candidate.
1706 It is useful for `anything' applications.")
1708 (defvar anything-scroll-amount nil
1709 "Scroll amount used by `anything-scroll-other-window' and `anything-scroll-other-window-down'.
1710 If you prefer scrolling line by line, set this value to 1.")
1712 (defvar anything-display-function
'anything-default-display-buffer
1713 "Function to display *anything* buffer.
1714 It is `anything-default-display-buffer' by default, which affects `anything-samewindow'.")
1716 (defvar anything-delayed-init-executed nil
)
1718 (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"
1719 "Help string displayed in mode-line in `anything'.
1720 If nil, use default `mode-line-format'.")
1722 (defvar anything-help-message
1723 "\\<anything-map>The keys that are defined for `anything' are:
1725 "Detailed help message string for `anything'.
1726 It also accepts function or variable symbol.")
1728 (put 'anything
'timid-completion
'disabled
)
1730 (defvar anything-inhibit-fit-frame-flag t
1731 "If non-nil, inhibit fitting anything frame to its buffer.
1732 It is nil by default because some flickering occurred in some environment.
1734 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
1735 `fit-frame-inhibit-fitting' to nil.")
1737 (defvar anything-source-in-each-line-flag nil
1738 "If non-nil, add anything-source text-property in each candidate.
1739 experimental feature.")
1741 (defvar anything-debug-forms nil
1742 "Forms to show in `anything-debug-output'.
1743 Otherwise all variables started with `anything-' are shown.
1744 It is useful for debug.")
1745 (defvaralias 'anything-debug-variables
'anything-debug-forms
)
1747 ;; (@* "Internal Variables")
1748 (defvar anything-test-candidate-list nil
)
1749 (defvar anything-test-mode nil
)
1750 (defvar anything-source-name nil
)
1751 (defvar anything-candidate-buffer-alist nil
)
1752 (defvar anything-check-minibuffer-input-timer nil
)
1753 (defvar anything-match-hash
(make-hash-table :test
'equal
))
1754 (defvar anything-cib-hash
(make-hash-table :test
'equal
))
1755 (defvar anything-tick-hash
(make-hash-table :test
'equal
))
1756 (defvar anything-issued-errors nil
)
1757 (defvar anything-shortcut-keys nil
)
1758 (defvar anything-once-called-functions nil
)
1759 (defvar anything-follow-mode nil
)
1761 ;; (@* "Programming Tools")
1762 (defmacro anything-aif
(test-form then-form
&rest else-forms
)
1763 "Anaphoric if. Temporary variable `it' is the result of test-form."
1764 `(let ((it ,test-form
))
1765 (if it
,then-form
,@else-forms
)))
1766 (put 'anything-aif
'lisp-indent-function
2)
1768 (defun anything-mklist (obj)
1769 "If OBJ is a list (but not lambda), return itself, otherwise make a list with one element."
1770 (if (and (listp obj
) (not (functionp obj
)))
1774 ;; (@* "Anything API")
1775 (defun anything-buffer-get ()
1776 "If *anything action* buffer is shown, return `anything-action-buffer', otherwise `anything-buffer'."
1777 (if (anything-action-window)
1778 anything-action-buffer
1781 (defun anything-window ()
1782 "Window of `anything-buffer'."
1783 (get-buffer-window (anything-buffer-get) 'visible
))
1785 (defun anything-action-window ()
1786 "Window of `anything-action-buffer'."
1787 (get-buffer-window anything-action-buffer
'visible
))
1789 (defmacro with-anything-window
(&rest body
)
1790 `(let ((--tmpfunc-- (lambda () ,@body
)))
1791 (if anything-test-mode
1792 (with-current-buffer (anything-buffer-get)
1793 (funcall --tmpfunc--
))
1794 (with-selected-window (anything-window)
1795 (funcall --tmpfunc--
)))))
1796 (put 'with-anything-window
'lisp-indent-function
0)
1798 (defmacro with-anything-restore-variables
(&rest body
)
1799 "Restore variables specified by `anything-restored-variables' after executing BODY ."
1800 `(let ((--orig-vars (mapcar (lambda (v) (cons v
(symbol-value v
))) anything-restored-variables
)))
1801 (unwind-protect (progn ,@body
)
1802 (loop for
(var . value
) in --orig-vars
1803 do
(set var value
)))))
1804 (put 'with-anything-restore-variables
'lisp-indent-function
0)
1806 (defun* anything-attr
(attribute-name &optional
(src (anything-get-current-source)))
1807 "Get the value of ATTRIBUTE-NAME of SRC (source).
1808 if SRC is omitted, use current source.
1809 It is useful to write your sources."
1810 (anything-aif (assq attribute-name src
)
1813 (defun* anything-attr-defined
(attribute-name &optional
(src (anything-get-current-source)))
1814 "Return non-nil if ATTRIBUTE-NAME of SRC (source) is defined.
1815 if SRC is omitted, use current source.
1816 It is useful to write your sources."
1817 (and (assq attribute-name src
) t
))
1819 (defun* anything-attrset
(attribute-name value
&optional
(src (anything-get-current-source)))
1820 "Set the value of ATTRIBUTE-NAME of SRC (source) to VALUE.
1821 if SRC is omitted, use current source.
1822 It is useful to write your sources."
1823 (anything-aif (assq attribute-name src
)
1825 (setcdr src
(cons (cons attribute-name value
) (cdr src
))))
1828 ;; anything-set-source-filter
1830 ;; This function sets a filter for anything sources and it may be
1831 ;; called while anything is running. It can be used to toggle
1832 ;; displaying of sources dinamically. For example, additional keys
1833 ;; can be bound into `anything-map' to display only the file-related
1834 ;; results if there are too many matches from other sources and
1835 ;; you're after files only:
1837 ;; Shift+F shows only file results from some sources:
1839 ;; (define-key anything-map "F" 'anything-my-show-files-only)
1841 ;; (defun anything-my-show-files-only ()
1843 ;; (anything-set-source-filter '("File Name History"
1844 ;; "Files from Current Directory")))
1846 ;; Shift+A shows all results:
1848 ;; (define-key anything-map "A" 'anything-my-show-all)
1850 ;; (defun anything-my-show-all ()
1852 ;; (anything-set-source-filter nil))
1855 ;; Note that you have to prefix the functions with anything- prefix,
1856 ;; otherwise they won't be bound when Anything is used under
1857 ;; Iswitchb. The -my- part is added to avoid collisions with
1858 ;; existing Anything function names.
1860 (defun anything-set-source-filter (sources)
1861 "Sets the value of `anything-source-filter' and updates the list of results."
1862 (unless (and (listp sources
)
1863 (loop for name in sources always
(stringp name
)))
1864 (error "invalid data in `anything-set-source-filter': %S" sources
))
1865 (setq anything-source-filter sources
)
1868 (defun anything-set-sources (sources &optional no-init no-update
)
1869 "Set `anything-sources' during `anything' invocation.
1870 If NO-INIT is non-nil, skip executing init functions of SOURCES.
1871 If NO-UPDATE is non-nil, skip executing `anything-update'."
1872 (setq anything-compiled-sources nil
1873 anything-sources sources
)
1874 (unless no-init
(anything-funcall-foreach 'init
))
1875 (unless no-update
(anything-update)))
1877 (defvar anything-compile-source-functions
1878 '(anything-compile-source--type
1879 anything-compile-source--dummy
1880 anything-compile-source--disable-shortcuts
1881 anything-compile-source--candidates-in-buffer
)
1882 "Functions to compile elements of `anything-sources' (plug-in).")
1884 (defun anything-get-sources ()
1885 "Return compiled `anything-sources', which is memoized.
1890 `anything-type-attributes' are merged in.
1892 candidates, volatile and match attrubute are created.
1896 ((anything-action-window)
1899 (anything-compiled-sources)
1902 (setq anything-compiled-sources
1903 (anything-compile-sources anything-sources anything-compile-source-functions
)))))
1905 (defun* anything-get-selection
(&optional
(buffer nil buffer-s
) (force-display-part))
1906 "Return the currently selected item or nil.
1907 if BUFFER is nil or unspecified, use anything-buffer as default value.
1908 If FORCE-DISPLAY-PART is non-nil, return the display string."
1909 (setq buffer
(if (and buffer buffer-s
) buffer anything-buffer
))
1910 (unless (zerop (buffer-size (get-buffer buffer
)))
1911 (with-current-buffer buffer
1913 (or (and (not force-display-part
)
1914 (get-text-property (overlay-start
1915 anything-selection-overlay
)
1916 'anything-realvalue
))
1917 (let ((disp (buffer-substring-no-properties
1918 (overlay-start anything-selection-overlay
)
1919 (1- (overlay-end anything-selection-overlay
))))
1920 (source (anything-get-current-source)))
1921 (anything-aif (and (not force-display-part
)
1922 (assoc-default 'display-to-real source
))
1923 (anything-funcall-with-source source it disp
)
1925 (unless (equal selection
"")
1928 (defun anything-get-action ()
1929 "Return the associated action for the selected candidate."
1930 (unless (zerop (buffer-size (get-buffer (anything-buffer-get))))
1931 (let* ((source (anything-get-current-source))
1932 (actions (assoc-default 'action source
)))
1934 (anything-aif (assoc-default 'action-transformer source
)
1935 ;; (funcall it actions (anything-get-selection))
1936 (anything-composed-funcall-with-source source it actions
(anything-get-selection))
1939 (defun anything-get-current-source ()
1940 "Return the source for the current selection / in init/candidates/action/candidate-transformer/filtered-candidate-transformer function."
1941 (declare (special source
))
1942 ;; The name `anything-get-current-source' should be used in init function etc.
1943 (if (and (boundp 'anything-source-name
) (stringp anything-source-name
))
1946 (with-current-buffer (anything-buffer-get)
1947 (get-text-property (point) 'anything-source
))
1949 (with-current-buffer (anything-buffer-get)
1950 ;; This goto-char shouldn't be necessary, but point is moved to
1951 ;; point-min somewhere else which shouldn't happen.
1952 (goto-char (overlay-start anything-selection-overlay
))
1953 (let* ((header-pos (or (anything-get-previous-header-pos)
1954 (anything-get-next-header-pos)))
1958 (message "No candidates")
1959 (return-from exit nil
))
1960 (goto-char header-pos
)
1961 (buffer-substring-no-properties
1962 (line-beginning-position) (line-end-position)))))
1963 (some (lambda (source)
1964 (if (equal (assoc-default 'name source
)
1967 (anything-get-sources))))))))
1969 (defun anything-buffer-is-modified (buffer)
1970 "Return non-nil when BUFFER is modified since `anything' was invoked."
1971 (let* ((b (get-buffer buffer
))
1972 (key (concat (buffer-name b
)
1974 (anything-attr 'name
)))
1975 (source-tick (or (gethash key anything-tick-hash
) 0))
1976 (buffer-tick (buffer-chars-modified-tick b
)))
1977 (prog1 (/= source-tick buffer-tick
)
1978 (puthash key buffer-tick anything-tick-hash
))))
1979 (defun anything-current-buffer-is-modified ()
1980 "Return non-nil when `anything-current-buffer' is modified since `anything' was invoked."
1981 (anything-buffer-is-modified anything-current-buffer
))
1983 (defvar anything-quit nil
)
1984 (defun anything-run-after-quit (function &rest args
)
1985 "Perform an action after quitting `anything'.
1986 The action is to call FUNCTION with arguments ARGS."
1987 (setq anything-quit t
)
1988 (apply 'run-with-idle-timer
0 nil function args
)
1989 (anything-exit-minibuffer))
1991 (defun define-anything-type-attribute (type definition
&optional doc
)
1992 "Register type attribute of TYPE as DEFINITION with DOC.
1993 DOC is displayed in `anything-type-attributes' docstring.
1995 Use this function is better than setting `anything-type-attributes' directly."
1996 (anything-add-type-attribute type definition
)
1997 (and doc
(anything-document-type-attribute type doc
))
2000 (defvar anything-additional-attributes nil
2001 "List of all `anything' attributes.")
2002 (defvaralias 'anything-attributes
'anything-additional-attributes
)
2003 (defun anything-document-attribute (attribute short-doc
&optional long-doc
)
2004 "Register ATTRIBUTE documentation introduced by plug-in.
2005 SHORT-DOC is displayed beside attribute name.
2006 LONG-DOC is displayed below attribute name and short documentation."
2008 (setq short-doc
(concat "(" short-doc
")"))
2009 (setq long-doc short-doc
2011 (add-to-list 'anything-additional-attributes attribute t
)
2012 (put attribute
'anything-attrdoc
2013 (concat "- " (symbol-name attribute
) " " short-doc
"\n\n" long-doc
"\n")))
2014 (put 'anything-document-attribute
'lisp-indent-function
2)
2016 (defun anything-require-at-least-version (version)
2017 "Output error message unless anything.el is older than VERSION.
2018 This is suitable for anything applications."
2019 (when (and (string= "1." (substring version
0 2))
2020 (string-match "1\.\\([0-9]+\\)" anything-version
)
2021 (< (string-to-number (match-string 1 anything-version
))
2022 (string-to-number (substring version
2))))
2023 (error "Please update anything.el!!
2025 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
2027 or M-x install-elisp-from-emacswiki anything.el")))
2029 (defun anything-interpret-value (value &optional source
)
2030 "interpret VALUE as variable, function or literal.
2031 If VALUE is a function, call it with no arguments and return the value.
2032 If SOURCE is `anything' source, `anything-source-name' is source name.
2034 If VALUE is a variable, return the value.
2036 If VALUE is a symbol, but it is not a function or a variable, cause an error.
2038 Otherwise, return VALUE itself."
2039 (cond ((and source
(functionp value
))
2040 (anything-funcall-with-source source value
))
2043 ((and (symbolp value
) (boundp value
))
2044 (symbol-value value
))
2046 (error "anything-interpret-value: Symbol must be a function or a variable"))
2050 (defun anything-once (function &rest args
)
2051 "Ensure FUNCTION with ARGS to be called once in `anything' session."
2052 (let ((spec (cons function args
)))
2053 (unless (member spec anything-once-called-functions
)
2054 (apply function args
)
2055 (push spec anything-once-called-functions
))))
2057 ;; (@* "Core: tools")
2058 (defun anything-funcall-with-source (source func
&rest args
)
2059 (let ((anything-source-name (assoc-default 'name source
))
2061 (dolist (func (if (functionp func
) (list func
) func
) result
)
2062 (setq result
(apply func args
)))))
2064 (defun anything-funcall-foreach (sym)
2065 "Call the sym function(s) for each source if any."
2066 (dolist (source (anything-get-sources))
2067 (when (symbolp source
)
2068 (setq source
(symbol-value source
)))
2069 (anything-aif (assoc-default sym source
)
2070 (anything-funcall-with-source source it
))))
2072 (defun anything-normalize-sources (sources)
2073 "If SOURCES is only one source, make a list."
2074 (cond ((or (and sources
; avoid nil
2076 (and (listp sources
) (assq 'name sources
)))
2079 (t anything-sources
)))
2081 (defun anything-approximate-candidate-number ()
2082 "Approximate Number of candidates.
2083 It is used to check if candidate number is 0, 1, or 2+."
2084 (with-current-buffer anything-buffer
2085 (let ((lines (1- (line-number-at-pos (1- (point-max))))))
2089 (goto-char (point-min))
2091 (if (anything-pos-multiline-p)
2092 (if (search-forward anything-candidate-separator nil t
) 2 1)
2095 (defmacro with-anything-quittable
(&rest body
)
2096 `(let (inhibit-quit)
2099 (quit (setq anything-quit t
)
2102 (put 'with-anything-quittable
'lisp-indent-function
0)
2104 (defun anything-compose (arg-lst func-lst
)
2105 "Call each function in FUNC-LST with the arguments specified in ARG-LST.
2106 The result of each function will be the new `car' of ARG-LST.
2108 This function allows easy sequencing of transformer functions."
2109 (dolist (func func-lst
)
2110 (setcar arg-lst
(apply func arg-lst
)))
2113 (defun anything-composed-funcall-with-source (source funcs
&rest args
)
2114 (if (functionp funcs
)
2115 (apply 'anything-funcall-with-source source funcs args
)
2116 (apply 'anything-funcall-with-source
2117 source
(lambda (&rest args
) (anything-compose args funcs
)) args
)))
2119 ;; (@* "Core: entry point")
2120 (defvar anything-buffers nil
2121 "All of `anything-buffer' in most recently used order.")
2124 (defun anything (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap
)
2125 "Select anything. In Lisp program, some optional arguments can be used.
2127 Note that all the optional arguments are prefixed because of
2128 dynamic scope problem, IOW argument variables may eat
2129 already-bound variables. Yuck!
2133 Temporary value of `anything-sources'. It also accepts a
2134 symbol, interpreted as a variable of an anything source. It
2135 also accepts an alist representing an anything source, which is
2136 detected by (assq 'name ANY-SOURCES)
2141 Temporary value of `anything-pattern', ie. initial input of minibuffer.
2145 Prompt other than \"pattern: \".
2149 If t, Resurrect previously instance of `anything'. Skip the initialization.
2150 If 'noresume, this instance of `anything' cannot be resumed.
2154 Initially selected candidate. Specified by exact candidate or a regexp.
2155 Note that it is not working with delayed sources.
2159 `anything-buffer' instead of *anything*.
2163 `anything-map' for current `anything' session.
2165 ;; TODO more document
2168 (with-anything-restore-variables
2169 (let (;; It is needed because `anything-source-name' is non-nil
2170 ;; when `anything' is invoked by action. Awful global scope.
2171 anything-source-name anything-in-persistent-action
2173 (case-fold-search t
)
2174 (anything-buffer (or any-buffer anything-buffer
))
2175 (anything-map (or any-keymap anything-map
)))
2176 (anything-frame/window-configuration
'save
)
2177 (setq anything-sources
(anything-normalize-sources any-sources
))
2178 (anything-initialize-1 any-resume any-input
)
2179 (anything-hooks 'setup
)
2180 (if (eq any-resume t
)
2182 (anything-window-configuration 'restore
)
2183 (error (anything-display-buffer anything-buffer
)))
2184 (anything-display-buffer anything-buffer
))
2186 (anything-read-pattern-maybe any-prompt any-input any-preselect any-resume
)
2188 (anything-hooks 'cleanup
)
2189 (anything-frame/window-configuration
'restore
))
2190 (unless anything-quit
2191 (anything-execute-selection-action-1))))
2196 (defun anything-resume-p (any-resume)
2197 "Whethre current anything session is resumed or not."
2198 (memq any-resume
'(t window-only
)))
2200 (defun anything-initialize-1 (any-resume any-input
)
2201 (anything-current-position 'save
)
2202 (if (anything-resume-p any-resume
)
2203 (anything-initialize-overlays (anything-buffer-get))
2204 (anything-initialize))
2205 (unless (eq any-resume
'noresume
)
2206 (anything-recent-push anything-buffer
'anything-buffers
)
2207 (setq anything-last-buffer anything-buffer
))
2208 (when any-input
(setq anything-input any-input anything-pattern any-input
))
2209 (and (anything-resume-p any-resume
) (anything-funcall-foreach 'resume
)))
2211 (defun anything-execute-selection-action-1 ()
2213 (anything-execute-selection-action)
2214 (anything-aif (get-buffer anything-action-buffer
)
2216 (run-hooks 'anything-after-action-hook
)))
2218 (defun anything-on-quit ()
2219 (setq minibuffer-history
(cons anything-input minibuffer-history
))
2220 (anything-current-position 'restore
))
2222 (defun anything-resume-select-buffer (input)
2223 (anything '(((name .
"Resume anything buffer")
2224 (candidates . anything-buffers
)
2225 (action . identity
)))
2226 input nil
'noresume nil
"*anything resume*"))
2228 (defun* anything-resume
(&optional
(any-buffer anything-last-buffer
) buffer-pattern
(any-resume t
))
2229 "Resurrect previously invoked `anything'."
2231 (when (or current-prefix-arg buffer-pattern
)
2232 (setq any-buffer
(anything-resume-select-buffer buffer-pattern
)))
2233 (setq anything-compiled-sources nil
)
2235 (or (buffer-local-value 'anything-last-sources-local
(get-buffer any-buffer
))
2236 anything-last-sources anything-sources
)
2237 (buffer-local-value 'anything-input-local
(get-buffer any-buffer
)) nil any-resume nil any-buffer
))
2239 ;;; rubikitch: experimental
2240 ;;; I use this and check it whether I am convenient.
2241 ;;; I may introduce an option to control the behavior.
2242 (defun* anything-resume-window-only
(&optional
(any-buffer anything-last-buffer
) buffer-pattern
)
2244 (anything-resume any-buffer buffer-pattern
'window-only
))
2246 (defun anything-recent-push (elt list-var
)
2247 "Add ELT to the value of LIST-VAR as most recently used value."
2248 (let ((m (member elt
(symbol-value list-var
))))
2249 (and m
(set list-var
(delq (car m
) (symbol-value list-var
))))
2250 (push elt
(symbol-value list-var
))))
2252 ;;; (@* "Core: Accessors")
2253 (defvar anything-window-configuration nil
)
2254 ;;; (set-window-configuration (buffer-local-value 'anything-window-configuration (get-buffer "*anything buffers*")))
2255 (defun anything-window-configuration (save-or-restore)
2256 (case save-or-restore
2258 (with-current-buffer anything-buffer
2259 (set (make-local-variable 'anything-window-configuration
)
2260 (current-window-configuration))))
2262 (with-current-buffer anything-buffer
2263 (set-window-configuration anything-window-configuration
))
2264 (select-window (anything-window)))))
2266 (defvar anything-current-position nil
2267 "Cons of (point) and (window-start) when `anything' is invoked.
2268 It is needed because restoring position when `anything' is keyboard-quitted.")
2269 (defun anything-current-position (save-or-restore)
2270 (case save-or-restore
2272 (setq anything-current-position
(cons (point) (window-start))))
2274 (goto-char (car anything-current-position
))
2275 (set-window-start (selected-window) (cdr anything-current-position
)))))
2277 ;;; FIXME I want to remove them. But anything-iswitchb uses them.
2278 (defun anything-current-frame/window-configuration
()
2279 (funcall (cdr anything-save-configuration-functions
)))
2280 (defun anything-set-frame/window-configuration
(conf)
2281 (funcall (car anything-save-configuration-functions
) conf
))
2283 (declare-function 'anything-frame
/window-configuration
"anything")
2285 (defun anything-frame/window-configuration
(save-or-restore)
2286 (case save-or-restore
2287 (save (setq conf
(funcall (cdr anything-save-configuration-functions
))))
2288 (restore (funcall (car anything-save-configuration-functions
) conf
)))))
2293 (defun anything-at-point (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer
)
2294 "Same as `anything' except when C-u is pressed, the initial input is the symbol at point."
2296 (anything any-sources
2297 (if current-prefix-arg
2298 (concat "\\b" (thing-at-point 'symbol
) "\\b"
2299 (if (featurep 'anything-match-plugin
) " " ""))
2301 any-prompt any-resume any-preselect any-buffer
))
2303 (defun anything-other-buffer (any-sources any-buffer
)
2304 "Simplified interface of `anything' with other `anything-buffer'"
2305 (anything any-sources nil nil nil nil any-buffer
))
2307 ;; (@* "Core: Display *anything* buffer")
2308 (defun anything-display-buffer (buf)
2309 "Display *anything* buffer."
2310 (funcall anything-display-function buf
))
2312 (defun anything-default-display-buffer (buf)
2313 (funcall (if anything-samewindow
'switch-to-buffer
'pop-to-buffer
) buf
))
2315 ;; (@* "Core: initialize")
2316 (defun anything-initialize ()
2317 "Initialize anything settings and set up the anything buffer."
2318 (run-hooks 'anything-before-initialize-hook
)
2319 (setq anything-once-called-functions nil
)
2320 (setq anything-delayed-init-executed nil
)
2321 (setq anything-current-buffer
(current-buffer))
2322 (setq anything-buffer-file-name buffer-file-name
)
2323 (setq anything-issued-errors nil
)
2324 (setq anything-compiled-sources nil
)
2325 (setq anything-saved-current-source nil
)
2326 ;; Call the init function for sources where appropriate
2327 (anything-funcall-foreach 'init
)
2329 (setq anything-pattern
"")
2330 (setq anything-input
"")
2331 (setq anything-candidate-cache nil
)
2332 (setq anything-last-sources anything-sources
)
2334 (anything-create-anything-buffer)
2335 (run-hooks 'anything-after-initialize-hook
))
2337 (defun anything-read-pattern-maybe (any-prompt any-input any-preselect any-resume
)
2338 (if (anything-resume-p any-resume
) (anything-mark-current-line) (anything-update))
2339 (select-frame-set-input-focus (window-frame (minibuffer-window)))
2340 (anything-preselect any-preselect
)
2341 (let ((ncandidate (anything-approximate-candidate-number))
2342 (minibuffer-local-map anything-map
))
2343 (cond ((and anything-execute-action-at-once-if-one
2346 ((and anything-quit-if-no-candidate
(= ncandidate
0))
2347 (setq anything-quit t
)
2348 (and (functionp anything-quit-if-no-candidate
)
2349 (funcall anything-quit-if-no-candidate
)))
2351 (read-string (or any-prompt
"pattern: ") any-input
)))))
2353 (defun anything-create-anything-buffer (&optional test-mode
)
2354 "Create newly created `anything-buffer'.
2355 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
2357 (setq anything-candidate-cache nil
))
2358 (with-current-buffer (get-buffer-create anything-buffer
)
2359 (buffer-disable-undo)
2361 (set (make-local-variable 'inhibit-read-only
) t
)
2362 (set (make-local-variable 'anything-last-sources-local
) anything-sources
)
2363 (set (make-local-variable 'anything-follow-mode
) nil
)
2365 (setq cursor-type nil
)
2366 (setq mode-name
"Anything"))
2367 (anything-initialize-overlays anything-buffer
)
2368 (get-buffer anything-buffer
))
2370 (defun anything-initialize-overlays (buffer)
2371 (if anything-selection-overlay
2372 ;; make sure the overlay belongs to the anything buffer if
2373 ;; it's newly created
2374 (move-overlay anything-selection-overlay
(point-min) (point-min)
2375 (get-buffer buffer
))
2377 (setq anything-selection-overlay
2378 (make-overlay (point-min) (point-min) (get-buffer buffer
)))
2379 (overlay-put anything-selection-overlay
'face anything-selection-face
))
2381 (when anything-enable-shortcuts
2382 (setq anything-shortcut-keys
(assoc-default anything-enable-shortcuts anything-shortcut-keys-alist
)))
2384 (if anything-enable-shortcuts
2385 (unless anything-digit-overlays
2386 (setq anything-digit-overlays
2387 (loop for key across anything-shortcut-keys
2388 for overlay
= (make-overlay (point-min) (point-min) (get-buffer buffer
))
2389 do
(overlay-put overlay
'before-string
2390 (format "%s - " (upcase (make-string 1 key
))))
2393 (when anything-digit-overlays
2394 (dolist (overlay anything-digit-overlays
)
2395 (delete-overlay overlay
))
2396 (setq anything-digit-overlays nil
))))
2398 (defun anything-hooks (setup-or-cleanup)
2399 (let ((hooks '((post-command-hook anything-check-minibuffer-input
)
2400 (minibuffer-setup-hook anything-print-error-messages
)
2401 (minibuffer-exit-hook (lambda () (anything-window-configuration 'save
))))))
2402 (if (eq setup-or-cleanup
'setup
)
2403 (dolist (args hooks
) (apply 'add-hook args
))
2404 (dolist (args (reverse hooks
)) (apply 'remove-hook args
)))))
2406 ;; (@* "Core: clean up")
2407 (defun anything-cleanup ()
2408 "Clean up the mess."
2409 (with-current-buffer anything-buffer
2410 (setq cursor-type t
))
2411 (bury-buffer anything-buffer
)
2412 (anything-funcall-foreach 'cleanup
)
2413 (if anything-check-minibuffer-input-timer
2414 (cancel-timer anything-check-minibuffer-input-timer
))
2415 (anything-kill-async-processes)
2416 (run-hooks 'anything-cleanup-hook
))
2418 ;; (@* "Core: input handling")
2419 (defun anything-check-minibuffer-input ()
2420 "Extract input string from the minibuffer and check if it needs
2422 (if (or (not anything-input-idle-delay
) (anything-action-window))
2423 (anything-check-minibuffer-input-1)
2424 (if anything-check-minibuffer-input-timer
2425 (cancel-timer anything-check-minibuffer-input-timer
))
2426 (setq anything-check-minibuffer-input-timer
2427 (run-with-idle-timer anything-input-idle-delay nil
2428 'anything-check-minibuffer-input-1
))))
2430 (defun anything-check-minibuffer-input-1 ()
2431 (with-anything-quittable
2432 (with-selected-window (minibuffer-window)
2433 (anything-check-new-input (minibuffer-contents)))))
2435 (defun anything-check-new-input (input)
2436 "Check input string and update the anything buffer if
2438 (unless (equal input anything-pattern
)
2439 (setq anything-pattern input
)
2440 (unless (anything-action-window)
2441 (setq anything-input anything-pattern
))
2444 ;; (@* "Core: source compiler")
2445 (defvar anything-compile-source-functions-default anything-compile-source-functions
2446 "Plug-ins this file provides.")
2447 (defun anything-compile-sources (sources funcs
)
2448 "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
2449 Anything plug-ins are realized by this function."
2452 (loop with source
= (if (listp source
) source
(symbol-value source
))
2454 do
(setq source
(funcall f source
))
2455 finally
(return source
)))
2458 ;; (@* "Core: plug-in attribute documentation hack")
2460 ;; `anything-document-attribute' is public API.
2461 (defadvice documentation-property
(after anything-document-attribute activate
)
2462 "Hack to display plug-in attributes' documentation as `anything-sources' docstring."
2463 (when (eq symbol
'anything-sources
)
2464 (setq ad-return-value
2465 (concat ad-return-value
"\n"
2466 (mapconcat (lambda (sym) (get sym
'anything-attrdoc
))
2467 anything-additional-attributes
2469 ;; (describe-variable 'anything-sources)
2470 ;; (documentation-property 'anything-sources 'variable-documentation)
2471 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
2473 ;; (@* "Core: all candidates")
2474 (defun anything-get-candidates (source)
2475 "Retrieve and return the list of candidates from
2477 (let ((name (assoc-default 'name source
)))
2478 (unless (member name anything-delayed-init-executed
)
2479 (anything-aif (assoc-default 'delayed-init source
)
2480 (when (functionp it
)
2481 (with-current-buffer anything-current-buffer
(funcall it
))
2482 (add-to-list 'anything-delayed-init-executed name
)))))
2483 (let* ((candidate-source (assoc-default 'candidates source
))
2484 (candidates (anything-interpret-value candidate-source source
)))
2485 (cond ((processp candidates
) candidates
)
2486 ((listp candidates
) (anything-transform-candidates candidates source
))
2487 (t (error (concat "Candidates must either be a function, "
2488 " a variable or a list: %s")
2489 candidate-source
)))))
2492 (defun anything-transform-candidates (candidates source
&optional process-p
)
2493 "Transform CANDIDATES according to candidate transformers."
2494 (anything-aif (assoc-default 'candidate-transformer source
)
2495 (setq candidates
(anything-composed-funcall-with-source source it candidates
)))
2496 (anything-aif (and process-p
(assoc-default 'filtered-candidate-transformer source
))
2497 (setq candidates
(anything-composed-funcall-with-source source it candidates source
)))
2498 (anything-aif (assoc-default 'real-to-display source
)
2499 (setq candidates
(anything-funcall-with-source
2503 ;; override DISPLAY from candidate-transformer
2504 (cons (funcall it
(cdr cand_
)) (cdr cand_
))
2505 (cons (funcall it cand_
) cand_
)))
2510 (defun anything-get-cached-candidates (source)
2511 "Return the cached value of candidates for SOURCE.
2512 Cache the candidates if there is not yet a cached value."
2513 (let* ((name (assoc-default 'name source
))
2514 (candidate-cache (assoc name anything-candidate-cache
))
2517 (setq candidates
(cdr candidate-cache
))
2519 (setq candidates
(anything-get-candidates source
))
2521 (if (processp candidates
)
2523 (push (cons candidates
2525 (list (cons 'item-count
0)
2526 (cons 'incomplete-line
""))))
2527 anything-async-processes
)
2528 (set-process-filter candidates
'anything-output-filter
)
2529 (setq candidates nil
))
2531 (unless (assoc 'volatile source
)
2532 (setq candidate-cache
(cons name candidates
))
2533 (push candidate-cache anything-candidate-cache
))))
2537 ;; (@* "Core: narrowing candidates")
2538 (defun anything-candidate-number-limit (source)
2539 "`anything-candidate-number-limit' variable may be overridden by SOURCE.
2540 If (candidate-number-limit) is in SOURCE, show all candidates in SOURCE,
2541 ie. cancel the effect of `anything-candidate-number-limit'."
2542 (anything-aif (assq 'candidate-number-limit source
)
2543 (or (cdr it
) 99999999)
2544 (or anything-candidate-number-limit
99999999)))
2546 (defun anything-compute-matches (source)
2547 "Compute matches from SOURCE according to its settings."
2548 (let ((doit (lambda ()
2549 (let ((functions (assoc-default 'match source
))
2550 (anything-source-name (assoc-default 'name source
))
2551 (limit (anything-candidate-number-limit source
))
2553 (anything-aif (assoc-default 'pattern-transformer source
)
2554 (anything-composed-funcall-with-source source it anything-pattern
)
2557 (cond ((or (equal anything-pattern
"") (equal functions
'(identity)))
2558 (setq matches
(anything-get-cached-candidates source
))
2559 (if (> (length matches
) limit
)
2561 (subseq matches
0 limit
))))
2564 (let ((item-count 0)
2565 (cands (anything-get-cached-candidates source
))
2570 (list (lambda (candidate)
2571 (string-match anything-pattern candidate
)))))
2573 (clrhash anything-match-hash
)
2574 (dolist (function functions
)
2575 (let (newmatches c cc
)
2576 (dolist (candidate cands
)
2577 (when (and (not (gethash candidate anything-match-hash
))
2578 (setq c
(if (listp candidate
)
2581 (setq cc
(cond ((stringp c
) c
)
2582 ((symbolp c
) (symbol-name c
))))
2583 (funcall function cc
))
2584 (puthash candidate t anything-match-hash
)
2585 (push candidate newmatches
)
2589 (when (= item-count limit
)
2593 (setq matches
(append matches
(reverse newmatches
)))
2598 (invalid-regexp (setq matches nil
)))))
2600 (anything-aif (assoc-default 'filtered-candidate-transformer source
)
2602 (anything-composed-funcall-with-source source it matches source
)))
2608 (error (anything-log-error
2609 "anything-compute-matches: error when processing source: %s"
2610 (assoc-default 'name source
))
2613 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2615 (defun anything-process-source (source)
2616 "Display matches from SOURCE according to its settings."
2617 (let ((matches (anything-compute-matches source
)))
2619 (when anything-test-mode
2620 (setq anything-test-candidate-list
2621 `(,@anything-test-candidate-list
2622 (,(assoc-default 'name source
)
2624 (let ((multiline (assq 'multiline source
))
2627 (anything-insert-header-from-source source
)
2628 (dolist (match matches
)
2629 (if (and multiline separate
)
2630 (anything-insert-candidate-separator)
2633 (when (and anything-enable-shortcuts
2634 (not (eq anything-digit-shortcut-count
2635 (length anything-digit-overlays
))))
2636 (move-overlay (nth anything-digit-shortcut-count
2637 anything-digit-overlays
)
2638 (line-beginning-position)
2639 (line-beginning-position))
2640 (incf anything-digit-shortcut-count
))
2641 (anything-insert-match match
'insert source
))
2644 (put-text-property start
(point) 'anything-multiline t
))))))
2646 (defun anything-process-delayed-sources (delayed-sources)
2647 "Process delayed sources if the user is idle for
2648 `anything-idle-delay' seconds."
2649 (with-anything-quittable
2650 (if (sit-for (if anything-input-idle-delay
2651 (max 0 (- anything-idle-delay anything-input-idle-delay
))
2652 anything-idle-delay
))
2653 (with-current-buffer anything-buffer
2655 (goto-char (point-max))
2656 (dolist (source delayed-sources
)
2657 (anything-process-source source
))
2659 (when (and (not (equal (buffer-size) 0))
2661 (= (overlay-start anything-selection-overlay
)
2662 (overlay-end anything-selection-overlay
)))
2663 (goto-char (point-min))
2664 (anything-next-line)))
2666 (goto-char (point-min))
2667 (run-hooks 'anything-update-hook
))
2668 (anything-maybe-fit-frame)))))
2670 ;; (@* "Core: *anything* buffer contents")
2671 (defvar anything-input-local nil
)
2672 (defun anything-update ()
2673 "Update the list of matches in the anything buffer according to
2674 the current pattern."
2675 (setq anything-digit-shortcut-count
0)
2676 (anything-kill-async-processes)
2677 (with-current-buffer (anything-buffer-get)
2678 (set (make-local-variable 'anything-input-local
) anything-pattern
)
2681 (if anything-enable-shortcuts
2682 (dolist (overlay anything-digit-overlays
)
2683 (delete-overlay overlay
)))
2685 (let (delayed-sources)
2687 (dolist (source (anything-get-sources))
2688 (when (and (or (not anything-source-filter
)
2689 (member (assoc-default 'name source
) anything-source-filter
))
2690 (>= (length anything-pattern
)
2691 (anything-aif (assoc 'requires-pattern source
)
2694 (if (or (assoc 'delayed source
)
2695 (and anything-quick-update
2696 (< (window-height (get-buffer-window (current-buffer)))
2697 (line-number-at-pos (point-max)))))
2698 (push source delayed-sources
)
2699 (anything-process-source source
))))
2701 (goto-char (point-min))
2702 (save-excursion (run-hooks 'anything-update-hook
))
2703 (anything-next-line)
2704 (setq delayed-sources
(nreverse delayed-sources
))
2705 (if anything-test-mode
2706 (dolist (source delayed-sources
)
2707 (anything-process-source source
))
2708 (anything-maybe-fit-frame)
2709 (when delayed-sources
2710 (run-with-idle-timer (if (featurep 'xemacs
)
2714 'anything-process-delayed-sources
2716 ;; FIXME I want to execute anything-after-update-hook
2717 ;; AFTER processing delayed sources
2718 (run-hooks 'anything-after-update-hook
))))))
2720 (defun anything-force-update ()
2721 "Recalculate and update candidates.
2722 If current source has `update' attribute, a function without argument, call it before update."
2724 (anything-aif (anything-attr 'update
)
2725 (anything-funcall-with-source (anything-get-current-source) it
))
2726 ;; Remove from candidate cache to recalculate candidates
2727 (setq anything-candidate-cache
2728 (delete (assoc (assoc-default 'name
(anything-get-current-source)) anything-candidate-cache
)
2729 anything-candidate-cache
))
2730 ;; Go to original selection after update
2731 (let ((selection (anything-get-selection))
2732 (source (anything-get-current-source)))
2734 (with-anything-window
2735 (anything-goto-source source
)
2736 (forward-char -
1) ;back to \n
2737 (if (search-forward (concat "\n" selection
"\n") nil t
)
2739 (goto-char (point-min))
2741 (anything-mark-current-line))))
2743 (defun anything-insert-match (match insert-function source
)
2744 "Insert MATCH into the anything buffer. If MATCH is a list then
2745 insert the string inteneded to appear on the display and store
2746 the real value in a text property."
2747 (let ((start (line-beginning-position (point)))
2748 (string (if (listp match
) (car match
) match
))
2749 (realvalue (if (listp match
) (cdr match
))))
2750 (when (symbolp string
) (setq string
(symbol-name string
)))
2751 (when (stringp string
)
2752 (funcall insert-function string
)
2753 ;; Some sources with candidates-in-buffer have already added
2754 ;; 'anything-realvalue property when creating candidate buffer.
2755 (unless (get-text-property start
'anything-realvalue
)
2757 (put-text-property start
(line-end-position)
2758 'anything-realvalue realvalue
)))
2759 (when anything-source-in-each-line-flag
2760 (put-text-property start
(line-end-position)
2761 'anything-source source
))
2762 (funcall insert-function
"\n"))))
2764 (defun anything-insert-header-from-source (source)
2765 (let ((name (assoc-default 'name source
)))
2766 (anything-insert-header name
2767 (anything-aif (assoc-default 'header-name source
)
2768 (anything-funcall-with-source source it name
)))))
2770 (defun anything-insert-header (name &optional display-string
)
2771 "Insert header of source NAME into the anything buffer."
2773 (let ((start (point)))
2775 (put-text-property start
(point) 'anything-header-separator t
)))
2777 (let ((start (point)))
2779 (put-text-property (line-beginning-position)
2780 (line-end-position) 'anything-header t
)
2781 (when display-string
2782 (overlay-put (make-overlay (line-beginning-position) (line-end-position))
2783 'display display-string
))
2785 (put-text-property start
(point) 'face anything-header-face
)))
2788 (defun anything-insert-candidate-separator ()
2789 "Insert separator of candidates into the anything buffer."
2790 (insert anything-candidate-separator
)
2791 (put-text-property (line-beginning-position)
2792 (line-end-position) 'anything-candidate-separator t
)
2798 ;; (@* "Core: async process")
2799 (defun anything-output-filter (process string
)
2800 "Process output from PROCESS."
2801 (let* ((process-assoc (assoc process anything-async-processes
))
2802 (process-info (cdr process-assoc
))
2803 (insertion-marker (assoc-default 'insertion-marker process-info
))
2804 (incomplete-line-info (assoc 'incomplete-line process-info
))
2805 (item-count-info (assoc 'item-count process-info
))
2806 (limit (anything-candidate-number-limit process-info
)))
2808 (with-current-buffer anything-buffer
2810 (if insertion-marker
2811 (goto-char insertion-marker
)
2813 (goto-char (point-max))
2814 (anything-insert-header-from-source process-info
)
2815 (setcdr process-assoc
2816 (append process-info
`((insertion-marker .
,(point-marker))))))
2818 (let ((lines (split-string string
"\n"))
2819 (multiline (assq 'multiline process-info
))
2821 candidates separate
)
2823 (if (not (cdr lines
))
2824 ;; store last incomplete line until new output arrives
2825 (setcdr incomplete-line-info
(car lines
))
2827 (if (cdr incomplete-line-info
)
2829 (push (concat (cdr incomplete-line-info
) (car lines
))
2831 (setcdr incomplete-line-info nil
))
2833 (push (car lines
) candidates
)))
2837 (setq candidates
(reverse candidates
))
2838 (dolist (candidate (anything-transform-candidates candidates process-info t
))
2840 ;; (if (and multiline separate)
2841 ;; (anything-insert-candidate-separator)
2842 ;; (setq separate t))
2843 (anything-insert-match candidate
'insert-before-markers process-info
)
2844 (incf (cdr item-count-info
))
2847 ;; (put-text-property start (point) 'anything-multiline t))
2848 (when (>= (cdr item-count-info
) limit
)
2849 (anything-kill-async-process process
)
2852 (anything-maybe-fit-frame)
2854 (run-hooks 'anything-update-hook
)
2857 (anything-next-line)
2859 (save-selected-window
2860 (select-window (get-buffer-window anything-buffer
'visible
))
2861 (anything-mark-current-line))))))
2864 (defun anything-kill-async-processes ()
2865 "Kill all known asynchronous processes according to
2866 `anything-async-processes'."
2867 "Kill locate process."
2868 (dolist (process-info anything-async-processes
)
2869 (anything-kill-async-process (car process-info
)))
2870 (setq anything-async-processes nil
))
2873 (defun anything-kill-async-process (process)
2874 "Kill PROCESS and detach the associated functions."
2875 (set-process-filter process nil
)
2876 (delete-process process
))
2879 ;; (@* "Core: action")
2880 (defun anything-execute-selection-action (&optional selection action clear-saved-action
)
2881 "If a candidate was selected then perform the associated
2883 (setq selection
(or selection
(anything-get-selection)))
2884 (setq action
(or action
2885 anything-saved-action
2886 (if (get-buffer anything-action-buffer
)
2887 (anything-get-selection anything-action-buffer
)
2888 (anything-get-action))))
2889 (let ((source (or anything-saved-current-source
(anything-get-current-source))))
2890 (if (and (not selection
) (assoc 'accept-empty source
))
2891 (setq selection
""))
2892 (if (and (listp action
)
2893 (not (functionp action
))) ; lambda
2894 ;;select the default action
2895 (setq action
(cdar action
)))
2896 (unless clear-saved-action
(setq anything-saved-action nil
))
2897 (if (and selection action
)
2898 (anything-funcall-with-source source action selection
))))
2900 (defun anything-select-action ()
2901 "Select an action for the currently selected candidate.
2902 If action buffer is selected, back to the anything buffer."
2904 (cond ((get-buffer-window anything-action-buffer
'visible
)
2905 (set-window-buffer (get-buffer-window anything-action-buffer
) anything-buffer
)
2906 (kill-buffer anything-action-buffer
))
2908 (setq anything-saved-selection
(anything-get-selection))
2909 (unless anything-saved-selection
2910 (error "Nothing is selected."))
2911 (setq anything-saved-current-source
(anything-get-current-source))
2912 (let ((actions (anything-get-action)))
2913 (if (functionp actions
)
2914 (message "Sole action: %s" actions
)
2915 (with-current-buffer (get-buffer-create anything-action-buffer
)
2917 (buffer-disable-undo)
2918 (set-window-buffer (get-buffer-window anything-buffer
) anything-action-buffer
)
2919 (set (make-local-variable 'anything-sources
)
2920 `(((name .
"Actions")
2922 (candidates .
,actions
)
2923 ;; Override `anything-candidate-number-limit'
2924 (candidate-number-limit .
9999))))
2925 (set (make-local-variable 'anything-source-filter
) nil
)
2926 (set (make-local-variable 'anything-selection-overlay
) nil
)
2927 (set (make-local-variable 'anything-digit-overlays
) nil
)
2928 (anything-initialize-overlays anything-action-buffer
))
2929 (with-selected-window (minibuffer-window)
2930 (delete-minibuffer-contents))
2931 (setq anything-pattern
'dummy
) ; so that it differs from the
2934 (anything-check-minibuffer-input))))))
2936 ;; (@* "Core: selection")
2937 (defun anything-move-selection-common (move-func unit direction
)
2938 "Move the selection marker to a new position determined by
2939 UNIT and DIRECTION."
2940 (unless (or (zerop (buffer-size (get-buffer (anything-buffer-get))))
2941 (not (anything-window)))
2942 (with-anything-window
2944 (while (and (not (bobp))
2945 (or (anything-pos-header-line-p)
2946 (anything-pos-candidate-separator-p)))
2947 (forward-line (if (and (eq direction
'previous
)
2948 (not (eq (line-beginning-position) (point-min))))
2951 (and (bobp) (forward-line 1)) ;skip first header
2952 (and (eobp) (forward-line -
1)) ;avoid last empty line
2953 (when (and anything-display-source-at-screen-top
(eq unit
'source
))
2954 (set-window-start (selected-window)
2955 (save-excursion (forward-line -
1) (point))))
2956 (when (anything-get-previous-header-pos)
2957 (anything-mark-current-line))
2958 (anything-display-mode-line (anything-get-current-source)))))
2960 (defvar anything-mode-line-string-real nil
)
2961 (defun anything-display-mode-line (source)
2962 (set (make-local-variable 'anything-mode-line-string
)
2963 (anything-interpret-value (or (assoc-default 'mode-line source
)
2964 (default-value 'anything-mode-line-string
))
2966 (if anything-mode-line-string
2967 (setq mode-line-format
2968 '(" " mode-line-buffer-identification
" "
2969 (line-number-mode "%l") " " (anything-follow-mode "(F)")
2970 " " anything-mode-line-string-real
"-%-")
2971 anything-mode-line-string-real
2972 (substitute-command-keys anything-mode-line-string
))
2973 (setq mode-line-format
2974 (default-value 'mode-line-format
)))
2975 (setq header-line-format
2976 (anything-interpret-value (assoc-default 'header-line source
) source
)))
2978 (defun anything-previous-line ()
2979 "Move selection to the previous line."
2981 (anything-move-selection-common
2984 (when (anything-pos-multiline-p)
2985 (if (or (anything-pos-header-line-p)
2986 (anything-pos-candidate-separator-p))
2989 (let ((header-pos (anything-get-previous-header-pos))
2990 (candidate-pos (anything-get-previous-candidate-separator-pos)))
2992 (if (or (null candidate-pos
) (< candidate-pos header-pos
))
2993 (goto-char header-pos
)
2994 (goto-char candidate-pos
))
2995 (forward-line 1)))))
2998 (defun anything-next-line ()
2999 "Move selection to the next line."
3001 (anything-move-selection-common
3003 (if (not (anything-pos-multiline-p))
3005 (let ((header-pos (anything-get-next-header-pos))
3006 (candidate-pos (anything-get-next-candidate-separator-pos)))
3007 (if (and candidate-pos
3008 (or (null header-pos
)
3009 (< candidate-pos header-pos
)))
3010 (goto-char candidate-pos
)
3012 (goto-char header-pos
)))
3014 (forward-line 1)))))
3017 (defun anything-previous-page ()
3018 "Move selection back with a pageful."
3020 (anything-move-selection-common
3024 (beginning-of-buffer (goto-char (point-min)))))
3027 (defun anything-next-page ()
3028 "Move selection forward with a pageful."
3030 (anything-move-selection-common
3034 (end-of-buffer (goto-char (point-max)))))
3037 (defun anything-beginning-of-buffer ()
3038 "Move selection at the top."
3040 (anything-move-selection-common (lambda () (goto-char (point-min)))
3043 (defun anything-end-of-buffer ()
3044 "Move selection at the bottom."
3046 (anything-move-selection-common (lambda () (goto-char (point-max)))
3049 (defun anything-previous-source ()
3050 "Move selection to the previous source."
3052 (anything-move-selection-common
3056 (goto-char (point-max))
3057 (if (anything-pos-header-line-p)
3060 (goto-char (anything-get-previous-header-pos))
3064 (defun anything-next-source ()
3065 "Move selection to the next source."
3067 (anything-move-selection-common
3068 (lambda () (goto-char (or (anything-get-next-header-pos) (point-min))))
3071 (defun anything-goto-source (source-or-name)
3072 "Move the selection to the source (SOURCE-OR-NAME)."
3073 (anything-move-selection-common
3075 (goto-char (point-min))
3076 (let ((name (if (stringp source-or-name
) source-or-name
3077 (assoc-default 'name source-or-name
))))
3078 (while (not (string= name
(buffer-substring (point-at-bol) (point-at-eol))))
3079 (goto-char (anything-get-next-header-pos)))))
3082 (defun anything-mark-current-line ()
3083 "Move selection overlay to current line."
3084 (move-overlay anything-selection-overlay
3085 (line-beginning-position)
3086 (if (anything-pos-multiline-p)
3087 (let ((header-pos (anything-get-next-header-pos))
3088 (candidate-pos (anything-get-next-candidate-separator-pos)))
3089 (or (and (null header-pos
) candidate-pos candidate-pos
)
3090 (and header-pos candidate-pos
(< candidate-pos header-pos
) candidate-pos
)
3093 (1+ (line-end-position))))
3094 (anything-follow-execute-persistent-action-maybe))
3096 (defun anything-this-command-key ()
3097 (event-basic-type (elt (this-command-keys-vector) 0)))
3098 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
3100 (defun anything-select-with-digit-shortcut ()
3102 (if anything-enable-shortcuts
3103 (save-selected-window
3104 (select-window (anything-window))
3105 (let* ((index (position (anything-this-command-key) anything-shortcut-keys
))
3106 (overlay (nth index anything-digit-overlays
)))
3107 (when (overlay-buffer overlay
)
3108 (goto-char (overlay-start overlay
))
3109 (anything-mark-current-line)
3110 (anything-exit-minibuffer))))
3111 (self-insert-command 1)))
3113 (defun anything-exit-minibuffer ()
3114 "Select the current candidate by exiting the minibuffer."
3116 (declare (special anything-iswitchb-candidate-selected
))
3117 (setq anything-iswitchb-candidate-selected
(anything-get-selection))
3121 (defun anything-get-next-header-pos ()
3122 "Return the position of the next header from point."
3123 (next-single-property-change (point) 'anything-header
))
3126 (defun anything-get-previous-header-pos ()
3127 "Return the position of the previous header from point"
3128 (previous-single-property-change (point) 'anything-header
))
3131 (defun anything-pos-multiline-p ()
3132 "Return non-nil if the current position is in the multiline source region."
3133 (get-text-property (point) 'anything-multiline
))
3136 (defun anything-get-next-candidate-separator-pos ()
3137 "Return the position of the next candidate separator from point."
3138 (next-single-property-change (point) 'anything-candidate-separator
))
3141 (defun anything-get-previous-candidate-separator-pos ()
3142 "Return the position of the previous candidate separator from point."
3143 (previous-single-property-change (point) 'anything-candidate-separator
))
3146 (defun anything-pos-header-line-p ()
3147 "Return t if the current line is a header line."
3148 (or (get-text-property (line-beginning-position) 'anything-header
)
3149 (get-text-property (line-beginning-position) 'anything-header-separator
)))
3151 (defun anything-pos-candidate-separator-p ()
3152 "Return t if the current line is a candidate separator."
3153 (get-text-property (line-beginning-position) 'anything-candidate-separator
))
3155 ;; (@* "Core: error handling")
3156 (defun anything-log-error (&rest args
)
3157 "Accumulate error messages into `anything-issued-errors'."
3158 (let ((msg (apply 'format args
)))
3159 (unless (member msg anything-issued-errors
)
3160 (add-to-list 'anything-issued-errors msg
))))
3162 (defun anything-print-error-messages ()
3163 "Print error messages in `anything-issued-errors'."
3164 (message "%s" (mapconcat 'identity
(reverse anything-issued-errors
) "\n")))
3167 ;; (@* "Core: help")
3168 (defun anything-help-internal (bufname insert-content-fn
)
3169 "Show long message during `anything' session."
3170 (save-window-excursion
3171 (select-window (anything-window))
3172 (delete-other-windows)
3173 (switch-to-buffer (get-buffer-create bufname
))
3174 (setq mode-line-format
"%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
3175 (setq cursor-type nil
)
3177 (funcall insert-content-fn
)
3180 (loop for event
= (read-event) do
3182 ((?\C-v ?
) (scroll-up))
3183 ((?\M-v ?b
) (scroll-down))
3186 (defun anything-help ()
3187 "Help of `anything'."
3189 (anything-help-internal
3192 (insert (substitute-command-keys
3193 (anything-interpret-value anything-help-message
)))
3196 (defun anything-debug-output ()
3197 "Show all anything-related variables at this time."
3199 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function
))
3201 (defun anything-debug-output-function (&optional vars
)
3202 (message "Calculating all anything-related values...")
3203 (insert "If you debug some variables or forms, set `anything-debug-forms'
3204 to a list of forms.\n\n")
3206 anything-debug-forms
3207 (apropos-internal "^anything-" 'boundp
)))
3209 (pp-to-string v
) "\n"
3210 (pp-to-string (eval v
)) "\n"))
3211 (message "Calculating all anything-related values...Done")
3214 ;; (@* "Core: misc")
3215 (defun anything-kill-buffer-hook ()
3216 "Remove tick entry from `anything-tick-hash' when killing a buffer."
3217 (loop for key being the hash-keys in anything-tick-hash
3218 if
(string-match (format "^%s/" (regexp-quote (buffer-name))) key
)
3219 do
(remhash key anything-tick-hash
)))
3220 (add-hook 'kill-buffer-hook
'anything-kill-buffer-hook
)
3222 (defun anything-maybe-fit-frame ()
3223 "Fit anything frame to its buffer, and put it at top right of display.
3225 It is disabled by default because some flickering occurred in some environment.
3226 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
3227 `fit-frame-inhibit-fitting' to nil.
3228 You can set user options `fit-frame-max-width-percent' and
3229 `fit-frame-max-height-percent' to control max frame size."
3230 (declare (warn (unresolved 0)))
3231 (when (and (require 'fit-frame nil t
)
3232 (boundp 'fit-frame-inhibit-fitting-flag
)
3233 (not anything-inhibit-fit-frame-flag
)
3234 (not fit-frame-inhibit-fitting-flag
)
3237 (with-anything-window
3238 (fit-frame nil nil nil t
)
3239 (modify-frame-parameters
3241 `((left .
,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
3242 (top .
0))))))) ; The (top . 0) shouldn't be necessary (Emacs bug).
3244 (defun anything-preselect (candidate-or-regexp)
3245 (when candidate-or-regexp
3246 (with-anything-window
3247 (goto-char (point-min))
3248 ;; go to first candidate of first source
3250 (let ((start (point)))
3251 (unless (or (re-search-forward (concat "^" (regexp-quote candidate-or-regexp
) "$") nil t
)
3252 (progn (goto-char start
)
3253 (re-search-forward candidate-or-regexp nil t
)))
3255 (anything-mark-current-line)))))
3257 (defun anything-delete-current-selection ()
3258 "Delete the currently selected item."
3260 (with-anything-window
3261 (cond ((anything-pos-multiline-p)
3262 (anything-aif (anything-get-next-candidate-separator-pos)
3263 (delete-region (point-at-bol)
3264 (1+ (progn (goto-char it
) (point-at-eol))))
3266 (goto-char (anything-get-previous-candidate-separator-pos))
3267 (delete-region (point-at-bol) (point-max)))
3269 (goto-char (or (anything-get-previous-candidate-separator-pos)
3273 (delete-region (point-at-bol) (1+ (point-at-eol)))
3274 (when (eobp) (forward-line -
1))))
3275 (anything-mark-current-line)))
3277 (defun anything-delete-minibuffer-content ()
3278 "Same as `delete-minibuffer-contents' but this is a command."
3280 (delete-minibuffer-contents))
3282 ;; (@* "Built-in plug-in: type")
3283 (defun anything-compile-source--type (source)
3284 (anything-aif (assoc-default 'type source
)
3285 (append source
(assoc-default it anything-type-attributes
) nil
)
3288 ;; `define-anything-type-attribute' is public API.
3290 (defun anything-add-type-attribute (type definition
)
3291 (anything-aif (assq type anything-type-attributes
)
3292 (setq anything-type-attributes
(delete it anything-type-attributes
)))
3293 (push (cons type definition
) anything-type-attributes
))
3295 (defvar anything-types nil
)
3296 (defun anything-document-type-attribute (type doc
)
3297 (add-to-list 'anything-types type t
)
3298 (put type
'anything-typeattrdoc
3299 (concat "- " (symbol-name type
) "\n\n" doc
"\n")))
3301 (defadvice documentation-property
(after anything-document-type-attribute activate
)
3302 "Hack to display type attributes' documentation as `anything-type-attributes' docstring."
3303 (when (eq symbol
'anything-type-attributes
)
3304 (setq ad-return-value
3305 (concat ad-return-value
"\n\n++++ Types currently defined ++++\n"
3306 (mapconcat (lambda (sym) (get sym
'anything-typeattrdoc
))
3307 anything-types
"\n")))))
3309 ;; (@* "Built-in plug-in: dummy")
3310 (defun anything-dummy-candidate (candidate source
)
3311 ;; `source' is defined in filtered-candidate-transformer
3312 (list anything-pattern
))
3314 (defun anything-compile-source--dummy (source)
3315 (if (assoc 'dummy source
)
3317 '((candidates "dummy")
3320 (filtered-candidate-transformer . anything-dummy-candidate
)
3325 ;; (@* "Built-in plug-in: disable-shortcuts")
3326 (defvar anything-orig-enable-shortcuts nil
)
3327 (defun anything-save-enable-shortcuts ()
3329 (lambda () (setq anything-orig-enable-shortcuts anything-enable-shortcuts
3330 anything-enable-shortcuts nil
))))
3331 (defun anything-compile-source--disable-shortcuts (source)
3332 (if (assoc 'disable-shortcuts source
)
3333 (append `((init ,@(anything-mklist (assoc-default 'init source
))
3334 anything-save-enable-shortcuts
)
3335 (resume ,@(anything-mklist (assoc-default 'resume source
))
3336 anything-save-enable-shortcuts
)
3337 (cleanup ,@(anything-mklist (assoc-default 'cleanup source
))
3338 (lambda () (setq anything-enable-shortcuts anything-orig-enable-shortcuts
))))
3342 ;; (@* "Built-in plug-in: candidates-in-buffer")
3343 (defun anything-candidates-in-buffer ()
3344 "Get candidates from the candidates buffer according to `anything-pattern'.
3346 BUFFER is `anything-candidate-buffer' by default. Each
3347 candidate must be placed in one line. This function is meant to
3348 be used in candidates-in-buffer or candidates attribute of an
3349 anything source. Especially fast for many (1000+) candidates.
3352 '((name . \"many files\")
3353 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
3354 (insert-many-filenames))))
3355 (search re-search-forward) ; optional
3356 (candidates-in-buffer)
3359 +===============================================================+
3360 | The new way of making and narrowing candidates: Using buffers |
3361 +===============================================================+
3363 By default, `anything' makes candidates by evaluating the
3364 candidates function, then narrows them by `string-match' for each
3367 But this way is very slow for many candidates. The new way is
3368 storing all candidates in a buffer and narrowing them by
3369 `re-search-forward'. Search function is customizable by search
3370 attribute. The important point is that buffer processing is MUCH
3371 FASTER than string list processing and is the Emacs way.
3373 The init function writes all candidates to a newly-created
3374 candidate buffer. The candidates buffer is created or specified
3375 by `anything-candidate-buffer'. Candidates are stored in a line.
3377 The candidates function narrows all candidates, IOW creates a
3378 subset of candidates dynamically. It is the task of
3379 `anything-candidates-in-buffer'. As long as
3380 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
3381 sufficient in most cases.
3383 Note that `(candidates-in-buffer)' is shortcut of three attributes:
3384 (candidates . anything-candidates-in-buffer)
3387 And `(candidates-in-buffer . func)' is shortcut of three attributes:
3391 The expansion is performed in `anything-get-sources'.
3393 The candidates-in-buffer attribute implies the volatile attribute.
3394 The volatile attribute is needed because `anything-candidates-in-buffer'
3395 creates candidates dynamically and need to be called everytime
3396 `anything-pattern' changes.
3398 Because `anything-candidates-in-buffer' plays the role of `match' attribute
3399 function, specifying `(match identity)' makes the source slightly faster.
3401 To customize `anything-candidates-in-buffer' behavior, use search,
3402 get-line and search-from-end attributes. See also `anything-sources' docstring.
3404 (declare (special source
))
3405 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
3407 (or (assoc-default 'get-line source
)
3408 #'buffer-substring-no-properties
)
3409 ;; use external variable `source'.
3410 (or (assoc-default 'search source
)
3411 (if (assoc 'search-from-end source
)
3412 '(re-search-backward)
3413 '(re-search-forward)))
3414 (anything-candidate-number-limit source
)
3415 (assoc 'search-from-end source
)))
3417 (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
)
3418 ;; buffer == nil when candidates buffer does not exist.
3420 (with-current-buffer buffer
3421 (let ((start-point (if search-from-end
(point-max) (point-min)))
3422 (next-line-fn (if search-from-end
3423 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
3425 (endp (if search-from-end
#'bobp
#'eobp
)))
3426 (goto-char (1- start-point
))
3427 (if (string= pattern
"")
3428 (delq nil
(loop until
(funcall endp
)
3429 for i from
1 to limit
3430 collecting
(funcall get-line-fn
(point-at-bol) (point-at-eol))
3431 do
(funcall next-line-fn
1)))
3434 (next-line-fn (if search-from-end
3435 (lambda (x) (goto-char (max (point-at-bol) 1)))
3438 matches exit newmatches
)
3440 (goto-char (point-min))
3442 (goto-char (point-max))
3444 (setq start-point
(if search-from-end
(point-max) (point-min)))
3445 (clrhash anything-cib-hash
)
3447 (dolist (searcher search-fns
)
3448 (goto-char start-point
)
3449 (setq newmatches nil
)
3450 (loop while
(funcall searcher pattern nil t
)
3451 if
(or (funcall endp
) (< limit i
))
3452 do
(setq exit t
) (return)
3454 (let ((cand (funcall get-line-fn
(point-at-bol) (point-at-eol))))
3455 (unless (gethash cand anything-cib-hash
)
3456 (puthash cand t anything-cib-hash
)
3458 (push cand newmatches
)))
3459 (funcall next-line-fn
1))
3460 (setq matches
(append matches
(nreverse newmatches
)))
3462 (goto-char (point-min))
3464 (goto-char (1- (point-max)))
3467 (set-buffer-modified-p nil
)))
3468 (delq nil matches
)))))))
3471 (defun anything-candidate-buffer (&optional create-or-buffer
)
3472 "Register and return a buffer containing candidates of current source.
3473 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3474 then global candidates buffer.
3476 Acceptable values of CREATE-OR-BUFFER:
3479 Only return the candidates buffer.
3481 Register a buffer as a candidates buffer.
3483 Create a new global candidates buffer,
3484 named \" *anything candidates:SOURCE*\".
3485 - other non-nil value
3486 Create a new global candidates buffer,
3487 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
3489 (let* ((gbufname (format " *anything candidates:%s*" anything-source-name
))
3490 (lbufname (concat gbufname
(buffer-name anything-current-buffer
)))
3492 (when create-or-buffer
3493 (if (bufferp create-or-buffer
)
3494 (setq anything-candidate-buffer-alist
3495 (cons (cons anything-source-name create-or-buffer
)
3496 (delete (assoc anything-source-name anything-candidate-buffer-alist
)
3497 anything-candidate-buffer-alist
)))
3498 (add-to-list 'anything-candidate-buffer-alist
3499 (cons anything-source-name create-or-buffer
))
3500 (when (eq create-or-buffer
'global
)
3501 (loop for b in
(buffer-list)
3502 if
(string-match (format "^%s" (regexp-quote gbufname
)) (buffer-name b
))
3503 do
(kill-buffer b
)))
3504 (with-current-buffer
3505 (get-buffer-create (if (eq create-or-buffer
'global
) gbufname lbufname
))
3506 (buffer-disable-undo)
3508 (font-lock-mode -
1))))
3509 (or (get-buffer lbufname
)
3510 (get-buffer gbufname
)
3511 (anything-aif (assoc-default anything-source-name anything-candidate-buffer-alist
)
3512 (and (buffer-live-p it
) it
)))))
3514 (defun anything-compile-source--candidates-in-buffer (source)
3515 (anything-aif (assoc 'candidates-in-buffer source
)
3516 (append source
`((candidates .
,(or (cdr it
) 'anything-candidates-in-buffer
))
3517 (volatile) (match identity
)))
3520 ;; (@* "Utility: resplit anything window")
3521 (defun anything-toggle-resplit-window ()
3522 "Toggle resplit anything window, vertically or horizontally."
3524 (with-anything-window
3525 (let ((before-height (window-height)))
3528 (select-window (if (= (window-height) before-height
)
3529 (split-window-vertically)
3530 (split-window-horizontally)))
3533 ;; (@* "Utility: select another action by key")
3534 (defun anything-select-nth-action (n)
3535 "Select the nth action for the currently selected candidate."
3536 (setq anything-saved-selection
(anything-get-selection))
3537 (unless anything-saved-selection
3538 (error "Nothing is selected."))
3539 (setq anything-saved-action
(cdr (elt (anything-get-action) n
)))
3540 (anything-exit-minibuffer))
3542 (defun anything-select-2nd-action ()
3543 "Select the 2nd action for the currently selected candidate."
3545 (anything-select-nth-action 1))
3547 (defun anything-select-3rd-action ()
3548 "Select the 3rd action for the currently selected candidate."
3550 (anything-select-nth-action 2))
3552 (defun anything-select-4th-action ()
3553 "Select the 4th action for the currently selected candidate."
3555 (anything-select-nth-action 3))
3557 (defun anything-select-2nd-action-or-end-of-line ()
3558 "Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
3559 Otherwise goto the end of minibuffer."
3562 (anything-select-nth-action 1)
3565 ;; (@* "Utility: Persistent Action")
3566 (defmacro with-anything-display-same-window
(&rest body
)
3567 "Make `pop-to-buffer' and `display-buffer' display in the same window."
3568 `(let ((display-buffer-function 'anything-persistent-action-display-buffer
))
3570 (put 'with-anything-display-same-window
'lisp-indent-function
0)
3572 (defun* anything-execute-persistent-action
(&optional
(attr 'persistent-action
))
3573 "If a candidate is selected then perform the associated action without quitting anything."
3575 (save-selected-window
3576 (select-window (get-buffer-window (anything-buffer-get)))
3577 (select-window (setq minibuffer-scroll-window
3578 (if (one-window-p t
) (split-window)
3579 (next-window (selected-window) 1))))
3580 (let ((anything-in-persistent-action t
))
3581 (with-anything-display-same-window
3582 (anything-execute-selection-action
3584 (or (assoc-default attr
(anything-get-current-source))
3585 (anything-get-action))
3587 (run-hooks 'anything-after-persistent-action-hook
)))))
3589 (defun anything-persistent-action-display-buffer (buf &optional not-this-window
)
3590 "Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
3591 If `anything-persistent-action-use-special-display' is non-nil and
3592 BUF is to be displayed by `special-display-function', use it.
3593 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
3594 (let* ((name (buffer-name buf
))
3595 display-buffer-function pop-up-windows
3596 (same-window-regexps
3597 (unless (and anything-persistent-action-use-special-display
3599 (mapcar (lambda (x) (or (car-safe x
) x
)) special-display-buffer-names
))
3601 (lambda (x) (string-match (or (car-safe x
) x
) name
))
3602 special-display-regexps
)))
3604 (display-buffer buf not-this-window
)))
3606 ;; scroll-other-window(-down)? for persistent-action
3607 (defun anything-scroll-other-window-base (command)
3608 (save-selected-window
3611 (lambda (w) (not (string= anything-buffer
(buffer-name (window-buffer w
)))))
3612 'no-minibuffer
'current-frame
))
3613 (call-interactively command
)))
3615 (defun anything-scroll-other-window ()
3616 "Scroll other window (not *Anything* window) upward."
3618 (anything-scroll-other-window-base (lambda ()
3620 (scroll-up anything-scroll-amount
))))
3621 (defun anything-scroll-other-window-down ()
3622 "Scroll other window (not *Anything* window) downward."
3624 (anything-scroll-other-window-base (lambda ()
3626 (scroll-down anything-scroll-amount
))))
3628 ;; (@* "Utility: Visible Mark")
3629 (defface anything-visible-mark
3630 '((((min-colors 88) (background dark
))
3631 (:background
"green1" :foreground
"black"))
3632 (((background dark
)) (:background
"green" :foreground
"black"))
3633 (((min-colors 88)) (:background
"green1"))
3634 (t (:background
"green")))
3635 "Face for visible mark."
3637 (defvar anything-visible-mark-face
'anything-visible-mark
)
3638 (defvar anything-visible-mark-overlays nil
)
3640 (defun anything-clear-visible-mark ()
3641 (mapc 'delete-overlay anything-visible-mark-overlays
)
3642 (setq anything-visible-mark-overlays nil
))
3643 (add-hook 'anything-after-initialize-hook
'anything-clear-visible-mark
)
3645 ;; (defun anything-toggle-visible-mark ()
3647 ;; (with-anything-window
3648 ;; (anything-aif (loop for o in anything-visible-mark-overlays
3649 ;; when (equal (line-beginning-position) (overlay-start o))
3652 ;; (progn (delete-overlay it)
3653 ;; (delq it anything-visible-mark-overlays))
3654 ;; (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
3655 ;; (overlay-put o 'face anything-visible-mark-face)
3656 ;; (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3657 ;; (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3658 ;; (add-to-list 'anything-visible-mark-overlays o)))))
3660 (defvar anything-c-marked-candidate-list nil
3661 "[OBSOLETE] DO NOT USE!!")
3662 (defvar anything-marked-candidates nil
3663 "Marked candadates. List of (source . real) pair.")
3664 (defun anything-toggle-visible-mark ()
3666 (with-anything-window
3667 (let ((display (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
3668 (source (anything-get-current-source))
3669 (selection (anything-get-selection)))
3670 (anything-aif (loop for o in anything-visible-mark-overlays
3671 when
(equal (line-beginning-position) (overlay-start o
))
3675 (setq anything-c-marked-candidate-list
3677 display anything-c-marked-candidate-list
))
3678 (setq anything-marked-candidates
3680 (cons source selection
)
3681 anything-marked-candidates
))
3683 (setq anything-visible-mark-overlays
(delq it anything-visible-mark-overlays
)))
3684 (let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
3685 (overlay-put o
'face anything-visible-mark-face
)
3686 (overlay-put o
'source
(assoc-default 'name source
))
3687 (overlay-put o
'string
(buffer-substring (overlay-start o
) (overlay-end o
)))
3688 (add-to-list 'anything-visible-mark-overlays o
)
3689 (push display anything-c-marked-candidate-list
)
3690 (push (cons source selection
) anything-marked-candidates
)))
3691 (anything-next-line))))
3693 (defun anything-marked-candidates ()
3694 "Marked candidates (real value) of current source if any,
3695 otherwise 1-element list of current selection.
3697 It is analogous to `dired-get-marked-files'."
3698 (if anything-marked-candidates
3699 (loop with current-src
= (anything-get-current-source)
3700 for
(source . real
) in
(reverse anything-marked-candidates
)
3701 when
(eq current-src source
)
3703 (list (anything-get-selection))))
3705 (defun anything-reset-marked-candidates ()
3706 (setq anything-c-marked-candidate-list nil
)
3707 (setq anything-marked-candidates nil
))
3709 (add-hook 'anything-after-initialize-hook
'anything-reset-marked-candidates
)
3710 (add-hook 'anything-after-action-hook
'anything-reset-marked-candidates
)
3712 (defun anything-revive-visible-mark ()
3714 (with-current-buffer anything-buffer
3715 (loop for o in anything-visible-mark-overlays do
3716 (goto-char (point-min))
3718 (while (and (not moved
)
3719 (search-forward (overlay-get o
'string
) nil t
))
3721 (when (and (save-excursion
3722 (goto-char (anything-get-previous-header-pos))
3723 (equal (overlay-get o
'source
)
3724 (buffer-substring (line-beginning-position) (line-end-position))))
3725 (not (find-if (lambda (x)
3726 (memq x anything-visible-mark-overlays
))
3727 (overlays-at (point)))))
3728 (move-overlay o
(line-beginning-position) (1+ (line-end-position)))
3730 (forward-line 1))))))
3731 (add-hook 'anything-update-hook
'anything-revive-visible-mark
)
3733 (defun anything-next-visible-mark (&optional prev
)
3735 (with-anything-window
3737 (setq anything-visible-mark-overlays
3738 (sort* anything-visible-mark-overlays
3739 '< :key
'overlay-start
))
3740 (let ((i (position-if (lambda (o) (< (point) (overlay-start o
)))
3741 anything-visible-mark-overlays
)))
3743 (unless anything-visible-mark-overlays
(return-from 'exit nil
))
3744 (if (not i
) (setq i
(length anything-visible-mark-overlays
)))
3745 (if (equal (point) (overlay-start (nth (1- i
) anything-visible-mark-overlays
)))
3748 (goto-char (overlay-start (nth (if prev
(1- i
) i
) anything-visible-mark-overlays
)))
3749 (anything-mark-current-line))))))
3751 (defun anything-prev-visible-mark ()
3753 (anything-next-visible-mark t
))
3755 ;; (@* "Utility: `find-file' integration")
3756 (defun anything-quit-and-find-file ()
3757 "Drop into `find-file' from `anything' like `iswitchb-find-file'.
3758 If current selection is a buffer or a file, `find-file' from its directory."
3760 (anything-run-after-quit
3762 (if (file-exists-p f
)
3763 (let ((default-directory (file-name-directory f
)))
3764 (call-interactively 'find-file
))
3765 (call-interactively 'find-file
)))
3766 (anything-aif (get-buffer (anything-get-selection))
3767 (buffer-file-name it
)
3768 (expand-file-name (anything-get-selection)))))
3770 ;; (@* "Utility: Selection Paste")
3771 (defun anything-yank-selection ()
3772 "Set minibuffer contents to current selection."
3774 (delete-minibuffer-contents)
3775 (insert (anything-get-selection nil t
)))
3777 (defun anything-kill-selection-and-quit ()
3778 "Store current selection to kill ring.
3779 You can paste it by typing C-y."
3781 (anything-run-after-quit
3784 (message "Killed: %s" sel
))
3785 (anything-get-selection nil t
)))
3788 ;; (@* "Utility: Automatical execution of persistent-action")
3789 (add-to-list 'minor-mode-alist
'(anything-follow-mode " AFollow"))
3790 (defun anything-follow-mode ()
3791 "If this mode is on, persistent action is executed everytime the cursor is moved."
3793 (with-current-buffer anything-buffer
3794 (setq anything-follow-mode
(not anything-follow-mode
))
3795 (message "anything-follow-mode is %s"
3796 (if anything-follow-mode
"enabled" "disabled"))))
3798 (defun anything-follow-execute-persistent-action-maybe ()
3799 "Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
3800 (and (buffer-local-value 'anything-follow-mode
3801 (get-buffer-create anything-buffer
))
3802 (sit-for anything-input-idle-delay
)
3804 (anything-get-selection)
3806 (anything-execute-persistent-action))))
3808 ;; (@* "Utility: Migrate `anything-sources' to my-anything command")
3809 (defun anything-migrate-sources ()
3810 "Help to migrate to new `anything' way."
3812 (with-current-buffer (get-buffer-create "*anything migrate*")
3815 Setting `anything-sources' directly is not good because
3816 `anything' is not for one command. For now, interactive use of
3817 `anything' (M-x anything) is only for demonstration purpose.
3818 So you should define commands calling `anything'.
3819 I help you to migrate to the new way.
3821 The code below is automatically generated from current
3822 `anything-sources' value. You can use the `my-anything' command
3825 Copy and paste it to your .emacs. Then substitute `my-anything'
3826 for `anything' bindings in all `define-key', `local-set-key' and
3827 `global-set-key' calls.
3829 \(defun my-anything ()
3830 \"Anything command for you.
3832 It is automatically generated by `anything-migrate-sources'.\"
3834 (anything-other-buffer
3837 " anything-sources
))
3838 (eval-last-sexp nil
)
3839 (substitute-key-definition 'anything
'my-anything global-map
)
3840 (pop-to-buffer (current-buffer))))
3842 ;; (@* "Utility: Incremental search within results (unmaintained)")
3844 (defvar anything-isearch-original-global-map nil
3845 "Original global map before Anything isearch is started.")
3847 (defvar anything-isearch-original-message-timeout nil
3848 "Original message timeout before Anything isearch is started.")
3850 (defvar anything-isearch-pattern nil
3851 "The current isearch pattern.")
3853 (defvar anything-isearch-message-suffix
""
3854 "Message suffix indicating the current state of the search.")
3856 (defvar anything-isearch-original-point nil
3857 "Original position of point before isearch is started.")
3859 (defvar anything-isearch-original-window nil
3860 "Original selected window before isearch is started.")
3862 (defvar anything-isearch-original-cursor-in-non-selected-windows nil
3863 "Original value of cursor-in-non-selected-windows before isearch is started.")
3865 (defvar anything-isearch-original-post-command-hook nil
3866 "Original value of post-command-hook before isearch is started.")
3868 (defvar anything-isearch-match-positions nil
3869 "Stack of positions of matches or non-matches.
3871 It's a list of plists with two properties: `event', the last user
3872 event, `start', the start position of the current match, and
3873 `pos', the position of point after that event.
3875 The value of `event' can be the following symbols: `char' if a
3876 character was typed, `error' if a non-matching character was
3877 typed, `search' if a forward search had to be done after a
3878 character, and `search-again' if a search was done for the next
3879 occurrence of the current pattern.")
3881 (defvar anything-isearch-match-start nil
3882 "Start position of the current match.")
3885 (defun anything-isearch ()
3886 "Start incremental search within results. (UNMAINTAINED)"
3888 (if (zerop (buffer-size (get-buffer (anything-buffer-get))))
3889 (message "There are no results.")
3891 (setq anything-isearch-original-message-timeout minibuffer-message-timeout
)
3892 (setq minibuffer-message-timeout nil
)
3894 (setq anything-isearch-original-global-map global-map
)
3898 (setq anything-isearch-original-window
(selected-window))
3899 (select-window (anything-window))
3900 (setq cursor-type t
)
3902 (setq anything-isearch-original-post-command-hook
3903 (default-value 'post-command-hook
))
3904 (setq-default post-command-hook nil
)
3905 (add-hook 'post-command-hook
'anything-isearch-post-command
)
3907 (use-global-map anything-isearch-map
)
3908 (setq overriding-terminal-local-map anything-isearch-map
)
3910 (setq anything-isearch-pattern
"")
3912 (setq anything-isearch-original-cursor-in-non-selected-windows
3913 cursor-in-non-selected-windows
)
3914 (setq cursor-in-non-selected-windows nil
)
3916 (setq anything-isearch-original-point
(point-marker))
3917 (goto-char (point-min))
3919 (anything-mark-current-line)
3921 (setq anything-isearch-match-positions nil
)
3922 (setq anything-isearch-match-start
(point-marker))
3924 (if anything-isearch-overlay
3925 ;; make sure the overlay belongs to the anything buffer
3926 (move-overlay anything-isearch-overlay
(point-min) (point-min)
3927 (get-buffer (anything-buffer-get)))
3929 (setq anything-isearch-overlay
(make-overlay (point-min) (point-min)))
3930 (overlay-put anything-isearch-overlay
'face anything-isearch-match-face
))
3932 (setq anything-isearch-message-suffix
3933 (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))
3935 (error (anything-isearch-cleanup)))))
3938 (defun anything-isearch-post-command ()
3939 "Print the current pattern after every command."
3940 (anything-isearch-message)
3941 (when (anything-window)
3942 (with-anything-window
3943 (move-overlay anything-isearch-overlay anything-isearch-match-start
(point)
3944 (get-buffer (anything-buffer-get))))))
3947 (defun anything-isearch-printing-char ()
3948 "Add printing char to the pattern."
3950 (let ((char (char-to-string last-command-event
)))
3951 (setq anything-isearch-pattern
(concat anything-isearch-pattern char
))
3953 (with-anything-window
3954 (if (looking-at char
)
3956 (push (list 'event
'char
3957 'start anything-isearch-match-start
3958 'pos
(point-marker))
3959 anything-isearch-match-positions
)
3962 (let ((start (point)))
3963 (while (and (re-search-forward anything-isearch-pattern nil t
)
3964 (anything-pos-header-line-p)))
3965 (if (or (anything-pos-header-line-p)
3969 (push (list 'event
'error
3970 'start anything-isearch-match-start
3971 'pos
(point-marker))
3972 anything-isearch-match-positions
))
3974 (push (list 'event
'search
3975 'start anything-isearch-match-start
3976 'pos
(copy-marker start
))
3977 anything-isearch-match-positions
)
3978 (setq anything-isearch-match-start
(copy-marker (match-beginning 0))))))
3980 (anything-mark-current-line))))
3983 (defun anything-isearch-again ()
3984 "Search again for the current pattern"
3986 (if (equal anything-isearch-pattern
"")
3987 (setq anything-isearch-message-suffix
"no pattern yet")
3989 (with-anything-window
3990 (let ((start (point)))
3991 (while (and (re-search-forward anything-isearch-pattern nil t
)
3992 (anything-pos-header-line-p)))
3993 (if (or (anything-pos-header-line-p)
3997 (unless (eq 'error
(plist-get (car anything-isearch-match-positions
)
3999 (setq anything-isearch-message-suffix
"no more matches")))
4001 (push (list 'event
'search-again
4002 'start anything-isearch-match-start
4003 'pos
(copy-marker start
))
4004 anything-isearch-match-positions
)
4005 (setq anything-isearch-match-start
(copy-marker (match-beginning 0)))
4007 (anything-mark-current-line))))))
4010 (defun anything-isearch-delete ()
4013 (unless (equal anything-isearch-pattern
"")
4014 (let ((last (pop anything-isearch-match-positions
)))
4015 (unless (eq 'search-again
(plist-get last
'event
))
4016 (setq anything-isearch-pattern
4017 (substring anything-isearch-pattern
0 -
1)))
4019 (with-anything-window
4020 (goto-char (plist-get last
'pos
))
4021 (setq anything-isearch-match-start
(plist-get last
'start
))
4022 (anything-mark-current-line)))))
4025 (defun anything-isearch-default-action ()
4026 "Execute the default action for the selected candidate."
4028 (anything-isearch-cleanup)
4029 (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))
4032 (defun anything-isearch-select-action ()
4033 "Choose an action for the selected candidate."
4035 (anything-isearch-cleanup)
4036 (with-anything-window
4037 (anything-select-action)))
4040 (defun anything-isearch-cancel ()
4041 "Cancel Anything isearch."
4043 (anything-isearch-cleanup)
4044 (when (anything-window)
4045 (with-anything-window
4046 (goto-char anything-isearch-original-point
)
4047 (anything-mark-current-line))))
4050 (defun anything-isearch-cleanup ()
4051 "Clean up the mess."
4052 (setq minibuffer-message-timeout anything-isearch-original-message-timeout
)
4053 (with-current-buffer (anything-buffer-get)
4054 (setq overriding-terminal-local-map nil
)
4055 (setq cursor-type nil
)
4056 (setq cursor-in-non-selected-windows
4057 anything-isearch-original-cursor-in-non-selected-windows
))
4058 (when anything-isearch-original-window
4059 (select-window anything-isearch-original-window
))
4061 (use-global-map anything-isearch-original-global-map
)
4062 (setq-default post-command-hook anything-isearch-original-post-command-hook
)
4063 (when (overlayp anything-isearch-overlay
)
4064 (delete-overlay anything-isearch-overlay
)))
4067 (defun anything-isearch-message ()
4069 (if (and (equal anything-isearch-message-suffix
"")
4070 (eq (plist-get (car anything-isearch-match-positions
) 'event
)
4072 (setq anything-isearch-message-suffix
"failing"))
4074 (unless (equal anything-isearch-message-suffix
"")
4075 (setq anything-isearch-message-suffix
4076 (concat " [" anything-isearch-message-suffix
"]")))
4078 (message (concat "Search within results: "
4079 anything-isearch-pattern
4080 anything-isearch-message-suffix
))
4082 (setq anything-isearch-message-suffix
""))
4085 ;; (@* "Utility: Iswitchb integration (unmaintained)")
4087 (defvar anything-iswitchb-candidate-selected nil
4088 "Indicates whether an anything candidate is selected from iswitchb.")
4090 (defvar anything-iswitchb-frame-configuration nil
4091 "Saved frame configuration, before anything buffer was displayed.")
4093 (defvar anything-iswitchb-saved-keys nil
4094 "The original in iswitchb before binding anything keys.")
4097 (defun anything-iswitchb-setup ()
4098 "Integrate anything completion into iswitchb (UNMAINTAINED).
4100 If the user is idle for `anything-iswitchb-idle-delay' seconds
4101 after typing something into iswitchb then anything candidates are
4102 shown for the current iswitchb input.
4104 ESC cancels anything completion and returns to normal iswitchb.
4106 Some key bindings in `anything-map' are modified.
4107 See also `anything-iswitchb-setup-keys'."
4112 ;; disable timid completion during iswitchb
4113 (put 'iswitchb-buffer
'timid-completion
'disabled
)
4114 (add-hook 'minibuffer-setup-hook
'anything-iswitchb-minibuffer-setup
)
4116 (defadvice iswitchb-visit-buffer
4117 (around anything-iswitchb-visit-buffer activate
)
4118 (if anything-iswitchb-candidate-selected
4119 (anything-execute-selection-action)
4122 (defadvice iswitchb-possible-new-buffer
4123 (around anything-iswitchb-possible-new-buffer activate
)
4124 (if anything-iswitchb-candidate-selected
4125 (anything-execute-selection-action)
4127 (anything-iswitchb-setup-keys)
4128 (message "Iswitchb integration is activated."))
4130 (defun anything-iswitchb-setup-keys ()
4131 "Modify `anything-map' for anything-iswitchb users.
4133 C-p is used instead of M-p, because anything uses ESC
4134 (currently hardcoded) for `anything-iswitchb-cancel-anything' and
4135 Emacs handles ESC and Meta as synonyms, so ESC overrides
4136 other commands with Meta prefix.
4138 Note that iswitchb uses M-p and M-n by default for history
4139 navigation, so you should bind C-p and C-n in
4140 `iswitchb-mode-map' if you use the history keys and don't want
4141 to use different keys for iswitchb while anything is not yet
4142 kicked in. These keys are not bound automatically by anything
4143 in `iswitchb-mode-map' because they (C-n at least) already have
4144 a standard iswitchb binding which you might be accustomed to.
4146 Binding M-s is used instead of C-s, because C-s has a binding in
4147 iswitchb. You can rebind it AFTER `anything-iswitchb-setup'.
4149 Unbind C-r to prevent problems during anything-isearch."
4150 (define-key anything-map
(kbd "C-s") nil
)
4151 (define-key anything-map
(kbd "M-p") nil
)
4152 (define-key anything-map
(kbd "M-n") nil
)
4153 (define-key anything-map
(kbd "M-v") nil
)
4154 (define-key anything-map
(kbd "C-v") nil
)
4155 (define-key anything-map
(kbd "C-p") 'anything-previous-history-element
)
4156 (define-key anything-map
(kbd "C-n") 'anything-next-history-element
)
4157 (define-key anything-map
(kbd "M-s") nil
)
4158 (define-key anything-map
(kbd "M-s") 'anything-isearch
)
4159 (define-key anything-map
(kbd "C-r") nil
))
4161 (defun anything-iswitchb-minibuffer-setup ()
4162 (when (eq this-command
'iswitchb-buffer
)
4163 (add-hook 'minibuffer-exit-hook
'anything-iswitchb-minibuffer-exit
)
4165 (setq anything-iswitchb-frame-configuration nil
)
4166 (setq anything-iswitchb-candidate-selected nil
)
4167 (add-hook 'anything-update-hook
'anything-iswitchb-handle-update
)
4169 (anything-initialize)
4171 (add-hook 'post-command-hook
'anything-iswitchb-check-input
)))
4174 (defun anything-iswitchb-minibuffer-exit ()
4175 (remove-hook 'minibuffer-exit-hook
'anything-iswitchb-minibuffer-exit
)
4176 (remove-hook 'post-command-hook
'anything-iswitchb-check-input
)
4177 (remove-hook 'anything-update-hook
'anything-iswitchb-handle-update
)
4181 (when anything-iswitchb-frame-configuration
4182 (anything-set-frame/window-configuration anything-iswitchb-frame-configuration
)
4183 (setq anything-iswitchb-frame-configuration nil
)))
4186 (defun anything-iswitchb-check-input ()
4187 "Extract iswitchb input and check if it needs to be handled."
4188 (declare (special iswitchb-text
))
4189 (if (or anything-iswitchb-frame-configuration
4190 (sit-for anything-iswitchb-idle-delay
))
4191 (anything-check-new-input iswitchb-text
)))
4194 (defun anything-iswitchb-handle-update ()
4195 "Pop up the anything buffer if it's not empty and it's not
4196 shown yet and bind anything commands in iswitchb."
4197 (unless (or (equal (buffer-size (get-buffer anything-buffer
)) 0)
4198 anything-iswitchb-frame-configuration
)
4199 (setq anything-iswitchb-frame-configuration
(anything-current-frame/window-configuration
))
4201 (save-selected-window
4202 (if (not anything-samewindow
)
4203 (pop-to-buffer anything-buffer
)
4205 (select-window (get-lru-window))
4206 (switch-to-buffer anything-buffer
)))
4208 (with-current-buffer (window-buffer (active-minibuffer-window))
4209 (let* ((anything-prefix "anything-")
4210 (prefix-length (length anything-prefix
))
4216 (let ((command (cdr binding
)))
4217 (when (and (symbolp command
)
4218 (eq (compare-strings
4221 (symbol-name command
)
4225 (cdr anything-map
)))))
4226 (bindings (mapcar (lambda (command)
4228 (where-is-internal command anything-map
)))
4231 (push (list 'anything-iswitchb-cancel-anything
(kbd "<ESC>"))
4234 (setq anything-iswitchb-saved-keys nil
)
4236 (let* ((iswitchb-prefix "iswitchb-")
4237 (prefix-length (length iswitchb-prefix
)))
4238 (dolist (binding bindings
)
4239 (dolist (key (cdr binding
))
4240 (let ((old-command (lookup-key (current-local-map) key
)))
4241 (unless (and anything-iswitchb-dont-touch-iswithcb-keys
4242 (symbolp old-command
)
4243 (eq (compare-strings iswitchb-prefix
4245 (symbol-name old-command
)
4248 (push (cons key old-command
)
4249 anything-iswitchb-saved-keys
)
4250 (define-key (current-local-map) key
(car binding
)))))))))))
4253 (defun anything-iswitchb-cancel-anything ()
4254 "Cancel anything completion and return to standard iswitchb."
4257 (dolist (binding anything-iswitchb-saved-keys
)
4258 (define-key (current-local-map) (car binding
) (cdr binding
)))
4259 (anything-iswitchb-minibuffer-exit)))
4261 ;; (@* "Compatibility")
4263 ;; Copied assoc-default from XEmacs version 21.5.12
4264 (unless (fboundp 'assoc-default
)
4265 (defun assoc-default (key alist
&optional test default
)
4266 "Find object KEY in a pseudo-alist ALIST.
4267 ALIST is a list of conses or objects. Each element (or the element's car,
4268 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
4269 If that is non-nil, the element matches;
4270 then `assoc-default' returns the element's cdr, if it is a cons,
4271 or DEFAULT if the element is not a cons.
4273 If no element matches, the value is nil.
4274 If TEST is omitted or nil, `equal' is used."
4275 (let (found (tail alist
) value
)
4276 (while (and tail
(not found
))
4277 (let ((elt (car tail
)))
4278 (when (funcall (or test
'equal
) (if (consp elt
) (car elt
) elt
) key
)
4279 (setq found t value
(if (consp elt
) (cdr elt
) default
))))
4280 (setq tail
(cdr tail
)))
4283 ;; Function not available in XEmacs,
4284 (unless (fboundp 'minibuffer-contents
)
4285 (defun minibuffer-contents ()
4286 "Return the user input in a minbuffer as a string.
4287 The current buffer must be a minibuffer."
4288 (field-string (point-max)))
4290 (defun delete-minibuffer-contents ()
4291 "Delete all user input in a minibuffer.
4292 The current buffer must be a minibuffer."
4293 (delete-field (point-max))))
4295 ;; Function not available in older Emacs (<= 22.1).
4296 (unless (fboundp 'buffer-chars-modified-tick
)
4297 (defun buffer-chars-modified-tick (&optional buffer
)
4298 "Return BUFFER's character-change tick counter.
4299 Each buffer has a character-change tick counter, which is set to the
4300 value of the buffer's tick counter (see `buffer-modified-tick'), each
4301 time text in that buffer is inserted or deleted. By comparing the
4302 values returned by two individual calls of `buffer-chars-modified-tick',
4303 you can tell whether a character change occurred in that buffer in
4304 between these calls. No argument or nil as argument means use current
4306 (with-current-buffer (or buffer
(current-buffer))
4307 (if (listp buffer-undo-list
)
4308 (length buffer-undo-list
)
4309 (buffer-modified-tick)))))
4311 ;;(@* "Attribute Documentation")
4312 (defun anything-describe-anything-attribute (anything-attribute)
4313 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol)."
4314 (interactive (list (intern
4316 "Describe anything attribute: "
4317 (mapcar 'symbol-name anything-additional-attributes
)))))
4318 (with-output-to-temp-buffer "*Help*"
4319 (princ (get anything-attribute
'anything-attrdoc
))))
4321 (anything-document-attribute 'name
"mandatory"
4322 " The name of the source. It is also the heading which appears
4323 above the list of matches from the source. Must be unique. ")
4324 (anything-document-attribute 'header-name
"optional"
4325 " A function returning the display string of the header. Its
4326 argument is the name of the source. This attribute is useful to
4327 add an additional information with the source name. ")
4328 (anything-document-attribute 'candidates
"mandatory if candidates-in-buffer attribute is not provided"
4329 " Specifies how to retrieve candidates from the source. It can
4330 either be a variable name, a function called with no parameters
4331 or the actual list of candidates.
4333 The list must be a list whose members are strings, symbols
4334 or (DISPLAY . REAL) pairs.
4336 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
4337 in the Anything buffer, but the REAL one is used as action
4338 argument when the candidate is selected. This allows a more
4339 readable presentation for candidates which would otherwise be,
4340 for example, too long or have a common part shared with other
4341 candidates which can be safely replaced with an abbreviated
4342 string for display purposes.
4344 Note that if the (DISPLAY . REAL) form is used then pattern
4345 matching is done on the displayed string, not on the real
4348 If the candidates have to be retrieved asynchronously (for
4349 example, by an external command which takes a while to run)
4350 then the function should start the external command
4351 asynchronously and return the associated process object.
4352 Anything will take care of managing the process (receiving the
4353 output from it, killing it if necessary, etc.). The process
4354 should return candidates matching the current pattern (see
4355 variable `anything-pattern'.)
4357 Note that currently results from asynchronous sources appear
4358 last in the anything buffer regardless of their position in
4359 `anything-sources'. ")
4360 (anything-document-attribute 'action
"mandatory if type attribute is not provided"
4361 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
4362 FUNCTION is called with one parameter: the selected candidate.
4364 An action other than the default can be chosen from this list
4365 of actions for the currently selected candidate (by default
4366 with TAB). The DISPLAY string is shown in the completions
4367 buffer and the FUNCTION is invoked when an action is
4368 selected. The first action of the list is the default. ")
4369 (anything-document-attribute 'type
"optional if action attribute is provided"
4370 " Indicates the type of the items the source returns.
4372 Merge attributes not specified in the source itself from
4373 `anything-type-attributes'.
4375 This attribute is implemented by plug-in. ")
4376 (anything-document-attribute 'init
"optional"
4377 " Function called with no parameters when anything is started. It
4378 is useful for collecting current state information which can be
4379 used to create the list of candidates later.
4381 For example, if a source needs to work with the current
4382 directory then it can store its value here, because later
4383 anything does its job in the minibuffer and in the
4384 `anything-buffer' and the current directory can be different
4386 (anything-document-attribute 'delayed-init
"optional"
4387 " Function called with no parameters before candidate function is
4388 called. It is similar with `init' attribute, but its
4389 evaluation is deferred. It is useful to combine with ")
4390 (anything-document-attribute 'match
"optional"
4391 " List of functions called with one parameter: a candidate. The
4392 function should return non-nil if the candidate matches the
4393 current pattern (see variable `anything-pattern').
4395 This attribute allows the source to override the default
4396 pattern matching based on `string-match'. It can be used, for
4397 example, to implement a source for file names and do the
4398 pattern matching on the basename of files, since it's more
4399 likely one is typing part of the basename when searching for a
4400 file, instead of some string anywhere else in its path.
4402 If the list contains more than one function then the list of
4403 matching candidates from the source is constructed by appending
4404 the results after invoking the first function on all the
4405 potential candidates, then the next function, and so on. The
4406 matching candidates supplied by the first function appear first
4407 in the list of results and then results from the other
4408 functions, respectively.
4410 This attribute has no effect for asynchronous sources (see
4411 attribute `candidates'), since they perform pattern matching
4413 (anything-document-attribute 'candidate-transformer
"optional"
4414 " It's a function or a list of functions called with one argument
4415 when the completion list from the source is built. The argument
4416 is the list of candidates retrieved from the source. The
4417 function should return a transformed list of candidates which
4418 will be used for the actual completion. If it is a list of
4419 functions, it calls each function sequentially.
4421 This can be used to transform or remove items from the list of
4424 Note that `candidates' is run already, so the given transformer
4425 function should also be able to handle candidates with (DISPLAY
4427 (anything-document-attribute 'filtered-candidate-transformer
"optional"
4428 " It has the same format as `candidate-transformer', except the
4429 function is called with two parameters: the candidate list and
4432 This transformer is run on the candidate list which is already
4433 filtered by the current pattern. While `candidate-transformer'
4434 is run only once, it is run every time the input pattern is
4437 It can be used to transform the candidate list dynamically, for
4438 example, based on the current pattern.
4440 In some cases it may also be more efficent to perform candidate
4441 transformation here, instead of with `candidate-transformer'
4442 even if this transformation is done every time the pattern is
4443 changed. For example, if a candidate set is very large then
4444 `candidate-transformer' transforms every candidate while only
4445 some of them will actually be dislpayed due to the limit
4446 imposed by `anything-candidate-number-limit'.
4448 Note that `candidates' and `candidate-transformer' is run
4449 already, so the given transformer function should also be able
4450 to handle candidates with (DISPLAY . REAL) format.
4452 This option has no effect for asynchronous sources. (Not yet,
4454 (anything-document-attribute 'action-transformer
"optional"
4455 " It's a function or a list of functions called with two
4456 arguments when the action list from the source is
4457 assembled. The first argument is the list of actions, the
4458 second is the current selection. If it is a list of functions,
4459 it calls each function sequentially.
4461 The function should return a transformed action list.
4463 This can be used to customize the list of actions based on the
4464 currently selected candidate. ")
4465 (anything-document-attribute 'pattern-transformer
"optional"
4466 " It's a function or a list of functions called with one argument
4467 before computing matches. Its argument is `anything-pattern'.
4468 Functions should return transformed `anything-pattern'.
4470 It is useful to change interpretation of `anything-pattern'. ")
4471 (anything-document-attribute 'delayed
"optional"
4472 " Candidates from the source are shown only if the user stops
4473 typing and is idle for `anything-idle-delay' seconds. ")
4474 (anything-document-attribute 'volatile
"optional"
4475 " Indicates the source assembles the candidate list dynamically,
4476 so it shouldn't be cached within a single Anything
4477 invocation. It is only applicable to synchronous sources,
4478 because asynchronous sources are not cached. ")
4479 (anything-document-attribute 'requires-pattern
"optional"
4480 " If present matches from the source are shown only if the
4481 pattern is not empty. Optionally, it can have an integer
4482 parameter specifying the required length of input which is
4483 useful in case of sources with lots of candidates. ")
4484 (anything-document-attribute 'persistent-action
"optional"
4485 " Function called with one parameter; the selected candidate.
4487 An action performed by `anything-execute-persistent-action'.
4488 If none, use the default action. ")
4489 (anything-document-attribute 'candidates-in-buffer
"optional"
4490 " Shortcut attribute for making and narrowing candidates using
4491 buffers. This newly-introduced attribute prevents us from
4492 forgetting to add volatile and match attributes.
4494 See docstring of `anything-candidates-in-buffer'.
4496 (candidates-in-buffer) is equivalent of three attributes:
4497 (candidates . anything-candidates-in-buffer)
4501 (candidates-in-buffer . candidates-function) is equivalent of:
4502 (candidates . candidates-function)
4506 This attribute is implemented by plug-in. ")
4507 (anything-document-attribute 'search
"optional"
4508 " List of functions like `re-search-forward' or `search-forward'.
4509 Buffer search function used by `anything-candidates-in-buffer'.
4510 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4511 This attribute is meant to be used with
4512 (candidates . anything-candidates-in-buffer) or
4513 (candidates-in-buffer) in short. ")
4514 (anything-document-attribute 'search-from-end
"optional"
4515 " Make `anything-candidates-in-buffer' search from the end of buffer.
4516 If this attribute is specified, `anything-candidates-in-buffer' uses
4517 `re-search-backward' instead. ")
4518 (anything-document-attribute 'get-line
"optional"
4519 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4520 This function converts point of line-beginning and point of line-end,
4521 which represents a candidate computed by `anything-candidates-in-buffer'.
4522 By default, `anything-candidates-in-buffer' uses
4523 `buffer-substring-no-properties'. ")
4524 (anything-document-attribute 'display-to-real
"optional"
4525 " Function called with one parameter; the selected candidate.
4527 The function transforms the selected candidate, and the result
4528 is passed to the action function. The display-to-real
4529 attribute provides another way to pass other string than one
4530 shown in Anything buffer.
4532 Traditionally, it is possible to make candidates,
4533 candidate-transformer or filtered-candidate-transformer
4534 function return a list with (DISPLAY . REAL) pairs. But if REAL
4535 can be generated from DISPLAY, display-to-real is more
4536 convenient and faster. ")
4537 (anything-document-attribute 'real-to-display
"optional"
4538 " Function called with one parameter; the selected candidate.
4540 The inverse of display-to-real attribute.
4542 The function transforms the selected candidate, which is passed
4543 to the action function, for display. The real-to-display
4544 attribute provides the other way to pass other string than one
4545 shown in Anything buffer.
4547 Traditionally, it is possible to make candidates,
4548 candidate-transformer or filtered-candidate-transformer
4549 function return a list with (DISPLAY . REAL) pairs. But if
4550 DISPLAY can be generated from REAL, real-to-display is more
4553 Note that DISPLAY parts returned from candidates /
4554 candidate-transformer are IGNORED as the name `display-to-real'
4556 (anything-document-attribute 'cleanup
"optional"
4557 " Function called with no parameters when *anything* buffer is closed. It
4558 is useful for killing unneeded candidates buffer.
4560 Note that the function is executed BEFORE performing action. ")
4561 (anything-document-attribute 'candidate-number-limit
"optional"
4562 " Override `anything-candidate-number-limit' only for this source. ")
4563 (anything-document-attribute 'accept-empty
"optional"
4564 " Pass empty string \"\" to action function. ")
4565 (anything-document-attribute 'disable-shortcuts
"optional"
4566 " Disable `anything-enable-shortcuts' in current `anything' session.
4568 This attribute is implemented by plug-in. ")
4569 (anything-document-attribute 'dummy
"optional"
4570 " Set `anything-pattern' to candidate. If this attribute is
4571 specified, The candidates attribute is ignored.
4573 This attribute is implemented by plug-in.
4574 This plug-in implies disable-shortcuts plug-in. ")
4575 (anything-document-attribute 'multiline
"optional"
4576 " Enable to selection multiline candidates. ")
4577 (anything-document-attribute 'update
"optional"
4578 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4579 (anything-document-attribute 'mode-line
"optional"
4580 " source local `anything-mode-line-string'. (included in `mode-line-format')
4581 It accepts also variable/function name. ")
4582 (anything-document-attribute 'header-line
"optional"
4583 " source local `header-line-format'.
4584 It accepts also variable/function name. ")
4585 (anything-document-attribute 'resume
"optional" " Function called with no parameters when `anything-resume' is started.")
4587 ;; (@* "Unit Tests")
4589 (defun* anything-test-candidates
(sources &optional
(input "") (compile-source-functions anything-compile-source-functions-default
))
4590 "Test helper function for anything.
4591 Given pseudo `anything-sources' and `anything-pattern', returns list like
4592 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4593 (\"source name2\" (\"candidate3\" \"candidate4\")))
4595 (let ((anything-test-mode t
)
4596 anything-enable-shortcuts
4597 anything-candidate-cache
4598 (anything-sources (anything-normalize-sources sources
))
4599 (anything-compile-source-functions compile-source-functions
)
4600 anything-before-initialize-hook
4601 anything-after-initialize-hook
4602 anything-update-hook
4603 anything-test-candidate-list
)
4604 (get-buffer-create anything-buffer
)
4606 (anything-initialize)
4607 (setq anything-input input anything-pattern input
)
4609 ;; test-mode spec: select 1st candidate!
4610 (with-current-buffer anything-buffer
4612 (anything-mark-current-line))
4614 anything-test-candidate-list
4615 (anything-cleanup))))
4617 (defmacro anything-test-update
(sources pattern
)
4618 "Test helper macro for anything. It is meant for testing *anything* buffer contents."
4619 `(progn (stub anything-get-sources
=> ,sources
)
4620 (stub run-hooks
=> nil
)
4621 (stub anything-maybe-fit-frame
=> nil
)
4622 (stub run-with-idle-timer
=> nil
)
4623 (let (anything-test-mode (anything-pattern ,pattern
))
4624 (anything-update))))
4627 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4628 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
4630 (when (fboundp 'expectations
)
4632 (desc "anything-current-buffer")
4633 (expect "__a_buffer"
4634 (with-current-buffer (get-buffer-create "__a_buffer")
4635 (anything-test-candidates '(((name .
"FOO"))) "")
4637 (buffer-name anything-current-buffer
)
4638 (kill-buffer "__a_buffer")
4640 (desc "anything-buffer-file-name")
4641 (expect (regexp "/__a_file__")
4642 (with-current-buffer (get-buffer-create "__a_file__")
4643 (setq buffer-file-name
"/__a_file__")
4644 (anything-test-candidates '(((name .
"FOO"))) "")
4646 anything-buffer-file-name
4647 ;;(kill-buffer "__a_file__")
4649 (desc "anything-interpret-value")
4651 (anything-interpret-value "literal"))
4653 (anything-interpret-value (lambda () "lambda")))
4654 (expect "lambda with source name"
4655 (let ((source '((name .
"lambda with source name"))))
4656 (anything-interpret-value (lambda () anything-source-name
) source
)))
4657 (expect "function symbol"
4658 (flet ((f () "function symbol"))
4659 (anything-interpret-value 'f
)))
4660 (expect "variable symbol"
4661 (let ((v "variable symbol"))
4662 (anything-interpret-value 'v
)))
4663 (expect (error error
*)
4664 (anything-interpret-value 'unbounded-1
))
4665 (desc "anything-compile-sources")
4666 (expect '(((name .
"foo")))
4667 (anything-compile-sources '(((name .
"foo"))) nil
)
4669 (expect '(((name .
"foo") (type . test
) (action . identity
)))
4670 (let ((anything-type-attributes '((test (action . identity
)))))
4671 (anything-compile-sources '(((name .
"foo") (type . test
)))
4672 '(anything-compile-source--type))))
4673 (desc "anything-sources accepts symbols")
4674 (expect '(((name .
"foo")))
4675 (let* ((foo '((name .
"foo"))))
4676 (anything-compile-sources '(foo) nil
)))
4677 (desc "anything-get-sources action")
4678 (expect '(((name .
"Actions") (candidates . actions
)))
4679 (stub anything-action-window
=> t
)
4680 (let (anything-compiled-sources
4681 (anything-sources '(((name .
"Actions") (candidates . actions
)))))
4682 (anything-get-sources)))
4683 (desc "get-buffer-create candidates-buffer")
4684 (expect '(((name .
"many") (init . many-init
)
4685 (candidates-in-buffer . anything-candidates-in-buffer
)
4686 (candidates . anything-candidates-in-buffer
)
4687 (volatile) (match identity
)))
4688 (anything-compile-sources
4689 '(((name .
"many") (init . many-init
)
4690 (candidates-in-buffer . anything-candidates-in-buffer
)))
4691 '(anything-compile-source--candidates-in-buffer)))
4692 (expect '(((name .
"many") (init . many-init
)
4693 (candidates-in-buffer)
4694 (candidates . anything-candidates-in-buffer
)
4695 (volatile) (match identity
)))
4696 (anything-compile-sources
4697 '(((name .
"many") (init . many-init
)
4698 (candidates-in-buffer)))
4699 '(anything-compile-source--candidates-in-buffer)))
4700 (expect '(((name .
"many") (init . many-init
)
4701 (candidates-in-buffer)
4704 (candidates . anything-candidates-in-buffer
)
4705 (volatile) (match identity
)))
4706 (let ((anything-type-attributes '((test (action . identity
)))))
4707 (anything-compile-sources
4708 '(((name .
"many") (init . many-init
)
4709 (candidates-in-buffer)
4711 '(anything-compile-source--type
4712 anything-compile-source--candidates-in-buffer
))))
4714 (desc "anything-get-candidates")
4715 (expect '("foo" "bar")
4716 (anything-get-candidates '((name .
"foo") (candidates "foo" "bar"))))
4717 (expect '("FOO" "BAR")
4718 (anything-get-candidates '((name .
"foo") (candidates "foo" "bar")
4719 (candidate-transformer
4720 .
(lambda (cands) (mapcar 'upcase cands
))))))
4721 (expect '("foo" "bar")
4722 (anything-get-candidates '((name .
"foo")
4723 (candidates .
(lambda () '("foo" "bar"))))))
4724 (expect '("foo" "bar")
4725 (let ((var '("foo" "bar")))
4726 (anything-get-candidates '((name .
"foo")
4727 (candidates . var
)))))
4728 (expect (error error
*)
4729 (anything-get-candidates '((name .
"foo")
4730 (candidates .
"err"))))
4731 (expect (error error
*)
4733 (anything-get-candidates '((name .
"foo")
4734 (candidates . var
)))))
4735 (desc "anything-compute-matches")
4736 (expect '("foo" "bar")
4737 (let ((anything-pattern ""))
4738 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
4740 (let ((anything-pattern "oo"))
4741 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
4743 (let ((anything-pattern "^b"))
4744 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
4746 (let ((anything-pattern "")
4747 (anything-candidate-number-limit 2))
4748 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
4750 (let ((anything-pattern ".")
4751 (anything-candidate-number-limit 2))
4752 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
4753 (expect '("a" "b" "c")
4754 (let ((anything-pattern "")
4755 anything-candidate-number-limit
)
4756 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
4757 (expect '("a" "b" "c")
4758 (let ((anything-pattern "[abc]")
4759 anything-candidate-number-limit
)
4760 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
4761 ;; using anything-test-candidate-list
4762 (desc "anything-test-candidates")
4763 (expect '(("FOO" ("foo" "bar")))
4764 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")))))
4765 (expect '(("FOO" ("bar")))
4766 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar"))) "ar"))
4767 (expect '(("T1" ("hoge" "aiue"))
4768 ("T2" ("test" "boke")))
4769 (anything-test-candidates '(((name .
"T1") (candidates "hoge" "aiue"))
4770 ((name .
"T2") (candidates "test" "boke")))))
4771 (expect '(("T1" ("hoge"))
4773 (anything-test-candidates '(((name .
"T1") (candidates "hoge" "aiue"))
4774 ((name .
"T2") (candidates "test" "boke"))) "o"))
4775 (desc "requires-pattern attribute")
4777 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
4778 (requires-pattern .
1)))))
4779 (expect '(("FOO" ("bar")))
4780 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
4781 (requires-pattern .
1))) "b"))
4782 (desc "delayed attribute(for test)")
4783 (expect '(("T2" ("boke"))
4785 (anything-test-candidates
4786 '(((name .
"T1") (candidates "hoge" "aiue") (delayed))
4787 ((name .
"T2") (candidates "test" "boke")))
4789 (desc "match attribute(prefix search)")
4790 (expect '(("FOO" ("bar")))
4791 (anything-test-candidates
4792 '(((name .
"FOO") (candidates "foo" "bar")
4793 (match (lambda (c) (string-match (concat "^" anything-pattern
) c
)))))
4796 (anything-test-candidates
4797 '(((name .
"FOO") (candidates "foo" "bar")
4798 (match (lambda (c) (string-match (concat "^" anything-pattern
) c
)))))
4800 (expect "TestSource"
4802 (anything-test-candidates
4803 '(((name .
"TestSource") (candidates "a")
4804 (match (lambda (c) (setq x anything-source-name
)))))
4807 (desc "init attribute")
4808 (expect '(("FOO" ("bar")))
4810 (anything-test-candidates
4811 '(((name .
"FOO") (init .
(lambda () (setq v
'("foo" "bar"))))
4814 (desc "candidate-transformer attribute")
4815 (expect '(("FOO" ("BAR")))
4816 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
4817 (candidate-transformer
4818 .
(lambda (cands) (mapcar 'upcase cands
)))))
4820 (desc "filtered-candidate-transformer attribute")
4822 (expect '(("FOO" ("BAR")))
4823 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
4824 (filtered-candidate-transformer
4825 .
(lambda (cands src
) (mapcar 'upcase cands
)))))
4827 (desc "anything-candidates-in-buffer-1")
4829 (anything-candidates-in-buffer-1 nil
))
4830 (expect '("foo+" "bar+" "baz+")
4832 (insert "foo+\nbar+\nbaz+\n")
4833 (let ((anything-candidate-number-limit 5))
4834 (anything-candidates-in-buffer-1 (current-buffer) ""))))
4835 (expect '("foo+" "bar+")
4837 (insert "foo+\nbar+\nbaz+\n")
4838 (let ((anything-candidate-number-limit 2))
4839 (anything-candidates-in-buffer-1 (current-buffer) ""))))
4842 (insert "foo+\nbar+\nbaz+\n")
4843 (anything-candidates-in-buffer-1 (current-buffer) "oo\\+")))
4846 (insert "foo+\nbar+\nbaz+\n")
4847 (anything-candidates-in-buffer-1
4848 (current-buffer) "oo+"
4849 #'buffer-substring-no-properties
'(search-forward))))
4850 (expect '(("foo+" "FOO+"))
4852 (insert "foo+\nbar+\nbaz+\n")
4853 (anything-candidates-in-buffer-1
4854 (current-buffer) "oo\\+"
4856 (let ((l (buffer-substring-no-properties s e
)))
4857 (list l
(upcase l
)))))))
4858 (desc "anything-candidates-in-buffer")
4859 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4860 (anything-test-candidates
4863 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4864 (insert "foo+\nbar+\nbaz+\n"))))
4865 (candidates . anything-candidates-in-buffer
)
4868 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4869 (let (anything-candidate-number-limit)
4870 (anything-test-candidates
4873 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4874 (insert "foo+\nbar+\nbaz+\n"))))
4875 (candidates . anything-candidates-in-buffer
)
4878 (expect '(("TEST" ("foo+")))
4879 (anything-test-candidates
4882 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4883 (insert "foo+\nbar+\nbaz+\n"))))
4884 (candidates . anything-candidates-in-buffer
)
4888 (desc "search attribute")
4889 (expect '(("TEST" ("foo+")))
4890 (anything-test-candidates
4893 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4894 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4895 (search search-forward
)
4896 (candidates . anything-candidates-in-buffer
)
4900 (expect '(("TEST" ("foo+" "ooo")))
4901 (anything-test-candidates
4904 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4905 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4906 (search search-forward re-search-forward
)
4907 (candidates . anything-candidates-in-buffer
)
4911 (expect '(("TEST" ("foo+" "ooo")))
4912 (anything-test-candidates
4915 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4916 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4917 (search re-search-forward search-forward
)
4918 (candidates . anything-candidates-in-buffer
)
4922 (expect '(("TEST" ("ooo" "foo+")))
4923 (anything-test-candidates
4926 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4927 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4928 (search re-search-forward search-forward
)
4929 (candidates . anything-candidates-in-buffer
)
4933 ;; faster exact match
4934 (expect '(("TEST" ("bar+")))
4935 (anything-test-candidates
4938 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4939 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4940 (search (lambda (pattern &rest _
)
4941 (and (search-forward (concat "\n" pattern
"\n") nil t
)
4942 (forward-line -
1))))
4943 (candidates . anything-candidates-in-buffer
)
4947 ;; faster prefix match
4948 (expect '(("TEST" ("bar+")))
4949 (anything-test-candidates
4952 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4953 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4954 (search (lambda (pattern &rest _
)
4955 (search-forward (concat "\n" pattern
) nil t
)))
4956 (candidates . anything-candidates-in-buffer
)
4960 (desc "anything-current-buffer-is-modified")
4961 (expect '(("FOO" ("modified")))
4962 (let ((sources '(((name .
"FOO")
4965 (if (anything-current-buffer-is-modified)
4967 '("unmodified"))))))))
4969 (clrhash anything-tick-hash
)
4971 (anything-test-candidates sources
))))
4972 (expect '(("FOO" ("unmodified")))
4973 (let ((sources '(((name .
"FOO")
4976 (if (anything-current-buffer-is-modified)
4978 '("unmodified"))))))))
4980 (clrhash anything-tick-hash
)
4982 (anything-test-candidates sources
)
4983 (anything-test-candidates sources
))))
4984 (expect '(("FOO" ("modified")))
4985 (let ((sources '(((name .
"FOO")
4988 (if (anything-current-buffer-is-modified)
4990 '("unmodified"))))))))
4992 (clrhash anything-tick-hash
)
4994 (anything-test-candidates sources
)
4996 (anything-test-candidates sources
))))
4997 (expect '(("BAR" ("modified")))
4998 (let ((sources1 '(((name .
"FOO")
5001 (if (anything-current-buffer-is-modified)
5003 '("unmodified")))))))
5004 (sources2 '(((name .
"BAR")
5007 (if (anything-current-buffer-is-modified)
5009 '("unmodified"))))))))
5011 (clrhash anything-tick-hash
)
5013 (anything-test-candidates sources1
)
5014 (anything-test-candidates sources2
))))
5015 (expect '(("FOO" ("unmodified")))
5016 (let ((sources1 '(((name .
"FOO")
5019 (if (anything-current-buffer-is-modified)
5021 '("unmodified")))))))
5022 (sources2 '(((name .
"BAR")
5025 (if (anything-current-buffer-is-modified)
5027 '("unmodified"))))))))
5029 (clrhash anything-tick-hash
)
5031 (anything-test-candidates sources1
)
5032 (anything-test-candidates sources2
)
5033 (anything-test-candidates sources1
))))
5034 (expect '(("BAR" ("unmodified")))
5035 (let ((sources1 '(((name .
"FOO")
5038 (if (anything-current-buffer-is-modified)
5040 '("unmodified")))))))
5041 (sources2 '(((name .
"BAR")
5044 (if (anything-current-buffer-is-modified)
5046 '("unmodified"))))))))
5048 (clrhash anything-tick-hash
)
5050 (anything-test-candidates sources1
)
5051 (anything-test-candidates sources2
)
5052 (anything-test-candidates sources2
))))
5053 (expect '(("BAR" ("modified")))
5054 (let ((sources1 '(((name .
"FOO")
5057 (if (anything-current-buffer-is-modified)
5059 '("unmodified")))))))
5060 (sources2 '(((name .
"BAR")
5063 (if (anything-current-buffer-is-modified)
5065 '("unmodified"))))))))
5067 (clrhash anything-tick-hash
)
5069 (anything-test-candidates sources1
)
5070 (anything-test-candidates sources2
)
5072 (anything-test-candidates sources2
)))))
5073 (desc "anything-source-name")
5076 (anything-test-candidates '(((name .
"FOO")
5078 .
(lambda () (setq v anything-source-name
)))
5079 (candidates "ok"))))
5083 (anything-test-candidates '(((name .
"FOO")
5086 (setq v anything-source-name
)
5091 (anything-test-candidates '(((name .
"FOO")
5093 (candidate-transformer
5095 (setq v anything-source-name
)
5100 (anything-test-candidates '(((name .
"FOO")
5102 (filtered-candidate-transformer
5104 (setq v anything-source-name
)
5109 (anything-test-candidates '(((name .
"FOO")
5113 (setq v anything-source-name
)
5115 (action . identity
))))
5116 (anything-execute-selection-action)
5118 (desc "anything-candidate-buffer create")
5119 (expect " *anything candidates:FOO*"
5120 (let* (anything-candidate-buffer-alist
5121 (anything-source-name "FOO")
5122 (buf (anything-candidate-buffer 'global
)))
5123 (prog1 (buffer-name buf
)
5124 (kill-buffer buf
))))
5125 (expect " *anything candidates:FOO*aTestBuffer"
5126 (let* (anything-candidate-buffer-alist
5127 (anything-source-name "FOO")
5128 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5129 (buf (anything-candidate-buffer 'local
)))
5130 (prog1 (buffer-name buf
)
5131 (kill-buffer anything-current-buffer
)
5132 (kill-buffer buf
))))
5134 (let (anything-candidate-buffer-alist
5135 (anything-source-name "FOO") buf
)
5136 (with-current-buffer (anything-candidate-buffer 'global
)
5138 (setq buf
(anything-candidate-buffer 'global
))
5139 (prog1 (buffer-size buf
)
5140 (kill-buffer buf
))))
5141 (desc "anything-candidate-buffer get-buffer")
5142 (expect " *anything candidates:FOO*"
5143 (let* (anything-candidate-buffer-alist
5144 (anything-source-name "FOO")
5145 (buf (anything-candidate-buffer 'global
)))
5146 (prog1 (buffer-name (anything-candidate-buffer))
5147 (kill-buffer buf
))))
5148 (expect " *anything candidates:FOO*aTestBuffer"
5149 (let* (anything-candidate-buffer-alist
5150 (anything-source-name "FOO")
5151 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5152 (buf (anything-candidate-buffer 'local
)))
5153 (prog1 (buffer-name (anything-candidate-buffer))
5154 (kill-buffer anything-current-buffer
)
5155 (kill-buffer buf
))))
5156 (expect " *anything candidates:FOO*"
5157 (let* (anything-candidate-buffer-alist
5158 (anything-source-name "FOO")
5159 (buf-local (anything-candidate-buffer 'local
))
5160 (buf-global (anything-candidate-buffer 'global
)))
5161 (prog1 (buffer-name (anything-candidate-buffer))
5162 (kill-buffer buf-local
)
5163 (kill-buffer buf-global
))))
5164 (expect " *anything candidates:FOO*aTestBuffer"
5165 (let* (anything-candidate-buffer-alist
5166 (anything-source-name "FOO")
5167 (anything-current-buffer (get-buffer-create "aTestBuffer"))
5168 (buf-global (anything-candidate-buffer 'global
))
5169 (buf-local (anything-candidate-buffer 'local
)))
5170 (prog1 (buffer-name (anything-candidate-buffer))
5171 (kill-buffer buf-local
)
5172 (kill-buffer buf-global
))))
5174 (let* (anything-candidate-buffer-alist
5175 (anything-source-name "NOP__"))
5176 (anything-candidate-buffer)))
5177 (desc "anything-candidate-buffer register-buffer")
5178 (expect " *anything test candidates*"
5179 (let (anything-candidate-buffer-alist
5180 (buf (get-buffer-create " *anything test candidates*")))
5181 (with-current-buffer buf
5183 (prog1 (buffer-name (anything-candidate-buffer buf
))
5184 (kill-buffer (current-buffer))))))
5185 (expect " *anything test candidates*"
5186 (let (anything-candidate-buffer-alist
5187 (buf (get-buffer-create " *anything test candidates*")))
5188 (with-current-buffer buf
5190 (anything-candidate-buffer buf
)
5191 (prog1 (buffer-name (anything-candidate-buffer))
5192 (kill-buffer (current-buffer))))))
5194 (let (anything-candidate-buffer-alist
5195 (buf (get-buffer-create " *anything test candidates*")))
5196 (with-current-buffer buf
5198 (anything-candidate-buffer buf
)
5199 (prog1 (buffer-string)
5200 (kill-buffer (current-buffer))))))
5202 (let (anything-candidate-buffer-alist
5203 (anything-source-name "foo")
5204 (buf1 (get-buffer-create "buf1"))
5205 (buf2 (get-buffer-create "buf2")))
5206 (anything-candidate-buffer buf1
)
5207 (anything-candidate-buffer buf2
)
5208 (prog1 (buffer-name (anything-candidate-buffer buf1
))
5210 (kill-buffer buf2
))))
5211 (desc "action attribute")
5213 (anything-test-candidates
5216 (action ("identity" . identity
)))))
5217 (anything-execute-selection-action))
5219 (anything-test-candidates
5222 (action ("identity" .
(lambda (c) (identity c
)))))))
5223 (anything-execute-selection-action))
5224 (desc "anything-execute-selection-action")
5226 (anything-execute-selection-action
5227 "foo" '(("upcase" . upcase
)) nil
))
5229 (anything-execute-selection-action
5230 "foo" '(("upcase" .
(lambda (c) (upcase c
)))) nil
))
5231 (desc "display-to-real attribute")
5233 (anything-test-candidates
5236 (display-to-real . upcase
)
5237 (action ("identity" . identity
)))))
5238 (anything-execute-selection-action))
5239 (desc "cleanup test")
5242 (anything-test-candidates
5244 (cleanup .
(lambda () (setq v
'cleaned
))))))
5246 (desc "anything-get-current-source")
5247 ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
5248 ;; display-to-real/cleanup function
5252 (anything-funcall-with-source '((name .
"FOO")) 'anything-get-current-source
)))
5256 (anything-test-candidates
5258 (init .
(lambda () (setq v
(anything-get-current-source)))))))
5259 (assoc-default 'name v
)))
5263 (anything-test-candidates
5265 (candidates .
(lambda () (setq v
(anything-get-current-source)) '("a"))))))
5266 (assoc-default 'name v
)))
5270 (anything-test-candidates
5274 .
(lambda (c) (setq v
(anything-get-current-source)) c
)))))
5275 (anything-execute-selection-action)
5276 (assoc-default 'name v
)))
5277 ;; candidate-transformer
5280 (anything-test-candidates
5283 (candidate-transformer
5284 .
(lambda (c) (setq v
(anything-get-current-source)) c
)))))
5285 (assoc-default 'name v
)))
5286 ;; filtered-candidate-transformer
5289 (anything-test-candidates
5292 (filtered-candidate-transformer
5293 .
(lambda (c s
) (setq v
(anything-get-current-source)) c
)))))
5294 (assoc-default 'name v
)))
5295 ;; action-transformer
5298 (anything-test-candidates
5302 .
(lambda (a c
) (setq v
(anything-get-current-source)) a
))
5303 (action . identity
))))
5304 (anything-execute-selection-action)
5305 (assoc-default 'name v
)))
5309 (anything-test-candidates
5311 (init .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5313 (candidates-in-buffer)
5315 .
(lambda (c) (setq v
(anything-get-current-source)) c
))
5316 (action . identity
))))
5317 (anything-execute-selection-action)
5318 (assoc-default 'name v
)))
5322 (anything-test-candidates
5326 .
(lambda () (setq v
(anything-get-current-source)))))))
5327 (assoc-default 'name v
)))
5328 ;; candidates are displayed
5330 (anything-test-candidates
5333 (action ("identity" . identity
)))))
5334 (assoc-default 'name
(anything-get-current-source)))
5335 (desc "anything-attr")
5337 (anything-funcall-with-source
5340 (anything-attr 'name
))))
5343 (anything-test-candidates
5346 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
5351 (anything-test-candidates
5353 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
5358 (anything-test-candidates
5360 (hoge) ;INCOMPATIBLE!
5361 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
5364 (desc "anything-attr-defined")
5367 (anything-test-candidates
5370 (init .
(lambda () (setq v
(anything-attr-defined 'hoge
))))
5375 (anything-test-candidates
5377 (init .
(lambda () (setq v
(anything-attr-defined 'hoge
))))
5380 (desc "anything-attrset")
5381 (expect '((name .
"FOO") (hoge .
77))
5382 (let ((src '((name .
"FOO") (hoge))))
5383 (anything-attrset 'hoge
77 src
)
5386 (anything-attrset 'hoge
77 '((name .
"FOO") (hoge))))
5388 (expect '((name .
"FOO") (hoge .
77))
5389 (let ((src '((name .
"FOO") (hoge .
1))))
5390 (anything-attrset 'hoge
77 src
)
5393 (expect '((name .
"FOO") (hoge .
77) (x))
5394 (let ((src '((name .
"FOO") (x))))
5395 (anything-attrset 'hoge
77 src
)
5398 (anything-attrset 'hoge
77 '((name .
"FOO"))))
5399 (desc "anything-preselect")
5402 (with-current-buffer (anything-create-anything-buffer t
)
5403 (let ((anything-pattern "")
5404 (anything-test-mode t
))
5405 (anything-process-source '((name .
"test")
5406 (candidates "hoge" "foo" "bar")))
5407 (anything-preselect "foo")
5408 (anything-get-selection))))
5411 (with-current-buffer (anything-create-anything-buffer t
)
5412 (let ((anything-pattern "")
5413 (anything-test-mode t
))
5414 (anything-process-source '((name .
"test")
5415 (candidates "hoge" "foo" "bar")))
5416 (anything-preselect "fo+")
5417 (anything-get-selection))))
5418 ;; no match -> first entry
5420 (with-current-buffer (anything-create-anything-buffer t
)
5421 (let ((anything-pattern "")
5422 (anything-test-mode t
))
5423 (anything-process-source '((name .
"test")
5424 (candidates "hoge" "foo" "bar")))
5425 (anything-preselect "not found")
5426 (anything-get-selection))))
5427 (desc "anything-check-new-input")
5428 (expect "newpattern"
5429 (stub anything-update
)
5430 (stub anything-action-window
)
5431 (let ((anything-pattern "pattern"))
5432 (anything-check-new-input "newpattern")
5434 ;; anything-input == nil when action window is available
5436 (stub anything-update
)
5437 (stub anything-action-window
=> t
)
5438 (let ((anything-pattern "pattern")
5440 (anything-check-new-input "newpattern")
5442 ;; anything-input == anything-pattern unless action window is available
5443 (expect "newpattern"
5444 (stub anything-update
)
5445 (stub anything-action-window
=> nil
)
5446 (let ((anything-pattern "pattern")
5448 (anything-check-new-input "newpattern")
5450 (expect (mock (anything-update))
5451 (stub anything-action-window
)
5452 (let (anything-pattern)
5453 (anything-check-new-input "foo")))
5454 (desc "anything-update")
5455 (expect (mock (anything-process-source '((name .
"1"))))
5456 (anything-test-update '(((name .
"1"))) ""))
5457 ;; (find-function 'anything-update)
5458 ;; TODO el-mock.el should express 2nd call of function.
5459 ;; (expect (mock (anything-process-source '((name . "2"))))
5460 ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
5462 ;; (stub anything-maybe-fit-frame)
5463 ;; (stub run-with-idle-timer)
5464 ;; (anything-update))
5465 (expect (mock (run-with-idle-timer * nil
'anything-process-delayed-sources
5466 '(((name .
"2") (delayed)))))
5467 (stub anything-get-sources
=> '(((name .
"1"))
5468 ((name .
"2") (delayed))))
5470 (stub anything-maybe-fit-frame
)
5471 (let ((anything-pattern "") anything-test-mode
)
5474 (desc "requires-pattern attribute")
5475 (expect (not-called anything-process-source
)
5476 (anything-test-update '(((name .
"1") (requires-pattern))) ""))
5477 (expect (not-called anything-process-source
)
5478 (anything-test-update '(((name .
"1") (requires-pattern .
3))) "xx"))
5481 (expect (mock (sit-for 0.25))
5482 (stub with-current-buffer
)
5483 (let ((anything-idle-delay 1.0)
5484 (anything-input-idle-delay 0.75))
5485 (anything-process-delayed-sources t
)))
5486 (expect (mock (sit-for 0.0))
5487 (stub with-current-buffer
)
5488 (let ((anything-idle-delay 0.2)
5489 (anything-input-idle-delay 0.5))
5490 (anything-process-delayed-sources t
)))
5491 (expect (mock (sit-for 0.5))
5492 (stub with-current-buffer
)
5493 (let ((anything-idle-delay 0.5)
5494 (anything-input-idle-delay nil
))
5495 (anything-process-delayed-sources t
)))
5496 (desc "anything-normalize-sources")
5497 (expect '(anything-c-source-test)
5498 (anything-normalize-sources 'anything-c-source-test
))
5499 (expect '(anything-c-source-test)
5500 (anything-normalize-sources '(anything-c-source-test)))
5501 (expect '(anything-c-source-test)
5502 (let ((anything-sources '(anything-c-source-test)))
5503 (anything-normalize-sources nil
)))
5504 (expect '(((name .
"test")))
5505 (anything-normalize-sources '((name .
"test"))))
5506 (expect '(((name .
"test")))
5507 (anything-normalize-sources '(((name .
"test")))))
5508 (desc "anything-get-action")
5509 (expect '(("identity" . identity
))
5510 (stub buffer-size
=> 1)
5511 (stub anything-get-current-source
=> '((name .
"test")
5512 (action ("identity" . identity
))))
5513 (anything-get-action))
5514 (expect '((("identity" . identity
)) "action-transformer is called")
5515 (stub buffer-size
=> 1)
5516 (stub anything-get-current-source
5517 => '((name .
"test")
5518 (action ("identity" . identity
))
5520 .
(lambda (actions selection
)
5521 (list actions selection
)))))
5522 (stub anything-get-selection
=> "action-transformer is called")
5523 (anything-get-action))
5524 (desc "anything-select-nth-action")
5526 (stub anything-get-selection
=> "selection")
5527 (stub anything-exit-minibuffer
)
5528 (let (anything-saved-selection)
5529 (anything-select-nth-action 1)
5530 anything-saved-selection
))
5532 (stub anything-get-action
=> '(("0" . car
) ("1" . cdr
) ("2" . cadr
)))
5533 (stub anything-exit-minibuffer
)
5534 (stub anything-get-selection
=> "selection")
5535 (let (anything-saved-action)
5536 (anything-select-nth-action 2)
5537 anything-saved-action
))
5538 (desc "anything-funcall-foreach")
5539 (expect (mock (upcase "foo"))
5540 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))))
5541 (anything-funcall-foreach 'init
))
5542 (expect (mock (downcase "bar"))
5543 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))
5544 ((init .
(lambda () (downcase "bar"))))))
5545 (anything-funcall-foreach 'init
))
5546 (expect (not-called anything-funcall-with-source
)
5547 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))))
5548 (anything-funcall-foreach 'not-found
))
5549 ;; TODO anything-select-with-digit-shortcut test
5550 (desc "anything-get-cached-candidates")
5551 (expect '("cached" "version")
5552 (let ((anything-candidate-cache '(("test" "cached" "version"))))
5553 (anything-get-cached-candidates '((name .
"test")
5554 (candidates "new")))))
5556 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5557 (anything-get-cached-candidates '((name .
"test")
5558 (candidates "new")))))
5559 (expect '(("test" "new")
5560 ("other" "cached" "version"))
5561 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5562 (anything-get-cached-candidates '((name .
"test")
5563 (candidates "new")))
5564 anything-candidate-cache
))
5565 (expect '(("other" "cached" "version"))
5566 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5567 (anything-get-cached-candidates '((name .
"test")
5570 anything-candidate-cache
))
5571 ;; TODO when candidates == process
5572 ;; TODO anything-output-filter
5573 (desc "candidate-number-limit attribute")
5575 (let ((anything-pattern "")
5576 (anything-candidate-number-limit 20))
5577 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c")
5578 (candidate-number-limit .
2) (volatile)))))
5580 (let ((anything-pattern "[abc]")
5581 (anything-candidate-number-limit 20))
5582 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c")
5583 (candidate-number-limit .
2) (volatile)))))
5584 (expect '("a" "b" "c" "d")
5585 (let ((anything-pattern "[abcd]")
5586 (anything-candidate-number-limit 2))
5587 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c" "d")
5588 (candidate-number-limit) (volatile)))))
5589 (expect '(("TEST" ("a" "b" "c")))
5590 (let ((anything-candidate-number-limit 2))
5591 (anything-test-candidates
5594 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5595 (insert "a\nb\nc\nd\n"))))
5596 (candidates . anything-candidates-in-buffer
)
5598 (candidate-number-limit .
3)
5600 (expect '(("TEST" ("a" "b" "c")))
5601 (let ((anything-candidate-number-limit 2))
5602 (anything-test-candidates
5605 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5606 (insert "a\nb\nc\nd\n"))))
5607 (candidates . anything-candidates-in-buffer
)
5609 (candidate-number-limit .
3)
5612 (desc "multiple init")
5615 (anything-test-candidates
5617 (init (lambda () (setq a
1))
5618 (lambda () (setq b
2))))))
5622 (anything-test-candidates
5624 (init (lambda () (setq a
1))))))
5626 (desc "multiple cleanup")
5629 (anything-test-candidates
5631 (cleanup (lambda () (setq a
1))
5632 (lambda () (setq b
2))))))
5634 (desc "anything-mklist")
5636 (anything-mklist 1))
5638 (anything-mklist '(2)))
5639 (expect '((lambda ()))
5640 (anything-mklist (lambda ())))
5641 (desc "anything-before-initialize-hook")
5643 (let ((anything-before-initialize-hook '((lambda () (setq v
'called
))))
5645 (anything-initialize)
5647 (desc "anything-after-initialize-hook")
5649 (let ((anything-before-initialize-hook
5650 '((lambda () (setq v
'(a)))))
5651 (anything-after-initialize-hook
5652 '((lambda () (setq v
(cons 'b v
)))))
5654 (anything-initialize)
5657 (let ((anything-after-initialize-hook
5658 '((lambda () (setq v
(buffer-size (get-buffer anything-buffer
))))))
5660 (anything-initialize)
5662 (desc "get-line attribute")
5663 (expect '(("TEST" ("FOO+")))
5664 (anything-test-candidates
5667 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5668 (insert "foo+\nbar+\nbaz+\n"))))
5669 (candidates-in-buffer)
5670 (get-line .
(lambda (s e
) (upcase (buffer-substring-no-properties s e
))))))
5672 (desc "with-anything-restore-variables")
5675 (anything-restored-variables '(a b
)))
5676 (with-anything-restore-variables
5679 (desc "anything-cleanup-hook")
5681 (let ((anything-cleanup-hook
5682 '((lambda () (setq v
'called
))))
5686 (desc "with-anything-display-same-window")
5688 (save-window-excursion
5689 (delete-other-windows)
5692 (let ((buf (get-buffer-create " tmp"))
5693 (win (selected-window)))
5694 (with-anything-display-same-window
5695 (display-buffer buf
)
5696 (eq win
(get-buffer-window buf
))))))
5698 (save-window-excursion
5699 (delete-other-windows)
5702 (let ((buf (get-buffer-create " tmp"))
5703 (win (selected-window)))
5704 (with-anything-display-same-window
5706 (eq win
(get-buffer-window buf
))))))
5708 (save-window-excursion
5709 (delete-other-windows)
5712 (let ((buf (get-buffer-create " tmp"))
5713 (win (selected-window)))
5714 (with-anything-display-same-window
5715 (switch-to-buffer buf
)
5716 (eq win
(get-buffer-window buf
))))))
5718 (save-window-excursion
5719 (delete-other-windows)
5720 (let ((buf (get-buffer-create " tmp"))
5721 (win (selected-window)))
5722 (with-anything-display-same-window
5723 (display-buffer buf
)
5724 (eq win
(get-buffer-window buf
))))))
5726 (save-window-excursion
5727 (delete-other-windows)
5728 (let ((buf (get-buffer-create " tmp"))
5729 (win (selected-window)))
5730 (with-anything-display-same-window
5732 (eq win
(get-buffer-window buf
))))))
5733 (desc "search-from-end attribute")
5734 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5735 (anything-test-candidates
5738 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5739 (insert "foo+\nbar+\nbaz+\n"))))
5740 (candidates-in-buffer)
5741 (search-from-end)))))
5742 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5743 (anything-test-candidates
5746 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5747 (insert "foo+\nbar+\nbaz+\n"))))
5748 (candidates-in-buffer)
5751 (expect '(("TEST" ("baz+" "bar+")))
5752 (anything-test-candidates
5755 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5756 (insert "foo+\nbar+\nbaz+\n"))))
5757 (candidates-in-buffer)
5759 (candidate-number-limit .
2)))))
5760 (expect '(("TEST" ("baz+" "bar+")))
5761 (anything-test-candidates
5764 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5765 (insert "foo+\nbar+\nbaz+\n"))))
5766 (candidates-in-buffer)
5768 (candidate-number-limit .
2)))
5771 (desc "header-name attribute")
5772 (expect "original is transformed"
5773 (anything-test-update '(((name .
"original")
5777 (format "%s is transformed" name
)))))
5779 (with-current-buffer (anything-buffer-get)
5781 (overlay-get (car (overlays-at (1+(point-min)))) 'display
)))
5782 (desc "volatile and match attribute")
5783 ;; candidates function is called once per `anything-process-delayed-sources'
5786 (anything-test-candidates '(((name .
"test")
5787 (candidates .
(lambda () (incf v
) '("ok")))
5789 (match identity identity identity
)))
5792 (desc "accept-empty attribute")
5794 (anything-test-candidates
5795 '(((name .
"test") (candidates "") (action . identity
))))
5796 (anything-execute-selection-action))
5798 (anything-test-candidates
5799 '(((name .
"test") (candidates "") (action . identity
) (accept-empty))))
5800 (anything-execute-selection-action))
5801 (desc "anything-tick-hash")
5803 (with-current-buffer (get-buffer-create " *00create+*")
5804 (puthash " *00create+*/xxx" 1 anything-tick-hash
)
5805 (kill-buffer (current-buffer)))
5806 (gethash " *00create+*/xxx" anything-tick-hash
))
5807 (desc "anything-execute-action-at-once-if-once")
5809 (let ((anything-execute-action-at-once-if-one t
))
5810 (anything '(((name .
"one test1")
5812 (action . upcase
))))))
5814 (let ((anything-execute-action-at-once-if-one t
))
5815 (anything '(((name .
"one test2")
5816 (candidates "hoge" "any")
5820 (expect (mock (read-string "word: " nil
))
5821 (let ((anything-execute-action-at-once-if-one t
))
5822 (anything '(((name .
"one test3")
5823 (candidates "hoge" "foo" "bar")
5824 (action . identity
)))
5826 (desc "anything-quit-if-no-candidate")
5828 (let ((anything-quit-if-no-candidate t
))
5829 (anything '(((name .
"zero test1") (candidates) (action . upcase
))))))
5831 (let (v (anything-quit-if-no-candidate (lambda () (setq v
'called
))))
5832 (anything '(((name .
"zero test2") (candidates) (action . upcase
))))
5834 (desc "real-to-display attribute")
5835 (expect '(("test" (("DDD" .
"ddd"))))
5836 (anything-test-candidates '(((name .
"test")
5838 (real-to-display . upcase
)
5839 (action . identity
)))))
5840 (expect '(("test" (("DDD" .
"ddd"))))
5841 (anything-test-candidates '(((name .
"test")
5842 (candidates ("ignored" .
"ddd"))
5843 (real-to-display . upcase
)
5844 (action . identity
)))))
5845 (expect '(("Commands" (("xxxhoge" .
"hoge") ("xxxboke" .
"boke"))))
5846 (anything-test-candidates '(((name .
"Commands")
5849 (real-to-display .
(lambda (x) (concat "xxx" x
)))
5850 (action . identity
)))
5852 (expect "test\nDDD\n"
5853 (anything-test-update '(((name .
"test")
5855 (real-to-display . upcase
)
5856 (action . identity
)))
5858 (with-current-buffer (anything-buffer-get) (buffer-string)))
5859 (desc "real-to-display and candidate-transformer attribute")
5860 (expect '(("test" (("DDD" .
"ddd"))))
5861 (anything-test-candidates
5864 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c
)) cands
)))
5865 (real-to-display . upcase
)
5866 (action . identity
)))))
5867 (expect "test\nDDD\n"
5868 (anything-test-update
5871 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c
)) cands
)))
5872 (real-to-display . upcase
)
5873 (action . identity
)))
5875 (with-current-buffer (anything-buffer-get) (buffer-string)))
5876 (desc "real-to-display and candidates-in-buffer")
5877 (expect '(("test" (("A" .
"a") ("B" .
"b"))))
5878 (anything-test-candidates
5881 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5883 (insert "a\nb\n"))))
5884 (candidates-in-buffer)
5885 (real-to-display . upcase
)
5886 (action . identity
)))))
5887 (expect "test\nA\nB\n"
5892 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5894 (insert "a\nb\n"))))
5895 (candidates-in-buffer)
5896 (real-to-display . upcase
)
5897 (action . identity
))))
5898 (with-current-buffer (anything-buffer-get) (buffer-string)))
5899 (desc "Symbols are acceptable as candidate.")
5900 (expect '(("test" (sym "str")))
5901 (anything-test-candidates
5903 (candidates sym
"str")))))
5904 (expect '(("test" ((sym . realsym
) ("str" .
"realstr"))))
5905 (anything-test-candidates
5907 (candidates (sym . realsym
) ("str" .
"realstr"))))))
5908 (expect '(("test" (sym)))
5909 (anything-test-candidates
5911 (candidates sym
"str")))
5913 (expect '(("test" ("str")))
5914 (anything-test-candidates
5916 (candidates sym
"str")))
5918 (expect '(("test" ((sym . realsym
))))
5919 (anything-test-candidates
5921 (candidates (sym . realsym
) ("str" .
"realstr"))))
5923 (expect '(("test" (("str" .
"realstr"))))
5924 (anything-test-candidates
5926 (candidates (sym . realsym
) ("str" .
"realstr"))))
5928 (desc "multiple transformers")
5929 (expect '(("test" ("<FOO>")))
5930 (anything-test-candidates
5933 (candidate-transformer
5935 (anything-compose (list cands
)
5936 (list (lambda (c) (mapcar 'upcase c
))
5937 (lambda (c) (list (concat "<" (car c
) ">")))))))))))
5939 (anything-composed-funcall-with-source
5941 (list (lambda (c) (mapcar 'upcase c
))
5942 (lambda (c) (list (concat "<" (car c
) ">"))))
5945 (expect '(("test" ("<FOO>")))
5946 (anything-test-candidates
5949 (candidate-transformer
5950 (lambda (c) (mapcar 'upcase c
))
5951 (lambda (c) (list (concat "<" (car c
) ">"))))))))
5952 (expect '(("test" ("<BAR>")))
5953 (anything-test-candidates
5956 (filtered-candidate-transformer
5957 (lambda (c s
) (mapcar 'upcase c
))
5958 (lambda (c s
) (list (concat "<" (car c
) ">"))))))))
5959 (expect '(("find-file" . find-file
)
5960 ("view-file" . view-file
))
5962 (stub anything-get-current-source
5963 => '((name .
"test")
5969 (list (lambda (a s
) (push '("view-file" . view-file
) a
))
5970 (lambda (a s
) (push '("find-file" . find-file
) a
))))))))
5971 (anything-get-action))
5972 (expect '(("find-file" . find-file
)
5973 ("view-file" . view-file
))
5975 (stub anything-get-current-source
5976 => '((name .
"test")
5979 (lambda (a s
) (push '("view-file" . view-file
) a
))
5980 (lambda (a s
) (push '("find-file" . find-file
) a
)))))
5981 (anything-get-action))
5982 (desc "define-anything-type-attribute")
5983 (expect '((file (action . find-file
)))
5984 (let (anything-type-attributes)
5985 (define-anything-type-attribute 'file
'((action . find-file
)))
5986 anything-type-attributes
))
5987 (expect '((file (action . find-file
)))
5988 (let ((anything-type-attributes '((file (action . view-file
)))))
5989 (define-anything-type-attribute 'file
'((action . find-file
)))
5990 anything-type-attributes
))
5991 (expect '((file (action . find-file
))
5992 (buffer (action . switch-to-buffer
)))
5993 (let (anything-type-attributes)
5994 (define-anything-type-attribute 'buffer
'((action . switch-to-buffer
)))
5995 (define-anything-type-attribute 'file
'((action . find-file
)))
5996 anything-type-attributes
))
5997 (desc "anything-approximate-candidate-number")
6000 (let ((anything-buffer (current-buffer)))
6001 (anything-approximate-candidate-number))))
6004 (let ((anything-buffer (current-buffer)))
6007 (anything-approximate-candidate-number))))
6010 (let ((anything-buffer (current-buffer)))
6014 (<= 2 (anything-approximate-candidate-number)))))
6017 (let ((anything-buffer (current-buffer)))
6019 (propertize "multi\nline\n" 'anything-multiline t
))
6020 (anything-approximate-candidate-number))))
6023 (let ((anything-buffer (current-buffer))
6024 (anything-candidate-separator "-----"))
6026 (propertize "multi\nline1\n" 'anything-multiline t
)
6028 (propertize "multi\nline2\n" 'anything-multiline t
))
6029 (<= 2 (anything-approximate-candidate-number)))))
6030 (desc "delayed-init attribute")
6033 (anything-test-candidates '(((name .
"test")
6034 (delayed-init .
(lambda () (incf value
)))
6036 (requires-pattern .
2)))
6041 (anything-test-candidates '(((name .
"test")
6042 (delayed-init .
(lambda () (incf value
)))
6044 (requires-pattern .
2)))
6050 (anything-test-candidates '(((name .
"test")
6052 .
(lambda () (setq value
6053 (eq anything-current-buffer
(current-buffer)))))
6055 (requires-pattern .
2)))
6058 (desc "pattern-transformer attribute")
6059 (expect '(("test2" ("foo")) ("test3" ("bar")))
6060 (anything-test-candidates '(((name .
"test1")
6061 (candidates "foo" "bar"))
6063 (pattern-transformer .
(lambda (pat) (substring pat
1)))
6064 (candidates "foo" "bar"))
6066 (pattern-transformer .
(lambda (pat) "bar"))
6067 (candidates "foo" "bar")))
6069 (expect '(("test2" ("foo")) ("test3" ("bar")))
6070 (anything-test-candidates '(((name .
"test1")
6071 (candidates "foo" "bar"))
6073 (pattern-transformer (lambda (pat) (substring pat
1)))
6074 (candidates "foo" "bar"))
6076 (pattern-transformer (lambda (pat) "bar"))
6077 (candidates "foo" "bar")))
6079 (expect '(("test2" ("foo")) ("test3" ("bar")))
6080 (anything-test-candidates '(((name .
"test1")
6082 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
6083 (insert "foo\nbar\n"))))
6084 (candidates-in-buffer))
6086 (pattern-transformer .
(lambda (pat) (substring pat
1)))
6088 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
6089 (insert "foo\nbar\n"))))
6090 (candidates-in-buffer))
6092 (pattern-transformer .
(lambda (pat) "bar"))
6094 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
6095 (insert "foo\nbar\n"))))
6096 (candidates-in-buffer)))
6098 (desc "anything-recent-push")
6099 (expect '("foo" "bar" "baz")
6100 (let ((lst '("bar" "baz")))
6101 (anything-recent-push "foo" 'lst
)))
6102 (expect '("foo" "bar" "baz")
6103 (let ((lst '("foo" "bar" "baz")))
6104 (anything-recent-push "foo" 'lst
)))
6105 (expect '("foo" "bar" "baz")
6106 (let ((lst '("bar" "foo" "baz")))
6107 (anything-recent-push "foo" 'lst
)))
6108 (desc "anything-require-at-least-version")
6110 (anything-require-at-least-version "1.1"))
6112 (anything-require-at-least-version "1.200"))
6114 (anything-require-at-least-version
6115 (and (string-match "1\.\\([0-9]+\\)" anything-version
)
6116 (match-string 0 anything-version
))))
6118 (anything-require-at-least-version "1.999"))
6120 (anything-require-at-least-version "1.2000"))
6121 (desc "anything-once")
6124 (anything-test-candidates
6126 (init .
(lambda () (incf i
))))
6128 (init .
(lambda () (incf i
))))))
6132 (anything-test-candidates
6134 (init .
(lambda () (anything-once (lambda () (incf i
))))))
6136 (init .
(lambda () (anything-once (lambda () (incf i
))))))))
6140 (flet ((init1 () (anything-once (lambda () (incf i
)))))
6141 (anything-test-candidates
6147 (desc "anything-marked-candidates")
6148 (expect '("mark3" "mark1")
6149 (let* ((source '((name .
"mark test")))
6150 (anything-marked-candidates
6151 `((,source .
"mark1")
6152 (((name .
"other")) .
"mark2")
6153 (,source .
"mark3"))))
6154 (stub anything-get-current-source
=> source
)
6155 (anything-marked-candidates)))
6156 (expect '("current")
6157 (let* ((source '((name .
"mark test")))
6158 (anything-marked-candidates nil
))
6159 (stub anything-get-current-source
=> source
)
6160 (stub anything-get-selection
=> "current")
6161 (anything-marked-candidates)))
6166 ;; How to save (DO NOT REMOVE!!)
6167 ;; (progn (magit-push) (emacswiki-post "anything.el"))
6168 ;;; anything.el ends here