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-list-emacs-process'
141 ;; Preconfigured `anything' for emacs process.
143 ;; Preconfigured Anything for Occur source.
144 ;; `anything-browse-code'
145 ;; Preconfigured anything to browse code.
146 ;; `anything-org-headlines'
147 ;; Preconfigured anything to show org headlines.
148 ;; `anything-kill-buffers'
149 ;; Preconfigured `anything' to kill buffer you selected.
151 ;; Preconfigured anything to build regexps and run query-replace-regexp against.
152 ;; `anything-insert-buffer-name'
153 ;; Insert buffer name.
154 ;; `anything-insert-symbol'
155 ;; Insert current symbol.
156 ;; `anything-insert-selection'
157 ;; Insert current selection.
158 ;; `anything-show-buffer-only'
159 ;; [OBSOLETE] Only show sources about buffer.
160 ;; `anything-show-bbdb-only'
161 ;; [OBSOLETE] Only show sources about BBDB.
162 ;; `anything-show-locate-only'
163 ;; [OBSOLETE] Only show sources about Locate.
164 ;; `anything-show-info-only'
165 ;; [OBSOLETE] Only show sources about Info.
166 ;; `anything-show-imenu-only'
167 ;; [OBSOLETE] Only show sources about Imenu.
168 ;; `anything-show-files-only'
169 ;; [OBSOLETE] Only show sources about File.
170 ;; `anything-show-w3m-bookmarks-only'
171 ;; [OBSOLETE] Only show source about w3m bookmark.
172 ;; `anything-show-colors-only'
173 ;; [OBSOLETE] Only show source about color.
174 ;; `anything-show-kill-ring-only'
175 ;; [OBSOLETE] Only show source about kill ring.
176 ;; `anything-show-this-source-only'
177 ;; Only show this source.
178 ;; `anything-test-sources'
179 ;; List all anything sources for test.
180 ;; `anything-select-source'
182 ;; `anything-find-files-down-one-level'
183 ;; Go down one level like unix command `cd ..'.
184 ;; `anything-find-files'
185 ;; Preconfigured `anything' for anything implementation of `find-file'.
186 ;; `anything-write-file'
187 ;; Preconfigured `anything' providing completion for `write-file'.
188 ;; `anything-insert-file'
189 ;; Preconfigured `anything' providing completion for `insert-file'.
190 ;; `anything-dired-rename-file'
191 ;; Preconfigured `anything' to rename files from dired.
192 ;; `anything-dired-copy-file'
193 ;; Preconfigured `anything' to copy files from dired.
194 ;; `anything-dired-symlink-file'
195 ;; Preconfigured `anything' to symlink files from dired.
196 ;; `anything-dired-hardlink-file'
197 ;; Preconfigured `anything' to hardlink files from dired.
198 ;; `anything-dired-bindings'
199 ;; Replace usual dired commands `C' and `R' by anything ones.
200 ;; `anything-do-grep'
201 ;; Preconfigured anything for grep.
202 ;; `anything-c-grep-precedent-file'
203 ;; Go to precedent file in `anything-do-grep'.
204 ;; `anything-c-grep-next-or-prec-file'
205 ;; Go to next or precedent candidate file in anything grep buffer.
206 ;; `anything-filelist'
207 ;; Preconfigured `anything' to open files instantly.
208 ;; `anything-filelist+'
209 ;; Preconfigured `anything' to open files/buffers/bookmarks instantly.
211 ;; Preconfigured `anything' for Emacs commands.
212 ;; `anything-manage-advice'
213 ;; Preconfigured `anything' to disable/enable function advices.
214 ;; `anything-bookmark-ext'
215 ;; Preconfigured `anything' for bookmark-extensions sources.
216 ;; `anything-simple-call-tree'
217 ;; Preconfigured `anything' for simple-call-tree. List function relationships.
218 ;; `anything-mark-ring'
219 ;; Preconfigured `anything' for `anything-c-source-mark-ring'.
220 ;; `anything-global-mark-ring'
221 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring'.
222 ;; `anything-all-mark-rings'
223 ;; Preconfigured `anything' for `anything-c-source-global-mark-ring' and `anything-c-source-mark-ring'.
224 ;; `anything-yaoddmuse-cache-pages'
225 ;; Fetch the list of files on emacswiki and create cache file.
226 ;; `anything-yaoddmuse-emacswiki-edit-or-view'
227 ;; Preconfigured `anything' to edit or view EmacsWiki page.
228 ;; `anything-yaoddmuse-emacswiki-post-library'
229 ;; Preconfigured `anything' to post library to EmacsWiki.
230 ;; `anything-eval-expression'
231 ;; Preconfigured anything for `anything-c-source-evaluation-result'.
232 ;; `anything-eval-expression-with-eldoc'
233 ;; Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support.
234 ;; `anything-surfraw'
235 ;; Preconfigured `anything' to search PATTERN with search ENGINE.
236 ;; `anything-call-source'
237 ;; Preconfigured `anything' to call anything source.
238 ;; `anything-call-source-from-anything'
239 ;; Call anything source within `anything' session.
240 ;; `anything-execute-anything-command'
241 ;; Preconfigured `anything' to execute preconfigured `anything'.
242 ;; `anything-create-from-anything'
243 ;; Run `anything-create' from `anything' as a fallback.
245 ;; Preconfigured `anything' to do many create actions from STRING.
247 ;; Preconfigured `anything' for top command.
248 ;; `anything-select-xfont'
249 ;; Preconfigured `anything' to select Xfont.
250 ;; `anything-world-time'
251 ;; Preconfigured `anything' to show world time.
253 ;; Preconfigured `anything' : frontend of APT package manager.
254 ;; `anything-c-shell-command-if-needed'
256 ;; `anything-c-run-external-command'
257 ;; Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
258 ;; `anything-ratpoison-commands'
259 ;; Preconfigured `anything' to execute ratpoison commands.
260 ;; `anything-c-set-variable'
261 ;; Set value to VAR interactively.
262 ;; `anything-c-adaptive-save-history'
263 ;; Save history information to file given by `anything-c-adaptive-history-file'.
265 ;; * User variables defined here:
266 ;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "anything-" :var-value t)
267 ;; `anything-c-use-standard-keys'
268 ;; Default Value: nil
269 ;; `anything-c-adaptive-history-file'
270 ;; Default Value: "~/.emacs.d/anything-c-adaptive-history"
271 ;; `anything-c-adaptive-history-length'
273 ;; `anything-c-google-suggest-url'
274 ;; Default Value: "http://google.com/complete/search?output=toolbar&q="
275 ;; `anything-c-google-suggest-search-url'
276 ;; Default Value: "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
277 ;; `anything-google-suggest-use-curl-p'
278 ;; Default Value: nil
279 ;; `anything-c-yahoo-suggest-url'
280 ;; Default Value: "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=G [...]
281 ;; `anything-c-yahoo-suggest-search-url'
282 ;; Default Value: "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
283 ;; `anything-c-boring-buffer-regexp'
284 ;; Default Value: "\\ (\\` \\)\\|\\*anything\\| \\*Echo Area\\| \\*Minibuf"
285 ;; `anything-c-boring-file-regexp'
286 ;; Default Value: "/\\ (?:\\(?:\\.\\(?:git\\|hg\\|svn\\)\\|CVS\\|_darcs\\)\\)\\(?:/\\|$\\)\\| [...]
287 ;; `anything-kill-ring-threshold'
289 ;; `anything-su-or-sudo'
290 ;; Default Value: "su"
291 ;; `anything-for-files-prefered-list'
292 ;; Default Value: (anything-c-source-ffap-line anything-c-source-ffap-guesser anything-c-sou [...]
293 ;; `anything-create--actions-private'
294 ;; Default Value: nil
295 ;; `anything-allow-skipping-current-buffer'
297 ;; `anything-c-enable-eval-defun-hack'
299 ;; `anything-tramp-verbose'
301 ;; `anything-raise-command'
302 ;; Default Value: nil
303 ;; `anything-command-map-prefix-key'
304 ;; Default Value: "<f5> a"
305 ;; `anything-c-find-files-show-icons'
307 ;; `anything-c-find-files-icons-directory'
308 ;; Default Value: "/usr/share/emacs/23.2.50/etc/images/tree-widget/default"
309 ;; `anything-c-browse-code-regexp-lisp'
310 ;; Default Value: "^ * (def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|type\\|th [...]
311 ;; `anything-c-browse-code-regexp-python'
312 ;; Default Value: "\\<def\\>\\|\\<class\\>"
313 ;; `anything-c-browse-code-regexp-alist'
314 ;; Default Value: ((lisp-interaction-mode . "^ *(def\\(un\\|subst\\|macro\\|face\\|alias\\|a [...]
315 ;; `anything-c-external-programs-associations'
316 ;; Default Value: nil
317 ;; `anything-c-filelist-file-name'
318 ;; Default Value: nil
320 ;; * Anything sources defined here:
321 ;; [EVAL] (autodoc-document-lisp-buffer :type 'anything-source :prefix "anything-" :any-sname t)
322 ;; `anything-c-source-regexp' (Regexp Builder)
323 ;; `anything-c-source-buffers' (Buffers)
324 ;; `anything-c-source-buffer-not-found' (Create buffer)
325 ;; `anything-c-source-buffers+' (Buffers)
326 ;; `anything-c-source-file-name-history' (File Name History)
327 ;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
328 ;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
329 ;; `anything-c-source-find-files' (Find Files (`C-.':Go to precedent level))
330 ;; `anything-c-source-write-file' (Write File (`C-.':Go to precedent level))
331 ;; `anything-c-source-insert-file' (Insert File (`C-.':Go to precedent level))
332 ;; `anything-c-source-copy-files' (Copy Files (`C-.':Go to precedent level))
333 ;; `anything-c-source-symlink-files' (Symlink Files (`C-.':Go to precedent level))
334 ;; `anything-c-source-hardlink-files' (Hardlink Files (`C-.':Go to precedent level))
335 ;; `anything-c-source-file-cache-initialized' ()
336 ;; `anything-c-source-file-cache' (File Cache)
337 ;; `anything-c-source-locate' (Locate)
338 ;; `anything-c-source-recentf' (Recentf)
339 ;; `anything-c-source-ffap-guesser' (File at point)
340 ;; `anything-c-source-ffap-line' (File/Lineno at point)
341 ;; `anything-c-source-files-in-all-dired' (Files in all dired buffer.)
342 ;; `anything-c-source-filelist' (FileList)
343 ;; `anything-c-source-info-pages' (Info Pages)
344 ;; `anything-c-source-info-elisp' (Info index: elisp)
345 ;; `anything-c-source-info-cl' (Info index: cl)
346 ;; `anything-c-source-info-org' (Info index: org)
347 ;; `anything-c-source-info-ratpoison' (Info index: ratpoison)
348 ;; `anything-c-source-info-zsh' (Info index: zsh)
349 ;; `anything-c-source-info-bash' (Info index: bash)
350 ;; `anything-c-source-info-coreutils' (Info index: coreutils)
351 ;; `anything-c-source-info-fileutils' (Info index: fileutils)
352 ;; `anything-c-source-info-find' (Info index: find)
353 ;; `anything-c-source-info-sh-utils' (Info index: sh-utils)
354 ;; `anything-c-source-info-textutils' (Info index: textutils)
355 ;; `anything-c-source-info-libc' (Info index: libc)
356 ;; `anything-c-source-info-make' (Info index: make)
357 ;; `anything-c-source-info-automake' (Info index: automake)
358 ;; `anything-c-source-info-autoconf' (Info index: autoconf)
359 ;; `anything-c-source-info-emacs-lisp-intro' (Info index: emacs-lisp-intro)
360 ;; `anything-c-source-info-emacs' (Info index: emacs)
361 ;; `anything-c-source-info-elib' (Info index: elib)
362 ;; `anything-c-source-info-eieio' (Info index: eieio)
363 ;; `anything-c-source-info-gauche-refe' (Info index: gauche)
364 ;; `anything-c-source-info-guile' (Info index: guile)
365 ;; `anything-c-source-info-guile-tut' (Info index: guile-tut)
366 ;; `anything-c-source-info-goops' (Info index: goops)
367 ;; `anything-c-source-info-screen' (Info index: screen)
368 ;; `anything-c-source-info-latex' (Info index: latex)
369 ;; `anything-c-source-info-gawk' (Info index: gawk)
370 ;; `anything-c-source-info-sed' (Info index: sed)
371 ;; `anything-c-source-info-m4' (Info index: m4)
372 ;; `anything-c-source-info-wget' (Info index: wget)
373 ;; `anything-c-source-info-binutils' (Info index: binutils)
374 ;; `anything-c-source-info-as' (Info index: as)
375 ;; `anything-c-source-info-bfd' (Info index: bfd)
376 ;; `anything-c-source-info-gprof' (Info index: gprof)
377 ;; `anything-c-source-info-ld' (Info index: ld)
378 ;; `anything-c-source-info-diff' (Info index: diff)
379 ;; `anything-c-source-info-flex' (Info index: flex)
380 ;; `anything-c-source-info-grep' (Info index: grep)
381 ;; `anything-c-source-info-gzip' (Info index: gzip)
382 ;; `anything-c-source-info-libtool' (Info index: libtool)
383 ;; `anything-c-source-info-texinfo' (Info index: texinfo)
384 ;; `anything-c-source-info-info' (Info index: info)
385 ;; `anything-c-source-info-gdb' (Info index: gdb)
386 ;; `anything-c-source-info-stabs' (Info index: stabs)
387 ;; `anything-c-source-info-cvsbook' (Info index: cvsbook)
388 ;; `anything-c-source-info-cvs' (Info index: cvs)
389 ;; `anything-c-source-info-bison' (Info index: bison)
390 ;; `anything-c-source-info-id-utils' (Info index: id-utils)
391 ;; `anything-c-source-info-global' (Info index: global)
392 ;; `anything-c-source-man-pages' (Manual Pages)
393 ;; `anything-c-source-complex-command-history' (Complex Command History)
394 ;; `anything-c-source-extended-command-history' (Emacs Commands History)
395 ;; `anything-c-source-emacs-commands' (Emacs Commands)
396 ;; `anything-c-source-lacarte' (Lacarte)
397 ;; `anything-c-source-emacs-functions' (Emacs Functions)
398 ;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
399 ;; `anything-c-source-advice' (Function Advice)
400 ;; `anything-c-source-emacs-variables' (Emacs Variables)
401 ;; `anything-c-source-bookmarks' (Bookmarks)
402 ;; `anything-c-source-bookmark-set' (Set Bookmark)
403 ;; `anything-c-source-bm' (Visible Bookmarks)
404 ;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
405 ;; `anything-c-source-bookmarks-su' (Bookmarks-root)
406 ;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
407 ;; `anything-c-source-bmkext-addressbook' (Bookmark Addressbook)
408 ;; `anything-c-source-bookmark-w3m' (Bookmark W3m)
409 ;; `anything-c-source-bookmark-images' (Bookmark Images)
410 ;; `anything-c-source-bookmark-man' (Bookmark Woman&Man)
411 ;; `anything-c-source-bookmark-gnus' (Bookmark Gnus)
412 ;; `anything-c-source-bookmark-info' (Bookmark Info)
413 ;; `anything-c-source-bookmark-files&dirs' (Bookmark Files&Directories)
414 ;; `anything-c-source-bookmark-su-files&dirs' (Bookmark Root-Files&Directories)
415 ;; `anything-c-source-bookmark-ssh-files&dirs' (Bookmark Ssh-Files&Directories)
416 ;; `anything-c-source-firefox-bookmarks' (Firefox Bookmarks)
417 ;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
418 ;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
419 ;; `anything-c-source-imenu' (Imenu)
420 ;; `anything-c-source-ctags' (Exuberant ctags)
421 ;; `anything-c-source-semantic' (Semantic Tags)
422 ;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
423 ;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
424 ;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
425 ;; `anything-c-source-customize-face' (Customize Face)
426 ;; `anything-c-source-colors' (Colors)
427 ;; `anything-c-source-tracker-search' (Tracker Search)
428 ;; `anything-c-source-mac-spotlight' (mdfind)
429 ;; `anything-c-source-kill-ring' (Kill Ring)
430 ;; `anything-c-source-mark-ring' (mark-ring)
431 ;; `anything-c-source-global-mark-ring' (global-mark-ring)
432 ;; `anything-c-source-register' (Registers)
433 ;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
434 ;; `anything-c-source-rd-headline' (RD HeadLine)
435 ;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
436 ;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
437 ;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
438 ;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
439 ;; `anything-c-source-org-headline' (Org HeadLine)
440 ;; `anything-c-source-yaoddmuse-emacswiki-edit-or-view' (Yaoddmuse Edit or View (EmacsWiki))
441 ;; `anything-c-source-yaoddmuse-emacswiki-post-library' (Yaoddmuse Post library (EmacsWiki))
442 ;; `anything-c-source-eev-anchor' (Anchors)
443 ;; `anything-c-source-org-keywords' (Org Keywords)
444 ;; `anything-c-source-picklist' (Picklist)
445 ;; `anything-c-source-bbdb' (BBDB)
446 ;; `anything-c-source-evaluation-result' (Evaluation Result)
447 ;; `anything-c-source-calculation-result' (Calculation Result)
448 ;; `anything-c-source-google-suggest' (Google Suggest)
449 ;; `anything-c-source-yahoo-suggest' (Yahoo Suggest)
450 ;; `anything-c-source-emms-streams' (Emms Streams)
451 ;; `anything-c-source-emms-dired' (Music Directory)
452 ;; `anything-c-source-emms-files' (Emms files)
453 ;; `anything-c-source-jabber-contacts' (Jabber Contacts)
454 ;; `anything-c-source-call-source' (Call anything source)
455 ;; `anything-c-source-anything-commands' (Preconfigured Anything)
456 ;; `anything-c-source-occur' (Occur)
457 ;; `anything-c-source-browse-code' (Browse code)
458 ;; `anything-c-source-create' (Create)
459 ;; `anything-c-source-minibuffer-history' (Minibuffer History)
460 ;; `anything-c-source-elscreen' (Elscreen)
461 ;; `anything-c-source-top' (Top (Press C-c C-u to refresh))
462 ;; `anything-c-source-absolute-time-timers' (Absolute Time Timers)
463 ;; `anything-c-source-idle-time-timers' (Idle Time Timers)
464 ;; `anything-c-source-xrandr-change-resolution' (Change Resolution)
465 ;; `anything-c-source-xfonts' (X Fonts)
466 ;; `anything-c-source-time-world' (Time World List)
467 ;; `anything-c-source-apt' (APT)
468 ;; `anything-c-source-gentoo' (Portage sources)
469 ;; `anything-c-source-use-flags' (Use Flags)
470 ;; `anything-c-source-emacs-process' (Emacs Process)
471 ;; `anything-c-source-ratpoison-commands' (Ratpoison Commands)
473 ;; *** END auto-documentation
478 ;; Change log of this file is found at
479 ;; http://repo.or.cz/w/anything-config.git/history/master:/anything-config.el
481 ;; Change log of this project is found at
482 ;; http://repo.or.cz/w/anything-config.git?a=shortlog
487 ;; Tassilo Horn <tassilo@member.fsf.org>
488 ;; Vagn Johansen <gonz808@hotmail.com>
489 ;; Mathias Dahl <mathias.dahl@gmail.com>
490 ;; Bill Clementson <billclem@gmail.com>
491 ;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
492 ;; Drew Adams <drew.adams@oracle.com>
493 ;; Jason McBrayer <jmcbray@carcosa.net>
494 ;; Andy Stewart <lazycat.manatee@gmail.com>
495 ;; Thierry Volpiatto <thierry.volpiatto@gmail.com>
496 ;; rubikitch <rubikitch@ruby-lang.org>
497 ;; Scott Vokes <vokes.s@gmail.com>
502 ;; Evaluate (autodoc-update-all) before commit. This function
503 ;; generates anything-c-source-* / functions / options list.
505 ;; Install also developer-tools/autodoc.el
506 ;; And eval it or run interactively.
508 ;; [EVAL IT] (autodoc-update-all)
510 ;; Please write details documentation about function, then others will
511 ;; read code more easier. -- Andy Stewart
517 ;; - Fix documentation, now many functions haven't documentations.
529 (let ((version "1.263"))
530 (when (and (string= "1." (substring version
0 2))
531 (string-match "1\.\\([0-9]+\\)" anything-version
)
532 (< (string-to-number (match-string 1 anything-version
))
533 (string-to-number (substring version
2))))
534 (error "Please update anything.el!!
536 http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
538 or M-x install-elisp-from-emacswiki anything.el")))
540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
541 (defgroup anything-config nil
542 "Predefined configurations for `anything.el'."
545 (defcustom anything-c-use-standard-keys nil
546 "Whether use standard keybindings. (no effect)
548 Key definitions in anything-config.el are removed because
549 anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
550 minibuffer history, C-s for isearch, etc.
552 If you use `iswitchb' with `anything',
553 evaluate (anything-iswitchb-setup) . Then some bindings that
554 conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
555 history, are removed from `anything-map'. "
557 :group
'anything-config
)
559 (defcustom anything-c-adaptive-history-file
"~/.emacs.d/anything-c-adaptive-history"
560 "Path of file where history information is stored."
562 :group
'anything-config
)
564 (defcustom anything-c-adaptive-history-length
50
565 "Maximum number of candidates stored for a source."
567 :group
'anything-config
)
569 (defcustom anything-c-google-suggest-url
570 "http://google.com/complete/search?output=toolbar&q="
571 "URL used for looking up Google suggestions."
573 :group
'anything-config
)
575 (defcustom anything-c-google-suggest-search-url
576 "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
577 "URL used for Google searching."
579 :group
'anything-config
)
581 (defcustom anything-google-suggest-use-curl-p nil
582 "*When non--nil use CURL to get info from `anything-c-google-suggest-url'.
583 Otherwise `url-retrieve-synchronously' is used."
585 :group
'anything-config
)
587 (defcustom anything-c-yahoo-suggest-url
588 "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
589 "Url used for looking up Yahoo suggestions."
591 :group
'anything-config
)
593 (defcustom anything-c-yahoo-suggest-search-url
594 "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p="
595 "Url used for Yahoo searching."
597 :group
'anything-config
)
599 (defcustom anything-c-boring-buffer-regexp
605 " *Echo Area" " *Minibuf"))
606 "The regexp that match boring buffers.
607 Buffer candidates matching this regular expression will be
608 filtered from the list of candidates if the
609 `anything-c-skip-boring-buffers' candidate transformer is used, or
610 they will be displayed with face `file-name-shadow' if
611 `anything-c-shadow-boring-buffers' is used."
613 :group
'anything-config
)
614 ;; (string-match anything-c-boring-buffer-regexp "buf")
615 ;; (string-match anything-c-boring-buffer-regexp " hidden")
616 ;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
618 (defcustom anything-c-boring-file-regexp
620 ;; Boring directories
621 (and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol
))
623 (and line-start
".#")
624 (and (or ".class" ".la" ".o" "~") eol
)))
625 "The regexp that match boring files.
626 File candidates matching this regular expression will be
627 filtered from the list of candidates if the
628 `anything-c-skip-boring-files' candidate transformer is used, or
629 they will be displayed with face `file-name-shadow' if
630 `anything-c-shadow-boring-files' is used."
632 :group
'anything-config
)
634 (defcustom anything-kill-ring-threshold
10
635 "*Minimum length to be listed by `anything-c-source-kill-ring'."
637 :group
'anything-config
)
639 (defcustom anything-su-or-sudo
"su"
640 "What command to use for root access."
642 :group
'anything-config
)
644 (defcustom anything-for-files-prefered-list
645 '(anything-c-source-ffap-line
646 anything-c-source-ffap-guesser
647 anything-c-source-buffers
+
648 anything-c-source-recentf
649 anything-c-source-bookmarks
650 anything-c-source-file-cache
651 anything-c-source-files-in-current-dir
+
652 anything-c-source-locate
)
653 "Your prefered sources to find files."
655 :group
'anything-config
)
657 (defcustom anything-create--actions-private nil
658 "User defined actions for `anything-create' / `anything-c-source-create'.
659 It is a list of (DISPLAY . FUNCTION) pairs like `action'
660 attribute of `anything-sources'.
662 It is prepended to predefined pairs."
664 :group
'anything-config
)
666 (defcustom anything-allow-skipping-current-buffer t
667 "Show current buffer or not in anything buffer"
669 :group
'anything-config
)
671 (defcustom anything-c-enable-eval-defun-hack t
672 "*If non-nil, execute `anything' using the source at point when C-M-x is pressed.
673 This hack is invoked when pressing C-M-x in the form \
674 (defvar anything-c-source-XXX ...) or (setq anything-c-source-XXX ...)."
676 :group
'anything-config
)
678 (defcustom anything-tramp-verbose
0
679 "*Just like `tramp-verbose' but specific to anything.
680 When set to 0 don't show tramp messages in anything.
681 If you want to have the default tramp messages set it to 3."
683 :group
'anything-config
)
685 (defcustom anything-raise-command nil
686 "*A shell command to jump to a window running specific program.
687 Need external program wmctrl.
688 This will be use with `format', so use something like \"wmctrl -xa %s\"."
690 :group
'anything-config
)
692 (defun anything-set-anything-command-map-prefix-key (var key
)
693 (when (boundp 'anything-command-map-prefix-key
)
694 (global-unset-key (read-kbd-macro anything-command-map-prefix-key
)))
695 (setq anything-command-map-prefix-key key
)
696 (global-set-key (read-kbd-macro anything-command-map-prefix-key
)
697 'anything-command-map
))
699 (defcustom anything-command-map-prefix-key
"<f5> a"
700 "*The prefix key for all `anything-command-map' commands.
703 This default value is very likely to be changed,
704 because it is under discussion."
706 :set
'anything-set-anything-command-map-prefix-key
707 :group
'anything-config
)
709 (defcustom anything-c-find-files-show-icons nil
710 "*Whether show or hide icons in `anything-find-files'."
712 :group
'anything-config
)
714 (defcustom anything-c-find-files-icons-directory
715 (concat (car image-load-path
) "tree-widget/default")
716 "*Default path where to find files and directory icons."
718 :group
'anything-config
)
720 (defcustom anything-c-browse-code-regexp-lisp
721 "^ *\(def\\(un\\|subst\\|macro\\|face\\|alias\\|advice\\|struct\\|\
722 type\\|theme\\|var\\|group\\|custom\\|const\\|method\\|class\\)"
723 "*Regexp used to parse lisp buffer when browsing code."
725 :group
'anything-config
)
727 (defcustom anything-c-browse-code-regexp-python
728 "\\<def\\>\\|\\<class\\>"
729 "*Regexp used to parse python buffer when browsing code."
731 :group
'anything-config
)
733 (defcustom anything-c-browse-code-regexp-alist
734 `((lisp-interaction-mode .
,anything-c-browse-code-regexp-lisp
)
735 (emacs-lisp-mode .
,anything-c-browse-code-regexp-lisp
)
736 (lisp-mode .
,anything-c-browse-code-regexp-lisp
)
737 (python-mode .
,anything-c-browse-code-regexp-python
))
738 "*Alist to store regexps for browsing code corresponding \
739 to a specific `major-mode'."
741 :group
'anything-config
)
743 (defcustom anything-c-external-programs-associations nil
744 "*Alist to store externals programs associated with file extension.
745 This variable overhide setting in .mailcap file.
746 e.g : '\(\(\"jpg\" . \"gqview\"\) (\"pdf\" . \"xpdf\"\)\) "
748 :group
'anything-config
)
751 (defun anything-configuration ()
752 "Customize `anything'."
754 (customize-group "anything-config"))
756 ;;; Anything-command-map
758 (defvar anything-command-map
)
759 (define-prefix-command 'anything-command-map
)
761 ;; rubikitch: Please change it freely because it is in discussion. I'll track from git.
762 (define-key anything-command-map
(kbd "<SPC>") 'anything-execute-anything-command
)
763 (define-key anything-command-map
(kbd "e") 'anything-etags-maybe-at-point
)
764 (define-key anything-command-map
(kbd "l") 'anything-locate
)
765 (define-key anything-command-map
(kbd "s") 'anything-surfraw
)
766 (define-key anything-command-map
(kbd "r") 'anything-regexp
)
767 (define-key anything-command-map
(kbd "w") 'anything-w3m-bookmarks
)
768 (define-key anything-command-map
(kbd "x") 'anything-firefox-bookmarks
)
769 (define-key anything-command-map
(kbd "#") 'anything-emms
)
770 (define-key anything-command-map
(kbd "m") 'anything-man-woman
)
771 (define-key anything-command-map
(kbd "t") 'anything-top
)
772 (define-key anything-command-map
(kbd "i") 'anything-imenu
)
773 (define-key anything-command-map
(kbd "p") 'anything-list-emacs-process
)
774 (define-key anything-command-map
(kbd "C-x r b") 'anything-c-pp-bookmarks
)
775 (define-key anything-command-map
(kbd "M-y") 'anything-show-kill-ring
)
776 (define-key anything-command-map
(kbd "C-c <SPC>") 'anything-all-mark-rings
)
777 (define-key anything-command-map
(kbd "C-x C-f") 'anything-find-files
)
778 (define-key anything-command-map
(kbd "f") 'anything-for-files
)
779 (define-key anything-command-map
(kbd "C-:") 'anything-eval-expression-with-eldoc
)
780 (define-key anything-command-map
(kbd "C-,") 'anything-calcul-expression
)
781 (define-key anything-command-map
(kbd "M-x") 'anything-M-x
)
782 (define-key anything-command-map
(kbd "C-x C-w") 'anything-write-file
)
783 (define-key anything-command-map
(kbd "C-x i") 'anything-insert-file
)
784 (define-key anything-command-map
(kbd "M-s o") 'anything-occur
)
785 (define-key anything-command-map
(kbd "M-g s") 'anything-do-grep
)
786 (define-key anything-command-map
(kbd "c") 'anything-colors
)
787 (define-key anything-command-map
(kbd "F") 'anything-select-xfont
)
788 (define-key anything-command-map
(kbd "C-c f") 'anything-recentf
)
789 (define-key anything-command-map
(kbd "C-c g") 'anything-google-suggest
)
790 (define-key anything-command-map
(kbd "h i") 'anything-info-at-point
)
791 (define-key anything-command-map
(kbd "h r") 'anything-info-emacs
)
792 (define-key anything-command-map
(kbd "C-x C-b") 'anything-buffers
+)
793 (define-key anything-command-map
(kbd "C-c C-b") 'anything-browse-code
)
794 (define-key anything-command-map
(kbd "C-x r i") 'anything-register
)
795 (define-key anything-command-map
(kbd "C-c C-x") 'anything-c-run-external-command
)
797 ;; In Emacs 23.1.50, minibuffer-local-must-match-filename-map was renamed to
798 ;; minibuffer-local-filename-must-match-map.
799 (defvar minibuffer-local-filename-must-match-map
(make-sparse-keymap)) ;; Emacs 23.1.+
800 (defvar minibuffer-local-must-match-filename-map
(make-sparse-keymap)) ;; Older Emacsen
801 (dolist (map (list minibuffer-local-filename-completion-map
802 minibuffer-local-completion-map
803 minibuffer-local-must-match-filename-map
804 minibuffer-local-filename-must-match-map
806 minibuffer-local-isearch-map
807 minibuffer-local-must-match-map
808 minibuffer-local-ns-map
))
809 (define-key map
"\C-r" 'anything-minibuffer-history
))
812 (easy-menu-define nil global-map
815 ["All anything commands" anything-execute-anything-command t
]
816 ["Find any Files/Buffers" anything-for-files t
]
819 ["Find files" anything-find-files t
]
820 ["Recent Files" anything-recentf t
]
821 ["Locate" anything-locate t
]
822 ["Bookmarks" anything-c-pp-bookmarks t
])
824 ["Find buffers" anything-buffers
+ t
])
826 ["Emacs Commands" anything-M-x t
]
827 ["Externals Commands" anything-c-run-external-command t
])
829 ["Info at point" anything-info-at-point t
]
830 ["Emacs Manual index" anything-info-emacs t
])
832 ["Org keywords" anything-org-keywords t
]
833 ["Org headlines" anything-org-headlines t
])
835 ["Occur" anything-occur t
]
836 ["Grep" anything-do-grep t
]
837 ["Browse Kill ring" anything-show-kill-ring t
]
838 ["Browse register" anything-register t
]
839 ["Browse code" anything-browse-code t
]
840 ["Mark Ring" anything-all-mark-rings t
]
841 ["Regexp handler" anything-regexp t
]
842 ["Colors & Faces" anything-colors t
]
843 ["Show xfonts" anything-select-xfont t
]
844 ["Imenu" anything-imenu t
]
845 ["Google Suggest" anything-google-suggest t
]
846 ["Eval expression" anything-eval-expression-with-eldoc t
]
847 ["Calcul expression" anything-calcul-expression t
]
848 ["Man pages" anything-man-woman t
]
849 ["Top externals process" anything-top t
]
850 ["Emacs internals process" anything-list-emacs-process t
])
852 ["Prefered Options" anything-configuration t
]))
856 ;; It is replaced by `anything-help'
857 (defun anything-c-describe-anything-bindings ()
858 "[OBSOLETE] Describe `anything' bindings."
860 (anything-run-after-quit
862 (with-current-buffer (get-buffer-create "*Anything Help*")
865 (substitute-command-keys
866 "The keys that are defined for `anything' are:
868 (pop-to-buffer "*Anything Help*")
869 (goto-char (point-min)))))
871 ;; Use `describe-mode' key in `global-map'
872 ;; (dolist (k (where-is-internal 'describe-mode global-map))
873 ;; (define-key anything-map k 'anything-c-describe-anything-bindings))
876 (defun anything-c-list-preconfigured-anything ()
879 for entry in
(cdr (assoc
880 (file-truename (locate-library "anything-config"))
882 if
(and (consp entry
)
883 (eq (car entry
) 'defun
)
884 (string-match "^Preconfigured.+$"
885 (setq doc
(or (documentation (setq sym
(cdr entry
)))
887 collect
(cons sym
(match-string 0 doc
))))
889 (defun anything-c-format-preconfigured-anything ()
890 (mapcar (lambda (x) (format "\\[%s] : %s\n" (car x
) (cdr x
)))
891 (anything-c-list-preconfigured-anything)))
893 (setq anything-help-message
897 "`anything' is QuickSilver-like candidate-selection framework.
899 Narrow the list by typing some pattern,
900 Multiple patterns are allowed by splitting by space.
901 Select with natural Emacs operations, choose with RET.
903 If you have any problems, press C-c C-x C-b!!
904 Feel free to send bug reports. I'll fix them.
905 The steps are described in the beginning of anything.el file.
907 == Basic Operations ==
908 C-p, Up: Previous Line
909 C-n, Down : Next Line
910 M-v, PageUp : Previous Page
911 C-v, PageDown : Next Page
912 Enter : Execute first (default) action / Select
915 M-PageUp, C-M-S-v, C-M-y : Previous Page (other-window)
916 M-PageDown, C-M-v : Next Page (other-window)
918 Tab, C-i : Show action list
919 Left : Previous Source
920 Right, C-o : Next Source
922 C-z : Persistent Action (Execute action with anything session kept)
923 C-c C-x C-b: Send a bug report
925 == Shortcuts For 2nd/3rd Action ==
926 \\[anything-select-2nd-action-or-end-of-line] : Execute 2nd Action (if the minibuffer cursor is at end of line)
927 \\[anything-select-3rd-action] : Execute 3rd Action
930 Visible marks store candidate. Some actions uses marked candidates.
932 \\[anything-toggle-visible-mark] : Toggle Visible Mark
933 \\[anything-prev-visible-mark] : Previous Mark
934 \\[anything-next-visible-mark] : Next Mark
936 == Miscellaneous Commands ==
937 \\[anything-toggle-resplit-window] : Toggle vertical/horizontal split anything window
938 \\[anything-quit-and-find-file] : Drop into `find-file'
939 \\[anything-delete-current-selection] : Delete Selected Item (visually)
940 \\[anything-kill-selection-and-quit] : Set Item Into the kill-ring And Quit
941 \\[anything-yank-selection] : Yank Selected Item Into Pattern
942 \\[anything-follow-mode] : Toggle Automatical Execution Of Persistent Action
943 \\[anything-force-update] : Recalculate And Redisplay Candidates
945 == Global Commands ==
946 \\<global-map>\\[anything-resume] revives last `anything' session.
947 It is very useful, so you should bind any key.
949 Single source is executed by \\[anything-call-source].
951 == Preconfigured `anything' ==
952 Preconfigured `anything' is commands that uses `anything' interface.
953 You can use them without configuration.
956 (apply 'concat
(anything-c-format-preconfigured-anything))
960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
962 (defun anything-mini ()
963 "Preconfigured `anything' lightweight version (buffer -> recentf)."
965 (anything-other-buffer '(anything-c-source-buffers+ anything-c-source-recentf
)
968 (defun anything-for-files ()
969 "Preconfigured `anything' for opening files.
970 ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
972 (anything-other-buffer anything-for-files-prefered-list
"*anything for files*"))
975 (defun anything-recentf ()
976 "Preconfigured `anything' for `recentf'."
978 (anything-other-buffer 'anything-c-source-recentf
"*anything recentf*"))
981 (defun anything-info-at-point ()
982 "Preconfigured `anything' for searching info at point."
984 (anything '(anything-c-source-info-elisp
985 anything-c-source-info-cl
986 anything-c-source-info-pages
)
987 (thing-at-point 'symbol
) nil nil nil
"*anything info*"))
990 (defun anything-info-emacs ()
991 "Preconfigured anything for Emacs manual index."
993 (anything-other-buffer 'anything-c-source-info-emacs
"*info emacs*"))
996 (defun anything-show-kill-ring ()
997 "Preconfigured `anything' for `kill-ring'. It is drop-in replacement of `yank-pop'.
998 You may bind this command to M-y."
1000 (let ((enable-recursive-minibuffers t
))
1001 (anything-other-buffer 'anything-c-source-kill-ring
"*anything kill-ring*")))
1004 (defun anything-minibuffer-history ()
1005 "Preconfigured `anything' for `minibuffer-history'."
1007 (let ((enable-recursive-minibuffers t
))
1008 (anything-other-buffer 'anything-c-source-minibuffer-history
1009 "*anything minibuffer-history*")))
1012 (defun anything-gentoo ()
1013 "Preconfigured `anything' for gentoo linux."
1015 (anything-other-buffer '(anything-c-source-gentoo
1016 anything-c-source-use-flags
)
1017 "*anything gentoo*"))
1020 (defun anything-imenu ()
1021 "Preconfigured `anything' for `imenu'."
1023 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
1026 (defun anything-google-suggest ()
1027 "Preconfigured `anything' for google search with google suggest."
1029 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
1032 (defun anything-yahoo-suggest ()
1033 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1035 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
1037 ;;; Converted from anything-show-*-only
1039 (defun anything-for-buffers ()
1040 "Preconfigured `anything' for buffer."
1042 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
1045 (defun anything-buffers+ ()
1046 "Enhanced preconfigured `anything' for buffer."
1048 (anything-other-buffer 'anything-c-source-buffers
+ "*anything buffers*"))
1051 (defun anything-bbdb ()
1052 "Preconfigured `anything' for BBDB.
1056 http://bbdb.sourceforge.net/"
1058 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
1061 (defun anything-locate ()
1062 "Preconfigured `anything' for Locate.
1063 Note you can add locate command after entering pattern.
1064 See man locate for more infos."
1066 (anything-other-buffer 'anything-c-source-locate
"*anything locate*"))
1069 (defun anything-w3m-bookmarks ()
1070 "Preconfigured `anything' for w3m bookmark.
1072 Needs w3m and emacs-w3m.
1074 http://w3m.sourceforge.net/
1075 http://emacs-w3m.namazu.org/"
1077 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1078 "*anything w3m bookmarks*"))
1081 (defun anything-firefox-bookmarks ()
1082 "Preconfigured `anything' for firefox bookmark.
1083 You will have to enable html bookmarks in firefox:
1084 open about:config in firefox and double click on this line to enable value \
1087 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1089 You should have now:
1091 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1093 After closing firefox, you will be able to browse you bookmarks.
1096 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1097 "*Anything Firefox*"))
1100 (defun anything-colors ()
1101 "Preconfigured `anything' for color."
1103 (anything-other-buffer
1104 '(anything-c-source-colors anything-c-source-customize-face
)
1105 "*anything colors*"))
1108 (defun anything-bookmarks ()
1109 "Preconfigured `anything' for bookmarks."
1111 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
1114 (defun anything-c-pp-bookmarks ()
1115 "Preconfigured `anything' for bookmarks (pretty-printed)."
1117 (anything-other-buffer '(anything-c-source-bookmarks-local
1118 anything-c-source-bookmarks-su
1119 anything-c-source-bookmarks-ssh
)
1120 "*anything pp bookmarks*"))
1123 (defun anything-register ()
1124 "Preconfigured `anything' for Emacs registers."
1126 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
1129 (defun anything-man-woman ()
1130 "Preconfigured `anything' for Man and Woman pages."
1132 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
1135 (defun anything-org-keywords ()
1136 "Preconfigured `anything' for org keywords."
1138 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
1141 (defun anything-emms ()
1142 "Preconfigured `anything' for emms sources."
1144 (anything '(anything-c-source-emms-streams
1145 anything-c-source-emms-files
1146 anything-c-source-emms-dired
)
1151 (defun anything-eev-anchors ()
1152 "Preconfigured `anything' for eev anchors."
1154 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
1157 (defun anything-bm-list ()
1158 "Preconfigured `anything' for visible bookmarks.
1162 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1164 (let ((anything-outline-using t
))
1165 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
1168 (defun anything-timers ()
1169 "Preconfigured `anything' for timers."
1171 (anything-other-buffer '(anything-c-source-absolute-time-timers
1172 anything-c-source-idle-time-timers
)
1173 "*anything timers*"))
1176 (defun anything-list-emacs-process ()
1177 "Preconfigured `anything' for emacs process."
1179 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
1182 (defun anything-occur ()
1183 "Preconfigured Anything for Occur source."
1185 (let ((anything-compile-source-functions
1186 ;; rule out anything-match-plugin because the input is one regexp.
1187 (delq 'anything-compile-source--match-plugin
1188 (copy-sequence anything-compile-source-functions
))))
1189 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
1192 (defun anything-browse-code ()
1193 "Preconfigured anything to browse code."
1195 (anything-other-buffer 'anything-c-source-browse-code
"*Browse code*"))
1198 (defun anything-org-headlines ()
1199 "Preconfigured anything to show org headlines."
1201 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
1203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1206 (defun anything-kill-buffers ()
1207 "Preconfigured `anything' to kill buffer you selected."
1210 '(((name .
"Kill Buffers")
1211 (candidates . anything-c-buffer-list
)
1213 ("Kill Buffer" .
(lambda (candidate)
1214 (kill-buffer candidate
)
1215 (anything-kill-buffers)
1220 (defun anything-c-query-replace-regexp (candidate)
1221 (let ((regexp (funcall (anything-attr 'regexp
))))
1222 (apply 'query-replace-regexp
1223 (anything-c-query-replace-args regexp
))))
1225 (defun anything-c-kill-regexp-as-sexp (candidate)
1226 (anything-c-regexp-kill-new
1227 (prin1-to-string (funcall (anything-attr 'regexp
)))))
1229 (defun anything-c-kill-regexp (candidate)
1230 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
1232 (defun anything-c-query-replace-args (regexp)
1233 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1234 (let ((region-only (anything-region-active-p)))
1237 (query-replace-read-to regexp
1238 (format "Query replace %s regexp %s"
1239 (if anything-current-prefix-arg
"word " "")
1240 (if region-only
"in region " ""))
1242 anything-current-prefix-arg
1243 (when region-only
(region-beginning))
1244 (when region-only
(region-end)))))
1246 (defvar anything-c-source-regexp
1247 '((name .
"Regexp Builder")
1249 (anything-candidate-buffer anything-current-buffer
)))
1250 (candidates-in-buffer)
1251 (get-line . anything-c-regexp-get-line
)
1252 (persistent-action . anything-c-regexp-persistent-action
)
1253 (persistent-help .
"Show this line")
1256 (requires-pattern .
2)
1257 (mode-line .
"Press TAB to select action.")
1259 ;; I use here `anything-input' because `anything-pattern' is lost when
1260 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1261 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1262 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1264 (regexp .
(lambda () anything-input
))
1265 (action .
(("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
1266 ("Query Replace Regexp" . anything-c-query-replace-regexp
)
1267 ("Kill Regexp" . anything-c-kill-regexp
)))))
1269 (defun anything-c-regexp-get-line (s e
)
1273 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
1275 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
1276 collect
(format "\n %s'%s'"
1277 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
1280 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1281 ;; It is implementation problem of candidates-in-buffer.
1285 ;; Shut up byte compiler
1286 (defun anything-goto-line (numline)
1287 "Replacement of `goto-line'."
1288 (goto-char (point-min))
1289 (forward-line (1- numline
)))
1291 (defun anything-c-regexp-persistent-action (pt)
1293 (anything-persistent-highlight-point))
1295 (defun anything-c-regexp-kill-new (input)
1297 (message "Killed: %s" input
))
1299 (defun anything-region-active-p ()
1300 (and transient-mark-mode mark-active
(/= (mark) (point))))
1302 (defun* anything-current-buffer-narrowed-p
(&optional
1303 (buffer anything-current-buffer
))
1304 "Check if BUFFER is narrowed.
1305 Default is `anything-current-buffer'."
1306 (with-current-buffer buffer
1307 (let ((beg (point-min))
1309 (total (buffer-size)))
1310 (or (/= beg
1) (/= end
(1+ total
))))))
1313 (defun anything-regexp ()
1314 "Preconfigured anything to build regexps and run query-replace-regexp \
1318 (let ((anything-compile-source-functions
1319 ;; rule out anything-match-plugin because the input is one regexp.
1320 (delq 'anything-compile-source--match-plugin
1321 (copy-sequence anything-compile-source-functions
))))
1322 (when (and (anything-region-active-p)
1323 ;; Don't narrow to region if buffer is already narrowed.
1324 (not (anything-current-buffer-narrowed-p)))
1325 (narrow-to-region (region-beginning) (region-end)))
1327 anything-c-source-regexp
1328 :buffer
"*anything regexp*"
1329 :prompt
"Regexp: "))))
1332 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1334 (defun anything-insert-buffer-name ()
1335 "Insert buffer name."
1337 (anything-insert-string
1338 (with-current-buffer anything-current-buffer
1339 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
1342 (defun anything-insert-symbol ()
1343 "Insert current symbol."
1345 (anything-insert-string
1346 (with-current-buffer anything-current-buffer
1348 (buffer-substring (beginning-of-thing 'symbol
)
1349 (end-of-thing 'symbol
))))))
1351 (defun anything-insert-selection ()
1352 "Insert current selection."
1354 (anything-insert-string
1355 (with-current-buffer anything-current-buffer
1356 (anything-get-selection))))
1358 (defun anything-show-buffer-only ()
1359 "[OBSOLETE] Only show sources about buffer.
1360 Use `anything-for-buffers' instead."
1362 (anything-set-source-filter '("Buffers")))
1364 (defun anything-show-bbdb-only ()
1365 "[OBSOLETE] Only show sources about BBDB.
1366 Use `anything-bbdb' instead."
1368 (anything-set-source-filter '("BBDB")))
1370 (defun anything-show-locate-only ()
1371 "[OBSOLETE] Only show sources about Locate.
1372 Use `anything-locate' instead."
1374 (anything-set-source-filter '("Locate")))
1376 (defun anything-show-info-only ()
1377 "[OBSOLETE] Only show sources about Info.
1378 Use `anything-info-at-point' instead."
1380 (anything-set-source-filter '("Info Pages"
1382 "Info Common-Lisp")))
1384 (defun anything-show-imenu-only ()
1385 "[OBSOLETE] Only show sources about Imenu.
1386 Use `anything-imenu' instead."
1388 (anything-set-source-filter '("Imenu")))
1390 (defun anything-show-files-only ()
1391 "[OBSOLETE] Only show sources about File.
1392 Use `anything-for-files' instead."
1394 (anything-set-source-filter '("File Name History"
1395 "Files from Current Directory"
1398 (defun anything-show-w3m-bookmarks-only ()
1399 "[OBSOLETE] Only show source about w3m bookmark.
1400 Use `anything-w3m-bookmarks' instead."
1402 (anything-set-source-filter '("W3m Bookmarks")))
1404 (defun anything-show-colors-only ()
1405 "[OBSOLETE] Only show source about color.
1406 Use `anything-colors' instead."
1408 (anything-set-source-filter '("Colors"
1409 "Customize Faces")))
1411 (defun anything-show-kill-ring-only ()
1412 "[OBSOLETE] Only show source about kill ring.
1413 Use `anything-show-kill-ring' instead."
1415 (anything-set-source-filter '("Kill Ring")))
1417 (defun anything-show-this-source-only ()
1418 "Only show this source."
1420 (setq anything-candidate-number-limit
9999)
1421 (anything-set-source-filter
1422 (list (assoc-default 'name
(anything-get-current-source)))))
1424 (defun anything-test-sources ()
1425 "List all anything sources for test.
1426 The output is sexps which are evaluated by \\[eval-last-sexp]."
1428 (with-output-to-temp-buffer "*Anything Test Sources*"
1429 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
1430 (apropos-internal "^anything-c-source" #'boundp
))
1431 (pop-to-buffer standard-output
)))
1433 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1434 ;;; For compatibility
1435 (unless (fboundp 'region-active-p
)
1436 (defun region-active-p ()
1437 "Return t if Transient Mark mode is enabled and the mark is active.
1439 Most commands that act on the region if it is active and
1440 Transient Mark mode is enabled, and on the text near point
1441 otherwise, should use `use-region-p' instead. That function
1442 checks the value of `use-empty-active-region' as well."
1443 (and transient-mark-mode mark-active
)))
1445 (defun anything-nest (&rest same-as-anything
)
1446 "Nested `anything'. If you use `anything' within `anything', use it."
1447 (with-selected-window (anything-window)
1448 (let (anything-current-position
1449 anything-current-buffer
1450 (orig-anything-buffer anything-buffer
)
1454 anything-compiled-sources
1455 anything-buffer-chars-modified-tick
1456 (anything-samewindow t
)
1457 (enable-recursive-minibuffers t
))
1459 (apply #'anything same-as-anything
)
1460 (anything-initialize-overlays orig-anything-buffer
)
1461 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
1463 (defun anything-displaying-source-names ()
1464 "Display sources name."
1465 (with-current-buffer anything-buffer
1466 (goto-char (point-min))
1468 while
(setq pos
(next-single-property-change (point) 'anything-header
))
1470 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
1471 do
(forward-line 1))))
1473 (defun anything-select-source ()
1476 (let ((default (assoc-default 'name
(anything-get-current-source)))
1477 (source-names (anything-displaying-source-names))
1478 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
1479 (anything-get-sources))))
1480 (setq anything-candidate-number-limit
9999)
1482 (let (anything-source-filter)
1483 (anything-nest '(((name .
"Anything Source")
1484 (candidates . source-names
)
1485 (action . identity
))
1486 ((name .
"Anything Source (ALL)")
1487 (candidates . all-source-names
)
1488 (action . identity
)))
1490 default
"*anything select source*"))
1491 (anything-set-source-filter (list it
))
1492 (anything-set-source-filter nil
))))
1494 (defun anything-insert-string (str)
1496 (delete-minibuffer-contents)
1499 (defun anything-c-match-on-file-name (candidate)
1500 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1501 (string-match anything-pattern
(file-name-nondirectory candidate
)))
1503 (defun anything-c-match-on-directory-name (candidate)
1504 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1505 (anything-aif (file-name-directory candidate
)
1506 (string-match anything-pattern it
)))
1508 (defun anything-c-string-match (candidate)
1509 "Return non-nil if `anything-pattern' match CANDIDATE.
1510 The match is done with `string-match'."
1511 (string-match anything-pattern candidate
))
1513 ;; `anything-c-compose' is no more needed, it is for compatibility.
1514 (defalias 'anything-c-compose
'anything-compose
)
1516 (defun anything-c-skip-entries (list regexp
)
1517 "Remove entries which matches REGEXP from LIST."
1518 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
1521 (defun anything-c-shadow-entries (list regexp
)
1522 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1523 (mapcar (lambda (file)
1524 ;; Add shadow face property to boring files.
1525 (let ((face (if (facep 'file-name-shadow
)
1527 ;; fall back to default on XEmacs
1529 (if (string-match regexp file
)
1530 (setq file
(propertize file
'face face
))))
1534 (defsubst anything-c-stringify
(str-or-sym)
1535 "Get string of STR-OR-SYM."
1536 (if (stringp str-or-sym
)
1538 (symbol-name str-or-sym
)))
1540 (defsubst anything-c-symbolify
(str-or-sym)
1541 "Get symbol of STR-OR-SYM."
1542 (if (symbolp str-or-sym
)
1544 (intern str-or-sym
)))
1546 (defun anything-c-describe-function (func)
1547 "FUNC is symbol or string."
1548 (describe-function (anything-c-symbolify func
)))
1550 (defun anything-c-describe-variable (var)
1551 "VAR is symbol or string."
1552 (describe-variable (anything-c-symbolify var
)))
1554 (defun anything-c-find-function (func)
1555 "FUNC is symbol or string."
1556 (find-function (anything-c-symbolify func
)))
1558 (defun anything-c-find-variable (var)
1559 "VAR is symbol or string."
1560 (find-variable (anything-c-symbolify var
)))
1562 (defun anything-c-kill-new (string &optional replace yank-handler
)
1563 "STRING is symbol or string."
1564 (kill-new (anything-c-stringify string
) replace yank-handler
))
1566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1567 ;; TODO: This should be integrated in anything.el instead of having
1568 ;; a defadvice here.
1570 (defvar anything-current-prefix-arg nil
1571 "Record `current-prefix-arg' when exiting minibuffer.
1572 It will be cleared at start of next `anything' call when \
1573 `anything-before-initialize-hook' is called.")
1575 (defadvice anything-exit-minibuffer
(before anything-current-prefix-arg activate
)
1576 (unless anything-current-prefix-arg
1577 (setq anything-current-prefix-arg current-prefix-arg
)))
1579 ;; using this hook instead of `anything-after-action-hook'
1580 ;; allow to record the prefix args and keep their values
1581 ;; when using `anything-comp-read'.
1582 (add-hook 'anything-before-initialize-hook
1583 (lambda () (setq anything-current-prefix-arg nil
)))
1586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1587 (defadvice eval-defun
(after anything-source-hack activate
)
1588 "See `anything-c-enable-eval-defun-hack'."
1589 (when anything-c-enable-eval-defun-hack
1590 (let ((varsym (save-excursion
1591 (beginning-of-defun)
1593 (when (memq (read (current-buffer)) '(defvar setq
))
1594 (read (current-buffer))))))
1595 (when (string-match "^anything-c-source-" (symbol-name varsym
))
1596 (anything varsym
)))))
1597 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1600 (defconst anything-c-create-summary-index-regexp
1601 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1602 (defun anything-c-create-summary ()
1603 "Create `anything' summary."
1605 (goto-char (point-min))
1607 while
(re-search-forward anything-c-create-summary-index-regexp nil t
)
1609 (cond ((setq it
(match-string-no-properties 1))
1611 ((setq it
(match-string-no-properties 2))
1613 ,(assoc-default 'name
(symbol-value (intern it
)))))
1614 ((setq it
(match-string-no-properties 3))
1616 ,(assoc-default 'name
(symbol-value (intern it
)))))))))
1618 ;; (find-epp (anything-c-create-summary))
1620 (defun anything-c-insert-summary ()
1621 "Insert `anything' summary."
1623 (goto-char (point-min))
1624 (search-forward ";; Below are complete source list you can setup in")
1626 (delete-region (point)
1627 (progn (search-forward ";;; Change log:" nil t
)
1628 (forward-line -
1) (point)))
1631 for
(kind . value
) in
(anything-c-create-summary)
1633 do
(cond ((eq kind
'section
)
1635 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
1636 (insert ";; " value
":\n")
1639 (insert ";; `" (car value
) "' (" (cdr value
) ")\n")))
1640 finally
(align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))))
1641 ;; (anything-c-insert-summary)
1643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1645 (defun anything-c-buffer-list ()
1646 "Return the list of names of buffers with boring buffers filtered out.
1647 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1648 The first buffer in the list will be the last recently used
1649 buffer that is not the current buffer."
1650 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
1651 (append (cdr buffers
) (list (car buffers
)))))
1653 (defvar anything-c-source-buffers
1654 '((name .
"Buffers")
1655 (candidates . anything-c-buffer-list
)
1657 ;; (anything 'anything-c-source-buffers)
1659 (defvar anything-c-source-buffer-not-found
1660 '((name .
"Create buffer")
1663 ;; (anything 'anything-c-source-buffer-not-found)
1666 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
1667 "*Face used for directory headings in dired buffers."
1670 (defface anything-file-name
1671 '((t (:foreground
"Blue")))
1672 "*Face used for file names (without suffixes) in dired buffers."
1675 (defface anything-dir-priv
1676 '((t (:foreground
"DarkRed" :background
"LightGray")))
1677 "*Face used for directory privilege indicator (d) in dired buffers."
1680 (defvar anything-c-buffers-face1
'anything-dir-priv
)
1681 (defvar anything-c-buffers-face2
'font-lock-type-face
)
1682 (defvar anything-c-buffers-face3
'italic
)
1683 (eval-when-compile (require 'dired
))
1684 (defun anything-c-highlight-buffers (buffers)
1686 (loop for i in buffers
1687 if
(rassoc (get-buffer i
) dired-buffers
)
1688 collect
(propertize i
1689 'face anything-c-buffers-face1
1690 'help-echo
(car (rassoc (get-buffer i
) dired-buffers
)))
1691 if
(buffer-file-name (get-buffer i
))
1692 collect
(propertize i
1693 'face anything-c-buffers-face2
1694 'help-echo
(buffer-file-name (get-buffer i
)))
1695 if
(and (not (rassoc (get-buffer i
) dired-buffers
))
1696 (not (buffer-file-name (get-buffer i
))))
1697 collect
(propertize i
1698 'face anything-c-buffers-face3
)))
1700 (defvar anything-c-source-buffers
+
1701 '((name .
"Buffers")
1702 (candidates . anything-c-buffer-list
)
1704 (candidate-transformer anything-c-skip-current-buffer
1705 anything-c-highlight-buffers
1706 anything-c-skip-boring-buffers
)
1707 (persistent-action . anything-c-buffers
+-persistent-action
)
1708 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1710 (defun anything-c-buffers+-persistent-action
(name)
1712 (with-current-buffer item
1713 (if (and (buffer-modified-p)
1714 (buffer-file-name (current-buffer)))
1718 (kill-buffer item
))))
1720 (switch-to-buffer item
)))
1721 (if current-prefix-arg
1724 (anything-delete-current-selection))
1727 ;; (anything 'anything-c-source-buffers+)
1731 ;;; File name history
1732 (defvar anything-c-source-file-name-history
1733 '((name .
"File Name History")
1734 (candidates . file-name-history
)
1735 (match anything-c-match-on-file-name
1736 anything-c-match-on-directory-name
)
1738 ;; (anything 'anything-c-source-file-name-history)
1740 ;;; Files in current dir
1741 (defvar anything-c-source-files-in-current-dir
1742 '((name .
"Files from Current Directory")
1743 (candidates .
(lambda ()
1744 (with-current-buffer anything-current-buffer
1745 (directory-files (anything-c-current-directory)))))
1746 ;; volatile is not needed, I think.
1748 ;; (anything 'anything-c-source-files-in-current-dir)
1750 (defvar anything-c-files-face1
'anything-dir-priv
)
1751 (defvar anything-c-files-face2
'anything-file-name
)
1752 (defun anything-c-highlight-files (files)
1753 (loop for i in files
1754 if
(file-directory-p i
)
1755 collect
(propertize (file-name-nondirectory i
)
1756 'face anything-c-files-face1
1757 'help-echo
(expand-file-name i
))
1759 collect
(propertize (file-name-nondirectory i
)
1760 'face anything-c-files-face2
1761 'help-echo
(expand-file-name i
))))
1764 (defvar anything-c-source-files-in-current-dir
+
1765 '((name .
"Files from Current Directory")
1766 (candidates .
(lambda ()
1767 (with-current-buffer anything-current-buffer
1768 (directory-files (anything-c-current-directory) t
))))
1769 (candidate-transformer anything-c-highlight-files
)
1770 ;; volatile is not needed, I think.
1773 ;; (anything 'anything-c-source-files-in-current-dir+)
1775 ;;; Anything replacement of file name completion for `find-file' and friends.
1777 (defvar anything-c-find-files-doc-header
(format " (`%s':Go to precedent level)"
1778 (if window-system
"C-." "C-l"))
1779 "*The doc that is inserted in the Name header of a find-files or dired source.")
1781 (defvar anything-c-source-find-files
1782 `((name .
,(concat "Find Files" anything-c-find-files-doc-header
))
1783 ;; It is needed for filenames with capital letters
1786 (setq ffap-newfile-prompt t
)))
1787 (candidates . anything-find-files-get-candidates
)
1788 (filtered-candidate-transformer anything-c-find-files-transformer
)
1789 (persistent-action . anything-find-files-persistent-action
)
1790 (persistent-help .
"Hit1 Expand Candidate, Hit2 or (C-u) Find file")
1792 (action-transformer . anything-find-files-action-transformer
)
1796 `(("Find File" . anything-c-find-file-or-marked
)
1797 ("Find file in Dired" . anything-c-point-file-in-dired
)
1798 ,(and (locate-library "elscreen")
1799 '("Find file in Elscreen" . anything-elscreen-find-file
))
1800 ("Complete at point"
1801 . anything-c-insert-file-name-completion-at-point
)
1802 ("Open file externally `C-u to choose'"
1803 . anything-c-open-file-externally
)
1804 ("Grep File(s)" .
(lambda (candidate)
1805 ;; Restore highlighting disabled in *-find-files.
1806 (let ((anything-mp-highlight-delay 0.7))
1807 (anything-do-grep (anything-marked-candidates)))))
1808 ("Ediff File" . anything-find-files-ediff-files
)
1809 ("Ediff Merge File" . anything-find-files-ediff-merge-files
)
1810 ("Delete File(s)" . anything-delete-marked-files
)
1811 ("Copy file(s) `C-u to follow'" . anything-find-files-copy
)
1812 ("Rename file(s) `C-u to follow'" . anything-find-files-rename
)
1813 ("Symlink files(s) `C-u to follow'" . anything-find-files-symlink
)
1814 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink
)
1815 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink
)
1816 ("Find file other window" . find-file-other-window
)
1817 ("Find file other frame" . find-file-other-frame
)
1818 ("Find file as root" . anything-find-file-as-root
))))))
1819 ;; (anything 'anything-c-source-find-files)
1821 (defun anything-find-files-set-prompt-for-action (prompt files
)
1822 "Set prompt for action in `anything-find-files'."
1823 (let ((len (length files
)))
1825 (format "%s * %d Files to: " prompt len
)
1826 (format "%s %s to: " prompt
(car files
)))))
1828 (defun anything-find-files-do-action (action)
1829 "Generic function for creating action from `anything-c-source-find-files'.
1830 ACTION must be an action supported by `anything-dired-action'."
1831 (let* ((ifiles (anything-marked-candidates))
1832 (prompt (anything-find-files-set-prompt-for-action
1833 (capitalize (symbol-name action
)) ifiles
))
1834 (parg anything-current-prefix-arg
)
1835 (dest (anything-c-read-file-name
1837 (win-conf (current-window-configuration)))
1839 ;; Create temporarily a dired buffer to call dired functions.
1840 (with-current-buffer (dired default-directory
)
1841 (anything-dired-action
1842 dest
:files ifiles
:action action
:follow parg
)
1844 (unless parg
(set-window-configuration win-conf
)))))
1846 (defun anything-find-files-copy (candidate)
1847 "Copy files from `anything-find-files'."
1848 (anything-find-files-do-action 'copy
))
1850 (defun anything-find-files-rename (candidate)
1851 "Rename files from `anything-find-files'."
1852 (anything-find-files-do-action 'rename
))
1854 (defun anything-find-files-symlink (candidate)
1855 "Symlink files from `anything-find-files'."
1856 (anything-find-files-do-action 'symlink
))
1858 (defun anything-find-files-relsymlink (candidate)
1859 "Relsymlink files from `anything-find-files'."
1860 (anything-find-files-do-action 'relsymlink
))
1862 (defun anything-find-files-hardlink (candidate)
1863 "Hardlink files from `anything-find-files'."
1864 (anything-find-files-do-action 'hardlink
))
1866 (defun anything-find-files-byte-compile (candidate)
1867 "Byte compile files from `anything-find-files'."
1868 (let ((files (anything-marked-candidates))
1869 (parg anything-current-prefix-arg
))
1870 (loop for fname in files
1871 do
(byte-compile-file fname parg
))))
1873 (defun anything-find-files-ediff-files (candidate)
1874 "Default action to ediff files in `anything-find-files'."
1877 (anything-c-read-file-name
1878 (format "Ediff `%s' With File: " (file-name-nondirectory candidate
)))))
1880 (defun anything-find-files-ediff-merge-files (candidate)
1881 "Default action to ediff merge files in `anything-find-files'."
1884 (anything-c-read-file-name
1885 (format "Ediff Merge `%s' With File: " (file-name-nondirectory candidate
)))))
1887 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
1888 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1889 If LEVEL is positive reduce from end else from beginning.
1890 If UNIX-CLOSE is non--nil close filename with /.
1891 If EXPAND is non--nil expand-file-name."
1892 (let* ((exp-fname (expand-file-name fname
))
1893 (fname-list (split-string (if (or (string= fname
"~/") expand
)
1894 exp-fname fname
) "/" t
))
1895 (len (length fname-list
))
1896 (pop-list (if (< level
0)
1897 (subseq fname-list
(* level -
1))
1898 (subseq fname-list
0 (- len level
))))
1899 (result (mapconcat 'identity pop-list
"/"))
1900 (empty (string= result
"")))
1901 (when unix-close
(setq result
(concat result
"/")))
1902 (if (string-match "^~" result
)
1903 (if (string= result
"~/") "~/" result
)
1905 (if empty
"../" (concat "../" result
))
1906 (cond ((eq system-type
'windows-nt
)
1907 (if empty
"c:/" result
))
1910 (concat "/" result
)))))))
1912 (defun anything-file-completion-source-p ()
1913 "Test if current source is a dired or find-files source."
1914 (let ((ff-sources '("Find Files" "Copy Files"
1915 "Rename Files" "Symlink Files"
1916 "Hardlink Files" "Write File"
1917 "Insert File" "Read file name"))
1918 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
1920 (dolist (i ff-sources
)
1921 (when (equal cur-source
(concat i anything-c-find-files-doc-header
))
1922 (throw 'break t
))))))
1924 (defun anything-find-files-down-one-level (arg)
1925 "Go down one level like unix command `cd ..'.
1926 If prefix numeric arg is given go ARG level down."
1928 (when (anything-file-completion-source-p)
1929 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
1930 :unix-close t
:expand t
)))
1931 (with-selected-window (minibuffer-window)
1932 (delete-minibuffer-contents)
1933 (insert new-pattern
)))))
1935 ;; `C-.' doesn't work in terms use `C-l' instead.
1937 (define-key anything-map
(kbd "C-.") 'anything-find-files-down-one-level
)
1938 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))
1940 (defun anything-c-point-file-in-dired (file)
1941 "Put point on filename FILE in dired buffer."
1942 (dired (file-name-directory file
))
1943 (dired-goto-file file
))
1945 (defun anything-create-tramp-name (fname)
1946 "Build filename for `anything-pattern' like /su:: or /sudo::."
1947 (apply #'tramp-make-tramp-file-name
1949 with v
= (tramp-dissect-file-name fname
)
1950 for i across v collect i
)))
1952 (defun anything-find-files-get-candidates ()
1953 "Create candidate list for `anything-c-source-find-files'."
1954 (let* ( ; Don't try to tramp connect before entering the second ":".
1955 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1956 (path (cond ((string-match "^~" anything-pattern
)
1957 (replace-match (getenv "HOME") nil t anything-pattern
))
1958 ((string-match tramp-file-name-regexp anything-pattern
)
1959 (let ((tramp-name (anything-create-tramp-name
1960 (match-string 0 anything-pattern
))))
1961 (replace-match tramp-name nil t anything-pattern
)))
1962 (t anything-pattern
)))
1963 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
1964 (set-text-properties 0 (length path
) nil path
)
1965 (if (member 'anything-compile-source--match-plugin
1966 anything-compile-source-functions
)
1967 (setq anything-pattern path
)
1968 (setq anything-pattern
(replace-regexp-in-string " " ".*" path
)))
1969 (cond ((or (file-regular-p path
)
1970 (and (not (file-exists-p path
)) (string-match "/$" path
))
1971 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
1973 ((string= anything-pattern
"") (directory-files "/" t
))
1974 ((file-directory-p path
) (directory-files path t
))
1978 (directory-files (file-name-directory path
) t
))))))
1980 (defface anything-dired-symlink-face
1981 '((t (:foreground
"DarkOrange")))
1982 "*Face used for symlinks in `anything-find-files'."
1985 (defface anything-ffiles-prefix-face
1986 '((t (:background
"yellow" :foreground
"black")))
1987 "*Face used to prefix new file or url paths in `anything-find-files'."
1990 (defun anything-c-prefix-filename (fname &optional image
)
1991 "Return fname FNAME prefixed with icon IMAGE."
1992 (let* ((img-name (and image
(expand-file-name
1993 image anything-c-find-files-icons-directory
)))
1994 (img (and image
(create-image img-name
)))
1995 (prefix-img (and image
(propertize " " 'display img
)))
1996 (prefix-new (propertize
1998 (propertize "[?]" 'face
'anything-ffiles-prefix-face
)))
1999 (prefix-url (propertize
2001 (propertize "[@]" 'face
'anything-ffiles-prefix-face
))))
2002 (cond ((or (file-exists-p fname
)
2003 (file-symlink-p fname
))
2004 (if image
(concat prefix-img fname
) fname
))
2005 ((string-match ffap-url-regexp fname
) (concat prefix-url
" " fname
))
2006 (t (concat prefix-new
" " fname
)))))
2008 (defun anything-c-find-files-transformer (files sources
)
2009 "Selector of transformer to use for `anything-c-source-find-files'."
2010 (if (and (window-system) anything-c-find-files-show-icons
)
2011 (anything-c-highlight-ffiles1 files sources
)
2012 (anything-c-highlight-ffiles files sources
)))
2014 (defun anything-c-highlight-ffiles (files sources
)
2015 "Candidate transformer for `anything-c-source-find-files' without icons."
2016 (loop for i in files
2017 collect
(cond ((file-symlink-p i
)
2019 (anything-c-prefix-filename
2020 (propertize i
'face
'anything-dired-symlink-face
2021 'help-echo
(file-truename i
)))
2023 ((file-directory-p i
)
2025 (anything-c-prefix-filename
2026 (propertize i
'face anything-c-files-face1
))
2030 (anything-c-prefix-filename
2031 (propertize i
'face anything-c-files-face2
))
2034 (defsubst anything-c-highlight-ffiles1
(files sources
)
2035 "Candidate transformer for `anything-c-source-find-files' that show icons."
2036 (loop for i in files
2037 for af
= (file-name-nondirectory i
)
2038 collect
(cond ( ;; Files.
2039 (eq nil
(car (file-attributes i
)))
2040 (cons (anything-c-prefix-filename
2041 (propertize i
'face anything-c-files-face2
)
2044 ( ;; Empty directories.
2045 (and (eq t
(car (file-attributes i
)))
2046 ;; Be sure to have permission to list content.
2050 i nil directory-files-no-dot-files-regexp t
))))
2051 (cons (anything-c-prefix-filename
2052 (propertize i
'face anything-c-files-face1
)
2055 ( ;; Open directories.
2056 (and (eq t
(car (file-attributes i
))) (get-buffer af
))
2057 (cons (anything-c-prefix-filename
2058 (propertize i
'face anything-c-files-face1
)
2061 (;; Closed directories.
2062 (eq t
(car (file-attributes i
)))
2063 (cons (anything-c-prefix-filename
2064 (propertize i
'face anything-c-files-face1
)
2067 ( ;; Open Symlinks directories.
2068 (and (stringp (car (file-attributes i
)))
2069 (file-directory-p i
) (get-buffer af
))
2070 (cons (anything-c-prefix-filename
2071 (propertize i
'face
'anything-dired-symlink-face
2072 'help-echo
(file-truename i
)) "open.xpm")
2074 ( ;; Closed Symlinks directories.
2075 (and (stringp (car (file-attributes i
))) (file-directory-p i
))
2076 (cons (anything-c-prefix-filename
2077 (propertize i
'face
'anything-dired-symlink-face
2078 'help-echo
(file-truename i
)) "close.xpm")
2080 ( ;; Files symlinks.
2081 (stringp (car (file-attributes i
)))
2082 (cons (anything-c-prefix-filename
2083 (propertize i
'face
'anything-dired-symlink-face
2084 'help-echo
(file-truename i
))
2088 (defun anything-find-files-action-transformer (actions candidate
)
2089 "Action transformer for `anything-c-source-find-files'."
2090 (cond ((with-current-buffer anything-current-buffer
(eq major-mode
'message-mode
))
2091 (append actions
'(("Gnus attach file(s)" . anything-ff-gnus-attach-files
))))
2092 ((string-match (image-file-name-regexp) candidate
)
2093 (append actions
'(("Rotate image right" . anything-ff-rotate-image-right
)
2094 ("Rotate image left" . anything-ff-rotate-image-left
))))
2095 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
2096 (car it
) candidate
))
2097 (append actions
'(("Byte compile lisp file(s) `C-u to load'"
2098 . anything-find-files-byte-compile
)
2099 ("Load File(s)" . load-file
))))
2102 (defun anything-ff-gnus-attach-files (candidate)
2103 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
2104 (let ((flist (anything-marked-candidates)))
2105 (gnus-dired-attach flist
)))
2107 (defun anything-ff-rotate-current-image1 (file &optional num-arg
)
2108 "Rotate current image at NUM-ARG degrees."
2109 (if (executable-find "mogrify")
2111 (shell-command (format "mogrify -rotate %s %s" (or num-arg
90) file
))
2112 (when (buffer-live-p image-dired-display-image-buffer
)
2113 (kill-buffer image-dired-display-image-buffer
))
2114 (image-dired-display-image file
)
2116 (display-buffer (get-buffer image-dired-display-image-buffer
)))
2117 (error "mogrify not found")))
2119 (defun anything-ff-rotate-image-left (candidate)
2120 "Rotate image file CANDIDATE left.
2121 This affect directly file CANDIDATE."
2122 (anything-ff-rotate-current-image1 candidate -
90))
2124 (defun anything-ff-rotate-image-right (candidate)
2125 "Rotate image file CANDIDATE right.
2126 This affect directly file CANDIDATE."
2127 (anything-ff-rotate-current-image1 candidate
))
2129 (defun anything-find-files-persistent-action (candidate)
2130 "Open subtree CANDIDATE without quitting anything.
2131 If CANDIDATE is not a directory expand CANDIDATE filename.
2132 If CANDIDATE is alone, open file CANDIDATE filename.
2134 First hit on C-z expand CANDIDATE second hit open file.
2135 If a prefix arg is given or `anything-follow-mode' is on open file."
2136 (let ((follow (buffer-local-value
2137 'anything-follow-mode
2138 (get-buffer-create anything-buffer
))))
2139 (flet ((insert-in-minibuffer (fname)
2140 (with-selected-window (minibuffer-window)
2142 (delete-minibuffer-contents)
2143 (set-text-properties 0 (length fname
) nil fname
)
2145 (cond ((and (file-directory-p candidate
) (file-symlink-p candidate
))
2146 (insert-in-minibuffer (file-name-as-directory
2148 (expand-file-name candidate
)))))
2149 ((file-directory-p candidate
)
2150 (insert-in-minibuffer (file-name-as-directory
2151 (expand-file-name candidate
))))
2152 ((file-symlink-p candidate
)
2153 (insert-in-minibuffer (file-truename candidate
)))
2155 ;; First hit on C-z expand CANDIDATE second hit open file.
2156 ;; If a prefix arg is given or `anything-follow-mode' is on open file.
2157 (let ((new-pattern (anything-get-selection))
2158 (num-lines-buf (with-current-buffer anything-buffer
2159 (count-lines (point-min) (point-max)))))
2160 (if (and (> num-lines-buf
3) (not current-prefix-arg
) (not follow
))
2161 (insert-in-minibuffer new-pattern
)
2162 (if (string-match (image-file-name-regexp) candidate
)
2164 (when (buffer-live-p image-dired-display-image-buffer
)
2165 (kill-buffer image-dired-display-image-buffer
))
2166 (image-dired-display-image candidate
)
2168 (display-buffer image-dired-display-image-buffer
))
2169 (find-file candidate
)))))))))
2171 (defun anything-c-insert-file-name-completion-at-point (candidate)
2172 "Insert file name completion at point."
2173 (if buffer-read-only
2174 (error "Error: Buffer `%s' is read-only" (buffer-name))
2175 (let* ((end (point))
2176 (guess (thing-at-point 'filename
))
2177 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess
)
2178 (string-match "^[^\~]" guess
))))
2179 (set-text-properties 0 (length candidate
) nil candidate
)
2180 (if (and guess
(not (string= guess
"")) (string-match "^~\\|/.*" guess
))
2182 (search-backward guess
(- (point) (length guess
)))
2183 (delete-region (point) end
)
2185 (insert (expand-file-name candidate
))
2186 (insert (abbreviate-file-name candidate
))))
2187 (error "Aborting completion: No valid file name at point")))))
2190 (defun anything-find-files (&optional fname
)
2191 "Preconfigured `anything' for anything implementation of `find-file'.
2192 In non--interactive use an argument FNAME can be used.
2193 This is the starting point for nearly all actions you can do on files."
2195 (let ((anything-mp-highlight-delay nil
))
2196 (anything :sources
'anything-c-source-find-files
2197 :input
(or (and fname
(expand-file-name fname
))
2198 (anything-find-files-input
2200 (thing-at-point 'filename
)))
2201 :prompt
"Find Files or Url: "
2202 :buffer
"*Anything Find Files*")))
2204 (defun anything-c-current-directory ()
2205 "Return current-directory name at point.
2206 Useful in dired buffers when there is inserted subdirs."
2207 (if (eq major-mode
'dired-mode
)
2208 (dired-current-directory)
2211 (defun anything-find-files-input (fap tap
)
2212 "Default input of `anything-find-files'."
2213 (let* ((def-dir (anything-c-current-directory))
2214 (lib (anything-find-library-at-point))
2215 (file-p (and fap
(file-exists-p fap
)
2217 (file-name-directory (expand-file-name tap def-dir
)))))
2219 (file-p (expand-file-name tap def-dir
))
2221 (or input
(expand-file-name def-dir
))))
2223 (defun anything-find-library-at-point ()
2224 "Try to find library path at point.
2225 Find inside `require' and `declare-function' sexp."
2226 (require 'find-func
)
2227 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
2228 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
2229 (sexp (and beg-sexp end-sexp
2230 (buffer-substring-no-properties
2231 (1+ beg-sexp
) (1- end-sexp
)))))
2233 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
2235 (replace-regexp-in-string
2237 ;; If require use third arg, ignore it,
2238 ;; always use library path found in `load-path'.
2239 (second (split-string (match-string 0 sexp
))))))
2240 ((and sexp
(string-match-p "^declare-function" sexp
))
2242 (replace-regexp-in-string
2244 (third (split-string sexp
)))))
2247 ;;; Anything completion for `write-file'.==> C-x C-w
2248 (defvar anything-c-source-write-file
2249 `((name .
,(concat "Write File" anything-c-find-files-doc-header
))
2250 ;; It is needed for filenames with capital letters
2252 (candidates . anything-find-files-get-candidates
)
2253 (filtered-candidate-transformer anything-c-find-files-transformer
)
2254 (persistent-action . anything-find-files-persistent-action
)
2255 (persistent-help .
"Expand Candidate")
2258 (("Write File" .
(lambda (candidate)
2259 (write-file candidate
'confirm
)))))))
2262 (defun anything-write-file ()
2263 "Preconfigured `anything' providing completion for `write-file'."
2265 (anything 'anything-c-source-write-file
2266 (expand-file-name default-directory
)
2267 "Write buffer to file: " nil nil
"*Anything write file*"))
2269 ;;; Anything completion for `insert-file'.==> C-x i
2270 (defvar anything-c-source-insert-file
2271 `((name .
,(concat "Insert File" anything-c-find-files-doc-header
))
2272 ;; It is needed for filenames with capital letters
2274 (candidates . anything-find-files-get-candidates
)
2275 (filtered-candidate-transformer anything-c-find-files-transformer
)
2276 (persistent-action . anything-find-files-persistent-action
)
2277 (persistent-help .
"Expand Candidate")
2280 (("Insert File" .
(lambda (candidate)
2281 (when (y-or-n-p (format "Really insert %s in %s "
2282 candidate anything-current-buffer
))
2283 (insert-file-contents candidate
))))))))
2286 (defun anything-insert-file ()
2287 "Preconfigured `anything' providing completion for `insert-file'."
2289 (anything 'anything-c-source-insert-file
2290 (expand-file-name default-directory
)
2291 "Insert file: " nil nil
"*Anything insert file*"))
2293 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2294 (defvar anything-c-source-copy-files
2295 `((name .
,(concat "Copy Files" anything-c-find-files-doc-header
))
2296 ;; It is needed for filenames with capital letters
2298 (candidates . anything-find-files-get-candidates
)
2299 (filtered-candidate-transformer anything-c-find-files-transformer
)
2300 (persistent-action . anything-find-files-persistent-action
)
2301 (persistent-help .
"Expand Candidate")
2305 .
(lambda (candidate)
2306 (anything-dired-action candidate
:action
'copy
)))
2308 .
(lambda (candidate)
2309 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
2312 (defvar anything-c-source-rename-files
2313 `((name .
,(concat "Rename Files" anything-c-find-files-doc-header
))
2314 ;; It is needed for filenames with capital letters
2316 (candidates . anything-find-files-get-candidates
)
2317 (filtered-candidate-transformer anything-c-find-files-transformer
)
2318 (persistent-action . anything-find-files-persistent-action
)
2319 (persistent-help .
"Expand Candidate")
2323 .
(lambda (candidate)
2324 (anything-dired-action candidate
:action
'rename
)))
2325 ("Rename and Follow"
2326 .
(lambda (candidate)
2327 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
2329 (defvar anything-c-source-symlink-files
2330 `((name .
,(concat "Symlink Files" anything-c-find-files-doc-header
))
2331 ;; It is needed for filenames with capital letters
2333 (candidates . anything-find-files-get-candidates
)
2334 (filtered-candidate-transformer anything-c-find-files-transformer
)
2335 (persistent-action . anything-find-files-persistent-action
)
2336 (persistent-help .
"Expand Candidate")
2340 .
(lambda (candidate)
2341 (anything-dired-action candidate
:action
'symlink
)))
2343 .
(lambda (candidate)
2344 (anything-dired-action candidate
:action
'relsymlink
)))))))
2347 (defvar anything-c-source-hardlink-files
2348 `((name .
,(concat "Hardlink Files" anything-c-find-files-doc-header
))
2349 ;; It is needed for filenames with capital letters
2351 (candidates . anything-find-files-get-candidates
)
2352 (filtered-candidate-transformer anything-c-find-files-transformer
)
2353 (persistent-action . anything-find-files-persistent-action
)
2354 (persistent-help .
"Expand Candidate")
2358 .
(lambda (candidate)
2359 (anything-dired-action candidate
:action
'hardlink
)))))))
2362 (defun* anything-dired-action
(candidate &key action follow
(files (dired-get-marked-files)))
2363 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2364 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2365 (let ((fn (case action
2366 ('copy
'dired-copy-file
)
2367 ('rename
'dired-rename-file
)
2368 ('symlink
'make-symbolic-link
)
2369 ('relsymlink
'dired-make-relative-symlink
)
2370 ('hardlink
'dired-hardlink
)))
2371 (marker (case action
2372 ((copy rename
) dired-keep-marker-copy
)
2373 ('symlink dired-keep-marker-symlink
)
2374 ('relsymlink dired-keep-marker-relsymlink
)
2375 ('hardlink dired-keep-marker-hardlink
))))
2377 fn
(symbol-name action
) files
2378 (if (file-directory-p candidate
)
2379 ;; When CANDIDATE is a directory, build file-name in this directory.
2380 ;; Else we use CANDIDATE.
2382 (expand-file-name (file-name-nondirectory from
) candidate
))
2383 #'(lambda (from) candidate
))
2386 (let* ((moved-flist (anything-get-dest-fnames-from-list files candidate
))
2387 (fname (car moved-flist
)))
2390 (setq anything-ff-cand-to-mark moved-flist
)
2391 (anything-find-files candidate
))
2392 (setq anything-ff-cand-to-mark nil
))))))
2395 (defvar anything-ff-cand-to-mark nil
)
2397 (defun anything-get-dest-fnames-from-list (flist dest-cand
)
2398 "Transform filenames of FLIST to abs of DEST-CAND."
2400 with dest
= (expand-file-name dest-cand
)
2402 for basename-src
= (if (file-directory-p src
)
2404 (directory-file-name src
)
2405 (file-name-directory src
))
2406 (file-name-nondirectory src
))
2407 for fname
= (if (file-directory-p dest
)
2408 (concat (file-name-as-directory dest
)
2413 (defun anything-c-maybe-mark-candidates ()
2414 "Mark all candidates of list `anything-ff-cand-to-mark'."
2415 (when (and (string= (assoc-default 'name
(anything-get-current-source))
2416 (assoc-default 'name anything-c-source-find-files
))
2417 anything-ff-cand-to-mark
)
2418 (with-anything-window
2419 (while anything-ff-cand-to-mark
2420 (if (search-forward (car anything-ff-cand-to-mark
) (point-at-eol) t
)
2422 (call-interactively 'anything-toggle-visible-mark
)
2423 (setq anything-ff-cand-to-mark
(cdr anything-ff-cand-to-mark
)))
2424 (call-interactively 'anything-next-line
)))
2425 (unless (anything-this-visible-mark)
2426 (call-interactively 'anything-prev-visible-mark
)))))
2428 (add-hook 'anything-after-update-hook
#'anything-c-maybe-mark-candidates
)
2431 (defun* anything-dired-do-action-on-file
(&key action
)
2432 (let* ((files (dired-get-marked-files))
2433 (len (length files
))
2434 (fname (if (> len
1)
2435 (format "* %d Files" len
)
2437 (source (case action
2438 ('copy
'anything-c-source-copy-files
)
2439 ('rename
'anything-c-source-rename-files
)
2440 ('symlink
'anything-c-source-symlink-files
)
2441 ('hardlink
'anything-c-source-hardlink-files
)))
2442 (prompt-fm (case action
2443 ('copy
"Copy %s to: ")
2444 ('rename
"Rename %s to: ")
2445 ('symlink
"Symlink %s to: ")
2446 ('hardlink
"Hardlink %s to: ")))
2447 (buffer (case action
2448 ('copy
"*Anything Copy Files*")
2449 ('rename
"*Anything Rename Files*")
2450 ('symlink
"*Anything Symlink Files*")
2451 ('hardlink
"*Anything Hardlink Files*"))))
2453 (or (dired-dwim-target-directory)
2454 (expand-file-name (anything-c-current-directory)))
2455 (format prompt-fm fname
) nil nil buffer
)))
2459 (defun anything-dired-rename-file ()
2460 "Preconfigured `anything' to rename files from dired."
2462 (anything-dired-do-action-on-file :action
'rename
))
2465 (defun anything-dired-copy-file ()
2466 "Preconfigured `anything' to copy files from dired."
2468 (anything-dired-do-action-on-file :action
'copy
))
2471 (defun anything-dired-symlink-file ()
2472 "Preconfigured `anything' to symlink files from dired."
2474 (anything-dired-do-action-on-file :action
'symlink
))
2477 (defun anything-dired-hardlink-file ()
2478 "Preconfigured `anything' to hardlink files from dired."
2480 (anything-dired-do-action-on-file :action
'hardlink
))
2482 (defvar anything-dired-bindings nil
)
2484 (defun anything-dired-bindings (&optional arg
)
2485 "Replace usual dired commands `C' and `R' by anything ones.
2486 When call interactively toggle dired bindings and anything bindings.
2487 When call non--interactively with arg > 0, enable anything bindings.
2488 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2490 (if (or (and arg
(> arg
0)) (not anything-dired-bindings
))
2491 ;; Replace dired bindings.
2493 (substitute-key-definition
2494 'dired-do-copy
'anything-dired-copy-file dired-mode-map
)
2495 (substitute-key-definition
2496 'dired-do-rename
'anything-dired-rename-file dired-mode-map
)
2497 (substitute-key-definition
2498 'dired-do-symlink
'anything-dired-symlink-file dired-mode-map
)
2499 (substitute-key-definition
2500 'dired-do-hardlink
'anything-dired-hardlink-file dired-mode-map
)
2501 (setq anything-dired-bindings t
))
2502 ;; Replace anything bindings.
2503 (substitute-key-definition
2504 'anything-dired-copy-file
'dired-do-copy dired-mode-map
)
2505 (substitute-key-definition
2506 'anything-dired-rename-file
'dired-do-rename dired-mode-map
)
2507 (substitute-key-definition
2508 'anything-dired-symlink-file
'dired-do-symlink dired-mode-map
)
2509 (substitute-key-definition
2510 'anything-dired-hardlink-file
'dired-do-hardlink dired-mode-map
)
2511 (setq anything-dired-bindings nil
)))
2513 (defun* anything-c-read-file-name
(prompt
2515 (initial-input (expand-file-name default-directory
))
2516 (buffer "*Anything Completions*")
2518 (marked-candidates nil
)
2519 (persistent-action 'anything-find-files-persistent-action
)
2520 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
2521 "Anything `read-file-name' emulation.
2522 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2523 (when (get-buffer anything-action-buffer
)
2524 (kill-buffer anything-action-buffer
))
2525 (let ((anything-mp-highlight-delay nil
))
2526 (flet ((action-fn (candidate)
2527 (if marked-candidates
2528 (anything-marked-candidates)
2529 (identity candidate
))))
2532 `((name .
,(concat "Read file name" anything-c-find-files-doc-header
))
2533 ;; It is needed for filenames with capital letters
2535 (candidates .
(lambda ()
2537 (loop with seq
= (anything-find-files-get-candidates)
2538 for fname in seq when
(funcall test fname
)
2540 (anything-find-files-get-candidates))))
2541 (filtered-candidate-transformer anything-c-find-files-transformer
)
2542 (persistent-action .
,persistent-action
)
2543 (persistent-help .
,persistent-help
)
2545 (action .
,'action-fn
))
2546 :input initial-input
2553 (defvar anything-c-source-file-cache-initialized nil
)
2555 (defvar anything-c-file-cache-files nil
)
2557 (defvar anything-c-source-file-cache
2558 '((name .
"File Cache")
2561 (require 'filecache nil t
)
2562 (unless anything-c-source-file-cache-initialized
2563 (setq anything-c-file-cache-files
2564 (loop for item in file-cache-alist append
2565 (destructuring-bind (base &rest dirs
) item
2566 (loop for dir in dirs collect
2567 (concat dir base
)))))
2568 (defadvice file-cache-add-file
(after file-cache-list activate
)
2569 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
2570 (setq anything-c-source-file-cache-initialized t
))))
2571 (candidates . anything-c-file-cache-files
)
2572 (match anything-c-match-on-file-name
2573 anything-c-match-on-directory-name
)
2575 ;; (anything 'anything-c-source-file-cache)
2578 ;; NOTE for WINDOZE users:
2579 ;; You have to install Everything with his command line interface here:
2580 ;; http://www.voidtools.com/download.php
2582 (defvar anything-c-locate-command
2584 ('gnu
/linux
"locate -i -r %s")
2585 ('berkeley-unix
"locate -i %s")
2586 ('windows-nt
"es -i -r %s")
2588 "A list of arguments for locate program.
2589 The \"-r\" option must be the last option.")
2591 (defun anything-c-locate-init ()
2592 "Initialize async locate process for `anything-c-source-locate'."
2594 (start-process-shell-command "locate-process" nil
2595 (format anything-c-locate-command
2597 (set-process-sentinel (get-process "locate-process")
2598 #'(lambda (process event
)
2599 (when (string= event
"finished\n")
2600 (with-anything-window
2601 (anything-update-move-first-line)))))))
2603 (defvar anything-c-source-locate
2605 (candidates . anything-c-locate-init
)
2607 (requires-pattern .
3)
2609 "Find files matching the current input pattern with locate.")
2611 ;; (anything 'anything-c-source-locate)
2614 (defvar anything-c-grep-default-command
"grep -nH -e '%s' %s %s")
2615 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
2617 (defun anything-c-grep-init (only-files)
2618 "Start an asynchronous grep process in ONLY-FILES list."
2620 (start-process-shell-command
2622 (format anything-c-grep-default-command
2625 (mapconcat #'(lambda (x)
2626 (concat "--exclude=" x
))
2627 grep-find-ignored-files
" ")))
2628 (set-process-sentinel (get-process "grep-process")
2629 #'(lambda (process event
)
2630 (when (string= event
"finished\n")
2631 (with-anything-window
2632 (anything-update-move-first-line)))))))
2634 (defun anything-c-grep-action (candidate &optional where
)
2635 "Define a default action for `anything-do-grep' on CANDIDATE.
2636 WHERE can be one of other-window, elscreen, other-frame."
2637 (let* ((split (split-string candidate
":"))
2638 (lineno (string-to-number (second split
)))
2639 (fname (car split
)))
2641 (other-window (find-file-other-window fname
))
2642 (elscreen (anything-elscreen-find-file fname
))
2643 (other-frame (find-file-other-frame fname
))
2644 (t (find-file fname
)))
2646 (anything-goto-line lineno
)))
2648 (defun anything-c-grep-persistent-action (candidate)
2649 (anything-c-grep-action candidate
)
2650 (anything-match-line-color-current-line))
2653 (defun anything-do-grep (only)
2654 "Preconfigured anything for grep.
2655 Contrarily to Emacs `grep' no default directory is given, but
2656 the full path of candidates in ONLY.
2657 That allow to grep different files not only in `default-directory' but anywhere
2658 by marking them (C-<SPACE>). If one or more directory is selected
2659 grep will search in all files of these directories
2660 like -d recursive, or -r would do.
2661 You can use also wildcard in the base name of candidate."
2663 (anything-c-read-file-name "Search in file(s): "
2664 :marked-candidates t
)))
2665 (let ((anything-compile-source-functions
2666 ;; rule out anything-match-plugin because the input is one regexp.
2667 (delq 'anything-compile-source--match-plugin
2668 (copy-sequence anything-compile-source-functions
))))
2669 ;; If one or more candidate is a directory, search in all files
2670 ;; of this candidate e.g /home/user/directory/*
2673 if
(file-directory-p i
)
2674 collect
(concat (file-name-as-directory i
) "*") into of
2675 else collect i into of
2676 finally return
(mapconcat 'identity of
" ")))
2677 ;; When called as action from an other source e.g *-find-files
2678 ;; we have to kill action buffer.
2679 (when (get-buffer anything-action-buffer
)
2680 (kill-buffer anything-action-buffer
))
2681 (define-key anything-map
(kbd "M-<down>") #'anything-c-grep-next-or-prec-file
)
2682 (define-key anything-map
(kbd "M-<up>") #'anything-c-grep-precedent-file
)
2685 `(((name .
"Grep (M-up/down - next/prec file)")
2687 ;; Load `grep-find-ignored-files'.
2689 (candidates .
(lambda ()
2690 (funcall anything-c-grep-default-function only
)))
2691 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
2694 `(("Find File" . anything-c-grep-action
)
2695 ("Find file other window"
2696 .
(lambda (candidate)
2697 (anything-c-grep-action candidate
'other-window
)))
2698 ,(and (locate-library "elscreen")
2699 '("Find file in Elscreen"
2700 .
(lambda (candidate)
2701 (anything-c-grep-action candidate
'elscreen
))))
2702 ("Find file other frame"
2703 .
(lambda (candidate)
2704 (anything-c-grep-action candidate
'other-frame
))))))
2705 (persistent-action .
(lambda (candidate)
2706 (anything-c-grep-persistent-action
2708 (requires-pattern .
3)
2710 :buffer
"*anything grep*")))
2712 (defun anything-c-grep-cand-transformer (candidates sources
)
2713 "Filtered candidate transformer function for `anything-do-grep'."
2714 (loop for i in candidates
2715 for split
= (split-string i
":")
2716 collect
(cons (concat (propertize (file-relative-name (nth 0 split
))
2717 'face
'((:foreground
"BlueViolet")))
2719 (propertize (nth 1 split
)
2720 'face
'((:foreground
"Darkorange1")))
2726 (defun anything-c-grep-precedent-file ()
2727 "Go to precedent file in `anything-do-grep'."
2729 (anything-c-grep-next-or-prec-file -
1))
2732 (defun* anything-c-grep-next-or-prec-file
(&optional
(n 1))
2733 "Go to next or precedent candidate file in anything grep buffer."
2735 (let ((cur-source (assoc-default 'name
(anything-get-current-source))))
2736 (with-anything-window
2737 (if (equal cur-source
"Grep (M-up/down - next/prec file)")
2738 (let* ((current-line-list (split-string
2741 (point-at-eol)) ":"))
2742 (current-fname (nth 0 current-line-list
))
2743 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
))) ; func back or forward
2745 (while (not (funcall fn-b-o-f
))
2748 (when (not (search-forward current-fname
(point-at-eol) t
))
2749 (anything-mark-current-line)
2750 (throw 'break nil
))))
2753 (re-search-backward ".")
2755 (anything-mark-current-line))
2759 (anything-mark-current-line))))
2761 (anything-next-line)
2762 (anything-previous-line))))))
2765 (defvar anything-c-source-recentf
2766 '((name .
"Recentf")
2769 (or recentf-mode
(recentf-mode 1))
2770 ;; Big value empowers anything/recentf
2771 (when (and (numberp recentf-max-saved-items
)
2772 (<= recentf-max-saved-items
20))
2773 (setq recentf-max-saved-items
500))))
2774 (candidates . recentf-list
)
2775 (match anything-c-match-on-file-name
2776 anything-c-match-on-directory-name
)
2778 "See (info \"(emacs)File Conveniences\").
2779 if `recentf-max-saved-items' is too small, set it to 500.")
2780 ;; (anything 'anything-c-source-recentf)
2783 (eval-when-compile (require 'ffap
))
2784 (defvar anything-c-source-ffap-guesser
2785 '((name .
"File at point")
2786 (init .
(lambda () (require 'ffap
)))
2787 (candidates .
(lambda ()
2789 (with-current-buffer anything-current-buffer
2793 ;; (anything 'anything-c-source-ffap-guesser)
2795 ;;; ffap with line number
2796 (defun anything-c-ffap-file-line-at-point ()
2797 "Get (FILENAME . LINENO) at point."
2798 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2801 (when (and (search-forward it nil t
)
2802 (looking-at ":\\([0-9]+\\)"))
2803 (cons it
(string-to-number (match-string 1)))))))
2805 (defvar anything-c-ffap-line-location nil
2806 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2807 It is cleared after jumping line.")
2809 (defun anything-c-ffap-line-candidates ()
2810 (with-current-buffer anything-current-buffer
2811 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
2812 (when anything-c-ffap-line-location
2813 (destructuring-bind (file . line
) anything-c-ffap-line-location
2814 (list (cons (format "%s (line %d)" file line
) file
)))))
2816 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2817 (defun anything-c-ffap-line-goto-line ()
2818 (when (car anything-c-ffap-line-location
)
2821 (with-selected-window
2823 (get-file-buffer (car anything-c-ffap-line-location
)))
2824 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
2825 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
2826 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
2828 (defvar anything-c-source-ffap-line
2829 '((name .
"File/Lineno at point")
2830 (init .
(lambda () (require 'ffap
)))
2831 (candidates . anything-c-ffap-line-candidates
)
2833 ;; (anything 'anything-c-source-ffap-line)
2835 ;;; list of files gleaned from every dired buffer
2836 (defun anything-c-files-in-all-dired-candidates ()
2840 (cond ((listp dir
) ;filelist
2842 ((equal "" (file-name-nondirectory dir
)) ;dir
2843 (directory-files dir t
))
2845 (file-expand-wildcards dir t
))))
2847 (mapcar (lambda (buf)
2849 (when (eq major-mode
'dired-mode
)
2850 (if (consp dired-directory
)
2851 (cdr dired-directory
) ;filelist
2852 dired-directory
))) ;dir or wildcard
2854 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2856 (defvar anything-c-source-files-in-all-dired
2857 '((name .
"Files in all dired buffer.")
2858 (candidates . anything-c-files-in-all-dired-candidates
)
2860 ;; (anything 'anything-c-source-files-in-all-dired)
2862 (defcustom anything-c-filelist-file-name nil
2863 "*Filename of file list.
2864 Accept a list of string for multiple files.
2866 This file tend to be very large (> 100MB) and recommend to be in ramdisk for speed.
2867 File list is created by make-filelist.rb script.
2870 ruby make-filelist.rb > /tmp/all.filelist
2873 ;; Assume that /tmp is ramdisk or tmpfs
2874 (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")
2875 (setq anything-c-filelist-file-name \"/tmp/all.filelist\")
2878 :group
'anything-config
)
2879 (defvar anything-c-source-filelist
2880 '((name .
"FileList")
2881 (grep-candidates . anything-c-filelist-file-name
)
2882 (candidate-number-limit .
200)
2883 (requires-pattern .
4)
2887 (defun anything-filelist ()
2888 "Preconfigured `anything' to open files instantly."
2890 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
2893 (defun anything-filelist+ ()
2894 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
2896 This is a replacement for `anything-for-files'."
2898 (anything-other-buffer
2899 '(anything-c-source-ffap-line
2900 anything-c-source-ffap-guesser
2901 anything-c-source-buffers
+
2902 anything-c-source-recentf
2903 anything-c-source-bookmarks
2904 anything-c-source-file-cache
2905 anything-c-source-filelist
)
2906 "*anything file list*"))
2911 (defvar anything-c-info-pages nil
2912 "All info pages on system.
2913 Will be calculated the first time you invoke anything with this
2916 (defvar anything-c-source-info-pages
2917 `((name .
"Info Pages")
2920 (if anything-c-info-pages
2921 anything-c-info-pages
2922 (setq anything-c-info-pages
2923 (save-window-excursion
2926 (Info-find-node "dir" "top")
2927 (goto-char (point-min))
2928 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2930 (while (re-search-forward info-topic-regexp nil t
)
2931 (add-to-list 'topics
(match-string-no-properties 1)))
2932 (goto-char (point-min))
2935 (action .
(("Show with Info" .
(lambda (node-str)
2936 (info (replace-regexp-in-string
2937 "^[^:]+: " "" node-str
))))))
2938 (requires-pattern .
2)))
2939 ;; (anything 'anything-c-source-info-pages)
2942 ;;; Use info-index plug-in. Note that `name' attribute is
2943 ;;; not needed but `anything-c-insert-summary' uses it.
2945 (defvar anything-c-source-info-elisp
2946 '((name .
"Info index: elisp")
2947 (info-index .
"elisp")))
2948 ;; (anything 'anything-c-source-info-elisp)
2951 (defvar anything-c-source-info-cl
2952 '((name .
"Info index: cl")
2953 (info-index .
"cl")))
2954 ;; (anything 'anything-c-source-info-cl)
2957 (defvar anything-c-source-info-org
2958 '((name .
"Info index: org")
2959 (info-index .
"org")))
2960 ;; (anything 'anything-c-source-info-org)
2962 ;; Info Index ratpoison
2963 (defvar anything-c-source-info-ratpoison
2964 '((name .
"Info index: ratpoison")
2965 (info-index .
"ratpoison")))
2966 ;; (anything 'anything-c-source-info-ratpoison)
2969 (defvar anything-c-source-info-zsh
2970 '((name .
"Info index: zsh")
2971 (info-index .
"zsh")))
2972 ;; (anything 'anything-c-source-info-zsh)
2975 (defvar anything-c-source-info-bash
2976 '((name .
"Info index: bash")
2977 (info-index .
"bash")))
2978 ;; (anything 'anything-c-source-info-bash)
2980 ;; Info Index coreutils
2981 (defvar anything-c-source-info-coreutils
2982 '((name .
"Info index: coreutils")
2983 (info-index .
"coreutils")))
2984 ;; (anything 'anything-c-source-info-coreutils)
2986 ;; Info Index fileutils
2987 (defvar anything-c-source-info-fileutils
2988 '((name .
"Info index: fileutils")
2989 (info-index .
"fileutils")))
2990 ;; (anything 'anything-c-source-info-fileutils)
2993 (defvar anything-c-source-info-find
2994 '((name .
"Info index: find")
2995 (info-index .
"find")))
2996 ;; (anything 'anything-c-source-info-find)
2998 ;; Info Index sh-utils
2999 (defvar anything-c-source-info-sh-utils
3000 '((name .
"Info index: sh-utils")
3001 (info-index .
"sh-utils")))
3002 ;; (anything 'anything-c-source-info-sh-utils)
3004 ;; Info Index textutils
3005 (defvar anything-c-source-info-textutils
3006 '((name .
"Info index: textutils")
3007 (info-index .
"textutils")))
3008 ;; (anything 'anything-c-source-info-textutils)
3011 (defvar anything-c-source-info-libc
3012 '((name .
"Info index: libc")
3013 (info-index .
"libc")))
3014 ;; (anything 'anything-c-source-info-libc)
3017 (defvar anything-c-source-info-make
3018 '((name .
"Info index: make")
3019 (info-index .
"make")))
3020 ;; (anything 'anything-c-source-info-make)
3022 ;; Info Index automake
3023 (defvar anything-c-source-info-automake
3024 '((name .
"Info index: automake")
3025 (info-index .
"automake")))
3026 ;; (anything 'anything-c-source-info-automake)
3028 ;; Info Index autoconf
3029 (defvar anything-c-source-info-autoconf
3030 '((name .
"Info index: autoconf")
3031 (info-index .
"autoconf")))
3032 ;; (anything 'anything-c-source-info-autoconf)
3034 ;; Info Index emacs-lisp-intro
3035 (defvar anything-c-source-info-emacs-lisp-intro
3036 '((name .
"Info index: emacs-lisp-intro")
3037 (info-index .
"emacs-lisp-intro")))
3038 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
3041 (defvar anything-c-source-info-emacs
3042 '((name .
"Info index: emacs")
3043 (info-index .
"emacs")))
3044 ;; (anything 'anything-c-source-info-emacs)
3047 (defvar anything-c-source-info-elib
3048 '((name .
"Info index: elib")
3049 (info-index .
"elib")))
3050 ;; (anything 'anything-c-source-info-elib)
3053 (defvar anything-c-source-info-eieio
3054 '((name .
"Info index: eieio")
3055 (info-index .
"eieio")))
3056 ;; (anything 'anything-c-source-info-eieio)
3058 ;; Info Index gauche-refe
3059 (defvar anything-c-source-info-gauche-refe
3060 '((name .
"Info index: gauche")
3061 (info-index .
"gauche-refe")))
3062 ;; (anything 'anything-c-source-info-gauche-refe)
3065 (defvar anything-c-source-info-guile
3066 '((name .
"Info index: guile")
3067 (info-index .
"guile")))
3068 ;; (anything 'anything-c-source-info-guile)
3070 ;; Info Index guile-tut
3071 (defvar anything-c-source-info-guile-tut
3072 '((name .
"Info index: guile-tut")
3073 (info-index .
"guile-tut")))
3074 ;; (anything 'anything-c-source-info-guile-tut)
3077 (defvar anything-c-source-info-goops
3078 '((name .
"Info index: goops")
3079 (info-index .
"goops")))
3080 ;; (anything 'anything-c-source-info-goops)
3082 ;; Info Index screen
3083 (defvar anything-c-source-info-screen
3084 '((name .
"Info index: screen")
3085 (info-index .
"screen")
3086 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
3087 ;; (anything 'anything-c-source-info-screen)
3090 (defvar anything-c-source-info-latex
3091 '((name .
"Info index: latex")
3092 (info-index .
"latex")))
3093 ;; (anything 'anything-c-source-info-latex)
3096 (defvar anything-c-source-info-gawk
3097 '((name .
"Info index: gawk")
3098 (info-index .
"gawk")))
3099 ;; (anything 'anything-c-source-info-gawk)
3102 (defvar anything-c-source-info-sed
3103 '((name .
"Info index: sed")
3104 (info-index .
"sed")))
3105 ;; (anything 'anything-c-source-info-sed)
3108 (defvar anything-c-source-info-m4
3109 '((name .
"Info index: m4")
3110 (info-index .
"m4")))
3111 ;; (anything 'anything-c-source-info-m4)
3114 (defvar anything-c-source-info-wget
3115 '((name .
"Info index: wget")
3116 (info-index .
"wget")))
3117 ;; (anything 'anything-c-source-info-wget)
3119 ;; Info Index binutils
3120 (defvar anything-c-source-info-binutils
3121 '((name .
"Info index: binutils")
3122 (info-index .
"binutils")))
3123 ;; (anything 'anything-c-source-info-binutils)
3126 (defvar anything-c-source-info-as
3127 '((name .
"Info index: as")
3128 (info-index .
"as")))
3129 ;; (anything 'anything-c-source-info-as)
3132 (defvar anything-c-source-info-bfd
3133 '((name .
"Info index: bfd")
3134 (info-index .
"bfd")))
3135 ;; (anything 'anything-c-source-info-bfd)
3138 (defvar anything-c-source-info-gprof
3139 '((name .
"Info index: gprof")
3140 (info-index .
"gprof")))
3141 ;; (anything 'anything-c-source-info-gprof)
3144 (defvar anything-c-source-info-ld
3145 '((name .
"Info index: ld")
3146 (info-index .
"ld")))
3147 ;; (anything 'anything-c-source-info-ld)
3150 (defvar anything-c-source-info-diff
3151 '((name .
"Info index: diff")
3152 (info-index .
"diff")))
3153 ;; (anything 'anything-c-source-info-diff)
3156 (defvar anything-c-source-info-flex
3157 '((name .
"Info index: flex")
3158 (info-index .
"flex")))
3159 ;; (anything 'anything-c-source-info-flex)
3162 (defvar anything-c-source-info-grep
3163 '((name .
"Info index: grep")
3164 (info-index .
"grep")))
3165 ;; (anything 'anything-c-source-info-grep)
3168 (defvar anything-c-source-info-gzip
3169 '((name .
"Info index: gzip")
3170 (info-index .
"gzip")))
3171 ;; (anything 'anything-c-source-info-gzip)
3173 ;; Info Index libtool
3174 (defvar anything-c-source-info-libtool
3175 '((name .
"Info index: libtool")
3176 (info-index .
"libtool")))
3177 ;; (anything 'anything-c-source-info-libtool)
3179 ;; Info Index texinfo
3180 (defvar anything-c-source-info-texinfo
3181 '((name .
"Info index: texinfo")
3182 (info-index .
"texinfo")))
3183 ;; (anything 'anything-c-source-info-texinfo)
3186 (defvar anything-c-source-info-info
3187 '((name .
"Info index: info")
3188 (info-index .
"info")))
3189 ;; (anything 'anything-c-source-info-info)
3192 (defvar anything-c-source-info-gdb
3193 '((name .
"Info index: gdb")
3194 (info-index .
"gdb")))
3195 ;; (anything 'anything-c-source-info-gdb)
3198 (defvar anything-c-source-info-stabs
3199 '((name .
"Info index: stabs")
3200 (info-index .
"stabs")))
3201 ;; (anything 'anything-c-source-info-stabs)
3203 ;; Info Index cvsbook
3204 (defvar anything-c-source-info-cvsbook
3205 '((name .
"Info index: cvsbook")
3206 (info-index .
"cvsbook")))
3207 ;; (anything 'anything-c-source-info-cvsbook)
3210 (defvar anything-c-source-info-cvs
3211 '((name .
"Info index: cvs")
3212 (info-index .
"cvs")))
3213 ;; (anything 'anything-c-source-info-cvs)
3216 (defvar anything-c-source-info-bison
3217 '((name .
"Info index: bison")
3218 (info-index .
"bison")))
3219 ;; (anything 'anything-c-source-info-bison)
3221 ;; Info Index id-utils
3222 (defvar anything-c-source-info-id-utils
3223 '((name .
"Info index: id-utils")
3224 (info-index .
"id-utils")))
3225 ;; (anything 'anything-c-source-info-id-utils)
3227 ;; Info Index global
3228 (defvar anything-c-source-info-global
3229 '((name .
"Info index: global")
3230 (info-index .
"global")))
3231 ;; (anything 'anything-c-source-info-global)
3235 (defvar anything-c-man-pages nil
3236 "All man pages on system.
3237 Will be calculated the first time you invoke anything with this
3240 (defvar anything-c-source-man-pages
3241 `((name .
"Manual Pages")
3242 (candidates .
(lambda ()
3243 (if anything-c-man-pages
3244 anything-c-man-pages
3245 ;; XEmacs doesn't have a woman :)
3246 (setq anything-c-man-pages
3249 (woman-file-name "")
3250 (sort (mapcar 'car woman-topic-all-completions
)
3252 (action ("Show with Woman"
3253 .
(lambda (candidate)
3254 (let ((wfiles (woman-file-name-all-completions candidate
)))
3255 (if (> (length wfiles
) 1)
3256 (woman-find-file (anything-comp-read "ManFile: " wfiles
3258 (woman candidate
))))))
3259 ;; Woman does not work OS X
3260 ;; http://xahlee.org/emacs/modernization_man_page.html
3261 (action-transformer .
(lambda (actions candidate
)
3262 (if (eq system-type
'darwin
)
3263 '(("Show with Man" . man
))
3265 (requires-pattern .
2)))
3266 ;; (anything 'anything-c-source-man-pages)
3269 ;;; Complex command history
3270 (defvar anything-c-source-complex-command-history
3271 '((name .
"Complex Command History")
3272 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
3274 ;; (anything 'anything-c-source-complex-command-history)
3277 (defvar anything-c-source-extended-command-history
3278 '((name .
"Emacs Commands History")
3279 (candidates . extended-command-history
)
3281 ;; (anything 'anything-c-source-extended-command-history)
3284 (defvar anything-c-source-emacs-commands
3285 '((name .
"Emacs Commands")
3286 (candidates .
(lambda ()
3288 (mapatoms (lambda (a)
3290 (push (symbol-name a
)
3292 (sort commands
'string-lessp
))))
3294 (requires-pattern .
2))
3295 "Source for completing and invoking Emacs commands.
3296 A command is a function with interactive spec that can
3297 be invoked with `M-x'.
3299 To get non-interactive functions listed, use
3300 `anything-c-source-emacs-functions'.")
3301 ;; (anything 'anything-c-source-emacs-commands)
3305 ;; Another replacement of `M-x' that act exactly like the
3306 ;; vanilla Emacs one, no problem of windows configuration, prefix args
3307 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
3308 ;; anything invocation.
3310 (defun anything-M-x ()
3311 "Preconfigured `anything' for Emacs commands.
3312 It is `anything' replacement of regular `M-x' `execute-extended-command'."
3314 (let* (in-help help-cand
3315 (command (anything-comp-read
3320 :name
"Emacs Commands"
3322 #'(lambda (candidate)
3323 (if (and in-help
(string= candidate help-cand
))
3324 (progn (kill-buffer "*Help*") (setq in-help nil
))
3325 (describe-function (intern candidate
))
3327 (setq help-cand candidate
))
3328 :persistent-help
"Describe this command"
3329 :history extended-command-history
3331 :fc-transformer
'anything-M-x-transformer
))
3332 (history (loop with hist
3333 for i in extended-command-history
3334 for com
= (intern i
)
3335 when
(and (fboundp com
) (not (member i hist
)))
3336 collect i into hist finally return hist
)))
3337 (unless current-prefix-arg
(setq current-prefix-arg anything-current-prefix-arg
))
3338 (call-interactively (intern command
))
3339 (setq extended-command-history
(cons command
(delete command history
)))))
3341 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
3342 "Return alist of MODE-MAP."
3343 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
3344 for str-key
= (key-description key
)
3345 for ismenu
= (string-match "<menu-bar>" str-key
)
3346 unless ismenu collect
(cons str-key com
)))
3348 (defun anything-get-mode-map-from-mode (mode)
3349 "Guess the mode-map name according to MODE.
3350 Some modes don't use conventional mode-map name
3351 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
3352 Return nil if no mode-map found."
3354 ;; Start with a conventional mode-map name.
3355 with mode-map
= (intern-soft (format "%s-map" mode
))
3356 with mode-string
= (symbol-name mode
)
3357 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
3358 while
(not mode-map
)
3359 for count downfrom
(length mode-name
)
3360 ;; Return when no result after parsing entire string.
3361 when
(eq count
0) return nil
3362 for sub-name
= (substring mode-name
0 count
)
3363 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
3364 finally return mode-map
))
3366 (defun anything-M-x-current-mode-map-alist ()
3367 "Return mode-map alist of current `major-mode'."
3368 (let ((map (anything-get-mode-map-from-mode major-mode
)))
3369 (when (and map
(boundp map
))
3370 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
3372 (defface anything-M-x-key-face
'((t (:foreground
"orange" :underline t
)))
3373 "*Face used in anything-M-x to show keybinding."
3376 (defun anything-M-x-transformer (candidates sources
)
3377 "filtered-candidate-transformer to show bindings in emacs commands.
3378 Show global bindings and local bindings according to current `major-mode'."
3380 with local-map
= (with-current-buffer anything-current-buffer
3381 (anything-M-x-current-mode-map-alist))
3383 for cand
= (symbol-name i
)
3384 for local-key
= (car (rassq i local-map
))
3385 for key
= (substitute-command-keys (format "\\[%s]" cand
))
3387 (cons (if (string-match "^M-x" key
)
3390 cand
" (" (propertize local-key
'face
'anything-M-x-key-face
)
3394 cand
" (" (propertize key
'face
'anything-M-x-key-face
) ")"))
3398 (defvar anything-c-source-lacarte
3399 '((name .
"Lacarte")
3400 (init .
(lambda () (require 'lacarte
)))
3401 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
3402 (candidate-number-limit .
9999)
3403 (action . anything-c-call-interactively
))
3406 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
3407 ;; (anything 'anything-c-source-lacarte)
3411 (defvar anything-c-source-emacs-functions
3412 '((name .
"Emacs Functions")
3413 (candidates .
(lambda ()
3415 (mapatoms (lambda (a)
3417 (push (symbol-name a
) commands
))))
3418 (sort commands
'string-lessp
))))
3420 (requires-pattern .
2))
3421 "Source for completing Emacs functions.")
3422 ;; (anything 'anything-c-source-emacs-functions)
3424 ;;; With abbrev expansion
3425 ;;; Similar to my exec-abbrev-cmd.el
3426 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
3427 (defvar anything-c-function-abbrev-regexp nil
3428 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
3429 Regexp built from the current `anything-pattern' interpreting it
3431 Only for internal use.")
3433 (defun anything-c-match-function-by-abbrev (candidate)
3434 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
3436 Abbreviations are made by taking the first character from each
3437 word in the function's name, e.g. \"bb\" is an abbrev for
3438 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
3439 (string-match anything-c-function-abbrev-regexp candidate
))
3441 (defvar anything-c-source-emacs-functions-with-abbrevs
3442 (append anything-c-source-emacs-functions
3443 '((match anything-c-match-function-by-abbrev
3444 anything-c-string-match
))
3447 (defadvice anything-update
3448 (before anything-c-update-function-abbrev-regexp activate
)
3449 (let ((char-list (append anything-pattern nil
))
3451 (dolist (c char-list
)
3452 (setq str
(concat str
(list c
) "[^-]*-")))
3453 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
3454 (setq anything-c-function-abbrev-regexp str
))))))))
3455 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
3457 (defvar anything-c-source-advice
3458 '((name .
"Function Advice")
3459 (candidates . anything-c-advice-candidates
)
3460 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
3461 ;; (real-to-display . anything-c-advice-real-to-display)
3464 (persistent-action . anything-c-advice-persistent-action
)
3465 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
3466 ;; (anything 'anything-c-source-advice)
3467 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
3470 (defun anything-c-advice-candidates ()
3472 (loop for
(fname) in ad-advised-functions
3473 for function
= (intern fname
)
3475 (loop for class in ad-advice-classes append
3476 (loop for advice in
(ad-get-advice-info-field function class
)
3477 for enabled
= (ad-advice-enabled advice
)
3481 (if enabled
"Enabled " "Disabled")
3482 (propertize fname
'face
'font-lock-function-name-face
)
3483 (ad-make-single-advice-docstring advice class nil
))
3484 (list function class advice
))))))
3486 (defun anything-c-advice-persistent-action (func-class-advice)
3487 (if current-prefix-arg
3488 (anything-c-advice-toggle func-class-advice
)
3489 (describe-function (car func-class-advice
))))
3491 (defun anything-c-advice-toggle (func-class-advice)
3492 (destructuring-bind (function class advice
) func-class-advice
3493 (cond ((ad-advice-enabled advice
)
3494 (ad-advice-set-enabled advice nil
)
3495 (message "Disabled"))
3497 (ad-advice-set-enabled advice t
)
3498 (message "Enabled")))
3499 (ad-activate function
)
3500 (and anything-in-persistent-action
3501 (anything-c-advice-update-current-display-string))))
3503 (defun anything-c-advice-update-current-display-string ()
3504 (anything-edit-current-selection
3505 (let ((newword (cond ((looking-at "Disabled") "Enabled")
3506 ((looking-at "Enabled") "Disabled")))
3509 (delete-region (point) (progn (forward-word 1) (point)))
3510 (insert newword
)))))
3513 (defun anything-manage-advice ()
3514 "Preconfigured `anything' to disable/enable function advices."
3516 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
3520 (defvar anything-c-source-emacs-variables
3521 '((name .
"Emacs Variables")
3522 (candidates .
(lambda ()
3523 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
3525 (requires-pattern .
2))
3526 "Source for completing Emacs variables.")
3527 ;; (anything 'anything-c-source-emacs-variables)
3531 (eval-when-compile (require 'bookmark
))
3532 (defvar anything-c-source-bookmarks
3533 '((name .
"Bookmarks")
3535 (require 'bookmark
)))
3536 (candidates . bookmark-all-names
)
3538 "See (info \"(emacs)Bookmarks\").")
3539 ;; (anything 'anything-c-source-bookmarks)
3542 (defvar anything-c-source-bookmark-set
3543 '((name .
"Set Bookmark")
3545 (action . bookmark-set
))
3546 "See (info \"(emacs)Bookmarks\").")
3547 ;; (anything 'anything-c-source-bookmark-set)
3549 ;;; Visible Bookmarks
3550 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
3553 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
3554 (defvar anything-c-source-bm
3555 '((name .
"Visible Bookmarks")
3556 (init . anything-c-bm-init
)
3557 (candidates-in-buffer)
3561 http://www.nongnu.org/bm/")
3563 (defun anything-c-bm-init ()
3564 "Init function for `anything-c-source-bm'."
3565 (when (require 'bm nil t
)
3567 (let ((bookmarks (bm-lists))
3568 (buf (anything-candidate-buffer 'global
)))
3569 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
3570 '< :key
'overlay-start
))
3571 (let ((start (overlay-start bm
))
3572 (end (overlay-end bm
))
3573 (annotation (or (overlay-get bm
'annotation
) "")))
3574 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
3575 (let ((str (format "%5d: [%s]: %s\n"
3576 (line-number-at-pos start
)
3578 (buffer-substring start
(1- end
)))))
3579 (with-current-buffer buf
(insert str
))))))))))
3581 ;;; Special bookmarks
3582 (defvar anything-c-source-bookmarks-ssh
3583 '((name .
"Bookmarks-ssh")
3585 (require 'bookmark
)))
3586 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
3588 "See (info \"(emacs)Bookmarks\").")
3589 ;; (anything 'anything-c-source-bookmarks-ssh)
3591 (defvar anything-c-source-bookmarks-su
3592 '((name .
"Bookmarks-root")
3594 (require 'bookmark
)))
3595 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
3596 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
3599 "See (info \"(emacs)Bookmarks\").")
3600 ;; (anything 'anything-c-source-bookmarks-su)
3602 (defvar anything-c-source-bookmarks-local
3603 '((name .
"Bookmarks-Local")
3605 (require 'bookmark
)))
3606 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
3607 (filtered-candidate-transformer
3608 anything-c-adaptive-sort
3609 anything-c-highlight-bookmark
)
3611 "See (info \"(emacs)Bookmarks\").")
3612 ;; (anything 'anything-c-source-bookmarks-local)
3614 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
3615 (let* ((lis-all (bookmark-all-names))
3616 (lis-loc (cond (local (loop for i in lis-all
3617 unless
(string-match "^(ssh)\\|^(su)" i
)
3619 (su (loop for i in lis-all
3620 when
(string-match "^(su)" i
)
3622 (sudo (loop for i in lis-all
3623 when
(string-match "^(sudo)" i
)
3625 (ssh (loop for i in lis-all
3626 when
(string-match "^(ssh)" i
)
3628 (sort lis-loc
'string-lessp
)))
3630 (defun anything-c-bookmark-root-logged-p ()
3632 (dolist (i (mapcar #'buffer-name
(buffer-list)))
3633 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
3634 (throw 'break t
)))))
3636 (defun anything-c-highlight-bookmark-su (files source
)
3637 (if (anything-c-bookmark-root-logged-p)
3638 (anything-c-highlight-bookmark files source
)
3639 (anything-c-highlight-not-logged files source
)))
3641 (defun anything-c-highlight-not-logged (files source
)
3642 (loop for i in files
3643 collect
(propertize i
'face anything-c-bookmarks-face3
)))
3645 (defun anything-c-highlight-bookmark (bookmarks source
)
3646 "Used as `candidate-transformer' to colorize bookmarks.
3647 Work both with standard Emacs bookmarks and bookmark-extensions.el."
3648 (loop for i in bookmarks
3649 for isfile
= (bookmark-get-filename i
)
3650 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
3651 (bmkext-get-buffer-name i
))
3652 for handlerp
= (and (fboundp 'bookmark-get-handler
)
3653 (bookmark-get-handler i
))
3654 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
3655 (bmkext-w3m-bookmark-p i
))
3656 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
3657 (bmkext-gnus-bookmark-p i
))
3658 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
3659 (bmkext-man-bookmark-p i
))
3660 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
3661 (bmkext-woman-bookmark-p i
))
3662 for handlerp
= (bookmark-get-handler i
)
3663 for isannotation
= (bookmark-get-annotation i
)
3664 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
3665 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
3666 ;; Add a * if bookmark have annotation
3667 if
(and isannotation
(not (string-equal isannotation
"")))
3668 do
(setq i
(concat "*" i
))
3669 collect
(cond (;; info buffers
3671 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
3674 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
3677 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
3680 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
3683 (propertize i
'face
'((:foreground
"Tomato"))))
3685 (and isfile
(file-directory-p isfile
))
3686 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
3689 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
3692 ;;; Faces for bookmarks
3693 (defface anything-bmkext-info
3694 '((t (:foreground
"green")))
3695 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3698 (defface anything-bmkext-w3m
3699 '((t (:foreground
"yellow")))
3700 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3703 (defface anything-bmkext-gnus
3704 '((t (:foreground
"magenta")))
3705 "*Face used for Gnus bookmarks."
3708 (defface anything-bmkext-man
3709 '((t (:foreground
"Orange4")))
3710 "*Face used for Woman/man bookmarks."
3713 (defface anything-bmkext-no--file
3714 '((t (:foreground
"grey")))
3715 "*Face used for non--file bookmarks."
3718 (defface anything-bmkext-file
3719 '((t (:foreground
"Deepskyblue2")))
3720 "*Face used for non--file bookmarks."
3723 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
3724 "Face for su/sudo bookmarks."
3727 (defvar anything-c-bookmarks-face1
'anything-dir-heading
)
3728 (defvar anything-c-bookmarks-face2
'anything-file-name
)
3729 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
3732 ;;; Sources to filter bookmark-extensions bookmarks.
3733 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3734 ;; If you want to enable google-maps in addressbook you will need
3735 ;; Julien Danjou google-maps-el package available here:
3736 ;; http://julien.danjou.info/google-maps-el.html
3738 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
3739 "Return a filtered `bookmark-alist' sorted alphabetically."
3741 with alist
= (if args
3742 (apply #'(lambda (x) (funcall fn x
)) args
)
3747 finally return
(sort sa
'string-lessp
)))
3750 (defvar anything-c-source-bmkext-addressbook
3751 '((name .
"Bookmark Addressbook")
3753 (require 'bookmark-extensions
)
3754 (bookmark-maybe-load-default-file)))
3755 (candidates . anything-c-bmkext-addressbook-setup-alist
)
3757 .
(lambda (candidate)
3758 (let ((bmk (anything-bookmark-get-bookmark-from-name
3760 (bookmark--jump-via bmk
'pop-to-buffer
))))
3761 (persistent-help .
"Show contact - Prefix with C-u to append")
3762 (filtered-candidate-transformer
3763 anything-c-adaptive-sort
3764 anything-c-highlight-bookmark
)
3765 (action .
(("Show person's data"
3766 .
(lambda (candidate)
3767 (let ((bmk (anything-bookmark-get-bookmark-from-name
3769 (current-prefix-arg anything-current-prefix-arg
))
3770 (bookmark-jump bmk
))))
3772 .
(lambda (candidate)
3773 (let ((bmk (anything-bookmark-get-bookmark-from-name
3775 (if anything-current-prefix-arg
3776 (addressbook-set-mail-buffer1 bmk
'append
)
3777 (addressbook-set-mail-buffer1 bmk
)))))
3779 .
(lambda (candidate)
3780 (let ((bmk (anything-bookmark-get-bookmark-from-name
3782 (addressbook-bookmark-edit
3783 (assoc bmk bookmark-alist
)))))
3784 ("Insert Email at point"
3785 .
(lambda (candidate)
3786 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3788 (mlist (split-string
3790 'email
(assoc bmk bookmark-alist
))
3793 (if (> (length mlist
) 1)
3795 "Insert Mail Address: " mlist
:must-match t
)
3798 .
(lambda (candidate)
3799 (let ((bmk (anything-bookmark-get-bookmark-from-name
3801 (bookmark-show-annotation bmk
))))
3803 .
(lambda (candidate)
3804 (let ((bmk (anything-bookmark-get-bookmark-from-name
3806 (bookmark-edit-annotation bmk
))))
3808 .
(lambda (candidate)
3809 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3811 (full-bmk (assoc bmk bookmark-alist
)))
3812 (addressbook-google-map full-bmk
))))))))
3815 (defun anything-c-bmkext-addressbook-setup-alist ()
3816 "Specialized filter function for bookmarks w3m."
3817 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
3820 (defvar anything-c-source-bookmark-w3m
3821 '((name .
"Bookmark W3m")
3823 (require 'bookmark-extensions
)
3824 (bookmark-maybe-load-default-file)))
3825 (candidates . anything-c-bookmark-w3m-setup-alist
)
3826 (filtered-candidate-transformer
3827 anything-c-adaptive-sort
3828 anything-c-highlight-bookmark
)
3830 ;; (anything 'anything-c-source-bookmark-w3m)
3832 (defun anything-c-bookmark-w3m-setup-alist ()
3833 "Specialized filter function for bookmarks w3m."
3834 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
3837 (defvar anything-c-source-bookmark-images
3838 '((name .
"Bookmark Images")
3840 (require 'bookmark-extensions
)
3841 (bookmark-maybe-load-default-file)))
3842 (candidates . anything-c-bookmark-images-setup-alist
)
3843 (filtered-candidate-transformer
3844 anything-c-adaptive-sort
3845 anything-c-highlight-bookmark
)
3847 ;; (anything 'anything-c-source-bookmark-images)
3849 (defun anything-c-bookmark-images-setup-alist ()
3850 "Specialized filter function for images bookmarks."
3851 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
3854 (defvar anything-c-source-bookmark-man
3855 '((name .
"Bookmark Woman&Man")
3857 (require 'bookmark-extensions
)
3858 (bookmark-maybe-load-default-file)))
3859 (candidates . anything-c-bookmark-man-setup-alist
)
3860 (filtered-candidate-transformer
3861 anything-c-adaptive-sort
3862 anything-c-highlight-bookmark
)
3864 ;; (anything 'anything-c-source-bookmark-man)
3866 (defun anything-c-bookmark-man-setup-alist ()
3867 "Specialized filter function for bookmarks w3m."
3868 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
3869 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
3872 (defvar anything-c-source-bookmark-gnus
3873 '((name .
"Bookmark Gnus")
3875 (require 'bookmark-extensions
)
3876 (bookmark-maybe-load-default-file)))
3877 (candidates . anything-c-bookmark-gnus-setup-alist
)
3878 (filtered-candidate-transformer
3879 anything-c-adaptive-sort
3880 anything-c-highlight-bookmark
)
3882 ;; (anything 'anything-c-source-bookmark-gnus)
3884 (defun anything-c-bookmark-gnus-setup-alist ()
3885 "Specialized filter function for bookmarks gnus."
3886 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
3889 (defvar anything-c-source-bookmark-info
3890 '((name .
"Bookmark Info")
3892 (require 'bookmark-extensions
)
3893 (bookmark-maybe-load-default-file)))
3894 (candidates . anything-c-bookmark-info-setup-alist
)
3895 (filtered-candidate-transformer
3896 anything-c-adaptive-sort
3897 anything-c-highlight-bookmark
)
3899 ;; (anything 'anything-c-source-bookmark-info)
3901 (defun anything-c-bookmark-info-setup-alist ()
3902 "Specialized filter function for bookmarks info."
3903 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
3905 ;; Local Files&directories
3906 (defvar anything-c-source-bookmark-files
&dirs
3907 '((name .
"Bookmark Files&Directories")
3909 (require 'bookmark-extensions
)
3910 (bookmark-maybe-load-default-file)))
3911 (candidates . anything-c-bookmark-local-files-setup-alist
)
3912 (filtered-candidate-transformer
3913 anything-c-adaptive-sort
3914 anything-c-highlight-bookmark
)
3916 ;; (anything 'anything-c-source-bookmark-files&dirs)
3918 (defun anything-c-bookmark-local-files-setup-alist ()
3919 "Specialized filter function for bookmarks locals files."
3920 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
3922 ;; Su Files&directories
3923 (defvar anything-c-source-bookmark-su-files
&dirs
3924 '((name .
"Bookmark Root-Files&Directories")
3926 (require 'bookmark-extensions
)
3927 (bookmark-maybe-load-default-file)))
3928 (candidates . anything-c-bookmark-su-files-setup-alist
)
3929 (filtered-candidate-transformer
3930 anything-c-adaptive-sort
3931 anything-c-highlight-bookmark-su
)
3933 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3935 (defun anything-c-bookmark-su-files-setup-alist ()
3936 "Specialized filter function for bookmarks su/sudo files."
3938 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
3940 for isfile
= (bookmark-get-filename i
)
3941 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
3943 (string-match tramp-file-name-regexp isfile
)))
3944 for issu
= (and istramp
3945 (string-match bmkext-su-or-sudo-regexp isfile
))
3949 ;; Ssh Files&directories
3950 (defvar anything-c-source-bookmark-ssh-files
&dirs
3951 '((name .
"Bookmark Ssh-Files&Directories")
3953 (require 'bookmark-extensions
)
3954 (bookmark-maybe-load-default-file)))
3955 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
3956 (filtered-candidate-transformer . anything-c-adaptive-sort
)
3958 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3960 (defun anything-c-bookmark-ssh-files-setup-alist ()
3961 "Specialized filter function for bookmarks ssh files."
3963 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
3965 for isfile
= (bookmark-get-filename i
)
3966 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
3968 (string-match tramp-file-name-regexp isfile
)))
3969 for isssh
= (and istramp
3970 (string-match "/ssh:" isfile
))
3975 ;; All bookmark-extensions sources.
3977 (defun anything-bookmark-ext ()
3978 "Preconfigured `anything' for bookmark-extensions sources.
3979 Needs bookmark-ext.el
3981 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
3985 '(anything-c-source-bookmark-files&dirs
3986 anything-c-source-bookmark-w3m
3987 anything-c-source-bmkext-addressbook
3988 anything-c-source-bookmark-gnus
3989 anything-c-source-bookmark-info
3990 anything-c-source-bookmark-man
3991 anything-c-source-bookmark-images
3992 anything-c-source-bookmark-su-files
&dirs
3993 anything-c-source-bookmark-ssh-files
&dirs
)
3994 :prompt
"SearchBookmark: "
3995 :buffer
"*anything bmkext*"))
3998 ;; Firefox bookmarks
3999 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
4000 ;; (only for firefox versions >=3)
4001 ;; To achieve that, open about:config in firefox and double click on this line to enable value
4003 ;; user_pref("browser.bookmarks.autoExportHTML", false);
4004 ;; You should have now:
4005 ;; user_pref("browser.bookmarks.autoExportHTML", true);
4007 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
4008 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
4010 (defun anything-get-firefox-user-init-dir ()
4011 "Guess the default Firefox user directory name."
4012 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
4014 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
4015 (goto-char (point-min))
4017 (when (search-forward "Path=" nil t
)
4018 (buffer-substring-no-properties (point) (point-at-eol)))
4020 (file-name-as-directory (concat moz-dir moz-user-dir
))))
4022 (defun anything-guess-firefox-bookmark-file ()
4023 "Return the path of the Firefox bookmarks file."
4024 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
4026 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
4027 "Parse html bookmark FILE and return an alist with (title . url) as elements."
4028 (let (bookmarks-alist url title
)
4030 (insert-file-contents file
)
4031 (goto-char (point-min))
4032 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
4034 (when (re-search-forward url-regexp nil t
)
4035 (setq url
(match-string 0)))
4036 (when (re-search-forward bmk-regexp nil t
)
4037 (setq title
(match-string 1)))
4038 (push (cons title url
) bookmarks-alist
)
4040 (nreverse bookmarks-alist
)))
4042 (defvar anything-c-firefox-bookmarks-alist nil
)
4043 (defvar anything-c-source-firefox-bookmarks
4044 '((name .
"Firefox Bookmarks")
4046 (setq anything-c-firefox-bookmarks-alist
4047 (anything-html-bookmarks-to-alist
4048 (anything-guess-firefox-bookmark-file)
4049 anything-firefox-bookmark-url-regexp
4050 anything-firefox-bookmarks-regexp
))))
4051 (candidates .
(lambda ()
4052 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
4053 (filtered-candidate-transformer
4054 anything-c-adaptive-sort
4055 anything-c-highlight-firefox-bookmarks
)
4056 (action .
(("Browse Url Firefox"
4057 .
(lambda (candidate)
4059 (anything-c-firefox-bookmarks-get-value candidate
))))
4061 .
(lambda (candidate)
4063 (anything-c-firefox-bookmarks-get-value candidate
))))
4066 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
4068 ;; (anything 'anything-c-source-firefox-bookmarks)
4070 (defun anything-c-firefox-bookmarks-get-value (elm)
4071 (assoc-default elm anything-c-firefox-bookmarks-alist
))
4073 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
4074 (loop for i in bookmarks
4076 i
'face
'((:foreground
"YellowGreen"))
4077 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
4080 (eval-when-compile (require 'w3m-bookmark nil t
))
4081 (unless (and (require 'w3m nil t
)
4082 (require 'w3m-bookmark nil t
))
4083 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html"))
4086 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
4087 "Face for w3m bookmarks" :group
'anything
)
4089 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
4090 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
4091 (defvar anything-c-w3m-bookmarks-alist nil
)
4092 (defvar anything-c-source-w3m-bookmarks
4093 '((name .
"W3m Bookmarks")
4095 (setq anything-c-w3m-bookmarks-alist
4096 (anything-html-bookmarks-to-alist
4098 anything-w3m-bookmark-url-regexp
4099 anything-w3m-bookmarks-regexp
))))
4100 (candidates .
(lambda ()
4101 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
4102 (filtered-candidate-transformer
4103 anything-c-adaptive-sort
4104 anything-c-highlight-w3m-bookmarks
)
4105 (action .
(("Browse Url"
4106 .
(lambda (candidate)
4107 (anything-c-w3m-browse-bookmark candidate
)))
4110 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
4111 ("Browse Url Firefox"
4112 .
(lambda (candidate)
4113 (anything-c-w3m-browse-bookmark candidate t
)))
4115 .
(lambda (candidate)
4116 (anything-c-w3m-delete-bookmark candidate
)))
4118 .
(lambda (candidate)
4119 (anything-c-w3m-rename-bookmark candidate
)))))
4120 (persistent-action .
(lambda (candidate)
4121 (if current-prefix-arg
4122 (anything-c-w3m-browse-bookmark candidate t
)
4123 (anything-c-w3m-browse-bookmark candidate nil t
))))
4124 (persistent-help .
"Open URL with emacs-w3m in new tab / \
4125 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
4126 "Needs w3m and emacs-w3m.
4128 http://w3m.sourceforge.net/
4129 http://emacs-w3m.namazu.org/")
4131 ;; (anything 'anything-c-source-w3m-bookmarks)
4133 (defun anything-c-w3m-bookmarks-get-value (elm)
4134 (replace-regexp-in-string
4135 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
4137 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
4138 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
4139 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
4140 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
4142 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
4143 (loop for i in bookmarks
4145 i
'face
'anything-w3m-bookmarks-face
4146 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
4149 (defun anything-c-w3m-delete-bookmark (elm)
4151 (find-file-literally w3m-bookmark-file
)
4152 (goto-char (point-min))
4153 (when (re-search-forward elm nil t
)
4155 (delete-region (point)
4156 (line-end-position))
4157 (delete-blank-lines))
4158 (save-buffer (current-buffer))
4159 (kill-buffer (current-buffer))))
4161 (defun anything-c-w3m-rename-bookmark (elm)
4162 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
4163 (new-title (read-string "NewTitle: " old-title
)))
4165 (find-file-literally w3m-bookmark-file
)
4166 (goto-char (point-min))
4167 (when (re-search-forward (concat elm
"<") nil t
)
4168 (goto-char (1- (point)))
4169 (delete-char (- (length old-title
)))
4171 (save-buffer (current-buffer))
4172 (kill-buffer (current-buffer)))))
4175 ;;; Elisp library scan
4176 (defvar anything-c-source-elisp-library-scan
4177 '((name .
"Elisp libraries (Scan)")
4178 (init .
(anything-c-elisp-library-scan-init))
4179 (candidates-in-buffer)
4180 (action ("Find library"
4181 .
(lambda (candidate) (find-file (find-library-name candidate
))))
4182 ("Find library other window"
4183 .
(lambda (candidate)
4184 (find-file-other-window (find-library-name candidate
))))
4186 .
(lambda (candidate) (load-library candidate
))))))
4187 ;; (anything 'anything-c-source-elisp-library-scan)
4189 (defun anything-c-elisp-library-scan-init ()
4190 "Init anything buffer status."
4191 (let ((anything-buffer (anything-candidate-buffer 'global
))
4192 (library-list (anything-c-elisp-library-scan-list)))
4193 (with-current-buffer anything-buffer
4194 (dolist (library library-list
)
4195 (insert (format "%s\n" library
))))))
4197 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
4198 "Do completion for file names passed to `locate-file'.
4199 DIRS is directory to search path.
4200 STRING is string to match."
4201 ;; Use `load-path' as path when ignore `dirs'.
4202 (or dirs
(setq dirs load-path
))
4203 ;; Init with blank when ignore `string'.
4204 (or string
(setq string
""))
4205 ;; Get library list.
4206 (let ((string-dir (file-name-directory string
))
4207 ;; File regexp that suffix match `load-file-rep-suffixes'.
4208 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
4213 (setq dir default-directory
))
4215 (setq dir
(expand-file-name string-dir dir
)))
4216 (when (file-directory-p dir
)
4217 (dolist (file (file-name-all-completions
4218 (file-name-nondirectory string
) dir
))
4219 ;; Suffixes match `load-file-rep-suffixes'.
4220 (setq name
(if string-dir
(concat string-dir file
) file
))
4221 (if (string-match match-regexp name
)
4222 (add-to-list 'names name
)))))
4227 (defvar anything-c-imenu-delimiter
" / ")
4229 (defvar anything-c-imenu-index-filter nil
)
4230 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
4232 (defvar anything-c-cached-imenu-alist nil
)
4233 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
4235 (defvar anything-c-cached-imenu-candidates nil
)
4236 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
4238 (defvar anything-c-cached-imenu-tick nil
)
4239 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
4241 (eval-when-compile (require 'imenu
))
4242 (setq imenu-auto-rescan t
)
4244 (defun anything-imenu-create-candidates (entry)
4245 "Create candidates with ENTRY."
4246 (if (listp (cdr entry
))
4249 (if (consp (cdr sub
))
4252 (concat (car entry
) anything-c-imenu-delimiter subentry
))
4253 (anything-imenu-create-candidates sub
))
4254 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
4258 (defvar anything-c-source-imenu
4260 (init .
(lambda () (require 'imenu
)))
4261 (candidates . anything-c-imenu-candidates
)
4262 (persistent-action .
(lambda (elm)
4263 (anything-c-imenu-default-action elm
)
4264 (unless (fboundp 'semantic-imenu-tag-overlay
)
4265 (anything-match-line-color-current-line))))
4266 (persistent-help .
"Show this entry")
4267 (action . anything-c-imenu-default-action
))
4268 "See (info \"(emacs)Imenu\")")
4270 ;; (anything 'anything-c-source-imenu)
4272 (defun anything-c-imenu-candidates ()
4273 (with-current-buffer anything-current-buffer
4274 (let ((tick (buffer-modified-tick)))
4275 (if (eq anything-c-cached-imenu-tick tick
)
4276 anything-c-cached-imenu-candidates
4277 (setq imenu--index-alist nil
)
4278 (setq anything-c-cached-imenu-tick tick
4279 anything-c-cached-imenu-candidates
4282 'anything-imenu-create-candidates
4283 (setq anything-c-cached-imenu-alist
4284 (let ((index (imenu--make-index-alist)))
4285 (if anything-c-imenu-index-filter
4286 (funcall anything-c-imenu-index-filter index
)
4288 (setq anything-c-cached-imenu-candidates
4289 (mapcar #'(lambda (x)
4293 anything-c-cached-imenu-candidates
))))))
4295 (setq imenu-default-goto-function
'imenu-default-goto-function
)
4296 (defun anything-c-imenu-default-action (elm)
4297 "The default action for `anything-c-source-imenu'."
4298 (let ((path (split-string elm anything-c-imenu-delimiter
))
4299 (alist anything-c-cached-imenu-alist
))
4300 (if (> (length path
) 1)
4302 (setq alist
(assoc (car path
) alist
))
4303 (setq elm
(cadr path
))
4304 (imenu (assoc elm alist
)))
4305 (imenu (assoc elm alist
)))))
4308 (defvar anything-c-ctags-modes
4309 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
4310 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
4311 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
4313 (defun anything-c-source-ctags-init ()
4314 (when (and buffer-file-name
4315 (memq major-mode anything-c-ctags-modes
)
4316 (anything-current-buffer-is-modified))
4317 (with-current-buffer (anything-candidate-buffer 'local
)
4318 (call-process-shell-command
4319 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
4320 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
4321 anything-buffer-file-name
)
4322 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
4323 nil
(current-buffer))
4324 (goto-char (point-min))
4326 (delete-region (point-min) (point))
4327 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
4328 for lineno-start
= (point)
4329 for lineno
= (buffer-substring
4331 (1- (search-forward "," (point-at-eol) t
)))
4334 (insert (format "%5s:" lineno
))
4335 (search-forward "\177" (point-at-eol) t
)
4336 (delete-region (1- (point)) (point-at-eol))
4337 (forward-line 1)))))
4339 (defvar anything-c-source-ctags
4340 '((name .
"Exuberant ctags")
4341 (init . anything-c-source-ctags-init
)
4342 (candidates-in-buffer)
4345 "Needs Exuberant Ctags.
4347 http://ctags.sourceforge.net/")
4348 ;; (anything 'anything-c-source-ctags)
4351 (eval-when-compile (require 'semantic nil t
))
4352 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
4353 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
4354 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
4355 (defvar anything-semantic-candidates nil
)
4357 (defun anything-semantic-construct-candidates (tags depth
)
4358 (when (require 'semantic nil t
)
4364 (let ((type (semantic-tag-type tag
))
4365 (class (semantic-tag-class tag
)))
4366 (if (or (and (stringp type
)
4367 (or (string= type
"class")
4368 (string= type
"namespace")))
4369 (eq class
'function
)
4370 (eq class
'variable
))
4371 (cons (cons (concat (make-string (* depth
2) ?\s
)
4372 (semantic-format-tag-summarize tag nil t
))
4374 (anything-semantic-construct-candidates
4375 (semantic-tag-components tag
) (1+ depth
)))))))
4378 (defun anything-semantic-default-action (candidate)
4379 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
4380 (semantic-go-to-tag tag
)))
4382 (defvar anything-c-source-semantic
4383 '((name .
"Semantic Tags")
4385 (setq anything-semantic-candidates
4386 (ignore-errors (anything-semantic-construct-candidates
4387 (semantic-fetch-tags) 0)))))
4388 (candidates .
(lambda ()
4389 (if anything-semantic-candidates
4390 (mapcar 'car anything-semantic-candidates
))))
4391 (persistent-action .
(lambda (elm)
4392 (anything-semantic-default-action elm
)
4393 (anything-match-line-color-current-line)))
4394 (persistent-help .
"Show this entry")
4395 (action . anything-semantic-default-action
)
4396 "Needs semantic in CEDET.
4398 http://cedet.sourceforge.net/semantic.shtml
4399 http://cedet.sourceforge.net/"))
4401 ;; (anything 'anything-c-source-semantic)
4403 ;;; Function is called by
4405 (defun anything-simple-call-tree ()
4406 "Preconfigured `anything' for simple-call-tree. List function relationships.
4408 Needs simple-call-tree.el.
4409 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
4411 (anything-other-buffer
4412 '(anything-c-source-simple-call-tree-functions-callers
4413 anything-c-source-simple-call-tree-callers-functions
)
4414 "*anything simple-call-tree*"))
4416 (defvar anything-c-source-simple-call-tree-functions-callers
4417 '((name .
"Function is called by")
4418 (init . anything-c-simple-call-tree-functions-callers-init
)
4420 (candidates . anything-c-simple-call-tree-candidates
)
4421 (persistent-action . anything-c-simple-call-tree-persistent-action
)
4422 (persistent-help .
"Show function definitions by rotation")
4423 (action ("Find definition selected by persistent-action" .
4424 anything-c-simple-call-tree-find-definition
)))
4425 "Needs simple-call-tree.el.
4426 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4428 (defvar anything-c-simple-call-tree-tick nil
)
4429 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
4430 (defun anything-c-simple-call-tree-analyze-maybe ()
4431 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
4432 (simple-call-tree-analyze)
4433 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
4435 (defun anything-c-simple-call-tree-init-base (function message
)
4436 (require 'simple-call-tree
)
4438 (when (anything-current-buffer-is-modified)
4439 (anything-c-simple-call-tree-analyze-maybe)
4440 (let ((list (funcall function simple-call-tree-alist
)))
4441 (with-current-buffer (anything-candidate-buffer 'local
)
4442 (dolist (entry list
)
4443 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
4444 (insert (car entry
) message
4445 (if (string= funcs
" ")
4450 (defun anything-c-simple-call-tree-functions-callers-init ()
4451 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
4454 (defun anything-c-simple-call-tree-candidates ()
4455 (with-current-buffer (anything-candidate-buffer)
4456 (split-string (buffer-string) "\n\n")))
4458 (defvar anything-c-simple-call-tree-related-functions nil
)
4459 (defvar anything-c-simple-call-tree-function-index
0)
4460 (defun anything-c-simple-call-tree-persistent-action (candidate)
4461 (unless (eq last-command
'anything-execute-persistent-action
)
4462 (setq anything-c-simple-call-tree-related-functions
4463 (delete "no functions."
4465 (replace-regexp-in-string " \\| is called by\\| calls "
4468 (setq anything-c-simple-call-tree-function-index -
1))
4469 (incf anything-c-simple-call-tree-function-index
)
4470 (anything-c-simple-call-tree-find-definition candidate
))
4472 (defun anything-c-simple-call-tree-find-definition (candidate)
4475 (nth (mod anything-c-simple-call-tree-function-index
4476 (length anything-c-simple-call-tree-related-functions
))
4477 anything-c-simple-call-tree-related-functions
))))
4479 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
4482 (defvar anything-c-source-simple-call-tree-callers-functions
4483 '((name .
"Function calls")
4484 (init . anything-c-simple-call-tree-callers-functions-init
)
4486 (candidates . anything-c-simple-call-tree-candidates
)
4487 (persistent-action . anything-c-simple-call-tree-persistent-action
)
4488 (persistent-help .
"Show function definitions by rotation")
4489 (action ("Find definition selected by persistent-action" .
4490 anything-c-simple-call-tree-find-definition
)))
4491 "Needs simple-call-tree.el.
4492 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4494 (defun anything-c-simple-call-tree-callers-functions-init ()
4495 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
4497 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
4499 ;;; Commands/Options with doc
4500 (defvar anything-c-auto-document-data nil
)
4501 (make-variable-buffer-local 'anything-c-auto-document-data
)
4502 (defvar anything-c-source-commands-and-options-in-file
4503 '((name .
"Commands/Options in file")
4505 .
(lambda (x) (format "Commands/Options in %s"
4506 (buffer-local-value 'buffer-file-name
4507 anything-current-buffer
))))
4508 (candidates . anything-command-and-options-candidates
)
4511 "List Commands and Options with doc. It needs auto-document.el .
4513 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
4515 (eval-when-compile (require 'auto-document nil t
))
4516 (defun anything-command-and-options-candidates ()
4517 (with-current-buffer anything-current-buffer
4518 (when (and (require 'auto-document nil t
)
4519 (eq major-mode
'emacs-lisp-mode
)
4520 (or (anything-current-buffer-is-modified)
4521 (not anything-c-auto-document-data
)))
4522 (or imenu--index-alist
(imenu--make-index-alist t
))
4523 (setq anything-c-auto-document-data
4524 (destructuring-bind (commands options
)
4525 (adoc-construct anything-current-buffer
)
4527 (loop for
(command . doc
) in commands
4528 for cmdname
= (symbol-name command
)
4531 (format "Command: %s\n %s"
4532 (propertize cmdname
'face font-lock-function-name-face
)
4533 (adoc-first-line doc
))
4534 (assoc cmdname imenu--index-alist
)))
4535 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
4536 for
(option doc default
) in options
4537 for optname
= (symbol-name option
)
4540 (format "Option: %s\n %s\n default = %s"
4541 (propertize optname
'face font-lock-variable-name-face
)
4542 (adoc-first-line doc
)
4543 (adoc-prin1-to-string default
))
4546 anything-c-auto-document-data
))
4548 ;; (anything 'anything-c-source-commands-and-options-in-file)
4550 ;;;; <Color and Face>
4552 (defvar anything-c-source-customize-face
4553 '((name .
"Customize Face")
4555 (unless (anything-candidate-buffer)
4556 (save-window-excursion (list-faces-display))
4557 (anything-candidate-buffer (get-buffer "*Faces*")))))
4558 (candidates-in-buffer)
4559 (get-line . buffer-substring
)
4560 (action .
(lambda (line)
4561 (customize-face (intern (car (split-string line
))))))
4562 (requires-pattern .
3))
4563 "See (info \"(emacs)Faces\")")
4564 ;; (anything 'anything-c-source-customize-face)
4567 (defvar anything-c-source-colors
4569 (init .
(lambda () (unless (anything-candidate-buffer)
4570 (save-window-excursion (list-colors-display))
4571 (anything-candidate-buffer (get-buffer "*Colors*")))))
4572 (candidates-in-buffer)
4573 (get-line . buffer-substring
)
4575 ("Copy Name" .
(lambda (candidate)
4576 (kill-new (anything-c-colors-get-name candidate
))))
4577 ("Copy RGB" .
(lambda (candidate)
4578 (kill-new (anything-c-colors-get-rgb candidate
))))
4579 ("Insert Name" .
(lambda (candidate)
4580 (with-current-buffer anything-current-buffer
4581 (insert (anything-c-colors-get-name candidate
)))))
4582 ("Insert RGB" .
(lambda (candidate)
4583 (with-current-buffer anything-current-buffer
4584 (insert (anything-c-colors-get-rgb candidate
))))))))
4585 ;; (anything 'anything-c-source-colors)
4587 (defun anything-c-colors-get-name (candidate)
4589 (replace-regexp-in-string
4592 (insert (capitalize candidate
))
4593 (goto-char (point-min))
4594 (search-forward-regexp "\\s-\\{2,\\}")
4595 (delete-region (point) (point-max))
4598 (defun anything-c-colors-get-rgb (candidate)
4600 (replace-regexp-in-string
4603 (insert (capitalize candidate
))
4604 (goto-char (point-max))
4605 (search-backward-regexp "\\s-\\{2,\\}")
4606 (delete-region (point) (point-min))
4609 ;;;; <Search Engine>
4610 ;;; Tracker desktop search
4611 (defvar anything-c-source-tracker-search
4612 '((name .
"Tracker Search")
4613 (candidates .
(lambda ()
4614 (start-process "tracker-search-process" nil
4618 (requires-pattern .
3)
4620 "Source for retrieving files matching the current input pattern
4621 with the tracker desktop search.")
4622 ;; (anything 'anything-c-source-tracker-search)
4624 ;;; Spotlight (MacOS X desktop search)
4625 (defvar anything-c-source-mac-spotlight
4628 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
4630 (requires-pattern .
3)
4632 "Source for retrieving files via Spotlight's command line
4634 ;; (anything 'anything-c-source-mac-spotlight)
4639 (defvar anything-c-source-kill-ring
4640 '((name .
"Kill Ring")
4641 (init .
(lambda () (anything-attrset 'last-command last-command
)))
4642 (candidates . anything-c-kill-ring-candidates
)
4643 (action . anything-c-kill-ring-action
)
4647 "Source for browse and insert contents of kill-ring.
4649 You should bind enable-recursive-minibuffers = t to use this source in minibuffer.")
4651 (defun anything-c-kill-ring-candidates ()
4652 (loop for kill in kill-ring
4653 unless
(or (< (length kill
) anything-kill-ring-threshold
)
4654 (string-match "^[\\s\\t]+$" kill
))
4657 (defun anything-c-kill-ring-action (str)
4658 "Insert STR in `kill-ring' and set STR to the head.
4659 If this action is executed just after `yank',
4660 replace with STR as yanked string."
4661 (setq kill-ring
(delete str kill-ring
))
4662 (if (not (eq (anything-attr 'last-command
) 'yank
))
4663 (insert-for-yank str
)
4665 (let ((inhibit-read-only t
)
4666 (before (< (point) (mark t
))))
4668 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
4669 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
4670 (setq yank-undo-function nil
)
4671 (set-marker (mark-marker) (point) (current-buffer))
4672 (insert-for-yank str
)
4673 ;; Set the window start back where it was in the yank command,
4675 (set-window-start (selected-window) yank-window-start t
)
4677 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
4678 ;; It is cleaner to avoid activation, even though the command
4679 ;; loop would deactivate the mark because we inserted text.
4680 (goto-char (prog1 (mark t
)
4681 (set-marker (mark-marker) (point) (current-buffer)))))))
4684 ;; (anything 'anything-c-source-kill-ring)
4687 ;; DO NOT include these sources in `anything-sources' use
4688 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
4689 ;; `anything-all-mark-rings' instead.
4691 (defun anything-c-source-mark-ring-candidates ()
4692 (flet ((get-marks (pos)
4696 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
4697 (when (string= "" line
)
4698 (setq line
"<EMPTY LINE>"))
4699 (format "%7d: %s" (line-number-at-pos) line
)))))
4700 (with-current-buffer anything-current-buffer
4702 with marks
= (cons (mark-marker) mark-ring
)
4705 for m
= (get-marks i
)
4706 unless
(member m recip
)
4707 collect m into recip
4708 finally return recip
))))
4710 (defvar anything-mark-ring-cache nil
)
4711 (defvar anything-c-source-mark-ring
4712 '((name .
"mark-ring")
4714 (setq anything-mark-ring-cache
4715 (ignore-errors (anything-c-source-mark-ring-candidates)))))
4716 (candidates .
(lambda ()
4717 (anything-aif anything-mark-ring-cache
4719 (action .
(("Goto line"
4720 .
(lambda (candidate)
4721 (anything-goto-line (string-to-number candidate
))))))
4722 (persistent-action .
(lambda (candidate)
4723 (anything-goto-line (string-to-number candidate
))
4724 (anything-match-line-color-current-line)))
4725 (persistent-help .
"Show this line")))
4727 ;; (anything 'anything-c-source-mark-ring)
4730 (defun anything-mark-ring ()
4731 "Preconfigured `anything' for `anything-c-source-mark-ring'."
4733 (anything 'anything-c-source-mark-ring
))
4735 ;;; Global-mark-ring
4736 (defvar anything-c-source-global-mark-ring
4737 '((name .
"global-mark-ring")
4738 (candidates . anything-c-source-global-mark-ring-candidates
)
4739 (action .
(("Goto line"
4740 .
(lambda (candidate)
4741 (let ((items (split-string candidate
":")))
4742 (switch-to-buffer (second items
))
4743 (anything-goto-line (string-to-number (car items
))))))))
4744 (persistent-action .
(lambda (candidate)
4745 (let ((items (split-string candidate
":")))
4746 (switch-to-buffer (second items
))
4747 (anything-goto-line (string-to-number (car items
)))
4748 (anything-match-line-color-current-line))))
4749 (persistent-help .
"Show this line")))
4751 (defun anything-c-source-global-mark-ring-candidates ()
4753 (with-current-buffer (marker-buffer m
)
4757 (if (string= "" line
)
4758 (setq line
"<EMPTY LINE>")
4759 (setq line
(car (split-string (thing-at-point 'line
)
4761 (format "%7d:%s: %s"
4762 (line-number-at-pos) (marker-buffer m
) line
)))))
4764 with marks
= global-mark-ring
4767 for gm
= (unless (or (string-match
4768 "^ " (format "%s" (marker-buffer i
)))
4769 (null (marker-buffer i
)))
4771 when
(and gm
(not (member gm recip
)))
4772 collect gm into recip
4773 finally return recip
)))
4775 ;; (anything 'anything-c-source-global-mark-ring)
4778 (defun anything-global-mark-ring ()
4779 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4781 (anything 'anything-c-source-global-mark-ring
))
4784 (defun anything-all-mark-rings ()
4785 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4786 `anything-c-source-mark-ring'."
4788 (anything '(anything-c-source-global-mark-ring
4789 anything-c-source-mark-ring
)))
4792 ;;; Insert from register
4793 (defvar anything-c-source-register
4794 '((name .
"Registers")
4795 (candidates . anything-c-register-candidates
)
4796 (action-transformer . anything-c-register-action-transformer
)
4799 "See (info \"(emacs)Registers\")")
4801 (defun anything-c-register-candidates ()
4802 "Collecting register contents and appropriate commands."
4803 (loop for
(char . val
) in register-alist
4804 for key
= (single-key-description char
)
4805 for string-actions
=
4808 (list (int-to-string val
)
4810 'increment-register
))
4812 (let ((buf (marker-buffer val
)))
4814 (list "a marker in no buffer")
4816 "a buffer position:"
4819 (int-to-string (marker-position val
)))
4821 'insert-register
))))
4822 ((and (consp val
) (window-configuration-p (car val
)))
4823 (list "window configuration."
4825 ((and (consp val
) (frame-configuration-p (car val
)))
4826 (list "frame configuration."
4828 ((and (consp val
) (eq (car val
) 'file
))
4829 (list (concat "file:"
4830 (prin1-to-string (cdr val
))
4833 ((and (consp val
) (eq (car val
) 'file-query
))
4834 (list (concat "file:a file-query reference: file "
4837 (int-to-string (car (cdr (cdr val
))))
4841 (let ((lines (format "%4d" (length val
))))
4842 (list (format "%s: %s\n" lines
4843 (truncate-string-to-width
4844 (mapconcat 'identity
(list (car val
))
4845 ;; (mapconcat (lambda (y) y) val
4846 "^J") (- (window-width) 15)))
4849 (list ;; without properties
4850 (substring-no-properties val
)
4853 'prepend-to-register
))
4856 collect
(cons (format "register %3s: %s" key
(car string-actions
))
4857 (cons char
(cdr string-actions
)))))
4859 (defun anything-c-register-action-transformer (actions register-and-functions
)
4860 "Decide actions by the contents of register."
4861 (loop with func-actions
=
4864 (lambda (c) (insert-register (car c
))))
4866 "Jump to Register" .
4867 (lambda (c) (jump-to-register (car c
))))
4869 "Append Region to Register" .
4870 (lambda (c) (append-to-register
4871 (car c
) (region-beginning) (region-end))))
4872 (prepend-to-register
4873 "Prepend Region to Register" .
4874 (lambda (c) (prepend-to-register
4875 (car c
) (region-beginning) (region-end))))
4877 "Increment Prefix Arg to Register" .
4878 (lambda (c) (increment-register
4879 anything-current-prefix-arg
(car c
)))))
4880 for func in
(cdr register-and-functions
)
4881 for cell
= (assq func func-actions
)
4883 collect
(cdr cell
)))
4885 ;; (anything 'anything-c-source-register)
4887 ;;;; <Headline Extraction>
4888 (defvar anything-c-source-fixme
4889 '((name .
"TODO/FIXME/DRY comments")
4890 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4893 "Show TODO/FIXME/DRY comments in current file.")
4894 ;; (anything 'anything-c-source-fixme)
4896 (defvar anything-c-source-rd-headline
4897 '((name .
"RD HeadLine")
4898 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4899 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
4905 http://en.wikipedia.org/wiki/Ruby_Document_format")
4906 ;; (anything 'anything-c-source-rd-headline)
4908 (defvar anything-c-source-oddmuse-headline
4909 '((name .
"Oddmuse HeadLine")
4910 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4911 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4912 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
4915 "Show Oddmuse headlines, such as EmacsWiki.")
4916 ;; (anything 'anything-c-source-oddmuse-headline)
4918 (defvar anything-c-source-emacs-source-defun
4919 '((name .
"Emacs Source DEFUN")
4920 (headline .
"DEFUN\\|DEFVAR")
4921 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
4922 (or buffer-file-name
""))))
4923 "Show DEFUN/DEFVAR in Emacs C source file.")
4924 ;; (anything 'anything-c-source-emacs-source-defun)
4926 (defvar anything-c-source-emacs-lisp-expectations
4927 '((name .
"Emacs Lisp Expectations")
4928 (headline .
"(desc[ ]\\|(expectations")
4929 (condition .
(eq major-mode
'emacs-lisp-mode
)))
4930 "Show descriptions (desc) in Emacs Lisp Expectations.
4932 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4933 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4935 (defvar anything-c-source-emacs-lisp-toplevels
4936 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4937 (headline .
"^(\\|(@\\*\\|^;;;;")
4938 (get-line . buffer-substring
)
4939 (condition .
(eq major-mode
'emacs-lisp-mode
))
4941 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4942 linkd.el is optional because linkd stars are extracted by regexp.
4943 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4944 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4946 (defvar anything-c-source-org-headline
4947 '((name .
"Org HeadLine")
4949 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4950 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4951 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4952 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4953 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4954 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4955 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4956 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4957 (condition .
(eq major-mode
'org-mode
))
4960 (persistent-action .
(lambda (elm)
4961 (anything-c-action-line-goto elm
)
4964 .
(lambda (actions candidate
)
4965 '(("Go to Line" . anything-c-action-line-goto
)
4966 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline
)))))
4967 "Show Org headlines.
4968 org-mode is very very much extended text-mode/outline-mode.
4970 See (find-library \"org.el\")
4971 See http://orgmode.org for the latest version.")
4973 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
4976 (anything-goto-line (car lineno-and-content
))
4977 (and (looking-at org-complex-heading-regexp
)
4978 (org-make-link-string (concat "*" (match-string 4)))))))
4980 ;; (anything 'anything-c-source-org-headline)
4982 ;;; Anything yaoddmuse
4983 ;; Be sure to have yaoddmuse.el installed
4984 ;; install-elisp may be required if you want to install elisp file from here.
4985 (defvar anything-yaoddmuse-use-cache-file nil
)
4986 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
4987 (defvar anything-c-yaoddmuse-ew-cache nil
)
4988 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
4989 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
4990 (candidates .
(lambda ()
4991 (if anything-yaoddmuse-use-cache-file
4993 (unless anything-c-yaoddmuse-ew-cache
4994 (load anything-c-yaoddmuse-cache-file
)
4995 (setq anything-c-yaoddmuse-ew-cache
4996 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
4997 anything-c-yaoddmuse-ew-cache
)
4998 (yaoddmuse-update-pagename t
)
4999 (gethash "EmacsWiki" yaoddmuse-pages-hash
))))
5000 (action .
(("Edit page" .
(lambda (candidate)
5001 (yaoddmuse-edit "EmacsWiki" candidate
)))
5002 ("Browse page" .
(lambda (candidate)
5003 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
5004 ("Browse page other window" .
(lambda (candidate)
5006 (split-window-vertically))
5007 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
5008 ("Browse diff" .
(lambda (candidate)
5009 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
5010 ("Copy URL" .
(lambda (candidate)
5011 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
5012 (message "Have copy page %s's URL to yank." candidate
)))
5013 ("Create page" .
(lambda (candidate)
5014 (yaoddmuse-edit "EmacsWiki" anything-input
)))
5015 ("Update cache" .
(lambda (candidate)
5016 (if anything-yaoddmuse-use-cache-file
5018 (anything-yaoddmuse-cache-pages t
)
5019 (setq anything-c-yaoddmuse-ew-cache
5020 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
5021 (yaoddmuse-update-pagename))))))
5022 (action-transformer anything-c-yaoddmuse-action-transformer
))
5023 "Needs yaoddmuse.el.
5025 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5027 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
5029 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
5030 '((name .
"Yaoddmuse Post library (EmacsWiki)")
5031 (init .
(anything-yaoddmuse-init))
5032 (candidates-in-buffer)
5033 (action .
(("Post library and Browse" .
(lambda (candidate)
5034 (yaoddmuse-post-file (find-library-name candidate
)
5036 (file-name-nondirectory (find-library-name candidate
))
5038 ("Post library" .
(lambda (candidate)
5039 (yaoddmuse-post-file (find-library-name candidate
)
5041 (file-name-nondirectory (find-library-name candidate
))))))))
5042 "Needs yaoddmuse.el.
5044 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5046 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
5048 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
5049 "Allow the use of `install-elisp' only on elisp files."
5050 (if (string-match "\.el$" candidate
)
5051 (append actions
'(("Install Elisp" .
(lambda (elm)
5052 (install-elisp-from-emacswiki elm
)))))
5056 (defun anything-yaoddmuse-cache-pages (&optional load
)
5057 "Fetch the list of files on emacswiki and create cache file.
5058 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
5060 (yaoddmuse-update-pagename)
5062 (find-file anything-c-yaoddmuse-cache-file
)
5064 (insert "(puthash \"EmacsWiki\" '(")
5065 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
5067 (insert (concat "(\"" (car i
) "\") ")))
5068 (insert ") yaoddmuse-pages-hash)\n")
5070 (kill-buffer (current-buffer))
5071 (when (or current-prefix-arg
5073 (load anything-c-yaoddmuse-cache-file
))))
5076 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
5077 "Preconfigured `anything' to edit or view EmacsWiki page.
5081 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5083 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
5086 (defun anything-yaoddmuse-emacswiki-post-library ()
5087 "Preconfigured `anything' to post library to EmacsWiki.
5091 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5093 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
5095 (defun anything-yaoddmuse-init ()
5096 "Init anything buffer status."
5097 (let ((anything-buffer (anything-candidate-buffer 'global
))
5098 (library-list (yaoddmuse-get-library-list)))
5099 (with-current-buffer anything-buffer
5100 ;; Insert library name.
5101 (dolist (library library-list
)
5102 (insert (format "%s\n" library
)))
5104 (sort-lines nil
(point-min) (point-max)))))
5107 (defvar anything-c-source-eev-anchor
5108 '((name .
"Anchors")
5112 (with-current-buffer anything-current-buffer
5113 (loop initially
(goto-char (point-min))
5114 while
(re-search-forward (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
5115 for anchor
= (match-string-no-properties 1)
5116 collect
(cons (format "%5d:%s"
5117 (line-number-at-pos (match-beginning 0))
5118 (format ee-anchor-format anchor
)) anchor
))))))
5119 (persistent-action .
(lambda (item)
5121 (anything-match-line-color-current-line)))
5122 (persistent-help .
"Show this entry")
5123 (action .
(("Goto link" . ee-to
)))))
5124 ;; (anything 'anything-c-source-eev-anchor)
5128 (defvar anything-c-source-org-keywords
5129 '((name .
"Org Keywords")
5130 (init . anything-c-org-keywords-init
)
5131 (candidates . anything-c-org-keywords-candidates
)
5132 (action . anything-c-org-keywords-insert
)
5133 (persistent-action . anything-c-org-keywords-show-help
)
5134 (persistent-help .
"Show an example and info page to describe this keyword.")
5137 ;; (anything 'anything-c-source-org-keywords)
5138 (defvar anything-c-org-keywords-info-location
5139 '(("#+TITLE:" .
"(org)Export options")
5140 ("#+AUTHOR:" .
"(org)Export options")
5141 ("#+DATE:" .
"(org)Export options")
5142 ("#+EMAIL:" .
"(org)Export options")
5143 ("#+DESCRIPTION:" .
"(org)Export options")
5144 ("#+KEYWORDS:" .
"(org)Export options")
5145 ("#+LANGUAGE:" .
"(org)Export options")
5146 ("#+TEXT:" .
"(org)Export options")
5147 ("#+TEXT:" .
"(org)Export options")
5148 ("#+OPTIONS:" .
"(org)Export options")
5149 ("#+BIND:" .
"(org)Export options")
5150 ("#+LINK_UP:" .
"(org)Export options")
5151 ("#+LINK_HOME:" .
"(org)Export options")
5152 ("#+LATEX_HEADER:" .
"(org)Export options")
5153 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
5154 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
5155 ("#+INFOJS_OPT" .
"(org)Javascript support")
5156 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
5157 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
5158 ("#+ORGTBL" .
"(org)Radio tables")
5159 ("#+HTML:" .
"(org)Quoting HTML tags")
5160 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
5161 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
5162 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
5163 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
5164 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
5165 ("#+BEGIN_SRC" .
"(org)Literal examples")
5166 ("#+CAPTION" .
"(org)Tables in HTML export")
5167 ("#+LABEL" .
"(org)Tables in LaTeX export")
5168 ("#+ATTR_HTML" .
"(org)Links")
5169 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
5171 (defun anything-c-org-keywords-init ()
5172 (unless (anything-attr 'keywords-examples
)
5174 (anything-attrset 'keywords-examples
5178 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
5179 (cons (match-string 2 x
) (match-string 1 x
)))
5180 (org-split-string (org-get-current-options) "\n"))
5181 (mapcar 'list org-additional-option-like-keywords
)))
5182 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
5184 (defun anything-c-org-keywords-candidates ()
5185 (and (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
5186 (anything-attr 'keywords
)))
5188 (defun anything-c-org-keywords-insert (keyword)
5189 (cond ((string-match "BEGIN" keyword
)
5190 (insert "#+" keyword
" ")
5192 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword
) "\n")))
5194 (insert "#+" keyword
" "))))
5196 (defun anything-c-org-keywords-show-help (keyword)
5197 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
5198 "(org)In-buffer settings"))
5199 (search-forward (concat "#+" keyword
) nil t
)
5200 (anything-persistent-highlight-point)
5201 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
5205 (defvar anything-c-source-picklist
5206 '((name .
"Picklist")
5207 (candidates .
(lambda () (mapcar 'car picklist-list
)))
5209 ;; (anything 'anything-c-source-picklist)
5212 (defvar bbdb-records
)
5213 (defvar bbdb-buffer-name
)
5214 (declare-function bbdb
"ext:bbdb-com")
5215 (declare-function bbdb-current-record
"ext:bbdb-com")
5216 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
5217 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
5218 (declare-function bbdb-current-record
"ext:bbdb-com")
5219 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
5220 (declare-function bbdb-records
"ext:bbdb-com"
5221 (&optional dont-check-disk already-in-db-buffer
))
5223 (defun anything-c-bbdb-candidates ()
5224 "Return a list of all names in the bbdb database. The format
5225 is \"Firstname Lastname\"."
5226 (mapcar (lambda (bbdb-record)
5227 (replace-regexp-in-string
5229 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
5232 (defun anything-c-bbdb-create-contact (actions candidate
)
5233 "Action transformer that returns only an entry to add the
5234 current `anything-pattern' as new contact. All other actions are
5236 (if (string= candidate
"*Add to contacts*")
5237 '(("Add to contacts" .
(lambda (actions)
5238 (bbdb-create-internal
5239 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
5240 (read-from-minibuffer "Company: ")
5241 (read-from-minibuffer "Email: ")
5244 (read-from-minibuffer "Note: ")))))
5247 (defun anything-c-bbdb-get-record (candidate)
5248 "Return record that match CANDIDATE."
5249 (bbdb candidate nil
)
5250 (set-buffer "*BBDB*")
5251 (bbdb-current-record))
5253 (defvar anything-c-bbdb-name nil
5254 "Only for internal use.")
5256 (defvar anything-c-source-bbdb
5258 (candidates . anything-c-bbdb-candidates
)
5259 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
5260 ("View person's data" . anything-c-bbdb-view-person-action
))
5261 (filtered-candidate-transformer .
(lambda (candidates source
)
5262 (setq anything-c-bbdb-name anything-pattern
)
5263 (if (not candidates
)
5264 (list "*Add to contacts*")
5266 (action-transformer .
(lambda (actions candidate
)
5267 (anything-c-bbdb-create-contact actions candidate
))))
5270 http://bbdb.sourceforge.net/")
5271 ;; (anything 'anything-c-source-bbdb)
5273 (defun anything-c-bbdb-view-person-action (candidate)
5274 "View BBDB data of single CANDIDATE or marked candidates."
5275 (anything-aif (anything-marked-candidates)
5276 (let ((bbdb-append-records (length it
)))
5278 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
5279 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
5281 (defun anything-c-bbdb-collect-mail-addresses ()
5282 "Return a list of all mail addresses of records in bbdb buffer."
5283 (with-current-buffer bbdb-buffer-name
5284 (loop for i in bbdb-records
5285 if
(bbdb-record-net (car i
))
5286 collect
(bbdb-dwim-net-address (car i
)))))
5288 (defun anything-c-bbdb-compose-mail (candidate)
5289 "Compose a mail with all records of bbdb buffer."
5290 (anything-c-bbdb-view-person-action candidate
)
5291 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
5292 (address-str (mapconcat 'identity address-list
",\n ")))
5293 (compose-mail address-str
)))
5295 ;;; Evaluation Result
5296 (defvar anything-c-source-evaluation-result
5297 '((name .
"Evaluation Result")
5300 (filtered-candidate-transformer .
(lambda (candidates source
)
5303 (with-current-buffer anything-current-buffer
5305 (eval (read anything-pattern
))))
5307 (action ("Copy result to kill-ring" .
(lambda (candidate)
5308 (with-current-buffer anything-buffer
5309 (let ((end (save-excursion
5310 (goto-char (point-max))
5311 (search-backward "\n")
5313 (kill-region (point) end
))))))))
5314 ;; (anything 'anything-c-source-evaluation-result)
5317 (defun anything-eval-expression (arg)
5318 "Preconfigured anything for `anything-c-source-evaluation-result'."
5320 (anything 'anything-c-source-evaluation-result
(when arg
(thing-at-point 'sexp
))
5321 nil nil nil
"*anything eval*"))
5324 (defun anything-eval-expression-with-eldoc ()
5325 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
5328 (let ((timer (run-with-idle-timer eldoc-idle-delay
5329 'repeat
'anything-eldoc-show-in-eval
)))
5331 (call-interactively 'anything-eval-expression
)
5332 (cancel-timer timer
)))
5333 (call-interactively 'anything-eval-expression
)))
5335 (defun anything-eldoc-show-in-eval ()
5336 "Return eldoc in a tooltip for current minibuffer input."
5337 (let* ((str-all (minibuffer-completion-contents))
5341 (goto-char (point-max))
5342 (unless (looking-back ")\\|\"") (forward-char -
1))
5343 (eldoc-current-symbol))))
5344 (doc (or (eldoc-get-var-docstring sym
)
5345 (eldoc-get-fnsym-args-string
5346 (car (eldoc-fnsym-in-current-sexp))))))
5347 (when doc
(tooltip-show doc
))))
5349 ;;; Calculation Result
5350 (defvar anything-c-source-calculation-result
5351 '((name .
"Calculation Result")
5353 (filtered-candidate-transformer .
(lambda (candidates source
)
5356 (calc-eval anything-pattern
)
5358 (action ("Copy result to kill-ring" . kill-new
))))
5359 ;; (anything 'anything-c-source-calculation-result)
5361 ;;; Google Suggestions
5362 (defvar anything-gg-sug-lgh-flag
0)
5363 (defun anything-c-google-suggest-fetch (input)
5364 "Fetch suggestions for INPUT from XML buffer.
5365 Return an alist with elements like (data . number_results)."
5366 (let ((request (concat anything-c-google-suggest-url
5367 (url-hexify-string input
))))
5370 with result-alist
= (xml-get-children
5371 (car (xml-parse-region (point-min) (point-max)))
5372 'CompleteSuggestion
)
5373 for i in result-alist
5374 for data
= (cdr (caadr (assoc 'suggestion i
)))
5375 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
5376 for ldata
= (length data
)
5378 (when (> ldata anything-gg-sug-lgh-flag
)
5379 (setq anything-gg-sug-lgh-flag ldata
))
5380 collect
(cons data nqueries
) into cont
5381 finally return cont
)))
5382 (if anything-google-suggest-use-curl-p
5384 (call-process "curl" nil t nil request
)
5386 (with-current-buffer
5387 (url-retrieve-synchronously request
)
5391 (defun anything-c-google-suggest-set-candidates ()
5392 "Set candidates with result and number of google results found."
5393 (let ((suggestions (anything-c-google-suggest-fetch anything-input
)))
5394 (setq suggestions
(loop for i in suggestions
5395 for interval
= (- anything-gg-sug-lgh-flag
(length (car i
)))
5396 for elm
= (concat (car i
)
5397 (make-string (+ 2 interval
) ?
)
5398 "(" (cdr i
) " results)")
5399 collect
(cons elm
(car i
))))
5400 (if (some (lambda (data) (equal (cdr data
) anything-input
)) suggestions
)
5402 ;; if there is no suggestion exactly matching the input then
5403 ;; prepend a Search on Google item to the list
5406 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
5407 anything-input
))))))
5410 (defun anything-c-google-suggest-action (candidate)
5411 "Default action to jump to a google suggested candidate."
5412 (anything-c-browse-url (concat anything-c-google-suggest-search-url
5413 (url-hexify-string candidate
))))
5416 (defvar anything-c-source-google-suggest
5417 '((name .
"Google Suggest")
5418 (candidates . anything-c-google-suggest-set-candidates
)
5419 (action .
(("Google Search" . anything-c-google-suggest-action
)))
5421 (requires-pattern .
3)
5424 ;; (anything 'anything-c-source-google-suggest)
5426 ;;; Yahoo suggestions
5428 (defun anything-c-yahoo-suggest-fetch (input)
5429 "Fetch Yahoo suggestions for INPUT from XML buffer.
5430 Return an alist with elements like (data . number_results)."
5431 (let ((request (concat anything-c-yahoo-suggest-url
5432 (url-hexify-string input
))))
5435 with result-alist
= (xml-get-children
5436 (car (xml-parse-region (point-min) (point-max)))
5438 for i in result-alist
5439 collect
(caddr i
))))
5440 (with-current-buffer
5441 (url-retrieve-synchronously request
)
5444 (defun anything-c-yahoo-suggest-set-candidates ()
5445 "Set candidates with Yahoo results found."
5446 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
5450 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
5451 anything-input
))))))
5453 (defun anything-c-yahoo-suggest-action (candidate)
5454 "Default action to jump to a Yahoo suggested candidate."
5455 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
5456 (url-hexify-string candidate
))))
5458 (defvar anything-c-source-yahoo-suggest
5459 '((name .
"Yahoo Suggest")
5460 (candidates . anything-c-yahoo-suggest-set-candidates
)
5461 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
5463 (requires-pattern .
3)
5466 ;; (anything 'anything-c-source-yahoo-suggest)
5469 ;;; Need external program surfraw.
5470 ;;; http://surfraw.alioth.debian.org/
5472 (require 'browse-url
)
5473 (defvar w3m-command nil
)
5474 (defvar anything-c-home-url
"http://www.google.fr"
5475 "*Default url to use as home url.")
5477 (defvar anything-browse-url-default-browser-alist
5478 `((,w3m-command . w3m-browse-url
)
5479 (,browse-url-firefox-program . browse-url-firefox
)
5480 (,browse-url-kde-program . browse-url-kde
)
5481 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
5482 (,browse-url-mozilla-program . browse-url-mozilla
)
5483 (,browse-url-galeon-program . browse-url-galeon
)
5484 (,browse-url-netscape-program . browse-url-netscape
)
5485 (,browse-url-mosaic-program . browse-url-mosaic
)
5486 (,browse-url-xterm-program . browse-url-text-xterm
))
5487 "*Alist of (executable . function) to try to find a suitable url browser.")
5489 (defun anything-browse-url-default-browser (url &rest args
)
5490 "Find a suitable browser and ask it to load URL."
5491 (let ((default-browser (loop
5492 for i in anything-browse-url-default-browser-alist
5493 when
(and (car i
) (executable-find (car i
))) return
(cdr i
))))
5495 (apply default-browser url args
)
5496 (error "No usable browser found"))))
5498 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
5499 "Default command to browse URL."
5500 (if browse-url-browser-function
5502 (anything-browse-url-default-browser url
)))
5504 (defun anything-c-build-elvi-list ()
5505 "Return list of all engines and descriptions handled by surfraw."
5508 (call-process "surfraw" nil t nil
5510 (split-string (buffer-string) "\n"))))
5512 (defvar anything-surfraw-engines-history nil
)
5514 (defun anything-surfraw (pattern engine
)
5515 "Preconfigured `anything' to search PATTERN with search ENGINE."
5516 (interactive (list (read-string "SearchFor: ")
5519 (anything-c-build-elvi-list)
5521 :name
"Surfraw Search Engines"
5522 :history anything-surfraw-engines-history
)))
5523 (let* ((engine-nodesc (car (split-string engine
)))
5524 (url (with-temp-buffer
5525 (apply 'call-process
"surfraw" nil t nil
5526 (list engine-nodesc
"-p" pattern
))
5527 (replace-regexp-in-string
5528 "\n" "" (buffer-string)))))
5529 (if (string= engine-nodesc
"W")
5530 (anything-c-browse-url)
5531 (anything-c-browse-url url
)
5532 (setq anything-surfraw-engines-history
5533 (cons engine
(delete engine anything-surfraw-engines-history
))))))
5537 (defun anything-emms-stream-edit-bookmark (elm)
5538 "Change the information of current emms-stream bookmark from anything."
5539 (let* ((cur-buf anything-current-buffer
)
5540 (bookmark (assoc elm emms-stream-list
))
5541 (name (read-from-minibuffer "Description: "
5543 (url (read-from-minibuffer "URL: "
5545 (fd (read-from-minibuffer "Feed Descriptor: "
5546 (int-to-string (nth 2 bookmark
))))
5547 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
5548 (format "%s" (car (last bookmark
))))))
5551 (when (re-search-forward (concat "^" name
) nil t
)
5553 (emms-stream-delete-bookmark)
5554 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
5555 (emms-stream-save-bookmarks-file)
5557 (switch-to-buffer cur-buf
)))))
5559 (defun anything-emms-stream-delete-bookmark (elm)
5560 "Delete an emms-stream bookmark from anything."
5561 (let* ((cur-buf anything-current-buffer
)
5562 (bookmark (assoc elm emms-stream-list
))
5563 (name (nth 0 bookmark
)))
5566 (when (re-search-forward (concat "^" name
) nil t
)
5568 (emms-stream-delete-bookmark)
5569 (emms-stream-save-bookmarks-file)
5571 (switch-to-buffer cur-buf
)))))
5573 (defvar anything-c-source-emms-streams
5574 '((name .
"Emms Streams")
5576 (emms-stream-init)))
5577 (candidates .
(lambda ()
5578 (mapcar 'car emms-stream-list
)))
5579 (action .
(("Play" .
(lambda (elm)
5580 (let* ((stream (assoc elm emms-stream-list
))
5581 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
5582 (url (second stream
)))
5584 ("Delete" . anything-emms-stream-delete-bookmark
)
5585 ("Edit" . anything-emms-stream-edit-bookmark
)))
5586 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
5587 ;; (anything 'anything-c-source-emms-streams)
5589 ;; Don't forget to set `emms-source-file-default-directory'
5590 (defvar anything-c-source-emms-dired
5591 '((name .
"Music Directory")
5592 (candidates .
(lambda ()
5593 (cddr (directory-files emms-source-file-default-directory
))))
5595 (("Play Directory" .
(lambda (item)
5596 (emms-play-directory
5599 emms-source-file-default-directory
))))
5600 ("Open dired in file's directory" .
(lambda (item)
5601 (anything-c-open-dired
5604 emms-source-file-default-directory
))))))
5605 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
5606 ;; (anything 'anything-c-source-emms-dired)
5608 (defface anything-emms-playlist
5609 '((t (:foreground
"Springgreen4" :underline t
)))
5610 "*Face used for tracks in current emms playlist."
5613 (defun anything-c-emms-files-modifier (candidates source
)
5614 (let ((current-playlist (with-current-emms-playlist
5616 with cur-list
= (emms-playlist-tracks-in-region
5617 (point-min) (point-max))
5619 collect
(assoc-default 'name i
)))))
5620 (loop for i in candidates
5621 if
(member (cdr i
) current-playlist
)
5622 collect
(cons (propertize (car i
)
5623 'face
'anything-emms-playlist
)
5625 else collect i into lis
5626 finally return lis
)))
5628 (defun anything-c-emms-play-current-playlist ()
5629 "Play current playlist."
5630 (with-current-emms-playlist
5631 (emms-playlist-first)
5632 (emms-playlist-mode-play-smart)))
5634 (defvar anything-c-source-emms-files
5635 '((name .
"Emms files")
5636 (candidates .
(lambda ()
5637 (loop for v being the hash-values in emms-cache-db
5638 for name
= (assoc-default 'name v
)
5639 for artist
= (or (assoc-default 'info-artist v
) "unknown")
5640 for genre
= (or (assoc-default 'info-genre v
) "unknown")
5641 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
5642 for song
= (or (assoc-default 'info-title v
) "unknown")
5643 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
5644 unless
(string-match "^http:" name
) collect
(cons info name
))))
5645 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
5646 (action .
(("Play file" . emms-play-file
)
5647 ("Add to Playlist and play (C-u clear current)"
5648 .
(lambda (candidate)
5649 (when anything-current-prefix-arg
5650 (emms-playlist-current-clear))
5652 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
5653 (unless emms-player-playing-p
5654 (anything-c-emms-play-current-playlist))))))))
5656 ;; (anything 'anything-c-source-emms-files)
5658 ;;; Jabber Contacts (jabber.el)
5659 (defun anything-c-jabber-online-contacts ()
5660 "List online Jabber contacts."
5663 (dolist (item (jabber-concat-rosters) jids
)
5664 (when (get item
'connected
)
5665 (push (if (get item
'name
)
5666 (cons (get item
'name
) item
)
5667 (cons (symbol-name item
) item
)) jids
))))))
5669 (defvar anything-c-source-jabber-contacts
5670 '((name .
"Jabber Contacts")
5671 (init .
(lambda () (require 'jabber
)))
5672 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
5673 (action .
(lambda (x)
5675 (jabber-read-account)
5677 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
5678 ;; (anything 'anything-c-source-jabber-contacts)
5682 (defvar anything-source-select-buffer
"*anything source select*")
5683 (defvar anything-c-source-call-source
5684 `((name .
"Call anything source")
5685 (candidate-number-limit)
5686 (candidates .
(lambda ()
5687 (loop for vname in
(all-completions "anything-c-source-" obarray
)
5688 for var
= (intern vname
)
5689 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
5690 if name collect
(cons (format "%s `%s'"
5691 name
(propertize vname
'face
'font-lock-variable-name-face
))
5693 (action .
(("Invoke anything with selected source" .
5695 (setq anything-candidate-number-limit
9999)
5696 (anything candidate nil nil nil nil
5697 anything-source-select-buffer
)))
5698 ("Describe variable" . describe-variable
)
5699 ("Find variable" . find-variable
)))
5700 (persistent-action . describe-variable
)
5701 (persistent-help .
"Show description of this source")))
5702 ;; (anything 'anything-c-source-call-source)
5705 (defun anything-call-source ()
5706 "Preconfigured `anything' to call anything source."
5708 (anything 'anything-c-source-call-source nil nil nil nil
5709 anything-source-select-buffer
))
5711 (defun anything-call-source-from-anything ()
5712 "Call anything source within `anything' session."
5714 (setq anything-input-idle-delay
0)
5715 (anything-set-sources '(anything-c-source-call-source)))
5717 ;;; Execute Preconfigured anything.
5718 (defvar anything-c-source-anything-commands
5719 '((name .
"Preconfigured Anything")
5720 (candidates . anything-c-anything-commands-candidates
)
5722 (candidate-number-limit)))
5723 ;; (anything 'anything-c-source-anything-commands)
5725 (defun anything-c-anything-commands-candidates ()
5726 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
5727 collect
(cons (if (where-is-internal cmd nil t
)
5728 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
5729 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
5733 (defun anything-execute-anything-command ()
5734 "Preconfigured `anything' to execute preconfigured `anything'."
5736 (anything-other-buffer 'anything-c-source-anything-commands
5737 "*anything commands*"))
5740 (defun anything-c-occur-init ()
5741 (anything-candidate-buffer anything-current-buffer
))
5743 (defun anything-c-occur-get-line (s e
)
5744 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
5746 (defvar anything-c-source-occur
5748 (init . anything-c-occur-init
)
5749 (candidates-in-buffer)
5751 (get-line . anything-c-occur-get-line
)
5754 (requires-pattern .
1)
5757 ;; (anything 'anything-c-source-occur)
5759 ;;; Anything browse code.
5760 (defun anything-c-browse-code-get-line (beg end
)
5761 "Select line if it match the regexp corresponding to current `major-mode'.
5762 Line is parsed for BEG position to END position."
5763 (let ((str-line (buffer-substring beg end
))
5764 (regexp (assoc-default major-mode
5765 anything-c-browse-code-regexp-alist
))
5766 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
5767 (when (and regexp
(string-match regexp str-line
))
5768 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
5771 (defvar anything-c-source-browse-code
5772 '((name .
"Browse code")
5774 (anything-candidate-buffer anything-current-buffer
)
5775 (with-current-buffer anything-current-buffer
5776 (jit-lock-fontify-now))))
5777 (candidates-in-buffer)
5778 (get-line . anything-c-browse-code-get-line
)
5782 ;; Do many actions for input
5783 (defvar anything-c-source-create
5787 (action-transformer . anything-create--actions
))
5788 "Do many create actions from `anything-pattern'.
5789 See also `anything-create--actions'.")
5790 ;; (anything 'anything-c-source-create)
5792 (defun anything-create-from-anything ()
5793 "Run `anything-create' from `anything' as a fallback."
5795 (anything-run-after-quit 'anything-create nil anything-pattern
))
5798 (defun anything-create (&optional string initial-input
)
5799 "Preconfigured `anything' to do many create actions from STRING.
5800 See also `anything-create--actions'."
5802 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
5803 (anything '(((name .
"Anything Create")
5804 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
5805 (candidates . anything-create--actions
)
5806 (candidate-number-limit)
5807 (action .
(lambda (func) (funcall func string
)))))))
5809 (defun anything-create--actions (&rest ignored
)
5810 "Default actions for `anything-create' / `anything-c-source-create'."
5812 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
5813 (append anything-create--actions-private
5814 '(("find-file" . find-file
)
5815 ("find-file other window" . find-file-other-window
)
5816 ("New buffer" . switch-to-buffer
)
5817 ("New buffer other window" . switch-to-buffer-other-window
)
5818 ("Bookmark Set" . bookmark-set
)
5820 (lambda (x) (set-register (read-char "Register: ") x
)))
5821 ("Insert Linkd star" . linkd-insert-star
)
5822 ("Insert Linkd Tag" . linkd-insert-tag
)
5823 ("Insert Linkd Link" . linkd-insert-link
)
5824 ("Insert Linkd Lisp" . linkd-insert-lisp
)
5825 ("Insert Linkd Wiki" . linkd-insert-wiki
)
5826 ("Google Search" . google
)))))
5828 ;; Minibuffer History
5829 (defvar anything-c-source-minibuffer-history
5830 '((name .
"Minibuffer History")
5831 (header-name .
(lambda (name) (format "%s (%s)" name minibuffer-history-variable
)))
5832 (candidates .
(lambda () (let ((history (symbol-value minibuffer-history-variable
)))
5833 (if (consp (car history
))
5834 (mapcar 'prin1-to-string history
)
5838 ;; (anything 'anything-c-source-minibuffer-history)
5841 (defvar anything-c-source-elscreen
5842 '((name .
"Elscreen")
5843 (candidates .
(lambda ()
5844 (if (cdr (elscreen-get-screen-to-name-alist))
5846 (loop for sname in
(elscreen-get-screen-to-name-alist)
5847 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
5848 finally
(return lst
))
5849 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
5850 (action .
(("Change Screen".
5852 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
5855 (dolist (i (anything-marked-candidates))
5856 (elscreen-goto (- (aref i
1) (aref "0" 0)))
5860 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
5861 (elscreen-kill-others)))))))
5862 ;; (anything 'anything-c-source-elscreen)
5867 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
5868 "Top command (batch mode). %s is replaced with `frame-width'.")
5869 (defvar anything-c-source-top
5870 '((name .
"Top (Press C-c C-u to refresh)")
5871 (init . anything-c-top-init
)
5872 (candidates-in-buffer)
5873 (display-to-real . anything-c-top-display-to-real
)
5874 (update . anything-c-top-update
)
5875 (persistent-action . anything-c-top-sh-persistent-action
)
5876 (persistent-help .
"SIGTERM")
5878 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
5879 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
5880 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
5881 ;; (anything 'anything-c-source-top)
5883 (defun anything-c-top-sh (cmd)
5884 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
5886 (defun anything-c-top-sh-persistent-action (pid)
5887 (delete-other-windows)
5888 (anything-c-top-sh (format "kill -TERM %s" pid
))
5889 (anything-force-update))
5891 (defun anything-c-top-init ()
5892 (with-current-buffer (anything-candidate-buffer 'global
)
5893 (call-process-shell-command
5894 (format anything-c-top-command
5895 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
5896 nil
(current-buffer))))
5898 (defun anything-c-top-display-to-real (line)
5899 (car (split-string line
)))
5901 (defun anything-c-top-update ()
5902 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
5903 (anything-c-top-init)))
5906 (defun anything-top ()
5907 "Preconfigured `anything' for top command."
5909 (let ((anything-samewindow t
)
5910 (anything-enable-shortcuts)
5911 (anything-display-function 'anything-default-display-buffer
)
5912 (anything-candidate-number-limit 9999))
5913 (save-window-excursion
5914 (delete-other-windows)
5915 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
5918 (defvar anything-c-source-absolute-time-timers
5919 '((name .
"Absolute Time Timers")
5920 (candidates . timer-list
)
5922 ;; (anything 'anything-c-source-absolute-time-timers)
5924 (defvar anything-c-source-idle-time-timers
5925 '((name .
"Idle Time Timers")
5926 (candidates . timer-idle-list
)
5928 ;; (anything 'anything-c-source-idle-time-timers)
5930 (defun anything-c-timer-real-to-display (timer)
5931 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
5932 (append timer nil
) ;use `append' to convert vector->list
5933 (format "%s repeat=%5S %s(%s)"
5934 (let ((time (list t1 t2 t3
)))
5936 (format-time-string "idle-for=%5s" time
)
5937 (format-time-string "%m/%d %T" time
)))
5940 (mapconcat 'prin1-to-string args
" "))))
5942 ;;; X RandR resolution change
5943 ;;; FIXME I do not care multi-display.
5944 (defvar anything-c-xrandr-output
"VGA")
5945 (defvar anything-c-xrandr-screen
"0")
5946 (defvar anything-c-source-xrandr-change-resolution
5947 '((name .
"Change Resolution")
5951 (call-process "xrandr" nil
(current-buffer) nil
5952 "--screen" anything-c-xrandr-screen
"-q")
5954 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
5955 collect
(match-string 1)))))
5957 ("Change Resolution" .
(lambda (mode)
5958 (call-process "xrandr" nil nil nil
5959 "--screen" anything-c-xrandr-screen
5960 "--output" anything-c-xrandr-output
5962 ;; (anything 'anything-c-source-xrandr-change-resolution)
5965 (defun anything-c-persistent-xfont-action (elm)
5966 "Show current font temporarily"
5967 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
5970 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
5971 (set-frame-font current-font
))))
5973 (defvar anything-c-xfonts-cache nil
)
5974 (defvar anything-c-source-xfonts
5975 '((name .
"X Fonts")
5977 (unless anything-c-xfonts-cache
5978 (setq anything-c-xfonts-cache
5979 (x-list-fonts "*")))))
5980 (candidates . anything-c-xfonts-cache
)
5981 (action .
(("Copy to kill ring" .
(lambda (elm)
5983 ("Set Font" .
(lambda (elm)
5985 (set-frame-font elm
'keep-size
)
5986 (message "New font have been copied to kill ring")))))
5987 (persistent-action . anything-c-persistent-xfont-action
)
5988 (persistent-help .
"Switch to this font temporarily")))
5991 (defun anything-select-xfont ()
5992 "Preconfigured `anything' to select Xfont."
5994 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
5996 ;; (anything 'anything-c-source-xfonts)
6000 (defvar anything-c-source-time-world
6001 '((name .
"Time World List")
6003 (let ((anything-buffer (anything-candidate-buffer 'global
)))
6004 (with-current-buffer anything-buffer
6005 (display-time-world-display display-time-world-list
)))))
6006 (candidates-in-buffer)))
6009 (defun anything-world-time ()
6010 "Preconfigured `anything' to show world time."
6012 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
6014 ;;; Source for Debian/Ubuntu users
6015 (defvar anything-c-source-apt
6017 (init . anything-c-apt-init
)
6018 (candidates-in-buffer)
6019 (candidate-transformer anything-c-apt-candidate-transformer
)
6020 (display-to-real . anything-c-apt-display-to-real
)
6021 (candidate-number-limit .
9999)
6023 ("Show package description" . anything-c-apt-cache-show
)
6024 ("Install package" . anything-c-apt-install
)
6025 ("Remove package" . anything-c-apt-uninstall
)
6026 ("Purge package" . anything-c-apt-purge
))
6027 (persistent-action . anything-c-apt-persistent-action
)
6028 (persistent-help .
"Show - C-u Refresh")))
6029 ;; (anything 'anything-c-source-apt)
6031 (defvar anything-c-apt-query
"emacs")
6032 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
6033 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
6034 (defvar anything-c-apt-installed-packages nil
)
6036 (defface anything-apt-installed
6037 '((t (:foreground
"green")))
6038 "*Face used for apt installed candidates."
6041 (defun anything-c-apt-refresh ()
6042 "Refresh installed candidates list."
6043 (setq anything-c-apt-installed-packages nil
)
6044 (anything-force-update))
6046 (defun anything-c-apt-persistent-action (candidate)
6047 "Persistent action for APT source."
6048 (if current-prefix-arg
6049 (anything-c-apt-refresh)
6050 (anything-c-apt-cache-show candidate
)))
6053 (defun anything-apt (query)
6054 "Preconfigured `anything' : frontend of APT package manager."
6055 (interactive "sAPT search: ")
6056 (let ((anything-c-apt-query query
))
6057 (anything 'anything-c-source-apt
)))
6059 (defun anything-c-apt-candidate-transformer (candidates)
6060 "Show installed candidates in a different color."
6063 for cand in candidates
6064 for name
= (anything-c-apt-display-to-real cand
)
6065 if
(member name anything-c-apt-installed-packages
)
6066 collect
(propertize cand
'face
'anything-apt-installed
) into all
6067 else collect cand into all finally return all
))
6069 (defun anything-c-apt-init ()
6070 "Initialize list of debian packages."
6071 (unless anything-c-apt-installed-packages
6072 (message "Updating installed candidate list...")
6073 (setq anything-c-apt-installed-packages
6075 (call-process-shell-command "dpkg --get-selections"
6076 nil
(current-buffer))
6077 (loop for i in
(split-string (buffer-string) "\n" t
)
6078 collect
(car (split-string i
))))))
6079 (with-current-buffer
6080 (anything-candidate-buffer
6081 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query
)))
6083 (call-process-shell-command
6084 (format anything-c-apt-search-command anything-c-apt-query
)
6085 nil
(current-buffer)))
6086 (message "Updating installed candidate list...done"))
6088 (defun anything-c-apt-display-to-real (line)
6089 "Return only name of a debian package.
6090 LINE is displayed like:
6091 package name - description."
6092 (car (split-string line
" - ")))
6095 (defun anything-c-shell-command-if-needed (command)
6096 (interactive "sShell command: ")
6097 (if (get-buffer command
) ; if the buffer already exists
6098 (switch-to-buffer command
) ; then just switch to it
6099 (switch-to-buffer command
) ; otherwise create it
6100 (insert (shell-command-to-string command
))))
6102 (defun anything-c-apt-cache-show (package)
6103 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package
)))
6105 (defun anything-c-apt-install (package)
6106 (anything-c-apt-install1 package
:action
'install
))
6108 (defun anything-c-apt-uninstall (package)
6109 (anything-c-apt-install1 package
:action
'uninstall
))
6111 (defun anything-c-apt-purge (package)
6112 (anything-c-apt-install1 package
:action
'purge
))
6114 (defun* anything-c-apt-install1
(candidate &key action
)
6115 (ansi-term (getenv "SHELL") "anything apt")
6117 (let ((command (case action
6118 ('install
"sudo apt-get install '%s'")
6119 ('uninstall
"sudo apt-get remove '%s'")
6120 ('purge
"sudo apt-get purge '%s'")
6121 (t (error "Unknow action"))))
6123 (goto-char (point-max))
6124 (insert (format command candidate
))
6126 (if (y-or-n-p (format "%s package" (symbol-name action
)))
6128 (setq anything-c-external-commands-list nil
)
6129 (setq anything-c-apt-installed-packages nil
)
6130 (term-char-mode) (term-send-input))
6131 (delete-region beg end
) (term-send-eof) (kill-buffer))))
6133 ;; (anything-c-apt-install "jed")
6135 ;;; Sources for gentoo users
6136 (defvar anything-c-gentoo-use-flags nil
)
6137 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
6138 (defvar anything-c-cache-gentoo nil
)
6139 (defvar anything-c-cache-world nil
)
6140 (defvar anything-c-source-gentoo
6141 '((name .
"Portage sources")
6143 (get-buffer-create anything-c-gentoo-buffer
)
6144 (unless anything-c-cache-gentoo
6145 (anything-c-gentoo-setup-cache))
6146 (unless anything-c-cache-world
6147 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
6148 (anything-c-gentoo-init-list)))
6149 (candidates-in-buffer)
6151 (candidate-transformer anything-c-highlight-world
)
6152 (action .
(("Show package" .
(lambda (elm)
6153 (anything-c-gentoo-eshell-action elm
"eix")))
6154 ("Show history" .
(lambda (elm)
6155 (if (member elm anything-c-cache-world
)
6156 (anything-c-gentoo-eshell-action elm
"genlop -qe")
6157 (message "No infos on packages not yet installed"))))
6158 ("Copy in kill-ring" . kill-new
)
6159 ("insert at point" . insert
)
6160 ("Browse HomePage" .
(lambda (elm)
6161 (let ((urls (anything-c-gentoo-get-url elm
)))
6162 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
6163 ("Show extra infos" .
(lambda (elm)
6164 (if (member elm anything-c-cache-world
)
6165 (anything-c-gentoo-eshell-action elm
"genlop -qi")
6166 (message "No infos on packages not yet installed"))))
6167 ("Show use flags" .
(lambda (elm)
6168 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
6169 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
6170 (font-lock-mode 1)))
6171 ("Run emerge pretend" .
(lambda (elm)
6172 (anything-c-gentoo-eshell-action elm
"emerge -p")))
6173 ("Emerge" .
(lambda (elm)
6174 (anything-gentoo-install elm
:action
'install
)))
6175 ("Unmerge" .
(lambda (elm)
6176 (anything-gentoo-install elm
:action
'uninstall
)))
6177 ("Show dependencies" .
(lambda (elm)
6178 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
6179 ("Show related files" .
(lambda (elm)
6180 (anything-c-gentoo-default-action elm
"equery" "files")))
6181 ("Refresh" .
(lambda (elm)
6182 (anything-c-gentoo-setup-cache)
6183 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
6185 ;; (anything 'anything-c-source-gentoo)
6187 (defun* anything-gentoo-install
(candidate &key action
)
6188 (setq anything-c-external-commands-list nil
)
6189 (ansi-term (getenv "SHELL") "Gentoo emerge")
6191 (let ((command (case action
6192 ('install
"sudo emerge -av ")
6193 ('uninstall
"sudo emerge -avC ")
6194 (t (error "Unknow action"))))
6195 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
6197 (goto-char (point-max))
6198 (insert (concat command elms
))
6200 (term-char-mode) (term-send-input)))
6202 (defun anything-c-gentoo-default-action (elm command
&rest args
)
6203 "Gentoo default action that use `anything-c-gentoo-buffer'."
6204 (if (member elm anything-c-cache-world
)
6206 (switch-to-buffer anything-c-gentoo-buffer
)
6208 (let ((com-list (append args
(list elm
))))
6209 (apply #'call-process command nil t nil
6211 (message "No infos on packages not yet installed")))
6213 (defvar anything-c-source-use-flags
6214 '((name .
"Use Flags")
6216 (unless anything-c-gentoo-use-flags
6217 (anything-c-gentoo-setup-use-flags-cache))
6218 (anything-c-gentoo-get-use)))
6219 (candidates-in-buffer)
6221 (candidate-transformer anything-c-highlight-local-use
)
6222 (action .
(("Description"
6224 (switch-to-buffer anything-c-gentoo-buffer
)
6226 (apply #'call-process
"euse" nil t nil
6229 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
6230 (font-lock-mode 1)))
6233 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
6236 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
6239 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
6240 ("Show which dep use this flag"
6242 (switch-to-buffer anything-c-gentoo-buffer
)
6244 (apply #'call-process
"equery" nil t nil
6250 ;; (anything 'anything-c-source-use-flags)
6252 (defun anything-c-gentoo-init-list ()
6253 "Initialize buffer with all packages in Portage."
6254 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
6255 (buf (anything-candidate-buffer 'portage-buf
)))
6256 (with-current-buffer buf
6257 (dolist (i anything-c-cache-gentoo
)
6258 (insert (concat i
"\n"))))))
6260 (defun anything-c-gentoo-setup-cache ()
6261 "Set up `anything-c-cache-gentoo'"
6262 (setq anything-c-cache-gentoo
6263 (split-string (with-temp-buffer
6264 (call-process "eix" nil t nil
6268 (defun anything-c-gentoo-eshell-action (elm command
)
6269 (when (get-buffer "*EShell Command Output*")
6270 (kill-buffer "*EShell Command Output*"))
6271 (message "Wait searching...")
6272 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
6273 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
6275 (save-window-excursion
6276 (pop-to-buffer "*scratch*")
6277 (eshell-command (format "%s %s" command elm
)))
6278 (pop-to-buffer "*EShell Command Output*"))
6279 (eshell-command (format "%s %s" command elm
)))))
6281 (defun anything-c-gentoo-get-use ()
6282 "Initialize buffer with all use flags."
6283 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
6284 (buf (anything-candidate-buffer 'use-buf
)))
6285 (with-current-buffer buf
6286 (dolist (i anything-c-gentoo-use-flags
)
6287 (insert (concat i
"\n"))))))
6290 (defun anything-c-gentoo-setup-use-flags-cache ()
6291 "Setup `anything-c-gentoo-use-flags'"
6292 (setq anything-c-gentoo-use-flags
6293 (split-string (with-temp-buffer
6294 (call-process "eix" nil t nil
6295 "--print-all-useflags")
6298 (defun anything-c-gentoo-get-url (elm)
6299 "Return a list of urls from eix output."
6301 with url-list
= (split-string
6303 (call-process "eix" nil t nil
6304 elm
"--format" "<homepage>\n")
6308 when
(and (string-match "^http://.*" i
)
6309 (not (member i all
)))
6311 finally return all
))
6313 (defun anything-c-gentoo-get-world ()
6314 "Return list of all installed package on your system."
6315 (split-string (with-temp-buffer
6316 (call-process "qlist" nil t nil
6320 (defun anything-c-gentoo-get-local-use ()
6321 (split-string (with-temp-buffer
6322 (call-process "portageq" nil t nil
6327 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
6328 "Face for anything-gentoo installed packages."
6329 :group
'traverse-faces
)
6331 (defun anything-c-highlight-world (eix)
6332 "Highlight all installed package."
6334 if
(member i anything-c-cache-world
)
6335 collect
(propertize i
'face
'anything-gentoo-match-face
)
6339 (defun anything-c-highlight-local-use (use-flags)
6340 (let ((local-uses (anything-c-gentoo-get-local-use)))
6341 (loop for i in use-flags
6342 if
(member i local-uses
)
6343 collect
(propertize i
'face
'anything-gentoo-match-face
)
6347 (defvar anything-c-source-emacs-process
6348 '((name .
"Emacs Process")
6349 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
6350 (persistent-action .
(lambda (elm)
6351 (delete-process (get-process elm
))
6352 (anything-delete-current-selection)))
6353 (persistent-help .
"Kill Process")
6354 (action ("Kill Process" .
(lambda (elm)
6355 (delete-process (get-process elm
)))))))
6357 ;; (anything 'anything-c-source-emacs-process)
6359 ;; Run Externals commands within Emacs
6360 (defmacro* anything-comp-hash-get-items
(hash-table &key test
)
6361 "Get the list of all keys/values of hash-table."
6362 `(let ((li-items ()))
6363 (maphash #'(lambda (x y
)
6365 (when (funcall ,test y
)
6366 (push (list x y
) li-items
))
6367 (push (list x y
) li-items
)))
6371 (defun anything-comp-read-get-candidates (collection &optional test sort-fn
)
6372 "Convert COLLECTION to list removing elements that don't match TEST.
6373 SORT-FN is a predicate to sort COLLECTION.
6374 If collection is an `obarray', a TEST is needed. See `obarray'."
6376 (cond ((and (listp collection
) test
)
6377 (loop for i in collection when
(funcall test i
) collect i
))
6378 ((and (eq collection obarray
) test
)
6379 (loop for s being the symbols of collection
6380 when
(funcall test s
) collect s
))
6381 ((and (vectorp collection
) test
)
6382 (loop for i across collection when
(funcall test i
) collect i
))
6383 ((vectorp collection
)
6384 (loop for i across collection collect i
))
6385 ((and (hash-table-p collection
) test
)
6386 (anything-comp-hash-get-items collection
:test test
))
6387 ((hash-table-p collection
)
6388 (anything-comp-hash-get-items collection
))
6390 (if sort-fn
(sort cands sort-fn
) cands
)))
6392 (defun anything-cr-default-transformer (candidates source
)
6393 "Default filter candidate function for `anything-comp-read'.
6394 Do nothing, just return candidate list unmodified."
6397 (defun* anything-comp-read
(prompt collection
6401 (buffer "*Anything Completions*")
6403 (requires-pattern 0)
6405 (persistent-action nil
)
6406 (persistent-help "DoNothing")
6407 (name "Anything Completions")
6409 (fc-transformer 'anything-cr-default-transformer
)
6410 (marked-candidates nil
))
6411 "Anything `completing-read' emulation.
6412 PROMPT is the prompt name to use.
6413 COLLECTION can be a list, vector, obarray or hash-table.
6416 TEST: A predicate called with one arg i.e candidate.
6417 INITIAL-INPUT: Same as initial-input arg in `anything'.
6418 BUFFER: Name of anything-buffer.
6419 MUST-MATCH: Candidate selected must be one of COLLECTION.
6420 REQUIRES-PATTERN: Same as anything attribute, default is 0.
6421 HISTORY: A list containing specific history, default is nil.
6422 When it is non--nil, all elements of HISTORY are displayed in
6423 anything-buffer before COLLECTION.
6424 PERSISTENT-ACTION: A function called with one arg i.e candidate.
6425 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
6426 NAME: The name related to this local source.
6427 SORT: A predicate to give to `sort' e.g `string-lessp'.
6428 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
6429 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
6431 Any prefix args passed during `anything-comp-read' invocation will be recorded
6432 in `anything-current-prefix-arg', otherwise if prefix args where given before
6433 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
6434 That's mean you can pass prefix arg before or after calling
6435 a command that use `anything-comp-read'."
6436 (when (get-buffer anything-action-buffer
)
6437 (kill-buffer anything-action-buffer
))
6438 (flet ((action-fn (candidate)
6439 (if marked-candidates
6440 (anything-marked-candidates)
6441 (identity candidate
))))
6444 `(((name .
,(format "%s History" name
))
6445 (candidates .
(lambda ()
6446 (anything-comp-read-get-candidates history
)))
6448 (persistent-action .
,persistent-action
)
6449 (persistent-help .
,persistent-help
)
6450 (action .
,'action-fn
))
6454 (let ((cands (anything-comp-read-get-candidates
6455 collection test sort
)))
6456 (if (or must-match
(string= anything-pattern
""))
6457 cands
(append (list anything-pattern
) cands
)))))
6458 (filtered-candidate-transformer ,fc-transformer
)
6459 (requires-pattern .
,requires-pattern
)
6460 (persistent-action .
,persistent-action
)
6461 (persistent-help .
,persistent-help
)
6463 (action .
,'action-fn
)))
6464 :input initial-input
6470 (defun anything-c-get-pid-from-process-name (process-name)
6471 "Get pid from running process PROCESS-NAME."
6472 (loop with process-list
= (list-system-processes)
6473 for pid in process-list
6474 for process
= (assoc-default 'comm
(process-attributes pid
))
6475 when
(and process
(string-match process-name process
))
6479 (defun anything-run-or-raise (exe &optional file
)
6480 "Generic command that run asynchronously EXE.
6481 If EXE is already running just jump to his window if `anything-raise-command'
6483 When FILE argument is provided run EXE with FILE.
6484 In this case EXE must be provided as \"EXE %s\"."
6485 (let ((real-com (car (split-string (replace-regexp-in-string "'%s'" "" exe
)))))
6486 (if (or (get-process real-com
)
6487 (anything-c-get-pid-from-process-name real-com
))
6488 (if anything-raise-command
6489 (shell-command (format anything-raise-command real-com
))
6490 (error "Error: %s is already running" real-com
))
6491 (when (member real-com anything-c-external-commands-list
)
6492 (message "Starting %s..." real-com
)
6494 (start-process-shell-command real-com nil
(format exe file
))
6495 (start-process-shell-command real-com nil real-com
))
6496 (set-process-sentinel
6497 (get-process real-com
)
6498 #'(lambda (process event
)
6499 (when (and (string= event
"finished\n")
6500 anything-raise-command
)
6501 (shell-command (format anything-raise-command
"emacs")))
6502 (message "%s process...Finished." process
))))
6503 (setq anything-c-external-commands-list
6504 (cons real-com
(delete real-com anything-c-external-commands-list
))))))
6507 (defvar anything-external-command-history nil
)
6509 (defun anything-c-run-external-command (program)
6510 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
6511 If program is already running exit with error.
6512 You can set your own list of commands with
6513 `anything-c-external-commands-list'."
6517 (anything-c-external-commands-list-1 'sort
)
6519 :name
"External Commands"
6520 :history anything-external-command-history
)))
6521 (anything-run-or-raise program
)
6522 (setq anything-external-command-history
6523 (cons program
(delete program
6524 (loop for i in anything-external-command-history
6525 when
(executable-find i
) collect i
)))))
6527 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
6528 "A simple and faster replacement of CL `position'."
6529 (loop for i in seq for index from
0
6530 when
(funcall test i item
) return index
))
6532 (defvar anything-c-source-ratpoison-commands
6533 '((name .
"Ratpoison Commands")
6534 (init . anything-c-ratpoison-commands-init
)
6535 (candidates-in-buffer)
6536 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
6537 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
6538 (candidate-number-limit)))
6539 ;; (anything 'anything-c-source-ratpoison-commands)
6541 (defun anything-c-ratpoison-commands-init ()
6542 (unless (anything-candidate-buffer)
6543 (with-current-buffer (anything-candidate-buffer 'global
)
6544 ;; with ratpoison prefix key
6546 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
6547 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
6548 (replace-match "<ratpoison> \\1: \\2"))
6549 (goto-char (point-max))
6552 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
6553 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
6554 (replace-match "\\1: \\2")))))
6556 (defun anything-c-ratpoison-commands-display-to-real (display)
6557 (and (string-match ": " display
)
6558 (substring display
(match-end 0))))
6560 (defun anything-c-ratpoison-commands-execute (candidate)
6561 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
6564 (defun anything-ratpoison-commands ()
6565 "Preconfigured `anything' to execute ratpoison commands."
6567 (anything-other-buffer 'anything-c-source-ratpoison-commands
6568 "*anything ratpoison commands*"))
6570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6572 (defvar anything-c-external-commands-list nil
6573 "A list of all external commands the user can execute. If this
6574 variable is not set by the user, it will be calculated
6577 (defun anything-c-external-commands-list-1 (&optional sort
)
6578 "Returns a list of all external commands the user can execute.
6579 If `anything-c-external-commands-list' is non-nil it will
6580 return its contents. Else it calculates all external commands
6581 and sets `anything-c-external-commands-list'."
6582 (if anything-c-external-commands-list
6583 anything-c-external-commands-list
6584 (setq anything-c-external-commands-list
6586 with paths
= (split-string (getenv "PATH") path-separator
)
6587 with completions
= ()
6589 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
6590 for lsdir
= (loop for i in
(directory-files dir t
)
6591 for bn
= (file-name-nondirectory i
)
6592 when
(and (not (member bn completions
))
6593 (not (file-directory-p i
))
6594 (file-executable-p i
))
6596 append lsdir into completions
6597 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
6600 (defun anything-c-file-buffers (filename)
6601 "Returns a list of buffer names corresponding to FILENAME."
6602 (let ((name (expand-file-name filename
))
6604 (dolist (buf (buffer-list) buf-list
)
6605 (let ((bfn (buffer-file-name buf
)))
6606 (when (and bfn
(string= name bfn
))
6607 (push (buffer-name buf
) buf-list
))))))
6609 (defun anything-c-delete-file (file)
6610 "Delete the given file after querying the user.
6611 Ask to kill buffers associated with that file, too."
6612 (let ((buffers (anything-c-file-buffers file
)))
6613 (dired-delete-file file
'dired-recursive-deletes
)
6615 (dolist (buf buffers
)
6616 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
6617 (kill-buffer buf
))))))
6619 (defun anything-get-mailcap-for-file (filename)
6620 "Get the command to use for FILENAME from mailcap files.
6621 The command is like <command %s> and is meant to use with `format'."
6622 (mailcap-parse-mailcaps)
6623 (let* ((ext (file-name-extension filename
))
6624 (mime (when ext
(mailcap-extension-to-mime ext
))))
6625 (when mime
(mailcap-mime-info mime
))))
6627 (defun anything-get-default-program-for-file (filename)
6628 "Try to find a default program to open FILENAME.
6629 Try first in `anything-c-external-programs-associations' and then in mailcap file
6630 if nothing found return nil."
6631 (let* ((ext (file-name-extension filename
))
6632 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
6633 (if (and def-prog
(not (string= def-prog
"")))
6634 (concat def-prog
" %s")
6635 (anything-get-mailcap-for-file filename
))))
6637 (defun anything-c-open-file-externally (file)
6638 "Open FILE with an external program.
6639 Try to guess which program to use with `anything-get-default-program-for-file'.
6640 If not found or a prefix arg is given query the user which tool to use."
6641 (let* ((fname (expand-file-name file
))
6642 (collection (anything-c-external-commands-list-1 'sort
))
6643 (def-prog (anything-get-default-program-for-file fname
))
6645 ;; No prefix arg, default program exists.
6646 (unless (or anything-current-prefix-arg
(not def-prog
))
6647 (replace-regexp-in-string " %s" "" def-prog
))
6648 ;; Prefix arg or no default program.
6650 "Program: " collection
6652 :name
"Open file Externally"
6653 :history anything-external-command-history
)))
6654 (program (concat real-prog-name
" '%s'")))
6655 (unless (or def-prog
; Association exists, no need to record it.
6656 (not (file-exists-p fname
))) ; Don't record non--filenames.
6660 "Do you want to make %s the default program for this kind of files? "
6662 (push (cons (file-name-extension fname
)
6664 "Program(Add args maybe and confirm): " real-prog-name
))
6665 anything-c-external-programs-associations
)
6666 (customize-save-variable 'anything-c-external-programs-associations
6667 anything-c-external-programs-associations
)))
6668 (anything-run-or-raise program file
)
6669 (setq anything-external-command-history
6670 (cons real-prog-name
6671 (delete real-prog-name
6672 (loop for i in anything-external-command-history
6673 when
(executable-find i
) collect i
))))))
6677 (defun w32-shell-execute-open-file (file)
6678 (interactive "fOpen file:")
6680 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
6682 (replace-regexp-in-string ; strip cygdrive paths
6683 "/cygdrive/\\(.\\)" "\\1:"
6684 file nil nil
) nil t
))))
6686 (defun anything-c-open-file-with-default-tool (file)
6687 "Open FILE with the default tool on this platform."
6688 (if (eq system-type
'windows-nt
)
6689 (w32-shell-execute-open-file file
)
6690 (start-process "anything-c-open-file-with-default-tool"
6692 (cond ((eq system-type
'gnu
/linux
)
6694 ((or (eq system-type
'darwin
) ;; Mac OS X
6695 (eq system-type
'macos
)) ;; Mac OS 9
6699 (defun anything-c-open-dired (file)
6700 "Opens a dired buffer in FILE's directory. If FILE is a
6701 directory, open this directory."
6702 (if (file-directory-p file
)
6704 (dired (file-name-directory file
))
6705 (dired-goto-file file
)))
6707 (defun anything-c-display-to-real-line (candidate)
6708 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
6709 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
6710 (error "Line number not found")))
6712 (defun anything-c-action-line-goto (lineno-and-content)
6713 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
6714 (append lineno-and-content
6715 (list (if (and (anything-attr-defined 'target-file
)
6716 (not anything-in-persistent-action
))
6717 'find-file-other-window
6720 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
6721 (apply #'anything-goto-file-line
6722 (if (stringp file-line-content
)
6723 ;; Case: filtered-candidate-transformer is skipped
6724 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
6725 file-line-content
)))
6728 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
6729 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
6731 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
6732 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
6733 (let ((filename (match-string 1 candidate
))
6734 (lineno (match-string 2 candidate
))
6735 (content (match-string 3 candidate
)))
6736 (cons (format "%s:%s\n %s"
6737 (propertize filename
'face compilation-info-face
)
6738 (propertize lineno
'face compilation-line-face
)
6740 (list (expand-file-name
6742 (or (anything-interpret-value (anything-attr 'default-directory
))
6743 (and (anything-candidate-buffer)
6745 'default-directory
(anything-candidate-buffer)))))
6746 (string-to-number lineno
) content
)))))
6748 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
6749 (anything-aif (anything-attr 'before-jump-hook
)
6751 (when file
(funcall find-file-function file
))
6752 (if (anything-attr-defined 'adjust
)
6753 (anything-c-goto-line-with-adjustment lineno content
)
6754 (anything-goto-line lineno
))
6755 (unless (anything-attr-defined 'recenter
)
6756 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
6757 (anything-aif (anything-attr 'after-jump-hook
)
6759 (when anything-in-persistent-action
6760 (anything-match-line-color-current-line)))
6762 (defun anything-find-file-as-root (candidate)
6763 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
6765 (defun anything-find-many-files (ignore)
6766 (mapc 'find-file
(anything-marked-candidates)))
6768 ;; borrowed from etags.el
6769 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
6770 (defun anything-c-goto-line-with-adjustment (line line-content
)
6773 ;; This constant is 1/2 the initial search window.
6774 ;; There is no sense in making it too small,
6775 ;; since just going around the loop once probably
6776 ;; costs about as much as searching 2000 chars.
6779 pat
(concat (if (eq selective-display t
)
6780 "\\(^\\|\^m\\) *" "^ *") ;allow indent
6781 (regexp-quote line-content
)))
6782 ;; If no char pos was given, try the given line number.
6783 (setq startpos
(progn (anything-goto-line line
) (point)))
6784 (or startpos
(setq startpos
(point-min)))
6785 ;; First see if the tag is right at the specified location.
6786 (goto-char startpos
)
6787 (setq found
(looking-at pat
))
6788 (while (and (not found
)
6790 (goto-char (- startpos offset
))
6793 (re-search-forward pat
(+ startpos offset
) t
)
6794 offset
(* 3 offset
))) ; expand search window
6796 (re-search-forward pat nil t
)
6797 (error "not found")))
6798 ;; Position point at the right place
6799 ;; if the search string matched an extra Ctrl-m at the beginning.
6800 (and (eq selective-display t
)
6803 (beginning-of-line))
6805 (anything-document-attribute 'default-directory
"type . file-line"
6806 "`default-directory' to interpret file.")
6807 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
6808 "Function to call before jumping to the target location.")
6809 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
6810 "Function to call after jumping to the target location.")
6811 (anything-document-attribute 'adjust
"type . file-line"
6812 "Search around line matching line contents.")
6813 (anything-document-attribute 'recenter
"type . file-line / line"
6814 "`recenter' after jumping.")
6815 (anything-document-attribute 'target-file
"type . line"
6816 "Goto line of target-file.")
6819 (defun anything-c-call-interactively (cmd-or-name)
6820 "Execute CMD-OR-NAME as Emacs command.
6821 It is added to `extended-command-history'.
6822 `anything-current-prefix-arg' is used as the command's prefix argument."
6823 (setq extended-command-history
6824 (cons (anything-c-stringify cmd-or-name
)
6825 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
6826 (let ((current-prefix-arg anything-current-prefix-arg
)
6827 (cmd (anything-c-symbolify cmd-or-name
)))
6828 (if (stringp (symbol-function cmd
))
6829 (execute-kbd-macro (symbol-function cmd
))
6830 (setq this-command cmd
)
6831 (call-interactively cmd
))))
6834 (defun anything-c-set-variable (var)
6835 "Set value to VAR interactively."
6837 (let ((sym (anything-c-symbolify var
)))
6838 (set sym
(eval-minibuffer (format "Set %s: " var
)
6839 (prin1-to-string (symbol-value sym
))))))
6841 ;; (anything-c-set-variable 'hh)
6843 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6844 (defvar anything-match-line-overlay-face nil
)
6845 (defvar anything-match-line-overlay nil
)
6847 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
6848 "Highlight and underline current position"
6849 (let ((args (list (or start
(line-beginning-position))
6850 (or end
(1+ (line-end-position)))
6852 (if (not anything-match-line-overlay
)
6853 (setq anything-match-line-overlay
(apply 'make-overlay args
))
6854 (apply 'move-overlay anything-match-line-overlay args
)))
6855 (overlay-put anything-match-line-overlay
6856 'face
(or face anything-match-line-overlay-face
))
6861 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
6863 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
6864 "Face for source header in the anything buffer." :group
'anything
)
6866 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
6868 (defun anything-match-line-cleanup ()
6869 (when anything-match-line-overlay
6870 (delete-overlay anything-match-line-overlay
)
6871 (setq anything-match-line-overlay nil
)))
6873 (defun anything-match-line-update ()
6874 (when anything-match-line-overlay
6875 (delete-overlay anything-match-line-overlay
)
6876 (anything-match-line-color-current-line)))
6878 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
6879 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
6881 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6883 (defun anything-c-transform-file-load-el (actions candidate
)
6884 "Add action to load the file CANDIDATE if it is an emacs lisp
6885 file. Else return ACTIONS unmodified."
6886 (if (member (file-name-extension candidate
) '("el" "elc"))
6887 (append actions
'(("Load Emacs Lisp File" . load-file
)))
6890 (defun anything-c-transform-file-browse-url (actions candidate
)
6891 "Add an action to browse the file CANDIDATE if it in a html
6892 file or URL. Else return ACTIONS unmodified."
6893 (let ((browse-action '("Browse with Browser" . browse-url
)))
6894 (cond ((string-match "^http\\|^ftp" candidate
)
6895 (cons browse-action actions
))
6896 ((string-match "\\.html?$" candidate
)
6897 (append actions
(list browse-action
)))
6901 (defun anything-c-transform-function-call-interactively (actions candidate
)
6902 "Add an action to call the function CANDIDATE interactively if
6903 it is a command. Else return ACTIONS unmodified."
6904 (if (commandp (intern-soft candidate
))
6905 (append actions
'(("Call Interactively"
6907 anything-c-call-interactively
)))
6911 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
6912 "If CANDIDATE's `car' is a command, then add an action to
6913 evaluate it and put it onto the `command-history'."
6914 (if (commandp (car (read candidate
)))
6915 ;; Make it first entry
6916 (cons '("Eval and put onto command-history" .
6918 (let ((sym (read sexp
)))
6920 (setq command-history
6921 (cons sym command-history
)))))
6925 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6927 (defun anything-c-skip-boring-buffers (buffers)
6928 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
6930 (defun anything-c-skip-current-buffer (buffers)
6931 (if anything-allow-skipping-current-buffer
6932 (remove (buffer-name anything-current-buffer
) buffers
)
6935 (defun anything-c-shadow-boring-buffers (buffers)
6936 "Buffers matching `anything-c-boring-buffer-regexp' will be
6937 displayed with the `file-name-shadow' face if available."
6938 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
6941 (defun anything-c-shadow-boring-files (files)
6942 "Files matching `anything-c-boring-file-regexp' will be
6943 displayed with the `file-name-shadow' face if available."
6944 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
6946 (defun anything-c-skip-boring-files (files)
6947 "Files matching `anything-c-boring-file-regexp' will be skipped."
6948 (anything-c-skip-entries files anything-c-boring-file-regexp
))
6949 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6951 (defun anything-c-skip-current-file (files)
6952 "Current file will be skipped."
6953 (remove (buffer-file-name anything-current-buffer
) files
))
6955 (defun anything-c-w32-pathname-transformer (args)
6956 "Change undesirable features of windows pathnames to ones more acceptable to
6957 other candidate transformers."
6958 (if (eq system-type
'windows-nt
)
6960 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
6962 (replace-regexp-in-string "\\\\" "/" y
)) args
))
6965 (defun anything-c-shorten-home-path (files)
6966 "Replaces /home/user with ~."
6967 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
6969 (mapcar (lambda (file)
6970 (if (and (stringp file
) (string-match home file
))
6971 (cons (replace-match "~" nil nil file
) file
)
6976 (defun anything-c-mark-interactive-functions (functions)
6977 "Mark interactive functions (commands) with (i) after the function name."
6979 (loop for function in functions
6980 do
(push (cons (concat function
6981 (when (commandp (intern-soft function
)) " (i)"))
6984 finally
(return (nreverse list
)))))
6986 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6987 (defvar anything-c-adaptive-done nil
6988 "nil if history information is not yet stored for the current
6991 (defvar anything-c-adaptive-history nil
6992 "Contains the stored history information.
6993 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
6995 (defadvice anything-initialize
(before anything-c-adaptive-initialize activate
)
6996 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
6997 when anything is started."
6998 (setq anything-c-adaptive-done nil
))
7000 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
7001 "Advise `anything-exit-minibuffer' to store history information
7002 when a candidate is selected with RET."
7003 (anything-c-adaptive-store-selection))
7005 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
7006 "Advise `anything-select-action' to store history information
7007 when the user goes to the action list with TAB."
7008 (anything-c-adaptive-store-selection))
7010 (defun anything-c-source-use-adaptative-p (&optional source-name
)
7011 "Return current source only if it use adaptative history, nil otherwise."
7012 (let* ((source (or source-name
(anything-get-current-source)))
7013 (adapt-source (or (assoc-default 'filtered-candidate-transformer
7014 (assoc (assoc-default 'type source
)
7015 anything-type-attributes
))
7016 (assoc-default 'candidate-transformer
7017 (assoc (assoc-default 'type source
)
7018 anything-type-attributes
))
7019 (assoc-default 'filtered-candidate-transformer source
)
7020 (assoc-default 'candidate-transformer source
))))
7021 (if (listp adapt-source
)
7022 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
7023 (when (eq adapt-source
'anything-c-adaptive-sort
) source
))))
7025 (defun anything-c-adaptive-store-selection ()
7026 "Store history information for the selected candidate."
7027 (unless anything-c-adaptive-done
7028 (setq anything-c-adaptive-done t
)
7029 (let ((source (anything-c-source-use-adaptative-p)))
7031 (let* ((source-name (or (assoc-default 'type source
)
7032 (assoc-default 'name source
)))
7033 (source-info (or (assoc source-name anything-c-adaptive-history
)
7035 (push (list source-name
) anything-c-adaptive-history
)
7036 (car anything-c-adaptive-history
))))
7037 (selection (anything-get-selection))
7038 (selection-info (progn
7041 (let ((found (assoc selection
(cdr source-info
))))
7046 ;; move entry to the beginning of the
7047 ;; list, so that it doesn't get
7048 ;; trimmed when the history is
7051 (delete found
(cdr source-info
)))
7054 (cadr source-info
)))
7055 (pattern-info (progn
7056 (setcdr selection-info
7058 (let ((found (assoc anything-pattern
(cdr selection-info
))))
7061 (cons anything-pattern
0)
7063 ;; move entry to the beginning of the
7064 ;; list, so if two patterns used the
7065 ;; same number of times then the one
7066 ;; used last appears first in the list
7067 (setcdr selection-info
7068 (delete found
(cdr selection-info
)))
7070 (cdr selection-info
)))
7071 (cadr selection-info
))))
7073 ;; increase usage count
7074 (setcdr pattern-info
(1+ (cdr pattern-info
)))
7076 ;; truncate history if needed
7077 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
7078 (setcdr selection-info
7079 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
7081 (if (file-readable-p anything-c-adaptive-history-file
)
7082 (load-file anything-c-adaptive-history-file
))
7083 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
7085 (defun anything-c-adaptive-save-history ()
7086 "Save history information to file given by `anything-c-adaptive-history-file'."
7090 ";; -*- mode: emacs-lisp -*-\n"
7091 ";; History entries used for anything adaptive display.\n")
7092 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
7095 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
7096 (unless (interactive-p) 'quiet
))))
7098 (defun anything-c-adaptive-sort (candidates source
)
7099 "Sort the CANDIDATES for SOURCE by usage frequency.
7100 This is a filtered candidate transformer you can use for the
7101 attribute `filtered-candidate-transformer' of a source in
7102 `anything-sources' or a type in `anything-type-attributes'."
7103 (let* ((source-name (or (assoc-default 'type source
)
7104 (assoc-default 'name source
)))
7105 (source-info (assoc source-name anything-c-adaptive-history
)))
7106 (if (not source-info
)
7107 ;; if there is no information stored for this source then do nothing
7111 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
7113 (mapcar (lambda (candidate-info)
7115 (dolist (pattern-info (cdr candidate-info
))
7116 (if (not (equal (car pattern-info
)
7118 (incf count
(cdr pattern-info
))
7120 ;; if current pattern is equal to the previously
7121 ;; used one then this candidate has priority
7122 ;; (that's why its count is boosted by 10000) and
7123 ;; it only has to compete with other candidates
7124 ;; which were also selected with the same pattern
7125 (setq count
(+ 10000 (cdr pattern-info
)))
7127 (cons (car candidate-info
) count
)))
7131 ;; sort the list in descending order, so candidates with highest
7132 ;; priorty come first
7133 (setq usage
(sort usage
(lambda (first second
)
7134 (> (cdr first
) (cdr second
)))))
7136 ;; put those candidates first which have the highest usage count
7137 (dolist (info usage
)
7138 (when (member* (car info
) candidates
7139 :test
'anything-c-adaptive-compare
)
7140 (push (car info
) sorted
)
7141 (setq candidates
(remove* (car info
) candidates
7142 :test
'anything-c-adaptive-compare
))))
7144 ;; and append the rest
7145 (append (reverse sorted
) candidates nil
)))))
7147 (defun anything-c-adaptive-compare (x y
)
7148 "Compare candidates X and Y taking into account that the
7149 candidate can be in (DISPLAY . REAL) format."
7150 (equal (if (listp x
)
7157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7158 (defvar anything-outline-goto-near-line-flag t
)
7159 (defvar anything-outline-using nil
)
7160 (defun anything-after-update-hook--outline ()
7161 (if (and (eq anything-outline-using t
)
7162 (eq anything-outline-goto-near-line-flag t
))
7163 (anything-outline-goto-near-line)))
7164 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
7166 (defun anything-outline-goto-near-line ()
7167 (with-anything-window
7168 ;; TODO need consideration whether to update position by every input.
7169 (when t
; (equal anything-pattern "")
7170 (anything-goto-line 2)
7171 (let ((lineno (with-current-buffer anything-current-buffer
7172 (line-number-at-pos (car anything-current-position
)))))
7174 (while (<= (progn (skip-chars-forward " ")
7175 (or (number-at-point) lineno
))
7180 (return-from exit
))))
7182 (and (bobp) (forward-line 1))
7183 (and (anything-pos-header-line-p) (forward-line -
2))
7184 (anything-mark-current-line)))))
7186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7187 ;; Plug-in: info-index
7188 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
7190 (unless (anything-candidate-buffer)
7191 (save-window-excursion
7194 (tobuf (anything-candidate-buffer 'global
))
7195 (infobuf (current-buffer))
7197 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
7198 (Info-goto-node node
)
7199 (goto-char (point-min))
7200 (while (search-forward "\n* " nil t
)
7201 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
7202 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
7203 (setq s
(point-at-bol)
7205 (with-current-buffer tobuf
7206 (insert-buffer-substring infobuf s e
)
7207 (insert "\n"))))))))))
7209 (defun anything-c-info-goto (node-line)
7210 (Info-goto-node (car node-line
))
7211 (anything-goto-line (cdr node-line
)))
7213 (defun anything-c-info-display-to-real (line)
7215 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
7216 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
7217 (string-to-number (or (match-string 3 line
) "1")))))
7219 (defun anything-c-make-info-source (file)
7220 `((name .
,(concat "Info Index: " file
))
7222 (init . anything-c-info-init
)
7223 (display-to-real . anything-c-info-display-to-real
)
7224 (get-line . buffer-substring
)
7225 (candidates-in-buffer)
7226 (action ("Goto node" . anything-c-info-goto
))))
7228 (defun anything-compile-source--info-index (source)
7229 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
7230 (anything-c-make-info-source it
)
7232 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
7234 (anything-document-attribute 'info-index
"info-index plugin"
7235 "Create a source of info index very easily.
7237 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
7239 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
7240 "Index nodes of info file.
7242 If it is omitted, `Info-index-nodes' is used to collect index nodes.
7243 Some info files are missing index specification.
7245 ex. See `anything-c-source-info-screen'.")
7247 ;; Plug-in: candidates-file
7248 (defun anything-compile-source--candidates-file (source)
7249 (if (assoc-default 'candidates-file source
)
7250 `((init anything-p-candidats-file-init
7251 ,@(let ((orig-init (assoc-default 'init source
)))
7252 (cond ((null orig-init
) nil
)
7253 ((functionp orig-init
) (list orig-init
))
7255 (candidates-in-buffer)
7258 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
7260 (defun anything-p-candidats-file-init ()
7261 (destructuring-bind (file &optional updating
)
7262 (anything-mklist (anything-attr 'candidates-file
))
7263 (setq file
(anything-interpret-value file
))
7264 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
7266 (buffer-disable-undo)
7268 (auto-revert-mode 1)))))
7270 (anything-document-attribute 'candidates-file
"candidates-file plugin"
7271 "Use a file as the candidates buffer.
7273 1st argument is a filename, string or function name or variable name.
7274 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
7276 ;; Plug-in: headline
7277 (defun anything-compile-source--anything-headline (source)
7278 (if (assoc-default 'headline source
)
7279 (append '((init . anything-headline-init
)
7280 (get-line . buffer-substring
)
7283 '((candidates-in-buffer)
7284 (persistent-help .
"Show this line")))
7286 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
7288 (defun anything-headline-init ()
7289 (when (and (anything-current-buffer-is-modified)
7290 (with-current-buffer anything-current-buffer
7291 (eval (or (anything-attr 'condition
) t
))))
7292 (anything-headline-make-candidate-buffer
7293 (anything-interpret-value (anything-attr 'headline
))
7294 (anything-interpret-value (anything-attr 'subexp
)))))
7296 (anything-document-attribute 'headline
"Headline plug-in"
7297 "Regexp string for anything-headline to scan.")
7298 (anything-document-attribute 'condition
"Headline plug-in"
7299 "A sexp representing the condition to use anything-headline.")
7300 (anything-document-attribute 'subexp
"Headline plug-in"
7301 "Display (match-string-no-properties subexp).")
7304 (defun anything-headline-get-candidates (regexp subexp
)
7305 (with-current-buffer anything-current-buffer
7307 (goto-char (point-min))
7308 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
7309 (let (hierarchy curhead
)
7311 (if (numberp subexp
)
7312 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
7313 (cons (buffer-substring (point-at-bol) (point-at-eol))
7315 (hierarchies (headlines)
7316 (1+ (loop for
(_ . hierarchy
) in headlines
7317 maximize hierarchy
)))
7319 (loop for i from
0 to hierarchy
7320 collecting
(aref curhead i
)))
7321 (arrange (headlines)
7322 (unless (null headlines
) ; FIX headlines empty bug!
7323 (loop with curhead
= (make-vector (hierarchies headlines
) "")
7324 for
((str . pt
) . hierarchy
) in headlines
7325 do
(aset curhead hierarchy str
)
7328 (format "H%d:%s" (1+ hierarchy
)
7329 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
7334 (loop for re in regexp
7335 for hierarchy from
0
7336 do
(goto-char (point-min))
7339 while
(re-search-forward re nil t
)
7340 collect
(cons (matched) hierarchy
)))
7341 (lambda (a b
) (> (cdar b
) (cdar a
)))))
7342 (loop while
(re-search-forward regexp nil t
)
7343 collect
(matched))))))))
7346 (defun anything-headline-make-candidate-buffer (regexp subexp
)
7347 (with-current-buffer (anything-candidate-buffer 'local
)
7348 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
7351 (with-current-buffer anything-current-buffer
7352 (line-number-at-pos pos
))
7355 (defun anything-headline-goto-position (pos recenter
)
7358 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
7360 (defun anything-revert-buffer (candidate)
7361 (with-current-buffer candidate
7362 (when (buffer-modified-p)
7363 (revert-buffer t t
))))
7365 (defun anything-revert-marked-buffers (ignore)
7366 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
7368 (defun anything-kill-marked-buffers (ignore)
7369 (mapc 'kill-buffer
(anything-marked-candidates)))
7371 ;; Plug-in: persistent-help
7372 (defun anything-compile-source--persistent-help (source)
7373 (append source
'((header-line . anything-persistent-help-string
))))
7374 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
7376 (defun anything-persistent-help-string ()
7377 (substitute-command-keys
7378 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
7379 (or (anything-interpret-value (anything-attr 'persistent-help
))
7380 (anything-aif (or (assoc-default 'persistent-action
7381 (anything-get-current-source))
7382 (assoc-default 'action
7383 (anything-get-current-source)))
7384 (cond ((symbolp it
) (symbol-name it
))
7385 ((listp it
) (or (ignore-errors (caar it
)) ""))))
7387 " (keeping session)")))
7389 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
7390 "A string to explain persistent-action of this source.
7391 It also accepts a function or a variable name.")
7393 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
7395 ;; Plug-in: Type customize
7396 (defun anything-c-uniq-list (lst)
7397 "Like `remove-duplicates' in CL.
7398 But cut deeper duplicates and test by `equal'. "
7399 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
7400 (defvar anything-additional-type-attributes nil
)
7401 (defun anything-c-arrange-type-attribute (type spec
)
7402 "Override type attributes by `define-anything-type-attribute'.
7404 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
7406 Example: Set `play-sound-file' as default action
7407 (anything-c-arrange-type-attribute 'file
7408 '((action (\"Play sound\" . play-sound-file)
7409 REST ;; Rest of actions (find-file, find-file-other-window, ...)
7412 (add-to-list 'anything-additional-type-attributes
7414 (loop with typeattr
= (assoc-default type anything-type-attributes
)
7415 for
(attr . value
) in spec
7418 (anything-c-uniq-list
7419 (loop for v in value
7421 append
(assoc-default attr typeattr
)
7425 collect
(cons attr value
)))))
7426 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
7428 (defun anything-compile-source--type-customize (source)
7429 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
7432 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
7434 ;; Plug-in: default-action
7435 (defun anything-compile-source--default-action (source)
7436 (anything-aif (assoc-default 'default-action source
)
7437 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
7440 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
7441 (anything-document-attribute 'default-action
"default-action plug-in"
7444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7446 (defun anything-c-find-file-or-marked (candidate)
7447 "Open file CANDIDATE or open anything marked files in background."
7448 (let ((marked (anything-marked-candidates)))
7449 (if (> (length marked
) 1)
7450 ;; Open all marked files in background.
7451 (mapc 'find-file-noselect marked
)
7452 (if (and (not (file-exists-p candidate
))
7453 (and ffap-url-regexp
7454 (not (string-match ffap-url-regexp candidate
)))
7455 (string-match "/$" candidate
))
7456 ;; A a non--existing filename ending with /
7457 ;; Create a directory and jump to it.
7458 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
7459 (let ((cur-dir default-directory
))
7462 (make-directory candidate
'parent
)
7463 (when (file-exists-p candidate
)
7465 (anything-find-files candidate
)))
7466 (setq default-directory cur-dir
))))
7467 ;; A non--existing filename NOT ending with / or
7468 ;; an existing filename, create or jump to it.
7469 (find-file-at-point candidate
)))))
7471 (defun anything-delete-marked-files (ignore)
7472 (let* ((files (anything-marked-candidates))
7473 (len (length files
)))
7475 (format "Delete *%s File(s):\n%s"
7477 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
7478 (message "(No deletions performed)")
7480 (set-text-properties 0 (length i
) nil i
)
7481 (anything-c-delete-file i
))
7482 (message "%s File(s) deleted" len
))))
7484 (defun anything-ediff-marked-buffers (candidate &optional merge
)
7485 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
7486 With optional arg `merge' call `ediff-merge-buffers'."
7487 (let ((lg-lst (length (anything-marked-candidates)))
7491 (error "Error:You have to mark at least 1 buffer"))
7493 (setq buf1 anything-current-buffer
7494 buf2
(first (anything-marked-candidates))))
7496 (setq buf1
(first (anything-marked-candidates))
7497 buf2
(second (anything-marked-candidates))))
7499 (error "Error:To much buffers marked!")))
7501 (ediff-merge-buffers buf1 buf2
)
7502 (ediff-buffers buf1 buf2
))))
7504 (defun anything-bookmark-get-bookmark-from-name (bmk)
7505 "Return bookmark name even if it is a bookmark with annotation.
7506 e.g prepended with *.
7507 Return nil if bmk is not a valid bookmark."
7508 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
7509 (if (assoc bookmark bookmark-alist
)
7511 (when (assoc bmk bookmark-alist
)
7514 (defun anything-delete-marked-bookmarks (ignore)
7515 "Delete this bookmark or all marked bookmarks."
7516 (dolist (i (anything-marked-candidates))
7517 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
7520 (defun anything-require-or-error (feature function
)
7521 (or (require feature nil t
)
7522 (error "Need %s to use `%s'." feature function
)))
7524 (defun anything-find-buffer-on-elscreen (candidate)
7525 "Open buffer in new screen, if marked buffers open all in elscreens."
7526 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
7527 (anything-aif (anything-marked-candidates)
7529 (let ((target-screen (elscreen-find-screen-by-buffer
7530 (get-buffer i
) 'create
)))
7531 (elscreen-goto target-screen
)))
7532 (let ((target-screen (elscreen-find-screen-by-buffer
7533 (get-buffer candidate
) 'create
)))
7534 (elscreen-goto target-screen
))))
7536 (defun anything-elscreen-find-file (file)
7537 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
7538 (elscreen-find-file file
))
7540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7542 ;;;; Type Attributes
7543 (define-anything-type-attribute 'buffer
7546 '(("Switch to buffer other window" . switch-to-buffer-other-window
)
7547 ("Switch to buffer" . switch-to-buffer
))
7548 '(("Switch to buffer" . switch-to-buffer
)
7549 ("Switch to buffer other window" . switch-to-buffer-other-window
)
7550 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)))
7551 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
7552 ("View buffer" . view-buffer
)
7553 ("Display buffer" . display-buffer
)
7554 ("Revert buffer" . anything-revert-buffer
)
7555 ("Revert Marked buffers" . anything-revert-marked-buffers
)
7556 ("Insert buffer" . insert-buffer
)
7557 ("Kill buffer" . kill-buffer
)
7558 ("Kill Marked buffers" . anything-kill-marked-buffers
)
7559 ("Diff with file" . diff-buffer-with-file
)
7560 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
7561 ("Ediff Merge marked buffers" .
(lambda (candidate)
7562 (anything-ediff-marked-buffers candidate t
))))
7563 (persistent-help .
"Show this buffer")
7564 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers
))
7565 "Buffer or buffer name.")
7567 (define-anything-type-attribute 'file
7570 '(("Find file other window" . find-file-other-window
)
7571 ("Find file(s)" . anything-find-many-files
)
7572 ("Find file as root" . anything-find-file-as-root
))
7573 '(("Find file" . anything-find-many-files
)
7574 ("Find file as root" . anything-find-file-as-root
)
7575 ("Find file other window" . find-file-other-window
)
7576 ("Find file other frame" . find-file-other-frame
)))
7577 ("Open dired in file's directory" . anything-c-open-dired
)
7578 ("Grep File(s)" .
(lambda (candidate)
7579 ;; Restore highlighting disabled in *-find-files.
7580 (let ((anything-mp-highlight-delay 0.7))
7581 (anything-do-grep (anything-marked-candidates)))))
7582 ("View file" . view-file
)
7583 ("Insert file" . insert-file
)
7584 ("Delete file(s)" . anything-delete-marked-files
)
7585 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
7586 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
7587 ("Find file in hex dump" . hexl-find-file
))
7588 (persistent-help .
"Show this file")
7589 (action-transformer anything-c-transform-file-load-el
7590 anything-c-transform-file-browse-url
)
7591 (candidate-transformer anything-c-w32-pathname-transformer
7592 anything-c-skip-current-file
7593 anything-c-skip-boring-files
7594 anything-c-shorten-home-path
))
7597 (let ((actions '(("Describe command" . describe-function
)
7598 ("Add command to kill ring" . anything-c-kill-new
)
7599 ("Go to command's definition" . find-function
)
7600 ("Debug on entry" . debug-on-entry
)
7601 ("Cancel debug on entry" . cancel-debug-on-entry
)
7602 ("Trace function" . trace-function
)
7603 ("Trace function (background)" . trace-function-background
)
7604 ("Untrace function" . untrace-function
))))
7605 (define-anything-type-attribute 'command
7606 `((action ("Call interactively" . anything-c-call-interactively
)
7608 ;; Sort commands according to their usage count.
7609 (filtered-candidate-transformer . anything-c-adaptive-sort
)
7610 (coerce . anything-c-symbolify
)
7611 (persistent-action . describe-function
))
7612 "Command. (string or symbol)")
7614 (define-anything-type-attribute 'function
7615 `((action .
,actions
)
7616 (action-transformer anything-c-transform-function-call-interactively
)
7617 (candidate-transformer anything-c-mark-interactive-functions
)
7618 (coerce . anything-c-symbolify
))
7619 "Function. (string or symbol)"))
7621 (define-anything-type-attribute 'variable
7622 '((action ("Describe variable" . describe-variable
)
7623 ("Add variable to kill ring" . anything-c-kill-new
)
7624 ("Go to variable's definition" . find-variable
)
7625 ("Set variable" . anything-c-set-variable
))
7626 (coerce . anything-c-symbolify
))
7629 (define-anything-type-attribute 'sexp
7630 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
7631 ("Add s-expression to kill ring" . kill-new
))
7632 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
7633 "String representing S-Expressions.")
7635 (define-anything-type-attribute 'bookmark
7636 `((coerce . anything-bookmark-get-bookmark-from-name
)
7638 ("Jump to bookmark" .
(lambda (bookmark)
7639 (let ((current-prefix-arg anything-current-prefix-arg
))
7640 (bookmark-jump bookmark
))
7642 ("Jump to BM other window" .
(lambda (bookmark)
7643 (bookmark-jump-other-window bookmark
)
7645 ("Bookmark edit annotation" . bookmark-edit-annotation
)
7646 ("Bookmark show annotation" . bookmark-show-annotation
)
7647 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
7648 ,@(when (fboundp 'bmkext-edit-bookmark
)
7649 '(("Edit Bookmark" . bmkext-edit-bookmark
)))
7650 ("Rename bookmark" . bookmark-rename
)
7651 ("Relocate bookmark" . bookmark-relocate
)))
7654 (define-anything-type-attribute 'line
7655 '((display-to-real . anything-c-display-to-real-line
)
7656 (action ("Go to Line" . anything-c-action-line-goto
)))
7657 "LINENO:CONTENT string, eg. \" 16:foo\".
7659 Optional `target-file' attribute is a name of target file.
7661 Optional `before-jump-hook' attribute is a function with no
7662 arguments which is called before jumping to position.
7664 Optional `after-jump-hook' attribute is a function with no
7665 arguments which is called after jumping to position.
7667 If `adjust' attribute is specified, searches the line whose
7668 content is CONTENT near the LINENO.
7670 If `recenter' attribute is specified, the line is displayed at
7671 the center of window, otherwise at the top of window.
7674 (define-anything-type-attribute 'file-line
7675 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
7677 (action ("Go to" . anything-c-action-file-line-goto
)))
7678 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
7680 Optional `default-directory' attribute is a default-directory
7681 FILENAME is interpreted.
7683 Optional `before-jump-hook' attribute is a function with no
7684 arguments which is called before jumping to position.
7686 Optional `after-jump-hook' attribute is a function with no
7687 arguments which is called after jumping to position.
7689 If `adjust' attribute is specified, searches the line whose
7690 content is CONTENT near the LINENO.
7692 If `recenter' attribute is specified, the line is displayed at
7693 the center of window, otherwise at the top of window.
7696 (define-anything-type-attribute 'timer
7697 '((real-to-display . anything-c-timer-real-to-display
)
7698 (action ("Cancel Timer" . cancel-timer
)
7699 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
7700 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
7701 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
7702 (persistent-help .
"Describe Function"))
7705 ;;;; Default `anything-sources'
7706 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
7707 ;; tend to invoke M-x anything directly. So I offer default setting.
7708 (setq anything-sources
7709 '(anything-c-source-buffers+
7710 anything-c-source-recentf
7711 anything-c-source-files-in-current-dir
+))
7714 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7715 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
7717 (when (fboundp 'expectations
)
7719 (desc "candidates-file plug-in")
7720 (expect '(anything-p-candidats-file-init)
7721 (assoc-default 'init
7722 (car (anything-compile-sources
7724 (candidates-file .
"test.txt")))
7725 '(anything-compile-source--candidates-file)))))
7726 (expect '(anything-p-candidats-file-init
7728 (assoc-default 'init
7729 (car (anything-compile-sources
7731 (candidates-file .
"test.txt")
7732 (init .
(lambda () 1))))
7733 '(anything-compile-source--candidates-file)))))
7734 (expect '(anything-p-candidats-file-init
7736 (assoc-default 'init
7737 (car (anything-compile-sources
7739 (candidates-file .
"test.txt")
7740 (init (lambda () 1))))
7741 '(anything-compile-source--candidates-file)))))
7743 ;; (desc "anything-c-source-buffers")
7744 ;; (expect '(("Buffers" ("foo" "curbuf")))
7745 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
7746 ;; (let ((anything-c-boring-buffer-regexp
7751 ;; " *Echo Area" " *Minibuf"))))
7752 ;; (flet ((buffer-name (&optional x) x))
7753 ;; (anything-test-candidates 'anything-c-source-buffers))))
7754 (desc "anything-c-stringify")
7756 (anything-c-stringify "str1"))
7758 (anything-c-stringify 'str2
))
7759 (desc "anything-c-symbolify")
7761 (anything-c-symbolify "sym1"))
7763 (anything-c-symbolify 'sym2
))
7764 (desc "plug-in:default-action")
7765 (expect '(((action ("default" . default
) ("original" . original
))
7766 (default-action .
("default" . default
))
7767 (action ("original" . original
))))
7768 (anything-compile-sources
7769 '(((default-action .
("default" . default
))
7770 (action ("original" . original
))))
7771 '(anything-compile-source--default-action)))
7772 (expect '(((action ("a1" . a1
) ("a2" . a2
))
7773 (default-action .
("a1" . a1
))
7774 (action ("a1" . a1
) ("a2" . a2
))))
7775 (anything-compile-sources
7776 '(((default-action .
("a1" . a1
))
7777 (action ("a1" . a1
) ("a2" . a2
))))
7778 '(anything-compile-source--default-action)))
7779 (expect '(((action ("a2" . a2
) ("a1" . a1
))
7780 (default-action .
("a2" . a2
))
7781 (action ("a1" . a1
) ("a2" . a2
))))
7782 (anything-compile-sources
7783 '(((default-action .
("a2" . a2
))
7784 (action ("a1" . a1
) ("a2" . a2
))))
7785 '(anything-compile-source--default-action))))))
7787 (provide 'anything-config
)
7789 ;;; Local Variables:
7790 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
7793 ;; How to save (DO NOT REMOVE!!)
7794 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
7795 ;;; anything-config.el ends here
7797 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
7798 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
7799 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
7800 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
7801 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
7802 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
7803 ;;; LocalWords: dotimes Thierry online vname
7804 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
7805 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
7806 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
7807 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
7808 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
7809 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
7810 ;;; LocalWords: startpos noselect dont desc