Merge branch 'my-anything'
[anything-config.git] / anything-config.el
blob98625ebe2b98cbedeb34226d0e1ab571a86d733f
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
15 ;; Version: 0.4.1
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:
22 ;; `anything'
25 ;;; This file is NOT part of GNU Emacs
27 ;;; License
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)
32 ;; any later version.
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.
44 ;;; !NOTICE!
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
49 ;;; Commentary:
51 ;; Predefined configurations for `anything.el'
53 ;; For quick start, try `anything-for-files' to open files.
54 ;;
55 ;; To configure anything you should define anything command
56 ;; with your favorite sources, like below:
58 ;; (defun my-anything ()
59 ;; (interactive)
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)
68 ;; " *my-anything*"))
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.
77 ;;; Commands:
79 ;; Below are complete command list:
81 ;; `anything-c-describe-anything-bindings'
82 ;; [OBSOLETE] Describe `anything' bindings.
83 ;; `anything-for-files'
84 ;; Preconfigured `anything' for opening files.
85 ;; `anything-info-at-point'
86 ;; Preconfigured `anything' for searching info at point.
87 ;; `anything-show-kill-ring'
88 ;; Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
89 ;; `anything-minibuffer-history'
90 ;; Preconfigured `anything' for `minibuffer-history'.
91 ;; `anything-gentoo'
92 ;; Preconfigured `anything' for gentoo linux.
93 ;; `anything-surfraw-only'
94 ;; Preconfigured `anything' for surfraw.
95 ;; `anything-imenu'
96 ;; Preconfigured `anything' for `imenu'.
97 ;; `anything-google-suggest'
98 ;; Preconfigured `anything' for google search with google suggest.
99 ;; `anything-yahoo-suggest'
100 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
101 ;; `anything-for-buffers'
102 ;; Preconfigured `anything' for buffer.
103 ;; `anything-bbdb'
104 ;; Preconfigured `anything' for BBDB.
105 ;; `anything-locate'
106 ;; Preconfigured `anything' for Locate.
107 ;; `anything-w3m-bookmarks'
108 ;; Preconfigured `anything' for w3m bookmark.
109 ;; `anything-colors'
110 ;; Preconfigured `anything' for color.
111 ;; `anything-bm-list'
112 ;; Preconfigured `anything' for visible bookmarks.
113 ;; `anything-timers'
114 ;; Preconfigured `anything' for timers.
115 ;; `anything-kill-buffers'
116 ;; Preconfigured `anything' to kill buffer you selected.
117 ;; `anything-query-replace-regexp'
118 ;; Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually.
119 ;; `anything-regexp'
120 ;; Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement.
121 ;; `anything-insert-buffer-name'
122 ;; Insert buffer name.
123 ;; `anything-insert-symbol'
124 ;; Insert current symbol.
125 ;; `anything-insert-selection'
126 ;; Insert current selection.
127 ;; `anything-show-buffer-only'
128 ;; [OBSOLETE] Only show sources about buffer.
129 ;; `anything-show-bbdb-only'
130 ;; [OBSOLETE] Only show sources about BBDB.
131 ;; `anything-show-locate-only'
132 ;; [OBSOLETE] Only show sources about Locate.
133 ;; `anything-show-info-only'
134 ;; [OBSOLETE] Only show sources about Info.
135 ;; `anything-show-imenu-only'
136 ;; [OBSOLETE] Only show sources about Imenu.
137 ;; `anything-show-files-only'
138 ;; [OBSOLETE] Only show sources about File.
139 ;; `anything-show-w3m-bookmarks-only'
140 ;; [OBSOLETE] Only show source about w3m bookmark.
141 ;; `anything-show-colors-only'
142 ;; [OBSOLETE] Only show source about color.
143 ;; `anything-show-kill-ring-only'
144 ;; [OBSOLETE] Only show source about kill ring.
145 ;; `anything-show-this-source-only'
146 ;; Only show this source.
147 ;; `anything-test-sources'
148 ;; List all anything sources for test.
149 ;; `anything-select-source'
150 ;; Select source.
151 ;; `anything-find-files-down-one-level'
152 ;; Go down one level like unix command `cd ..'.
153 ;; `anything-find-files'
154 ;; Preconfigured `anything' for `find-file'.
155 ;; `anything-write-file'
156 ;; Preconfigured `anything' providing completion for `write-file'.
157 ;; `anything-insert-file'
158 ;; Preconfigured `anything' providing completion for `insert-file'.
159 ;; `anything-dired-rename-file'
160 ;; Preconfigured `anything' to rename files from dired.
161 ;; `anything-dired-copy-file'
162 ;; Preconfigured `anything' to copy files from dired.
163 ;; `anything-dired-symlink-file'
164 ;; Preconfigured `anything' to symlink files from dired.
165 ;; `anything-dired-hardlink-file'
166 ;; Preconfigured `anything' to hardlink files from dired.
167 ;; `anything-dired-bindings'
168 ;; Replace usual dired commands `C' and `R' by anything ones.
169 ;; `anything-bookmark-ext'
170 ;; Preconfigured `anything' for bookmark-extensions sources.
171 ;; `anything-simple-call-tree'
172 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
173 ;; `anything-mark-ring'
174 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
175 ;; `anything-global-mark-ring'
176 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
177 ;; `anything-yaoddmuse-cache-pages'
178 ;; Fetch the list of files on emacswiki and create cache file.
179 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
180 ;; Preconfigured `anything' to edit or view EmacsWiki page.
181 ;; `anything-yaoddmuse-emacswiki-post-library'
182 ;; Preconfigured `anything' to post library to EmacsWiki.
183 ;; `anything-emms-stream-edit-bookmark'
184 ;; Change the information of current emms-stream bookmark from anything.
185 ;; `anything-emms-stream-delete-bookmark'
186 ;; Delete an emms-stream bookmark from anything.
187 ;; `anything-call-source'
188 ;; Preconfigured `anything' to call anything source.
189 ;; `anything-call-source-from-anything'
190 ;; Call anything source within `anything' session.
191 ;; `anything-create-from-anything'
192 ;; Run `anything-create' from `anything' as a fallback.
193 ;; `anything-create'
194 ;; Preconfigured `anything' to do many create actions from STRING.
195 ;; `anything-top'
196 ;; Preconfigured `anything' for top command.
197 ;; `anything-select-xfont'
198 ;; Preconfigured `anything' to select Xfont.
199 ;; `anything-apt'
200 ;; Preconfigured `anything' : frontend of APT package manager.
201 ;; `anything-c-set-variable'
202 ;; Set value to VAR interactively.
203 ;; `anything-c-adaptive-save-history'
204 ;; Save history information to file given by `anything-c-adaptive-history-file'.
206 ;;; Customizable Options:
208 ;; Below are customizable option list:
210 ;; `anything-c-use-standard-keys'
211 ;; Whether use standard keybindings. (no effect)
212 ;; default = nil
213 ;; `anything-c-adaptive-history-file'
214 ;; Path of file where history information is stored.
215 ;; default = "~/.emacs.d/anything-c-adaptive-history"
216 ;; `anything-c-adaptive-history-length'
217 ;; Maximum number of candidates stored for a source.
218 ;; default = 50
219 ;; `anything-c-google-suggest-url'
220 ;; URL used for looking up Google suggestions.
221 ;; default = "http://google.com/complete/search?output=toolbar&q="
222 ;; `anything-c-google-suggest-search-url'
223 ;; URL used for Google searching.
224 ;; default = "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
225 ;; `anything-google-suggest-use-curl-p'
226 ;; *When non--nil use CURL to get info from `anything-c-google-suggest-url'.
227 ;; default = nil
228 ;; `anything-c-yahoo-suggest-url'
229 ;; Url used for looking up Yahoo suggestions.
230 ;; default = "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
231 ;; `anything-c-yahoo-suggest-search-url'
232 ;; Url used for Yahoo searching.
233 ;; default = "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
234 ;; `anything-c-boring-buffer-regexp'
235 ;; The regexp that match boring buffers.
236 ;; default = (rx (or (group bos " ") "*anything" " *Echo Area" " *Minibuf"))
237 ;; `anything-c-boring-file-regexp'
238 ;; The regexp that match boring files.
239 ;; default = (rx (or (and "/" ... ...) (and line-start ".#") (and ... eol)))
240 ;; `anything-kill-ring-threshold'
241 ;; *Minimum length to be listed by `anything-c-source-kill-ring'.
242 ;; default = 10
243 ;; `anything-su-or-sudo'
244 ;; What command to use for root access.
245 ;; default = "su"
246 ;; `anything-for-files-prefered-list'
247 ;; Your prefered sources to find files.
248 ;; default = (quote (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-source-buffers+ anything-c-source-recentf anything-c-source-bookmarks ...))
249 ;; `anything-create--actions-private'
250 ;; User defined actions for `anything-create' / `anything-c-source-create'.
251 ;; default = nil
252 ;; `anything-allow-skipping-current-buffer'
253 ;; Show current buffer or not in anything buffer
254 ;; default = t
255 ;; `anything-c-enable-eval-defun-hack'
256 ;; *If non-nil, execute `anything' using the source at point when C-M-x is pressed.
257 ;; default = t
258 ;; `anything-tramp-verbose'
259 ;; *Just like `tramp-verbose' but specific to anything.
260 ;; default = 0
263 ;; Anything sources can be tested by M-x `anything-call-source'.
264 ;; Below are complete source list you can setup in the first argument
266 ;; Buffer:
267 ;; `anything-c-source-buffers' (Buffers)
268 ;; `anything-c-source-buffer-not-found' (Create buffer)
269 ;; `anything-c-source-buffers+' (Buffers)
270 ;; File:
271 ;; `anything-c-source-file-name-history' (File Name History)
272 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
273 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
274 ;; `anything-c-source-find-files' (Find Files (`C-z':Expand Candidate, `C-.':Go to precedent level))
275 ;; `anything-c-source-file-cache' (File Cache)
276 ;; `anything-c-source-locate' (Locate)
277 ;; `anything-c-source-recentf' (Recentf)
278 ;; `anything-c-source-ffap-guesser' (File at point)
279 ;; `anything-c-source-ffap-line' (File/Lineno at point)
280 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
281 ;; Help:
282 ;; `anything-c-source-man-pages' (Manual Pages)
283 ;; `anything-c-source-info-pages' (Info Pages)
284 ;; `anything-c-source-info-elisp' (Info Elisp)
285 ;; `anything-c-source-info-cl' (Info Common-Lisp)
286 ;; Command:
287 ;; `anything-c-source-complex-command-history' (Complex Command History)
288 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
289 ;; `anything-c-source-emacs-commands' (Emacs Commands)
290 ;; `anything-c-source-lacarte' (Lacarte)
291 ;; Function:
292 ;; `anything-c-source-emacs-functions' (Emacs Functions)
293 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
294 ;; Variable:
295 ;; `anything-c-source-emacs-variables' (Emacs Variables)
296 ;; Bookmark:
297 ;; `anything-c-source-bookmarks' (Bookmarks)
298 ;; `anything-c-source-bookmark-set' (Set Bookmark)
299 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
300 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
301 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
302 ;; `anything-c-source-bookmark-regions' (Bookmark Regions)
303 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
304 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
305 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
306 ;; `anything-c-source-bookmark-info' (Bookmark Info)
307 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
308 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
309 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
310 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
311 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
312 ;; Library:
313 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
314 ;; Programming:
315 ;; `anything-c-source-imenu' (Imenu)
316 ;; `anything-c-source-ctags' (Exuberant ctags)
317 ;; `anything-c-source-semantic' (Semantic Tags)
318 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
319 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
320 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
321 ;; Color and Face:
322 ;; `anything-c-source-customize-face' (Customize Face)
323 ;; `anything-c-source-colors' (Colors)
324 ;; Search Engine:
325 ;; `anything-c-source-tracker-search' (Tracker Search)
326 ;; `anything-c-source-mac-spotlight' (mdfind)
327 ;; Kill ring:
328 ;; `anything-c-source-kill-ring' (Kill Ring)
329 ;; Mark ring:
330 ;; `anything-c-source-mark-ring' (mark-ring)
331 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
332 ;; Register:
333 ;; `anything-c-source-register' (Registers)
334 ;; Headline Extraction:
335 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
336 ;; `anything-c-source-rd-headline' (RD HeadLine)
337 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
338 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
339 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
340 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
341 ;; `anything-c-source-org-headline' (Org HeadLine)
342 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
343 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
344 ;; `anything-c-source-eev-anchor' (Anchors)
345 ;; Misc:
346 ;; `anything-c-source-org-keywords' (Org Keywords)
347 ;; `anything-c-source-picklist' (Picklist)
348 ;; `anything-c-source-bbdb' (BBDB)
349 ;; `anything-c-source-evaluation-result' (Evaluation Result)
350 ;; `anything-c-source-calculation-result' (Calculation Result)
351 ;; `anything-c-source-google-suggest' (Google Suggest)
352 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
353 ;; `anything-c-source-surfraw' (Surfraw)
354 ;; `anything-c-source-emms-streams' (Emms Streams)
355 ;; `anything-c-source-emms-dired' (Music Directory)
356 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
357 ;; `anything-c-source-call-source' (Call anything source)
358 ;; `anything-c-source-occur' (Occur)
359 ;; `anything-c-source-create' (Create)
360 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
361 ;; `anything-c-source-elscreen' (Elscreen)
362 ;; System:
363 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
364 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
365 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
366 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
367 ;; `anything-c-source-xfonts' (X Fonts)
368 ;; `anything-c-source-apt' (APT)
369 ;; `anything-c-source-gentoo' (Portage sources)
370 ;; `anything-c-source-use-flags' (Use Flags)
371 ;; `anything-c-source-emacs-process' (Emacs Process)
373 ;;; Change log:
375 ;; Change log of this file is found at
376 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
378 ;;; Contributors:
380 ;; Tamas Patrovics
381 ;; Tassilo Horn <tassilo@member.fsf.org>
382 ;; Vagn Johansen <gonz808@hotmail.com>
383 ;; Mathias Dahl <mathias.dahl@gmail.com>
384 ;; Bill Clementson <billclem@gmail.com>
385 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
386 ;; Drew Adams <drew.adams@oracle.com>
387 ;; Jason McBrayer <jmcbray@carcosa.net>
388 ;; Andy Stewart <lazycat.manatee@gmail.com>
389 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
390 ;; rubikitch <rubikitch@ruby-lang.org>
391 ;; Scott Vokes <vokes.s@gmail.com>
394 ;;; For Maintainers:
396 ;; Evaluate (anything-c-insert-summary) before commit. This function
397 ;; generates anything-c-source-* list.
399 ;; Install also http://www.emacswiki.org/emacs/auto-document.el
400 ;; And eval it or run interactively.
402 ;; [EVAL IT] (anything-c-insert-summary)
403 ;; [EVAL IT] (auto-document)
405 ;; Please write details documentation about function, then others will
406 ;; read code more easier. -- Andy Stewart
410 ;;; TODO
412 ;; - anything-c-adaptive stores infos for sources/types that don't have
413 ;; set it as `filtered-candidate-transformer'.
415 ;; - Fix documentation, now many functions haven't documentations.
418 ;;; Require
419 (require 'anything)
420 (require 'thingatpt)
421 (require 'ffap)
422 (require 'cl)
424 ;;; Code:
426 ;; version check
427 (let ((version "1.263"))
428 (when (and (string= "1." (substring version 0 2))
429 (string-match "1\.\\([0-9]+\\)" anything-version)
430 (< (string-to-number (match-string 1 anything-version))
431 (string-to-number (substring version 2))))
432 (error "Please update anything.el!!
434 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
436 or M-x install-elisp-from-emacswiki anything.el")))
438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
439 (defgroup anything-config nil
440 "Predefined configurations for `anything.el'."
441 :group 'anything)
443 (defcustom anything-c-use-standard-keys nil
444 "Whether use standard keybindings. (no effect)
446 Key definitions in anything-config.el are removed because
447 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
448 minibuffer history, C-s for isearch, etc.
450 If you use `iswitchb' with `anything',
451 evaluate (anything-iswitchb-setup) . Then some bindings that
452 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
453 history, are removed from `anything-map'. "
454 :type 'boolean
455 :group 'anything-config)
457 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
458 "Path of file where history information is stored."
459 :type 'string
460 :group 'anything-config)
462 (defcustom anything-c-adaptive-history-length 50
463 "Maximum number of candidates stored for a source."
464 :type 'number
465 :group 'anything-config)
467 (defcustom anything-c-google-suggest-url
468 "http://google.com/complete/search?output=toolbar&q="
469 "URL used for looking up Google suggestions."
470 :type 'string
471 :group 'anything-config)
473 (defcustom anything-c-google-suggest-search-url
474 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
475 "URL used for Google searching."
476 :type 'string
477 :group 'anything-config)
479 (defcustom anything-google-suggest-use-curl-p nil
480 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
481 Otherwise `url-retrieve-synchronously' is used."
482 :type 'boolean
483 :group 'anything-config)
485 (defcustom anything-c-yahoo-suggest-url
486 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
487 "Url used for looking up Yahoo suggestions."
488 :type 'string
489 :group 'anything-config)
491 (defcustom anything-c-yahoo-suggest-search-url
492 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
493 "Url used for Yahoo searching."
494 :type 'string
495 :group 'anything-config)
497 (defcustom anything-c-boring-buffer-regexp
498 (rx (or
499 (group bos " ")
500 ;; anything-buffer
501 "*anything"
502 ;; echo area
503 " *Echo Area" " *Minibuf"))
504 "The regexp that match boring buffers.
505 Buffer candidates matching this regular expression will be
506 filtered from the list of candidates if the
507 `anything-c-skip-boring-buffers' candidate transformer is used, or
508 they will be displayed with face `file-name-shadow' if
509 `anything-c-shadow-boring-buffers' is used."
510 :type 'string
511 :group 'anything-config)
512 ;; (string-match anything-c-boring-buffer-regexp "buf")
513 ;; (string-match anything-c-boring-buffer-regexp " hidden")
514 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
516 (defcustom anything-c-boring-file-regexp
517 (rx (or
518 ;; Boring directories
519 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
520 ;; Boring files
521 (and line-start ".#")
522 (and (or ".class" ".la" ".o" "~") eol)))
523 "The regexp that match boring files.
524 File candidates matching this regular expression will be
525 filtered from the list of candidates if the
526 `anything-c-skip-boring-files' candidate transformer is used, or
527 they will be displayed with face `file-name-shadow' if
528 `anything-c-shadow-boring-files' is used."
529 :type 'string
530 :group 'anything-config)
532 (defcustom anything-kill-ring-threshold 10
533 "*Minimum length to be listed by `anything-c-source-kill-ring'."
534 :type 'integer
535 :group 'anything-config)
537 (defcustom anything-su-or-sudo "su"
538 "What command to use for root access."
539 :type 'string
540 :group 'anything-config)
542 (defcustom anything-for-files-prefered-list '(anything-c-source-ffap-line
543 anything-c-source-ffap-guesser
544 anything-c-source-buffers+
545 anything-c-source-recentf
546 anything-c-source-bookmarks
547 anything-c-source-file-cache
548 anything-c-source-files-in-current-dir+
549 anything-c-source-locate)
550 "Your prefered sources to find files."
551 :type 'list
552 :group 'anything-config)
554 (defcustom anything-create--actions-private nil
555 "User defined actions for `anything-create' / `anything-c-source-create'.
556 It is a list of (DISPLAY . FUNCTION) pairs like `action'
557 attribute of `anything-sources'.
559 It is prepended to predefined pairs."
560 :type 'list
561 :group 'anything-config)
563 (defcustom anything-allow-skipping-current-buffer t
564 "Show current buffer or not in anything buffer"
565 :type 'boolean
566 :group 'anything-config)
568 (defcustom anything-c-enable-eval-defun-hack t
569 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
570 This hack is invoked when pressing C-M-x in the form (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
571 :type 'boolean
572 :group 'anything-config)
574 (defcustom anything-tramp-verbose 0
575 "*Just like `tramp-verbose' but specific to anything.
576 When set to 0 don't show tramp messages in anything.
577 If you want to have the default tramp messages set it to 3."
578 :type 'integer
579 :group 'anything-config)
581 ;;; Documentation
582 ;; It is replaced by `anything-help'
583 (defun anything-c-describe-anything-bindings ()
584 "[OBSOLETE] Describe `anything' bindings."
585 (interactive)
586 (anything-run-after-quit
587 #'(lambda ()
588 (with-current-buffer (get-buffer-create "*Anything Help*")
589 (erase-buffer)
590 (insert
591 (substitute-command-keys
592 "The keys that are defined for `anything' are:
593 \\{anything-map}")))
594 (pop-to-buffer "*Anything Help*")
595 (goto-char (point-min)))))
597 ;; Use `describe-mode' key in `global-map'
598 ;; (dolist (k (where-is-internal 'describe-mode global-map))
599 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
601 ;;; Help message
602 (defun anything-c-list-preconfigured-anything ()
603 (loop with doc
604 with sym
605 for entry in (cdr (assoc (locate-library "anything-config") load-history))
606 if (and (consp entry)
607 (eq (car entry) 'defun)
608 (string-match "^Preconfigured.+$"
609 (setq doc (or (documentation (setq sym (cdr entry)))
610 ""))))
611 collect (format "\\[%s] : %s\n" sym (match-string 0 doc))))
613 (setq anything-help-message
614 (concat
615 "\\<anything-map>"
616 "`anything' is QuickSilver-like candidate-selection framework.
618 Narrow the list by typing some pattern,
619 Multiple patterns are allowed by splitting by space.
620 Select with natural Emacs operations, choose with RET.
622 == Basic Operations ==
623 C-p, Up: Previous Line
624 C-n, Down : Next Line
625 M-v, PageUp : Previous Page
626 C-v, PageDown : Next Page
627 Enter : Execute first (default) action / Select
628 M-< : First Line
629 M-> : Last Line
630 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
631 M-PageDown, C-M-v : Next Page (other-window)
633 Tab, C-i : Show action list
634 Left : Previous Source
635 Right, C-o : Next Source
636 C-k : Delete pattern
637 C-z : Persistent Action (Execute action with anything session kept)
639 == Shortcuts For 2nd/3rd Action ==
640 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
641 \\[anything-select-3rd-action] : Execute 3rd Action
643 == Visible Marks ==
644 Visible marks store candidate. Some actions uses marked candidates.
646 \\[anything-toggle-visible-mark] : Toggle Visible Mark
647 \\[anything-prev-visible-mark] : Previous Mark
648 \\[anything-next-visible-mark] : Next Mark
650 == Miscellaneous Commands ==
651 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
652 \\[anything-quit-and-find-file] : Drop into `find-file'
653 \\[anything-delete-current-selection] : Delete Selected Item (visually)
654 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
655 \\[anything-yank-selection] : Yank Selected Item Into Pattern
656 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
657 \\[anything-force-update] : Recalculate And Redisplay Candidates
659 == Global Commands ==
660 \\<global-map>\\[anything-resume] revives last `anything' session.
661 It is very useful, so you should bind any key.
663 Simgle source is executed by \\[anything-call-source].
665 == Preconfigured `anything' ==
666 Preconfigured `anything' is commands that uses `anything' interface.
667 You can use them without configuration.
670 (apply 'concat (anything-c-list-preconfigured-anything))
672 Enjoy!"))
674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
675 (defun anything-for-files ()
676 "Preconfigured `anything' for opening files.
677 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
678 (interactive)
679 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
681 (defun anything-info-at-point ()
682 "Preconfigured `anything' for searching info at point."
683 (interactive)
684 (anything '(anything-c-source-info-elisp
685 anything-c-source-info-cl
686 anything-c-source-info-pages)
687 (thing-at-point 'symbol) nil nil nil "*anything info*"))
689 (defun anything-show-kill-ring ()
690 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
691 You may bind this command to M-y."
692 (interactive)
693 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
695 (defun anything-minibuffer-history ()
696 "Preconfigured `anything' for `minibuffer-history'."
697 (interactive)
698 (let ((enable-recursive-minibuffers t))
699 (anything-other-buffer 'anything-c-source-minibuffer-history
700 "*anything minibuffer-history*")))
702 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
703 ;; minibuffer-local-filename-must-match-map.
704 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
705 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
706 (dolist (map (list minibuffer-local-filename-completion-map
707 minibuffer-local-completion-map
708 minibuffer-local-must-match-filename-map
709 minibuffer-local-filename-must-match-map
710 minibuffer-local-map
711 minibuffer-local-isearch-map
712 minibuffer-local-must-match-map
713 minibuffer-local-ns-map))
714 (define-key map "\C-r" 'anything-minibuffer-history))
716 (defun anything-gentoo ()
717 "Preconfigured `anything' for gentoo linux."
718 (interactive)
719 (anything-other-buffer '(anything-c-source-gentoo
720 anything-c-source-use-flags)
721 "*anything gentoo*"))
723 (defun anything-surfraw-only ()
724 "Preconfigured `anything' for surfraw.
725 If region is marked set anything-pattern to region.
726 With one prefix arg search symbol at point.
727 With two prefix args allow choosing in which symbol to search."
728 (interactive)
729 (let (search pattern)
730 (cond ((region-active-p)
731 (setq pattern (buffer-substring (region-beginning) (region-end))))
732 ((equal current-prefix-arg '(4))
733 (setq pattern (thing-at-point 'symbol)))
734 ((equal current-prefix-arg '(16))
735 (setq search
736 (intern
737 (completing-read "Search in: "
738 (list "symbol" "sentence" "sexp" "line" "word"))))
739 (setq pattern (thing-at-point search))))
740 (anything 'anything-c-source-surfraw
741 (and pattern (replace-regexp-in-string "\n" "" pattern))
742 nil nil nil "*anything surfraw*")))
744 (defun anything-imenu ()
745 "Preconfigured `anything' for `imenu'."
746 (interactive)
747 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
749 (defun anything-google-suggest ()
750 "Preconfigured `anything' for google search with google suggest."
751 (interactive)
752 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
754 (defun anything-yahoo-suggest ()
755 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
756 (interactive)
757 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
759 ;;; Converted from anything-show-*-only
760 (defun anything-for-buffers ()
761 "Preconfigured `anything' for buffer."
762 (interactive)
763 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
765 (defun anything-bbdb ()
766 "Preconfigured `anything' for BBDB."
767 (interactive)
768 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
770 (defun anything-locate ()
771 "Preconfigured `anything' for Locate."
772 (interactive)
773 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
775 (defun anything-w3m-bookmarks ()
776 "Preconfigured `anything' for w3m bookmark."
777 (interactive)
778 (anything-other-buffer 'anything-c-source-w3m-bookmarks "*anything w3m bookmarks*"))
780 (defun anything-colors ()
781 "Preconfigured `anything' for color."
782 (interactive)
783 (anything-other-buffer '(anything-c-source-colors anything-c-source-customize-face)
784 "*anything colors*"))
786 (defun anything-bm-list ()
787 "Preconfigured `anything' for visible bookmarks."
788 (interactive)
789 (anything-other-buffer 'anything-c-source-bm "*anything bm list*"))
791 (defun anything-timers ()
792 "Preconfigured `anything' for timers."
793 (interactive)
794 (anything-other-buffer '(anything-c-source-absolute-time-timers
795 anything-c-source-idle-time-timers)
796 "*anything timers*"))
798 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
799 ;;; kill buffers
800 (defun anything-kill-buffers ()
801 "Preconfigured `anything' to kill buffer you selected."
802 (interactive)
803 (anything
804 '(((name . "Kill Buffers")
805 (candidates . anything-c-buffer-list)
806 (action
807 ("Kill Buffer" . (lambda (candidate)
808 (kill-buffer candidate)
809 (anything-kill-buffers)
810 )))))
811 nil nil))
813 ;;; Regexp
814 (defun anything-query-replace-regexp (&rest args)
815 "Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually."
816 (interactive
817 (let ((common
818 (anything-c-regexp-base "Query Replace Regexp: "
819 '((name . "Lines matching Regexp")
820 (mode-line . "Set replace start line and type RET.")
821 (action . anything-c-query-replace-args)))))
822 (if (not common)
823 (keyboard-quit))
824 (list (car common) (cadr common) (caddr common)
825 ;; These are done separately here
826 ;; so that command-history will record these expressions
827 ;; rather than the values they had this time.
829 ;; This idea is borrowed from original `query-replace-regexp'.
830 (if (and transient-mark-mode mark-active)
831 (region-beginning))
832 (if (and transient-mark-mode mark-active)
833 (region-end)))))
834 (apply 'query-replace-regexp args))
836 (defun anything-regexp ()
837 "Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement."
838 (interactive)
839 (anything-c-regexp-base
840 "Regexp: "
841 '((name . "Regexp Builder")
842 (mode-line . "Press TAB to select action.")
843 (action
844 ("Kill Regexp as sexp" .
845 (lambda (x) (anything-c-regexp-kill-new (prin1-to-string (funcall (anything-attr 'regexp))))))
846 ("Query Replace Regexp" .
847 (lambda (x) (apply 'query-replace-regexp (anything-c-query-replace-args (point)))))
848 ("Kill Regexp" .
849 (lambda (x) (anything-c-regexp-kill-new (funcall (anything-attr 'regexp)))))))))
851 (defun anything-c-query-replace-args (start-point)
852 ;; create arguments of `query-replace-regexp'.
853 (let ((region-only (and transient-mark-mode mark-active))
854 (regexp (funcall (anything-attr 'regexp))))
855 (list
856 regexp
857 (query-replace-read-to regexp
858 (format "Query replace regexp %s%s%s with: "
859 (if region-only "in region " "")
860 regexp
861 (if current-prefix-arg "(word) " ""))
863 current-prefix-arg)))
865 (defun anything-c-regexp-get-line (s e)
866 (propertize
867 (apply 'concat
868 ;; Line contents
869 (format "%5d: %s" (line-number-at-pos s) (buffer-substring s e))
870 ;; subexps
871 (loop for i from 0 to (1- (/ (length (match-data)) 2))
872 unless (zerop i)
873 collect (format "\n $%d = %s"
874 i (match-string i))))
875 ;; match beginning
876 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
877 ;; It is implementation problem of candidates-in-buffer.
878 'anything-realvalue
879 (1- s)))
881 ;; Shut up byte compiler
882 (defun anything-goto-line (numline)
883 "Replacement of `goto-line'."
884 (goto-char (point-min))
885 (forward-line (1- numline)))
887 (defun anything-c-regexp-persistent-action (pt)
888 (goto-char pt)
889 (anything-persistent-highlight-point))
891 (defun anything-c-regexp-base (prompt attributes)
892 (save-restriction
893 (let ((anything-compile-source-functions
894 ;; rule out anything-match-plugin because the input is one regexp.
895 (delq 'anything-compile-source--match-plugin
896 (copy-sequence anything-compile-source-functions)))
897 (base-attributes
898 '((init . (lambda () (anything-candidate-buffer anything-current-buffer)))
899 (candidates-in-buffer)
900 (get-line . anything-c-regexp-get-line)
901 (persistent-action . anything-c-regexp-persistent-action)
902 (persistent-help . "Show this line")
903 (multiline)
904 (delayed))))
905 (if (and transient-mark-mode mark-active)
906 (narrow-to-region (region-beginning) (region-end)))
907 (anything
908 (list
909 (append
910 attributes
911 '((regexp . (lambda () anything-pattern)))
912 base-attributes)
913 ;; sexp form regexp
914 (append
915 `((name . ,(concat (assoc-default 'name attributes) " (sexp)")))
916 attributes
917 '((candidates-in-buffer
918 . (lambda () (let ((anything-pattern (eval (read anything-pattern))))
919 (anything-candidates-in-buffer))))
920 (regexp . (lambda () (eval (read anything-pattern)))))
921 base-attributes))
922 nil prompt nil nil "*anything regexp*"))))
924 ;; (anything-c-regexp-base "Regexp: " '((name . "test")))
925 ;; (anything-c-regexp-base "Regexp: " '((name . "test") (candidates-in-buffer . (lambda () (let ((anything-pattern (eval (read anything-pattern)))) (anything-candidates-in-buffer))))))
927 (defun anything-c-regexp-kill-new (input)
928 (kill-new input)
929 (message "Killed: %s" input))
931 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
933 (defun anything-insert-buffer-name ()
934 "Insert buffer name."
935 (interactive)
936 (anything-insert-string
937 (with-current-buffer anything-current-buffer
938 (if buffer-file-name (file-name-nondirectory buffer-file-name)
939 (buffer-name)))))
941 (defun anything-insert-symbol ()
942 "Insert current symbol."
943 (interactive)
944 (anything-insert-string
945 (with-current-buffer anything-current-buffer
946 (save-excursion
947 (buffer-substring (beginning-of-thing 'symbol)
948 (end-of-thing 'symbol))))))
950 (defun anything-insert-selection ()
951 "Insert current selection."
952 (interactive)
953 (anything-insert-string
954 (with-current-buffer anything-current-buffer
955 (anything-get-selection))))
957 (defun anything-show-buffer-only ()
958 "[OBSOLETE] Only show sources about buffer.
959 Use `anything-for-buffers' instead."
960 (interactive)
961 (anything-set-source-filter '("Buffers")))
963 (defun anything-show-bbdb-only ()
964 "[OBSOLETE] Only show sources about BBDB.
965 Use `anything-bbdb' instead."
966 (interactive)
967 (anything-set-source-filter '("BBDB")))
969 (defun anything-show-locate-only ()
970 "[OBSOLETE] Only show sources about Locate.
971 Use `anything-locate' instead."
972 (interactive)
973 (anything-set-source-filter '("Locate")))
975 (defun anything-show-info-only ()
976 "[OBSOLETE] Only show sources about Info.
977 Use `anything-info-at-point' instead."
978 (interactive)
979 (anything-set-source-filter '("Info Pages"
980 "Info Elisp"
981 "Info Common-Lisp")))
983 (defun anything-show-imenu-only ()
984 "[OBSOLETE] Only show sources about Imenu.
985 Use `anything-imenu' instead."
986 (interactive)
987 (anything-set-source-filter '("Imenu")))
989 (defun anything-show-files-only ()
990 "[OBSOLETE] Only show sources about File.
991 Use `anything-for-files' instead."
992 (interactive)
993 (anything-set-source-filter '("File Name History"
994 "Files from Current Directory"
995 "Recentf")))
997 (defun anything-show-w3m-bookmarks-only ()
998 "[OBSOLETE] Only show source about w3m bookmark.
999 Use `anything-w3m-bookmarks' instead."
1000 (interactive)
1001 (anything-set-source-filter '("W3m Bookmarks")))
1003 (defun anything-show-colors-only ()
1004 "[OBSOLETE] Only show source about color.
1005 Use `anything-colors' instead."
1006 (interactive)
1007 (anything-set-source-filter '("Colors"
1008 "Customize Faces")))
1010 (defun anything-show-kill-ring-only ()
1011 "[OBSOLETE] Only show source about kill ring.
1012 Use `anything-show-kill-ring' instead."
1013 (interactive)
1014 (anything-set-source-filter '("Kill Ring")))
1016 (defun anything-show-this-source-only ()
1017 "Only show this source."
1018 (interactive)
1019 (setq anything-candidate-number-limit 9999)
1020 (anything-set-source-filter
1021 (list (assoc-default 'name (anything-get-current-source)))))
1023 (defun anything-test-sources ()
1024 "List all anything sources for test.
1025 The output is sexps which are evaluated by \\[eval-last-sexp]."
1026 (interactive)
1027 (with-output-to-temp-buffer "*Anything Test Sources*"
1028 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
1029 (apropos-internal "^anything-c-source" #'boundp))
1030 (pop-to-buffer standard-output)))
1032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1033 ;;; For compatibility
1034 (unless (fboundp 'region-active-p)
1035 (defun region-active-p ()
1036 "Return t if Transient Mark mode is enabled and the mark is active.
1038 Most commands that act on the region if it is active and
1039 Transient Mark mode is enabled, and on the text near point
1040 otherwise, should use `use-region-p' instead. That function
1041 checks the value of `use-empty-active-region' as well."
1042 (and transient-mark-mode mark-active)))
1044 (defun anything-nest (&rest same-as-anything)
1045 "Nested `anything'. If you use `anything' within `anything', use it."
1046 (with-selected-window (anything-window)
1047 (let (anything-current-position
1048 anything-current-buffer
1049 (orig-anything-buffer anything-buffer)
1050 anything-pattern
1051 anything-buffer
1052 anything-sources
1053 anything-compiled-sources
1054 anything-buffer-chars-modified-tick
1055 (anything-samewindow t)
1056 (enable-recursive-minibuffers t))
1057 (unwind-protect
1058 (apply #'anything same-as-anything)
1059 (anything-initialize-overlays orig-anything-buffer)
1060 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
1062 (defun anything-displaying-source-names ()
1063 "Display sources name."
1064 (with-current-buffer anything-buffer
1065 (goto-char (point-min))
1066 (loop with pos
1067 while (setq pos (next-single-property-change (point) 'anything-header))
1068 do (goto-char pos)
1069 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1070 do (forward-line 1))))
1072 (defun anything-select-source ()
1073 "Select source."
1074 (interactive)
1075 (let ((default (assoc-default 'name (anything-get-current-source)))
1076 (source-names (anything-displaying-source-names))
1077 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
1078 (anything-get-sources))))
1079 (setq anything-candidate-number-limit 9999)
1080 (anything-aif
1081 (let (anything-source-filter)
1082 (anything-nest '(((name . "Anything Source")
1083 (candidates . source-names)
1084 (action . identity))
1085 ((name . "Anything Source (ALL)")
1086 (candidates . all-source-names)
1087 (action . identity)))
1088 nil "Source: " nil
1089 default "*anything select source*"))
1090 (anything-set-source-filter (list it))
1091 (anything-set-source-filter nil))))
1093 (defun anything-insert-string (str)
1094 "Insert STR."
1095 (delete-minibuffer-contents)
1096 (insert str))
1098 (defun anything-c-match-on-file-name (candidate)
1099 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1100 (string-match anything-pattern (file-name-nondirectory candidate)))
1102 (defun anything-c-match-on-directory-name (candidate)
1103 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1104 (anything-aif (file-name-directory candidate)
1105 (string-match anything-pattern it)))
1107 (defun anything-c-string-match (candidate)
1108 "Return non-nil if `anything-pattern' match CANDIDATE.
1109 The match is done with `string-match'."
1110 (string-match anything-pattern candidate))
1112 ;; `anything-c-compose' is no more needed, it is for compatibility.
1113 (defalias 'anything-c-compose 'anything-compose)
1115 (defun anything-c-skip-entries (list regexp)
1116 "Remove entries which matches REGEXP from LIST."
1117 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
1118 list))
1120 (defun anything-c-shadow-entries (list regexp)
1121 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1122 (mapcar (lambda (file)
1123 ;; Add shadow face property to boring files.
1124 (let ((face (if (facep 'file-name-shadow)
1125 'file-name-shadow
1126 ;; fall back to default on XEmacs
1127 'default)))
1128 (if (string-match regexp file)
1129 (setq file (propertize file 'face face))))
1130 file)
1131 list))
1133 (defsubst anything-c-stringify (str-or-sym)
1134 "Get string of STR-OR-SYM."
1135 (if (stringp str-or-sym)
1136 str-or-sym
1137 (symbol-name str-or-sym)))
1139 (defsubst anything-c-symbolify (str-or-sym)
1140 "Get symbol of STR-OR-SYM."
1141 (if (symbolp str-or-sym)
1142 str-or-sym
1143 (intern str-or-sym)))
1145 (defun anything-c-describe-function (func)
1146 "FUNC is symbol or string."
1147 (describe-function (anything-c-symbolify func)))
1149 (defun anything-c-describe-variable (var)
1150 "VAR is symbol or string."
1151 (describe-variable (anything-c-symbolify var)))
1153 (defun anything-c-find-function (func)
1154 "FUNC is symbol or string."
1155 (find-function (anything-c-symbolify func)))
1157 (defun anything-c-find-variable (var)
1158 "VAR is symbol or string."
1159 (find-variable (anything-c-symbolify var)))
1161 (defun anything-c-kill-new (string &optional replace yank-handler)
1162 "STRING is symbol or string."
1163 (kill-new (anything-c-stringify string) replace yank-handler))
1165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1166 ;; TODO
1167 (defvar anything-current-prefix-arg nil
1168 "`current-prefix-arg' when selecting action.
1169 It is cleared after executing action.")
1171 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
1172 (unless anything-current-prefix-arg
1173 (setq anything-current-prefix-arg current-prefix-arg)))
1175 (add-hook 'anything-after-action-hook
1176 (lambda () (setq anything-current-prefix-arg nil)))
1179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1180 (defadvice eval-defun (after anything-source-hack activate)
1181 "See `anything-c-enable-eval-defun-hack'."
1182 (when anything-c-enable-eval-defun-hack
1183 (let ((varsym (save-excursion
1184 (beginning-of-defun)
1185 (forward-char 1)
1186 (when (memq (read (current-buffer)) '(defvar setq))
1187 (read (current-buffer))))))
1188 (when (string-match "^anything-c-source-" (symbol-name varsym))
1189 (anything varsym)))))
1190 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1193 (defun anything-c-create-summary ()
1194 "Create `anything' summary."
1195 (save-excursion
1196 (goto-char (point-min))
1197 (loop while (re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$" nil t)
1198 collect (cond ((match-beginning 1)
1199 (cons 'section (match-string-no-properties 1)))
1200 ((match-beginning 2)
1201 (cons 'source
1202 (cons (match-string-no-properties 2)
1203 (assoc-default 'name (symbol-value (intern (match-string-no-properties 2)))))))
1204 ((match-beginning 3)
1205 (cons 'source
1206 (cons (match-string-no-properties 3)
1207 (assoc-default 'name (symbol-value (intern (match-string-no-properties 3)))))))))))
1209 ;; (find-epp (anything-c-create-summary))
1211 (defun anything-c-insert-summary ()
1212 "Insert `anything' summary."
1213 (save-excursion
1214 (goto-char (point-min))
1215 (search-forward ";; Below are complete source list you can setup in")
1216 (forward-line 1)
1217 (delete-region (point)
1218 (progn (search-forward ";;; Change log:" nil t)
1219 (forward-line -1) (point)))
1220 (insert ";;\n")
1221 (loop with beg
1222 for (kind . value) in (anything-c-create-summary)
1223 for i from 0
1224 do (cond ((eq kind 'section)
1225 (unless (zerop i)
1226 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1227 (insert ";; " value ":\n")
1228 (setq beg (point)))
1230 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
1231 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
1232 ;; (anything-c-insert-summary)
1234 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1235 ;;;; <Buffer>
1236 (defun anything-c-buffer-list ()
1237 "Return the list of names of buffers with boring buffers filtered out.
1238 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1239 The first buffer in the list will be the last recently used
1240 buffer that is not the current buffer."
1241 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1242 (append (cdr buffers) (list (car buffers)))))
1244 (defvar anything-c-source-buffers
1245 '((name . "Buffers")
1246 (candidates . anything-c-buffer-list)
1247 (type . buffer)))
1248 ;; (anything 'anything-c-source-buffers)
1250 (defvar anything-c-source-buffer-not-found
1251 '((name . "Create buffer")
1252 (dummy)
1253 (type . buffer)))
1254 ;; (anything 'anything-c-source-buffer-not-found)
1256 ;;; Buffers+
1257 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1258 "*Face used for directory headings in dired buffers."
1259 :group 'anything)
1261 (defface anything-file-name
1262 '((t (:foreground "Blue")))
1263 "*Face used for file names (without suffixes) in dired buffers."
1264 :group 'anything)
1266 (defface anything-dir-priv
1267 '((t (:foreground "DarkRed" :background "LightGray")))
1268 "*Face used for directory privilege indicator (d) in dired buffers."
1269 :group 'anything)
1271 (defvar anything-c-buffers-face1 'anything-dir-priv)
1272 (defvar anything-c-buffers-face2 'font-lock-type-face)
1273 (defvar anything-c-buffers-face3 'italic)
1274 (eval-when-compile (require 'dired))
1275 (defun anything-c-highlight-buffers (buffers)
1276 (require 'dired)
1277 (loop for i in buffers
1278 if (rassoc (get-buffer i) dired-buffers)
1279 collect (propertize i
1280 'face anything-c-buffers-face1
1281 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1282 if (buffer-file-name (get-buffer i))
1283 collect (propertize i
1284 'face anything-c-buffers-face2
1285 'help-echo (buffer-file-name (get-buffer i)))
1286 if (and (not (rassoc (get-buffer i) dired-buffers))
1287 (not (buffer-file-name (get-buffer i))))
1288 collect (propertize i
1289 'face anything-c-buffers-face3)))
1291 (defvar anything-c-source-buffers+
1292 '((name . "Buffers")
1293 (candidates . anything-c-buffer-list)
1294 (type . buffer)
1295 (candidate-transformer anything-c-skip-current-buffer
1296 anything-c-highlight-buffers
1297 anything-c-skip-boring-buffers)
1298 (persistent-action . anything-c-buffers+-persistent-action)
1299 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1301 (defun anything-c-buffers+-persistent-action (name)
1302 (flet ((kill (item)
1303 (with-current-buffer item
1304 (if (and (buffer-modified-p)
1305 (buffer-file-name (current-buffer)))
1306 (progn
1307 (save-buffer)
1308 (kill-buffer item))
1309 (kill-buffer item))))
1310 (goto (item)
1311 (switch-to-buffer item)))
1312 (if current-prefix-arg
1313 (progn
1314 (kill name)
1315 (anything-delete-current-selection))
1316 (goto name))))
1318 ;; (anything 'anything-c-source-buffers+)
1321 ;;;; <File>
1322 ;;; File name history
1323 (defvar anything-c-source-file-name-history
1324 '((name . "File Name History")
1325 (candidates . file-name-history)
1326 (match anything-c-match-on-file-name
1327 anything-c-match-on-directory-name)
1328 (type . file)))
1329 ;; (anything 'anything-c-source-file-name-history)
1331 ;;; Files in current dir
1332 (defvar anything-c-source-files-in-current-dir
1333 '((name . "Files from Current Directory")
1334 (candidates . (lambda ()
1335 (with-current-buffer anything-current-buffer
1336 (directory-files default-directory))))
1337 ;; volatile is not needed, I think.
1338 (type . file)))
1339 ;; (anything 'anything-c-source-files-in-current-dir)
1341 (defvar anything-c-files-face1 'anything-dir-priv)
1342 (defvar anything-c-files-face2 'anything-file-name)
1343 (defun anything-c-highlight-files (files)
1344 (loop for i in files
1345 if (file-directory-p i)
1346 collect (propertize (file-name-nondirectory i)
1347 'face anything-c-files-face1
1348 'help-echo (expand-file-name i))
1349 else
1350 collect (propertize (file-name-nondirectory i)
1351 'face anything-c-files-face2
1352 'help-echo (expand-file-name i))))
1355 (defvar anything-c-source-files-in-current-dir+
1356 '((name . "Files from Current Directory")
1357 (candidates . (lambda ()
1358 (with-current-buffer anything-current-buffer
1359 (directory-files default-directory t))))
1360 (candidate-transformer anything-c-highlight-files)
1361 ;; volatile is not needed, I think.
1362 (type . file)))
1364 ;; (anything 'anything-c-source-files-in-current-dir+)
1366 ;;; Anything replacement of file name completion for `find-file' and friends.
1368 (defvar anything-c-find-files-doc-header (format " (`%s':Go to precedent level)"
1369 (if window-system "C-." "C-l"))
1370 "*The doc that is inserted in the Name header of a find-files or dired source.")
1372 (defvar anything-c-source-find-files
1373 `((name . ,(concat "Find Files" anything-c-find-files-doc-header))
1374 (init . (lambda ()
1375 (setq ffap-newfile-prompt t)))
1376 (candidates . anything-find-files-get-candidates)
1377 (candidate-transformer anything-c-highlight-ffiles)
1378 (persistent-action . anything-find-files-persistent-action)
1379 (persistent-help . "Expand Candidate")
1380 (volatile)
1381 (action . ,(delq nil `(("Find File" . find-file-at-point)
1382 ("Find file in Dired" . anything-c-point-file-in-dired)
1383 ,(and (locate-library "elscreen") '("Find file in Elscreen" . anything-elscreen-find-file))
1384 ("Complete at point" . anything-c-insert-file-name-completion-at-point)
1385 ("Delete File(s)" . anything-delete-marked-files)
1386 ("Find file as root" . anything-find-file-as-root)
1387 ("Find file other window" . find-file-other-window)
1388 ("Find file other frame" . find-file-other-frame))))))
1390 ;; (anything 'anything-c-source-find-files)
1392 (defun* anything-reduce-file-name (fname level &key unix-close expand)
1393 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1394 If LEVEL is positive reduce from end else from beginning.
1395 If UNIX-CLOSE is non--nil close filename with /.
1396 If EXPAND is non--nil expand-file-name."
1397 (let* ((exp-fname (expand-file-name fname))
1398 (fname-list (split-string (if (or (string= fname "~/") expand)
1399 exp-fname fname) "/" t))
1400 (len (length fname-list))
1401 (pop-list (if (< level 0)
1402 (subseq fname-list (* level -1))
1403 (subseq fname-list 0 (- len level))))
1404 (result (mapconcat 'identity pop-list "/"))
1405 (empty (string= result "")))
1406 (when unix-close (setq result (concat result "/")))
1407 (if (string-match "^~" result)
1408 (if (string= result "~/") "~/" result)
1409 (if (< level 0)
1410 (if empty "../" (concat "../" result))
1411 (cond ((and (eq system-type 'windows-nt) empty)
1412 "c:/")
1413 ((and (not empty) (eq system-type 'windows-nt))
1414 result)
1415 (empty "/")
1417 (concat "/" result)))))))
1419 (defun anything-find-files-or-dired-p ()
1420 "Test if current source is a dired or find-files source."
1421 (let ((ff-sources '("Find Files" "Copy Files"
1422 "Rename Files" "Symlink Files"
1423 "Hardlink Files" "Write File" "Insert File"))
1424 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
1425 (catch 'break
1426 (dolist (i ff-sources)
1427 (when (equal cur-source (concat i anything-c-find-files-doc-header))
1428 (throw 'break t))))))
1430 (defun anything-find-files-down-one-level (arg)
1431 "Go down one level like unix command `cd ..'.
1432 If prefix numeric arg is given go ARG level down."
1433 (interactive "p")
1434 (when (anything-find-files-or-dired-p)
1435 (let ((new-pattern (anything-reduce-file-name anything-pattern arg :unix-close t :expand t)))
1436 (with-selected-window (minibuffer-window)
1437 (delete-minibuffer-contents)
1438 (insert new-pattern)))))
1440 ;; `C-.' doesn't work in terms use `C-l' instead.
1441 (if window-system
1442 (define-key anything-map (kbd "C-.") 'anything-find-files-down-one-level)
1443 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))
1445 (defun anything-c-point-file-in-dired (file)
1446 "Put point on filename FILE in dired buffer."
1447 (dired (file-name-directory file))
1448 (dired-goto-file file))
1450 (defun anything-create-tramp-name (fname)
1451 "Build filename for `anything-pattern' like /su:: or /sudo::."
1452 (apply #'tramp-make-tramp-file-name
1453 (loop
1454 with v = (tramp-dissect-file-name fname)
1455 for i across v collect i)))
1457 (defun anything-find-files-get-candidates ()
1458 "Create candidate list for `anything-c-source-find-files'."
1459 (let ((path (cond ((string-match "^~" anything-pattern)
1460 (replace-match (getenv "HOME") nil t anything-pattern))
1461 ((string-match "/su::" anything-pattern)
1462 (let ((tramp-name (anything-create-tramp-name "/su::")))
1463 (replace-match tramp-name nil t anything-pattern)))
1464 ((string-match "/sudo::" anything-pattern)
1465 (let ((tramp-name (anything-create-tramp-name "/sudo::")))
1466 (replace-match tramp-name nil t anything-pattern)))
1467 (t anything-pattern)))
1468 (tramp-verbose anything-tramp-verbose) ; No tramp message when 0.
1469 ;; Don't try to tramp connect before entering the second ":".
1470 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:"))
1471 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1472 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1473 ;; and sorting.
1474 (flet ((tramp-handle-directory-files
1475 (directory &optional full match nosort files-only)
1476 "Like `directory-files' for Tramp files."
1477 ;; FILES-ONLY is valid for XEmacs only.
1478 (when (file-directory-p directory)
1479 (setq directory (file-name-as-directory (expand-file-name directory)))
1480 (let ((temp (nreverse (file-name-all-completions "" directory)))
1481 result item)
1483 (while temp
1484 (setq item (directory-file-name (pop temp)))
1485 (when (and (or (null match) (string-match match item))
1486 (or (null files-only)
1487 ;; Files only.
1488 (and (equal files-only t) (file-regular-p item))
1489 ;; Directories only.
1490 (file-directory-p item)))
1491 (push (if full (concat directory item) item)
1492 result)))
1493 (if nosort result (sort result 'string<))))))
1495 (set-text-properties 0 (length path) nil path)
1496 (setq anything-pattern path)
1497 (cond ((or (file-regular-p path)
1498 (and ffap-url-regexp (string-match ffap-url-regexp path)))
1499 (list path))
1500 ((string= anything-pattern "") (directory-files "/" t))
1501 ((file-directory-p path) (directory-files path t))
1503 (append
1504 (list path)
1505 (directory-files (file-name-directory path) t)))))))
1507 (defface anything-dired-symlink-face
1508 '((t (:foreground "DarkOrange")))
1509 "*Face used for symlinks in `anything-find-files'."
1510 :group 'anything)
1512 (defun anything-c-highlight-ffiles (files)
1513 "Candidate transformer for `anything-c-source-find-files'."
1514 (loop for i in files
1515 if (file-symlink-p i)
1516 collect (propertize i 'face 'anything-dired-symlink-face
1517 'help-echo (file-truename i)) into a
1518 if (file-directory-p i)
1519 collect (propertize i 'face anything-c-files-face1) into a
1520 else
1521 collect (propertize i 'face anything-c-files-face2) into a
1522 finally return a))
1524 (defun anything-find-files-persistent-action (candidate)
1525 "Open subtree CANDIDATE without quitting anything.
1526 If CANDIDATE is not a directory open this file."
1527 (flet ((insert-in-minibuffer (elm)
1528 (with-selected-window (minibuffer-window)
1529 (delete-minibuffer-contents)
1530 (set-text-properties 0 (length elm) nil elm)
1531 (insert elm))))
1532 (cond ((and (file-directory-p candidate) (file-symlink-p candidate))
1533 (insert-in-minibuffer (file-name-as-directory
1534 (file-truename
1535 (expand-file-name candidate)))))
1536 ((file-directory-p candidate)
1537 (insert-in-minibuffer (file-name-as-directory
1538 (expand-file-name candidate))))
1539 ((file-symlink-p candidate)
1540 (insert-in-minibuffer (file-truename candidate)))
1542 (let ((new-pattern (anything-get-selection anything-last-buffer)))
1543 (set-text-properties 0 (length new-pattern) nil new-pattern)
1544 (insert-in-minibuffer new-pattern))))))
1547 (defun anything-c-insert-file-name-completion-at-point (candidate)
1548 "Insert file name completion at point."
1549 (let* ((end (point))
1550 (guess (thing-at-point 'filename))
1551 (full-path-p (string-match (concat "^" (getenv "HOME")) guess)))
1552 (set-text-properties 0 (length candidate) nil candidate)
1553 (condition-case nil
1554 (when (file-exists-p (file-name-directory guess))
1555 (search-backward guess (- (point) (length guess)))
1556 (delete-region (point) end)
1557 (if full-path-p
1558 (insert (expand-file-name candidate))
1559 (insert (abbreviate-file-name candidate))))
1560 (error nil))))
1562 (defun anything-find-files ()
1563 "Preconfigured `anything' for `find-file'."
1564 (interactive)
1565 (let* ((fap (ffap-guesser))
1566 (file-p (and fap (file-exists-p fap)))
1567 (tap (thing-at-point 'filename))
1568 (input (if file-p (expand-file-name tap) fap)))
1569 (anything 'anything-c-source-find-files
1570 (or input (expand-file-name default-directory))
1571 "Find Files or Url: " nil nil "*Anything Find Files*")))
1573 ;;; Anything completion for `write-file'.==> C-x C-w
1574 (defvar anything-c-source-write-file
1575 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
1576 (candidates . anything-find-files-get-candidates)
1577 (candidate-transformer anything-c-highlight-ffiles)
1578 (persistent-action . anything-find-files-persistent-action)
1579 (persistent-help . "Expand Candidate")
1580 (volatile)
1581 (action .
1582 (("Write File" . (lambda (candidate)
1583 (write-file candidate 'confirm)))))))
1585 (defun anything-write-file ()
1586 "Preconfigured `anything' providing completion for `write-file'."
1587 (interactive)
1588 (anything 'anything-c-source-write-file
1589 (expand-file-name default-directory)
1590 "Write buffer to file: " nil nil "*Anything write file*"))
1592 ;;; Anything completion for `insert-file'.==> C-x i
1593 (defvar anything-c-source-insert-file
1594 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
1595 (candidates . anything-find-files-get-candidates)
1596 (candidate-transformer anything-c-highlight-ffiles)
1597 (persistent-action . anything-find-files-persistent-action)
1598 (persistent-help . "Expand Candidate")
1599 (volatile)
1600 (action .
1601 (("Insert File" . (lambda (candidate)
1602 (when (y-or-n-p (format "Really insert %s in %s "
1603 candidate anything-current-buffer))
1604 (insert-file candidate))))))))
1606 (defun anything-insert-file ()
1607 "Preconfigured `anything' providing completion for `insert-file'."
1608 (interactive)
1609 (anything 'anything-c-source-insert-file
1610 (expand-file-name default-directory)
1611 "Insert file here: " nil nil "*Anything insert file*"))
1613 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
1614 (defvar anything-c-source-copy-files
1615 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
1616 (candidates . anything-find-files-get-candidates)
1617 (candidate-transformer anything-c-highlight-ffiles)
1618 (persistent-action . anything-find-files-persistent-action)
1619 (persistent-help . "Expand Candidate")
1620 (volatile)
1621 (action .
1622 (("Copy File" . (lambda (candidate)
1623 (anything-dired-action candidate :action 'copy)))))))
1626 (defvar anything-c-source-rename-files
1627 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
1628 (candidates . anything-find-files-get-candidates)
1629 (candidate-transformer anything-c-highlight-ffiles)
1630 (persistent-action . anything-find-files-persistent-action)
1631 (persistent-help . "Expand Candidate")
1632 (volatile)
1633 (action .
1634 (("Rename File" . (lambda (candidate)
1635 (anything-dired-action candidate :action 'rename)))))))
1637 (defvar anything-c-source-symlink-files
1638 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
1639 (candidates . anything-find-files-get-candidates)
1640 (candidate-transformer anything-c-highlight-ffiles)
1641 (persistent-action . anything-find-files-persistent-action)
1642 (persistent-help . "Expand Candidate")
1643 (volatile)
1644 (action .
1645 (("Symlink File" . (lambda (candidate)
1646 (anything-dired-action candidate :action 'symlink)))
1647 ("RelSymlink File" . (lambda (candidate)
1648 (anything-dired-action candidate :action 'relsymlink)))))))
1651 (defvar anything-c-source-hardlink-files
1652 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
1653 (candidates . anything-find-files-get-candidates)
1654 (candidate-transformer anything-c-highlight-ffiles)
1655 (persistent-action . anything-find-files-persistent-action)
1656 (persistent-help . "Expand Candidate")
1657 (volatile)
1658 (action .
1659 (("Hardlink File" . (lambda (candidate)
1660 (anything-dired-action candidate :action 'hardlink)))))))
1662 (defun* anything-dired-action (candidate &key action)
1663 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
1664 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
1665 (let ((files (dired-get-marked-files))
1666 (fn (case action
1667 ('copy 'dired-copy-file)
1668 ('rename 'dired-rename-file)
1669 ('symlink 'make-symbolic-link)
1670 ('relsymlink 'dired-make-relative-symlink)
1671 ('hardlink 'dired-hardlink)))
1672 (marker (case action
1673 ((copy rename) dired-keep-marker-copy)
1674 ('symlink dired-keep-marker-symlink)
1675 ('relsymlink dired-keep-marker-relsymlink)
1676 ('hardlink dired-keep-marker-hardlink))))
1677 (dired-create-files
1678 fn (symbol-name action) files
1679 (if (file-directory-p candidate)
1680 ;; When CANDIDATE is a directory, build file-name in this directory.
1681 ;; Else we use CANDIDATE.
1682 #'(lambda (from)
1683 (expand-file-name (file-name-nondirectory from) candidate))
1684 #'(lambda (from) candidate))
1685 marker)))
1688 (defun* anything-dired-do-action-on-file (&key action)
1689 (let* ((files (dired-get-marked-files))
1690 (len (length files))
1691 (fname (if (> len 1)
1692 (format "* %d Files" len)
1693 (car files)))
1694 (source (case action
1695 ('copy 'anything-c-source-copy-files)
1696 ('rename 'anything-c-source-rename-files)
1697 ('symlink 'anything-c-source-symlink-files)
1698 ('hardlink 'anything-c-source-hardlink-files)))
1699 (prompt-fm (case action
1700 ('copy "Copy %s to: ")
1701 ('rename "Rename %s to: ")
1702 ('symlink "Symlink %s to: ")
1703 ('hardlink "Hardlink %s to: ")))
1704 (buffer (case action
1705 ('copy "*Anything Copy Files*")
1706 ('rename "*Anything Rename Files*")
1707 ('symlink "*Anything Symlink Files*")
1708 ('hardlink "*Anything Hardlink Files*"))))
1709 (anything source
1710 (or (dired-dwim-target-directory)
1711 (expand-file-name default-directory))
1712 (format prompt-fm fname) nil nil buffer)))
1715 (defun anything-dired-rename-file ()
1716 "Preconfigured `anything' to rename files from dired."
1717 (interactive)
1718 (anything-dired-do-action-on-file :action 'rename))
1720 (defun anything-dired-copy-file ()
1721 "Preconfigured `anything' to copy files from dired."
1722 (interactive)
1723 (anything-dired-do-action-on-file :action 'copy))
1725 (defun anything-dired-symlink-file ()
1726 "Preconfigured `anything' to symlink files from dired."
1727 (interactive)
1728 (anything-dired-do-action-on-file :action 'symlink))
1730 (defun anything-dired-hardlink-file ()
1731 "Preconfigured `anything' to hardlink files from dired."
1732 (interactive)
1733 (anything-dired-do-action-on-file :action 'hardlink))
1735 (defvar anything-dired-bindings nil)
1736 (defun anything-dired-bindings (&optional arg)
1737 "Replace usual dired commands `C' and `R' by anything ones.
1738 When call interactively toggle dired bindings and anything bindings.
1739 When call non--interactively with arg > 0, enable anything bindings.
1740 You can put (anything-dired-binding 1) in init file to enable anything bindings."
1741 (interactive)
1742 (if (or (when arg (> arg 0)) (not anything-dired-bindings))
1743 (progn
1744 (define-key dired-mode-map (kbd "C") 'anything-dired-copy-file)
1745 (define-key dired-mode-map (kbd "R") 'anything-dired-rename-file)
1746 (define-key dired-mode-map (kbd "S") 'anything-dired-symlink-file)
1747 (define-key dired-mode-map (kbd "H") 'anything-dired-hardlink-file)
1748 (setq anything-dired-bindings t))
1749 (define-key dired-mode-map (kbd "C") 'dired-do-copy)
1750 (define-key dired-mode-map (kbd "R") 'dired-do-rename)
1751 (define-key dired-mode-map (kbd "S") 'dired-do-symlink)
1752 (define-key dired-mode-map (kbd "H") 'dired-do-hardlink)
1753 (setq anything-dired-bindings nil)))
1755 ;;; File Cache
1756 (defvar anything-c-source-file-cache-initialized nil)
1758 (defvar anything-c-file-cache-files nil)
1760 (defvar anything-c-source-file-cache
1761 '((name . "File Cache")
1762 (init . (lambda ()
1763 (require 'filecache nil t)
1764 (unless anything-c-source-file-cache-initialized
1765 (setq anything-c-file-cache-files
1766 (loop for item in file-cache-alist append
1767 (destructuring-bind (base &rest dirs) item
1768 (loop for dir in dirs collect
1769 (concat dir base)))))
1770 (defadvice file-cache-add-file (after file-cache-list activate)
1771 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
1772 (setq anything-c-source-file-cache-initialized t))))
1773 (candidates . anything-c-file-cache-files)
1774 (match anything-c-match-on-file-name
1775 anything-c-match-on-directory-name)
1776 (type . file)))
1777 ;; (anything 'anything-c-source-file-cache)
1779 ;;; Locate
1780 (defvar anything-c-locate-options
1781 (cond
1782 ((eq system-type 'darwin) '("locate"))
1783 ((eq system-type 'berkeley-unix) '("locate" "-i"))
1784 (t '("locate" "-i" "-r")))
1785 "A list where the `car' is the name of the locat program followed by options.
1786 The search pattern will be appended, so the
1787 \"-r\" option should be the last option.")
1789 (defvar anything-c-source-locate
1790 '((name . "Locate")
1791 (candidates . (lambda ()
1792 (apply 'start-process "locate-process" nil
1793 (append anything-c-locate-options
1794 (list anything-pattern)))))
1795 (type . file)
1796 (requires-pattern . 3)
1797 (delayed))
1798 "Source for retrieving files matching the current input pattern with locate.")
1799 ;; (anything 'anything-c-source-locate)
1801 ;;; Recentf files
1802 (defvar anything-c-source-recentf
1803 '((name . "Recentf")
1804 (init . (lambda ()
1805 (require 'recentf)
1806 (or recentf-mode (recentf-mode 1))
1807 ;; Big value empowers anything/recentf
1808 (when (and (numberp recentf-max-saved-items)
1809 (<= recentf-max-saved-items 20))
1810 (setq recentf-max-saved-items 500))))
1811 (candidates . recentf-list)
1812 (match anything-c-match-on-file-name
1813 anything-c-match-on-directory-name)
1814 (type . file))
1815 "See (info \"(emacs)File Conveniences\").
1816 if `recentf-max-saved-items' is too small, set it to 500.")
1817 ;; (anything 'anything-c-source-recentf)
1819 ;;; ffap
1820 (eval-when-compile (require 'ffap))
1821 (defvar anything-c-source-ffap-guesser
1822 '((name . "File at point")
1823 (init . (lambda () (require 'ffap)))
1824 (candidates . (lambda ()
1825 (anything-aif
1826 (with-current-buffer anything-current-buffer
1827 (ffap-guesser))
1828 (list it))))
1829 (type . file)))
1830 ;; (anything 'anything-c-source-ffap-guesser)
1832 ;;; ffap with line number
1833 (defun anything-c-ffap-file-line-at-point ()
1834 "Get (FILENAME . LINENO) at point."
1835 (anything-aif (let (ffap-alist) (ffap-file-at-point))
1836 (save-excursion
1837 (beginning-of-line)
1838 (when (and (search-forward it nil t)
1839 (looking-at ":\\([0-9]+\\)"))
1840 (cons it (string-to-number (match-string 1)))))))
1842 (defvar anything-c-ffap-line-location nil
1843 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
1844 It is cleared after jumping line.")
1846 (defun anything-c-ffap-line-candidates ()
1847 (with-current-buffer anything-current-buffer
1848 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
1849 (when anything-c-ffap-line-location
1850 (destructuring-bind (file . line) anything-c-ffap-line-location
1851 (list (cons (format "%s (line %d)" file line) file)))))
1853 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
1854 (defun anything-c-ffap-line-goto-line ()
1855 (when (car anything-c-ffap-line-location)
1856 (unwind-protect
1857 (ignore-errors
1858 (with-selected-window (get-buffer-window
1859 (get-file-buffer (car anything-c-ffap-line-location)))
1860 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
1861 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
1862 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
1864 (defvar anything-c-source-ffap-line
1865 '((name . "File/Lineno at point")
1866 (init . (lambda () (require 'ffap)))
1867 (candidates . anything-c-ffap-line-candidates)
1868 (type . file)))
1869 ;; (anything 'anything-c-source-ffap-line)
1871 ;;; list of files gleaned from every dired buffer
1872 (defun anything-c-files-in-all-dired-candidates ()
1873 (save-excursion
1874 (mapcan
1875 (lambda (dir)
1876 (cond ((listp dir) ;filelist
1877 dir)
1878 ((equal "" (file-name-nondirectory dir)) ;dir
1879 (directory-files dir t))
1880 (t ;wildcard
1881 (file-expand-wildcards dir t))))
1882 (delq nil
1883 (mapcar (lambda (buf)
1884 (set-buffer buf)
1885 (when (eq major-mode 'dired-mode)
1886 (if (consp dired-directory)
1887 (cdr dired-directory) ;filelist
1888 dired-directory))) ;dir or wildcard
1889 (buffer-list))))))
1890 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
1892 (defvar anything-c-source-files-in-all-dired
1893 '((name . "Files in all dired buffer.")
1894 (candidates . anything-c-files-in-all-dired-candidates)
1895 (type . file)))
1896 ;; (anything 'anything-c-source-files-in-all-dired)
1898 ;;;; <Help>
1899 ;;; Man Pages
1900 (defvar anything-c-man-pages nil
1901 "All man pages on system.
1902 Will be calculated the first time you invoke anything with this
1903 source.")
1905 (defvar anything-c-source-man-pages
1906 `((name . "Manual Pages")
1907 (candidates . (lambda ()
1908 (if anything-c-man-pages
1909 anything-c-man-pages
1910 ;; XEmacs doesn't have a woman :)
1911 (setq anything-c-man-pages
1912 (ignore-errors
1913 (require 'woman)
1914 (woman-file-name "")
1915 (sort (mapcar 'car woman-topic-all-completions)
1916 'string-lessp))))))
1917 (action ("Show with Woman" . woman))
1918 ;; Woman does not work OS X
1919 ;; http://xahlee.org/emacs/modernization_man_page.html
1920 (action-transformer . (lambda (actions candidate)
1921 (if (eq system-type 'darwin)
1922 '(("Show with Man" . man))
1923 actions)))
1924 (requires-pattern . 2)))
1925 ;; (anything 'anything-c-source-man-pages)
1927 ;;; Info pages
1928 (defvar anything-c-info-pages nil
1929 "All info pages on system.
1930 Will be calculated the first time you invoke anything with this
1931 source.")
1933 (defvar anything-c-source-info-pages
1934 `((name . "Info Pages")
1935 (candidates . (lambda ()
1936 (if anything-c-info-pages
1937 anything-c-info-pages
1938 (setq anything-c-info-pages
1939 (save-window-excursion
1940 (save-excursion
1941 (require 'info)
1942 (Info-find-node "dir" "top")
1943 (goto-char (point-min))
1944 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
1945 topics)
1946 (while (re-search-forward info-topic-regexp nil t)
1947 (add-to-list 'topics (match-string-no-properties 1)))
1948 (goto-char (point-min))
1949 (Info-exit)
1950 topics)))))))
1951 (action . (("Show with Info" .(lambda (node-str)
1952 (info (replace-regexp-in-string "^[^:]+: "
1954 node-str))))))
1955 (requires-pattern . 2)))
1956 ;; (anything 'anything-c-source-info-pages)
1958 ;; Info Elisp
1959 (defvar anything-c-info-elisp nil)
1960 (defvar anything-c-source-info-elisp
1961 `((name . "Info Elisp")
1962 (init . (lambda ()
1963 (save-window-excursion
1964 (unless anything-c-info-elisp
1965 (with-temp-buffer
1966 (Info-find-node "elisp" "Index")
1967 (setq anything-c-info-elisp (split-string (buffer-string) "\n"))
1968 (Info-exit))))))
1969 (candidates . (lambda ()
1970 (loop for i in anything-c-info-elisp
1971 if (string-match "^* [^ \n]+[^: ]" i)
1972 collect (match-string 0 i))))
1973 (action . (lambda (candidate)
1974 (Info-find-node "elisp" "Index")
1975 (Info-index (replace-regexp-in-string "* " "" candidate))))
1976 (requires-pattern . 2)))
1977 ;; (anything 'anything-c-source-info-elisp)
1979 ;; Info-Common-Lisp
1980 (defvar anything-c-info-cl-fn nil)
1981 (defvar anything-c-source-info-cl
1982 `((name . "Info Common-Lisp")
1983 (init . (lambda ()
1984 (save-window-excursion
1985 (unless anything-c-info-cl-fn
1986 (with-temp-buffer
1987 (Info-find-node "cl" "Function Index")
1988 (setq anything-c-info-cl-fn (split-string (buffer-string) "\n"))
1989 (Info-exit))))))
1990 (candidates . (lambda ()
1991 (loop for i in anything-c-info-cl-fn
1992 if (string-match "^* [^ \n]+[^: ]" i)
1993 collect (match-string 0 i))))
1994 (action . (lambda (candidate)
1995 (Info-find-node "cl" "Function Index")
1996 (Info-index (replace-regexp-in-string "* " "" candidate))))
1997 (requires-pattern . 2)))
1998 ;; (anything 'anything-c-source-info-cl)
2000 ;;;; <Command>
2001 ;;; Complex command history
2002 (defvar anything-c-source-complex-command-history
2003 '((name . "Complex Command History")
2004 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
2005 (type . sexp)))
2006 ;; (anything 'anything-c-source-complex-command-history)
2008 ;;; M-x history
2009 (defvar anything-c-source-extended-command-history
2010 '((name . "Emacs Commands History")
2011 (candidates . extended-command-history)
2012 (type . command)))
2013 ;; (anything 'anything-c-source-extended-command-history)
2015 ;;; Emacs commands
2016 (defvar anything-c-source-emacs-commands
2017 '((name . "Emacs Commands")
2018 (candidates . (lambda ()
2019 (let (commands)
2020 (mapatoms (lambda (a)
2021 (if (commandp a)
2022 (push (symbol-name a)
2023 commands))))
2024 (sort commands 'string-lessp))))
2025 (type . command)
2026 (requires-pattern . 2))
2027 "Source for completing and invoking Emacs commands.
2028 A command is a function with interactive spec that can
2029 be invoked with `M-x'.
2031 To get non-interactive functions listed, use
2032 `anything-c-source-emacs-functions'.")
2033 ;; (anything 'anything-c-source-emacs-commands)
2035 ;;; LaCarte
2036 (defvar anything-c-source-lacarte
2037 '((name . "Lacarte")
2038 (init . (lambda () (require 'lacarte )))
2039 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2040 (candidate-number-limit . 9999)
2041 (action . anything-c-call-interactively))
2042 "Needs lacarte.el.
2044 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2045 ;; (anything 'anything-c-source-lacarte)
2047 ;;;; <Function>
2048 ;;; Emacs functions
2049 (defvar anything-c-source-emacs-functions
2050 '((name . "Emacs Functions")
2051 (candidates . (lambda ()
2052 (let (commands)
2053 (mapatoms (lambda (a) (if (functionp a)
2054 (push (symbol-name a) commands))))
2055 (sort commands 'string-lessp))))
2056 (type . function)
2057 (requires-pattern . 2))
2058 "Source for completing Emacs functions.")
2059 ;; (anything 'anything-c-source-emacs-functions)
2061 ;;; With abbrev expansion
2062 ;;; Similar to my exec-abbrev-cmd.el
2063 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2064 (defvar anything-c-function-abbrev-regexp nil
2065 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2066 Regexp built from the current `anything-pattern' interpreting it
2067 as abbreviation.
2068 Only for internal use.")
2070 (defun anything-c-match-function-by-abbrev (candidate)
2071 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2073 Abbreviations are made by taking the first character from each
2074 word in the function's name, e.g. \"bb\" is an abbrev for
2075 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2076 (string-match anything-c-function-abbrev-regexp candidate))
2078 (defvar anything-c-source-emacs-functions-with-abbrevs
2079 (append anything-c-source-emacs-functions
2080 '((match anything-c-match-function-by-abbrev
2081 anything-c-string-match))
2082 '((init . (lambda ()
2083 (defadvice anything-update
2084 (before anything-c-update-function-abbrev-regexp activate)
2085 (let ((char-list (append anything-pattern nil))
2086 (str "^"))
2087 (dolist (c char-list)
2088 (setq str (concat str (list c) "[^-]*-")))
2089 (setq str (concat (substring str 0 (1- (length str))) "$"))
2090 (setq anything-c-function-abbrev-regexp str))))))))
2091 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2093 ;;;; <Variable>
2094 ;;; Emacs variables
2095 (defvar anything-c-source-emacs-variables
2096 '((name . "Emacs Variables")
2097 (candidates . (lambda ()
2098 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
2099 (type . variable)
2100 (requires-pattern . 2))
2101 "Source for completing Emacs variables.")
2102 ;; (anything 'anything-c-source-emacs-variables)
2104 ;;;; <Bookmark>
2105 ;;; Bookmarks
2106 (eval-when-compile (require 'bookmark))
2107 (defvar anything-c-source-bookmarks
2108 '((name . "Bookmarks")
2109 (init . (lambda ()
2110 (require 'bookmark)))
2111 (candidates . bookmark-all-names)
2112 (type . bookmark))
2113 "See (info \"(emacs)Bookmarks\").")
2114 ;; (anything 'anything-c-source-bookmarks)
2116 ;;; bookmark-set
2117 (defvar anything-c-source-bookmark-set
2118 '((name . "Set Bookmark")
2119 (dummy)
2120 (action . bookmark-set))
2121 "See (info \"(emacs)Bookmarks\").")
2122 ;; (anything 'anything-c-source-bookmark-set)
2124 ;;; Visible Bookmarks
2125 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2128 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2129 (defvar anything-c-source-bm
2130 '((name . "Visible Bookmarks")
2131 (init . anything-c-bm-init)
2132 (candidates-in-buffer)
2133 (type . line))
2134 "Needs bm.el.
2136 http://www.nongnu.org/bm/")
2138 (defun anything-c-bm-init ()
2139 "Init function for `anything-c-source-bm'."
2140 (when (require 'bm nil t)
2141 (with-no-warnings
2142 (let ((bookmarks (bm-lists))
2143 (buf (anything-candidate-buffer 'global)))
2144 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
2145 '< :key 'overlay-start))
2146 (let ((start (overlay-start bm))
2147 (end (overlay-end bm))
2148 (annotation (or (overlay-get bm 'annotation) "")))
2149 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
2150 (let ((str (format "%7d: [%s]: %s\n"
2151 (line-number-at-pos start)
2152 annotation
2153 (buffer-substring start (1- end)))))
2154 (with-current-buffer buf (insert str))))))))))
2156 ;;; Special bookmarks
2157 (defvar anything-c-source-bookmarks-ssh
2158 '((name . "Bookmarks-ssh")
2159 (init . (lambda ()
2160 (require 'bookmark)))
2161 ;; DRY
2162 (candidates . (lambda ()
2163 (let (lis-all lis-ssh)
2164 (setq lis-all (bookmark-all-names))
2165 (setq lis-ssh (loop for i in lis-all
2166 if (string-match "^(ssh)" i)
2167 collect i))
2168 (sort lis-ssh 'string-lessp))))
2169 (type . bookmark))
2170 "See (info \"(emacs)Bookmarks\").")
2171 ;; (anything 'anything-c-source-bookmarks-ssh)
2173 (defvar anything-c-source-bookmarks-su
2174 '((name . "Bookmarks-root")
2175 (init . (lambda ()
2176 (require 'bookmark)))
2177 ;; DRY
2178 (candidates . (lambda ()
2179 (let (lis-all lis-su)
2180 (setq lis-all (bookmark-all-names))
2181 (setq lis-su (loop for i in lis-all
2182 if (string-match (format "^(%s)" anything-su-or-sudo) i)
2183 collect i))
2184 (sort lis-su 'string-lessp))))
2185 (candidate-transformer anything-c-highlight-bookmark-su)
2187 (type . bookmark))
2188 "See (info \"(emacs)Bookmarks\").")
2189 ;; (anything 'anything-c-source-bookmarks-su)
2192 (defun tv-root-logged-p ()
2193 (catch 'break
2194 (dolist (i (mapcar #'buffer-name (buffer-list)))
2195 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
2196 (throw 'break t)))))
2199 (defun anything-c-highlight-bookmark-su (files)
2200 (if (tv-root-logged-p)
2201 (anything-c-highlight-bookmark files)
2202 (anything-c-highlight-not-logged files)))
2204 (defun anything-c-highlight-not-logged (files)
2205 (loop for i in files
2206 collect (propertize i 'face anything-c-bookmarks-face3)))
2208 (defun anything-c-highlight-bookmark (bookmarks)
2209 "Used as `candidate-transformer' to colorize bookmarks.
2210 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2211 (loop for i in bookmarks
2212 for pred = (bookmark-get-filename i)
2213 for bufp = (and (fboundp 'bmkext-get-buffer-name)
2214 (bmkext-get-buffer-name i))
2215 for regp = (and (fboundp 'bmkext-get-end-position)
2216 (bmkext-get-end-position i)
2217 (/= (bookmark-get-position i)
2218 (bmkext-get-end-position i)))
2219 for handlerp = (and (fboundp 'bookmark-get-handler)
2220 (bookmark-get-handler i))
2221 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
2222 (bmkext-w3m-bookmark-p i))
2223 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
2224 (bmkext-gnus-bookmark-p i))
2225 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
2226 (bmkext-man-bookmark-p i))
2227 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
2228 (bmkext-woman-bookmark-p i))
2229 for handlerp = (bookmark-get-handler i)
2230 for isannotation = (bookmark-get-annotation i)
2231 ;; Add a * if bookmark have annotation
2232 if (and isannotation (not (string-equal isannotation "")))
2233 do (setq i (concat "*" i))
2234 ;; info buffers
2235 if (eq handlerp 'Info-bookmark-jump)
2236 collect (propertize i 'face 'anything-bmkext-info 'help-echo pred)
2237 ;; w3m buffers
2238 if isw3m
2239 collect (propertize i 'face 'anything-bmkext-w3m 'help-echo pred)
2240 ;; gnus buffers
2241 if isgnus
2242 collect (propertize i 'face 'anything-bmkext-gnus 'help-echo pred)
2243 ;; Man Woman
2244 if (or iswoman isman)
2245 collect (propertize i 'face 'anything-bmkext-man 'help-echo pred)
2246 ;; directories
2247 if (and pred (file-directory-p pred))
2248 collect (propertize i 'face anything-c-bookmarks-face1 'help-echo pred)
2249 ;; regular files with regions saved
2250 if (and pred (not (file-directory-p pred)) (file-exists-p pred) regp)
2251 collect (propertize i 'face 'anything-bmkext-region 'help-echo pred)
2252 ;; regular files
2253 if (and pred (not (file-directory-p pred)) (file-exists-p pred)
2254 (not regp) (not (or iswoman isman)))
2255 collect (propertize i 'face 'anything-bmkext-file 'help-echo pred)
2256 ;; buffer non--filename
2257 if (and (fboundp 'bmkext-get-buffer-name) bufp (not handlerp)
2258 (if pred (not (file-exists-p pred)) (not pred)))
2259 collect (propertize i 'face 'anything-bmkext-no--file)))
2261 ;;; Faces for bookmarks
2262 (defface anything-bmkext-info
2263 '((t (:foreground "green")))
2264 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2265 :group 'anything)
2267 (defface anything-bmkext-w3m
2268 '((t (:foreground "yellow")))
2269 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2270 :group 'anything)
2272 (defface anything-bmkext-gnus
2273 '((t (:foreground "magenta")))
2274 "*Face used for Gnus bookmarks."
2275 :group 'anything)
2277 (defface anything-bmkext-man
2278 '((t (:foreground "Orange4")))
2279 "*Face used for Woman/man bookmarks."
2280 :group 'anything)
2282 (defface anything-bmkext-region
2283 '((t (:foreground "Indianred2")))
2284 "*Face used for region bookmarks."
2285 :group 'anything)
2287 (defface anything-bmkext-no--file
2288 '((t (:foreground "grey")))
2289 "*Face used for non--file bookmarks."
2290 :group 'anything)
2292 (defface anything-bmkext-file
2293 '((t (:foreground "Deepskyblue2")))
2294 "*Face used for non--file bookmarks."
2295 :group 'anything)
2297 (defface anything-bookmarks-su-face '((t (:foreground "red")))
2298 "Face for su/sudo bookmarks."
2299 :group 'anything)
2301 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
2302 (defvar anything-c-bookmarks-face2 'anything-file-name)
2303 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
2305 (defvar anything-c-source-bookmarks-local
2306 '((name . "Bookmarks-Local")
2307 (init . (lambda ()
2308 (require 'bookmark)))
2309 ;; DRY
2310 (candidates . (lambda ()
2311 (let (lis-all lis-loc)
2312 (setq lis-all (bookmark-all-names))
2313 (setq lis-loc (loop for i in lis-all
2314 if (and (not (string-match "^(ssh)" i))
2315 (not (string-match "^(su)" i)))
2316 collect i))
2317 (sort lis-loc 'string-lessp))))
2318 (candidate-transformer anything-c-highlight-bookmark)
2319 (type . bookmark))
2320 "See (info \"(emacs)Bookmarks\").")
2321 ;; (anything 'anything-c-source-bookmarks-local)
2323 ;;; Sources to filter bookmark-extensions bookmarks.
2324 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
2327 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
2328 "Return a filtered `bookmark-alist' sorted alphabetically."
2329 (loop
2330 with alist = (if args
2331 (apply #'(lambda (x) (funcall fn x)) args)
2332 (funcall fn))
2333 for i in alist
2334 for b = (car i)
2335 collect b into sa
2336 finally return (sort sa 'string-lessp)))
2338 ;; Regions
2339 (defvar anything-c-source-bookmark-regions
2340 '((name . "Bookmark Regions")
2341 (init . (lambda ()
2342 (require 'bookmark-extensions)
2343 (bookmark-maybe-load-default-file)))
2344 (candidates . anything-c-bookmark-region-setup-alist)
2345 (candidate-transformer anything-c-highlight-bookmark)
2346 (filtered-candidate-transformer . anything-c-adaptive-sort)
2347 (type . bookmark)))
2348 ;; (anything 'anything-c-source-bookmark-regions)
2350 (defun anything-c-bookmark-region-setup-alist ()
2351 "Specialized filter function for bookmarks regions."
2352 (anything-c-bmkext-filter-setup-alist 'bmkext-region-alist-only))
2354 ;; W3m
2355 (defvar anything-c-source-bookmark-w3m
2356 '((name . "Bookmark W3m")
2357 (init . (lambda ()
2358 (require 'bookmark-extensions)
2359 (bookmark-maybe-load-default-file)))
2360 (candidates . anything-c-bookmark-w3m-setup-alist)
2361 (candidate-transformer anything-c-highlight-bookmark)
2362 (filtered-candidate-transformer . anything-c-adaptive-sort)
2363 (type . bookmark)))
2364 ;; (anything 'anything-c-source-bookmark-w3m)
2366 (defun anything-c-bookmark-w3m-setup-alist ()
2367 "Specialized filter function for bookmarks w3m."
2368 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
2370 ;; Woman Man
2371 (defvar anything-c-source-bookmark-man
2372 '((name . "Bookmark Woman&Man")
2373 (init . (lambda ()
2374 (require 'bookmark-extensions)
2375 (bookmark-maybe-load-default-file)))
2376 (candidates . anything-c-bookmark-man-setup-alist)
2377 (candidate-transformer anything-c-highlight-bookmark)
2378 (filtered-candidate-transformer . anything-c-adaptive-sort)
2379 (type . bookmark)))
2380 ;; (anything 'anything-c-source-bookmark-man)
2382 (defun anything-c-bookmark-man-setup-alist ()
2383 "Specialized filter function for bookmarks w3m."
2384 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
2385 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
2387 ;; Gnus
2388 (defvar anything-c-source-bookmark-gnus
2389 '((name . "Bookmark Gnus")
2390 (init . (lambda ()
2391 (require 'bookmark-extensions)
2392 (bookmark-maybe-load-default-file)))
2393 (candidates . anything-c-bookmark-gnus-setup-alist)
2394 (candidate-transformer anything-c-highlight-bookmark)
2395 (filtered-candidate-transformer . anything-c-adaptive-sort)
2396 (type . bookmark)))
2397 ;; (anything 'anything-c-source-bookmark-gnus)
2399 (defun anything-c-bookmark-gnus-setup-alist ()
2400 "Specialized filter function for bookmarks gnus."
2401 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
2403 ;; Info
2404 (defvar anything-c-source-bookmark-info
2405 '((name . "Bookmark Info")
2406 (init . (lambda ()
2407 (require 'bookmark-extensions)
2408 (bookmark-maybe-load-default-file)))
2409 (candidates . anything-c-bookmark-info-setup-alist)
2410 (candidate-transformer anything-c-highlight-bookmark)
2411 (filtered-candidate-transformer . anything-c-adaptive-sort)
2412 (type . bookmark)))
2413 ;; (anything 'anything-c-source-bookmark-info)
2415 (defun anything-c-bookmark-info-setup-alist ()
2416 "Specialized filter function for bookmarks info."
2417 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
2419 ;; Local Files&directories
2420 (defvar anything-c-source-bookmark-files&dirs
2421 '((name . "Bookmark Files&Directories")
2422 (init . (lambda ()
2423 (require 'bookmark-extensions)
2424 (bookmark-maybe-load-default-file)))
2425 (candidates . anything-c-bookmark-local-files-setup-alist)
2426 (candidate-transformer anything-c-highlight-bookmark)
2427 (filtered-candidate-transformer . anything-c-adaptive-sort)
2428 (type . bookmark)))
2429 ;; (anything 'anything-c-source-bookmark-files&dirs)
2431 (defun anything-c-bookmark-local-files-setup-alist ()
2432 "Specialized filter function for bookmarks locals files."
2433 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
2435 ;; Su Files&directories
2436 (defun anything-c-highlight-bmkext-su (bmk)
2437 (if (bmkext-root-or-sudo-logged-p)
2438 (anything-c-highlight-bookmark bmk)
2439 (anything-c-highlight-not-logged bmk)))
2441 (defvar anything-c-source-bookmark-su-files&dirs
2442 '((name . "Bookmark Root-Files&Directories")
2443 (init . (lambda ()
2444 (require 'bookmark-extensions)
2445 (bookmark-maybe-load-default-file)))
2446 (candidates . anything-c-bookmark-su-files-setup-alist)
2447 (candidate-transformer anything-c-highlight-bmkext-su)
2448 (filtered-candidate-transformer . anything-c-adaptive-sort)
2449 (type . bookmark)))
2450 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
2452 (defun anything-c-bookmark-su-files-setup-alist ()
2453 "Specialized filter function for bookmarks su/sudo files."
2454 (loop
2455 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
2456 for i in l
2457 for isfile = (bookmark-get-filename i)
2458 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
2459 (save-match-data
2460 (string-match tramp-file-name-regexp isfile)))
2461 for issu = (and istramp
2462 (string-match bmkext-su-or-sudo-regexp isfile))
2463 if issu
2464 collect i))
2466 ;; Ssh Files&directories
2467 (defvar anything-c-source-bookmark-ssh-files&dirs
2468 '((name . "Bookmark Ssh-Files&Directories")
2469 (init . (lambda ()
2470 (require 'bookmark-extensions)
2471 (bookmark-maybe-load-default-file)))
2472 (candidates . anything-c-bookmark-ssh-files-setup-alist)
2473 (filtered-candidate-transformer . anything-c-adaptive-sort)
2474 (type . bookmark)))
2475 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
2477 (defun anything-c-bookmark-ssh-files-setup-alist ()
2478 "Specialized filter function for bookmarks ssh files."
2479 (loop
2480 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
2481 for i in l
2482 for isfile = (bookmark-get-filename i)
2483 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
2484 (save-match-data
2485 (string-match tramp-file-name-regexp isfile)))
2486 for isssh = (and istramp
2487 (string-match "/ssh:" isfile))
2488 if isssh
2489 collect i))
2492 ;; All bookmark-extensions sources.
2493 (defun anything-bookmark-ext ()
2494 "Preconfigured `anything' for bookmark-extensions sources.
2495 See: <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>."
2496 (interactive)
2497 (anything '(anything-c-source-bookmark-files&dirs
2498 anything-c-source-bookmark-w3m
2499 anything-c-source-bookmark-gnus
2500 anything-c-source-bookmark-info
2501 anything-c-source-bookmark-man
2502 anything-c-source-bookmark-regions
2503 anything-c-source-bookmark-su-files&dirs
2504 anything-c-source-bookmark-ssh-files&dirs)))
2507 ;; Firefox bookmarks
2508 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
2509 ;; (only for firefox versions >=3)
2510 ;; To achieve that, open about:config in firefox and double click on this line to enable value
2511 ;; to true:
2512 ;; user_pref("browser.bookmarks.autoExportHTML", false);
2513 ;; You should have now:
2514 ;; user_pref("browser.bookmarks.autoExportHTML", true);
2516 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
2517 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
2519 (defun anything-get-firefox-user-init-dir ()
2520 "Guess the default Firefox user directory name."
2521 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
2522 (moz-user-dir (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
2523 (goto-char (point-min))
2524 (when (search-forward "Path=" nil t)
2525 (buffer-substring-no-properties (point) (point-at-eol))))))
2526 (file-name-as-directory (concat moz-dir moz-user-dir))))
2528 (defun anything-guess-firefox-bookmark-file ()
2529 "Return the path of the Firefox bookmarks file."
2530 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
2532 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
2533 "Parse html bookmark FILE and return an alist with (title . url) as elements."
2534 (let (bookmarks-alist url title)
2535 (with-temp-buffer
2536 (insert-file-contents file)
2537 (goto-char (point-min))
2538 (while (not (eobp))
2539 (forward-line)
2540 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
2541 (beginning-of-line)
2542 (when (re-search-forward url-regexp nil t)
2543 (setq url (concat "\"" (match-string 0))))
2544 (beginning-of-line)
2545 (when (re-search-forward bmk-regexp nil t)
2546 (setq title (match-string 1)))
2547 (push (cons title url) bookmarks-alist))))
2548 (nreverse bookmarks-alist)))
2551 (defvar anything-c-firefox-bookmarks-alist nil)
2552 (defvar anything-c-source-firefox-bookmarks
2553 '((name . "Firefox Bookmarks")
2554 (init . (lambda ()
2555 (setq anything-c-firefox-bookmarks-alist
2556 (anything-html-bookmarks-to-alist
2557 (anything-guess-firefox-bookmark-file)
2558 anything-firefox-bookmark-url-regexp
2559 anything-firefox-bookmarks-regexp))))
2560 (candidates . (lambda ()
2561 (mapcar #'car
2562 anything-c-firefox-bookmarks-alist)))
2563 (candidate-transformer anything-c-highlight-firefox-bookmarks)
2564 (action . (("Browse Url" . (lambda (candidate)
2565 (w3m-browse-url
2566 (anything-c-firefox-bookmarks-get-value candidate))))
2567 ("Browse Url Firefox" . (lambda (candidate)
2568 (browse-url-firefox
2569 (anything-c-firefox-bookmarks-get-value candidate))))
2570 ("Copy Url" . (lambda (elm)
2571 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
2573 ;; (anything 'anything-c-source-firefox-bookmarks)
2575 (defun anything-c-firefox-bookmarks-get-value (elm)
2576 (replace-regexp-in-string "\"" ""
2577 (cdr (assoc elm
2578 anything-c-firefox-bookmarks-alist))))
2581 (defun anything-c-highlight-firefox-bookmarks (books)
2582 (loop for i in books
2583 collect (propertize i
2584 'face '((:foreground "YellowGreen"))
2585 'help-echo (anything-c-firefox-bookmarks-get-value i))))
2587 ;; W3m bookmark
2588 (eval-when-compile (require 'w3m-bookmark nil t))
2589 (unless (and (require 'w3m nil t)
2590 (require 'w3m-bookmark nil t))
2591 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
2594 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
2595 "Face for w3m bookmarks" :group 'anything)
2597 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
2598 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
2599 (defvar anything-c-w3m-bookmarks-alist nil)
2600 (defvar anything-c-source-w3m-bookmarks
2601 '((name . "W3m Bookmarks")
2602 (init . (lambda ()
2603 (setq anything-c-w3m-bookmarks-alist
2604 (anything-html-bookmarks-to-alist
2605 w3m-bookmark-file
2606 anything-w3m-bookmark-url-regexp
2607 anything-w3m-bookmarks-regexp))))
2608 (candidates . (lambda ()
2609 (mapcar #'car
2610 anything-c-w3m-bookmarks-alist)))
2611 (candidate-transformer anything-c-highlight-w3m-bookmarks)
2612 (action . (("Browse Url" . (lambda (candidate)
2613 (anything-c-w3m-browse-bookmark candidate)))
2614 ("Copy Url" . (lambda (elm)
2615 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
2616 ("Browse Url Firefox" . (lambda (candidate)
2617 (anything-c-w3m-browse-bookmark candidate t)))
2618 ("Delete Bookmark" . (lambda (candidate)
2619 (anything-c-w3m-delete-bookmark candidate)))
2620 ("Rename Bookmark" . (lambda (candidate)
2621 (anything-c-w3m-rename-bookmark candidate)))))
2622 (persistent-action . (lambda (candidate)
2623 (if current-prefix-arg
2624 (anything-c-w3m-browse-bookmark candidate t)
2625 (anything-c-w3m-browse-bookmark candidate nil t))))
2626 (persistent-help . "Open URL with FireFox / C-u \\[anything-execute-persistent-action]: Open URL with emacs-w3m")))
2628 ;; (anything 'anything-c-source-w3m-bookmarks)
2630 (defun anything-c-w3m-bookmarks-get-value (elm)
2631 (replace-regexp-in-string "\"" ""
2632 (cdr (assoc elm
2633 anything-c-w3m-bookmarks-alist))))
2636 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
2637 (let* ((fn (if use-firefox
2638 'browse-url-firefox
2639 'w3m-browse-url))
2640 (arg (and (eq fn 'w3m-browse-url)
2641 new-tab)))
2642 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
2645 (defun anything-c-highlight-w3m-bookmarks (books)
2646 (loop for i in books
2647 collect (propertize i
2648 'face 'anything-w3m-bookmarks-face
2649 'help-echo (anything-c-w3m-bookmarks-get-value i))))
2652 (defun anything-c-w3m-delete-bookmark (elm)
2653 (save-excursion
2654 (find-file-literally w3m-bookmark-file)
2655 (goto-char (point-min))
2656 (when (re-search-forward elm nil t)
2657 (beginning-of-line)
2658 (delete-region (point)
2659 (line-end-position))
2660 (delete-blank-lines))
2661 (save-buffer (current-buffer))
2662 (kill-buffer (current-buffer))))
2664 (defun anything-c-w3m-rename-bookmark (elm)
2665 (let* ((old-title (replace-regexp-in-string ">" "" elm))
2666 (new-title (read-string "NewTitle: " old-title)))
2667 (save-excursion
2668 (find-file-literally w3m-bookmark-file)
2669 (goto-char (point-min))
2670 (when (re-search-forward (concat elm "<") nil t)
2671 (goto-char (1- (point)))
2672 (delete-backward-char (length old-title))
2673 (insert new-title))
2674 (save-buffer (current-buffer))
2675 (kill-buffer (current-buffer)))))
2677 ;;;; <Library>
2678 ;;; Elisp library scan
2679 (defvar anything-c-source-elisp-library-scan
2680 '((name . "Elisp libraries (Scan)")
2681 (init . (anything-c-elisp-library-scan-init))
2682 (candidates-in-buffer)
2683 (action ("Find library" . (lambda (candidate)
2684 (find-file (find-library-name candidate))))
2685 ("Find library other window" . (lambda (candidate)
2686 (find-file-other-window (find-library-name candidate))))
2687 ("Load library" . (lambda (candidate)
2688 (load-library candidate))))))
2689 ;; (anything 'anything-c-source-elisp-library-scan)
2691 (defun anything-c-elisp-library-scan-init ()
2692 "Init anything buffer status."
2693 (let ((anything-buffer (anything-candidate-buffer 'global))
2694 (library-list (anything-c-elisp-library-scan-list)))
2695 (with-current-buffer anything-buffer
2696 (dolist (library library-list)
2697 (insert (format "%s\n" library))))))
2699 (defun anything-c-elisp-library-scan-list (&optional dirs string)
2700 "Do completion for file names passed to `locate-file'.
2701 DIRS is directory to search path.
2702 STRING is string to match."
2703 ;; Use `load-path' as path when ignore `dirs'.
2704 (or dirs (setq dirs load-path))
2705 ;; Init with blank when ignore `string'.
2706 (or string (setq string ""))
2707 ;; Get library list.
2708 (let ((string-dir (file-name-directory string))
2709 ;; File regexp that suffix match `load-file-rep-suffixes'.
2710 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
2711 name
2712 names)
2713 (dolist (dir dirs)
2714 (unless dir
2715 (setq dir default-directory))
2716 (if string-dir
2717 (setq dir (expand-file-name string-dir dir)))
2718 (when (file-directory-p dir)
2719 (dolist (file (file-name-all-completions
2720 (file-name-nondirectory string) dir))
2721 ;; Suffixes match `load-file-rep-suffixes'.
2722 (setq name (if string-dir (concat string-dir file) file))
2723 (if (string-match match-regexp name)
2724 (add-to-list 'names name)))))
2725 names))
2727 ;;;; <Programming>
2728 ;;; Imenu
2729 (defvar anything-c-imenu-delimiter " / ")
2731 (defvar anything-c-imenu-index-filter nil)
2732 (make-variable-buffer-local 'anything-c-imenu-index-filter)
2734 (defvar anything-c-cached-imenu-alist nil)
2735 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
2737 (defvar anything-c-cached-imenu-candidates nil)
2738 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
2740 (defvar anything-c-cached-imenu-tick nil)
2741 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
2743 (eval-when-compile (require 'imenu))
2744 (setq imenu-auto-rescan t)
2746 (defun anything-imenu-create-candidates (entry)
2747 "Create candidates with ENTRY."
2748 (if (listp (cdr entry))
2749 (mapcan (lambda (sub)
2750 (if (consp (cdr sub))
2751 (mapcar
2752 (lambda (subentry)
2753 (concat (car entry) anything-c-imenu-delimiter subentry))
2754 (anything-imenu-create-candidates sub))
2755 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
2756 (cdr entry))
2757 (list entry)))
2759 (defvar anything-c-source-imenu
2760 '((name . "Imenu")
2761 (candidates . anything-c-imenu-candidates)
2762 (persistent-action . (lambda (elm)
2763 (anything-c-imenu-default-action elm)
2764 (unless (fboundp 'semantic-imenu-tag-overlay)
2765 (anything-match-line-color-current-line))))
2766 (persistent-help . "Show this entry")
2767 (action . anything-c-imenu-default-action))
2768 "See (info \"(emacs)Imenu\")")
2770 ;; (anything 'anything-c-source-imenu)
2772 (defun anything-c-imenu-candidates ()
2773 (with-current-buffer anything-current-buffer
2774 (let ((tick (buffer-modified-tick)))
2775 (if (eq anything-c-cached-imenu-tick tick)
2776 anything-c-cached-imenu-candidates
2777 (setq imenu--index-alist nil)
2778 (setq anything-c-cached-imenu-tick tick
2779 anything-c-cached-imenu-candidates
2780 (condition-case nil
2781 (mapcan
2782 'anything-imenu-create-candidates
2783 (setq anything-c-cached-imenu-alist
2784 (let ((index (imenu--make-index-alist)))
2785 (if anything-c-imenu-index-filter
2786 (funcall anything-c-imenu-index-filter index)
2787 index))))
2788 (error nil)))
2789 (setq anything-c-cached-imenu-candidates
2790 (mapcar #'(lambda (x)
2791 (if (stringp x)
2793 (car x)))
2794 anything-c-cached-imenu-candidates))))))
2796 (setq imenu-default-goto-function 'imenu-default-goto-function)
2797 (defun anything-c-imenu-default-action (elm)
2798 "The default action for `anything-c-source-imenu'."
2799 (let ((path (split-string elm anything-c-imenu-delimiter))
2800 (alist anything-c-cached-imenu-alist))
2801 (if (> (length path) 1)
2802 (progn
2803 (setq alist (assoc (car path) alist))
2804 (setq elm (cadr path))
2805 (imenu (assoc elm alist)))
2806 (imenu (assoc elm alist)))))
2808 ;;; Ctags
2809 (defvar anything-c-ctags-modes
2810 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
2811 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
2812 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
2814 (defun anything-c-source-ctags-init ()
2815 (when (and buffer-file-name
2816 (memq major-mode anything-c-ctags-modes)
2817 (anything-current-buffer-is-modified))
2818 (with-current-buffer (anything-candidate-buffer 'local)
2819 (call-process-shell-command
2820 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
2821 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
2822 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
2823 nil (current-buffer))
2824 (goto-char (point-min))
2825 (forward-line 2)
2826 (delete-region (point-min) (point))
2827 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
2828 for lineno-start = (point)
2829 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
2831 (beginning-of-line)
2832 (insert (format "%5s:" lineno))
2833 (search-forward "\177" (point-at-eol) t)
2834 (delete-region (1- (point)) (point-at-eol))
2835 (forward-line 1)))))
2837 (defvar anything-c-source-ctags
2838 '((name . "Exuberant ctags")
2839 (init . anything-c-source-ctags-init)
2840 (candidates-in-buffer)
2841 (adjust)
2842 (type . line))
2843 "Needs Exuberant Ctags.
2845 http://ctags.sourceforge.net/")
2846 ;; (anything 'anything-c-source-ctags)
2848 ;; Semantic
2849 (defvar anything-semantic-candidates nil)
2850 (eval-when-compile (require 'semantic nil t))
2851 (defun anything-semantic-construct-candidates (tags depth)
2852 (when (require 'semantic nil t)
2853 (apply 'append
2854 (mapcar (lambda (tag)
2855 (if (listp tag)
2856 (let ((type (semantic-tag-type tag))
2857 (class (semantic-tag-class tag)))
2858 (if (or (and (stringp type)
2859 (or (string= type "class")
2860 (string= type "namespace")))
2861 (eq class 'function)
2862 (eq class 'variable))
2863 (cons (cons (concat (make-string (* depth 2) ?\s)
2864 (semantic-format-tag-summarize tag nil t)) tag)
2865 (anything-semantic-construct-candidates (semantic-tag-components tag)
2866 (1+ depth)))))))
2867 tags))))
2869 (defun anything-semantic-default-action (candidate)
2870 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
2871 (semantic-go-to-tag tag)))
2873 (defvar anything-c-source-semantic
2874 '((name . "Semantic Tags")
2875 (init . (lambda ()
2876 (setq anything-semantic-candidates
2877 (condition-case nil
2878 (anything-semantic-construct-candidates (semantic-fetch-tags) 0)
2879 (error nil)))))
2880 (candidates . (lambda ()
2881 (if anything-semantic-candidates
2882 (mapcar 'car anything-semantic-candidates))))
2883 (persistent-action . (lambda (elm)
2884 (anything-semantic-default-action elm)
2885 (anything-match-line-color-current-line)))
2886 (persistent-help . "Show this entry")
2887 (action . anything-semantic-default-action)
2888 "Needs semantic in CEDET.
2890 http://cedet.sourceforge.net/semantic.shtml
2891 http://cedet.sourceforge.net/"))
2893 ;; (anything 'anything-c-source-semantic)
2895 ;;; Function is called by
2896 (defun anything-simple-call-tree ()
2897 "Preconfigured `anything' for simple-call-tree. List function relationships."
2898 (interactive)
2899 (anything-other-buffer
2900 '(anything-c-source-simple-call-tree-functions-callers
2901 anything-c-source-simple-call-tree-callers-functions)
2902 "*anything simple-call-tree*"))
2904 (defvar anything-c-source-simple-call-tree-functions-callers
2905 '((name . "Function is called by")
2906 (init . anything-c-simple-call-tree-functions-callers-init)
2907 (multiline)
2908 (candidates . anything-c-simple-call-tree-candidates)
2909 (persistent-action . anything-c-simple-call-tree-persistent-action)
2910 (persistent-help . "Show function definitions by rotation")
2911 (action ("Find definition selected by persistent-action" .
2912 anything-c-simple-call-tree-find-definition)))
2913 "Needs simple-call-tree.el.
2914 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
2916 (defvar anything-c-simple-call-tree-tick nil)
2917 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
2918 (defun anything-c-simple-call-tree-analyze-maybe ()
2919 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
2920 (simple-call-tree-analyze)
2921 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
2923 (defun anything-c-simple-call-tree-init-base (function message)
2924 (require 'simple-call-tree)
2925 (with-no-warnings
2926 (when (anything-current-buffer-is-modified)
2927 (anything-c-simple-call-tree-analyze-maybe)
2928 (let ((list (funcall function simple-call-tree-alist)))
2929 (with-current-buffer (anything-candidate-buffer 'local)
2930 (dolist (entry list)
2931 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
2932 (insert (car entry) message
2933 (if (string= funcs " ")
2934 " no functions."
2935 funcs)
2936 "\n\n"))))))))
2938 (defun anything-c-simple-call-tree-functions-callers-init ()
2939 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert " is called by\n"))
2941 (defun anything-c-simple-call-tree-candidates ()
2942 (with-current-buffer (anything-candidate-buffer)
2943 (split-string (buffer-string) "\n\n")))
2945 (defvar anything-c-simple-call-tree-related-functions nil)
2946 (defvar anything-c-simple-call-tree-function-index 0)
2947 (defun anything-c-simple-call-tree-persistent-action (candidate)
2948 (unless (eq last-command 'anything-execute-persistent-action)
2949 (setq anything-c-simple-call-tree-related-functions
2950 (delete "no functions."
2951 (split-string
2952 (replace-regexp-in-string " \\| is called by\\| calls " "" candidate)
2953 "\n")))
2954 (setq anything-c-simple-call-tree-function-index -1))
2955 (incf anything-c-simple-call-tree-function-index)
2956 (anything-c-simple-call-tree-find-definition candidate))
2958 (defun anything-c-simple-call-tree-find-definition (candidate)
2959 (find-function (intern
2960 (nth (mod anything-c-simple-call-tree-function-index
2961 (length anything-c-simple-call-tree-related-functions))
2962 anything-c-simple-call-tree-related-functions))))
2964 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
2966 ;;; Function calls
2967 (defvar anything-c-source-simple-call-tree-callers-functions
2968 '((name . "Function calls")
2969 (init . anything-c-simple-call-tree-callers-functions-init)
2970 (multiline)
2971 (candidates . anything-c-simple-call-tree-candidates)
2972 (persistent-action . anything-c-simple-call-tree-persistent-action)
2973 (persistent-help . "Show function definitions by rotation")
2974 (action ("Find definition selected by persistent-action" .
2975 anything-c-simple-call-tree-find-definition)))
2976 "Needs simple-call-tree.el.
2977 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
2979 (defun anything-c-simple-call-tree-callers-functions-init ()
2980 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
2982 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
2984 ;;; Commands/Options with doc
2985 (defvar anything-c-auto-document-data nil)
2986 (make-variable-buffer-local 'anything-c-auto-document-data)
2987 (defvar anything-c-source-commands-and-options-in-file
2988 '((name . "Commands/Options in file")
2989 (header-name
2990 . (lambda (x) (format "Commands/Options in %s"
2991 (buffer-local-value 'buffer-file-name anything-current-buffer))))
2992 (candidates . anything-command-and-options-candidates)
2993 (multiline)
2994 (action . imenu))
2995 "List Commands and Options with doc. It needs auto-document.el .
2997 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
2999 (eval-when-compile (require 'auto-document nil t))
3000 (defun anything-command-and-options-candidates ()
3001 (with-current-buffer anything-current-buffer
3002 (when (and (require 'auto-document nil t)
3003 (eq major-mode 'emacs-lisp-mode)
3004 (or (anything-current-buffer-is-modified)
3005 (not anything-c-auto-document-data)))
3006 (or imenu--index-alist (imenu--make-index-alist t))
3007 (setq anything-c-auto-document-data
3008 (destructuring-bind (commands options)
3009 (adoc-construct anything-current-buffer)
3010 (append
3011 (loop for (command . doc) in commands
3012 for cmdname = (symbol-name command)
3013 collect
3014 (cons (format "Command: %s\n %s"
3015 (propertize cmdname 'face font-lock-function-name-face)
3016 (adoc-first-line doc))
3017 (assoc cmdname imenu--index-alist)))
3018 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
3019 for (option doc default) in options
3020 for optname = (symbol-name option)
3021 collect
3022 (cons (format "Option: %s\n %s\n default = %s"
3023 (propertize optname 'face font-lock-variable-name-face)
3024 (adoc-first-line doc)
3025 (adoc-prin1-to-string default))
3026 (assoc optname
3027 var-alist)))))))
3028 anything-c-auto-document-data))
3030 ;; (anything 'anything-c-source-commands-and-options-in-file)
3032 ;;;; <Color and Face>
3033 ;;; Customize Face
3034 (defvar anything-c-source-customize-face
3035 '((name . "Customize Face")
3036 (init . (lambda ()
3037 (unless (anything-candidate-buffer)
3038 (save-window-excursion (list-faces-display))
3039 (anything-candidate-buffer (get-buffer "*Faces*")))))
3040 (candidates-in-buffer)
3041 (get-line . buffer-substring)
3042 (action . (lambda (line)
3043 (customize-face (intern (car (split-string line))))))
3044 (requires-pattern . 3))
3045 "See (info \"(emacs)Faces\")")
3046 ;; (anything 'anything-c-source-customize-face)
3048 ;; Color
3049 (defvar anything-c-source-colors
3050 '((name . "Colors")
3051 (init . (lambda () (unless (anything-candidate-buffer)
3052 (save-window-excursion (list-colors-display))
3053 (anything-candidate-buffer (get-buffer "*Colors*")))))
3054 (candidates-in-buffer)
3055 (get-line . buffer-substring)
3056 (action ("Copy Name" . (lambda (candidate)
3057 (kill-new (anything-c-colors-get-name candidate))))
3058 ("Copy RGB" . (lambda (candidate)
3059 (kill-new (anything-c-colors-get-rgb candidate))))
3060 ("Insert Name" . (lambda (candidate)
3061 (with-current-buffer anything-current-buffer
3062 (insert (anything-c-colors-get-name candidate)))))
3063 ("Insert RGB" . (lambda (candidate)
3064 (with-current-buffer anything-current-buffer
3065 (insert (anything-c-colors-get-rgb candidate))))))))
3066 ;; (anything 'anything-c-source-colors)
3068 (defun anything-c-colors-get-name (candidate)
3069 "Get color name."
3070 (replace-regexp-in-string
3071 " " ""
3072 (with-temp-buffer
3073 (insert (capitalize candidate))
3074 (goto-char (point-min))
3075 (search-forward-regexp "\\s-\\{2,\\}")
3076 (kill-line)
3077 (buffer-string))))
3079 (defun anything-c-colors-get-rgb (candidate)
3080 "Get color RGB."
3081 (replace-regexp-in-string
3082 " " ""
3083 (with-temp-buffer
3084 (insert (capitalize candidate))
3085 (goto-char (point-max))
3086 (search-backward-regexp "\\s-\\{2,\\}")
3087 (kill-region (point) (point-min))
3088 (buffer-string))))
3090 ;;;; <Search Engine>
3091 ;;; Tracker desktop search
3092 (defvar anything-c-source-tracker-search
3093 '((name . "Tracker Search")
3094 (candidates . (lambda ()
3095 (start-process "tracker-search-process" nil
3096 "tracker-search"
3097 anything-pattern)))
3098 (type . file)
3099 (requires-pattern . 3)
3100 (delayed))
3101 "Source for retrieving files matching the current input pattern
3102 with the tracker desktop search.")
3103 ;; (anything 'anything-c-source-tracker-search)
3105 ;;; Spotlight (MacOS X desktop search)
3106 (defvar anything-c-source-mac-spotlight
3107 '((name . "mdfind")
3108 (candidates . (lambda ()
3109 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
3110 (type . file)
3111 (requires-pattern . 3)
3112 (delayed))
3113 "Source for retrieving files via Spotlight's command line
3114 utility mdfind.")
3115 ;; (anything 'anything-c-source-mac-spotlight)
3118 ;;;; <Kill ring>
3119 ;;; Kill ring
3120 (defvar anything-c-source-kill-ring
3121 '((name . "Kill Ring")
3122 (init . (lambda () (anything-attrset 'last-command last-command)))
3123 (candidates . (lambda ()
3124 (loop for kill in kill-ring
3125 unless (or (< (length kill) anything-kill-ring-threshold)
3126 (string-match "^[\\s\\t]+$" kill))
3127 collect kill)))
3128 (action . anything-c-kill-ring-action)
3129 (last-command)
3130 (migemo)
3131 (multiline))
3132 "Source for browse and insert contents of kill-ring.")
3134 (defun anything-c-kill-ring-action (str)
3135 "Insert STR in `kill-ring' and set STR to the head.
3136 If this action is executed just after `yank', replace with STR as yanked string."
3137 (setq kill-ring (delete str kill-ring))
3138 (if (not (eq (anything-attr 'last-command) 'yank))
3139 (insert-for-yank str)
3140 ;; from `yank-pop'
3141 (let ((inhibit-read-only t)
3142 (before (< (point) (mark t))))
3143 (if before
3144 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
3145 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
3146 (setq yank-undo-function nil)
3147 (set-marker (mark-marker) (point) (current-buffer))
3148 (insert-for-yank str)
3149 ;; Set the window start back where it was in the yank command,
3150 ;; if possible.
3151 (set-window-start (selected-window) yank-window-start t)
3152 (if before
3153 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3154 ;; It is cleaner to avoid activation, even though the command
3155 ;; loop would deactivate the mark because we inserted text.
3156 (goto-char (prog1 (mark t)
3157 (set-marker (mark-marker) (point) (current-buffer)))))))
3158 (kill-new str))
3160 ;; (anything 'anything-c-source-kill-ring)
3162 ;;;; <Mark ring>
3163 ;; DO NOT include these sources in `anything-sources' use
3164 ;; the commands `anything-mark-ring' and `anything-global-mark-ring' instead.
3166 (defun anything-c-source-mark-ring-candidates ()
3167 (flet ((get-marks (pos)
3168 (save-excursion
3169 (goto-char pos)
3170 (beginning-of-line)
3171 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3172 (when (string= "" line)
3173 (setq line "<EMPTY LINE>"))
3174 (format "%7d: %s" (line-number-at-pos) line)))))
3175 (with-current-buffer anything-current-buffer
3176 (loop
3177 with marks = (cons (mark-marker) mark-ring)
3178 with recip = nil
3179 for i in marks
3180 for f = (get-marks i)
3181 if (not (member f recip))
3183 (push f recip)
3184 finally (return (reverse recip))))))
3186 (defvar anything-mark-ring-cache nil)
3187 (defvar anything-c-source-mark-ring
3188 '((name . "mark-ring")
3189 (init . (lambda ()
3190 (setq anything-mark-ring-cache
3191 (anything-c-source-mark-ring-candidates))))
3192 (candidates . (lambda ()
3193 (anything-aif anything-mark-ring-cache
3194 it)))
3195 (action . (("Goto line" . (lambda (candidate)
3196 (anything-goto-line (string-to-number candidate))))))
3197 (persistent-action . (lambda (candidate)
3198 (anything-goto-line (string-to-number candidate))
3199 (anything-match-line-color-current-line)))
3200 (persistent-help . "Show this line")))
3202 ;; (anything 'anything-c-source-mark-ring)
3204 (defun anything-mark-ring ()
3205 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3206 (interactive)
3207 (anything 'anything-c-source-mark-ring))
3209 ;;; Global-mark-ring
3210 (defvar anything-c-source-global-mark-ring
3211 '((name . "global-mark-ring")
3212 (candidates . anything-c-source-global-mark-ring-candidates)
3213 (action . (("Goto line" . (lambda (candidate)
3214 (let ((items (split-string candidate ":")))
3215 (switch-to-buffer (second items))
3216 (anything-goto-line (string-to-number (car items))))))))
3217 (persistent-action . (lambda (candidate)
3218 (let ((items (split-string candidate ":")))
3219 (switch-to-buffer (second items))
3220 (anything-goto-line (string-to-number (car items)))
3221 (anything-match-line-color-current-line))))
3222 (persistent-help . "Show this line")))
3224 (defun anything-c-source-global-mark-ring-candidates ()
3225 (flet ((buf-fn (m)
3226 (with-current-buffer (marker-buffer m)
3227 (goto-char m)
3228 (beginning-of-line)
3229 (let (line)
3230 (if (string= "" line)
3231 (setq line "<EMPTY LINE>")
3232 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3233 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
3234 (loop
3235 with marks = global-mark-ring
3236 with recip = nil
3237 for i in marks
3238 if (not (or (string-match "^ " (format "%s" (marker-buffer i)))
3239 (null (marker-buffer i))))
3240 for a = (buf-fn i)
3241 if (and a (not (member a recip)))
3243 (push a recip)
3244 finally (return (reverse recip)))))
3246 ;; (anything 'anything-c-source-global-mark-ring)
3248 (defun anything-global-mark-ring ()
3249 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
3250 (interactive)
3251 (anything 'anything-c-source-global-mark-ring))
3253 ;;;; <Register>
3254 ;;; Insert from register
3255 (defvar anything-c-source-register
3256 '((name . "Registers")
3257 (candidates . anything-c-register-candidates)
3258 (action-transformer . anything-c-register-action-transformer)
3259 (multiline)
3260 (action))
3261 "See (info \"(emacs)Registers\")")
3263 (defun anything-c-register-candidates ()
3264 "Collecting register contents and appropriate commands."
3265 (loop for (char . val) in register-alist
3266 for key = (single-key-description char)
3267 for string-actions = (cond
3268 ((numberp val)
3269 (list (int-to-string val)
3270 'insert-register
3271 'increment-register))
3272 ((markerp val)
3273 (let ((buf (marker-buffer val)))
3274 (if (null buf)
3275 (list "a marker in no buffer")
3276 (list (concat
3277 "a buffer position:"
3278 (buffer-name buf)
3279 ", position "
3280 (int-to-string (marker-position val)))
3281 'jump-to-register
3282 'insert-register))))
3283 ((and (consp val) (window-configuration-p (car val)))
3284 (list "window configuration."
3285 'jump-to-register))
3286 ((and (consp val) (frame-configuration-p (car val)))
3287 (list "frame configuration."
3288 'jump-to-register))
3289 ((and (consp val) (eq (car val) 'file))
3290 (list (concat "file:"
3291 (prin1-to-string (cdr val))
3292 ".")
3293 'jump-to-register))
3294 ((and (consp val) (eq (car val) 'file-query))
3295 (list (concat "file:a file-query reference: file "
3296 (car (cdr val))
3297 ", position "
3298 (int-to-string (car (cdr (cdr val))))
3299 ".")
3300 'jump-to-register))
3301 ((consp val)
3302 (let ((lines (format "%4d" (length val))))
3303 (list (format "%s: %s\n" lines
3304 (truncate-string-to-width
3305 (mapconcat 'identity (list (car val))
3306 ;; (mapconcat (lambda (y) y) val
3307 "^J") (- (window-width) 15)))
3308 'insert-register)))
3309 ((stringp val)
3310 (list ;; without properties
3311 (substring-no-properties val)
3312 'insert-register
3313 'append-to-register
3314 'prepend-to-register))
3316 "GARBAGE!"))
3317 collect (cons (format "register %3s: %s" key (car string-actions))
3318 (cons char (cdr string-actions)))))
3320 (defun anything-c-register-action-transformer (actions register-and-functions)
3321 "Decide actions by the contents of register."
3322 (loop with func-actions =
3323 '((insert-register
3324 "Insert Register" .
3325 (lambda (c) (insert-register (car c))))
3326 (jump-to-register
3327 "Jump to Register" .
3328 (lambda (c) (jump-to-register (car c))))
3329 (append-to-register
3330 "Append Region to Register" .
3331 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
3332 (prepend-to-register
3333 "Prepend Region to Register" .
3334 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
3335 (increment-register
3336 "Increment Prefix Arg to Register" .
3337 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
3338 for func in (cdr register-and-functions)
3339 for cell = (assq func func-actions)
3340 when cell
3341 collect (cdr cell)))
3343 ;; (anything 'anything-c-source-register)
3345 ;;;; <Headline Extraction>
3346 (defvar anything-c-source-fixme
3347 '((name . "TODO/FIXME/DRY comments")
3348 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
3349 (adjust)
3350 (recenter))
3351 "Show TODO/FIXME/DRY comments in current file.")
3352 ;; (anything 'anything-c-source-fixme)
3354 (defvar anything-c-source-rd-headline
3355 '((name . "RD HeadLine")
3356 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
3357 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
3358 (migemo)
3359 (subexp . 1))
3360 "Show RD headlines.
3362 RD is Ruby's POD.
3363 http://en.wikipedia.org/wiki/Ruby_Document_format")
3364 ;; (anything 'anything-c-source-rd-headline)
3366 (defvar anything-c-source-oddmuse-headline
3367 '((name . "Oddmuse HeadLine")
3368 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
3369 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
3370 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
3371 (migemo)
3372 (subexp . 1))
3373 "Show Oddmuse headlines, such as EmacsWiki.")
3374 ;; (anything 'anything-c-source-oddmuse-headline)
3376 (defvar anything-c-source-emacs-source-defun
3377 '((name . "Emacs Source DEFUN")
3378 (headline . "DEFUN\\|DEFVAR")
3379 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
3380 "Show DEFUN/DEFVAR in Emacs C source file.")
3381 ;; (anything 'anything-c-source-emacs-source-defun)
3383 (defvar anything-c-source-emacs-lisp-expectations
3384 '((name . "Emacs Lisp Expectations")
3385 (headline . "(desc[ ]\\|(expectations")
3386 (condition . (eq major-mode 'emacs-lisp-mode)))
3387 "Show descriptions (desc) in Emacs Lisp Expectations.
3389 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
3390 ;; (anything 'anything-c-source-emacs-lisp-expectations)
3392 (defvar anything-c-source-emacs-lisp-toplevels
3393 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
3394 (headline . "^(\\|(@\\*\\|^;;;;")
3395 (get-line . buffer-substring)
3396 (condition . (eq major-mode 'emacs-lisp-mode))
3397 (adjust))
3398 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
3399 linkd.el is optional because linkd stars are extracted by regexp.
3400 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
3401 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
3403 (defvar anything-c-source-org-headline
3404 '((name . "Org HeadLine")
3405 (headline
3406 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3407 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3408 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3409 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3410 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3411 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3412 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3413 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3414 (condition . (eq major-mode 'org-mode))
3415 (migemo)
3416 (subexp . 1)
3417 (persistent-action . (lambda (elm)
3418 (anything-c-action-line-goto elm)
3419 (org-cycle)))
3420 (action-transformer
3421 . (lambda (actions candidate)
3422 '(("Go to Line" . anything-c-action-line-goto)
3423 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
3424 "Show Org headlines.
3425 org-mode is very very much extended text-mode/outline-mode.
3427 See (find-library \"org.el\")
3428 See http://orgmode.org for the latest version.")
3430 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
3431 (insert
3432 (save-excursion
3433 (anything-goto-line (car lineno-and-content))
3434 (and (looking-at "^\\*+ \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3435 (org-make-link-string (concat "*" (match-string 1)))))))
3437 ;; (anything 'anything-c-source-org-headline)
3439 ;;; Anything yaoddmuse
3440 ;; Be sure to have yaoddmuse.el installed
3441 ;; install-elisp may be required if you want to install elisp file from here.
3442 (defvar anything-yaoddmuse-use-cache-file nil)
3443 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
3444 (defvar anything-c-yaoddmuse-ew-cache nil)
3445 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
3446 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
3447 (candidates . (lambda ()
3448 (if anything-yaoddmuse-use-cache-file
3449 (condition-case nil
3450 (progn
3451 (unless anything-c-yaoddmuse-ew-cache
3452 (load anything-c-yaoddmuse-cache-file)
3453 (setq anything-c-yaoddmuse-ew-cache
3454 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
3455 anything-c-yaoddmuse-ew-cache)
3456 (error nil))
3457 (yaoddmuse-update-pagename t)
3458 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
3459 (action . (("Edit page" . (lambda (candidate)
3460 (yaoddmuse-edit "EmacsWiki" candidate)))
3461 ("Browse page" . (lambda (candidate)
3462 (yaoddmuse-browse-page "EmacsWiki" candidate)))
3463 ("Browse page other window" . (lambda (candidate)
3464 (if (one-window-p)
3465 (split-window-vertically))
3466 (yaoddmuse-browse-page "EmacsWiki" candidate)))
3467 ("Browse diff" . (lambda (candidate)
3468 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
3469 ("Copy URL" . (lambda (candidate)
3470 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
3471 (message "Have copy page %s's URL to yank." candidate)))
3472 ("Create page" . (lambda (candidate)
3473 (yaoddmuse-edit "EmacsWiki" anything-input)))
3474 ("Update cache" . (lambda (candidate)
3475 (if anything-yaoddmuse-use-cache-file
3476 (progn
3477 (anything-yaoddmuse-cache-pages t)
3478 (setq anything-c-yaoddmuse-ew-cache
3479 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
3480 (yaoddmuse-update-pagename))))))
3481 (action-transformer anything-c-yaoddmuse-action-transformer)))
3483 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
3485 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
3486 '((name . "Yaoddmuse Post library (EmacsWiki)")
3487 (init . (anything-yaoddmuse-init))
3488 (candidates-in-buffer)
3489 (action . (("Post library and Browse" . (lambda (candidate)
3490 (yaoddmuse-post-file (find-library-name candidate)
3491 "EmacsWiki"
3492 (file-name-nondirectory (find-library-name candidate))
3493 nil t)))
3494 ("Post library" . (lambda (candidate)
3495 (yaoddmuse-post-file (find-library-name candidate)
3496 "EmacsWiki"
3497 (file-name-nondirectory (find-library-name candidate)))))))))
3499 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
3501 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
3502 "Allow the use of `install-elisp' only on elisp files."
3503 (if (string-match "\.el$" candidate)
3504 (append actions '(("Install Elisp" . (lambda (elm)
3505 (install-elisp-from-emacswiki elm)))))
3506 actions))
3508 (defun anything-yaoddmuse-cache-pages (&optional load)
3509 "Fetch the list of files on emacswiki and create cache file.
3510 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
3511 (interactive)
3512 (yaoddmuse-update-pagename)
3513 (save-excursion
3514 (find-file anything-c-yaoddmuse-cache-file)
3515 (erase-buffer)
3516 (insert "(puthash \"EmacsWiki\" '(")
3517 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
3519 (insert (concat "(\"" (car i) "\") ")))
3520 (insert ") yaoddmuse-pages-hash)\n")
3521 (save-buffer)
3522 (kill-buffer (current-buffer))
3523 (when (or current-prefix-arg
3524 load)
3525 (load anything-c-yaoddmuse-cache-file))))
3527 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
3528 "Preconfigured `anything' to edit or view EmacsWiki page."
3529 (interactive)
3530 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
3532 (defun anything-yaoddmuse-emacswiki-post-library ()
3533 "Preconfigured `anything' to post library to EmacsWiki."
3534 (interactive)
3535 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
3537 (defun anything-yaoddmuse-init ()
3538 "Init anything buffer status."
3539 (let ((anything-buffer (anything-candidate-buffer 'global))
3540 (library-list (yaoddmuse-get-library-list)))
3541 (with-current-buffer anything-buffer
3542 ;; Insert library name.
3543 (dolist (library library-list)
3544 (insert (format "%s\n" library)))
3545 ;; Sort lines.
3546 (sort-lines nil (point-min) (point-max)))))
3548 ;;; Eev anchors
3549 (defvar anything-c-source-eev-anchor
3550 '((name . "Anchors")
3551 (init . (lambda ()
3552 (setq anything-c-eev-anchor-buffer
3553 (current-buffer))))
3554 (candidates . (lambda ()
3555 (condition-case nil
3556 (save-excursion
3557 (with-current-buffer anything-c-eev-anchor-buffer
3558 (goto-char (point-min))
3559 (let (anchors)
3560 (while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
3561 (push (match-string-no-properties 1) anchors))
3562 (setq anchors (reverse anchors)))))
3563 (error nil))))
3564 (persistent-action . (lambda (item)
3565 (ee-to item)
3566 (anything-match-line-color-current-line)))
3567 (persistent-help . "Show this entry")
3568 (action . (("Goto link" . (lambda (item)
3569 (ee-to item)))))))
3571 ;; (anything 'anything-c-source-eev-anchor)
3573 ;;;; <Misc>
3574 ;;; Org keywords
3575 (defvar anything-c-source-org-keywords
3576 '((name . "Org Keywords")
3577 (init . anything-c-org-keywords-init)
3578 (candidates . anything-c-org-keywords-candidates)
3579 (action . anything-c-org-keywords-insert)
3580 (persistent-action . anything-c-org-keywords-show-help)
3581 (persistent-help . "Show an example and info page to describe this keyword.")
3582 (keywords-examples)
3583 (keywords)))
3584 ;; (anything 'anything-c-source-org-keywords)
3585 (defvar anything-c-org-keywords-info-location
3586 '(("#+TITLE:" . "(org)Export options")
3587 ("#+AUTHOR:" . "(org)Export options")
3588 ("#+DATE:" . "(org)Export options")
3589 ("#+EMAIL:" . "(org)Export options")
3590 ("#+DESCRIPTION:" . "(org)Export options")
3591 ("#+KEYWORDS:" . "(org)Export options")
3592 ("#+LANGUAGE:" . "(org)Export options")
3593 ("#+TEXT:" . "(org)Export options")
3594 ("#+TEXT:" . "(org)Export options")
3595 ("#+OPTIONS:" . "(org)Export options")
3596 ("#+BIND:" . "(org)Export options")
3597 ("#+LINK_UP:" . "(org)Export options")
3598 ("#+LINK_HOME:" . "(org)Export options")
3599 ("#+LATEX_HEADER:" . "(org)Export options")
3600 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
3601 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
3602 ("#+INFOJS_OPT" . "(org)Javascript support")
3603 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
3604 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
3605 ("#+ORGTBL" . "(org)Radio tables")
3606 ("#+HTML:" . "(org)Quoting HTML tags")
3607 ("#+LaTeX:" . "(org)Quoting LaTeX code")
3608 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
3609 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
3610 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
3611 ("#+BEGIN_VERSE" . "(org)Paragraphs")
3612 ("#+BEGIN_SRC" . "(org)Literal examples")
3613 ("#+CAPTION" . "(org)Tables in HTML export")
3614 ("#+LABEL" . "(org)Tables in LaTeX export")
3615 ("#+ATTR_HTML" . "(org)Links")
3616 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
3618 (defun anything-c-org-keywords-init ()
3619 (unless (anything-attr 'keywords-examples)
3620 (require 'org)
3621 (anything-attrset 'keywords-examples
3622 (append
3623 (mapcar
3624 (lambda (x)
3625 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
3626 (cons (match-string 2 x) (match-string 1 x)))
3627 (org-split-string (org-get-current-options) "\n"))
3628 (mapcar 'list org-additional-option-like-keywords)))
3629 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
3631 (defun anything-c-org-keywords-candidates ()
3632 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
3633 (anything-attr 'keywords)))
3635 (defun anything-c-org-keywords-insert (keyword)
3636 (cond ((string-match "BEGIN" keyword)
3637 (insert "#+" keyword " ")
3638 (save-excursion
3639 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
3641 (insert "#+" keyword " "))))
3643 (defun anything-c-org-keywords-show-help (keyword)
3644 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
3645 "(org)In-buffer settings"))
3646 (search-forward (concat "#+" keyword) nil t)
3647 (anything-persistent-highlight-point)
3648 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
3651 ;;; Picklist
3652 (defvar anything-c-source-picklist
3653 '((name . "Picklist")
3654 (candidates . (lambda () (mapcar 'car picklist-list)))
3655 (type . file)))
3656 ;; (anything 'anything-c-source-picklist)
3658 ;;; BBDB
3659 (defun anything-c-bbdb-candidates ()
3660 "Return a list of all names in the bbdb database. The format
3661 is \"Firstname Lastname\"."
3662 (mapcar (lambda (bbdb-record)
3663 (replace-regexp-in-string
3664 "\\s-+$" ""
3665 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
3666 (bbdb-records)))
3668 (defun anything-c-bbdb-create-contact (actions candidate)
3669 "Action transformer that returns only an entry to add the
3670 current `anything-pattern' as new contact. All other actions are
3671 removed."
3672 (if (string= candidate "*Add to contacts*")
3673 '(("Add to contacts" . (lambda (actions)
3674 (bbdb-create-internal
3675 (read-from-minibuffer "Name: " anything-c-bbdb-name)
3676 (read-from-minibuffer "Company: ")
3677 (read-from-minibuffer "Email: ")
3680 (read-from-minibuffer "Note: ")))))
3681 actions))
3683 (defun anything-c-bbdb-get-record (candidate)
3684 "Return record that match CANDIDATE."
3685 (bbdb candidate nil)
3686 (set-buffer "*BBDB*")
3687 (bbdb-current-record))
3689 (defvar anything-c-bbdb-name nil
3690 "Only for internal use.")
3692 (defvar anything-c-source-bbdb
3693 '((name . "BBDB")
3694 (candidates . anything-c-bbdb-candidates)
3695 (action ("Send a mail" . anything-c-bbdb-compose-mail)
3696 ("View person's data" . anything-c-bbdb-view-person-action))
3697 (filtered-candidate-transformer . (lambda (candidates source)
3698 (setq anything-c-bbdb-name anything-pattern)
3699 (if (not candidates)
3700 (list "*Add to contacts*")
3701 candidates)))
3702 (action-transformer . (lambda (actions candidate)
3703 (anything-c-bbdb-create-contact actions candidate)))))
3704 ;; (anything 'anything-c-source-bbdb)
3706 (defun anything-c-bbdb-view-person-action (candidate)
3707 "View BBDB data of single CANDIDATE or marked candidates."
3708 (anything-aif (anything-marked-candidates)
3709 (let ((bbdb-append-records (length it)))
3710 (dolist (i it)
3711 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
3712 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
3714 (defun anything-c-bbdb-collect-mail-addresses ()
3715 "Return a list of all mail addresses of records in bbdb buffer."
3716 (with-current-buffer bbdb-buffer-name
3717 (loop for i in bbdb-records
3718 if (bbdb-record-net (car i))
3719 collect (bbdb-dwim-net-address (car i)))))
3721 (defun anything-c-bbdb-compose-mail (candidate)
3722 "Compose a mail with all records of bbdb buffer."
3723 (anything-c-bbdb-view-person-action candidate)
3724 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
3725 (address-str (mapconcat 'identity address-list ",\n ")))
3726 (compose-mail address-str)))
3728 ;;; Evaluation Result
3729 (defvar anything-c-source-evaluation-result
3730 '((name . "Evaluation Result")
3731 (dummy)
3732 (filtered-candidate-transformer . (lambda (candidates source)
3733 (list
3734 (condition-case nil
3735 (pp-to-string
3736 (eval (read anything-pattern)))
3737 (error "Error")))))
3738 (action ("Do Nothing" . ignore))))
3739 ;; (anything 'anything-c-source-evaluation-result)
3741 ;;; Calculation Result
3742 (defvar anything-c-source-calculation-result
3743 '((name . "Calculation Result")
3744 (dummy)
3745 (filtered-candidate-transformer . (lambda (candidates source)
3746 (list
3747 (condition-case nil
3748 (calc-eval anything-pattern)
3749 (error "error")))))
3750 (action ("Copy result to kill-ring" . kill-new))))
3751 ;; (anything 'anything-c-source-calculation-result)
3753 ;;; Google Suggestions
3754 (defvar anything-gg-sug-lgh-flag 0)
3755 (defun anything-c-google-suggest-fetch (input)
3756 "Fetch suggestions for INPUT from XML buffer.
3757 Return an alist with elements like (data . number_results)."
3758 (let ((request (concat anything-c-google-suggest-url
3759 (url-hexify-string input))))
3760 (flet ((fetch ()
3761 (loop
3762 with result-alist = (xml-get-children
3763 (car (xml-parse-region (point-min) (point-max)))
3764 'CompleteSuggestion)
3765 for i in result-alist
3766 for data = (cdr (caadr (assoc 'suggestion i)))
3767 for nqueries = (cdr (caadr (assoc 'num_queries i)))
3768 for ldata = (length data)
3770 (when (> ldata anything-gg-sug-lgh-flag)
3771 (setq anything-gg-sug-lgh-flag ldata))
3772 collect (cons data nqueries) into cont
3773 finally return cont)))
3774 (if anything-google-suggest-use-curl-p
3775 (with-temp-buffer
3776 (call-process "curl" nil t nil request)
3777 (fetch))
3778 (with-current-buffer
3779 (url-retrieve-synchronously request)
3780 (fetch))))))
3783 (defun anything-c-google-suggest-set-candidates ()
3784 "Set candidates with result and number of google results found."
3785 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
3786 (setq suggestions (loop for i in suggestions
3787 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
3788 for elm = (concat (car i)
3789 (make-string (+ 2 interval) ? )
3790 "(" (cdr i) " results)")
3791 collect (cons elm (car i))))
3792 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
3793 suggestions
3794 ;; if there is no suggestion exactly matching the input then
3795 ;; prepend a Search on Google item to the list
3796 (append
3797 suggestions
3798 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
3799 anything-input))))))
3802 (defun anything-c-google-suggest-action (candidate)
3803 "Default action to jump to a google suggested candidate."
3804 (browse-url (concat anything-c-google-suggest-search-url
3805 (url-hexify-string candidate))))
3808 (defvar anything-c-source-google-suggest
3809 '((name . "Google Suggest")
3810 (candidates . anything-c-google-suggest-set-candidates)
3811 (action . (("Google Search" . anything-c-google-suggest-action)))
3812 (volatile)
3813 (requires-pattern . 3)
3814 (delayed)))
3816 ;; (anything 'anything-c-source-google-suggest)
3818 ;;; Yahoo suggestions
3820 (defun anything-c-yahoo-suggest-fetch (input)
3821 "Fetch Yahoo suggestions for INPUT from XML buffer.
3822 Return an alist with elements like (data . number_results)."
3823 (let ((request (concat anything-c-yahoo-suggest-url
3824 (url-hexify-string input))))
3825 (flet ((fetch ()
3826 (loop
3827 with result-alist = (xml-get-children
3828 (car (xml-parse-region (point-min) (point-max)))
3829 'Result)
3830 for i in result-alist
3831 collect (caddr i))))
3832 (with-current-buffer
3833 (url-retrieve-synchronously request)
3834 (fetch)))))
3836 (defun anything-c-yahoo-suggest-set-candidates ()
3837 "Set candidates with Yahoo results found."
3838 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
3839 (or suggestions
3840 (append
3841 suggestions
3842 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
3843 anything-input))))))
3845 (defun anything-c-yahoo-suggest-action (candidate)
3846 "Default action to jump to a Yahoo suggested candidate."
3847 (browse-url (concat anything-c-yahoo-suggest-search-url
3848 (url-hexify-string candidate))))
3850 (defvar anything-c-source-yahoo-suggest
3851 '((name . "Yahoo Suggest")
3852 (candidates . anything-c-yahoo-suggest-set-candidates)
3853 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
3854 (volatile)
3855 (requires-pattern . 3)
3856 (delayed)))
3858 ;; (anything 'anything-c-source-yahoo-suggest)
3860 ;;; Surfraw
3861 ;;; Need external program surfraw.
3862 ;;; http://surfraw.alioth.debian.org/
3863 ;; user variables
3864 (defvar anything-c-surfraw-favorites '("google" "wikipedia"
3865 "yahoo" "translate"
3866 "codesearch" "genpkg"
3867 "genportage" "fast"
3868 "currency")
3869 "All elements of this list will appear first in results.")
3870 (defvar anything-c-surfraw-use-only-favorites nil
3871 "If non-nil use only `anything-c-surfraw-favorites'.")
3874 (defun anything-c-build-elvi-alist ()
3875 "Build elvi alist.
3876 A list of search engines."
3877 (let* ((elvi-list
3878 (with-temp-buffer
3879 (call-process "surfraw" nil t nil
3880 "-elvi")
3881 (split-string (buffer-string) "\n")))
3882 (elvi-alist
3883 (let (line)
3884 (loop for i in elvi-list
3886 (setq line (split-string i))
3887 collect (cons (first line) (mapconcat #'(lambda (x) x) (cdr line) " "))))))
3888 elvi-alist))
3890 (defun anything-c-surfraw-sort-elvi (&optional only-fav)
3891 "Sort elvi alist according to `anything-c-surfraw-favorites'."
3892 (let* ((elvi-alist (anything-c-build-elvi-alist))
3893 (fav-alist (loop for j in anything-c-surfraw-favorites
3894 collect (assoc j elvi-alist)))
3895 (rest-elvi (loop for i in elvi-alist
3896 if (not (member i fav-alist))
3897 collect i)))
3898 (if only-fav
3899 fav-alist
3900 (append fav-alist rest-elvi))))
3902 (defun anything-c-surfraw-get-url (engine pattern)
3903 "Get search url from `engine' for `anything-pattern'."
3904 (with-temp-buffer
3905 (apply #'call-process "surfraw" nil t nil
3906 `(,engine
3907 "-p"
3908 ,anything-pattern))
3909 (buffer-string)))
3912 (defvar anything-c-surfraw-elvi nil)
3913 (defvar anything-c-surfraw-cache nil)
3914 (defvar anything-c-source-surfraw
3915 '((name . "Surfraw")
3916 (init . (lambda ()
3917 (unless anything-c-surfraw-cache
3918 (setq anything-c-surfraw-elvi (anything-c-surfraw-sort-elvi
3919 anything-c-surfraw-use-only-favorites))
3920 (setq anything-c-surfraw-cache
3921 (loop for i in anything-c-surfraw-elvi
3922 if (car i)
3923 collect (car i))))))
3924 (candidates . (lambda ()
3925 (loop for i in anything-c-surfraw-cache
3926 for s = (anything-c-surfraw-get-url i anything-pattern)
3927 collect (concat (propertize i
3928 'face '((:foreground "green"))
3929 'help-echo (cdr (assoc i anything-c-surfraw-elvi)))
3930 ">>>" (replace-regexp-in-string "\n" "" s)))))
3931 (action . (("Browse" . (lambda (candidate)
3932 (let ((url (second (split-string candidate ">>>"))))
3933 (browse-url url))))
3934 ("Browse firefox" . (lambda (candidate)
3935 (let ((url (second (split-string candidate ">>>"))))
3936 (browse-url-firefox url t))))))
3937 (volatile)
3938 (requires-pattern . 3)
3939 (multiline)
3940 (delayed)))
3942 ;; (anything 'anything-c-source-surfraw)
3944 ;;; Emms
3946 (defun anything-emms-stream-edit-bookmark (elm)
3947 "Change the information of current emms-stream bookmark from anything."
3948 (interactive)
3949 (let* ((cur-buf anything-current-buffer)
3950 (bookmark (assoc elm emms-stream-list))
3951 (name (read-from-minibuffer "Description: "
3952 (nth 0 bookmark)))
3953 (url (read-from-minibuffer "URL: "
3954 (nth 1 bookmark)))
3955 (fd (read-from-minibuffer "Feed Descriptor: "
3956 (int-to-string (nth 2 bookmark))))
3957 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
3958 (format "%s" (car (last bookmark))))))
3959 (save-excursion
3960 (emms-streams)
3961 (when (re-search-forward (concat "^" name) nil t)
3962 (beginning-of-line)
3963 (emms-stream-delete-bookmark)
3964 (emms-stream-add-bookmark name url (string-to-number fd) type)
3965 (emms-stream-save-bookmarks-file)
3966 (emms-stream-quit)
3967 (switch-to-buffer cur-buf)))))
3969 (defun anything-emms-stream-delete-bookmark (elm)
3970 "Delete an emms-stream bookmark from anything."
3971 (interactive)
3972 (let* ((cur-buf anything-current-buffer)
3973 (bookmark (assoc elm emms-stream-list))
3974 (name (nth 0 bookmark)))
3975 (save-excursion
3976 (emms-streams)
3977 (when (re-search-forward (concat "^" name) nil t)
3978 (beginning-of-line)
3979 (emms-stream-delete-bookmark)
3980 (emms-stream-save-bookmarks-file)
3981 (emms-stream-quit)
3982 (switch-to-buffer cur-buf)))))
3984 (defvar anything-c-source-emms-streams
3985 '((name . "Emms Streams")
3986 (init . (lambda ()
3987 (emms-stream-init)))
3988 (candidates . (lambda ()
3989 (mapcar 'car emms-stream-list)))
3990 (action . (("Play" . (lambda (elm)
3991 (let* ((stream (assoc elm emms-stream-list))
3992 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
3993 (url (second stream)))
3994 (funcall fn url))))
3995 ("Delete" . anything-emms-stream-delete-bookmark)
3996 ("Edit" . anything-emms-stream-edit-bookmark)))
3997 (filtered-candidate-transformer . anything-c-adaptive-sort)))
3998 ;; (anything 'anything-c-source-emms-streams)
4000 ;; Don't forget to set `emms-source-file-default-directory'
4001 (defvar anything-c-source-emms-dired
4002 '((name . "Music Directory")
4003 (candidates . (lambda ()
4004 (cddr (directory-files emms-source-file-default-directory))))
4005 (action .
4006 (("Play Directory" . (lambda (item)
4007 (emms-play-directory
4008 (expand-file-name
4009 item
4010 emms-source-file-default-directory))))
4011 ("Open dired in file's directory" . (lambda (item)
4012 (anything-c-open-dired
4013 (expand-file-name
4014 item
4015 emms-source-file-default-directory))))))
4016 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4017 ;; (anything 'anything-c-source-emms-dired)
4019 ;;; Jabber Contacts (jabber.el)
4020 (defun anything-c-jabber-online-contacts ()
4021 "List online Jabber contacts."
4022 (with-no-warnings
4023 (let (jids)
4024 (dolist (item (jabber-concat-rosters) jids)
4025 (when (get item 'connected)
4026 (push (if (get item 'name)
4027 (cons (get item 'name) item)
4028 (cons (symbol-name item) item)) jids))))))
4030 (defvar anything-c-source-jabber-contacts
4031 '((name . "Jabber Contacts")
4032 (init . (lambda () (require 'jabber)))
4033 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
4034 (action . (lambda (x)
4035 (jabber-chat-with
4036 (jabber-read-account)
4037 (symbol-name
4038 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
4039 ;; (anything 'anything-c-source-jabber-contacts)
4042 ;;; Call source.
4043 (defvar anything-source-select-buffer "*anything source select*")
4044 (defvar anything-c-source-call-source
4045 `((name . "Call anything source")
4046 (candidate-number-limit)
4047 (candidates . (lambda ()
4048 (loop for vname in (all-completions "anything-c-source-" obarray)
4049 for var = (intern vname)
4050 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
4051 if name collect (cons (format "%s `%s'"
4052 name (propertize vname 'face 'font-lock-variable-name-face))
4053 var))))
4054 (action . (("Invoke anything with selected source" .
4055 (lambda (candidate)
4056 (setq anything-candidate-number-limit 9999)
4057 (anything candidate nil nil nil nil
4058 anything-source-select-buffer)))
4059 ("Describe variable" . describe-variable)))
4060 (persistent-action . describe-variable)
4061 (persistent-help . "Show description of this source")))
4062 ;; (anything 'anything-c-source-call-source)
4064 (defun anything-call-source ()
4065 "Preconfigured `anything' to call anything source."
4066 (interactive)
4067 (anything 'anything-c-source-call-source nil nil nil nil
4068 anything-source-select-buffer))
4070 (defun anything-call-source-from-anything ()
4071 "Call anything source within `anything' session."
4072 (interactive)
4073 (setq anything-input-idle-delay 0)
4074 (anything-set-sources '(anything-c-source-call-source)))
4076 ;; Occur
4077 (defvar anything-c-source-occur
4078 '((name . "Occur")
4079 (init . (lambda ()
4080 (setq anything-c-source-occur-current-buffer
4081 (current-buffer))))
4082 (candidates . (lambda ()
4083 (setq anything-occur-buf (get-buffer-create "*Anything Occur*"))
4084 (with-current-buffer anything-occur-buf
4085 (erase-buffer)
4086 (let ((count (occur-engine anything-pattern
4087 (list anything-c-source-occur-current-buffer) anything-occur-buf
4088 list-matching-lines-default-context-lines nil
4089 list-matching-lines-buffer-name-face
4090 nil list-matching-lines-face
4091 (not (eq occur-excluded-properties t)))))
4092 (when (> count 0)
4093 (let ((lines (split-string (buffer-string) "\n" t)))
4094 (cdr lines)))))))
4095 (action . (("Goto line" . (lambda (candidate)
4096 (anything-goto-line (string-to-number candidate) anything-c-source-occur-current-buffer)))))
4097 (requires-pattern . 1)
4098 (volatile)))
4099 ;; (anything 'anything-c-source-occur)
4101 ;; Do many actions for input
4102 (defvar anything-c-source-create
4103 '((name . "Create")
4104 (dummy)
4105 (action)
4106 (candidate-number-limit . 9999)
4107 (action-transformer . anything-create--actions))
4108 "Do many create actions from `anything-pattern'.
4109 See also `anything-create--actions'.")
4110 ;; (anything 'anything-c-source-create)
4112 (defun anything-create-from-anything ()
4113 "Run `anything-create' from `anything' as a fallback."
4114 (interactive)
4115 (anything-run-after-quit 'anything-create nil anything-pattern))
4117 (defun anything-create (&optional string initial-input)
4118 "Preconfigured `anything' to do many create actions from STRING.
4119 See also `anything-create--actions'."
4120 (interactive)
4121 (setq string (or string (read-string "Create Anything: " initial-input)))
4122 (anything '(((name . "Anything Create")
4123 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
4124 (candidates . anything-create--actions)
4125 (candidate-number-limit . 9999)
4126 (action . (lambda (func) (funcall func string)))))))
4128 (defun anything-create--actions (&rest ignored)
4129 "Default actions for `anything-create' / `anything-c-source-create'."
4130 (remove-if-not
4131 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
4132 (append anything-create--actions-private
4133 '(("find-file" . find-file)
4134 ("find-file other window" . find-file-other-window)
4135 ("New buffer" . switch-to-buffer)
4136 ("New buffer other window" . switch-to-buffer-other-window)
4137 ("Bookmark Set" . bookmark-set)
4138 ("Set Register" .
4139 (lambda (x) (set-register (read-char "Register: ") x)))
4140 ("Insert Linkd star" . linkd-insert-star)
4141 ("Insert Linkd Tag" . linkd-insert-tag)
4142 ("Insert Linkd Link" . linkd-insert-link)
4143 ("Insert Linkd Lisp" . linkd-insert-lisp)
4144 ("Insert Linkd Wiki" . linkd-insert-wiki)
4145 ("Google Search" . google)))))
4147 ;; Minibuffer History
4148 (defvar anything-c-source-minibuffer-history
4149 '((name . "Minibuffer History")
4150 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
4151 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
4152 (if (consp (car history))
4153 (mapcar 'prin1-to-string history)
4154 history))))
4155 (migemo)
4156 (action . insert)))
4157 ;; (anything 'anything-c-source-minibuffer-history)
4159 ;; elscreen
4160 (defvar anything-c-source-elscreen
4161 '((name . "Elscreen")
4162 (candidates . (lambda ()
4163 (if (cdr (elscreen-get-screen-to-name-alist))
4164 (sort
4165 (loop for sname in (elscreen-get-screen-to-name-alist)
4166 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
4167 finally (return lst))
4168 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
4169 (action . (("Change Screen".
4170 (lambda (candidate)
4171 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
4172 ("Kill Screen(s)".
4173 (lambda (candidate)
4174 (anything-aif (anything-marked-candidates)
4175 (dolist (i it)
4176 (elscreen-kill-internal (- (aref i 1) (aref "0" 0))))
4177 (elscreen-kill-internal (- (aref candidate 1) (aref "0" 0))))))
4178 ("Only Screen".
4179 (lambda (candidate)
4180 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
4181 (elscreen-kill-others)))))))
4182 ;; (anything 'anything-c-source-elscreen)
4184 ;;;; <System>
4186 ;;; Top (process)
4187 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
4188 "Top command (batch mode). %s is replaced with `frame-width'.")
4189 (defvar anything-c-source-top
4190 '((name . "Top (Press C-c C-u to refresh)")
4191 (init . anything-c-top-init)
4192 (candidates-in-buffer)
4193 (display-to-real . anything-c-top-display-to-real)
4194 (update . anything-c-top-update)
4195 (action
4196 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
4197 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
4198 ("Copy PID" . (lambda (pid) (kill-new pid))))))
4199 ;; (anything 'anything-c-source-top)
4201 (defun anything-c-top-sh (cmd)
4202 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
4204 (defun anything-c-top-init ()
4205 (with-current-buffer (anything-candidate-buffer 'global)
4206 (call-process-shell-command
4207 (format anything-c-top-command
4208 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
4209 nil (current-buffer))))
4211 (defun anything-c-top-display-to-real (line)
4212 (car (split-string line)))
4214 (defun anything-c-top-update ()
4215 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
4216 (anything-c-top-init)))
4218 (defun anything-top ()
4219 "Preconfigured `anything' for top command."
4220 (interactive)
4221 (let ((anything-samewindow t)
4222 (anything-enable-shortcuts)
4223 (anything-display-function 'anything-default-display-buffer)
4224 (anything-candidate-number-limit 9999))
4225 (save-window-excursion
4226 (delete-other-windows)
4227 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
4229 ;;; Timers
4230 (defvar anything-c-source-absolute-time-timers
4231 '((name . "Absolute Time Timers")
4232 (candidates . timer-list)
4233 (type . timer)))
4234 ;; (anything 'anything-c-source-absolute-time-timers)
4236 (defvar anything-c-source-idle-time-timers
4237 '((name . "Idle Time Timers")
4238 (candidates . timer-idle-list)
4239 (type . timer)))
4240 ;; (anything 'anything-c-source-idle-time-timers)
4242 (defun anything-c-timer-real-to-display (timer)
4243 (destructuring-bind (_ t1 t2 t3 _ func args &rest rest) (append timer nil)
4244 (format "%s %s(%s)"
4245 (format-time-string "%m/%d %T" (list t1 t2 t3))
4246 func
4247 (mapconcat 'prin1-to-string (aref timer 6) " "))))
4249 ;;; X RandR resolution change
4250 ;;; FIXME I do not care multi-display.
4251 (defvar anything-c-xrandr-output "VGA")
4252 (defvar anything-c-xrandr-screen "0")
4253 (defvar anything-c-source-xrandr-change-resolution
4254 '((name . "Change Resolution")
4255 (candidates
4256 . (lambda ()
4257 (with-temp-buffer
4258 (call-process "xrandr" nil (current-buffer) nil
4259 "--screen" anything-c-xrandr-screen "-q")
4260 (goto-char 1)
4261 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
4262 collect (match-string 1)))))
4263 (action
4264 ("Change Resolution" . (lambda (mode)
4265 (call-process "xrandr" nil nil nil
4266 "--screen" anything-c-xrandr-screen
4267 "--output" anything-c-xrandr-output
4268 "--mode" mode))))))
4269 ;; (anything 'anything-c-source-xrandr-change-resolution)
4271 ;;; Xfont selection
4272 (defun anything-c-persistent-xfont-action (elm)
4273 "Show current font temporarily"
4274 (let ((current-font (cdr (assoc 'font (frame-parameters))))
4275 (default-font elm))
4276 (unwind-protect
4277 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
4278 (set-frame-font current-font))))
4280 (defvar anything-c-xfonts-cache nil)
4281 (defvar anything-c-source-xfonts
4282 '((name . "X Fonts")
4283 (init . (lambda ()
4284 (unless anything-c-xfonts-cache
4285 (setq anything-c-xfonts-cache
4286 (x-list-fonts "*")))))
4287 (candidates . anything-c-xfonts-cache)
4288 (action . (("Copy to kill ring" . (lambda (elm)
4289 (kill-new elm)))
4290 ("Set Font" . (lambda (elm)
4291 (kill-new elm)
4292 (set-frame-font elm 'keep-size)
4293 (message "New font have been copied to kill ring")))))
4294 (persistent-action . anything-c-persistent-xfont-action)
4295 (persistent-help . "Switch to this font temporarily")))
4297 (defun anything-select-xfont ()
4298 "Preconfigured `anything' to select Xfont."
4299 (interactive)
4300 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
4302 ;; (anything 'anything-c-source-xfonts)
4304 ;; Source for Debian/Ubuntu users
4305 (defvar anything-c-source-apt
4306 '((name . "APT")
4307 (init . anything-c-apt-init)
4308 (candidates-in-buffer)
4309 (display-to-real . anything-c-apt-display-to-real)
4310 (candidate-number-limit . 9999)
4311 (action
4312 ("Show package description" . anything-c-apt-cache-show)
4313 ("Install package" . anything-c-apt-install))))
4314 ;; (anything 'anything-c-source-apt)
4316 (defvar anything-c-apt-query "emacs")
4317 (defvar anything-c-apt-search-command "apt-cache search '%s'")
4318 (defvar anything-c-apt-show-command "apt-cache show '%s'")
4319 (defvar anything-c-apt-install-command "xterm -e sudo apt-get install '%s' &")
4321 (defun anything-apt (query)
4322 "Preconfigured `anything' : frontend of APT package manager."
4323 (interactive "sAPT search: ")
4324 (let ((anything-c-apt-query query))
4325 (anything 'anything-c-source-apt)))
4327 (defun anything-c-apt-init ()
4328 (with-current-buffer
4329 (anything-candidate-buffer
4330 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
4331 (call-process-shell-command
4332 (format anything-c-apt-search-command anything-c-apt-query)
4333 nil (current-buffer))))
4334 (defun anything-c-apt-display-to-real (line)
4335 (car (split-string line " - ")))
4337 (defun anything-c-shell-command-if-needed (command)
4338 (interactive "sShell command: ")
4339 (if (get-buffer command) ; if the buffer already exists
4340 (switch-to-buffer command) ; then just switch to it
4341 (switch-to-buffer command) ; otherwise create it
4342 (insert (shell-command-to-string command))))
4344 (defun anything-c-apt-cache-show (package)
4345 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
4346 (defun anything-c-apt-install (package)
4347 (shell-command (format anything-c-apt-install-command package) "*apt install*"))
4349 ;; (anything-c-apt-install "jed")
4350 ;; Sources for gentoo users
4352 (defvar anything-gentoo-prefered-shell 'eshell
4353 "Your favorite shell to run emerge command.")
4355 (defvar anything-c-gentoo-use-flags nil)
4356 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
4357 (defvar anything-c-cache-gentoo nil)
4358 (defvar anything-c-cache-world nil)
4359 (defvar anything-c-source-gentoo
4360 '((name . "Portage sources")
4361 (init . (lambda ()
4362 (get-buffer-create anything-c-gentoo-buffer)
4363 (unless anything-c-cache-gentoo
4364 (anything-c-gentoo-setup-cache))
4365 (unless anything-c-cache-world
4366 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
4367 (anything-c-gentoo-init-list)))
4368 (candidates-in-buffer)
4369 (match . identity)
4370 (candidate-transformer anything-c-highlight-world)
4371 (action . (("Show package" . (lambda (elm)
4372 (anything-c-gentoo-eshell-action elm "eix")))
4373 ("Show history" . (lambda (elm)
4374 (if (member elm anything-c-cache-world)
4375 (anything-c-gentoo-eshell-action elm "genlop -qe")
4376 (message "No infos on packages not yet installed"))))
4377 ("Copy in kill-ring" . kill-new)
4378 ("insert at point" . insert)
4379 ("Browse HomePage" . (lambda (elm)
4380 (browse-url (car (anything-c-gentoo-get-url elm)))))
4381 ("Show extra infos" . (lambda (elm)
4382 (if (member elm anything-c-cache-world)
4383 (anything-c-gentoo-eshell-action elm "genlop -qi")
4384 (message "No infos on packages not yet installed"))))
4385 ("Show use flags" . (lambda (elm)
4386 (anything-c-gentoo-default-action elm "equery" "-C" "u")
4387 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
4388 (font-lock-mode 1)))
4389 ("Run emerge pretend" . (lambda (elm)
4390 (anything-c-gentoo-eshell-action elm "emerge -p")))
4391 ("Emerge" . (lambda (elm)
4392 (anything-gentoo-install elm :action 'install)))
4393 ("Unmerge" . (lambda (elm)
4394 (anything-gentoo-install elm :action 'uninstall)))
4395 ("Show dependencies" . (lambda (elm)
4396 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
4397 ("Show related files" . (lambda (elm)
4398 (anything-c-gentoo-default-action elm "equery" "files")))
4399 ("Refresh" . (lambda (elm)
4400 (anything-c-gentoo-setup-cache)
4401 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
4403 ;; (anything 'anything-c-source-gentoo)
4405 (defun* anything-gentoo-install (candidate &key action)
4406 (funcall anything-gentoo-prefered-shell)
4407 (let ((command (case action
4408 ('install "*sudo emerge -av ")
4409 ('uninstall "*sudo emerge -avC ")
4410 (t (error "Unknow action")))))
4411 (if (anything-marked-candidates)
4412 (let ((elms (mapconcat 'identity (anything-marked-candidates) " ")))
4413 (insert (concat command elms)))
4414 (insert (concat command candidate)))))
4417 (defun anything-c-gentoo-default-action (elm command &rest args)
4418 "Gentoo default action that use `anything-c-gentoo-buffer'."
4419 (if (member elm anything-c-cache-world)
4420 (progn
4421 (switch-to-buffer anything-c-gentoo-buffer)
4422 (erase-buffer)
4423 (let ((com-list (append args (list elm))))
4424 (apply #'call-process command nil t nil
4425 com-list)))
4426 (message "No infos on packages not yet installed")))
4428 (defvar anything-c-source-use-flags
4429 '((name . "Use Flags")
4430 (init . (lambda ()
4431 (unless anything-c-gentoo-use-flags
4432 (anything-c-gentoo-setup-use-flags-cache))
4433 (anything-c-gentoo-get-use)))
4434 (candidates-in-buffer)
4435 (match . identity)
4436 (candidate-transformer anything-c-highlight-local-use)
4437 (action . (("Description"
4438 . (lambda (elm)
4439 (switch-to-buffer anything-c-gentoo-buffer)
4440 (erase-buffer)
4441 (apply #'call-process "euse" nil t nil
4442 `("-i"
4443 ,elm))
4444 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
4445 (font-lock-mode 1)))
4446 ("Enable"
4447 . (lambda (elm)
4448 (anything-c-gentoo-eshell-action elm "*sudo euse -E")))
4449 ("Disable"
4450 . (lambda (elm)
4451 (anything-c-gentoo-eshell-action elm "*sudo euse -D")))
4452 ("Remove"
4453 . (lambda (elm)
4454 (anything-c-gentoo-eshell-action elm "*sudo euse -P")))
4455 ("Show which dep use this flag"
4456 . (lambda (elm)
4457 (switch-to-buffer anything-c-gentoo-buffer)
4458 (erase-buffer)
4459 (apply #'call-process "equery" nil t nil
4460 `("-C"
4462 ,elm))))))))
4465 ;; (anything 'anything-c-source-use-flags)
4467 (defun anything-c-gentoo-init-list ()
4468 "Initialize buffer with all packages in Portage."
4469 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
4470 (buf (anything-candidate-buffer 'portage-buf)))
4471 (with-current-buffer buf
4472 (dolist (i anything-c-cache-gentoo)
4473 (insert (concat i "\n"))))))
4475 (defun anything-c-gentoo-setup-cache ()
4476 "Set up `anything-c-cache-gentoo'"
4477 (setq anything-c-cache-gentoo
4478 (split-string (with-temp-buffer
4479 (call-process "eix" nil t nil
4480 "--only-names")
4481 (buffer-string)))))
4483 (defun anything-c-gentoo-eshell-action (elm command)
4484 (when (get-buffer "*EShell Command Output*")
4485 (kill-buffer "*EShell Command Output*"))
4486 (message "Wait searching...")
4487 (let ((buf-fname (buffer-file-name anything-current-buffer)))
4488 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
4489 (progn
4490 (save-window-excursion
4491 (pop-to-buffer "*scratch*")
4492 (eshell-command (format "%s %s" command elm)))
4493 (pop-to-buffer "*EShell Command Output*"))
4494 (eshell-command (format "%s %s" command elm)))))
4496 (defun anything-c-gentoo-get-use ()
4497 "Initialize buffer with all use flags."
4498 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
4499 (buf (anything-candidate-buffer 'use-buf)))
4500 (with-current-buffer buf
4501 (dolist (i anything-c-gentoo-use-flags)
4502 (insert (concat i "\n"))))))
4505 (defun anything-c-gentoo-setup-use-flags-cache ()
4506 "Setup `anything-c-gentoo-use-flags'"
4507 (setq anything-c-gentoo-use-flags
4508 (split-string (with-temp-buffer
4509 (call-process "eix" nil t nil
4510 "--print-all-useflags")
4511 (buffer-string)))))
4513 (defun anything-c-gentoo-get-url (elm)
4514 "Return a list of urls from eix output."
4515 (split-string (eshell-command-result
4516 (format "eix %s | grep Homepage | awk '{print $2}'" elm))))
4518 (defun anything-c-gentoo-get-world ()
4519 "Return list of all installed package on your system."
4520 (split-string (with-temp-buffer
4521 (call-process "qlist" nil t nil
4522 "-I")
4523 (buffer-string))))
4525 (defun anything-c-gentoo-get-local-use ()
4526 (split-string (with-temp-buffer
4527 (call-process "portageq" nil t nil
4528 "envvar"
4529 "USE")
4530 (buffer-string))))
4532 (defface anything-gentoo-match-face '((t (:foreground "red")))
4533 "Face for anything-gentoo installed packages."
4534 :group 'traverse-faces)
4536 (defun anything-c-highlight-world (eix)
4537 "Highlight all installed package."
4538 (loop for i in eix
4539 if (member i anything-c-cache-world)
4540 collect (propertize i 'face 'anything-gentoo-match-face)
4541 else
4542 collect i))
4544 (defun anything-c-highlight-local-use (use-flags)
4545 (let ((local-uses (anything-c-gentoo-get-local-use)))
4546 (loop for i in use-flags
4547 if (member i local-uses)
4548 collect (propertize i 'face 'anything-gentoo-match-face)
4549 else
4550 collect i)))
4552 (defvar anything-c-source-emacs-process
4553 '((name . "Emacs Process")
4554 (candidates . (lambda () (mapcar #'process-name (process-list))))
4555 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
4557 ;; (anything 'anything-c-source-emacs-process)
4560 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4561 ;;; Files
4562 (defvar anything-c-external-commands-list nil
4563 "A list of all external commands the user can execute. If this
4564 variable is not set by the user, it will be calculated
4565 automatically.")
4567 (defun anything-c-external-commands-list-1 ()
4568 "Returns a list of all external commands the user can execute.
4570 If `anything-c-external-commands-list' is non-nil it will
4571 return its contents. Else it calculates all external commands
4572 and sets `anything-c-external-commands-list'.
4574 The code is ripped out of `eshell-complete-commands-list'."
4575 (if anything-c-external-commands-list
4576 anything-c-external-commands-list
4577 (setq anything-c-external-commands-list
4578 (let* ((paths (split-string (getenv "PATH") path-separator))
4579 (cwd (file-name-as-directory
4580 (expand-file-name default-directory)))
4581 (path "") (comps-in-path ())
4582 (file "") (filepath "") (completions ()))
4583 ;; Go thru each path in the search path, finding completions.
4584 (while paths
4585 (setq path (file-name-as-directory
4586 (expand-file-name (or (car paths) ".")))
4587 comps-in-path
4588 (and (file-accessible-directory-p path)
4589 (file-name-all-completions "" path)))
4590 ;; Go thru each completion found, to see whether it should be
4591 ;; used, e.g. see if it's executable.
4592 (while comps-in-path
4593 (setq file (car comps-in-path)
4594 filepath (concat path file))
4595 (if (and (not (member file completions))
4596 (or (string-equal path cwd)
4597 (not (file-directory-p filepath)))
4598 (file-executable-p filepath))
4599 (setq completions (cons file completions)))
4600 (setq comps-in-path (cdr comps-in-path)))
4601 (setq paths (cdr paths)))
4602 completions))))
4604 (defun anything-c-file-buffers (filename)
4605 "Returns a list of buffer names corresponding to FILENAME."
4606 (let ((name (expand-file-name filename))
4607 (buf-list ()))
4608 (dolist (buf (buffer-list) buf-list)
4609 (let ((bfn (buffer-file-name buf)))
4610 (when (and bfn (string= name bfn))
4611 (push (buffer-name buf) buf-list))))))
4613 (defun anything-c-delete-file (file)
4614 "Delete the given file after querying the user.
4615 Ask to kill buffers associated with that file, too."
4616 (let ((buffers (anything-c-file-buffers file)))
4617 (dired-delete-file file 'dired-recursive-deletes)
4618 (when buffers
4619 (dolist (buf buffers)
4620 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
4621 (kill-buffer buf))))))
4623 (defun anything-c-open-file-externally (file)
4624 "Open FILE with an external tool. Query the user which tool to use."
4625 (start-process "anything-c-open-file-externally"
4627 (completing-read "Program: "
4628 (anything-c-external-commands-list-1))
4629 file))
4631 (defun w32-shell-execute-open-file (file)
4632 (interactive "fOpen file:")
4633 (with-no-warnings
4634 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
4635 "/" "\\"
4636 (replace-regexp-in-string ; strip cygdrive paths
4637 "/cygdrive/\\(.\\)" "\\1:" file nil nil) nil t))))
4638 (defun anything-c-open-file-with-default-tool (file)
4639 "Open FILE with the default tool on this platform."
4640 (if (eq system-type 'windows-nt)
4641 (w32-shell-execute-open-file file)
4642 (start-process "anything-c-open-file-with-default-tool"
4644 (cond ((eq system-type 'gnu/linux)
4645 "xdg-open")
4646 ((or (eq system-type 'darwin) ;; Mac OS X
4647 (eq system-type 'macos)) ;; Mac OS 9
4648 "open"))
4649 file)))
4651 (defun anything-c-open-dired (file)
4652 "Opens a dired buffer in FILE's directory. If FILE is a
4653 directory, open this directory."
4654 (if (file-directory-p file)
4655 (dired file)
4656 (dired (file-name-directory file))
4657 (dired-goto-file file)))
4659 (defun anything-c-display-to-real-line (candidate)
4660 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
4661 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
4662 (error "Line number not found")))
4664 (defun anything-c-action-line-goto (lineno-and-content)
4665 (apply #'anything-goto-file-line (anything-attr 'target-file)
4666 (append lineno-and-content
4667 (list (if (and (anything-attr-defined 'target-file)
4668 (not anything-in-persistent-action))
4669 'find-file-other-window
4670 'find-file)))))
4672 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
4673 (apply #'anything-goto-file-line file-line-content))
4675 (require 'compile)
4676 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
4677 (mapcar
4678 (lambda (candidate)
4679 (if (not (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate))
4680 (error "Filename and line number not found")
4681 (let ((filename (match-string 1 candidate))
4682 (lineno (match-string 2 candidate))
4683 (content (match-string 3 candidate)))
4684 (cons (format "%s:%s\n %s"
4685 (propertize filename 'face compilation-info-face)
4686 (propertize lineno 'face compilation-line-face)
4687 content)
4688 (list (expand-file-name
4689 filename
4690 (anything-aif (anything-attr 'default-directory)
4691 (if (functionp it) (funcall it) it)
4692 (and (anything-candidate-buffer)
4693 (buffer-local-value
4694 'default-directory
4695 (anything-candidate-buffer)))))
4696 (string-to-number lineno) content)))))
4697 candidates))
4699 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
4700 (anything-aif (anything-attr 'before-jump-hook)
4701 (funcall it))
4702 (when file (funcall find-file-function file))
4703 (if (anything-attr-defined 'adjust)
4704 (anything-c-goto-line-with-adjustment lineno content)
4705 (anything-goto-line lineno))
4706 (unless (anything-attr-defined 'recenter)
4707 (set-window-start (get-buffer-window anything-current-buffer) (point)))
4708 (anything-aif (anything-attr 'after-jump-hook)
4709 (funcall it))
4710 (when anything-in-persistent-action
4711 (anything-match-line-color-current-line)))
4713 (defun anything-find-file-as-root (candidate)
4714 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
4716 ;; borrowed from etags.el
4717 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
4718 (defun anything-c-goto-line-with-adjustment (line line-content)
4719 (let ((startpos)
4720 offset found pat)
4721 ;; This constant is 1/2 the initial search window.
4722 ;; There is no sense in making it too small,
4723 ;; since just going around the loop once probably
4724 ;; costs about as much as searching 2000 chars.
4725 (setq offset 1000
4726 found nil
4727 pat (concat (if (eq selective-display t)
4728 "\\(^\\|\^m\\) *" "^ *") ;allow indent
4729 (regexp-quote line-content)))
4730 ;; If no char pos was given, try the given line number.
4731 (setq startpos (progn (anything-goto-line line) (point)))
4732 (or startpos (setq startpos (point-min)))
4733 ;; First see if the tag is right at the specified location.
4734 (goto-char startpos)
4735 (setq found (looking-at pat))
4736 (while (and (not found)
4737 (progn
4738 (goto-char (- startpos offset))
4739 (not (bobp))))
4740 (setq found
4741 (re-search-forward pat (+ startpos offset) t)
4742 offset (* 3 offset))) ; expand search window
4743 (or found
4744 (re-search-forward pat nil t)
4745 (error "not found")))
4746 ;; Position point at the right place
4747 ;; if the search string matched an extra Ctrl-m at the beginning.
4748 (and (eq selective-display t)
4749 (looking-at "\^m")
4750 (forward-char 1))
4751 (beginning-of-line))
4753 (anything-document-attribute 'default-directory "type . file-line"
4754 "`default-directory' to interpret file.")
4755 (anything-document-attribute 'before-jump-hook "type . file-line / line"
4756 "Function to call before jumping to the target location.")
4757 (anything-document-attribute 'after-jump-hook "type . file-line / line"
4758 "Function to call after jumping to the target location.")
4759 (anything-document-attribute 'adjust "type . file-line"
4760 "Search around line matching line contents.")
4761 (anything-document-attribute 'recenter "type . file-line / line"
4762 "`recenter' after jumping.")
4763 (anything-document-attribute 'target-file "type . line"
4764 "Goto line of target-file.")
4766 (defun anything-c-call-interactively (cmd-or-name)
4767 "Execute CMD-OR-NAME as Emacs command.
4768 It is added to `extended-command-history'.
4769 `anything-current-prefix-arg' is used as the command's prefix argument."
4770 (setq extended-command-history
4771 (cons (anything-c-stringify cmd-or-name)
4772 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
4773 (let ((current-prefix-arg anything-current-prefix-arg)
4774 (cmd (anything-c-symbolify cmd-or-name)))
4775 (if (stringp (symbol-function cmd))
4776 (execute-kbd-macro (symbol-function cmd))
4777 (call-interactively cmd))))
4779 (defun anything-c-set-variable (var)
4780 "Set value to VAR interactively."
4781 (interactive)
4782 (let ((sym (anything-c-symbolify var)))
4783 (set sym (eval-minibuffer (format "Set %s: " var)
4784 (prin1-to-string (symbol-value sym))))))
4785 ;; (setq hh 12)
4786 ;; (anything-c-set-variable 'hh)
4788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4789 (defvar anything-match-line-overlay-face nil)
4790 (defvar anything-match-line-overlay nil)
4792 (defun anything-match-line-color-current-line (&optional start end buf face rec)
4793 "Highlight and underline current position"
4794 (let ((args (list (or start (line-beginning-position))
4795 (or end (1+ (line-end-position)))
4796 buf)))
4797 (if (not anything-match-line-overlay)
4798 (setq anything-match-line-overlay (apply 'make-overlay args))
4799 (apply 'move-overlay anything-match-line-overlay args)))
4800 (overlay-put anything-match-line-overlay
4801 'face (or face anything-match-line-overlay-face))
4802 (when rec
4803 (goto-char start)
4804 (recenter)))
4806 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
4808 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
4809 "Face for source header in the anything buffer." :group 'anything)
4811 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
4813 (defun anything-match-line-cleanup ()
4814 (when anything-match-line-overlay
4815 (delete-overlay anything-match-line-overlay)
4816 (setq anything-match-line-overlay nil)))
4818 (defun anything-match-line-update ()
4819 (when anything-match-line-overlay
4820 (delete-overlay anything-match-line-overlay)
4821 (anything-match-line-color-current-line)))
4823 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
4824 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
4826 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4827 ;;; Files
4828 (defun anything-c-transform-file-load-el (actions candidate)
4829 "Add action to load the file CANDIDATE if it is an emacs lisp
4830 file. Else return ACTIONS unmodified."
4831 (if (member (file-name-extension candidate) '("el" "elc"))
4832 (append actions '(("Load Emacs Lisp File" . load-file)))
4833 actions))
4835 (defun anything-c-transform-file-browse-url (actions candidate)
4836 "Add an action to browse the file CANDIDATE if it in a html
4837 file or URL. Else return ACTIONS unmodified."
4838 (let ((browse-action '("Browse with Browser" . browse-url)))
4839 (cond ((string-match "^http\\|^ftp" candidate)
4840 (cons browse-action actions))
4841 ((string-match "\\.html?$" candidate)
4842 (append actions (list browse-action)))
4843 (t actions))))
4845 ;;;; Function
4846 (defun anything-c-transform-function-call-interactively (actions candidate)
4847 "Add an action to call the function CANDIDATE interactively if
4848 it is a command. Else return ACTIONS unmodified."
4849 (if (commandp (intern-soft candidate))
4850 (append actions '(("Call Interactively"
4852 anything-c-call-interactively)))
4853 actions))
4855 ;;;; S-Expressions
4856 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
4857 "If CANDIDATE's `car' is a command, then add an action to
4858 evaluate it and put it onto the `command-history'."
4859 (if (commandp (car (read candidate)))
4860 ;; Make it first entry
4861 (cons '("Eval and put onto command-history" .
4862 (lambda (sexp)
4863 (let ((sym (read sexp)))
4864 (eval sym)
4865 (setq command-history
4866 (cons sym command-history)))))
4867 actions)
4868 actions))
4870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4871 ;;; Buffers
4872 (defun anything-c-skip-boring-buffers (buffers)
4873 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
4875 (defun anything-c-skip-current-buffer (buffers)
4876 (if anything-allow-skipping-current-buffer
4877 (remove (buffer-name anything-current-buffer) buffers)
4878 buffers))
4880 (defun anything-c-shadow-boring-buffers (buffers)
4881 "Buffers matching `anything-c-boring-buffer-regexp' will be
4882 displayed with the `file-name-shadow' face if available."
4883 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
4885 ;;; Files
4886 (defun anything-c-shadow-boring-files (files)
4887 "Files matching `anything-c-boring-file-regexp' will be
4888 displayed with the `file-name-shadow' face if available."
4889 (anything-c-shadow-entries files anything-c-boring-file-regexp))
4891 (defun anything-c-skip-boring-files (files)
4892 "Files matching `anything-c-boring-file-regexp' will be skipped."
4893 (anything-c-skip-entries files anything-c-boring-file-regexp))
4894 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
4896 (defun anything-c-skip-current-file (files)
4897 "Current file will be skipped."
4898 (remove (buffer-file-name anything-current-buffer) files))
4900 (defun anything-c-w32-pathname-transformer (args)
4901 "Change undesirable features of windows pathnames to ones more acceptable to
4902 other candidate transformers."
4903 (if (eq system-type 'windows-nt)
4904 (mapcar (lambda (x)
4905 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
4906 (mapcar (lambda (y)
4907 (replace-regexp-in-string "\\\\" "/" y)) args))
4908 args))
4910 (defun anything-c-shorten-home-path (files)
4911 "Replaces /home/user with ~."
4912 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
4913 (getenv "HOME"))))
4914 (mapcar (lambda (file)
4915 (if (and (stringp file) (string-match home file))
4916 (cons (replace-match "~" nil nil file) file)
4917 file))
4918 files)))
4920 ;;; Functions
4921 (defun anything-c-mark-interactive-functions (functions)
4922 "Mark interactive functions (commands) with (i) after the function name."
4923 (let (list)
4924 (loop for function in functions
4925 do (push (cons (concat function
4926 (when (commandp (intern-soft function)) " (i)"))
4927 function)
4928 list)
4929 finally (return (nreverse list)))))
4931 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4932 (defvar anything-c-adaptive-done nil
4933 "nil if history information is not yet stored for the current
4934 selection.")
4936 (defvar anything-c-adaptive-history nil
4937 "Contains the stored history information.
4938 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
4940 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
4941 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
4942 when anything is started."
4943 (setq anything-c-adaptive-done nil))
4945 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
4946 "Advise `anything-exit-minibuffer' to store history information
4947 when a candidate is selected with RET."
4948 (anything-c-adaptive-store-selection))
4950 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
4951 "Advise `anything-select-action' to store history information
4952 when the user goes to the action list with TAB."
4953 (anything-c-adaptive-store-selection))
4955 (defun anything-c-source-use-adaptative-p (&optional source-name)
4956 "Return current source only if it use adaptative history, nil otherwise."
4957 (let* ((source (or source-name (anything-get-current-source)))
4958 (adapt-source (or (assoc-default 'filtered-candidate-transformer
4959 (assoc (assoc-default 'type source)
4960 anything-type-attributes))
4961 (assoc-default 'candidate-transformer
4962 (assoc (assoc-default 'type source)
4963 anything-type-attributes))
4964 (assoc-default 'filtered-candidate-transformer source)
4965 (assoc-default 'candidate-transformer source))))
4966 (if (listp adapt-source)
4967 (when (member 'anything-c-adaptive-sort adapt-source) source)
4968 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
4970 (defun anything-c-adaptive-store-selection ()
4971 "Store history information for the selected candidate."
4972 (unless anything-c-adaptive-done
4973 (setq anything-c-adaptive-done t)
4974 (let ((source (anything-c-source-use-adaptative-p)))
4975 (when source
4976 (let* ((source-name (or (assoc-default 'type source)
4977 (assoc-default 'name source)))
4978 (source-info (or (assoc source-name anything-c-adaptive-history)
4979 (progn
4980 (push (list source-name) anything-c-adaptive-history)
4981 (car anything-c-adaptive-history))))
4982 (selection (anything-get-selection))
4983 (selection-info (progn
4984 (setcdr source-info
4985 (cons
4986 (let ((found (assoc selection (cdr source-info))))
4987 (if (not found)
4988 ;; new entry
4989 (list selection)
4991 ;; move entry to the beginning of the
4992 ;; list, so that it doesn't get
4993 ;; trimmed when the history is
4994 ;; truncated
4995 (setcdr source-info
4996 (delete found (cdr source-info)))
4997 found))
4998 (cdr source-info)))
4999 (cadr source-info)))
5000 (pattern-info (progn
5001 (setcdr selection-info
5002 (cons
5003 (let ((found (assoc anything-pattern (cdr selection-info))))
5004 (if (not found)
5005 ;; new entry
5006 (cons anything-pattern 0)
5008 ;; move entry to the beginning of the
5009 ;; list, so if two patterns used the
5010 ;; same number of times then the one
5011 ;; used last appears first in the list
5012 (setcdr selection-info
5013 (delete found (cdr selection-info)))
5014 found))
5015 (cdr selection-info)))
5016 (cadr selection-info))))
5018 ;; increase usage count
5019 (setcdr pattern-info (1+ (cdr pattern-info)))
5021 ;; truncate history if needed
5022 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
5023 (setcdr selection-info
5024 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
5026 (if (file-readable-p anything-c-adaptive-history-file)
5027 (load-file anything-c-adaptive-history-file))
5028 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
5030 (defun anything-c-adaptive-save-history ()
5031 "Save history information to file given by `anything-c-adaptive-history-file'."
5032 (interactive)
5033 (with-temp-buffer
5034 (insert
5035 ";; -*- mode: emacs-lisp -*-\n"
5036 ";; History entries used for anything adaptive display.\n")
5037 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
5038 (current-buffer))
5039 (insert ?\n)
5040 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
5041 (unless (interactive-p) 'quiet))))
5043 (defun anything-c-adaptive-sort (candidates source)
5044 "Sort the CANDIDATES for SOURCE by usage frequency.
5045 This is a filtered candidate transformer you can use for the
5046 attribute `filtered-candidate-transformer' of a source in
5047 `anything-sources' or a type in `anything-type-attributes'."
5048 (let* ((source-name (or (assoc-default 'type source)
5049 (assoc-default 'name source)))
5050 (source-info (assoc source-name anything-c-adaptive-history)))
5051 (if (not source-info)
5052 ;; if there is no information stored for this source then do nothing
5053 candidates
5054 ;; else...
5055 (let ((usage
5056 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
5057 ;; pairs
5058 (mapcar (lambda (candidate-info)
5059 (let ((count 0))
5060 (dolist (pattern-info (cdr candidate-info))
5061 (if (not (equal (car pattern-info)
5062 anything-pattern))
5063 (incf count (cdr pattern-info))
5065 ;; if current pattern is equal to the previously
5066 ;; used one then this candidate has priority
5067 ;; (that's why its count is boosted by 10000) and
5068 ;; it only has to compete with other candidates
5069 ;; which were also selected with the same pattern
5070 (setq count (+ 10000 (cdr pattern-info)))
5071 (return)))
5072 (cons (car candidate-info) count)))
5073 (cdr source-info)))
5074 sorted)
5076 ;; sort the list in descending order, so candidates with highest
5077 ;; priorty come first
5078 (setq usage (sort usage (lambda (first second)
5079 (> (cdr first) (cdr second)))))
5081 ;; put those candidates first which have the highest usage count
5082 (dolist (info usage)
5083 (when (member* (car info) candidates
5084 :test 'anything-c-adaptive-compare)
5085 (push (car info) sorted)
5086 (setq candidates (remove* (car info) candidates
5087 :test 'anything-c-adaptive-compare))))
5089 ;; and append the rest
5090 (append (reverse sorted) candidates nil)))))
5092 (defun anything-c-adaptive-compare (x y)
5093 "Compare candidates X and Y taking into account that the
5094 candidate can be in (DISPLAY . REAL) format."
5095 (equal (if (listp x)
5096 (cdr x)
5098 (if (listp y)
5099 (cdr y)
5100 y)))
5102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5103 ;; Plug-in: candidates-file
5104 (defun anything-compile-source--candidates-file (source)
5105 (if (assoc-default 'candidates-file source)
5106 `((init anything-p-candidats-file-init
5107 ,@(let ((orig-init (assoc-default 'init source)))
5108 (cond ((null orig-init) nil)
5109 ((functionp orig-init) (list orig-init))
5110 (t orig-init))))
5111 (candidates-in-buffer)
5112 ,@source)
5113 source))
5114 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
5116 (defun anything-p-candidats-file-init ()
5117 (destructuring-bind (file &optional updating)
5118 (anything-mklist (anything-attr 'candidates-file))
5119 (setq file (anything-interpret-value file))
5120 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
5121 (when updating
5122 (buffer-disable-undo)
5123 (font-lock-mode -1)
5124 (auto-revert-mode 1)))))
5126 (anything-document-attribute 'candidates-file "candidates-file plugin"
5127 "Use a file as the candidates buffer.
5129 1st argument is a filename, string or function name or variable name.
5130 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
5132 ;; Plug-in: headline
5133 (defun anything-compile-source--anything-headline (source)
5134 (if (assoc-default 'headline source)
5135 (append '((init . anything-headline-init)
5136 (get-line-fn . buffer-substring)
5137 (type . line))
5138 source
5139 '((candidates-in-buffer)
5140 (persistent-help . "Show this line")))
5141 source))
5142 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
5144 (defun anything-headline-init ()
5145 (when (and (anything-current-buffer-is-modified)
5146 (with-current-buffer anything-current-buffer
5147 (eval (or (anything-attr 'condition) t))))
5148 (anything-headline-make-candidate-buffer
5149 (anything-attr 'headline)
5150 (anything-attr 'subexp))))
5152 (anything-document-attribute 'headline "Headline plug-in"
5153 "Regexp string for anything-headline to scan.")
5154 (anything-document-attribute 'condition "Headline plug-in"
5155 "A sexp representing the condition to use anything-headline.")
5156 (anything-document-attribute 'subexp "Headline plug-in"
5157 "Display (match-string-no-properties subexp).")
5160 (defun anything-headline-get-candidates (regexp subexp)
5161 (with-current-buffer anything-current-buffer
5162 (save-excursion
5163 (goto-char (point-min))
5164 (if (functionp regexp) (setq regexp (funcall regexp)))
5165 (let (hierarchy curhead)
5166 (flet ((matched ()
5167 (if (numberp subexp)
5168 (cons (match-string-no-properties subexp) (match-beginning subexp))
5169 (cons (buffer-substring (point-at-bol) (point-at-eol))
5170 (point-at-bol))))
5171 (hierarchies (headlines)
5172 (1+ (loop for (_ . hierarchy) in headlines
5173 maximize hierarchy)))
5174 (vector-0-n (v n)
5175 (loop for i from 0 to hierarchy
5176 collecting (aref curhead i)))
5177 (arrange (headlines)
5178 (loop with curhead = (make-vector (hierarchies headlines) "")
5179 for ((str . pt) . hierarchy) in headlines
5180 do (aset curhead hierarchy str)
5181 collecting
5182 (cons
5183 (mapconcat 'identity (vector-0-n curhead hierarchy) " / ")
5184 pt))))
5185 (if (listp regexp)
5186 (arrange
5187 (sort
5188 (loop for re in regexp
5189 for hierarchy from 0
5190 do (goto-char (point-min))
5191 appending
5192 (loop
5193 while (re-search-forward re nil t)
5194 collect (cons (matched) hierarchy)))
5195 (lambda (a b) (> (cdar b) (cdar a)))))
5196 (loop while (re-search-forward regexp nil t)
5197 collect (matched))))))))
5200 (defun anything-headline-make-candidate-buffer (regexp subexp)
5201 (with-current-buffer (anything-candidate-buffer 'local)
5202 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
5203 do (insert
5204 (format "%5d:%s\n"
5205 (with-current-buffer anything-current-buffer
5206 (line-number-at-pos pos))
5207 content)))))
5209 (defun anything-headline-goto-position (pos recenter)
5210 (goto-char pos)
5211 (unless recenter
5212 (set-window-start (get-buffer-window anything-current-buffer) (point))))
5214 (defun anything-revert-buffer (candidate)
5215 (with-current-buffer candidate
5216 (when (buffer-modified-p)
5217 (revert-buffer t t))))
5219 (defun anything-revert-marked-buffers (candidate)
5220 (dolist (i (anything-marked-candidates))
5221 (anything-revert-buffer i)))
5223 (defun anything-kill-marked-buffers (candidate)
5224 (dolist (i (anything-marked-candidates))
5225 (kill-buffer i)))
5227 ;; Plug-in: persistent-help
5228 (defun anything-compile-source--persistent-help (source)
5229 (append source '((header-line . anything-persistent-help-string))))
5230 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
5232 (defun anything-persistent-help-string ()
5233 (substitute-command-keys
5234 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
5235 (or (anything-attr 'persistent-help)
5236 (anything-aif (or (assoc-default 'persistent-action (anything-get-current-source))
5237 (assoc-default 'action (anything-get-current-source))
5239 (cond ((symbolp it) (symbol-name it))
5240 ((listp it) (or (ignore-errors (caar it)) ""))))
5242 " (keeping session)")))
5244 (anything-document-attribute 'persistent-help "persistent-help plug-in"
5245 "A string to explain persistent-action of this source.
5246 It also accepts a function or a variable name.")
5248 ;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
5250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5252 (defun anything-delete-marked-files (candidate)
5253 (anything-aif (anything-marked-candidates)
5254 (if (y-or-n-p (format "Delete *%s Files " (length it)))
5255 (progn
5256 (dolist (i it)
5257 (set-text-properties 0 (length i) nil i)
5258 (anything-c-delete-file i))
5259 (message "%s Files deleted" (length it)))
5260 (message "(No deletions performed)"))
5261 (set-text-properties 0 (length candidate) nil candidate)
5262 (if (y-or-n-p (format "Really delete file `%s' " candidate))
5263 (progn
5264 (anything-c-delete-file candidate)
5265 (message "1 file deleted"))
5266 (message "(No deletions performed)"))))
5268 (defun anything-ediff-marked-buffers (candidate &optional merge)
5269 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
5270 With optional arg `merge' call `ediff-merge-buffers'."
5271 (let ((lg-lst (length (anything-marked-candidates)))
5272 buf1 buf2)
5273 (case lg-lst
5275 (error "Error:You have to mark at least 1 buffer"))
5277 (setq buf1 anything-current-buffer
5278 buf2 (first (anything-marked-candidates))))
5280 (setq buf1 (first (anything-marked-candidates))
5281 buf2 (second (anything-marked-candidates))))
5283 (error "Error:To much buffers marked!")))
5284 (if merge
5285 (ediff-merge-buffers buf1 buf2)
5286 (ediff-buffers buf1 buf2))))
5288 (defun anything-bookmark-get-bookmark-from-name (bmk)
5289 "Return bookmark name even if it is a bookmark with annotation.
5290 e.g prepended with *.
5291 Return nil if bmk is not a valid bookmark."
5292 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
5293 (if (assoc bookmark bookmark-alist)
5294 bookmark
5295 (when (assoc bmk bookmark-alist)
5296 bmk))))
5298 (defun anything-delete-marked-bookmarks (elm)
5299 "Delete this bookmark or all marked bookmarks."
5300 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
5301 (anything-aif (anything-marked-candidates)
5302 (dolist (i it)
5303 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
5304 (bookmark-delete bmk 'batch)))
5305 (bookmark-delete bookmark 'batch))))
5307 (defun anything-bookmark-active-region-maybe (candidate)
5308 "Active saved region if this bookmark have one."
5309 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5310 (condition-case nil
5311 (when (and (boundp bmkext-use-region-flag)
5312 bmkext-use-region-flag)
5313 (let ((bmk-name (or (bmkext-get-buffer-name bookmark)
5314 (file-name-nondirectory
5315 (bookmark-get-filename bookmark)))))
5316 (when bmk-name
5317 (with-current-buffer bmk-name
5318 (setq deactivate-mark nil)))))
5319 (error nil))))
5321 (defun anything-require-or-error (feature function)
5322 (or (require feature nil t)
5323 (error "Need %s to use `%s'." feature function)))
5325 (defun anything-find-buffer-on-elscreen (candidate)
5326 "Open buffer in new screen, if marked buffers open all in elscreens."
5327 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
5328 (anything-aif (anything-marked-candidates)
5329 (dolist (i it)
5330 (let ((target-screen (elscreen-find-screen-by-buffer
5331 (get-buffer i) 'create)))
5332 (elscreen-goto target-screen)))
5333 (let ((target-screen (elscreen-find-screen-by-buffer
5334 (get-buffer candidate) 'create)))
5335 (elscreen-goto target-screen))))
5337 (defun anything-elscreen-find-file (file)
5338 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
5339 (elscreen-find-file file))
5341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5343 ;;; Type Attributes
5344 (define-anything-type-attribute 'buffer
5345 `((action
5346 ,@(if pop-up-frames
5347 '(("Switch to buffer other window" . switch-to-buffer-other-window)
5348 ("Switch to buffer" . switch-to-buffer))
5349 '(("Switch to buffer" . switch-to-buffer)
5350 ("Switch to buffer other window" . switch-to-buffer-other-window)
5351 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
5352 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
5353 ("Display buffer" . display-buffer)
5354 ("Revert buffer" . anything-revert-buffer)
5355 ("Revert Marked buffers" . anything-revert-marked-buffers)
5356 ("Kill buffer" . kill-buffer)
5357 ("Kill Marked buffers" . anything-kill-marked-buffers)
5358 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
5359 ("Ediff Merge marked buffers" . (lambda (candidate)
5360 (anything-ediff-marked-buffers candidate t))))
5361 (persistent-help . "Show this buffer")
5362 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
5363 "Buffer or buffer name.")
5365 (define-anything-type-attribute 'file
5366 `((action
5367 ,@(if pop-up-frames
5368 '(("Find file other window" . find-file-other-window)
5369 ("Find file" . find-file)
5370 ("Find file as root" . anything-find-file-as-root))
5371 '(("Find file" . find-file)
5372 ("Find file as root" . anything-find-file-as-root)
5373 ("Find file other window" . find-file-other-window)
5374 ("Find file other frame" . find-file-other-frame)))
5375 ("Open dired in file's directory" . anything-c-open-dired)
5376 ("Delete file(s)" . anything-delete-marked-files)
5377 ("Open file externally" . anything-c-open-file-externally)
5378 ("Open file with default tool" . anything-c-open-file-with-default-tool))
5379 (persistent-help . "Show this file")
5380 (action-transformer anything-c-transform-file-load-el
5381 anything-c-transform-file-browse-url)
5382 (candidate-transformer anything-c-w32-pathname-transformer
5383 anything-c-skip-current-file
5384 anything-c-skip-boring-files
5385 anything-c-shorten-home-path))
5386 "File name.")
5388 (define-anything-type-attribute 'command
5389 `((action ("Call interactively" . anything-c-call-interactively)
5390 ("Describe command" . anything-c-describe-function)
5391 ("Add command to kill ring" . anything-c-kill-new)
5392 ("Go to command's definition" . anything-c-find-function))
5393 ;; Sort commands according to their usage count.
5394 (filtered-candidate-transformer . anything-c-adaptive-sort))
5395 "Command. (string or symbol)")
5397 (define-anything-type-attribute 'function
5398 '((action ("Describe function" . anything-c-describe-function)
5399 ("Add function to kill ring" . anything-c-kill-new)
5400 ("Go to function's definition" . anything-c-find-function))
5401 (action-transformer anything-c-transform-function-call-interactively)
5402 (candidate-transformer anything-c-mark-interactive-functions))
5403 "Function. (string or symbol)")
5405 (define-anything-type-attribute 'variable
5406 '((action ("Describe variable" . anything-c-describe-variable)
5407 ("Add variable to kill ring" . anything-c-kill-new)
5408 ("Go to variable's definition" . anything-c-find-variable)
5409 ("Set variable" . anything-c-set-variable)))
5410 "Variable.")
5412 (define-anything-type-attribute 'sexp
5413 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
5414 ("Add s-expression to kill ring" . kill-new))
5415 (action-transformer anything-c-transform-sexp-eval-command-sexp))
5416 "String representing S-Expressions.")
5418 (define-anything-type-attribute 'bookmark
5419 `((action
5420 ("Jump to bookmark" . (lambda (candidate)
5421 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate))
5422 (current-prefix-arg anything-current-prefix-arg))
5423 (bookmark-jump bookmark))
5424 (anything-update)
5425 (anything-bookmark-active-region-maybe candidate)))
5426 ("Jump to BM other window" . (lambda (candidate)
5427 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5428 (bookmark-jump-other-window bookmark))
5429 (anything-update)
5430 (anything-bookmark-active-region-maybe candidate)))
5431 ("Bookmark edit annotation" . (lambda (candidate)
5432 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5433 (bookmark-edit-annotation bookmark))))
5434 ("Bookmark show annotation" . (lambda (candidate)
5435 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5436 (bookmark-show-annotation bookmark))))
5437 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
5438 ,@(when (fboundp 'bmkext-edit-bookmark)
5439 '(("Edit Bookmark" . (lambda (candidate)
5440 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5441 (bmkext-edit-bookmark bookmark))))))
5442 ("Rename bookmark" . (lambda (candidate)
5443 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5444 (bookmark-rename bookmark))))
5445 ("Relocate bookmark" . (lambda (candidate)
5446 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5447 (bookmark-relocate bookmark))))))
5448 "Bookmark name.")
5450 (define-anything-type-attribute 'line
5451 '((display-to-real . anything-c-display-to-real-line)
5452 (action ("Go to Line" . anything-c-action-line-goto)))
5453 "LINENO:CONTENT string, eg. \" 16:foo\".
5455 Optional `target-file' attribute is a name of target file.
5457 Optional `before-jump-hook' attribute is a function with no
5458 arguments which is called before jumping to position.
5460 Optional `after-jump-hook' attribute is a function with no
5461 arguments which is called after jumping to position.
5463 If `adjust' attribute is specified, searches the line whose
5464 content is CONTENT near the LINENO.
5466 If `recenter' attribute is specified, the line is displayed at
5467 the center of window, otherwise at the top of window.
5470 (define-anything-type-attribute 'file-line
5471 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
5472 (multiline)
5473 (action ("Go to" . anything-c-action-file-line-goto)))
5474 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
5476 Optional `default-directory' attribute is a default-directory
5477 FILENAME is interpreted.
5479 Optional `before-jump-hook' attribute is a function with no
5480 arguments which is called before jumping to position.
5482 Optional `after-jump-hook' attribute is a function with no
5483 arguments which is called after jumping to position.
5485 If `adjust' attribute is specified, searches the line whose
5486 content is CONTENT near the LINENO.
5488 If `recenter' attribute is specified, the line is displayed at
5489 the center of window, otherwise at the top of window.
5492 (define-anything-type-attribute 'timer
5493 '((real-to-display . anything-c-timer-real-to-display)
5494 (action ("Cancel Timer" . cancel-timer)))
5495 "Timer.")
5497 ;;;; unit test
5498 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
5499 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
5500 (dont-compile
5501 (when (fboundp 'expectations)
5502 (expectations
5503 (desc "candidates-file plug-in")
5504 (expect '(anything-p-candidats-file-init)
5505 (assoc-default 'init
5506 (car (anything-compile-sources
5507 '(((name . "test")
5508 (candidates-file . "test.txt")))
5509 '(anything-compile-source--candidates-file)))))
5510 (expect '(anything-p-candidats-file-init
5511 (lambda () 1))
5512 (assoc-default 'init
5513 (car (anything-compile-sources
5514 '(((name . "test")
5515 (candidates-file . "test.txt")
5516 (init . (lambda () 1))))
5517 '(anything-compile-source--candidates-file)))))
5518 (expect '(anything-p-candidats-file-init
5519 (lambda () 1))
5520 (assoc-default 'init
5521 (car (anything-compile-sources
5522 '(((name . "test")
5523 (candidates-file . "test.txt")
5524 (init (lambda () 1))))
5525 '(anything-compile-source--candidates-file)))))
5526 (desc "anything-c-source-buffers")
5527 (expect '(("Buffers" ("foo" "curbuf")))
5528 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
5529 (let ((anything-c-boring-buffer-regexp
5530 (rx (or
5531 (group bos " ")
5532 "*anything"
5533 ;; echo area
5534 " *Echo Area" " *Minibuf"))))
5535 (flet ((buffer-name (x) x))
5536 (anything-test-candidates 'anything-c-source-buffers))))
5537 (desc "anything-c-stringify")
5538 (expect "str1"
5539 (anything-c-stringify "str1"))
5540 (expect "str2"
5541 (anything-c-stringify 'str2))
5542 (desc "anything-c-symbolify")
5543 (expect 'sym1
5544 (anything-c-symbolify "sym1"))
5545 (expect 'sym2
5546 (anything-c-symbolify 'sym2)))))
5549 (provide 'anything-config)
5551 ;;; Local Variables:
5552 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
5553 ;;; End:
5555 ;; How to save (DO NOT REMOVE!!)
5556 ;; (emacswiki-post "anything-config.el")
5557 ;;; anything-config.el ends here
5559 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
5560 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
5561 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
5562 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
5563 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
5564 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
5565 ;;; LocalWords: dotimes Thierry online vname
5566 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
5567 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
5568 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
5569 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
5570 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
5571 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
5572 ;;; LocalWords: startpos noselect dont desc