Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
5773 lines (5193 sloc) 230 KB
;;;; anything.el --- open anything / QuickSilver-like
;;;; candidate-selection framework
;; $Id: anything.el,v 1.248 2010/02/20 12:34:38 rubikitch Exp $
;; Copyright (C) 2007 Tamas Patrovics
;; 2008, 2009, 2010 rubikitch <>
;; Author: Tamas Patrovics
;; Maintainer: rubikitch <>
;; Keywords: files, frames, help, matching, outlines, processes,
;; tools, convenience, anything
;; URL:
;; Site:
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Start with M-x anything, narrow the list by typing some pattern,
;; select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter,
;; left/right moves between sources. With TAB actions can be selected
;; if the selected candidate has more than one possible action.
;; Note that anything.el provides only the framework and some example
;; configurations for demonstration purposes. See anything-config.el
;; for practical, polished, easy to use configurations which can be
;; used to assemble a custom personalized configuration. And many
;; other configurations are in the EmacsWiki.
;; Maintainer's configuration is in the EmacsWiki. It would tell you
;; many tips to write smart sources!
;; Here is Japanese translation of `anything-sources'
;; attributes. Thanks.
;;; Commands:
;; Below are complete command list:
;; `anything'
;; Select anything. In Lisp program, some optional arguments can be
;; `anything-resume'
;; Resurrect previously invoked `anything'.
;; `anything-at-point'
;; Same as `anything' except when C-u is pressed, the initial input
;;is the symbol at point.
;; `anything-select-action'
;; Select an action for the currently selected candidate.
;; `anything-previous-line'
;; Move selection to the previous line.
;; `anything-next-line'
;; Move selection to the next line.
;; `anything-previous-page'
;; Move selection back with a pageful.
;; `anything-next-page'
;; Move selection forward with a pageful.
;; `anything-beginning-of-buffer'
;; Move selection at the top.
;; `anything-end-of-buffer'
;; Move selection at the bottom.
;; `anything-previous-source'
;; Move selection to the previous source.
;; `anything-next-source'
;; Move selection to the next source.
;; `anything-exit-minibuffer'
;; Select the current candidate by exiting the minibuffer.
;; `anything-delete-current-selection'
;; Delete the currently selected item.
;; `anything-delete-minibuffer-content'
;; Same as `delete-minibuffer-contents' but this is a command.
;; `anything-toggle-resplit-window'
;; Toggle resplit anything window, vertically or horizontally.
;; `anything-select-2nd-action'
;; Select the 2nd action for the currently selected candidate.
;; `anything-select-3rd-action'
;; Select the 3rd action for the currently selected candidate.
;; `anything-select-4th-action'
;; Select the 4th action for the currently selected candidate.
;; `anything-select-2nd-action-or-end-of-line'
;; Select the 2nd action for the currently selected candidate if
;;the point is at the end of minibuffer.
;; `anything-execute-persistent-action'
;; If a candidate is selected then perform the associated action
;;without quitting anything.
;; `anything-scroll-other-window'
;; Scroll other window (not *Anything* window) upward.
;; `anything-scroll-other-window-down'
;; Scroll other window (not *Anything* window) downward.
;; `anything-quit-and-find-file'
;; Drop into `find-file' from `anything' like `iswitchb-find-file'.
;; `anything-yank-selection'
;; Set minibuffer contents to current selection.
;; `anything-kill-selection-and-quit'
;; Store current selection to kill ring.
;; `anything-follow-mode'
;; If this mode is on, persistent action is executed everytime the
;;cursor is moved.
;; `anything-isearch'
;; Start incremental search within results. (UNMAINTAINED)
;; `anything-isearch-printing-char'
;; Add printing char to the pattern.
;; `anything-isearch-again'
;; Search again for the current pattern
;; `anything-isearch-delete'
;; Undo last event.
;; `anything-isearch-default-action'
;; Execute the default action for the selected candidate.
;; `anything-isearch-select-action'
;; Choose an action for the selected candidate.
;; `anything-isearch-cancel'
;; Cancel Anything isearch.
;; `anything-iswitchb-setup'
;; Integrate anything completion into iswitchb (UNMAINTAINED).
;; `anything-iswitchb-cancel-anything'
;; Cancel anything completion and return to standard iswitchb.
;;; Customizable Options:
;; Below are customizable option list:
;; You can extend `anything' by writing plug-ins. As soon as
;; `anything' is invoked, `anything-sources' is compiled into basic
;; attributes, then compiled one is used during invocation.
;; The oldest built-in plug-in is `type' attribute: appends
;; appropriate element of `anything-type-attributes'. Second built-in
;; plug-in is `candidates-in-buffer': selecting a line from candidates
;; buffer.
;; To write a plug-in:
;; 1. Define a compiler: anything-compile-source--*
;; 2. Add compier function to `anything-compile-source-functions'.
;; 3. (optional) Write helper functions.
;; Anything plug-ins are found in the EmacsWiki.
;; Tested on Emacs 22/23.
;; Thanks to Vagn Johansen for ideas.
;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
;; Thanks to Tassilo Horn for fixes.
;; Thanks to Drew Adams for various fixes (frame, isearch,
;;customization, etc.)
;; Thanks to IMAKADO for candidates-in-buffer idea.
;; Thanks to Tomohiro MATSUYAMA for multiline patch.
;;; (@* "Index")
;; If you have library `linkd.el', load
;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
;; navigate around the sections Linkd mode will
;; highlight this Index. You can get `linkd.el' here:
;; v1.114
;; `anything-attr' returns nil when the source attribute is defined
;; but the value of attribute is nil, eg. (volatile) cell. Use
;; `anything-attr-defined' when testing whether the attribute is
;; defined.
;;; (@* "Tips")
;; Now symbols are acceptable as candidates. So you do not have to use
;; `symbol-name' function. The source is much simpler. For example,
;; `apropos-internal' returns a list of symbols.
;; (anything
;; '(((name . "Commands")
;; (candidates . (lambda () (apropos-internal anything-pattern
;; 'commandp)))
;; (volatile)
;; (action . describe-function))))
;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
;; marked candidate, press M-[ or M-].
;; `anything-map' is now Emacs-standard key bindings by default. If
;; you are using `iswitchb', execute `anything-iswitchb-setup'. Then
;; some key bindings are adjusted to `iswitchb'. Note that
;; anything-iswitchb is not maintained.
;; There are many `anything' applications, using `anything' for
;; selecting candidate. In this case, if there is one candidate or no
;; candidate, popping up *anything* buffer is irritating. If one
;; candidate, you want to select it at once. If no candidate, you want
;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
;; that setting these variables GLOBALLY is bad idea because of
;; delayed sources. These are meant to be let-binded.
;; See anything-etags.el for example.
;; [EVAL IT] (install-elisp
;; "")
;; ex.
;; (let ((anything-execute-action-at-once-if-one t)
;; (anything-quit-if-no-candidate (lambda () (message "No
;; candidate"))))
;; (anything temporary-sources input))
;; `set-frame-configuration' arises flickering. If you hate
;; flickering, eval:
;; (setq anything-save-configuration-functions
;; '(set-window-configuration . current-window-configuration))
;; at the cost of restoring frame configuration (only window
;; configuration).
;; `anything-delete-current-selection' deletes the current line.
;; It is useful when deleting a candidate in persistent action.
;; eg. `kill-buffer'.
;; [EVAL IT] (describe-function 'anything-delete-current-selection)
;; `anything-attr' gets the attribute. `anything-attrset' sets the
;; attribute. `anything-attr-defined' tests whether the attribute is
;; defined. They handles source-local variables.
;; [EVAL IT] (describe-function 'anything-attr)
;; [EVAL IT] (describe-function 'anything-attrset)
;; [EVAL IT] (describe-function 'anything-attr-defined)
;; `anything-sources' accepts many attributes to make your life
;; easier.
;; Now `anything-sources' accepts a list of symbols.
;; [EVAL IT] (describe-variable 'anything-sources)
;; `anything' has optional arguments. Now you do not have to let-bind
;; `anything-sources'.
;; [EVAL IT] (describe-function 'anything)
;; `anything-resume' resumes last `anything' session. Now you do not
;; have to retype pattern.
;; [EVAL IT] (describe-function 'anything-resume)
;; `anything-execute-persistent-action' executes action without
;; quitting `anything'. When popping up a buffer in other window by
;; persistent action, you can scroll with
;; `anything-scroll-other-window' and
;; `anything-scroll-other-window-down'. See also `anything-sources'
;; docstring.
;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
;; [EVAL IT] (describe-variable 'anything-sources)
;; `anything-select-2nd-action', `anything-select-3rd-action' and
;; `anything-select-4th-action' select other than default action
;; without pressing Tab.
;; Using `anything-candidate-buffer' and the candidates-in-buffer
;; attribute is much faster than traditional "candidates and match"
;; way. And `anything-current-buffer-is-modified' avoids to
;; recalculate candidates for unmodified buffer. See docstring of
;; them.
;; [EVAL IT] (describe-function 'anything-candidate-buffer)
;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
;; `anything-current-buffer' and `anything-buffer-file-name' stores
;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
;; is invoked. Use them freely.
;; [EVAL IT] (describe-variable 'anything-current-buffer)
;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
;; `anything-completing-read' and `anything-read-file-name' are
;; experimental implementation. If you are curious, type M-x
;; anything-read-string-mode. It is a minor mode and toggles on/off.
;; Use `anything-test-candidates' to test your handmade anything
;; sources. It simulates contents of *anything* buffer with pseudo
;; `anything-sources' and `anything-pattern', without side-effect. So
;; you can unit-test your anything sources! Let's TDD!
;; [EVAL IT] (describe-function 'anything-test-candidates)
;; There are many unit-testing framework in Emacs Lisp. See the
;; EmacsWiki.
;; There is an unit-test by Emacs Lisp Expectations at the tail of
;; this file.
;; (@* "TODO")
;; - process status indication
;; - async sources doesn't honor digit-shortcut-count
;; - anything-candidate-number-limit can't be nil everywhere
;; (@* "HISTORY")
;; $Log: anything.el,v $
;; Revision 1.248 2010/02/20 12:34:38 rubikitch
;; Mode-line help!! `anything-mode-line-string' is help string.
;; Revision 1.247 2010/02/20 10:41:39 rubikitch
;; Automatically update `anything-version' when upgrading
;; Revision 1.246 2010/02/20 10:38:58 rubikitch
;; update copyright
;; Revision 1.245 2010/02/20 10:36:01 rubikitch
;; New API: `anything-require-at-least-version'
;; Revision 1.244 2010/02/20 10:06:54 rubikitch
;; * New plug-in: `disable-shortcuts'
;; * `dummy' plug-in implies `disable-shortcuts' because it enables us
;; to input capital letters.
;; Revision 1.243 2010/02/20 09:54:16 rubikitch
;; `anything-compile-source--dummy': swap arguments of `append'
;; Revision 1.242 2010/02/19 17:37:12 rubikitch
;; error check in `anything-set-source-filter'
;; Revision 1.241 2010/01/29 18:53:17 rubikitch
;; Fix a bug of `candidate-number-limit' in process sources.
;; Revision 1.240 2010/01/23 04:21:31 rubikitch
;; * `anything': Use `anything-display-buffer' as fallback
;; * `anything-select-with-digit-shortcut': `self-insert-command' if
;; disabled
;; Revision 1.239 2009/12/28 07:33:28 rubikitch
;; New command: `anything-toggle-resplit-window' (C-t)
;; Revision 1.238 2009/12/28 07:19:37 rubikitch
;; bugfix
;; Revision 1.237 2009/12/28 07:15:30 rubikitch
;; `anything-window-configuration' stores window configuration only.
;; Revision 1.236 2009/12/28 07:07:09 rubikitch
;; `anything-resume' resumes window configuration now.
;; Revision 1.235 2009/12/28 04:12:33 rubikitch
;; Fix tiny bug
;; Revision 1.234 2009/12/28 03:57:33 rubikitch
;; `anything-resume': New optional argument
;; Revision 1.233 2009/12/28 03:43:12 rubikitch
;; remove warnings
;; Revision 1.232 2009/12/28 03:37:25 rubikitch
;; refactoring
;; Revision 1.231 2009/12/28 02:33:41 rubikitch
;; refactoring
;; Revision 1.230 2009/12/27 09:28:06 rubikitch
;; `anything-window-configuration' save/restore anything window
;; configuration (NOT YET)
;; Revision 1.229 2009/12/26 21:41:33 rubikitch
;; revive `anything-input' when resuming
;; Revision 1.228 2009/12/25 01:34:35 rubikitch
;; * `anything-resume' use anything interface to select anything
;; buffers.
;; * Its candidates are sorted by most recently used order.
;; * 4th arg of `anything' accepts 'noresume not to resume this
;; session.
;; Revision 1.227 2009/12/19 20:30:12 rubikitch
;; add `pattern-transformer' doc
;; Revision 1.226 2009/12/19 20:15:47 rubikitch
;; pattern-transformer can have multiple functions now
;; Revision 1.225 2009/12/19 20:11:16 rubikitch
;; add `delayed-init' doc
;; Revision 1.224 2009/12/19 12:26:00 rubikitch
;; New attribute `pattern-transformer'
;; Revision 1.223 2009/12/19 11:57:41 rubikitch
;; New attribute `delayed-init'
;; Revision 1.222 2009/12/14 20:55:23 rubikitch
;; Fix display bug: `anything-enable-digit-shortcuts' / multiline
;; Revision 1.221 2009/12/14 20:29:49 rubikitch
;; fix an error when executing `anything-prev-visible-mark' with no
;; visible marks.
;; Revision 1.220 2009/12/14 20:19:05 rubikitch
;; Bugfix about anything-execute-action-at-once-if-one and multiline
;; Revision 1.219 2009/12/14 03:21:11 rubikitch
;; Extend alphabet shortcuts to A-Z
;; Revision 1.218 2009/12/13 01:03:34 rubikitch
;; Changed data structure of `anything-shortcut-keys-alist'
;; Revision 1.217 2009/12/03 23:16:17 rubikitch
;; silence warning
;; Revision 1.216 2009/12/03 20:43:51 rubikitch
;; Add keybindings for alphabet shortcuts
;; Revision 1.215 2009/12/03 20:37:13 rubikitch
;; `anything-enable-shortcuts' is an alias of
;; `anything-enable-digit-shortcuts'.
;; Alphabet shortcuts can be used now.
;; Revision 1.214 2009/12/03 20:23:40 rubikitch
;; `anything-enable-digit-shortcuts' also accepts 'alphabet.
;; Now alphabet shortcuts are usable.
;; Revision 1.213 2009/12/03 09:59:58 rubikitch
;; refactoring
;; Revision 1.212 2009/11/15 09:42:15 rubikitch
;; refactoring
;; Revision 1.211 2009/11/06 21:42:58 rubikitch
;; New command: `anything-beginning-of-buffer',
;; `anything-end-of-buffer'
;; Revision 1.210 2009/10/22 13:30:06 rubikitch
;; `real-to-display' function is evaluated just after
;; `candidate-transformer' function now.
;; This enables us to narrow candidates by display string by
;; `real-to-display'.
;; Revision 1.209 2009/10/21 20:25:10 rubikitch
;; Add a document. (no code change)
;; Revision 1.208 2009/10/21 11:31:15 rubikitch
;; `anything': accept one source alist
;; Revision 1.207 2009/10/16 19:47:39 rubikitch
;; Link to Japanese translation of `anything-sources' attributes. (No
;; code change)
;; Revision 1.206 2009/10/10 09:28:54 rubikitch
;; Remove an unnecessary test
;; Revision 1.205 2009/10/10 06:21:28 rubikitch
;; obsolete: `anything-c-marked-candidate-list'
;; New function: `anything-marked-candidates'
;; Revision 1.204 2009/10/06 21:01:12 rubikitch
;; Call `anything-process-delayed-sources' only if delayed-sources is
;; available.
;; Revision 1.203 2009/10/02 10:04:07 rubikitch
;; Tested on Emacs23 too. (no code change)
;; Revision 1.202 2009/10/02 10:03:34 rubikitch
;; * Display "no candidates" rather than assertion
;; * Ensure to call `remove-hook' in `anything-current-buffer'
;; Revision 1.201 2009/08/08 13:25:30 rubikitch
;; `anything-toggle-visible-mark': move next line after unmarking
;; Revision 1.200 2009/08/08 13:23:46 rubikitch
;; `anything-toggle-visible-mark': Applied ThierryVolpiatto's
;; patch. thx.
;; Revision 1.199 2009/07/19 13:22:29 rubikitch
;; `anything-follow-execute-persistent-action-maybe': execute
;; persistent action after `anything-input-idle-delay'
;; Revision 1.198 2009/07/06 15:22:48 rubikitch
;; header modified (no code change)
;; Revision 1.197 2009/06/29 15:10:13 rubikitch
;; OOPS! remove debug code
;; Revision 1.196 2009/06/29 13:29:25 rubikitch
;; anything-follow-mode: automatical execution of persistent-action
;; (C-c C-f)
;; Revision 1.195 2009/06/19 14:42:57 rubikitch
;; silence byte compiler
;; Revision 1.194 2009/06/14 15:12:34 rubikitch
;; typo
;; Revision 1.193 2009/06/08 19:37:12 rubikitch
;; typo!
;; Revision 1.192 2009/06/08 19:36:39 rubikitch
;; New keybind: C-e, C-j, C-k
;; Revision 1.191 2009/06/08 19:30:27 rubikitch
;; New command: `anything-select-2nd-action-or-end-of-line'
;; Revision 1.190 2009/06/07 17:09:50 rubikitch
;; add M-<next>, C-M-S-v, M-<prior> to `anything-map'.
;; Revision 1.189 2009/06/01 21:36:31 rubikitch
;; New function: `anything-other-buffer'
;; Revision 1.188 2009/05/29 18:33:07 rubikitch
;; avoid error when executing (anything-mark-current-line) in async
;; process.
;; Revision 1.187 2009/05/29 06:49:05 rubikitch
;; small refactoring
;; Revision 1.186 2009/05/29 06:46:34 rubikitch
;; Prevent `anything-isearch-map' from overwriting `global-map'. With
;; `copy-keymap', the prefix command "M-s" in `global-map' ends up
;; getting clobbered by `anything-isearch-again', preventing `occur'
;; (among other things) from running. This change replaces overwriting
;; a
;; copied map with writing to a sparse map whose parent is
;; `global-map'.
;; patched by DanielHackney. thanks!
;; Revision 1.185 2009/05/25 19:07:42 rubikitch
;; `anything': set `case-fold-search' to t
;; Because users can assign commands to capital letter keys.
;; Revision 1.184 2009/05/25 19:05:04 rubikitch
;; Added auto-document
;; Revision 1.183 2009/05/15 01:50:46 rubikitch
;; typo
;; Revision 1.182 2009/05/08 18:28:18 rubikitch
;; Bug fix: `anything-attr' is usable in `header-name' function.
;; Revision 1.181 2009/05/04 19:05:03 rubikitch
;; * `anything-yank-selection' and `anything-kill-selection-and-quit'
;; handles display string now.
;; * `anything-get-selection': Added optional arguments.
;; Revision 1.180 2009/05/03 19:03:34 rubikitch
;; Add `anything-input' to `minibuffer-history' even if `anything' is
;; quit.
;; Revision 1.179 2009/04/20 16:35:44 rubikitch
;; New keybindings in anything-map:
;; C-c C-d: `anything-delete-current-selection'
;; C-c C-y: `anything-yank-selection'
;; C-c C-k: `anything-kill-selection-and-quit'
;; Revision 1.178 2009/04/20 16:18:58 rubikitch
;; New variable: `anything-display-function'
;; Revision 1.177 2009/04/20 02:17:16 rubikitch
;; New commands: `anything-yank-selection',
;; `anything-kill-selection-and-quit'
;; Revision 1.176 2009/04/08 14:48:15 rubikitch
;; bug fix in `anything-candidate-buffer'
;; Revision 1.175 2009/03/22 19:10:37 rubikitch
;; New Variable: `anything-scroll-amount' (thx. ThierryVolpiatto)
;; Revision 1.174 2009/03/12 19:12:24 rubikitch
;; New API: `define-anything-type-attribute'
;; Revision 1.173 2009/03/11 08:10:32 rubikitch
;; Update doc
;; Revision 1.172 2009/03/10 17:11:58 rubikitch
;; `candidate-transformer', `filtered-candidate-transformer',
;; `action-transformer' attributes: accept a list of functions
;; Revision 1.171 2009/03/09 18:49:44 rubikitch
;; New command: `anything-quit-and-find-file'
;; Revision 1.170 2009/03/09 18:46:11 rubikitch
;; New API: `anything-run-after-quit'
;; Revision 1.169 2009/03/09 10:02:49 rubikitch
;; Set candidate-number-limit attribute for actions.
;; Revision 1.168 2009/03/07 21:01:10 rubikitch
;; Bug workaround
;; Revision 1.167 2009/03/06 04:13:42 rubikitch
;; Fix doc
;; Revision 1.166 2009/03/03 10:35:57 rubikitch
;; Set default `anything-input-idle-delay' to 0.1
;; Revision 1.165 2009/03/03 07:14:42 rubikitch
;; Make sure to run `anything-update-hook' after processing delayed
;; sources.
;; Revision 1.164 2009/03/02 01:51:40 rubikitch
;; better error handling.
;; Revision 1.163 2009/03/01 05:15:00 rubikitch
;; anything-iswitchb and anything-isearch are marked as unmaintained.
;; (document change only)
;; Revision 1.162 2009/02/28 01:24:13 rubikitch
;; Symbols are now acceptable as candidate.
;; Revision 1.161 2009/02/27 07:18:46 rubikitch
;; Fix bug of `anything-scroll-other-window' and
;; `anything-scroll-other-window-down'.
;; Revision 1.160 2009/02/27 01:05:06 rubikitch
;; * Make sure to restore point after running `anything-update-hook'.
;; * Make `anything-compute-matches' easy to find error.
;; Revision 1.159 2009/02/26 23:45:48 rubikitch
;; * Check whether candidate is a string, otherwise ignore.
;; Revision 1.158 2009/02/24 06:39:20 rubikitch
;; suppress compile warnings.
;; Revision 1.157 2009/02/23 22:51:43 rubikitch
;; New function: `anything-document-attribute'
;; Revision 1.156 2009/02/23 21:36:09 rubikitch
;; New Variable: `anything-display-source-at-screen-top'
;; Revision 1.155 2009/02/23 21:30:52 rubikitch
;; New command: `anything-at-point'
;; Revision 1.154 2009/02/23 08:57:54 rubikitch
;; Visible Mark
;; Revision 1.153 2009/02/23 08:38:57 rubikitch
;; update doc
;; Revision 1.152 2009/02/23 08:32:17 rubikitch
;; More key bindings.
;; Revision 1.151 2009/02/23 08:21:24 rubikitch
;; `anything-map' is now Emacs-standard key bindings by default.
;; After evaluating `anything-iswitchb-setup'. some key bindings are
;; adjusted to iswitchb.
;; Revision 1.150 2009/02/20 22:58:18 rubikitch
;; Cancel timer in `anything-cleanup'.
;; Revision 1.149 2009/02/20 12:23:44 rubikitch
;; `anything-header' face now inherits header-line (not a copy).
;; Revision 1.148 2009/02/16 23:40:22 rubikitch
;; `real-to-display' attribute bug fix.
;; Revision 1.147 2009/02/02 20:51:41 rubikitch
;; New `anything-sources' attribute: real-to-display
;; Revision 1.146 2009/02/01 20:01:00 rubikitch
;; Update Tips
;; Revision 1.145 2009/02/01 19:45:53 rubikitch
;; New variable: `anything-quit-if-no-candidate'
;; Revision 1.144 2009/02/01 19:31:47 rubikitch
;; fixed a typo
;; Revision 1.143 2009/02/01 19:23:32 rubikitch
;; New variable: `anything-execute-action-at-once-if-one'
;; Revision 1.142 2009/02/01 19:12:34 rubikitch
;; `anything-persistent-action-display-buffer': bug fix
;; Revision 1.141 2009/02/01 18:25:25 rubikitch
;; * fix docstring
;; * New variable: `anything-selection-face'
;; Revision 1.140 2009/01/16 16:36:25 rubikitch
;; New variable: `anything-persistent-action-use-special-display'.
;; Revision 1.139 2009/01/05 20:15:53 rubikitch
;; Fixed a bug of anything action buffer.
;; The action source should not be cached.
;; Revision 1.138 2008/12/21 16:56:05 rubikitch
;; Fixed an error when action attribute is a function symbol and press
;; TAB,
;; Revision 1.137 2008/12/20 19:38:47 rubikitch
;; `anything-check-minibuffer-input-1': proper quit handling
;; `anything-process-delayed-sources': ditto
;; Revision 1.136 2008/10/27 17:41:27 rubikitch
;; `anything-process-delayed-sources',
;; `anything-check-minibuffer-input-1': quittable
;; Revision 1.135 2008/10/27 17:04:25 rubikitch
;; arranged source, added more linkd tags (no code change)
;; Revision 1.134 2008/10/27 15:02:25 rubikitch
;; New variable: `anything-save-configuration-functions'
;; Delete variable: `anything-save-configuration-type'
;; Revision 1.133 2008/10/27 11:16:13 rubikitch
;; New variable: `anything-save-configuration-type'
;; Revision 1.132 2008/10/26 22:34:59 rubikitch
;; `anything-delete-current-selection' with multiline
;; Revision 1.131 2008/10/26 21:44:43 rubikitch
;; New command: `anything-delete-current-selection'
;; Revision 1.130 2008/10/22 10:41:09 rubikitch
;; `anything-insert-match': do not override 'anything-realvalue
;; property
;; Revision 1.129 2008/10/21 17:01:37 rubikitch
;; `anything-resume' per buffer.
;; `anything-last-sources': obsolete
;; Revision 1.128 2008/10/20 06:27:54 rubikitch
;; `anything-quick-update': new user option
;; Revision 1.127 2008/10/20 05:47:49 rubikitch
;; refactoring
;; Revision 1.126 2008/10/20 03:47:58 rubikitch
;; `anything-update': reversed order of delayed sources
;; Revision 1.125 2008/10/19 00:29:54 rubikitch
;; kill buffer-local candidate buffers when creating global candidate
;; buffers.
;; Revision 1.124 2008/10/18 13:04:20 rubikitch
;; Remove tick entry from `anything-tick-hash' when killing a buffer.
;; Revision 1.123 2008/10/18 10:23:36 rubikitch
;; multiline patch by Tomohiro MATSUYAMA.
;; Revision 1.122 2008/10/13 03:10:07 rubikitch
;; `anything': do `anything-mark-current-line' when resuming
;; Revision 1.121 2008/10/13 03:08:08 rubikitch
;; always set `anything-current-position'
;; Revision 1.120 2008/10/07 14:12:02 rubikitch
;; `anything-execute-persistent-action': optional arg
;; Revision 1.119 2008/10/06 06:43:29 rubikitch
;; `anything-candidate-buffer': return nil when the buffer is dead
;; Revision 1.118 2008/09/30 22:21:28 rubikitch
;; New `anything-sources' attribute: accept-empty
;; dummy: include accept-empty
;; Revision 1.117 2008/09/30 21:59:10 rubikitch
;; New function: `anything-buffer-is-modified'
;; Revision 1.116 2008/09/22 11:27:29 rubikitch
;; *** empty log message ***
;; Revision 1.115 2008/09/20 20:21:11 rubikitch
;; added linkd index. (no code change)
;; Revision 1.114 2008/09/20 20:09:57 rubikitch
;; INCOMPATIBLE CHANGES: `anything-attr'
;; New functions: `anything-attrset', `anything-attr-defined'
;; Revision 1.113 2008/09/14 15:15:32 rubikitch
;; bugfix: volatile and match attribute / process and match attribute
;; Revision 1.112 2008/09/12 01:57:17 rubikitch
;; When resuming anything, reinitialize overlays.
;; Revision 1.111 2008/09/10 22:53:11 rubikitch
;; anything: bug fix of `anything-buffer'
;; New macro: `anything-test-update'
;; Revision 1.110 2008/09/10 22:17:11 rubikitch
;; New `anything-sources' attribute: header-name
;; Revision 1.109 2008/09/10 21:12:26 rubikitch
;; New hook: `anything-after-action-hook'
;; Revision 1.108 2008/09/06 06:07:56 rubikitch
;; Extended `anything-set-sources' optional arguments.
;; Revision 1.107 2008/09/05 03:14:35 rubikitch
;; reimplement `anything-current-buffer-is-modified' in the right way
;; Revision 1.106 2008/09/05 00:11:05 rubikitch
;; Moved `anything-read-string-mode' and read functions to
;; anything-complete.el.
;; Revision 1.105 2008/09/04 12:45:06 rubikitch
;; New hook: `anything-after-persistent-action-hook'
;; Revision 1.104 2008/09/04 12:27:05 rubikitch
;; `anything': prefixed optional arguments
;; Revision 1.103 2008/09/04 09:16:28 rubikitch
;; fixed a bug of `anything-read-file-name'.
;; Revision 1.102 2008/09/03 11:25:19 rubikitch
;; Extended `anything' optional arguments: buffer
;; Revision 1.101 2008/09/03 11:15:13 rubikitch
;; `anything': return nil when keybord-quitted
;; Revision 1.100 2008/09/01 23:11:02 rubikitch
;; bug fix of search-from-end
;; Revision 1.99 2008/09/01 13:45:55 rubikitch
;; bug fix of search-from-end
;; Revision 1.98 2008/09/01 11:23:38 rubikitch
;; New `anything-sources' attribute: search-from-end
;; Revision 1.97 2008/09/01 00:44:34 rubikitch
;; Make sure to display the other window when persistent action.
;; Revision 1.96 2008/08/31 20:55:20 rubikitch
;; define `buffer-modified-tick' for older emacs.
;; Revision 1.95 2008/08/30 04:55:51 rubikitch
;; fixed a bug of `anything-completing-read'
;; Revision 1.94 2008/08/28 20:18:03 rubikitch
;; added some tests
;; Revision 1.93 2008/08/25 20:18:46 rubikitch
;; `anything': set `anything-input' and `anything-pattern' before
;; `anything-update'
;; Revision 1.92 2008/08/24 22:38:46 rubikitch
;; *** empty log message ***
;; Revision 1.91 2008/08/24 21:34:35 rubikitch
;; rewrite `with-anything-restore-variables'
;; Revision 1.90 2008/08/24 20:33:02 rubikitch
;; prevent the unit test from byte-compiled.
;; macro bug fix.
;; Revision 1.89 2008/08/24 08:35:27 rubikitch
;; *** empty log message ***
;; Revision 1.88 2008/08/24 08:22:19 rubikitch
;; Rename `anything-candidates-buffer' -> `anything-candidate-buffer'
;; Revision 1.87 2008/08/23 22:27:04 rubikitch
;; New hook: `anything-cleanup-hook'
;; Revision 1.86 2008/08/23 22:05:42 rubikitch
;; `anything-original-source-filter' is removed.
;; Now use `anything-restored-variables' and
;; `with-anything-restore-variables'.
;; Revision 1.85 2008/08/23 21:23:21 rubikitch
;; inhibit-read-only = t in anything-buffer
;; Revision 1.84 2008/08/23 21:18:33 rubikitch
;; *** empty log message ***
;; Revision 1.83 2008/08/23 20:44:20 rubikitch
;; `anything-execute-persistent-action': display-to-real bug fix
;; Revision 1.82 2008/08/23 20:19:12 rubikitch
;; New `anything-sources' attribute: get-line
;; Revision 1.81 2008/08/23 19:32:14 rubikitch
;; `anything-attr': Return t in (attribute-name) case.
;; Revision 1.80 2008/08/22 21:25:05 rubikitch
;; anything-candidates-in-buffer-1:
;; Open a line at the BOB to make use of `search-forward' for faster
;; exact/prefix match.
;; Of course, restore the buffer contents after search.
;; Revision 1.79 2008/08/22 17:11:00 rubikitch
;; New hook: `anything-before-initialize-hook',
;; `anything-after-initialize-hook'
;; Revision 1.78 2008/08/21 18:37:03 rubikitch
;; Implemented dummy sources as plug-in.
;; Revision 1.77 2008/08/21 17:40:40 rubikitch
;; New function: `anything-set-sources'
;; Revision 1.76 2008/08/21 12:25:02 rubikitch
;; New variable: `anything-version'
;; Revision 1.75 2008/08/21 12:13:46 rubikitch
;; New variable: `anything-in-persistent-action'
;; Revision 1.74 2008/08/21 10:34:22 rubikitch
;; New function `anything-mklist'
;; Revision 1.73 2008/08/21 09:41:38 rubikitch
;; accept multiple init/cleanup functions so that plug-ins can add new
;; function.
;; Revision 1.72 2008/08/20 22:51:53 rubikitch
;; New `anything-sources' attribute: candidate-number-limit
;; Revision 1.71 2008/08/20 21:45:42 rubikitch
;; added many tests.
;; Revision 1.70 2008/08/20 18:51:45 rubikitch
;; `anything-preselect' bug fix.
;; refactoring.
;; Revision 1.69 2008/08/20 17:57:51 rubikitch
;; Extended `anything' optional arguments: preselect
;; Revision 1.68 2008/08/20 16:39:07 rubikitch
;; Nested `anything' invocation support, ie. `anything' can be invoked
;; by anything action.
;; (anything '(((name . "nested anything invocation test")
;; (candidates "anything-c-source-buffers"
;; "anything-c-source-man-pages")
;; (display-to-real . intern)
;; (action . anything))))
;; Revision 1.67 2008/08/20 00:08:28 rubikitch
;; `anything-candidates-in-buffer-1': add code when pattern == ""
;; Revision 1.66 2008/08/19 23:31:52 rubikitch
;; Removed `anything-show-exact-match-first' because it should be
;; provided as a plug-in.
;; Revision 1.65 2008/08/19 23:18:47 rubikitch
;; *** empty log message ***
;; Revision 1.64 2008/08/19 23:15:43 rubikitch
;; `anything-compute-matches': short-cut when match == '(identity)
;; Revision 1.63 2008/08/19 23:06:42 rubikitch
;; Use hash table to speed uniquify candidates.
;; Revision 1.62 2008/08/19 22:40:57 rubikitch
;; `anything-test-candidates': additional optonal argument
;; Revision 1.61 2008/08/19 18:13:39 rubikitch
;; search attribute: multiple search functions
;; Revision 1.60 2008/08/19 15:07:39 rubikitch
;; New function: `anything-attr'
;; Revision 1.59 2008/08/19 15:01:59 rubikitch
;; arranged code
;; added unit tests
;; update doc
;; Revision 1.58 2008/08/19 13:40:52 rubikitch
;; `anything-get-current-source': This function can be used in
;; init/candidates/action/candidate-transformer/filtered-candidate-transformer
;; display-to-real/cleanup function.
;; Revision 1.57 2008/08/19 03:43:57 rubikitch
;; `anything-process-delayed-sources': delay = anything-idle-delay -
;; anything-input-idle-delay
;; Revision 1.56 2008/08/18 06:37:51 rubikitch
;; Make `anything-input-idle-delay' ineffective when the action list
;; is shown.
;; Revision 1.55 2008/08/18 06:35:00 rubikitch
;; New variable: `anything-show-exact-match-first'
;; Revision 1.54 2008/08/17 23:22:24 rubikitch
;; *** empty log message ***
;; Revision 1.53 2008/08/17 23:15:38 rubikitch
;; bind `anything-source-name' when executing action to enable to use
;; `anything-candidate-buffer' in action.
;; Revision 1.52 2008/08/17 15:21:27 rubikitch
;; `anything-test-candidates': accept a symbol for source
;; New variable: `anything-input-idle-delay'
;; Revision 1.51 2008/08/17 12:45:30 rubikitch
;; (buffer-disable-undo) in anything-buffer
;; Revision 1.50 2008/08/16 22:21:37 rubikitch
;; `anything-saved-sources': removed
;; `anything-action-buffer': action selection buffer
;; `anything-select-action': toggle actions <=> candidates
;; Revision 1.49 2008/08/16 19:46:11 rubikitch
;; New function: `anything-action-list-is-shown'
;; Revision 1.48 2008/08/16 17:03:02 rubikitch
;; bugfix: cleanup
;; Revision 1.47 2008/08/16 16:35:24 rubikitch
;; silence byte compiler
;; Revision 1.46 2008/08/16 14:51:27 rubikitch
;; *** empty log message ***
;; Revision 1.45 2008/08/16 11:27:59 rubikitch
;; refactoring
;; `anything-aif': Anaphoric if.
;; `anything-compile-source-functions': make `anything-get-sources'
;; customizable.
;; Revision 1.44 2008/08/16 09:38:15 rubikitch
;; *** empty log message ***
;; Revision 1.43 2008/08/15 11:44:28 rubikitch
;; `anything-read-string-mode': minor mode for `anything' version of
;; read functions. (experimental)
;; Revision 1.42 2008/08/15 11:03:20 rubikitch
;; update docs
;; Revision 1.41 2008/08/14 20:51:28 rubikitch
;; New `anything-sources' attribute: cleanup
;; Revision 1.40 2008/08/14 10:34:04 rubikitch
;; `anything': SOURCES: accept symbols
;; Revision 1.39 2008/08/10 22:46:01 rubikitch
;; `anything-move-selection': avoid infinite loop
;; Revision 1.38 2008/08/09 21:38:25 rubikitch
;; `anything-read-file-name': experimental implementation.
;; Revision 1.37 2008/08/09 17:54:25 rubikitch
;; action test
;; Revision 1.36 2008/08/09 17:13:00 rubikitch
;; fixed test
;; Revision 1.35 2008/08/09 10:43:08 rubikitch
;; New `anything-sources' attribute: display-to-real
;; Revision 1.34 2008/08/07 13:15:44 rubikitch
;; New `anything-sources' attribute: search
;; Revision 1.33 2008/08/05 23:14:20 rubikitch
;; `anything-candidate-buffer': bugfix
;; Revision 1.32 2008/08/05 21:42:15 rubikitch
;; *** empty log message ***
;; Revision 1.31 2008/08/05 21:06:23 rubikitch
;; `anything-candidate-buffer': candidates buffer registration
;; Revision 1.30 2008/08/05 19:46:36 rubikitch
;; New `anything-sources' attribute: candidates-in-buffer
;; Revision 1.29 2008/08/05 17:58:31 rubikitch
;; *** empty log message ***
;; Revision 1.28 2008/08/05 17:46:04 rubikitch
;; memoized `anything-get-sources'
;; Revision 1.27 2008/08/05 17:29:40 rubikitch
;; update doc
;; Revision 1.26 2008/08/05 08:35:45 rubikitch
;; `anything-completing-read': accept obarray
;; Revision 1.25 2008/08/05 07:26:17 rubikitch
;; `anything-completing-read': guard from non-string return value
;; Revision 1.24 2008/08/04 12:05:41 rubikitch
;; Wrote Tips and some docstrings.
;; `anything-candidate-buffer': buffer-local by default
;; Revision 1.23 2008/08/04 05:29:46 rubikitch
;; `anything-buffer-file-name': `buffer-file-name' when `anything' is
;; invoked.
;; Revision 1.22 2008/08/04 00:10:13 rubikitch
;; `anything-candidate-buffer': new API
;; Revision 1.21 2008/08/03 22:05:08 rubikitch
;; `anything-candidate-buffer': Return a buffer containing candidates
;; of current source.
;; Revision 1.20 2008/08/03 20:47:56 rubikitch
;; `anything-current-buffer-is-modified': modify checker
;; Revision 1.19 2008/08/03 19:06:18 rubikitch
;; `anything-candidates-in-buffer': use `with-current-buffer' instead.
;; Revision 1.18 2008/08/03 05:55:01 rubikitch
;; `anything-candidates-in-buffer': extract candidates in a buffer for
;; speed.
;; Revision 1.17 2008/08/02 21:31:29 rubikitch
;; Extended `anything' optional arguments.
;; `anything-completing-read': experimental implementation.
;; Revision 1.16 2008/08/02 20:32:54 rubikitch
;; Extended `anything' optional arguments.
;; Revision 1.15 2008/08/02 16:53:40 rubikitch
;; Fixed a small bug of `anything-test-candidates'.
;; Revision 1.14 2008/08/02 16:48:29 rubikitch
;; Refactored to testable code.
;; Added many candidate tests with `anything-test-candidates'.
;; Revision 1.13 2008/08/02 15:08:14 rubikitch
;; *** empty log message ***
;; Revision 1.12 2008/08/02 14:29:31 rubikitch
;; `anything-sources' accepts symbols. (patched by Sugawara)
;; Revision 1.11 2008/08/02 10:20:36 rubikitch
;; `anything-resume' is usable with other (let-binded)
;; `anything-sources'.
;; Revision 1.10 2008/08/01 19:44:01 rubikitch
;; `anything-resume': resurrect previously invoked `anything'.
;; Revision 1.9 2008/07/30 15:44:49 rubikitch
;; *** empty log message ***
;; Revision 1.8 2008/07/30 15:38:51 rubikitch
;; *** empty log message ***
;; Revision 1.7 2008/07/30 15:21:48 rubikitch
;; `anything-scroll-other-window',
;; `anything-scroll-other-window-down':
;; Scroll other window (for persistent action).
;; Revision 1.6 2008/07/30 15:12:36 rubikitch
;; *** empty log message ***
;; Revision 1.5 2008/07/30 15:06:32 rubikitch
;; `anything-select-2nd-action', `anything-select-3rd-action',
;; `anything-select-4th-action':
;; Select other than default action without pressing Tab.
;; Revision 1.4 2008/07/30 14:58:27 rubikitch
;; `anything-current-buffer': Store current buffer when `anything' is
;; invoked.
;; `anything-current-position': Restore position when
;; keyboard-quitted.
;; Revision 1.3 2008/07/30 14:38:04 rubikitch
;; Implemented persistent action.
;; Revision 1.2 2008/07/30 13:37:16 rubikitch
;; Update doc.
;; Revision 1.1 2008/07/30 13:22:06 rubikitch
;; New maintainer.
;; ugly hack to auto-update version
(defvar anything-version nil)
(setq anything-version "$Id: anything.el,v 1.248 2010/02/20 12:34:38 rubikitch Exp $")
(require 'cl)
;; (@* "User Configuration")
;; This is only an example. Customize it to your own taste!
(defvar anything-sources `(((name . "Buffers")
. (lambda ()
(remove-if (lambda (name)
(or (equal name anything-buffer)
(eq ?\ (aref name 0))))
(mapcar 'buffer-name (buffer-list)))))
(type . buffer))
((name . "File Name History")
(candidates . file-name-history)
(match (lambda (candidate)
;; list basename matches first
(file-name-nondirectory candidate)))
(lambda (candidate)
;; and then directory part matches
(let ((dir (file-name-directory candidate)))
(if dir
(string-match anything-pattern dir)))))
(type . file))
((name . "Files from Current Directory")
(init . (lambda ()
(setq anything-default-directory
(candidates . (lambda ()
(type . file))
((name . "Manual Pages")
(candidates . ,(progn
;; XEmacs doesn't have a woman :)
(declare (special woman-file-name
(condition-case nil
(require 'woman)
(woman-file-name "")
(sort (mapcar 'car
(error nil))))
(action . (("Open Manual Page" . woman)))
(requires-pattern . 2))
((name . "Complex Command History")
(candidates . (lambda ()
(mapcar 'prin1-to-string
(action . (("Repeat Complex Command" .
(lambda (c)
(eval (read c))))))
"The source of candidates for anything.
It accepts symbols:
(setq anything-sources (list anything-c-foo anything-c-bar))
can be written as
(setq anything-sources '(anything-c-foo anything-c-bar))
The latter is recommended because if you change anything-c-* variable,
you do not have to update `anything-sources'.
You are STRONGLY recommended to define a command which calls
`anything' or `anything-other-buffer' with argument rather than
to set `anything-sources' externally.
If you want to change `anything-sources' during `anything' invocation,
use `anything-set-sources', never use `setq'.
- name (mandatory)
The name of the source. It is also the heading which appears
above the list of matches from the source. Must be unique.
- header-name (optional)
A function returning the display string of the header. Its
argument is the name of the source. This attribute is useful to
add an additional information with the source name.
- candidates (mandatory if candidates-in-buffer attribute is not provided)
Specifies how to retrieve candidates from the source. It can
either be a variable name, a function called with no parameters
or the actual list of candidates.
The list must be a list whose members are strings, symbols
or (DISPLAY . REAL) pairs.
In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
in the Anything buffer, but the REAL one is used as action
argument when the candidate is selected. This allows a more
readable presentation for candidates which would otherwise be,
for example, too long or have a common part shared with other
candidates which can be safely replaced with an abbreviated
string for display purposes.
Note that if the (DISPLAY . REAL) form is used then pattern
matching is done on the displayed string, not on the real
If the candidates have to be retrieved asynchronously (for
example, by an external command which takes a while to run)
then the function should start the external command
asynchronously and return the associated process object.
Anything will take care of managing the process (receiving the
output from it, killing it if necessary, etc.). The process
should return candidates matching the current pattern (see
variable `anything-pattern'.)
Note that currently results from asynchronous sources appear
last in the anything buffer regardless of their position in
- action (mandatory if type attribute is not provided)
It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
FUNCTION is called with one parameter: the selected candidate.
An action other than the default can be chosen from this list
of actions for the currently selected candidate (by default
with TAB). The DISPLAY string is shown in the completions
buffer and the FUNCTION is invoked when an action is
selected. The first action of the list is the default.
- type (optional if action attribute is provided)
Indicates the type of the items the source returns.
Merge attributes not specified in the source itself from
This attribute is implemented by plug-in.
- init (optional)
Function called with no parameters when anything is started. It
is useful for collecting current state information which can be
used to create the list of candidates later.
For example, if a source needs to work with the current
directory then it can store its value here, because later
anything does its job in the minibuffer and in the
`anything-buffer' and the current directory can be different
- delayed-init (optional)
Function called with no parameters before candidate function is
called. It is similar with `init' attribute, but its
evaluation is deferred. It is useful to combine with
`requires-pattern' attribute.
- match (optional)
List of functions called with one parameter: a candidate. The
function should return non-nil if the candidate matches the
current pattern (see variable `anything-pattern').
This attribute allows the source to override the default
pattern matching based on `string-match'. It can be used, for
example, to implement a source for file names and do the
pattern matching on the basename of files, since it's more
likely one is typing part of the basename when searching for a
file, instead of some string anywhere else in its path.
If the list contains more than one function then the list of
matching candidates from the source is constructed by appending
the results after invoking the first function on all the
potential candidates, then the next function, and so on. The
matching candidates supplied by the first function appear first
in the list of results and then results from the other
functions, respectively.
This attribute has no effect for asynchronous sources (see
attribute `candidates'), since they perform pattern matching
- candidate-transformer (optional)
It's a function or a list of functions called with one argument
when the completion list from the source is built. The argument
is the list of candidates retrieved from the source. The
function should return a transformed list of candidates which
will be used for the actual completion. If it is a list of
functions, it calls each function sequentially.
This can be used to transform or remove items from the list of
Note that `candidates' is run already, so the given transformer
function should also be able to handle candidates with (DISPLAY
. REAL) format.
- filtered-candidate-transformer (optional)
It has the same format as `candidate-transformer', except the
function is called with two parameters: the candidate list and
the source.
This transformer is run on the candidate list which is already
filtered by the current pattern. While `candidate-transformer'
is run only once, it is run every time the input pattern is
It can be used to transform the candidate list dynamically, for
example, based on the current pattern.
In some cases it may also be more efficent to perform candidate
transformation here, instead of with `candidate-transformer'
even if this transformation is done every time the pattern is
changed. For example, if a candidate set is very large then
`candidate-transformer' transforms every candidate while only
some of them will actually be dislpayed due to the limit
imposed by `anything-candidate-number-limit'.
Note that `candidates' and `candidate-transformer' is run
already, so the given transformer function should also be able
to handle candidates with (DISPLAY . REAL) format.
This option has no effect for asynchronous sources. (Not yet,
at least.
- action-transformer (optional)
It's a function or a list of functions called with two
arguments when the action list from the source is
assembled. The first argument is the list of actions, the
second is the current selection. If it is a list of functions,
it calls each function sequentially.
The function should return a transformed action list.
This can be used to customize the list of actions based on the
currently selected candidate.
- pattern-transformer (optional)
It's a function or a list of functions called with one argument
before computing matches. Its argument is `anything-pattern'.
Functions should return transformed `anything-pattern'.
It is useful to change interpretation of `anything-pattern'.
- delayed (optional)
Candidates from the source are shown only if the user stops
typing and is idle for `anything-idle-delay' seconds.
- volatile (optional)
Indicates the source assembles the candidate list dynamically,
so it shouldn't be cached within a single Anything
invocation. It is only applicable to synchronous sources,
because asynchronous sources are not cached.
- requires-pattern (optional)
If present matches from the source are shown only if the
pattern is not empty. Optionally, it can have an integer
parameter specifying the required length of input which is
useful in case of sources with lots of candidates.
- persistent-action (optional)
Function called with one parameter; the selected candidate.
An action performed by `anything-execute-persistent-action'.
If none, use the default action.
- candidates-in-buffer (optional)
Shortcut attribute for making and narrowing candidates using
buffers. This newly-introduced attribute prevents us from
forgetting to add volatile and match attributes.
See docstring of `anything-candidates-in-buffer'.
(candidates-in-buffer) is equivalent of three attributes:
(candidates . anything-candidates-in-buffer)
(match identity)
(candidates-in-buffer . candidates-function) is equivalent of:
(candidates . candidates-function)
(match identity)
This attribute is implemented by plug-in.
- search (optional)
List of functions like `re-search-forward' or `search-forward'.
Buffer search function used by `anything-candidates-in-buffer'.
By default, `anything-candidates-in-buffer' uses `re-search-forward'.
This attribute is meant to be used with
(candidates . anything-candidates-in-buffer) or
(candidates-in-buffer) in short.
- search-from-end (optional)
Make `anything-candidates-in-buffer' search from the end of buffer.
If this attribute is specified, `anything-candidates-in-buffer' uses
`re-search-backward' instead.
- get-line (optional)
A function like `buffer-substring-no-properties' or `buffer-substring'.
This function converts point of line-beginning and point of line-end,
which represents a candidate computed by `anything-candidates-in-buffer'.
By default, `anything-candidates-in-buffer' uses
- display-to-real (optional)
Function called with one parameter; the selected candidate.
The function transforms the selected candidate, and the result
is passed to the action function. The display-to-real
attribute provides another way to pass other string than one
shown in Anything buffer.
Traditionally, it is possible to make candidates,
candidate-transformer or filtered-candidate-transformer
function return a list with (DISPLAY . REAL) pairs. But if REAL
can be generated from DISPLAY, display-to-real is more
convenient and faster.
- real-to-display (optional)
Function called with one parameter; the selected candidate.
The inverse of display-to-real attribute.
The function transforms the selected candidate, which is passed
to the action function, for display. The real-to-display
attribute provides the other way to pass other string than one
shown in Anything buffer.
Traditionally, it is possible to make candidates,
candidate-transformer or filtered-candidate-transformer
function return a list with (DISPLAY . REAL) pairs. But if
DISPLAY can be generated from REAL, real-to-display is more
Note that DISPLAY parts returned from candidates /
candidate-transformer are IGNORED as the name `display-to-real'
- cleanup (optional)
Function called with no parameters when *anything* buffer is closed. It
is useful for killing unneeded candidates buffer.
Note that the function is executed BEFORE performing action.
- candidate-number-limit (optional)
Override `anything-candidate-number-limit' only for this source.
- accept-empty (optional)
Pass empty string \"\" to action function.
- disable-shortcuts (optional)
Disable `anything-enable-shortcuts' in current `anything' session.
This attribute is implemented by plug-in.
- dummy (optional)
Set `anything-pattern' to candidate. If this attribute is
specified, The candidates attribute is ignored.
This attribute is implemented by plug-in.
This plug-in implies disable-shortcuts plug-in.
- multiline (optional)
Enable to selection multiline candidates.
;; This value is only provided as an example. Customize it to your own
;; taste!
(defvar anything-type-attributes
'((file (action . (("Find File" . find-file)
("Delete File" . (lambda (file)
(if (y-or-n-p (format "Really delete file %s? "
(delete-file file)))))))
(buffer (action . (("Switch to Buffer" . switch-to-buffer)
("Pop to Buffer" . pop-to-buffer)
("Display Buffer" . display-buffer)
("Kill Buffer" . kill-buffer)))))
"It's a list of (TYPE ATTRIBUTES ...). ATTRIBUTES are the same
as attributes for `anything-sources'. TYPE connects the value
to the appropriate sources in `anything-sources'.
This allows specifying common attributes for several
sources. For example, sources which provide files can specify
common attributes with a `file' type.")
(defvar anything-enable-shortcuts nil
"*Whether to use digit/alphabet shortcut to select the first nine matches.
If t then they can be selected using Ctrl+<number>.
If 'alphabet then they can be selected using Shift+<alphabet>.
Keys (digit/alphabet) are listed in `anything-digit-shortcut-index-alist'.")
(defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
"Alphabet shortcuts are usable now. Then `anything-enable-digit-shortcuts' should be renamed.
`anything-enable-digit-shortcuts' is retained for compatibility.")
(defvar anything-shortcut-keys-alist
'((alphabet . "asdfghjklzxcvbnmqwertyuiop")
(t . "123456789")))
(defvar anything-display-source-at-screen-top t
"*If t, `anything-next-source' and `anything-previous-source'
display candidates at the top of screen.")
(defvar anything-candidate-number-limit 50
"*Do not show more candidates than this limit from individual
sources. It is usually pointless to show hundreds of matches
when the pattern is empty, because it is much simpler to type a
few characters to narrow down the list of potential candidates.
Set it to nil if you don't want this limit.")
(defvar anything-idle-delay 0.5
"*The user has to be idle for this many seconds, before
candidates from delayed sources are collected. This is useful
for sources involving heavy operations (like launching external
programs), so that candidates from the source are not retrieved
unnecessarily if the user keeps typing.
It also can be used to declutter the results anything displays,
so that results from certain sources are not shown with every
character typed, only if the user hesitates a bit.")
(defvar anything-input-idle-delay 0.1
"The user has to be idle for this many seconds, before ALL candidates are collected.
Unlink `anything-input-idle', it is also effective for non-delayed sources.
If nil, candidates are collected immediately. ")
(defvar anything-samewindow nil
"If t then Anything doesn't pop up a new window, it uses the
current window to show the candidates.")
(defvar anything-source-filter nil
"A list of source names to be displayed. Other sources won't
appear in the search results. If nil then there is no filtering.
See also `anything-set-source-filter'.")
(defvar anything-map
(let ((map (copy-keymap minibuffer-local-map)))
(define-key map (kbd "<down>") 'anything-next-line)
(define-key map (kbd "<up>") 'anything-previous-line)
(define-key map (kbd "C-n") 'anything-next-line)
(define-key map (kbd "C-p") 'anything-previous-line)
(define-key map (kbd "<prior>") 'anything-previous-page)
(define-key map (kbd "<next>") 'anything-next-page)
(define-key map (kbd "M-v") 'anything-previous-page)
(define-key map (kbd "C-v") 'anything-next-page)
(define-key map (kbd "M-<") 'anything-beginning-of-buffer)
(define-key map (kbd "M->") 'anything-end-of-buffer)
(define-key map (kbd "<right>") 'anything-next-source)
(define-key map (kbd "<left>") 'anything-previous-source)
(define-key map (kbd "<RET>") 'anything-exit-minibuffer)
(define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
(loop for c from ?A to ?Z do
(define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
(define-key map (kbd "C-i") 'anything-select-action)
(define-key map (kbd "C-z") 'anything-execute-persistent-action)
(define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
(define-key map (kbd "C-j") 'anything-select-3rd-action)
(define-key map (kbd "C-o") 'anything-next-source)
(define-key map (kbd "C-M-v") 'anything-scroll-other-window)
(define-key map (kbd "M-<next>") 'anything-scroll-other-window)
(define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
(define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
(define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
(define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
(define-key map (kbd "M-[") 'anything-prev-visible-mark)
(define-key map (kbd "M-]") 'anything-next-visible-mark)
(define-key map (kbd "C-k") 'anything-delete-minibuffer-content)
(define-key map (kbd "C-s") 'anything-isearch)
(define-key map (kbd "C-r") 'undefined)
(define-key map (kbd "C-t") 'anything-toggle-resplit-window)
(define-key map (kbd "C-x C-f") 'anything-quit-and-find-file)
(define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
(define-key map (kbd "C-c C-y") 'anything-yank-selection)
(define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
(define-key map (kbd "C-c C-f") 'anything-follow-mode)
;; the defalias is needed because commands are bound by name
;; when
;; using iswitchb, so only commands having the prefix
;; anything-
;; get rebound
(defalias 'anything-previous-history-element 'previous-history-element)
(defalias 'anything-next-history-element 'next-history-element)
(define-key map (kbd "M-p") 'anything-previous-history-element)
(define-key map (kbd "M-n") 'anything-next-history-element)
"Keymap for anything.
If you execute `anything-iswitchb-setup', some keys are modified.
See `anything-iswitchb-setup-keys'.")
(defvar anything-isearch-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map (current-global-map))
(define-key map (kbd "<return>") 'anything-isearch-default-action)
(define-key map (kbd "<RET>") 'anything-isearch-default-action)
(define-key map (kbd "C-i") 'anything-isearch-select-action)
(define-key map (kbd "C-g") 'anything-isearch-cancel)
(define-key map (kbd "M-s") 'anything-isearch-again)
(define-key map (kbd "<backspace>") 'anything-isearch-delete)
;; add printing chars
(loop for i from 32 below 256 do
(define-key map (vector i) 'anything-isearch-printing-char))
"Keymap for anything incremental search.")
(defgroup anything nil
"Open anything." :prefix "anything-" :group 'convenience)
(defface anything-header
'((t (:inherit header-line)))
"Face for header lines in the anything buffer." :group 'anything)
(defvar anything-header-face 'anything-header
"Face for header lines in the anything buffer.")
(defface anything-isearch-match '((t (:background "Yellow")))
"Face for isearch in the anything buffer." :group 'anything)
(defvar anything-isearch-match-face 'anything-isearch-match
"Face for matches during incremental search.")
(defvar anything-selection-face 'highlight
"Face for currently selected item.")
(defvar anything-iswitchb-idle-delay 1
"Show anything completions if the user is idle that many
seconds after typing.")
(defvar anything-iswitchb-dont-touch-iswithcb-keys nil
"If t then those commands are not bound from `anything-map'
under iswitchb which would override standard iswithcb keys.
This allows an even more seamless integration with iswitchb for
those who prefer using iswitchb bindings even if the anything
completions buffer is popped up.
Note that you can bind alternative keys for the same command in
`anything-map', so that you can use different keys for anything
under iswitchb. For example, I bind the character \ to
`anything-exit-minibuffer' which key is just above Enter on my
keyboard. This way I can switch buffers with Enter and choose
anything completions with \.")
(defvar anything-buffer "*anything*"
"Buffer showing completions.")
(defvar anything-action-buffer "*anything action*"
"Buffer showing actions.")
(defvar anything-selection-overlay nil
"Overlay used to highlight the currently selected item.")
(defvar anything-isearch-overlay nil
"Overlay used to highlight the current match during isearch.")
(defvar anything-digit-overlays nil
"Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
(defvar anything-candidate-cache nil
"Holds the available candidate withing a single anything invocation.")
(defvar anything-pattern
"The input pattern used to update the anything buffer.")
(defvar anything-input
"The input typed in the candidates panel.")
(defvar anything-async-processes nil
"List of information about asynchronous processes managed by anything.")
(defvar anything-digit-shortcut-count 0
"Number of digit shortcuts shown in the anything buffer.")
(defvar anything-before-initialize-hook nil
"Run before anything initialization.
This hook is run before init functions in `anything-sources'.")
(defvar anything-after-initialize-hook nil
"Run after anything initialization.
Global variables are initialized and the anything buffer is created.
But the anything buffer has no contents. ")
(defvar anything-update-hook nil
"Run after the anything buffer was updated according the new
input pattern.")
(defvar anything-cleanup-hook nil
"Run after anything minibuffer is closed, IOW this hook is executed BEFORE performing action. ")
(defvar anything-after-action-hook nil
"Run after executing action.")
(defvar anything-after-persistent-action-hook nil
"Run after executing persistent action.")
(defvar anything-restored-variables
'( anything-candidate-number-limit
"Variables which are restored after `anything' invocation.")
;; `anything-saved-sources' is removed
(defvar anything-saved-selection nil
"Saved value of the currently selected object when the action
list is shown.")
;; `anything-original-source-filter' is removed
(defvar anything-candidate-separator
"Candidates separator of `multiline' source.")
(defvar anything-current-buffer nil
"Current buffer when `anything' is invoked.")
(defvar anything-buffer-file-name nil
"`buffer-file-name' when `anything' is invoked.")
(defvar anything-current-position nil
"Cons of (point) and (window-start) when `anything' is invoked.
It is needed because restoring position when `anything' is keyboard-quitted.")
(defvar anything-saved-action nil
"Saved value of the currently selected action by key.")
(defvar anything-last-sources nil
"OBSOLETE!! Sources of previously invoked `anything'.")
(defvar anything-saved-current-source nil
"Saved value of the original (anything-get-current-source) when the action
list is shown.")
(defvar anything-compiled-sources nil
"Compiled version of `anything-sources'. ")
(defvar anything-in-persistent-action nil
"Flag whether in persistent-action or not.")
(defvar anything-quick-update nil
"If non-nil, suppress displaying sources which are out of screen at first.
They are treated as delayed sources at this input.
This flag makes `anything' a bit faster with many sources.")
(defvar anything-last-sources-local nil
"Buffer local value of `anything-sources'.")
(defvar anything-last-buffer nil
"`anything-buffer' of previously `anything' session.")
(defvar anything-save-configuration-functions
'(set-frame-configuration . current-frame-configuration)
"If you hate flickering, set this variable to
'(set-window-configuration . current-window-configuration)
(defvar anything-persistent-action-use-special-display nil
"If non-nil, use `special-display-function' in persistent action.")
(defvar anything-execute-action-at-once-if-one nil
"If non-nil and there is one candidate, execute the first action without selection.
It is useful for `anything' applications.")
(defvar anything-quit-if-no-candidate nil
"if non-nil and there is no candidate, do not display *anything* buffer and quit.
This variable accepts a function, which is executed if no candidate.
It is useful for `anything' applications.")
(defvar anything-scroll-amount nil
"Scroll amount used by `anything-scroll-other-window' and `anything-scroll-other-window-down'.
If you prefer scrolling line by line, set this value to 1.")
(defvar anything-display-function 'anything-default-display-buffer
"Function to display *anything* buffer.
It is `anything-default-display-buffer' by default, which affects `anything-samewindow'.")
(defvar anything-delayed-init-executed nil)
(defvar anything-mode-line-string "(C-c?:help TAB:act C-m/C-e/C-j:nthact C-o:nextsrc C-z:pers-act C-SPC:mark M-[/M-]:movemark C-t:splt C-cC-f:follow)"
"Help string displayed in mode-line in `anything'.
If nil, use default `mode-line-format'.")
(put 'anything 'timid-completion 'disabled)
;; (@* "Internal Variables")
(defvar anything-test-candidate-list nil)
(defvar anything-test-mode nil)
(defvar anything-source-name nil)
(defvar anything-candidate-buffer-alist nil)
(defvar anything-check-minibuffer-input-timer nil)
(defvar anything-match-hash (make-hash-table :test 'equal))
(defvar anything-cib-hash (make-hash-table :test 'equal))
(defvar anything-tick-hash (make-hash-table :test 'equal))
(defvar anything-issued-errors nil)
(defvar anything-shortcut-keys nil)
;; (@* "Programming Tools")
(defmacro anything-aif (test-form then-form &rest else-forms)
"Anaphoric if. Temporary variable `it' is the result of test-form."
`(let ((it ,test-form))
(if it ,then-form ,@else-forms)))
(put 'anything-aif 'lisp-indent-function 2)
(defun anything-mklist (obj)
"If OBJ is a list, return itself, otherwise make a list with one element."
(if (listp obj) obj (list obj)))
;; (@* "Anything API")
(defun anything-buffer-get ()
"If *anything action* buffer is shown, return `anything-action-buffer', otherwise `anything-buffer'."
(if (anything-action-window)
(defun anything-window ()
"Window of `anything-buffer'."
(get-buffer-window (anything-buffer-get) 'visible))
(defun anything-action-window ()
"Window of `anything-action-buffer'."
(get-buffer-window anything-action-buffer 'visible))
(defmacro with-anything-window (&rest body)
`(let ((--tmpfunc-- (lambda () ,@body)))
(if anything-test-mode
(with-current-buffer (anything-buffer-get)
(funcall --tmpfunc--))
(with-selected-window (anything-window)
(funcall --tmpfunc--)))))
(put 'with-anything-window 'lisp-indent-function 0)
(defmacro with-anything-restore-variables (&rest body)
"Restore variables specified by `anything-restored-variables' after executing BODY ."
`(let ((--orig-vars (mapcar (lambda (v) (cons v (symbol-value v))) anything-restored-variables)))
(unwind-protect (progn ,@body)
(loop for (var . value) in --orig-vars
do (set var value)))))
(put 'with-anything-restore-variables 'lisp-indent-function 0)
(defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
"Get the value of ATTRIBUTE-NAME of SRC (source).
if SRC is omitted, use current source.
It is useful to write your sources."
(anything-aif (assq attribute-name src)
(cdr it)))
(defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
"Return non-nil if ATTRIBUTE-NAME of SRC (source) is defined.
if SRC is omitted, use current source.
It is useful to write your sources."
(and (assq attribute-name src) t))
(defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
"Set the value of ATTRIBUTE-NAME of SRC (source) to VALUE.
if SRC is omitted, use current source.
It is useful to write your sources."
(anything-aif (assq attribute-name src)
(setcdr it value)
(setcdr src (cons (cons attribute-name value) (cdr src))))
;; anything-set-source-filter
;; This function sets a filter for anything sources and it may be
;; called while anything is running. It can be used to toggle
;; displaying of sources dinamically. For example, additional keys
;; can be bound into `anything-map' to display only the file-related
;; results if there are too many matches from other sources and
;; you're after files only:
;; Shift+F shows only file results from some sources:
;; (define-key anything-map "F" 'anything-my-show-files-only)
;; (defun anything-my-show-files-only ()
;; (interactive)
;; (anything-set-source-filter '("File Name History"
;; "Files from Current
;; Shift+A shows all results:
;; (define-key anything-map "A" 'anything-my-show-all)
;; (defun anything-my-show-all ()
;; (interactive)
;; (anything-set-source-filter nil))
;; Note that you have to prefix the functions with anything- prefix,
;; otherwise they won't be bound when Anything is used under
;; Iswitchb. The -my- part is added to avoid collisions with
;; existing Anything function names.
(defun anything-set-source-filter (sources)
"Sets the value of `anything-source-filter' and updates the list of results."
(unless (and (listp sources)
(loop for name in sources always (stringp name)))
(error "invalid data in `anything-set-source-filter': %S" sources))
(setq anything-source-filter sources)
(defun anything-set-sources (sources &optional no-init no-update)
"Set `anything-sources' during `anything' invocation.
If NO-INIT is non-nil, skip executing init functions of SOURCES.
If NO-UPDATE is non-nil, skip executing `anything-update'."
(setq anything-compiled-sources nil
anything-sources sources)
(unless no-init (anything-funcall-foreach 'init))
(unless no-update (anything-update)))
(defvar anything-compile-source-functions
"Functions to compile elements of `anything-sources' (plug-in).")
(defun anything-get-sources ()
"Return compiled `anything-sources', which is memoized.
- type
`anything-type-attributes' are merged in.
- candidates-buffer
candidates, volatile and match attrubute are created.
;; action
;; memoized
;; first time
(setq anything-compiled-sources
(anything-compile-sources anything-sources anything-compile-source-functions)))))
(defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
"Return the currently selected item or nil.
if BUFFER is nil or unspecified, use anything-buffer as default value.
If FORCE-DISPLAY-PART is non-nil, return the display string."
(setq buffer (if (and buffer buffer-s) buffer anything-buffer))
(unless (zerop (buffer-size (get-buffer buffer)))
(with-current-buffer buffer
(let ((selection
(or (and (not force-display-part)
(get-text-property (overlay-start
(overlay-start anything-selection-overlay)
(1- (overlay-end anything-selection-overlay))))))
(unless (equal selection "")
(defun anything-get-action ()
"Return the associated action for the selected candidate."
(unless (zerop (buffer-size (get-buffer (anything-buffer-get))))
(let* ((source (anything-get-current-source))
(actions (assoc-default 'action source)))
(anything-aif (assoc-default 'action-transformer source)
;; (funcall it actions
;; (anything-get-selection))
(anything-composed-funcall-with-source source it actions (anything-get-selection))
(defun anything-get-current-source ()
"Return the source for the current selection / in init/candidates/action/candidate-transformer/filtered-candidate-transformer function."
(declare (special source))
;; The name `anything-get-current-source' should be used in init
;; function etc.
(if (and (boundp 'anything-source-name) (stringp anything-source-name))
(with-current-buffer (anything-buffer-get)
;; This goto-char shouldn't be necessary, but point is
;; moved to
;; point-min somewhere else which shouldn't happen.
(goto-char (overlay-start anything-selection-overlay))
(let* ((header-pos (anything-get-previous-header-pos))
(or header-pos (error "No candidates"))
(goto-char header-pos)
(line-beginning-position) (line-end-position)))))
(some (lambda (source)
(if (equal (assoc-default 'name source)
(defun anything-buffer-is-modified (buffer)
"Return non-nil when BUFFER is modified since `anything' was invoked."
(let* ((b (get-buffer buffer))
(key (concat (buffer-name b)
(anything-attr 'name)))
(source-tick (or (gethash key anything-tick-hash) 0))
(buffer-tick (buffer-chars-modified-tick b)))
(prog1 (/= source-tick buffer-tick)
(puthash key buffer-tick anything-tick-hash))))
(defun anything-current-buffer-is-modified ()
"Return non-nil when `anything-current-buffer' is modified since `anything' was invoked."
(anything-buffer-is-modified anything-current-buffer))
(defvar anything-quit nil)
(defun anything-run-after-quit (function &rest args)
"Perform an action after quitting `anything'.
The action is to call FUNCTION with arguments ARGS."
(setq anything-quit t)
(apply 'run-with-idle-timer 0 nil function args)
(defun define-anything-type-attribute (type definition &optional doc)
"Register type attribute of TYPE as DEFINITION with DOC.
DOC is displayed in `anything-type-attributes' docstring.
Use this function is better than setting `anything-type-attributes' directly."
(anything-add-type-attribute type definition)
(and doc (anything-document-type-attribute type doc))
(defvar anything-additional-attributes nil)
(defun anything-document-attribute (attribute short-doc &optional long-doc)
"Register ATTRIBUTE documentation introduced by plug-in.
SHORT-DOC is displayed beside attribute name.
LONG-DOC is displayed below attribute name and short documentation."
(if long-doc
(setq short-doc (concat "(" short-doc ")"))
(setq long-doc short-doc
short-doc ""))
(add-to-list 'anything-additional-attributes attribute t)
(put attribute 'anything-attrdoc
(concat "- " (symbol-name attribute) " " short-doc "\n\n" long-doc "\n")))
(put 'anything-document-attribute 'lisp-indent-function 2)
(defun anything-require-at-least-version (version)
"Output error message unless anything.el is older than VERSION.
This is suitable for anything applications."
(when (and (string= "1." (substring version 0 2))
(string-match "1\.\\([0-9]+\\)" anything-version)
(< (string-to-number (match-string 1 anything-version))
(string-to-number (substring version 2))))
(error "Please update anything.el!!
or M-x install-elisp-from-emacswiki anything.el")))
;; (@* "Core: tools")
(defun anything-current-frame/window-configuration ()
(funcall (cdr anything-save-configuration-functions)))
(defun anything-set-frame/window-configuration (conf)
(funcall (car anything-save-configuration-functions) conf))
(defun anything-funcall-with-source (source func &rest args)
(let ((anything-source-name (assoc-default 'name source)))
(apply func args)))
(defun anything-funcall-foreach (sym)
"Call the sym function(s) for each source if any."
(dolist (source (anything-get-sources))
(when (symbolp source)
(setq source (symbol-value source)))
(anything-aif (assoc-default sym source)
(dolist (func (if (functionp it) (list it) it))
(anything-funcall-with-source source func)))))
(defun anything-normalize-sources (sources)
"If SOURCES is only one source, make a list."
(cond ((or (and sources ; avoid nil
(symbolp sources))
(and (listp sources) (assq 'name sources)))
(list sources))
(t anything-sources)))
(defun anything-approximate-candidate-number ()
"Approximate Number of candidates.
It is used to check if candidate number is 0, 1, or 2+."
(with-current-buffer anything-buffer
(let ((lines (1- (line-number-at-pos (1- (point-max))))))
(if (zerop lines)
(goto-char (point-min))
(forward-line 1)
(if (anything-pos-multiline-p)
(if (search-forward anything-candidate-separator nil t) 2 1)
(defmacro with-anything-quittable (&rest body)
`(let (inhibit-quit)
(condition-case v
(progn ,@body)
(quit (setq anything-quit t)
(put 'with-anything-quittable 'lisp-indent-function 0)
(defun anything-compose (arg-lst func-lst)
"Call each function in FUNC-LST with the arguments specified in ARG-LST.
The result of each function will be the new `car' of ARG-LST.
This function allows easy sequencing of transformer functions."
(dolist (func func-lst)
(setcar arg-lst (apply func arg-lst)))
(car arg-lst))
(defun anything-composed-funcall-with-source (source funcs &rest args)
(if (functionp funcs)
(apply 'anything-funcall-with-source source funcs args)
(apply 'anything-funcall-with-source
source (lambda (&rest args) (anything-compose args funcs)) args)))
;; (@* "Core: entry point")
(defvar anything-buffers nil
"All of `anything-buffer' in most recently used order.")
(defun anything (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
"Select anything. In Lisp program, some optional arguments can be used.
Note that all the optional arguments are prefixed because of
dynamic scope problem, IOW argument variables may eat
already-bound variables. Yuck!
Temporary value of `anything-sources'. It also accepts a
symbol, interpreted as a variable of an anything source. It
also accepts an alist representing an anything source, which is
detected by (assq 'name ANY-SOURCES)
Temporary value of `anything-pattern', ie. initial input of minibuffer.
Prompt other than \"pattern: \".
If t, Resurrect previously instance of `anything'. Skip the initialization.
If 'noresume, this instance of `anything' cannot be resumed.
Initially selected candidate. Specified by exact candidate or a regexp.
Note that it is not working with delayed sources.
`anything-buffer' instead of *anything*.
;; TODO more document
(condition-case v
(let ((frameconfig (anything-current-frame/window-configuration))
;; It is needed because
;; `anything-source-name' is non-nil
;; when `anything' is invoked by
;; action. Awful global scope.
anything-source-name anything-in-persistent-action
anything-quit anything-follow-mode
(case-fold-search t)
(anything-buffer (or any-buffer anything-buffer))
(anything-sources (anything-normalize-sources any-sources)))
(anything-initialize-1 any-resume any-input)
(anything-hooks 'setup)
(if (eq any-resume t)
(condition-case x
(anything-window-configuration 'set)
(error (anything-display-buffer anything-buffer)))
(anything-display-buffer anything-buffer))
(anything-read-pattern-maybe any-prompt any-input any-preselect any-resume)
(anything-hooks 'cleanup)
(anything-set-frame/window-configuration frameconfig))
(unless anything-quit
(defun anything-initialize-1 (any-resume any-input)
(setq anything-current-position (cons (point) (window-start)))
(if (eq any-resume t)
(anything-initialize-overlays (anything-buffer-get))
(unless (eq any-resume 'noresume)
(anything-recent-push anything-buffer 'anything-buffers)
(setq anything-last-buffer anything-buffer))
(when any-input (setq anything-input any-input anything-pattern any-input)))
(defun anything-execute-selection-action-1 ()
(anything-aif (get-buffer anything-action-buffer)
(kill-buffer it))
(run-hooks 'anything-after-action-hook)))
(defun anything-on-quit ()
(setq minibuffer-history (cons anything-input minibuffer-history))
(goto-char (car anything-current-position))
(set-window-start (selected-window) (cdr anything-current-position)))
(defun anything-resume-select-buffer (input)
(anything '(((name . "Resume anything buffer")
(candidates . anything-buffers)
(action . identity)))
input nil 'noresume nil "*anything resume*"))
(defun* anything-resume (&optional (any-buffer anything-last-buffer) buffer-pattern)
"Resurrect previously invoked `anything'."
(when (or current-prefix-arg buffer-pattern)
(setq any-buffer (anything-resume-select-buffer buffer-pattern)))
(setq anything-compiled-sources nil)
(or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
anything-last-sources anything-sources)
(buffer-local-value 'anything-input-local (get-buffer any-buffer)) nil t nil any-buffer))
(defvar anything-window-configuration nil)
;;; (set-window-configuration (buffer-local-value
;;; 'anything-window-configuration (get-buffer "*anything buffers*")))
(defun anything-window-configuration (store-or-set)
(case store-or-set
(with-current-buffer anything-buffer
(set (make-local-variable 'anything-window-configuration)
(with-current-buffer anything-buffer
(set-window-configuration anything-window-configuration))
(select-window (anything-window)))))
(defun anything-recent-push (elt list-var)
"Add ELT to the value of LIST-VAR as most recently used value."
(let ((m (member elt (symbol-value list-var))))
(and m (set list-var (delq (car m) (symbol-value list-var))))
(push elt (symbol-value list-var))))
(defun anything-at-point (&optional any-sources any-input any-prompt any-resume any-preselect any-buffer)
"Same as `anything' except when C-u is pressed, the initial input is the symbol at point."
(anything any-sources
(if current-prefix-arg
(concat "\\b" (thing-at-point 'symbol) "\\b"
(if (featurep 'anything-match-plugin) " " ""))
any-prompt any-resume any-preselect any-buffer))
(defun anything-other-buffer (any-sources any-buffer)
"Simplified interface of `anything' with other `anything-buffer'"
(anything any-sources nil nil nil nil any-buffer))
;; (@* "Core: Display *anything* buffer")
(defun anything-display-buffer (buf)
"Display *anything* buffer."
(funcall anything-display-function buf))
(defun anything-default-display-buffer (buf)
(funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
;; (@* "Core: initialize")
(defun anything-initialize ()
"Initialize anything settings and set up the anything buffer."
(run-hooks 'anything-before-initialize-hook)
(setq anything-delayed-init-executed nil)
(setq anything-current-buffer (current-buffer))
(setq anything-buffer-file-name buffer-file-name)
(setq anything-issued-errors nil)
(setq anything-compiled-sources nil)
(setq anything-saved-current-source nil)
;; Call the init function for sources where appropriate
(anything-funcall-foreach 'init)
(setq anything-pattern "")
(setq anything-input "")
(setq anything-candidate-cache nil)
(setq anything-last-sources anything-sources)
(run-hooks 'anything-after-initialize-hook))
(defun anything-read-pattern-maybe (any-prompt any-input any-preselect any-resume)
(if (eq any-resume t) (anything-mark-current-line) (anything-update))
(select-frame-set-input-focus (window-frame (minibuffer-window)))
(anything-preselect any-preselect)
(let ((ncandidate (anything-approximate-candidate-number))
(minibuffer-local-map anything-map))
(cond ((and anything-execute-action-at-once-if-one
(= ncandidate 1))
((and anything-quit-if-no-candidate (= ncandidate 0))
(setq anything-quit t)
(and (functionp anything-quit-if-no-candidate)
(funcall anything-quit-if-no-candidate)))
(read-string (or any-prompt "pattern: ") any-input)))))
(defun anything-create-anything-buffer (&optional test-mode)
"Create newly created `anything-buffer'.
If TEST-MODE is non-nil, clear `anything-candidate-cache'."
(when test-mode
(setq anything-candidate-cache nil))
(with-current-buffer (get-buffer-create anything-buffer)
(set (make-local-variable 'inhibit-read-only) t)
(set (make-local-variable 'anything-last-sources-local) anything-sources)
(if anything-mode-line-string
(setq mode-line-format
'(" " mode-line-buffer-identification " "
(line-number-mode "%l") " " anything-mode-line-string "-%-"))
(kill-local-variable 'mode-line-format))
(setq cursor-type nil)
(setq mode-name "Anything"))
(anything-initialize-overlays anything-buffer)
(get-buffer anything-buffer))
(defun anything-initialize-overlays (buffer)
(if anything-selection-overlay
;; make sure the overlay belongs to the anything buffer if
;; it's newly created
(move-overlay anything-selection-overlay (point-min) (point-min)
(get-buffer buffer))
(setq anything-selection-overlay
(make-overlay (point-min) (point-min) (get-buffer buffer)))
(overlay-put anything-selection-overlay 'face anything-selection-face))
(when anything-enable-shortcuts
(setq anything-shortcut-keys (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist)))
(if anything-enable-shortcuts
(unless anything-digit-overlays
(setq anything-digit-overlays
(loop for key across anything-shortcut-keys
for overlay = (make-overlay (point-min) (point-min) (get-buffer buffer))
do (overlay-put overlay 'before-string
(format "%s - " (upcase (make-string 1 key))))
collect overlay)))
(when anything-digit-overlays
(dolist (overlay anything-digit-overlays)
(delete-overlay overlay))
(setq anything-digit-overlays nil))))
(defun anything-hooks (setup-or-cleanup)
(let ((hooks '((post-command-hook anything-check-minibuffer-input)
(minibuffer-setup-hook anything-print-error-messages)
(minibuffer-exit-hook (lambda () (anything-window-configuration 'store))))))
(with-current-buffer anything-current-buffer
(if (eq setup-or-cleanup 'setup)
(dolist (args hooks) (apply 'add-hook args))
(dolist (args (reverse hooks)) (apply 'remove-hook args))))))
;; (@* "Core: clean up")
(defun anything-cleanup ()
"Clean up the mess."
(with-current-buffer anything-buffer
(setq cursor-type t))
(bury-buffer anything-buffer)
(anything-funcall-foreach 'cleanup)
(if anything-check-minibuffer-input-timer
(cancel-timer anything-check-minibuffer-input-timer))
(run-hooks 'anything-cleanup-hook))
;; (@* "Core: input handling")
(defun anything-check-minibuffer-input ()
"Extract input string from the minibuffer and check if it needs
to be handled."
(if (or (not anything-input-idle-delay) (anything-action-window))
(if anything-check-minibuffer-input-timer
(cancel-timer anything-check-minibuffer-input-timer))
(setq anything-check-minibuffer-input-timer
(run-with-idle-timer anything-input-idle-delay nil
(defun anything-check-minibuffer-input-1 ()
(with-selected-window (minibuffer-window)
(anything-check-new-input (minibuffer-contents)))))
(defun anything-check-new-input (input)
"Check input string and update the anything buffer if
(unless (equal input anything-pattern)
(setq anything-pattern input)
(unless (anything-action-window)
(setq anything-input anything-pattern))
;; (@* "Core: source compiler")
(defvar anything-compile-source-functions-default anything-compile-source-functions
"Plug-ins this file provides.")
(defun anything-compile-sources (sources funcs)
"Compile sources (`anything-sources') with funcs (`anything-compile-source-functions').
Anything plug-ins are realized by this function."
(lambda (source)
(loop with source = (if (listp source) source (symbol-value source))
for f in funcs
do (setq source (funcall f source))
finally (return source)))
;; (@* "Core: plug-in attribute documentation hack")
;; `anything-document-attribute' is public API.
(defadvice documentation-property (after anything-document-attribute activate)
"Hack to display plug-in attributes' documentation as `anything-sources' docstring."
(when (eq symbol 'anything-sources)
(setq ad-return-value
(concat ad-return-value "++++ Additional attributes by plug-ins ++++\n"
(mapconcat (lambda (sym) (get sym 'anything-attrdoc))
;; (describe-variable 'anything-sources)
;; (documentation-property 'anything-sources 'variable-documentation)
;; (progn (ad-disable-advice 'documentation-property 'after
;; 'anything-document-attribute) (ad-update 'documentation-property))
;; (@* "Core: all candidates")
(defun anything-get-candidates (source)
"Retrieve and return the list of candidates from
(let ((name (assoc-default 'name source)))
(unless (member name anything-delayed-init-executed)
(anything-aif (assoc-default 'delayed-init source)
(when (functionp it)
(funcall it)
(add-to-list 'anything-delayed-init-executed name)))))
(let* ((candidate-source (assoc-default 'candidates source))
(cond ((functionp candidate-source)
(anything-funcall-with-source source candidate-source))
((listp candidate-source)
((and (symbolp candidate-source) (boundp candidate-source))
(symbol-value candidate-source))
(error (concat "Candidates must either be a function, "
" a variable or a list: %s")
(if (processp candidates)
(anything-transform-candidates candidates source))))
(defun anything-transform-candidates (candidates source)
"Transform CANDIDATES according to candidate transformers."
(anything-aif (assoc-default 'candidate-transformer source)
(setq candidates (anything-composed-funcall-with-source source it candidates)))
(anything-aif (assoc-default 'real-to-display source)
(setq candidates (anything-funcall-with-source
source 'mapcar
(lambda (cand_)
(if (consp cand_)
;; override DISPLAY from candidate-transformer
(cons (funcall it (cdr cand_)) (cdr cand_))
(cons (funcall it cand_) cand_)))
(defun anything-get-cached-candidates (source)
"Return the cached value of candidates for SOURCE.
Cache the candidates if there is not yet a cached value."
(let* ((name (assoc-default 'name source))
(candidate-cache (assoc name anything-candidate-cache))
(if candidate-cache
(setq candidates (cdr candidate-cache))
(setq candidates (anything-get-candidates source))
(if (processp candidates)
(push (cons candidates
(append source
(list (cons 'item-count 0)
(cons 'incomplete-line ""))))
(set-process-filter candidates 'anything-output-filter)
(setq candidates nil))
(unless (assoc 'volatile source)
(setq candidate-cache (cons name candidates))
(push candidate-cache anything-candidate-cache))))
;; (@* "Core: narrowing candidates")
(defun anything-candidate-number-limit (source)
"`anything-candidate-number-limit' variable may be overridden by SOURCE."
(or (assoc-default 'candidate-number-limit source)
(defun anything-compute-matches (source)
"Compute matches from SOURCE according to its settings."
(let ((doit (lambda ()
(let ((functions (assoc-default 'match source))
(limit (anything-candidate-number-limit source))
(anything-aif (assoc-default 'pattern-transformer source)
(anything-composed-funcall-with-source source it anything-pattern)
(cond ((or (equal anything-pattern "") (equal functions '(identity)))
(setq matches (anything-get-cached-candidates source))
(if (> (length matches) limit)
(setq matches
(subseq matches 0 limit))))
(condition-case nil
(let ((item-count 0)
(cands (anything-get-cached-candidates source))
(unless functions
(setq functions
(list (lambda (candidate)
(string-match anything-pattern candidate)))))
(clrhash anything-match-hash)
(dolist (function functions)
(let (newmatches c cc)
(dolist (candidate cands)
(when (and (not (gethash candidate anything-match-hash))
(setq c (if (listp candidate)
(car candidate)
(setq cc (cond ((stringp c) c)
((symbolp c) (symbol-name c))))
(funcall function cc))
(puthash candidate t anything-match-hash)
(push candidate newmatches)
(when limit
(incf item-count)
(when (= item-count limit)
(setq exit t)
(setq matches (append matches (reverse newmatches)))
(if exit
(invalid-regexp (setq matches nil)))))
(anything-aif (assoc-default 'filtered-candidate-transformer source)
(setq matches
(anything-composed-funcall-with-source source it matches source)))
(if debug-on-error
(funcall doit)
(condition-case v
(funcall doit)
(error (anything-log-error
"anything-compute-matches: error when processing source: %s"
(assoc-default 'name source))
;; (anything '(((name . "error")(candidates . (lambda () (hage)))
;; (action . identity))))
(defun anything-process-source (source)
"Display matches from SOURCE according to its settings."
(let ((matches (anything-compute-matches source)))
(when matches
(when anything-test-mode
(setq anything-test-candidate-list
(,(assoc-default 'name source)
(let ((multiline (assoc 'multiline source))
(start (point))
(anything-insert-header-from-source source)
(dolist (match matches)
(if (and multiline separate)
(setq separate t))
(when (and anything-enable-shortcuts
(not (eq anything-digit-shortcut-count
(length anything-digit-overlays))))
(move-overlay (nth anything-digit-shortcut-count
(incf anything-digit-shortcut-count))
(anything-insert-match match 'insert))
(if multiline
(put-text-property start (point) 'anything-multiline t))))))
(defun anything-process-delayed-sources (delayed-sources)
"Process delayed sources if the user is idle for
`anything-idle-delay' seconds."
(if (sit-for (if anything-input-idle-delay
(max 0 (- anything-idle-delay anything-input-idle-delay))
(with-current-buffer anything-buffer
(goto-char (point-max))
(dolist (source delayed-sources)
(anything-process-source source))
(when (and (not (equal (buffer-size) 0))
;; no selection yet
(= (overlay-start anything-selection-overlay)
(overlay-end anything-selection-overlay)))
(goto-char (point-min))
(goto-char (point-min))
(run-hooks 'anything-update-hook))
;; (@* "Core: *anything* buffer contents")
(defvar anything-input-local nil)
(defun anything-update ()
"Update the list of matches in the anything buffer according to
the current pattern."
(setq anything-digit-shortcut-count 0)
(with-current-buffer (anything-buffer-get)
(set (make-local-variable 'anything-input-local) anything-pattern)
(if anything-enable-shortcuts
(dolist (overlay anything-digit-overlays)
(delete-overlay overlay)))
(let (delayed-sources)
(dolist (source (anything-get-sources))
(when (and (or (not anything-source-filter)
(member (assoc-default 'name source) anything-source-filter))
(>= (length anything-pattern)
(anything-aif (assoc 'requires-pattern source)
(or (cdr it) 1)
(if (or (assoc 'delayed source)
(and anything-quick-update
(< (window-height (get-buffer-window (current-buffer)))
(line-number-at-pos (point-max)))))
(push source delayed-sources)
(anything-process-source source))))
(goto-char (point-min))
(save-excursion (run-hooks 'anything-update-hook))
(setq delayed-sources (nreverse delayed-sources))
(if anything-test-mode
(dolist (source delayed-sources)
(anything-process-source source))
(when delayed-sources
(run-with-idle-timer (if (featurep 'xemacs)
(defun anything-insert-match (match insert-function &optional ignored)
"Insert MATCH into the anything buffer. If MATCH is a list then
insert the string inteneded to appear on the display and store
the real value in a text property."
(let ((start (line-beginning-position (point)))
(string (if (listp match) (car match) match))
(realvalue (if (listp match) (cdr match) match)))
(when (symbolp string) (setq string (symbol-name string)))
(when (stringp string)
(funcall insert-function string)
;; Some sources with candidates-in-buffer have already
;; added
;; 'anything-realvalue property when creating candidate
;; buffer.
(unless (get-text-property start 'anything-realvalue)
(put-text-property start (line-end-position)
'anything-realvalue realvalue))
(funcall insert-function "\n"))))
(defun anything-insert-header-from-source (source)
(let ((name (assoc-default 'name source)))
(anything-insert-header name
(anything-aif (assoc-default 'header-name source)
(anything-funcall-with-source source it name)))))
(defun anything-insert-header (name &optional display-string)
"Insert header of source NAME into the anything buffer."
(unless (bobp)
(let ((start (point)))
(insert "\n")
(put-text-property start (point) 'anything-header-separator t)))
(let ((start (point)))
(insert name)
(put-text-property (line-beginning-position)
(line-end-position) 'anything-header t)
(when display-string
(overlay-put (make-overlay (line-beginning-position) (line-end-position))
'display display-string))
(insert "\n")
(put-text-property start (point) 'face anything-header-face)))
(defun anything-insert-candidate-separator ()
"Insert separator of candidates into the anything buffer."
(insert anything-candidate-separator)
(put-text-property (line-beginning-position)
(line-end-position) 'anything-candidate-separator t)
(insert "\n"))
;; (@* "Core: async process")
(defun anything-output-filter (process string)
"Process output from PROCESS."
(let* ((process-assoc (assoc process anything-async-processes))
(process-info (cdr process-assoc))
(insertion-marker (assoc-default 'insertion-marker process-info))
(incomplete-line-info (assoc 'incomplete-line process-info))
(item-count-info (assoc 'item-count process-info))
(limit (anything-candidate-number-limit process-info)))
(with-current-buffer anything-buffer
(if insertion-marker
(goto-char insertion-marker)
(goto-char (point-max))
(anything-insert-header-from-source process-info)
(setcdr process-assoc
(append process-info `((insertion-marker . ,(point-marker))))))
(let ((lines (split-string string "\n"))
(while lines
(if (not (cdr lines))
;; store last incomplete line until
;; new output arrives
(setcdr incomplete-line-info (car lines))
(if (cdr incomplete-line-info)
(push (concat (cdr incomplete-line-info) (car lines))
(setcdr incomplete-line-info nil))
(push (car lines) candidates)))
(pop lines))
(setq candidates (reverse candidates))
(dolist (candidate (anything-transform-candidates candidates process-info))
(anything-insert-match candidate 'insert-before-markers)
(incf (cdr item-count-info))
(when (>= (cdr item-count-info) limit)
(anything-kill-async-process process)
(run-hooks 'anything-update-hook)
(if (bobp)
(select-window (get-buffer-window anything-buffer 'visible))
(defun anything-kill-async-processes ()
"Kill all known asynchronous processes according to
"Kill locate process."
(dolist (process-info anything-async-processes)
(anything-kill-async-process (car process-info)))
(setq anything-async-processes nil))
(defun anything-kill-async-process (process)
"Kill PROCESS and detach the associated functions."
(set-process-filter process nil)
(delete-process process))
;; (@* "Core: action")
(defun anything-execute-selection-action (&optional selection action clear-saved-action display-to-real)
"If a candidate was selected then perform the associated
(setq selection (or selection (anything-get-selection)))
(setq action (or action
(if (get-buffer anything-action-buffer)
(anything-get-selection anything-action-buffer)
(let ((source (or anything-saved-current-source (anything-get-current-source))))
(if (and (not selection) (assoc 'accept-empty source))
(setq selection ""))
(setq display-to-real
(or display-to-real (assoc-default 'display-to-real source)
(if (and (listp action)
(not (functionp action))) ; lambda
;;select the default action
(setq action (cdar action)))
(unless clear-saved-action (setq anything-saved-action nil))
(if (and selection action)
source action
(anything-funcall-with-source source display-to-real selection)))))
(defun anything-select-action ()
"Select an action for the currently selected candidate.
If action buffer is selected, back to the anything buffer."
(cond ((get-buffer-window anything-action-buffer 'visible)
(set-window-buffer (get-buffer-window anything-action-buffer) anything-buffer)
(kill-buffer anything-action-buffer))
(setq anything-saved-selection (anything-get-selection))
(unless anything-saved-selection
(error "Nothing is selected."))
(setq anything-saved-current-source (anything-get-current-source))
(let ((actions (anything-get-action)))
(if (functionp actions)
(message "Sole action: %s" actions)
(with-current-buffer (get-buffer-create anything-action-buffer)
(set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
(set (make-local-variable 'anything-sources)
`(((name . "Actions")
(candidates . ,actions)
;; Override
;; `anything-candidate-number-limit'
(candidate-number-limit . 9999))))
(set (make-local-variable 'anything-source-filter) nil)
(set (make-local-variable 'anything-selection-overlay) nil)
(set (make-local-variable 'anything-digit-overlays) nil)
(anything-initialize-overlays anything-action-buffer))
(with-selected-window (minibuffer-window)
(setq anything-pattern 'dummy) ; so that it
; differs from the
; previous one
;; (@* "Core: selection")
(defun anything-previous-line ()
"Move selection to the previous line."
(anything-move-selection 'line 'previous))
(defun anything-next-line ()
"Move selection to the next line."
(anything-move-selection 'line 'next))
(defun anything-previous-page ()
"Move selection back with a pageful."
(anything-move-selection 'page 'previous))
(defun anything-next-page ()
"Move selection forward with a pageful."
(anything-move-selection 'page 'next))
(defun anything-beginning-of-buffer ()
"Move selection at the top."
(anything-move-selection 'edge 'previous))
(defun anything-end-of-buffer ()
"Move selection at the bottom."
(anything-move-selection 'edge 'next))
(defun anything-previous-source ()
"Move selection to the previous source."
(anything-move-selection 'source 'previous))
(defun anything-next-source ()
"Move selection to the next source."
(anything-move-selection 'source 'next))
(defun anything-move-selection (unit direction)
"Move the selection marker to a new position determined by
(unless (or (zerop (buffer-size (get-buffer (anything-buffer-get))))
(not (anything-window)))
(case unit
(line (case direction
(next (if (not (anything-pos-multiline-p))
(forward-line 1)
(let ((header-pos (anything-get-next-header-pos))
(candidate-pos (anything-get-next-candidate-separator-pos)))
(if (and candidate-pos
(or (null header-pos)
(< candidate-pos header-pos)))
(goto-char candidate-pos)
(if header-pos
(goto-char header-pos)))
(if candidate-pos
(forward-line 1)))))
(previous (progn
(forward-line -1)
(when (anything-pos-multiline-p)
(if (or (anything-pos-header-line-p)
(forward-line -1)
(forward-line 1))
(let ((header-pos (anything-get-previous-header-pos))
(candidate-pos (anything-get-previous-candidate-separator-pos)))
(when header-pos
(if (or (null candidate-pos) (< candidate-pos header-pos))
(goto-char header-pos)
(goto-char candidate-pos))
(forward-line 1))))))
(t (error "Invalid direction."))))
(page (case direction
(next (condition-case nil
(end-of-buffer (goto-char (point-max)))))
(previous (condition-case nil
(beginning-of-buffer (goto-char (point-min)))))
(t (error "Invalid direction."))))
(source (case direction
(next (goto-char (or (anything-get-next-header-pos)
(previous (progn
(forward-line -1)
(if (bobp)
(goto-char (point-max))
(if (anything-pos-header-line-p)
(forward-line -1)
(forward-line 1)))
(goto-char (anything-get-previous-header-pos))
(forward-line 1)))
(t (error "Invalid direction."))))
(edge (case direction
(next (goto-char (point-max)))
(previous (goto-char (point-min)))
(t (error "Invalid direction."))))
(t (error "Invalid unit.")))
(while (and (not (bobp))
(or (anything-pos-header-line-p)
(forward-line (if (and (eq direction 'previous)
(not (eq (line-beginning-position)
(if (bobp)
(forward-line 1))
(if (eobp)
(forward-line -1))
(when (and anything-display-source-at-screen-top (eq unit 'source))
(set-window-start (selected-window)
(save-excursion (forward-line -1) (point))))
(when (anything-get-previous-header-pos)
(defun anything-mark-current-line ()
"Move selection overlay to current line."
(move-overlay anything-selection-overlay
(if (anything-pos-multiline-p)
(let ((header-pos (anything-get-next-header-pos))
(candidate-pos (anything-get-next-candidate-separator-pos)))
(or (and (null header-pos) candidate-pos candidate-pos)
(and header-pos candidate-pos (< candidate-pos header-pos) candidate-pos)
(1+ (line-end-position))))
(defun anything-this-command-key ()
(event-basic-type (elt (this-command-keys-vector) 0)))
;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
(defun anything-select-with-digit-shortcut ()
(if anything-enable-shortcuts
(select-window (anything-window))
(let* ((index (position (anything-this-command-key) anything-shortcut-keys))
(overlay (nth index anything-digit-overlays)))
(when (overlay-buffer overlay)
(goto-char (overlay-start overlay))
(self-insert-command 1)))
(defun anything-exit-minibuffer ()
"Select the current candidate by exiting the minibuffer."
(declare (special anything-iswitchb-candidate-selected))
(setq anything-iswitchb-candidate-selected (anything-get-selection))
(defun anything-get-next-header-pos ()
"Return the position of the next header from point."
(next-single-property-change (point) 'anything-header))
(defun anything-get-previous-header-pos ()
"Return the position of the previous header from point"
(previous-single-property-change (point) 'anything-header))
(defun anything-pos-multiline-p ()
"Return non-nil if the current position is in the multiline source region."
(get-text-property (point) 'anything-multiline))
(defun anything-get-next-candidate-separator-pos ()
"Return the position of the next candidate separator from point."
(next-single-property-change (point) 'anything-candidate-separator))
(defun anything-get-previous-candidate-separator-pos ()
"Return the position of the previous candidate separator from point."
(previous-single-property-change (point) 'anything-candidate-separator))
(defun anything-pos-header-line-p ()
"Return t if the current line is a header line."
(or (get-text-property (line-beginning-position) 'anything-header)
(get-text-property (line-beginning-position) 'anything-header-separator)))
(defun anything-pos-candidate-separator-p ()
"Return t if the current line is a candidate separator."
(get-text-property (line-beginning-position) 'anything-candidate-separator))
;; (@* "Core: error handling")
(defun anything-log-error (&rest args)
"Accumulate error messages into `anything-issued-errors'."
(let ((msg (apply 'format args)))
(unless (member msg anything-issued-errors)
(add-to-list 'anything-issued-errors msg))))
(defun anything-print-error-messages ()
"Print error messages in `anything-issued-errors'."
(message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))
;; (@* "Core: misc")
(defun anything-kill-buffer-hook ()
"Remove tick entry from `anything-tick-hash' when killing a buffer."
(loop for key being the hash-keys in anything-tick-hash
if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
do (remhash key anything-tick-hash)))
(add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
(defun anything-maybe-fit-frame ()
"Fit anything frame to its buffer, and put it at top right of display.
To inhibit fitting, set `fit-frame-inhibit-fitting-flag' to t.
You can set user options `fit-frame-max-width-percent' and
`fit-frame-max-height-percent' to control max frame size."
(declare (warn (unresolved 0)))
(when (and (require 'fit-frame nil t)
(boundp 'fit-frame-inhibit-fitting-flag)
(not fit-frame-inhibit-fitting-flag)
(fit-frame nil nil nil t)
`((left . ,(- (x-display-pixel-width) (+ (frame-pixel-width) 7)))
(top . 0))))))) ; The (top . 0) shouldn't be
; necessary (Emacs bug).
(defun anything-preselect (candidate-or-regexp)
(when candidate-or-regexp
(goto-char (point-min))
;; go to first candidate of first source
(forward-line 1)
(let ((start (point)))
(unless (or (re-search-forward (concat "^" (regexp-quote candidate-or-regexp) "$") nil t)
(progn (goto-char start)
(re-search-forward candidate-or-regexp nil t)))
(goto-char start))
(defun anything-delete-current-selection ()
"Delete the currently selected item."
(cond ((anything-pos-multiline-p)
(anything-aif (anything-get-next-candidate-separator-pos)
(delete-region (point-at-bol)
(1+ (progn (goto-char it) (point-at-eol))))
;; last candidate
(goto-char (anything-get-previous-candidate-separator-pos))
(delete-region (point-at-bol) (point-max)))
(when (eobp)
(goto-char (or (anything-get-previous-candidate-separator-pos)
(forward-line 1)))
(delete-region (point-at-bol) (1+ (point-at-eol)))
(when (eobp) (forward-line -1))))
(defun anything-delete-minibuffer-content ()
"Same as `delete-minibuffer-contents' but this is a command."
;; (@* "Built-in plug-in: type")
(defun anything-compile-source--type (source)
(anything-aif (assoc-default 'type source)
(append source (assoc-default it anything-type-attributes) nil)
;; `define-anything-type-attribute' is public API.
(defun anything-add-type-attribute (type definition)
(anything-aif (assq type anything-type-attributes)
(setq anything-type-attributes (delete it anything-type-attributes)))
(push (cons type definition) anything-type-attributes))
(defvar anything-types nil)
(defun anything-document-type-attribute (type doc)
(add-to-list 'anything-types type t)
(put type 'anything-typeattrdoc
(concat "- " (symbol-name type) "\n\n" doc "\n")))
(defadvice documentation-property (after anything-document-type-attribute activate)
"Hack to display type attributes' documentation as `anything-type-attributes' docstring."
(when (eq symbol 'anything-type-attributes)
(setq ad-return-value
(concat ad-return-value "\n\n++++ Types currently defined ++++\n"
(mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
anything-types "\n")))))
;; (@* "Built-in plug-in: dummy")
(defun anything-dummy-candidate (candidate source)
;; `source' is defined in filtered-candidate-transformer
(list anything-pattern))
(defun anything-compile-source--dummy (source)
(if (assoc 'dummy source)
(append source
'((candidates "dummy")
(match identity)
(filtered-candidate-transformer . anything-dummy-candidate)
;; (@* "Built-in plug-in: disable-shortcuts")
(defvar anything-orig-enable-shortcuts nil)
(defun anything-compile-source--disable-shortcuts (source)
(if (assoc 'disable-shortcuts source)
(append source
'((init . (lambda () (setq anything-orig-enable-shortcuts anything-enable-shortcuts
anything-enable-shortcuts nil)))
(cleanup . (lambda () (setq anything-enable-shortcuts anything-orig-enable-shortcuts)))))
;; (@* "Built-in plug-in: candidates-in-buffer")
(defun anything-candidates-in-buffer ()
"Get candidates from the candidates buffer according to `anything-pattern'.
BUFFER is `anything-candidate-buffer' by default. Each
candidate must be placed in one line. This function is meant to
be used in candidates-in-buffer or candidates attribute of an
anything source. Especially fast for many (1000+) candidates.
'((name . \"many files\")
(init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
(search re-search-forward) ; optional
(type . file))
| The new way of making and narrowing candidates: Using buffers |
By default, `anything' makes candidates by evaluating the
candidates function, then narrows them by `string-match' for each
But this way is very slow for many candidates. The new way is
storing all candidates in a buffer and narrowing them by
`re-search-forward'. Search function is customizable by search
attribute. The important point is that buffer processing is MUCH
FASTER than string list processing and is the Emacs way.
The init function writes all candidates to a newly-created
candidate buffer. The candidates buffer is created or specified
by `anything-candidate-buffer'. Candidates are stored in a line.
The candidates function narrows all candidates, IOW creates a
subset of candidates dynamically. It is the task of
`anything-candidates-in-buffer'. As long as
`anything-candidate-buffer' is used,`(candidates-in-buffer)' is
sufficient in most cases.
Note that `(candidates-in-buffer)' is shortcut of three attributes:
(candidates . anything-candidates-in-buffer)
(match identity)
And `(candidates-in-buffer . func)' is shortcut of three attributes:
(candidates . func)
(match identity)
The expansion is performed in `anything-get-sources'.
The candidates-in-buffer attribute implies the volatile attribute.
The volatile attribute is needed because `anything-candidates-in-buffer'
creates candidates dynamically and need to be called everytime
`anything-pattern' changes.
Because `anything-candidates-in-buffer' plays the role of `match' attribute
function, specifying `(match identity)' makes the source slightly faster.
To customize `anything-candidates-in-buffer' behavior, use search,
get-line and search-from-end attributes. See also `anything-sources' docstring.
(declare (special source))
(anything-candidates-in-buffer-1 (anything-candidate-buffer)
(or (assoc-default 'get-line source)
;; use external variable `source'.
(or (assoc-default 'search source)
(if (assoc 'search-from-end source)
(anything-candidate-number-limit source)
(assoc 'search-from-end source)))
(defun* anything-candidates-in-buffer-1 (buffer &optional (pattern anything-pattern) (get-line-fn 'buffer-substring-no-properties) (search-fns '(re-search-forward)) (limit anything-candidate-number-limit) search-from-end)
;; buffer == nil when candidates buffer does not exist.
(when buffer
(with-current-buffer buffer
(let ((start-point (if search-from-end (point-max) (point-min)))
(next-line-fn (if search-from-end
(lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
(endp (if search-from-end #'bobp #'eobp)))
(goto-char (1- start-point))
(if (string= pattern "")
(delq nil (loop until (funcall endp)
for i from 1 to limit
collecting (funcall get-line-fn (point-at-bol) (point-at-eol))
do (funcall next-line-fn 1)))
(let ((i 1)
(next-line-fn (if search-from-end
(lambda (x) (goto-char (max (point-at-bol) 1)))
matches exit newmatches)
(goto-char (point-min))
(insert "\n")
(goto-char (point-max))
(insert "\n")
(setq start-point (if search-from-end (point-max) (point-min)))
(clrhash anything-cib-hash)
(dolist (searcher search-fns)
(goto-char start-point)
(setq newmatches nil)
(loop while (funcall searcher pattern nil t)
if (or (funcall endp) (< limit i))
do (setq exit t) (return)
else do
(let ((cand (funcall get-line-fn (point-at-bol) (point-at-eol))))
(unless (gethash cand anything-cib-hash)
(puthash cand t anything-cib-hash)
(incf i)
(push cand newmatches)))
(funcall next-line-fn 1))
(setq matches (append matches (nreverse newmatches)))
(if exit (return)))
(goto-char (point-min))
(delete-char 1)
(goto-char (1- (point-max)))
(delete-char 1)
(set-buffer-modified-p nil)))
(delq nil matches)))))))
(defun anything-candidate-buffer (&optional create-or-buffer)
"Register and return a buffer containing candidates of current source.
`anything-candidate-buffer' searches buffer-local candidates buffer first,
then global candidates buffer.
Acceptable values of CREATE-OR-BUFFER:
- nil (omit)
Only return the candidates buffer.
- a buffer
Register a buffer as a candidates buffer.
- 'global
Create a new global candidates buffer,
named \" *anything candidates:SOURCE*\".
- other non-nil value
Create a new global candidates buffer,
named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\".
(let* ((gbufname (format " *anything candidates:%s*" anything-source-name))
(lbufname (concat gbufname (buffer-name anything-current-buffer)))
(when create-or-buffer
(if (bufferp create-or-buffer)
(setq anything-candidate-buffer-alist
(cons (cons anything-source-name create-or-buffer)
(delete (assoc anything-source-name anything-candidate-buffer-alist)
(add-to-list 'anything-candidate-buffer-alist
(cons anything-source-name create-or-buffer))
(when (eq create-or-buffer 'global)
(loop for b in (buffer-list)
if (string-match (format "^%s" (regexp-quote gbufname)) (buffer-name b))
do (kill-buffer b)))
(get-buffer-create (if (eq create-or-buffer 'global) gbufname lbufname))
(font-lock-mode -1))))
(or (get-buffer lbufname)
(get-buffer gbufname)
(anything-aif (assoc-default anything-source-name anything-candidate-buffer-alist)
(and (buffer-live-p it) it)))))
(defun anything-compile-source--candidates-in-buffer (source)
(anything-aif (assoc 'candidates-in-buffer source)
(append source `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
(volatile) (match identity)))
;; (@* "Utility: resplit anything window")
(defun anything-toggle-resplit-window ()
"Toggle resplit anything window, vertically or horizontally."
(let ((before-height (window-height)))
(select-window (if (= (window-height) before-height)
;; (@* "Utility: select another action by key")
(defun anything-select-nth-action (n)
"Select the nth action for the currently selected candidate."
(setq anything-saved-selection (anything-get-selection))
(unless anything-saved-selection
(error "Nothing is selected."))
(setq anything-saved-action (cdr (elt (anything-get-action) n)))
(defun anything-select-2nd-action ()
"Select the 2nd action for the currently selected candidate."
(anything-select-nth-action 1))
(defun anything-select-3rd-action ()
"Select the 3rd action for the currently selected candidate."
(anything-select-nth-action 2))
(defun anything-select-4th-action ()
"Select the 4th action for the currently selected candidate."
(anything-select-nth-action 3))
(defun anything-select-2nd-action-or-end-of-line ()
"Select the 2nd action for the currently selected candidate if the point is at the end of minibuffer.
Otherwise goto the end of minibuffer."
(if (eolp)
(anything-select-nth-action 1)
;; (@* "Utility: Persistent Action")
(defmacro with-anything-display-same-window (&rest body)
"Make `pop-to-buffer' and `display-buffer' display in the same window."
`(let ((display-buffer-function 'anything-persistent-action-display-buffer))
(put 'with-anything-display-same-window 'lisp-indent-function 0)
(defun* anything-execute-persistent-action (&optional (attr 'persistent-action))
"If a candidate is selected then perform the associated action without quitting anything."
(select-window (get-buffer-window (anything-buffer-get)))
(select-window (setq minibuffer-scroll-window
(if (one-window-p t) (split-window)
(next-window (selected-window) 1))))
(let ((anything-in-persistent-action t))
(or (assoc-default attr (anything-get-current-source))
(run-hooks 'anything-after-persistent-action-hook)))))
(defun anything-persistent-action-display-buffer (buf &optional not-this-window)
"Make `pop-to-buffer' and `display-buffer' display in the same window in persistent action.
If `anything-persistent-action-use-special-display' is non-nil and
BUF is to be displayed by `special-display-function', use it.
Otherwise ignores `special-display-buffer-names' and `special-display-regexps'."
(let* ((name (buffer-name buf))
display-buffer-function pop-up-windows
(unless (and anything-persistent-action-use-special-display
(or (member name
(mapcar (lambda (x) (or (car-safe x) x)) special-display-buffer-names))
(lambda (x) (string-match (or (car-safe x) x) name))
(display-buffer buf not-this-window)))
;; scroll-other-window(-down)? for persistent-action
(defun anything-scroll-other-window-base (command)
(lambda (w) (not (string= anything-buffer (buffer-name (window-buffer w)))))
'no-minibuffer 'current-frame))
(call-interactively command)))
(defun anything-scroll-other-window ()
"Scroll other window (not *Anything* window) upward."
(anything-scroll-other-window-base (lambda ()
(scroll-up anything-scroll-amount))))
(defun anything-scroll-other-window-down ()
"Scroll other window (not *Anything* window) downward."
(anything-scroll-other-window-base (lambda ()
(scroll-down anything-scroll-amount))))
;; (@* "Utility: Visible Mark")
(defface anything-visible-mark
'((((min-colors 88) (background dark))
(:background "green1" :foreground "black"))
(((background dark)) (:background "green" :foreground "black"))
(((min-colors 88)) (:background "green1"))
(t (:background "green")))
"Face for visible mark."
:group 'anything)
(defvar anything-visible-mark-face 'anything-visible-mark)
(defvar anything-visible-mark-overlays nil)
(defun anything-clear-visible-mark ()
(mapc 'delete-overlay anything-visible-mark-overlays)
(setq anything-visible-mark-overlays nil))
(add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
;; (defun anything-toggle-visible-mark ()
;; (interactive)
;; (with-anything-window
;; (anything-aif (loop for o in anything-visible-mark-overlays
;; when (equal (line-beginning-position)
;; (overlay-start o))
;; do (return o))
;; ;; delete
;; (progn (delete-overlay it)
;; (delq it anything-visible-mark-overlays))
;; (let ((o (make-overlay (line-beginning-position) (1+
;; (line-end-position)))))
;; (overlay-put o 'face anything-visible-mark-face)
;; (overlay-put o 'source (assoc-default 'name
;; (anything-get-current-source)))
;; (overlay-put o 'string (buffer-substring (overlay-start o)
;; (overlay-end o)))
;; (add-to-list 'anything-visible-mark-overlays o)))))
(defvar anything-c-marked-candidate-list nil
(defvar anything-marked-candidates nil
"Marked candadates. List of (source . real) pair.")
(defun anything-toggle-visible-mark ()
(let ((display (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
(source (anything-get-current-source))
(selection (anything-get-selection)))
(anything-aif (loop for o in anything-visible-mark-overlays
when (equal (line-beginning-position) (overlay-start o))
do (return o))
;; delete
(setq anything-c-marked-candidate-list
display anything-c-marked-candidate-list))
(setq anything-marked-candidates
(cons source selection)
(delete-overlay it)
(delq it anything-visible-mark-overlays))
(let ((o (make-overlay (line-beginning-position) (1+ (line-end-position)))))
(overlay-put o 'face anything-visible-mark-face)
(overlay-put o 'source (assoc-default 'name source))
(overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
(add-to-list 'anything-visible-mark-overlays o)
(push display anything-c-marked-candidate-list)
(push (cons source selection) anything-marked-candidates)))
(defun anything-marked-candidates ()
"Marked candidates (real value) of current source."
(loop with current-src = (anything-get-current-source)
for (source . real) in anything-marked-candidates
when (eq current-src source)
collect real))
(defun anything-reset-marked-candidates ()
(setq anything-c-marked-candidate-list nil)
(setq anything-marked-candidates nil))
(add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
(add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
(defun anything-revive-visible-mark ()
(with-current-buffer anything-buffer
(loop for o in anything-visible-mark-overlays do
(goto-char (point-min))
(when (search-forward (overlay-get o 'string) nil t)
(forward-line -1)
(when (save-excursion
(goto-char (anything-get-previous-header-pos))
(equal (overlay-get o 'source)
(buffer-substring (line-beginning-position) (line-end-position))))
(move-overlay o (line-beginning-position) (1+ (line-end-position))))))))
(add-hook 'anything-update-hook 'anything-revive-visible-mark)
(defun anything-next-visible-mark (&optional prev)
(block 'exit
(setq anything-visible-mark-overlays
(sort* anything-visible-mark-overlays
'< :key 'overlay-start))
(let ((i (position-if (lambda (o) (< (point) (overlay-start o)))
(when prev
(unless anything-visible-mark-overlays (return-from 'exit nil))
(if (not i) (setq i (length anything-visible-mark-overlays)))
(if (equal (point) (overlay-start (nth (1- i) anything-visible-mark-overlays)))
(setq i (1- i))))
(when i
(goto-char (overlay-start (nth (if prev (1- i) i) anything-visible-mark-overlays)))
(defun anything-prev-visible-mark ()
(anything-next-visible-mark t))
;; (@* "Utility: `find-file' integration")
(defun anything-quit-and-find-file ()
"Drop into `find-file' from `anything' like `iswitchb-find-file'.
This command is a simple example of `anything-run-after-quit'."
(anything-run-after-quit 'call-interactively 'find-file))
;; (@* "Utility: Selection Paste")
(defun anything-yank-selection ()
"Set minibuffer contents to current selection."
(insert (anything-get-selection nil t)))
(defun anything-kill-selection-and-quit ()
"Store current selection to kill ring.
You can paste it by typing C-y."
(lambda (sel)
(kill-new sel)
(message "Killed: %s" sel))
(anything-get-selection nil t)))
;; (@* "Utility: Automatical execution of persistent-action")
(define-minor-mode anything-follow-mode
"If this mode is on, persistent action is executed everytime the cursor is moved."
nil " AFollow" :global t)
(defun anything-follow-execute-persistent-action-maybe ()
"Execute persistent action after `anything-input-idle-delay' secs when `anything-follow-mode' is enabled."
(and anything-follow-mode
(sit-for anything-input-idle-delay)
;; (@* "Utility: Incremental search within results (unmaintained)")
(defvar anything-isearch-original-global-map nil
"Original global map before Anything isearch is started.")
(defvar anything-isearch-original-message-timeout nil
"Original message timeout before Anything isearch is started.")
(defvar anything-isearch-pattern nil
"The current isearch pattern.")
(defvar anything-isearch-message-suffix ""
"Message suffix indicating the current state of the search.")
(defvar anything-isearch-original-point nil
"Original position of point before isearch is started.")
(defvar anything-isearch-original-window nil
"Original selected window before isearch is started.")
(defvar anything-isearch-original-cursor-in-non-selected-windows nil
"Original value of cursor-in-non-selected-windows before isearch is started.")
(defvar anything-isearch-original-post-command-hook nil
"Original value of post-command-hook before isearch is started.")
(defvar anything-isearch-match-positions nil
"Stack of positions of matches or non-matches.
It's a list of plists with two properties: `event', the last user
event, `start', the start position of the current match, and
`pos', the position of point after that event.
The value of `event' can be the following symbols: `char' if a
character was typed, `error' if a non-matching character was