remove unneeded anything-multi-sources-version line
[anything-config.git] / anything-config.el
blobb68e6fd9cc48c40a9371c505932ed9d01fa069fb
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-occur'
192 ;; Preconfigured Anything for Occur source.
193 ;; `anything-create-from-anything'
194 ;; Run `anything-create' from `anything' as a fallback.
195 ;; `anything-create'
196 ;; Preconfigured `anything' to do many create actions from STRING.
197 ;; `anything-top'
198 ;; Preconfigured `anything' for top command.
199 ;; `anything-select-xfont'
200 ;; Preconfigured `anything' to select Xfont.
201 ;; `anything-apt'
202 ;; Preconfigured `anything' : frontend of APT package manager.
203 ;; `anything-c-set-variable'
204 ;; Set value to VAR interactively.
205 ;; `anything-c-adaptive-save-history'
206 ;; Save history information to file given by `anything-c-adaptive-history-file'.
208 ;;; Customizable Options:
210 ;; Below are customizable option list:
212 ;; `anything-c-use-standard-keys'
213 ;; Whether use standard keybindings. (no effect)
214 ;; default = nil
215 ;; `anything-c-adaptive-history-file'
216 ;; Path of file where history information is stored.
217 ;; default = "~/.emacs.d/anything-c-adaptive-history"
218 ;; `anything-c-adaptive-history-length'
219 ;; Maximum number of candidates stored for a source.
220 ;; default = 50
221 ;; `anything-c-google-suggest-url'
222 ;; URL used for looking up Google suggestions.
223 ;; default = "http://google.com/complete/search?output=toolbar&q="
224 ;; `anything-c-google-suggest-search-url'
225 ;; URL used for Google searching.
226 ;; default = "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
227 ;; `anything-google-suggest-use-curl-p'
228 ;; *When non--nil use CURL to get info from `anything-c-google-suggest-url'.
229 ;; default = nil
230 ;; `anything-c-yahoo-suggest-url'
231 ;; Url used for looking up Yahoo suggestions.
232 ;; default = "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
233 ;; `anything-c-yahoo-suggest-search-url'
234 ;; Url used for Yahoo searching.
235 ;; default = "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
236 ;; `anything-c-boring-buffer-regexp'
237 ;; The regexp that match boring buffers.
238 ;; default = (rx (or (group bos " ") "*anything" " *Echo Area" " *Minibuf"))
239 ;; `anything-c-boring-file-regexp'
240 ;; The regexp that match boring files.
241 ;; default = (rx (or (and "/" ... ...) (and line-start ".#") (and ... eol)))
242 ;; `anything-kill-ring-threshold'
243 ;; *Minimum length to be listed by `anything-c-source-kill-ring'.
244 ;; default = 10
245 ;; `anything-su-or-sudo'
246 ;; What command to use for root access.
247 ;; default = "su"
248 ;; `anything-for-files-prefered-list'
249 ;; Your prefered sources to find files.
250 ;; default = (quote (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-source-buffers+ anything-c-source-recentf anything-c-source-bookmarks ...))
251 ;; `anything-create--actions-private'
252 ;; User defined actions for `anything-create' / `anything-c-source-create'.
253 ;; default = nil
254 ;; `anything-allow-skipping-current-buffer'
255 ;; Show current buffer or not in anything buffer
256 ;; default = t
257 ;; `anything-c-enable-eval-defun-hack'
258 ;; *If non-nil, execute `anything' using the source at point when C-M-x is pressed.
259 ;; default = t
260 ;; `anything-tramp-verbose'
261 ;; *Just like `tramp-verbose' but specific to anything.
262 ;; default = 0
265 ;; Anything sources can be tested by M-x `anything-call-source'.
266 ;; Below are complete source list you can setup in the first argument
268 ;; Buffer:
269 ;; `anything-c-source-buffers' (Buffers)
270 ;; `anything-c-source-buffer-not-found' (Create buffer)
271 ;; `anything-c-source-buffers+' (Buffers)
272 ;; File:
273 ;; `anything-c-source-file-name-history' (File Name History)
274 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
275 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
276 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
277 ;; `anything-c-source-file-cache' (File Cache)
278 ;; `anything-c-source-locate' (Locate)
279 ;; `anything-c-source-recentf' (Recentf)
280 ;; `anything-c-source-ffap-guesser' (File at point)
281 ;; `anything-c-source-ffap-line' (File/Lineno at point)
282 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
283 ;; info:
284 ;; `anything-c-source-info-pages' (Info Pages)
285 ;; `anything-c-source-info-elisp' (Info index: elisp)
286 ;; `anything-c-source-info-cl' (Info index: cl)
287 ;; `anything-c-source-info-org' (Info index: org)
288 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
289 ;; `anything-c-source-info-zsh' (Info index: zsh)
290 ;; `anything-c-source-info-bash' (Info index: bash)
291 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
292 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
293 ;; `anything-c-source-info-find' (Info index: find)
294 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
295 ;; `anything-c-source-info-textutils' (Info index: textutils)
296 ;; `anything-c-source-info-libc' (Info index: libc)
297 ;; `anything-c-source-info-make' (Info index: make)
298 ;; `anything-c-source-info-automake' (Info index: automake)
299 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
300 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
301 ;; `anything-c-source-info-emacs' (Info index: emacs)
302 ;; `anything-c-source-info-elib' (Info index: elib)
303 ;; `anything-c-source-info-eieio' (Info index: eieio)
304 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
305 ;; `anything-c-source-info-guile' (Info index: guile)
306 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
307 ;; `anything-c-source-info-goops' (Info index: goops)
308 ;; `anything-c-source-info-screen' (Info index: screen)
309 ;; `anything-c-source-info-latex' (Info index: latex)
310 ;; `anything-c-source-info-gawk' (Info index: gawk)
311 ;; `anything-c-source-info-sed' (Info index: sed)
312 ;; `anything-c-source-info-m4' (Info index: m4)
313 ;; `anything-c-source-info-wget' (Info index: wget)
314 ;; `anything-c-source-info-binutils' (Info index: binutils)
315 ;; `anything-c-source-info-as' (Info index: as)
316 ;; `anything-c-source-info-bfd' (Info index: bfd)
317 ;; `anything-c-source-info-gprof' (Info index: gprof)
318 ;; `anything-c-source-info-ld' (Info index: ld)
319 ;; `anything-c-source-info-diff' (Info index: diff)
320 ;; `anything-c-source-info-flex' (Info index: flex)
321 ;; `anything-c-source-info-grep' (Info index: grep)
322 ;; `anything-c-source-info-gzip' (Info index: gzip)
323 ;; `anything-c-source-info-libtool' (Info index: libtool)
324 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
325 ;; `anything-c-source-info-info' (Info index: info)
326 ;; `anything-c-source-info-gdb' (Info index: gdb)
327 ;; `anything-c-source-info-stabs' (Info index: stabs)
328 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
329 ;; `anything-c-source-info-cvs' (Info index: cvs)
330 ;; `anything-c-source-info-bison' (Info index: bison)
331 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
332 ;; `anything-c-source-info-global' (Info index: global)
333 ;; Help:
334 ;; `anything-c-source-man-pages' (Manual Pages)
335 ;; Command:
336 ;; `anything-c-source-complex-command-history' (Complex Command History)
337 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
338 ;; `anything-c-source-emacs-commands' (Emacs Commands)
339 ;; `anything-c-source-lacarte' (Lacarte)
340 ;; Function:
341 ;; `anything-c-source-emacs-functions' (Emacs Functions)
342 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
343 ;; Variable:
344 ;; `anything-c-source-emacs-variables' (Emacs Variables)
345 ;; Bookmark:
346 ;; `anything-c-source-bookmarks' (Bookmarks)
347 ;; `anything-c-source-bookmark-set' (Set Bookmark)
348 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
349 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
350 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
351 ;; `anything-c-source-bookmark-regions' (Bookmark Regions)
352 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
353 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
354 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
355 ;; `anything-c-source-bookmark-info' (Bookmark Info)
356 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
357 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
358 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
359 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
360 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
361 ;; Library:
362 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
363 ;; Programming:
364 ;; `anything-c-source-imenu' (Imenu)
365 ;; `anything-c-source-ctags' (Exuberant ctags)
366 ;; `anything-c-source-semantic' (Semantic Tags)
367 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
368 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
369 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
370 ;; Color and Face:
371 ;; `anything-c-source-customize-face' (Customize Face)
372 ;; `anything-c-source-colors' (Colors)
373 ;; Search Engine:
374 ;; `anything-c-source-tracker-search' (Tracker Search)
375 ;; `anything-c-source-mac-spotlight' (mdfind)
376 ;; Kill ring:
377 ;; `anything-c-source-kill-ring' (Kill Ring)
378 ;; Mark ring:
379 ;; `anything-c-source-mark-ring' (mark-ring)
380 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
381 ;; Register:
382 ;; `anything-c-source-register' (Registers)
383 ;; Headline Extraction:
384 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
385 ;; `anything-c-source-rd-headline' (RD HeadLine)
386 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
387 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
388 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
389 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
390 ;; `anything-c-source-org-headline' (Org HeadLine)
391 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
392 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
393 ;; `anything-c-source-eev-anchor' (Anchors)
394 ;; Misc:
395 ;; `anything-c-source-org-keywords' (Org Keywords)
396 ;; `anything-c-source-picklist' (Picklist)
397 ;; `anything-c-source-bbdb' (BBDB)
398 ;; `anything-c-source-evaluation-result' (Evaluation Result)
399 ;; `anything-c-source-calculation-result' (Calculation Result)
400 ;; `anything-c-source-google-suggest' (Google Suggest)
401 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
402 ;; `anything-c-source-surfraw' (Surfraw)
403 ;; `anything-c-source-emms-streams' (Emms Streams)
404 ;; `anything-c-source-emms-dired' (Music Directory)
405 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
406 ;; `anything-c-source-call-source' (Call anything source)
407 ;; `anything-c-source-occur' (Occur)
408 ;; `anything-c-source-create' (Create)
409 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
410 ;; `anything-c-source-elscreen' (Elscreen)
411 ;; System:
412 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
413 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
414 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
415 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
416 ;; `anything-c-source-xfonts' (X Fonts)
417 ;; `anything-c-source-apt' (APT)
418 ;; `anything-c-source-gentoo' (Portage sources)
419 ;; `anything-c-source-use-flags' (Use Flags)
420 ;; `anything-c-source-emacs-process' (Emacs Process)
422 ;;; Change log:
424 ;; Change log of this file is found at
425 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
427 ;;; Contributors:
429 ;; Tamas Patrovics
430 ;; Tassilo Horn <tassilo@member.fsf.org>
431 ;; Vagn Johansen <gonz808@hotmail.com>
432 ;; Mathias Dahl <mathias.dahl@gmail.com>
433 ;; Bill Clementson <billclem@gmail.com>
434 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
435 ;; Drew Adams <drew.adams@oracle.com>
436 ;; Jason McBrayer <jmcbray@carcosa.net>
437 ;; Andy Stewart <lazycat.manatee@gmail.com>
438 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
439 ;; rubikitch <rubikitch@ruby-lang.org>
440 ;; Scott Vokes <vokes.s@gmail.com>
443 ;;; For Maintainers:
445 ;; Evaluate (anything-c-insert-summary) before commit. This function
446 ;; generates anything-c-source-* list.
448 ;; Install also http://www.emacswiki.org/emacs/auto-document.el
449 ;; And eval it or run interactively.
451 ;; [EVAL IT] (anything-c-insert-summary)
452 ;; [EVAL IT] (auto-document)
454 ;; Please write details documentation about function, then others will
455 ;; read code more easier. -- Andy Stewart
459 ;;; TODO
461 ;; - Fix documentation, now many functions haven't documentations.
464 ;;; Require
465 (require 'anything)
466 (require 'thingatpt)
467 (require 'ffap)
468 (require 'cl)
470 ;;; Code:
472 ;; version check
473 (let ((version "1.263"))
474 (when (and (string= "1." (substring version 0 2))
475 (string-match "1\.\\([0-9]+\\)" anything-version)
476 (< (string-to-number (match-string 1 anything-version))
477 (string-to-number (substring version 2))))
478 (error "Please update anything.el!!
480 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
482 or M-x install-elisp-from-emacswiki anything.el")))
484 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
485 (defgroup anything-config nil
486 "Predefined configurations for `anything.el'."
487 :group 'anything)
489 (defcustom anything-c-use-standard-keys nil
490 "Whether use standard keybindings. (no effect)
492 Key definitions in anything-config.el are removed because
493 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
494 minibuffer history, C-s for isearch, etc.
496 If you use `iswitchb' with `anything',
497 evaluate (anything-iswitchb-setup) . Then some bindings that
498 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
499 history, are removed from `anything-map'. "
500 :type 'boolean
501 :group 'anything-config)
503 (defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
504 "Path of file where history information is stored."
505 :type 'string
506 :group 'anything-config)
508 (defcustom anything-c-adaptive-history-length 50
509 "Maximum number of candidates stored for a source."
510 :type 'number
511 :group 'anything-config)
513 (defcustom anything-c-google-suggest-url
514 "http://google.com/complete/search?output=toolbar&q="
515 "URL used for looking up Google suggestions."
516 :type 'string
517 :group 'anything-config)
519 (defcustom anything-c-google-suggest-search-url
520 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
521 "URL used for Google searching."
522 :type 'string
523 :group 'anything-config)
525 (defcustom anything-google-suggest-use-curl-p nil
526 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
527 Otherwise `url-retrieve-synchronously' is used."
528 :type 'boolean
529 :group 'anything-config)
531 (defcustom anything-c-yahoo-suggest-url
532 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
533 "Url used for looking up Yahoo suggestions."
534 :type 'string
535 :group 'anything-config)
537 (defcustom anything-c-yahoo-suggest-search-url
538 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
539 "Url used for Yahoo searching."
540 :type 'string
541 :group 'anything-config)
543 (defcustom anything-c-boring-buffer-regexp
544 (rx (or
545 (group bos " ")
546 ;; anything-buffer
547 "*anything"
548 ;; echo area
549 " *Echo Area" " *Minibuf"))
550 "The regexp that match boring buffers.
551 Buffer candidates matching this regular expression will be
552 filtered from the list of candidates if the
553 `anything-c-skip-boring-buffers' candidate transformer is used, or
554 they will be displayed with face `file-name-shadow' if
555 `anything-c-shadow-boring-buffers' is used."
556 :type 'string
557 :group 'anything-config)
558 ;; (string-match anything-c-boring-buffer-regexp "buf")
559 ;; (string-match anything-c-boring-buffer-regexp " hidden")
560 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
562 (defcustom anything-c-boring-file-regexp
563 (rx (or
564 ;; Boring directories
565 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
566 ;; Boring files
567 (and line-start ".#")
568 (and (or ".class" ".la" ".o" "~") eol)))
569 "The regexp that match boring files.
570 File candidates matching this regular expression will be
571 filtered from the list of candidates if the
572 `anything-c-skip-boring-files' candidate transformer is used, or
573 they will be displayed with face `file-name-shadow' if
574 `anything-c-shadow-boring-files' is used."
575 :type 'string
576 :group 'anything-config)
578 (defcustom anything-kill-ring-threshold 10
579 "*Minimum length to be listed by `anything-c-source-kill-ring'."
580 :type 'integer
581 :group 'anything-config)
583 (defcustom anything-su-or-sudo "su"
584 "What command to use for root access."
585 :type 'string
586 :group 'anything-config)
588 (defcustom anything-for-files-prefered-list '(anything-c-source-ffap-line
589 anything-c-source-ffap-guesser
590 anything-c-source-buffers+
591 anything-c-source-recentf
592 anything-c-source-bookmarks
593 anything-c-source-file-cache
594 anything-c-source-files-in-current-dir+
595 anything-c-source-locate)
596 "Your prefered sources to find files."
597 :type 'list
598 :group 'anything-config)
600 (defcustom anything-create--actions-private nil
601 "User defined actions for `anything-create' / `anything-c-source-create'.
602 It is a list of (DISPLAY . FUNCTION) pairs like `action'
603 attribute of `anything-sources'.
605 It is prepended to predefined pairs."
606 :type 'list
607 :group 'anything-config)
609 (defcustom anything-allow-skipping-current-buffer t
610 "Show current buffer or not in anything buffer"
611 :type 'boolean
612 :group 'anything-config)
614 (defcustom anything-c-enable-eval-defun-hack t
615 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
616 This hack is invoked when pressing C-M-x in the form (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
617 :type 'boolean
618 :group 'anything-config)
620 (defcustom anything-tramp-verbose 0
621 "*Just like `tramp-verbose' but specific to anything.
622 When set to 0 don't show tramp messages in anything.
623 If you want to have the default tramp messages set it to 3."
624 :type 'integer
625 :group 'anything-config)
627 ;;; Documentation
628 ;; It is replaced by `anything-help'
629 (defun anything-c-describe-anything-bindings ()
630 "[OBSOLETE] Describe `anything' bindings."
631 (interactive)
632 (anything-run-after-quit
633 #'(lambda ()
634 (with-current-buffer (get-buffer-create "*Anything Help*")
635 (erase-buffer)
636 (insert
637 (substitute-command-keys
638 "The keys that are defined for `anything' are:
639 \\{anything-map}")))
640 (pop-to-buffer "*Anything Help*")
641 (goto-char (point-min)))))
643 ;; Use `describe-mode' key in `global-map'
644 ;; (dolist (k (where-is-internal 'describe-mode global-map))
645 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
647 ;;; Help message
648 (defun anything-c-list-preconfigured-anything ()
649 (loop with doc
650 with sym
651 for entry in (cdr (assoc (locate-library "anything-config") load-history))
652 if (and (consp entry)
653 (eq (car entry) 'defun)
654 (string-match "^Preconfigured.+$"
655 (setq doc (or (documentation (setq sym (cdr entry)))
656 ""))))
657 collect (format "\\[%s] : %s\n" sym (match-string 0 doc))))
659 (setq anything-help-message
660 (concat
661 "\\<anything-map>"
662 "`anything' is QuickSilver-like candidate-selection framework.
664 Narrow the list by typing some pattern,
665 Multiple patterns are allowed by splitting by space.
666 Select with natural Emacs operations, choose with RET.
668 == Basic Operations ==
669 C-p, Up: Previous Line
670 C-n, Down : Next Line
671 M-v, PageUp : Previous Page
672 C-v, PageDown : Next Page
673 Enter : Execute first (default) action / Select
674 M-< : First Line
675 M-> : Last Line
676 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
677 M-PageDown, C-M-v : Next Page (other-window)
679 Tab, C-i : Show action list
680 Left : Previous Source
681 Right, C-o : Next Source
682 C-k : Delete pattern
683 C-z : Persistent Action (Execute action with anything session kept)
685 == Shortcuts For 2nd/3rd Action ==
686 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
687 \\[anything-select-3rd-action] : Execute 3rd Action
689 == Visible Marks ==
690 Visible marks store candidate. Some actions uses marked candidates.
692 \\[anything-toggle-visible-mark] : Toggle Visible Mark
693 \\[anything-prev-visible-mark] : Previous Mark
694 \\[anything-next-visible-mark] : Next Mark
696 == Miscellaneous Commands ==
697 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
698 \\[anything-quit-and-find-file] : Drop into `find-file'
699 \\[anything-delete-current-selection] : Delete Selected Item (visually)
700 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
701 \\[anything-yank-selection] : Yank Selected Item Into Pattern
702 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
703 \\[anything-force-update] : Recalculate And Redisplay Candidates
705 == Global Commands ==
706 \\<global-map>\\[anything-resume] revives last `anything' session.
707 It is very useful, so you should bind any key.
709 Simgle source is executed by \\[anything-call-source].
711 == Preconfigured `anything' ==
712 Preconfigured `anything' is commands that uses `anything' interface.
713 You can use them without configuration.
716 (apply 'concat (anything-c-list-preconfigured-anything))
718 Enjoy!"))
720 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
721 (defun anything-for-files ()
722 "Preconfigured `anything' for opening files.
723 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
724 (interactive)
725 (anything-other-buffer anything-for-files-prefered-list "*anything for files*"))
727 (defun anything-info-at-point ()
728 "Preconfigured `anything' for searching info at point."
729 (interactive)
730 (anything '(anything-c-source-info-elisp
731 anything-c-source-info-cl
732 anything-c-source-info-pages)
733 (thing-at-point 'symbol) nil nil nil "*anything info*"))
735 (defun anything-show-kill-ring ()
736 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
737 You may bind this command to M-y."
738 (interactive)
739 (anything-other-buffer 'anything-c-source-kill-ring "*anything kill-ring*"))
741 (defun anything-minibuffer-history ()
742 "Preconfigured `anything' for `minibuffer-history'."
743 (interactive)
744 (let ((enable-recursive-minibuffers t))
745 (anything-other-buffer 'anything-c-source-minibuffer-history
746 "*anything minibuffer-history*")))
748 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
749 ;; minibuffer-local-filename-must-match-map.
750 (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) ;; Emacs 23.1.+
751 (defvar minibuffer-local-must-match-filename-map (make-sparse-keymap)) ;; Older Emacsen
752 (dolist (map (list minibuffer-local-filename-completion-map
753 minibuffer-local-completion-map
754 minibuffer-local-must-match-filename-map
755 minibuffer-local-filename-must-match-map
756 minibuffer-local-map
757 minibuffer-local-isearch-map
758 minibuffer-local-must-match-map
759 minibuffer-local-ns-map))
760 (define-key map "\C-r" 'anything-minibuffer-history))
762 (defun anything-gentoo ()
763 "Preconfigured `anything' for gentoo linux."
764 (interactive)
765 (anything-other-buffer '(anything-c-source-gentoo
766 anything-c-source-use-flags)
767 "*anything gentoo*"))
769 (defun anything-surfraw-only ()
770 "Preconfigured `anything' for surfraw.
771 If region is marked set anything-pattern to region.
772 With one prefix arg search symbol at point.
773 With two prefix args allow choosing in which symbol to search."
774 (interactive)
775 (let (search pattern)
776 (cond ((region-active-p)
777 (setq pattern (buffer-substring (region-beginning) (region-end))))
778 ((equal current-prefix-arg '(4))
779 (setq pattern (thing-at-point 'symbol)))
780 ((equal current-prefix-arg '(16))
781 (setq search
782 (intern
783 (completing-read "Search in: "
784 (list "symbol" "sentence" "sexp" "line" "word"))))
785 (setq pattern (thing-at-point search))))
786 (anything 'anything-c-source-surfraw
787 (and pattern (replace-regexp-in-string "\n" "" pattern))
788 nil nil nil "*anything surfraw*")))
790 (defun anything-imenu ()
791 "Preconfigured `anything' for `imenu'."
792 (interactive)
793 (anything 'anything-c-source-imenu nil nil nil nil "*anything imenu*"))
795 (defun anything-google-suggest ()
796 "Preconfigured `anything' for google search with google suggest."
797 (interactive)
798 (anything-other-buffer 'anything-c-source-google-suggest "*anything google*"))
800 (defun anything-yahoo-suggest ()
801 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
802 (interactive)
803 (anything-other-buffer 'anything-c-source-yahoo-suggest "*anything yahoo*"))
805 ;;; Converted from anything-show-*-only
806 (defun anything-for-buffers ()
807 "Preconfigured `anything' for buffer."
808 (interactive)
809 (anything-other-buffer 'anything-c-source-buffers "*anything for buffers*"))
811 (defun anything-bbdb ()
812 "Preconfigured `anything' for BBDB."
813 (interactive)
814 (anything-other-buffer 'anything-c-source-bbdb "*anything bbdb*"))
816 (defun anything-locate ()
817 "Preconfigured `anything' for Locate."
818 (interactive)
819 (anything-other-buffer 'anything-c-source-locate "*anything locate*"))
821 (defun anything-w3m-bookmarks ()
822 "Preconfigured `anything' for w3m bookmark."
823 (interactive)
824 (anything-other-buffer 'anything-c-source-w3m-bookmarks "*anything w3m bookmarks*"))
826 (defun anything-colors ()
827 "Preconfigured `anything' for color."
828 (interactive)
829 (anything-other-buffer '(anything-c-source-colors anything-c-source-customize-face)
830 "*anything colors*"))
832 (defun anything-bm-list ()
833 "Preconfigured `anything' for visible bookmarks."
834 (interactive)
835 (anything-other-buffer 'anything-c-source-bm "*anything bm list*"))
837 (defun anything-timers ()
838 "Preconfigured `anything' for timers."
839 (interactive)
840 (anything-other-buffer '(anything-c-source-absolute-time-timers
841 anything-c-source-idle-time-timers)
842 "*anything timers*"))
844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
845 ;;; kill buffers
846 (defun anything-kill-buffers ()
847 "Preconfigured `anything' to kill buffer you selected."
848 (interactive)
849 (anything
850 '(((name . "Kill Buffers")
851 (candidates . anything-c-buffer-list)
852 (action
853 ("Kill Buffer" . (lambda (candidate)
854 (kill-buffer candidate)
855 (anything-kill-buffers)
856 )))))
857 nil nil))
859 ;;; Regexp
860 (defun anything-query-replace-regexp (&rest args)
861 "Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually."
862 (interactive
863 (let ((common
864 (anything-c-regexp-base "Query Replace Regexp: "
865 '((name . "Lines matching Regexp")
866 (mode-line . "Set replace start line and type RET.")
867 (action . anything-c-query-replace-args)))))
868 (if (not common)
869 (keyboard-quit))
870 (list (car common) (cadr common) (caddr common)
871 ;; These are done separately here
872 ;; so that command-history will record these expressions
873 ;; rather than the values they had this time.
875 ;; This idea is borrowed from original `query-replace-regexp'.
876 (if (and transient-mark-mode mark-active)
877 (region-beginning))
878 (if (and transient-mark-mode mark-active)
879 (region-end)))))
880 (apply 'query-replace-regexp args))
882 (defun anything-regexp ()
883 "Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement."
884 (interactive)
885 (anything-c-regexp-base
886 "Regexp: "
887 '((name . "Regexp Builder")
888 (mode-line . "Press TAB to select action.")
889 (action
890 ("Kill Regexp as sexp" .
891 (lambda (x) (anything-c-regexp-kill-new (prin1-to-string (funcall (anything-attr 'regexp))))))
892 ("Query Replace Regexp" .
893 (lambda (x) (apply 'query-replace-regexp (anything-c-query-replace-args (point)))))
894 ("Kill Regexp" .
895 (lambda (x) (anything-c-regexp-kill-new (funcall (anything-attr 'regexp)))))))))
897 (defun anything-c-query-replace-args (start-point)
898 ;; create arguments of `query-replace-regexp'.
899 (let ((region-only (and transient-mark-mode mark-active))
900 (regexp (funcall (anything-attr 'regexp))))
901 (list
902 regexp
903 (query-replace-read-to regexp
904 (format "Query replace regexp %s%s%s with: "
905 (if region-only "in region " "")
906 regexp
907 (if current-prefix-arg "(word) " ""))
909 current-prefix-arg)))
911 (defun anything-c-regexp-get-line (s e)
912 (propertize
913 (apply 'concat
914 ;; Line contents
915 (format "%5d: %s" (line-number-at-pos s) (buffer-substring s e))
916 ;; subexps
917 (loop for i from 0 to (1- (/ (length (match-data)) 2))
918 unless (zerop i)
919 collect (format "\n $%d = %s"
920 i (match-string i))))
921 ;; match beginning
922 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
923 ;; It is implementation problem of candidates-in-buffer.
924 'anything-realvalue
925 (1- s)))
927 ;; Shut up byte compiler
928 (defun anything-goto-line (numline)
929 "Replacement of `goto-line'."
930 (goto-char (point-min))
931 (forward-line (1- numline)))
933 (defun anything-c-regexp-persistent-action (pt)
934 (goto-char pt)
935 (anything-persistent-highlight-point))
937 (defun anything-c-regexp-base (prompt attributes)
938 (save-restriction
939 (let ((anything-compile-source-functions
940 ;; rule out anything-match-plugin because the input is one regexp.
941 (delq 'anything-compile-source--match-plugin
942 (copy-sequence anything-compile-source-functions)))
943 (base-attributes
944 '((init . (lambda () (anything-candidate-buffer anything-current-buffer)))
945 (candidates-in-buffer)
946 (get-line . anything-c-regexp-get-line)
947 (persistent-action . anything-c-regexp-persistent-action)
948 (persistent-help . "Show this line")
949 (multiline)
950 (delayed))))
951 (if (and transient-mark-mode mark-active)
952 (narrow-to-region (region-beginning) (region-end)))
953 (anything
954 (list
955 (append
956 attributes
957 '((regexp . (lambda () anything-pattern)))
958 base-attributes)
959 ;; sexp form regexp
960 (append
961 `((name . ,(concat (assoc-default 'name attributes) " (sexp)")))
962 attributes
963 '((candidates-in-buffer
964 . (lambda () (let ((anything-pattern (eval (read anything-pattern))))
965 (anything-candidates-in-buffer))))
966 (regexp . (lambda () (eval (read anything-pattern)))))
967 base-attributes))
968 nil prompt nil nil "*anything regexp*"))))
970 ;; (anything-c-regexp-base "Regexp: " '((name . "test")))
971 ;; (anything-c-regexp-base "Regexp: " '((name . "test") (candidates-in-buffer . (lambda () (let ((anything-pattern (eval (read anything-pattern)))) (anything-candidates-in-buffer))))))
973 (defun anything-c-regexp-kill-new (input)
974 (kill-new input)
975 (message "Killed: %s" input))
977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
979 (defun anything-insert-buffer-name ()
980 "Insert buffer name."
981 (interactive)
982 (anything-insert-string
983 (with-current-buffer anything-current-buffer
984 (if buffer-file-name (file-name-nondirectory buffer-file-name)
985 (buffer-name)))))
987 (defun anything-insert-symbol ()
988 "Insert current symbol."
989 (interactive)
990 (anything-insert-string
991 (with-current-buffer anything-current-buffer
992 (save-excursion
993 (buffer-substring (beginning-of-thing 'symbol)
994 (end-of-thing 'symbol))))))
996 (defun anything-insert-selection ()
997 "Insert current selection."
998 (interactive)
999 (anything-insert-string
1000 (with-current-buffer anything-current-buffer
1001 (anything-get-selection))))
1003 (defun anything-show-buffer-only ()
1004 "[OBSOLETE] Only show sources about buffer.
1005 Use `anything-for-buffers' instead."
1006 (interactive)
1007 (anything-set-source-filter '("Buffers")))
1009 (defun anything-show-bbdb-only ()
1010 "[OBSOLETE] Only show sources about BBDB.
1011 Use `anything-bbdb' instead."
1012 (interactive)
1013 (anything-set-source-filter '("BBDB")))
1015 (defun anything-show-locate-only ()
1016 "[OBSOLETE] Only show sources about Locate.
1017 Use `anything-locate' instead."
1018 (interactive)
1019 (anything-set-source-filter '("Locate")))
1021 (defun anything-show-info-only ()
1022 "[OBSOLETE] Only show sources about Info.
1023 Use `anything-info-at-point' instead."
1024 (interactive)
1025 (anything-set-source-filter '("Info Pages"
1026 "Info Elisp"
1027 "Info Common-Lisp")))
1029 (defun anything-show-imenu-only ()
1030 "[OBSOLETE] Only show sources about Imenu.
1031 Use `anything-imenu' instead."
1032 (interactive)
1033 (anything-set-source-filter '("Imenu")))
1035 (defun anything-show-files-only ()
1036 "[OBSOLETE] Only show sources about File.
1037 Use `anything-for-files' instead."
1038 (interactive)
1039 (anything-set-source-filter '("File Name History"
1040 "Files from Current Directory"
1041 "Recentf")))
1043 (defun anything-show-w3m-bookmarks-only ()
1044 "[OBSOLETE] Only show source about w3m bookmark.
1045 Use `anything-w3m-bookmarks' instead."
1046 (interactive)
1047 (anything-set-source-filter '("W3m Bookmarks")))
1049 (defun anything-show-colors-only ()
1050 "[OBSOLETE] Only show source about color.
1051 Use `anything-colors' instead."
1052 (interactive)
1053 (anything-set-source-filter '("Colors"
1054 "Customize Faces")))
1056 (defun anything-show-kill-ring-only ()
1057 "[OBSOLETE] Only show source about kill ring.
1058 Use `anything-show-kill-ring' instead."
1059 (interactive)
1060 (anything-set-source-filter '("Kill Ring")))
1062 (defun anything-show-this-source-only ()
1063 "Only show this source."
1064 (interactive)
1065 (setq anything-candidate-number-limit 9999)
1066 (anything-set-source-filter
1067 (list (assoc-default 'name (anything-get-current-source)))))
1069 (defun anything-test-sources ()
1070 "List all anything sources for test.
1071 The output is sexps which are evaluated by \\[eval-last-sexp]."
1072 (interactive)
1073 (with-output-to-temp-buffer "*Anything Test Sources*"
1074 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
1075 (apropos-internal "^anything-c-source" #'boundp))
1076 (pop-to-buffer standard-output)))
1078 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1079 ;;; For compatibility
1080 (unless (fboundp 'region-active-p)
1081 (defun region-active-p ()
1082 "Return t if Transient Mark mode is enabled and the mark is active.
1084 Most commands that act on the region if it is active and
1085 Transient Mark mode is enabled, and on the text near point
1086 otherwise, should use `use-region-p' instead. That function
1087 checks the value of `use-empty-active-region' as well."
1088 (and transient-mark-mode mark-active)))
1090 (defun anything-nest (&rest same-as-anything)
1091 "Nested `anything'. If you use `anything' within `anything', use it."
1092 (with-selected-window (anything-window)
1093 (let (anything-current-position
1094 anything-current-buffer
1095 (orig-anything-buffer anything-buffer)
1096 anything-pattern
1097 anything-buffer
1098 anything-sources
1099 anything-compiled-sources
1100 anything-buffer-chars-modified-tick
1101 (anything-samewindow t)
1102 (enable-recursive-minibuffers t))
1103 (unwind-protect
1104 (apply #'anything same-as-anything)
1105 (anything-initialize-overlays orig-anything-buffer)
1106 (add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
1108 (defun anything-displaying-source-names ()
1109 "Display sources name."
1110 (with-current-buffer anything-buffer
1111 (goto-char (point-min))
1112 (loop with pos
1113 while (setq pos (next-single-property-change (point) 'anything-header))
1114 do (goto-char pos)
1115 collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
1116 do (forward-line 1))))
1118 (defun anything-select-source ()
1119 "Select source."
1120 (interactive)
1121 (let ((default (assoc-default 'name (anything-get-current-source)))
1122 (source-names (anything-displaying-source-names))
1123 (all-source-names (mapcar (lambda (s) (assoc-default 'name s))
1124 (anything-get-sources))))
1125 (setq anything-candidate-number-limit 9999)
1126 (anything-aif
1127 (let (anything-source-filter)
1128 (anything-nest '(((name . "Anything Source")
1129 (candidates . source-names)
1130 (action . identity))
1131 ((name . "Anything Source (ALL)")
1132 (candidates . all-source-names)
1133 (action . identity)))
1134 nil "Source: " nil
1135 default "*anything select source*"))
1136 (anything-set-source-filter (list it))
1137 (anything-set-source-filter nil))))
1139 (defun anything-insert-string (str)
1140 "Insert STR."
1141 (delete-minibuffer-contents)
1142 (insert str))
1144 (defun anything-c-match-on-file-name (candidate)
1145 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1146 (string-match anything-pattern (file-name-nondirectory candidate)))
1148 (defun anything-c-match-on-directory-name (candidate)
1149 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1150 (anything-aif (file-name-directory candidate)
1151 (string-match anything-pattern it)))
1153 (defun anything-c-string-match (candidate)
1154 "Return non-nil if `anything-pattern' match CANDIDATE.
1155 The match is done with `string-match'."
1156 (string-match anything-pattern candidate))
1158 ;; `anything-c-compose' is no more needed, it is for compatibility.
1159 (defalias 'anything-c-compose 'anything-compose)
1161 (defun anything-c-skip-entries (list regexp)
1162 "Remove entries which matches REGEXP from LIST."
1163 (remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
1164 list))
1166 (defun anything-c-shadow-entries (list regexp)
1167 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1168 (mapcar (lambda (file)
1169 ;; Add shadow face property to boring files.
1170 (let ((face (if (facep 'file-name-shadow)
1171 'file-name-shadow
1172 ;; fall back to default on XEmacs
1173 'default)))
1174 (if (string-match regexp file)
1175 (setq file (propertize file 'face face))))
1176 file)
1177 list))
1179 (defsubst anything-c-stringify (str-or-sym)
1180 "Get string of STR-OR-SYM."
1181 (if (stringp str-or-sym)
1182 str-or-sym
1183 (symbol-name str-or-sym)))
1185 (defsubst anything-c-symbolify (str-or-sym)
1186 "Get symbol of STR-OR-SYM."
1187 (if (symbolp str-or-sym)
1188 str-or-sym
1189 (intern str-or-sym)))
1191 (defun anything-c-describe-function (func)
1192 "FUNC is symbol or string."
1193 (describe-function (anything-c-symbolify func)))
1195 (defun anything-c-describe-variable (var)
1196 "VAR is symbol or string."
1197 (describe-variable (anything-c-symbolify var)))
1199 (defun anything-c-find-function (func)
1200 "FUNC is symbol or string."
1201 (find-function (anything-c-symbolify func)))
1203 (defun anything-c-find-variable (var)
1204 "VAR is symbol or string."
1205 (find-variable (anything-c-symbolify var)))
1207 (defun anything-c-kill-new (string &optional replace yank-handler)
1208 "STRING is symbol or string."
1209 (kill-new (anything-c-stringify string) replace yank-handler))
1211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1212 ;; TODO
1213 (defvar anything-current-prefix-arg nil
1214 "`current-prefix-arg' when selecting action.
1215 It is cleared after executing action.")
1217 (defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
1218 (unless anything-current-prefix-arg
1219 (setq anything-current-prefix-arg current-prefix-arg)))
1221 (add-hook 'anything-after-action-hook
1222 (lambda () (setq anything-current-prefix-arg nil)))
1225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1226 (defadvice eval-defun (after anything-source-hack activate)
1227 "See `anything-c-enable-eval-defun-hack'."
1228 (when anything-c-enable-eval-defun-hack
1229 (let ((varsym (save-excursion
1230 (beginning-of-defun)
1231 (forward-char 1)
1232 (when (memq (read (current-buffer)) '(defvar setq))
1233 (read (current-buffer))))))
1234 (when (string-match "^anything-c-source-" (symbol-name varsym))
1235 (anything varsym)))))
1236 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1239 (defun anything-c-create-summary ()
1240 "Create `anything' summary."
1241 (save-excursion
1242 (goto-char (point-min))
1243 (loop while (re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$" nil t)
1244 collect (cond ((match-beginning 1)
1245 (cons 'section (match-string-no-properties 1)))
1246 ((match-beginning 2)
1247 (cons 'source
1248 (cons (match-string-no-properties 2)
1249 (assoc-default 'name (symbol-value (intern (match-string-no-properties 2)))))))
1250 ((match-beginning 3)
1251 (cons 'source
1252 (cons (match-string-no-properties 3)
1253 (assoc-default 'name (symbol-value (intern (match-string-no-properties 3)))))))))))
1255 ;; (find-epp (anything-c-create-summary))
1257 (defun anything-c-insert-summary ()
1258 "Insert `anything' summary."
1259 (save-excursion
1260 (goto-char (point-min))
1261 (search-forward ";; Below are complete source list you can setup in")
1262 (forward-line 1)
1263 (delete-region (point)
1264 (progn (search-forward ";;; Change log:" nil t)
1265 (forward-line -1) (point)))
1266 (insert ";;\n")
1267 (loop with beg
1268 for (kind . value) in (anything-c-create-summary)
1269 for i from 0
1270 do (cond ((eq kind 'section)
1271 (unless (zerop i)
1272 (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
1273 (insert ";; " value ":\n")
1274 (setq beg (point)))
1276 (insert ";; `" (car value) "' (" (cdr value) ")\n")))
1277 finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
1278 ;; (anything-c-insert-summary)
1280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1281 ;;;; <Buffer>
1282 (defun anything-c-buffer-list ()
1283 "Return the list of names of buffers with boring buffers filtered out.
1284 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1285 The first buffer in the list will be the last recently used
1286 buffer that is not the current buffer."
1287 (let ((buffers (mapcar 'buffer-name (buffer-list))))
1288 (append (cdr buffers) (list (car buffers)))))
1290 (defvar anything-c-source-buffers
1291 '((name . "Buffers")
1292 (candidates . anything-c-buffer-list)
1293 (type . buffer)))
1294 ;; (anything 'anything-c-source-buffers)
1296 (defvar anything-c-source-buffer-not-found
1297 '((name . "Create buffer")
1298 (dummy)
1299 (type . buffer)))
1300 ;; (anything 'anything-c-source-buffer-not-found)
1302 ;;; Buffers+
1303 (defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
1304 "*Face used for directory headings in dired buffers."
1305 :group 'anything)
1307 (defface anything-file-name
1308 '((t (:foreground "Blue")))
1309 "*Face used for file names (without suffixes) in dired buffers."
1310 :group 'anything)
1312 (defface anything-dir-priv
1313 '((t (:foreground "DarkRed" :background "LightGray")))
1314 "*Face used for directory privilege indicator (d) in dired buffers."
1315 :group 'anything)
1317 (defvar anything-c-buffers-face1 'anything-dir-priv)
1318 (defvar anything-c-buffers-face2 'font-lock-type-face)
1319 (defvar anything-c-buffers-face3 'italic)
1320 (eval-when-compile (require 'dired))
1321 (defun anything-c-highlight-buffers (buffers)
1322 (require 'dired)
1323 (loop for i in buffers
1324 if (rassoc (get-buffer i) dired-buffers)
1325 collect (propertize i
1326 'face anything-c-buffers-face1
1327 'help-echo (car (rassoc (get-buffer i) dired-buffers)))
1328 if (buffer-file-name (get-buffer i))
1329 collect (propertize i
1330 'face anything-c-buffers-face2
1331 'help-echo (buffer-file-name (get-buffer i)))
1332 if (and (not (rassoc (get-buffer i) dired-buffers))
1333 (not (buffer-file-name (get-buffer i))))
1334 collect (propertize i
1335 'face anything-c-buffers-face3)))
1337 (defvar anything-c-source-buffers+
1338 '((name . "Buffers")
1339 (candidates . anything-c-buffer-list)
1340 (type . buffer)
1341 (candidate-transformer anything-c-skip-current-buffer
1342 anything-c-highlight-buffers
1343 anything-c-skip-boring-buffers)
1344 (persistent-action . anything-c-buffers+-persistent-action)
1345 (persistent-help . "Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1347 (defun anything-c-buffers+-persistent-action (name)
1348 (flet ((kill (item)
1349 (with-current-buffer item
1350 (if (and (buffer-modified-p)
1351 (buffer-file-name (current-buffer)))
1352 (progn
1353 (save-buffer)
1354 (kill-buffer item))
1355 (kill-buffer item))))
1356 (goto (item)
1357 (switch-to-buffer item)))
1358 (if current-prefix-arg
1359 (progn
1360 (kill name)
1361 (anything-delete-current-selection))
1362 (goto name))))
1364 ;; (anything 'anything-c-source-buffers+)
1367 ;;;; <File>
1368 ;;; File name history
1369 (defvar anything-c-source-file-name-history
1370 '((name . "File Name History")
1371 (candidates . file-name-history)
1372 (match anything-c-match-on-file-name
1373 anything-c-match-on-directory-name)
1374 (type . file)))
1375 ;; (anything 'anything-c-source-file-name-history)
1377 ;;; Files in current dir
1378 (defvar anything-c-source-files-in-current-dir
1379 '((name . "Files from Current Directory")
1380 (candidates . (lambda ()
1381 (with-current-buffer anything-current-buffer
1382 (directory-files default-directory))))
1383 ;; volatile is not needed, I think.
1384 (type . file)))
1385 ;; (anything 'anything-c-source-files-in-current-dir)
1387 (defvar anything-c-files-face1 'anything-dir-priv)
1388 (defvar anything-c-files-face2 'anything-file-name)
1389 (defun anything-c-highlight-files (files)
1390 (loop for i in files
1391 if (file-directory-p i)
1392 collect (propertize (file-name-nondirectory i)
1393 'face anything-c-files-face1
1394 'help-echo (expand-file-name i))
1395 else
1396 collect (propertize (file-name-nondirectory i)
1397 'face anything-c-files-face2
1398 'help-echo (expand-file-name i))))
1401 (defvar anything-c-source-files-in-current-dir+
1402 '((name . "Files from Current Directory")
1403 (candidates . (lambda ()
1404 (with-current-buffer anything-current-buffer
1405 (directory-files default-directory t))))
1406 (candidate-transformer anything-c-highlight-files)
1407 ;; volatile is not needed, I think.
1408 (type . file)))
1410 ;; (anything 'anything-c-source-files-in-current-dir+)
1412 ;;; Anything replacement of file name completion for `find-file' and friends.
1414 (defvar anything-c-find-files-doc-header (format " (`%s':Go to precedent level)"
1415 (if window-system "C-." "C-l"))
1416 "*The doc that is inserted in the Name header of a find-files or dired source.")
1418 (defvar anything-c-source-find-files
1419 `((name . ,(concat "Find Files" anything-c-find-files-doc-header))
1420 ;; It is needed for filenames with capital letters
1421 (disable-shortcuts)
1422 (init . (lambda ()
1423 (setq ffap-newfile-prompt t)))
1424 (candidates . anything-find-files-get-candidates)
1425 (candidate-transformer anything-c-highlight-ffiles)
1426 (persistent-action . anything-find-files-persistent-action)
1427 (persistent-help . "Expand Candidate")
1428 (volatile)
1429 (action . ,(delq nil `(("Find File" . find-file-at-point)
1430 ("Find file in Dired" . anything-c-point-file-in-dired)
1431 ,(and (locate-library "elscreen") '("Find file in Elscreen" . anything-elscreen-find-file))
1432 ("Complete at point" . anything-c-insert-file-name-completion-at-point)
1433 ("Delete File(s)" . anything-delete-marked-files)
1434 ("Find file as root" . anything-find-file-as-root)
1435 ("Find file other window" . find-file-other-window)
1436 ("Find file other frame" . find-file-other-frame))))))
1438 ;; (anything 'anything-c-source-find-files)
1440 (defun* anything-reduce-file-name (fname level &key unix-close expand)
1441 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1442 If LEVEL is positive reduce from end else from beginning.
1443 If UNIX-CLOSE is non--nil close filename with /.
1444 If EXPAND is non--nil expand-file-name."
1445 (let* ((exp-fname (expand-file-name fname))
1446 (fname-list (split-string (if (or (string= fname "~/") expand)
1447 exp-fname fname) "/" t))
1448 (len (length fname-list))
1449 (pop-list (if (< level 0)
1450 (subseq fname-list (* level -1))
1451 (subseq fname-list 0 (- len level))))
1452 (result (mapconcat 'identity pop-list "/"))
1453 (empty (string= result "")))
1454 (when unix-close (setq result (concat result "/")))
1455 (if (string-match "^~" result)
1456 (if (string= result "~/") "~/" result)
1457 (if (< level 0)
1458 (if empty "../" (concat "../" result))
1459 (cond ((and (eq system-type 'windows-nt) empty)
1460 "c:/")
1461 ((and (not empty) (eq system-type 'windows-nt))
1462 result)
1463 (empty "/")
1465 (concat "/" result)))))))
1467 (defun anything-find-files-or-dired-p ()
1468 "Test if current source is a dired or find-files source."
1469 (let ((ff-sources '("Find Files" "Copy Files"
1470 "Rename Files" "Symlink Files"
1471 "Hardlink Files" "Write File" "Insert File"))
1472 (cur-source (cdr (assoc 'name (anything-get-current-source)))))
1473 (catch 'break
1474 (dolist (i ff-sources)
1475 (when (equal cur-source (concat i anything-c-find-files-doc-header))
1476 (throw 'break t))))))
1478 (defun anything-find-files-down-one-level (arg)
1479 "Go down one level like unix command `cd ..'.
1480 If prefix numeric arg is given go ARG level down."
1481 (interactive "p")
1482 (when (anything-find-files-or-dired-p)
1483 (let ((new-pattern (anything-reduce-file-name anything-pattern arg :unix-close t :expand t)))
1484 (with-selected-window (minibuffer-window)
1485 (delete-minibuffer-contents)
1486 (insert new-pattern)))))
1488 ;; `C-.' doesn't work in terms use `C-l' instead.
1489 (if window-system
1490 (define-key anything-map (kbd "C-.") 'anything-find-files-down-one-level)
1491 (define-key anything-map (kbd "C-l") 'anything-find-files-down-one-level))
1493 (defun anything-c-point-file-in-dired (file)
1494 "Put point on filename FILE in dired buffer."
1495 (dired (file-name-directory file))
1496 (dired-goto-file file))
1498 (defun anything-create-tramp-name (fname)
1499 "Build filename for `anything-pattern' like /su:: or /sudo::."
1500 (apply #'tramp-make-tramp-file-name
1501 (loop
1502 with v = (tramp-dissect-file-name fname)
1503 for i across v collect i)))
1505 (defun anything-find-files-get-candidates ()
1506 "Create candidate list for `anything-c-source-find-files'."
1507 (let* (; Don't try to tramp connect before entering the second ":".
1508 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1509 (path (cond ((string-match "^~" anything-pattern)
1510 (replace-match (getenv "HOME") nil t anything-pattern))
1511 ((string-match tramp-file-name-regexp anything-pattern)
1512 (let ((tramp-name (anything-create-tramp-name
1513 (match-string 0 anything-pattern))))
1514 (replace-match tramp-name nil t anything-pattern)))
1515 (t anything-pattern)))
1516 (tramp-verbose anything-tramp-verbose)) ; No tramp message when 0.
1517 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1518 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1519 ;; and sorting.
1520 (flet ((tramp-handle-directory-files
1521 (directory &optional full match nosort files-only)
1522 "Like `directory-files' for Tramp files."
1523 ;; FILES-ONLY is valid for XEmacs only.
1524 (when (file-directory-p directory)
1525 (setq directory (file-name-as-directory (expand-file-name directory)))
1526 (let ((temp (nreverse (file-name-all-completions "" directory)))
1527 result item)
1529 (while temp
1530 (setq item (directory-file-name (pop temp)))
1531 (when (and (or (null match) (string-match match item))
1532 (or (null files-only)
1533 ;; Files only.
1534 (and (equal files-only t) (file-regular-p item))
1535 ;; Directories only.
1536 (file-directory-p item)))
1537 (push (if full (concat directory item) item)
1538 result)))
1539 (if nosort result (sort result 'string<))))))
1541 (set-text-properties 0 (length path) nil path)
1542 (setq anything-pattern path)
1543 (cond ((or (file-regular-p path)
1544 (and ffap-url-regexp (string-match ffap-url-regexp path)))
1545 (list path))
1546 ((string= anything-pattern "") (directory-files "/" t))
1547 ((file-directory-p path) (directory-files path t))
1549 (append
1550 (list path)
1551 (directory-files (file-name-directory path) t)))))))
1553 (defface anything-dired-symlink-face
1554 '((t (:foreground "DarkOrange")))
1555 "*Face used for symlinks in `anything-find-files'."
1556 :group 'anything)
1558 (defun anything-c-highlight-ffiles (files)
1559 "Candidate transformer for `anything-c-source-find-files'."
1560 (loop for i in files
1561 if (file-symlink-p i)
1562 collect (propertize i 'face 'anything-dired-symlink-face
1563 'help-echo (file-truename i)) into a
1564 if (file-directory-p i)
1565 collect (propertize i 'face anything-c-files-face1) into a
1566 else
1567 collect (propertize i 'face anything-c-files-face2) into a
1568 finally return a))
1571 (defun anything-find-files-persistent-action (candidate)
1572 "Open subtree CANDIDATE without quitting anything.
1573 If CANDIDATE is not a directory expand CANDIDATE filename.
1574 If CANDIDATE is alone, open file CANDIDATE filename."
1575 (flet ((insert-in-minibuffer (elm)
1576 (with-selected-window (minibuffer-window)
1577 (delete-minibuffer-contents)
1578 (set-text-properties 0 (length elm) nil elm)
1579 (insert elm))))
1580 (cond ((and (file-directory-p candidate) (file-symlink-p candidate))
1581 (insert-in-minibuffer (file-name-as-directory
1582 (file-truename
1583 (expand-file-name candidate)))))
1584 ((file-directory-p candidate)
1585 (insert-in-minibuffer (file-name-as-directory
1586 (expand-file-name candidate))))
1587 ((file-symlink-p candidate)
1588 (insert-in-minibuffer (file-truename candidate)))
1589 (t ; First hit on C-z expand CANDIDATE second hit open file.
1590 (let ((new-pattern (anything-get-selection anything-last-buffer))
1591 (num-lines-buf (with-current-buffer anything-last-buffer
1592 (count-lines (point-min) (point-max)))))
1593 (if (> num-lines-buf 3)
1594 (insert-in-minibuffer new-pattern) (find-file candidate)))))))
1597 (defun anything-c-insert-file-name-completion-at-point (candidate)
1598 "Insert file name completion at point."
1599 (let* ((end (point))
1600 (guess (thing-at-point 'filename))
1601 (full-path-p (string-match (concat "^" (getenv "HOME")) guess)))
1602 (set-text-properties 0 (length candidate) nil candidate)
1603 (condition-case nil
1604 (when (file-exists-p (file-name-directory guess))
1605 (search-backward guess (- (point) (length guess)))
1606 (delete-region (point) end)
1607 (if full-path-p
1608 (insert (expand-file-name candidate))
1609 (insert (abbreviate-file-name candidate))))
1610 (error nil))))
1612 (defun anything-find-files ()
1613 "Preconfigured `anything' for `find-file'."
1614 (interactive)
1615 (let* ((fap (ffap-guesser))
1616 (file-p (and fap (file-exists-p fap)))
1617 (tap (thing-at-point 'filename))
1618 (input (if file-p (expand-file-name tap) fap)))
1619 (anything 'anything-c-source-find-files
1620 (or input (expand-file-name default-directory))
1621 "Find Files or Url: " nil nil "*Anything Find Files*")))
1623 ;;; Anything completion for `write-file'.==> C-x C-w
1624 (defvar anything-c-source-write-file
1625 `((name . ,(concat "Write File" anything-c-find-files-doc-header))
1626 (candidates . anything-find-files-get-candidates)
1627 (candidate-transformer anything-c-highlight-ffiles)
1628 (persistent-action . anything-find-files-persistent-action)
1629 (persistent-help . "Expand Candidate")
1630 (volatile)
1631 (action .
1632 (("Write File" . (lambda (candidate)
1633 (write-file candidate 'confirm)))))))
1635 (defun anything-write-file ()
1636 "Preconfigured `anything' providing completion for `write-file'."
1637 (interactive)
1638 (anything 'anything-c-source-write-file
1639 (expand-file-name default-directory)
1640 "Write buffer to file: " nil nil "*Anything write file*"))
1642 ;;; Anything completion for `insert-file'.==> C-x i
1643 (defvar anything-c-source-insert-file
1644 `((name . ,(concat "Insert File" anything-c-find-files-doc-header))
1645 (candidates . anything-find-files-get-candidates)
1646 (candidate-transformer anything-c-highlight-ffiles)
1647 (persistent-action . anything-find-files-persistent-action)
1648 (persistent-help . "Expand Candidate")
1649 (volatile)
1650 (action .
1651 (("Insert File" . (lambda (candidate)
1652 (when (y-or-n-p (format "Really insert %s in %s "
1653 candidate anything-current-buffer))
1654 (insert-file candidate))))))))
1656 (defun anything-insert-file ()
1657 "Preconfigured `anything' providing completion for `insert-file'."
1658 (interactive)
1659 (anything 'anything-c-source-insert-file
1660 (expand-file-name default-directory)
1661 "Insert file: " nil nil "*Anything insert file*"))
1663 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
1664 (defvar anything-c-source-copy-files
1665 `((name . ,(concat "Copy Files" anything-c-find-files-doc-header))
1666 (candidates . anything-find-files-get-candidates)
1667 (candidate-transformer anything-c-highlight-ffiles)
1668 (persistent-action . anything-find-files-persistent-action)
1669 (persistent-help . "Expand Candidate")
1670 (volatile)
1671 (action .
1672 (("Copy File"
1673 . (lambda (candidate)
1674 (anything-dired-action candidate :action 'copy)))
1675 ("Copy and Follow"
1676 . (lambda (candidate)
1677 (anything-dired-action candidate :action 'copy :follow t)))))))
1680 (defvar anything-c-source-rename-files
1681 `((name . ,(concat "Rename Files" anything-c-find-files-doc-header))
1682 (candidates . anything-find-files-get-candidates)
1683 (candidate-transformer anything-c-highlight-ffiles)
1684 (persistent-action . anything-find-files-persistent-action)
1685 (persistent-help . "Expand Candidate")
1686 (volatile)
1687 (action .
1688 (("Rename File"
1689 . (lambda (candidate)
1690 (anything-dired-action candidate :action 'rename)))
1691 ("Rename and Follow"
1692 . (lambda (candidate)
1693 (anything-dired-action candidate :action 'rename :follow t)))))))
1695 (defvar anything-c-source-symlink-files
1696 `((name . ,(concat "Symlink Files" anything-c-find-files-doc-header))
1697 (candidates . anything-find-files-get-candidates)
1698 (candidate-transformer anything-c-highlight-ffiles)
1699 (persistent-action . anything-find-files-persistent-action)
1700 (persistent-help . "Expand Candidate")
1701 (volatile)
1702 (action .
1703 (("Symlink File" . (lambda (candidate)
1704 (anything-dired-action candidate :action 'symlink)))
1705 ("RelSymlink File" . (lambda (candidate)
1706 (anything-dired-action candidate :action 'relsymlink)))))))
1709 (defvar anything-c-source-hardlink-files
1710 `((name . ,(concat "Hardlink Files" anything-c-find-files-doc-header))
1711 (candidates . anything-find-files-get-candidates)
1712 (candidate-transformer anything-c-highlight-ffiles)
1713 (persistent-action . anything-find-files-persistent-action)
1714 (persistent-help . "Expand Candidate")
1715 (volatile)
1716 (action .
1717 (("Hardlink File" . (lambda (candidate)
1718 (anything-dired-action candidate :action 'hardlink)))))))
1720 (defun* anything-dired-action (candidate &key action follow)
1721 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
1722 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
1723 (let ((files (dired-get-marked-files))
1724 (fn (case action
1725 ('copy 'dired-copy-file)
1726 ('rename 'dired-rename-file)
1727 ('symlink 'make-symbolic-link)
1728 ('relsymlink 'dired-make-relative-symlink)
1729 ('hardlink 'dired-hardlink)))
1730 (marker (case action
1731 ((copy rename) dired-keep-marker-copy)
1732 ('symlink dired-keep-marker-symlink)
1733 ('relsymlink dired-keep-marker-relsymlink)
1734 ('hardlink dired-keep-marker-hardlink))))
1735 (dired-create-files
1736 fn (symbol-name action) files
1737 (if (file-directory-p candidate)
1738 ;; When CANDIDATE is a directory, build file-name in this directory.
1739 ;; Else we use CANDIDATE.
1740 #'(lambda (from)
1741 (expand-file-name (file-name-nondirectory from) candidate))
1742 #'(lambda (from) candidate))
1743 marker)
1744 (when follow
1745 (let* ((src (car files))
1746 (dest (expand-file-name candidate))
1747 (basename-src (if (file-directory-p src)
1748 (file-relative-name
1749 (directory-file-name src)
1750 (file-name-directory src))
1751 (file-name-nondirectory src)))
1752 (fname (if (file-directory-p dest)
1753 (concat (file-name-as-directory dest)
1754 basename-src)
1755 dest)))
1756 (anything-c-point-file-in-dired fname)))))
1759 (defun* anything-dired-do-action-on-file (&key action)
1760 (let* ((files (dired-get-marked-files))
1761 (len (length files))
1762 (fname (if (> len 1)
1763 (format "* %d Files" len)
1764 (car files)))
1765 (source (case action
1766 ('copy 'anything-c-source-copy-files)
1767 ('rename 'anything-c-source-rename-files)
1768 ('symlink 'anything-c-source-symlink-files)
1769 ('hardlink 'anything-c-source-hardlink-files)))
1770 (prompt-fm (case action
1771 ('copy "Copy %s to: ")
1772 ('rename "Rename %s to: ")
1773 ('symlink "Symlink %s to: ")
1774 ('hardlink "Hardlink %s to: ")))
1775 (buffer (case action
1776 ('copy "*Anything Copy Files*")
1777 ('rename "*Anything Rename Files*")
1778 ('symlink "*Anything Symlink Files*")
1779 ('hardlink "*Anything Hardlink Files*"))))
1780 (anything source
1781 (or (dired-dwim-target-directory)
1782 (expand-file-name default-directory))
1783 (format prompt-fm fname) nil nil buffer)))
1786 (defun anything-dired-rename-file ()
1787 "Preconfigured `anything' to rename files from dired."
1788 (interactive)
1789 (anything-dired-do-action-on-file :action 'rename))
1791 (defun anything-dired-copy-file ()
1792 "Preconfigured `anything' to copy files from dired."
1793 (interactive)
1794 (anything-dired-do-action-on-file :action 'copy))
1796 (defun anything-dired-symlink-file ()
1797 "Preconfigured `anything' to symlink files from dired."
1798 (interactive)
1799 (anything-dired-do-action-on-file :action 'symlink))
1801 (defun anything-dired-hardlink-file ()
1802 "Preconfigured `anything' to hardlink files from dired."
1803 (interactive)
1804 (anything-dired-do-action-on-file :action 'hardlink))
1806 (defvar anything-dired-bindings nil)
1807 (defun anything-dired-bindings (&optional arg)
1808 "Replace usual dired commands `C' and `R' by anything ones.
1809 When call interactively toggle dired bindings and anything bindings.
1810 When call non--interactively with arg > 0, enable anything bindings.
1811 You can put (anything-dired-binding 1) in init file to enable anything bindings."
1812 (interactive)
1813 (if (or (when arg (> arg 0)) (not anything-dired-bindings))
1814 (progn
1815 (define-key dired-mode-map (kbd "C") 'anything-dired-copy-file)
1816 (define-key dired-mode-map (kbd "R") 'anything-dired-rename-file)
1817 (define-key dired-mode-map (kbd "S") 'anything-dired-symlink-file)
1818 (define-key dired-mode-map (kbd "H") 'anything-dired-hardlink-file)
1819 (setq anything-dired-bindings t))
1820 (define-key dired-mode-map (kbd "C") 'dired-do-copy)
1821 (define-key dired-mode-map (kbd "R") 'dired-do-rename)
1822 (define-key dired-mode-map (kbd "S") 'dired-do-symlink)
1823 (define-key dired-mode-map (kbd "H") 'dired-do-hardlink)
1824 (setq anything-dired-bindings nil)))
1826 ;;; File Cache
1827 (defvar anything-c-source-file-cache-initialized nil)
1829 (defvar anything-c-file-cache-files nil)
1831 (defvar anything-c-source-file-cache
1832 '((name . "File Cache")
1833 (init . (lambda ()
1834 (require 'filecache nil t)
1835 (unless anything-c-source-file-cache-initialized
1836 (setq anything-c-file-cache-files
1837 (loop for item in file-cache-alist append
1838 (destructuring-bind (base &rest dirs) item
1839 (loop for dir in dirs collect
1840 (concat dir base)))))
1841 (defadvice file-cache-add-file (after file-cache-list activate)
1842 (add-to-list 'anything-c-file-cache-files (expand-file-name file)))
1843 (setq anything-c-source-file-cache-initialized t))))
1844 (candidates . anything-c-file-cache-files)
1845 (match anything-c-match-on-file-name
1846 anything-c-match-on-directory-name)
1847 (type . file)))
1848 ;; (anything 'anything-c-source-file-cache)
1850 ;;; Locate
1851 (defvar anything-c-locate-options
1852 (cond
1853 ((eq system-type 'darwin) '("locate"))
1854 ((eq system-type 'berkeley-unix) '("locate" "-i"))
1855 (t '("locate" "-i" "-r")))
1856 "A list where the `car' is the name of the locat program followed by options.
1857 The search pattern will be appended, so the
1858 \"-r\" option should be the last option.")
1860 (defvar anything-c-source-locate
1861 '((name . "Locate")
1862 (candidates . (lambda ()
1863 (apply 'start-process "locate-process" nil
1864 (append anything-c-locate-options
1865 (list anything-pattern)))))
1866 (type . file)
1867 (requires-pattern . 3)
1868 (delayed))
1869 "Source for retrieving files matching the current input pattern with locate.")
1870 ;; (anything 'anything-c-source-locate)
1872 ;;; Recentf files
1873 (defvar anything-c-source-recentf
1874 '((name . "Recentf")
1875 (init . (lambda ()
1876 (require 'recentf)
1877 (or recentf-mode (recentf-mode 1))
1878 ;; Big value empowers anything/recentf
1879 (when (and (numberp recentf-max-saved-items)
1880 (<= recentf-max-saved-items 20))
1881 (setq recentf-max-saved-items 500))))
1882 (candidates . recentf-list)
1883 (match anything-c-match-on-file-name
1884 anything-c-match-on-directory-name)
1885 (type . file))
1886 "See (info \"(emacs)File Conveniences\").
1887 if `recentf-max-saved-items' is too small, set it to 500.")
1888 ;; (anything 'anything-c-source-recentf)
1890 ;;; ffap
1891 (eval-when-compile (require 'ffap))
1892 (defvar anything-c-source-ffap-guesser
1893 '((name . "File at point")
1894 (init . (lambda () (require 'ffap)))
1895 (candidates . (lambda ()
1896 (anything-aif
1897 (with-current-buffer anything-current-buffer
1898 (ffap-guesser))
1899 (list it))))
1900 (type . file)))
1901 ;; (anything 'anything-c-source-ffap-guesser)
1903 ;;; ffap with line number
1904 (defun anything-c-ffap-file-line-at-point ()
1905 "Get (FILENAME . LINENO) at point."
1906 (anything-aif (let (ffap-alist) (ffap-file-at-point))
1907 (save-excursion
1908 (beginning-of-line)
1909 (when (and (search-forward it nil t)
1910 (looking-at ":\\([0-9]+\\)"))
1911 (cons it (string-to-number (match-string 1)))))))
1913 (defvar anything-c-ffap-line-location nil
1914 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
1915 It is cleared after jumping line.")
1917 (defun anything-c-ffap-line-candidates ()
1918 (with-current-buffer anything-current-buffer
1919 (setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
1920 (when anything-c-ffap-line-location
1921 (destructuring-bind (file . line) anything-c-ffap-line-location
1922 (list (cons (format "%s (line %d)" file line) file)))))
1924 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
1925 (defun anything-c-ffap-line-goto-line ()
1926 (when (car anything-c-ffap-line-location)
1927 (unwind-protect
1928 (ignore-errors
1929 (with-selected-window (get-buffer-window
1930 (get-file-buffer (car anything-c-ffap-line-location)))
1931 (anything-goto-line (cdr anything-c-ffap-line-location)))))))
1932 (add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
1933 (add-hook 'anything-after-persistent-action-hook 'anything-c-ffap-line-goto-line)
1935 (defvar anything-c-source-ffap-line
1936 '((name . "File/Lineno at point")
1937 (init . (lambda () (require 'ffap)))
1938 (candidates . anything-c-ffap-line-candidates)
1939 (type . file)))
1940 ;; (anything 'anything-c-source-ffap-line)
1942 ;;; list of files gleaned from every dired buffer
1943 (defun anything-c-files-in-all-dired-candidates ()
1944 (save-excursion
1945 (mapcan
1946 (lambda (dir)
1947 (cond ((listp dir) ;filelist
1948 dir)
1949 ((equal "" (file-name-nondirectory dir)) ;dir
1950 (directory-files dir t))
1951 (t ;wildcard
1952 (file-expand-wildcards dir t))))
1953 (delq nil
1954 (mapcar (lambda (buf)
1955 (set-buffer buf)
1956 (when (eq major-mode 'dired-mode)
1957 (if (consp dired-directory)
1958 (cdr dired-directory) ;filelist
1959 dired-directory))) ;dir or wildcard
1960 (buffer-list))))))
1961 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
1963 (defvar anything-c-source-files-in-all-dired
1964 '((name . "Files in all dired buffer.")
1965 (candidates . anything-c-files-in-all-dired-candidates)
1966 (type . file)))
1967 ;; (anything 'anything-c-source-files-in-all-dired)
1969 ;;;; <info>
1970 ;;; Info pages
1971 (defvar anything-c-info-pages nil
1972 "All info pages on system.
1973 Will be calculated the first time you invoke anything with this
1974 source.")
1976 (defvar anything-c-source-info-pages
1977 `((name . "Info Pages")
1978 (candidates . (lambda ()
1979 (if anything-c-info-pages
1980 anything-c-info-pages
1981 (setq anything-c-info-pages
1982 (save-window-excursion
1983 (save-excursion
1984 (require 'info)
1985 (Info-find-node "dir" "top")
1986 (goto-char (point-min))
1987 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
1988 topics)
1989 (while (re-search-forward info-topic-regexp nil t)
1990 (add-to-list 'topics (match-string-no-properties 1)))
1991 (goto-char (point-min))
1992 (Info-exit)
1993 topics)))))))
1994 (action . (("Show with Info" .(lambda (node-str)
1995 (info (replace-regexp-in-string "^[^:]+: "
1997 node-str))))))
1998 (requires-pattern . 2)))
1999 ;; (anything 'anything-c-source-info-pages)
2002 ;;; Use info-index plug-in. Note that `name' attribute is
2003 ;;; not needed but `anything-c-insert-summary' uses it.
2004 ;; Info Elisp
2005 (defvar anything-c-source-info-elisp
2006 '((name . "Info index: elisp")
2007 (info-index . "elisp")))
2008 ;; (anything 'anything-c-source-info-elisp)
2010 ;; Info-Common-Lisp
2011 (defvar anything-c-source-info-cl
2012 '((name . "Info index: cl")
2013 (info-index . "cl")))
2014 ;; (anything 'anything-c-source-info-cl)
2016 ;; Info Index org
2017 (defvar anything-c-source-info-org
2018 '((name . "Info index: org")
2019 (info-index . "org")))
2020 ;; (anything 'anything-c-source-info-org)
2022 ;; Info Index ratpoison
2023 (defvar anything-c-source-info-ratpoison
2024 '((name . "Info index: ratpoison")
2025 (info-index . "ratpoison")))
2026 ;; (anything 'anything-c-source-info-ratpoison)
2028 ;; Info Index zsh
2029 (defvar anything-c-source-info-zsh
2030 '((name . "Info index: zsh")
2031 (info-index . "zsh")))
2032 ;; (anything 'anything-c-source-info-zsh)
2034 ;; Info Index bash
2035 (defvar anything-c-source-info-bash
2036 '((name . "Info index: bash")
2037 (info-index . "bash")))
2038 ;; (anything 'anything-c-source-info-bash)
2040 ;; Info Index coreutils
2041 (defvar anything-c-source-info-coreutils
2042 '((name . "Info index: coreutils")
2043 (info-index . "coreutils")))
2044 ;; (anything 'anything-c-source-info-coreutils)
2046 ;; Info Index fileutils
2047 (defvar anything-c-source-info-fileutils
2048 '((name . "Info index: fileutils")
2049 (info-index . "fileutils")))
2050 ;; (anything 'anything-c-source-info-fileutils)
2052 ;; Info Index find
2053 (defvar anything-c-source-info-find
2054 '((name . "Info index: find")
2055 (info-index . "find")))
2056 ;; (anything 'anything-c-source-info-find)
2058 ;; Info Index sh-utils
2059 (defvar anything-c-source-info-sh-utils
2060 '((name . "Info index: sh-utils")
2061 (info-index . "sh-utils")))
2062 ;; (anything 'anything-c-source-info-sh-utils)
2064 ;; Info Index textutils
2065 (defvar anything-c-source-info-textutils
2066 '((name . "Info index: textutils")
2067 (info-index . "textutils")))
2068 ;; (anything 'anything-c-source-info-textutils)
2070 ;; Info Index libc
2071 (defvar anything-c-source-info-libc
2072 '((name . "Info index: libc")
2073 (info-index . "libc")))
2074 ;; (anything 'anything-c-source-info-libc)
2076 ;; Info Index make
2077 (defvar anything-c-source-info-make
2078 '((name . "Info index: make")
2079 (info-index . "make")))
2080 ;; (anything 'anything-c-source-info-make)
2082 ;; Info Index automake
2083 (defvar anything-c-source-info-automake
2084 '((name . "Info index: automake")
2085 (info-index . "automake")))
2086 ;; (anything 'anything-c-source-info-automake)
2088 ;; Info Index autoconf
2089 (defvar anything-c-source-info-autoconf
2090 '((name . "Info index: autoconf")
2091 (info-index . "autoconf")))
2092 ;; (anything 'anything-c-source-info-autoconf)
2094 ;; Info Index emacs-lisp-intro
2095 (defvar anything-c-source-info-emacs-lisp-intro
2096 '((name . "Info index: emacs-lisp-intro")
2097 (info-index . "emacs-lisp-intro")))
2098 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2100 ;; Info Index emacs
2101 (defvar anything-c-source-info-emacs
2102 '((name . "Info index: emacs")
2103 (info-index . "emacs")))
2104 ;; (anything 'anything-c-source-info-emacs)
2106 ;; Info Index elib
2107 (defvar anything-c-source-info-elib
2108 '((name . "Info index: elib")
2109 (info-index . "elib")))
2110 ;; (anything 'anything-c-source-info-elib)
2112 ;; Info Index eieio
2113 (defvar anything-c-source-info-eieio
2114 '((name . "Info index: eieio")
2115 (info-index . "eieio")))
2116 ;; (anything 'anything-c-source-info-eieio)
2118 ;; Info Index gauche-refe
2119 (defvar anything-c-source-info-gauche-refe
2120 '((name . "Info index: gauche")
2121 (info-index . "gauche-refe")))
2122 ;; (anything 'anything-c-source-info-gauche-refe)
2124 ;; Info Index guile
2125 (defvar anything-c-source-info-guile
2126 '((name . "Info index: guile")
2127 (info-index . "guile")))
2128 ;; (anything 'anything-c-source-info-guile)
2130 ;; Info Index guile-tut
2131 (defvar anything-c-source-info-guile-tut
2132 '((name . "Info index: guile-tut")
2133 (info-index . "guile-tut")))
2134 ;; (anything 'anything-c-source-info-guile-tut)
2136 ;; Info Index goops
2137 (defvar anything-c-source-info-goops
2138 '((name . "Info index: goops")
2139 (info-index . "goops")))
2140 ;; (anything 'anything-c-source-info-goops)
2142 ;; Info Index screen
2143 (defvar anything-c-source-info-screen
2144 '((name . "Info index: screen")
2145 (info-index . "screen")
2146 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2147 ;; (anything 'anything-c-source-info-screen)
2149 ;; Info Index latex
2150 (defvar anything-c-source-info-latex
2151 '((name . "Info index: latex")
2152 (info-index . "latex")))
2153 ;; (anything 'anything-c-source-info-latex)
2155 ;; Info Index gawk
2156 (defvar anything-c-source-info-gawk
2157 '((name . "Info index: gawk")
2158 (info-index . "gawk")))
2159 ;; (anything 'anything-c-source-info-gawk)
2161 ;; Info Index sed
2162 (defvar anything-c-source-info-sed
2163 '((name . "Info index: sed")
2164 (info-index . "sed")))
2165 ;; (anything 'anything-c-source-info-sed)
2167 ;; Info Index m4
2168 (defvar anything-c-source-info-m4
2169 '((name . "Info index: m4")
2170 (info-index . "m4")))
2171 ;; (anything 'anything-c-source-info-m4)
2173 ;; Info Index wget
2174 (defvar anything-c-source-info-wget
2175 '((name . "Info index: wget")
2176 (info-index . "wget")))
2177 ;; (anything 'anything-c-source-info-wget)
2179 ;; Info Index binutils
2180 (defvar anything-c-source-info-binutils
2181 '((name . "Info index: binutils")
2182 (info-index . "binutils")))
2183 ;; (anything 'anything-c-source-info-binutils)
2185 ;; Info Index as
2186 (defvar anything-c-source-info-as
2187 '((name . "Info index: as")
2188 (info-index . "as")))
2189 ;; (anything 'anything-c-source-info-as)
2191 ;; Info Index bfd
2192 (defvar anything-c-source-info-bfd
2193 '((name . "Info index: bfd")
2194 (info-index . "bfd")))
2195 ;; (anything 'anything-c-source-info-bfd)
2197 ;; Info Index gprof
2198 (defvar anything-c-source-info-gprof
2199 '((name . "Info index: gprof")
2200 (info-index . "gprof")))
2201 ;; (anything 'anything-c-source-info-gprof)
2203 ;; Info Index ld
2204 (defvar anything-c-source-info-ld
2205 '((name . "Info index: ld")
2206 (info-index . "ld")))
2207 ;; (anything 'anything-c-source-info-ld)
2209 ;; Info Index diff
2210 (defvar anything-c-source-info-diff
2211 '((name . "Info index: diff")
2212 (info-index . "diff")))
2213 ;; (anything 'anything-c-source-info-diff)
2215 ;; Info Index flex
2216 (defvar anything-c-source-info-flex
2217 '((name . "Info index: flex")
2218 (info-index . "flex")))
2219 ;; (anything 'anything-c-source-info-flex)
2221 ;; Info Index grep
2222 (defvar anything-c-source-info-grep
2223 '((name . "Info index: grep")
2224 (info-index . "grep")))
2225 ;; (anything 'anything-c-source-info-grep)
2227 ;; Info Index gzip
2228 (defvar anything-c-source-info-gzip
2229 '((name . "Info index: gzip")
2230 (info-index . "gzip")))
2231 ;; (anything 'anything-c-source-info-gzip)
2233 ;; Info Index libtool
2234 (defvar anything-c-source-info-libtool
2235 '((name . "Info index: libtool")
2236 (info-index . "libtool")))
2237 ;; (anything 'anything-c-source-info-libtool)
2239 ;; Info Index texinfo
2240 (defvar anything-c-source-info-texinfo
2241 '((name . "Info index: texinfo")
2242 (info-index . "texinfo")))
2243 ;; (anything 'anything-c-source-info-texinfo)
2245 ;; Info Index info
2246 (defvar anything-c-source-info-info
2247 '((name . "Info index: info")
2248 (info-index . "info")))
2249 ;; (anything 'anything-c-source-info-info)
2251 ;; Info Index gdb
2252 (defvar anything-c-source-info-gdb
2253 '((name . "Info index: gdb")
2254 (info-index . "gdb")))
2255 ;; (anything 'anything-c-source-info-gdb)
2257 ;; Info Index stabs
2258 (defvar anything-c-source-info-stabs
2259 '((name . "Info index: stabs")
2260 (info-index . "stabs")))
2261 ;; (anything 'anything-c-source-info-stabs)
2263 ;; Info Index cvsbook
2264 (defvar anything-c-source-info-cvsbook
2265 '((name . "Info index: cvsbook")
2266 (info-index . "cvsbook")))
2267 ;; (anything 'anything-c-source-info-cvsbook)
2269 ;; Info Index cvs
2270 (defvar anything-c-source-info-cvs
2271 '((name . "Info index: cvs")
2272 (info-index . "cvs")))
2273 ;; (anything 'anything-c-source-info-cvs)
2275 ;; Info Index bison
2276 (defvar anything-c-source-info-bison
2277 '((name . "Info index: bison")
2278 (info-index . "bison")))
2279 ;; (anything 'anything-c-source-info-bison)
2281 ;; Info Index id-utils
2282 (defvar anything-c-source-info-id-utils
2283 '((name . "Info index: id-utils")
2284 (info-index . "id-utils")))
2285 ;; (anything 'anything-c-source-info-id-utils)
2287 ;; Info Index global
2288 (defvar anything-c-source-info-global
2289 '((name . "Info index: global")
2290 (info-index . "global")))
2291 ;; (anything 'anything-c-source-info-global)
2293 ;;;; <Help>
2294 ;;; Man Pages
2295 (defvar anything-c-man-pages nil
2296 "All man pages on system.
2297 Will be calculated the first time you invoke anything with this
2298 source.")
2300 (defvar anything-c-source-man-pages
2301 `((name . "Manual Pages")
2302 (candidates . (lambda ()
2303 (if anything-c-man-pages
2304 anything-c-man-pages
2305 ;; XEmacs doesn't have a woman :)
2306 (setq anything-c-man-pages
2307 (ignore-errors
2308 (require 'woman)
2309 (woman-file-name "")
2310 (sort (mapcar 'car woman-topic-all-completions)
2311 'string-lessp))))))
2312 (action ("Show with Woman" . woman))
2313 ;; Woman does not work OS X
2314 ;; http://xahlee.org/emacs/modernization_man_page.html
2315 (action-transformer . (lambda (actions candidate)
2316 (if (eq system-type 'darwin)
2317 '(("Show with Man" . man))
2318 actions)))
2319 (requires-pattern . 2)))
2320 ;; (anything 'anything-c-source-man-pages)
2322 ;;;; <Command>
2323 ;;; Complex command history
2324 (defvar anything-c-source-complex-command-history
2325 '((name . "Complex Command History")
2326 (candidates . (lambda () (mapcar 'prin1-to-string command-history)))
2327 (type . sexp)))
2328 ;; (anything 'anything-c-source-complex-command-history)
2330 ;;; M-x history
2331 (defvar anything-c-source-extended-command-history
2332 '((name . "Emacs Commands History")
2333 (candidates . extended-command-history)
2334 (type . command)))
2335 ;; (anything 'anything-c-source-extended-command-history)
2337 ;;; Emacs commands
2338 (defvar anything-c-source-emacs-commands
2339 '((name . "Emacs Commands")
2340 (candidates . (lambda ()
2341 (let (commands)
2342 (mapatoms (lambda (a)
2343 (if (commandp a)
2344 (push (symbol-name a)
2345 commands))))
2346 (sort commands 'string-lessp))))
2347 (type . command)
2348 (requires-pattern . 2))
2349 "Source for completing and invoking Emacs commands.
2350 A command is a function with interactive spec that can
2351 be invoked with `M-x'.
2353 To get non-interactive functions listed, use
2354 `anything-c-source-emacs-functions'.")
2355 ;; (anything 'anything-c-source-emacs-commands)
2357 ;;; LaCarte
2358 (defvar anything-c-source-lacarte
2359 '((name . "Lacarte")
2360 (init . (lambda () (require 'lacarte )))
2361 (candidates . (lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2362 (candidate-number-limit . 9999)
2363 (action . anything-c-call-interactively))
2364 "Needs lacarte.el.
2366 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2367 ;; (anything 'anything-c-source-lacarte)
2369 ;;;; <Function>
2370 ;;; Emacs functions
2371 (defvar anything-c-source-emacs-functions
2372 '((name . "Emacs Functions")
2373 (candidates . (lambda ()
2374 (let (commands)
2375 (mapatoms (lambda (a) (if (functionp a)
2376 (push (symbol-name a) commands))))
2377 (sort commands 'string-lessp))))
2378 (type . function)
2379 (requires-pattern . 2))
2380 "Source for completing Emacs functions.")
2381 ;; (anything 'anything-c-source-emacs-functions)
2383 ;;; With abbrev expansion
2384 ;;; Similar to my exec-abbrev-cmd.el
2385 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2386 (defvar anything-c-function-abbrev-regexp nil
2387 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2388 Regexp built from the current `anything-pattern' interpreting it
2389 as abbreviation.
2390 Only for internal use.")
2392 (defun anything-c-match-function-by-abbrev (candidate)
2393 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2395 Abbreviations are made by taking the first character from each
2396 word in the function's name, e.g. \"bb\" is an abbrev for
2397 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2398 (string-match anything-c-function-abbrev-regexp candidate))
2400 (defvar anything-c-source-emacs-functions-with-abbrevs
2401 (append anything-c-source-emacs-functions
2402 '((match anything-c-match-function-by-abbrev
2403 anything-c-string-match))
2404 '((init . (lambda ()
2405 (defadvice anything-update
2406 (before anything-c-update-function-abbrev-regexp activate)
2407 (let ((char-list (append anything-pattern nil))
2408 (str "^"))
2409 (dolist (c char-list)
2410 (setq str (concat str (list c) "[^-]*-")))
2411 (setq str (concat (substring str 0 (1- (length str))) "$"))
2412 (setq anything-c-function-abbrev-regexp str))))))))
2413 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2415 ;;;; <Variable>
2416 ;;; Emacs variables
2417 (defvar anything-c-source-emacs-variables
2418 '((name . "Emacs Variables")
2419 (candidates . (lambda ()
2420 (sort (all-completions "" obarray 'boundp) 'string-lessp)))
2421 (type . variable)
2422 (requires-pattern . 2))
2423 "Source for completing Emacs variables.")
2424 ;; (anything 'anything-c-source-emacs-variables)
2426 ;;;; <Bookmark>
2427 ;;; Bookmarks
2428 (eval-when-compile (require 'bookmark))
2429 (defvar anything-c-source-bookmarks
2430 '((name . "Bookmarks")
2431 (init . (lambda ()
2432 (require 'bookmark)))
2433 (candidates . bookmark-all-names)
2434 (type . bookmark))
2435 "See (info \"(emacs)Bookmarks\").")
2436 ;; (anything 'anything-c-source-bookmarks)
2438 ;;; bookmark-set
2439 (defvar anything-c-source-bookmark-set
2440 '((name . "Set Bookmark")
2441 (dummy)
2442 (action . bookmark-set))
2443 "See (info \"(emacs)Bookmarks\").")
2444 ;; (anything 'anything-c-source-bookmark-set)
2446 ;;; Visible Bookmarks
2447 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2450 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2451 (defvar anything-c-source-bm
2452 '((name . "Visible Bookmarks")
2453 (init . anything-c-bm-init)
2454 (candidates-in-buffer)
2455 (type . line))
2456 "Needs bm.el.
2458 http://www.nongnu.org/bm/")
2460 (defun anything-c-bm-init ()
2461 "Init function for `anything-c-source-bm'."
2462 (when (require 'bm nil t)
2463 (with-no-warnings
2464 (let ((bookmarks (bm-lists))
2465 (buf (anything-candidate-buffer 'global)))
2466 (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks))
2467 '< :key 'overlay-start))
2468 (let ((start (overlay-start bm))
2469 (end (overlay-end bm))
2470 (annotation (or (overlay-get bm 'annotation) "")))
2471 (unless (< (- end start) 1) ; org => (if (< (- end start) 2)
2472 (let ((str (format "%7d: [%s]: %s\n"
2473 (line-number-at-pos start)
2474 annotation
2475 (buffer-substring start (1- end)))))
2476 (with-current-buffer buf (insert str))))))))))
2478 ;;; Special bookmarks
2479 (defvar anything-c-source-bookmarks-ssh
2480 '((name . "Bookmarks-ssh")
2481 (init . (lambda ()
2482 (require 'bookmark)))
2483 ;; DRY
2484 (candidates . (lambda ()
2485 (let (lis-all lis-ssh)
2486 (setq lis-all (bookmark-all-names))
2487 (setq lis-ssh (loop for i in lis-all
2488 if (string-match "^(ssh)" i)
2489 collect i))
2490 (sort lis-ssh 'string-lessp))))
2491 (type . bookmark))
2492 "See (info \"(emacs)Bookmarks\").")
2493 ;; (anything 'anything-c-source-bookmarks-ssh)
2495 (defvar anything-c-source-bookmarks-su
2496 '((name . "Bookmarks-root")
2497 (init . (lambda ()
2498 (require 'bookmark)))
2499 ;; DRY
2500 (candidates . (lambda ()
2501 (let (lis-all lis-su)
2502 (setq lis-all (bookmark-all-names))
2503 (setq lis-su (loop for i in lis-all
2504 if (string-match (format "^(%s)" anything-su-or-sudo) i)
2505 collect i))
2506 (sort lis-su 'string-lessp))))
2507 (candidate-transformer anything-c-highlight-bookmark-su)
2509 (type . bookmark))
2510 "See (info \"(emacs)Bookmarks\").")
2511 ;; (anything 'anything-c-source-bookmarks-su)
2514 (defun tv-root-logged-p ()
2515 (catch 'break
2516 (dolist (i (mapcar #'buffer-name (buffer-list)))
2517 (when (string-match (format "*tramp/%s ." anything-su-or-sudo) i)
2518 (throw 'break t)))))
2521 (defun anything-c-highlight-bookmark-su (files)
2522 (if (tv-root-logged-p)
2523 (anything-c-highlight-bookmark files)
2524 (anything-c-highlight-not-logged files)))
2526 (defun anything-c-highlight-not-logged (files)
2527 (loop for i in files
2528 collect (propertize i 'face anything-c-bookmarks-face3)))
2530 (defun anything-c-highlight-bookmark (bookmarks)
2531 "Used as `candidate-transformer' to colorize bookmarks.
2532 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2533 (loop for i in bookmarks
2534 for pred = (bookmark-get-filename i)
2535 for bufp = (and (fboundp 'bmkext-get-buffer-name)
2536 (bmkext-get-buffer-name i))
2537 for regp = (and (fboundp 'bmkext-get-end-position)
2538 (bmkext-get-end-position i)
2539 (/= (bookmark-get-position i)
2540 (bmkext-get-end-position i)))
2541 for handlerp = (and (fboundp 'bookmark-get-handler)
2542 (bookmark-get-handler i))
2543 for isw3m = (and (fboundp 'bmkext-w3m-bookmark-p)
2544 (bmkext-w3m-bookmark-p i))
2545 for isgnus = (and (fboundp 'bmkext-gnus-bookmark-p)
2546 (bmkext-gnus-bookmark-p i))
2547 for isman = (and (fboundp 'bmkext-man-bookmark-p) ; Man
2548 (bmkext-man-bookmark-p i))
2549 for iswoman = (and (fboundp 'bmkext-woman-bookmark-p) ; Woman
2550 (bmkext-woman-bookmark-p i))
2551 for handlerp = (bookmark-get-handler i)
2552 for isannotation = (bookmark-get-annotation i)
2553 ;; Add a * if bookmark have annotation
2554 if (and isannotation (not (string-equal isannotation "")))
2555 do (setq i (concat "*" i))
2556 ;; info buffers
2557 if (eq handlerp 'Info-bookmark-jump)
2558 collect (propertize i 'face 'anything-bmkext-info 'help-echo pred)
2559 ;; w3m buffers
2560 if isw3m
2561 collect (propertize i 'face 'anything-bmkext-w3m 'help-echo pred)
2562 ;; gnus buffers
2563 if isgnus
2564 collect (propertize i 'face 'anything-bmkext-gnus 'help-echo pred)
2565 ;; Man Woman
2566 if (or iswoman isman)
2567 collect (propertize i 'face 'anything-bmkext-man 'help-echo pred)
2568 ;; directories
2569 if (and pred (file-directory-p pred))
2570 collect (propertize i 'face anything-c-bookmarks-face1 'help-echo pred)
2571 ;; regular files with regions saved
2572 if (and pred (not (file-directory-p pred)) (file-exists-p pred) regp)
2573 collect (propertize i 'face 'anything-bmkext-region 'help-echo pred)
2574 ;; regular files
2575 if (and pred (not (file-directory-p pred)) (file-exists-p pred)
2576 (not regp) (not (or iswoman isman)))
2577 collect (propertize i 'face 'anything-bmkext-file 'help-echo pred)
2578 ;; buffer non--filename
2579 if (and (fboundp 'bmkext-get-buffer-name) bufp (not handlerp)
2580 (if pred (not (file-exists-p pred)) (not pred)))
2581 collect (propertize i 'face 'anything-bmkext-no--file)))
2583 ;;; Faces for bookmarks
2584 (defface anything-bmkext-info
2585 '((t (:foreground "green")))
2586 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2587 :group 'anything)
2589 (defface anything-bmkext-w3m
2590 '((t (:foreground "yellow")))
2591 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2592 :group 'anything)
2594 (defface anything-bmkext-gnus
2595 '((t (:foreground "magenta")))
2596 "*Face used for Gnus bookmarks."
2597 :group 'anything)
2599 (defface anything-bmkext-man
2600 '((t (:foreground "Orange4")))
2601 "*Face used for Woman/man bookmarks."
2602 :group 'anything)
2604 (defface anything-bmkext-region
2605 '((t (:foreground "Indianred2")))
2606 "*Face used for region bookmarks."
2607 :group 'anything)
2609 (defface anything-bmkext-no--file
2610 '((t (:foreground "grey")))
2611 "*Face used for non--file bookmarks."
2612 :group 'anything)
2614 (defface anything-bmkext-file
2615 '((t (:foreground "Deepskyblue2")))
2616 "*Face used for non--file bookmarks."
2617 :group 'anything)
2619 (defface anything-bookmarks-su-face '((t (:foreground "red")))
2620 "Face for su/sudo bookmarks."
2621 :group 'anything)
2623 (defvar anything-c-bookmarks-face1 'anything-dir-heading)
2624 (defvar anything-c-bookmarks-face2 'anything-file-name)
2625 (defvar anything-c-bookmarks-face3 'anything-bookmarks-su-face)
2627 (defvar anything-c-source-bookmarks-local
2628 '((name . "Bookmarks-Local")
2629 (init . (lambda ()
2630 (require 'bookmark)))
2631 ;; DRY
2632 (candidates . (lambda ()
2633 (let (lis-all lis-loc)
2634 (setq lis-all (bookmark-all-names))
2635 (setq lis-loc (loop for i in lis-all
2636 if (and (not (string-match "^(ssh)" i))
2637 (not (string-match "^(su)" i)))
2638 collect i))
2639 (sort lis-loc 'string-lessp))))
2640 (candidate-transformer anything-c-highlight-bookmark)
2641 (type . bookmark))
2642 "See (info \"(emacs)Bookmarks\").")
2643 ;; (anything 'anything-c-source-bookmarks-local)
2645 ;;; Sources to filter bookmark-extensions bookmarks.
2646 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
2649 (defun anything-c-bmkext-filter-setup-alist (fn &rest args)
2650 "Return a filtered `bookmark-alist' sorted alphabetically."
2651 (loop
2652 with alist = (if args
2653 (apply #'(lambda (x) (funcall fn x)) args)
2654 (funcall fn))
2655 for i in alist
2656 for b = (car i)
2657 collect b into sa
2658 finally return (sort sa 'string-lessp)))
2660 ;; Regions
2661 (defvar anything-c-source-bookmark-regions
2662 '((name . "Bookmark Regions")
2663 (init . (lambda ()
2664 (require 'bookmark-extensions)
2665 (bookmark-maybe-load-default-file)))
2666 (candidates . anything-c-bookmark-region-setup-alist)
2667 (candidate-transformer anything-c-highlight-bookmark)
2668 (filtered-candidate-transformer . anything-c-adaptive-sort)
2669 (type . bookmark)))
2670 ;; (anything 'anything-c-source-bookmark-regions)
2672 (defun anything-c-bookmark-region-setup-alist ()
2673 "Specialized filter function for bookmarks regions."
2674 (anything-c-bmkext-filter-setup-alist 'bmkext-region-alist-only))
2676 ;; W3m
2677 (defvar anything-c-source-bookmark-w3m
2678 '((name . "Bookmark W3m")
2679 (init . (lambda ()
2680 (require 'bookmark-extensions)
2681 (bookmark-maybe-load-default-file)))
2682 (candidates . anything-c-bookmark-w3m-setup-alist)
2683 (candidate-transformer anything-c-highlight-bookmark)
2684 (filtered-candidate-transformer . anything-c-adaptive-sort)
2685 (type . bookmark)))
2686 ;; (anything 'anything-c-source-bookmark-w3m)
2688 (defun anything-c-bookmark-w3m-setup-alist ()
2689 "Specialized filter function for bookmarks w3m."
2690 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only))
2692 ;; Woman Man
2693 (defvar anything-c-source-bookmark-man
2694 '((name . "Bookmark Woman&Man")
2695 (init . (lambda ()
2696 (require 'bookmark-extensions)
2697 (bookmark-maybe-load-default-file)))
2698 (candidates . anything-c-bookmark-man-setup-alist)
2699 (candidate-transformer anything-c-highlight-bookmark)
2700 (filtered-candidate-transformer . anything-c-adaptive-sort)
2701 (type . bookmark)))
2702 ;; (anything 'anything-c-source-bookmark-man)
2704 (defun anything-c-bookmark-man-setup-alist ()
2705 "Specialized filter function for bookmarks w3m."
2706 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only)
2707 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only)))
2709 ;; Gnus
2710 (defvar anything-c-source-bookmark-gnus
2711 '((name . "Bookmark Gnus")
2712 (init . (lambda ()
2713 (require 'bookmark-extensions)
2714 (bookmark-maybe-load-default-file)))
2715 (candidates . anything-c-bookmark-gnus-setup-alist)
2716 (candidate-transformer anything-c-highlight-bookmark)
2717 (filtered-candidate-transformer . anything-c-adaptive-sort)
2718 (type . bookmark)))
2719 ;; (anything 'anything-c-source-bookmark-gnus)
2721 (defun anything-c-bookmark-gnus-setup-alist ()
2722 "Specialized filter function for bookmarks gnus."
2723 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only))
2725 ;; Info
2726 (defvar anything-c-source-bookmark-info
2727 '((name . "Bookmark Info")
2728 (init . (lambda ()
2729 (require 'bookmark-extensions)
2730 (bookmark-maybe-load-default-file)))
2731 (candidates . anything-c-bookmark-info-setup-alist)
2732 (candidate-transformer anything-c-highlight-bookmark)
2733 (filtered-candidate-transformer . anything-c-adaptive-sort)
2734 (type . bookmark)))
2735 ;; (anything 'anything-c-source-bookmark-info)
2737 (defun anything-c-bookmark-info-setup-alist ()
2738 "Specialized filter function for bookmarks info."
2739 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only))
2741 ;; Local Files&directories
2742 (defvar anything-c-source-bookmark-files&dirs
2743 '((name . "Bookmark Files&Directories")
2744 (init . (lambda ()
2745 (require 'bookmark-extensions)
2746 (bookmark-maybe-load-default-file)))
2747 (candidates . anything-c-bookmark-local-files-setup-alist)
2748 (candidate-transformer anything-c-highlight-bookmark)
2749 (filtered-candidate-transformer . anything-c-adaptive-sort)
2750 (type . bookmark)))
2751 ;; (anything 'anything-c-source-bookmark-files&dirs)
2753 (defun anything-c-bookmark-local-files-setup-alist ()
2754 "Specialized filter function for bookmarks locals files."
2755 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only))
2757 ;; Su Files&directories
2758 (defun anything-c-highlight-bmkext-su (bmk)
2759 (if (bmkext-root-or-sudo-logged-p)
2760 (anything-c-highlight-bookmark bmk)
2761 (anything-c-highlight-not-logged bmk)))
2763 (defvar anything-c-source-bookmark-su-files&dirs
2764 '((name . "Bookmark Root-Files&Directories")
2765 (init . (lambda ()
2766 (require 'bookmark-extensions)
2767 (bookmark-maybe-load-default-file)))
2768 (candidates . anything-c-bookmark-su-files-setup-alist)
2769 (candidate-transformer anything-c-highlight-bmkext-su)
2770 (filtered-candidate-transformer . anything-c-adaptive-sort)
2771 (type . bookmark)))
2772 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
2774 (defun anything-c-bookmark-su-files-setup-alist ()
2775 "Specialized filter function for bookmarks su/sudo files."
2776 (loop
2777 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
2778 for i in l
2779 for isfile = (bookmark-get-filename i)
2780 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
2781 (save-match-data
2782 (string-match tramp-file-name-regexp isfile)))
2783 for issu = (and istramp
2784 (string-match bmkext-su-or-sudo-regexp isfile))
2785 if issu
2786 collect i))
2788 ;; Ssh Files&directories
2789 (defvar anything-c-source-bookmark-ssh-files&dirs
2790 '((name . "Bookmark Ssh-Files&Directories")
2791 (init . (lambda ()
2792 (require 'bookmark-extensions)
2793 (bookmark-maybe-load-default-file)))
2794 (candidates . anything-c-bookmark-ssh-files-setup-alist)
2795 (filtered-candidate-transformer . anything-c-adaptive-sort)
2796 (type . bookmark)))
2797 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
2799 (defun anything-c-bookmark-ssh-files-setup-alist ()
2800 "Specialized filter function for bookmarks ssh files."
2801 (loop
2802 with l = (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only)
2803 for i in l
2804 for isfile = (bookmark-get-filename i)
2805 for istramp = (and isfile (boundp 'tramp-file-name-regexp)
2806 (save-match-data
2807 (string-match tramp-file-name-regexp isfile)))
2808 for isssh = (and istramp
2809 (string-match "/ssh:" isfile))
2810 if isssh
2811 collect i))
2814 ;; All bookmark-extensions sources.
2815 (defun anything-bookmark-ext ()
2816 "Preconfigured `anything' for bookmark-extensions sources.
2817 See: <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>."
2818 (interactive)
2819 (anything '(anything-c-source-bookmark-files&dirs
2820 anything-c-source-bookmark-w3m
2821 anything-c-source-bookmark-gnus
2822 anything-c-source-bookmark-info
2823 anything-c-source-bookmark-man
2824 anything-c-source-bookmark-regions
2825 anything-c-source-bookmark-su-files&dirs
2826 anything-c-source-bookmark-ssh-files&dirs)))
2829 ;; Firefox bookmarks
2830 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
2831 ;; (only for firefox versions >=3)
2832 ;; To achieve that, open about:config in firefox and double click on this line to enable value
2833 ;; to true:
2834 ;; user_pref("browser.bookmarks.autoExportHTML", false);
2835 ;; You should have now:
2836 ;; user_pref("browser.bookmarks.autoExportHTML", true);
2838 (defvar anything-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
2839 (defvar anything-firefox-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
2841 (defun anything-get-firefox-user-init-dir ()
2842 "Guess the default Firefox user directory name."
2843 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
2844 (moz-user-dir (with-current-buffer (find-file-noselect (concat moz-dir "profiles.ini"))
2845 (goto-char (point-min))
2846 (when (search-forward "Path=" nil t)
2847 (buffer-substring-no-properties (point) (point-at-eol))))))
2848 (file-name-as-directory (concat moz-dir moz-user-dir))))
2850 (defun anything-guess-firefox-bookmark-file ()
2851 "Return the path of the Firefox bookmarks file."
2852 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
2854 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp)
2855 "Parse html bookmark FILE and return an alist with (title . url) as elements."
2856 (let (bookmarks-alist url title)
2857 (with-temp-buffer
2858 (insert-file-contents file)
2859 (goto-char (point-min))
2860 (while (not (eobp))
2861 (forward-line)
2862 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t)
2863 (beginning-of-line)
2864 (when (re-search-forward url-regexp nil t)
2865 (setq url (concat "\"" (match-string 0))))
2866 (beginning-of-line)
2867 (when (re-search-forward bmk-regexp nil t)
2868 (setq title (match-string 1)))
2869 (push (cons title url) bookmarks-alist))))
2870 (nreverse bookmarks-alist)))
2873 (defvar anything-c-firefox-bookmarks-alist nil)
2874 (defvar anything-c-source-firefox-bookmarks
2875 '((name . "Firefox Bookmarks")
2876 (init . (lambda ()
2877 (setq anything-c-firefox-bookmarks-alist
2878 (anything-html-bookmarks-to-alist
2879 (anything-guess-firefox-bookmark-file)
2880 anything-firefox-bookmark-url-regexp
2881 anything-firefox-bookmarks-regexp))))
2882 (candidates . (lambda ()
2883 (mapcar #'car
2884 anything-c-firefox-bookmarks-alist)))
2885 (candidate-transformer anything-c-highlight-firefox-bookmarks)
2886 (filtered-candidate-transformer . anything-c-adaptive-sort)
2887 (action . (("Browse Url" . (lambda (candidate)
2888 (w3m-browse-url
2889 (anything-c-firefox-bookmarks-get-value candidate))))
2890 ("Browse Url Firefox" . (lambda (candidate)
2891 (browse-url-firefox
2892 (anything-c-firefox-bookmarks-get-value candidate))))
2893 ("Copy Url" . (lambda (elm)
2894 (kill-new (anything-c-w3m-bookmarks-get-value elm))))))))
2896 ;; (anything 'anything-c-source-firefox-bookmarks)
2898 (defun anything-c-firefox-bookmarks-get-value (elm)
2899 (replace-regexp-in-string "\"" ""
2900 (cdr (assoc elm
2901 anything-c-firefox-bookmarks-alist))))
2904 (defun anything-c-highlight-firefox-bookmarks (books)
2905 (loop for i in books
2906 collect (propertize i
2907 'face '((:foreground "YellowGreen"))
2908 'help-echo (anything-c-firefox-bookmarks-get-value i))))
2910 ;; W3m bookmark
2911 (eval-when-compile (require 'w3m-bookmark nil t))
2912 (unless (and (require 'w3m nil t)
2913 (require 'w3m-bookmark nil t))
2914 (defvar w3m-bookmark-file "~/.w3m/bookmark.html"))
2917 (defface anything-w3m-bookmarks-face '((t (:foreground "cyan1" :underline t)))
2918 "Face for w3m bookmarks" :group 'anything)
2920 (defvar anything-w3m-bookmarks-regexp ">\\([^><]+.[^</a>]\\)")
2921 (defvar anything-w3m-bookmark-url-regexp "\\(https\\|http\\|ftp\\|file\\)://[^>]*")
2922 (defvar anything-c-w3m-bookmarks-alist nil)
2923 (defvar anything-c-source-w3m-bookmarks
2924 '((name . "W3m Bookmarks")
2925 (init . (lambda ()
2926 (setq anything-c-w3m-bookmarks-alist
2927 (anything-html-bookmarks-to-alist
2928 w3m-bookmark-file
2929 anything-w3m-bookmark-url-regexp
2930 anything-w3m-bookmarks-regexp))))
2931 (candidates . (lambda ()
2932 (mapcar #'car anything-c-w3m-bookmarks-alist)))
2933 (candidate-transformer anything-c-highlight-w3m-bookmarks)
2934 (filtered-candidate-transformer . anything-c-adaptive-sort)
2935 (action . (("Browse Url" . (lambda (candidate)
2936 (anything-c-w3m-browse-bookmark candidate)))
2937 ("Copy Url" . (lambda (elm)
2938 (kill-new (anything-c-w3m-bookmarks-get-value elm))))
2939 ("Browse Url Firefox" . (lambda (candidate)
2940 (anything-c-w3m-browse-bookmark candidate t)))
2941 ("Delete Bookmark" . (lambda (candidate)
2942 (anything-c-w3m-delete-bookmark candidate)))
2943 ("Rename Bookmark" . (lambda (candidate)
2944 (anything-c-w3m-rename-bookmark candidate)))))
2945 (persistent-action . (lambda (candidate)
2946 (if current-prefix-arg
2947 (anything-c-w3m-browse-bookmark candidate t)
2948 (anything-c-w3m-browse-bookmark candidate nil t))))
2949 (persistent-help . "Open URL with emacs-w3m in new tab / \
2950 C-u \\[anything-execute-persistent-action]: Open URL with Firefox")))
2952 ;; (anything 'anything-c-source-w3m-bookmarks)
2954 (defun anything-c-w3m-bookmarks-get-value (elm)
2955 (replace-regexp-in-string
2956 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist))))
2958 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab)
2959 (let* ((fn (if use-firefox 'browse-url-firefox 'w3m-browse-url))
2960 (arg (and (eq fn 'w3m-browse-url) new-tab)))
2961 (funcall fn (anything-c-w3m-bookmarks-get-value elm) arg)))
2963 (defun anything-c-highlight-w3m-bookmarks (books)
2964 (loop for i in books
2965 collect (propertize
2966 i 'face 'anything-w3m-bookmarks-face
2967 'help-echo (anything-c-w3m-bookmarks-get-value i))))
2970 (defun anything-c-w3m-delete-bookmark (elm)
2971 (save-excursion
2972 (find-file-literally w3m-bookmark-file)
2973 (goto-char (point-min))
2974 (when (re-search-forward elm nil t)
2975 (beginning-of-line)
2976 (delete-region (point)
2977 (line-end-position))
2978 (delete-blank-lines))
2979 (save-buffer (current-buffer))
2980 (kill-buffer (current-buffer))))
2982 (defun anything-c-w3m-rename-bookmark (elm)
2983 (let* ((old-title (replace-regexp-in-string ">" "" elm))
2984 (new-title (read-string "NewTitle: " old-title)))
2985 (save-excursion
2986 (find-file-literally w3m-bookmark-file)
2987 (goto-char (point-min))
2988 (when (re-search-forward (concat elm "<") nil t)
2989 (goto-char (1- (point)))
2990 (delete-backward-char (length old-title))
2991 (insert new-title))
2992 (save-buffer (current-buffer))
2993 (kill-buffer (current-buffer)))))
2995 ;;;; <Library>
2996 ;;; Elisp library scan
2997 (defvar anything-c-source-elisp-library-scan
2998 '((name . "Elisp libraries (Scan)")
2999 (init . (anything-c-elisp-library-scan-init))
3000 (candidates-in-buffer)
3001 (action ("Find library" . (lambda (candidate)
3002 (find-file (find-library-name candidate))))
3003 ("Find library other window" . (lambda (candidate)
3004 (find-file-other-window (find-library-name candidate))))
3005 ("Load library" . (lambda (candidate)
3006 (load-library candidate))))))
3007 ;; (anything 'anything-c-source-elisp-library-scan)
3009 (defun anything-c-elisp-library-scan-init ()
3010 "Init anything buffer status."
3011 (let ((anything-buffer (anything-candidate-buffer 'global))
3012 (library-list (anything-c-elisp-library-scan-list)))
3013 (with-current-buffer anything-buffer
3014 (dolist (library library-list)
3015 (insert (format "%s\n" library))))))
3017 (defun anything-c-elisp-library-scan-list (&optional dirs string)
3018 "Do completion for file names passed to `locate-file'.
3019 DIRS is directory to search path.
3020 STRING is string to match."
3021 ;; Use `load-path' as path when ignore `dirs'.
3022 (or dirs (setq dirs load-path))
3023 ;; Init with blank when ignore `string'.
3024 (or string (setq string ""))
3025 ;; Get library list.
3026 (let ((string-dir (file-name-directory string))
3027 ;; File regexp that suffix match `load-file-rep-suffixes'.
3028 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)))
3029 name
3030 names)
3031 (dolist (dir dirs)
3032 (unless dir
3033 (setq dir default-directory))
3034 (if string-dir
3035 (setq dir (expand-file-name string-dir dir)))
3036 (when (file-directory-p dir)
3037 (dolist (file (file-name-all-completions
3038 (file-name-nondirectory string) dir))
3039 ;; Suffixes match `load-file-rep-suffixes'.
3040 (setq name (if string-dir (concat string-dir file) file))
3041 (if (string-match match-regexp name)
3042 (add-to-list 'names name)))))
3043 names))
3045 ;;;; <Programming>
3046 ;;; Imenu
3047 (defvar anything-c-imenu-delimiter " / ")
3049 (defvar anything-c-imenu-index-filter nil)
3050 (make-variable-buffer-local 'anything-c-imenu-index-filter)
3052 (defvar anything-c-cached-imenu-alist nil)
3053 (make-variable-buffer-local 'anything-c-cached-imenu-alist)
3055 (defvar anything-c-cached-imenu-candidates nil)
3056 (make-variable-buffer-local 'anything-c-cached-imenu-candidates)
3058 (defvar anything-c-cached-imenu-tick nil)
3059 (make-variable-buffer-local 'anything-c-cached-imenu-tick)
3061 (eval-when-compile (require 'imenu))
3062 (setq imenu-auto-rescan t)
3064 (defun anything-imenu-create-candidates (entry)
3065 "Create candidates with ENTRY."
3066 (if (listp (cdr entry))
3067 (mapcan (lambda (sub)
3068 (if (consp (cdr sub))
3069 (mapcar
3070 (lambda (subentry)
3071 (concat (car entry) anything-c-imenu-delimiter subentry))
3072 (anything-imenu-create-candidates sub))
3073 (list (concat (car entry) anything-c-imenu-delimiter (car sub)))))
3074 (cdr entry))
3075 (list entry)))
3077 (defvar anything-c-source-imenu
3078 '((name . "Imenu")
3079 (candidates . anything-c-imenu-candidates)
3080 (persistent-action . (lambda (elm)
3081 (anything-c-imenu-default-action elm)
3082 (unless (fboundp 'semantic-imenu-tag-overlay)
3083 (anything-match-line-color-current-line))))
3084 (persistent-help . "Show this entry")
3085 (action . anything-c-imenu-default-action))
3086 "See (info \"(emacs)Imenu\")")
3088 ;; (anything 'anything-c-source-imenu)
3090 (defun anything-c-imenu-candidates ()
3091 (with-current-buffer anything-current-buffer
3092 (let ((tick (buffer-modified-tick)))
3093 (if (eq anything-c-cached-imenu-tick tick)
3094 anything-c-cached-imenu-candidates
3095 (setq imenu--index-alist nil)
3096 (setq anything-c-cached-imenu-tick tick
3097 anything-c-cached-imenu-candidates
3098 (condition-case nil
3099 (mapcan
3100 'anything-imenu-create-candidates
3101 (setq anything-c-cached-imenu-alist
3102 (let ((index (imenu--make-index-alist)))
3103 (if anything-c-imenu-index-filter
3104 (funcall anything-c-imenu-index-filter index)
3105 index))))
3106 (error nil)))
3107 (setq anything-c-cached-imenu-candidates
3108 (mapcar #'(lambda (x)
3109 (if (stringp x)
3111 (car x)))
3112 anything-c-cached-imenu-candidates))))))
3114 (setq imenu-default-goto-function 'imenu-default-goto-function)
3115 (defun anything-c-imenu-default-action (elm)
3116 "The default action for `anything-c-source-imenu'."
3117 (let ((path (split-string elm anything-c-imenu-delimiter))
3118 (alist anything-c-cached-imenu-alist))
3119 (if (> (length path) 1)
3120 (progn
3121 (setq alist (assoc (car path) alist))
3122 (setq elm (cadr path))
3123 (imenu (assoc elm alist)))
3124 (imenu (assoc elm alist)))))
3126 ;;; Ctags
3127 (defvar anything-c-ctags-modes
3128 '( c-mode c++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3129 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3130 scheme-mode sh-mode slang-mode sql-mode tcl-mode ))
3132 (defun anything-c-source-ctags-init ()
3133 (when (and buffer-file-name
3134 (memq major-mode anything-c-ctags-modes)
3135 (anything-current-buffer-is-modified))
3136 (with-current-buffer (anything-candidate-buffer 'local)
3137 (call-process-shell-command
3138 (if (string-match "\\.el\\.gz$" anything-buffer-file-name)
3139 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name)
3140 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name))
3141 nil (current-buffer))
3142 (goto-char (point-min))
3143 (forward-line 2)
3144 (delete-region (point-min) (point))
3145 (loop while (and (not (eobp)) (search-forward "\001" (point-at-eol) t))
3146 for lineno-start = (point)
3147 for lineno = (buffer-substring lineno-start (1- (search-forward "," (point-at-eol) t)))
3149 (beginning-of-line)
3150 (insert (format "%5s:" lineno))
3151 (search-forward "\177" (point-at-eol) t)
3152 (delete-region (1- (point)) (point-at-eol))
3153 (forward-line 1)))))
3155 (defvar anything-c-source-ctags
3156 '((name . "Exuberant ctags")
3157 (init . anything-c-source-ctags-init)
3158 (candidates-in-buffer)
3159 (adjust)
3160 (type . line))
3161 "Needs Exuberant Ctags.
3163 http://ctags.sourceforge.net/")
3164 ;; (anything 'anything-c-source-ctags)
3166 ;; Semantic
3167 (defvar anything-semantic-candidates nil)
3168 (eval-when-compile (require 'semantic nil t))
3169 (defun anything-semantic-construct-candidates (tags depth)
3170 (when (require 'semantic nil t)
3171 (apply 'append
3172 (mapcar (lambda (tag)
3173 (if (listp tag)
3174 (let ((type (semantic-tag-type tag))
3175 (class (semantic-tag-class tag)))
3176 (if (or (and (stringp type)
3177 (or (string= type "class")
3178 (string= type "namespace")))
3179 (eq class 'function)
3180 (eq class 'variable))
3181 (cons (cons (concat (make-string (* depth 2) ?\s)
3182 (semantic-format-tag-summarize tag nil t)) tag)
3183 (anything-semantic-construct-candidates (semantic-tag-components tag)
3184 (1+ depth)))))))
3185 tags))))
3187 (defun anything-semantic-default-action (candidate)
3188 (let ((tag (cdr (assoc candidate anything-semantic-candidates))))
3189 (semantic-go-to-tag tag)))
3191 (defvar anything-c-source-semantic
3192 '((name . "Semantic Tags")
3193 (init . (lambda ()
3194 (setq anything-semantic-candidates
3195 (condition-case nil
3196 (anything-semantic-construct-candidates (semantic-fetch-tags) 0)
3197 (error nil)))))
3198 (candidates . (lambda ()
3199 (if anything-semantic-candidates
3200 (mapcar 'car anything-semantic-candidates))))
3201 (persistent-action . (lambda (elm)
3202 (anything-semantic-default-action elm)
3203 (anything-match-line-color-current-line)))
3204 (persistent-help . "Show this entry")
3205 (action . anything-semantic-default-action)
3206 "Needs semantic in CEDET.
3208 http://cedet.sourceforge.net/semantic.shtml
3209 http://cedet.sourceforge.net/"))
3211 ;; (anything 'anything-c-source-semantic)
3213 ;;; Function is called by
3214 (defun anything-simple-call-tree ()
3215 "Preconfigured `anything' for simple-call-tree. List function relationships."
3216 (interactive)
3217 (anything-other-buffer
3218 '(anything-c-source-simple-call-tree-functions-callers
3219 anything-c-source-simple-call-tree-callers-functions)
3220 "*anything simple-call-tree*"))
3222 (defvar anything-c-source-simple-call-tree-functions-callers
3223 '((name . "Function is called by")
3224 (init . anything-c-simple-call-tree-functions-callers-init)
3225 (multiline)
3226 (candidates . anything-c-simple-call-tree-candidates)
3227 (persistent-action . anything-c-simple-call-tree-persistent-action)
3228 (persistent-help . "Show function definitions by rotation")
3229 (action ("Find definition selected by persistent-action" .
3230 anything-c-simple-call-tree-find-definition)))
3231 "Needs simple-call-tree.el.
3232 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3234 (defvar anything-c-simple-call-tree-tick nil)
3235 (make-variable-buffer-local 'anything-c-simple-call-tree-tick)
3236 (defun anything-c-simple-call-tree-analyze-maybe ()
3237 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick)
3238 (simple-call-tree-analyze)
3239 (setq anything-c-simple-call-tree-tick (buffer-chars-modified-tick))))
3241 (defun anything-c-simple-call-tree-init-base (function message)
3242 (require 'simple-call-tree)
3243 (with-no-warnings
3244 (when (anything-current-buffer-is-modified)
3245 (anything-c-simple-call-tree-analyze-maybe)
3246 (let ((list (funcall function simple-call-tree-alist)))
3247 (with-current-buffer (anything-candidate-buffer 'local)
3248 (dolist (entry list)
3249 (let ((funcs (concat " " (mapconcat #'identity (cdr entry) "\n "))))
3250 (insert (car entry) message
3251 (if (string= funcs " ")
3252 " no functions."
3253 funcs)
3254 "\n\n"))))))))
3256 (defun anything-c-simple-call-tree-functions-callers-init ()
3257 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert " is called by\n"))
3259 (defun anything-c-simple-call-tree-candidates ()
3260 (with-current-buffer (anything-candidate-buffer)
3261 (split-string (buffer-string) "\n\n")))
3263 (defvar anything-c-simple-call-tree-related-functions nil)
3264 (defvar anything-c-simple-call-tree-function-index 0)
3265 (defun anything-c-simple-call-tree-persistent-action (candidate)
3266 (unless (eq last-command 'anything-execute-persistent-action)
3267 (setq anything-c-simple-call-tree-related-functions
3268 (delete "no functions."
3269 (split-string
3270 (replace-regexp-in-string " \\| is called by\\| calls " "" candidate)
3271 "\n")))
3272 (setq anything-c-simple-call-tree-function-index -1))
3273 (incf anything-c-simple-call-tree-function-index)
3274 (anything-c-simple-call-tree-find-definition candidate))
3276 (defun anything-c-simple-call-tree-find-definition (candidate)
3277 (find-function (intern
3278 (nth (mod anything-c-simple-call-tree-function-index
3279 (length anything-c-simple-call-tree-related-functions))
3280 anything-c-simple-call-tree-related-functions))))
3282 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3284 ;;; Function calls
3285 (defvar anything-c-source-simple-call-tree-callers-functions
3286 '((name . "Function calls")
3287 (init . anything-c-simple-call-tree-callers-functions-init)
3288 (multiline)
3289 (candidates . anything-c-simple-call-tree-candidates)
3290 (persistent-action . anything-c-simple-call-tree-persistent-action)
3291 (persistent-help . "Show function definitions by rotation")
3292 (action ("Find definition selected by persistent-action" .
3293 anything-c-simple-call-tree-find-definition)))
3294 "Needs simple-call-tree.el.
3295 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3297 (defun anything-c-simple-call-tree-callers-functions-init ()
3298 (anything-c-simple-call-tree-init-base 'identity " calls \n"))
3300 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3302 ;;; Commands/Options with doc
3303 (defvar anything-c-auto-document-data nil)
3304 (make-variable-buffer-local 'anything-c-auto-document-data)
3305 (defvar anything-c-source-commands-and-options-in-file
3306 '((name . "Commands/Options in file")
3307 (header-name
3308 . (lambda (x) (format "Commands/Options in %s"
3309 (buffer-local-value 'buffer-file-name anything-current-buffer))))
3310 (candidates . anything-command-and-options-candidates)
3311 (multiline)
3312 (action . imenu))
3313 "List Commands and Options with doc. It needs auto-document.el .
3315 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3317 (eval-when-compile (require 'auto-document nil t))
3318 (defun anything-command-and-options-candidates ()
3319 (with-current-buffer anything-current-buffer
3320 (when (and (require 'auto-document nil t)
3321 (eq major-mode 'emacs-lisp-mode)
3322 (or (anything-current-buffer-is-modified)
3323 (not anything-c-auto-document-data)))
3324 (or imenu--index-alist (imenu--make-index-alist t))
3325 (setq anything-c-auto-document-data
3326 (destructuring-bind (commands options)
3327 (adoc-construct anything-current-buffer)
3328 (append
3329 (loop for (command . doc) in commands
3330 for cmdname = (symbol-name command)
3331 collect
3332 (cons (format "Command: %s\n %s"
3333 (propertize cmdname 'face font-lock-function-name-face)
3334 (adoc-first-line doc))
3335 (assoc cmdname imenu--index-alist)))
3336 (loop with var-alist = (cdr (assoc "Variables" imenu--index-alist))
3337 for (option doc default) in options
3338 for optname = (symbol-name option)
3339 collect
3340 (cons (format "Option: %s\n %s\n default = %s"
3341 (propertize optname 'face font-lock-variable-name-face)
3342 (adoc-first-line doc)
3343 (adoc-prin1-to-string default))
3344 (assoc optname
3345 var-alist)))))))
3346 anything-c-auto-document-data))
3348 ;; (anything 'anything-c-source-commands-and-options-in-file)
3350 ;;;; <Color and Face>
3351 ;;; Customize Face
3352 (defvar anything-c-source-customize-face
3353 '((name . "Customize Face")
3354 (init . (lambda ()
3355 (unless (anything-candidate-buffer)
3356 (save-window-excursion (list-faces-display))
3357 (anything-candidate-buffer (get-buffer "*Faces*")))))
3358 (candidates-in-buffer)
3359 (get-line . buffer-substring)
3360 (action . (lambda (line)
3361 (customize-face (intern (car (split-string line))))))
3362 (requires-pattern . 3))
3363 "See (info \"(emacs)Faces\")")
3364 ;; (anything 'anything-c-source-customize-face)
3366 ;; Color
3367 (defvar anything-c-source-colors
3368 '((name . "Colors")
3369 (init . (lambda () (unless (anything-candidate-buffer)
3370 (save-window-excursion (list-colors-display))
3371 (anything-candidate-buffer (get-buffer "*Colors*")))))
3372 (candidates-in-buffer)
3373 (get-line . buffer-substring)
3374 (action ("Copy Name" . (lambda (candidate)
3375 (kill-new (anything-c-colors-get-name candidate))))
3376 ("Copy RGB" . (lambda (candidate)
3377 (kill-new (anything-c-colors-get-rgb candidate))))
3378 ("Insert Name" . (lambda (candidate)
3379 (with-current-buffer anything-current-buffer
3380 (insert (anything-c-colors-get-name candidate)))))
3381 ("Insert RGB" . (lambda (candidate)
3382 (with-current-buffer anything-current-buffer
3383 (insert (anything-c-colors-get-rgb candidate))))))))
3384 ;; (anything 'anything-c-source-colors)
3386 (defun anything-c-colors-get-name (candidate)
3387 "Get color name."
3388 (replace-regexp-in-string
3389 " " ""
3390 (with-temp-buffer
3391 (insert (capitalize candidate))
3392 (goto-char (point-min))
3393 (search-forward-regexp "\\s-\\{2,\\}")
3394 (kill-line)
3395 (buffer-string))))
3397 (defun anything-c-colors-get-rgb (candidate)
3398 "Get color RGB."
3399 (replace-regexp-in-string
3400 " " ""
3401 (with-temp-buffer
3402 (insert (capitalize candidate))
3403 (goto-char (point-max))
3404 (search-backward-regexp "\\s-\\{2,\\}")
3405 (kill-region (point) (point-min))
3406 (buffer-string))))
3408 ;;;; <Search Engine>
3409 ;;; Tracker desktop search
3410 (defvar anything-c-source-tracker-search
3411 '((name . "Tracker Search")
3412 (candidates . (lambda ()
3413 (start-process "tracker-search-process" nil
3414 "tracker-search"
3415 anything-pattern)))
3416 (type . file)
3417 (requires-pattern . 3)
3418 (delayed))
3419 "Source for retrieving files matching the current input pattern
3420 with the tracker desktop search.")
3421 ;; (anything 'anything-c-source-tracker-search)
3423 ;;; Spotlight (MacOS X desktop search)
3424 (defvar anything-c-source-mac-spotlight
3425 '((name . "mdfind")
3426 (candidates . (lambda ()
3427 (start-process "mdfind-process" nil "mdfind" anything-pattern)))
3428 (type . file)
3429 (requires-pattern . 3)
3430 (delayed))
3431 "Source for retrieving files via Spotlight's command line
3432 utility mdfind.")
3433 ;; (anything 'anything-c-source-mac-spotlight)
3436 ;;;; <Kill ring>
3437 ;;; Kill ring
3438 (defvar anything-c-source-kill-ring
3439 '((name . "Kill Ring")
3440 (init . (lambda () (anything-attrset 'last-command last-command)))
3441 (candidates . (lambda ()
3442 (loop for kill in kill-ring
3443 unless (or (< (length kill) anything-kill-ring-threshold)
3444 (string-match "^[\\s\\t]+$" kill))
3445 collect kill)))
3446 (action . anything-c-kill-ring-action)
3447 (last-command)
3448 (migemo)
3449 (multiline))
3450 "Source for browse and insert contents of kill-ring.")
3452 (defun anything-c-kill-ring-action (str)
3453 "Insert STR in `kill-ring' and set STR to the head.
3454 If this action is executed just after `yank', replace with STR as yanked string."
3455 (setq kill-ring (delete str kill-ring))
3456 (if (not (eq (anything-attr 'last-command) 'yank))
3457 (insert-for-yank str)
3458 ;; from `yank-pop'
3459 (let ((inhibit-read-only t)
3460 (before (< (point) (mark t))))
3461 (if before
3462 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
3463 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
3464 (setq yank-undo-function nil)
3465 (set-marker (mark-marker) (point) (current-buffer))
3466 (insert-for-yank str)
3467 ;; Set the window start back where it was in the yank command,
3468 ;; if possible.
3469 (set-window-start (selected-window) yank-window-start t)
3470 (if before
3471 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3472 ;; It is cleaner to avoid activation, even though the command
3473 ;; loop would deactivate the mark because we inserted text.
3474 (goto-char (prog1 (mark t)
3475 (set-marker (mark-marker) (point) (current-buffer)))))))
3476 (kill-new str))
3478 ;; (anything 'anything-c-source-kill-ring)
3480 ;;;; <Mark ring>
3481 ;; DO NOT include these sources in `anything-sources' use
3482 ;; the commands `anything-mark-ring' and `anything-global-mark-ring' instead.
3484 (defun anything-c-source-mark-ring-candidates ()
3485 (flet ((get-marks (pos)
3486 (save-excursion
3487 (goto-char pos)
3488 (beginning-of-line)
3489 (let ((line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3490 (when (string= "" line)
3491 (setq line "<EMPTY LINE>"))
3492 (format "%7d: %s" (line-number-at-pos) line)))))
3493 (with-current-buffer anything-current-buffer
3494 (loop
3495 with marks = (cons (mark-marker) mark-ring)
3496 with recip = nil
3497 for i in marks
3498 for f = (get-marks i)
3499 if (not (member f recip))
3501 (push f recip)
3502 finally (return (reverse recip))))))
3504 (defvar anything-mark-ring-cache nil)
3505 (defvar anything-c-source-mark-ring
3506 '((name . "mark-ring")
3507 (init . (lambda ()
3508 (setq anything-mark-ring-cache
3509 (anything-c-source-mark-ring-candidates))))
3510 (candidates . (lambda ()
3511 (anything-aif anything-mark-ring-cache
3512 it)))
3513 (action . (("Goto line" . (lambda (candidate)
3514 (anything-goto-line (string-to-number candidate))))))
3515 (persistent-action . (lambda (candidate)
3516 (anything-goto-line (string-to-number candidate))
3517 (anything-match-line-color-current-line)))
3518 (persistent-help . "Show this line")))
3520 ;; (anything 'anything-c-source-mark-ring)
3522 (defun anything-mark-ring ()
3523 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3524 (interactive)
3525 (anything 'anything-c-source-mark-ring))
3527 ;;; Global-mark-ring
3528 (defvar anything-c-source-global-mark-ring
3529 '((name . "global-mark-ring")
3530 (candidates . anything-c-source-global-mark-ring-candidates)
3531 (action . (("Goto line" . (lambda (candidate)
3532 (let ((items (split-string candidate ":")))
3533 (switch-to-buffer (second items))
3534 (anything-goto-line (string-to-number (car items))))))))
3535 (persistent-action . (lambda (candidate)
3536 (let ((items (split-string candidate ":")))
3537 (switch-to-buffer (second items))
3538 (anything-goto-line (string-to-number (car items)))
3539 (anything-match-line-color-current-line))))
3540 (persistent-help . "Show this line")))
3542 (defun anything-c-source-global-mark-ring-candidates ()
3543 (flet ((buf-fn (m)
3544 (with-current-buffer (marker-buffer m)
3545 (goto-char m)
3546 (beginning-of-line)
3547 (let (line)
3548 (if (string= "" line)
3549 (setq line "<EMPTY LINE>")
3550 (setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
3551 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m) line)))))
3552 (loop
3553 with marks = global-mark-ring
3554 with recip = nil
3555 for i in marks
3556 if (not (or (string-match "^ " (format "%s" (marker-buffer i)))
3557 (null (marker-buffer i))))
3558 for a = (buf-fn i)
3559 if (and a (not (member a recip)))
3561 (push a recip)
3562 finally (return (reverse recip)))))
3564 ;; (anything 'anything-c-source-global-mark-ring)
3566 (defun anything-global-mark-ring ()
3567 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
3568 (interactive)
3569 (anything 'anything-c-source-global-mark-ring))
3571 ;;;; <Register>
3572 ;;; Insert from register
3573 (defvar anything-c-source-register
3574 '((name . "Registers")
3575 (candidates . anything-c-register-candidates)
3576 (action-transformer . anything-c-register-action-transformer)
3577 (multiline)
3578 (action))
3579 "See (info \"(emacs)Registers\")")
3581 (defun anything-c-register-candidates ()
3582 "Collecting register contents and appropriate commands."
3583 (loop for (char . val) in register-alist
3584 for key = (single-key-description char)
3585 for string-actions = (cond
3586 ((numberp val)
3587 (list (int-to-string val)
3588 'insert-register
3589 'increment-register))
3590 ((markerp val)
3591 (let ((buf (marker-buffer val)))
3592 (if (null buf)
3593 (list "a marker in no buffer")
3594 (list (concat
3595 "a buffer position:"
3596 (buffer-name buf)
3597 ", position "
3598 (int-to-string (marker-position val)))
3599 'jump-to-register
3600 'insert-register))))
3601 ((and (consp val) (window-configuration-p (car val)))
3602 (list "window configuration."
3603 'jump-to-register))
3604 ((and (consp val) (frame-configuration-p (car val)))
3605 (list "frame configuration."
3606 'jump-to-register))
3607 ((and (consp val) (eq (car val) 'file))
3608 (list (concat "file:"
3609 (prin1-to-string (cdr val))
3610 ".")
3611 'jump-to-register))
3612 ((and (consp val) (eq (car val) 'file-query))
3613 (list (concat "file:a file-query reference: file "
3614 (car (cdr val))
3615 ", position "
3616 (int-to-string (car (cdr (cdr val))))
3617 ".")
3618 'jump-to-register))
3619 ((consp val)
3620 (let ((lines (format "%4d" (length val))))
3621 (list (format "%s: %s\n" lines
3622 (truncate-string-to-width
3623 (mapconcat 'identity (list (car val))
3624 ;; (mapconcat (lambda (y) y) val
3625 "^J") (- (window-width) 15)))
3626 'insert-register)))
3627 ((stringp val)
3628 (list ;; without properties
3629 (substring-no-properties val)
3630 'insert-register
3631 'append-to-register
3632 'prepend-to-register))
3634 "GARBAGE!"))
3635 collect (cons (format "register %3s: %s" key (car string-actions))
3636 (cons char (cdr string-actions)))))
3638 (defun anything-c-register-action-transformer (actions register-and-functions)
3639 "Decide actions by the contents of register."
3640 (loop with func-actions =
3641 '((insert-register
3642 "Insert Register" .
3643 (lambda (c) (insert-register (car c))))
3644 (jump-to-register
3645 "Jump to Register" .
3646 (lambda (c) (jump-to-register (car c))))
3647 (append-to-register
3648 "Append Region to Register" .
3649 (lambda (c) (append-to-register (car c) (region-beginning) (region-end))))
3650 (prepend-to-register
3651 "Prepend Region to Register" .
3652 (lambda (c) (prepend-to-register (car c) (region-beginning) (region-end))))
3653 (increment-register
3654 "Increment Prefix Arg to Register" .
3655 (lambda (c) (increment-register anything-current-prefix-arg (car c)))))
3656 for func in (cdr register-and-functions)
3657 for cell = (assq func func-actions)
3658 when cell
3659 collect (cdr cell)))
3661 ;; (anything 'anything-c-source-register)
3663 ;;;; <Headline Extraction>
3664 (defvar anything-c-source-fixme
3665 '((name . "TODO/FIXME/DRY comments")
3666 (headline . "^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
3667 (adjust)
3668 (recenter))
3669 "Show TODO/FIXME/DRY comments in current file.")
3670 ;; (anything 'anything-c-source-fixme)
3672 (defvar anything-c-source-rd-headline
3673 '((name . "RD HeadLine")
3674 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
3675 (condition . (memq major-mode '(rdgrep-mode rd-mode)))
3676 (migemo)
3677 (subexp . 1))
3678 "Show RD headlines.
3680 RD is Ruby's POD.
3681 http://en.wikipedia.org/wiki/Ruby_Document_format")
3682 ;; (anything 'anything-c-source-rd-headline)
3684 (defvar anything-c-source-oddmuse-headline
3685 '((name . "Oddmuse HeadLine")
3686 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
3687 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
3688 (condition . (memq major-mode '(oddmuse-mode yaoddmuse-mode)))
3689 (migemo)
3690 (subexp . 1))
3691 "Show Oddmuse headlines, such as EmacsWiki.")
3692 ;; (anything 'anything-c-source-oddmuse-headline)
3694 (defvar anything-c-source-emacs-source-defun
3695 '((name . "Emacs Source DEFUN")
3696 (headline . "DEFUN\\|DEFVAR")
3697 (condition . (string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name ""))))
3698 "Show DEFUN/DEFVAR in Emacs C source file.")
3699 ;; (anything 'anything-c-source-emacs-source-defun)
3701 (defvar anything-c-source-emacs-lisp-expectations
3702 '((name . "Emacs Lisp Expectations")
3703 (headline . "(desc[ ]\\|(expectations")
3704 (condition . (eq major-mode 'emacs-lisp-mode)))
3705 "Show descriptions (desc) in Emacs Lisp Expectations.
3707 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
3708 ;; (anything 'anything-c-source-emacs-lisp-expectations)
3710 (defvar anything-c-source-emacs-lisp-toplevels
3711 '((name . "Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
3712 (headline . "^(\\|(@\\*\\|^;;;;")
3713 (get-line . buffer-substring)
3714 (condition . (eq major-mode 'emacs-lisp-mode))
3715 (adjust))
3716 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
3717 linkd.el is optional because linkd stars are extracted by regexp.
3718 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
3719 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
3721 (defvar anything-c-source-org-headline
3722 '((name . "Org HeadLine")
3723 (headline
3724 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3725 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3726 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3727 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3728 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3729 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3730 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3731 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3732 (condition . (eq major-mode 'org-mode))
3733 (migemo)
3734 (subexp . 1)
3735 (persistent-action . (lambda (elm)
3736 (anything-c-action-line-goto elm)
3737 (org-cycle)))
3738 (action-transformer
3739 . (lambda (actions candidate)
3740 '(("Go to Line" . anything-c-action-line-goto)
3741 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline)))))
3742 "Show Org headlines.
3743 org-mode is very very much extended text-mode/outline-mode.
3745 See (find-library \"org.el\")
3746 See http://orgmode.org for the latest version.")
3748 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
3749 (insert
3750 (save-excursion
3751 (anything-goto-line (car lineno-and-content))
3752 (and (looking-at "^\\*+ \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3753 (org-make-link-string (concat "*" (match-string 1)))))))
3755 ;; (anything 'anything-c-source-org-headline)
3757 ;;; Anything yaoddmuse
3758 ;; Be sure to have yaoddmuse.el installed
3759 ;; install-elisp may be required if you want to install elisp file from here.
3760 (defvar anything-yaoddmuse-use-cache-file nil)
3761 (defvar anything-c-yaoddmuse-cache-file "~/.emacs.d/yaoddmuse-cache.el")
3762 (defvar anything-c-yaoddmuse-ew-cache nil)
3763 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
3764 '((name . "Yaoddmuse Edit or View (EmacsWiki)")
3765 (candidates . (lambda ()
3766 (if anything-yaoddmuse-use-cache-file
3767 (condition-case nil
3768 (progn
3769 (unless anything-c-yaoddmuse-ew-cache
3770 (load anything-c-yaoddmuse-cache-file)
3771 (setq anything-c-yaoddmuse-ew-cache
3772 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
3773 anything-c-yaoddmuse-ew-cache)
3774 (error nil))
3775 (yaoddmuse-update-pagename t)
3776 (gethash "EmacsWiki" yaoddmuse-pages-hash))))
3777 (action . (("Edit page" . (lambda (candidate)
3778 (yaoddmuse-edit "EmacsWiki" candidate)))
3779 ("Browse page" . (lambda (candidate)
3780 (yaoddmuse-browse-page "EmacsWiki" candidate)))
3781 ("Browse page other window" . (lambda (candidate)
3782 (if (one-window-p)
3783 (split-window-vertically))
3784 (yaoddmuse-browse-page "EmacsWiki" candidate)))
3785 ("Browse diff" . (lambda (candidate)
3786 (yaoddmuse-browse-page-diff "EmacsWiki" candidate)))
3787 ("Copy URL" . (lambda (candidate)
3788 (kill-new (yaoddmuse-url "EmacsWiki" candidate))
3789 (message "Have copy page %s's URL to yank." candidate)))
3790 ("Create page" . (lambda (candidate)
3791 (yaoddmuse-edit "EmacsWiki" anything-input)))
3792 ("Update cache" . (lambda (candidate)
3793 (if anything-yaoddmuse-use-cache-file
3794 (progn
3795 (anything-yaoddmuse-cache-pages t)
3796 (setq anything-c-yaoddmuse-ew-cache
3797 (gethash "EmacsWiki" yaoddmuse-pages-hash)))
3798 (yaoddmuse-update-pagename))))))
3799 (action-transformer anything-c-yaoddmuse-action-transformer)))
3801 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
3803 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
3804 '((name . "Yaoddmuse Post library (EmacsWiki)")
3805 (init . (anything-yaoddmuse-init))
3806 (candidates-in-buffer)
3807 (action . (("Post library and Browse" . (lambda (candidate)
3808 (yaoddmuse-post-file (find-library-name candidate)
3809 "EmacsWiki"
3810 (file-name-nondirectory (find-library-name candidate))
3811 nil t)))
3812 ("Post library" . (lambda (candidate)
3813 (yaoddmuse-post-file (find-library-name candidate)
3814 "EmacsWiki"
3815 (file-name-nondirectory (find-library-name candidate)))))))))
3817 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
3819 (defun anything-c-yaoddmuse-action-transformer (actions candidate)
3820 "Allow the use of `install-elisp' only on elisp files."
3821 (if (string-match "\.el$" candidate)
3822 (append actions '(("Install Elisp" . (lambda (elm)
3823 (install-elisp-from-emacswiki elm)))))
3824 actions))
3826 (defun anything-yaoddmuse-cache-pages (&optional load)
3827 "Fetch the list of files on emacswiki and create cache file.
3828 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
3829 (interactive)
3830 (yaoddmuse-update-pagename)
3831 (save-excursion
3832 (find-file anything-c-yaoddmuse-cache-file)
3833 (erase-buffer)
3834 (insert "(puthash \"EmacsWiki\" '(")
3835 (loop for i in (gethash "EmacsWiki" yaoddmuse-pages-hash)
3837 (insert (concat "(\"" (car i) "\") ")))
3838 (insert ") yaoddmuse-pages-hash)\n")
3839 (save-buffer)
3840 (kill-buffer (current-buffer))
3841 (when (or current-prefix-arg
3842 load)
3843 (load anything-c-yaoddmuse-cache-file))))
3845 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
3846 "Preconfigured `anything' to edit or view EmacsWiki page."
3847 (interactive)
3848 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view))
3850 (defun anything-yaoddmuse-emacswiki-post-library ()
3851 "Preconfigured `anything' to post library to EmacsWiki."
3852 (interactive)
3853 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library))
3855 (defun anything-yaoddmuse-init ()
3856 "Init anything buffer status."
3857 (let ((anything-buffer (anything-candidate-buffer 'global))
3858 (library-list (yaoddmuse-get-library-list)))
3859 (with-current-buffer anything-buffer
3860 ;; Insert library name.
3861 (dolist (library library-list)
3862 (insert (format "%s\n" library)))
3863 ;; Sort lines.
3864 (sort-lines nil (point-min) (point-max)))))
3866 ;;; Eev anchors
3867 (defvar anything-c-source-eev-anchor
3868 '((name . "Anchors")
3869 (init . (lambda ()
3870 (setq anything-c-eev-anchor-buffer
3871 (current-buffer))))
3872 (candidates . (lambda ()
3873 (condition-case nil
3874 (save-excursion
3875 (with-current-buffer anything-c-eev-anchor-buffer
3876 (goto-char (point-min))
3877 (let (anchors)
3878 (while (re-search-forward (format ee-anchor-format "\\([^\.].+\\)") nil t)
3879 (push (match-string-no-properties 1) anchors))
3880 (setq anchors (reverse anchors)))))
3881 (error nil))))
3882 (persistent-action . (lambda (item)
3883 (ee-to item)
3884 (anything-match-line-color-current-line)))
3885 (persistent-help . "Show this entry")
3886 (action . (("Goto link" . (lambda (item)
3887 (ee-to item)))))))
3889 ;; (anything 'anything-c-source-eev-anchor)
3891 ;;;; <Misc>
3892 ;;; Org keywords
3893 (defvar anything-c-source-org-keywords
3894 '((name . "Org Keywords")
3895 (init . anything-c-org-keywords-init)
3896 (candidates . anything-c-org-keywords-candidates)
3897 (action . anything-c-org-keywords-insert)
3898 (persistent-action . anything-c-org-keywords-show-help)
3899 (persistent-help . "Show an example and info page to describe this keyword.")
3900 (keywords-examples)
3901 (keywords)))
3902 ;; (anything 'anything-c-source-org-keywords)
3903 (defvar anything-c-org-keywords-info-location
3904 '(("#+TITLE:" . "(org)Export options")
3905 ("#+AUTHOR:" . "(org)Export options")
3906 ("#+DATE:" . "(org)Export options")
3907 ("#+EMAIL:" . "(org)Export options")
3908 ("#+DESCRIPTION:" . "(org)Export options")
3909 ("#+KEYWORDS:" . "(org)Export options")
3910 ("#+LANGUAGE:" . "(org)Export options")
3911 ("#+TEXT:" . "(org)Export options")
3912 ("#+TEXT:" . "(org)Export options")
3913 ("#+OPTIONS:" . "(org)Export options")
3914 ("#+BIND:" . "(org)Export options")
3915 ("#+LINK_UP:" . "(org)Export options")
3916 ("#+LINK_HOME:" . "(org)Export options")
3917 ("#+LATEX_HEADER:" . "(org)Export options")
3918 ("#+EXPORT_SELECT_TAGS:" . "(org)Export options")
3919 ("#+EXPORT_EXCLUDE_TAGS:" . "(org)Export options")
3920 ("#+INFOJS_OPT" . "(org)Javascript support")
3921 ("#+BEGIN_HTML" . "(org)Quoting HTML tags")
3922 ("#+BEGIN_LaTeX" . "(org)Quoting LaTeX code")
3923 ("#+ORGTBL" . "(org)Radio tables")
3924 ("#+HTML:" . "(org)Quoting HTML tags")
3925 ("#+LaTeX:" . "(org)Quoting LaTeX code")
3926 ("#+BEGIN:" . "(org)Dynamic blocks") ;clocktable columnview
3927 ("#+BEGIN_EXAMPLE" . "(org)Literal examples")
3928 ("#+BEGIN_QUOTE" . "(org)Paragraphs")
3929 ("#+BEGIN_VERSE" . "(org)Paragraphs")
3930 ("#+BEGIN_SRC" . "(org)Literal examples")
3931 ("#+CAPTION" . "(org)Tables in HTML export")
3932 ("#+LABEL" . "(org)Tables in LaTeX export")
3933 ("#+ATTR_HTML" . "(org)Links")
3934 ("#+ATTR_LaTeX" . "(org)Images in LaTeX export")))
3936 (defun anything-c-org-keywords-init ()
3937 (unless (anything-attr 'keywords-examples)
3938 (require 'org)
3939 (anything-attrset 'keywords-examples
3940 (append
3941 (mapcar
3942 (lambda (x)
3943 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
3944 (cons (match-string 2 x) (match-string 1 x)))
3945 (org-split-string (org-get-current-options) "\n"))
3946 (mapcar 'list org-additional-option-like-keywords)))
3947 (anything-attrset 'keywords (mapcar 'car (anything-attr 'keywords-examples)))))
3949 (defun anything-c-org-keywords-candidates ()
3950 (and (eq (buffer-local-value 'major-mode anything-current-buffer) 'org-mode)
3951 (anything-attr 'keywords)))
3953 (defun anything-c-org-keywords-insert (keyword)
3954 (cond ((string-match "BEGIN" keyword)
3955 (insert "#+" keyword " ")
3956 (save-excursion
3957 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword) "\n")))
3959 (insert "#+" keyword " "))))
3961 (defun anything-c-org-keywords-show-help (keyword)
3962 (info (or (assoc-default (concat "#+" keyword) anything-c-org-keywords-info-location)
3963 "(org)In-buffer settings"))
3964 (search-forward (concat "#+" keyword) nil t)
3965 (anything-persistent-highlight-point)
3966 (message "%s" (or (cdr (assoc keyword (anything-attr 'keywords-examples))) "")))
3969 ;;; Picklist
3970 (defvar anything-c-source-picklist
3971 '((name . "Picklist")
3972 (candidates . (lambda () (mapcar 'car picklist-list)))
3973 (type . file)))
3974 ;; (anything 'anything-c-source-picklist)
3976 ;;; BBDB
3977 (defun anything-c-bbdb-candidates ()
3978 "Return a list of all names in the bbdb database. The format
3979 is \"Firstname Lastname\"."
3980 (mapcar (lambda (bbdb-record)
3981 (replace-regexp-in-string
3982 "\\s-+$" ""
3983 (concat (aref bbdb-record 0) " " (aref bbdb-record 1))))
3984 (bbdb-records)))
3986 (defun anything-c-bbdb-create-contact (actions candidate)
3987 "Action transformer that returns only an entry to add the
3988 current `anything-pattern' as new contact. All other actions are
3989 removed."
3990 (if (string= candidate "*Add to contacts*")
3991 '(("Add to contacts" . (lambda (actions)
3992 (bbdb-create-internal
3993 (read-from-minibuffer "Name: " anything-c-bbdb-name)
3994 (read-from-minibuffer "Company: ")
3995 (read-from-minibuffer "Email: ")
3998 (read-from-minibuffer "Note: ")))))
3999 actions))
4001 (defun anything-c-bbdb-get-record (candidate)
4002 "Return record that match CANDIDATE."
4003 (bbdb candidate nil)
4004 (set-buffer "*BBDB*")
4005 (bbdb-current-record))
4007 (defvar anything-c-bbdb-name nil
4008 "Only for internal use.")
4010 (defvar anything-c-source-bbdb
4011 '((name . "BBDB")
4012 (candidates . anything-c-bbdb-candidates)
4013 (action ("Send a mail" . anything-c-bbdb-compose-mail)
4014 ("View person's data" . anything-c-bbdb-view-person-action))
4015 (filtered-candidate-transformer . (lambda (candidates source)
4016 (setq anything-c-bbdb-name anything-pattern)
4017 (if (not candidates)
4018 (list "*Add to contacts*")
4019 candidates)))
4020 (action-transformer . (lambda (actions candidate)
4021 (anything-c-bbdb-create-contact actions candidate)))))
4022 ;; (anything 'anything-c-source-bbdb)
4024 (defun anything-c-bbdb-view-person-action (candidate)
4025 "View BBDB data of single CANDIDATE or marked candidates."
4026 (anything-aif (anything-marked-candidates)
4027 (let ((bbdb-append-records (length it)))
4028 (dolist (i it)
4029 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i))))
4030 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate))))
4032 (defun anything-c-bbdb-collect-mail-addresses ()
4033 "Return a list of all mail addresses of records in bbdb buffer."
4034 (with-current-buffer bbdb-buffer-name
4035 (loop for i in bbdb-records
4036 if (bbdb-record-net (car i))
4037 collect (bbdb-dwim-net-address (car i)))))
4039 (defun anything-c-bbdb-compose-mail (candidate)
4040 "Compose a mail with all records of bbdb buffer."
4041 (anything-c-bbdb-view-person-action candidate)
4042 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4043 (address-str (mapconcat 'identity address-list ",\n ")))
4044 (compose-mail address-str)))
4046 ;;; Evaluation Result
4047 (defvar anything-c-source-evaluation-result
4048 '((name . "Evaluation Result")
4049 (dummy)
4050 (filtered-candidate-transformer . (lambda (candidates source)
4051 (list
4052 (condition-case nil
4053 (pp-to-string
4054 (eval (read anything-pattern)))
4055 (error "Error")))))
4056 (action ("Do Nothing" . ignore))))
4057 ;; (anything 'anything-c-source-evaluation-result)
4059 ;;; Calculation Result
4060 (defvar anything-c-source-calculation-result
4061 '((name . "Calculation Result")
4062 (dummy)
4063 (filtered-candidate-transformer . (lambda (candidates source)
4064 (list
4065 (condition-case nil
4066 (calc-eval anything-pattern)
4067 (error "error")))))
4068 (action ("Copy result to kill-ring" . kill-new))))
4069 ;; (anything 'anything-c-source-calculation-result)
4071 ;;; Google Suggestions
4072 (defvar anything-gg-sug-lgh-flag 0)
4073 (defun anything-c-google-suggest-fetch (input)
4074 "Fetch suggestions for INPUT from XML buffer.
4075 Return an alist with elements like (data . number_results)."
4076 (let ((request (concat anything-c-google-suggest-url
4077 (url-hexify-string input))))
4078 (flet ((fetch ()
4079 (loop
4080 with result-alist = (xml-get-children
4081 (car (xml-parse-region (point-min) (point-max)))
4082 'CompleteSuggestion)
4083 for i in result-alist
4084 for data = (cdr (caadr (assoc 'suggestion i)))
4085 for nqueries = (cdr (caadr (assoc 'num_queries i)))
4086 for ldata = (length data)
4088 (when (> ldata anything-gg-sug-lgh-flag)
4089 (setq anything-gg-sug-lgh-flag ldata))
4090 collect (cons data nqueries) into cont
4091 finally return cont)))
4092 (if anything-google-suggest-use-curl-p
4093 (with-temp-buffer
4094 (call-process "curl" nil t nil request)
4095 (fetch))
4096 (with-current-buffer
4097 (url-retrieve-synchronously request)
4098 (fetch))))))
4101 (defun anything-c-google-suggest-set-candidates ()
4102 "Set candidates with result and number of google results found."
4103 (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
4104 (setq suggestions (loop for i in suggestions
4105 for interval = (- anything-gg-sug-lgh-flag (length (car i)))
4106 for elm = (concat (car i)
4107 (make-string (+ 2 interval) ? )
4108 "(" (cdr i) " results)")
4109 collect (cons elm (car i))))
4110 (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
4111 suggestions
4112 ;; if there is no suggestion exactly matching the input then
4113 ;; prepend a Search on Google item to the list
4114 (append
4115 suggestions
4116 (list (cons (concat "Search for " "'" anything-input "'" " on Google")
4117 anything-input))))))
4120 (defun anything-c-google-suggest-action (candidate)
4121 "Default action to jump to a google suggested candidate."
4122 (browse-url (concat anything-c-google-suggest-search-url
4123 (url-hexify-string candidate))))
4126 (defvar anything-c-source-google-suggest
4127 '((name . "Google Suggest")
4128 (candidates . anything-c-google-suggest-set-candidates)
4129 (action . (("Google Search" . anything-c-google-suggest-action)))
4130 (volatile)
4131 (requires-pattern . 3)
4132 (delayed)))
4134 ;; (anything 'anything-c-source-google-suggest)
4136 ;;; Yahoo suggestions
4138 (defun anything-c-yahoo-suggest-fetch (input)
4139 "Fetch Yahoo suggestions for INPUT from XML buffer.
4140 Return an alist with elements like (data . number_results)."
4141 (let ((request (concat anything-c-yahoo-suggest-url
4142 (url-hexify-string input))))
4143 (flet ((fetch ()
4144 (loop
4145 with result-alist = (xml-get-children
4146 (car (xml-parse-region (point-min) (point-max)))
4147 'Result)
4148 for i in result-alist
4149 collect (caddr i))))
4150 (with-current-buffer
4151 (url-retrieve-synchronously request)
4152 (fetch)))))
4154 (defun anything-c-yahoo-suggest-set-candidates ()
4155 "Set candidates with Yahoo results found."
4156 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input)))
4157 (or suggestions
4158 (append
4159 suggestions
4160 (list (cons (concat "Search for " "'" anything-input "'" " on Yahoo")
4161 anything-input))))))
4163 (defun anything-c-yahoo-suggest-action (candidate)
4164 "Default action to jump to a Yahoo suggested candidate."
4165 (browse-url (concat anything-c-yahoo-suggest-search-url
4166 (url-hexify-string candidate))))
4168 (defvar anything-c-source-yahoo-suggest
4169 '((name . "Yahoo Suggest")
4170 (candidates . anything-c-yahoo-suggest-set-candidates)
4171 (action . (("Yahoo Search" . anything-c-yahoo-suggest-action)))
4172 (volatile)
4173 (requires-pattern . 3)
4174 (delayed)))
4176 ;; (anything 'anything-c-source-yahoo-suggest)
4178 ;;; Surfraw
4179 ;;; Need external program surfraw.
4180 ;;; http://surfraw.alioth.debian.org/
4181 ;; user variables
4182 (defvar anything-c-surfraw-favorites '("google" "wikipedia"
4183 "yahoo" "translate"
4184 "codesearch" "genpkg"
4185 "genportage" "fast"
4186 "currency")
4187 "All elements of this list will appear first in results.")
4188 (defvar anything-c-surfraw-use-only-favorites nil
4189 "If non-nil use only `anything-c-surfraw-favorites'.")
4192 (defun anything-c-build-elvi-alist ()
4193 "Build elvi alist.
4194 A list of search engines."
4195 (let* ((elvi-list
4196 (with-temp-buffer
4197 (call-process "surfraw" nil t nil
4198 "-elvi")
4199 (split-string (buffer-string) "\n")))
4200 (elvi-alist
4201 (let (line)
4202 (loop for i in elvi-list
4204 (setq line (split-string i))
4205 collect (cons (first line) (mapconcat #'(lambda (x) x) (cdr line) " "))))))
4206 elvi-alist))
4208 (defun anything-c-surfraw-sort-elvi (&optional only-fav)
4209 "Sort elvi alist according to `anything-c-surfraw-favorites'."
4210 (let* ((elvi-alist (anything-c-build-elvi-alist))
4211 (fav-alist (loop for j in anything-c-surfraw-favorites
4212 collect (assoc j elvi-alist)))
4213 (rest-elvi (loop for i in elvi-alist
4214 if (not (member i fav-alist))
4215 collect i)))
4216 (if only-fav
4217 fav-alist
4218 (append fav-alist rest-elvi))))
4220 (defun anything-c-surfraw-get-url (engine pattern)
4221 "Get search url from `engine' for `anything-pattern'."
4222 (with-temp-buffer
4223 (apply #'call-process "surfraw" nil t nil
4224 `(,engine
4225 "-p"
4226 ,anything-pattern))
4227 (buffer-string)))
4230 (defvar anything-c-surfraw-elvi nil)
4231 (defvar anything-c-surfraw-cache nil)
4232 (defvar anything-c-source-surfraw
4233 '((name . "Surfraw")
4234 (init . (lambda ()
4235 (unless anything-c-surfraw-cache
4236 (setq anything-c-surfraw-elvi (anything-c-surfraw-sort-elvi
4237 anything-c-surfraw-use-only-favorites))
4238 (setq anything-c-surfraw-cache
4239 (loop for i in anything-c-surfraw-elvi
4240 if (car i)
4241 collect (car i))))))
4242 (candidates . (lambda ()
4243 (loop for i in anything-c-surfraw-cache
4244 for s = (anything-c-surfraw-get-url i anything-pattern)
4245 collect (concat (propertize i
4246 'face '((:foreground "green"))
4247 'help-echo (cdr (assoc i anything-c-surfraw-elvi)))
4248 ">>>" (replace-regexp-in-string "\n" "" s)))))
4249 (action . (("Browse" . (lambda (candidate)
4250 (let ((url (second (split-string candidate ">>>"))))
4251 (browse-url url))))
4252 ("Browse firefox" . (lambda (candidate)
4253 (let ((url (second (split-string candidate ">>>"))))
4254 (browse-url-firefox url t))))))
4255 (volatile)
4256 (requires-pattern . 3)
4257 (multiline)
4258 (delayed)))
4260 ;; (anything 'anything-c-source-surfraw)
4262 ;;; Emms
4264 (defun anything-emms-stream-edit-bookmark (elm)
4265 "Change the information of current emms-stream bookmark from anything."
4266 (interactive)
4267 (let* ((cur-buf anything-current-buffer)
4268 (bookmark (assoc elm emms-stream-list))
4269 (name (read-from-minibuffer "Description: "
4270 (nth 0 bookmark)))
4271 (url (read-from-minibuffer "URL: "
4272 (nth 1 bookmark)))
4273 (fd (read-from-minibuffer "Feed Descriptor: "
4274 (int-to-string (nth 2 bookmark))))
4275 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4276 (format "%s" (car (last bookmark))))))
4277 (save-excursion
4278 (emms-streams)
4279 (when (re-search-forward (concat "^" name) nil t)
4280 (beginning-of-line)
4281 (emms-stream-delete-bookmark)
4282 (emms-stream-add-bookmark name url (string-to-number fd) type)
4283 (emms-stream-save-bookmarks-file)
4284 (emms-stream-quit)
4285 (switch-to-buffer cur-buf)))))
4287 (defun anything-emms-stream-delete-bookmark (elm)
4288 "Delete an emms-stream bookmark from anything."
4289 (interactive)
4290 (let* ((cur-buf anything-current-buffer)
4291 (bookmark (assoc elm emms-stream-list))
4292 (name (nth 0 bookmark)))
4293 (save-excursion
4294 (emms-streams)
4295 (when (re-search-forward (concat "^" name) nil t)
4296 (beginning-of-line)
4297 (emms-stream-delete-bookmark)
4298 (emms-stream-save-bookmarks-file)
4299 (emms-stream-quit)
4300 (switch-to-buffer cur-buf)))))
4302 (defvar anything-c-source-emms-streams
4303 '((name . "Emms Streams")
4304 (init . (lambda ()
4305 (emms-stream-init)))
4306 (candidates . (lambda ()
4307 (mapcar 'car emms-stream-list)))
4308 (action . (("Play" . (lambda (elm)
4309 (let* ((stream (assoc elm emms-stream-list))
4310 (fn (intern (concat "emms-play-" (symbol-name (car (last stream))))))
4311 (url (second stream)))
4312 (funcall fn url))))
4313 ("Delete" . anything-emms-stream-delete-bookmark)
4314 ("Edit" . anything-emms-stream-edit-bookmark)))
4315 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4316 ;; (anything 'anything-c-source-emms-streams)
4318 ;; Don't forget to set `emms-source-file-default-directory'
4319 (defvar anything-c-source-emms-dired
4320 '((name . "Music Directory")
4321 (candidates . (lambda ()
4322 (cddr (directory-files emms-source-file-default-directory))))
4323 (action .
4324 (("Play Directory" . (lambda (item)
4325 (emms-play-directory
4326 (expand-file-name
4327 item
4328 emms-source-file-default-directory))))
4329 ("Open dired in file's directory" . (lambda (item)
4330 (anything-c-open-dired
4331 (expand-file-name
4332 item
4333 emms-source-file-default-directory))))))
4334 (filtered-candidate-transformer . anything-c-adaptive-sort)))
4335 ;; (anything 'anything-c-source-emms-dired)
4337 ;;; Jabber Contacts (jabber.el)
4338 (defun anything-c-jabber-online-contacts ()
4339 "List online Jabber contacts."
4340 (with-no-warnings
4341 (let (jids)
4342 (dolist (item (jabber-concat-rosters) jids)
4343 (when (get item 'connected)
4344 (push (if (get item 'name)
4345 (cons (get item 'name) item)
4346 (cons (symbol-name item) item)) jids))))))
4348 (defvar anything-c-source-jabber-contacts
4349 '((name . "Jabber Contacts")
4350 (init . (lambda () (require 'jabber)))
4351 (candidates . (lambda () (mapcar 'car (anything-c-jabber-online-contacts))))
4352 (action . (lambda (x)
4353 (jabber-chat-with
4354 (jabber-read-account)
4355 (symbol-name
4356 (cdr (assoc x (anything-c-jabber-online-contacts)))))))))
4357 ;; (anything 'anything-c-source-jabber-contacts)
4360 ;;; Call source.
4361 (defvar anything-source-select-buffer "*anything source select*")
4362 (defvar anything-c-source-call-source
4363 `((name . "Call anything source")
4364 (candidate-number-limit)
4365 (candidates . (lambda ()
4366 (loop for vname in (all-completions "anything-c-source-" obarray)
4367 for var = (intern vname)
4368 for name = (ignore-errors (assoc-default 'name (symbol-value var)))
4369 if name collect (cons (format "%s `%s'"
4370 name (propertize vname 'face 'font-lock-variable-name-face))
4371 var))))
4372 (action . (("Invoke anything with selected source" .
4373 (lambda (candidate)
4374 (setq anything-candidate-number-limit 9999)
4375 (anything candidate nil nil nil nil
4376 anything-source-select-buffer)))
4377 ("Describe variable" . describe-variable)))
4378 (persistent-action . describe-variable)
4379 (persistent-help . "Show description of this source")))
4380 ;; (anything 'anything-c-source-call-source)
4382 (defun anything-call-source ()
4383 "Preconfigured `anything' to call anything source."
4384 (interactive)
4385 (anything 'anything-c-source-call-source nil nil nil nil
4386 anything-source-select-buffer))
4388 (defun anything-call-source-from-anything ()
4389 "Call anything source within `anything' session."
4390 (interactive)
4391 (setq anything-input-idle-delay 0)
4392 (anything-set-sources '(anything-c-source-call-source)))
4395 ;; Occur
4397 (defun anything-c-occur-goto-line (candidate)
4398 "Goto line action for anything-c-source-occur."
4399 (anything-goto-line (string-to-number candidate)))
4401 (defun anything-c-occur-persistent-action (candidate)
4402 "Persistent action for anything occur source."
4403 (anything-c-occur-goto-line candidate)
4404 (anything-match-line-color-current-line))
4406 (defun anything-c-get-occur-candidates ()
4407 "Get `anything-c-source-occur' candidates."
4408 (with-temp-buffer
4409 (let ((count (occur-engine
4410 anything-pattern
4411 (list anything-current-buffer) (current-buffer)
4412 list-matching-lines-default-context-lines nil
4413 list-matching-lines-buffer-name-face
4414 nil list-matching-lines-face
4415 (not (eq occur-excluded-properties t)))))
4416 (when (> count 0)
4417 (cdr (split-string (buffer-string) "\n" t))))))
4419 (defvar anything-c-source-occur
4420 '((name . "Occur")
4421 (candidates . anything-c-get-occur-candidates)
4422 (persistent-action . anything-c-occur-persistent-action)
4423 (action . anything-c-occur-goto-line)
4424 (requires-pattern . 1)
4425 (delayed)
4426 (volatile)))
4427 ;; (anything 'anything-c-source-occur)
4429 (defun anything-occur ()
4430 "Preconfigured Anything for Occur source."
4431 (interactive)
4432 (anything-other-buffer 'anything-c-source-occur "*Anything Occur*"))
4434 ;; Do many actions for input
4435 (defvar anything-c-source-create
4436 '((name . "Create")
4437 (dummy)
4438 (action)
4439 (candidate-number-limit . 9999)
4440 (action-transformer . anything-create--actions))
4441 "Do many create actions from `anything-pattern'.
4442 See also `anything-create--actions'.")
4443 ;; (anything 'anything-c-source-create)
4445 (defun anything-create-from-anything ()
4446 "Run `anything-create' from `anything' as a fallback."
4447 (interactive)
4448 (anything-run-after-quit 'anything-create nil anything-pattern))
4450 (defun anything-create (&optional string initial-input)
4451 "Preconfigured `anything' to do many create actions from STRING.
4452 See also `anything-create--actions'."
4453 (interactive)
4454 (setq string (or string (read-string "Create Anything: " initial-input)))
4455 (anything '(((name . "Anything Create")
4456 (header-name . (lambda (_) (format "Action for \"%s\"" string)))
4457 (candidates . anything-create--actions)
4458 (candidate-number-limit . 9999)
4459 (action . (lambda (func) (funcall func string)))))))
4461 (defun anything-create--actions (&rest ignored)
4462 "Default actions for `anything-create' / `anything-c-source-create'."
4463 (remove-if-not
4464 (lambda (pair) (and (consp pair) (functionp (cdr pair))))
4465 (append anything-create--actions-private
4466 '(("find-file" . find-file)
4467 ("find-file other window" . find-file-other-window)
4468 ("New buffer" . switch-to-buffer)
4469 ("New buffer other window" . switch-to-buffer-other-window)
4470 ("Bookmark Set" . bookmark-set)
4471 ("Set Register" .
4472 (lambda (x) (set-register (read-char "Register: ") x)))
4473 ("Insert Linkd star" . linkd-insert-star)
4474 ("Insert Linkd Tag" . linkd-insert-tag)
4475 ("Insert Linkd Link" . linkd-insert-link)
4476 ("Insert Linkd Lisp" . linkd-insert-lisp)
4477 ("Insert Linkd Wiki" . linkd-insert-wiki)
4478 ("Google Search" . google)))))
4480 ;; Minibuffer History
4481 (defvar anything-c-source-minibuffer-history
4482 '((name . "Minibuffer History")
4483 (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
4484 (candidates . (lambda () (let ((history (symbol-value minibuffer-history-variable)))
4485 (if (consp (car history))
4486 (mapcar 'prin1-to-string history)
4487 history))))
4488 (migemo)
4489 (action . insert)))
4490 ;; (anything 'anything-c-source-minibuffer-history)
4492 ;; elscreen
4493 (defvar anything-c-source-elscreen
4494 '((name . "Elscreen")
4495 (candidates . (lambda ()
4496 (if (cdr (elscreen-get-screen-to-name-alist))
4497 (sort
4498 (loop for sname in (elscreen-get-screen-to-name-alist)
4499 append (list (format "[%d] %s" (car sname) (cdr sname))) into lst
4500 finally (return lst))
4501 #'(lambda (a b) (compare-strings a nil nil b nil nil))))))
4502 (action . (("Change Screen".
4503 (lambda (candidate)
4504 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))))
4505 ("Kill Screen(s)".
4506 (lambda (candidate)
4507 (anything-aif (anything-marked-candidates)
4508 (dolist (i it)
4509 (elscreen-kill-internal (- (aref i 1) (aref "0" 0))))
4510 (elscreen-kill-internal (- (aref candidate 1) (aref "0" 0))))))
4511 ("Only Screen".
4512 (lambda (candidate)
4513 (elscreen-goto (- (aref candidate 1) (aref "0" 0)))
4514 (elscreen-kill-others)))))))
4515 ;; (anything 'anything-c-source-elscreen)
4517 ;;;; <System>
4519 ;;; Top (process)
4520 (defvar anything-c-top-command "COLUMNS=%s top -b -n 1"
4521 "Top command (batch mode). %s is replaced with `frame-width'.")
4522 (defvar anything-c-source-top
4523 '((name . "Top (Press C-c C-u to refresh)")
4524 (init . anything-c-top-init)
4525 (candidates-in-buffer)
4526 (display-to-real . anything-c-top-display-to-real)
4527 (update . anything-c-top-update)
4528 (action
4529 ("kill (TERM)" . (lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid))))
4530 ("kill (KILL)" . (lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid))))
4531 ("Copy PID" . (lambda (pid) (kill-new pid))))))
4532 ;; (anything 'anything-c-source-top)
4534 (defun anything-c-top-sh (cmd)
4535 (message "Executed %s\n%s" cmd (shell-command-to-string cmd)))
4537 (defun anything-c-top-init ()
4538 (with-current-buffer (anything-candidate-buffer 'global)
4539 (call-process-shell-command
4540 (format anything-c-top-command
4541 (- (frame-width) (if anything-enable-digit-shortcuts 4 0)))
4542 nil (current-buffer))))
4544 (defun anything-c-top-display-to-real (line)
4545 (car (split-string line)))
4547 (defun anything-c-top-update ()
4548 (let ((anything-source-name (assoc-default 'name anything-c-source-top))) ;UGLY HACK
4549 (anything-c-top-init)))
4551 (defun anything-top ()
4552 "Preconfigured `anything' for top command."
4553 (interactive)
4554 (let ((anything-samewindow t)
4555 (anything-enable-shortcuts)
4556 (anything-display-function 'anything-default-display-buffer)
4557 (anything-candidate-number-limit 9999))
4558 (save-window-excursion
4559 (delete-other-windows)
4560 (anything-other-buffer 'anything-c-source-top "*anything top*"))))
4562 ;;; Timers
4563 (defvar anything-c-source-absolute-time-timers
4564 '((name . "Absolute Time Timers")
4565 (candidates . timer-list)
4566 (type . timer)))
4567 ;; (anything 'anything-c-source-absolute-time-timers)
4569 (defvar anything-c-source-idle-time-timers
4570 '((name . "Idle Time Timers")
4571 (candidates . timer-idle-list)
4572 (type . timer)))
4573 ;; (anything 'anything-c-source-idle-time-timers)
4575 (defun anything-c-timer-real-to-display (timer)
4576 (destructuring-bind (_ t1 t2 t3 _ func args &rest rest) (append timer nil)
4577 (format "%s %s(%s)"
4578 (format-time-string "%m/%d %T" (list t1 t2 t3))
4579 func
4580 (mapconcat 'prin1-to-string (aref timer 6) " "))))
4582 ;;; X RandR resolution change
4583 ;;; FIXME I do not care multi-display.
4584 (defvar anything-c-xrandr-output "VGA")
4585 (defvar anything-c-xrandr-screen "0")
4586 (defvar anything-c-source-xrandr-change-resolution
4587 '((name . "Change Resolution")
4588 (candidates
4589 . (lambda ()
4590 (with-temp-buffer
4591 (call-process "xrandr" nil (current-buffer) nil
4592 "--screen" anything-c-xrandr-screen "-q")
4593 (goto-char 1)
4594 (loop while (re-search-forward " \\([0-9]+x[0-9]+\\)" nil t)
4595 collect (match-string 1)))))
4596 (action
4597 ("Change Resolution" . (lambda (mode)
4598 (call-process "xrandr" nil nil nil
4599 "--screen" anything-c-xrandr-screen
4600 "--output" anything-c-xrandr-output
4601 "--mode" mode))))))
4602 ;; (anything 'anything-c-source-xrandr-change-resolution)
4604 ;;; Xfont selection
4605 (defun anything-c-persistent-xfont-action (elm)
4606 "Show current font temporarily"
4607 (let ((current-font (cdr (assoc 'font (frame-parameters))))
4608 (default-font elm))
4609 (unwind-protect
4610 (progn (set-frame-font default-font 'keep-size) (sit-for 2))
4611 (set-frame-font current-font))))
4613 (defvar anything-c-xfonts-cache nil)
4614 (defvar anything-c-source-xfonts
4615 '((name . "X Fonts")
4616 (init . (lambda ()
4617 (unless anything-c-xfonts-cache
4618 (setq anything-c-xfonts-cache
4619 (x-list-fonts "*")))))
4620 (candidates . anything-c-xfonts-cache)
4621 (action . (("Copy to kill ring" . (lambda (elm)
4622 (kill-new elm)))
4623 ("Set Font" . (lambda (elm)
4624 (kill-new elm)
4625 (set-frame-font elm 'keep-size)
4626 (message "New font have been copied to kill ring")))))
4627 (persistent-action . anything-c-persistent-xfont-action)
4628 (persistent-help . "Switch to this font temporarily")))
4630 (defun anything-select-xfont ()
4631 "Preconfigured `anything' to select Xfont."
4632 (interactive)
4633 (anything-other-buffer 'anything-c-source-xfonts "*anything select* xfont"))
4635 ;; (anything 'anything-c-source-xfonts)
4637 ;; Source for Debian/Ubuntu users
4638 (defvar anything-c-source-apt
4639 '((name . "APT")
4640 (init . anything-c-apt-init)
4641 (candidates-in-buffer)
4642 (display-to-real . anything-c-apt-display-to-real)
4643 (candidate-number-limit . 9999)
4644 (action
4645 ("Show package description" . anything-c-apt-cache-show)
4646 ("Install package" . anything-c-apt-install))))
4647 ;; (anything 'anything-c-source-apt)
4649 (defvar anything-c-apt-query "emacs")
4650 (defvar anything-c-apt-search-command "apt-cache search '%s'")
4651 (defvar anything-c-apt-show-command "apt-cache show '%s'")
4652 (defvar anything-c-apt-install-command "xterm -e sudo apt-get install '%s' &")
4654 (defun anything-apt (query)
4655 "Preconfigured `anything' : frontend of APT package manager."
4656 (interactive "sAPT search: ")
4657 (let ((anything-c-apt-query query))
4658 (anything 'anything-c-source-apt)))
4660 (defun anything-c-apt-init ()
4661 (with-current-buffer
4662 (anything-candidate-buffer
4663 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query)))
4664 (call-process-shell-command
4665 (format anything-c-apt-search-command anything-c-apt-query)
4666 nil (current-buffer))))
4667 (defun anything-c-apt-display-to-real (line)
4668 (car (split-string line " - ")))
4670 (defun anything-c-shell-command-if-needed (command)
4671 (interactive "sShell command: ")
4672 (if (get-buffer command) ; if the buffer already exists
4673 (switch-to-buffer command) ; then just switch to it
4674 (switch-to-buffer command) ; otherwise create it
4675 (insert (shell-command-to-string command))))
4677 (defun anything-c-apt-cache-show (package)
4678 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package)))
4679 (defun anything-c-apt-install (package)
4680 (shell-command (format anything-c-apt-install-command package) "*apt install*"))
4682 ;; (anything-c-apt-install "jed")
4683 ;; Sources for gentoo users
4685 (defvar anything-gentoo-prefered-shell 'eshell
4686 "Your favorite shell to run emerge command.")
4688 (defvar anything-c-gentoo-use-flags nil)
4689 (defvar anything-c-gentoo-buffer "*anything-gentoo-output*")
4690 (defvar anything-c-cache-gentoo nil)
4691 (defvar anything-c-cache-world nil)
4692 (defvar anything-c-source-gentoo
4693 '((name . "Portage sources")
4694 (init . (lambda ()
4695 (get-buffer-create anything-c-gentoo-buffer)
4696 (unless anything-c-cache-gentoo
4697 (anything-c-gentoo-setup-cache))
4698 (unless anything-c-cache-world
4699 (setq anything-c-cache-world (anything-c-gentoo-get-world)))
4700 (anything-c-gentoo-init-list)))
4701 (candidates-in-buffer)
4702 (match . identity)
4703 (candidate-transformer anything-c-highlight-world)
4704 (action . (("Show package" . (lambda (elm)
4705 (anything-c-gentoo-eshell-action elm "eix")))
4706 ("Show history" . (lambda (elm)
4707 (if (member elm anything-c-cache-world)
4708 (anything-c-gentoo-eshell-action elm "genlop -qe")
4709 (message "No infos on packages not yet installed"))))
4710 ("Copy in kill-ring" . kill-new)
4711 ("insert at point" . insert)
4712 ("Browse HomePage" . (lambda (elm)
4713 (browse-url (car (anything-c-gentoo-get-url elm)))))
4714 ("Show extra infos" . (lambda (elm)
4715 (if (member elm anything-c-cache-world)
4716 (anything-c-gentoo-eshell-action elm "genlop -qi")
4717 (message "No infos on packages not yet installed"))))
4718 ("Show use flags" . (lambda (elm)
4719 (anything-c-gentoo-default-action elm "equery" "-C" "u")
4720 (font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
4721 (font-lock-mode 1)))
4722 ("Run emerge pretend" . (lambda (elm)
4723 (anything-c-gentoo-eshell-action elm "emerge -p")))
4724 ("Emerge" . (lambda (elm)
4725 (anything-gentoo-install elm :action 'install)))
4726 ("Unmerge" . (lambda (elm)
4727 (anything-gentoo-install elm :action 'uninstall)))
4728 ("Show dependencies" . (lambda (elm)
4729 (anything-c-gentoo-default-action elm "equery" "-C" "d")))
4730 ("Show related files" . (lambda (elm)
4731 (anything-c-gentoo-default-action elm "equery" "files")))
4732 ("Refresh" . (lambda (elm)
4733 (anything-c-gentoo-setup-cache)
4734 (setq anything-c-cache-world (anything-c-gentoo-get-world))))))))
4736 ;; (anything 'anything-c-source-gentoo)
4738 (defun* anything-gentoo-install (candidate &key action)
4739 (funcall anything-gentoo-prefered-shell)
4740 (let ((command (case action
4741 ('install "*sudo emerge -av ")
4742 ('uninstall "*sudo emerge -avC ")
4743 (t (error "Unknow action")))))
4744 (if (anything-marked-candidates)
4745 (let ((elms (mapconcat 'identity (anything-marked-candidates) " ")))
4746 (insert (concat command elms)))
4747 (insert (concat command candidate)))))
4750 (defun anything-c-gentoo-default-action (elm command &rest args)
4751 "Gentoo default action that use `anything-c-gentoo-buffer'."
4752 (if (member elm anything-c-cache-world)
4753 (progn
4754 (switch-to-buffer anything-c-gentoo-buffer)
4755 (erase-buffer)
4756 (let ((com-list (append args (list elm))))
4757 (apply #'call-process command nil t nil
4758 com-list)))
4759 (message "No infos on packages not yet installed")))
4761 (defvar anything-c-source-use-flags
4762 '((name . "Use Flags")
4763 (init . (lambda ()
4764 (unless anything-c-gentoo-use-flags
4765 (anything-c-gentoo-setup-use-flags-cache))
4766 (anything-c-gentoo-get-use)))
4767 (candidates-in-buffer)
4768 (match . identity)
4769 (candidate-transformer anything-c-highlight-local-use)
4770 (action . (("Description"
4771 . (lambda (elm)
4772 (switch-to-buffer anything-c-gentoo-buffer)
4773 (erase-buffer)
4774 (apply #'call-process "euse" nil t nil
4775 `("-i"
4776 ,elm))
4777 (font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
4778 (font-lock-mode 1)))
4779 ("Enable"
4780 . (lambda (elm)
4781 (anything-c-gentoo-eshell-action elm "*sudo euse -E")))
4782 ("Disable"
4783 . (lambda (elm)
4784 (anything-c-gentoo-eshell-action elm "*sudo euse -D")))
4785 ("Remove"
4786 . (lambda (elm)
4787 (anything-c-gentoo-eshell-action elm "*sudo euse -P")))
4788 ("Show which dep use this flag"
4789 . (lambda (elm)
4790 (switch-to-buffer anything-c-gentoo-buffer)
4791 (erase-buffer)
4792 (apply #'call-process "equery" nil t nil
4793 `("-C"
4795 ,elm))))))))
4798 ;; (anything 'anything-c-source-use-flags)
4800 (defun anything-c-gentoo-init-list ()
4801 "Initialize buffer with all packages in Portage."
4802 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
4803 (buf (anything-candidate-buffer 'portage-buf)))
4804 (with-current-buffer buf
4805 (dolist (i anything-c-cache-gentoo)
4806 (insert (concat i "\n"))))))
4808 (defun anything-c-gentoo-setup-cache ()
4809 "Set up `anything-c-cache-gentoo'"
4810 (setq anything-c-cache-gentoo
4811 (split-string (with-temp-buffer
4812 (call-process "eix" nil t nil
4813 "--only-names")
4814 (buffer-string)))))
4816 (defun anything-c-gentoo-eshell-action (elm command)
4817 (when (get-buffer "*EShell Command Output*")
4818 (kill-buffer "*EShell Command Output*"))
4819 (message "Wait searching...")
4820 (let ((buf-fname (buffer-file-name anything-current-buffer)))
4821 (if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
4822 (progn
4823 (save-window-excursion
4824 (pop-to-buffer "*scratch*")
4825 (eshell-command (format "%s %s" command elm)))
4826 (pop-to-buffer "*EShell Command Output*"))
4827 (eshell-command (format "%s %s" command elm)))))
4829 (defun anything-c-gentoo-get-use ()
4830 "Initialize buffer with all use flags."
4831 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
4832 (buf (anything-candidate-buffer 'use-buf)))
4833 (with-current-buffer buf
4834 (dolist (i anything-c-gentoo-use-flags)
4835 (insert (concat i "\n"))))))
4838 (defun anything-c-gentoo-setup-use-flags-cache ()
4839 "Setup `anything-c-gentoo-use-flags'"
4840 (setq anything-c-gentoo-use-flags
4841 (split-string (with-temp-buffer
4842 (call-process "eix" nil t nil
4843 "--print-all-useflags")
4844 (buffer-string)))))
4846 (defun anything-c-gentoo-get-url (elm)
4847 "Return a list of urls from eix output."
4848 (split-string (eshell-command-result
4849 (format "eix %s | grep Homepage | awk '{print $2}'" elm))))
4851 (defun anything-c-gentoo-get-world ()
4852 "Return list of all installed package on your system."
4853 (split-string (with-temp-buffer
4854 (call-process "qlist" nil t nil
4855 "-I")
4856 (buffer-string))))
4858 (defun anything-c-gentoo-get-local-use ()
4859 (split-string (with-temp-buffer
4860 (call-process "portageq" nil t nil
4861 "envvar"
4862 "USE")
4863 (buffer-string))))
4865 (defface anything-gentoo-match-face '((t (:foreground "red")))
4866 "Face for anything-gentoo installed packages."
4867 :group 'traverse-faces)
4869 (defun anything-c-highlight-world (eix)
4870 "Highlight all installed package."
4871 (loop for i in eix
4872 if (member i anything-c-cache-world)
4873 collect (propertize i 'face 'anything-gentoo-match-face)
4874 else
4875 collect i))
4877 (defun anything-c-highlight-local-use (use-flags)
4878 (let ((local-uses (anything-c-gentoo-get-local-use)))
4879 (loop for i in use-flags
4880 if (member i local-uses)
4881 collect (propertize i 'face 'anything-gentoo-match-face)
4882 else
4883 collect i)))
4885 (defvar anything-c-source-emacs-process
4886 '((name . "Emacs Process")
4887 (candidates . (lambda () (mapcar #'process-name (process-list))))
4888 (action ("Kill Process" . (lambda (elm) (delete-process (get-process elm)))))))
4890 ;; (anything 'anything-c-source-emacs-process)
4893 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4894 ;;; Files
4895 (defvar anything-c-external-commands-list nil
4896 "A list of all external commands the user can execute. If this
4897 variable is not set by the user, it will be calculated
4898 automatically.")
4900 (defun anything-c-external-commands-list-1 ()
4901 "Returns a list of all external commands the user can execute.
4903 If `anything-c-external-commands-list' is non-nil it will
4904 return its contents. Else it calculates all external commands
4905 and sets `anything-c-external-commands-list'.
4907 The code is ripped out of `eshell-complete-commands-list'."
4908 (if anything-c-external-commands-list
4909 anything-c-external-commands-list
4910 (setq anything-c-external-commands-list
4911 (let* ((paths (split-string (getenv "PATH") path-separator))
4912 (cwd (file-name-as-directory
4913 (expand-file-name default-directory)))
4914 (path "") (comps-in-path ())
4915 (file "") (filepath "") (completions ()))
4916 ;; Go thru each path in the search path, finding completions.
4917 (while paths
4918 (setq path (file-name-as-directory
4919 (expand-file-name (or (car paths) ".")))
4920 comps-in-path
4921 (and (file-accessible-directory-p path)
4922 (file-name-all-completions "" path)))
4923 ;; Go thru each completion found, to see whether it should be
4924 ;; used, e.g. see if it's executable.
4925 (while comps-in-path
4926 (setq file (car comps-in-path)
4927 filepath (concat path file))
4928 (if (and (not (member file completions))
4929 (or (string-equal path cwd)
4930 (not (file-directory-p filepath)))
4931 (file-executable-p filepath))
4932 (setq completions (cons file completions)))
4933 (setq comps-in-path (cdr comps-in-path)))
4934 (setq paths (cdr paths)))
4935 completions))))
4937 (defun anything-c-file-buffers (filename)
4938 "Returns a list of buffer names corresponding to FILENAME."
4939 (let ((name (expand-file-name filename))
4940 (buf-list ()))
4941 (dolist (buf (buffer-list) buf-list)
4942 (let ((bfn (buffer-file-name buf)))
4943 (when (and bfn (string= name bfn))
4944 (push (buffer-name buf) buf-list))))))
4946 (defun anything-c-delete-file (file)
4947 "Delete the given file after querying the user.
4948 Ask to kill buffers associated with that file, too."
4949 (let ((buffers (anything-c-file-buffers file)))
4950 (dired-delete-file file 'dired-recursive-deletes)
4951 (when buffers
4952 (dolist (buf buffers)
4953 (when (y-or-n-p (format "Kill buffer %s, too? " buf))
4954 (kill-buffer buf))))))
4956 (defun anything-c-open-file-externally (file)
4957 "Open FILE with an external tool. Query the user which tool to use."
4958 (start-process "anything-c-open-file-externally"
4960 (completing-read "Program: "
4961 (anything-c-external-commands-list-1))
4962 file))
4964 (defun w32-shell-execute-open-file (file)
4965 (interactive "fOpen file:")
4966 (with-no-warnings
4967 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
4968 "/" "\\"
4969 (replace-regexp-in-string ; strip cygdrive paths
4970 "/cygdrive/\\(.\\)" "\\1:" file nil nil) nil t))))
4971 (defun anything-c-open-file-with-default-tool (file)
4972 "Open FILE with the default tool on this platform."
4973 (if (eq system-type 'windows-nt)
4974 (w32-shell-execute-open-file file)
4975 (start-process "anything-c-open-file-with-default-tool"
4977 (cond ((eq system-type 'gnu/linux)
4978 "xdg-open")
4979 ((or (eq system-type 'darwin) ;; Mac OS X
4980 (eq system-type 'macos)) ;; Mac OS 9
4981 "open"))
4982 file)))
4984 (defun anything-c-open-dired (file)
4985 "Opens a dired buffer in FILE's directory. If FILE is a
4986 directory, open this directory."
4987 (if (file-directory-p file)
4988 (dired file)
4989 (dired (file-name-directory file))
4990 (dired-goto-file file)))
4992 (defun anything-c-display-to-real-line (candidate)
4993 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate)
4994 (list (string-to-number (match-string 1 candidate)) (match-string 2 candidate))
4995 (error "Line number not found")))
4997 (defun anything-c-action-line-goto (lineno-and-content)
4998 (apply #'anything-goto-file-line (anything-attr 'target-file)
4999 (append lineno-and-content
5000 (list (if (and (anything-attr-defined 'target-file)
5001 (not anything-in-persistent-action))
5002 'find-file-other-window
5003 'find-file)))))
5005 (defun* anything-c-action-file-line-goto (file-line-content &optional (find-file-function #'find-file))
5006 (apply #'anything-goto-file-line file-line-content))
5008 (require 'compile)
5009 (defun anything-c-filtered-candidate-transformer-file-line (candidates source)
5010 (mapcar
5011 (lambda (candidate)
5012 (if (not (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate))
5013 (error "Filename and line number not found")
5014 (let ((filename (match-string 1 candidate))
5015 (lineno (match-string 2 candidate))
5016 (content (match-string 3 candidate)))
5017 (cons (format "%s:%s\n %s"
5018 (propertize filename 'face compilation-info-face)
5019 (propertize lineno 'face compilation-line-face)
5020 content)
5021 (list (expand-file-name
5022 filename
5023 (anything-aif (anything-attr 'default-directory)
5024 (if (functionp it) (funcall it) it)
5025 (and (anything-candidate-buffer)
5026 (buffer-local-value
5027 'default-directory
5028 (anything-candidate-buffer)))))
5029 (string-to-number lineno) content)))))
5030 candidates))
5032 (defun* anything-goto-file-line (file lineno content &optional (find-file-function #'find-file))
5033 (anything-aif (anything-attr 'before-jump-hook)
5034 (funcall it))
5035 (when file (funcall find-file-function file))
5036 (if (anything-attr-defined 'adjust)
5037 (anything-c-goto-line-with-adjustment lineno content)
5038 (anything-goto-line lineno))
5039 (unless (anything-attr-defined 'recenter)
5040 (set-window-start (get-buffer-window anything-current-buffer) (point)))
5041 (anything-aif (anything-attr 'after-jump-hook)
5042 (funcall it))
5043 (when anything-in-persistent-action
5044 (anything-match-line-color-current-line)))
5046 (defun anything-find-file-as-root (candidate)
5047 (find-file (concat "/" anything-su-or-sudo "::" (expand-file-name candidate))))
5049 (defun anything-find-many-files (ignore)
5050 (mapc 'find-file (anything-marked-candidates)))
5052 ;; borrowed from etags.el
5053 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
5054 (defun anything-c-goto-line-with-adjustment (line line-content)
5055 (let ((startpos)
5056 offset found pat)
5057 ;; This constant is 1/2 the initial search window.
5058 ;; There is no sense in making it too small,
5059 ;; since just going around the loop once probably
5060 ;; costs about as much as searching 2000 chars.
5061 (setq offset 1000
5062 found nil
5063 pat (concat (if (eq selective-display t)
5064 "\\(^\\|\^m\\) *" "^ *") ;allow indent
5065 (regexp-quote line-content)))
5066 ;; If no char pos was given, try the given line number.
5067 (setq startpos (progn (anything-goto-line line) (point)))
5068 (or startpos (setq startpos (point-min)))
5069 ;; First see if the tag is right at the specified location.
5070 (goto-char startpos)
5071 (setq found (looking-at pat))
5072 (while (and (not found)
5073 (progn
5074 (goto-char (- startpos offset))
5075 (not (bobp))))
5076 (setq found
5077 (re-search-forward pat (+ startpos offset) t)
5078 offset (* 3 offset))) ; expand search window
5079 (or found
5080 (re-search-forward pat nil t)
5081 (error "not found")))
5082 ;; Position point at the right place
5083 ;; if the search string matched an extra Ctrl-m at the beginning.
5084 (and (eq selective-display t)
5085 (looking-at "\^m")
5086 (forward-char 1))
5087 (beginning-of-line))
5089 (anything-document-attribute 'default-directory "type . file-line"
5090 "`default-directory' to interpret file.")
5091 (anything-document-attribute 'before-jump-hook "type . file-line / line"
5092 "Function to call before jumping to the target location.")
5093 (anything-document-attribute 'after-jump-hook "type . file-line / line"
5094 "Function to call after jumping to the target location.")
5095 (anything-document-attribute 'adjust "type . file-line"
5096 "Search around line matching line contents.")
5097 (anything-document-attribute 'recenter "type . file-line / line"
5098 "`recenter' after jumping.")
5099 (anything-document-attribute 'target-file "type . line"
5100 "Goto line of target-file.")
5102 (defun anything-c-call-interactively (cmd-or-name)
5103 "Execute CMD-OR-NAME as Emacs command.
5104 It is added to `extended-command-history'.
5105 `anything-current-prefix-arg' is used as the command's prefix argument."
5106 (setq extended-command-history
5107 (cons (anything-c-stringify cmd-or-name)
5108 (delete (anything-c-stringify cmd-or-name) extended-command-history)))
5109 (let ((current-prefix-arg anything-current-prefix-arg)
5110 (cmd (anything-c-symbolify cmd-or-name)))
5111 (if (stringp (symbol-function cmd))
5112 (execute-kbd-macro (symbol-function cmd))
5113 (call-interactively cmd))))
5115 (defun anything-c-set-variable (var)
5116 "Set value to VAR interactively."
5117 (interactive)
5118 (let ((sym (anything-c-symbolify var)))
5119 (set sym (eval-minibuffer (format "Set %s: " var)
5120 (prin1-to-string (symbol-value sym))))))
5121 ;; (setq hh 12)
5122 ;; (anything-c-set-variable 'hh)
5124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5125 (defvar anything-match-line-overlay-face nil)
5126 (defvar anything-match-line-overlay nil)
5128 (defun anything-match-line-color-current-line (&optional start end buf face rec)
5129 "Highlight and underline current position"
5130 (let ((args (list (or start (line-beginning-position))
5131 (or end (1+ (line-end-position)))
5132 buf)))
5133 (if (not anything-match-line-overlay)
5134 (setq anything-match-line-overlay (apply 'make-overlay args))
5135 (apply 'move-overlay anything-match-line-overlay args)))
5136 (overlay-put anything-match-line-overlay
5137 'face (or face anything-match-line-overlay-face))
5138 (when rec
5139 (goto-char start)
5140 (recenter)))
5142 (defalias 'anything-persistent-highlight-point 'anything-match-line-color-current-line)
5144 (defface anything-overlay-line-face '((t (:background "IndianRed4" :underline t)))
5145 "Face for source header in the anything buffer." :group 'anything)
5147 (setq anything-match-line-overlay-face 'anything-overlay-line-face)
5149 (defun anything-match-line-cleanup ()
5150 (when anything-match-line-overlay
5151 (delete-overlay anything-match-line-overlay)
5152 (setq anything-match-line-overlay nil)))
5154 (defun anything-match-line-update ()
5155 (when anything-match-line-overlay
5156 (delete-overlay anything-match-line-overlay)
5157 (anything-match-line-color-current-line)))
5159 (add-hook 'anything-cleanup-hook 'anything-match-line-cleanup)
5160 (add-hook 'anything-after-persistent-action-hook 'anything-match-line-update)
5162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5163 ;;; Files
5164 (defun anything-c-transform-file-load-el (actions candidate)
5165 "Add action to load the file CANDIDATE if it is an emacs lisp
5166 file. Else return ACTIONS unmodified."
5167 (if (member (file-name-extension candidate) '("el" "elc"))
5168 (append actions '(("Load Emacs Lisp File" . load-file)))
5169 actions))
5171 (defun anything-c-transform-file-browse-url (actions candidate)
5172 "Add an action to browse the file CANDIDATE if it in a html
5173 file or URL. Else return ACTIONS unmodified."
5174 (let ((browse-action '("Browse with Browser" . browse-url)))
5175 (cond ((string-match "^http\\|^ftp" candidate)
5176 (cons browse-action actions))
5177 ((string-match "\\.html?$" candidate)
5178 (append actions (list browse-action)))
5179 (t actions))))
5181 ;;;; Function
5182 (defun anything-c-transform-function-call-interactively (actions candidate)
5183 "Add an action to call the function CANDIDATE interactively if
5184 it is a command. Else return ACTIONS unmodified."
5185 (if (commandp (intern-soft candidate))
5186 (append actions '(("Call Interactively"
5188 anything-c-call-interactively)))
5189 actions))
5191 ;;;; S-Expressions
5192 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate)
5193 "If CANDIDATE's `car' is a command, then add an action to
5194 evaluate it and put it onto the `command-history'."
5195 (if (commandp (car (read candidate)))
5196 ;; Make it first entry
5197 (cons '("Eval and put onto command-history" .
5198 (lambda (sexp)
5199 (let ((sym (read sexp)))
5200 (eval sym)
5201 (setq command-history
5202 (cons sym command-history)))))
5203 actions)
5204 actions))
5206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5207 ;;; Buffers
5208 (defun anything-c-skip-boring-buffers (buffers)
5209 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp))
5211 (defun anything-c-skip-current-buffer (buffers)
5212 (if anything-allow-skipping-current-buffer
5213 (remove (buffer-name anything-current-buffer) buffers)
5214 buffers))
5216 (defun anything-c-shadow-boring-buffers (buffers)
5217 "Buffers matching `anything-c-boring-buffer-regexp' will be
5218 displayed with the `file-name-shadow' face if available."
5219 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp))
5221 ;;; Files
5222 (defun anything-c-shadow-boring-files (files)
5223 "Files matching `anything-c-boring-file-regexp' will be
5224 displayed with the `file-name-shadow' face if available."
5225 (anything-c-shadow-entries files anything-c-boring-file-regexp))
5227 (defun anything-c-skip-boring-files (files)
5228 "Files matching `anything-c-boring-file-regexp' will be skipped."
5229 (anything-c-skip-entries files anything-c-boring-file-regexp))
5230 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
5232 (defun anything-c-skip-current-file (files)
5233 "Current file will be skipped."
5234 (remove (buffer-file-name anything-current-buffer) files))
5236 (defun anything-c-w32-pathname-transformer (args)
5237 "Change undesirable features of windows pathnames to ones more acceptable to
5238 other candidate transformers."
5239 (if (eq system-type 'windows-nt)
5240 (mapcar (lambda (x)
5241 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x))
5242 (mapcar (lambda (y)
5243 (replace-regexp-in-string "\\\\" "/" y)) args))
5244 args))
5246 (defun anything-c-shorten-home-path (files)
5247 "Replaces /home/user with ~."
5248 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
5249 (getenv "HOME"))))
5250 (mapcar (lambda (file)
5251 (if (and (stringp file) (string-match home file))
5252 (cons (replace-match "~" nil nil file) file)
5253 file))
5254 files)))
5256 ;;; Functions
5257 (defun anything-c-mark-interactive-functions (functions)
5258 "Mark interactive functions (commands) with (i) after the function name."
5259 (let (list)
5260 (loop for function in functions
5261 do (push (cons (concat function
5262 (when (commandp (intern-soft function)) " (i)"))
5263 function)
5264 list)
5265 finally (return (nreverse list)))))
5267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5268 (defvar anything-c-adaptive-done nil
5269 "nil if history information is not yet stored for the current
5270 selection.")
5272 (defvar anything-c-adaptive-history nil
5273 "Contains the stored history information.
5274 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
5276 (defadvice anything-initialize (before anything-c-adaptive-initialize activate)
5277 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
5278 when anything is started."
5279 (setq anything-c-adaptive-done nil))
5281 (defadvice anything-exit-minibuffer (before anything-c-adaptive-exit-minibuffer activate)
5282 "Advise `anything-exit-minibuffer' to store history information
5283 when a candidate is selected with RET."
5284 (anything-c-adaptive-store-selection))
5286 (defadvice anything-select-action (before anything-c-adaptive-select-action activate)
5287 "Advise `anything-select-action' to store history information
5288 when the user goes to the action list with TAB."
5289 (anything-c-adaptive-store-selection))
5291 (defun anything-c-source-use-adaptative-p (&optional source-name)
5292 "Return current source only if it use adaptative history, nil otherwise."
5293 (let* ((source (or source-name (anything-get-current-source)))
5294 (adapt-source (or (assoc-default 'filtered-candidate-transformer
5295 (assoc (assoc-default 'type source)
5296 anything-type-attributes))
5297 (assoc-default 'candidate-transformer
5298 (assoc (assoc-default 'type source)
5299 anything-type-attributes))
5300 (assoc-default 'filtered-candidate-transformer source)
5301 (assoc-default 'candidate-transformer source))))
5302 (if (listp adapt-source)
5303 (when (member 'anything-c-adaptive-sort adapt-source) source)
5304 (when (eq adapt-source 'anything-c-adaptive-sort) source))))
5306 (defun anything-c-adaptive-store-selection ()
5307 "Store history information for the selected candidate."
5308 (unless anything-c-adaptive-done
5309 (setq anything-c-adaptive-done t)
5310 (let ((source (anything-c-source-use-adaptative-p)))
5311 (when source
5312 (let* ((source-name (or (assoc-default 'type source)
5313 (assoc-default 'name source)))
5314 (source-info (or (assoc source-name anything-c-adaptive-history)
5315 (progn
5316 (push (list source-name) anything-c-adaptive-history)
5317 (car anything-c-adaptive-history))))
5318 (selection (anything-get-selection))
5319 (selection-info (progn
5320 (setcdr source-info
5321 (cons
5322 (let ((found (assoc selection (cdr source-info))))
5323 (if (not found)
5324 ;; new entry
5325 (list selection)
5327 ;; move entry to the beginning of the
5328 ;; list, so that it doesn't get
5329 ;; trimmed when the history is
5330 ;; truncated
5331 (setcdr source-info
5332 (delete found (cdr source-info)))
5333 found))
5334 (cdr source-info)))
5335 (cadr source-info)))
5336 (pattern-info (progn
5337 (setcdr selection-info
5338 (cons
5339 (let ((found (assoc anything-pattern (cdr selection-info))))
5340 (if (not found)
5341 ;; new entry
5342 (cons anything-pattern 0)
5344 ;; move entry to the beginning of the
5345 ;; list, so if two patterns used the
5346 ;; same number of times then the one
5347 ;; used last appears first in the list
5348 (setcdr selection-info
5349 (delete found (cdr selection-info)))
5350 found))
5351 (cdr selection-info)))
5352 (cadr selection-info))))
5354 ;; increase usage count
5355 (setcdr pattern-info (1+ (cdr pattern-info)))
5357 ;; truncate history if needed
5358 (if (> (length (cdr selection-info)) anything-c-adaptive-history-length)
5359 (setcdr selection-info
5360 (subseq (cdr selection-info) 0 anything-c-adaptive-history-length))))))))
5362 (if (file-readable-p anything-c-adaptive-history-file)
5363 (load-file anything-c-adaptive-history-file))
5364 (add-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
5366 (defun anything-c-adaptive-save-history ()
5367 "Save history information to file given by `anything-c-adaptive-history-file'."
5368 (interactive)
5369 (with-temp-buffer
5370 (insert
5371 ";; -*- mode: emacs-lisp -*-\n"
5372 ";; History entries used for anything adaptive display.\n")
5373 (prin1 `(setq anything-c-adaptive-history ',anything-c-adaptive-history)
5374 (current-buffer))
5375 (insert ?\n)
5376 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
5377 (unless (interactive-p) 'quiet))))
5379 (defun anything-c-adaptive-sort (candidates source)
5380 "Sort the CANDIDATES for SOURCE by usage frequency.
5381 This is a filtered candidate transformer you can use for the
5382 attribute `filtered-candidate-transformer' of a source in
5383 `anything-sources' or a type in `anything-type-attributes'."
5384 (let* ((source-name (or (assoc-default 'type source)
5385 (assoc-default 'name source)))
5386 (source-info (assoc source-name anything-c-adaptive-history)))
5387 (if (not source-info)
5388 ;; if there is no information stored for this source then do nothing
5389 candidates
5390 ;; else...
5391 (let ((usage
5392 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
5393 ;; pairs
5394 (mapcar (lambda (candidate-info)
5395 (let ((count 0))
5396 (dolist (pattern-info (cdr candidate-info))
5397 (if (not (equal (car pattern-info)
5398 anything-pattern))
5399 (incf count (cdr pattern-info))
5401 ;; if current pattern is equal to the previously
5402 ;; used one then this candidate has priority
5403 ;; (that's why its count is boosted by 10000) and
5404 ;; it only has to compete with other candidates
5405 ;; which were also selected with the same pattern
5406 (setq count (+ 10000 (cdr pattern-info)))
5407 (return)))
5408 (cons (car candidate-info) count)))
5409 (cdr source-info)))
5410 sorted)
5412 ;; sort the list in descending order, so candidates with highest
5413 ;; priorty come first
5414 (setq usage (sort usage (lambda (first second)
5415 (> (cdr first) (cdr second)))))
5417 ;; put those candidates first which have the highest usage count
5418 (dolist (info usage)
5419 (when (member* (car info) candidates
5420 :test 'anything-c-adaptive-compare)
5421 (push (car info) sorted)
5422 (setq candidates (remove* (car info) candidates
5423 :test 'anything-c-adaptive-compare))))
5425 ;; and append the rest
5426 (append (reverse sorted) candidates nil)))))
5428 (defun anything-c-adaptive-compare (x y)
5429 "Compare candidates X and Y taking into account that the
5430 candidate can be in (DISPLAY . REAL) format."
5431 (equal (if (listp x)
5432 (cdr x)
5434 (if (listp y)
5435 (cdr y)
5436 y)))
5438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5439 ;; Plug-in: info-index
5440 (defun* anything-c-info-init (&optional (file (anything-attr 'info-file)))
5441 (let (result)
5442 (unless (anything-candidate-buffer)
5443 (save-window-excursion
5444 (info file)
5445 (let (Info-history
5446 (tobuf (anything-candidate-buffer 'global))
5447 (infobuf (current-buffer))
5448 s e)
5449 (dolist (node (or (anything-attr 'index-nodes) (Info-index-nodes)))
5450 (Info-goto-node node)
5451 (goto-char (point-min))
5452 (while (search-forward "\n* " nil t)
5453 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t)
5454 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result)
5455 (setq s (point-at-bol)
5456 e (point-at-eol))
5457 (with-current-buffer tobuf
5458 (insert-buffer-substring infobuf s e)
5459 (insert "\n"))))))))))
5461 (defun anything-c-info-goto (node-line)
5462 (Info-goto-node (car node-line))
5463 (anything-goto-line (cdr node-line)))
5465 (defun anything-c-info-display-to-real (line)
5466 (and (string-match
5467 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line)
5468 (cons (format "(%s)%s" (anything-attr 'info-file) (match-string 2 line))
5469 (string-to-number (or (match-string 3 line) "1")))))
5471 (defun anything-c-make-info-source (file)
5472 `((name . ,(concat "Info Index: " file))
5473 (info-file . ,file)
5474 (init . anything-c-info-init)
5475 (display-to-real . anything-c-info-display-to-real)
5476 (get-line . buffer-substring)
5477 (candidates-in-buffer)
5478 (action ("Goto node" . anything-c-info-goto))))
5480 (defun anything-compile-source--info-index (source)
5481 (anything-aif (assoc-default 'info-index source)
5482 (anything-c-make-info-source it)
5483 source))
5484 (add-to-list 'anything-compile-source-functions 'anything-compile-source--info-index)
5486 (anything-document-attribute 'info-index "info-index plugin"
5487 "Create a source of info index very easily.
5489 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
5491 (anything-document-attribute 'index-nodes "info-index plugin (optional)"
5492 "Index nodes of info file.
5494 If it is omitted, `Info-index-nodes' is used to collect index nodes.
5495 Some info files are missing index specification.
5497 ex. See `anything-c-source-info-screen'.")
5499 ;; Plug-in: candidates-file
5500 (defun anything-compile-source--candidates-file (source)
5501 (if (assoc-default 'candidates-file source)
5502 `((init anything-p-candidats-file-init
5503 ,@(let ((orig-init (assoc-default 'init source)))
5504 (cond ((null orig-init) nil)
5505 ((functionp orig-init) (list orig-init))
5506 (t orig-init))))
5507 (candidates-in-buffer)
5508 ,@source)
5509 source))
5510 (add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file)
5512 (defun anything-p-candidats-file-init ()
5513 (destructuring-bind (file &optional updating)
5514 (anything-mklist (anything-attr 'candidates-file))
5515 (setq file (anything-interpret-value file))
5516 (with-current-buffer (anything-candidate-buffer (find-file-noselect file))
5517 (when updating
5518 (buffer-disable-undo)
5519 (font-lock-mode -1)
5520 (auto-revert-mode 1)))))
5522 (anything-document-attribute 'candidates-file "candidates-file plugin"
5523 "Use a file as the candidates buffer.
5525 1st argument is a filename, string or function name or variable name.
5526 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
5528 ;; Plug-in: headline
5529 (defun anything-compile-source--anything-headline (source)
5530 (if (assoc-default 'headline source)
5531 (append '((init . anything-headline-init)
5532 (get-line-fn . buffer-substring)
5533 (type . line))
5534 source
5535 '((candidates-in-buffer)
5536 (persistent-help . "Show this line")))
5537 source))
5538 (add-to-list 'anything-compile-source-functions 'anything-compile-source--anything-headline)
5540 (defun anything-headline-init ()
5541 (when (and (anything-current-buffer-is-modified)
5542 (with-current-buffer anything-current-buffer
5543 (eval (or (anything-attr 'condition) t))))
5544 (anything-headline-make-candidate-buffer
5545 (anything-attr 'headline)
5546 (anything-attr 'subexp))))
5548 (anything-document-attribute 'headline "Headline plug-in"
5549 "Regexp string for anything-headline to scan.")
5550 (anything-document-attribute 'condition "Headline plug-in"
5551 "A sexp representing the condition to use anything-headline.")
5552 (anything-document-attribute 'subexp "Headline plug-in"
5553 "Display (match-string-no-properties subexp).")
5556 (defun anything-headline-get-candidates (regexp subexp)
5557 (with-current-buffer anything-current-buffer
5558 (save-excursion
5559 (goto-char (point-min))
5560 (if (functionp regexp) (setq regexp (funcall regexp)))
5561 (let (hierarchy curhead)
5562 (flet ((matched ()
5563 (if (numberp subexp)
5564 (cons (match-string-no-properties subexp) (match-beginning subexp))
5565 (cons (buffer-substring (point-at-bol) (point-at-eol))
5566 (point-at-bol))))
5567 (hierarchies (headlines)
5568 (1+ (loop for (_ . hierarchy) in headlines
5569 maximize hierarchy)))
5570 (vector-0-n (v n)
5571 (loop for i from 0 to hierarchy
5572 collecting (aref curhead i)))
5573 (arrange (headlines)
5574 (loop with curhead = (make-vector (hierarchies headlines) "")
5575 for ((str . pt) . hierarchy) in headlines
5576 do (aset curhead hierarchy str)
5577 collecting
5578 (cons
5579 (mapconcat 'identity (vector-0-n curhead hierarchy) " / ")
5580 pt))))
5581 (if (listp regexp)
5582 (arrange
5583 (sort
5584 (loop for re in regexp
5585 for hierarchy from 0
5586 do (goto-char (point-min))
5587 appending
5588 (loop
5589 while (re-search-forward re nil t)
5590 collect (cons (matched) hierarchy)))
5591 (lambda (a b) (> (cdar b) (cdar a)))))
5592 (loop while (re-search-forward regexp nil t)
5593 collect (matched))))))))
5596 (defun anything-headline-make-candidate-buffer (regexp subexp)
5597 (with-current-buffer (anything-candidate-buffer 'local)
5598 (loop for (content . pos) in (anything-headline-get-candidates regexp subexp)
5599 do (insert
5600 (format "%5d:%s\n"
5601 (with-current-buffer anything-current-buffer
5602 (line-number-at-pos pos))
5603 content)))))
5605 (defun anything-headline-goto-position (pos recenter)
5606 (goto-char pos)
5607 (unless recenter
5608 (set-window-start (get-buffer-window anything-current-buffer) (point))))
5610 (defun anything-revert-buffer (candidate)
5611 (with-current-buffer candidate
5612 (when (buffer-modified-p)
5613 (revert-buffer t t))))
5615 (defun anything-revert-marked-buffers (candidate)
5616 (dolist (i (anything-marked-candidates))
5617 (anything-revert-buffer i)))
5619 (defun anything-kill-marked-buffers (candidate)
5620 (dolist (i (anything-marked-candidates))
5621 (kill-buffer i)))
5623 ;; Plug-in: persistent-help
5624 (defun anything-compile-source--persistent-help (source)
5625 (append source '((header-line . anything-persistent-help-string))))
5626 (add-to-list 'anything-compile-source-functions 'anything-compile-source--persistent-help)
5628 (defun anything-persistent-help-string ()
5629 (substitute-command-keys
5630 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
5631 (or (anything-attr 'persistent-help)
5632 (anything-aif (or (assoc-default 'persistent-action (anything-get-current-source))
5633 (assoc-default 'action (anything-get-current-source))
5635 (cond ((symbolp it) (symbol-name it))
5636 ((listp it) (or (ignore-errors (caar it)) ""))))
5638 " (keeping session)")))
5640 (anything-document-attribute 'persistent-help "persistent-help plug-in"
5641 "A string to explain persistent-action of this source.
5642 It also accepts a function or a variable name.")
5644 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
5646 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5648 (defun anything-delete-marked-files (candidate)
5649 (anything-aif (anything-marked-candidates)
5650 (if (y-or-n-p (format "Delete *%s Files " (length it)))
5651 (progn
5652 (dolist (i it)
5653 (set-text-properties 0 (length i) nil i)
5654 (anything-c-delete-file i))
5655 (message "%s Files deleted" (length it)))
5656 (message "(No deletions performed)"))
5657 (set-text-properties 0 (length candidate) nil candidate)
5658 (if (y-or-n-p (format "Really delete file `%s' " candidate))
5659 (progn
5660 (anything-c-delete-file candidate)
5661 (message "1 file deleted"))
5662 (message "(No deletions performed)"))))
5664 (defun anything-ediff-marked-buffers (candidate &optional merge)
5665 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
5666 With optional arg `merge' call `ediff-merge-buffers'."
5667 (let ((lg-lst (length (anything-marked-candidates)))
5668 buf1 buf2)
5669 (case lg-lst
5671 (error "Error:You have to mark at least 1 buffer"))
5673 (setq buf1 anything-current-buffer
5674 buf2 (first (anything-marked-candidates))))
5676 (setq buf1 (first (anything-marked-candidates))
5677 buf2 (second (anything-marked-candidates))))
5679 (error "Error:To much buffers marked!")))
5680 (if merge
5681 (ediff-merge-buffers buf1 buf2)
5682 (ediff-buffers buf1 buf2))))
5684 (defun anything-bookmark-get-bookmark-from-name (bmk)
5685 "Return bookmark name even if it is a bookmark with annotation.
5686 e.g prepended with *.
5687 Return nil if bmk is not a valid bookmark."
5688 (let ((bookmark (replace-regexp-in-string "\*" "" bmk)))
5689 (if (assoc bookmark bookmark-alist)
5690 bookmark
5691 (when (assoc bmk bookmark-alist)
5692 bmk))))
5694 (defun anything-delete-marked-bookmarks (elm)
5695 "Delete this bookmark or all marked bookmarks."
5696 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm)))
5697 (anything-aif (anything-marked-candidates)
5698 (dolist (i it)
5699 (let ((bmk (anything-bookmark-get-bookmark-from-name i)))
5700 (bookmark-delete bmk 'batch)))
5701 (bookmark-delete bookmark 'batch))))
5703 (defun anything-bookmark-active-region-maybe (candidate)
5704 "Active saved region if this bookmark have one."
5705 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5706 (condition-case nil
5707 (when (and (boundp bmkext-use-region-flag)
5708 bmkext-use-region-flag)
5709 (let ((bmk-name (or (bmkext-get-buffer-name bookmark)
5710 (file-name-nondirectory
5711 (bookmark-get-filename bookmark)))))
5712 (when bmk-name
5713 (with-current-buffer bmk-name
5714 (setq deactivate-mark nil)))))
5715 (error nil))))
5717 (defun anything-require-or-error (feature function)
5718 (or (require feature nil t)
5719 (error "Need %s to use `%s'." feature function)))
5721 (defun anything-find-buffer-on-elscreen (candidate)
5722 "Open buffer in new screen, if marked buffers open all in elscreens."
5723 (anything-require-or-error 'elscreen 'anything-find-buffer-on-elscreen)
5724 (anything-aif (anything-marked-candidates)
5725 (dolist (i it)
5726 (let ((target-screen (elscreen-find-screen-by-buffer
5727 (get-buffer i) 'create)))
5728 (elscreen-goto target-screen)))
5729 (let ((target-screen (elscreen-find-screen-by-buffer
5730 (get-buffer candidate) 'create)))
5731 (elscreen-goto target-screen))))
5733 (defun anything-elscreen-find-file (file)
5734 (anything-require-or-error 'elscreen 'anything-elscreen-find-file)
5735 (elscreen-find-file file))
5737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5739 ;;; Type Attributes
5740 (define-anything-type-attribute 'buffer
5741 `((action
5742 ,@(if pop-up-frames
5743 '(("Switch to buffer other window" . switch-to-buffer-other-window)
5744 ("Switch to buffer" . switch-to-buffer))
5745 '(("Switch to buffer" . switch-to-buffer)
5746 ("Switch to buffer other window" . switch-to-buffer-other-window)
5747 ("Switch to buffer other frame" . switch-to-buffer-other-frame)))
5748 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen))
5749 ("Display buffer" . display-buffer)
5750 ("Revert buffer" . anything-revert-buffer)
5751 ("Revert Marked buffers" . anything-revert-marked-buffers)
5752 ("Kill buffer" . kill-buffer)
5753 ("Kill Marked buffers" . anything-kill-marked-buffers)
5754 ("Ediff Marked buffers" . anything-ediff-marked-buffers)
5755 ("Ediff Merge marked buffers" . (lambda (candidate)
5756 (anything-ediff-marked-buffers candidate t))))
5757 (persistent-help . "Show this buffer")
5758 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers))
5759 "Buffer or buffer name.")
5761 (define-anything-type-attribute 'file
5762 `((action
5763 ,@(if pop-up-frames
5764 '(("Find file other window" . find-file-other-window)
5765 ("Find file(s)" . anything-find-many-files)
5766 ("Find file as root" . anything-find-file-as-root))
5767 '(("Find file" . anything-find-many-files)
5768 ("Find file as root" . anything-find-file-as-root)
5769 ("Find file other window" . find-file-other-window)
5770 ("Find file other frame" . find-file-other-frame)))
5771 ("Open dired in file's directory" . anything-c-open-dired)
5772 ("Delete file(s)" . anything-delete-marked-files)
5773 ("Open file externally" . anything-c-open-file-externally)
5774 ("Open file with default tool" . anything-c-open-file-with-default-tool))
5775 (persistent-help . "Show this file")
5776 (action-transformer anything-c-transform-file-load-el
5777 anything-c-transform-file-browse-url)
5778 (candidate-transformer anything-c-w32-pathname-transformer
5779 anything-c-skip-current-file
5780 anything-c-skip-boring-files
5781 anything-c-shorten-home-path))
5782 "File name.")
5784 (define-anything-type-attribute 'command
5785 `((action ("Call interactively" . anything-c-call-interactively)
5786 ("Describe command" . anything-c-describe-function)
5787 ("Add command to kill ring" . anything-c-kill-new)
5788 ("Go to command's definition" . anything-c-find-function))
5789 ;; Sort commands according to their usage count.
5790 (filtered-candidate-transformer . anything-c-adaptive-sort))
5791 "Command. (string or symbol)")
5793 (define-anything-type-attribute 'function
5794 '((action ("Describe function" . anything-c-describe-function)
5795 ("Add function to kill ring" . anything-c-kill-new)
5796 ("Go to function's definition" . anything-c-find-function))
5797 (action-transformer anything-c-transform-function-call-interactively)
5798 (candidate-transformer anything-c-mark-interactive-functions))
5799 "Function. (string or symbol)")
5801 (define-anything-type-attribute 'variable
5802 '((action ("Describe variable" . anything-c-describe-variable)
5803 ("Add variable to kill ring" . anything-c-kill-new)
5804 ("Go to variable's definition" . anything-c-find-variable)
5805 ("Set variable" . anything-c-set-variable)))
5806 "Variable.")
5808 (define-anything-type-attribute 'sexp
5809 '((action ("Eval s-expression" . (lambda (c) (eval (read c))))
5810 ("Add s-expression to kill ring" . kill-new))
5811 (action-transformer anything-c-transform-sexp-eval-command-sexp))
5812 "String representing S-Expressions.")
5814 (define-anything-type-attribute 'bookmark
5815 `((action
5816 ("Jump to bookmark" . (lambda (candidate)
5817 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate))
5818 (current-prefix-arg anything-current-prefix-arg))
5819 (bookmark-jump bookmark))
5820 (anything-update)
5821 (anything-bookmark-active-region-maybe candidate)))
5822 ("Jump to BM other window" . (lambda (candidate)
5823 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5824 (bookmark-jump-other-window bookmark))
5825 (anything-update)
5826 (anything-bookmark-active-region-maybe candidate)))
5827 ("Bookmark edit annotation" . (lambda (candidate)
5828 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5829 (bookmark-edit-annotation bookmark))))
5830 ("Bookmark show annotation" . (lambda (candidate)
5831 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5832 (bookmark-show-annotation bookmark))))
5833 ("Delete bookmark(s)" . anything-delete-marked-bookmarks)
5834 ,@(when (fboundp 'bmkext-edit-bookmark)
5835 '(("Edit Bookmark" . (lambda (candidate)
5836 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5837 (bmkext-edit-bookmark bookmark))))))
5838 ("Rename bookmark" . (lambda (candidate)
5839 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5840 (bookmark-rename bookmark))))
5841 ("Relocate bookmark" . (lambda (candidate)
5842 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate)))
5843 (bookmark-relocate bookmark))))))
5844 "Bookmark name.")
5846 (define-anything-type-attribute 'line
5847 '((display-to-real . anything-c-display-to-real-line)
5848 (action ("Go to Line" . anything-c-action-line-goto)))
5849 "LINENO:CONTENT string, eg. \" 16:foo\".
5851 Optional `target-file' attribute is a name of target file.
5853 Optional `before-jump-hook' attribute is a function with no
5854 arguments which is called before jumping to position.
5856 Optional `after-jump-hook' attribute is a function with no
5857 arguments which is called after jumping to position.
5859 If `adjust' attribute is specified, searches the line whose
5860 content is CONTENT near the LINENO.
5862 If `recenter' attribute is specified, the line is displayed at
5863 the center of window, otherwise at the top of window.
5866 (define-anything-type-attribute 'file-line
5867 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line)
5868 (multiline)
5869 (action ("Go to" . anything-c-action-file-line-goto)))
5870 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
5872 Optional `default-directory' attribute is a default-directory
5873 FILENAME is interpreted.
5875 Optional `before-jump-hook' attribute is a function with no
5876 arguments which is called before jumping to position.
5878 Optional `after-jump-hook' attribute is a function with no
5879 arguments which is called after jumping to position.
5881 If `adjust' attribute is specified, searches the line whose
5882 content is CONTENT near the LINENO.
5884 If `recenter' attribute is specified, the line is displayed at
5885 the center of window, otherwise at the top of window.
5888 (define-anything-type-attribute 'timer
5889 '((real-to-display . anything-c-timer-real-to-display)
5890 (action ("Cancel Timer" . cancel-timer)))
5891 "Timer.")
5893 ;;;; unit test
5894 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
5895 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
5896 (dont-compile
5897 (when (fboundp 'expectations)
5898 (expectations
5899 (desc "candidates-file plug-in")
5900 (expect '(anything-p-candidats-file-init)
5901 (assoc-default 'init
5902 (car (anything-compile-sources
5903 '(((name . "test")
5904 (candidates-file . "test.txt")))
5905 '(anything-compile-source--candidates-file)))))
5906 (expect '(anything-p-candidats-file-init
5907 (lambda () 1))
5908 (assoc-default 'init
5909 (car (anything-compile-sources
5910 '(((name . "test")
5911 (candidates-file . "test.txt")
5912 (init . (lambda () 1))))
5913 '(anything-compile-source--candidates-file)))))
5914 (expect '(anything-p-candidats-file-init
5915 (lambda () 1))
5916 (assoc-default 'init
5917 (car (anything-compile-sources
5918 '(((name . "test")
5919 (candidates-file . "test.txt")
5920 (init (lambda () 1))))
5921 '(anything-compile-source--candidates-file)))))
5922 (desc "anything-c-source-buffers")
5923 (expect '(("Buffers" ("foo" "curbuf")))
5924 (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
5925 (let ((anything-c-boring-buffer-regexp
5926 (rx (or
5927 (group bos " ")
5928 "*anything"
5929 ;; echo area
5930 " *Echo Area" " *Minibuf"))))
5931 (flet ((buffer-name (x) x))
5932 (anything-test-candidates 'anything-c-source-buffers))))
5933 (desc "anything-c-stringify")
5934 (expect "str1"
5935 (anything-c-stringify "str1"))
5936 (expect "str2"
5937 (anything-c-stringify 'str2))
5938 (desc "anything-c-symbolify")
5939 (expect 'sym1
5940 (anything-c-symbolify "sym1"))
5941 (expect 'sym2
5942 (anything-c-symbolify 'sym2)))))
5945 (provide 'anything-config)
5947 ;;; Local Variables:
5948 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
5949 ;;; End:
5951 ;; How to save (DO NOT REMOVE!!)
5952 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
5953 ;;; anything-config.el ends here
5955 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
5956 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
5957 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
5958 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
5959 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
5960 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
5961 ;;; LocalWords: dotimes Thierry online vname
5962 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
5963 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
5964 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
5965 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
5966 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
5967 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
5968 ;;; LocalWords: startpos noselect dont desc