1 ;;; anything-config.el --- Predefined configurations for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Predefined configurations for `anything.el'
6 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
7 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
8 ;; rubikitch <rubikitch@ruby-lang.org>
9 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
10 ;; Copyright (C) 2007 ~ 2010, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009 ~ 2010, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009 ~ 2010, Thierry Volpiatto, all rights reserved.
14 ;; Created: 2009-02-16 21:38:23
16 ;; URL: http://www.emacswiki.org/emacs/download/anything-config.el
17 ;; Keywords: anything, anything-config
18 ;; Compatibility: GNU Emacs 22 ~ 23
20 ;; Features that might be required by this library:
25 ;;; This file is NOT part of GNU Emacs
29 ;; This program is free software; you can redistribute it and/or modify
30 ;; it under the terms of the GNU General Public License as published by
31 ;; the Free Software Foundation; either version 3, or (at your option)
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;; GNU General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING. If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
51 ;; Predefined configurations for `anything.el'
53 ;; For quick start, try `anything-for-files' to open files.
55 ;; To configure anything you should define anything command
56 ;; with your favorite sources, like below:
58 ;; (defun my-anything ()
60 ;; (anything-other-buffer
61 ;; '(anything-c-source-buffers
62 ;; anything-c-source-file-name-history
63 ;; anything-c-source-info-pages
64 ;; anything-c-source-info-elisp
65 ;; anything-c-source-man-pages
66 ;; anything-c-source-locate
67 ;; anything-c-source-emacs-commands)
70 ;; Then type M-x my-anything to use sources.
72 ;; Defining own command is better than setup `anything-sources'
73 ;; directly, because you can define multiple anything commands with
74 ;; different sources. Each anything command should have own anything
75 ;; buffer, because M-x anything-resume revives anything command.
78 ;; Anything sources can be tested by M-x `anything-call-source'.
79 ;; Below are complete source list you can setup in the first argument
80 ;; of `anything-other-buffer':
83 ;; `anything-c-source-buffers' (Buffers)
84 ;; `anything-c-source-buffer-not-found' (Create buffer)
85 ;; `anything-c-source-buffers+' (Buffers)
87 ;; `anything-c-source-file-name-history' (File Name History)
88 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
89 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
90 ;; `anything-c-source-find-files' (Find Files)
91 ;; `anything-c-source-file-cache' (File Cache)
92 ;; `anything-c-source-locate' (Locate)
93 ;; `anything-c-source-recentf' (Recentf)
94 ;; `anything-c-source-ffap-guesser' (File at point)
95 ;; `anything-c-source-ffap-line' (File/Lineno at point)
96 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
98 ;; `anything-c-source-man-pages' (Manual Pages)
99 ;; `anything-c-source-info-pages' (Info Pages)
100 ;; `anything-c-source-info-elisp' (Info Elisp)
101 ;; `anything-c-source-info-cl' (Info Common-Lisp)
103 ;; `anything-c-source-complex-command-history' (Complex Command History)
104 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
105 ;; `anything-c-source-emacs-commands' (Emacs Commands)
106 ;; `anything-c-source-lacarte' (Lacarte)
108 ;; `anything-c-source-emacs-functions' (Emacs Functions)
109 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
111 ;; `anything-c-source-emacs-variables' (Emacs Variables)
113 ;; `anything-c-source-bookmarks' (Bookmarks)
114 ;; `anything-c-source-bookmark-set' (Set Bookmark)
115 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
116 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
117 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
118 ;; `anything-c-source-bookmark-regions' (Bookmark Regions)
119 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
120 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
121 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
122 ;; `anything-c-source-bookmark-info' (Bookmark Info)
123 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
124 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
125 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
126 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
127 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
129 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
131 ;; `anything-c-source-imenu' (Imenu)
132 ;; `anything-c-source-ctags' (Exuberant ctags)
133 ;; `anything-c-source-semantic' (Semantic Tags)
134 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
135 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
136 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
138 ;; `anything-c-source-customize-face' (Customize Face)
139 ;; `anything-c-source-colors' (Colors)
141 ;; `anything-c-source-tracker-search' (Tracker Search)
142 ;; `anything-c-source-mac-spotlight' (mdfind)
144 ;; `anything-c-source-kill-ring' (Kill Ring)
146 ;; `anything-c-source-mark-ring' (mark-ring)
147 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
149 ;; `anything-c-source-register' (Registers)
150 ;; Headline Extraction:
151 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
152 ;; `anything-c-source-rd-headline' (RD HeadLine)
153 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
154 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
155 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
156 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
157 ;; `anything-c-source-org-headline' (Org HeadLine)
158 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
159 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
160 ;; `anything-c-source-eev-anchor' (Anchors)
162 ;; `anything-c-source-picklist' (Picklist)
163 ;; `anything-c-source-bbdb' (BBDB)
164 ;; `anything-c-source-evaluation-result' (Evaluation Result)
165 ;; `anything-c-source-calculation-result' (Calculation Result)
166 ;; `anything-c-source-google-suggest' (Google Suggest)
167 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
168 ;; `anything-c-source-surfraw' (Surfraw)
169 ;; `anything-c-source-emms-streams' (Emms Streams)
170 ;; `anything-c-source-emms-dired' (Music Directory)
171 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
172 ;; `anything-c-source-call-source' (Call anything source)
173 ;; `anything-c-source-occur' (Occur)
174 ;; `anything-c-source-create' (Create)
175 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
176 ;; `anything-c-source-elscreen' (Elscreen)
178 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
179 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
180 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
181 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
182 ;; `anything-c-source-xfonts' (X Fonts)
183 ;; `anything-c-source-apt' (APT)
184 ;; `anything-c-source-gentoo' (Portage sources)
185 ;; `anything-c-source-use-flags' (Use Flags)
186 ;; `anything-c-source-emacs-process' (Emacs Process)
190 ;; Below are complete command list:
192 ;; `anything-c-describe-anything-bindings'
193 ;; Describe `anything' bindings.
194 ;; `anything-for-files'
195 ;; Preconfigured `anything' for opening files.
196 ;; `anything-info-at-point'
197 ;; Preconfigured `anything' for searching info at point.
198 ;; `anything-show-kill-ring'
199 ;; Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
200 ;; `anything-minibuffer-history'
201 ;; Preconfigured `anything' for `minibuffer-history'.
203 ;; Preconfigured `anything' for gentoo linux.
204 ;; `anything-surfraw-only'
205 ;; Preconfigured `anything' for surfraw.
207 ;; Preconfigured `anything' for `imenu'.
208 ;; `anything-google-suggest'
209 ;; Preconfigured `anything' for google search with google suggest.
210 ;; `anything-yahoo-suggest'
211 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
212 ;; `anything-for-buffers'
213 ;; Preconfigured `anything' for buffer.
215 ;; Preconfigured `anything' for BBDB.
217 ;; Preconfigured `anything' for Locate.
218 ;; `anything-w3m-bookmarks'
219 ;; Preconfigured `anything' for w3m bookmark.
221 ;; Preconfigured `anything' for color.
222 ;; `anything-bm-list'
223 ;; Preconfigured `anything' for visible bookmarks.
225 ;; Preconfigured `anything' for timers.
226 ;; `anything-kill-buffers'
227 ;; You can continuously kill buffer you selected.
228 ;; `anything-query-replace-regexp'
229 ;; Drop-in replacement of `query-replace-regexp' with building regexp visually.
231 ;; It is like `re-builder'. It helps buliding regexp and replacement.
232 ;; `anything-insert-buffer-name'
233 ;; Insert buffer name.
234 ;; `anything-insert-symbol'
235 ;; Insert current symbol.
236 ;; `anything-insert-selection'
237 ;; Insert current selection.
238 ;; `anything-show-buffer-only'
239 ;; [OBSOLETE] Only show sources about buffer.
240 ;; `anything-show-bbdb-only'
241 ;; [OBSOLETE] Only show sources about BBDB.
242 ;; `anything-show-locate-only'
243 ;; [OBSOLETE] Only show sources about Locate.
244 ;; `anything-show-info-only'
245 ;; [OBSOLETE] Only show sources about Info.
246 ;; `anything-show-imenu-only'
247 ;; [OBSOLETE] Only show sources about Imenu.
248 ;; `anything-show-files-only'
249 ;; [OBSOLETE] Only show sources about File.
250 ;; `anything-show-w3m-bookmarks-only'
251 ;; [OBSOLETE] Only show source about w3m bookmark.
252 ;; `anything-show-colors-only'
253 ;; [OBSOLETE] Only show source about color.
254 ;; `anything-show-kill-ring-only'
255 ;; [OBSOLETE] Only show source about kill ring.
256 ;; `anything-show-this-source-only'
257 ;; Only show this source.
258 ;; `anything-test-sources'
259 ;; List all anything sources for test.
260 ;; `anything-select-source'
262 ;; `anything-find-files-down-one-level'
263 ;; Go down one level like unix command `cd ..'.
264 ;; `anything-find-files'
265 ;; Preconfigured anything for `find-file'.
266 ;; `anything-write-file'
267 ;; Preconfigured anything providing completion for `write-file'.
268 ;; `anything-insert-file'
269 ;; Preconfigured anything providing completion for `insert-file'.
270 ;; `anything-dired-rename-file'
271 ;; Preconfigured anything to rename files from dired.
272 ;; `anything-dired-copy-file'
273 ;; Preconfigured anything to copy files from dired.
274 ;; `anything-dired-symlink-file'
275 ;; Preconfigured anything to symlink files from dired.
276 ;; `anything-dired-hardlink-file'
277 ;; Preconfigured anything to hardlink files from dired.
278 ;; `anything-dired-bindings'
279 ;; Replace usual dired commands `C' and `R' by anything ones.
280 ;; `anything-bookmark-ext'
281 ;; Preconfigured anything for bookmark-extensions sources.
282 ;; `anything-mark-ring'
283 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
284 ;; `anything-global-mark-ring'
285 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
286 ;; `anything-yaoddmuse-cache-pages'
287 ;; Fetch the list of files on emacswiki and create cache file.
288 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
289 ;; Edit or View EmacsWiki page.
290 ;; `anything-yaoddmuse-emacswiki-post-library'
291 ;; Post library to EmacsWiki.
292 ;; `anything-emms-stream-edit-bookmark'
293 ;; Change the information of current emms-stream bookmark from anything.
294 ;; `anything-emms-stream-delete-bookmark'
295 ;; Delete an emms-stream bookmark from anything.
296 ;; `anything-call-source'
297 ;; Call anything source.
298 ;; `anything-call-source-from-anything'
299 ;; Call anything source within `anything' session.
300 ;; `anything-create-from-anything'
301 ;; Run `anything-create' from `anything' as a fallback.
303 ;; Do many create actions from STRING.
305 ;; Preconfigured `anything' for top command.
306 ;; `anything-select-xfont'
307 ;; Preconfigured `anything' to select Xfont.
309 ;; The `anything' frontend of APT package manager.
310 ;; `anything-c-set-variable'
311 ;; Set value to VAR interactively.
312 ;; `anything-c-adaptive-save-history'
313 ;; Save history information to file given by `anything-c-adaptive-history-file'.
315 ;;; Customizable Options:
317 ;; Below are customizable option list:
319 ;; `anything-c-use-standard-keys'
320 ;; Whether use standard keybindings. (no effect)
322 ;; `anything-c-adaptive-history-file'
323 ;; Path of file where history information is stored.
324 ;; default = "~/.emacs.d/anything-c-adaptive-history"
325 ;; `anything-c-adaptive-history-length'
326 ;; Maximum number of candidates stored for a source.
328 ;; `anything-c-google-suggest-url'
329 ;; URL used for looking up Google suggestions.
330 ;; default = "http://google.com/complete/search?output=toolbar&q="
331 ;; `anything-c-google-suggest-search-url'
332 ;; URL used for Google searching.
333 ;; default = "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
334 ;; `anything-google-suggest-use-curl-p'
335 ;; *When non--nil use CURL to get info from `anything-c-google-suggest-url'.
337 ;; `anything-c-yahoo-suggest-url'
338 ;; Url used for looking up Yahoo suggestions.
339 ;; default = "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
340 ;; `anything-c-yahoo-suggest-search-url'
341 ;; Url used for Yahoo searching.
342 ;; default = "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
343 ;; `anything-c-boring-buffer-regexp'
344 ;; The regexp that match boring buffers.
345 ;; default = (rx (or (group bos " ") "*anything" " *Echo Area" " *Minibuf"))
346 ;; `anything-c-boring-file-regexp'
347 ;; The regexp that match boring files.
348 ;; default = (rx (or (and "/" ... ...) (and line-start ".#") (and ... eol)))
349 ;; `anything-kill-ring-threshold'
350 ;; *Minimum length to be listed by `anything-c-source-kill-ring'.
352 ;; `anything-su-or-sudo'
353 ;; What command to use for root access.
355 ;; `anything-for-files-prefered-list'
356 ;; Your prefered sources to find files.
357 ;; default = (quote (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-source-buffers+ anything-c-source-recentf anything-c-source-bookmarks ...))
358 ;; `anything-create--actions-private'
359 ;; User defined actions for `anything-create' / `anything-c-source-create'.
361 ;; `anything-allow-skipping-current-buffer'
362 ;; Show current buffer or not in anything buffer
364 ;; `anything-c-enable-eval-defun-hack'
365 ;; *If non-nil, execute `anything' using the source at point when C-M-x is pressed.
367 ;; `anything-tramp-verbose'
368 ;; *Just like `tramp-verbose' but specific to anything.
374 ;; Change log of this file is found at
375 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
380 ;; Tassilo Horn <tassilo@member.fsf.org>
381 ;; Vagn Johansen <gonz808@hotmail.com>
382 ;; Mathias Dahl <mathias.dahl@gmail.com>
383 ;; Bill Clementson <billclem@gmail.com>
384 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
385 ;; Drew Adams <drew.adams@oracle.com>
386 ;; Jason McBrayer <jmcbray@carcosa.net>
387 ;; Andy Stewart <lazycat.manatee@gmail.com>
388 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
389 ;; rubikitch <rubikitch@ruby-lang.org>
390 ;; Scott Vokes <vokes.s@gmail.com>
395 ;; Evaluate (anything-c-insert-summary) before commit. This function
396 ;; generates anything-c-source-* list.
398 ;; Install also http://www.emacswiki.org/emacs/auto-document.el
399 ;; And eval it or run interactively.
401 ;; [EVAL IT] (anything-c-insert-summary)
402 ;; [EVAL IT] (auto-document)
404 ;; Please write details documentation about function, then others will
405 ;; read code more easier. -- Andy Stewart
411 ;; - anything-c-adaptive stores infos for sources/types that don't have
412 ;; set it as `filtered-candidate-transformer'.
414 ;; - Fix documentation, now many functions haven't documentations.
426 (let ((version "1.256"))
427 (when (and (string= "1." (substring version
0 2))
428 (string-match "1\.\\([0-9]+\\)" anything-version
)
429 (< (string-to-number (match-string 1 anything-version
))
430 (string-to-number (substring version
2))))
431 (error "Please update anything.el!!
433 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
435 or M-x install-elisp-from-emacswiki anything.el")))
437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
438 (defgroup anything-config nil
439 "Predefined configurations for `anything.el'."
442 (defcustom anything-c-use-standard-keys nil
443 "Whether use standard keybindings. (no effect)
445 Key definitions in anything-config.el are removed because
446 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
447 minibuffer history, C-s for isearch, etc.
449 If you use `iswitchb' with `anything',
450 evaluate (anything-iswitchb-setup) . Then some bindings that
451 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
452 history, are removed from `anything-map'. "
454 :group
'anything-config
)
456 (defcustom anything-c-adaptive-history-file
"~/.emacs.d/anything-c-adaptive-history"
457 "Path of file where history information is stored."
459 :group
'anything-config
)
461 (defcustom anything-c-adaptive-history-length
50
462 "Maximum number of candidates stored for a source."
464 :group
'anything-config
)
466 (defcustom anything-c-google-suggest-url
467 "http://google.com/complete/search?output=toolbar&q="
468 "URL used for looking up Google suggestions."
470 :group
'anything-config
)
472 (defcustom anything-c-google-suggest-search-url
473 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
474 "URL used for Google searching."
476 :group
'anything-config
)
478 (defcustom anything-google-suggest-use-curl-p nil
479 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
480 Otherwise `url-retrieve-synchronously' is used."
482 :group
'anything-config
)
484 (defcustom anything-c-yahoo-suggest-url
485 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
486 "Url used for looking up Yahoo suggestions."
488 :group
'anything-config
)
490 (defcustom anything-c-yahoo-suggest-search-url
491 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
492 "Url used for Yahoo searching."
494 :group
'anything-config
)
496 (defcustom anything-c-boring-buffer-regexp
502 " *Echo Area" " *Minibuf"))
503 "The regexp that match boring buffers.
504 Buffer candidates matching this regular expression will be
505 filtered from the list of candidates if the
506 `anything-c-skip-boring-buffers' candidate transformer is used, or
507 they will be displayed with face `file-name-shadow' if
508 `anything-c-shadow-boring-buffers' is used."
510 :group
'anything-config
)
511 ;; (string-match anything-c-boring-buffer-regexp "buf")
512 ;; (string-match anything-c-boring-buffer-regexp " hidden")
513 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
515 (defcustom anything-c-boring-file-regexp
517 ;; Boring directories
518 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
520 (and line-start
".#")
521 (and (or ".class" ".la" ".o" "~") eol
)))
522 "The regexp that match boring files.
523 File candidates matching this regular expression will be
524 filtered from the list of candidates if the
525 `anything-c-skip-boring-files' candidate transformer is used, or
526 they will be displayed with face `file-name-shadow' if
527 `anything-c-shadow-boring-files' is used."
529 :group
'anything-config
)
531 (defcustom anything-kill-ring-threshold
10
532 "*Minimum length to be listed by `anything-c-source-kill-ring'."
534 :group
'anything-config
)
536 (defcustom anything-su-or-sudo
"su"
537 "What command to use for root access."
539 :group
'anything-config
)
541 (defcustom anything-for-files-prefered-list
'(anything-c-source-ffap-line
542 anything-c-source-ffap-guesser
543 anything-c-source-buffers
+
544 anything-c-source-recentf
545 anything-c-source-bookmarks
546 anything-c-source-file-cache
547 anything-c-source-files-in-current-dir
+
548 anything-c-source-locate
)
549 "Your prefered sources to find files."
551 :group
'anything-config
)
553 (defcustom anything-create--actions-private nil
554 "User defined actions for `anything-create' / `anything-c-source-create'.
555 It is a list of (DISPLAY . FUNCTION) pairs like `action'
556 attribute of `anything-sources'.
558 It is prepended to predefined pairs."
560 :group
'anything-config
)
562 (defcustom anything-allow-skipping-current-buffer t
563 "Show current buffer or not in anything buffer"
565 :group
'anything-config
)
567 (defcustom anything-c-enable-eval-defun-hack t
568 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
569 This hack is invoked when pressing C-M-x in the form (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
571 :group
'anything-config
)
573 (defcustom anything-tramp-verbose
0
574 "*Just like `tramp-verbose' but specific to anything.
575 When set to 0 don't show tramp messages in anything.
576 If you want to have the default tramp messages set it to 3."
578 :group
'anything-config
)
581 (defun anything-c-describe-anything-bindings ()
582 "Describe `anything' bindings."
584 (anything-run-after-quit
586 (with-current-buffer (get-buffer-create "*Anything Help*")
589 (substitute-command-keys
590 "The keys that are defined for `anything' are:
592 (pop-to-buffer "*Anything Help*")
593 (goto-char (point-min)))))
595 ;; Use `describe-mode' key in `global-map'
596 (dolist (k (where-is-internal 'describe-mode global-map
))
597 (define-key anything-map k
'anything-c-describe-anything-bindings
))
599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
600 (defun anything-for-files ()
601 "Preconfigured `anything' for opening files.
602 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
604 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
606 (defun anything-info-at-point ()
607 "Preconfigured `anything' for searching info at point."
609 (anything '(anything-c-source-info-elisp
610 anything-c-source-info-cl
611 anything-c-source-info-pages
)
612 (thing-at-point 'symbol
) nil nil nil
"*anything info*"))
614 (defun anything-show-kill-ring ()
615 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
616 You may bind this command to M-y."
618 (anything-other-buffer 'anything-c-source-kill-ring
"*anything kill-ring*"))
620 (defun anything-minibuffer-history ()
621 "Preconfigured `anything' for `minibuffer-history'."
623 (let ((enable-recursive-minibuffers t
))
624 (anything-other-buffer 'anything-c-source-minibuffer-history
625 "*anything minibuffer-history*")))
627 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
628 ;; minibuffer-local-filename-must-match-map.
629 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
630 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
631 (dolist (map (list minibuffer-local-filename-completion-map
632 minibuffer-local-completion-map
633 minibuffer-local-must-match-filename-map
634 minibuffer-local-filename-must-match-map
636 minibuffer-local-isearch-map
637 minibuffer-local-must-match-map
638 minibuffer-local-ns-map
))
639 (define-key map
"\C-r" 'anything-minibuffer-history
))
641 (defun anything-gentoo ()
642 "Preconfigured `anything' for gentoo linux."
644 (anything-other-buffer '(anything-c-source-gentoo
645 anything-c-source-use-flags
)
646 "*anything gentoo*"))
648 (defun anything-surfraw-only ()
649 "Preconfigured `anything' for surfraw.
650 If region is marked set anything-pattern to region.
651 With one prefix arg search symbol at point.
652 With two prefix args allow choosing in which symbol to search."
654 (let (search pattern
)
655 (cond ((region-active-p)
656 (setq pattern
(buffer-substring (region-beginning) (region-end))))
657 ((equal current-prefix-arg
'(4))
658 (setq pattern
(thing-at-point 'symbol
)))
659 ((equal current-prefix-arg
'(16))
662 (completing-read "Search in: "
663 (list "symbol" "sentence" "sexp" "line" "word"))))
664 (setq pattern
(thing-at-point search
))))
665 (anything 'anything-c-source-surfraw
666 (and pattern
(replace-regexp-in-string "\n" "" pattern
))
667 nil nil nil
"*anything surfraw*")))
669 (defun anything-imenu ()
670 "Preconfigured `anything' for `imenu'."
672 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
674 (defun anything-google-suggest ()
675 "Preconfigured `anything' for google search with google suggest."
677 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
679 (defun anything-yahoo-suggest ()
680 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
682 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
684 ;;; Converted from anything-show-*-only
685 (defun anything-for-buffers ()
686 "Preconfigured `anything' for buffer."
688 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
690 (defun anything-bbdb ()
691 "Preconfigured `anything' for BBDB."
693 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
695 (defun anything-locate ()
696 "Preconfigured `anything' for Locate."
698 (anything-other-buffer 'anything-c-source-locate
"*anything locate*"))
700 (defun anything-w3m-bookmarks ()
701 "Preconfigured `anything' for w3m bookmark."
703 (anything-other-buffer 'anything-c-source-w3m-bookmarks
"*anything w3m bookmarks*"))
705 (defun anything-colors ()
706 "Preconfigured `anything' for color."
708 (anything-other-buffer '(anything-c-source-colors anything-c-source-customize-face
)
709 "*anything colors*"))
711 (defun anything-bm-list ()
712 "Preconfigured `anything' for visible bookmarks."
714 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*"))
716 (defun anything-timers ()
717 "Preconfigured `anything' for timers."
719 (anything-other-buffer '(anything-c-source-absolute-time-timers
720 anything-c-source-idle-time-timers
)
721 "*anything timers*"))
723 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
725 (defun anything-kill-buffers ()
726 "You can continuously kill buffer you selected."
729 '(((name .
"Kill Buffers")
730 (candidates . anything-c-buffer-list
)
732 ("Kill Buffer" .
(lambda (candidate)
733 (kill-buffer candidate
)
734 (anything-kill-buffers)
739 (defun anything-query-replace-regexp (&rest args
)
740 "Drop-in replacement of `query-replace-regexp' with building regexp visually."
743 (anything-c-regexp-base "Query Replace Regexp: "
744 '((name .
"Lines matching Regexp")
745 (action . anything-c-query-replace-args
)))))
748 (list (car common
) (cadr common
) (caddr common
)
749 ;; These are done separately here
750 ;; so that command-history will record these expressions
751 ;; rather than the values they had this time.
753 ;; This idea is borrowed from original `query-replace-regexp'.
754 (if (and transient-mark-mode mark-active
)
756 (if (and transient-mark-mode mark-active
)
758 (apply 'query-replace-regexp args
))
760 (defun anything-regexp ()
761 "It is like `re-builder'. It helps buliding regexp and replacement."
763 (anything-c-regexp-base
765 '((name .
"Regexp Builder")
767 ("Kill Regexp as sexp" .
768 (lambda (x) (anything-c-regexp-kill-new (prin1-to-string (funcall (anything-attr 'regexp
))))))
769 ("Query Replace Regexp" .
770 (lambda (x) (apply 'query-replace-regexp
(anything-c-query-replace-args (point)))))
772 (lambda (x) (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
)))))))))
774 (defun anything-c-query-replace-args (start-point)
775 ;; create arguments of `query-replace-regexp'.
776 (let ((region-only (and transient-mark-mode mark-active
))
777 (regexp (funcall (anything-attr 'regexp
))))
780 (query-replace-read-to regexp
781 (format "Query replace regexp %s%s%s with: "
782 (if region-only
"in region " "")
784 (if current-prefix-arg
"(word) " ""))
786 current-prefix-arg
)))
788 (defun anything-c-regexp-get-line (s e
)
792 (format "%5d: %s" (line-number-at-pos s
) (buffer-substring s e
))
794 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
796 collect
(format "\n $%d = %s"
797 i
(match-string i
))))
799 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
800 ;; It is implementation problem of candidates-in-buffer.
804 ;; Shut up byte compiler
805 (defun anything-goto-line (numline)
806 "Replacement of `goto-line'."
807 (goto-char (point-min)) (forward-line (1- numline
)))
809 (defun anything-c-regexp-persistent-action (txt)
810 (anything-goto-line (anything-aif (string-match "^ *\\([0-9]+\\)" txt
)
811 (string-to-number (match-string 1 txt
)))))
813 (defun anything-c-regexp-base (prompt attributes
)
815 (let ((anything-compile-source-functions
816 ;; rule out anything-match-plugin because the input is one regexp.
817 (delq 'anything-compile-source--match-plugin
818 (copy-sequence anything-compile-source-functions
)))
820 '((init .
(lambda () (anything-candidate-buffer anything-current-buffer
)))
821 (candidates-in-buffer)
822 (get-line . anything-c-regexp-get-line
)
823 (persistent-action . anything-c-regexp-persistent-action
)
826 (if (and transient-mark-mode mark-active
)
827 (narrow-to-region (region-beginning) (region-end)))
832 '((regexp .
(lambda () anything-pattern
)))
836 `((name .
,(concat (assoc-default 'name attributes
) " (sexp)")))
838 '((candidates-in-buffer
839 .
(lambda () (let ((anything-pattern (eval (read anything-pattern
))))
840 (anything-candidates-in-buffer))))
841 (regexp .
(lambda () (eval (read anything-pattern
)))))
843 nil prompt nil nil
"*anything regexp*"))))
845 ;; (anything-c-regexp-base "Regexp: " '((name . "test")))
846 ;; (anything-c-regexp-base "Regexp: " '((name . "test") (candidates-in-buffer . (lambda () (let ((anything-pattern (eval (read anything-pattern)))) (anything-candidates-in-buffer))))))
848 (defun anything-c-regexp-kill-new (input)
850 (message "Killed: %s" input
))
852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
854 (defun anything-insert-buffer-name ()
855 "Insert buffer name."
857 (anything-insert-string
858 (with-current-buffer anything-current-buffer
859 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
862 (defun anything-insert-symbol ()
863 "Insert current symbol."
865 (anything-insert-string
866 (with-current-buffer anything-current-buffer
868 (buffer-substring (beginning-of-thing 'symbol
)
869 (end-of-thing 'symbol
))))))
871 (defun anything-insert-selection ()
872 "Insert current selection."
874 (anything-insert-string
875 (with-current-buffer anything-current-buffer
876 (anything-get-selection))))
878 (defun anything-show-buffer-only ()
879 "[OBSOLETE] Only show sources about buffer.
880 Use `anything-for-buffers' instead."
882 (anything-set-source-filter '("Buffers")))
884 (defun anything-show-bbdb-only ()
885 "[OBSOLETE] Only show sources about BBDB.
886 Use `anything-bbdb' instead."
888 (anything-set-source-filter '("BBDB")))
890 (defun anything-show-locate-only ()
891 "[OBSOLETE] Only show sources about Locate.
892 Use `anything-locate' instead."
894 (anything-set-source-filter '("Locate")))
896 (defun anything-show-info-only ()
897 "[OBSOLETE] Only show sources about Info.
898 Use `anything-info-at-point' instead."
900 (anything-set-source-filter '("Info Pages"
902 "Info Common-Lisp")))
904 (defun anything-show-imenu-only ()
905 "[OBSOLETE] Only show sources about Imenu.
906 Use `anything-imenu' instead."
908 (anything-set-source-filter '("Imenu")))
910 (defun anything-show-files-only ()
911 "[OBSOLETE] Only show sources about File.
912 Use `anything-for-files' instead."
914 (anything-set-source-filter '("File Name History"
915 "Files from Current Directory"
918 (defun anything-show-w3m-bookmarks-only ()
919 "[OBSOLETE] Only show source about w3m bookmark.
920 Use `anything-w3m-bookmarks' instead."
922 (anything-set-source-filter '("W3m Bookmarks")))
924 (defun anything-show-colors-only ()
925 "[OBSOLETE] Only show source about color.
926 Use `anything-colors' instead."
928 (anything-set-source-filter '("Colors"
931 (defun anything-show-kill-ring-only ()
932 "[OBSOLETE] Only show source about kill ring.
933 Use `anything-show-kill-ring' instead."
935 (anything-set-source-filter '("Kill Ring")))
937 (defun anything-show-this-source-only ()
938 "Only show this source."
940 (setq anything-candidate-number-limit
9999)
941 (anything-set-source-filter
942 (list (assoc-default 'name
(anything-get-current-source)))))
944 (defun anything-test-sources ()
945 "List all anything sources for test.
946 The output is sexps which are evaluated by \\[eval-last-sexp]."
948 (with-output-to-temp-buffer "*Anything Test Sources*"
949 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
950 (apropos-internal "^anything-c-source" #'boundp
))
951 (pop-to-buffer standard-output
)))
953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
954 ;;; For compatibility
955 (unless (fboundp 'region-active-p
)
956 (defun region-active-p ()
957 "Return t if Transient Mark mode is enabled and the mark is active.
959 Most commands that act on the region if it is active and
960 Transient Mark mode is enabled, and on the text near point
961 otherwise, should use `use-region-p' instead. That function
962 checks the value of `use-empty-active-region' as well."
963 (and transient-mark-mode mark-active
)))
965 (defun anything-nest (&rest same-as-anything
)
966 "Nested `anything'. If you use `anything' within `anything', use it."
967 (with-selected-window (anything-window)
968 (let (anything-current-position
969 anything-current-buffer
970 (orig-anything-buffer anything-buffer
)
974 anything-compiled-sources
975 anything-buffer-chars-modified-tick
976 (anything-samewindow t
)
977 (enable-recursive-minibuffers t
))
979 (apply #'anything same-as-anything
)
980 (anything-initialize-overlays orig-anything-buffer
)
981 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
983 (defun anything-displaying-source-names ()
984 "Display sources name."
985 (with-current-buffer anything-buffer
986 (goto-char (point-min))
988 while
(setq pos
(next-single-property-change (point) 'anything-header
))
990 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
991 do
(forward-line 1))))
993 (defun anything-select-source ()
996 (let ((default (assoc-default 'name
(anything-get-current-source)))
997 (source-names (anything-displaying-source-names))
998 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
999 (anything-get-sources))))
1000 (setq anything-candidate-number-limit
9999)
1002 (let (anything-source-filter)
1003 (anything-nest '(((name .
"Anything Source")
1004 (candidates . source-names
)
1005 (action . identity
))
1006 ((name .
"Anything Source (ALL)")
1007 (candidates . all-source-names
)
1008 (action . identity
)))
1010 default
"*anything select source*"))
1011 (anything-set-source-filter (list it
))
1012 (anything-set-source-filter nil
))))
1014 (defun anything-insert-string (str)
1016 (delete-minibuffer-contents)
1019 (defun anything-c-match-on-file-name (candidate)
1020 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1021 (string-match anything-pattern
(file-name-nondirectory candidate
)))
1023 (defun anything-c-match-on-directory-name (candidate)
1024 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1025 (anything-aif (file-name-directory candidate
)
1026 (string-match anything-pattern it
)))
1028 (defun anything-c-string-match (candidate)
1029 "Return non-nil if `anything-pattern' match CANDIDATE.
1030 The match is done with `string-match'."
1031 (string-match anything-pattern candidate
))
1033 ;; `anything-c-compose' is no more needed, it is for compatibility.
1034 (defalias 'anything-c-compose
'anything-compose
)
1036 (defun anything-c-skip-entries (list regexp
)
1037 "Remove entries which matches REGEXP from LIST."
1038 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
1041 (defun anything-c-shadow-entries (list regexp
)
1042 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1043 (mapcar (lambda (file)
1044 ;; Add shadow face property to boring files.
1045 (let ((face (if (facep 'file-name-shadow
)
1047 ;; fall back to default on XEmacs
1049 (if (string-match regexp file
)
1050 (setq file
(propertize file
'face face
))))
1054 (defsubst anything-c-stringify
(str-or-sym)
1055 "Get string of STR-OR-SYM."
1056 (if (stringp str-or-sym
)
1058 (symbol-name str-or-sym
)))
1060 (defsubst anything-c-symbolify
(str-or-sym)
1061 "Get symbol of STR-OR-SYM."
1062 (if (symbolp str-or-sym
)
1064 (intern str-or-sym
)))
1066 (defun anything-c-describe-function (func)
1067 "FUNC is symbol or string."
1068 (describe-function (anything-c-symbolify func
)))
1070 (defun anything-c-describe-variable (var)
1071 "VAR is symbol or string."
1072 (describe-variable (anything-c-symbolify var
)))
1074 (defun anything-c-find-function (func)
1075 "FUNC is symbol or string."
1076 (find-function (anything-c-symbolify func
)))
1078 (defun anything-c-find-variable (var)
1079 "VAR is symbol or string."
1080 (find-variable (anything-c-symbolify var
)))
1082 (defun anything-c-kill-new (string &optional replace yank-handler
)
1083 "STRING is symbol or string."
1084 (kill-new (anything-c-stringify string
) replace yank-handler
))
1086 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1088 (defvar anything-current-prefix-arg nil
1089 "`current-prefix-arg' when selecting action.
1090 It is cleared after executing action.")
1092 (defadvice anything-exit-minibuffer
(before anything-current-prefix-arg activate
)
1093 (unless anything-current-prefix-arg
1094 (setq anything-current-prefix-arg current-prefix-arg
)))
1096 (add-hook 'anything-after-action-hook
1097 (lambda () (setq anything-current-prefix-arg nil
)))
1100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1101 (defadvice eval-defun
(after anything-source-hack activate
)
1102 "See `anything-c-enable-eval-defun-hack'."
1103 (when anything-c-enable-eval-defun-hack
1104 (let ((varsym (save-excursion
1105 (beginning-of-defun)
1107 (when (memq (read (current-buffer)) '(defvar setq
))
1108 (read (current-buffer))))))
1109 (when (string-match "^anything-c-source-" (symbol-name varsym
))
1110 (anything varsym
)))))
1111 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1114 (defun anything-c-create-summary ()
1115 "Create `anything' summary."
1117 (goto-char (point-min))
1118 (loop while
(re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$" nil t
)
1119 collect
(cond ((match-beginning 1)
1120 (cons 'section
(match-string-no-properties 1)))
1121 ((match-beginning 2)
1123 (cons (match-string-no-properties 2)
1124 (assoc-default 'name
(symbol-value (intern (match-string-no-properties 2)))))))
1125 ((match-beginning 3)
1127 (cons (match-string-no-properties 3)
1128 (assoc-default 'name
(symbol-value (intern (match-string-no-properties 3)))))))))))
1130 ;; (find-epp (anything-c-create-summary))
1132 (defun anything-c-insert-summary ()
1133 "Insert `anything' summary."
1135 (goto-char (point-min))
1136 (search-forward ";; Below are complete source list you can setup in")
1138 (delete-region (point)
1139 (progn (search-forward ";;; Change log:" nil t
)
1140 (forward-line -
1) (point)))
1143 for
(kind . value
) in
(anything-c-create-summary)
1145 do
(cond ((eq kind
'section
)
1147 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
1148 (insert ";; " value
":\n")
1151 (insert ";; `" (car value
) "' (" (cdr value
) ")\n")))
1152 finally
(align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))))
1153 ;; (anything-c-insert-summary)
1155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1157 (defun anything-c-buffer-list ()
1158 "Return the list of names of buffers with boring buffers filtered out.
1159 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1160 The first buffer in the list will be the last recently used
1161 buffer that is not the current buffer."
1162 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
1163 (append (cdr buffers
) (list (car buffers
)))))
1165 (defvar anything-c-source-buffers
1166 '((name .
"Buffers")
1167 (candidates . anything-c-buffer-list
)
1169 ;; (anything 'anything-c-source-buffers)
1171 (defvar anything-c-source-buffer-not-found
1172 '((name .
"Create buffer")
1175 ;; (anything 'anything-c-source-buffer-not-found)
1178 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
1179 "*Face used for directory headings in dired buffers."
1182 (defface anything-file-name
1183 '((t (:foreground
"Blue")))
1184 "*Face used for file names (without suffixes) in dired buffers."
1187 (defface anything-dir-priv
1188 '((t (:foreground
"DarkRed" :background
"LightGray")))
1189 "*Face used for directory privilege indicator (d) in dired buffers."
1192 (defvar anything-c-buffers-face1
'anything-dir-priv
)
1193 (defvar anything-c-buffers-face2
'font-lock-type-face
)
1194 (defvar anything-c-buffers-face3
'italic
)
1195 (eval-when-compile (require 'dired
))
1196 (defun anything-c-highlight-buffers (buffers)
1198 (loop for i in buffers
1199 if
(rassoc (get-buffer i
) dired-buffers
)
1200 collect
(propertize i
1201 'face anything-c-buffers-face1
1202 'help-echo
(car (rassoc (get-buffer i
) dired-buffers
)))
1203 if
(buffer-file-name (get-buffer i
))
1204 collect
(propertize i
1205 'face anything-c-buffers-face2
1206 'help-echo
(buffer-file-name (get-buffer i
)))
1207 if
(and (not (rassoc (get-buffer i
) dired-buffers
))
1208 (not (buffer-file-name (get-buffer i
))))
1209 collect
(propertize i
1210 'face anything-c-buffers-face3
)))
1212 (defvar anything-c-source-buffers
+
1213 '((name .
"Buffers")
1214 (candidates . anything-c-buffer-list
)
1216 (candidate-transformer anything-c-skip-current-buffer
1217 anything-c-highlight-buffers
1218 anything-c-skip-boring-buffers
)
1219 (persistent-action . anything-c-buffers
+-persistent-action
)))
1221 (defun anything-c-buffers+-persistent-action
(name)
1223 (with-current-buffer item
1224 (if (and (buffer-modified-p)
1225 (buffer-file-name (current-buffer)))
1229 (kill-buffer item
))))
1231 (switch-to-buffer item
)))
1232 (if current-prefix-arg
1235 (anything-delete-current-selection))
1238 ;; (anything 'anything-c-source-buffers+)
1242 ;;; File name history
1243 (defvar anything-c-source-file-name-history
1244 '((name .
"File Name History")
1245 (candidates . file-name-history
)
1246 (match anything-c-match-on-file-name
1247 anything-c-match-on-directory-name
)
1249 ;; (anything 'anything-c-source-file-name-history)
1251 ;;; Files in current dir
1252 (defvar anything-c-source-files-in-current-dir
1253 '((name .
"Files from Current Directory")
1254 (candidates .
(lambda ()
1255 (with-current-buffer anything-current-buffer
1256 (directory-files default-directory
))))
1257 ;; volatile is not needed, I think.
1259 ;; (anything 'anything-c-source-files-in-current-dir)
1261 (defvar anything-c-files-face1
'anything-dir-priv
)
1262 (defvar anything-c-files-face2
'anything-file-name
)
1263 (defun anything-c-highlight-files (files)
1264 (loop for i in files
1265 if
(file-directory-p i
)
1266 collect
(propertize (file-name-nondirectory i
)
1267 'face anything-c-files-face1
1268 'help-echo
(expand-file-name i
))
1270 collect
(propertize (file-name-nondirectory i
)
1271 'face anything-c-files-face2
1272 'help-echo
(expand-file-name i
))))
1275 (defvar anything-c-source-files-in-current-dir
+
1276 '((name .
"Files from Current Directory")
1277 (candidates .
(lambda ()
1278 (with-current-buffer anything-current-buffer
1279 (directory-files default-directory t
))))
1280 (candidate-transformer anything-c-highlight-files
)
1281 ;; volatile is not needed, I think.
1284 ;; (anything 'anything-c-source-files-in-current-dir+)
1286 ;;; Anything replacement of file name completion for `find-file' and friends.
1288 (defvar anything-c-find-files-doc-header
" (`C-z':Expand Candidate, `C-.':Go to precedent level)"
1289 "*The doc that is inserted in the Name header of a find-files or dired source.")
1291 (defvar anything-c-source-find-files
1292 `((name .
,(concat "Find Files" anything-c-find-files-doc-header
))
1294 (setq ffap-newfile-prompt t
)))
1295 (candidates . anything-find-files-get-candidates
)
1296 (candidate-transformer anything-c-highlight-ffiles
)
1297 (persistent-action . anything-find-files-persistent-action
)
1299 (action .
,(delq nil
`(("Find File" . find-file-at-point
)
1300 ("Find file in Dired" . anything-c-point-file-in-dired
)
1301 ,(and (locate-library "elscreen") '("Find file in Elscreen" . anything-elscreen-find-file
))
1302 ("Complete at point" . anything-c-insert-file-name-completion-at-point
)
1303 ("Delete File(s)" . anything-delete-marked-files
)
1304 ("Find file as root" . anything-find-file-as-root
)
1305 ("Find file other window" . find-file-other-window
)
1306 ("Find file other frame" . find-file-other-frame
))))))
1308 ;; (anything 'anything-c-source-find-files)
1310 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
1311 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1312 If LEVEL is positive reduce from end else from beginning.
1313 If UNIX-CLOSE is non--nil close filename with /.
1314 If EXPAND is non--nil expand-file-name."
1315 (let* ((exp-fname (expand-file-name fname
))
1316 (fname-list (split-string (if (or (string= fname
"~/") expand
)
1317 exp-fname fname
) "/" t
))
1318 (len (length fname-list
))
1319 (pop-list (if (< level
0)
1320 (subseq fname-list
(* level -
1))
1321 (subseq fname-list
0 (- len level
))))
1322 (result (mapconcat 'identity pop-list
"/"))
1323 (empty (string= result
"")))
1324 (when unix-close
(setq result
(concat result
"/")))
1325 (if (string-match "^~" result
)
1326 (if (string= result
"~/") "~/" result
)
1328 (if empty
"../" (concat "../" result
))
1329 (cond ((and (eq system-type
'windows-nt
) empty
)
1331 ((and (not empty
) (eq system-type
'windows-nt
))
1335 (concat "/" result
)))))))
1337 (defun anything-find-files-or-dired-p ()
1338 "Test if current source is a dired or find-files source."
1339 (let ((ff-sources '("Find Files" "Copy Files"
1340 "Rename Files" "Symlink Files"
1341 "Hardlink Files" "Write File" "Insert File"))
1342 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
1344 (dolist (i ff-sources
)
1345 (when (equal cur-source
(concat i anything-c-find-files-doc-header
))
1346 (throw 'break t
))))))
1348 (defun anything-find-files-down-one-level (arg)
1349 "Go down one level like unix command `cd ..'.
1350 If prefix numeric arg is given go ARG level down."
1352 (when (anything-find-files-or-dired-p)
1353 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
:unix-close t
:expand t
)))
1354 (with-selected-window (minibuffer-window)
1355 (delete-minibuffer-contents)
1356 (insert new-pattern
)))))
1357 (define-key anything-map
(kbd "C-.") 'anything-find-files-down-one-level
)
1359 (defun anything-c-point-file-in-dired (file)
1360 "Put point on filename FILE in dired buffer."
1361 (dired (file-name-directory file
))
1362 (dired-goto-file file
))
1364 (defun anything-create-tramp-name (fname)
1365 "Build filename for `anything-pattern' like /su:: or /sudo::."
1366 (apply #'tramp-make-tramp-file-name
1368 with v
= (tramp-dissect-file-name fname
)
1369 for i across v collect i
)))
1371 (defun anything-find-files-get-candidates ()
1372 "Create candidate list for `anything-c-source-find-files'."
1373 (let ((path (cond ((string-match "^~" anything-pattern
)
1374 (replace-match (getenv "HOME") nil t anything-pattern
))
1375 ((string-match "/su::" anything-pattern
)
1376 (let ((tramp-name (anything-create-tramp-name "/su::")))
1377 (replace-match tramp-name nil t anything-pattern
)))
1378 ((string-match "/sudo::" anything-pattern
)
1379 (let ((tramp-name (anything-create-tramp-name "/sudo::")))
1380 (replace-match tramp-name nil t anything-pattern
)))
1381 (t anything-pattern
)))
1382 (tramp-verbose anything-tramp-verbose
) ; No tramp message when 0.
1383 ;; Don't try to tramp connect before entering the second ":".
1384 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:"))
1385 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1386 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1388 (flet ((tramp-handle-directory-files
1389 (directory &optional full match nosort files-only
)
1390 "Like `directory-files' for Tramp files."
1391 ;; FILES-ONLY is valid for XEmacs only.
1392 (when (file-directory-p directory
)
1393 (setq directory
(file-name-as-directory (expand-file-name directory
)))
1394 (let ((temp (nreverse (file-name-all-completions "" directory
)))
1398 (setq item
(directory-file-name (pop temp
)))
1399 (when (and (or (null match
) (string-match match item
))
1400 (or (null files-only
)
1402 (and (equal files-only t
) (file-regular-p item
))
1403 ;; Directories only.
1404 (file-directory-p item
)))
1405 (push (if full
(concat directory item
) item
)
1407 (if nosort result
(sort result
'string
<))))))
1409 (set-text-properties 0 (length path
) nil path
)
1410 (setq anything-pattern path
)
1411 (cond ((or (file-regular-p path
)
1412 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
1414 ((string= anything-pattern
"") (directory-files "/" t
))
1415 ((file-directory-p path
) (directory-files path t
))
1419 (directory-files (file-name-directory path
) t
)))))))
1421 (defface anything-dired-symlink-face
1422 '((t (:foreground
"DarkOrange")))
1423 "*Face used for symlinks in `anything-find-files'."
1426 (defun anything-c-highlight-ffiles (files)
1427 "Candidate transformer for `anything-c-source-find-files'."
1428 (loop for i in files
1429 if
(file-symlink-p i
)
1430 collect
(propertize i
'face
'anything-dired-symlink-face
1431 'help-echo
(file-truename i
)) into a
1432 if
(file-directory-p i
)
1433 collect
(propertize i
'face anything-c-files-face1
) into a
1435 collect
(propertize i
'face anything-c-files-face2
) into a
1438 (defun anything-find-files-persistent-action (candidate)
1439 "Open subtree CANDIDATE without quitting anything.
1440 If CANDIDATE is not a directory open this file."
1441 (flet ((insert-in-minibuffer (elm)
1442 (with-selected-window (minibuffer-window)
1443 (delete-minibuffer-contents)
1444 (set-text-properties 0 (length elm
) nil elm
)
1446 (cond ((and (file-directory-p candidate
) (file-symlink-p candidate
))
1447 (insert-in-minibuffer (file-name-as-directory
1449 (expand-file-name candidate
)))))
1450 ((file-directory-p candidate
)
1451 (insert-in-minibuffer (file-name-as-directory
1452 (expand-file-name candidate
))))
1453 ((file-symlink-p candidate
)
1454 (insert-in-minibuffer (file-truename candidate
)))
1456 (let ((new-pattern (anything-get-selection anything-last-buffer
)))
1457 (set-text-properties 0 (length new-pattern
) nil new-pattern
)
1458 (insert-in-minibuffer new-pattern
))))))
1461 (defun anything-c-insert-file-name-completion-at-point (candidate)
1462 "Insert file name completion at point."
1463 (let* ((end (point))
1464 (guess (thing-at-point 'filename
))
1465 (full-path-p (string-match (concat "^" (getenv "HOME")) guess
)))
1467 (when (file-exists-p (file-name-directory guess
))
1468 (search-backward guess
(- (point) (length guess
)))
1469 (delete-region (point) end
)
1471 (insert (expand-file-name candidate
))
1472 (insert (abbreviate-file-name candidate
))))
1476 (defun anything-find-files ()
1477 "Preconfigured anything for `find-file'."
1479 (let ((fap (ffap-guesser)))
1480 (anything 'anything-c-source-find-files
1481 (or (if (and fap
(file-exists-p fap
)) (expand-file-name fap
) fap
)
1482 (expand-file-name default-directory
))
1483 "Find Files or Url: " nil nil
"*Anything Find Files*")))
1486 ;;; Anything completion for `write-file'.==> C-x C-w
1487 (defvar anything-c-source-write-file
1488 `((name .
,(concat "Write File" anything-c-find-files-doc-header
))
1489 (candidates . anything-find-files-get-candidates
)
1490 (candidate-transformer anything-c-highlight-ffiles
)
1491 (persistent-action . anything-find-files-persistent-action
)
1494 (("Write File" .
(lambda (candidate)
1495 (write-file candidate
'confirm
)))))))
1497 (defun anything-write-file ()
1498 "Preconfigured anything providing completion for `write-file'."
1500 (anything 'anything-c-source-write-file
1501 (expand-file-name default-directory
)
1502 "Write buffer to file: " nil nil
"*Anything write file*"))
1504 ;;; Anything completion for `insert-file'.==> C-x i
1505 (defvar anything-c-source-insert-file
1506 `((name .
,(concat "Insert File" anything-c-find-files-doc-header
))
1507 (candidates . anything-find-files-get-candidates
)
1508 (candidate-transformer anything-c-highlight-ffiles
)
1509 (persistent-action . anything-find-files-persistent-action
)
1512 (("Insert File" .
(lambda (candidate)
1513 (when (y-or-n-p (format "Really insert %s in %s "
1514 candidate anything-current-buffer
))
1515 (insert-file candidate
))))))))
1517 (defun anything-insert-file ()
1518 "Preconfigured anything providing completion for `insert-file'."
1520 (anything 'anything-c-source-insert-file
1521 (expand-file-name default-directory
)
1522 "Insert file here: " nil nil
"*Anything insert file*"))
1524 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
1525 (defvar anything-c-source-copy-files
1526 `((name .
,(concat "Copy Files" anything-c-find-files-doc-header
))
1527 (candidates . anything-find-files-get-candidates
)
1528 (candidate-transformer anything-c-highlight-ffiles
)
1529 (persistent-action . anything-find-files-persistent-action
)
1532 (("Copy File" .
(lambda (candidate)
1533 (anything-dired-action candidate
:action
'copy
)))))))
1536 (defvar anything-c-source-rename-files
1537 `((name .
,(concat "Rename Files" anything-c-find-files-doc-header
))
1538 (candidates . anything-find-files-get-candidates
)
1539 (candidate-transformer anything-c-highlight-ffiles
)
1540 (persistent-action . anything-find-files-persistent-action
)
1543 (("Rename File" .
(lambda (candidate)
1544 (anything-dired-action candidate
:action
'rename
)))))))
1546 (defvar anything-c-source-symlink-files
1547 `((name .
,(concat "Symlink Files" anything-c-find-files-doc-header
))
1548 (candidates . anything-find-files-get-candidates
)
1549 (candidate-transformer anything-c-highlight-ffiles
)
1550 (persistent-action . anything-find-files-persistent-action
)
1553 (("Symlink File" .
(lambda (candidate)
1554 (anything-dired-action candidate
:action
'symlink
)))
1555 ("RelSymlink File" .
(lambda (candidate)
1556 (anything-dired-action candidate
:action
'relsymlink
)))))))
1559 (defvar anything-c-source-hardlink-files
1560 `((name .
,(concat "Hardlink Files" anything-c-find-files-doc-header
))
1561 (candidates . anything-find-files-get-candidates
)
1562 (candidate-transformer anything-c-highlight-ffiles
)
1563 (persistent-action . anything-find-files-persistent-action
)
1566 (("Hardlink File" .
(lambda (candidate)
1567 (anything-dired-action candidate
:action
'hardlink
)))))))
1569 (defun* anything-dired-action
(candidate &key action
)
1570 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
1571 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
1572 (let ((files (dired-get-marked-files))
1574 ('copy
'dired-copy-file
)
1575 ('rename
'dired-rename-file
)
1576 ('symlink
'make-symbolic-link
)
1577 ('relsymlink
'dired-make-relative-symlink
)
1578 ('hardlink
'dired-hardlink
)))
1579 (marker (case action
1580 ((copy rename
) dired-keep-marker-copy
)
1581 ('symlink dired-keep-marker-symlink
)
1582 ('relsymlink dired-keep-marker-relsymlink
)
1583 ('hardlink dired-keep-marker-hardlink
))))
1585 fn
(symbol-name action
) files
1586 (if (file-directory-p candidate
)
1587 ;; When CANDIDATE is a directory, build file-name in this directory.
1588 ;; Else we use CANDIDATE.
1590 (expand-file-name (file-name-nondirectory from
) candidate
))
1591 #'(lambda (from) candidate
))
1595 (defun* anything-dired-do-action-on-file
(&key action
)
1596 (let* ((files (dired-get-marked-files))
1597 (len (length files
))
1598 (fname (if (> len
1)
1599 (format "* %d Files" len
)
1601 (source (case action
1602 ('copy
'anything-c-source-copy-files
)
1603 ('rename
'anything-c-source-rename-files
)
1604 ('symlink
'anything-c-source-symlink-files
)
1605 ('hardlink
'anything-c-source-hardlink-files
)))
1606 (prompt-fm (case action
1607 ('copy
"Copy %s to: ")
1608 ('rename
"Rename %s to: ")
1609 ('symlink
"Symlink %s to: ")
1610 ('hardlink
"Hardlink %s to: ")))
1611 (buffer (case action
1612 ('copy
"*Anything Copy Files*")
1613 ('rename
"*Anything Rename Files*")
1614 ('symlink
"*Anything Symlink Files*")
1615 ('hardlink
"*Anything Hardlink Files*"))))
1617 (or (dired-dwim-target-directory)
1618 (expand-file-name default-directory
))
1619 (format prompt-fm fname
) nil nil buffer
)))
1622 (defun anything-dired-rename-file ()
1623 "Preconfigured anything to rename files from dired."
1625 (anything-dired-do-action-on-file :action
'rename
))
1627 (defun anything-dired-copy-file ()
1628 "Preconfigured anything to copy files from dired."
1630 (anything-dired-do-action-on-file :action
'copy
))
1632 (defun anything-dired-symlink-file ()
1633 "Preconfigured anything to symlink files from dired."
1635 (anything-dired-do-action-on-file :action
'symlink
))
1637 (defun anything-dired-hardlink-file ()
1638 "Preconfigured anything to hardlink files from dired."
1640 (anything-dired-do-action-on-file :action
'hardlink
))
1642 (defvar anything-dired-bindings nil
)
1643 (defun anything-dired-bindings (&optional arg
)
1644 "Replace usual dired commands `C' and `R' by anything ones.
1645 When call interactively toggle dired bindings and anything bindings.
1646 When call non--interactively with arg > 0, enable anything bindings.
1647 You can put (anything-dired-binding 1) in init file to enable anything bindings."
1649 (if (or (when arg
(> arg
0)) (not anything-dired-bindings
))
1651 (define-key dired-mode-map
(kbd "C") 'anything-dired-copy-file
)
1652 (define-key dired-mode-map
(kbd "R") 'anything-dired-rename-file
)
1653 (define-key dired-mode-map
(kbd "S") 'anything-dired-symlink-file
)
1654 (define-key dired-mode-map
(kbd "H") 'anything-dired-hardlink-file
)
1655 (setq anything-dired-bindings t
))
1656 (define-key dired-mode-map
(kbd "C") 'dired-do-copy
)
1657 (define-key dired-mode-map
(kbd "R") 'dired-do-rename
)
1658 (define-key dired-mode-map
(kbd "S") 'dired-do-symlink
)
1659 (define-key dired-mode-map
(kbd "H") 'dired-do-hardlink
)
1660 (setq anything-dired-bindings nil
)))
1663 (defvar anything-c-source-file-cache-initialized nil
)
1665 (defvar anything-c-file-cache-files nil
)
1667 (defvar anything-c-source-file-cache
1668 '((name .
"File Cache")
1670 (require 'filecache nil t
)
1671 (unless anything-c-source-file-cache-initialized
1672 (setq anything-c-file-cache-files
1673 (loop for item in file-cache-alist append
1674 (destructuring-bind (base &rest dirs
) item
1675 (loop for dir in dirs collect
1676 (concat dir base
)))))
1677 (defadvice file-cache-add-file
(after file-cache-list activate
)
1678 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
1679 (setq anything-c-source-file-cache-initialized t
))))
1680 (candidates . anything-c-file-cache-files
)
1681 (match anything-c-match-on-file-name
1682 anything-c-match-on-directory-name
)
1684 ;; (anything 'anything-c-source-file-cache)
1687 (defvar anything-c-locate-options
1689 ((eq system-type
'darwin
) '("locate"))
1690 ((eq system-type
'berkeley-unix
) '("locate" "-i"))
1691 (t '("locate" "-i" "-r")))
1692 "A list where the `car' is the name of the locat program followed by options.
1693 The search pattern will be appended, so the
1694 \"-r\" option should be the last option.")
1696 (defvar anything-c-source-locate
1698 (candidates .
(lambda ()
1699 (apply 'start-process
"locate-process" nil
1700 (append anything-c-locate-options
1701 (list anything-pattern
)))))
1703 (requires-pattern .
3)
1705 "Source for retrieving files matching the current input pattern with locate.")
1706 ;; (anything 'anything-c-source-locate)
1709 (defvar anything-c-source-recentf
1710 '((name .
"Recentf")
1713 (or recentf-mode
(recentf-mode 1))
1714 ;; Big value empowers anything/recentf
1715 (when (and (numberp recentf-max-saved-items
)
1716 (<= recentf-max-saved-items
20))
1717 (setq recentf-max-saved-items
500))))
1718 (candidates . recentf-list
)
1719 (match anything-c-match-on-file-name
1720 anything-c-match-on-directory-name
)
1722 "See (info \"(emacs)File Conveniences\").
1723 if `recentf-max-saved-items' is too small, set it to 500.")
1724 ;; (anything 'anything-c-source-recentf)
1727 (eval-when-compile (require 'ffap
))
1728 (defvar anything-c-source-ffap-guesser
1729 '((name .
"File at point")
1730 (init .
(lambda () (require 'ffap
)))
1731 (candidates .
(lambda ()
1733 (with-current-buffer anything-current-buffer
1737 ;; (anything 'anything-c-source-ffap-guesser)
1739 ;;; ffap with line number
1740 (defun anything-c-ffap-file-line-at-point ()
1741 "Get (FILENAME . LINENO) at point."
1742 (anything-aif (let (ffap-alist) (ffap-file-at-point))
1745 (when (and (search-forward it nil t
)
1746 (looking-at ":\\([0-9]+\\)"))
1747 (cons it
(string-to-number (match-string 1)))))))
1749 (defvar anything-c-ffap-line-location nil
1750 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
1751 It is cleared after jumping line.")
1753 (defun anything-c-ffap-line-candidates ()
1754 (with-current-buffer anything-current-buffer
1755 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
1756 (when anything-c-ffap-line-location
1757 (destructuring-bind (file . line
) anything-c-ffap-line-location
1758 (list (cons (format "%s (line %d)" file line
) file
)))))
1760 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
1761 (defun anything-c-ffap-line-goto-line ()
1762 (when (car anything-c-ffap-line-location
)
1765 (with-selected-window (get-buffer-window
1766 (get-file-buffer (car anything-c-ffap-line-location
)))
1767 (anything-goto-line (cdr anything-c-ffap-line-location
))))
1768 (setq anything-c-ffap-line-location nil
))))
1769 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
1771 (defvar anything-c-source-ffap-line
1772 '((name .
"File/Lineno at point")
1773 (init .
(lambda () (require 'ffap
)))
1774 (candidates . anything-c-ffap-line-candidates
)
1776 ;; (anything 'anything-c-source-ffap-line)
1778 ;;; list of files gleaned from every dired buffer
1779 (defun anything-c-files-in-all-dired-candidates ()
1783 (cond ((listp dir
) ;filelist
1785 ((equal "" (file-name-nondirectory dir
)) ;dir
1786 (directory-files dir t
))
1788 (file-expand-wildcards dir t
))))
1790 (mapcar (lambda (buf)
1792 (when (eq major-mode
'dired-mode
)
1793 (if (consp dired-directory
)
1794 (cdr dired-directory
) ;filelist
1795 dired-directory
))) ;dir or wildcard
1797 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
1799 (defvar anything-c-source-files-in-all-dired
1800 '((name .
"Files in all dired buffer.")
1801 (candidates . anything-c-files-in-all-dired-candidates
)
1803 ;; (anything 'anything-c-source-files-in-all-dired)
1807 (defvar anything-c-man-pages nil
1808 "All man pages on system.
1809 Will be calculated the first time you invoke anything with this
1812 (defvar anything-c-source-man-pages
1813 `((name .
"Manual Pages")
1814 (candidates .
(lambda ()
1815 (if anything-c-man-pages
1816 anything-c-man-pages
1817 ;; XEmacs doesn't have a woman :)
1818 (setq anything-c-man-pages
1821 (woman-file-name "")
1822 (sort (mapcar 'car woman-topic-all-completions
)
1824 (action ("Show with Woman" . woman
))
1825 (requires-pattern .
2)))
1826 ;; (anything 'anything-c-source-man-pages)
1829 (defvar anything-c-info-pages nil
1830 "All info pages on system.
1831 Will be calculated the first time you invoke anything with this
1834 (defvar anything-c-source-info-pages
1835 `((name .
"Info Pages")
1836 (candidates .
(lambda ()
1837 (if anything-c-info-pages
1838 anything-c-info-pages
1839 (setq anything-c-info-pages
1840 (save-window-excursion
1843 (Info-find-node "dir" "top")
1844 (goto-char (point-min))
1845 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
1847 (while (re-search-forward info-topic-regexp nil t
)
1848 (add-to-list 'topics
(match-string-no-properties 1)))
1849 (goto-char (point-min))
1852 (action .
(("Show with Info" .
(lambda (node-str)
1853 (info (replace-regexp-in-string "^[^:]+: "
1856 (requires-pattern .
2)))
1857 ;; (anything 'anything-c-source-info-pages)
1860 (defvar anything-c-info-elisp nil
)
1861 (defvar anything-c-source-info-elisp
1862 `((name .
"Info Elisp")
1864 (save-window-excursion
1865 (unless anything-c-info-elisp
1867 (Info-find-node "elisp" "Index")
1868 (setq anything-c-info-elisp
(split-string (buffer-string) "\n"))
1870 (candidates .
(lambda ()
1871 (loop for i in anything-c-info-elisp
1872 if
(string-match "^* [^ \n]+[^: ]" i
)
1873 collect
(match-string 0 i
))))
1874 (action .
(lambda (candidate)
1875 (Info-find-node "elisp" "Index")
1876 (Info-index (replace-regexp-in-string "* " "" candidate
))))
1877 (requires-pattern .
2)))
1878 ;; (anything 'anything-c-source-info-elisp)
1881 (defvar anything-c-info-cl-fn nil
)
1882 (defvar anything-c-source-info-cl
1883 `((name .
"Info Common-Lisp")
1885 (save-window-excursion
1886 (unless anything-c-info-cl-fn
1888 (Info-find-node "cl" "Function Index")
1889 (setq anything-c-info-cl-fn
(split-string (buffer-string) "\n"))
1891 (candidates .
(lambda ()
1892 (loop for i in anything-c-info-cl-fn
1893 if
(string-match "^* [^ \n]+[^: ]" i
)
1894 collect
(match-string 0 i
))))
1895 (action .
(lambda (candidate)
1896 (Info-find-node "cl" "Function Index")
1897 (Info-index (replace-regexp-in-string "* " "" candidate
))))
1898 (requires-pattern .
2)))
1899 ;; (anything 'anything-c-source-info-cl)
1902 ;;; Complex command history
1903 (defvar anything-c-source-complex-command-history
1904 '((name .
"Complex Command History")
1905 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
1907 ;; (anything 'anything-c-source-complex-command-history)
1910 (defvar anything-c-source-extended-command-history
1911 '((name .
"Emacs Commands History")
1912 (candidates . extended-command-history
)
1914 ;; (anything 'anything-c-source-extended-command-history)
1917 (defvar anything-c-source-emacs-commands
1918 '((name .
"Emacs Commands")
1919 (candidates .
(lambda ()
1921 (mapatoms (lambda (a)
1923 (push (symbol-name a
)
1925 (sort commands
'string-lessp
))))
1927 (requires-pattern .
2))
1928 "Source for completing and invoking Emacs commands.
1929 A command is a function with interactive spec that can
1930 be invoked with `M-x'.
1932 To get non-interactive functions listed, use
1933 `anything-c-source-emacs-functions'.")
1934 ;; (anything 'anything-c-source-emacs-commands)
1937 (defvar anything-c-source-lacarte
1938 '((name .
"Lacarte")
1939 (init .
(lambda () (require 'lacarte
)))
1940 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
1941 (candidate-number-limit .
9999)
1942 (action . anything-c-call-interactively
))
1945 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
1946 ;; (anything 'anything-c-source-lacarte)
1950 (defvar anything-c-source-emacs-functions
1951 '((name .
"Emacs Functions")
1952 (candidates .
(lambda ()
1954 (mapatoms (lambda (a) (if (functionp a
)
1955 (push (symbol-name a
) commands
))))
1956 (sort commands
'string-lessp
))))
1958 (requires-pattern .
2))
1959 "Source for completing Emacs functions.")
1960 ;; (anything 'anything-c-source-emacs-functions)
1962 ;;; With abbrev expansion
1963 ;;; Similar to my exec-abbrev-cmd.el
1964 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
1965 (defvar anything-c-function-abbrev-regexp nil
1966 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
1967 Regexp built from the current `anything-pattern' interpreting it
1969 Only for internal use.")
1971 (defun anything-c-match-function-by-abbrev (candidate)
1972 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
1974 Abbreviations are made by taking the first character from each
1975 word in the function's name, e.g. \"bb\" is an abbrev for
1976 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
1977 (string-match anything-c-function-abbrev-regexp candidate
))
1979 (defvar anything-c-source-emacs-functions-with-abbrevs
1980 (append anything-c-source-emacs-functions
1981 '((match anything-c-match-function-by-abbrev
1982 anything-c-string-match
))
1983 '((init .
(lambda ()
1984 (defadvice anything-update
1985 (before anything-c-update-function-abbrev-regexp activate
)
1986 (let ((char-list (append anything-pattern nil
))
1988 (dolist (c char-list
)
1989 (setq str
(concat str
(list c
) "[^-]*-")))
1990 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
1991 (setq anything-c-function-abbrev-regexp str
))))))))
1992 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
1996 (defvar anything-c-source-emacs-variables
1997 '((name .
"Emacs Variables")
1998 (candidates .
(lambda ()
1999 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
2001 (requires-pattern .
2))
2002 "Source for completing Emacs variables.")
2003 ;; (anything 'anything-c-source-emacs-variables)
2007 (eval-when-compile (require 'bookmark
))
2008 (defvar anything-c-source-bookmarks
2009 '((name .
"Bookmarks")
2011 (require 'bookmark
)))
2012 (candidates . bookmark-all-names
)
2014 "See (info \"(emacs)Bookmarks\").")
2015 ;; (anything 'anything-c-source-bookmarks)
2018 (defvar anything-c-source-bookmark-set
2019 '((name .
"Set Bookmark")
2021 (action . bookmark-set
))
2022 "See (info \"(emacs)Bookmarks\").")
2023 ;; (anything 'anything-c-source-bookmark-set)
2025 ;;; Visible Bookmarks
2026 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2029 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2030 (defvar anything-c-source-bm
2031 '((name .
"Visible Bookmarks")
2032 (init . anything-c-bm-init
)
2033 (candidates-in-buffer)
2037 http://www.nongnu.org/bm/")
2039 (defun anything-c-bm-init ()
2040 "Init function for `anything-c-source-bm'."
2041 (when (require 'bm nil t
)
2043 (let ((bookmarks (bm-lists))
2044 (buf (anything-candidate-buffer 'global
)))
2045 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
2046 '< :key
'overlay-start
))
2047 (let ((start (overlay-start bm
))
2048 (end (overlay-end bm
))
2049 (annotation (or (overlay-get bm
'annotation
) "")))
2050 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
2051 (let ((str (format "%7d: [%s]: %s\n"
2052 (line-number-at-pos start
)
2054 (buffer-substring start
(1- end
)))))
2055 (with-current-buffer buf
(insert str
))))))))))
2057 ;;; Special bookmarks
2058 (defvar anything-c-source-bookmarks-ssh
2059 '((name .
"Bookmarks-ssh")
2061 (require 'bookmark
)))
2063 (candidates .
(lambda ()
2064 (let (lis-all lis-ssh
)
2065 (setq lis-all
(bookmark-all-names))
2066 (setq lis-ssh
(loop for i in lis-all
2067 if
(string-match "^(ssh)" i
)
2069 (sort lis-ssh
'string-lessp
))))
2071 "See (info \"(emacs)Bookmarks\").")
2072 ;; (anything 'anything-c-source-bookmarks-ssh)
2074 (defvar anything-c-source-bookmarks-su
2075 '((name .
"Bookmarks-root")
2077 (require 'bookmark
)))
2079 (candidates .
(lambda ()
2080 (let (lis-all lis-su
)
2081 (setq lis-all
(bookmark-all-names))
2082 (setq lis-su
(loop for i in lis-all
2083 if
(string-match (format "^(%s)" anything-su-or-sudo
) i
)
2085 (sort lis-su
'string-lessp
))))
2086 (candidate-transformer anything-c-highlight-bookmark-su
)
2089 "See (info \"(emacs)Bookmarks\").")
2090 ;; (anything 'anything-c-source-bookmarks-su)
2093 (defun tv-root-logged-p ()
2095 (dolist (i (mapcar #'buffer-name
(buffer-list)))
2096 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
2097 (throw 'break t
)))))
2100 (defun anything-c-highlight-bookmark-su (files)
2101 (if (tv-root-logged-p)
2102 (anything-c-highlight-bookmark files
)
2103 (anything-c-highlight-not-logged files
)))
2105 (defun anything-c-highlight-not-logged (files)
2106 (loop for i in files
2107 collect
(propertize i
'face anything-c-bookmarks-face3
)))
2109 (defun anything-c-highlight-bookmark (bookmarks)
2110 "Used as `candidate-transformer' to colorize bookmarks.
2111 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2112 (loop for i in bookmarks
2113 for pred
= (bookmark-get-filename i
)
2114 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
2115 (bmkext-get-buffer-name i
))
2116 for regp
= (and (fboundp 'bmkext-get-end-position
)
2117 (bmkext-get-end-position i
)
2118 (/= (bookmark-get-position i
)
2119 (bmkext-get-end-position i
)))
2120 for handlerp
= (and (fboundp 'bookmark-get-handler
)
2121 (bookmark-get-handler i
))
2122 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
2123 (bmkext-w3m-bookmark-p i
))
2124 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
2125 (bmkext-gnus-bookmark-p i
))
2126 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
2127 (bmkext-man-bookmark-p i
))
2128 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
2129 (bmkext-woman-bookmark-p i
))
2130 for handlerp
= (bookmark-get-handler i
)
2131 for isannotation
= (bookmark-get-annotation i
)
2132 ;; Add a * if bookmark have annotation
2133 if
(and isannotation
(not (string-equal isannotation
"")))
2134 do
(setq i
(concat "*" i
))
2136 if
(eq handlerp
'Info-bookmark-jump
)
2137 collect
(propertize i
'face
'anything-bmkext-info
'help-echo pred
)
2140 collect
(propertize i
'face
'anything-bmkext-w3m
'help-echo pred
)
2143 collect
(propertize i
'face
'anything-bmkext-gnus
'help-echo pred
)
2145 if
(or iswoman isman
)
2146 collect
(propertize i
'face
'anything-bmkext-man
'help-echo pred
)
2148 if
(and pred
(file-directory-p pred
))
2149 collect
(propertize i
'face anything-c-bookmarks-face1
'help-echo pred
)
2150 ;; regular files with regions saved
2151 if
(and pred
(not (file-directory-p pred
)) (file-exists-p pred
) regp
)
2152 collect
(propertize i
'face
'anything-bmkext-region
'help-echo pred
)
2154 if
(and pred
(not (file-directory-p pred
)) (file-exists-p pred
)
2155 (not regp
) (not (or iswoman isman
)))
2156 collect
(propertize i
'face
'anything-bmkext-file
'help-echo pred
)
2157 ;; buffer non--filename
2158 if
(and (fboundp 'bmkext-get-buffer-name
) bufp
(not handlerp
)
2159 (if pred
(not (file-exists-p pred
)) (not pred
)))
2160 collect
(propertize i
'face
'anything-bmkext-no--file
)))
2162 ;;; Faces for bookmarks
2163 (defface anything-bmkext-info
2164 '((t (:foreground
"green")))
2165 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2168 (defface anything-bmkext-w3m
2169 '((t (:foreground
"yellow")))
2170 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2173 (defface anything-bmkext-gnus
2174 '((t (:foreground
"magenta")))
2175 "*Face used for Gnus bookmarks."
2178 (defface anything-bmkext-man
2179 '((t (:foreground
"Orange4")))
2180 "*Face used for Woman/man bookmarks."
2183 (defface anything-bmkext-region
2184 '((t (:foreground
"Indianred2")))
2185 "*Face used for region bookmarks."
2188 (defface anything-bmkext-no--file
2189 '((t (:foreground
"grey")))
2190 "*Face used for non--file bookmarks."
2193 (defface anything-bmkext-file
2194 '((t (:foreground
"Deepskyblue2")))
2195 "*Face used for non--file bookmarks."
2198 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
2199 "Face for su/sudo bookmarks."
2202 (defvar anything-c-bookmarks-face1
'anything-dir-heading
)
2203 (defvar anything-c-bookmarks-face2
'anything-file-name
)
2204 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
2206 (defvar anything-c-source-bookmarks-local
2207 '((name .
"Bookmarks-Local")
2209 (require 'bookmark
)))
2211 (candidates .
(lambda ()
2212 (let (lis-all lis-loc
)
2213 (setq lis-all
(bookmark-all-names))
2214 (setq lis-loc
(loop for i in lis-all
2215 if
(and (not (string-match "^(ssh)" i
))
2216 (not (string-match "^(su)" i
)))
2218 (sort lis-loc
'string-lessp
))))
2219 (candidate-transformer anything-c-highlight-bookmark
)
2221 "See (info \"(emacs)Bookmarks\").")
2222 ;; (anything 'anything-c-source-bookmarks-local)
2224 ;;; Sources to filter bookmark-extensions bookmarks.
2225 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
2228 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
2229 "Return a filtered `bookmark-alist' sorted alphabetically."
2231 with alist
= (if args
2232 (apply #'(lambda (x) (funcall fn x
)) args
)
2237 finally return
(sort sa
'string-lessp
)))
2240 (defvar anything-c-source-bookmark-regions
2241 '((name .
"Bookmark Regions")
2243 (require 'bookmark-extensions
)
2244 (bookmark-maybe-load-default-file)))
2245 (candidates . anything-c-bookmark-region-setup-alist
)
2246 (candidate-transformer anything-c-highlight-bookmark
)
2247 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2249 ;; (anything 'anything-c-source-bookmark-regions)
2251 (defun anything-c-bookmark-region-setup-alist ()
2252 "Specialized filter function for bookmarks regions."
2253 (anything-c-bmkext-filter-setup-alist 'bmkext-region-alist-only
))
2256 (defvar anything-c-source-bookmark-w3m
2257 '((name .
"Bookmark W3m")
2259 (require 'bookmark-extensions
)
2260 (bookmark-maybe-load-default-file)))
2261 (candidates . anything-c-bookmark-w3m-setup-alist
)
2262 (candidate-transformer anything-c-highlight-bookmark
)
2263 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2265 ;; (anything 'anything-c-source-bookmark-w3m)
2267 (defun anything-c-bookmark-w3m-setup-alist ()
2268 "Specialized filter function for bookmarks w3m."
2269 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
2272 (defvar anything-c-source-bookmark-man
2273 '((name .
"Bookmark Woman&Man")
2275 (require 'bookmark-extensions
)
2276 (bookmark-maybe-load-default-file)))
2277 (candidates . anything-c-bookmark-man-setup-alist
)
2278 (candidate-transformer anything-c-highlight-bookmark
)
2279 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2281 ;; (anything 'anything-c-source-bookmark-man)
2283 (defun anything-c-bookmark-man-setup-alist ()
2284 "Specialized filter function for bookmarks w3m."
2285 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
2286 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
2289 (defvar anything-c-source-bookmark-gnus
2290 '((name .
"Bookmark Gnus")
2292 (require 'bookmark-extensions
)
2293 (bookmark-maybe-load-default-file)))
2294 (candidates . anything-c-bookmark-gnus-setup-alist
)
2295 (candidate-transformer anything-c-highlight-bookmark
)
2296 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2298 ;; (anything 'anything-c-source-bookmark-gnus)
2300 (defun anything-c-bookmark-gnus-setup-alist ()
2301 "Specialized filter function for bookmarks gnus."
2302 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
2305 (defvar anything-c-source-bookmark-info
2306 '((name .
"Bookmark Info")
2308 (require 'bookmark-extensions
)
2309 (bookmark-maybe-load-default-file)))
2310 (candidates . anything-c-bookmark-info-setup-alist
)
2311 (candidate-transformer anything-c-highlight-bookmark
)
2312 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2314 ;; (anything 'anything-c-source-bookmark-info)
2316 (defun anything-c-bookmark-info-setup-alist ()
2317 "Specialized filter function for bookmarks info."
2318 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
2320 ;; Local Files&directories
2321 (defvar anything-c-source-bookmark-files
&dirs
2322 '((name .
"Bookmark Files&Directories")
2324 (require 'bookmark-extensions
)
2325 (bookmark-maybe-load-default-file)))
2326 (candidates . anything-c-bookmark-local-files-setup-alist
)
2327 (candidate-transformer anything-c-highlight-bookmark
)
2328 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2330 ;; (anything 'anything-c-source-bookmark-files&dirs)
2332 (defun anything-c-bookmark-local-files-setup-alist ()
2333 "Specialized filter function for bookmarks locals files."
2334 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
2336 ;; Su Files&directories
2337 (defun anything-c-highlight-bmkext-su (bmk)
2338 (if (bmkext-root-or-sudo-logged-p)
2339 (anything-c-highlight-bookmark bmk
)
2340 (anything-c-highlight-not-logged bmk
)))
2342 (defvar anything-c-source-bookmark-su-files
&dirs
2343 '((name .
"Bookmark Root-Files&Directories")
2345 (require 'bookmark-extensions
)
2346 (bookmark-maybe-load-default-file)))
2347 (candidates . anything-c-bookmark-su-files-setup-alist
)
2348 (candidate-transformer anything-c-highlight-bmkext-su
)
2349 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2351 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
2353 (defun anything-c-bookmark-su-files-setup-alist ()
2354 "Specialized filter function for bookmarks su/sudo files."
2356 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
2358 for isfile
= (bookmark-get-filename i
)
2359 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
2361 (string-match tramp-file-name-regexp isfile
)))
2362 for issu
= (and istramp
2363 (string-match bmkext-su-or-sudo-regexp isfile
))
2367 ;; Ssh Files&directories
2368 (defvar anything-c-source-bookmark-ssh-files
&dirs
2369 '((name .
"Bookmark Ssh-Files&Directories")
2371 (require 'bookmark-extensions
)
2372 (bookmark-maybe-load-default-file)))
2373 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
2374 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2376 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
2378 (defun anything-c-bookmark-ssh-files-setup-alist ()
2379 "Specialized filter function for bookmarks ssh files."
2381 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
2383 for isfile
= (bookmark-get-filename i
)
2384 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
2386 (string-match tramp-file-name-regexp isfile
)))
2387 for isssh
= (and istramp
2388 (string-match "/ssh:" isfile
))
2393 ;; All bookmark-extensions sources.
2394 (defun anything-bookmark-ext ()
2395 "Preconfigured anything for bookmark-extensions sources.
2396 See: <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>."
2398 (anything '(anything-c-source-bookmark-files&dirs
2399 anything-c-source-bookmark-w3m
2400 anything-c-source-bookmark-gnus
2401 anything-c-source-bookmark-info
2402 anything-c-source-bookmark-man
2403 anything-c-source-bookmark-regions
2404 anything-c-source-bookmark-su-files
&dirs
2405 anything-c-source-bookmark-ssh-files
&dirs
)))
2408 ;; Firefox bookmarks
2409 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
2410 ;; (only for firefox versions >=3)
2411 ;; To achieve that, open about:config in firefox and double click on this line to enable value
2413 ;; user_pref("browser.bookmarks.autoExportHTML", false);
2414 ;; You should have now:
2415 ;; user_pref("browser.bookmarks.autoExportHTML", true);
2417 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
2418 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
2420 (defun anything-get-firefox-user-init-dir ()
2421 "Guess the default Firefox user directory name."
2422 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
2423 (moz-user-dir (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
2424 (goto-char (point-min))
2425 (when (search-forward "Path=" nil t
)
2426 (buffer-substring-no-properties (point) (point-at-eol))))))
2427 (file-name-as-directory (concat moz-dir moz-user-dir
))))
2429 (defun anything-guess-firefox-bookmark-file ()
2430 "Return the path of the Firefox bookmarks file."
2431 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
2433 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
2434 "Parse html bookmark FILE and return an alist with (title . url) as elements."
2435 (let (bookmarks-alist url title
)
2437 (insert-file-contents file
)
2438 (goto-char (point-min))
2441 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
2443 (when (re-search-forward url-regexp nil t
)
2444 (setq url
(concat "\"" (match-string 0))))
2446 (when (re-search-forward bmk-regexp nil t
)
2447 (setq title
(match-string 1)))
2448 (push (cons title url
) bookmarks-alist
))))
2449 (nreverse bookmarks-alist
)))
2452 (defvar anything-c-firefox-bookmarks-alist nil
)
2453 (defvar anything-c-source-firefox-bookmarks
2454 '((name .
"Firefox Bookmarks")
2456 (setq anything-c-firefox-bookmarks-alist
2457 (anything-html-bookmarks-to-alist
2458 (anything-guess-firefox-bookmark-file)
2459 anything-firefox-bookmark-url-regexp
2460 anything-firefox-bookmarks-regexp
))))
2461 (candidates .
(lambda ()
2463 anything-c-firefox-bookmarks-alist
)))
2464 (candidate-transformer anything-c-highlight-firefox-bookmarks
)
2465 (action .
(("Browse Url" .
(lambda (candidate)
2467 (anything-c-firefox-bookmarks-get-value candidate
))))
2468 ("Browse Url Firefox" .
(lambda (candidate)
2470 (anything-c-firefox-bookmarks-get-value candidate
))))
2471 ("Copy Url" .
(lambda (elm)
2472 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
2474 ;; (anything 'anything-c-source-firefox-bookmarks)
2476 (defun anything-c-firefox-bookmarks-get-value (elm)
2477 (replace-regexp-in-string "\"" ""
2479 anything-c-firefox-bookmarks-alist
))))
2482 (defun anything-c-highlight-firefox-bookmarks (books)
2483 (loop for i in books
2484 collect
(propertize i
2485 'face
'((:foreground
"YellowGreen"))
2486 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
2489 (eval-when-compile (require 'w3m-bookmark nil t
))
2490 (unless (and (require 'w3m nil t
)
2491 (require 'w3m-bookmark nil t
))
2492 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html"))
2495 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
2496 "Face for w3m bookmarks" :group
'anything
)
2498 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
2499 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
2500 (defvar anything-c-w3m-bookmarks-alist nil
)
2501 (defvar anything-c-source-w3m-bookmarks
2502 '((name .
"W3m Bookmarks")
2504 (setq anything-c-w3m-bookmarks-alist
2505 (anything-html-bookmarks-to-alist
2507 anything-w3m-bookmark-url-regexp
2508 anything-w3m-bookmarks-regexp
))))
2509 (candidates .
(lambda ()
2511 anything-c-w3m-bookmarks-alist
)))
2512 (candidate-transformer anything-c-highlight-w3m-bookmarks
)
2513 (action .
(("Browse Url" .
(lambda (candidate)
2514 (anything-c-w3m-browse-bookmark candidate
)))
2515 ("Copy Url" .
(lambda (elm)
2516 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
2517 ("Browse Url Firefox" .
(lambda (candidate)
2518 (anything-c-w3m-browse-bookmark candidate t
)))
2519 ("Delete Bookmark" .
(lambda (candidate)
2520 (anything-c-w3m-delete-bookmark candidate
)))
2521 ("Rename Bookmark" .
(lambda (candidate)
2522 (anything-c-w3m-rename-bookmark candidate
)))))
2523 (persistent-action .
(lambda (candidate)
2524 (if current-prefix-arg
2525 (anything-c-w3m-browse-bookmark candidate t
)
2526 (anything-c-w3m-browse-bookmark candidate nil t
))))))
2528 ;; (anything 'anything-c-source-w3m-bookmarks)
2530 (defun anything-c-w3m-bookmarks-get-value (elm)
2531 (replace-regexp-in-string "\"" ""
2533 anything-c-w3m-bookmarks-alist
))))
2536 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
2537 (let* ((fn (if use-firefox
2540 (arg (and (eq fn
'w3m-browse-url
)
2542 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
2545 (defun anything-c-highlight-w3m-bookmarks (books)
2546 (loop for i in books
2547 collect
(propertize i
2548 'face
'anything-w3m-bookmarks-face
2549 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
2552 (defun anything-c-w3m-delete-bookmark (elm)
2554 (find-file-literally w3m-bookmark-file
)
2555 (goto-char (point-min))
2556 (when (re-search-forward elm nil t
)
2558 (delete-region (point)
2559 (line-end-position))
2560 (delete-blank-lines))
2561 (save-buffer (current-buffer))
2562 (kill-buffer (current-buffer))))
2564 (defun anything-c-w3m-rename-bookmark (elm)
2565 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
2566 (new-title (read-string "NewTitle: " old-title
)))
2568 (find-file-literally w3m-bookmark-file
)
2569 (goto-char (point-min))
2570 (when (re-search-forward (concat elm
"<") nil t
)
2571 (goto-char (1- (point)))
2572 (delete-backward-char (length old-title
))
2574 (save-buffer (current-buffer))
2575 (kill-buffer (current-buffer)))))
2578 ;;; Elisp library scan
2579 (defvar anything-c-source-elisp-library-scan
2580 '((name .
"Elisp libraries (Scan)")
2581 (init .
(anything-c-elisp-library-scan-init))
2582 (candidates-in-buffer)
2583 (action ("Find library" .
(lambda (candidate)
2584 (find-file (find-library-name candidate
))))
2585 ("Find library other window" .
(lambda (candidate)
2586 (find-file-other-window (find-library-name candidate
))))
2587 ("Load library" .
(lambda (candidate)
2588 (load-library candidate
))))))
2589 ;; (anything 'anything-c-source-elisp-library-scan)
2591 (defun anything-c-elisp-library-scan-init ()
2592 "Init anything buffer status."
2593 (let ((anything-buffer (anything-candidate-buffer 'global
))
2594 (library-list (anything-c-elisp-library-scan-list)))
2595 (with-current-buffer anything-buffer
2596 (dolist (library library-list
)
2597 (insert (format "%s\n" library
))))))
2599 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
2600 "Do completion for file names passed to `locate-file'.
2601 DIRS is directory to search path.
2602 STRING is string to match."
2603 ;; Use `load-path' as path when ignore `dirs'.
2604 (or dirs
(setq dirs load-path
))
2605 ;; Init with blank when ignore `string'.
2606 (or string
(setq string
""))
2607 ;; Get library list.
2608 (let ((string-dir (file-name-directory string
))
2609 ;; File regexp that suffix match `load-file-rep-suffixes'.
2610 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
2615 (setq dir default-directory
))
2617 (setq dir
(expand-file-name string-dir dir
)))
2618 (when (file-directory-p dir
)
2619 (dolist (file (file-name-all-completions
2620 (file-name-nondirectory string
) dir
))
2621 ;; Suffixes match `load-file-rep-suffixes'.
2622 (setq name
(if string-dir
(concat string-dir file
) file
))
2623 (if (string-match match-regexp name
)
2624 (add-to-list 'names name
)))))
2629 (defvar anything-c-imenu-delimiter
" / ")
2631 (defvar anything-c-imenu-index-filter nil
)
2632 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
2634 (defvar anything-c-cached-imenu-alist nil
)
2635 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
2637 (defvar anything-c-cached-imenu-candidates nil
)
2638 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
2640 (defvar anything-c-cached-imenu-tick nil
)
2641 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
2643 (eval-when-compile (require 'imenu
))
2644 (setq imenu-auto-rescan t
)
2646 (defun anything-imenu-create-candidates (entry)
2647 "Create candidates with ENTRY."
2648 (if (listp (cdr entry
))
2649 (mapcan (lambda (sub)
2650 (if (consp (cdr sub
))
2653 (concat (car entry
) anything-c-imenu-delimiter subentry
))
2654 (anything-imenu-create-candidates sub
))
2655 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
2659 (defvar anything-c-source-imenu
2661 (candidates . anything-c-imenu-candidates
)
2662 (persistent-action .
(lambda (elm)
2663 (anything-c-imenu-default-action elm
)
2664 (unless (fboundp 'semantic-imenu-tag-overlay
)
2665 (anything-match-line-color-current-line))))
2666 (action . anything-c-imenu-default-action
))
2667 "See (info \"(emacs)Imenu\")")
2669 ;; (anything 'anything-c-source-imenu)
2671 (defun anything-c-imenu-candidates ()
2672 (with-current-buffer anything-current-buffer
2673 (let ((tick (buffer-modified-tick)))
2674 (if (eq anything-c-cached-imenu-tick tick
)
2675 anything-c-cached-imenu-candidates
2676 (setq imenu--index-alist nil
)
2677 (setq anything-c-cached-imenu-tick tick
2678 anything-c-cached-imenu-candidates
2681 'anything-imenu-create-candidates
2682 (setq anything-c-cached-imenu-alist
2683 (let ((index (imenu--make-index-alist)))
2684 (if anything-c-imenu-index-filter
2685 (funcall anything-c-imenu-index-filter index
)
2688 (setq anything-c-cached-imenu-candidates
2689 (mapcar #'(lambda (x)
2693 anything-c-cached-imenu-candidates
))))))
2695 (setq imenu-default-goto-function
'imenu-default-goto-function
)
2696 (defun anything-c-imenu-default-action (elm)
2697 "The default action for `anything-c-source-imenu'."
2698 (let ((path (split-string elm anything-c-imenu-delimiter
))
2699 (alist anything-c-cached-imenu-alist
))
2700 (if (> (length path
) 1)
2702 (setq alist
(assoc (car path
) alist
))
2703 (setq elm
(cadr path
))
2704 (imenu (assoc elm alist
)))
2705 (imenu (assoc elm alist
)))))
2708 (defvar anything-c-ctags-modes
2709 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
2710 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
2711 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
2713 (defun anything-c-source-ctags-init ()
2714 (when (and buffer-file-name
2715 (memq major-mode anything-c-ctags-modes
)
2716 (anything-current-buffer-is-modified))
2717 (with-current-buffer (anything-candidate-buffer 'local
)
2718 (call-process-shell-command
2719 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
2720 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name
)
2721 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
2722 nil
(current-buffer))
2723 (goto-char (point-min))
2725 (delete-region (point-min) (point))
2726 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
2727 for lineno-start
= (point)
2728 for lineno
= (buffer-substring lineno-start
(1- (search-forward "," (point-at-eol) t
)))
2731 (insert (format "%5s:" lineno
))
2732 (search-forward "\177" (point-at-eol) t
)
2733 (delete-region (1- (point)) (point-at-eol))
2734 (forward-line 1)))))
2736 (defvar anything-c-source-ctags
2737 '((name .
"Exuberant ctags")
2738 (init . anything-c-source-ctags-init
)
2739 (candidates-in-buffer)
2742 "Needs Exuberant Ctags.
2744 http://ctags.sourceforge.net/")
2745 ;; (anything 'anything-c-source-ctags)
2748 (defvar anything-semantic-candidates nil
)
2749 (eval-when-compile (require 'semantic nil t
))
2750 (defun anything-semantic-construct-candidates (tags depth
)
2751 (when (require 'semantic nil t
)
2753 (mapcar (lambda (tag)
2755 (let ((type (semantic-tag-type tag
))
2756 (class (semantic-tag-class tag
)))
2757 (if (or (and (stringp type
)
2758 (or (string= type
"class")
2759 (string= type
"namespace")))
2760 (eq class
'function
)
2761 (eq class
'variable
))
2762 (cons (cons (concat (make-string (* depth
2) ?\s
)
2763 (semantic-format-tag-summarize tag nil t
)) tag
)
2764 (anything-semantic-construct-candidates (semantic-tag-components tag
)
2768 (defun anything-semantic-default-action (candidate)
2769 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
2770 (semantic-go-to-tag tag
)))
2772 (defvar anything-c-source-semantic
2773 '((name .
"Semantic Tags")
2775 (setq anything-semantic-candidates
2777 (anything-semantic-construct-candidates (semantic-fetch-tags) 0)
2779 (candidates .
(lambda ()
2780 (if anything-semantic-candidates
2781 (mapcar 'car anything-semantic-candidates
))))
2782 (persistent-action .
(lambda (elm)
2783 (anything-semantic-default-action elm
)
2784 (anything-match-line-color-current-line)))
2785 (action . anything-semantic-default-action
)
2786 "Needs semantic in CEDET.
2788 http://cedet.sourceforge.net/semantic.shtml
2789 http://cedet.sourceforge.net/"))
2791 ;; (anything 'anything-c-source-semantic)
2793 ;;; Function is called by
2794 (defvar anything-c-source-simple-call-tree-functions-callers
2795 '((name .
"Function is called by")
2796 (init . anything-c-simple-call-tree-functions-callers-init
)
2798 (candidates-in-buffer))
2799 "Needs simple-call-tree.el.
2800 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
2802 (defun anything-c-simple-call-tree-functions-callers-init ()
2803 (require 'simple-call-tree
)
2805 (when (anything-current-buffer-is-modified)
2806 (simple-call-tree-analyze)
2807 (let ((list (simple-call-tree-invert simple-call-tree-alist
)))
2808 (with-current-buffer (anything-candidate-buffer 'local
)
2809 (dolist (entry list
)
2810 (let ((callers (mapconcat #'identity
(cdr entry
) ", ")))
2811 (insert (car entry
) " is called by "
2812 (if (string= callers
"")
2816 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
2819 (defvar anything-c-source-simple-call-tree-callers-functions
2820 '((name .
"Function calls")
2821 (init . anything-c-simple-call-tree-callers-functions-init
)
2823 (candidates-in-buffer))
2824 "Needs simple-call-tree.el.
2825 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
2827 (defun anything-c-simple-call-tree-callers-functions-init ()
2828 (require 'simple-call-tree
)
2830 (when (anything-current-buffer-is-modified)
2831 (simple-call-tree-analyze)
2832 (let ((list simple-call-tree-alist
))
2833 (with-current-buffer (anything-candidate-buffer 'local
)
2834 (dolist (entry list
)
2835 (let ((functions (mapconcat #'identity
(cdr entry
) ", ")))
2836 (insert (car entry
) " calls "
2837 (if (string= functions
"")
2842 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
2844 ;;; Commands/Options with doc
2845 (defvar anything-c-auto-document-data nil
)
2846 (make-variable-buffer-local 'anything-c-auto-document-data
)
2847 (defvar anything-c-source-commands-and-options-in-file
2848 '((name .
"Commands/Options in file")
2850 .
(lambda (x) (format "Commands/Options in %s"
2851 (buffer-local-value 'buffer-file-name anything-current-buffer
))))
2852 (candidates . anything-command-and-options-candidates
)
2855 "List Commands and Options with doc. It needs auto-document.el .
2857 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
2859 (eval-when-compile (require 'auto-document nil t
))
2860 (defun anything-command-and-options-candidates ()
2861 (with-current-buffer anything-current-buffer
2862 (when (and (require 'auto-document nil t
)
2863 (eq major-mode
'emacs-lisp-mode
)
2864 (or (anything-current-buffer-is-modified)
2865 (not anything-c-auto-document-data
)))
2866 (or imenu--index-alist
(imenu--make-index-alist t
))
2867 (setq anything-c-auto-document-data
2868 (destructuring-bind (commands options
)
2869 (adoc-construct anything-current-buffer
)
2871 (loop for
(command . doc
) in commands
2872 for cmdname
= (symbol-name command
)
2874 (cons (format "Command: %s\n %s"
2875 (propertize cmdname
'face font-lock-function-name-face
)
2876 (adoc-first-line doc
))
2877 (assoc cmdname imenu--index-alist
)))
2878 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
2879 for
(option doc default
) in options
2880 for optname
= (symbol-name option
)
2882 (cons (format "Option: %s\n %s\n default = %s"
2883 (propertize optname
'face font-lock-variable-name-face
)
2884 (adoc-first-line doc
)
2885 (adoc-prin1-to-string default
))
2888 anything-c-auto-document-data
))
2890 ;; (anything 'anything-c-source-commands-and-options-in-file)
2892 ;;;; <Color and Face>
2894 (defvar anything-c-source-customize-face
2895 '((name .
"Customize Face")
2897 (unless (anything-candidate-buffer)
2898 (save-window-excursion (list-faces-display))
2899 (anything-candidate-buffer (get-buffer "*Faces*")))))
2900 (candidates-in-buffer)
2901 (get-line . buffer-substring
)
2902 (action .
(lambda (line)
2903 (customize-face (intern (car (split-string line
))))))
2904 (requires-pattern .
3))
2905 "See (info \"(emacs)Faces\")")
2906 ;; (anything 'anything-c-source-customize-face)
2909 (defvar anything-c-source-colors
2911 (init .
(lambda () (unless (anything-candidate-buffer)
2912 (save-window-excursion (list-colors-display))
2913 (anything-candidate-buffer (get-buffer "*Colors*")))))
2914 (candidates-in-buffer)
2915 (get-line . buffer-substring
)
2916 (action ("Copy Name" .
(lambda (candidate)
2917 (kill-new (anything-c-colors-get-name candidate
))))
2918 ("Copy RGB" .
(lambda (candidate)
2919 (kill-new (anything-c-colors-get-rgb candidate
))))
2920 ("Insert Name" .
(lambda (candidate)
2921 (with-current-buffer anything-current-buffer
2922 (insert (anything-c-colors-get-name candidate
)))))
2923 ("Insert RGB" .
(lambda (candidate)
2924 (with-current-buffer anything-current-buffer
2925 (insert (anything-c-colors-get-rgb candidate
))))))))
2926 ;; (anything 'anything-c-source-colors)
2928 (defun anything-c-colors-get-name (candidate)
2930 (replace-regexp-in-string
2933 (insert (capitalize candidate
))
2934 (goto-char (point-min))
2935 (search-forward-regexp "\\s-\\{2,\\}")
2939 (defun anything-c-colors-get-rgb (candidate)
2941 (replace-regexp-in-string
2944 (insert (capitalize candidate
))
2945 (goto-char (point-max))
2946 (search-backward-regexp "\\s-\\{2,\\}")
2947 (kill-region (point) (point-min))
2950 ;;;; <Search Engine>
2951 ;;; Tracker desktop search
2952 (defvar anything-c-source-tracker-search
2953 '((name .
"Tracker Search")
2954 (candidates .
(lambda ()
2955 (start-process "tracker-search-process" nil
2959 (requires-pattern .
3)
2961 "Source for retrieving files matching the current input pattern
2962 with the tracker desktop search.")
2963 ;; (anything 'anything-c-source-tracker-search)
2965 ;;; Spotlight (MacOS X desktop search)
2966 (defvar anything-c-source-mac-spotlight
2968 (candidates .
(lambda ()
2969 (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
2971 (requires-pattern .
3)
2973 "Source for retrieving files via Spotlight's command line
2975 ;; (anything 'anything-c-source-mac-spotlight)
2980 (defvar anything-c-source-kill-ring
2981 '((name .
"Kill Ring")
2982 (init .
(lambda () (anything-attrset 'last-command last-command
)))
2983 (candidates .
(lambda ()
2984 (loop for kill in kill-ring
2985 unless
(or (< (length kill
) anything-kill-ring-threshold
)
2986 (string-match "^[\\s\\t]+$" kill
))
2988 (action . anything-c-kill-ring-action
)
2992 "Source for browse and insert contents of kill-ring.")
2994 (defun anything-c-kill-ring-action (str)
2995 "Insert STR in `kill-ring' and set STR to the head.
2996 If this action is executed just after `yank', replace with STR as yanked string."
2997 (setq kill-ring
(delete str kill-ring
))
2998 (if (not (eq (anything-attr 'last-command
) 'yank
))
2999 (insert-for-yank str
)
3001 (let ((inhibit-read-only t
)
3002 (before (< (point) (mark t
))))
3004 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
3005 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
3006 (setq yank-undo-function nil
)
3007 (set-marker (mark-marker) (point) (current-buffer))
3008 (insert-for-yank str
)
3009 ;; Set the window start back where it was in the yank command,
3011 (set-window-start (selected-window) yank-window-start t
)
3013 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3014 ;; It is cleaner to avoid activation, even though the command
3015 ;; loop would deactivate the mark because we inserted text.
3016 (goto-char (prog1 (mark t
)
3017 (set-marker (mark-marker) (point) (current-buffer)))))))
3020 ;; (anything 'anything-c-source-kill-ring)
3023 ;; DO NOT include these sources in `anything-sources' use
3024 ;; the commands `anything-mark-ring' and `anything-global-mark-ring' instead.
3026 (defun anything-c-source-mark-ring-candidates ()
3027 (flet ((get-marks (pos)
3031 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
3032 (when (string= "" line
)
3033 (setq line
"<EMPTY LINE>"))
3034 (format "%7d: %s" (line-number-at-pos) line
)))))
3035 (with-current-buffer anything-current-buffer
3037 with marks
= (cons (mark-marker) mark-ring
)
3040 for f
= (get-marks i
)
3041 if
(not (member f recip
))
3044 finally
(return (reverse recip
))))))
3046 (defvar anything-mark-ring-cache nil
)
3047 (defvar anything-c-source-mark-ring
3048 '((name .
"mark-ring")
3050 (setq anything-mark-ring-cache
3051 (anything-c-source-mark-ring-candidates))))
3052 (candidates .
(lambda ()
3053 (anything-aif anything-mark-ring-cache
3055 (action .
(("Goto line" .
(lambda (candidate)
3056 (anything-goto-line (string-to-number candidate
))))))
3057 (persistent-action .
(lambda (candidate)
3058 (anything-goto-line (string-to-number candidate
))
3059 (anything-match-line-color-current-line)))))
3061 ;; (anything 'anything-c-source-mark-ring)
3063 (defun anything-mark-ring ()
3064 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3066 (anything 'anything-c-source-mark-ring
))
3068 ;;; Global-mark-ring
3069 (defvar anything-c-source-global-mark-ring
3070 '((name .
"global-mark-ring")
3071 (candidates . anything-c-source-global-mark-ring-candidates
)
3072 (action .
(("Goto line" .
(lambda (candidate)
3073 (let ((items (split-string candidate
":")))
3074 (switch-to-buffer (second items
))
3075 (anything-goto-line (string-to-number (car items
))))))))
3076 (persistent-action .
(lambda (candidate)
3077 (let ((items (split-string candidate
":")))
3078 (switch-to-buffer (second items
))
3079 (anything-goto-line (string-to-number (car items
)))
3080 (anything-match-line-color-current-line))))))
3082 (defun anything-c-source-global-mark-ring-candidates ()
3084 (with-current-buffer (marker-buffer m
)
3088 (if (string= "" line
)
3089 (setq line
"<EMPTY LINE>")
3090 (setq line
(car (split-string (thing-at-point 'line
) "[\n\r]"))))
3091 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m
) line
)))))
3093 with marks
= global-mark-ring
3096 if
(not (or (string-match "^ " (format "%s" (marker-buffer i
)))
3097 (null (marker-buffer i
))))
3099 if
(and a
(not (member a recip
)))
3102 finally
(return (reverse recip
)))))
3104 ;; (anything 'anything-c-source-global-mark-ring)
3106 (defun anything-global-mark-ring ()
3107 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
3109 (anything 'anything-c-source-global-mark-ring
))
3112 ;;; Insert from register
3113 (defvar anything-c-source-register
3114 '((name .
"Registers")
3115 (candidates . anything-c-register-candidates
)
3116 (action-transformer . anything-c-register-action-transformer
)
3119 "See (info \"(emacs)Registers\")")
3121 (defun anything-c-register-candidates ()
3122 "Collecting register contents and appropriate commands."
3123 (loop for
(char . val
) in register-alist
3124 for key
= (single-key-description char
)
3125 for string-actions
= (cond
3127 (list (int-to-string val
)
3129 'increment-register
))
3131 (let ((buf (marker-buffer val
)))
3133 (list "a marker in no buffer")
3135 "a buffer position:"
3138 (int-to-string (marker-position val
)))
3140 'insert-register
))))
3141 ((and (consp val
) (window-configuration-p (car val
)))
3142 (list "window configuration."
3144 ((and (consp val
) (frame-configuration-p (car val
)))
3145 (list "frame configuration."
3147 ((and (consp val
) (eq (car val
) 'file
))
3148 (list (concat "file:"
3149 (prin1-to-string (cdr val
))
3152 ((and (consp val
) (eq (car val
) 'file-query
))
3153 (list (concat "file:a file-query reference: file "
3156 (int-to-string (car (cdr (cdr val
))))
3160 (let ((lines (format "%4d" (length val
))))
3161 (list (format "%s: %s\n" lines
3162 (truncate-string-to-width
3163 (mapconcat 'identity
(list (car val
))
3164 ;; (mapconcat (lambda (y) y) val
3165 "^J") (- (window-width) 15)))
3168 (list ;; without properties
3169 (substring-no-properties val
)
3172 'prepend-to-register
))
3175 collect
(cons (format "register %3s: %s" key
(car string-actions
))
3176 (cons char
(cdr string-actions
)))))
3178 (defun anything-c-register-action-transformer (actions register-and-functions
)
3179 "Decide actions by the contents of register."
3180 (loop with func-actions
=
3183 (lambda (c) (insert-register (car c
))))
3185 "Jump to Register" .
3186 (lambda (c) (jump-to-register (car c
))))
3188 "Append Region to Register" .
3189 (lambda (c) (append-to-register (car c
) (region-beginning) (region-end))))
3190 (prepend-to-register
3191 "Prepend Region to Register" .
3192 (lambda (c) (prepend-to-register (car c
) (region-beginning) (region-end))))
3194 "Increment Prefix Arg to Register" .
3195 (lambda (c) (increment-register anything-current-prefix-arg
(car c
)))))
3196 for func in
(cdr register-and-functions
)
3197 for cell
= (assq func func-actions
)
3199 collect
(cdr cell
)))
3201 ;; (anything 'anything-c-source-register)
3203 ;;;; <Headline Extraction>
3204 (defvar anything-c-source-fixme
3205 '((name .
"TODO/FIXME/DRY comments")
3206 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
3209 "Show TODO/FIXME/DRY comments in current file.")
3210 ;; (anything 'anything-c-source-fixme)
3212 (defvar anything-c-source-rd-headline
3213 '((name .
"RD HeadLine")
3214 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
3215 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
3221 http://en.wikipedia.org/wiki/Ruby_Document_format")
3222 ;; (anything 'anything-c-source-rd-headline)
3224 (defvar anything-c-source-oddmuse-headline
3225 '((name .
"Oddmuse HeadLine")
3226 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
3227 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
3228 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
3231 "Show Oddmuse headlines, such as EmacsWiki.")
3232 ;; (anything 'anything-c-source-oddmuse-headline)
3234 (defvar anything-c-source-emacs-source-defun
3235 '((name .
"Emacs Source DEFUN")
3236 (headline .
"DEFUN\\|DEFVAR")
3237 (condition .
(string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name
""))))
3238 "Show DEFUN/DEFVAR in Emacs C source file.")
3239 ;; (anything 'anything-c-source-emacs-source-defun)
3241 (defvar anything-c-source-emacs-lisp-expectations
3242 '((name .
"Emacs Lisp Expectations")
3243 (headline .
"(desc[ ]\\|(expectations")
3244 (condition .
(eq major-mode
'emacs-lisp-mode
)))
3245 "Show descriptions (desc) in Emacs Lisp Expectations.
3247 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
3248 ;; (anything 'anything-c-source-emacs-lisp-expectations)
3250 (defvar anything-c-source-emacs-lisp-toplevels
3251 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
3252 (headline .
"^(\\|(@\\*\\|^;;;;")
3253 (get-line . buffer-substring
)
3254 (condition .
(eq major-mode
'emacs-lisp-mode
))
3256 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
3257 linkd.el is optional because linkd stars are extracted by regexp.
3258 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
3259 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
3261 (defvar anything-c-source-org-headline
3262 '((name .
"Org HeadLine")
3264 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3265 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3266 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3267 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3268 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3269 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3270 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3271 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3272 (condition .
(eq major-mode
'org-mode
))
3275 (persistent-action .
(lambda (elm)
3276 (anything-c-action-line-goto elm
)
3279 .
(lambda (actions candidate
)
3280 '(("Go to Line" . anything-c-action-line-goto
)
3281 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline
)))))
3282 "Show Org headlines.
3283 org-mode is very very much extended text-mode/outline-mode.
3285 See (find-library \"org.el\")
3286 See http://orgmode.org for the latest version.")
3288 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
3291 (anything-goto-line (car lineno-and-content
))
3292 (and (looking-at "^\\*+ \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3293 (org-make-link-string (concat "*" (match-string 1)))))))
3295 ;; (anything 'anything-c-source-org-headline)
3297 ;;; Anything yaoddmuse
3298 ;; Be sure to have yaoddmuse.el installed
3299 ;; install-elisp may be required if you want to install elisp file from here.
3300 (defvar anything-yaoddmuse-use-cache-file nil
)
3301 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
3302 (defvar anything-c-yaoddmuse-ew-cache nil
)
3303 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
3304 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
3305 (candidates .
(lambda ()
3306 (if anything-yaoddmuse-use-cache-file
3309 (unless anything-c-yaoddmuse-ew-cache
3310 (load anything-c-yaoddmuse-cache-file
)
3311 (setq anything-c-yaoddmuse-ew-cache
3312 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
3313 anything-c-yaoddmuse-ew-cache
)
3315 (yaoddmuse-update-pagename t
)
3316 (gethash "EmacsWiki" yaoddmuse-pages-hash
))))
3317 (action .
(("Edit page" .
(lambda (candidate)
3318 (yaoddmuse-edit "EmacsWiki" candidate
)))
3319 ("Browse page" .
(lambda (candidate)
3320 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
3321 ("Browse page other window" .
(lambda (candidate)
3323 (split-window-vertically))
3324 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
3325 ("Browse diff" .
(lambda (candidate)
3326 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
3327 ("Copy URL" .
(lambda (candidate)
3328 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
3329 (message "Have copy page %s's URL to yank." candidate
)))
3330 ("Create page" .
(lambda (candidate)
3331 (yaoddmuse-edit "EmacsWiki" anything-input
)))
3332 ("Update cache" .
(lambda (candidate)
3333 (if anything-yaoddmuse-use-cache-file
3335 (anything-yaoddmuse-cache-pages t
)
3336 (setq anything-c-yaoddmuse-ew-cache
3337 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
3338 (yaoddmuse-update-pagename))))))
3339 (action-transformer anything-c-yaoddmuse-action-transformer
)))
3341 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
3343 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
3344 '((name .
"Yaoddmuse Post library (EmacsWiki)")
3345 (init .
(anything-yaoddmuse-init))
3346 (candidates-in-buffer)
3347 (action .
(("Post library and Browse" .
(lambda (candidate)
3348 (yaoddmuse-post-file (find-library-name candidate
)
3350 (file-name-nondirectory (find-library-name candidate
))
3352 ("Post library" .
(lambda (candidate)
3353 (yaoddmuse-post-file (find-library-name candidate
)
3355 (file-name-nondirectory (find-library-name candidate
)))))))))
3357 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
3359 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
3360 "Allow the use of `install-elisp' only on elisp files."
3361 (if (string-match "\.el$" candidate
)
3362 (append actions
'(("Install Elisp" .
(lambda (elm)
3363 (install-elisp-from-emacswiki elm
)))))
3366 (defun anything-yaoddmuse-cache-pages (&optional load
)
3367 "Fetch the list of files on emacswiki and create cache file.
3368 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
3370 (yaoddmuse-update-pagename)
3372 (find-file anything-c-yaoddmuse-cache-file
)
3374 (insert "(puthash \"EmacsWiki\" '(")
3375 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
3377 (insert (concat "(\"" (car i
) "\") ")))
3378 (insert ") yaoddmuse-pages-hash)\n")
3380 (kill-buffer (current-buffer))
3381 (when (or current-prefix-arg
3383 (load anything-c-yaoddmuse-cache-file
))))
3385 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
3386 "Edit or View EmacsWiki page."
3388 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
3390 (defun anything-yaoddmuse-emacswiki-post-library ()
3391 "Post library to EmacsWiki."
3393 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
3395 (defun anything-yaoddmuse-init ()
3396 "Init anything buffer status."
3397 (let ((anything-buffer (anything-candidate-buffer 'global
))
3398 (library-list (yaoddmuse-get-library-list)))
3399 (with-current-buffer anything-buffer
3400 ;; Insert library name.
3401 (dolist (library library-list
)
3402 (insert (format "%s\n" library
)))
3404 (sort-lines nil
(point-min) (point-max)))))
3407 (defvar anything-c-source-eev-anchor
3408 '((name .
"Anchors")
3410 (setq anything-c-eev-anchor-buffer
3412 (candidates .
(lambda ()
3415 (with-current-buffer anything-c-eev-anchor-buffer
3416 (goto-char (point-min))
3418 (while (re-search-forward (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
3419 (push (match-string-no-properties 1) anchors
))
3420 (setq anchors
(reverse anchors
)))))
3422 (persistent-action .
(lambda (item)
3424 (anything-match-line-color-current-line)))
3425 (action .
(("Goto link" .
(lambda (item)
3428 ;; (anything 'anything-c-source-eev-anchor)
3432 (defvar anything-c-source-picklist
3433 '((name .
"Picklist")
3434 (candidates .
(lambda () (mapcar 'car picklist-list
)))
3436 ;; (anything 'anything-c-source-picklist)
3439 (defun anything-c-bbdb-candidates ()
3440 "Return a list of all names in the bbdb database. The format
3441 is \"Firstname Lastname\"."
3442 (mapcar (lambda (bbdb-record)
3443 (replace-regexp-in-string
3445 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
3448 (defun anything-c-bbdb-create-contact (actions candidate
)
3449 "Action transformer that returns only an entry to add the
3450 current `anything-pattern' as new contact. All other actions are
3452 (if (string= candidate
"*Add to contacts*")
3453 '(("Add to contacts" .
(lambda (actions)
3454 (bbdb-create-internal
3455 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
3456 (read-from-minibuffer "Company: ")
3457 (read-from-minibuffer "Email: ")
3460 (read-from-minibuffer "Note: ")))))
3463 (defun anything-c-bbdb-get-record (candidate)
3464 "Return record that match CANDIDATE."
3465 (bbdb candidate nil
)
3466 (set-buffer "*BBDB*")
3467 (bbdb-current-record))
3469 (defvar anything-c-bbdb-name nil
3470 "Only for internal use.")
3472 (defvar anything-c-source-bbdb
3474 (candidates . anything-c-bbdb-candidates
)
3475 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
3476 ("View person's data" . anything-c-bbdb-view-person-action
))
3477 (filtered-candidate-transformer .
(lambda (candidates source
)
3478 (setq anything-c-bbdb-name anything-pattern
)
3479 (if (not candidates
)
3480 (list "*Add to contacts*")
3482 (action-transformer .
(lambda (actions candidate
)
3483 (anything-c-bbdb-create-contact actions candidate
)))))
3484 ;; (anything 'anything-c-source-bbdb)
3486 (defun anything-c-bbdb-view-person-action (candidate)
3487 "View BBDB data of single CANDIDATE or marked candidates."
3488 (anything-aif (anything-marked-candidates)
3489 (let ((bbdb-append-records (length it
)))
3491 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
3492 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
3494 (defun anything-c-bbdb-collect-mail-addresses ()
3495 "Return a list of all mail addresses of records in bbdb buffer."
3496 (with-current-buffer bbdb-buffer-name
3497 (loop for i in bbdb-records
3498 if
(bbdb-record-net (car i
))
3499 collect
(bbdb-dwim-net-address (car i
)))))
3501 (defun anything-c-bbdb-compose-mail (candidate)
3502 "Compose a mail with all records of bbdb buffer."
3503 (anything-c-bbdb-view-person-action candidate
)
3504 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
3505 (address-str (mapconcat 'identity address-list
",\n ")))
3506 (compose-mail address-str
)))
3508 ;;; Evaluation Result
3509 (defvar anything-c-source-evaluation-result
3510 '((name .
"Evaluation Result")
3512 (filtered-candidate-transformer .
(lambda (candidates source
)
3516 (eval (read anything-pattern
)))
3518 (action ("Do Nothing" . ignore
))))
3519 ;; (anything 'anything-c-source-evaluation-result)
3521 ;;; Calculation Result
3522 (defvar anything-c-source-calculation-result
3523 '((name .
"Calculation Result")
3525 (filtered-candidate-transformer .
(lambda (candidates source
)
3528 (calc-eval anything-pattern
)
3530 (action ("Copy result to kill-ring" . kill-new
))))
3531 ;; (anything 'anything-c-source-calculation-result)
3533 ;;; Google Suggestions
3534 (defvar anything-gg-sug-lgh-flag
0)
3535 (defun anything-c-google-suggest-fetch (input)
3536 "Fetch suggestions for INPUT from XML buffer.
3537 Return an alist with elements like (data . number_results)."
3538 (let ((request (concat anything-c-google-suggest-url
3539 (url-hexify-string input
))))
3542 with result-alist
= (xml-get-children
3543 (car (xml-parse-region (point-min) (point-max)))
3544 'CompleteSuggestion
)
3545 for i in result-alist
3546 for data
= (cdr (caadr (assoc 'suggestion i
)))
3547 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
3548 for ldata
= (length data
)
3550 (when (> ldata anything-gg-sug-lgh-flag
)
3551 (setq anything-gg-sug-lgh-flag ldata
))
3552 collect
(cons data nqueries
) into cont
3553 finally return cont
)))
3554 (if anything-google-suggest-use-curl-p
3556 (call-process "curl" nil t nil request
)
3558 (with-current-buffer
3559 (url-retrieve-synchronously request
)
3563 (defun anything-c-google-suggest-set-candidates ()
3564 "Set candidates with result and number of google results found."
3565 (let ((suggestions (anything-c-google-suggest-fetch anything-input
)))
3566 (setq suggestions
(loop for i in suggestions
3567 for interval
= (- anything-gg-sug-lgh-flag
(length (car i
)))
3568 for elm
= (concat (car i
)
3569 (make-string (+ 2 interval
) ?
)
3570 "(" (cdr i
) " results)")
3571 collect
(cons elm
(car i
))))
3572 (if (some (lambda (data) (equal (cdr data
) anything-input
)) suggestions
)
3574 ;; if there is no suggestion exactly matching the input then
3575 ;; prepend a Search on Google item to the list
3578 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
3579 anything-input
))))))
3582 (defun anything-c-google-suggest-action (candidate)
3583 "Default action to jump to a google suggested candidate."
3584 (browse-url (concat anything-c-google-suggest-search-url
3585 (url-hexify-string candidate
))))
3588 (defvar anything-c-source-google-suggest
3589 '((name .
"Google Suggest")
3590 (candidates . anything-c-google-suggest-set-candidates
)
3591 (action .
(("Google Search" . anything-c-google-suggest-action
)))
3593 (requires-pattern .
3)
3596 ;; (anything 'anything-c-source-google-suggest)
3598 ;;; Yahoo suggestions
3600 (defun anything-c-yahoo-suggest-fetch (input)
3601 "Fetch Yahoo suggestions for INPUT from XML buffer.
3602 Return an alist with elements like (data . number_results)."
3603 (let ((request (concat anything-c-yahoo-suggest-url
3604 (url-hexify-string input
))))
3607 with result-alist
= (xml-get-children
3608 (car (xml-parse-region (point-min) (point-max)))
3610 for i in result-alist
3611 collect
(caddr i
))))
3612 (with-current-buffer
3613 (url-retrieve-synchronously request
)
3616 (defun anything-c-yahoo-suggest-set-candidates ()
3617 "Set candidates with Yahoo results found."
3618 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
3622 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
3623 anything-input
))))))
3625 (defun anything-c-yahoo-suggest-action (candidate)
3626 "Default action to jump to a Yahoo suggested candidate."
3627 (browse-url (concat anything-c-yahoo-suggest-search-url
3628 (url-hexify-string candidate
))))
3630 (defvar anything-c-source-yahoo-suggest
3631 '((name .
"Yahoo Suggest")
3632 (candidates . anything-c-yahoo-suggest-set-candidates
)
3633 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
3635 (requires-pattern .
3)
3638 ;; (anything 'anything-c-source-yahoo-suggest)
3641 ;;; Need external program surfraw.
3642 ;;; http://surfraw.alioth.debian.org/
3644 (defvar anything-c-surfraw-favorites
'("google" "wikipedia"
3646 "codesearch" "genpkg"
3649 "All elements of this list will appear first in results.")
3650 (defvar anything-c-surfraw-use-only-favorites nil
3651 "If non-nil use only `anything-c-surfraw-favorites'.")
3654 (defun anything-c-build-elvi-alist ()
3656 A list of search engines."
3659 (call-process "surfraw" nil t nil
3661 (split-string (buffer-string) "\n")))
3664 (loop for i in elvi-list
3666 (setq line
(split-string i
))
3667 collect
(cons (first line
) (mapconcat #'(lambda (x) x
) (cdr line
) " "))))))
3670 (defun anything-c-surfraw-sort-elvi (&optional only-fav
)
3671 "Sort elvi alist according to `anything-c-surfraw-favorites'."
3672 (let* ((elvi-alist (anything-c-build-elvi-alist))
3673 (fav-alist (loop for j in anything-c-surfraw-favorites
3674 collect
(assoc j elvi-alist
)))
3675 (rest-elvi (loop for i in elvi-alist
3676 if
(not (member i fav-alist
))
3680 (append fav-alist rest-elvi
))))
3682 (defun anything-c-surfraw-get-url (engine pattern
)
3683 "Get search url from `engine' for `anything-pattern'."
3685 (apply #'call-process
"surfraw" nil t nil
3692 (defvar anything-c-surfraw-elvi nil
)
3693 (defvar anything-c-surfraw-cache nil
)
3694 (defvar anything-c-source-surfraw
3695 '((name .
"Surfraw")
3697 (unless anything-c-surfraw-cache
3698 (setq anything-c-surfraw-elvi
(anything-c-surfraw-sort-elvi
3699 anything-c-surfraw-use-only-favorites
))
3700 (setq anything-c-surfraw-cache
3701 (loop for i in anything-c-surfraw-elvi
3703 collect
(car i
))))))
3704 (candidates .
(lambda ()
3705 (loop for i in anything-c-surfraw-cache
3706 for s
= (anything-c-surfraw-get-url i anything-pattern
)
3707 collect
(concat (propertize i
3708 'face
'((:foreground
"green"))
3709 'help-echo
(cdr (assoc i anything-c-surfraw-elvi
)))
3710 ">>>" (replace-regexp-in-string "\n" "" s
)))))
3711 (action .
(("Browse" .
(lambda (candidate)
3712 (let ((url (second (split-string candidate
">>>"))))
3714 ("Browse firefox" .
(lambda (candidate)
3715 (let ((url (second (split-string candidate
">>>"))))
3716 (browse-url-firefox url t
))))))
3718 (requires-pattern .
3)
3722 ;; (anything 'anything-c-source-surfraw)
3726 (defun anything-emms-stream-edit-bookmark (elm)
3727 "Change the information of current emms-stream bookmark from anything."
3729 (let* ((cur-buf anything-current-buffer
)
3730 (bookmark (assoc elm emms-stream-list
))
3731 (name (read-from-minibuffer "Description: "
3733 (url (read-from-minibuffer "URL: "
3735 (fd (read-from-minibuffer "Feed Descriptor: "
3736 (int-to-string (nth 2 bookmark
))))
3737 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
3738 (format "%s" (car (last bookmark
))))))
3741 (when (re-search-forward (concat "^" name
) nil t
)
3743 (emms-stream-delete-bookmark)
3744 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
3745 (emms-stream-save-bookmarks-file)
3747 (switch-to-buffer cur-buf
)))))
3749 (defun anything-emms-stream-delete-bookmark (elm)
3750 "Delete an emms-stream bookmark from anything."
3752 (let* ((cur-buf anything-current-buffer
)
3753 (bookmark (assoc elm emms-stream-list
))
3754 (name (nth 0 bookmark
)))
3757 (when (re-search-forward (concat "^" name
) nil t
)
3759 (emms-stream-delete-bookmark)
3760 (emms-stream-save-bookmarks-file)
3762 (switch-to-buffer cur-buf
)))))
3764 (defvar anything-c-source-emms-streams
3765 '((name .
"Emms Streams")
3767 (emms-stream-init)))
3768 (candidates .
(lambda ()
3769 (mapcar 'car emms-stream-list
)))
3770 (action .
(("Play" .
(lambda (elm)
3771 (let* ((stream (assoc elm emms-stream-list
))
3772 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
3773 (url (second stream
)))
3775 ("Delete" . anything-emms-stream-delete-bookmark
)
3776 ("Edit" . anything-emms-stream-edit-bookmark
)))
3777 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
3778 ;; (anything 'anything-c-source-emms-streams)
3780 ;; Don't forget to set `emms-source-file-default-directory'
3781 (defvar anything-c-source-emms-dired
3782 '((name .
"Music Directory")
3783 (candidates .
(lambda ()
3784 (cddr (directory-files emms-source-file-default-directory
))))
3786 (("Play Directory" .
(lambda (item)
3787 (emms-play-directory
3790 emms-source-file-default-directory
))))
3791 ("Open dired in file's directory" .
(lambda (item)
3792 (anything-c-open-dired
3795 emms-source-file-default-directory
))))))
3796 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
3797 ;; (anything 'anything-c-source-emms-dired)
3799 ;;; Jabber Contacts (jabber.el)
3800 (defun anything-c-jabber-online-contacts ()
3801 "List online Jabber contacts."
3804 (dolist (item (jabber-concat-rosters) jids
)
3805 (when (get item
'connected
)
3806 (push (if (get item
'name
)
3807 (cons (get item
'name
) item
)
3808 (cons (symbol-name item
) item
)) jids
))))))
3810 (defvar anything-c-source-jabber-contacts
3811 '((name .
"Jabber Contacts")
3812 (init .
(lambda () (require 'jabber
)))
3813 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
3814 (action .
(lambda (x)
3816 (jabber-read-account)
3818 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
3819 ;; (anything 'anything-c-source-jabber-contacts)
3823 (defvar anything-source-select-buffer
"*anything source select*")
3824 (defvar anything-c-source-call-source
3825 `((name .
"Call anything source")
3826 (candidate-number-limit)
3827 (candidates .
(lambda ()
3828 (loop for vname in
(all-completions "anything-c-source-" obarray
)
3829 for var
= (intern vname
)
3830 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
3831 if name collect
(cons (format "%s `%s'"
3832 name
(propertize vname
'face
'font-lock-variable-name-face
))
3834 (action .
(("Invoke anything with selected source" .
3836 (setq anything-candidate-number-limit
9999)
3837 (anything candidate nil nil nil nil
3838 anything-source-select-buffer
)))
3839 ("Describe variable" . describe-variable
)))
3840 (persistent-action . describe-variable
)))
3841 ;; (anything 'anything-c-source-call-source)
3843 (defun anything-call-source ()
3844 "Call anything source."
3846 (anything 'anything-c-source-call-source nil nil nil nil
3847 anything-source-select-buffer
))
3849 (defun anything-call-source-from-anything ()
3850 "Call anything source within `anything' session."
3852 (setq anything-input-idle-delay
0)
3853 (anything-set-sources '(anything-c-source-call-source)))
3856 (defvar anything-c-source-occur
3859 (setq anything-c-source-occur-current-buffer
3861 (candidates .
(lambda ()
3862 (setq anything-occur-buf
(get-buffer-create "*Anything Occur*"))
3863 (with-current-buffer anything-occur-buf
3865 (let ((count (occur-engine anything-pattern
3866 (list anything-c-source-occur-current-buffer
) anything-occur-buf
3867 list-matching-lines-default-context-lines nil
3868 list-matching-lines-buffer-name-face
3869 nil list-matching-lines-face
3870 (not (eq occur-excluded-properties t
)))))
3872 (let ((lines (split-string (buffer-string) "\n" t
)))
3874 (action .
(("Goto line" .
(lambda (candidate)
3875 (anything-goto-line (string-to-number candidate
) anything-c-source-occur-current-buffer
)))))
3876 (requires-pattern .
1)
3878 ;; (anything 'anything-c-source-occur)
3880 ;; Do many actions for input
3881 (defvar anything-c-source-create
3885 (candidate-number-limit .
9999)
3886 (action-transformer . anything-create--actions
))
3887 "Do many create actions from `anything-pattern'.
3888 See also `anything-create--actions'.")
3889 ;; (anything 'anything-c-source-create)
3891 (defun anything-create-from-anything ()
3892 "Run `anything-create' from `anything' as a fallback."
3894 (anything-run-after-quit 'anything-create nil anything-pattern
))
3896 (defun anything-create (&optional string initial-input
)
3897 "Do many create actions from STRING.
3898 See also `anything-create--actions'."
3900 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
3901 (anything '(((name .
"Anything Create")
3902 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
3903 (candidates . anything-create--actions
)
3904 (candidate-number-limit .
9999)
3905 (action .
(lambda (func) (funcall func string
)))))))
3907 (defun anything-create--actions (&rest ignored
)
3908 "Default actions for `anything-create' / `anything-c-source-create'."
3910 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
3911 (append anything-create--actions-private
3912 '(("find-file" . find-file
)
3913 ("find-file other window" . find-file-other-window
)
3914 ("New buffer" . switch-to-buffer
)
3915 ("New buffer other window" . switch-to-buffer-other-window
)
3916 ("Bookmark Set" . bookmark-set
)
3918 (lambda (x) (set-register (read-char "Register: ") x
)))
3919 ("Insert Linkd star" . linkd-insert-star
)
3920 ("Insert Linkd Tag" . linkd-insert-tag
)
3921 ("Insert Linkd Link" . linkd-insert-link
)
3922 ("Insert Linkd Lisp" . linkd-insert-lisp
)
3923 ("Insert Linkd Wiki" . linkd-insert-wiki
)
3924 ("Google Search" . google
)))))
3926 ;; Minibuffer History
3927 (defvar anything-c-source-minibuffer-history
3928 '((name .
"Minibuffer History")
3929 (header-name .
(lambda (name) (format "%s (%s)" name minibuffer-history-variable
)))
3930 (candidates .
(lambda () (let ((history (symbol-value minibuffer-history-variable
)))
3931 (if (consp (car history
))
3932 (mapcar 'prin1-to-string history
)
3936 ;; (anything 'anything-c-source-minibuffer-history)
3939 (defvar anything-c-source-elscreen
3940 '((name .
"Elscreen")
3941 (candidates .
(lambda ()
3942 (if (cdr (elscreen-get-screen-to-name-alist))
3944 (loop for sname in
(elscreen-get-screen-to-name-alist)
3945 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
3946 finally
(return lst
))
3947 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
3948 (action .
(("Change Screen".
3950 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
3953 (anything-aif (anything-marked-candidates)
3955 (elscreen-kill-internal (- (aref i
1) (aref "0" 0))))
3956 (elscreen-kill-internal (- (aref candidate
1) (aref "0" 0))))))
3959 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
3960 (elscreen-kill-others)))))))
3961 ;; (anything 'anything-c-source-elscreen)
3966 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
3967 "Top command (batch mode). %s is replaced with `frame-width'.")
3968 (defvar anything-c-source-top
3969 '((name .
"Top (Press C-c C-u to refresh)")
3970 (init . anything-c-top-init
)
3971 (candidates-in-buffer)
3972 (display-to-real . anything-c-top-display-to-real
)
3974 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
3975 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
3976 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
3977 ;; (anything 'anything-c-source-top)
3979 (defun anything-c-top-sh (cmd)
3980 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
3982 (defun anything-c-top-init ()
3983 (with-current-buffer (anything-candidate-buffer 'global
)
3984 (call-process-shell-command
3985 (format anything-c-top-command
3986 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
3987 nil
(current-buffer))))
3989 (defun anything-c-top-display-to-real (line)
3990 (car (split-string line
)))
3992 (defun anything-c-top-refresh ()
3994 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
3995 (anything-c-top-init))
3998 (defun anything-top ()
3999 "Preconfigured `anything' for top command."
4001 (let ((anything-samewindow t
)
4002 (anything-enable-shortcuts)
4003 (anything-display-function 'anything-default-display-buffer
)
4004 (anything-map (copy-keymap anything-map
))
4005 (anything-candidate-number-limit 9999))
4006 (define-key anything-map
"\C-c\C-u" 'anything-c-top-refresh
)
4007 (save-window-excursion
4008 (delete-other-windows)
4009 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
4012 (defvar anything-c-source-absolute-time-timers
4013 '((name .
"Absolute Time Timers")
4014 (candidates . timer-list
)
4016 ;; (anything 'anything-c-source-absolute-time-timers)
4018 (defvar anything-c-source-idle-time-timers
4019 '((name .
"Idle Time Timers")
4020 (candidates . timer-idle-list
)
4022 ;; (anything 'anything-c-source-idle-time-timers)
4024 (defun anything-c-timer-real-to-display (timer)
4025 (destructuring-bind (_ t1 t2 t3 _ func args
&rest rest
) (append timer nil
)
4027 (format-time-string "%m/%d %T" (list t1 t2 t3
))
4029 (mapconcat 'prin1-to-string
(aref timer
6) " "))))
4031 ;;; X RandR resolution change
4032 ;;; FIXME I do not care multi-display.
4033 (defvar anything-c-xrandr-output
"VGA")
4034 (defvar anything-c-xrandr-screen
"0")
4035 (defvar anything-c-source-xrandr-change-resolution
4036 '((name .
"Change Resolution")
4040 (call-process "xrandr" nil
(current-buffer) nil
4041 "--screen" anything-c-xrandr-screen
"-q")
4043 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
4044 collect
(match-string 1)))))
4046 ("Change Resolution" .
(lambda (mode)
4047 (call-process "xrandr" nil nil nil
4048 "--screen" anything-c-xrandr-screen
4049 "--output" anything-c-xrandr-output
4051 ;; (anything 'anything-c-source-xrandr-change-resolution)
4054 (defun anything-c-persistent-xfont-action (elm)
4055 "Show current font temporarily"
4056 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
4059 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
4060 (set-frame-font current-font
))))
4062 (defvar anything-c-xfonts-cache nil
)
4063 (defvar anything-c-source-xfonts
4064 '((name .
"X Fonts")
4066 (unless anything-c-xfonts-cache
4067 (setq anything-c-xfonts-cache
4068 (x-list-fonts "*")))))
4069 (candidates . anything-c-xfonts-cache
)
4070 (action .
(("Copy to kill ring" .
(lambda (elm)
4072 ("Set Font" .
(lambda (elm)
4074 (set-frame-font elm
'keep-size
)
4075 (message "New font have been copied to kill ring")))))
4076 (persistent-action . anything-c-persistent-xfont-action
)))
4078 (defun anything-select-xfont ()
4079 "Preconfigured `anything' to select Xfont."
4081 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
4083 ;; (anything 'anything-c-source-xfonts)
4085 ;; Source for Debian/Ubuntu users
4086 (defvar anything-c-source-apt
4088 (init . anything-c-apt-init
)
4089 (candidates-in-buffer)
4090 (display-to-real . anything-c-apt-display-to-real
)
4091 (candidate-number-limit .
9999)
4093 ("Show package description" . anything-c-apt-cache-show
)
4094 ("Install package" . anything-c-apt-install
))))
4095 ;; (anything 'anything-c-source-apt)
4097 (defvar anything-c-apt-query
"emacs")
4098 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
4099 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
4100 (defvar anything-c-apt-install-command
"xterm -e sudo apt-get install '%s' &")
4102 (defun anything-apt (query)
4103 "The `anything' frontend of APT package manager."
4104 (interactive "sAPT search: ")
4105 (let ((anything-c-apt-query query
))
4106 (anything 'anything-c-source-apt
)))
4108 (defun anything-c-apt-init ()
4109 (with-current-buffer
4110 (anything-candidate-buffer
4111 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query
)))
4112 (call-process-shell-command
4113 (format anything-c-apt-search-command anything-c-apt-query
)
4114 nil
(current-buffer))))
4115 (defun anything-c-apt-display-to-real (line)
4116 (car (split-string line
" - ")))
4118 (defun anything-c-shell-command-if-needed (command)
4119 (interactive "sShell command: ")
4120 (if (get-buffer command
) ; if the buffer already exists
4121 (switch-to-buffer command
) ; then just switch to it
4122 (switch-to-buffer command
) ; otherwise create it
4123 (insert (shell-command-to-string command
))))
4125 (defun anything-c-apt-cache-show (package)
4126 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package
)))
4127 (defun anything-c-apt-install (package)
4128 (shell-command (format anything-c-apt-install-command package
) "*apt install*"))
4130 ;; (anything-c-apt-install "jed")
4131 ;; Sources for gentoo users
4133 (defvar anything-gentoo-prefered-shell
'eshell
4134 "Your favorite shell to run emerge command.")
4136 (defvar anything-c-gentoo-use-flags nil
)
4137 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
4138 (defvar anything-c-cache-gentoo nil
)
4139 (defvar anything-c-cache-world nil
)
4140 (defvar anything-c-source-gentoo
4141 '((name .
"Portage sources")
4143 (get-buffer-create anything-c-gentoo-buffer
)
4144 (unless anything-c-cache-gentoo
4145 (anything-c-gentoo-setup-cache))
4146 (unless anything-c-cache-world
4147 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
4148 (anything-c-gentoo-init-list)))
4149 (candidates-in-buffer)
4151 (candidate-transformer anything-c-highlight-world
)
4152 (action .
(("Show package" .
(lambda (elm)
4153 (anything-c-gentoo-eshell-action elm
"eix")))
4154 ("Show history" .
(lambda (elm)
4155 (if (member elm anything-c-cache-world
)
4156 (anything-c-gentoo-eshell-action elm
"genlop -qe")
4157 (message "No infos on packages not yet installed"))))
4158 ("Copy in kill-ring" . kill-new
)
4159 ("insert at point" . insert
)
4160 ("Browse HomePage" .
(lambda (elm)
4161 (browse-url (car (anything-c-gentoo-get-url elm
)))))
4162 ("Show extra infos" .
(lambda (elm)
4163 (if (member elm anything-c-cache-world
)
4164 (anything-c-gentoo-eshell-action elm
"genlop -qi")
4165 (message "No infos on packages not yet installed"))))
4166 ("Show use flags" .
(lambda (elm)
4167 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
4168 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
4169 (font-lock-mode 1)))
4170 ("Run emerge pretend" .
(lambda (elm)
4171 (anything-c-gentoo-eshell-action elm
"emerge -p")))
4172 ("Emerge" .
(lambda (elm)
4173 (anything-gentoo-install elm
:action
'install
)))
4174 ("Unmerge" .
(lambda (elm)
4175 (anything-gentoo-install elm
:action
'uninstall
)))
4176 ("Show dependencies" .
(lambda (elm)
4177 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
4178 ("Show related files" .
(lambda (elm)
4179 (anything-c-gentoo-default-action elm
"equery" "files")))
4180 ("Refresh" .
(lambda (elm)
4181 (anything-c-gentoo-setup-cache)
4182 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
4184 ;; (anything 'anything-c-source-gentoo)
4186 (defun* anything-gentoo-install
(candidate &key action
)
4187 (funcall anything-gentoo-prefered-shell
)
4188 (let ((command (case action
4189 ('install
"*sudo emerge -av ")
4190 ('uninstall
"*sudo emerge -avC ")
4191 (t (error "Unknow action")))))
4192 (if (anything-marked-candidates)
4193 (let ((elms (mapconcat 'identity
(anything-marked-candidates) " ")))
4194 (insert (concat command elms
)))
4195 (insert (concat command candidate
)))))
4198 (defun anything-c-gentoo-default-action (elm command
&rest args
)
4199 "Gentoo default action that use `anything-c-gentoo-buffer'."
4200 (if (member elm anything-c-cache-world
)
4202 (switch-to-buffer anything-c-gentoo-buffer
)
4204 (let ((com-list (append args
(list elm
))))
4205 (apply #'call-process command nil t nil
4207 (message "No infos on packages not yet installed")))
4209 (defvar anything-c-source-use-flags
4210 '((name .
"Use Flags")
4212 (unless anything-c-gentoo-use-flags
4213 (anything-c-gentoo-setup-use-flags-cache))
4214 (anything-c-gentoo-get-use)))
4215 (candidates-in-buffer)
4217 (candidate-transformer anything-c-highlight-local-use
)
4218 (action .
(("Description"
4220 (switch-to-buffer anything-c-gentoo-buffer
)
4222 (apply #'call-process
"euse" nil t nil
4225 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
4226 (font-lock-mode 1)))
4229 (anything-c-gentoo-eshell-action elm
"*sudo euse -E")))
4232 (anything-c-gentoo-eshell-action elm
"*sudo euse -D")))
4235 (anything-c-gentoo-eshell-action elm
"*sudo euse -P")))
4236 ("Show which dep use this flag"
4238 (switch-to-buffer anything-c-gentoo-buffer
)
4240 (apply #'call-process
"equery" nil t nil
4246 ;; (anything 'anything-c-source-use-flags)
4248 (defun anything-c-gentoo-init-list ()
4249 "Initialize buffer with all packages in Portage."
4250 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
4251 (buf (anything-candidate-buffer 'portage-buf
)))
4252 (with-current-buffer buf
4253 (dolist (i anything-c-cache-gentoo
)
4254 (insert (concat i
"\n"))))))
4256 (defun anything-c-gentoo-setup-cache ()
4257 "Set up `anything-c-cache-gentoo'"
4258 (setq anything-c-cache-gentoo
4259 (split-string (with-temp-buffer
4260 (call-process "eix" nil t nil
4264 (defun anything-c-gentoo-eshell-action (elm command
)
4265 (when (get-buffer "*EShell Command Output*")
4266 (kill-buffer "*EShell Command Output*"))
4267 (message "Wait searching...")
4268 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
4269 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
4271 (save-window-excursion
4272 (pop-to-buffer "*scratch*")
4273 (eshell-command (format "%s %s" command elm
)))
4274 (pop-to-buffer "*EShell Command Output*"))
4275 (eshell-command (format "%s %s" command elm
)))))
4277 (defun anything-c-gentoo-get-use ()
4278 "Initialize buffer with all use flags."
4279 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
4280 (buf (anything-candidate-buffer 'use-buf
)))
4281 (with-current-buffer buf
4282 (dolist (i anything-c-gentoo-use-flags
)
4283 (insert (concat i
"\n"))))))
4286 (defun anything-c-gentoo-setup-use-flags-cache ()
4287 "Setup `anything-c-gentoo-use-flags'"
4288 (setq anything-c-gentoo-use-flags
4289 (split-string (with-temp-buffer
4290 (call-process "eix" nil t nil
4291 "--print-all-useflags")
4294 (defun anything-c-gentoo-get-url (elm)
4295 "Return a list of urls from eix output."
4296 (split-string (eshell-command-result
4297 (format "eix %s | grep Homepage | awk '{print $2}'" elm
))))
4299 (defun anything-c-gentoo-get-world ()
4300 "Return list of all installed package on your system."
4301 (split-string (with-temp-buffer
4302 (call-process "qlist" nil t nil
4306 (defun anything-c-gentoo-get-local-use ()
4307 (split-string (with-temp-buffer
4308 (call-process "portageq" nil t nil
4313 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
4314 "Face for anything-gentoo installed packages."
4315 :group
'traverse-faces
)
4317 (defun anything-c-highlight-world (eix)
4318 "Highlight all installed package."
4320 if
(member i anything-c-cache-world
)
4321 collect
(propertize i
'face
'anything-gentoo-match-face
)
4325 (defun anything-c-highlight-local-use (use-flags)
4326 (let ((local-uses (anything-c-gentoo-get-local-use)))
4327 (loop for i in use-flags
4328 if
(member i local-uses
)
4329 collect
(propertize i
'face
'anything-gentoo-match-face
)
4333 (defvar anything-c-source-emacs-process
4334 '((name .
"Emacs Process")
4335 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
4336 (action ("Kill Process" .
(lambda (elm) (delete-process (get-process elm
)))))))
4338 ;; (anything 'anything-c-source-emacs-process)
4341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4343 (defvar anything-c-external-commands-list nil
4344 "A list of all external commands the user can execute. If this
4345 variable is not set by the user, it will be calculated
4348 (defun anything-c-external-commands-list-1 ()
4349 "Returns a list of all external commands the user can execute.
4351 If `anything-c-external-commands-list' is non-nil it will
4352 return its contents. Else it calculates all external commands
4353 and sets `anything-c-external-commands-list'.
4355 The code is ripped out of `eshell-complete-commands-list'."
4356 (if anything-c-external-commands-list
4357 anything-c-external-commands-list
4358 (setq anything-c-external-commands-list
4359 (let* ((paths (split-string (getenv "PATH") path-separator
))
4360 (cwd (file-name-as-directory
4361 (expand-file-name default-directory
)))
4362 (path "") (comps-in-path ())
4363 (file "") (filepath "") (completions ()))
4364 ;; Go thru each path in the search path, finding completions.
4366 (setq path
(file-name-as-directory
4367 (expand-file-name (or (car paths
) ".")))
4369 (and (file-accessible-directory-p path
)
4370 (file-name-all-completions "" path
)))
4371 ;; Go thru each completion found, to see whether it should be
4372 ;; used, e.g. see if it's executable.
4373 (while comps-in-path
4374 (setq file
(car comps-in-path
)
4375 filepath
(concat path file
))
4376 (if (and (not (member file completions
))
4377 (or (string-equal path cwd
)
4378 (not (file-directory-p filepath
)))
4379 (file-executable-p filepath
))
4380 (setq completions
(cons file completions
)))
4381 (setq comps-in-path
(cdr comps-in-path
)))
4382 (setq paths
(cdr paths
)))
4385 (defun anything-c-file-buffers (filename)
4386 "Returns a list of buffer names corresponding to FILENAME."
4387 (let ((name (expand-file-name filename
))
4389 (dolist (buf (buffer-list) buf-list
)
4390 (let ((bfn (buffer-file-name buf
)))
4391 (when (and bfn
(string= name bfn
))
4392 (push (buffer-name buf
) buf-list
))))))
4394 (defun anything-c-delete-file (file)
4395 "Delete the given file after querying the user.
4396 Ask to kill buffers associated with that file, too."
4397 (let ((buffers (anything-c-file-buffers file
)))
4398 (dired-delete-file file
'dired-recursive-deletes
)
4400 (dolist (buf buffers
)
4401 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
4402 (kill-buffer buf
))))))
4404 (defun anything-c-open-file-externally (file)
4405 "Open FILE with an external tool. Query the user which tool to use."
4406 (start-process "anything-c-open-file-externally"
4408 (completing-read "Program: "
4409 (anything-c-external-commands-list-1))
4412 (defun w32-shell-execute-open-file (file)
4413 (interactive "fOpen file:")
4415 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
4417 (replace-regexp-in-string ; strip cygdrive paths
4418 "/cygdrive/\\(.\\)" "\\1:" file nil nil
) nil t
))))
4419 (defun anything-c-open-file-with-default-tool (file)
4420 "Open FILE with the default tool on this platform."
4421 (if (eq system-type
'windows-nt
)
4422 (w32-shell-execute-open-file file
)
4423 (start-process "anything-c-open-file-with-default-tool"
4425 (cond ((eq system-type
'gnu
/linux
)
4427 ((or (eq system-type
'darwin
) ;; Mac OS X
4428 (eq system-type
'macos
)) ;; Mac OS 9
4432 (defun anything-c-open-dired (file)
4433 "Opens a dired buffer in FILE's directory. If FILE is a
4434 directory, open this directory."
4435 (if (file-directory-p file
)
4437 (dired (file-name-directory file
))
4438 (dired-goto-file file
)))
4440 (defun anything-c-display-to-real-line (candidate)
4441 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
4442 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
4443 (error "Line number not found")))
4445 (defun anything-c-action-line-goto (lineno-and-content)
4446 (apply #'anything-goto-file-line
(anything-attr 'target-file
)
4447 (append lineno-and-content
4448 (list (if (and (anything-attr-defined 'target-file
)
4449 (not anything-in-persistent-action
))
4450 'find-file-other-window
4453 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
4454 (apply #'anything-goto-file-line file-line-content
))
4457 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
4460 (if (not (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
))
4461 (error "Filename and line number not found")
4462 (let ((filename (match-string 1 candidate
))
4463 (lineno (match-string 2 candidate
))
4464 (content (match-string 3 candidate
)))
4465 (cons (format "%s:%s\n %s"
4466 (propertize filename
'face compilation-info-face
)
4467 (propertize lineno
'face compilation-line-face
)
4469 (list (expand-file-name
4471 (anything-aif (anything-attr 'default-directory
)
4472 (if (functionp it
) (funcall it
) it
)
4473 (and (anything-candidate-buffer)
4476 (anything-candidate-buffer)))))
4477 (string-to-number lineno
) content
)))))
4480 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
4481 (anything-aif (anything-attr 'before-jump-hook
)
4483 (when file
(funcall find-file-function file
))
4484 (if (anything-attr-defined 'adjust
)
4485 (anything-c-goto-line-with-adjustment lineno content
)
4486 (anything-goto-line lineno
))
4487 (unless (anything-attr-defined 'recenter
)
4488 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
4489 (anything-aif (anything-attr 'after-jump-hook
)
4491 (when anything-in-persistent-action
4492 (anything-match-line-color-current-line)))
4494 (defun anything-find-file-as-root (candidate)
4495 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
4497 ;; borrowed from etags.el
4498 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
4499 (defun anything-c-goto-line-with-adjustment (line line-content
)
4502 ;; This constant is 1/2 the initial search window.
4503 ;; There is no sense in making it too small,
4504 ;; since just going around the loop once probably
4505 ;; costs about as much as searching 2000 chars.
4508 pat
(concat (if (eq selective-display t
)
4509 "\\(^\\|\^m\\) *" "^ *") ;allow indent
4510 (regexp-quote line-content
)))
4511 ;; If no char pos was given, try the given line number.
4512 (setq startpos
(progn (anything-goto-line line
) (point)))
4513 (or startpos
(setq startpos
(point-min)))
4514 ;; First see if the tag is right at the specified location.
4515 (goto-char startpos
)
4516 (setq found
(looking-at pat
))
4517 (while (and (not found
)
4519 (goto-char (- startpos offset
))
4522 (re-search-forward pat
(+ startpos offset
) t
)
4523 offset
(* 3 offset
))) ; expand search window
4525 (re-search-forward pat nil t
)
4526 (error "not found")))
4527 ;; Position point at the right place
4528 ;; if the search string matched an extra Ctrl-m at the beginning.
4529 (and (eq selective-display t
)
4532 (beginning-of-line))
4534 (anything-document-attribute 'default-directory
"type . file-line"
4535 "`default-directory' to interpret file.")
4536 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
4537 "Function to call before jumping to the target location.")
4538 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
4539 "Function to call after jumping to the target location.")
4540 (anything-document-attribute 'adjust
"type . file-line"
4541 "Search around line matching line contents.")
4542 (anything-document-attribute 'recenter
"type . file-line / line"
4543 "`recenter' after jumping.")
4544 (anything-document-attribute 'target-file
"type . line"
4545 "Goto line of target-file.")
4547 (defun anything-c-call-interactively (cmd-or-name)
4548 "Execute CMD-OR-NAME as Emacs command.
4549 It is added to `extended-command-history'.
4550 `anything-current-prefix-arg' is used as the command's prefix argument."
4551 (setq extended-command-history
4552 (cons (anything-c-stringify cmd-or-name
)
4553 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
4554 (let ((current-prefix-arg anything-current-prefix-arg
)
4555 (cmd (anything-c-symbolify cmd-or-name
)))
4556 (if (stringp (symbol-function cmd
))
4557 (execute-kbd-macro (symbol-function cmd
))
4558 (call-interactively cmd
))))
4560 (defun anything-c-set-variable (var)
4561 "Set value to VAR interactively."
4563 (let ((sym (anything-c-symbolify var
)))
4564 (set sym
(eval-minibuffer (format "Set %s: " var
)
4565 (prin1-to-string (symbol-value sym
))))))
4567 ;; (anything-c-set-variable 'hh)
4569 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4570 (defvar anything-match-line-overlay-face nil
)
4571 (defvar anything-match-line-overlay nil
)
4573 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
4574 "Highlight and underline current position"
4575 (let ((args (list (or start
(line-beginning-position))
4576 (or end
(1+ (line-end-position)))
4578 (if (not anything-match-line-overlay
)
4579 (setq anything-match-line-overlay
(apply 'make-overlay args
))
4580 (apply 'move-overlay anything-match-line-overlay args
)))
4581 (overlay-put anything-match-line-overlay
4582 'face
(or face anything-match-line-overlay-face
))
4587 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
4589 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
4590 "Face for source header in the anything buffer." :group
'anything
)
4592 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
4594 (defun anything-match-line-cleanup ()
4595 (when anything-match-line-overlay
4596 (delete-overlay anything-match-line-overlay
)
4597 (setq anything-match-line-overlay nil
)))
4599 (defun anything-match-line-update ()
4600 (when anything-match-line-overlay
4601 (delete-overlay anything-match-line-overlay
)
4602 (anything-match-line-color-current-line)))
4604 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
4605 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
4607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4609 (defun anything-c-transform-file-load-el (actions candidate
)
4610 "Add action to load the file CANDIDATE if it is an emacs lisp
4611 file. Else return ACTIONS unmodified."
4612 (if (member (file-name-extension candidate
) '("el" "elc"))
4613 (append actions
'(("Load Emacs Lisp File" . load-file
)))
4616 (defun anything-c-transform-file-browse-url (actions candidate
)
4617 "Add an action to browse the file CANDIDATE if it in a html
4618 file or URL. Else return ACTIONS unmodified."
4619 (if (string-match "^http\\|^ftp\\|\\.html?$" candidate
)
4620 (cons '("Browse with Browser" . browse-url
) actions
)
4624 (defun anything-c-transform-function-call-interactively (actions candidate
)
4625 "Add an action to call the function CANDIDATE interactively if
4626 it is a command. Else return ACTIONS unmodified."
4627 (if (commandp (intern-soft candidate
))
4628 (append actions
'(("Call Interactively"
4630 anything-c-call-interactively
)))
4634 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
4635 "If CANDIDATE's `car' is a command, then add an action to
4636 evaluate it and put it onto the `command-history'."
4637 (if (commandp (car (read candidate
)))
4638 ;; Make it first entry
4639 (cons '("Eval and put onto command-history" .
4641 (let ((sym (read sexp
)))
4643 (setq command-history
4644 (cons sym command-history
)))))
4648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4650 (defun anything-c-skip-boring-buffers (buffers)
4651 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
4653 (defun anything-c-skip-current-buffer (buffers)
4654 (if anything-allow-skipping-current-buffer
4655 (remove (buffer-name anything-current-buffer
) buffers
)
4658 (defun anything-c-shadow-boring-buffers (buffers)
4659 "Buffers matching `anything-c-boring-buffer-regexp' will be
4660 displayed with the `file-name-shadow' face if available."
4661 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
4664 (defun anything-c-shadow-boring-files (files)
4665 "Files matching `anything-c-boring-file-regexp' will be
4666 displayed with the `file-name-shadow' face if available."
4667 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
4669 (defun anything-c-skip-boring-files (files)
4670 "Files matching `anything-c-boring-file-regexp' will be skipped."
4671 (anything-c-skip-entries files anything-c-boring-file-regexp
))
4672 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
4674 (defun anything-c-skip-current-file (files)
4675 "Current file will be skipped."
4676 (remove (buffer-file-name anything-current-buffer
) files
))
4678 (defun anything-c-w32-pathname-transformer (args)
4679 "Change undesirable features of windows pathnames to ones more acceptable to
4680 other candidate transformers."
4681 (if (eq system-type
'windows-nt
)
4683 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
4685 (replace-regexp-in-string "\\\\" "/" y
)) args
))
4688 (defun anything-c-shorten-home-path (files)
4689 "Replaces /home/user with ~."
4690 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
4692 (mapcar (lambda (file)
4693 (if (and (stringp file
) (string-match home file
))
4694 (cons (replace-match "~" nil nil file
) file
)
4699 (defun anything-c-mark-interactive-functions (functions)
4700 "Mark interactive functions (commands) with (i) after the function name."
4702 (loop for function in functions
4703 do
(push (cons (concat function
4704 (when (commandp (intern-soft function
)) " (i)"))
4707 finally
(return (nreverse list
)))))
4709 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4710 (defvar anything-c-adaptive-done nil
4711 "nil if history information is not yet stored for the current
4714 (defvar anything-c-adaptive-history nil
4715 "Contains the stored history information.
4716 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
4718 (defadvice anything-initialize
(before anything-c-adaptive-initialize activate
)
4719 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
4720 when anything is started."
4721 (setq anything-c-adaptive-done nil
))
4723 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
4724 "Advise `anything-exit-minibuffer' to store history information
4725 when a candidate is selected with RET."
4726 (anything-c-adaptive-store-selection))
4728 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
4729 "Advise `anything-select-action' to store history information
4730 when the user goes to the action list with TAB."
4731 (anything-c-adaptive-store-selection))
4733 (defun anything-c-source-use-adaptative-p (&optional source-name
)
4734 "Return current source only if it use adaptative history, nil otherwise."
4735 (let* ((source (or source-name
(anything-get-current-source)))
4736 (adapt-source (or (assoc-default 'filtered-candidate-transformer
4737 (assoc (assoc-default 'type source
)
4738 anything-type-attributes
))
4739 (assoc-default 'candidate-transformer
4740 (assoc (assoc-default 'type source
)
4741 anything-type-attributes
))
4742 (assoc-default 'filtered-candidate-transformer source
)
4743 (assoc-default 'candidate-transformer source
))))
4744 (if (listp adapt-source
)
4745 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
4746 (when (eq adapt-source
'anything-c-adaptive-sort
) source
))))
4748 (defun anything-c-adaptive-store-selection ()
4749 "Store history information for the selected candidate."
4750 (unless anything-c-adaptive-done
4751 (setq anything-c-adaptive-done t
)
4752 (let ((source (anything-c-source-use-adaptative-p)))
4754 (let* ((source-name (or (assoc-default 'type source
)
4755 (assoc-default 'name source
)))
4756 (source-info (or (assoc source-name anything-c-adaptive-history
)
4758 (push (list source-name
) anything-c-adaptive-history
)
4759 (car anything-c-adaptive-history
))))
4760 (selection (anything-get-selection))
4761 (selection-info (progn
4764 (let ((found (assoc selection
(cdr source-info
))))
4769 ;; move entry to the beginning of the
4770 ;; list, so that it doesn't get
4771 ;; trimmed when the history is
4774 (delete found
(cdr source-info
)))
4777 (cadr source-info
)))
4778 (pattern-info (progn
4779 (setcdr selection-info
4781 (let ((found (assoc anything-pattern
(cdr selection-info
))))
4784 (cons anything-pattern
0)
4786 ;; move entry to the beginning of the
4787 ;; list, so if two patterns used the
4788 ;; same number of times then the one
4789 ;; used last appears first in the list
4790 (setcdr selection-info
4791 (delete found
(cdr selection-info
)))
4793 (cdr selection-info
)))
4794 (cadr selection-info
))))
4796 ;; increase usage count
4797 (setcdr pattern-info
(1+ (cdr pattern-info
)))
4799 ;; truncate history if needed
4800 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
4801 (setcdr selection-info
4802 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
4804 (if (file-readable-p anything-c-adaptive-history-file
)
4805 (load-file anything-c-adaptive-history-file
))
4806 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
4808 (defun anything-c-adaptive-save-history ()
4809 "Save history information to file given by `anything-c-adaptive-history-file'."
4813 ";; -*- mode: emacs-lisp -*-\n"
4814 ";; History entries used for anything adaptive display.\n")
4815 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
4818 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
4819 (unless (interactive-p) 'quiet
))))
4821 (defun anything-c-adaptive-sort (candidates source
)
4822 "Sort the CANDIDATES for SOURCE by usage frequency.
4823 This is a filtered candidate transformer you can use for the
4824 attribute `filtered-candidate-transformer' of a source in
4825 `anything-sources' or a type in `anything-type-attributes'."
4826 (let* ((source-name (or (assoc-default 'type source
)
4827 (assoc-default 'name source
)))
4828 (source-info (assoc source-name anything-c-adaptive-history
)))
4829 (if (not source-info
)
4830 ;; if there is no information stored for this source then do nothing
4834 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
4836 (mapcar (lambda (candidate-info)
4838 (dolist (pattern-info (cdr candidate-info
))
4839 (if (not (equal (car pattern-info
)
4841 (incf count
(cdr pattern-info
))
4843 ;; if current pattern is equal to the previously
4844 ;; used one then this candidate has priority
4845 ;; (that's why its count is boosted by 10000) and
4846 ;; it only has to compete with other candidates
4847 ;; which were also selected with the same pattern
4848 (setq count
(+ 10000 (cdr pattern-info
)))
4850 (cons (car candidate-info
) count
)))
4854 ;; sort the list in descending order, so candidates with highest
4855 ;; priorty come first
4856 (setq usage
(sort usage
(lambda (first second
)
4857 (> (cdr first
) (cdr second
)))))
4859 ;; put those candidates first which have the highest usage count
4860 (dolist (info usage
)
4861 (when (member* (car info
) candidates
4862 :test
'anything-c-adaptive-compare
)
4863 (push (car info
) sorted
)
4864 (setq candidates
(remove* (car info
) candidates
4865 :test
'anything-c-adaptive-compare
))))
4867 ;; and append the rest
4868 (append (reverse sorted
) candidates nil
)))))
4870 (defun anything-c-adaptive-compare (x y
)
4871 "Compare candidates X and Y taking into account that the
4872 candidate can be in (DISPLAY . REAL) format."
4873 (equal (if (listp x
)
4880 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4881 ;; Plug-in: candidates-file
4882 (defun anything-compile-source--candidates-file (source)
4883 (if (assoc-default 'candidates-file source
)
4884 `((init anything-p-candidats-file-init
4885 ,@(let ((orig-init (assoc-default 'init source
)))
4886 (cond ((null orig-init
) nil
)
4887 ((functionp orig-init
) (list orig-init
))
4889 (candidates-in-buffer)
4892 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
4894 (defun anything-p-candidats-file-init ()
4895 (destructuring-bind (file &optional updating
)
4896 (anything-mklist (anything-attr 'candidates-file
))
4897 (setq file
(anything-interpret-value file
))
4898 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
4900 (buffer-disable-undo)
4902 (auto-revert-mode 1)))))
4904 (anything-document-attribute 'candidates-file
"candidates-file plugin"
4905 "Use a file as the candidates buffer.
4907 1st argument is a filename, string or function name or variable name.
4908 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
4910 ;; Plug-in: headline
4911 (defun anything-compile-source--anything-headline (source)
4912 (if (assoc-default 'headline source
)
4913 (append '((init . anything-headline-init
)
4914 (get-line-fn . buffer-substring
)
4917 '((candidates-in-buffer)))
4919 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
4921 (defun anything-headline-init ()
4922 (when (and (anything-current-buffer-is-modified)
4923 (with-current-buffer anything-current-buffer
4924 (eval (or (anything-attr 'condition
) t
))))
4925 (anything-headline-make-candidate-buffer
4926 (anything-attr 'headline
)
4927 (anything-attr 'subexp
))))
4929 (anything-document-attribute 'headline
"Headline plug-in"
4930 "Regexp string for anything-headline to scan.")
4931 (anything-document-attribute 'condition
"Headline plug-in"
4932 "A sexp representing the condition to use anything-headline.")
4933 (anything-document-attribute 'subexp
"Headline plug-in"
4934 "Display (match-string-no-properties subexp).")
4937 (defun anything-headline-get-candidates (regexp subexp
)
4938 (with-current-buffer anything-current-buffer
4940 (goto-char (point-min))
4941 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
4942 (let (hierarchy curhead
)
4944 (if (numberp subexp
)
4945 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
4946 (cons (buffer-substring (point-at-bol) (point-at-eol))
4948 (hierarchies (headlines)
4949 (1+ (loop for
(_ . hierarchy
) in headlines
4950 maximize hierarchy
)))
4952 (loop for i from
0 to hierarchy
4953 collecting
(aref curhead i
)))
4954 (arrange (headlines)
4955 (loop with curhead
= (make-vector (hierarchies headlines
) "")
4956 for
((str . pt
) . hierarchy
) in headlines
4957 do
(aset curhead hierarchy str
)
4960 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / ")
4965 (loop for re in regexp
4966 for hierarchy from
0
4967 do
(goto-char (point-min))
4970 while
(re-search-forward re nil t
)
4971 collect
(cons (matched) hierarchy
)))
4972 (lambda (a b
) (> (cdar b
) (cdar a
)))))
4973 (loop while
(re-search-forward regexp nil t
)
4974 collect
(matched))))))))
4977 (defun anything-headline-make-candidate-buffer (regexp subexp
)
4978 (with-current-buffer (anything-candidate-buffer 'local
)
4979 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
4982 (with-current-buffer anything-current-buffer
4983 (line-number-at-pos pos
))
4986 (defun anything-headline-goto-position (pos recenter
)
4989 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
4991 (defun anything-revert-buffer (candidate)
4992 (with-current-buffer candidate
4993 (when (buffer-modified-p)
4994 (revert-buffer t t
))))
4996 (defun anything-revert-marked-buffers (candidate)
4997 (dolist (i (anything-marked-candidates))
4998 (anything-revert-buffer i
)))
5000 (defun anything-kill-marked-buffers (candidate)
5001 (dolist (i (anything-marked-candidates))
5004 (defun anything-delete-marked-files (candidate)
5005 (anything-aif (anything-marked-candidates)
5006 (if (y-or-n-p (format "Delete *%s Files " (length it
)))
5009 (set-text-properties 0 (length i
) nil i
)
5010 (anything-c-delete-file i
))
5011 (message "%s Files deleted" (length it
)))
5012 (message "(No deletions performed)"))
5013 (set-text-properties 0 (length candidate
) nil candidate
)
5014 (if (y-or-n-p (format "Really delete file `%s' " candidate
))
5016 (anything-c-delete-file candidate
)
5017 (message "1 file deleted"))
5018 (message "(No deletions performed)"))))
5020 (defun anything-ediff-marked-buffers (candidate &optional merge
)
5021 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
5022 With optional arg `merge' call `ediff-merge-buffers'."
5023 (let ((lg-lst (length (anything-marked-candidates)))
5027 (error "Error:You have to mark at least 1 buffer"))
5029 (setq buf1 anything-current-buffer
5030 buf2
(first (anything-marked-candidates))))
5032 (setq buf1
(first (anything-marked-candidates))
5033 buf2
(second (anything-marked-candidates))))
5035 (error "Error:To much buffers marked!")))
5037 (ediff-merge-buffers buf1 buf2
)
5038 (ediff-buffers buf1 buf2
))))
5040 (defun anything-bookmark-get-bookmark-from-name (bmk)
5041 "Return bookmark name even if it is a bookmark with annotation.
5042 e.g prepended with *.
5043 Return nil if bmk is not a valid bookmark."
5044 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
5045 (if (assoc bookmark bookmark-alist
)
5047 (when (assoc bmk bookmark-alist
)
5050 (defun anything-delete-marked-bookmarks (elm)
5051 "Delete this bookmark or all marked bookmarks."
5052 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm
)))
5053 (anything-aif (anything-marked-candidates)
5055 (let ((bmk (anything-bookmark-get-bookmark-from-name i
)))
5056 (bookmark-delete bmk
'batch
)))
5057 (bookmark-delete bookmark
'batch
))))
5059 (defun anything-bookmark-active-region-maybe (candidate)
5060 "Active saved region if this bookmark have one."
5061 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5063 (when (and (boundp bmkext-use-region-flag
)
5064 bmkext-use-region-flag
)
5065 (let ((bmk-name (or (bmkext-get-buffer-name bookmark
)
5066 (file-name-nondirectory
5067 (bookmark-get-filename bookmark
)))))
5069 (with-current-buffer bmk-name
5070 (setq deactivate-mark nil
)))))
5073 (defun anything-require-or-error (feature function
)
5074 (or (require feature nil t
)
5075 (error "Need %s to use `%s'." feature function
)))
5077 (defun anything-find-buffer-on-elscreen (candidate)
5078 "Open buffer in new screen, if marked buffers open all in elscreens."
5079 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
5080 (anything-aif (anything-marked-candidates)
5082 (let ((target-screen (elscreen-find-screen-by-buffer
5083 (get-buffer i
) 'create
)))
5084 (elscreen-goto target-screen
)))
5085 (let ((target-screen (elscreen-find-screen-by-buffer
5086 (get-buffer candidate
) 'create
)))
5087 (elscreen-goto target-screen
))))
5089 (defun anything-elscreen-find-file (file)
5090 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
5091 (elscreen-find-file file
))
5093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5096 (define-anything-type-attribute 'buffer
5099 '(("Switch to buffer other window" . switch-to-buffer-other-window
)
5100 ("Switch to buffer" . switch-to-buffer
))
5101 '(("Switch to buffer" . switch-to-buffer
)
5102 ("Switch to buffer other window" . switch-to-buffer-other-window
)
5103 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)))
5104 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
5105 ("Display buffer" . display-buffer
)
5106 ("Revert buffer" . anything-revert-buffer
)
5107 ("Revert Marked buffers" . anything-revert-marked-buffers
)
5108 ("Kill buffer" . kill-buffer
)
5109 ("Kill Marked buffers" . anything-kill-marked-buffers
)
5110 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
5111 ("Ediff Merge marked buffers" .
(lambda (candidate)
5112 (anything-ediff-marked-buffers candidate t
))))
5113 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers
))
5114 "Buffer or buffer name.")
5116 (define-anything-type-attribute 'file
5119 '(("Find file other window" . find-file-other-window
)
5120 ("Find file" . find-file
)
5121 ("Find file as root" . anything-find-file-as-root
))
5122 '(("Find file" . find-file
)
5123 ("Find file as root" . anything-find-file-as-root
)
5124 ("Find file other window" . find-file-other-window
)
5125 ("Find file other frame" . find-file-other-frame
)))
5126 ("Open dired in file's directory" . anything-c-open-dired
)
5127 ("Delete file(s)" . anything-delete-marked-files
)
5128 ("Open file externally" . anything-c-open-file-externally
)
5129 ("Open file with default tool" . anything-c-open-file-with-default-tool
))
5130 (action-transformer anything-c-transform-file-load-el
5131 anything-c-transform-file-browse-url
)
5132 (candidate-transformer anything-c-w32-pathname-transformer
5133 anything-c-skip-current-file
5134 anything-c-skip-boring-files
5135 anything-c-shorten-home-path
))
5138 (define-anything-type-attribute 'command
5139 `((action ("Call interactively" . anything-c-call-interactively
)
5140 ("Describe command" . anything-c-describe-function
)
5141 ("Add command to kill ring" . anything-c-kill-new
)
5142 ("Go to command's definition" . anything-c-find-function
))
5143 ;; Sort commands according to their usage count.
5144 (filtered-candidate-transformer . anything-c-adaptive-sort
))
5145 "Command. (string or symbol)")
5147 (define-anything-type-attribute 'function
5148 '((action ("Describe function" . anything-c-describe-function
)
5149 ("Add function to kill ring" . anything-c-kill-new
)
5150 ("Go to function's definition" . anything-c-find-function
))
5151 (action-transformer anything-c-transform-function-call-interactively
)
5152 (candidate-transformer anything-c-mark-interactive-functions
))
5153 "Function. (string or symbol)")
5155 (define-anything-type-attribute 'variable
5156 '((action ("Describe variable" . anything-c-describe-variable
)
5157 ("Add variable to kill ring" . anything-c-kill-new
)
5158 ("Go to variable's definition" . anything-c-find-variable
)
5159 ("Set variable" . anything-c-set-variable
)))
5162 (define-anything-type-attribute 'sexp
5163 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
5164 ("Add s-expression to kill ring" . kill-new
))
5165 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
5166 "String representing S-Expressions.")
5168 (define-anything-type-attribute 'bookmark
5170 ("Jump to bookmark" .
(lambda (candidate)
5171 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
))
5172 (current-prefix-arg anything-current-prefix-arg
))
5173 (bookmark-jump bookmark
))
5175 (anything-bookmark-active-region-maybe candidate
)))
5176 ("Jump to BM other window" .
(lambda (candidate)
5177 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5178 (bookmark-jump-other-window bookmark
))
5180 (anything-bookmark-active-region-maybe candidate
)))
5181 ("Bookmark edit annotation" .
(lambda (candidate)
5182 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5183 (bookmark-edit-annotation bookmark
))))
5184 ("Bookmark show annotation" .
(lambda (candidate)
5185 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5186 (bookmark-show-annotation bookmark
))))
5187 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
5188 ,@(when (fboundp 'bmkext-edit-bookmark
)
5189 '(("Edit Bookmark" .
(lambda (candidate)
5190 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5191 (bmkext-edit-bookmark bookmark
))))))
5192 ("Rename bookmark" .
(lambda (candidate)
5193 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5194 (bookmark-rename bookmark
))))
5195 ("Relocate bookmark" .
(lambda (candidate)
5196 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5197 (bookmark-relocate bookmark
))))))
5200 (define-anything-type-attribute 'line
5201 '((display-to-real . anything-c-display-to-real-line
)
5202 (action ("Go to Line" . anything-c-action-line-goto
)))
5203 "LINENO:CONTENT string, eg. \" 16:foo\".
5205 Optional `target-file' attribute is a name of target file.
5207 Optional `before-jump-hook' attribute is a function with no
5208 arguments which is called before jumping to position.
5210 Optional `after-jump-hook' attribute is a function with no
5211 arguments which is called after jumping to position.
5213 If `adjust' attribute is specified, searches the line whose
5214 content is CONTENT near the LINENO.
5216 If `recenter' attribute is specified, the line is displayed at
5217 the center of window, otherwise at the top of window.
5220 (define-anything-type-attribute 'file-line
5221 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
5223 (action ("Go to" . anything-c-action-file-line-goto
)))
5224 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
5226 Optional `default-directory' attribute is a default-directory
5227 FILENAME is interpreted.
5229 Optional `before-jump-hook' attribute is a function with no
5230 arguments which is called before jumping to position.
5232 Optional `after-jump-hook' attribute is a function with no
5233 arguments which is called after jumping to position.
5235 If `adjust' attribute is specified, searches the line whose
5236 content is CONTENT near the LINENO.
5238 If `recenter' attribute is specified, the line is displayed at
5239 the center of window, otherwise at the top of window.
5242 (define-anything-type-attribute 'timer
5243 '((real-to-display . anything-c-timer-real-to-display
)
5244 (action ("Cancel Timer" . cancel-timer
)))
5248 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
5249 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
5251 (when (fboundp 'expectations
)
5253 (desc "candidates-file plug-in")
5254 (expect '(anything-p-candidats-file-init)
5255 (assoc-default 'init
5256 (car (anything-compile-sources
5258 (candidates-file .
"test.txt")))
5259 '(anything-compile-source--candidates-file)))))
5260 (expect '(anything-p-candidats-file-init
5262 (assoc-default 'init
5263 (car (anything-compile-sources
5265 (candidates-file .
"test.txt")
5266 (init .
(lambda () 1))))
5267 '(anything-compile-source--candidates-file)))))
5268 (expect '(anything-p-candidats-file-init
5270 (assoc-default 'init
5271 (car (anything-compile-sources
5273 (candidates-file .
"test.txt")
5274 (init (lambda () 1))))
5275 '(anything-compile-source--candidates-file)))))
5276 (desc "anything-c-source-buffers")
5277 (expect '(("Buffers" ("foo" "curbuf")))
5278 (stub buffer-list
=> '("curbuf" " hidden" "foo" "*anything*"))
5279 (let ((anything-c-boring-buffer-regexp
5284 " *Echo Area" " *Minibuf"))))
5285 (flet ((buffer-name (x) x
))
5286 (anything-test-candidates 'anything-c-source-buffers
))))
5287 (desc "anything-c-stringify")
5289 (anything-c-stringify "str1"))
5291 (anything-c-stringify 'str2
))
5292 (desc "anything-c-symbolify")
5294 (anything-c-symbolify "sym1"))
5296 (anything-c-symbolify 'sym2
)))))
5299 (provide 'anything-config
)
5301 ;;; Local Variables:
5302 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
5305 ;; How to save (DO NOT REMOVE!!)
5306 ;; (emacswiki-post "anything-config.el")
5307 ;;; anything-config.el ends here
5309 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
5310 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
5311 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
5312 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
5313 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
5314 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
5315 ;;; LocalWords: dotimes Thierry online vname
5316 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
5317 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
5318 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
5319 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
5320 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
5321 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
5322 ;;; LocalWords: startpos noselect dont desc