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 (anything-other-buffer 'anything-c-source-kill-ring
"*anything kill-ring*"))
1003 (defun anything-minibuffer-history ()
1004 "Preconfigured `anything' for `minibuffer-history'."
1006 (let ((enable-recursive-minibuffers t
))
1007 (anything-other-buffer 'anything-c-source-minibuffer-history
1008 "*anything minibuffer-history*")))
1011 (defun anything-gentoo ()
1012 "Preconfigured `anything' for gentoo linux."
1014 (anything-other-buffer '(anything-c-source-gentoo
1015 anything-c-source-use-flags
)
1016 "*anything gentoo*"))
1019 (defun anything-imenu ()
1020 "Preconfigured `anything' for `imenu'."
1022 (anything 'anything-c-source-imenu nil nil nil nil
"*anything imenu*"))
1025 (defun anything-google-suggest ()
1026 "Preconfigured `anything' for google search with google suggest."
1028 (anything-other-buffer 'anything-c-source-google-suggest
"*anything google*"))
1031 (defun anything-yahoo-suggest ()
1032 "Preconfigured `anything' for Yahoo searching with Yahoo suggest."
1034 (anything-other-buffer 'anything-c-source-yahoo-suggest
"*anything yahoo*"))
1036 ;;; Converted from anything-show-*-only
1038 (defun anything-for-buffers ()
1039 "Preconfigured `anything' for buffer."
1041 (anything-other-buffer 'anything-c-source-buffers
"*anything for buffers*"))
1044 (defun anything-buffers+ ()
1045 "Enhanced preconfigured `anything' for buffer."
1047 (anything-other-buffer 'anything-c-source-buffers
+ "*anything buffers*"))
1050 (defun anything-bbdb ()
1051 "Preconfigured `anything' for BBDB.
1055 http://bbdb.sourceforge.net/"
1057 (anything-other-buffer 'anything-c-source-bbdb
"*anything bbdb*"))
1060 (defun anything-locate ()
1061 "Preconfigured `anything' for Locate.
1062 Note you can add locate command after entering pattern.
1063 See man locate for more infos."
1065 (anything-other-buffer 'anything-c-source-locate
"*anything locate*"))
1068 (defun anything-w3m-bookmarks ()
1069 "Preconfigured `anything' for w3m bookmark.
1071 Needs w3m and emacs-w3m.
1073 http://w3m.sourceforge.net/
1074 http://emacs-w3m.namazu.org/"
1076 (anything-other-buffer 'anything-c-source-w3m-bookmarks
1077 "*anything w3m bookmarks*"))
1080 (defun anything-firefox-bookmarks ()
1081 "Preconfigured `anything' for firefox bookmark.
1082 You will have to enable html bookmarks in firefox:
1083 open about:config in firefox and double click on this line to enable value \
1086 user_pref(\"browser.bookmarks.autoExportHTML\", false);
1088 You should have now:
1090 user_pref(\"browser.bookmarks.autoExportHTML\", true);
1092 After closing firefox, you will be able to browse you bookmarks.
1095 (anything-other-buffer 'anything-c-source-firefox-bookmarks
1096 "*Anything Firefox*"))
1099 (defun anything-colors ()
1100 "Preconfigured `anything' for color."
1102 (anything-other-buffer
1103 '(anything-c-source-colors anything-c-source-customize-face
)
1104 "*anything colors*"))
1107 (defun anything-bookmarks ()
1108 "Preconfigured `anything' for bookmarks."
1110 (anything-other-buffer 'anything-c-source-bookmarks
"*anything bookmarks*"))
1113 (defun anything-c-pp-bookmarks ()
1114 "Preconfigured `anything' for bookmarks (pretty-printed)."
1116 (anything-other-buffer '(anything-c-source-bookmarks-local
1117 anything-c-source-bookmarks-su
1118 anything-c-source-bookmarks-ssh
)
1119 "*anything pp bookmarks*"))
1122 (defun anything-register ()
1123 "Preconfigured `anything' for Emacs registers."
1125 (anything-other-buffer 'anything-c-source-register
"*anything register*"))
1128 (defun anything-man-woman ()
1129 "Preconfigured `anything' for Man and Woman pages."
1131 (anything-other-buffer 'anything-c-source-man-pages
"*Anything man woman*"))
1134 (defun anything-org-keywords ()
1135 "Preconfigured `anything' for org keywords."
1137 (anything-other-buffer 'anything-c-source-org-keywords
"*org keywords*"))
1140 (defun anything-emms ()
1141 "Preconfigured `anything' for emms sources."
1143 (anything '(anything-c-source-emms-streams
1144 anything-c-source-emms-files
1145 anything-c-source-emms-dired
)
1150 (defun anything-eev-anchors ()
1151 "Preconfigured `anything' for eev anchors."
1153 (anything-other-buffer 'anything-c-source-eev-anchor
"*Anything eev anchors*"))
1156 (defun anything-bm-list ()
1157 "Preconfigured `anything' for visible bookmarks.
1161 http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el"
1163 (let ((anything-outline-using t
))
1164 (anything-other-buffer 'anything-c-source-bm
"*anything bm list*")))
1167 (defun anything-timers ()
1168 "Preconfigured `anything' for timers."
1170 (anything-other-buffer '(anything-c-source-absolute-time-timers
1171 anything-c-source-idle-time-timers
)
1172 "*anything timers*"))
1175 (defun anything-list-emacs-process ()
1176 "Preconfigured `anything' for emacs process."
1178 (anything-other-buffer 'anything-c-source-emacs-process
"*anything process*"))
1181 (defun anything-occur ()
1182 "Preconfigured Anything for Occur source."
1184 (let ((anything-compile-source-functions
1185 ;; rule out anything-match-plugin because the input is one regexp.
1186 (delq 'anything-compile-source--match-plugin
1187 (copy-sequence anything-compile-source-functions
))))
1188 (anything-other-buffer 'anything-c-source-occur
"*Anything Occur*")))
1191 (defun anything-browse-code ()
1192 "Preconfigured anything to browse code."
1194 (anything-other-buffer 'anything-c-source-browse-code
"*Browse code*"))
1197 (defun anything-org-headlines ()
1198 "Preconfigured anything to show org headlines."
1200 (anything-other-buffer 'anything-c-source-org-headline
"*org headlines*"))
1202 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1205 (defun anything-kill-buffers ()
1206 "Preconfigured `anything' to kill buffer you selected."
1209 '(((name .
"Kill Buffers")
1210 (candidates . anything-c-buffer-list
)
1212 ("Kill Buffer" .
(lambda (candidate)
1213 (kill-buffer candidate
)
1214 (anything-kill-buffers)
1219 (defun anything-c-query-replace-regexp (candidate)
1220 (let ((regexp (funcall (anything-attr 'regexp
))))
1221 (apply 'query-replace-regexp
1222 (anything-c-query-replace-args regexp
))))
1224 (defun anything-c-kill-regexp-as-sexp (candidate)
1225 (anything-c-regexp-kill-new
1226 (prin1-to-string (funcall (anything-attr 'regexp
)))))
1228 (defun anything-c-kill-regexp (candidate)
1229 (anything-c-regexp-kill-new (funcall (anything-attr 'regexp
))))
1231 (defun anything-c-query-replace-args (regexp)
1232 "create arguments of `query-replace-regexp' action in `anything-regexp'."
1233 (let ((region-only (anything-region-active-p)))
1236 (query-replace-read-to regexp
1237 (format "Query replace %s regexp %s"
1238 (if anything-current-prefix-arg
"word " "")
1239 (if region-only
"in region " ""))
1241 anything-current-prefix-arg
1242 (when region-only
(region-beginning))
1243 (when region-only
(region-end)))))
1245 (defvar anything-c-source-regexp
1246 '((name .
"Regexp Builder")
1248 (anything-candidate-buffer anything-current-buffer
)))
1249 (candidates-in-buffer)
1250 (get-line . anything-c-regexp-get-line
)
1251 (persistent-action . anything-c-regexp-persistent-action
)
1252 (persistent-help .
"Show this line")
1255 (requires-pattern .
2)
1256 (mode-line .
"Press TAB to select action.")
1258 ;; I use here `anything-input' because `anything-pattern' is lost when
1259 ;; using actions from action buffer (otherwise no e.g from RET, C-e or C-j).
1260 ;; It seem `anything-select-action' reset `anything-pattern' to empty too early.
1261 ;; Though the regexp attribute stay defined (tested with *-attr-defined).
1263 (regexp .
(lambda () anything-input
))
1264 (action .
(("Kill Regexp as sexp" . anything-c-kill-regexp-as-sexp
)
1265 ("Query Replace Regexp" . anything-c-query-replace-regexp
)
1266 ("Kill Regexp" . anything-c-kill-regexp
)))))
1268 (defun anything-c-regexp-get-line (s e
)
1272 (format "%5d: %s" (line-number-at-pos (1- s
)) (buffer-substring s e
))
1274 (loop for i from
0 to
(1- (/ (length (match-data)) 2))
1275 collect
(format "\n %s'%s'"
1276 (if (zerop i
) "Group 0: " (format "Group %d: " i
))
1279 ;; KLUDGE: point of anything-candidate-buffer is +1 than that of anything-current-buffer.
1280 ;; It is implementation problem of candidates-in-buffer.
1284 ;; Shut up byte compiler
1285 (defun anything-goto-line (numline)
1286 "Replacement of `goto-line'."
1287 (goto-char (point-min))
1288 (forward-line (1- numline
)))
1290 (defun anything-c-regexp-persistent-action (pt)
1292 (anything-persistent-highlight-point))
1294 (defun anything-c-regexp-kill-new (input)
1296 (message "Killed: %s" input
))
1298 (defun anything-region-active-p ()
1299 (and transient-mark-mode mark-active
(/= (mark) (point))))
1301 (defun* anything-current-buffer-narrowed-p
(&optional
1302 (buffer anything-current-buffer
))
1303 "Check if BUFFER is narrowed.
1304 Default is `anything-current-buffer'."
1305 (with-current-buffer buffer
1306 (let ((beg (point-min))
1308 (total (buffer-size)))
1309 (or (/= beg
1) (/= end
(1+ total
))))))
1312 (defun anything-regexp ()
1313 "Preconfigured anything to build regexps and run query-replace-regexp \
1317 (let ((anything-compile-source-functions
1318 ;; rule out anything-match-plugin because the input is one regexp.
1319 (delq 'anything-compile-source--match-plugin
1320 (copy-sequence anything-compile-source-functions
))))
1321 (when (and (anything-region-active-p)
1322 ;; Don't narrow to region if buffer is already narrowed.
1323 (not (anything-current-buffer-narrowed-p)))
1324 (narrow-to-region (region-beginning) (region-end)))
1326 anything-c-source-regexp
1327 :buffer
"*anything regexp*"
1328 :prompt
"Regexp: "))))
1331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1333 (defun anything-insert-buffer-name ()
1334 "Insert buffer name."
1336 (anything-insert-string
1337 (with-current-buffer anything-current-buffer
1338 (if buffer-file-name
(file-name-nondirectory buffer-file-name
)
1341 (defun anything-insert-symbol ()
1342 "Insert current symbol."
1344 (anything-insert-string
1345 (with-current-buffer anything-current-buffer
1347 (buffer-substring (beginning-of-thing 'symbol
)
1348 (end-of-thing 'symbol
))))))
1350 (defun anything-insert-selection ()
1351 "Insert current selection."
1353 (anything-insert-string
1354 (with-current-buffer anything-current-buffer
1355 (anything-get-selection))))
1357 (defun anything-show-buffer-only ()
1358 "[OBSOLETE] Only show sources about buffer.
1359 Use `anything-for-buffers' instead."
1361 (anything-set-source-filter '("Buffers")))
1363 (defun anything-show-bbdb-only ()
1364 "[OBSOLETE] Only show sources about BBDB.
1365 Use `anything-bbdb' instead."
1367 (anything-set-source-filter '("BBDB")))
1369 (defun anything-show-locate-only ()
1370 "[OBSOLETE] Only show sources about Locate.
1371 Use `anything-locate' instead."
1373 (anything-set-source-filter '("Locate")))
1375 (defun anything-show-info-only ()
1376 "[OBSOLETE] Only show sources about Info.
1377 Use `anything-info-at-point' instead."
1379 (anything-set-source-filter '("Info Pages"
1381 "Info Common-Lisp")))
1383 (defun anything-show-imenu-only ()
1384 "[OBSOLETE] Only show sources about Imenu.
1385 Use `anything-imenu' instead."
1387 (anything-set-source-filter '("Imenu")))
1389 (defun anything-show-files-only ()
1390 "[OBSOLETE] Only show sources about File.
1391 Use `anything-for-files' instead."
1393 (anything-set-source-filter '("File Name History"
1394 "Files from Current Directory"
1397 (defun anything-show-w3m-bookmarks-only ()
1398 "[OBSOLETE] Only show source about w3m bookmark.
1399 Use `anything-w3m-bookmarks' instead."
1401 (anything-set-source-filter '("W3m Bookmarks")))
1403 (defun anything-show-colors-only ()
1404 "[OBSOLETE] Only show source about color.
1405 Use `anything-colors' instead."
1407 (anything-set-source-filter '("Colors"
1408 "Customize Faces")))
1410 (defun anything-show-kill-ring-only ()
1411 "[OBSOLETE] Only show source about kill ring.
1412 Use `anything-show-kill-ring' instead."
1414 (anything-set-source-filter '("Kill Ring")))
1416 (defun anything-show-this-source-only ()
1417 "Only show this source."
1419 (setq anything-candidate-number-limit
9999)
1420 (anything-set-source-filter
1421 (list (assoc-default 'name
(anything-get-current-source)))))
1423 (defun anything-test-sources ()
1424 "List all anything sources for test.
1425 The output is sexps which are evaluated by \\[eval-last-sexp]."
1427 (with-output-to-temp-buffer "*Anything Test Sources*"
1428 (mapc (lambda (s) (princ (format ";; (anything '%s)\n" s
)))
1429 (apropos-internal "^anything-c-source" #'boundp
))
1430 (pop-to-buffer standard-output
)))
1432 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1433 ;;; For compatibility
1434 (unless (fboundp 'region-active-p
)
1435 (defun region-active-p ()
1436 "Return t if Transient Mark mode is enabled and the mark is active.
1438 Most commands that act on the region if it is active and
1439 Transient Mark mode is enabled, and on the text near point
1440 otherwise, should use `use-region-p' instead. That function
1441 checks the value of `use-empty-active-region' as well."
1442 (and transient-mark-mode mark-active
)))
1444 (defun anything-nest (&rest same-as-anything
)
1445 "Nested `anything'. If you use `anything' within `anything', use it."
1446 (with-selected-window (anything-window)
1447 (let (anything-current-position
1448 anything-current-buffer
1449 (orig-anything-buffer anything-buffer
)
1453 anything-compiled-sources
1454 anything-buffer-chars-modified-tick
1455 (anything-samewindow t
)
1456 (enable-recursive-minibuffers t
))
1458 (apply #'anything same-as-anything
)
1459 (anything-initialize-overlays orig-anything-buffer
)
1460 (add-hook 'post-command-hook
'anything-check-minibuffer-input
)))))
1462 (defun anything-displaying-source-names ()
1463 "Display sources name."
1464 (with-current-buffer anything-buffer
1465 (goto-char (point-min))
1467 while
(setq pos
(next-single-property-change (point) 'anything-header
))
1469 collect
(buffer-substring-no-properties (point-at-bol)(point-at-eol))
1470 do
(forward-line 1))))
1472 (defun anything-select-source ()
1475 (let ((default (assoc-default 'name
(anything-get-current-source)))
1476 (source-names (anything-displaying-source-names))
1477 (all-source-names (mapcar (lambda (s) (assoc-default 'name s
))
1478 (anything-get-sources))))
1479 (setq anything-candidate-number-limit
9999)
1481 (let (anything-source-filter)
1482 (anything-nest '(((name .
"Anything Source")
1483 (candidates . source-names
)
1484 (action . identity
))
1485 ((name .
"Anything Source (ALL)")
1486 (candidates . all-source-names
)
1487 (action . identity
)))
1489 default
"*anything select source*"))
1490 (anything-set-source-filter (list it
))
1491 (anything-set-source-filter nil
))))
1493 (defun anything-insert-string (str)
1495 (delete-minibuffer-contents)
1498 (defun anything-c-match-on-file-name (candidate)
1499 "Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
1500 (string-match anything-pattern
(file-name-nondirectory candidate
)))
1502 (defun anything-c-match-on-directory-name (candidate)
1503 "Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
1504 (anything-aif (file-name-directory candidate
)
1505 (string-match anything-pattern it
)))
1507 (defun anything-c-string-match (candidate)
1508 "Return non-nil if `anything-pattern' match CANDIDATE.
1509 The match is done with `string-match'."
1510 (string-match anything-pattern candidate
))
1512 ;; `anything-c-compose' is no more needed, it is for compatibility.
1513 (defalias 'anything-c-compose
'anything-compose
)
1515 (defun anything-c-skip-entries (list regexp
)
1516 "Remove entries which matches REGEXP from LIST."
1517 (remove-if (lambda (x) (and (stringp x
) (string-match regexp x
)))
1520 (defun anything-c-shadow-entries (list regexp
)
1521 "Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
1522 (mapcar (lambda (file)
1523 ;; Add shadow face property to boring files.
1524 (let ((face (if (facep 'file-name-shadow
)
1526 ;; fall back to default on XEmacs
1528 (if (string-match regexp file
)
1529 (setq file
(propertize file
'face face
))))
1533 (defsubst anything-c-stringify
(str-or-sym)
1534 "Get string of STR-OR-SYM."
1535 (if (stringp str-or-sym
)
1537 (symbol-name str-or-sym
)))
1539 (defsubst anything-c-symbolify
(str-or-sym)
1540 "Get symbol of STR-OR-SYM."
1541 (if (symbolp str-or-sym
)
1543 (intern str-or-sym
)))
1545 (defun anything-c-describe-function (func)
1546 "FUNC is symbol or string."
1547 (describe-function (anything-c-symbolify func
)))
1549 (defun anything-c-describe-variable (var)
1550 "VAR is symbol or string."
1551 (describe-variable (anything-c-symbolify var
)))
1553 (defun anything-c-find-function (func)
1554 "FUNC is symbol or string."
1555 (find-function (anything-c-symbolify func
)))
1557 (defun anything-c-find-variable (var)
1558 "VAR is symbol or string."
1559 (find-variable (anything-c-symbolify var
)))
1561 (defun anything-c-kill-new (string &optional replace yank-handler
)
1562 "STRING is symbol or string."
1563 (kill-new (anything-c-stringify string
) replace yank-handler
))
1565 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1566 ;; TODO: This should be integrated in anything.el instead of having
1567 ;; a defadvice here.
1569 (defvar anything-current-prefix-arg nil
1570 "Record `current-prefix-arg' when exiting minibuffer.
1571 It will be cleared at start of next `anything' call when \
1572 `anything-before-initialize-hook' is called.")
1574 (defadvice anything-exit-minibuffer
(before anything-current-prefix-arg activate
)
1575 (unless anything-current-prefix-arg
1576 (setq anything-current-prefix-arg current-prefix-arg
)))
1578 ;; using this hook instead of `anything-after-action-hook'
1579 ;; allow to record the prefix args and keep their values
1580 ;; when using `anything-comp-read'.
1581 (add-hook 'anything-before-initialize-hook
1582 (lambda () (setq anything-current-prefix-arg nil
)))
1585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1586 (defadvice eval-defun
(after anything-source-hack activate
)
1587 "See `anything-c-enable-eval-defun-hack'."
1588 (when anything-c-enable-eval-defun-hack
1589 (let ((varsym (save-excursion
1590 (beginning-of-defun)
1592 (when (memq (read (current-buffer)) '(defvar setq
))
1593 (read (current-buffer))))))
1594 (when (string-match "^anything-c-source-" (symbol-name varsym
))
1595 (anything varsym
)))))
1596 ;; (progn (ad-disable-advice 'eval-defun 'after 'anything-source-hack) (ad-update 'eval-defun))
1598 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1599 (defconst anything-c-create-summary-index-regexp
1600 "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$\\|^ *;; (anything '\\(.+?\\))$")
1601 (defun anything-c-create-summary ()
1602 "Create `anything' summary."
1604 (goto-char (point-min))
1606 while
(re-search-forward anything-c-create-summary-index-regexp nil t
)
1608 (cond ((setq it
(match-string-no-properties 1))
1610 ((setq it
(match-string-no-properties 2))
1612 ,(assoc-default 'name
(symbol-value (intern it
)))))
1613 ((setq it
(match-string-no-properties 3))
1615 ,(assoc-default 'name
(symbol-value (intern it
)))))))))
1617 ;; (find-epp (anything-c-create-summary))
1619 (defun anything-c-insert-summary ()
1620 "Insert `anything' summary."
1622 (goto-char (point-min))
1623 (search-forward ";; Below are complete source list you can setup in")
1625 (delete-region (point)
1626 (progn (search-forward ";;; Change log:" nil t
)
1627 (forward-line -
1) (point)))
1630 for
(kind . value
) in
(anything-c-create-summary)
1632 do
(cond ((eq kind
'section
)
1634 (align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))
1635 (insert ";; " value
":\n")
1638 (insert ";; `" (car value
) "' (" (cdr value
) ")\n")))
1639 finally
(align-regexp beg
(point) "\\(\\s-*\\)(" 1 1 nil
))))
1640 ;; (anything-c-insert-summary)
1642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1644 (defun anything-c-buffer-list ()
1645 "Return the list of names of buffers with boring buffers filtered out.
1646 Boring buffers is specified by `anything-c-boring-buffer-regexp'.
1647 The first buffer in the list will be the last recently used
1648 buffer that is not the current buffer."
1649 (let ((buffers (mapcar 'buffer-name
(buffer-list))))
1650 (append (cdr buffers
) (list (car buffers
)))))
1652 (defvar anything-c-source-buffers
1653 '((name .
"Buffers")
1654 (candidates . anything-c-buffer-list
)
1656 ;; (anything 'anything-c-source-buffers)
1658 (defvar anything-c-source-buffer-not-found
1659 '((name .
"Create buffer")
1662 ;; (anything 'anything-c-source-buffer-not-found)
1665 (defface anything-dir-heading
'((t (:foreground
"Blue" :background
"Pink")))
1666 "*Face used for directory headings in dired buffers."
1669 (defface anything-file-name
1670 '((t (:foreground
"Blue")))
1671 "*Face used for file names (without suffixes) in dired buffers."
1674 (defface anything-dir-priv
1675 '((t (:foreground
"DarkRed" :background
"LightGray")))
1676 "*Face used for directory privilege indicator (d) in dired buffers."
1679 (defvar anything-c-buffers-face1
'anything-dir-priv
)
1680 (defvar anything-c-buffers-face2
'font-lock-type-face
)
1681 (defvar anything-c-buffers-face3
'italic
)
1682 (eval-when-compile (require 'dired
))
1683 (defun anything-c-highlight-buffers (buffers)
1685 (loop for i in buffers
1686 if
(rassoc (get-buffer i
) dired-buffers
)
1687 collect
(propertize i
1688 'face anything-c-buffers-face1
1689 'help-echo
(car (rassoc (get-buffer i
) dired-buffers
)))
1690 if
(buffer-file-name (get-buffer i
))
1691 collect
(propertize i
1692 'face anything-c-buffers-face2
1693 'help-echo
(buffer-file-name (get-buffer i
)))
1694 if
(and (not (rassoc (get-buffer i
) dired-buffers
))
1695 (not (buffer-file-name (get-buffer i
))))
1696 collect
(propertize i
1697 'face anything-c-buffers-face3
)))
1699 (defvar anything-c-source-buffers
+
1700 '((name .
"Buffers")
1701 (candidates . anything-c-buffer-list
)
1703 (candidate-transformer anything-c-skip-current-buffer
1704 anything-c-highlight-buffers
1705 anything-c-skip-boring-buffers
)
1706 (persistent-action . anything-c-buffers
+-persistent-action
)
1707 (persistent-help .
"Show this buffer / C-u \\[anything-execute-persistent-action]: Kill this buffer")))
1709 (defun anything-c-buffers+-persistent-action
(name)
1711 (with-current-buffer item
1712 (if (and (buffer-modified-p)
1713 (buffer-file-name (current-buffer)))
1717 (kill-buffer item
))))
1719 (switch-to-buffer item
)))
1720 (if current-prefix-arg
1723 (anything-delete-current-selection))
1726 ;; (anything 'anything-c-source-buffers+)
1730 ;;; File name history
1731 (defvar anything-c-source-file-name-history
1732 '((name .
"File Name History")
1733 (candidates . file-name-history
)
1734 (match anything-c-match-on-file-name
1735 anything-c-match-on-directory-name
)
1737 ;; (anything 'anything-c-source-file-name-history)
1739 ;;; Files in current dir
1740 (defvar anything-c-source-files-in-current-dir
1741 '((name .
"Files from Current Directory")
1742 (candidates .
(lambda ()
1743 (with-current-buffer anything-current-buffer
1744 (directory-files (anything-c-current-directory)))))
1745 ;; volatile is not needed, I think.
1747 ;; (anything 'anything-c-source-files-in-current-dir)
1749 (defvar anything-c-files-face1
'anything-dir-priv
)
1750 (defvar anything-c-files-face2
'anything-file-name
)
1751 (defun anything-c-highlight-files (files)
1752 (loop for i in files
1753 if
(file-directory-p i
)
1754 collect
(propertize (file-name-nondirectory i
)
1755 'face anything-c-files-face1
1756 'help-echo
(expand-file-name i
))
1758 collect
(propertize (file-name-nondirectory i
)
1759 'face anything-c-files-face2
1760 'help-echo
(expand-file-name i
))))
1763 (defvar anything-c-source-files-in-current-dir
+
1764 '((name .
"Files from Current Directory")
1765 (candidates .
(lambda ()
1766 (with-current-buffer anything-current-buffer
1767 (directory-files (anything-c-current-directory) t
))))
1768 (candidate-transformer anything-c-highlight-files
)
1769 ;; volatile is not needed, I think.
1772 ;; (anything 'anything-c-source-files-in-current-dir+)
1774 ;;; Anything replacement of file name completion for `find-file' and friends.
1776 (defvar anything-c-find-files-doc-header
(format " (`%s':Go to precedent level)"
1777 (if window-system
"C-." "C-l"))
1778 "*The doc that is inserted in the Name header of a find-files or dired source.")
1780 (defvar anything-c-source-find-files
1781 `((name .
,(concat "Find Files" anything-c-find-files-doc-header
))
1782 ;; It is needed for filenames with capital letters
1785 (setq ffap-newfile-prompt t
)))
1786 (candidates . anything-find-files-get-candidates
)
1787 (filtered-candidate-transformer anything-c-find-files-transformer
)
1788 (persistent-action . anything-find-files-persistent-action
)
1789 (persistent-help .
"Hit1 Expand Candidate, Hit2 or (C-u) Find file")
1791 (action-transformer . anything-find-files-action-transformer
)
1795 `(("Find File" . anything-c-find-file-or-marked
)
1796 ("Find file in Dired" . anything-c-point-file-in-dired
)
1797 ,(and (locate-library "elscreen")
1798 '("Find file in Elscreen" . anything-elscreen-find-file
))
1799 ("Complete at point"
1800 . anything-c-insert-file-name-completion-at-point
)
1801 ("Open file externally `C-u to choose'"
1802 . anything-c-open-file-externally
)
1803 ("Grep File(s)" .
(lambda (candidate)
1804 ;; Restore highlighting disabled in *-find-files.
1805 (let ((anything-mp-highlight-delay 0.7))
1806 (anything-do-grep (anything-marked-candidates)))))
1807 ("Ediff File" . anything-find-files-ediff-files
)
1808 ("Ediff Merge File" . anything-find-files-ediff-merge-files
)
1809 ("Delete File(s)" . anything-delete-marked-files
)
1810 ("Copy file(s) `C-u to follow'" . anything-find-files-copy
)
1811 ("Rename file(s) `C-u to follow'" . anything-find-files-rename
)
1812 ("Symlink files(s) `C-u to follow'" . anything-find-files-symlink
)
1813 ("Relsymlink file(s) `C-u to follow'" . anything-find-files-relsymlink
)
1814 ("Hardlink file(s) `C-u to follow'" . anything-find-files-hardlink
)
1815 ("Find file other window" . find-file-other-window
)
1816 ("Find file other frame" . find-file-other-frame
)
1817 ("Find file as root" . anything-find-file-as-root
))))))
1818 ;; (anything 'anything-c-source-find-files)
1820 (defun anything-find-files-set-prompt-for-action (prompt files
)
1821 "Set prompt for action in `anything-find-files'."
1822 (let ((len (length files
)))
1824 (format "%s * %d Files to: " prompt len
)
1825 (format "%s %s to: " prompt
(car files
)))))
1827 (defun anything-find-files-do-action (action)
1828 "Generic function for creating action from `anything-c-source-find-files'.
1829 ACTION must be an action supported by `anything-dired-action'."
1830 (let* ((ifiles (anything-marked-candidates))
1831 (buf anything-current-buffer
)
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
)
1843 ;; If we have started in a dired buffer, don't kill it.
1844 (unless (eq (current-buffer) (get-buffer buf
))
1846 (unless parg
(set-window-configuration win-conf
)))))
1848 (defun anything-find-files-copy (candidate)
1849 "Copy files from `anything-find-files'."
1850 (anything-find-files-do-action 'copy
))
1852 (defun anything-find-files-rename (candidate)
1853 "Rename files from `anything-find-files'."
1854 (anything-find-files-do-action 'rename
))
1856 (defun anything-find-files-symlink (candidate)
1857 "Symlink files from `anything-find-files'."
1858 (anything-find-files-do-action 'symlink
))
1860 (defun anything-find-files-relsymlink (candidate)
1861 "Relsymlink files from `anything-find-files'."
1862 (anything-find-files-do-action 'relsymlink
))
1864 (defun anything-find-files-hardlink (candidate)
1865 "Hardlink files from `anything-find-files'."
1866 (anything-find-files-do-action 'hardlink
))
1868 (defun anything-find-files-byte-compile (candidate)
1869 "Byte compile files from `anything-find-files'."
1870 (let ((files (anything-marked-candidates))
1871 (parg anything-current-prefix-arg
))
1872 (loop for fname in files
1873 do
(byte-compile-file fname parg
))))
1875 (defun anything-find-files-ediff-files (candidate)
1876 "Default action to ediff files in `anything-find-files'."
1879 (anything-c-read-file-name
1880 (format "Ediff `%s' With File: " (file-name-nondirectory candidate
)))))
1882 (defun anything-find-files-ediff-merge-files (candidate)
1883 "Default action to ediff merge files in `anything-find-files'."
1886 (anything-c-read-file-name
1887 (format "Ediff Merge `%s' With File: " (file-name-nondirectory candidate
)))))
1889 (defun* anything-reduce-file-name
(fname level
&key unix-close expand
)
1890 "Reduce FNAME by LEVEL from end or beginning depending LEVEL value.
1891 If LEVEL is positive reduce from end else from beginning.
1892 If UNIX-CLOSE is non--nil close filename with /.
1893 If EXPAND is non--nil expand-file-name."
1894 (let* ((exp-fname (expand-file-name fname
))
1895 (fname-list (split-string (if (or (string= fname
"~/") expand
)
1896 exp-fname fname
) "/" t
))
1897 (len (length fname-list
))
1898 (pop-list (if (< level
0)
1899 (subseq fname-list
(* level -
1))
1900 (subseq fname-list
0 (- len level
))))
1901 (result (mapconcat 'identity pop-list
"/"))
1902 (empty (string= result
"")))
1903 (when unix-close
(setq result
(concat result
"/")))
1904 (if (string-match "^~" result
)
1905 (if (string= result
"~/") "~/" result
)
1907 (if empty
"../" (concat "../" result
))
1908 (cond ((eq system-type
'windows-nt
)
1909 (if empty
"c:/" result
))
1912 (concat "/" result
)))))))
1914 (defun anything-file-completion-source-p ()
1915 "Test if current source is a dired or find-files source."
1916 (let ((ff-sources '("Find Files" "Copy Files"
1917 "Rename Files" "Symlink Files"
1918 "Hardlink Files" "Write File"
1919 "Insert File" "Read file name"))
1920 (cur-source (cdr (assoc 'name
(anything-get-current-source)))))
1922 (dolist (i ff-sources
)
1923 (when (equal cur-source
(concat i anything-c-find-files-doc-header
))
1924 (throw 'break t
))))))
1926 (defun anything-find-files-down-one-level (arg)
1927 "Go down one level like unix command `cd ..'.
1928 If prefix numeric arg is given go ARG level down."
1930 (when (anything-file-completion-source-p)
1931 (let ((new-pattern (anything-reduce-file-name anything-pattern arg
1932 :unix-close t
:expand t
)))
1933 (with-selected-window (minibuffer-window)
1934 (delete-minibuffer-contents)
1935 (insert new-pattern
)))))
1937 ;; `C-.' doesn't work in terms use `C-l' instead.
1939 (define-key anything-map
(kbd "C-.") 'anything-find-files-down-one-level
)
1940 (define-key anything-map
(kbd "C-l") 'anything-find-files-down-one-level
))
1942 (defun anything-c-point-file-in-dired (file)
1943 "Put point on filename FILE in dired buffer."
1944 (dired (file-name-directory file
))
1945 (dired-goto-file file
))
1947 (defun anything-create-tramp-name (fname)
1948 "Build filename for `anything-pattern' like /su:: or /sudo::."
1949 (apply #'tramp-make-tramp-file-name
1951 with v
= (tramp-dissect-file-name fname
)
1952 for i across v collect i
)))
1954 (defun anything-find-files-get-candidates ()
1955 "Create candidate list for `anything-c-source-find-files'."
1956 (let* ( ; Don't try to tramp connect before entering the second ":".
1957 (tramp-file-name-regexp "\\`/\\([^[/:]+\\|[^/]+]\\):.*:?")
1958 (path (cond ((string-match "^~" anything-pattern
)
1959 (replace-match (getenv "HOME") nil t anything-pattern
))
1960 ((string-match tramp-file-name-regexp anything-pattern
)
1961 (let ((tramp-name (anything-create-tramp-name
1962 (match-string 0 anything-pattern
))))
1963 (replace-match tramp-name nil t anything-pattern
)))
1964 (t anything-pattern
)))
1965 (tramp-verbose anything-tramp-verbose
)) ; No tramp message when 0.
1966 (set-text-properties 0 (length path
) nil path
)
1967 (if (member 'anything-compile-source--match-plugin
1968 anything-compile-source-functions
)
1969 (setq anything-pattern path
)
1970 (setq anything-pattern
(replace-regexp-in-string " " ".*" path
)))
1971 (cond ((or (file-regular-p path
)
1972 (and (not (file-exists-p path
)) (string-match "/$" path
))
1973 (and ffap-url-regexp
(string-match ffap-url-regexp path
)))
1975 ((string= anything-pattern
"") (directory-files "/" t
))
1976 ((file-directory-p path
) (directory-files path t
))
1980 (directory-files (file-name-directory path
) t
))))))
1982 (defface anything-dired-symlink-face
1983 '((t (:foreground
"DarkOrange")))
1984 "*Face used for symlinks in `anything-find-files'."
1987 (defface anything-ffiles-prefix-face
1988 '((t (:background
"yellow" :foreground
"black")))
1989 "*Face used to prefix new file or url paths in `anything-find-files'."
1992 (defun anything-c-prefix-filename (fname &optional image
)
1993 "Return fname FNAME prefixed with icon IMAGE."
1994 (let* ((img-name (and image
(expand-file-name
1995 image anything-c-find-files-icons-directory
)))
1996 (img (and image
(create-image img-name
)))
1997 (prefix-img (and image
(propertize " " 'display img
)))
1998 (prefix-new (propertize
2000 (propertize "[?]" 'face
'anything-ffiles-prefix-face
)))
2001 (prefix-url (propertize
2003 (propertize "[@]" 'face
'anything-ffiles-prefix-face
))))
2004 (cond ((or (file-exists-p fname
)
2005 (file-symlink-p fname
))
2006 (if image
(concat prefix-img fname
) fname
))
2007 ((string-match ffap-url-regexp fname
) (concat prefix-url
" " fname
))
2008 (t (concat prefix-new
" " fname
)))))
2010 (defun anything-c-find-files-transformer (files sources
)
2011 "Selector of transformer to use for `anything-c-source-find-files'."
2012 (if (and (window-system) anything-c-find-files-show-icons
)
2013 (anything-c-highlight-ffiles1 files sources
)
2014 (anything-c-highlight-ffiles files sources
)))
2016 (defun anything-c-highlight-ffiles (files sources
)
2017 "Candidate transformer for `anything-c-source-find-files' without icons."
2018 (loop for i in files
2019 collect
(cond ((file-symlink-p i
)
2021 (anything-c-prefix-filename
2022 (propertize i
'face
'anything-dired-symlink-face
2023 'help-echo
(file-truename i
)))
2025 ((file-directory-p i
)
2027 (anything-c-prefix-filename
2028 (propertize i
'face anything-c-files-face1
))
2032 (anything-c-prefix-filename
2033 (propertize i
'face anything-c-files-face2
))
2036 (defsubst anything-c-highlight-ffiles1
(files sources
)
2037 "Candidate transformer for `anything-c-source-find-files' that show icons."
2038 (loop for i in files
2039 for af
= (file-name-nondirectory i
)
2040 collect
(cond ( ;; Files.
2041 (eq nil
(car (file-attributes i
)))
2042 (cons (anything-c-prefix-filename
2043 (propertize i
'face anything-c-files-face2
)
2046 ( ;; Empty directories.
2047 (and (eq t
(car (file-attributes i
)))
2048 ;; Be sure to have permission to list content.
2052 i nil directory-files-no-dot-files-regexp t
))))
2053 (cons (anything-c-prefix-filename
2054 (propertize i
'face anything-c-files-face1
)
2057 ( ;; Open directories.
2058 (and (eq t
(car (file-attributes i
))) (get-buffer af
))
2059 (cons (anything-c-prefix-filename
2060 (propertize i
'face anything-c-files-face1
)
2063 (;; Closed directories.
2064 (eq t
(car (file-attributes i
)))
2065 (cons (anything-c-prefix-filename
2066 (propertize i
'face anything-c-files-face1
)
2069 ( ;; Open Symlinks directories.
2070 (and (stringp (car (file-attributes i
)))
2071 (file-directory-p i
) (get-buffer af
))
2072 (cons (anything-c-prefix-filename
2073 (propertize i
'face
'anything-dired-symlink-face
2074 'help-echo
(file-truename i
)) "open.xpm")
2076 ( ;; Closed Symlinks directories.
2077 (and (stringp (car (file-attributes i
))) (file-directory-p i
))
2078 (cons (anything-c-prefix-filename
2079 (propertize i
'face
'anything-dired-symlink-face
2080 'help-echo
(file-truename i
)) "close.xpm")
2082 ( ;; Files symlinks.
2083 (stringp (car (file-attributes i
)))
2084 (cons (anything-c-prefix-filename
2085 (propertize i
'face
'anything-dired-symlink-face
2086 'help-echo
(file-truename i
))
2090 (defun anything-find-files-action-transformer (actions candidate
)
2091 "Action transformer for `anything-c-source-find-files'."
2092 (cond ((with-current-buffer anything-current-buffer
(eq major-mode
'message-mode
))
2093 (append actions
'(("Gnus attach file(s)" . anything-ff-gnus-attach-files
))))
2094 ((string-match (image-file-name-regexp) candidate
)
2095 (append actions
'(("Rotate image right" . anything-ff-rotate-image-right
)
2096 ("Rotate image left" . anything-ff-rotate-image-left
))))
2097 ((string-match "\.el$" (anything-aif (anything-marked-candidates)
2098 (car it
) candidate
))
2099 (append actions
'(("Byte compile lisp file(s) `C-u to load'"
2100 . anything-find-files-byte-compile
)
2101 ("Load File(s)" . load-file
))))
2104 (defun anything-ff-gnus-attach-files (candidate)
2105 "Run `gnus-dired-attach' on `anything-marked-candidates' or CANDIDATE."
2106 (let ((flist (anything-marked-candidates)))
2107 (gnus-dired-attach flist
)))
2109 (defun anything-ff-rotate-current-image1 (file &optional num-arg
)
2110 "Rotate current image at NUM-ARG degrees."
2111 (if (executable-find "mogrify")
2113 (shell-command (format "mogrify -rotate %s %s" (or num-arg
90) file
))
2114 (when (buffer-live-p image-dired-display-image-buffer
)
2115 (kill-buffer image-dired-display-image-buffer
))
2116 (image-dired-display-image file
)
2118 (display-buffer (get-buffer image-dired-display-image-buffer
)))
2119 (error "mogrify not found")))
2121 (defun anything-ff-rotate-image-left (candidate)
2122 "Rotate image file CANDIDATE left.
2123 This affect directly file CANDIDATE."
2124 (anything-ff-rotate-current-image1 candidate -
90))
2126 (defun anything-ff-rotate-image-right (candidate)
2127 "Rotate image file CANDIDATE right.
2128 This affect directly file CANDIDATE."
2129 (anything-ff-rotate-current-image1 candidate
))
2131 (defun anything-find-files-persistent-action (candidate)
2132 "Open subtree CANDIDATE without quitting anything.
2133 If CANDIDATE is not a directory expand CANDIDATE filename.
2134 If CANDIDATE is alone, open file CANDIDATE filename.
2136 First hit on C-z expand CANDIDATE second hit open file.
2137 If a prefix arg is given or `anything-follow-mode' is on open file."
2138 (let ((follow (buffer-local-value
2139 'anything-follow-mode
2140 (get-buffer-create anything-buffer
))))
2141 (flet ((insert-in-minibuffer (fname)
2142 (with-selected-window (minibuffer-window)
2144 (delete-minibuffer-contents)
2145 (set-text-properties 0 (length fname
) nil fname
)
2147 (cond ((and (file-directory-p candidate
) (file-symlink-p candidate
))
2148 (insert-in-minibuffer (file-name-as-directory
2150 (expand-file-name candidate
)))))
2151 ((file-directory-p candidate
)
2152 (insert-in-minibuffer (file-name-as-directory
2153 (expand-file-name candidate
))))
2154 ((file-symlink-p candidate
)
2155 (insert-in-minibuffer (file-truename candidate
)))
2157 ;; First hit on C-z expand CANDIDATE second hit open file.
2158 ;; If a prefix arg is given or `anything-follow-mode' is on open file.
2159 (let ((new-pattern (anything-get-selection))
2160 (num-lines-buf (with-current-buffer anything-buffer
2161 (count-lines (point-min) (point-max)))))
2162 (if (and (> num-lines-buf
3) (not current-prefix-arg
) (not follow
))
2163 (insert-in-minibuffer new-pattern
)
2164 (if (string-match (image-file-name-regexp) candidate
)
2166 (when (buffer-live-p image-dired-display-image-buffer
)
2167 (kill-buffer image-dired-display-image-buffer
))
2168 (image-dired-display-image candidate
)
2170 (display-buffer image-dired-display-image-buffer
))
2171 (find-file candidate
)))))))))
2173 (defun anything-c-insert-file-name-completion-at-point (candidate)
2174 "Insert file name completion at point."
2175 (if buffer-read-only
2176 (error "Error: Buffer `%s' is read-only" (buffer-name))
2177 (let* ((end (point))
2178 (guess (thing-at-point 'filename
))
2179 (full-path-p (or (string-match (concat "^" (getenv "HOME")) guess
)
2180 (string-match "^[^\~]" guess
))))
2181 (set-text-properties 0 (length candidate
) nil candidate
)
2182 (if (and guess
(not (string= guess
"")) (string-match "^~\\|/.*" guess
))
2184 (search-backward guess
(- (point) (length guess
)))
2185 (delete-region (point) end
)
2187 (insert (expand-file-name candidate
))
2188 (insert (abbreviate-file-name candidate
))))
2189 (error "Aborting completion: No valid file name at point")))))
2192 (defun anything-find-files (&optional fname
)
2193 "Preconfigured `anything' for anything implementation of `find-file'.
2194 In non--interactive use an argument FNAME can be used.
2195 This is the starting point for nearly all actions you can do on files."
2197 (let ((anything-mp-highlight-delay nil
))
2198 (anything :sources
'anything-c-source-find-files
2199 :input
(or (and fname
(expand-file-name fname
))
2200 (anything-find-files-input
2202 (thing-at-point 'filename
)))
2203 :prompt
"Find Files or Url: "
2204 :buffer
"*Anything Find Files*")))
2206 (defun anything-c-current-directory ()
2207 "Return current-directory name at point.
2208 Useful in dired buffers when there is inserted subdirs."
2209 (if (eq major-mode
'dired-mode
)
2210 (dired-current-directory)
2213 (defun anything-find-files-input (fap tap
)
2214 "Default input of `anything-find-files'."
2215 (let* ((def-dir (anything-c-current-directory))
2216 (lib (anything-find-library-at-point))
2217 (file-p (and fap
(file-exists-p fap
)
2219 (file-name-directory (expand-file-name tap def-dir
)))))
2221 (file-p (expand-file-name tap def-dir
))
2223 (or input
(expand-file-name def-dir
))))
2225 (defun anything-find-library-at-point ()
2226 "Try to find library path at point.
2227 Find inside `require' and `declare-function' sexp."
2228 (require 'find-func
)
2229 (let* ((beg-sexp (save-excursion (search-backward "(" (point-at-bol) t
)))
2230 (end-sexp (save-excursion (search-forward ")" (point-at-eol) t
)))
2231 (sexp (and beg-sexp end-sexp
2232 (buffer-substring-no-properties
2233 (1+ beg-sexp
) (1- end-sexp
)))))
2235 (cond ((and sexp
(string-match "require \'.+[^)]" sexp
))
2237 (replace-regexp-in-string
2239 ;; If require use third arg, ignore it,
2240 ;; always use library path found in `load-path'.
2241 (second (split-string (match-string 0 sexp
))))))
2242 ((and sexp
(string-match-p "^declare-function" sexp
))
2244 (replace-regexp-in-string
2246 (third (split-string sexp
)))))
2249 ;;; Anything completion for `write-file'.==> C-x C-w
2250 (defvar anything-c-source-write-file
2251 `((name .
,(concat "Write File" anything-c-find-files-doc-header
))
2252 ;; It is needed for filenames with capital letters
2254 (candidates . anything-find-files-get-candidates
)
2255 (filtered-candidate-transformer anything-c-find-files-transformer
)
2256 (persistent-action . anything-find-files-persistent-action
)
2257 (persistent-help .
"Expand Candidate")
2260 (("Write File" .
(lambda (candidate)
2261 (write-file candidate
'confirm
)))))))
2264 (defun anything-write-file ()
2265 "Preconfigured `anything' providing completion for `write-file'."
2267 (anything 'anything-c-source-write-file
2268 (expand-file-name default-directory
)
2269 "Write buffer to file: " nil nil
"*Anything write file*"))
2271 ;;; Anything completion for `insert-file'.==> C-x i
2272 (defvar anything-c-source-insert-file
2273 `((name .
,(concat "Insert File" anything-c-find-files-doc-header
))
2274 ;; It is needed for filenames with capital letters
2276 (candidates . anything-find-files-get-candidates
)
2277 (filtered-candidate-transformer anything-c-find-files-transformer
)
2278 (persistent-action . anything-find-files-persistent-action
)
2279 (persistent-help .
"Expand Candidate")
2282 (("Insert File" .
(lambda (candidate)
2283 (when (y-or-n-p (format "Really insert %s in %s "
2284 candidate anything-current-buffer
))
2285 (insert-file-contents candidate
))))))))
2288 (defun anything-insert-file ()
2289 "Preconfigured `anything' providing completion for `insert-file'."
2291 (anything 'anything-c-source-insert-file
2292 (expand-file-name default-directory
)
2293 "Insert file: " nil nil
"*Anything insert file*"))
2295 ;;; Anything completion for copy, rename and (rel)sym/hard/link files from dired.
2296 (defvar anything-c-source-copy-files
2297 `((name .
,(concat "Copy Files" anything-c-find-files-doc-header
))
2298 ;; It is needed for filenames with capital letters
2300 (candidates . anything-find-files-get-candidates
)
2301 (filtered-candidate-transformer anything-c-find-files-transformer
)
2302 (persistent-action . anything-find-files-persistent-action
)
2303 (persistent-help .
"Expand Candidate")
2307 .
(lambda (candidate)
2308 (anything-dired-action candidate
:action
'copy
)))
2310 .
(lambda (candidate)
2311 (anything-dired-action candidate
:action
'copy
:follow t
)))))))
2314 (defvar anything-c-source-rename-files
2315 `((name .
,(concat "Rename Files" anything-c-find-files-doc-header
))
2316 ;; It is needed for filenames with capital letters
2318 (candidates . anything-find-files-get-candidates
)
2319 (filtered-candidate-transformer anything-c-find-files-transformer
)
2320 (persistent-action . anything-find-files-persistent-action
)
2321 (persistent-help .
"Expand Candidate")
2325 .
(lambda (candidate)
2326 (anything-dired-action candidate
:action
'rename
)))
2327 ("Rename and Follow"
2328 .
(lambda (candidate)
2329 (anything-dired-action candidate
:action
'rename
:follow t
)))))))
2331 (defvar anything-c-source-symlink-files
2332 `((name .
,(concat "Symlink Files" anything-c-find-files-doc-header
))
2333 ;; It is needed for filenames with capital letters
2335 (candidates . anything-find-files-get-candidates
)
2336 (filtered-candidate-transformer anything-c-find-files-transformer
)
2337 (persistent-action . anything-find-files-persistent-action
)
2338 (persistent-help .
"Expand Candidate")
2342 .
(lambda (candidate)
2343 (anything-dired-action candidate
:action
'symlink
)))
2345 .
(lambda (candidate)
2346 (anything-dired-action candidate
:action
'relsymlink
)))))))
2349 (defvar anything-c-source-hardlink-files
2350 `((name .
,(concat "Hardlink Files" anything-c-find-files-doc-header
))
2351 ;; It is needed for filenames with capital letters
2353 (candidates . anything-find-files-get-candidates
)
2354 (filtered-candidate-transformer anything-c-find-files-transformer
)
2355 (persistent-action . anything-find-files-persistent-action
)
2356 (persistent-help .
"Expand Candidate")
2360 .
(lambda (candidate)
2361 (anything-dired-action candidate
:action
'hardlink
)))))))
2364 (defun* anything-dired-action
(candidate &key action follow
(files (dired-get-marked-files)))
2365 "Copy, rename or symlink file at point or marked files in dired to CANDIDATE.
2366 ACTION is a key that can be one of 'copy, 'rename, 'symlink, 'relsymlink."
2367 (let ((fn (case action
2368 ('copy
'dired-copy-file
)
2369 ('rename
'dired-rename-file
)
2370 ('symlink
'make-symbolic-link
)
2371 ('relsymlink
'dired-make-relative-symlink
)
2372 ('hardlink
'dired-hardlink
)))
2373 (marker (case action
2374 ((copy rename
) dired-keep-marker-copy
)
2375 ('symlink dired-keep-marker-symlink
)
2376 ('relsymlink dired-keep-marker-relsymlink
)
2377 ('hardlink dired-keep-marker-hardlink
))))
2379 fn
(symbol-name action
) files
2380 (if (file-directory-p candidate
)
2381 ;; When CANDIDATE is a directory, build file-name in this directory.
2382 ;; Else we use CANDIDATE.
2384 (expand-file-name (file-name-nondirectory from
) candidate
))
2385 #'(lambda (from) candidate
))
2388 (let* ((moved-flist (anything-get-dest-fnames-from-list files candidate
))
2389 (fname (car moved-flist
)))
2392 (setq anything-ff-cand-to-mark moved-flist
)
2393 (anything-find-files candidate
))
2394 (setq anything-ff-cand-to-mark nil
))))))
2397 (defvar anything-ff-cand-to-mark nil
)
2399 (defun anything-get-dest-fnames-from-list (flist dest-cand
)
2400 "Transform filenames of FLIST to abs of DEST-CAND."
2402 with dest
= (expand-file-name dest-cand
)
2404 for basename-src
= (if (file-directory-p src
)
2406 (directory-file-name src
)
2407 (file-name-directory src
))
2408 (file-name-nondirectory src
))
2409 for fname
= (if (file-directory-p dest
)
2410 (concat (file-name-as-directory dest
)
2415 (defun anything-c-maybe-mark-candidates ()
2416 "Mark all candidates of list `anything-ff-cand-to-mark'."
2417 (when (and (string= (assoc-default 'name
(anything-get-current-source))
2418 (assoc-default 'name anything-c-source-find-files
))
2419 anything-ff-cand-to-mark
)
2420 (with-anything-window
2421 (while anything-ff-cand-to-mark
2422 (if (search-forward (car anything-ff-cand-to-mark
) (point-at-eol) t
)
2424 (call-interactively 'anything-toggle-visible-mark
)
2425 (setq anything-ff-cand-to-mark
(cdr anything-ff-cand-to-mark
)))
2426 (call-interactively 'anything-next-line
)))
2427 (unless (anything-this-visible-mark)
2428 (call-interactively 'anything-prev-visible-mark
)))))
2430 (add-hook 'anything-after-update-hook
#'anything-c-maybe-mark-candidates
)
2433 (defun* anything-dired-do-action-on-file
(&key action
)
2434 (let* ((files (dired-get-marked-files))
2435 (len (length files
))
2436 (fname (if (> len
1)
2437 (format "* %d Files" len
)
2439 (source (case action
2440 ('copy
'anything-c-source-copy-files
)
2441 ('rename
'anything-c-source-rename-files
)
2442 ('symlink
'anything-c-source-symlink-files
)
2443 ('hardlink
'anything-c-source-hardlink-files
)))
2444 (prompt-fm (case action
2445 ('copy
"Copy %s to: ")
2446 ('rename
"Rename %s to: ")
2447 ('symlink
"Symlink %s to: ")
2448 ('hardlink
"Hardlink %s to: ")))
2449 (buffer (case action
2450 ('copy
"*Anything Copy Files*")
2451 ('rename
"*Anything Rename Files*")
2452 ('symlink
"*Anything Symlink Files*")
2453 ('hardlink
"*Anything Hardlink Files*"))))
2455 (or (dired-dwim-target-directory)
2456 (expand-file-name (anything-c-current-directory)))
2457 (format prompt-fm fname
) nil nil buffer
)))
2461 (defun anything-dired-rename-file ()
2462 "Preconfigured `anything' to rename files from dired."
2464 (anything-dired-do-action-on-file :action
'rename
))
2467 (defun anything-dired-copy-file ()
2468 "Preconfigured `anything' to copy files from dired."
2470 (anything-dired-do-action-on-file :action
'copy
))
2473 (defun anything-dired-symlink-file ()
2474 "Preconfigured `anything' to symlink files from dired."
2476 (anything-dired-do-action-on-file :action
'symlink
))
2479 (defun anything-dired-hardlink-file ()
2480 "Preconfigured `anything' to hardlink files from dired."
2482 (anything-dired-do-action-on-file :action
'hardlink
))
2484 (defvar anything-dired-bindings nil
)
2486 (defun anything-dired-bindings (&optional arg
)
2487 "Replace usual dired commands `C' and `R' by anything ones.
2488 When call interactively toggle dired bindings and anything bindings.
2489 When call non--interactively with arg > 0, enable anything bindings.
2490 You can put (anything-dired-binding 1) in init file to enable anything bindings."
2492 (if (or (and arg
(> arg
0)) (not anything-dired-bindings
))
2493 ;; Replace dired bindings.
2495 (substitute-key-definition
2496 'dired-do-copy
'anything-dired-copy-file dired-mode-map
)
2497 (substitute-key-definition
2498 'dired-do-rename
'anything-dired-rename-file dired-mode-map
)
2499 (substitute-key-definition
2500 'dired-do-symlink
'anything-dired-symlink-file dired-mode-map
)
2501 (substitute-key-definition
2502 'dired-do-hardlink
'anything-dired-hardlink-file dired-mode-map
)
2503 (setq anything-dired-bindings t
))
2504 ;; Replace anything bindings.
2505 (substitute-key-definition
2506 'anything-dired-copy-file
'dired-do-copy dired-mode-map
)
2507 (substitute-key-definition
2508 'anything-dired-rename-file
'dired-do-rename dired-mode-map
)
2509 (substitute-key-definition
2510 'anything-dired-symlink-file
'dired-do-symlink dired-mode-map
)
2511 (substitute-key-definition
2512 'anything-dired-hardlink-file
'dired-do-hardlink dired-mode-map
)
2513 (setq anything-dired-bindings nil
)))
2515 (defun* anything-c-read-file-name
(prompt
2517 (initial-input (expand-file-name default-directory
))
2518 (buffer "*Anything Completions*")
2520 (marked-candidates nil
)
2521 (persistent-action 'anything-find-files-persistent-action
)
2522 (persistent-help "Hit1 Expand Candidate, Hit2 or (C-u) Find file"))
2523 "Anything `read-file-name' emulation.
2524 INITIAL-INPUT is a valid path, TEST is a predicate that take one arg."
2525 (when (get-buffer anything-action-buffer
)
2526 (kill-buffer anything-action-buffer
))
2527 (let ((anything-mp-highlight-delay nil
))
2528 (flet ((action-fn (candidate)
2529 (if marked-candidates
2530 (anything-marked-candidates)
2531 (identity candidate
))))
2534 `((name .
,(concat "Read file name" anything-c-find-files-doc-header
))
2535 ;; It is needed for filenames with capital letters
2537 (candidates .
(lambda ()
2539 (loop with seq
= (anything-find-files-get-candidates)
2540 for fname in seq when
(funcall test fname
)
2542 (anything-find-files-get-candidates))))
2543 (filtered-candidate-transformer anything-c-find-files-transformer
)
2544 (persistent-action .
,persistent-action
)
2545 (persistent-help .
,persistent-help
)
2547 (action .
,'action-fn
))
2548 :input initial-input
2555 (defvar anything-c-source-file-cache-initialized nil
)
2557 (defvar anything-c-file-cache-files nil
)
2559 (defvar anything-c-source-file-cache
2560 '((name .
"File Cache")
2563 (require 'filecache nil t
)
2564 (unless anything-c-source-file-cache-initialized
2565 (setq anything-c-file-cache-files
2566 (loop for item in file-cache-alist append
2567 (destructuring-bind (base &rest dirs
) item
2568 (loop for dir in dirs collect
2569 (concat dir base
)))))
2570 (defadvice file-cache-add-file
(after file-cache-list activate
)
2571 (add-to-list 'anything-c-file-cache-files
(expand-file-name file
)))
2572 (setq anything-c-source-file-cache-initialized t
))))
2573 (candidates . anything-c-file-cache-files
)
2574 (match anything-c-match-on-file-name
2575 anything-c-match-on-directory-name
)
2577 ;; (anything 'anything-c-source-file-cache)
2580 ;; NOTE for WINDOZE users:
2581 ;; You have to install Everything with his command line interface here:
2582 ;; http://www.voidtools.com/download.php
2584 (defvar anything-c-locate-command
2586 ('gnu
/linux
"locate -i -r %s")
2587 ('berkeley-unix
"locate -i %s")
2588 ('windows-nt
"es -i -r %s")
2590 "A list of arguments for locate program.
2591 The \"-r\" option must be the last option.")
2593 (defun anything-c-locate-init ()
2594 "Initialize async locate process for `anything-c-source-locate'."
2596 (start-process-shell-command "locate-process" nil
2597 (format anything-c-locate-command
2599 (set-process-sentinel (get-process "locate-process")
2600 #'(lambda (process event
)
2601 (when (string= event
"finished\n")
2602 (with-anything-window
2603 (anything-update-move-first-line)))))))
2605 (defvar anything-c-source-locate
2607 (candidates . anything-c-locate-init
)
2609 (requires-pattern .
3)
2611 "Find files matching the current input pattern with locate.")
2613 ;; (anything 'anything-c-source-locate)
2616 (defvar anything-c-grep-default-command
"grep -niH -e %s %s %s")
2617 (defvar anything-c-grep-default-function
'anything-c-grep-init
)
2619 (defun anything-c-grep-init (only-files)
2620 "Start an asynchronous grep process in ONLY-FILES list."
2621 (kill-local-variable 'mode-line-format
)
2622 (setq mode-line-format
2623 '(" " mode-line-buffer-identification
" "
2624 (line-number-mode "%l") " "
2625 (:eval
(propertize "(Grep Process Running) "
2626 'face
'((:foreground
"red"))))))
2628 (start-process-shell-command
2630 (format anything-c-grep-default-command
2631 (shell-quote-argument anything-pattern
)
2635 (concat "--exclude=" (shell-quote-argument x
)))
2636 grep-find-ignored-files
" ")))
2637 (set-process-sentinel
2638 (get-process "grep-process")
2639 #'(lambda (process event
)
2640 (when (string= event
"finished\n")
2641 (with-anything-window
2642 (anything-update-move-first-line)))))))
2644 (defun anything-c-grep-action (candidate &optional where
)
2645 "Define a default action for `anything-do-grep' on CANDIDATE.
2646 WHERE can be one of other-window, elscreen, other-frame."
2647 (let* ((split (split-string candidate
":"))
2648 (lineno (string-to-number (if (eq system-type
'windows-nt
)
2651 (fname (if (eq system-type
'windows-nt
)
2652 (concat (car split
) ":" (second split
))
2655 (other-window (find-file-other-window fname
))
2656 (elscreen (anything-elscreen-find-file fname
))
2657 (other-frame (find-file-other-frame fname
))
2658 (t (find-file fname
)))
2660 (anything-goto-line lineno
)))
2662 (defun anything-c-grep-persistent-action (candidate)
2663 (anything-c-grep-action candidate
)
2664 (anything-match-line-color-current-line))
2667 (defun anything-do-grep (only)
2668 "Preconfigured anything for grep.
2669 Contrarily to Emacs `grep' no default directory is given, but
2670 the full path of candidates in ONLY.
2671 That allow to grep different files not only in `default-directory' but anywhere
2672 by marking them (C-<SPACE>). If one or more directory is selected
2673 grep will search in all files of these directories
2674 like -d recursive, or -r would do.
2675 You can use also wildcard in the base name of candidate."
2677 (anything-c-read-file-name "Search in file(s): "
2678 :marked-candidates t
)))
2679 (let ((anything-compile-source-functions
2680 ;; rule out anything-match-plugin because the input is one regexp.
2681 (delq 'anything-compile-source--match-plugin
2682 (copy-sequence anything-compile-source-functions
))))
2683 ;; If one or more candidate is a directory, search in all files
2684 ;; of this candidate e.g /home/user/directory/*
2685 ;; We need here to expand wildcards to support crap windows filenames
2686 ;; as grep don't accept quoted wildcards (e.g "dir/*.el").
2689 for args
= (replace-regexp-in-string
2690 "grep" "" anything-c-grep-default-command
)
2692 (cond ((and (file-directory-p i
)
2693 (string-match "r\\|recurse" args
))
2694 (list (file-name-as-directory
2695 (replace-regexp-in-string "[.]$" "" i
))))
2696 ((file-directory-p i
)
2697 (file-expand-wildcards (concat (file-name-as-directory i
) "*") t
))
2698 ((string-match "\*" i
) (file-expand-wildcards i t
))
2699 (t (list i
))) into of
2701 (mapconcat #'(lambda (x) (shell-quote-argument x
)) of
" ")))
2702 ;; When called as action from an other source e.g *-find-files
2703 ;; we have to kill action buffer.
2704 (when (get-buffer anything-action-buffer
)
2705 (kill-buffer anything-action-buffer
))
2706 (define-key anything-map
(kbd "M-<down>") #'anything-c-grep-next-or-prec-file
)
2707 (define-key anything-map
(kbd "M-<up>") #'anything-c-grep-precedent-file
)
2710 `(((name .
"Grep (M-up/down - next/prec file)")
2712 ;; Load `grep-find-ignored-files'.
2714 (candidates .
(lambda ()
2715 (funcall anything-c-grep-default-function only
)))
2716 (filtered-candidate-transformer anything-c-grep-cand-transformer
)
2719 `(("Find File" . anything-c-grep-action
)
2720 ("Find file other window"
2721 .
(lambda (candidate)
2722 (anything-c-grep-action candidate
'other-window
)))
2723 ,(and (locate-library "elscreen")
2724 '("Find file in Elscreen"
2725 .
(lambda (candidate)
2726 (anything-c-grep-action candidate
'elscreen
))))
2727 ("Find file other frame"
2728 .
(lambda (candidate)
2729 (anything-c-grep-action candidate
'other-frame
))))))
2730 (persistent-action .
(lambda (candidate)
2731 (anything-c-grep-persistent-action
2733 (requires-pattern .
3)
2735 :buffer
"*anything grep*")))
2737 (defun anything-c-grep-cand-transformer (candidates sources
)
2738 "Filtered candidate transformer function for `anything-do-grep'."
2739 (loop for i in candidates
2740 for split
= (and i
(split-string i
":"))
2741 for fname
= (and split
2742 (if (eq system-type
'windows-nt
)
2743 (concat (car split
) ":" (second split
))
2745 for lineno
= (and split
2746 (if (eq system-type
'windows-nt
)
2749 for str
= (and split
2750 (if (eq system-type
'windows-nt
)
2753 when
(and split fname lineno str
)
2754 collect
(cons (concat (propertize (file-name-nondirectory fname
)
2755 'face
'((:foreground
"BlueViolet"))
2759 'face
'((:foreground
"Darkorange1")))
2765 (defun anything-c-grep-precedent-file ()
2766 "Go to precedent file in `anything-do-grep'."
2768 (anything-c-grep-next-or-prec-file -
1))
2771 (defun* anything-c-grep-next-or-prec-file
(&optional
(n 1))
2772 "Go to next or precedent candidate file in anything grep buffer."
2774 (let ((cur-source (assoc-default 'name
(anything-get-current-source))))
2775 (with-anything-window
2776 (if (equal cur-source
"Grep (M-up/down - next/prec file)")
2777 (let* ((current-line-list (split-string
2780 (point-at-eol)) ":"))
2781 (current-fname (nth 0 current-line-list
))
2782 (fn-b-o-f (if (eq n
1) 'eobp
'bobp
))) ; func back or forward
2784 (while (not (funcall fn-b-o-f
))
2787 (when (not (search-forward current-fname
(point-at-eol) t
))
2788 (anything-mark-current-line)
2789 (throw 'break nil
))))
2792 (re-search-backward ".")
2794 (anything-mark-current-line))
2798 (anything-mark-current-line))))
2800 (anything-next-line)
2801 (anything-previous-line))))))
2804 (defvar anything-c-source-recentf
2805 '((name .
"Recentf")
2808 (or recentf-mode
(recentf-mode 1))
2809 ;; Big value empowers anything/recentf
2810 (when (and (numberp recentf-max-saved-items
)
2811 (<= recentf-max-saved-items
20))
2812 (setq recentf-max-saved-items
500))))
2813 (candidates . recentf-list
)
2814 (match anything-c-match-on-file-name
2815 anything-c-match-on-directory-name
)
2817 "See (info \"(emacs)File Conveniences\").
2818 if `recentf-max-saved-items' is too small, set it to 500.")
2819 ;; (anything 'anything-c-source-recentf)
2822 (eval-when-compile (require 'ffap
))
2823 (defvar anything-c-source-ffap-guesser
2824 '((name .
"File at point")
2825 (init .
(lambda () (require 'ffap
)))
2826 (candidates .
(lambda ()
2828 (with-current-buffer anything-current-buffer
2832 ;; (anything 'anything-c-source-ffap-guesser)
2834 ;;; ffap with line number
2835 (defun anything-c-ffap-file-line-at-point ()
2836 "Get (FILENAME . LINENO) at point."
2837 (anything-aif (let (ffap-alist) (ffap-file-at-point))
2840 (when (and (search-forward it nil t
)
2841 (looking-at ":\\([0-9]+\\)"))
2842 (cons it
(string-to-number (match-string 1)))))))
2844 (defvar anything-c-ffap-line-location nil
2845 "(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
2846 It is cleared after jumping line.")
2848 (defun anything-c-ffap-line-candidates ()
2849 (with-current-buffer anything-current-buffer
2850 (setq anything-c-ffap-line-location
(anything-c-ffap-file-line-at-point)))
2851 (when anything-c-ffap-line-location
2852 (destructuring-bind (file . line
) anything-c-ffap-line-location
2853 (list (cons (format "%s (line %d)" file line
) file
)))))
2855 ;;; Goto line after opening file by `anything-c-source-ffap-line'.
2856 (defun anything-c-ffap-line-goto-line ()
2857 (when (car anything-c-ffap-line-location
)
2860 (with-selected-window
2862 (get-file-buffer (car anything-c-ffap-line-location
)))
2863 (anything-goto-line (cdr anything-c-ffap-line-location
)))))))
2864 (add-hook 'anything-after-action-hook
'anything-c-ffap-line-goto-line
)
2865 (add-hook 'anything-after-persistent-action-hook
'anything-c-ffap-line-goto-line
)
2867 (defvar anything-c-source-ffap-line
2868 '((name .
"File/Lineno at point")
2869 (init .
(lambda () (require 'ffap
)))
2870 (candidates . anything-c-ffap-line-candidates
)
2872 ;; (anything 'anything-c-source-ffap-line)
2874 ;;; list of files gleaned from every dired buffer
2875 (defun anything-c-files-in-all-dired-candidates ()
2879 (cond ((listp dir
) ;filelist
2881 ((equal "" (file-name-nondirectory dir
)) ;dir
2882 (directory-files dir t
))
2884 (file-expand-wildcards dir t
))))
2886 (mapcar (lambda (buf)
2888 (when (eq major-mode
'dired-mode
)
2889 (if (consp dired-directory
)
2890 (cdr dired-directory
) ;filelist
2891 dired-directory
))) ;dir or wildcard
2893 ;; (dired '("~/" "~/.emacs-custom.el" "~/.emacs.bmk"))
2895 (defvar anything-c-source-files-in-all-dired
2896 '((name .
"Files in all dired buffer.")
2897 (candidates . anything-c-files-in-all-dired-candidates
)
2899 ;; (anything 'anything-c-source-files-in-all-dired)
2901 (defcustom anything-c-filelist-file-name nil
2902 "*Filename of file list.
2903 Accept a list of string for multiple files.
2905 This file tend to be very large (> 100MB) and recommend to be in ramdisk for speed.
2906 File list is created by make-filelist.rb script.
2909 ruby make-filelist.rb > /tmp/all.filelist
2912 ;; Assume that /tmp is ramdisk or tmpfs
2913 (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")
2914 (setq anything-c-filelist-file-name \"/tmp/all.filelist\")
2917 :group
'anything-config
)
2918 (defvar anything-c-source-filelist
2919 '((name .
"FileList")
2920 (grep-candidates . anything-c-filelist-file-name
)
2921 (candidate-number-limit .
200)
2922 (requires-pattern .
4)
2926 (defun anything-filelist ()
2927 "Preconfigured `anything' to open files instantly."
2929 (anything-other-buffer 'anything-c-source-filelist
"*anything file list*"))
2932 (defun anything-filelist+ ()
2933 "Preconfigured `anything' to open files/buffers/bookmarks instantly.
2935 This is a replacement for `anything-for-files'."
2937 (anything-other-buffer
2938 '(anything-c-source-ffap-line
2939 anything-c-source-ffap-guesser
2940 anything-c-source-buffers
+
2941 anything-c-source-recentf
2942 anything-c-source-bookmarks
2943 anything-c-source-file-cache
2944 anything-c-source-filelist
)
2945 "*anything file list*"))
2950 (defvar anything-c-info-pages nil
2951 "All info pages on system.
2952 Will be calculated the first time you invoke anything with this
2955 (defvar anything-c-source-info-pages
2956 `((name .
"Info Pages")
2959 (if anything-c-info-pages
2960 anything-c-info-pages
2961 (setq anything-c-info-pages
2962 (save-window-excursion
2965 (Info-find-node "dir" "top")
2966 (goto-char (point-min))
2967 (let ((info-topic-regexp "\\* +\\([^:]+: ([^)]+)[^.]*\\)\\.")
2969 (while (re-search-forward info-topic-regexp nil t
)
2970 (add-to-list 'topics
(match-string-no-properties 1)))
2971 (goto-char (point-min))
2974 (action .
(("Show with Info" .
(lambda (node-str)
2975 (info (replace-regexp-in-string
2976 "^[^:]+: " "" node-str
))))))
2977 (requires-pattern .
2)))
2978 ;; (anything 'anything-c-source-info-pages)
2981 ;;; Use info-index plug-in. Note that `name' attribute is
2982 ;;; not needed but `anything-c-insert-summary' uses it.
2984 (defvar anything-c-source-info-elisp
2985 '((name .
"Info index: elisp")
2986 (info-index .
"elisp")))
2987 ;; (anything 'anything-c-source-info-elisp)
2990 (defvar anything-c-source-info-cl
2991 '((name .
"Info index: cl")
2992 (info-index .
"cl")))
2993 ;; (anything 'anything-c-source-info-cl)
2996 (defvar anything-c-source-info-org
2997 '((name .
"Info index: org")
2998 (info-index .
"org")))
2999 ;; (anything 'anything-c-source-info-org)
3001 ;; Info Index ratpoison
3002 (defvar anything-c-source-info-ratpoison
3003 '((name .
"Info index: ratpoison")
3004 (info-index .
"ratpoison")))
3005 ;; (anything 'anything-c-source-info-ratpoison)
3008 (defvar anything-c-source-info-zsh
3009 '((name .
"Info index: zsh")
3010 (info-index .
"zsh")))
3011 ;; (anything 'anything-c-source-info-zsh)
3014 (defvar anything-c-source-info-bash
3015 '((name .
"Info index: bash")
3016 (info-index .
"bash")))
3017 ;; (anything 'anything-c-source-info-bash)
3019 ;; Info Index coreutils
3020 (defvar anything-c-source-info-coreutils
3021 '((name .
"Info index: coreutils")
3022 (info-index .
"coreutils")))
3023 ;; (anything 'anything-c-source-info-coreutils)
3025 ;; Info Index fileutils
3026 (defvar anything-c-source-info-fileutils
3027 '((name .
"Info index: fileutils")
3028 (info-index .
"fileutils")))
3029 ;; (anything 'anything-c-source-info-fileutils)
3032 (defvar anything-c-source-info-find
3033 '((name .
"Info index: find")
3034 (info-index .
"find")))
3035 ;; (anything 'anything-c-source-info-find)
3037 ;; Info Index sh-utils
3038 (defvar anything-c-source-info-sh-utils
3039 '((name .
"Info index: sh-utils")
3040 (info-index .
"sh-utils")))
3041 ;; (anything 'anything-c-source-info-sh-utils)
3043 ;; Info Index textutils
3044 (defvar anything-c-source-info-textutils
3045 '((name .
"Info index: textutils")
3046 (info-index .
"textutils")))
3047 ;; (anything 'anything-c-source-info-textutils)
3050 (defvar anything-c-source-info-libc
3051 '((name .
"Info index: libc")
3052 (info-index .
"libc")))
3053 ;; (anything 'anything-c-source-info-libc)
3056 (defvar anything-c-source-info-make
3057 '((name .
"Info index: make")
3058 (info-index .
"make")))
3059 ;; (anything 'anything-c-source-info-make)
3061 ;; Info Index automake
3062 (defvar anything-c-source-info-automake
3063 '((name .
"Info index: automake")
3064 (info-index .
"automake")))
3065 ;; (anything 'anything-c-source-info-automake)
3067 ;; Info Index autoconf
3068 (defvar anything-c-source-info-autoconf
3069 '((name .
"Info index: autoconf")
3070 (info-index .
"autoconf")))
3071 ;; (anything 'anything-c-source-info-autoconf)
3073 ;; Info Index emacs-lisp-intro
3074 (defvar anything-c-source-info-emacs-lisp-intro
3075 '((name .
"Info index: emacs-lisp-intro")
3076 (info-index .
"emacs-lisp-intro")))
3077 ;; (anything 'anything-c-source-info-emacs-lisp-intro)
3080 (defvar anything-c-source-info-emacs
3081 '((name .
"Info index: emacs")
3082 (info-index .
"emacs")))
3083 ;; (anything 'anything-c-source-info-emacs)
3086 (defvar anything-c-source-info-elib
3087 '((name .
"Info index: elib")
3088 (info-index .
"elib")))
3089 ;; (anything 'anything-c-source-info-elib)
3092 (defvar anything-c-source-info-eieio
3093 '((name .
"Info index: eieio")
3094 (info-index .
"eieio")))
3095 ;; (anything 'anything-c-source-info-eieio)
3097 ;; Info Index gauche-refe
3098 (defvar anything-c-source-info-gauche-refe
3099 '((name .
"Info index: gauche")
3100 (info-index .
"gauche-refe")))
3101 ;; (anything 'anything-c-source-info-gauche-refe)
3104 (defvar anything-c-source-info-guile
3105 '((name .
"Info index: guile")
3106 (info-index .
"guile")))
3107 ;; (anything 'anything-c-source-info-guile)
3109 ;; Info Index guile-tut
3110 (defvar anything-c-source-info-guile-tut
3111 '((name .
"Info index: guile-tut")
3112 (info-index .
"guile-tut")))
3113 ;; (anything 'anything-c-source-info-guile-tut)
3116 (defvar anything-c-source-info-goops
3117 '((name .
"Info index: goops")
3118 (info-index .
"goops")))
3119 ;; (anything 'anything-c-source-info-goops)
3121 ;; Info Index screen
3122 (defvar anything-c-source-info-screen
3123 '((name .
"Info index: screen")
3124 (info-index .
"screen")
3125 (index-nodes "Concept Index" "Command Index" "Keystroke Index")))
3126 ;; (anything 'anything-c-source-info-screen)
3129 (defvar anything-c-source-info-latex
3130 '((name .
"Info index: latex")
3131 (info-index .
"latex")))
3132 ;; (anything 'anything-c-source-info-latex)
3135 (defvar anything-c-source-info-gawk
3136 '((name .
"Info index: gawk")
3137 (info-index .
"gawk")))
3138 ;; (anything 'anything-c-source-info-gawk)
3141 (defvar anything-c-source-info-sed
3142 '((name .
"Info index: sed")
3143 (info-index .
"sed")))
3144 ;; (anything 'anything-c-source-info-sed)
3147 (defvar anything-c-source-info-m4
3148 '((name .
"Info index: m4")
3149 (info-index .
"m4")))
3150 ;; (anything 'anything-c-source-info-m4)
3153 (defvar anything-c-source-info-wget
3154 '((name .
"Info index: wget")
3155 (info-index .
"wget")))
3156 ;; (anything 'anything-c-source-info-wget)
3158 ;; Info Index binutils
3159 (defvar anything-c-source-info-binutils
3160 '((name .
"Info index: binutils")
3161 (info-index .
"binutils")))
3162 ;; (anything 'anything-c-source-info-binutils)
3165 (defvar anything-c-source-info-as
3166 '((name .
"Info index: as")
3167 (info-index .
"as")))
3168 ;; (anything 'anything-c-source-info-as)
3171 (defvar anything-c-source-info-bfd
3172 '((name .
"Info index: bfd")
3173 (info-index .
"bfd")))
3174 ;; (anything 'anything-c-source-info-bfd)
3177 (defvar anything-c-source-info-gprof
3178 '((name .
"Info index: gprof")
3179 (info-index .
"gprof")))
3180 ;; (anything 'anything-c-source-info-gprof)
3183 (defvar anything-c-source-info-ld
3184 '((name .
"Info index: ld")
3185 (info-index .
"ld")))
3186 ;; (anything 'anything-c-source-info-ld)
3189 (defvar anything-c-source-info-diff
3190 '((name .
"Info index: diff")
3191 (info-index .
"diff")))
3192 ;; (anything 'anything-c-source-info-diff)
3195 (defvar anything-c-source-info-flex
3196 '((name .
"Info index: flex")
3197 (info-index .
"flex")))
3198 ;; (anything 'anything-c-source-info-flex)
3201 (defvar anything-c-source-info-grep
3202 '((name .
"Info index: grep")
3203 (info-index .
"grep")))
3204 ;; (anything 'anything-c-source-info-grep)
3207 (defvar anything-c-source-info-gzip
3208 '((name .
"Info index: gzip")
3209 (info-index .
"gzip")))
3210 ;; (anything 'anything-c-source-info-gzip)
3212 ;; Info Index libtool
3213 (defvar anything-c-source-info-libtool
3214 '((name .
"Info index: libtool")
3215 (info-index .
"libtool")))
3216 ;; (anything 'anything-c-source-info-libtool)
3218 ;; Info Index texinfo
3219 (defvar anything-c-source-info-texinfo
3220 '((name .
"Info index: texinfo")
3221 (info-index .
"texinfo")))
3222 ;; (anything 'anything-c-source-info-texinfo)
3225 (defvar anything-c-source-info-info
3226 '((name .
"Info index: info")
3227 (info-index .
"info")))
3228 ;; (anything 'anything-c-source-info-info)
3231 (defvar anything-c-source-info-gdb
3232 '((name .
"Info index: gdb")
3233 (info-index .
"gdb")))
3234 ;; (anything 'anything-c-source-info-gdb)
3237 (defvar anything-c-source-info-stabs
3238 '((name .
"Info index: stabs")
3239 (info-index .
"stabs")))
3240 ;; (anything 'anything-c-source-info-stabs)
3242 ;; Info Index cvsbook
3243 (defvar anything-c-source-info-cvsbook
3244 '((name .
"Info index: cvsbook")
3245 (info-index .
"cvsbook")))
3246 ;; (anything 'anything-c-source-info-cvsbook)
3249 (defvar anything-c-source-info-cvs
3250 '((name .
"Info index: cvs")
3251 (info-index .
"cvs")))
3252 ;; (anything 'anything-c-source-info-cvs)
3255 (defvar anything-c-source-info-bison
3256 '((name .
"Info index: bison")
3257 (info-index .
"bison")))
3258 ;; (anything 'anything-c-source-info-bison)
3260 ;; Info Index id-utils
3261 (defvar anything-c-source-info-id-utils
3262 '((name .
"Info index: id-utils")
3263 (info-index .
"id-utils")))
3264 ;; (anything 'anything-c-source-info-id-utils)
3266 ;; Info Index global
3267 (defvar anything-c-source-info-global
3268 '((name .
"Info index: global")
3269 (info-index .
"global")))
3270 ;; (anything 'anything-c-source-info-global)
3274 (defvar anything-c-man-pages nil
3275 "All man pages on system.
3276 Will be calculated the first time you invoke anything with this
3279 (defvar anything-c-source-man-pages
3280 `((name .
"Manual Pages")
3281 (candidates .
(lambda ()
3282 (if anything-c-man-pages
3283 anything-c-man-pages
3284 ;; XEmacs doesn't have a woman :)
3285 (setq anything-c-man-pages
3288 (woman-file-name "")
3289 (sort (mapcar 'car woman-topic-all-completions
)
3291 (action ("Show with Woman"
3292 .
(lambda (candidate)
3293 (let ((wfiles (woman-file-name-all-completions candidate
)))
3294 (if (> (length wfiles
) 1)
3295 (woman-find-file (anything-comp-read "ManFile: " wfiles
3297 (woman candidate
))))))
3298 ;; Woman does not work OS X
3299 ;; http://xahlee.org/emacs/modernization_man_page.html
3300 (action-transformer .
(lambda (actions candidate
)
3301 (if (eq system-type
'darwin
)
3302 '(("Show with Man" . man
))
3304 (requires-pattern .
2)))
3305 ;; (anything 'anything-c-source-man-pages)
3308 ;;; Complex command history
3309 (defvar anything-c-source-complex-command-history
3310 '((name .
"Complex Command History")
3311 (candidates .
(lambda () (mapcar 'prin1-to-string command-history
)))
3313 ;; (anything 'anything-c-source-complex-command-history)
3316 (defvar anything-c-source-extended-command-history
3317 '((name .
"Emacs Commands History")
3318 (candidates . extended-command-history
)
3320 ;; (anything 'anything-c-source-extended-command-history)
3323 (defvar anything-c-source-emacs-commands
3324 '((name .
"Emacs Commands")
3325 (candidates .
(lambda ()
3327 (mapatoms (lambda (a)
3329 (push (symbol-name a
)
3331 (sort commands
'string-lessp
))))
3333 (requires-pattern .
2))
3334 "Source for completing and invoking Emacs commands.
3335 A command is a function with interactive spec that can
3336 be invoked with `M-x'.
3338 To get non-interactive functions listed, use
3339 `anything-c-source-emacs-functions'.")
3340 ;; (anything 'anything-c-source-emacs-commands)
3344 ;; Another replacement of `M-x' that act exactly like the
3345 ;; vanilla Emacs one, no problem of windows configuration, prefix args
3346 ;; can be passed before calling `M-x' (e.g C-u M-x..) but also during
3347 ;; anything invocation.
3349 (defun anything-M-x ()
3350 "Preconfigured `anything' for Emacs commands.
3351 It is `anything' replacement of regular `M-x' `execute-extended-command'."
3353 (let* (in-help help-cand
3354 (command (anything-comp-read
3359 :name
"Emacs Commands"
3361 #'(lambda (candidate)
3362 (if (and in-help
(string= candidate help-cand
))
3363 (progn (kill-buffer "*Help*") (setq in-help nil
))
3364 (describe-function (intern candidate
))
3366 (setq help-cand candidate
))
3367 :persistent-help
"Describe this command"
3368 :history extended-command-history
3370 :fc-transformer
'anything-M-x-transformer
))
3371 (history (loop with hist
3372 for i in extended-command-history
3373 for com
= (intern i
)
3374 when
(and (fboundp com
) (not (member i hist
)))
3375 collect i into hist finally return hist
)))
3376 (unless current-prefix-arg
(setq current-prefix-arg anything-current-prefix-arg
))
3377 (call-interactively (intern command
))
3378 (setq extended-command-history
(cons command
(delete command history
)))))
3380 (defun* anything-M-x-get-major-mode-command-alist
(mode-map)
3381 "Return alist of MODE-MAP."
3382 (loop for key being the key-seqs of mode-map using
(key-bindings com
)
3383 for str-key
= (key-description key
)
3384 for ismenu
= (string-match "<menu-bar>" str-key
)
3385 unless ismenu collect
(cons str-key com
)))
3387 (defun anything-get-mode-map-from-mode (mode)
3388 "Guess the mode-map name according to MODE.
3389 Some modes don't use conventional mode-map name
3390 so we need to guess mode-map name. e.g python-mode ==> py-mode-map.
3391 Return nil if no mode-map found."
3393 ;; Start with a conventional mode-map name.
3394 with mode-map
= (intern-soft (format "%s-map" mode
))
3395 with mode-string
= (symbol-name mode
)
3396 with mode-name
= (replace-regexp-in-string "-mode" "" mode-string
)
3397 while
(not mode-map
)
3398 for count downfrom
(length mode-name
)
3399 ;; Return when no result after parsing entire string.
3400 when
(eq count
0) return nil
3401 for sub-name
= (substring mode-name
0 count
)
3402 do
(setq mode-map
(intern-soft (format "%s-map" (concat sub-name
"-mode"))))
3403 finally return mode-map
))
3405 (defun anything-M-x-current-mode-map-alist ()
3406 "Return mode-map alist of current `major-mode'."
3407 (let ((map (anything-get-mode-map-from-mode major-mode
)))
3408 (when (and map
(boundp map
))
3409 (anything-M-x-get-major-mode-command-alist (symbol-value map
)))))
3411 (defface anything-M-x-key-face
'((t (:foreground
"orange" :underline t
)))
3412 "*Face used in anything-M-x to show keybinding."
3415 (defun anything-M-x-transformer (candidates sources
)
3416 "filtered-candidate-transformer to show bindings in emacs commands.
3417 Show global bindings and local bindings according to current `major-mode'."
3419 with local-map
= (with-current-buffer anything-current-buffer
3420 (anything-M-x-current-mode-map-alist))
3422 for cand
= (symbol-name i
)
3423 for local-key
= (car (rassq i local-map
))
3424 for key
= (substitute-command-keys (format "\\[%s]" cand
))
3426 (cons (if (string-match "^M-x" key
)
3429 cand
" (" (propertize local-key
'face
'anything-M-x-key-face
)
3433 cand
" (" (propertize key
'face
'anything-M-x-key-face
) ")"))
3437 (defvar anything-c-source-lacarte
3438 '((name .
"Lacarte")
3439 (init .
(lambda () (require 'lacarte
)))
3440 (candidates .
(lambda () (delete '(nil) (lacarte-get-overall-menu-item-alist))))
3441 (candidate-number-limit .
9999)
3442 (action . anything-c-call-interactively
))
3445 http://www.emacswiki.org/cgi-bin/wiki/download/lacarte.el")
3446 ;; (anything 'anything-c-source-lacarte)
3450 (defvar anything-c-source-emacs-functions
3451 '((name .
"Emacs Functions")
3452 (candidates .
(lambda ()
3454 (mapatoms (lambda (a)
3456 (push (symbol-name a
) commands
))))
3457 (sort commands
'string-lessp
))))
3459 (requires-pattern .
2))
3460 "Source for completing Emacs functions.")
3461 ;; (anything 'anything-c-source-emacs-functions)
3463 ;;; With abbrev expansion
3464 ;;; Similar to my exec-abbrev-cmd.el
3465 ;;; See http://www.tsdh.de/cgi-bin/wiki.pl/exec-abbrev-cmd.el
3466 (defvar anything-c-function-abbrev-regexp nil
3467 "The regexp for `anything-c-source-emacs-functions-with-abbrevs'.
3468 Regexp built from the current `anything-pattern' interpreting it
3470 Only for internal use.")
3472 (defun anything-c-match-function-by-abbrev (candidate)
3473 "Return non-nil if `anything-pattern' is an abbreviation of the function CANDIDATE.
3475 Abbreviations are made by taking the first character from each
3476 word in the function's name, e.g. \"bb\" is an abbrev for
3477 `bury-buffer', \"stb\" is an abbrev for `switch-to-buffer'."
3478 (string-match anything-c-function-abbrev-regexp candidate
))
3480 (defvar anything-c-source-emacs-functions-with-abbrevs
3481 (append anything-c-source-emacs-functions
3482 '((match anything-c-match-function-by-abbrev
3483 anything-c-string-match
))
3486 (defadvice anything-update
3487 (before anything-c-update-function-abbrev-regexp activate
)
3488 (let ((char-list (append anything-pattern nil
))
3490 (dolist (c char-list
)
3491 (setq str
(concat str
(list c
) "[^-]*-")))
3492 (setq str
(concat (substring str
0 (1- (length str
))) "$"))
3493 (setq anything-c-function-abbrev-regexp str
))))))))
3494 ;; (anything 'anything-c-source-emacs-functions-with-abbrevs)
3496 (defvar anything-c-source-advice
3497 '((name .
"Function Advice")
3498 (candidates . anything-c-advice-candidates
)
3499 (action ("Toggle Enable/Disable" . anything-c-advice-toggle
))
3500 ;; (real-to-display . anything-c-advice-real-to-display)
3503 (persistent-action . anything-c-advice-persistent-action
)
3504 (persistent-help .
"Describe function / C-u C-z: Toggle advice")))
3505 ;; (anything 'anything-c-source-advice)
3506 ;; (let ((debug-on-signal t))(anything 'anything-c-source-advice))
3509 (defun anything-c-advice-candidates ()
3511 (loop for
(fname) in ad-advised-functions
3512 for function
= (intern fname
)
3514 (loop for class in ad-advice-classes append
3515 (loop for advice in
(ad-get-advice-info-field function class
)
3516 for enabled
= (ad-advice-enabled advice
)
3520 (if enabled
"Enabled " "Disabled")
3521 (propertize fname
'face
'font-lock-function-name-face
)
3522 (ad-make-single-advice-docstring advice class nil
))
3523 (list function class advice
))))))
3525 (defun anything-c-advice-persistent-action (func-class-advice)
3526 (if current-prefix-arg
3527 (anything-c-advice-toggle func-class-advice
)
3528 (describe-function (car func-class-advice
))))
3530 (defun anything-c-advice-toggle (func-class-advice)
3531 (destructuring-bind (function class advice
) func-class-advice
3532 (cond ((ad-advice-enabled advice
)
3533 (ad-advice-set-enabled advice nil
)
3534 (message "Disabled"))
3536 (ad-advice-set-enabled advice t
)
3537 (message "Enabled")))
3538 (ad-activate function
)
3539 (and anything-in-persistent-action
3540 (anything-c-advice-update-current-display-string))))
3542 (defun anything-c-advice-update-current-display-string ()
3543 (anything-edit-current-selection
3544 (let ((newword (cond ((looking-at "Disabled") "Enabled")
3545 ((looking-at "Enabled") "Disabled")))
3548 (delete-region (point) (progn (forward-word 1) (point)))
3549 (insert newword
)))))
3552 (defun anything-manage-advice ()
3553 "Preconfigured `anything' to disable/enable function advices."
3555 (anything-other-buffer 'anything-c-source-advice
"*anything advice*"))
3559 (defvar anything-c-source-emacs-variables
3560 '((name .
"Emacs Variables")
3561 (candidates .
(lambda ()
3562 (sort (all-completions "" obarray
'boundp
) 'string-lessp
)))
3564 (requires-pattern .
2))
3565 "Source for completing Emacs variables.")
3566 ;; (anything 'anything-c-source-emacs-variables)
3570 (eval-when-compile (require 'bookmark
))
3571 (defvar anything-c-source-bookmarks
3572 '((name .
"Bookmarks")
3574 (require 'bookmark
)))
3575 (candidates . bookmark-all-names
)
3577 "See (info \"(emacs)Bookmarks\").")
3578 ;; (anything 'anything-c-source-bookmarks)
3581 (defvar anything-c-source-bookmark-set
3582 '((name .
"Set Bookmark")
3584 (action . bookmark-set
))
3585 "See (info \"(emacs)Bookmarks\").")
3586 ;; (anything 'anything-c-source-bookmark-set)
3588 ;;; Visible Bookmarks
3589 ;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
3592 ;; http://d.hatena.ne.jp/grandVin/20080911/1221114327
3593 (defvar anything-c-source-bm
3594 '((name .
"Visible Bookmarks")
3595 (init . anything-c-bm-init
)
3596 (candidates-in-buffer)
3600 http://www.nongnu.org/bm/")
3602 (defun anything-c-bm-init ()
3603 "Init function for `anything-c-source-bm'."
3604 (when (require 'bm nil t
)
3606 (let ((bookmarks (bm-lists))
3607 (buf (anything-candidate-buffer 'global
)))
3608 (dolist (bm (sort* (append (car bookmarks
) (cdr bookmarks
))
3609 '< :key
'overlay-start
))
3610 (let ((start (overlay-start bm
))
3611 (end (overlay-end bm
))
3612 (annotation (or (overlay-get bm
'annotation
) "")))
3613 (unless (< (- end start
) 1) ; org => (if (< (- end start) 2)
3614 (let ((str (format "%5d: [%s]: %s\n"
3615 (line-number-at-pos start
)
3617 (buffer-substring start
(1- end
)))))
3618 (with-current-buffer buf
(insert str
))))))))))
3620 ;;; Special bookmarks
3621 (defvar anything-c-source-bookmarks-ssh
3622 '((name .
"Bookmarks-ssh")
3624 (require 'bookmark
)))
3625 (candidates .
(lambda () (anything-c-collect-bookmarks :ssh t
)))
3627 "See (info \"(emacs)Bookmarks\").")
3628 ;; (anything 'anything-c-source-bookmarks-ssh)
3630 (defvar anything-c-source-bookmarks-su
3631 '((name .
"Bookmarks-root")
3633 (require 'bookmark
)))
3634 (candidates .
(lambda () (anything-c-collect-bookmarks :su t
)))
3635 (filtered-candidate-transformer anything-c-highlight-bookmark-su
)
3638 "See (info \"(emacs)Bookmarks\").")
3639 ;; (anything 'anything-c-source-bookmarks-su)
3641 (defvar anything-c-source-bookmarks-local
3642 '((name .
"Bookmarks-Local")
3644 (require 'bookmark
)))
3645 (candidates .
(lambda () (anything-c-collect-bookmarks :local t
)))
3646 (filtered-candidate-transformer
3647 anything-c-adaptive-sort
3648 anything-c-highlight-bookmark
)
3650 "See (info \"(emacs)Bookmarks\").")
3651 ;; (anything 'anything-c-source-bookmarks-local)
3653 (defun* anything-c-collect-bookmarks
(&key local su sudo ssh
)
3654 (let* ((lis-all (bookmark-all-names))
3655 (lis-loc (cond (local (loop for i in lis-all
3656 unless
(string-match "^(ssh)\\|^(su)" i
)
3658 (su (loop for i in lis-all
3659 when
(string-match "^(su)" i
)
3661 (sudo (loop for i in lis-all
3662 when
(string-match "^(sudo)" i
)
3664 (ssh (loop for i in lis-all
3665 when
(string-match "^(ssh)" i
)
3667 (sort lis-loc
'string-lessp
)))
3669 (defun anything-c-bookmark-root-logged-p ()
3671 (dolist (i (mapcar #'buffer-name
(buffer-list)))
3672 (when (string-match (format "*tramp/%s ." anything-su-or-sudo
) i
)
3673 (throw 'break t
)))))
3675 (defun anything-c-highlight-bookmark-su (files source
)
3676 (if (anything-c-bookmark-root-logged-p)
3677 (anything-c-highlight-bookmark files source
)
3678 (anything-c-highlight-not-logged files source
)))
3680 (defun anything-c-highlight-not-logged (files source
)
3681 (loop for i in files
3682 collect
(propertize i
'face anything-c-bookmarks-face3
)))
3684 (defun anything-c-highlight-bookmark (bookmarks source
)
3685 "Used as `candidate-transformer' to colorize bookmarks.
3686 Work both with standard Emacs bookmarks and bookmark-extensions.el."
3687 (loop for i in bookmarks
3688 for isfile
= (bookmark-get-filename i
)
3689 for bufp
= (and (fboundp 'bmkext-get-buffer-name
)
3690 (bmkext-get-buffer-name i
))
3691 for handlerp
= (and (fboundp 'bookmark-get-handler
)
3692 (bookmark-get-handler i
))
3693 for isw3m
= (and (fboundp 'bmkext-w3m-bookmark-p
)
3694 (bmkext-w3m-bookmark-p i
))
3695 for isgnus
= (and (fboundp 'bmkext-gnus-bookmark-p
)
3696 (bmkext-gnus-bookmark-p i
))
3697 for isman
= (and (fboundp 'bmkext-man-bookmark-p
) ; Man
3698 (bmkext-man-bookmark-p i
))
3699 for iswoman
= (and (fboundp 'bmkext-woman-bookmark-p
) ; Woman
3700 (bmkext-woman-bookmark-p i
))
3701 for handlerp
= (bookmark-get-handler i
)
3702 for isannotation
= (bookmark-get-annotation i
)
3703 for isabook
= (string= (bookmark-prop-get i
'type
) "addressbook")
3704 for isinfo
= (eq handlerp
'Info-bookmark-jump
)
3705 ;; Add a * if bookmark have annotation
3706 if
(and isannotation
(not (string-equal isannotation
"")))
3707 do
(setq i
(concat "*" i
))
3708 collect
(cond (;; info buffers
3710 (propertize i
'face
'anything-bmkext-info
'help-echo isfile
))
3713 (propertize i
'face
'anything-bmkext-w3m
'help-echo isfile
))
3716 (propertize i
'face
'anything-bmkext-gnus
'help-echo isfile
))
3719 (propertize i
'face
'anything-bmkext-man
'help-echo isfile
))
3722 (propertize i
'face
'((:foreground
"Tomato"))))
3724 (and isfile
(file-directory-p isfile
))
3725 (propertize i
'face anything-c-bookmarks-face1
'help-echo isfile
))
3728 (propertize i
'face
'anything-bmkext-file
'help-echo isfile
)))))
3731 ;;; Faces for bookmarks
3732 (defface anything-bmkext-info
3733 '((t (:foreground
"green")))
3734 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3737 (defface anything-bmkext-w3m
3738 '((t (:foreground
"yellow")))
3739 "*Face used for W3m Emacs bookmarks (not w3m bookmarks)."
3742 (defface anything-bmkext-gnus
3743 '((t (:foreground
"magenta")))
3744 "*Face used for Gnus bookmarks."
3747 (defface anything-bmkext-man
3748 '((t (:foreground
"Orange4")))
3749 "*Face used for Woman/man bookmarks."
3752 (defface anything-bmkext-no--file
3753 '((t (:foreground
"grey")))
3754 "*Face used for non--file bookmarks."
3757 (defface anything-bmkext-file
3758 '((t (:foreground
"Deepskyblue2")))
3759 "*Face used for non--file bookmarks."
3762 (defface anything-bookmarks-su-face
'((t (:foreground
"red")))
3763 "Face for su/sudo bookmarks."
3766 (defvar anything-c-bookmarks-face1
'anything-dir-heading
)
3767 (defvar anything-c-bookmarks-face2
'anything-file-name
)
3768 (defvar anything-c-bookmarks-face3
'anything-bookmarks-su-face
)
3771 ;;; Sources to filter bookmark-extensions bookmarks.
3772 ;; Dependency: http://mercurial.intuxication.org/hg/emacs-bookmark-extension
3773 ;; If you want to enable google-maps in addressbook you will need
3774 ;; Julien Danjou google-maps-el package available here:
3775 ;; http://julien.danjou.info/google-maps-el.html
3777 (defun anything-c-bmkext-filter-setup-alist (fn &rest args
)
3778 "Return a filtered `bookmark-alist' sorted alphabetically."
3780 with alist
= (if args
3781 (apply #'(lambda (x) (funcall fn x
)) args
)
3786 finally return
(sort sa
'string-lessp
)))
3789 (defvar anything-c-source-bmkext-addressbook
3790 '((name .
"Bookmark Addressbook")
3792 (require 'bookmark-extensions
)
3793 (bookmark-maybe-load-default-file)))
3794 (candidates . anything-c-bmkext-addressbook-setup-alist
)
3796 .
(lambda (candidate)
3797 (let ((bmk (anything-bookmark-get-bookmark-from-name
3799 (bookmark--jump-via bmk
'pop-to-buffer
))))
3800 (persistent-help .
"Show contact - Prefix with C-u to append")
3801 (filtered-candidate-transformer
3802 anything-c-adaptive-sort
3803 anything-c-highlight-bookmark
)
3804 (action .
(("Show person's data"
3805 .
(lambda (candidate)
3806 (let ((bmk (anything-bookmark-get-bookmark-from-name
3808 (current-prefix-arg anything-current-prefix-arg
))
3809 (bookmark-jump bmk
))))
3811 .
(lambda (candidate)
3812 (let ((bmk (anything-bookmark-get-bookmark-from-name
3814 (if anything-current-prefix-arg
3815 (addressbook-set-mail-buffer1 bmk
'append
)
3816 (addressbook-set-mail-buffer1 bmk
)))))
3818 .
(lambda (candidate)
3819 (let ((bmk (anything-bookmark-get-bookmark-from-name
3821 (addressbook-bookmark-edit
3822 (assoc bmk bookmark-alist
)))))
3823 ("Insert Email at point"
3824 .
(lambda (candidate)
3825 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3827 (mlist (split-string
3829 'email
(assoc bmk bookmark-alist
))
3832 (if (> (length mlist
) 1)
3834 "Insert Mail Address: " mlist
:must-match t
)
3837 .
(lambda (candidate)
3838 (let ((bmk (anything-bookmark-get-bookmark-from-name
3840 (bookmark-show-annotation bmk
))))
3842 .
(lambda (candidate)
3843 (let ((bmk (anything-bookmark-get-bookmark-from-name
3845 (bookmark-edit-annotation bmk
))))
3847 .
(lambda (candidate)
3848 (let* ((bmk (anything-bookmark-get-bookmark-from-name
3850 (full-bmk (assoc bmk bookmark-alist
)))
3851 (addressbook-google-map full-bmk
))))))))
3854 (defun anything-c-bmkext-addressbook-setup-alist ()
3855 "Specialized filter function for bookmarks w3m."
3856 (anything-c-bmkext-filter-setup-alist 'bmkext-addressbook-alist-only
))
3859 (defvar anything-c-source-bookmark-w3m
3860 '((name .
"Bookmark W3m")
3862 (require 'bookmark-extensions
)
3863 (bookmark-maybe-load-default-file)))
3864 (candidates . anything-c-bookmark-w3m-setup-alist
)
3865 (filtered-candidate-transformer
3866 anything-c-adaptive-sort
3867 anything-c-highlight-bookmark
)
3869 ;; (anything 'anything-c-source-bookmark-w3m)
3871 (defun anything-c-bookmark-w3m-setup-alist ()
3872 "Specialized filter function for bookmarks w3m."
3873 (anything-c-bmkext-filter-setup-alist 'bmkext-w3m-alist-only
))
3876 (defvar anything-c-source-bookmark-images
3877 '((name .
"Bookmark Images")
3879 (require 'bookmark-extensions
)
3880 (bookmark-maybe-load-default-file)))
3881 (candidates . anything-c-bookmark-images-setup-alist
)
3882 (filtered-candidate-transformer
3883 anything-c-adaptive-sort
3884 anything-c-highlight-bookmark
)
3886 ;; (anything 'anything-c-source-bookmark-images)
3888 (defun anything-c-bookmark-images-setup-alist ()
3889 "Specialized filter function for images bookmarks."
3890 (anything-c-bmkext-filter-setup-alist 'bmkext-image-file-alist-only
))
3893 (defvar anything-c-source-bookmark-man
3894 '((name .
"Bookmark Woman&Man")
3896 (require 'bookmark-extensions
)
3897 (bookmark-maybe-load-default-file)))
3898 (candidates . anything-c-bookmark-man-setup-alist
)
3899 (filtered-candidate-transformer
3900 anything-c-adaptive-sort
3901 anything-c-highlight-bookmark
)
3903 ;; (anything 'anything-c-source-bookmark-man)
3905 (defun anything-c-bookmark-man-setup-alist ()
3906 "Specialized filter function for bookmarks w3m."
3907 (append (anything-c-bmkext-filter-setup-alist 'bmkext-man-alist-only
)
3908 (anything-c-bmkext-filter-setup-alist 'bmkext-woman-alist-only
)))
3911 (defvar anything-c-source-bookmark-gnus
3912 '((name .
"Bookmark Gnus")
3914 (require 'bookmark-extensions
)
3915 (bookmark-maybe-load-default-file)))
3916 (candidates . anything-c-bookmark-gnus-setup-alist
)
3917 (filtered-candidate-transformer
3918 anything-c-adaptive-sort
3919 anything-c-highlight-bookmark
)
3921 ;; (anything 'anything-c-source-bookmark-gnus)
3923 (defun anything-c-bookmark-gnus-setup-alist ()
3924 "Specialized filter function for bookmarks gnus."
3925 (anything-c-bmkext-filter-setup-alist 'bmkext-gnus-alist-only
))
3928 (defvar anything-c-source-bookmark-info
3929 '((name .
"Bookmark Info")
3931 (require 'bookmark-extensions
)
3932 (bookmark-maybe-load-default-file)))
3933 (candidates . anything-c-bookmark-info-setup-alist
)
3934 (filtered-candidate-transformer
3935 anything-c-adaptive-sort
3936 anything-c-highlight-bookmark
)
3938 ;; (anything 'anything-c-source-bookmark-info)
3940 (defun anything-c-bookmark-info-setup-alist ()
3941 "Specialized filter function for bookmarks info."
3942 (anything-c-bmkext-filter-setup-alist 'bmkext-info-alist-only
))
3944 ;; Local Files&directories
3945 (defvar anything-c-source-bookmark-files
&dirs
3946 '((name .
"Bookmark Files&Directories")
3948 (require 'bookmark-extensions
)
3949 (bookmark-maybe-load-default-file)))
3950 (candidates . anything-c-bookmark-local-files-setup-alist
)
3951 (filtered-candidate-transformer
3952 anything-c-adaptive-sort
3953 anything-c-highlight-bookmark
)
3955 ;; (anything 'anything-c-source-bookmark-files&dirs)
3957 (defun anything-c-bookmark-local-files-setup-alist ()
3958 "Specialized filter function for bookmarks locals files."
3959 (anything-c-bmkext-filter-setup-alist 'bmkext-local-file-alist-only
))
3961 ;; Su Files&directories
3962 (defvar anything-c-source-bookmark-su-files
&dirs
3963 '((name .
"Bookmark Root-Files&Directories")
3965 (require 'bookmark-extensions
)
3966 (bookmark-maybe-load-default-file)))
3967 (candidates . anything-c-bookmark-su-files-setup-alist
)
3968 (filtered-candidate-transformer
3969 anything-c-adaptive-sort
3970 anything-c-highlight-bookmark-su
)
3972 ;; (anything 'anything-c-source-bookmark-su-files&dirs)
3974 (defun anything-c-bookmark-su-files-setup-alist ()
3975 "Specialized filter function for bookmarks su/sudo files."
3977 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
3979 for isfile
= (bookmark-get-filename i
)
3980 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
3982 (string-match tramp-file-name-regexp isfile
)))
3983 for issu
= (and istramp
3984 (string-match bmkext-su-or-sudo-regexp isfile
))
3988 ;; Ssh Files&directories
3989 (defvar anything-c-source-bookmark-ssh-files
&dirs
3990 '((name .
"Bookmark Ssh-Files&Directories")
3992 (require 'bookmark-extensions
)
3993 (bookmark-maybe-load-default-file)))
3994 (candidates . anything-c-bookmark-ssh-files-setup-alist
)
3995 (filtered-candidate-transformer . anything-c-adaptive-sort
)
3997 ;; (anything 'anything-c-source-bookmark-ssh-files&dirs)
3999 (defun anything-c-bookmark-ssh-files-setup-alist ()
4000 "Specialized filter function for bookmarks ssh files."
4002 with l
= (anything-c-bmkext-filter-setup-alist 'bmkext-remote-file-alist-only
)
4004 for isfile
= (bookmark-get-filename i
)
4005 for istramp
= (and isfile
(boundp 'tramp-file-name-regexp
)
4007 (string-match tramp-file-name-regexp isfile
)))
4008 for isssh
= (and istramp
4009 (string-match "/ssh:" isfile
))
4014 ;; All bookmark-extensions sources.
4016 (defun anything-bookmark-ext ()
4017 "Preconfigured `anything' for bookmark-extensions sources.
4018 Needs bookmark-ext.el
4020 http://mercurial.intuxication.org/hg/emacs-bookmark-extension"
4024 '(anything-c-source-bookmark-files&dirs
4025 anything-c-source-bookmark-w3m
4026 anything-c-source-bmkext-addressbook
4027 anything-c-source-bookmark-gnus
4028 anything-c-source-bookmark-info
4029 anything-c-source-bookmark-man
4030 anything-c-source-bookmark-images
4031 anything-c-source-bookmark-su-files
&dirs
4032 anything-c-source-bookmark-ssh-files
&dirs
)
4033 :prompt
"SearchBookmark: "
4034 :buffer
"*anything bmkext*"))
4037 ;; Firefox bookmarks
4038 ;; You will have to set firefox to import bookmarks in his html file bookmarks.html.
4039 ;; (only for firefox versions >=3)
4040 ;; To achieve that, open about:config in firefox and double click on this line to enable value
4042 ;; user_pref("browser.bookmarks.autoExportHTML", false);
4043 ;; You should have now:
4044 ;; user_pref("browser.bookmarks.autoExportHTML", true);
4046 (defvar anything-firefox-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*")
4047 (defvar anything-firefox-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
4049 (defun anything-get-firefox-user-init-dir ()
4050 "Guess the default Firefox user directory name."
4051 (let* ((moz-dir (concat (getenv "HOME") "/.mozilla/firefox/"))
4053 (with-current-buffer (find-file-noselect (concat moz-dir
"profiles.ini"))
4054 (goto-char (point-min))
4056 (when (search-forward "Path=" nil t
)
4057 (buffer-substring-no-properties (point) (point-at-eol)))
4059 (file-name-as-directory (concat moz-dir moz-user-dir
))))
4061 (defun anything-guess-firefox-bookmark-file ()
4062 "Return the path of the Firefox bookmarks file."
4063 (concat (anything-get-firefox-user-init-dir) "bookmarks.html"))
4065 (defun anything-html-bookmarks-to-alist (file url-regexp bmk-regexp
)
4066 "Parse html bookmark FILE and return an alist with (title . url) as elements."
4067 (let (bookmarks-alist url title
)
4069 (insert-file-contents file
)
4070 (goto-char (point-min))
4071 (while (re-search-forward "href=\\|^ *<DT><A HREF=" nil t
)
4073 (when (re-search-forward url-regexp nil t
)
4074 (setq url
(match-string 0)))
4075 (when (re-search-forward bmk-regexp nil t
)
4076 (setq title
(match-string 1)))
4077 (push (cons title url
) bookmarks-alist
)
4079 (nreverse bookmarks-alist
)))
4081 (defvar anything-c-firefox-bookmarks-alist nil
)
4082 (defvar anything-c-source-firefox-bookmarks
4083 '((name .
"Firefox Bookmarks")
4085 (setq anything-c-firefox-bookmarks-alist
4086 (anything-html-bookmarks-to-alist
4087 (anything-guess-firefox-bookmark-file)
4088 anything-firefox-bookmark-url-regexp
4089 anything-firefox-bookmarks-regexp
))))
4090 (candidates .
(lambda ()
4091 (mapcar #'car anything-c-firefox-bookmarks-alist
)))
4092 (filtered-candidate-transformer
4093 anything-c-adaptive-sort
4094 anything-c-highlight-firefox-bookmarks
)
4095 (action .
(("Browse Url Firefox"
4096 .
(lambda (candidate)
4098 (anything-c-firefox-bookmarks-get-value candidate
))))
4100 .
(lambda (candidate)
4102 (anything-c-firefox-bookmarks-get-value candidate
))))
4105 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))))))
4107 ;; (anything 'anything-c-source-firefox-bookmarks)
4109 (defun anything-c-firefox-bookmarks-get-value (elm)
4110 (assoc-default elm anything-c-firefox-bookmarks-alist
))
4112 (defun anything-c-highlight-firefox-bookmarks (bookmarks source
)
4113 (loop for i in bookmarks
4115 i
'face
'((:foreground
"YellowGreen"))
4116 'help-echo
(anything-c-firefox-bookmarks-get-value i
))))
4119 (eval-when-compile (require 'w3m-bookmark nil t
))
4120 (unless (and (require 'w3m nil t
)
4121 (require 'w3m-bookmark nil t
))
4122 (defvar w3m-bookmark-file
"~/.w3m/bookmark.html"))
4125 (defface anything-w3m-bookmarks-face
'((t (:foreground
"cyan1" :underline t
)))
4126 "Face for w3m bookmarks" :group
'anything
)
4128 (defvar anything-w3m-bookmarks-regexp
">\\([^><]+.[^</a>]\\)")
4129 (defvar anything-w3m-bookmark-url-regexp
"\\(https\\|http\\|ftp\\|file\\)://[^>]*")
4130 (defvar anything-c-w3m-bookmarks-alist nil
)
4131 (defvar anything-c-source-w3m-bookmarks
4132 '((name .
"W3m Bookmarks")
4134 (setq anything-c-w3m-bookmarks-alist
4135 (anything-html-bookmarks-to-alist
4137 anything-w3m-bookmark-url-regexp
4138 anything-w3m-bookmarks-regexp
))))
4139 (candidates .
(lambda ()
4140 (mapcar #'car anything-c-w3m-bookmarks-alist
)))
4141 (filtered-candidate-transformer
4142 anything-c-adaptive-sort
4143 anything-c-highlight-w3m-bookmarks
)
4144 (action .
(("Browse Url"
4145 .
(lambda (candidate)
4146 (anything-c-w3m-browse-bookmark candidate
)))
4149 (kill-new (anything-c-w3m-bookmarks-get-value elm
))))
4150 ("Browse Url Firefox"
4151 .
(lambda (candidate)
4152 (anything-c-w3m-browse-bookmark candidate t
)))
4154 .
(lambda (candidate)
4155 (anything-c-w3m-delete-bookmark candidate
)))
4157 .
(lambda (candidate)
4158 (anything-c-w3m-rename-bookmark candidate
)))))
4159 (persistent-action .
(lambda (candidate)
4160 (if current-prefix-arg
4161 (anything-c-w3m-browse-bookmark candidate t
)
4162 (anything-c-w3m-browse-bookmark candidate nil t
))))
4163 (persistent-help .
"Open URL with emacs-w3m in new tab / \
4164 C-u \\[anything-execute-persistent-action]: Open URL with Firefox"))
4165 "Needs w3m and emacs-w3m.
4167 http://w3m.sourceforge.net/
4168 http://emacs-w3m.namazu.org/")
4170 ;; (anything 'anything-c-source-w3m-bookmarks)
4172 (defun anything-c-w3m-bookmarks-get-value (elm)
4173 (replace-regexp-in-string
4174 "\"" "" (cdr (assoc elm anything-c-w3m-bookmarks-alist
))))
4176 (defun anything-c-w3m-browse-bookmark (elm &optional use-firefox new-tab
)
4177 (let* ((fn (if use-firefox
'browse-url-firefox
'w3m-browse-url
))
4178 (arg (and (eq fn
'w3m-browse-url
) new-tab
)))
4179 (funcall fn
(anything-c-w3m-bookmarks-get-value elm
) arg
)))
4181 (defun anything-c-highlight-w3m-bookmarks (bookmarks source
)
4182 (loop for i in bookmarks
4184 i
'face
'anything-w3m-bookmarks-face
4185 'help-echo
(anything-c-w3m-bookmarks-get-value i
))))
4188 (defun anything-c-w3m-delete-bookmark (elm)
4190 (find-file-literally w3m-bookmark-file
)
4191 (goto-char (point-min))
4192 (when (re-search-forward elm nil t
)
4194 (delete-region (point)
4195 (line-end-position))
4196 (delete-blank-lines))
4197 (save-buffer (current-buffer))
4198 (kill-buffer (current-buffer))))
4200 (defun anything-c-w3m-rename-bookmark (elm)
4201 (let* ((old-title (replace-regexp-in-string ">" "" elm
))
4202 (new-title (read-string "NewTitle: " old-title
)))
4204 (find-file-literally w3m-bookmark-file
)
4205 (goto-char (point-min))
4206 (when (re-search-forward (concat elm
"<") nil t
)
4207 (goto-char (1- (point)))
4208 (delete-char (- (length old-title
)))
4210 (save-buffer (current-buffer))
4211 (kill-buffer (current-buffer)))))
4214 ;;; Elisp library scan
4215 (defvar anything-c-source-elisp-library-scan
4216 '((name .
"Elisp libraries (Scan)")
4217 (init .
(anything-c-elisp-library-scan-init))
4218 (candidates-in-buffer)
4219 (action ("Find library"
4220 .
(lambda (candidate) (find-file (find-library-name candidate
))))
4221 ("Find library other window"
4222 .
(lambda (candidate)
4223 (find-file-other-window (find-library-name candidate
))))
4225 .
(lambda (candidate) (load-library candidate
))))))
4226 ;; (anything 'anything-c-source-elisp-library-scan)
4228 (defun anything-c-elisp-library-scan-init ()
4229 "Init anything buffer status."
4230 (let ((anything-buffer (anything-candidate-buffer 'global
))
4231 (library-list (anything-c-elisp-library-scan-list)))
4232 (with-current-buffer anything-buffer
4233 (dolist (library library-list
)
4234 (insert (format "%s\n" library
))))))
4236 (defun anything-c-elisp-library-scan-list (&optional dirs string
)
4237 "Do completion for file names passed to `locate-file'.
4238 DIRS is directory to search path.
4239 STRING is string to match."
4240 ;; Use `load-path' as path when ignore `dirs'.
4241 (or dirs
(setq dirs load-path
))
4242 ;; Init with blank when ignore `string'.
4243 (or string
(setq string
""))
4244 ;; Get library list.
4245 (let ((string-dir (file-name-directory string
))
4246 ;; File regexp that suffix match `load-file-rep-suffixes'.
4247 (match-regexp (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes
)))
4252 (setq dir default-directory
))
4254 (setq dir
(expand-file-name string-dir dir
)))
4255 (when (file-directory-p dir
)
4256 (dolist (file (file-name-all-completions
4257 (file-name-nondirectory string
) dir
))
4258 ;; Suffixes match `load-file-rep-suffixes'.
4259 (setq name
(if string-dir
(concat string-dir file
) file
))
4260 (if (string-match match-regexp name
)
4261 (add-to-list 'names name
)))))
4266 (defvar anything-c-imenu-delimiter
" / ")
4268 (defvar anything-c-imenu-index-filter nil
)
4269 (make-variable-buffer-local 'anything-c-imenu-index-filter
)
4271 (defvar anything-c-cached-imenu-alist nil
)
4272 (make-variable-buffer-local 'anything-c-cached-imenu-alist
)
4274 (defvar anything-c-cached-imenu-candidates nil
)
4275 (make-variable-buffer-local 'anything-c-cached-imenu-candidates
)
4277 (defvar anything-c-cached-imenu-tick nil
)
4278 (make-variable-buffer-local 'anything-c-cached-imenu-tick
)
4280 (eval-when-compile (require 'imenu
))
4281 (setq imenu-auto-rescan t
)
4283 (defun anything-imenu-create-candidates (entry)
4284 "Create candidates with ENTRY."
4285 (if (listp (cdr entry
))
4288 (if (consp (cdr sub
))
4291 (concat (car entry
) anything-c-imenu-delimiter subentry
))
4292 (anything-imenu-create-candidates sub
))
4293 (list (concat (car entry
) anything-c-imenu-delimiter
(car sub
)))))
4297 (defvar anything-c-source-imenu
4299 (init .
(lambda () (require 'imenu
)))
4300 (candidates . anything-c-imenu-candidates
)
4301 (persistent-action .
(lambda (elm)
4302 (anything-c-imenu-default-action elm
)
4303 (unless (fboundp 'semantic-imenu-tag-overlay
)
4304 (anything-match-line-color-current-line))))
4305 (persistent-help .
"Show this entry")
4306 (action . anything-c-imenu-default-action
))
4307 "See (info \"(emacs)Imenu\")")
4309 ;; (anything 'anything-c-source-imenu)
4311 (defun anything-c-imenu-candidates ()
4312 (with-current-buffer anything-current-buffer
4313 (let ((tick (buffer-modified-tick)))
4314 (if (eq anything-c-cached-imenu-tick tick
)
4315 anything-c-cached-imenu-candidates
4316 (setq imenu--index-alist nil
)
4317 (setq anything-c-cached-imenu-tick tick
4318 anything-c-cached-imenu-candidates
4321 'anything-imenu-create-candidates
4322 (setq anything-c-cached-imenu-alist
4323 (let ((index (imenu--make-index-alist)))
4324 (if anything-c-imenu-index-filter
4325 (funcall anything-c-imenu-index-filter index
)
4327 (setq anything-c-cached-imenu-candidates
4328 (mapcar #'(lambda (x)
4332 anything-c-cached-imenu-candidates
))))))
4334 (setq imenu-default-goto-function
'imenu-default-goto-function
)
4335 (defun anything-c-imenu-default-action (elm)
4336 "The default action for `anything-c-source-imenu'."
4337 (let ((path (split-string elm anything-c-imenu-delimiter
))
4338 (alist anything-c-cached-imenu-alist
))
4339 (if (> (length path
) 1)
4341 (setq alist
(assoc (car path
) alist
))
4342 (setq elm
(cadr path
))
4343 (imenu (assoc elm alist
)))
4344 (imenu (assoc elm alist
)))))
4347 (defvar anything-c-ctags-modes
4348 '( c-mode c
++-mode awk-mode csharp-mode java-mode javascript-mode lua-mode
4349 makefile-mode pascal-mode perl-mode cperl-mode php-mode python-mode
4350 scheme-mode sh-mode slang-mode sql-mode tcl-mode
))
4352 (defun anything-c-source-ctags-init ()
4353 (when (and buffer-file-name
4354 (memq major-mode anything-c-ctags-modes
)
4355 (anything-current-buffer-is-modified))
4356 (with-current-buffer (anything-candidate-buffer 'local
)
4357 (call-process-shell-command
4358 (if (string-match "\\.el\\.gz$" anything-buffer-file-name
)
4359 (format "ctags -e -u -f- --language-force=lisp --fields=n =(zcat %s) "
4360 anything-buffer-file-name
)
4361 (format "ctags -e -u -f- --fields=n %s " anything-buffer-file-name
))
4362 nil
(current-buffer))
4363 (goto-char (point-min))
4365 (delete-region (point-min) (point))
4366 (loop while
(and (not (eobp)) (search-forward "\001" (point-at-eol) t
))
4367 for lineno-start
= (point)
4368 for lineno
= (buffer-substring
4370 (1- (search-forward "," (point-at-eol) t
)))
4373 (insert (format "%5s:" lineno
))
4374 (search-forward "\177" (point-at-eol) t
)
4375 (delete-region (1- (point)) (point-at-eol))
4376 (forward-line 1)))))
4378 (defvar anything-c-source-ctags
4379 '((name .
"Exuberant ctags")
4380 (init . anything-c-source-ctags-init
)
4381 (candidates-in-buffer)
4384 "Needs Exuberant Ctags.
4386 http://ctags.sourceforge.net/")
4387 ;; (anything 'anything-c-source-ctags)
4390 (eval-when-compile (require 'semantic nil t
))
4391 (declare-function semantic-format-tag-summarize
"ext:format.el" (tag &optional parent color
) t
)
4392 (declare-function semantic-tag-components
"ext:tag.el" (tag) t
)
4393 (declare-function semantic-go-to-tag
"ext:tag-file.el" (tag) t
)
4394 (defvar anything-semantic-candidates nil
)
4396 (defun anything-semantic-construct-candidates (tags depth
)
4397 (when (require 'semantic nil t
)
4403 (let ((type (semantic-tag-type tag
))
4404 (class (semantic-tag-class tag
)))
4405 (if (or (and (stringp type
)
4406 (or (string= type
"class")
4407 (string= type
"namespace")))
4408 (eq class
'function
)
4409 (eq class
'variable
))
4410 (cons (cons (concat (make-string (* depth
2) ?\s
)
4411 (semantic-format-tag-summarize tag nil t
))
4413 (anything-semantic-construct-candidates
4414 (semantic-tag-components tag
) (1+ depth
)))))))
4417 (defun anything-semantic-default-action (candidate)
4418 (let ((tag (cdr (assoc candidate anything-semantic-candidates
))))
4419 (semantic-go-to-tag tag
)))
4421 (defvar anything-c-source-semantic
4422 '((name .
"Semantic Tags")
4424 (setq anything-semantic-candidates
4425 (ignore-errors (anything-semantic-construct-candidates
4426 (semantic-fetch-tags) 0)))))
4427 (candidates .
(lambda ()
4428 (if anything-semantic-candidates
4429 (mapcar 'car anything-semantic-candidates
))))
4430 (persistent-action .
(lambda (elm)
4431 (anything-semantic-default-action elm
)
4432 (anything-match-line-color-current-line)))
4433 (persistent-help .
"Show this entry")
4434 (action . anything-semantic-default-action
)
4435 "Needs semantic in CEDET.
4437 http://cedet.sourceforge.net/semantic.shtml
4438 http://cedet.sourceforge.net/"))
4440 ;; (anything 'anything-c-source-semantic)
4442 ;;; Function is called by
4444 (defun anything-simple-call-tree ()
4445 "Preconfigured `anything' for simple-call-tree. List function relationships.
4447 Needs simple-call-tree.el.
4448 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el"
4450 (anything-other-buffer
4451 '(anything-c-source-simple-call-tree-functions-callers
4452 anything-c-source-simple-call-tree-callers-functions
)
4453 "*anything simple-call-tree*"))
4455 (defvar anything-c-source-simple-call-tree-functions-callers
4456 '((name .
"Function is called by")
4457 (init . anything-c-simple-call-tree-functions-callers-init
)
4459 (candidates . anything-c-simple-call-tree-candidates
)
4460 (persistent-action . anything-c-simple-call-tree-persistent-action
)
4461 (persistent-help .
"Show function definitions by rotation")
4462 (action ("Find definition selected by persistent-action" .
4463 anything-c-simple-call-tree-find-definition
)))
4464 "Needs simple-call-tree.el.
4465 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4467 (defvar anything-c-simple-call-tree-tick nil
)
4468 (make-variable-buffer-local 'anything-c-simple-call-tree-tick
)
4469 (defun anything-c-simple-call-tree-analyze-maybe ()
4470 (unless (eq (buffer-chars-modified-tick) anything-c-simple-call-tree-tick
)
4471 (simple-call-tree-analyze)
4472 (setq anything-c-simple-call-tree-tick
(buffer-chars-modified-tick))))
4474 (defun anything-c-simple-call-tree-init-base (function message
)
4475 (require 'simple-call-tree
)
4477 (when (anything-current-buffer-is-modified)
4478 (anything-c-simple-call-tree-analyze-maybe)
4479 (let ((list (funcall function simple-call-tree-alist
)))
4480 (with-current-buffer (anything-candidate-buffer 'local
)
4481 (dolist (entry list
)
4482 (let ((funcs (concat " " (mapconcat #'identity
(cdr entry
) "\n "))))
4483 (insert (car entry
) message
4484 (if (string= funcs
" ")
4489 (defun anything-c-simple-call-tree-functions-callers-init ()
4490 (anything-c-simple-call-tree-init-base 'simple-call-tree-invert
4493 (defun anything-c-simple-call-tree-candidates ()
4494 (with-current-buffer (anything-candidate-buffer)
4495 (split-string (buffer-string) "\n\n")))
4497 (defvar anything-c-simple-call-tree-related-functions nil
)
4498 (defvar anything-c-simple-call-tree-function-index
0)
4499 (defun anything-c-simple-call-tree-persistent-action (candidate)
4500 (unless (eq last-command
'anything-execute-persistent-action
)
4501 (setq anything-c-simple-call-tree-related-functions
4502 (delete "no functions."
4504 (replace-regexp-in-string " \\| is called by\\| calls "
4507 (setq anything-c-simple-call-tree-function-index -
1))
4508 (incf anything-c-simple-call-tree-function-index
)
4509 (anything-c-simple-call-tree-find-definition candidate
))
4511 (defun anything-c-simple-call-tree-find-definition (candidate)
4514 (nth (mod anything-c-simple-call-tree-function-index
4515 (length anything-c-simple-call-tree-related-functions
))
4516 anything-c-simple-call-tree-related-functions
))))
4518 ;; (anything 'anything-c-source-simple-call-tree-functions-callers)
4521 (defvar anything-c-source-simple-call-tree-callers-functions
4522 '((name .
"Function calls")
4523 (init . anything-c-simple-call-tree-callers-functions-init
)
4525 (candidates . anything-c-simple-call-tree-candidates
)
4526 (persistent-action . anything-c-simple-call-tree-persistent-action
)
4527 (persistent-help .
"Show function definitions by rotation")
4528 (action ("Find definition selected by persistent-action" .
4529 anything-c-simple-call-tree-find-definition
)))
4530 "Needs simple-call-tree.el.
4531 http://www.emacswiki.org/cgi-bin/wiki/download/simple-call-tree.el")
4533 (defun anything-c-simple-call-tree-callers-functions-init ()
4534 (anything-c-simple-call-tree-init-base 'identity
" calls \n"))
4536 ;; (anything 'anything-c-source-simple-call-tree-callers-functions)
4538 ;;; Commands/Options with doc
4539 (defvar anything-c-auto-document-data nil
)
4540 (make-variable-buffer-local 'anything-c-auto-document-data
)
4541 (defvar anything-c-source-commands-and-options-in-file
4542 '((name .
"Commands/Options in file")
4544 .
(lambda (x) (format "Commands/Options in %s"
4545 (buffer-local-value 'buffer-file-name
4546 anything-current-buffer
))))
4547 (candidates . anything-command-and-options-candidates
)
4550 "List Commands and Options with doc. It needs auto-document.el .
4552 http://www.emacswiki.org/cgi-bin/wiki/download/auto-document.el")
4554 (eval-when-compile (require 'auto-document nil t
))
4555 (defun anything-command-and-options-candidates ()
4556 (with-current-buffer anything-current-buffer
4557 (when (and (require 'auto-document nil t
)
4558 (eq major-mode
'emacs-lisp-mode
)
4559 (or (anything-current-buffer-is-modified)
4560 (not anything-c-auto-document-data
)))
4561 (or imenu--index-alist
(imenu--make-index-alist t
))
4562 (setq anything-c-auto-document-data
4563 (destructuring-bind (commands options
)
4564 (adoc-construct anything-current-buffer
)
4566 (loop for
(command . doc
) in commands
4567 for cmdname
= (symbol-name command
)
4570 (format "Command: %s\n %s"
4571 (propertize cmdname
'face font-lock-function-name-face
)
4572 (adoc-first-line doc
))
4573 (assoc cmdname imenu--index-alist
)))
4574 (loop with var-alist
= (cdr (assoc "Variables" imenu--index-alist
))
4575 for
(option doc default
) in options
4576 for optname
= (symbol-name option
)
4579 (format "Option: %s\n %s\n default = %s"
4580 (propertize optname
'face font-lock-variable-name-face
)
4581 (adoc-first-line doc
)
4582 (adoc-prin1-to-string default
))
4585 anything-c-auto-document-data
))
4587 ;; (anything 'anything-c-source-commands-and-options-in-file)
4589 ;;;; <Color and Face>
4591 (defvar anything-c-source-customize-face
4592 '((name .
"Customize Face")
4594 (unless (anything-candidate-buffer)
4595 (save-window-excursion (list-faces-display))
4596 (anything-candidate-buffer (get-buffer "*Faces*")))))
4597 (candidates-in-buffer)
4598 (get-line . buffer-substring
)
4599 (action .
(lambda (line)
4600 (customize-face (intern (car (split-string line
))))))
4601 (requires-pattern .
3))
4602 "See (info \"(emacs)Faces\")")
4603 ;; (anything 'anything-c-source-customize-face)
4606 (defvar anything-c-source-colors
4608 (init .
(lambda () (unless (anything-candidate-buffer)
4609 (save-window-excursion (list-colors-display))
4610 (anything-candidate-buffer (get-buffer "*Colors*")))))
4611 (candidates-in-buffer)
4612 (get-line . buffer-substring
)
4614 ("Copy Name" .
(lambda (candidate)
4615 (kill-new (anything-c-colors-get-name candidate
))))
4616 ("Copy RGB" .
(lambda (candidate)
4617 (kill-new (anything-c-colors-get-rgb candidate
))))
4618 ("Insert Name" .
(lambda (candidate)
4619 (with-current-buffer anything-current-buffer
4620 (insert (anything-c-colors-get-name candidate
)))))
4621 ("Insert RGB" .
(lambda (candidate)
4622 (with-current-buffer anything-current-buffer
4623 (insert (anything-c-colors-get-rgb candidate
))))))))
4624 ;; (anything 'anything-c-source-colors)
4626 (defun anything-c-colors-get-name (candidate)
4628 (replace-regexp-in-string
4631 (insert (capitalize candidate
))
4632 (goto-char (point-min))
4633 (search-forward-regexp "\\s-\\{2,\\}")
4634 (delete-region (point) (point-max))
4637 (defun anything-c-colors-get-rgb (candidate)
4639 (replace-regexp-in-string
4642 (insert (capitalize candidate
))
4643 (goto-char (point-max))
4644 (search-backward-regexp "\\s-\\{2,\\}")
4645 (delete-region (point) (point-min))
4648 ;;;; <Search Engine>
4649 ;;; Tracker desktop search
4650 (defvar anything-c-source-tracker-search
4651 '((name .
"Tracker Search")
4652 (candidates .
(lambda ()
4653 (start-process "tracker-search-process" nil
4657 (requires-pattern .
3)
4659 "Source for retrieving files matching the current input pattern
4660 with the tracker desktop search.")
4661 ;; (anything 'anything-c-source-tracker-search)
4663 ;;; Spotlight (MacOS X desktop search)
4664 (defvar anything-c-source-mac-spotlight
4667 .
(lambda () (start-process "mdfind-process" nil
"mdfind" anything-pattern
)))
4669 (requires-pattern .
3)
4671 "Source for retrieving files via Spotlight's command line
4673 ;; (anything 'anything-c-source-mac-spotlight)
4678 (defvar anything-c-source-kill-ring
4679 '((name .
"Kill Ring")
4680 (init .
(lambda () (anything-attrset 'last-command last-command
)))
4681 (candidates . anything-c-kill-ring-candidates
)
4682 (action . anything-c-kill-ring-action
)
4686 "Source for browse and insert contents of kill-ring.")
4688 (defun anything-c-kill-ring-candidates ()
4689 (loop for kill in kill-ring
4690 unless
(or (< (length kill
) anything-kill-ring-threshold
)
4691 (string-match "^[\\s\\t]+$" kill
))
4694 (defun anything-c-kill-ring-action (str)
4695 "Insert STR in `kill-ring' and set STR to the head.
4696 If this action is executed just after `yank',
4697 replace with STR as yanked string."
4698 (setq kill-ring
(delete str kill-ring
))
4699 (if (not (eq (anything-attr 'last-command
) 'yank
))
4700 (insert-for-yank str
)
4702 (let ((inhibit-read-only t
)
4703 (before (< (point) (mark t
))))
4705 (funcall (or yank-undo-function
'delete-region
) (point) (mark t
))
4706 (funcall (or yank-undo-function
'delete-region
) (mark t
) (point)))
4707 (setq yank-undo-function nil
)
4708 (set-marker (mark-marker) (point) (current-buffer))
4709 (insert-for-yank str
)
4710 ;; Set the window start back where it was in the yank command,
4712 (set-window-start (selected-window) yank-window-start t
)
4714 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
4715 ;; It is cleaner to avoid activation, even though the command
4716 ;; loop would deactivate the mark because we inserted text.
4717 (goto-char (prog1 (mark t
)
4718 (set-marker (mark-marker) (point) (current-buffer)))))))
4721 ;; (anything 'anything-c-source-kill-ring)
4724 ;; DO NOT include these sources in `anything-sources' use
4725 ;; the commands `anything-mark-ring', `anything-global-mark-ring' or
4726 ;; `anything-all-mark-rings' instead.
4728 (defun anything-c-source-mark-ring-candidates ()
4729 (flet ((get-marks (pos)
4733 (let ((line (car (split-string (thing-at-point 'line
) "[\n\r]"))))
4734 (when (string= "" line
)
4735 (setq line
"<EMPTY LINE>"))
4736 (format "%7d: %s" (line-number-at-pos) line
)))))
4737 (with-current-buffer anything-current-buffer
4739 with marks
= (cons (mark-marker) mark-ring
)
4742 for m
= (get-marks i
)
4743 unless
(member m recip
)
4744 collect m into recip
4745 finally return recip
))))
4747 (defvar anything-mark-ring-cache nil
)
4748 (defvar anything-c-source-mark-ring
4749 '((name .
"mark-ring")
4751 (setq anything-mark-ring-cache
4752 (ignore-errors (anything-c-source-mark-ring-candidates)))))
4753 (candidates .
(lambda ()
4754 (anything-aif anything-mark-ring-cache
4756 (action .
(("Goto line"
4757 .
(lambda (candidate)
4758 (anything-goto-line (string-to-number candidate
))))))
4759 (persistent-action .
(lambda (candidate)
4760 (anything-goto-line (string-to-number candidate
))
4761 (anything-match-line-color-current-line)))
4762 (persistent-help .
"Show this line")))
4764 ;; (anything 'anything-c-source-mark-ring)
4767 (defun anything-mark-ring ()
4768 "Preconfigured `anything' for `anything-c-source-mark-ring'."
4770 (anything 'anything-c-source-mark-ring
))
4772 ;;; Global-mark-ring
4773 (defvar anything-c-source-global-mark-ring
4774 '((name .
"global-mark-ring")
4775 (candidates . anything-c-source-global-mark-ring-candidates
)
4776 (action .
(("Goto line"
4777 .
(lambda (candidate)
4778 (let ((items (split-string candidate
":")))
4779 (switch-to-buffer (second items
))
4780 (anything-goto-line (string-to-number (car items
))))))))
4781 (persistent-action .
(lambda (candidate)
4782 (let ((items (split-string candidate
":")))
4783 (switch-to-buffer (second items
))
4784 (anything-goto-line (string-to-number (car items
)))
4785 (anything-match-line-color-current-line))))
4786 (persistent-help .
"Show this line")))
4788 (defun anything-c-source-global-mark-ring-candidates ()
4790 (with-current-buffer (marker-buffer m
)
4794 (if (string= "" line
)
4795 (setq line
"<EMPTY LINE>")
4796 (setq line
(car (split-string (thing-at-point 'line
)
4798 (format "%7d:%s: %s"
4799 (line-number-at-pos) (marker-buffer m
) line
)))))
4801 with marks
= global-mark-ring
4804 for gm
= (unless (or (string-match
4805 "^ " (format "%s" (marker-buffer i
)))
4806 (null (marker-buffer i
)))
4808 when
(and gm
(not (member gm recip
)))
4809 collect gm into recip
4810 finally return recip
)))
4812 ;; (anything 'anything-c-source-global-mark-ring)
4815 (defun anything-global-mark-ring ()
4816 "Preconfigured `anything' for `anything-c-source-global-mark-ring'."
4818 (anything 'anything-c-source-global-mark-ring
))
4821 (defun anything-all-mark-rings ()
4822 "Preconfigured `anything' for `anything-c-source-global-mark-ring' and \
4823 `anything-c-source-mark-ring'."
4825 (anything '(anything-c-source-global-mark-ring
4826 anything-c-source-mark-ring
)))
4829 ;;; Insert from register
4830 (defvar anything-c-source-register
4831 '((name .
"Registers")
4832 (candidates . anything-c-register-candidates
)
4833 (action-transformer . anything-c-register-action-transformer
)
4836 "See (info \"(emacs)Registers\")")
4838 (defun anything-c-register-candidates ()
4839 "Collecting register contents and appropriate commands."
4840 (loop for
(char . val
) in register-alist
4841 for key
= (single-key-description char
)
4842 for string-actions
=
4845 (list (int-to-string val
)
4847 'increment-register
))
4849 (let ((buf (marker-buffer val
)))
4851 (list "a marker in no buffer")
4853 "a buffer position:"
4856 (int-to-string (marker-position val
)))
4858 'insert-register
))))
4859 ((and (consp val
) (window-configuration-p (car val
)))
4860 (list "window configuration."
4862 ((and (consp val
) (frame-configuration-p (car val
)))
4863 (list "frame configuration."
4865 ((and (consp val
) (eq (car val
) 'file
))
4866 (list (concat "file:"
4867 (prin1-to-string (cdr val
))
4870 ((and (consp val
) (eq (car val
) 'file-query
))
4871 (list (concat "file:a file-query reference: file "
4874 (int-to-string (car (cdr (cdr val
))))
4878 (let ((lines (format "%4d" (length val
))))
4879 (list (format "%s: %s\n" lines
4880 (truncate-string-to-width
4881 (mapconcat 'identity
(list (car val
))
4882 ;; (mapconcat (lambda (y) y) val
4883 "^J") (- (window-width) 15)))
4886 (list ;; without properties
4887 (substring-no-properties val
)
4890 'prepend-to-register
))
4893 collect
(cons (format "register %3s: %s" key
(car string-actions
))
4894 (cons char
(cdr string-actions
)))))
4896 (defun anything-c-register-action-transformer (actions register-and-functions
)
4897 "Decide actions by the contents of register."
4898 (loop with func-actions
=
4901 (lambda (c) (insert-register (car c
))))
4903 "Jump to Register" .
4904 (lambda (c) (jump-to-register (car c
))))
4906 "Append Region to Register" .
4907 (lambda (c) (append-to-register
4908 (car c
) (region-beginning) (region-end))))
4909 (prepend-to-register
4910 "Prepend Region to Register" .
4911 (lambda (c) (prepend-to-register
4912 (car c
) (region-beginning) (region-end))))
4914 "Increment Prefix Arg to Register" .
4915 (lambda (c) (increment-register
4916 anything-current-prefix-arg
(car c
)))))
4917 for func in
(cdr register-and-functions
)
4918 for cell
= (assq func func-actions
)
4920 collect
(cdr cell
)))
4922 ;; (anything 'anything-c-source-register)
4924 ;;;; <Headline Extraction>
4925 (defvar anything-c-source-fixme
4926 '((name .
"TODO/FIXME/DRY comments")
4927 (headline .
"^.*\\<\\(TODO\\|FIXME\\|DRY\\)\\>.*$")
4930 "Show TODO/FIXME/DRY comments in current file.")
4931 ;; (anything 'anything-c-source-fixme)
4933 (defvar anything-c-source-rd-headline
4934 '((name .
"RD HeadLine")
4935 (headline "^= \\(.+\\)$" "^== \\(.+\\)$" "^=== \\(.+\\)$" "^==== \\(.+\\)$")
4936 (condition .
(memq major-mode
'(rdgrep-mode rd-mode
)))
4942 http://en.wikipedia.org/wiki/Ruby_Document_format")
4943 ;; (anything 'anything-c-source-rd-headline)
4945 (defvar anything-c-source-oddmuse-headline
4946 '((name .
"Oddmuse HeadLine")
4947 (headline "^= \\(.+\\) =$" "^== \\(.+\\) ==$"
4948 "^=== \\(.+\\) ===$" "^==== \\(.+\\) ====$")
4949 (condition .
(memq major-mode
'(oddmuse-mode yaoddmuse-mode
)))
4952 "Show Oddmuse headlines, such as EmacsWiki.")
4953 ;; (anything 'anything-c-source-oddmuse-headline)
4955 (defvar anything-c-source-emacs-source-defun
4956 '((name .
"Emacs Source DEFUN")
4957 (headline .
"DEFUN\\|DEFVAR")
4958 (condition .
(string-match "/emacs2[0-9].+/src/.+c$"
4959 (or buffer-file-name
""))))
4960 "Show DEFUN/DEFVAR in Emacs C source file.")
4961 ;; (anything 'anything-c-source-emacs-source-defun)
4963 (defvar anything-c-source-emacs-lisp-expectations
4964 '((name .
"Emacs Lisp Expectations")
4965 (headline .
"(desc[ ]\\|(expectations")
4966 (condition .
(eq major-mode
'emacs-lisp-mode
)))
4967 "Show descriptions (desc) in Emacs Lisp Expectations.
4969 http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
4970 ;; (anything 'anything-c-source-emacs-lisp-expectations)
4972 (defvar anything-c-source-emacs-lisp-toplevels
4973 '((name .
"Emacs Lisp Toplevel / Level 4 Comment / Linkd Star")
4974 (headline .
"^(\\|(@\\*\\|^;;;;")
4975 (get-line . buffer-substring
)
4976 (condition .
(eq major-mode
'emacs-lisp-mode
))
4978 "Show top-level forms, level 4 comments and linkd stars (optional) in Emacs Lisp.
4979 linkd.el is optional because linkd stars are extracted by regexp.
4980 http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el")
4981 ;; (anything 'anything-c-source-emacs-lisp-toplevels)
4983 (defvar anything-c-source-org-headline
4984 '((name .
"Org HeadLine")
4986 "^\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4987 "^\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4988 "^\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4989 "^\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4990 "^\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4991 "^\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4992 "^\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$"
4993 "^\\*\\*\\*\\*\\*\\*\\*\\* \\(.+?\\)\\([ \t]*:[a-zA-Z0-9_@:]+:\\)?[ \t]*$")
4994 (condition .
(eq major-mode
'org-mode
))
4997 (persistent-action .
(lambda (elm)
4998 (anything-c-action-line-goto elm
)
5001 .
(lambda (actions candidate
)
5002 '(("Go to Line" . anything-c-action-line-goto
)
5003 ("Insert Link to This Headline" . anything-c-org-headline-insert-link-to-headline
)))))
5004 "Show Org headlines.
5005 org-mode is very very much extended text-mode/outline-mode.
5007 See (find-library \"org.el\")
5008 See http://orgmode.org for the latest version.")
5010 (defun anything-c-org-headline-insert-link-to-headline (lineno-and-content)
5013 (anything-goto-line (car lineno-and-content
))
5014 (and (looking-at org-complex-heading-regexp
)
5015 (org-make-link-string (concat "*" (match-string 4)))))))
5017 ;; (anything 'anything-c-source-org-headline)
5019 ;;; Anything yaoddmuse
5020 ;; Be sure to have yaoddmuse.el installed
5021 ;; install-elisp may be required if you want to install elisp file from here.
5022 (defvar anything-yaoddmuse-use-cache-file nil
)
5023 (defvar anything-c-yaoddmuse-cache-file
"~/.emacs.d/yaoddmuse-cache.el")
5024 (defvar anything-c-yaoddmuse-ew-cache nil
)
5025 (defvar anything-c-source-yaoddmuse-emacswiki-edit-or-view
5026 '((name .
"Yaoddmuse Edit or View (EmacsWiki)")
5027 (candidates .
(lambda ()
5028 (if anything-yaoddmuse-use-cache-file
5030 (unless anything-c-yaoddmuse-ew-cache
5031 (load anything-c-yaoddmuse-cache-file
)
5032 (setq anything-c-yaoddmuse-ew-cache
5033 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
5034 anything-c-yaoddmuse-ew-cache
)
5035 (yaoddmuse-update-pagename t
)
5036 (gethash "EmacsWiki" yaoddmuse-pages-hash
))))
5037 (action .
(("Edit page" .
(lambda (candidate)
5038 (yaoddmuse-edit "EmacsWiki" candidate
)))
5039 ("Browse page" .
(lambda (candidate)
5040 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
5041 ("Browse page other window" .
(lambda (candidate)
5043 (split-window-vertically))
5044 (yaoddmuse-browse-page "EmacsWiki" candidate
)))
5045 ("Browse diff" .
(lambda (candidate)
5046 (yaoddmuse-browse-page-diff "EmacsWiki" candidate
)))
5047 ("Copy URL" .
(lambda (candidate)
5048 (kill-new (yaoddmuse-url "EmacsWiki" candidate
))
5049 (message "Have copy page %s's URL to yank." candidate
)))
5050 ("Create page" .
(lambda (candidate)
5051 (yaoddmuse-edit "EmacsWiki" anything-input
)))
5052 ("Update cache" .
(lambda (candidate)
5053 (if anything-yaoddmuse-use-cache-file
5055 (anything-yaoddmuse-cache-pages t
)
5056 (setq anything-c-yaoddmuse-ew-cache
5057 (gethash "EmacsWiki" yaoddmuse-pages-hash
)))
5058 (yaoddmuse-update-pagename))))))
5059 (action-transformer anything-c-yaoddmuse-action-transformer
))
5060 "Needs yaoddmuse.el.
5062 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5064 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view)
5066 (defvar anything-c-source-yaoddmuse-emacswiki-post-library
5067 '((name .
"Yaoddmuse Post library (EmacsWiki)")
5068 (init .
(anything-yaoddmuse-init))
5069 (candidates-in-buffer)
5070 (action .
(("Post library and Browse" .
(lambda (candidate)
5071 (yaoddmuse-post-file (find-library-name candidate
)
5073 (file-name-nondirectory (find-library-name candidate
))
5075 ("Post library" .
(lambda (candidate)
5076 (yaoddmuse-post-file (find-library-name candidate
)
5078 (file-name-nondirectory (find-library-name candidate
))))))))
5079 "Needs yaoddmuse.el.
5081 http://www.emacswiki.org/emacs/download/yaoddmuse.el")
5083 ;; (anything 'anything-c-source-yaoddmuse-emacswiki-post-library)
5085 (defun anything-c-yaoddmuse-action-transformer (actions candidate
)
5086 "Allow the use of `install-elisp' only on elisp files."
5087 (if (string-match "\.el$" candidate
)
5088 (append actions
'(("Install Elisp" .
(lambda (elm)
5089 (install-elisp-from-emacswiki elm
)))))
5093 (defun anything-yaoddmuse-cache-pages (&optional load
)
5094 "Fetch the list of files on emacswiki and create cache file.
5095 If load is non--nil load the file and feed `yaoddmuse-pages-hash'."
5097 (yaoddmuse-update-pagename)
5099 (find-file anything-c-yaoddmuse-cache-file
)
5101 (insert "(puthash \"EmacsWiki\" '(")
5102 (loop for i in
(gethash "EmacsWiki" yaoddmuse-pages-hash
)
5104 (insert (concat "(\"" (car i
) "\") ")))
5105 (insert ") yaoddmuse-pages-hash)\n")
5107 (kill-buffer (current-buffer))
5108 (when (or current-prefix-arg
5110 (load anything-c-yaoddmuse-cache-file
))))
5113 (defun anything-yaoddmuse-emacswiki-edit-or-view ()
5114 "Preconfigured `anything' to edit or view EmacsWiki page.
5118 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5120 (anything 'anything-c-source-yaoddmuse-emacswiki-edit-or-view
))
5123 (defun anything-yaoddmuse-emacswiki-post-library ()
5124 "Preconfigured `anything' to post library to EmacsWiki.
5128 http://www.emacswiki.org/emacs/download/yaoddmuse.el"
5130 (anything 'anything-c-source-yaoddmuse-emacswiki-post-library
))
5132 (defun anything-yaoddmuse-init ()
5133 "Init anything buffer status."
5134 (let ((anything-buffer (anything-candidate-buffer 'global
))
5135 (library-list (yaoddmuse-get-library-list)))
5136 (with-current-buffer anything-buffer
5137 ;; Insert library name.
5138 (dolist (library library-list
)
5139 (insert (format "%s\n" library
)))
5141 (sort-lines nil
(point-min) (point-max)))))
5144 (defvar anything-c-source-eev-anchor
5145 '((name .
"Anchors")
5149 (with-current-buffer anything-current-buffer
5150 (loop initially
(goto-char (point-min))
5151 while
(re-search-forward (format ee-anchor-format
"\\([^\.].+\\)") nil t
)
5152 for anchor
= (match-string-no-properties 1)
5153 collect
(cons (format "%5d:%s"
5154 (line-number-at-pos (match-beginning 0))
5155 (format ee-anchor-format anchor
)) anchor
))))))
5156 (persistent-action .
(lambda (item)
5158 (anything-match-line-color-current-line)))
5159 (persistent-help .
"Show this entry")
5160 (action .
(("Goto link" . ee-to
)))))
5161 ;; (anything 'anything-c-source-eev-anchor)
5165 (defvar anything-c-source-org-keywords
5166 '((name .
"Org Keywords")
5167 (init . anything-c-org-keywords-init
)
5168 (candidates . anything-c-org-keywords-candidates
)
5169 (action . anything-c-org-keywords-insert
)
5170 (persistent-action . anything-c-org-keywords-show-help
)
5171 (persistent-help .
"Show an example and info page to describe this keyword.")
5174 ;; (anything 'anything-c-source-org-keywords)
5175 (defvar anything-c-org-keywords-info-location
5176 '(("#+TITLE:" .
"(org)Export options")
5177 ("#+AUTHOR:" .
"(org)Export options")
5178 ("#+DATE:" .
"(org)Export options")
5179 ("#+EMAIL:" .
"(org)Export options")
5180 ("#+DESCRIPTION:" .
"(org)Export options")
5181 ("#+KEYWORDS:" .
"(org)Export options")
5182 ("#+LANGUAGE:" .
"(org)Export options")
5183 ("#+TEXT:" .
"(org)Export options")
5184 ("#+TEXT:" .
"(org)Export options")
5185 ("#+OPTIONS:" .
"(org)Export options")
5186 ("#+BIND:" .
"(org)Export options")
5187 ("#+LINK_UP:" .
"(org)Export options")
5188 ("#+LINK_HOME:" .
"(org)Export options")
5189 ("#+LATEX_HEADER:" .
"(org)Export options")
5190 ("#+EXPORT_SELECT_TAGS:" .
"(org)Export options")
5191 ("#+EXPORT_EXCLUDE_TAGS:" .
"(org)Export options")
5192 ("#+INFOJS_OPT" .
"(org)Javascript support")
5193 ("#+BEGIN_HTML" .
"(org)Quoting HTML tags")
5194 ("#+BEGIN_LaTeX" .
"(org)Quoting LaTeX code")
5195 ("#+ORGTBL" .
"(org)Radio tables")
5196 ("#+HTML:" .
"(org)Quoting HTML tags")
5197 ("#+LaTeX:" .
"(org)Quoting LaTeX code")
5198 ("#+BEGIN:" .
"(org)Dynamic blocks") ;clocktable columnview
5199 ("#+BEGIN_EXAMPLE" .
"(org)Literal examples")
5200 ("#+BEGIN_QUOTE" .
"(org)Paragraphs")
5201 ("#+BEGIN_VERSE" .
"(org)Paragraphs")
5202 ("#+BEGIN_SRC" .
"(org)Literal examples")
5203 ("#+CAPTION" .
"(org)Tables in HTML export")
5204 ("#+LABEL" .
"(org)Tables in LaTeX export")
5205 ("#+ATTR_HTML" .
"(org)Links")
5206 ("#+ATTR_LaTeX" .
"(org)Images in LaTeX export")))
5208 (defun anything-c-org-keywords-init ()
5209 (unless (anything-attr 'keywords-examples
)
5211 (anything-attrset 'keywords-examples
5215 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x
)
5216 (cons (match-string 2 x
) (match-string 1 x
)))
5217 (org-split-string (org-get-current-options) "\n"))
5218 (mapcar 'list org-additional-option-like-keywords
)))
5219 (anything-attrset 'keywords
(mapcar 'car
(anything-attr 'keywords-examples
)))))
5221 (defun anything-c-org-keywords-candidates ()
5222 (and (eq (buffer-local-value 'major-mode anything-current-buffer
) 'org-mode
)
5223 (anything-attr 'keywords
)))
5225 (defun anything-c-org-keywords-insert (keyword)
5226 (cond ((string-match "BEGIN" keyword
)
5227 (insert "#+" keyword
" ")
5229 (insert "\n" (replace-regexp-in-string "BEGIN" "END" keyword
) "\n")))
5231 (insert "#+" keyword
" "))))
5233 (defun anything-c-org-keywords-show-help (keyword)
5234 (info (or (assoc-default (concat "#+" keyword
) anything-c-org-keywords-info-location
)
5235 "(org)In-buffer settings"))
5236 (search-forward (concat "#+" keyword
) nil t
)
5237 (anything-persistent-highlight-point)
5238 (message "%s" (or (cdr (assoc keyword
(anything-attr 'keywords-examples
))) "")))
5242 (defvar anything-c-source-picklist
5243 '((name .
"Picklist")
5244 (candidates .
(lambda () (mapcar 'car picklist-list
)))
5246 ;; (anything 'anything-c-source-picklist)
5249 (defvar bbdb-records
)
5250 (defvar bbdb-buffer-name
)
5251 (declare-function bbdb
"ext:bbdb-com")
5252 (declare-function bbdb-current-record
"ext:bbdb-com")
5253 (declare-function bbdb-redisplay-one-record
"ext:bbdb-com")
5254 (declare-function bbdb-record-net
"ext:bbdb-com" (string) t
)
5255 (declare-function bbdb-current-record
"ext:bbdb-com")
5256 (declare-function bbdb-dwim-net-address
"ext:bbdb-com")
5257 (declare-function bbdb-records
"ext:bbdb-com"
5258 (&optional dont-check-disk already-in-db-buffer
))
5260 (defun anything-c-bbdb-candidates ()
5261 "Return a list of all names in the bbdb database. The format
5262 is \"Firstname Lastname\"."
5263 (mapcar (lambda (bbdb-record)
5264 (replace-regexp-in-string
5266 (concat (aref bbdb-record
0) " " (aref bbdb-record
1))))
5269 (defun anything-c-bbdb-create-contact (actions candidate
)
5270 "Action transformer that returns only an entry to add the
5271 current `anything-pattern' as new contact. All other actions are
5273 (if (string= candidate
"*Add to contacts*")
5274 '(("Add to contacts" .
(lambda (actions)
5275 (bbdb-create-internal
5276 (read-from-minibuffer "Name: " anything-c-bbdb-name
)
5277 (read-from-minibuffer "Company: ")
5278 (read-from-minibuffer "Email: ")
5281 (read-from-minibuffer "Note: ")))))
5284 (defun anything-c-bbdb-get-record (candidate)
5285 "Return record that match CANDIDATE."
5286 (bbdb candidate nil
)
5287 (set-buffer "*BBDB*")
5288 (bbdb-current-record))
5290 (defvar anything-c-bbdb-name nil
5291 "Only for internal use.")
5293 (defvar anything-c-source-bbdb
5295 (candidates . anything-c-bbdb-candidates
)
5296 (action ("Send a mail" . anything-c-bbdb-compose-mail
)
5297 ("View person's data" . anything-c-bbdb-view-person-action
))
5298 (filtered-candidate-transformer .
(lambda (candidates source
)
5299 (setq anything-c-bbdb-name anything-pattern
)
5300 (if (not candidates
)
5301 (list "*Add to contacts*")
5303 (action-transformer .
(lambda (actions candidate
)
5304 (anything-c-bbdb-create-contact actions candidate
))))
5307 http://bbdb.sourceforge.net/")
5308 ;; (anything 'anything-c-source-bbdb)
5310 (defun anything-c-bbdb-view-person-action (candidate)
5311 "View BBDB data of single CANDIDATE or marked candidates."
5312 (anything-aif (anything-marked-candidates)
5313 (let ((bbdb-append-records (length it
)))
5315 (bbdb-redisplay-one-record (anything-c-bbdb-get-record i
))))
5316 (bbdb-redisplay-one-record (anything-c-bbdb-get-record candidate
))))
5318 (defun anything-c-bbdb-collect-mail-addresses ()
5319 "Return a list of all mail addresses of records in bbdb buffer."
5320 (with-current-buffer bbdb-buffer-name
5321 (loop for i in bbdb-records
5322 if
(bbdb-record-net (car i
))
5323 collect
(bbdb-dwim-net-address (car i
)))))
5325 (defun anything-c-bbdb-compose-mail (candidate)
5326 "Compose a mail with all records of bbdb buffer."
5327 (anything-c-bbdb-view-person-action candidate
)
5328 (let* ((address-list (anything-c-bbdb-collect-mail-addresses))
5329 (address-str (mapconcat 'identity address-list
",\n ")))
5330 (compose-mail address-str
)))
5332 ;;; Evaluation Result
5333 (defvar anything-c-source-evaluation-result
5334 '((name .
"Evaluation Result")
5337 (filtered-candidate-transformer .
(lambda (candidates source
)
5340 (with-current-buffer anything-current-buffer
5342 (eval (read anything-pattern
))))
5344 (action ("Copy result to kill-ring" .
(lambda (candidate)
5345 (with-current-buffer anything-buffer
5346 (let ((end (save-excursion
5347 (goto-char (point-max))
5348 (search-backward "\n")
5350 (kill-region (point) end
))))))))
5351 ;; (anything 'anything-c-source-evaluation-result)
5354 (defun anything-eval-expression (arg)
5355 "Preconfigured anything for `anything-c-source-evaluation-result'."
5357 (anything 'anything-c-source-evaluation-result
(when arg
(thing-at-point 'sexp
))
5358 nil nil nil
"*anything eval*"))
5361 (defun anything-eval-expression-with-eldoc ()
5362 "Preconfigured anything for `anything-c-source-evaluation-result' with `eldoc' support. "
5365 (let ((timer (run-with-idle-timer eldoc-idle-delay
5366 'repeat
'anything-eldoc-show-in-eval
)))
5368 (call-interactively 'anything-eval-expression
)
5369 (cancel-timer timer
)))
5370 (call-interactively 'anything-eval-expression
)))
5372 (defun anything-eldoc-show-in-eval ()
5373 "Return eldoc in a tooltip for current minibuffer input."
5374 (let* ((str-all (minibuffer-completion-contents))
5378 (goto-char (point-max))
5379 (unless (looking-back ")\\|\"") (forward-char -
1))
5380 (eldoc-current-symbol))))
5381 (doc (or (eldoc-get-var-docstring sym
)
5382 (eldoc-get-fnsym-args-string
5383 (car (eldoc-fnsym-in-current-sexp))))))
5384 (when doc
(tooltip-show doc
))))
5386 ;;; Calculation Result
5387 (defvar anything-c-source-calculation-result
5388 '((name .
"Calculation Result")
5390 (filtered-candidate-transformer .
(lambda (candidates source
)
5393 (calc-eval anything-pattern
)
5395 (action ("Copy result to kill-ring" . kill-new
))))
5396 ;; (anything 'anything-c-source-calculation-result)
5398 ;;; Google Suggestions
5399 (defvar anything-gg-sug-lgh-flag
0)
5400 (defun anything-c-google-suggest-fetch (input)
5401 "Fetch suggestions for INPUT from XML buffer.
5402 Return an alist with elements like (data . number_results)."
5403 (let ((request (concat anything-c-google-suggest-url
5404 (url-hexify-string input
))))
5407 with result-alist
= (xml-get-children
5408 (car (xml-parse-region (point-min) (point-max)))
5409 'CompleteSuggestion
)
5410 for i in result-alist
5411 for data
= (cdr (caadr (assoc 'suggestion i
)))
5412 for nqueries
= (cdr (caadr (assoc 'num_queries i
)))
5413 for ldata
= (length data
)
5415 (when (> ldata anything-gg-sug-lgh-flag
)
5416 (setq anything-gg-sug-lgh-flag ldata
))
5417 collect
(cons data nqueries
) into cont
5418 finally return cont
)))
5419 (if anything-google-suggest-use-curl-p
5421 (call-process "curl" nil t nil request
)
5423 (with-current-buffer
5424 (url-retrieve-synchronously request
)
5428 (defun anything-c-google-suggest-set-candidates ()
5429 "Set candidates with result and number of google results found."
5430 (let ((suggestions (anything-c-google-suggest-fetch anything-input
)))
5431 (setq suggestions
(loop for i in suggestions
5432 for interval
= (- anything-gg-sug-lgh-flag
(length (car i
)))
5433 for elm
= (concat (car i
)
5434 (make-string (+ 2 interval
) ?
)
5435 "(" (cdr i
) " results)")
5436 collect
(cons elm
(car i
))))
5437 (if (some (lambda (data) (equal (cdr data
) anything-input
)) suggestions
)
5439 ;; if there is no suggestion exactly matching the input then
5440 ;; prepend a Search on Google item to the list
5443 (list (cons (concat "Search for " "'" anything-input
"'" " on Google")
5444 anything-input
))))))
5447 (defun anything-c-google-suggest-action (candidate)
5448 "Default action to jump to a google suggested candidate."
5449 (anything-c-browse-url (concat anything-c-google-suggest-search-url
5450 (url-hexify-string candidate
))))
5453 (defvar anything-c-source-google-suggest
5454 '((name .
"Google Suggest")
5455 (candidates . anything-c-google-suggest-set-candidates
)
5456 (action .
(("Google Search" . anything-c-google-suggest-action
)))
5458 (requires-pattern .
3)
5461 ;; (anything 'anything-c-source-google-suggest)
5463 ;;; Yahoo suggestions
5465 (defun anything-c-yahoo-suggest-fetch (input)
5466 "Fetch Yahoo suggestions for INPUT from XML buffer.
5467 Return an alist with elements like (data . number_results)."
5468 (let ((request (concat anything-c-yahoo-suggest-url
5469 (url-hexify-string input
))))
5472 with result-alist
= (xml-get-children
5473 (car (xml-parse-region (point-min) (point-max)))
5475 for i in result-alist
5476 collect
(caddr i
))))
5477 (with-current-buffer
5478 (url-retrieve-synchronously request
)
5481 (defun anything-c-yahoo-suggest-set-candidates ()
5482 "Set candidates with Yahoo results found."
5483 (let ((suggestions (anything-c-yahoo-suggest-fetch anything-input
)))
5487 (list (cons (concat "Search for " "'" anything-input
"'" " on Yahoo")
5488 anything-input
))))))
5490 (defun anything-c-yahoo-suggest-action (candidate)
5491 "Default action to jump to a Yahoo suggested candidate."
5492 (anything-c-browse-url (concat anything-c-yahoo-suggest-search-url
5493 (url-hexify-string candidate
))))
5495 (defvar anything-c-source-yahoo-suggest
5496 '((name .
"Yahoo Suggest")
5497 (candidates . anything-c-yahoo-suggest-set-candidates
)
5498 (action .
(("Yahoo Search" . anything-c-yahoo-suggest-action
)))
5500 (requires-pattern .
3)
5503 ;; (anything 'anything-c-source-yahoo-suggest)
5506 ;;; Need external program surfraw.
5507 ;;; http://surfraw.alioth.debian.org/
5509 (require 'browse-url
)
5510 (defvar w3m-command nil
)
5511 (defvar anything-c-home-url
"http://www.google.fr"
5512 "*Default url to use as home url.")
5514 (defvar anything-browse-url-default-browser-alist
5515 `((,w3m-command . w3m-browse-url
)
5516 (,browse-url-firefox-program . browse-url-firefox
)
5517 (,browse-url-kde-program . browse-url-kde
)
5518 (,browse-url-gnome-moz-program . browse-url-gnome-moz
)
5519 (,browse-url-mozilla-program . browse-url-mozilla
)
5520 (,browse-url-galeon-program . browse-url-galeon
)
5521 (,browse-url-netscape-program . browse-url-netscape
)
5522 (,browse-url-mosaic-program . browse-url-mosaic
)
5523 (,browse-url-xterm-program . browse-url-text-xterm
))
5524 "*Alist of (executable . function) to try to find a suitable url browser.")
5526 (defun anything-browse-url-default-browser (url &rest args
)
5527 "Find a suitable browser and ask it to load URL."
5528 (let ((default-browser (loop
5529 for i in anything-browse-url-default-browser-alist
5530 when
(and (car i
) (executable-find (car i
))) return
(cdr i
))))
5532 (apply default-browser url args
)
5533 (error "No usable browser found"))))
5535 (defun* anything-c-browse-url
(&optional
(url anything-c-home-url
))
5536 "Default command to browse URL."
5537 (if browse-url-browser-function
5539 (anything-browse-url-default-browser url
)))
5541 (defun anything-c-build-elvi-list ()
5542 "Return list of all engines and descriptions handled by surfraw."
5545 (call-process "surfraw" nil t nil
5547 (split-string (buffer-string) "\n"))))
5549 (defvar anything-surfraw-engines-history nil
)
5551 (defun anything-surfraw (pattern engine
)
5552 "Preconfigured `anything' to search PATTERN with search ENGINE."
5553 (interactive (list (read-string "SearchFor: ")
5556 (anything-c-build-elvi-list)
5558 :name
"Surfraw Search Engines"
5559 :history anything-surfraw-engines-history
)))
5560 (let* ((engine-nodesc (car (split-string engine
)))
5561 (url (with-temp-buffer
5562 (apply 'call-process
"surfraw" nil t nil
5563 (list engine-nodesc
"-p" pattern
))
5564 (replace-regexp-in-string
5565 "\n" "" (buffer-string)))))
5566 (if (string= engine-nodesc
"W")
5567 (anything-c-browse-url)
5568 (anything-c-browse-url url
)
5569 (setq anything-surfraw-engines-history
5570 (cons engine
(delete engine anything-surfraw-engines-history
))))))
5574 (defun anything-emms-stream-edit-bookmark (elm)
5575 "Change the information of current emms-stream bookmark from anything."
5576 (let* ((cur-buf anything-current-buffer
)
5577 (bookmark (assoc elm emms-stream-list
))
5578 (name (read-from-minibuffer "Description: "
5580 (url (read-from-minibuffer "URL: "
5582 (fd (read-from-minibuffer "Feed Descriptor: "
5583 (int-to-string (nth 2 bookmark
))))
5584 (type (read-from-minibuffer "Type (url, streamlist, or lastfm): "
5585 (format "%s" (car (last bookmark
))))))
5588 (when (re-search-forward (concat "^" name
) nil t
)
5590 (emms-stream-delete-bookmark)
5591 (emms-stream-add-bookmark name url
(string-to-number fd
) type
)
5592 (emms-stream-save-bookmarks-file)
5594 (switch-to-buffer cur-buf
)))))
5596 (defun anything-emms-stream-delete-bookmark (elm)
5597 "Delete an emms-stream bookmark from anything."
5598 (let* ((cur-buf anything-current-buffer
)
5599 (bookmark (assoc elm emms-stream-list
))
5600 (name (nth 0 bookmark
)))
5603 (when (re-search-forward (concat "^" name
) nil t
)
5605 (emms-stream-delete-bookmark)
5606 (emms-stream-save-bookmarks-file)
5608 (switch-to-buffer cur-buf
)))))
5610 (defvar anything-c-source-emms-streams
5611 '((name .
"Emms Streams")
5613 (emms-stream-init)))
5614 (candidates .
(lambda ()
5615 (mapcar 'car emms-stream-list
)))
5616 (action .
(("Play" .
(lambda (elm)
5617 (let* ((stream (assoc elm emms-stream-list
))
5618 (fn (intern (concat "emms-play-" (symbol-name (car (last stream
))))))
5619 (url (second stream
)))
5621 ("Delete" . anything-emms-stream-delete-bookmark
)
5622 ("Edit" . anything-emms-stream-edit-bookmark
)))
5623 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
5624 ;; (anything 'anything-c-source-emms-streams)
5626 ;; Don't forget to set `emms-source-file-default-directory'
5627 (defvar anything-c-source-emms-dired
5628 '((name .
"Music Directory")
5629 (candidates .
(lambda ()
5630 (cddr (directory-files emms-source-file-default-directory
))))
5632 (("Play Directory" .
(lambda (item)
5633 (emms-play-directory
5636 emms-source-file-default-directory
))))
5637 ("Open dired in file's directory" .
(lambda (item)
5638 (anything-c-open-dired
5641 emms-source-file-default-directory
))))))
5642 (filtered-candidate-transformer . anything-c-adaptive-sort
)))
5643 ;; (anything 'anything-c-source-emms-dired)
5645 (defface anything-emms-playlist
5646 '((t (:foreground
"Springgreen4" :underline t
)))
5647 "*Face used for tracks in current emms playlist."
5650 (defun anything-c-emms-files-modifier (candidates source
)
5651 (let ((current-playlist (with-current-emms-playlist
5653 with cur-list
= (emms-playlist-tracks-in-region
5654 (point-min) (point-max))
5656 collect
(assoc-default 'name i
)))))
5657 (loop for i in candidates
5658 if
(member (cdr i
) current-playlist
)
5659 collect
(cons (propertize (car i
)
5660 'face
'anything-emms-playlist
)
5662 else collect i into lis
5663 finally return lis
)))
5665 (defun anything-c-emms-play-current-playlist ()
5666 "Play current playlist."
5667 (with-current-emms-playlist
5668 (emms-playlist-first)
5669 (emms-playlist-mode-play-smart)))
5671 (defvar anything-c-source-emms-files
5672 '((name .
"Emms files")
5673 (candidates .
(lambda ()
5674 (loop for v being the hash-values in emms-cache-db
5675 for name
= (assoc-default 'name v
)
5676 for artist
= (or (assoc-default 'info-artist v
) "unknown")
5677 for genre
= (or (assoc-default 'info-genre v
) "unknown")
5678 for tracknum
= (or (assoc-default 'info-tracknumber v
) "unknown")
5679 for song
= (or (assoc-default 'info-title v
) "unknown")
5680 for info
= (concat artist
" - " genre
" - " tracknum
": " song
)
5681 unless
(string-match "^http:" name
) collect
(cons info name
))))
5682 (filtered-candidate-transformer . anything-c-emms-files-modifier
)
5683 (action .
(("Play file" . emms-play-file
)
5684 ("Add to Playlist and play (C-u clear current)"
5685 .
(lambda (candidate)
5686 (when anything-current-prefix-arg
5687 (emms-playlist-current-clear))
5689 (mapc 'emms-add-playlist-file
(anything-marked-candidates))
5690 (unless emms-player-playing-p
5691 (anything-c-emms-play-current-playlist))))))))
5693 ;; (anything 'anything-c-source-emms-files)
5695 ;;; Jabber Contacts (jabber.el)
5696 (defun anything-c-jabber-online-contacts ()
5697 "List online Jabber contacts."
5700 (dolist (item (jabber-concat-rosters) jids
)
5701 (when (get item
'connected
)
5702 (push (if (get item
'name
)
5703 (cons (get item
'name
) item
)
5704 (cons (symbol-name item
) item
)) jids
))))))
5706 (defvar anything-c-source-jabber-contacts
5707 '((name .
"Jabber Contacts")
5708 (init .
(lambda () (require 'jabber
)))
5709 (candidates .
(lambda () (mapcar 'car
(anything-c-jabber-online-contacts))))
5710 (action .
(lambda (x)
5712 (jabber-read-account)
5714 (cdr (assoc x
(anything-c-jabber-online-contacts)))))))))
5715 ;; (anything 'anything-c-source-jabber-contacts)
5719 (defvar anything-source-select-buffer
"*anything source select*")
5720 (defvar anything-c-source-call-source
5721 `((name .
"Call anything source")
5722 (candidate-number-limit)
5723 (candidates .
(lambda ()
5724 (loop for vname in
(all-completions "anything-c-source-" obarray
)
5725 for var
= (intern vname
)
5726 for name
= (ignore-errors (assoc-default 'name
(symbol-value var
)))
5727 if name collect
(cons (format "%s `%s'"
5728 name
(propertize vname
'face
'font-lock-variable-name-face
))
5730 (action .
(("Invoke anything with selected source" .
5732 (setq anything-candidate-number-limit
9999)
5733 (anything candidate nil nil nil nil
5734 anything-source-select-buffer
)))
5735 ("Describe variable" . describe-variable
)
5736 ("Find variable" . find-variable
)))
5737 (persistent-action . describe-variable
)
5738 (persistent-help .
"Show description of this source")))
5739 ;; (anything 'anything-c-source-call-source)
5742 (defun anything-call-source ()
5743 "Preconfigured `anything' to call anything source."
5745 (anything 'anything-c-source-call-source nil nil nil nil
5746 anything-source-select-buffer
))
5748 (defun anything-call-source-from-anything ()
5749 "Call anything source within `anything' session."
5751 (setq anything-input-idle-delay
0)
5752 (anything-set-sources '(anything-c-source-call-source)))
5754 ;;; Execute Preconfigured anything.
5755 (defvar anything-c-source-anything-commands
5756 '((name .
"Preconfigured Anything")
5757 (candidates . anything-c-anything-commands-candidates
)
5759 (candidate-number-limit)))
5760 ;; (anything 'anything-c-source-anything-commands)
5762 (defun anything-c-anything-commands-candidates ()
5763 (loop for
(cmd . desc
) in
(anything-c-list-preconfigured-anything)
5764 collect
(cons (if (where-is-internal cmd nil t
)
5765 (substitute-command-keys (format "M-x %s (\\[%s]) : %s" cmd cmd desc
))
5766 (substitute-command-keys (format "\\[%s] : %s" cmd desc
)))
5770 (defun anything-execute-anything-command ()
5771 "Preconfigured `anything' to execute preconfigured `anything'."
5773 (anything-other-buffer 'anything-c-source-anything-commands
5774 "*anything commands*"))
5777 (defun anything-c-occur-init ()
5778 (anything-candidate-buffer anything-current-buffer
))
5780 (defun anything-c-occur-get-line (s e
)
5781 (format "%7d:%s" (line-number-at-pos (1- s
)) (buffer-substring s e
)))
5783 (defvar anything-c-source-occur
5785 (init . anything-c-occur-init
)
5786 (candidates-in-buffer)
5788 (get-line . anything-c-occur-get-line
)
5791 (requires-pattern .
1)
5794 ;; (anything 'anything-c-source-occur)
5796 ;;; Anything browse code.
5797 (defun anything-c-browse-code-get-line (beg end
)
5798 "Select line if it match the regexp corresponding to current `major-mode'.
5799 Line is parsed for BEG position to END position."
5800 (let ((str-line (buffer-substring beg end
))
5801 (regexp (assoc-default major-mode
5802 anything-c-browse-code-regexp-alist
))
5803 (num-line (if (string= anything-pattern
"") beg
(1- beg
))))
5804 (when (and regexp
(string-match regexp str-line
))
5805 (format "%4d:%s" (line-number-at-pos num-line
) str-line
))))
5808 (defvar anything-c-source-browse-code
5809 '((name .
"Browse code")
5811 (anything-candidate-buffer anything-current-buffer
)
5812 (with-current-buffer anything-current-buffer
5813 (jit-lock-fontify-now))))
5814 (candidates-in-buffer)
5815 (get-line . anything-c-browse-code-get-line
)
5819 ;; Do many actions for input
5820 (defvar anything-c-source-create
5824 (action-transformer . anything-create--actions
))
5825 "Do many create actions from `anything-pattern'.
5826 See also `anything-create--actions'.")
5827 ;; (anything 'anything-c-source-create)
5829 (defun anything-create-from-anything ()
5830 "Run `anything-create' from `anything' as a fallback."
5832 (anything-run-after-quit 'anything-create nil anything-pattern
))
5835 (defun anything-create (&optional string initial-input
)
5836 "Preconfigured `anything' to do many create actions from STRING.
5837 See also `anything-create--actions'."
5839 (setq string
(or string
(read-string "Create Anything: " initial-input
)))
5840 (anything '(((name .
"Anything Create")
5841 (header-name .
(lambda (_) (format "Action for \"%s\"" string
)))
5842 (candidates . anything-create--actions
)
5843 (candidate-number-limit)
5844 (action .
(lambda (func) (funcall func string
)))))))
5846 (defun anything-create--actions (&rest ignored
)
5847 "Default actions for `anything-create' / `anything-c-source-create'."
5849 (lambda (pair) (and (consp pair
) (functionp (cdr pair
))))
5850 (append anything-create--actions-private
5851 '(("find-file" . find-file
)
5852 ("find-file other window" . find-file-other-window
)
5853 ("New buffer" . switch-to-buffer
)
5854 ("New buffer other window" . switch-to-buffer-other-window
)
5855 ("Bookmark Set" . bookmark-set
)
5857 (lambda (x) (set-register (read-char "Register: ") x
)))
5858 ("Insert Linkd star" . linkd-insert-star
)
5859 ("Insert Linkd Tag" . linkd-insert-tag
)
5860 ("Insert Linkd Link" . linkd-insert-link
)
5861 ("Insert Linkd Lisp" . linkd-insert-lisp
)
5862 ("Insert Linkd Wiki" . linkd-insert-wiki
)
5863 ("Google Search" . google
)))))
5865 ;; Minibuffer History
5866 (defvar anything-c-source-minibuffer-history
5867 '((name .
"Minibuffer History")
5868 (header-name .
(lambda (name) (format "%s (%s)" name minibuffer-history-variable
)))
5869 (candidates .
(lambda () (let ((history (symbol-value minibuffer-history-variable
)))
5870 (if (consp (car history
))
5871 (mapcar 'prin1-to-string history
)
5875 ;; (anything 'anything-c-source-minibuffer-history)
5878 (defvar anything-c-source-elscreen
5879 '((name .
"Elscreen")
5880 (candidates .
(lambda ()
5881 (if (cdr (elscreen-get-screen-to-name-alist))
5883 (loop for sname in
(elscreen-get-screen-to-name-alist)
5884 append
(list (format "[%d] %s" (car sname
) (cdr sname
))) into lst
5885 finally
(return lst
))
5886 #'(lambda (a b
) (compare-strings a nil nil b nil nil
))))))
5887 (action .
(("Change Screen".
5889 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))))
5892 (dolist (i (anything-marked-candidates))
5893 (elscreen-goto (- (aref i
1) (aref "0" 0)))
5897 (elscreen-goto (- (aref candidate
1) (aref "0" 0)))
5898 (elscreen-kill-others)))))))
5899 ;; (anything 'anything-c-source-elscreen)
5904 (defvar anything-c-top-command
"COLUMNS=%s top -b -n 1"
5905 "Top command (batch mode). %s is replaced with `frame-width'.")
5906 (defvar anything-c-source-top
5907 '((name .
"Top (Press C-c C-u to refresh)")
5908 (init . anything-c-top-init
)
5909 (candidates-in-buffer)
5910 (display-to-real . anything-c-top-display-to-real
)
5911 (update . anything-c-top-update
)
5912 (persistent-action . anything-c-top-sh-persistent-action
)
5913 (persistent-help .
"SIGTERM")
5915 ("kill (TERM)" .
(lambda (pid) (anything-c-top-sh (format "kill -TERM %s" pid
))))
5916 ("kill (KILL)" .
(lambda (pid) (anything-c-top-sh (format "kill -KILL %s" pid
))))
5917 ("Copy PID" .
(lambda (pid) (kill-new pid
))))))
5918 ;; (anything 'anything-c-source-top)
5920 (defun anything-c-top-sh (cmd)
5921 (message "Executed %s\n%s" cmd
(shell-command-to-string cmd
)))
5923 (defun anything-c-top-sh-persistent-action (pid)
5924 (delete-other-windows)
5925 (anything-c-top-sh (format "kill -TERM %s" pid
))
5926 (anything-force-update))
5928 (defun anything-c-top-init ()
5929 (with-current-buffer (anything-candidate-buffer 'global
)
5930 (call-process-shell-command
5931 (format anything-c-top-command
5932 (- (frame-width) (if anything-enable-digit-shortcuts
4 0)))
5933 nil
(current-buffer))))
5935 (defun anything-c-top-display-to-real (line)
5936 (car (split-string line
)))
5938 (defun anything-c-top-update ()
5939 (let ((anything-source-name (assoc-default 'name anything-c-source-top
))) ;UGLY HACK
5940 (anything-c-top-init)))
5943 (defun anything-top ()
5944 "Preconfigured `anything' for top command."
5946 (let ((anything-samewindow t
)
5947 (anything-enable-shortcuts)
5948 (anything-display-function 'anything-default-display-buffer
)
5949 (anything-candidate-number-limit 9999))
5950 (save-window-excursion
5951 (delete-other-windows)
5952 (anything-other-buffer 'anything-c-source-top
"*anything top*"))))
5955 (defvar anything-c-source-absolute-time-timers
5956 '((name .
"Absolute Time Timers")
5957 (candidates . timer-list
)
5959 ;; (anything 'anything-c-source-absolute-time-timers)
5961 (defvar anything-c-source-idle-time-timers
5962 '((name .
"Idle Time Timers")
5963 (candidates . timer-idle-list
)
5965 ;; (anything 'anything-c-source-idle-time-timers)
5967 (defun anything-c-timer-real-to-display (timer)
5968 (destructuring-bind (triggered t1 t2 t3 repeat-delay func args idle-delay
)
5969 (append timer nil
) ;use `append' to convert vector->list
5970 (format "%s repeat=%5S %s(%s)"
5971 (let ((time (list t1 t2 t3
)))
5973 (format-time-string "idle-for=%5s" time
)
5974 (format-time-string "%m/%d %T" time
)))
5977 (mapconcat 'prin1-to-string args
" "))))
5979 ;;; X RandR resolution change
5980 ;;; FIXME I do not care multi-display.
5981 (defvar anything-c-xrandr-output
"VGA")
5982 (defvar anything-c-xrandr-screen
"0")
5983 (defvar anything-c-source-xrandr-change-resolution
5984 '((name .
"Change Resolution")
5988 (call-process "xrandr" nil
(current-buffer) nil
5989 "--screen" anything-c-xrandr-screen
"-q")
5991 (loop while
(re-search-forward " \\([0-9]+x[0-9]+\\)" nil t
)
5992 collect
(match-string 1)))))
5994 ("Change Resolution" .
(lambda (mode)
5995 (call-process "xrandr" nil nil nil
5996 "--screen" anything-c-xrandr-screen
5997 "--output" anything-c-xrandr-output
5999 ;; (anything 'anything-c-source-xrandr-change-resolution)
6002 (defun anything-c-persistent-xfont-action (elm)
6003 "Show current font temporarily"
6004 (let ((current-font (cdr (assoc 'font
(frame-parameters))))
6007 (progn (set-frame-font default-font
'keep-size
) (sit-for 2))
6008 (set-frame-font current-font
))))
6010 (defvar anything-c-xfonts-cache nil
)
6011 (defvar anything-c-source-xfonts
6012 '((name .
"X Fonts")
6014 (unless anything-c-xfonts-cache
6015 (setq anything-c-xfonts-cache
6016 (x-list-fonts "*")))))
6017 (candidates . anything-c-xfonts-cache
)
6018 (action .
(("Copy to kill ring" .
(lambda (elm)
6020 ("Set Font" .
(lambda (elm)
6022 (set-frame-font elm
'keep-size
)
6023 (message "New font have been copied to kill ring")))))
6024 (persistent-action . anything-c-persistent-xfont-action
)
6025 (persistent-help .
"Switch to this font temporarily")))
6028 (defun anything-select-xfont ()
6029 "Preconfigured `anything' to select Xfont."
6031 (anything-other-buffer 'anything-c-source-xfonts
"*anything select* xfont"))
6033 ;; (anything 'anything-c-source-xfonts)
6037 (defvar anything-c-source-time-world
6038 '((name .
"Time World List")
6040 (let ((anything-buffer (anything-candidate-buffer 'global
)))
6041 (with-current-buffer anything-buffer
6042 (display-time-world-display display-time-world-list
)))))
6043 (candidates-in-buffer)))
6046 (defun anything-world-time ()
6047 "Preconfigured `anything' to show world time."
6049 (anything-other-buffer 'anything-c-source-time-world
"*anything world time*"))
6051 ;;; Source for Debian/Ubuntu users
6052 (defvar anything-c-source-apt
6054 (init . anything-c-apt-init
)
6055 (candidates-in-buffer)
6056 (candidate-transformer anything-c-apt-candidate-transformer
)
6057 (display-to-real . anything-c-apt-display-to-real
)
6058 (candidate-number-limit .
9999)
6060 ("Show package description" . anything-c-apt-cache-show
)
6061 ("Install package" . anything-c-apt-install
)
6062 ("Remove package" . anything-c-apt-uninstall
)
6063 ("Purge package" . anything-c-apt-purge
))
6064 (persistent-action . anything-c-apt-persistent-action
)
6065 (persistent-help .
"Show - C-u Refresh")))
6066 ;; (anything 'anything-c-source-apt)
6068 (defvar anything-c-apt-query
"emacs")
6069 (defvar anything-c-apt-search-command
"apt-cache search '%s'")
6070 (defvar anything-c-apt-show-command
"apt-cache show '%s'")
6071 (defvar anything-c-apt-installed-packages nil
)
6073 (defface anything-apt-installed
6074 '((t (:foreground
"green")))
6075 "*Face used for apt installed candidates."
6078 (defun anything-c-apt-refresh ()
6079 "Refresh installed candidates list."
6080 (setq anything-c-apt-installed-packages nil
)
6081 (anything-force-update))
6083 (defun anything-c-apt-persistent-action (candidate)
6084 "Persistent action for APT source."
6085 (if current-prefix-arg
6086 (anything-c-apt-refresh)
6087 (anything-c-apt-cache-show candidate
)))
6090 (defun anything-apt (query)
6091 "Preconfigured `anything' : frontend of APT package manager."
6092 (interactive "sAPT search: ")
6093 (let ((anything-c-apt-query query
))
6094 (anything 'anything-c-source-apt
)))
6096 (defun anything-c-apt-candidate-transformer (candidates)
6097 "Show installed candidates in a different color."
6100 for cand in candidates
6101 for name
= (anything-c-apt-display-to-real cand
)
6102 if
(member name anything-c-apt-installed-packages
)
6103 collect
(propertize cand
'face
'anything-apt-installed
) into all
6104 else collect cand into all finally return all
))
6106 (defun anything-c-apt-init ()
6107 "Initialize list of debian packages."
6108 (unless anything-c-apt-installed-packages
6109 (message "Updating installed candidate list...")
6110 (setq anything-c-apt-installed-packages
6112 (call-process-shell-command "dpkg --get-selections"
6113 nil
(current-buffer))
6114 (loop for i in
(split-string (buffer-string) "\n" t
)
6115 collect
(car (split-string i
))))))
6116 (with-current-buffer
6117 (anything-candidate-buffer
6118 (get-buffer-create (format "*anything-apt:%s*" anything-c-apt-query
)))
6120 (call-process-shell-command
6121 (format anything-c-apt-search-command anything-c-apt-query
)
6122 nil
(current-buffer)))
6123 (message "Updating installed candidate list...done"))
6125 (defun anything-c-apt-display-to-real (line)
6126 "Return only name of a debian package.
6127 LINE is displayed like:
6128 package name - description."
6129 (car (split-string line
" - ")))
6132 (defun anything-c-shell-command-if-needed (command)
6133 (interactive "sShell command: ")
6134 (if (get-buffer command
) ; if the buffer already exists
6135 (switch-to-buffer command
) ; then just switch to it
6136 (switch-to-buffer command
) ; otherwise create it
6137 (insert (shell-command-to-string command
))))
6139 (defun anything-c-apt-cache-show (package)
6140 (anything-c-shell-command-if-needed (format anything-c-apt-show-command package
)))
6142 (defun anything-c-apt-install (package)
6143 (anything-c-apt-install1 package
:action
'install
))
6145 (defun anything-c-apt-uninstall (package)
6146 (anything-c-apt-install1 package
:action
'uninstall
))
6148 (defun anything-c-apt-purge (package)
6149 (anything-c-apt-install1 package
:action
'purge
))
6151 (defun* anything-c-apt-install1
(candidate &key action
)
6152 (ansi-term (getenv "SHELL") "anything apt")
6154 (let ((command (case action
6155 ('install
"sudo apt-get install '%s'")
6156 ('uninstall
"sudo apt-get remove '%s'")
6157 ('purge
"sudo apt-get purge '%s'")
6158 (t (error "Unknow action"))))
6160 (goto-char (point-max))
6161 (insert (format command candidate
))
6163 (if (y-or-n-p (format "%s package" (symbol-name action
)))
6165 (setq anything-c-external-commands-list nil
)
6166 (setq anything-c-apt-installed-packages nil
)
6167 (term-char-mode) (term-send-input))
6168 (delete-region beg end
) (term-send-eof) (kill-buffer))))
6170 ;; (anything-c-apt-install "jed")
6172 ;;; Sources for gentoo users
6173 (defvar anything-c-gentoo-use-flags nil
)
6174 (defvar anything-c-gentoo-buffer
"*anything-gentoo-output*")
6175 (defvar anything-c-cache-gentoo nil
)
6176 (defvar anything-c-cache-world nil
)
6177 (defvar anything-c-source-gentoo
6178 '((name .
"Portage sources")
6180 (get-buffer-create anything-c-gentoo-buffer
)
6181 (unless anything-c-cache-gentoo
6182 (anything-c-gentoo-setup-cache))
6183 (unless anything-c-cache-world
6184 (setq anything-c-cache-world
(anything-c-gentoo-get-world)))
6185 (anything-c-gentoo-init-list)))
6186 (candidates-in-buffer)
6188 (candidate-transformer anything-c-highlight-world
)
6189 (action .
(("Show package" .
(lambda (elm)
6190 (anything-c-gentoo-eshell-action elm
"eix")))
6191 ("Show history" .
(lambda (elm)
6192 (if (member elm anything-c-cache-world
)
6193 (anything-c-gentoo-eshell-action elm
"genlop -qe")
6194 (message "No infos on packages not yet installed"))))
6195 ("Copy in kill-ring" . kill-new
)
6196 ("insert at point" . insert
)
6197 ("Browse HomePage" .
(lambda (elm)
6198 (let ((urls (anything-c-gentoo-get-url elm
)))
6199 (browse-url (anything-comp-read "Url: " urls
:must-match t
)))))
6200 ("Show extra infos" .
(lambda (elm)
6201 (if (member elm anything-c-cache-world
)
6202 (anything-c-gentoo-eshell-action elm
"genlop -qi")
6203 (message "No infos on packages not yet installed"))))
6204 ("Show use flags" .
(lambda (elm)
6205 (anything-c-gentoo-default-action elm
"equery" "-C" "u")
6206 (font-lock-add-keywords nil
'(("^\+.*" . font-lock-variable-name-face
)))
6207 (font-lock-mode 1)))
6208 ("Run emerge pretend" .
(lambda (elm)
6209 (anything-c-gentoo-eshell-action elm
"emerge -p")))
6210 ("Emerge" .
(lambda (elm)
6211 (anything-gentoo-install elm
:action
'install
)))
6212 ("Unmerge" .
(lambda (elm)
6213 (anything-gentoo-install elm
:action
'uninstall
)))
6214 ("Show dependencies" .
(lambda (elm)
6215 (anything-c-gentoo-default-action elm
"equery" "-C" "d")))
6216 ("Show related files" .
(lambda (elm)
6217 (anything-c-gentoo-default-action elm
"equery" "files")))
6218 ("Refresh" .
(lambda (elm)
6219 (anything-c-gentoo-setup-cache)
6220 (setq anything-c-cache-world
(anything-c-gentoo-get-world))))))))
6222 ;; (anything 'anything-c-source-gentoo)
6224 (defun* anything-gentoo-install
(candidate &key action
)
6225 (setq anything-c-external-commands-list nil
)
6226 (ansi-term (getenv "SHELL") "Gentoo emerge")
6228 (let ((command (case action
6229 ('install
"sudo emerge -av ")
6230 ('uninstall
"sudo emerge -avC ")
6231 (t (error "Unknow action"))))
6232 (elms (mapconcat 'identity
(anything-marked-candidates) " "))
6234 (goto-char (point-max))
6235 (insert (concat command elms
))
6237 (term-char-mode) (term-send-input)))
6239 (defun anything-c-gentoo-default-action (elm command
&rest args
)
6240 "Gentoo default action that use `anything-c-gentoo-buffer'."
6241 (if (member elm anything-c-cache-world
)
6243 (switch-to-buffer anything-c-gentoo-buffer
)
6245 (let ((com-list (append args
(list elm
))))
6246 (apply #'call-process command nil t nil
6248 (message "No infos on packages not yet installed")))
6250 (defvar anything-c-source-use-flags
6251 '((name .
"Use Flags")
6253 (unless anything-c-gentoo-use-flags
6254 (anything-c-gentoo-setup-use-flags-cache))
6255 (anything-c-gentoo-get-use)))
6256 (candidates-in-buffer)
6258 (candidate-transformer anything-c-highlight-local-use
)
6259 (action .
(("Description"
6261 (switch-to-buffer anything-c-gentoo-buffer
)
6263 (apply #'call-process
"euse" nil t nil
6266 (font-lock-add-keywords nil
`((,elm . font-lock-variable-name-face
)))
6267 (font-lock-mode 1)))
6270 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -E")))
6273 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -D")))
6276 (anything-c-gentoo-eshell-action elm
"*sudo -p Password: euse -P")))
6277 ("Show which dep use this flag"
6279 (switch-to-buffer anything-c-gentoo-buffer
)
6281 (apply #'call-process
"equery" nil t nil
6287 ;; (anything 'anything-c-source-use-flags)
6289 (defun anything-c-gentoo-init-list ()
6290 "Initialize buffer with all packages in Portage."
6291 (let* ((portage-buf (get-buffer-create "*anything-gentoo*"))
6292 (buf (anything-candidate-buffer 'portage-buf
)))
6293 (with-current-buffer buf
6294 (dolist (i anything-c-cache-gentoo
)
6295 (insert (concat i
"\n"))))))
6297 (defun anything-c-gentoo-setup-cache ()
6298 "Set up `anything-c-cache-gentoo'"
6299 (setq anything-c-cache-gentoo
6300 (split-string (with-temp-buffer
6301 (call-process "eix" nil t nil
6305 (defun anything-c-gentoo-eshell-action (elm command
)
6306 (when (get-buffer "*EShell Command Output*")
6307 (kill-buffer "*EShell Command Output*"))
6308 (message "Wait searching...")
6309 (let ((buf-fname (buffer-file-name anything-current-buffer
)))
6310 (if (and buf-fname
(string-match tramp-file-name-regexp buf-fname
))
6312 (save-window-excursion
6313 (pop-to-buffer "*scratch*")
6314 (eshell-command (format "%s %s" command elm
)))
6315 (pop-to-buffer "*EShell Command Output*"))
6316 (eshell-command (format "%s %s" command elm
)))))
6318 (defun anything-c-gentoo-get-use ()
6319 "Initialize buffer with all use flags."
6320 (let* ((use-buf (get-buffer-create "*anything-gentoo-use*"))
6321 (buf (anything-candidate-buffer 'use-buf
)))
6322 (with-current-buffer buf
6323 (dolist (i anything-c-gentoo-use-flags
)
6324 (insert (concat i
"\n"))))))
6327 (defun anything-c-gentoo-setup-use-flags-cache ()
6328 "Setup `anything-c-gentoo-use-flags'"
6329 (setq anything-c-gentoo-use-flags
6330 (split-string (with-temp-buffer
6331 (call-process "eix" nil t nil
6332 "--print-all-useflags")
6335 (defun anything-c-gentoo-get-url (elm)
6336 "Return a list of urls from eix output."
6338 with url-list
= (split-string
6340 (call-process "eix" nil t nil
6341 elm
"--format" "<homepage>\n")
6345 when
(and (string-match "^http://.*" i
)
6346 (not (member i all
)))
6348 finally return all
))
6350 (defun anything-c-gentoo-get-world ()
6351 "Return list of all installed package on your system."
6352 (split-string (with-temp-buffer
6353 (call-process "qlist" nil t nil
6357 (defun anything-c-gentoo-get-local-use ()
6358 (split-string (with-temp-buffer
6359 (call-process "portageq" nil t nil
6364 (defface anything-gentoo-match-face
'((t (:foreground
"red")))
6365 "Face for anything-gentoo installed packages."
6366 :group
'traverse-faces
)
6368 (defun anything-c-highlight-world (eix)
6369 "Highlight all installed package."
6371 if
(member i anything-c-cache-world
)
6372 collect
(propertize i
'face
'anything-gentoo-match-face
)
6376 (defun anything-c-highlight-local-use (use-flags)
6377 (let ((local-uses (anything-c-gentoo-get-local-use)))
6378 (loop for i in use-flags
6379 if
(member i local-uses
)
6380 collect
(propertize i
'face
'anything-gentoo-match-face
)
6384 (defvar anything-c-source-emacs-process
6385 '((name .
"Emacs Process")
6386 (candidates .
(lambda () (mapcar #'process-name
(process-list))))
6387 (persistent-action .
(lambda (elm)
6388 (delete-process (get-process elm
))
6389 (anything-delete-current-selection)))
6390 (persistent-help .
"Kill Process")
6391 (action ("Kill Process" .
(lambda (elm)
6392 (delete-process (get-process elm
)))))))
6394 ;; (anything 'anything-c-source-emacs-process)
6396 ;; Run Externals commands within Emacs
6397 (defmacro* anything-comp-hash-get-items
(hash-table &key test
)
6398 "Get the list of all keys/values of hash-table."
6399 `(let ((li-items ()))
6400 (maphash #'(lambda (x y
)
6402 (when (funcall ,test y
)
6403 (push (list x y
) li-items
))
6404 (push (list x y
) li-items
)))
6408 (defun anything-comp-read-get-candidates (collection &optional test sort-fn
)
6409 "Convert COLLECTION to list removing elements that don't match TEST.
6410 SORT-FN is a predicate to sort COLLECTION.
6411 If collection is an `obarray', a TEST is needed. See `obarray'."
6413 (cond ((and (listp collection
) test
)
6414 (loop for i in collection when
(funcall test i
) collect i
))
6415 ((and (eq collection obarray
) test
)
6416 (loop for s being the symbols of collection
6417 when
(funcall test s
) collect s
))
6418 ((and (vectorp collection
) test
)
6419 (loop for i across collection when
(funcall test i
) collect i
))
6420 ((vectorp collection
)
6421 (loop for i across collection collect i
))
6422 ((and (hash-table-p collection
) test
)
6423 (anything-comp-hash-get-items collection
:test test
))
6424 ((hash-table-p collection
)
6425 (anything-comp-hash-get-items collection
))
6427 (if sort-fn
(sort cands sort-fn
) cands
)))
6429 (defun anything-cr-default-transformer (candidates source
)
6430 "Default filter candidate function for `anything-comp-read'.
6431 Do nothing, just return candidate list unmodified."
6434 (defun* anything-comp-read
(prompt collection
6438 (buffer "*Anything Completions*")
6440 (requires-pattern 0)
6442 (persistent-action nil
)
6443 (persistent-help "DoNothing")
6444 (name "Anything Completions")
6446 (fc-transformer 'anything-cr-default-transformer
)
6447 (marked-candidates nil
))
6448 "Anything `completing-read' emulation.
6449 PROMPT is the prompt name to use.
6450 COLLECTION can be a list, vector, obarray or hash-table.
6453 TEST: A predicate called with one arg i.e candidate.
6454 INITIAL-INPUT: Same as initial-input arg in `anything'.
6455 BUFFER: Name of anything-buffer.
6456 MUST-MATCH: Candidate selected must be one of COLLECTION.
6457 REQUIRES-PATTERN: Same as anything attribute, default is 0.
6458 HISTORY: A list containing specific history, default is nil.
6459 When it is non--nil, all elements of HISTORY are displayed in
6460 anything-buffer before COLLECTION.
6461 PERSISTENT-ACTION: A function called with one arg i.e candidate.
6462 PERSISTENT-HELP: A string to document PERSISTENT-ACTION.
6463 NAME: The name related to this local source.
6464 SORT: A predicate to give to `sort' e.g `string-lessp'.
6465 FC-TRANSFORMER: A `filtered-candidate-transformer' function.
6466 MARKED-CANDIDATES: If non--nil return candidate or marked candidates as a list.
6468 Any prefix args passed during `anything-comp-read' invocation will be recorded
6469 in `anything-current-prefix-arg', otherwise if prefix args where given before
6470 `anything-comp-read' invocation, the value of `current-prefix-arg' will be used.
6471 That's mean you can pass prefix arg before or after calling
6472 a command that use `anything-comp-read'."
6473 (when (get-buffer anything-action-buffer
)
6474 (kill-buffer anything-action-buffer
))
6475 (flet ((action-fn (candidate)
6476 (if marked-candidates
6477 (anything-marked-candidates)
6478 (identity candidate
))))
6481 `(((name .
,(format "%s History" name
))
6482 (candidates .
(lambda ()
6483 (anything-comp-read-get-candidates history
)))
6485 (persistent-action .
,persistent-action
)
6486 (persistent-help .
,persistent-help
)
6487 (action .
,'action-fn
))
6491 (let ((cands (anything-comp-read-get-candidates
6492 collection test sort
)))
6493 (if (or must-match
(string= anything-pattern
""))
6494 cands
(append (list anything-pattern
) cands
)))))
6495 (filtered-candidate-transformer ,fc-transformer
)
6496 (requires-pattern .
,requires-pattern
)
6497 (persistent-action .
,persistent-action
)
6498 (persistent-help .
,persistent-help
)
6500 (action .
,'action-fn
)))
6501 :input initial-input
6507 (defun anything-c-get-pid-from-process-name (process-name)
6508 "Get pid from running process PROCESS-NAME."
6509 (loop with process-list
= (list-system-processes)
6510 for pid in process-list
6511 for process
= (assoc-default 'comm
(process-attributes pid
))
6512 when
(and process
(string-match process-name process
))
6516 (defun anything-run-or-raise (exe &optional file
)
6517 "Generic command that run asynchronously EXE.
6518 If EXE is already running just jump to his window if `anything-raise-command'
6520 When FILE argument is provided run EXE with FILE.
6521 In this case EXE must be provided as \"EXE %s\"."
6522 (let ((real-com (car (split-string (replace-regexp-in-string "'%s'" "" exe
)))))
6523 (if (or (get-process real-com
)
6524 (anything-c-get-pid-from-process-name real-com
))
6525 (if anything-raise-command
6526 (shell-command (format anything-raise-command real-com
))
6527 (error "Error: %s is already running" real-com
))
6528 (when (member real-com anything-c-external-commands-list
)
6529 (message "Starting %s..." real-com
)
6531 (start-process-shell-command real-com nil
(format exe file
))
6532 (start-process-shell-command real-com nil real-com
))
6533 (set-process-sentinel
6534 (get-process real-com
)
6535 #'(lambda (process event
)
6536 (when (and (string= event
"finished\n")
6537 anything-raise-command
)
6538 (shell-command (format anything-raise-command
"emacs")))
6539 (message "%s process...Finished." process
))))
6540 (setq anything-c-external-commands-list
6541 (cons real-com
(delete real-com anything-c-external-commands-list
))))))
6544 (defvar anything-external-command-history nil
)
6546 (defun anything-c-run-external-command (program)
6547 "Preconfigured `anything' to run External PROGRAM asyncronously from Emacs.
6548 If program is already running exit with error.
6549 You can set your own list of commands with
6550 `anything-c-external-commands-list'."
6554 (anything-c-external-commands-list-1 'sort
)
6556 :name
"External Commands"
6557 :history anything-external-command-history
)))
6558 (anything-run-or-raise program
)
6559 (setq anything-external-command-history
6560 (cons program
(delete program
6561 (loop for i in anything-external-command-history
6562 when
(executable-find i
) collect i
)))))
6564 (defsubst* anything-c-position
(item seq
&key
(test 'eq
))
6565 "A simple and faster replacement of CL `position'."
6566 (loop for i in seq for index from
0
6567 when
(funcall test i item
) return index
))
6569 (defvar anything-c-source-ratpoison-commands
6570 '((name .
"Ratpoison Commands")
6571 (init . anything-c-ratpoison-commands-init
)
6572 (candidates-in-buffer)
6573 (action ("Execute the command" . anything-c-ratpoison-commands-execute
))
6574 (display-to-real . anything-c-ratpoison-commands-display-to-real
)
6575 (candidate-number-limit)))
6576 ;; (anything 'anything-c-source-ratpoison-commands)
6578 (defun anything-c-ratpoison-commands-init ()
6579 (unless (anything-candidate-buffer)
6580 (with-current-buffer (anything-candidate-buffer 'global
)
6581 ;; with ratpoison prefix key
6583 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help"))
6584 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
6585 (replace-match "<ratpoison> \\1: \\2"))
6586 (goto-char (point-max))
6589 (call-process "ratpoison" nil
(current-buffer) nil
"-c" "help top"))
6590 (while (re-search-forward "^\\([^ ]+\\) \\(.+\\)$" nil t
)
6591 (replace-match "\\1: \\2")))))
6593 (defun anything-c-ratpoison-commands-display-to-real (display)
6594 (and (string-match ": " display
)
6595 (substring display
(match-end 0))))
6597 (defun anything-c-ratpoison-commands-execute (candidate)
6598 (call-process "ratpoison" nil nil nil
"-ic" candidate
))
6601 (defun anything-ratpoison-commands ()
6602 "Preconfigured `anything' to execute ratpoison commands."
6604 (anything-other-buffer 'anything-c-source-ratpoison-commands
6605 "*anything ratpoison commands*"))
6607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6609 (defvar anything-c-external-commands-list nil
6610 "A list of all external commands the user can execute. If this
6611 variable is not set by the user, it will be calculated
6614 (defun anything-c-external-commands-list-1 (&optional sort
)
6615 "Returns a list of all external commands the user can execute.
6616 If `anything-c-external-commands-list' is non-nil it will
6617 return its contents. Else it calculates all external commands
6618 and sets `anything-c-external-commands-list'."
6619 (if anything-c-external-commands-list
6620 anything-c-external-commands-list
6621 (setq anything-c-external-commands-list
6623 with paths
= (split-string (getenv "PATH") path-separator
)
6624 with completions
= ()
6626 when
(and (file-exists-p dir
) (file-accessible-directory-p dir
))
6627 for lsdir
= (loop for i in
(directory-files dir t
)
6628 for bn
= (file-name-nondirectory i
)
6629 when
(and (not (member bn completions
))
6630 (not (file-directory-p i
))
6631 (file-executable-p i
))
6633 append lsdir into completions
6634 finally return
(if sort
(sort completions
'string-lessp
) completions
)))))
6637 (defun anything-c-file-buffers (filename)
6638 "Returns a list of buffer names corresponding to FILENAME."
6639 (let ((name (expand-file-name filename
))
6641 (dolist (buf (buffer-list) buf-list
)
6642 (let ((bfn (buffer-file-name buf
)))
6643 (when (and bfn
(string= name bfn
))
6644 (push (buffer-name buf
) buf-list
))))))
6646 (defun anything-c-delete-file (file)
6647 "Delete the given file after querying the user.
6648 Ask to kill buffers associated with that file, too."
6649 (let ((buffers (anything-c-file-buffers file
)))
6650 (dired-delete-file file
'dired-recursive-deletes
)
6652 (dolist (buf buffers
)
6653 (when (y-or-n-p (format "Kill buffer %s, too? " buf
))
6654 (kill-buffer buf
))))))
6656 (defun anything-get-mailcap-for-file (filename)
6657 "Get the command to use for FILENAME from mailcap files.
6658 The command is like <command %s> and is meant to use with `format'."
6659 (mailcap-parse-mailcaps)
6660 (let* ((ext (file-name-extension filename
))
6661 (mime (when ext
(mailcap-extension-to-mime ext
))))
6662 (when mime
(mailcap-mime-info mime
))))
6664 (defun anything-get-default-program-for-file (filename)
6665 "Try to find a default program to open FILENAME.
6666 Try first in `anything-c-external-programs-associations' and then in mailcap file
6667 if nothing found return nil."
6668 (let* ((ext (file-name-extension filename
))
6669 (def-prog (assoc-default ext anything-c-external-programs-associations
)))
6670 (if (and def-prog
(not (string= def-prog
"")))
6671 (concat def-prog
" %s")
6672 (anything-get-mailcap-for-file filename
))))
6674 (defun anything-c-open-file-externally (file)
6675 "Open FILE with an external program.
6676 Try to guess which program to use with `anything-get-default-program-for-file'.
6677 If not found or a prefix arg is given query the user which tool to use."
6678 (let* ((fname (expand-file-name file
))
6679 (collection (anything-c-external-commands-list-1 'sort
))
6680 (def-prog (anything-get-default-program-for-file fname
))
6682 ;; No prefix arg, default program exists.
6683 (unless (or anything-current-prefix-arg
(not def-prog
))
6684 (replace-regexp-in-string " %s" "" def-prog
))
6685 ;; Prefix arg or no default program.
6687 "Program: " collection
6689 :name
"Open file Externally"
6690 :history anything-external-command-history
)))
6691 (program (concat real-prog-name
" '%s'")))
6692 (unless (or def-prog
; Association exists, no need to record it.
6693 (not (file-exists-p fname
))) ; Don't record non--filenames.
6697 "Do you want to make %s the default program for this kind of files? "
6699 (push (cons (file-name-extension fname
)
6701 "Program(Add args maybe and confirm): " real-prog-name
))
6702 anything-c-external-programs-associations
)
6703 (customize-save-variable 'anything-c-external-programs-associations
6704 anything-c-external-programs-associations
)))
6705 (anything-run-or-raise program file
)
6706 (setq anything-external-command-history
6707 (cons real-prog-name
6708 (delete real-prog-name
6709 (loop for i in anything-external-command-history
6710 when
(executable-find i
) collect i
))))))
6714 (defun w32-shell-execute-open-file (file)
6715 (interactive "fOpen file:")
6717 (w32-shell-execute "open" (replace-regexp-in-string ;for UNC paths
6719 (replace-regexp-in-string ; strip cygdrive paths
6720 "/cygdrive/\\(.\\)" "\\1:"
6721 file nil nil
) nil t
))))
6723 (defun anything-c-open-file-with-default-tool (file)
6724 "Open FILE with the default tool on this platform."
6725 (if (eq system-type
'windows-nt
)
6726 (w32-shell-execute-open-file file
)
6727 (start-process "anything-c-open-file-with-default-tool"
6729 (cond ((eq system-type
'gnu
/linux
)
6731 ((or (eq system-type
'darwin
) ;; Mac OS X
6732 (eq system-type
'macos
)) ;; Mac OS 9
6736 (defun anything-c-open-dired (file)
6737 "Opens a dired buffer in FILE's directory. If FILE is a
6738 directory, open this directory."
6739 (if (file-directory-p file
)
6741 (dired (file-name-directory file
))
6742 (dired-goto-file file
)))
6744 (defun anything-c-display-to-real-line (candidate)
6745 (if (string-match "^ *\\([0-9]+\\):\\(.*\\)$" candidate
)
6746 (list (string-to-number (match-string 1 candidate
)) (match-string 2 candidate
))
6747 (error "Line number not found")))
6749 (defun anything-c-action-line-goto (lineno-and-content)
6750 (apply #'anything-goto-file-line
(anything-interpret-value (anything-attr 'target-file
))
6751 (append lineno-and-content
6752 (list (if (and (anything-attr-defined 'target-file
)
6753 (not anything-in-persistent-action
))
6754 'find-file-other-window
6757 (defun* anything-c-action-file-line-goto
(file-line-content &optional
(find-file-function #'find-file
))
6758 (apply #'anything-goto-file-line
6759 (if (stringp file-line-content
)
6760 ;; Case: filtered-candidate-transformer is skipped
6761 (cdr (anything-c-filtered-candidate-transformer-file-line-1 file-line-content
))
6762 file-line-content
)))
6765 (defun anything-c-filtered-candidate-transformer-file-line (candidates source
)
6766 (delq nil
(mapcar 'anything-c-filtered-candidate-transformer-file-line-1 candidates
)))
6768 (defun anything-c-filtered-candidate-transformer-file-line-1 (candidate)
6769 (when (string-match "^\\(.+?\\):\\([0-9]+\\):\\(.*\\)$" candidate
)
6770 (let ((filename (match-string 1 candidate
))
6771 (lineno (match-string 2 candidate
))
6772 (content (match-string 3 candidate
)))
6773 (cons (format "%s:%s\n %s"
6774 (propertize filename
'face compilation-info-face
)
6775 (propertize lineno
'face compilation-line-face
)
6777 (list (expand-file-name
6779 (or (anything-interpret-value (anything-attr 'default-directory
))
6780 (and (anything-candidate-buffer)
6782 'default-directory
(anything-candidate-buffer)))))
6783 (string-to-number lineno
) content
)))))
6785 (defun* anything-goto-file-line
(file lineno content
&optional
(find-file-function #'find-file
))
6786 (anything-aif (anything-attr 'before-jump-hook
)
6788 (when file
(funcall find-file-function file
))
6789 (if (anything-attr-defined 'adjust
)
6790 (anything-c-goto-line-with-adjustment lineno content
)
6791 (anything-goto-line lineno
))
6792 (unless (anything-attr-defined 'recenter
)
6793 (set-window-start (get-buffer-window anything-current-buffer
) (point)))
6794 (anything-aif (anything-attr 'after-jump-hook
)
6796 (when anything-in-persistent-action
6797 (anything-match-line-color-current-line)))
6799 (defun anything-find-file-as-root (candidate)
6800 (find-file (concat "/" anything-su-or-sudo
"::" (expand-file-name candidate
))))
6802 (defun anything-find-many-files (ignore)
6803 (mapc 'find-file
(anything-marked-candidates)))
6805 ;; borrowed from etags.el
6806 ;; (anything-c-goto-line-with-adjustment (line-number-at-pos) ";; borrowed from etags.el")
6807 (defun anything-c-goto-line-with-adjustment (line line-content
)
6810 ;; This constant is 1/2 the initial search window.
6811 ;; There is no sense in making it too small,
6812 ;; since just going around the loop once probably
6813 ;; costs about as much as searching 2000 chars.
6816 pat
(concat (if (eq selective-display t
)
6817 "\\(^\\|\^m\\) *" "^ *") ;allow indent
6818 (regexp-quote line-content
)))
6819 ;; If no char pos was given, try the given line number.
6820 (setq startpos
(progn (anything-goto-line line
) (point)))
6821 (or startpos
(setq startpos
(point-min)))
6822 ;; First see if the tag is right at the specified location.
6823 (goto-char startpos
)
6824 (setq found
(looking-at pat
))
6825 (while (and (not found
)
6827 (goto-char (- startpos offset
))
6830 (re-search-forward pat
(+ startpos offset
) t
)
6831 offset
(* 3 offset
))) ; expand search window
6833 (re-search-forward pat nil t
)
6834 (error "not found")))
6835 ;; Position point at the right place
6836 ;; if the search string matched an extra Ctrl-m at the beginning.
6837 (and (eq selective-display t
)
6840 (beginning-of-line))
6842 (anything-document-attribute 'default-directory
"type . file-line"
6843 "`default-directory' to interpret file.")
6844 (anything-document-attribute 'before-jump-hook
"type . file-line / line"
6845 "Function to call before jumping to the target location.")
6846 (anything-document-attribute 'after-jump-hook
"type . file-line / line"
6847 "Function to call after jumping to the target location.")
6848 (anything-document-attribute 'adjust
"type . file-line"
6849 "Search around line matching line contents.")
6850 (anything-document-attribute 'recenter
"type . file-line / line"
6851 "`recenter' after jumping.")
6852 (anything-document-attribute 'target-file
"type . line"
6853 "Goto line of target-file.")
6856 (defun anything-c-call-interactively (cmd-or-name)
6857 "Execute CMD-OR-NAME as Emacs command.
6858 It is added to `extended-command-history'.
6859 `anything-current-prefix-arg' is used as the command's prefix argument."
6860 (setq extended-command-history
6861 (cons (anything-c-stringify cmd-or-name
)
6862 (delete (anything-c-stringify cmd-or-name
) extended-command-history
)))
6863 (let ((current-prefix-arg anything-current-prefix-arg
)
6864 (cmd (anything-c-symbolify cmd-or-name
)))
6865 (if (stringp (symbol-function cmd
))
6866 (execute-kbd-macro (symbol-function cmd
))
6867 (setq this-command cmd
)
6868 (call-interactively cmd
))))
6871 (defun anything-c-set-variable (var)
6872 "Set value to VAR interactively."
6874 (let ((sym (anything-c-symbolify var
)))
6875 (set sym
(eval-minibuffer (format "Set %s: " var
)
6876 (prin1-to-string (symbol-value sym
))))))
6878 ;; (anything-c-set-variable 'hh)
6880 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Persistent Action Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6881 (defvar anything-match-line-overlay-face nil
)
6882 (defvar anything-match-line-overlay nil
)
6884 (defun anything-match-line-color-current-line (&optional start end buf face rec
)
6885 "Highlight and underline current position"
6886 (let ((args (list (or start
(line-beginning-position))
6887 (or end
(1+ (line-end-position)))
6889 (if (not anything-match-line-overlay
)
6890 (setq anything-match-line-overlay
(apply 'make-overlay args
))
6891 (apply 'move-overlay anything-match-line-overlay args
)))
6892 (overlay-put anything-match-line-overlay
6893 'face
(or face anything-match-line-overlay-face
))
6898 (defalias 'anything-persistent-highlight-point
'anything-match-line-color-current-line
)
6900 (defface anything-overlay-line-face
'((t (:background
"IndianRed4" :underline t
)))
6901 "Face for source header in the anything buffer." :group
'anything
)
6903 (setq anything-match-line-overlay-face
'anything-overlay-line-face
)
6905 (defun anything-match-line-cleanup ()
6906 (when anything-match-line-overlay
6907 (delete-overlay anything-match-line-overlay
)
6908 (setq anything-match-line-overlay nil
)))
6910 (defun anything-match-line-update ()
6911 (when anything-match-line-overlay
6912 (delete-overlay anything-match-line-overlay
)
6913 (anything-match-line-color-current-line)))
6915 (add-hook 'anything-cleanup-hook
'anything-match-line-cleanup
)
6916 (add-hook 'anything-after-persistent-action-hook
'anything-match-line-update
)
6918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Actions Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6920 (defun anything-c-transform-file-load-el (actions candidate
)
6921 "Add action to load the file CANDIDATE if it is an emacs lisp
6922 file. Else return ACTIONS unmodified."
6923 (if (member (file-name-extension candidate
) '("el" "elc"))
6924 (append actions
'(("Load Emacs Lisp File" . load-file
)))
6927 (defun anything-c-transform-file-browse-url (actions candidate
)
6928 "Add an action to browse the file CANDIDATE if it in a html
6929 file or URL. Else return ACTIONS unmodified."
6930 (let ((browse-action '("Browse with Browser" . browse-url
)))
6931 (cond ((string-match "^http\\|^ftp" candidate
)
6932 (cons browse-action actions
))
6933 ((string-match "\\.html?$" candidate
)
6934 (append actions
(list browse-action
)))
6938 (defun anything-c-transform-function-call-interactively (actions candidate
)
6939 "Add an action to call the function CANDIDATE interactively if
6940 it is a command. Else return ACTIONS unmodified."
6941 (if (commandp (intern-soft candidate
))
6942 (append actions
'(("Call Interactively"
6944 anything-c-call-interactively
)))
6948 (defun anything-c-transform-sexp-eval-command-sexp (actions candidate
)
6949 "If CANDIDATE's `car' is a command, then add an action to
6950 evaluate it and put it onto the `command-history'."
6951 (if (commandp (car (read candidate
)))
6952 ;; Make it first entry
6953 (cons '("Eval and put onto command-history" .
6955 (let ((sym (read sexp
)))
6957 (setq command-history
6958 (cons sym command-history
)))))
6962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Candidate Transformers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6964 (defun anything-c-skip-boring-buffers (buffers)
6965 (anything-c-skip-entries buffers anything-c-boring-buffer-regexp
))
6967 (defun anything-c-skip-current-buffer (buffers)
6968 (if anything-allow-skipping-current-buffer
6969 (remove (buffer-name anything-current-buffer
) buffers
)
6972 (defun anything-c-shadow-boring-buffers (buffers)
6973 "Buffers matching `anything-c-boring-buffer-regexp' will be
6974 displayed with the `file-name-shadow' face if available."
6975 (anything-c-shadow-entries buffers anything-c-boring-buffer-regexp
))
6978 (defun anything-c-shadow-boring-files (files)
6979 "Files matching `anything-c-boring-file-regexp' will be
6980 displayed with the `file-name-shadow' face if available."
6981 (anything-c-shadow-entries files anything-c-boring-file-regexp
))
6983 (defun anything-c-skip-boring-files (files)
6984 "Files matching `anything-c-boring-file-regexp' will be skipped."
6985 (anything-c-skip-entries files anything-c-boring-file-regexp
))
6986 ;; (anything-c-skip-boring-files '("README" "/src/.svn/hoge"))
6988 (defun anything-c-skip-current-file (files)
6989 "Current file will be skipped."
6990 (remove (buffer-file-name anything-current-buffer
) files
))
6992 (defun anything-c-w32-pathname-transformer (args)
6993 "Change undesirable features of windows pathnames to ones more acceptable to
6994 other candidate transformers."
6995 (if (eq system-type
'windows-nt
)
6997 (replace-regexp-in-string "/cygdrive/\\(.\\)" "\\1:" x
))
6999 (replace-regexp-in-string "\\\\" "/" y
)) args
))
7002 (defun anything-c-shorten-home-path (files)
7003 "Replaces /home/user with ~."
7004 (let ((home (replace-regexp-in-string "\\\\" "/" ; stupid Windows...
7006 (mapcar (lambda (file)
7007 (if (and (stringp file
) (string-match home file
))
7008 (cons (replace-match "~" nil nil file
) file
)
7013 (defun anything-c-mark-interactive-functions (functions)
7014 "Mark interactive functions (commands) with (i) after the function name."
7016 (loop for function in functions
7017 do
(push (cons (concat function
7018 (when (commandp (intern-soft function
)) " (i)"))
7021 finally
(return (nreverse list
)))))
7023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Adaptive Sorting of Candidates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7024 (defvar anything-c-adaptive-done nil
7025 "nil if history information is not yet stored for the current
7028 (defvar anything-c-adaptive-history nil
7029 "Contains the stored history information.
7030 Format: ((SOURCE-NAME (SELECTED-CANDIDATE (PATTERN . NUMBER-OF-USE) ...) ...) ...)")
7032 (defadvice anything-initialize
(before anything-c-adaptive-initialize activate
)
7033 "Advise `anything-initialize' to reset `anything-c-adaptive-done'
7034 when anything is started."
7035 (setq anything-c-adaptive-done nil
))
7037 (defadvice anything-exit-minibuffer
(before anything-c-adaptive-exit-minibuffer activate
)
7038 "Advise `anything-exit-minibuffer' to store history information
7039 when a candidate is selected with RET."
7040 (anything-c-adaptive-store-selection))
7042 (defadvice anything-select-action
(before anything-c-adaptive-select-action activate
)
7043 "Advise `anything-select-action' to store history information
7044 when the user goes to the action list with TAB."
7045 (anything-c-adaptive-store-selection))
7047 (defun anything-c-source-use-adaptative-p (&optional source-name
)
7048 "Return current source only if it use adaptative history, nil otherwise."
7049 (let* ((source (or source-name
(anything-get-current-source)))
7050 (adapt-source (or (assoc-default 'filtered-candidate-transformer
7051 (assoc (assoc-default 'type source
)
7052 anything-type-attributes
))
7053 (assoc-default 'candidate-transformer
7054 (assoc (assoc-default 'type source
)
7055 anything-type-attributes
))
7056 (assoc-default 'filtered-candidate-transformer source
)
7057 (assoc-default 'candidate-transformer source
))))
7058 (if (listp adapt-source
)
7059 (when (member 'anything-c-adaptive-sort adapt-source
) source
)
7060 (when (eq adapt-source
'anything-c-adaptive-sort
) source
))))
7062 (defun anything-c-adaptive-store-selection ()
7063 "Store history information for the selected candidate."
7064 (unless anything-c-adaptive-done
7065 (setq anything-c-adaptive-done t
)
7066 (let ((source (anything-c-source-use-adaptative-p)))
7068 (let* ((source-name (or (assoc-default 'type source
)
7069 (assoc-default 'name source
)))
7070 (source-info (or (assoc source-name anything-c-adaptive-history
)
7072 (push (list source-name
) anything-c-adaptive-history
)
7073 (car anything-c-adaptive-history
))))
7074 (selection (anything-get-selection))
7075 (selection-info (progn
7078 (let ((found (assoc selection
(cdr source-info
))))
7083 ;; move entry to the beginning of the
7084 ;; list, so that it doesn't get
7085 ;; trimmed when the history is
7088 (delete found
(cdr source-info
)))
7091 (cadr source-info
)))
7092 (pattern-info (progn
7093 (setcdr selection-info
7095 (let ((found (assoc anything-pattern
(cdr selection-info
))))
7098 (cons anything-pattern
0)
7100 ;; move entry to the beginning of the
7101 ;; list, so if two patterns used the
7102 ;; same number of times then the one
7103 ;; used last appears first in the list
7104 (setcdr selection-info
7105 (delete found
(cdr selection-info
)))
7107 (cdr selection-info
)))
7108 (cadr selection-info
))))
7110 ;; increase usage count
7111 (setcdr pattern-info
(1+ (cdr pattern-info
)))
7113 ;; truncate history if needed
7114 (if (> (length (cdr selection-info
)) anything-c-adaptive-history-length
)
7115 (setcdr selection-info
7116 (subseq (cdr selection-info
) 0 anything-c-adaptive-history-length
))))))))
7118 (if (file-readable-p anything-c-adaptive-history-file
)
7119 (load-file anything-c-adaptive-history-file
))
7120 (add-hook 'kill-emacs-hook
'anything-c-adaptive-save-history
)
7122 (defun anything-c-adaptive-save-history ()
7123 "Save history information to file given by `anything-c-adaptive-history-file'."
7127 ";; -*- mode: emacs-lisp -*-\n"
7128 ";; History entries used for anything adaptive display.\n")
7129 (prin1 `(setq anything-c-adaptive-history
',anything-c-adaptive-history
)
7132 (write-region (point-min) (point-max) anything-c-adaptive-history-file nil
7133 (unless (interactive-p) 'quiet
))))
7135 (defun anything-c-adaptive-sort (candidates source
)
7136 "Sort the CANDIDATES for SOURCE by usage frequency.
7137 This is a filtered candidate transformer you can use for the
7138 attribute `filtered-candidate-transformer' of a source in
7139 `anything-sources' or a type in `anything-type-attributes'."
7140 (let* ((source-name (or (assoc-default 'type source
)
7141 (assoc-default 'name source
)))
7142 (source-info (assoc source-name anything-c-adaptive-history
)))
7143 (if (not source-info
)
7144 ;; if there is no information stored for this source then do nothing
7148 ;; ... assemble a list containing the (CANIDATE . USAGE-COUNT)
7150 (mapcar (lambda (candidate-info)
7152 (dolist (pattern-info (cdr candidate-info
))
7153 (if (not (equal (car pattern-info
)
7155 (incf count
(cdr pattern-info
))
7157 ;; if current pattern is equal to the previously
7158 ;; used one then this candidate has priority
7159 ;; (that's why its count is boosted by 10000) and
7160 ;; it only has to compete with other candidates
7161 ;; which were also selected with the same pattern
7162 (setq count
(+ 10000 (cdr pattern-info
)))
7164 (cons (car candidate-info
) count
)))
7168 ;; sort the list in descending order, so candidates with highest
7169 ;; priorty come first
7170 (setq usage
(sort usage
(lambda (first second
)
7171 (> (cdr first
) (cdr second
)))))
7173 ;; put those candidates first which have the highest usage count
7174 (dolist (info usage
)
7175 (when (member* (car info
) candidates
7176 :test
'anything-c-adaptive-compare
)
7177 (push (car info
) sorted
)
7178 (setq candidates
(remove* (car info
) candidates
7179 :test
'anything-c-adaptive-compare
))))
7181 ;; and append the rest
7182 (append (reverse sorted
) candidates nil
)))))
7184 (defun anything-c-adaptive-compare (x y
)
7185 "Compare candidates X and Y taking into account that the
7186 candidate can be in (DISPLAY . REAL) format."
7187 (equal (if (listp x
)
7194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Outliner ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7195 (defvar anything-outline-goto-near-line-flag t
)
7196 (defvar anything-outline-using nil
)
7197 (defun anything-after-update-hook--outline ()
7198 (if (and (eq anything-outline-using t
)
7199 (eq anything-outline-goto-near-line-flag t
))
7200 (anything-outline-goto-near-line)))
7201 (add-hook 'anything-after-update-hook
'anything-after-update-hook--outline
)
7203 (defun anything-outline-goto-near-line ()
7204 (with-anything-window
7205 ;; TODO need consideration whether to update position by every input.
7206 (when t
; (equal anything-pattern "")
7207 (anything-goto-line 2)
7208 (let ((lineno (with-current-buffer anything-current-buffer
7209 (line-number-at-pos (car anything-current-position
)))))
7211 (while (<= (progn (skip-chars-forward " ")
7212 (or (number-at-point) lineno
))
7217 (return-from exit
))))
7219 (and (bobp) (forward-line 1))
7220 (and (anything-pos-header-line-p) (forward-line -
2))
7221 (anything-mark-current-line)))))
7223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Plug-in ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7224 ;; Plug-in: info-index
7225 (defun* anything-c-info-init
(&optional
(file (anything-attr 'info-file
)))
7227 (unless (anything-candidate-buffer)
7228 (save-window-excursion
7231 (tobuf (anything-candidate-buffer 'global
))
7232 (infobuf (current-buffer))
7234 (dolist (node (or (anything-attr 'index-nodes
) (Info-index-nodes)))
7235 (Info-goto-node node
)
7236 (goto-char (point-min))
7237 (while (search-forward "\n* " nil t
)
7238 (unless (search-forward "Menu:\n" (1+ (point-at-eol)) t
)
7239 '(save-current-buffer (buffer-substring-no-properties (point-at-bol) (point-at-eol)) result
)
7240 (setq s
(point-at-bol)
7242 (with-current-buffer tobuf
7243 (insert-buffer-substring infobuf s e
)
7244 (insert "\n"))))))))))
7246 (defun anything-c-info-goto (node-line)
7247 (Info-goto-node (car node-line
))
7248 (anything-goto-line (cdr node-line
)))
7250 (defun anything-c-info-display-to-real (line)
7252 "\\* +\\([^\n]*.+[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?" line
)
7253 (cons (format "(%s)%s" (anything-attr 'info-file
) (match-string 2 line
))
7254 (string-to-number (or (match-string 3 line
) "1")))))
7256 (defun anything-c-make-info-source (file)
7257 `((name .
,(concat "Info Index: " file
))
7259 (init . anything-c-info-init
)
7260 (display-to-real . anything-c-info-display-to-real
)
7261 (get-line . buffer-substring
)
7262 (candidates-in-buffer)
7263 (action ("Goto node" . anything-c-info-goto
))))
7265 (defun anything-compile-source--info-index (source)
7266 (anything-aif (anything-interpret-value (assoc-default 'info-index source
))
7267 (anything-c-make-info-source it
)
7269 (add-to-list 'anything-compile-source-functions
'anything-compile-source--info-index
)
7271 (anything-document-attribute 'info-index
"info-index plugin"
7272 "Create a source of info index very easily.
7274 ex. (defvar anything-c-source-info-wget '((info-index . \"wget\"))")
7276 (anything-document-attribute 'index-nodes
"info-index plugin (optional)"
7277 "Index nodes of info file.
7279 If it is omitted, `Info-index-nodes' is used to collect index nodes.
7280 Some info files are missing index specification.
7282 ex. See `anything-c-source-info-screen'.")
7284 ;; Plug-in: candidates-file
7285 (defun anything-compile-source--candidates-file (source)
7286 (if (assoc-default 'candidates-file source
)
7287 `((init anything-p-candidats-file-init
7288 ,@(let ((orig-init (assoc-default 'init source
)))
7289 (cond ((null orig-init
) nil
)
7290 ((functionp orig-init
) (list orig-init
))
7292 (candidates-in-buffer)
7295 (add-to-list 'anything-compile-source-functions
'anything-compile-source--candidates-file
)
7297 (defun anything-p-candidats-file-init ()
7298 (destructuring-bind (file &optional updating
)
7299 (anything-mklist (anything-attr 'candidates-file
))
7300 (setq file
(anything-interpret-value file
))
7301 (with-current-buffer (anything-candidate-buffer (find-file-noselect file
))
7303 (buffer-disable-undo)
7305 (auto-revert-mode 1)))))
7307 (anything-document-attribute 'candidates-file
"candidates-file plugin"
7308 "Use a file as the candidates buffer.
7310 1st argument is a filename, string or function name or variable name.
7311 If optional 2nd argument is non-nil, the file opened with `auto-revert-mode'.")
7313 ;; Plug-in: headline
7314 (defun anything-compile-source--anything-headline (source)
7315 (if (assoc-default 'headline source
)
7316 (append '((init . anything-headline-init
)
7317 (get-line . buffer-substring
)
7320 '((candidates-in-buffer)
7321 (persistent-help .
"Show this line")))
7323 (add-to-list 'anything-compile-source-functions
'anything-compile-source--anything-headline
)
7325 (defun anything-headline-init ()
7326 (when (and (anything-current-buffer-is-modified)
7327 (with-current-buffer anything-current-buffer
7328 (eval (or (anything-attr 'condition
) t
))))
7329 (anything-headline-make-candidate-buffer
7330 (anything-interpret-value (anything-attr 'headline
))
7331 (anything-interpret-value (anything-attr 'subexp
)))))
7333 (anything-document-attribute 'headline
"Headline plug-in"
7334 "Regexp string for anything-headline to scan.")
7335 (anything-document-attribute 'condition
"Headline plug-in"
7336 "A sexp representing the condition to use anything-headline.")
7337 (anything-document-attribute 'subexp
"Headline plug-in"
7338 "Display (match-string-no-properties subexp).")
7341 (defun anything-headline-get-candidates (regexp subexp
)
7342 (with-current-buffer anything-current-buffer
7344 (goto-char (point-min))
7345 (if (functionp regexp
) (setq regexp
(funcall regexp
)))
7346 (let (hierarchy curhead
)
7348 (if (numberp subexp
)
7349 (cons (match-string-no-properties subexp
) (match-beginning subexp
))
7350 (cons (buffer-substring (point-at-bol) (point-at-eol))
7352 (hierarchies (headlines)
7353 (1+ (loop for
(_ . hierarchy
) in headlines
7354 maximize hierarchy
)))
7356 (loop for i from
0 to hierarchy
7357 collecting
(aref curhead i
)))
7358 (arrange (headlines)
7359 (unless (null headlines
) ; FIX headlines empty bug!
7360 (loop with curhead
= (make-vector (hierarchies headlines
) "")
7361 for
((str . pt
) . hierarchy
) in headlines
7362 do
(aset curhead hierarchy str
)
7365 (format "H%d:%s" (1+ hierarchy
)
7366 (mapconcat 'identity
(vector-0-n curhead hierarchy
) " / "))
7371 (loop for re in regexp
7372 for hierarchy from
0
7373 do
(goto-char (point-min))
7376 while
(re-search-forward re nil t
)
7377 collect
(cons (matched) hierarchy
)))
7378 (lambda (a b
) (> (cdar b
) (cdar a
)))))
7379 (loop while
(re-search-forward regexp nil t
)
7380 collect
(matched))))))))
7383 (defun anything-headline-make-candidate-buffer (regexp subexp
)
7384 (with-current-buffer (anything-candidate-buffer 'local
)
7385 (loop for
(content . pos
) in
(anything-headline-get-candidates regexp subexp
)
7388 (with-current-buffer anything-current-buffer
7389 (line-number-at-pos pos
))
7392 (defun anything-headline-goto-position (pos recenter
)
7395 (set-window-start (get-buffer-window anything-current-buffer
) (point))))
7397 (defun anything-revert-buffer (candidate)
7398 (with-current-buffer candidate
7399 (when (buffer-modified-p)
7400 (revert-buffer t t
))))
7402 (defun anything-revert-marked-buffers (ignore)
7403 (mapc 'anything-revert-buffer
(anything-marked-candidates)))
7405 (defun anything-kill-marked-buffers (ignore)
7406 (mapc 'kill-buffer
(anything-marked-candidates)))
7408 ;; Plug-in: persistent-help
7409 (defun anything-compile-source--persistent-help (source)
7410 (append source
'((header-line . anything-persistent-help-string
))))
7411 (add-to-list 'anything-compile-source-functions
'anything-compile-source--persistent-help
)
7413 (defun anything-persistent-help-string ()
7414 (substitute-command-keys
7415 (concat "\\<anything-map>\\[anything-execute-persistent-action]: "
7416 (or (anything-interpret-value (anything-attr 'persistent-help
))
7417 (anything-aif (or (assoc-default 'persistent-action
7418 (anything-get-current-source))
7419 (assoc-default 'action
7420 (anything-get-current-source)))
7421 (cond ((symbolp it
) (symbol-name it
))
7422 ((listp it
) (or (ignore-errors (caar it
)) ""))))
7424 " (keeping session)")))
7426 (anything-document-attribute 'persistent-help
"persistent-help plug-in"
7427 "A string to explain persistent-action of this source.
7428 It also accepts a function or a variable name.")
7430 ;;; (anything '(((name . "persistent-help test")(candidates "a")(persistent-help . "TEST"))))
7432 ;; Plug-in: Type customize
7433 (defun anything-c-uniq-list (lst)
7434 "Like `remove-duplicates' in CL.
7435 But cut deeper duplicates and test by `equal'. "
7436 (reverse (remove-duplicates (reverse lst
) :test
'equal
)))
7437 (defvar anything-additional-type-attributes nil
)
7438 (defun anything-c-arrange-type-attribute (type spec
)
7439 "Override type attributes by `define-anything-type-attribute'.
7441 The SPEC is like source. The symbol `REST' is replaced with original attribute value.
7443 Example: Set `play-sound-file' as default action
7444 (anything-c-arrange-type-attribute 'file
7445 '((action (\"Play sound\" . play-sound-file)
7446 REST ;; Rest of actions (find-file, find-file-other-window, ...)
7449 (add-to-list 'anything-additional-type-attributes
7451 (loop with typeattr
= (assoc-default type anything-type-attributes
)
7452 for
(attr . value
) in spec
7455 (anything-c-uniq-list
7456 (loop for v in value
7458 append
(assoc-default attr typeattr
)
7462 collect
(cons attr value
)))))
7463 (put 'anything-c-arrange-type-attribute
'lisp-indent-function
1)
7465 (defun anything-compile-source--type-customize (source)
7466 (anything-aif (assoc-default (assoc-default 'type source
) anything-additional-type-attributes
)
7469 (add-to-list 'anything-compile-source-functions
'anything-compile-source--type-customize t
)
7471 ;; Plug-in: default-action
7472 (defun anything-compile-source--default-action (source)
7473 (anything-aif (assoc-default 'default-action source
)
7474 (append `((action ,it
,@(remove it
(assoc-default 'action source
))))
7477 (add-to-list 'anything-compile-source-functions
'anything-compile-source--default-action t
)
7478 (anything-document-attribute 'default-action
"default-action plug-in"
7481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7483 (defun anything-c-find-file-or-marked (candidate)
7484 "Open file CANDIDATE or open anything marked files in background."
7485 (let ((marked (anything-marked-candidates)))
7486 (if (> (length marked
) 1)
7487 ;; Open all marked files in background.
7488 (mapc 'find-file-noselect marked
)
7489 (if (and (not (file-exists-p candidate
))
7490 (and ffap-url-regexp
7491 (not (string-match ffap-url-regexp candidate
)))
7492 (string-match "/$" candidate
))
7493 ;; A a non--existing filename ending with /
7494 ;; Create a directory and jump to it.
7495 (when (y-or-n-p (format "Create directory `%s'? " candidate
))
7496 (let ((cur-dir default-directory
))
7499 (make-directory candidate
'parent
)
7500 (when (file-exists-p candidate
)
7502 (anything-find-files candidate
)))
7503 (setq default-directory cur-dir
))))
7504 ;; A non--existing filename NOT ending with / or
7505 ;; an existing filename, create or jump to it.
7506 (find-file-at-point candidate
)))))
7508 (defun anything-delete-marked-files (ignore)
7509 (let* ((files (anything-marked-candidates))
7510 (len (length files
)))
7512 (format "Delete *%s File(s):\n%s"
7514 (mapconcat (lambda (f) (format "- %s\n" f
)) files
""))))
7515 (message "(No deletions performed)")
7517 (set-text-properties 0 (length i
) nil i
)
7518 (anything-c-delete-file i
))
7519 (message "%s File(s) deleted" len
))))
7521 (defun anything-ediff-marked-buffers (candidate &optional merge
)
7522 "Ediff 2 marked buffers or 1 marked buffer and current-buffer.
7523 With optional arg `merge' call `ediff-merge-buffers'."
7524 (let ((lg-lst (length (anything-marked-candidates)))
7528 (error "Error:You have to mark at least 1 buffer"))
7530 (setq buf1 anything-current-buffer
7531 buf2
(first (anything-marked-candidates))))
7533 (setq buf1
(first (anything-marked-candidates))
7534 buf2
(second (anything-marked-candidates))))
7536 (error "Error:To much buffers marked!")))
7538 (ediff-merge-buffers buf1 buf2
)
7539 (ediff-buffers buf1 buf2
))))
7541 (defun anything-bookmark-get-bookmark-from-name (bmk)
7542 "Return bookmark name even if it is a bookmark with annotation.
7543 e.g prepended with *.
7544 Return nil if bmk is not a valid bookmark."
7545 (let ((bookmark (replace-regexp-in-string "\*" "" bmk
)))
7546 (if (assoc bookmark bookmark-alist
)
7548 (when (assoc bmk bookmark-alist
)
7551 (defun anything-delete-marked-bookmarks (ignore)
7552 "Delete this bookmark or all marked bookmarks."
7553 (dolist (i (anything-marked-candidates))
7554 (bookmark-delete (anything-bookmark-get-bookmark-from-name i
)
7557 (defun anything-require-or-error (feature function
)
7558 (or (require feature nil t
)
7559 (error "Need %s to use `%s'." feature function
)))
7561 (defun anything-find-buffer-on-elscreen (candidate)
7562 "Open buffer in new screen, if marked buffers open all in elscreens."
7563 (anything-require-or-error 'elscreen
'anything-find-buffer-on-elscreen
)
7564 (anything-aif (anything-marked-candidates)
7566 (let ((target-screen (elscreen-find-screen-by-buffer
7567 (get-buffer i
) 'create
)))
7568 (elscreen-goto target-screen
)))
7569 (let ((target-screen (elscreen-find-screen-by-buffer
7570 (get-buffer candidate
) 'create
)))
7571 (elscreen-goto target-screen
))))
7573 (defun anything-elscreen-find-file (file)
7574 (anything-require-or-error 'elscreen
'anything-elscreen-find-file
)
7575 (elscreen-find-file file
))
7577 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7579 ;;;; Type Attributes
7580 (define-anything-type-attribute 'buffer
7583 '(("Switch to buffer other window" . switch-to-buffer-other-window
)
7584 ("Switch to buffer" . switch-to-buffer
))
7585 '(("Switch to buffer" . switch-to-buffer
)
7586 ("Switch to buffer other window" . switch-to-buffer-other-window
)
7587 ("Switch to buffer other frame" . switch-to-buffer-other-frame
)))
7588 ,(and (locate-library "elscreen") '("Display buffer in Elscreen" . anything-find-buffer-on-elscreen
))
7589 ("View buffer" . view-buffer
)
7590 ("Display buffer" . display-buffer
)
7591 ("Revert buffer" . anything-revert-buffer
)
7592 ("Revert Marked buffers" . anything-revert-marked-buffers
)
7593 ("Insert buffer" . insert-buffer
)
7594 ("Kill buffer" . kill-buffer
)
7595 ("Kill Marked buffers" . anything-kill-marked-buffers
)
7596 ("Diff with file" . diff-buffer-with-file
)
7597 ("Ediff Marked buffers" . anything-ediff-marked-buffers
)
7598 ("Ediff Merge marked buffers" .
(lambda (candidate)
7599 (anything-ediff-marked-buffers candidate t
))))
7600 (persistent-help .
"Show this buffer")
7601 (candidate-transformer anything-c-skip-current-buffer anything-c-skip-boring-buffers
))
7602 "Buffer or buffer name.")
7604 (define-anything-type-attribute 'file
7607 '(("Find file other window" . find-file-other-window
)
7608 ("Find file(s)" . anything-find-many-files
)
7609 ("Find file as root" . anything-find-file-as-root
))
7610 '(("Find file" . anything-find-many-files
)
7611 ("Find file as root" . anything-find-file-as-root
)
7612 ("Find file other window" . find-file-other-window
)
7613 ("Find file other frame" . find-file-other-frame
)))
7614 ("Open dired in file's directory" . anything-c-open-dired
)
7615 ("Grep File(s)" .
(lambda (candidate)
7616 ;; Restore highlighting disabled in *-find-files.
7617 (let ((anything-mp-highlight-delay 0.7))
7618 (anything-do-grep (anything-marked-candidates)))))
7619 ("View file" . view-file
)
7620 ("Insert file" . insert-file
)
7621 ("Delete file(s)" . anything-delete-marked-files
)
7622 ("Open file externally (C-u to choose)" . anything-c-open-file-externally
)
7623 ("Open file with default tool" . anything-c-open-file-with-default-tool
)
7624 ("Find file in hex dump" . hexl-find-file
))
7625 (persistent-help .
"Show this file")
7626 (action-transformer anything-c-transform-file-load-el
7627 anything-c-transform-file-browse-url
)
7628 (candidate-transformer anything-c-w32-pathname-transformer
7629 anything-c-skip-current-file
7630 anything-c-skip-boring-files
7631 anything-c-shorten-home-path
))
7634 (let ((actions '(("Describe command" . describe-function
)
7635 ("Add command to kill ring" . anything-c-kill-new
)
7636 ("Go to command's definition" . find-function
)
7637 ("Debug on entry" . debug-on-entry
)
7638 ("Cancel debug on entry" . cancel-debug-on-entry
)
7639 ("Trace function" . trace-function
)
7640 ("Trace function (background)" . trace-function-background
)
7641 ("Untrace function" . untrace-function
))))
7642 (define-anything-type-attribute 'command
7643 `((action ("Call interactively" . anything-c-call-interactively
)
7645 ;; Sort commands according to their usage count.
7646 (filtered-candidate-transformer . anything-c-adaptive-sort
)
7647 (coerce . anything-c-symbolify
)
7648 (persistent-action . describe-function
))
7649 "Command. (string or symbol)")
7651 (define-anything-type-attribute 'function
7652 `((action .
,actions
)
7653 (action-transformer anything-c-transform-function-call-interactively
)
7654 (candidate-transformer anything-c-mark-interactive-functions
)
7655 (coerce . anything-c-symbolify
))
7656 "Function. (string or symbol)"))
7658 (define-anything-type-attribute 'variable
7659 '((action ("Describe variable" . describe-variable
)
7660 ("Add variable to kill ring" . anything-c-kill-new
)
7661 ("Go to variable's definition" . find-variable
)
7662 ("Set variable" . anything-c-set-variable
))
7663 (coerce . anything-c-symbolify
))
7666 (define-anything-type-attribute 'sexp
7667 '((action ("Eval s-expression" .
(lambda (c) (eval (read c
))))
7668 ("Add s-expression to kill ring" . kill-new
))
7669 (action-transformer anything-c-transform-sexp-eval-command-sexp
))
7670 "String representing S-Expressions.")
7672 (define-anything-type-attribute 'bookmark
7673 `((coerce . anything-bookmark-get-bookmark-from-name
)
7675 ("Jump to bookmark" .
(lambda (bookmark)
7676 (let ((current-prefix-arg anything-current-prefix-arg
))
7677 (bookmark-jump bookmark
))
7679 ("Jump to BM other window" .
(lambda (bookmark)
7680 (bookmark-jump-other-window bookmark
)
7682 ("Bookmark edit annotation" . bookmark-edit-annotation
)
7683 ("Bookmark show annotation" . bookmark-show-annotation
)
7684 ("Delete bookmark(s)" . anything-delete-marked-bookmarks
)
7685 ,@(when (fboundp 'bmkext-edit-bookmark
)
7686 '(("Edit Bookmark" . bmkext-edit-bookmark
)))
7687 ("Rename bookmark" . bookmark-rename
)
7688 ("Relocate bookmark" . bookmark-relocate
)))
7691 (define-anything-type-attribute 'line
7692 '((display-to-real . anything-c-display-to-real-line
)
7693 (action ("Go to Line" . anything-c-action-line-goto
)))
7694 "LINENO:CONTENT string, eg. \" 16:foo\".
7696 Optional `target-file' attribute is a name of target file.
7698 Optional `before-jump-hook' attribute is a function with no
7699 arguments which is called before jumping to position.
7701 Optional `after-jump-hook' attribute is a function with no
7702 arguments which is called after jumping to position.
7704 If `adjust' attribute is specified, searches the line whose
7705 content is CONTENT near the LINENO.
7707 If `recenter' attribute is specified, the line is displayed at
7708 the center of window, otherwise at the top of window.
7711 (define-anything-type-attribute 'file-line
7712 `((filtered-candidate-transformer anything-c-filtered-candidate-transformer-file-line
)
7714 (action ("Go to" . anything-c-action-file-line-goto
)))
7715 "FILENAME:LINENO:CONTENT string, eg. \"~/.emacs:16:;; comment\".
7717 Optional `default-directory' attribute is a default-directory
7718 FILENAME is interpreted.
7720 Optional `before-jump-hook' attribute is a function with no
7721 arguments which is called before jumping to position.
7723 Optional `after-jump-hook' attribute is a function with no
7724 arguments which is called after jumping to position.
7726 If `adjust' attribute is specified, searches the line whose
7727 content is CONTENT near the LINENO.
7729 If `recenter' attribute is specified, the line is displayed at
7730 the center of window, otherwise at the top of window.
7733 (define-anything-type-attribute 'timer
7734 '((real-to-display . anything-c-timer-real-to-display
)
7735 (action ("Cancel Timer" . cancel-timer
)
7736 ("Describe Function" .
(lambda (tm) (describe-function (timer--function tm
))))
7737 ("Find Function" .
(lambda (tm) (find-function (timer--function tm
)))))
7738 (persistent-action .
(lambda (tm) (describe-function (timer--function tm
))))
7739 (persistent-help .
"Describe Function"))
7742 ;;;; Default `anything-sources'
7743 ;; Setting `anything-sources' is DEPRECATED, but it seems that newbies
7744 ;; tend to invoke M-x anything directly. So I offer default setting.
7745 (setq anything-sources
7746 '(anything-c-source-buffers+
7747 anything-c-source-recentf
7748 anything-c-source-files-in-current-dir
+))
7751 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
7752 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
7754 (when (fboundp 'expectations
)
7756 (desc "candidates-file plug-in")
7757 (expect '(anything-p-candidats-file-init)
7758 (assoc-default 'init
7759 (car (anything-compile-sources
7761 (candidates-file .
"test.txt")))
7762 '(anything-compile-source--candidates-file)))))
7763 (expect '(anything-p-candidats-file-init
7765 (assoc-default 'init
7766 (car (anything-compile-sources
7768 (candidates-file .
"test.txt")
7769 (init .
(lambda () 1))))
7770 '(anything-compile-source--candidates-file)))))
7771 (expect '(anything-p-candidats-file-init
7773 (assoc-default 'init
7774 (car (anything-compile-sources
7776 (candidates-file .
"test.txt")
7777 (init (lambda () 1))))
7778 '(anything-compile-source--candidates-file)))))
7780 ;; (desc "anything-c-source-buffers")
7781 ;; (expect '(("Buffers" ("foo" "curbuf")))
7782 ;; (stub buffer-list => '("curbuf" " hidden" "foo" "*anything*"))
7783 ;; (let ((anything-c-boring-buffer-regexp
7788 ;; " *Echo Area" " *Minibuf"))))
7789 ;; (flet ((buffer-name (&optional x) x))
7790 ;; (anything-test-candidates 'anything-c-source-buffers))))
7791 (desc "anything-c-stringify")
7793 (anything-c-stringify "str1"))
7795 (anything-c-stringify 'str2
))
7796 (desc "anything-c-symbolify")
7798 (anything-c-symbolify "sym1"))
7800 (anything-c-symbolify 'sym2
))
7801 (desc "plug-in:default-action")
7802 (expect '(((action ("default" . default
) ("original" . original
))
7803 (default-action .
("default" . default
))
7804 (action ("original" . original
))))
7805 (anything-compile-sources
7806 '(((default-action .
("default" . default
))
7807 (action ("original" . original
))))
7808 '(anything-compile-source--default-action)))
7809 (expect '(((action ("a1" . a1
) ("a2" . a2
))
7810 (default-action .
("a1" . a1
))
7811 (action ("a1" . a1
) ("a2" . a2
))))
7812 (anything-compile-sources
7813 '(((default-action .
("a1" . a1
))
7814 (action ("a1" . a1
) ("a2" . a2
))))
7815 '(anything-compile-source--default-action)))
7816 (expect '(((action ("a2" . a2
) ("a1" . a1
))
7817 (default-action .
("a2" . a2
))
7818 (action ("a1" . a1
) ("a2" . a2
))))
7819 (anything-compile-sources
7820 '(((default-action .
("a2" . a2
))
7821 (action ("a1" . a1
) ("a2" . a2
))))
7822 '(anything-compile-source--default-action))))))
7824 (provide 'anything-config
)
7826 ;;; Local Variables:
7827 ;;; time-stamp-format: "%:y-%02m-%02d %02H:%02M:%02S (%Z) %u"
7830 ;; How to save (DO NOT REMOVE!!)
7831 ;; (progn (magit-push) (emacswiki-post "anything-config.el"))
7832 ;;; anything-config.el ends here
7834 ;;; LocalWords: Tassilo Patrovics Vagn Johansen Dahl Clementson infos
7835 ;;; LocalWords: Kamphausen informations McBrayer Volpiatto bbdb bb
7836 ;;; LocalWords: iswitchb imenu Recentf sym samewindow pos bol eol
7837 ;;; LocalWords: aif str lst func attrib recentf lessp prin mapatoms commandp
7838 ;;; LocalWords: cmd stb Picklist picklist mapcan subentry destructuring dirs
7839 ;;; LocalWords: darwin locat MacOS mdfind Firstname Lastname calc prepend jids
7840 ;;; LocalWords: dotimes Thierry online vname
7841 ;;; LocalWords: csharp javascript lua makefile cperl zcat lineno buf
7842 ;;; LocalWords: multiline href fn cand NewTitle cwd filepath thru ret
7843 ;;; LocalWords: bfn fOpen UNC cygdrive nt xdg macos FILE's elc rx svn hg
7844 ;;; LocalWords: CANDIDATE's darcs facep pathname args pathnames subseq priorty
7845 ;;; LocalWords: Vokes rfind berkeley JST ffap lacarte bos
7846 ;;; LocalWords: Lacarte Minibuf epp LaCarte bm attrset migemo attr conf mklist
7847 ;;; LocalWords: startpos noselect dont desc