* anything.el (define-anything-type-attribute): remove nil entries.
[anything-config.git] / anything.el
blobceec706630e24ce8aca6682c08d5501c18ba5930
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 (delq nil (car definition))
1282 (anything-add-type-attribute type definition)
1283 (and doc (anything-document-type-attribute type doc))
1284 nil)
1286 (defvaralias 'anything-attributes 'anything-additional-attributes)
1287 (defvar anything-additional-attributes nil
1288 "List of all `anything' attributes.")
1289 (defun anything-document-attribute (attribute short-doc &optional long-doc)
1290 "Register ATTRIBUTE documentation introduced by plug-in.
1291 SHORT-DOC is displayed beside attribute name.
1292 LONG-DOC is displayed below attribute name and short documentation."
1293 (if long-doc
1294 (setq short-doc (concat "(" short-doc ")"))
1295 (setq long-doc short-doc
1296 short-doc ""))
1297 (add-to-list 'anything-additional-attributes attribute t)
1298 (put attribute 'anything-attrdoc
1299 (concat "- " (symbol-name attribute) " " short-doc "\n\n" long-doc "\n")))
1300 (put 'anything-document-attribute 'lisp-indent-function 2)
1302 (defun anything-require-at-least-version (version)
1303 "Output error message unless anything.el is older than VERSION.
1304 This is suitable for anything applications."
1305 (when (and (string= "1." (substring version 0 2))
1306 (string-match "1\.\\([0-9]+\\)" anything-version)
1307 (< (string-to-number (match-string 1 anything-version))
1308 (string-to-number (substring version 2))))
1309 (error "Please update anything.el!!
1311 M-x auto-install-batch anything
1313 You must have auto-install.el too.
1314 http://www.emacswiki.org/cgi-bin/wiki/download/auto-install.el
1315 ")))
1317 (defun anything-interpret-value (value &optional source)
1318 "interpret VALUE as variable, function or literal.
1319 If VALUE is a function, call it with no arguments and return the value.
1320 If SOURCE is `anything' source, `anything-source-name' is source name.
1322 If VALUE is a variable, return the value.
1324 If VALUE is a symbol, but it is not a function or a variable, cause an error.
1326 Otherwise, return VALUE itself."
1327 (cond ((and source (functionp value))
1328 (anything-funcall-with-source source value))
1329 ((functionp value)
1330 (funcall value))
1331 ((and (symbolp value) (boundp value))
1332 (symbol-value value))
1333 ((symbolp value)
1334 (error "anything-interpret-value: Symbol must be a function or a variable"))
1336 value)))
1338 (defun anything-once (function &rest args)
1339 "Ensure FUNCTION with ARGS to be called once in `anything' session."
1340 (let ((spec (cons function args)))
1341 (unless (member spec anything-once-called-functions)
1342 (apply function args)
1343 (push spec anything-once-called-functions))))
1345 ;; (@* "Core: API helper")
1346 (defun anything-empty-buffer-p (&optional buffer)
1347 (zerop (buffer-size (and buffer (get-buffer buffer)))))
1349 (defun anything-let-eval-varlist (varlist)
1350 (mapcar (lambda (pair)
1351 (if (listp pair)
1352 (cons (car pair) (eval (cadr pair)))
1353 (cons pair nil)))
1354 varlist))
1355 (defun anything-let*-eval-varlist (varlist)
1356 (let ((vars (mapcar (lambda (pair) (or (car-safe pair) pair)) varlist)))
1357 (eval `(let ,vars
1358 ,@(mapcar (lambda (pair)
1359 (if (listp pair)
1360 `(setq ,(car pair) ,(cadr pair))
1361 `(setq ,pair nil)))
1362 varlist)
1363 (mapcar (lambda (v) (cons v (symbol-value v))) ',vars)))))
1364 (defun anything-let-internal (binding bodyfunc)
1365 "Evaluate BODYFUNC and Set BINDING to anything buffer-local variables.
1366 BINDING is a list of (VARNAME . VALUE) pair."
1367 (setq anything-let-variables binding)
1368 (unwind-protect
1369 (funcall bodyfunc)
1370 (setq anything-let-variables nil)))
1373 ;; (@* "Core: tools")
1374 (defun anything-current-line-contents ()
1375 "Current line strig without properties."
1376 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1378 (defun anything-funcall-with-source (source func &rest args)
1379 "Call FUNC with ARGS with variable `anything-source-name' and `source' is bound.
1380 FUNC can be function list. Return the result of last function call."
1381 (let ((anything-source-name (assoc-default 'name source))
1382 result)
1383 (anything-log-eval anything-source-name func args)
1384 (dolist (func (if (functionp func) (list func) func) result)
1385 (setq result (apply func args)))))
1387 (defun anything-funcall-foreach (sym)
1388 "Call the sym function(s) for each source if any."
1389 (dolist (source (anything-get-sources))
1390 (anything-aif (assoc-default sym source)
1391 (anything-funcall-with-source source it))))
1393 (defun anything-normalize-sources (sources)
1394 "If SOURCES is only one source, make a list."
1395 (cond ((or (and sources ; avoid nil
1396 (symbolp sources))
1397 (and (listp sources) (assq 'name sources)))
1398 (list sources))
1399 (sources)
1400 (t anything-sources)))
1402 (defun anything-approximate-candidate-number ()
1403 "Approximate Number of candidates.
1404 It is used to check if candidate number is 0, 1, or 2+."
1405 (with-current-buffer anything-buffer
1406 (let ((lines (1- (line-number-at-pos (1- (point-max))))))
1407 (if (zerop lines)
1409 (save-excursion
1410 (goto-char (point-min))
1411 (forward-line 1)
1412 (if (anything-pos-multiline-p)
1413 (if (search-forward anything-candidate-separator nil t) 2 1)
1414 lines))))))
1416 (defmacro with-anything-quittable (&rest body)
1417 `(let (inhibit-quit)
1418 (condition-case v
1419 (progn ,@body)
1420 (quit (setq anything-quit t)
1421 (exit-minibuffer)
1422 (keyboard-quit)))))
1423 (put 'with-anything-quittable 'lisp-indent-function 0)
1425 (defun anything-compose (arg-lst func-lst)
1426 "Call each function in FUNC-LST with the arguments specified in ARG-LST.
1427 The result of each function will be the new `car' of ARG-LST.
1429 This function allows easy sequencing of transformer functions."
1430 (dolist (func func-lst)
1431 (setcar arg-lst (apply func arg-lst)))
1432 (car arg-lst))
1434 (defun anything-composed-funcall-with-source (source funcs &rest args)
1435 (if (functionp funcs)
1436 (apply 'anything-funcall-with-source source funcs args)
1437 (apply 'anything-funcall-with-source
1438 source (lambda (&rest args) (anything-compose args funcs)) args)))
1440 (defun anything-new-timer (variable timer)
1441 "Set new TIMER to VARIABLE. Old timer is cancelled."
1442 (anything-aif (symbol-value variable)
1443 (cancel-timer it))
1444 (set variable timer))
1446 ;; (@* "Core: entry point")
1447 (defconst anything-argument-keys
1448 '(:sources :input :prompt :resume :preselect :buffer :keymap))
1449 ;;;###autoload
1450 (defun anything (&rest plist)
1451 "Select anything. In Lisp program, some optional arguments can be used.
1453 PLIST is a list like (:key1 val1 :key2 val2 ...) or
1454 (&optional sources input prompt resume preselect buffer keymap).
1456 Basic keywords are the following:
1458 - :sources
1460 Temporary value of `anything-sources'. It also accepts a
1461 symbol, interpreted as a variable of an anything source. It
1462 also accepts an alist representing an anything source, which is
1463 detected by (assq 'name ANY-SOURCES)
1465 - :input
1467 Temporary value of `anything-pattern', ie. initial input of minibuffer.
1469 - :prompt
1471 Prompt other than \"pattern: \".
1473 - :resume
1475 If t, Resurrect previously instance of `anything'. Skip the initialization.
1476 If 'noresume, this instance of `anything' cannot be resumed.
1478 - :preselect
1480 Initially selected candidate. Specified by exact candidate or a regexp.
1481 Note that it is not working with delayed sources.
1483 - :buffer
1485 `anything-buffer' instead of *anything*.
1487 - :keymap
1489 `anything-map' for current `anything' session.
1492 Of course, conventional arguments are supported, the two are same.
1494 (anything :sources sources :input input :prompt prompt :resume resume
1495 :preselect preselect :buffer buffer :keymap keymap)
1496 (anything sources input prompt resume preselect buffer keymap)
1499 Other keywords are interpreted as local variables of this anything session.
1500 The `anything-' prefix can be omitted. For example,
1502 (anything :sources 'anything-c-source-buffers
1503 :buffer \"*buffers*\" :candidate-number-limit 10)
1505 means starting anything session with `anything-c-source-buffers'
1506 source in *buffers* buffer and set
1507 `anything-candidate-number-limit' to 10 as session local variable. "
1508 (interactive)
1509 (if (keywordp (car plist))
1510 (anything-let-internal
1511 (anything-parse-keys plist)
1512 (lambda ()
1513 (apply 'anything
1514 (mapcar (lambda (key) (plist-get plist key))
1515 anything-argument-keys))))
1516 (apply 'anything-internal plist)))
1518 (defun* anything-resume (&optional (any-buffer anything-last-buffer) buffer-pattern (any-resume t))
1519 "Resurrect previously invoked `anything'."
1520 (interactive)
1521 (when (or current-prefix-arg buffer-pattern)
1522 (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
1523 (setq anything-compiled-sources nil)
1524 (anything
1525 (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
1526 anything-last-sources anything-sources)
1527 (buffer-local-value 'anything-input-local (get-buffer any-buffer))
1528 nil any-resume nil any-buffer))
1530 ;;; rubikitch: experimental
1531 ;;; I use this and check it whether I am convenient.
1532 ;;; I may introduce an option to control the behavior.
1533 (defun* anything-resume-window-only (&optional (any-buffer anything-last-buffer) buffer-pattern)
1534 (interactive)
1535 (anything-resume any-buffer buffer-pattern 'window-only))
1537 ;;;###autoload
1538 (defun anything-at-point (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
1539 "Same as `anything' except when C-u is pressed, the initial input is the symbol at point."
1540 (interactive)
1541 (anything any-sources
1542 (if current-prefix-arg
1543 (concat "\\b" (thing-at-point 'symbol) "\\b"
1544 (if (featurep 'anything-match-plugin) " " ""))
1545 any-input)
1546 any-prompt any-resume any-preselect any-buffer))
1548 ;;;###autoload
1549 (defun anything-other-buffer (any-sources any-buffer)
1550 "Simplified interface of `anything' with other `anything-buffer'"
1551 (anything any-sources nil nil nil nil any-buffer))
1553 ;;; (@* "Core: entry point helper")
1554 (defun anything-internal (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer any-keymap)
1555 "Older interface of `anything'. It is called by `anything'."
1556 (anything-log "++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
1557 (anything-log-eval any-prompt any-preselect any-buffer any-keymap)
1558 (unwind-protect
1559 (condition-case v
1560 (let ( ;; It is needed because `anything-source-name' is non-nil
1561 ;; when `anything' is invoked by action. Awful global scope.
1562 anything-source-name
1563 anything-in-persistent-action
1564 anything-quit
1565 (case-fold-search t)
1566 (anything-buffer (or any-buffer anything-buffer))
1567 ;; cua-mode ; avoid error when region is selected
1569 (with-anything-restore-variables
1570 (anything-initialize-1 any-resume any-input any-sources)
1571 (anything-display-buffer anything-buffer)
1572 (anything-log "show prompt")
1573 (unwind-protect
1574 (anything-read-pattern-maybe
1575 any-prompt any-input any-preselect any-resume any-keymap)
1576 (anything-cleanup)))
1577 (prog1 (unless anything-quit (anything-execute-selection-action-1))
1578 (anything-log "end session --------------------------------------------")))
1579 (quit
1580 (anything-on-quit)
1581 (anything-log "end session (quit) -------------------------------------")
1582 nil))
1583 (anything-log-save-maybe)))
1587 (defun anything-parse-keys (keys)
1588 (loop for (key value &rest _) on keys by #'cddr
1589 for symname = (substring (symbol-name key) 1)
1590 for sym = (intern (if (string-match "^anything-" symname)
1591 symname
1592 (concat "anything-" symname)))
1593 unless (memq key anything-argument-keys)
1594 collect (cons sym value)))
1596 (defun anything-resume-p (any-resume)
1597 "Whethre current anything session is resumed or not."
1598 (memq any-resume '(t window-only)))
1600 (defvar anything-buffers nil
1601 "All of `anything-buffer' in most recently used order.")
1602 (defun anything-initialize-1 (any-resume any-input any-sources)
1603 "The real initialization of `anything'.
1605 This function name should be `anything-initialize', but anything
1606 extensions may advice `anything-initalize'. I cannot rename, sigh."
1607 (anything-log "start initialization: any-resume=%S any-input=%S" any-resume any-input)
1608 (anything-frame/window-configuration 'save)
1609 (setq anything-sources (anything-normalize-sources any-sources))
1610 (anything-log "sources = %S" anything-sources)
1611 (anything-hooks 'setup)
1612 (anything-current-position 'save)
1613 (if (anything-resume-p any-resume)
1614 (anything-initialize-overlays (anything-buffer-get))
1615 (anything-initialize))
1616 (unless (eq any-resume 'noresume)
1617 (anything-recent-push anything-buffer 'anything-buffers)
1618 (setq anything-last-buffer anything-buffer))
1619 (when any-input (setq anything-input any-input anything-pattern any-input))
1620 (and (anything-resume-p any-resume) (anything-funcall-foreach 'resume))
1621 (anything-log "end initialization"))
1623 (defun anything-execute-selection-action-1 ()
1624 (unwind-protect
1625 (anything-execute-selection-action)
1626 (anything-aif (get-buffer anything-action-buffer)
1627 (kill-buffer it))
1628 (anything-log-run-hook 'anything-after-action-hook)))
1630 (defun anything-on-quit ()
1631 (setq minibuffer-history (cons anything-input minibuffer-history))
1632 (anything-current-position 'restore))
1634 (defun anything-resume-select-buffer (input)
1635 (anything '(((name . "Resume anything buffer")
1636 (candidates . anything-buffers)
1637 (action . identity)))
1638 input nil 'noresume nil "*anything resume*"))
1640 (defun anything-recent-push (elt list-var)
1641 "Add ELT to the value of LIST-VAR as most recently used value."
1642 (let ((m (member elt (symbol-value list-var))))
1643 (and m (set list-var (delq (car m) (symbol-value list-var))))
1644 (push elt (symbol-value list-var))))
1646 ;;; (@* "Core: Accessors")
1647 ;;; rubikitch: I love to create functions to control variables.
1648 (defvar anything-current-position nil
1649 "Cons of (point) and (window-start) when `anything' is invoked.
1650 It is needed because restoring position when `anything' is keyboard-quitted.")
1651 (defun anything-current-position (save-or-restore)
1652 (case save-or-restore
1653 (save
1654 (setq anything-current-position (cons (point) (window-start))))
1655 (restore
1656 (goto-char (car anything-current-position))
1657 (set-window-start (selected-window) (cdr anything-current-position)))))
1659 ;;; FIXME I want to remove them. But anything-iswitchb uses them.
1660 (defun anything-current-frame/window-configuration ()
1661 (funcall (cdr anything-save-configuration-functions)))
1662 (defun anything-set-frame/window-configuration (conf)
1663 (funcall (car anything-save-configuration-functions) conf))
1665 (lexical-let (conf)
1666 (defun anything-frame/window-configuration (save-or-restore)
1667 (anything-log-eval anything-save-configuration-functions)
1668 (case save-or-restore
1669 (save (setq conf (funcall (cdr anything-save-configuration-functions))))
1670 (restore (funcall (car anything-save-configuration-functions) conf)))))
1672 ;; (@* "Core: Display *anything* buffer")
1673 (defun anything-display-buffer (buf)
1674 "Display *anything* buffer."
1675 (funcall (with-current-buffer buf anything-display-function) buf))
1677 (defun anything-default-display-buffer (buf)
1678 (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
1680 ;; (@* "Core: initialize")
1681 (defun anything-initialize ()
1682 "Initialize anything settings and set up the anything buffer."
1683 (anything-log-run-hook 'anything-before-initialize-hook)
1684 (setq anything-once-called-functions nil)
1685 (setq anything-delayed-init-executed nil)
1686 (setq anything-current-buffer (current-buffer))
1687 (setq anything-buffer-file-name buffer-file-name)
1688 (setq anything-issued-errors nil)
1689 (setq anything-compiled-sources nil)
1690 (setq anything-saved-current-source nil)
1691 ;; Call the init function for sources where appropriate
1692 (anything-funcall-foreach 'init)
1694 (setq anything-pattern "")
1695 (setq anything-input "")
1696 (setq anything-candidate-cache nil)
1697 (setq anything-last-sources anything-sources)
1699 (anything-create-anything-buffer)
1700 (anything-log-run-hook 'anything-after-initialize-hook))
1702 (defvar anything-reading-pattern nil
1703 "Whether in `read-string' in anything or not.")
1704 (defun anything-read-pattern-maybe (any-prompt any-input any-preselect any-resume any-keymap)
1705 (if (anything-resume-p any-resume)
1706 (anything-mark-current-line)
1707 (anything-update))
1708 (select-frame-set-input-focus (window-frame (minibuffer-window)))
1709 (anything-preselect any-preselect)
1710 (let ((minibuffer-local-map
1711 (with-current-buffer (anything-buffer-get)
1712 (and any-keymap (set (make-local-variable 'anything-map) any-keymap))
1713 anything-map)))
1714 (anything-log-eval (anything-approximate-candidate-number)
1715 anything-execute-action-at-once-if-one
1716 anything-quit-if-no-candidate)
1717 (cond ((and anything-execute-action-at-once-if-one
1718 (= (anything-approximate-candidate-number) 1))
1719 (ignore))
1720 ((and anything-quit-if-no-candidate
1721 (= (anything-approximate-candidate-number) 0))
1722 (setq anything-quit t)
1723 (and (functionp anything-quit-if-no-candidate)
1724 (funcall anything-quit-if-no-candidate)))
1726 (let ((anything-reading-pattern t))
1727 (read-string (or any-prompt "pattern: ") any-input))))))
1729 (defun anything-create-anything-buffer (&optional test-mode)
1730 "Create newly created `anything-buffer'.
1731 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
1732 (when test-mode
1733 (setq anything-candidate-cache nil))
1734 (with-current-buffer (get-buffer-create anything-buffer)
1735 (anything-log "kill local variables: %S" (buffer-local-variables))
1736 (kill-all-local-variables)
1737 (set (make-local-variable 'inhibit-read-only) t)
1738 (buffer-disable-undo)
1739 (erase-buffer)
1740 (set (make-local-variable 'inhibit-read-only) t)
1741 (set (make-local-variable 'anything-last-sources-local) anything-sources)
1742 (set (make-local-variable 'anything-follow-mode) nil)
1743 (set (make-local-variable 'anything-display-function) anything-display-function)
1744 (anything-initialize-persistent-action)
1745 (anything-log-eval anything-display-function anything-let-variables)
1746 (loop for (var . val) in anything-let-variables
1747 do (set (make-local-variable var) val))
1749 (setq cursor-type nil)
1750 (setq mode-name "Anything"))
1751 (anything-initialize-overlays anything-buffer)
1752 (get-buffer anything-buffer))
1754 (defun anything-initialize-overlays (buffer)
1755 (anything-log "overlay setup")
1756 (if anything-selection-overlay
1757 ;; make sure the overlay belongs to the anything buffer if
1758 ;; it's newly created
1759 (move-overlay anything-selection-overlay (point-min) (point-min)
1760 (get-buffer buffer))
1762 (setq anything-selection-overlay
1763 (make-overlay (point-min) (point-min) (get-buffer buffer)))
1764 (overlay-put anything-selection-overlay 'face anything-selection-face))
1766 (cond (anything-enable-shortcuts
1767 (setq anything-shortcut-keys
1768 (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist))
1769 (unless anything-digit-overlays
1770 (setq anything-digit-overlays
1771 (loop for key across anything-shortcut-keys
1772 for overlay = (make-overlay (point-min) (point-min)
1773 (get-buffer buffer))
1774 do (overlay-put overlay 'before-string
1775 (format "%s - " (upcase (make-string 1 key))))
1776 collect overlay))))
1777 (anything-digit-overlays
1778 (mapc 'delete-overlay anything-digit-overlays)
1779 (setq anything-digit-overlays nil))))
1781 (defun anything-hooks (setup-or-cleanup)
1782 (let ((hooks '((deferred-action-list anything-check-minibuffer-input)
1783 (minibuffer-setup-hook anything-print-error-messages))))
1784 (if (eq setup-or-cleanup 'setup)
1785 (dolist (args hooks) (apply 'add-hook args))
1786 (dolist (args (reverse hooks)) (apply 'remove-hook args)))))
1788 ;; (@* "Core: clean up")
1789 ;;; TODO move
1790 (defun anything-cleanup ()
1791 "Clean up the mess."
1792 (anything-log "start cleanup")
1793 (with-current-buffer anything-buffer
1794 (setq cursor-type t))
1795 (bury-buffer anything-buffer)
1796 (anything-funcall-foreach 'cleanup)
1797 (anything-new-timer 'anything-check-minibuffer-input-timer nil)
1798 (anything-kill-async-processes)
1799 (anything-log-run-hook 'anything-cleanup-hook)
1800 (anything-hooks 'cleanup)
1801 (anything-frame/window-configuration 'restore))
1803 ;; (@* "Core: input handling")
1804 (defun anything-check-minibuffer-input ()
1805 "Extract input string from the minibuffer and check if it needs
1806 to be handled."
1807 (let ((delay (with-current-buffer anything-buffer anything-input-idle-delay)))
1808 (if (or (not delay) (anything-action-window))
1809 (anything-check-minibuffer-input-1)
1810 (anything-new-timer
1811 'anything-check-minibuffer-input-timer
1812 (run-with-idle-timer delay nil 'anything-check-minibuffer-input-1)))))
1814 (defun anything-check-minibuffer-input-1 ()
1815 (with-anything-quittable
1816 (with-selected-window (minibuffer-window)
1817 (anything-check-new-input (minibuffer-contents)))))
1819 (defun anything-check-new-input (input)
1820 "Check input string and update the anything buffer if
1821 necessary."
1822 (unless (equal input anything-pattern)
1823 (setq anything-pattern input)
1824 (unless (anything-action-window)
1825 (setq anything-input anything-pattern))
1826 (anything-log-eval anything-pattern anything-input)
1827 (anything-update)))
1829 ;; (@* "Core: source compiler")
1830 (defvar anything-compile-source-functions-default anything-compile-source-functions
1831 "Plug-ins this file provides.")
1832 (defun anything-compile-sources (sources funcs)
1833 "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
1834 Anything plug-ins are realized by this function."
1835 (mapcar
1836 (lambda (source)
1837 (loop with source = (if (listp source) source (symbol-value source))
1838 for f in funcs
1839 do (setq source (funcall f source))
1840 finally (return source)))
1841 sources))
1843 ;; (@* "Core: plug-in attribute documentation hack")
1845 ;; `anything-document-attribute' is public API.
1846 (defadvice documentation-property (after anything-document-attribute activate)
1847 "Hack to display plug-in attributes' documentation as `anything-sources' docstring."
1848 (when (eq symbol 'anything-sources)
1849 (setq ad-return-value
1850 (concat ad-return-value "\n"
1851 (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
1852 anything-additional-attributes
1853 "\n")))))
1854 ;; (describe-variable 'anything-sources)
1855 ;; (documentation-property 'anything-sources 'variable-documentation)
1856 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
1858 ;; (@* "Core: all candidates")
1859 (defun anything-process-delayed-init (source)
1860 (let ((name (assoc-default 'name source)))
1861 (unless (member name anything-delayed-init-executed)
1862 (anything-aif (assoc-default 'delayed-init source)
1863 (with-current-buffer anything-current-buffer
1864 (anything-funcall-with-source source it)
1865 (dolist (f (if (functionp it) (list it) it))
1866 (add-to-list 'anything-delayed-init-executed name)))))))
1868 (defun anything-get-candidates (source)
1869 "Retrieve and return the list of candidates from
1870 SOURCE."
1871 (anything-process-delayed-init source)
1872 (let* ((candidate-source (assoc-default 'candidates source))
1873 (type-error (lambda ()
1874 (error (concat "Candidates must either be a function, "
1875 " a variable or a list: %s")
1876 candidate-source)))
1877 (candidates (condition-case err
1878 (anything-interpret-value candidate-source source)
1879 (error (funcall type-error)))))
1880 (cond ((processp candidates) candidates)
1881 ((listp candidates) (anything-transform-candidates candidates source))
1882 (t (funcall type-error)))))
1885 (defun anything-get-cached-candidates (source)
1886 "Return the cached value of candidates for SOURCE.
1887 Cache the candidates if there is not yet a cached value."
1888 (let* ((name (assoc-default 'name source))
1889 (candidate-cache (assoc name anything-candidate-cache)))
1890 (cond (candidate-cache
1891 (anything-log "use cached candidates")
1892 (cdr candidate-cache))
1894 (anything-log "calculate candidates")
1895 (let ((candidates (anything-get-candidates source)))
1896 (cond ((processp candidates)
1897 (push (cons candidates
1898 (append source
1899 (list (cons 'item-count 0)
1900 (cons 'incomplete-line ""))))
1901 anything-async-processes)
1902 (set-process-filter candidates 'anything-output-filter)
1903 (setq candidates nil))
1904 ((not (assoc 'volatile source))
1905 (setq candidate-cache (cons name candidates))
1906 (push candidate-cache anything-candidate-cache)))
1907 candidates)))))
1909 ;;; (@* "Core: candidate transformers")
1910 (defun anything-process-candidate-transformer (candidates source)
1911 (anything-aif (assoc-default 'candidate-transformer source)
1912 (anything-composed-funcall-with-source source it candidates)
1913 candidates))
1914 (defun anything-process-filtered-candidate-transformer (candidates source)
1915 (anything-aif (assoc-default 'filtered-candidate-transformer source)
1916 (anything-composed-funcall-with-source source it candidates source)
1917 candidates))
1918 (defun anything-process-filtered-candidate-transformer-maybe (candidates source process-p)
1919 (if process-p
1920 (anything-process-filtered-candidate-transformer candidates source)
1921 candidates))
1922 (defun anything-process-real-to-display (candidates source)
1923 (anything-aif (assoc-default 'real-to-display source)
1924 (setq candidates (anything-funcall-with-source
1925 source 'mapcar
1926 (lambda (cand_)
1927 (if (consp cand_)
1928 ;; override DISPLAY from candidate-transformer
1929 (cons (funcall it (cdr cand_)) (cdr cand_))
1930 (cons (funcall it cand_) cand_)))
1931 candidates))
1932 candidates))
1933 (defun anything-transform-candidates (candidates source &optional process-p)
1934 "Transform CANDIDATES according to candidate transformers."
1935 (anything-process-real-to-display
1936 (anything-process-filtered-candidate-transformer-maybe
1937 (anything-process-candidate-transformer candidates source) source process-p)
1938 source))
1941 ;; (@* "Core: narrowing candidates")
1942 (defun anything-candidate-number-limit (source)
1943 "`anything-candidate-number-limit' variable may be overridden by SOURCE.
1944 If (candidate-number-limit) is in SOURCE, show all candidates in SOURCE,
1945 ie. cancel the effect of `anything-candidate-number-limit'."
1946 (anything-aif (assq 'candidate-number-limit source)
1947 (or (cdr it) 99999999)
1948 (or anything-candidate-number-limit 99999999)))
1950 (defconst anything-default-match-functions
1951 (list (lambda (candidate)
1952 (string-match anything-pattern candidate))))
1954 (defun anything-compute-matches (source)
1955 "Compute matches from SOURCE according to its settings."
1956 (if debug-on-error
1957 (anything-compute-matches-internal source)
1958 (condition-case v
1959 (anything-compute-matches-internal source)
1960 (error (anything-log-error
1961 "anything-compute-matches: error when processing source: %s"
1962 (assoc-default 'name source))
1963 nil))))
1965 (defun anything-candidate-get-display (candidate)
1966 "Get display part (searched) from CANDIDATE.
1967 CANDIDATE is a string, a symbol, or (DISPLAY . REAL) cons cell."
1968 (format "%s" (or (car-safe candidate) candidate)))
1970 (defun anything-process-pattern-transformer (pattern source)
1971 (anything-aif (assoc-default 'pattern-transformer source)
1972 (anything-composed-funcall-with-source source it pattern)
1973 pattern))
1975 (defun anything-match-functions (source)
1976 (or (assoc-default 'match source)
1977 anything-default-match-functions))
1979 (defmacro anything-accumulate-candidates-internal (cand newmatches hash item-count limit)
1980 "INTERNAL: add CAND (ITEM-COUNT th match) into NEWMATCHES.
1981 Use HASH to uniq NEWMATCHES.
1982 if ITEM-COUNT reaches LIMIT, exit from inner loop."
1983 `(unless (gethash ,cand ,hash)
1984 (puthash ,cand t ,hash)
1985 (push ,cand ,newmatches)
1986 (incf ,item-count)
1987 (when (= ,item-count ,limit)
1988 (setq exit t)
1989 (return))))
1991 (defun anything-take-first-elements (seq n)
1992 (if (> (length seq) n)
1993 (setq seq (subseq seq 0 n))
1994 seq))
1996 (defun anything-match-from-candidates (cands matchfns limit)
1997 (let (matches)
1998 (condition-case nil
1999 (let ((item-count 0) exit)
2000 (clrhash anything-match-hash)
2001 (dolist (match matchfns)
2002 (let (newmatches)
2003 (dolist (candidate cands)
2004 (when (funcall match (anything-candidate-get-display candidate))
2005 (anything-accumulate-candidates-internal
2006 candidate newmatches anything-match-hash item-count limit)))
2007 (setq matches (append matches (reverse newmatches)))
2008 (if exit (return)))))
2009 (invalid-regexp (setq matches nil)))
2010 matches))
2012 (defun anything-compute-matches-internal (source)
2013 (let ((matchfns (anything-match-functions source))
2014 (anything-source-name (assoc-default 'name source))
2015 (limit (anything-candidate-number-limit source))
2016 (anything-pattern (anything-process-pattern-transformer
2017 anything-pattern source)))
2018 (anything-process-filtered-candidate-transformer
2019 (if (or (equal anything-pattern "") (equal matchfns '(identity)))
2020 (anything-take-first-elements
2021 (anything-get-cached-candidates source) limit)
2022 (anything-match-from-candidates
2023 (anything-get-cached-candidates source) matchfns limit))
2024 source)))
2026 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2028 (defun anything-process-source (source)
2029 "Display matches from SOURCE according to its settings."
2030 (anything-log-eval (assoc-default 'name source))
2031 (if (assq 'direct-insert-match source) ;experimental
2032 (anything-process-source--direct-insert-match source)
2033 (let ((matches (anything-compute-matches source)))
2034 (when matches
2035 (when anything-test-mode
2036 (setq anything-test-candidate-list
2037 `(,@anything-test-candidate-list
2038 (,(assoc-default 'name source)
2039 ,matches))))
2040 (anything-insert-header-from-source source)
2041 (if (not (assq 'multiline source))
2042 (mapc 'anything-insert-match-with-digit-overlay matches)
2043 (let ((start (point)) separate)
2044 (dolist (match matches)
2045 (if separate
2046 (anything-insert-candidate-separator)
2047 (setq separate t))
2048 (anything-insert-match-with-digit-overlay match))
2049 (put-text-property start (point) 'anything-multiline t)))))))
2051 (defun anything-insert-match-with-digit-overlay (match)
2052 (declare (special source))
2053 (anything-put-digit-overlay-maybe)
2054 (anything-insert-match match 'insert source))
2056 (defun anything-put-digit-overlay-maybe ()
2057 (when (and anything-enable-shortcuts
2058 (not (eq anything-digit-shortcut-count
2059 (length anything-digit-overlays))))
2060 (move-overlay (nth anything-digit-shortcut-count
2061 anything-digit-overlays)
2062 (point-at-bol)
2063 (point-at-bol))
2064 (incf anything-digit-shortcut-count)))
2066 (defun anything-process-source--direct-insert-match (source)
2067 "[EXPERIMENTAL] Insert candidates from `anything-candidate-buffer'"
2068 (anything-log-eval (assoc-default 'name source))
2069 (let ((anything-source-name (assoc-default 'name source))
2070 content-buf)
2071 (funcall (assoc-default 'candidates source))
2072 (setq content-buf (anything-candidate-buffer))
2073 (unless (anything-empty-buffer-p content-buf)
2074 (anything-insert-header-from-source source)
2075 (insert-buffer-substring content-buf)
2076 ;; TODO call anything-put-digit-overlay-maybe with loop
2079 (defun anything-process-delayed-sources (delayed-sources)
2080 "Process delayed sources if the user is idle for
2081 `anything-idle-delay' seconds."
2082 (with-anything-quittable
2083 (anything-log-eval (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2084 (with-current-buffer anything-buffer
2085 (save-excursion
2086 (goto-char (point-max))
2087 (mapc 'anything-process-source delayed-sources)
2088 (when (and (not (anything-empty-buffer-p))
2089 ;; no selection yet
2090 (= (overlay-start anything-selection-overlay)
2091 (overlay-end anything-selection-overlay)))
2092 (goto-char (point-min))
2093 (anything-next-line)))
2094 (save-excursion
2095 (goto-char (point-min))
2096 (anything-log-run-hook 'anything-update-hook))
2097 (anything-maybe-fit-frame))))
2099 ;; (@* "Core: *anything* buffer contents")
2100 (defvar anything-input-local nil)
2101 (defvar anything-process-delayed-sources-timer nil)
2102 (defun anything-update ()
2103 "Update the list of matches in the anything buffer according to
2104 the current pattern."
2105 (anything-log "start update")
2106 (setq anything-digit-shortcut-count 0)
2107 (anything-kill-async-processes)
2108 (with-current-buffer (anything-buffer-get)
2109 (set (make-local-variable 'anything-input-local) anything-pattern)
2110 (erase-buffer)
2111 (when anything-enable-shortcuts
2112 (mapc 'delete-overlay anything-digit-overlays))
2113 (let (delayed-sources)
2114 (unwind-protect
2115 (setq delayed-sources
2116 (loop for source in (remove-if-not 'anything-update-source-p
2117 (anything-get-sources))
2118 if (anything-delayed-source-p source)
2119 collect source
2120 else do (anything-process-source source)))
2121 (anything-log-eval
2122 (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2123 (anything-update-move-first-line)
2124 (if anything-test-mode
2125 (mapc 'anything-process-source delayed-sources)
2126 (anything-maybe-fit-frame)
2127 (when delayed-sources
2128 (anything-new-timer
2129 'anything-process-delayed-sources-timer
2130 (run-with-idle-timer
2131 anything-idle-delay nil
2132 'anything-process-delayed-sources delayed-sources)))
2133 ;; FIXME I want to execute anything-after-update-hook
2134 ;; AFTER processing delayed sources
2135 (anything-log-run-hook 'anything-after-update-hook))
2136 (anything-log "end update")))))
2138 (defun anything-update-source-p (source)
2139 (and (or (not anything-source-filter)
2140 (member (assoc-default 'name source) anything-source-filter))
2141 (>= (length anything-pattern)
2142 (anything-aif (assoc 'requires-pattern source)
2143 (or (cdr it) 1)
2144 0))))
2145 (defun anything-delayed-source-p (source)
2146 (or (assoc 'delayed source)
2147 (and anything-quick-update
2148 (< (window-height (get-buffer-window (current-buffer)))
2149 (line-number-at-pos (point-max))))))
2151 (defun anything-update-move-first-line ()
2152 (goto-char (point-min))
2153 (save-excursion (anything-log-run-hook 'anything-update-hook))
2154 (anything-next-line))
2156 (defun anything-force-update ()
2157 "Recalculate and update candidates.
2158 If current source has `update' attribute, a function without argument, call it before update."
2159 (interactive)
2160 (let ((source (anything-get-current-source)))
2161 (if source
2162 (anything-force-update--reinit source)
2163 (anything-erase-message)
2164 (mapc 'anything-force-update--reinit (anything-get-sources)))
2165 (let ((selection (anything-get-selection nil t)))
2166 (anything-update)
2167 (anything-keep-selection source selection))))
2169 (defun anything-force-update--reinit (source)
2170 (anything-aif (anything-funcall-with-source source 'anything-candidate-buffer)
2171 (kill-buffer it))
2172 (dolist (attr '(update init))
2173 (anything-aif (assoc-default attr source)
2174 (anything-funcall-with-source source it)))
2175 (anything-remove-candidate-cache source))
2177 (defun anything-erase-message ()
2178 (message ""))
2180 (defun anything-keep-selection (source selection)
2181 (when (and source selection)
2182 (with-anything-window
2183 (anything-goto-source source)
2184 (forward-char -1) ;back to \n
2185 (if (search-forward (concat "\n" selection "\n") nil t)
2186 (forward-line -1)
2187 (goto-char (point-min))
2188 (forward-line 1))
2189 (anything-mark-current-line))))
2191 (defun anything-remove-candidate-cache (source)
2192 (setq anything-candidate-cache
2193 (delete (assoc (assoc-default 'name source) anything-candidate-cache)
2194 anything-candidate-cache)))
2196 (defun anything-insert-match (match insert-function source)
2197 "Insert MATCH into the anything buffer. If MATCH is a list then
2198 insert the string inteneded to appear on the display and store
2199 the real value in a text property."
2200 (let ((start (point-at-bol (point)))
2201 (string (or (car-safe match) match))
2202 (realvalue (cdr-safe match)))
2203 (when (symbolp string) (setq string (symbol-name string)))
2204 (when (stringp string)
2205 (funcall insert-function string)
2206 ;; Some sources with candidates-in-buffer have already added
2207 ;; 'anything-realvalue property when creating candidate buffer.
2208 (unless (get-text-property start 'anything-realvalue)
2209 (and realvalue
2210 (put-text-property start (point-at-eol)
2211 'anything-realvalue realvalue)))
2212 (when anything-source-in-each-line-flag
2213 (put-text-property start (point-at-eol) 'anything-source source))
2214 (funcall insert-function "\n"))))
2216 (defun anything-insert-header-from-source (source)
2217 (let ((name (assoc-default 'name source)))
2218 (anything-insert-header
2219 name
2220 (anything-aif (assoc-default 'header-name source)
2221 (anything-funcall-with-source source it name)))))
2223 (defun anything-insert-header (name &optional display-string)
2224 "Insert header of source NAME into the anything buffer."
2225 (unless (bobp)
2226 (let ((start (point)))
2227 (insert "\n")
2228 (put-text-property start (point) 'anything-header-separator t)))
2230 (let ((start (point)))
2231 (insert name)
2232 (put-text-property (point-at-bol)
2233 (point-at-eol) 'anything-header t)
2234 (when display-string
2235 (overlay-put (make-overlay (point-at-bol) (point-at-eol))
2236 'display display-string))
2237 (insert "\n")
2238 (put-text-property start (point) 'face anything-header-face)))
2241 (defun anything-insert-candidate-separator ()
2242 "Insert separator of candidates into the anything buffer."
2243 (insert anything-candidate-separator)
2244 (put-text-property (point-at-bol)
2245 (point-at-eol) 'anything-candidate-separator t)
2246 (insert "\n"))
2251 ;; (@* "Core: async process")
2252 (defun anything-output-filter (process string)
2253 "Process output from PROCESS."
2254 (anything-output-filter-1 (assoc process anything-async-processes) string))
2256 (defun anything-output-filter-1 (process-assoc string)
2257 (anything-log-eval string)
2258 (with-current-buffer anything-buffer
2259 (let ((source (cdr process-assoc)))
2260 (save-excursion
2261 (anything-aif (assoc-default 'insertion-marker source)
2262 (goto-char it)
2263 (goto-char (point-max))
2264 (anything-insert-header-from-source source)
2265 (setcdr process-assoc
2266 (append source `((insertion-marker . ,(point-marker))))))
2267 (anything-output-filter--process-source
2268 (car process-assoc) string source
2269 (anything-candidate-number-limit source))))
2270 (anything-output-filter--post-process)))
2272 (defun anything-output-filter--process-source (process string source limit)
2273 (dolist (candidate (anything-transform-candidates
2274 (anything-output-filter--collect-candidates
2275 (split-string string "\n")
2276 (assoc 'incomplete-line source))
2277 source t))
2278 (if (not (assq 'multiline source))
2279 (anything-insert-match candidate 'insert-before-markers source)
2280 (let ((start (point)))
2281 (anything-insert-candidate-separator)
2282 (anything-insert-match candidate 'insert-before-markers source)
2283 (put-text-property start (point) 'anything-multiline t)))
2284 (incf (cdr (assoc 'item-count source)))
2285 (when (>= (assoc-default 'item-count source) limit)
2286 (anything-kill-async-process process)
2287 (return))))
2289 (defun anything-output-filter--collect-candidates (lines incomplete-line-info)
2290 (anything-log-eval (cdr incomplete-line-info))
2291 (butlast
2292 (loop for line in lines collect
2293 (if (cdr incomplete-line-info)
2294 (prog1
2295 (concat (cdr incomplete-line-info) line)
2296 (setcdr incomplete-line-info nil))
2297 line)
2298 finally (setcdr incomplete-line-info line))))
2300 (defun anything-output-filter--post-process ()
2301 (anything-maybe-fit-frame)
2302 (anything-log-run-hook 'anything-update-hook)
2303 (anything-aif (get-buffer-window anything-buffer 'visible)
2304 (save-selected-window
2305 (select-window it)
2306 (anything-skip-noncandidate-line 'next)
2307 (anything-mark-current-line))))
2310 (defun anything-kill-async-processes ()
2311 "Kill all known asynchronous processes according to
2312 `anything-async-processes'."
2313 "Kill locate process."
2314 (mapc 'anything-kill-async-process (mapcar 'car anything-async-processes))
2315 (setq anything-async-processes nil))
2318 (defun anything-kill-async-process (process)
2319 "Kill PROCESS and detach the associated functions."
2320 (set-process-filter process nil)
2321 (delete-process process))
2324 ;; (@* "Core: action")
2325 (defun anything-execute-selection-action (&optional selection action preserve-saved-action)
2326 "If a candidate was selected then perform the associated
2327 action."
2328 (anything-log "executing action")
2329 (setq action (anything-get-default-action
2330 (or action
2331 anything-saved-action
2332 (if (get-buffer anything-action-buffer)
2333 (anything-get-selection anything-action-buffer)
2334 (anything-get-action)))))
2335 (let ((source (or anything-saved-current-source (anything-get-current-source))))
2336 (setq selection (or selection
2337 (anything-get-selection)
2338 (and (assoc 'accept-empty source) "")))
2339 (unless preserve-saved-action (setq anything-saved-action nil))
2340 (if (and selection action)
2341 (anything-funcall-with-source
2342 source action
2343 (anything-coerce-selection selection source)))))
2345 (defun anything-coerce-selection (selection source)
2346 "Coerce source with coerce function."
2347 (anything-aif (assoc-default 'coerce source)
2348 (anything-funcall-with-source source it selection)
2349 selection))
2351 (defun anything-get-default-action (action)
2352 (if (and (listp action) (not (functionp action)))
2353 (cdar action)
2354 action))
2356 (defun anything-select-action ()
2357 "Select an action for the currently selected candidate.
2358 If action buffer is selected, back to the anything buffer."
2359 (interactive)
2360 (cond ((get-buffer-window anything-action-buffer 'visible)
2361 (set-window-buffer (get-buffer-window anything-action-buffer)
2362 anything-buffer)
2363 (kill-buffer anything-action-buffer)
2364 (anything-set-pattern anything-input 'noupdate))
2366 (setq anything-saved-selection (anything-get-selection))
2367 (unless anything-saved-selection
2368 (error "Nothing is selected."))
2369 (setq anything-saved-current-source (anything-get-current-source))
2370 (let ((actions (anything-get-action)))
2371 (if (functionp actions)
2372 (message "Sole action: %s" actions)
2373 (anything-show-action-buffer actions)
2374 (anything-delete-minibuffer-contents)
2375 (setq anything-pattern 'dummy) ; so that it differs from the previous one
2376 (anything-check-minibuffer-input))))))
2378 (defun anything-show-action-buffer (actions)
2379 (with-current-buffer (get-buffer-create anything-action-buffer)
2380 (erase-buffer)
2381 (buffer-disable-undo)
2382 (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
2383 (set (make-local-variable 'anything-sources)
2384 `(((name . "Actions")
2385 (volatile)
2386 (candidates . ,actions)
2387 (candidate-number-limit))))
2388 (set (make-local-variable 'anything-source-filter) nil)
2389 (set (make-local-variable 'anything-selection-overlay) nil)
2390 (set (make-local-variable 'anything-digit-overlays) nil)
2391 (anything-initialize-overlays anything-action-buffer)))
2393 ;; (@* "Core: selection")
2394 (defun anything-move-selection-common (move-func unit direction)
2395 "Move the selection marker to a new position determined by
2396 UNIT and DIRECTION."
2397 (unless (or (anything-empty-buffer-p (anything-buffer-get))
2398 (not (anything-window)))
2399 (with-anything-window
2400 (funcall move-func)
2401 (anything-skip-noncandidate-line direction)
2402 (anything-display-source-at-screen-top-maybe unit)
2403 (when (anything-get-previous-header-pos)
2404 (anything-mark-current-line))
2405 (anything-display-mode-line (anything-get-current-source)))))
2407 (defun anything-display-source-at-screen-top-maybe (unit)
2408 (when (and anything-display-source-at-screen-top (eq unit 'source))
2409 (set-window-start (selected-window)
2410 (save-excursion (forward-line -1) (point)))))
2412 (defun anything-skip-noncandidate-line (direction)
2413 (anything-skip-header-and-separator-line direction)
2414 (and (bobp) (forward-line 1)) ;skip first header
2415 (and (eobp) (forward-line -1)) ;avoid last empty line
2418 (defun anything-skip-header-and-separator-line (direction)
2419 (while (and (not (bobp))
2420 (or (anything-pos-header-line-p)
2421 (anything-pos-candidate-separator-p)))
2422 (forward-line (if (and (eq direction 'previous)
2423 (not (eq (point-at-bol) (point-min))))
2425 1))))
2427 (defvar anything-mode-line-string-real nil)
2428 (defun anything-display-mode-line (source)
2429 (set (make-local-variable 'anything-mode-line-string)
2430 (anything-interpret-value (or (assoc-default 'mode-line source)
2431 (default-value 'anything-mode-line-string))
2432 source))
2433 (if anything-mode-line-string
2434 (setq mode-line-format
2435 '(" " mode-line-buffer-identification " "
2436 (line-number-mode "%l") " " (anything-follow-mode "(F)")
2437 " " anything-mode-line-string-real "-%-")
2438 anything-mode-line-string-real
2439 (substitute-command-keys anything-mode-line-string))
2440 (setq mode-line-format
2441 (default-value 'mode-line-format)))
2442 (setq header-line-format
2443 (anything-interpret-value (assoc-default 'header-line source) source)))
2445 (defun anything-previous-line ()
2446 "Move selection to the previous line."
2447 (interactive)
2448 (anything-move-selection-common
2449 (lambda ()
2450 (if (not (anything-pos-multiline-p))
2451 (forward-line -1) ;double forward-line is meaningful
2452 (forward-line -1) ;because evaluation order is important
2453 (anything-skip-header-and-separator-line 'previous)
2454 (let ((header-pos (anything-get-previous-header-pos))
2455 (separator-pos (anything-get-previous-candidate-separator-pos)))
2456 (when header-pos
2457 (goto-char (if (or (null separator-pos) (< separator-pos header-pos))
2458 header-pos ; first candidate
2459 separator-pos))
2460 (forward-line 1)))))
2461 'line 'previous))
2463 (defun anything-next-line ()
2464 "Move selection to the next line."
2465 (interactive)
2466 (anything-move-selection-common
2467 (lambda ()
2468 (if (not (anything-pos-multiline-p))
2469 (forward-line 1)
2470 (let ((header-pos (anything-get-next-header-pos))
2471 (separator-pos (anything-get-next-candidate-separator-pos)))
2472 (cond ((and separator-pos
2473 (or (null header-pos) (< separator-pos header-pos)))
2474 (goto-char separator-pos))
2475 (header-pos
2476 (goto-char header-pos))))))
2477 'line 'next))
2479 (defun anything-previous-page ()
2480 "Move selection back with a pageful."
2481 (interactive)
2482 (anything-move-selection-common
2483 (lambda ()
2484 (condition-case nil
2485 (scroll-down)
2486 (beginning-of-buffer (goto-char (point-min)))))
2487 'page 'previous))
2489 (defun anything-next-page ()
2490 "Move selection forward with a pageful."
2491 (interactive)
2492 (anything-move-selection-common
2493 (lambda ()
2494 (condition-case nil
2495 (scroll-up)
2496 (end-of-buffer (goto-char (point-max)))))
2497 'page 'next))
2499 (defun anything-beginning-of-buffer ()
2500 "Move selection at the top."
2501 (interactive)
2502 (anything-move-selection-common (lambda () (goto-char (point-min)))
2503 'edge 'previous))
2505 (defun anything-end-of-buffer ()
2506 "Move selection at the bottom."
2507 (interactive)
2508 (anything-move-selection-common (lambda () (goto-char (point-max)))
2509 'edge 'next))
2511 (defun anything-previous-source ()
2512 "Move selection to the previous source."
2513 (interactive)
2514 (anything-move-selection-common
2515 (lambda ()
2516 (forward-line -1)
2517 (if (bobp)
2518 (goto-char (point-max))
2519 (anything-skip-header-and-separator-line 'previous))
2520 (goto-char (anything-get-previous-header-pos))
2521 (forward-line 1))
2522 'source 'previous))
2524 (defun anything-next-source ()
2525 "Move selection to the next source."
2526 (interactive)
2527 (anything-move-selection-common
2528 (lambda () (goto-char (or (anything-get-next-header-pos) (point-min))))
2529 'source 'next))
2531 (defun anything-goto-source (source-or-name)
2532 "Move the selection to the source (SOURCE-OR-NAME)."
2533 (anything-move-selection-common
2534 (lambda ()
2535 (goto-char (point-min))
2536 (let ((name (if (stringp source-or-name) source-or-name
2537 (assoc-default 'name source-or-name))))
2538 (condition-case err
2539 (while (not (string= name (anything-current-line-contents)))
2540 (goto-char (anything-get-next-header-pos)))
2541 (error (message "")))))
2542 'source 'next))
2544 (defun anything-mark-current-line ()
2545 "Move selection overlay to current line."
2546 (move-overlay
2547 anything-selection-overlay (point-at-bol)
2548 (if (anything-pos-multiline-p)
2549 (let ((header-pos (anything-get-next-header-pos))
2550 (separator-pos (anything-get-next-candidate-separator-pos)))
2551 (or (and (null header-pos) separator-pos)
2552 (and header-pos separator-pos (< separator-pos header-pos)
2553 separator-pos)
2554 header-pos
2555 (point-max)))
2556 (1+ (point-at-eol))))
2557 (anything-follow-execute-persistent-action-maybe))
2559 (defun anything-this-command-key ()
2560 (event-basic-type (elt (this-command-keys-vector) 0)))
2561 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
2563 (defun anything-select-with-shortcut-internal (types get-key-func)
2564 (if (memq anything-enable-shortcuts types)
2565 (save-selected-window
2566 (select-window (anything-window))
2567 (let* ((key (funcall get-key-func))
2568 (overlay (ignore-errors (nth (position key anything-shortcut-keys)
2569 anything-digit-overlays))))
2570 (if (not (and overlay (overlay-buffer overlay)))
2571 (when (numberp key)
2572 (select-window (minibuffer-window))
2573 (self-insert-command 1))
2574 (goto-char (overlay-start overlay))
2575 (anything-mark-current-line)
2576 (anything-exit-minibuffer))))
2577 (self-insert-command 1)))
2579 (defun anything-select-with-prefix-shortcut ()
2580 "Invoke default action with prefix shortcut."
2581 (interactive)
2582 (anything-select-with-shortcut-internal
2583 '(prefix)
2584 (lambda () (read-event "Select shortcut key: "))))
2586 (defun anything-select-with-digit-shortcut ()
2587 "Invoke default action with digit/alphabet shortcut."
2588 (interactive)
2589 (anything-select-with-shortcut-internal
2590 '(alphabet t) 'anything-this-command-key))
2592 ;; (setq anything-enable-shortcuts 'prefix)
2593 ;; (define-key anything-map "@" 'anything-select-with-prefix-shortcut)
2594 ;; (define-key anything-map (kbd "<f18>") 'anything-select-with-prefix-shortcut)
2596 (defun anything-exit-minibuffer ()
2597 "Select the current candidate by exiting the minibuffer."
2598 (interactive)
2599 (declare (special anything-iswitchb-candidate-selected))
2600 (setq anything-iswitchb-candidate-selected (anything-get-selection))
2601 (exit-minibuffer))
2603 (defun anything-keyboard-quit ()
2604 "Quit minibuffer in anything.
2606 If action buffer is displayed, kill it."
2607 (interactive)
2608 (when (get-buffer-window anything-action-buffer 'visible)
2609 (kill-buffer anything-action-buffer))
2610 (abort-recursive-edit))
2612 (defun anything-get-next-header-pos ()
2613 "Return the position of the next header from point."
2614 (next-single-property-change (point) 'anything-header))
2617 (defun anything-get-previous-header-pos ()
2618 "Return the position of the previous header from point"
2619 (previous-single-property-change (point) 'anything-header))
2622 (defun anything-pos-multiline-p ()
2623 "Return non-nil if the current position is in the multiline source region."
2624 (get-text-property (point) 'anything-multiline))
2627 (defun anything-get-next-candidate-separator-pos ()
2628 "Return the position of the next candidate separator from point."
2629 (next-single-property-change (point) 'anything-candidate-separator))
2632 (defun anything-get-previous-candidate-separator-pos ()
2633 "Return the position of the previous candidate separator from point."
2634 (previous-single-property-change (point) 'anything-candidate-separator))
2637 (defun anything-pos-header-line-p ()
2638 "Return t if the current line is a header line."
2639 (or (get-text-property (point-at-bol) 'anything-header)
2640 (get-text-property (point-at-bol) 'anything-header-separator)))
2642 (defun anything-pos-candidate-separator-p ()
2643 "Return t if the current line is a candidate separator."
2644 (get-text-property (point-at-bol) 'anything-candidate-separator))
2646 ;; (@* "Core: help")
2647 (defun anything-help-internal (bufname insert-content-fn)
2648 "Show long message during `anything' session."
2649 (save-window-excursion
2650 (select-window (anything-window))
2651 (delete-other-windows)
2652 (switch-to-buffer (get-buffer-create bufname))
2653 (erase-buffer)
2654 (funcall insert-content-fn)
2655 (setq mode-line-format "%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
2656 (setq cursor-type nil)
2657 (goto-char 1)
2658 (anything-help-event-loop)))
2660 (defun anything-help-event-loop ()
2661 (ignore-errors
2662 (loop for event = (read-event) do
2663 (case event
2664 ((?\C-v ? ) (scroll-up))
2665 ((?\M-v ?b) (scroll-down))
2666 (t (return))))))
2668 (defun anything-help ()
2669 "Help of `anything'."
2670 (interactive)
2671 (anything-help-internal
2672 " *Anything Help*"
2673 (lambda ()
2674 (insert (substitute-command-keys
2675 (anything-interpret-value anything-help-message)))
2676 (org-mode))))
2678 (defun anything-debug-output ()
2679 "Show all anything-related variables at this time."
2680 (interactive)
2681 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function))
2683 (defun anything-debug-output-function (&optional vars)
2684 (message "Calculating all anything-related values...")
2685 (insert "If you debug some variables or forms, set `anything-debug-forms'
2686 to a list of forms.\n\n")
2687 (dolist (v (or vars
2688 anything-debug-forms
2689 (apropos-internal "^anything-" 'boundp)))
2690 (insert "** "
2691 (pp-to-string v) "\n"
2692 (pp-to-string (eval v)) "\n"))
2693 (message "Calculating all anything-related values...Done"))
2695 ;; (@* "Core: misc")
2696 (defun anything-kill-buffer-hook ()
2697 "Remove tick entry from `anything-tick-hash' when killing a buffer."
2698 (loop for key being the hash-keys in anything-tick-hash
2699 if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
2700 do (remhash key anything-tick-hash)))
2701 (add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
2703 (defun anything-maybe-fit-frame ()
2704 "Fit anything frame to its buffer, and put it at top right of display.
2706 It is disabled by default because some flickering occurred in some environment.
2707 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
2708 `fit-frame-inhibit-fitting' to nil.
2709 You can set user options `fit-frame-max-width-percent' and
2710 `fit-frame-max-height-percent' to control max frame size."
2711 (declare (warn (unresolved 0)))
2712 (when (and (not anything-inhibit-fit-frame-flag)
2713 (anything-window)
2714 (require 'fit-frame nil t)
2715 (boundp 'fit-frame-inhibit-fitting-flag)
2716 (not fit-frame-inhibit-fitting-flag))
2717 (ignore-errors
2718 (with-anything-window
2719 (fit-frame nil nil nil t)
2720 (modify-frame-parameters
2721 (selected-frame)
2722 `((left . ,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
2723 (top . 0))))))) ; The (top . 0) shouldn't be necessary (Emacs bug).
2725 (defun anything-preselect (candidate-or-regexp)
2726 (with-anything-window
2727 (when candidate-or-regexp
2728 (goto-char (point-min))
2729 ;; go to first candidate of first source
2730 (forward-line 1)
2731 (let ((start (point)))
2732 (unless (or (re-search-forward
2733 (concat "^" (regexp-quote candidate-or-regexp) "$")
2734 nil t)
2735 (progn (goto-char start)
2736 (re-search-forward candidate-or-regexp nil t)))
2737 (goto-char start))))
2738 (anything-mark-current-line)))
2740 (defun anything-delete-current-selection ()
2741 "Delete the currently selected item."
2742 (interactive)
2743 (with-anything-window
2744 (cond ((anything-pos-multiline-p)
2745 (anything-aif (anything-get-next-candidate-separator-pos)
2746 (delete-region (point-at-bol)
2747 (1+ (progn (goto-char it) (point-at-eol))))
2748 ;; last candidate
2749 (goto-char (anything-get-previous-candidate-separator-pos))
2750 (delete-region (point-at-bol) (point-max)))
2751 (when (eobp)
2752 (goto-char (or (anything-get-previous-candidate-separator-pos)
2753 (point-min)))
2754 (forward-line 1)))
2756 (delete-region (point-at-bol) (1+ (point-at-eol)))
2757 (when (eobp) (forward-line -1))))
2758 (anything-mark-current-line)))
2760 (defun anything-edit-current-selection-internal (func)
2761 (with-anything-window
2762 (beginning-of-line)
2763 (let ((realvalue (get-text-property (point) 'anything-realvalue)))
2764 (funcall func)
2765 (beginning-of-line)
2766 (and realvalue
2767 (put-text-property (point) (point-at-eol)
2768 'anything-realvalue realvalue))
2769 (anything-mark-current-line))))
2771 (defmacro anything-edit-current-selection (&rest forms)
2772 "Evaluate FORMS at current selection in the anything buffer.
2773 You can edit the line."
2774 `(anything-edit-current-selection-internal
2775 (lambda () ,@forms)))
2776 (put 'anything-edit-current-selection 'lisp-indent-function 0)
2778 (defun anything-set-pattern (pattern &optional noupdate)
2779 "Set minibuffer contents to PATTERN.
2780 if optional NOUPDATE is non-nil, anything buffer is not changed."
2781 (with-selected-window (minibuffer-window)
2782 (delete-minibuffer-contents)
2783 (insert pattern))
2784 (when noupdate
2785 (setq anything-pattern pattern)
2786 (anything-hooks 'cleanup)
2787 (run-with-idle-timer 0 nil 'anything-hooks 'setup)))
2789 (defun anything-delete-minibuffer-contents ()
2790 "Same as `delete-minibuffer-contents' but this is a command."
2791 (interactive)
2792 (anything-set-pattern ""))
2793 (defalias 'anything-delete-minibuffer-content 'anything-delete-minibuffer-contents)
2795 ;; (@* "Built-in plug-in: type")
2796 (defun anything-compile-source--type (source)
2797 (anything-aif (assoc-default 'type source)
2798 (append source (assoc-default it anything-type-attributes) nil)
2799 source))
2801 ;; `define-anything-type-attribute' is public API.
2803 (defun anything-add-type-attribute (type definition)
2804 (anything-aif (assq type anything-type-attributes)
2805 (setq anything-type-attributes (delete it anything-type-attributes)))
2806 (push (cons type definition) anything-type-attributes))
2808 (defvar anything-types nil)
2809 (defun anything-document-type-attribute (type doc)
2810 (add-to-list 'anything-types type t)
2811 (put type 'anything-typeattrdoc
2812 (concat "- " (symbol-name type) "\n\n" doc "\n")))
2814 (defadvice documentation-property (after anything-document-type-attribute activate)
2815 "Hack to display type attributes' documentation as `anything-type-attributes' docstring."
2816 (when (eq symbol 'anything-type-attributes)
2817 (setq ad-return-value
2818 (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
2819 (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
2820 anything-types "\n")))))
2822 ;; (@* "Built-in plug-in: dummy")
2823 (defun anything-dummy-candidate (candidate source)
2824 ;; `source' is defined in filtered-candidate-transformer
2825 (list anything-pattern))
2827 (defun anything-compile-source--dummy (source)
2828 (if (assoc 'dummy source)
2829 (append source
2830 '((candidates "dummy")
2831 (accept-empty)
2832 (match identity)
2833 (filtered-candidate-transformer . anything-dummy-candidate)
2834 (disable-shortcuts)
2835 (volatile)))
2836 source))
2838 ;; (@* "Built-in plug-in: disable-shortcuts")
2839 (defvar anything-orig-enable-shortcuts nil)
2840 (defun anything-save-enable-shortcuts ()
2841 (anything-once
2842 (lambda () (setq anything-orig-enable-shortcuts anything-enable-shortcuts
2843 anything-enable-shortcuts nil))))
2844 (defun anything-compile-source--disable-shortcuts (source)
2845 (if (assoc 'disable-shortcuts source)
2846 (append `((init ,@(anything-mklist (assoc-default 'init source))
2847 anything-save-enable-shortcuts)
2848 (resume ,@(anything-mklist (assoc-default 'resume source))
2849 anything-save-enable-shortcuts)
2850 (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
2851 (lambda () (setq anything-enable-shortcuts
2852 anything-orig-enable-shortcuts))))
2853 source)
2854 source))
2856 ;; (@* "Built-in plug-in: candidates-in-buffer")
2857 (defun anything-candidates-in-buffer ()
2858 "Get candidates from the candidates buffer according to `anything-pattern'.
2860 BUFFER is `anything-candidate-buffer' by default. Each
2861 candidate must be placed in one line. This function is meant to
2862 be used in candidates-in-buffer or candidates attribute of an
2863 anything source. Especially fast for many (1000+) candidates.
2866 '((name . \"many files\")
2867 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
2868 (insert-many-filenames))))
2869 (search re-search-forward) ; optional
2870 (candidates-in-buffer)
2871 (type . file))
2873 +===============================================================+
2874 | The new way of making and narrowing candidates: Using buffers |
2875 +===============================================================+
2877 By default, `anything' makes candidates by evaluating the
2878 candidates function, then narrows them by `string-match' for each
2879 candidate.
2881 But this way is very slow for many candidates. The new way is
2882 storing all candidates in a buffer and narrowing them by
2883 `re-search-forward'. Search function is customizable by search
2884 attribute. The important point is that buffer processing is MUCH
2885 FASTER than string list processing and is the Emacs way.
2887 The init function writes all candidates to a newly-created
2888 candidate buffer. The candidates buffer is created or specified
2889 by `anything-candidate-buffer'. Candidates are stored in a line.
2891 The candidates function narrows all candidates, IOW creates a
2892 subset of candidates dynamically. It is the task of
2893 `anything-candidates-in-buffer'. As long as
2894 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
2895 sufficient in most cases.
2897 Note that `(candidates-in-buffer)' is shortcut of three attributes:
2898 (candidates . anything-candidates-in-buffer)
2899 (volatile)
2900 (match identity)
2901 And `(candidates-in-buffer . func)' is shortcut of three attributes:
2902 (candidates . func)
2903 (volatile)
2904 (match identity)
2905 The expansion is performed in `anything-get-sources'.
2907 The candidates-in-buffer attribute implies the volatile attribute.
2908 The volatile attribute is needed because `anything-candidates-in-buffer'
2909 creates candidates dynamically and need to be called everytime
2910 `anything-pattern' changes.
2912 Because `anything-candidates-in-buffer' plays the role of `match' attribute
2913 function, specifying `(match identity)' makes the source slightly faster.
2915 To customize `anything-candidates-in-buffer' behavior, use search,
2916 get-line and search-from-end attributes. See also `anything-sources' docstring.
2918 (declare (special source))
2919 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
2920 anything-pattern
2921 (or (assoc-default 'get-line source)
2922 #'buffer-substring-no-properties)
2923 ;; use external variable `source'.
2924 (or (assoc-default 'search source)
2925 (if (assoc 'search-from-end source)
2926 '(re-search-backward)
2927 '(re-search-forward)))
2928 (anything-candidate-number-limit source)
2929 (assoc 'search-from-end source)))
2931 (defun anything-candidates-in-buffer-1 (buffer pattern get-line-fn search-fns limit search-from-end)
2932 ;; buffer == nil when candidates buffer does not exist.
2933 (when buffer
2934 (with-current-buffer buffer
2935 (let ((start-point (if search-from-end (point-max) (point-min)))
2936 (endp (if search-from-end #'bobp #'eobp)))
2937 (goto-char (1- start-point))
2938 (if (string= pattern "")
2939 (anything-initial-candidates-from-candidate-buffer
2940 endp get-line-fn limit search-from-end)
2941 (anything-search-from-candidate-buffer
2942 pattern get-line-fn search-fns limit search-from-end
2943 start-point endp))))))
2945 (defun anything-point-is-moved (proc)
2946 "If point is moved after executing PROC, return t, otherwise nil."
2947 (/= (point) (progn (funcall proc) (point))))
2949 (defun anything-search-from-candidate-buffer (pattern get-line-fn search-fns
2950 limit search-from-end
2951 start-point endp)
2952 (let (buffer-read-only
2953 matches exit newmatches)
2954 (anything-search-from-candidate-buffer-internal
2955 (lambda ()
2956 (clrhash anything-cib-hash)
2957 (dolist (searcher search-fns)
2958 (goto-char start-point)
2959 (setq newmatches nil)
2960 (loop with item-count = 0
2961 while (funcall searcher pattern nil t)
2962 for cand = (funcall get-line-fn (point-at-bol) (point-at-eol))
2963 do (anything-accumulate-candidates-internal
2964 cand newmatches anything-cib-hash item-count limit)
2965 unless (anything-point-is-moved
2966 (lambda ()
2967 (if search-from-end
2968 (goto-char (1- (point-at-bol)))
2969 (forward-line 1))))
2970 return nil)
2971 (setq matches (append matches (nreverse newmatches)))
2972 (if exit (return)))
2973 (delq nil matches)))))
2975 (defun anything-initial-candidates-from-candidate-buffer (endp get-line-fn limit search-from-end)
2976 (delq nil (loop with next-line-fn =
2977 (if search-from-end
2978 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
2979 #'forward-line)
2980 until (funcall endp)
2981 for i from 1 to limit
2982 collect (funcall get-line-fn (point-at-bol) (point-at-eol))
2983 do (funcall next-line-fn 1))))
2985 (defun anything-search-from-candidate-buffer-internal (search-fn)
2986 (goto-char (point-min))
2987 (insert "\n")
2988 (goto-char (point-max))
2989 (insert "\n")
2990 (unwind-protect
2991 (funcall search-fn)
2992 (goto-char (point-min))
2993 (delete-char 1)
2994 (goto-char (1- (point-max)))
2995 (delete-char 1)
2997 (set-buffer-modified-p nil)))
2999 (defun anything-candidate-buffer (&optional create-or-buffer)
3000 "Register and return a buffer containing candidates of current source.
3001 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3002 then global candidates buffer.
3004 Acceptable values of CREATE-OR-BUFFER:
3006 - nil (omit)
3007 Only return the candidates buffer.
3008 - a buffer
3009 Register a buffer as a candidates buffer.
3010 - 'global
3011 Create a new global candidates buffer,
3012 named \" *anything candidates:SOURCE*\".
3013 - other non-nil value
3014 Create a new local candidates buffer,
3015 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
3017 (let* ((global-bname (format " *anything candidates:%s*" anything-source-name))
3018 (local-bname (format " *anything candidates:%s*%s"
3019 anything-source-name
3020 (buffer-name anything-current-buffer)))
3021 (register-func
3022 (lambda ()
3023 (setq anything-candidate-buffer-alist
3024 (cons (cons anything-source-name create-or-buffer)
3025 (delete (assoc anything-source-name
3026 anything-candidate-buffer-alist)
3027 anything-candidate-buffer-alist)))))
3028 (kill-buffers-func
3029 (lambda ()
3030 (loop for b in (buffer-list)
3031 if (string-match (format "^%s" (regexp-quote global-bname))
3032 (buffer-name b))
3033 do (kill-buffer b))))
3034 (create-func
3035 (lambda ()
3036 (with-current-buffer
3037 (get-buffer-create (if (eq create-or-buffer 'global)
3038 global-bname
3039 local-bname))
3040 (buffer-disable-undo)
3041 (erase-buffer)
3042 (font-lock-mode -1))))
3043 (return-func
3044 (lambda ()
3045 (or (get-buffer local-bname)
3046 (get-buffer global-bname)
3047 (anything-aif (assoc-default anything-source-name
3048 anything-candidate-buffer-alist)
3049 (and (buffer-live-p it) it))))))
3050 (when create-or-buffer
3051 (funcall register-func)
3052 (unless (bufferp create-or-buffer)
3053 (and (eq create-or-buffer 'global) (funcall kill-buffers-func))
3054 (funcall create-func)))
3055 (funcall return-func)))
3057 (defun anything-compile-source--candidates-in-buffer (source)
3058 (anything-aif (assoc 'candidates-in-buffer source)
3059 (append source
3060 `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
3061 (volatile) (match identity)))
3062 source))
3064 ;; (@* "Utility: resplit anything window")
3065 (defun anything-toggle-resplit-window ()
3066 "Toggle resplit anything window, vertically or horizontally."
3067 (interactive)
3068 (with-anything-window
3069 (let ((before-height (window-height)))
3070 (delete-window)
3071 (set-window-buffer
3072 (select-window (if (= (window-height) before-height)
3073 (split-window-vertically)
3074 (split-window-horizontally)))
3075 anything-buffer))))
3077 ;; (@* "Utility: select another action by key")
3078 (defun anything-select-nth-action (n)
3079 "Select the nth action for the currently selected candidate."
3080 (setq anything-saved-selection (anything-get-selection))
3081 (unless anything-saved-selection
3082 (error "Nothing is selected."))
3083 (setq anything-saved-action (anything-get-nth-action n (anything-get-action)))
3084 (anything-exit-minibuffer))
3086 (defun anything-get-nth-action (n action)
3087 (cond ((and (zerop n) (functionp action))
3088 action)
3089 ((listp action)
3090 (or (cdr (elt action n))
3091 (error "No such action")))
3092 ((and (functionp action) (< 0 n))
3093 (error "Sole action."))
3095 (error "Error in `anything-select-nth-action'."))))
3097 (defun anything-select-2nd-action ()
3098 "Select the 2nd action for the currently selected candidate."
3099 (interactive)
3100 (anything-select-nth-action 1))
3102 (defun anything-select-3rd-action ()
3103 "Select the 3rd action for the currently selected candidate."
3104 (interactive)
3105 (anything-select-nth-action 2))
3107 (defun anything-select-4th-action ()
3108 "Select the 4th action for the currently selected candidate."
3109 (interactive)
3110 (anything-select-nth-action 3))
3112 (defun anything-select-2nd-action-or-end-of-line ()
3113 "Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
3114 Otherwise goto the end of minibuffer."
3115 (interactive)
3116 (if (eolp)
3117 (anything-select-nth-action 1)
3118 (end-of-line)))
3120 ;; (@* "Utility: Persistent Action")
3121 (defmacro with-anything-display-same-window (&rest body)
3122 "Make `pop-to-buffer' and `display-buffer' display in the same window."
3123 `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
3124 ,@body))
3125 (put 'with-anything-display-same-window 'lisp-indent-function 0)
3127 (defvar anything-persistent-action-display-window nil)
3128 (defun anything-initialize-persistent-action ()
3129 (set (make-local-variable 'anything-persistent-action-display-window) nil))
3131 (defun* anything-execute-persistent-action (&optional (attr 'persistent-action))
3132 "If a candidate is selected then perform the associated action without quitting anything."
3133 (interactive)
3134 (anything-log "executing persistent-action")
3135 (save-selected-window
3136 (anything-select-persistent-action-window)
3137 (anything-log-eval (current-buffer))
3138 (let ((anything-in-persistent-action t))
3139 (with-anything-display-same-window
3140 (anything-execute-selection-action
3142 (or (assoc-default attr (anything-get-current-source))
3143 (anything-get-action))
3145 (anything-log-run-hook 'anything-after-persistent-action-hook)))))
3147 (defun anything-persistent-action-display-window ()
3148 (with-current-buffer anything-buffer
3149 (setq anything-persistent-action-display-window
3150 (cond ((window-live-p anything-persistent-action-display-window)
3151 anything-persistent-action-display-window)
3152 ((and anything-samewindow (one-window-p t))
3153 (split-window))
3154 ((get-buffer-window anything-current-buffer))
3156 (next-window (selected-window) 1))))))
3158 (defun anything-select-persistent-action-window ()
3159 (select-window (get-buffer-window (anything-buffer-get)))
3160 (select-window
3161 (setq minibuffer-scroll-window (anything-persistent-action-display-window))))
3163 (defun anything-persistent-action-display-buffer (buf &optional not-this-window)
3164 "Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
3165 If `anything-persistent-action-use-special-display' is non-nil and
3166 BUF is to be displayed by `special-display-function', use it.
3167 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
3168 (let* ((name (buffer-name buf))
3169 display-buffer-function pop-up-windows
3170 (same-window-regexps
3171 (unless (and anything-persistent-action-use-special-display
3172 (or (member name
3173 (mapcar (lambda (x) (or (car-safe x) x))
3174 special-display-buffer-names))
3175 (remove-if-not
3176 (lambda (x) (string-match (or (car-safe x) x) name))
3177 special-display-regexps)))
3178 '("."))))
3179 (display-buffer buf not-this-window)))
3181 ;; scroll-other-window(-down)? for persistent-action
3182 (defun anything-scroll-other-window-base (command)
3183 (with-selected-window (anything-persistent-action-display-window)
3184 (funcall command anything-scroll-amount)))
3186 (defun anything-scroll-other-window ()
3187 "Scroll other window (not *Anything* window) upward."
3188 (interactive)
3189 (anything-scroll-other-window-base 'scroll-up))
3190 (defun anything-scroll-other-window-down ()
3191 "Scroll other window (not *Anything* window) downward."
3192 (interactive)
3193 (anything-scroll-other-window-base 'scroll-down))
3195 ;; (@* "Utility: Visible Mark")
3196 (defface anything-visible-mark
3197 '((((min-colors 88) (background dark))
3198 (:background "green1" :foreground "black"))
3199 (((background dark)) (:background "green" :foreground "black"))
3200 (((min-colors 88)) (:background "green1"))
3201 (t (:background "green")))
3202 "Face for visible mark."
3203 :group 'anything)
3204 (defvar anything-visible-mark-face 'anything-visible-mark)
3205 (defvar anything-visible-mark-overlays nil)
3207 (defun anything-clear-visible-mark ()
3208 (with-current-buffer (anything-buffer-get)
3209 (mapc 'delete-overlay anything-visible-mark-overlays)
3210 (set (make-local-variable 'anything-visible-mark-overlays) nil)))
3211 (add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
3213 (defvar anything-c-marked-candidate-list nil
3214 "[OBSOLETE] DO NOT USE!!")
3215 (defvar anything-marked-candidates nil
3216 "Marked candadates. List of (source . real) pair.")
3218 (defun anything-this-visible-mark ()
3219 (loop for o in anything-visible-mark-overlays
3220 when (equal (point-at-bol) (overlay-start o))
3221 do (return o)))
3223 (defun anything-delete-visible-mark (overlay)
3224 (setq anything-c-marked-candidate-list
3225 (remove (anything-current-line-contents) anything-c-marked-candidate-list))
3226 (setq anything-marked-candidates
3227 (remove
3228 (cons (anything-get-current-source) (anything-get-selection))
3229 anything-marked-candidates))
3230 (delete-overlay overlay)
3231 (setq anything-visible-mark-overlays
3232 (delq overlay anything-visible-mark-overlays)))
3234 (defun anything-make-visible-mark ()
3235 (let ((o (make-overlay (point-at-bol) (1+ (point-at-eol)))))
3236 (overlay-put o 'face anything-visible-mark-face)
3237 (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3238 (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3239 (add-to-list 'anything-visible-mark-overlays o))
3240 (push (anything-current-line-contents) anything-c-marked-candidate-list)
3241 (push (cons (anything-get-current-source) (anything-get-selection))
3242 anything-marked-candidates))
3244 (defun anything-toggle-visible-mark ()
3245 "Toggle anything visible mark at point."
3246 (interactive)
3247 (with-anything-window
3248 (anything-aif (anything-this-visible-mark)
3249 (anything-delete-visible-mark it)
3250 (anything-make-visible-mark))
3251 (anything-next-line)))
3253 (defun anything-display-all-visible-marks ()
3254 "Show all `anything' visible marks strings."
3255 (interactive)
3256 (with-anything-window
3257 (lexical-let ((overlays (reverse anything-visible-mark-overlays)))
3258 (anything-run-after-quit
3259 (lambda ()
3260 (with-output-to-temp-buffer "*anything visible marks*"
3261 (dolist (o overlays) (princ (overlay-get o 'string)))))))))
3263 (defun anything-marked-candidates ()
3264 "Marked candidates (real value) of current source if any,
3265 otherwise 1-element list of current selection.
3267 It is analogous to `dired-get-marked-files'."
3268 (with-current-buffer (anything-buffer-get)
3269 (let ((cands
3270 (if anything-marked-candidates
3271 (loop with current-src = (anything-get-current-source)
3272 for (source . real) in (reverse anything-marked-candidates)
3273 when (equal current-src source)
3274 collect (anything-coerce-selection real source))
3275 (list (anything-get-selection)))))
3276 (anything-log-eval cands)
3277 cands)))
3279 (defun anything-reset-marked-candidates ()
3280 (with-current-buffer (anything-buffer-get)
3281 (set (make-local-variable 'anything-c-marked-candidate-list) nil)
3282 (set (make-local-variable 'anything-marked-candidates) nil)))
3284 (add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
3285 ;; (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3287 (defun anything-current-source-name= (name)
3288 (save-excursion
3289 (goto-char (anything-get-previous-header-pos))
3290 (equal name (anything-current-line-contents))))
3292 (defun anything-revive-visible-mark ()
3293 (with-current-buffer anything-buffer
3294 (dolist (o anything-visible-mark-overlays)
3295 (goto-char (point-min))
3296 (while (and (search-forward (overlay-get o 'string) nil t)
3297 (anything-current-source-name= (overlay-get o 'source)))
3298 ;; Now the next line of visible mark
3299 (move-overlay o (point-at-bol 0) (1+ (point-at-eol 0)))))))
3300 (add-hook 'anything-update-hook 'anything-revive-visible-mark)
3302 (defun anything-next-point-in-list (curpos points &optional prev)
3303 (cond
3304 ;; rule out special cases
3305 ((null points) curpos)
3306 ((and prev (< curpos (car points))) curpos)
3307 ((< (car (last points)) curpos)
3308 (if prev (car (last points)) curpos))
3310 (nth (if prev
3311 (loop for pt in points
3312 for i from 0
3313 if (<= curpos pt)
3314 do (return (1- i)))
3315 (loop for pt in points
3316 for i from 0
3317 if (< curpos pt)
3318 do (return i)))
3319 points))))
3321 (defun anything-next-visible-mark (&optional prev)
3322 "Move next anything visible mark."
3323 (interactive)
3324 (with-anything-window
3325 (goto-char (anything-next-point-in-list
3326 (point)
3327 (sort (mapcar 'overlay-start anything-visible-mark-overlays) '<)
3328 prev))
3329 (anything-mark-current-line)))
3331 (defun anything-prev-visible-mark ()
3332 "Move previous anything visible mark."
3333 (interactive)
3334 (anything-next-visible-mark t))
3336 ;; (@* "Utility: `find-file' integration")
3337 (defun anything-quit-and-find-file ()
3338 "Drop into `find-file' from `anything' like `iswitchb-find-file'.
3339 If current selection is a buffer or a file, `find-file' from its directory."
3340 (interactive)
3341 (anything-run-after-quit
3342 (lambda (f)
3343 (if (file-exists-p f)
3344 (let ((default-directory (file-name-directory f)))
3345 (call-interactively 'find-file))
3346 (call-interactively 'find-file)))
3347 (anything-aif (get-buffer (anything-get-selection))
3348 (buffer-file-name it)
3349 (expand-file-name (anything-get-selection)))))
3351 ;; (@* "Utility: Selection Paste")
3352 (defun anything-yank-selection ()
3353 "Set minibuffer contents to current selection."
3354 (interactive)
3355 (anything-set-pattern (anything-get-selection nil t)))
3357 (defun anything-kill-selection-and-quit ()
3358 "Store current selection to kill ring.
3359 You can paste it by typing C-y."
3360 (interactive)
3361 (anything-run-after-quit
3362 (lambda (sel)
3363 (kill-new sel)
3364 (message "Killed: %s" sel))
3365 (anything-get-selection nil t)))
3368 ;; (@* "Utility: Automatical execution of persistent-action")
3369 (add-to-list 'minor-mode-alist '(anything-follow-mode " AFollow"))
3370 (defun anything-follow-mode ()
3371 "If this mode is on, persistent action is executed everytime the cursor is moved."
3372 (interactive)
3373 (with-current-buffer anything-buffer
3374 (setq anything-follow-mode (not anything-follow-mode))
3375 (message "anything-follow-mode is %s"
3376 (if anything-follow-mode "enabled" "disabled"))))
3378 (defun anything-follow-execute-persistent-action-maybe ()
3379 "Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
3380 (and (not (get-buffer-window anything-action-buffer 'visible))
3381 (buffer-local-value 'anything-follow-mode
3382 (get-buffer-create anything-buffer))
3383 (sit-for anything-input-idle-delay)
3384 (anything-window)
3385 (anything-get-selection)
3386 (save-excursion
3387 (anything-execute-persistent-action))))
3389 ;; (@* "Utility: Migrate `anything-sources' to my-anything command")
3390 (defun anything-migrate-sources ()
3391 "Help to migrate to new `anything' way."
3392 (interactive)
3393 (with-current-buffer (get-buffer-create "*anything migrate*")
3394 (erase-buffer)
3395 (insert (format "\
3396 Setting `anything-sources' directly is not good because
3397 `anything' is not for one command. For now, interactive use of
3398 `anything' (M-x anything) is only for demonstration purpose.
3399 So you should define commands calling `anything'.
3400 I help you to migrate to the new way.
3402 The code below is automatically generated from current
3403 `anything-sources' value. You can use the `my-anything' command
3404 now!
3406 Copy and paste it to your .emacs. Then substitute `my-anything'
3407 for `anything' bindings in all `define-key', `local-set-key' and
3408 `global-set-key' calls.
3410 \(defun my-anything ()
3411 \"Anything command for you.
3413 It is automatically generated by `anything-migrate-sources'.\"
3414 (interactive)
3415 (anything-other-buffer
3417 \"*my-anything*\"))
3418 " anything-sources))
3419 (eval-last-sexp nil)
3420 (substitute-key-definition 'anything 'my-anything global-map)
3421 (pop-to-buffer (current-buffer))))
3423 ;; (@* "Utility: Incremental search within results (unmaintained)")
3425 (defvar anything-isearch-original-global-map nil
3426 "Original global map before Anything isearch is started.")
3428 (defvar anything-isearch-original-message-timeout nil
3429 "Original message timeout before Anything isearch is started.")
3431 (defvar anything-isearch-pattern nil
3432 "The current isearch pattern.")
3434 (defvar anything-isearch-message-suffix ""
3435 "Message suffix indicating the current state of the search.")
3437 (defvar anything-isearch-original-point nil
3438 "Original position of point before isearch is started.")
3440 (defvar anything-isearch-original-window nil
3441 "Original selected window before isearch is started.")
3443 (defvar anything-isearch-original-cursor-in-non-selected-windows nil
3444 "Original value of cursor-in-non-selected-windows before isearch is started.")
3446 (defvar anything-isearch-original-deferred-action-list nil
3447 "Original value of deferred-action-list before isearch is started.")
3449 (defvar anything-isearch-match-positions nil
3450 "Stack of positions of matches or non-matches.
3452 It's a list of plists with two properties: `event', the last user
3453 event, `start', the start position of the current match, and
3454 `pos', the position of point after that event.
3456 The value of `event' can be the following symbols: `char' if a
3457 character was typed, `error' if a non-matching character was
3458 typed, `search' if a forward search had to be done after a
3459 character, and `search-again' if a search was done for the next
3460 occurrence of the current pattern.")
3462 (defvar anything-isearch-match-start nil
3463 "Start position of the current match.")
3466 (defun anything-isearch ()
3467 "Start incremental search within results. (UNMAINTAINED)"
3468 (interactive)
3469 (if (anything-empty-buffer-p (anything-buffer-get))
3470 (message "There are no results.")
3472 (setq anything-isearch-original-message-timeout minibuffer-message-timeout)
3473 (setq minibuffer-message-timeout nil)
3475 (setq anything-isearch-original-global-map global-map)
3477 (condition-case nil
3478 (progn
3479 (setq anything-isearch-original-window (selected-window))
3480 (select-window (anything-window))
3481 (setq cursor-type t)
3483 (setq anything-isearch-original-deferred-action-list
3484 (default-value 'deferred-action-list))
3485 (setq-default deferred-action-list nil)
3486 (add-hook 'deferred-action-list 'anything-isearch-post-command)
3488 (use-global-map anything-isearch-map)
3489 (setq overriding-terminal-local-map anything-isearch-map)
3491 (setq anything-isearch-pattern "")
3493 (setq anything-isearch-original-cursor-in-non-selected-windows
3494 cursor-in-non-selected-windows)
3495 (setq cursor-in-non-selected-windows nil)
3497 (setq anything-isearch-original-point (point-marker))
3498 (goto-char (point-min))
3499 (forward-line)
3500 (anything-mark-current-line)
3502 (setq anything-isearch-match-positions nil)
3503 (setq anything-isearch-match-start (point-marker))
3505 (if anything-isearch-overlay
3506 ;; make sure the overlay belongs to the anything buffer
3507 (move-overlay anything-isearch-overlay (point-min) (point-min)
3508 (get-buffer (anything-buffer-get)))
3510 (setq anything-isearch-overlay (make-overlay (point-min) (point-min)))
3511 (overlay-put anything-isearch-overlay 'face anything-isearch-match-face))
3513 (setq anything-isearch-message-suffix
3514 (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))
3516 (error (anything-isearch-cleanup)))))
3519 (defun anything-isearch-post-command ()
3520 "Print the current pattern after every command."
3521 (anything-isearch-message)
3522 (when (anything-window)
3523 (with-anything-window
3524 (move-overlay anything-isearch-overlay anything-isearch-match-start (point)
3525 (get-buffer (anything-buffer-get))))))
3528 (defun anything-isearch-printing-char ()
3529 "Add printing char to the pattern."
3530 (interactive)
3531 (let ((char (char-to-string last-command-event)))
3532 (setq anything-isearch-pattern (concat anything-isearch-pattern char))
3534 (with-anything-window
3535 (if (looking-at char)
3536 (progn
3537 (push (list 'event 'char
3538 'start anything-isearch-match-start
3539 'pos (point-marker))
3540 anything-isearch-match-positions)
3541 (forward-char))
3543 (let ((start (point)))
3544 (while (and (re-search-forward anything-isearch-pattern nil t)
3545 (anything-pos-header-line-p)))
3546 (if (or (anything-pos-header-line-p)
3547 (eq start (point)))
3548 (progn
3549 (goto-char start)
3550 (push (list 'event 'error
3551 'start anything-isearch-match-start
3552 'pos (point-marker))
3553 anything-isearch-match-positions))
3555 (push (list 'event 'search
3556 'start anything-isearch-match-start
3557 'pos (copy-marker start))
3558 anything-isearch-match-positions)
3559 (setq anything-isearch-match-start
3560 (copy-marker (match-beginning 0))))))
3562 (anything-mark-current-line))))
3565 (defun anything-isearch-again ()
3566 "Search again for the current pattern"
3567 (interactive)
3568 (if (equal anything-isearch-pattern "")
3569 (setq anything-isearch-message-suffix "no pattern yet")
3571 (with-anything-window
3572 (let ((start (point)))
3573 (while (and (re-search-forward anything-isearch-pattern nil t)
3574 (anything-pos-header-line-p)))
3575 (if (or (anything-pos-header-line-p)
3576 (eq start (point)))
3577 (progn
3578 (goto-char start)
3579 (unless (eq 'error
3580 (plist-get (car anything-isearch-match-positions)
3581 'event))
3582 (setq anything-isearch-message-suffix "no more matches")))
3584 (push (list 'event 'search-again
3585 'start anything-isearch-match-start
3586 'pos (copy-marker start))
3587 anything-isearch-match-positions)
3588 (setq anything-isearch-match-start (copy-marker (match-beginning 0)))
3590 (anything-mark-current-line))))))
3593 (defun anything-isearch-delete ()
3594 "Undo last event."
3595 (interactive)
3596 (unless (equal anything-isearch-pattern "")
3597 (let ((last (pop anything-isearch-match-positions)))
3598 (unless (eq 'search-again (plist-get last 'event))
3599 (setq anything-isearch-pattern
3600 (substring anything-isearch-pattern 0 -1)))
3602 (with-anything-window
3603 (goto-char (plist-get last 'pos))
3604 (setq anything-isearch-match-start (plist-get last 'start))
3605 (anything-mark-current-line)))))
3608 (defun anything-isearch-default-action ()
3609 "Execute the default action for the selected candidate."
3610 (interactive)
3611 (anything-isearch-cleanup)
3612 (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))
3615 (defun anything-isearch-select-action ()
3616 "Choose an action for the selected candidate."
3617 (interactive)
3618 (anything-isearch-cleanup)
3619 (with-anything-window
3620 (anything-select-action)))
3623 (defun anything-isearch-cancel ()
3624 "Cancel Anything isearch."
3625 (interactive)
3626 (anything-isearch-cleanup)
3627 (when (anything-window)
3628 (with-anything-window
3629 (goto-char anything-isearch-original-point)
3630 (anything-mark-current-line))))
3633 (defun anything-isearch-cleanup ()
3634 "Clean up the mess."
3635 (setq minibuffer-message-timeout anything-isearch-original-message-timeout)
3636 (with-current-buffer (anything-buffer-get)
3637 (setq overriding-terminal-local-map nil)
3638 (setq cursor-type nil)
3639 (setq cursor-in-non-selected-windows
3640 anything-isearch-original-cursor-in-non-selected-windows))
3641 (when anything-isearch-original-window
3642 (select-window anything-isearch-original-window))
3644 (use-global-map anything-isearch-original-global-map)
3645 (setq-default deferred-action-list
3646 anything-isearch-original-deferred-action-list)
3647 (when (overlayp anything-isearch-overlay)
3648 (delete-overlay anything-isearch-overlay)))
3651 (defun anything-isearch-message ()
3652 "Print prompt."
3653 (if (and (equal anything-isearch-message-suffix "")
3654 (eq (plist-get (car anything-isearch-match-positions) 'event)
3655 'error))
3656 (setq anything-isearch-message-suffix "failing"))
3658 (unless (equal anything-isearch-message-suffix "")
3659 (setq anything-isearch-message-suffix
3660 (concat " [" anything-isearch-message-suffix "]")))
3662 (message (concat "Search within results: "
3663 anything-isearch-pattern
3664 anything-isearch-message-suffix))
3666 (setq anything-isearch-message-suffix ""))
3669 ;; (@* "Utility: Iswitchb integration (unmaintained)")
3671 (defvar anything-iswitchb-candidate-selected nil
3672 "Indicates whether an anything candidate is selected from iswitchb.")
3674 (defvar anything-iswitchb-frame-configuration nil
3675 "Saved frame configuration, before anything buffer was displayed.")
3677 (defvar anything-iswitchb-saved-keys nil
3678 "The original in iswitchb before binding anything keys.")
3681 (defun anything-iswitchb-setup ()
3682 "Integrate anything completion into iswitchb (UNMAINTAINED).
3684 If the user is idle for `anything-iswitchb-idle-delay' seconds
3685 after typing something into iswitchb then anything candidates are
3686 shown for the current iswitchb input.
3688 ESC cancels anything completion and returns to normal iswitchb.
3690 Some key bindings in `anything-map' are modified.
3691 See also `anything-iswitchb-setup-keys'."
3692 (interactive)
3694 (require 'iswitchb)
3696 ;; disable timid completion during iswitchb
3697 (put 'iswitchb-buffer 'timid-completion 'disabled)
3698 (add-hook 'minibuffer-setup-hook 'anything-iswitchb-minibuffer-setup)
3700 (defadvice iswitchb-visit-buffer
3701 (around anything-iswitchb-visit-buffer activate)
3702 (if anything-iswitchb-candidate-selected
3703 (anything-execute-selection-action)
3704 ad-do-it))
3706 (defadvice iswitchb-possible-new-buffer
3707 (around anything-iswitchb-possible-new-buffer activate)
3708 (if anything-iswitchb-candidate-selected
3709 (anything-execute-selection-action)
3710 ad-do-it))
3711 (anything-iswitchb-setup-keys)
3712 (message "Iswitchb integration is activated."))
3714 (defun anything-iswitchb-setup-keys ()
3715 "Modify `anything-map' for anything-iswitchb users.
3717 C-p is used instead of M-p, because anything uses ESC
3718 (currently hardcoded) for `anything-iswitchb-cancel-anything' and
3719 Emacs handles ESC and Meta as synonyms, so ESC overrides
3720 other commands with Meta prefix.
3722 Note that iswitchb uses M-p and M-n by default for history
3723 navigation, so you should bind C-p and C-n in
3724 `iswitchb-mode-map' if you use the history keys and don't want
3725 to use different keys for iswitchb while anything is not yet
3726 kicked in. These keys are not bound automatically by anything
3727 in `iswitchb-mode-map' because they (C-n at least) already have
3728 a standard iswitchb binding which you might be accustomed to.
3730 Binding M-s is used instead of C-s, because C-s has a binding in
3731 iswitchb. You can rebind it AFTER `anything-iswitchb-setup'.
3733 Unbind C-r to prevent problems during anything-isearch."
3734 (define-key anything-map (kbd "C-s") nil)
3735 (define-key anything-map (kbd "M-p") nil)
3736 (define-key anything-map (kbd "M-n") nil)
3737 (define-key anything-map (kbd "M-v") nil)
3738 (define-key anything-map (kbd "C-v") nil)
3739 (define-key anything-map (kbd "C-p") 'anything-previous-history-element)
3740 (define-key anything-map (kbd "C-n") 'anything-next-history-element)
3741 (define-key anything-map (kbd "M-s") nil)
3742 (define-key anything-map (kbd "M-s") 'anything-isearch)
3743 (define-key anything-map (kbd "C-r") nil))
3745 (defun anything-iswitchb-minibuffer-setup ()
3746 (when (eq this-command 'iswitchb-buffer)
3747 (add-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
3749 (setq anything-iswitchb-frame-configuration nil)
3750 (setq anything-iswitchb-candidate-selected nil)
3751 (add-hook 'anything-update-hook 'anything-iswitchb-handle-update)
3753 (anything-initialize)
3755 (add-hook 'deferred-action-list 'anything-iswitchb-check-input)))
3758 (defun anything-iswitchb-minibuffer-exit ()
3759 (remove-hook 'minibuffer-exit-hook 'anything-iswitchb-minibuffer-exit)
3760 (remove-hook 'deferred-action-list 'anything-iswitchb-check-input)
3761 (remove-hook 'anything-update-hook 'anything-iswitchb-handle-update)
3763 (anything-cleanup)
3765 (when anything-iswitchb-frame-configuration
3766 (anything-set-frame/window-configuration
3767 anything-iswitchb-frame-configuration)
3768 (setq anything-iswitchb-frame-configuration nil)))
3771 (defun anything-iswitchb-check-input ()
3772 "Extract iswitchb input and check if it needs to be handled."
3773 (declare (special iswitchb-text))
3774 (if (or anything-iswitchb-frame-configuration
3775 (sit-for anything-iswitchb-idle-delay))
3776 (anything-check-new-input iswitchb-text)))
3779 (defun anything-iswitchb-handle-update ()
3780 "Pop up the anything buffer if it's not empty and it's not
3781 shown yet and bind anything commands in iswitchb."
3782 (unless (or (anything-empty-buffer-p anything-buffer)
3783 anything-iswitchb-frame-configuration)
3784 (setq anything-iswitchb-frame-configuration
3785 (anything-current-frame/window-configuration))
3787 (save-selected-window
3788 (if (not anything-samewindow)
3789 (pop-to-buffer anything-buffer)
3791 (select-window (get-lru-window))
3792 (switch-to-buffer anything-buffer)))
3794 (with-current-buffer (window-buffer (active-minibuffer-window))
3795 (let* ((anything-prefix "anything-")
3796 (prefix-length (length anything-prefix))
3797 (commands
3798 (delete-dups
3799 (remove-if 'null
3800 (mapcar
3801 (lambda (binding)
3802 (let ((command (cdr binding)))
3803 (when (and (symbolp command)
3804 (eq (compare-strings
3805 anything-prefix
3806 0 prefix-length
3807 (symbol-name command)
3808 0 prefix-length)
3810 command)))
3811 (cdr anything-map)))))
3812 (bindings (mapcar (lambda (command)
3813 (cons command
3814 (where-is-internal command anything-map)))
3815 commands)))
3817 (push (list 'anything-iswitchb-cancel-anything (kbd "<ESC>"))
3818 bindings)
3820 (setq anything-iswitchb-saved-keys nil)
3822 (let* ((iswitchb-prefix "iswitchb-")
3823 (prefix-length (length iswitchb-prefix)))
3824 (dolist (binding bindings)
3825 (dolist (key (cdr binding))
3826 (let ((old-command (lookup-key (current-local-map) key)))
3827 (unless (and anything-iswitchb-dont-touch-iswithcb-keys
3828 (symbolp old-command)
3829 (eq (compare-strings iswitchb-prefix
3830 0 prefix-length
3831 (symbol-name old-command)
3832 0 prefix-length)
3834 (push (cons key old-command)
3835 anything-iswitchb-saved-keys)
3836 (define-key (current-local-map) key (car binding)))))))))))
3839 (defun anything-iswitchb-cancel-anything ()
3840 "Cancel anything completion and return to standard iswitchb."
3841 (interactive)
3842 (save-excursion
3843 (dolist (binding anything-iswitchb-saved-keys)
3844 (define-key (current-local-map) (car binding) (cdr binding)))
3845 (anything-iswitchb-minibuffer-exit)))
3847 ;; (@* "Compatibility")
3849 ;; Copied assoc-default from XEmacs version 21.5.12
3850 (unless (fboundp 'assoc-default)
3851 (defun assoc-default (key alist &optional test default)
3852 "Find object KEY in a pseudo-alist ALIST.
3853 ALIST is a list of conses or objects. Each element (or the element's car,
3854 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
3855 If that is non-nil, the element matches;
3856 then `assoc-default' returns the element's cdr, if it is a cons,
3857 or DEFAULT if the element is not a cons.
3859 If no element matches, the value is nil.
3860 If TEST is omitted or nil, `equal' is used."
3861 (let (found (tail alist) value)
3862 (while (and tail (not found))
3863 (let ((elt (car tail)))
3864 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
3865 (setq found t value (if (consp elt) (cdr elt) default))))
3866 (setq tail (cdr tail)))
3867 value)))
3869 ;; Function not available in XEmacs,
3870 (unless (fboundp 'minibuffer-contents)
3871 (defun minibuffer-contents ()
3872 "Return the user input in a minbuffer as a string.
3873 The current buffer must be a minibuffer."
3874 (field-string (point-max)))
3876 (defun delete-minibuffer-contents ()
3877 "Delete all user input in a minibuffer.
3878 The current buffer must be a minibuffer."
3879 (delete-field (point-max))))
3881 ;; Function not available in older Emacs (<= 22.1).
3882 (unless (fboundp 'buffer-chars-modified-tick)
3883 (defun buffer-chars-modified-tick (&optional buffer)
3884 "Return BUFFER's character-change tick counter.
3885 Each buffer has a character-change tick counter, which is set to the
3886 value of the buffer's tick counter (see `buffer-modified-tick'), each
3887 time text in that buffer is inserted or deleted. By comparing the
3888 values returned by two individual calls of `buffer-chars-modified-tick',
3889 you can tell whether a character change occurred in that buffer in
3890 between these calls. No argument or nil as argument means use current
3891 buffer as BUFFER."
3892 (with-current-buffer (or buffer (current-buffer))
3893 (if (listp buffer-undo-list)
3894 (length buffer-undo-list)
3895 (buffer-modified-tick)))))
3897 ;; (@* "CUA workaround")
3898 (defadvice cua-delete-region (around anything-avoid-cua activate)
3899 (ignore-errors ad-do-it))
3900 (defadvice copy-region-as-kill (around anything-avoid-cua activate)
3901 (if cua-mode
3902 (ignore-errors ad-do-it)
3903 ad-do-it))
3906 ;;(@* "Attribute Documentation")
3907 (defun anything-describe-anything-attribute (anything-attribute)
3908 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol)."
3909 (interactive (list (intern
3910 (completing-read
3911 "Describe anything attribute: "
3912 (mapcar 'symbol-name anything-additional-attributes)))))
3913 (with-output-to-temp-buffer "*Help*"
3914 (princ (get anything-attribute 'anything-attrdoc))))
3916 (anything-document-attribute 'name "mandatory"
3917 " The name of the source. It is also the heading which appears
3918 above the list of matches from the source. Must be unique. ")
3919 (anything-document-attribute 'header-name "optional"
3920 " A function returning the display string of the header. Its
3921 argument is the name of the source. This attribute is useful to
3922 add an additional information with the source name. ")
3923 (anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
3924 " Specifies how to retrieve candidates from the source. It can
3925 either be a variable name, a function called with no parameters
3926 or the actual list of candidates.
3928 The list must be a list whose members are strings, symbols
3929 or (DISPLAY . REAL) pairs.
3931 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
3932 in the Anything buffer, but the REAL one is used as action
3933 argument when the candidate is selected. This allows a more
3934 readable presentation for candidates which would otherwise be,
3935 for example, too long or have a common part shared with other
3936 candidates which can be safely replaced with an abbreviated
3937 string for display purposes.
3939 Note that if the (DISPLAY . REAL) form is used then pattern
3940 matching is done on the displayed string, not on the real
3941 value.
3943 If the candidates have to be retrieved asynchronously (for
3944 example, by an external command which takes a while to run)
3945 then the function should start the external command
3946 asynchronously and return the associated process object.
3947 Anything will take care of managing the process (receiving the
3948 output from it, killing it if necessary, etc.). The process
3949 should return candidates matching the current pattern (see
3950 variable `anything-pattern'.)
3952 Note that currently results from asynchronous sources appear
3953 last in the anything buffer regardless of their position in
3954 `anything-sources'. ")
3955 (anything-document-attribute 'action "mandatory if type attribute is not provided"
3956 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
3957 FUNCTION is called with one parameter: the selected candidate.
3959 An action other than the default can be chosen from this list
3960 of actions for the currently selected candidate (by default
3961 with TAB). The DISPLAY string is shown in the completions
3962 buffer and the FUNCTION is invoked when an action is
3963 selected. The first action of the list is the default. ")
3964 (anything-document-attribute 'coerce "optional"
3965 " It's a function called with one argument: the selected candidate.
3967 This function is intended for type convertion.
3968 In normal case, the selected candidate (string) is passed to action function.
3969 If coerce function is specified, it is called just before action function.
3971 Example: converting string to symbol
3972 (coerce . intern)
3974 (anything-document-attribute 'type "optional if action attribute is provided"
3975 " Indicates the type of the items the source returns.
3977 Merge attributes not specified in the source itself from
3978 `anything-type-attributes'.
3980 This attribute is implemented by plug-in. ")
3981 (anything-document-attribute 'init "optional"
3982 " Function called with no parameters when anything is started. It
3983 is useful for collecting current state information which can be
3984 used to create the list of candidates later.
3986 For example, if a source needs to work with the current
3987 directory then it can store its value here, because later
3988 anything does its job in the minibuffer and in the
3989 `anything-buffer' and the current directory can be different
3990 there. ")
3991 (anything-document-attribute 'delayed-init "optional"
3992 " Function called with no parameters before candidate function is
3993 called. It is similar with `init' attribute, but its
3994 evaluation is deferred. It is useful to combine with ")
3995 (anything-document-attribute 'match "optional"
3996 " List of functions called with one parameter: a candidate. The
3997 function should return non-nil if the candidate matches the
3998 current pattern (see variable `anything-pattern').
4000 This attribute allows the source to override the default
4001 pattern matching based on `string-match'. It can be used, for
4002 example, to implement a source for file names and do the
4003 pattern matching on the basename of files, since it's more
4004 likely one is typing part of the basename when searching for a
4005 file, instead of some string anywhere else in its path.
4007 If the list contains more than one function then the list of
4008 matching candidates from the source is constructed by appending
4009 the results after invoking the first function on all the
4010 potential candidates, then the next function, and so on. The
4011 matching candidates supplied by the first function appear first
4012 in the list of results and then results from the other
4013 functions, respectively.
4015 This attribute has no effect for asynchronous sources (see
4016 attribute `candidates'), since they perform pattern matching
4017 themselves. ")
4018 (anything-document-attribute 'candidate-transformer "optional"
4019 " It's a function or a list of functions called with one argument
4020 when the completion list from the source is built. The argument
4021 is the list of candidates retrieved from the source. The
4022 function should return a transformed list of candidates which
4023 will be used for the actual completion. If it is a list of
4024 functions, it calls each function sequentially.
4026 This can be used to transform or remove items from the list of
4027 candidates.
4029 Note that `candidates' is run already, so the given transformer
4030 function should also be able to handle candidates with (DISPLAY
4031 . REAL) format. ")
4032 (anything-document-attribute 'filtered-candidate-transformer "optional"
4033 " It has the same format as `candidate-transformer', except the
4034 function is called with two parameters: the candidate list and
4035 the source.
4037 This transformer is run on the candidate list which is already
4038 filtered by the current pattern. While `candidate-transformer'
4039 is run only once, it is run every time the input pattern is
4040 changed.
4042 It can be used to transform the candidate list dynamically, for
4043 example, based on the current pattern.
4045 In some cases it may also be more efficent to perform candidate
4046 transformation here, instead of with `candidate-transformer'
4047 even if this transformation is done every time the pattern is
4048 changed. For example, if a candidate set is very large then
4049 `candidate-transformer' transforms every candidate while only
4050 some of them will actually be dislpayed due to the limit
4051 imposed by `anything-candidate-number-limit'.
4053 Note that `candidates' and `candidate-transformer' is run
4054 already, so the given transformer function should also be able
4055 to handle candidates with (DISPLAY . REAL) format.
4057 This option has no effect for asynchronous sources. (Not yet,
4058 at least. ")
4059 (anything-document-attribute 'action-transformer "optional"
4060 " It's a function or a list of functions called with two
4061 arguments when the action list from the source is
4062 assembled. The first argument is the list of actions, the
4063 second is the current selection. If it is a list of functions,
4064 it calls each function sequentially.
4066 The function should return a transformed action list.
4068 This can be used to customize the list of actions based on the
4069 currently selected candidate. ")
4070 (anything-document-attribute 'pattern-transformer "optional"
4071 " It's a function or a list of functions called with one argument
4072 before computing matches. Its argument is `anything-pattern'.
4073 Functions should return transformed `anything-pattern'.
4075 It is useful to change interpretation of `anything-pattern'. ")
4076 (anything-document-attribute 'delayed "optional"
4077 " Candidates from the source are shown only if the user stops
4078 typing and is idle for `anything-idle-delay' seconds. ")
4079 (anything-document-attribute 'volatile "optional"
4080 " Indicates the source assembles the candidate list dynamically,
4081 so it shouldn't be cached within a single Anything
4082 invocation. It is only applicable to synchronous sources,
4083 because asynchronous sources are not cached. ")
4084 (anything-document-attribute 'requires-pattern "optional"
4085 " If present matches from the source are shown only if the
4086 pattern is not empty. Optionally, it can have an integer
4087 parameter specifying the required length of input which is
4088 useful in case of sources with lots of candidates. ")
4089 (anything-document-attribute 'persistent-action "optional"
4090 " Function called with one parameter; the selected candidate.
4092 An action performed by `anything-execute-persistent-action'.
4093 If none, use the default action. ")
4094 (anything-document-attribute 'candidates-in-buffer "optional"
4095 " Shortcut attribute for making and narrowing candidates using
4096 buffers. This newly-introduced attribute prevents us from
4097 forgetting to add volatile and match attributes.
4099 See docstring of `anything-candidates-in-buffer'.
4101 (candidates-in-buffer) is equivalent of three attributes:
4102 (candidates . anything-candidates-in-buffer)
4103 (volatile)
4104 (match identity)
4106 (candidates-in-buffer . candidates-function) is equivalent of:
4107 (candidates . candidates-function)
4108 (volatile)
4109 (match identity)
4111 This attribute is implemented by plug-in. ")
4112 (anything-document-attribute 'search "optional"
4113 " List of functions like `re-search-forward' or `search-forward'.
4114 Buffer search function used by `anything-candidates-in-buffer'.
4115 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4116 This attribute is meant to be used with
4117 (candidates . anything-candidates-in-buffer) or
4118 (candidates-in-buffer) in short. ")
4119 (anything-document-attribute 'search-from-end "optional"
4120 " Make `anything-candidates-in-buffer' search from the end of buffer.
4121 If this attribute is specified, `anything-candidates-in-buffer' uses
4122 `re-search-backward' instead. ")
4123 (anything-document-attribute 'get-line "optional"
4124 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4125 This function converts point of line-beginning and point of line-end,
4126 which represents a candidate computed by `anything-candidates-in-buffer'.
4127 By default, `anything-candidates-in-buffer' uses
4128 `buffer-substring-no-properties'. ")
4129 (anything-document-attribute 'display-to-real "optional"
4130 " Function called with one parameter; the selected candidate.
4132 The function transforms the selected candidate, and the result
4133 is passed to the action function. The display-to-real
4134 attribute provides another way to pass other string than one
4135 shown in Anything buffer.
4137 Traditionally, it is possible to make candidates,
4138 candidate-transformer or filtered-candidate-transformer
4139 function return a list with (DISPLAY . REAL) pairs. But if REAL
4140 can be generated from DISPLAY, display-to-real is more
4141 convenient and faster. ")
4142 (anything-document-attribute 'real-to-display "optional"
4143 " Function called with one parameter; the selected candidate.
4145 The inverse of display-to-real attribute.
4147 The function transforms the selected candidate, which is passed
4148 to the action function, for display. The real-to-display
4149 attribute provides the other way to pass other string than one
4150 shown in Anything buffer.
4152 Traditionally, it is possible to make candidates,
4153 candidate-transformer or filtered-candidate-transformer
4154 function return a list with (DISPLAY . REAL) pairs. But if
4155 DISPLAY can be generated from REAL, real-to-display is more
4156 convenient.
4158 Note that DISPLAY parts returned from candidates /
4159 candidate-transformer are IGNORED as the name `display-to-real'
4160 says. ")
4161 (anything-document-attribute 'cleanup "optional"
4162 " Function called with no parameters when *anything* buffer is closed. It
4163 is useful for killing unneeded candidates buffer.
4165 Note that the function is executed BEFORE performing action. ")
4166 (anything-document-attribute 'candidate-number-limit "optional"
4167 " Override `anything-candidate-number-limit' only for this source. ")
4168 (anything-document-attribute 'accept-empty "optional"
4169 " Pass empty string \"\" to action function. ")
4170 (anything-document-attribute 'disable-shortcuts "optional"
4171 " Disable `anything-enable-shortcuts' in current `anything' session.
4173 This attribute is implemented by plug-in. ")
4174 (anything-document-attribute 'dummy "optional"
4175 " Set `anything-pattern' to candidate. If this attribute is
4176 specified, The candidates attribute is ignored.
4178 This attribute is implemented by plug-in.
4179 This plug-in implies disable-shortcuts plug-in. ")
4180 (anything-document-attribute 'multiline "optional"
4181 " Enable to selection multiline candidates. ")
4182 (anything-document-attribute 'update "optional"
4183 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4184 (anything-document-attribute 'mode-line "optional"
4185 " source local `anything-mode-line-string'. (included in `mode-line-format')
4186 It accepts also variable/function name. ")
4187 (anything-document-attribute 'header-line "optional"
4188 " source local `header-line-format'.
4189 It accepts also variable/function name. ")
4190 (anything-document-attribute 'resume "optional" " Function called with no parameters when `anything-resume' is started.")
4192 ;; (@* "Bug Report")
4193 (defvar anything-maintainer-mail-address
4194 (concat "rubiki" "tch@ru" "by-lang.org"))
4195 (defvar anything-bug-report-salutation
4196 "Describe bug below, using a precise recipe.
4198 When I executed M-x ...
4200 How to send a bug report:
4201 1) Be sure to use the LATEST version of anything.el.
4202 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
4203 3) Use Lisp version instead of compiled one: (load \"anything.el\")
4204 4) If you got an error, please paste *Backtrace* buffer.
4205 5) Type C-c C-c to send.
4206 # If you are a Japanese, please write in Japanese:-)")
4207 (defvar anything-no-dump-variables
4208 '(anything-candidate-buffer-alist
4209 anything-digit-overlays
4210 anything-help-message
4211 anything-candidate-cache
4213 "Variables not to dump in bug report.")
4215 (defun anything-dumped-variables-in-bug-report ()
4216 (let ((hash (make-hash-table)))
4217 (loop for var in (apropos-internal "anything-" 'boundp)
4218 for vname = (symbol-name var)
4219 unless (or (string-match "-map$" vname)
4220 (string-match "^anything-c-source-" vname)
4221 (string-match "-hash$" vname)
4222 (string-match "-face$" vname)
4223 (memq var anything-no-dump-variables))
4224 collect var)))
4226 (defun anything-send-bug-report ()
4227 "Send a bug report of anything.el."
4228 (interactive)
4229 (with-current-buffer (or anything-last-buffer
4230 (current-buffer))
4231 (reporter-submit-bug-report
4232 anything-maintainer-mail-address
4233 "anything.el"
4234 (anything-dumped-variables-in-bug-report)
4235 nil nil
4236 anything-bug-report-salutation)))
4238 (defun anything-send-bug-report-from-anything ()
4239 "Send a bug report of anything.el in anything session."
4240 (interactive)
4241 (anything-run-after-quit 'anything-send-bug-report))
4243 ;; (@* "Unit Tests")
4245 (defun* anything-test-candidates (sources &optional (input "") (compile-source-functions anything-compile-source-functions-default))
4246 "Test helper function for anything.
4247 Given pseudo `anything-sources' and `anything-pattern', returns list like
4248 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4249 (\"source name2\" (\"candidate3\" \"candidate4\")))
4251 (let ((anything-test-mode t)
4252 anything-enable-shortcuts
4253 anything-candidate-cache
4254 (anything-compile-source-functions compile-source-functions)
4255 anything-before-initialize-hook
4256 anything-after-initialize-hook
4257 anything-update-hook
4258 anything-test-candidate-list)
4259 (get-buffer-create anything-buffer)
4261 (anything-initialize-1 nil input sources)
4262 (anything-update)
4263 ;; test-mode spec: select 1st candidate!
4264 (with-current-buffer anything-buffer
4265 (forward-line 1)
4266 (anything-mark-current-line))
4267 (prog1
4268 anything-test-candidate-list
4269 (anything-cleanup))))
4271 (defmacro anything-test-update (sources pattern)
4272 "Test helper macro for anything. It is meant for testing *anything* buffer contents."
4273 `(progn (stub anything-get-sources => ,sources)
4274 (stub anything-log-run-hook => nil)
4275 (stub anything-maybe-fit-frame => nil)
4276 (stub run-with-idle-timer => nil)
4277 (let (anything-test-mode (anything-pattern ,pattern))
4278 (anything-update))))
4280 ;;;; unit test
4281 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4282 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
4283 (dont-compile
4284 (when (fboundp 'expectations)
4285 (expectations
4286 (desc "anything-current-buffer")
4287 (expect "__a_buffer"
4288 (with-current-buffer (get-buffer-create "__a_buffer")
4289 (anything-test-candidates '(((name . "FOO"))) "")
4290 (prog1
4291 (buffer-name anything-current-buffer)
4292 (kill-buffer "__a_buffer")
4294 (desc "anything-buffer-file-name")
4295 (expect (regexp "/__a_file__")
4296 (with-current-buffer (get-buffer-create "__a_file__")
4297 (setq buffer-file-name "/__a_file__")
4298 (anything-test-candidates '(((name . "FOO"))) "")
4299 (prog1
4300 anything-buffer-file-name
4301 ;;(kill-buffer "__a_file__")
4303 (desc "anything-interpret-value")
4304 (expect "literal"
4305 (anything-interpret-value "literal"))
4306 (expect "lambda"
4307 (anything-interpret-value (lambda () "lambda")))
4308 (expect "lambda with source name"
4309 (let ((source '((name . "lambda with source name"))))
4310 (anything-interpret-value (lambda () anything-source-name) source)))
4311 (expect "function symbol"
4312 (flet ((f () "function symbol"))
4313 (anything-interpret-value 'f)))
4314 (expect "variable symbol"
4315 (let ((v "variable symbol"))
4316 (anything-interpret-value 'v)))
4317 (expect (error error *)
4318 (anything-interpret-value 'unbounded-1))
4319 (desc "anything-compile-sources")
4320 (expect '(((name . "foo")))
4321 (anything-compile-sources '(((name . "foo"))) nil)
4323 (expect '(((name . "foo") (type . test) (action . identity)))
4324 (let ((anything-type-attributes '((test (action . identity)))))
4325 (anything-compile-sources '(((name . "foo") (type . test)))
4326 '(anything-compile-source--type))))
4327 (desc "anything-sources accepts symbols")
4328 (expect '(((name . "foo")))
4329 (let* ((foo '((name . "foo"))))
4330 (anything-compile-sources '(foo) nil)))
4331 (desc "anything-get-sources action")
4332 (expect '(((name . "Actions") (candidates . actions)))
4333 (stub anything-action-window => t)
4334 (let (anything-compiled-sources
4335 (anything-sources '(((name . "Actions") (candidates . actions)))))
4336 (anything-get-sources)))
4337 (desc "get-buffer-create candidates-buffer")
4338 (expect '(((name . "many") (init . many-init)
4339 (candidates-in-buffer . anything-candidates-in-buffer)
4340 (candidates . anything-candidates-in-buffer)
4341 (volatile) (match identity)))
4342 (anything-compile-sources
4343 '(((name . "many") (init . many-init)
4344 (candidates-in-buffer . anything-candidates-in-buffer)))
4345 '(anything-compile-source--candidates-in-buffer)))
4346 (expect '(((name . "many") (init . many-init)
4347 (candidates-in-buffer)
4348 (candidates . anything-candidates-in-buffer)
4349 (volatile) (match identity)))
4350 (anything-compile-sources
4351 '(((name . "many") (init . many-init)
4352 (candidates-in-buffer)))
4353 '(anything-compile-source--candidates-in-buffer)))
4354 (expect '(((name . "many") (init . many-init)
4355 (candidates-in-buffer)
4356 (type . test)
4357 (action . identity)
4358 (candidates . anything-candidates-in-buffer)
4359 (volatile) (match identity)))
4360 (let ((anything-type-attributes '((test (action . identity)))))
4361 (anything-compile-sources
4362 '(((name . "many") (init . many-init)
4363 (candidates-in-buffer)
4364 (type . test)))
4365 '(anything-compile-source--type
4366 anything-compile-source--candidates-in-buffer))))
4368 (desc "anything-get-candidates")
4369 (expect '("foo" "bar")
4370 (anything-get-candidates '((name . "foo") (candidates "foo" "bar"))))
4371 (expect '("FOO" "BAR")
4372 (anything-get-candidates '((name . "foo") (candidates "foo" "bar")
4373 (candidate-transformer
4374 . (lambda (cands) (mapcar 'upcase cands))))))
4375 (expect '("foo" "bar")
4376 (anything-get-candidates '((name . "foo")
4377 (candidates . (lambda () '("foo" "bar"))))))
4378 (expect '("foo" "bar")
4379 (let ((var '("foo" "bar")))
4380 (anything-get-candidates '((name . "foo")
4381 (candidates . var)))))
4382 (expect (error error *)
4383 (anything-get-candidates '((name . "foo")
4384 (candidates . "err"))))
4385 (expect (error error *)
4386 (let ((var "err"))
4387 (anything-get-candidates '((name . "foo")
4388 (candidates . var)))))
4389 (expect (error error *)
4390 (anything-get-candidates '((name . "foo")
4391 (candidates . unDeFined-syMbol))))
4392 (desc "anything-compute-matches")
4393 (expect '("foo" "bar")
4394 (let ((anything-pattern ""))
4395 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4396 (expect '("foo")
4397 (let ((anything-pattern "oo"))
4398 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4399 (expect '("bar")
4400 (let ((anything-pattern "^b"))
4401 (anything-compute-matches '((name . "FOO") (candidates "foo" "bar") (volatile)))))
4402 (expect '("a" "b")
4403 (let ((anything-pattern "")
4404 (anything-candidate-number-limit 2))
4405 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4406 (expect '("a" "b")
4407 (let ((anything-pattern ".")
4408 (anything-candidate-number-limit 2))
4409 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4410 (expect '("a" "b" "c")
4411 (let ((anything-pattern "")
4412 anything-candidate-number-limit)
4413 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4414 (expect '("a" "b" "c")
4415 (let ((anything-pattern "[abc]")
4416 anything-candidate-number-limit)
4417 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c") (volatile)))))
4418 (expect '(a b c)
4419 (let ((anything-pattern "[abc]")
4420 anything-candidate-number-limit)
4421 (anything-compute-matches '((name . "FOO") (candidates a b c) (volatile)))))
4422 (expect '(("foo" . "FOO") ("bar" . "BAR"))
4423 (let ((anything-pattern ""))
4424 (anything-compute-matches '((name . "FOO") (candidates ("foo" . "FOO") ("bar" . "BAR")) (volatile)))))
4425 (expect '(("foo" . "FOO"))
4426 (let ((anything-pattern "foo"))
4427 (anything-compute-matches '((name . "FOO") (candidates ("foo" . "FOO") ("bar" . "foo")) (volatile)))))
4428 ;; using anything-test-candidate-list
4429 (desc "anything-test-candidates")
4430 (expect '(("FOO" ("foo" "bar")))
4431 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")))))
4432 (expect '(("FOO" ("bar")))
4433 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar"))) "ar"))
4434 (expect '(("T1" ("hoge" "aiue"))
4435 ("T2" ("test" "boke")))
4436 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4437 ((name . "T2") (candidates "test" "boke")))))
4438 (expect '(("T1" ("hoge"))
4439 ("T2" ("boke")))
4440 (anything-test-candidates '(((name . "T1") (candidates "hoge" "aiue"))
4441 ((name . "T2") (candidates "test" "boke"))) "o"))
4442 (desc "requires-pattern attribute")
4443 (expect nil
4444 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4445 (requires-pattern . 1)))))
4446 (expect '(("FOO" ("bar")))
4447 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4448 (requires-pattern . 1))) "b"))
4449 (desc "delayed attribute(for test)")
4450 (expect '(("T2" ("boke"))
4451 ("T1" ("hoge")))
4452 (anything-test-candidates
4453 '(((name . "T1") (candidates "hoge" "aiue") (delayed))
4454 ((name . "T2") (candidates "test" "boke")))
4455 "o"))
4456 (desc "match attribute(prefix search)")
4457 (expect '(("FOO" ("bar")))
4458 (anything-test-candidates
4459 '(((name . "FOO") (candidates "foo" "bar")
4460 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4461 "ba"))
4462 (expect nil
4463 (anything-test-candidates
4464 '(((name . "FOO") (candidates "foo" "bar")
4465 (match (lambda (c) (string-match (concat "^" anything-pattern) c)))))
4466 "ar"))
4467 (expect "TestSource"
4468 (let (x)
4469 (anything-test-candidates
4470 '(((name . "TestSource") (candidates "a")
4471 (match (lambda (c) (setq x anything-source-name)))))
4472 "a")
4474 (desc "init attribute")
4475 (expect '(("FOO" ("bar")))
4476 (let (v)
4477 (anything-test-candidates
4478 '(((name . "FOO") (init . (lambda () (setq v '("foo" "bar"))))
4479 (candidates . v)))
4480 "ar")))
4481 (desc "candidate-transformer attribute")
4482 (expect '(("FOO" ("BAR")))
4483 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4484 (candidate-transformer
4485 . (lambda (cands) (mapcar 'upcase cands)))))
4486 "ar"))
4487 (desc "filtered-candidate-transformer attribute")
4488 ;; needs more tests
4489 (expect '(("FOO" ("BAR")))
4490 (anything-test-candidates '(((name . "FOO") (candidates "foo" "bar")
4491 (filtered-candidate-transformer
4492 . (lambda (cands src) (mapcar 'upcase cands)))))
4493 "ar"))
4494 (desc "anything-transform-candidates in process")
4495 (expect (mock (anything-composed-funcall-with-source
4496 '((name . "FOO") (candidates "foo" "bar")
4497 (filtered-candidate-transformer
4498 . (lambda (cands src) (mapcar 'upcase cands))))
4499 (lambda (cands src) (mapcar 'upcase cands))
4500 '("foo" "bar")
4501 '((name . "FOO") (candidates "foo" "bar")
4502 (filtered-candidate-transformer
4503 . (lambda (cands src) (mapcar 'upcase cands))))
4505 (stub anything-process-candidate-transformer => '("foo" "bar"))
4506 (anything-transform-candidates
4507 '("foo" "bar")
4508 '((name . "FOO") (candidates "foo" "bar")
4509 (filtered-candidate-transformer
4510 . (lambda (cands src) (mapcar 'upcase cands))))
4513 (desc "anything-candidates-in-buffer-1")
4514 (expect nil
4515 (anything-candidates-in-buffer-1
4516 nil ""
4517 'buffer-substring-no-properties '(re-search-forward) 50 nil))
4518 (expect '("foo+" "bar+" "baz+")
4519 (with-temp-buffer
4520 (insert "foo+\nbar+\nbaz+\n")
4521 (anything-candidates-in-buffer-1
4522 (current-buffer) ""
4523 'buffer-substring-no-properties '(re-search-forward) 5 nil)))
4524 (expect '("foo+" "bar+")
4525 (with-temp-buffer
4526 (insert "foo+\nbar+\nbaz+\n")
4527 (anything-candidates-in-buffer-1
4528 (current-buffer) ""
4529 'buffer-substring-no-properties '(re-search-forward) 2 nil)))
4530 (expect '("foo+")
4531 (with-temp-buffer
4532 (insert "foo+\nbar+\nbaz+\n")
4533 (anything-candidates-in-buffer-1
4534 (current-buffer) "oo\\+"
4535 'buffer-substring-no-properties '(re-search-forward) 50 nil)))
4536 (expect '("foo+")
4537 (with-temp-buffer
4538 (insert "foo+\nbar+\nbaz+\n")
4539 (anything-candidates-in-buffer-1
4540 (current-buffer) "oo+"
4541 #'buffer-substring-no-properties '(search-forward) 50 nil)))
4542 (expect '("foo+" "bar+")
4543 (with-temp-buffer
4544 (insert "foo+\nbar+\nbaz+\n")
4545 (anything-candidates-in-buffer-1
4546 (current-buffer) "."
4547 'buffer-substring-no-properties '(re-search-forward) 2 nil)))
4548 (expect '(("foo+" "FOO+"))
4549 (with-temp-buffer
4550 (insert "foo+\nbar+\nbaz+\n")
4551 (anything-candidates-in-buffer-1
4552 (current-buffer) "oo\\+"
4553 (lambda (s e)
4554 (let ((l (buffer-substring-no-properties s e)))
4555 (list l (upcase l))))
4556 '(re-search-forward) 50 nil)))
4557 (desc "anything-candidates-in-buffer")
4558 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4559 (anything-test-candidates
4560 '(((name . "TEST")
4561 (init
4562 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4563 (insert "foo+\nbar+\nbaz+\n"))))
4564 (candidates . anything-candidates-in-buffer)
4565 (match identity)
4566 (volatile)))))
4567 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4568 (let (anything-candidate-number-limit)
4569 (anything-test-candidates
4570 '(((name . "TEST")
4571 (init
4572 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4573 (insert "foo+\nbar+\nbaz+\n"))))
4574 (candidates . anything-candidates-in-buffer)
4575 (match identity)
4576 (volatile))))))
4577 (expect '(("TEST" ("foo+")))
4578 (anything-test-candidates
4579 '(((name . "TEST")
4580 (init
4581 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4582 (insert "foo+\nbar+\nbaz+\n"))))
4583 (candidates . anything-candidates-in-buffer)
4584 (match identity)
4585 (volatile)))
4586 "oo\\+"))
4587 ;; BUG remain empty string, but the pattern is rare case.
4588 (expect '(("a" ("" "a" "b")))
4589 (anything-test-candidates
4590 '(((name . "a")
4591 (init . (lambda ()
4592 (with-current-buffer (anything-candidate-buffer 'global)
4593 (insert "a\nb\n"))))
4594 (candidates-in-buffer)))
4595 "a*"))
4596 (desc "search attribute")
4597 (expect '(("TEST" ("foo+")))
4598 (anything-test-candidates
4599 '(((name . "TEST")
4600 (init
4601 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4602 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4603 (search search-forward)
4604 (candidates . anything-candidates-in-buffer)
4605 (match identity)
4606 (volatile)))
4607 "oo+"))
4608 (expect '(("TEST" ("foo+" "ooo")))
4609 (anything-test-candidates
4610 '(((name . "TEST")
4611 (init
4612 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4613 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4614 (search search-forward re-search-forward)
4615 (candidates . anything-candidates-in-buffer)
4616 (match identity)
4617 (volatile)))
4618 "oo+"))
4619 (expect '(("TEST" ("foo+" "ooo")))
4620 (anything-test-candidates
4621 '(((name . "TEST")
4622 (init
4623 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4624 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4625 (search re-search-forward search-forward)
4626 (candidates . anything-candidates-in-buffer)
4627 (match identity)
4628 (volatile)))
4629 "oo+"))
4630 (expect '(("TEST" ("ooo" "foo+")))
4631 (anything-test-candidates
4632 '(((name . "TEST")
4633 (init
4634 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4635 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4636 (search re-search-forward search-forward)
4637 (candidates . anything-candidates-in-buffer)
4638 (match identity)
4639 (volatile)))
4640 "oo+"))
4641 ;; faster exact match
4642 (expect '(("TEST" ("bar+")))
4643 (anything-test-candidates
4644 '(((name . "TEST")
4645 (init
4646 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4647 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4648 (search (lambda (pattern &rest _)
4649 (and (search-forward (concat "\n" pattern "\n") nil t)
4650 (forward-line -1))))
4651 (candidates . anything-candidates-in-buffer)
4652 (match identity)
4653 (volatile)))
4654 "bar+"))
4655 ;; faster prefix match
4656 (expect '(("TEST" ("bar+")))
4657 (anything-test-candidates
4658 '(((name . "TEST")
4659 (init
4660 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
4661 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4662 (search (lambda (pattern &rest _)
4663 (search-forward (concat "\n" pattern) nil t)))
4664 (candidates . anything-candidates-in-buffer)
4665 (match identity)
4666 (volatile)))
4667 "ba"))
4668 (desc "anything-current-buffer-is-modified")
4669 (expect '(("FOO" ("modified")))
4670 (let ((sources '(((name . "FOO")
4671 (candidates
4672 . (lambda ()
4673 (if (anything-current-buffer-is-modified)
4674 '("modified")
4675 '("unmodified"))))))))
4676 (with-temp-buffer
4677 (clrhash anything-tick-hash)
4678 (insert "1")
4679 (anything-test-candidates sources))))
4680 (expect '(("FOO" ("unmodified")))
4681 (let ((sources '(((name . "FOO")
4682 (candidates
4683 . (lambda ()
4684 (if (anything-current-buffer-is-modified)
4685 '("modified")
4686 '("unmodified"))))))))
4687 (with-temp-buffer
4688 (clrhash anything-tick-hash)
4689 (insert "1")
4690 (anything-test-candidates sources)
4691 (anything-test-candidates sources))))
4692 (expect '(("FOO" ("modified")))
4693 (let ((sources '(((name . "FOO")
4694 (candidates
4695 . (lambda ()
4696 (if (anything-current-buffer-is-modified)
4697 '("modified")
4698 '("unmodified"))))))))
4699 (with-temp-buffer
4700 (clrhash anything-tick-hash)
4701 (insert "1")
4702 (anything-test-candidates sources)
4703 (insert "2")
4704 (anything-test-candidates sources))))
4705 (expect '(("BAR" ("modified")))
4706 (let ((sources1 '(((name . "FOO")
4707 (candidates
4708 . (lambda ()
4709 (if (anything-current-buffer-is-modified)
4710 '("modified")
4711 '("unmodified")))))))
4712 (sources2 '(((name . "BAR")
4713 (candidates
4714 . (lambda ()
4715 (if (anything-current-buffer-is-modified)
4716 '("modified")
4717 '("unmodified"))))))))
4718 (with-temp-buffer
4719 (clrhash anything-tick-hash)
4720 (insert "1")
4721 (anything-test-candidates sources1)
4722 (anything-test-candidates sources2))))
4723 (expect '(("FOO" ("unmodified")))
4724 (let ((sources1 '(((name . "FOO")
4725 (candidates
4726 . (lambda ()
4727 (if (anything-current-buffer-is-modified)
4728 '("modified")
4729 '("unmodified")))))))
4730 (sources2 '(((name . "BAR")
4731 (candidates
4732 . (lambda ()
4733 (if (anything-current-buffer-is-modified)
4734 '("modified")
4735 '("unmodified"))))))))
4736 (with-temp-buffer
4737 (clrhash anything-tick-hash)
4738 (insert "1")
4739 (anything-test-candidates sources1)
4740 (anything-test-candidates sources2)
4741 (anything-test-candidates sources1))))
4742 (expect '(("BAR" ("unmodified")))
4743 (let ((sources1 '(((name . "FOO")
4744 (candidates
4745 . (lambda ()
4746 (if (anything-current-buffer-is-modified)
4747 '("modified")
4748 '("unmodified")))))))
4749 (sources2 '(((name . "BAR")
4750 (candidates
4751 . (lambda ()
4752 (if (anything-current-buffer-is-modified)
4753 '("modified")
4754 '("unmodified"))))))))
4755 (with-temp-buffer
4756 (clrhash anything-tick-hash)
4757 (insert "1")
4758 (anything-test-candidates sources1)
4759 (anything-test-candidates sources2)
4760 (anything-test-candidates sources2))))
4761 (expect '(("BAR" ("modified")))
4762 (let ((sources1 '(((name . "FOO")
4763 (candidates
4764 . (lambda ()
4765 (if (anything-current-buffer-is-modified)
4766 '("modified")
4767 '("unmodified")))))))
4768 (sources2 '(((name . "BAR")
4769 (candidates
4770 . (lambda ()
4771 (if (anything-current-buffer-is-modified)
4772 '("modified")
4773 '("unmodified"))))))))
4774 (with-temp-buffer
4775 (clrhash anything-tick-hash)
4776 (insert "1")
4777 (anything-test-candidates sources1)
4778 (anything-test-candidates sources2)
4779 (with-temp-buffer
4780 (anything-test-candidates sources2)))))
4781 (desc "anything-source-name")
4782 (expect "FOO"
4783 (let (v)
4784 (anything-test-candidates '(((name . "FOO")
4785 (init
4786 . (lambda () (setq v anything-source-name)))
4787 (candidates "ok"))))
4789 (expect "FOO"
4790 (let (v)
4791 (anything-test-candidates '(((name . "FOO")
4792 (candidates
4793 . (lambda ()
4794 (setq v anything-source-name)
4795 '("ok"))))))
4797 (expect "FOO"
4798 (let (v)
4799 (anything-test-candidates '(((name . "FOO")
4800 (candidates "ok")
4801 (candidate-transformer
4802 . (lambda (c)
4803 (setq v anything-source-name)
4804 c)))))
4806 (expect "FOO"
4807 (let (v)
4808 (anything-test-candidates '(((name . "FOO")
4809 (candidates "ok")
4810 (filtered-candidate-transformer
4811 . (lambda (c s)
4812 (setq v anything-source-name)
4813 c)))))
4815 (expect "FOO"
4816 (let (v)
4817 (anything-test-candidates '(((name . "FOO")
4818 (candidates "ok")
4819 (display-to-real
4820 . (lambda (c)
4821 (setq v anything-source-name)
4823 (action . identity))))
4824 (anything-execute-selection-action)
4826 (desc "anything-candidate-buffer create")
4827 (expect " *anything candidates:FOO*"
4828 (let* (anything-candidate-buffer-alist
4829 (anything-source-name "FOO")
4830 (buf (anything-candidate-buffer 'global)))
4831 (prog1 (buffer-name buf)
4832 (kill-buffer buf))))
4833 (expect " *anything candidates:FOO*aTestBuffer"
4834 (let* (anything-candidate-buffer-alist
4835 (anything-source-name "FOO")
4836 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4837 (buf (anything-candidate-buffer 'local)))
4838 (prog1 (buffer-name buf)
4839 (kill-buffer anything-current-buffer)
4840 (kill-buffer buf))))
4841 (expect 0
4842 (let (anything-candidate-buffer-alist
4843 (anything-source-name "FOO") buf)
4844 (with-current-buffer (anything-candidate-buffer 'global)
4845 (insert "1"))
4846 (setq buf (anything-candidate-buffer 'global))
4847 (prog1 (buffer-size buf)
4848 (kill-buffer buf))))
4849 (desc "anything-candidate-buffer get-buffer")
4850 (expect " *anything candidates:FOO*"
4851 (let* (anything-candidate-buffer-alist
4852 (anything-source-name "FOO")
4853 (buf (anything-candidate-buffer 'global)))
4854 (prog1 (buffer-name (anything-candidate-buffer))
4855 (kill-buffer buf))))
4856 (expect " *anything candidates:FOO*aTestBuffer"
4857 (let* (anything-candidate-buffer-alist
4858 (anything-source-name "FOO")
4859 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4860 (buf (anything-candidate-buffer 'local)))
4861 (prog1 (buffer-name (anything-candidate-buffer))
4862 (kill-buffer anything-current-buffer)
4863 (kill-buffer buf))))
4864 (expect " *anything candidates:FOO*"
4865 (let* (anything-candidate-buffer-alist
4866 (anything-source-name "FOO")
4867 (buf-local (anything-candidate-buffer 'local))
4868 (buf-global (anything-candidate-buffer 'global)))
4869 (prog1 (buffer-name (anything-candidate-buffer))
4870 (kill-buffer buf-local)
4871 (kill-buffer buf-global))))
4872 (expect " *anything candidates:FOO*aTestBuffer"
4873 (let* (anything-candidate-buffer-alist
4874 (anything-source-name "FOO")
4875 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4876 (buf-global (anything-candidate-buffer 'global))
4877 (buf-local (anything-candidate-buffer 'local)))
4878 (prog1 (buffer-name (anything-candidate-buffer))
4879 (kill-buffer buf-local)
4880 (kill-buffer buf-global))))
4881 (expect nil
4882 (let* (anything-candidate-buffer-alist
4883 (anything-source-name "NOP__"))
4884 (anything-candidate-buffer)))
4885 (desc "anything-candidate-buffer register-buffer")
4886 (expect " *anything test candidates*"
4887 (let (anything-candidate-buffer-alist
4888 (buf (get-buffer-create " *anything test candidates*")))
4889 (with-current-buffer buf
4890 (insert "1\n2\n")
4891 (prog1 (buffer-name (anything-candidate-buffer buf))
4892 (kill-buffer (current-buffer))))))
4893 (expect " *anything test candidates*"
4894 (let (anything-candidate-buffer-alist
4895 (buf (get-buffer-create " *anything test candidates*")))
4896 (with-current-buffer buf
4897 (insert "1\n2\n")
4898 (anything-candidate-buffer buf)
4899 (prog1 (buffer-name (anything-candidate-buffer))
4900 (kill-buffer (current-buffer))))))
4901 (expect "1\n2\n"
4902 (let (anything-candidate-buffer-alist
4903 (buf (get-buffer-create " *anything test candidates*")))
4904 (with-current-buffer buf
4905 (insert "1\n2\n")
4906 (anything-candidate-buffer buf)
4907 (prog1 (buffer-string)
4908 (kill-buffer (current-buffer))))))
4909 (expect "buf1"
4910 (let (anything-candidate-buffer-alist
4911 (anything-source-name "foo")
4912 (buf1 (get-buffer-create "buf1"))
4913 (buf2 (get-buffer-create "buf2")))
4914 (anything-candidate-buffer buf1)
4915 (anything-candidate-buffer buf2)
4916 (prog1 (buffer-name (anything-candidate-buffer buf1))
4917 (kill-buffer buf1)
4918 (kill-buffer buf2))))
4919 (desc "action attribute")
4920 (expect "foo"
4921 (anything-test-candidates
4922 '(((name . "TEST")
4923 (candidates "foo")
4924 (action ("identity" . identity)))))
4925 (anything-execute-selection-action))
4926 (expect "foo"
4927 (anything-test-candidates
4928 '(((name . "TEST")
4929 (candidates "foo")
4930 (action ("identity" . (lambda (c) (identity c)))))))
4931 (anything-execute-selection-action))
4932 (desc "anything-get-default-action")
4933 (expect 'upcase
4934 (anything-get-default-action '(("upcase" . upcase))))
4935 (expect 'downcase
4936 (anything-get-default-action '(("downcase" . downcase))))
4937 (expect (lambda (x) (capitalize x))
4938 (anything-get-default-action (lambda (x) (capitalize x))))
4939 (expect 'identity
4940 (anything-get-default-action 'identity))
4941 (desc "anything-execute-selection-action")
4942 (expect "FOO"
4943 (anything-execute-selection-action
4944 "foo" '(("upcase" . upcase)) nil))
4945 (expect "FOO"
4946 (anything-execute-selection-action
4947 "foo" '(("upcase" . (lambda (c) (upcase c)))) nil))
4949 (desc "display-to-real attribute")
4950 (expect "FOO"
4951 (anything-test-candidates
4952 '(((name . "TEST")
4953 (candidates "foo")
4954 (display-to-real . upcase)
4955 (action ("identity" . identity)))))
4956 (anything-execute-selection-action))
4957 (desc "cleanup test")
4958 (expect 'cleaned
4959 (let (v)
4960 (anything-test-candidates
4961 '(((name . "TEST")
4962 (cleanup . (lambda () (setq v 'cleaned))))))
4964 (desc "anything-get-current-source")
4965 ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
4966 ;; display-to-real/cleanup function
4967 (expect "FOO"
4968 (assoc-default
4969 'name
4970 (anything-funcall-with-source '((name . "FOO")) 'anything-get-current-source)))
4971 ;; init
4972 (expect "FOO"
4973 (let (v)
4974 (anything-test-candidates
4975 '(((name . "FOO")
4976 (init . (lambda () (setq v (anything-get-current-source)))))))
4977 (assoc-default 'name v)))
4978 ;; candidates
4979 (expect "FOO"
4980 (let (v)
4981 (anything-test-candidates
4982 '(((name . "FOO")
4983 (candidates . (lambda () (setq v (anything-get-current-source)) '("a"))))))
4984 (assoc-default 'name v)))
4985 ;; action
4986 (expect "FOO"
4987 (let (v)
4988 (anything-test-candidates
4989 '(((name . "FOO")
4990 (candidates "a")
4991 (action
4992 . (lambda (c) (setq v (anything-get-current-source)) c)))))
4993 (anything-execute-selection-action)
4994 (assoc-default 'name v)))
4995 ;; candidate-transformer
4996 (expect "FOO"
4997 (let (v)
4998 (anything-test-candidates
4999 '(((name . "FOO")
5000 (candidates "a")
5001 (candidate-transformer
5002 . (lambda (c) (setq v (anything-get-current-source)) c)))))
5003 (assoc-default 'name v)))
5004 ;; filtered-candidate-transformer
5005 (expect "FOO"
5006 (let (v)
5007 (anything-test-candidates
5008 '(((name . "FOO")
5009 (candidates "a")
5010 (filtered-candidate-transformer
5011 . (lambda (c s) (setq v (anything-get-current-source)) c)))))
5012 (assoc-default 'name v)))
5013 ;; action-transformer
5014 (expect "FOO"
5015 (let (v)
5016 (anything-test-candidates
5017 '(((name . "FOO")
5018 (candidates "a")
5019 (action-transformer
5020 . (lambda (a c) (setq v (anything-get-current-source)) a))
5021 (action . identity))))
5022 (anything-execute-selection-action)
5023 (assoc-default 'name v)))
5024 ;; display-to-real
5025 (expect "FOO"
5026 (let (v)
5027 (anything-test-candidates
5028 '(((name . "FOO")
5029 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5030 (insert "a\n"))))
5031 (candidates-in-buffer)
5032 (display-to-real
5033 . (lambda (c) (setq v (anything-get-current-source)) c))
5034 (action . identity))))
5035 (anything-execute-selection-action)
5036 (assoc-default 'name v)))
5037 ;; cleanup
5038 (expect "FOO"
5039 (let (v)
5040 (anything-test-candidates
5041 '(((name . "FOO")
5042 (candidates "a")
5043 (cleanup
5044 . (lambda () (setq v (anything-get-current-source)))))))
5045 (assoc-default 'name v)))
5046 ;; candidates are displayed
5047 (expect "TEST"
5048 (anything-test-candidates
5049 '(((name . "TEST")
5050 (candidates "foo")
5051 (action ("identity" . identity)))))
5052 (assoc-default 'name (anything-get-current-source)))
5053 (desc "anything-attr")
5054 (expect "FOO"
5055 (anything-funcall-with-source
5056 '((name . "FOO"))
5057 (lambda ()
5058 (anything-attr 'name))))
5059 (expect 'fuga
5060 (let (v)
5061 (anything-test-candidates
5062 '(((name . "FOO")
5063 (hoge . fuga)
5064 (init . (lambda () (setq v (anything-attr 'hoge))))
5065 (candidates "a"))))
5067 (expect nil
5068 (let (v)
5069 (anything-test-candidates
5070 '(((name . "FOO")
5071 (init . (lambda () (setq v (anything-attr 'hoge))))
5072 (candidates "a"))))
5074 (expect nil
5075 (let (v)
5076 (anything-test-candidates
5077 '(((name . "FOO")
5078 (hoge) ;INCOMPATIBLE!
5079 (init . (lambda () (setq v (anything-attr 'hoge))))
5080 (candidates "a"))))
5082 (desc "anything-attr*")
5083 (expect "generic"
5084 (let (v (value1 "generic"))
5085 (anything-test-candidates
5086 '(((name . "FOO")
5087 (hoge . value1)
5088 (init . (lambda () (setq v (anything-attr* 'hoge)))))))
5090 (desc "anything-attr-defined")
5091 (expect (non-nil)
5092 (let (v)
5093 (anything-test-candidates
5094 '(((name . "FOO")
5095 (hoge)
5096 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5097 (candidates "a"))))
5098 v))
5099 (expect nil
5100 (let (v)
5101 (anything-test-candidates
5102 '(((name . "FOO")
5103 (init . (lambda () (setq v (anything-attr-defined 'hoge))))
5104 (candidates "a"))))
5105 v))
5106 (desc "anything-attrset")
5107 (expect '((name . "FOO") (hoge . 77))
5108 (let ((src '((name . "FOO") (hoge))))
5109 (anything-attrset 'hoge 77 src)
5110 src))
5111 (expect 77
5112 (anything-attrset 'hoge 77 '((name . "FOO") (hoge))))
5114 (expect '((name . "FOO") (hoge . 77))
5115 (let ((src '((name . "FOO") (hoge . 1))))
5116 (anything-attrset 'hoge 77 src)
5117 src))
5119 (expect '((name . "FOO") (hoge . 77) (x))
5120 (let ((src '((name . "FOO") (x))))
5121 (anything-attrset 'hoge 77 src)
5122 src))
5123 (expect 77
5124 (anything-attrset 'hoge 77 '((name . "FOO"))))
5125 (desc "anything-preselect")
5126 ;; entire candidate
5127 (expect "foo"
5128 (with-current-buffer (anything-create-anything-buffer t)
5129 (let ((anything-pattern "")
5130 (anything-test-mode t))
5131 (anything-process-source '((name . "test")
5132 (candidates "hoge" "foo" "bar")))
5133 (anything-preselect "foo")
5134 (anything-get-selection))))
5135 ;; regexp
5136 (expect "foo"
5137 (with-current-buffer (anything-create-anything-buffer t)
5138 (let ((anything-pattern "")
5139 (anything-test-mode t))
5140 (anything-process-source '((name . "test")
5141 (candidates "hoge" "foo" "bar")))
5142 (anything-preselect "fo+")
5143 (anything-get-selection))))
5144 ;; no match -> first entry
5145 (expect "hoge"
5146 (with-current-buffer (anything-create-anything-buffer t)
5147 (let ((anything-pattern "")
5148 (anything-test-mode t))
5149 (anything-process-source '((name . "test")
5150 (candidates "hoge" "foo" "bar")))
5151 (anything-preselect "not found")
5152 (anything-get-selection))))
5153 (desc "anything-check-new-input")
5154 (expect "newpattern"
5155 (stub anything-update)
5156 (stub anything-action-window)
5157 (let ((anything-pattern "pattern"))
5158 (anything-check-new-input "newpattern")
5159 anything-pattern))
5160 ;; anything-input == nil when action window is available
5161 (expect nil
5162 (stub anything-update)
5163 (stub anything-action-window => t)
5164 (let ((anything-pattern "pattern")
5165 anything-input)
5166 (anything-check-new-input "newpattern")
5167 anything-input))
5168 ;; anything-input == anything-pattern unless action window is available
5169 (expect "newpattern"
5170 (stub anything-update)
5171 (stub anything-action-window => nil)
5172 (let ((anything-pattern "pattern")
5173 anything-input)
5174 (anything-check-new-input "newpattern")
5175 anything-input))
5176 (expect (mock (anything-update))
5177 (stub anything-action-window)
5178 (let (anything-pattern)
5179 (anything-check-new-input "foo")))
5180 (desc "anything-update")
5181 (expect (mock (anything-process-source '((name . "1"))))
5182 (anything-test-update '(((name . "1"))) ""))
5183 ;; (find-function 'anything-update)
5184 ;; TODO el-mock.el should express 2nd call of function.
5185 ;; (expect (mock (anything-process-source '((name . "2"))))
5186 ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
5187 ;; (stub anything-log-run-hook)
5188 ;; (stub anything-maybe-fit-frame)
5189 ;; (stub run-with-idle-timer)
5190 ;; (anything-update))
5191 (expect (mock (run-with-idle-timer * nil 'anything-process-delayed-sources
5192 '(((name . "2") (delayed)))))
5193 (stub anything-get-sources => '(((name . "1"))
5194 ((name . "2") (delayed))))
5195 (stub anything-log-run-hook)
5196 (stub anything-maybe-fit-frame)
5197 (let ((anything-pattern "") anything-test-mode)
5198 (anything-update)))
5200 (desc "requires-pattern attribute")
5201 (expect (not-called anything-process-source)
5202 (anything-test-update '(((name . "1") (requires-pattern))) ""))
5203 (expect (not-called anything-process-source)
5204 (anything-test-update '(((name . "1") (requires-pattern . 3))) "xx"))
5206 (desc "anything-normalize-sources")
5207 (expect '(anything-c-source-test)
5208 (anything-normalize-sources 'anything-c-source-test))
5209 (expect '(anything-c-source-test)
5210 (anything-normalize-sources '(anything-c-source-test)))
5211 (expect '(anything-c-source-test)
5212 (let ((anything-sources '(anything-c-source-test)))
5213 (anything-normalize-sources nil)))
5214 (expect '(((name . "test")))
5215 (anything-normalize-sources '((name . "test"))))
5216 (expect '(((name . "test")))
5217 (anything-normalize-sources '(((name . "test")))))
5218 (desc "anything-get-action")
5219 (expect '(("identity" . identity))
5220 (stub buffer-size => 1)
5221 (stub anything-get-current-source => '((name . "test")
5222 (action ("identity" . identity))))
5223 (anything-get-action))
5224 (expect 'identity
5225 (stub buffer-size => 1)
5226 (stub anything-get-current-source => '((name . "test")
5227 (action . identity)))
5228 (anything-get-action))
5229 (expect '((("identity" . identity)) "action-transformer is called")
5230 (stub buffer-size => 1)
5231 (stub anything-get-current-source
5232 => '((name . "test")
5233 (action ("identity" . identity))
5234 (action-transformer
5235 . (lambda (actions selection)
5236 (list actions selection)))))
5237 (stub anything-get-selection => "action-transformer is called")
5238 (anything-get-action))
5239 (desc "anything-select-nth-action")
5240 (expect (error error *)
5241 (stub anything-get-selection => nil)
5242 (anything-select-nth-action 0))
5243 (desc "anything-get-nth-action")
5244 (expect 'cadr
5245 (anything-get-nth-action 2 '(("0" . car) ("1" . cdr) ("2" . cadr))))
5246 (expect (error error *)
5247 (anything-get-nth-action 2 '(("0" . car))))
5248 (expect 'identity
5249 (anything-get-nth-action 0 'identity))
5250 (expect (error error *)
5251 (anything-get-nth-action 1 'identity))
5252 (expect (error error *)
5253 (anything-get-nth-action 0 'unbound-function-xxx))
5254 (expect (error error *)
5255 (anything-get-nth-action 0 "invalid data"))
5256 (desc "anything-funcall-foreach")
5257 (expect (mock (upcase "foo"))
5258 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5259 (anything-funcall-foreach 'init))
5260 (expect (mock (downcase "bar"))
5261 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))
5262 ((init . (lambda () (downcase "bar"))))))
5263 (anything-funcall-foreach 'init))
5264 (expect (not-called anything-funcall-with-source)
5265 (stub anything-get-sources => '(((init . (lambda () (upcase "foo"))))))
5266 (anything-funcall-foreach 'not-found))
5267 ;; TODO anything-select-with-digit-shortcut test
5268 (desc "anything-get-cached-candidates")
5269 (expect '("cached" "version")
5270 (let ((anything-candidate-cache '(("test" "cached" "version"))))
5271 (anything-get-cached-candidates '((name . "test")
5272 (candidates "new")))))
5273 (expect '("new")
5274 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5275 (anything-get-cached-candidates '((name . "test")
5276 (candidates "new")))))
5277 (expect '(("test" "new")
5278 ("other" "cached" "version"))
5279 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5280 (anything-get-cached-candidates '((name . "test")
5281 (candidates "new")))
5282 anything-candidate-cache))
5283 (expect '(("other" "cached" "version"))
5284 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5285 (anything-get-cached-candidates '((name . "test")
5286 (candidates "new")
5287 (volatile)))
5288 anything-candidate-cache))
5289 ;; TODO when candidates == process
5290 ;; TODO anything-output-filter
5291 (desc "candidate-number-limit attribute")
5292 (expect '("a" "b")
5293 (let ((anything-pattern "")
5294 (anything-candidate-number-limit 20))
5295 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5296 (candidate-number-limit . 2) (volatile)))))
5297 (expect '("a" "b")
5298 (let ((anything-pattern "[abc]")
5299 (anything-candidate-number-limit 20))
5300 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c")
5301 (candidate-number-limit . 2) (volatile)))))
5302 (expect '("a" "b" "c" "d")
5303 (let ((anything-pattern "[abcd]")
5304 (anything-candidate-number-limit 2))
5305 (anything-compute-matches '((name . "FOO") (candidates "a" "b" "c" "d")
5306 (candidate-number-limit) (volatile)))))
5307 (expect '(("TEST" ("a" "b" "c")))
5308 (let ((anything-candidate-number-limit 2))
5309 (anything-test-candidates
5310 '(((name . "TEST")
5311 (init
5312 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5313 (insert "a\nb\nc\nd\n"))))
5314 (candidates . anything-candidates-in-buffer)
5315 (match identity)
5316 (candidate-number-limit . 3)
5317 (volatile))))))
5318 (expect '(("TEST" ("a" "b" "c")))
5319 (let ((anything-candidate-number-limit 2))
5320 (anything-test-candidates
5321 '(((name . "TEST")
5322 (init
5323 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5324 (insert "a\nb\nc\nd\n"))))
5325 (candidates . anything-candidates-in-buffer)
5326 (match identity)
5327 (candidate-number-limit . 3)
5328 (volatile)))
5329 ".")))
5330 (desc "multiple init")
5331 (expect '(1 . 2)
5332 (let (a b)
5333 (anything-test-candidates
5334 '(((name . "test")
5335 (init (lambda () (setq a 1))
5336 (lambda () (setq b 2))))))
5337 (cons a b)))
5338 (expect 1
5339 (let (a)
5340 (anything-test-candidates
5341 '(((name . "test")
5342 (init (lambda () (setq a 1))))))
5344 (desc "multiple cleanup")
5345 (expect '(1 . 2)
5346 (let (a b)
5347 (anything-test-candidates
5348 '(((name . "test")
5349 (cleanup (lambda () (setq a 1))
5350 (lambda () (setq b 2))))))
5351 (cons a b)))
5352 (desc "anything-mklist")
5353 (expect '(1)
5354 (anything-mklist 1))
5355 (expect '(2)
5356 (anything-mklist '(2)))
5357 (expect '((lambda ()))
5358 (anything-mklist (lambda ())))
5359 (desc "anything-before-initialize-hook")
5360 (expect 'called
5361 (let ((anything-before-initialize-hook '((lambda () (setq v 'called))))
5363 (anything-initialize)
5365 (desc "anything-after-initialize-hook")
5366 (expect '(b a)
5367 (let ((anything-before-initialize-hook
5368 '((lambda () (setq v '(a)))))
5369 (anything-after-initialize-hook
5370 '((lambda () (setq v (cons 'b v)))))
5372 (anything-initialize)
5374 (expect 0
5375 (let ((anything-after-initialize-hook
5376 '((lambda () (setq v (buffer-size (get-buffer anything-buffer))))))
5378 (anything-initialize)
5380 (desc "get-line attribute")
5381 (expect '(("TEST" ("FOO+")))
5382 (anything-test-candidates
5383 '(((name . "TEST")
5384 (init
5385 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5386 (insert "foo+\nbar+\nbaz+\n"))))
5387 (candidates-in-buffer)
5388 (get-line . (lambda (s e) (upcase (buffer-substring-no-properties s e))))))
5389 "oo\\+"))
5390 (desc "with-anything-restore-variables")
5391 (expect '(7 8)
5392 (let ((a 7) (b 8)
5393 (anything-restored-variables '(a b)))
5394 (with-anything-restore-variables
5395 (setq a 0 b 0))
5396 (list a b)))
5397 (desc "anything-cleanup-hook")
5398 (expect 'called
5399 (let ((anything-cleanup-hook
5400 '((lambda () (setq v 'called))))
5402 (anything-cleanup)
5404 (desc "with-anything-display-same-window")
5405 (expect (non-nil)
5406 (save-window-excursion
5407 (delete-other-windows)
5408 (split-window)
5410 (let ((buf (get-buffer-create " tmp"))
5411 (win (selected-window)))
5412 (with-anything-display-same-window
5413 (display-buffer buf)
5414 (eq win (get-buffer-window buf))))))
5415 (expect (non-nil)
5416 (save-window-excursion
5417 (delete-other-windows)
5418 (split-window)
5420 (let ((buf (get-buffer-create " tmp"))
5421 (win (selected-window)))
5422 (with-anything-display-same-window
5423 (pop-to-buffer buf)
5424 (eq win (get-buffer-window buf))))))
5425 (expect (non-nil)
5426 (save-window-excursion
5427 (delete-other-windows)
5428 (split-window)
5430 (let ((buf (get-buffer-create " tmp"))
5431 (win (selected-window)))
5432 (with-anything-display-same-window
5433 (switch-to-buffer buf)
5434 (eq win (get-buffer-window buf))))))
5435 (expect (non-nil)
5436 (save-window-excursion
5437 (delete-other-windows)
5438 (let ((buf (get-buffer-create " tmp"))
5439 (win (selected-window)))
5440 (with-anything-display-same-window
5441 (display-buffer buf)
5442 (eq win (get-buffer-window buf))))))
5443 (expect (non-nil)
5444 (save-window-excursion
5445 (delete-other-windows)
5446 (let ((buf (get-buffer-create " tmp"))
5447 (win (selected-window)))
5448 (with-anything-display-same-window
5449 (pop-to-buffer buf)
5450 (eq win (get-buffer-window buf))))))
5451 (desc "search-from-end attribute")
5452 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5453 (anything-test-candidates
5454 '(((name . "TEST")
5455 (init
5456 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5457 (insert "foo+\nbar+\nbaz+\n"))))
5458 (candidates-in-buffer)
5459 (search-from-end)))))
5460 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5461 (anything-test-candidates
5462 '(((name . "TEST")
5463 (init
5464 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5465 (insert "foo+\nbar+\nbaz+\n"))))
5466 (candidates-in-buffer)
5467 (search-from-end)))
5468 "\\+"))
5469 (expect '(("TEST" ("baz+" "bar+")))
5470 (anything-test-candidates
5471 '(((name . "TEST")
5472 (init
5473 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5474 (insert "foo+\nbar+\nbaz+\n"))))
5475 (candidates-in-buffer)
5476 (search-from-end)
5477 (candidate-number-limit . 2)))))
5478 (expect '(("TEST" ("baz+" "bar+")))
5479 (anything-test-candidates
5480 '(((name . "TEST")
5481 (init
5482 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5483 (insert "foo+\nbar+\nbaz+\n"))))
5484 (candidates-in-buffer)
5485 (search-from-end)
5486 (candidate-number-limit . 2)))
5487 "\\+"))
5488 (expect '(("a" ("c2" "c1")))
5489 (anything-test-candidates
5490 '(((name . "a")
5491 (init . (lambda ()
5492 (with-current-buffer (anything-candidate-buffer 'global)
5493 (insert "c1\nc2\n"))))
5494 (search-from-end)
5495 (candidates-in-buffer)))))
5496 ;; BUG remain empty string, but the pattern is rare case.
5497 (expect '(("a" ("c" "b" "a" "")))
5498 (anything-test-candidates
5499 '(((name . "a")
5500 (init . (lambda ()
5501 (with-current-buffer (anything-candidate-buffer 'global)
5502 (insert "a\nb\nc\n"))))
5503 (search-from-end)
5504 (candidates-in-buffer)))
5505 "a*"))
5506 (desc "header-name attribute")
5507 (expect "original is transformed"
5508 (anything-test-update '(((name . "original")
5509 (candidates "1")
5510 (header-name
5511 . (lambda (name)
5512 (format "%s is transformed" name)))))
5514 (with-current-buffer (anything-buffer-get)
5515 (buffer-string)
5516 (overlay-get (car (overlays-at (1+(point-min)))) 'display)))
5517 (desc "volatile and match attribute")
5518 ;; candidates function is called once per `anything-process-delayed-sources'
5519 (expect 1
5520 (let ((v 0))
5521 (anything-test-candidates '(((name . "test")
5522 (candidates . (lambda () (incf v) '("ok")))
5523 (volatile)
5524 (match identity identity identity)))
5525 "o")
5527 (desc "accept-empty attribute")
5528 (expect nil
5529 (anything-test-candidates
5530 '(((name . "test") (candidates "") (action . identity))))
5531 (anything-execute-selection-action))
5532 (expect ""
5533 (anything-test-candidates
5534 '(((name . "test") (candidates "") (action . identity) (accept-empty))))
5535 (anything-execute-selection-action))
5536 (desc "anything-tick-hash")
5537 (expect nil
5538 (with-current-buffer (get-buffer-create " *00create+*")
5539 (puthash " *00create+*/xxx" 1 anything-tick-hash)
5540 (kill-buffer (current-buffer)))
5541 (gethash " *00create+*/xxx" anything-tick-hash))
5542 (desc "anything-execute-action-at-once-if-once")
5543 (expect "HOGE"
5544 (let ((anything-execute-action-at-once-if-one t))
5545 (anything '(((name . "one test1")
5546 (candidates "hoge")
5547 (action . upcase))))))
5548 (expect "ANY"
5549 (let ((anything-execute-action-at-once-if-one t))
5550 (anything '(((name . "one test2")
5551 (candidates "hoge" "any")
5552 (action . upcase)))
5553 "an")))
5554 ;; candidates > 1
5555 (expect (mock (read-string "word: " nil))
5556 (let ((anything-execute-action-at-once-if-one t))
5557 (anything '(((name . "one test3")
5558 (candidates "hoge" "foo" "bar")
5559 (action . identity)))
5560 nil "word: ")))
5561 (desc "anything-quit-if-no-candidate")
5562 (expect nil
5563 (let ((anything-quit-if-no-candidate t))
5564 (anything '(((name . "zero test1") (candidates) (action . upcase))))))
5565 (expect 'called
5566 (let (v (anything-quit-if-no-candidate (lambda () (setq v 'called))))
5567 (anything '(((name . "zero test2") (candidates) (action . upcase))))
5569 (desc "real-to-display attribute")
5570 (expect '(("test" (("DDD" . "ddd"))))
5571 (anything-test-candidates '(((name . "test")
5572 (candidates "ddd")
5573 (real-to-display . upcase)
5574 (action . identity)))))
5575 (expect '(("test" (("DDD" . "ddd"))))
5576 (anything-test-candidates '(((name . "test")
5577 (candidates ("ignored" . "ddd"))
5578 (real-to-display . upcase)
5579 (action . identity)))))
5580 (expect '(("Commands" (("xxxhoge" . "hoge") ("xxxboke" . "boke"))))
5581 (anything-test-candidates '(((name . "Commands")
5582 (candidates
5583 "hoge" "boke")
5584 (real-to-display . (lambda (x) (concat "xxx" x)))
5585 (action . identity)))
5586 "xxx"))
5587 (expect "test\nDDD\n"
5588 (anything-test-update '(((name . "test")
5589 (candidates "ddd")
5590 (real-to-display . upcase)
5591 (action . identity)))
5593 (with-current-buffer (anything-buffer-get) (buffer-string)))
5594 (desc "real-to-display and candidate-transformer attribute")
5595 (expect '(("test" (("DDD" . "ddd"))))
5596 (anything-test-candidates
5597 '(((name . "test")
5598 (candidates "ddd")
5599 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
5600 (real-to-display . upcase)
5601 (action . identity)))))
5602 (expect "test\nDDD\n"
5603 (anything-test-update
5604 '(((name . "test")
5605 (candidates "ddd")
5606 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c)) cands)))
5607 (real-to-display . upcase)
5608 (action . identity)))
5610 (with-current-buffer (anything-buffer-get) (buffer-string)))
5611 (desc "real-to-display and candidates-in-buffer")
5612 (expect '(("test" (("A" . "a") ("B" . "b"))))
5613 (anything-test-candidates
5614 '(((name . "test")
5615 (init
5616 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5617 (erase-buffer)
5618 (insert "a\nb\n"))))
5619 (candidates-in-buffer)
5620 (real-to-display . upcase)
5621 (action . identity)))))
5622 (expect "test\nA\nB\n"
5623 (stub read-string)
5624 (anything
5625 '(((name . "test")
5626 (init
5627 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5628 (erase-buffer)
5629 (insert "a\nb\n"))))
5630 (candidates-in-buffer)
5631 (real-to-display . upcase)
5632 (action . identity))))
5633 (with-current-buffer (anything-buffer-get) (buffer-string)))
5634 (desc "Symbols are acceptable as candidate.")
5635 (expect '(("test" (sym "str")))
5636 (anything-test-candidates
5637 '(((name . "test")
5638 (candidates sym "str")))))
5639 (expect '(("test" ((sym . realsym) ("str" . "realstr"))))
5640 (anything-test-candidates
5641 '(((name . "test")
5642 (candidates (sym . realsym) ("str" . "realstr"))))))
5643 (expect '(("test" (sym)))
5644 (anything-test-candidates
5645 '(((name . "test")
5646 (candidates sym "str")))
5647 "sym"))
5648 (expect '(("test" ("str")))
5649 (anything-test-candidates
5650 '(((name . "test")
5651 (candidates sym "str")))
5652 "str"))
5653 (expect '(("test" ((sym . realsym))))
5654 (anything-test-candidates
5655 '(((name . "test")
5656 (candidates (sym . realsym) ("str" . "realstr"))))
5657 "sym"))
5658 (expect '(("test" (("str" . "realstr"))))
5659 (anything-test-candidates
5660 '(((name . "test")
5661 (candidates (sym . realsym) ("str" . "realstr"))))
5662 "str"))
5663 (desc "multiple transformers")
5664 (expect '(("test" ("<FOO>")))
5665 (anything-test-candidates
5666 '(((name . "test")
5667 (candidates "foo")
5668 (candidate-transformer
5669 . (lambda (cands)
5670 (anything-compose (list cands)
5671 (list (lambda (c) (mapcar 'upcase c))
5672 (lambda (c) (list (concat "<" (car c) ">")))))))))))
5673 (expect '("<FOO>")
5674 (anything-composed-funcall-with-source
5675 '((name . "test"))
5676 (list (lambda (c) (mapcar 'upcase c))
5677 (lambda (c) (list (concat "<" (car c) ">"))))
5678 '("foo"))
5680 (expect '(("test" ("<FOO>")))
5681 (anything-test-candidates
5682 '(((name . "test")
5683 (candidates "foo")
5684 (candidate-transformer
5685 (lambda (c) (mapcar 'upcase c))
5686 (lambda (c) (list (concat "<" (car c) ">"))))))))
5687 (expect '(("test" ("<BAR>")))
5688 (anything-test-candidates
5689 '(((name . "test")
5690 (candidates "bar")
5691 (filtered-candidate-transformer
5692 (lambda (c s) (mapcar 'upcase c))
5693 (lambda (c s) (list (concat "<" (car c) ">"))))))))
5694 (expect '(("find-file" . find-file)
5695 ("view-file" . view-file))
5696 (stub zerop => nil)
5697 (stub anything-get-current-source
5698 => '((name . "test")
5699 (action)
5700 (action-transformer
5701 . (lambda (a s)
5702 (anything-compose
5703 (list a s)
5704 (list (lambda (a s) (push '("view-file" . view-file) a))
5705 (lambda (a s) (push '("find-file" . find-file) a))))))))
5706 (anything-get-action))
5707 (expect '(("find-file" . find-file)
5708 ("view-file" . view-file))
5709 (stub zerop => nil)
5710 (stub anything-get-current-source
5711 => '((name . "test")
5712 (action)
5713 (action-transformer
5714 (lambda (a s) (push '("view-file" . view-file) a))
5715 (lambda (a s) (push '("find-file" . find-file) a)))))
5716 (anything-get-action))
5717 (desc "define-anything-type-attribute")
5718 (expect '((file (action . find-file)))
5719 (let (anything-type-attributes)
5720 (define-anything-type-attribute 'file '((action . find-file)))
5721 anything-type-attributes))
5722 (expect '((file (action . find-file)))
5723 (let ((anything-type-attributes '((file (action . view-file)))))
5724 (define-anything-type-attribute 'file '((action . find-file)))
5725 anything-type-attributes))
5726 (expect '((file (action . find-file))
5727 (buffer (action . switch-to-buffer)))
5728 (let (anything-type-attributes)
5729 (define-anything-type-attribute 'buffer '((action . switch-to-buffer)))
5730 (define-anything-type-attribute 'file '((action . find-file)))
5731 anything-type-attributes))
5732 (desc "anything-approximate-candidate-number")
5733 (expect 0
5734 (with-temp-buffer
5735 (let ((anything-buffer (current-buffer)))
5736 (anything-approximate-candidate-number))))
5737 (expect 1
5738 (with-temp-buffer
5739 (let ((anything-buffer (current-buffer)))
5740 (insert "Title\n"
5741 "candiate1\n")
5742 (anything-approximate-candidate-number))))
5743 (expect t
5744 (with-temp-buffer
5745 (let ((anything-buffer (current-buffer)))
5746 (insert "Title\n"
5747 "candiate1\n"
5748 "candiate2\n")
5749 (<= 2 (anything-approximate-candidate-number)))))
5750 (expect 1
5751 (with-temp-buffer
5752 (let ((anything-buffer (current-buffer)))
5753 (insert "Title\n"
5754 (propertize "multi\nline\n" 'anything-multiline t))
5755 (anything-approximate-candidate-number))))
5756 (expect t
5757 (with-temp-buffer
5758 (let ((anything-buffer (current-buffer))
5759 (anything-candidate-separator "-----"))
5760 (insert "Title\n"
5761 (propertize "multi\nline1\n" 'anything-multiline t)
5762 "-----\n"
5763 (propertize "multi\nline2\n" 'anything-multiline t))
5764 (<= 2 (anything-approximate-candidate-number)))))
5765 (desc "delayed-init attribute")
5766 (expect 0
5767 (let ((value 0))
5768 (anything-test-candidates '(((name . "test")
5769 (delayed-init . (lambda () (incf value)))
5770 (candiates "abc")
5771 (requires-pattern . 2)))
5773 value))
5774 (expect 1
5775 (let ((value 0))
5776 (anything-test-candidates '(((name . "test")
5777 (delayed-init . (lambda () (incf value)))
5778 (candiates "abc")
5779 (requires-pattern . 2)))
5780 "abc")
5781 value))
5782 (expect 2
5783 (let ((value 0))
5784 (anything-test-candidates '(((name . "test")
5785 (delayed-init (lambda () (incf value))
5786 (lambda () (incf value)))
5787 (candiates "abc")
5788 (requires-pattern . 2)))
5789 "abc")
5790 value))
5791 (expect t
5792 (let (value)
5793 (with-temp-buffer
5794 (anything-test-candidates '(((name . "test")
5795 (delayed-init
5796 . (lambda () (setq value
5797 (eq anything-current-buffer (current-buffer)))))
5798 (candiates "abc")
5799 (requires-pattern . 2)))
5800 "abc")
5801 value)))
5802 (desc "pattern-transformer attribute")
5803 (expect '(("test2" ("foo")) ("test3" ("bar")))
5804 (anything-test-candidates '(((name . "test1")
5805 (candidates "foo" "bar"))
5806 ((name . "test2")
5807 (pattern-transformer . (lambda (pat) (substring pat 1)))
5808 (candidates "foo" "bar"))
5809 ((name . "test3")
5810 (pattern-transformer . (lambda (pat) "bar"))
5811 (candidates "foo" "bar")))
5812 "xfoo"))
5813 (expect '(("test2" ("foo")) ("test3" ("bar")))
5814 (anything-test-candidates '(((name . "test1")
5815 (candidates "foo" "bar"))
5816 ((name . "test2")
5817 (pattern-transformer (lambda (pat) (substring pat 1)))
5818 (candidates "foo" "bar"))
5819 ((name . "test3")
5820 (pattern-transformer (lambda (pat) "bar"))
5821 (candidates "foo" "bar")))
5822 "xfoo"))
5823 (expect '(("test2" ("foo")) ("test3" ("bar")))
5824 (anything-test-candidates '(((name . "test1")
5825 (init
5826 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5827 (insert "foo\nbar\n"))))
5828 (candidates-in-buffer))
5829 ((name . "test2")
5830 (pattern-transformer . (lambda (pat) (substring pat 1)))
5831 (init
5832 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5833 (insert "foo\nbar\n"))))
5834 (candidates-in-buffer))
5835 ((name . "test3")
5836 (pattern-transformer . (lambda (pat) "bar"))
5837 (init
5838 . (lambda () (with-current-buffer (anything-candidate-buffer 'global)
5839 (insert "foo\nbar\n"))))
5840 (candidates-in-buffer)))
5841 "xfoo"))
5842 (desc "anything-recent-push")
5843 (expect '("foo" "bar" "baz")
5844 (let ((lst '("bar" "baz")))
5845 (anything-recent-push "foo" 'lst)))
5846 (expect '("foo" "bar" "baz")
5847 (let ((lst '("foo" "bar" "baz")))
5848 (anything-recent-push "foo" 'lst)))
5849 (expect '("foo" "bar" "baz")
5850 (let ((lst '("bar" "foo" "baz")))
5851 (anything-recent-push "foo" 'lst)))
5852 (desc "anything-require-at-least-version")
5853 (expect nil
5854 (anything-require-at-least-version "1.1"))
5855 (expect nil
5856 (anything-require-at-least-version "1.200"))
5857 (expect nil
5858 (anything-require-at-least-version
5859 (and (string-match "1\.\\([0-9]+\\)" anything-version)
5860 (match-string 0 anything-version))))
5861 (expect (error)
5862 (anything-require-at-least-version "1.999"))
5863 (expect (error)
5864 (anything-require-at-least-version "1.2000"))
5865 (desc "anything-once")
5866 (expect 2
5867 (let ((i 0))
5868 (anything-test-candidates
5869 '(((name . "1")
5870 (init . (lambda () (incf i))))
5871 ((name . "2")
5872 (init . (lambda () (incf i))))))
5874 (expect 1
5875 (let ((i 0))
5876 (anything-test-candidates
5877 '(((name . "1")
5878 (init . (lambda () (anything-once (lambda () (incf i))))))
5879 ((name . "2")
5880 (init . (lambda () (anything-once (lambda () (incf i))))))))
5882 (expect 1
5883 (let ((i 0))
5884 (flet ((init1 () (anything-once (lambda () (incf i)))))
5885 (anything-test-candidates
5886 '(((name . "1")
5887 (init . init1))
5888 ((name . "2")
5889 (init . init1)))))
5891 (desc "anything-marked-candidates")
5892 (expect '("mark3" "mark1")
5893 (let* ((source '((name . "mark test")))
5894 (anything-marked-candidates
5895 `((,source . "mark1")
5896 (((name . "other")) . "mark2")
5897 (,source . "mark3"))))
5898 (stub anything-buffer-get => (current-buffer))
5899 (stub anything-get-current-source => source)
5900 (anything-marked-candidates)))
5901 (expect '("current")
5902 (let* ((source '((name . "mark test")))
5903 (anything-marked-candidates nil))
5904 (stub anything-get-current-source => source)
5905 (stub anything-get-selection => "current")
5906 (anything-marked-candidates)))
5907 (desc "anything-marked-candidates with coerce")
5908 (expect '(mark3 mark1)
5909 (let* ((source '((name . "mark test")
5910 (coerce . intern)))
5911 (anything-marked-candidates
5912 `((,source . "mark1")
5913 (((name . "other")) . "mark2")
5914 (,source . "mark3"))))
5915 (stub anything-buffer-get => (current-buffer))
5916 (stub anything-get-current-source => source)
5917 (anything-marked-candidates)))
5918 (desc "anything-let")
5919 (expect '(1 10000 nil)
5920 (let ((a 9999)
5921 (b 8)
5923 (anything-buffer (exps-tmpbuf)))
5924 (anything-let ((a 1)
5925 (b (1+ a))
5927 (anything-create-anything-buffer))
5928 (with-current-buffer anything-buffer
5929 (list a b c))))
5930 (expect (non-nil)
5931 (let ((a 9999)
5932 (b 8)
5934 (anything-buffer (exps-tmpbuf)))
5935 (anything-let ((a 1)
5936 (b (1+ a))
5938 (anything-create-anything-buffer))
5939 (with-current-buffer anything-buffer
5940 (and (assq 'a (buffer-local-variables))
5941 (assq 'b (buffer-local-variables))
5942 (assq 'c (buffer-local-variables))))))
5943 (expect 'retval
5944 (let ((a 9999)
5945 (b 8)
5947 (anything-buffer (exps-tmpbuf)))
5948 (anything-let ((a 1)
5949 (b (1+ a))
5951 'retval)))
5952 (desc "anything-let*")
5953 (expect '(1 2 nil)
5954 (let ((a 9999)
5955 (b 8)
5957 (anything-buffer (exps-tmpbuf)))
5958 (anything-let* ((a 1)
5959 (b (1+ a))
5961 (anything-create-anything-buffer))
5962 (with-current-buffer anything-buffer
5963 (list a b c))))
5964 (expect (non-nil)
5965 (let ((a 9999)
5966 (b 8)
5968 (anything-buffer (exps-tmpbuf)))
5969 (anything-let* ((a 1)
5970 (b (1+ a))
5972 (anything-create-anything-buffer))
5973 (with-current-buffer anything-buffer
5974 (and (assq 'a (buffer-local-variables))
5975 (assq 'b (buffer-local-variables))
5976 (assq 'c (buffer-local-variables))))))
5977 (expect 'retval*
5978 (let ((a 9999)
5979 (b 8)
5981 (anything-buffer (exps-tmpbuf)))
5982 (anything-let* ((a 1)
5983 (b (1+ a))
5985 'retval*)))
5986 (desc "anything with keyword")
5987 (expect (mock (anything-internal 'test-source "input" "prompt: " nil "preselect" "*test*" nil))
5988 (anything :sources 'test-source
5989 :input "input"
5990 :prompt "prompt: "
5991 :resume nil
5992 :preselect "preselect"
5993 :buffer "*test*"
5994 :keymap nil))
5995 (expect (mock (anything-internal 'test-source nil nil nil nil "*test*" nil))
5996 (anything :sources 'test-source
5997 :buffer "*test*"
5998 :candidate-number-limit 20))
5999 (expect (mock (anything-internal 'test-source nil nil nil nil "*test*" nil))
6000 (anything 'test-source nil nil nil nil "*test*" nil))
6001 (desc "anything-log-eval-internal")
6002 (expect (mock (anything-log "%S = %S" '(+ 1 2) 3))
6003 (anything-log-eval-internal '((+ 1 2))))
6004 (expect (mock (anything-log "%S = ERROR!" 'unDeFined))
6005 (anything-log-eval-internal '(unDeFined)))
6007 (desc "anything-output-filter--collect-candidates")
6008 (expect '("a" "b" "")
6009 (split-string "a\nb\n" "\n"))
6010 (expect '("a" "b")
6011 (anything-output-filter--collect-candidates
6012 '("a" "b" "") (cons 'incomplete-line "")))
6013 (expect '("a" "b")
6014 (split-string "a\nb" "\n"))
6015 (expect '("a")
6016 (anything-output-filter--collect-candidates
6017 '("a" "b") (cons 'incomplete-line "")))
6018 (expect '(incomplete-line . "b")
6019 (let ((incomplete-line-info (cons 'incomplete-line "")))
6020 (anything-output-filter--collect-candidates
6021 '("a" "b") incomplete-line-info)
6022 incomplete-line-info))
6023 (expect '("" "c" "")
6024 (split-string "\nc\n" "\n"))
6025 (expect '("b" "c")
6026 ;; "a\nb" + "\nc\n"
6027 (let ((incomplete-line-info (cons 'incomplete-line "")))
6028 (anything-output-filter--collect-candidates
6029 '("a" "b") incomplete-line-info)
6030 (anything-output-filter--collect-candidates
6031 '("" "c" "") incomplete-line-info)))
6032 (desc "coerce attribute")
6033 (expect "string"
6034 (anything :sources '(((name . "test")
6035 (candidates "string")
6036 (action . identity)))
6037 :execute-action-at-once-if-one t))
6038 (expect 'symbol
6039 (anything :sources '(((name . "test")
6040 (candidates "symbol")
6041 (coerce . intern)
6042 (action . identity)))
6043 :execute-action-at-once-if-one t))
6044 (expect 'real
6045 (anything :sources '(((name . "test")
6046 (candidates ("display" . "real"))
6047 (coerce . intern)
6048 (action . identity)))
6049 :execute-action-at-once-if-one t))
6050 (expect 'real
6051 (anything :sources '(((name . "test")
6052 (candidates)
6053 (candidate-transformer
6054 (lambda (c) '(("display" . "real"))))
6055 (coerce . intern)
6056 (action . identity)))
6057 :execute-action-at-once-if-one t))
6058 (expect 'real
6059 (anything :sources '(((name . "test")
6060 (candidates)
6061 (filtered-candidate-transformer
6062 (lambda (c s) '(("display" . "real"))))
6063 (coerce . intern)
6064 (action . identity)))
6065 :execute-action-at-once-if-one t))
6066 (expect 'real
6067 (anything :sources '(((name . "test")
6068 (candidates "dummy")
6069 (display-to-real (lambda (disp) "real"))
6070 (coerce . intern)
6071 (action . identity)))
6072 :execute-action-at-once-if-one t))
6073 (desc "anything-next-point-in-list")
6074 (expect 10
6075 (anything-next-point-in-list 5 '(10 20) nil))
6076 (expect 20
6077 (anything-next-point-in-list 15 '(10 20) nil))
6078 (expect 25
6079 (anything-next-point-in-list 25 '(10 20) nil))
6080 (expect 5
6081 (anything-next-point-in-list 5 '(10 20) t))
6082 (expect 10
6083 (anything-next-point-in-list 15 '(10 20) t))
6084 (expect 20
6085 (anything-next-point-in-list 25 '(10 20) t))
6086 (expect 5
6087 (anything-next-point-in-list 5 '() nil))
6088 (expect 5
6089 (anything-next-point-in-list 5 '() t))
6090 (expect 10
6091 (anything-next-point-in-list 5 '(10) nil))
6092 (expect 10
6093 (anything-next-point-in-list 15 '(10) t))
6094 (expect 20
6095 (anything-next-point-in-list 10 '(10 20) nil))
6096 (expect 10
6097 (anything-next-point-in-list 20 '(10 20) t))
6098 (expect 20
6099 (anything-next-point-in-list 30 '(10 20 30) t))
6103 (provide 'anything)
6104 ;; How to save (DO NOT REMOVE!!)
6105 ;; (progn (magit-push) (emacswiki-post "anything.el"))
6106 ;; Local Variables:
6107 ;; coding: utf-8
6108 ;; End:
6109 ;;; anything.el ends here