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