* anything.el (anything-restore-position-on-quit): Renamed from anything-on-quit...
[anything-config.git] / anything.el
blob12384dfcab3f2b862144fe133cb02bdacc166af5
1 ;;;; anything.el --- open anything / QuickSilver-like candidate-selection framework
3 ;; Copyright (C) 2007 Tamas Patrovics
4 ;; 2008 ~ 2011 rubikitch <rubikitch@ruby-lang.org>
5 ;; 2011 Thierry Volpiatto <thierry.volpiatto@gmail.com>
7 ;; Author: Tamas Patrovics
9 ;; Maintainers: rubikitch <rubikitch@ruby-lang.org>
10 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
12 ;; Keywords: files, frames, help, matching, outlines, processes, tools, convenience, anything
14 ;; X-URL: http://repo.or.cz/w/anything-config.git
16 ;; Site: http://www.emacswiki.org/cgi-bin/emacs/Anything
18 ;; MailingList: https://groups.google.com/group/emacs-anything?hl=en
21 ;;; This file is NOT part of GNU Emacs
23 ;;; License
25 ;; This file is free software; you can redistribute it and/or modify
26 ;; it under the terms of the GNU General Public License as published by
27 ;; the Free Software Foundation; either version 2, or (at your option)
28 ;; any later version.
30 ;; This file is distributed in the hope that it will be useful,
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 ;; GNU General Public License for more details.
36 ;; You should have received a copy of the GNU General Public License
37 ;; along with GNU Emacs; see the file COPYING. If not, write to the
38 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39 ;; Boston, MA 02110-1301, USA.
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 ;;; Autodoc documentation:
45 ;; ---------------------
47 ;; * Commands defined here are:
48 ;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything-" :docstring t)
49 ;; `anything-open-last-log'
50 ;; Open anything log file of last anything session.
51 ;; `anything-resume'
52 ;; Resurrect previously invoked `anything'.
53 ;; `anything-resume-window-only'
54 ;;
55 ;; `anything-at-point'
56 ;; Call anything with symbol at point as initial input.
57 ;; `anything-force-update'
58 ;; Force recalculation and update of candidates.
59 ;; `anything-select-action'
60 ;; Select an action for the currently selected candidate.
61 ;; `anything-previous-line'
62 ;; Move selection to the previous line.
63 ;; `anything-next-line'
64 ;; Move selection to the next line.
65 ;; `anything-previous-page'
66 ;; Move selection back with a pageful.
67 ;; `anything-next-page'
68 ;; Move selection forward with a pageful.
69 ;; `anything-beginning-of-buffer'
70 ;; Move selection at the top.
71 ;; `anything-end-of-buffer'
72 ;; Move selection at the bottom.
73 ;; `anything-previous-source'
74 ;; Move selection to the previous source.
75 ;; `anything-next-source'
76 ;; Move selection to the next source.
77 ;; `anything-select-with-prefix-shortcut'
78 ;; Invoke default action with prefix shortcut.
79 ;; `anything-select-with-digit-shortcut'
80 ;; Invoke default action with digit/alphabet shortcut.
81 ;; `anything-exit-minibuffer'
82 ;; Select the current candidate by exiting the minibuffer.
83 ;; `anything-keyboard-quit'
84 ;; Quit minibuffer in anything.
85 ;; `anything-help'
86 ;; Help of `anything'.
87 ;; `anything-debug-output'
88 ;; Show all anything-related variables at this time.
89 ;; `anything-delete-current-selection'
90 ;; Delete the currently selected item.
91 ;; `anything-delete-minibuffer-contents'
92 ;; Same as `delete-minibuffer-contents' but this is a command.
93 ;; `anything-toggle-resplit-window'
94 ;; Toggle resplit anything window, vertically or horizontally.
95 ;; `anything-narrow-window'
96 ;; Narrow anything window.
97 ;; `anything-enlarge-window'
98 ;; Enlarge anything window.
99 ;; `anything-select-2nd-action'
100 ;; Select the 2nd action for the currently selected candidate.
101 ;; `anything-select-3rd-action'
102 ;; Select the 3rd action for the currently selected candidate.
103 ;; `anything-select-4th-action'
104 ;; Select the 4th action for the currently selected candidate.
105 ;; `anything-select-2nd-action-or-end-of-line'
106 ;; Select the 2nd action for the currently selected candidate.
107 ;; `anything-execute-persistent-action'
108 ;; Perform the associated action ATTR without quitting anything.
109 ;; `anything-scroll-other-window'
110 ;; Scroll other window (not *Anything* window) upward.
111 ;; `anything-scroll-other-window-down'
112 ;; Scroll other window (not *Anything* window) downward.
113 ;; `anything-toggle-visible-mark'
114 ;; Toggle anything visible mark at point.
115 ;; `anything-display-all-visible-marks'
116 ;; Show all `anything' visible marks strings.
117 ;; `anything-next-visible-mark'
118 ;; Move next anything visible mark.
119 ;; `anything-prev-visible-mark'
120 ;; Move previous anything visible mark.
121 ;; `anything-yank-selection'
122 ;; Set minibuffer contents to current selection.
123 ;; `anything-kill-selection-and-quit'
124 ;; Store current selection to kill ring.
125 ;; `anything-follow-mode'
126 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
127 ;; `anything-migrate-sources'
128 ;; Help to migrate to new `anything' way.
129 ;; `anything-describe-anything-attribute'
130 ;; Display the full documentation of ANYTHING-ATTRIBUTE.
131 ;; `anything-send-bug-report'
132 ;; Send a bug report of anything.el.
133 ;; `anything-send-bug-report-from-anything'
134 ;; Send a bug report of anything.el in anything session.
136 ;; * Variables defined here are:
137 ;; [EVAL] (autodoc-document-lisp-buffer :type 'internal-variable :prefix "anything-" :docstring t)
138 ;; `anything-version'
139 ;; Not documented.
140 ;; `anything-sources'
141 ;; A list of sources to use with `anything'.
142 ;; `anything-type-attributes'
143 ;; It's a list of (TYPE ATTRIBUTES ...).
144 ;; `anything-enable-shortcuts'
145 ;; *Whether to use digit/alphabet shortcut to select the first nine matches.
146 ;; `anything-shortcut-keys-alist'
147 ;; Not documented.
148 ;; `anything-display-source-at-screen-top'
149 ;; *Display candidates at the top of screen.
150 ;; `anything-candidate-number-limit'
151 ;; Apply candidate-number-limit attribute value.
152 ;; `anything-idle-delay'
153 ;; *Be idle for this many seconds, before updating in delayed sources.
154 ;; `anything-input-idle-delay'
155 ;; Be idle for this many seconds, before updating.
156 ;; `anything-samewindow'
157 ;; Use current window to show the candidates.
158 ;; `anything-source-filter'
159 ;; A list of source names to be displayed.
160 ;; `anything-map'
161 ;; Keymap for anything.
162 ;; `anything-header-face'
163 ;; *Face for header lines in the anything buffer.
164 ;; `anything-selection-face'
165 ;; *Face for currently selected item.
166 ;; `anything-buffer'
167 ;; Buffer showing completions.
168 ;; `anything-action-buffer'
169 ;; Buffer showing actions.
170 ;; `anything-selection-overlay'
171 ;; Overlay used to highlight the currently selected item.
172 ;; `anything-digit-overlays'
173 ;; Overlays for digit shortcuts. See `anything-enable-shortcuts'.
174 ;; `anything-candidate-cache'
175 ;; Holds the available candidate withing a single anything invocation.
176 ;; `anything-pattern'
177 ;; Not documented.
178 ;; `anything-input'
179 ;; Not documented.
180 ;; `anything-async-processes'
181 ;; List of information about asynchronous processes managed by anything.
182 ;; `anything-digit-shortcut-count'
183 ;; Number of digit shortcuts shown in the anything buffer.
184 ;; `anything-before-initialize-hook'
185 ;; Run before anything initialization.
186 ;; `anything-after-initialize-hook'
187 ;; Run after anything initialization.
188 ;; `anything-update-hook'
189 ;; Run after the anything buffer was updated according the new input pattern.
190 ;; `anything-after-update-hook'
191 ;; Run after the anything buffer was updated according the new input pattern.
192 ;; `anything-cleanup-hook'
193 ;; Run after anything minibuffer is closed.
194 ;; `anything-after-action-hook'
195 ;; Run after executing action.
196 ;; `anything-after-persistent-action-hook'
197 ;; Run after executing persistent action.
198 ;; `anything-move-selection-before-hook'
199 ;; Run before moving selection in `anything-buffer'.
200 ;; `anything-move-selection-after-hook'
201 ;; Run after moving selection in `anything-buffer'.
202 ;; `anything-restored-variables'
203 ;; Variables which are restored after `anything' invocation.
204 ;; `anything-saved-selection'
205 ;; Value of the currently selected object when the action list is shown.
206 ;; `anything-current-prefix-arg'
207 ;; Record `current-prefix-arg' when exiting minibuffer.
208 ;; `anything-candidate-separator'
209 ;; Candidates separator of `multiline' source.
210 ;; `anything-current-buffer'
211 ;; Current buffer when `anything' is invoked.
212 ;; `anything-buffer-file-name'
213 ;; Variable `buffer-file-name' when `anything' is invoked.
214 ;; `anything-saved-action'
215 ;; Saved value of the currently selected action by key.
216 ;; `anything-last-sources'
217 ;; OBSOLETE!! Sources of previously invoked `anything'.
218 ;; `anything-saved-current-source'
219 ;; Value of the current source when the action list is shown.
220 ;; `anything-compiled-sources'
221 ;; Compiled version of `anything-sources'.
222 ;; `anything-in-persistent-action'
223 ;; Flag whether in persistent-action or not.
224 ;; `anything-quick-update'
225 ;; If non-nil, suppress displaying sources which are out of screen at first.
226 ;; `anything-last-sources-local'
227 ;; Buffer local value of `anything-sources'.
228 ;; `anything-last-buffer'
229 ;; `anything-buffer' of previously `anything' session.
230 ;; `anything-persistent-action-use-special-display'
231 ;; If non-nil, use `special-display-function' in persistent action.
232 ;; `anything-execute-action-at-once-if-one'
233 ;; Execute default action and exit when only one candidate is remaining.
234 ;; `anything-quit-if-no-candidate'
235 ;; Quit when there is no candidates when non--nil.
236 ;; `anything-scroll-amount'
237 ;; Scroll amount when scrolling other window in an anything session.
238 ;; `anything-display-function'
239 ;; Function to display *anything* buffer.
240 ;; `anything-delayed-init-executed'
241 ;; Not documented.
242 ;; `anything-mode-line-string'
243 ;; Help string displayed in mode-line in `anything'.
244 ;; `anything-help-message'
245 ;; Detailed help message string for `anything'.
246 ;; `anything-source-in-each-line-flag'
247 ;; Non-nil means add anything-source text-property in each candidate.
248 ;; `anything-debug-forms'
249 ;; Forms to show in `anything-debug-output'.
250 ;; `anything-debug'
251 ;; If non-nil, write log message into *Anything Log* buffer.
252 ;; `anything-test-candidate-list'
253 ;; Not documented.
254 ;; `anything-test-mode'
255 ;; Not documented.
256 ;; `anything-source-name'
257 ;; Not documented.
258 ;; `anything-candidate-buffer-alist'
259 ;; Not documented.
260 ;; `anything-check-minibuffer-input-timer'
261 ;; Not documented.
262 ;; `anything-match-hash'
263 ;; Not documented.
264 ;; `anything-cib-hash'
265 ;; Not documented.
266 ;; `anything-tick-hash'
267 ;; Not documented.
268 ;; `anything-issued-errors'
269 ;; Not documented.
270 ;; `anything-shortcut-keys'
271 ;; Not documented.
272 ;; `anything-once-called-functions'
273 ;; Not documented.
274 ;; `anything-follow-mode'
275 ;; If this mode is on, persistent action is executed everytime the cursor is moved.
276 ;; `anything-let-variables'
277 ;; Not documented.
278 ;; `anything-split-window-state'
279 ;; Not documented.
280 ;; `anything-last-log-file'
281 ;; Not documented.
282 ;; `anything-compile-source-functions'
283 ;; Functions to compile elements of `anything-sources' (plug-in).
284 ;; `anything-quit'
285 ;; Not documented.
286 ;; `anything-additional-attributes'
287 ;; List of all `anything' attributes.
288 ;; `anything-buffers'
289 ;; All of `anything-buffer' in most recently used order.
290 ;; `anything-current-position'
291 ;; Restore or save current position in `anything-current-buffer'.
292 ;; `anything-last-frame-or-window-configuration'
293 ;; Used to store window or frame configuration when anything start.
294 ;; `anything-reading-pattern'
295 ;; Whether in `read-string' in anything or not.
296 ;; `anything-compile-source-functions-default'
297 ;; Plug-ins this file provides.
298 ;; `anything-input-local'
299 ;; Not documented.
300 ;; `anything-process-delayed-sources-timer'
301 ;; Not documented.
302 ;; `anything-mode-line-string-real'
303 ;; Not documented.
304 ;; `anything-exit-status'
305 ;; Flag to inform whether anything have aborted or quitted.
306 ;; `anything-types'
307 ;; Not documented.
308 ;; `anything-orig-enable-shortcuts'
309 ;; Not documented.
310 ;; `anything-persistent-action-display-window'
311 ;; Return the window that will be used for presistent action.
312 ;; `anything-visible-mark-face'
313 ;; Not documented.
314 ;; `anything-visible-mark-overlays'
315 ;; Not documented.
316 ;; `anything-marked-candidates'
317 ;; Return marked candidates of current source if any.
318 ;; `anything-maintainer-mail-address'
319 ;; Not documented.
320 ;; `anything-bug-report-salutation'
321 ;; Not documented.
322 ;; `anything-no-dump-variables'
323 ;; Variables not to dump in bug report.
325 ;; *** END auto-documentation
327 ;; [EVAL] (autodoc-update-all)
330 ;;; Commentary:
333 ;; Start with M-x anything, narrow the list by typing some pattern,
334 ;; select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter,
335 ;; left/right moves between sources. With TAB actions can be selected
336 ;; if the selected candidate has more than one possible action.
338 ;; Note that anything.el provides only the framework and some example
339 ;; configurations for demonstration purposes. See anything-config.el
340 ;; for practical, polished, easy to use configurations which can be
341 ;; used to assemble a custom personalized configuration. And many
342 ;; other configurations are in the EmacsWiki.
344 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-config.el
345 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingSources
347 ;; Maintainer's configuration is in the EmacsWiki. It would tell you
348 ;; many tips to write smart sources!
350 ;; http://www.emacswiki.org/cgi-bin/emacs/RubikitchAnythingConfiguration
352 ;; Here is Japanese translation of `anything-sources' attributes. Thanks.
353 ;; http://d.hatena.ne.jp/sirocco634/20091012/1255336649
356 ;;; Bug Report:
358 ;; If you have problems, send a bug report via C-c C-x C-b in anything session (best)
359 ;; or M-x anything-send-bug-report outside anything session.
360 ;; I implemented bug report feature because I want to know your current state.
361 ;; It helps me to solve problems easily.
362 ;; The step is:
363 ;; 0) Setup mail in Emacs, the easiest way is:
364 ;; (setq user-mail-address "your@mail.address")
365 ;; (setq user-full-name "Your Full Name")
366 ;; (setq smtpmail-smtp-server "your.smtp.server.jp")
367 ;; (setq mail-user-agent 'message-user-agent)
368 ;; (setq message-send-mail-function 'message-smtpmail-send-it)
369 ;; 1) Be sure to use the LATEST version of anything.el.
370 ;; 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
371 ;; 3) Use Lisp version instead of compiled one: (load "anything.el")
372 ;; 4) Do it!
373 ;; 5) If you got an error, please do not close *Backtrace* buffer.
374 ;; 6) Type C-c C-x C-b (anything session, best!)
375 ;; or M-x anything-send-bug-report (outside)
376 ;; then M-x insert-buffer *Backtrace* (if you got error)
377 ;; 7) Describe the bug using a precise recipe.
378 ;; 8) Type C-c C-c to send.
379 ;; # If you are a Japanese, please write in Japanese:-)
382 ;; You can extend `anything' by writing plug-ins. As soon as
383 ;; `anything' is invoked, `anything-sources' is compiled into basic
384 ;; attributes, then compiled one is used during invocation.
386 ;; The oldest built-in plug-in is `type' attribute: appends
387 ;; appropriate element of `anything-type-attributes'. Second built-in
388 ;; plug-in is `candidates-in-buffer': selecting a line from candidates
389 ;; buffer.
391 ;; To write a plug-in:
392 ;; 1. Define a compiler: anything-compile-source--*
393 ;; 2. Add compier function to `anything-compile-source-functions'.
394 ;; 3. (optional) Write helper functions.
396 ;; Anything plug-ins are found in the EmacsWiki.
398 ;; http://www.emacswiki.org/cgi-bin/emacs/AnythingPlugins
400 ;; Tested on Emacs 22/23/24.
403 ;; Thanks to Vagn Johansen for ideas.
404 ;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
405 ;; Thanks to Tassilo Horn for fixes.
406 ;; Thanks to Drew Adams for various fixes
407 ;; Thanks to IMAKADO for candidates-in-buffer idea.
408 ;; Thanks to Tomohiro MATSUYAMA for multiline patch.
411 ;;; (@* "Index")
413 ;; If you have library `linkd.el', load
414 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
415 ;; navigate around the sections Linkd mode will
416 ;; highlight this Index. You can get `linkd.el' here:
417 ;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
421 ;;; (@* "Tips")
424 ;; `anything' accepts keyword arguments. See docstring.
425 ;; [EVAL IT] (describe-function 'anything)
428 ;; `anything-enable-shortcuts' enables us to select candidate easily.
429 ;; If 'prefix then they can be selected using <prefix-key> <alnum>.
430 ;; The prefix key is `anything-select-with-prefix-shortcut'.
431 ;; If the <prefix-key> is a letter, pressing twice inputs the letter itself.
432 ;; e.g.
433 ;; (setq anything-enable-shortcuts 'prefix)
434 ;; (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
437 ;; You can edit current selection using `anything-edit-current-selection'.
438 ;; It is useful after persistent-action.
441 ;; For `anything' users, setting `anything-sources' directly and
442 ;; invoke M-x anything is obsolete way for now. Try M-x
443 ;; `anything-migrate-sources'!
446 ;; If you want to create anything sources, yasnippet would help you.
447 ;; http://yasnippet.googlecode.com/
449 ;; Then get the snippet from
450 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
452 ;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
456 ;; `anything-interpret-value' is useful function to interpret value
457 ;; like `candidates' attribute.
459 ;; (anything-interpret-value "literal") ; => "literal"
460 ;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
461 ;; (let ((source '((name . "lambda with source name"))))
462 ;; (anything-interpret-value
463 ;; (lambda () anything-source-name)
464 ;; source)) ; => "lambda with source name"
465 ;; (flet ((f () "function symbol"))
466 ;; (anything-interpret-value 'f)) ; => "function symbol"
467 ;; (let ((v "variable symbol"))
468 ;; (anything-interpret-value 'v)) ; => "variable symbol"
469 ;; (anything-interpret-value 'unbounded-1) ; error
472 ;; Now symbols are acceptable as candidates. So you do not have to use
473 ;; `symbol-name' function. The source is much simpler. For example,
474 ;; `apropos-internal' returns a list of symbols.
476 ;; (anything
477 ;; '(((name . "Commands")
478 ;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
479 ;; (volatile)
480 ;; (action . describe-function))))
483 ;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
484 ;; marked candidate, press M-[ or M-].
487 ;; `anything-map' is now Emacs-standard key bindings by default.
489 ;; There are many `anything' applications, using `anything' for
490 ;; selecting candidate. In this case, if there is one candidate or no
491 ;; candidate, popping up *anything* buffer is irritating. If one
492 ;; candidate, you want to select it at once. If no candidate, you want
493 ;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
494 ;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
495 ;; that setting these variables GLOBALLY is bad idea because of
496 ;; delayed sources. These are meant to be let-binded.
497 ;; See anything-etags.el for example.
499 ;; [EVAL IT] (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/anything-etags.el")
501 ;; ex.
502 ;; (let ((anything-execute-action-at-once-if-one t)
503 ;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
504 ;; (anything temporary-sources input))
507 ;; `set-frame-configuration' arises flickering. If you hate
508 ;; flickering, eval:
509 ;; (setq anything-save-configuration-functions
510 ;; '(set-window-configuration . current-window-configuration))
511 ;; at the cost of restoring frame configuration (only window configuration).
514 ;; `anything-delete-current-selection' deletes the current line.
515 ;; It is useful when deleting a candidate in persistent action.
516 ;; eg. `kill-buffer'.
518 ;; [EVAL IT] (describe-function 'anything-delete-current-selection)
521 ;; `anything-attr' gets the attribute. `anything-attrset' sets the
522 ;; attribute. `anything-attr-defined' tests whether the attribute is
523 ;; defined. They handles source-local variables.
525 ;; [EVAL IT] (describe-function 'anything-attr)
526 ;; [EVAL IT] (describe-function 'anything-attrset)
527 ;; [EVAL IT] (describe-function 'anything-attr-defined)
530 ;; `anything-sources' accepts many attributes to make your life easier.
531 ;; Now `anything-sources' accepts a list of symbols.
533 ;; [EVAL IT] (describe-variable 'anything-sources)
536 ;; `anything' has optional arguments. Now you do not have to let-bind
537 ;; `anything-sources'.
539 ;; [EVAL IT] (describe-function 'anything)
542 ;; `anything-resume' resumes last `anything' session. Now you do not
543 ;; have to retype pattern.
545 ;; [EVAL IT] (describe-function 'anything-resume)
548 ;; `anything-execute-persistent-action' executes action without
549 ;; quitting `anything'. When popping up a buffer in other window by
550 ;; persistent action, you can scroll with `anything-scroll-other-window' and
551 ;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
553 ;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
554 ;; [EVAL IT] (describe-variable 'anything-sources)
557 ;; `anything-select-2nd-action', `anything-select-3rd-action' and
558 ;; `anything-select-4th-action' select other than default action
559 ;; without pressing Tab.
562 ;; Using `anything-candidate-buffer' and the candidates-in-buffer
563 ;; attribute is much faster than traditional "candidates and match"
564 ;; way. And `anything-current-buffer-is-modified' avoids to
565 ;; recalculate candidates for unmodified buffer. See docstring of
566 ;; them.
568 ;; [EVAL IT] (describe-function 'anything-candidate-buffer)
569 ;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
570 ;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
573 ;; `anything-current-buffer' and `anything-buffer-file-name' stores
574 ;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
575 ;; is invoked. Use them freely.
577 ;; [EVAL IT] (describe-variable 'anything-current-buffer)
578 ;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
581 ;; `anything-completing-read' and `anything-read-file-name' are
582 ;; experimental implementation. If you are curious, type M-x
583 ;; anything-read-string-mode. It is a minor mode and toggles on/off.
586 ;; Use `anything-test-candidates' to test your handmade anything
587 ;; sources. It simulates contents of *anything* buffer with pseudo
588 ;; `anything-sources' and `anything-pattern', without side-effect. So
589 ;; you can unit-test your anything sources! Let's TDD!
591 ;; [EVAL IT] (describe-function 'anything-test-candidates)
593 ;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
594 ;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
596 ;; There is an unit-test by Emacs Lisp Expectations at the tail of this file.
597 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
598 ;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
601 ;; If you want to create anything sources, see anything-config.el.
602 ;; It is huge collection of sources. You can learn from examples.
605 ;; (@* "TODO")
607 ;; - process status indication
609 ;; - async sources doesn't honor digit-shortcut-count
611 ;; - anything-candidate-number-limit can't be nil everywhere
613 ;; (@* "HISTORY")
615 ;; Change log of this file is found at
616 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything.el
618 ;; Change log of this project is found at
619 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
624 ;;; Code:
626 (require 'cl)
628 (defvar anything-version "1.3.3")
630 ;; (@* "User Configuration")
633 ;;; Variables
636 ;; [DEPRECATED]
637 ;; A default value is provided in anything-config.el
638 (defvar anything-sources nil
639 "A list of sources to use with `anything'.
640 It is deprecated, you should not use this.
641 Use instead individual sources or list of sources of your choice.")
643 ;; Default values are provided in anything-config.el.
644 (defvar anything-type-attributes nil
645 "It's a list of \(TYPE ATTRIBUTES ...\).
646 ATTRIBUTES are the same as attributes for `anything-sources'.
647 TYPE connects the value to the appropriate sources.
648 Don't set this directly, use instead `define-anything-type-attribute'.
650 This allows specifying common attributes for several sources.
651 For example, sources which provide files can specify
652 common attributes with a `file' type.")
654 (defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
655 "Same as `anything-enable-shortcuts'.
656 Alphabet shortcuts are available now in `anything-enable-shortcuts'.
657 `anything-enable-digit-shortcuts' is retained for compatibility.")
659 (defvar anything-enable-shortcuts nil
660 "*Whether to use digit/alphabet shortcut to select the first nine matches.
661 If t then they can be selected using Ctrl+<number>.
663 If 'prefix then they can be selected using <prefix-key> <alnum>.
664 The prefix key is `anything-select-with-prefix-shortcut'.
665 If the <prefix-key> is a letter, pressing twice inputs the letter itself.
666 e.g.
667 (setq anything-enable-shortcuts 'prefix)
668 (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
670 If 'alphabet then they can be selected using Shift+<alphabet> (deprecated).
671 It is not recommended because you cannot input capital letters in pattern.
673 Keys (digit/alphabet) are listed in `anything-shortcut-keys-alist'.")
675 (defvar anything-shortcut-keys-alist
676 '((alphabet . "asdfghjklzxcvbnmqwertyuiop")
677 (prefix . "asdfghjklzxcvbnmqwertyuiop1234567890")
678 (t . "123456789")))
680 (defvar anything-display-source-at-screen-top t
681 "*Display candidates at the top of screen.
682 This happen when using `anything-next-source' and `anything-previous-source'.")
684 (defvar anything-candidate-number-limit 50
685 "*Limit candidate number globally.
686 Do not show more candidates than this limit from individual sources.
687 It is usually pointless to show hundreds of matches
688 when the pattern is empty, because it is much simpler to type a
689 few characters to narrow down the list of potential candidates.
691 Set it to nil if you don't want this limit.")
693 (defvar anything-idle-delay 0.3
694 "*Be idle for this many seconds, before updating in delayed sources.
695 This is useful for sources involving heavy operations
696 \(like launching external programs\), so that candidates
697 from the source are not retrieved unnecessarily if the user keeps typing.
699 It also can be used to declutter the results anything displays,
700 so that results from certain sources are not shown with every
701 character typed, only if the user hesitates a bit.")
703 (defvar anything-input-idle-delay 0.3
704 "Be idle for this many seconds, before updating.
706 Unlike `anything-idle-delay', it is also effective for non-delayed sources.
707 If nil, candidates are collected immediately.
709 Note: If this value is too low compared to `anything-idle-delay',
710 you may have duplicated sources when using multiples sources.
711 Safe value is always >= `anything-idle-delay'.
712 Default settings are equal value for both.")
714 (defvar anything-samewindow nil
715 "Use current window to show the candidates.
716 If t then Anything doesn't pop up a new window.")
718 (defvar anything-source-filter nil
719 "A list of source names to be displayed.
720 Other sources won't appear in the search results.
721 If nil then there is no filtering.
722 See also `anything-set-source-filter'.")
725 (defvar anything-map
726 (let ((map (copy-keymap minibuffer-local-map)))
727 (define-key map (kbd "<down>") 'anything-next-line)
728 (define-key map (kbd "<up>") 'anything-previous-line)
729 (define-key map (kbd "C-n") 'anything-next-line)
730 (define-key map (kbd "C-p") 'anything-previous-line)
731 (define-key map (kbd "<prior>") 'anything-previous-page)
732 (define-key map (kbd "<next>") 'anything-next-page)
733 (define-key map (kbd "M-v") 'anything-previous-page)
734 (define-key map (kbd "C-v") 'anything-next-page)
735 (define-key map (kbd "M-<") 'anything-beginning-of-buffer)
736 (define-key map (kbd "M->") 'anything-end-of-buffer)
737 (define-key map (kbd "C-g") 'anything-keyboard-quit)
738 (define-key map (kbd "<right>") 'anything-next-source)
739 (define-key map (kbd "<left>") 'anything-previous-source)
740 (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
741 (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
742 (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
743 (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
744 (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
745 (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
746 (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
747 (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
748 (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
749 (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
750 (loop for c from ?A to ?Z do
751 (define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
752 (define-key map (kbd "C-i") 'anything-select-action)
753 (define-key map (kbd "C-z") 'anything-execute-persistent-action)
754 (define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
755 (define-key map (kbd "C-j") 'anything-select-3rd-action)
756 (define-key map (kbd "C-o") 'anything-next-source)
757 (define-key map (kbd "C-M-v") 'anything-scroll-other-window)
758 (define-key map (kbd "M-<next>") 'anything-scroll-other-window)
759 (define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
760 (define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
761 (define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
762 (define-key map (kbd "<C-M-down>") 'anything-scroll-other-window)
763 (define-key map (kbd "<C-M-up>") 'anything-scroll-other-window-down)
764 (define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
765 (define-key map (kbd "M-[") 'anything-prev-visible-mark)
766 (define-key map (kbd "M-]") 'anything-next-visible-mark)
767 (define-key map (kbd "C-k") 'anything-delete-minibuffer-contents)
769 (define-key map (kbd "C-r") 'undefined)
770 (define-key map (kbd "C-t") 'anything-toggle-resplit-window)
771 (define-key map (kbd "C-}") 'anything-narrow-window)
772 (define-key map (kbd "C-{") 'anything-enlarge-window)
774 (define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
775 (define-key map (kbd "C-c C-y") 'anything-yank-selection)
776 (define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
777 (define-key map (kbd "C-c C-f") 'anything-follow-mode)
778 (define-key map (kbd "C-c C-u") 'anything-force-update)
779 (define-key map (kbd "M-p") 'previous-history-element)
780 (define-key map (kbd "M-n") 'next-history-element)
781 ;; Debugging command
782 (define-key map "\C-c\C-x\C-d" 'anything-debug-output)
783 (define-key map "\C-c\C-x\C-m" 'anything-display-all-visible-marks)
784 (define-key map "\C-c\C-x\C-b" 'anything-send-bug-report-from-anything)
785 ;; Use `describe-mode' key in `global-map'.
786 (define-key map [f1] nil) ; Allow to eval keymap whithout errors.
787 (dolist (k (where-is-internal 'describe-mode global-map))
788 (define-key map k 'anything-help))
789 map)
790 "Keymap for anything.")
793 (defgroup anything nil
794 "Open anything."
795 :prefix "anything-" :group 'convenience)
797 (defface anything-header
798 '((t (:inherit header-line)))
799 "Face for header lines in the anything buffer."
800 :group 'anything)
802 (defvar anything-header-face 'anything-header
803 "*Face for header lines in the anything buffer.")
805 (defface anything-candidate-number
806 '((t (:background "Yellow" :foreground "black")))
807 "Face for candidate number in mode-line." :group 'anything)
809 (defvar anything-selection-face 'highlight
810 "*Face for currently selected item.")
812 (defvar anything-buffer "*anything*"
813 "Buffer showing completions.")
815 (defvar anything-action-buffer "*anything action*"
816 "Buffer showing actions.")
818 (defvar anything-selection-overlay nil
819 "Overlay used to highlight the currently selected item.")
821 (defvar anything-digit-overlays nil
822 "Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
824 (defvar anything-candidate-cache nil
825 "Holds the available candidate withing a single anything invocation.")
827 (defvar anything-pattern
828 "The input pattern used to update the anything buffer.")
830 (defvar anything-input
831 "The input typed in the candidates panel.")
833 (defvar anything-async-processes nil
834 "List of information about asynchronous processes managed by anything.")
836 (defvar anything-digit-shortcut-count 0
837 "Number of digit shortcuts shown in the anything buffer.")
839 (defvar anything-before-initialize-hook nil
840 "Run before anything initialization.
841 This hook is run before init functions in `anything-sources'.")
843 (defvar anything-after-initialize-hook nil
844 "Run after anything initialization.
845 Global variables are initialized and the anything buffer is created.
846 But the anything buffer has no contents.")
848 (defvar anything-update-hook nil
849 "Run after the anything buffer was updated according the new input pattern.
850 This hook is run at the beginning of buffer.
851 The first candidate is selected after running this hook.
852 See also `anything-after-update-hook'.")
854 (defvar anything-after-update-hook nil
855 "Run after the anything buffer was updated according the new input pattern.
856 This is very similar to `anything-update-hook' but selection is not moved.
857 It is useful to select a particular object instead of the first one.")
859 (defvar anything-cleanup-hook nil
860 "Run after anything minibuffer is closed.
861 IOW this hook is executed BEFORE performing action.")
863 (defvar anything-before-action-hook nil
864 "Run before executing action.
865 Contrarily to `anything-cleanup-hook',
866 this hook run before anything minibuffer is closed
867 and before performing action.")
869 (defvar anything-after-action-hook nil
870 "Run after executing action.")
872 (defvar anything-after-persistent-action-hook nil
873 "Run after executing persistent action.")
875 (defvar anything-move-selection-before-hook nil
876 "Run before moving selection in `anything-buffer'.")
878 (defvar anything-move-selection-after-hook nil
879 "Run after moving selection in `anything-buffer'.")
881 (defvar anything-restored-variables
882 '( anything-candidate-number-limit
883 anything-source-filter
884 anything-source-in-each-line-flag
885 anything-map
886 anything-sources)
887 "Variables which are restored after `anything' invocation.")
889 (defvar anything-saved-selection nil
890 "Value of the currently selected object when the action list is shown.")
892 (defvar anything-current-prefix-arg nil
893 "Record `current-prefix-arg' when exiting minibuffer.")
895 (defvar anything-candidate-separator
896 "--------------------"
897 "Candidates separator of `multiline' source.")
899 (defvar anything-current-buffer nil
900 "Current buffer when `anything' is invoked.")
902 (defvar anything-buffer-file-name nil
903 "Variable `buffer-file-name' when `anything' is invoked.")
905 (defvar anything-saved-action nil
906 "Saved value of the currently selected action by key.")
908 (defvar anything-last-sources nil
909 "OBSOLETE!! Sources of previously invoked `anything'.")
911 (defvar anything-saved-current-source nil
912 "Value of the current source when the action list is shown.")
914 (defvar anything-compiled-sources nil
915 "Compiled version of `anything-sources'.")
917 (defvar anything-in-persistent-action nil
918 "Flag whether in persistent-action or not.")
920 (defvar anything-quick-update nil
921 "If non-nil, suppress displaying sources which are out of screen at first.
922 They are treated as delayed sources at this input.
923 This flag makes `anything' a bit faster with many sources.")
925 (defvar anything-last-sources-local nil
926 "Buffer local value of `anything-sources'.")
928 (defvar anything-last-buffer nil
929 "`anything-buffer' of previously `anything' session.")
931 (defvar anything-save-configuration-functions
932 '(set-window-configuration . current-window-configuration)
933 "The functions used to restore/save window or frame configurations.
934 It is a pair where the car is the function to restore window or frame config,
935 and the cdr is the function to save the window or frame config.
937 If you want to save and restore frame configuration, set this variable to
938 '\(set-frame-configuration . current-frame-configuration\)
940 Older version saves/restores frame configuration, but the default is changed now
941 because flickering can occur in some environment. ")
943 (defvar anything-persistent-action-use-special-display nil
944 "If non-nil, use `special-display-function' in persistent action.")
946 (defvar anything-execute-action-at-once-if-one nil
947 "Execute default action and exit when only one candidate is remaining.
948 It is useful for `anything' applications.")
950 (defvar anything-quit-if-no-candidate nil
951 "Quit when there is no candidates when non--nil.
952 This variable accepts a function, which is executed if no candidate.
954 It is useful for `anything' applications.")
956 (defvar anything-scroll-amount nil
957 "Scroll amount when scrolling other window in an anything session.
958 It is used by `anything-scroll-other-window'
959 and `anything-scroll-other-window-down'.
961 If you prefer scrolling line by line, set this value to 1.")
963 (defvar anything-display-function 'anything-default-display-buffer
964 "Function to display *anything* buffer.
965 It is `anything-default-display-buffer' by default,
966 which affects `anything-samewindow'.")
968 (defvar anything-delayed-init-executed nil)
970 (defvar anything-mode-line-string "\\<anything-map>\\[anything-help]:help \
971 \\[anything-select-action]:Acts \
972 \\[anything-exit-minibuffer]/\\[anything-select-2nd-action-or-end-of-line]/\
973 \\[anything-select-3rd-action]:NthAct \
974 \\[anything-send-bug-report-from-anything]:BugReport"
975 "Help string displayed in mode-line in `anything'.
976 It can be a string or a list of two args, in this case,
977 first arg is a string that will be used as name for candidates number,
978 second arg any string to display in mode line.
979 If nil, use default `mode-line-format'.")
981 (defvar anything-help-message
982 "\\<anything-map>The keys that are defined for `anything' are:
983 \\{anything-map}"
984 "Detailed help message string for `anything'.
985 It also accepts function or variable symbol.")
987 ;; FIXME: What is this
988 ;(put 'anything 'timid-completion 'disabled)
990 (defvar anything-source-in-each-line-flag nil
991 "Non-nil means add anything-source text-property in each candidate.
992 experimental feature.")
994 (defvaralias 'anything-debug-variables 'anything-debug-forms)
996 (defvar anything-debug-forms nil
997 "Forms to show in `anything-debug-output'.
998 Otherwise all variables started with `anything-' are shown.
999 It is useful for debug.")
1001 (defvar anything-debug nil
1002 "If non-nil, write log message into *Anything Log* buffer.
1003 If `debug-on-error' is non-nil, write log message regardless of this variable.
1004 It is disabled by default because *Anything Log* grows quickly.")
1007 ;; (@* "Internal Variables")
1008 (defvar anything-test-candidate-list nil)
1009 (defvar anything-test-mode nil)
1010 (defvar anything-source-name nil)
1011 (defvar anything-candidate-buffer-alist nil)
1012 (defvar anything-check-minibuffer-input-timer nil)
1013 (defvar anything-match-hash (make-hash-table :test 'equal))
1014 (defvar anything-cib-hash (make-hash-table :test 'equal))
1015 (defvar anything-tick-hash (make-hash-table :test 'equal))
1016 (defvar anything-issued-errors nil)
1017 (defvar anything-shortcut-keys nil)
1018 (defvar anything-once-called-functions nil)
1019 (defvar anything-follow-mode nil)
1020 (defvar anything-let-variables nil)
1021 (defvar anything-split-window-state nil)
1024 ;; (@* "Utility: logging")
1025 (defun anything-log (format-string &rest args)
1026 "Log message if `debug-on-error' or `anything-debug' is non-nil.
1027 Messages are written to the *Anything Log* buffer.
1029 Argument FORMAT-STRING is a string to use with `format'.
1030 Use optional arguments ARGS like in `format'."
1031 (when (or debug-on-error anything-debug)
1032 (with-current-buffer (get-buffer-create "*Anything Log*")
1033 (buffer-disable-undo)
1034 (set (make-local-variable 'inhibit-read-only) t)
1035 (goto-char (point-max))
1036 (insert (let ((tm (current-time)))
1037 (format "%s.%06d (%s) %s\n"
1038 (format-time-string "%H:%M:%S" tm)
1039 (nth 2 tm)
1040 (anything-log-get-current-function)
1041 (apply #'format (cons format-string args))))))))
1043 (defmacro anything-log-eval (&rest exprs)
1044 "Write each EXPRS evaluation result to the *Anything Log* buffer."
1045 `(anything-log-eval-internal ',exprs))
1047 (defun anything-log-run-hook (hook)
1048 "Run HOOK like `run-hooks' but write these actions to anything log buffer."
1049 (anything-log "executing %s" hook)
1050 (when (boundp hook)
1051 (anything-log-eval (symbol-value hook))
1052 (anything-log-eval (default-value hook)))
1053 (run-hooks hook)
1054 (anything-log "executed %s" hook))
1056 (defun anything-log-eval-internal (exprs)
1057 "Eval EXPRS and write results to anything log buffer."
1058 (dolist (expr exprs)
1059 (condition-case err
1060 (anything-log "%S = %S" expr (eval expr))
1061 (error (anything-log "%S = ERROR!" expr)))))
1063 (defun anything-log-get-current-function ()
1064 "Get function name calling `anything-log'.
1065 The original idea is from `tramp-debug-message'."
1066 (loop with exclude-func-re = "^anything-\\(?:interpret\\|log\\|.*funcall\\)"
1067 for btn from 1 to 40 ;avoid inf-loop
1068 for btf = (second (backtrace-frame btn))
1069 for fn = (if (symbolp btf) (symbol-name btf) "")
1070 if (and (string-match "^anything" fn)
1071 (not (string-match exclude-func-re fn)))
1072 return fn))
1074 (defun anything-log-error (&rest args)
1075 "Accumulate error messages into `anything-issued-errors'.
1076 ARGS are args given to `format'."
1077 (apply 'anything-log (concat "ERROR: " (car args)) (cdr args))
1078 (let ((msg (apply 'format args)))
1079 (unless (member msg anything-issued-errors)
1080 (add-to-list 'anything-issued-errors msg))))
1082 (defvar anything-last-log-file nil)
1083 (defun anything-log-save-maybe ()
1084 "May be save log buffer to `anything-last-log-file'."
1085 (when (stringp anything-debug)
1086 (let ((logdir (expand-file-name (format-time-string "%Y%m%d")
1087 anything-debug)))
1088 (make-directory logdir t)
1089 (with-current-buffer (get-buffer-create "*Anything Log*")
1090 (write-region (point-min) (point-max)
1091 (setq anything-last-log-file
1092 (expand-file-name (format-time-string "%Y%m%d-%H%M%S")
1093 logdir))
1094 nil 'silent)
1095 (erase-buffer)))))
1097 (defun anything-open-last-log ()
1098 "Open anything log file of last anything session."
1099 (interactive)
1100 (if anything-last-log-file
1101 (view-file anything-last-log-file)
1102 (switch-to-buffer "*Anything Log*")))
1104 (defun anything-print-error-messages ()
1105 "Print error messages in `anything-issued-errors'."
1106 (message "%s" (mapconcat 'identity (reverse anything-issued-errors) "\n")))
1108 ;; (anything-log "test")
1109 ;; (switch-to-buffer-other-window "*Anything Log*")
1112 ;; (@* "Programming Tools")
1113 (defmacro anything-aif (test-form then-form &rest else-forms)
1114 "Like `if' but set the result of TEST-FORM in a temprary variable called `it'.
1115 THEN-FORM and ELSE-FORMS are then excuted just like in `if'."
1116 (declare (indent 2) (debug t))
1117 `(let ((it ,test-form))
1118 (if it ,then-form ,@else-forms)))
1120 (defun anything-mklist (obj)
1121 "If OBJ is a list \(but not lambda\), return itself.
1122 Otherwise make a list with one element."
1123 (if (and (listp obj) (not (functionp obj)))
1125 (list obj)))
1128 ;; (@* "Anything API")
1130 (defun anything-buffer-get ()
1131 "Return `anything-action-buffer' if shown otherwise `anything-buffer'."
1132 (if (anything-action-window)
1133 anything-action-buffer
1134 anything-buffer))
1136 (defun anything-window ()
1137 "Window of `anything-buffer'."
1138 (get-buffer-window (anything-buffer-get) 'visible))
1140 (defun anything-action-window ()
1141 "Window of `anything-action-buffer'."
1142 (get-buffer-window anything-action-buffer 'visible))
1144 (defmacro with-anything-window (&rest body)
1145 "Be sure BODY is excuted in the anything window."
1146 (declare (indent 0) (debug t))
1147 `(if anything-test-mode
1148 (with-current-buffer (anything-buffer-get)
1149 ,@body)
1150 (with-selected-window (anything-window)
1151 ,@body)))
1153 (defmacro with-anything-current-buffer (&rest body)
1154 "Eval BODY inside `anything-current-buffer'."
1155 (declare (indent 0) (debug t))
1156 `(with-current-buffer anything-current-buffer
1157 ,@body))
1159 (defmacro with-anything-restore-variables(&rest body)
1160 "Restore `anything-restored-variables' after executing BODY.
1161 `post-command-hook' is handled specially."
1162 (declare (indent 0) (debug t))
1163 `(let ((--orig-vars (mapcar (lambda (v)
1164 (cons v (symbol-value v)))
1165 anything-restored-variables))
1166 (--post-command-hook-pair (cons post-command-hook
1167 (default-value 'post-command-hook))))
1168 (setq post-command-hook '(t))
1169 (setq-default post-command-hook nil)
1170 (unwind-protect (progn ,@body)
1171 (loop for (var . value) in --orig-vars
1172 do (set var value))
1173 (setq post-command-hook (car --post-command-hook-pair))
1174 (setq-default post-command-hook (cdr --post-command-hook-pair))
1175 (anything-log "restore variables"))))
1177 (defun* anything-attr (attribute-name &optional (src (anything-get-current-source)))
1178 "Get the value of ATTRIBUTE-NAME of SRC.
1179 if SRC is omitted, use current source.
1180 It is useful to write your sources."
1181 (anything-aif (assq attribute-name src)
1182 (cdr it)))
1184 (defun* anything-attr* (attribute-name &optional (src (anything-get-current-source)))
1185 "Pass the value of ATTRIBUTE-NAME of SRC to `anything-interpret-value'.
1186 if SRC is omitted, use current source.
1187 It is useful to write your sources."
1188 (anything-interpret-value (anything-attr attribute-name src)))
1190 (defun* anything-attr-defined (attribute-name &optional (src (anything-get-current-source)))
1191 "Return non-nil if ATTRIBUTE-NAME of SRC is defined.
1192 if SRC is omitted, use current source.
1193 It is useful to write your sources."
1194 (and (assq attribute-name src) t))
1196 (defun* anything-attrset (attribute-name value &optional (src (anything-get-current-source)))
1197 "Set the value of ATTRIBUTE-NAME of SRC to VALUE.
1198 if SRC is omitted, use current source.
1199 It is useful to write your sources."
1200 (anything-aif (assq attribute-name src)
1201 (setcdr it value)
1202 (setcdr src (cons (cons attribute-name value) (cdr src))))
1203 value)
1205 (defun anything-set-source-filter (sources)
1206 "Set the value of `anything-source-filter' to SOURCES and update.
1208 This function sets a filter for anything sources and it may be
1209 called while anything is running. It can be used to toggle
1210 displaying of sources dinamically. For example, additional keys
1211 can be bound into `anything-map' to display only the file-related
1212 results if there are too many matches from other sources and
1213 you're after files only:
1215 Shift+F shows only file results from some sources:
1217 \(define-key anything-map \"F\" 'anything-my-show-files-only)
1219 \(defun anything-my-show-files-only ()
1220 (interactive)
1221 (anything-set-source-filter '(\"File Name History\"
1222 \"Files from Current Directory\")))
1224 Shift+A shows all results:
1226 \(define-key anything-map \"A\" 'anything-my-show-all)
1228 \(defun anything-my-show-all ()
1229 (interactive)
1230 (anything-set-source-filter nil))
1232 Note that you have to prefix the functions with anything- prefix,
1233 otherwise they won't be bound when Anything is used under
1234 Iswitchb. The -my- part is added to avoid collisions with
1235 existing Anything function names."
1236 (unless (and (listp sources)
1237 (loop for name in sources always (stringp name)))
1238 (error "Invalid data in `anything-set-source-filter': %S" sources))
1239 (setq anything-source-filter sources)
1240 (anything-log-eval anything-source-filter)
1241 (anything-update))
1243 (defun anything-set-sources (sources &optional no-init no-update)
1244 "Set SOURCES during `anything' invocation.
1245 If NO-INIT is non-nil, skip executing init functions of SOURCES.
1246 If NO-UPDATE is non-nil, skip executing `anything-update'."
1247 (with-current-buffer anything-buffer
1248 (setq anything-compiled-sources nil
1249 anything-sources sources
1250 anything-last-sources-local sources)
1251 (anything-log-eval anything-compiled-sources anything-sources))
1252 (unless no-init (anything-funcall-foreach 'init))
1253 (unless no-update (anything-update)))
1255 (defvar anything-compile-source-functions
1256 '(anything-compile-source--type
1257 anything-compile-source--dummy
1258 anything-compile-source--disable-shortcuts
1259 anything-compile-source--candidates-in-buffer)
1260 "Functions to compile elements of `anything-sources' (plug-in).")
1262 (defun anything-get-sources ()
1263 "Return compiled `anything-sources', which is memoized.
1265 Attributes:
1267 - type
1268 `anything-type-attributes' are merged in.
1269 - candidates-buffer
1270 candidates, volatile and match attrubute are created."
1271 (cond
1272 ;; action
1273 ((anything-action-window)
1274 anything-sources)
1275 ;; memoized
1276 (anything-compiled-sources)
1277 ;; first time
1279 (prog1
1280 (setq anything-compiled-sources
1281 (anything-compile-sources
1282 anything-sources anything-compile-source-functions))
1283 (anything-log-eval anything-compiled-sources)))))
1285 (defun* anything-get-selection (&optional (buffer nil buffer-s) (force-display-part))
1286 "Return the currently selected item or nil.
1287 if BUFFER is nil or unspecified, use anything-buffer as default value.
1288 If FORCE-DISPLAY-PART is non-nil, return the display string."
1289 (setq buffer (if (and buffer buffer-s) buffer anything-buffer))
1290 (unless (anything-empty-buffer-p buffer)
1291 (with-current-buffer buffer
1292 (let ((selection
1293 (or (and (not force-display-part)
1294 (get-text-property (overlay-start
1295 anything-selection-overlay)
1296 'anything-realvalue))
1297 (let ((disp (buffer-substring-no-properties
1298 (overlay-start anything-selection-overlay)
1299 (1- (overlay-end anything-selection-overlay))))
1300 (source (anything-get-current-source)))
1301 (anything-aif (and (not force-display-part)
1302 (assoc-default 'display-to-real source))
1303 (anything-funcall-with-source source it disp)
1304 disp)))))
1305 (unless (equal selection "")
1306 (anything-log-eval selection)
1307 selection)))))
1309 (defun anything-get-action ()
1310 "Return the associated action for the selected candidate.
1311 It is a function symbol \(sole action\) or list
1312 of \(action-display . function\)."
1313 (unless (anything-empty-buffer-p (anything-buffer-get))
1314 (anything-aif (anything-attr 'action-transformer)
1315 (anything-composed-funcall-with-source
1316 (anything-get-current-source) it
1317 (anything-attr 'action) (anything-get-selection))
1318 (anything-attr 'action))))
1320 (defun anything-get-current-source ()
1321 "Return the source for the current selection.
1322 Use it in init, candidates, action, candidate-transformer,
1323 filtered-candidate-transformer functions."
1324 (declare (special source))
1325 ;; The name `anything-get-current-source' should be used in init function etc.
1326 (if (and (boundp 'anything-source-name) (stringp anything-source-name))
1327 source
1328 (with-current-buffer (anything-buffer-get)
1329 (or (get-text-property (point) 'anything-source)
1330 (block exit
1331 ;; This goto-char shouldn't be necessary, but point is moved to
1332 ;; point-min somewhere else which shouldn't happen.
1333 (goto-char (overlay-start anything-selection-overlay))
1334 (let* ((header-pos (or (anything-get-previous-header-pos)
1335 (anything-get-next-header-pos)))
1336 (source-name
1337 (save-excursion
1338 (unless header-pos
1339 ;(message "No candidates")
1340 (return-from exit nil))
1341 (goto-char header-pos)
1342 (anything-current-line-contents))))
1343 (some (lambda (source)
1344 (if (equal (assoc-default 'name source) source-name)
1345 source))
1346 (anything-get-sources))))))))
1348 (defun anything-buffer-is-modified (buffer)
1349 "Return non-nil when BUFFER is modified since `anything' was invoked."
1350 (let* ((b (get-buffer buffer))
1351 (key (concat (buffer-name b) "/" (anything-attr 'name)))
1352 (source-tick (or (gethash key anything-tick-hash) 0))
1353 (buffer-tick (buffer-chars-modified-tick b))
1354 (modifiedp (/= source-tick buffer-tick)))
1355 (puthash key buffer-tick anything-tick-hash)
1356 (anything-log-eval buffer modifiedp)
1357 modifiedp))
1359 (defun anything-current-buffer-is-modified ()
1360 "Check if `anything-current-buffer' is modified since `anything' was invoked."
1361 (anything-buffer-is-modified anything-current-buffer))
1363 (defvar anything-quit nil)
1364 (defun anything-run-after-quit (function &rest args)
1365 "Perform an action after quitting `anything'.
1366 The action is to call FUNCTION with arguments ARGS."
1367 (setq anything-quit t)
1368 (anything-log-eval function args)
1369 (apply 'run-with-idle-timer 0 nil function args)
1370 (anything-exit-minibuffer))
1373 (defun define-anything-type-attribute (type definition &optional doc)
1374 "Register type attribute of TYPE as DEFINITION with DOC.
1375 DOC is displayed in `anything-type-attributes' docstring.
1377 Use this function is better than setting `anything-type-attributes' directly."
1378 (loop for i in definition do
1379 ;; without `ignore-errors', error at emacs22
1380 (ignore-errors (setf i (delete nil i))))
1381 (anything-add-type-attribute type definition)
1382 (and doc (anything-document-type-attribute type doc))
1383 nil)
1385 (defvaralias 'anything-attributes 'anything-additional-attributes)
1386 (defvar anything-additional-attributes nil
1387 "List of all `anything' attributes.")
1388 (defun anything-document-attribute (attribute short-doc &optional long-doc)
1389 "Register ATTRIBUTE documentation introduced by plug-in.
1390 SHORT-DOC is displayed beside attribute name.
1391 LONG-DOC is displayed below attribute name and short documentation."
1392 (declare (indent 2) (debug t))
1393 (if long-doc
1394 (setq short-doc (concat "(" short-doc ")"))
1395 (setq long-doc short-doc
1396 short-doc ""))
1397 (add-to-list 'anything-additional-attributes attribute t)
1398 (put attribute 'anything-attrdoc
1399 (concat "- " (symbol-name attribute)
1400 " " short-doc "\n\n" long-doc "\n")))
1403 (defun anything-interpret-value (value &optional source)
1404 "Interpret VALUE as variable, function or literal.
1405 If VALUE is a function, call it with no arguments and return the value.
1406 If SOURCE is `anything' source, `anything-source-name' is source name.
1408 If VALUE is a variable, return the value.
1410 If VALUE is a symbol, but it is not a function or a variable, cause an error.
1412 Otherwise, return VALUE itself."
1413 (cond ((and source (functionp value))
1414 (anything-funcall-with-source source value))
1415 ((functionp value)
1416 (funcall value))
1417 ((and (symbolp value) (boundp value))
1418 (symbol-value value))
1419 ((symbolp value)
1420 (error "anything-interpret-value: Symbol must be a function or a variable"))
1422 value)))
1424 (defun anything-once (function &rest args)
1425 "Ensure FUNCTION with ARGS to be called once in `anything' session."
1426 (let ((spec (cons function args)))
1427 (unless (member spec anything-once-called-functions)
1428 (apply function args)
1429 (push spec anything-once-called-functions))))
1432 ;; (@* "Core: API helper")
1433 (defun* anything-empty-buffer-p (&optional (buffer anything-buffer))
1434 "Check if BUFFER have candidates.
1435 Default value for BUFFER is `anything-buffer'."
1436 (zerop (buffer-size (and buffer (get-buffer buffer)))))
1438 (defun anything-let-eval-varlist (varlist)
1439 "Return the list of pairs VARLIST with each cdr of pair evaluated.
1440 If VARLIST contain single elements, those are returned
1441 as a list of one element."
1442 (mapcar (lambda (pair)
1443 (if (listp pair)
1444 (cons (car pair) (eval (cadr pair)))
1445 (cons pair nil)))
1446 varlist))
1448 ;; [NOT USED]
1449 ;; (defun anything-let*-eval-varlist (varlist)
1450 ;; (let ((vars (mapcar (lambda (pair)
1451 ;; (or (car-safe pair) pair))
1452 ;; varlist)))
1453 ;; (eval `(let ,vars
1454 ;; ,@(mapcar (lambda (pair)
1455 ;; (if (listp pair)
1456 ;; `(setq ,(car pair) ,(cadr pair))
1457 ;; `(setq ,pair nil)))
1458 ;; varlist)
1459 ;; (mapcar (lambda (v)
1460 ;; (cons v (symbol-value v)))
1461 ;; ',vars)))))
1463 (defun anything-let-internal (binding bodyfunc)
1464 "Set BINDING to anything buffer-local variables and Evaluate BODYFUNC.
1465 BINDING is a list of \(VARNAME . VALUE\) pair."
1466 (setq anything-let-variables binding)
1467 (unwind-protect
1468 (funcall bodyfunc)
1469 (setq anything-let-variables nil)))
1472 ;; (@* "Core: tools")
1473 (defun anything-current-line-contents ()
1474 "Current line string without properties."
1475 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
1477 (defun anything-funcall-with-source (source func &rest args)
1478 "Call from SOURCE FUNC list or single function FUNC with ARGS.
1479 FUNC can be a symbol or a list of functions.
1480 Return the result of last function call."
1481 (let ((anything-source-name (assoc-default 'name source))
1482 result)
1483 (anything-log-eval anything-source-name func args)
1484 (dolist (func (if (functionp func) (list func) func) result)
1485 (setq result (apply func args)))))
1487 (defun anything-funcall-foreach (sym)
1488 "Call the function SYM for each source if any."
1489 (dolist (source (anything-get-sources))
1490 (anything-aif (assoc-default sym source)
1491 (anything-funcall-with-source source it))))
1493 (defun anything-normalize-sources (sources)
1494 "If SOURCES is only one source, make a list of one element."
1495 (cond ((or (and sources
1496 (symbolp sources))
1497 (and (listp sources) (assq 'name sources)))
1498 (list sources))
1499 (sources)
1500 (t anything-sources)))
1502 (defun anything-approximate-candidate-number (&optional in-current-source)
1503 "Return approximate number of candidates in `anything-buffer'.
1504 If IN-CURRENT-SOURCE is provided return number of candidates
1505 in the source where point is.
1506 It is used to check if candidate number is 0, 1, or 2+."
1507 (with-current-buffer anything-buffer
1508 (save-excursion
1509 (if in-current-source
1510 (goto-char (anything-get-previous-header-pos))
1511 (goto-char (point-min)))
1512 (forward-line 1)
1513 (let ((count-multi 1))
1514 (if (anything-pos-multiline-p)
1515 (save-excursion
1516 (loop while (and (not (if in-current-source
1517 (save-excursion
1518 (forward-line 2)
1519 (or (anything-pos-header-line-p) (eobp)))
1520 (eobp)))
1521 (search-forward anything-candidate-separator nil t))
1522 do (incf count-multi)
1523 finally return count-multi))
1524 (save-excursion
1525 (loop with ln = 0
1526 while (not (if in-current-source
1527 (or (anything-pos-header-line-p) (eobp))
1528 (eobp)))
1529 unless (anything-pos-header-line-p)
1530 do (incf ln)
1531 do (forward-line 1) finally return ln)))))))
1533 (defmacro with-anything-quittable (&rest body)
1534 "If an error occur in execution of BODY, quit anything safely."
1535 (declare (indent 0) (debug t))
1536 `(let (inhibit-quit)
1537 (condition-case v
1538 (progn ,@body)
1539 (quit (setq anything-quit t)
1540 (exit-minibuffer)
1541 (keyboard-quit)))))
1543 (defun anything-compose (arg-lst func-lst)
1544 "Apply arguments specified in ARG-LST with each function of FUNC-LST.
1545 The result of each function will be the new `car' of ARG-LST.
1547 This function allows easy sequencing of transformer functions."
1548 (dolist (func func-lst)
1549 (setcar arg-lst (apply func arg-lst)))
1550 (car arg-lst))
1552 (defun anything-composed-funcall-with-source (source funcs &rest args)
1553 "With SOURCE apply `anything-funcall-with-source' with each FUNCS and ARGS.
1554 This is used in transformers to modify candidates list."
1555 (if (functionp funcs)
1556 (apply 'anything-funcall-with-source source funcs args)
1557 (apply 'anything-funcall-with-source source
1558 (lambda (&rest args)
1559 (anything-compose args funcs))
1560 args)))
1562 (defun anything-new-timer (variable timer)
1563 "Give VARIABLE value to TIMER and cancel old timer."
1564 (anything-aif (symbol-value variable)
1565 (cancel-timer it))
1566 (set variable timer))
1569 ;; (@* "Core: entry point")
1570 (defconst anything-argument-keys
1571 '(:sources :input :prompt :resume :preselect :buffer :keymap :default :history))
1573 ;;;###autoload
1574 (defun anything (&rest plist)
1575 "Main function to execute anything sources.
1577 When call interactively with no arguments deprecated `anything-sources'
1578 will be used if non--nil.
1580 PLIST is a list like \(:key1 val1 :key2 val2 ...\) or
1581 \(&optional sources input prompt resume preselect buffer keymap\).
1583 Basic keywords are the following:
1585 \:sources
1587 Temporary value of `anything-sources'. It also accepts a
1588 symbol, interpreted as a variable of an anything source. It
1589 also accepts an alist representing an anything source, which is
1590 detected by \(assq 'name ANY-SOURCES\)
1592 \:input
1594 Temporary value of `anything-pattern', ie. initial input of minibuffer.
1596 \:prompt
1598 Prompt other than \"pattern: \".
1600 \:resume
1602 If t, Resurrect previously instance of `anything'. Skip the initialization.
1603 If 'noresume, this instance of `anything' cannot be resumed.
1605 \:preselect
1607 Initially selected candidate. Specified by exact candidate or a regexp.
1608 Note that it is not working with delayed sources.
1610 \:buffer
1612 `anything-buffer' instead of *anything*.
1614 \:keymap
1616 `anything-map' for current `anything' session.
1618 \:default
1620 A default argument that will be inserted in minibuffer \
1621 with \\<minibuffer-local-map>\\[next-history-element].
1622 When nil of not present `thing-at-point' will be used instead.
1624 \:history
1626 By default all minibuffer input is pushed to `minibuffer-history',
1627 if an argument HISTORY is provided, input will be pushed to HISTORY.
1628 History element should be a symbol.
1630 Of course, conventional arguments are supported, the two are same.
1632 \(anything :sources sources :input input :prompt prompt :resume resume
1633 :preselect preselect :buffer buffer :keymap keymap\)
1634 \(anything sources input prompt resume preselect buffer keymap\)
1636 Other keywords are interpreted as local variables of this anything session.
1637 The `anything-' prefix can be omitted. For example,
1639 \(anything :sources 'anything-c-source-buffers
1640 :buffer \"*buffers*\" :candidate-number-limit 10\)
1642 means starting anything session with `anything-c-source-buffers'
1643 source in *buffers* buffer and set variable `anything-candidate-number-limit'
1644 to 10 as session local variable."
1645 (interactive)
1646 (if (keywordp (car plist))
1647 (anything-let-internal
1648 (anything-parse-keys plist)
1649 (lambda ()
1650 (apply 'anything
1651 (mapcar (lambda (key) (plist-get plist key))
1652 anything-argument-keys))))
1653 (apply 'anything-internal plist)))
1655 (defun* anything-resume (&optional
1656 (any-buffer anything-last-buffer)
1657 buffer-pattern (any-resume t))
1658 "Resurrect previously invoked `anything'.
1659 Called with a prefix arg, allow choosing among all existing
1660 anything buffers. i.e choose among various anything sessions."
1661 (interactive)
1662 (when (or current-prefix-arg buffer-pattern)
1663 (setq any-buffer (anything-resume-select-buffer buffer-pattern)))
1664 (setq anything-compiled-sources nil)
1665 (anything
1666 (or (buffer-local-value 'anything-last-sources-local (get-buffer any-buffer))
1667 anything-last-sources anything-sources)
1668 (buffer-local-value 'anything-input-local (get-buffer any-buffer))
1669 nil any-resume nil any-buffer))
1671 ;;; rubikitch: experimental
1672 ;;; I use this and check it whether I am convenient.
1673 ;;; I may introduce an option to control the behavior.
1674 (defun* anything-resume-window-only (&optional
1675 (any-buffer anything-last-buffer)
1676 buffer-pattern)
1677 (interactive)
1678 (anything-resume any-buffer buffer-pattern 'window-only))
1680 ;;;###autoload
1681 (defun anything-at-point (&optional
1682 any-sources any-input
1683 any-prompt any-resume
1684 any-preselect any-buffer)
1685 "Call anything with symbol at point as initial input.
1686 ANY-SOURCES ANY-INPUT ANY-PROMPT ANY-RESUME ANY-PRESELECT and ANY-BUFFER
1687 are same args as in `anything'."
1688 (interactive)
1689 (anything any-sources
1690 (if current-prefix-arg
1691 (concat "\\b" (thing-at-point 'symbol) "\\b"
1692 (if (featurep 'anything-match-plugin) " " ""))
1693 any-input)
1694 any-prompt any-resume any-preselect any-buffer))
1696 ;;;###autoload
1697 (defun anything-other-buffer (any-sources any-buffer)
1698 "Simplified interface of `anything' with other `anything-buffer'.
1699 Call `anything' with only ANY-SOURCES and ANY-BUFFER as args."
1700 (anything any-sources nil nil nil nil any-buffer))
1703 ;;; (@* "Core: entry point helper")
1704 (defun anything-internal (&optional
1705 any-sources any-input
1706 any-prompt any-resume
1707 any-preselect any-buffer
1708 any-keymap any-default any-history)
1709 "The internal anything function called by `anything'.
1710 For ANY-SOURCES ANY-INPUT ANY-PROMPT ANY-RESUME ANY-PRESELECT ANY-BUFFER and
1711 ANY-KEYMAP See `anything'."
1712 (anything-log "++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
1713 (anything-log-eval any-prompt any-preselect any-buffer any-keymap any-default)
1714 (unwind-protect
1715 (condition-case v
1716 (let ( ;; It is needed because `anything-source-name' is non-nil
1717 ;; when `anything' is invoked by action. Awful global scope.
1718 anything-source-name
1719 anything-in-persistent-action
1720 anything-quit
1721 (case-fold-search t)
1722 (anything-buffer (or any-buffer anything-buffer))
1723 ;; cua-mode ; avoid error when region is selected
1725 (with-anything-restore-variables
1726 (anything-initialize any-resume any-input any-sources)
1727 (anything-display-buffer anything-buffer)
1728 (anything-log "show prompt")
1729 (unwind-protect
1730 (anything-read-pattern-maybe
1731 any-prompt any-input any-preselect any-resume any-keymap any-default)
1732 (anything-cleanup)))
1733 (prog1 (unless anything-quit (anything-execute-selection-action-1 any-history))
1734 (anything-log "end session --------------------------------------------")))
1735 (quit
1736 (anything-restore-position-on-quit)
1737 (anything-log "end session (quit) -------------------------------------")
1738 nil))
1739 (anything-log-save-maybe)))
1741 (defun anything-parse-keys (keys)
1742 "Parse the KEYS arguments of `anything'."
1743 (loop for (key value &rest _) on keys by #'cddr
1744 for symname = (substring (symbol-name key) 1)
1745 for sym = (intern (if (string-match "^anything-" symname)
1746 symname
1747 (concat "anything-" symname)))
1748 unless (memq key anything-argument-keys)
1749 collect (cons sym value)))
1751 (defun anything-resume-p (any-resume)
1752 "Whether current anything session is resumed or not.
1753 Just check if ANY-RESUME value is t or window-only."
1754 (memq any-resume '(t window-only)))
1756 (defvar anything-buffers nil
1757 "All of `anything-buffer' in most recently used order.")
1758 (defun anything-initialize (any-resume any-input any-sources)
1759 "Start initialization of `anything' session.
1760 For ANY-RESUME ANY-INPUT and ANY-SOURCES See `anything'."
1761 (anything-log "start initialization: any-resume=%S any-input=%S" any-resume any-input)
1762 (anything-frame-or-window-configuration 'save)
1763 (setq anything-sources (anything-normalize-sources any-sources))
1764 (anything-log "sources = %S" anything-sources)
1765 (anything-hooks 'setup)
1766 (anything-current-position 'save)
1767 (if (anything-resume-p any-resume)
1768 (anything-initialize-overlays (anything-buffer-get))
1769 (anything-initial-setup))
1770 (unless (eq any-resume 'noresume)
1771 (anything-recent-push anything-buffer 'anything-buffers)
1772 (setq anything-last-buffer anything-buffer))
1773 (when any-input (setq anything-input any-input anything-pattern any-input))
1774 (and (anything-resume-p any-resume) (anything-funcall-foreach 'resume))
1775 (anything-log "end initialization"))
1777 ;; Here defun* allow using implicit block `anything-execute-selection-action-1'.
1778 (defun* anything-execute-selection-action-1 (&optional history)
1779 "Execute current action.
1780 Push current input to HISTORY if present, otherwise
1781 minibuffer-history will be used instead."
1782 (anything-log-run-hook 'anything-before-action-hook)
1783 (unwind-protect
1784 (anything-execute-selection-action)
1785 (anything-aif (get-buffer anything-action-buffer)
1786 (kill-buffer it))
1787 (when (and history (not (string= anything-pattern "")))
1788 (set history (cons anything-pattern (symbol-value history))))
1789 (anything-log-run-hook 'anything-after-action-hook)))
1791 (defun anything-restore-position-on-quit ()
1792 "Restore position in `anything-current-buffer' when quitting."
1793 (anything-current-position 'restore))
1795 (defun anything-resume-select-buffer (input)
1796 "Resume precedent anything session with initial input INPUT."
1797 (anything '(((name . "Resume anything buffer")
1798 (candidates . anything-buffers)
1799 (action . identity)))
1800 input nil 'noresume nil "*anything resume*"))
1802 (defun anything-recent-push (elt list-var)
1803 "Add ELT to the value of LIST-VAR as most recently used value."
1804 (let ((m (member elt (symbol-value list-var))))
1805 (and m (set list-var (delq (car m) (symbol-value list-var))))
1806 (push elt (symbol-value list-var))))
1809 ;;; (@* "Core: Accessors")
1810 ;;; rubikitch: I love to create functions to control variables.
1811 (defvar anything-current-position nil
1812 "Cons of \(point . window-start\) when `anything' is invoked.
1813 It is needed to restore position in `anything-current-buffer'
1814 when `anything' is keyboard-quitted.")
1815 (defun anything-current-position (save-or-restore)
1816 "Restore or save current position in `anything-current-buffer'.
1817 Argument SAVE-OR-RESTORE is one of save or restore."
1818 (case save-or-restore
1819 (save
1820 (anything-log "Save position at %S" (cons (point) (window-start)))
1821 (setq anything-current-position (cons (point) (window-start))))
1822 (restore
1823 (anything-log "Restore position at %S in buffer %s"
1824 anything-current-position
1825 (buffer-name (current-buffer)))
1826 (goto-char (car anything-current-position))
1827 ;; Fix this position with the NOFORCE arg of `set-window-start'
1828 ;; otherwise, if there is some other buffer than `anything-current-buffer'
1829 ;; one, position will be lost.
1830 (set-window-start (selected-window) (cdr anything-current-position) t))))
1833 ;; Internal.
1834 (defvar anything-last-frame-or-window-configuration nil
1835 "Used to store window or frame configuration when anything start.")
1836 (defun anything-frame-or-window-configuration (save-or-restore)
1837 "Save or restore last frame or window configuration.
1838 Possible value of SAVE-OR-RESTORE are 'save and 'restore.
1839 window or frame configuration is saved/restored according to values of
1840 `anything-save-configuration-functions'."
1841 (anything-log-eval anything-save-configuration-functions)
1842 (case save-or-restore
1843 (save (setq anything-last-frame-or-window-configuration
1844 (funcall (cdr anything-save-configuration-functions))))
1845 (restore (funcall (car anything-save-configuration-functions)
1846 anything-last-frame-or-window-configuration)
1847 ;; Restore frame focus.
1848 (let ((frame (and (listp anything-last-frame-or-window-configuration)
1849 (caadr anything-last-frame-or-window-configuration))))
1850 ;; If `anything-save-configuration-functions' are window functions
1851 ;; frame should be nil, use current frame.
1852 (unless (framep frame)
1853 (setq frame (selected-frame)))
1854 (select-frame-set-input-focus frame)))))
1857 ;; (@* "Core: Display *anything* buffer")
1858 (defun anything-display-buffer (buf)
1859 "Display *anything* buffer BUF."
1860 (let (pop-up-frames)
1861 (funcall (with-current-buffer buf anything-display-function) buf)))
1863 (defun anything-default-display-buffer (buf)
1864 "Default function to display BUF.
1865 Where BUF is generally `anything-buffer'.
1866 It use `switch-to-buffer' or `pop-to-buffer' depending of value of
1867 `anything-samewindow'."
1868 (funcall (if anything-samewindow 'switch-to-buffer 'pop-to-buffer) buf))
1871 ;; (@* "Core: initialize")
1872 (defun anything-initial-setup ()
1873 "Initialize anything settings and set up the anything buffer."
1874 (anything-log-run-hook 'anything-before-initialize-hook)
1875 (setq anything-current-prefix-arg nil)
1876 (setq anything-once-called-functions nil)
1877 (setq anything-delayed-init-executed nil)
1878 (setq anything-current-buffer
1879 (if (minibuffer-window-active-p (minibuffer-window))
1880 ;; If minibuffer is active be sure to use it's buffer
1881 ;; as `anything-current-buffer'.
1882 (window-buffer (active-minibuffer-window))
1883 (current-buffer)))
1884 (setq anything-buffer-file-name buffer-file-name)
1885 (setq anything-issued-errors nil)
1886 (setq anything-compiled-sources nil)
1887 (setq anything-saved-current-source nil)
1888 (if (or (not split-width-threshold)
1889 (and (integerp split-width-threshold)
1890 (>= split-width-threshold (+ (frame-width) 4))))
1891 (setq anything-split-window-state 'vertical)
1892 (setq anything-split-window-state 'horizontal))
1893 ;; Call the init function for sources where appropriate
1894 (anything-funcall-foreach 'init)
1895 (setq anything-pattern "")
1896 (setq anything-input "")
1897 (setq anything-candidate-cache nil)
1898 (setq anything-last-sources anything-sources)
1899 (anything-create-anything-buffer)
1900 (anything-log-run-hook 'anything-after-initialize-hook))
1902 (defvar anything-reading-pattern nil
1903 "Whether in `read-string' in anything or not.")
1904 (defun anything-read-pattern-maybe (any-prompt any-input
1905 any-preselect any-resume any-keymap any-default)
1906 "Read pattern with prompt ANY-PROMPT and initial input ANY-INPUT.
1907 For ANY-PRESELECT ANY-RESUME ANY-KEYMAP, See `anything'."
1908 (if (anything-resume-p any-resume)
1909 (anything-mark-current-line)
1910 (anything-update any-preselect))
1911 (with-current-buffer (anything-buffer-get)
1912 (and any-keymap (set (make-local-variable 'anything-map) any-keymap))
1913 (let ((minibuffer-local-map
1914 anything-map))
1915 (anything-log-eval (anything-approximate-candidate-number)
1916 anything-execute-action-at-once-if-one
1917 anything-quit-if-no-candidate)
1918 (cond ((and anything-execute-action-at-once-if-one
1919 (= (anything-approximate-candidate-number) 1))
1920 (ignore))
1921 ((and anything-quit-if-no-candidate
1922 (= (anything-approximate-candidate-number) 0))
1923 (setq anything-quit t)
1924 (and (functionp anything-quit-if-no-candidate)
1925 (funcall anything-quit-if-no-candidate)))
1927 (let ((anything-reading-pattern t)
1928 (tap (or any-default
1929 (with-anything-current-buffer
1930 (thing-at-point 'symbol)))))
1931 (read-string (or any-prompt "pattern: ") any-input nil tap)))))))
1933 (defun anything-create-anything-buffer (&optional test-mode)
1934 "Create newly created `anything-buffer'.
1935 If TEST-MODE is non-nil, clear `anything-candidate-cache'."
1936 (when test-mode
1937 (setq anything-candidate-cache nil))
1938 (with-current-buffer (get-buffer-create anything-buffer)
1939 (anything-log "kill local variables: %S" (buffer-local-variables))
1940 (kill-all-local-variables)
1941 (set (make-local-variable 'inhibit-read-only) t)
1942 (buffer-disable-undo)
1943 (erase-buffer)
1944 (set (make-local-variable 'inhibit-read-only) t)
1945 (set (make-local-variable 'anything-last-sources-local) anything-sources)
1946 (set (make-local-variable 'anything-follow-mode) nil)
1947 (set (make-local-variable 'anything-display-function) anything-display-function)
1948 (anything-initialize-persistent-action)
1949 (anything-log-eval anything-display-function anything-let-variables)
1950 (loop for (var . val) in anything-let-variables
1951 do (set (make-local-variable var) val))
1952 (setq cursor-type nil)
1953 (setq mode-name "Anything"))
1954 (anything-initialize-overlays anything-buffer)
1955 (get-buffer anything-buffer))
1957 (defun anything-initialize-overlays (buffer)
1958 "Initialize anything overlays in BUFFER."
1959 (anything-log "overlay setup")
1960 (if anything-selection-overlay
1961 ;; make sure the overlay belongs to the anything buffer if
1962 ;; it's newly created
1963 (move-overlay anything-selection-overlay (point-min) (point-min)
1964 (get-buffer buffer))
1966 (setq anything-selection-overlay
1967 (make-overlay (point-min) (point-min) (get-buffer buffer)))
1968 (overlay-put anything-selection-overlay 'face anything-selection-face))
1970 (cond (anything-enable-shortcuts
1971 (setq anything-shortcut-keys
1972 (assoc-default anything-enable-shortcuts anything-shortcut-keys-alist))
1973 (unless anything-digit-overlays
1974 (setq anything-digit-overlays
1975 (loop for key across anything-shortcut-keys
1976 for overlay = (make-overlay (point-min) (point-min)
1977 (get-buffer buffer))
1978 do (overlay-put overlay 'before-string
1979 (format "%s - " (upcase (make-string 1 key))))
1980 collect overlay))))
1981 (anything-digit-overlays
1982 (mapc 'delete-overlay anything-digit-overlays)
1983 (setq anything-digit-overlays nil))))
1985 (defun anything-hooks (setup-or-cleanup)
1986 "Add or remove hooks according to SETUP-OR-CLEANUP value.
1987 if SETUP-OR-CLEANUP value is setup add hooks, any other value
1988 will remove hooks.
1989 hooks concerned are `post-command-hook' and `minibuffer-setup-hook'."
1990 (let ((hooks '((post-command-hook anything-check-minibuffer-input)
1991 (minibuffer-setup-hook anything-print-error-messages))))
1992 (if (eq setup-or-cleanup 'setup)
1993 (dolist (args hooks) (apply 'add-hook args))
1994 (dolist (args (reverse hooks)) (apply 'remove-hook args)))))
1997 ;; (@* "Core: clean up")
1998 ;;; TODO move
1999 (defun anything-cleanup ()
2000 "Clean up the mess when anything exit or quit."
2001 (anything-log "start cleanup")
2002 (with-current-buffer anything-buffer
2003 (setq cursor-type t)
2004 ;; Call burry-buffer whithout arg
2005 ;; to remove anything-buffer from window.
2006 (bury-buffer)
2007 ;; Be sure we call this from anything-buffer.
2008 (anything-funcall-foreach 'cleanup))
2009 (anything-new-timer 'anything-check-minibuffer-input-timer nil)
2010 (anything-kill-async-processes)
2011 (anything-log-run-hook 'anything-cleanup-hook)
2012 (anything-hooks 'cleanup)
2013 (anything-frame-or-window-configuration 'restore)
2014 ;; This is needed in some cases where last input
2015 ;; is yielded infinitely in minibuffer after anything session.
2016 (anything-clean-up-minibuffer))
2018 (defun anything-clean-up-minibuffer ()
2019 "Remove contents of minibuffer."
2020 (let ((miniwin (minibuffer-window)))
2021 ;; Clean only current minibuffer used by anything.
2022 ;; i.e The precedent one is active.
2023 (unless (minibuffer-window-active-p miniwin)
2024 (with-current-buffer (window-buffer miniwin)
2025 (delete-minibuffer-contents)))))
2028 ;; (@* "Core: input handling")
2029 (defun anything-check-minibuffer-input ()
2030 "Extract input string from the minibuffer and check if it needs to be handled."
2031 (let ((delay (with-current-buffer anything-buffer anything-input-idle-delay)))
2032 (if (or (not delay) (anything-action-window))
2033 (anything-check-minibuffer-input-1)
2034 (anything-new-timer
2035 'anything-check-minibuffer-input-timer
2036 (run-with-idle-timer delay nil 'anything-check-minibuffer-input-1)))))
2038 (defun anything-check-minibuffer-input-1 ()
2039 "Check minibuffer content."
2040 (with-anything-quittable
2041 (with-selected-window (or (active-minibuffer-window) (minibuffer-window))
2042 (anything-check-new-input (minibuffer-contents)))))
2044 (defun anything-check-new-input (input)
2045 "Check INPUT string and update the anything buffer if necessary."
2046 (unless (equal input anything-pattern)
2047 (setq anything-pattern input)
2048 (unless (anything-action-window)
2049 (setq anything-input anything-pattern))
2050 (anything-log-eval anything-pattern anything-input)
2051 (anything-update)))
2054 ;; (@* "Core: source compiler")
2055 (defvar anything-compile-source-functions-default anything-compile-source-functions
2056 "Plug-ins this file provides.")
2057 (defun anything-compile-sources (sources funcs)
2058 "Compile SOURCES with FUNCS.
2059 See `anything-compile-source-functions'.
2060 Anything plug-ins are realized by this function."
2061 (mapcar
2062 (lambda (source)
2063 (loop with source = (if (listp source) source (symbol-value source))
2064 for f in funcs
2065 do (setq source (funcall f source))
2066 finally (return source)))
2067 sources))
2070 ;; (@* "Core: plug-in attribute documentation hack")
2072 ;; `anything-document-attribute' is public API.
2073 (defadvice documentation-property (after anything-document-attribute activate)
2074 "Display plug-in attributes' documentation as `anything-sources' docstring."
2075 (when (eq (ad-get-arg 0) 'anything-sources)
2076 (setq ad-return-value
2077 (concat ad-return-value "\n"
2078 (mapconcat (lambda (sym) (get sym 'anything-attrdoc))
2079 anything-additional-attributes
2080 "\n")))))
2081 ;; (describe-variable 'anything-sources)
2082 ;; (documentation-property 'anything-sources 'variable-documentation)
2083 ;; (progn (ad-disable-advice 'documentation-property 'after 'anything-document-attribute) (ad-update 'documentation-property))
2086 ;; (@* "Core: all candidates")
2087 (defun anything-process-delayed-init (source)
2088 "Initialize delayed SOURCE."
2089 (let ((name (assoc-default 'name source)))
2090 (unless (member name anything-delayed-init-executed)
2091 (anything-aif (assoc-default 'delayed-init source)
2092 (with-current-buffer anything-current-buffer
2093 (anything-funcall-with-source source it)
2094 (dolist (f (if (functionp it) (list it) it))
2095 (add-to-list 'anything-delayed-init-executed name)))))))
2097 (defun anything-get-candidates (source)
2098 "Retrieve and return the list of candidates from SOURCE."
2099 (anything-process-delayed-init source)
2100 (let* ((candidate-source (assoc-default 'candidates source))
2101 (type-error (lambda ()
2102 (error (concat "Candidates must either be a function, "
2103 " a variable or a list: %s")
2104 candidate-source)))
2105 (candidates (condition-case err
2106 (anything-interpret-value candidate-source source)
2107 (error (funcall type-error)))))
2108 (cond ((processp candidates) candidates)
2109 ((listp candidates) (anything-transform-candidates candidates source))
2110 (t (funcall type-error)))))
2113 (defun anything-get-cached-candidates (source)
2114 "Return the cached value of candidates for SOURCE.
2115 Cache the candidates if there is not yet a cached value."
2116 (let* ((name (assoc-default 'name source))
2117 (candidate-cache (assoc name anything-candidate-cache)))
2118 (cond (candidate-cache
2119 (anything-log "use cached candidates")
2120 (cdr candidate-cache))
2122 (anything-log "calculate candidates")
2123 (let ((candidates (anything-get-candidates source)))
2124 (cond ((processp candidates)
2125 (push (cons candidates
2126 (append source
2127 (list (cons 'item-count 0)
2128 (cons 'incomplete-line ""))))
2129 anything-async-processes)
2130 (set-process-filter candidates 'anything-output-filter)
2131 (setq candidates nil))
2132 ((not (assoc 'volatile source))
2133 (setq candidate-cache (cons name candidates))
2134 (push candidate-cache anything-candidate-cache)))
2135 candidates)))))
2138 ;;; (@* "Core: candidate transformers")
2139 (defun anything-process-candidate-transformer (candidates source)
2140 "Execute candidate-transformer function on all CANDIDATES of SOURCE."
2141 (anything-aif (assoc-default 'candidate-transformer source)
2142 (anything-composed-funcall-with-source source it candidates)
2143 candidates))
2145 (defun anything-process-filtered-candidate-transformer (candidates source)
2146 "Execute filtered-candidate-transformer function on all CANDIDATES of SOURCE."
2147 (anything-aif (assoc-default 'filtered-candidate-transformer source)
2148 (anything-composed-funcall-with-source source it candidates source)
2149 candidates))
2151 (defun anything-process-filtered-candidate-transformer-maybe (candidates source process-p)
2152 "Execute filtered-candidate-transformer function on all CANDIDATES of SOURCE.
2153 This happen if PROCESS-P is non-nil."
2154 (if process-p
2155 (anything-process-filtered-candidate-transformer candidates source)
2156 candidates))
2158 (defun anything-process-real-to-display (candidates source)
2159 "Execute real-to-display function on all CANDIDATES of SOURCE."
2160 (anything-aif (assoc-default 'real-to-display source)
2161 (setq candidates (anything-funcall-with-source
2162 source 'mapcar
2163 (lambda (cand_)
2164 (if (consp cand_)
2165 ;; override DISPLAY from candidate-transformer
2166 (cons (funcall it (cdr cand_)) (cdr cand_))
2167 (cons (funcall it cand_) cand_)))
2168 candidates))
2169 candidates))
2171 (defun anything-transform-candidates (candidates source &optional process-p)
2172 "Transform CANDIDATES of SOURCE according to candidate transformers.
2173 This happen if PROCESS-P is non-nil."
2174 (anything-process-real-to-display
2175 (anything-process-filtered-candidate-transformer-maybe
2176 (anything-process-candidate-transformer candidates source) source process-p)
2177 source))
2180 ;; (@* "Core: narrowing candidates")
2181 (defun anything-candidate-number-limit (source)
2182 "Apply candidate-number-limit attribute value.
2183 This overhide variable `anything-candidate-number-limit'.
2185 e.g:
2186 If \(candidate-number-limit\) is in SOURCE, show all candidates in SOURCE.
2187 If \(candidate-number-limit . 123\) is in SOURCE limit candidate to 123."
2188 (anything-aif (assq 'candidate-number-limit source)
2189 (or (cdr it) 99999999)
2190 (or anything-candidate-number-limit 99999999)))
2192 ;; FIXME: Why a defconst here
2193 (defconst anything-default-match-functions
2194 (list (lambda (candidate)
2195 (string-match anything-pattern candidate)))
2196 "Default functions to match candidates according to `anything-pattern'.")
2198 (defun anything-compute-matches (source)
2199 "Compute matched results from SOURCE according to its settings."
2200 (if debug-on-error
2201 (anything-compute-matches-internal source)
2202 (condition-case v
2203 (anything-compute-matches-internal source)
2204 (error (anything-log-error
2205 "anything-compute-matches: error when processing source: %s"
2206 (assoc-default 'name source))
2207 nil))))
2209 (defun anything-candidate-get-display (candidate)
2210 "Get searched display part from CANDIDATE.
2211 CANDIDATE is a string, a symbol, or \(DISPLAY . REAL\) cons cell."
2212 (format "%s" (or (car-safe candidate) candidate)))
2214 (defun anything-process-pattern-transformer (pattern source)
2215 "Execute pattern-transformer attribute PATTERN function in SOURCE."
2216 (anything-aif (assoc-default 'pattern-transformer source)
2217 (anything-composed-funcall-with-source source it pattern)
2218 pattern))
2220 (defun anything-match-functions (source)
2221 (or (assoc-default 'match source)
2222 anything-default-match-functions))
2224 (defmacro anything-accumulate-candidates-internal (cand newmatches
2225 hash item-count limit)
2226 "Internal, add CAND into NEWMATCHES.
2227 Use HASH to uniq NEWMATCHES.
2228 Argument ITEM-COUNT count the matches.
2229 if ITEM-COUNT reaches LIMIT, exit from inner loop."
2230 `(unless (gethash ,cand ,hash)
2231 (puthash ,cand t ,hash)
2232 (push ,cand ,newmatches)
2233 (incf ,item-count)
2234 (when (= ,item-count ,limit)
2235 (setq exit t)
2236 (return))))
2238 (defun anything-take-first-elements (seq n)
2239 (if (> (length seq) n)
2240 (setq seq (subseq seq 0 n))
2241 seq))
2243 (defun anything-match-from-candidates (cands matchfns limit)
2244 (let (matches)
2245 (condition-case nil
2246 (let ((item-count 0) exit)
2247 (clrhash anything-match-hash)
2248 (dolist (match matchfns)
2249 (let (newmatches)
2250 (dolist (candidate cands)
2251 (when (funcall match (anything-candidate-get-display candidate))
2252 (anything-accumulate-candidates-internal
2253 candidate newmatches anything-match-hash item-count limit)))
2254 (setq matches (append matches (reverse newmatches)))
2255 (if exit (return)))))
2256 (invalid-regexp (setq matches nil)))
2257 matches))
2259 (defun anything-compute-matches-internal (source)
2260 (save-current-buffer
2261 (let ((matchfns (anything-match-functions source))
2262 (anything-source-name (assoc-default 'name source))
2263 (limit (anything-candidate-number-limit source))
2264 (anything-pattern (anything-process-pattern-transformer
2265 anything-pattern source)))
2266 (anything-process-filtered-candidate-transformer
2267 (if (or (equal anything-pattern "") (equal matchfns '(identity)))
2268 (anything-take-first-elements
2269 (anything-get-cached-candidates source) limit)
2270 (anything-match-from-candidates
2271 (anything-get-cached-candidates source) matchfns limit))
2272 source))))
2274 ;; (anything '(((name . "error")(candidates . (lambda () (hage))) (action . identity))))
2276 (defun anything-process-source (source)
2277 "Display matched results from SOURCE according to its settings."
2278 (anything-log-eval (assoc-default 'name source))
2279 (if (assq 'direct-insert-match source) ;experimental
2280 (anything-process-source--direct-insert-match source)
2281 (let ((matches (anything-compute-matches source)))
2282 (when matches
2283 (when anything-test-mode
2284 (setq anything-test-candidate-list
2285 `(,@anything-test-candidate-list
2286 (,(assoc-default 'name source)
2287 ,matches))))
2288 (anything-insert-header-from-source source)
2289 (if (not (assq 'multiline source))
2290 (mapc 'anything-insert-match-with-digit-overlay matches)
2291 (let ((start (point)) separate)
2292 (dolist (match matches)
2293 (if separate
2294 (anything-insert-candidate-separator)
2295 (setq separate t))
2296 (anything-insert-match-with-digit-overlay match))
2297 (put-text-property start (point) 'anything-multiline t)))))))
2299 (defun anything-insert-match-with-digit-overlay (match)
2300 (declare (special source))
2301 (anything-put-digit-overlay-maybe)
2302 (anything-insert-match match 'insert source))
2304 (defun anything-put-digit-overlay-maybe ()
2305 (when (and anything-enable-shortcuts
2306 (not (eq anything-digit-shortcut-count
2307 (length anything-digit-overlays))))
2308 (move-overlay (nth anything-digit-shortcut-count
2309 anything-digit-overlays)
2310 (point-at-bol)
2311 (point-at-bol))
2312 (incf anything-digit-shortcut-count)))
2314 (defun anything-process-source--direct-insert-match (source)
2315 "[EXPERIMENTAL] Insert candidates from `anything-candidate-buffer' in SOURCE."
2316 (anything-log-eval (assoc-default 'name source))
2317 (let ((anything-source-name (assoc-default 'name source))
2318 content-buf)
2319 (funcall (assoc-default 'candidates source))
2320 (setq content-buf (anything-candidate-buffer))
2321 (unless (anything-empty-buffer-p content-buf)
2322 (anything-insert-header-from-source source)
2323 (insert-buffer-substring content-buf)
2324 ;; TODO call anything-put-digit-overlay-maybe with loop
2327 (defun anything-process-delayed-sources (delayed-sources &optional preselect)
2328 "Process anything DELAYED-SOURCES.
2329 Move selection to string or regexp PRESELECT if non--nil.
2330 This function is called in `anything-process-delayed-sources-timer'
2331 when emacs is idle for `anything-idle-delay'."
2332 (with-anything-quittable
2333 (anything-log-eval (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2334 (with-current-buffer anything-buffer
2335 (save-excursion
2336 (goto-char (point-max))
2337 (mapc 'anything-process-source delayed-sources)
2338 (when (and (not (anything-empty-buffer-p))
2339 ;; No selection yet.
2340 (= (overlay-start anything-selection-overlay)
2341 (overlay-end anything-selection-overlay)))
2342 (anything-update-move-first-line 'without-hook)))
2343 (when preselect (anything-preselect preselect))
2344 (save-excursion
2345 (goto-char (point-min))
2346 (anything-log-run-hook 'anything-update-hook))
2347 (anything-log-run-hook 'anything-after-update-hook))))
2350 ;; (@* "Core: *anything* buffer contents")
2351 (defvar anything-input-local nil)
2352 (defvar anything-process-delayed-sources-timer nil)
2353 (defun anything-update (&optional preselect)
2354 "Update candidates list in `anything-buffer' according to `anything-pattern'.
2355 Argument PRESELECT is a string or regexp used to move selection to a particular
2356 place once updating is done. It should be used on single source because search
2357 is done on whole `anything-buffer' and not on current source."
2358 (anything-log "start update")
2359 (setq anything-digit-shortcut-count 0)
2360 (anything-kill-async-processes)
2361 (with-current-buffer (anything-buffer-get)
2362 (set (make-local-variable 'anything-input-local) anything-pattern)
2363 (erase-buffer)
2364 (when anything-enable-shortcuts
2365 (mapc 'delete-overlay anything-digit-overlays))
2366 (let (delayed-sources
2367 normal-sources)
2368 (unwind-protect ; Process normal sources and store delayed one's.
2369 (setq delayed-sources
2370 (loop for source in (remove-if-not 'anything-update-source-p
2371 (anything-get-sources))
2372 if (anything-delayed-source-p source)
2373 collect source
2374 else do (progn (push source normal-sources)
2375 (anything-process-source source))))
2376 (anything-log-eval
2377 (mapcar (lambda (s) (assoc-default 'name s)) delayed-sources))
2378 (if anything-test-mode ; Need only to process sources.
2379 (mapc 'anything-process-source delayed-sources)
2380 (cond ((and preselect delayed-sources normal-sources)
2381 ;; Preselection run here when there is
2382 ;; normal AND delayed sources.
2383 (anything-log "Update preselect candidate %s" preselect)
2384 (anything-preselect preselect))
2385 (delayed-sources ; Preselection and hooks will run later.
2386 (anything-update-move-first-line 'without-hook))
2387 (t ; No delayed sources, run the hooks now.
2388 (anything-update-move-first-line)
2389 (anything-log-run-hook 'anything-after-update-hook)
2390 (when preselect
2391 (anything-log "Update preselect candidate %s" preselect)
2392 (anything-preselect preselect))))
2393 (when delayed-sources
2394 (anything-new-timer
2395 'anything-process-delayed-sources-timer
2396 (run-with-idle-timer
2397 ;; Be sure anything-idle-delay is >
2398 ;; to anything-input-idle-delay
2399 ;; otherwise use value of anything-input-idle-delay.
2400 (max anything-idle-delay anything-input-idle-delay) nil
2401 'anything-process-delayed-sources delayed-sources preselect))))
2402 (anything-log "end update")))))
2404 (defun anything-update-source-p (source)
2405 "Wheter SOURCE need updating or not."
2406 (and (or (not anything-source-filter)
2407 (member (assoc-default 'name source) anything-source-filter))
2408 (>= (length anything-pattern)
2409 (anything-aif (assoc 'requires-pattern source)
2410 (or (cdr it) 1)
2411 0))))
2413 (defun anything-delayed-source-p (source)
2414 "Wheter SOURCE is a delayed source or not."
2415 (or (assoc 'delayed source)
2416 (and anything-quick-update
2417 (< (window-height (get-buffer-window (current-buffer)))
2418 (line-number-at-pos (point-max))))))
2420 (defun anything-update-move-first-line (&optional without-hook)
2421 "Goto first line of `anything-buffer'."
2422 (goto-char (point-min))
2423 (unless without-hook
2424 (save-excursion (anything-log-run-hook 'anything-update-hook)))
2425 (anything-next-line))
2427 (defun anything-force-update (&optional preselect)
2428 "Force recalculation and update of candidates.
2429 If current source has `update' attribute, a function without argument,
2430 call it before update."
2431 (interactive)
2432 (let ((source (anything-get-current-source))
2433 (selection (anything-get-selection nil t)))
2434 (when source
2435 (mapc 'anything-force-update--reinit
2436 (anything-get-sources)))
2437 (anything-update preselect)
2438 ;; If preselect arg exists, `anything-update' should
2439 ;; have moved to selection, otherwise do it now.
2440 (unless preselect
2441 (anything-keep-selection (assoc-default 'name source) selection))
2442 (with-anything-window (recenter))))
2444 (defun anything-force-update--reinit (source)
2445 "Reinit SOURCE by calling his update and/or init functions."
2446 (anything-aif (anything-funcall-with-source
2447 source 'anything-candidate-buffer)
2448 (kill-buffer it))
2449 (dolist (attr '(update init))
2450 (anything-aif (assoc-default attr source)
2451 (anything-funcall-with-source source it)))
2452 (anything-remove-candidate-cache source))
2454 (defun anything-keep-selection (source selection)
2455 "Switch to SOURCE and goto SELECTION."
2456 (when (and source selection)
2457 (with-anything-window
2458 (anything-goto-source source)
2459 (forward-char -1)
2460 (if (search-forward selection nil t)
2461 (forward-line 0)
2462 (goto-char (point-min))
2463 (forward-line 1))
2464 (anything-mark-current-line))))
2466 (defun anything-remove-candidate-cache (source)
2467 "Remove SOURCE from `anything-candidate-cache'."
2468 (setq anything-candidate-cache
2469 (delete (assoc (assoc-default 'name source)
2470 anything-candidate-cache)
2471 anything-candidate-cache)))
2473 (defun anything-insert-match (match insert-function source)
2474 "Insert MATCH into `anything-buffer' with INSERT-FUNCTION for SOURCE.
2475 If MATCH is a list then insert the string intended to appear on the display
2476 and store the real value in a text property."
2477 (let ((start (point-at-bol (point)))
2478 (string (or (car-safe match) match))
2479 (realvalue (cdr-safe match)))
2480 (when (symbolp string) (setq string (symbol-name string)))
2481 (when (stringp string)
2482 (funcall insert-function string)
2483 ;; Some sources with candidates-in-buffer have already added
2484 ;; 'anything-realvalue property when creating candidate buffer.
2485 (unless (get-text-property start 'anything-realvalue)
2486 (and realvalue
2487 (put-text-property start (point-at-eol)
2488 'anything-realvalue realvalue)))
2489 (when anything-source-in-each-line-flag
2490 (put-text-property start (point-at-eol) 'anything-source source))
2491 (funcall insert-function "\n"))))
2493 (defun anything-insert-header-from-source (source)
2494 "Insert SOURCE name in `anything-buffer' header.
2495 Maybe insert by overlay additional info after source name if SOURCE have
2496 header-name attribute."
2497 (let ((name (assoc-default 'name source)))
2498 (anything-insert-header
2499 name
2500 (anything-aif (assoc-default 'header-name source)
2501 (anything-funcall-with-source source it name)))))
2503 (defun anything-insert-header (name &optional display-string)
2504 "Insert header of source NAME into the anything buffer.
2505 If DISPLAY-STRING is non--nil and a string, display this additional info
2506 after the source name by overlay."
2507 (unless (bobp)
2508 (let ((start (point)))
2509 (insert "\n")
2510 (put-text-property start (point) 'anything-header-separator t)))
2511 (let ((start (point)))
2512 (insert name)
2513 (put-text-property (point-at-bol)
2514 (point-at-eol) 'anything-header t)
2515 (when display-string
2516 (overlay-put (make-overlay (point-at-bol) (point-at-eol))
2517 'display display-string))
2518 (insert "\n")
2519 (put-text-property start (point) 'face anything-header-face)))
2521 (defun anything-insert-candidate-separator ()
2522 "Insert separator of candidates into the anything buffer."
2523 (insert anything-candidate-separator)
2524 (put-text-property (point-at-bol)
2525 (point-at-eol) 'anything-candidate-separator t)
2526 (insert "\n"))
2529 ;; (@* "Core: async process")
2530 (defun anything-output-filter (process string)
2531 "From PROCESS process output STRING."
2532 (anything-output-filter-1 (assoc process anything-async-processes) string))
2534 (defun anything-output-filter-1 (process-assoc string)
2535 (anything-log-eval string)
2536 (with-current-buffer anything-buffer
2537 (let ((source (cdr process-assoc)))
2538 (save-excursion
2539 (anything-aif (assoc-default 'insertion-marker source)
2540 (goto-char it)
2541 (goto-char (point-max))
2542 (anything-insert-header-from-source source)
2543 (setcdr process-assoc
2544 (append source `((insertion-marker . ,(point-marker))))))
2545 (anything-output-filter--process-source
2546 (car process-assoc) string source
2547 (anything-candidate-number-limit source))))
2548 (anything-output-filter--post-process)))
2550 (defun anything-output-filter--process-source (process string source limit)
2551 (dolist (candidate (anything-transform-candidates
2552 (anything-output-filter--collect-candidates
2553 (split-string string "\n")
2554 (assoc 'incomplete-line source))
2555 source t))
2556 (if (not (assq 'multiline source))
2557 (anything-insert-match candidate 'insert-before-markers source)
2558 (let ((start (point)))
2559 (anything-insert-candidate-separator)
2560 (anything-insert-match candidate 'insert-before-markers source)
2561 (put-text-property start (point) 'anything-multiline t)))
2562 (incf (cdr (assoc 'item-count source)))
2563 (when (>= (assoc-default 'item-count source) limit)
2564 (anything-kill-async-process process)
2565 (return))))
2567 (defun anything-output-filter--collect-candidates (lines incomplete-line-info)
2568 (anything-log-eval (cdr incomplete-line-info))
2569 (butlast
2570 (loop for line in lines collect
2571 (if (cdr incomplete-line-info)
2572 (prog1
2573 (concat (cdr incomplete-line-info) line)
2574 (setcdr incomplete-line-info nil))
2575 line)
2576 finally (setcdr incomplete-line-info line))))
2578 (defun anything-output-filter--post-process ()
2579 (anything-log-run-hook 'anything-update-hook)
2580 (anything-aif (get-buffer-window anything-buffer 'visible)
2581 (save-selected-window
2582 (select-window it)
2583 (anything-skip-noncandidate-line 'next)
2584 (anything-mark-current-line))))
2586 (defun anything-kill-async-processes ()
2587 "Kill all known asynchronous processes of `anything-async-processes'."
2588 (mapc 'anything-kill-async-process (mapcar 'car anything-async-processes))
2589 (setq anything-async-processes nil))
2591 (defun anything-kill-async-process (process)
2592 "Kill PROCESS and detach the associated functions."
2593 (set-process-filter process nil)
2594 (delete-process process))
2597 ;; (@* "Core: action")
2598 (defun anything-execute-selection-action (&optional
2599 selection action
2600 preserve-saved-action)
2601 "If a candidate SELECTION is present then perform the associated ACTION on it.
2602 If PRESERVE-SAVED-ACTION is non-nil don't save action."
2603 (anything-log "executing action")
2604 (setq action (anything-get-default-action
2605 (or action
2606 anything-saved-action
2607 (if (get-buffer anything-action-buffer)
2608 (anything-get-selection anything-action-buffer)
2609 (anything-get-action)))))
2610 (let ((source (or anything-saved-current-source
2611 (anything-get-current-source))))
2612 (setq selection (or selection
2613 (anything-get-selection)
2614 (and (assoc 'accept-empty source) "")))
2615 (unless preserve-saved-action (setq anything-saved-action nil))
2616 (if (and selection action)
2617 (anything-funcall-with-source
2618 source action
2619 (anything-coerce-selection selection source)))))
2621 (defun anything-coerce-selection (selection source)
2622 "Apply coerce attribute function to SELECTION in SOURCE.
2623 Coerce source with coerce function."
2624 (anything-aif (assoc-default 'coerce source)
2625 (anything-funcall-with-source source it selection)
2626 selection))
2628 (defun anything-get-default-action (action)
2629 (if (and (listp action) (not (functionp action)))
2630 (cdar action)
2631 action))
2633 (defun anything-select-action ()
2634 "Select an action for the currently selected candidate.
2635 If action buffer is selected, back to the anything buffer."
2636 (interactive)
2637 (cond ((get-buffer-window anything-action-buffer 'visible)
2638 (set-window-buffer (get-buffer-window anything-action-buffer)
2639 anything-buffer)
2640 (kill-buffer anything-action-buffer)
2641 (anything-set-pattern anything-input 'noupdate))
2643 (setq anything-saved-selection (anything-get-selection))
2644 (unless anything-saved-selection
2645 (error "Nothing is selected"))
2646 (setq anything-saved-current-source (anything-get-current-source))
2647 (let ((actions (anything-get-action)))
2648 (if (functionp actions)
2649 (message "Sole action: %s" actions)
2650 (anything-show-action-buffer actions)
2651 (anything-delete-minibuffer-contents)
2652 (setq anything-pattern 'dummy) ; so that it differs from the previous one
2653 (anything-check-minibuffer-input))))))
2655 (defun anything-show-action-buffer (actions)
2656 (with-current-buffer (get-buffer-create anything-action-buffer)
2657 (erase-buffer)
2658 (buffer-disable-undo)
2659 (set-window-buffer (get-buffer-window anything-buffer) anything-action-buffer)
2660 (set (make-local-variable 'anything-sources)
2661 `(((name . "Actions")
2662 (volatile)
2663 (candidates . ,actions)
2664 (candidate-number-limit))))
2665 (set (make-local-variable 'anything-source-filter) nil)
2666 (set (make-local-variable 'anything-selection-overlay) nil)
2667 (set (make-local-variable 'anything-digit-overlays) nil)
2668 (anything-initialize-overlays anything-action-buffer)))
2671 ;; (@* "Core: selection")
2672 (defun anything-move-selection-common (move-func unit direction)
2673 "Move the selection marker to a new position wit function MOVE-FUNC.
2674 It is determined by UNIT and DIRECTION."
2675 (unless (or (anything-empty-buffer-p (anything-buffer-get))
2676 (not (anything-window)))
2677 (with-anything-window
2678 (anything-log-run-hook 'anything-move-selection-before-hook)
2679 (funcall move-func)
2680 (anything-skip-noncandidate-line direction)
2681 (anything-display-source-at-screen-top-maybe unit)
2682 (when (anything-get-previous-header-pos)
2683 (anything-mark-current-line))
2684 (anything-display-mode-line (anything-get-current-source))
2685 (anything-log-run-hook 'anything-move-selection-after-hook))))
2687 (defun anything-display-source-at-screen-top-maybe (unit)
2688 (when (and anything-display-source-at-screen-top (eq unit 'source))
2689 (set-window-start (selected-window)
2690 (save-excursion (forward-line -1) (point)))))
2692 (defun anything-skip-noncandidate-line (direction)
2693 (anything-skip-header-and-separator-line direction)
2694 (and (bobp) (forward-line 1)) ;skip first header
2695 (and (eobp) (forward-line -1))) ;avoid last empty line
2698 (defun anything-skip-header-and-separator-line (direction)
2699 (while (and (not (bobp))
2700 (or (anything-pos-header-line-p)
2701 (anything-pos-candidate-separator-p)))
2702 (forward-line (if (and (eq direction 'previous)
2703 (not (eq (point-at-bol) (point-min))))
2704 -1 1))))
2706 (defvar anything-mode-line-string-real nil)
2707 (defun anything-display-mode-line (source)
2708 (set (make-local-variable 'anything-mode-line-string)
2709 (anything-interpret-value (or (assoc-default 'mode-line source)
2710 (default-value 'anything-mode-line-string))
2711 source))
2712 (if anything-mode-line-string
2713 (setq mode-line-format
2714 '(" " mode-line-buffer-identification " "
2715 (line-number-mode "L%l") " " (anything-follow-mode "(F) ")
2716 (:eval (anything-show-candidate-number
2717 (when (listp anything-mode-line-string)
2718 (car anything-mode-line-string))))
2719 " " anything-mode-line-string-real "-%-")
2720 anything-mode-line-string-real
2721 (substitute-command-keys (if (listp anything-mode-line-string)
2722 (cadr anything-mode-line-string)
2723 anything-mode-line-string)))
2724 (setq mode-line-format
2725 (default-value 'mode-line-format)))
2726 (setq header-line-format
2727 (anything-interpret-value (assoc-default 'header-line source) source)))
2729 (defun anything-show-candidate-number (&optional name)
2730 "Used to display candidate number in mode-line.
2731 You can specify NAME of candidates e.g \"Buffers\" otherwise
2732 it is \"Candidate\(s\)\" by default."
2733 (propertize
2734 (format "[%s %s]"
2735 (anything-approximate-candidate-number 'in-current-source)
2736 (or name "Candidate(s)"))
2737 'face 'anything-candidate-number))
2739 (defun anything-previous-line ()
2740 "Move selection to the previous line."
2741 (interactive)
2742 (anything-move-selection-common
2743 (lambda ()
2744 (if (not (anything-pos-multiline-p))
2745 (forward-line -1) ;double forward-line is meaningful
2746 (forward-line -1) ;because evaluation order is important
2747 (anything-skip-header-and-separator-line 'previous)
2748 (let ((header-pos (anything-get-previous-header-pos))
2749 (separator-pos (anything-get-previous-candidate-separator-pos)))
2750 (when header-pos
2751 (goto-char (if (or (null separator-pos) (< separator-pos header-pos))
2752 header-pos ; first candidate
2753 separator-pos))
2754 (forward-line 1)))))
2755 'line 'previous))
2757 (defun anything-next-line ()
2758 "Move selection to the next line."
2759 (interactive)
2760 (anything-move-selection-common
2761 (lambda ()
2762 (if (not (anything-pos-multiline-p))
2763 (forward-line 1)
2764 (let ((header-pos (anything-get-next-header-pos))
2765 (separator-pos (anything-get-next-candidate-separator-pos)))
2766 (cond ((and separator-pos
2767 (or (null header-pos) (< separator-pos header-pos)))
2768 (goto-char separator-pos))
2769 (header-pos
2770 (goto-char header-pos))))))
2771 'line 'next))
2773 (defun anything-previous-page ()
2774 "Move selection back with a pageful."
2775 (interactive)
2776 (anything-move-selection-common
2777 (lambda ()
2778 (condition-case nil
2779 (scroll-down)
2780 (beginning-of-buffer (goto-char (point-min)))))
2781 'page 'previous))
2783 (defun anything-next-page ()
2784 "Move selection forward with a pageful."
2785 (interactive)
2786 (anything-move-selection-common
2787 (lambda ()
2788 (condition-case nil
2789 (scroll-up)
2790 (end-of-buffer (goto-char (point-max)))))
2791 'page 'next))
2793 (defun anything-beginning-of-buffer ()
2794 "Move selection at the top."
2795 (interactive)
2796 (anything-move-selection-common
2797 (lambda () (goto-char (point-min)))
2798 'edge 'previous))
2800 (defun anything-end-of-buffer ()
2801 "Move selection at the bottom."
2802 (interactive)
2803 (anything-move-selection-common
2804 (lambda () (goto-char (point-max)))
2805 'edge 'next))
2807 (defun anything-previous-source ()
2808 "Move selection to the previous source."
2809 (interactive)
2810 (anything-move-selection-common
2811 (lambda ()
2812 (forward-line -1)
2813 (if (bobp)
2814 (goto-char (point-max))
2815 (anything-skip-header-and-separator-line 'previous))
2816 (goto-char (anything-get-previous-header-pos))
2817 (forward-line 1))
2818 'source 'previous))
2820 (defun anything-next-source ()
2821 "Move selection to the next source."
2822 (interactive)
2823 (anything-move-selection-common
2824 (lambda ()
2825 (goto-char (or (anything-get-next-header-pos) (point-min))))
2826 'source 'next))
2828 (defun anything-goto-source (source-or-name)
2829 "Move the selection to the source SOURCE-OR-NAME."
2830 (anything-move-selection-common
2831 (lambda ()
2832 (goto-char (point-min))
2833 (let ((name (if (stringp source-or-name) source-or-name
2834 (assoc-default 'name source-or-name))))
2835 (condition-case err
2836 (while (not (string= name (anything-current-line-contents)))
2837 (goto-char (anything-get-next-header-pos)))
2838 (error (message "")))))
2839 'source 'next))
2841 (defun anything-mark-current-line ()
2842 "Move `anything-selection-overlay' to current line.
2843 Note that this is not related with visibles marks, which are used
2844 to mark candidates."
2845 (move-overlay
2846 anything-selection-overlay (point-at-bol)
2847 (if (anything-pos-multiline-p)
2848 (let ((header-pos (anything-get-next-header-pos))
2849 (separator-pos (anything-get-next-candidate-separator-pos)))
2850 (or (and (null header-pos) separator-pos)
2851 (and header-pos separator-pos (< separator-pos header-pos)
2852 separator-pos)
2853 header-pos
2854 (point-max)))
2855 (1+ (point-at-eol))))
2856 (anything-follow-execute-persistent-action-maybe))
2858 (defun anything-this-command-key ()
2859 (event-basic-type (elt (this-command-keys-vector) 0)))
2860 ;; (progn (read-key-sequence "Key: ") (p (anything-this-command-key)))
2862 (defun anything-select-with-shortcut-internal (types get-key-func)
2863 (if (memq anything-enable-shortcuts types)
2864 (save-selected-window
2865 (select-window (anything-window))
2866 (let* ((key (funcall get-key-func))
2867 (overlay (ignore-errors (nth (position key anything-shortcut-keys)
2868 anything-digit-overlays))))
2869 (if (not (and overlay (overlay-buffer overlay)))
2870 (when (numberp key)
2871 (select-window (minibuffer-window))
2872 (self-insert-command 1))
2873 (goto-char (overlay-start overlay))
2874 (anything-mark-current-line)
2875 (anything-exit-minibuffer))))
2876 (self-insert-command 1)))
2878 (defun anything-select-with-prefix-shortcut ()
2879 "Invoke default action with prefix shortcut."
2880 (interactive)
2881 (anything-select-with-shortcut-internal
2882 '(prefix)
2883 (lambda () (read-event "Select shortcut key: "))))
2885 (defun anything-select-with-digit-shortcut ()
2886 "Invoke default action with digit/alphabet shortcut."
2887 (interactive)
2888 (anything-select-with-shortcut-internal
2889 '(alphabet t) 'anything-this-command-key))
2891 ;; (setq anything-enable-shortcuts 'prefix)
2892 ;; (define-key anything-map "@" 'anything-select-with-prefix-shortcut)
2893 ;; (define-key anything-map (kbd "<f18>") 'anything-select-with-prefix-shortcut)
2895 (defvar anything-exit-status 0
2896 "Flag to inform whether anything have aborted or quitted.
2897 Exit with 0 mean anything exit executing an action.
2898 Exit with 1 mean anything abort with \\[keyboard-quit]
2899 It is useful for example to restore a window config if anything abort
2900 in special cases.
2901 See `anything-exit-minibuffer' and `anything-keyboard-quit'.")
2903 (defun anything-exit-minibuffer ()
2904 "Select the current candidate by exiting the minibuffer."
2905 (interactive)
2906 (unless anything-current-prefix-arg
2907 (setq anything-current-prefix-arg current-prefix-arg))
2908 (setq anything-exit-status 0)
2909 (exit-minibuffer))
2911 (defun anything-keyboard-quit ()
2912 "Quit minibuffer in anything.
2913 If action buffer is displayed, kill it."
2914 (interactive)
2915 (when (get-buffer-window anything-action-buffer 'visible)
2916 (kill-buffer anything-action-buffer))
2917 (setq anything-exit-status 1)
2918 (abort-recursive-edit))
2920 (defun anything-get-next-header-pos ()
2921 "Return the position of the next header from point."
2922 (next-single-property-change (point) 'anything-header))
2924 (defun anything-get-previous-header-pos ()
2925 "Return the position of the previous header from point."
2926 (previous-single-property-change (point) 'anything-header))
2928 (defun anything-pos-multiline-p ()
2929 "Return non-nil if the current position is in the multiline source region."
2930 (get-text-property (point) 'anything-multiline))
2932 (defun anything-get-next-candidate-separator-pos ()
2933 "Return the position of the next candidate separator from point."
2934 (next-single-property-change (point) 'anything-candidate-separator))
2936 (defun anything-get-previous-candidate-separator-pos ()
2937 "Return the position of the previous candidate separator from point."
2938 (previous-single-property-change (point) 'anything-candidate-separator))
2940 (defun anything-pos-header-line-p ()
2941 "Return t if the current line is a header line."
2942 (or (get-text-property (point-at-bol) 'anything-header)
2943 (get-text-property (point-at-bol) 'anything-header-separator)))
2945 (defun anything-pos-candidate-separator-p ()
2946 "Return t if the current line is a candidate separator."
2947 (get-text-property (point-at-bol) 'anything-candidate-separator))
2950 ;; (@* "Core: help")
2951 (defun anything-help-internal (bufname insert-content-fn)
2952 "Show long message during `anything' session in BUFNAME.
2953 INSERT-CONTENT-FN is the text to be displayed in BUFNAME."
2954 (save-window-excursion
2955 (select-window (anything-window))
2956 (delete-other-windows)
2957 (switch-to-buffer (get-buffer-create bufname))
2958 (erase-buffer)
2959 (funcall insert-content-fn)
2960 (setq mode-line-format "%b (SPC,C-v:NextPage b,M-v:PrevPage other:Exit)")
2961 (setq cursor-type nil)
2962 (goto-char 1)
2963 (anything-help-event-loop)))
2965 (defun anything-help-event-loop ()
2966 (ignore-errors
2967 (loop for event = (read-event) do
2968 (case event
2969 ((?\C-v ? ) (scroll-up))
2970 ((?\M-v ?b) (scroll-down))
2971 (t (return))))))
2973 (defun anything-help ()
2974 "Help of `anything'."
2975 (interactive)
2976 (anything-help-internal
2977 " *Anything Help*"
2978 (lambda ()
2979 (insert (substitute-command-keys
2980 (anything-interpret-value anything-help-message)))
2981 (org-mode))))
2983 (defun anything-debug-output ()
2984 "Show all anything-related variables at this time."
2985 (interactive)
2986 (anything-help-internal " *Anything Debug*" 'anything-debug-output-function))
2988 (defun anything-debug-output-function (&optional vars)
2989 (message "Calculating all anything-related values...")
2990 (insert "If you debug some variables or forms, set `anything-debug-forms'
2991 to a list of forms.\n\n")
2992 (dolist (v (or vars
2993 anything-debug-forms
2994 (apropos-internal "^anything-" 'boundp)))
2995 (insert "** "
2996 (pp-to-string v) "\n"
2997 (pp-to-string (eval v)) "\n"))
2998 (message "Calculating all anything-related values...Done"))
3001 ;; (@* "Core: misc")
3002 (defun anything-kill-buffer-hook ()
3003 "Remove tick entry from `anything-tick-hash' when killing a buffer."
3004 (loop for key being the hash-keys in anything-tick-hash
3005 if (string-match (format "^%s/" (regexp-quote (buffer-name))) key)
3006 do (remhash key anything-tick-hash)))
3007 (add-hook 'kill-buffer-hook 'anything-kill-buffer-hook)
3009 (defun anything-preselect (candidate-or-regexp)
3010 "Move `anything-selection-overlay' to CANDIDATE-OR-REGEXP on startup."
3011 (with-anything-window
3012 (when candidate-or-regexp
3013 (goto-char (point-min))
3014 ;; go to first candidate of first source
3015 (forward-line 1)
3016 (let ((start (point)))
3017 (or (re-search-forward
3018 (concat "^" (regexp-quote candidate-or-regexp) "$") nil t)
3019 (re-search-forward candidate-or-regexp nil t)
3020 (search-forward candidate-or-regexp nil t)
3021 (goto-char start))))
3022 (anything-mark-current-line)))
3024 (defun anything-delete-current-selection ()
3025 "Delete the currently selected item."
3026 (interactive)
3027 (with-anything-window
3028 (cond ((anything-pos-multiline-p)
3029 (anything-aif (anything-get-next-candidate-separator-pos)
3030 (delete-region (point-at-bol)
3031 (1+ (progn (goto-char it) (point-at-eol))))
3032 ;; last candidate
3033 (goto-char (anything-get-previous-candidate-separator-pos))
3034 (delete-region (point-at-bol) (point-max)))
3035 (when (anything-end-of-source-p)
3036 (goto-char (or (anything-get-previous-candidate-separator-pos)
3037 (point-min)))
3038 (forward-line 1)))
3040 (delete-region (point-at-bol) (1+ (point-at-eol)))
3041 (when (anything-end-of-source-p) (forward-line -1))))
3042 (anything-mark-current-line)))
3044 (defun anything-end-of-source-p ()
3045 "Return non--nil if we are at eob or end of source."
3046 (save-excursion
3047 (forward-line 1)
3048 (or (eq (point-at-bol) (point-at-eol))
3049 (anything-pos-header-line-p)
3050 (eobp))))
3052 (defun anything-edit-current-selection-internal (func)
3053 (with-anything-window
3054 (beginning-of-line)
3055 (let ((realvalue (get-text-property (point) 'anything-realvalue)))
3056 (funcall func)
3057 (beginning-of-line)
3058 (and realvalue
3059 (put-text-property (point) (point-at-eol)
3060 'anything-realvalue realvalue))
3061 (anything-mark-current-line))))
3063 (defmacro anything-edit-current-selection (&rest forms)
3064 "Evaluate FORMS at current selection in the anything buffer.
3065 You can edit the line."
3066 (declare (indent 0) (debug t))
3067 `(anything-edit-current-selection-internal
3068 (lambda () ,@forms)))
3070 (defun anything-set-pattern (pattern &optional noupdate)
3071 "Set minibuffer contents to PATTERN.
3072 if optional NOUPDATE is non-nil, anything buffer is not changed."
3073 (with-selected-window (or (active-minibuffer-window) (minibuffer-window))
3074 (delete-minibuffer-contents)
3075 (insert pattern))
3076 (when noupdate
3077 (setq anything-pattern pattern)
3078 (anything-hooks 'cleanup)
3079 (run-with-idle-timer 0 nil 'anything-hooks 'setup)))
3081 (defun anything-delete-minibuffer-contents ()
3082 "Same as `delete-minibuffer-contents' but this is a command."
3083 (interactive)
3084 (anything-set-pattern ""))
3085 (defalias 'anything-delete-minibuffer-content 'anything-delete-minibuffer-contents)
3088 ;;; Plugins
3090 ;; (@* "Built-in plug-in: type")
3091 (defun anything-compile-source--type (source)
3092 (anything-aif (assoc-default 'type source)
3093 (append source (assoc-default it anything-type-attributes) nil)
3094 source))
3096 ;; `define-anything-type-attribute' is public API.
3098 (defun anything-add-type-attribute (type definition)
3099 (anything-aif (assq type anything-type-attributes)
3100 (setq anything-type-attributes (delete it anything-type-attributes)))
3101 (push (cons type definition) anything-type-attributes))
3103 (defvar anything-types nil)
3104 (defun anything-document-type-attribute (type doc)
3105 (add-to-list 'anything-types type t)
3106 (put type 'anything-typeattrdoc
3107 (concat "- " (symbol-name type) "\n\n" doc "\n")))
3109 (defadvice documentation-property (after anything-document-type-attribute activate)
3110 "Display type attributes' documentation as `anything-type-attributes' docstring."
3111 (when (eq (ad-get-arg 0) 'anything-type-attributes)
3112 (setq ad-return-value
3113 (concat ad-return-value "\n\n++++ Types currently defined ++++\n"
3114 (mapconcat (lambda (sym) (get sym 'anything-typeattrdoc))
3115 anything-types "\n")))))
3117 ;; (@* "Built-in plug-in: dummy")
3118 (defun anything-dummy-candidate (candidate source)
3119 "Use `anything-pattern' as CANDIDATE in SOURCE."
3120 ;; `source' is defined in filtered-candidate-transformer
3121 (list anything-pattern))
3123 (defun anything-compile-source--dummy (source)
3124 (if (assoc 'dummy source)
3125 (append source
3126 '((candidates "dummy")
3127 (accept-empty)
3128 (match identity)
3129 (filtered-candidate-transformer . anything-dummy-candidate)
3130 (disable-shortcuts)
3131 (volatile)))
3132 source))
3134 ;; (@* "Built-in plug-in: disable-shortcuts")
3135 (defvar anything-orig-enable-shortcuts nil)
3136 (defun anything-save-enable-shortcuts ()
3137 (anything-once
3138 (lambda ()
3139 (setq anything-orig-enable-shortcuts anything-enable-shortcuts
3140 anything-enable-shortcuts nil))))
3142 (defun anything-compile-source--disable-shortcuts (source)
3143 (if (assoc 'disable-shortcuts source)
3144 (append `((init ,@(anything-mklist (assoc-default 'init source))
3145 anything-save-enable-shortcuts)
3146 (resume ,@(anything-mklist (assoc-default 'resume source))
3147 anything-save-enable-shortcuts)
3148 (cleanup ,@(anything-mklist (assoc-default 'cleanup source))
3149 (lambda () (setq anything-enable-shortcuts
3150 anything-orig-enable-shortcuts))))
3151 source)
3152 source))
3154 ;; (@* "Built-in plug-in: candidates-in-buffer")
3155 (defun anything-candidates-in-buffer ()
3156 "Get candidates from the candidates buffer according to `anything-pattern'.
3158 BUFFER is `anything-candidate-buffer' by default. Each
3159 candidate must be placed in one line. This function is meant to
3160 be used in candidates-in-buffer or candidates attribute of an
3161 anything source. Especially fast for many (1000+) candidates.
3164 '((name . \"many files\")
3165 (init . (lambda () (with-current-buffer (anything-candidate-buffer 'local)
3166 (insert-many-filenames))))
3167 (search re-search-forward) ; optional
3168 (candidates-in-buffer)
3169 (type . file))
3171 +===============================================================+
3172 | The new way of making and narrowing candidates: Using buffers |
3173 +===============================================================+
3175 By default, `anything' makes candidates by evaluating the
3176 candidates function, then narrows them by `string-match' for each
3177 candidate.
3179 But this way is very slow for many candidates. The new way is
3180 storing all candidates in a buffer and narrowing them by
3181 `re-search-forward'. Search function is customizable by search
3182 attribute. The important point is that buffer processing is MUCH
3183 FASTER than string list processing and is the Emacs way.
3185 The init function writes all candidates to a newly-created
3186 candidate buffer. The candidates buffer is created or specified
3187 by `anything-candidate-buffer'. Candidates are stored in a line.
3189 The candidates function narrows all candidates, IOW creates a
3190 subset of candidates dynamically. It is the task of
3191 `anything-candidates-in-buffer'. As long as
3192 `anything-candidate-buffer' is used,`(candidates-in-buffer)' is
3193 sufficient in most cases.
3195 Note that `(candidates-in-buffer)' is shortcut of three attributes:
3196 (candidates . anything-candidates-in-buffer)
3197 (volatile)
3198 (match identity)
3199 And `(candidates-in-buffer . func)' is shortcut of three attributes:
3200 (candidates . func)
3201 (volatile)
3202 (match identity)
3203 The expansion is performed in `anything-get-sources'.
3205 The candidates-in-buffer attribute implies the volatile attribute.
3206 The volatile attribute is needed because `anything-candidates-in-buffer'
3207 creates candidates dynamically and need to be called everytime
3208 `anything-pattern' changes.
3210 Because `anything-candidates-in-buffer' plays the role of `match' attribute
3211 function, specifying `(match identity)' makes the source slightly faster.
3213 To customize `anything-candidates-in-buffer' behavior, use search,
3214 get-line and search-from-end attributes. See also `anything-sources' docstring."
3215 (declare (special source))
3216 (anything-candidates-in-buffer-1 (anything-candidate-buffer)
3217 anything-pattern
3218 (or (assoc-default 'get-line source)
3219 #'buffer-substring-no-properties)
3220 ;; use external variable `source'.
3221 (or (assoc-default 'search source)
3222 (if (assoc 'search-from-end source)
3223 '(re-search-backward)
3224 '(re-search-forward)))
3225 (anything-candidate-number-limit source)
3226 (assoc 'search-from-end source)))
3228 (defun anything-candidates-in-buffer-1 (buffer pattern get-line-fn search-fns limit search-from-end)
3229 ;; buffer == nil when candidates buffer does not exist.
3230 (when buffer
3231 (with-current-buffer buffer
3232 (let ((start-point (if search-from-end (point-max) (point-min)))
3233 (endp (if search-from-end #'bobp #'eobp)))
3234 (goto-char (1- start-point))
3235 (if (string= pattern "")
3236 (anything-initial-candidates-from-candidate-buffer
3237 endp get-line-fn limit search-from-end)
3238 (anything-search-from-candidate-buffer
3239 pattern get-line-fn search-fns limit search-from-end
3240 start-point endp))))))
3242 (defun anything-point-is-moved (proc)
3243 "If point is moved after executing PROC, return t, otherwise nil."
3244 (/= (point) (progn (funcall proc) (point))))
3246 (defun anything-search-from-candidate-buffer (pattern get-line-fn search-fns
3247 limit search-from-end
3248 start-point endp)
3249 (let (buffer-read-only
3250 matches exit newmatches)
3251 (anything-search-from-candidate-buffer-internal
3252 (lambda ()
3253 (clrhash anything-cib-hash)
3254 (dolist (searcher search-fns)
3255 (goto-char start-point)
3256 (setq newmatches nil)
3257 (loop with item-count = 0
3258 while (funcall searcher pattern nil t)
3259 for cand = (funcall get-line-fn (point-at-bol) (point-at-eol))
3260 do (anything-accumulate-candidates-internal
3261 cand newmatches anything-cib-hash item-count limit)
3262 unless (anything-point-is-moved
3263 (lambda ()
3264 (if search-from-end
3265 (goto-char (1- (point-at-bol)))
3266 (forward-line 1))))
3267 return nil)
3268 (setq matches (append matches (nreverse newmatches)))
3269 (if exit (return)))
3270 (delq nil matches)))))
3272 (defun anything-initial-candidates-from-candidate-buffer (endp get-line-fn limit search-from-end)
3273 (delq nil (loop with next-line-fn =
3274 (if search-from-end
3275 (lambda (x) (goto-char (max (1- (point-at-bol)) 1)))
3276 #'forward-line)
3277 until (funcall endp)
3278 for i from 1 to limit
3279 collect (funcall get-line-fn (point-at-bol) (point-at-eol))
3280 do (funcall next-line-fn 1))))
3282 (defun anything-search-from-candidate-buffer-internal (search-fn)
3283 (goto-char (point-min))
3284 (insert "\n")
3285 (goto-char (point-max))
3286 (insert "\n")
3287 (unwind-protect
3288 (funcall search-fn)
3289 (goto-char (point-min))
3290 (delete-char 1)
3291 (goto-char (1- (point-max)))
3292 (delete-char 1)
3294 (set-buffer-modified-p nil)))
3296 (defun anything-candidate-buffer (&optional create-or-buffer)
3297 "Register and return a buffer containing candidates of current source.
3298 `anything-candidate-buffer' searches buffer-local candidates buffer first,
3299 then global candidates buffer.
3301 Acceptable values of CREATE-OR-BUFFER:
3303 - nil (omit)
3304 Only return the candidates buffer.
3305 - a buffer
3306 Register a buffer as a candidates buffer.
3307 - 'global
3308 Create a new global candidates buffer,
3309 named \" *anything candidates:SOURCE*\".
3310 - other non-nil value
3311 Create a new local candidates buffer,
3312 named \" *anything candidates:SOURCE*ANYTHING-CURRENT-BUFFER\"."
3313 (let* ((global-bname (format " *anything candidates:%s*" anything-source-name))
3314 (local-bname (format " *anything candidates:%s*%s"
3315 anything-source-name
3316 (buffer-name anything-current-buffer)))
3317 (register-func
3318 (lambda ()
3319 (setq anything-candidate-buffer-alist
3320 (cons (cons anything-source-name create-or-buffer)
3321 (delete (assoc anything-source-name
3322 anything-candidate-buffer-alist)
3323 anything-candidate-buffer-alist)))))
3324 (kill-buffers-func
3325 (lambda ()
3326 (loop for b in (buffer-list)
3327 if (string-match (format "^%s" (regexp-quote global-bname))
3328 (buffer-name b))
3329 do (kill-buffer b))))
3330 (create-func
3331 (lambda ()
3332 (with-current-buffer
3333 (get-buffer-create (if (eq create-or-buffer 'global)
3334 global-bname
3335 local-bname))
3336 (buffer-disable-undo)
3337 (erase-buffer)
3338 (font-lock-mode -1))))
3339 (return-func
3340 (lambda ()
3341 (or (get-buffer local-bname)
3342 (get-buffer global-bname)
3343 (anything-aif (assoc-default anything-source-name
3344 anything-candidate-buffer-alist)
3345 (and (buffer-live-p it) it))))))
3346 (when create-or-buffer
3347 (funcall register-func)
3348 (unless (bufferp create-or-buffer)
3349 (and (eq create-or-buffer 'global) (funcall kill-buffers-func))
3350 (funcall create-func)))
3351 (funcall return-func)))
3353 (defun anything-compile-source--candidates-in-buffer (source)
3354 (anything-aif (assoc 'candidates-in-buffer source)
3355 (append source
3356 `((candidates . ,(or (cdr it) 'anything-candidates-in-buffer))
3357 (volatile) (match identity)))
3358 source))
3361 ;; (@* "Utility: resplit anything window")
3362 (defun anything-toggle-resplit-window ()
3363 "Toggle resplit anything window, vertically or horizontally."
3364 (interactive)
3365 (with-anything-window
3366 (let ((before-height (window-height)))
3367 (delete-window)
3368 (set-window-buffer
3369 (select-window (if (= (window-height) before-height)
3370 (prog1
3371 (split-window-vertically)
3372 (setq anything-split-window-state 'vertical))
3373 (setq anything-split-window-state 'horizontal)
3374 (split-window-horizontally)))
3375 anything-buffer))))
3377 ;; (@* "Utility: Resize anything window.")
3378 (defun anything-enlarge-window-1 (n)
3379 "Enlarge or narrow anything window.
3380 If N is positive enlarge, if negative narrow."
3381 (unless anything-samewindow
3382 (let ((horizontal-p (eq anything-split-window-state 'horizontal)))
3383 (with-anything-window
3384 (enlarge-window n horizontal-p)))))
3386 (defun anything-narrow-window ()
3387 "Narrow anything window."
3388 (interactive)
3389 (anything-enlarge-window-1 -1))
3391 (defun anything-enlarge-window ()
3392 "Enlarge anything window."
3393 (interactive)
3394 (anything-enlarge-window-1 1))
3396 ;; (@* "Utility: select another action by key")
3397 (defun anything-select-nth-action (n)
3398 "Select the N nth action for the currently selected candidate."
3399 (setq anything-saved-selection (anything-get-selection))
3400 (unless anything-saved-selection
3401 (error "Nothing is selected"))
3402 (setq anything-saved-action (anything-get-nth-action n (anything-get-action)))
3403 (anything-exit-minibuffer))
3405 (defun anything-get-nth-action (n action)
3406 (cond ((and (zerop n) (functionp action))
3407 action)
3408 ((listp action)
3409 (or (cdr (elt action n))
3410 (error "No such action")))
3411 ((and (functionp action) (< 0 n))
3412 (error "Sole action"))
3414 (error "Error in `anything-select-nth-action'"))))
3416 (defun anything-select-2nd-action ()
3417 "Select the 2nd action for the currently selected candidate."
3418 (interactive)
3419 (anything-select-nth-action 1))
3421 (defun anything-select-3rd-action ()
3422 "Select the 3rd action for the currently selected candidate."
3423 (interactive)
3424 (anything-select-nth-action 2))
3426 (defun anything-select-4th-action ()
3427 "Select the 4th action for the currently selected candidate."
3428 (interactive)
3429 (anything-select-nth-action 3))
3431 (defun anything-select-2nd-action-or-end-of-line ()
3432 "Select the 2nd action for the currently selected candidate.
3433 This happen when point is at the end of minibuffer.
3434 Otherwise goto the end of minibuffer."
3435 (interactive)
3436 (if (eolp)
3437 (anything-select-nth-action 1)
3438 (end-of-line)))
3440 ;; (@* "Utility: Persistent Action")
3441 (defmacro with-anything-display-same-window (&rest body)
3442 "Execute BODY in the window used for persistent action.
3443 Make `pop-to-buffer' and `display-buffer' display in the same window."
3444 (declare (indent 0) (debug t))
3445 `(let ((display-buffer-function 'anything-persistent-action-display-buffer))
3446 ,@body))
3448 (defvar anything-persistent-action-display-window nil)
3449 (defun anything-initialize-persistent-action ()
3450 (set (make-local-variable 'anything-persistent-action-display-window) nil))
3452 (defun* anything-execute-persistent-action (&optional (attr 'persistent-action) onewindow)
3453 "Perform the associated action ATTR without quitting anything.
3454 ATTR default is 'persistent-action', but it can be anything else.
3455 In this case you have to add this new attribute to your source.
3456 When `anything-samewindow' and ONEWINDOW are non--nil,
3457 the anything window is never split in persistent action."
3458 (interactive)
3459 (anything-log "executing persistent-action")
3460 (with-anything-window
3461 (save-selected-window
3462 (anything-select-persistent-action-window onewindow)
3463 (anything-log-eval (current-buffer))
3464 (let ((anything-in-persistent-action t))
3465 (with-anything-display-same-window
3466 (anything-execute-selection-action
3468 (or (assoc-default attr (anything-get-current-source))
3469 (anything-get-action))
3471 (anything-log-run-hook 'anything-after-persistent-action-hook))))))
3474 (defun anything-persistent-action-display-window (&optional onewindow)
3475 "Return the window that will be used for presistent action.
3476 If ONEWINDOW is non--nil window will not be splitted in persistent action
3477 if `anything-samewindow' is non--nil also."
3478 (with-anything-window
3479 (setq anything-persistent-action-display-window
3480 (cond ((window-live-p anything-persistent-action-display-window)
3481 anything-persistent-action-display-window)
3482 ((and anything-samewindow (one-window-p t) (not onewindow))
3483 (split-window))
3484 ((get-buffer-window anything-current-buffer))
3486 (next-window (selected-window) 1))))))
3488 (defun anything-select-persistent-action-window (&optional onewindow)
3489 "Select the window that will be used for persistent action.
3490 See `anything-persistent-action-display-window' for how to use ONEWINDOW."
3491 (select-window (get-buffer-window (anything-buffer-get)))
3492 (select-window
3493 (setq minibuffer-scroll-window
3494 (anything-persistent-action-display-window onewindow))))
3496 (defun anything-persistent-action-display-buffer (buf &optional not-this-window)
3497 "Make `pop-to-buffer' and `display-buffer' display in the same window.
3498 If `anything-persistent-action-use-special-display' is non-nil and
3499 BUF is to be displayed by `special-display-function', use it.
3500 Otherwise ignores `special-display-buffer-names' and `special-display-regexps'.
3501 Argument NOT-THIS-WINDOW if present will be used as
3502 second argument of `display-buffer'."
3503 (let* ((name (buffer-name buf))
3504 display-buffer-function pop-up-windows pop-up-frames
3505 (same-window-regexps
3506 (unless (and anything-persistent-action-use-special-display
3507 (or (member name
3508 (mapcar (lambda (x) (or (car-safe x) x))
3509 special-display-buffer-names))
3510 (remove-if-not
3511 (lambda (x) (string-match (or (car-safe x) x) name))
3512 special-display-regexps)))
3513 '("."))))
3514 (display-buffer buf not-this-window)))
3516 ;; scroll-other-window(-down)? for persistent-action
3517 (defun anything-scroll-other-window-base (command)
3518 (with-selected-window (anything-persistent-action-display-window)
3519 (funcall command anything-scroll-amount)))
3521 (defun anything-scroll-other-window ()
3522 "Scroll other window (not *Anything* window) upward."
3523 (interactive)
3524 (anything-scroll-other-window-base 'scroll-up))
3526 (defun anything-scroll-other-window-down ()
3527 "Scroll other window (not *Anything* window) downward."
3528 (interactive)
3529 (anything-scroll-other-window-base 'scroll-down))
3532 ;; (@* "Utility: Visible Mark")
3533 (defface anything-visible-mark
3534 '((((min-colors 88) (background dark))
3535 (:background "green1" :foreground "black"))
3536 (((background dark)) (:background "green" :foreground "black"))
3537 (((min-colors 88)) (:background "green1"))
3538 (t (:background "green")))
3539 "Face for visible mark."
3540 :group 'anything)
3542 (defvar anything-visible-mark-face 'anything-visible-mark)
3543 (defvar anything-visible-mark-overlays nil)
3545 (defun anything-clear-visible-mark ()
3546 (with-current-buffer (anything-buffer-get)
3547 (mapc 'delete-overlay anything-visible-mark-overlays)
3548 (set (make-local-variable 'anything-visible-mark-overlays) nil)))
3549 (add-hook 'anything-after-initialize-hook 'anything-clear-visible-mark)
3551 (defvar anything-marked-candidates nil
3552 "Marked candadates. List of \(source . real\) pair.")
3554 (defun anything-this-visible-mark ()
3555 (loop for o in anything-visible-mark-overlays
3556 when (equal (point-at-bol) (overlay-start o))
3557 do (return o)))
3559 (defun anything-delete-visible-mark (overlay)
3560 (setq anything-marked-candidates
3561 (remove
3562 (cons (anything-get-current-source) (anything-get-selection))
3563 anything-marked-candidates))
3564 (delete-overlay overlay)
3565 (setq anything-visible-mark-overlays
3566 (delq overlay anything-visible-mark-overlays)))
3568 (defun anything-make-visible-mark ()
3569 (let ((o (make-overlay (point-at-bol) (1+ (point-at-eol)))))
3570 (overlay-put o 'face anything-visible-mark-face)
3571 (overlay-put o 'source (assoc-default 'name (anything-get-current-source)))
3572 (overlay-put o 'string (buffer-substring (overlay-start o) (overlay-end o)))
3573 (overlay-put o 'real (anything-get-selection))
3574 (add-to-list 'anything-visible-mark-overlays o))
3575 (push (cons (anything-get-current-source) (anything-get-selection))
3576 anything-marked-candidates))
3578 (defun anything-toggle-visible-mark ()
3579 "Toggle anything visible mark at point."
3580 (interactive)
3581 (with-anything-window
3582 (anything-aif (anything-this-visible-mark)
3583 (anything-delete-visible-mark it)
3584 (anything-make-visible-mark))
3585 (anything-next-line)))
3587 (defun anything-display-all-visible-marks ()
3588 "Show all `anything' visible marks strings."
3589 (interactive)
3590 (with-anything-window
3591 (lexical-let ((overlays (reverse anything-visible-mark-overlays)))
3592 (anything-run-after-quit
3593 (lambda ()
3594 (with-output-to-temp-buffer "*anything visible marks*"
3595 (dolist (o overlays) (princ (overlay-get o 'string)))))))))
3597 (defun anything-marked-candidates ()
3598 "Return marked candidates of current source if any.
3599 Otherwise one element list of current selection.
3601 It is analogous to `dired-get-marked-files'."
3602 (with-current-buffer (anything-buffer-get)
3603 (let ((cands
3604 (if anything-marked-candidates
3605 (loop with current-src = (anything-get-current-source)
3606 for (source . real) in (reverse anything-marked-candidates)
3607 when (equal current-src source)
3608 collect (anything-coerce-selection real source))
3609 (list (anything-get-selection)))))
3610 (anything-log-eval cands)
3611 cands)))
3613 (defun anything-reset-marked-candidates ()
3614 (with-current-buffer (anything-buffer-get)
3615 (set (make-local-variable 'anything-marked-candidates) nil)))
3617 (add-hook 'anything-after-initialize-hook 'anything-reset-marked-candidates)
3618 ;; (add-hook 'anything-after-action-hook 'anything-reset-marked-candidates)
3620 (defun anything-current-source-name= (name)
3621 (save-excursion
3622 (goto-char (anything-get-previous-header-pos))
3623 (equal name (anything-current-line-contents))))
3625 (defun anything-revive-visible-mark ()
3626 "Restore marked candidates when anything update display."
3627 (with-current-buffer anything-buffer
3628 (dolist (o anything-visible-mark-overlays)
3629 (goto-char (point-min))
3630 (while (and (search-forward (overlay-get o 'string) nil t)
3631 (anything-current-source-name= (overlay-get o 'source)))
3632 ;; Calculate real value of candidate.
3633 ;; It can be nil if candidate have only a display value.
3634 (let ((real (get-text-property (point-at-bol 0) 'anything-realvalue)))
3635 (if real
3636 ;; Check if real value of current candidate is the same
3637 ;; that the one stored in overlay.
3638 (and (string= (overlay-get o 'real) real)
3639 (move-overlay o (point-at-bol 0) (1+ (point-at-eol 0))))
3640 (move-overlay o (point-at-bol 0) (1+ (point-at-eol 0)))))))))
3641 (add-hook 'anything-update-hook 'anything-revive-visible-mark)
3643 (defun anything-next-point-in-list (curpos points &optional prev)
3644 (cond
3645 ;; rule out special cases
3646 ((null points) curpos)
3647 ((and prev (< curpos (car points))) curpos)
3648 ((< (car (last points)) curpos)
3649 (if prev (car (last points)) curpos))
3651 (nth (if prev
3652 (loop for pt in points
3653 for i from 0
3654 if (<= curpos pt)
3655 do (return (1- i)))
3656 (loop for pt in points
3657 for i from 0
3658 if (< curpos pt)
3659 do (return i)))
3660 points))))
3662 (defun anything-next-visible-mark (&optional prev)
3663 "Move next anything visible mark.
3664 If PREV is non-nil move to precedent."
3665 (interactive)
3666 (with-anything-window
3667 (goto-char (anything-next-point-in-list
3668 (point)
3669 (sort (mapcar 'overlay-start anything-visible-mark-overlays) '<)
3670 prev))
3671 (anything-mark-current-line)))
3673 (defun anything-prev-visible-mark ()
3674 "Move previous anything visible mark."
3675 (interactive)
3676 (anything-next-visible-mark t))
3678 ;; (@* "Utility: Selection Paste")
3679 (defun anything-yank-selection ()
3680 "Set minibuffer contents to current selection."
3681 (interactive)
3682 (anything-set-pattern (anything-get-selection nil t)))
3684 (defun anything-kill-selection-and-quit ()
3685 "Store current selection to kill ring.
3686 You can paste it by typing \\[yank]."
3687 (interactive)
3688 (anything-run-after-quit
3689 (lambda (sel)
3690 (kill-new sel)
3691 (message "Killed: %s" sel))
3692 (anything-get-selection nil t)))
3695 ;; (@* "Utility: Automatical execution of persistent-action")
3696 (add-to-list 'minor-mode-alist '(anything-follow-mode " AFollow"))
3697 (defun anything-follow-mode ()
3698 "If this mode is on, persistent action is executed everytime the cursor is moved."
3699 (interactive)
3700 (with-current-buffer anything-buffer
3701 (setq anything-follow-mode (not anything-follow-mode))
3702 (message "anything-follow-mode is %s"
3703 (if anything-follow-mode "enabled" "disabled"))))
3705 (defun anything-follow-execute-persistent-action-maybe ()
3706 "Execute persistent action in mode `anything-follow-mode'.
3707 This happen after `anything-input-idle-delay' secs."
3708 (and (not (get-buffer-window anything-action-buffer 'visible))
3709 (buffer-local-value 'anything-follow-mode
3710 (get-buffer-create anything-buffer))
3711 (sit-for anything-input-idle-delay)
3712 (anything-window)
3713 (anything-get-selection)
3714 (save-excursion
3715 (anything-execute-persistent-action))))
3718 ;; (@* "Utility: Migrate `anything-sources' to my-anything command")
3719 (defun anything-migrate-sources ()
3720 "Help to migrate to new `anything' way."
3721 (interactive)
3722 (with-current-buffer (get-buffer-create "*anything migrate*")
3723 (erase-buffer)
3724 (insert (format "\
3725 Setting `anything-sources' directly is not good because
3726 `anything' is not for one command. For now, interactive use of
3727 `anything' (M-x anything) is only for demonstration purpose.
3728 So you should define commands calling `anything'.
3729 I help you to migrate to the new way.
3731 The code below is automatically generated from current
3732 `anything-sources' value. You can use the `my-anything' command
3733 now!
3735 Copy and paste it to your .emacs. Then substitute `my-anything'
3736 for `anything' bindings in all `define-key', `local-set-key' and
3737 `global-set-key' calls.
3739 \(defun my-anything ()
3740 \"Anything command for you.
3742 It is automatically generated by `anything-migrate-sources'.\"
3743 (interactive)
3744 (anything-other-buffer
3746 \"*my-anything*\"))
3747 " anything-sources))
3748 (eval-last-sexp nil)
3749 (substitute-key-definition 'anything 'my-anything global-map)
3750 (pop-to-buffer (current-buffer))))
3753 ;; (@* "Compatibility")
3755 ;; Copied assoc-default from XEmacs version 21.5.12
3756 (unless (fboundp 'assoc-default)
3757 (defun assoc-default (key alist &optional test default)
3758 "Find object KEY in a pseudo-alist ALIST.
3759 ALIST is a list of conses or objects. Each element (or the element's car,
3760 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
3761 If that is non-nil, the element matches;
3762 then `assoc-default' returns the element's cdr, if it is a cons,
3763 or DEFAULT if the element is not a cons.
3765 If no element matches, the value is nil.
3766 If TEST is omitted or nil, `equal' is used."
3767 (let (found (tail alist) value)
3768 (while (and tail (not found))
3769 (let ((elt (car tail)))
3770 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
3771 (setq found t value (if (consp elt) (cdr elt) default))))
3772 (setq tail (cdr tail)))
3773 value)))
3775 ;; Function not available in XEmacs,
3776 (unless (fboundp 'minibuffer-contents)
3777 (defun minibuffer-contents ()
3778 "Return the user input in a minbuffer as a string.
3779 The current buffer must be a minibuffer."
3780 (field-string (point-max)))
3782 (defun delete-minibuffer-contents ()
3783 "Delete all user input in a minibuffer.
3784 The current buffer must be a minibuffer."
3785 (delete-field (point-max))))
3787 ;; Function not available in older Emacs (<= 22.1).
3788 (unless (fboundp 'buffer-chars-modified-tick)
3789 (defun buffer-chars-modified-tick (&optional buffer)
3790 "Return BUFFER's character-change tick counter.
3791 Each buffer has a character-change tick counter, which is set to the
3792 value of the buffer's tick counter (see `buffer-modified-tick'), each
3793 time text in that buffer is inserted or deleted. By comparing the
3794 values returned by two individual calls of `buffer-chars-modified-tick',
3795 you can tell whether a character change occurred in that buffer in
3796 between these calls. No argument or nil as argument means use current
3797 buffer as BUFFER."
3798 (with-current-buffer (or buffer (current-buffer))
3799 (if (listp buffer-undo-list)
3800 (length buffer-undo-list)
3801 (buffer-modified-tick)))))
3804 ;; (@* "CUA workaround")
3805 (defadvice cua-delete-region (around anything-avoid-cua activate)
3806 (ignore-errors ad-do-it))
3808 (defadvice copy-region-as-kill (around anything-avoid-cua activate)
3809 (if cua-mode
3810 (ignore-errors ad-do-it)
3811 ad-do-it))
3813 ;;(@* "Attribute Documentation")
3814 (defun anything-describe-anything-attribute (anything-attribute)
3815 "Display the full documentation of ANYTHING-ATTRIBUTE.
3816 ANYTHING-ATTRIBUTE should be a symbol."
3817 (interactive (list (intern
3818 (completing-read
3819 "Describe anything attribute: "
3820 (mapcar 'symbol-name anything-additional-attributes)))))
3821 (with-output-to-temp-buffer "*Help*"
3822 (princ (get anything-attribute 'anything-attrdoc))))
3824 (anything-document-attribute 'name "mandatory"
3825 " The name of the source. It is also the heading which appears
3826 above the list of matches from the source. Must be unique. ")
3827 (anything-document-attribute 'header-name "optional"
3828 " A function returning the display string of the header. Its
3829 argument is the name of the source. This attribute is useful to
3830 add an additional information with the source name. ")
3831 (anything-document-attribute 'candidates "mandatory if candidates-in-buffer attribute is not provided"
3832 " Specifies how to retrieve candidates from the source. It can
3833 either be a variable name, a function called with no parameters
3834 or the actual list of candidates.
3836 The list must be a list whose members are strings, symbols
3837 or (DISPLAY . REAL) pairs.
3839 In case of (DISPLAY . REAL) pairs, the DISPLAY string is shown
3840 in the Anything buffer, but the REAL one is used as action
3841 argument when the candidate is selected. This allows a more
3842 readable presentation for candidates which would otherwise be,
3843 for example, too long or have a common part shared with other
3844 candidates which can be safely replaced with an abbreviated
3845 string for display purposes.
3847 Note that if the (DISPLAY . REAL) form is used then pattern
3848 matching is done on the displayed string, not on the real
3849 value.
3851 If the candidates have to be retrieved asynchronously (for
3852 example, by an external command which takes a while to run)
3853 then the function should start the external command
3854 asynchronously and return the associated process object.
3855 Anything will take care of managing the process (receiving the
3856 output from it, killing it if necessary, etc.). The process
3857 should return candidates matching the current pattern (see
3858 variable `anything-pattern'.)
3860 Note that currently results from asynchronous sources appear
3861 last in the anything buffer regardless of their position in
3862 `anything-sources'. ")
3863 (anything-document-attribute 'action "mandatory if type attribute is not provided"
3864 " It is a list of (DISPLAY . FUNCTION) pairs or FUNCTION.
3865 FUNCTION is called with one parameter: the selected candidate.
3867 An action other than the default can be chosen from this list
3868 of actions for the currently selected candidate (by default
3869 with TAB). The DISPLAY string is shown in the completions
3870 buffer and the FUNCTION is invoked when an action is
3871 selected. The first action of the list is the default. ")
3872 (anything-document-attribute 'coerce "optional"
3873 " It's a function called with one argument: the selected candidate.
3875 This function is intended for type convertion.
3876 In normal case, the selected candidate (string) is passed to action function.
3877 If coerce function is specified, it is called just before action function.
3879 Example: converting string to symbol
3880 (coerce . intern) ")
3881 (anything-document-attribute 'type "optional if action attribute is provided"
3882 " Indicates the type of the items the source returns.
3884 Merge attributes not specified in the source itself from
3885 `anything-type-attributes'.
3887 This attribute is implemented by plug-in. ")
3888 (anything-document-attribute 'init "optional"
3889 " Function called with no parameters when anything is started. It
3890 is useful for collecting current state information which can be
3891 used to create the list of candidates later.
3893 For example, if a source needs to work with the current
3894 directory then it can store its value here, because later
3895 anything does its job in the minibuffer and in the
3896 `anything-buffer' and the current directory can be different
3897 there. ")
3898 (anything-document-attribute 'delayed-init "optional"
3899 " Function called with no parameters before candidate function is
3900 called. It is similar with `init' attribute, but its
3901 evaluation is deferred. It is useful to combine with ")
3902 (anything-document-attribute 'match "optional"
3903 " List of functions called with one parameter: a candidate. The
3904 function should return non-nil if the candidate matches the
3905 current pattern (see variable `anything-pattern').
3907 This attribute allows the source to override the default
3908 pattern matching based on `string-match'. It can be used, for
3909 example, to implement a source for file names and do the
3910 pattern matching on the basename of files, since it's more
3911 likely one is typing part of the basename when searching for a
3912 file, instead of some string anywhere else in its path.
3914 If the list contains more than one function then the list of
3915 matching candidates from the source is constructed by appending
3916 the results after invoking the first function on all the
3917 potential candidates, then the next function, and so on. The
3918 matching candidates supplied by the first function appear first
3919 in the list of results and then results from the other
3920 functions, respectively.
3922 This attribute has no effect for asynchronous sources (see
3923 attribute `candidates'), since they perform pattern matching
3924 themselves. ")
3925 (anything-document-attribute 'candidate-transformer "optional"
3926 " It's a function or a list of functions called with one argument
3927 when the completion list from the source is built. The argument
3928 is the list of candidates retrieved from the source. The
3929 function should return a transformed list of candidates which
3930 will be used for the actual completion. If it is a list of
3931 functions, it calls each function sequentially.
3933 This can be used to transform or remove items from the list of
3934 candidates.
3936 Note that `candidates' is run already, so the given transformer
3937 function should also be able to handle candidates with (DISPLAY
3938 . REAL) format. ")
3939 (anything-document-attribute 'filtered-candidate-transformer "optional"
3940 " It has the same format as `candidate-transformer', except the
3941 function is called with two parameters: the candidate list and
3942 the source.
3944 This transformer is run on the candidate list which is already
3945 filtered by the current pattern. While `candidate-transformer'
3946 is run only once, it is run every time the input pattern is
3947 changed.
3949 It can be used to transform the candidate list dynamically, for
3950 example, based on the current pattern.
3952 In some cases it may also be more efficent to perform candidate
3953 transformation here, instead of with `candidate-transformer'
3954 even if this transformation is done every time the pattern is
3955 changed. For example, if a candidate set is very large then
3956 `candidate-transformer' transforms every candidate while only
3957 some of them will actually be dislpayed due to the limit
3958 imposed by `anything-candidate-number-limit'.
3960 Note that `candidates' and `candidate-transformer' is run
3961 already, so the given transformer function should also be able
3962 to handle candidates with (DISPLAY . REAL) format.
3964 This option has no effect for asynchronous sources. (Not yet,
3965 at least. ")
3966 (anything-document-attribute 'action-transformer "optional"
3967 " It's a function or a list of functions called with two
3968 arguments when the action list from the source is
3969 assembled. The first argument is the list of actions, the
3970 second is the current selection. If it is a list of functions,
3971 it calls each function sequentially.
3973 The function should return a transformed action list.
3975 This can be used to customize the list of actions based on the
3976 currently selected candidate. ")
3977 (anything-document-attribute 'pattern-transformer "optional"
3978 " It's a function or a list of functions called with one argument
3979 before computing matches. Its argument is `anything-pattern'.
3980 Functions should return transformed `anything-pattern'.
3982 It is useful to change interpretation of `anything-pattern'. ")
3983 (anything-document-attribute 'delayed "optional"
3984 " Candidates from the source are shown only if the user stops
3985 typing and is idle for `anything-idle-delay' seconds. ")
3986 (anything-document-attribute 'volatile "optional"
3987 " Indicates the source assembles the candidate list dynamically,
3988 so it shouldn't be cached within a single Anything
3989 invocation. It is only applicable to synchronous sources,
3990 because asynchronous sources are not cached. ")
3991 (anything-document-attribute 'requires-pattern "optional"
3992 " If present matches from the source are shown only if the
3993 pattern is not empty. Optionally, it can have an integer
3994 parameter specifying the required length of input which is
3995 useful in case of sources with lots of candidates. ")
3996 (anything-document-attribute 'persistent-action "optional"
3997 " Function called with one parameter; the selected candidate.
3999 An action performed by `anything-execute-persistent-action'.
4000 If none, use the default action. ")
4001 (anything-document-attribute 'candidates-in-buffer "optional"
4002 " Shortcut attribute for making and narrowing candidates using
4003 buffers. This newly-introduced attribute prevents us from
4004 forgetting to add volatile and match attributes.
4006 See docstring of `anything-candidates-in-buffer'.
4008 (candidates-in-buffer) is equivalent of three attributes:
4009 (candidates . anything-candidates-in-buffer)
4010 (volatile)
4011 (match identity)
4013 (candidates-in-buffer . candidates-function) is equivalent of:
4014 (candidates . candidates-function)
4015 (volatile)
4016 (match identity)
4018 This attribute is implemented by plug-in. ")
4019 (anything-document-attribute 'search "optional"
4020 " List of functions like `re-search-forward' or `search-forward'.
4021 Buffer search function used by `anything-candidates-in-buffer'.
4022 By default, `anything-candidates-in-buffer' uses `re-search-forward'.
4023 This attribute is meant to be used with
4024 (candidates . anything-candidates-in-buffer) or
4025 (candidates-in-buffer) in short. ")
4026 (anything-document-attribute 'search-from-end "optional"
4027 " Make `anything-candidates-in-buffer' search from the end of buffer.
4028 If this attribute is specified, `anything-candidates-in-buffer' uses
4029 `re-search-backward' instead. ")
4030 (anything-document-attribute 'get-line "optional"
4031 " A function like `buffer-substring-no-properties' or `buffer-substring'.
4032 This function converts point of line-beginning and point of line-end,
4033 which represents a candidate computed by `anything-candidates-in-buffer'.
4034 By default, `anything-candidates-in-buffer' uses
4035 `buffer-substring-no-properties'. ")
4036 (anything-document-attribute 'display-to-real "optional"
4037 " Function called with one parameter; the selected candidate.
4039 The function transforms the selected candidate, and the result
4040 is passed to the action function. The display-to-real
4041 attribute provides another way to pass other string than one
4042 shown in Anything buffer.
4044 Traditionally, it is possible to make candidates,
4045 candidate-transformer or filtered-candidate-transformer
4046 function return a list with (DISPLAY . REAL) pairs. But if REAL
4047 can be generated from DISPLAY, display-to-real is more
4048 convenient and faster. ")
4049 (anything-document-attribute 'real-to-display "optional"
4050 " Function called with one parameter; the selected candidate.
4052 The inverse of display-to-real attribute.
4054 The function transforms the selected candidate, which is passed
4055 to the action function, for display. The real-to-display
4056 attribute provides the other way to pass other string than one
4057 shown in Anything buffer.
4059 Traditionally, it is possible to make candidates,
4060 candidate-transformer or filtered-candidate-transformer
4061 function return a list with (DISPLAY . REAL) pairs. But if
4062 DISPLAY can be generated from REAL, real-to-display is more
4063 convenient.
4065 Note that DISPLAY parts returned from candidates /
4066 candidate-transformer are IGNORED as the name `display-to-real'
4067 says. ")
4068 (anything-document-attribute 'cleanup "optional"
4069 " Function called with no parameters when *anything* buffer is closed. It
4070 is useful for killing unneeded candidates buffer.
4072 Note that the function is executed BEFORE performing action. ")
4073 (anything-document-attribute 'candidate-number-limit "optional"
4074 " Override `anything-candidate-number-limit' only for this source. ")
4075 (anything-document-attribute 'accept-empty "optional"
4076 " Pass empty string \"\" to action function. ")
4077 (anything-document-attribute 'disable-shortcuts "optional"
4078 " Disable `anything-enable-shortcuts' in current `anything' session.
4080 This attribute is implemented by plug-in. ")
4081 (anything-document-attribute 'dummy "optional"
4082 " Set `anything-pattern' to candidate. If this attribute is
4083 specified, The candidates attribute is ignored.
4085 This attribute is implemented by plug-in.
4086 This plug-in implies disable-shortcuts plug-in. ")
4087 (anything-document-attribute 'multiline "optional"
4088 " Enable to selection multiline candidates. ")
4089 (anything-document-attribute 'update "optional"
4090 ;; FIXME: this is not displayed correctly in help buffer.
4091 " Function called with no parameters when \\<anything-map>\\[anything-force-update] is pressed. ")
4092 (anything-document-attribute 'mode-line "optional"
4093 " source local `anything-mode-line-string'. (included in `mode-line-format')
4094 It accepts also variable/function name. ")
4095 (anything-document-attribute 'header-line "optional"
4096 " source local `header-line-format'.
4097 It accepts also variable/function name. ")
4098 (anything-document-attribute
4099 'resume "optional"
4100 " Function called with no parameters when `anything-resume' is started.")
4103 ;; (@* "Bug Report")
4104 (defvar anything-maintainer-mail-address "emacs-anything@googlegroups.com")
4106 (defvar anything-bug-report-salutation
4107 "Describe bug below, using a precise recipe.
4109 When I executed M-x ...
4111 How to send a bug report:
4112 1) Be sure to use the LATEST version of anything.el.
4113 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
4114 3) Use Lisp version instead of compiled one: (load \"anything.el\")
4115 4) If you got an error, please paste *Backtrace* buffer.
4116 5) Type C-c C-c to send.")
4118 (defvar anything-no-dump-variables
4119 '(anything-candidate-buffer-alist
4120 anything-digit-overlays
4121 anything-help-message
4122 anything-candidate-cache
4124 "Variables not to dump in bug report.")
4126 (defun anything-dumped-variables-in-bug-report ()
4127 (let ((hash (make-hash-table)))
4128 (loop for var in (apropos-internal "anything-" 'boundp)
4129 for vname = (symbol-name var)
4130 unless (or (string-match "-map$" vname)
4131 (string-match "^anything-c-source-" vname)
4132 (string-match "-hash$" vname)
4133 (string-match "-face$" vname)
4134 (memq var anything-no-dump-variables))
4135 collect var)))
4137 (defun anything-send-bug-report ()
4138 "Send a bug report of anything.el."
4139 (interactive)
4140 (with-current-buffer (or anything-last-buffer
4141 (current-buffer))
4142 (reporter-submit-bug-report
4143 anything-maintainer-mail-address
4144 "anything.el"
4145 (anything-dumped-variables-in-bug-report)
4146 nil nil
4147 anything-bug-report-salutation)))
4149 (defun anything-send-bug-report-from-anything ()
4150 "Send a bug report of anything.el in anything session."
4151 (interactive)
4152 (anything-run-after-quit 'anything-send-bug-report))
4154 ;; Debugging function.
4155 (defun* anything-test-candidates
4156 (sources &optional (input "")
4157 (compile-source-functions
4158 anything-compile-source-functions-default))
4159 "Test helper function for anything.
4160 Given pseudo `anything-sources' and `anything-pattern', returns list like
4161 ((\"source name1\" (\"candidate1\" \"candidate2\"))
4162 (\"source name2\" (\"candidate3\" \"candidate4\")))"
4163 (let ((anything-test-mode t)
4164 anything-enable-shortcuts
4165 anything-candidate-cache
4166 (anything-compile-source-functions compile-source-functions)
4167 anything-before-initialize-hook
4168 anything-after-initialize-hook
4169 anything-update-hook
4170 anything-test-candidate-list)
4171 (get-buffer-create anything-buffer)
4172 (anything-initialize nil input sources)
4173 (anything-update)
4174 ;; test-mode spec: select 1st candidate!
4175 (with-current-buffer anything-buffer
4176 (forward-line 1)
4177 (anything-mark-current-line))
4178 (prog1
4179 anything-test-candidate-list
4180 (anything-cleanup))))
4183 ;; (@* "Unit Tests")
4184 ;; See developer-tools/unit-test-anything.el
4186 (provide 'anything)
4188 ;; How to save (DO NOT REMOVE!!)
4189 ;; (progn (magit-push) (emacswiki-post "anything.el"))
4191 ;; Local Variables:
4192 ;; coding: utf-8
4193 ;; End:
4195 ;;; anything.el ends here