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)
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.
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.
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
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.
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")
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:-)
83 ;; Below are complete command list:
85 ;; `anything-open-last-log'
86 ;; Open anything log file of last anything session.
88 ;; Select anything. In Lisp program, some optional arguments can be used.
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.
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'
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
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.
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")
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)
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
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
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.
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.
311 ;; '(((name . "Commands")
312 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
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")
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
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
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.
445 ;; - process status indication
447 ;; - async sources doesn't honor digit-shortcut-count
449 ;; - anything-candidate-number-limit can't be nil everywhere
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
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")
469 (remove-if (lambda (name)
470 (or (equal name anything-buffer
)
471 (eq ?\
(aref name
0))))
472 (mapcar 'buffer-name
(buffer-list)))))
475 ((name .
"File Name History")
476 (candidates . file-name-history
)
477 (match (lambda (candidate)
478 ;; list basename matches first
481 (file-name-nondirectory candidate
)))
484 ;; and then directory part matches
485 (let ((dir (file-name-directory candidate
)))
487 (string-match anything-pattern dir
)))))
490 ((name .
"Files from Current Directory")
492 (setq anything-default-directory
494 (candidates .
(lambda ()
496 anything-default-directory
)))
499 ((name .
"Complex Command History")
500 (candidates .
(lambda ()
501 (mapcar 'prin1-to-string
503 (action .
(("Repeat Complex Command" .
507 "The source of candidates for anything.
509 (setq anything-sources (list anything-c-foo anything-c-bar))
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'.
527 ;; This value is only provided as an example. Customize it to your own
529 (defvar anything-type-attributes
530 '((file (action .
(("Find File" . find-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.
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")
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'.")
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
)
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-
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
)
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
))
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
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
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
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:
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
)
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
)
956 (anything-log-eval (symbol-value hook
))
957 (anything-log-eval (default-value hook
)))
959 (anything-log "executed %s" hook
))
960 (defun anything-log-eval-internal (exprs)
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
)))
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")
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")
997 (defun anything-open-last-log ()
998 "Open anything log file of last anything session."
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
)))
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
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
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
)
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
)
1102 (setcdr src
(cons (cons attribute-name value
) (cdr src
))))
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 ()
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 ()
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
)
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.
1171 `anything-type-attributes' are merged in.
1173 candidates, volatile and match attrubute are created.
1177 ((anything-action-window)
1180 (anything-compiled-sources)
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
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
)
1209 (unless (equal selection
"")
1210 (anything-log-eval 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
))
1229 (with-current-buffer (anything-buffer-get)
1230 (or (get-text-property (point) 'anything-source
)
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)))
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
)
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
)
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
))
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."
1289 (setq short-doc
(concat "(" short-doc
")"))
1290 (setq long-doc 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
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
))
1326 ((and (symbolp value
) (boundp value
))
1327 (symbol-value value
))
1329 (error "anything-interpret-value: Symbol must be a function or a variable"))
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)
1347 (cons (car pair
) (eval (cadr pair
)))
1350 (defun anything-let*-eval-varlist
(varlist)
1351 (let ((vars (mapcar (lambda (pair) (or (car-safe pair
) pair
)) varlist
)))
1353 ,@(mapcar (lambda (pair)
1355 `(setq ,(car pair
) ,(cadr pair
))
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
)
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
))
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
1392 (and (listp sources
) (assq 'name 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))))))
1405 (goto-char (point-min))
1407 (if (anything-pos-multiline-p)
1408 (if (search-forward anything-candidate-separator nil t
) 2 1)
1411 (defmacro with-anything-quittable
(&rest body
)
1412 `(let (inhibit-quit)
1415 (quit (setq anything-quit t
)
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
)))
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
)
1439 (set variable timer
))
1441 ;; (@* "Core: entry point")
1442 (defconst anything-argument-keys
1443 '(:sources
:input
:prompt
:resume
:preselect
:buffer
:keymap
))
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:
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)
1462 Temporary value of `anything-pattern', ie. initial input of minibuffer.
1466 Prompt other than \"pattern: \".
1470 If t, Resurrect previously instance of `anything'. Skip the initialization.
1471 If 'noresume, this instance of `anything' cannot be resumed.
1475 Initially selected candidate. Specified by exact candidate or a regexp.
1476 Note that it is not working with delayed sources.
1480 `anything-buffer' instead of *anything*.
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. "
1504 (if (keywordp (car plist
))
1505 (anything-let-internal
1506 (anything-parse-keys plist
)
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'."
1516 (when (or current-prefix-arg buffer-pattern
)
1517 (setq any-buffer
(anything-resume-select-buffer buffer-pattern
)))
1518 (setq anything-compiled-sources nil
)
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
)
1530 (anything-resume any-buffer buffer-pattern
'window-only
))
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."
1536 (anything any-sources
1537 (if current-prefix-arg
1538 (concat "\\b" (thing-at-point 'symbol
) "\\b"
1539 (if (featurep 'anything-match-plugin
) " " ""))
1541 any-prompt any-resume any-preselect any-buffer
))
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
)
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
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")
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 --------------------------------------------")))
1576 (anything-log "end session (quit) -------------------------------------")
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
)
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 ()
1620 (anything-execute-selection-action)
1621 (anything-aif (get-buffer anything-action-buffer
)
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
1649 (setq anything-current-position
(cons (point) (window-start))))
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
))
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)
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
))
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))
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'."
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)
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-initialize-persistent-action)
1736 (anything-log-eval anything-display-function anything-let-variables
)
1737 (loop for
(var . val
) in anything-let-variables
1738 do
(set (make-local-variable var
) val
))
1740 (setq cursor-type nil
)
1741 (setq mode-name
"Anything"))
1742 (anything-initialize-overlays anything-buffer
)
1743 (get-buffer anything-buffer
))
1745 (defun anything-initialize-overlays (buffer)
1746 (anything-log "overlay setup")
1747 (if anything-selection-overlay
1748 ;; make sure the overlay belongs to the anything buffer if
1749 ;; it's newly created
1750 (move-overlay anything-selection-overlay
(point-min) (point-min)
1751 (get-buffer buffer
))
1753 (setq anything-selection-overlay
1754 (make-overlay (point-min) (point-min) (get-buffer buffer
)))
1755 (overlay-put anything-selection-overlay
'face anything-selection-face
))
1757 (cond (anything-enable-shortcuts
1758 (setq anything-shortcut-keys
1759 (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist
))
1760 (unless anything-digit-overlays
1761 (setq anything-digit-overlays
1762 (loop for key across anything-shortcut-keys
1763 for overlay
= (make-overlay (point-min) (point-min)
1764 (get-buffer buffer
))
1765 do
(overlay-put overlay
'before-string
1766 (format "%s - " (upcase (make-string 1 key
))))
1768 (anything-digit-overlays
1769 (mapc 'delete-overlay anything-digit-overlays
)
1770 (setq anything-digit-overlays nil
))))
1772 (defun anything-hooks (setup-or-cleanup)
1773 (let ((hooks '((deferred-action-list anything-check-minibuffer-input
)
1774 (minibuffer-setup-hook anything-print-error-messages
))))
1775 (if (eq setup-or-cleanup
'setup
)
1776 (dolist (args hooks
) (apply 'add-hook args
))
1777 (dolist (args (reverse hooks
)) (apply 'remove-hook args
)))))
1779 ;; (@* "Core: clean up")
1781 (defun anything-cleanup ()
1782 "Clean up the mess."
1783 (anything-log "start cleanup")
1784 (with-current-buffer anything-buffer
1785 (setq cursor-type t
))
1786 (bury-buffer anything-buffer
)
1787 (anything-funcall-foreach 'cleanup
)
1788 (anything-new-timer 'anything-check-minibuffer-input-timer nil
)
1789 (anything-kill-async-processes)
1790 (anything-log-run-hook 'anything-cleanup-hook
)
1791 (anything-hooks 'cleanup
)
1792 (anything-frame/window-configuration
'restore
))
1794 ;; (@* "Core: input handling")
1795 (defun anything-check-minibuffer-input ()
1796 "Extract input string from the minibuffer and check if it needs
1798 (let ((delay (with-current-buffer anything-buffer anything-input-idle-delay
)))
1799 (if (or (not delay
) (anything-action-window))
1800 (anything-check-minibuffer-input-1)
1802 'anything-check-minibuffer-input-timer
1803 (run-with-idle-timer delay nil
'anything-check-minibuffer-input-1
)))))
1805 (defun anything-check-minibuffer-input-1 ()
1806 (with-anything-quittable
1807 (with-selected-window (minibuffer-window)
1808 (anything-check-new-input (minibuffer-contents)))))
1810 (defun anything-check-new-input (input)
1811 "Check input string and update the anything buffer if
1813 (unless (equal input anything-pattern
)
1814 (setq anything-pattern input
)
1815 (unless (anything-action-window)
1816 (setq anything-input anything-pattern
))
1817 (anything-log-eval anything-pattern anything-input
)
1820 ;; (@* "Core: source compiler")
1821 (defvar anything-compile-source-functions-default anything-compile-source-functions
1822 "Plug-ins this file provides.")
1823 (defun anything-compile-sources (sources funcs
)
1824 "Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
1825 Anything plug-ins are realized by this function."
1828 (loop with source
= (if (listp source
) source
(symbol-value source
))
1830 do
(setq source
(funcall f source
))
1831 finally
(return source
)))
1834 ;; (@* "Core: plug-in attribute documentation hack")
1836 ;; `anything-document-attribute' is public API.
1837 (defadvice documentation-property
(after anything-document-attribute activate
)
1838 "Hack to display plug-in attributes' documentation as `anything-sources' docstring."
1839 (when (eq symbol
'anything-sources
)
1840 (setq ad-return-value
1841 (concat ad-return-value
"\n"
1842 (mapconcat (lambda (sym) (get sym
'anything-attrdoc
))
1843 anything-additional-attributes
1845 ;; (describe-variable 'anything-sources)
1846 ;; (documentation-property 'anything-sources 'variable-documentation)
1847 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
1849 ;; (@* "Core: all candidates")
1850 (defun anything-process-delayed-init (source)
1851 (let ((name (assoc-default 'name source
)))
1852 (unless (member name anything-delayed-init-executed
)
1853 (anything-aif (assoc-default 'delayed-init source
)
1854 (with-current-buffer anything-current-buffer
1855 (anything-funcall-with-source source it
)
1856 (dolist (f (if (functionp it
) (list it
) it
))
1857 (add-to-list 'anything-delayed-init-executed name
)))))))
1859 (defun anything-get-candidates (source)
1860 "Retrieve and return the list of candidates from
1862 (anything-process-delayed-init source
)
1863 (let* ((candidate-source (assoc-default 'candidates source
))
1864 (type-error (lambda ()
1865 (error (concat "Candidates must either be a function, "
1866 " a variable or a list: %s")
1868 (candidates (condition-case err
1869 (anything-interpret-value candidate-source source
)
1870 (error (funcall type-error
)))))
1871 (cond ((processp candidates
) candidates
)
1872 ((listp candidates
) (anything-transform-candidates candidates source
))
1873 (t (funcall type-error
)))))
1876 (defun anything-get-cached-candidates (source)
1877 "Return the cached value of candidates for SOURCE.
1878 Cache the candidates if there is not yet a cached value."
1879 (let* ((name (assoc-default 'name source
))
1880 (candidate-cache (assoc name anything-candidate-cache
)))
1881 (cond (candidate-cache
1882 (anything-log "use cached candidates")
1883 (cdr candidate-cache
))
1885 (anything-log "calculate candidates")
1886 (let ((candidates (anything-get-candidates source
)))
1887 (cond ((processp candidates
)
1888 (push (cons candidates
1890 (list (cons 'item-count
0)
1891 (cons 'incomplete-line
""))))
1892 anything-async-processes
)
1893 (set-process-filter candidates
'anything-output-filter
)
1894 (setq candidates nil
))
1895 ((not (assoc 'volatile source
))
1896 (setq candidate-cache
(cons name candidates
))
1897 (push candidate-cache anything-candidate-cache
)))
1900 ;;; (@* "Core: candidate transformers")
1901 (defun anything-process-candidate-transformer (candidates source
)
1902 (anything-aif (assoc-default 'candidate-transformer source
)
1903 (anything-composed-funcall-with-source source it candidates
)
1905 (defun anything-process-filtered-candidate-transformer (candidates source
)
1906 (anything-aif (assoc-default 'filtered-candidate-transformer source
)
1907 (anything-composed-funcall-with-source source it candidates source
)
1909 (defun anything-process-filtered-candidate-transformer-maybe (candidates source process-p
)
1911 (anything-process-filtered-candidate-transformer candidates source
)
1913 (defun anything-process-real-to-display (candidates source
)
1914 (anything-aif (assoc-default 'real-to-display source
)
1915 (setq candidates
(anything-funcall-with-source
1919 ;; override DISPLAY from candidate-transformer
1920 (cons (funcall it
(cdr cand_
)) (cdr cand_
))
1921 (cons (funcall it cand_
) cand_
)))
1924 (defun anything-transform-candidates (candidates source
&optional process-p
)
1925 "Transform CANDIDATES according to candidate transformers."
1926 (anything-process-real-to-display
1927 (anything-process-filtered-candidate-transformer-maybe
1928 (anything-process-candidate-transformer candidates source
) source process-p
)
1932 ;; (@* "Core: narrowing candidates")
1933 (defun anything-candidate-number-limit (source)
1934 "`anything-candidate-number-limit' variable may be overridden by SOURCE.
1935 If (candidate-number-limit) is in SOURCE, show all candidates in SOURCE,
1936 ie. cancel the effect of `anything-candidate-number-limit'."
1937 (anything-aif (assq 'candidate-number-limit source
)
1938 (or (cdr it
) 99999999)
1939 (or anything-candidate-number-limit
99999999)))
1941 (defconst anything-default-match-functions
1942 (list (lambda (candidate)
1943 (string-match anything-pattern candidate
))))
1945 (defun anything-compute-matches (source)
1946 "Compute matches from SOURCE according to its settings."
1948 (anything-compute-matches-internal source
)
1950 (anything-compute-matches-internal source
)
1951 (error (anything-log-error
1952 "anything-compute-matches: error when processing source: %s"
1953 (assoc-default 'name source
))
1956 (defun anything-candidate-get-display (candidate)
1957 "Get display part (searched) from CANDIDATE.
1958 CANDIDATE is a string, a symbol, or (DISPLAY . REAL) cons cell."
1959 (format "%s" (or (car-safe candidate
) candidate
)))
1961 (defun anything-process-pattern-transformer (pattern source
)
1962 (anything-aif (assoc-default 'pattern-transformer source
)
1963 (anything-composed-funcall-with-source source it pattern
)
1966 (defun anything-match-functions (source)
1967 (or (assoc-default 'match source
)
1968 anything-default-match-functions
))
1970 (defmacro anything-accumulate-candidates-internal
(cand newmatches hash item-count limit
)
1971 "INTERNAL: add CAND (ITEM-COUNT th match) into NEWMATCHES.
1972 Use HASH to uniq NEWMATCHES.
1973 if ITEM-COUNT reaches LIMIT, exit from inner loop."
1974 `(unless (gethash ,cand
,hash
)
1975 (puthash ,cand t
,hash
)
1976 (push ,cand
,newmatches
)
1978 (when (= ,item-count
,limit
)
1982 (defun anything-take-first-elements (seq n
)
1983 (if (> (length seq
) n
)
1984 (setq seq
(subseq seq
0 n
))
1987 (defun anything-match-from-candidates (cands matchfns limit
)
1990 (let ((item-count 0) exit
)
1991 (clrhash anything-match-hash
)
1992 (dolist (match matchfns
)
1994 (dolist (candidate cands
)
1995 (when (funcall match
(anything-candidate-get-display candidate
))
1996 (anything-accumulate-candidates-internal
1997 candidate newmatches anything-match-hash item-count limit
)))
1998 (setq matches
(append matches
(reverse newmatches
)))
1999 (if exit
(return)))))
2000 (invalid-regexp (setq matches nil
)))
2003 (defun anything-compute-matches-internal (source)
2004 (let ((matchfns (anything-match-functions source
))
2005 (anything-source-name (assoc-default 'name source
))
2006 (limit (anything-candidate-number-limit source
))
2007 (anything-pattern (anything-process-pattern-transformer
2008 anything-pattern source
)))
2009 (anything-process-filtered-candidate-transformer
2010 (if (or (equal anything-pattern
"") (equal matchfns
'(identity)))
2011 (anything-take-first-elements
2012 (anything-get-cached-candidates source
) limit
)
2013 (anything-match-from-candidates
2014 (anything-get-cached-candidates source
) matchfns limit
))
2017 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2019 (defun anything-process-source (source)
2020 "Display matches from SOURCE according to its settings."
2021 (anything-log-eval (assoc-default 'name source
))
2022 (if (assq 'direct-insert-match source
) ;experimental
2023 (anything-process-source--direct-insert-match source
)
2024 (let ((matches (anything-compute-matches source
)))
2026 (when anything-test-mode
2027 (setq anything-test-candidate-list
2028 `(,@anything-test-candidate-list
2029 (,(assoc-default 'name source
)
2031 (anything-insert-header-from-source source
)
2032 (if (not (assq 'multiline source
))
2033 (mapc 'anything-insert-match-with-digit-overlay matches
)
2034 (let ((start (point)) separate
)
2035 (dolist (match matches
)
2037 (anything-insert-candidate-separator)
2039 (anything-insert-match-with-digit-overlay match
))
2040 (put-text-property start
(point) 'anything-multiline t
)))))))
2042 (defun anything-insert-match-with-digit-overlay (match)
2043 (declare (special source
))
2044 (anything-put-digit-overlay-maybe)
2045 (anything-insert-match match
'insert source
))
2047 (defun anything-put-digit-overlay-maybe ()
2048 (when (and anything-enable-shortcuts
2049 (not (eq anything-digit-shortcut-count
2050 (length anything-digit-overlays
))))
2051 (move-overlay (nth anything-digit-shortcut-count
2052 anything-digit-overlays
)
2055 (incf anything-digit-shortcut-count
)))
2057 (defun anything-process-source--direct-insert-match (source)
2058 "[EXPERIMENTAL] Insert candidates from `anything-candidate-buffer'"
2059 (anything-log-eval (assoc-default 'name source
))
2060 (let ((anything-source-name (assoc-default 'name source
))
2062 (funcall (assoc-default 'candidates source
))
2063 (setq content-buf
(anything-candidate-buffer))
2064 (unless (anything-empty-buffer-p content-buf
)
2065 (anything-insert-header-from-source source
)
2066 (insert-buffer-substring content-buf
)
2067 ;; TODO call anything-put-digit-overlay-maybe with loop
2070 (defun anything-process-delayed-sources (delayed-sources)
2071 "Process delayed sources if the user is idle for
2072 `anything-idle-delay' seconds."
2073 (with-anything-quittable
2074 (anything-log-eval (mapcar (lambda (s) (assoc-default 'name s
)) delayed-sources
))
2075 (with-current-buffer anything-buffer
2077 (goto-char (point-max))
2078 (mapc 'anything-process-source delayed-sources
)
2079 (when (and (not (anything-empty-buffer-p))
2081 (= (overlay-start anything-selection-overlay
)
2082 (overlay-end anything-selection-overlay
)))
2083 (goto-char (point-min))
2084 (anything-next-line)))
2086 (goto-char (point-min))
2087 (anything-log-run-hook 'anything-update-hook
))
2088 (anything-maybe-fit-frame))))
2090 ;; (@* "Core: *anything* buffer contents")
2091 (defvar anything-input-local nil
)
2092 (defvar anything-process-delayed-sources-timer nil
)
2093 (defun anything-update ()
2094 "Update the list of matches in the anything buffer according to
2095 the current pattern."
2096 (anything-log "start update")
2097 (setq anything-digit-shortcut-count
0)
2098 (anything-kill-async-processes)
2099 (with-current-buffer (anything-buffer-get)
2100 (set (make-local-variable 'anything-input-local
) anything-pattern
)
2102 (when anything-enable-shortcuts
2103 (mapc 'delete-overlay anything-digit-overlays
))
2104 (let (delayed-sources)
2106 (setq delayed-sources
2107 (loop for source in
(remove-if-not 'anything-update-source-p
2108 (anything-get-sources))
2109 if
(anything-delayed-source-p source
)
2111 else do
(anything-process-source source
)))
2113 (mapcar (lambda (s) (assoc-default 'name s
)) delayed-sources
))
2114 (anything-update-move-first-line)
2115 (if anything-test-mode
2116 (mapc 'anything-process-source delayed-sources
)
2117 (anything-maybe-fit-frame)
2118 (when delayed-sources
2120 'anything-process-delayed-sources-timer
2121 (run-with-idle-timer
2122 anything-idle-delay nil
2123 'anything-process-delayed-sources delayed-sources
)))
2124 ;; FIXME I want to execute anything-after-update-hook
2125 ;; AFTER processing delayed sources
2126 (anything-log-run-hook 'anything-after-update-hook
))
2127 (anything-log "end update")))))
2129 (defun anything-update-source-p (source)
2130 (and (or (not anything-source-filter
)
2131 (member (assoc-default 'name source
) anything-source-filter
))
2132 (>= (length anything-pattern
)
2133 (anything-aif (assoc 'requires-pattern source
)
2136 (defun anything-delayed-source-p (source)
2137 (or (assoc 'delayed source
)
2138 (and anything-quick-update
2139 (< (window-height (get-buffer-window (current-buffer)))
2140 (line-number-at-pos (point-max))))))
2142 (defun anything-update-move-first-line ()
2143 (goto-char (point-min))
2144 (save-excursion (anything-log-run-hook 'anything-update-hook
))
2145 (anything-next-line))
2147 (defun anything-force-update ()
2148 "Recalculate and update candidates.
2149 If current source has `update' attribute, a function without argument, call it before update."
2151 (let ((source (anything-get-current-source)))
2153 (anything-force-update--reinit source
)
2154 (anything-erase-message)
2155 (mapc 'anything-force-update--reinit
(anything-get-sources)))
2156 (let ((selection (anything-get-selection nil t
)))
2158 (anything-keep-selection source selection
))))
2160 (defun anything-force-update--reinit (source)
2161 (anything-aif (anything-funcall-with-source source
'anything-candidate-buffer
)
2163 (dolist (attr '(update init
))
2164 (anything-aif (assoc-default attr source
)
2165 (anything-funcall-with-source source it
)))
2166 (anything-remove-candidate-cache source
))
2168 (defun anything-erase-message ()
2171 (defun anything-keep-selection (source selection
)
2172 (when (and source selection
)
2173 (with-anything-window
2174 (anything-goto-source source
)
2175 (forward-char -
1) ;back to \n
2176 (if (search-forward (concat "\n" selection
"\n") nil t
)
2178 (goto-char (point-min))
2180 (anything-mark-current-line))))
2182 (defun anything-remove-candidate-cache (source)
2183 (setq anything-candidate-cache
2184 (delete (assoc (assoc-default 'name source
) anything-candidate-cache
)
2185 anything-candidate-cache
)))
2187 (defun anything-insert-match (match insert-function source
)
2188 "Insert MATCH into the anything buffer. If MATCH is a list then
2189 insert the string inteneded to appear on the display and store
2190 the real value in a text property."
2191 (let ((start (point-at-bol (point)))
2192 (string (or (car-safe match
) match
))
2193 (realvalue (cdr-safe match
)))
2194 (when (symbolp string
) (setq string
(symbol-name string
)))
2195 (when (stringp string
)
2196 (funcall insert-function string
)
2197 ;; Some sources with candidates-in-buffer have already added
2198 ;; 'anything-realvalue property when creating candidate buffer.
2199 (unless (get-text-property start
'anything-realvalue
)
2201 (put-text-property start
(point-at-eol)
2202 'anything-realvalue realvalue
)))
2203 (when anything-source-in-each-line-flag
2204 (put-text-property start
(point-at-eol) 'anything-source source
))
2205 (funcall insert-function
"\n"))))
2207 (defun anything-insert-header-from-source (source)
2208 (let ((name (assoc-default 'name source
)))
2209 (anything-insert-header
2211 (anything-aif (assoc-default 'header-name source
)
2212 (anything-funcall-with-source source it name
)))))
2214 (defun anything-insert-header (name &optional display-string
)
2215 "Insert header of source NAME into the anything buffer."
2217 (let ((start (point)))
2219 (put-text-property start
(point) 'anything-header-separator t
)))
2221 (let ((start (point)))
2223 (put-text-property (point-at-bol)
2224 (point-at-eol) 'anything-header t
)
2225 (when display-string
2226 (overlay-put (make-overlay (point-at-bol) (point-at-eol))
2227 'display display-string
))
2229 (put-text-property start
(point) 'face anything-header-face
)))
2232 (defun anything-insert-candidate-separator ()
2233 "Insert separator of candidates into the anything buffer."
2234 (insert anything-candidate-separator
)
2235 (put-text-property (point-at-bol)
2236 (point-at-eol) 'anything-candidate-separator t
)
2242 ;; (@* "Core: async process")
2243 (defun anything-output-filter (process string
)
2244 "Process output from PROCESS."
2245 (anything-output-filter-1 (assoc process anything-async-processes
) string
))
2247 (defun anything-output-filter-1 (process-assoc string
)
2248 (anything-log-eval string
)
2249 (with-current-buffer anything-buffer
2250 (let ((source (cdr process-assoc
)))
2252 (anything-aif (assoc-default 'insertion-marker source
)
2254 (goto-char (point-max))
2255 (anything-insert-header-from-source source
)
2256 (setcdr process-assoc
2257 (append source
`((insertion-marker .
,(point-marker))))))
2258 (anything-output-filter--process-source
2259 (car process-assoc
) string source
2260 (anything-candidate-number-limit source
))))
2261 (anything-output-filter--post-process)))
2263 (defun anything-output-filter--process-source (process string source limit
)
2264 (dolist (candidate (anything-transform-candidates
2265 (anything-output-filter--collect-candidates
2266 (split-string string
"\n")
2267 (assoc 'incomplete-line source
))
2269 (if (not (assq 'multiline source
))
2270 (anything-insert-match candidate
'insert-before-markers source
)
2271 (let ((start (point)))
2272 (anything-insert-candidate-separator)
2273 (anything-insert-match candidate
'insert-before-markers source
)
2274 (put-text-property start
(point) 'anything-multiline t
)))
2275 (incf (cdr (assoc 'item-count source
)))
2276 (when (>= (assoc-default 'item-count source
) limit
)
2277 (anything-kill-async-process process
)
2280 (defun anything-output-filter--collect-candidates (lines incomplete-line-info
)
2281 (anything-log-eval (cdr incomplete-line-info
))
2283 (loop for line in lines collect
2284 (if (cdr incomplete-line-info
)
2286 (concat (cdr incomplete-line-info
) line
)
2287 (setcdr incomplete-line-info nil
))
2289 finally
(setcdr incomplete-line-info line
))))
2291 (defun anything-output-filter--post-process ()
2292 (anything-maybe-fit-frame)
2293 (anything-log-run-hook 'anything-update-hook
)
2294 (save-selected-window
2295 (select-window (get-buffer-window anything-buffer
'visible
))
2296 (anything-skip-noncandidate-line 'next
)
2297 (anything-mark-current-line)))
2300 (defun anything-kill-async-processes ()
2301 "Kill all known asynchronous processes according to
2302 `anything-async-processes'."
2303 "Kill locate process."
2304 (mapc 'anything-kill-async-process
(mapcar 'car anything-async-processes
))
2305 (setq anything-async-processes nil
))
2308 (defun anything-kill-async-process (process)
2309 "Kill PROCESS and detach the associated functions."
2310 (set-process-filter process nil
)
2311 (delete-process process
))
2314 ;; (@* "Core: action")
2315 (defun anything-execute-selection-action (&optional selection action preserve-saved-action
)
2316 "If a candidate was selected then perform the associated
2318 (anything-log "executing action")
2319 (setq action
(anything-get-default-action
2321 anything-saved-action
2322 (if (get-buffer anything-action-buffer
)
2323 (anything-get-selection anything-action-buffer
)
2324 (anything-get-action)))))
2325 (let ((source (or anything-saved-current-source
(anything-get-current-source))))
2326 (setq selection
(or selection
2327 (anything-get-selection)
2328 (and (assoc 'accept-empty source
) "")))
2329 (unless preserve-saved-action
(setq anything-saved-action nil
))
2330 (if (and selection action
)
2331 (anything-funcall-with-source
2333 (anything-coerce-selection selection source
)))))
2335 (defun anything-coerce-selection (selection source
)
2336 "Coerce source with coerce function."
2337 (anything-aif (assoc-default 'coerce source
)
2338 (anything-funcall-with-source source it selection
)
2341 (defun anything-get-default-action (action)
2342 (if (and (listp action
) (not (functionp action
)))
2346 (defun anything-select-action ()
2347 "Select an action for the currently selected candidate.
2348 If action buffer is selected, back to the anything buffer."
2350 (cond ((get-buffer-window anything-action-buffer
'visible
)
2351 (set-window-buffer (get-buffer-window anything-action-buffer
)
2353 (kill-buffer anything-action-buffer
)
2354 (anything-set-pattern anything-input
'noupdate
))
2356 (setq anything-saved-selection
(anything-get-selection))
2357 (unless anything-saved-selection
2358 (error "Nothing is selected."))
2359 (setq anything-saved-current-source
(anything-get-current-source))
2360 (let ((actions (anything-get-action)))
2361 (if (functionp actions
)
2362 (message "Sole action: %s" actions
)
2363 (anything-show-action-buffer actions
)
2364 (anything-delete-minibuffer-contents)
2365 (setq anything-pattern
'dummy
) ; so that it differs from the previous one
2366 (anything-check-minibuffer-input))))))
2368 (defun anything-show-action-buffer (actions)
2369 (with-current-buffer (get-buffer-create anything-action-buffer
)
2371 (buffer-disable-undo)
2372 (set-window-buffer (get-buffer-window anything-buffer
) anything-action-buffer
)
2373 (set (make-local-variable 'anything-sources
)
2374 `(((name .
"Actions")
2376 (candidates .
,actions
)
2377 (candidate-number-limit))))
2378 (set (make-local-variable 'anything-source-filter
) nil
)
2379 (set (make-local-variable 'anything-selection-overlay
) nil
)
2380 (set (make-local-variable 'anything-digit-overlays
) nil
)
2381 (anything-initialize-overlays anything-action-buffer
)))
2383 ;; (@* "Core: selection")
2384 (defun anything-move-selection-common (move-func unit direction
)
2385 "Move the selection marker to a new position determined by
2386 UNIT and DIRECTION."
2387 (unless (or (anything-empty-buffer-p (anything-buffer-get))
2388 (not (anything-window)))
2389 (with-anything-window
2391 (anything-skip-noncandidate-line direction
)
2392 (anything-display-source-at-screen-top-maybe unit
)
2393 (when (anything-get-previous-header-pos)
2394 (anything-mark-current-line))
2395 (anything-display-mode-line (anything-get-current-source)))))
2397 (defun anything-display-source-at-screen-top-maybe (unit)
2398 (when (and anything-display-source-at-screen-top
(eq unit
'source
))
2399 (set-window-start (selected-window)
2400 (save-excursion (forward-line -
1) (point)))))
2402 (defun anything-skip-noncandidate-line (direction)
2403 (anything-skip-header-and-separator-line direction
)
2404 (and (bobp) (forward-line 1)) ;skip first header
2405 (and (eobp) (forward-line -
1)) ;avoid last empty line
2408 (defun anything-skip-header-and-separator-line (direction)
2409 (while (and (not (bobp))
2410 (or (anything-pos-header-line-p)
2411 (anything-pos-candidate-separator-p)))
2412 (forward-line (if (and (eq direction
'previous
)
2413 (not (eq (point-at-bol) (point-min))))
2417 (defvar anything-mode-line-string-real nil
)
2418 (defun anything-display-mode-line (source)
2419 (set (make-local-variable 'anything-mode-line-string
)
2420 (anything-interpret-value (or (assoc-default 'mode-line source
)
2421 (default-value 'anything-mode-line-string
))
2423 (if anything-mode-line-string
2424 (setq mode-line-format
2425 '(" " mode-line-buffer-identification
" "
2426 (line-number-mode "%l") " " (anything-follow-mode "(F)")
2427 " " anything-mode-line-string-real
"-%-")
2428 anything-mode-line-string-real
2429 (substitute-command-keys anything-mode-line-string
))
2430 (setq mode-line-format
2431 (default-value 'mode-line-format
)))
2432 (setq header-line-format
2433 (anything-interpret-value (assoc-default 'header-line source
) source
)))
2435 (defun anything-previous-line ()
2436 "Move selection to the previous line."
2438 (anything-move-selection-common
2440 (if (not (anything-pos-multiline-p))
2441 (forward-line -
1) ;double forward-line is meaningful
2442 (forward-line -
1) ;because evaluation order is important
2443 (anything-skip-header-and-separator-line 'previous
)
2444 (let ((header-pos (anything-get-previous-header-pos))
2445 (separator-pos (anything-get-previous-candidate-separator-pos)))
2447 (goto-char (if (or (null separator-pos
) (< separator-pos header-pos
))
2448 header-pos
; first candidate
2450 (forward-line 1)))))
2453 (defun anything-next-line ()
2454 "Move selection to the next line."
2456 (anything-move-selection-common
2458 (if (not (anything-pos-multiline-p))
2460 (let ((header-pos (anything-get-next-header-pos))
2461 (separator-pos (anything-get-next-candidate-separator-pos)))
2462 (cond ((and separator-pos
2463 (or (null header-pos
) (< separator-pos header-pos
)))
2464 (goto-char separator-pos
))
2466 (goto-char header-pos
))))))
2469 (defun anything-previous-page ()
2470 "Move selection back with a pageful."
2472 (anything-move-selection-common
2476 (beginning-of-buffer (goto-char (point-min)))))
2479 (defun anything-next-page ()
2480 "Move selection forward with a pageful."
2482 (anything-move-selection-common
2486 (end-of-buffer (goto-char (point-max)))))
2489 (defun anything-beginning-of-buffer ()
2490 "Move selection at the top."
2492 (anything-move-selection-common (lambda () (goto-char (point-min)))
2495 (defun anything-end-of-buffer ()
2496 "Move selection at the bottom."
2498 (anything-move-selection-common (lambda () (goto-char (point-max)))
2501 (defun anything-previous-source ()
2502 "Move selection to the previous source."
2504 (anything-move-selection-common
2508 (goto-char (point-max))
2509 (anything-skip-header-and-separator-line 'previous
))
2510 (goto-char (anything-get-previous-header-pos))
2514 (defun anything-next-source ()
2515 "Move selection to the next source."
2517 (anything-move-selection-common
2518 (lambda () (goto-char (or (anything-get-next-header-pos) (point-min))))
2521 (defun anything-goto-source (source-or-name)
2522 "Move the selection to the source (SOURCE-OR-NAME)."
2523 (anything-move-selection-common
2525 (goto-char (point-min))
2526 (let ((name (if (stringp source-or-name
) source-or-name
2527 (assoc-default 'name source-or-name
))))
2529 (while (not (string= name
(anything-current-line-contents)))
2530 (goto-char (anything-get-next-header-pos)))
2531 (error (message "")))))
2534 (defun anything-mark-current-line ()
2535 "Move selection overlay to current line."
2537 anything-selection-overlay
(point-at-bol)
2538 (if (anything-pos-multiline-p)
2539 (let ((header-pos (anything-get-next-header-pos))
2540 (separator-pos (anything-get-next-candidate-separator-pos)))
2541 (or (and (null header-pos
) separator-pos
)
2542 (and header-pos separator-pos
(< separator-pos header-pos
)
2546 (1+ (point-at-eol))))
2547 (anything-follow-execute-persistent-action-maybe))
2549 (defun anything-this-command-key ()
2550 (event-basic-type (elt (this-command-keys-vector) 0)))
2551 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
2553 (defun anything-select-with-shortcut-internal (types get-key-func
)
2554 (if (memq anything-enable-shortcuts types
)
2555 (save-selected-window
2556 (select-window (anything-window))
2557 (let* ((key (funcall get-key-func
))
2558 (overlay (ignore-errors (nth (position key anything-shortcut-keys
)
2559 anything-digit-overlays
))))
2560 (if (not (and overlay
(overlay-buffer overlay
)))
2562 (select-window (minibuffer-window))
2563 (self-insert-command 1))
2564 (goto-char (overlay-start overlay
))
2565 (anything-mark-current-line)
2566 (anything-exit-minibuffer))))
2567 (self-insert-command 1)))
2569 (defun anything-select-with-prefix-shortcut ()
2570 "Invoke default action with prefix shortcut."
2572 (anything-select-with-shortcut-internal
2574 (lambda () (read-event "Select shortcut key: "))))
2576 (defun anything-select-with-digit-shortcut ()
2577 "Invoke default action with digit/alphabet shortcut."
2579 (anything-select-with-shortcut-internal
2580 '(alphabet t
) 'anything-this-command-key
))
2582 ;; (setq anything-enable-shortcuts 'prefix)
2583 ;; (define-key anything-map "@" 'anything-select-with-prefix-shortcut)
2584 ;; (define-key anything-map (kbd "<f18>") 'anything-select-with-prefix-shortcut)
2586 (defun anything-exit-minibuffer ()
2587 "Select the current candidate by exiting the minibuffer."
2589 (declare (special anything-iswitchb-candidate-selected
))
2590 (setq anything-iswitchb-candidate-selected
(anything-get-selection))
2594 (defun anything-get-next-header-pos ()
2595 "Return the position of the next header from point."
2596 (next-single-property-change (point) 'anything-header
))
2599 (defun anything-get-previous-header-pos ()
2600 "Return the position of the previous header from point"
2601 (previous-single-property-change (point) 'anything-header
))
2604 (defun anything-pos-multiline-p ()
2605 "Return non-nil if the current position is in the multiline source region."
2606 (get-text-property (point) 'anything-multiline
))
2609 (defun anything-get-next-candidate-separator-pos ()
2610 "Return the position of the next candidate separator from point."
2611 (next-single-property-change (point) 'anything-candidate-separator
))
2614 (defun anything-get-previous-candidate-separator-pos ()
2615 "Return the position of the previous candidate separator from point."
2616 (previous-single-property-change (point) 'anything-candidate-separator
))
2619 (defun anything-pos-header-line-p ()
2620 "Return t if the current line is a header line."
2621 (or (get-text-property (point-at-bol) 'anything-header
)
2622 (get-text-property (point-at-bol) 'anything-header-separator
)))
2624 (defun anything-pos-candidate-separator-p ()
2625 "Return t if the current line is a candidate separator."
2626 (get-text-property (point-at-bol) 'anything-candidate-separator
))
2628 ;; (@* "Core: help")
2629 (defun anything-help-internal (bufname insert-content-fn
)
2630 "Show long message during `anything' session."
2631 (save-window-excursion
2632 (select-window (anything-window))
2633 (delete-other-windows)
2634 (switch-to-buffer (get-buffer-create bufname
))
2636 (funcall insert-content-fn
)
2637 (setq mode-line-format
"%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
2638 (setq cursor-type nil
)
2640 (anything-help-event-loop)))
2642 (defun anything-help-event-loop ()
2644 (loop for event
= (read-event) do
2646 ((?\C-v ?
) (scroll-up))
2647 ((?\M-v ?b
) (scroll-down))
2650 (defun anything-help ()
2651 "Help of `anything'."
2653 (anything-help-internal
2656 (insert (substitute-command-keys
2657 (anything-interpret-value anything-help-message
)))
2660 (defun anything-debug-output ()
2661 "Show all anything-related variables at this time."
2663 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function
))
2665 (defun anything-debug-output-function (&optional vars
)
2666 (message "Calculating all anything-related values...")
2667 (insert "If you debug some variables or forms, set `anything-debug-forms'
2668 to a list of forms.\n\n")
2670 anything-debug-forms
2671 (apropos-internal "^anything-" 'boundp
)))
2673 (pp-to-string v
) "\n"
2674 (pp-to-string (eval v
)) "\n"))
2675 (message "Calculating all anything-related values...Done"))
2677 ;; (@* "Core: misc")
2678 (defun anything-kill-buffer-hook ()
2679 "Remove tick entry from `anything-tick-hash' when killing a buffer."
2680 (loop for key being the hash-keys in anything-tick-hash
2681 if
(string-match (format "^%s/" (regexp-quote (buffer-name))) key
)
2682 do
(remhash key anything-tick-hash
)))
2683 (add-hook 'kill-buffer-hook
'anything-kill-buffer-hook
)
2685 (defun anything-maybe-fit-frame ()
2686 "Fit anything frame to its buffer, and put it at top right of display.
2688 It is disabled by default because some flickering occurred in some environment.
2689 To enable fitting, set both `anything-inhibit-fit-frame-flag' and
2690 `fit-frame-inhibit-fitting' to nil.
2691 You can set user options `fit-frame-max-width-percent' and
2692 `fit-frame-max-height-percent' to control max frame size."
2693 (declare (warn (unresolved 0)))
2694 (when (and (not anything-inhibit-fit-frame-flag
)
2696 (require 'fit-frame nil t
)
2697 (boundp 'fit-frame-inhibit-fitting-flag
)
2698 (not fit-frame-inhibit-fitting-flag
))
2700 (with-anything-window
2701 (fit-frame nil nil nil t
)
2702 (modify-frame-parameters
2704 `((left .
,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
2705 (top .
0))))))) ; The (top . 0) shouldn't be necessary (Emacs bug).
2707 (defun anything-preselect (candidate-or-regexp)
2708 (with-anything-window
2709 (when candidate-or-regexp
2710 (goto-char (point-min))
2711 ;; go to first candidate of first source
2713 (let ((start (point)))
2714 (unless (or (re-search-forward
2715 (concat "^" (regexp-quote candidate-or-regexp
) "$")
2717 (progn (goto-char start
)
2718 (re-search-forward candidate-or-regexp nil t
)))
2719 (goto-char start
))))
2720 (anything-mark-current-line)))
2722 (defun anything-delete-current-selection ()
2723 "Delete the currently selected item."
2725 (with-anything-window
2726 (cond ((anything-pos-multiline-p)
2727 (anything-aif (anything-get-next-candidate-separator-pos)
2728 (delete-region (point-at-bol)
2729 (1+ (progn (goto-char it
) (point-at-eol))))
2731 (goto-char (anything-get-previous-candidate-separator-pos))
2732 (delete-region (point-at-bol) (point-max)))
2734 (goto-char (or (anything-get-previous-candidate-separator-pos)
2738 (delete-region (point-at-bol) (1+ (point-at-eol)))
2739 (when (eobp) (forward-line -
1))))
2740 (anything-mark-current-line)))
2742 (defun anything-edit-current-selection-internal (func)
2743 (with-anything-window
2745 (let ((realvalue (get-text-property (point) 'anything-realvalue
)))
2749 (put-text-property (point) (point-at-eol)
2750 'anything-realvalue realvalue
))
2751 (anything-mark-current-line))))
2753 (defmacro anything-edit-current-selection
(&rest forms
)
2754 "Evaluate FORMS at current selection in the anything buffer.
2755 You can edit the line."
2756 `(anything-edit-current-selection-internal
2757 (lambda () ,@forms
)))
2758 (put 'anything-edit-current-selection
'lisp-indent-function
0)
2760 (defun anything-set-pattern (pattern &optional noupdate
)
2761 "Set minibuffer contents to PATTERN.
2762 if optional NOUPDATE is non-nil, anything buffer is not changed."
2763 (with-selected-window (minibuffer-window)
2764 (delete-minibuffer-contents)
2767 (setq anything-pattern pattern
)
2768 (anything-hooks 'cleanup
)
2769 (run-with-idle-timer 0 nil
'anything-hooks
'setup
)))
2771 (defun anything-delete-minibuffer-contents ()
2772 "Same as `delete-minibuffer-contents' but this is a command."
2774 (anything-set-pattern ""))
2775 (defalias 'anything-delete-minibuffer-content
'anything-delete-minibuffer-contents
)
2777 ;; (@* "Built-in plug-in: type")
2778 (defun anything-compile-source--type (source)
2779 (anything-aif (assoc-default 'type source
)
2780 (append source
(assoc-default it anything-type-attributes
) nil
)
2783 ;; `define-anything-type-attribute' is public API.
2785 (defun anything-add-type-attribute (type definition
)
2786 (anything-aif (assq type anything-type-attributes
)
2787 (setq anything-type-attributes
(delete it anything-type-attributes
)))
2788 (push (cons type definition
) anything-type-attributes
))
2790 (defvar anything-types nil
)
2791 (defun anything-document-type-attribute (type doc
)
2792 (add-to-list 'anything-types type t
)
2793 (put type
'anything-typeattrdoc
2794 (concat "- " (symbol-name type
) "\n\n" doc
"\n")))
2796 (defadvice documentation-property
(after anything-document-type-attribute activate
)
2797 "Hack to display type attributes' documentation as `anything-type-attributes' docstring."
2798 (when (eq symbol
'anything-type-attributes
)
2799 (setq ad-return-value
2800 (concat ad-return-value
"\n\n++++ Types currently defined ++++\n"
2801 (mapconcat (lambda (sym) (get sym
'anything-typeattrdoc
))
2802 anything-types
"\n")))))
2804 ;; (@* "Built-in plug-in: dummy")
2805 (defun anything-dummy-candidate (candidate source
)
2806 ;; `source' is defined in filtered-candidate-transformer
2807 (list anything-pattern
))
2809 (defun anything-compile-source--dummy (source)
2810 (if (assoc 'dummy source
)
2812 '((candidates "dummy")
2815 (filtered-candidate-transformer . anything-dummy-candidate
)
2820 ;; (@* "Built-in plug-in: disable-shortcuts")
2821 (defvar anything-orig-enable-shortcuts nil
)
2822 (defun anything-save-enable-shortcuts ()
2824 (lambda () (setq anything-orig-enable-shortcuts anything-enable-shortcuts
2825 anything-enable-shortcuts nil
))))
2826 (defun anything-compile-source--disable-shortcuts (source)
2827 (if (assoc 'disable-shortcuts source
)
2828 (append `((init ,@(anything-mklist (assoc-default 'init source
))
2829 anything-save-enable-shortcuts
)
2830 (resume ,@(anything-mklist (assoc-default 'resume source
))
2831 anything-save-enable-shortcuts
)
2832 (cleanup ,@(anything-mklist (assoc-default 'cleanup source
))
2833 (lambda () (setq anything-enable-shortcuts
2834 anything-orig-enable-shortcuts
))))
2838 ;; (@* "Built-in plug-in: candidates-in-buffer")
2839 (defun anything-candidates-in-buffer ()
2840 "Get candidates from the candidates buffer according to `anything-pattern'.
2842 BUFFER is `anything-candidate-buffer' by default. Each
2843 candidate must be placed in one line. This function is meant to
2844 be used in candidates-in-buffer or candidates attribute of an
2845 anything source. Especially fast for many (1000+) candidates.
2848 '((name . \"many files\")
2849 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
2850 (insert-many-filenames))))
2851 (search re-search-forward) ; optional
2852 (candidates-in-buffer)
2855 +===============================================================+
2856 | The new way of making and narrowing candidates: Using buffers |
2857 +===============================================================+
2859 By default, `anything' makes candidates by evaluating the
2860 candidates function, then narrows them by `string-match' for each
2863 But this way is very slow for many candidates. The new way is
2864 storing all candidates in a buffer and narrowing them by
2865 `re-search-forward'. Search function is customizable by search
2866 attribute. The important point is that buffer processing is MUCH
2867 FASTER than string list processing and is the Emacs way.
2869 The init function writes all candidates to a newly-created
2870 candidate buffer. The candidates buffer is created or specified
2871 by `anything-candidate-buffer'. Candidates are stored in a line.
2873 The candidates function narrows all candidates, IOW creates a
2874 subset of candidates dynamically. It is the task of
2875 `anything-candidates-in-buffer'. As long as
2876 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
2877 sufficient in most cases.
2879 Note that `(candidates-in-buffer)' is shortcut of three attributes:
2880 (candidates . anything-candidates-in-buffer)
2883 And `(candidates-in-buffer . func)' is shortcut of three attributes:
2887 The expansion is performed in `anything-get-sources'.
2889 The candidates-in-buffer attribute implies the volatile attribute.
2890 The volatile attribute is needed because `anything-candidates-in-buffer'
2891 creates candidates dynamically and need to be called everytime
2892 `anything-pattern' changes.
2894 Because `anything-candidates-in-buffer' plays the role of `match' attribute
2895 function, specifying `(match identity)' makes the source slightly faster.
2897 To customize `anything-candidates-in-buffer' behavior, use search,
2898 get-line and search-from-end attributes. See also `anything-sources' docstring.
2900 (declare (special source
))
2901 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
2903 (or (assoc-default 'get-line source
)
2904 #'buffer-substring-no-properties
)
2905 ;; use external variable `source'.
2906 (or (assoc-default 'search source
)
2907 (if (assoc 'search-from-end source
)
2908 '(re-search-backward)
2909 '(re-search-forward)))
2910 (anything-candidate-number-limit source
)
2911 (assoc 'search-from-end source
)))
2913 (defun anything-candidates-in-buffer-1 (buffer pattern get-line-fn search-fns limit search-from-end
)
2914 ;; buffer == nil when candidates buffer does not exist.
2916 (with-current-buffer buffer
2917 (let ((start-point (if search-from-end
(point-max) (point-min)))
2918 (endp (if search-from-end
#'bobp
#'eobp
)))
2919 (goto-char (1- start-point
))
2920 (if (string= pattern
"")
2921 (anything-initial-candidates-from-candidate-buffer
2922 endp get-line-fn limit search-from-end
)
2923 (anything-search-from-candidate-buffer
2924 pattern get-line-fn search-fns limit search-from-end
2925 start-point endp
))))))
2927 (defun anything-point-is-moved (proc)
2928 "If point is moved after executing PROC, return t, otherwise nil."
2929 (/= (point) (progn (funcall proc
) (point))))
2931 (defun anything-search-from-candidate-buffer (pattern get-line-fn search-fns
2932 limit search-from-end
2934 (let (buffer-read-only
2935 matches exit newmatches
)
2936 (anything-search-from-candidate-buffer-internal
2938 (clrhash anything-cib-hash
)
2939 (dolist (searcher search-fns
)
2940 (goto-char start-point
)
2941 (setq newmatches nil
)
2942 (loop with item-count
= 0
2943 while
(funcall searcher pattern nil t
)
2944 for cand
= (funcall get-line-fn
(point-at-bol) (point-at-eol))
2945 do
(anything-accumulate-candidates-internal
2946 cand newmatches anything-cib-hash item-count limit
)
2947 unless
(anything-point-is-moved
2950 (goto-char (1- (point-at-bol)))
2953 (setq matches
(append matches
(nreverse newmatches
)))
2955 (delq nil matches
)))))
2957 (defun anything-initial-candidates-from-candidate-buffer (endp get-line-fn limit search-from-end
)
2958 (delq nil
(loop with next-line-fn
=
2960 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
2962 until
(funcall endp
)
2963 for i from
1 to limit
2964 collect
(funcall get-line-fn
(point-at-bol) (point-at-eol))
2965 do
(funcall next-line-fn
1))))
2967 (defun anything-search-from-candidate-buffer-internal (search-fn)
2968 (goto-char (point-min))
2970 (goto-char (point-max))
2974 (goto-char (point-min))
2976 (goto-char (1- (point-max)))
2979 (set-buffer-modified-p nil
)))
2981 (defun anything-candidate-buffer (&optional create-or-buffer
)
2982 "Register and return a buffer containing candidates of current source.
2983 `anything-candidate-buffer' searches buffer-local candidates buffer first,
2984 then global candidates buffer.
2986 Acceptable values of CREATE-OR-BUFFER:
2989 Only return the candidates buffer.
2991 Register a buffer as a candidates buffer.
2993 Create a new global candidates buffer,
2994 named \" *anything candidates:SOURCE*\".
2995 - other non-nil value
2996 Create a new local candidates buffer,
2997 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
2999 (let* ((global-bname (format " *anything candidates:%s*" anything-source-name
))
3000 (local-bname (format " *anything candidates:%s*%s"
3001 anything-source-name
3002 (buffer-name anything-current-buffer
)))
3005 (setq anything-candidate-buffer-alist
3006 (cons (cons anything-source-name create-or-buffer
)
3007 (delete (assoc anything-source-name
3008 anything-candidate-buffer-alist
)
3009 anything-candidate-buffer-alist
)))))
3012 (loop for b in
(buffer-list)
3013 if
(string-match (format "^%s" (regexp-quote global-bname
))
3015 do
(kill-buffer b
))))
3018 (with-current-buffer
3019 (get-buffer-create (if (eq create-or-buffer
'global
)
3022 (buffer-disable-undo)
3024 (font-lock-mode -
1))))
3027 (or (get-buffer local-bname
)
3028 (get-buffer global-bname
)
3029 (anything-aif (assoc-default anything-source-name
3030 anything-candidate-buffer-alist
)
3031 (and (buffer-live-p it
) it
))))))
3032 (when create-or-buffer
3033 (funcall register-func
)
3034 (unless (bufferp create-or-buffer
)
3035 (and (eq create-or-buffer
'global
) (funcall kill-buffers-func
))
3036 (funcall create-func
)))
3037 (funcall return-func
)))
3039 (defun anything-compile-source--candidates-in-buffer (source)
3040 (anything-aif (assoc 'candidates-in-buffer source
)
3042 `((candidates .
,(or (cdr it
) 'anything-candidates-in-buffer
))
3043 (volatile) (match identity
)))
3046 ;; (@* "Utility: resplit anything window")
3047 (defun anything-toggle-resplit-window ()
3048 "Toggle resplit anything window, vertically or horizontally."
3050 (with-anything-window
3051 (let ((before-height (window-height)))
3054 (select-window (if (= (window-height) before-height
)
3055 (split-window-vertically)
3056 (split-window-horizontally)))
3059 ;; (@* "Utility: select another action by key")
3060 (defun anything-select-nth-action (n)
3061 "Select the nth action for the currently selected candidate."
3062 (setq anything-saved-selection
(anything-get-selection))
3063 (unless anything-saved-selection
3064 (error "Nothing is selected."))
3065 (setq anything-saved-action
(anything-get-nth-action n
(anything-get-action)))
3066 (anything-exit-minibuffer))
3068 (defun anything-get-nth-action (n action
)
3069 (cond ((and (zerop n
) (functionp action
))
3072 (or (cdr (elt action n
))
3073 (error "No such action")))
3074 ((and (functionp action
) (< 0 n
))
3075 (error "Sole action."))
3077 (error "Error in `anything-select-nth-action'."))))
3079 (defun anything-select-2nd-action ()
3080 "Select the 2nd action for the currently selected candidate."
3082 (anything-select-nth-action 1))
3084 (defun anything-select-3rd-action ()
3085 "Select the 3rd action for the currently selected candidate."
3087 (anything-select-nth-action 2))
3089 (defun anything-select-4th-action ()
3090 "Select the 4th action for the currently selected candidate."
3092 (anything-select-nth-action 3))
3094 (defun anything-select-2nd-action-or-end-of-line ()
3095 "Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
3096 Otherwise goto the end of minibuffer."
3099 (anything-select-nth-action 1)
3102 ;; (@* "Utility: Persistent Action")
3103 (defmacro with-anything-display-same-window
(&rest body
)
3104 "Make `pop-to-buffer' and `display-buffer' display in the same window."
3105 `(let ((display-buffer-function 'anything-persistent-action-display-buffer
))
3107 (put 'with-anything-display-same-window
'lisp-indent-function
0)
3109 (defvar anything-persistent-action-display-window nil
)
3110 (defun anything-initialize-persistent-action ()
3111 (set (make-local-variable 'anything-persistent-action-display-window
) nil
))
3113 (defun* anything-execute-persistent-action
(&optional
(attr 'persistent-action
))
3114 "If a candidate is selected then perform the associated action without quitting anything."
3116 (anything-log "executing persistent-action")
3117 (save-selected-window
3118 (anything-select-persistent-action-window)
3119 (anything-log-eval (current-buffer))
3120 (let ((anything-in-persistent-action t
))
3121 (with-anything-display-same-window
3122 (anything-execute-selection-action
3124 (or (assoc-default attr
(anything-get-current-source))
3125 (anything-get-action))
3127 (anything-log-run-hook 'anything-after-persistent-action-hook
)))))
3129 (defun anything-select-persistent-action-window ()
3130 (select-window (get-buffer-window (anything-buffer-get)))
3131 (select-window (setq minibuffer-scroll-window
3132 (setq anything-persistent-action-display-window
3133 (or anything-persistent-action-display-window
3134 (if anything-samewindow
3135 (if (one-window-p t
) (split-window)
3136 (next-window (selected-window) 1))
3137 (get-buffer-window anything-current-buffer
)))))))
3139 (defun anything-persistent-action-display-buffer (buf &optional not-this-window
)
3140 "Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
3141 If `anything-persistent-action-use-special-display' is non-nil and
3142 BUF is to be displayed by `special-display-function', use it.
3143 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
3144 (let* ((name (buffer-name buf
))
3145 display-buffer-function pop-up-windows
3146 (same-window-regexps
3147 (unless (and anything-persistent-action-use-special-display
3149 (mapcar (lambda (x) (or (car-safe x
) x
))
3150 special-display-buffer-names
))
3152 (lambda (x) (string-match (or (car-safe x
) x
) name
))
3153 special-display-regexps
)))
3155 (display-buffer buf not-this-window
)))
3157 ;; scroll-other-window(-down)? for persistent-action
3158 (defun anything-scroll-other-window-base (command)
3159 (save-selected-window
3162 (lambda (w) (not (string= anything-buffer
(buffer-name (window-buffer w
)))))
3163 'no-minibuffer
'current-frame
))
3164 (funcall command anything-scroll-amount
)))
3166 (defun anything-scroll-other-window ()
3167 "Scroll other window (not *Anything* window) upward."
3169 (anything-scroll-other-window-base 'scroll-up
))
3170 (defun anything-scroll-other-window-down ()
3171 "Scroll other window (not *Anything* window) downward."
3173 (anything-scroll-other-window-base 'scroll-down
))
3175 ;; (@* "Utility: Visible Mark")
3176 (defface anything-visible-mark
3177 '((((min-colors 88) (background dark
))
3178 (:background
"green1" :foreground
"black"))
3179 (((background dark
)) (:background
"green" :foreground
"black"))
3180 (((min-colors 88)) (:background
"green1"))
3181 (t (:background
"green")))
3182 "Face for visible mark."
3184 (defvar anything-visible-mark-face
'anything-visible-mark
)
3185 (defvar anything-visible-mark-overlays nil
)
3187 (defun anything-clear-visible-mark ()
3188 (with-current-buffer (anything-buffer-get)
3189 (mapc 'delete-overlay anything-visible-mark-overlays
)
3190 (set (make-local-variable 'anything-visible-mark-overlays
) nil
)))
3191 (add-hook 'anything-after-initialize-hook
'anything-clear-visible-mark
)
3193 (defvar anything-c-marked-candidate-list nil
3194 "[OBSOLETE] DO NOT USE!!")
3195 (defvar anything-marked-candidates nil
3196 "Marked candadates. List of (source . real) pair.")
3198 (defun anything-this-visible-mark ()
3199 (loop for o in anything-visible-mark-overlays
3200 when
(equal (point-at-bol) (overlay-start o
))
3203 (defun anything-delete-visible-mark (overlay)
3204 (setq anything-c-marked-candidate-list
3205 (remove (anything-current-line-contents) anything-c-marked-candidate-list
))
3206 (setq anything-marked-candidates
3208 (cons (anything-get-current-source) (anything-get-selection))
3209 anything-marked-candidates
))
3210 (delete-overlay overlay
)
3211 (setq anything-visible-mark-overlays
3212 (delq overlay anything-visible-mark-overlays
)))
3214 (defun anything-make-visible-mark ()
3215 (let ((o (make-overlay (point-at-bol) (1+ (point-at-eol)))))
3216 (overlay-put o
'face anything-visible-mark-face
)
3217 (overlay-put o
'source
(assoc-default 'name
(anything-get-current-source)))
3218 (overlay-put o
'string
(buffer-substring (overlay-start o
) (overlay-end o
)))
3219 (add-to-list 'anything-visible-mark-overlays o
))
3220 (push (anything-current-line-contents) anything-c-marked-candidate-list
)
3221 (push (cons (anything-get-current-source) (anything-get-selection))
3222 anything-marked-candidates
))
3224 (defun anything-toggle-visible-mark ()
3225 "Toggle anything visible mark at point."
3227 (with-anything-window
3228 (anything-aif (anything-this-visible-mark)
3229 (anything-delete-visible-mark it
)
3230 (anything-make-visible-mark))
3231 (anything-next-line)))
3233 (defun anything-display-all-visible-marks ()
3234 "Show all `anything' visible marks strings."
3236 (with-anything-window
3237 (lexical-let ((overlays (reverse anything-visible-mark-overlays
)))
3238 (anything-run-after-quit
3240 (with-output-to-temp-buffer "*anything visible marks*"
3241 (dolist (o overlays
) (princ (overlay-get o
'string
)))))))))
3243 (defun anything-marked-candidates ()
3244 "Marked candidates (real value) of current source if any,
3245 otherwise 1-element list of current selection.
3247 It is analogous to `dired-get-marked-files'."
3248 (with-current-buffer (anything-buffer-get)
3250 (if anything-marked-candidates
3251 (loop with current-src
= (anything-get-current-source)
3252 for
(source . real
) in
(reverse anything-marked-candidates
)
3253 when
(equal current-src source
)
3254 collect
(anything-coerce-selection real source
))
3255 (list (anything-get-selection)))))
3256 (anything-log-eval cands
)
3259 (defun anything-reset-marked-candidates ()
3260 (with-current-buffer (anything-buffer-get)
3261 (set (make-local-variable 'anything-c-marked-candidate-list
) nil
)
3262 (set (make-local-variable 'anything-marked-candidates
) nil
)))
3264 (add-hook 'anything-after-initialize-hook
'anything-reset-marked-candidates
)
3265 ;; (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3267 (defun anything-current-source-name= (name)
3269 (goto-char (anything-get-previous-header-pos))
3270 (equal name
(anything-current-line-contents))))
3272 (defun anything-revive-visible-mark ()
3273 (with-current-buffer anything-buffer
3274 (dolist (o anything-visible-mark-overlays
)
3275 (goto-char (point-min))
3276 (while (and (search-forward (overlay-get o
'string
) nil t
)
3277 (anything-current-source-name= (overlay-get o
'source
)))
3278 ;; Now the next line of visible mark
3279 (move-overlay o
(point-at-bol 0) (1+ (point-at-eol 0)))))))
3280 (add-hook 'anything-update-hook
'anything-revive-visible-mark
)
3282 (defun anything-next-point-in-list (curpos points
&optional prev
)
3284 ;; rule out special cases
3285 ((null points
) curpos
)
3286 ((and prev
(< curpos
(car points
))) curpos
)
3287 ((< (car (last points
)) curpos
)
3288 (if prev
(car (last points
)) curpos
))
3291 (loop for pt in points
3295 (loop for pt in points
3301 (defun anything-next-visible-mark (&optional prev
)
3302 "Move next anything visible mark."
3304 (with-anything-window
3305 (goto-char (anything-next-point-in-list
3307 (sort (mapcar 'overlay-start anything-visible-mark-overlays
) '<)
3309 (anything-mark-current-line)))
3311 (defun anything-prev-visible-mark ()
3312 "Move previous anything visible mark."
3314 (anything-next-visible-mark t
))
3316 ;; (@* "Utility: `find-file' integration")
3317 (defun anything-quit-and-find-file ()
3318 "Drop into `find-file' from `anything' like `iswitchb-find-file'.
3319 If current selection is a buffer or a file, `find-file' from its directory."
3321 (anything-run-after-quit
3323 (if (file-exists-p f
)
3324 (let ((default-directory (file-name-directory f
)))
3325 (call-interactively 'find-file
))
3326 (call-interactively 'find-file
)))
3327 (anything-aif (get-buffer (anything-get-selection))
3328 (buffer-file-name it
)
3329 (expand-file-name (anything-get-selection)))))
3331 ;; (@* "Utility: Selection Paste")
3332 (defun anything-yank-selection ()
3333 "Set minibuffer contents to current selection."
3335 (anything-set-pattern (anything-get-selection nil t
)))
3337 (defun anything-kill-selection-and-quit ()
3338 "Store current selection to kill ring.
3339 You can paste it by typing C-y."
3341 (anything-run-after-quit
3344 (message "Killed: %s" sel
))
3345 (anything-get-selection nil t
)))
3348 ;; (@* "Utility: Automatical execution of persistent-action")
3349 (add-to-list 'minor-mode-alist
'(anything-follow-mode " AFollow"))
3350 (defun anything-follow-mode ()
3351 "If this mode is on, persistent action is executed everytime the cursor is moved."
3353 (with-current-buffer anything-buffer
3354 (setq anything-follow-mode
(not anything-follow-mode
))
3355 (message "anything-follow-mode is %s"
3356 (if anything-follow-mode
"enabled" "disabled"))))
3358 (defun anything-follow-execute-persistent-action-maybe ()
3359 "Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
3360 (and (not (get-buffer-window anything-action-buffer
'visible
))
3361 (buffer-local-value 'anything-follow-mode
3362 (get-buffer-create anything-buffer
))
3363 (sit-for anything-input-idle-delay
)
3365 (anything-get-selection)
3367 (anything-execute-persistent-action))))
3369 ;; (@* "Utility: Migrate `anything-sources' to my-anything command")
3370 (defun anything-migrate-sources ()
3371 "Help to migrate to new `anything' way."
3373 (with-current-buffer (get-buffer-create "*anything migrate*")
3376 Setting `anything-sources' directly is not good because
3377 `anything' is not for one command. For now, interactive use of
3378 `anything' (M-x anything) is only for demonstration purpose.
3379 So you should define commands calling `anything'.
3380 I help you to migrate to the new way.
3382 The code below is automatically generated from current
3383 `anything-sources' value. You can use the `my-anything' command
3386 Copy and paste it to your .emacs. Then substitute `my-anything'
3387 for `anything' bindings in all `define-key', `local-set-key' and
3388 `global-set-key' calls.
3390 \(defun my-anything ()
3391 \"Anything command for you.
3393 It is automatically generated by `anything-migrate-sources'.\"
3395 (anything-other-buffer
3398 " anything-sources
))
3399 (eval-last-sexp nil
)
3400 (substitute-key-definition 'anything
'my-anything global-map
)
3401 (pop-to-buffer (current-buffer))))
3403 ;; (@* "Utility: Incremental search within results (unmaintained)")
3405 (defvar anything-isearch-original-global-map nil
3406 "Original global map before Anything isearch is started.")
3408 (defvar anything-isearch-original-message-timeout nil
3409 "Original message timeout before Anything isearch is started.")
3411 (defvar anything-isearch-pattern nil
3412 "The current isearch pattern.")
3414 (defvar anything-isearch-message-suffix
""
3415 "Message suffix indicating the current state of the search.")
3417 (defvar anything-isearch-original-point nil
3418 "Original position of point before isearch is started.")
3420 (defvar anything-isearch-original-window nil
3421 "Original selected window before isearch is started.")
3423 (defvar anything-isearch-original-cursor-in-non-selected-windows nil
3424 "Original value of cursor-in-non-selected-windows before isearch is started.")
3426 (defvar anything-isearch-original-deferred-action-list nil
3427 "Original value of deferred-action-list before isearch is started.")
3429 (defvar anything-isearch-match-positions nil
3430 "Stack of positions of matches or non-matches.
3432 It's a list of plists with two properties: `event', the last user
3433 event, `start', the start position of the current match, and
3434 `pos', the position of point after that event.
3436 The value of `event' can be the following symbols: `char' if a
3437 character was typed, `error' if a non-matching character was
3438 typed, `search' if a forward search had to be done after a
3439 character, and `search-again' if a search was done for the next
3440 occurrence of the current pattern.")
3442 (defvar anything-isearch-match-start nil
3443 "Start position of the current match.")
3446 (defun anything-isearch ()
3447 "Start incremental search within results. (UNMAINTAINED)"
3449 (if (anything-empty-buffer-p (anything-buffer-get))
3450 (message "There are no results.")
3452 (setq anything-isearch-original-message-timeout minibuffer-message-timeout
)
3453 (setq minibuffer-message-timeout nil
)
3455 (setq anything-isearch-original-global-map global-map
)
3459 (setq anything-isearch-original-window
(selected-window))
3460 (select-window (anything-window))
3461 (setq cursor-type t
)
3463 (setq anything-isearch-original-deferred-action-list
3464 (default-value 'deferred-action-list
))
3465 (setq-default deferred-action-list nil
)
3466 (add-hook 'deferred-action-list
'anything-isearch-post-command
)
3468 (use-global-map anything-isearch-map
)
3469 (setq overriding-terminal-local-map anything-isearch-map
)
3471 (setq anything-isearch-pattern
"")
3473 (setq anything-isearch-original-cursor-in-non-selected-windows
3474 cursor-in-non-selected-windows
)
3475 (setq cursor-in-non-selected-windows nil
)
3477 (setq anything-isearch-original-point
(point-marker))
3478 (goto-char (point-min))
3480 (anything-mark-current-line)
3482 (setq anything-isearch-match-positions nil
)
3483 (setq anything-isearch-match-start
(point-marker))
3485 (if anything-isearch-overlay
3486 ;; make sure the overlay belongs to the anything buffer
3487 (move-overlay anything-isearch-overlay
(point-min) (point-min)
3488 (get-buffer (anything-buffer-get)))
3490 (setq anything-isearch-overlay
(make-overlay (point-min) (point-min)))
3491 (overlay-put anything-isearch-overlay
'face anything-isearch-match-face
))
3493 (setq anything-isearch-message-suffix
3494 (substitute-command-keys "cancel with \\[anything-isearch-cancel]")))
3496 (error (anything-isearch-cleanup)))))
3499 (defun anything-isearch-post-command ()
3500 "Print the current pattern after every command."
3501 (anything-isearch-message)
3502 (when (anything-window)
3503 (with-anything-window
3504 (move-overlay anything-isearch-overlay anything-isearch-match-start
(point)
3505 (get-buffer (anything-buffer-get))))))
3508 (defun anything-isearch-printing-char ()
3509 "Add printing char to the pattern."
3511 (let ((char (char-to-string last-command-event
)))
3512 (setq anything-isearch-pattern
(concat anything-isearch-pattern char
))
3514 (with-anything-window
3515 (if (looking-at char
)
3517 (push (list 'event
'char
3518 'start anything-isearch-match-start
3519 'pos
(point-marker))
3520 anything-isearch-match-positions
)
3523 (let ((start (point)))
3524 (while (and (re-search-forward anything-isearch-pattern nil t
)
3525 (anything-pos-header-line-p)))
3526 (if (or (anything-pos-header-line-p)
3530 (push (list 'event
'error
3531 'start anything-isearch-match-start
3532 'pos
(point-marker))
3533 anything-isearch-match-positions
))
3535 (push (list 'event
'search
3536 'start anything-isearch-match-start
3537 'pos
(copy-marker start
))
3538 anything-isearch-match-positions
)
3539 (setq anything-isearch-match-start
3540 (copy-marker (match-beginning 0))))))
3542 (anything-mark-current-line))))
3545 (defun anything-isearch-again ()
3546 "Search again for the current pattern"
3548 (if (equal anything-isearch-pattern
"")
3549 (setq anything-isearch-message-suffix
"no pattern yet")
3551 (with-anything-window
3552 (let ((start (point)))
3553 (while (and (re-search-forward anything-isearch-pattern nil t
)
3554 (anything-pos-header-line-p)))
3555 (if (or (anything-pos-header-line-p)
3560 (plist-get (car anything-isearch-match-positions
)
3562 (setq anything-isearch-message-suffix
"no more matches")))
3564 (push (list 'event
'search-again
3565 'start anything-isearch-match-start
3566 'pos
(copy-marker start
))
3567 anything-isearch-match-positions
)
3568 (setq anything-isearch-match-start
(copy-marker (match-beginning 0)))
3570 (anything-mark-current-line))))))
3573 (defun anything-isearch-delete ()
3576 (unless (equal anything-isearch-pattern
"")
3577 (let ((last (pop anything-isearch-match-positions
)))
3578 (unless (eq 'search-again
(plist-get last
'event
))
3579 (setq anything-isearch-pattern
3580 (substring anything-isearch-pattern
0 -
1)))
3582 (with-anything-window
3583 (goto-char (plist-get last
'pos
))
3584 (setq anything-isearch-match-start
(plist-get last
'start
))
3585 (anything-mark-current-line)))))
3588 (defun anything-isearch-default-action ()
3589 "Execute the default action for the selected candidate."
3591 (anything-isearch-cleanup)
3592 (with-current-buffer (anything-buffer-get) (anything-exit-minibuffer)))
3595 (defun anything-isearch-select-action ()
3596 "Choose an action for the selected candidate."
3598 (anything-isearch-cleanup)
3599 (with-anything-window
3600 (anything-select-action)))
3603 (defun anything-isearch-cancel ()
3604 "Cancel Anything isearch."
3606 (anything-isearch-cleanup)
3607 (when (anything-window)
3608 (with-anything-window
3609 (goto-char anything-isearch-original-point
)
3610 (anything-mark-current-line))))
3613 (defun anything-isearch-cleanup ()
3614 "Clean up the mess."
3615 (setq minibuffer-message-timeout anything-isearch-original-message-timeout
)
3616 (with-current-buffer (anything-buffer-get)
3617 (setq overriding-terminal-local-map nil
)
3618 (setq cursor-type nil
)
3619 (setq cursor-in-non-selected-windows
3620 anything-isearch-original-cursor-in-non-selected-windows
))
3621 (when anything-isearch-original-window
3622 (select-window anything-isearch-original-window
))
3624 (use-global-map anything-isearch-original-global-map
)
3625 (setq-default deferred-action-list
3626 anything-isearch-original-deferred-action-list
)
3627 (when (overlayp anything-isearch-overlay
)
3628 (delete-overlay anything-isearch-overlay
)))
3631 (defun anything-isearch-message ()
3633 (if (and (equal anything-isearch-message-suffix
"")
3634 (eq (plist-get (car anything-isearch-match-positions
) 'event
)
3636 (setq anything-isearch-message-suffix
"failing"))
3638 (unless (equal anything-isearch-message-suffix
"")
3639 (setq anything-isearch-message-suffix
3640 (concat " [" anything-isearch-message-suffix
"]")))
3642 (message (concat "Search within results: "
3643 anything-isearch-pattern
3644 anything-isearch-message-suffix
))
3646 (setq anything-isearch-message-suffix
""))
3649 ;; (@* "Utility: Iswitchb integration (unmaintained)")
3651 (defvar anything-iswitchb-candidate-selected nil
3652 "Indicates whether an anything candidate is selected from iswitchb.")
3654 (defvar anything-iswitchb-frame-configuration nil
3655 "Saved frame configuration, before anything buffer was displayed.")
3657 (defvar anything-iswitchb-saved-keys nil
3658 "The original in iswitchb before binding anything keys.")
3661 (defun anything-iswitchb-setup ()
3662 "Integrate anything completion into iswitchb (UNMAINTAINED).
3664 If the user is idle for `anything-iswitchb-idle-delay' seconds
3665 after typing something into iswitchb then anything candidates are
3666 shown for the current iswitchb input.
3668 ESC cancels anything completion and returns to normal iswitchb.
3670 Some key bindings in `anything-map' are modified.
3671 See also `anything-iswitchb-setup-keys'."
3676 ;; disable timid completion during iswitchb
3677 (put 'iswitchb-buffer
'timid-completion
'disabled
)
3678 (add-hook 'minibuffer-setup-hook
'anything-iswitchb-minibuffer-setup
)
3680 (defadvice iswitchb-visit-buffer
3681 (around anything-iswitchb-visit-buffer activate
)
3682 (if anything-iswitchb-candidate-selected
3683 (anything-execute-selection-action)
3686 (defadvice iswitchb-possible-new-buffer
3687 (around anything-iswitchb-possible-new-buffer activate
)
3688 (if anything-iswitchb-candidate-selected
3689 (anything-execute-selection-action)
3691 (anything-iswitchb-setup-keys)
3692 (message "Iswitchb integration is activated."))
3694 (defun anything-iswitchb-setup-keys ()
3695 "Modify `anything-map' for anything-iswitchb users.
3697 C-p is used instead of M-p, because anything uses ESC
3698 (currently hardcoded) for `anything-iswitchb-cancel-anything' and
3699 Emacs handles ESC and Meta as synonyms, so ESC overrides
3700 other commands with Meta prefix.
3702 Note that iswitchb uses M-p and M-n by default for history
3703 navigation, so you should bind C-p and C-n in
3704 `iswitchb-mode-map' if you use the history keys and don't want
3705 to use different keys for iswitchb while anything is not yet
3706 kicked in. These keys are not bound automatically by anything
3707 in `iswitchb-mode-map' because they (C-n at least) already have
3708 a standard iswitchb binding which you might be accustomed to.
3710 Binding M-s is used instead of C-s, because C-s has a binding in
3711 iswitchb. You can rebind it AFTER `anything-iswitchb-setup'.
3713 Unbind C-r to prevent problems during anything-isearch."
3714 (define-key anything-map
(kbd "C-s") nil
)
3715 (define-key anything-map
(kbd "M-p") nil
)
3716 (define-key anything-map
(kbd "M-n") nil
)
3717 (define-key anything-map
(kbd "M-v") nil
)
3718 (define-key anything-map
(kbd "C-v") nil
)
3719 (define-key anything-map
(kbd "C-p") 'anything-previous-history-element
)
3720 (define-key anything-map
(kbd "C-n") 'anything-next-history-element
)
3721 (define-key anything-map
(kbd "M-s") nil
)
3722 (define-key anything-map
(kbd "M-s") 'anything-isearch
)
3723 (define-key anything-map
(kbd "C-r") nil
))
3725 (defun anything-iswitchb-minibuffer-setup ()
3726 (when (eq this-command
'iswitchb-buffer
)
3727 (add-hook 'minibuffer-exit-hook
'anything-iswitchb-minibuffer-exit
)
3729 (setq anything-iswitchb-frame-configuration nil
)
3730 (setq anything-iswitchb-candidate-selected nil
)
3731 (add-hook 'anything-update-hook
'anything-iswitchb-handle-update
)
3733 (anything-initialize)
3735 (add-hook 'deferred-action-list
'anything-iswitchb-check-input
)))
3738 (defun anything-iswitchb-minibuffer-exit ()
3739 (remove-hook 'minibuffer-exit-hook
'anything-iswitchb-minibuffer-exit
)
3740 (remove-hook 'deferred-action-list
'anything-iswitchb-check-input
)
3741 (remove-hook 'anything-update-hook
'anything-iswitchb-handle-update
)
3745 (when anything-iswitchb-frame-configuration
3746 (anything-set-frame/window-configuration
3747 anything-iswitchb-frame-configuration
)
3748 (setq anything-iswitchb-frame-configuration nil
)))
3751 (defun anything-iswitchb-check-input ()
3752 "Extract iswitchb input and check if it needs to be handled."
3753 (declare (special iswitchb-text
))
3754 (if (or anything-iswitchb-frame-configuration
3755 (sit-for anything-iswitchb-idle-delay
))
3756 (anything-check-new-input iswitchb-text
)))
3759 (defun anything-iswitchb-handle-update ()
3760 "Pop up the anything buffer if it's not empty and it's not
3761 shown yet and bind anything commands in iswitchb."
3762 (unless (or (anything-empty-buffer-p anything-buffer
)
3763 anything-iswitchb-frame-configuration
)
3764 (setq anything-iswitchb-frame-configuration
3765 (anything-current-frame/window-configuration
))
3767 (save-selected-window
3768 (if (not anything-samewindow
)
3769 (pop-to-buffer anything-buffer
)
3771 (select-window (get-lru-window))
3772 (switch-to-buffer anything-buffer
)))
3774 (with-current-buffer (window-buffer (active-minibuffer-window))
3775 (let* ((anything-prefix "anything-")
3776 (prefix-length (length anything-prefix
))
3782 (let ((command (cdr binding
)))
3783 (when (and (symbolp command
)
3784 (eq (compare-strings
3787 (symbol-name command
)
3791 (cdr anything-map
)))))
3792 (bindings (mapcar (lambda (command)
3794 (where-is-internal command anything-map
)))
3797 (push (list 'anything-iswitchb-cancel-anything
(kbd "<ESC>"))
3800 (setq anything-iswitchb-saved-keys nil
)
3802 (let* ((iswitchb-prefix "iswitchb-")
3803 (prefix-length (length iswitchb-prefix
)))
3804 (dolist (binding bindings
)
3805 (dolist (key (cdr binding
))
3806 (let ((old-command (lookup-key (current-local-map) key
)))
3807 (unless (and anything-iswitchb-dont-touch-iswithcb-keys
3808 (symbolp old-command
)
3809 (eq (compare-strings iswitchb-prefix
3811 (symbol-name old-command
)
3814 (push (cons key old-command
)
3815 anything-iswitchb-saved-keys
)
3816 (define-key (current-local-map) key
(car binding
)))))))))))
3819 (defun anything-iswitchb-cancel-anything ()
3820 "Cancel anything completion and return to standard iswitchb."
3823 (dolist (binding anything-iswitchb-saved-keys
)
3824 (define-key (current-local-map) (car binding
) (cdr binding
)))
3825 (anything-iswitchb-minibuffer-exit)))
3827 ;; (@* "Compatibility")
3829 ;; Copied assoc-default from XEmacs version 21.5.12
3830 (unless (fboundp 'assoc-default
)
3831 (defun assoc-default (key alist
&optional test default
)
3832 "Find object KEY in a pseudo-alist ALIST.
3833 ALIST is a list of conses or objects. Each element (or the element's car,
3834 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
3835 If that is non-nil, the element matches;
3836 then `assoc-default' returns the element's cdr, if it is a cons,
3837 or DEFAULT if the element is not a cons.
3839 If no element matches, the value is nil.
3840 If TEST is omitted or nil, `equal' is used."
3841 (let (found (tail alist
) value
)
3842 (while (and tail
(not found
))
3843 (let ((elt (car tail
)))
3844 (when (funcall (or test
'equal
) (if (consp elt
) (car elt
) elt
) key
)
3845 (setq found t value
(if (consp elt
) (cdr elt
) default
))))
3846 (setq tail
(cdr tail
)))
3849 ;; Function not available in XEmacs,
3850 (unless (fboundp 'minibuffer-contents
)
3851 (defun minibuffer-contents ()
3852 "Return the user input in a minbuffer as a string.
3853 The current buffer must be a minibuffer."
3854 (field-string (point-max)))
3856 (defun delete-minibuffer-contents ()
3857 "Delete all user input in a minibuffer.
3858 The current buffer must be a minibuffer."
3859 (delete-field (point-max))))
3861 ;; Function not available in older Emacs (<= 22.1).
3862 (unless (fboundp 'buffer-chars-modified-tick
)
3863 (defun buffer-chars-modified-tick (&optional buffer
)
3864 "Return BUFFER's character-change tick counter.
3865 Each buffer has a character-change tick counter, which is set to the
3866 value of the buffer's tick counter (see `buffer-modified-tick'), each
3867 time text in that buffer is inserted or deleted. By comparing the
3868 values returned by two individual calls of `buffer-chars-modified-tick',
3869 you can tell whether a character change occurred in that buffer in
3870 between these calls. No argument or nil as argument means use current
3872 (with-current-buffer (or buffer
(current-buffer))
3873 (if (listp buffer-undo-list
)
3874 (length buffer-undo-list
)
3875 (buffer-modified-tick)))))
3877 ;; (@* "CUA workaround")
3878 (defadvice cua-delete-region
(around anything-avoid-cua activate
)
3879 (ignore-errors ad-do-it
))
3880 (defadvice copy-region-as-kill
(around anything-avoid-cua activate
)
3882 (ignore-errors ad-do-it
)
3886 ;;(@* "Attribute Documentation")
3887 (defun anything-describe-anything-attribute (anything-attribute)
3888 "Display the full documentation of ANYTHING-ATTRIBUTE (a symbol)."
3889 (interactive (list (intern
3891 "Describe anything attribute: "
3892 (mapcar 'symbol-name anything-additional-attributes
)))))
3893 (with-output-to-temp-buffer "*Help*"
3894 (princ (get anything-attribute
'anything-attrdoc
))))
3896 (anything-document-attribute 'name
"mandatory"
3897 " The name of the source. It is also the heading which appears
3898 above the list of matches from the source. Must be unique. ")
3899 (anything-document-attribute 'header-name
"optional"
3900 " A function returning the display string of the header. Its
3901 argument is the name of the source. This attribute is useful to
3902 add an additional information with the source name. ")
3903 (anything-document-attribute 'candidates
"mandatory if candidates-in-buffer attribute is not provided"
3904 " Specifies how to retrieve candidates from the source. It can
3905 either be a variable name, a function called with no parameters
3906 or the actual list of candidates.
3908 The list must be a list whose members are strings, symbols
3909 or (DISPLAY . REAL) pairs.
3911 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
3912 in the Anything buffer, but the REAL one is used as action
3913 argument when the candidate is selected. This allows a more
3914 readable presentation for candidates which would otherwise be,
3915 for example, too long or have a common part shared with other
3916 candidates which can be safely replaced with an abbreviated
3917 string for display purposes.
3919 Note that if the (DISPLAY . REAL) form is used then pattern
3920 matching is done on the displayed string, not on the real
3923 If the candidates have to be retrieved asynchronously (for
3924 example, by an external command which takes a while to run)
3925 then the function should start the external command
3926 asynchronously and return the associated process object.
3927 Anything will take care of managing the process (receiving the
3928 output from it, killing it if necessary, etc.). The process
3929 should return candidates matching the current pattern (see
3930 variable `anything-pattern'.)
3932 Note that currently results from asynchronous sources appear
3933 last in the anything buffer regardless of their position in
3934 `anything-sources'. ")
3935 (anything-document-attribute 'action
"mandatory if type attribute is not provided"
3936 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
3937 FUNCTION is called with one parameter: the selected candidate.
3939 An action other than the default can be chosen from this list
3940 of actions for the currently selected candidate (by default
3941 with TAB). The DISPLAY string is shown in the completions
3942 buffer and the FUNCTION is invoked when an action is
3943 selected. The first action of the list is the default. ")
3944 (anything-document-attribute 'coerce
"optional"
3945 " It's a function called with one argument: the selected candidate.
3947 This function is intended for type convertion.
3948 In normal case, the selected candidate (string) is passed to action function.
3949 If coerce function is specified, it is called just before action function.
3951 Example: converting string to symbol
3954 (anything-document-attribute 'type
"optional if action attribute is provided"
3955 " Indicates the type of the items the source returns.
3957 Merge attributes not specified in the source itself from
3958 `anything-type-attributes'.
3960 This attribute is implemented by plug-in. ")
3961 (anything-document-attribute 'init
"optional"
3962 " Function called with no parameters when anything is started. It
3963 is useful for collecting current state information which can be
3964 used to create the list of candidates later.
3966 For example, if a source needs to work with the current
3967 directory then it can store its value here, because later
3968 anything does its job in the minibuffer and in the
3969 `anything-buffer' and the current directory can be different
3971 (anything-document-attribute 'delayed-init
"optional"
3972 " Function called with no parameters before candidate function is
3973 called. It is similar with `init' attribute, but its
3974 evaluation is deferred. It is useful to combine with ")
3975 (anything-document-attribute 'match
"optional"
3976 " List of functions called with one parameter: a candidate. The
3977 function should return non-nil if the candidate matches the
3978 current pattern (see variable `anything-pattern').
3980 This attribute allows the source to override the default
3981 pattern matching based on `string-match'. It can be used, for
3982 example, to implement a source for file names and do the
3983 pattern matching on the basename of files, since it's more
3984 likely one is typing part of the basename when searching for a
3985 file, instead of some string anywhere else in its path.
3987 If the list contains more than one function then the list of
3988 matching candidates from the source is constructed by appending
3989 the results after invoking the first function on all the
3990 potential candidates, then the next function, and so on. The
3991 matching candidates supplied by the first function appear first
3992 in the list of results and then results from the other
3993 functions, respectively.
3995 This attribute has no effect for asynchronous sources (see
3996 attribute `candidates'), since they perform pattern matching
3998 (anything-document-attribute 'candidate-transformer
"optional"
3999 " It's a function or a list of functions called with one argument
4000 when the completion list from the source is built. The argument
4001 is the list of candidates retrieved from the source. The
4002 function should return a transformed list of candidates which
4003 will be used for the actual completion. If it is a list of
4004 functions, it calls each function sequentially.
4006 This can be used to transform or remove items from the list of
4009 Note that `candidates' is run already, so the given transformer
4010 function should also be able to handle candidates with (DISPLAY
4012 (anything-document-attribute 'filtered-candidate-transformer
"optional"
4013 " It has the same format as `candidate-transformer', except the
4014 function is called with two parameters: the candidate list and
4017 This transformer is run on the candidate list which is already
4018 filtered by the current pattern. While `candidate-transformer'
4019 is run only once, it is run every time the input pattern is
4022 It can be used to transform the candidate list dynamically, for
4023 example, based on the current pattern.
4025 In some cases it may also be more efficent to perform candidate
4026 transformation here, instead of with `candidate-transformer'
4027 even if this transformation is done every time the pattern is
4028 changed. For example, if a candidate set is very large then
4029 `candidate-transformer' transforms every candidate while only
4030 some of them will actually be dislpayed due to the limit
4031 imposed by `anything-candidate-number-limit'.
4033 Note that `candidates' and `candidate-transformer' is run
4034 already, so the given transformer function should also be able
4035 to handle candidates with (DISPLAY . REAL) format.
4037 This option has no effect for asynchronous sources. (Not yet,
4039 (anything-document-attribute 'action-transformer
"optional"
4040 " It's a function or a list of functions called with two
4041 arguments when the action list from the source is
4042 assembled. The first argument is the list of actions, the
4043 second is the current selection. If it is a list of functions,
4044 it calls each function sequentially.
4046 The function should return a transformed action list.
4048 This can be used to customize the list of actions based on the
4049 currently selected candidate. ")
4050 (anything-document-attribute 'pattern-transformer
"optional"
4051 " It's a function or a list of functions called with one argument
4052 before computing matches. Its argument is `anything-pattern'.
4053 Functions should return transformed `anything-pattern'.
4055 It is useful to change interpretation of `anything-pattern'. ")
4056 (anything-document-attribute 'delayed
"optional"
4057 " Candidates from the source are shown only if the user stops
4058 typing and is idle for `anything-idle-delay' seconds. ")
4059 (anything-document-attribute 'volatile
"optional"
4060 " Indicates the source assembles the candidate list dynamically,
4061 so it shouldn't be cached within a single Anything
4062 invocation. It is only applicable to synchronous sources,
4063 because asynchronous sources are not cached. ")
4064 (anything-document-attribute 'requires-pattern
"optional"
4065 " If present matches from the source are shown only if the
4066 pattern is not empty. Optionally, it can have an integer
4067 parameter specifying the required length of input which is
4068 useful in case of sources with lots of candidates. ")
4069 (anything-document-attribute 'persistent-action
"optional"
4070 " Function called with one parameter; the selected candidate.
4072 An action performed by `anything-execute-persistent-action'.
4073 If none, use the default action. ")
4074 (anything-document-attribute 'candidates-in-buffer
"optional"
4075 " Shortcut attribute for making and narrowing candidates using
4076 buffers. This newly-introduced attribute prevents us from
4077 forgetting to add volatile and match attributes.
4079 See docstring of `anything-candidates-in-buffer'.
4081 (candidates-in-buffer) is equivalent of three attributes:
4082 (candidates . anything-candidates-in-buffer)
4086 (candidates-in-buffer . candidates-function) is equivalent of:
4087 (candidates . candidates-function)
4091 This attribute is implemented by plug-in. ")
4092 (anything-document-attribute 'search
"optional"
4093 " List of functions like `re-search-forward' or `search-forward'.
4094 Buffer search function used by `anything-candidates-in-buffer'.
4095 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4096 This attribute is meant to be used with
4097 (candidates . anything-candidates-in-buffer) or
4098 (candidates-in-buffer) in short. ")
4099 (anything-document-attribute 'search-from-end
"optional"
4100 " Make `anything-candidates-in-buffer' search from the end of buffer.
4101 If this attribute is specified, `anything-candidates-in-buffer' uses
4102 `re-search-backward' instead. ")
4103 (anything-document-attribute 'get-line
"optional"
4104 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4105 This function converts point of line-beginning and point of line-end,
4106 which represents a candidate computed by `anything-candidates-in-buffer'.
4107 By default, `anything-candidates-in-buffer' uses
4108 `buffer-substring-no-properties'. ")
4109 (anything-document-attribute 'display-to-real
"optional"
4110 " Function called with one parameter; the selected candidate.
4112 The function transforms the selected candidate, and the result
4113 is passed to the action function. The display-to-real
4114 attribute provides another way to pass other string than one
4115 shown in Anything buffer.
4117 Traditionally, it is possible to make candidates,
4118 candidate-transformer or filtered-candidate-transformer
4119 function return a list with (DISPLAY . REAL) pairs. But if REAL
4120 can be generated from DISPLAY, display-to-real is more
4121 convenient and faster. ")
4122 (anything-document-attribute 'real-to-display
"optional"
4123 " Function called with one parameter; the selected candidate.
4125 The inverse of display-to-real attribute.
4127 The function transforms the selected candidate, which is passed
4128 to the action function, for display. The real-to-display
4129 attribute provides the other way to pass other string than one
4130 shown in Anything buffer.
4132 Traditionally, it is possible to make candidates,
4133 candidate-transformer or filtered-candidate-transformer
4134 function return a list with (DISPLAY . REAL) pairs. But if
4135 DISPLAY can be generated from REAL, real-to-display is more
4138 Note that DISPLAY parts returned from candidates /
4139 candidate-transformer are IGNORED as the name `display-to-real'
4141 (anything-document-attribute 'cleanup
"optional"
4142 " Function called with no parameters when *anything* buffer is closed. It
4143 is useful for killing unneeded candidates buffer.
4145 Note that the function is executed BEFORE performing action. ")
4146 (anything-document-attribute 'candidate-number-limit
"optional"
4147 " Override `anything-candidate-number-limit' only for this source. ")
4148 (anything-document-attribute 'accept-empty
"optional"
4149 " Pass empty string \"\" to action function. ")
4150 (anything-document-attribute 'disable-shortcuts
"optional"
4151 " Disable `anything-enable-shortcuts' in current `anything' session.
4153 This attribute is implemented by plug-in. ")
4154 (anything-document-attribute 'dummy
"optional"
4155 " Set `anything-pattern' to candidate. If this attribute is
4156 specified, The candidates attribute is ignored.
4158 This attribute is implemented by plug-in.
4159 This plug-in implies disable-shortcuts plug-in. ")
4160 (anything-document-attribute 'multiline
"optional"
4161 " Enable to selection multiline candidates. ")
4162 (anything-document-attribute 'update
"optional"
4163 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4164 (anything-document-attribute 'mode-line
"optional"
4165 " source local `anything-mode-line-string'. (included in `mode-line-format')
4166 It accepts also variable/function name. ")
4167 (anything-document-attribute 'header-line
"optional"
4168 " source local `header-line-format'.
4169 It accepts also variable/function name. ")
4170 (anything-document-attribute 'resume
"optional" " Function called with no parameters when `anything-resume' is started.")
4172 ;; (@* "Bug Report")
4173 (defvar anything-maintainer-mail-address
4174 (concat "rubiki" "tch@ru" "by-lang.org"))
4175 (defvar anything-bug-report-salutation
4176 "Describe bug below, using a precise recipe.
4178 When I executed M-x ...
4180 How to send a bug report:
4181 1) Be sure to use the LATEST version of anything.el.
4182 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
4183 3) Use Lisp version instead of compiled one: (load \"anything.el\")
4184 4) If you got an error, please paste *Backtrace* buffer.
4185 5) Type C-c C-c to send.
4186 # If you are a Japanese, please write in Japanese:-)")
4187 (defvar anything-no-dump-variables
4188 '(anything-candidate-buffer-alist
4189 anything-digit-overlays
4190 anything-help-message
4191 anything-candidate-cache
4193 "Variables not to dump in bug report.")
4195 (defun anything-dumped-variables-in-bug-report ()
4196 (let ((hash (make-hash-table)))
4197 (loop for var in
(apropos-internal "anything-" 'boundp
)
4198 for vname
= (symbol-name var
)
4199 unless
(or (string-match "-map$" vname
)
4200 (string-match "^anything-c-source-" vname
)
4201 (string-match "-hash$" vname
)
4202 (string-match "-face$" vname
)
4203 (memq var anything-no-dump-variables
))
4206 (defun anything-send-bug-report ()
4207 "Send a bug report of anything.el."
4209 (with-current-buffer (or anything-last-buffer
4211 (reporter-submit-bug-report
4212 anything-maintainer-mail-address
4214 (anything-dumped-variables-in-bug-report)
4216 anything-bug-report-salutation
)))
4218 (defun anything-send-bug-report-from-anything ()
4219 "Send a bug report of anything.el in anything session."
4221 (anything-run-after-quit 'anything-send-bug-report
))
4223 ;; (@* "Unit Tests")
4225 (defun* anything-test-candidates
(sources &optional
(input "") (compile-source-functions anything-compile-source-functions-default
))
4226 "Test helper function for anything.
4227 Given pseudo `anything-sources' and `anything-pattern', returns list like
4228 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4229 (\"source name2\" (\"candidate3\" \"candidate4\")))
4231 (let ((anything-test-mode t
)
4232 anything-enable-shortcuts
4233 anything-candidate-cache
4234 (anything-compile-source-functions compile-source-functions
)
4235 anything-before-initialize-hook
4236 anything-after-initialize-hook
4237 anything-update-hook
4238 anything-test-candidate-list
)
4239 (get-buffer-create anything-buffer
)
4241 (anything-initialize-1 nil input sources
)
4243 ;; test-mode spec: select 1st candidate!
4244 (with-current-buffer anything-buffer
4246 (anything-mark-current-line))
4248 anything-test-candidate-list
4249 (anything-cleanup))))
4251 (defmacro anything-test-update
(sources pattern
)
4252 "Test helper macro for anything. It is meant for testing *anything* buffer contents."
4253 `(progn (stub anything-get-sources
=> ,sources
)
4254 (stub anything-log-run-hook
=> nil
)
4255 (stub anything-maybe-fit-frame
=> nil
)
4256 (stub run-with-idle-timer
=> nil
)
4257 (let (anything-test-mode (anything-pattern ,pattern
))
4258 (anything-update))))
4261 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4262 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
4264 (when (fboundp 'expectations
)
4266 (desc "anything-current-buffer")
4267 (expect "__a_buffer"
4268 (with-current-buffer (get-buffer-create "__a_buffer")
4269 (anything-test-candidates '(((name .
"FOO"))) "")
4271 (buffer-name anything-current-buffer
)
4272 (kill-buffer "__a_buffer")
4274 (desc "anything-buffer-file-name")
4275 (expect (regexp "/__a_file__")
4276 (with-current-buffer (get-buffer-create "__a_file__")
4277 (setq buffer-file-name
"/__a_file__")
4278 (anything-test-candidates '(((name .
"FOO"))) "")
4280 anything-buffer-file-name
4281 ;;(kill-buffer "__a_file__")
4283 (desc "anything-interpret-value")
4285 (anything-interpret-value "literal"))
4287 (anything-interpret-value (lambda () "lambda")))
4288 (expect "lambda with source name"
4289 (let ((source '((name .
"lambda with source name"))))
4290 (anything-interpret-value (lambda () anything-source-name
) source
)))
4291 (expect "function symbol"
4292 (flet ((f () "function symbol"))
4293 (anything-interpret-value 'f
)))
4294 (expect "variable symbol"
4295 (let ((v "variable symbol"))
4296 (anything-interpret-value 'v
)))
4297 (expect (error error
*)
4298 (anything-interpret-value 'unbounded-1
))
4299 (desc "anything-compile-sources")
4300 (expect '(((name .
"foo")))
4301 (anything-compile-sources '(((name .
"foo"))) nil
)
4303 (expect '(((name .
"foo") (type . test
) (action . identity
)))
4304 (let ((anything-type-attributes '((test (action . identity
)))))
4305 (anything-compile-sources '(((name .
"foo") (type . test
)))
4306 '(anything-compile-source--type))))
4307 (desc "anything-sources accepts symbols")
4308 (expect '(((name .
"foo")))
4309 (let* ((foo '((name .
"foo"))))
4310 (anything-compile-sources '(foo) nil
)))
4311 (desc "anything-get-sources action")
4312 (expect '(((name .
"Actions") (candidates . actions
)))
4313 (stub anything-action-window
=> t
)
4314 (let (anything-compiled-sources
4315 (anything-sources '(((name .
"Actions") (candidates . actions
)))))
4316 (anything-get-sources)))
4317 (desc "get-buffer-create candidates-buffer")
4318 (expect '(((name .
"many") (init . many-init
)
4319 (candidates-in-buffer . anything-candidates-in-buffer
)
4320 (candidates . anything-candidates-in-buffer
)
4321 (volatile) (match identity
)))
4322 (anything-compile-sources
4323 '(((name .
"many") (init . many-init
)
4324 (candidates-in-buffer . anything-candidates-in-buffer
)))
4325 '(anything-compile-source--candidates-in-buffer)))
4326 (expect '(((name .
"many") (init . many-init
)
4327 (candidates-in-buffer)
4328 (candidates . anything-candidates-in-buffer
)
4329 (volatile) (match identity
)))
4330 (anything-compile-sources
4331 '(((name .
"many") (init . many-init
)
4332 (candidates-in-buffer)))
4333 '(anything-compile-source--candidates-in-buffer)))
4334 (expect '(((name .
"many") (init . many-init
)
4335 (candidates-in-buffer)
4338 (candidates . anything-candidates-in-buffer
)
4339 (volatile) (match identity
)))
4340 (let ((anything-type-attributes '((test (action . identity
)))))
4341 (anything-compile-sources
4342 '(((name .
"many") (init . many-init
)
4343 (candidates-in-buffer)
4345 '(anything-compile-source--type
4346 anything-compile-source--candidates-in-buffer
))))
4348 (desc "anything-get-candidates")
4349 (expect '("foo" "bar")
4350 (anything-get-candidates '((name .
"foo") (candidates "foo" "bar"))))
4351 (expect '("FOO" "BAR")
4352 (anything-get-candidates '((name .
"foo") (candidates "foo" "bar")
4353 (candidate-transformer
4354 .
(lambda (cands) (mapcar 'upcase cands
))))))
4355 (expect '("foo" "bar")
4356 (anything-get-candidates '((name .
"foo")
4357 (candidates .
(lambda () '("foo" "bar"))))))
4358 (expect '("foo" "bar")
4359 (let ((var '("foo" "bar")))
4360 (anything-get-candidates '((name .
"foo")
4361 (candidates . var
)))))
4362 (expect (error error
*)
4363 (anything-get-candidates '((name .
"foo")
4364 (candidates .
"err"))))
4365 (expect (error error
*)
4367 (anything-get-candidates '((name .
"foo")
4368 (candidates . var
)))))
4369 (expect (error error
*)
4370 (anything-get-candidates '((name .
"foo")
4371 (candidates . unDeFined-syMbol
))))
4372 (desc "anything-compute-matches")
4373 (expect '("foo" "bar")
4374 (let ((anything-pattern ""))
4375 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
4377 (let ((anything-pattern "oo"))
4378 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
4380 (let ((anything-pattern "^b"))
4381 (anything-compute-matches '((name .
"FOO") (candidates "foo" "bar") (volatile)))))
4383 (let ((anything-pattern "")
4384 (anything-candidate-number-limit 2))
4385 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
4387 (let ((anything-pattern ".")
4388 (anything-candidate-number-limit 2))
4389 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
4390 (expect '("a" "b" "c")
4391 (let ((anything-pattern "")
4392 anything-candidate-number-limit
)
4393 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
4394 (expect '("a" "b" "c")
4395 (let ((anything-pattern "[abc]")
4396 anything-candidate-number-limit
)
4397 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c") (volatile)))))
4399 (let ((anything-pattern "[abc]")
4400 anything-candidate-number-limit
)
4401 (anything-compute-matches '((name .
"FOO") (candidates a b c
) (volatile)))))
4402 (expect '(("foo" .
"FOO") ("bar" .
"BAR"))
4403 (let ((anything-pattern ""))
4404 (anything-compute-matches '((name .
"FOO") (candidates ("foo" .
"FOO") ("bar" .
"BAR")) (volatile)))))
4405 (expect '(("foo" .
"FOO"))
4406 (let ((anything-pattern "foo"))
4407 (anything-compute-matches '((name .
"FOO") (candidates ("foo" .
"FOO") ("bar" .
"foo")) (volatile)))))
4408 ;; using anything-test-candidate-list
4409 (desc "anything-test-candidates")
4410 (expect '(("FOO" ("foo" "bar")))
4411 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")))))
4412 (expect '(("FOO" ("bar")))
4413 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar"))) "ar"))
4414 (expect '(("T1" ("hoge" "aiue"))
4415 ("T2" ("test" "boke")))
4416 (anything-test-candidates '(((name .
"T1") (candidates "hoge" "aiue"))
4417 ((name .
"T2") (candidates "test" "boke")))))
4418 (expect '(("T1" ("hoge"))
4420 (anything-test-candidates '(((name .
"T1") (candidates "hoge" "aiue"))
4421 ((name .
"T2") (candidates "test" "boke"))) "o"))
4422 (desc "requires-pattern attribute")
4424 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
4425 (requires-pattern .
1)))))
4426 (expect '(("FOO" ("bar")))
4427 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
4428 (requires-pattern .
1))) "b"))
4429 (desc "delayed attribute(for test)")
4430 (expect '(("T2" ("boke"))
4432 (anything-test-candidates
4433 '(((name .
"T1") (candidates "hoge" "aiue") (delayed))
4434 ((name .
"T2") (candidates "test" "boke")))
4436 (desc "match attribute(prefix search)")
4437 (expect '(("FOO" ("bar")))
4438 (anything-test-candidates
4439 '(((name .
"FOO") (candidates "foo" "bar")
4440 (match (lambda (c) (string-match (concat "^" anything-pattern
) c
)))))
4443 (anything-test-candidates
4444 '(((name .
"FOO") (candidates "foo" "bar")
4445 (match (lambda (c) (string-match (concat "^" anything-pattern
) c
)))))
4447 (expect "TestSource"
4449 (anything-test-candidates
4450 '(((name .
"TestSource") (candidates "a")
4451 (match (lambda (c) (setq x anything-source-name
)))))
4454 (desc "init attribute")
4455 (expect '(("FOO" ("bar")))
4457 (anything-test-candidates
4458 '(((name .
"FOO") (init .
(lambda () (setq v
'("foo" "bar"))))
4461 (desc "candidate-transformer attribute")
4462 (expect '(("FOO" ("BAR")))
4463 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
4464 (candidate-transformer
4465 .
(lambda (cands) (mapcar 'upcase cands
)))))
4467 (desc "filtered-candidate-transformer attribute")
4469 (expect '(("FOO" ("BAR")))
4470 (anything-test-candidates '(((name .
"FOO") (candidates "foo" "bar")
4471 (filtered-candidate-transformer
4472 .
(lambda (cands src
) (mapcar 'upcase cands
)))))
4474 (desc "anything-transform-candidates in process")
4475 (expect (mock (anything-composed-funcall-with-source
4476 '((name .
"FOO") (candidates "foo" "bar")
4477 (filtered-candidate-transformer
4478 .
(lambda (cands src
) (mapcar 'upcase cands
))))
4479 (lambda (cands src
) (mapcar 'upcase cands
))
4481 '((name .
"FOO") (candidates "foo" "bar")
4482 (filtered-candidate-transformer
4483 .
(lambda (cands src
) (mapcar 'upcase cands
))))
4485 (stub anything-process-candidate-transformer
=> '("foo" "bar"))
4486 (anything-transform-candidates
4488 '((name .
"FOO") (candidates "foo" "bar")
4489 (filtered-candidate-transformer
4490 .
(lambda (cands src
) (mapcar 'upcase cands
))))
4493 (desc "anything-candidates-in-buffer-1")
4495 (anything-candidates-in-buffer-1
4497 'buffer-substring-no-properties
'(re-search-forward) 50 nil
))
4498 (expect '("foo+" "bar+" "baz+")
4500 (insert "foo+\nbar+\nbaz+\n")
4501 (anything-candidates-in-buffer-1
4503 'buffer-substring-no-properties
'(re-search-forward) 5 nil
)))
4504 (expect '("foo+" "bar+")
4506 (insert "foo+\nbar+\nbaz+\n")
4507 (anything-candidates-in-buffer-1
4509 'buffer-substring-no-properties
'(re-search-forward) 2 nil
)))
4512 (insert "foo+\nbar+\nbaz+\n")
4513 (anything-candidates-in-buffer-1
4514 (current-buffer) "oo\\+"
4515 'buffer-substring-no-properties
'(re-search-forward) 50 nil
)))
4518 (insert "foo+\nbar+\nbaz+\n")
4519 (anything-candidates-in-buffer-1
4520 (current-buffer) "oo+"
4521 #'buffer-substring-no-properties
'(search-forward) 50 nil
)))
4522 (expect '("foo+" "bar+")
4524 (insert "foo+\nbar+\nbaz+\n")
4525 (anything-candidates-in-buffer-1
4526 (current-buffer) "."
4527 'buffer-substring-no-properties
'(re-search-forward) 2 nil
)))
4528 (expect '(("foo+" "FOO+"))
4530 (insert "foo+\nbar+\nbaz+\n")
4531 (anything-candidates-in-buffer-1
4532 (current-buffer) "oo\\+"
4534 (let ((l (buffer-substring-no-properties s e
)))
4535 (list l
(upcase l
))))
4536 '(re-search-forward) 50 nil
)))
4537 (desc "anything-candidates-in-buffer")
4538 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4539 (anything-test-candidates
4542 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4543 (insert "foo+\nbar+\nbaz+\n"))))
4544 (candidates . anything-candidates-in-buffer
)
4547 (expect '(("TEST" ("foo+" "bar+" "baz+")))
4548 (let (anything-candidate-number-limit)
4549 (anything-test-candidates
4552 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4553 (insert "foo+\nbar+\nbaz+\n"))))
4554 (candidates . anything-candidates-in-buffer
)
4557 (expect '(("TEST" ("foo+")))
4558 (anything-test-candidates
4561 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4562 (insert "foo+\nbar+\nbaz+\n"))))
4563 (candidates . anything-candidates-in-buffer
)
4567 ;; BUG remain empty string, but the pattern is rare case.
4568 (expect '(("a" ("" "a" "b")))
4569 (anything-test-candidates
4572 (with-current-buffer (anything-candidate-buffer 'global
)
4573 (insert "a\nb\n"))))
4574 (candidates-in-buffer)))
4576 (desc "search attribute")
4577 (expect '(("TEST" ("foo+")))
4578 (anything-test-candidates
4581 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4582 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4583 (search search-forward
)
4584 (candidates . anything-candidates-in-buffer
)
4588 (expect '(("TEST" ("foo+" "ooo")))
4589 (anything-test-candidates
4592 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4593 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4594 (search search-forward re-search-forward
)
4595 (candidates . anything-candidates-in-buffer
)
4599 (expect '(("TEST" ("foo+" "ooo")))
4600 (anything-test-candidates
4603 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4604 (insert "foo+\nbar+\nbaz+\nooo\n"))))
4605 (search re-search-forward search-forward
)
4606 (candidates . anything-candidates-in-buffer
)
4610 (expect '(("TEST" ("ooo" "foo+")))
4611 (anything-test-candidates
4614 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4615 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4616 (search re-search-forward search-forward
)
4617 (candidates . anything-candidates-in-buffer
)
4621 ;; faster exact match
4622 (expect '(("TEST" ("bar+")))
4623 (anything-test-candidates
4626 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4627 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4628 (search (lambda (pattern &rest _
)
4629 (and (search-forward (concat "\n" pattern
"\n") nil t
)
4630 (forward-line -
1))))
4631 (candidates . anything-candidates-in-buffer
)
4635 ;; faster prefix match
4636 (expect '(("TEST" ("bar+")))
4637 (anything-test-candidates
4640 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
4641 (insert "bar+\nbaz+\nooo\nfoo+\n"))))
4642 (search (lambda (pattern &rest _
)
4643 (search-forward (concat "\n" pattern
) nil t
)))
4644 (candidates . anything-candidates-in-buffer
)
4648 (desc "anything-current-buffer-is-modified")
4649 (expect '(("FOO" ("modified")))
4650 (let ((sources '(((name .
"FOO")
4653 (if (anything-current-buffer-is-modified)
4655 '("unmodified"))))))))
4657 (clrhash anything-tick-hash
)
4659 (anything-test-candidates sources
))))
4660 (expect '(("FOO" ("unmodified")))
4661 (let ((sources '(((name .
"FOO")
4664 (if (anything-current-buffer-is-modified)
4666 '("unmodified"))))))))
4668 (clrhash anything-tick-hash
)
4670 (anything-test-candidates sources
)
4671 (anything-test-candidates sources
))))
4672 (expect '(("FOO" ("modified")))
4673 (let ((sources '(((name .
"FOO")
4676 (if (anything-current-buffer-is-modified)
4678 '("unmodified"))))))))
4680 (clrhash anything-tick-hash
)
4682 (anything-test-candidates sources
)
4684 (anything-test-candidates sources
))))
4685 (expect '(("BAR" ("modified")))
4686 (let ((sources1 '(((name .
"FOO")
4689 (if (anything-current-buffer-is-modified)
4691 '("unmodified")))))))
4692 (sources2 '(((name .
"BAR")
4695 (if (anything-current-buffer-is-modified)
4697 '("unmodified"))))))))
4699 (clrhash anything-tick-hash
)
4701 (anything-test-candidates sources1
)
4702 (anything-test-candidates sources2
))))
4703 (expect '(("FOO" ("unmodified")))
4704 (let ((sources1 '(((name .
"FOO")
4707 (if (anything-current-buffer-is-modified)
4709 '("unmodified")))))))
4710 (sources2 '(((name .
"BAR")
4713 (if (anything-current-buffer-is-modified)
4715 '("unmodified"))))))))
4717 (clrhash anything-tick-hash
)
4719 (anything-test-candidates sources1
)
4720 (anything-test-candidates sources2
)
4721 (anything-test-candidates sources1
))))
4722 (expect '(("BAR" ("unmodified")))
4723 (let ((sources1 '(((name .
"FOO")
4726 (if (anything-current-buffer-is-modified)
4728 '("unmodified")))))))
4729 (sources2 '(((name .
"BAR")
4732 (if (anything-current-buffer-is-modified)
4734 '("unmodified"))))))))
4736 (clrhash anything-tick-hash
)
4738 (anything-test-candidates sources1
)
4739 (anything-test-candidates sources2
)
4740 (anything-test-candidates sources2
))))
4741 (expect '(("BAR" ("modified")))
4742 (let ((sources1 '(((name .
"FOO")
4745 (if (anything-current-buffer-is-modified)
4747 '("unmodified")))))))
4748 (sources2 '(((name .
"BAR")
4751 (if (anything-current-buffer-is-modified)
4753 '("unmodified"))))))))
4755 (clrhash anything-tick-hash
)
4757 (anything-test-candidates sources1
)
4758 (anything-test-candidates sources2
)
4760 (anything-test-candidates sources2
)))))
4761 (desc "anything-source-name")
4764 (anything-test-candidates '(((name .
"FOO")
4766 .
(lambda () (setq v anything-source-name
)))
4767 (candidates "ok"))))
4771 (anything-test-candidates '(((name .
"FOO")
4774 (setq v anything-source-name
)
4779 (anything-test-candidates '(((name .
"FOO")
4781 (candidate-transformer
4783 (setq v anything-source-name
)
4788 (anything-test-candidates '(((name .
"FOO")
4790 (filtered-candidate-transformer
4792 (setq v anything-source-name
)
4797 (anything-test-candidates '(((name .
"FOO")
4801 (setq v anything-source-name
)
4803 (action . identity
))))
4804 (anything-execute-selection-action)
4806 (desc "anything-candidate-buffer create")
4807 (expect " *anything candidates:FOO*"
4808 (let* (anything-candidate-buffer-alist
4809 (anything-source-name "FOO")
4810 (buf (anything-candidate-buffer 'global
)))
4811 (prog1 (buffer-name buf
)
4812 (kill-buffer buf
))))
4813 (expect " *anything candidates:FOO*aTestBuffer"
4814 (let* (anything-candidate-buffer-alist
4815 (anything-source-name "FOO")
4816 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4817 (buf (anything-candidate-buffer 'local
)))
4818 (prog1 (buffer-name buf
)
4819 (kill-buffer anything-current-buffer
)
4820 (kill-buffer buf
))))
4822 (let (anything-candidate-buffer-alist
4823 (anything-source-name "FOO") buf
)
4824 (with-current-buffer (anything-candidate-buffer 'global
)
4826 (setq buf
(anything-candidate-buffer 'global
))
4827 (prog1 (buffer-size buf
)
4828 (kill-buffer buf
))))
4829 (desc "anything-candidate-buffer get-buffer")
4830 (expect " *anything candidates:FOO*"
4831 (let* (anything-candidate-buffer-alist
4832 (anything-source-name "FOO")
4833 (buf (anything-candidate-buffer 'global
)))
4834 (prog1 (buffer-name (anything-candidate-buffer))
4835 (kill-buffer buf
))))
4836 (expect " *anything candidates:FOO*aTestBuffer"
4837 (let* (anything-candidate-buffer-alist
4838 (anything-source-name "FOO")
4839 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4840 (buf (anything-candidate-buffer 'local
)))
4841 (prog1 (buffer-name (anything-candidate-buffer))
4842 (kill-buffer anything-current-buffer
)
4843 (kill-buffer buf
))))
4844 (expect " *anything candidates:FOO*"
4845 (let* (anything-candidate-buffer-alist
4846 (anything-source-name "FOO")
4847 (buf-local (anything-candidate-buffer 'local
))
4848 (buf-global (anything-candidate-buffer 'global
)))
4849 (prog1 (buffer-name (anything-candidate-buffer))
4850 (kill-buffer buf-local
)
4851 (kill-buffer buf-global
))))
4852 (expect " *anything candidates:FOO*aTestBuffer"
4853 (let* (anything-candidate-buffer-alist
4854 (anything-source-name "FOO")
4855 (anything-current-buffer (get-buffer-create "aTestBuffer"))
4856 (buf-global (anything-candidate-buffer 'global
))
4857 (buf-local (anything-candidate-buffer 'local
)))
4858 (prog1 (buffer-name (anything-candidate-buffer))
4859 (kill-buffer buf-local
)
4860 (kill-buffer buf-global
))))
4862 (let* (anything-candidate-buffer-alist
4863 (anything-source-name "NOP__"))
4864 (anything-candidate-buffer)))
4865 (desc "anything-candidate-buffer register-buffer")
4866 (expect " *anything test candidates*"
4867 (let (anything-candidate-buffer-alist
4868 (buf (get-buffer-create " *anything test candidates*")))
4869 (with-current-buffer buf
4871 (prog1 (buffer-name (anything-candidate-buffer buf
))
4872 (kill-buffer (current-buffer))))))
4873 (expect " *anything test candidates*"
4874 (let (anything-candidate-buffer-alist
4875 (buf (get-buffer-create " *anything test candidates*")))
4876 (with-current-buffer buf
4878 (anything-candidate-buffer buf
)
4879 (prog1 (buffer-name (anything-candidate-buffer))
4880 (kill-buffer (current-buffer))))))
4882 (let (anything-candidate-buffer-alist
4883 (buf (get-buffer-create " *anything test candidates*")))
4884 (with-current-buffer buf
4886 (anything-candidate-buffer buf
)
4887 (prog1 (buffer-string)
4888 (kill-buffer (current-buffer))))))
4890 (let (anything-candidate-buffer-alist
4891 (anything-source-name "foo")
4892 (buf1 (get-buffer-create "buf1"))
4893 (buf2 (get-buffer-create "buf2")))
4894 (anything-candidate-buffer buf1
)
4895 (anything-candidate-buffer buf2
)
4896 (prog1 (buffer-name (anything-candidate-buffer buf1
))
4898 (kill-buffer buf2
))))
4899 (desc "action attribute")
4901 (anything-test-candidates
4904 (action ("identity" . identity
)))))
4905 (anything-execute-selection-action))
4907 (anything-test-candidates
4910 (action ("identity" .
(lambda (c) (identity c
)))))))
4911 (anything-execute-selection-action))
4912 (desc "anything-get-default-action")
4914 (anything-get-default-action '(("upcase" . upcase
))))
4916 (anything-get-default-action '(("downcase" . downcase
))))
4917 (expect (lambda (x) (capitalize x
))
4918 (anything-get-default-action (lambda (x) (capitalize x
))))
4920 (anything-get-default-action 'identity
))
4921 (desc "anything-execute-selection-action")
4923 (anything-execute-selection-action
4924 "foo" '(("upcase" . upcase
)) nil
))
4926 (anything-execute-selection-action
4927 "foo" '(("upcase" .
(lambda (c) (upcase c
)))) nil
))
4929 (desc "display-to-real attribute")
4931 (anything-test-candidates
4934 (display-to-real . upcase
)
4935 (action ("identity" . identity
)))))
4936 (anything-execute-selection-action))
4937 (desc "cleanup test")
4940 (anything-test-candidates
4942 (cleanup .
(lambda () (setq v
'cleaned
))))))
4944 (desc "anything-get-current-source")
4945 ;; in init/candidates/action/candidate-transformer/filtered-candidate-transformer
4946 ;; display-to-real/cleanup function
4950 (anything-funcall-with-source '((name .
"FOO")) 'anything-get-current-source
)))
4954 (anything-test-candidates
4956 (init .
(lambda () (setq v
(anything-get-current-source)))))))
4957 (assoc-default 'name v
)))
4961 (anything-test-candidates
4963 (candidates .
(lambda () (setq v
(anything-get-current-source)) '("a"))))))
4964 (assoc-default 'name v
)))
4968 (anything-test-candidates
4972 .
(lambda (c) (setq v
(anything-get-current-source)) c
)))))
4973 (anything-execute-selection-action)
4974 (assoc-default 'name v
)))
4975 ;; candidate-transformer
4978 (anything-test-candidates
4981 (candidate-transformer
4982 .
(lambda (c) (setq v
(anything-get-current-source)) c
)))))
4983 (assoc-default 'name v
)))
4984 ;; filtered-candidate-transformer
4987 (anything-test-candidates
4990 (filtered-candidate-transformer
4991 .
(lambda (c s
) (setq v
(anything-get-current-source)) c
)))))
4992 (assoc-default 'name v
)))
4993 ;; action-transformer
4996 (anything-test-candidates
5000 .
(lambda (a c
) (setq v
(anything-get-current-source)) a
))
5001 (action . identity
))))
5002 (anything-execute-selection-action)
5003 (assoc-default 'name v
)))
5007 (anything-test-candidates
5009 (init .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5011 (candidates-in-buffer)
5013 .
(lambda (c) (setq v
(anything-get-current-source)) c
))
5014 (action . identity
))))
5015 (anything-execute-selection-action)
5016 (assoc-default 'name v
)))
5020 (anything-test-candidates
5024 .
(lambda () (setq v
(anything-get-current-source)))))))
5025 (assoc-default 'name v
)))
5026 ;; candidates are displayed
5028 (anything-test-candidates
5031 (action ("identity" . identity
)))))
5032 (assoc-default 'name
(anything-get-current-source)))
5033 (desc "anything-attr")
5035 (anything-funcall-with-source
5038 (anything-attr 'name
))))
5041 (anything-test-candidates
5044 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
5049 (anything-test-candidates
5051 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
5056 (anything-test-candidates
5058 (hoge) ;INCOMPATIBLE!
5059 (init .
(lambda () (setq v
(anything-attr 'hoge
))))
5062 (desc "anything-attr*")
5064 (let (v (value1 "generic"))
5065 (anything-test-candidates
5068 (init .
(lambda () (setq v
(anything-attr* 'hoge
)))))))
5070 (desc "anything-attr-defined")
5073 (anything-test-candidates
5076 (init .
(lambda () (setq v
(anything-attr-defined 'hoge
))))
5081 (anything-test-candidates
5083 (init .
(lambda () (setq v
(anything-attr-defined 'hoge
))))
5086 (desc "anything-attrset")
5087 (expect '((name .
"FOO") (hoge .
77))
5088 (let ((src '((name .
"FOO") (hoge))))
5089 (anything-attrset 'hoge
77 src
)
5092 (anything-attrset 'hoge
77 '((name .
"FOO") (hoge))))
5094 (expect '((name .
"FOO") (hoge .
77))
5095 (let ((src '((name .
"FOO") (hoge .
1))))
5096 (anything-attrset 'hoge
77 src
)
5099 (expect '((name .
"FOO") (hoge .
77) (x))
5100 (let ((src '((name .
"FOO") (x))))
5101 (anything-attrset 'hoge
77 src
)
5104 (anything-attrset 'hoge
77 '((name .
"FOO"))))
5105 (desc "anything-preselect")
5108 (with-current-buffer (anything-create-anything-buffer t
)
5109 (let ((anything-pattern "")
5110 (anything-test-mode t
))
5111 (anything-process-source '((name .
"test")
5112 (candidates "hoge" "foo" "bar")))
5113 (anything-preselect "foo")
5114 (anything-get-selection))))
5117 (with-current-buffer (anything-create-anything-buffer t
)
5118 (let ((anything-pattern "")
5119 (anything-test-mode t
))
5120 (anything-process-source '((name .
"test")
5121 (candidates "hoge" "foo" "bar")))
5122 (anything-preselect "fo+")
5123 (anything-get-selection))))
5124 ;; no match -> first entry
5126 (with-current-buffer (anything-create-anything-buffer t
)
5127 (let ((anything-pattern "")
5128 (anything-test-mode t
))
5129 (anything-process-source '((name .
"test")
5130 (candidates "hoge" "foo" "bar")))
5131 (anything-preselect "not found")
5132 (anything-get-selection))))
5133 (desc "anything-check-new-input")
5134 (expect "newpattern"
5135 (stub anything-update
)
5136 (stub anything-action-window
)
5137 (let ((anything-pattern "pattern"))
5138 (anything-check-new-input "newpattern")
5140 ;; anything-input == nil when action window is available
5142 (stub anything-update
)
5143 (stub anything-action-window
=> t
)
5144 (let ((anything-pattern "pattern")
5146 (anything-check-new-input "newpattern")
5148 ;; anything-input == anything-pattern unless action window is available
5149 (expect "newpattern"
5150 (stub anything-update
)
5151 (stub anything-action-window
=> nil
)
5152 (let ((anything-pattern "pattern")
5154 (anything-check-new-input "newpattern")
5156 (expect (mock (anything-update))
5157 (stub anything-action-window
)
5158 (let (anything-pattern)
5159 (anything-check-new-input "foo")))
5160 (desc "anything-update")
5161 (expect (mock (anything-process-source '((name .
"1"))))
5162 (anything-test-update '(((name .
"1"))) ""))
5163 ;; (find-function 'anything-update)
5164 ;; TODO el-mock.el should express 2nd call of function.
5165 ;; (expect (mock (anything-process-source '((name . "2"))))
5166 ;; (stub anything-get-sources => '(((name . "1")) ((name . "2"))))
5167 ;; (stub anything-log-run-hook)
5168 ;; (stub anything-maybe-fit-frame)
5169 ;; (stub run-with-idle-timer)
5170 ;; (anything-update))
5171 (expect (mock (run-with-idle-timer * nil
'anything-process-delayed-sources
5172 '(((name .
"2") (delayed)))))
5173 (stub anything-get-sources
=> '(((name .
"1"))
5174 ((name .
"2") (delayed))))
5175 (stub anything-log-run-hook
)
5176 (stub anything-maybe-fit-frame
)
5177 (let ((anything-pattern "") anything-test-mode
)
5180 (desc "requires-pattern attribute")
5181 (expect (not-called anything-process-source
)
5182 (anything-test-update '(((name .
"1") (requires-pattern))) ""))
5183 (expect (not-called anything-process-source
)
5184 (anything-test-update '(((name .
"1") (requires-pattern .
3))) "xx"))
5186 (desc "anything-normalize-sources")
5187 (expect '(anything-c-source-test)
5188 (anything-normalize-sources 'anything-c-source-test
))
5189 (expect '(anything-c-source-test)
5190 (anything-normalize-sources '(anything-c-source-test)))
5191 (expect '(anything-c-source-test)
5192 (let ((anything-sources '(anything-c-source-test)))
5193 (anything-normalize-sources nil
)))
5194 (expect '(((name .
"test")))
5195 (anything-normalize-sources '((name .
"test"))))
5196 (expect '(((name .
"test")))
5197 (anything-normalize-sources '(((name .
"test")))))
5198 (desc "anything-get-action")
5199 (expect '(("identity" . identity
))
5200 (stub buffer-size
=> 1)
5201 (stub anything-get-current-source
=> '((name .
"test")
5202 (action ("identity" . identity
))))
5203 (anything-get-action))
5205 (stub buffer-size
=> 1)
5206 (stub anything-get-current-source
=> '((name .
"test")
5207 (action . identity
)))
5208 (anything-get-action))
5209 (expect '((("identity" . identity
)) "action-transformer is called")
5210 (stub buffer-size
=> 1)
5211 (stub anything-get-current-source
5212 => '((name .
"test")
5213 (action ("identity" . identity
))
5215 .
(lambda (actions selection
)
5216 (list actions selection
)))))
5217 (stub anything-get-selection
=> "action-transformer is called")
5218 (anything-get-action))
5219 (desc "anything-select-nth-action")
5220 (expect (error error
*)
5221 (stub anything-get-selection
=> nil
)
5222 (anything-select-nth-action 0))
5223 (desc "anything-get-nth-action")
5225 (anything-get-nth-action 2 '(("0" . car
) ("1" . cdr
) ("2" . cadr
))))
5226 (expect (error error
*)
5227 (anything-get-nth-action 2 '(("0" . car
))))
5229 (anything-get-nth-action 0 'identity
))
5230 (expect (error error
*)
5231 (anything-get-nth-action 1 'identity
))
5232 (expect (error error
*)
5233 (anything-get-nth-action 0 'unbound-function-xxx
))
5234 (expect (error error
*)
5235 (anything-get-nth-action 0 "invalid data"))
5236 (desc "anything-funcall-foreach")
5237 (expect (mock (upcase "foo"))
5238 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))))
5239 (anything-funcall-foreach 'init
))
5240 (expect (mock (downcase "bar"))
5241 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))
5242 ((init .
(lambda () (downcase "bar"))))))
5243 (anything-funcall-foreach 'init
))
5244 (expect (not-called anything-funcall-with-source
)
5245 (stub anything-get-sources
=> '(((init .
(lambda () (upcase "foo"))))))
5246 (anything-funcall-foreach 'not-found
))
5247 ;; TODO anything-select-with-digit-shortcut test
5248 (desc "anything-get-cached-candidates")
5249 (expect '("cached" "version")
5250 (let ((anything-candidate-cache '(("test" "cached" "version"))))
5251 (anything-get-cached-candidates '((name .
"test")
5252 (candidates "new")))))
5254 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5255 (anything-get-cached-candidates '((name .
"test")
5256 (candidates "new")))))
5257 (expect '(("test" "new")
5258 ("other" "cached" "version"))
5259 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5260 (anything-get-cached-candidates '((name .
"test")
5261 (candidates "new")))
5262 anything-candidate-cache
))
5263 (expect '(("other" "cached" "version"))
5264 (let ((anything-candidate-cache '(("other" "cached" "version"))))
5265 (anything-get-cached-candidates '((name .
"test")
5268 anything-candidate-cache
))
5269 ;; TODO when candidates == process
5270 ;; TODO anything-output-filter
5271 (desc "candidate-number-limit attribute")
5273 (let ((anything-pattern "")
5274 (anything-candidate-number-limit 20))
5275 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c")
5276 (candidate-number-limit .
2) (volatile)))))
5278 (let ((anything-pattern "[abc]")
5279 (anything-candidate-number-limit 20))
5280 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c")
5281 (candidate-number-limit .
2) (volatile)))))
5282 (expect '("a" "b" "c" "d")
5283 (let ((anything-pattern "[abcd]")
5284 (anything-candidate-number-limit 2))
5285 (anything-compute-matches '((name .
"FOO") (candidates "a" "b" "c" "d")
5286 (candidate-number-limit) (volatile)))))
5287 (expect '(("TEST" ("a" "b" "c")))
5288 (let ((anything-candidate-number-limit 2))
5289 (anything-test-candidates
5292 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5293 (insert "a\nb\nc\nd\n"))))
5294 (candidates . anything-candidates-in-buffer
)
5296 (candidate-number-limit .
3)
5298 (expect '(("TEST" ("a" "b" "c")))
5299 (let ((anything-candidate-number-limit 2))
5300 (anything-test-candidates
5303 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5304 (insert "a\nb\nc\nd\n"))))
5305 (candidates . anything-candidates-in-buffer
)
5307 (candidate-number-limit .
3)
5310 (desc "multiple init")
5313 (anything-test-candidates
5315 (init (lambda () (setq a
1))
5316 (lambda () (setq b
2))))))
5320 (anything-test-candidates
5322 (init (lambda () (setq a
1))))))
5324 (desc "multiple cleanup")
5327 (anything-test-candidates
5329 (cleanup (lambda () (setq a
1))
5330 (lambda () (setq b
2))))))
5332 (desc "anything-mklist")
5334 (anything-mklist 1))
5336 (anything-mklist '(2)))
5337 (expect '((lambda ()))
5338 (anything-mklist (lambda ())))
5339 (desc "anything-before-initialize-hook")
5341 (let ((anything-before-initialize-hook '((lambda () (setq v
'called
))))
5343 (anything-initialize)
5345 (desc "anything-after-initialize-hook")
5347 (let ((anything-before-initialize-hook
5348 '((lambda () (setq v
'(a)))))
5349 (anything-after-initialize-hook
5350 '((lambda () (setq v
(cons 'b v
)))))
5352 (anything-initialize)
5355 (let ((anything-after-initialize-hook
5356 '((lambda () (setq v
(buffer-size (get-buffer anything-buffer
))))))
5358 (anything-initialize)
5360 (desc "get-line attribute")
5361 (expect '(("TEST" ("FOO+")))
5362 (anything-test-candidates
5365 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5366 (insert "foo+\nbar+\nbaz+\n"))))
5367 (candidates-in-buffer)
5368 (get-line .
(lambda (s e
) (upcase (buffer-substring-no-properties s e
))))))
5370 (desc "with-anything-restore-variables")
5373 (anything-restored-variables '(a b
)))
5374 (with-anything-restore-variables
5377 (desc "anything-cleanup-hook")
5379 (let ((anything-cleanup-hook
5380 '((lambda () (setq v
'called
))))
5384 (desc "with-anything-display-same-window")
5386 (save-window-excursion
5387 (delete-other-windows)
5390 (let ((buf (get-buffer-create " tmp"))
5391 (win (selected-window)))
5392 (with-anything-display-same-window
5393 (display-buffer buf
)
5394 (eq win
(get-buffer-window buf
))))))
5396 (save-window-excursion
5397 (delete-other-windows)
5400 (let ((buf (get-buffer-create " tmp"))
5401 (win (selected-window)))
5402 (with-anything-display-same-window
5404 (eq win
(get-buffer-window buf
))))))
5406 (save-window-excursion
5407 (delete-other-windows)
5410 (let ((buf (get-buffer-create " tmp"))
5411 (win (selected-window)))
5412 (with-anything-display-same-window
5413 (switch-to-buffer buf
)
5414 (eq win
(get-buffer-window buf
))))))
5416 (save-window-excursion
5417 (delete-other-windows)
5418 (let ((buf (get-buffer-create " tmp"))
5419 (win (selected-window)))
5420 (with-anything-display-same-window
5421 (display-buffer buf
)
5422 (eq win
(get-buffer-window buf
))))))
5424 (save-window-excursion
5425 (delete-other-windows)
5426 (let ((buf (get-buffer-create " tmp"))
5427 (win (selected-window)))
5428 (with-anything-display-same-window
5430 (eq win
(get-buffer-window buf
))))))
5431 (desc "search-from-end attribute")
5432 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5433 (anything-test-candidates
5436 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5437 (insert "foo+\nbar+\nbaz+\n"))))
5438 (candidates-in-buffer)
5439 (search-from-end)))))
5440 (expect '(("TEST" ("baz+" "bar+" "foo+")))
5441 (anything-test-candidates
5444 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5445 (insert "foo+\nbar+\nbaz+\n"))))
5446 (candidates-in-buffer)
5449 (expect '(("TEST" ("baz+" "bar+")))
5450 (anything-test-candidates
5453 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5454 (insert "foo+\nbar+\nbaz+\n"))))
5455 (candidates-in-buffer)
5457 (candidate-number-limit .
2)))))
5458 (expect '(("TEST" ("baz+" "bar+")))
5459 (anything-test-candidates
5462 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5463 (insert "foo+\nbar+\nbaz+\n"))))
5464 (candidates-in-buffer)
5466 (candidate-number-limit .
2)))
5468 (expect '(("a" ("c2" "c1")))
5469 (anything-test-candidates
5472 (with-current-buffer (anything-candidate-buffer 'global
)
5473 (insert "c1\nc2\n"))))
5475 (candidates-in-buffer)))))
5476 ;; BUG remain empty string, but the pattern is rare case.
5477 (expect '(("a" ("c" "b" "a" "")))
5478 (anything-test-candidates
5481 (with-current-buffer (anything-candidate-buffer 'global
)
5482 (insert "a\nb\nc\n"))))
5484 (candidates-in-buffer)))
5486 (desc "header-name attribute")
5487 (expect "original is transformed"
5488 (anything-test-update '(((name .
"original")
5492 (format "%s is transformed" name
)))))
5494 (with-current-buffer (anything-buffer-get)
5496 (overlay-get (car (overlays-at (1+(point-min)))) 'display
)))
5497 (desc "volatile and match attribute")
5498 ;; candidates function is called once per `anything-process-delayed-sources'
5501 (anything-test-candidates '(((name .
"test")
5502 (candidates .
(lambda () (incf v
) '("ok")))
5504 (match identity identity identity
)))
5507 (desc "accept-empty attribute")
5509 (anything-test-candidates
5510 '(((name .
"test") (candidates "") (action . identity
))))
5511 (anything-execute-selection-action))
5513 (anything-test-candidates
5514 '(((name .
"test") (candidates "") (action . identity
) (accept-empty))))
5515 (anything-execute-selection-action))
5516 (desc "anything-tick-hash")
5518 (with-current-buffer (get-buffer-create " *00create+*")
5519 (puthash " *00create+*/xxx" 1 anything-tick-hash
)
5520 (kill-buffer (current-buffer)))
5521 (gethash " *00create+*/xxx" anything-tick-hash
))
5522 (desc "anything-execute-action-at-once-if-once")
5524 (let ((anything-execute-action-at-once-if-one t
))
5525 (anything '(((name .
"one test1")
5527 (action . upcase
))))))
5529 (let ((anything-execute-action-at-once-if-one t
))
5530 (anything '(((name .
"one test2")
5531 (candidates "hoge" "any")
5535 (expect (mock (read-string "word: " nil
))
5536 (let ((anything-execute-action-at-once-if-one t
))
5537 (anything '(((name .
"one test3")
5538 (candidates "hoge" "foo" "bar")
5539 (action . identity
)))
5541 (desc "anything-quit-if-no-candidate")
5543 (let ((anything-quit-if-no-candidate t
))
5544 (anything '(((name .
"zero test1") (candidates) (action . upcase
))))))
5546 (let (v (anything-quit-if-no-candidate (lambda () (setq v
'called
))))
5547 (anything '(((name .
"zero test2") (candidates) (action . upcase
))))
5549 (desc "real-to-display attribute")
5550 (expect '(("test" (("DDD" .
"ddd"))))
5551 (anything-test-candidates '(((name .
"test")
5553 (real-to-display . upcase
)
5554 (action . identity
)))))
5555 (expect '(("test" (("DDD" .
"ddd"))))
5556 (anything-test-candidates '(((name .
"test")
5557 (candidates ("ignored" .
"ddd"))
5558 (real-to-display . upcase
)
5559 (action . identity
)))))
5560 (expect '(("Commands" (("xxxhoge" .
"hoge") ("xxxboke" .
"boke"))))
5561 (anything-test-candidates '(((name .
"Commands")
5564 (real-to-display .
(lambda (x) (concat "xxx" x
)))
5565 (action . identity
)))
5567 (expect "test\nDDD\n"
5568 (anything-test-update '(((name .
"test")
5570 (real-to-display . upcase
)
5571 (action . identity
)))
5573 (with-current-buffer (anything-buffer-get) (buffer-string)))
5574 (desc "real-to-display and candidate-transformer attribute")
5575 (expect '(("test" (("DDD" .
"ddd"))))
5576 (anything-test-candidates
5579 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c
)) cands
)))
5580 (real-to-display . upcase
)
5581 (action . identity
)))))
5582 (expect "test\nDDD\n"
5583 (anything-test-update
5586 (candidate-transformer (lambda (cands) (mapcar (lambda (c) (cons "X" c
)) cands
)))
5587 (real-to-display . upcase
)
5588 (action . identity
)))
5590 (with-current-buffer (anything-buffer-get) (buffer-string)))
5591 (desc "real-to-display and candidates-in-buffer")
5592 (expect '(("test" (("A" .
"a") ("B" .
"b"))))
5593 (anything-test-candidates
5596 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5598 (insert "a\nb\n"))))
5599 (candidates-in-buffer)
5600 (real-to-display . upcase
)
5601 (action . identity
)))))
5602 (expect "test\nA\nB\n"
5607 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5609 (insert "a\nb\n"))))
5610 (candidates-in-buffer)
5611 (real-to-display . upcase
)
5612 (action . identity
))))
5613 (with-current-buffer (anything-buffer-get) (buffer-string)))
5614 (desc "Symbols are acceptable as candidate.")
5615 (expect '(("test" (sym "str")))
5616 (anything-test-candidates
5618 (candidates sym
"str")))))
5619 (expect '(("test" ((sym . realsym
) ("str" .
"realstr"))))
5620 (anything-test-candidates
5622 (candidates (sym . realsym
) ("str" .
"realstr"))))))
5623 (expect '(("test" (sym)))
5624 (anything-test-candidates
5626 (candidates sym
"str")))
5628 (expect '(("test" ("str")))
5629 (anything-test-candidates
5631 (candidates sym
"str")))
5633 (expect '(("test" ((sym . realsym
))))
5634 (anything-test-candidates
5636 (candidates (sym . realsym
) ("str" .
"realstr"))))
5638 (expect '(("test" (("str" .
"realstr"))))
5639 (anything-test-candidates
5641 (candidates (sym . realsym
) ("str" .
"realstr"))))
5643 (desc "multiple transformers")
5644 (expect '(("test" ("<FOO>")))
5645 (anything-test-candidates
5648 (candidate-transformer
5650 (anything-compose (list cands
)
5651 (list (lambda (c) (mapcar 'upcase c
))
5652 (lambda (c) (list (concat "<" (car c
) ">")))))))))))
5654 (anything-composed-funcall-with-source
5656 (list (lambda (c) (mapcar 'upcase c
))
5657 (lambda (c) (list (concat "<" (car c
) ">"))))
5660 (expect '(("test" ("<FOO>")))
5661 (anything-test-candidates
5664 (candidate-transformer
5665 (lambda (c) (mapcar 'upcase c
))
5666 (lambda (c) (list (concat "<" (car c
) ">"))))))))
5667 (expect '(("test" ("<BAR>")))
5668 (anything-test-candidates
5671 (filtered-candidate-transformer
5672 (lambda (c s
) (mapcar 'upcase c
))
5673 (lambda (c s
) (list (concat "<" (car c
) ">"))))))))
5674 (expect '(("find-file" . find-file
)
5675 ("view-file" . view-file
))
5677 (stub anything-get-current-source
5678 => '((name .
"test")
5684 (list (lambda (a s
) (push '("view-file" . view-file
) a
))
5685 (lambda (a s
) (push '("find-file" . find-file
) a
))))))))
5686 (anything-get-action))
5687 (expect '(("find-file" . find-file
)
5688 ("view-file" . view-file
))
5690 (stub anything-get-current-source
5691 => '((name .
"test")
5694 (lambda (a s
) (push '("view-file" . view-file
) a
))
5695 (lambda (a s
) (push '("find-file" . find-file
) a
)))))
5696 (anything-get-action))
5697 (desc "define-anything-type-attribute")
5698 (expect '((file (action . find-file
)))
5699 (let (anything-type-attributes)
5700 (define-anything-type-attribute 'file
'((action . find-file
)))
5701 anything-type-attributes
))
5702 (expect '((file (action . find-file
)))
5703 (let ((anything-type-attributes '((file (action . view-file
)))))
5704 (define-anything-type-attribute 'file
'((action . find-file
)))
5705 anything-type-attributes
))
5706 (expect '((file (action . find-file
))
5707 (buffer (action . switch-to-buffer
)))
5708 (let (anything-type-attributes)
5709 (define-anything-type-attribute 'buffer
'((action . switch-to-buffer
)))
5710 (define-anything-type-attribute 'file
'((action . find-file
)))
5711 anything-type-attributes
))
5712 (desc "anything-approximate-candidate-number")
5715 (let ((anything-buffer (current-buffer)))
5716 (anything-approximate-candidate-number))))
5719 (let ((anything-buffer (current-buffer)))
5722 (anything-approximate-candidate-number))))
5725 (let ((anything-buffer (current-buffer)))
5729 (<= 2 (anything-approximate-candidate-number)))))
5732 (let ((anything-buffer (current-buffer)))
5734 (propertize "multi\nline\n" 'anything-multiline t
))
5735 (anything-approximate-candidate-number))))
5738 (let ((anything-buffer (current-buffer))
5739 (anything-candidate-separator "-----"))
5741 (propertize "multi\nline1\n" 'anything-multiline t
)
5743 (propertize "multi\nline2\n" 'anything-multiline t
))
5744 (<= 2 (anything-approximate-candidate-number)))))
5745 (desc "delayed-init attribute")
5748 (anything-test-candidates '(((name .
"test")
5749 (delayed-init .
(lambda () (incf value
)))
5751 (requires-pattern .
2)))
5756 (anything-test-candidates '(((name .
"test")
5757 (delayed-init .
(lambda () (incf value
)))
5759 (requires-pattern .
2)))
5764 (anything-test-candidates '(((name .
"test")
5765 (delayed-init (lambda () (incf value
))
5766 (lambda () (incf value
)))
5768 (requires-pattern .
2)))
5774 (anything-test-candidates '(((name .
"test")
5776 .
(lambda () (setq value
5777 (eq anything-current-buffer
(current-buffer)))))
5779 (requires-pattern .
2)))
5782 (desc "pattern-transformer attribute")
5783 (expect '(("test2" ("foo")) ("test3" ("bar")))
5784 (anything-test-candidates '(((name .
"test1")
5785 (candidates "foo" "bar"))
5787 (pattern-transformer .
(lambda (pat) (substring pat
1)))
5788 (candidates "foo" "bar"))
5790 (pattern-transformer .
(lambda (pat) "bar"))
5791 (candidates "foo" "bar")))
5793 (expect '(("test2" ("foo")) ("test3" ("bar")))
5794 (anything-test-candidates '(((name .
"test1")
5795 (candidates "foo" "bar"))
5797 (pattern-transformer (lambda (pat) (substring pat
1)))
5798 (candidates "foo" "bar"))
5800 (pattern-transformer (lambda (pat) "bar"))
5801 (candidates "foo" "bar")))
5803 (expect '(("test2" ("foo")) ("test3" ("bar")))
5804 (anything-test-candidates '(((name .
"test1")
5806 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5807 (insert "foo\nbar\n"))))
5808 (candidates-in-buffer))
5810 (pattern-transformer .
(lambda (pat) (substring pat
1)))
5812 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5813 (insert "foo\nbar\n"))))
5814 (candidates-in-buffer))
5816 (pattern-transformer .
(lambda (pat) "bar"))
5818 .
(lambda () (with-current-buffer (anything-candidate-buffer 'global
)
5819 (insert "foo\nbar\n"))))
5820 (candidates-in-buffer)))
5822 (desc "anything-recent-push")
5823 (expect '("foo" "bar" "baz")
5824 (let ((lst '("bar" "baz")))
5825 (anything-recent-push "foo" 'lst
)))
5826 (expect '("foo" "bar" "baz")
5827 (let ((lst '("foo" "bar" "baz")))
5828 (anything-recent-push "foo" 'lst
)))
5829 (expect '("foo" "bar" "baz")
5830 (let ((lst '("bar" "foo" "baz")))
5831 (anything-recent-push "foo" 'lst
)))
5832 (desc "anything-require-at-least-version")
5834 (anything-require-at-least-version "1.1"))
5836 (anything-require-at-least-version "1.200"))
5838 (anything-require-at-least-version
5839 (and (string-match "1\.\\([0-9]+\\)" anything-version
)
5840 (match-string 0 anything-version
))))
5842 (anything-require-at-least-version "1.999"))
5844 (anything-require-at-least-version "1.2000"))
5845 (desc "anything-once")
5848 (anything-test-candidates
5850 (init .
(lambda () (incf i
))))
5852 (init .
(lambda () (incf i
))))))
5856 (anything-test-candidates
5858 (init .
(lambda () (anything-once (lambda () (incf i
))))))
5860 (init .
(lambda () (anything-once (lambda () (incf i
))))))))
5864 (flet ((init1 () (anything-once (lambda () (incf i
)))))
5865 (anything-test-candidates
5871 (desc "anything-marked-candidates")
5872 (expect '("mark3" "mark1")
5873 (let* ((source '((name .
"mark test")))
5874 (anything-marked-candidates
5875 `((,source .
"mark1")
5876 (((name .
"other")) .
"mark2")
5877 (,source .
"mark3"))))
5878 (stub anything-buffer-get
=> (current-buffer))
5879 (stub anything-get-current-source
=> source
)
5880 (anything-marked-candidates)))
5881 (expect '("current")
5882 (let* ((source '((name .
"mark test")))
5883 (anything-marked-candidates nil
))
5884 (stub anything-get-current-source
=> source
)
5885 (stub anything-get-selection
=> "current")
5886 (anything-marked-candidates)))
5887 (desc "anything-marked-candidates with coerce")
5888 (expect '(mark3 mark1
)
5889 (let* ((source '((name .
"mark test")
5891 (anything-marked-candidates
5892 `((,source .
"mark1")
5893 (((name .
"other")) .
"mark2")
5894 (,source .
"mark3"))))
5895 (stub anything-buffer-get
=> (current-buffer))
5896 (stub anything-get-current-source
=> source
)
5897 (anything-marked-candidates)))
5898 (desc "anything-let")
5899 (expect '(1 10000 nil
)
5903 (anything-buffer (exps-tmpbuf)))
5904 (anything-let ((a 1)
5907 (anything-create-anything-buffer))
5908 (with-current-buffer anything-buffer
5914 (anything-buffer (exps-tmpbuf)))
5915 (anything-let ((a 1)
5918 (anything-create-anything-buffer))
5919 (with-current-buffer anything-buffer
5920 (and (assq 'a
(buffer-local-variables))
5921 (assq 'b
(buffer-local-variables))
5922 (assq 'c
(buffer-local-variables))))))
5927 (anything-buffer (exps-tmpbuf)))
5928 (anything-let ((a 1)
5932 (desc "anything-let*")
5937 (anything-buffer (exps-tmpbuf)))
5938 (anything-let* ((a 1)
5941 (anything-create-anything-buffer))
5942 (with-current-buffer anything-buffer
5948 (anything-buffer (exps-tmpbuf)))
5949 (anything-let* ((a 1)
5952 (anything-create-anything-buffer))
5953 (with-current-buffer anything-buffer
5954 (and (assq 'a
(buffer-local-variables))
5955 (assq 'b
(buffer-local-variables))
5956 (assq 'c
(buffer-local-variables))))))
5961 (anything-buffer (exps-tmpbuf)))
5962 (anything-let* ((a 1)
5966 (desc "anything with keyword")
5967 (expect (mock (anything-internal 'test-source
"input" "prompt: " nil
"preselect" "*test*" nil
))
5968 (anything :sources
'test-source
5972 :preselect
"preselect"
5975 (expect (mock (anything-internal 'test-source nil nil nil nil
"*test*" nil
))
5976 (anything :sources
'test-source
5978 :candidate-number-limit
20))
5979 (expect (mock (anything-internal 'test-source nil nil nil nil
"*test*" nil
))
5980 (anything 'test-source nil nil nil nil
"*test*" nil
))
5981 (desc "anything-log-eval-internal")
5982 (expect (mock (anything-log "%S = %S" '(+ 1 2) 3))
5983 (anything-log-eval-internal '((+ 1 2))))
5984 (expect (mock (anything-log "%S = ERROR!" 'unDeFined
))
5985 (anything-log-eval-internal '(unDeFined)))
5987 (desc "anything-output-filter--collect-candidates")
5988 (expect '("a" "b" "")
5989 (split-string "a\nb\n" "\n"))
5991 (anything-output-filter--collect-candidates
5992 '("a" "b" "") (cons 'incomplete-line
"")))
5994 (split-string "a\nb" "\n"))
5996 (anything-output-filter--collect-candidates
5997 '("a" "b") (cons 'incomplete-line
"")))
5998 (expect '(incomplete-line .
"b")
5999 (let ((incomplete-line-info (cons 'incomplete-line
"")))
6000 (anything-output-filter--collect-candidates
6001 '("a" "b") incomplete-line-info
)
6002 incomplete-line-info
))
6003 (expect '("" "c" "")
6004 (split-string "\nc\n" "\n"))
6007 (let ((incomplete-line-info (cons 'incomplete-line
"")))
6008 (anything-output-filter--collect-candidates
6009 '("a" "b") incomplete-line-info
)
6010 (anything-output-filter--collect-candidates
6011 '("" "c" "") incomplete-line-info
)))
6012 (desc "coerce attribute")
6014 (anything :sources
'(((name .
"test")
6015 (candidates "string")
6016 (action . identity
)))
6017 :execute-action-at-once-if-one t
))
6019 (anything :sources
'(((name .
"test")
6020 (candidates "symbol")
6022 (action . identity
)))
6023 :execute-action-at-once-if-one t
))
6025 (anything :sources
'(((name .
"test")
6026 (candidates ("display" .
"real"))
6028 (action . identity
)))
6029 :execute-action-at-once-if-one t
))
6031 (anything :sources
'(((name .
"test")
6033 (candidate-transformer
6034 (lambda (c) '(("display" .
"real"))))
6036 (action . identity
)))
6037 :execute-action-at-once-if-one t
))
6039 (anything :sources
'(((name .
"test")
6041 (filtered-candidate-transformer
6042 (lambda (c s
) '(("display" .
"real"))))
6044 (action . identity
)))
6045 :execute-action-at-once-if-one t
))
6047 (anything :sources
'(((name .
"test")
6048 (candidates "dummy")
6049 (display-to-real (lambda (disp) "real"))
6051 (action . identity
)))
6052 :execute-action-at-once-if-one t
))
6053 (desc "anything-next-point-in-list")
6055 (anything-next-point-in-list 5 '(10 20) nil
))
6057 (anything-next-point-in-list 15 '(10 20) nil
))
6059 (anything-next-point-in-list 25 '(10 20) nil
))
6061 (anything-next-point-in-list 5 '(10 20) t
))
6063 (anything-next-point-in-list 15 '(10 20) t
))
6065 (anything-next-point-in-list 25 '(10 20) t
))
6067 (anything-next-point-in-list 5 '() nil
))
6069 (anything-next-point-in-list 5 '() t
))
6071 (anything-next-point-in-list 5 '(10) nil
))
6073 (anything-next-point-in-list 15 '(10) t
))
6075 (anything-next-point-in-list 10 '(10 20) nil
))
6077 (anything-next-point-in-list 20 '(10 20) t
))
6079 (anything-next-point-in-list 30 '(10 20 30) t
))
6084 ;; How to save (DO NOT REMOVE!!)
6085 ;; (progn (magit-push) (emacswiki-post "anything.el"))
6089 ;;; anything.el ends here