1 ;;; anything-config.el --- Predefined configurations for `anything.el'
3 ;; Filename: anything-config.el
5 ;; Description: Predefined configurations for `anything.el'
6 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
7 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
8 ;; rubikitch <rubikitch@ruby-lang.org>
9 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
10 ;; Copyright (C) 2007 ~ 2010, Tassilo Horn, all rights reserved.
11 ;; Copyright (C) 2009, Andy Stewart, all rights reserved.
12 ;; Copyright (C) 2009 ~ 2010, rubikitch, all rights reserved.
13 ;; Copyright (C) 2009 ~ 2010, Thierry Volpiatto, all rights reserved.
14 ;; Created: 2009-02-16 21:38:23
16 ;; URL: http://www.emacswiki.org/emacs/download/anything-config.el
17 ;; Keywords: anything, anything-config
18 ;; Compatibility: GNU Emacs 22 ~ 23
20 ;; Features that might be required by this library:
25 ;;; This file is NOT part of GNU Emacs
29 ;; This program is free software; you can redistribute it and/or modify
30 ;; it under the terms of the GNU General Public License as published by
31 ;; the Free Software Foundation; either version 3, or (at your option)
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;; GNU General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING. If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
46 ;; If this file does not work, upgrade anything.el!
47 ;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
51 ;; Predefined configurations for `anything.el'
53 ;; For quick start, try `anything-for-files' to open files.
55 ;; To configure anything you should define anything command
56 ;; with your favorite sources, like below:
58 ;; (defun my-anything ()
60 ;; (anything-other-buffer
61 ;; '(anything-c-source-buffers
62 ;; anything-c-source-file-name-history
63 ;; anything-c-source-info-pages
64 ;; anything-c-source-info-elisp
65 ;; anything-c-source-man-pages
66 ;; anything-c-source-locate
67 ;; anything-c-source-emacs-commands)
70 ;; Then type M-x my-anything to use sources.
72 ;; Defining own command is better than setup `anything-sources'
73 ;; directly, because you can define multiple anything commands with
74 ;; different sources. Each anything command should have own anything
75 ;; buffer, because M-x anything-resume revives anything command.
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'.
93 ;; Preconfigured `anything' for gentoo linux.
94 ;; `anything-surfraw-only'
95 ;; Preconfigured `anything' for surfraw.
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.
105 ;; Preconfigured `anything' for BBDB.
107 ;; Preconfigured `anything' for Locate.
108 ;; `anything-w3m-bookmarks'
109 ;; Preconfigured `anything' for w3m bookmark.
111 ;; Preconfigured `anything' for color.
112 ;; `anything-bm-list'
113 ;; Preconfigured `anything' for visible bookmarks.
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.
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'
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.
193 ;; Preconfigured Anything for Occur source.
194 ;; `anything-create-from-anything'
195 ;; Run `anything-create' from `anything' as a fallback.
197 ;; Preconfigured `anything' to do many create actions from STRING.
199 ;; Preconfigured `anything' for top command.
200 ;; `anything-select-xfont'
201 ;; Preconfigured `anything' to select Xfont.
203 ;; Preconfigured `anything' : frontend of APT package manager.
204 ;; `anything-c-shell-command-if-needed'
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'
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'
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'
245 ;; `anything-c-enable-eval-defun-hack'
247 ;; `anything-tramp-verbose'
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
401 ;; Change log of this file is found at
402 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
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>
422 ;; Evaluate (autodoc-update-all) before commit. This function
423 ;; generates anything-c-source-* / functions / options list.
425 ;; Install also http://www.emacswiki.org/emacs/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
437 ;; - Fix documentation, now many functions haven't documentations.
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'."
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'. "
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."
482 :group
'anything-config
)
484 (defcustom anything-c-adaptive-history-length
50
485 "Maximum number of candidates stored for a source."
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."
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."
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."
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."
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."
517 :group
'anything-config
)
519 (defcustom anything-c-boring-buffer-regexp
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."
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
540 ;; Boring directories
541 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
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."
552 :group
'anything-config
)
554 (defcustom anything-kill-ring-threshold
10
555 "*Minimum length to be listed by `anything-c-source-kill-ring'."
557 :group
'anything-config
)
559 (defcustom anything-su-or-sudo
"su"
560 "What command to use for root access."
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."
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."
583 :group
'anything-config
)
585 (defcustom anything-allow-skipping-current-buffer t
586 "Show current buffer or not in anything buffer"
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 ...)."
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."
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\"."
611 :group
'anything-config
)
614 ;; It is replaced by `anything-help'
615 (defun anything-c-describe-anything-bindings ()
616 "[OBSOLETE] Describe `anything' bindings."
618 (anything-run-after-quit
620 (with-current-buffer (get-buffer-create "*Anything Help*")
623 (substitute-command-keys
624 "The keys that are defined for `anything' are:
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))
634 (defun anything-c-list-preconfigured-anything ()
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
)))
643 collect
(format "\\[%s] : %s\n" sym
(match-string 0 doc
))))
645 (setq anything-help-message
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
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
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
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))
707 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
709 (defun anything-for-files ()
710 "Preconfigured `anything' for opening files.
711 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
713 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
716 (defun anything-info-at-point ()
717 "Preconfigured `anything' for searching info at point."
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*"))
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."
729 (anything-other-buffer 'anything-c-source-kill-ring
"*anything kill-ring*"))
732 (defun anything-minibuffer-history ()
733 "Preconfigured `anything' for `minibuffer-history'."
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
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
))
754 (defun anything-gentoo ()
755 "Preconfigured `anything' for gentoo linux."
757 (anything-other-buffer '(anything-c-source-gentoo
758 anything-c-source-use-flags
)
759 "*anything gentoo*"))
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."
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))
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*")))
784 (defun anything-imenu ()
785 "Preconfigured `anything' for `imenu'."
787 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
790 (defun anything-google-suggest ()
791 "Preconfigured `anything' for google search with google suggest."
793 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
796 (defun anything-yahoo-suggest ()
797 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
799 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
801 ;;; Converted from anything-show-*-only
803 (defun anything-for-buffers ()
804 "Preconfigured `anything' for buffer."
806 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
809 (defun anything-bbdb ()
810 "Preconfigured `anything' for BBDB."
812 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
815 (defun anything-locate ()
816 "Preconfigured `anything' for Locate."
818 (anything-other-buffer 'anything-c-source-locate
"*anything locate*"))
821 (defun anything-w3m-bookmarks ()
822 "Preconfigured `anything' for w3m bookmark."
824 (anything-other-buffer 'anything-c-source-w3m-bookmarks
"*anything w3m bookmarks*"))
827 (defun anything-colors ()
828 "Preconfigured `anything' for color."
830 (anything-other-buffer '(anything-c-source-colors anything-c-source-customize-face
)
831 "*anything colors*"))
834 (defun anything-bm-list ()
835 "Preconfigured `anything' for visible bookmarks."
837 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*"))
840 (defun anything-timers ()
841 "Preconfigured `anything' for timers."
843 (anything-other-buffer '(anything-c-source-absolute-time-timers
844 anything-c-source-idle-time-timers
)
845 "*anything timers*"))
847 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
850 (defun anything-kill-buffers ()
851 "Preconfigured `anything' to kill buffer you selected."
854 '(((name .
"Kill Buffers")
855 (candidates . anything-c-buffer-list
)
857 ("Kill Buffer" .
(lambda (candidate)
858 (kill-buffer candidate
)
859 (anything-kill-buffers)
865 (defun anything-query-replace-regexp (&rest args
)
866 "Preconfigured `anything' : Drop-in replacement of `query-replace-regexp' with building regexp visually."
869 (anything-c-regexp-base "Query Replace Regexp: "
870 '((name .
"Lines matching Regexp")
871 (mode-line .
"Set replace start line and type RET.")
872 (action . anything-c-query-replace-args
)))))
875 (list (car common
) (cadr common
) (caddr common
)
876 ;; These are done separately here
877 ;; so that command-history will record these expressions
878 ;; rather than the values they had this time.
880 ;; This idea is borrowed from original `query-replace-regexp'.
881 (if (and transient-mark-mode mark-active
)
883 (if (and transient-mark-mode mark-active
)
885 (apply 'query-replace-regexp args
))
888 (defun anything-regexp ()
889 "Preconfigured `anything' : It is like `re-builder'. It helps buliding regexp and replacement."
891 (anything-c-regexp-base
893 '((name .
"Regexp Builder")
894 (mode-line .
"Press TAB to select action.")
896 ("Kill Regexp as sexp" .
897 (lambda (x) (anything-c-regexp-kill-new (prin1-to-string (funcall (anything-attr 'regexp
))))))
898 ("Query Replace Regexp" .
899 (lambda (x) (apply 'query-replace-regexp
(anything-c-query-replace-args (point)))))
901 (lambda (x) (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
)))))))))
903 (defun anything-c-query-replace-args (start-point)
904 ;; create arguments of `query-replace-regexp'.
905 (let ((region-only (and transient-mark-mode mark-active
))
906 (regexp (funcall (anything-attr 'regexp
))))
909 (query-replace-read-to regexp
910 (format "Query replace regexp %s%s%s with: "
911 (if region-only
"in region " "")
913 (if current-prefix-arg
"(word) " ""))
915 current-prefix-arg
)))
917 (defun anything-c-regexp-get-line (s e
)
921 (format "%5d: %s" (line-number-at-pos s
) (buffer-substring s e
))
923 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
925 collect
(format "\n $%d = %s"
926 i
(match-string i
))))
928 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
929 ;; It is implementation problem of candidates-in-buffer.
933 ;; Shut up byte compiler
934 (defun anything-goto-line (numline)
935 "Replacement of `goto-line'."
936 (goto-char (point-min))
937 (forward-line (1- numline
)))
939 (defun anything-c-regexp-persistent-action (pt)
941 (anything-persistent-highlight-point))
943 (defun anything-c-regexp-base (prompt attributes
)
945 (let ((anything-compile-source-functions
946 ;; rule out anything-match-plugin because the input is one regexp.
947 (delq 'anything-compile-source--match-plugin
948 (copy-sequence anything-compile-source-functions
)))
950 '((init .
(lambda () (anything-candidate-buffer anything-current-buffer
)))
951 (candidates-in-buffer)
952 (get-line . anything-c-regexp-get-line
)
953 (persistent-action . anything-c-regexp-persistent-action
)
954 (persistent-help .
"Show this line")
957 (if (and transient-mark-mode mark-active
)
958 (narrow-to-region (region-beginning) (region-end)))
963 '((regexp .
(lambda () anything-pattern
)))
967 `((name .
,(concat (assoc-default 'name attributes
) " (sexp)")))
969 '((candidates-in-buffer
970 .
(lambda () (let ((anything-pattern (eval (read anything-pattern
))))
971 (anything-candidates-in-buffer))))
972 (regexp .
(lambda () (eval (read anything-pattern
)))))
974 nil prompt nil nil
"*anything regexp*"))))
976 ;; (anything-c-regexp-base "Regexp: " '((name . "test")))
977 ;; (anything-c-regexp-base "Regexp: " '((name . "test") (candidates-in-buffer . (lambda () (let ((anything-pattern (eval (read anything-pattern)))) (anything-candidates-in-buffer))))))
979 (defun anything-c-regexp-kill-new (input)
981 (message "Killed: %s" input
))
983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
985 (defun anything-insert-buffer-name ()
986 "Insert buffer name."
988 (anything-insert-string
989 (with-current-buffer anything-current-buffer
990 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
993 (defun anything-insert-symbol ()
994 "Insert current symbol."
996 (anything-insert-string
997 (with-current-buffer anything-current-buffer
999 (buffer-substring (beginning-of-thing 'symbol
)
1000 (end-of-thing 'symbol
))))))
1002 (defun anything-insert-selection ()
1003 "Insert current selection."
1005 (anything-insert-string
1006 (with-current-buffer anything-current-buffer
1007 (anything-get-selection))))
1009 (defun anything-show-buffer-only ()
1010 "[OBSOLETE] Only show sources about buffer.
1011 Use `anything-for-buffers' instead."
1013 (anything-set-source-filter '("Buffers")))
1015 (defun anything-show-bbdb-only ()
1016 "[OBSOLETE] Only show sources about BBDB.
1017 Use `anything-bbdb' instead."
1019 (anything-set-source-filter '("BBDB")))
1021 (defun anything-show-locate-only ()
1022 "[OBSOLETE] Only show sources about Locate.
1023 Use `anything-locate' instead."
1025 (anything-set-source-filter '("Locate")))
1027 (defun anything-show-info-only ()
1028 "[OBSOLETE] Only show sources about Info.
1029 Use `anything-info-at-point' instead."
1031 (anything-set-source-filter '("Info Pages"
1033 "Info Common-Lisp")))
1035 (defun anything-show-imenu-only ()
1036 "[OBSOLETE] Only show sources about Imenu.
1037 Use `anything-imenu' instead."
1039 (anything-set-source-filter '("Imenu")))
1041 (defun anything-show-files-only ()
1042 "[OBSOLETE] Only show sources about File.
1043 Use `anything-for-files' instead."
1045 (anything-set-source-filter '("File Name History"
1046 "Files from Current Directory"
1049 (defun anything-show-w3m-bookmarks-only ()
1050 "[OBSOLETE] Only show source about w3m bookmark.
1051 Use `anything-w3m-bookmarks' instead."
1053 (anything-set-source-filter '("W3m Bookmarks")))
1055 (defun anything-show-colors-only ()
1056 "[OBSOLETE] Only show source about color.
1057 Use `anything-colors' instead."
1059 (anything-set-source-filter '("Colors"
1060 "Customize Faces")))
1062 (defun anything-show-kill-ring-only ()
1063 "[OBSOLETE] Only show source about kill ring.
1064 Use `anything-show-kill-ring' instead."
1066 (anything-set-source-filter '("Kill Ring")))
1068 (defun anything-show-this-source-only ()
1069 "Only show this source."
1071 (setq anything-candidate-number-limit
9999)
1072 (anything-set-source-filter
1073 (list (assoc-default 'name
(anything-get-current-source)))))
1075 (defun anything-test-sources ()
1076 "List all anything sources for test.
1077 The output is sexps which are evaluated by \\[eval-last-sexp]."
1079 (with-output-to-temp-buffer "*Anything Test Sources*"
1080 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
1081 (apropos-internal "^anything-c-source" #'boundp
))
1082 (pop-to-buffer standard-output
)))
1084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1085 ;;; For compatibility
1086 (unless (fboundp 'region-active-p
)
1087 (defun region-active-p ()
1088 "Return t if Transient Mark mode is enabled and the mark is active.
1090 Most commands that act on the region if it is active and
1091 Transient Mark mode is enabled, and on the text near point
1092 otherwise, should use `use-region-p' instead. That function
1093 checks the value of `use-empty-active-region' as well."
1094 (and transient-mark-mode mark-active
)))
1096 (defun anything-nest (&rest same-as-anything
)
1097 "Nested `anything'. If you use `anything' within `anything', use it."
1098 (with-selected-window (anything-window)
1099 (let (anything-current-position
1100 anything-current-buffer
1101 (orig-anything-buffer anything-buffer
)
1105 anything-compiled-sources
1106 anything-buffer-chars-modified-tick
1107 (anything-samewindow t
)
1108 (enable-recursive-minibuffers t
))
1110 (apply #'anything same-as-anything
)
1111 (anything-initialize-overlays orig-anything-buffer
)
1112 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
1114 (defun anything-displaying-source-names ()
1115 "Display sources name."
1116 (with-current-buffer anything-buffer
1117 (goto-char (point-min))
1119 while
(setq pos
(next-single-property-change (point) 'anything-header
))
1121 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
1122 do
(forward-line 1))))
1124 (defun anything-select-source ()
1127 (let ((default (assoc-default 'name
(anything-get-current-source)))
1128 (source-names (anything-displaying-source-names))
1129 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
1130 (anything-get-sources))))
1131 (setq anything-candidate-number-limit
9999)
1133 (let (anything-source-filter)
1134 (anything-nest '(((name .
"Anything Source")
1135 (candidates . source-names
)
1136 (action . identity
))
1137 ((name .
"Anything Source (ALL)")
1138 (candidates . all-source-names
)
1139 (action . identity
)))
1141 default
"*anything select source*"))
1142 (anything-set-source-filter (list it
))
1143 (anything-set-source-filter nil
))))
1145 (defun anything-insert-string (str)
1147 (delete-minibuffer-contents)
1150 (defun anything-c-match-on-file-name (candidate)
1151 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1152 (string-match anything-pattern
(file-name-nondirectory candidate
)))
1154 (defun anything-c-match-on-directory-name (candidate)
1155 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1156 (anything-aif (file-name-directory candidate
)
1157 (string-match anything-pattern it
)))
1159 (defun anything-c-string-match (candidate)
1160 "Return non-nil if `anything-pattern' match CANDIDATE.
1161 The match is done with `string-match'."
1162 (string-match anything-pattern candidate
))
1164 ;; `anything-c-compose' is no more needed, it is for compatibility.
1165 (defalias 'anything-c-compose
'anything-compose
)
1167 (defun anything-c-skip-entries (list regexp
)
1168 "Remove entries which matches REGEXP from LIST."
1169 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
1172 (defun anything-c-shadow-entries (list regexp
)
1173 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1174 (mapcar (lambda (file)
1175 ;; Add shadow face property to boring files.
1176 (let ((face (if (facep 'file-name-shadow
)
1178 ;; fall back to default on XEmacs
1180 (if (string-match regexp file
)
1181 (setq file
(propertize file
'face face
))))
1185 (defsubst anything-c-stringify
(str-or-sym)
1186 "Get string of STR-OR-SYM."
1187 (if (stringp str-or-sym
)
1189 (symbol-name str-or-sym
)))
1191 (defsubst anything-c-symbolify
(str-or-sym)
1192 "Get symbol of STR-OR-SYM."
1193 (if (symbolp str-or-sym
)
1195 (intern str-or-sym
)))
1197 (defun anything-c-describe-function (func)
1198 "FUNC is symbol or string."
1199 (describe-function (anything-c-symbolify func
)))
1201 (defun anything-c-describe-variable (var)
1202 "VAR is symbol or string."
1203 (describe-variable (anything-c-symbolify var
)))
1205 (defun anything-c-find-function (func)
1206 "FUNC is symbol or string."
1207 (find-function (anything-c-symbolify func
)))
1209 (defun anything-c-find-variable (var)
1210 "VAR is symbol or string."
1211 (find-variable (anything-c-symbolify var
)))
1213 (defun anything-c-kill-new (string &optional replace yank-handler
)
1214 "STRING is symbol or string."
1215 (kill-new (anything-c-stringify string
) replace yank-handler
))
1217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1219 (defvar anything-current-prefix-arg nil
1220 "`current-prefix-arg' when selecting action.
1221 It is cleared after executing action.")
1223 (defadvice anything-exit-minibuffer
(before anything-current-prefix-arg activate
)
1224 (unless anything-current-prefix-arg
1225 (setq anything-current-prefix-arg current-prefix-arg
)))
1227 (add-hook 'anything-after-action-hook
1228 (lambda () (setq anything-current-prefix-arg nil
)))
1231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1232 (defadvice eval-defun
(after anything-source-hack activate
)
1233 "See `anything-c-enable-eval-defun-hack'."
1234 (when anything-c-enable-eval-defun-hack
1235 (let ((varsym (save-excursion
1236 (beginning-of-defun)
1238 (when (memq (read (current-buffer)) '(defvar setq
))
1239 (read (current-buffer))))))
1240 (when (string-match "^anything-c-source-" (symbol-name varsym
))
1241 (anything varsym
)))))
1242 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1245 (defun anything-c-create-summary ()
1246 "Create `anything' summary."
1248 (goto-char (point-min))
1249 (loop while
(re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$" nil t
)
1250 collect
(cond ((match-beginning 1)
1251 (cons 'section
(match-string-no-properties 1)))
1252 ((match-beginning 2)
1254 (cons (match-string-no-properties 2)
1255 (assoc-default 'name
(symbol-value (intern (match-string-no-properties 2)))))))
1256 ((match-beginning 3)
1258 (cons (match-string-no-properties 3)
1259 (assoc-default 'name
(symbol-value (intern (match-string-no-properties 3)))))))))))
1261 ;; (find-epp (anything-c-create-summary))
1263 (defun anything-c-insert-summary ()
1264 "Insert `anything' summary."
1266 (goto-char (point-min))
1267 (search-forward ";; Below are complete source list you can setup in")
1269 (delete-region (point)
1270 (progn (search-forward ";;; Change log:" nil t
)
1271 (forward-line -
1) (point)))
1274 for
(kind . value
) in
(anything-c-create-summary)
1276 do
(cond ((eq kind
'section
)
1278 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
1279 (insert ";; " value
":\n")
1282 (insert ";; `" (car value
) "' (" (cdr value
) ")\n")))
1283 finally
(align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))))
1284 ;; (anything-c-insert-summary)
1286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1288 (defun anything-c-buffer-list ()
1289 "Return the list of names of buffers with boring buffers filtered out.
1290 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1291 The first buffer in the list will be the last recently used
1292 buffer that is not the current buffer."
1293 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
1294 (append (cdr buffers
) (list (car buffers
)))))
1296 (defvar anything-c-source-buffers
1297 '((name .
"Buffers")
1298 (candidates . anything-c-buffer-list
)
1300 ;; (anything 'anything-c-source-buffers)
1302 (defvar anything-c-source-buffer-not-found
1303 '((name .
"Create buffer")
1306 ;; (anything 'anything-c-source-buffer-not-found)
1309 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
1310 "*Face used for directory headings in dired buffers."
1313 (defface anything-file-name
1314 '((t (:foreground
"Blue")))
1315 "*Face used for file names (without suffixes) in dired buffers."
1318 (defface anything-dir-priv
1319 '((t (:foreground
"DarkRed" :background
"LightGray")))
1320 "*Face used for directory privilege indicator (d) in dired buffers."
1323 (defvar anything-c-buffers-face1
'anything-dir-priv
)
1324 (defvar anything-c-buffers-face2
'font-lock-type-face
)
1325 (defvar anything-c-buffers-face3
'italic
)
1326 (eval-when-compile (require 'dired
))
1327 (defun anything-c-highlight-buffers (buffers)
1329 (loop for i in buffers
1330 if
(rassoc (get-buffer i
) dired-buffers
)
1331 collect
(propertize i
1332 'face anything-c-buffers-face1
1333 'help-echo
(car (rassoc (get-buffer i
) dired-buffers
)))
1334 if
(buffer-file-name (get-buffer i
))
1335 collect
(propertize i
1336 'face anything-c-buffers-face2
1337 'help-echo
(buffer-file-name (get-buffer i
)))
1338 if
(and (not (rassoc (get-buffer i
) dired-buffers
))
1339 (not (buffer-file-name (get-buffer i
))))
1340 collect
(propertize i
1341 'face anything-c-buffers-face3
)))
1343 (defvar anything-c-source-buffers
+
1344 '((name .
"Buffers")
1345 (candidates . anything-c-buffer-list
)
1347 (candidate-transformer anything-c-skip-current-buffer
1348 anything-c-highlight-buffers
1349 anything-c-skip-boring-buffers
)
1350 (persistent-action . anything-c-buffers
+-persistent-action
)
1351 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1353 (defun anything-c-buffers+-persistent-action
(name)
1355 (with-current-buffer item
1356 (if (and (buffer-modified-p)
1357 (buffer-file-name (current-buffer)))
1361 (kill-buffer item
))))
1363 (switch-to-buffer item
)))
1364 (if current-prefix-arg
1367 (anything-delete-current-selection))
1370 ;; (anything 'anything-c-source-buffers+)
1374 ;;; File name history
1375 (defvar anything-c-source-file-name-history
1376 '((name .
"File Name History")
1377 (candidates . file-name-history
)
1378 (match anything-c-match-on-file-name
1379 anything-c-match-on-directory-name
)
1381 ;; (anything 'anything-c-source-file-name-history)
1383 ;;; Files in current dir
1384 (defvar anything-c-source-files-in-current-dir
1385 '((name .
"Files from Current Directory")
1386 (candidates .
(lambda ()
1387 (with-current-buffer anything-current-buffer
1388 (directory-files default-directory
))))
1389 ;; volatile is not needed, I think.
1391 ;; (anything 'anything-c-source-files-in-current-dir)
1393 (defvar anything-c-files-face1
'anything-dir-priv
)
1394 (defvar anything-c-files-face2
'anything-file-name
)
1395 (defun anything-c-highlight-files (files)
1396 (loop for i in files
1397 if
(file-directory-p i
)
1398 collect
(propertize (file-name-nondirectory i
)
1399 'face anything-c-files-face1
1400 'help-echo
(expand-file-name i
))
1402 collect
(propertize (file-name-nondirectory i
)
1403 'face anything-c-files-face2
1404 'help-echo
(expand-file-name i
))))
1407 (defvar anything-c-source-files-in-current-dir
+
1408 '((name .
"Files from Current Directory")
1409 (candidates .
(lambda ()
1410 (with-current-buffer anything-current-buffer
1411 (directory-files default-directory t
))))
1412 (candidate-transformer anything-c-highlight-files
)
1413 ;; volatile is not needed, I think.
1416 ;; (anything 'anything-c-source-files-in-current-dir+)
1418 ;;; Anything replacement of file name completion for `find-file' and friends.
1420 (defvar anything-c-find-files-doc-header
(format " (`%s':Go to precedent level)"
1421 (if window-system
"C-." "C-l"))
1422 "*The doc that is inserted in the Name header of a find-files or dired source.")
1424 (defvar anything-c-source-find-files
1425 `((name .
,(concat "Find Files" anything-c-find-files-doc-header
))
1426 ;; It is needed for filenames with capital letters
1429 (setq ffap-newfile-prompt t
)))
1430 (candidates . anything-find-files-get-candidates
)
1431 (candidate-transformer anything-c-highlight-ffiles
)
1432 (persistent-action . anything-find-files-persistent-action
)
1433 (persistent-help .
"Expand Candidate")
1435 (action .
,(delq nil
`(("Find File" . find-file-at-point
)
1436 ("Find file in Dired" . anything-c-point-file-in-dired
)
1437 ,(and (locate-library "elscreen") '("Find file in Elscreen" . anything-elscreen-find-file
))
1438 ("Complete at point" . anything-c-insert-file-name-completion-at-point
)
1439 ("Delete File(s)" . anything-delete-marked-files
)
1440 ("Find file as root" . anything-find-file-as-root
)
1441 ("Open file externally" . anything-c-open-file-externally
)
1442 ("Find file other window" . find-file-other-window
)
1443 ("Find file other frame" . find-file-other-frame
))))))
1445 ;; (anything 'anything-c-source-find-files)
1447 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
1448 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1449 If LEVEL is positive reduce from end else from beginning.
1450 If UNIX-CLOSE is non--nil close filename with /.
1451 If EXPAND is non--nil expand-file-name."
1452 (let* ((exp-fname (expand-file-name fname
))
1453 (fname-list (split-string (if (or (string= fname
"~/") expand
)
1454 exp-fname fname
) "/" t
))
1455 (len (length fname-list
))
1456 (pop-list (if (< level
0)
1457 (subseq fname-list
(* level -
1))
1458 (subseq fname-list
0 (- len level
))))
1459 (result (mapconcat 'identity pop-list
"/"))
1460 (empty (string= result
"")))
1461 (when unix-close
(setq result
(concat result
"/")))
1462 (if (string-match "^~" result
)
1463 (if (string= result
"~/") "~/" result
)
1465 (if empty
"../" (concat "../" result
))
1466 (cond ((and (eq system-type
'windows-nt
) empty
)
1468 ((and (not empty
) (eq system-type
'windows-nt
))
1472 (concat "/" result
)))))))
1474 (defun anything-find-files-or-dired-p ()
1475 "Test if current source is a dired or find-files source."
1476 (let ((ff-sources '("Find Files" "Copy Files"
1477 "Rename Files" "Symlink Files"
1478 "Hardlink Files" "Write File" "Insert File"))
1479 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
1481 (dolist (i ff-sources
)
1482 (when (equal cur-source
(concat i anything-c-find-files-doc-header
))
1483 (throw 'break t
))))))
1485 (defun anything-find-files-down-one-level (arg)
1486 "Go down one level like unix command `cd ..'.
1487 If prefix numeric arg is given go ARG level down."
1489 (when (anything-find-files-or-dired-p)
1490 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
:unix-close t
:expand t
)))
1491 (with-selected-window (minibuffer-window)
1492 (delete-minibuffer-contents)
1493 (insert new-pattern
)))))
1495 ;; `C-.' doesn't work in terms use `C-l' instead.
1497 (define-key anything-map
(kbd "C-.") 'anything-find-files-down-one-level
)
1498 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))
1500 (defun anything-c-point-file-in-dired (file)
1501 "Put point on filename FILE in dired buffer."
1502 (dired (file-name-directory file
))
1503 (dired-goto-file file
))
1505 (defun anything-create-tramp-name (fname)
1506 "Build filename for `anything-pattern' like /su:: or /sudo::."
1507 (apply #'tramp-make-tramp-file-name
1509 with v
= (tramp-dissect-file-name fname
)
1510 for i across v collect i
)))
1512 (defun anything-find-files-get-candidates ()
1513 "Create candidate list for `anything-c-source-find-files'."
1514 (let* ( ; Don't try to tramp connect before entering the second ":".
1515 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1516 (path (cond ((string-match "^~" anything-pattern
)
1517 (replace-match (getenv "HOME") nil t anything-pattern
))
1518 ((string-match tramp-file-name-regexp anything-pattern
)
1519 (let ((tramp-name (anything-create-tramp-name
1520 (match-string 0 anything-pattern
))))
1521 (replace-match tramp-name nil t anything-pattern
)))
1522 (t anything-pattern
)))
1523 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
1524 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1525 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1527 (flet ((tramp-handle-directory-files
1528 (directory &optional full match nosort files-only
)
1529 "Like `directory-files' for Tramp files."
1530 ;; FILES-ONLY is valid for XEmacs only.
1531 (when (file-directory-p directory
)
1532 (setq directory
(file-name-as-directory (expand-file-name directory
)))
1533 (let ((temp (nreverse (file-name-all-completions "" directory
)))
1537 (setq item
(directory-file-name (pop temp
)))
1538 (when (and (or (null match
) (string-match match item
))
1539 (or (null files-only
)
1541 (and (equal files-only t
) (file-regular-p item
))
1542 ;; Directories only.
1543 (file-directory-p item
)))
1544 (push (if full
(concat directory item
) item
)
1546 (if nosort result
(sort result
'string
<))))))
1548 (set-text-properties 0 (length path
) nil path
)
1549 (setq anything-pattern path
)
1550 (cond ((or (file-regular-p path
)
1551 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
1553 ((string= anything-pattern
"") (directory-files "/" t
))
1554 ((file-directory-p path
) (directory-files path t
))
1558 (directory-files (file-name-directory path
) t
)))))))
1560 (defface anything-dired-symlink-face
1561 '((t (:foreground
"DarkOrange")))
1562 "*Face used for symlinks in `anything-find-files'."
1565 (defun anything-c-highlight-ffiles (files)
1566 "Candidate transformer for `anything-c-source-find-files'."
1567 (loop for i in files
1568 if
(file-symlink-p i
)
1569 collect
(propertize i
'face
'anything-dired-symlink-face
1570 'help-echo
(file-truename i
)) into a
1571 if
(file-directory-p i
)
1572 collect
(propertize i
'face anything-c-files-face1
) into a
1574 collect
(propertize i
'face anything-c-files-face2
) into a
1578 (defun anything-find-files-persistent-action (candidate)
1579 "Open subtree CANDIDATE without quitting anything.
1580 If CANDIDATE is not a directory expand CANDIDATE filename.
1581 If CANDIDATE is alone, open file CANDIDATE filename."
1582 (flet ((insert-in-minibuffer (elm)
1583 (with-selected-window (minibuffer-window)
1584 (delete-minibuffer-contents)
1585 (set-text-properties 0 (length elm
) nil elm
)
1587 (cond ((and (file-directory-p candidate
) (file-symlink-p candidate
))
1588 (insert-in-minibuffer (file-name-as-directory
1590 (expand-file-name candidate
)))))
1591 ((file-directory-p candidate
)
1592 (insert-in-minibuffer (file-name-as-directory
1593 (expand-file-name candidate
))))
1594 ((file-symlink-p candidate
)
1595 (insert-in-minibuffer (file-truename candidate
)))
1596 (t ; First hit on C-z expand CANDIDATE second hit open file.
1597 (let ((new-pattern (anything-get-selection anything-last-buffer
))
1598 (num-lines-buf (with-current-buffer anything-last-buffer
1599 (count-lines (point-min) (point-max)))))
1600 (if (> num-lines-buf
3)
1601 (insert-in-minibuffer new-pattern
) (find-file candidate
)))))))
1603 (defun anything-c-insert-file-name-completion-at-point (candidate)
1604 "Insert file name completion at point."
1605 (let* ((end (point))
1606 (guess (thing-at-point 'filename
))
1607 (full-path-p (string-match (concat "^" (getenv "HOME")) guess
)))
1608 (set-text-properties 0 (length candidate
) nil candidate
)
1609 (when (and guess
(not (string= guess
"")))
1610 (search-backward guess
(- (point) (length guess
)))
1611 (delete-region (point) end
)
1613 (insert (expand-file-name candidate
))
1614 (insert (abbreviate-file-name candidate
))))))
1617 ;;; FIXME completing on regexps don't erase initial text.
1619 ;; (defun anything-c-insert-file-name-completion-at-point (candidate)
1620 ;; "Insert filename completion at point."
1621 ;; (let* ((end (point))
1622 ;; (guess (anything-get-regexp-filename-at-point))
1623 ;; (full-path-p (string-match (concat "^" (getenv "HOME")) (cdr guess))))
1624 ;; (set-text-properties 0 (length candidate) nil candidate)
1625 ;; (delete-region (- (point) (car guess)) end)
1627 ;; (insert (expand-file-name candidate))
1628 ;; (insert (abbreviate-file-name candidate)))))
1631 ;; (defun anything-get-regexp-filename-at-point ()
1632 ;; "Return filename at point even if filename contain regexps."
1633 ;; (let ((thing-at-point-file-name-chars "\\(^\\|~/\\|/\\)*[:alnum:]_.${}#%,:"))
1635 ;; (loop with count = 0
1636 ;; for tap = (thing-at-point 'filename)
1637 ;; while (and (string= tap "") (not (looking-back "\"\\|\'\\|\n")))
1638 ;; do (progn (forward-char -1) (incf count))
1639 ;; finally return (cons (+ count (length tap)) tap)))))
1642 (defun anything-find-files ()
1643 "Preconfigured `anything' for anything implementation of `find-file'."
1645 (anything 'anything-c-source-find-files
1646 (anything-find-files-input (ffap-guesser) (thing-at-point 'filename
))
1647 "Find Files or Url: " nil nil
"*Anything Find Files*"))
1649 (defun anything-find-files-input (fap tap
)
1650 "Default input of `anything-find-files'."
1651 (let* ((file-p (and fap
(file-exists-p fap
)
1653 (file-name-directory (expand-file-name tap
)))))
1654 (input (if file-p
(expand-file-name tap
) fap
)))
1655 (or input
(expand-file-name default-directory
))))
1657 ;;; Anything completion for `write-file'.==> C-x C-w
1658 (defvar anything-c-source-write-file
1659 `((name .
,(concat "Write File" anything-c-find-files-doc-header
))
1660 (candidates . anything-find-files-get-candidates
)
1661 (candidate-transformer anything-c-highlight-ffiles
)
1662 (persistent-action . anything-find-files-persistent-action
)
1663 (persistent-help .
"Expand Candidate")
1666 (("Write File" .
(lambda (candidate)
1667 (write-file candidate
'confirm
)))))))
1670 (defun anything-write-file ()
1671 "Preconfigured `anything' providing completion for `write-file'."
1673 (anything 'anything-c-source-write-file
1674 (expand-file-name default-directory
)
1675 "Write buffer to file: " nil nil
"*Anything write file*"))
1677 ;;; Anything completion for `insert-file'.==> C-x i
1678 (defvar anything-c-source-insert-file
1679 `((name .
,(concat "Insert File" anything-c-find-files-doc-header
))
1680 (candidates . anything-find-files-get-candidates
)
1681 (candidate-transformer anything-c-highlight-ffiles
)
1682 (persistent-action . anything-find-files-persistent-action
)
1683 (persistent-help .
"Expand Candidate")
1686 (("Insert File" .
(lambda (candidate)
1687 (when (y-or-n-p (format "Really insert %s in %s "
1688 candidate anything-current-buffer
))
1689 (insert-file candidate
))))))))
1692 (defun anything-insert-file ()
1693 "Preconfigured `anything' providing completion for `insert-file'."
1695 (anything 'anything-c-source-insert-file
1696 (expand-file-name default-directory
)
1697 "Insert file: " nil nil
"*Anything insert file*"))
1699 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
1700 (defvar anything-c-source-copy-files
1701 `((name .
,(concat "Copy Files" anything-c-find-files-doc-header
))
1702 (candidates . anything-find-files-get-candidates
)
1703 (candidate-transformer anything-c-highlight-ffiles
)
1704 (persistent-action . anything-find-files-persistent-action
)
1705 (persistent-help .
"Expand Candidate")
1709 .
(lambda (candidate)
1710 (anything-dired-action candidate
:action
'copy
)))
1712 .
(lambda (candidate)
1713 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
1716 (defvar anything-c-source-rename-files
1717 `((name .
,(concat "Rename Files" anything-c-find-files-doc-header
))
1718 (candidates . anything-find-files-get-candidates
)
1719 (candidate-transformer anything-c-highlight-ffiles
)
1720 (persistent-action . anything-find-files-persistent-action
)
1721 (persistent-help .
"Expand Candidate")
1725 .
(lambda (candidate)
1726 (anything-dired-action candidate
:action
'rename
)))
1727 ("Rename and Follow"
1728 .
(lambda (candidate)
1729 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
1731 (defvar anything-c-source-symlink-files
1732 `((name .
,(concat "Symlink Files" anything-c-find-files-doc-header
))
1733 (candidates . anything-find-files-get-candidates
)
1734 (candidate-transformer anything-c-highlight-ffiles
)
1735 (persistent-action . anything-find-files-persistent-action
)
1736 (persistent-help .
"Expand Candidate")
1739 (("Symlink File" .
(lambda (candidate)
1740 (anything-dired-action candidate
:action
'symlink
)))
1741 ("RelSymlink File" .
(lambda (candidate)
1742 (anything-dired-action candidate
:action
'relsymlink
)))))))
1745 (defvar anything-c-source-hardlink-files
1746 `((name .
,(concat "Hardlink Files" anything-c-find-files-doc-header
))
1747 (candidates . anything-find-files-get-candidates
)
1748 (candidate-transformer anything-c-highlight-ffiles
)
1749 (persistent-action . anything-find-files-persistent-action
)
1750 (persistent-help .
"Expand Candidate")
1753 (("Hardlink File" .
(lambda (candidate)
1754 (anything-dired-action candidate
:action
'hardlink
)))))))
1756 (defun* anything-dired-action
(candidate &key action follow
)
1757 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
1758 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
1759 (let ((files (dired-get-marked-files))
1761 ('copy
'dired-copy-file
)
1762 ('rename
'dired-rename-file
)
1763 ('symlink
'make-symbolic-link
)
1764 ('relsymlink
'dired-make-relative-symlink
)
1765 ('hardlink
'dired-hardlink
)))
1766 (marker (case action
1767 ((copy rename
) dired-keep-marker-copy
)
1768 ('symlink dired-keep-marker-symlink
)
1769 ('relsymlink dired-keep-marker-relsymlink
)
1770 ('hardlink dired-keep-marker-hardlink
))))
1772 fn
(symbol-name action
) files
1773 (if (file-directory-p candidate
)
1774 ;; When CANDIDATE is a directory, build file-name in this directory.
1775 ;; Else we use CANDIDATE.
1777 (expand-file-name (file-name-nondirectory from
) candidate
))
1778 #'(lambda (from) candidate
))
1781 (let* ((src (car files
))
1782 (dest (expand-file-name candidate
))
1783 (basename-src (if (file-directory-p src
)
1785 (directory-file-name src
)
1786 (file-name-directory src
))
1787 (file-name-nondirectory src
)))
1788 (fname (if (file-directory-p dest
)
1789 (concat (file-name-as-directory dest
)
1792 (anything-c-point-file-in-dired fname
)))))
1795 (defun* anything-dired-do-action-on-file
(&key action
)
1796 (let* ((files (dired-get-marked-files))
1797 (len (length files
))
1798 (fname (if (> len
1)
1799 (format "* %d Files" len
)
1801 (source (case action
1802 ('copy
'anything-c-source-copy-files
)
1803 ('rename
'anything-c-source-rename-files
)
1804 ('symlink
'anything-c-source-symlink-files
)
1805 ('hardlink
'anything-c-source-hardlink-files
)))
1806 (prompt-fm (case action
1807 ('copy
"Copy %s to: ")
1808 ('rename
"Rename %s to: ")
1809 ('symlink
"Symlink %s to: ")
1810 ('hardlink
"Hardlink %s to: ")))
1811 (buffer (case action
1812 ('copy
"*Anything Copy Files*")
1813 ('rename
"*Anything Rename Files*")
1814 ('symlink
"*Anything Symlink Files*")
1815 ('hardlink
"*Anything Hardlink Files*"))))
1817 (or (dired-dwim-target-directory)
1818 (expand-file-name default-directory
))
1819 (format prompt-fm fname
) nil nil buffer
)))
1823 (defun anything-dired-rename-file ()
1824 "Preconfigured `anything' to rename files from dired."
1826 (anything-dired-do-action-on-file :action
'rename
))
1829 (defun anything-dired-copy-file ()
1830 "Preconfigured `anything' to copy files from dired."
1832 (anything-dired-do-action-on-file :action
'copy
))
1835 (defun anything-dired-symlink-file ()
1836 "Preconfigured `anything' to symlink files from dired."
1838 (anything-dired-do-action-on-file :action
'symlink
))
1841 (defun anything-dired-hardlink-file ()
1842 "Preconfigured `anything' to hardlink files from dired."
1844 (anything-dired-do-action-on-file :action
'hardlink
))
1846 (defvar anything-dired-bindings nil
)
1848 (defun anything-dired-bindings (&optional arg
)
1849 "Replace usual dired commands `C' and `R' by anything ones.
1850 When call interactively toggle dired bindings and anything bindings.
1851 When call non--interactively with arg > 0, enable anything bindings.
1852 You can put (anything-dired-binding 1) in init file to enable anything bindings."
1854 (if (or (when arg
(> arg
0)) (not anything-dired-bindings
))
1856 (define-key dired-mode-map
(kbd "C") 'anything-dired-copy-file
)
1857 (define-key dired-mode-map
(kbd "R") 'anything-dired-rename-file
)
1858 (define-key dired-mode-map
(kbd "S") 'anything-dired-symlink-file
)
1859 (define-key dired-mode-map
(kbd "H") 'anything-dired-hardlink-file
)
1860 (setq anything-dired-bindings t
))
1861 (define-key dired-mode-map
(kbd "C") 'dired-do-copy
)
1862 (define-key dired-mode-map
(kbd "R") 'dired-do-rename
)
1863 (define-key dired-mode-map
(kbd "S") 'dired-do-symlink
)
1864 (define-key dired-mode-map
(kbd "H") 'dired-do-hardlink
)
1865 (setq anything-dired-bindings nil
)))
1868 (defvar anything-c-source-file-cache-initialized nil
)
1870 (defvar anything-c-file-cache-files nil
)
1872 (defvar anything-c-source-file-cache
1873 '((name .
"File Cache")
1875 (require 'filecache nil t
)
1876 (unless anything-c-source-file-cache-initialized
1877 (setq anything-c-file-cache-files
1878 (loop for item in file-cache-alist append
1879 (destructuring-bind (base &rest dirs
) item
1880 (loop for dir in dirs collect
1881 (concat dir base
)))))
1882 (defadvice file-cache-add-file
(after file-cache-list activate
)
1883 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
1884 (setq anything-c-source-file-cache-initialized t
))))
1885 (candidates . anything-c-file-cache-files
)
1886 (match anything-c-match-on-file-name
1887 anything-c-match-on-directory-name
)
1889 ;; (anything 'anything-c-source-file-cache)
1892 (defvar anything-c-locate-options
1894 ((eq system-type
'darwin
) '("locate"))
1895 ((eq system-type
'berkeley-unix
) '("locate" "-i"))
1896 (t '("locate" "-i" "-r")))
1897 "A list where the `car' is the name of the locat program followed by options.
1898 The search pattern will be appended, so the
1899 \"-r\" option should be the last option.")
1901 (defvar anything-c-source-locate
1903 (candidates .
(lambda ()
1904 (apply 'start-process
"locate-process" nil
1905 (append anything-c-locate-options
1906 (list anything-pattern
)))))
1908 (requires-pattern .
3)
1910 "Source for retrieving files matching the current input pattern with locate.")
1911 ;; (anything 'anything-c-source-locate)
1914 (defvar anything-c-source-recentf
1915 '((name .
"Recentf")
1918 (or recentf-mode
(recentf-mode 1))
1919 ;; Big value empowers anything/recentf
1920 (when (and (numberp recentf-max-saved-items
)
1921 (<= recentf-max-saved-items
20))
1922 (setq recentf-max-saved-items
500))))
1923 (candidates . recentf-list
)
1924 (match anything-c-match-on-file-name
1925 anything-c-match-on-directory-name
)
1927 "See (info \"(emacs)File Conveniences\").
1928 if `recentf-max-saved-items' is too small, set it to 500.")
1929 ;; (anything 'anything-c-source-recentf)
1932 (eval-when-compile (require 'ffap
))
1933 (defvar anything-c-source-ffap-guesser
1934 '((name .
"File at point")
1935 (init .
(lambda () (require 'ffap
)))
1936 (candidates .
(lambda ()
1938 (with-current-buffer anything-current-buffer
1942 ;; (anything 'anything-c-source-ffap-guesser)
1944 ;;; ffap with line number
1945 (defun anything-c-ffap-file-line-at-point ()
1946 "Get (FILENAME . LINENO) at point."
1947 (anything-aif (let (ffap-alist) (ffap-file-at-point))
1950 (when (and (search-forward it nil t
)
1951 (looking-at ":\\([0-9]+\\)"))
1952 (cons it
(string-to-number (match-string 1)))))))
1954 (defvar anything-c-ffap-line-location nil
1955 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
1956 It is cleared after jumping line.")
1958 (defun anything-c-ffap-line-candidates ()
1959 (with-current-buffer anything-current-buffer
1960 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
1961 (when anything-c-ffap-line-location
1962 (destructuring-bind (file . line
) anything-c-ffap-line-location
1963 (list (cons (format "%s (line %d)" file line
) file
)))))
1965 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
1966 (defun anything-c-ffap-line-goto-line ()
1967 (when (car anything-c-ffap-line-location
)
1970 (with-selected-window (get-buffer-window
1971 (get-file-buffer (car anything-c-ffap-line-location
)))
1972 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
1973 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
1974 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
1976 (defvar anything-c-source-ffap-line
1977 '((name .
"File/Lineno at point")
1978 (init .
(lambda () (require 'ffap
)))
1979 (candidates . anything-c-ffap-line-candidates
)
1981 ;; (anything 'anything-c-source-ffap-line)
1983 ;;; list of files gleaned from every dired buffer
1984 (defun anything-c-files-in-all-dired-candidates ()
1988 (cond ((listp dir
) ;filelist
1990 ((equal "" (file-name-nondirectory dir
)) ;dir
1991 (directory-files dir t
))
1993 (file-expand-wildcards dir t
))))
1995 (mapcar (lambda (buf)
1997 (when (eq major-mode
'dired-mode
)
1998 (if (consp dired-directory
)
1999 (cdr dired-directory
) ;filelist
2000 dired-directory
))) ;dir or wildcard
2002 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2004 (defvar anything-c-source-files-in-all-dired
2005 '((name .
"Files in all dired buffer.")
2006 (candidates . anything-c-files-in-all-dired-candidates
)
2008 ;; (anything 'anything-c-source-files-in-all-dired)
2012 (defvar anything-c-info-pages nil
2013 "All info pages on system.
2014 Will be calculated the first time you invoke anything with this
2017 (defvar anything-c-source-info-pages
2018 `((name .
"Info Pages")
2019 (candidates .
(lambda ()
2020 (if anything-c-info-pages
2021 anything-c-info-pages
2022 (setq anything-c-info-pages
2023 (save-window-excursion
2026 (Info-find-node "dir" "top")
2027 (goto-char (point-min))
2028 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2030 (while (re-search-forward info-topic-regexp nil t
)
2031 (add-to-list 'topics
(match-string-no-properties 1)))
2032 (goto-char (point-min))
2035 (action .
(("Show with Info" .
(lambda (node-str)
2036 (info (replace-regexp-in-string "^[^:]+: "
2039 (requires-pattern .
2)))
2040 ;; (anything 'anything-c-source-info-pages)
2043 ;;; Use info-index plug-in. Note that `name' attribute is
2044 ;;; not needed but `anything-c-insert-summary' uses it.
2046 (defvar anything-c-source-info-elisp
2047 '((name .
"Info index: elisp")
2048 (info-index .
"elisp")))
2049 ;; (anything 'anything-c-source-info-elisp)
2052 (defvar anything-c-source-info-cl
2053 '((name .
"Info index: cl")
2054 (info-index .
"cl")))
2055 ;; (anything 'anything-c-source-info-cl)
2058 (defvar anything-c-source-info-org
2059 '((name .
"Info index: org")
2060 (info-index .
"org")))
2061 ;; (anything 'anything-c-source-info-org)
2063 ;; Info Index ratpoison
2064 (defvar anything-c-source-info-ratpoison
2065 '((name .
"Info index: ratpoison")
2066 (info-index .
"ratpoison")))
2067 ;; (anything 'anything-c-source-info-ratpoison)
2070 (defvar anything-c-source-info-zsh
2071 '((name .
"Info index: zsh")
2072 (info-index .
"zsh")))
2073 ;; (anything 'anything-c-source-info-zsh)
2076 (defvar anything-c-source-info-bash
2077 '((name .
"Info index: bash")
2078 (info-index .
"bash")))
2079 ;; (anything 'anything-c-source-info-bash)
2081 ;; Info Index coreutils
2082 (defvar anything-c-source-info-coreutils
2083 '((name .
"Info index: coreutils")
2084 (info-index .
"coreutils")))
2085 ;; (anything 'anything-c-source-info-coreutils)
2087 ;; Info Index fileutils
2088 (defvar anything-c-source-info-fileutils
2089 '((name .
"Info index: fileutils")
2090 (info-index .
"fileutils")))
2091 ;; (anything 'anything-c-source-info-fileutils)
2094 (defvar anything-c-source-info-find
2095 '((name .
"Info index: find")
2096 (info-index .
"find")))
2097 ;; (anything 'anything-c-source-info-find)
2099 ;; Info Index sh-utils
2100 (defvar anything-c-source-info-sh-utils
2101 '((name .
"Info index: sh-utils")
2102 (info-index .
"sh-utils")))
2103 ;; (anything 'anything-c-source-info-sh-utils)
2105 ;; Info Index textutils
2106 (defvar anything-c-source-info-textutils
2107 '((name .
"Info index: textutils")
2108 (info-index .
"textutils")))
2109 ;; (anything 'anything-c-source-info-textutils)
2112 (defvar anything-c-source-info-libc
2113 '((name .
"Info index: libc")
2114 (info-index .
"libc")))
2115 ;; (anything 'anything-c-source-info-libc)
2118 (defvar anything-c-source-info-make
2119 '((name .
"Info index: make")
2120 (info-index .
"make")))
2121 ;; (anything 'anything-c-source-info-make)
2123 ;; Info Index automake
2124 (defvar anything-c-source-info-automake
2125 '((name .
"Info index: automake")
2126 (info-index .
"automake")))
2127 ;; (anything 'anything-c-source-info-automake)
2129 ;; Info Index autoconf
2130 (defvar anything-c-source-info-autoconf
2131 '((name .
"Info index: autoconf")
2132 (info-index .
"autoconf")))
2133 ;; (anything 'anything-c-source-info-autoconf)
2135 ;; Info Index emacs-lisp-intro
2136 (defvar anything-c-source-info-emacs-lisp-intro
2137 '((name .
"Info index: emacs-lisp-intro")
2138 (info-index .
"emacs-lisp-intro")))
2139 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2142 (defvar anything-c-source-info-emacs
2143 '((name .
"Info index: emacs")
2144 (info-index .
"emacs")))
2145 ;; (anything 'anything-c-source-info-emacs)
2148 (defvar anything-c-source-info-elib
2149 '((name .
"Info index: elib")
2150 (info-index .
"elib")))
2151 ;; (anything 'anything-c-source-info-elib)
2154 (defvar anything-c-source-info-eieio
2155 '((name .
"Info index: eieio")
2156 (info-index .
"eieio")))
2157 ;; (anything 'anything-c-source-info-eieio)
2159 ;; Info Index gauche-refe
2160 (defvar anything-c-source-info-gauche-refe
2161 '((name .
"Info index: gauche")
2162 (info-index .
"gauche-refe")))
2163 ;; (anything 'anything-c-source-info-gauche-refe)
2166 (defvar anything-c-source-info-guile
2167 '((name .
"Info index: guile")
2168 (info-index .
"guile")))
2169 ;; (anything 'anything-c-source-info-guile)
2171 ;; Info Index guile-tut
2172 (defvar anything-c-source-info-guile-tut
2173 '((name .
"Info index: guile-tut")
2174 (info-index .
"guile-tut")))
2175 ;; (anything 'anything-c-source-info-guile-tut)
2178 (defvar anything-c-source-info-goops
2179 '((name .
"Info index: goops")
2180 (info-index .
"goops")))
2181 ;; (anything 'anything-c-source-info-goops)
2183 ;; Info Index screen
2184 (defvar anything-c-source-info-screen
2185 '((name .
"Info index: screen")
2186 (info-index .
"screen")
2187 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2188 ;; (anything 'anything-c-source-info-screen)
2191 (defvar anything-c-source-info-latex
2192 '((name .
"Info index: latex")
2193 (info-index .
"latex")))
2194 ;; (anything 'anything-c-source-info-latex)
2197 (defvar anything-c-source-info-gawk
2198 '((name .
"Info index: gawk")
2199 (info-index .
"gawk")))
2200 ;; (anything 'anything-c-source-info-gawk)
2203 (defvar anything-c-source-info-sed
2204 '((name .
"Info index: sed")
2205 (info-index .
"sed")))
2206 ;; (anything 'anything-c-source-info-sed)
2209 (defvar anything-c-source-info-m4
2210 '((name .
"Info index: m4")
2211 (info-index .
"m4")))
2212 ;; (anything 'anything-c-source-info-m4)
2215 (defvar anything-c-source-info-wget
2216 '((name .
"Info index: wget")
2217 (info-index .
"wget")))
2218 ;; (anything 'anything-c-source-info-wget)
2220 ;; Info Index binutils
2221 (defvar anything-c-source-info-binutils
2222 '((name .
"Info index: binutils")
2223 (info-index .
"binutils")))
2224 ;; (anything 'anything-c-source-info-binutils)
2227 (defvar anything-c-source-info-as
2228 '((name .
"Info index: as")
2229 (info-index .
"as")))
2230 ;; (anything 'anything-c-source-info-as)
2233 (defvar anything-c-source-info-bfd
2234 '((name .
"Info index: bfd")
2235 (info-index .
"bfd")))
2236 ;; (anything 'anything-c-source-info-bfd)
2239 (defvar anything-c-source-info-gprof
2240 '((name .
"Info index: gprof")
2241 (info-index .
"gprof")))
2242 ;; (anything 'anything-c-source-info-gprof)
2245 (defvar anything-c-source-info-ld
2246 '((name .
"Info index: ld")
2247 (info-index .
"ld")))
2248 ;; (anything 'anything-c-source-info-ld)
2251 (defvar anything-c-source-info-diff
2252 '((name .
"Info index: diff")
2253 (info-index .
"diff")))
2254 ;; (anything 'anything-c-source-info-diff)
2257 (defvar anything-c-source-info-flex
2258 '((name .
"Info index: flex")
2259 (info-index .
"flex")))
2260 ;; (anything 'anything-c-source-info-flex)
2263 (defvar anything-c-source-info-grep
2264 '((name .
"Info index: grep")
2265 (info-index .
"grep")))
2266 ;; (anything 'anything-c-source-info-grep)
2269 (defvar anything-c-source-info-gzip
2270 '((name .
"Info index: gzip")
2271 (info-index .
"gzip")))
2272 ;; (anything 'anything-c-source-info-gzip)
2274 ;; Info Index libtool
2275 (defvar anything-c-source-info-libtool
2276 '((name .
"Info index: libtool")
2277 (info-index .
"libtool")))
2278 ;; (anything 'anything-c-source-info-libtool)
2280 ;; Info Index texinfo
2281 (defvar anything-c-source-info-texinfo
2282 '((name .
"Info index: texinfo")
2283 (info-index .
"texinfo")))
2284 ;; (anything 'anything-c-source-info-texinfo)
2287 (defvar anything-c-source-info-info
2288 '((name .
"Info index: info")
2289 (info-index .
"info")))
2290 ;; (anything 'anything-c-source-info-info)
2293 (defvar anything-c-source-info-gdb
2294 '((name .
"Info index: gdb")
2295 (info-index .
"gdb")))
2296 ;; (anything 'anything-c-source-info-gdb)
2299 (defvar anything-c-source-info-stabs
2300 '((name .
"Info index: stabs")
2301 (info-index .
"stabs")))
2302 ;; (anything 'anything-c-source-info-stabs)
2304 ;; Info Index cvsbook
2305 (defvar anything-c-source-info-cvsbook
2306 '((name .
"Info index: cvsbook")
2307 (info-index .
"cvsbook")))
2308 ;; (anything 'anything-c-source-info-cvsbook)
2311 (defvar anything-c-source-info-cvs
2312 '((name .
"Info index: cvs")
2313 (info-index .
"cvs")))
2314 ;; (anything 'anything-c-source-info-cvs)
2317 (defvar anything-c-source-info-bison
2318 '((name .
"Info index: bison")
2319 (info-index .
"bison")))
2320 ;; (anything 'anything-c-source-info-bison)
2322 ;; Info Index id-utils
2323 (defvar anything-c-source-info-id-utils
2324 '((name .
"Info index: id-utils")
2325 (info-index .
"id-utils")))
2326 ;; (anything 'anything-c-source-info-id-utils)
2328 ;; Info Index global
2329 (defvar anything-c-source-info-global
2330 '((name .
"Info index: global")
2331 (info-index .
"global")))
2332 ;; (anything 'anything-c-source-info-global)
2336 (defvar anything-c-man-pages nil
2337 "All man pages on system.
2338 Will be calculated the first time you invoke anything with this
2341 (defvar anything-c-source-man-pages
2342 `((name .
"Manual Pages")
2343 (candidates .
(lambda ()
2344 (if anything-c-man-pages
2345 anything-c-man-pages
2346 ;; XEmacs doesn't have a woman :)
2347 (setq anything-c-man-pages
2350 (woman-file-name "")
2351 (sort (mapcar 'car woman-topic-all-completions
)
2353 (action ("Show with Woman" . woman
))
2354 ;; Woman does not work OS X
2355 ;; http://xahlee.org/emacs/modernization_man_page.html
2356 (action-transformer .
(lambda (actions candidate
)
2357 (if (eq system-type
'darwin
)
2358 '(("Show with Man" . man
))
2360 (requires-pattern .
2)))
2361 ;; (anything 'anything-c-source-man-pages)
2364 ;;; Complex command history
2365 (defvar anything-c-source-complex-command-history
2366 '((name .
"Complex Command History")
2367 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
2369 ;; (anything 'anything-c-source-complex-command-history)
2372 (defvar anything-c-source-extended-command-history
2373 '((name .
"Emacs Commands History")
2374 (candidates . extended-command-history
)
2376 ;; (anything 'anything-c-source-extended-command-history)
2379 (defvar anything-c-source-emacs-commands
2380 '((name .
"Emacs Commands")
2381 (candidates .
(lambda ()
2383 (mapatoms (lambda (a)
2385 (push (symbol-name a
)
2387 (sort commands
'string-lessp
))))
2389 (requires-pattern .
2))
2390 "Source for completing and invoking Emacs commands.
2391 A command is a function with interactive spec that can
2392 be invoked with `M-x'.
2394 To get non-interactive functions listed, use
2395 `anything-c-source-emacs-functions'.")
2396 ;; (anything 'anything-c-source-emacs-commands)
2399 (defvar anything-c-source-lacarte
2400 '((name .
"Lacarte")
2401 (init .
(lambda () (require 'lacarte
)))
2402 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2403 (candidate-number-limit .
9999)
2404 (action . anything-c-call-interactively
))
2407 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2408 ;; (anything 'anything-c-source-lacarte)
2412 (defvar anything-c-source-emacs-functions
2413 '((name .
"Emacs Functions")
2414 (candidates .
(lambda ()
2416 (mapatoms (lambda (a) (if (functionp a
)
2417 (push (symbol-name a
) commands
))))
2418 (sort commands
'string-lessp
))))
2420 (requires-pattern .
2))
2421 "Source for completing Emacs functions.")
2422 ;; (anything 'anything-c-source-emacs-functions)
2424 ;;; With abbrev expansion
2425 ;;; Similar to my exec-abbrev-cmd.el
2426 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2427 (defvar anything-c-function-abbrev-regexp nil
2428 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2429 Regexp built from the current `anything-pattern' interpreting it
2431 Only for internal use.")
2433 (defun anything-c-match-function-by-abbrev (candidate)
2434 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2436 Abbreviations are made by taking the first character from each
2437 word in the function's name, e.g. \"bb\" is an abbrev for
2438 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2439 (string-match anything-c-function-abbrev-regexp candidate
))
2441 (defvar anything-c-source-emacs-functions-with-abbrevs
2442 (append anything-c-source-emacs-functions
2443 '((match anything-c-match-function-by-abbrev
2444 anything-c-string-match
))
2445 '((init .
(lambda ()
2446 (defadvice anything-update
2447 (before anything-c-update-function-abbrev-regexp activate
)
2448 (let ((char-list (append anything-pattern nil
))
2450 (dolist (c char-list
)
2451 (setq str
(concat str
(list c
) "[^-]*-")))
2452 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
2453 (setq anything-c-function-abbrev-regexp str
))))))))
2454 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2458 (defvar anything-c-source-emacs-variables
2459 '((name .
"Emacs Variables")
2460 (candidates .
(lambda ()
2461 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
2463 (requires-pattern .
2))
2464 "Source for completing Emacs variables.")
2465 ;; (anything 'anything-c-source-emacs-variables)
2469 (eval-when-compile (require 'bookmark
))
2470 (defvar anything-c-source-bookmarks
2471 '((name .
"Bookmarks")
2473 (require 'bookmark
)))
2474 (candidates . bookmark-all-names
)
2476 "See (info \"(emacs)Bookmarks\").")
2477 ;; (anything 'anything-c-source-bookmarks)
2480 (defvar anything-c-source-bookmark-set
2481 '((name .
"Set Bookmark")
2483 (action . bookmark-set
))
2484 "See (info \"(emacs)Bookmarks\").")
2485 ;; (anything 'anything-c-source-bookmark-set)
2487 ;;; Visible Bookmarks
2488 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
2491 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
2492 (defvar anything-c-source-bm
2493 '((name .
"Visible Bookmarks")
2494 (init . anything-c-bm-init
)
2495 (candidates-in-buffer)
2499 http://www.nongnu.org/bm/")
2501 (defun anything-c-bm-init ()
2502 "Init function for `anything-c-source-bm'."
2503 (when (require 'bm nil t
)
2505 (let ((bookmarks (bm-lists))
2506 (buf (anything-candidate-buffer 'global
)))
2507 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
2508 '< :key
'overlay-start
))
2509 (let ((start (overlay-start bm
))
2510 (end (overlay-end bm
))
2511 (annotation (or (overlay-get bm
'annotation
) "")))
2512 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
2513 (let ((str (format "%5d: [%s]: %s\n"
2514 (line-number-at-pos start
)
2516 (buffer-substring start
(1- end
)))))
2517 (with-current-buffer buf
(insert str
))))))))))
2519 ;;; Special bookmarks
2520 (defvar anything-c-source-bookmarks-ssh
2521 '((name .
"Bookmarks-ssh")
2523 (require 'bookmark
)))
2525 (candidates .
(lambda ()
2526 (let (lis-all lis-ssh
)
2527 (setq lis-all
(bookmark-all-names))
2528 (setq lis-ssh
(loop for i in lis-all
2529 if
(string-match "^(ssh)" i
)
2531 (sort lis-ssh
'string-lessp
))))
2533 "See (info \"(emacs)Bookmarks\").")
2534 ;; (anything 'anything-c-source-bookmarks-ssh)
2536 (defvar anything-c-source-bookmarks-su
2537 '((name .
"Bookmarks-root")
2539 (require 'bookmark
)))
2541 (candidates .
(lambda ()
2542 (let (lis-all lis-su
)
2543 (setq lis-all
(bookmark-all-names))
2544 (setq lis-su
(loop for i in lis-all
2545 if
(string-match (format "^(%s)" anything-su-or-sudo
) i
)
2547 (sort lis-su
'string-lessp
))))
2548 (candidate-transformer anything-c-highlight-bookmark-su
)
2551 "See (info \"(emacs)Bookmarks\").")
2552 ;; (anything 'anything-c-source-bookmarks-su)
2555 (defun tv-root-logged-p ()
2557 (dolist (i (mapcar #'buffer-name
(buffer-list)))
2558 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
2559 (throw 'break t
)))))
2562 (defun anything-c-highlight-bookmark-su (files)
2563 (if (tv-root-logged-p)
2564 (anything-c-highlight-bookmark files
)
2565 (anything-c-highlight-not-logged files
)))
2567 (defun anything-c-highlight-not-logged (files)
2568 (loop for i in files
2569 collect
(propertize i
'face anything-c-bookmarks-face3
)))
2571 (defun anything-c-highlight-bookmark (bookmarks)
2572 "Used as `candidate-transformer' to colorize bookmarks.
2573 Work both with standard Emacs bookmarks and bookmark-extensions.el."
2574 (loop for i in bookmarks
2575 for pred
= (bookmark-get-filename i
)
2576 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
2577 (bmkext-get-buffer-name i
))
2578 for handlerp
= (and (fboundp 'bookmark-get-handler
)
2579 (bookmark-get-handler i
))
2580 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
2581 (bmkext-w3m-bookmark-p i
))
2582 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
2583 (bmkext-gnus-bookmark-p i
))
2584 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
2585 (bmkext-man-bookmark-p i
))
2586 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
2587 (bmkext-woman-bookmark-p i
))
2588 for handlerp
= (bookmark-get-handler i
)
2589 for isannotation
= (bookmark-get-annotation i
)
2590 ;; Add a * if bookmark have annotation
2591 if
(and isannotation
(not (string-equal isannotation
"")))
2592 do
(setq i
(concat "*" i
))
2594 if
(eq handlerp
'Info-bookmark-jump
)
2595 collect
(propertize i
'face
'anything-bmkext-info
'help-echo pred
)
2598 collect
(propertize i
'face
'anything-bmkext-w3m
'help-echo pred
)
2601 collect
(propertize i
'face
'anything-bmkext-gnus
'help-echo pred
)
2603 if
(or iswoman isman
)
2604 collect
(propertize i
'face
'anything-bmkext-man
'help-echo pred
)
2606 if
(and pred
(file-directory-p pred
))
2607 collect
(propertize i
'face anything-c-bookmarks-face1
'help-echo pred
)
2609 if
(and pred
(not (file-directory-p pred
)) (file-exists-p pred
)
2610 (not (or iswoman isman
)))
2611 collect
(propertize i
'face
'anything-bmkext-file
'help-echo pred
)))
2613 ;;; Faces for bookmarks
2614 (defface anything-bmkext-info
2615 '((t (:foreground
"green")))
2616 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2619 (defface anything-bmkext-w3m
2620 '((t (:foreground
"yellow")))
2621 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
2624 (defface anything-bmkext-gnus
2625 '((t (:foreground
"magenta")))
2626 "*Face used for Gnus bookmarks."
2629 (defface anything-bmkext-man
2630 '((t (:foreground
"Orange4")))
2631 "*Face used for Woman/man bookmarks."
2634 (defface anything-bmkext-no--file
2635 '((t (:foreground
"grey")))
2636 "*Face used for non--file bookmarks."
2639 (defface anything-bmkext-file
2640 '((t (:foreground
"Deepskyblue2")))
2641 "*Face used for non--file bookmarks."
2644 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
2645 "Face for su/sudo bookmarks."
2648 (defvar anything-c-bookmarks-face1
'anything-dir-heading
)
2649 (defvar anything-c-bookmarks-face2
'anything-file-name
)
2650 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
2652 (defvar anything-c-source-bookmarks-local
2653 '((name .
"Bookmarks-Local")
2655 (require 'bookmark
)))
2657 (candidates .
(lambda ()
2658 (let (lis-all lis-loc
)
2659 (setq lis-all
(bookmark-all-names))
2660 (setq lis-loc
(loop for i in lis-all
2661 if
(and (not (string-match "^(ssh)" i
))
2662 (not (string-match "^(su)" i
)))
2664 (sort lis-loc
'string-lessp
))))
2665 (candidate-transformer anything-c-highlight-bookmark
)
2667 "See (info \"(emacs)Bookmarks\").")
2668 ;; (anything 'anything-c-source-bookmarks-local)
2670 ;;; Sources to filter bookmark-extensions bookmarks.
2671 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
2674 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
2675 "Return a filtered `bookmark-alist' sorted alphabetically."
2677 with alist
= (if args
2678 (apply #'(lambda (x) (funcall fn x
)) args
)
2683 finally return
(sort sa
'string-lessp
)))
2686 (defvar anything-c-source-bookmark-w3m
2687 '((name .
"Bookmark W3m")
2689 (require 'bookmark-extensions
)
2690 (bookmark-maybe-load-default-file)))
2691 (candidates . anything-c-bookmark-w3m-setup-alist
)
2692 (candidate-transformer anything-c-highlight-bookmark
)
2693 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2695 ;; (anything 'anything-c-source-bookmark-w3m)
2697 (defun anything-c-bookmark-w3m-setup-alist ()
2698 "Specialized filter function for bookmarks w3m."
2699 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
2702 (defvar anything-c-source-bookmark-man
2703 '((name .
"Bookmark Woman&Man")
2705 (require 'bookmark-extensions
)
2706 (bookmark-maybe-load-default-file)))
2707 (candidates . anything-c-bookmark-man-setup-alist
)
2708 (candidate-transformer anything-c-highlight-bookmark
)
2709 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2711 ;; (anything 'anything-c-source-bookmark-man)
2713 (defun anything-c-bookmark-man-setup-alist ()
2714 "Specialized filter function for bookmarks w3m."
2715 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
2716 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
2719 (defvar anything-c-source-bookmark-gnus
2720 '((name .
"Bookmark Gnus")
2722 (require 'bookmark-extensions
)
2723 (bookmark-maybe-load-default-file)))
2724 (candidates . anything-c-bookmark-gnus-setup-alist
)
2725 (candidate-transformer anything-c-highlight-bookmark
)
2726 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2728 ;; (anything 'anything-c-source-bookmark-gnus)
2730 (defun anything-c-bookmark-gnus-setup-alist ()
2731 "Specialized filter function for bookmarks gnus."
2732 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
2735 (defvar anything-c-source-bookmark-info
2736 '((name .
"Bookmark Info")
2738 (require 'bookmark-extensions
)
2739 (bookmark-maybe-load-default-file)))
2740 (candidates . anything-c-bookmark-info-setup-alist
)
2741 (candidate-transformer anything-c-highlight-bookmark
)
2742 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2744 ;; (anything 'anything-c-source-bookmark-info)
2746 (defun anything-c-bookmark-info-setup-alist ()
2747 "Specialized filter function for bookmarks info."
2748 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
2750 ;; Local Files&directories
2751 (defvar anything-c-source-bookmark-files
&dirs
2752 '((name .
"Bookmark Files&Directories")
2754 (require 'bookmark-extensions
)
2755 (bookmark-maybe-load-default-file)))
2756 (candidates . anything-c-bookmark-local-files-setup-alist
)
2757 (candidate-transformer anything-c-highlight-bookmark
)
2758 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2760 ;; (anything 'anything-c-source-bookmark-files&dirs)
2762 (defun anything-c-bookmark-local-files-setup-alist ()
2763 "Specialized filter function for bookmarks locals files."
2764 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
2766 ;; Su Files&directories
2767 (defun anything-c-highlight-bmkext-su (bmk)
2768 (if (bmkext-root-or-sudo-logged-p)
2769 (anything-c-highlight-bookmark bmk
)
2770 (anything-c-highlight-not-logged bmk
)))
2772 (defvar anything-c-source-bookmark-su-files
&dirs
2773 '((name .
"Bookmark Root-Files&Directories")
2775 (require 'bookmark-extensions
)
2776 (bookmark-maybe-load-default-file)))
2777 (candidates . anything-c-bookmark-su-files-setup-alist
)
2778 (candidate-transformer anything-c-highlight-bmkext-su
)
2779 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2781 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
2783 (defun anything-c-bookmark-su-files-setup-alist ()
2784 "Specialized filter function for bookmarks su/sudo files."
2786 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
2788 for isfile
= (bookmark-get-filename i
)
2789 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
2791 (string-match tramp-file-name-regexp isfile
)))
2792 for issu
= (and istramp
2793 (string-match bmkext-su-or-sudo-regexp isfile
))
2797 ;; Ssh Files&directories
2798 (defvar anything-c-source-bookmark-ssh-files
&dirs
2799 '((name .
"Bookmark Ssh-Files&Directories")
2801 (require 'bookmark-extensions
)
2802 (bookmark-maybe-load-default-file)))
2803 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
2804 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2806 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
2808 (defun anything-c-bookmark-ssh-files-setup-alist ()
2809 "Specialized filter function for bookmarks ssh files."
2811 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
2813 for isfile
= (bookmark-get-filename i
)
2814 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
2816 (string-match tramp-file-name-regexp isfile
)))
2817 for isssh
= (and istramp
2818 (string-match "/ssh:" isfile
))
2823 ;; All bookmark-extensions sources.
2825 (defun anything-bookmark-ext ()
2826 "Preconfigured `anything' for bookmark-extensions sources.
2827 See: <http://mercurial.intuxication.org/hg/emacs-bookmark-extension>."
2829 (anything '(anything-c-source-bookmark-files&dirs
2830 anything-c-source-bookmark-w3m
2831 anything-c-source-bookmark-gnus
2832 anything-c-source-bookmark-info
2833 anything-c-source-bookmark-man
2834 anything-c-source-bookmark-su-files
&dirs
2835 anything-c-source-bookmark-ssh-files
&dirs
)))
2838 ;; Firefox bookmarks
2839 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
2840 ;; (only for firefox versions >=3)
2841 ;; To achieve that, open about:config in firefox and double click on this line to enable value
2843 ;; user_pref("browser.bookmarks.autoExportHTML", false);
2844 ;; You should have now:
2845 ;; user_pref("browser.bookmarks.autoExportHTML", true);
2847 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
2848 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
2850 (defun anything-get-firefox-user-init-dir ()
2851 "Guess the default Firefox user directory name."
2852 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
2853 (moz-user-dir (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
2854 (goto-char (point-min))
2855 (when (search-forward "Path=" nil t
)
2856 (buffer-substring-no-properties (point) (point-at-eol))))))
2857 (file-name-as-directory (concat moz-dir moz-user-dir
))))
2859 (defun anything-guess-firefox-bookmark-file ()
2860 "Return the path of the Firefox bookmarks file."
2861 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
2863 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
2864 "Parse html bookmark FILE and return an alist with (title . url) as elements."
2865 (let (bookmarks-alist url title
)
2867 (insert-file-contents file
)
2868 (goto-char (point-min))
2871 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
2873 (when (re-search-forward url-regexp nil t
)
2874 (setq url
(concat "\"" (match-string 0))))
2876 (when (re-search-forward bmk-regexp nil t
)
2877 (setq title
(match-string 1)))
2878 (push (cons title url
) bookmarks-alist
))))
2879 (nreverse bookmarks-alist
)))
2882 (defvar anything-c-firefox-bookmarks-alist nil
)
2883 (defvar anything-c-source-firefox-bookmarks
2884 '((name .
"Firefox Bookmarks")
2886 (setq anything-c-firefox-bookmarks-alist
2887 (anything-html-bookmarks-to-alist
2888 (anything-guess-firefox-bookmark-file)
2889 anything-firefox-bookmark-url-regexp
2890 anything-firefox-bookmarks-regexp
))))
2891 (candidates .
(lambda ()
2893 anything-c-firefox-bookmarks-alist
)))
2894 (candidate-transformer anything-c-highlight-firefox-bookmarks
)
2895 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2896 (action .
(("Browse Url" .
(lambda (candidate)
2898 (anything-c-firefox-bookmarks-get-value candidate
))))
2899 ("Browse Url Firefox" .
(lambda (candidate)
2901 (anything-c-firefox-bookmarks-get-value candidate
))))
2902 ("Copy Url" .
(lambda (elm)
2903 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
2905 ;; (anything 'anything-c-source-firefox-bookmarks)
2907 (defun anything-c-firefox-bookmarks-get-value (elm)
2908 (replace-regexp-in-string "\"" ""
2910 anything-c-firefox-bookmarks-alist
))))
2913 (defun anything-c-highlight-firefox-bookmarks (books)
2914 (loop for i in books
2915 collect
(propertize i
2916 'face
'((:foreground
"YellowGreen"))
2917 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
2920 (eval-when-compile (require 'w3m-bookmark nil t
))
2921 (unless (and (require 'w3m nil t
)
2922 (require 'w3m-bookmark nil t
))
2923 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html"))
2926 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
2927 "Face for w3m bookmarks" :group
'anything
)
2929 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
2930 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
2931 (defvar anything-c-w3m-bookmarks-alist nil
)
2932 (defvar anything-c-source-w3m-bookmarks
2933 '((name .
"W3m Bookmarks")
2935 (setq anything-c-w3m-bookmarks-alist
2936 (anything-html-bookmarks-to-alist
2938 anything-w3m-bookmark-url-regexp
2939 anything-w3m-bookmarks-regexp
))))
2940 (candidates .
(lambda ()
2941 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
2942 (candidate-transformer anything-c-highlight-w3m-bookmarks
)
2943 (filtered-candidate-transformer . anything-c-adaptive-sort
)
2944 (action .
(("Browse Url" .
(lambda (candidate)
2945 (anything-c-w3m-browse-bookmark candidate
)))
2946 ("Copy Url" .
(lambda (elm)
2947 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
2948 ("Browse Url Firefox" .
(lambda (candidate)
2949 (anything-c-w3m-browse-bookmark candidate t
)))
2950 ("Delete Bookmark" .
(lambda (candidate)
2951 (anything-c-w3m-delete-bookmark candidate
)))
2952 ("Rename Bookmark" .
(lambda (candidate)
2953 (anything-c-w3m-rename-bookmark candidate
)))))
2954 (persistent-action .
(lambda (candidate)
2955 (if current-prefix-arg
2956 (anything-c-w3m-browse-bookmark candidate t
)
2957 (anything-c-w3m-browse-bookmark candidate nil t
))))
2958 (persistent-help .
"Open URL with emacs-w3m in new tab / \
2959 C-u \\[anything-execute-persistent-action]: Open URL with Firefox")))
2961 ;; (anything 'anything-c-source-w3m-bookmarks)
2963 (defun anything-c-w3m-bookmarks-get-value (elm)
2964 (replace-regexp-in-string
2965 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
2967 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
2968 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
2969 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
2970 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
2972 (defun anything-c-highlight-w3m-bookmarks (books)
2973 (loop for i in books
2975 i
'face
'anything-w3m-bookmarks-face
2976 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
2979 (defun anything-c-w3m-delete-bookmark (elm)
2981 (find-file-literally w3m-bookmark-file
)
2982 (goto-char (point-min))
2983 (when (re-search-forward elm nil t
)
2985 (delete-region (point)
2986 (line-end-position))
2987 (delete-blank-lines))
2988 (save-buffer (current-buffer))
2989 (kill-buffer (current-buffer))))
2991 (defun anything-c-w3m-rename-bookmark (elm)
2992 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
2993 (new-title (read-string "NewTitle: " old-title
)))
2995 (find-file-literally w3m-bookmark-file
)
2996 (goto-char (point-min))
2997 (when (re-search-forward (concat elm
"<") nil t
)
2998 (goto-char (1- (point)))
2999 (delete-backward-char (length old-title
))
3001 (save-buffer (current-buffer))
3002 (kill-buffer (current-buffer)))))
3005 ;;; Elisp library scan
3006 (defvar anything-c-source-elisp-library-scan
3007 '((name .
"Elisp libraries (Scan)")
3008 (init .
(anything-c-elisp-library-scan-init))
3009 (candidates-in-buffer)
3010 (action ("Find library" .
(lambda (candidate)
3011 (find-file (find-library-name candidate
))))
3012 ("Find library other window" .
(lambda (candidate)
3013 (find-file-other-window (find-library-name candidate
))))
3014 ("Load library" .
(lambda (candidate)
3015 (load-library candidate
))))))
3016 ;; (anything 'anything-c-source-elisp-library-scan)
3018 (defun anything-c-elisp-library-scan-init ()
3019 "Init anything buffer status."
3020 (let ((anything-buffer (anything-candidate-buffer 'global
))
3021 (library-list (anything-c-elisp-library-scan-list)))
3022 (with-current-buffer anything-buffer
3023 (dolist (library library-list
)
3024 (insert (format "%s\n" library
))))))
3026 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
3027 "Do completion for file names passed to `locate-file'.
3028 DIRS is directory to search path.
3029 STRING is string to match."
3030 ;; Use `load-path' as path when ignore `dirs'.
3031 (or dirs
(setq dirs load-path
))
3032 ;; Init with blank when ignore `string'.
3033 (or string
(setq string
""))
3034 ;; Get library list.
3035 (let ((string-dir (file-name-directory string
))
3036 ;; File regexp that suffix match `load-file-rep-suffixes'.
3037 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
3042 (setq dir default-directory
))
3044 (setq dir
(expand-file-name string-dir dir
)))
3045 (when (file-directory-p dir
)
3046 (dolist (file (file-name-all-completions
3047 (file-name-nondirectory string
) dir
))
3048 ;; Suffixes match `load-file-rep-suffixes'.
3049 (setq name
(if string-dir
(concat string-dir file
) file
))
3050 (if (string-match match-regexp name
)
3051 (add-to-list 'names name
)))))
3056 (defvar anything-c-imenu-delimiter
" / ")
3058 (defvar anything-c-imenu-index-filter nil
)
3059 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
3061 (defvar anything-c-cached-imenu-alist nil
)
3062 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
3064 (defvar anything-c-cached-imenu-candidates nil
)
3065 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
3067 (defvar anything-c-cached-imenu-tick nil
)
3068 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
3070 (eval-when-compile (require 'imenu
))
3071 (setq imenu-auto-rescan t
)
3073 (defun anything-imenu-create-candidates (entry)
3074 "Create candidates with ENTRY."
3075 (if (listp (cdr entry
))
3076 (mapcan (lambda (sub)
3077 (if (consp (cdr sub
))
3080 (concat (car entry
) anything-c-imenu-delimiter subentry
))
3081 (anything-imenu-create-candidates sub
))
3082 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
3086 (defvar anything-c-source-imenu
3088 (candidates . anything-c-imenu-candidates
)
3089 (persistent-action .
(lambda (elm)
3090 (anything-c-imenu-default-action elm
)
3091 (unless (fboundp 'semantic-imenu-tag-overlay
)
3092 (anything-match-line-color-current-line))))
3093 (persistent-help .
"Show this entry")
3094 (action . anything-c-imenu-default-action
))
3095 "See (info \"(emacs)Imenu\")")
3097 ;; (anything 'anything-c-source-imenu)
3099 (defun anything-c-imenu-candidates ()
3100 (with-current-buffer anything-current-buffer
3101 (let ((tick (buffer-modified-tick)))
3102 (if (eq anything-c-cached-imenu-tick tick
)
3103 anything-c-cached-imenu-candidates
3104 (setq imenu--index-alist nil
)
3105 (setq anything-c-cached-imenu-tick tick
3106 anything-c-cached-imenu-candidates
3109 'anything-imenu-create-candidates
3110 (setq anything-c-cached-imenu-alist
3111 (let ((index (imenu--make-index-alist)))
3112 (if anything-c-imenu-index-filter
3113 (funcall anything-c-imenu-index-filter index
)
3116 (setq anything-c-cached-imenu-candidates
3117 (mapcar #'(lambda (x)
3121 anything-c-cached-imenu-candidates
))))))
3123 (setq imenu-default-goto-function
'imenu-default-goto-function
)
3124 (defun anything-c-imenu-default-action (elm)
3125 "The default action for `anything-c-source-imenu'."
3126 (let ((path (split-string elm anything-c-imenu-delimiter
))
3127 (alist anything-c-cached-imenu-alist
))
3128 (if (> (length path
) 1)
3130 (setq alist
(assoc (car path
) alist
))
3131 (setq elm
(cadr path
))
3132 (imenu (assoc elm alist
)))
3133 (imenu (assoc elm alist
)))))
3136 (defvar anything-c-ctags-modes
3137 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3138 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3139 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
3141 (defun anything-c-source-ctags-init ()
3142 (when (and buffer-file-name
3143 (memq major-mode anything-c-ctags-modes
)
3144 (anything-current-buffer-is-modified))
3145 (with-current-buffer (anything-candidate-buffer 'local
)
3146 (call-process-shell-command
3147 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
3148 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) " anything-buffer-file-name
)
3149 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
3150 nil
(current-buffer))
3151 (goto-char (point-min))
3153 (delete-region (point-min) (point))
3154 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
3155 for lineno-start
= (point)
3156 for lineno
= (buffer-substring lineno-start
(1- (search-forward "," (point-at-eol) t
)))
3159 (insert (format "%5s:" lineno
))
3160 (search-forward "\177" (point-at-eol) t
)
3161 (delete-region (1- (point)) (point-at-eol))
3162 (forward-line 1)))))
3164 (defvar anything-c-source-ctags
3165 '((name .
"Exuberant ctags")
3166 (init . anything-c-source-ctags-init
)
3167 (candidates-in-buffer)
3170 "Needs Exuberant Ctags.
3172 http://ctags.sourceforge.net/")
3173 ;; (anything 'anything-c-source-ctags)
3176 (defvar anything-semantic-candidates nil
)
3177 (eval-when-compile (require 'semantic nil t
))
3178 (defun anything-semantic-construct-candidates (tags depth
)
3179 (when (require 'semantic nil t
)
3181 (mapcar (lambda (tag)
3183 (let ((type (semantic-tag-type tag
))
3184 (class (semantic-tag-class tag
)))
3185 (if (or (and (stringp type
)
3186 (or (string= type
"class")
3187 (string= type
"namespace")))
3188 (eq class
'function
)
3189 (eq class
'variable
))
3190 (cons (cons (concat (make-string (* depth
2) ?\s
)
3191 (semantic-format-tag-summarize tag nil t
)) tag
)
3192 (anything-semantic-construct-candidates (semantic-tag-components tag
)
3196 (defun anything-semantic-default-action (candidate)
3197 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
3198 (semantic-go-to-tag tag
)))
3200 (defvar anything-c-source-semantic
3201 '((name .
"Semantic Tags")
3203 (setq anything-semantic-candidates
3205 (anything-semantic-construct-candidates (semantic-fetch-tags) 0)
3207 (candidates .
(lambda ()
3208 (if anything-semantic-candidates
3209 (mapcar 'car anything-semantic-candidates
))))
3210 (persistent-action .
(lambda (elm)
3211 (anything-semantic-default-action elm
)
3212 (anything-match-line-color-current-line)))
3213 (persistent-help .
"Show this entry")
3214 (action . anything-semantic-default-action
)
3215 "Needs semantic in CEDET.
3217 http://cedet.sourceforge.net/semantic.shtml
3218 http://cedet.sourceforge.net/"))
3220 ;; (anything 'anything-c-source-semantic)
3222 ;;; Function is called by
3224 (defun anything-simple-call-tree ()
3225 "Preconfigured `anything' for simple-call-tree. List function relationships."
3227 (anything-other-buffer
3228 '(anything-c-source-simple-call-tree-functions-callers
3229 anything-c-source-simple-call-tree-callers-functions
)
3230 "*anything simple-call-tree*"))
3232 (defvar anything-c-source-simple-call-tree-functions-callers
3233 '((name .
"Function is called by")
3234 (init . anything-c-simple-call-tree-functions-callers-init
)
3236 (candidates . anything-c-simple-call-tree-candidates
)
3237 (persistent-action . anything-c-simple-call-tree-persistent-action
)
3238 (persistent-help .
"Show function definitions by rotation")
3239 (action ("Find definition selected by persistent-action" .
3240 anything-c-simple-call-tree-find-definition
)))
3241 "Needs simple-call-tree.el.
3242 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3244 (defvar anything-c-simple-call-tree-tick nil
)
3245 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
3246 (defun anything-c-simple-call-tree-analyze-maybe ()
3247 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
3248 (simple-call-tree-analyze)
3249 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
3251 (defun anything-c-simple-call-tree-init-base (function message
)
3252 (require 'simple-call-tree
)
3254 (when (anything-current-buffer-is-modified)
3255 (anything-c-simple-call-tree-analyze-maybe)
3256 (let ((list (funcall function simple-call-tree-alist
)))
3257 (with-current-buffer (anything-candidate-buffer 'local
)
3258 (dolist (entry list
)
3259 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
3260 (insert (car entry
) message
3261 (if (string= funcs
" ")
3266 (defun anything-c-simple-call-tree-functions-callers-init ()
3267 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
" is called by\n"))
3269 (defun anything-c-simple-call-tree-candidates ()
3270 (with-current-buffer (anything-candidate-buffer)
3271 (split-string (buffer-string) "\n\n")))
3273 (defvar anything-c-simple-call-tree-related-functions nil
)
3274 (defvar anything-c-simple-call-tree-function-index
0)
3275 (defun anything-c-simple-call-tree-persistent-action (candidate)
3276 (unless (eq last-command
'anything-execute-persistent-action
)
3277 (setq anything-c-simple-call-tree-related-functions
3278 (delete "no functions."
3280 (replace-regexp-in-string " \\| is called by\\| calls " "" candidate
)
3282 (setq anything-c-simple-call-tree-function-index -
1))
3283 (incf anything-c-simple-call-tree-function-index
)
3284 (anything-c-simple-call-tree-find-definition candidate
))
3286 (defun anything-c-simple-call-tree-find-definition (candidate)
3287 (find-function (intern
3288 (nth (mod anything-c-simple-call-tree-function-index
3289 (length anything-c-simple-call-tree-related-functions
))
3290 anything-c-simple-call-tree-related-functions
))))
3292 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
3295 (defvar anything-c-source-simple-call-tree-callers-functions
3296 '((name .
"Function calls")
3297 (init . anything-c-simple-call-tree-callers-functions-init
)
3299 (candidates . anything-c-simple-call-tree-candidates
)
3300 (persistent-action . anything-c-simple-call-tree-persistent-action
)
3301 (persistent-help .
"Show function definitions by rotation")
3302 (action ("Find definition selected by persistent-action" .
3303 anything-c-simple-call-tree-find-definition
)))
3304 "Needs simple-call-tree.el.
3305 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3307 (defun anything-c-simple-call-tree-callers-functions-init ()
3308 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
3310 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
3312 ;;; Commands/Options with doc
3313 (defvar anything-c-auto-document-data nil
)
3314 (make-variable-buffer-local 'anything-c-auto-document-data
)
3315 (defvar anything-c-source-commands-and-options-in-file
3316 '((name .
"Commands/Options in file")
3318 .
(lambda (x) (format "Commands/Options in %s"
3319 (buffer-local-value 'buffer-file-name anything-current-buffer
))))
3320 (candidates . anything-command-and-options-candidates
)
3323 "List Commands and Options with doc. It needs auto-document.el .
3325 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
3327 (eval-when-compile (require 'auto-document nil t
))
3328 (defun anything-command-and-options-candidates ()
3329 (with-current-buffer anything-current-buffer
3330 (when (and (require 'auto-document nil t
)
3331 (eq major-mode
'emacs-lisp-mode
)
3332 (or (anything-current-buffer-is-modified)
3333 (not anything-c-auto-document-data
)))
3334 (or imenu--index-alist
(imenu--make-index-alist t
))
3335 (setq anything-c-auto-document-data
3336 (destructuring-bind (commands options
)
3337 (adoc-construct anything-current-buffer
)
3339 (loop for
(command . doc
) in commands
3340 for cmdname
= (symbol-name command
)
3342 (cons (format "Command: %s\n %s"
3343 (propertize cmdname
'face font-lock-function-name-face
)
3344 (adoc-first-line doc
))
3345 (assoc cmdname imenu--index-alist
)))
3346 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
3347 for
(option doc default
) in options
3348 for optname
= (symbol-name option
)
3350 (cons (format "Option: %s\n %s\n default = %s"
3351 (propertize optname
'face font-lock-variable-name-face
)
3352 (adoc-first-line doc
)
3353 (adoc-prin1-to-string default
))
3356 anything-c-auto-document-data
))
3358 ;; (anything 'anything-c-source-commands-and-options-in-file)
3360 ;;;; <Color and Face>
3362 (defvar anything-c-source-customize-face
3363 '((name .
"Customize Face")
3365 (unless (anything-candidate-buffer)
3366 (save-window-excursion (list-faces-display))
3367 (anything-candidate-buffer (get-buffer "*Faces*")))))
3368 (candidates-in-buffer)
3369 (get-line . buffer-substring
)
3370 (action .
(lambda (line)
3371 (customize-face (intern (car (split-string line
))))))
3372 (requires-pattern .
3))
3373 "See (info \"(emacs)Faces\")")
3374 ;; (anything 'anything-c-source-customize-face)
3377 (defvar anything-c-source-colors
3379 (init .
(lambda () (unless (anything-candidate-buffer)
3380 (save-window-excursion (list-colors-display))
3381 (anything-candidate-buffer (get-buffer "*Colors*")))))
3382 (candidates-in-buffer)
3383 (get-line . buffer-substring
)
3384 (action ("Copy Name" .
(lambda (candidate)
3385 (kill-new (anything-c-colors-get-name candidate
))))
3386 ("Copy RGB" .
(lambda (candidate)
3387 (kill-new (anything-c-colors-get-rgb candidate
))))
3388 ("Insert Name" .
(lambda (candidate)
3389 (with-current-buffer anything-current-buffer
3390 (insert (anything-c-colors-get-name candidate
)))))
3391 ("Insert RGB" .
(lambda (candidate)
3392 (with-current-buffer anything-current-buffer
3393 (insert (anything-c-colors-get-rgb candidate
))))))))
3394 ;; (anything 'anything-c-source-colors)
3396 (defun anything-c-colors-get-name (candidate)
3398 (replace-regexp-in-string
3401 (insert (capitalize candidate
))
3402 (goto-char (point-min))
3403 (search-forward-regexp "\\s-\\{2,\\}")
3407 (defun anything-c-colors-get-rgb (candidate)
3409 (replace-regexp-in-string
3412 (insert (capitalize candidate
))
3413 (goto-char (point-max))
3414 (search-backward-regexp "\\s-\\{2,\\}")
3415 (kill-region (point) (point-min))
3418 ;;;; <Search Engine>
3419 ;;; Tracker desktop search
3420 (defvar anything-c-source-tracker-search
3421 '((name .
"Tracker Search")
3422 (candidates .
(lambda ()
3423 (start-process "tracker-search-process" nil
3427 (requires-pattern .
3)
3429 "Source for retrieving files matching the current input pattern
3430 with the tracker desktop search.")
3431 ;; (anything 'anything-c-source-tracker-search)
3433 ;;; Spotlight (MacOS X desktop search)
3434 (defvar anything-c-source-mac-spotlight
3436 (candidates .
(lambda ()
3437 (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
3439 (requires-pattern .
3)
3441 "Source for retrieving files via Spotlight's command line
3443 ;; (anything 'anything-c-source-mac-spotlight)
3448 (defvar anything-c-source-kill-ring
3449 '((name .
"Kill Ring")
3450 (init .
(lambda () (anything-attrset 'last-command last-command
)))
3451 (candidates .
(lambda ()
3452 (loop for kill in kill-ring
3453 unless
(or (< (length kill
) anything-kill-ring-threshold
)
3454 (string-match "^[\\s\\t]+$" kill
))
3456 (action . anything-c-kill-ring-action
)
3460 "Source for browse and insert contents of kill-ring.")
3462 (defun anything-c-kill-ring-action (str)
3463 "Insert STR in `kill-ring' and set STR to the head.
3464 If this action is executed just after `yank', replace with STR as yanked string."
3465 (setq kill-ring
(delete str kill-ring
))
3466 (if (not (eq (anything-attr 'last-command
) 'yank
))
3467 (insert-for-yank str
)
3469 (let ((inhibit-read-only t
)
3470 (before (< (point) (mark t
))))
3472 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
3473 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
3474 (setq yank-undo-function nil
)
3475 (set-marker (mark-marker) (point) (current-buffer))
3476 (insert-for-yank str
)
3477 ;; Set the window start back where it was in the yank command,
3479 (set-window-start (selected-window) yank-window-start t
)
3481 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3482 ;; It is cleaner to avoid activation, even though the command
3483 ;; loop would deactivate the mark because we inserted text.
3484 (goto-char (prog1 (mark t
)
3485 (set-marker (mark-marker) (point) (current-buffer)))))))
3488 ;; (anything 'anything-c-source-kill-ring)
3491 ;; DO NOT include these sources in `anything-sources' use
3492 ;; the commands `anything-mark-ring' and `anything-global-mark-ring' instead.
3494 (defun anything-c-source-mark-ring-candidates ()
3495 (flet ((get-marks (pos)
3499 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
3500 (when (string= "" line
)
3501 (setq line
"<EMPTY LINE>"))
3502 (format "%7d: %s" (line-number-at-pos) line
)))))
3503 (with-current-buffer anything-current-buffer
3505 with marks
= (cons (mark-marker) mark-ring
)
3508 for f
= (get-marks i
)
3509 if
(not (member f recip
))
3512 finally
(return (reverse recip
))))))
3514 (defvar anything-mark-ring-cache nil
)
3515 (defvar anything-c-source-mark-ring
3516 '((name .
"mark-ring")
3518 (setq anything-mark-ring-cache
3519 (anything-c-source-mark-ring-candidates))))
3520 (candidates .
(lambda ()
3521 (anything-aif anything-mark-ring-cache
3523 (action .
(("Goto line" .
(lambda (candidate)
3524 (anything-goto-line (string-to-number candidate
))))))
3525 (persistent-action .
(lambda (candidate)
3526 (anything-goto-line (string-to-number candidate
))
3527 (anything-match-line-color-current-line)))
3528 (persistent-help .
"Show this line")))
3530 ;; (anything 'anything-c-source-mark-ring)
3533 (defun anything-mark-ring ()
3534 "Preconfigured `anything' for `anything-c-source-mark-ring'."
3536 (anything 'anything-c-source-mark-ring
))
3538 ;;; Global-mark-ring
3539 (defvar anything-c-source-global-mark-ring
3540 '((name .
"global-mark-ring")
3541 (candidates . anything-c-source-global-mark-ring-candidates
)
3542 (action .
(("Goto line" .
(lambda (candidate)
3543 (let ((items (split-string candidate
":")))
3544 (switch-to-buffer (second items
))
3545 (anything-goto-line (string-to-number (car items
))))))))
3546 (persistent-action .
(lambda (candidate)
3547 (let ((items (split-string candidate
":")))
3548 (switch-to-buffer (second items
))
3549 (anything-goto-line (string-to-number (car items
)))
3550 (anything-match-line-color-current-line))))
3551 (persistent-help .
"Show this line")))
3553 (defun anything-c-source-global-mark-ring-candidates ()
3555 (with-current-buffer (marker-buffer m
)
3559 (if (string= "" line
)
3560 (setq line
"<EMPTY LINE>")
3561 (setq line
(car (split-string (thing-at-point 'line
) "[\n\r]"))))
3562 (format "%7d:%s: %s" (line-number-at-pos) (marker-buffer m
) line
)))))
3564 with marks
= global-mark-ring
3567 if
(not (or (string-match "^ " (format "%s" (marker-buffer i
)))
3568 (null (marker-buffer i
))))
3570 if
(and a
(not (member a recip
)))
3573 finally
(return (reverse recip
)))))
3575 ;; (anything 'anything-c-source-global-mark-ring)
3578 (defun anything-global-mark-ring ()
3579 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
3581 (anything 'anything-c-source-global-mark-ring
))
3584 ;;; Insert from register
3585 (defvar anything-c-source-register
3586 '((name .
"Registers")
3587 (candidates . anything-c-register-candidates
)
3588 (action-transformer . anything-c-register-action-transformer
)
3591 "See (info \"(emacs)Registers\")")
3593 (defun anything-c-register-candidates ()
3594 "Collecting register contents and appropriate commands."
3595 (loop for
(char . val
) in register-alist
3596 for key
= (single-key-description char
)
3597 for string-actions
= (cond
3599 (list (int-to-string val
)
3601 'increment-register
))
3603 (let ((buf (marker-buffer val
)))
3605 (list "a marker in no buffer")
3607 "a buffer position:"
3610 (int-to-string (marker-position val
)))
3612 'insert-register
))))
3613 ((and (consp val
) (window-configuration-p (car val
)))
3614 (list "window configuration."
3616 ((and (consp val
) (frame-configuration-p (car val
)))
3617 (list "frame configuration."
3619 ((and (consp val
) (eq (car val
) 'file
))
3620 (list (concat "file:"
3621 (prin1-to-string (cdr val
))
3624 ((and (consp val
) (eq (car val
) 'file-query
))
3625 (list (concat "file:a file-query reference: file "
3628 (int-to-string (car (cdr (cdr val
))))
3632 (let ((lines (format "%4d" (length val
))))
3633 (list (format "%s: %s\n" lines
3634 (truncate-string-to-width
3635 (mapconcat 'identity
(list (car val
))
3636 ;; (mapconcat (lambda (y) y) val
3637 "^J") (- (window-width) 15)))
3640 (list ;; without properties
3641 (substring-no-properties val
)
3644 'prepend-to-register
))
3647 collect
(cons (format "register %3s: %s" key
(car string-actions
))
3648 (cons char
(cdr string-actions
)))))
3650 (defun anything-c-register-action-transformer (actions register-and-functions
)
3651 "Decide actions by the contents of register."
3652 (loop with func-actions
=
3655 (lambda (c) (insert-register (car c
))))
3657 "Jump to Register" .
3658 (lambda (c) (jump-to-register (car c
))))
3660 "Append Region to Register" .
3661 (lambda (c) (append-to-register (car c
) (region-beginning) (region-end))))
3662 (prepend-to-register
3663 "Prepend Region to Register" .
3664 (lambda (c) (prepend-to-register (car c
) (region-beginning) (region-end))))
3666 "Increment Prefix Arg to Register" .
3667 (lambda (c) (increment-register anything-current-prefix-arg
(car c
)))))
3668 for func in
(cdr register-and-functions
)
3669 for cell
= (assq func func-actions
)
3671 collect
(cdr cell
)))
3673 ;; (anything 'anything-c-source-register)
3675 ;;;; <Headline Extraction>
3676 (defvar anything-c-source-fixme
3677 '((name .
"TODO/FIXME/DRY comments")
3678 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
3681 "Show TODO/FIXME/DRY comments in current file.")
3682 ;; (anything 'anything-c-source-fixme)
3684 (defvar anything-c-source-rd-headline
3685 '((name .
"RD HeadLine")
3686 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
3687 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
3693 http://en.wikipedia.org/wiki/Ruby_Document_format")
3694 ;; (anything 'anything-c-source-rd-headline)
3696 (defvar anything-c-source-oddmuse-headline
3697 '((name .
"Oddmuse HeadLine")
3698 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
3699 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
3700 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
3703 "Show Oddmuse headlines, such as EmacsWiki.")
3704 ;; (anything 'anything-c-source-oddmuse-headline)
3706 (defvar anything-c-source-emacs-source-defun
3707 '((name .
"Emacs Source DEFUN")
3708 (headline .
"DEFUN\\|DEFVAR")
3709 (condition .
(string-match "/emacs2[0-9].+/src/.+c$" (or buffer-file-name
""))))
3710 "Show DEFUN/DEFVAR in Emacs C source file.")
3711 ;; (anything 'anything-c-source-emacs-source-defun)
3713 (defvar anything-c-source-emacs-lisp-expectations
3714 '((name .
"Emacs Lisp Expectations")
3715 (headline .
"(desc[ ]\\|(expectations")
3716 (condition .
(eq major-mode
'emacs-lisp-mode
)))
3717 "Show descriptions (desc) in Emacs Lisp Expectations.
3719 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
3720 ;; (anything 'anything-c-source-emacs-lisp-expectations)
3722 (defvar anything-c-source-emacs-lisp-toplevels
3723 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
3724 (headline .
"^(\\|(@\\*\\|^;;;;")
3725 (get-line . buffer-substring
)
3726 (condition .
(eq major-mode
'emacs-lisp-mode
))
3728 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
3729 linkd.el is optional because linkd stars are extracted by regexp.
3730 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
3731 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
3733 (defvar anything-c-source-org-headline
3734 '((name .
"Org HeadLine")
3736 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3737 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3738 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3739 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3740 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3741 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3742 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
3743 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3744 (condition .
(eq major-mode
'org-mode
))
3747 (persistent-action .
(lambda (elm)
3748 (anything-c-action-line-goto elm
)
3751 .
(lambda (actions candidate
)
3752 '(("Go to Line" . anything-c-action-line-goto
)
3753 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline
)))))
3754 "Show Org headlines.
3755 org-mode is very very much extended text-mode/outline-mode.
3757 See (find-library \"org.el\")
3758 See http://orgmode.org for the latest version.")
3760 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
3763 (anything-goto-line (car lineno-and-content
))
3764 (and (looking-at "^\\*+ \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
3765 (org-make-link-string (concat "*" (match-string 1)))))))
3767 ;; (anything 'anything-c-source-org-headline)
3769 ;;; Anything yaoddmuse
3770 ;; Be sure to have yaoddmuse.el installed
3771 ;; install-elisp may be required if you want to install elisp file from here.
3772 (defvar anything-yaoddmuse-use-cache-file nil
)
3773 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
3774 (defvar anything-c-yaoddmuse-ew-cache nil
)
3775 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
3776 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
3777 (candidates .
(lambda ()
3778 (if anything-yaoddmuse-use-cache-file
3781 (unless anything-c-yaoddmuse-ew-cache
3782 (load anything-c-yaoddmuse-cache-file
)
3783 (setq anything-c-yaoddmuse-ew-cache
3784 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
3785 anything-c-yaoddmuse-ew-cache
)
3787 (yaoddmuse-update-pagename t
)
3788 (gethash "EmacsWiki" yaoddmuse-pages-hash
))))
3789 (action .
(("Edit page" .
(lambda (candidate)
3790 (yaoddmuse-edit "EmacsWiki" candidate
)))
3791 ("Browse page" .
(lambda (candidate)
3792 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
3793 ("Browse page other window" .
(lambda (candidate)
3795 (split-window-vertically))
3796 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
3797 ("Browse diff" .
(lambda (candidate)
3798 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
3799 ("Copy URL" .
(lambda (candidate)
3800 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
3801 (message "Have copy page %s's URL to yank." candidate
)))
3802 ("Create page" .
(lambda (candidate)
3803 (yaoddmuse-edit "EmacsWiki" anything-input
)))
3804 ("Update cache" .
(lambda (candidate)
3805 (if anything-yaoddmuse-use-cache-file
3807 (anything-yaoddmuse-cache-pages t
)
3808 (setq anything-c-yaoddmuse-ew-cache
3809 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
3810 (yaoddmuse-update-pagename))))))
3811 (action-transformer anything-c-yaoddmuse-action-transformer
)))
3813 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
3815 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
3816 '((name .
"Yaoddmuse Post library (EmacsWiki)")
3817 (init .
(anything-yaoddmuse-init))
3818 (candidates-in-buffer)
3819 (action .
(("Post library and Browse" .
(lambda (candidate)
3820 (yaoddmuse-post-file (find-library-name candidate
)
3822 (file-name-nondirectory (find-library-name candidate
))
3824 ("Post library" .
(lambda (candidate)
3825 (yaoddmuse-post-file (find-library-name candidate
)
3827 (file-name-nondirectory (find-library-name candidate
)))))))))
3829 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
3831 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
3832 "Allow the use of `install-elisp' only on elisp files."
3833 (if (string-match "\.el$" candidate
)
3834 (append actions
'(("Install Elisp" .
(lambda (elm)
3835 (install-elisp-from-emacswiki elm
)))))
3839 (defun anything-yaoddmuse-cache-pages (&optional load
)
3840 "Fetch the list of files on emacswiki and create cache file.
3841 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
3843 (yaoddmuse-update-pagename)
3845 (find-file anything-c-yaoddmuse-cache-file
)
3847 (insert "(puthash \"EmacsWiki\" '(")
3848 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
3850 (insert (concat "(\"" (car i
) "\") ")))
3851 (insert ") yaoddmuse-pages-hash)\n")
3853 (kill-buffer (current-buffer))
3854 (when (or current-prefix-arg
3856 (load anything-c-yaoddmuse-cache-file
))))
3859 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
3860 "Preconfigured `anything' to edit or view EmacsWiki page."
3862 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
3865 (defun anything-yaoddmuse-emacswiki-post-library ()
3866 "Preconfigured `anything' to post library to EmacsWiki."
3868 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
3870 (defun anything-yaoddmuse-init ()
3871 "Init anything buffer status."
3872 (let ((anything-buffer (anything-candidate-buffer 'global
))
3873 (library-list (yaoddmuse-get-library-list)))
3874 (with-current-buffer anything-buffer
3875 ;; Insert library name.
3876 (dolist (library library-list
)
3877 (insert (format "%s\n" library
)))
3879 (sort-lines nil
(point-min) (point-max)))))
3882 (defvar anything-c-source-eev-anchor
3883 '((name .
"Anchors")
3885 (setq anything-c-eev-anchor-buffer
3887 (candidates .
(lambda ()
3890 (with-current-buffer anything-c-eev-anchor-buffer
3891 (goto-char (point-min))
3893 (while (re-search-forward (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
3894 (push (match-string-no-properties 1) anchors
))
3895 (setq anchors
(reverse anchors
)))))
3897 (persistent-action .
(lambda (item)
3899 (anything-match-line-color-current-line)))
3900 (persistent-help .
"Show this entry")
3901 (action .
(("Goto link" .
(lambda (item)
3904 ;; (anything 'anything-c-source-eev-anchor)
3908 (defvar anything-c-source-org-keywords
3909 '((name .
"Org Keywords")
3910 (init . anything-c-org-keywords-init
)
3911 (candidates . anything-c-org-keywords-candidates
)
3912 (action . anything-c-org-keywords-insert
)
3913 (persistent-action . anything-c-org-keywords-show-help
)
3914 (persistent-help .
"Show an example and info page to describe this keyword.")
3917 ;; (anything 'anything-c-source-org-keywords)
3918 (defvar anything-c-org-keywords-info-location
3919 '(("#+TITLE:" .
"(org)Export options")
3920 ("#+AUTHOR:" .
"(org)Export options")
3921 ("#+DATE:" .
"(org)Export options")
3922 ("#+EMAIL:" .
"(org)Export options")
3923 ("#+DESCRIPTION:" .
"(org)Export options")
3924 ("#+KEYWORDS:" .
"(org)Export options")
3925 ("#+LANGUAGE:" .
"(org)Export options")
3926 ("#+TEXT:" .
"(org)Export options")
3927 ("#+TEXT:" .
"(org)Export options")
3928 ("#+OPTIONS:" .
"(org)Export options")
3929 ("#+BIND:" .
"(org)Export options")
3930 ("#+LINK_UP:" .
"(org)Export options")
3931 ("#+LINK_HOME:" .
"(org)Export options")
3932 ("#+LATEX_HEADER:" .
"(org)Export options")
3933 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
3934 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
3935 ("#+INFOJS_OPT" .
"(org)Javascript support")
3936 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
3937 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
3938 ("#+ORGTBL" .
"(org)Radio tables")
3939 ("#+HTML:" .
"(org)Quoting HTML tags")
3940 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
3941 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
3942 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
3943 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
3944 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
3945 ("#+BEGIN_SRC" .
"(org)Literal examples")
3946 ("#+CAPTION" .
"(org)Tables in HTML export")
3947 ("#+LABEL" .
"(org)Tables in LaTeX export")
3948 ("#+ATTR_HTML" .
"(org)Links")
3949 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
3951 (defun anything-c-org-keywords-init ()
3952 (unless (anything-attr 'keywords-examples
)
3954 (anything-attrset 'keywords-examples
3958 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
3959 (cons (match-string 2 x
) (match-string 1 x
)))
3960 (org-split-string (org-get-current-options) "\n"))
3961 (mapcar 'list org-additional-option-like-keywords
)))
3962 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
3964 (defun anything-c-org-keywords-candidates ()
3965 (and (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
3966 (anything-attr 'keywords
)))
3968 (defun anything-c-org-keywords-insert (keyword)
3969 (cond ((string-match "BEGIN" keyword
)
3970 (insert "#+" keyword
" ")
3972 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword
) "\n")))
3974 (insert "#+" keyword
" "))))
3976 (defun anything-c-org-keywords-show-help (keyword)
3977 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
3978 "(org)In-buffer settings"))
3979 (search-forward (concat "#+" keyword
) nil t
)
3980 (anything-persistent-highlight-point)
3981 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
3985 (defvar anything-c-source-picklist
3986 '((name .
"Picklist")
3987 (candidates .
(lambda () (mapcar 'car picklist-list
)))
3989 ;; (anything 'anything-c-source-picklist)
3992 (defun anything-c-bbdb-candidates ()
3993 "Return a list of all names in the bbdb database. The format
3994 is \"Firstname Lastname\"."
3995 (mapcar (lambda (bbdb-record)
3996 (replace-regexp-in-string
3998 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
4001 (defun anything-c-bbdb-create-contact (actions candidate
)
4002 "Action transformer that returns only an entry to add the
4003 current `anything-pattern' as new contact. All other actions are
4005 (if (string= candidate
"*Add to contacts*")
4006 '(("Add to contacts" .
(lambda (actions)
4007 (bbdb-create-internal
4008 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
4009 (read-from-minibuffer "Company: ")
4010 (read-from-minibuffer "Email: ")
4013 (read-from-minibuffer "Note: ")))))
4016 (defun anything-c-bbdb-get-record (candidate)
4017 "Return record that match CANDIDATE."
4018 (bbdb candidate nil
)
4019 (set-buffer "*BBDB*")
4020 (bbdb-current-record))
4022 (defvar anything-c-bbdb-name nil
4023 "Only for internal use.")
4025 (defvar anything-c-source-bbdb
4027 (candidates . anything-c-bbdb-candidates
)
4028 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
4029 ("View person's data" . anything-c-bbdb-view-person-action
))
4030 (filtered-candidate-transformer .
(lambda (candidates source
)
4031 (setq anything-c-bbdb-name anything-pattern
)
4032 (if (not candidates
)
4033 (list "*Add to contacts*")
4035 (action-transformer .
(lambda (actions candidate
)
4036 (anything-c-bbdb-create-contact actions candidate
)))))
4037 ;; (anything 'anything-c-source-bbdb)
4039 (defun anything-c-bbdb-view-person-action (candidate)
4040 "View BBDB data of single CANDIDATE or marked candidates."
4041 (anything-aif (anything-marked-candidates)
4042 (let ((bbdb-append-records (length it
)))
4044 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
4045 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
4047 (defun anything-c-bbdb-collect-mail-addresses ()
4048 "Return a list of all mail addresses of records in bbdb buffer."
4049 (with-current-buffer bbdb-buffer-name
4050 (loop for i in bbdb-records
4051 if
(bbdb-record-net (car i
))
4052 collect
(bbdb-dwim-net-address (car i
)))))
4054 (defun anything-c-bbdb-compose-mail (candidate)
4055 "Compose a mail with all records of bbdb buffer."
4056 (anything-c-bbdb-view-person-action candidate
)
4057 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4058 (address-str (mapconcat 'identity address-list
",\n ")))
4059 (compose-mail address-str
)))
4061 ;;; Evaluation Result
4062 (defvar anything-c-source-evaluation-result
4063 '((name .
"Evaluation Result")
4065 (filtered-candidate-transformer .
(lambda (candidates source
)
4069 (eval (read anything-pattern
)))
4071 (action ("Do Nothing" . ignore
))))
4072 ;; (anything 'anything-c-source-evaluation-result)
4074 ;;; Calculation Result
4075 (defvar anything-c-source-calculation-result
4076 '((name .
"Calculation Result")
4078 (filtered-candidate-transformer .
(lambda (candidates source
)
4081 (calc-eval anything-pattern
)
4083 (action ("Copy result to kill-ring" . kill-new
))))
4084 ;; (anything 'anything-c-source-calculation-result)
4086 ;;; Google Suggestions
4087 (defvar anything-gg-sug-lgh-flag
0)
4088 (defun anything-c-google-suggest-fetch (input)
4089 "Fetch suggestions for INPUT from XML buffer.
4090 Return an alist with elements like (data . number_results)."
4091 (let ((request (concat anything-c-google-suggest-url
4092 (url-hexify-string input
))))
4095 with result-alist
= (xml-get-children
4096 (car (xml-parse-region (point-min) (point-max)))
4097 'CompleteSuggestion
)
4098 for i in result-alist
4099 for data
= (cdr (caadr (assoc 'suggestion i
)))
4100 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
4101 for ldata
= (length data
)
4103 (when (> ldata anything-gg-sug-lgh-flag
)
4104 (setq anything-gg-sug-lgh-flag ldata
))
4105 collect
(cons data nqueries
) into cont
4106 finally return cont
)))
4107 (if anything-google-suggest-use-curl-p
4109 (call-process "curl" nil t nil request
)
4111 (with-current-buffer
4112 (url-retrieve-synchronously request
)
4116 (defun anything-c-google-suggest-set-candidates ()
4117 "Set candidates with result and number of google results found."
4118 (let ((suggestions (anything-c-google-suggest-fetch anything-input
)))
4119 (setq suggestions
(loop for i in suggestions
4120 for interval
= (- anything-gg-sug-lgh-flag
(length (car i
)))
4121 for elm
= (concat (car i
)
4122 (make-string (+ 2 interval
) ?
)
4123 "(" (cdr i
) " results)")
4124 collect
(cons elm
(car i
))))
4125 (if (some (lambda (data) (equal (cdr data
) anything-input
)) suggestions
)
4127 ;; if there is no suggestion exactly matching the input then
4128 ;; prepend a Search on Google item to the list
4131 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
4132 anything-input
))))))
4135 (defun anything-c-google-suggest-action (candidate)
4136 "Default action to jump to a google suggested candidate."
4137 (browse-url (concat anything-c-google-suggest-search-url
4138 (url-hexify-string candidate
))))
4141 (defvar anything-c-source-google-suggest
4142 '((name .
"Google Suggest")
4143 (candidates . anything-c-google-suggest-set-candidates
)
4144 (action .
(("Google Search" . anything-c-google-suggest-action
)))
4146 (requires-pattern .
3)
4149 ;; (anything 'anything-c-source-google-suggest)
4151 ;;; Yahoo suggestions
4153 (defun anything-c-yahoo-suggest-fetch (input)
4154 "Fetch Yahoo suggestions for INPUT from XML buffer.
4155 Return an alist with elements like (data . number_results)."
4156 (let ((request (concat anything-c-yahoo-suggest-url
4157 (url-hexify-string input
))))
4160 with result-alist
= (xml-get-children
4161 (car (xml-parse-region (point-min) (point-max)))
4163 for i in result-alist
4164 collect
(caddr i
))))
4165 (with-current-buffer
4166 (url-retrieve-synchronously request
)
4169 (defun anything-c-yahoo-suggest-set-candidates ()
4170 "Set candidates with Yahoo results found."
4171 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
4175 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
4176 anything-input
))))))
4178 (defun anything-c-yahoo-suggest-action (candidate)
4179 "Default action to jump to a Yahoo suggested candidate."
4180 (browse-url (concat anything-c-yahoo-suggest-search-url
4181 (url-hexify-string candidate
))))
4183 (defvar anything-c-source-yahoo-suggest
4184 '((name .
"Yahoo Suggest")
4185 (candidates . anything-c-yahoo-suggest-set-candidates
)
4186 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
4188 (requires-pattern .
3)
4191 ;; (anything 'anything-c-source-yahoo-suggest)
4194 ;;; Need external program surfraw.
4195 ;;; http://surfraw.alioth.debian.org/
4197 (defvar anything-c-surfraw-favorites
'("google" "wikipedia"
4199 "codesearch" "genpkg"
4202 "All elements of this list will appear first in results.")
4203 (defvar anything-c-surfraw-use-only-favorites nil
4204 "If non-nil use only `anything-c-surfraw-favorites'.")
4207 (defun anything-c-build-elvi-alist ()
4209 A list of search engines."
4212 (call-process "surfraw" nil t nil
4214 (split-string (buffer-string) "\n")))
4217 (loop for i in elvi-list
4219 (setq line
(split-string i
))
4220 collect
(cons (first line
) (mapconcat #'(lambda (x) x
) (cdr line
) " "))))))
4223 (defun anything-c-surfraw-sort-elvi (&optional only-fav
)
4224 "Sort elvi alist according to `anything-c-surfraw-favorites'."
4225 (let* ((elvi-alist (anything-c-build-elvi-alist))
4226 (fav-alist (loop for j in anything-c-surfraw-favorites
4227 collect
(assoc j elvi-alist
)))
4228 (rest-elvi (loop for i in elvi-alist
4229 if
(not (member i fav-alist
))
4233 (append fav-alist rest-elvi
))))
4235 (defun anything-c-surfraw-get-url (engine pattern
)
4236 "Get search url from `engine' for `anything-pattern'."
4238 (apply #'call-process
"surfraw" nil t nil
4245 (defvar anything-c-surfraw-elvi nil
)
4246 (defvar anything-c-surfraw-cache nil
)
4247 (defvar anything-c-source-surfraw
4248 '((name .
"Surfraw")
4250 (unless anything-c-surfraw-cache
4251 (setq anything-c-surfraw-elvi
(anything-c-surfraw-sort-elvi
4252 anything-c-surfraw-use-only-favorites
))
4253 (setq anything-c-surfraw-cache
4254 (loop for i in anything-c-surfraw-elvi
4256 collect
(car i
))))))
4257 (candidates .
(lambda ()
4258 (loop for i in anything-c-surfraw-cache
4259 for s
= (anything-c-surfraw-get-url i anything-pattern
)
4260 collect
(concat (propertize i
4261 'face
'((:foreground
"green"))
4262 'help-echo
(cdr (assoc i anything-c-surfraw-elvi
)))
4263 ">>>" (replace-regexp-in-string "\n" "" s
)))))
4264 (action .
(("Browse" .
(lambda (candidate)
4265 (let ((url (second (split-string candidate
">>>"))))
4267 ("Browse firefox" .
(lambda (candidate)
4268 (let ((url (second (split-string candidate
">>>"))))
4269 (browse-url-firefox url t
))))))
4271 (requires-pattern .
3)
4275 ;; (anything 'anything-c-source-surfraw)
4280 (defun anything-emms-stream-edit-bookmark (elm)
4281 "Change the information of current emms-stream bookmark from anything."
4283 (let* ((cur-buf anything-current-buffer
)
4284 (bookmark (assoc elm emms-stream-list
))
4285 (name (read-from-minibuffer "Description: "
4287 (url (read-from-minibuffer "URL: "
4289 (fd (read-from-minibuffer "Feed Descriptor: "
4290 (int-to-string (nth 2 bookmark
))))
4291 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
4292 (format "%s" (car (last bookmark
))))))
4295 (when (re-search-forward (concat "^" name
) nil t
)
4297 (emms-stream-delete-bookmark)
4298 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
4299 (emms-stream-save-bookmarks-file)
4301 (switch-to-buffer cur-buf
)))))
4303 (defun anything-emms-stream-delete-bookmark (elm)
4304 "Delete an emms-stream bookmark from anything."
4306 (let* ((cur-buf anything-current-buffer
)
4307 (bookmark (assoc elm emms-stream-list
))
4308 (name (nth 0 bookmark
)))
4311 (when (re-search-forward (concat "^" name
) nil t
)
4313 (emms-stream-delete-bookmark)
4314 (emms-stream-save-bookmarks-file)
4316 (switch-to-buffer cur-buf
)))))
4318 (defvar anything-c-source-emms-streams
4319 '((name .
"Emms Streams")
4321 (emms-stream-init)))
4322 (candidates .
(lambda ()
4323 (mapcar 'car emms-stream-list
)))
4324 (action .
(("Play" .
(lambda (elm)
4325 (let* ((stream (assoc elm emms-stream-list
))
4326 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
4327 (url (second stream
)))
4329 ("Delete" . anything-emms-stream-delete-bookmark
)
4330 ("Edit" . anything-emms-stream-edit-bookmark
)))
4331 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
4332 ;; (anything 'anything-c-source-emms-streams)
4334 ;; Don't forget to set `emms-source-file-default-directory'
4335 (defvar anything-c-source-emms-dired
4336 '((name .
"Music Directory")
4337 (candidates .
(lambda ()
4338 (cddr (directory-files emms-source-file-default-directory
))))
4340 (("Play Directory" .
(lambda (item)
4341 (emms-play-directory
4344 emms-source-file-default-directory
))))
4345 ("Open dired in file's directory" .
(lambda (item)
4346 (anything-c-open-dired
4349 emms-source-file-default-directory
))))))
4350 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
4351 ;; (anything 'anything-c-source-emms-dired)
4353 ;;; Jabber Contacts (jabber.el)
4354 (defun anything-c-jabber-online-contacts ()
4355 "List online Jabber contacts."
4358 (dolist (item (jabber-concat-rosters) jids
)
4359 (when (get item
'connected
)
4360 (push (if (get item
'name
)
4361 (cons (get item
'name
) item
)
4362 (cons (symbol-name item
) item
)) jids
))))))
4364 (defvar anything-c-source-jabber-contacts
4365 '((name .
"Jabber Contacts")
4366 (init .
(lambda () (require 'jabber
)))
4367 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
4368 (action .
(lambda (x)
4370 (jabber-read-account)
4372 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
4373 ;; (anything 'anything-c-source-jabber-contacts)
4377 (defvar anything-source-select-buffer
"*anything source select*")
4378 (defvar anything-c-source-call-source
4379 `((name .
"Call anything source")
4380 (candidate-number-limit)
4381 (candidates .
(lambda ()
4382 (loop for vname in
(all-completions "anything-c-source-" obarray
)
4383 for var
= (intern vname
)
4384 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
4385 if name collect
(cons (format "%s `%s'"
4386 name
(propertize vname
'face
'font-lock-variable-name-face
))
4388 (action .
(("Invoke anything with selected source" .
4390 (setq anything-candidate-number-limit
9999)
4391 (anything candidate nil nil nil nil
4392 anything-source-select-buffer
)))
4393 ("Describe variable" . describe-variable
)))
4394 (persistent-action . describe-variable
)
4395 (persistent-help .
"Show description of this source")))
4396 ;; (anything 'anything-c-source-call-source)
4399 (defun anything-call-source ()
4400 "Preconfigured `anything' to call anything source."
4402 (anything 'anything-c-source-call-source nil nil nil nil
4403 anything-source-select-buffer
))
4405 (defun anything-call-source-from-anything ()
4406 "Call anything source within `anything' session."
4408 (setq anything-input-idle-delay
0)
4409 (anything-set-sources '(anything-c-source-call-source)))
4414 (defun anything-c-occur-goto-line (candidate)
4415 "Goto line action for anything-c-source-occur."
4416 (anything-goto-line (string-to-number candidate
)))
4418 (defun anything-c-occur-persistent-action (candidate)
4419 "Persistent action for anything occur source."
4420 (anything-c-occur-goto-line candidate
)
4421 (anything-match-line-color-current-line))
4423 (defun anything-c-get-occur-candidates ()
4424 "Get `anything-c-source-occur' candidates."
4426 (let ((count (occur-engine
4428 (list anything-current-buffer
) (current-buffer)
4429 list-matching-lines-default-context-lines nil
4430 list-matching-lines-buffer-name-face
4431 nil list-matching-lines-face
4432 (not (eq occur-excluded-properties t
)))))
4434 (cdr (split-string (buffer-string) "\n" t
))))))
4436 (defvar anything-c-source-occur
4438 (candidates . anything-c-get-occur-candidates
)
4439 (persistent-action . anything-c-occur-persistent-action
)
4440 (persistent-help .
"Goto Line")
4441 (action . anything-c-occur-goto-line
)
4442 (requires-pattern .
1)
4445 ;; (anything 'anything-c-source-occur)
4448 (defun anything-occur ()
4449 "Preconfigured Anything for Occur source."
4451 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*"))
4453 ;; Do many actions for input
4454 (defvar anything-c-source-create
4458 (candidate-number-limit .
9999)
4459 (action-transformer . anything-create--actions
))
4460 "Do many create actions from `anything-pattern'.
4461 See also `anything-create--actions'.")
4462 ;; (anything 'anything-c-source-create)
4464 (defun anything-create-from-anything ()
4465 "Run `anything-create' from `anything' as a fallback."
4467 (anything-run-after-quit 'anything-create nil anything-pattern
))
4470 (defun anything-create (&optional string initial-input
)
4471 "Preconfigured `anything' to do many create actions from STRING.
4472 See also `anything-create--actions'."
4474 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
4475 (anything '(((name .
"Anything Create")
4476 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
4477 (candidates . anything-create--actions
)
4478 (candidate-number-limit .
9999)
4479 (action .
(lambda (func) (funcall func string
)))))))
4481 (defun anything-create--actions (&rest ignored
)
4482 "Default actions for `anything-create' / `anything-c-source-create'."
4484 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
4485 (append anything-create--actions-private
4486 '(("find-file" . find-file
)
4487 ("find-file other window" . find-file-other-window
)
4488 ("New buffer" . switch-to-buffer
)
4489 ("New buffer other window" . switch-to-buffer-other-window
)
4490 ("Bookmark Set" . bookmark-set
)
4492 (lambda (x) (set-register (read-char "Register: ") x
)))
4493 ("Insert Linkd star" . linkd-insert-star
)
4494 ("Insert Linkd Tag" . linkd-insert-tag
)
4495 ("Insert Linkd Link" . linkd-insert-link
)
4496 ("Insert Linkd Lisp" . linkd-insert-lisp
)
4497 ("Insert Linkd Wiki" . linkd-insert-wiki
)
4498 ("Google Search" . google
)))))
4500 ;; Minibuffer History
4501 (defvar anything-c-source-minibuffer-history
4502 '((name .
"Minibuffer History")
4503 (header-name .
(lambda (name) (format "%s (%s)" name minibuffer-history-variable
)))
4504 (candidates .
(lambda () (let ((history (symbol-value minibuffer-history-variable
)))
4505 (if (consp (car history
))
4506 (mapcar 'prin1-to-string history
)
4510 ;; (anything 'anything-c-source-minibuffer-history)
4513 (defvar anything-c-source-elscreen
4514 '((name .
"Elscreen")
4515 (candidates .
(lambda ()
4516 (if (cdr (elscreen-get-screen-to-name-alist))
4518 (loop for sname in
(elscreen-get-screen-to-name-alist)
4519 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
4520 finally
(return lst
))
4521 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
4522 (action .
(("Change Screen".
4524 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
4527 (anything-aif (anything-marked-candidates)
4529 (elscreen-kill-internal (- (aref i
1) (aref "0" 0))))
4530 (elscreen-kill-internal (- (aref candidate
1) (aref "0" 0))))))
4533 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
4534 (elscreen-kill-others)))))))
4535 ;; (anything 'anything-c-source-elscreen)
4540 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
4541 "Top command (batch mode). %s is replaced with `frame-width'.")
4542 (defvar anything-c-source-top
4543 '((name .
"Top (Press C-c C-u to refresh)")
4544 (init . anything-c-top-init
)
4545 (candidates-in-buffer)
4546 (display-to-real . anything-c-top-display-to-real
)
4547 (update . anything-c-top-update
)
4549 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
4550 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
4551 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
4552 ;; (anything 'anything-c-source-top)
4554 (defun anything-c-top-sh (cmd)
4555 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
4557 (defun anything-c-top-init ()
4558 (with-current-buffer (anything-candidate-buffer 'global
)
4559 (call-process-shell-command
4560 (format anything-c-top-command
4561 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
4562 nil
(current-buffer))))
4564 (defun anything-c-top-display-to-real (line)
4565 (car (split-string line
)))
4567 (defun anything-c-top-update ()
4568 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
4569 (anything-c-top-init)))
4572 (defun anything-top ()
4573 "Preconfigured `anything' for top command."
4575 (let ((anything-samewindow t
)
4576 (anything-enable-shortcuts)
4577 (anything-display-function 'anything-default-display-buffer
)
4578 (anything-candidate-number-limit 9999))
4579 (save-window-excursion
4580 (delete-other-windows)
4581 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
4584 (defvar anything-c-source-absolute-time-timers
4585 '((name .
"Absolute Time Timers")
4586 (candidates . timer-list
)
4588 ;; (anything 'anything-c-source-absolute-time-timers)
4590 (defvar anything-c-source-idle-time-timers
4591 '((name .
"Idle Time Timers")
4592 (candidates . timer-idle-list
)
4594 ;; (anything 'anything-c-source-idle-time-timers)
4596 (defun anything-c-timer-real-to-display (timer)
4597 (destructuring-bind (_ t1 t2 t3 _ func args
&rest rest
) (append timer nil
)
4599 (format-time-string "%m/%d %T" (list t1 t2 t3
))
4601 (mapconcat 'prin1-to-string
(aref timer
6) " "))))
4603 ;;; X RandR resolution change
4604 ;;; FIXME I do not care multi-display.
4605 (defvar anything-c-xrandr-output
"VGA")
4606 (defvar anything-c-xrandr-screen
"0")
4607 (defvar anything-c-source-xrandr-change-resolution
4608 '((name .
"Change Resolution")
4612 (call-process "xrandr" nil
(current-buffer) nil
4613 "--screen" anything-c-xrandr-screen
"-q")
4615 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
4616 collect
(match-string 1)))))
4618 ("Change Resolution" .
(lambda (mode)
4619 (call-process "xrandr" nil nil nil
4620 "--screen" anything-c-xrandr-screen
4621 "--output" anything-c-xrandr-output
4623 ;; (anything 'anything-c-source-xrandr-change-resolution)
4626 (defun anything-c-persistent-xfont-action (elm)
4627 "Show current font temporarily"
4628 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
4631 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
4632 (set-frame-font current-font
))))
4634 (defvar anything-c-xfonts-cache nil
)
4635 (defvar anything-c-source-xfonts
4636 '((name .
"X Fonts")
4638 (unless anything-c-xfonts-cache
4639 (setq anything-c-xfonts-cache
4640 (x-list-fonts "*")))))
4641 (candidates . anything-c-xfonts-cache
)
4642 (action .
(("Copy to kill ring" .
(lambda (elm)
4644 ("Set Font" .
(lambda (elm)
4646 (set-frame-font elm
'keep-size
)
4647 (message "New font have been copied to kill ring")))))
4648 (persistent-action . anything-c-persistent-xfont-action
)
4649 (persistent-help .
"Switch to this font temporarily")))
4652 (defun anything-select-xfont ()
4653 "Preconfigured `anything' to select Xfont."
4655 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
4657 ;; (anything 'anything-c-source-xfonts)
4659 ;; Source for Debian/Ubuntu users
4660 (defvar anything-c-source-apt
4662 (init . anything-c-apt-init
)
4663 (candidates-in-buffer)
4664 (display-to-real . anything-c-apt-display-to-real
)
4665 (candidate-number-limit .
9999)
4667 ("Show package description" . anything-c-apt-cache-show
)
4668 ("Install package" . anything-c-apt-install
))))
4669 ;; (anything 'anything-c-source-apt)
4671 (defvar anything-c-apt-query
"emacs")
4672 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
4673 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
4674 (defvar anything-c-apt-install-command
"xterm -e sudo apt-get install '%s' &")
4677 (defun anything-apt (query)
4678 "Preconfigured `anything' : frontend of APT package manager."
4679 (interactive "sAPT search: ")
4680 (let ((anything-c-apt-query query
))
4681 (anything 'anything-c-source-apt
)))
4683 (defun anything-c-apt-init ()
4684 (with-current-buffer
4685 (anything-candidate-buffer
4686 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query
)))
4687 (call-process-shell-command
4688 (format anything-c-apt-search-command anything-c-apt-query
)
4689 nil
(current-buffer))))
4690 (defun anything-c-apt-display-to-real (line)
4691 (car (split-string line
" - ")))
4694 (defun anything-c-shell-command-if-needed (command)
4695 (interactive "sShell command: ")
4696 (if (get-buffer command
) ; if the buffer already exists
4697 (switch-to-buffer command
) ; then just switch to it
4698 (switch-to-buffer command
) ; otherwise create it
4699 (insert (shell-command-to-string command
))))
4701 (defun anything-c-apt-cache-show (package)
4702 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package
)))
4703 (defun anything-c-apt-install (package)
4704 (shell-command (format anything-c-apt-install-command package
) "*apt install*"))
4706 ;; (anything-c-apt-install "jed")
4707 ;; Sources for gentoo users
4709 (defvar anything-gentoo-prefered-shell
'eshell
4710 "Your favorite shell to run emerge command.")
4712 (defvar anything-c-gentoo-use-flags nil
)
4713 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
4714 (defvar anything-c-cache-gentoo nil
)
4715 (defvar anything-c-cache-world nil
)
4716 (defvar anything-c-source-gentoo
4717 '((name .
"Portage sources")
4719 (get-buffer-create anything-c-gentoo-buffer
)
4720 (unless anything-c-cache-gentoo
4721 (anything-c-gentoo-setup-cache))
4722 (unless anything-c-cache-world
4723 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
4724 (anything-c-gentoo-init-list)))
4725 (candidates-in-buffer)
4727 (candidate-transformer anything-c-highlight-world
)
4728 (action .
(("Show package" .
(lambda (elm)
4729 (anything-c-gentoo-eshell-action elm
"eix")))
4730 ("Show history" .
(lambda (elm)
4731 (if (member elm anything-c-cache-world
)
4732 (anything-c-gentoo-eshell-action elm
"genlop -qe")
4733 (message "No infos on packages not yet installed"))))
4734 ("Copy in kill-ring" . kill-new
)
4735 ("insert at point" . insert
)
4736 ("Browse HomePage" .
(lambda (elm)
4737 (browse-url (car (anything-c-gentoo-get-url elm
)))))
4738 ("Show extra infos" .
(lambda (elm)
4739 (if (member elm anything-c-cache-world
)
4740 (anything-c-gentoo-eshell-action elm
"genlop -qi")
4741 (message "No infos on packages not yet installed"))))
4742 ("Show use flags" .
(lambda (elm)
4743 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
4744 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
4745 (font-lock-mode 1)))
4746 ("Run emerge pretend" .
(lambda (elm)
4747 (anything-c-gentoo-eshell-action elm
"emerge -p")))
4748 ("Emerge" .
(lambda (elm)
4749 (anything-gentoo-install elm
:action
'install
)))
4750 ("Unmerge" .
(lambda (elm)
4751 (anything-gentoo-install elm
:action
'uninstall
)))
4752 ("Show dependencies" .
(lambda (elm)
4753 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
4754 ("Show related files" .
(lambda (elm)
4755 (anything-c-gentoo-default-action elm
"equery" "files")))
4756 ("Refresh" .
(lambda (elm)
4757 (anything-c-gentoo-setup-cache)
4758 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
4760 ;; (anything 'anything-c-source-gentoo)
4762 (defun* anything-gentoo-install
(candidate &key action
)
4763 (funcall anything-gentoo-prefered-shell
)
4764 (let ((command (case action
4765 ('install
"*sudo emerge -av ")
4766 ('uninstall
"*sudo emerge -avC ")
4767 (t (error "Unknow action")))))
4768 (if (anything-marked-candidates)
4769 (let ((elms (mapconcat 'identity
(anything-marked-candidates) " ")))
4770 (insert (concat command elms
)))
4771 (insert (concat command candidate
)))))
4774 (defun anything-c-gentoo-default-action (elm command
&rest args
)
4775 "Gentoo default action that use `anything-c-gentoo-buffer'."
4776 (if (member elm anything-c-cache-world
)
4778 (switch-to-buffer anything-c-gentoo-buffer
)
4780 (let ((com-list (append args
(list elm
))))
4781 (apply #'call-process command nil t nil
4783 (message "No infos on packages not yet installed")))
4785 (defvar anything-c-source-use-flags
4786 '((name .
"Use Flags")
4788 (unless anything-c-gentoo-use-flags
4789 (anything-c-gentoo-setup-use-flags-cache))
4790 (anything-c-gentoo-get-use)))
4791 (candidates-in-buffer)
4793 (candidate-transformer anything-c-highlight-local-use
)
4794 (action .
(("Description"
4796 (switch-to-buffer anything-c-gentoo-buffer
)
4798 (apply #'call-process
"euse" nil t nil
4801 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
4802 (font-lock-mode 1)))
4805 (anything-c-gentoo-eshell-action elm
"*sudo euse -E")))
4808 (anything-c-gentoo-eshell-action elm
"*sudo euse -D")))
4811 (anything-c-gentoo-eshell-action elm
"*sudo euse -P")))
4812 ("Show which dep use this flag"
4814 (switch-to-buffer anything-c-gentoo-buffer
)
4816 (apply #'call-process
"equery" nil t nil
4822 ;; (anything 'anything-c-source-use-flags)
4824 (defun anything-c-gentoo-init-list ()
4825 "Initialize buffer with all packages in Portage."
4826 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
4827 (buf (anything-candidate-buffer 'portage-buf
)))
4828 (with-current-buffer buf
4829 (dolist (i anything-c-cache-gentoo
)
4830 (insert (concat i
"\n"))))))
4832 (defun anything-c-gentoo-setup-cache ()
4833 "Set up `anything-c-cache-gentoo'"
4834 (setq anything-c-cache-gentoo
4835 (split-string (with-temp-buffer
4836 (call-process "eix" nil t nil
4840 (defun anything-c-gentoo-eshell-action (elm command
)
4841 (when (get-buffer "*EShell Command Output*")
4842 (kill-buffer "*EShell Command Output*"))
4843 (message "Wait searching...")
4844 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
4845 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
4847 (save-window-excursion
4848 (pop-to-buffer "*scratch*")
4849 (eshell-command (format "%s %s" command elm
)))
4850 (pop-to-buffer "*EShell Command Output*"))
4851 (eshell-command (format "%s %s" command elm
)))))
4853 (defun anything-c-gentoo-get-use ()
4854 "Initialize buffer with all use flags."
4855 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
4856 (buf (anything-candidate-buffer 'use-buf
)))
4857 (with-current-buffer buf
4858 (dolist (i anything-c-gentoo-use-flags
)
4859 (insert (concat i
"\n"))))))
4862 (defun anything-c-gentoo-setup-use-flags-cache ()
4863 "Setup `anything-c-gentoo-use-flags'"
4864 (setq anything-c-gentoo-use-flags
4865 (split-string (with-temp-buffer
4866 (call-process "eix" nil t nil
4867 "--print-all-useflags")
4870 (defun anything-c-gentoo-get-url (elm)
4871 "Return a list of urls from eix output."
4872 (split-string (eshell-command-result
4873 (format "eix %s | grep Homepage | awk '{print $2}'" elm
))))
4875 (defun anything-c-gentoo-get-world ()
4876 "Return list of all installed package on your system."
4877 (split-string (with-temp-buffer
4878 (call-process "qlist" nil t nil
4882 (defun anything-c-gentoo-get-local-use ()
4883 (split-string (with-temp-buffer
4884 (call-process "portageq" nil t nil
4889 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
4890 "Face for anything-gentoo installed packages."
4891 :group
'traverse-faces
)
4893 (defun anything-c-highlight-world (eix)
4894 "Highlight all installed package."
4896 if
(member i anything-c-cache-world
)
4897 collect
(propertize i
'face
'anything-gentoo-match-face
)
4901 (defun anything-c-highlight-local-use (use-flags)
4902 (let ((local-uses (anything-c-gentoo-get-local-use)))
4903 (loop for i in use-flags
4904 if
(member i local-uses
)
4905 collect
(propertize i
'face
'anything-gentoo-match-face
)
4909 (defvar anything-c-source-emacs-process
4910 '((name .
"Emacs Process")
4911 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
4912 (action ("Kill Process" .
(lambda (elm) (delete-process (get-process elm
)))))))
4914 ;; (anything 'anything-c-source-emacs-process)
4916 ;; Run Externals commands within Emacs
4917 (defmacro* anything-comp-hash-get-items
(hash-table &key test
)
4918 "Get the list of all keys/values of hash-table."
4919 `(let ((li-items ()))
4920 (maphash #'(lambda (x y
)
4922 (when (funcall ,test y
)
4923 (push (list x y
) li-items
))
4924 (push (list x y
) li-items
)))
4928 (defun anything-comp-read-get-candidates (collection &optional test
)
4929 "Convert collection to list.
4930 If collection is an `obarray', a test is maybe needed, otherwise
4931 the list would be incomplete.
4933 (cond ((and (listp collection
) test
)
4934 (loop for i in collection
4935 when
(funcall test i
) collect i
))
4936 ((and (vectorp collection
) test
)
4940 (when (funcall test s
) (push s ob
))))
4942 ((and (hash-table-p collection
) test
)
4943 (anything-comp-hash-get-items collection
:test test
))
4944 ((vectorp collection
)
4945 (loop for i across collection collect i
))
4946 ((hash-table-p collection
)
4947 (anything-comp-hash-get-items collection
))
4950 (defun* anything-comp-read
(prompt collection
&key test initial-input
4951 (buffer "*Anything Completions*"))
4952 "Anything `completing-read' emulation.
4953 Collection can be a list, vector, obarray or hash-table."
4954 (when (get-buffer anything-action-buffer
)
4955 (kill-buffer anything-action-buffer
))
4957 `((name .
"Completions")
4960 (anything-comp-read-get-candidates collection test
)))
4961 (action .
(("candidate" .
,'identity
))))
4962 initial-input prompt
'noresume nil buffer
)
4965 (defun anything-c-get-pid-from-process-name (process-name)
4966 "Get pid from running process PROCESS-NAME."
4967 (let ((process-list (list-system-processes)))
4969 (dolist (i process-list
)
4970 (let ((process-attr (process-attributes i
)))
4972 (when (string-match process-name
4980 (defun anything-c-run-external-command (program)
4981 "Run External PROGRAM asyncronously from Emacs.
4982 If program is already running exit with error.
4983 You can set your own list of commands with
4984 `anything-c-external-commands-list'."
4988 (anything-c-external-commands-list-1 'sort
))))
4989 (if (or (get-process program
)
4990 (anything-c-get-pid-from-process-name program
))
4991 (error "Error: %s is already running" program
)
4992 (message "Starting %s..." program
)
4993 (start-process-shell-command program nil program
)
4994 (set-process-sentinel
4995 (get-process program
)
4996 #'(lambda (process event
)
4997 (when (string= event
"finished\n")
4998 (message "%s process...Finished." process
)
4999 (when anything-back-to-emacs-shell-command
5000 (shell-command anything-back-to-emacs-shell-command
)))))
5001 (setq anything-c-external-commands-list
5002 (push (pop (nthcdr (anything-c-position
5003 program anything-c-external-commands-list
)
5004 anything-c-external-commands-list
))
5005 anything-c-external-commands-list
))))
5007 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
5008 "A simple and faster replacement of CL `position'."
5009 (loop for i in seq for index from
0
5010 when
(funcall test i item
) return index
))
5013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5015 (defvar anything-c-external-commands-list nil
5016 "A list of all external commands the user can execute. If this
5017 variable is not set by the user, it will be calculated
5020 (defun anything-c-external-commands-list-1 (&optional sort
)
5021 "Returns a list of all external commands the user can execute.
5023 If `anything-c-external-commands-list' is non-nil it will
5024 return its contents. Else it calculates all external commands
5025 and sets `anything-c-external-commands-list'.
5027 The code is ripped out of `eshell-complete-commands-list'."
5028 (if anything-c-external-commands-list
5029 anything-c-external-commands-list
5030 (setq anything-c-external-commands-list
5031 (let* ((paths (split-string (getenv "PATH") path-separator
))
5032 (cwd (file-name-as-directory
5033 (expand-file-name default-directory
)))
5034 (path "") (comps-in-path ())
5035 (file "") (filepath "") (completions ()))
5036 ;; Go thru each path in the search path, finding completions.
5038 (setq path
(file-name-as-directory
5039 (expand-file-name (or (car paths
) ".")))
5041 (and (file-accessible-directory-p path
)
5042 (file-name-all-completions "" path
)))
5043 ;; Go thru each completion found, to see whether it should be
5044 ;; used, e.g. see if it's executable.
5045 (while comps-in-path
5046 (setq file
(car comps-in-path
)
5047 filepath
(concat path file
))
5048 (if (and (not (member file completions
))
5049 (or (string-equal path cwd
)
5050 (not (file-directory-p filepath
)))
5051 (file-executable-p filepath
))
5052 (setq completions
(cons file completions
)))
5053 (setq comps-in-path
(cdr comps-in-path
)))
5054 (setq paths
(cdr paths
)))
5056 (sort completions
#'(lambda (x y
) (string< x y
)))
5059 (defun anything-c-file-buffers (filename)
5060 "Returns a list of buffer names corresponding to FILENAME."
5061 (let ((name (expand-file-name filename
))
5063 (dolist (buf (buffer-list) buf-list
)
5064 (let ((bfn (buffer-file-name buf
)))
5065 (when (and bfn
(string= name bfn
))
5066 (push (buffer-name buf
) buf-list
))))))
5068 (defun anything-c-delete-file (file)
5069 "Delete the given file after querying the user.
5070 Ask to kill buffers associated with that file, too."
5071 (let ((buffers (anything-c-file-buffers file
)))
5072 (dired-delete-file file
'dired-recursive-deletes
)
5074 (dolist (buf buffers
)
5075 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
5076 (kill-buffer buf
))))))
5078 (defun anything-c-open-file-externally (file)
5079 "Open FILE with an external tool. Query the user which tool to use."
5080 (let* ((fname (expand-file-name file
))
5081 (program (anything-comp-read
5082 "Program: " (anything-c-external-commands-list-1 'sort
))))
5083 (start-process "anything-c-open-file-externally"
5085 (setq anything-c-external-commands-list
5086 (push (pop (nthcdr (anything-c-position
5087 program anything-c-external-commands-list
)
5088 anything-c-external-commands-list
))
5089 anything-c-external-commands-list
))))
5092 (defun w32-shell-execute-open-file (file)
5093 (interactive "fOpen file:")
5095 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
5097 (replace-regexp-in-string ; strip cygdrive paths
5098 "/cygdrive/\\(.\\)" "\\1:" file nil nil
) nil t
))))
5100 (defun anything-c-open-file-with-default-tool (file)
5101 "Open FILE with the default tool on this platform."
5102 (if (eq system-type
'windows-nt
)
5103 (w32-shell-execute-open-file file
)
5104 (start-process "anything-c-open-file-with-default-tool"
5106 (cond ((eq system-type
'gnu
/linux
)
5108 ((or (eq system-type
'darwin
) ;; Mac OS X
5109 (eq system-type
'macos
)) ;; Mac OS 9
5113 (defun anything-c-open-dired (file)
5114 "Opens a dired buffer in FILE's directory. If FILE is a
5115 directory, open this directory."
5116 (if (file-directory-p file
)
5118 (dired (file-name-directory file
))
5119 (dired-goto-file file
)))
5121 (defun anything-c-display-to-real-line (candidate)
5122 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
5123 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
5124 (error "Line number not found")))
5126 (defun anything-c-action-line-goto (lineno-and-content)
5127 (apply #'anything-goto-file-line
(anything-attr 'target-file
)
5128 (append lineno-and-content
5129 (list (if (and (anything-attr-defined 'target-file
)
5130 (not anything-in-persistent-action
))
5131 'find-file-other-window
5134 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
5135 (apply #'anything-goto-file-line file-line-content
))
5138 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
5141 (if (not (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
))
5142 (error "Filename and line number not found")
5143 (let ((filename (match-string 1 candidate
))
5144 (lineno (match-string 2 candidate
))
5145 (content (match-string 3 candidate
)))
5146 (cons (format "%s:%s\n %s"
5147 (propertize filename
'face compilation-info-face
)
5148 (propertize lineno
'face compilation-line-face
)
5150 (list (expand-file-name
5152 (anything-aif (anything-attr 'default-directory
)
5153 (if (functionp it
) (funcall it
) it
)
5154 (and (anything-candidate-buffer)
5157 (anything-candidate-buffer)))))
5158 (string-to-number lineno
) content
)))))
5161 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
5162 (anything-aif (anything-attr 'before-jump-hook
)
5164 (when file
(funcall find-file-function file
))
5165 (if (anything-attr-defined 'adjust
)
5166 (anything-c-goto-line-with-adjustment lineno content
)
5167 (anything-goto-line lineno
))
5168 (unless (anything-attr-defined 'recenter
)
5169 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
5170 (anything-aif (anything-attr 'after-jump-hook
)
5172 (when anything-in-persistent-action
5173 (anything-match-line-color-current-line)))
5175 (defun anything-find-file-as-root (candidate)
5176 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
5178 (defun anything-find-many-files (ignore)
5179 (mapc 'find-file
(anything-marked-candidates)))
5181 ;; borrowed from etags.el
5182 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
5183 (defun anything-c-goto-line-with-adjustment (line line-content
)
5186 ;; This constant is 1/2 the initial search window.
5187 ;; There is no sense in making it too small,
5188 ;; since just going around the loop once probably
5189 ;; costs about as much as searching 2000 chars.
5192 pat
(concat (if (eq selective-display t
)
5193 "\\(^\\|\^m\\) *" "^ *") ;allow indent
5194 (regexp-quote line-content
)))
5195 ;; If no char pos was given, try the given line number.
5196 (setq startpos
(progn (anything-goto-line line
) (point)))
5197 (or startpos
(setq startpos
(point-min)))
5198 ;; First see if the tag is right at the specified location.
5199 (goto-char startpos
)
5200 (setq found
(looking-at pat
))
5201 (while (and (not found
)
5203 (goto-char (- startpos offset
))
5206 (re-search-forward pat
(+ startpos offset
) t
)
5207 offset
(* 3 offset
))) ; expand search window
5209 (re-search-forward pat nil t
)
5210 (error "not found")))
5211 ;; Position point at the right place
5212 ;; if the search string matched an extra Ctrl-m at the beginning.
5213 (and (eq selective-display t
)
5216 (beginning-of-line))
5218 (anything-document-attribute 'default-directory
"type . file-line"
5219 "`default-directory' to interpret file.")
5220 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
5221 "Function to call before jumping to the target location.")
5222 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
5223 "Function to call after jumping to the target location.")
5224 (anything-document-attribute 'adjust
"type . file-line"
5225 "Search around line matching line contents.")
5226 (anything-document-attribute 'recenter
"type . file-line / line"
5227 "`recenter' after jumping.")
5228 (anything-document-attribute 'target-file
"type . line"
5229 "Goto line of target-file.")
5232 (defun anything-c-call-interactively (cmd-or-name)
5233 "Execute CMD-OR-NAME as Emacs command.
5234 It is added to `extended-command-history'.
5235 `anything-current-prefix-arg' is used as the command's prefix argument."
5236 (setq extended-command-history
5237 (cons (anything-c-stringify cmd-or-name
)
5238 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
5239 (let ((current-prefix-arg anything-current-prefix-arg
)
5240 (cmd (anything-c-symbolify cmd-or-name
)))
5241 (if (stringp (symbol-function cmd
))
5242 (execute-kbd-macro (symbol-function cmd
))
5243 (call-interactively cmd
))))
5246 (defun anything-c-set-variable (var)
5247 "Set value to VAR interactively."
5249 (let ((sym (anything-c-symbolify var
)))
5250 (set sym
(eval-minibuffer (format "Set %s: " var
)
5251 (prin1-to-string (symbol-value sym
))))))
5253 ;; (anything-c-set-variable 'hh)
5255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5256 (defvar anything-match-line-overlay-face nil
)
5257 (defvar anything-match-line-overlay nil
)
5259 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
5260 "Highlight and underline current position"
5261 (let ((args (list (or start
(line-beginning-position))
5262 (or end
(1+ (line-end-position)))
5264 (if (not anything-match-line-overlay
)
5265 (setq anything-match-line-overlay
(apply 'make-overlay args
))
5266 (apply 'move-overlay anything-match-line-overlay args
)))
5267 (overlay-put anything-match-line-overlay
5268 'face
(or face anything-match-line-overlay-face
))
5273 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
5275 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
5276 "Face for source header in the anything buffer." :group
'anything
)
5278 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
5280 (defun anything-match-line-cleanup ()
5281 (when anything-match-line-overlay
5282 (delete-overlay anything-match-line-overlay
)
5283 (setq anything-match-line-overlay nil
)))
5285 (defun anything-match-line-update ()
5286 (when anything-match-line-overlay
5287 (delete-overlay anything-match-line-overlay
)
5288 (anything-match-line-color-current-line)))
5290 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
5291 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
5293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5295 (defun anything-c-transform-file-load-el (actions candidate
)
5296 "Add action to load the file CANDIDATE if it is an emacs lisp
5297 file. Else return ACTIONS unmodified."
5298 (if (member (file-name-extension candidate
) '("el" "elc"))
5299 (append actions
'(("Load Emacs Lisp File" . load-file
)))
5302 (defun anything-c-transform-file-browse-url (actions candidate
)
5303 "Add an action to browse the file CANDIDATE if it in a html
5304 file or URL. Else return ACTIONS unmodified."
5305 (let ((browse-action '("Browse with Browser" . browse-url
)))
5306 (cond ((string-match "^http\\|^ftp" candidate
)
5307 (cons browse-action actions
))
5308 ((string-match "\\.html?$" candidate
)
5309 (append actions
(list browse-action
)))
5313 (defun anything-c-transform-function-call-interactively (actions candidate
)
5314 "Add an action to call the function CANDIDATE interactively if
5315 it is a command. Else return ACTIONS unmodified."
5316 (if (commandp (intern-soft candidate
))
5317 (append actions
'(("Call Interactively"
5319 anything-c-call-interactively
)))
5323 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
5324 "If CANDIDATE's `car' is a command, then add an action to
5325 evaluate it and put it onto the `command-history'."
5326 (if (commandp (car (read candidate
)))
5327 ;; Make it first entry
5328 (cons '("Eval and put onto command-history" .
5330 (let ((sym (read sexp
)))
5332 (setq command-history
5333 (cons sym command-history
)))))
5337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5339 (defun anything-c-skip-boring-buffers (buffers)
5340 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
5342 (defun anything-c-skip-current-buffer (buffers)
5343 (if anything-allow-skipping-current-buffer
5344 (remove (buffer-name anything-current-buffer
) buffers
)
5347 (defun anything-c-shadow-boring-buffers (buffers)
5348 "Buffers matching `anything-c-boring-buffer-regexp' will be
5349 displayed with the `file-name-shadow' face if available."
5350 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
5353 (defun anything-c-shadow-boring-files (files)
5354 "Files matching `anything-c-boring-file-regexp' will be
5355 displayed with the `file-name-shadow' face if available."
5356 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
5358 (defun anything-c-skip-boring-files (files)
5359 "Files matching `anything-c-boring-file-regexp' will be skipped."
5360 (anything-c-skip-entries files anything-c-boring-file-regexp
))
5361 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
5363 (defun anything-c-skip-current-file (files)
5364 "Current file will be skipped."
5365 (remove (buffer-file-name anything-current-buffer
) files
))
5367 (defun anything-c-w32-pathname-transformer (args)
5368 "Change undesirable features of windows pathnames to ones more acceptable to
5369 other candidate transformers."
5370 (if (eq system-type
'windows-nt
)
5372 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
5374 (replace-regexp-in-string "\\\\" "/" y
)) args
))
5377 (defun anything-c-shorten-home-path (files)
5378 "Replaces /home/user with ~."
5379 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
5381 (mapcar (lambda (file)
5382 (if (and (stringp file
) (string-match home file
))
5383 (cons (replace-match "~" nil nil file
) file
)
5388 (defun anything-c-mark-interactive-functions (functions)
5389 "Mark interactive functions (commands) with (i) after the function name."
5391 (loop for function in functions
5392 do
(push (cons (concat function
5393 (when (commandp (intern-soft function
)) " (i)"))
5396 finally
(return (nreverse list
)))))
5398 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5399 (defvar anything-c-adaptive-done nil
5400 "nil if history information is not yet stored for the current
5403 (defvar anything-c-adaptive-history nil
5404 "Contains the stored history information.
5405 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
5407 (defadvice anything-initialize
(before anything-c-adaptive-initialize activate
)
5408 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
5409 when anything is started."
5410 (setq anything-c-adaptive-done nil
))
5412 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
5413 "Advise `anything-exit-minibuffer' to store history information
5414 when a candidate is selected with RET."
5415 (anything-c-adaptive-store-selection))
5417 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
5418 "Advise `anything-select-action' to store history information
5419 when the user goes to the action list with TAB."
5420 (anything-c-adaptive-store-selection))
5422 (defun anything-c-source-use-adaptative-p (&optional source-name
)
5423 "Return current source only if it use adaptative history, nil otherwise."
5424 (let* ((source (or source-name
(anything-get-current-source)))
5425 (adapt-source (or (assoc-default 'filtered-candidate-transformer
5426 (assoc (assoc-default 'type source
)
5427 anything-type-attributes
))
5428 (assoc-default 'candidate-transformer
5429 (assoc (assoc-default 'type source
)
5430 anything-type-attributes
))
5431 (assoc-default 'filtered-candidate-transformer source
)
5432 (assoc-default 'candidate-transformer source
))))
5433 (if (listp adapt-source
)
5434 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
5435 (when (eq adapt-source
'anything-c-adaptive-sort
) source
))))
5437 (defun anything-c-adaptive-store-selection ()
5438 "Store history information for the selected candidate."
5439 (unless anything-c-adaptive-done
5440 (setq anything-c-adaptive-done t
)
5441 (let ((source (anything-c-source-use-adaptative-p)))
5443 (let* ((source-name (or (assoc-default 'type source
)
5444 (assoc-default 'name source
)))
5445 (source-info (or (assoc source-name anything-c-adaptive-history
)
5447 (push (list source-name
) anything-c-adaptive-history
)
5448 (car anything-c-adaptive-history
))))
5449 (selection (anything-get-selection))
5450 (selection-info (progn
5453 (let ((found (assoc selection
(cdr source-info
))))
5458 ;; move entry to the beginning of the
5459 ;; list, so that it doesn't get
5460 ;; trimmed when the history is
5463 (delete found
(cdr source-info
)))
5466 (cadr source-info
)))
5467 (pattern-info (progn
5468 (setcdr selection-info
5470 (let ((found (assoc anything-pattern
(cdr selection-info
))))
5473 (cons anything-pattern
0)
5475 ;; move entry to the beginning of the
5476 ;; list, so if two patterns used the
5477 ;; same number of times then the one
5478 ;; used last appears first in the list
5479 (setcdr selection-info
5480 (delete found
(cdr selection-info
)))
5482 (cdr selection-info
)))
5483 (cadr selection-info
))))
5485 ;; increase usage count
5486 (setcdr pattern-info
(1+ (cdr pattern-info
)))
5488 ;; truncate history if needed
5489 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
5490 (setcdr selection-info
5491 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
5493 (if (file-readable-p anything-c-adaptive-history-file
)
5494 (load-file anything-c-adaptive-history-file
))
5495 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
5497 (defun anything-c-adaptive-save-history ()
5498 "Save history information to file given by `anything-c-adaptive-history-file'."
5502 ";; -*- mode: emacs-lisp -*-\n"
5503 ";; History entries used for anything adaptive display.\n")
5504 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
5507 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
5508 (unless (interactive-p) 'quiet
))))
5510 (defun anything-c-adaptive-sort (candidates source
)
5511 "Sort the CANDIDATES for SOURCE by usage frequency.
5512 This is a filtered candidate transformer you can use for the
5513 attribute `filtered-candidate-transformer' of a source in
5514 `anything-sources' or a type in `anything-type-attributes'."
5515 (let* ((source-name (or (assoc-default 'type source
)
5516 (assoc-default 'name source
)))
5517 (source-info (assoc source-name anything-c-adaptive-history
)))
5518 (if (not source-info
)
5519 ;; if there is no information stored for this source then do nothing
5523 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
5525 (mapcar (lambda (candidate-info)
5527 (dolist (pattern-info (cdr candidate-info
))
5528 (if (not (equal (car pattern-info
)
5530 (incf count
(cdr pattern-info
))
5532 ;; if current pattern is equal to the previously
5533 ;; used one then this candidate has priority
5534 ;; (that's why its count is boosted by 10000) and
5535 ;; it only has to compete with other candidates
5536 ;; which were also selected with the same pattern
5537 (setq count
(+ 10000 (cdr pattern-info
)))
5539 (cons (car candidate-info
) count
)))
5543 ;; sort the list in descending order, so candidates with highest
5544 ;; priorty come first
5545 (setq usage
(sort usage
(lambda (first second
)
5546 (> (cdr first
) (cdr second
)))))
5548 ;; put those candidates first which have the highest usage count
5549 (dolist (info usage
)
5550 (when (member* (car info
) candidates
5551 :test
'anything-c-adaptive-compare
)
5552 (push (car info
) sorted
)
5553 (setq candidates
(remove* (car info
) candidates
5554 :test
'anything-c-adaptive-compare
))))
5556 ;; and append the rest
5557 (append (reverse sorted
) candidates nil
)))))
5559 (defun anything-c-adaptive-compare (x y
)
5560 "Compare candidates X and Y taking into account that the
5561 candidate can be in (DISPLAY . REAL) format."
5562 (equal (if (listp x
)
5569 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5570 ;; Plug-in: info-index
5571 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
5573 (unless (anything-candidate-buffer)
5574 (save-window-excursion
5577 (tobuf (anything-candidate-buffer 'global
))
5578 (infobuf (current-buffer))
5580 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
5581 (Info-goto-node node
)
5582 (goto-char (point-min))
5583 (while (search-forward "\n* " nil t
)
5584 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
5585 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
5586 (setq s
(point-at-bol)
5588 (with-current-buffer tobuf
5589 (insert-buffer-substring infobuf s e
)
5590 (insert "\n"))))))))))
5592 (defun anything-c-info-goto (node-line)
5593 (Info-goto-node (car node-line
))
5594 (anything-goto-line (cdr node-line
)))
5596 (defun anything-c-info-display-to-real (line)
5598 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
5599 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
5600 (string-to-number (or (match-string 3 line
) "1")))))
5602 (defun anything-c-make-info-source (file)
5603 `((name .
,(concat "Info Index: " file
))
5605 (init . anything-c-info-init
)
5606 (display-to-real . anything-c-info-display-to-real
)
5607 (get-line . buffer-substring
)
5608 (candidates-in-buffer)
5609 (action ("Goto node" . anything-c-info-goto
))))
5611 (defun anything-compile-source--info-index (source)
5612 (anything-aif (assoc-default 'info-index source
)
5613 (anything-c-make-info-source it
)
5615 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
5617 (anything-document-attribute 'info-index
"info-index plugin"
5618 "Create a source of info index very easily.
5620 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
5622 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
5623 "Index nodes of info file.
5625 If it is omitted, `Info-index-nodes' is used to collect index nodes.
5626 Some info files are missing index specification.
5628 ex. See `anything-c-source-info-screen'.")
5630 ;; Plug-in: candidates-file
5631 (defun anything-compile-source--candidates-file (source)
5632 (if (assoc-default 'candidates-file source
)
5633 `((init anything-p-candidats-file-init
5634 ,@(let ((orig-init (assoc-default 'init source
)))
5635 (cond ((null orig-init
) nil
)
5636 ((functionp orig-init
) (list orig-init
))
5638 (candidates-in-buffer)
5641 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
5643 (defun anything-p-candidats-file-init ()
5644 (destructuring-bind (file &optional updating
)
5645 (anything-mklist (anything-attr 'candidates-file
))
5646 (setq file
(anything-interpret-value file
))
5647 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
5649 (buffer-disable-undo)
5651 (auto-revert-mode 1)))))
5653 (anything-document-attribute 'candidates-file
"candidates-file plugin"
5654 "Use a file as the candidates buffer.
5656 1st argument is a filename, string or function name or variable name.
5657 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
5659 ;; Plug-in: headline
5660 (defun anything-compile-source--anything-headline (source)
5661 (if (assoc-default 'headline source
)
5662 (append '((init . anything-headline-init
)
5663 (get-line-fn . buffer-substring
)
5666 '((candidates-in-buffer)
5667 (persistent-help .
"Show this line")))
5669 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
5671 (defun anything-headline-init ()
5672 (when (and (anything-current-buffer-is-modified)
5673 (with-current-buffer anything-current-buffer
5674 (eval (or (anything-attr 'condition
) t
))))
5675 (anything-headline-make-candidate-buffer
5676 (anything-attr 'headline
)
5677 (anything-attr 'subexp
))))
5679 (anything-document-attribute 'headline
"Headline plug-in"
5680 "Regexp string for anything-headline to scan.")
5681 (anything-document-attribute 'condition
"Headline plug-in"
5682 "A sexp representing the condition to use anything-headline.")
5683 (anything-document-attribute 'subexp
"Headline plug-in"
5684 "Display (match-string-no-properties subexp).")
5687 (defun anything-headline-get-candidates (regexp subexp
)
5688 (with-current-buffer anything-current-buffer
5690 (goto-char (point-min))
5691 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
5692 (let (hierarchy curhead
)
5694 (if (numberp subexp
)
5695 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
5696 (cons (buffer-substring (point-at-bol) (point-at-eol))
5698 (hierarchies (headlines)
5699 (1+ (loop for
(_ . hierarchy
) in headlines
5700 maximize hierarchy
)))
5702 (loop for i from
0 to hierarchy
5703 collecting
(aref curhead i
)))
5704 (arrange (headlines)
5705 (unless (null headlines
) ; FIX headlines empty bug!
5706 (loop with curhead
= (make-vector (hierarchies headlines
) "")
5707 for
((str . pt
) . hierarchy
) in headlines
5708 do
(aset curhead hierarchy str
)
5711 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / ")
5716 (loop for re in regexp
5717 for hierarchy from
0
5718 do
(goto-char (point-min))
5721 while
(re-search-forward re nil t
)
5722 collect
(cons (matched) hierarchy
)))
5723 (lambda (a b
) (> (cdar b
) (cdar a
)))))
5724 (loop while
(re-search-forward regexp nil t
)
5725 collect
(matched))))))))
5728 (defun anything-headline-make-candidate-buffer (regexp subexp
)
5729 (with-current-buffer (anything-candidate-buffer 'local
)
5730 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
5733 (with-current-buffer anything-current-buffer
5734 (line-number-at-pos pos
))
5737 (defun anything-headline-goto-position (pos recenter
)
5740 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
5742 (defun anything-revert-buffer (candidate)
5743 (with-current-buffer candidate
5744 (when (buffer-modified-p)
5745 (revert-buffer t t
))))
5747 (defun anything-revert-marked-buffers (candidate)
5748 (dolist (i (anything-marked-candidates))
5749 (anything-revert-buffer i
)))
5751 (defun anything-kill-marked-buffers (candidate)
5752 (dolist (i (anything-marked-candidates))
5755 ;; Plug-in: persistent-help
5756 (defun anything-compile-source--persistent-help (source)
5757 (append source
'((header-line . anything-persistent-help-string
))))
5758 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
5760 (defun anything-persistent-help-string ()
5761 (substitute-command-keys
5762 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
5763 (or (anything-attr 'persistent-help
)
5764 (anything-aif (or (assoc-default 'persistent-action
(anything-get-current-source))
5765 (assoc-default 'action
(anything-get-current-source))
5767 (cond ((symbolp it
) (symbol-name it
))
5768 ((listp it
) (or (ignore-errors (caar it
)) ""))))
5770 " (keeping session)")))
5772 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
5773 "A string to explain persistent-action of this source.
5774 It also accepts a function or a variable name.")
5776 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
5778 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5780 (defun anything-delete-marked-files (candidate)
5781 (anything-aif (anything-marked-candidates)
5782 (if (y-or-n-p (format "Delete *%s Files " (length it
)))
5785 (set-text-properties 0 (length i
) nil i
)
5786 (anything-c-delete-file i
))
5787 (message "%s Files deleted" (length it
)))
5788 (message "(No deletions performed)"))
5789 (set-text-properties 0 (length candidate
) nil candidate
)
5790 (if (y-or-n-p (format "Really delete file `%s' " candidate
))
5792 (anything-c-delete-file candidate
)
5793 (message "1 file deleted"))
5794 (message "(No deletions performed)"))))
5796 (defun anything-ediff-marked-buffers (candidate &optional merge
)
5797 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
5798 With optional arg `merge' call `ediff-merge-buffers'."
5799 (let ((lg-lst (length (anything-marked-candidates)))
5803 (error "Error:You have to mark at least 1 buffer"))
5805 (setq buf1 anything-current-buffer
5806 buf2
(first (anything-marked-candidates))))
5808 (setq buf1
(first (anything-marked-candidates))
5809 buf2
(second (anything-marked-candidates))))
5811 (error "Error:To much buffers marked!")))
5813 (ediff-merge-buffers buf1 buf2
)
5814 (ediff-buffers buf1 buf2
))))
5816 (defun anything-bookmark-get-bookmark-from-name (bmk)
5817 "Return bookmark name even if it is a bookmark with annotation.
5818 e.g prepended with *.
5819 Return nil if bmk is not a valid bookmark."
5820 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
5821 (if (assoc bookmark bookmark-alist
)
5823 (when (assoc bmk bookmark-alist
)
5826 (defun anything-delete-marked-bookmarks (elm)
5827 "Delete this bookmark or all marked bookmarks."
5828 (let ((bookmark (anything-bookmark-get-bookmark-from-name elm
)))
5829 (anything-aif (anything-marked-candidates)
5831 (let ((bmk (anything-bookmark-get-bookmark-from-name i
)))
5832 (bookmark-delete bmk
'batch
)))
5833 (bookmark-delete bookmark
'batch
))))
5835 (defun anything-require-or-error (feature function
)
5836 (or (require feature nil t
)
5837 (error "Need %s to use `%s'." feature function
)))
5839 (defun anything-find-buffer-on-elscreen (candidate)
5840 "Open buffer in new screen, if marked buffers open all in elscreens."
5841 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
5842 (anything-aif (anything-marked-candidates)
5844 (let ((target-screen (elscreen-find-screen-by-buffer
5845 (get-buffer i
) 'create
)))
5846 (elscreen-goto target-screen
)))
5847 (let ((target-screen (elscreen-find-screen-by-buffer
5848 (get-buffer candidate
) 'create
)))
5849 (elscreen-goto target-screen
))))
5851 (defun anything-elscreen-find-file (file)
5852 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
5853 (elscreen-find-file file
))
5855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5858 (define-anything-type-attribute 'buffer
5861 '(("Switch to buffer other window" . switch-to-buffer-other-window
)
5862 ("Switch to buffer" . switch-to-buffer
))
5863 '(("Switch to buffer" . switch-to-buffer
)
5864 ("Switch to buffer other window" . switch-to-buffer-other-window
)
5865 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)))
5866 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
5867 ("Display buffer" . display-buffer
)
5868 ("Revert buffer" . anything-revert-buffer
)
5869 ("Revert Marked buffers" . anything-revert-marked-buffers
)
5870 ("Kill buffer" . kill-buffer
)
5871 ("Kill Marked buffers" . anything-kill-marked-buffers
)
5872 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
5873 ("Ediff Merge marked buffers" .
(lambda (candidate)
5874 (anything-ediff-marked-buffers candidate t
))))
5875 (persistent-help .
"Show this buffer")
5876 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers
))
5877 "Buffer or buffer name.")
5879 (define-anything-type-attribute 'file
5882 '(("Find file other window" . find-file-other-window
)
5883 ("Find file(s)" . anything-find-many-files
)
5884 ("Find file as root" . anything-find-file-as-root
))
5885 '(("Find file" . anything-find-many-files
)
5886 ("Find file as root" . anything-find-file-as-root
)
5887 ("Find file other window" . find-file-other-window
)
5888 ("Find file other frame" . find-file-other-frame
)))
5889 ("Open dired in file's directory" . anything-c-open-dired
)
5890 ("Delete file(s)" . anything-delete-marked-files
)
5891 ("Open file externally" . anything-c-open-file-externally
)
5892 ("Open file with default tool" . anything-c-open-file-with-default-tool
))
5893 (persistent-help .
"Show this file")
5894 (action-transformer anything-c-transform-file-load-el
5895 anything-c-transform-file-browse-url
)
5896 (candidate-transformer anything-c-w32-pathname-transformer
5897 anything-c-skip-current-file
5898 anything-c-skip-boring-files
5899 anything-c-shorten-home-path
))
5902 (define-anything-type-attribute 'command
5903 `((action ("Call interactively" . anything-c-call-interactively
)
5904 ("Describe command" . anything-c-describe-function
)
5905 ("Add command to kill ring" . anything-c-kill-new
)
5906 ("Go to command's definition" . anything-c-find-function
))
5907 ;; Sort commands according to their usage count.
5908 (filtered-candidate-transformer . anything-c-adaptive-sort
))
5909 "Command. (string or symbol)")
5911 (define-anything-type-attribute 'function
5912 '((action ("Describe function" . anything-c-describe-function
)
5913 ("Add function to kill ring" . anything-c-kill-new
)
5914 ("Go to function's definition" . anything-c-find-function
))
5915 (action-transformer anything-c-transform-function-call-interactively
)
5916 (candidate-transformer anything-c-mark-interactive-functions
))
5917 "Function. (string or symbol)")
5919 (define-anything-type-attribute 'variable
5920 '((action ("Describe variable" . anything-c-describe-variable
)
5921 ("Add variable to kill ring" . anything-c-kill-new
)
5922 ("Go to variable's definition" . anything-c-find-variable
)
5923 ("Set variable" . anything-c-set-variable
)))
5926 (define-anything-type-attribute 'sexp
5927 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
5928 ("Add s-expression to kill ring" . kill-new
))
5929 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
5930 "String representing S-Expressions.")
5932 (define-anything-type-attribute 'bookmark
5934 ("Jump to bookmark" .
(lambda (candidate)
5935 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
))
5936 (current-prefix-arg anything-current-prefix-arg
))
5937 (bookmark-jump bookmark
))
5939 ("Jump to BM other window" .
(lambda (candidate)
5940 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5941 (bookmark-jump-other-window bookmark
))
5943 ("Bookmark edit annotation" .
(lambda (candidate)
5944 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5945 (bookmark-edit-annotation bookmark
))))
5946 ("Bookmark show annotation" .
(lambda (candidate)
5947 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5948 (bookmark-show-annotation bookmark
))))
5949 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
5950 ,@(when (fboundp 'bmkext-edit-bookmark
)
5951 '(("Edit Bookmark" .
(lambda (candidate)
5952 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5953 (bmkext-edit-bookmark bookmark
))))))
5954 ("Rename bookmark" .
(lambda (candidate)
5955 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5956 (bookmark-rename bookmark
))))
5957 ("Relocate bookmark" .
(lambda (candidate)
5958 (let ((bookmark (anything-bookmark-get-bookmark-from-name candidate
)))
5959 (bookmark-relocate bookmark
))))))
5962 (define-anything-type-attribute 'line
5963 '((display-to-real . anything-c-display-to-real-line
)
5964 (action ("Go to Line" . anything-c-action-line-goto
)))
5965 "LINENO:CONTENT string, eg. \" 16:foo\".
5967 Optional `target-file' attribute is a name of target file.
5969 Optional `before-jump-hook' attribute is a function with no
5970 arguments which is called before jumping to position.
5972 Optional `after-jump-hook' attribute is a function with no
5973 arguments which is called after jumping to position.
5975 If `adjust' attribute is specified, searches the line whose
5976 content is CONTENT near the LINENO.
5978 If `recenter' attribute is specified, the line is displayed at
5979 the center of window, otherwise at the top of window.
5982 (define-anything-type-attribute 'file-line
5983 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
5985 (action ("Go to" . anything-c-action-file-line-goto
)))
5986 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
5988 Optional `default-directory' attribute is a default-directory
5989 FILENAME is interpreted.
5991 Optional `before-jump-hook' attribute is a function with no
5992 arguments which is called before jumping to position.
5994 Optional `after-jump-hook' attribute is a function with no
5995 arguments which is called after jumping to position.
5997 If `adjust' attribute is specified, searches the line whose
5998 content is CONTENT near the LINENO.
6000 If `recenter' attribute is specified, the line is displayed at
6001 the center of window, otherwise at the top of window.
6004 (define-anything-type-attribute 'timer
6005 '((real-to-display . anything-c-timer-real-to-display
)
6006 (action ("Cancel Timer" . cancel-timer
)))
6010 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
6011 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
6013 (when (fboundp 'expectations
)
6015 (desc "candidates-file plug-in")
6016 (expect '(anything-p-candidats-file-init)
6017 (assoc-default 'init
6018 (car (anything-compile-sources
6020 (candidates-file .
"test.txt")))
6021 '(anything-compile-source--candidates-file)))))
6022 (expect '(anything-p-candidats-file-init
6024 (assoc-default 'init
6025 (car (anything-compile-sources
6027 (candidates-file .
"test.txt")
6028 (init .
(lambda () 1))))
6029 '(anything-compile-source--candidates-file)))))
6030 (expect '(anything-p-candidats-file-init
6032 (assoc-default 'init
6033 (car (anything-compile-sources
6035 (candidates-file .
"test.txt")
6036 (init (lambda () 1))))
6037 '(anything-compile-source--candidates-file)))))
6038 (desc "anything-c-source-buffers")
6039 (expect '(("Buffers" ("foo" "curbuf")))
6040 (stub buffer-list
=> '("curbuf" " hidden" "foo" "*anything*"))
6041 (let ((anything-c-boring-buffer-regexp
6046 " *Echo Area" " *Minibuf"))))
6047 (flet ((buffer-name (x) x
))
6048 (anything-test-candidates 'anything-c-source-buffers
))))
6049 (desc "anything-c-stringify")
6051 (anything-c-stringify "str1"))
6053 (anything-c-stringify 'str2
))
6054 (desc "anything-c-symbolify")
6056 (anything-c-symbolify "sym1"))
6058 (anything-c-symbolify 'sym2
)))))
6060 (provide 'anything-config
)
6062 ;;; Local Variables:
6063 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
6066 ;; How to save (DO NOT REMOVE!!)
6067 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
6068 ;;; anything-config.el ends here
6070 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
6071 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
6072 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
6073 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
6074 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
6075 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
6076 ;;; LocalWords: dotimes Thierry online vname
6077 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
6078 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
6079 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
6080 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
6081 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
6082 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
6083 ;;; LocalWords: startpos noselect dont desc