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-configuration'
83 ;; Customize `anything'.
84 ;; `anything-c-describe-anything-bindings'
85 ;; [OBSOLETE] Describe `anything' bindings.
87 ;; Preconfigured `anything' lightweight version (buffer -> recentf).
88 ;; `anything-for-files'
89 ;; Preconfigured `anything' for opening files.
91 ;; Preconfigured `anything' for `recentf'.
92 ;; `anything-info-at-point'
93 ;; Preconfigured `anything' for searching info at point.
94 ;; `anything-info-emacs'
95 ;; Preconfigured anything for Emacs manual index.
96 ;; `anything-show-kill-ring'
97 ;; Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
98 ;; `anything-minibuffer-history'
99 ;; Preconfigured `anything' for `minibuffer-history'.
101 ;; Preconfigured `anything' for gentoo linux.
103 ;; Preconfigured `anything' for `imenu'.
104 ;; `anything-google-suggest'
105 ;; Preconfigured `anything' for google search with google suggest.
106 ;; `anything-yahoo-suggest'
107 ;; Preconfigured `anything' for Yahoo searching with Yahoo suggest.
108 ;; `anything-for-buffers'
109 ;; Preconfigured `anything' for buffer.
110 ;; `anything-buffers+'
111 ;; Enhanced preconfigured `anything' for buffer.
113 ;; Preconfigured `anything' for BBDB.
115 ;; Preconfigured `anything' for Locate.
116 ;; `anything-w3m-bookmarks'
117 ;; Preconfigured `anything' for w3m bookmark.
118 ;; `anything-firefox-bookmarks'
119 ;; Preconfigured `anything' for firefox bookmark.
121 ;; Preconfigured `anything' for color.
122 ;; `anything-bookmarks'
123 ;; Preconfigured `anything' for bookmarks.
124 ;; `anything-c-pp-bookmarks'
125 ;; Preconfigured `anything' for bookmarks (pretty-printed).
126 ;; `anything-register'
127 ;; Preconfigured `anything' for Emacs registers.
128 ;; `anything-man-woman'
129 ;; Preconfigured `anything' for Man and Woman pages.
130 ;; `anything-org-keywords'
131 ;; Preconfigured `anything' for org keywords.
133 ;; Preconfigured `anything' for emms sources.
134 ;; `anything-eev-anchors'
135 ;; Preconfigured `anything' for eev anchors.
136 ;; `anything-bm-list'
137 ;; Preconfigured `anything' for visible bookmarks.
139 ;; Preconfigured `anything' for timers.
140 ;; `anything-kill-buffers'
141 ;; Preconfigured `anything' to kill buffer you selected.
143 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
144 ;; `anything-insert-buffer-name'
145 ;; Insert buffer name.
146 ;; `anything-insert-symbol'
147 ;; Insert current symbol.
148 ;; `anything-insert-selection'
149 ;; Insert current selection.
150 ;; `anything-show-buffer-only'
151 ;; [OBSOLETE] Only show sources about buffer.
152 ;; `anything-show-bbdb-only'
153 ;; [OBSOLETE] Only show sources about BBDB.
154 ;; `anything-show-locate-only'
155 ;; [OBSOLETE] Only show sources about Locate.
156 ;; `anything-show-info-only'
157 ;; [OBSOLETE] Only show sources about Info.
158 ;; `anything-show-imenu-only'
159 ;; [OBSOLETE] Only show sources about Imenu.
160 ;; `anything-show-files-only'
161 ;; [OBSOLETE] Only show sources about File.
162 ;; `anything-show-w3m-bookmarks-only'
163 ;; [OBSOLETE] Only show source about w3m bookmark.
164 ;; `anything-show-colors-only'
165 ;; [OBSOLETE] Only show source about color.
166 ;; `anything-show-kill-ring-only'
167 ;; [OBSOLETE] Only show source about kill ring.
168 ;; `anything-show-this-source-only'
169 ;; Only show this source.
170 ;; `anything-test-sources'
171 ;; List all anything sources for test.
172 ;; `anything-select-source'
174 ;; `anything-find-files-down-one-level'
175 ;; Go down one level like unix command `cd ..'.
176 ;; `anything-find-files'
177 ;; Preconfigured `anything' for anything implementation of `find-file'.
178 ;; `anything-write-file'
179 ;; Preconfigured `anything' providing completion for `write-file'.
180 ;; `anything-insert-file'
181 ;; Preconfigured `anything' providing completion for `insert-file'.
182 ;; `anything-dired-rename-file'
183 ;; Preconfigured `anything' to rename files from dired.
184 ;; `anything-dired-copy-file'
185 ;; Preconfigured `anything' to copy files from dired.
186 ;; `anything-dired-symlink-file'
187 ;; Preconfigured `anything' to symlink files from dired.
188 ;; `anything-dired-hardlink-file'
189 ;; Preconfigured `anything' to hardlink files from dired.
190 ;; `anything-dired-bindings'
191 ;; Replace usual dired commands `C' and `R' by anything ones.
193 ;; Preconfigured `anything' for Emacs commands.
194 ;; `anything-manage-advice'
195 ;; Preconfigured `anything' to disable/enable function advices.
196 ;; `anything-bookmark-ext'
197 ;; Preconfigured `anything' for bookmark-extensions sources.
198 ;; `anything-simple-call-tree'
199 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
200 ;; `anything-mark-ring'
201 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
202 ;; `anything-global-mark-ring'
203 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
204 ;; `anything-all-mark-rings'
205 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
206 ;; `anything-yaoddmuse-cache-pages'
207 ;; Fetch the list of files on emacswiki and create cache file.
208 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
209 ;; Preconfigured `anything' to edit or view EmacsWiki page.
210 ;; `anything-yaoddmuse-emacswiki-post-library'
211 ;; Preconfigured `anything' to post library to EmacsWiki.
212 ;; `anything-eval-expression'
213 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
214 ;; `anything-eval-expression-with-eldoc'
215 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
216 ;; `anything-surfraw'
217 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
218 ;; `anything-emms-stream-edit-bookmark'
219 ;; Change the information of current emms-stream bookmark from anything.
220 ;; `anything-emms-stream-delete-bookmark'
221 ;; Delete an emms-stream bookmark from anything.
222 ;; `anything-call-source'
223 ;; Preconfigured `anything' to call anything source.
224 ;; `anything-call-source-from-anything'
225 ;; Call anything source within `anything' session.
226 ;; `anything-execute-anything-command'
227 ;; Preconfigured `anything' to execute preconfigured `anything'.
229 ;; Preconfigured Anything for Occur source.
230 ;; `anything-create-from-anything'
231 ;; Run `anything-create' from `anything' as a fallback.
233 ;; Preconfigured `anything' to do many create actions from STRING.
235 ;; Preconfigured `anything' for top command.
236 ;; `anything-select-xfont'
237 ;; Preconfigured `anything' to select Xfont.
239 ;; Preconfigured `anything' : frontend of APT package manager.
240 ;; `anything-c-shell-command-if-needed'
242 ;; `anything-c-run-external-command'
243 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
244 ;; `anything-ratpoison-commands'
245 ;; Preconfigured `anything' to execute ratpoison commands.
246 ;; `anything-c-set-variable'
247 ;; Set value to VAR interactively.
248 ;; `anything-c-adaptive-save-history'
249 ;; Save history information to file given by `anything-c-adaptive-history-file'.
251 ;; * User variables defined here:
252 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
253 ;; `anything-c-use-standard-keys'
254 ;; Default Value: nil
255 ;; `anything-c-adaptive-history-file'
256 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
257 ;; `anything-c-adaptive-history-length'
259 ;; `anything-c-google-suggest-url'
260 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
261 ;; `anything-c-google-suggest-search-url'
262 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
263 ;; `anything-google-suggest-use-curl-p'
264 ;; Default Value: nil
265 ;; `anything-c-yahoo-suggest-url'
266 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
267 ;; `anything-c-yahoo-suggest-search-url'
268 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
269 ;; `anything-c-boring-buffer-regexp'
270 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
271 ;; `anything-c-boring-file-regexp'
272 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
273 ;; `anything-kill-ring-threshold'
275 ;; `anything-su-or-sudo'
276 ;; Default Value: "su"
277 ;; `anything-for-files-prefered-list'
278 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
279 ;; `anything-create--actions-private'
280 ;; Default Value: nil
281 ;; `anything-allow-skipping-current-buffer'
283 ;; `anything-c-enable-eval-defun-hack'
285 ;; `anything-tramp-verbose'
287 ;; `anything-raise-command'
288 ;; Default Value: nil
289 ;; `anything-command-map-prefix-key'
290 ;; Default Value: "<f5> a"
291 ;; `anything-c-find-files-show-icons'
292 ;; Default Value: nil
294 ;; * Anything sources defined here:
295 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
296 ;; `anything-c-source-regexp' (Regexp Builder)
297 ;; `anything-c-source-buffers' (Buffers)
298 ;; `anything-c-source-buffer-not-found' (Create buffer)
299 ;; `anything-c-source-buffers+' (Buffers)
300 ;; `anything-c-source-file-name-history' (File Name History)
301 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
302 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
303 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
304 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
305 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
306 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
307 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
308 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
309 ;; `anything-c-source-file-cache-initialized' ()
310 ;; `anything-c-source-file-cache' (File Cache)
311 ;; `anything-c-source-locate' (Locate)
312 ;; `anything-c-source-recentf' (Recentf)
313 ;; `anything-c-source-ffap-guesser' (File at point)
314 ;; `anything-c-source-ffap-line' (File/Lineno at point)
315 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
316 ;; `anything-c-source-info-pages' (Info Pages)
317 ;; `anything-c-source-info-elisp' (Info index: elisp)
318 ;; `anything-c-source-info-cl' (Info index: cl)
319 ;; `anything-c-source-info-org' (Info index: org)
320 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
321 ;; `anything-c-source-info-zsh' (Info index: zsh)
322 ;; `anything-c-source-info-bash' (Info index: bash)
323 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
324 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
325 ;; `anything-c-source-info-find' (Info index: find)
326 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
327 ;; `anything-c-source-info-textutils' (Info index: textutils)
328 ;; `anything-c-source-info-libc' (Info index: libc)
329 ;; `anything-c-source-info-make' (Info index: make)
330 ;; `anything-c-source-info-automake' (Info index: automake)
331 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
332 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
333 ;; `anything-c-source-info-emacs' (Info index: emacs)
334 ;; `anything-c-source-info-elib' (Info index: elib)
335 ;; `anything-c-source-info-eieio' (Info index: eieio)
336 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
337 ;; `anything-c-source-info-guile' (Info index: guile)
338 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
339 ;; `anything-c-source-info-goops' (Info index: goops)
340 ;; `anything-c-source-info-screen' (Info index: screen)
341 ;; `anything-c-source-info-latex' (Info index: latex)
342 ;; `anything-c-source-info-gawk' (Info index: gawk)
343 ;; `anything-c-source-info-sed' (Info index: sed)
344 ;; `anything-c-source-info-m4' (Info index: m4)
345 ;; `anything-c-source-info-wget' (Info index: wget)
346 ;; `anything-c-source-info-binutils' (Info index: binutils)
347 ;; `anything-c-source-info-as' (Info index: as)
348 ;; `anything-c-source-info-bfd' (Info index: bfd)
349 ;; `anything-c-source-info-gprof' (Info index: gprof)
350 ;; `anything-c-source-info-ld' (Info index: ld)
351 ;; `anything-c-source-info-diff' (Info index: diff)
352 ;; `anything-c-source-info-flex' (Info index: flex)
353 ;; `anything-c-source-info-grep' (Info index: grep)
354 ;; `anything-c-source-info-gzip' (Info index: gzip)
355 ;; `anything-c-source-info-libtool' (Info index: libtool)
356 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
357 ;; `anything-c-source-info-info' (Info index: info)
358 ;; `anything-c-source-info-gdb' (Info index: gdb)
359 ;; `anything-c-source-info-stabs' (Info index: stabs)
360 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
361 ;; `anything-c-source-info-cvs' (Info index: cvs)
362 ;; `anything-c-source-info-bison' (Info index: bison)
363 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
364 ;; `anything-c-source-info-global' (Info index: global)
365 ;; `anything-c-source-man-pages' (Manual Pages)
366 ;; `anything-c-source-complex-command-history' (Complex Command History)
367 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
368 ;; `anything-c-source-emacs-commands' (Emacs Commands)
369 ;; `anything-c-source-lacarte' (Lacarte)
370 ;; `anything-c-source-emacs-functions' (Emacs Functions)
371 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
372 ;; `anything-c-source-advice' (Function Advice)
373 ;; `anything-c-source-emacs-variables' (Emacs Variables)
374 ;; `anything-c-source-bookmarks' (Bookmarks)
375 ;; `anything-c-source-bookmark-set' (Set Bookmark)
376 ;; `anything-c-source-bm' (Visible Bookmarks)
377 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
378 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
379 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
380 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
381 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
382 ;; `anything-c-source-bookmark-images' (Bookmark Images)
383 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
384 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
385 ;; `anything-c-source-bookmark-info' (Bookmark Info)
386 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
387 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
388 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
389 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
390 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
391 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
392 ;; `anything-c-source-imenu' (Imenu)
393 ;; `anything-c-source-ctags' (Exuberant ctags)
394 ;; `anything-c-source-semantic' (Semantic Tags)
395 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
396 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
397 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
398 ;; `anything-c-source-customize-face' (Customize Face)
399 ;; `anything-c-source-colors' (Colors)
400 ;; `anything-c-source-tracker-search' (Tracker Search)
401 ;; `anything-c-source-mac-spotlight' (mdfind)
402 ;; `anything-c-source-kill-ring' (Kill Ring)
403 ;; `anything-c-source-mark-ring' (mark-ring)
404 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
405 ;; `anything-c-source-register' (Registers)
406 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
407 ;; `anything-c-source-rd-headline' (RD HeadLine)
408 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
409 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
410 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
411 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
412 ;; `anything-c-source-org-headline' (Org HeadLine)
413 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
414 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
415 ;; `anything-c-source-eev-anchor' (Anchors)
416 ;; `anything-c-source-org-keywords' (Org Keywords)
417 ;; `anything-c-source-picklist' (Picklist)
418 ;; `anything-c-source-bbdb' (BBDB)
419 ;; `anything-c-source-evaluation-result' (Evaluation Result)
420 ;; `anything-c-source-calculation-result' (Calculation Result)
421 ;; `anything-c-source-google-suggest' (Google Suggest)
422 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
423 ;; `anything-c-source-emms-streams' (Emms Streams)
424 ;; `anything-c-source-emms-dired' (Music Directory)
425 ;; `anything-c-source-emms-files' (Emms files)
426 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
427 ;; `anything-c-source-call-source' (Call anything source)
428 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
429 ;; `anything-c-source-occur' (Occur)
430 ;; `anything-c-source-create' (Create)
431 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
432 ;; `anything-c-source-elscreen' (Elscreen)
433 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
434 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
435 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
436 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
437 ;; `anything-c-source-xfonts' (X Fonts)
438 ;; `anything-c-source-apt' (APT)
439 ;; `anything-c-source-gentoo' (Portage sources)
440 ;; `anything-c-source-use-flags' (Use Flags)
441 ;; `anything-c-source-emacs-process' (Emacs Process)
442 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
444 ;; *** END auto-documentation
449 ;; Change log of this file is found at
450 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
452 ;; Change log of this project is found at
453 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
458 ;; Tassilo Horn <tassilo@member.fsf.org>
459 ;; Vagn Johansen <gonz808@hotmail.com>
460 ;; Mathias Dahl <mathias.dahl@gmail.com>
461 ;; Bill Clementson <billclem@gmail.com>
462 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
463 ;; Drew Adams <drew.adams@oracle.com>
464 ;; Jason McBrayer <jmcbray@carcosa.net>
465 ;; Andy Stewart <lazycat.manatee@gmail.com>
466 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
467 ;; rubikitch <rubikitch@ruby-lang.org>
468 ;; Scott Vokes <vokes.s@gmail.com>
473 ;; Evaluate (autodoc-update-all) before commit. This function
474 ;; generates anything-c-source-* / functions / options list.
476 ;; Install also developer-tools/autodoc.el
477 ;; And eval it or run interactively.
479 ;; [EVAL IT] (autodoc-update-all)
481 ;; Please write details documentation about function, then others will
482 ;; read code more easier. -- Andy Stewart
488 ;; - Fix documentation, now many functions haven't documentations.
500 (let ((version "1.263"))
501 (when (and (string= "1." (substring version
0 2))
502 (string-match "1\.\\([0-9]+\\)" anything-version
)
503 (< (string-to-number (match-string 1 anything-version
))
504 (string-to-number (substring version
2))))
505 (error "Please update anything.el!!
507 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
509 or M-x install-elisp-from-emacswiki anything.el")))
511 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
512 (defgroup anything-config nil
513 "Predefined configurations for `anything.el'."
516 (defcustom anything-c-use-standard-keys nil
517 "Whether use standard keybindings. (no effect)
519 Key definitions in anything-config.el are removed because
520 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
521 minibuffer history, C-s for isearch, etc.
523 If you use `iswitchb' with `anything',
524 evaluate (anything-iswitchb-setup) . Then some bindings that
525 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
526 history, are removed from `anything-map'. "
528 :group
'anything-config
)
530 (defcustom anything-c-adaptive-history-file
"~/.emacs.d/anything-c-adaptive-history"
531 "Path of file where history information is stored."
533 :group
'anything-config
)
535 (defcustom anything-c-adaptive-history-length
50
536 "Maximum number of candidates stored for a source."
538 :group
'anything-config
)
540 (defcustom anything-c-google-suggest-url
541 "http://google.com/complete/search?output=toolbar&q="
542 "URL used for looking up Google suggestions."
544 :group
'anything-config
)
546 (defcustom anything-c-google-suggest-search-url
547 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
548 "URL used for Google searching."
550 :group
'anything-config
)
552 (defcustom anything-google-suggest-use-curl-p nil
553 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
554 Otherwise `url-retrieve-synchronously' is used."
556 :group
'anything-config
)
558 (defcustom anything-c-yahoo-suggest-url
559 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
560 "Url used for looking up Yahoo suggestions."
562 :group
'anything-config
)
564 (defcustom anything-c-yahoo-suggest-search-url
565 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
566 "Url used for Yahoo searching."
568 :group
'anything-config
)
570 (defcustom anything-c-boring-buffer-regexp
576 " *Echo Area" " *Minibuf"))
577 "The regexp that match boring buffers.
578 Buffer candidates matching this regular expression will be
579 filtered from the list of candidates if the
580 `anything-c-skip-boring-buffers' candidate transformer is used, or
581 they will be displayed with face `file-name-shadow' if
582 `anything-c-shadow-boring-buffers' is used."
584 :group
'anything-config
)
585 ;; (string-match anything-c-boring-buffer-regexp "buf")
586 ;; (string-match anything-c-boring-buffer-regexp " hidden")
587 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
589 (defcustom anything-c-boring-file-regexp
591 ;; Boring directories
592 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
594 (and line-start
".#")
595 (and (or ".class" ".la" ".o" "~") eol
)))
596 "The regexp that match boring files.
597 File candidates matching this regular expression will be
598 filtered from the list of candidates if the
599 `anything-c-skip-boring-files' candidate transformer is used, or
600 they will be displayed with face `file-name-shadow' if
601 `anything-c-shadow-boring-files' is used."
603 :group
'anything-config
)
605 (defcustom anything-kill-ring-threshold
10
606 "*Minimum length to be listed by `anything-c-source-kill-ring'."
608 :group
'anything-config
)
610 (defcustom anything-su-or-sudo
"su"
611 "What command to use for root access."
613 :group
'anything-config
)
615 (defcustom anything-for-files-prefered-list
616 '(anything-c-source-ffap-line
617 anything-c-source-ffap-guesser
618 anything-c-source-buffers
+
619 anything-c-source-recentf
620 anything-c-source-bookmarks
621 anything-c-source-file-cache
622 anything-c-source-files-in-current-dir
+
623 anything-c-source-locate
)
624 "Your prefered sources to find files."
626 :group
'anything-config
)
628 (defcustom anything-create--actions-private nil
629 "User defined actions for `anything-create' / `anything-c-source-create'.
630 It is a list of (DISPLAY . FUNCTION) pairs like `action'
631 attribute of `anything-sources'.
633 It is prepended to predefined pairs."
635 :group
'anything-config
)
637 (defcustom anything-allow-skipping-current-buffer t
638 "Show current buffer or not in anything buffer"
640 :group
'anything-config
)
642 (defcustom anything-c-enable-eval-defun-hack t
643 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
644 This hack is invoked when pressing C-M-x in the form \
645 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
647 :group
'anything-config
)
649 (defcustom anything-tramp-verbose
0
650 "*Just like `tramp-verbose' but specific to anything.
651 When set to 0 don't show tramp messages in anything.
652 If you want to have the default tramp messages set it to 3."
654 :group
'anything-config
)
656 (defcustom anything-raise-command nil
657 "*A shell command to jump to a window running specific program.
658 Stumpwm users could use:
659 \"stumpish eval \"\(stumpwm::%s\)\"\".
660 With others windows manager you could use:
662 Though wmctrl work also with stumpwm."
664 :group
'anything-config
)
666 (defun anything-set-anything-command-map-prefix-key (var key
)
667 (when (boundp 'anything-command-map-prefix-key
)
668 (global-unset-key (read-kbd-macro anything-command-map-prefix-key
)))
669 (setq anything-command-map-prefix-key key
)
670 (global-set-key (read-kbd-macro anything-command-map-prefix-key
)
671 'anything-command-map
))
673 (defcustom anything-command-map-prefix-key
"<f5> a"
674 "*The prefix key for all `anything-command-map' commands.
677 This default value is very likely to be changed,
678 because it is under discussion."
680 :set
'anything-set-anything-command-map-prefix-key
681 :group
'anything-config
)
683 (defcustom anything-c-find-files-show-icons nil
684 "*Whether show or hide icons in `anything-find-files'."
686 :group
'anything-config
)
688 (defcustom anything-c-find-files-icons-directory
689 (concat (car image-load-path
) "tree-widget/default")
690 "*Default path where to find files and directory icons."
692 :group
'anything-config
)
694 (defcustom anything-c-browse-code-regexp-lisp
695 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
696 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
697 "*Regexp used to parse lisp buffer when browsing code."
699 :group
'anything-config
)
701 (defcustom anything-c-browse-code-regexp-python
702 "\\<def\\>\\|\\<class\\>"
703 "*Regexp used to parse python buffer when browsing code."
705 :group
'anything-config
)
707 (defcustom anything-c-browse-code-regexp-alist
708 `((lisp-interaction-mode .
,anything-c-browse-code-regexp-lisp
)
709 (emacs-lisp-mode .
,anything-c-browse-code-regexp-lisp
)
710 (lisp-mode .
,anything-c-browse-code-regexp-lisp
)
711 (python-mode .
,anything-c-browse-code-regexp-python
))
712 "*Alist to store regexps for browsing code corresponding \
713 to a specific `major-mode'."
715 :group
'anything-config
)
717 (defcustom anything-c-external-programs-associations nil
718 "*Alist to store externals programs associated with file extension.
719 This variable overhide setting in .mailcap file.
720 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
722 :group
'anything-config
)
725 (defun anything-configuration ()
726 "Customize `anything'."
728 (customize-group "anything-config"))
730 ;;; Anything-command-map
732 (defvar anything-command-map
)
733 (define-prefix-command 'anything-command-map
)
735 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
736 (define-key anything-command-map
(kbd "<SPC>") 'anything-execute-anything-command
)
737 (define-key anything-command-map
(kbd "e") 'anything-etags-maybe-at-point
)
738 (define-key anything-command-map
(kbd "l") 'anything-locate
)
739 (define-key anything-command-map
(kbd "s") 'anything-surfraw
)
740 (define-key anything-command-map
(kbd "r") 'anything-regexp
)
741 (define-key anything-command-map
(kbd "w") 'anything-w3m-bookmarks
)
742 (define-key anything-command-map
(kbd "x") 'anything-firefox-bookmarks
)
743 (define-key anything-command-map
(kbd "#") 'anything-emms
)
744 (define-key anything-command-map
(kbd "m") 'anything-man-woman
)
745 (define-key anything-command-map
(kbd "t") 'anything-top
)
746 (define-key anything-command-map
(kbd "i") 'anything-imenu
)
747 (define-key anything-command-map
(kbd "p") 'anything-list-emacs-process
)
748 (define-key anything-command-map
(kbd "C-x r b") 'anything-c-pp-bookmarks
)
749 (define-key anything-command-map
(kbd "M-y") 'anything-show-kill-ring
)
750 (define-key anything-command-map
(kbd "C-c <SPC>") 'anything-all-mark-rings
)
751 (define-key anything-command-map
(kbd "C-x C-f") 'anything-find-files
)
752 (define-key anything-command-map
(kbd "f") 'anything-for-files
)
753 (define-key anything-command-map
(kbd "C-:") 'anything-eval-expression-with-eldoc
)
754 (define-key anything-command-map
(kbd "C-,") 'anything-calcul-expression
)
755 (define-key anything-command-map
(kbd "M-x") 'anything-M-x
)
756 (define-key anything-command-map
(kbd "C-x C-w") 'anything-write-file
)
757 (define-key anything-command-map
(kbd "C-x i") 'anything-insert-file
)
758 (define-key anything-command-map
(kbd "M-s o") 'anything-occur
)
759 (define-key anything-command-map
(kbd "c") 'anything-colors
)
760 (define-key anything-command-map
(kbd "F") 'anything-select-xfont
)
761 (define-key anything-command-map
(kbd "C-c f") 'anything-recentf
)
762 (define-key anything-command-map
(kbd "C-c g") 'anything-google-suggest
)
763 (define-key anything-command-map
(kbd "h i") 'anything-info-at-point
)
764 (define-key anything-command-map
(kbd "h r") 'anything-info-emacs
)
765 (define-key anything-command-map
(kbd "C-x C-b") 'anything-buffers
+)
766 (define-key anything-command-map
(kbd "C-c C-b") 'anything-browse-code
)
767 (define-key anything-command-map
(kbd "C-x r i") 'anything-register
)
768 (define-key anything-command-map
(kbd "C-c C-x") 'anything-c-run-external-command
)
770 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
771 ;; minibuffer-local-filename-must-match-map.
772 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
773 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
774 (dolist (map (list minibuffer-local-filename-completion-map
775 minibuffer-local-completion-map
776 minibuffer-local-must-match-filename-map
777 minibuffer-local-filename-must-match-map
779 minibuffer-local-isearch-map
780 minibuffer-local-must-match-map
781 minibuffer-local-ns-map
))
782 (define-key map
"\C-r" 'anything-minibuffer-history
))
785 (easy-menu-define nil global-map
788 ["All anything commands" anything-execute-anything-command t
]
789 ["Find any Files/Buffers" anything-for-files t
]
792 ["Find files" anything-find-files t
]
793 ["Recent Files" anything-recentf t
]
794 ["Locate" anything-locate t
]
795 ["Bookmarks" anything-c-pp-bookmarks t
])
797 ["Find buffers" anything-buffers
+ t
])
799 ["Emacs Commands" anything-M-x t
]
800 ["Externals Commands" anything-c-run-external-command t
])
802 ["Info at point" anything-info-at-point t
]
803 ["Emacs Manual index" anything-info-emacs t
])
805 ["Occur" anything-occur t
]
806 ["Browse Kill ring" anything-show-kill-ring t
]
807 ["Browse register" anything-register t
]
808 ["Browse code" anything-browse-code t
]
809 ["Mark Ring" anything-all-mark-rings t
]
810 ["Regexp handler" anything-regexp t
]
811 ["Colors & Faces" anything-colors t
]
812 ["Show xfonts" anything-select-xfont t
]
813 ["Imenu" anything-imenu t
]
814 ["Google Suggest" anything-google-suggest t
]
815 ["Eval expression" anything-eval-expression-with-eldoc t
]
816 ["Calcul expression" anything-calcul-expression t
]
817 ["Man pages" anything-man-woman t
]
818 ["Top externals process" anything-top t
]
819 ["Emacs internals process" anything-list-emacs-process t
])
821 ["Prefered Options" anything-configuration t
]))
825 ;; It is replaced by `anything-help'
826 (defun anything-c-describe-anything-bindings ()
827 "[OBSOLETE] Describe `anything' bindings."
829 (anything-run-after-quit
831 (with-current-buffer (get-buffer-create "*Anything Help*")
834 (substitute-command-keys
835 "The keys that are defined for `anything' are:
837 (pop-to-buffer "*Anything Help*")
838 (goto-char (point-min)))))
840 ;; Use `describe-mode' key in `global-map'
841 ;; (dolist (k (where-is-internal 'describe-mode global-map))
842 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
845 (defun anything-c-list-preconfigured-anything ()
848 for entry in
(cdr (assoc
849 (file-truename (locate-library "anything-config"))
851 if
(and (consp entry
)
852 (eq (car entry
) 'defun
)
853 (string-match "^Preconfigured.+$"
854 (setq doc
(or (documentation (setq sym
(cdr entry
)))
856 collect
(cons sym
(match-string 0 doc
))))
858 (defun anything-c-format-preconfigured-anything ()
859 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x
) (cdr x
)))
860 (anything-c-list-preconfigured-anything)))
862 (setq anything-help-message
866 "`anything' is QuickSilver-like candidate-selection framework.
868 Narrow the list by typing some pattern,
869 Multiple patterns are allowed by splitting by space.
870 Select with natural Emacs operations, choose with RET.
872 If you have any problems, press C-c C-x C-b!!
873 Feel free to send bug reports. I'll fix them.
874 The steps are described in the beginning of anything.el file.
876 == Basic Operations ==
877 C-p, Up: Previous Line
878 C-n, Down : Next Line
879 M-v, PageUp : Previous Page
880 C-v, PageDown : Next Page
881 Enter : Execute first (default) action / Select
884 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
885 M-PageDown, C-M-v : Next Page (other-window)
887 Tab, C-i : Show action list
888 Left : Previous Source
889 Right, C-o : Next Source
891 C-z : Persistent Action (Execute action with anything session kept)
892 C-c C-x C-b: Send a bug report
894 == Shortcuts For 2nd/3rd Action ==
895 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
896 \\[anything-select-3rd-action] : Execute 3rd Action
899 Visible marks store candidate. Some actions uses marked candidates.
901 \\[anything-toggle-visible-mark] : Toggle Visible Mark
902 \\[anything-prev-visible-mark] : Previous Mark
903 \\[anything-next-visible-mark] : Next Mark
905 == Miscellaneous Commands ==
906 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
907 \\[anything-quit-and-find-file] : Drop into `find-file'
908 \\[anything-delete-current-selection] : Delete Selected Item (visually)
909 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
910 \\[anything-yank-selection] : Yank Selected Item Into Pattern
911 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
912 \\[anything-force-update] : Recalculate And Redisplay Candidates
914 == Global Commands ==
915 \\<global-map>\\[anything-resume] revives last `anything' session.
916 It is very useful, so you should bind any key.
918 Single source is executed by \\[anything-call-source].
920 == Preconfigured `anything' ==
921 Preconfigured `anything' is commands that uses `anything' interface.
922 You can use them without configuration.
925 (apply 'concat
(anything-c-format-preconfigured-anything))
929 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931 (defun anything-mini ()
932 "Preconfigured `anything' lightweight version (buffer -> recentf)."
934 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf
)
937 (defun anything-for-files ()
938 "Preconfigured `anything' for opening files.
939 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
941 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
944 (defun anything-recentf ()
945 "Preconfigured `anything' for `recentf'."
947 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
950 (defun anything-info-at-point ()
951 "Preconfigured `anything' for searching info at point."
953 (anything '(anything-c-source-info-elisp
954 anything-c-source-info-cl
955 anything-c-source-info-pages
)
956 (thing-at-point 'symbol
) nil nil nil
"*anything info*"))
959 (defun anything-info-emacs ()
960 "Preconfigured anything for Emacs manual index."
962 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
965 (defun anything-show-kill-ring ()
966 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
967 You may bind this command to M-y."
969 (anything-other-buffer 'anything-c-source-kill-ring
"*anything kill-ring*"))
972 (defun anything-minibuffer-history ()
973 "Preconfigured `anything' for `minibuffer-history'."
975 (let ((enable-recursive-minibuffers t
))
976 (anything-other-buffer 'anything-c-source-minibuffer-history
977 "*anything minibuffer-history*")))
980 (defun anything-gentoo ()
981 "Preconfigured `anything' for gentoo linux."
983 (anything-other-buffer '(anything-c-source-gentoo
984 anything-c-source-use-flags
)
985 "*anything gentoo*"))
988 (defun anything-imenu ()
989 "Preconfigured `anything' for `imenu'."
991 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
994 (defun anything-google-suggest ()
995 "Preconfigured `anything' for google search with google suggest."
997 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
1000 (defun anything-yahoo-suggest ()
1001 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1003 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
1005 ;;; Converted from anything-show-*-only
1007 (defun anything-for-buffers ()
1008 "Preconfigured `anything' for buffer."
1010 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
1013 (defun anything-buffers+ ()
1014 "Enhanced preconfigured `anything' for buffer."
1016 (anything-other-buffer 'anything-c-source-buffers
+ "*anything buffers*"))
1019 (defun anything-bbdb ()
1020 "Preconfigured `anything' for BBDB.
1024 http://bbdb.sourceforge.net/"
1026 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
1029 (defun anything-locate ()
1030 "Preconfigured `anything' for Locate.
1031 Note you can add locate command after entering pattern.
1032 See man locate for more infos."
1034 (anything-other-buffer 'anything-c-source-locate
"*anything locate*"))
1037 (defun anything-w3m-bookmarks ()
1038 "Preconfigured `anything' for w3m bookmark.
1040 Needs w3m and emacs-w3m.
1042 http://w3m.sourceforge.net/
1043 http://emacs-w3m.namazu.org/"
1045 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1046 "*anything w3m bookmarks*"))
1049 (defun anything-firefox-bookmarks ()
1050 "Preconfigured `anything' for firefox bookmark.
1051 You will have to enable html bookmarks in firefox:
1052 open about:config in firefox and double click on this line to enable value \
1055 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1057 You should have now:
1059 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1061 After closing firefox, you will be able to browse you bookmarks.
1064 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1065 "*Anything Firefox*"))
1068 (defun anything-colors ()
1069 "Preconfigured `anything' for color."
1071 (anything-other-buffer
1072 '(anything-c-source-colors anything-c-source-customize-face
)
1073 "*anything colors*"))
1076 (defun anything-bookmarks ()
1077 "Preconfigured `anything' for bookmarks."
1079 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
1082 (defun anything-c-pp-bookmarks ()
1083 "Preconfigured `anything' for bookmarks (pretty-printed)."
1085 (anything-other-buffer '(anything-c-source-bookmarks-local
1086 anything-c-source-bookmarks-su
1087 anything-c-source-bookmarks-ssh
)
1088 "*anything pp bookmarks*"))
1091 (defun anything-register ()
1092 "Preconfigured `anything' for Emacs registers."
1094 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
1097 (defun anything-man-woman ()
1098 "Preconfigured `anything' for Man and Woman pages."
1100 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
1103 (defun anything-org-keywords ()
1104 "Preconfigured `anything' for org keywords."
1106 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
1109 (defun anything-emms ()
1110 "Preconfigured `anything' for emms sources."
1112 (anything '(anything-c-source-emms-streams
1113 anything-c-source-emms-files
1114 anything-c-source-emms-dired
)
1119 (defun anything-eev-anchors ()
1120 "Preconfigured `anything' for eev anchors."
1122 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
1125 (defun anything-bm-list ()
1126 "Preconfigured `anything' for visible bookmarks.
1130 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1132 (let ((anything-outline-using t
))
1133 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
1136 (defun anything-timers ()
1137 "Preconfigured `anything' for timers."
1139 (anything-other-buffer '(anything-c-source-absolute-time-timers
1140 anything-c-source-idle-time-timers
)
1141 "*anything timers*"))
1144 (defun anything-list-emacs-process ()
1145 "Preconfigured `anything' for emacs process."
1147 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
1150 (defun anything-occur ()
1151 "Preconfigured Anything for Occur source."
1153 (let ((anything-compile-source-functions
1154 ;; rule out anything-match-plugin because the input is one regexp.
1155 (delq 'anything-compile-source--match-plugin
1156 (copy-sequence anything-compile-source-functions
))))
1157 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
1160 (defun anything-browse-code ()
1161 "Preconfigured anything to browse code."
1163 (anything-other-buffer 'anything-c-source-browse-code
"*Browse code*"))
1165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1168 (defun anything-kill-buffers ()
1169 "Preconfigured `anything' to kill buffer you selected."
1172 '(((name .
"Kill Buffers")
1173 (candidates . anything-c-buffer-list
)
1175 ("Kill Buffer" .
(lambda (candidate)
1176 (kill-buffer candidate
)
1177 (anything-kill-buffers)
1182 (defun anything-c-query-replace-regexp (candidate)
1183 (let ((regexp (funcall (anything-attr 'regexp
))))
1184 (apply 'query-replace-regexp
1185 (anything-c-query-replace-args regexp
))))
1187 (defun anything-c-kill-regexp-as-sexp (candidate)
1188 (anything-c-regexp-kill-new
1189 (prin1-to-string (funcall (anything-attr 'regexp
)))))
1191 (defun anything-c-kill-regexp (candidate)
1192 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
1194 (defun anything-c-query-replace-args (regexp)
1195 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1196 (let ((region-only (anything-region-active-p)))
1199 (query-replace-read-to regexp
1200 (format "Query replace %s regexp %s"
1201 (if anything-current-prefix-arg
"word " "")
1202 (if region-only
"in region " ""))
1204 anything-current-prefix-arg
1205 (when region-only
(region-beginning))
1206 (when region-only
(region-end)))))
1208 (defvar anything-c-source-regexp
1209 '((name .
"Regexp Builder")
1211 (anything-candidate-buffer anything-current-buffer
)))
1212 (candidates-in-buffer)
1213 (get-line . anything-c-regexp-get-line
)
1214 (persistent-action . anything-c-regexp-persistent-action
)
1215 (persistent-help .
"Show this line")
1218 (requires-pattern .
2)
1219 (mode-line .
"Press TAB to select action.")
1221 ;; I use here `anything-input' because `anything-pattern' is lost when
1222 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1223 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1224 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1226 (regexp .
(lambda () anything-input
))
1227 (action .
(("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
1228 ("Query Replace Regexp" . anything-c-query-replace-regexp
)
1229 ("Kill Regexp" . anything-c-kill-regexp
)))))
1231 (defun anything-c-regexp-get-line (s e
)
1235 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
1237 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
1238 collect
(format "\n %s'%s'"
1239 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
1242 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1243 ;; It is implementation problem of candidates-in-buffer.
1247 ;; Shut up byte compiler
1248 (defun anything-goto-line (numline)
1249 "Replacement of `goto-line'."
1250 (goto-char (point-min))
1251 (forward-line (1- numline
)))
1253 (defun anything-c-regexp-persistent-action (pt)
1255 (anything-persistent-highlight-point))
1257 (defun anything-c-regexp-kill-new (input)
1259 (message "Killed: %s" input
))
1261 (defun anything-region-active-p ()
1262 (and transient-mark-mode mark-active
(/= (mark) (point))))
1264 (defun* anything-current-buffer-narrowed-p
(&optional
1265 (buffer anything-current-buffer
))
1266 "Check if BUFFER is narrowed.
1267 Default is `anything-current-buffer'."
1268 (with-current-buffer buffer
1269 (let ((beg (point-min))
1271 (total (buffer-size)))
1272 (or (/= beg
1) (/= end
(1+ total
))))))
1275 (defun anything-regexp ()
1276 "Preconfigured anything to build regexps and run query-replace-regexp \
1280 (let ((anything-compile-source-functions
1281 ;; rule out anything-match-plugin because the input is one regexp.
1282 (delq 'anything-compile-source--match-plugin
1283 (copy-sequence anything-compile-source-functions
))))
1284 (when (and (anything-region-active-p)
1285 ;; Don't narrow to region if buffer is already narrowed.
1286 (not (anything-current-buffer-narrowed-p)))
1287 (narrow-to-region (region-beginning) (region-end)))
1289 anything-c-source-regexp
1290 :buffer
"*anything regexp*"
1291 :prompt
"Regexp: "))))
1294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1296 (defun anything-insert-buffer-name ()
1297 "Insert buffer name."
1299 (anything-insert-string
1300 (with-current-buffer anything-current-buffer
1301 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
1304 (defun anything-insert-symbol ()
1305 "Insert current symbol."
1307 (anything-insert-string
1308 (with-current-buffer anything-current-buffer
1310 (buffer-substring (beginning-of-thing 'symbol
)
1311 (end-of-thing 'symbol
))))))
1313 (defun anything-insert-selection ()
1314 "Insert current selection."
1316 (anything-insert-string
1317 (with-current-buffer anything-current-buffer
1318 (anything-get-selection))))
1320 (defun anything-show-buffer-only ()
1321 "[OBSOLETE] Only show sources about buffer.
1322 Use `anything-for-buffers' instead."
1324 (anything-set-source-filter '("Buffers")))
1326 (defun anything-show-bbdb-only ()
1327 "[OBSOLETE] Only show sources about BBDB.
1328 Use `anything-bbdb' instead."
1330 (anything-set-source-filter '("BBDB")))
1332 (defun anything-show-locate-only ()
1333 "[OBSOLETE] Only show sources about Locate.
1334 Use `anything-locate' instead."
1336 (anything-set-source-filter '("Locate")))
1338 (defun anything-show-info-only ()
1339 "[OBSOLETE] Only show sources about Info.
1340 Use `anything-info-at-point' instead."
1342 (anything-set-source-filter '("Info Pages"
1344 "Info Common-Lisp")))
1346 (defun anything-show-imenu-only ()
1347 "[OBSOLETE] Only show sources about Imenu.
1348 Use `anything-imenu' instead."
1350 (anything-set-source-filter '("Imenu")))
1352 (defun anything-show-files-only ()
1353 "[OBSOLETE] Only show sources about File.
1354 Use `anything-for-files' instead."
1356 (anything-set-source-filter '("File Name History"
1357 "Files from Current Directory"
1360 (defun anything-show-w3m-bookmarks-only ()
1361 "[OBSOLETE] Only show source about w3m bookmark.
1362 Use `anything-w3m-bookmarks' instead."
1364 (anything-set-source-filter '("W3m Bookmarks")))
1366 (defun anything-show-colors-only ()
1367 "[OBSOLETE] Only show source about color.
1368 Use `anything-colors' instead."
1370 (anything-set-source-filter '("Colors"
1371 "Customize Faces")))
1373 (defun anything-show-kill-ring-only ()
1374 "[OBSOLETE] Only show source about kill ring.
1375 Use `anything-show-kill-ring' instead."
1377 (anything-set-source-filter '("Kill Ring")))
1379 (defun anything-show-this-source-only ()
1380 "Only show this source."
1382 (setq anything-candidate-number-limit
9999)
1383 (anything-set-source-filter
1384 (list (assoc-default 'name
(anything-get-current-source)))))
1386 (defun anything-test-sources ()
1387 "List all anything sources for test.
1388 The output is sexps which are evaluated by \\[eval-last-sexp]."
1390 (with-output-to-temp-buffer "*Anything Test Sources*"
1391 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
1392 (apropos-internal "^anything-c-source" #'boundp
))
1393 (pop-to-buffer standard-output
)))
1395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1396 ;;; For compatibility
1397 (unless (fboundp 'region-active-p
)
1398 (defun region-active-p ()
1399 "Return t if Transient Mark mode is enabled and the mark is active.
1401 Most commands that act on the region if it is active and
1402 Transient Mark mode is enabled, and on the text near point
1403 otherwise, should use `use-region-p' instead. That function
1404 checks the value of `use-empty-active-region' as well."
1405 (and transient-mark-mode mark-active
)))
1407 (defun anything-nest (&rest same-as-anything
)
1408 "Nested `anything'. If you use `anything' within `anything', use it."
1409 (with-selected-window (anything-window)
1410 (let (anything-current-position
1411 anything-current-buffer
1412 (orig-anything-buffer anything-buffer
)
1416 anything-compiled-sources
1417 anything-buffer-chars-modified-tick
1418 (anything-samewindow t
)
1419 (enable-recursive-minibuffers t
))
1421 (apply #'anything same-as-anything
)
1422 (anything-initialize-overlays orig-anything-buffer
)
1423 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
1425 (defun anything-displaying-source-names ()
1426 "Display sources name."
1427 (with-current-buffer anything-buffer
1428 (goto-char (point-min))
1430 while
(setq pos
(next-single-property-change (point) 'anything-header
))
1432 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
1433 do
(forward-line 1))))
1435 (defun anything-select-source ()
1438 (let ((default (assoc-default 'name
(anything-get-current-source)))
1439 (source-names (anything-displaying-source-names))
1440 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
1441 (anything-get-sources))))
1442 (setq anything-candidate-number-limit
9999)
1444 (let (anything-source-filter)
1445 (anything-nest '(((name .
"Anything Source")
1446 (candidates . source-names
)
1447 (action . identity
))
1448 ((name .
"Anything Source (ALL)")
1449 (candidates . all-source-names
)
1450 (action . identity
)))
1452 default
"*anything select source*"))
1453 (anything-set-source-filter (list it
))
1454 (anything-set-source-filter nil
))))
1456 (defun anything-insert-string (str)
1458 (delete-minibuffer-contents)
1461 (defun anything-c-match-on-file-name (candidate)
1462 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1463 (string-match anything-pattern
(file-name-nondirectory candidate
)))
1465 (defun anything-c-match-on-directory-name (candidate)
1466 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1467 (anything-aif (file-name-directory candidate
)
1468 (string-match anything-pattern it
)))
1470 (defun anything-c-string-match (candidate)
1471 "Return non-nil if `anything-pattern' match CANDIDATE.
1472 The match is done with `string-match'."
1473 (string-match anything-pattern candidate
))
1475 ;; `anything-c-compose' is no more needed, it is for compatibility.
1476 (defalias 'anything-c-compose
'anything-compose
)
1478 (defun anything-c-skip-entries (list regexp
)
1479 "Remove entries which matches REGEXP from LIST."
1480 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
1483 (defun anything-c-shadow-entries (list regexp
)
1484 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1485 (mapcar (lambda (file)
1486 ;; Add shadow face property to boring files.
1487 (let ((face (if (facep 'file-name-shadow
)
1489 ;; fall back to default on XEmacs
1491 (if (string-match regexp file
)
1492 (setq file
(propertize file
'face face
))))
1496 (defsubst anything-c-stringify
(str-or-sym)
1497 "Get string of STR-OR-SYM."
1498 (if (stringp str-or-sym
)
1500 (symbol-name str-or-sym
)))
1502 (defsubst anything-c-symbolify
(str-or-sym)
1503 "Get symbol of STR-OR-SYM."
1504 (if (symbolp str-or-sym
)
1506 (intern str-or-sym
)))
1508 (defun anything-c-describe-function (func)
1509 "FUNC is symbol or string."
1510 (describe-function (anything-c-symbolify func
)))
1512 (defun anything-c-describe-variable (var)
1513 "VAR is symbol or string."
1514 (describe-variable (anything-c-symbolify var
)))
1516 (defun anything-c-find-function (func)
1517 "FUNC is symbol or string."
1518 (find-function (anything-c-symbolify func
)))
1520 (defun anything-c-find-variable (var)
1521 "VAR is symbol or string."
1522 (find-variable (anything-c-symbolify var
)))
1524 (defun anything-c-kill-new (string &optional replace yank-handler
)
1525 "STRING is symbol or string."
1526 (kill-new (anything-c-stringify string
) replace yank-handler
))
1528 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1530 (defvar anything-current-prefix-arg nil
1531 "`current-prefix-arg' when selecting action.
1532 It is cleared after executing action.")
1534 (defadvice anything-exit-minibuffer
(before anything-current-prefix-arg activate
)
1535 (unless anything-current-prefix-arg
1536 (setq anything-current-prefix-arg current-prefix-arg
)))
1538 (add-hook 'anything-after-action-hook
1539 (lambda () (setq anything-current-prefix-arg nil
)))
1542 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1543 (defadvice eval-defun
(after anything-source-hack activate
)
1544 "See `anything-c-enable-eval-defun-hack'."
1545 (when anything-c-enable-eval-defun-hack
1546 (let ((varsym (save-excursion
1547 (beginning-of-defun)
1549 (when (memq (read (current-buffer)) '(defvar setq
))
1550 (read (current-buffer))))))
1551 (when (string-match "^anything-c-source-" (symbol-name varsym
))
1552 (anything varsym
)))))
1553 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1555 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1556 (defconst anything-c-create-summary-index-regexp
1557 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1558 (defun anything-c-create-summary ()
1559 "Create `anything' summary."
1561 (goto-char (point-min))
1563 while
(re-search-forward anything-c-create-summary-index-regexp nil t
)
1565 (cond ((setq it
(match-string-no-properties 1))
1567 ((setq it
(match-string-no-properties 2))
1569 ,(assoc-default 'name
(symbol-value (intern it
)))))
1570 ((setq it
(match-string-no-properties 3))
1572 ,(assoc-default 'name
(symbol-value (intern it
)))))))))
1574 ;; (find-epp (anything-c-create-summary))
1576 (defun anything-c-insert-summary ()
1577 "Insert `anything' summary."
1579 (goto-char (point-min))
1580 (search-forward ";; Below are complete source list you can setup in")
1582 (delete-region (point)
1583 (progn (search-forward ";;; Change log:" nil t
)
1584 (forward-line -
1) (point)))
1587 for
(kind . value
) in
(anything-c-create-summary)
1589 do
(cond ((eq kind
'section
)
1591 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
1592 (insert ";; " value
":\n")
1595 (insert ";; `" (car value
) "' (" (cdr value
) ")\n")))
1596 finally
(align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))))
1597 ;; (anything-c-insert-summary)
1599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1601 (defun anything-c-buffer-list ()
1602 "Return the list of names of buffers with boring buffers filtered out.
1603 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1604 The first buffer in the list will be the last recently used
1605 buffer that is not the current buffer."
1606 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
1607 (append (cdr buffers
) (list (car buffers
)))))
1609 (defvar anything-c-source-buffers
1610 '((name .
"Buffers")
1611 (candidates . anything-c-buffer-list
)
1613 ;; (anything 'anything-c-source-buffers)
1615 (defvar anything-c-source-buffer-not-found
1616 '((name .
"Create buffer")
1619 ;; (anything 'anything-c-source-buffer-not-found)
1622 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
1623 "*Face used for directory headings in dired buffers."
1626 (defface anything-file-name
1627 '((t (:foreground
"Blue")))
1628 "*Face used for file names (without suffixes) in dired buffers."
1631 (defface anything-dir-priv
1632 '((t (:foreground
"DarkRed" :background
"LightGray")))
1633 "*Face used for directory privilege indicator (d) in dired buffers."
1636 (defvar anything-c-buffers-face1
'anything-dir-priv
)
1637 (defvar anything-c-buffers-face2
'font-lock-type-face
)
1638 (defvar anything-c-buffers-face3
'italic
)
1639 (eval-when-compile (require 'dired
))
1640 (defun anything-c-highlight-buffers (buffers)
1642 (loop for i in buffers
1643 if
(rassoc (get-buffer i
) dired-buffers
)
1644 collect
(propertize i
1645 'face anything-c-buffers-face1
1646 'help-echo
(car (rassoc (get-buffer i
) dired-buffers
)))
1647 if
(buffer-file-name (get-buffer i
))
1648 collect
(propertize i
1649 'face anything-c-buffers-face2
1650 'help-echo
(buffer-file-name (get-buffer i
)))
1651 if
(and (not (rassoc (get-buffer i
) dired-buffers
))
1652 (not (buffer-file-name (get-buffer i
))))
1653 collect
(propertize i
1654 'face anything-c-buffers-face3
)))
1656 (defvar anything-c-source-buffers
+
1657 '((name .
"Buffers")
1658 (candidates . anything-c-buffer-list
)
1660 (candidate-transformer anything-c-skip-current-buffer
1661 anything-c-highlight-buffers
1662 anything-c-skip-boring-buffers
)
1663 (persistent-action . anything-c-buffers
+-persistent-action
)
1664 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1666 (defun anything-c-buffers+-persistent-action
(name)
1668 (with-current-buffer item
1669 (if (and (buffer-modified-p)
1670 (buffer-file-name (current-buffer)))
1674 (kill-buffer item
))))
1676 (switch-to-buffer item
)))
1677 (if current-prefix-arg
1680 (anything-delete-current-selection))
1683 ;; (anything 'anything-c-source-buffers+)
1687 ;;; File name history
1688 (defvar anything-c-source-file-name-history
1689 '((name .
"File Name History")
1690 (candidates . file-name-history
)
1691 (match anything-c-match-on-file-name
1692 anything-c-match-on-directory-name
)
1694 ;; (anything 'anything-c-source-file-name-history)
1696 ;;; Files in current dir
1697 (defvar anything-c-source-files-in-current-dir
1698 '((name .
"Files from Current Directory")
1699 (candidates .
(lambda ()
1700 (with-current-buffer anything-current-buffer
1701 (directory-files (anything-c-current-directory)))))
1702 ;; volatile is not needed, I think.
1704 ;; (anything 'anything-c-source-files-in-current-dir)
1706 (defvar anything-c-files-face1
'anything-dir-priv
)
1707 (defvar anything-c-files-face2
'anything-file-name
)
1708 (defun anything-c-highlight-files (files)
1709 (loop for i in files
1710 if
(file-directory-p i
)
1711 collect
(propertize (file-name-nondirectory i
)
1712 'face anything-c-files-face1
1713 'help-echo
(expand-file-name i
))
1715 collect
(propertize (file-name-nondirectory i
)
1716 'face anything-c-files-face2
1717 'help-echo
(expand-file-name i
))))
1720 (defvar anything-c-source-files-in-current-dir
+
1721 '((name .
"Files from Current Directory")
1722 (candidates .
(lambda ()
1723 (with-current-buffer anything-current-buffer
1724 (directory-files (anything-c-current-directory) t
))))
1725 (candidate-transformer anything-c-highlight-files
)
1726 ;; volatile is not needed, I think.
1729 ;; (anything 'anything-c-source-files-in-current-dir+)
1731 ;;; Anything replacement of file name completion for `find-file' and friends.
1733 (defvar anything-c-find-files-doc-header
(format " (`%s':Go to precedent level)"
1734 (if window-system
"C-." "C-l"))
1735 "*The doc that is inserted in the Name header of a find-files or dired source.")
1737 (defvar anything-c-source-find-files
1738 `((name .
,(concat "Find Files" anything-c-find-files-doc-header
))
1739 ;; It is needed for filenames with capital letters
1742 (setq ffap-newfile-prompt t
)))
1743 (candidates . anything-find-files-get-candidates
)
1744 (filtered-candidate-transformer anything-c-find-files-transformer
)
1745 (persistent-action . anything-find-files-persistent-action
)
1746 (persistent-help .
"Expand Candidate")
1751 `(("Find File" . anything-c-find-file-or-marked
)
1752 ("Find file in Dired" . anything-c-point-file-in-dired
)
1753 ,(and (locate-library "elscreen")
1754 '("Find file in Elscreen" . anything-elscreen-find-file
))
1755 ("Complete at point"
1756 . anything-c-insert-file-name-completion-at-point
)
1757 ("Delete File(s)" . anything-delete-marked-files
)
1758 ("Find file as root" . anything-find-file-as-root
)
1759 ("Open file externally (C-u to choose)"
1760 . anything-c-open-file-externally
)
1761 ;; ("Create dired buffer on marked"
1762 ;; . anything-c-create-dired-on-marked)
1763 ("Find file other window" . find-file-other-window
)
1764 ("Find file other frame" . find-file-other-frame
))))))
1766 ;; (anything 'anything-c-source-find-files)
1768 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
1769 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1770 If LEVEL is positive reduce from end else from beginning.
1771 If UNIX-CLOSE is non--nil close filename with /.
1772 If EXPAND is non--nil expand-file-name."
1773 (let* ((exp-fname (expand-file-name fname
))
1774 (fname-list (split-string (if (or (string= fname
"~/") expand
)
1775 exp-fname fname
) "/" t
))
1776 (len (length fname-list
))
1777 (pop-list (if (< level
0)
1778 (subseq fname-list
(* level -
1))
1779 (subseq fname-list
0 (- len level
))))
1780 (result (mapconcat 'identity pop-list
"/"))
1781 (empty (string= result
"")))
1782 (when unix-close
(setq result
(concat result
"/")))
1783 (if (string-match "^~" result
)
1784 (if (string= result
"~/") "~/" result
)
1786 (if empty
"../" (concat "../" result
))
1787 (cond ((eq system-type
'windows-nt
)
1788 (if empty
"c:/" result
))
1791 (concat "/" result
)))))))
1793 (defun anything-file-completion-source-p ()
1794 "Test if current source is a dired or find-files source."
1795 (let ((ff-sources '("Find Files" "Copy Files"
1796 "Rename Files" "Symlink Files"
1797 "Hardlink Files" "Write File"
1798 "Insert File" "Read file name"))
1799 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
1801 (dolist (i ff-sources
)
1802 (when (equal cur-source
(concat i anything-c-find-files-doc-header
))
1803 (throw 'break t
))))))
1805 (defun anything-find-files-down-one-level (arg)
1806 "Go down one level like unix command `cd ..'.
1807 If prefix numeric arg is given go ARG level down."
1809 (when (anything-file-completion-source-p)
1810 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
1811 :unix-close t
:expand t
)))
1812 (with-selected-window (minibuffer-window)
1813 (delete-minibuffer-contents)
1814 (insert new-pattern
)))))
1816 ;; `C-.' doesn't work in terms use `C-l' instead.
1818 (define-key anything-map
(kbd "C-.") 'anything-find-files-down-one-level
)
1819 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))
1821 (defun anything-c-point-file-in-dired (file)
1822 "Put point on filename FILE in dired buffer."
1823 (dired (file-name-directory file
))
1824 (dired-goto-file file
))
1826 (defun anything-create-tramp-name (fname)
1827 "Build filename for `anything-pattern' like /su:: or /sudo::."
1828 (apply #'tramp-make-tramp-file-name
1830 with v
= (tramp-dissect-file-name fname
)
1831 for i across v collect i
)))
1833 (defun anything-find-files-get-candidates ()
1834 "Create candidate list for `anything-c-source-find-files'."
1835 (let* ( ; Don't try to tramp connect before entering the second ":".
1836 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1837 (path (cond ((string-match "^~" anything-pattern
)
1838 (replace-match (getenv "HOME") nil t anything-pattern
))
1839 ((string-match tramp-file-name-regexp anything-pattern
)
1840 (let ((tramp-name (anything-create-tramp-name
1841 (match-string 0 anything-pattern
))))
1842 (replace-match tramp-name nil t anything-pattern
)))
1843 (t anything-pattern
)))
1844 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
1845 ;; Inlined version (<2010-02-18 Jeu.>.) of `tramp-handle-directory-files'
1846 ;; to fix bug in tramp that doesn't show the dot file names(i.e "." "..")
1848 (flet ((tramp-handle-directory-files
1849 (directory &optional full match nosort files-only
)
1850 "Like `directory-files' for Tramp files."
1851 ;; FILES-ONLY is valid for XEmacs only.
1852 (when (file-directory-p directory
)
1853 (setq directory
(file-name-as-directory (expand-file-name directory
)))
1854 (let ((temp (nreverse (file-name-all-completions "" directory
)))
1858 (setq item
(directory-file-name (pop temp
)))
1859 (when (and (or (null match
) (string-match match item
))
1860 (or (null files-only
)
1862 (and (equal files-only t
) (file-regular-p item
))
1863 ;; Directories only.
1864 (file-directory-p item
)))
1865 (push (if full
(concat directory item
) item
)
1867 (if nosort result
(sort result
'string
<))))))
1869 (set-text-properties 0 (length path
) nil path
)
1870 (setq anything-pattern
(replace-regexp-in-string " " ".*" path
))
1871 (cond ((or (file-regular-p path
)
1872 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
1874 ((string= anything-pattern
"") (directory-files "/" t
))
1875 ((file-directory-p path
) (directory-files path t
))
1879 (directory-files (file-name-directory path
) t
)))))))
1881 (defface anything-dired-symlink-face
1882 '((t (:foreground
"DarkOrange")))
1883 "*Face used for symlinks in `anything-find-files'."
1886 (defface anything-ffiles-prefix-face
1887 '((t (:background
"yellow" :foreground
"black")))
1888 "*Face used to prefix new file or url paths in `anything-find-files'."
1891 (defun anything-c-prefix-filename (fname &optional image
)
1892 "Return fname FNAME prefixed with icon IMAGE."
1893 (let* ((img-name (and image
(expand-file-name
1894 image anything-c-find-files-icons-directory
)))
1895 (img (and image
(create-image img-name
)))
1896 (prefix-img (and image
(propertize " " 'display img
)))
1897 (prefix-new (propertize
1899 (propertize "[?]" 'face
'anything-ffiles-prefix-face
)))
1900 (prefix-url (propertize
1902 (propertize "[@]" 'face
'anything-ffiles-prefix-face
))))
1903 (cond ((or (file-exists-p fname
)
1904 (file-symlink-p fname
))
1905 (if image
(concat prefix-img fname
) fname
))
1906 ((string-match ffap-url-regexp fname
) (concat prefix-url
" " fname
))
1907 (t (concat prefix-new
" " fname
)))))
1909 (defun anything-c-find-files-transformer (files sources
)
1910 (if (and (window-system) anything-c-find-files-show-icons
)
1911 (anything-c-highlight-ffiles1 files sources
)
1912 (anything-c-highlight-ffiles files sources
)))
1914 (defun anything-c-highlight-ffiles (files sources
)
1915 "Candidate transformer for `anything-c-source-find-files' without icons."
1916 (loop for i in files
1917 collect
(cond ((file-symlink-p i
)
1919 (anything-c-prefix-filename
1920 (propertize i
'face
'anything-dired-symlink-face
1921 'help-echo
(file-truename i
)))
1923 ((file-directory-p i
)
1925 (anything-c-prefix-filename
1926 (propertize i
'face anything-c-files-face1
))
1930 (anything-c-prefix-filename
1931 (propertize i
'face anything-c-files-face2
))
1934 (defsubst anything-c-highlight-ffiles1
(files sources
)
1935 "Candidate transformer for `anything-c-source-find-files' that show icons."
1936 (loop for i in files
1937 for af
= (file-name-nondirectory i
)
1938 collect
(cond ( ;; Files.
1939 (eq nil
(car (file-attributes i
)))
1940 (cons (anything-c-prefix-filename
1941 (propertize i
'face anything-c-files-face2
)
1944 ( ;; Empty directories.
1945 (and (eq t
(car (file-attributes i
)))
1946 ;; Be sure to have permission to list content.
1950 i nil directory-files-no-dot-files-regexp t
))))
1951 (cons (anything-c-prefix-filename
1952 (propertize i
'face anything-c-files-face1
)
1955 ( ;; Open directories.
1956 (and (eq t
(car (file-attributes i
))) (get-buffer af
))
1957 (cons (anything-c-prefix-filename
1958 (propertize i
'face anything-c-files-face1
)
1961 (;; Closed directories.
1962 (eq t
(car (file-attributes i
)))
1963 (cons (anything-c-prefix-filename
1964 (propertize i
'face anything-c-files-face1
)
1967 ( ;; Open Symlinks directories.
1968 (and (stringp (car (file-attributes i
)))
1969 (file-directory-p i
) (get-buffer af
))
1970 (cons (anything-c-prefix-filename
1971 (propertize i
'face
'anything-dired-symlink-face
1972 'help-echo
(file-truename i
)) "open.xpm")
1974 ( ;; Closed Symlinks directories.
1975 (and (stringp (car (file-attributes i
))) (file-directory-p i
))
1976 (cons (anything-c-prefix-filename
1977 (propertize i
'face
'anything-dired-symlink-face
1978 'help-echo
(file-truename i
)) "close.xpm")
1980 ( ;; Files symlinks.
1981 (stringp (car (file-attributes i
)))
1982 (cons (anything-c-prefix-filename
1983 (propertize i
'face
'anything-dired-symlink-face
1984 'help-echo
(file-truename i
))
1989 (defun anything-find-files-persistent-action (candidate)
1990 "Open subtree CANDIDATE without quitting anything.
1991 If CANDIDATE is not a directory expand CANDIDATE filename.
1992 If CANDIDATE is alone, open file CANDIDATE filename."
1993 (flet ((insert-in-minibuffer (elm)
1994 (with-selected-window (minibuffer-window)
1995 (delete-minibuffer-contents)
1996 (set-text-properties 0 (length elm
) nil elm
)
1998 (cond ((and (file-directory-p candidate
) (file-symlink-p candidate
))
1999 (insert-in-minibuffer (file-name-as-directory
2001 (expand-file-name candidate
)))))
2002 ((file-directory-p candidate
)
2003 (insert-in-minibuffer (file-name-as-directory
2004 (expand-file-name candidate
))))
2005 ((file-symlink-p candidate
)
2006 (insert-in-minibuffer (file-truename candidate
)))
2007 (t ; First hit on C-z expand CANDIDATE second hit open file.
2008 (let ((new-pattern (anything-get-selection anything-last-buffer
))
2009 (num-lines-buf (with-current-buffer anything-last-buffer
2010 (count-lines (point-min) (point-max)))))
2011 (if (> num-lines-buf
3)
2012 (insert-in-minibuffer new-pattern
) (find-file candidate
)))))))
2014 (defun anything-c-insert-file-name-completion-at-point (candidate)
2015 "Insert file name completion at point."
2016 (if buffer-read-only
2017 (error "Error: Buffer `%s' is read-only" (buffer-name))
2018 (let* ((end (point))
2019 (guess (thing-at-point 'filename
))
2020 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess
)
2021 (string-match "^[^\~]" guess
))))
2022 (set-text-properties 0 (length candidate
) nil candidate
)
2023 (if (and guess
(not (string= guess
"")) (string-match "^~\\|/.*" guess
))
2025 (search-backward guess
(- (point) (length guess
)))
2026 (delete-region (point) end
)
2028 (insert (expand-file-name candidate
))
2029 (insert (abbreviate-file-name candidate
))))
2030 (error "Aborting completion: No valid file name at point")))))
2033 (defun anything-find-files ()
2034 "Preconfigured `anything' for anything implementation of `find-file'."
2036 (let ((anything-mp-highlight-delay nil
))
2037 (anything :sources
'anything-c-source-find-files
2038 :input
(anything-find-files-input (ffap-guesser)
2039 (thing-at-point 'filename
))
2040 :prompt
"Find Files or Url: "
2041 :buffer
"*Anything Find Files*")))
2043 (defun anything-c-current-directory ()
2044 "Return current-directory name at point.
2045 Useful in dired buffers when there is inserted subdirs."
2046 (if (eq major-mode
'dired-mode
)
2047 (dired-current-directory)
2050 (defun anything-find-files-input (fap tap
)
2051 "Default input of `anything-find-files'."
2052 (let* ((def-dir (anything-c-current-directory))
2053 (lib (anything-find-library-at-point))
2054 (file-p (and fap
(file-exists-p fap
)
2056 (file-name-directory (expand-file-name tap def-dir
)))))
2058 (file-p (expand-file-name tap def-dir
))
2060 (or input
(expand-file-name def-dir
))))
2062 (defun anything-find-library-at-point ()
2063 "Try to find library path at point.
2064 Find inside `require' and `declare-function' sexp."
2065 (require 'find-func
)
2066 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
2067 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
2068 (sexp (and beg-sexp end-sexp
2069 (buffer-substring-no-properties
2070 (1+ beg-sexp
) (1- end-sexp
)))))
2072 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
2074 (replace-regexp-in-string
2076 ;; If require use third arg, ignore it,
2077 ;; always use library path found in `load-path'.
2078 (second (split-string (match-string 0 sexp
))))))
2079 ((and sexp
(string-match-p "^declare-function" sexp
))
2081 (replace-regexp-in-string
2083 (third (split-string sexp
)))))
2086 ;;; Anything completion for `write-file'.==> C-x C-w
2087 (defvar anything-c-source-write-file
2088 `((name .
,(concat "Write File" anything-c-find-files-doc-header
))
2089 ;; It is needed for filenames with capital letters
2091 (candidates . anything-find-files-get-candidates
)
2092 (filtered-candidate-transformer anything-c-find-files-transformer
)
2093 (persistent-action . anything-find-files-persistent-action
)
2094 (persistent-help .
"Expand Candidate")
2097 (("Write File" .
(lambda (candidate)
2098 (write-file candidate
'confirm
)))))))
2101 (defun anything-write-file ()
2102 "Preconfigured `anything' providing completion for `write-file'."
2104 (anything 'anything-c-source-write-file
2105 (expand-file-name default-directory
)
2106 "Write buffer to file: " nil nil
"*Anything write file*"))
2108 ;;; Anything completion for `insert-file'.==> C-x i
2109 (defvar anything-c-source-insert-file
2110 `((name .
,(concat "Insert File" anything-c-find-files-doc-header
))
2111 ;; It is needed for filenames with capital letters
2113 (candidates . anything-find-files-get-candidates
)
2114 (filtered-candidate-transformer anything-c-find-files-transformer
)
2115 (persistent-action . anything-find-files-persistent-action
)
2116 (persistent-help .
"Expand Candidate")
2119 (("Insert File" .
(lambda (candidate)
2120 (when (y-or-n-p (format "Really insert %s in %s "
2121 candidate anything-current-buffer
))
2122 (insert-file-contents candidate
))))))))
2125 (defun anything-insert-file ()
2126 "Preconfigured `anything' providing completion for `insert-file'."
2128 (anything 'anything-c-source-insert-file
2129 (expand-file-name default-directory
)
2130 "Insert file: " nil nil
"*Anything insert file*"))
2132 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2133 (defvar anything-c-source-copy-files
2134 `((name .
,(concat "Copy Files" anything-c-find-files-doc-header
))
2135 ;; It is needed for filenames with capital letters
2137 (candidates . anything-find-files-get-candidates
)
2138 (filtered-candidate-transformer anything-c-find-files-transformer
)
2139 (persistent-action . anything-find-files-persistent-action
)
2140 (persistent-help .
"Expand Candidate")
2144 .
(lambda (candidate)
2145 (anything-dired-action candidate
:action
'copy
)))
2147 .
(lambda (candidate)
2148 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
2151 (defvar anything-c-source-rename-files
2152 `((name .
,(concat "Rename Files" anything-c-find-files-doc-header
))
2153 ;; It is needed for filenames with capital letters
2155 (candidates . anything-find-files-get-candidates
)
2156 (filtered-candidate-transformer anything-c-find-files-transformer
)
2157 (persistent-action . anything-find-files-persistent-action
)
2158 (persistent-help .
"Expand Candidate")
2162 .
(lambda (candidate)
2163 (anything-dired-action candidate
:action
'rename
)))
2164 ("Rename and Follow"
2165 .
(lambda (candidate)
2166 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
2168 (defvar anything-c-source-symlink-files
2169 `((name .
,(concat "Symlink Files" anything-c-find-files-doc-header
))
2170 ;; It is needed for filenames with capital letters
2172 (candidates . anything-find-files-get-candidates
)
2173 (filtered-candidate-transformer anything-c-find-files-transformer
)
2174 (persistent-action . anything-find-files-persistent-action
)
2175 (persistent-help .
"Expand Candidate")
2179 .
(lambda (candidate)
2180 (anything-dired-action candidate
:action
'symlink
)))
2182 .
(lambda (candidate)
2183 (anything-dired-action candidate
:action
'relsymlink
)))))))
2186 (defvar anything-c-source-hardlink-files
2187 `((name .
,(concat "Hardlink Files" anything-c-find-files-doc-header
))
2188 ;; It is needed for filenames with capital letters
2190 (candidates . anything-find-files-get-candidates
)
2191 (filtered-candidate-transformer anything-c-find-files-transformer
)
2192 (persistent-action . anything-find-files-persistent-action
)
2193 (persistent-help .
"Expand Candidate")
2197 .
(lambda (candidate)
2198 (anything-dired-action candidate
:action
'hardlink
)))))))
2200 (defun* anything-dired-action
(candidate &key action follow
)
2201 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2202 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2203 (let ((files (dired-get-marked-files))
2205 ('copy
'dired-copy-file
)
2206 ('rename
'dired-rename-file
)
2207 ('symlink
'make-symbolic-link
)
2208 ('relsymlink
'dired-make-relative-symlink
)
2209 ('hardlink
'dired-hardlink
)))
2210 (marker (case action
2211 ((copy rename
) dired-keep-marker-copy
)
2212 ('symlink dired-keep-marker-symlink
)
2213 ('relsymlink dired-keep-marker-relsymlink
)
2214 ('hardlink dired-keep-marker-hardlink
))))
2216 fn
(symbol-name action
) files
2217 (if (file-directory-p candidate
)
2218 ;; When CANDIDATE is a directory, build file-name in this directory.
2219 ;; Else we use CANDIDATE.
2221 (expand-file-name (file-name-nondirectory from
) candidate
))
2222 #'(lambda (from) candidate
))
2225 (let* ((src (car files
))
2226 (dest (expand-file-name candidate
))
2227 (basename-src (if (file-directory-p src
)
2229 (directory-file-name src
)
2230 (file-name-directory src
))
2231 (file-name-nondirectory src
)))
2232 (fname (if (file-directory-p dest
)
2233 (concat (file-name-as-directory dest
)
2236 (anything-c-point-file-in-dired fname
)))))
2239 (defun* anything-dired-do-action-on-file
(&key action
)
2240 (let* ((files (dired-get-marked-files))
2241 (len (length files
))
2242 (fname (if (> len
1)
2243 (format "* %d Files" len
)
2245 (source (case action
2246 ('copy
'anything-c-source-copy-files
)
2247 ('rename
'anything-c-source-rename-files
)
2248 ('symlink
'anything-c-source-symlink-files
)
2249 ('hardlink
'anything-c-source-hardlink-files
)))
2250 (prompt-fm (case action
2251 ('copy
"Copy %s to: ")
2252 ('rename
"Rename %s to: ")
2253 ('symlink
"Symlink %s to: ")
2254 ('hardlink
"Hardlink %s to: ")))
2255 (buffer (case action
2256 ('copy
"*Anything Copy Files*")
2257 ('rename
"*Anything Rename Files*")
2258 ('symlink
"*Anything Symlink Files*")
2259 ('hardlink
"*Anything Hardlink Files*"))))
2261 (or (dired-dwim-target-directory)
2262 (expand-file-name (anything-c-current-directory)))
2263 (format prompt-fm fname
) nil nil buffer
)))
2267 (defun anything-dired-rename-file ()
2268 "Preconfigured `anything' to rename files from dired."
2270 (anything-dired-do-action-on-file :action
'rename
))
2273 (defun anything-dired-copy-file ()
2274 "Preconfigured `anything' to copy files from dired."
2276 (anything-dired-do-action-on-file :action
'copy
))
2279 (defun anything-dired-symlink-file ()
2280 "Preconfigured `anything' to symlink files from dired."
2282 (anything-dired-do-action-on-file :action
'symlink
))
2285 (defun anything-dired-hardlink-file ()
2286 "Preconfigured `anything' to hardlink files from dired."
2288 (anything-dired-do-action-on-file :action
'hardlink
))
2290 (defvar anything-dired-bindings nil
)
2292 (defun anything-dired-bindings (&optional arg
)
2293 "Replace usual dired commands `C' and `R' by anything ones.
2294 When call interactively toggle dired bindings and anything bindings.
2295 When call non--interactively with arg > 0, enable anything bindings.
2296 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2298 (if (or (when arg
(> arg
0)) (not anything-dired-bindings
))
2300 (define-key dired-mode-map
(kbd "C") 'anything-dired-copy-file
)
2301 (define-key dired-mode-map
(kbd "R") 'anything-dired-rename-file
)
2302 (define-key dired-mode-map
(kbd "S") 'anything-dired-symlink-file
)
2303 (define-key dired-mode-map
(kbd "H") 'anything-dired-hardlink-file
)
2304 (setq anything-dired-bindings t
))
2305 (define-key dired-mode-map
(kbd "C") 'dired-do-copy
)
2306 (define-key dired-mode-map
(kbd "R") 'dired-do-rename
)
2307 (define-key dired-mode-map
(kbd "S") 'dired-do-symlink
)
2308 (define-key dired-mode-map
(kbd "H") 'dired-do-hardlink
)
2309 (setq anything-dired-bindings nil
)))
2311 (defun* anything-c-read-file-name
(prompt &key
2312 (initial-input (expand-file-name default-directory
))
2313 (buffer "*Anything Completions*")
2315 "Anything `read-file-name' emulation.
2316 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2317 (when (get-buffer anything-action-buffer
)
2318 (kill-buffer anything-action-buffer
))
2321 `((name .
,(concat "Read file name" anything-c-find-files-doc-header
))
2322 ;; It is needed for filenames with capital letters
2324 (candidates .
(lambda ()
2326 (loop with seq
= (anything-find-files-get-candidates)
2327 for fname in seq when
(funcall test fname
)
2329 (anything-find-files-get-candidates))))
2330 (filtered-candidate-transformer anything-c-highlight-ffiles
)
2331 (persistent-action . anything-find-files-persistent-action
)
2332 (persistent-help .
"Expand Candidate")
2334 (action .
(("candidate" .
,'identity
))))
2335 :input initial-input
2342 (defvar anything-c-source-file-cache-initialized nil
)
2344 (defvar anything-c-file-cache-files nil
)
2346 (defvar anything-c-source-file-cache
2347 '((name .
"File Cache")
2350 (require 'filecache nil t
)
2351 (unless anything-c-source-file-cache-initialized
2352 (setq anything-c-file-cache-files
2353 (loop for item in file-cache-alist append
2354 (destructuring-bind (base &rest dirs
) item
2355 (loop for dir in dirs collect
2356 (concat dir base
)))))
2357 (defadvice file-cache-add-file
(after file-cache-list activate
)
2358 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
2359 (setq anything-c-source-file-cache-initialized t
))))
2360 (candidates . anything-c-file-cache-files
)
2361 (match anything-c-match-on-file-name
2362 anything-c-match-on-directory-name
)
2364 ;; (anything 'anything-c-source-file-cache)
2367 ;; NOTE for WINDOZE users:
2368 ;; You have to install Everything with his command line interface here:
2369 ;; http://www.voidtools.com/download.php
2371 (defvar anything-c-locate-command
2373 ('gnu
/linux
"locate -i -r %s")
2374 ('berkeley-unix
"locate -i %s")
2375 ('windows-nt
"es -i -r %s")
2377 "A list of arguments for locate program.
2378 The \"-r\" option must be the last option.")
2380 (defun anything-c-locate-init ()
2381 "Initialize async locate process for `anything-c-source-locate'."
2382 (start-process-shell-command "locate-process" nil
2383 (format anything-c-locate-command
2386 (defvar anything-c-source-locate
2388 (candidates . anything-c-locate-init
)
2390 (requires-pattern .
3)
2392 "Find files matching the current input pattern with locate.")
2394 ;; (anything 'anything-c-source-locate)
2397 (defvar anything-c-source-recentf
2398 '((name .
"Recentf")
2401 (or recentf-mode
(recentf-mode 1))
2402 ;; Big value empowers anything/recentf
2403 (when (and (numberp recentf-max-saved-items
)
2404 (<= recentf-max-saved-items
20))
2405 (setq recentf-max-saved-items
500))))
2406 (candidates . recentf-list
)
2407 (match anything-c-match-on-file-name
2408 anything-c-match-on-directory-name
)
2410 "See (info \"(emacs)File Conveniences\").
2411 if `recentf-max-saved-items' is too small, set it to 500.")
2412 ;; (anything 'anything-c-source-recentf)
2415 (eval-when-compile (require 'ffap
))
2416 (defvar anything-c-source-ffap-guesser
2417 '((name .
"File at point")
2418 (init .
(lambda () (require 'ffap
)))
2419 (candidates .
(lambda ()
2421 (with-current-buffer anything-current-buffer
2425 ;; (anything 'anything-c-source-ffap-guesser)
2427 ;;; ffap with line number
2428 (defun anything-c-ffap-file-line-at-point ()
2429 "Get (FILENAME . LINENO) at point."
2430 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2433 (when (and (search-forward it nil t
)
2434 (looking-at ":\\([0-9]+\\)"))
2435 (cons it
(string-to-number (match-string 1)))))))
2437 (defvar anything-c-ffap-line-location nil
2438 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2439 It is cleared after jumping line.")
2441 (defun anything-c-ffap-line-candidates ()
2442 (with-current-buffer anything-current-buffer
2443 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
2444 (when anything-c-ffap-line-location
2445 (destructuring-bind (file . line
) anything-c-ffap-line-location
2446 (list (cons (format "%s (line %d)" file line
) file
)))))
2448 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2449 (defun anything-c-ffap-line-goto-line ()
2450 (when (car anything-c-ffap-line-location
)
2453 (with-selected-window
2455 (get-file-buffer (car anything-c-ffap-line-location
)))
2456 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
2457 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
2458 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
2460 (defvar anything-c-source-ffap-line
2461 '((name .
"File/Lineno at point")
2462 (init .
(lambda () (require 'ffap
)))
2463 (candidates . anything-c-ffap-line-candidates
)
2465 ;; (anything 'anything-c-source-ffap-line)
2467 ;;; list of files gleaned from every dired buffer
2468 (defun anything-c-files-in-all-dired-candidates ()
2472 (cond ((listp dir
) ;filelist
2474 ((equal "" (file-name-nondirectory dir
)) ;dir
2475 (directory-files dir t
))
2477 (file-expand-wildcards dir t
))))
2479 (mapcar (lambda (buf)
2481 (when (eq major-mode
'dired-mode
)
2482 (if (consp dired-directory
)
2483 (cdr dired-directory
) ;filelist
2484 dired-directory
))) ;dir or wildcard
2486 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2488 (defvar anything-c-source-files-in-all-dired
2489 '((name .
"Files in all dired buffer.")
2490 (candidates . anything-c-files-in-all-dired-candidates
)
2492 ;; (anything 'anything-c-source-files-in-all-dired)
2496 (defvar anything-c-info-pages nil
2497 "All info pages on system.
2498 Will be calculated the first time you invoke anything with this
2501 (defvar anything-c-source-info-pages
2502 `((name .
"Info Pages")
2505 (if anything-c-info-pages
2506 anything-c-info-pages
2507 (setq anything-c-info-pages
2508 (save-window-excursion
2511 (Info-find-node "dir" "top")
2512 (goto-char (point-min))
2513 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2515 (while (re-search-forward info-topic-regexp nil t
)
2516 (add-to-list 'topics
(match-string-no-properties 1)))
2517 (goto-char (point-min))
2520 (action .
(("Show with Info" .
(lambda (node-str)
2521 (info (replace-regexp-in-string
2522 "^[^:]+: " "" node-str
))))))
2523 (requires-pattern .
2)))
2524 ;; (anything 'anything-c-source-info-pages)
2527 ;;; Use info-index plug-in. Note that `name' attribute is
2528 ;;; not needed but `anything-c-insert-summary' uses it.
2530 (defvar anything-c-source-info-elisp
2531 '((name .
"Info index: elisp")
2532 (info-index .
"elisp")))
2533 ;; (anything 'anything-c-source-info-elisp)
2536 (defvar anything-c-source-info-cl
2537 '((name .
"Info index: cl")
2538 (info-index .
"cl")))
2539 ;; (anything 'anything-c-source-info-cl)
2542 (defvar anything-c-source-info-org
2543 '((name .
"Info index: org")
2544 (info-index .
"org")))
2545 ;; (anything 'anything-c-source-info-org)
2547 ;; Info Index ratpoison
2548 (defvar anything-c-source-info-ratpoison
2549 '((name .
"Info index: ratpoison")
2550 (info-index .
"ratpoison")))
2551 ;; (anything 'anything-c-source-info-ratpoison)
2554 (defvar anything-c-source-info-zsh
2555 '((name .
"Info index: zsh")
2556 (info-index .
"zsh")))
2557 ;; (anything 'anything-c-source-info-zsh)
2560 (defvar anything-c-source-info-bash
2561 '((name .
"Info index: bash")
2562 (info-index .
"bash")))
2563 ;; (anything 'anything-c-source-info-bash)
2565 ;; Info Index coreutils
2566 (defvar anything-c-source-info-coreutils
2567 '((name .
"Info index: coreutils")
2568 (info-index .
"coreutils")))
2569 ;; (anything 'anything-c-source-info-coreutils)
2571 ;; Info Index fileutils
2572 (defvar anything-c-source-info-fileutils
2573 '((name .
"Info index: fileutils")
2574 (info-index .
"fileutils")))
2575 ;; (anything 'anything-c-source-info-fileutils)
2578 (defvar anything-c-source-info-find
2579 '((name .
"Info index: find")
2580 (info-index .
"find")))
2581 ;; (anything 'anything-c-source-info-find)
2583 ;; Info Index sh-utils
2584 (defvar anything-c-source-info-sh-utils
2585 '((name .
"Info index: sh-utils")
2586 (info-index .
"sh-utils")))
2587 ;; (anything 'anything-c-source-info-sh-utils)
2589 ;; Info Index textutils
2590 (defvar anything-c-source-info-textutils
2591 '((name .
"Info index: textutils")
2592 (info-index .
"textutils")))
2593 ;; (anything 'anything-c-source-info-textutils)
2596 (defvar anything-c-source-info-libc
2597 '((name .
"Info index: libc")
2598 (info-index .
"libc")))
2599 ;; (anything 'anything-c-source-info-libc)
2602 (defvar anything-c-source-info-make
2603 '((name .
"Info index: make")
2604 (info-index .
"make")))
2605 ;; (anything 'anything-c-source-info-make)
2607 ;; Info Index automake
2608 (defvar anything-c-source-info-automake
2609 '((name .
"Info index: automake")
2610 (info-index .
"automake")))
2611 ;; (anything 'anything-c-source-info-automake)
2613 ;; Info Index autoconf
2614 (defvar anything-c-source-info-autoconf
2615 '((name .
"Info index: autoconf")
2616 (info-index .
"autoconf")))
2617 ;; (anything 'anything-c-source-info-autoconf)
2619 ;; Info Index emacs-lisp-intro
2620 (defvar anything-c-source-info-emacs-lisp-intro
2621 '((name .
"Info index: emacs-lisp-intro")
2622 (info-index .
"emacs-lisp-intro")))
2623 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
2626 (defvar anything-c-source-info-emacs
2627 '((name .
"Info index: emacs")
2628 (info-index .
"emacs")))
2629 ;; (anything 'anything-c-source-info-emacs)
2632 (defvar anything-c-source-info-elib
2633 '((name .
"Info index: elib")
2634 (info-index .
"elib")))
2635 ;; (anything 'anything-c-source-info-elib)
2638 (defvar anything-c-source-info-eieio
2639 '((name .
"Info index: eieio")
2640 (info-index .
"eieio")))
2641 ;; (anything 'anything-c-source-info-eieio)
2643 ;; Info Index gauche-refe
2644 (defvar anything-c-source-info-gauche-refe
2645 '((name .
"Info index: gauche")
2646 (info-index .
"gauche-refe")))
2647 ;; (anything 'anything-c-source-info-gauche-refe)
2650 (defvar anything-c-source-info-guile
2651 '((name .
"Info index: guile")
2652 (info-index .
"guile")))
2653 ;; (anything 'anything-c-source-info-guile)
2655 ;; Info Index guile-tut
2656 (defvar anything-c-source-info-guile-tut
2657 '((name .
"Info index: guile-tut")
2658 (info-index .
"guile-tut")))
2659 ;; (anything 'anything-c-source-info-guile-tut)
2662 (defvar anything-c-source-info-goops
2663 '((name .
"Info index: goops")
2664 (info-index .
"goops")))
2665 ;; (anything 'anything-c-source-info-goops)
2667 ;; Info Index screen
2668 (defvar anything-c-source-info-screen
2669 '((name .
"Info index: screen")
2670 (info-index .
"screen")
2671 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
2672 ;; (anything 'anything-c-source-info-screen)
2675 (defvar anything-c-source-info-latex
2676 '((name .
"Info index: latex")
2677 (info-index .
"latex")))
2678 ;; (anything 'anything-c-source-info-latex)
2681 (defvar anything-c-source-info-gawk
2682 '((name .
"Info index: gawk")
2683 (info-index .
"gawk")))
2684 ;; (anything 'anything-c-source-info-gawk)
2687 (defvar anything-c-source-info-sed
2688 '((name .
"Info index: sed")
2689 (info-index .
"sed")))
2690 ;; (anything 'anything-c-source-info-sed)
2693 (defvar anything-c-source-info-m4
2694 '((name .
"Info index: m4")
2695 (info-index .
"m4")))
2696 ;; (anything 'anything-c-source-info-m4)
2699 (defvar anything-c-source-info-wget
2700 '((name .
"Info index: wget")
2701 (info-index .
"wget")))
2702 ;; (anything 'anything-c-source-info-wget)
2704 ;; Info Index binutils
2705 (defvar anything-c-source-info-binutils
2706 '((name .
"Info index: binutils")
2707 (info-index .
"binutils")))
2708 ;; (anything 'anything-c-source-info-binutils)
2711 (defvar anything-c-source-info-as
2712 '((name .
"Info index: as")
2713 (info-index .
"as")))
2714 ;; (anything 'anything-c-source-info-as)
2717 (defvar anything-c-source-info-bfd
2718 '((name .
"Info index: bfd")
2719 (info-index .
"bfd")))
2720 ;; (anything 'anything-c-source-info-bfd)
2723 (defvar anything-c-source-info-gprof
2724 '((name .
"Info index: gprof")
2725 (info-index .
"gprof")))
2726 ;; (anything 'anything-c-source-info-gprof)
2729 (defvar anything-c-source-info-ld
2730 '((name .
"Info index: ld")
2731 (info-index .
"ld")))
2732 ;; (anything 'anything-c-source-info-ld)
2735 (defvar anything-c-source-info-diff
2736 '((name .
"Info index: diff")
2737 (info-index .
"diff")))
2738 ;; (anything 'anything-c-source-info-diff)
2741 (defvar anything-c-source-info-flex
2742 '((name .
"Info index: flex")
2743 (info-index .
"flex")))
2744 ;; (anything 'anything-c-source-info-flex)
2747 (defvar anything-c-source-info-grep
2748 '((name .
"Info index: grep")
2749 (info-index .
"grep")))
2750 ;; (anything 'anything-c-source-info-grep)
2753 (defvar anything-c-source-info-gzip
2754 '((name .
"Info index: gzip")
2755 (info-index .
"gzip")))
2756 ;; (anything 'anything-c-source-info-gzip)
2758 ;; Info Index libtool
2759 (defvar anything-c-source-info-libtool
2760 '((name .
"Info index: libtool")
2761 (info-index .
"libtool")))
2762 ;; (anything 'anything-c-source-info-libtool)
2764 ;; Info Index texinfo
2765 (defvar anything-c-source-info-texinfo
2766 '((name .
"Info index: texinfo")
2767 (info-index .
"texinfo")))
2768 ;; (anything 'anything-c-source-info-texinfo)
2771 (defvar anything-c-source-info-info
2772 '((name .
"Info index: info")
2773 (info-index .
"info")))
2774 ;; (anything 'anything-c-source-info-info)
2777 (defvar anything-c-source-info-gdb
2778 '((name .
"Info index: gdb")
2779 (info-index .
"gdb")))
2780 ;; (anything 'anything-c-source-info-gdb)
2783 (defvar anything-c-source-info-stabs
2784 '((name .
"Info index: stabs")
2785 (info-index .
"stabs")))
2786 ;; (anything 'anything-c-source-info-stabs)
2788 ;; Info Index cvsbook
2789 (defvar anything-c-source-info-cvsbook
2790 '((name .
"Info index: cvsbook")
2791 (info-index .
"cvsbook")))
2792 ;; (anything 'anything-c-source-info-cvsbook)
2795 (defvar anything-c-source-info-cvs
2796 '((name .
"Info index: cvs")
2797 (info-index .
"cvs")))
2798 ;; (anything 'anything-c-source-info-cvs)
2801 (defvar anything-c-source-info-bison
2802 '((name .
"Info index: bison")
2803 (info-index .
"bison")))
2804 ;; (anything 'anything-c-source-info-bison)
2806 ;; Info Index id-utils
2807 (defvar anything-c-source-info-id-utils
2808 '((name .
"Info index: id-utils")
2809 (info-index .
"id-utils")))
2810 ;; (anything 'anything-c-source-info-id-utils)
2812 ;; Info Index global
2813 (defvar anything-c-source-info-global
2814 '((name .
"Info index: global")
2815 (info-index .
"global")))
2816 ;; (anything 'anything-c-source-info-global)
2820 (defvar anything-c-man-pages nil
2821 "All man pages on system.
2822 Will be calculated the first time you invoke anything with this
2825 (defvar anything-c-source-man-pages
2826 `((name .
"Manual Pages")
2827 (candidates .
(lambda ()
2828 (if anything-c-man-pages
2829 anything-c-man-pages
2830 ;; XEmacs doesn't have a woman :)
2831 (setq anything-c-man-pages
2834 (woman-file-name "")
2835 (sort (mapcar 'car woman-topic-all-completions
)
2837 (action ("Show with Woman"
2838 .
(lambda (candidate)
2839 (let ((wfiles (woman-file-name-all-completions candidate
)))
2840 (if (> (length wfiles
) 1)
2841 (woman-find-file (anything-comp-read "ManFile: " wfiles
2843 (woman candidate
))))))
2844 ;; Woman does not work OS X
2845 ;; http://xahlee.org/emacs/modernization_man_page.html
2846 (action-transformer .
(lambda (actions candidate
)
2847 (if (eq system-type
'darwin
)
2848 '(("Show with Man" . man
))
2850 (requires-pattern .
2)))
2851 ;; (anything 'anything-c-source-man-pages)
2854 ;;; Complex command history
2855 (defvar anything-c-source-complex-command-history
2856 '((name .
"Complex Command History")
2857 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
2859 ;; (anything 'anything-c-source-complex-command-history)
2862 (defvar anything-c-source-extended-command-history
2863 '((name .
"Emacs Commands History")
2864 (candidates . extended-command-history
)
2866 ;; (anything 'anything-c-source-extended-command-history)
2869 (defvar anything-c-source-emacs-commands
2870 '((name .
"Emacs Commands")
2871 (candidates .
(lambda ()
2873 (mapatoms (lambda (a)
2875 (push (symbol-name a
)
2877 (sort commands
'string-lessp
))))
2879 (requires-pattern .
2))
2880 "Source for completing and invoking Emacs commands.
2881 A command is a function with interactive spec that can
2882 be invoked with `M-x'.
2884 To get non-interactive functions listed, use
2885 `anything-c-source-emacs-functions'.")
2886 ;; (anything 'anything-c-source-emacs-commands)
2888 ;; Another replacement of `M-x' that act exactly like the
2889 ;; vanilla Emacs one, no problem of windows configuration, prefix args
2890 ;; are passed before calling `M-x' (e.g C-u M-x..).
2892 (defun anything-M-x ()
2893 "Preconfigured `anything' for Emacs commands.
2894 It is `anything' replacement of regular `M-x' `execute-extended-command'."
2896 (let ((command (anything-comp-read "M-x " obarray
2900 :name
"Emacs Commands"
2902 #'(lambda (candidate)
2903 (describe-function (intern candidate
)))
2904 :persistent-help
"Describe this command"
2905 :history extended-command-history
))
2906 (history (loop with hist
2907 for i in extended-command-history
2908 for com
= (intern i
)
2909 when
(and (fboundp com
) (not (member i hist
)))
2910 collect i into hist finally return hist
)))
2911 (call-interactively (intern command
))
2912 (setq extended-command-history
(cons command
(delete command history
)))))
2915 (defvar anything-c-source-lacarte
2916 '((name .
"Lacarte")
2917 (init .
(lambda () (require 'lacarte
)))
2918 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
2919 (candidate-number-limit .
9999)
2920 (action . anything-c-call-interactively
))
2923 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
2924 ;; (anything 'anything-c-source-lacarte)
2928 (defvar anything-c-source-emacs-functions
2929 '((name .
"Emacs Functions")
2930 (candidates .
(lambda ()
2932 (mapatoms (lambda (a)
2934 (push (symbol-name a
) commands
))))
2935 (sort commands
'string-lessp
))))
2937 (requires-pattern .
2))
2938 "Source for completing Emacs functions.")
2939 ;; (anything 'anything-c-source-emacs-functions)
2941 ;;; With abbrev expansion
2942 ;;; Similar to my exec-abbrev-cmd.el
2943 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
2944 (defvar anything-c-function-abbrev-regexp nil
2945 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
2946 Regexp built from the current `anything-pattern' interpreting it
2948 Only for internal use.")
2950 (defun anything-c-match-function-by-abbrev (candidate)
2951 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
2953 Abbreviations are made by taking the first character from each
2954 word in the function's name, e.g. \"bb\" is an abbrev for
2955 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
2956 (string-match anything-c-function-abbrev-regexp candidate
))
2958 (defvar anything-c-source-emacs-functions-with-abbrevs
2959 (append anything-c-source-emacs-functions
2960 '((match anything-c-match-function-by-abbrev
2961 anything-c-string-match
))
2964 (defadvice anything-update
2965 (before anything-c-update-function-abbrev-regexp activate
)
2966 (let ((char-list (append anything-pattern nil
))
2968 (dolist (c char-list
)
2969 (setq str
(concat str
(list c
) "[^-]*-")))
2970 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
2971 (setq anything-c-function-abbrev-regexp str
))))))))
2972 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
2974 (defvar anything-c-source-advice
2975 '((name .
"Function Advice")
2976 (candidates . anything-c-advice-candidates
)
2977 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
2978 ;; (real-to-display . anything-c-advice-real-to-display)
2981 (persistent-action . anything-c-advice-persistent-action
)
2982 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
2983 ;; (anything 'anything-c-source-advice)
2984 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
2987 (defun anything-c-advice-candidates ()
2989 (loop for
(fname) in ad-advised-functions
2990 for function
= (intern fname
)
2992 (loop for class in ad-advice-classes append
2993 (loop for advice in
(ad-get-advice-info-field function class
)
2994 for enabled
= (ad-advice-enabled advice
)
2998 (if enabled
"Enabled " "Disabled")
2999 (propertize fname
'face
'font-lock-function-name-face
)
3000 (ad-make-single-advice-docstring advice class nil
))
3001 (list function class advice
))))))
3003 (defun anything-c-advice-persistent-action (func-class-advice)
3004 (if current-prefix-arg
3005 (anything-c-advice-toggle func-class-advice
)
3006 (describe-function (car func-class-advice
))))
3008 (defun anything-c-advice-toggle (func-class-advice)
3009 (destructuring-bind (function class advice
) func-class-advice
3010 (cond ((ad-advice-enabled advice
)
3011 (ad-advice-set-enabled advice nil
)
3012 (message "Disabled"))
3014 (ad-advice-set-enabled advice t
)
3015 (message "Enabled")))
3016 (ad-activate function
)
3017 (and anything-in-persistent-action
3018 (anything-c-advice-update-current-display-string))))
3020 (defun anything-c-advice-update-current-display-string ()
3021 (anything-edit-current-selection
3022 (let ((newword (cond ((looking-at "Disabled") "Enabled")
3023 ((looking-at "Enabled") "Disabled")))
3026 (delete-region (point) (progn (forward-word 1) (point)))
3027 (insert newword
)))))
3030 (defun anything-manage-advice ()
3031 "Preconfigured `anything' to disable/enable function advices."
3033 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
3037 (defvar anything-c-source-emacs-variables
3038 '((name .
"Emacs Variables")
3039 (candidates .
(lambda ()
3040 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
3042 (requires-pattern .
2))
3043 "Source for completing Emacs variables.")
3044 ;; (anything 'anything-c-source-emacs-variables)
3048 (eval-when-compile (require 'bookmark
))
3049 (defvar anything-c-source-bookmarks
3050 '((name .
"Bookmarks")
3052 (require 'bookmark
)))
3053 (candidates . bookmark-all-names
)
3055 "See (info \"(emacs)Bookmarks\").")
3056 ;; (anything 'anything-c-source-bookmarks)
3059 (defvar anything-c-source-bookmark-set
3060 '((name .
"Set Bookmark")
3062 (action . bookmark-set
))
3063 "See (info \"(emacs)Bookmarks\").")
3064 ;; (anything 'anything-c-source-bookmark-set)
3066 ;;; Visible Bookmarks
3067 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
3070 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
3071 (defvar anything-c-source-bm
3072 '((name .
"Visible Bookmarks")
3073 (init . anything-c-bm-init
)
3074 (candidates-in-buffer)
3078 http://www.nongnu.org/bm/")
3080 (defun anything-c-bm-init ()
3081 "Init function for `anything-c-source-bm'."
3082 (when (require 'bm nil t
)
3084 (let ((bookmarks (bm-lists))
3085 (buf (anything-candidate-buffer 'global
)))
3086 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
3087 '< :key
'overlay-start
))
3088 (let ((start (overlay-start bm
))
3089 (end (overlay-end bm
))
3090 (annotation (or (overlay-get bm
'annotation
) "")))
3091 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
3092 (let ((str (format "%5d: [%s]: %s\n"
3093 (line-number-at-pos start
)
3095 (buffer-substring start
(1- end
)))))
3096 (with-current-buffer buf
(insert str
))))))))))
3098 ;;; Special bookmarks
3099 (defvar anything-c-source-bookmarks-ssh
3100 '((name .
"Bookmarks-ssh")
3102 (require 'bookmark
)))
3103 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
3105 "See (info \"(emacs)Bookmarks\").")
3106 ;; (anything 'anything-c-source-bookmarks-ssh)
3108 (defvar anything-c-source-bookmarks-su
3109 '((name .
"Bookmarks-root")
3111 (require 'bookmark
)))
3112 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
3113 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
3116 "See (info \"(emacs)Bookmarks\").")
3117 ;; (anything 'anything-c-source-bookmarks-su)
3119 (defvar anything-c-source-bookmarks-local
3120 '((name .
"Bookmarks-Local")
3122 (require 'bookmark
)))
3123 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
3124 (filtered-candidate-transformer
3125 anything-c-adaptive-sort
3126 anything-c-highlight-bookmark
)
3128 "See (info \"(emacs)Bookmarks\").")
3129 ;; (anything 'anything-c-source-bookmarks-local)
3131 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
3132 (let* ((lis-all (bookmark-all-names))
3133 (lis-loc (cond (local (loop for i in lis-all
3134 unless
(string-match "^(ssh)\\|^(su)" i
)
3136 (su (loop for i in lis-all
3137 when
(string-match "^(su)" i
)
3139 (sudo (loop for i in lis-all
3140 when
(string-match "^(sudo)" i
)
3142 (ssh (loop for i in lis-all
3143 when
(string-match "^(ssh)" i
)
3145 (sort lis-loc
'string-lessp
)))
3147 (defun anything-c-bookmark-root-logged-p ()
3149 (dolist (i (mapcar #'buffer-name
(buffer-list)))
3150 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
3151 (throw 'break t
)))))
3153 (defun anything-c-highlight-bookmark-su (files source
)
3154 (if (anything-c-bookmark-root-logged-p)
3155 (anything-c-highlight-bookmark files source
)
3156 (anything-c-highlight-not-logged files source
)))
3158 (defun anything-c-highlight-not-logged (files source
)
3159 (loop for i in files
3160 collect
(propertize i
'face anything-c-bookmarks-face3
)))
3162 (defun anything-c-highlight-bookmark (bookmarks source
)
3163 "Used as `candidate-transformer' to colorize bookmarks.
3164 Work both with standard Emacs bookmarks and bookmark-extensions.el."
3165 (loop for i in bookmarks
3166 for isfile
= (bookmark-get-filename i
)
3167 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
3168 (bmkext-get-buffer-name i
))
3169 for handlerp
= (and (fboundp 'bookmark-get-handler
)
3170 (bookmark-get-handler i
))
3171 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
3172 (bmkext-w3m-bookmark-p i
))
3173 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
3174 (bmkext-gnus-bookmark-p i
))
3175 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
3176 (bmkext-man-bookmark-p i
))
3177 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
3178 (bmkext-woman-bookmark-p i
))
3179 for handlerp
= (bookmark-get-handler i
)
3180 for isannotation
= (bookmark-get-annotation i
)
3181 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
3182 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
3183 ;; Add a * if bookmark have annotation
3184 if
(and isannotation
(not (string-equal isannotation
"")))
3185 do
(setq i
(concat "*" i
))
3186 collect
(cond (;; info buffers
3188 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
3191 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
3194 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
3197 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
3200 (propertize i
'face
'((:foreground
"Tomato"))))
3202 (and isfile
(file-directory-p isfile
))
3203 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
3206 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
3209 ;;; Faces for bookmarks
3210 (defface anything-bmkext-info
3211 '((t (:foreground
"green")))
3212 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3215 (defface anything-bmkext-w3m
3216 '((t (:foreground
"yellow")))
3217 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3220 (defface anything-bmkext-gnus
3221 '((t (:foreground
"magenta")))
3222 "*Face used for Gnus bookmarks."
3225 (defface anything-bmkext-man
3226 '((t (:foreground
"Orange4")))
3227 "*Face used for Woman/man bookmarks."
3230 (defface anything-bmkext-no--file
3231 '((t (:foreground
"grey")))
3232 "*Face used for non--file bookmarks."
3235 (defface anything-bmkext-file
3236 '((t (:foreground
"Deepskyblue2")))
3237 "*Face used for non--file bookmarks."
3240 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
3241 "Face for su/sudo bookmarks."
3244 (defvar anything-c-bookmarks-face1
'anything-dir-heading
)
3245 (defvar anything-c-bookmarks-face2
'anything-file-name
)
3246 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
3249 ;;; Sources to filter bookmark-extensions bookmarks.
3250 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3251 ;; If you want to enable google-maps in addressbook you will need
3252 ;; Julien Danjou google-maps-el package available here:
3253 ;; http://julien.danjou.info/google-maps-el.html
3255 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
3256 "Return a filtered `bookmark-alist' sorted alphabetically."
3258 with alist
= (if args
3259 (apply #'(lambda (x) (funcall fn x
)) args
)
3264 finally return
(sort sa
'string-lessp
)))
3267 (defvar anything-c-source-bmkext-addressbook
3268 '((name .
"Bookmark Addressbook")
3270 (require 'bookmark-extensions
)
3271 (bookmark-maybe-load-default-file)))
3272 (candidates . anything-c-bmkext-addressbook-setup-alist
)
3274 .
(lambda (candidate)
3275 (let ((bmk (anything-bookmark-get-bookmark-from-name
3277 (bookmark--jump-via bmk
'pop-to-buffer
))))
3278 (persistent-help .
"Show contact - Prefix with C-u to append")
3279 (filtered-candidate-transformer
3280 anything-c-adaptive-sort
3281 anything-c-highlight-bookmark
)
3282 (action .
(("Show person's data"
3283 .
(lambda (candidate)
3284 (let ((bmk (anything-bookmark-get-bookmark-from-name
3286 (current-prefix-arg anything-current-prefix-arg
))
3287 (bookmark-jump bmk
))))
3289 .
(lambda (candidate)
3290 (let ((bmk (anything-bookmark-get-bookmark-from-name
3292 (if anything-current-prefix-arg
3293 (addressbook-set-mail-buffer1 bmk
'append
)
3294 (addressbook-set-mail-buffer1 bmk
)))))
3296 .
(lambda (candidate)
3297 (let ((bmk (anything-bookmark-get-bookmark-from-name
3299 (addressbook-bookmark-edit
3300 (assoc bmk bookmark-alist
)))))
3301 ("Insert Email at point"
3302 .
(lambda (candidate)
3303 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3305 (mlist (split-string
3307 'email
(assoc bmk bookmark-alist
))
3310 (if (> (length mlist
) 1)
3312 "Insert Mail Address: " mlist
:must-match t
)
3315 .
(lambda (candidate)
3316 (let ((bmk (anything-bookmark-get-bookmark-from-name
3318 (bookmark-show-annotation bmk
))))
3320 .
(lambda (candidate)
3321 (let ((bmk (anything-bookmark-get-bookmark-from-name
3323 (bookmark-edit-annotation bmk
))))
3325 .
(lambda (candidate)
3326 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3328 (full-bmk (assoc bmk bookmark-alist
)))
3329 (addressbook-google-map full-bmk
))))))))
3332 (defun anything-c-bmkext-addressbook-setup-alist ()
3333 "Specialized filter function for bookmarks w3m."
3334 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
3337 (defvar anything-c-source-bookmark-w3m
3338 '((name .
"Bookmark W3m")
3340 (require 'bookmark-extensions
)
3341 (bookmark-maybe-load-default-file)))
3342 (candidates . anything-c-bookmark-w3m-setup-alist
)
3343 (filtered-candidate-transformer
3344 anything-c-adaptive-sort
3345 anything-c-highlight-bookmark
)
3347 ;; (anything 'anything-c-source-bookmark-w3m)
3349 (defun anything-c-bookmark-w3m-setup-alist ()
3350 "Specialized filter function for bookmarks w3m."
3351 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
3354 (defvar anything-c-source-bookmark-images
3355 '((name .
"Bookmark Images")
3357 (require 'bookmark-extensions
)
3358 (bookmark-maybe-load-default-file)))
3359 (candidates . anything-c-bookmark-images-setup-alist
)
3360 (filtered-candidate-transformer
3361 anything-c-adaptive-sort
3362 anything-c-highlight-bookmark
)
3364 ;; (anything 'anything-c-source-bookmark-images)
3366 (defun anything-c-bookmark-images-setup-alist ()
3367 "Specialized filter function for images bookmarks."
3368 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
3371 (defvar anything-c-source-bookmark-man
3372 '((name .
"Bookmark Woman&Man")
3374 (require 'bookmark-extensions
)
3375 (bookmark-maybe-load-default-file)))
3376 (candidates . anything-c-bookmark-man-setup-alist
)
3377 (filtered-candidate-transformer
3378 anything-c-adaptive-sort
3379 anything-c-highlight-bookmark
)
3381 ;; (anything 'anything-c-source-bookmark-man)
3383 (defun anything-c-bookmark-man-setup-alist ()
3384 "Specialized filter function for bookmarks w3m."
3385 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
3386 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
3389 (defvar anything-c-source-bookmark-gnus
3390 '((name .
"Bookmark Gnus")
3392 (require 'bookmark-extensions
)
3393 (bookmark-maybe-load-default-file)))
3394 (candidates . anything-c-bookmark-gnus-setup-alist
)
3395 (filtered-candidate-transformer
3396 anything-c-adaptive-sort
3397 anything-c-highlight-bookmark
)
3399 ;; (anything 'anything-c-source-bookmark-gnus)
3401 (defun anything-c-bookmark-gnus-setup-alist ()
3402 "Specialized filter function for bookmarks gnus."
3403 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
3406 (defvar anything-c-source-bookmark-info
3407 '((name .
"Bookmark Info")
3409 (require 'bookmark-extensions
)
3410 (bookmark-maybe-load-default-file)))
3411 (candidates . anything-c-bookmark-info-setup-alist
)
3412 (filtered-candidate-transformer
3413 anything-c-adaptive-sort
3414 anything-c-highlight-bookmark
)
3416 ;; (anything 'anything-c-source-bookmark-info)
3418 (defun anything-c-bookmark-info-setup-alist ()
3419 "Specialized filter function for bookmarks info."
3420 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
3422 ;; Local Files&directories
3423 (defvar anything-c-source-bookmark-files
&dirs
3424 '((name .
"Bookmark Files&Directories")
3426 (require 'bookmark-extensions
)
3427 (bookmark-maybe-load-default-file)))
3428 (candidates . anything-c-bookmark-local-files-setup-alist
)
3429 (filtered-candidate-transformer
3430 anything-c-adaptive-sort
3431 anything-c-highlight-bookmark
)
3433 ;; (anything 'anything-c-source-bookmark-files&dirs)
3435 (defun anything-c-bookmark-local-files-setup-alist ()
3436 "Specialized filter function for bookmarks locals files."
3437 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
3439 ;; Su Files&directories
3440 (defvar anything-c-source-bookmark-su-files
&dirs
3441 '((name .
"Bookmark Root-Files&Directories")
3443 (require 'bookmark-extensions
)
3444 (bookmark-maybe-load-default-file)))
3445 (candidates . anything-c-bookmark-su-files-setup-alist
)
3446 (filtered-candidate-transformer
3447 anything-c-adaptive-sort
3448 anything-c-highlight-bookmark-su
)
3450 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3452 (defun anything-c-bookmark-su-files-setup-alist ()
3453 "Specialized filter function for bookmarks su/sudo files."
3455 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
3457 for isfile
= (bookmark-get-filename i
)
3458 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
3460 (string-match tramp-file-name-regexp isfile
)))
3461 for issu
= (and istramp
3462 (string-match bmkext-su-or-sudo-regexp isfile
))
3466 ;; Ssh Files&directories
3467 (defvar anything-c-source-bookmark-ssh-files
&dirs
3468 '((name .
"Bookmark Ssh-Files&Directories")
3470 (require 'bookmark-extensions
)
3471 (bookmark-maybe-load-default-file)))
3472 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
3473 (filtered-candidate-transformer . anything-c-adaptive-sort
)
3475 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3477 (defun anything-c-bookmark-ssh-files-setup-alist ()
3478 "Specialized filter function for bookmarks ssh files."
3480 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
3482 for isfile
= (bookmark-get-filename i
)
3483 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
3485 (string-match tramp-file-name-regexp isfile
)))
3486 for isssh
= (and istramp
3487 (string-match "/ssh:" isfile
))
3492 ;; All bookmark-extensions sources.
3494 (defun anything-bookmark-ext ()
3495 "Preconfigured `anything' for bookmark-extensions sources.
3496 Needs bookmark-ext.el
3498 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3502 '(anything-c-source-bookmark-files&dirs
3503 anything-c-source-bookmark-w3m
3504 anything-c-source-bmkext-addressbook
3505 anything-c-source-bookmark-gnus
3506 anything-c-source-bookmark-info
3507 anything-c-source-bookmark-man
3508 anything-c-source-bookmark-images
3509 anything-c-source-bookmark-su-files
&dirs
3510 anything-c-source-bookmark-ssh-files
&dirs
)
3511 :prompt
"SearchBookmark: "
3512 :buffer
"*anything bmkext*"))
3515 ;; Firefox bookmarks
3516 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
3517 ;; (only for firefox versions >=3)
3518 ;; To achieve that, open about:config in firefox and double click on this line to enable value
3520 ;; user_pref("browser.bookmarks.autoExportHTML", false);
3521 ;; You should have now:
3522 ;; user_pref("browser.bookmarks.autoExportHTML", true);
3524 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ ]*")
3525 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
3527 (defun anything-get-firefox-user-init-dir ()
3528 "Guess the default Firefox user directory name."
3529 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
3531 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
3532 (goto-char (point-min))
3533 (when (search-forward "Path=" nil t
)
3534 (buffer-substring-no-properties (point) (point-at-eol))))))
3535 (file-name-as-directory (concat moz-dir moz-user-dir
))))
3537 (defun anything-guess-firefox-bookmark-file ()
3538 "Return the path of the Firefox bookmarks file."
3539 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
3541 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
3542 "Parse html bookmark FILE and return an alist with (title . url) as elements."
3543 (let (bookmarks-alist url title
)
3545 (insert-file-contents file
)
3546 (goto-char (point-min))
3549 (when (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
3551 (when (re-search-forward url-regexp nil t
)
3552 (setq url
(concat "\"" (match-string 0))))
3554 (when (re-search-forward bmk-regexp nil t
)
3555 (setq title
(match-string 1)))
3556 (push (cons title url
) bookmarks-alist
))))
3557 (nreverse bookmarks-alist
)))
3560 (defvar anything-c-firefox-bookmarks-alist nil
)
3561 (defvar anything-c-source-firefox-bookmarks
3562 '((name .
"Firefox Bookmarks")
3564 (setq anything-c-firefox-bookmarks-alist
3565 (anything-html-bookmarks-to-alist
3566 (anything-guess-firefox-bookmark-file)
3567 anything-firefox-bookmark-url-regexp
3568 anything-firefox-bookmarks-regexp
))))
3569 (candidates .
(lambda ()
3571 anything-c-firefox-bookmarks-alist
)))
3572 (filtered-candidate-transformer
3573 anything-c-adaptive-sort
3574 anything-c-highlight-firefox-bookmarks
)
3575 (action .
(("Browse Url Firefox"
3576 .
(lambda (candidate)
3578 (anything-c-firefox-bookmarks-get-value candidate
))))
3580 .
(lambda (candidate)
3582 (anything-c-firefox-bookmarks-get-value candidate
))))
3585 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
3587 ;; (anything 'anything-c-source-firefox-bookmarks)
3589 (defun anything-c-firefox-bookmarks-get-value (elm)
3590 (replace-regexp-in-string "\"" ""
3592 anything-c-firefox-bookmarks-alist
))))
3595 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
3596 (loop for i in bookmarks
3599 'face
'((:foreground
"YellowGreen"))
3600 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
3603 (eval-when-compile (require 'w3m-bookmark nil t
))
3604 (unless (and (require 'w3m nil t
)
3605 (require 'w3m-bookmark nil t
))
3606 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html"))
3609 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
3610 "Face for w3m bookmarks" :group
'anything
)
3612 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
3613 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
3614 (defvar anything-c-w3m-bookmarks-alist nil
)
3615 (defvar anything-c-source-w3m-bookmarks
3616 '((name .
"W3m Bookmarks")
3618 (setq anything-c-w3m-bookmarks-alist
3619 (anything-html-bookmarks-to-alist
3621 anything-w3m-bookmark-url-regexp
3622 anything-w3m-bookmarks-regexp
))))
3623 (candidates .
(lambda ()
3624 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
3625 (filtered-candidate-transformer
3626 anything-c-adaptive-sort
3627 anything-c-highlight-w3m-bookmarks
)
3628 (action .
(("Browse Url"
3629 .
(lambda (candidate)
3630 (anything-c-w3m-browse-bookmark candidate
)))
3633 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
3634 ("Browse Url Firefox"
3635 .
(lambda (candidate)
3636 (anything-c-w3m-browse-bookmark candidate t
)))
3638 .
(lambda (candidate)
3639 (anything-c-w3m-delete-bookmark candidate
)))
3641 .
(lambda (candidate)
3642 (anything-c-w3m-rename-bookmark candidate
)))))
3643 (persistent-action .
(lambda (candidate)
3644 (if current-prefix-arg
3645 (anything-c-w3m-browse-bookmark candidate t
)
3646 (anything-c-w3m-browse-bookmark candidate nil t
))))
3647 (persistent-help .
"Open URL with emacs-w3m in new tab / \
3648 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
3649 "Needs w3m and emacs-w3m.
3651 http://w3m.sourceforge.net/
3652 http://emacs-w3m.namazu.org/")
3654 ;; (anything 'anything-c-source-w3m-bookmarks)
3656 (defun anything-c-w3m-bookmarks-get-value (elm)
3657 (replace-regexp-in-string
3658 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
3660 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
3661 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
3662 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
3663 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
3665 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
3666 (loop for i in bookmarks
3668 i
'face
'anything-w3m-bookmarks-face
3669 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
3672 (defun anything-c-w3m-delete-bookmark (elm)
3674 (find-file-literally w3m-bookmark-file
)
3675 (goto-char (point-min))
3676 (when (re-search-forward elm nil t
)
3678 (delete-region (point)
3679 (line-end-position))
3680 (delete-blank-lines))
3681 (save-buffer (current-buffer))
3682 (kill-buffer (current-buffer))))
3684 (defun anything-c-w3m-rename-bookmark (elm)
3685 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
3686 (new-title (read-string "NewTitle: " old-title
)))
3688 (find-file-literally w3m-bookmark-file
)
3689 (goto-char (point-min))
3690 (when (re-search-forward (concat elm
"<") nil t
)
3691 (goto-char (1- (point)))
3692 (delete-char (- (length old-title
)))
3694 (save-buffer (current-buffer))
3695 (kill-buffer (current-buffer)))))
3698 ;;; Elisp library scan
3699 (defvar anything-c-source-elisp-library-scan
3700 '((name .
"Elisp libraries (Scan)")
3701 (init .
(anything-c-elisp-library-scan-init))
3702 (candidates-in-buffer)
3703 (action ("Find library"
3704 .
(lambda (candidate) (find-file (find-library-name candidate
))))
3705 ("Find library other window"
3706 .
(lambda (candidate)
3707 (find-file-other-window (find-library-name candidate
))))
3709 .
(lambda (candidate) (load-library candidate
))))))
3710 ;; (anything 'anything-c-source-elisp-library-scan)
3712 (defun anything-c-elisp-library-scan-init ()
3713 "Init anything buffer status."
3714 (let ((anything-buffer (anything-candidate-buffer 'global
))
3715 (library-list (anything-c-elisp-library-scan-list)))
3716 (with-current-buffer anything-buffer
3717 (dolist (library library-list
)
3718 (insert (format "%s\n" library
))))))
3720 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
3721 "Do completion for file names passed to `locate-file'.
3722 DIRS is directory to search path.
3723 STRING is string to match."
3724 ;; Use `load-path' as path when ignore `dirs'.
3725 (or dirs
(setq dirs load-path
))
3726 ;; Init with blank when ignore `string'.
3727 (or string
(setq string
""))
3728 ;; Get library list.
3729 (let ((string-dir (file-name-directory string
))
3730 ;; File regexp that suffix match `load-file-rep-suffixes'.
3731 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
3736 (setq dir default-directory
))
3738 (setq dir
(expand-file-name string-dir dir
)))
3739 (when (file-directory-p dir
)
3740 (dolist (file (file-name-all-completions
3741 (file-name-nondirectory string
) dir
))
3742 ;; Suffixes match `load-file-rep-suffixes'.
3743 (setq name
(if string-dir
(concat string-dir file
) file
))
3744 (if (string-match match-regexp name
)
3745 (add-to-list 'names name
)))))
3750 (defvar anything-c-imenu-delimiter
" / ")
3752 (defvar anything-c-imenu-index-filter nil
)
3753 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
3755 (defvar anything-c-cached-imenu-alist nil
)
3756 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
3758 (defvar anything-c-cached-imenu-candidates nil
)
3759 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
3761 (defvar anything-c-cached-imenu-tick nil
)
3762 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
3764 (eval-when-compile (require 'imenu
))
3765 (setq imenu-auto-rescan t
)
3767 (defun anything-imenu-create-candidates (entry)
3768 "Create candidates with ENTRY."
3769 (if (listp (cdr entry
))
3772 (if (consp (cdr sub
))
3775 (concat (car entry
) anything-c-imenu-delimiter subentry
))
3776 (anything-imenu-create-candidates sub
))
3777 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
3781 (defvar anything-c-source-imenu
3783 (init .
(lambda () (require 'imenu
)))
3784 (candidates . anything-c-imenu-candidates
)
3785 (persistent-action .
(lambda (elm)
3786 (anything-c-imenu-default-action elm
)
3787 (unless (fboundp 'semantic-imenu-tag-overlay
)
3788 (anything-match-line-color-current-line))))
3789 (persistent-help .
"Show this entry")
3790 (action . anything-c-imenu-default-action
))
3791 "See (info \"(emacs)Imenu\")")
3793 ;; (anything 'anything-c-source-imenu)
3795 (defun anything-c-imenu-candidates ()
3796 (with-current-buffer anything-current-buffer
3797 (let ((tick (buffer-modified-tick)))
3798 (if (eq anything-c-cached-imenu-tick tick
)
3799 anything-c-cached-imenu-candidates
3800 (setq imenu--index-alist nil
)
3801 (setq anything-c-cached-imenu-tick tick
3802 anything-c-cached-imenu-candidates
3805 'anything-imenu-create-candidates
3806 (setq anything-c-cached-imenu-alist
3807 (let ((index (imenu--make-index-alist)))
3808 (if anything-c-imenu-index-filter
3809 (funcall anything-c-imenu-index-filter index
)
3811 (setq anything-c-cached-imenu-candidates
3812 (mapcar #'(lambda (x)
3816 anything-c-cached-imenu-candidates
))))))
3818 (setq imenu-default-goto-function
'imenu-default-goto-function
)
3819 (defun anything-c-imenu-default-action (elm)
3820 "The default action for `anything-c-source-imenu'."
3821 (let ((path (split-string elm anything-c-imenu-delimiter
))
3822 (alist anything-c-cached-imenu-alist
))
3823 (if (> (length path
) 1)
3825 (setq alist
(assoc (car path
) alist
))
3826 (setq elm
(cadr path
))
3827 (imenu (assoc elm alist
)))
3828 (imenu (assoc elm alist
)))))
3831 (defvar anything-c-ctags-modes
3832 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
3833 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
3834 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
3836 (defun anything-c-source-ctags-init ()
3837 (when (and buffer-file-name
3838 (memq major-mode anything-c-ctags-modes
)
3839 (anything-current-buffer-is-modified))
3840 (with-current-buffer (anything-candidate-buffer 'local
)
3841 (call-process-shell-command
3842 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
3843 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
3844 anything-buffer-file-name
)
3845 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
3846 nil
(current-buffer))
3847 (goto-char (point-min))
3849 (delete-region (point-min) (point))
3850 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
3851 for lineno-start
= (point)
3852 for lineno
= (buffer-substring
3854 (1- (search-forward "," (point-at-eol) t
)))
3857 (insert (format "%5s:" lineno
))
3858 (search-forward "\177" (point-at-eol) t
)
3859 (delete-region (1- (point)) (point-at-eol))
3860 (forward-line 1)))))
3862 (defvar anything-c-source-ctags
3863 '((name .
"Exuberant ctags")
3864 (init . anything-c-source-ctags-init
)
3865 (candidates-in-buffer)
3868 "Needs Exuberant Ctags.
3870 http://ctags.sourceforge.net/")
3871 ;; (anything 'anything-c-source-ctags)
3874 (eval-when-compile (require 'semantic nil t
))
3875 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
3876 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
3877 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
3878 (defvar anything-semantic-candidates nil
)
3880 (defun anything-semantic-construct-candidates (tags depth
)
3881 (when (require 'semantic nil t
)
3887 (let ((type (semantic-tag-type tag
))
3888 (class (semantic-tag-class tag
)))
3889 (if (or (and (stringp type
)
3890 (or (string= type
"class")
3891 (string= type
"namespace")))
3892 (eq class
'function
)
3893 (eq class
'variable
))
3894 (cons (cons (concat (make-string (* depth
2) ?\s
)
3895 (semantic-format-tag-summarize tag nil t
))
3897 (anything-semantic-construct-candidates
3898 (semantic-tag-components tag
) (1+ depth
)))))))
3901 (defun anything-semantic-default-action (candidate)
3902 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
3903 (semantic-go-to-tag tag
)))
3905 (defvar anything-c-source-semantic
3906 '((name .
"Semantic Tags")
3908 (setq anything-semantic-candidates
3909 (ignore-errors (anything-semantic-construct-candidates
3910 (semantic-fetch-tags) 0)))))
3911 (candidates .
(lambda ()
3912 (if anything-semantic-candidates
3913 (mapcar 'car anything-semantic-candidates
))))
3914 (persistent-action .
(lambda (elm)
3915 (anything-semantic-default-action elm
)
3916 (anything-match-line-color-current-line)))
3917 (persistent-help .
"Show this entry")
3918 (action . anything-semantic-default-action
)
3919 "Needs semantic in CEDET.
3921 http://cedet.sourceforge.net/semantic.shtml
3922 http://cedet.sourceforge.net/"))
3924 ;; (anything 'anything-c-source-semantic)
3926 ;;; Function is called by
3928 (defun anything-simple-call-tree ()
3929 "Preconfigured `anything' for simple-call-tree. List function relationships.
3931 Needs simple-call-tree.el.
3932 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
3934 (anything-other-buffer
3935 '(anything-c-source-simple-call-tree-functions-callers
3936 anything-c-source-simple-call-tree-callers-functions
)
3937 "*anything simple-call-tree*"))
3939 (defvar anything-c-source-simple-call-tree-functions-callers
3940 '((name .
"Function is called by")
3941 (init . anything-c-simple-call-tree-functions-callers-init
)
3943 (candidates . anything-c-simple-call-tree-candidates
)
3944 (persistent-action . anything-c-simple-call-tree-persistent-action
)
3945 (persistent-help .
"Show function definitions by rotation")
3946 (action ("Find definition selected by persistent-action" .
3947 anything-c-simple-call-tree-find-definition
)))
3948 "Needs simple-call-tree.el.
3949 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
3951 (defvar anything-c-simple-call-tree-tick nil
)
3952 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
3953 (defun anything-c-simple-call-tree-analyze-maybe ()
3954 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
3955 (simple-call-tree-analyze)
3956 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
3958 (defun anything-c-simple-call-tree-init-base (function message
)
3959 (require 'simple-call-tree
)
3961 (when (anything-current-buffer-is-modified)
3962 (anything-c-simple-call-tree-analyze-maybe)
3963 (let ((list (funcall function simple-call-tree-alist
)))
3964 (with-current-buffer (anything-candidate-buffer 'local
)
3965 (dolist (entry list
)
3966 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
3967 (insert (car entry
) message
3968 (if (string= funcs
" ")
3973 (defun anything-c-simple-call-tree-functions-callers-init ()
3974 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
3977 (defun anything-c-simple-call-tree-candidates ()
3978 (with-current-buffer (anything-candidate-buffer)
3979 (split-string (buffer-string) "\n\n")))
3981 (defvar anything-c-simple-call-tree-related-functions nil
)
3982 (defvar anything-c-simple-call-tree-function-index
0)
3983 (defun anything-c-simple-call-tree-persistent-action (candidate)
3984 (unless (eq last-command
'anything-execute-persistent-action
)
3985 (setq anything-c-simple-call-tree-related-functions
3986 (delete "no functions."
3988 (replace-regexp-in-string " \\| is called by\\| calls "
3991 (setq anything-c-simple-call-tree-function-index -
1))
3992 (incf anything-c-simple-call-tree-function-index
)
3993 (anything-c-simple-call-tree-find-definition candidate
))
3995 (defun anything-c-simple-call-tree-find-definition (candidate)
3998 (nth (mod anything-c-simple-call-tree-function-index
3999 (length anything-c-simple-call-tree-related-functions
))
4000 anything-c-simple-call-tree-related-functions
))))
4002 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
4005 (defvar anything-c-source-simple-call-tree-callers-functions
4006 '((name .
"Function calls")
4007 (init . anything-c-simple-call-tree-callers-functions-init
)
4009 (candidates . anything-c-simple-call-tree-candidates
)
4010 (persistent-action . anything-c-simple-call-tree-persistent-action
)
4011 (persistent-help .
"Show function definitions by rotation")
4012 (action ("Find definition selected by persistent-action" .
4013 anything-c-simple-call-tree-find-definition
)))
4014 "Needs simple-call-tree.el.
4015 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4017 (defun anything-c-simple-call-tree-callers-functions-init ()
4018 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
4020 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
4022 ;;; Commands/Options with doc
4023 (defvar anything-c-auto-document-data nil
)
4024 (make-variable-buffer-local 'anything-c-auto-document-data
)
4025 (defvar anything-c-source-commands-and-options-in-file
4026 '((name .
"Commands/Options in file")
4028 .
(lambda (x) (format "Commands/Options in %s"
4029 (buffer-local-value 'buffer-file-name
4030 anything-current-buffer
))))
4031 (candidates . anything-command-and-options-candidates
)
4034 "List Commands and Options with doc. It needs auto-document.el .
4036 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
4038 (eval-when-compile (require 'auto-document nil t
))
4039 (defun anything-command-and-options-candidates ()
4040 (with-current-buffer anything-current-buffer
4041 (when (and (require 'auto-document nil t
)
4042 (eq major-mode
'emacs-lisp-mode
)
4043 (or (anything-current-buffer-is-modified)
4044 (not anything-c-auto-document-data
)))
4045 (or imenu--index-alist
(imenu--make-index-alist t
))
4046 (setq anything-c-auto-document-data
4047 (destructuring-bind (commands options
)
4048 (adoc-construct anything-current-buffer
)
4050 (loop for
(command . doc
) in commands
4051 for cmdname
= (symbol-name command
)
4054 (format "Command: %s\n %s"
4055 (propertize cmdname
'face font-lock-function-name-face
)
4056 (adoc-first-line doc
))
4057 (assoc cmdname imenu--index-alist
)))
4058 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
4059 for
(option doc default
) in options
4060 for optname
= (symbol-name option
)
4063 (format "Option: %s\n %s\n default = %s"
4064 (propertize optname
'face font-lock-variable-name-face
)
4065 (adoc-first-line doc
)
4066 (adoc-prin1-to-string default
))
4069 anything-c-auto-document-data
))
4071 ;; (anything 'anything-c-source-commands-and-options-in-file)
4073 ;;;; <Color and Face>
4075 (defvar anything-c-source-customize-face
4076 '((name .
"Customize Face")
4078 (unless (anything-candidate-buffer)
4079 (save-window-excursion (list-faces-display))
4080 (anything-candidate-buffer (get-buffer "*Faces*")))))
4081 (candidates-in-buffer)
4082 (get-line . buffer-substring
)
4083 (action .
(lambda (line)
4084 (customize-face (intern (car (split-string line
))))))
4085 (requires-pattern .
3))
4086 "See (info \"(emacs)Faces\")")
4087 ;; (anything 'anything-c-source-customize-face)
4090 (defvar anything-c-source-colors
4092 (init .
(lambda () (unless (anything-candidate-buffer)
4093 (save-window-excursion (list-colors-display))
4094 (anything-candidate-buffer (get-buffer "*Colors*")))))
4095 (candidates-in-buffer)
4096 (get-line . buffer-substring
)
4098 ("Copy Name" .
(lambda (candidate)
4099 (kill-new (anything-c-colors-get-name candidate
))))
4100 ("Copy RGB" .
(lambda (candidate)
4101 (kill-new (anything-c-colors-get-rgb candidate
))))
4102 ("Insert Name" .
(lambda (candidate)
4103 (with-current-buffer anything-current-buffer
4104 (insert (anything-c-colors-get-name candidate
)))))
4105 ("Insert RGB" .
(lambda (candidate)
4106 (with-current-buffer anything-current-buffer
4107 (insert (anything-c-colors-get-rgb candidate
))))))))
4108 ;; (anything 'anything-c-source-colors)
4110 (defun anything-c-colors-get-name (candidate)
4112 (replace-regexp-in-string
4115 (insert (capitalize candidate
))
4116 (goto-char (point-min))
4117 (search-forward-regexp "\\s-\\{2,\\}")
4118 (delete-region (point) (point-max))
4121 (defun anything-c-colors-get-rgb (candidate)
4123 (replace-regexp-in-string
4126 (insert (capitalize candidate
))
4127 (goto-char (point-max))
4128 (search-backward-regexp "\\s-\\{2,\\}")
4129 (delete-region (point) (point-min))
4132 ;;;; <Search Engine>
4133 ;;; Tracker desktop search
4134 (defvar anything-c-source-tracker-search
4135 '((name .
"Tracker Search")
4136 (candidates .
(lambda ()
4137 (start-process "tracker-search-process" nil
4141 (requires-pattern .
3)
4143 "Source for retrieving files matching the current input pattern
4144 with the tracker desktop search.")
4145 ;; (anything 'anything-c-source-tracker-search)
4147 ;;; Spotlight (MacOS X desktop search)
4148 (defvar anything-c-source-mac-spotlight
4151 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
4153 (requires-pattern .
3)
4155 "Source for retrieving files via Spotlight's command line
4157 ;; (anything 'anything-c-source-mac-spotlight)
4162 (defvar anything-c-source-kill-ring
4163 '((name .
"Kill Ring")
4164 (init .
(lambda () (anything-attrset 'last-command last-command
)))
4165 (candidates . anything-c-kill-ring-candidates
)
4166 (action . anything-c-kill-ring-action
)
4170 "Source for browse and insert contents of kill-ring.")
4172 (defun anything-c-kill-ring-candidates ()
4173 (loop for kill in kill-ring
4174 unless
(or (< (length kill
) anything-kill-ring-threshold
)
4175 (string-match "^[\\s\\t]+$" kill
))
4178 (defun anything-c-kill-ring-action (str)
4179 "Insert STR in `kill-ring' and set STR to the head.
4180 If this action is executed just after `yank',
4181 replace with STR as yanked string."
4182 (setq kill-ring
(delete str kill-ring
))
4183 (if (not (eq (anything-attr 'last-command
) 'yank
))
4184 (insert-for-yank str
)
4186 (let ((inhibit-read-only t
)
4187 (before (< (point) (mark t
))))
4189 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
4190 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
4191 (setq yank-undo-function nil
)
4192 (set-marker (mark-marker) (point) (current-buffer))
4193 (insert-for-yank str
)
4194 ;; Set the window start back where it was in the yank command,
4196 (set-window-start (selected-window) yank-window-start t
)
4198 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
4199 ;; It is cleaner to avoid activation, even though the command
4200 ;; loop would deactivate the mark because we inserted text.
4201 (goto-char (prog1 (mark t
)
4202 (set-marker (mark-marker) (point) (current-buffer)))))))
4205 ;; (anything 'anything-c-source-kill-ring)
4208 ;; DO NOT include these sources in `anything-sources' use
4209 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
4210 ;; `anything-all-mark-rings' instead.
4212 (defun anything-c-source-mark-ring-candidates ()
4213 (flet ((get-marks (pos)
4217 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
4218 (when (string= "" line
)
4219 (setq line
"<EMPTY LINE>"))
4220 (format "%7d: %s" (line-number-at-pos) line
)))))
4221 (with-current-buffer anything-current-buffer
4223 with marks
= (cons (mark-marker) mark-ring
)
4226 for m
= (get-marks i
)
4227 unless
(member m recip
)
4228 collect m into recip
4229 finally return recip
))))
4231 (defvar anything-mark-ring-cache nil
)
4232 (defvar anything-c-source-mark-ring
4233 '((name .
"mark-ring")
4235 (setq anything-mark-ring-cache
4236 (ignore-errors (anything-c-source-mark-ring-candidates)))))
4237 (candidates .
(lambda ()
4238 (anything-aif anything-mark-ring-cache
4240 (action .
(("Goto line"
4241 .
(lambda (candidate)
4242 (anything-goto-line (string-to-number candidate
))))))
4243 (persistent-action .
(lambda (candidate)
4244 (anything-goto-line (string-to-number candidate
))
4245 (anything-match-line-color-current-line)))
4246 (persistent-help .
"Show this line")))
4248 ;; (anything 'anything-c-source-mark-ring)
4251 (defun anything-mark-ring ()
4252 "Preconfigured `anything' for `anything-c-source-mark-ring'."
4254 (anything 'anything-c-source-mark-ring
))
4256 ;;; Global-mark-ring
4257 (defvar anything-c-source-global-mark-ring
4258 '((name .
"global-mark-ring")
4259 (candidates . anything-c-source-global-mark-ring-candidates
)
4260 (action .
(("Goto line"
4261 .
(lambda (candidate)
4262 (let ((items (split-string candidate
":")))
4263 (switch-to-buffer (second items
))
4264 (anything-goto-line (string-to-number (car items
))))))))
4265 (persistent-action .
(lambda (candidate)
4266 (let ((items (split-string candidate
":")))
4267 (switch-to-buffer (second items
))
4268 (anything-goto-line (string-to-number (car items
)))
4269 (anything-match-line-color-current-line))))
4270 (persistent-help .
"Show this line")))
4272 (defun anything-c-source-global-mark-ring-candidates ()
4274 (with-current-buffer (marker-buffer m
)
4278 (if (string= "" line
)
4279 (setq line
"<EMPTY LINE>")
4280 (setq line
(car (split-string (thing-at-point 'line
)
4282 (format "%7d:%s: %s"
4283 (line-number-at-pos) (marker-buffer m
) line
)))))
4285 with marks
= global-mark-ring
4288 for gm
= (unless (or (string-match
4289 "^ " (format "%s" (marker-buffer i
)))
4290 (null (marker-buffer i
)))
4292 when
(and gm
(not (member gm recip
)))
4293 collect gm into recip
4294 finally return recip
)))
4296 ;; (anything 'anything-c-source-global-mark-ring)
4299 (defun anything-global-mark-ring ()
4300 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4302 (anything 'anything-c-source-global-mark-ring
))
4305 (defun anything-all-mark-rings ()
4306 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4307 `anything-c-source-mark-ring'."
4309 (anything '(anything-c-source-global-mark-ring
4310 anything-c-source-mark-ring
)))
4313 ;;; Insert from register
4314 (defvar anything-c-source-register
4315 '((name .
"Registers")
4316 (candidates . anything-c-register-candidates
)
4317 (action-transformer . anything-c-register-action-transformer
)
4320 "See (info \"(emacs)Registers\")")
4322 (defun anything-c-register-candidates ()
4323 "Collecting register contents and appropriate commands."
4324 (loop for
(char . val
) in register-alist
4325 for key
= (single-key-description char
)
4326 for string-actions
=
4329 (list (int-to-string val
)
4331 'increment-register
))
4333 (let ((buf (marker-buffer val
)))
4335 (list "a marker in no buffer")
4337 "a buffer position:"
4340 (int-to-string (marker-position val
)))
4342 'insert-register
))))
4343 ((and (consp val
) (window-configuration-p (car val
)))
4344 (list "window configuration."
4346 ((and (consp val
) (frame-configuration-p (car val
)))
4347 (list "frame configuration."
4349 ((and (consp val
) (eq (car val
) 'file
))
4350 (list (concat "file:"
4351 (prin1-to-string (cdr val
))
4354 ((and (consp val
) (eq (car val
) 'file-query
))
4355 (list (concat "file:a file-query reference: file "
4358 (int-to-string (car (cdr (cdr val
))))
4362 (let ((lines (format "%4d" (length val
))))
4363 (list (format "%s: %s\n" lines
4364 (truncate-string-to-width
4365 (mapconcat 'identity
(list (car val
))
4366 ;; (mapconcat (lambda (y) y) val
4367 "^J") (- (window-width) 15)))
4370 (list ;; without properties
4371 (substring-no-properties val
)
4374 'prepend-to-register
))
4377 collect
(cons (format "register %3s: %s" key
(car string-actions
))
4378 (cons char
(cdr string-actions
)))))
4380 (defun anything-c-register-action-transformer (actions register-and-functions
)
4381 "Decide actions by the contents of register."
4382 (loop with func-actions
=
4385 (lambda (c) (insert-register (car c
))))
4387 "Jump to Register" .
4388 (lambda (c) (jump-to-register (car c
))))
4390 "Append Region to Register" .
4391 (lambda (c) (append-to-register
4392 (car c
) (region-beginning) (region-end))))
4393 (prepend-to-register
4394 "Prepend Region to Register" .
4395 (lambda (c) (prepend-to-register
4396 (car c
) (region-beginning) (region-end))))
4398 "Increment Prefix Arg to Register" .
4399 (lambda (c) (increment-register
4400 anything-current-prefix-arg
(car c
)))))
4401 for func in
(cdr register-and-functions
)
4402 for cell
= (assq func func-actions
)
4404 collect
(cdr cell
)))
4406 ;; (anything 'anything-c-source-register)
4408 ;;;; <Headline Extraction>
4409 (defvar anything-c-source-fixme
4410 '((name .
"TODO/FIXME/DRY comments")
4411 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4414 "Show TODO/FIXME/DRY comments in current file.")
4415 ;; (anything 'anything-c-source-fixme)
4417 (defvar anything-c-source-rd-headline
4418 '((name .
"RD HeadLine")
4419 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4420 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
4426 http://en.wikipedia.org/wiki/Ruby_Document_format")
4427 ;; (anything 'anything-c-source-rd-headline)
4429 (defvar anything-c-source-oddmuse-headline
4430 '((name .
"Oddmuse HeadLine")
4431 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4432 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4433 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
4436 "Show Oddmuse headlines, such as EmacsWiki.")
4437 ;; (anything 'anything-c-source-oddmuse-headline)
4439 (defvar anything-c-source-emacs-source-defun
4440 '((name .
"Emacs Source DEFUN")
4441 (headline .
"DEFUN\\|DEFVAR")
4442 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
4443 (or buffer-file-name
""))))
4444 "Show DEFUN/DEFVAR in Emacs C source file.")
4445 ;; (anything 'anything-c-source-emacs-source-defun)
4447 (defvar anything-c-source-emacs-lisp-expectations
4448 '((name .
"Emacs Lisp Expectations")
4449 (headline .
"(desc[ ]\\|(expectations")
4450 (condition .
(eq major-mode
'emacs-lisp-mode
)))
4451 "Show descriptions (desc) in Emacs Lisp Expectations.
4453 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4454 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4456 (defvar anything-c-source-emacs-lisp-toplevels
4457 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4458 (headline .
"^(\\|(@\\*\\|^;;;;")
4459 (get-line . buffer-substring
)
4460 (condition .
(eq major-mode
'emacs-lisp-mode
))
4462 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4463 linkd.el is optional because linkd stars are extracted by regexp.
4464 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4465 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4467 (defvar anything-c-source-org-headline
4468 '((name .
"Org HeadLine")
4470 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4471 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4472 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4473 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4474 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4475 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4476 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4477 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4478 (condition .
(eq major-mode
'org-mode
))
4481 (persistent-action .
(lambda (elm)
4482 (anything-c-action-line-goto elm
)
4485 .
(lambda (actions candidate
)
4486 '(("Go to Line" . anything-c-action-line-goto
)
4487 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline
)))))
4488 "Show Org headlines.
4489 org-mode is very very much extended text-mode/outline-mode.
4491 See (find-library \"org.el\")
4492 See http://orgmode.org for the latest version.")
4494 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4497 (anything-goto-line (car lineno-and-content
))
4498 (and (looking-at org-complex-heading-regexp
)
4499 (org-make-link-string (concat "*" (match-string 4)))))))
4501 ;; (anything 'anything-c-source-org-headline)
4503 ;;; Anything yaoddmuse
4504 ;; Be sure to have yaoddmuse.el installed
4505 ;; install-elisp may be required if you want to install elisp file from here.
4506 (defvar anything-yaoddmuse-use-cache-file nil
)
4507 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
4508 (defvar anything-c-yaoddmuse-ew-cache nil
)
4509 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4510 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
4511 (candidates .
(lambda ()
4512 (if anything-yaoddmuse-use-cache-file
4514 (unless anything-c-yaoddmuse-ew-cache
4515 (load anything-c-yaoddmuse-cache-file
)
4516 (setq anything-c-yaoddmuse-ew-cache
4517 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
4518 anything-c-yaoddmuse-ew-cache
)
4519 (yaoddmuse-update-pagename t
)
4520 (gethash "EmacsWiki" yaoddmuse-pages-hash
))))
4521 (action .
(("Edit page" .
(lambda (candidate)
4522 (yaoddmuse-edit "EmacsWiki" candidate
)))
4523 ("Browse page" .
(lambda (candidate)
4524 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
4525 ("Browse page other window" .
(lambda (candidate)
4527 (split-window-vertically))
4528 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
4529 ("Browse diff" .
(lambda (candidate)
4530 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
4531 ("Copy URL" .
(lambda (candidate)
4532 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
4533 (message "Have copy page %s's URL to yank." candidate
)))
4534 ("Create page" .
(lambda (candidate)
4535 (yaoddmuse-edit "EmacsWiki" anything-input
)))
4536 ("Update cache" .
(lambda (candidate)
4537 (if anything-yaoddmuse-use-cache-file
4539 (anything-yaoddmuse-cache-pages t
)
4540 (setq anything-c-yaoddmuse-ew-cache
4541 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
4542 (yaoddmuse-update-pagename))))))
4543 (action-transformer anything-c-yaoddmuse-action-transformer
))
4544 "Needs yaoddmuse.el.
4546 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4548 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
4550 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
4551 '((name .
"Yaoddmuse Post library (EmacsWiki)")
4552 (init .
(anything-yaoddmuse-init))
4553 (candidates-in-buffer)
4554 (action .
(("Post library and Browse" .
(lambda (candidate)
4555 (yaoddmuse-post-file (find-library-name candidate
)
4557 (file-name-nondirectory (find-library-name candidate
))
4559 ("Post library" .
(lambda (candidate)
4560 (yaoddmuse-post-file (find-library-name candidate
)
4562 (file-name-nondirectory (find-library-name candidate
))))))))
4563 "Needs yaoddmuse.el.
4565 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
4567 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
4569 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
4570 "Allow the use of `install-elisp' only on elisp files."
4571 (if (string-match "\.el$" candidate
)
4572 (append actions
'(("Install Elisp" .
(lambda (elm)
4573 (install-elisp-from-emacswiki elm
)))))
4577 (defun anything-yaoddmuse-cache-pages (&optional load
)
4578 "Fetch the list of files on emacswiki and create cache file.
4579 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
4581 (yaoddmuse-update-pagename)
4583 (find-file anything-c-yaoddmuse-cache-file
)
4585 (insert "(puthash \"EmacsWiki\" '(")
4586 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
4588 (insert (concat "(\"" (car i
) "\") ")))
4589 (insert ") yaoddmuse-pages-hash)\n")
4591 (kill-buffer (current-buffer))
4592 (when (or current-prefix-arg
4594 (load anything-c-yaoddmuse-cache-file
))))
4597 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
4598 "Preconfigured `anything' to edit or view EmacsWiki page.
4602 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4604 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
4607 (defun anything-yaoddmuse-emacswiki-post-library ()
4608 "Preconfigured `anything' to post library to EmacsWiki.
4612 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
4614 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
4616 (defun anything-yaoddmuse-init ()
4617 "Init anything buffer status."
4618 (let ((anything-buffer (anything-candidate-buffer 'global
))
4619 (library-list (yaoddmuse-get-library-list)))
4620 (with-current-buffer anything-buffer
4621 ;; Insert library name.
4622 (dolist (library library-list
)
4623 (insert (format "%s\n" library
)))
4625 (sort-lines nil
(point-min) (point-max)))))
4628 (defvar anything-c-source-eev-anchor
4629 '((name .
"Anchors")
4633 (with-current-buffer anything-current-buffer
4634 (loop initially
(goto-char (point-min))
4635 while
(re-search-forward (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
4636 for anchor
= (match-string-no-properties 1)
4637 collect
(cons (format "%5d:%s"
4638 (line-number-at-pos (match-beginning 0))
4639 (format ee-anchor-format anchor
)) anchor
))))))
4640 (persistent-action .
(lambda (item)
4642 (anything-match-line-color-current-line)))
4643 (persistent-help .
"Show this entry")
4644 (action .
(("Goto link" . ee-to
)))))
4645 ;; (anything 'anything-c-source-eev-anchor)
4649 (defvar anything-c-source-org-keywords
4650 '((name .
"Org Keywords")
4651 (init . anything-c-org-keywords-init
)
4652 (candidates . anything-c-org-keywords-candidates
)
4653 (action . anything-c-org-keywords-insert
)
4654 (persistent-action . anything-c-org-keywords-show-help
)
4655 (persistent-help .
"Show an example and info page to describe this keyword.")
4658 ;; (anything 'anything-c-source-org-keywords)
4659 (defvar anything-c-org-keywords-info-location
4660 '(("#+TITLE:" .
"(org)Export options")
4661 ("#+AUTHOR:" .
"(org)Export options")
4662 ("#+DATE:" .
"(org)Export options")
4663 ("#+EMAIL:" .
"(org)Export options")
4664 ("#+DESCRIPTION:" .
"(org)Export options")
4665 ("#+KEYWORDS:" .
"(org)Export options")
4666 ("#+LANGUAGE:" .
"(org)Export options")
4667 ("#+TEXT:" .
"(org)Export options")
4668 ("#+TEXT:" .
"(org)Export options")
4669 ("#+OPTIONS:" .
"(org)Export options")
4670 ("#+BIND:" .
"(org)Export options")
4671 ("#+LINK_UP:" .
"(org)Export options")
4672 ("#+LINK_HOME:" .
"(org)Export options")
4673 ("#+LATEX_HEADER:" .
"(org)Export options")
4674 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
4675 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
4676 ("#+INFOJS_OPT" .
"(org)Javascript support")
4677 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
4678 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
4679 ("#+ORGTBL" .
"(org)Radio tables")
4680 ("#+HTML:" .
"(org)Quoting HTML tags")
4681 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
4682 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
4683 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
4684 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
4685 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
4686 ("#+BEGIN_SRC" .
"(org)Literal examples")
4687 ("#+CAPTION" .
"(org)Tables in HTML export")
4688 ("#+LABEL" .
"(org)Tables in LaTeX export")
4689 ("#+ATTR_HTML" .
"(org)Links")
4690 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
4692 (defun anything-c-org-keywords-init ()
4693 (unless (anything-attr 'keywords-examples
)
4695 (anything-attrset 'keywords-examples
4699 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
4700 (cons (match-string 2 x
) (match-string 1 x
)))
4701 (org-split-string (org-get-current-options) "\n"))
4702 (mapcar 'list org-additional-option-like-keywords
)))
4703 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
4705 (defun anything-c-org-keywords-candidates ()
4706 (and (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
4707 (anything-attr 'keywords
)))
4709 (defun anything-c-org-keywords-insert (keyword)
4710 (cond ((string-match "BEGIN" keyword
)
4711 (insert "#+" keyword
" ")
4713 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword
) "\n")))
4715 (insert "#+" keyword
" "))))
4717 (defun anything-c-org-keywords-show-help (keyword)
4718 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
4719 "(org)In-buffer settings"))
4720 (search-forward (concat "#+" keyword
) nil t
)
4721 (anything-persistent-highlight-point)
4722 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
4726 (defvar anything-c-source-picklist
4727 '((name .
"Picklist")
4728 (candidates .
(lambda () (mapcar 'car picklist-list
)))
4730 ;; (anything 'anything-c-source-picklist)
4733 (defvar bbdb-records
)
4734 (defvar bbdb-buffer-name
)
4735 (declare-function bbdb
"ext:bbdb-com")
4736 (declare-function bbdb-current-record
"ext:bbdb-com")
4737 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
4738 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
4739 (declare-function bbdb-current-record
"ext:bbdb-com")
4740 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
4741 (declare-function bbdb-records
"ext:bbdb-com"
4742 (&optional dont-check-disk already-in-db-buffer
))
4744 (defun anything-c-bbdb-candidates ()
4745 "Return a list of all names in the bbdb database. The format
4746 is \"Firstname Lastname\"."
4747 (mapcar (lambda (bbdb-record)
4748 (replace-regexp-in-string
4750 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
4753 (defun anything-c-bbdb-create-contact (actions candidate
)
4754 "Action transformer that returns only an entry to add the
4755 current `anything-pattern' as new contact. All other actions are
4757 (if (string= candidate
"*Add to contacts*")
4758 '(("Add to contacts" .
(lambda (actions)
4759 (bbdb-create-internal
4760 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
4761 (read-from-minibuffer "Company: ")
4762 (read-from-minibuffer "Email: ")
4765 (read-from-minibuffer "Note: ")))))
4768 (defun anything-c-bbdb-get-record (candidate)
4769 "Return record that match CANDIDATE."
4770 (bbdb candidate nil
)
4771 (set-buffer "*BBDB*")
4772 (bbdb-current-record))
4774 (defvar anything-c-bbdb-name nil
4775 "Only for internal use.")
4777 (defvar anything-c-source-bbdb
4779 (candidates . anything-c-bbdb-candidates
)
4780 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
4781 ("View person's data" . anything-c-bbdb-view-person-action
))
4782 (filtered-candidate-transformer .
(lambda (candidates source
)
4783 (setq anything-c-bbdb-name anything-pattern
)
4784 (if (not candidates
)
4785 (list "*Add to contacts*")
4787 (action-transformer .
(lambda (actions candidate
)
4788 (anything-c-bbdb-create-contact actions candidate
))))
4791 http://bbdb.sourceforge.net/")
4792 ;; (anything 'anything-c-source-bbdb)
4794 (defun anything-c-bbdb-view-person-action (candidate)
4795 "View BBDB data of single CANDIDATE or marked candidates."
4796 (anything-aif (anything-marked-candidates)
4797 (let ((bbdb-append-records (length it
)))
4799 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
4800 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
4802 (defun anything-c-bbdb-collect-mail-addresses ()
4803 "Return a list of all mail addresses of records in bbdb buffer."
4804 (with-current-buffer bbdb-buffer-name
4805 (loop for i in bbdb-records
4806 if
(bbdb-record-net (car i
))
4807 collect
(bbdb-dwim-net-address (car i
)))))
4809 (defun anything-c-bbdb-compose-mail (candidate)
4810 "Compose a mail with all records of bbdb buffer."
4811 (anything-c-bbdb-view-person-action candidate
)
4812 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
4813 (address-str (mapconcat 'identity address-list
",\n ")))
4814 (compose-mail address-str
)))
4816 ;;; Evaluation Result
4817 (defvar anything-c-source-evaluation-result
4818 '((name .
"Evaluation Result")
4821 (filtered-candidate-transformer .
(lambda (candidates source
)
4824 (with-current-buffer anything-current-buffer
4826 (eval (read anything-pattern
))))
4828 (action ("Copy result to kill-ring" .
(lambda (candidate)
4829 (with-current-buffer anything-buffer
4830 (let ((end (save-excursion
4831 (goto-char (point-max))
4832 (search-backward "\n")
4834 (kill-region (point) end
))))))))
4835 ;; (anything 'anything-c-source-evaluation-result)
4838 (defun anything-eval-expression (arg)
4839 "Preconfigured anything for `anything-c-source-evaluation-result'."
4841 (anything 'anything-c-source-evaluation-result
(when arg
(thing-at-point 'sexp
))
4842 nil nil nil
"*anything eval*"))
4845 (defun anything-eval-expression-with-eldoc ()
4846 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
4849 (let ((timer (run-with-idle-timer eldoc-idle-delay
4850 'repeat
'anything-eldoc-show-in-eval
)))
4852 (call-interactively 'anything-eval-expression
)
4853 (cancel-timer timer
)))
4854 (call-interactively 'anything-eval-expression
)))
4856 (defun anything-eldoc-show-in-eval ()
4857 "Return eldoc in a tooltip for current minibuffer input."
4858 (let* ((str-all (minibuffer-completion-contents))
4862 (goto-char (point-max))
4863 (unless (looking-back ")\\|\"") (forward-char -
1))
4864 (eldoc-current-symbol))))
4865 (doc (or (eldoc-get-var-docstring sym
)
4866 (eldoc-get-fnsym-args-string
4867 (car (eldoc-fnsym-in-current-sexp))))))
4868 (when doc
(tooltip-show doc
))))
4870 ;;; Calculation Result
4871 (defvar anything-c-source-calculation-result
4872 '((name .
"Calculation Result")
4874 (filtered-candidate-transformer .
(lambda (candidates source
)
4877 (calc-eval anything-pattern
)
4879 (action ("Copy result to kill-ring" . kill-new
))))
4880 ;; (anything 'anything-c-source-calculation-result)
4882 ;;; Google Suggestions
4883 (defvar anything-gg-sug-lgh-flag
0)
4884 (defun anything-c-google-suggest-fetch (input)
4885 "Fetch suggestions for INPUT from XML buffer.
4886 Return an alist with elements like (data . number_results)."
4887 (let ((request (concat anything-c-google-suggest-url
4888 (url-hexify-string input
))))
4891 with result-alist
= (xml-get-children
4892 (car (xml-parse-region (point-min) (point-max)))
4893 'CompleteSuggestion
)
4894 for i in result-alist
4895 for data
= (cdr (caadr (assoc 'suggestion i
)))
4896 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
4897 for ldata
= (length data
)
4899 (when (> ldata anything-gg-sug-lgh-flag
)
4900 (setq anything-gg-sug-lgh-flag ldata
))
4901 collect
(cons data nqueries
) into cont
4902 finally return cont
)))
4903 (if anything-google-suggest-use-curl-p
4905 (call-process "curl" nil t nil request
)
4907 (with-current-buffer
4908 (url-retrieve-synchronously request
)
4912 (defun anything-c-google-suggest-set-candidates ()
4913 "Set candidates with result and number of google results found."
4914 (let ((suggestions (anything-c-google-suggest-fetch anything-input
)))
4915 (setq suggestions
(loop for i in suggestions
4916 for interval
= (- anything-gg-sug-lgh-flag
(length (car i
)))
4917 for elm
= (concat (car i
)
4918 (make-string (+ 2 interval
) ?
)
4919 "(" (cdr i
) " results)")
4920 collect
(cons elm
(car i
))))
4921 (if (some (lambda (data) (equal (cdr data
) anything-input
)) suggestions
)
4923 ;; if there is no suggestion exactly matching the input then
4924 ;; prepend a Search on Google item to the list
4927 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
4928 anything-input
))))))
4931 (defun anything-c-google-suggest-action (candidate)
4932 "Default action to jump to a google suggested candidate."
4933 (anything-c-browse-url (concat anything-c-google-suggest-search-url
4934 (url-hexify-string candidate
))))
4937 (defvar anything-c-source-google-suggest
4938 '((name .
"Google Suggest")
4939 (candidates . anything-c-google-suggest-set-candidates
)
4940 (action .
(("Google Search" . anything-c-google-suggest-action
)))
4942 (requires-pattern .
3)
4945 ;; (anything 'anything-c-source-google-suggest)
4947 ;;; Yahoo suggestions
4949 (defun anything-c-yahoo-suggest-fetch (input)
4950 "Fetch Yahoo suggestions for INPUT from XML buffer.
4951 Return an alist with elements like (data . number_results)."
4952 (let ((request (concat anything-c-yahoo-suggest-url
4953 (url-hexify-string input
))))
4956 with result-alist
= (xml-get-children
4957 (car (xml-parse-region (point-min) (point-max)))
4959 for i in result-alist
4960 collect
(caddr i
))))
4961 (with-current-buffer
4962 (url-retrieve-synchronously request
)
4965 (defun anything-c-yahoo-suggest-set-candidates ()
4966 "Set candidates with Yahoo results found."
4967 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
4971 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
4972 anything-input
))))))
4974 (defun anything-c-yahoo-suggest-action (candidate)
4975 "Default action to jump to a Yahoo suggested candidate."
4976 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
4977 (url-hexify-string candidate
))))
4979 (defvar anything-c-source-yahoo-suggest
4980 '((name .
"Yahoo Suggest")
4981 (candidates . anything-c-yahoo-suggest-set-candidates
)
4982 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
4984 (requires-pattern .
3)
4987 ;; (anything 'anything-c-source-yahoo-suggest)
4990 ;;; Need external program surfraw.
4991 ;;; http://surfraw.alioth.debian.org/
4993 (require 'browse-url
)
4994 (defvar w3m-command nil
)
4995 (defvar anything-c-home-url
"http://www.google.fr"
4996 "*Default url to use as home url.")
4998 (defvar anything-browse-url-default-browser-alist
4999 `((,w3m-command . w3m-browse-url
)
5000 (,browse-url-firefox-program . browse-url-firefox
)
5001 (,browse-url-kde-program . browse-url-kde
)
5002 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
5003 (,browse-url-mozilla-program . browse-url-mozilla
)
5004 (,browse-url-galeon-program . browse-url-galeon
)
5005 (,browse-url-netscape-program . browse-url-netscape
)
5006 (,browse-url-mosaic-program . browse-url-mosaic
)
5007 (,browse-url-xterm-program . browse-url-text-xterm
))
5008 "*Alist of (executable . function) to try to find a suitable url browser.")
5010 (defun anything-browse-url-default-browser (url &rest args
)
5011 "Find a suitable browser and ask it to load URL."
5012 (let ((default-browser (loop
5013 for i in anything-browse-url-default-browser-alist
5014 when
(and (car i
) (executable-find (car i
))) return
(cdr i
))))
5016 (apply default-browser url args
)
5017 (error "No usable browser found"))))
5019 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
5020 "Default command to browse URL."
5021 (if browse-url-browser-function
5023 (anything-browse-url-default-browser url
)))
5025 (defun anything-c-build-elvi-list ()
5026 "Return list of all engines and descriptions handled by surfraw."
5029 (call-process "surfraw" nil t nil
5031 (split-string (buffer-string) "\n"))))
5033 (defvar anything-surfraw-engines-history nil
)
5035 (defun anything-surfraw (pattern engine
)
5036 "Preconfigured `anything' to search PATTERN with search ENGINE."
5037 (interactive (list (read-string "SearchFor: ")
5040 (anything-c-build-elvi-list)
5042 :name
"Surfraw Search Engines"
5043 :history anything-surfraw-engines-history
)))
5044 (let* ((engine-nodesc (car (split-string engine
)))
5045 (url (with-temp-buffer
5046 (apply 'call-process
"surfraw" nil t nil
5047 (list engine-nodesc
"-p" pattern
))
5048 (replace-regexp-in-string
5049 "\n" "" (buffer-string)))))
5050 (if (string= engine-nodesc
"W")
5051 (anything-c-browse-url)
5052 (anything-c-browse-url url
)
5053 (setq anything-surfraw-engines-history
5054 (cons engine
(delete engine anything-surfraw-engines-history
))))))
5059 (defun anything-emms-stream-edit-bookmark (elm)
5060 "Change the information of current emms-stream bookmark from anything."
5062 (let* ((cur-buf anything-current-buffer
)
5063 (bookmark (assoc elm emms-stream-list
))
5064 (name (read-from-minibuffer "Description: "
5066 (url (read-from-minibuffer "URL: "
5068 (fd (read-from-minibuffer "Feed Descriptor: "
5069 (int-to-string (nth 2 bookmark
))))
5070 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
5071 (format "%s" (car (last bookmark
))))))
5074 (when (re-search-forward (concat "^" name
) nil t
)
5076 (emms-stream-delete-bookmark)
5077 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
5078 (emms-stream-save-bookmarks-file)
5080 (switch-to-buffer cur-buf
)))))
5082 (defun anything-emms-stream-delete-bookmark (elm)
5083 "Delete an emms-stream bookmark from anything."
5085 (let* ((cur-buf anything-current-buffer
)
5086 (bookmark (assoc elm emms-stream-list
))
5087 (name (nth 0 bookmark
)))
5090 (when (re-search-forward (concat "^" name
) nil t
)
5092 (emms-stream-delete-bookmark)
5093 (emms-stream-save-bookmarks-file)
5095 (switch-to-buffer cur-buf
)))))
5097 (defvar anything-c-source-emms-streams
5098 '((name .
"Emms Streams")
5100 (emms-stream-init)))
5101 (candidates .
(lambda ()
5102 (mapcar 'car emms-stream-list
)))
5103 (action .
(("Play" .
(lambda (elm)
5104 (let* ((stream (assoc elm emms-stream-list
))
5105 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
5106 (url (second stream
)))
5108 ("Delete" . anything-emms-stream-delete-bookmark
)
5109 ("Edit" . anything-emms-stream-edit-bookmark
)))
5110 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
5111 ;; (anything 'anything-c-source-emms-streams)
5113 ;; Don't forget to set `emms-source-file-default-directory'
5114 (defvar anything-c-source-emms-dired
5115 '((name .
"Music Directory")
5116 (candidates .
(lambda ()
5117 (cddr (directory-files emms-source-file-default-directory
))))
5119 (("Play Directory" .
(lambda (item)
5120 (emms-play-directory
5123 emms-source-file-default-directory
))))
5124 ("Open dired in file's directory" .
(lambda (item)
5125 (anything-c-open-dired
5128 emms-source-file-default-directory
))))))
5129 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
5130 ;; (anything 'anything-c-source-emms-dired)
5132 (defface anything-emms-playlist
5133 '((t (:foreground
"Springgreen4" :underline t
)))
5134 "*Face used for tracks in current emms playlist."
5137 (defun anything-c-emms-files-modifier (candidates)
5138 (let ((current-playlist (with-current-emms-playlist
5140 with cur-list
= (emms-playlist-tracks-in-region
5141 (point-min) (point-max))
5143 collect
(assoc-default 'info-file i
)))))
5144 (loop for i in candidates
5145 if
(member i current-playlist
)
5146 collect
(propertize i
'face
'anything-emms-playlist
) into lis
5147 else collect i into lis finally return lis
)))
5149 (defun anything-c-emms-play-current-playlist ()
5150 "Play current playlist."
5151 (with-current-emms-playlist
5152 (emms-playlist-first)
5153 (emms-playlist-mode-play-smart)))
5155 (defvar anything-c-source-emms-files
5156 '((name .
"Emms files")
5157 (candidates .
(lambda ()
5158 (loop for v being the hash-values in emms-cache-db
5159 for name
= (assoc-default 'name v
)
5160 unless
(string-match "^http:" name
) collect name
)))
5161 (candidate-transformer . anything-c-emms-files-modifier
)
5162 (action .
(("Play file" . emms-play-file
)
5163 ("Add to Playlist and play"
5164 .
(lambda (candidate)
5166 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
5167 (unless emms-player-playing-p
5168 (anything-c-emms-play-current-playlist))))))))
5170 ;; (anything 'anything-c-source-emms-files)
5172 ;;; Jabber Contacts (jabber.el)
5173 (defun anything-c-jabber-online-contacts ()
5174 "List online Jabber contacts."
5177 (dolist (item (jabber-concat-rosters) jids
)
5178 (when (get item
'connected
)
5179 (push (if (get item
'name
)
5180 (cons (get item
'name
) item
)
5181 (cons (symbol-name item
) item
)) jids
))))))
5183 (defvar anything-c-source-jabber-contacts
5184 '((name .
"Jabber Contacts")
5185 (init .
(lambda () (require 'jabber
)))
5186 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
5187 (action .
(lambda (x)
5189 (jabber-read-account)
5191 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
5192 ;; (anything 'anything-c-source-jabber-contacts)
5196 (defvar anything-source-select-buffer
"*anything source select*")
5197 (defvar anything-c-source-call-source
5198 `((name .
"Call anything source")
5199 (candidate-number-limit)
5200 (candidates .
(lambda ()
5201 (loop for vname in
(all-completions "anything-c-source-" obarray
)
5202 for var
= (intern vname
)
5203 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
5204 if name collect
(cons (format "%s `%s'"
5205 name
(propertize vname
'face
'font-lock-variable-name-face
))
5207 (action .
(("Invoke anything with selected source" .
5209 (setq anything-candidate-number-limit
9999)
5210 (anything candidate nil nil nil nil
5211 anything-source-select-buffer
)))
5212 ("Describe variable" . describe-variable
)
5213 ("Find variable" . find-variable
)))
5214 (persistent-action . describe-variable
)
5215 (persistent-help .
"Show description of this source")))
5216 ;; (anything 'anything-c-source-call-source)
5219 (defun anything-call-source ()
5220 "Preconfigured `anything' to call anything source."
5222 (anything 'anything-c-source-call-source nil nil nil nil
5223 anything-source-select-buffer
))
5225 (defun anything-call-source-from-anything ()
5226 "Call anything source within `anything' session."
5228 (setq anything-input-idle-delay
0)
5229 (anything-set-sources '(anything-c-source-call-source)))
5231 ;;; Execute Preconfigured anything.
5232 (defvar anything-c-source-anything-commands
5233 '((name .
"Preconfigured Anything")
5234 (candidates . anything-c-anything-commands-candidates
)
5236 (candidate-number-limit)))
5237 ;; (anything 'anything-c-source-anything-commands)
5239 (defun anything-c-anything-commands-candidates ()
5240 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
5241 collect
(cons (if (where-is-internal cmd nil t
)
5242 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
5243 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
5247 (defun anything-execute-anything-command ()
5248 "Preconfigured `anything' to execute preconfigured `anything'."
5250 (anything-other-buffer 'anything-c-source-anything-commands
5251 "*anything commands*"))
5254 (defun anything-c-occur-init ()
5255 (anything-candidate-buffer anything-current-buffer
))
5257 (defun anything-c-occur-get-line (s e
)
5258 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
5260 (defvar anything-c-source-occur
5262 (init . anything-c-occur-init
)
5263 (candidates-in-buffer)
5265 (get-line . anything-c-occur-get-line
)
5268 (requires-pattern .
1)
5271 ;; (anything 'anything-c-source-occur)
5273 ;;; Anything browse code.
5274 (defun anything-c-browse-code-get-line (beg end
)
5275 "Select line if it match the regexp corresponding to current `major-mode'.
5276 Line is parsed for BEG position to END position."
5277 (let ((str-line (buffer-substring beg end
))
5278 (regexp (assoc-default major-mode
5279 anything-c-browse-code-regexp-alist
))
5280 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
5281 (when (and regexp
(string-match regexp str-line
))
5282 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
5285 (defvar anything-c-source-browse-code
5286 '((name .
"Browse code")
5288 (anything-candidate-buffer anything-current-buffer
)
5289 (with-current-buffer anything-current-buffer
5290 (jit-lock-fontify-now))))
5291 (candidates-in-buffer)
5292 (get-line . anything-c-browse-code-get-line
)
5296 ;; Do many actions for input
5297 (defvar anything-c-source-create
5301 (action-transformer . anything-create--actions
))
5302 "Do many create actions from `anything-pattern'.
5303 See also `anything-create--actions'.")
5304 ;; (anything 'anything-c-source-create)
5306 (defun anything-create-from-anything ()
5307 "Run `anything-create' from `anything' as a fallback."
5309 (anything-run-after-quit 'anything-create nil anything-pattern
))
5312 (defun anything-create (&optional string initial-input
)
5313 "Preconfigured `anything' to do many create actions from STRING.
5314 See also `anything-create--actions'."
5316 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
5317 (anything '(((name .
"Anything Create")
5318 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
5319 (candidates . anything-create--actions
)
5320 (candidate-number-limit)
5321 (action .
(lambda (func) (funcall func string
)))))))
5323 (defun anything-create--actions (&rest ignored
)
5324 "Default actions for `anything-create' / `anything-c-source-create'."
5326 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
5327 (append anything-create--actions-private
5328 '(("find-file" . find-file
)
5329 ("find-file other window" . find-file-other-window
)
5330 ("New buffer" . switch-to-buffer
)
5331 ("New buffer other window" . switch-to-buffer-other-window
)
5332 ("Bookmark Set" . bookmark-set
)
5334 (lambda (x) (set-register (read-char "Register: ") x
)))
5335 ("Insert Linkd star" . linkd-insert-star
)
5336 ("Insert Linkd Tag" . linkd-insert-tag
)
5337 ("Insert Linkd Link" . linkd-insert-link
)
5338 ("Insert Linkd Lisp" . linkd-insert-lisp
)
5339 ("Insert Linkd Wiki" . linkd-insert-wiki
)
5340 ("Google Search" . google
)))))
5342 ;; Minibuffer History
5343 (defvar anything-c-source-minibuffer-history
5344 '((name .
"Minibuffer History")
5345 (header-name .
(lambda (name) (format "%s (%s)" name minibuffer-history-variable
)))
5346 (candidates .
(lambda () (let ((history (symbol-value minibuffer-history-variable
)))
5347 (if (consp (car history
))
5348 (mapcar 'prin1-to-string history
)
5352 ;; (anything 'anything-c-source-minibuffer-history)
5355 (defvar anything-c-source-elscreen
5356 '((name .
"Elscreen")
5357 (candidates .
(lambda ()
5358 (if (cdr (elscreen-get-screen-to-name-alist))
5360 (loop for sname in
(elscreen-get-screen-to-name-alist)
5361 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
5362 finally
(return lst
))
5363 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
5364 (action .
(("Change Screen".
5366 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
5369 (dolist (i (anything-marked-candidates))
5370 (elscreen-goto (- (aref i
1) (aref "0" 0)))
5374 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
5375 (elscreen-kill-others)))))))
5376 ;; (anything 'anything-c-source-elscreen)
5381 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
5382 "Top command (batch mode). %s is replaced with `frame-width'.")
5383 (defvar anything-c-source-top
5384 '((name .
"Top (Press C-c C-u to refresh)")
5385 (init . anything-c-top-init
)
5386 (candidates-in-buffer)
5387 (display-to-real . anything-c-top-display-to-real
)
5388 (update . anything-c-top-update
)
5390 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
5391 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
5392 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
5393 ;; (anything 'anything-c-source-top)
5395 (defun anything-c-top-sh (cmd)
5396 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
5398 (defun anything-c-top-init ()
5399 (with-current-buffer (anything-candidate-buffer 'global
)
5400 (call-process-shell-command
5401 (format anything-c-top-command
5402 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
5403 nil
(current-buffer))))
5405 (defun anything-c-top-display-to-real (line)
5406 (car (split-string line
)))
5408 (defun anything-c-top-update ()
5409 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
5410 (anything-c-top-init)))
5413 (defun anything-top ()
5414 "Preconfigured `anything' for top command."
5416 (let ((anything-samewindow t
)
5417 (anything-enable-shortcuts)
5418 (anything-display-function 'anything-default-display-buffer
)
5419 (anything-candidate-number-limit 9999))
5420 (save-window-excursion
5421 (delete-other-windows)
5422 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
5425 (defvar anything-c-source-absolute-time-timers
5426 '((name .
"Absolute Time Timers")
5427 (candidates . timer-list
)
5429 ;; (anything 'anything-c-source-absolute-time-timers)
5431 (defvar anything-c-source-idle-time-timers
5432 '((name .
"Idle Time Timers")
5433 (candidates . timer-idle-list
)
5435 ;; (anything 'anything-c-source-idle-time-timers)
5437 (defun anything-c-timer-real-to-display (timer)
5438 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
5439 (append timer nil
) ;use `append' to convert vector->list
5440 (format "%s repeat=%5S %s(%s)"
5441 (let ((time (list t1 t2 t3
)))
5443 (format-time-string "idle-for=%5s" time
)
5444 (format-time-string "%m/%d %T" time
)))
5447 (mapconcat 'prin1-to-string args
" "))))
5449 ;;; X RandR resolution change
5450 ;;; FIXME I do not care multi-display.
5451 (defvar anything-c-xrandr-output
"VGA")
5452 (defvar anything-c-xrandr-screen
"0")
5453 (defvar anything-c-source-xrandr-change-resolution
5454 '((name .
"Change Resolution")
5458 (call-process "xrandr" nil
(current-buffer) nil
5459 "--screen" anything-c-xrandr-screen
"-q")
5461 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
5462 collect
(match-string 1)))))
5464 ("Change Resolution" .
(lambda (mode)
5465 (call-process "xrandr" nil nil nil
5466 "--screen" anything-c-xrandr-screen
5467 "--output" anything-c-xrandr-output
5469 ;; (anything 'anything-c-source-xrandr-change-resolution)
5472 (defun anything-c-persistent-xfont-action (elm)
5473 "Show current font temporarily"
5474 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
5477 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
5478 (set-frame-font current-font
))))
5480 (defvar anything-c-xfonts-cache nil
)
5481 (defvar anything-c-source-xfonts
5482 '((name .
"X Fonts")
5484 (unless anything-c-xfonts-cache
5485 (setq anything-c-xfonts-cache
5486 (x-list-fonts "*")))))
5487 (candidates . anything-c-xfonts-cache
)
5488 (action .
(("Copy to kill ring" .
(lambda (elm)
5490 ("Set Font" .
(lambda (elm)
5492 (set-frame-font elm
'keep-size
)
5493 (message "New font have been copied to kill ring")))))
5494 (persistent-action . anything-c-persistent-xfont-action
)
5495 (persistent-help .
"Switch to this font temporarily")))
5498 (defun anything-select-xfont ()
5499 "Preconfigured `anything' to select Xfont."
5501 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
5503 ;; (anything 'anything-c-source-xfonts)
5505 ;;; Source for Debian/Ubuntu users
5506 (defvar anything-c-source-apt
5508 (init . anything-c-apt-init
)
5509 (candidates-in-buffer)
5510 (candidate-transformer anything-c-apt-candidate-transformer
)
5511 (display-to-real . anything-c-apt-display-to-real
)
5512 (candidate-number-limit .
9999)
5514 ("Show package description" . anything-c-apt-cache-show
)
5515 ("Install package" . anything-c-apt-install
)
5516 ("Remove package" . anything-c-apt-uninstall
)
5517 ("Purge package" . anything-c-apt-purge
))
5518 (persistent-action . anything-c-apt-persistent-action
)
5519 (persistent-help .
"Show - C-u Refresh")))
5520 ;; (anything 'anything-c-source-apt)
5522 (defvar anything-c-apt-query
"emacs")
5523 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
5524 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
5525 (defvar anything-c-apt-installed-packages nil
)
5527 (defface anything-apt-installed
5528 '((t (:foreground
"green")))
5529 "*Face used for apt installed candidates."
5532 (defun anything-c-apt-refresh ()
5533 "Refresh installed candidates list."
5534 (setq anything-c-apt-installed-packages nil
)
5535 (anything-force-update))
5537 (defun anything-c-apt-persistent-action (candidate)
5538 "Persistent action for APT source."
5539 (if current-prefix-arg
5540 (anything-c-apt-refresh)
5541 (anything-c-apt-cache-show candidate
)))
5544 (defun anything-apt (query)
5545 "Preconfigured `anything' : frontend of APT package manager."
5546 (interactive "sAPT search: ")
5547 (let ((anything-c-apt-query query
))
5548 (anything 'anything-c-source-apt
)))
5550 (defun anything-c-apt-candidate-transformer (candidates)
5551 "Show installed candidates in a different color."
5554 for cand in candidates
5555 for name
= (anything-c-apt-display-to-real cand
)
5556 if
(member name anything-c-apt-installed-packages
)
5557 collect
(propertize cand
'face
'anything-apt-installed
) into all
5558 else collect cand into all finally return all
))
5560 (defun anything-c-apt-init ()
5561 "Initialize list of debian packages."
5562 (unless anything-c-apt-installed-packages
5563 (message "Updating installed candidate list...")
5564 (setq anything-c-apt-installed-packages
5566 (call-process-shell-command "dpkg --get-selections"
5567 nil
(current-buffer))
5568 (loop for i in
(split-string (buffer-string) "\n" t
)
5569 collect
(car (split-string i
))))))
5570 (with-current-buffer
5571 (anything-candidate-buffer
5572 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query
)))
5574 (call-process-shell-command
5575 (format anything-c-apt-search-command anything-c-apt-query
)
5576 nil
(current-buffer)))
5577 (message "Updating installed candidate list...done"))
5579 (defun anything-c-apt-display-to-real (line)
5580 "Return only name of a debian package.
5581 LINE is displayed like:
5582 package name - description."
5583 (car (split-string line
" - ")))
5586 (defun anything-c-shell-command-if-needed (command)
5587 (interactive "sShell command: ")
5588 (if (get-buffer command
) ; if the buffer already exists
5589 (switch-to-buffer command
) ; then just switch to it
5590 (switch-to-buffer command
) ; otherwise create it
5591 (insert (shell-command-to-string command
))))
5593 (defun anything-c-apt-cache-show (package)
5594 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package
)))
5596 (defun anything-c-apt-install (package)
5597 (anything-c-apt-install1 package
:action
'install
))
5599 (defun anything-c-apt-uninstall (package)
5600 (anything-c-apt-install1 package
:action
'uninstall
))
5602 (defun anything-c-apt-purge (package)
5603 (anything-c-apt-install1 package
:action
'purge
))
5605 (defun* anything-c-apt-install1
(candidate &key action
)
5606 (ansi-term (getenv "SHELL") "anything apt")
5608 (let ((command (case action
5609 ('install
"sudo apt-get install '%s'")
5610 ('uninstall
"sudo apt-get remove '%s'")
5611 ('purge
"sudo apt-get purge '%s'")
5612 (t (error "Unknow action"))))
5614 (goto-char (point-max))
5615 (insert (format command candidate
))
5617 (if (y-or-n-p (format "%s package" (symbol-name action
)))
5619 (setq anything-c-external-commands-list nil
)
5620 (setq anything-c-apt-installed-packages nil
)
5621 (term-char-mode) (term-send-input))
5622 (delete-region beg end
) (term-send-eof) (kill-buffer))))
5624 ;; (anything-c-apt-install "jed")
5626 ;;; Sources for gentoo users
5627 (defvar anything-c-gentoo-use-flags nil
)
5628 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
5629 (defvar anything-c-cache-gentoo nil
)
5630 (defvar anything-c-cache-world nil
)
5631 (defvar anything-c-source-gentoo
5632 '((name .
"Portage sources")
5634 (get-buffer-create anything-c-gentoo-buffer
)
5635 (unless anything-c-cache-gentoo
5636 (anything-c-gentoo-setup-cache))
5637 (unless anything-c-cache-world
5638 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
5639 (anything-c-gentoo-init-list)))
5640 (candidates-in-buffer)
5642 (candidate-transformer anything-c-highlight-world
)
5643 (action .
(("Show package" .
(lambda (elm)
5644 (anything-c-gentoo-eshell-action elm
"eix")))
5645 ("Show history" .
(lambda (elm)
5646 (if (member elm anything-c-cache-world
)
5647 (anything-c-gentoo-eshell-action elm
"genlop -qe")
5648 (message "No infos on packages not yet installed"))))
5649 ("Copy in kill-ring" . kill-new
)
5650 ("insert at point" . insert
)
5651 ("Browse HomePage" .
(lambda (elm)
5652 (let ((urls (anything-c-gentoo-get-url elm
)))
5653 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
5654 ("Show extra infos" .
(lambda (elm)
5655 (if (member elm anything-c-cache-world
)
5656 (anything-c-gentoo-eshell-action elm
"genlop -qi")
5657 (message "No infos on packages not yet installed"))))
5658 ("Show use flags" .
(lambda (elm)
5659 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
5660 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
5661 (font-lock-mode 1)))
5662 ("Run emerge pretend" .
(lambda (elm)
5663 (anything-c-gentoo-eshell-action elm
"emerge -p")))
5664 ("Emerge" .
(lambda (elm)
5665 (anything-gentoo-install elm
:action
'install
)))
5666 ("Unmerge" .
(lambda (elm)
5667 (anything-gentoo-install elm
:action
'uninstall
)))
5668 ("Show dependencies" .
(lambda (elm)
5669 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
5670 ("Show related files" .
(lambda (elm)
5671 (anything-c-gentoo-default-action elm
"equery" "files")))
5672 ("Refresh" .
(lambda (elm)
5673 (anything-c-gentoo-setup-cache)
5674 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
5676 ;; (anything 'anything-c-source-gentoo)
5678 (defun* anything-gentoo-install
(candidate &key action
)
5679 (setq anything-c-external-commands-list nil
)
5680 (ansi-term (getenv "SHELL") "Gentoo emerge")
5682 (let ((command (case action
5683 ('install
"sudo emerge -av ")
5684 ('uninstall
"sudo emerge -avC ")
5685 (t (error "Unknow action"))))
5686 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
5688 (goto-char (point-max))
5689 (insert (concat command elms
))
5691 (term-char-mode) (term-send-input)))
5693 (defun anything-c-gentoo-default-action (elm command
&rest args
)
5694 "Gentoo default action that use `anything-c-gentoo-buffer'."
5695 (if (member elm anything-c-cache-world
)
5697 (switch-to-buffer anything-c-gentoo-buffer
)
5699 (let ((com-list (append args
(list elm
))))
5700 (apply #'call-process command nil t nil
5702 (message "No infos on packages not yet installed")))
5704 (defvar anything-c-source-use-flags
5705 '((name .
"Use Flags")
5707 (unless anything-c-gentoo-use-flags
5708 (anything-c-gentoo-setup-use-flags-cache))
5709 (anything-c-gentoo-get-use)))
5710 (candidates-in-buffer)
5712 (candidate-transformer anything-c-highlight-local-use
)
5713 (action .
(("Description"
5715 (switch-to-buffer anything-c-gentoo-buffer
)
5717 (apply #'call-process
"euse" nil t nil
5720 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
5721 (font-lock-mode 1)))
5724 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
5727 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
5730 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
5731 ("Show which dep use this flag"
5733 (switch-to-buffer anything-c-gentoo-buffer
)
5735 (apply #'call-process
"equery" nil t nil
5741 ;; (anything 'anything-c-source-use-flags)
5743 (defun anything-c-gentoo-init-list ()
5744 "Initialize buffer with all packages in Portage."
5745 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
5746 (buf (anything-candidate-buffer 'portage-buf
)))
5747 (with-current-buffer buf
5748 (dolist (i anything-c-cache-gentoo
)
5749 (insert (concat i
"\n"))))))
5751 (defun anything-c-gentoo-setup-cache ()
5752 "Set up `anything-c-cache-gentoo'"
5753 (setq anything-c-cache-gentoo
5754 (split-string (with-temp-buffer
5755 (call-process "eix" nil t nil
5759 (defun anything-c-gentoo-eshell-action (elm command
)
5760 (when (get-buffer "*EShell Command Output*")
5761 (kill-buffer "*EShell Command Output*"))
5762 (message "Wait searching...")
5763 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
5764 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
5766 (save-window-excursion
5767 (pop-to-buffer "*scratch*")
5768 (eshell-command (format "%s %s" command elm
)))
5769 (pop-to-buffer "*EShell Command Output*"))
5770 (eshell-command (format "%s %s" command elm
)))))
5772 (defun anything-c-gentoo-get-use ()
5773 "Initialize buffer with all use flags."
5774 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
5775 (buf (anything-candidate-buffer 'use-buf
)))
5776 (with-current-buffer buf
5777 (dolist (i anything-c-gentoo-use-flags
)
5778 (insert (concat i
"\n"))))))
5781 (defun anything-c-gentoo-setup-use-flags-cache ()
5782 "Setup `anything-c-gentoo-use-flags'"
5783 (setq anything-c-gentoo-use-flags
5784 (split-string (with-temp-buffer
5785 (call-process "eix" nil t nil
5786 "--print-all-useflags")
5789 (defun anything-c-gentoo-get-url (elm)
5790 "Return a list of urls from eix output."
5792 with url-list
= (split-string
5794 (call-process "eix" nil t nil
5795 elm
"--format" "<homepage>\n")
5799 when
(and (string-match "^http://.*" i
)
5800 (not (member i all
)))
5802 finally return all
))
5804 (defun anything-c-gentoo-get-world ()
5805 "Return list of all installed package on your system."
5806 (split-string (with-temp-buffer
5807 (call-process "qlist" nil t nil
5811 (defun anything-c-gentoo-get-local-use ()
5812 (split-string (with-temp-buffer
5813 (call-process "portageq" nil t nil
5818 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
5819 "Face for anything-gentoo installed packages."
5820 :group
'traverse-faces
)
5822 (defun anything-c-highlight-world (eix)
5823 "Highlight all installed package."
5825 if
(member i anything-c-cache-world
)
5826 collect
(propertize i
'face
'anything-gentoo-match-face
)
5830 (defun anything-c-highlight-local-use (use-flags)
5831 (let ((local-uses (anything-c-gentoo-get-local-use)))
5832 (loop for i in use-flags
5833 if
(member i local-uses
)
5834 collect
(propertize i
'face
'anything-gentoo-match-face
)
5838 (defvar anything-c-source-emacs-process
5839 '((name .
"Emacs Process")
5840 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
5841 (persistent-action .
(lambda (elm)
5842 (delete-process (get-process elm
))
5843 (anything-delete-current-selection)))
5844 (persistent-help .
"Kill Process")
5845 (action ("Kill Process" .
(lambda (elm)
5846 (delete-process (get-process elm
)))))))
5848 ;; (anything 'anything-c-source-emacs-process)
5850 ;; Run Externals commands within Emacs
5851 (defmacro* anything-comp-hash-get-items
(hash-table &key test
)
5852 "Get the list of all keys/values of hash-table."
5853 `(let ((li-items ()))
5854 (maphash #'(lambda (x y
)
5856 (when (funcall ,test y
)
5857 (push (list x y
) li-items
))
5858 (push (list x y
) li-items
)))
5862 (defun anything-comp-read-get-candidates (collection &optional test
)
5863 "Convert collection to list.
5864 If collection is an `obarray', a test is maybe needed, otherwise
5865 the list would be incomplete.
5867 (cond ((and (listp collection
) test
)
5868 (loop for i in collection when
(funcall test i
) collect i
))
5869 ((and (eq collection obarray
) test
)
5870 (loop for s being the symbols of collection
5871 when
(funcall test s
) collect s
))
5872 ((and (vectorp collection
) test
)
5873 (loop for i across collection when
(funcall test i
) collect i
))
5874 ((vectorp collection
)
5875 (loop for i across collection collect i
))
5876 ((and (hash-table-p collection
) test
)
5877 (anything-comp-hash-get-items collection
:test test
))
5878 ((hash-table-p collection
)
5879 (anything-comp-hash-get-items collection
))
5882 (defun* anything-comp-read
(prompt collection
5886 (buffer "*Anything Completions*")
5888 (requires-pattern 0)
5890 (persistent-action nil
)
5891 (persistent-help "DoNothing")
5892 (name "Anything Completions"))
5893 "Anything `completing-read' emulation.
5894 Collection can be a list, vector, obarray or hash-table."
5895 (when (get-buffer anything-action-buffer
)
5896 (kill-buffer anything-action-buffer
))
5899 `(((name .
,(format "%s History" name
))
5900 (candidates .
(lambda ()
5901 (anything-comp-read-get-candidates history
)))
5903 (persistent-action .
,persistent-action
)
5904 (persistent-help .
,persistent-help
)
5905 (action .
,'identity
))
5909 (let ((cands (anything-comp-read-get-candidates
5911 (if (or must-match
(string= anything-pattern
""))
5912 cands
(append (list anything-pattern
) cands
)))))
5913 (requires-pattern .
,requires-pattern
)
5914 (persistent-action .
,persistent-action
)
5915 (persistent-help .
,persistent-help
)
5917 (action .
(("candidate" .
,'identity
)))))
5918 :input initial-input
5924 (defun anything-c-get-pid-from-process-name (process-name)
5925 "Get pid from running process PROCESS-NAME."
5926 (loop with process-list
= (list-system-processes)
5927 for pid in process-list
5928 for process
= (assoc-default 'comm
(process-attributes pid
))
5929 when
(and process
(string-match process-name process
))
5933 (defun anything-run-or-raise (exe &optional file
)
5934 "Generic command that run asynchronously EXE.
5935 If EXE is already running just jump to his window if `anything-raise-command'
5937 When FILE argument is provided run EXE with FILE.
5938 In this case EXE must be provided as \"EXE %s\"."
5939 (let ((real-com (car (split-string (replace-regexp-in-string " %s" "" exe
)))))
5940 (if (or (get-process real-com
)
5941 (anything-c-get-pid-from-process-name real-com
))
5942 (if anything-raise-command
5943 (shell-command (format anything-raise-command real-com
))
5944 (error "Error: %s is already running" real-com
))
5945 (when (member real-com anything-c-external-commands-list
)
5946 (message "Starting %s..." real-com
)
5948 (start-process-shell-command real-com nil
(format exe file
))
5949 (start-process-shell-command real-com nil real-com
))
5950 (set-process-sentinel
5951 (get-process real-com
)
5952 #'(lambda (process event
)
5953 (when (string= event
"finished\n")
5954 (when anything-raise-command
5955 (shell-command (format anything-raise-command
"emacs")))
5956 (message "%s process...Finished." process
))))
5957 (setq anything-c-external-commands-list
5958 (push (pop (nthcdr (anything-c-position
5959 real-com anything-c-external-commands-list
5961 anything-c-external-commands-list
))
5962 anything-c-external-commands-list
))))))
5964 (defvar anything-external-command-history nil
)
5966 (defun anything-c-run-external-command (program)
5967 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
5968 If program is already running exit with error.
5969 You can set your own list of commands with
5970 `anything-c-external-commands-list'."
5974 (anything-c-external-commands-list-1 'sort
)
5976 :name
"External Commands"
5977 :history anything-external-command-history
)))
5978 (anything-run-or-raise program
)
5979 (setq anything-external-command-history
5980 (cons program
(delete program anything-external-command-history
))))
5982 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
5983 "A simple and faster replacement of CL `position'."
5984 (loop for i in seq for index from
0
5985 when
(funcall test i item
) return index
))
5987 (defvar anything-c-source-ratpoison-commands
5988 '((name .
"Ratpoison Commands")
5989 (init . anything-c-ratpoison-commands-init
)
5990 (candidates-in-buffer)
5991 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
5992 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
5993 (candidate-number-limit)))
5994 ;; (anything 'anything-c-source-ratpoison-commands)
5996 (defun anything-c-ratpoison-commands-init ()
5997 (unless (anything-candidate-buffer)
5998 (with-current-buffer (anything-candidate-buffer 'global
)
5999 ;; with ratpoison prefix key
6001 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
6002 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
6003 (replace-match "<ratpoison> \\1: \\2"))
6004 (goto-char (point-max))
6007 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
6008 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
6009 (replace-match "\\1: \\2")))))
6011 (defun anything-c-ratpoison-commands-display-to-real (display)
6012 (and (string-match ": " display
)
6013 (substring display
(match-end 0))))
6015 (defun anything-c-ratpoison-commands-execute (candidate)
6016 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
6019 (defun anything-ratpoison-commands ()
6020 "Preconfigured `anything' to execute ratpoison commands."
6022 (anything-other-buffer 'anything-c-source-ratpoison-commands
6023 "*anything ratpoison commands*"))
6025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6027 (defvar anything-c-external-commands-list nil
6028 "A list of all external commands the user can execute. If this
6029 variable is not set by the user, it will be calculated
6032 (defun anything-c-external-commands-list-1 (&optional sort
)
6033 "Returns a list of all external commands the user can execute.
6034 If `anything-c-external-commands-list' is non-nil it will
6035 return its contents. Else it calculates all external commands
6036 and sets `anything-c-external-commands-list'."
6037 (if anything-c-external-commands-list
6038 anything-c-external-commands-list
6039 (setq anything-c-external-commands-list
6041 with paths
= (split-string (getenv "PATH") path-separator
)
6042 with completions
= ()
6044 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
6045 for lsdir
= (loop for i in
(directory-files dir t
)
6046 for bn
= (file-name-nondirectory i
)
6047 when
(and (not (member bn completions
))
6048 (not (file-directory-p i
))
6049 (file-executable-p i
))
6051 append lsdir into completions
6052 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
6055 (defun anything-c-file-buffers (filename)
6056 "Returns a list of buffer names corresponding to FILENAME."
6057 (let ((name (expand-file-name filename
))
6059 (dolist (buf (buffer-list) buf-list
)
6060 (let ((bfn (buffer-file-name buf
)))
6061 (when (and bfn
(string= name bfn
))
6062 (push (buffer-name buf
) buf-list
))))))
6064 (defun anything-c-delete-file (file)
6065 "Delete the given file after querying the user.
6066 Ask to kill buffers associated with that file, too."
6067 (let ((buffers (anything-c-file-buffers file
)))
6068 (dired-delete-file file
'dired-recursive-deletes
)
6070 (dolist (buf buffers
)
6071 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
6072 (kill-buffer buf
))))))
6074 (defun anything-get-mailcap-for-file (filename)
6075 "Get the command to use for FILENAME from mailcap files.
6076 The command is like <command %s> and is meant to use with `format'."
6077 (mailcap-parse-mailcaps)
6078 (let* ((ext (file-name-extension filename
))
6079 (mime (when ext
(mailcap-extension-to-mime ext
))))
6080 (when mime
(mailcap-mime-info mime
))))
6082 (defun anything-get-default-program-for-file (filename)
6083 "Try to find a default program to open FILENAME.
6084 Try first in `anything-c-external-programs-associations' and then in mailcap file
6085 if nothing found return nil."
6086 (let* ((ext (file-name-extension filename
))
6087 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
6088 (if (and def-prog
(not (string= def-prog
"")))
6089 (concat def-prog
" %s")
6090 (anything-get-mailcap-for-file filename
))))
6092 (defun anything-c-open-file-externally (file)
6093 "Open FILE with an external program.
6094 Try to guess which program to use with `anything-get-default-program-for-file'.
6095 If not found or a prefix arg is given query the user which tool to use."
6096 (let* ((fname (expand-file-name file
))
6097 (collection (anything-c-external-commands-list-1 'sort
))
6098 (def-prog (anything-get-default-program-for-file fname
))
6099 (program (or (unless (or anything-current-prefix-arg
6104 "Program: " collection
6106 :name
"Open file Externally"
6107 :history anything-external-command-history
)
6109 (real-prog-name (replace-regexp-in-string " %s" "" program
)))
6114 "Do you want to make %s the default program for this kind of files? "
6116 (push (cons (file-name-extension fname
)
6118 "Program(Add args maybe and confirm): " real-prog-name
))
6119 anything-c-external-programs-associations
)
6120 (customize-save-variable 'anything-c-external-programs-associations
6121 anything-c-external-programs-associations
)))
6122 (anything-run-or-raise program file
)
6123 (setq anything-external-command-history
6124 (cons real-prog-name
6125 (delete real-prog-name anything-external-command-history
)))))
6129 (defun w32-shell-execute-open-file (file)
6130 (interactive "fOpen file:")
6132 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
6134 (replace-regexp-in-string ; strip cygdrive paths
6135 "/cygdrive/\\(.\\)" "\\1:"
6136 file nil nil
) nil t
))))
6138 (defun anything-c-open-file-with-default-tool (file)
6139 "Open FILE with the default tool on this platform."
6140 (if (eq system-type
'windows-nt
)
6141 (w32-shell-execute-open-file file
)
6142 (start-process "anything-c-open-file-with-default-tool"
6144 (cond ((eq system-type
'gnu
/linux
)
6146 ((or (eq system-type
'darwin
) ;; Mac OS X
6147 (eq system-type
'macos
)) ;; Mac OS 9
6151 (defun anything-c-open-dired (file)
6152 "Opens a dired buffer in FILE's directory. If FILE is a
6153 directory, open this directory."
6154 (if (file-directory-p file
)
6156 (dired (file-name-directory file
))
6157 (dired-goto-file file
)))
6159 (defun anything-c-display-to-real-line (candidate)
6160 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
6161 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
6162 (error "Line number not found")))
6164 (defun anything-c-action-line-goto (lineno-and-content)
6165 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
6166 (append lineno-and-content
6167 (list (if (and (anything-attr-defined 'target-file
)
6168 (not anything-in-persistent-action
))
6169 'find-file-other-window
6172 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
6173 (apply #'anything-goto-file-line
6174 (if (stringp file-line-content
)
6175 ;; Case: filtered-candidate-transformer is skipped
6176 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
6177 file-line-content
)))
6180 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
6181 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
6183 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
6184 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
6185 (let ((filename (match-string 1 candidate
))
6186 (lineno (match-string 2 candidate
))
6187 (content (match-string 3 candidate
)))
6188 (cons (format "%s:%s\n %s"
6189 (propertize filename
'face compilation-info-face
)
6190 (propertize lineno
'face compilation-line-face
)
6192 (list (expand-file-name
6194 (or (anything-interpret-value (anything-attr 'default-directory
))
6195 (and (anything-candidate-buffer)
6197 'default-directory
(anything-candidate-buffer)))))
6198 (string-to-number lineno
) content
)))))
6200 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
6201 (anything-aif (anything-attr 'before-jump-hook
)
6203 (when file
(funcall find-file-function file
))
6204 (if (anything-attr-defined 'adjust
)
6205 (anything-c-goto-line-with-adjustment lineno content
)
6206 (anything-goto-line lineno
))
6207 (unless (anything-attr-defined 'recenter
)
6208 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
6209 (anything-aif (anything-attr 'after-jump-hook
)
6211 (when anything-in-persistent-action
6212 (anything-match-line-color-current-line)))
6214 (defun anything-find-file-as-root (candidate)
6215 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
6217 (defun anything-find-many-files (ignore)
6218 (mapc 'find-file
(anything-marked-candidates)))
6220 ;; borrowed from etags.el
6221 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
6222 (defun anything-c-goto-line-with-adjustment (line line-content
)
6225 ;; This constant is 1/2 the initial search window.
6226 ;; There is no sense in making it too small,
6227 ;; since just going around the loop once probably
6228 ;; costs about as much as searching 2000 chars.
6231 pat
(concat (if (eq selective-display t
)
6232 "\\(^\\|\^m\\) *" "^ *") ;allow indent
6233 (regexp-quote line-content
)))
6234 ;; If no char pos was given, try the given line number.
6235 (setq startpos
(progn (anything-goto-line line
) (point)))
6236 (or startpos
(setq startpos
(point-min)))
6237 ;; First see if the tag is right at the specified location.
6238 (goto-char startpos
)
6239 (setq found
(looking-at pat
))
6240 (while (and (not found
)
6242 (goto-char (- startpos offset
))
6245 (re-search-forward pat
(+ startpos offset
) t
)
6246 offset
(* 3 offset
))) ; expand search window
6248 (re-search-forward pat nil t
)
6249 (error "not found")))
6250 ;; Position point at the right place
6251 ;; if the search string matched an extra Ctrl-m at the beginning.
6252 (and (eq selective-display t
)
6255 (beginning-of-line))
6257 (anything-document-attribute 'default-directory
"type . file-line"
6258 "`default-directory' to interpret file.")
6259 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
6260 "Function to call before jumping to the target location.")
6261 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
6262 "Function to call after jumping to the target location.")
6263 (anything-document-attribute 'adjust
"type . file-line"
6264 "Search around line matching line contents.")
6265 (anything-document-attribute 'recenter
"type . file-line / line"
6266 "`recenter' after jumping.")
6267 (anything-document-attribute 'target-file
"type . line"
6268 "Goto line of target-file.")
6271 (defun anything-c-call-interactively (cmd-or-name)
6272 "Execute CMD-OR-NAME as Emacs command.
6273 It is added to `extended-command-history'.
6274 `anything-current-prefix-arg' is used as the command's prefix argument."
6275 (setq extended-command-history
6276 (cons (anything-c-stringify cmd-or-name
)
6277 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
6278 (let ((current-prefix-arg anything-current-prefix-arg
)
6279 (cmd (anything-c-symbolify cmd-or-name
)))
6280 (if (stringp (symbol-function cmd
))
6281 (execute-kbd-macro (symbol-function cmd
))
6282 (setq this-command cmd
)
6283 (call-interactively cmd
))))
6286 (defun anything-c-set-variable (var)
6287 "Set value to VAR interactively."
6289 (let ((sym (anything-c-symbolify var
)))
6290 (set sym
(eval-minibuffer (format "Set %s: " var
)
6291 (prin1-to-string (symbol-value sym
))))))
6293 ;; (anything-c-set-variable 'hh)
6295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6296 (defvar anything-match-line-overlay-face nil
)
6297 (defvar anything-match-line-overlay nil
)
6299 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
6300 "Highlight and underline current position"
6301 (let ((args (list (or start
(line-beginning-position))
6302 (or end
(1+ (line-end-position)))
6304 (if (not anything-match-line-overlay
)
6305 (setq anything-match-line-overlay
(apply 'make-overlay args
))
6306 (apply 'move-overlay anything-match-line-overlay args
)))
6307 (overlay-put anything-match-line-overlay
6308 'face
(or face anything-match-line-overlay-face
))
6313 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
6315 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
6316 "Face for source header in the anything buffer." :group
'anything
)
6318 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
6320 (defun anything-match-line-cleanup ()
6321 (when anything-match-line-overlay
6322 (delete-overlay anything-match-line-overlay
)
6323 (setq anything-match-line-overlay nil
)))
6325 (defun anything-match-line-update ()
6326 (when anything-match-line-overlay
6327 (delete-overlay anything-match-line-overlay
)
6328 (anything-match-line-color-current-line)))
6330 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
6331 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
6333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6335 (defun anything-c-transform-file-load-el (actions candidate
)
6336 "Add action to load the file CANDIDATE if it is an emacs lisp
6337 file. Else return ACTIONS unmodified."
6338 (if (member (file-name-extension candidate
) '("el" "elc"))
6339 (append actions
'(("Load Emacs Lisp File" . load-file
)))
6342 (defun anything-c-transform-file-browse-url (actions candidate
)
6343 "Add an action to browse the file CANDIDATE if it in a html
6344 file or URL. Else return ACTIONS unmodified."
6345 (let ((browse-action '("Browse with Browser" . browse-url
)))
6346 (cond ((string-match "^http\\|^ftp" candidate
)
6347 (cons browse-action actions
))
6348 ((string-match "\\.html?$" candidate
)
6349 (append actions
(list browse-action
)))
6353 (defun anything-c-transform-function-call-interactively (actions candidate
)
6354 "Add an action to call the function CANDIDATE interactively if
6355 it is a command. Else return ACTIONS unmodified."
6356 (if (commandp (intern-soft candidate
))
6357 (append actions
'(("Call Interactively"
6359 anything-c-call-interactively
)))
6363 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
6364 "If CANDIDATE's `car' is a command, then add an action to
6365 evaluate it and put it onto the `command-history'."
6366 (if (commandp (car (read candidate
)))
6367 ;; Make it first entry
6368 (cons '("Eval and put onto command-history" .
6370 (let ((sym (read sexp
)))
6372 (setq command-history
6373 (cons sym command-history
)))))
6377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6379 (defun anything-c-skip-boring-buffers (buffers)
6380 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
6382 (defun anything-c-skip-current-buffer (buffers)
6383 (if anything-allow-skipping-current-buffer
6384 (remove (buffer-name anything-current-buffer
) buffers
)
6387 (defun anything-c-shadow-boring-buffers (buffers)
6388 "Buffers matching `anything-c-boring-buffer-regexp' will be
6389 displayed with the `file-name-shadow' face if available."
6390 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
6393 (defun anything-c-shadow-boring-files (files)
6394 "Files matching `anything-c-boring-file-regexp' will be
6395 displayed with the `file-name-shadow' face if available."
6396 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
6398 (defun anything-c-skip-boring-files (files)
6399 "Files matching `anything-c-boring-file-regexp' will be skipped."
6400 (anything-c-skip-entries files anything-c-boring-file-regexp
))
6401 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6403 (defun anything-c-skip-current-file (files)
6404 "Current file will be skipped."
6405 (remove (buffer-file-name anything-current-buffer
) files
))
6407 (defun anything-c-w32-pathname-transformer (args)
6408 "Change undesirable features of windows pathnames to ones more acceptable to
6409 other candidate transformers."
6410 (if (eq system-type
'windows-nt
)
6412 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
6414 (replace-regexp-in-string "\\\\" "/" y
)) args
))
6417 (defun anything-c-shorten-home-path (files)
6418 "Replaces /home/user with ~."
6419 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6421 (mapcar (lambda (file)
6422 (if (and (stringp file
) (string-match home file
))
6423 (cons (replace-match "~" nil nil file
) file
)
6428 (defun anything-c-mark-interactive-functions (functions)
6429 "Mark interactive functions (commands) with (i) after the function name."
6431 (loop for function in functions
6432 do
(push (cons (concat function
6433 (when (commandp (intern-soft function
)) " (i)"))
6436 finally
(return (nreverse list
)))))
6438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6439 (defvar anything-c-adaptive-done nil
6440 "nil if history information is not yet stored for the current
6443 (defvar anything-c-adaptive-history nil
6444 "Contains the stored history information.
6445 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6447 (defadvice anything-initialize
(before anything-c-adaptive-initialize activate
)
6448 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6449 when anything is started."
6450 (setq anything-c-adaptive-done nil
))
6452 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
6453 "Advise `anything-exit-minibuffer' to store history information
6454 when a candidate is selected with RET."
6455 (anything-c-adaptive-store-selection))
6457 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
6458 "Advise `anything-select-action' to store history information
6459 when the user goes to the action list with TAB."
6460 (anything-c-adaptive-store-selection))
6462 (defun anything-c-source-use-adaptative-p (&optional source-name
)
6463 "Return current source only if it use adaptative history, nil otherwise."
6464 (let* ((source (or source-name
(anything-get-current-source)))
6465 (adapt-source (or (assoc-default 'filtered-candidate-transformer
6466 (assoc (assoc-default 'type source
)
6467 anything-type-attributes
))
6468 (assoc-default 'candidate-transformer
6469 (assoc (assoc-default 'type source
)
6470 anything-type-attributes
))
6471 (assoc-default 'filtered-candidate-transformer source
)
6472 (assoc-default 'candidate-transformer source
))))
6473 (if (listp adapt-source
)
6474 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
6475 (when (eq adapt-source
'anything-c-adaptive-sort
) source
))))
6477 (defun anything-c-adaptive-store-selection ()
6478 "Store history information for the selected candidate."
6479 (unless anything-c-adaptive-done
6480 (setq anything-c-adaptive-done t
)
6481 (let ((source (anything-c-source-use-adaptative-p)))
6483 (let* ((source-name (or (assoc-default 'type source
)
6484 (assoc-default 'name source
)))
6485 (source-info (or (assoc source-name anything-c-adaptive-history
)
6487 (push (list source-name
) anything-c-adaptive-history
)
6488 (car anything-c-adaptive-history
))))
6489 (selection (anything-get-selection))
6490 (selection-info (progn
6493 (let ((found (assoc selection
(cdr source-info
))))
6498 ;; move entry to the beginning of the
6499 ;; list, so that it doesn't get
6500 ;; trimmed when the history is
6503 (delete found
(cdr source-info
)))
6506 (cadr source-info
)))
6507 (pattern-info (progn
6508 (setcdr selection-info
6510 (let ((found (assoc anything-pattern
(cdr selection-info
))))
6513 (cons anything-pattern
0)
6515 ;; move entry to the beginning of the
6516 ;; list, so if two patterns used the
6517 ;; same number of times then the one
6518 ;; used last appears first in the list
6519 (setcdr selection-info
6520 (delete found
(cdr selection-info
)))
6522 (cdr selection-info
)))
6523 (cadr selection-info
))))
6525 ;; increase usage count
6526 (setcdr pattern-info
(1+ (cdr pattern-info
)))
6528 ;; truncate history if needed
6529 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
6530 (setcdr selection-info
6531 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
6533 (if (file-readable-p anything-c-adaptive-history-file
)
6534 (load-file anything-c-adaptive-history-file
))
6535 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
6537 (defun anything-c-adaptive-save-history ()
6538 "Save history information to file given by `anything-c-adaptive-history-file'."
6542 ";; -*- mode: emacs-lisp -*-\n"
6543 ";; History entries used for anything adaptive display.\n")
6544 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
6547 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
6548 (unless (interactive-p) 'quiet
))))
6550 (defun anything-c-adaptive-sort (candidates source
)
6551 "Sort the CANDIDATES for SOURCE by usage frequency.
6552 This is a filtered candidate transformer you can use for the
6553 attribute `filtered-candidate-transformer' of a source in
6554 `anything-sources' or a type in `anything-type-attributes'."
6555 (let* ((source-name (or (assoc-default 'type source
)
6556 (assoc-default 'name source
)))
6557 (source-info (assoc source-name anything-c-adaptive-history
)))
6558 (if (not source-info
)
6559 ;; if there is no information stored for this source then do nothing
6563 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
6565 (mapcar (lambda (candidate-info)
6567 (dolist (pattern-info (cdr candidate-info
))
6568 (if (not (equal (car pattern-info
)
6570 (incf count
(cdr pattern-info
))
6572 ;; if current pattern is equal to the previously
6573 ;; used one then this candidate has priority
6574 ;; (that's why its count is boosted by 10000) and
6575 ;; it only has to compete with other candidates
6576 ;; which were also selected with the same pattern
6577 (setq count
(+ 10000 (cdr pattern-info
)))
6579 (cons (car candidate-info
) count
)))
6583 ;; sort the list in descending order, so candidates with highest
6584 ;; priorty come first
6585 (setq usage
(sort usage
(lambda (first second
)
6586 (> (cdr first
) (cdr second
)))))
6588 ;; put those candidates first which have the highest usage count
6589 (dolist (info usage
)
6590 (when (member* (car info
) candidates
6591 :test
'anything-c-adaptive-compare
)
6592 (push (car info
) sorted
)
6593 (setq candidates
(remove* (car info
) candidates
6594 :test
'anything-c-adaptive-compare
))))
6596 ;; and append the rest
6597 (append (reverse sorted
) candidates nil
)))))
6599 (defun anything-c-adaptive-compare (x y
)
6600 "Compare candidates X and Y taking into account that the
6601 candidate can be in (DISPLAY . REAL) format."
6602 (equal (if (listp x
)
6609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6610 (defvar anything-outline-goto-near-line-flag t
)
6611 (defvar anything-outline-using nil
)
6612 (defun anything-after-update-hook--outline ()
6613 (if (and (eq anything-outline-using t
)
6614 (eq anything-outline-goto-near-line-flag t
))
6615 (anything-outline-goto-near-line)))
6616 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
6618 (defun anything-outline-goto-near-line ()
6619 (with-anything-window
6620 ;; TODO need consideration whether to update position by every input.
6621 (when t
; (equal anything-pattern "")
6622 (anything-goto-line 2)
6623 (let ((lineno (with-current-buffer anything-current-buffer
6624 (line-number-at-pos (car anything-current-position
)))))
6626 (while (<= (progn (skip-chars-forward " ")
6627 (or (number-at-point) lineno
))
6632 (return-from exit
))))
6634 (and (bobp) (forward-line 1))
6635 (and (anything-pos-header-line-p) (forward-line -
2))
6636 (anything-mark-current-line)))))
6638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6639 ;; Plug-in: info-index
6640 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
6642 (unless (anything-candidate-buffer)
6643 (save-window-excursion
6646 (tobuf (anything-candidate-buffer 'global
))
6647 (infobuf (current-buffer))
6649 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
6650 (Info-goto-node node
)
6651 (goto-char (point-min))
6652 (while (search-forward "\n* " nil t
)
6653 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
6654 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
6655 (setq s
(point-at-bol)
6657 (with-current-buffer tobuf
6658 (insert-buffer-substring infobuf s e
)
6659 (insert "\n"))))))))))
6661 (defun anything-c-info-goto (node-line)
6662 (Info-goto-node (car node-line
))
6663 (anything-goto-line (cdr node-line
)))
6665 (defun anything-c-info-display-to-real (line)
6667 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
6668 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
6669 (string-to-number (or (match-string 3 line
) "1")))))
6671 (defun anything-c-make-info-source (file)
6672 `((name .
,(concat "Info Index: " file
))
6674 (init . anything-c-info-init
)
6675 (display-to-real . anything-c-info-display-to-real
)
6676 (get-line . buffer-substring
)
6677 (candidates-in-buffer)
6678 (action ("Goto node" . anything-c-info-goto
))))
6680 (defun anything-compile-source--info-index (source)
6681 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
6682 (anything-c-make-info-source it
)
6684 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
6686 (anything-document-attribute 'info-index
"info-index plugin"
6687 "Create a source of info index very easily.
6689 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
6691 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
6692 "Index nodes of info file.
6694 If it is omitted, `Info-index-nodes' is used to collect index nodes.
6695 Some info files are missing index specification.
6697 ex. See `anything-c-source-info-screen'.")
6699 ;; Plug-in: candidates-file
6700 (defun anything-compile-source--candidates-file (source)
6701 (if (assoc-default 'candidates-file source
)
6702 `((init anything-p-candidats-file-init
6703 ,@(let ((orig-init (assoc-default 'init source
)))
6704 (cond ((null orig-init
) nil
)
6705 ((functionp orig-init
) (list orig-init
))
6707 (candidates-in-buffer)
6710 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
6712 (defun anything-p-candidats-file-init ()
6713 (destructuring-bind (file &optional updating
)
6714 (anything-mklist (anything-attr 'candidates-file
))
6715 (setq file
(anything-interpret-value file
))
6716 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
6718 (buffer-disable-undo)
6720 (auto-revert-mode 1)))))
6722 (anything-document-attribute 'candidates-file
"candidates-file plugin"
6723 "Use a file as the candidates buffer.
6725 1st argument is a filename, string or function name or variable name.
6726 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
6728 ;; Plug-in: headline
6729 (defun anything-compile-source--anything-headline (source)
6730 (if (assoc-default 'headline source
)
6731 (append '((init . anything-headline-init
)
6732 (get-line . buffer-substring
)
6735 '((candidates-in-buffer)
6736 (persistent-help .
"Show this line")))
6738 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
6740 (defun anything-headline-init ()
6741 (when (and (anything-current-buffer-is-modified)
6742 (with-current-buffer anything-current-buffer
6743 (eval (or (anything-attr 'condition
) t
))))
6744 (anything-headline-make-candidate-buffer
6745 (anything-interpret-value (anything-attr 'headline
))
6746 (anything-interpret-value (anything-attr 'subexp
)))))
6748 (anything-document-attribute 'headline
"Headline plug-in"
6749 "Regexp string for anything-headline to scan.")
6750 (anything-document-attribute 'condition
"Headline plug-in"
6751 "A sexp representing the condition to use anything-headline.")
6752 (anything-document-attribute 'subexp
"Headline plug-in"
6753 "Display (match-string-no-properties subexp).")
6756 (defun anything-headline-get-candidates (regexp subexp
)
6757 (with-current-buffer anything-current-buffer
6759 (goto-char (point-min))
6760 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
6761 (let (hierarchy curhead
)
6763 (if (numberp subexp
)
6764 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
6765 (cons (buffer-substring (point-at-bol) (point-at-eol))
6767 (hierarchies (headlines)
6768 (1+ (loop for
(_ . hierarchy
) in headlines
6769 maximize hierarchy
)))
6771 (loop for i from
0 to hierarchy
6772 collecting
(aref curhead i
)))
6773 (arrange (headlines)
6774 (unless (null headlines
) ; FIX headlines empty bug!
6775 (loop with curhead
= (make-vector (hierarchies headlines
) "")
6776 for
((str . pt
) . hierarchy
) in headlines
6777 do
(aset curhead hierarchy str
)
6780 (format "H%d:%s" (1+ hierarchy
)
6781 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
6786 (loop for re in regexp
6787 for hierarchy from
0
6788 do
(goto-char (point-min))
6791 while
(re-search-forward re nil t
)
6792 collect
(cons (matched) hierarchy
)))
6793 (lambda (a b
) (> (cdar b
) (cdar a
)))))
6794 (loop while
(re-search-forward regexp nil t
)
6795 collect
(matched))))))))
6798 (defun anything-headline-make-candidate-buffer (regexp subexp
)
6799 (with-current-buffer (anything-candidate-buffer 'local
)
6800 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
6803 (with-current-buffer anything-current-buffer
6804 (line-number-at-pos pos
))
6807 (defun anything-headline-goto-position (pos recenter
)
6810 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
6812 (defun anything-revert-buffer (candidate)
6813 (with-current-buffer candidate
6814 (when (buffer-modified-p)
6815 (revert-buffer t t
))))
6817 (defun anything-revert-marked-buffers (ignore)
6818 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
6820 (defun anything-kill-marked-buffers (ignore)
6821 (mapc 'kill-buffer
(anything-marked-candidates)))
6823 ;; Plug-in: persistent-help
6824 (defun anything-compile-source--persistent-help (source)
6825 (append source
'((header-line . anything-persistent-help-string
))))
6826 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
6828 (defun anything-persistent-help-string ()
6829 (substitute-command-keys
6830 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
6831 (or (anything-interpret-value (anything-attr 'persistent-help
))
6832 (anything-aif (or (assoc-default 'persistent-action
6833 (anything-get-current-source))
6834 (assoc-default 'action
6835 (anything-get-current-source)))
6836 (cond ((symbolp it
) (symbol-name it
))
6837 ((listp it
) (or (ignore-errors (caar it
)) ""))))
6839 " (keeping session)")))
6841 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
6842 "A string to explain persistent-action of this source.
6843 It also accepts a function or a variable name.")
6845 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
6847 ;; Plug-in: default-action
6848 (defun anything-compile-source--default-action (source)
6849 (anything-aif (assoc-default 'default-action source
)
6850 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
6853 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
6854 (anything-document-attribute 'default-action
"default-action plug-in"
6857 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6859 (defun anything-c-find-file-or-marked (candidate)
6860 "Open file CANDIDATE or open anything marked files in background."
6861 (let ((marked (anything-marked-candidates)))
6862 (if (> (length marked
) 1)
6863 (mapc 'find-file-noselect marked
)
6864 (find-file-at-point candidate
))))
6866 ;; FIXME there is a bug in dired that confuse all dired commands
6867 ;; when using this feature, so i suspend it until bug is fixed in emacs.
6869 ;; (defun anything-c-create-dired-on-marked (candidate)
6870 ;; "Create a new dired buffer with only marked candidates."
6871 ;; (let ((marked (anything-marked-candidates))
6872 ;; (buffer-name (read-string "New Dired Buffer: ")))
6873 ;; (dired (cons buffer-name marked))))
6875 (defun anything-delete-marked-files (ignore)
6876 (let* ((files (anything-marked-candidates))
6877 (len (length files
)))
6879 (format "Delete *%s File(s):\n%s"
6881 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
6882 (message "(No deletions performed)")
6884 (set-text-properties 0 (length i
) nil i
)
6885 (anything-c-delete-file i
))
6886 (message "%s File(s) deleted" len
))))
6888 (defun anything-ediff-marked-buffers (candidate &optional merge
)
6889 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
6890 With optional arg `merge' call `ediff-merge-buffers'."
6891 (let ((lg-lst (length (anything-marked-candidates)))
6895 (error "Error:You have to mark at least 1 buffer"))
6897 (setq buf1 anything-current-buffer
6898 buf2
(first (anything-marked-candidates))))
6900 (setq buf1
(first (anything-marked-candidates))
6901 buf2
(second (anything-marked-candidates))))
6903 (error "Error:To much buffers marked!")))
6905 (ediff-merge-buffers buf1 buf2
)
6906 (ediff-buffers buf1 buf2
))))
6908 (defun anything-bookmark-get-bookmark-from-name (bmk)
6909 "Return bookmark name even if it is a bookmark with annotation.
6910 e.g prepended with *.
6911 Return nil if bmk is not a valid bookmark."
6912 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
6913 (if (assoc bookmark bookmark-alist
)
6915 (when (assoc bmk bookmark-alist
)
6918 (defun anything-delete-marked-bookmarks (ignore)
6919 "Delete this bookmark or all marked bookmarks."
6920 (dolist (i (anything-marked-candidates))
6921 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
6924 (defun anything-require-or-error (feature function
)
6925 (or (require feature nil t
)
6926 (error "Need %s to use `%s'." feature function
)))
6928 (defun anything-find-buffer-on-elscreen (candidate)
6929 "Open buffer in new screen, if marked buffers open all in elscreens."
6930 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
6931 (anything-aif (anything-marked-candidates)
6933 (let ((target-screen (elscreen-find-screen-by-buffer
6934 (get-buffer i
) 'create
)))
6935 (elscreen-goto target-screen
)))
6936 (let ((target-screen (elscreen-find-screen-by-buffer
6937 (get-buffer candidate
) 'create
)))
6938 (elscreen-goto target-screen
))))
6940 (defun anything-elscreen-find-file (file)
6941 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
6942 (elscreen-find-file file
))
6944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6946 ;;;; Type Attributes
6947 (define-anything-type-attribute 'buffer
6950 '(("Switch to buffer other window" . switch-to-buffer-other-window
)
6951 ("Switch to buffer" . switch-to-buffer
))
6952 '(("Switch to buffer" . switch-to-buffer
)
6953 ("Switch to buffer other window" . switch-to-buffer-other-window
)
6954 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)))
6955 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
6956 ("View buffer" . view-buffer
)
6957 ("Display buffer" . display-buffer
)
6958 ("Revert buffer" . anything-revert-buffer
)
6959 ("Revert Marked buffers" . anything-revert-marked-buffers
)
6960 ("Insert buffer" . insert-buffer
)
6961 ("Kill buffer" . kill-buffer
)
6962 ("Kill Marked buffers" . anything-kill-marked-buffers
)
6963 ("Diff with file" . diff-buffer-with-file
)
6964 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
6965 ("Ediff Merge marked buffers" .
(lambda (candidate)
6966 (anything-ediff-marked-buffers candidate t
))))
6967 (persistent-help .
"Show this buffer")
6968 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers
))
6969 "Buffer or buffer name.")
6971 (define-anything-type-attribute 'file
6974 '(("Find file other window" . find-file-other-window
)
6975 ("Find file(s)" . anything-find-many-files
)
6976 ("Find file as root" . anything-find-file-as-root
))
6977 '(("Find file" . anything-find-many-files
)
6978 ("Find file as root" . anything-find-file-as-root
)
6979 ("Find file other window" . find-file-other-window
)
6980 ("Find file other frame" . find-file-other-frame
)))
6981 ("Open dired in file's directory" . anything-c-open-dired
)
6982 ("View file" . view-file
)
6983 ("Insert file" . insert-file
)
6984 ("Delete file(s)" . anything-delete-marked-files
)
6985 ("Open file externally" . anything-c-open-file-externally
)
6986 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
6987 ("Find file in hex dump" . hexl-find-file
))
6988 (persistent-help .
"Show this file")
6989 (action-transformer anything-c-transform-file-load-el
6990 anything-c-transform-file-browse-url
)
6991 (candidate-transformer anything-c-w32-pathname-transformer
6992 anything-c-skip-current-file
6993 anything-c-skip-boring-files
6994 anything-c-shorten-home-path
))
6997 (let ((actions '(("Describe command" . describe-function
)
6998 ("Add command to kill ring" . anything-c-kill-new
)
6999 ("Go to command's definition" . find-function
)
7000 ("Debug on entry" . debug-on-entry
)
7001 ("Cancel debug on entry" . cancel-debug-on-entry
)
7002 ("Trace function" . trace-function
)
7003 ("Trace function (background)" . trace-function-background
)
7004 ("Untrace function" . untrace-function
))))
7005 (define-anything-type-attribute 'command
7006 `((action ("Call interactively" . anything-c-call-interactively
)
7008 ;; Sort commands according to their usage count.
7009 (filtered-candidate-transformer . anything-c-adaptive-sort
)
7010 (coerce . anything-c-symbolify
)
7011 (persistent-action . describe-function
))
7012 "Command. (string or symbol)")
7014 (define-anything-type-attribute 'function
7015 `((action .
,actions
)
7016 (action-transformer anything-c-transform-function-call-interactively
)
7017 (candidate-transformer anything-c-mark-interactive-functions
)
7018 (coerce . anything-c-symbolify
))
7019 "Function. (string or symbol)"))
7021 (define-anything-type-attribute 'variable
7022 '((action ("Describe variable" . describe-variable
)
7023 ("Add variable to kill ring" . anything-c-kill-new
)
7024 ("Go to variable's definition" . find-variable
)
7025 ("Set variable" . anything-c-set-variable
))
7026 (coerce . anything-c-symbolify
))
7029 (define-anything-type-attribute 'sexp
7030 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
7031 ("Add s-expression to kill ring" . kill-new
))
7032 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
7033 "String representing S-Expressions.")
7035 (define-anything-type-attribute 'bookmark
7036 `((coerce . anything-bookmark-get-bookmark-from-name
)
7038 ("Jump to bookmark" .
(lambda (bookmark)
7039 (let ((current-prefix-arg anything-current-prefix-arg
))
7040 (bookmark-jump bookmark
))
7042 ("Jump to BM other window" .
(lambda (bookmark)
7043 (bookmark-jump-other-window bookmark
)
7045 ("Bookmark edit annotation" . bookmark-edit-annotation
)
7046 ("Bookmark show annotation" . bookmark-show-annotation
)
7047 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
7048 ,@(when (fboundp 'bmkext-edit-bookmark
)
7049 '(("Edit Bookmark" . bmkext-edit-bookmark
)))
7050 ("Rename bookmark" . bookmark-rename
)
7051 ("Relocate bookmark" . bookmark-relocate
)))
7054 (define-anything-type-attribute 'line
7055 '((display-to-real . anything-c-display-to-real-line
)
7056 (action ("Go to Line" . anything-c-action-line-goto
)))
7057 "LINENO:CONTENT string, eg. \" 16:foo\".
7059 Optional `target-file' attribute is a name of target file.
7061 Optional `before-jump-hook' attribute is a function with no
7062 arguments which is called before jumping to position.
7064 Optional `after-jump-hook' attribute is a function with no
7065 arguments which is called after jumping to position.
7067 If `adjust' attribute is specified, searches the line whose
7068 content is CONTENT near the LINENO.
7070 If `recenter' attribute is specified, the line is displayed at
7071 the center of window, otherwise at the top of window.
7074 (define-anything-type-attribute 'file-line
7075 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
7077 (action ("Go to" . anything-c-action-file-line-goto
)))
7078 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
7080 Optional `default-directory' attribute is a default-directory
7081 FILENAME is interpreted.
7083 Optional `before-jump-hook' attribute is a function with no
7084 arguments which is called before jumping to position.
7086 Optional `after-jump-hook' attribute is a function with no
7087 arguments which is called after jumping to position.
7089 If `adjust' attribute is specified, searches the line whose
7090 content is CONTENT near the LINENO.
7092 If `recenter' attribute is specified, the line is displayed at
7093 the center of window, otherwise at the top of window.
7096 (define-anything-type-attribute 'timer
7097 '((real-to-display . anything-c-timer-real-to-display
)
7098 (action ("Cancel Timer" . cancel-timer
)
7099 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
7100 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
7101 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
7102 (persistent-help .
"Describe Function"))
7105 ;;;; Default `anything-sources'
7106 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
7107 ;; tend to invoke M-x anything directly. So I offer default setting.
7108 (setq anything-sources
7109 '(anything-c-source-buffers+
7110 anything-c-source-recentf
7111 anything-c-source-files-in-current-dir
+))
7114 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7115 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
7117 (when (fboundp 'expectations
)
7119 (desc "candidates-file plug-in")
7120 (expect '(anything-p-candidats-file-init)
7121 (assoc-default 'init
7122 (car (anything-compile-sources
7124 (candidates-file .
"test.txt")))
7125 '(anything-compile-source--candidates-file)))))
7126 (expect '(anything-p-candidats-file-init
7128 (assoc-default 'init
7129 (car (anything-compile-sources
7131 (candidates-file .
"test.txt")
7132 (init .
(lambda () 1))))
7133 '(anything-compile-source--candidates-file)))))
7134 (expect '(anything-p-candidats-file-init
7136 (assoc-default 'init
7137 (car (anything-compile-sources
7139 (candidates-file .
"test.txt")
7140 (init (lambda () 1))))
7141 '(anything-compile-source--candidates-file)))))
7143 ;; (desc "anything-c-source-buffers")
7144 ;; (expect '(("Buffers" ("foo" "curbuf")))
7145 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
7146 ;; (let ((anything-c-boring-buffer-regexp
7151 ;; " *Echo Area" " *Minibuf"))))
7152 ;; (flet ((buffer-name (&optional x) x))
7153 ;; (anything-test-candidates 'anything-c-source-buffers))))
7154 (desc "anything-c-stringify")
7156 (anything-c-stringify "str1"))
7158 (anything-c-stringify 'str2
))
7159 (desc "anything-c-symbolify")
7161 (anything-c-symbolify "sym1"))
7163 (anything-c-symbolify 'sym2
))
7164 (desc "plug-in:default-action")
7165 (expect '(((action ("default" . default
) ("original" . original
))
7166 (default-action .
("default" . default
))
7167 (action ("original" . original
))))
7168 (anything-compile-sources
7169 '(((default-action .
("default" . default
))
7170 (action ("original" . original
))))
7171 '(anything-compile-source--default-action)))
7172 (expect '(((action ("a1" . a1
) ("a2" . a2
))
7173 (default-action .
("a1" . a1
))
7174 (action ("a1" . a1
) ("a2" . a2
))))
7175 (anything-compile-sources
7176 '(((default-action .
("a1" . a1
))
7177 (action ("a1" . a1
) ("a2" . a2
))))
7178 '(anything-compile-source--default-action)))
7179 (expect '(((action ("a2" . a2
) ("a1" . a1
))
7180 (default-action .
("a2" . a2
))
7181 (action ("a1" . a1
) ("a2" . a2
))))
7182 (anything-compile-sources
7183 '(((default-action .
("a2" . a2
))
7184 (action ("a1" . a1
) ("a2" . a2
))))
7185 '(anything-compile-source--default-action))))))
7187 (provide 'anything-config
)
7189 ;;; Local Variables:
7190 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
7193 ;; How to save (DO NOT REMOVE!!)
7194 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
7195 ;;; anything-config.el ends here
7197 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
7198 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
7199 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
7200 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
7201 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
7202 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
7203 ;;; LocalWords: dotimes Thierry online vname
7204 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
7205 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
7206 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
7207 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
7208 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
7209 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
7210 ;;; LocalWords: startpos noselect dont desc