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