anything.el (documentation-property): use ad-get-arg
[anything-config.git] / anything.el
blobe6f9e7237fff8df4e2f165a10459f63aa8378f34
1 ;;;; anything.el --- open anything / QuickSilver-like candidate-selection framework
3 ;; Copyright (C) 2007 Tamas Patrovics
4 ;; 2008, 2009, 2010 rubikitch <rubikitch@ruby-lang.org>
6 ;; Author: Tamas Patrovics
7 ;; Maintainer: rubikitch <rubikitch@ruby-lang.org>
8 ;; Keywords: files, frames, help, matching, outlines, processes, tools, convenience, anything
9 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
10 ;; Site: http://www.emacswiki.org/cgi-bin/emacs/Anything
11 (defvar anything-version nil)
12 (setq anything-version "1.287")
14 ;; This file is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
19 ;; This file is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
30 ;;; Commentary:
33 ;; Start with M-x anything, narrow the list by typing some pattern,
34 ;; select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter,
35 ;; left/right moves between sources. With TAB actions can be selected
36 ;; if the selected candidate has more than one possible action.
38 ;; Note that anything.el provides only the framework and some example
39 ;; configurations for demonstration purposes. See anything-config.el
40 ;; for practical, polished, easy to use configurations which can be
41 ;; used to assemble a custom personalized configuration. And many
42 ;; other configurations are in the EmacsWiki.
43 ;;
44 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-config.el
45 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingSources
47 ;; Maintainer's configuration is in the EmacsWiki. It would tell you
48 ;; many tips to write smart sources!
50 ;; http://www.emacswiki.org/cgi-bin/emacs/RubikitchAnythingConfiguration
52 ;; Here is Japanese translation of `anything-sources' attributes. Thanks.
53 ;; http://d.hatena.ne.jp/sirocco634/20091012/1255336649
55 ;;; Bug Report:
57 ;; If you have problems, send a bug report via C-c C-x C-b in anything session (best)
58 ;; or M-x anything-send-bug-report outside anything session.
59 ;; I implemented bug report feature because I want to know your current state.
60 ;; It helps me to solve problems easily.
61 ;; The step is:
62 ;; 0) Setup mail in Emacs, the easiest way is:
63 ;; (setq user-mail-address "your@mail.address")
64 ;; (setq user-full-name "Your Full Name")
65 ;; (setq smtpmail-smtp-server "your.smtp.server.jp")
66 ;; (setq mail-user-agent 'message-user-agent)
67 ;; (setq message-send-mail-function 'message-smtpmail-send-it)
68 ;; 1) Be sure to use the LATEST version of anything.el.
69 ;; 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
70 ;; 3) Use Lisp version instead of compiled one: (load "anything.el")
71 ;; 4) Do it!
72 ;; 5) If you got an error, please do not close *Backtrace* buffer.
73 ;; 6) Type C-c C-x C-b (anything session, best!)
74 ;; or M-x anything-send-bug-report (outside)
75 ;; then M-x insert-buffer *Backtrace* (if you got error)
76 ;; 7) Describe the bug using a precise recipe.
77 ;; 8) Type C-c C-c to send.
78 ;; # If you are a Japanese, please write in Japanese:-)
81 ;;; Commands:
83 ;; Below are complete command list:
85 ;; `anything-open-last-log'
86 ;; Open anything log file of last anything session.
87 ;; `anything'
88 ;; Select anything. In Lisp program, some optional arguments can be used.
89 ;; `anything-resume'
90 ;; Resurrect previously invoked `anything'.
91 ;; `anything-at-point'
92 ;; Same as `anything' except when C-u is pressed, the initial input is the symbol at point.
93 ;; `anything-force-update'
94 ;; Recalculate and update candidates.
95 ;; `anything-select-action'
96 ;; Select an action for the currently selected candidate.
97 ;; `anything-previous-line'
98 ;; Move selection to the previous line.
99 ;; `anything-next-line'
100 ;; Move selection to the next line.
101 ;; `anything-previous-page'
102 ;; Move selection back with a pageful.
103 ;; `anything-next-page'
104 ;; Move selection forward with a pageful.
105 ;; `anything-beginning-of-buffer'
106 ;; Move selection at the top.
107 ;; `anything-end-of-buffer'
108 ;; Move selection at the bottom.
109 ;; `anything-previous-source'
110 ;; Move selection to the previous source.
111 ;; `anything-next-source'
112 ;; Move selection to the next source.
113 ;; `anything-select-with-prefix-shortcut'
114 ;; Invoke default action with prefix shortcut.
115 ;; `anything-select-with-digit-shortcut'
116 ;; Invoke default action with digit/alphabet shortcut.
117 ;; `anything-exit-minibuffer'
118 ;; Select the current candidate by exiting the minibuffer.
119 ;; `anything-keyboard-quit'
120 ;; Quit minibuffer in anything.
121 ;; `anything-help'
122 ;; Help of `anything'.
123 ;; `anything-debug-output'
124 ;; Show all anything-related variables at this time.
125 ;; `anything-delete-current-selection'
126 ;; Delete the currently selected item.
127 ;; `anything-delete-minibuffer-contents'
128 ;; Same as `delete-minibuffer-contents' but this is a command.
129 ;; `anything-toggle-resplit-window'
130 ;; Toggle resplit anything window, vertically or horizontally.
131 ;; `anything-select-2nd-action'
132 ;; Select the 2nd action for the currently selected candidate.
133 ;; `anything-select-3rd-action'
134 ;; Select the 3rd action for the currently selected candidate.
135 ;; `anything-select-4th-action'
136 ;; Select the 4th action for the currently selected candidate.
137 ;; `anything-select-2nd-action-or-end-of-line'
138 ;; Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
139 ;; `anything-execute-persistent-action'
140 ;; If a candidate is selected then perform the associated action without quitting anything.
141 ;; `anything-scroll-other-window'
142 ;; Scroll other window (not *Anything* window) upward.
143 ;; `anything-scroll-other-window-down'
144 ;; Scroll other window (not *Anything* window) downward.
145 ;; `anything-toggle-visible-mark'
146 ;; Toggle anything visible mark at point.
147 ;; `anything-display-all-visible-marks'
148 ;; Show all `anything' visible marks strings.
149 ;; `anything-next-visible-mark'
150 ;; Move next anything visible mark.
151 ;; `anything-prev-visible-mark'
152 ;; Move previous anything visible mark.
153 ;; `anything-quit-and-find-file'
154 ;; Drop into `find-file' from `anything' like `iswitchb-find-file'.
155 ;; `anything-yank-selection'
156 ;; Set minibuffer contents to current selection.
157 ;; `anything-kill-selection-and-quit'
158 ;; Store current selection to kill ring.
159 ;; `anything-follow-mode'
160 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
161 ;; `anything-migrate-sources'
162 ;; Help to migrate to new `anything' way.
163 ;; `anything-isearch'
164 ;; Start incremental search within results. (UNMAINTAINED)
165 ;; `anything-isearch-printing-char'
166 ;; Add printing char to the pattern.
167 ;; `anything-isearch-again'
168 ;; Search again for the current pattern
169 ;; `anything-isearch-delete'
170 ;; Undo last event.
171 ;; `anything-isearch-default-action'
172 ;; Execute the default action for the selected candidate.
173 ;; `anything-isearch-select-action'
174 ;; Choose an action for the selected candidate.
175 ;; `anything-isearch-cancel'
176 ;; Cancel Anything isearch.
177 ;; `anything-iswitchb-setup'
178 ;; Integrate anything completion into iswitchb (UNMAINTAINED).
179 ;; `anything-iswitchb-cancel-anything'
180 ;; Cancel anything completion and return to standard iswitchb.
181 ;; `anything-describe-anything-attribute'
182 ;; Display the full documentation of ANYTHING-ATTRIBUTE (a symbol).
183 ;; `anything-send-bug-report'
184 ;; Send a bug report of anything.el.
185 ;; `anything-send-bug-report-from-anything'
186 ;; Send a bug report of anything.el in anything session.
188 ;;; Customizable Options:
190 ;; Below are customizable option list:
193 ;; You can extend `anything' by writing plug-ins. As soon as
194 ;; `anything' is invoked, `anything-sources' is compiled into basic
195 ;; attributes, then compiled one is used during invocation.
197 ;; The oldest built-in plug-in is `type' attribute: appends
198 ;; appropriate element of `anything-type-attributes'. Second built-in
199 ;; plug-in is `candidates-in-buffer': selecting a line from candidates
200 ;; buffer.
202 ;; To write a plug-in:
203 ;; 1. Define a compiler: anything-compile-source--*
204 ;; 2. Add compier function to `anything-compile-source-functions'.
205 ;; 3. (optional) Write helper functions.
207 ;; Anything plug-ins are found in the EmacsWiki.
209 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
211 ;; Tested on Emacs 22/23.
214 ;; Thanks to Vagn Johansen for ideas.
215 ;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
216 ;; Thanks to Tassilo Horn for fixes.
217 ;; Thanks to Drew Adams for various fixes (frame, isearch, customization, etc.)
218 ;; Thanks to IMAKADO for candidates-in-buffer idea.
219 ;; Thanks to Tomohiro MATSUYAMA for multiline patch.
222 ;;; (@* "Index")
224 ;; If you have library `linkd.el', load
225 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
226 ;; navigate around the sections Linkd mode will
227 ;; highlight this Index. You can get `linkd.el' here:
228 ;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
232 ;;; (@* "INCOMPATIBLE CHANGES")
234 ;; v1.277
236 ;; Default setting of `anything-save-configuration-functions' is changed.
237 ;; Anything saves/restores window configuration instead of frame configuration now.
238 ;; The default is changed because flickering is occurred in some environment.
240 ;; If you want to save and restore frame configuration, set this variable to
241 ;; '(set-frame-configuration . current-frame-configuration)
243 ;; v1.276
245 ;; Fitting frame is disabled by default, because some flickering occurred
246 ;; in some environment. To enable fitting, set both
247 ;; `anything-inhibit-fit-frame-flag' and `fit-frame-inhibit-fitting' to
248 ;; nil.
250 ;; v1.114
252 ;; `anything-attr' returns nil when the source attribute is defined
253 ;; but the value of attribute is nil, eg. (volatile) cell. Use
254 ;; `anything-attr-defined' when testing whether the attribute is
255 ;; defined.
257 ;;; (@* "Tips")
260 ;; `anything' accepts keyword arguments. See docstring.
261 ;; [EVAL IT] (describe-function 'anything)
264 ;; `anything-enable-shortcuts' enables us to select candidate easily.
265 ;; If 'prefix then they can be selected using <prefix-key> <alnum>.
266 ;; The prefix key is `anything-select-with-prefix-shortcut'.
267 ;; If the <prefix-key> is a letter, pressing twice inputs the letter itself.
268 ;; e.g.
269 ;; (setq anything-enable-shortcuts 'prefix)
270 ;; (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
273 ;; You can edit current selection using `anything-edit-current-selection'.
274 ;; It is useful after persistent-action.
277 ;; For `anything' users, setting `anything-sources' directly and
278 ;; invoke M-x anything is obsolete way for now. Try M-x
279 ;; `anything-migrate-sources'!
282 ;; If you want to create anything sources, yasnippet would help you.
283 ;; http://yasnippet.googlecode.com/
285 ;; Then get the snippet from
286 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
288 ;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
292 ;; `anything-interpret-value' is useful function to interpret value
293 ;; like `candidates' attribute.
295 ;; (anything-interpret-value "literal") ; => "literal"
296 ;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
297 ;; (let ((source '((name . "lambda with source name"))))
298 ;; (anything-interpret-value
299 ;; (lambda () anything-source-name)
300 ;; source)) ; => "lambda with source name"
301 ;; (flet ((f () "function symbol"))
302 ;; (anything-interpret-value 'f)) ; => "function symbol"
303 ;; (let ((v "variable symbol"))
304 ;; (anything-interpret-value 'v)) ; => "variable symbol"
305 ;; (anything-interpret-value 'unbounded-1) ; error
308 ;; Now symbols are acceptable as candidates. So you do not have to use
309 ;; `symbol-name' function. The source is much simpler. For example,
310 ;; `apropos-internal' returns a list of symbols.
312 ;; (anything
313 ;; '(((name . "Commands")
314 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
315 ;; (volatile)
316 ;; (action . describe-function))))
319 ;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
320 ;; marked candidate, press M-[ or M-].
323 ;; `anything-map' is now Emacs-standard key bindings by default. If
324 ;; you are using `iswitchb', execute `anything-iswitchb-setup'. Then
325 ;; some key bindings are adjusted to `iswitchb'. Note that
326 ;; anything-iswitchb is not maintained.
329 ;; There are many `anything' applications, using `anything' for
330 ;; selecting candidate. In this case, if there is one candidate or no
331 ;; candidate, popping up *anything* buffer is irritating. If one
332 ;; candidate, you want to select it at once. If no candidate, you want
333 ;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
334 ;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
335 ;; that setting these variables GLOBALLY is bad idea because of
336 ;; delayed sources. These are meant to be let-binded.
337 ;; See anything-etags.el for example.
339 ;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
341 ;; ex.
342 ;; (let ((anything-execute-action-at-once-if-one t)
343 ;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
344 ;; (anything temporary-sources input))
347 ;; `set-frame-configuration' arises flickering. If you hate
348 ;; flickering, eval:
349 ;; (setq anything-save-configuration-functions
350 ;; '(set-window-configuration . current-window-configuration))
351 ;; at the cost of restoring frame configuration (only window configuration).
354 ;; `anything-delete-current-selection' deletes the current line.
355 ;; It is useful when deleting a candidate in persistent action.
356 ;; eg. `kill-buffer'.
358 ;; [EVAL IT] (describe-function 'anything-delete-current-selection)
361 ;; `anything-attr' gets the attribute. `anything-attrset' sets the
362 ;; attribute. `anything-attr-defined' tests whether the attribute is
363 ;; defined. They handles source-local variables.
365 ;; [EVAL IT] (describe-function 'anything-attr)
366 ;; [EVAL IT] (describe-function 'anything-attrset)
367 ;; [EVAL IT] (describe-function 'anything-attr-defined)
370 ;; `anything-sources' accepts many attributes to make your life easier.
371 ;; Now `anything-sources' accepts a list of symbols.
373 ;; [EVAL IT] (describe-variable 'anything-sources)
376 ;; `anything' has optional arguments. Now you do not have to let-bind
377 ;; `anything-sources'.
379 ;; [EVAL IT] (describe-function 'anything)
382 ;; `anything-resume' resumes last `anything' session. Now you do not
383 ;; have to retype pattern.
385 ;; [EVAL IT] (describe-function 'anything-resume)
388 ;; `anything-execute-persistent-action' executes action without
389 ;; quitting `anything'. When popping up a buffer in other window by
390 ;; persistent action, you can scroll with `anything-scroll-other-window' and
391 ;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
393 ;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
394 ;; [EVAL IT] (describe-variable 'anything-sources)
397 ;; `anything-select-2nd-action', `anything-select-3rd-action' and
398 ;; `anything-select-4th-action' select other than default action
399 ;; without pressing Tab.
402 ;; Using `anything-candidate-buffer' and the candidates-in-buffer
403 ;; attribute is much faster than traditional "candidates and match"
404 ;; way. And `anything-current-buffer-is-modified' avoids to
405 ;; recalculate candidates for unmodified buffer. See docstring of
406 ;; them.
408 ;; [EVAL IT] (describe-function 'anything-candidate-buffer)
409 ;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
410 ;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
413 ;; `anything-current-buffer' and `anything-buffer-file-name' stores
414 ;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
415 ;; is invoked. Use them freely.
417 ;; [EVAL IT] (describe-variable 'anything-current-buffer)
418 ;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
421 ;; `anything-completing-read' and `anything-read-file-name' are
422 ;; experimental implementation. If you are curious, type M-x
423 ;; anything-read-string-mode. It is a minor mode and toggles on/off.
426 ;; Use `anything-test-candidates' to test your handmade anything
427 ;; sources. It simulates contents of *anything* buffer with pseudo
428 ;; `anything-sources' and `anything-pattern', without side-effect. So
429 ;; you can unit-test your anything sources! Let's TDD!
431 ;; [EVAL IT] (describe-function 'anything-test-candidates)
433 ;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
434 ;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
436 ;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
437 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
438 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
441 ;; If you want to create anything sources, see anything-config.el.
442 ;; It is huge collection of sources. You can learn from examples.
445 ;; (@* "TODO")
447 ;; - process status indication
449 ;; - async sources doesn't honor digit-shortcut-count
451 ;; - anything-candidate-number-limit can't be nil everywhere
453 ;; (@* "HISTORY")
455 ;; Change log of this file is found at
456 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything.el
458 ;; Change log of this project is found at
459 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
461 (require 'cl)
462 ;; (require 'anything-match-plugin nil t)
464 ;; (@* "User Configuration")
466 ;; This is only an example. Customize it to your own taste!
467 (defvar anything-sources
468 `(((name . "Buffers")
469 (candidates
470 . (lambda ()
471 (remove-if (lambda (name)
472 (or (equal name anything-buffer)
473 (eq ?\ (aref name 0))))
474 (mapcar 'buffer-name (buffer-list)))))
475 (type . buffer))
477 ((name . "File Name History")
478 (candidates . file-name-history)
479 (match (lambda (candidate)
480 ;; list basename matches first
481 (string-match
482 anything-pattern
483 (file-name-nondirectory candidate)))
485 (lambda (candidate)
486 ;; and then directory part matches
487 (let ((dir (file-name-directory candidate)))
488 (if dir
489 (string-match anything-pattern dir)))))
490 (type . file))
492 ((name . "Files from Current Directory")
493 (init . (lambda ()
494 (setq anything-default-directory
495 default-directory)))
496 (candidates . (lambda ()
497 (directory-files
498 anything-default-directory)))
499 (type . file))
501 ((name . "Complex Command History")
502 (candidates . (lambda ()
503 (mapcar 'prin1-to-string
504 command-history)))
505 (action . (("Repeat Complex Command" .
506 (lambda (c)
507 (eval (read c))))))
508 (delayed)))
509 "The source of candidates for anything.
510 It accepts symbols:
511 (setq anything-sources (list anything-c-foo anything-c-bar))
512 can be written as
513 (setq anything-sources '(anything-c-foo anything-c-bar))
514 The latter is recommended because if you change anything-c-* variable,
515 you do not have to update `anything-sources'.
517 You are STRONGLY recommended to define a command which calls
518 `anything' or `anything-other-buffer' with argument rather than
519 to set `anything-sources' externally.
521 If you want to change `anything-sources' during `anything' invocation,
522 use `anything-set-sources', never use `setq'.
524 Attributes:
529 ;; This value is only provided as an example. Customize it to your own
530 ;; taste!
531 (defvar anything-type-attributes
532 '((file (action . (("Find File" . find-file)
533 ("Delete File" .
534 (lambda (file)
535 (if (y-or-n-p (format "Really delete file %s? " file))
536 (delete-file file)))))))
537 (buffer (action . (("Switch to Buffer" . switch-to-buffer)
538 ("Pop to Buffer" . pop-to-buffer)
539 ("Display Buffer" . display-buffer)
540 ("Kill Buffer" . kill-buffer)))))
541 "It's a list of (TYPE ATTRIBUTES ...). ATTRIBUTES are the same
542 as attributes for `anything-sources'. TYPE connects the value
543 to the appropriate sources in `anything-sources'.
545 This allows specifying common attributes for several
546 sources. For example, sources which provide files can specify
547 common attributes with a `file' type.")
550 (defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
551 "Alphabet shortcuts are usable now. Then `anything-enable-digit-shortcuts' should be renamed.
552 `anything-enable-digit-shortcuts' is retained for compatibility.")
553 (defvar anything-enable-shortcuts nil
554 "*Whether to use digit/alphabet shortcut to select the first nine matches.
555 If t then they can be selected using Ctrl+<number>.
557 If 'prefix then they can be selected using <prefix-key> <alnum>.
558 The prefix key is `anything-select-with-prefix-shortcut'.
559 If the <prefix-key> is a letter, pressing twice inputs the letter itself.
560 e.g.
561 (setq anything-enable-shortcuts 'prefix)
562 (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
564 If 'alphabet then they can be selected using Shift+<alphabet> (deprecated).
565 It is not recommended because you cannot input capital letters in pattern.
567 Keys (digit/alphabet) are listed in `anything-shortcut-keys-alist'.")
569 (defvar anything-shortcut-keys-alist
570 '((alphabet . "asdfghjklzxcvbnmqwertyuiop")
571 (prefix . "asdfghjklzxcvbnmqwertyuiop1234567890")
572 (t . "123456789")))
574 (defvar anything-display-source-at-screen-top t
575 "*If t, `anything-next-source' and `anything-previous-source'
576 display candidates at the top of screen.")
578 (defvar anything-candidate-number-limit 50
579 "*Do not show more candidates than this limit from individual
580 sources. It is usually pointless to show hundreds of matches
581 when the pattern is empty, because it is much simpler to type a
582 few characters to narrow down the list of potential candidates.
584 Set it to nil if you don't want this limit.")
587 (defvar anything-idle-delay 0.5
588 "*The user has to be idle for this many seconds, before
589 candidates from delayed sources are collected. This is useful
590 for sources involving heavy operations (like launching external
591 programs), so that candidates from the source are not retrieved
592 unnecessarily if the user keeps typing.
594 It also can be used to declutter the results anything displays,
595 so that results from certain sources are not shown with every
596 character typed, only if the user hesitates a bit.")
599 (defvar anything-input-idle-delay 0.1
600 "The user has to be idle for this many seconds, before ALL candidates are collected.
601 Unlink `anything-input-idle', it is also effective for non-delayed sources.
602 If nil, candidates are collected immediately. ")
605 (defvar anything-samewindow nil
606 "If t then Anything doesn't pop up a new window, it uses the
607 current window to show the candidates.")
610 (defvar anything-source-filter nil
611 "A list of source names to be displayed. Other sources won't
612 appear in the search results. If nil then there is no filtering.
613 See also `anything-set-source-filter'.")
616 (defvar anything-map
617 (let ((map (copy-keymap minibuffer-local-map)))
618 (define-key map (kbd "<down>") 'anything-next-line)
619 (define-key map (kbd "<up>") 'anything-previous-line)
620 (define-key map (kbd "C-n") 'anything-next-line)
621 (define-key map (kbd "C-p") 'anything-previous-line)
622 (define-key map (kbd "<prior>") 'anything-previous-page)
623 (define-key map (kbd "<next>") 'anything-next-page)
624 (define-key map (kbd "M-v") 'anything-previous-page)
625 (define-key map (kbd "C-v") 'anything-next-page)
626 (define-key map (kbd "M-<") 'anything-beginning-of-buffer)
627 (define-key map (kbd "M->") 'anything-end-of-buffer)
628 (define-key map (kbd "C-g") 'anything-keyboard-quit)
629 (define-key map (kbd "<right>") 'anything-next-source)
630 (define-key map (kbd "<left>") 'anything-previous-source)
631 (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
632 (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
633 (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
634 (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
635 (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
636 (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
637 (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
638 (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
639 (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
640 (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
641 (loop for c from ?A to ?Z do
642 (define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
643 (define-key map (kbd "C-i") 'anything-select-action)
644 (define-key map (kbd "C-z") 'anything-execute-persistent-action)
645 (define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
646 (define-key map (kbd "C-j") 'anything-select-3rd-action)
647 (define-key map (kbd "C-o") 'anything-next-source)
648 (define-key map (kbd "C-M-v") 'anything-scroll-other-window)
649 (define-key map (kbd "M-<next>") 'anything-scroll-other-window)
650 (define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
651 (define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
652 (define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
653 (define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
654 (define-key map (kbd "M-[") 'anything-prev-visible-mark)
655 (define-key map (kbd "M-]") 'anything-next-visible-mark)
656 (define-key map (kbd "C-k") 'anything-delete-minibuffer-contents)
658 (define-key map (kbd "C-s") 'anything-isearch)
659 (define-key map (kbd "C-r") 'undefined)
660 (define-key map (kbd "C-t") 'anything-toggle-resplit-window)
661 (define-key map (kbd "C-x C-f") 'anything-quit-and-find-file)
663 (define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
664 (define-key map (kbd "C-c C-y") 'anything-yank-selection)
665 (define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
666 (define-key map (kbd "C-c C-f") 'anything-follow-mode)
667 (define-key map (kbd "C-c C-u") 'anything-force-update)
669 ;; Debugging command
670 (define-key map "\C-c\C-x\C-d" 'anything-debug-output)
671 (define-key map "\C-c\C-x\C-m" 'anything-display-all-visible-marks)
672 (define-key map "\C-c\C-x\C-b" 'anything-send-bug-report-from-anything)
673 ;; Use `describe-mode' key in `global-map'
674 (dolist (k (where-is-internal 'describe-mode global-map))
675 (define-key map k 'anything-help))
676 ;; the defalias is needed because commands are bound by name when
677 ;; using iswitchb, so only commands having the prefix anything-
678 ;; get rebound
679 (defalias 'anything-previous-history-element 'previous-history-element)
680 (defalias 'anything-next-history-element 'next-history-element)
681 (define-key map (kbd "M-p") 'anything-previous-history-element)
682 (define-key map (kbd "M-n") 'anything-next-history-element)
683 map)
684 "Keymap for anything.
686 If you execute `anything-iswitchb-setup', some keys are modified.
687 See `anything-iswitchb-setup-keys'.")
689 (defvar anything-isearch-map
690 (let ((map (make-sparse-keymap)))
691 (set-keymap-parent map (current-global-map))
692 (define-key map (kbd "<return>") 'anything-isearch-default-action)
693 (define-key map (kbd "<RET>") 'anything-isearch-default-action)
694 (define-key map (kbd "C-i") 'anything-isearch-select-action)
695 (define-key map (kbd "C-g") 'anything-isearch-cancel)
696 (define-key map (kbd "M-s") 'anything-isearch-again)
697 (define-key map (kbd "<backspace>") 'anything-isearch-delete)
698 ;; add printing chars
699 (loop for i from 32 below 256 do
700 (define-key map (vector i) 'anything-isearch-printing-char))
701 map)
702 "Keymap for anything incremental search.")
705 (defgroup anything nil
706 "Open anything." :prefix "anything-" :group 'convenience)
708 (defface anything-header
709 '((t (:inherit header-line)))
710 "Face for header lines in the anything buffer." :group 'anything)
712 (defvar anything-header-face 'anything-header
713 "Face for header lines in the anything buffer.")
715 (defface anything-isearch-match '((t (:background "Yellow")))
716 "Face for isearch in the anything buffer." :group 'anything)
718 (defvar anything-isearch-match-face 'anything-isearch-match
719 "Face for matches during incremental search.")
721 (defvar anything-selection-face 'highlight
722 "Face for currently selected item.")
724 (defvar anything-iswitchb-idle-delay 1
725 "Show anything completions if the user is idle that many
726 seconds after typing.")
728 (defvar anything-iswitchb-dont-touch-iswithcb-keys nil
729 "If t then those commands are not bound from `anything-map'
730 under iswitchb which would override standard iswithcb keys.
732 This allows an even more seamless integration with iswitchb for
733 those who prefer using iswitchb bindings even if the anything
734 completions buffer is popped up.
736 Note that you can bind alternative keys for the same command in
737 `anything-map', so that you can use different keys for anything
738 under iswitchb. For example, I bind the character \ to
739 `anything-exit-minibuffer' which key is just above Enter on my
740 keyboard. This way I can switch buffers with Enter and choose
741 anything completions with \.")
743 ;;----------------------------------------------------------------------
745 (defvar anything-buffer "*anything*"
746 "Buffer showing completions.")
748 (defvar anything-action-buffer "*anything action*"
749 "Buffer showing actions.")
751 (defvar anything-selection-overlay nil
752 "Overlay used to highlight the currently selected item.")
754 (defvar anything-isearch-overlay nil
755 "Overlay used to highlight the current match during isearch.")
757 (defvar anything-digit-overlays nil
758 "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
760 (defvar anything-candidate-cache nil
761 "Holds the available candidate withing a single anything invocation.")
763 (defvar anything-pattern
764 "The input pattern used to update the anything buffer.")
766 (defvar anything-input
767 "The input typed in the candidates panel.")
769 (defvar anything-async-processes nil
770 "List of information about asynchronous processes managed by anything.")
772 (defvar anything-digit-shortcut-count 0
773 "Number of digit shortcuts shown in the anything buffer.")
775 (defvar anything-before-initialize-hook nil
776 "Run before anything initialization.
777 This hook is run before init functions in `anything-sources'.")
779 (defvar anything-after-initialize-hook nil
780 "Run after anything initialization.
781 Global variables are initialized and the anything buffer is created.
782 But the anything buffer has no contents. ")
784 (defvar anything-update-hook nil
785 "Run after the anything buffer was updated according the new input pattern.
786 This hook is run at the beginning of buffer.
787 The first candidate is selected after running this hook.
788 See also `anything-after-update-hook'.")
790 (defvar anything-after-update-hook nil
791 "Run after the anything buffer was updated according the new input pattern.
792 This is very similar to `anything-update-hook' but selection is not moved.
793 It is useful to select a particular object instead of the first one. ")
795 (defvar anything-cleanup-hook nil
796 "Run after anything minibuffer is closed, IOW this hook is executed BEFORE performing action. ")
798 (defvar anything-after-action-hook nil
799 "Run after executing action.")
801 (defvar anything-after-persistent-action-hook nil
802 "Run after executing persistent action.")
804 (defvar anything-restored-variables
805 '( anything-candidate-number-limit
806 anything-source-filter
807 anything-source-in-each-line-flag
808 anything-map
809 anything-sources
810 deferred-action-list)
811 "Variables which are restored after `anything' invocation.")
812 ;; `anything-saved-sources' is removed
814 (defvar anything-saved-selection nil
815 "Saved value of the currently selected object when the action
816 list is shown.")
818 ;; `anything-original-source-filter' is removed
820 (defvar anything-candidate-separator
821 "--------------------"
822 "Candidates separator of `multiline' source.")
824 (defvar anything-current-buffer nil
825 "Current buffer when `anything' is invoked.")
827 (defvar anything-buffer-file-name nil
828 "`buffer-file-name' when `anything' is invoked.")
830 (defvar anything-saved-action nil
831 "Saved value of the currently selected action by key.")
833 (defvar anything-last-sources nil
834 "OBSOLETE!! Sources of previously invoked `anything'.")
836 (defvar anything-saved-current-source nil
837 "Saved value of the original (anything-get-current-source) when the action
838 list is shown.")
840 (defvar anything-compiled-sources nil
841 "Compiled version of `anything-sources'. ")
843 (defvar anything-in-persistent-action nil
844 "Flag whether in persistent-action or not.")
846 (defvar anything-quick-update nil
847 "If non-nil, suppress displaying sources which are out of screen at first.
848 They are treated as delayed sources at this input.
849 This flag makes `anything' a bit faster with many sources.")
851 (defvar anything-last-sources-local nil
852 "Buffer local value of `anything-sources'.")
853 (defvar anything-last-buffer nil
854 "`anything-buffer' of previously `anything' session.")
856 (defvar anything-save-configuration-functions
857 '(set-window-configuration . current-window-configuration)
858 "If you want to save and restore frame configuration, set this variable to
859 '(set-frame-configuration . current-frame-configuration)
861 Older version saves/restores frame configuration, but the default is changed now,
862 because flickering is occurred in some environment.
865 (defvar anything-persistent-action-use-special-display nil
866 "If non-nil, use `special-display-function' in persistent action.")
868 (defvar anything-execute-action-at-once-if-one nil
869 "If non-nil and there is one candidate, execute the first action without selection.
870 It is useful for `anything' applications.")
872 (defvar anything-quit-if-no-candidate nil
873 "if non-nil and there is no candidate, do not display *anything* buffer and quit.
874 This variable accepts a function, which is executed if no candidate.
876 It is useful for `anything' applications.")
878 (defvar anything-scroll-amount nil
879 "Scroll amount used by `anything-scroll-other-window' and `anything-scroll-other-window-down'.
880 If you prefer scrolling line by line, set this value to 1.")
882 (defvar anything-display-function 'anything-default-display-buffer
883 "Function to display *anything* buffer.
884 It is `anything-default-display-buffer' by default, which affects `anything-samewindow'.")
886 (defvar anything-delayed-init-executed nil)
888 (defvar anything-mode-line-string "\\<anything-map>\\[anything-help]:help \\[anything-select-action]:Acts \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\\[anything-select-3rd-action]:NthAct \\[anything-send-bug-report-from-anything]:BugReport"
889 "Help string displayed in mode-line in `anything'.
890 If nil, use default `mode-line-format'.")
892 (defvar anything-help-message
893 "\\<anything-map>The keys that are defined for `anything' are:
894 \\{anything-map}"
895 "Detailed help message string for `anything'.
896 It also accepts function or variable symbol.")
898 (put 'anything 'timid-completion 'disabled)
900 (defvar anything-inhibit-fit-frame-flag t
901 "If non-nil, inhibit fitting anything frame to its buffer.
902 It is nil by default because some flickering occurred in some environment.
904 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
905 `fit-frame-inhibit-fitting' to nil.")
907 (defvar anything-source-in-each-line-flag nil
908 "If non-nil, add anything-source text-property in each candidate.
909 experimental feature.")
911 (defvaralias 'anything-debug-variables 'anything-debug-forms)
912 (defvar anything-debug-forms nil
913 "Forms to show in `anything-debug-output'.
914 Otherwise all variables started with `anything-' are shown.
915 It is useful for debug.")
917 (defvar anything-debug nil
918 "If non-nil, write log message into *Anything Log* buffer.
919 If `debug-on-error' is non-nil, write log message regardless of this variable.
920 It is disabled by default because *Anything Log* grows quickly.")
922 ;; (@* "Internal Variables")
923 (defvar anything-test-candidate-list nil)
924 (defvar anything-test-mode nil)
925 (defvar anything-source-name nil)
926 (defvar anything-candidate-buffer-alist nil)
927 (defvar anything-check-minibuffer-input-timer nil)
928 (defvar anything-match-hash (make-hash-table :test 'equal))
929 (defvar anything-cib-hash (make-hash-table :test 'equal))
930 (defvar anything-tick-hash (make-hash-table :test 'equal))
931 (defvar anything-issued-errors nil)
932 (defvar anything-shortcut-keys nil)
933 (defvar anything-once-called-functions nil)
934 (defvar anything-follow-mode nil)
935 (defvar anything-let-variables nil)
937 ;; (@* "Utility: logging")
938 (defun anything-log (format-string &rest args)
939 "Log message if `debug-on-error' or `anything-debug' is non-nil.
940 Messages are written to the *Anythingn Log* buffer.
941 Arguments are same as `format'."
942 (when (or debug-on-error anything-debug)
943 (with-current-buffer (get-buffer-create "*Anything Log*")
944 (buffer-disable-undo)
945 (set (make-local-variable 'inhibit-read-only) t)
946 (goto-char (point-max))
947 (insert (let ((tm (current-time)))
948 (format "%s.%06d (%s) %s\n"
949 (format-time-string "%H:%M:%S" tm)
950 (nth 2 tm)
951 (anything-log-get-current-function)
952 (apply #'format (cons format-string args))))))))
953 (defmacro anything-log-eval (&rest exprs)
954 "Write each EXPR evaluation result to the *Anything Log* buffer."
955 `(anything-log-eval-internal ',exprs))
956 (defun anything-log-run-hook (hook)
957 (anything-log "executing %s" hook)
958 (when (boundp hook)
959 (anything-log-eval (symbol-value hook))
960 (anything-log-eval (default-value hook)))
961 (run-hooks hook)
962 (anything-log "executed %s" hook))
963 (defun anything-log-eval-internal (exprs)
964 (dolist (expr exprs)
965 (condition-case err
966 (anything-log "%S = %S" expr (eval expr))
967 (error (anything-log "%S = ERROR!" expr)))))
968 (defun anything-log-get-current-function ()
969 "Get function name calling `anything-log'.
970 The original idea is from `tramp-debug-message'."
971 (loop with exclude-func-re = "^anything-\\(?:interpret\\|log\\|.*funcall\\)"
972 for btn from 1 to 40 ;avoid inf-loop
973 for btf = (second (backtrace-frame btn))
974 for fn = (if (symbolp btf) (symbol-name btf) "")
975 if (and (string-match "^anything" fn)
976 (not (string-match exclude-func-re fn)))
977 return fn))
979 (defun anything-log-error (&rest args)
980 "Accumulate error messages into `anything-issued-errors'."
981 (apply 'anything-log (concat "ERROR: " (car args)) (cdr args))
982 (let ((msg (apply 'format args)))
983 (unless (member msg anything-issued-errors)
984 (add-to-list 'anything-issued-errors msg))))
986 (defvar anything-last-log-file nil)
987 (defun anything-log-save-maybe ()
988 (when (stringp anything-debug)
989 (let ((logdir (expand-file-name (format-time-string "%Y%m%d")
990 anything-debug)))
991 (make-directory logdir t)
992 (with-current-buffer (get-buffer-create "*Anything Log*")
993 (write-region (point-min) (point-max)
994 (setq anything-last-log-file
995 (expand-file-name (format-time-string "%Y%m%d-%H%M%S")
996 logdir))
997 nil 'silent)
998 (erase-buffer)))))
1000 (defun anything-open-last-log ()
1001 "Open anything log file of last anything session."
1002 (interactive)
1003 (if anything-last-log-file
1004 (view-file anything-last-log-file)
1005 (switch-to-buffer "*Anything Log*")))
1007 (defun anything-print-error-messages ()
1008 "Print error messages in `anything-issued-errors'."
1009 (message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))
1014 ;; (anything-log "test")
1015 ;; (switch-to-buffer-other-window "*Anything Log*")
1017 ;; (@* "Programming Tools")
1018 (defmacro anything-aif (test-form then-form &rest else-forms)
1019 "Anaphoric if. Temporary variable `it' is the result of test-form."
1020 `(let ((it ,test-form))
1021 (if it ,then-form ,@else-forms)))
1022 (put 'anything-aif 'lisp-indent-function 2)
1024 (defun anything-mklist (obj)
1025 "If OBJ is a list (but not lambda), return itself, otherwise make a list with one element."
1026 (if (and (listp obj) (not (functionp obj)))
1028 (list obj)))
1030 ;; (@* "Anything API")
1031 (defmacro anything-let (varlist &rest body)
1032 "[OBSOLETE] Like `let'. Bind anything buffer local variables according to VARLIST then eval BODY."
1033 `(anything-let-internal (anything-let-eval-varlist ',varlist)
1034 (lambda () ,@body)))
1035 (put 'anything-let 'lisp-indent-function 1)
1037 (defmacro anything-let* (varlist &rest body)
1038 "[OBSOLETE] Like `let*'. Bind anything buffer local variables according to VARLIST then eval BODY."
1039 `(anything-let-internal (anything-let*-eval-varlist ',varlist)
1040 (lambda () ,@body)))
1041 (put 'anything-let* 'lisp-indent-function 1)
1043 (defun anything-buffer-get ()
1044 "If *anything action* buffer is shown, return `anything-action-buffer', otherwise `anything-buffer'."
1045 (if (anything-action-window)
1046 anything-action-buffer
1047 anything-buffer))
1049 (defun anything-window ()
1050 "Window of `anything-buffer'."
1051 (get-buffer-window (anything-buffer-get) 'visible))
1053 (defun anything-action-window ()
1054 "Window of `anything-action-buffer'."
1055 (get-buffer-window anything-action-buffer 'visible))
1057 (defmacro with-anything-window (&rest body)
1058 `(let ((--tmpfunc-- (lambda () ,@body)))
1059 (if anything-test-mode
1060 (with-current-buffer (anything-buffer-get)
1061 (funcall --tmpfunc--))
1062 (with-selected-window (anything-window)
1063 (funcall --tmpfunc--)))))
1064 (put 'with-anything-window 'lisp-indent-function 0)
1066 (defun anything-deferred-action-function ()
1067 (dolist (f deferred-action-list) (funcall f)))
1068 (defmacro with-anything-restore-variables(&rest body)
1069 "Restore variables specified by `anything-restored-variables' after executing BODY . "
1070 `(let ((--orig-vars (mapcar (lambda (v) (cons v (symbol-value v)))
1071 anything-restored-variables))
1072 (deferred-action-function 'anything-deferred-action-function))
1073 (anything-log "save variables: %S" --orig-vars)
1074 (unwind-protect (progn ,@body)
1075 (loop for (var . value) in --orig-vars
1076 do (set var value))
1077 (anything-log "restore variables"))))
1078 (put 'with-anything-restore-variables 'lisp-indent-function 0)
1080 (defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
1081 "Get the value of ATTRIBUTE-NAME of SRC (source).
1082 if SRC is omitted, use current source.
1083 It is useful to write your sources."
1084 (anything-aif (assq attribute-name src)
1085 (cdr it)))
1087 (defun* anything-attr* (attribute-name &optional (src (anything-get-current-source)))
1088 "Get the value of ATTRIBUTE-NAME of SRC (source) and pass to `anything-interpret-value'.
1089 if SRC is omitted, use current source.
1090 It is useful to write your sources."
1091 (anything-interpret-value (anything-attr attribute-name src)))
1093 (defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
1094 "Return non-nil if ATTRIBUTE-NAME of SRC (source) is defined.
1095 if SRC is omitted, use current source.
1096 It is useful to write your sources."
1097 (and (assq attribute-name src) t))
1099 (defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
1100 "Set the value of ATTRIBUTE-NAME of SRC (source) to VALUE.
1101 if SRC is omitted, use current source.
1102 It is useful to write your sources."
1103 (anything-aif (assq attribute-name src)
1104 (setcdr it value)
1105 (setcdr src (cons (cons attribute-name value) (cdr src))))
1106 value)
1108 ;; anything-set-source-filter
1110 ;; This function sets a filter for anything sources and it may be
1111 ;; called while anything is running. It can be used to toggle
1112 ;; displaying of sources dinamically. For example, additional keys
1113 ;; can be bound into `anything-map' to display only the file-related
1114 ;; results if there are too many matches from other sources and
1115 ;; you're after files only:
1117 ;; Shift+F shows only file results from some sources:
1119 ;; (define-key anything-map "F" 'anything-my-show-files-only)
1121 ;; (defun anything-my-show-files-only ()
1122 ;; (interactive)
1123 ;; (anything-set-source-filter '("File Name History"
1124 ;; "Files from Current Directory")))
1126 ;; Shift+A shows all results:
1128 ;; (define-key anything-map "A" 'anything-my-show-all)
1130 ;; (defun anything-my-show-all ()
1131 ;; (interactive)
1132 ;; (anything-set-source-filter nil))
1135 ;; Note that you have to prefix the functions with anything- prefix,
1136 ;; otherwise they won't be bound when Anything is used under
1137 ;; Iswitchb. The -my- part is added to avoid collisions with
1138 ;; existing Anything function names.
1140 (defun anything-set-source-filter (sources)
1141 "Sets the value of `anything-source-filter' and updates the list of results."
1142 (unless (and (listp sources)
1143 (loop for name in sources always (stringp name)))
1144 (error "invalid data in `anything-set-source-filter': %S" sources))
1145 (setq anything-source-filter sources)
1146 (anything-log-eval anything-source-filter)
1147 (anything-update))
1149 (defun anything-set-sources (sources &optional no-init no-update)
1150 "Set `anything-sources' during `anything' invocation.
1151 If NO-INIT is non-nil, skip executing init functions of SOURCES.
1152 If NO-UPDATE is non-nil, skip executing `anything-update'."
1153 (with-current-buffer anything-buffer
1154 (setq anything-compiled-sources nil
1155 anything-sources sources
1156 anything-last-sources-local sources)
1157 (anything-log-eval anything-compiled-sources anything-sources))
1158 (unless no-init (anything-funcall-foreach 'init))
1159 (unless no-update (anything-update)))
1161 (defvar anything-compile-source-functions
1162 '(anything-compile-source--type
1163 anything-compile-source--dummy
1164 anything-compile-source--disable-shortcuts
1165 anything-compile-source--candidates-in-buffer)
1166 "Functions to compile elements of `anything-sources' (plug-in).")
1168 (defun anything-get-sources ()
1169 "Return compiled `anything-sources', which is memoized.
1171 Attributes:
1173 - type
1174 `anything-type-attributes' are merged in.
1175 - candidates-buffer
1176 candidates, volatile and match attrubute are created.
1178 (cond
1179 ;; action
1180 ((anything-action-window)
1181 anything-sources)
1182 ;; memoized
1183 (anything-compiled-sources)
1184 ;; first time
1186 (prog1
1187 (setq anything-compiled-sources
1188 (anything-compile-sources
1189 anything-sources anything-compile-source-functions))
1190 (anything-log-eval anything-compiled-sources)))))
1192 (defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
1193 "Return the currently selected item or nil.
1194 if BUFFER is nil or unspecified, use anything-buffer as default value.
1195 If FORCE-DISPLAY-PART is non-nil, return the display string."
1196 (setq buffer (if (and buffer buffer-s) buffer anything-buffer))
1197 (unless (anything-empty-buffer-p buffer)
1198 (with-current-buffer buffer
1199 (let ((selection
1200 (or (and (not force-display-part)
1201 (get-text-property (overlay-start
1202 anything-selection-overlay)
1203 'anything-realvalue))
1204 (let ((disp (buffer-substring-no-properties
1205 (overlay-start anything-selection-overlay)
1206 (1- (overlay-end anything-selection-overlay))))
1207 (source (anything-get-current-source)))
1208 (anything-aif (and (not force-display-part)
1209 (assoc-default 'display-to-real source))
1210 (anything-funcall-with-source source it disp)
1211 disp)))))
1212 (unless (equal selection "")
1213 (anything-log-eval selection)
1214 selection)))))
1216 (defun anything-get-action ()
1217 "Return the associated action for the selected candidate.
1218 It is a function symbol (sole action) or list of (action-display . function)."
1219 (unless (anything-empty-buffer-p (anything-buffer-get))
1220 (anything-aif (anything-attr 'action-transformer)
1221 (anything-composed-funcall-with-source
1222 (anything-get-current-source) it
1223 (anything-attr 'action) (anything-get-selection))
1224 (anything-attr 'action))))
1226 (defun anything-get-current-source ()
1227 "Return the source for the current selection / in init/candidates/action/candidate-transformer/filtered-candidate-transformer function."
1228 (declare (special source))
1229 ;; The name `anything-get-current-source' should be used in init function etc.
1230 (if (and (boundp 'anything-source-name) (stringp anything-source-name))
1231 source
1232 (with-current-buffer (anything-buffer-get)
1233 (or (get-text-property (point) 'anything-source)
1234 (block exit
1235 ;; This goto-char shouldn't be necessary, but point is moved to
1236 ;; point-min somewhere else which shouldn't happen.
1237 (goto-char (overlay-start anything-selection-overlay))
1238 (let* ((header-pos (or (anything-get-previous-header-pos)
1239 (anything-get-next-header-pos)))
1240 (source-name
1241 (save-excursion
1242 (unless header-pos
1243 ;(message "No candidates")
1244 (return-from exit nil))
1245 (goto-char header-pos)
1246 (anything-current-line-contents))))
1247 (some (lambda (source)
1248 (if (equal (assoc-default 'name source) source-name)
1249 source))
1250 (anything-get-sources))))))))
1252 (defun anything-buffer-is-modified (buffer)
1253 "Return non-nil when BUFFER is modified since `anything' was invoked."
1254 (let* ((b (get-buffer buffer))
1255 (key (concat (buffer-name b) "/" (anything-attr 'name)))
1256 (source-tick (or (gethash key anything-tick-hash) 0))
1257 (buffer-tick (buffer-chars-modified-tick b))
1258 (modifiedp (/= source-tick buffer-tick)))
1259 (puthash key buffer-tick anything-tick-hash)
1260 (anything-log-eval buffer modifiedp)
1261 modifiedp))
1262 (defun anything-current-buffer-is-modified ()
1263 "Return non-nil when `anything-current-buffer' is modified since `anything' was invoked."
1264 (anything-buffer-is-modified anything-current-buffer))
1266 (defvar anything-quit nil)
1267 (defun anything-run-after-quit (function &rest args)
1268 "Perform an action after quitting `anything'.
1269 The action is to call FUNCTION with arguments ARGS."
1270 (setq anything-quit t)
1271 (anything-log-eval function args)
1272 (apply 'run-with-idle-timer 0 nil function args)
1273 (anything-exit-minibuffer))
1276 (defun define-anything-type-attribute (type definition &optional doc)
1277 "Register type attribute of TYPE as DEFINITION with DOC.
1278 DOC is displayed in `anything-type-attributes' docstring.
1280 Use this function is better than setting `anything-type-attributes' directly."
1281 (loop for i in definition do
1282 ;; without `ignore-errors', error at emacs22
1283 (ignore-errors (setf i (delete nil i))))
1284 (anything-add-type-attribute type definition)
1285 (and doc (anything-document-type-attribute type doc))
1286 nil)
1288 (defvaralias 'anything-attributes 'anything-additional-attributes)
1289 (defvar anything-additional-attributes nil
1290 "List of all `anything' attributes.")
1291 (defun anything-document-attribute (attribute short-doc &optional long-doc)
1292 "Register ATTRIBUTE documentation introduced by plug-in.
1293 SHORT-DOC is displayed beside attribute name.
1294 LONG-DOC is displayed below attribute name and short documentation."
1295 (if long-doc
1296 (setq short-doc (concat "(" short-doc ")"))
1297 (setq long-doc short-doc
1298 short-doc ""))
1299 (add-to-list 'anything-additional-attributes attribute t)
1300 (put attribute 'anything-attrdoc
1301 (concat "- " (symbol-name attribute) " " short-doc "\n\n" long-doc "\n")))
1302 (put 'anything-document-attribute 'lisp-indent-function 2)
1304 (defun anything-require-at-least-version (version)
1305 "Output error message unless anything.el is older than VERSION.
1306 This is suitable for anything applications."
1307 (when (and (string= "1." (substring version 0 2))
1308 (string-match "1\.\\([0-9]+\\)" anything-version)
1309 (< (string-to-number (match-string 1 anything-version))
1310 (string-to-number (substring version 2))))
1311 (error "Please update anything.el!!
1313 M-x auto-install-batch anything
1315 You must have auto-install.el too.
1316 http://www.emacswiki.org/cgi-bin/wiki/download/auto-install.el
1317 ")))
1319 (defun anything-interpret-value (value &optional source)
1320 "interpret VALUE as variable, function or literal.
1321 If VALUE is a function, call it with no arguments and return the value.
1322 If SOURCE is `anything' source, `anything-source-name' is source name.
1324 If VALUE is a variable, return the value.
1326 If VALUE is a symbol, but it is not a function or a variable, cause an error.
1328 Otherwise, return VALUE itself."
1329 (cond ((and source (functionp value))
1330 (anything-funcall-with-source source value))
1331 ((functionp value)
1332 (funcall value))
1333 ((and (symbolp value) (boundp value))
1334 (symbol-value value))
1335 ((symbolp value)
1336 (error "anything-interpret-value: Symbol must be a function or a variable"))
1338 value)))
1340 (defun anything-once (function &rest args)
1341 "Ensure FUNCTION with ARGS to be called once in `anything' session."
1342 (let ((spec (cons function args)))
1343 (unless (member spec anything-once-called-functions)
1344 (apply function args)
1345 (push spec anything-once-called-functions))))
1347 ;; (@* "Core: API helper")
1348 (defun anything-empty-buffer-p (&optional buffer)
1349 (zerop (buffer-size (and buffer (get-buffer buffer)))))
1351 (defun anything-let-eval-varlist (varlist)
1352 (mapcar (lambda (pair)
1353 (if (listp pair)
1354 (cons (car pair) (eval (cadr pair)))
1355 (cons pair nil)))
1356 varlist))
1357 (defun anything-let*-eval-varlist (varlist)
1358 (let ((vars (mapcar (lambda (pair) (or (car-safe pair) pair)) varlist)))
1359 (eval `(let ,vars
1360 ,@(mapcar (lambda (pair)
1361 (if (listp pair)
1362 `(setq ,(car pair) ,(cadr pair))
1363 `(setq ,pair nil)))
1364 varlist)
1365 (mapcar (lambda (v) (cons v (symbol-value v))) ',vars)))))
1366 (defun anything-let-internal (binding bodyfunc)
1367 "Evaluate BODYFUNC and Set BINDING to anything buffer-local variables.
1368 BINDING is a list of (VARNAME . VALUE) pair."
1369 (setq anything-let-variables binding)
1370 (unwind-protect
1371 (funcall bodyfunc)
1372 (setq anything-let-variables nil)))
1375 ;; (@* "Core: tools")
1376 (defun anything-current-line-contents ()
1377 "Current line strig without properties."
1378 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1380 (defun anything-funcall-with-source (source func &rest args)
1381 "Call FUNC with ARGS with variable `anything-source-name' and `source' is bound.
1382 FUNC can be function list. Return the result of last function call."
1383 (let ((anything-source-name (assoc-default 'name source))
1384 result)
1385 (anything-log-eval anything-source-name func args)
1386 (dolist (func (if (functionp func) (list func) func) result)
1387 (setq result (apply func args)))))
1389 (defun anything-funcall-foreach (sym)
1390 "Call the sym function(s) for each source if any."
1391 (dolist (source (anything-get-sources))
1392 (anything-aif (assoc-default sym source)
1393 (anything-funcall-with-source source it))))
1395 (defun anything-normalize-sources (sources)
1396 "If SOURCES is only one source, make a list."
1397 (cond ((or (and sources ; avoid nil
1398 (symbolp sources))
1399 (and (listp sources) (assq 'name sources)))
1400 (list sources))
1401 (sources)
1402 (t anything-sources)))
1404 (defun anything-approximate-candidate-number ()
1405 "Approximate Number of candidates.
1406 It is used to check if candidate number is 0, 1, or 2+."
1407 (with-current-buffer anything-buffer
1408 (let ((lines (1- (line-number-at-pos (1- (point-max))))))
1409 (if (zerop lines)
1411 (save-excursion
1412 (goto-char (point-min))
1413 (forward-line 1)
1414 (if (anything-pos-multiline-p)
1415 (if (search-forward anything-candidate-separator nil t) 2 1)
1416 lines))))))
1418 (defmacro with-anything-quittable (&rest body)
1419 `(let (inhibit-quit)
1420 (condition-case v
1421 (progn ,@body)
1422 (quit (setq anything-quit t)
1423 (exit-minibuffer)
1424 (keyboard-quit)))))
1425 (put 'with-anything-quittable 'lisp-indent-function 0)
1427 (defun anything-compose (arg-lst func-lst)
1428 "Call each function in FUNC-LST with the arguments specified in ARG-LST.
1429 The result of each function will be the new `car' of ARG-LST.
1431 This function allows easy sequencing of transformer functions."
1432 (dolist (func func-lst)
1433 (setcar arg-lst (apply func arg-lst)))
1434 (car arg-lst))
1436 (defun anything-composed-funcall-with-source (source funcs &rest args)
1437 (if (functionp funcs)
1438 (apply 'anything-funcall-with-source source funcs args)
1439 (apply 'anything-funcall-with-source
1440 source (lambda (&rest args) (anything-compose args funcs)) args)))
1442 (defun anything-new-timer (variable timer)
1443 "Set new TIMER to VARIABLE. Old timer is cancelled."
1444 (anything-aif (symbol-value variable)
1445 (cancel-timer it))
1446 (set variable timer))
1448 ;; (@* "Core: entry point")
1449 (defconst anything-argument-keys
1450 '(:sources :input :prompt :resume :preselect :buffer :keymap))
1451 ;;;###autoload
1452 (defun anything (&rest plist)
1453 "Select anything. In Lisp program, some optional arguments can be used.
1455 PLIST is a list like (:key1 val1 :key2 val2 ...) or
1456 (&optional sources input prompt resume preselect buffer keymap).
1458 Basic keywords are the following:
1460 - :sources
1462 Temporary value of `anything-sources'. It also accepts a
1463 symbol, interpreted as a variable of an anything source. It
1464 also accepts an alist representing an anything source, which is
1465 detected by (assq 'name ANY-SOURCES)
1467 - :input
1469 Temporary value of `anything-pattern', ie. initial input of minibuffer.
1471 - :prompt
1473 Prompt other than \"pattern: \".
1475 - :resume
1477 If t, Resurrect previously instance of `anything'. Skip the initialization.
1478 If 'noresume, this instance of `anything' cannot be resumed.
1480 - :preselect
1482 Initially selected candidate. Specified by exact candidate or a regexp.
1483 Note that it is not working with delayed sources.
1485 - :buffer
1487 `anything-buffer' instead of *anything*.
1489 - :keymap
1491 `anything-map' for current `anything' session.
1494 Of course, conventional arguments are supported, the two are same.
1496 (anything :sources sources :input input :prompt prompt :resume resume
1497 :preselect preselect :buffer buffer :keymap keymap)
1498 (anything sources input prompt resume preselect buffer keymap)
1501 Other keywords are interpreted as local variables of this anything session.
1502 The `anything-' prefix can be omitted. For example,
1504 (anything :sources 'anything-c-source-buffers
1505 :buffer \"*buffers*\" :candidate-number-limit 10)
1507 means starting anything session with `anything-c-source-buffers'
1508 source in *buffers* buffer and set
1509 `anything-candidate-number-limit' to 10 as session local variable. "
1510 (interactive)
1511 (if (keywordp (car plist))
1512 (anything-let-internal
1513 (anything-parse-keys plist)
1514 (lambda ()
1515 (apply 'anything
1516 (mapcar (lambda (key) (plist-get plist key))
1517 anything-argument-keys))))
1518 (apply 'anything-internal plist)))
1520 (defun* anything-resume (&optional (any-buffer anything-last-buffer) buffer-pattern (any-resume t))
1521 "Resurrect previously invoked `anything'."
1522 (interactive)
1523 (when (or current-prefix-arg buffer-pattern)
1524 (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
1525 (setq anything-compiled-sources nil)
1526 (anything
1527 (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
1528 anything-last-sources anything-sources)
1529 (buffer-local-value 'anything-input-local (get-buffer any-buffer))
1530 nil any-resume nil any-buffer))
1532 ;;; rubikitch: experimental
1533 ;;; I use this and check it whether I am convenient.
1534 ;;; I may introduce an option to control the behavior.
1535 (defun* anything-resume-window-only (&optional (any-buffer anything-last-buffer) buffer-pattern)
1536 (interactive)
1537 (anything-resume any-buffer buffer-pattern 'window-only))
1539 ;;;###autoload
1540 (defun anything-at-point (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
1541 "Same as `anything' except when C-u is pressed, the initial input is the symbol at point."
1542 (interactive)
1543 (anything any-sources
1544 (if current-prefix-arg
1545 (concat "\\b" (thing-at-point 'symbol) "\\b"
1546 (if (featurep 'anything-match-plugin) " " ""))
1547 any-input)
1548 any-prompt any-resume any-preselect any-buffer))
1550 ;;;###autoload
1551 (defun anything-other-buffer (any-sources any-buffer)
1552 "Simplified interface of `anything' with other `anything-buffer'"
1553 (anything any-sources nil nil nil nil any-buffer))
1555 ;;; (@* "Core: entry point helper")
1556 (defun anything-internal (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap)
1557 "Older interface of `anything'. It is called by `anything'."
1558 (anything-log "++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
1559 (anything-log-eval any-prompt any-preselect any-buffer any-keymap)
1560 (unwind-protect
1561 (condition-case v
1562 (let ( ;; It is needed because `anything-source-name' is non-nil
1563 ;; when `anything' is invoked by action. Awful global scope.
1564 anything-source-name
1565 anything-in-persistent-action
1566 anything-quit
1567 (case-fold-search t)
1568 (anything-buffer (or any-buffer anything-buffer))
1569 ;; cua-mode ; avoid error when region is selected
1571 (with-anything-restore-variables
1572 (anything-initialize-1 any-resume any-input any-sources)
1573 (anything-display-buffer anything-buffer)
1574 (anything-log "show prompt")
1575 (unwind-protect
1576 (anything-read-pattern-maybe
1577 any-prompt any-input any-preselect any-resume any-keymap)
1578 (anything-cleanup)))
1579 (prog1 (unless anything-quit (anything-execute-selection-action-1))
1580 (anything-log "end session --------------------------------------------")))
1581 (quit
1582 (anything-on-quit)
1583 (anything-log "end session (quit) -------------------------------------")
1584 nil))
1585 (anything-log-save-maybe)))
1589 (defun anything-parse-keys (keys)
1590 (loop for (key value &rest _) on keys by #'cddr
1591 for symname = (substring (symbol-name key) 1)
1592 for sym = (intern (if (string-match "^anything-" symname)
1593 symname
1594 (concat "anything-" symname)))
1595 unless (memq key anything-argument-keys)
1596 collect (cons sym value)))
1598 (defun anything-resume-p (any-resume)
1599 "Whethre current anything session is resumed or not."
1600 (memq any-resume '(t window-only)))
1602 (defvar anything-buffers nil
1603 "All of `anything-buffer' in most recently used order.")
1604 (defun anything-initialize-1 (any-resume any-input any-sources)
1605 "The real initialization of `anything'.
1607 This function name should be `anything-initialize', but anything
1608 extensions may advice `anything-initalize'. I cannot rename, sigh."
1609 (anything-log "start initialization: any-resume=%S any-input=%S" any-resume any-input)
1610 (anything-frame/window-configuration 'save)
1611 (setq anything-sources (anything-normalize-sources any-sources))
1612 (anything-log "sources = %S" anything-sources)
1613 (anything-hooks 'setup)
1614 (anything-current-position 'save)
1615 (if (anything-resume-p any-resume)
1616 (anything-initialize-overlays (anything-buffer-get))
1617 (anything-initialize))
1618 (unless (eq any-resume 'noresume)
1619 (anything-recent-push anything-buffer 'anything-buffers)
1620 (setq anything-last-buffer anything-buffer))
1621 (when any-input (setq anything-input any-input anything-pattern any-input))
1622 (and (anything-resume-p any-resume) (anything-funcall-foreach 'resume))
1623 (anything-log "end initialization"))
1625 (defun anything-execute-selection-action-1 ()
1626 (unwind-protect
1627 (anything-execute-selection-action)
1628 (anything-aif (get-buffer anything-action-buffer)
1629 (kill-buffer it))
1630 (anything-log-run-hook 'anything-after-action-hook)))
1632 (defun anything-on-quit ()
1633 (setq minibuffer-history (cons anything-input minibuffer-history))
1634 (anything-current-position 'restore))
1636 (defun anything-resume-select-buffer (input)
1637 (anything '(((name . "Resume anything buffer")
1638 (candidates . anything-buffers)
1639 (action . identity)))
1640 input nil 'noresume nil "*anything resume*"))
1642 (defun anything-recent-push (elt list-var)
1643 "Add ELT to the value of LIST-VAR as most recently used value."
1644 (let ((m (member elt (symbol-value list-var))))
1645 (and m (set list-var (delq (car m) (symbol-value list-var))))
1646 (push elt (symbol-value list-var))))
1648 ;;; (@* "Core: Accessors")
1649 ;;; rubikitch: I love to create functions to control variables.
1650 (defvar anything-current-position nil
1651 "Cons of (point) and (window-start) when `anything' is invoked.
1652 It is needed because restoring position when `anything' is keyboard-quitted.")
1653 (defun anything-current-position (save-or-restore)
1654 (case save-or-restore
1655 (save
1656 (setq anything-current-position (cons (point) (window-start))))
1657 (restore
1658 (goto-char (car anything-current-position))
1659 (set-window-start (selected-window) (cdr anything-current-position)))))
1661 ;;; FIXME I want to remove them. But anything-iswitchb uses them.
1662 (defun anything-current-frame/window-configuration ()
1663 (funcall (cdr anything-save-configuration-functions)))
1664 (defun anything-set-frame/window-configuration (conf)
1665 (funcall (car anything-save-configuration-functions) conf))
1667 (lexical-let (conf)
1668 (defun anything-frame/window-configuration (save-or-restore)
1669 (anything-log-eval anything-save-configuration-functions)
1670 (case save-or-restore
1671 (save (setq conf (funcall (cdr anything-save-configuration-functions))))
1672 (restore (funcall (car anything-save-configuration-functions) conf)))))
1674 ;; (@* "Core: Display *anything* buffer")
1675 (defun anything-display-buffer (buf)
1676 "Display *anything* buffer."
1677 (funcall (with-current-buffer buf anything-display-function) buf))
1679 (defun anything-default-display-buffer (buf)
1680 (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
1682 ;; (@* "Core: initialize")
1683 (defun anything-initialize ()
1684 "Initialize anything settings and set up the anything buffer."
1685 (anything-log-run-hook 'anything-before-initialize-hook)
1686 (setq anything-once-called-functions nil)
1687 (setq anything-delayed-init-executed nil)
1688 (setq anything-current-buffer (current-buffer))
1689 (setq anything-buffer-file-name buffer-file-name)
1690 (setq anything-issued-errors nil)
1691 (setq anything-compiled-sources nil)
1692 (setq anything-saved-current-source nil)
1693 ;; Call the init function for sources where appropriate
1694 (anything-funcall-foreach 'init)
1696 (setq anything-pattern "")
1697 (setq anything-input "")
1698 (setq anything-candidate-cache nil)
1699 (setq anything-last-sources anything-sources)
1701 (anything-create-anything-buffer)
1702 (anything-log-run-hook 'anything-after-initialize-hook))
1704 (defvar anything-reading-pattern nil
1705 "Whether in `read-string' in anything or not.")
1706 (defun anything-read-pattern-maybe (any-prompt any-input any-preselect any-resume any-keymap)
1707 (if (anything-resume-p any-resume)
1708 (anything-mark-current-line)
1709 (anything-update))
1710 (select-frame-set-input-focus (window-frame (minibuffer-window)))
1711 (anything-preselect any-preselect)
1712 (with-current-buffer (anything-buffer-get)
1713 (and any-keymap (set (make-local-variable 'anything-map) any-keymap))
1714 (let ((minibuffer-local-map
1715 anything-map))
1716 (anything-log-eval (anything-approximate-candidate-number)
1717 anything-execute-action-at-once-if-one
1718 anything-quit-if-no-candidate)
1719 (cond ((and anything-execute-action-at-once-if-one
1720 (= (anything-approximate-candidate-number) 1))
1721 (ignore))
1722 ((and anything-quit-if-no-candidate
1723 (= (anything-approximate-candidate-number) 0))
1724 (setq anything-quit t)
1725 (and (functionp anything-quit-if-no-candidate)
1726 (funcall anything-quit-if-no-candidate)))
1728 (let ((anything-reading-pattern t))
1729 (read-string (or any-prompt "pattern: ") any-input)))))))
1731 (defun anything-create-anything-buffer (&optional test-mode)
1732 "Create newly created `anything-buffer'.
1733 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
1734 (when test-mode
1735 (setq anything-candidate-cache nil))
1736 (with-current-buffer (get-buffer-create anything-buffer)
1737 (anything-log "kill local variables: %S" (buffer-local-variables))
1738 (kill-all-local-variables)
1739 (set (make-local-variable 'inhibit-read-only) t)
1740 (buffer-disable-undo)
1741 (erase-buffer)
1742 (set (make-local-variable 'inhibit-read-only) t)
1743 (set (make-local-variable 'anything-last-sources-local) anything-sources)
1744 (set (make-local-variable 'anything-follow-mode) nil)
1745 (set (make-local-variable 'anything-display-function) anything-display-function)
1746 (anything-initialize-persistent-action)
1747 (anything-log-eval anything-display-function anything-let-variables)
1748 (loop for (var . val) in anything-let-variables
1749 do (set (make-local-variable var) val))
1751 (setq cursor-type nil)
1752 (setq mode-name "Anything"))
1753 (anything-initialize-overlays anything-buffer)
1754 (get-buffer anything-buffer))
1756 (defun anything-initialize-overlays (buffer)
1757 (anything-log "overlay setup")
1758 (if anything-selection-overlay
1759 ;; make sure the overlay belongs to the anything buffer if
1760 ;; it's newly created
1761 (move-overlay anything-selection-overlay (point-min) (point-min)
1762 (get-buffer buffer))
1764 (setq anything-selection-overlay
1765 (make-overlay (point-min) (point-min) (get-buffer buffer)))
1766 (overlay-put anything-selection-overlay 'face anything-selection-face))
1768 (cond (anything-enable-shortcuts
1769 (setq anything-shortcut-keys
1770 (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist))
1771 (unless anything-digit-overlays
1772 (setq anything-digit-overlays
1773 (loop for key across anything-shortcut-keys
1774 for overlay = (make-overlay (point-min) (point-min)
1775 (get-buffer buffer))
1776 do (overlay-put overlay 'before-string
1777 (format "%s - " (upcase (make-string 1 key))))
1778 collect overlay))))
1779 (anything-digit-overlays
1780 (mapc 'delete-overlay anything-digit-overlays)
1781 (setq anything-digit-overlays nil))))
1783 (defun anything-hooks (setup-or-cleanup)
1784 (let ((hooks '((deferred-action-list anything-check-minibuffer-input)
1785 (minibuffer-setup-hook anything-print-error-messages))))
1786 (if (eq setup-or-cleanup 'setup)
1787 (dolist (args hooks) (apply 'add-hook args))
1788 (dolist (args (reverse hooks)) (apply 'remove-hook args)))))
1790 ;; (@* "Core: clean up")
1791 ;;; TODO move
1792 (defun anything-cleanup ()
1793 "Clean up the mess."
1794 (anything-log "start cleanup")
1795 (with-current-buffer anything-buffer
1796 (setq cursor-type t))
1797 (bury-buffer anything-buffer)
1798 (anything-funcall-foreach 'cleanup)
1799 (anything-new-timer 'anything-check-minibuffer-input-timer nil)
1800 (anything-kill-async-processes)
1801 (anything-log-run-hook 'anything-cleanup-hook)
1802 (anything-hooks 'cleanup)
1803 (anything-frame/window-configuration 'restore))
1805 ;; (@* "Core: input handling")
1806 (defun anything-check-minibuffer-input ()
1807 "Extract input string from the minibuffer and check if it needs
1808 to be handled."
1809 (let ((delay (with-current-buffer anything-buffer anything-input-idle-delay)))
1810 (if (or (not delay) (anything-action-window))
1811 (anything-check-minibuffer-input-1)
1812 (anything-new-timer
1813 'anything-check-minibuffer-input-timer
1814 (run-with-idle-timer delay nil 'anything-check-minibuffer-input-1)))))
1816 (defun anything-check-minibuffer-input-1 ()
1817 (with-anything-quittable
1818 (with-selected-window (minibuffer-window)
1819 (anything-check-new-input (minibuffer-contents)))))
1821 (defun anything-check-new-input (input)
1822 "Check input string and update the anything buffer if
1823 necessary."
1824 (unless (equal input anything-pattern)
1825 (setq anything-pattern input)
1826 (unless (anything-action-window)
1827 (setq anything-input anything-pattern))
1828 (anything-log-eval anything-pattern anything-input)
1829 (anything-update)))
1831 ;; (@* "Core: source compiler")
1832 (defvar anything-compile-source-functions-default anything-compile-source-functions
1833 "Plug-ins this file provides.")
1834 (defun anything-compile-sources (sources funcs)
1835 "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
1836 Anything plug-ins are realized by this function."
1837 (mapcar
1838 (lambda (source)
1839 (loop with source = (if (listp source) source (symbol-value source))
1840 for f in funcs
1841 do (setq source (funcall f source))
1842 finally (return source)))
1843 sources))
1845 ;; (@* "Core: plug-in attribute documentation hack")
1847 ;; `anything-document-attribute' is public API.
1848 (defadvice documentation-property (after anything-document-attribute activate)
1849 "Hack to display plug-in attributes' documentation as `anything-sources' docstring."
1850 (when (eq (ad-get-arg 0) 'anything-sources)
1851 (setq ad-return-value
1852 (concat ad-return-value "\n"
1853 (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
1854 anything-additional-attributes
1855 "\n")))))
1856 ;; (describe-variable 'anything-sources)
1857 ;; (documentation-property 'anything-sources 'variable-documentation)
1858 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
1860 ;; (@* "Core: all candidates")
1861 (defun anything-process-delayed-init (source)
1862 (let ((name (assoc-default 'name source)))
1863 (unless (member name anything-delayed-init-executed)
1864 (anything-aif (assoc-default 'delayed-init source)
1865 (with-current-buffer anything-current-buffer
1866 (anything-funcall-with-source source it)
1867 (dolist (f (if (functionp it) (list it) it))
1868 (add-to-list 'anything-delayed-init-executed name)))))))
1870 (defun anything-get-candidates (source)
1871 "Retrieve and return the list of candidates from
1872 SOURCE."
1873 (anything-process-delayed-init source)
1874 (let* ((candidate-source (assoc-default 'candidates source))
1875 (type-error (lambda ()
1876 (error (concat "Candidates must either be a function, "
1877 " a variable or a list: %s")
1878 candidate-source)))
1879 (candidates (condition-case err
1880 (anything-interpret-value candidate-source source)
1881 (error (funcall type-error)))))
1882 (cond ((processp candidates) candidates)
1883 ((listp candidates) (anything-transform-candidates candidates source))
1884 (t (funcall type-error)))))
1887 (defun anything-get-cached-candidates (source)
1888 "Return the cached value of candidates for SOURCE.
1889 Cache the candidates if there is not yet a cached value."
1890 (let* ((name (assoc-default 'name source))
1891 (candidate-cache (assoc name anything-candidate-cache)))
1892 (cond (candidate-cache
1893 (anything-log "use cached candidates")
1894 (cdr candidate-cache))
1896 (anything-log "calculate candidates")
1897 (let ((candidates (anything-get-candidates source)))
1898 (cond ((processp candidates)
1899 (push (cons candidates
1900 (append source
1901 (list (cons 'item-count 0)
1902 (cons 'incomplete-line ""))))
1903 anything-async-processes)
1904 (set-process-filter candidates 'anything-output-filter)
1905 (setq candidates nil))
1906 ((not (assoc 'volatile source))
1907 (setq candidate-cache (cons name candidates))
1908 (push candidate-cache anything-candidate-cache)))
1909 candidates)))))
1911 ;;; (@* "Core: candidate transformers")
1912 (defun anything-process-candidate-transformer (candidates source)
1913 (anything-aif (assoc-default 'candidate-transformer source)
1914 (anything-composed-funcall-with-source source it candidates)
1915 candidates))
1916 (defun anything-process-filtered-candidate-transformer (candidates source)
1917 (anything-aif (assoc-default 'filtered-candidate-transformer source)
1918 (anything-composed-funcall-with-source source it candidates source)
1919 candidates))
1920 (defun anything-process-filtered-candidate-transformer-maybe (candidates source process-p)
1921 (if process-p
1922 (anything-process-filtered-candidate-transformer candidates source)
1923 candidates))
1924 (defun anything-process-real-to-display (candidates source)
1925 (anything-aif (assoc-default 'real-to-display source)
1926 (setq candidates (anything-funcall-with-source
1927 source 'mapcar
1928 (lambda (cand_)
1929 (if (consp cand_)
1930 ;; override DISPLAY from candidate-transformer
1931 (cons (funcall it (cdr cand_)) (cdr cand_))
1932 (cons (funcall it cand_) cand_)))
1933 candidates))
1934 candidates))
1935 (defun anything-transform-candidates (candidates source &optional process-p)
1936 "Transform CANDIDATES according to candidate transformers."
1937 (anything-process-real-to-display
1938 (anything-process-filtered-candidate-transformer-maybe
1939 (anything-process-candidate-transformer candidates source) source process-p)
1940 source))
1943 ;; (@* "Core: narrowing candidates")
1944 (defun anything-candidate-number-limit (source)
1945 "`anything-candidate-number-limit' variable may be overridden by SOURCE.
1946 If (candidate-number-limit) is in SOURCE, show all candidates in SOURCE,
1947 ie. cancel the effect of `anything-candidate-number-limit'."
1948 (anything-aif (assq 'candidate-number-limit source)
1949 (or (cdr it) 99999999)
1950 (or anything-candidate-number-limit 99999999)))
1952 (defconst anything-default-match-functions
1953 (list (lambda (candidate)
1954 (string-match anything-pattern candidate))))
1956 (defun anything-compute-matches (source)
1957 "Compute matches from SOURCE according to its settings."
1958 (if debug-on-error
1959 (anything-compute-matches-internal source)
1960 (condition-case v
1961 (anything-compute-matches-internal source)
1962 (error (anything-log-error
1963 "anything-compute-matches: error when processing source: %s"
1964 (assoc-default 'name source))
1965 nil))))
1967 (defun anything-candidate-get-display (candidate)
1968 "Get display part (searched) from CANDIDATE.
1969 CANDIDATE is a string, a symbol, or (DISPLAY . REAL) cons cell."
1970 (format "%s" (or (car-safe candidate) candidate)))
1972 (defun anything-process-pattern-transformer (pattern source)
1973 (anything-aif (assoc-default 'pattern-transformer source)
1974 (anything-composed-funcall-with-source source it pattern)
1975 pattern))
1977 (defun anything-match-functions (source)
1978 (or (assoc-default 'match source)
1979 anything-default-match-functions))
1981 (defmacro anything-accumulate-candidates-internal (cand newmatches hash item-count limit)
1982 "INTERNAL: add CAND (ITEM-COUNT th match) into NEWMATCHES.
1983 Use HASH to uniq NEWMATCHES.
1984 if ITEM-COUNT reaches LIMIT, exit from inner loop."
1985 `(unless (gethash ,cand ,hash)
1986 (puthash ,cand t ,hash)
1987 (push ,cand ,newmatches)
1988 (incf ,item-count)
1989 (when (= ,item-count ,limit)
1990 (setq exit t)
1991 (return))))
1993 (defun anything-take-first-elements (seq n)
1994 (if (> (length seq) n)
1995 (setq seq (subseq seq 0 n))
1996 seq))
1998 (defun anything-match-from-candidates (cands matchfns limit)
1999 (let (matches)
2000 (condition-case nil
2001 (let ((item-count 0) exit)
2002 (clrhash anything-match-hash)
2003 (dolist (match matchfns)
2004 (let (newmatches)
2005 (dolist (candidate cands)
2006 (when (funcall match (anything-candidate-get-display candidate))
2007 (anything-accumulate-candidates-internal
2008 candidate newmatches anything-match-hash item-count limit)))
2009 (setq matches (append matches (reverse newmatches)))
2010 (if exit (return)))))
2011 (invalid-regexp (setq matches nil)))
2012 matches))
2014 (defun anything-compute-matches-internal (source)
2015 (save-current-buffer
2016 (let ((matchfns (anything-match-functions source))
2017 (anything-source-name (assoc-default 'name source))
2018 (limit (anything-candidate-number-limit source))
2019 (anything-pattern (anything-process-pattern-transformer
2020 anything-pattern source)))
2021 (anything-process-filtered-candidate-transformer
2022 (if (or (equal anything-pattern "") (equal matchfns '(identity)))
2023 (anything-take-first-elements
2024 (anything-get-cached-candidates source) limit)
2025 (anything-match-from-candidates
2026 (anything-get-cached-candidates source) matchfns limit))
2027 source))))
2029 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2031 (defun anything-process-source (source)
2032 "Display matches from SOURCE according to its settings."
2033 (anything-log-eval (assoc-default 'name source))
2034 (if (assq 'direct-insert-match source) ;experimental
2035 (anything-process-source--direct-insert-match source)
2036 (let ((matches (anything-compute-matches source)))
2037 (when matches
2038 (when anything-test-mode
2039 (setq anything-test-candidate-list
2040 `(,@anything-test-candidate-list
2041 (,(assoc-default 'name source)
2042 ,matches))))
2043 (anything-insert-header-from-source source)
2044 (if (not (assq 'multiline source))
2045 (mapc 'anything-insert-match-with-digit-overlay matches)
2046 (let ((start (point)) separate)
2047 (dolist (match matches)
2048 (if separate
2049 (anything-insert-candidate-separator)
2050 (setq separate t))
2051 (anything-insert-match-with-digit-overlay match))
2052 (put-text-property start (point) 'anything-multiline t)))))))
2054 (defun anything-insert-match-with-digit-overlay (match)
2055 (declare (special source))
2056 (anything-put-digit-overlay-maybe)
2057 (anything-insert-match match 'insert source))
2059 (defun anything-put-digit-overlay-maybe ()
2060 (when (and anything-enable-shortcuts
2061 (not (eq anything-digit-shortcut-count
2062 (length anything-digit-overlays))))
2063 (move-overlay (nth anything-digit-shortcut-count
2064 anything-digit-overlays)
2065 (point-at-bol)
2066 (point-at-bol))
2067 (incf anything-digit-shortcut-count)))
2069 (defun anything-process-source--direct-insert-match (source)
2070 "[EXPERIMENTAL] Insert candidates from `anything-candidate-buffer'"
2071 (anything-log-eval (assoc-default 'name source))
2072 (let ((anything-source-name (assoc-default 'name source))
2073 content-buf)
2074 (funcall (assoc-default 'candidates source))
2075 (setq content-buf (anything-candidate-buffer))
2076 (unless (anything-empty-buffer-p content-buf)
2077 (anything-insert-header-from-source source)
2078 (insert-buffer-substring content-buf)
2079 ;; TODO call anything-put-digit-overlay-maybe with loop
2082 (defun anything-process-delayed-sources (delayed-sources)
2083 "Process delayed sources if the user is idle for
2084 `anything-idle-delay' seconds."
2085 (with-anything-quittable
2086 (anything-log-eval (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2087 (with-current-buffer anything-buffer
2088 (save-excursion
2089 (goto-char (point-max))
2090 (mapc 'anything-process-source delayed-sources)
2091 (when (and (not (anything-empty-buffer-p))
2092 ;; no selection yet
2093 (= (overlay-start anything-selection-overlay)
2094 (overlay-end anything-selection-overlay)))
2095 (goto-char (point-min))
2096 (anything-next-line)))
2097 (save-excursion
2098 (goto-char (point-min))
2099 (anything-log-run-hook 'anything-update-hook))
2100 (anything-maybe-fit-frame))))
2102 ;; (@* "Core: *anything* buffer contents")
2103 (defvar anything-input-local nil)
2104 (defvar anything-process-delayed-sources-timer nil)
2105 (defun anything-update ()
2106 "Update the list of matches in the anything buffer according to
2107 the current pattern."
2108 (anything-log "start update")
2109 (setq anything-digit-shortcut-count 0)
2110 (anything-kill-async-processes)
2111 (with-current-buffer (anything-buffer-get)
2112 (set (make-local-variable 'anything-input-local) anything-pattern)
2113 (erase-buffer)
2114 (when anything-enable-shortcuts
2115 (mapc 'delete-overlay anything-digit-overlays))
2116 (let (delayed-sources)
2117 (unwind-protect
2118 (setq delayed-sources
2119 (loop for source in (remove-if-not 'anything-update-source-p
2120 (anything-get-sources))
2121 if (anything-delayed-source-p source)
2122 collect source
2123 else do (anything-process-source source)))
2124 (anything-log-eval
2125 (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2126 (anything-update-move-first-line)
2127 (if anything-test-mode
2128 (mapc 'anything-process-source delayed-sources)
2129 (anything-maybe-fit-frame)
2130 (when delayed-sources
2131 (anything-new-timer
2132 'anything-process-delayed-sources-timer
2133 (run-with-idle-timer
2134 anything-idle-delay nil
2135 'anything-process-delayed-sources delayed-sources)))
2136 ;; FIXME I want to execute anything-after-update-hook
2137 ;; AFTER processing delayed sources
2138 (anything-log-run-hook 'anything-after-update-hook))
2139 (anything-log "end update")))))
2141 (defun anything-update-source-p (source)
2142 (and (or (not anything-source-filter)
2143 (member (assoc-default 'name source) anything-source-filter))
2144 (>= (length anything-pattern)
2145 (anything-aif (assoc 'requires-pattern source)
2146 (or (cdr it) 1)
2147 0))))
2148 (defun anything-delayed-source-p (source)
2149 (or (assoc 'delayed source)
2150 (and anything-quick-update
2151 (< (window-height (get-buffer-window (current-buffer)))
2152 (line-number-at-pos (point-max))))))
2154 (defun anything-update-move-first-line ()
2155 (goto-char (point-min))
2156 (save-excursion (anything-log-run-hook 'anything-update-hook))
2157 (anything-next-line))
2159 (defun anything-force-update ()
2160 "Recalculate and update candidates.
2161 If current source has `update' attribute, a function without argument, call it before update."
2162 (interactive)
2163 (let ((source (anything-get-current-source)))
2164 (if source
2165 (anything-force-update--reinit source)
2166 (anything-erase-message)
2167 (mapc 'anything-force-update--reinit (anything-get-sources)))
2168 (let ((selection (anything-get-selection nil t)))
2169 (anything-update)
2170 (anything-keep-selection source selection))))
2172 (defun anything-force-update--reinit (source)
2173 (anything-aif (anything-funcall-with-source source 'anything-candidate-buffer)
2174 (kill-buffer it))
2175 (dolist (attr '(update init))
2176 (anything-aif (assoc-default attr source)
2177 (anything-funcall-with-source source it)))
2178 (anything-remove-candidate-cache source))
2180 (defun anything-erase-message ()
2181 (message ""))
2183 (defun anything-keep-selection (source selection)
2184 (when (and source selection)
2185 (with-anything-window
2186 (anything-goto-source source)
2187 (forward-char -1) ;back to \n
2188 (if (search-forward (concat "\n" selection "\n") nil t)
2189 (forward-line -1)
2190 (goto-char (point-min))
2191 (forward-line 1))
2192 (anything-mark-current-line))))
2194 (defun anything-remove-candidate-cache (source)
2195 (setq anything-candidate-cache
2196 (delete (assoc (assoc-default 'name source) anything-candidate-cache)
2197 anything-candidate-cache)))
2199 (defun anything-insert-match (match insert-function source)
2200 "Insert MATCH into the anything buffer. If MATCH is a list then
2201 insert the string inteneded to appear on the display and store
2202 the real value in a text property."
2203 (let ((start (point-at-bol (point)))
2204 (string (or (car-safe match) match))
2205 (realvalue (cdr-safe match)))
2206 (when (symbolp string) (setq string (symbol-name string)))
2207 (when (stringp string)
2208 (funcall insert-function string)
2209 ;; Some sources with candidates-in-buffer have already added
2210 ;; 'anything-realvalue property when creating candidate buffer.
2211 (unless (get-text-property start 'anything-realvalue)
2212 (and realvalue
2213 (put-text-property start (point-at-eol)
2214 'anything-realvalue realvalue)))
2215 (when anything-source-in-each-line-flag
2216 (put-text-property start (point-at-eol) 'anything-source source))
2217 (funcall insert-function "\n"))))
2219 (defun anything-insert-header-from-source (source)
2220 (let ((name (assoc-default 'name source)))
2221 (anything-insert-header
2222 name
2223 (anything-aif (assoc-default 'header-name source)
2224 (anything-funcall-with-source source it name)))))
2226 (defun anything-insert-header (name &optional display-string)
2227 "Insert header of source NAME into the anything buffer."
2228 (unless (bobp)
2229 (let ((start (point)))
2230 (insert "\n")
2231 (put-text-property start (point) 'anything-header-separator t)))
2233 (let ((start (point)))
2234 (insert name)
2235 (put-text-property (point-at-bol)
2236 (point-at-eol) 'anything-header t)
2237 (when display-string
2238 (overlay-put (make-overlay (point-at-bol) (point-at-eol))
2239 'display display-string))
2240 (insert "\n")
2241 (put-text-property start (point) 'face anything-header-face)))
2244 (defun anything-insert-candidate-separator ()
2245 "Insert separator of candidates into the anything buffer."
2246 (insert anything-candidate-separator)
2247 (put-text-property (point-at-bol)
2248 (point-at-eol) 'anything-candidate-separator t)
2249 (insert "\n"))
2254 ;; (@* "Core: async process")
2255 (defun anything-output-filter (process string)
2256 "Process output from PROCESS."
2257 (anything-output-filter-1 (assoc process anything-async-processes) string))
2259 (defun anything-output-filter-1 (process-assoc string)
2260 (anything-log-eval string)
2261 (with-current-buffer anything-buffer
2262 (let ((source (cdr process-assoc)))
2263 (save-excursion
2264 (anything-aif (assoc-default 'insertion-marker source)
2265 (goto-char it)
2266 (goto-char (point-max))
2267 (anything-insert-header-from-source source)
2268 (setcdr process-assoc
2269 (append source `((insertion-marker . ,(point-marker))))))
2270 (anything-output-filter--process-source
2271 (car process-assoc) string source
2272 (anything-candidate-number-limit source))))
2273 (anything-output-filter--post-process)))
2275 (defun anything-output-filter--process-source (process string source limit)
2276 (dolist (candidate (anything-transform-candidates
2277 (anything-output-filter--collect-candidates
2278 (split-string string "\n")
2279 (assoc 'incomplete-line source))
2280 source t))
2281 (if (not (assq 'multiline source))
2282 (anything-insert-match candidate 'insert-before-markers source)
2283 (let ((start (point)))
2284 (anything-insert-candidate-separator)
2285 (anything-insert-match candidate 'insert-before-markers source)
2286 (put-text-property start (point) 'anything-multiline t)))
2287 (incf (cdr (assoc 'item-count source)))
2288 (when (>= (assoc-default 'item-count source) limit)
2289 (anything-kill-async-process process)
2290 (return))))
2292 (defun anything-output-filter--collect-candidates (lines incomplete-line-info)
2293 (anything-log-eval (cdr incomplete-line-info))
2294 (butlast
2295 (loop for line in lines collect
2296 (if (cdr incomplete-line-info)
2297 (prog1
2298 (concat (cdr incomplete-line-info) line)
2299 (setcdr incomplete-line-info nil))
2300 line)
2301 finally (setcdr incomplete-line-info line))))
2303 (defun anything-output-filter--post-process ()
2304 (anything-maybe-fit-frame)
2305 (anything-log-run-hook 'anything-update-hook)
2306 (anything-aif (get-buffer-window anything-buffer 'visible)
2307 (save-selected-window
2308 (select-window it)
2309 (anything-skip-noncandidate-line 'next)
2310 (anything-mark-current-line))))
2313 (defun anything-kill-async-processes ()
2314 "Kill all known asynchronous processes according to
2315 `anything-async-processes'."
2316 "Kill locate process."
2317 (mapc 'anything-kill-async-process (mapcar 'car anything-async-processes))
2318 (setq anything-async-processes nil))
2321 (defun anything-kill-async-process (process)
2322 "Kill PROCESS and detach the associated functions."
2323 (set-process-filter process nil)
2324 (delete-process process))
2327 ;; (@* "Core: action")
2328 (defun anything-execute-selection-action (&optional selection action preserve-saved-action)
2329 "If a candidate was selected then perform the associated
2330 action."
2331 (anything-log "executing action")
2332 (setq action (anything-get-default-action
2333 (or action
2334 anything-saved-action
2335 (if (get-buffer anything-action-buffer)
2336 (anything-get-selection anything-action-buffer)
2337 (anything-get-action)))))
2338 (let ((source (or anything-saved-current-source (anything-get-current-source))))
2339 (setq selection (or selection
2340 (anything-get-selection)
2341 (and (assoc 'accept-empty source) "")))
2342 (unless preserve-saved-action (setq anything-saved-action nil))
2343 (if (and selection action)
2344 (anything-funcall-with-source
2345 source action
2346 (anything-coerce-selection selection source)))))
2348 (defun anything-coerce-selection (selection source)
2349 "Coerce source with coerce function."
2350 (anything-aif (assoc-default 'coerce source)
2351 (anything-funcall-with-source source it selection)
2352 selection))
2354 (defun anything-get-default-action (action)
2355 (if (and (listp action) (not (functionp action)))
2356 (cdar action)
2357 action))
2359 (defun anything-select-action ()
2360 "Select an action for the currently selected candidate.
2361 If action buffer is selected, back to the anything buffer."
2362 (interactive)
2363 (cond ((get-buffer-window anything-action-buffer 'visible)
2364 (set-window-buffer (get-buffer-window anything-action-buffer)
2365 anything-buffer)
2366 (kill-buffer anything-action-buffer)
2367 (anything-set-pattern anything-input 'noupdate))
2369 (setq anything-saved-selection (anything-get-selection))
2370 (unless anything-saved-selection
2371 (error "Nothing is selected."))
2372 (setq anything-saved-current-source (anything-get-current-source))
2373 (let ((actions (anything-get-action)))
2374 (if (functionp actions)
2375 (message "Sole action: %s" actions)
2376 (anything-show-action-buffer actions)
2377 (anything-delete-minibuffer-contents)
2378 (setq anything-pattern 'dummy) ; so that it differs from the previous one
2379 (anything-check-minibuffer-input))))))
2381 (defun anything-show-action-buffer (actions)
2382 (with-current-buffer (get-buffer-create anything-action-buffer)
2383 (erase-buffer)
2384 (buffer-disable-undo)
2385 (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
2386 (set (make-local-variable 'anything-sources)
2387 `(((name . "Actions")
2388 (volatile)
2389 (candidates . ,actions)
2390 (candidate-number-limit))))
2391 (set (make-local-variable 'anything-source-filter) nil)
2392 (set (make-local-variable 'anything-selection-overlay) nil)
2393 (set (make-local-variable 'anything-digit-overlays) nil)
2394 (anything-initialize-overlays anything-action-buffer)))
2396 ;; (@* "Core: selection")
2397 (defun anything-move-selection-common (move-func unit direction)
2398 "Move the selection marker to a new position determined by
2399 UNIT and DIRECTION."
2400 (unless (or (anything-empty-buffer-p (anything-buffer-get))
2401 (not (anything-window)))
2402 (with-anything-window
2403 (funcall move-func)
2404 (anything-skip-noncandidate-line direction)
2405 (anything-display-source-at-screen-top-maybe unit)
2406 (when (anything-get-previous-header-pos)
2407 (anything-mark-current-line))
2408 (anything-display-mode-line (anything-get-current-source)))))
2410 (defun anything-display-source-at-screen-top-maybe (unit)
2411 (when (and anything-display-source-at-screen-top (eq unit 'source))
2412 (set-window-start (selected-window)
2413 (save-excursion (forward-line -1) (point)))))
2415 (defun anything-skip-noncandidate-line (direction)
2416 (anything-skip-header-and-separator-line direction)
2417 (and (bobp) (forward-line 1)) ;skip first header
2418 (and (eobp) (forward-line -1)) ;avoid last empty line
2421 (defun anything-skip-header-and-separator-line (direction)
2422 (while (and (not (bobp))
2423 (or (anything-pos-header-line-p)
2424 (anything-pos-candidate-separator-p)))
2425 (forward-line (if (and (eq direction 'previous)
2426 (not (eq (point-at-bol) (point-min))))
2428 1))))
2430 (defvar anything-mode-line-string-real nil)
2431 (defun anything-display-mode-line (source)
2432 (set (make-local-variable 'anything-mode-line-string)
2433 (anything-interpret-value (or (assoc-default 'mode-line source)
2434 (default-value 'anything-mode-line-string))
2435 source))
2436 (if anything-mode-line-string
2437 (setq mode-line-format
2438 '(" " mode-line-buffer-identification " "
2439 (line-number-mode "%l") " " (anything-follow-mode "(F)")
2440 " " anything-mode-line-string-real "-%-")
2441 anything-mode-line-string-real
2442 (substitute-command-keys anything-mode-line-string))
2443 (setq mode-line-format
2444 (default-value 'mode-line-format)))
2445 (setq header-line-format
2446 (anything-interpret-value (assoc-default 'header-line source) source)))
2448 (defun anything-previous-line ()
2449 "Move selection to the previous line."
2450 (interactive)
2451 (anything-move-selection-common
2452 (lambda ()
2453 (if (not (anything-pos-multiline-p))
2454 (forward-line -1) ;double forward-line is meaningful
2455 (forward-line -1) ;because evaluation order is important
2456 (anything-skip-header-and-separator-line 'previous)
2457 (let ((header-pos (anything-get-previous-header-pos))
2458 (separator-pos (anything-get-previous-candidate-separator-pos)))
2459 (when header-pos
2460 (goto-char (if (or (null separator-pos) (< separator-pos header-pos))
2461 header-pos ; first candidate
2462 separator-pos))
2463 (forward-line 1)))))
2464 'line 'previous))
2466 (defun anything-next-line ()
2467 "Move selection to the next line."
2468 (interactive)
2469 (anything-move-selection-common
2470 (lambda ()
2471 (if (not (anything-pos-multiline-p))
2472 (forward-line 1)
2473 (let ((header-pos (anything-get-next-header-pos))
2474 (separator-pos (anything-get-next-candidate-separator-pos)))
2475 (cond ((and separator-pos
2476 (or (null header-pos) (< separator-pos header-pos)))
2477 (goto-char separator-pos))
2478 (header-pos
2479 (goto-char header-pos))))))
2480 'line 'next))
2482 (defun anything-previous-page ()
2483 "Move selection back with a pageful."
2484 (interactive)
2485 (anything-move-selection-common
2486 (lambda ()
2487 (condition-case nil
2488 (scroll-down)
2489 (beginning-of-buffer (goto-char (point-min)))))
2490 'page 'previous))
2492 (defun anything-next-page ()
2493 "Move selection forward with a pageful."
2494 (interactive)
2495 (anything-move-selection-common
2496 (lambda ()
2497 (condition-case nil
2498 (scroll-up)
2499 (end-of-buffer (goto-char (point-max)))))
2500 'page 'next))
2502 (defun anything-beginning-of-buffer ()
2503 "Move selection at the top."
2504 (interactive)
2505 (anything-move-selection-common (lambda () (goto-char (point-min)))
2506 'edge 'previous))
2508 (defun anything-end-of-buffer ()
2509 "Move selection at the bottom."
2510 (interactive)
2511 (anything-move-selection-common (lambda () (goto-char (point-max)))
2512 'edge 'next))
2514 (defun anything-previous-source ()
2515 "Move selection to the previous source."
2516 (interactive)
2517 (anything-move-selection-common
2518 (lambda ()
2519 (forward-line -1)
2520 (if (bobp)
2521 (goto-char (point-max))
2522 (anything-skip-header-and-separator-line 'previous))
2523 (goto-char (anything-get-previous-header-pos))
2524 (forward-line 1))
2525 'source 'previous))
2527 (defun anything-next-source ()
2528 "Move selection to the next source."
2529 (interactive)
2530 (anything-move-selection-common
2531 (lambda () (goto-char (or (anything-get-next-header-pos) (point-min))))
2532 'source 'next))
2534 (defun anything-goto-source (source-or-name)
2535 "Move the selection to the source (SOURCE-OR-NAME)."
2536 (anything-move-selection-common
2537 (lambda ()
2538 (goto-char (point-min))
2539 (let ((name (if (stringp source-or-name) source-or-name
2540 (assoc-default 'name source-or-name))))
2541 (condition-case err
2542 (while (not (string= name (anything-current-line-contents)))
2543 (goto-char (anything-get-next-header-pos)))
2544 (error (message "")))))
2545 'source 'next))
2547 (defun anything-mark-current-line ()
2548 "Move selection overlay to current line."
2549 (move-overlay
2550 anything-selection-overlay (point-at-bol)
2551 (if (anything-pos-multiline-p)
2552 (let ((header-pos (anything-get-next-header-pos))
2553 (separator-pos (anything-get-next-candidate-separator-pos)))
2554 (or (and (null header-pos) separator-pos)
2555 (and header-pos separator-pos (< separator-pos header-pos)
2556 separator-pos)
2557 header-pos
2558 (point-max)))
2559 (1+ (point-at-eol))))
2560 (anything-follow-execute-persistent-action-maybe))
2562 (defun anything-this-command-key ()
2563 (event-basic-type (elt (this-command-keys-vector) 0)))
2564 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
2566 (defun anything-select-with-shortcut-internal (types get-key-func)
2567 (if (memq anything-enable-shortcuts types)
2568 (save-selected-window
2569 (select-window (anything-window))
2570 (let* ((key (funcall get-key-func))
2571 (overlay (ignore-errors (nth (position key anything-shortcut-keys)
2572 anything-digit-overlays))))
2573 (if (not (and overlay (overlay-buffer overlay)))
2574 (when (numberp key)
2575 (select-window (minibuffer-window))
2576 (self-insert-command 1))
2577 (goto-char (overlay-start overlay))
2578 (anything-mark-current-line)
2579 (anything-exit-minibuffer))))
2580 (self-insert-command 1)))
2582 (defun anything-select-with-prefix-shortcut ()
2583 "Invoke default action with prefix shortcut."
2584 (interactive)
2585 (anything-select-with-shortcut-internal
2586 '(prefix)
2587 (lambda () (read-event "Select shortcut key: "))))
2589 (defun anything-select-with-digit-shortcut ()
2590 "Invoke default action with digit/alphabet shortcut."
2591 (interactive)
2592 (anything-select-with-shortcut-internal
2593 '(alphabet t) 'anything-this-command-key))
2595 ;; (setq anything-enable-shortcuts 'prefix)
2596 ;; (define-key anything-map "@" 'anything-select-with-prefix-shortcut)
2597 ;; (define-key anything-map (kbd "<f18>") 'anything-select-with-prefix-shortcut)
2599 (defun anything-exit-minibuffer ()
2600 "Select the current candidate by exiting the minibuffer."
2601 (interactive)
2602 (declare (special anything-iswitchb-candidate-selected))
2603 (setq anything-iswitchb-candidate-selected (anything-get-selection))
2604 (exit-minibuffer))
2606 (defun anything-keyboard-quit ()
2607 "Quit minibuffer in anything.
2609 If action buffer is displayed, kill it."
2610 (interactive)
2611 (when (get-buffer-window anything-action-buffer 'visible)
2612 (kill-buffer anything-action-buffer))
2613 (abort-recursive-edit))
2615 (defun anything-get-next-header-pos ()
2616 "Return the position of the next header from point."
2617 (next-single-property-change (point) 'anything-header))
2620 (defun anything-get-previous-header-pos ()
2621 "Return the position of the previous header from point"
2622 (previous-single-property-change (point) 'anything-header))
2625 (defun anything-pos-multiline-p ()
2626 "Return non-nil if the current position is in the multiline source region."
2627 (get-text-property (point) 'anything-multiline))
2630 (defun anything-get-next-candidate-separator-pos ()
2631 "Return the position of the next candidate separator from point."
2632 (next-single-property-change (point) 'anything-candidate-separator))
2635 (defun anything-get-previous-candidate-separator-pos ()
2636 "Return the position of the previous candidate separator from point."
2637 (previous-single-property-change (point) 'anything-candidate-separator))
2640 (defun anything-pos-header-line-p ()
2641 "Return t if the current line is a header line."
2642 (or (get-text-property (point-at-bol) 'anything-header)
2643 (get-text-property (point-at-bol) 'anything-header-separator)))
2645 (defun anything-pos-candidate-separator-p ()
2646 "Return t if the current line is a candidate separator."
2647 (get-text-property (point-at-bol) 'anything-candidate-separator))
2649 ;; (@* "Core: help")
2650 (defun anything-help-internal (bufname insert-content-fn)
2651 "Show long message during `anything' session."
2652 (save-window-excursion
2653 (select-window (anything-window))
2654 (delete-other-windows)
2655 (switch-to-buffer (get-buffer-create bufname))
2656 (erase-buffer)
2657 (funcall insert-content-fn)
2658 (setq mode-line-format "%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
2659 (setq cursor-type nil)
2660 (goto-char 1)
2661 (anything-help-event-loop)))
2663 (defun anything-help-event-loop ()
2664 (ignore-errors
2665 (loop for event = (read-event) do
2666 (case event
2667 ((?\C-v ? ) (scroll-up))
2668 ((?\M-v ?b) (scroll-down))
2669 (t (return))))))
2671 (defun anything-help ()
2672 "Help of `anything'."
2673 (interactive)
2674 (anything-help-internal
2675 " *Anything Help*"
2676 (lambda ()
2677 (insert (substitute-command-keys
2678 (anything-interpret-value anything-help-message)))
2679 (org-mode))))
2681 (defun anything-debug-output ()
2682 "Show all anything-related variables at this time."
2683 (interactive)
2684 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function))
2686 (defun anything-debug-output-function (&optional vars)
2687 (message "Calculating all anything-related values...")
2688 (insert "If you debug some variables or forms, set `anything-debug-forms'
2689 to a list of forms.\n\n")
2690 (dolist (v (or vars
2691 anything-debug-forms
2692 (apropos-internal "^anything-" 'boundp)))
2693 (insert "** "
2694 (pp-to-string v) "\n"
2695 (pp-to-string (eval v)) "\n"))
2696 (message "Calculating all anything-related values...Done"))
2698 ;; (@* "Core: misc")
2699 (defun anything-kill-buffer-hook ()
2700 "Remove tick entry from `anything-tick-hash' when killing a buffer."
2701 (loop for key being the hash-keys in anything-tick-hash
2702 if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
2703 do (remhash key anything-tick-hash)))
2704 (add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
2706 (defun anything-maybe-fit-frame ()
2707 "Fit anything frame to its buffer, and put it at top right of display.
2709 It is disabled by default because some flickering occurred in some environment.
2710 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
2711 `fit-frame-inhibit-fitting' to nil.
2712 You can set user options `fit-frame-max-width-percent' and
2713 `fit-frame-max-height-percent' to control max frame size."
2714 (declare (warn (unresolved 0)))
2715 (when (and (not anything-inhibit-fit-frame-flag)
2716 (anything-window)
2717 (require 'fit-frame nil t)
2718 (boundp 'fit-frame-inhibit-fitting-flag)
2719 (not fit-frame-inhibit-fitting-flag))
2720 (ignore-errors
2721 (with-anything-window
2722 (fit-frame nil nil nil t)
2723 (modify-frame-parameters
2724 (selected-frame)
2725 `((left . ,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
2726 (top . 0))))))) ; The (top . 0) shouldn't be necessary (Emacs bug).
2728 (defun anything-preselect (candidate-or-regexp)
2729 (with-anything-window
2730 (when candidate-or-regexp
2731 (goto-char (point-min))
2732 ;; go to first candidate of first source
2733 (forward-line 1)
2734 (let ((start (point)))
2735 (unless (or (re-search-forward
2736 (concat "^" (regexp-quote candidate-or-regexp) "$")
2737 nil t)
2738 (progn (goto-char start)
2739 (re-search-forward candidate-or-regexp nil t)))
2740 (goto-char start))))
2741 (anything-mark-current-line)))
2743 (defun anything-delete-current-selection ()
2744 "Delete the currently selected item."
2745 (interactive)
2746 (with-anything-window
2747 (cond ((anything-pos-multiline-p)
2748 (anything-aif (anything-get-next-candidate-separator-pos)
2749 (delete-region (point-at-bol)
2750 (1+ (progn (goto-char it) (point-at-eol))))
2751 ;; last candidate
2752 (goto-char (anything-get-previous-candidate-separator-pos))
2753 (delete-region (point-at-bol) (point-max)))
2754 (when (eobp)
2755 (goto-char (or (anything-get-previous-candidate-separator-pos)
2756 (point-min)))
2757 (forward-line 1)))
2759 (delete-region (point-at-bol) (1+ (point-at-eol)))
2760 (when (eobp) (forward-line -1))))
2761 (anything-mark-current-line)))
2763 (defun anything-edit-current-selection-internal (func)
2764 (with-anything-window
2765 (beginning-of-line)
2766 (let ((realvalue (get-text-property (point) 'anything-realvalue)))
2767 (funcall func)
2768 (beginning-of-line)
2769 (and realvalue
2770 (put-text-property (point) (point-at-eol)
2771 'anything-realvalue realvalue))
2772 (anything-mark-current-line))))
2774 (defmacro anything-edit-current-selection (&rest forms)
2775 "Evaluate FORMS at current selection in the anything buffer.
2776 You can edit the line."
2777 `(anything-edit-current-selection-internal
2778 (lambda () ,@forms)))
2779 (put 'anything-edit-current-selection 'lisp-indent-function 0)
2781 (defun anything-set-pattern (pattern &optional noupdate)
2782 "Set minibuffer contents to PATTERN.
2783 if optional NOUPDATE is non-nil, anything buffer is not changed."
2784 (with-selected-window (minibuffer-window)
2785 (delete-minibuffer-contents)
2786 (insert pattern))
2787 (when noupdate
2788 (setq anything-pattern pattern)
2789 (anything-hooks 'cleanup)
2790 (run-with-idle-timer 0 nil 'anything-hooks 'setup)))
2792 (defun anything-delete-minibuffer-contents ()
2793 "Same as `delete-minibuffer-contents' but this is a command."
2794 (interactive)
2795 (anything-set-pattern ""))
2796 (defalias 'anything-delete-minibuffer-content 'anything-delete-minibuffer-contents)
2798 ;; (@* "Built-in plug-in: type")
2799 (defun anything-compile-source--type (source)
2800 (anything-aif (assoc-default 'type source)
2801 (append source (assoc-default it anything-type-attributes) nil)
2802 source))
2804 ;; `define-anything-type-attribute' is public API.
2806 (defun anything-add-type-attribute (type definition)
2807 (anything-aif (assq type anything-type-attributes)
2808 (setq anything-type-attributes (delete it anything-type-attributes)))
2809 (push (cons type definition) anything-type-attributes))
2811 (defvar anything-types nil)
2812 (defun anything-document-type-attribute (type doc)
2813 (add-to-list 'anything-types type t)
2814 (put type 'anything-typeattrdoc
2815 (concat "- " (symbol-name type) "\n\n" doc "\n")))
2817 (defadvice documentation-property (after anything-document-type-attribute activate)
2818 "Hack to display type attributes' documentation as `anything-type-attributes' docstring."
2819 (when (eq symbol 'anything-type-attributes)
2820 (setq ad-return-value
2821 (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
2822 (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
2823 anything-types "\n")))))
2825 ;; (@* "Built-in plug-in: dummy")
2826 (defun anything-dummy-candidate (candidate source)
2827 ;; `source' is defined in filtered-candidate-transformer
2828 (list anything-pattern))
2830 (defun anything-compile-source--dummy (source)
2831 (if (assoc 'dummy source)
2832 (append source
2833 '((candidates "dummy")
2834 (accept-empty)
2835 (match identity)
2836 (filtered-candidate-transformer . anything-dummy-candidate)
2837 (disable-shortcuts)
2838 (volatile)))
2839 source))
2841 ;; (@* "Built-in plug-in: disable-shortcuts")
2842 (defvar anything-orig-enable-shortcuts nil)
2843 (defun anything-save-enable-shortcuts ()
2844 (anything-once
2845 (lambda () (setq anything-orig-enable-shortcuts anything-enable-shortcuts
2846 anything-enable-shortcuts nil))))
2847 (defun anything-compile-source--disable-shortcuts (source)
2848 (if (assoc 'disable-shortcuts source)
2849 (append `((init ,@(anything-mklist (assoc-default 'init source))
2850 anything-save-enable-shortcuts)
2851 (resume ,@(anything-mklist (assoc-default 'resume source))
2852 anything-save-enable-shortcuts)
2853 (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
2854 (lambda () (setq anything-enable-shortcuts
2855 anything-orig-enable-shortcuts))))
2856 source)
2857 source))
2859 ;; (@* "Built-in plug-in: candidates-in-buffer")
2860 (defun anything-candidates-in-buffer ()
2861 "Get candidates from the candidates buffer according to `anything-pattern'.
2863 BUFFER is `anything-candidate-buffer' by default. Each
2864 candidate must be placed in one line. This function is meant to
2865 be used in candidates-in-buffer or candidates attribute of an
2866 anything source. Especially fast for many (1000+) candidates.
2869 '((name . \"many files\")
2870 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
2871 (insert-many-filenames))))
2872 (search re-search-forward) ; optional
2873 (candidates-in-buffer)
2874 (type . file))
2876 +===============================================================+
2877 | The new way of making and narrowing candidates: Using buffers |
2878 +===============================================================+
2880 By default, `anything' makes candidates by evaluating the
2881 candidates function, then narrows them by `string-match' for each
2882 candidate.
2884 But this way is very slow for many candidates. The new way is
2885 storing all candidates in a buffer and narrowing them by
2886 `re-search-forward'. Search function is customizable by search
2887 attribute. The important point is that buffer processing is MUCH
2888 FASTER than string list processing and is the Emacs way.
2890 The init function writes all candidates to a newly-created
2891 candidate buffer. The candidates buffer is created or specified
2892 by `anything-candidate-buffer'. Candidates are stored in a line.
2894 The candidates function narrows all candidates, IOW creates a
2895 subset of candidates dynamically. It is the task of
2896 `anything-candidates-in-buffer'. As long as
2897 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
2898 sufficient in most cases.
2900 Note that `(candidates-in-buffer)' is shortcut of three attributes:
2901 (candidates . anything-candidates-in-buffer)
2902 (volatile)
2903 (match identity)
2904 And `(candidates-in-buffer . func)' is shortcut of three attributes:
2905 (candidates . func)
2906 (volatile)
2907 (match identity)
2908 The expansion is performed in `anything-get-sources'.
2910 The candidates-in-buffer attribute implies the volatile attribute.
2911 The volatile attribute is needed because `anything-candidates-in-buffer'
2912 creates candidates dynamically and need to be called everytime
2913 `anything-pattern' changes.
2915 Because `anything-candidates-in-buffer' plays the role of `match' attribute
2916 function, specifying `(match identity)' makes the source slightly faster.
2918 To customize `anything-candidates-in-buffer' behavior, use search,
2919 get-line and search-from-end attributes. See also `anything-sources' docstring.
2921 (declare (special source))
2922 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
2923 anything-pattern
2924 (or (assoc-default 'get-line source)
2925 #'buffer-substring-no-properties)
2926 ;; use external variable `source'.
2927 (or (assoc-default 'search source)
2928 (if (assoc 'search-from-end source)
2929 '(re-search-backward)
2930 '(re-search-forward)))
2931 (anything-candidate-number-limit source)
2932 (assoc 'search-from-end source)))
2934 (defun anything-candidates-in-buffer-1 (buffer pattern get-line-fn search-fns limit search-from-end)
2935 ;; buffer == nil when candidates buffer does not exist.
2936 (when buffer
2937 (with-current-buffer buffer
2938 (let ((start-point (if search-from-end (point-max) (point-min)))
2939 (endp (if search-from-end #'bobp #'eobp)))
2940 (goto-char (1- start-point))
2941 (if (string= pattern "")
2942 (anything-initial-candidates-from-candidate-buffer
2943 endp get-line-fn limit search-from-end)
2944 (anything-search-from-candidate-buffer
2945 pattern get-line-fn search-fns limit search-from-end
2946 start-point endp))))))
2948 (defun anything-point-is-moved (proc)
2949 "If point is moved after executing PROC, return t, otherwise nil."
2950 (/= (point) (progn (funcall proc) (point))))
2952 (defun anything-search-from-candidate-buffer (pattern get-line-fn search-fns
2953 limit search-from-end
2954 start-point endp)
2955 (let (buffer-read-only
2956 matches exit newmatches)
2957 (anything-search-from-candidate-buffer-internal
2958 (lambda ()
2959 (clrhash anything-cib-hash)
2960 (dolist (searcher search-fns)
2961 (goto-char start-point)
2962 (setq newmatches nil)
2963 (loop with item-count = 0
2964 while (funcall searcher pattern nil t)
2965 for cand = (funcall get-line-fn (point-at-bol) (point-at-eol))
2966 do (anything-accumulate-candidates-internal
2967 cand newmatches anything-cib-hash item-count limit)
2968 unless (anything-point-is-moved
2969 (lambda ()
2970 (if search-from-end
2971 (goto-char (1- (point-at-bol)))
2972 (forward-line 1))))
2973 return nil)
2974 (setq matches (append matches (nreverse newmatches)))
2975 (if exit (return)))
2976 (delq nil matches)))))
2978 (defun anything-initial-candidates-from-candidate-buffer (endp get-line-fn limit search-from-end)
2979 (delq nil (loop with next-line-fn =
2980 (if search-from-end
2981 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
2982 #'forward-line)
2983 until (funcall endp)
2984 for i from 1 to limit
2985 collect (funcall get-line-fn (point-at-bol) (point-at-eol))
2986 do (funcall next-line-fn 1))))
2988 (defun anything-search-from-candidate-buffer-internal (search-fn)
2989 (goto-char (point-min))
2990 (insert "\n")
2991 (goto-char (point-max))
2992 (insert "\n")
2993 (unwind-protect
2994 (funcall search-fn)
2995 (goto-char (point-min))
2996 (delete-char 1)
2997 (goto-char (1- (point-max)))
2998 (delete-char 1)
3000 (set-buffer-modified-p nil)))
3002 (defun anything-candidate-buffer (&optional create-or-buffer)
3003 "Register and return a buffer containing candidates of current source.
3004 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3005 then global candidates buffer.
3007 Acceptable values of CREATE-OR-BUFFER:
3009 - nil (omit)
3010 Only return the candidates buffer.
3011 - a buffer
3012 Register a buffer as a candidates buffer.
3013 - 'global
3014 Create a new global candidates buffer,
3015 named \" *anything candidates:SOURCE*\".
3016 - other non-nil value
3017 Create a new local candidates buffer,
3018 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
3020 (let* ((global-bname (format " *anything candidates:%s*" anything-source-name))
3021 (local-bname (format " *anything candidates:%s*%s"
3022 anything-source-name
3023 (buffer-name anything-current-buffer)))
3024 (register-func
3025 (lambda ()
3026 (setq anything-candidate-buffer-alist
3027 (cons (cons anything-source-name create-or-buffer)
3028 (delete (assoc anything-source-name
3029 anything-candidate-buffer-alist)
3030 anything-candidate-buffer-alist)))))
3031 (kill-buffers-func
3032 (lambda ()
3033 (loop for b in (buffer-list)
3034 if (string-match (format "^%s" (regexp-quote global-bname))
3035 (buffer-name b))
3036 do (kill-buffer b))))
3037 (create-func
3038 (lambda ()
3039 (with-current-buffer
3040 (get-buffer-create (if (eq create-or-buffer 'global)
3041 global-bname
3042 local-bname))
3043 (buffer-disable-undo)
3044 (erase-buffer)
3045 (font-lock-mode -1))))
3046 (return-func
3047 (lambda ()
3048 (or (get-buffer local-bname)
3049 (get-buffer global-bname)
3050 (anything-aif (assoc-default anything-source-name
3051 anything-candidate-buffer-alist)
3052 (and (buffer-live-p it) it))))))
3053 (when create-or-buffer
3054 (funcall register-func)
3055 (unless (bufferp create-or-buffer)
3056 (and (eq create-or-buffer 'global) (funcall kill-buffers-func))
3057 (funcall create-func)))
3058 (funcall return-func)))
3060 (defun anything-compile-source--candidates-in-buffer (source)
3061 (anything-aif (assoc 'candidates-in-buffer source)
3062 (append source
3063 `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
3064 (volatile) (match identity)))
3065 source))
3067 ;; (@* "Utility: resplit anything window")
3068 (defun anything-toggle-resplit-window ()
3069 "Toggle resplit anything window, vertically or horizontally."
3070 (interactive)
3071 (with-anything-window
3072 (let ((before-height (window-height)))
3073 (delete-window)
3074 (set-window-buffer
3075 (select-window (if (= (window-height) before-height)
3076 (split-window-vertically)
3077 (split-window-horizontally)))
3078 anything-buffer))))
3080 ;; (@* "Utility: select another action by key")
3081 (defun anything-select-nth-action (n)
3082 "Select the nth action for the currently selected candidate."
3083 (setq anything-saved-selection (anything-get-selection))
3084 (unless anything-saved-selection
3085 (error "Nothing is selected."))
3086 (setq anything-saved-action (anything-get-nth-action n (anything-get-action)))
3087 (anything-exit-minibuffer))
3089 (defun anything-get-nth-action (n action)
3090 (cond ((and (zerop n) (functionp action))
3091 action)
3092 ((listp action)
3093 (or (cdr (elt action n))
3094 (error "No such action")))
3095 ((and (functionp action) (< 0 n))
3096 (error "Sole action."))
3098 (error "Error in `anything-select-nth-action'."))))
3100 (defun anything-select-2nd-action ()
3101 "Select the 2nd action for the currently selected candidate."
3102 (interactive)
3103 (anything-select-nth-action 1))
3105 (defun anything-select-3rd-action ()
3106 "Select the 3rd action for the currently selected candidate."
3107 (interactive)
3108 (anything-select-nth-action 2))
3110 (defun anything-select-4th-action ()
3111 "Select the 4th action for the currently selected candidate."
3112 (interactive)
3113 (anything-select-nth-action 3))
3115 (defun anything-select-2nd-action-or-end-of-line ()
3116 "Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
3117 Otherwise goto the end of minibuffer."
3118 (interactive)
3119 (if (eolp)
3120 (anything-select-nth-action 1)
3121 (end-of-line)))
3123 ;; (@* "Utility: Persistent Action")
3124 (defmacro with-anything-display-same-window (&rest body)
3125 "Make `pop-to-buffer' and `display-buffer' display in the same window."
3126 `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
3127 ,@body))
3128 (put 'with-anything-display-same-window 'lisp-indent-function 0)
3130 (defvar anything-persistent-action-display-window nil)
3131 (defun anything-initialize-persistent-action ()
3132 (set (make-local-variable 'anything-persistent-action-display-window) nil))
3134 (defun* anything-execute-persistent-action (&optional (attr 'persistent-action))
3135 "If a candidate is selected then perform the associated action without quitting anything."
3136 (interactive)
3137 (anything-log "executing persistent-action")
3138 (save-selected-window
3139 (anything-select-persistent-action-window)
3140 (anything-log-eval (current-buffer))
3141 (let ((anything-in-persistent-action t))
3142 (with-anything-display-same-window
3143 (anything-execute-selection-action
3145 (or (assoc-default attr (anything-get-current-source))
3146 (anything-get-action))
3148 (anything-log-run-hook 'anything-after-persistent-action-hook)))))
3150 (defun anything-persistent-action-display-window ()
3151 (with-current-buffer anything-buffer
3152 (setq anything-persistent-action-display-window
3153 (cond ((window-live-p anything-persistent-action-display-window)
3154 anything-persistent-action-display-window)
3155 ((and anything-samewindow (one-window-p t))
3156 (split-window))
3157 ((get-buffer-window anything-current-buffer))
3159 (next-window (selected-window) 1))))))
3161 (defun anything-select-persistent-action-window ()
3162 (select-window (get-buffer-window (anything-buffer-get)))
3163 (select-window
3164 (setq minibuffer-scroll-window (anything-persistent-action-display-window))))
3166 (defun anything-persistent-action-display-buffer (buf &optional not-this-window)
3167 "Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
3168 If `anything-persistent-action-use-special-display' is non-nil and
3169 BUF is to be displayed by `special-display-function', use it.
3170 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
3171 (let* ((name (buffer-name buf))
3172 display-buffer-function pop-up-windows
3173 (same-window-regexps
3174 (unless (and anything-persistent-action-use-special-display
3175 (or (member name
3176 (mapcar (lambda (x) (or (car-safe x) x))
3177 special-display-buffer-names))
3178 (remove-if-not
3179 (lambda (x) (string-match (or (car-safe x) x) name))
3180 special-display-regexps)))
3181 '("."))))
3182 (display-buffer buf not-this-window)))
3184 ;; scroll-other-window(-down)? for persistent-action
3185 (defun anything-scroll-other-window-base (command)
3186 (with-selected-window (anything-persistent-action-display-window)
3187 (funcall command anything-scroll-amount)))
3189 (defun anything-scroll-other-window ()
3190 "Scroll other window (not *Anything* window) upward."
3191 (interactive)
3192 (anything-scroll-other-window-base 'scroll-up))
3193 (defun anything-scroll-other-window-down ()
3194 "Scroll other window (not *Anything* window) downward."
3195 (interactive)
3196 (anything-scroll-other-window-base 'scroll-down))
3198 ;; (@* "Utility: Visible Mark")
3199 (defface anything-visible-mark
3200 '((((min-colors 88) (background dark))
3201 (:background "green1" :foreground "black"))
3202 (((background dark)) (:background "green" :foreground "black"))
3203 (((min-colors 88)) (:background "green1"))
3204 (t (:background "green")))
3205 "Face for visible mark."
3206 :group 'anything)
3207 (defvar anything-visible-mark-face 'anything-visible-mark)
3208 (defvar anything-visible-mark-overlays nil)
3210 (defun anything-clear-visible-mark ()
3211 (with-current-buffer (anything-buffer-get)
3212 (mapc 'delete-overlay anything-visible-mark-overlays)
3213 (set (make-local-variable 'anything-visible-mark-overlays) nil)))
3214 (add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
3216 (defvar anything-c-marked-candidate-list nil
3217 "[OBSOLETE] DO NOT USE!!")
3218 (defvar anything-marked-candidates nil
3219 "Marked candadates. List of (source . real) pair.")
3221 (defun anything-this-visible-mark ()
3222 (loop for o in anything-visible-mark-overlays
3223 when (equal (point-at-bol) (overlay-start o))
3224 do (return o)))
3226 (defun anything-delete-visible-mark (overlay)
3227 (setq anything-c-marked-candidate-list
3228 (remove (anything-current-line-contents) anything-c-marked-candidate-list))
3229 (setq anything-marked-candidates
3230 (remove
3231 (cons (anything-get-current-source) (anything-get-selection))
3232 anything-marked-candidates))
3233 (delete-overlay overlay)
3234 (setq anything-visible-mark-overlays
3235 (delq overlay anything-visible-mark-overlays)))
3237 (defun anything-make-visible-mark ()
3238 (let ((o (make-overlay (point-at-bol) (1+ (point-at-eol)))))
3239 (overlay-put o 'face anything-visible-mark-face)
3240 (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3241 (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3242 (add-to-list 'anything-visible-mark-overlays o))
3243 (push (anything-current-line-contents) anything-c-marked-candidate-list)
3244 (push (cons (anything-get-current-source) (anything-get-selection))
3245 anything-marked-candidates))
3247 (defun anything-toggle-visible-mark ()
3248 "Toggle anything visible mark at point."
3249 (interactive)
3250 (with-anything-window
3251 (anything-aif (anything-this-visible-mark)
3252 (anything-delete-visible-mark it)
3253 (anything-make-visible-mark))
3254 (anything-next-line)))
3256 (defun anything-display-all-visible-marks ()
3257 "Show all `anything' visible marks strings."
3258 (interactive)
3259 (with-anything-window
3260 (lexical-let ((overlays (reverse anything-visible-mark-overlays)))
3261 (anything-run-after-quit
3262 (lambda ()
3263 (with-output-to-temp-buffer "*anything visible marks*"
3264 (dolist (o overlays) (princ (overlay-get o 'string)))))))))
3266 (defun anything-marked-candidates ()
3267 "Marked candidates (real value) of current source if any,
3268 otherwise 1-element list of current selection.
3270 It is analogous to `dired-get-marked-files'."
3271 (with-current-buffer (anything-buffer-get)
3272 (let ((cands
3273 (if anything-marked-candidates
3274 (loop with current-src = (anything-get-current-source)
3275 for (source . real) in (reverse anything-marked-candidates)
3276 when (equal current-src source)
3277 collect (anything-coerce-selection real source))
3278 (list (anything-get-selection)))))
3279 (anything-log-eval cands)
3280 cands)))
3282 (defun anything-reset-marked-candidates ()
3283 (with-current-buffer (anything-buffer-get)
3284 (set (make-local-variable 'anything-c-marked-candidate-list) nil)
3285 (set (make-local-variable 'anything-marked-candidates) nil)))
3287 (add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
3288 ;; (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3290 (defun anything-current-source-name= (name)
3291 (save-excursion
3292 (goto-char (anything-get-previous-header-pos))
3293 (equal name (anything-current-line-contents))))
3295 (defun anything-revive-visible-mark ()
3296 (with-current-buffer anything-buffer
3297 (dolist (o anything-visible-mark-overlays)
3298 (goto-char (point-min))
3299 (while (and (search-forward (overlay-get o 'string) nil t)
3300 (anything-current-source-name= (overlay-get o 'source)))
3301 ;; Now the next line of visible mark
3302 (move-overlay o (point-at-bol 0) (1+ (point-at-eol 0)))))))
3303 (add-hook 'anything-update-hook 'anything-revive-visible-mark)
3305 (defun anything-next-point-in-list (curpos points &optional prev)
3306 (cond
3307 ;; rule out special cases
3308 ((null points) curpos)
3309 ((and prev (< curpos (car points))) curpos)
3310 ((< (car (last points)) curpos)
3311 (if prev (car (last points)) curpos))
3313 (nth (if prev
3314 (loop for pt in points
3315 for i from 0
3316 if (<= curpos pt)
3317 do (return (1- i)))
3318 (loop for pt in points
3319 for i from 0
3320 if (< curpos pt)
3321 do (return i)))
3322 points))))
3324 (defun anything-next-visible-mark (&optional prev)
3325 "Move next anything visible mark."
3326 (interactive)
3327 (with-anything-window
3328 (goto-char (anything-next-point-in-list
3329 (point)
3330 (sort (mapcar 'overlay-start anything-visible-mark-overlays) '<)
3331 prev))
3332 (anything-mark-current-line)))
3334 (defun anything-prev-visible-mark ()
3335 "Move previous anything visible mark."
3336 (interactive)
3337 (anything-next-visible-mark t))
3339 ;; (@* "Utility: `find-file' integration")
3340 (defun anything-quit-and-find-file ()
3341 "Drop into `find-file' from `anything' like `iswitchb-find-file'.
3342 If current selection is a buffer or a file, `find-file' from its directory."
3343 (interactive)
3344 (anything-run-after-quit
3345 (lambda (f)
3346 (if (file-exists-p f)
3347 (let ((default-directory (file-name-directory f)))
3348 (call-interactively 'find-file))
3349 (call-interactively 'find-file)))
3350 (anything-aif (get-buffer (anything-get-selection))
3351 (buffer-file-name it)
3352 (expand-file-name (anything-get-selection)))))
3354 ;; (@* "Utility: Selection Paste")
3355 (defun anything-yank-selection ()
3356 "Set minibuffer contents to current selection."
3357 (interactive)
3358 (anything-set-pattern (anything-get-selection nil t)))
3360 (defun anything-kill-selection-and-quit ()
3361 "Store current selection to kill ring.
3362 You can paste it by typing C-y."
3363 (interactive)
3364 (anything-run-after-quit
3365 (lambda (sel)
3366 (kill-new sel)
3367 (message "Killed: %s" sel))
3368 (anything-get-selection nil t)))
3371 ;; (@* "Utility: Automatical execution of persistent-action")
3372 (add-to-list 'minor-mode-alist '(anything-follow-mode " AFollow"))
3373 (defun anything-follow-mode ()
3374 "If this mode is on, persistent action is executed everytime the cursor is moved."
3375 (interactive)
3376 (with-current-buffer anything-buffer
3377 (setq anything-follow-mode (not anything-follow-mode))
3378 (message "anything-follow-mode is %s"
3379 (if anything-follow-mode "enabled" "disabled"))))
3381 (defun anything-follow-execute-persistent-action-maybe ()
3382 "Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
3383 (and (not (get-buffer-window anything-action-buffer 'visible))
3384 (buffer-local-value 'anything-follow-mode
3385 (get-buffer-create anything-buffer))
3386 (sit-for anything-input-idle-delay)
3387 (anything-window)
3388 (anything-get-selection)
3389 (save-excursion
3390 (anything-execute-persistent-action))))
3392 ;; (@* "Utility: Migrate `anything-sources' to my-anything command")
3393 (defun anything-migrate-sources ()
3394 "Help to migrate to new `anything' way."
3395 (interactive)
3396 (with-current-buffer (get-buffer-create "*anything migrate*")
3397 (erase-buffer)
3398 (insert (format "\
3399 Setting `anything-sources' directly is not good because
3400 `anything' is not for one command. For now, interactive use of
3401 `anything' (M-x anything) is only for demonstration purpose.
3402 So you should define commands calling `anything'.
3403 I help you to migrate to the new way.
3405 The code below is automatically generated from current
3406 `anything-sources' value. You can use the `my-anything' command
3407 now!
3409 Copy and paste it to your .emacs. Then substitute `my-anything'
3410 for `anything' bindings in all `define-key', `local-set-key' and
3411 `global-set-key' calls.
3413 \(defun my-anything ()
3414 \"Anything command for you.
3416 It is automatically generated by `anything-migrate-sources'.\"
3417 (interactive)
3418 (anything-other-buffer
3420 \"*my-anything*\"))
3421 " anything-sources))
3422 (eval-last-sexp nil)
3423 (substitute-key-definition 'anything 'my-anything global-map)
3424 (pop-to-buffer (current-buffer))))
3426 ;; (@* "Utility: Incremental search within results (unmaintained)")
3428 (defvar anything-isearch-original-global-map nil
3429 "Original global map before Anything isearch is started.")
3431 (defvar anything-isearch-original-message-timeout nil
3432 "Original message timeout before Anything isearch is started.")
3434 (defvar anything-isearch-pattern nil
3435 "The current isearch pattern.")
3437 (defvar anything-isearch-message-suffix ""
3438 "Message suffix indicating the current state of the search.")
3440 (defvar anything-isearch-original-point nil
3441 "Original position of point before isearch is started.")
3443 (defvar anything-isearch-original-window nil
3444 "Original selected window before isearch is started.")
3446 (defvar anything-isearch-original-cursor-in-non-selected-windows nil
3447 "Original value of cursor-in-non-selected-windows before isearch is started.")
3449 (defvar anything-isearch-original-deferred-action-list nil
3450 "Original value of deferred-action-list before isearch is started.")
3452 (defvar anything-isearch-match-positions nil
3453 "Stack of positions of matches or non-matches.
3455 It's a list of plists with two properties: `event', the last user
3456 event, `start', the start position of the current match, and
3457 `pos', the position of point after that event.
3459 The value of `event' can be the following symbols: `char' if a
3460 character was typed, `error' if a non-matching character was
3461 typed, `search' if a forward search had to be done after a
3462 character, and `search-again' if a search was done for the next
3463 occurrence of the current pattern.")
3465 (defvar anything-isearch-match-start nil
3466 "Start position of the current match.")
3469 (defun anything-isearch ()
3470 "Start incremental search within results. (UNMAINTAINED)"
3471 (interactive)
3472 (if (anything-empty-buffer-p (anything-buffer-get))
3473 (message "There are no results.")
3475 (setq anything-isearch-original-message-timeout minibuffer-message-timeout)
3476 (setq minibuffer-message-timeout nil)
3478 (setq anything-isearch-original-global-map global-map)
3480 (condition-case nil
3481 (progn
3482 (setq anything-isearch-original-window (selected-window))
3483 (select-window (anything-window))
3484 (setq cursor-type t)
3486 (setq anything-isearch-original-deferred-action-list
3487 (default-value 'deferred-action-list))
3488 (setq-default deferred-action-list nil)
3489 (add-hook 'deferred-action-list 'anything-isearch-post-command)
3491 (use-global-map anything-isearch-map)
3492 (setq overriding-terminal-local-map anything-isearch-map)
3494 (setq anything-isearch-pattern "")
3496 (setq anything-isearch-original-cursor-in-non-selected-windows
3497 cursor-in-non-selected-windows)
3498 (setq cursor-in-non-selected-windows nil)
3500 (setq anything-isearch-original-point (point-marker))
3501 (goto-char (point-min))
3502 (forward-line)
3503 (anything-mark-current-line)
3505 (setq anything-isearch-match-positions nil)
3506 (setq anything-isearch-match-start (point-marker))
3508 (if anything-isearch-overlay
3509 ;; make sure the overlay belongs to the anything buffer
3510 (move-overlay anything-isearch-overlay (point-min) (point-min)
3511 (get-buffer (anything-buffer-get)))
3513 (setq anything-isearch-overlay (make-overlay (point-min) (point-min)))
3514 (overlay-put anything-isearch-overlay 'face anything-isearch-match-face))
3516 (setq anything-isearch-message-suffix
3517 (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))
3519 (error (anything-isearch-cleanup)))))
3522 (defun anything-isearch-post-command ()
3523 "Print the current pattern after every command."
3524 (anything-isearch-message)
3525 (when (anything-window)
3526 (with-anything-window
3527 (move-overlay anything-isearch-overlay anything-isearch-match-start (point)
3528 (get-buffer (anything-buffer-get))))))
3531 (defun anything-isearch-printing-char ()
3532 "Add printing char to the pattern."
3533 (interactive)
3534 (let ((char (char-to-string last-command-event)))
3535 (setq anything-isearch-pattern (concat anything-isearch-pattern char))
3537 (with-anything-window
3538 (if (looking-at char)
3539 (progn
3540 (push (list 'event 'char
3541 'start anything-isearch-match-start
3542 'pos (point-marker))
3543 anything-isearch-match-positions)
3544 (forward-char))
3546 (let ((start (point)))
3547 (while (and (re-search-forward anything-isearch-pattern nil t)
3548 (anything-pos-header-line-p)))
3549 (if (or (anything-pos-header-line-p)
3550 (eq start (point)))
3551 (progn
3552 (goto-char start)
3553 (push (list 'event 'error
3554 'start anything-isearch-match-start
3555 'pos (point-marker))
3556 anything-isearch-match-positions))
3558 (push (list 'event 'search
3559 'start anything-isearch-match-start
3560 'pos (copy-marker start))
3561 anything-isearch-match-positions)
3562 (setq anything-isearch-match-start
3563 (copy-marker (match-beginning 0))))))
3565 (anything-mark-current-line))))
3568 (defun anything-isearch-again ()
3569 "Search again for the current pattern"
3570 (interactive)
3571 (if (equal anything-isearch-pattern "")
3572 (setq anything-isearch-message-suffix "no pattern yet")
3574 (with-anything-window
3575 (let ((start (point)))
3576 (while (and (re-search-forward anything-isearch-pattern nil t)
3577 (anything-pos-header-line-p)))
3578 (if (or (anything-pos-header-line-p)
3579 (eq start (point)))
3580 (progn
3581 (goto-char start)
3582 (unless (eq 'error
3583 (plist-get (car anything-isearch-match-positions)
3584 'event))
3585 (setq anything-isearch-message-suffix "no more matches")))
3587 (push (list 'event 'search-again
3588 'start anything-isearch-match-start
3589 'pos (copy-marker start))
3590 anything-isearch-match-positions)
3591 (setq anything-isearch-match-start (copy-marker (match-beginning 0)))
3593 (anything-mark-current-line))))))
3596 (defun anything-isearch-delete ()
3597 "Undo last event."
3598 (interactive)
3599 (unless (equal anything-isearch-pattern "")
3600 (let ((last (pop anything-isearch-match-positions)))
3601 (unless (eq 'search-again (plist-get last 'event))
3602 (setq anything-isearch-pattern
3603 (substring anything-isearch-pattern 0 -1)))
3605 (with-anything-window
3606 (goto-char (plist-get last 'pos))
3607 (setq anything-isearch-match-start (plist-get last 'start))
3608 (anything-mark-current-line)))))
3611 (defun anything-isearch-default-action ()
3612 "Execute the default action for the selected candidate."
3613 (interactive)
3614 (anything-isearch-cleanup)
3615 (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))
3618 (defun anything-isearch-select-action ()
3619 "Choose an action for the selected candidate."
3620 (interactive)
3621 (anything-isearch-cleanup)
3622 (with-anything-window
3623 (anything-select-action)))
3626 (defun anything-isearch-cancel ()
3627 "Cancel Anything isearch."
3628 (interactive)
3629 (anything-isearch-cleanup)
3630 (when (anything-window)
3631 (with-anything-window
3632 (goto-char anything-isearch-original-point)
3633 (anything-mark-current-line))))
3636 (defun anything-isearch-cleanup ()
3637 "Clean up the mess."
3638 (setq minibuffer-message-timeout anything-isearch-original-message-timeout)
3639 (with-current-buffer (anything-buffer-get)
3640 (setq overriding-terminal-local-map nil)
3641 (setq cursor-type nil)
3642 (setq cursor-in-non-selected-windows
3643 anything-isearch-original-cursor-in-non-selected-windows))
3644 (when anything-isearch-original-window
3645 (select-window anything-isearch-original-window))
3647 (use-global-map anything-isearch-original-global-map)
3648 (setq-default deferred-action-list
3649 anything-isearch-original-deferred-action-list)
3650 (when (overlayp anything-isearch-overlay)
3651 (delete-overlay anything-isearch-overlay)))
3654 (defun anything-isearch-message ()
3655 "Print prompt."
3656 (if (and (equal anything-isearch-message-suffix "")
3657 (eq (plist-get (car anything-isearch-match-positions) 'event)
3658 'error))
3659 (setq anything-isearch-message-suffix "failing"))
3661 (unless (equal anything-isearch-message-suffix "")
3662 (setq anything-isearch-message-suffix
3663 (concat " [" anything-isearch-message-suffix "]")))
3665 (message (concat "Search within results: "
3666 anything-isearch-pattern
3667 anything-isearch-message-suffix))
3669 (setq anything-isearch-message-suffix ""))
3672 ;; (@* "Utility: Iswitchb integration (unmaintained)")
3674 (defvar anything-iswitchb-candidate-selected nil
3675 "Indicates whether an anything candidate is selected from iswitchb.")
3677 (defvar anything-iswitchb-frame-configuration nil
3678 "Saved frame configuration, before anything buffer was displayed.")
3680 (defvar anything-iswitchb-saved-keys nil
3681 "The original in iswitchb before binding anything keys.")
3684 (defun anything-iswitchb-setup ()
3685 "Integrate anything completion into iswitchb (UNMAINTAINED).
3687 If the user is idle for `anything-iswitchb-idle-delay' seconds
3688 after typing something into iswitchb then anything candidates are
3689 shown for the current iswitchb input.
3691 ESC cancels anything completion and returns to normal iswitchb.
3693 Some key bindings in `anything-map' are modified.
3694 See also `anything-iswitchb-setup-keys'."
3695 (interactive)
3697 (require 'iswitchb)
3699 ;; disable timid completion during iswitchb
3700 (put 'iswitchb-buffer 'timid-completion 'disabled)
3701 (add-hook 'minibuffer-setup-hook 'anything-iswitchb-minibuffer-setup)
3703 (defadvice iswitchb-visit-buffer
3704 (around anything-iswitchb-visit-buffer activate)
3705 (if anything-iswitchb-candidate-selected
3706 (anything-execute-selection-action)
3707 ad-do-it))
3709 (defadvice iswitchb-possible-new-buffer
3710 (around anything-iswitchb-possible-new-buffer activate)
3711 (if anything-iswitchb-candidate-selected
3712 (anything-execute-selection-action)
3713 ad-do-it))
3714 (anything-iswitchb-setup-keys)
3715 (message "Iswitchb integration is activated."))
3717 (defun anything-iswitchb-setup-keys ()
3718 "Modify `anything-map' for anything-iswitchb users.
3720 C-p is used instead of M-p, because anything uses ESC
3721 (currently hardcoded) for `anything-iswitchb-cancel-anything' and
3722 Emacs handles ESC and Meta as synonyms, so ESC overrides
3723 other commands with Meta prefix.
3725 Note that iswitchb uses M-p and M-n by default for history
3726 navigation, so you should bind C-p and C-n in
3727 `iswitchb-mode-map' if you use the history keys and don't want
3728 to use different keys for iswitchb while anything is not yet
3729 kicked in. These keys are not bound automatically by anything
3730 in `iswitchb-mode-map' because they (C-n at least) already have
3731 a standard iswitchb binding which you might be accustomed to.
3733 Binding M-s is used instead of C-s, because C-s has a binding in
3734 iswitchb. You can rebind it AFTER `anything-iswitchb-setup'.
3736 Unbind C-r to prevent problems during anything-isearch."
3737 (define-key anything-map (kbd "C-s") nil)
3738 (define-key anything-map (kbd "M-p") nil)
3739 (define-key anything-map (kbd "M-n") nil)
3740 (define-key anything-map (kbd "M-v") nil)
3741 (define-key anything-map (kbd "C-v") nil)
3742 (define-key anything-map (kbd "C-p") 'anything-previous-history-element)
3743 (define-key anything-map (kbd "C-n") 'anything-next-history-element)
3744 (define-key anything-map (kbd "M-s") nil)
3745 (define-key anything-map (kbd "M-s") 'anything-isearch)
3746 (define-key anything-map (kbd "C-r") nil))
3748 (defun anything-iswitchb-minibuffer-setup ()
3749 (when (eq this-command 'iswitchb-buffer)
3750 (add-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
3752 (setq anything-iswitchb-frame-configuration nil)
3753 (setq anything-iswitchb-candidate-selected nil)
3754 (add-hook 'anything-update-hook 'anything-iswitchb-handle-update)
3756 (anything-initialize)
3758 (add-hook 'deferred-action-list 'anything-iswitchb-check-input)))
3761 (defun anything-iswitchb-minibuffer-exit ()
3762 (remove-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
3763 (remove-hook 'deferred-action-list 'anything-iswitchb-check-input)
3764 (remove-hook 'anything-update-hook 'anything-iswitchb-handle-update)
3766 (anything-cleanup)
3768 (when anything-iswitchb-frame-configuration
3769 (anything-set-frame/window-configuration
3770 anything-iswitchb-frame-configuration)
3771 (setq anything-iswitchb-frame-configuration nil)))
3774 (defun anything-iswitchb-check-input ()
3775 "Extract iswitchb input and check if it needs to be handled."
3776 (declare (special iswitchb-text))
3777 (if (or anything-iswitchb-frame-configuration
3778 (sit-for anything-iswitchb-idle-delay))
3779 (anything-check-new-input iswitchb-text)))
3782 (defun anything-iswitchb-handle-update ()
3783 "Pop up the anything buffer if it's not empty and it's not
3784 shown yet and bind anything commands in iswitchb."
3785 (unless (or (anything-empty-buffer-p anything-buffer)
3786 anything-iswitchb-frame-configuration)
3787 (setq anything-iswitchb-frame-configuration
3788 (anything-current-frame/window-configuration))
3790 (save-selected-window
3791 (if (not anything-samewindow)
3792 (pop-to-buffer anything-buffer)
3794 (select-window (get-lru-window))
3795 (switch-to-buffer anything-buffer)))
3797 (with-current-buffer (window-buffer (active-minibuffer-window))
3798 (let* ((anything-prefix "anything-")
3799 (prefix-length (length anything-prefix))
3800 (commands
3801 (delete-dups
3802 (remove-if 'null
3803 (mapcar
3804 (lambda (binding)
3805 (let ((command (cdr binding)))
3806 (when (and (symbolp command)
3807 (eq (compare-strings
3808 anything-prefix
3809 0 prefix-length
3810 (symbol-name command)
3811 0 prefix-length)
3813 command)))
3814 (cdr anything-map)))))
3815 (bindings (mapcar (lambda (command)
3816 (cons command
3817 (where-is-internal command anything-map)))
3818 commands)))
3820 (push (list 'anything-iswitchb-cancel-anything (kbd "<ESC>"))
3821 bindings)
3823 (setq anything-iswitchb-saved-keys nil)
3825 (let* ((iswitchb-prefix "iswitchb-")
3826 (prefix-length (length iswitchb-prefix)))
3827 (dolist (binding bindings)
3828 (dolist (key (cdr binding))
3829 (let ((old-command (lookup-key (current-local-map) key)))
3830 (unless (and anything-iswitchb-dont-touch-iswithcb-keys
3831 (symbolp old-command)
3832 (eq (compare-strings iswitchb-prefix
3833 0 prefix-length
3834 (symbol-name old-command)
3835 0 prefix-length)
3837 (push (cons key old-command)
3838 anything-iswitchb-saved-keys)
3839 (define-key (current-local-map) key (car binding)))))))))))
3842 (defun anything-iswitchb-cancel-anything ()
3843 "Cancel anything completion and return to standard iswitchb."
3844 (interactive)
3845 (save-excursion
3846 (dolist (binding anything-iswitchb-saved-keys)
3847 (define-key (current-local-map) (car binding) (cdr binding)))
3848 (anything-iswitchb-minibuffer-exit)))
3850 ;; (@* "Compatibility")
3852 ;; Copied assoc-default from XEmacs version 21.5.12
3853 (unless (fboundp 'assoc-default)
3854 (defun assoc-default (key alist &optional test default)
3855 "Find object KEY in a pseudo-alist ALIST.
3856 ALIST is a list of conses or objects. Each element (or the element's car,
3857 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
3858 If that is non-nil, the element matches;
3859 then `assoc-default' returns the element's cdr, if it is a cons,
3860 or DEFAULT if the element is not a cons.
3862 If no element matches, the value is nil.
3863 If TEST is omitted or nil, `equal' is used."
3864 (let (found (tail alist) value)
3865 (while (and tail (not found))
3866 (let ((elt (car tail)))
3867 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
3868 (setq found t value (if (consp elt) (cdr elt) default))))
3869 (setq tail (cdr tail)))
3870 value)))
3872 ;; Function not available in XEmacs,
3873 (unless (fboundp 'minibuffer-contents)
3874 (defun minibuffer-contents ()
3875 "Return the user input in a minbuffer as a string.
3876 The current buffer must be a minibuffer."
3877 (field-string (point-max)))
3879 (defun delete-minibuffer-contents ()
3880 "Delete all user input in a minibuffer.
3881 The current buffer must be a minibuffer."
3882 (delete-field (point-max))))
3884 ;; Function not available in older Emacs (<= 22.1).
3885 (unless (fboundp 'buffer-chars-modified-tick)
3886 (defun buffer-chars-modified-tick (&optional buffer)
3887 "Return BUFFER's character-change tick counter.
3888 Each buffer has a character-change tick counter, which is set to the
3889 value of the buffer's tick counter (see `buffer-modified-tick'), each
3890 time text in that buffer is inserted or deleted. By comparing the
3891 values returned by two individual calls of `buffer-chars-modified-tick',
3892 you can tell whether a character change occurred in that buffer in
3893 between these calls. No argument or nil as argument means use current
3894 buffer as BUFFER."
3895 (with-current-buffer (or buffer (current-buffer))
3896 (if (listp buffer-undo-list)
3897 (length buffer-undo-list)
3898 (buffer-modified-tick)))))
3900 ;; (@* "CUA workaround")
3901 (defadvice cua-delete-region (around anything-avoid-cua activate)
3902 (ignore-errors ad-do-it))
3903 (defadvice copy-region-as-kill (around anything-avoid-cua activate)
3904 (if cua-mode
3905 (ignore-errors ad-do-it)
3906 ad-do-it))
3909 ;;(@* "Attribute Documentation")
3910 (defun anything-describe-anything-attribute (anything-attribute)
3911 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol)."
3912 (interactive (list (intern
3913 (completing-read
3914 "Describe anything attribute: "
3915 (mapcar 'symbol-name anything-additional-attributes)))))
3916 (with-output-to-temp-buffer "*Help*"
3917 (princ (get anything-attribute 'anything-attrdoc))))
3919 (anything-document-attribute 'name "mandatory"
3920 " The name of the source. It is also the heading which appears
3921 above the list of matches from the source. Must be unique. ")
3922 (anything-document-attribute 'header-name "optional"
3923 " A function returning the display string of the header. Its
3924 argument is the name of the source. This attribute is useful to
3925 add an additional information with the source name. ")
3926 (anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
3927 " Specifies how to retrieve candidates from the source. It can
3928 either be a variable name, a function called with no parameters
3929 or the actual list of candidates.
3931 The list must be a list whose members are strings, symbols
3932 or (DISPLAY . REAL) pairs.
3934 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
3935 in the Anything buffer, but the REAL one is used as action
3936 argument when the candidate is selected. This allows a more
3937 readable presentation for candidates which would otherwise be,
3938 for example, too long or have a common part shared with other
3939 candidates which can be safely replaced with an abbreviated
3940 string for display purposes.
3942 Note that if the (DISPLAY . REAL) form is used then pattern
3943 matching is done on the displayed string, not on the real
3944 value.
3946 If the candidates have to be retrieved asynchronously (for
3947 example, by an external command which takes a while to run)
3948 then the function should start the external command
3949 asynchronously and return the associated process object.
3950 Anything will take care of managing the process (receiving the
3951 output from it, killing it if necessary, etc.). The process
3952 should return candidates matching the current pattern (see
3953 variable `anything-pattern'.)
3955 Note that currently results from asynchronous sources appear
3956 last in the anything buffer regardless of their position in
3957 `anything-sources'. ")
3958 (anything-document-attribute 'action "mandatory if type attribute is not provided"
3959 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
3960 FUNCTION is called with one parameter: the selected candidate.
3962 An action other than the default can be chosen from this list
3963 of actions for the currently selected candidate (by default
3964 with TAB). The DISPLAY string is shown in the completions
3965 buffer and the FUNCTION is invoked when an action is
3966 selected. The first action of the list is the default. ")
3967 (anything-document-attribute 'coerce "optional"
3968 " It's a function called with one argument: the selected candidate.
3970 This function is intended for type convertion.
3971 In normal case, the selected candidate (string) is passed to action function.
3972 If coerce function is specified, it is called just before action function.
3974 Example: converting string to symbol
3975 (coerce . intern)
3977 (anything-document-attribute 'type "optional if action attribute is provided"
3978 " Indicates the type of the items the source returns.
3980 Merge attributes not specified in the source itself from
3981 `anything-type-attributes'.
3983 This attribute is implemented by plug-in. ")
3984 (anything-document-attribute 'init "optional"
3985 " Function called with no parameters when anything is started. It
3986 is useful for collecting current state information which can be
3987 used to create the list of candidates later.
3989 For example, if a source needs to work with the current
3990 directory then it can store its value here, because later
3991 anything does its job in the minibuffer and in the
3992 `anything-buffer' and the current directory can be different
3993 there. ")
3994 (anything-document-attribute 'delayed-init "optional"
3995 " Function called with no parameters before candidate function is
3996 called. It is similar with `init' attribute, but its
3997 evaluation is deferred. It is useful to combine with ")
3998 (anything-document-attribute 'match "optional"
3999 " List of functions called with one parameter: a candidate. The
4000 function should return non-nil if the candidate matches the
4001 current pattern (see variable `anything-pattern').
4003 This attribute allows the source to override the default
4004 pattern matching based on `string-match'. It can be used, for
4005 example, to implement a source for file names and do the
4006 pattern matching on the basename of files, since it's more
4007 likely one is typing part of the basename when searching for a
4008 file, instead of some string anywhere else in its path.
4010 If the list contains more than one function then the list of
4011 matching candidates from the source is constructed by appending
4012 the results after invoking the first function on all the
4013 potential candidates, then the next function, and so on. The
4014 matching candidates supplied by the first function appear first
4015 in the list of results and then results from the other
4016 functions, respectively.
4018 This attribute has no effect for asynchronous sources (see
4019 attribute `candidates'), since they perform pattern matching
4020 themselves. ")
4021 (anything-document-attribute 'candidate-transformer "optional"
4022 " It's a function or a list of functions called with one argument
4023 when the completion list from the source is built. The argument
4024 is the list of candidates retrieved from the source. The
4025 function should return a transformed list of candidates which
4026 will be used for the actual completion. If it is a list of
4027 functions, it calls each function sequentially.
4029 This can be used to transform or remove items from the list of
4030 candidates.
4032 Note that `candidates' is run already, so the given transformer
4033 function should also be able to handle candidates with (DISPLAY
4034 . REAL) format. ")
4035 (anything-document-attribute 'filtered-candidate-transformer "optional"
4036 " It has the same format as `candidate-transformer', except the
4037 function is called with two parameters: the candidate list and
4038 the source.
4040 This transformer is run on the candidate list which is already
4041 filtered by the current pattern. While `candidate-transformer'
4042 is run only once, it is run every time the input pattern is
4043 changed.
4045 It can be used to transform the candidate list dynamically, for
4046 example, based on the current pattern.
4048 In some cases it may also be more efficent to perform candidate
4049 transformation here, instead of with `candidate-transformer'
4050 even if this transformation is done every time the pattern is
4051 changed. For example, if a candidate set is very large then
4052 `candidate-transformer' transforms every candidate while only
4053 some of them will actually be dislpayed due to the limit
4054 imposed by `anything-candidate-number-limit'.
4056 Note that `candidates' and `candidate-transformer' is run
4057 already, so the given transformer function should also be able
4058 to handle candidates with (DISPLAY . REAL) format.
4060 This option has no effect for asynchronous sources. (Not yet,
4061 at least. ")
4062 (anything-document-attribute 'action-transformer "optional"
4063 " It's a function or a list of functions called with two
4064 arguments when the action list from the source is
4065 assembled. The first argument is the list of actions, the
4066 second is the current selection. If it is a list of functions,
4067 it calls each function sequentially.
4069 The function should return a transformed action list.
4071 This can be used to customize the list of actions based on the
4072 currently selected candidate. ")
4073 (anything-document-attribute 'pattern-transformer "optional"
4074 " It's a function or a list of functions called with one argument
4075 before computing matches. Its argument is `anything-pattern'.
4076 Functions should return transformed `anything-pattern'.
4078 It is useful to change interpretation of `anything-pattern'. ")
4079 (anything-document-attribute 'delayed "optional"
4080 " Candidates from the source are shown only if the user stops
4081 typing and is idle for `anything-idle-delay' seconds. ")
4082 (anything-document-attribute 'volatile "optional"
4083 " Indicates the source assembles the candidate list dynamically,
4084 so it shouldn't be cached within a single Anything
4085 invocation. It is only applicable to synchronous sources,
4086 because asynchronous sources are not cached. ")
4087 (anything-document-attribute 'requires-pattern "optional"
4088 " If present matches from the source are shown only if the
4089 pattern is not empty. Optionally, it can have an integer
4090 parameter specifying the required length of input which is
4091 useful in case of sources with lots of candidates. ")
4092 (anything-document-attribute 'persistent-action "optional"
4093 " Function called with one parameter; the selected candidate.
4095 An action performed by `anything-execute-persistent-action'.
4096 If none, use the default action. ")
4097 (anything-document-attribute 'candidates-in-buffer "optional"
4098 " Shortcut attribute for making and narrowing candidates using
4099 buffers. This newly-introduced attribute prevents us from
4100 forgetting to add volatile and match attributes.
4102 See docstring of `anything-candidates-in-buffer'.
4104 (candidates-in-buffer) is equivalent of three attributes:
4105 (candidates . anything-candidates-in-buffer)
4106 (volatile)
4107 (match identity)
4109 (candidates-in-buffer . candidates-function) is equivalent of:
4110 (candidates . candidates-function)
4111 (volatile)
4112 (match identity)
4114 This attribute is implemented by plug-in. ")
4115 (anything-document-attribute 'search "optional"
4116 " List of functions like `re-search-forward' or `search-forward'.
4117 Buffer search function used by `anything-candidates-in-buffer'.
4118 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4119 This attribute is meant to be used with
4120 (candidates . anything-candidates-in-buffer) or
4121 (candidates-in-buffer) in short. ")
4122 (anything-document-attribute 'search-from-end "optional"
4123 " Make `anything-candidates-in-buffer' search from the end of buffer.
4124 If this attribute is specified, `anything-candidates-in-buffer' uses
4125 `re-search-backward' instead. ")
4126 (anything-document-attribute 'get-line "optional"
4127 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4128 This function converts point of line-beginning and point of line-end,
4129 which represents a candidate computed by `anything-candidates-in-buffer'.
4130 By default, `anything-candidates-in-buffer' uses
4131 `buffer-substring-no-properties'. ")
4132 (anything-document-attribute 'display-to-real "optional"
4133 " Function called with one parameter; the selected candidate.
4135 The function transforms the selected candidate, and the result
4136 is passed to the action function. The display-to-real
4137 attribute provides another way to pass other string than one
4138 shown in Anything buffer.
4140 Traditionally, it is possible to make candidates,
4141 candidate-transformer or filtered-candidate-transformer
4142 function return a list with (DISPLAY . REAL) pairs. But if REAL
4143 can be generated from DISPLAY, display-to-real is more
4144 convenient and faster. ")
4145 (anything-document-attribute 'real-to-display "optional"
4146 " Function called with one parameter; the selected candidate.
4148 The inverse of display-to-real attribute.
4150 The function transforms the selected candidate, which is passed
4151 to the action function, for display. The real-to-display
4152 attribute provides the other way to pass other string than one
4153 shown in Anything buffer.
4155 Traditionally, it is possible to make candidates,
4156 candidate-transformer or filtered-candidate-transformer
4157 function return a list with (DISPLAY . REAL) pairs. But if
4158 DISPLAY can be generated from REAL, real-to-display is more
4159 convenient.
4161 Note that DISPLAY parts returned from candidates /
4162 candidate-transformer are IGNORED as the name `display-to-real'
4163 says. ")
4164 (anything-document-attribute 'cleanup "optional"
4165 " Function called with no parameters when *anything* buffer is closed. It
4166 is useful for killing unneeded candidates buffer.
4168 Note that the function is executed BEFORE performing action. ")
4169 (anything-document-attribute 'candidate-number-limit "optional"
4170 " Override `anything-candidate-number-limit' only for this source. ")
4171 (anything-document-attribute 'accept-empty "optional"
4172 " Pass empty string \"\" to action function. ")
4173 (anything-document-attribute 'disable-shortcuts "optional"
4174 " Disable `anything-enable-shortcuts' in current `anything' session.
4176 This attribute is implemented by plug-in. ")
4177 (anything-document-attribute 'dummy "optional"
4178 " Set `anything-pattern' to candidate. If this attribute is
4179 specified, The candidates attribute is ignored.
4181 This attribute is implemented by plug-in.
4182 This plug-in implies disable-shortcuts plug-in. ")
4183 (anything-document-attribute 'multiline "optional"
4184 " Enable to selection multiline candidates. ")
4185 (anything-document-attribute 'update "optional"
4186 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4187 (anything-document-attribute 'mode-line "optional"
4188 " source local `anything-mode-line-string'. (included in `mode-line-format')
4189 It accepts also variable/function name. ")
4190 (anything-document-attribute 'header-line "optional"
4191 " source local `header-line-format'.
4192 It accepts also variable/function name. ")
4193 (anything-document-attribute 'resume "optional" " Function called with no parameters when `anything-resume' is started.")
4195 ;; (@* "Bug Report")
4196 (defvar anything-maintainer-mail-address
4197 (concat "rubiki" "tch@ru" "by-lang.org"))
4198 (defvar anything-bug-report-salutation
4199 "Describe bug below, using a precise recipe.
4201 When I executed M-x ...
4203 How to send a bug report:
4204 1) Be sure to use the LATEST version of anything.el.
4205 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
4206 3) Use Lisp version instead of compiled one: (load \"anything.el\")
4207 4) If you got an error, please paste *Backtrace* buffer.
4208 5) Type C-c C-c to send.
4209 # If you are a Japanese, please write in Japanese:-)")
4210 (defvar anything-no-dump-variables
4211 '(anything-candidate-buffer-alist
4212 anything-digit-overlays
4213 anything-help-message
4214 anything-candidate-cache
4216 "Variables not to dump in bug report.")
4218 (defun anything-dumped-variables-in-bug-report ()
4219 (let ((hash (make-hash-table)))
4220 (loop for var in (apropos-internal "anything-" 'boundp)
4221 for vname = (symbol-name var)
4222 unless (or (string-match "-map$" vname)
4223 (string-match "^anything-c-source-" vname)
4224 (string-match "-hash$" vname)
4225 (string-match "-face$" vname)
4226 (memq var anything-no-dump-variables))
4227 collect var)))
4229 (defun anything-send-bug-report ()
4230 "Send a bug report of anything.el."
4231 (interactive)
4232 (with-current-buffer (or anything-last-buffer
4233 (current-buffer))
4234 (reporter-submit-bug-report
4235 anything-maintainer-mail-address
4236 "anything.el"
4237 (anything-dumped-variables-in-bug-report)
4238 nil nil
4239 anything-bug-report-salutation)))
4241 (defun anything-send-bug-report-from-anything ()
4242 "Send a bug report of anything.el in anything session."
4243 (interactive)
4244 (anything-run-after-quit 'anything-send-bug-report))
4246 ;; (@* "Unit Tests")
4248 (defun* anything-test-candidates (sources &optional (input "") (compile-source-functions anything-compile-source-functions-default))
4249 "Test helper function for anything.
4250 Given pseudo `anything-sources' and `anything-pattern', returns list like
4251 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4252 (\"source name2\" (\"candidate3\" \"candidate4\")))
4254 (let ((anything-test-mode t)
4255 anything-enable-shortcuts
4256 anything-candidate-cache
4257 (anything-compile-source-functions compile-source-functions)
4258 anything-before-initialize-hook
4259 anything-after-initialize-hook
4260 anything-update-hook
4261 anything-test-candidate-list)
4262 (get-buffer-create anything-buffer)
4264 (anything-initialize-1 nil input sources)
4265 (anything-update)
4266 ;; test-mode spec: select 1st candidate!
4267 (with-current-buffer anything-buffer
4268 (forward-line 1)
4269 (anything-mark-current-line))
4270 (prog1
4271 anything-test-candidate-list
4272 (anything-cleanup))))
4274 (defmacro anything-test-update (sources pattern)
4275 "Test helper macro for anything. It is meant for testing *anything* buffer contents."
4276 `(progn (stub anything-get-sources => ,sources)
4277 (stub anything-log-run-hook => nil)
4278 (stub anything-maybe-fit-frame => nil)
4279 (stub run-with-idle-timer => nil)
4280 (let (anything-test-mode (anything-pattern ,pattern))
4281 (anything-update))))
4283 ;;;; unit test
4284 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4285 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
4286 (dont-compile
4287 (when (fboundp 'expectations)
4288 (expectations
4289 (desc "anything-current-buffer")
4290 (expect "__a_buffer"
4291 (with-current-buffer (get-buffer-create "__a_buffer")
4292 (anything-test-candidates '(((name . "FOO"))) "")
4293 (prog1
4294 (buffer-name anything-current-buffer)
4295 (kill-buffer "__a_buffer")
4297 (desc "anything-buffer-file-name")
4298 (expect (regexp "/__a_file__")
4299 (with-current-buffer (get-buffer-create "__a_file__")
4300 (setq buffer-file-name "/__a_file__")
4301 (anything-test-candidates '(((name . "FOO"))) "")
4302 (prog1
4303 anything-buffer-file-name
4304 ;;(kill-buffer "__a_file__")
4306 (desc "anything-interpret-value")
4307 (expect "literal"
4308 (anything-interpret-value "literal"))
4309 (expect "lambda"
4310 (anything-interpret-value (lambda () "lambda")))
4311 (expect "lambda with source name"
4312 (let ((source '((name . "lambda with source name"))))
4313 (anything-interpret-value (lambda () anything-source-name) source)))
4314 (expect "function symbol"
4315 (flet ((f () "function symbol"))
4316 (anything-interpret-value 'f)))
4317 (expect "variable symbol"
4318 (let ((v "variable symbol"))
4319 (anything-interpret-value 'v)))
4320 (expect (error error *)
4321 (anything-interpret-value 'unbounded-1))
4322 (desc "anything-compile-sources")
4323 (expect '(((name . "foo")))
4324 (anything-compile-sources '(((name . "foo"))) nil)
4326 (expect '(((name . "foo") (type . test) (action . identity)))
4327 (let ((anything-type-attributes '((test (action . identity)))))
4328 (anything-compile-sources '(((name . "foo") (type . test)))
4329 '(anything-compile-source--type))))
4330 (desc "anything-sources accepts symbols")
4331 (expect '(((name . "foo")))
4332 (let* ((foo '((name . "foo"))))
4333 (anything-compile-sources '(foo) nil)))
4334 (desc "anything-get-sources action")
4335 (expect '(((name . "Actions") (candidates . actions)))
4336 (stub anything-action-window => t)
4337 (let (anything-compiled-sources
4338 (anything-sources '(((name . "Actions") (candidates . actions)))))
4339 (anything-get-sources)))
4340 (desc "get-buffer-create candidates-buffer")
4341 (expect '(((name . "many") (init . many-init)
4342 (candidates-in-buffer . anything-candidates-in-buffer)
4343 (candidates . anything-candidates-in-buffer)
4344 (volatile) (match identity)))
4345 (anything-compile-sources
4346 '(((name . "many") (init . many-init)
4347 (candidates-in-buffer . anything-candidates-in-buffer)))
4348 '(anything-compile-source--candidates-in-buffer)))
4349 (expect '(((name . "many") (init . many-init)
4350 (candidates-in-buffer)
4351 (candidates . anything-candidates-in-buffer)
4352 (volatile) (match identity)))
4353 (anything-compile-sources
4354 '(((name . "many") (init . many-init)
4355 (candidates-in-buffer)))
4356 '(anything-compile-source--candidates-in-buffer)))
4357 (expect '(((name . "many") (init . many-init)
4358 (candidates-in-buffer)
4359 (type . test)
4360 (action . identity)
4361 (candidates . anything-candidates-in-buffer)
4362 (volatile) (match identity)))
4363 (let ((anything-type-attributes '((test (action . identity)))))
4364 (anything-compile-sources
4365 '(((name . "many") (init . many-init)
4366 (candidates-in-buffer)
4367 (type . test)))
4368 '(anything-compile-source--type
4369 anything-compile-source--candidates-in-buffer))))
4371 (desc "anything-get-candidates")
4372 (expect '("foo" "bar")
4373 (anything-get-candidates '((name . "foo") (candidates "foo" "bar"))))
4374 (expect '("FOO" "BAR")
4375 (anything-get-candidates '((name . "foo") (candidates "foo" "bar")
4376 (candidate-transformer
4377 . (lambda (cands) (mapcar 'upcase cands))))))
4378 (expect '("foo" "bar")
4379 (anything-get-candidates '((name . "foo")
4380 (candidates . (lambda () '("foo" "bar"))))))
4381 (expect '("foo" "bar")
4382 (let ((var '("foo" "bar")))
4383 (anything-get-candidates '((name . "foo")
4384 (candidates . var)))))
4385 (expect (error error *)
4386 (anything-get-candidates '((name . "foo")
4387 (candidates . "err"))))
4388 (expect (error error *)
4389 (let ((var "err"))
4390 (anything-get-candidates '((name . "foo")
4391 (candidates . var)))))
4392 (expect (error error *)
4393 (anything-get-candidates '((name . "foo")
4394 (candidates . unDeFined-syMbol))))
4395 (desc "anything-compute-matches")
4396 (expect '("foo" "bar")
4397 (let ((anything-pattern ""))
4398 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4399 (expect '("foo")
4400 (let ((anything-pattern "oo"))
4401 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4402 (expect '("bar")
4403 (let ((anything-pattern "^b"))
4404 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4405 (expect '("a" "b")
4406 (let ((anything-pattern "")
4407 (anything-candidate-number-limit 2))
4408 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4409 (expect '("a" "b")
4410 (let ((anything-pattern ".")
4411 (anything-candidate-number-limit 2))
4412 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4413 (expect '("a" "b" "c")
4414 (let ((anything-pattern "")
4415 anything-candidate-number-limit)
4416 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4417 (expect '("a" "b" "c")
4418 (let ((anything-pattern "[abc]")
4419 anything-candidate-number-limit)
4420 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4421 (expect '(a b c)
4422 (let ((anything-pattern "[abc]")
4423 anything-candidate-number-limit)
4424 (anything-compute-matches '((name . "FOO") (candidates a b c) (volatile)))))
4425 (expect '(("foo" . "FOO") ("bar" . "BAR"))
4426 (let ((anything-pattern ""))
4427 (anything-compute-matches '((name . "FOO") (candidates ("foo" . "FOO") ("bar" . "BAR")) (volatile)))))
4428 (expect '(("foo" . "FOO"))
4429 (let ((anything-pattern "foo"))
4430 (anything-compute-matches '((name . "FOO") (candidates ("foo" . "FOO") ("bar" . "foo")) (volatile)))))
4431 ;; using anything-test-candidate-list
4432 (desc "anything-test-candidates")
4433 (expect '(("FOO" ("foo" "bar")))
4434 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")))))
4435 (expect '(("FOO" ("bar")))
4436 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar"))) "ar"))
4437 (expect '(("T1" ("hoge" "aiue"))
4438 ("T2" ("test" "boke")))
4439 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4440 ((name . "T2") (candidates "test" "boke")))))
4441 (expect '(("T1" ("hoge"))
4442 ("T2" ("boke")))
4443 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4444 ((name . "T2") (candidates "test" "boke"))) "o"))
4445 (desc "requires-pattern attribute")
4446 (expect nil
4447 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4448 (requires-pattern . 1)))))
4449 (expect '(("FOO" ("bar")))
4450 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4451 (requires-pattern . 1))) "b"))
4452 (desc "delayed attribute(for test)")
4453 (expect '(("T2" ("boke"))
4454 ("T1" ("hoge")))
4455 (anything-test-candidates
4456 '(((name . "T1") (candidates "hoge" "aiue") (delayed))
4457 ((name . "T2") (candidates "test" "boke")))
4458 "o"))
4459 (desc "match attribute(prefix search)")
4460 (expect '(("FOO" ("bar")))
4461 (anything-test-candidates
4462 '(((name . "FOO") (candidates "foo" "bar")
4463 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4464 "ba"))
4465 (expect nil
4466 (anything-test-candidates
4467 '(((name . "FOO") (candidates "foo" "bar")
4468 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4469 "ar"))
4470 (expect "TestSource"
4471 (let (x)
4472 (anything-test-candidates
4473 '(((name . "TestSource") (candidates "a")
4474 (match (lambda (c) (setq x anything-source-name)))))
4475 "a")
4477 (desc "init attribute")
4478 (expect '(("FOO" ("bar")))
4479 (let (v)
4480 (anything-test-candidates
4481 '(((name . "FOO") (init . (lambda () (setq v '("foo" "bar"))))
4482 (candidates . v)))
4483 "ar")))
4484 (desc "candidate-transformer attribute")
4485 (expect '(("FOO" ("BAR")))
4486 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4487 (candidate-transformer
4488 . (lambda (cands) (mapcar 'upcase cands)))))
4489 "ar"))
4490 (desc "filtered-candidate-transformer attribute")
4491 ;; needs more tests
4492 (expect '(("FOO" ("BAR")))
4493 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4494 (filtered-candidate-transformer
4495 . (lambda (cands src) (mapcar 'upcase cands)))))
4496 "ar"))
4497 (desc "anything-transform-candidates in process")
4498 (expect (mock (anything-composed-funcall-with-source
4499 '((name . "FOO") (candidates "foo" "bar")
4500 (filtered-candidate-transformer
4501 . (lambda (cands src) (mapcar 'upcase cands))))
4502 (lambda (cands src) (mapcar 'upcase cands))
4503 '("foo" "bar")
4504 '((name . "FOO") (candidates "foo" "bar")
4505 (filtered-candidate-transformer
4506 . (lambda (cands src) (mapcar 'upcase cands))))
4508 (stub anything-process-candidate-transformer => '("foo" "bar"))
4509 (anything-transform-candidates
4510 '("foo" "bar")
4511 '((name . "FOO") (candidates "foo" "bar")
4512 (filtered-candidate-transformer
4513 . (lambda (cands src) (mapcar 'upcase cands))))
4516 (desc "anything-candidates-in-buffer-1")
4517 (expect nil
4518 (anything-candidates-in-buffer-1
4519 nil ""
4520 'buffer-substring-no-properties '(re-search-forward) 50 nil))
4521 (expect '("foo+" "bar+" "baz+")
4522 (with-temp-buffer
4523 (insert "foo+\nbar+\nbaz+\n")
4524 (anything-candidates-in-buffer-1
4525 (current-buffer) ""
4526 'buffer-substring-no-properties '(re-search-forward) 5 nil)))
4527 (expect '("foo+" "bar+")
4528 (with-temp-buffer
4529 (insert "foo+\nbar+\nbaz+\n")
4530 (anything-candidates-in-buffer-1
4531 (current-buffer) ""
4532 'buffer-substring-no-properties '(re-search-forward) 2 nil)))
4533 (expect '("foo+")
4534 (with-temp-buffer
4535 (insert "foo+\nbar+\nbaz+\n")
4536 (anything-candidates-in-buffer-1
4537 (current-buffer) "oo\\+"
4538 'buffer-substring-no-properties '(re-search-forward) 50 nil)))
4539 (expect '("foo+")
4540 (with-temp-buffer
4541 (insert "foo+\nbar+\nbaz+\n")
4542 (anything-candidates-in-buffer-1
4543 (current-buffer) "oo+"
4544 #'buffer-substring-no-properties '(search-forward) 50 nil)))
4545 (expect '("foo+" "bar+")
4546 (with-temp-buffer
4547 (insert "foo+\nbar+\nbaz+\n")
4548 (anything-candidates-in-buffer-1
4549 (current-buffer) "."
4550 'buffer-substring-no-properties '(re-search-forward) 2 nil)))
4551 (expect '(("foo+" "FOO+"))
4552 (with-temp-buffer
4553 (insert "foo+\nbar+\nbaz+\n")
4554 (anything-candidates-in-buffer-1
4555 (current-buffer) "oo\\+"
4556 (lambda (s e)
4557 (let ((l (buffer-substring-no-properties s e)))
4558 (list l (upcase l))))
4559 '(re-search-forward) 50 nil)))
4560 (desc "anything-candidates-in-buffer")
4561 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4562 (anything-test-candidates
4563 '(((name . "TEST")
4564 (init
4565 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4566 (insert "foo+\nbar+\nbaz+\n"))))
4567 (candidates . anything-candidates-in-buffer)
4568 (match identity)
4569 (volatile)))))
4570 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4571 (let (anything-candidate-number-limit)
4572 (anything-test-candidates
4573 '(((name . "TEST")
4574 (init
4575 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4576 (insert "foo+\nbar+\nbaz+\n"))))
4577 (candidates . anything-candidates-in-buffer)
4578 (match identity)
4579 (volatile))))))
4580 (expect '(("TEST" ("foo+")))
4581 (anything-test-candidates
4582 '(((name . "TEST")
4583 (init
4584 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4585 (insert "foo+\nbar+\nbaz+\n"))))
4586 (candidates . anything-candidates-in-buffer)
4587 (match identity)
4588 (volatile)))
4589 "oo\\+"))
4590 ;; BUG remain empty string, but the pattern is rare case.
4591 (expect '(("a" ("" "a" "b")))
4592 (anything-test-candidates
4593 '(((name . "a")
4594 (init . (lambda ()
4595 (with-current-buffer (anything-candidate-buffer 'global)
4596 (insert "a\nb\n"))))
4597 (candidates-in-buffer)))
4598 "a*"))
4599 (desc "search attribute")
4600 (expect '(("TEST" ("foo+")))
4601 (anything-test-candidates
4602 '(((name . "TEST")
4603 (init
4604 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4605 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4606 (search search-forward)
4607 (candidates . anything-candidates-in-buffer)
4608 (match identity)
4609 (volatile)))
4610 "oo+"))
4611 (expect '(("TEST" ("foo+" "ooo")))
4612 (anything-test-candidates
4613 '(((name . "TEST")
4614 (init
4615 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4616 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4617 (search search-forward re-search-forward)
4618 (candidates . anything-candidates-in-buffer)
4619 (match identity)
4620 (volatile)))
4621 "oo+"))
4622 (expect '(("TEST" ("foo+" "ooo")))
4623 (anything-test-candidates
4624 '(((name . "TEST")
4625 (init
4626 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4627 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4628 (search re-search-forward search-forward)
4629 (candidates . anything-candidates-in-buffer)
4630 (match identity)
4631 (volatile)))
4632 "oo+"))
4633 (expect '(("TEST" ("ooo" "foo+")))
4634 (anything-test-candidates
4635 '(((name . "TEST")
4636 (init
4637 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4638 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4639 (search re-search-forward search-forward)
4640 (candidates . anything-candidates-in-buffer)
4641 (match identity)
4642 (volatile)))
4643 "oo+"))
4644 ;; faster exact match
4645 (expect '(("TEST" ("bar+")))
4646 (anything-test-candidates
4647 '(((name . "TEST")
4648 (init
4649 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4650 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4651 (search (lambda (pattern &rest _)
4652 (and (search-forward (concat "\n" pattern "\n") nil t)
4653 (forward-line -1))))
4654 (candidates . anything-candidates-in-buffer)
4655 (match identity)
4656 (volatile)))
4657 "bar+"))
4658 ;; faster prefix match
4659 (expect '(("TEST" ("bar+")))
4660 (anything-test-candidates
4661 '(((name . "TEST")
4662 (init
4663 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4664 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4665 (search (lambda (pattern &rest _)
4666 (search-forward (concat "\n" pattern) nil t)))
4667 (candidates . anything-candidates-in-buffer)
4668 (match identity)
4669 (volatile)))
4670 "ba"))
4671 (desc "anything-current-buffer-is-modified")
4672 (expect '(("FOO" ("modified")))
4673 (let ((sources '(((name . "FOO")
4674 (candidates
4675 . (lambda ()
4676 (if (anything-current-buffer-is-modified)
4677 '("modified")
4678 '("unmodified"))))))))
4679 (with-temp-buffer
4680 (clrhash anything-tick-hash)
4681 (insert "1")
4682 (anything-test-candidates sources))))
4683 (expect '(("FOO" ("unmodified")))
4684 (let ((sources '(((name . "FOO")
4685 (candidates
4686 . (lambda ()
4687 (if (anything-current-buffer-is-modified)
4688 '("modified")
4689 '("unmodified"))))))))
4690 (with-temp-buffer
4691 (clrhash anything-tick-hash)
4692 (insert "1")
4693 (anything-test-candidates sources)
4694 (anything-test-candidates sources))))
4695 (expect '(("FOO" ("modified")))
4696 (let ((sources '(((name . "FOO")
4697 (candidates
4698 . (lambda ()
4699 (if (anything-current-buffer-is-modified)
4700 '("modified")
4701 '("unmodified"))))))))
4702 (with-temp-buffer
4703 (clrhash anything-tick-hash)
4704 (insert "1")
4705 (anything-test-candidates sources)
4706 (insert "2")
4707 (anything-test-candidates sources))))
4708 (expect '(("BAR" ("modified")))
4709 (let ((sources1 '(((name . "FOO")
4710 (candidates
4711 . (lambda ()
4712 (if (anything-current-buffer-is-modified)
4713 '("modified")
4714 '("unmodified")))))))
4715 (sources2 '(((name . "BAR")
4716 (candidates
4717 . (lambda ()
4718 (if (anything-current-buffer-is-modified)
4719 '("modified")
4720 '("unmodified"))))))))
4721 (with-temp-buffer
4722 (clrhash anything-tick-hash)
4723 (insert "1")
4724 (anything-test-candidates sources1)
4725 (anything-test-candidates sources2))))
4726 (expect '(("FOO" ("unmodified")))
4727 (let ((sources1 '(((name . "FOO")
4728 (candidates
4729 . (lambda ()
4730 (if (anything-current-buffer-is-modified)
4731 '("modified")
4732 '("unmodified")))))))
4733 (sources2 '(((name . "BAR")
4734 (candidates
4735 . (lambda ()
4736 (if (anything-current-buffer-is-modified)
4737 '("modified")
4738 '("unmodified"))))))))
4739 (with-temp-buffer
4740 (clrhash anything-tick-hash)
4741 (insert "1")
4742 (anything-test-candidates sources1)
4743 (anything-test-candidates sources2)
4744 (anything-test-candidates sources1))))
4745 (expect '(("BAR" ("unmodified")))
4746 (let ((sources1 '(((name . "FOO")
4747 (candidates
4748 . (lambda ()
4749 (if (anything-current-buffer-is-modified)
4750 '("modified")
4751 '("unmodified")))))))
4752 (sources2 '(((name . "BAR")
4753 (candidates
4754 . (lambda ()
4755 (if (anything-current-buffer-is-modified)
4756 '("modified")
4757 '("unmodified"))))))))
4758 (with-temp-buffer
4759 (clrhash anything-tick-hash)
4760 (insert "1")
4761 (anything-test-candidates sources1)
4762 (anything-test-candidates sources2)
4763 (anything-test-candidates sources2))))
4764 (expect '(("BAR" ("modified")))
4765 (let ((sources1 '(((name . "FOO")
4766 (candidates
4767 . (lambda ()
4768 (if (anything-current-buffer-is-modified)
4769 '("modified")
4770 '("unmodified")))))))
4771 (sources2 '(((name . "BAR")
4772 (candidates
4773 . (lambda ()
4774 (if (anything-current-buffer-is-modified)
4775 '("modified")
4776 '("unmodified"))))))))
4777 (with-temp-buffer
4778 (clrhash anything-tick-hash)
4779 (insert "1")
4780 (anything-test-candidates sources1)
4781 (anything-test-candidates sources2)
4782 (with-temp-buffer
4783 (anything-test-candidates sources2)))))
4784 (desc "anything-source-name")
4785 (expect "FOO"
4786 (let (v)
4787 (anything-test-candidates '(((name . "FOO")
4788 (init
4789 . (lambda () (setq v anything-source-name)))
4790 (candidates "ok"))))
4792 (expect "FOO"
4793 (let (v)
4794 (anything-test-candidates '(((name . "FOO")
4795 (candidates
4796 . (lambda ()
4797 (setq v anything-source-name)
4798 '("ok"))))))
4800 (expect "FOO"
4801 (let (v)
4802 (anything-test-candidates '(((name . "FOO")
4803 (candidates "ok")
4804 (candidate-transformer
4805 . (lambda (c)
4806 (setq v anything-source-name)
4807 c)))))
4809 (expect "FOO"
4810 (let (v)
4811 (anything-test-candidates '(((name . "FOO")
4812 (candidates "ok")
4813 (filtered-candidate-transformer
4814 . (lambda (c s)
4815 (setq v anything-source-name)
4816 c)))))
4818 (expect "FOO"
4819 (let (v)
4820 (anything-test-candidates '(((name . "FOO")
4821 (candidates "ok")
4822 (display-to-real
4823 . (lambda (c)
4824 (setq v anything-source-name)
4826 (action . identity))))
4827 (anything-execute-selection-action)
4829 (desc "anything-candidate-buffer create")
4830 (expect " *anything candidates:FOO*"
4831 (let* (anything-candidate-buffer-alist
4832 (anything-source-name "FOO")
4833 (buf (anything-candidate-buffer 'global)))
4834 (prog1 (buffer-name buf)
4835 (kill-buffer buf))))
4836 (expect " *anything candidates:FOO*aTestBuffer"
4837 (let* (anything-candidate-buffer-alist
4838 (anything-source-name "FOO")
4839 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4840 (buf (anything-candidate-buffer 'local)))
4841 (prog1 (buffer-name buf)
4842 (kill-buffer anything-current-buffer)
4843 (kill-buffer buf))))
4844 (expect 0
4845 (let (anything-candidate-buffer-alist
4846 (anything-source-name "FOO") buf)
4847 (with-current-buffer (anything-candidate-buffer 'global)
4848 (insert "1"))
4849 (setq buf (anything-candidate-buffer 'global))
4850 (prog1 (buffer-size buf)
4851 (kill-buffer buf))))
4852 (desc "anything-candidate-buffer get-buffer")
4853 (expect " *anything candidates:FOO*"
4854 (let* (anything-candidate-buffer-alist
4855 (anything-source-name "FOO")
4856 (buf (anything-candidate-buffer 'global)))
4857 (prog1 (buffer-name (anything-candidate-buffer))
4858 (kill-buffer buf))))
4859 (expect " *anything candidates:FOO*aTestBuffer"
4860 (let* (anything-candidate-buffer-alist
4861 (anything-source-name "FOO")
4862 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4863 (buf (anything-candidate-buffer 'local)))
4864 (prog1 (buffer-name (anything-candidate-buffer))
4865 (kill-buffer anything-current-buffer)
4866 (kill-buffer buf))))
4867 (expect " *anything candidates:FOO*"
4868 (let* (anything-candidate-buffer-alist
4869 (anything-source-name "FOO")
4870 (buf-local (anything-candidate-buffer 'local))
4871 (buf-global (anything-candidate-buffer 'global)))
4872 (prog1 (buffer-name (anything-candidate-buffer))
4873 (kill-buffer buf-local)
4874 (kill-buffer buf-global))))
4875 (expect " *anything candidates:FOO*aTestBuffer"
4876 (let* (anything-candidate-buffer-alist
4877 (anything-source-name "FOO")
4878 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4879 (buf-global (anything-candidate-buffer 'global))
4880 (buf-local (anything-candidate-buffer 'local)))
4881 (prog1 (buffer-name (anything-candidate-buffer))
4882 (kill-buffer buf-local)
4883 (kill-buffer buf-global))))
4884 (expect nil
4885 (let* (anything-candidate-buffer-alist
4886 (anything-source-name "NOP__"))
4887 (anything-candidate-buffer)))
4888 (desc "anything-candidate-buffer register-buffer")
4889 (expect " *anything test candidates*"
4890 (let (anything-candidate-buffer-alist
4891 (buf (get-buffer-create " *anything test candidates*")))
4892 (with-current-buffer buf
4893 (insert "1\n2\n")
4894 (prog1 (buffer-name (anything-candidate-buffer buf))
4895 (kill-buffer (current-buffer))))))
4896 (expect " *anything test candidates*"
4897 (let (anything-candidate-buffer-alist
4898 (buf (get-buffer-create " *anything test candidates*")))
4899 (with-current-buffer buf
4900 (insert "1\n2\n")
4901 (anything-candidate-buffer buf)
4902 (prog1 (buffer-name (anything-candidate-buffer))
4903 (kill-buffer (current-buffer))))))
4904 (expect "1\n2\n"
4905 (let (anything-candidate-buffer-alist
4906 (buf (get-buffer-create " *anything test candidates*")))
4907 (with-current-buffer buf
4908 (insert "1\n2\n")
4909 (anything-candidate-buffer buf)
4910 (prog1 (buffer-string)
4911 (kill-buffer (current-buffer))))))
4912 (expect "buf1"
4913 (let (anything-candidate-buffer-alist
4914 (anything-source-name "foo")
4915 (buf1 (get-buffer-create "buf1"))
4916 (buf2 (get-buffer-create "buf2")))
4917 (anything-candidate-buffer buf1)
4918 (anything-candidate-buffer buf2)
4919 (prog1 (buffer-name (anything-candidate-buffer buf1))
4920 (kill-buffer buf1)
4921 (kill-buffer buf2))))
4922 (desc "action attribute")
4923 (expect "foo"
4924 (anything-test-candidates
4925 '(((name . "TEST")
4926 (candidates "foo")
4927 (action ("identity" . identity)))))
4928 (anything-execute-selection-action))
4929 (expect "foo"
4930 (anything-test-candidates
4931 '(((name . "TEST")
4932 (candidates "foo")
4933 (action ("identity" . (lambda (c) (identity c)))))))
4934 (anything-execute-selection-action))
4935 (desc "anything-get-default-action")
4936 (expect 'upcase
4937 (anything-get-default-action '(("upcase" . upcase))))
4938 (expect 'downcase
4939 (anything-get-default-action '(("downcase" . downcase))))
4940 (expect (lambda (x) (capitalize x))
4941 (anything-get-default-action (lambda (x) (capitalize x))))
4942 (expect 'identity
4943 (anything-get-default-action 'identity))
4944 (desc "anything-execute-selection-action")
4945 (expect "FOO"
4946 (anything-execute-selection-action
4947 "foo" '(("upcase" . upcase)) nil))
4948 (expect "FOO"
4949 (anything-execute-selection-action
4950 "foo" '(("upcase" . (lambda (c) (upcase c)))) nil))
4952 (desc "display-to-real attribute")
4953 (expect "FOO"
4954 (anything-test-candidates
4955 '(((name . "TEST")
4956 (candidates "foo")
4957 (display-to-real . upcase)
4958 (action ("identity" . identity)))))
4959 (anything-execute-selection-action))
4960 (desc "cleanup test")
4961 (expect 'cleaned
4962 (let (v)
4963 (anything-test-candidates
4964 '(((name . "TEST")
4965 (cleanup . (lambda () (setq v 'cleaned))))))
4967 (desc "anything-get-current-source")
4968 ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
4969 ;; display-to-real/cleanup function
4970 (expect "FOO"
4971 (assoc-default
4972 'name
4973 (anything-funcall-with-source '((name . "FOO")) 'anything-get-current-source)))
4974 ;; init
4975 (expect "FOO"
4976 (let (v)
4977 (anything-test-candidates
4978 '(((name . "FOO")
4979 (init . (lambda () (setq v (anything-get-current-source)))))))
4980 (assoc-default 'name v)))
4981 ;; candidates
4982 (expect "FOO"
4983 (let (v)
4984 (anything-test-candidates
4985 '(((name . "FOO")
4986 (candidates . (lambda () (setq v (anything-get-current-source)) '("a"))))))
4987 (assoc-default 'name v)))
4988 ;; action
4989 (expect "FOO"
4990 (let (v)
4991 (anything-test-candidates
4992 '(((name . "FOO")
4993 (candidates "a")
4994 (action
4995 . (lambda (c) (setq v (anything-get-current-source)) c)))))
4996 (anything-execute-selection-action)
4997 (assoc-default 'name v)))
4998 ;; candidate-transformer
4999 (expect "FOO"
5000 (let (v)
5001 (anything-test-candidates
5002 '(((name . "FOO")
5003 (candidates "a")
5004 (candidate-transformer
5005 . (lambda (c) (setq v (anything-get-current-source)) c)))))
5006 (assoc-default 'name v)))
5007 ;; filtered-candidate-transformer
5008 (expect "FOO"
5009 (let (v)
5010 (anything-test-candidates
5011 '(((name . "FOO")
5012 (candidates "a")
5013 (filtered-candidate-transformer
5014 . (lambda (c s) (setq v (anything-get-current-source)) c)))))
5015 (assoc-default 'name v)))
5016 ;; action-transformer
5017 (expect "FOO"
5018 (let (v)
5019 (anything-test-candidates
5020 '(((name . "FOO")
5021 (candidates "a")
5022 (action-transformer
5023 . (lambda (a c) (setq v (anything-get-current-source)) a))
5024 (action . identity))))
5025 (anything-execute-selection-action)
5026 (assoc-default 'name v)))
5027 ;; display-to-real
5028 (expect "FOO"
5029 (let (v)
5030 (anything-test-candidates
5031 '(((name . "FOO")
5032 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5033 (insert "a\n"))))
5034 (candidates-in-buffer)
5035 (display-to-real
5036 . (lambda (c) (setq v (anything-get-current-source)) c))
5037 (action . identity))))
5038 (anything-execute-selection-action)
5039 (assoc-default 'name v)))
5040 ;; cleanup
5041 (expect "FOO"
5042 (let (v)
5043 (anything-test-candidates
5044 '(((name . "FOO")
5045 (candidates "a")
5046 (cleanup
5047 . (lambda () (setq v (anything-get-current-source)))))))
5048 (assoc-default 'name v)))
5049 ;; candidates are displayed
5050 (expect "TEST"
5051 (anything-test-candidates
5052 '(((name . "TEST")
5053 (candidates "foo")
5054 (action ("identity" . identity)))))
5055 (assoc-default 'name (anything-get-current-source)))
5056 (desc "anything-attr")
5057 (expect "FOO"
5058 (anything-funcall-with-source
5059 '((name . "FOO"))
5060 (lambda ()
5061 (anything-attr 'name))))
5062 (expect 'fuga
5063 (let (v)
5064 (anything-test-candidates
5065 '(((name . "FOO")
5066 (hoge . fuga)
5067 (init . (lambda () (setq v (anything-attr 'hoge))))
5068 (candidates "a"))))
5070 (expect nil
5071 (let (v)
5072 (anything-test-candidates
5073 '(((name . "FOO")
5074 (init . (lambda () (setq v (anything-attr 'hoge))))
5075 (candidates "a"))))
5077 (expect nil
5078 (let (v)
5079 (anything-test-candidates
5080 '(((name . "FOO")
5081 (hoge) ;INCOMPATIBLE!
5082 (init . (lambda () (setq v (anything-attr 'hoge))))
5083 (candidates "a"))))
5085 (desc "anything-attr*")
5086 (expect "generic"
5087 (let (v (value1 "generic"))
5088 (anything-test-candidates
5089 '(((name . "FOO")
5090 (hoge . value1)
5091 (init . (lambda () (setq v (anything-attr* 'hoge)))))))
5093 (desc "anything-attr-defined")
5094 (expect (non-nil)
5095 (let (v)
5096 (anything-test-candidates
5097 '(((name . "FOO")
5098 (hoge)
5099 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5100 (candidates "a"))))
5101 v))
5102 (expect nil
5103 (let (v)
5104 (anything-test-candidates
5105 '(((name . "FOO")
5106 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5107 (candidates "a"))))
5108 v))
5109 (desc "anything-attrset")
5110 (expect '((name . "FOO") (hoge . 77))
5111 (let ((src '((name . "FOO") (hoge))))
5112 (anything-attrset 'hoge 77 src)
5113 src))
5114 (expect 77
5115 (anything-attrset 'hoge 77 '((name . "FOO") (hoge))))
5117 (expect '((name . "FOO") (hoge . 77))
5118 (let ((src '((name . "FOO") (hoge . 1))))
5119 (anything-attrset 'hoge 77 src)
5120 src))
5122 (expect '((name . "FOO") (hoge . 77) (x))
5123 (let ((src '((name . "FOO") (x))))
5124 (anything-attrset 'hoge 77 src)
5125 src))
5126 (expect 77
5127 (anything-attrset 'hoge 77 '((name . "FOO"))))
5128 (desc "anything-preselect")
5129 ;; entire candidate
5130 (expect "foo"
5131 (with-current-buffer (anything-create-anything-buffer t)
5132 (let ((anything-pattern "")
5133 (anything-test-mode t))
5134 (anything-process-source '((name . "test")
5135 (candidates "hoge" "foo" "bar")))
5136 (anything-preselect "foo")
5137 (anything-get-selection))))
5138 ;; regexp
5139 (expect "foo"
5140 (with-current-buffer (anything-create-anything-buffer t)
5141 (let ((anything-pattern "")
5142 (anything-test-mode t))
5143 (anything-process-source '((name . "test")
5144 (candidates "hoge" "foo" "bar")))
5145 (anything-preselect "fo+")
5146 (anything-get-selection))))
5147 ;; no match -> first entry
5148 (expect "hoge"
5149 (with-current-buffer (anything-create-anything-buffer t)
5150 (let ((anything-pattern "")
5151 (anything-test-mode t))
5152 (anything-process-source '((name . "test")
5153 (candidates "hoge" "foo" "bar")))
5154 (anything-preselect "not found")
5155 (anything-get-selection))))
5156 (desc "anything-check-new-input")
5157 (expect "newpattern"
5158 (stub anything-update)
5159 (stub anything-action-window)
5160 (let ((anything-pattern "pattern"))
5161 (anything-check-new-input "newpattern")
5162 anything-pattern))
5163 ;; anything-input == nil when action window is available
5164 (expect nil
5165 (stub anything-update)
5166 (stub anything-action-window => t)
5167 (let ((anything-pattern "pattern")
5168 anything-input)
5169 (anything-check-new-input "newpattern")
5170 anything-input))
5171 ;; anything-input == anything-pattern unless action window is available
5172 (expect "newpattern"
5173 (stub anything-update)
5174 (stub anything-action-window => nil)
5175 (let ((anything-pattern "pattern")
5176 anything-input)
5177 (anything-check-new-input "newpattern")
5178 anything-input))
5179 (expect (mock (anything-update))
5180 (stub anything-action-window)
5181 (let (anything-pattern)
5182 (anything-check-new-input "foo")))
5183 (desc "anything-update")
5184 (expect (mock (anything-process-source '((name . "1"))))
5185 (anything-test-update '(((name . "1"))) ""))
5186 ;; (find-function 'anything-update)
5187 ;; TODO el-mock.el should express 2nd call of function.
5188 ;; (expect (mock (anything-process-source '((name . "2"))))
5189 ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
5190 ;; (stub anything-log-run-hook)
5191 ;; (stub anything-maybe-fit-frame)
5192 ;; (stub run-with-idle-timer)
5193 ;; (anything-update))
5194 (expect (mock (run-with-idle-timer * nil 'anything-process-delayed-sources
5195 '(((name . "2") (delayed)))))
5196 (stub anything-get-sources => '(((name . "1"))
5197 ((name . "2") (delayed))))
5198 (stub anything-log-run-hook)
5199 (stub anything-maybe-fit-frame)
5200 (let ((anything-pattern "") anything-test-mode)
5201 (anything-update)))
5203 (desc "requires-pattern attribute")
5204 (expect (not-called anything-process-source)
5205 (anything-test-update '(((name . "1") (requires-pattern))) ""))
5206 (expect (not-called anything-process-source)
5207 (anything-test-update '(((name . "1") (requires-pattern . 3))) "xx"))
5209 (desc "anything-normalize-sources")
5210 (expect '(anything-c-source-test)
5211 (anything-normalize-sources 'anything-c-source-test))
5212 (expect '(anything-c-source-test)
5213 (anything-normalize-sources '(anything-c-source-test)))
5214 (expect '(anything-c-source-test)
5215 (let ((anything-sources '(anything-c-source-test)))
5216 (anything-normalize-sources nil)))
5217 (expect '(((name . "test")))
5218 (anything-normalize-sources '((name . "test"))))
5219 (expect '(((name . "test")))
5220 (anything-normalize-sources '(((name . "test")))))
5221 (desc "anything-get-action")
5222 (expect '(("identity" . identity))
5223 (stub buffer-size => 1)
5224 (stub anything-get-current-source => '((name . "test")
5225 (action ("identity" . identity))))
5226 (anything-get-action))
5227 (expect 'identity
5228 (stub buffer-size => 1)
5229 (stub anything-get-current-source => '((name . "test")
5230 (action . identity)))
5231 (anything-get-action))
5232 (expect '((("identity" . identity)) "action-transformer is called")
5233 (stub buffer-size => 1)
5234 (stub anything-get-current-source
5235 => '((name . "test")
5236 (action ("identity" . identity))
5237 (action-transformer
5238 . (lambda (actions selection)
5239 (list actions selection)))))
5240 (stub anything-get-selection => "action-transformer is called")
5241 (anything-get-action))
5242 (desc "anything-select-nth-action")
5243 (expect (error error *)
5244 (stub anything-get-selection => nil)
5245 (anything-select-nth-action 0))
5246 (desc "anything-get-nth-action")
5247 (expect 'cadr
5248 (anything-get-nth-action 2 '(("0" . car) ("1" . cdr) ("2" . cadr))))
5249 (expect (error error *)
5250 (anything-get-nth-action 2 '(("0" . car))))
5251 (expect 'identity
5252 (anything-get-nth-action 0 'identity))
5253 (expect (error error *)
5254 (anything-get-nth-action 1 'identity))
5255 (expect (error error *)
5256 (anything-get-nth-action 0 'unbound-function-xxx))
5257 (expect (error error *)
5258 (anything-get-nth-action 0 "invalid data"))
5259 (desc "anything-funcall-foreach")
5260 (expect (mock (upcase "foo"))
5261 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5262 (anything-funcall-foreach 'init))
5263 (expect (mock (downcase "bar"))
5264 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))
5265 ((init . (lambda () (downcase "bar"))))))
5266 (anything-funcall-foreach 'init))
5267 (expect (not-called anything-funcall-with-source)
5268 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5269 (anything-funcall-foreach 'not-found))
5270 ;; TODO anything-select-with-digit-shortcut test
5271 (desc "anything-get-cached-candidates")
5272 (expect '("cached" "version")
5273 (let ((anything-candidate-cache '(("test" "cached" "version"))))
5274 (anything-get-cached-candidates '((name . "test")
5275 (candidates "new")))))
5276 (expect '("new")
5277 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5278 (anything-get-cached-candidates '((name . "test")
5279 (candidates "new")))))
5280 (expect '(("test" "new")
5281 ("other" "cached" "version"))
5282 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5283 (anything-get-cached-candidates '((name . "test")
5284 (candidates "new")))
5285 anything-candidate-cache))
5286 (expect '(("other" "cached" "version"))
5287 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5288 (anything-get-cached-candidates '((name . "test")
5289 (candidates "new")
5290 (volatile)))
5291 anything-candidate-cache))
5292 ;; TODO when candidates == process
5293 ;; TODO anything-output-filter
5294 (desc "candidate-number-limit attribute")
5295 (expect '("a" "b")
5296 (let ((anything-pattern "")
5297 (anything-candidate-number-limit 20))
5298 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5299 (candidate-number-limit . 2) (volatile)))))
5300 (expect '("a" "b")
5301 (let ((anything-pattern "[abc]")
5302 (anything-candidate-number-limit 20))
5303 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5304 (candidate-number-limit . 2) (volatile)))))
5305 (expect '("a" "b" "c" "d")
5306 (let ((anything-pattern "[abcd]")
5307 (anything-candidate-number-limit 2))
5308 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c" "d")
5309 (candidate-number-limit) (volatile)))))
5310 (expect '(("TEST" ("a" "b" "c")))
5311 (let ((anything-candidate-number-limit 2))
5312 (anything-test-candidates
5313 '(((name . "TEST")
5314 (init
5315 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5316 (insert "a\nb\nc\nd\n"))))
5317 (candidates . anything-candidates-in-buffer)
5318 (match identity)
5319 (candidate-number-limit . 3)
5320 (volatile))))))
5321 (expect '(("TEST" ("a" "b" "c")))
5322 (let ((anything-candidate-number-limit 2))
5323 (anything-test-candidates
5324 '(((name . "TEST")
5325 (init
5326 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5327 (insert "a\nb\nc\nd\n"))))
5328 (candidates . anything-candidates-in-buffer)
5329 (match identity)
5330 (candidate-number-limit . 3)
5331 (volatile)))
5332 ".")))
5333 (desc "multiple init")
5334 (expect '(1 . 2)
5335 (let (a b)
5336 (anything-test-candidates
5337 '(((name . "test")
5338 (init (lambda () (setq a 1))
5339 (lambda () (setq b 2))))))
5340 (cons a b)))
5341 (expect 1
5342 (let (a)
5343 (anything-test-candidates
5344 '(((name . "test")
5345 (init (lambda () (setq a 1))))))
5347 (desc "multiple cleanup")
5348 (expect '(1 . 2)
5349 (let (a b)
5350 (anything-test-candidates
5351 '(((name . "test")
5352 (cleanup (lambda () (setq a 1))
5353 (lambda () (setq b 2))))))
5354 (cons a b)))
5355 (desc "anything-mklist")
5356 (expect '(1)
5357 (anything-mklist 1))
5358 (expect '(2)
5359 (anything-mklist '(2)))
5360 (expect '((lambda ()))
5361 (anything-mklist (lambda ())))
5362 (desc "anything-before-initialize-hook")
5363 (expect 'called
5364 (let ((anything-before-initialize-hook '((lambda () (setq v 'called))))
5366 (anything-initialize)
5368 (desc "anything-after-initialize-hook")
5369 (expect '(b a)
5370 (let ((anything-before-initialize-hook
5371 '((lambda () (setq v '(a)))))
5372 (anything-after-initialize-hook
5373 '((lambda () (setq v (cons 'b v)))))
5375 (anything-initialize)
5377 (expect 0
5378 (let ((anything-after-initialize-hook
5379 '((lambda () (setq v (buffer-size (get-buffer anything-buffer))))))
5381 (anything-initialize)
5383 (desc "get-line attribute")
5384 (expect '(("TEST" ("FOO+")))
5385 (anything-test-candidates
5386 '(((name . "TEST")
5387 (init
5388 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5389 (insert "foo+\nbar+\nbaz+\n"))))
5390 (candidates-in-buffer)
5391 (get-line . (lambda (s e) (upcase (buffer-substring-no-properties s e))))))
5392 "oo\\+"))
5393 (desc "with-anything-restore-variables")
5394 (expect '(7 8)
5395 (let ((a 7) (b 8)
5396 (anything-restored-variables '(a b)))
5397 (with-anything-restore-variables
5398 (setq a 0 b 0))
5399 (list a b)))
5400 (desc "anything-cleanup-hook")
5401 (expect 'called
5402 (let ((anything-cleanup-hook
5403 '((lambda () (setq v 'called))))
5405 (anything-cleanup)
5407 (desc "with-anything-display-same-window")
5408 (expect (non-nil)
5409 (save-window-excursion
5410 (delete-other-windows)
5411 (split-window)
5413 (let ((buf (get-buffer-create " tmp"))
5414 (win (selected-window)))
5415 (with-anything-display-same-window
5416 (display-buffer buf)
5417 (eq win (get-buffer-window buf))))))
5418 (expect (non-nil)
5419 (save-window-excursion
5420 (delete-other-windows)
5421 (split-window)
5423 (let ((buf (get-buffer-create " tmp"))
5424 (win (selected-window)))
5425 (with-anything-display-same-window
5426 (pop-to-buffer buf)
5427 (eq win (get-buffer-window buf))))))
5428 (expect (non-nil)
5429 (save-window-excursion
5430 (delete-other-windows)
5431 (split-window)
5433 (let ((buf (get-buffer-create " tmp"))
5434 (win (selected-window)))
5435 (with-anything-display-same-window
5436 (switch-to-buffer buf)
5437 (eq win (get-buffer-window buf))))))
5438 (expect (non-nil)
5439 (save-window-excursion
5440 (delete-other-windows)
5441 (let ((buf (get-buffer-create " tmp"))
5442 (win (selected-window)))
5443 (with-anything-display-same-window
5444 (display-buffer buf)
5445 (eq win (get-buffer-window buf))))))
5446 (expect (non-nil)
5447 (save-window-excursion
5448 (delete-other-windows)
5449 (let ((buf (get-buffer-create " tmp"))
5450 (win (selected-window)))
5451 (with-anything-display-same-window
5452 (pop-to-buffer buf)
5453 (eq win (get-buffer-window buf))))))
5454 (desc "search-from-end attribute")
5455 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5456 (anything-test-candidates
5457 '(((name . "TEST")
5458 (init
5459 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5460 (insert "foo+\nbar+\nbaz+\n"))))
5461 (candidates-in-buffer)
5462 (search-from-end)))))
5463 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5464 (anything-test-candidates
5465 '(((name . "TEST")
5466 (init
5467 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5468 (insert "foo+\nbar+\nbaz+\n"))))
5469 (candidates-in-buffer)
5470 (search-from-end)))
5471 "\\+"))
5472 (expect '(("TEST" ("baz+" "bar+")))
5473 (anything-test-candidates
5474 '(((name . "TEST")
5475 (init
5476 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5477 (insert "foo+\nbar+\nbaz+\n"))))
5478 (candidates-in-buffer)
5479 (search-from-end)
5480 (candidate-number-limit . 2)))))
5481 (expect '(("TEST" ("baz+" "bar+")))
5482 (anything-test-candidates
5483 '(((name . "TEST")
5484 (init
5485 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5486 (insert "foo+\nbar+\nbaz+\n"))))
5487 (candidates-in-buffer)
5488 (search-from-end)
5489 (candidate-number-limit . 2)))
5490 "\\+"))
5491 (expect '(("a" ("c2" "c1")))
5492 (anything-test-candidates
5493 '(((name . "a")
5494 (init . (lambda ()
5495 (with-current-buffer (anything-candidate-buffer 'global)
5496 (insert "c1\nc2\n"))))
5497 (search-from-end)
5498 (candidates-in-buffer)))))
5499 ;; BUG remain empty string, but the pattern is rare case.
5500 (expect '(("a" ("c" "b" "a" "")))
5501 (anything-test-candidates
5502 '(((name . "a")
5503 (init . (lambda ()
5504 (with-current-buffer (anything-candidate-buffer 'global)
5505 (insert "a\nb\nc\n"))))
5506 (search-from-end)
5507 (candidates-in-buffer)))
5508 "a*"))
5509 (desc "header-name attribute")
5510 (expect "original is transformed"
5511 (anything-test-update '(((name . "original")
5512 (candidates "1")
5513 (header-name
5514 . (lambda (name)
5515 (format "%s is transformed" name)))))
5517 (with-current-buffer (anything-buffer-get)
5518 (buffer-string)
5519 (overlay-get (car (overlays-at (1+(point-min)))) 'display)))
5520 (desc "volatile and match attribute")
5521 ;; candidates function is called once per `anything-process-delayed-sources'
5522 (expect 1
5523 (let ((v 0))
5524 (anything-test-candidates '(((name . "test")
5525 (candidates . (lambda () (incf v) '("ok")))
5526 (volatile)
5527 (match identity identity identity)))
5528 "o")
5530 (desc "accept-empty attribute")
5531 (expect nil
5532 (anything-test-candidates
5533 '(((name . "test") (candidates "") (action . identity))))
5534 (anything-execute-selection-action))
5535 (expect ""
5536 (anything-test-candidates
5537 '(((name . "test") (candidates "") (action . identity) (accept-empty))))
5538 (anything-execute-selection-action))
5539 (desc "anything-tick-hash")
5540 (expect nil
5541 (with-current-buffer (get-buffer-create " *00create+*")
5542 (puthash " *00create+*/xxx" 1 anything-tick-hash)
5543 (kill-buffer (current-buffer)))
5544 (gethash " *00create+*/xxx" anything-tick-hash))
5545 (desc "anything-execute-action-at-once-if-once")
5546 (expect "HOGE"
5547 (let ((anything-execute-action-at-once-if-one t))
5548 (anything '(((name . "one test1")
5549 (candidates "hoge")
5550 (action . upcase))))))
5551 (expect "ANY"
5552 (let ((anything-execute-action-at-once-if-one t))
5553 (anything '(((name . "one test2")
5554 (candidates "hoge" "any")
5555 (action . upcase)))
5556 "an")))
5557 ;; candidates > 1
5558 (expect (mock (read-string "word: " nil))
5559 (let ((anything-execute-action-at-once-if-one t))
5560 (anything '(((name . "one test3")
5561 (candidates "hoge" "foo" "bar")
5562 (action . identity)))
5563 nil "word: ")))
5564 (desc "anything-quit-if-no-candidate")
5565 (expect nil
5566 (let ((anything-quit-if-no-candidate t))
5567 (anything '(((name . "zero test1") (candidates) (action . upcase))))))
5568 (expect 'called
5569 (let (v (anything-quit-if-no-candidate (lambda () (setq v 'called))))
5570 (anything '(((name . "zero test2") (candidates) (action . upcase))))
5572 (desc "real-to-display attribute")
5573 (expect '(("test" (("DDD" . "ddd"))))
5574 (anything-test-candidates '(((name . "test")
5575 (candidates "ddd")
5576 (real-to-display . upcase)
5577 (action . identity)))))
5578 (expect '(("test" (("DDD" . "ddd"))))
5579 (anything-test-candidates '(((name . "test")
5580 (candidates ("ignored" . "ddd"))
5581 (real-to-display . upcase)
5582 (action . identity)))))
5583 (expect '(("Commands" (("xxxhoge" . "hoge") ("xxxboke" . "boke"))))
5584 (anything-test-candidates '(((name . "Commands")
5585 (candidates
5586 "hoge" "boke")
5587 (real-to-display . (lambda (x) (concat "xxx" x)))
5588 (action . identity)))
5589 "xxx"))
5590 (expect "test\nDDD\n"
5591 (anything-test-update '(((name . "test")
5592 (candidates "ddd")
5593 (real-to-display . upcase)
5594 (action . identity)))
5596 (with-current-buffer (anything-buffer-get) (buffer-string)))
5597 (desc "real-to-display and candidate-transformer attribute")
5598 (expect '(("test" (("DDD" . "ddd"))))
5599 (anything-test-candidates
5600 '(((name . "test")
5601 (candidates "ddd")
5602 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
5603 (real-to-display . upcase)
5604 (action . identity)))))
5605 (expect "test\nDDD\n"
5606 (anything-test-update
5607 '(((name . "test")
5608 (candidates "ddd")
5609 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
5610 (real-to-display . upcase)
5611 (action . identity)))
5613 (with-current-buffer (anything-buffer-get) (buffer-string)))
5614 (desc "real-to-display and candidates-in-buffer")
5615 (expect '(("test" (("A" . "a") ("B" . "b"))))
5616 (anything-test-candidates
5617 '(((name . "test")
5618 (init
5619 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5620 (erase-buffer)
5621 (insert "a\nb\n"))))
5622 (candidates-in-buffer)
5623 (real-to-display . upcase)
5624 (action . identity)))))
5625 (expect "test\nA\nB\n"
5626 (stub read-string)
5627 (anything
5628 '(((name . "test")
5629 (init
5630 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5631 (erase-buffer)
5632 (insert "a\nb\n"))))
5633 (candidates-in-buffer)
5634 (real-to-display . upcase)
5635 (action . identity))))
5636 (with-current-buffer (anything-buffer-get) (buffer-string)))
5637 (desc "Symbols are acceptable as candidate.")
5638 (expect '(("test" (sym "str")))
5639 (anything-test-candidates
5640 '(((name . "test")
5641 (candidates sym "str")))))
5642 (expect '(("test" ((sym . realsym) ("str" . "realstr"))))
5643 (anything-test-candidates
5644 '(((name . "test")
5645 (candidates (sym . realsym) ("str" . "realstr"))))))
5646 (expect '(("test" (sym)))
5647 (anything-test-candidates
5648 '(((name . "test")
5649 (candidates sym "str")))
5650 "sym"))
5651 (expect '(("test" ("str")))
5652 (anything-test-candidates
5653 '(((name . "test")
5654 (candidates sym "str")))
5655 "str"))
5656 (expect '(("test" ((sym . realsym))))
5657 (anything-test-candidates
5658 '(((name . "test")
5659 (candidates (sym . realsym) ("str" . "realstr"))))
5660 "sym"))
5661 (expect '(("test" (("str" . "realstr"))))
5662 (anything-test-candidates
5663 '(((name . "test")
5664 (candidates (sym . realsym) ("str" . "realstr"))))
5665 "str"))
5666 (desc "multiple transformers")
5667 (expect '(("test" ("<FOO>")))
5668 (anything-test-candidates
5669 '(((name . "test")
5670 (candidates "foo")
5671 (candidate-transformer
5672 . (lambda (cands)
5673 (anything-compose (list cands)
5674 (list (lambda (c) (mapcar 'upcase c))
5675 (lambda (c) (list (concat "<" (car c) ">")))))))))))
5676 (expect '("<FOO>")
5677 (anything-composed-funcall-with-source
5678 '((name . "test"))
5679 (list (lambda (c) (mapcar 'upcase c))
5680 (lambda (c) (list (concat "<" (car c) ">"))))
5681 '("foo"))
5683 (expect '(("test" ("<FOO>")))
5684 (anything-test-candidates
5685 '(((name . "test")
5686 (candidates "foo")
5687 (candidate-transformer
5688 (lambda (c) (mapcar 'upcase c))
5689 (lambda (c) (list (concat "<" (car c) ">"))))))))
5690 (expect '(("test" ("<BAR>")))
5691 (anything-test-candidates
5692 '(((name . "test")
5693 (candidates "bar")
5694 (filtered-candidate-transformer
5695 (lambda (c s) (mapcar 'upcase c))
5696 (lambda (c s) (list (concat "<" (car c) ">"))))))))
5697 (expect '(("find-file" . find-file)
5698 ("view-file" . view-file))
5699 (stub zerop => nil)
5700 (stub anything-get-current-source
5701 => '((name . "test")
5702 (action)
5703 (action-transformer
5704 . (lambda (a s)
5705 (anything-compose
5706 (list a s)
5707 (list (lambda (a s) (push '("view-file" . view-file) a))
5708 (lambda (a s) (push '("find-file" . find-file) a))))))))
5709 (anything-get-action))
5710 (expect '(("find-file" . find-file)
5711 ("view-file" . view-file))
5712 (stub zerop => nil)
5713 (stub anything-get-current-source
5714 => '((name . "test")
5715 (action)
5716 (action-transformer
5717 (lambda (a s) (push '("view-file" . view-file) a))
5718 (lambda (a s) (push '("find-file" . find-file) a)))))
5719 (anything-get-action))
5720 (desc "define-anything-type-attribute")
5721 (expect '((file (action . find-file)))
5722 (let (anything-type-attributes)
5723 (define-anything-type-attribute 'file '((action . find-file)))
5724 anything-type-attributes))
5725 (expect '((file (action . find-file)))
5726 (let ((anything-type-attributes '((file (action . view-file)))))
5727 (define-anything-type-attribute 'file '((action . find-file)))
5728 anything-type-attributes))
5729 (expect '((file (action . find-file))
5730 (buffer (action . switch-to-buffer)))
5731 (let (anything-type-attributes)
5732 (define-anything-type-attribute 'buffer '((action . switch-to-buffer)))
5733 (define-anything-type-attribute 'file '((action . find-file)))
5734 anything-type-attributes))
5735 (desc "anything-approximate-candidate-number")
5736 (expect 0
5737 (with-temp-buffer
5738 (let ((anything-buffer (current-buffer)))
5739 (anything-approximate-candidate-number))))
5740 (expect 1
5741 (with-temp-buffer
5742 (let ((anything-buffer (current-buffer)))
5743 (insert "Title\n"
5744 "candiate1\n")
5745 (anything-approximate-candidate-number))))
5746 (expect t
5747 (with-temp-buffer
5748 (let ((anything-buffer (current-buffer)))
5749 (insert "Title\n"
5750 "candiate1\n"
5751 "candiate2\n")
5752 (<= 2 (anything-approximate-candidate-number)))))
5753 (expect 1
5754 (with-temp-buffer
5755 (let ((anything-buffer (current-buffer)))
5756 (insert "Title\n"
5757 (propertize "multi\nline\n" 'anything-multiline t))
5758 (anything-approximate-candidate-number))))
5759 (expect t
5760 (with-temp-buffer
5761 (let ((anything-buffer (current-buffer))
5762 (anything-candidate-separator "-----"))
5763 (insert "Title\n"
5764 (propertize "multi\nline1\n" 'anything-multiline t)
5765 "-----\n"
5766 (propertize "multi\nline2\n" 'anything-multiline t))
5767 (<= 2 (anything-approximate-candidate-number)))))
5768 (desc "delayed-init attribute")
5769 (expect 0
5770 (let ((value 0))
5771 (anything-test-candidates '(((name . "test")
5772 (delayed-init . (lambda () (incf value)))
5773 (candiates "abc")
5774 (requires-pattern . 2)))
5776 value))
5777 (expect 1
5778 (let ((value 0))
5779 (anything-test-candidates '(((name . "test")
5780 (delayed-init . (lambda () (incf value)))
5781 (candiates "abc")
5782 (requires-pattern . 2)))
5783 "abc")
5784 value))
5785 (expect 2
5786 (let ((value 0))
5787 (anything-test-candidates '(((name . "test")
5788 (delayed-init (lambda () (incf value))
5789 (lambda () (incf value)))
5790 (candiates "abc")
5791 (requires-pattern . 2)))
5792 "abc")
5793 value))
5794 (expect t
5795 (let (value)
5796 (with-temp-buffer
5797 (anything-test-candidates '(((name . "test")
5798 (delayed-init
5799 . (lambda () (setq value
5800 (eq anything-current-buffer (current-buffer)))))
5801 (candiates "abc")
5802 (requires-pattern . 2)))
5803 "abc")
5804 value)))
5805 (desc "pattern-transformer attribute")
5806 (expect '(("test2" ("foo")) ("test3" ("bar")))
5807 (anything-test-candidates '(((name . "test1")
5808 (candidates "foo" "bar"))
5809 ((name . "test2")
5810 (pattern-transformer . (lambda (pat) (substring pat 1)))
5811 (candidates "foo" "bar"))
5812 ((name . "test3")
5813 (pattern-transformer . (lambda (pat) "bar"))
5814 (candidates "foo" "bar")))
5815 "xfoo"))
5816 (expect '(("test2" ("foo")) ("test3" ("bar")))
5817 (anything-test-candidates '(((name . "test1")
5818 (candidates "foo" "bar"))
5819 ((name . "test2")
5820 (pattern-transformer (lambda (pat) (substring pat 1)))
5821 (candidates "foo" "bar"))
5822 ((name . "test3")
5823 (pattern-transformer (lambda (pat) "bar"))
5824 (candidates "foo" "bar")))
5825 "xfoo"))
5826 (expect '(("test2" ("foo")) ("test3" ("bar")))
5827 (anything-test-candidates '(((name . "test1")
5828 (init
5829 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5830 (insert "foo\nbar\n"))))
5831 (candidates-in-buffer))
5832 ((name . "test2")
5833 (pattern-transformer . (lambda (pat) (substring pat 1)))
5834 (init
5835 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5836 (insert "foo\nbar\n"))))
5837 (candidates-in-buffer))
5838 ((name . "test3")
5839 (pattern-transformer . (lambda (pat) "bar"))
5840 (init
5841 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5842 (insert "foo\nbar\n"))))
5843 (candidates-in-buffer)))
5844 "xfoo"))
5845 (desc "anything-recent-push")
5846 (expect '("foo" "bar" "baz")
5847 (let ((lst '("bar" "baz")))
5848 (anything-recent-push "foo" 'lst)))
5849 (expect '("foo" "bar" "baz")
5850 (let ((lst '("foo" "bar" "baz")))
5851 (anything-recent-push "foo" 'lst)))
5852 (expect '("foo" "bar" "baz")
5853 (let ((lst '("bar" "foo" "baz")))
5854 (anything-recent-push "foo" 'lst)))
5855 (desc "anything-require-at-least-version")
5856 (expect nil
5857 (anything-require-at-least-version "1.1"))
5858 (expect nil
5859 (anything-require-at-least-version "1.200"))
5860 (expect nil
5861 (anything-require-at-least-version
5862 (and (string-match "1\.\\([0-9]+\\)" anything-version)
5863 (match-string 0 anything-version))))
5864 (expect (error)
5865 (anything-require-at-least-version "1.999"))
5866 (expect (error)
5867 (anything-require-at-least-version "1.2000"))
5868 (desc "anything-once")
5869 (expect 2
5870 (let ((i 0))
5871 (anything-test-candidates
5872 '(((name . "1")
5873 (init . (lambda () (incf i))))
5874 ((name . "2")
5875 (init . (lambda () (incf i))))))
5877 (expect 1
5878 (let ((i 0))
5879 (anything-test-candidates
5880 '(((name . "1")
5881 (init . (lambda () (anything-once (lambda () (incf i))))))
5882 ((name . "2")
5883 (init . (lambda () (anything-once (lambda () (incf i))))))))
5885 (expect 1
5886 (let ((i 0))
5887 (flet ((init1 () (anything-once (lambda () (incf i)))))
5888 (anything-test-candidates
5889 '(((name . "1")
5890 (init . init1))
5891 ((name . "2")
5892 (init . init1)))))
5894 (desc "anything-marked-candidates")
5895 (expect '("mark3" "mark1")
5896 (let* ((source '((name . "mark test")))
5897 (anything-marked-candidates
5898 `((,source . "mark1")
5899 (((name . "other")) . "mark2")
5900 (,source . "mark3"))))
5901 (stub anything-buffer-get => (current-buffer))
5902 (stub anything-get-current-source => source)
5903 (anything-marked-candidates)))
5904 (expect '("current")
5905 (let* ((source '((name . "mark test")))
5906 (anything-marked-candidates nil))
5907 (stub anything-get-current-source => source)
5908 (stub anything-get-selection => "current")
5909 (anything-marked-candidates)))
5910 (desc "anything-marked-candidates with coerce")
5911 (expect '(mark3 mark1)
5912 (let* ((source '((name . "mark test")
5913 (coerce . intern)))
5914 (anything-marked-candidates
5915 `((,source . "mark1")
5916 (((name . "other")) . "mark2")
5917 (,source . "mark3"))))
5918 (stub anything-buffer-get => (current-buffer))
5919 (stub anything-get-current-source => source)
5920 (anything-marked-candidates)))
5921 (desc "anything-let")
5922 (expect '(1 10000 nil)
5923 (let ((a 9999)
5924 (b 8)
5926 (anything-buffer (exps-tmpbuf)))
5927 (anything-let ((a 1)
5928 (b (1+ a))
5930 (anything-create-anything-buffer))
5931 (with-current-buffer anything-buffer
5932 (list a b c))))
5933 (expect (non-nil)
5934 (let ((a 9999)
5935 (b 8)
5937 (anything-buffer (exps-tmpbuf)))
5938 (anything-let ((a 1)
5939 (b (1+ a))
5941 (anything-create-anything-buffer))
5942 (with-current-buffer anything-buffer
5943 (and (assq 'a (buffer-local-variables))
5944 (assq 'b (buffer-local-variables))
5945 (assq 'c (buffer-local-variables))))))
5946 (expect 'retval
5947 (let ((a 9999)
5948 (b 8)
5950 (anything-buffer (exps-tmpbuf)))
5951 (anything-let ((a 1)
5952 (b (1+ a))
5954 'retval)))
5955 (desc "anything-let*")
5956 (expect '(1 2 nil)
5957 (let ((a 9999)
5958 (b 8)
5960 (anything-buffer (exps-tmpbuf)))
5961 (anything-let* ((a 1)
5962 (b (1+ a))
5964 (anything-create-anything-buffer))
5965 (with-current-buffer anything-buffer
5966 (list a b c))))
5967 (expect (non-nil)
5968 (let ((a 9999)
5969 (b 8)
5971 (anything-buffer (exps-tmpbuf)))
5972 (anything-let* ((a 1)
5973 (b (1+ a))
5975 (anything-create-anything-buffer))
5976 (with-current-buffer anything-buffer
5977 (and (assq 'a (buffer-local-variables))
5978 (assq 'b (buffer-local-variables))
5979 (assq 'c (buffer-local-variables))))))
5980 (expect 'retval*
5981 (let ((a 9999)
5982 (b 8)
5984 (anything-buffer (exps-tmpbuf)))
5985 (anything-let* ((a 1)
5986 (b (1+ a))
5988 'retval*)))
5989 (desc "anything with keyword")
5990 (expect (mock (anything-internal 'test-source "input" "prompt: " nil "preselect" "*test*" nil))
5991 (anything :sources 'test-source
5992 :input "input"
5993 :prompt "prompt: "
5994 :resume nil
5995 :preselect "preselect"
5996 :buffer "*test*"
5997 :keymap nil))
5998 (expect (mock (anything-internal 'test-source nil nil nil nil "*test*" nil))
5999 (anything :sources 'test-source
6000 :buffer "*test*"
6001 :candidate-number-limit 20))
6002 (expect (mock (anything-internal 'test-source nil nil nil nil "*test*" nil))
6003 (anything 'test-source nil nil nil nil "*test*" nil))
6004 (desc "anything-log-eval-internal")
6005 (expect (mock (anything-log "%S = %S" '(+ 1 2) 3))
6006 (anything-log-eval-internal '((+ 1 2))))
6007 (expect (mock (anything-log "%S = ERROR!" 'unDeFined))
6008 (anything-log-eval-internal '(unDeFined)))
6010 (desc "anything-output-filter--collect-candidates")
6011 (expect '("a" "b" "")
6012 (split-string "a\nb\n" "\n"))
6013 (expect '("a" "b")
6014 (anything-output-filter--collect-candidates
6015 '("a" "b" "") (cons 'incomplete-line "")))
6016 (expect '("a" "b")
6017 (split-string "a\nb" "\n"))
6018 (expect '("a")
6019 (anything-output-filter--collect-candidates
6020 '("a" "b") (cons 'incomplete-line "")))
6021 (expect '(incomplete-line . "b")
6022 (let ((incomplete-line-info (cons 'incomplete-line "")))
6023 (anything-output-filter--collect-candidates
6024 '("a" "b") incomplete-line-info)
6025 incomplete-line-info))
6026 (expect '("" "c" "")
6027 (split-string "\nc\n" "\n"))
6028 (expect '("b" "c")
6029 ;; "a\nb" + "\nc\n"
6030 (let ((incomplete-line-info (cons 'incomplete-line "")))
6031 (anything-output-filter--collect-candidates
6032 '("a" "b") incomplete-line-info)
6033 (anything-output-filter--collect-candidates
6034 '("" "c" "") incomplete-line-info)))
6035 (desc "coerce attribute")
6036 (expect "string"
6037 (anything :sources '(((name . "test")
6038 (candidates "string")
6039 (action . identity)))
6040 :execute-action-at-once-if-one t))
6041 (expect 'symbol
6042 (anything :sources '(((name . "test")
6043 (candidates "symbol")
6044 (coerce . intern)
6045 (action . identity)))
6046 :execute-action-at-once-if-one t))
6047 (expect 'real
6048 (anything :sources '(((name . "test")
6049 (candidates ("display" . "real"))
6050 (coerce . intern)
6051 (action . identity)))
6052 :execute-action-at-once-if-one t))
6053 (expect 'real
6054 (anything :sources '(((name . "test")
6055 (candidates)
6056 (candidate-transformer
6057 (lambda (c) '(("display" . "real"))))
6058 (coerce . intern)
6059 (action . identity)))
6060 :execute-action-at-once-if-one t))
6061 (expect 'real
6062 (anything :sources '(((name . "test")
6063 (candidates)
6064 (filtered-candidate-transformer
6065 (lambda (c s) '(("display" . "real"))))
6066 (coerce . intern)
6067 (action . identity)))
6068 :execute-action-at-once-if-one t))
6069 (expect 'real
6070 (anything :sources '(((name . "test")
6071 (candidates "dummy")
6072 (display-to-real (lambda (disp) "real"))
6073 (coerce . intern)
6074 (action . identity)))
6075 :execute-action-at-once-if-one t))
6076 (desc "anything-next-point-in-list")
6077 (expect 10
6078 (anything-next-point-in-list 5 '(10 20) nil))
6079 (expect 20
6080 (anything-next-point-in-list 15 '(10 20) nil))
6081 (expect 25
6082 (anything-next-point-in-list 25 '(10 20) nil))
6083 (expect 5
6084 (anything-next-point-in-list 5 '(10 20) t))
6085 (expect 10
6086 (anything-next-point-in-list 15 '(10 20) t))
6087 (expect 20
6088 (anything-next-point-in-list 25 '(10 20) t))
6089 (expect 5
6090 (anything-next-point-in-list 5 '() nil))
6091 (expect 5
6092 (anything-next-point-in-list 5 '() t))
6093 (expect 10
6094 (anything-next-point-in-list 5 '(10) nil))
6095 (expect 10
6096 (anything-next-point-in-list 15 '(10) t))
6097 (expect 20
6098 (anything-next-point-in-list 10 '(10 20) nil))
6099 (expect 10
6100 (anything-next-point-in-list 20 '(10 20) t))
6101 (expect 20
6102 (anything-next-point-in-list 30 '(10 20 30) t))
6106 (provide 'anything)
6107 ;; How to save (DO NOT REMOVE!!)
6108 ;; (progn (magit-push) (emacswiki-post "anything.el"))
6109 ;; Local Variables:
6110 ;; coding: utf-8
6111 ;; End:
6112 ;;; anything.el ends here